{"text": "\\subsection{How many unique operators are there?}\n\nAn arbitrary operator takes \\(n\\) inputs are returns \\(T\\) or \\(F\\).\n\nWith \\(0\\) inputs there is one posible permutation. For every additional input the number of possible permutations doubles. Therefore there are \\(2^n\\) possible permutations.\n\nFor the operator with one permutation there are two operators. For every additional permutation the number of operator doubles. Therefore there are \\(2^{(2^n)}\\) possible operations.\n\nWith \\(0\\) inputs, we need \\(2\\) different operators to cover all outputs. For \\(1\\) input we need \\(4\\) and for \\(2\\) inputs we need \\(16\\).\n\n\\subsection{We don't need \\(0\\)-ary operators}\n\nThere are two unique \\(0\\)-ary operators. One always returns \\(T\\) and the other always returns \\(F\\). These are already described.\n\n\\subsection{We need one unary operator}\n\nFor the operators with \\(1\\) input we have:\n\n\\begin{itemize}\n\\item one which always returns \\(T\\)\n\\item one which always returns \\(F\\)\n\\item one which always returns the same as the input\n\\item one which returns the opposite of the input\n\\end{itemize}\n\nIt is this last one, negation, shown as \\(\\neg \\) and is of most interest.\n\n\\subsection{We can use a subset of binary operators}\n\nThe full list of binary operators are included below.\n\nOf these, the first two are \\(0\\)-ary operators, and so are not needed. The next four are unary operators, and so are not needed.\n\nThe non-implications can be rewritten using negation.\n\n\\subsection{Brackets replace the need for n-ary operators}\n\nN-ary operators contain \\(3\\) or more inputs.\n\nN-ary operators can be defined in terms of binary operators.\n\nAs an example if we want an operator to return positive if all inputs are true, we can use:\n\n\\((\\theta \\land \\gamma )\\land \\beta \\)\n\n", "meta": {"hexsha": "9aa60dc86885fbff3e630a5430f27287331abc07", "size": 1772, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogic/04-02-operators.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/propositionalLogic/04-02-operators.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/propositionalLogic/04-02-operators.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.5217391304, "max_line_length": 182, "alphanum_fraction": 0.7387133183, "num_tokens": 420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620539235896, "lm_q2_score": 0.8856314677809303, "lm_q1q2_score": 0.849995476536789}}
{"text": "\\section{Function Reference}\n\n\\subsection*{abs($x$)}\n\nReturns the absolute value or vector length of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nX = (x,y,z)\nabs(X)\n\\end{verbatim}\n}\n\n\\noindent\n$\\left(x^2+y^2+z^2\\right)^{1/2}$\n\n\\subsection*{adj($m$)}\n\nReturns the adjunct of matrix $m$.\nAdjunct is equal to determinant times inverse.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\nadj(A) == det(A) inv(A)\n\\end{verbatim}\n}\n\n\\noindent\n$1$\n\n\\subsection*{and($a,b,\\ldots$)}\n\nReturns 1 if all arguments are true (nonzero).\nReturns 0 otherwise.\n\n{\\color{blue}\n\\begin{verbatim}\nand(1=1,2=2)\n\\end{verbatim}\n}\n\n\\noindent\n$1$\n\n\\subsection*{arccos($x$)}\n\nReturns the arc cosine of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\narccos(1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\tfrac{1}{3}\\pi$\n\n\\subsection*{arccosh($x$)}\n\nReturns the arc hyperbolic cosine of $x$.\n\n\\subsection*{arcsin($x$)}\n\nReturns the arc sine of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\narcsin(1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\tfrac{1}{6}\\pi$\n\n\\subsection*{arcsinh($x$)}\n\nReturns the arc hyperbolic sine of $x$.\n\n\\subsection*{arctan($y,x$)}\n\nReturns the arc tangent of $y$ over $x$.\nIf $x$ is omitted then $x=1$ is used.\n\n{\\color{blue}\n\\begin{verbatim}\narctan(1,0)\n\\end{verbatim}\n}\n\n\\noindent\n$\\tfrac{1}{2}\\pi$\n\n\\subsection*{arctanh($x$)}\n\nReturns the arc hyperbolic tangent of $x$.\n\n\\subsection*{arg($z$)}\n\nReturns the angle of complex $z$.\n\n{\\color{blue}\n\\begin{verbatim}\narg(2 - 3i)\n\\end{verbatim}\n}\n\n\\noindent\n$\\arctan(-3,2)$\n\n\\subsection*{binding($s$)}\n\nThe result of evaluating a symbol can differ from the symbol's binding.\nFor example, the result may be expanded.\nThe {\\tt binding} function returns the actual binding of a symbol.\n\n{\\color{blue}\n\\begin{verbatim}\np = quote((x + 1)^2)\np\n\\end{verbatim}\n}\n\n\\noindent\n$p=x^2+2x+1$\n\n{\\color{blue}\n\\begin{verbatim}\nbinding(p)\n\\end{verbatim}\n}\n\n\\noindent\n$(x+1)^2$\n\n\\subsection*{ceiling($x$)}\n\nReturns the smallest integer greater than or equal to $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nceiling(1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$1$\n\n\\subsection*{check($x$)}\n\nIf $x$ is true (nonzero) then continue, else stop.\nExpression $x$ can include the relational operators\n\\verb$=$,\n\\verb$==$,\n\\verb$<$,\n\\verb$<=$,\n\\verb$>$,\n\\verb$>=$.\nUse the\n\\verb$not$\nfunction to test for inequality.\n\n{\\color{blue}\n\\begin{verbatim}\nA = 1\nB = 1\ncheck(A=B) -- stop here if A not equal to B\n\\end{verbatim}\n}\n\n\\subsection*{circexp($x$)}\n\nReturns expression $x$ with circular and hyperbolic functions\nconverted to exponentials.\n\n{\\color{blue}\n\\begin{verbatim}\ncircexp(cos(x) + i sin(x))\n\\end{verbatim}\n}\n\n\\noindent\n$\\exp(ix)$\n\n\\subsection*{clear}\n\nClears all symbol definitions.\n\n\\subsection*{clock($z$)}\n\nReturns complex $z$ in polar form with base of negative 1 instead of $e$.\n\n{\\color{blue}\n\\begin{verbatim}\nclock(2 - 3i)\n\\end{verbatim}\n}\n\n\\noindent\n$13^{1/2}\\,(-1)^{\\arctan(-3,2)/\\pi}$\n\n\\subsection*{conj($z$)}\n\nReturns the complex conjugate of $z$.\n\n{\\color{blue}\n\\begin{verbatim}\nconj(2 - 3i)\n\\end{verbatim}\n}\n\n\\noindent\n$2 + 3 i$\n\n\\subsection*{contract($a,i,j$)}\n\nReturns tensor $a$ summed over indices $i$ and $j$.\nIf $i$ and $j$ are omitted then 1 and 2 are used.\nThe expression {\\tt contract(m)} computes the trace of matrix $m$.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\ncontract(A)\n\\end{verbatim}\n}\n\n\\noindent\n$a + d$\n\n\\subsection*{cos($x$)}\n\nReturns the cosine of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\ncos(pi/4)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{1}{2^{1/2}}$\n\n\\subsection*{cosh($x$)}\n\nReturns the hyperbolic cosine of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\ncircexp(cosh(x))\n\\end{verbatim}\n}\n\n\\noindent\n$\\tfrac{1}{2}\\exp(-x)+\\tfrac{1}{2}\\exp(x)$\n\n\\subsection*{d($f,x$)}\n\nReturns the partial derivative of $f$ with respect to $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nd(x^2,x)\n\\end{verbatim}\n}\n\n\\noindent\n$2x$\n\n\\bigskip\n\\noindent\nArgument $f$ can be a tensor of any rank.\nArgument $x$ can be a vector.\nWhen $x$ is a vector the result is the gradient of $f$.\n\n{\\color{blue}\n\\begin{verbatim}\nF = (f(),g(),h())\nX = (x,y,z)\nd(F,X)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\begin{bmatrix}\n\\operatorname{d}(f(),x) & \\operatorname{d}(f(),y) &  \\operatorname{d}(f(),z)\\\\\n\\operatorname{d}(g(),x) & \\operatorname{d}(g(),y) &  \\operatorname{d}(g(),z)\\\\\n\\operatorname{d}(h(),x) & \\operatorname{d}(h(),y) &  \\operatorname{d}(h(),z)\n\\end{bmatrix}\n$\n\n\\bigskip\n\\noindent\nIt is OK to use {\\tt d} as a variable name.\nIt will not conflict with function {\\tt d}.\n\n\\bigskip\n\\noindent\nIt is OK to redefine {\\tt d} as a different function.\nThe function {\\tt derivative}, a synonym for {\\tt d},\ncan still be used to obtain a partial derivative.\n\n\\subsection*{defint($f,x,a,b$)}\n\nReturns the definite integral of $f$ with respect to $x$\nevaluated from $a$ to $b$.\nThe argument list can be extended for multiple integrals\nas shown in the following example.\n\n{\\color{blue}\n\\begin{verbatim}\nf = (1 + cos(theta)^2) sin(theta)\ndefint(f, theta, 0, pi, phi, 0, 2pi) -- integrate over theta then over phi\n\\end{verbatim}\n}\n\n\\noindent\n$\\tfrac{16}{3}\\pi$\n\n\\subsection*{denominator($x$)}\n\nReturns the denominator of expression $x$.\n\n{\\color{blue}\n\\begin{verbatim}\ndenominator(a/b)\n\\end{verbatim}\n}\n\n\\noindent\n$b$\n\n\\subsection*{det($m$)}\n\nReturns the determinant of matrix $m$.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\ndet(A)\n\\end{verbatim}\n}\n\n\\noindent\n$a d - b c$\n\n\\subsection*{dim($a,n$)}\n\nReturns the dimension of the $n$th index of tensor $a$.\nIndex numbering starts with 1.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((1,2),(3,4),(5,6))\ndim(A,1)\n\\end{verbatim}\n}\n\n\\noindent\n$3$\n\n\\subsection*{do($a,b,\\ldots$)}\n\nEvaluates each argument from left to right.\nReturns the result of the final argument.\n\n{\\color{blue}\n\\begin{verbatim}\ndo(A=1,B=2,A+B)\n\\end{verbatim}\n}\n\n\\noindent\n$3$\n\n\\subsection*{dot($a,b,\\ldots$)}\n\nReturns the dot product of vectors, matrices, and tensors.\nAlso known as the matrix product.\n\n{\\color{blue}\n\\begin{verbatim}\n-- solve for X in AX=B\nA = ((1,2),(3,4))\nB = (5,6)\nX = dot(inv(A),B)\nX\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\begin{bmatrix}-4\\\\ \\tfrac{9}{2}\\end{bmatrix}$\n\n\\subsection*{draw($f,x$)}\n\nDraws a graph of $f(x)$.\nDrawing ranges can be set with {\\tt xrange} and {\\tt yrange}.\n\n{\\color{blue}\n\\begin{verbatim}\nxrange = (0,1)\nyrange = (0,1)\ndraw(x^2,x)\n\\end{verbatim}\n}\n\n\\subsection*{eval($f,x,a$)}\n\nReturns expression $f$ evaluated at $x$ equals $a$.\nThe argument list can be extended for multivariate expressions.\nFor example,\n\\verb$eval(f,x,a,y,b)$\nis equivalent to\n\\verb$eval(eval(f,x,a),y,b)$.\n\n{\\color{blue}\n\\begin{verbatim}\neval(x + y,x,a,y,b)\n\\end{verbatim}\n}\n\n\\noindent\n$a+b$\n\n\\subsection*{exp($x$)}\n\nReturns the exponential of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nexp(i pi)\n\\end{verbatim}\n}\n\n\\noindent\n$-1$\n\n\\subsection*{expcos($z$)}\n\nReturns the cosine of $z$ in exponential form.\n\n{\\color{blue}\n\\begin{verbatim}\nexpcos(z)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\tfrac{1}{2}\\exp(iz)+\\tfrac{1}{2}\\exp(-iz)$\n\n\\subsection*{expcosh($z$)}\n\nReturns the hyperbolic cosine of $z$ in exponential form.\n\n{\\color{blue}\n\\begin{verbatim}\nexpcosh(z)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\tfrac{1}{2}\\exp(-z)+\\tfrac{1}{2}\\exp(z)$\n\n\\subsection*{expsin($z$)}\n\nReturns the sine of $z$ in exponential form.\n\n{\\color{blue}\n\\begin{verbatim}\nexpsin(z)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle -\\tfrac{1}{2}i\\exp(iz)+\\tfrac{1}{2}i\\exp(-iz)$\n\n\\subsection*{expsinh($z$)}\n\nReturns the hyperbolic sine of $z$ in exponential form.\n\n{\\color{blue}\n\\begin{verbatim}\nexpsinh(z)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle -\\tfrac{1}{2}\\exp(-z)+\\tfrac{1}{2}\\exp(z)$\n\n\\subsection*{exptan($z$)}\n\nReturns the tangent of $z$ in exponential form.\n\n{\\color{blue}\n\\begin{verbatim}\nexptan(z)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{i}{\\exp(2iz)+1}-\\frac{i\\exp(2iz)}{\\exp(2iz)+1}$\n\n\\subsection*{exptanh($z$)}\n\nReturns the hyperbolic tangent of $z$ in exponential form.\n\n{\\color{blue}\n\\begin{verbatim}\nexptanh(z)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle -\\frac{1}{\\exp(2z)+1}+\\frac{\\exp(2z)}{\\exp(2z)+1}$\n\n\\subsection*{factorial($n$)}\n\nReturns the factorial of $n$.\nThe expression {\\tt n!} can also be used.\n\n{\\color{blue}\n\\begin{verbatim}\n20!\n\\end{verbatim}\n}\n\n\\noindent\n$2432902008176640000$\n\n\\subsection*{float($x$)}\n\nReturns expression $x$ with rational numbers and integers converted to\nfloating point values.\nThe symbol {\\tt pi} and the natural number are also converted.\n\n{\\color{blue}\n\\begin{verbatim}\nfloat(212^17)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle 3.52947\\times 10^{39}$\n\n\\subsection*{floor($x$)}\n\nReturns the largest integer less than or equal to $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nfloor(1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$0$\n\n\\subsection*{for($i,j,k,a,b,\\ldots$)}\n\nFor $i$ equals $j$ through $k$ evaluate $a$, $b$, etc.\n\n{\\color{blue}\n\\begin{verbatim}\nfor(k,1,3,A=k,print(A))\n\\end{verbatim}\n}\n\n\\noindent\n$A=1$\\\\\n$A=2$\\\\\n$A=3$\n\n\\bigskip\n\\noindent\nNote: The original value of $i$ is restored after {\\tt for} completes.\nIf symbol {\\tt i} is used for index variable $i$\nthen the imaginary unit is overridden in the scope of {\\tt for}.\n\n\\subsection*{i}\n\nSymbol {\\tt i} is initialized to the imaginary unit $\\sqrt{-1}$.\n\n{\\color{blue}\n\\begin{verbatim}\nexp(i pi)\n\\end{verbatim}\n}\n\n\\noindent\n$-1$\n\n\\bigskip\n\\noindent\nNote: It is OK to clear or redefine {\\tt i} and use the symbol for something else.\n\n\\subsection*{imag($z$)}\n\nReturns the imaginary part of complex $z$.\n\n{\\color{blue}\n\\begin{verbatim}\nimag(2 - 3i)\n\\end{verbatim}\n}\n\n\\noindent\n$-3$\n\n\\subsection*{inner($a,b,\\ldots$)}\n\nReturns the inner product of vectors, matrices, and tensors.\nAlso known as the matrix product.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\nB = (x,y)\ninner(A,B)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\n\\begin{bmatrix}\nax+by\\\\\ncx+dy\n\\end{bmatrix}\n$\n\n\\bigskip\n\\noindent\nNote: {\\tt inner} and {\\tt dot} are the same function.\n\n\\subsection*{integral($f,x$)}\n\nReturns the integral of $f$ with respect to $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nintegral(x^2,x)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\tfrac{1}{3}x^3$\n\n\\subsection*{inv($m$)}\n\nReturns the inverse of matrix $m$.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((1,2),(3,4))\ninv(A)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\n\\begin{bmatrix}\n-2 & 1\\\\\n\\tfrac{3}{2} & -\\tfrac{1}{2}\n\\end{bmatrix}\n$\n\n\\subsection*{j}\n\nSet {\\tt j=sqrt(-1)} to use {\\tt j} for the imaginary unit instead of {\\tt i}.\n\n{\\color{blue}\n\\begin{verbatim}\nj = sqrt(-1)\n1/sqrt(-1)\n\\end{verbatim}\n}\n\n\\noindent\n$-j$\n\n\\subsection*{last}\n\nThe result of the previous calculation is stored in {\\tt last}.\n\n{\\color{blue}\n\\begin{verbatim}\n212^17\n\\end{verbatim}\n}\n\n\\noindent\n$3529471145760275132301897342055866171392$\n\n{\\color{blue}\n\\begin{verbatim}\nlast\n\\end{verbatim}\n}\n\n\\noindent\n$last=3529471145760275132301897342055866171392$\n\n\\bigskip\n\\noindent\nSymbol {\\tt last} is an implied argument when a function has no argument list.\n\n{\\color{blue}\n\\begin{verbatim}\nfloat\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle 3.52947\\times10^{39}$\n\n\\subsection*{log($x$)}\n\nReturns the natural logarithm of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nlog(x^y)\n\\end{verbatim}\n}\n\n\\noindent\n$y\\log(x)$\n\n\\subsection*{mag($z$)}\n\nReturns the magnitude of complex $z$.\nFunction {\\tt mag} treats undefined symbols as real while {\\tt abs} does not.\n\n{\\color{blue}\n\\begin{verbatim}\nmag(x + i y)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle (x^2+y^2)^{1/2}$\n\n\\subsection*{not($x$)}\n\nReturns 0 if $x$ is true (nonzero).\nReturns 1 otherwise.\n\n{\\color{blue}\n\\begin{verbatim}\nnot(1=1)\n\\end{verbatim}\n}\n\n\\noindent\n$0$\n\n\\subsection*{numerator($x$)}\n\nReturns the numerator of expression $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nnumerator(a/b)\n\\end{verbatim}\n}\n\n\\noindent\n$a$\n\n\\subsection*{or($a,b,\\ldots$)}\n\nReturns 1 if at least one argument is true (nonzero).\nReturns 0 otherwise.\n\n{\\color{blue}\n\\begin{verbatim}\nor(1=1,2=2)\n\\end{verbatim}\n}\n\n\\noindent\n$1$\n\n\\subsection*{outer($a,b,\\ldots$)}\n\nReturns the outer product of vectors, matrices, and tensors.\nAlso known as the tensor product.\n\n{\\color{blue}\n\\begin{verbatim}\nA = (a,b,c)\nB = (x,y,z)\nouter(A,B)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\n\\begin{bmatrix}\na x & a y & a z\\\\\nb x & b y & b z\\\\\nc x & c y & c z\n\\end{bmatrix}\n$\n\n\\subsection*{pi}\n\nSymbol for $\\pi$.\n\n{\\color{blue}\n\\begin{verbatim}\nexp(i pi)\n\\end{verbatim}\n}\n\n\\noindent\n$-1$\n\n\\subsection*{polar($z$)}\n\nReturns complex $z$ in polar form.\n\n{\\color{blue}\n\\begin{verbatim}\npolar(x - i y)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle (x^2+y^2)^{1/2}\\exp(i\\arctan(-y,x))$\n\n\\subsection*{power}\n\nUse \\verb$^$ to raise something to a power.\nUse parentheses for negative powers.\n\n{\\color{blue}\n\\begin{verbatim}\nx^(-2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{1}{x^2}$\n\n\\subsection*{print($a,b,\\ldots$)}\n\nEvaluate expressions and print the results.\nUseful for printing from inside a {\\tt for} loop.\n\n{\\color{blue}\n\\begin{verbatim}\nfor(j,1,3,print(j))\n\\end{verbatim}\n}\n\n\\noindent\n$j=1$\\newline\n$j=2$\\newline\n$j=3$\n\n\\section*{product($i,j,k,f$)}\n\nFor $i$ equals $j$ through $k$ evaluate $f$.\nReturns the product of all $f$.\n\n{\\color{blue}\n\\begin{verbatim}\nproduct(j,1,3,x + j)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle x^3+6x^2+11x+6$\n\n\\bigskip\n\\noindent\nNote: The original value of $i$ is restored after {\\tt product} completes.\nIf symbol {\\tt i} is used for index variable $i$\nthen the imaginary unit is overridden in the scope of {\\tt product}.\n\n\\subsection*{quote($x$)}\n\nReturns expression $x$ without evaluating it first.\n\n{\\color{blue}\n\\begin{verbatim}\nquote((x + 1)^2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle (x+1)^2$\n\n\\subsection*{rank($a$)}\n\nReturns the number of indices that tensor $a$ has.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\nrank(A)\n\\end{verbatim}\n}\n\n\\noindent\n2\n\n\\subsection*{rationalize($x$)}\n\nReturns expression $x$ with everything over a common denominator.\n\n{\\color{blue}\n\\begin{verbatim}\nrationalize(1/a + 1/b + 1/2)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{2a+ab+2b}{2ab}$\n\n\\bigskip\n\\noindent\nNote:\n\\verb$rationalize$\nreturns an unexpanded expression.\nIf the result is assigned to a symbol, evaluating the symbol will expand the result.\nUse\n\\verb$binding$\nto retrieve the unexpanded expression.\n\n{\\color{blue}\n\\begin{verbatim}\nf = rationalize(1/a + 1/b + 1/2)\nbinding(f)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{2a+ab+2b}{2ab}$\n\n\\subsection*{real($z$)}\n\nReturns the real part of complex $z$.\n\n{\\color{blue}\n\\begin{verbatim}\nreal(2 - 3i)\n\\end{verbatim}\n}\n\n\\noindent\n2\n\n\\subsection*{rect($z$)}\n\nReturns complex $z$ in rectangular form.\n\n{\\color{blue}\n\\begin{verbatim}\nrect(exp(i x))\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\cos(x)+i\\sin(x)$\n\n\\subsection*{run({\\it file})}\n\nRun script {\\it file}.\nUseful for importing function libraries.\n\n{\\color{blue}\n\\begin{verbatim}\nrun(\"Downloads/EVA.txt\")\n\\end{verbatim}\n}\n\n\\noindent\nNote: {\\it file} must be in the Downloads folder due to security requirements for apps distributed on the Mac App Store.\n\n\\subsection*{simplify($x$)}\n\nReturns expression $x$ in a simpler form.\n\n{\\color{blue}\n\\begin{verbatim}\nsimplify(sin(x)^2 + cos(x)^2)\n\\end{verbatim}\n}\n\n\\noindent\n1\n\n\\subsection*{sin($x$)}\n\nReturns the sine of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nsin(pi/4)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle \\frac{1}{2^{1/2}}$\n\n\\subsection*{sinh($x$)}\n\nReturns the hyperbolic sine of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\ncircexp(sinh(x))\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle -\\tfrac{1}{2}\\exp(-x)+\\tfrac{1}{2}\\exp(x)$\n\n\\subsection*{sqrt($x$)}\n\nReturns the square root of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nsqrt(10!)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle 720\\; 7^{1/2}$\n\n\\subsection*{stop}\n\nIn a script, it does what it says.\n\n\\subsection*{sum($i,j,k,f$)}\n\nFor $i$ equals $j$ through $k$ evaluate $f$.\nReturns the sum of all $f$.\n\n{\\color{blue}\n\\begin{verbatim}\nsum(j,1,5,x^j)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle x^5+x^4+x^3+x^2+x$\n\n\\bigskip\n\\noindent\nNote: The original value of $i$ is restored after {\\tt sum} completes.\nIf symbol {\\tt i} is used for index variable $i$\nthen the imaginary unit is overridden in the scope of {\\tt sum}.\n\n\\subsection*{tan($x$)}\n\nReturns the tangent of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\nsimplify(tan(x) - sin(x)/cos(x))\n\\end{verbatim}\n}\n\n\\noindent\n0\n\n\\subsection*{tanh($x$)}\n\nReturns the hyperbolic tangent of $x$.\n\n{\\color{blue}\n\\begin{verbatim}\ncircexp(tanh(x))\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle -\\frac{1}{\\exp(2x)+1}+\\frac{\\exp(2x)}{\\exp(2x)+1}$\n\n\\subsection*{test($a,b,c,d,\\ldots$)}\n\nIf argument $a$ is true (nonzero) then $b$ is returned, else if $c$ is true then $d$ is returned, etc.\nIf the number of arguments is odd then the final argument is returned if all else fails.\nExpressions can include the relational operators\n\\verb$=$,\n\\verb$==$,\n\\verb$<$,\n\\verb$<=$,\n\\verb$>$,\n\\verb$>=$.\nUse the\n\\verb$not$\nfunction to test for inequality.\n(The equality operator\n\\verb$==$\nis available for contexts in which\n\\verb$=$\nis the assignment operator.)\n\n{\\color{blue}\n\\begin{verbatim}\nA = 1\nB = 1\ntest(A=B,\"yes\",\"no\")\n\\end{verbatim}\n}\n\n\\noindent\nyes\n\n\\subsection*{trace}\n\nSet {\\tt trace=1} in a script to print the script as it is evaluated.\nUseful for debugging.\n\n{\\color{blue}\n\\begin{verbatim}\ntrace = 1\n\\end{verbatim}\n}\n\n\\noindent\nNote:\nThe\n\\verb$contract$\nfunction is used to obtain the trace of a matrix.\n\n\\subsection*{transpose($a,i,j$)}\n\nReturns the transpose of tensor $a$ with respect to indices $i$ and $j$.\nIf $i$ and $j$ are omitted then 1 and 2 are used.\nHence a matrix can be transposed with a single argument.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\ntranspose(A)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\n\\begin{bmatrix}\na & c\\\\\nb & d\n\\end{bmatrix}\n$\n\n\\bigskip\n\\noindent\nNote:\nThe argument list can be extended for multiple transpose operations.\nThe arguments are evaluated from left to right.\nFor example,\n\\verb$transpose(A,1,2,2,3)$\nis equivalent to\n\\verb$transpose(transpose(A,1,2),2,3)$.\n\n\\subsection*{unit($n$)}\n\nReturns an $n$ by $n$ identity matrix.\n\n{\\color{blue}\n\\begin{verbatim}\nunit(3)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\n\\begin{bmatrix}\n1 & 0 & 0\\\\\n0 & 1 & 0\\\\\n0 & 0 & 1\n\\end{bmatrix}\n$\n\n\\subsection*{zero($i,j,\\ldots$)}\n\nReturns a null tensor with dimensions $i$, $j$, etc.\nUseful for creating a tensor and then setting component values.\n\n{\\color{blue}\n\\begin{verbatim}\nA = zero(3,3)\nfor(k,1,3,A[k,k]=k)\nA\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle\nA=\n\\begin{bmatrix}\n1 & 0 & 0\\\\\n0 & 2 & 0\\\\\n0 & 0 & 3\n\\end{bmatrix}\n$\n", "meta": {"hexsha": "2eb98a62a1e9b6b04f97fcf20db4d03c3363260a", "size": 18366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/help.tex", "max_stars_repo_name": "DazzlingOkami/eigenmath", "max_stars_repo_head_hexsha": "d46e595598947e21598900aa7321244b89b3a67d", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/help.tex", "max_issues_repo_name": "DazzlingOkami/eigenmath", "max_issues_repo_head_hexsha": "d46e595598947e21598900aa7321244b89b3a67d", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/help.tex", "max_forks_repo_name": "DazzlingOkami/eigenmath", "max_forks_repo_head_hexsha": "d46e595598947e21598900aa7321244b89b3a67d", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.2668329177, "max_line_length": 120, "alphanum_fraction": 0.6751061745, "num_tokens": 6233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.9059898140375993, "lm_q1q2_score": 0.8499308043730694}}
{"text": "\n\\subsection{Prime numbers and composite numbers}\n\n\\subsubsection{Definition}\n\nA prime number is a number which does not have any divisors other than \\(1\\) and itself.\n\nBy convention we do not refer to \\(0\\) or \\(1\\) as prime numbers.\n\n\\subsubsection{Identifying prime numbers}\n\nDivisors must be smaller than the number. As a result it is easy to identify early prime numbers, as we can try to divide by all preceding numbers.\n\n\\subsubsection{Examples of prime numbers}\n\n\\([2, 3 5, 7, 11, 13,...]\\)\n\n\\subsubsection{Composite numbers}\n\nComposite numbers are numbers that are  made up through the multiplication of other numbers.\n\nThey are not prime.\n\n", "meta": {"hexsha": "2b70259f41df131fda1e4db6fdb0898b014c330b", "size": 650, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/primes/01-01-Primes.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/primes/01-01-Primes.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/primes/01-01-Primes.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0833333333, "max_line_length": 147, "alphanum_fraction": 0.7569230769, "num_tokens": 153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966747198242, "lm_q2_score": 0.8976952914230971, "lm_q1q2_score": 0.8497553777727472}}
{"text": "\n\\subsection{Finite state Markov chains}\n\n\\subsubsection{Transition matrices}\n\nThis shows the probability for moving between discrete states.\n\nWe can show the probability of being in a state by multiplying the vector state by the transition matrix.\n\n\\(Mv\\)\n\n\\subsubsection{Time-homogenous Markov chains}\n\nFor time-homogenous Markov chains the transition matrix is independent of time.\n\nFor these we can calculate the probability of being in any given state in the future:\n\n\\(M^nv\\)\n\nThis becomes independent of v as we tend to infinity. The initial starting state does not matter for long term probabilities.\n\nHow to find steady state probability?\n\n\\(Mv=v\\)\n\nThe eigenvectors! With associated eigenvector \\(1\\). There is only one eigenvector. We can find it by iteratively multiplying any vector by \\(M\\).\n\n", "meta": {"hexsha": "2ae715fd209741036f3be9d1f65ac981e6a875c9", "size": 807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stochasticMarkov/02-01-MC_finite.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/stochasticMarkov/02-01-MC_finite.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/stochasticMarkov/02-01-MC_finite.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8214285714, "max_line_length": 146, "alphanum_fraction": 0.7843866171, "num_tokens": 176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693645535724, "lm_q2_score": 0.8947894639983208, "lm_q1q2_score": 0.849754141684517}}
{"text": "\n\\subsection{Herfindahl\u2013Hirschman Index (HHI)}\n\nThe index is the sum of each firm\u2019s market share squared.\n\nFor a monopolist this is \\(1\\), for a completely competitive market it is \\(0\\), or \\(\\dfrac{1}{n}\\).\n\n\\(H=\\sum_{i=1}^ns^2_i\\)\n\nTo normalise this between \\(0\\) and \\(1\\) we can use:\n\n\\(H*=\\dfrac{H-\\dfrac{1}{n}}{1-\\dfrac{1}{n}}\\)\n\n", "meta": {"hexsha": "2106bad0ed48bfebde55fae8bb0bfa49347019a1", "size": 337, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/econometricsAggregate/06-01-HHI.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/econometricsAggregate/06-01-HHI.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/econometricsAggregate/06-01-HHI.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0714285714, "max_line_length": 101, "alphanum_fraction": 0.6439169139, "num_tokens": 121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.957277806109987, "lm_q2_score": 0.8872045899891118, "lm_q1q2_score": 0.8493012634754875}}
{"text": "\n\\subsection{Green's theorem}\n\nWe have a curve \\(C\\) on a plane.\n\nInside this is region \\(D\\).\n\nWe have two functions: \\(L(x,y)\\) and \\(M(x,y)\\) defined on the region and curve.\n\n\\(\\oint_C (L dx + M dy)=\\int \\int_D (\\dfrac{\\delta M}{\\delta x}-\\dfrac{\\delta L}{\\delta y})dx dy\\)\n\n\n", "meta": {"hexsha": "e961406395d34b6b5dc65789f3e547dc89cd1e7c", "size": 280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/multiScalarIntegration/01-05-greenTheorem.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/multiScalarIntegration/01-05-greenTheorem.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/multiScalarIntegration/01-05-greenTheorem.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.5384615385, "max_line_length": 98, "alphanum_fraction": 0.6214285714, "num_tokens": 94, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9658995742876885, "lm_q2_score": 0.8791467675095294, "lm_q1q2_score": 0.8491674884738518}}
{"text": "\n\\subsection{Multinomial distribution}\n\nThe mass function for the binomial case is:\n\n\\(f(x)=\\dfrac{n!}{x!(n-x)!}p^k(1-p)^{n-k}\\)\n\n\\subsection{The multinomial distribution}\n\nThis generalises the binomial distribution where there are more than \\(2\\) outcomes.\n\n\\(f(x_1,...,x_n)=\\dfrac{n!}{\\prod_i x_i!}\\prod_i p_i^{x_i}\\)\n\n", "meta": {"hexsha": "246b1e4c2d206ed6dd6fb18ff29ab0dda76ad79a", "size": 321, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/distributionsDiscreteRepeated/01-02-multinomial.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/distributionsDiscreteRepeated/01-02-multinomial.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/distributionsDiscreteRepeated/01-02-multinomial.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.9285714286, "max_line_length": 84, "alphanum_fraction": 0.6947040498, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9658995752693051, "lm_q2_score": 0.8791467611766711, "lm_q1q2_score": 0.8491674832199319}}
{"text": "\\section{Page Rank}\n\t\\textbf{Page Rank} is a link analysis algorithm based on the Web graph (pages as nodes and hyper-links as edges), taking the rank value to indicate an importance of a particular page, which is defined recursively and\tdepends on the number of all pages that link to it (in-links).\n\n\t\\subsection{The Simplest Model}\n\tThe page in web can be regard as a node $A$ in a digraph $\\mathcal G=(\\mathcal V,\\mathcal E)$. If the page $A$ have a hyper-link to page $B$, then there is a edge $A\\rightarrow B$ in $\\mathcal E$. For example, the web show in Figure \\eqref{fig:fournodesweb} can be represented by a digraph $\\mathcal G=(\\mathcal V,\\mathcal E)$ with\n\t\\begin{gather*}\n\t\\mathcal{V} =\\{A,B,C,D\\}\\\\\n\t\\mathcal{E} =\\{A\\rightarrow B, A\\rightarrow C,A\\rightarrow D,B\\rightarrow A,\\\\ B\\rightarrow D,C\\rightarrow A,D\\rightarrow B,D\\rightarrow C\\}\n\t\\end{gather*}\n\t\\begin{figure}[h]\n\t\t\\centering\n\t\t\\includegraphics[width=0.7\\linewidth]{fournodesweb}\n\t\t\\caption{A web witch has 4 nodes}\n\t\t\\label{fig:fournodesweb}\n\t\\end{figure}\n\t\n\tSuppose there is a person Jack who is suffering the Internet, and at timing $t$, he is browsing page $A$. When he wants to leave page $A$, he will randomly click a hyper-link in page $A$ and go to browse next page and the possibility of clicking each page is the same. As an example in Figure \\eqref{fig:fournodesweb}, each possibility from $A$ to $B,C,D$ are $\\dfrac 13$. (If the page have no out-links, we can think it have a out-link to itself.) If we do that for each nodes, then we will have a transform matrix $M(\\mathcal G)$. The transform matrix of the \\eqref{fig:fournodesweb} is\n\t\\begin{equation*}\n\t\t\\begin{matrix}\n\t\t to\\backslash from&A&B&C&D\\\\\n\t\tA& &1/2 &1 &\\\\\n\t\tB&1/3 & & &1/2\\\\\n\t\tC&1/3 & & &1/2\\\\\n\t\tD&1/3 &1/2 & &\n\t\t\\end{matrix}\n\t\\end{equation*}\n\ti.e. \n\t\\begin{equation*}\n\t\\mathbf M=\\mathbf M(\\mathcal{G})=\n\t\\begin{pmatrix}\n\t &1/2 &1 &\\\\\n1/3 & & &1/2\\\\\n1/3 & & &1/2\\\\\n1/3 &1/2 & &\n\t\\end{pmatrix}.\n\t\\end{equation*}\n\t\n\tNow, we assume there are a large number of people, and at the timing $t=0$, each page has the same amount of people browsing it, i.e. for every page there are $\\dfrac 1{|\\mathcal V|}$ people browsing it at timing $t=0$. We use a vector $\\mathbf v_0 =(\\dfrac 1{|\\mathcal V|},...,\\dfrac 1{|\\mathcal V|})^T$ to represent the initial state. \n\t\n\tIn the next timing $t=1$, every one randomly clicking a hyper-link in the page which he or she is browsing. Then the distribution of the people at $t=1$ is $$\\mathbf v_1=\\mathbf M\\mathbf v_0.$$ By parity of reasoning, we can obtain the distribution of the people at $t=\\mu$ is  $$\\mathbf v_\\mu=\\mathbf M^\\mu\\mathbf v_0.$$\n\t\n\tWe can regard this process is a Markov process, so the convergence of $\\mathbf v_\\mu$ is equivalent to the digraph $\\mathcal G$ is \\textbf{strongly connected}. So we have the following theorem:\n\t\n\t\n\t\\begin{theorem}\n\t\t $\\mathbf v_\\mu$ is convergent $\\Leftrightarrow$ $\\mathcal G$ is strongly connected\n\t\\end{theorem}\n\tIf we get the convergence result $\\mathbf v_\\infty$, the $i$th component $v_{\\infty i}$ measures the importance of the $i$th page. Because the bigger $v_{\\infty i}$ is, the more people will browse this page.\n\tBesides, by the theory of power method, we know if $\\mathbf v_\\mu$ is convergent, then the $\\mathbf v_\\infty$ is the corresponding eigenvector of the max eigenvalue of $\\mathbf M$. \n\t\\subsection{More General Models}\n\tHowever the $\\mathcal G$ of a real Internet web is impossible to be strongly connected, because there is always some pages have no out-links. Besides, if a page only have the out-link to itself, the result $\\|\\mathbf v_\\infty\\|$ may have no use value.\n\t\n\tNow we suppose Jack randomly click a hyper-link in the page with probability $\\alpha$ or randomly input a new URL of a page with probability $1-\\alpha$, so the iteration relation becomes:\n\t\\begin{equation}\\label{alpha}\n\t\\mathbf v_{\\mu+1}=(1-\\alpha)\\mathbf 1 +\\alpha \\mathbf M \\mathbf v_\\mu\n\t\\end{equation}\n\tBecause of $\\|\\mathbf v_0\\|_1=1$ and the sum of each column of $\\mathbf M$ is equal to 1, we can obtain $\\|\\mathbf v_\\mu\\|_1=1$ for any $\\mu$. And the spectral radius of $\\alpha \\mathbf M$ is $$\\rho(\\alpha \\mathbf M)=\\alpha\\rho(\\mathbf M)\\leq\\alpha ||\\mathbf M||_1=\\alpha <1.$$ So the iteration \\eqref{alpha} must be convergent, and $\\mathbf v_\\infty$ satisfy$$ \t\\mathbf v_{\\infty}=(1-\\alpha)\\mathbf 1 +\\alpha \\mathbf M \\mathbf v_\\infty.$$ \n\ti.e.\n\t$$\\mathbf v_\\infty = (1-\\alpha)(1-\\alpha \\mathbf M)^{-1}\\mathbf 1 $$\n", "meta": {"hexsha": "9f97a2d4eae3007f1a430360fcaf69f0cc815539", "size": 4455, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/PageRank.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/PageRank.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/PageRank.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.25, "max_line_length": 589, "alphanum_fraction": 0.7032547699, "num_tokens": 1445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.8962513662057089, "lm_q1q2_score": 0.8490915547164711}}
{"text": "\\section{Physical Interpretations of the Derivative}\r\nAs we've seen, the idea derivative is fundamentally about continuous change.\r\nThis idea makes the derivative very useful for describing physical situations.\r\n\r\n\\begin{example}\r\n\t\tFind the rate of change of the area of a circle with respect to its radius in meters.\r\n\t\tFind the rate of change of the volume of a sphere with respect to its radius in meters.\r\n\t\tWhat are these quantities (with appropriate units) when $r=5\\text{m}$?\r\n\\end{example}\r\n\\begin{answer}\r\n\tStarting with the area of a circle,\r\n\t\\begin{align*}\r\n\t\tA &= \\pi r^2\r\n\t\t\\dd{A}{r} = 2\\pi r.\r\n\t\\end{align*}\r\n\t\r\n\tYou might recognize this as the formula for the circumference of a circle.\\\\\r\n\t\r\n\tStarting with the volume of a sphere,\r\n\t\\begin{align*}\r\n\t\tV &= \\frac{4}{3}\\pi r^3 \\\\\r\n\t\t\\dd{V}{r} &= 4\\pi r^2.\r\n\t\\end{align*}\r\n\t\r\n\tYou might recognize this as the formula for the surface area of a sphere.\\\\\r\n\t\r\n\tWhen $r=5\\text{m}$,\r\n\t\\begin{align*}\r\n\t\t\\dd{A}{r}\\biggr\\rvert_{r=5\\text{m}} &= 2\\pi\\left(5\\text{m}\\right) = 10\\pi\\text{m}. \\\\\r\n\t\t\\dd{V}{r}\\biggr\\rvert_{r=5\\text{m}} &= 4\\pi\\left(5\\text{m}\\right)^2 = 100\\pi\\text{m}^2.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsection{Displacement, Velocity, and Acceleration}\r\nIf we have an object whose position is determined by a single variable, like time $t$, then we can model the position as a function.\r\n\\begin{equation*}\r\n\ts = f(t).\r\n\\end{equation*}\r\nThe displacement over some interval of length $\\Delta t$, would be\r\n\\begin{equation*}\r\n\t\\Delta s = f(t + \\Delta t) - f(t).\r\n\\end{equation*}\r\nThe average velocity over this interval would be\r\n\\begin{equation*}\r\n\t\\bar{v} = \\frac{f(t + \\Delta t) - f(t)}{\\Delta t}.\r\n\\end{equation*}\r\nAs $\\Delta t$ approaches 0, we see that $\\bar{v}$ is exactly the definition of the derivative of $f$ with respect to $t$: the instantaneous velocity.\r\n\\begin{equation*}\r\n\tv(t) = \\dd{s}{t} = \\lim_{\\Delta t \\to 0}{\\frac{f(t + \\Delta t) - f(t)}{\\Delta t}}.\r\n\\end{equation*}\r\nWe can go through the same steps to derive that instantaneous acceleration is the derivative of instantaneous velocity with respect to $t$.\r\n\\begin{equation*}\r\n\ta(t) = \\dd{v}{t} = \\dd{{}^2s}{t^2} = \\lim_{\\Delta t \\to 0}{\\frac{v(t + \\Delta t) - v(t)}{\\Delta t}}.\r\n\\end{equation*}\r\nAlthough in everyday language we might use the terms speed and velocity interchangeably, speed is defined as the absolute value of velocity, meaning it is a scalar quantity while velocity is a vector quantity.\r\n\\begin{equation*}\r\n\t\\text{Speed} = \\abs{v(t)} = \\biggr\\lvert \\dd{s}{t} \\biggr\\rvert.\r\n\\end{equation*}\r\n\r\n\r\nModeling the motion of free-falling bodies was one of the earliest motivations for discovering calculus.\r\nThrough experiments and applications of physics theory, we know that the height of a falling body when dropped from initial height $h_0$ meters is modeled by\r\n\\begin{equation*}\r\n\ts(t) = h_0 - \\frac{1}{2}gt^2,\r\n\\end{equation*}\r\nwhere $t$ is the time in seconds since the object was released and $g = 9.81m/s^2$ is the acceleration due to gravity near Earth.\r\n\r\n\\begin{example}\r\n\tA ball is dropped from an initial height of 100 meters.\r\n\tHow long does it take for the ball to hit the ground?\r\n\tWhat speed is the ball traveling when it hits the ground?\r\n\\end{example}\r\n\\begin{answer}\r\n\tIn this case, $h_0 = 100\\text{m}$.\r\n\tSo,\r\n\t\\begin{equation*}\r\n\t\ts(t) = 100\\text{m} - \\frac{1}{2}gt^2.\r\n\t\\end{equation*}\r\n\t\r\n\tWe want to solve for $t$ where $s(t)=0$.\r\n\t\\begin{equation*}\r\n\t\tt = \\sqrt{\\frac{200\\text{m}}{g}} \\approx 4.515\\text{s}.\r\n\t\\end{equation*}\r\n\t\r\n\tWe take take the derivative of $s$ with respect to $t$ and then take the absolute value to get the speed.\r\n\t\\begin{align*}\r\n\t\tv(t) &= \\dd{}{t}s(t) = -gt. \\\\\r\n\t\t\\text{Speed}(t) &= \\abs{v(t)} = gt.\r\n\t\\end{align*}\r\n\t\r\n\tPlugging in the time we got when the ball hits the ground,\r\n\t\\begin{equation*}\r\n\t\t\\text{Speed}_{\\text{Ground}} \\approx g(4.515\\text{s}) \\approx 44.294\\text{m/s}.\r\n\t\\end{equation*}\r\n\\end{answer}", "meta": {"hexsha": "fe4b253dcc1898e0a2fc751a5385940120f0dc65", "size": 3925, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/physical_interpretations_derivative.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/derivatives/physical_interpretations_derivative.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/derivatives/physical_interpretations_derivative.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 41.3157894737, "max_line_length": 210, "alphanum_fraction": 0.6754140127, "num_tokens": 1266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322216, "lm_q2_score": 0.8976952886860979, "lm_q1q2_score": 0.8490413470138782}}
{"text": "\\section{Elementary Equations and Elementary Matrices}\r\n\\begin{definition}\r\n    An elementary column operation on an $m\\times n$ matrix $A$ are one of the followings:\\\\\r\n    (i) Swap columns $i,j$ with $i\\neq j$.\\\\\r\n    (ii) Multiply the entire column $i$ by $\\lambda\\in F\\setminus\\{0\\}$.\\\\\r\n    (iii) Add $\\lambda$ times column $i$ to column $j$ where $\\lambda\\in F$.\r\n\\end{definition}\r\nWe can do row operations in a analogous (transposed) way.\r\nSomething remarkable is that these operations are invertible.\r\nInstead of find the inverses one-by-one, we realise these operations via the action of elementary matrices.\r\nLet $E_{ij}$ be the matrix with $1$ on the $i,j$ entry and zero anywhere else, we have:\r\n\\begin{definition}[Elementary Matrices]\r\n    The elementary matrices are $T_{ij}=I-E_{ii}-E_{jj}+E_{ij}+E_{ji}$ for $i\\neq j$, $M_{i,\\lambda}=I+(\\lambda-1)E_{ij}$ for $\\lambda\\neq 0$ and $C_{i,j,\\lambda}=I+\\lambda E_{ij}$.\r\n\\end{definition}\r\nThen, we easily see that $T_{ij}$ corresponds to column (row) operation (i), $M_{i,\\lambda}$ to operation (ii) and $C_{i,j,\\lambda}$ to operation (iii) via the operation of multiplying $A$ with the correspondinng matrix from the right (left).\r\n\\begin{example}\r\n    $$\\begin{pmatrix}\r\n        1&2\\\\\r\n        3&4\r\n    \\end{pmatrix}\\begin{pmatrix}\r\n        0&1\\\\\r\n        1&0\r\n    \\end{pmatrix}=\\begin{pmatrix}\r\n        2&1\\\\\r\n        4&3\r\n    \\end{pmatrix}$$\r\n\\end{example}\r\n\\begin{proof}[Constructive Proof of Proposition \\ref{eqv_form}]\r\n    It suffices to show that we can get from any matrix to\r\n    $$\\left( \\begin{array}{c|c}\r\n        I_r&0\\\\\r\n        \\hline\r\n        0&0\r\n    \\end{array} \\right)$$\r\n    via elementary column and row operations.\r\n    Start with a matrix $A$.\r\n    If $A=0$ then we are done.\r\n    Otherwise pick $a_{ij}=\\lambda\\neq 0$ and swap rows $i$ and $1$ and then columns $j$ and $1$, after which $\\lambda$ is at position $1,1$.\r\n    Then multiply column $1$ by $\\lambda^{-1}$.\r\n    So we get $1$ at position $1,1$.\r\n    Now we clean up row $1$ and column $1$ via operation (iii) (both row and column).\r\n    Afterwards we can perform the same procedure on the submatrix by removing the first row and column.\r\n    By induction we can get the desired form at the end.\r\n\\end{proof}\r\nThere are a few variations on these row and column operations.\r\nThe first one is Gauss' pivot algorithm.\r\nIf one use only row operations, then one will reach the ``row echelon form'' (which we will define later) in the following way:\r\nAssume $a_{i1}\\neq 0$ for some $i$.\r\nOtherwise just move on by deleting the first zero columns.\r\nThen swap rows $i$ and $1$ and divide row $1$ by $\\lambda=a_{i1}$ to get $1$ at position $1,1$ and use (iii) to clean up the first column.\r\nAnd one can move on with the same method to the submatrix removing the first row and first column.\r\nDo this repeatedly and at the end we can get a matrix satisfying:\\\\\r\n1. For any $i$ here exists $k(i)\\ge i$ such that $a_{ij}=0$ for any $j<k(i)$.\\\\\r\n2. $k(i)$ is increasing in $i$.\\\\\r\n3. Row $k(i)$ equals $e_{k(i)}$.\\\\\r\nAnd matrices satisfying these conditions are called matrices in row echelon form.\r\nNote that the operations above is exactly what we will get when solving a linear system of equations.\r\nSo this can be an algorithm of doing that, which is now known as Gauss' pivot algorithm (or Gaussian elimination).\\\\\r\nAnother variation is the following:\r\n\\begin{lemma}\r\n    We can obtain the identity matrix from any invertible square matrix via column operations only.\r\n\\end{lemma}\r\nBy transpose, we can replace column operations by row operations.\r\n\\begin{proof}\r\n    We argue by induction on the $k$ where we can guarantee to transform $A$ to the form\r\n    $$\\begin{pmatrix}\r\n        I_k&0\\\\\r\n        \\ast&\\ast\r\n    \\end{pmatrix}$$\r\n    The initial case is obvious.\r\n    Suppose we can do this for some $k$, we shall show that we can do this for $k+1$.\r\n    Now there must be some $j>k$ such that $a_{k+1,j}=\\lambda\\neq0$.\r\n    Otherwise the vector $e_{k+1}$ is not in the span of the column vectors of $A$, contradiction.\r\n    So we swap columns $k+1$ and $j$ and then divide column $k+1$ by $\\lambda$.\r\n    This gets us $1$ at position $k+1,k+1$.\r\n    Then we can clean up the row $k+1$ by this $1$, which completes the induction process.\r\n\\end{proof}\r\nThis immediately provides an algorithm (a quite cost-effective one) for computing the inverse.\r\nAs one can see, this algorithm is analogous to the algorithm of solving a nonsingular linear system.\r\nAlso,\r\n\\begin{proposition}\r\n    Any invertible matrix is a product of elementary matrices.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Writing the operations in the preceding lemma as a product of elementary matrices representing the operations gives the inverse of that matrix.\r\n    But any invertible matrix is the inverse of its own inverse.\r\n\\end{proof}", "meta": {"hexsha": "95d897124399c08f0fe67d18f19e9813cfb590c9", "size": 4843, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/ele.tex", "max_stars_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_stars_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "7/ele.tex", "max_issues_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_issues_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "7/ele.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.6666666667, "max_line_length": 243, "alphanum_fraction": 0.6855255007, "num_tokens": 1362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.908617906830944, "lm_q1q2_score": 0.8490081734209783}}
{"text": "\\section{Related Rates}\r\nIn related rates problems, we generally have two related functions and want to know and answer questions about the rate of change of one function given that we know the rate of change of the other. The same problem solving steps as in modeling and optimization apply, but we'll usually be taking derivatives using implicit differentiation with respect to some variable like time.\r\n\r\n\\begin{example}\r\n\tLet $A$ be the area of a square with side length $x$.\r\n\tAssume that $x$ varies with time.\r\n\tHow are $\\dd{A}{t}$ and $\\dd{x}{t}$ related?\r\n\tAt a certain instant, the sides are 3 feet and growing at a rate of 2 feet per minute.\r\n\tHow quickly is the area changing at this instant?\r\n\\end{example}\r\n\\begin{answer}\r\n\tStarting with the area of the square and implicitly differentiating with respect to $t$,\r\n\t\\begin{align*}\r\n\t\tA &= x^2 \\\\\r\n\t\t\\dd{A}{t} = 2x\\dd{x}{t}.\r\n\t\\end{align*}\r\n\t\r\n\tWhen $x=3\\text{ft}$ and $\\dd{x}{t}=3\\text{ft/min}$,\r\n\t\\begin{equation*}\r\n\t\t\\dd{A}{t} = 2(3\\text{ft})(3\\text{ft/min}) = 12\\text{ft$^2$/min}.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tThe top of a 13 foot ladder propped against a vertical wall begins falling towards the ground at 12ft/s.\r\n\tWhen the top of the ladder is 5 feet off the ground, how quickly is the bottom of the ladder moving away from the wall?\r\n\tHow is the angle between the ladder and the ground changing?\r\n\\end{example}\r\n\\begin{answer}\r\n\tLet $h$ be the height of the top of the ladder of the ground.\r\n\tThen $\\dd{h}{t} = -12\\text{ft/s}$.\r\n\tLet $b$ the the distance from the base of the ladder to the wall.\r\n\tWe can relate $b$ and $h$ using the Pythagorean Theorem, where the 13-foot long ladder is the hypotenuse.\r\n\t\\begin{equation*}\r\n\t\tb^2 + h^2 = 13^2.\r\n\t\\end{equation*}\r\n\t\r\n\tWe can also use this relationship to see that when $h=5\\text{ft}$, $b=12\\text{ft}$.\r\n\tImplicitly differentiating,\r\n\t\\begin{equation*}\r\n\t\t2b\\dd{b}{t} + 2h\\dd{h}{t} = 0.\r\n\t\\end{equation*}\r\n\t\r\n\tPlugging in what we know and solving for $\\dd{b}{t}$,\r\n\t\\begin{align*}\r\n\t\t2(12\\text{ft})\\dd{b}{t} + 2(5\\text{ft})(-12\\text{ft/s}) &= 0 \\\\\r\n\t\t24\\text{ft}\\dd{b}{t} &= 120\\text{ft$^2$/s} \\\\\r\n\t\t\\dd{b}{t} &= 5\\text{ft/s}.\r\n\t\\end{align*}\r\n\t\r\n\tSo, the base of the ladder is moving away from the wall at a rate of 5ft/s.\r\n\tLet $\\theta$ be the angle between the ladder and the ground.\r\n\tWe can use $\\sin$ to relate $\\theta$ to $b$.\r\n\t\\begin{equation*}\r\n\t\t13\\sin{\\theta} = b.\r\n\t\\end{equation*}\r\n\t\r\n\tImplicitly differentiating,\r\n\t\\begin{equation*}\r\n\t\t13\\text{ft}\\cos{(\\theta)}\\dd{\\theta}{t} = \\dd{b}{t}.\r\n\t\\end{equation*}\r\n\t\r\n\tWhen $\\cos$ is adjacent divided by hypotenuse, so $\\cos{\\theta} = 12/13$.\r\n\tPlugging in what we know and solving for $\\dd{\\theta}{t}$,\r\n\t\\begin{align*}\r\n\t\t13\\text{ft}(12/13)\\dd{\\theta}{t} &= -12\\text{ft/s} \\\\\r\n\t\t\\dd{\\theta}{t} &= -1\\text{/s}.\r\n\t\\end{align*}\r\n\t\r\n\tSo, the angle between the ladder and ground is decreasing at at rate of 1 rad/s.\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tGrain is is poured at a rate of 10ft$^3$/min and falls into a cone-shaped pile whose bottom radius is half its altitude.\r\n\tHow fast will the circumference of the base be increasing when the pile is 8 ft tall?\r\n\\end{example}\r\n\\begin{answer}\r\n\tLet $h$ the the altitude of the cone.\r\n\tAt the instant we care about $h=8\\text{ft}$.\r\n\tLet $r$ be the bottom radius of the cone.\r\n\tAt the instant we care about, $r=h/2=4\\text{ft}$.\r\n\tLet $V$ be the volume of the cone.\r\n\tWe know that $\\dd{V}{t}=10\\text{ft$^3$/s}$.\r\n\tWe can relate these three quantites using the formula for the volume of a cone.\r\n\t\\begin{equation*}\r\n\t\tV = \\frac{1}{3}\\pi r^2 h.\r\n\t\\end{equation*}\r\n\t\r\n\tSince we know that $2r = h$, we can simplify to get rid of $h$.\r\n\t\\begin{equation*}\r\n\t\tV = \\frac{2}{3}\\pi r^3\r\n\t\\end{equation*} \r\n\t\r\n\tImplicitly differentiating,\r\n\t\\begin{equation*}\r\n\t\t\\dd{V}{t} = 2\\pi r^2 \\dd{r}{t}.\r\n\t\\end{equation*}\r\n\t\r\n\tWe know the formula for the circumference $C$ of the circular base.\r\n\t\\begin{equation*}\r\n\t\tC = 2\\pi r.\r\n\t\\end{equation*}\r\n\t\r\n\tImplicitly differentiating,\r\n\t\\begin{equation*}\r\n\t\t\\dd{C}{t} = 2\\pi \\dd{r}{t}.\r\n\t\\end{equation*}\r\n\t\r\n\tWe can substitute into our equation involving $\\dd{V}{t}$.\r\n\t\\begin{equation*}\r\n\t\t\\dd{V}{t} = r^2\\dd{C}{t}.\r\n\t\\end{equation*}\r\n\t\r\n\tPlugging in what we know,\r\n\t\\begin{align*}\r\n\t\t10\\text{ft}^3\\text{/s} &= (4\\text{ft})^2\\dd{C}{t} \\\\\r\n\t\t\\dd{C}{t} &= \\frac{5}{8}\\text{ft/s}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n", "meta": {"hexsha": "2417005645413335fef098b54a85b8e695289b87", "size": 4375, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/applications_derivative/related_rates.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/applications_derivative/related_rates.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/applications_derivative/related_rates.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 36.4583333333, "max_line_length": 380, "alphanum_fraction": 0.6521142857, "num_tokens": 1536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.9086178870347122, "lm_q1q2_score": 0.8490081632232792}}
{"text": "\\chapter{Linear Maps, Kernals and Range}\n\n\\begin{definition}\n\tLet $U$ and $V$ be vector spaces over the same field $F$. A mapping $T:U \\rightarrow V$ is linear if \t$ \\forall u_1, u_2 \\in U, \\forall \\lambda \\in F$ \n\t\\begin{center}\n \t\t$T(u_1 + u_2) = T(u_1) + T(u_2)$\\\\ \n \t\t$T(\\lambda u_1) = \\lambda T(u_1)$\n\t\\end{center}\n\t\n\\end{definition}\n\nThe set of all linear mappings from $U \\rightarrow V$ is denoted by $\\mathcal{L}(U,V)$. If $U=V$, then linear mappings are denoted by $\\mathcal{L}(U)$, which is a set of linear mappings from a set onto itself. \\\\ \n\n\\textbf{Examples}\n\\begin{itemize}\n\t\\item $T: \\mathcal{C}[a, b] \\rightarrow \\Re$, $f \\rightarrow \\int_{a}^{b} f(x) dx$. Integration is linear operator since it does not matter whether you add two functions and then integrate or vice versa. Also, we can pull out scalar multiples out of the integrals. \n\t\\item $D: \\mathcal{C}^{\\infty} [a, b] \\rightarrow \\mathcal{C}^{\\infty} [a, b]$, $f \\rightarrow f'$. The derivative of the sum of functions is the same as taking the sum and then derivatves. \\\\\n\\end{itemize}\n\n\\begin{definition}\n\t$T \\in \\mathcal{L}(U, V)$. Then the kernal of $T$ (null space) is defined as : \n\t\\begin{center}\n\t\t$ker(T) := null(T) := \\{u \\in U | Tu = 0\\}$\n\t\\end{center}\n\t\n\\end{definition}\n\n\\begin{proposition}\n\t$ker(T)$ is a subspace of $U$.\n\\end{proposition}\n\n$T$ is injective iff $ker(T) = \\{0\\}$. Means if we take two input points in the input space then they are always mapped to different points in the output space. \nSo 0 is always an element in the kernal since a linear map always maps 0 to 0. Thus the kernal is never empty. The smallest kernal of any vector space is just the 0 vector. \n\n\\begin{definition}\n\tThe range of $T$ (image of $T$) is defined as: \n\t\\begin{center}\n\t\t$range(T) := Image(T) := \\{Tu | u \\in U\\}$\n\t\\end{center}\n\\end{definition}\n\n\\begin{proposition}\n\tThe range is always a subspace of $V$\n\\end{proposition}\n\n$T$ is surjective iff $range(T) = V$\n\n\\begin{definition}\n\t$V' \\subset V$ where $V'$ is any set. The pre-image of $V'$ is defined as: \n\t\\begin{center}\n\t\t$T^{-1} (V') := \\{u \\in U | Tu \\in V'\\}$\n\t\\end{center} \n\\end{definition}\n\n\\begin{proposition}\n\tIf $V' \\subset V$ is a subspace of V, then $T^{-1}(V')$ is a subspace of $U$.\n\\end{proposition}\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=0.5\\textheight]{ch-3-img-1}\n\t\\caption{Kernal and range of a $T: U \\rightarrow V$}\n\\end{figure}\n\nWe can see in the figure above that a part of $U$ which is mapped to 0 is known as the kernal of tha map $T$. The range lives in $V$ and the kernal lives in $U$. \n\n\\begin{theorem}\n\tLet $V$ be finite dimensionalm $W$ be any vector space and $T \\in \\mathcal{L}(V,W)$. Let $u_1,...,u_n$ be a basis of $ker(T) \\subset V$. Let $w_1,...,w_m$ be a basis of the $range(T) \\subset W$. Then $u_1,...,u_n$, $T^{-1}(w_1),...,T^{-1}(w_m)$ forms a basis of $V$. In particular , $dim(V) = dim(ker(T)) + dim(range(T))$\n\\end{theorem}\n\n\\begin{proof}\n\tDenote $T^{-1}(w_1) := z_1,...,T^{-1}(w_m) := z_m$. If $\\{u_1,...u_n,z_1,...z_m\\}$ for a basis of $V$, then they must span the whole space $V$ and be linearly independent. Let's do each step by step. \\\\\n\tStep 1: Prove that $V \\subset span\\{u_1,...u_n,z_1,...z_m\\}$ \\\\ \n\tLet $v \\in V$, and $Tv \\in range(T)$. Since we know the basis of $range(T)$,\n\t\\begin{align*}\n\t\t\\exists \\lambda_1,...,\\lambda_m: Tv &= \\lambda_1 w_1 + ... + \\lambda_m w_m \\\\\n\t\t\t\t\t\t\t\t\t\t\t&= \\lambda_1 T(z_1) + ... + \\lambda_m T(z_m) \\\\\n\t\t\t\t\t\t\t\t\t\t\t&= T(\\lambda_1 z_1) + ... + T(\\lambda_m z_m)\n\t\\end{align*}\n$ \\implies Tv - T(\\lambda_1z_1 + ... + \\lambda_mz_m) = T(v - (\\lambda_1z_1 + ... + \\lambda_mz_m)) =  0$  \\\\\n$\\implies (v - (\\lambda_1z_1 + ... + \\lambda_mz_m)) \\in kernal(T)$ since this vector is mapped to 0 by the linear mapping. Since we also know the basis of the kernal any vector in the kernal can be written as: \n\\begin{align*}\n(v - (\\lambda_1z_1 + ... + \\lambda_mz_m)) &= \\mu_1 u_1 + ... + \\mu_n u_n \\\\ \nv &= \\lambda_1 z_1 + ... + \\lambda_m z_m + \\mu_1 u_1 + ... + \\mu_n u_n\n\\end{align*}\nStep 2 : Prove that $u_1,...,u_n, z_1,...,z_m$ are linearly independent. \\\\ \nAssume that $\\mu_1 u_1 + ... \\mu_n u_n + \\lambda_1 z_1 + ... + \\lambda_m z_m  = 0$ \\\\\nIf these vectors are linearly independent then all the coefficients will simultaneously go to zero. \n\\begin{align*}\n\t\\lambda_1 w_1 + ... + \\lambda_m w_m &= \\lambda_1 T(z_1) + ... + \\lambda_m T(z_m) \\\\\n\t&= \\lambda_1 T(z_1) + ... + \\lambda_m T(z_m) + \\mu_1 T(u_1) + ... + \\mu_n T(u_n) \\\\ \n\t&= T(\\lambda_1 z_1 + ... \\lambda_m z_m + \\mu_1 u_1 + ... + \\mu_n u_n) = T(0) = 0\n\\end{align*}\nWe can add $ \\mu_1 T(u_1) + ... + \\mu_n T(u_n)$ to the expression since it goes to zero by definition of a kernal. Everything inside the operator is zero due to the assumption at the beginning of step 2. \nSince $\\lambda_1 w_1 + ... + \\lambda_m w_m = 0$ and $w_1,...,w_m$ is a basis \n$\\implies \\lambda_1 = ... = \\lambda_m = 0$ \\\\\nNow $\\mu_1 u_1 + ... + \\mu_n u_n = 0$ since we have already proved the other half of the assumption to be zero. Since $u_1,...,u_n$ is the basis of the kernal $\\implies \\mu_1=...\\mu_n=0$.\n\\end{proof}\n\n\\begin{proposition}\n\tLet $T \\in \\mathcal{L}(V, W)$ and $V, W$ be finite dimensional, then the following statements are equivalent.\n\t\\begin{itemize}\n\t\t\\item T is injective\n\t\t\\item T is surjective\n\t\t\\item T is bijective\n\t\\end{itemize} \n\\end{proposition}\n\nThis proposition does not hold in infinite dimensional spaces. \n\n\n\n", "meta": {"hexsha": "0a99a9c39266095e84d97d631f943fd90ba217a1", "size": 5397, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter-3-linearmaps-kernals-range.tex", "max_stars_repo_name": "agupta54/maths-for-ml", "max_stars_repo_head_hexsha": "c5e54f14e4a24a389d31a613c34c7ef40e2bc0d1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter-3-linearmaps-kernals-range.tex", "max_issues_repo_name": "agupta54/maths-for-ml", "max_issues_repo_head_hexsha": "c5e54f14e4a24a389d31a613c34c7ef40e2bc0d1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter-3-linearmaps-kernals-range.tex", "max_forks_repo_name": "agupta54/maths-for-ml", "max_forks_repo_head_hexsha": "c5e54f14e4a24a389d31a613c34c7ef40e2bc0d1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.7610619469, "max_line_length": 322, "alphanum_fraction": 0.6416527701, "num_tokens": 1957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941718, "lm_q2_score": 0.9124361539289197, "lm_q1q2_score": 0.8489837520345143}}
{"text": "\\section{Point Mass Distributions}\n\nIf the entire probability is concentrated at a single point $\\alpha$, then that can be expressed in terms of the Kronecker Delta in the discrete case and the Dirac Delta function in the continuous case.\n\n\\subsection{Kronecker Delta $\\delta_{\\alpha}$}\nIn the discrete case:\n\n\\begin{equation}\n\\delta_{\\alpha} = \\left\\{\\begin{array}{l} 1\\mathrm{\\ if\\ }x = \\alpha \\\\ 0\\mathrm{\\ else}\\end{array} \\right.\n\\end{equation}\n\n\\subsection{Dirac Delta Function $\\delta(x-\\alpha)$}\nIn the continuous case:\n\n\\begin{equation}\n\\int_A \\delta(x-\\alpha) \\mathrm{d}x = \\left\\{\\begin{array}{l} 1\\mathrm{\\ if\\ }\\alpha \\in A \\\\ 0\\mathrm{\\ else}\\end{array} \\right.\n\\end{equation}\n\nThe Dirac Delta function is actually a distribution with extremely useful properties that I ought to write up. \n\n\\section{Uniform Distributions}\n\n\\subsection{Discrete Uniform $\\mathrm{Uniform(1,k)}$}\nWith $k>0$ be some integer, the PMF is:\n\n\\begin{equation}\nf(x) = \\left\\{\\begin{array}{l} 1/k \\mathrm{\\ if\\ }x \\in \\{1,...,k\\} \\\\ 0\\mathrm{\\ else}\\end{array} \\right.\n\\end{equation}\n\nThe CDF is:\n\n\\begin{equation}\nF(x)= \\left\\{\\begin{array}{cl} \n0& x < 1\\\\\n\\frac{x}{k}& 1\\leq x \\leq k\\\\\n1& x>k\n\\end{array} \\right.\n\\end{equation}\n\n% continuous uniform\n\\subsection{Continuous Uniform $\\mathrm{Uniform(a,b)}$}\n\nWith $a,b\\in\\mathbb{R}$ and $b>a$, the PDF is:\n\n\\begin{equation}\nf(x) = \\left\\{\\begin{array}{l} 1/(b-a) \\mathrm{\\ if\\ }x \\in [a,b] \\\\ 0\\mathrm{\\ else}\\end{array} \\right.\n\\end{equation}\n\nThe CDF is:\n\n\\begin{equation}\nF(x)= \\left\\{\\begin{array}{cl} \n0& x < a\\\\\n\\frac{x-a}{b-a}& a\\leq x \\leq b\\\\\n1& x>b\n\\end{array} \\right.\n\\end{equation}\n\n\n% bernoulli \n\\section{Bernoulli Processes}\nA Bernoulli process is a number of discrete trials with binary outcome, for example a series of coinflips. This is typically framed in terms of success $X=1$ with probability $p$ and failure $X=0$ with probability $1-p$. The trials are independent from each other. Thinking of the process as a sequence in time, this means that the process is memoryless: the number of successes or time since the last success have no bearing on the future. Thinking about the process as a sequence in space, the successes are independently scattered over a grid like randomly flipped bits in a string of bits. That is, the events are uniformly distributed.\n\n\n\\subsection{Bernoulli $\\mathrm{Bernoulli(p)}$}\nThe PMF of a single binary outcome $X=1$ with probability $p$ and $X=0$ with probability $1-p$. The PMF is:\n\n\\begin{equation}\nf(x) = p^x (1-p)^{1-x} =  \\left\\{\\begin{array}{cl} \np& x = 1\\\\\n(1-p)& x=0\n\\end{array} \\right.\n\\end{equation}\n\nFor $x\\in\\{0,1\\}$ and $p\\in[0,1]$.\n\n\n% binomial\n\\subsection{Binomial $\\mathrm{Binomial}(n,p)$}\nThe binomial distribution is the PMF for the number of successes with probability $p$ among $n$ trials. That is, if $X_i \\sim \\mathrm{Bernoulli}(p)$, then $X = \\sum_i^n X_i$ has distribution:\n\n\\begin{equation}\nf(x) = {n \\choose x} p^x (1-p)^{n-x}\n\\end{equation}\n\nIt follows that if $X_1 \\sim \\mathrm{Binomial}(n_1,p)$ and $X_2 \\sim \\mathrm{Binomial}(n_2,p)$, then $X_1 + X_2 \\sim \\mathrm{Binomial}(n_1+n_2,p)$. The binomial distribution can be interpreted of the probability that there will be $x$ successes among $n$ draws with replacement.\n\n\n% geometric distribution\n\\subsection{Geometric $\\mathrm{Geom}(p)$}\nThe PMF for the number of Bernoulli trials with parameter $p\\in(0,1)$ is given by: \n\n\\begin{equation}\nf(x) = p(1-p)^{x-1}\n\\end{equation}\n\nIn the time picture, it models the number of intervals $x$ until the first success occurs, or, equivalently, the number of trials between two successes. In the space picture, it models the distance between successes that are independently scattered on a grid.\n\n\n\n% negative binomial distribution\n\\subsection{Pascal, Negative Binomial $\\mathrm{NB}(r,p)$}\nThe negative binomial distribution with parameters $r$ and $p$ gives the sum of $r$ geometric random variables with parameter $p$. In the time picture, if $X \\sim \\mathrm{NB}(r,p)$, $X$ gives the probability for the number of failures in a sequence of Bernoulli trials until there are $r$ successes. In the space picture, it the probability for the width of the interval of a grid between $r$ successes (not counting the spots taken up by the successes). Its PMF is given by:\n\n\\begin{equation}\nf(x) = {x+r-1\\choose x} p^r (1-p)^x\n\\end{equation} \n\nFor $r=1$, the distribution is the same as the geometric distribution with parameter $p\\rightarrow 1-p$. The negative binomial distribution gives the probability that, when drawing with replacement, it will take $x$ failures until there have been $r$ successes, where each success has probability $p$.\n\n% bernoulli without replacement\n\\section{Bernoulli Processes \tWithout Replacement}\nBernoulli Processes were a sequence of independent trials, which can be thought of as a sequence of samples with replacement. The \"hyper\"- distributions treat the analogous case where samples are not replacemed.  \n\n% hypergeometric distribution\n\\subsection{Hypergeometric $\\mathrm{Hypergeom(N,K,n)}$}\nThe hypergeometric distribution gives the probability for the number of successes when drawing $n$ times from a population of $N$, of which $K$ correspond to successes.\n\n\\begin{equation}\nf(k) = \\frac{{K \\choose k}{ N-K \\choose n-k}}{{N \\choose k}}\n\\end{equation} \n\nIt is the analogue to the binomial distribution for sampling without replacement.\n\n% negative hypergeometric distribution\n\\subsection{Negative Hypergeometric $\\mathrm{NH(N,K,n)}$}\nThe negative hypergeometric distribution gives the probability that, when sampling without replacement, it will take $r$ failures until there have been $k$ successes, if the total population is $N$ and the number of elements corresponding to a success is $K$.\n\n\\begin{equation}\nf(k) = \\frac{{k+r-1\\choose k}{N-r-k \\choose K-k}}{{N\\choose K}}\n\\end{equation}\n\nThe negative hypergeometric distribution is the analogue to the negative binomial distribution for sampling without replacement. \n\n\n% poisson processes\n\\section{Poisson Point Processes}\nPoisson point processes are the continuous analogue to Bernoulli processes. Rather than looking at the outcome of a number of binary trials, they look at the number or spacing of independent point events over a continuous interval. In one dimension, Poisson Processes very often model rare events happening over a given time interval. In higher dimensions, the Poisson process can be thought of as independently scattered points in some volume. The process is typically characterized by the parameter $\\Lambda$, called the \\textit{rate} or \\textit{intensity} of the process. It can be written $\\Lambda = \\nu \\lambda$ where $\\nu$ is a Lebesgue measure (assigning a length or volume to a set) and $\\lambda$ is a constant. For a temporal process, $\\nu$ would be the time interval. For a spatial process, $\\nu$ would be a volume. The events have uniform distribution over the measure. This is also called a homogenous Poisson process. \n\n% poisson distribution\n\\subsection{Poisson $\\mathrm{Poisson}(\\Lambda)$}\nThe poisson distribution is the continuous analogue to the Binomial distribution. It measures the number of events for a process with intensity $\\Lambda$.\n\n\\begin{equation}\nf(x) = e^{-\\Lambda}\\frac{\\Lambda^x}{x!}\\ \\ \\mathrm{x\\geq0}\n\\end{equation}\n\nJust like for the Binomial distribution, if $X_1 \\sim \\mathrm{Poisson}(\\Lambda_1)$ and $X_2 \\sim \\mathrm{Poisson}(\\Lambda_2)$, then $X_1 + X_2 \\sim \\mathrm{Poisson}(\\Lambda_1 + \\Lambda_2)$. \n\nThe mean and variance of the poisson distribution are both $\\lambda$. This link means that Poisson distributed data is inherently heteroskedastic. The Poisson distribution can be obtained from the Bernoulli distribution by considering a very large number of trials with a small probability of success in each trial. That is, if $Y \\sim B(n,\\pi)$ then letting $n\\rightarrow \\infty$ with $\\pi \\rightarrow 0$ and $\\mu \\rightarrow n\\pi$ you recover the Poisson distribution. In this sense, the Poisson distribution is an approximation to a Binomial process with rare events with large $n$ and small $\\pi$. \n\n\n\n% exponential distribution\n\\subsection{Exponential $\\mathrm{Exp}(\\lambda)$}\nThe exponential distribution is the continuous analogue to the Geometric distribution. In one dimension, if $X \\sim \\mathrm{Exp}(\\Lambda)$, then $X$ can be interpreted as the distance between two independently scattered points on the real line. In the time picture, that would be the time that elapses between two events, or, equivalently, the time until the next event, where $\\lambda$ is the rate or intensity.\n\n\\begin{equation}\nf(x) = \\lambda e^{-\\lambda}\n\\end{equation}\n\n\n% gamma distribution\n\\subsection{Gamma $\\mathrm{Gamma(\\alpha,\\beta)}$}\nThe Gamma Distribution is the continuous analogue to the negative binomial distribution. For integer $\\alpha$, it gives the probability of the value of the sum of $\\alpha$ exponentially distributed random variables with parameter $\\beta=\\frac{1}{\\lambda}$. That is, if $X_i \\sim Exp(\\frac{1}{\\beta})$ then $X = \\sum_i^\\alpha X_i \\sim \\mathrm{Gamma}(\\alpha,\\beta)$. The PDF is given by:\n\n\\begin{equation}\nf_x = \\frac{1}{\\beta^\\alpha \\Gamma(\\alpha)}x^{\\alpha-1}e^{-x/\\beta}\n\\end{equation}\n\nWith $\\alpha,\\beta > 0$.\n\nAs one would expect, if $X_1 \\sim \\Gamma(\\alpha_1,\\beta)$ and $X_2 \\sim \\Gamma(\\alpha_2,\\beta)$ then $X_1 + X_2 \\sim \\Gamma(\\alpha_1+\\alpha_2,\\beta)$. \n\n\n\n% t distribution\n\\section{$t$-Distribution $\\mathrm{t_\\nu\\ }$}\n\n\\subsection{Cauchy Distribution $t_1$}\nThe Cauchy Distribution does not have a mean. It is infinite.\n\n\n\\section{Chi$^2$-Distribution $\\chi^2_p$}\nThe $\\chi^2$ distribution is the probability distribution of the sum of squares of standard normally distributed random variables. If $Z_i$ has standard normal distribution, then $X = \\sum_i^p Z_i \\sim \\chi^2_p$.\n\n\n% normal\n\\section{Normal $\\mathscr{N}(\\mu,\\sigma^2)$}\n\n\n\\subsection{Standard Normal Distribution $\\mathscr{N}(0,1)$ }\n\nThe normal distribution is so ubiquitous that there is notation specifically for the \\textit{standard normal distribution}, which is the normal distribution with parameters $\\mu = 0$ and $\\sigma = 1$. It is always possible to transform a random variable $X$ to have standard normal distribution by performing a coordinate transform. The PDF of the standard normal distribution is written $\\phi(x)$ and the CDF $\\Phi(x)$. The PDF is given by: \n\n\\begin{equation}\n\\phi(x) = \\frac{1}{\\sqrt{2\\pi}}\\exp{-x^2}\n\\end{equation}\n\nThe CDF has no closed form expression. \n\nBy convention, $Z$ is the random variable that has standard normal distribution. If $X \\sim \\mathscr{N}(\\mu,\\sigma^2)$, then $Z = \\frac{X-\\mu}{\\sigma} \\sim \\mathscr{N}(0,1)$. This standardizing transformation allows for calculations using lookup tables. \n\n\\subsubsection{Example: Interval $\\mathbb{P}(a<X<b)$}\n\n\\begin{equation}\n\\mathbb{P}(a<X<b) =  \\mathbb{P}(a' < Z < b') = \\Phi(b') - \\Phi(a')\n\\end{equation}\n\nwith $a' = \\frac{a-\\mu}{\\sigma}$ and $b' = \\frac{b-\\mu}{\\sigma}$.\n\n\\subsubsection{Example: Quantile $x = F^{-1}(q)$}\n\n\\begin{equation}\nz = \\Phi^{-1}(q)\n\\end{equation}\n\nwith $z = \\frac{x-\\mu}{\\sigma}$, so that $x = \\sigma \\Phi^{-1}(q)+\\mu$. The interquartile range is calculated by transforming $(z_{1}=\\Phi^{-1}(0.25),z_{3}=\\Phi^{-1}(0.75))$, and so on.\n\n\n% log normal \n\\section{Log Normal Distribution}\nThe log normal distribution has the odd property that is ``thin tailed\" for low variance and ``fat tailed\" for high variance.\n\n% Multinoulli Processes\n\\section{Categorial Processes, Multinoulli Processes}\nA Multnoulli process is a number of discrete trials that may assume a number of different categorical outcomes, for example a series of dice throws or a random sequence of letters. It is the generalization of the Bernoulli process to processes with more than two possible outcomes. The trials are independent from each other. Thinking of the process as a sequence in time, this means that the process is memoryless: the sequence of future outcomes is independent of past outcomes. Thinking about the process as a sequence in space, it is a uniformly random assignment of one of a set number of outcomes to grid points.\n\n% Multinoulli\n\\subsection{Categorical, Multinoulli $\\mathrm{Categorical(\\mathbf{p})}$}\nThe categorial or Multinoulli distribution is the generalization of the Bernoulli distribution to more than two possible outcomes. The PMF is given by:\n\n\\begin{equation}\nf(\\mathbf{x}) = \\prod_i^k p_i^{[x=k]}\n\\end{equation}\n\nWith $p_i \\in \\mathbf{p}$ a discrete probability distribution and $[x=k]$ is the Iverson bracket.\n\n% Multinomial\n\\subsection{Multinomial $\\mathrm{Multinomial(n,\\mathbf{p})}$}\nThe multinomial distribution is the multivariate generalization of the binomial process. Rather than a binary outcome, there are $k$ possible outcomes. If $\\mathbf{X}=(X_1,X_2,...,X_k)$ has multinomial distribution with parameter vector $\\mathbf{p} = (p_1,p_2,...,p_k)$, then it gives the probability that out of $n$ trials, $x_j$ will be of type $j$, where the probabilities of the different classes is given by the discrete probability distribution $\\mathbf{p}$.\n\n\\begin{equation}\nf(\\mathbf{x}) = {n \\choose x_1,x_2,...,x_k} p_1^{x_1}p_2^{x_2}...p_k^{x_k} = {|\\mathbf{x}|\\choose \\mathbf{x}}\\mathbf{p}^{\\mathbf{x}}\n\\end{equation}\n\nWhere the final expression uses multi-index notation. The binomial process corresponds to $k=2$ classes (success and failure). The marginal distribution of $X_j$ is $Binomial(n,p_j)$.\n\n\n% beta distribution\n\\section{Beta $\\mathrm{Beta}(\\alpha,\\beta)$}\n\nThe PDF for the beta distribution is:\n\n\\begin{equation}\nf(x) = \\frac{\\Gamma(\\alpha + \\beta)}{\\Gamma(\\alpha)\\Gamma(\\beta)}x^{\\alpha-1}(1-x)^{\\beta-1}\\ \\ 0 < x < 1\n\\end{equation}\n\nWith $\\alpha, \\beta > 0$.\n\nThe Beta distribution is the conjugate prior to the Bernoulli and Binomial distributions.\n\n% dirichlet distribution\n\\section{Dirichlet $\\mathrm{Dirichlet}(\\mathbf{\\alpha})$}\nThe Dirichlet Distribution is the multivariate generalization of the Beta Distribution. Given $\\mathbf{X} = (X_1,...,X_K)$ and the parameter vector $\\mathbf{\\alpha} = (\\alpha_1,...,\\alpha_K),\\ \\alpha_j > 0$, the PDF is:\n\n\\begin{equation}\nf(\\mathbf{x},\\mathbf{\\alpha}) = \\frac{1}{B(\\mathbf{\\alpha})} \\prod^K_{i=1} x_i^{\\alpha_i -1}\n\\end{equation}\n\nWhere $B(\\mathbf{\\alpha})$ is the multivariate Beta function:\n\n\\begin{equation}\nB(\\mathbf{\\alpha}) = \\frac{\\prod^K_{i=1}\\Gamma(\\alpha_i)}{\\Gamma(\\sum_{i=1}^K\\alpha_i)}\n\\end{equation}\n\nThe Dirichlet distribution is the conjugate prior to the Multinoulli/Categorical and Multinomial distributions. The marginal distributions are Beta distributions, i.e. $X_i \\sim \\mathbf{Beta}(\\alpha_i,\\alpha_0-\\alpha_1)$ where $\\alpha_0 = \\sum_j \\alpha_j$.\n\n\n\n% multivariate normal distribution\n\\section{Multivariate Normal $\\mathscr{N}(\\mathbf{\\mu},\\mathbf{\\Sigma})$}\nThe multivariate normal distribution is the multivariate generalization of the normal distribution. The PDF is given by:\n\n\\begin{equation}\nf{\\mathbf{x}} = \\frac{1}{(2\\pi)^{\\frac{k}{2}}|\\Sigma|^{\\frac{1}{2}}}\\exp\\{-\\frac{1}{2}(\\mathbf{x}-\\mathbf{\\mu})^T \\mathbf{\\Sigma}^{-1}(\\mathbf{x}-\\mathbf{\\mu})\\}\n\\end{equation}\n\n\n\n% covariance matrix\n\\subsection{Covariance Matrix $\\mathbf{\\Sigma}$}\nThe covariance matrix $\\mathbf{\\Sigma}$ is symmetric and positive definite. Therefore, $\\mathbf{\\Sigma}^{\\frac{1}{2}}$ exists and is real, symmetric, and\n\n\\begin{itemize}\n\\item $\\mathbf{\\Sigma}^{\\frac{1}{2}}\\mathbf{\\Sigma}^{\\frac{1}{2}} = \\mathbf{\\Sigma}$\n\\item $\\mathbf{\\Sigma}^{\\frac{1}{2}}\\mathbf{\\Sigma}^{-\\frac{1}{2}}=\\mathbf{\\Sigma}^{-\\frac{1}{2}}\\mathbf{\\Sigma}^{\\frac{1}{2}}=\\mathbf{I}$\n\\end{itemize}\n\n\n% marginal distribution \n\\subsection{Marginal Distribution}\nIf $\\mathbf{X} \\sim \\mathscr{N}(\\mathbf{0},\\mathbf{\\Sigma})$, then the marginal distribution of $X_a$ is:\n\n\\begin{equation}\nX_a \\sim \\mathscr{\\mu_a,\\Sigma_{aa}}\n\\end{equation}\n\n\n% conditional distribution\n\\subsection{Conditional Distribution}\nIf $\\mathbf{X} \\sim \\mathscr{N}(\\mathbf{0},\\mathbf{\\Sigma})$, then the conditional distribution of $X_b$ given $X_a = x_a$ is:\n\n\\begin{equation}\nX_b|X_a = x_a \\sim \\mathscr{N}(\\mu_b + \\Sigma_{ba}\\Sigma_{aa}^{-1}(x_a - \\mu_a), \\Sigma_{bb}-\\Sigma_{ba}\\Sigma_{aa}^{-1}\\Sigma_{ab}) \n\\end{equation}\n\n\n% vector multiplication \n\\subsection{Vector Multiplication}\nIf $\\mathbf{a}$ is a vector, then:\n\n\\begin{equation}\n\\mathbf{a}^T \\mathbf{X} \\sim \\mathscr{N}(\\mathbf{a}^T \\mathbf{\\mu}, \\mathbf{a}^T\\mathbf{\\Sigma}\\mathbf{a})\n\\end{equation}\n\n\n% relationship to chi2\n\\subsection{Relationship to Chi$^2$}\n\\begin{equation}\nV = \\mathbf{Z}^T\\mathbf{Z} = (\\mathbf{X}-\\mathbf{\\mu})^T\\mathbf{\\Sigma}^{-1}(\\mathbf{X}-\\mathbf{\\mu}) \\sim \\chi^2_k\n\\end{equation}\n\n\\subsection{Multivariate Standard Normal Distribution $\\mathscr{N}(\\mathbf{0},\\mathbf{\\Sigma})$}\nThe standard multivariate normal distribution for $\\mathbf{Z} = (Z_1,...,Z_k)$ with $\\mathbf{Z} \\sim \\mathscr{N}(\\mathbf{0},\\mathbf{I})$ is:\n\n\\begin{equation}\nf(z) = \\prod^k_{i=1} f(z_i) = \\frac{1}{(2\\pi)^{\\frac{k}{2}}}\\exp \\{ \\frac{1}{2} \\sum^{k}_{j=1} z_j\\} = \\frac{1}{(2\\pi)^{\\frac{k}{2}}}\\exp \\{ \\frac{1}{2} \\mathbf{z^T z}\\}\n\\end{equation}\n\nThe transformation to a general multivariate normal random variable $\\mathbf{X}$ is that if $\\mathbf{Z} \\sim \\mathscr{0,\\mathbf{I}}$, then $\\mathbf{X} = \\mathbf{\\mu} + \\mathbf{\\Sigma}^{\\frac{1}{2}}\\mathbf{Z}$. Conversely, if $\\mathbf{X}\\sim \\mathscr{\\mathbf{\\mu},\\mathbf{\\Sigma}}$ then $\\mathbf{\\Sigma}^{-\\frac{1}{2}}(\\mathbf{X}-\\mathbf{\\mu}) \\sim \\mathscr{N}(0,\\mathbf{I})$.\n", "meta": {"hexsha": "0b08c06212ef8faa967d16d38482731751a0480a", "size": 17421, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/proba_distributions.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/proba_distributions.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/proba_distributions.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.9385964912, "max_line_length": 931, "alphanum_fraction": 0.7243556627, "num_tokens": 5204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109955, "lm_q2_score": 0.9184802501617068, "lm_q1q2_score": 0.8488060042421686}}
{"text": "\\section{Clustering}\n\nTwo Views:\n\nClustering input: $S_n = \\{x^{(i)}|n=1,\\cdots,n\\}$\n\nClustering output are indexes for the data that partition the data: $C_1,\\cdots,C_k$; where $C_1 \\cup C_2 \\cup ... \\cup C_ K = \\big \\{  1, 2, ..., n \\big \\}$ and the union of all  $C_j$ 's is the original set and the intersection of any  $C_i$  and  $C_j$  is an empty set.\n\nRepresentatives of clusters: $z^{(1)},\\cdots,z^{(k)}$.\\\\\n\nCost of partitioning is the sum of costs of individual clusters: $cost(C_1,\\cdots,C_k) = \\sum_{j=1}^k cost (C_j)$. \n\nCost of cluster is sum of distances from data points to the representative of the cluster:$Cost(C,z) = \\sum_{i \\in C} = distance(x^{(i)},z)$\n\nCosine similarity: $cos(x^{(i)},x^{(j)}) = \\frac{x^{(i)} \\cdot x^{(j)}}{||x^{(i)}|| ||x^{(j)}||}$ is not sensitive of magnitude of vector (will not react to length).\\\\\n\nEuclidean square distance: $dist(x^{(i)},x^{(j)})= ||x^{(i)}-x^{(j)}||^2$. Will react to length.\\\\\n\n$cost(C_1,\\cdots,C_k; z^{(1)},\\cdots,z^{(k)}) = \\sum_{j=1}^k \\sum_{c \\in C_j} ||x^{(i)}-z^{(j)}||^2 $\n\n\\subsection{The K-Means Algorithm}\n\nOnly works with Euclidean square distance.\n\nGiven a set of feature vectors $S_ n = \\big \\{ x^{(i)}| i = 1,...,n\\big \\}$ and the number of clusters  $K$ we can find cluster assignments  $C_1,\\cdots,C_K$ and the representatives of each of the $K$ clusters $z_1,\\cdots,z_K$:\\\\\n\n\n\\begin{enumerate}\n\\item Randomly select $z_1,\\cdots,z_K$\n\\item Iterate\n\\begin{enumerate}\n\\item Given $z_1,\\cdots,z_K$, assign each data point $x^{(i)}$ to the closest $z_j$, so that $\\text {Cost}(z_1, ... z_ K) = \\sum _{i=1}^{n} \\min _{j=1,...,K} \\left\\|  x^{(i)} - z_ j \\right\\| ^2$\n\\item Given $C_1,\\cdots,C_K$ find the best representatives $z_1,\\cdots,z_K$, i.e. find $z_1,\\cdots,z_K$ such that $\\displaystyle z_ j=\\operatorname {argmin}_{z} \\sum _{i \\in C_ j} \\| x^{(i)} - z \\| ^2$\n\\end{enumerate}\n\\end{enumerate}\n\nThe best representative is found by optimization (gradient with respect to $z^{(j)}$, setting to zero and solving for $z^{(j)}$). It is the centroid of the cluster: $z^{(j)}=\\displaystyle \\frac{\\sum _{i \\in C_ j} x^{(i)}}{|C_ j|}$\\\\\n\nThe clustering output that the K-Means algorithm converges to depends on the intialization.\nIn KM the fact that the z's are actually not guaranteed to be the members of the original set of points x\n\n\\subsection{K-Medoids Algorithm}\n\nFinds the cost-minimizing representatives  $z_1,\\cdots,z_K$ for any distance measure. Uses real data points for initialization.\n\n\\begin{enumerate}\n\\item Randomly select $\\big \\{  z_1, ..., z_ K \\big \\}  \\subseteq \\big \\{  x_1, ..., x_ n \\big \\}$\n\\item Iterate\n\\begin{enumerate}\n\\item Given $z_1,\\cdots,z_K$, assign each data point $x^{(i)}$ to the closest $z_j$, so that $\\text {Cost}(z_1, ... z_ K) = \\sum _{i=1}^{n} \\min _{j=1,...,K} \\left\\|  x^{(i)} - z_ j \\right\\| ^2$\n\\item Given $C_ j \\in \\big \\{ C_1,...,C_ K\\big \\}$ find the best representative $z_ j \\in \\big \\{ x_1,...,x_ n\\big \\}$ such that $\\sum _{x^{(i)} \\in C_ j} \\text {dist}(x^{(i)}, z_ j)$ is minimal\n\\end{enumerate}\n\\end{enumerate}\n\n\\subsection{some useful notes:}\nmeasure of the cluster heterogeneity: cluster diameter (the distance\nbetween the most extreme feature vectors, i.e. the outliers),the average distance,\n the sum of the distances between every member and  $z_j$, the\nrepresentative vector of cluster $C_j$.\n\n", "meta": {"hexsha": "f3ed15dfa1605b77bcc92275322826348fd8987f", "size": 3337, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/clustering.tex", "max_stars_repo_name": "sharov-am/MITx_capstone_2", "max_stars_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "content/clustering.tex", "max_issues_repo_name": "sharov-am/MITx_capstone_2", "max_issues_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content/clustering.tex", "max_forks_repo_name": "sharov-am/MITx_capstone_2", "max_forks_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.7049180328, "max_line_length": 273, "alphanum_fraction": 0.6535810608, "num_tokens": 1176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587142, "lm_q2_score": 0.9019206824612297, "lm_q1q2_score": 0.8485177327039487}}
{"text": "\\section{Lengths in metric spaces}\n\nOn $S^2 \\subset \\mathbb{R}^3$, we define $\\mathrm{d}(a,b) = \\text{inf}\\left( \\{ \\text{length}(\\gamma) | \\gamma \\text{ is a path on } S^2 \\text{ from } a \\text{ to } b \\} \\right)$, where $a$ and $b$ are points of $S^2$.\n\n\\noindent Now we try to generalize this construction. We assume that $X$ is a metric space.\n\n\\begin{itemize}\n  \\item We will define \\emph{lengths of paths in} $X$.\n  \\item Given lengths of paths, we will define a new distance $\\hat{d}$ on $X$ as follows:\n  $$\\hat{d}(a,b) = \\text{inf}\\left( \\{ \\text{length}(\\gamma) \\ | \\ \\gamma \\text{ is a path from } a \\text{ to } b \\} \\right)$$\n  where $a$ and $b$ are points of $X$.\n\\end{itemize}\n", "meta": {"hexsha": "95d2170170cca7518121121791ceb4b5b1e19bf6", "size": 691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/LengthInMetricSpaces.tex", "max_stars_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_stars_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-12-28T05:53:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-20T05:56:59.000Z", "max_issues_repo_path": "src/LengthInMetricSpaces.tex", "max_issues_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_issues_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/LengthInMetricSpaces.tex", "max_forks_repo_name": "siddhartha-gadgil/MetricGeometryCourse", "max_forks_repo_head_hexsha": "92ec7727f358107a8ad61a7229bc94e2aa9bbafc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.1538461538, "max_line_length": 218, "alphanum_fraction": 0.6266280753, "num_tokens": 253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338090839607, "lm_q2_score": 0.8824278772763472, "lm_q1q2_score": 0.8484842380793999}}
{"text": "\\lab{Applications}{Correlation and Covariance}{Correlation and Covariance}\n\\label{Stats1}\n\n\\objective{This section will teach about using Python to solve problems in statistics. This will include finding means, correlation matrices, and solving least squares problems.}\n\n\\section*{Shifting Data by the Mean}\n\nConsider the table below representing students scores in a class.\\\\\n\n\\begin{figure}[h!]\n\\begin{center}\n\\begin{tabular}{|c|r|r|r|r|}\n\t\\hline\nStudent & Homework & Exam 1  & Exam 2 & Final \\\\\n\\hline\nS1  & 89 & 91 & 77 & 75 \\\\\nS2  & 67 & 72 & 76 & 66 \\\\\nS3  & 72 & 77 & 69 & 70 \\\\\nS4  & 56 & 60 & 55 & 61 \\\\\nS5  & 92 & 98 & 89 & 86 \\\\\nS6  & 83 & 88 & 90 & 84 \\\\\nS7  & 45 & 60 & 55 & 48 \\\\\n\\hline\nAverage  & 72 & 78 & 73 & 70\\\\\n\\hline\n\\end{tabular}\\\\\n\\end{center}\n\\end{figure}\n\nWe can shift our data set by subtracting each column by its average value.  This makes it so that the average of each column in the matrix below is zero.  If $W$ represents the matrix of scores, the following Python command will subtract out the average.  Why does this work?\n\\begin{lstlisting}[style=python]\n:X = W - sp.dot(sp.ones((7,1),dtype=sp.float_),sp.mean(W,axis=0).reshape(1,4));X\narray([[ 17.,  13.,   4.,   5.],\n       [ -5.,  -6.,   3.,  -4.],\n       [  0.,  -1.,  -4.,   0.],\n       [-16., -18., -18.,  -9.],\n       [ 20.,  20.,  16.,  16.],\n       [ 11.,  10.,  17.,  14.],\n       [-27., -18., -18., -22.]])\n\\end{lstlisting}\n\n\n\\section*{Angles Between Vectors}\n\nInner products give information about lengths of vectors and angles between vectors.  Recall that the angle $\\theta$ between two vectors is given by\n\\[\n\\cos{\\theta} = \\frac{\\ipt{x}{y}}{\\norm{x}\\norm{y}}\n\\]\nwhere the norm (or length) of a vector is $\\norm{x} = \\sqrt{\\ipt{x}{x}}$.  Note that the usual inner product in $\\mathbb{R}^n$ is given by\n\\[\n\\ipt{x}{y} = x^T y\n\\]\nAlternatively, if we can first divide our vectors by their length (these are called unit vectors) and then take the inner product\n\\[\n\\cos{\\theta} = \\left\\langle\\frac{x}{\\norm{x}},\\frac{y}{\\norm{y}}\\right\\rangle\n\\]\nHence, we can find the cosine of the angles between our data columns in $X$ by dividing each column by its length.  There are a couple of ways of doing this.  The following is an interesting way of doing it.  Be sure to explore why it works:\n\\begin{lstlisting}[style=python]\n: Y = X / sp.dot(sp.ones((7,1),dtype=sp.float_),sp.sqrt(sp.diag(sp.dot(X.T,X)).T).reshape(1,4));Y\narray([[ 0.39848615,  0.35329218,  0.11386819,  0.15371887],\n       [-0.11720181, -0.16305793,  0.08540114, -0.12297509],\n       [ 0.        , -0.02717632, -0.11386819,  0.        ],\n       [-0.37504578, -0.48917378, -0.51240685, -0.27669396],\n       [ 0.46880723,  0.54352643,  0.45547275,  0.49190037],\n       [ 0.25784398,  0.27176321,  0.4839398 ,  0.43041282],\n       [-0.63288976, -0.48917378, -0.51240685, -0.67636301]])\n\\end{lstlisting}\nHence we have:\n\\[\nY=\n\\begin{bmatrix}\n0.3985 & 0.3533 & 0.1139 & 0.1537\\\\\n-0.1172 & -0.1631 & 0.0854 & -0.1230\\\\\n0 &-0.0272 &-0.1139 & 0\\\\\n-0.3750 & -0.4892 & -0.5124 & -0.2767\\\\\n0.4688 & 0.5435 & 0.4555 & 0.4919\\\\\n0.2578 & 0.2718 & 0.4839 & 0.4304\\\\\n-0.6329 & -0.4892 & -0.5124 & -0.6764\n\\end{bmatrix}\n\\]\nFinally, we get the cosines of the angles between columns by computing $Y^T Y$.  In Python, that's just\n\\begin{lstlisting}[style=python]\n: sp.dot(Y.T,Y)\narray([[ 1.        ,  0.97782999,  0.89014869,  0.94908967],\n       [ 0.97782999,  1.        ,  0.90978843,  0.92490144],\n       [ 0.89014869,  0.90978843,  1.        ,  0.9276955 ],\n       [ 0.94908967,  0.92490144,  0.9276955 ,  1.        ]])\n\\end{lstlisting}\nThis yields\n\\[\nY^T Y = \n\\begin{bmatrix}\n1.0000 & 0.9778 & 0.8901 & 0.9491\\\\\n0.9778 & 1.0000 & 0.9098 & 0.9249\\\\\n0.8901 & 0.9098 & 1.0000 & 0.9277\\\\\n0.9491 & 0.9249 & 0.9277 & 1.0000\n\\end{bmatrix}.\n\\]\nNote that the $(j,k)$ entry of $Y^T Y$ corresponds to the cosine of the angle between the $j^{th}$ and $k^{th}$ columns.  We remark that the diagonals are always equal to one because the angle between a vector and itself is zero and the cosine of zero is one.\n\nIt is also worth noting that the matrix resulting from the operation $A \\cdot A^T$ is symmetric and positive definite, so it can be solved with the cholesky decomposition that was discussed at the end of Lab \\ref{lab:LUdecomp}.\n\n\\section*{Correlation}\n\nWe remark that the cosine of the angle between two vectors is sometimes called the correlation coefficient.  Two columns are said to be \n\\begin{itemize}\n\\item Perfectly correlated if the cosine of the angle between them is one.\n\\item Positively correlated if the cosine of the angle between them is between zero and one.\n\\item Uncorrelated if the cosine of the angle between them is zero.\n\\item Negatively correlated if the cosine of the angle between them is between negative one and zero.\n\\item Perfectly anticorrelated if the cosine of the angle between them is negative one.\n\\end{itemize}\n\nThe notion of correlation is important in establishing the relationships between measurements.  For example, there is a high correlation between those who smoke and those who get lung cancer.  It's important to understand that the high correlation alone does not necessarily imply that smoking causes lung cancer, it only links them statistically.  This is the famous issue of causation versus correlation.  For example, there is a high correlation between crime rates and sales of ice cream.  This doesn't mean that ice cream causes crime or that increases in crime makes people want to eat more ice cream, but both rates do go up in the summer.\n\n\\begin{problem}\nLoad the data file \\texttt{data.npy}.\nThe dataset consists of two columns.  Find the correlation coefficient of the two columns.  Then plot the original data and see if the value that you got is reasonable.\n\\end{problem}\n", "meta": {"hexsha": "5172f61bcd048f329d93db9a22ea82b2391479c0", "size": 5773, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/CorrCovariance/CorrCovariance.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/CorrCovariance/CorrCovariance.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/CorrCovariance/CorrCovariance.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.1083333333, "max_line_length": 646, "alphanum_fraction": 0.6774640568, "num_tokens": 1947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009573133051, "lm_q2_score": 0.9273632976542184, "lm_q1q2_score": 0.8484455688010679}}
{"text": "\\section{Areas in the Plane}\r\n\\begin{lemma}\r\n\tIf $f(x) \\geq g(x)$ on $[a,b]$ then the area between $f(x)$ and $g(x)$ on $[a,b]$ is given by\r\n\t\\begin{equation*}\r\n\t\tA = \\int_{a}^{b}{\\left(f(x)-g(x)\\right)\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{lemma}\r\n\r\nYou can easily visualize why this is true.\r\nWe can break the integral into two parts: adding the area under $f$ and the other subtracting the area under $g$.\r\nThe first integral will over count the area between $f$ and $g$, counting all area between $f$ and the $x$-axis.\r\nThe second integral will subtract exactly the amount of area that is over counted: the area that is also between $g$ and the $x$-axis.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{area_between_curves}\r\n\t\\centering\r\n\t\\includegraphics[width = 0.33\\textwidth]{./applications_integrals/curve1.png}\r\n\t\\includegraphics[width = 0.33\\textwidth]{./applications_integrals/curve2.png}\r\n\t\\caption{\\hyperref{}{}{}{Subtracting two areas to get the area between them}}\r\n\\end{figure}\r\n\r\nEven if both of the curves has more area below the $x$-axis, the same idea applies.\r\n$f$ will give a smaller-magnitude negative area, while $g$ will give a larger magnitude negative area.\r\nSubtracting a larger-magnitude negative number from a smaller magnitude negative number will give a positive area.\r\n\r\n\\begin{example}\r\n\tFind the area enclosed between the two curves $y=2-x^2$ and $y=-x$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tThese two curves intersect at $x=-1$ and $x=2$.\r\n\tApplying the formula,\r\n\t\\begin{align*}\r\n\t\tA &= \\int_{-1}^{2}{((2-x^2)-(-x))\\d{x}} \\\\\r\n\t\t&= 2x-\\frac{x^3}{3} + \\frac{x^2}{2}\\biggr\\rvert_{-1}^{2} \\\\\r\n\t\t&= \\frac{9}{2}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsection{Subregions}\r\nSometimes it might be useful to break the enclosed regions into subregions and find the area of each separately.\r\n\\begin{example}\r\n\tFind the area above the $x$-axis, below $y=\\sqrt{x}$, and above $y=x-2$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tIf we simply took the area between the two curves, we'd count some area we don't want beneath the $x$-axis\\footnote{Although this extra region is just a triangle and not too hard to find the area of, you'd effectively be applying the same strategy of two subregions, they'd just overlap. However, using geometry to your advantage is certainly a valid approach.}.\r\n\tInstead, we can break the area into two subregions: one between the $x$-axis and $\\sqrt{x}$ and the other between $x-2$ and $\\sqrt{x}$.\r\n\t\\begin{figure}[H]\r\n\t\t\\label{subregions}\r\n\t\t\\centering\r\n\t\t\\includegraphics[width = 0.33\\textwidth]{./applications_integrals/two_regions.png}\r\n\t\t\\caption{\\hyperref{}{}{}{Break complicated areas into simpler subregions}}\r\n\t\\end{figure}\r\n\t\r\n\tFinding the area of the blue region,\r\n\t\\begin{equation*}\r\n\t\tA_1 = \\int_{0}^{2}{\\sqrt{x}\\d{x}} = \\frac{2x\\sqrt{x}}{3}\\biggr\\rvert_0^2 = \\frac{4\\sqrt{2}}{3}.\r\n\t\\end{equation*}\r\n\t\r\n\tFinding the area of the green region,\r\n\t\\begin{equation*}\r\n\t\tA_2 = \\int_{2}^{4}{(\\sqrt{x}-(x-2))\\d{x}} = \\frac{2x\\sqrt{x}}{3} - \\frac{x^2}{2} + 2x \\biggr\\rvert_2^4 = \\frac{10}{3} - \\frac{4\\sqrt{2}}{3}.\r\n\t\\end{equation*}\r\n\t\r\n\tAdding the areas of the two regions,\r\n\t\\begin{equation*}\r\n\t\tA = A_1 + A_2 = \\frac{10}{3}.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\subsection{Integrating with Respect to $y$}\r\nAnother strategy when finding the area of more complex regions is to see if they become easier to deal with if we were to instead integrate with respect to $y$.\r\nIn the above example, it is indeed easier to work with respect to $y$ because both bounding curves are between the same $y$ values.\r\n\\begin{example}\r\n\tFind the area above the $x$-axis, below $y=\\sqrt{x}$, and above $y=x-2$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe need to rearrange our equations to be of the form $x=\\ldots$ instead of $y=\\ldots$ by simply solving for $x$.\r\n\t\\begin{equation*}\r\n\t\tx = y^2, y\\geq 0 \\text{ and } x = y+2.\r\n\t\\end{equation*}\r\n\t\r\n\tSince $x=y+2$ is further from the $x$-axis, it becomes our top curve.\r\n\t\\begin{align*}\r\n\t\tA &= \\int_{0}^{2}{((y+2)-y^2)\\d{y}} \\\\\r\n\t\t&= \\frac{y^2}{2} + 2y - \\frac{y^3}{3} \\biggr\\rvert_0^2 \\\\\r\n\t\t&= \\frac{10}{3}.\r\n\t\\end{align*}\r\n\\end{answer}", "meta": {"hexsha": "6202098337d35100d86462acbc1f1e38c4bd2518", "size": 4082, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/applications_integrals/areas.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/applications_integrals/areas.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/applications_integrals/areas.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 46.3863636364, "max_line_length": 364, "alphanum_fraction": 0.6778539931, "num_tokens": 1344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167044, "lm_q2_score": 0.9149009578933863, "lm_q1q2_score": 0.8484455601556827}}
{"text": "\n\\subsection{Polar co-ordinates}\n\n\\subsubsection{All complex numbers can be shown in polar form}\n\nConsider a complex number\n\n\\(z=a+bi\\)\n\nWe can write this as:\n\n\\(z=r\\cos(\\theta ) + ir\\sin(\\theta )\\)\n\n\\subsubsection{Polar forms are not unique}\n\nBecause the functions loop:\n\n\\(ae^{i\\theta }=a(\\cos(\\theta )+i\\sin(\\theta ))\\)\n\n\\(ae^{i\\theta }=a(\\cos(\\theta +n\\tau )+i\\sin(\\theta +n\\tau ))\\)\n\n\\(ae^{i\\theta }= ae^{i\\theta +n\\tau}\\)\n\nAdditionally:\n\n\\(ae^{i\\theta }=a(\\cos(\\theta )+i\\sin(\\theta ))\\)\n\n\\(ae^{i\\theta }=a(\\cos(\\theta )+i\\sin(\\theta ))\\)\n\n\\(ae^{i\\theta }=-a(\\cos(\\theta )-i\\sin(\\theta ))\\)\n\n\\(ae^{i\\theta }=-a(\\cos(\\theta +\\dfrac{\\pi }{2})+i\\sin(\\theta +\\dfrac{\\pi }{2}))\\)\n\n\\subsubsection{Real and imaginary parts of a complex number in polar form}\n\nWe can extract the real and imaginary parts of this number.\n\n\\(Re(z):=r\\cos (\\theta )\\)\n\n\\(Im(z):=r\\sin (\\theta )\\)\n\nAlternatively:\n\n\\(Re(z)=r\\dfrac{e^{i\\theta }+e^{-i\\theta }}{2}\\)\n\n\\(Im(z)=r\\dfrac{e^{i\\theta }-e^{-i\\theta }}{2i}\\)\n\n", "meta": {"hexsha": "433d89811d26a11094048b2fee7623efcd602c1c", "size": 992, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/trigonometryPolar/01-01-polar.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/trigonometryPolar/01-01-polar.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/trigonometryPolar/01-01-polar.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.6666666667, "max_line_length": 82, "alphanum_fraction": 0.6088709677, "num_tokens": 367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122732859021, "lm_q2_score": 0.8856314783461302, "lm_q1q2_score": 0.8483572627160958}}
{"text": "\\section{Probability Theory}\n\n\\begin{theorem}[Laws of Set Algebra]\n    For any three sets $A$, $B$, $C$ all subsets of $S$, we have that the operators $\\cup$ and $\\cap$ are distributive, commutative, associative and satisfy DeMorgan's Laws:\n    \\begin{align*}\n        \\comp{(A \\cup B)} &= \\comp{A} \\cap \\comp{B} \\\\\n        \\comp{(A \\cap B)} &= \\comp{A} \\cup \\comp{B}\n    \\end{align*}\n\\end{theorem}\n\n\\begin{definition}[Sigma Algebra]\n    A collections of subsets S is calles a \\emph{sigma algebra} (or \\emph{Borel Field}), denoted by $\\B{}$, if it has the following three properties:\n    \\begin{enumerate}[a.]\n        \\item $\\emptyset \\in \\B{}$\n        \\item $A \\in \\B{} \\implies \\comp{A} \\in \\B{}$\n        \\item If $A_i \\in \\B{}$ for $i$ in $\\mathcal{I}$ then $\\cup_{i\\in\\mathcal{I}}A_i \\in \\B{}$, where $\\mathcal{I}$ is countable. So $\\B{}$ is closed under countable union.\n    \\end{enumerate}\n\\end{definition}\n\nNote that from DeMorgan's laws we have\n\\begin{equation}\n    \\comp{\\left(\\bigcup_{i=1}^\\infty \\comp{A_i}\\right)} = \\bigcap_{i=1}^\\infty A_i\n\\end{equation}\nwhich means that, using b. we get $\\B{}$ is also closed under countable intersections $\\cap_{i=1}^\\infty A_i \\in \\B{}$.\n\n\\begin{definition}[Kolmogorov Axioms]\n    Given a sample space $S$ and an associated sigma algebra $\\B{}$, a \\emph{probability function} is a function $\\P{}$ with domain $\\B{}$ that satisfies\n    \\begin{enumerate}\n        \\item $\\P{}(A) \\geq 0 \\quad \\forall A \\in \\B{}$\n        \\item $\\P{}(S) = 1$\n        \\item If $A_1, A_2, \\dots \\in \\B{}$ are pairwise disjoint, then $\\P{}(\\cup_{i=1}^\\infty A_i = \\sum_{i=1}^{\\infty})\\P{}(A_i)$\n    \\end{enumerate}\n\\end{definition}\n\nThe following result makes it a bit easier to find probability functions.\n\n\\begin{theorem}\n    Let $S=\\{s_1, s_2, \\dots\\}$ be a countable set. Let $\\B{}$ be any sigma algebra of subsets of $S$. Let $p_1, p_2, \\dots$ be nonnegative numbers that sum to 1. For any $A \\in \\B{}$, define $\\P{}(A)$ by\n    \\[\n        \\P{}(A) = \\sum_{\\{i: s_i \\in A\\}} p_i.\n    \\]\nThen $\\P{}$ is a probability function on $\\B{}$.\n\\end{theorem}\n\n\\begin{definition}[Random Variable]\n    A \\emph{random variable} is a function from a sample space $S$ into the real numbers.\n\\end{definition}\n\n\\begin{definition}[cdf]\n    The \\emph{cumulative distribution function} of \\emph{cdf} of a random variable $X$ is defined by\n    \\[\n        F_X(x) = \\P{}_X(X \\leq x) \\quad \\forall x\n    \\]\n\\end{definition}\n\n\\begin{theorem}\n    The function $F(x)$ is a cdf if and only if:\n    \\begin{enumerate}\n        \\item $\\lim_{x \\to - \\infty} F(x) = 0$ and $\\lim_{x\\to\\infty} F(x) = 1$.\n        \\item $F(x)$ is a non-decreasing function of x.\n        \\item $F(x)$ is right-continuous, that is, for every number $x_0$, $\\lim_{x\\downarrow x_0} F(x) = F(x_0)$\n    \\end{enumerate}\n\\end{theorem}\n\nWe say that a random variable is continuous if its cdf is continuous, and we say that it is discrete if its cdf is a step function.\n\n\\begin{theorem}\n    The following statements are equivalent:\n    \\begin{enumerate}\n        \\item $X$ and $Y$ are identically distributed\n        \\item $F_X(x) = F_Y(x) \\quad \\forall x$\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{definition}[probability mass function]\n    The \\emph{probability mass function} or \\emph{pmf} of a discrete random variable $X$ is\n    \\[\n        f_X(x) = P(X=x) \\quad \\forall x\n    \\]\n\\end{definition}\n\n\\begin{definition}[probability density function]\n    The \\emph{probability density function} or \\emph{pdf} of a continuous random variable $X$ is the function $f_X(x)$ that satisfies\n    \\[\n        F_X(x) = \\int_{-\\infty}^{x}f_X(t) \\d{} t \\quad \\forall x\n    \\]\n\\end{definition}\n\n\\begin{theorem}\n    A function $f_X(x)$ is a pdf (of pmf) of a random variable $X$ if and only if\n    \\begin{enumerate}[a.]\n        \\item $f_X(x) \\geq 0 \\quad \\forall x$\n        \\item $\\sum_x f_X(x) = 1$ (pmf) or $\\int_x f_X(x)\\d{}x = 1$ (pdf).\n    \\end{enumerate}\n\\end{theorem}\n\n\n\n\n\n\n", "meta": {"hexsha": "c6ec60dbb696e72c5e491bf8e349f42f0fb73229", "size": 3930, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter1/content.tex", "max_stars_repo_name": "brynhayder/statistical_inference", "max_stars_repo_head_hexsha": "fc3e770650e9c145aa9d45e604c9e67624c2a013", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-25T05:52:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-12T07:20:16.000Z", "max_issues_repo_path": "notes/chapters/chapter1/content.tex", "max_issues_repo_name": "brynhayder/statistical_inference", "max_issues_repo_head_hexsha": "fc3e770650e9c145aa9d45e604c9e67624c2a013", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-17T15:44:01.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-24T09:31:29.000Z", "max_forks_repo_path": "notes/chapters/chapter1/content.tex", "max_forks_repo_name": "brynhayder/statistical_inference", "max_forks_repo_head_hexsha": "fc3e770650e9c145aa9d45e604c9e67624c2a013", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-29T11:11:32.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-17T09:47:07.000Z", "avg_line_length": 38.5294117647, "max_line_length": 204, "alphanum_fraction": 0.6259541985, "num_tokens": 1326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693716759488, "lm_q2_score": 0.8933094074745443, "lm_q1q2_score": 0.8483485837085646}}
{"text": "\n\\subsection{Length of a curve}\n\nWe have a curve from \\(a\\) to \\(b\\) in \\(\\mathbf R^n\\).\n\n\\(f:[a,b]\\rightarrow \\mathbf R^n\\)\n\nWe divide this into \\(n\\) segments.\n\nThe \\(i\\)th cut is at:\n\n\\(t_i=a+\\dfrac{i}{n}(b-a)\\)\n\nSo the first cut is at:\n\n\\(t_0=a\\)\n\n\\(t_n=b\\)\n\nThe distance between two sequential cuts is:\n\n\\(||f(t_i)-f(t_{i-1}||\\)\n\nThe sum of all these differences is:\n\n\\(L=\\sum_{i=1}^n ||f(t_{i})-f(t_{i-1})||\\)\n\nThe limit is:\n\n\\(L=\\lim_{n\\rightarrow \\infty }\\sum_{i=1}^n ||f(t_{i})-f(t_{i-1})||\\)\n\\subsubsection{Method 1}\n\n\\(L=\\lim_{n\\rightarrow \\infty }\\sum_{i=1}^n ||f(t_{i})-f(t_{i-1})||\\)\n\n\\(L=\\lim_{n\\rightarrow \\infty }\\sum_{i=1}^n ||\\dfrac{f(t_{i})-f(t_{i-1})}{\\Delta t}||\\Delta t\\)\n\n\\(L=\\lim_{n\\rightarrow \\infty }\\sum_{i=1}^n ||f'(t)||\\Delta t\\)\n\n\\(L=\\int_a^b ||f'(t)||dt\\)\n\n\\subsubsection{Method 2}\n\n\\(L=\\lim_{n\\rightarrow \\infty }\\sum_{i=1}^n ||f(t_{i})-f(t_{i-1})||\\)\n\n\\(L=\\lim_{n\\rightarrow \\infty }\\sum_{i=1}^n \\sqrt {(f(t_{i})-f(t_{i-1}))^*M(f(t_{i})-f(t_{i-1}))}\\)\n\n\\(L=\\int_a^b \\sqrt {(dt)^TM(dt)}\\)\n\n", "meta": {"hexsha": "e8be6c55218384a386b8f9f82bc50557d34f1d7b", "size": 1023, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/multiFunctions/01-04-length.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/multiFunctions/01-04-length.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/multiFunctions/01-04-length.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.8775510204, "max_line_length": 99, "alphanum_fraction": 0.5601173021, "num_tokens": 453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693659780479, "lm_q2_score": 0.8933093975331751, "lm_q1q2_score": 0.8483485691775623}}
{"text": "One way of visualizing some relations is by using a directed graph, which we define below.\n\n\\begin{definition}\nA \\textbf{directed graph} consists of two sets $V$ and $E \\subset V \\times V$. The set $V$ is called the set of vertices and the set $E$ is called the set of (directed) edges. \n\\end{definition}\n\nWe can visualize a directed graph as follows. For visual purposes and a concrete example, we will consider the directed graph $V = \\{a, b, c\\}$ and $E = \\{(a, a), (a, b), (b, c), (c, c)\\}$. First, we imagine the objects of $V$ as dots.\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics{Ch3/vertices.png}\n\\end{figure}\n\nWe can imagine each object $(x, y)$ of $E$ as a ``directed arrow'' (ie an arrow) where the back end of the arrow is $x$ and the front end of the arrow is $y$. For the example graph pictured this is visualized as follows.\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics{Ch3/edges.png}\n\\end{figure}\n\nIn this way a graph can be visualized. One minor thing to observe is that any edge $(x, x)$ from an object $x$ to itself is drawn as a ``loop'' from the vertex starting at $x$ and pointing back at itself. The final thing to be observed is that any relation $R$ on a set $A$ can be seen as a graph. In this case, we take the vertices to be the set $A$ and we take the set of edges to be the set $R \\subset A \\times A$. We call this graph the \\textbf{associated graph} of the relation $R$.\n\n\\begin{example}\\label{gp1}\nSuppose that a relation $R$ is transitive. Recall that a relation $R$ is transitive if for all $a, b, c \\in A$, $(a, b) \\in R, (b, c) \\in R \\implies (a, c) \\in R$. What does this mean for its associated graph? Suppose then we have $a, b, c \\in A$ with $(a, b) \\in R, (b, c) \\in R$. Then $(a, c) \\in R$. A consequence of this is that if we have a chain of arrows from $a$ to $c$ then by transitivity there must be an arrow from $a$ to $c$ itself. This is illustrated in the picture below.\n\\end{example}\n\\begin{figure}[ht]\n\\centering\n\\includegraphics{Ch3/transitivity.png}\n\\end{figure}\n\n%remark. For any a in R transitivity implies that any vertex that can be reached by ``travelling'' through $a$ can be reached through a in one step (this might require induction `formally').\n\n\\subsubsection{Exercises}\n\n\\include{Ch3/rgraph_exercises}", "meta": {"hexsha": "3eae063c7156d369e06a4718a284b07e76e1b266", "size": 2274, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch3/rgraph.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch3/rgraph.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch3/rgraph.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.9714285714, "max_line_length": 487, "alphanum_fraction": 0.7106420405, "num_tokens": 676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422227627597, "lm_q2_score": 0.8918110440002045, "lm_q1q2_score": 0.8482391386747318}}
{"text": "\\chapter{Linear Maps}\n\\section{Vector spaces}\nA vector space over a field \\(F\\) is a set \\(V\\) that is closed under vector addition (+) and scalar multiplication (\\( \\cdot \\)). A vecotr space must fulfill following axioms:\n\\begin{align}\n    \\begin{split}\n        v, w, u \\in V \\\\\n        \\alpha, \\beta \\in F \\\\\n        v + w = u  \\\\\n        \\alpha \\cdot v = u \\\\\n        (\\alpha \\cdot \\beta) \\cdot v = \\alpha \\cdot (\\beta \\cdot v)      \\\\\n        \\alpha (v + w) = \\alpha \\cdot v + \\alpha \\cdot w              \\\\\n        (\\alpha + \\beta) \\cdot w = \\alpha \\cdot v + \\beta \\cdot w \\\\\n        1 \\cdot v = w\n    \\end{split}\n\\end{align}\nThe vector addition \\((V,+)\\) form a commutative group.\n\\begin{align*}\n    (v + w) + u = v + (w + z) \\tag*{Associativity} \\\\\n    v + 0 = V \\tag*{Identity element: zero vector} \\\\\n    v + w = 0 \\tag*{Inverse element}               \\\\\n    v + w  = w + v \\tag*{Commutativity}            \\\\\n\\end{align*}\n\\( (F, +, \\cdot)\\) form a field.\n\\begin{align*}\n    a, a^{-1}, b, c \\in F                                                         \\\\\n    (a + b) + c = a + (b + c) \\tag*{Additive associativity}                       \\\\\n    a + a^{-1} = 0 \\tag*{Additive inverse}                                        \\\\\n    a + 0 = a \\tag*{Additive identity}                                            \\\\\n    a + b = b + a \\tag*{Additive commutativity}                                   \\\\\n    (a \\cdot b) \\cdot c = a \\cdot (b \\cdot c)  \\tag*{Mulitlicative associativity} \\\\\n    a \\cdot a^{-1} = 1, a^{-1} \\neq 0 \\tag*{Mulitlicative inverse}                \\\\\n    a  \\cdot 1 = a \\tag*{Multiplicative identity}                                 \\\\\n    a \\cdot b = b \\cdot a \\tag*{Mulitplicative commutativity}                     \\\\\n    a \\cdot (b + c) = a\\cdot b + \\cdot c \\tag*{Distibutivity}\n\\end{align*}\nExample for fields: \\((\\mathbb{R}, +, \\cdot)\\) \\( (\\mathbb{C}, +, \\cdot)\\) \\\\\nExample for non fields: \\((\\mathbb{N}, +, \\cdot)\\) \\( (\\mathbb{Z}, +, \\cdot)\\) \\\\\n\\subsection{Subspace}\nLet \\(V\\) be a vector space ofer a field \\(F\\). A subspace \\(W\\) is a subset of \\(V\\) that also form a vector space over \\(F\\).\n\\begin{example}\n    \\(\\mathbb{R}^2\\) is a vector space over \\(\\mathbb{R}\\).\n    \\begin{align*}\n        W = \\setb{c \\cdot \\begin{bmatrix}\n                1 \\\\2\n            \\end{bmatrix}\n        }{c \\in \\mathbb{R}} = \\{ \\dots \\begin{bmatrix}\n            -1 \\\\ -2\n        \\end{bmatrix}, \\begin{bmatrix}\n            1 \\\\2\n        \\end{bmatrix}, \\begin{bmatrix}\n            2 \\\\4\n        \\end{bmatrix},\\begin{bmatrix}\n            2.4 \\\\ 4.8\n        \\end{bmatrix} \\dots\n        \\}\n    \\end{align*}\n\\end{example}\n\\subsubsection{Direct sum}\nLet \\(V\\) be a vector space ofer a field \\(F\\)  and \\(W\\) and \\(U\\) subspaces of \\(V\\)\nWhen:\n\\begin{align}\n    W \\cap U & = \\{ 0 \\} \\\\\n    W \\cup U & = V\n\\end{align}\nThen \\(U\\) and \\(W\\) are a direct sum of \\(V\\). It is denoted by\n\\begin{equation}\n    V = U \\oplus W\n\\end{equation}\n\\subsection{Span, (lineare H\u00fclle)}\nLet \\(V\\) be a vector space ofer a field \\(F\\) and \\(S\\) a finite subset of \\(V\\) wiht length \\(n\\). The span of \\(S\\) is the set of vectors that can be created by linear combinations with the vectors in \\(S\\).\n\\begin{equation}\n    span(S) = \\setb{\n        \\sum_{i=1}^{n} a_i \\cdot s_i\n    }{n \\in \\mathbb{N}, a_i \\in F, s_i \\in S}\n\\end{equation}\n\\begin{example}\n    \\begin{align*}\n        S        & = \\{\n        \\begin{bmatrix}\n            1 \\\\ 0 \\\\ 0\n        \\end{bmatrix},\n        \\begin{bmatrix}\n            0 \\\\ 1 \\\\ 0\n        \\end{bmatrix}\n        \\}                   \\\\\n        \\vspan S & =  \\setb{\n            a_1\n            \\begin{bmatrix}\n                1 \\\\ 0 \\\\ 0\n            \\end{bmatrix} + a_2\n            \\begin{bmatrix}\n                0 \\\\ 1 \\\\ 0\n            \\end{bmatrix}\n            \\\n        }{a_1, a_2 \\in \\mathbb{R}}\n    \\end{align*}\n\\end{example}\n\\subsubsection{Spanning set}\nLet \\(V\\) be a vector space ofer a field \\(F\\) and \\(S\\) a finite subset of \\(V\\). \\(S\\) is a spanning set of if\n\\begin{equation}\n    \\vspan S = V\n\\end{equation}\n\\begin{example}\n    Let \\(V\\) be \\(\\mathbb{R}^2\\) over the field \\(\\mathbb{R}\\). Following subsets are spanning set of \\(V\\):\n    \\begin{align*}\n        S_1 & = \\{ \\begin{bmatrix}\n            1 \\\\ 0\n        \\end{bmatrix},\n        \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\n        \\}                                     \\\\\n        S_2 & = \\{ \\begin{bmatrix}\n            3 \\\\ 0\n        \\end{bmatrix},\n        \\begin{bmatrix} 0 \\\\ 2 \\end{bmatrix}\n        \\}                                     \\\\\n        S_3 & = \\{ \\begin{bmatrix}\n            3 \\\\ 0\n        \\end{bmatrix},\n        \\begin{bmatrix} 0 \\\\ 2 \\end{bmatrix},\n        \\begin{bmatrix} 1 \\\\ 2 \\end{bmatrix}\n        \\}\n    \\end{align*}\n\\end{example}\n\\subsection{Base}\nLet \\(V\\) be a vector space ofer a field \\(F\\) and \\(B\\) a spanning set of \\(V\\). If the elements of \\(B\\) are lineary independent then \\(B\\) is called a basis.\nThe coefficients of the linear combination are referred to as components or coordinates of the vector with respect to \\(B\\).\nThe elements of \\(B\\) are called basis vectors.\n\\begin{example}\n    Let \\(V\\) be \\(\\mathbb{R}^2\\) over the field \\(\\mathbb{R}\\). Following subsets are spanning set of \\(V\\):\n    \\begin{align*}\n        B_1 & = \\{ \\begin{bmatrix}\n            1 \\\\ 0\n        \\end{bmatrix},\n        \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\n        \\}                                     \\\\\n        B_2 & = \\{ \\begin{bmatrix}\n            3 \\\\ 0\n        \\end{bmatrix},\n        \\begin{bmatrix} 0 \\\\ 2 \\end{bmatrix}\n        \\}                                     \\\\\n    \\end{align*}\n    In previous example \\(S_3\\) is not a valid base, because its elements are lineary dependent.\n\\end{example}\n\\subsubsection{Standard base}\nA base \\(B\\) is called a Standard base if the vecotors of \\(B\\) are all zero, except one that equals 1. The vectors\nof the standard base are called unit vectors.\n\\begin{example}\n    The standard base for \\(\\mathbb{R}^n\\) is\n    \\begin{align*}\n        \\hat{i} & = \\begin{bmatrix}\n            1 \\\\ 0 \\\\ 0\n        \\end{bmatrix}, \\hat{j} = \\begin{bmatrix}\n            0 \\\\ 1 \\\\ 0\n        \\end{bmatrix}, \\hat{k} = \\begin{bmatrix}\n            0 \\\\ 0 \\\\ 1\n        \\end{bmatrix} \\\\\n        B       & = \\{ \\hat{i}, \\hat{j}, \\hat{k} \\}\n    \\end{align*}\n    A vector \\(v\\) expressed in the standard basis \\(B\\).\n    \\begin{align*}\n        v = \\begin{bmatrix}\n            4 \\\\ 5 \\\\ 6\n        \\end{bmatrix}= 4 \\hat{i} + 5  \\hat{j} + 6  \\hat{k}\n    \\end{align*}\n\\end{example}\n\\subsection{Dimension}\\label{dimension}\nThe dimension \\( \\dim \\) of a vector space is the size of its base \\(B\\). The dimension\nis equal to the rank (see \\ref{rank}) of the tranformation matrix.\n\\begin{example}\n    The vector space \\(\\mathbb{R}^n\\)\n    \\begin{align*}\n        \\dim \\mathbb{R}^n = n\n    \\end{align*}\n\\end{example}\n\\begin{example}\n    \\begin{align*}\n        V      & = \\setb{\n            c_1\n            \\begin{bmatrix}\n                1 \\\\ 0 \\\\ 0 \\\\ 0\n            \\end{bmatrix},\n            c_2\n            \\begin{bmatrix}\n                0 \\\\ 1 \\\\ 0 \\\\ 0\n            \\end{bmatrix}\n        }{c_1, c_2 \\in \\mathbb{R}} \\\\\n        \\dim V & = 2\n    \\end{align*}\n\\end{example}\n\\begin{example}\n    \\begin{align*}\n        V      & = \\setb{\n            c_1\n            \\begin{bmatrix}\n                1 \\\\ 1 \\\\ 0 \\\\ 0\n            \\end{bmatrix},\n            c_2\n            \\begin{bmatrix}\n                0 \\\\ 1 \\\\ 0 \\\\ 0\n            \\end{bmatrix}\n        }{c_1, c_2 \\in \\mathbb{R}} \\\\\n        \\dim V & = 1\n    \\end{align*}\n\\end{example}\n\\begin{example}\n    The only vector space with dimension 0 is where V contains only the zero vector.\n    \\begin{align*}\n        \\dim \\{ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\end{bmatrix}\\} = 0\n    \\end{align*}\n\n\\end{example}\nsection{Linear maps}\nLet \\(V\\) \\(W\\) be vector spaces over the same field \\(F\\).\nA function \\(f: V \\rightarrow W\\) is said to be a linear map if for any two vectors \\(v, u \\in V\\) and any scalar \\(c \\in F\\) the following two conditions are satisfied:\n\\begin{align}\n    f(u + v)     & = f(u) + f(v) \\tag{Additvity} \\\\\n    f(c \\cdot u) & = c \\cdot u \\tag{Homogenity}\n\\end{align}\n\\subsection{Transformation matrix}\nEach linear transformation can be represented as a matrix vector multiplication.\n\\begin{align*}\n    f      & : W \\rightarrow V  \\\\\n    \\dim W & = n, \\dim V = m    \\\\\n    f(x)   & = A^{m \\times n} x \\\\\n\\end{align*}\n\\begin{example}\n    \\begin{align*}\n        f(x)                                       &\n        = \\begin{bmatrix}\n            1 & 2 & 3 \\\\ 5 & 7 & 9\n        \\end{bmatrix} \\begin{bmatrix}\n            x_1 \\\\ x_2 \\\\ x_3\n        \\end{bmatrix}                   \\\\\n        f \\left(\\begin{bmatrix}\n            5 \\\\ 6 \\\\ 7\n        \\end{bmatrix} \\right) & = \\begin{bmatrix}\n            38 \\\\ 130\n        \\end{bmatrix}\n    \\end{align*}\n\\end{example}\n\\subsubsection{Composition}\nIf there are two linear maps \\(f, g\\) wiht tranformation matrices:\n\\begin{align*}\n    f : V \\rightarrow W  = Ax \\\\\n    g : U \\rightarrow V = Bx\n\\end{align*}\nthen the compostition is:\n\\begin{align*}\n    h : U \\rightarrow W = f \\circ g \\\\\n    h(x) = A(Bx) = (A \\cdot B)x\n\\end{align*}\n\\begin{example}\n    \\begin{align*}\n        f(x)                                        & = \\begin{bmatrix}\n            1 & 2 & 3 \\\\ 5 & 7 & 9\n        \\end{bmatrix} \\cdot x                                                                             \\\\\n        g(x)                                        & = \\begin{bmatrix}\n            -1 & -2 \\\\ -7 & -9 \\\\ 13 & 17\n        \\end{bmatrix} \\cdot x                                                                             \\\\\n        h(x)                                        & = f \\circ g = \\begin{bmatrix}\n            1 & 2 & 3 \\\\ 5 & 7 & 9\n        \\end{bmatrix} \\begin{bmatrix}\n            -1 & -2 \\\\ -7 & -9 \\\\ 13 & 17\n        \\end{bmatrix} \\cdot x = \\begin{bmatrix}\n            24 & 31 \\\\ 64  & 80\n        \\end{bmatrix} \\cdot x \\\\\n        g \\left( \\begin{bmatrix}\n            3 \\\\ 4\n        \\end{bmatrix} \\right) & = \\begin{bmatrix}\n            -11 \\\\ -57 \\\\ 107\n        \\end{bmatrix}, f \\left( \\begin{bmatrix}\n            -11 \\\\ -57 \\\\ 107\n        \\end{bmatrix} \\right) = \\begin{bmatrix}\n            196 \\\\ 509\n        \\end{bmatrix}           \\\\\n        h(\\begin{bmatrix}\n            3 \\\\ 4\n        \\end{bmatrix})               & = \\begin{bmatrix}\n            196 \\\\ 509\n        \\end{bmatrix}\n    \\end{align*}\n\\end{example}\n\\subsection{Image (Bild)}\nThe image \\(f^{\\rightarrow}\\) of a tranformation \\(L: V \\rightarrow W \\) is the set of vectors that the tranformation can produce.\n\\begin{equation}\n    f^{\\rightarrow} (L)  = \\setb{L(x)}{x \\in V}\n\\end{equation}\nThe image is the columnspan of the tranformation matrix. The dimenson of the image ist called \\textbf{rank}, and is the\nsame as the rank of the transformation matrix.\n\\begin{example}\n    \\begin{align*}\n        L(x)                & = \\begin{bmatrix}\n            1 & 0 \\\\\n            0 & 1 \\\\\n        \\end{bmatrix}x \\\\\n        f^{\\rightarrow} (L) & = \\mathbb{R}^2\n    \\end{align*}\n\\end{example}\n\\begin{example}\n    \\begin{align*}\n        L(x)                & = \\begin{bmatrix}\n            1 & 0 \\\\\n            2 & 0 \\\\\n            1 & 1 \\\\\n            0 & 2 \\\\\n        \\end{bmatrix}x      \\\\\n        f^{\\rightarrow} (L) & = \\setb{\\begin{bmatrix}\n                c_1 \\\\ 2c_1 \\\\ c_1 + c_2 \\\\ 2 c_2\n            \\end{bmatrix}\n        }{c_1, c_2 \\in \\mathbb{R}}\n    \\end{align*}\n\\end{example}\n\\subsection{Kernel, Null Space (Kern)}\\label{kernel}\nThe kernel of a linear map \\(L: V \\rightarrow W \\) is the linear subspace of the domain of the map which is mapped to the zero vector.\n\\begin{equation}\n    \\ker L = \\{ v \\in V | L(v) = 0 \\} \\\\\n\\end{equation}\n\nThe vecots of the kernel are the set of vectors that yield the zero vector after multiplication with the tranformation matrx.\n\\begin{align*}\n    L  & : Ax = y                          \\\\\n    x' & \\in \\ker L  \\textbf{ if } Ax' = 0\n\\end{align*}\nThe kernel forms a subspace of \\( V \\):\n\\begin{align*}\n    v, u \\in \\ker L, \\alpha \\in \\mathbb{F} \\\\\n    \\alpha v \\in \\ker L                    \\\\\n    v + u \\in \\ker L                       \\\\\n\\end{align*}\nThe dimension of the kernel is called the \\textbf{nullity}.\n\\begin{example}\n    \\begin{align*}\n        L & : Ax = y                        \\\\\n        A & =  \\begin{bmatrix}\n            1 & -1, & 0 \\\\\n            0 & -2  & 4 \\\\\n        \\end{bmatrix} & \\\\\n    \\end{align*}\n    To calculate \\( \\ker A\\) simply set \\(y\\) to the zero vector and solve for \\(x\\).\n    \\begin{align*}\n        \\begin{bmatrix}\n            1 & -1, & 0 \\\\\n            0 & -2  & 4 \\\\\n        \\end{bmatrix} \\begin{bmatrix}\n            x_1 \\\\\n            x_2 \\\\\n            x_3 \\\\\n        \\end{bmatrix} = \\begin{bmatrix}\n            0 \\\\ 0 \\\\ 0\n        \\end{bmatrix} \\\\\n        x_1 - x_2       = 0 \\rightarrow x_1 = x_2                                          \\\\\n        -2 x_2 + 4 x_3  = 0 \\rightarrow x_2 = 2 x_3                                        \\\\\n    \\end{align*}\n    The kernel is:\n    \\begin{align*}\n        \\ker L & = \\setb{\n            c \\cdot \\begin{bmatrix}\n                2 \\\\ 2 \\\\ 1\n            \\end{bmatrix}\n        }{c \\in \\mathbb{C} }\n    \\end{align*}\n    A concrete example:\n    \\begin{align*}\n        \\begin{bmatrix}\n            4 \\\\ 4 \\\\ 2\n        \\end{bmatrix}                 & \\in \\ker L                                                \\\\\n        L \\left(\\begin{bmatrix}\n            4 \\\\ 4 \\\\ 2\n        \\end{bmatrix} \\right) & = \\begin{bmatrix}\n            1 \\cdot 4  -1 \\cdot 4  + 0 \\cdot 2 \\\\\n            0 \\cdot 4  -2 \\cdot 4 + 4 \\cdot 2  \\\\\n        \\end{bmatrix} = \\begin{bmatrix}\n            0 \\\\ 0\n        \\end{bmatrix} \\\\\n    \\end{align*}\n    \\begin{example}\n\n    \\end{example}\n    \\section{Rank-Nullity theorem}\n    If \\(L : V \\rightarrow W\\) is a linear tranformation then it.\n    \\begin{equation}\n        \\rank L + \\nullity T = \\dim (image T) + \\dim(\\ker(T)) = \\dim(V)\n    \\end{equation}\n    \\begin{example}\n        \\begin{align*}\n            L          & : \\begin{bmatrix}\n                1 & 0 \\\\ 0 & 1\n            \\end{bmatrix} x = y \\\\\n            image T    & = \\mathbb{R}^2                     \\\\\n            \\rank L    & = 2                                \\\\\n            \\ker T     & = \\{ \\begin{bmatrix}\n                0 \\\\ 0\n            \\end{bmatrix} \\} \\\\\n            \\nullity L & = 0                                \\\\\n            \\dim V     & = \\rank L + \\nullity T = 2 +0 = 2\n        \\end{align*}\n    \\end{example}\n    \\begin{example}\n        \\begin{align*}\n            L      & : \\begin{bmatrix}\n                1 & 2 & 4 \\\\ 2 & 4 & 8\n            \\end{bmatrix} x = y \\\\\n            imag L & = \\setb{\n                \\begin{bmatrix}\n                    c \\\\ 2 c\n                \\end{bmatrix}\n            }{c \\in \\mathbb{R}}\n        \\end{align*}\n        \\begin{align*}\n            \\rank L = 1 \\\\\n            \\ker L = \\setb{\n                \\begin{bmatrix}\n                    -2 c_1 - 4 c_2 \\\\ c_1 \\\\  c_2\n                \\end{bmatrix}\n            }{ c_1, c_2 \\in \\mathbb{R}}\n            \\nullity A = 2\n        \\end{align*}\n    \\end{example}\n\\end{example}", "meta": {"hexsha": "666e4ee265b2fc42d7f7ef2466c4257b07911fa7", "size": 15131, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/liner_maps.tex", "max_stars_repo_name": "KriCse/Math-knowledge", "max_stars_repo_head_hexsha": "92c036c4563999ddaa97888a4023297e22bb7649", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/liner_maps.tex", "max_issues_repo_name": "KriCse/Math-knowledge", "max_issues_repo_head_hexsha": "92c036c4563999ddaa97888a4023297e22bb7649", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/liner_maps.tex", "max_forks_repo_name": "KriCse/Math-knowledge", "max_forks_repo_head_hexsha": "92c036c4563999ddaa97888a4023297e22bb7649", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.1121718377, "max_line_length": 210, "alphanum_fraction": 0.4562818056, "num_tokens": 4863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422213778251, "lm_q2_score": 0.8918110432813418, "lm_q1q2_score": 0.8482391367558911}}
{"text": "\\section{The symmetric group}\nGiven a set $X$, the class of all bijections $\\pi \\in Bij(X,X)$ is called the symmetric group\n$$S(X),\\ \\tmr{or}\\ S_X.$$\nIn particular, given the integer interval $N := \\{1,\\ldots,n\\} \\subset \\zz$ we call\n$$S_N := S_n$$\nthe $n$-th symmetric group.\n\\subsection{Representation theory of $S_n$}\nThe first to mention is the \n\\subsubsection{Trivial representation of $S_n$}\nGiven a unital commutative ring $R$, then the pair $(R,\\rho_R)$\n$$S_n \\ni \\pi \\stackrel{\\rho_R}{\\longmapsto} 1_R$$\nis called the trivial representation of $S_n$. We only mention it for completeness - as it will be used later on.\n\\subsubsection{Permutation representation of $S_n$}\nGiven $R$ and $S_n$ as above, we call\n$$(M,\\rho_{\\tmr{perm}}),\\ M = R^n,\\ \\pi \\longmapsto \\sum_{i=1}^n e_{\\pi(i)i}$$\nthe permutation representation of $S_n$. Note, that although most often $R$ to be an algebraic field it need not be - $\\zz$ as the initial object in the category of unital rings is sufficient.\n\\subsubsection{Standard representation of $S_n$}\nAgain, $R$, $S_n$ and now $M$ as above - we get \n$$(M',\\rho_{\\tmr{std}}),\\ M' = \\left<e_i - e_n : 1 \\leq i \\leq n - 1\\right> \\subsetneq M,\\ \\pi \\longmapsto \\left[\\sum_i^{n-1} \\lambda_i \\alpha_i \\longmapsto \\sum_i \\lambda_i \\right]$$\nthe standard representation. Here, $e_i$ denotes the canonical generators of $M$ and $\\alpha_i = e_i - e_n$ are our generators. Let us expand:\n$$\\sum_i \\lambda_i \\alpha_i = \\sum_i \\lambda_i (e_i - e_n)\\longmapsto \\sum_i \\lambda_i (e_{\\pi(i)} - e_{\\pi(n)}) ) = \\sum_i \\lambda_i(e_{\\pi(i)} - e_n + e_n - e_{\\pi(n)}) = \\sum_i \\lambda_i (\\alpha_{\\pi(i)} - \\alpha_{\\pi(n)})$$\nIn this context, $\\alpha_{\\pi(n)}$ is simply either zero if $\\pi(n) = n$, otherwise $\\pi(n) < n$ and thus there is an element $\\alpha_{\\pi(n)}$. I.e.:\n$$\\alpha_i \\longmapsto \\alpha_{\\pi(i)} - (1 - \\delta_{\\pi(n),n}) \\alpha_{\\pi(n)}\\ \\forall 1 \\leq i \\leq n - 1.$$ \nIn conclusion:\n$$\\pi \\longmapsto \\sum_{i=1}^{n-1} \\left(f_{\\pi(i)i} - (1 - \\delta_{\\pi(n),n}) f_{\\pi(n)i}\\right)$$\nwhere $f_{ji} = [\\alpha_i \\longmapsto \\alpha_j] \\in \\tmr{End}_R(M')\\ \\forall 1 \\leq i,j \\leq n - 1$.\nThe alert reader will have noticed that we already employed the following\n\\begin{prop} The permutation representation $(M,\\rho_{\\tmr{perm}})$ decomposes into the trivial and standard representation:\n$$(M,\\rho_{\\tmr{perm}}) = (M',\\rho_{\\tmr{std}}) \\oplus  (M'',\\rho_{\\tmr{trivial}}).$$\n\\end{prop}\nWe already saw that $M'$ is an $S_n$ submodule of $M$. The trivial representation is given by\n$$M'' := \\left<\\sum_{i=1}^n e_i\\right>$$\nand the fact that any $\\pi \\in S_n$ operates trivially on $\\sum_i e_i$ (i.e. just a reshuffle of the summands).", "meta": {"hexsha": "b3750648e96e13915ada10b2fb607cd414ef1caa", "size": 2665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "symm_grp_rep/symmetric.tex", "max_stars_repo_name": "gmuel/texlib", "max_stars_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "symm_grp_rep/symmetric.tex", "max_issues_repo_name": "gmuel/texlib", "max_issues_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "symm_grp_rep/symmetric.tex", "max_forks_repo_name": "gmuel/texlib", "max_forks_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 80.7575757576, "max_line_length": 227, "alphanum_fraction": 0.6682926829, "num_tokens": 946, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813538993889, "lm_q2_score": 0.8872045847699185, "lm_q1q2_score": 0.8481510401340918}}
{"text": "\\section{Mean Value Theorem for Derivatives}\r\n\\begin{theorem}[Mean Value Theorem for Derivatives]\r\n\tIf $f$ is continuous on the interval $[a,b]$ and differentiable on the interval $(a,b)$, then there exists at least one point in $(a,b)$ such that\r\n\t\\begin{equation*}\r\n\t\tf^\\prime(c) = \\frac{f(b)-f(a)}{b-a}.\r\n\t\\end{equation*}\r\n\\end{theorem}\r\n\r\nThat is, there's at least one point where the instantaneous rate of change and average rate of change are equal.\r\nAnother way of visualizing this is that there's al least one point where the tangent and secant lines are parallel.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{mvt}\r\n\t\\centering\r\n\t\\includegraphics[width = 0.5\\textwidth]{./applications_derivative/mvt.png}\r\n\t\\caption{\\hyperref{https://en.wikipedia.org/wiki/Mean\\_value\\_theorem}{}{}{Wikipedia - Mean Value Theorem}}\r\n\\end{figure}\r\n\r\n\\begin{example}\r\n\tA trucker drives 150 miles of a route in 2 hours.\r\n\tThe speed limit along the route is 65 miles per hour.\r\n\tShow that at at least one point, the trucker must have been speeding.\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe can model the trucker's position along the route $s$ as a function of time $t$ where $s(0)=0$ and $s(2)=150$.\r\n\tWe know that velocity is the derivative of position, so $v(t) = s^\\prime(t)$.\r\n\tIt's reasonable to assume that $s$ is differentiable on the interval $[0,2]$.\r\n\tSo, by the Mean Value Theorem, there must exist a point $c$ where\r\n\t\\begin{equation*}\r\n\t\tv(t) = \\frac{s(2)-s(0)}{2-0} = \\frac{150-0}{2} = 75\\text{mph}.\r\n\t\\end{equation*}\r\n\tAt this point, the trucker was exceeding the speed limit of 65 miles per hour.\r\n\\end{answer}\r\n\r\n\\begin{definition}\r\n\tLet $f$ be defined on an interval $I$.\r\n\tLet $a$ and $b$ be any two different points in $I$.\r\n\t\\begin{align*}\r\n\t\t\\text{$f$ increases on $I$ if } a < b &\\implies f(a) < f(b). \\\\\r\n\t\t\\text{$f$ decreases on $I$ if } a < b &\\implies f(a) > f(b).\r\n\t\\end{align*}\r\n\\end{definition}\r\n\r\n\\begin{corollary}\r\n\tLet $f$ be continuous of $[a,b]$ and differentiable on $(a,b)$.\r\n\t\\begin{align*}\r\n\t\t\\text{If $f^\\prime > 0$ at every point on $(a,b)$ then $f$ increases on $[a,b]$}. \\\\\r\n\t\t\\text{If $f^\\prime < 0$ at every point on $(a,b)$ then $f$ decreases on $[a,b]$}.\r\n\t\\end{align*}\r\n\\end{corollary}\r\n\r\nThis should make sense given our theorem about local extrema.\r\nIf $f$ could still increase/decrease while its derivative was negative/positive, then we couldn't be sure that $f$ is at a local maxima/minima when $f^\\prime=0$.\r\n\r\n\\begin{corollary}\r\n\tIf $f^\\prime(x) = 0$ at all points in an interval $I$, then there is some constant $C$ such that $f(x) = C$ for all points in $I$.\r\n\\end{corollary}\r\n\r\nThis follows from the Mean Value Theorem.\r\nSince $f^\\prime = 0$, the numerator in the Mean Value Theorem, $f(b) - f(a)$, must also be 0, meaning $f(b) = f(a) = C$.\r\n\r\n\\begin{corollary}\r\n\tIf $f^\\prime(x) = g^\\prime(x)$ at ever point in some interval $I$, then there is come constant $C$ such that $f(x) = g(x) + C$.\r\n\\end{corollary}\r\n\r\nThat is, functions with the same derivative differ by a constant.\r\nThis should make sense given our constant and sum and difference derivative rules.\r\nIf we let $h^\\prime(x) = f^\\prime(x) - g^\\prime(x) = 0$ and apply the previous corollary, we get $C$.\r\n\r\n\\begin{definition}\r\n\tA function $F(x)$ is the antiderivative\tof $f(x)$ if $F^\\prime(x) = f(x)$ for all points in the domain of $f$.\r\n\\end{definition}\r\n\r\nAs we saw in the previous corollary, a function will have infinitely many antiderivatives that differ by a constant.", "meta": {"hexsha": "98ea1d5851736c885d7be8b8ee755e2bad6c1fc6", "size": 3463, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/applications_derivative/mvt.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/applications_derivative/mvt.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/applications_derivative/mvt.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.7972972973, "max_line_length": 162, "alphanum_fraction": 0.6788911349, "num_tokens": 1081, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813513911655, "lm_q2_score": 0.8872045862611166, "lm_q1q2_score": 0.8481510393343421}}
{"text": "\n\\subsection{Curl}\n\nThe curl of a vector field is defined as:\n\n\\(curl \\mathbf F=\\nabla \\times \\mathbf F\\)\n\nWhere: \\(\\nabla =(\\sum_{i=1}^n e_i\\dfrac{\\delta }{\\delta x_i})\\)\n\nAnd: \\(\\mathbf x\\times \\mathbf y=\\||\\mathbf x|| ||\\mathbf y|| \\sin(\\theta )\\mathbf n\\)\n\nThe curl of a vector field is another vector field.\n\nThe curl measures the rotation about a given point. For example if a vector field is the gradient of a height map, the curl is \\(0\\) at all points, however for a rotating body of water the curl reflects the rotation at a given point.\n\n\\subsection{Divergence of the curl}\n\nIf we have a vector field \\(\\mathbf F\\), the divergence of its curl is \\(0\\):\n\n\\(\\nabla . (\\nabla \\times \\mathbf F)=0\\)\n\n", "meta": {"hexsha": "ba1bbdca2beb7f9027c9f8e82a99d0635b35fe19", "size": 707, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/multiCalculus/04-01-curl.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/multiCalculus/04-01-curl.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/multiCalculus/04-01-curl.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1363636364, "max_line_length": 233, "alphanum_fraction": 0.6916548798, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731094431571, "lm_q2_score": 0.8807970701552505, "lm_q1q2_score": 0.8479196543147777}}
{"text": "\\section{Polynomial functions}\nA very useful family of real functions can be derived using only three fundamental operations: addition, multiplication and exponentiation: the (real) \\emph{polynomial functions}. These are functions of the form\n\\begin{equation}\n\tP_{n}(x) = a_{0} + a_{1}x + a_{2}x^{2} + a_{3}x^{3} + \\cdots + a_{n}x^{n},\n\t\\label{eq:polynomial_function}\n\\end{equation}\nwhere $a_{0},a_{1},\\dots,a_{n}$ are real numbers called the \\emph{coefficients} of the polynomial function. Note that $a_{n}\\neq0$, i.e. the \\emph{degree} of the polynomial function is the index of the highest non-zero coefficient (and thus the highest power in the expression). We also call this the \\emph{order} of the polynomial function.\n\n\\begin{example}{Polynomial}{}\n\tThe following is a polynomial function of degree $n=6$:\n\t\\[\n\t\tP(x) = 4 + 2x - 3x^{2} + 7x^{4} - x^{5} + 3x^{6}.\n\t\\]\n\n\tBreaking down this polynomial to its constituent terms:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}[node distance=15mm]\n\t\t\t\\node (P) {$P(x)=$};\n\t\t\t\\node[right of=P]  (x0) {$4$};\n\t\t\t\\node[right of=x0] (x1) {$+2x$};\n\t\t\t\\node[right of=x1] (x2) {$-3x^{2}$};\n\t\t\t\\node[right of=x2] (x4) {$+7x^{4}$};\n\t\t\t\\node[right of=x4] (x5) {$-x^{5}$};\n\t\t\t\\node[right of=x5] (x6) {$+3x^{6}$};\n\t\t\t\n\t\t\t\\node[below of=x0] (a0) {$a_{0}=4$};\n\t\t\t\\node[below of=x1] (a1) {$a_{1}=2$};\n\t\t\t\\node[below of=x2] (a2) {$a_{2}=-3$};\n\t\t\t\\node[below of=x4] (a4) {$a_{4}=7$};\n\t\t\t\\node[below of=x5] (a5) {$a_{5}=-1$};\n\t\t\t\\node[below of=x6] (a6) {$a_{6}=3$};\n\n\t\t\t\\draw[arrow, thin] (x0) -- (a0);\n\t\t\t\\draw[arrow, thin] (x1) -- (a1);\n\t\t\t\\draw[arrow, thin] (x2) -- (a2);\n\t\t\t\\draw[arrow, thin] (x4) -- (a4);\n\t\t\t\\draw[arrow, thin] (x5) -- (a5);\n\t\t\t\\draw[arrow, thin] (x6) -- (a6);\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\n\tNote that $a_{3}$ is missing from the polynomial function (i.e. there is no $x^{3}$ term). This means that $a_{3}=0$.\n\\end{example}\n\nA shorthand way to write the general form of a polynomial function is by using the \\emph{summation notation}:\n\\begin{equation}\n\tP(x) = \\sum\\limits_{k=0}^{n}a_{k}x^{k}.\n\t\\label{eq:summation_notation}\n\\end{equation}\nThis notation, called the \\emph{Capital-sigma notation}, essentially represents addition of $n$ elements (in the case shown here), each with its own \\emph{index of summation}, in this case $i$. The most general form of the summation notation is\n\\begin{equation}\n\t\\sum\\limits_{i=k}^{n}a_{i} = a_{k} + a_{k+1} + a_{k+2} + \\cdots + a_{n-1} + a_{n},\n\t\\label{eq:summation_notation_general}\n\\end{equation}\ni.e. the notation tells us to add those elements $a_{i}$ for which $k\\geq i\\geq n$. Note that in the case of \\autoref{eq:summation_notation}, when $k=0,\\ x^{k}=x^{0}=1$ and the first term of the polynomial function has no $x$ power (i.e. it is simply $a_{0}$), and when $k=1,\\ x^{k}=x^{1}=x$ and thus the second term is $a_{1}x$. We will encounter the summation notation in more details later in the book.\n\nIn the special case $n=0$, i.e. when $P(x)=a_{0}$, the function is constant. When $n=1$ the function $P(x)=a_{0}+a_{1}x$ is a line, and when $n=2,\\ P(x)=a_{0}+a_{1}x+a_{2}x^{2}$ is a quadratic function.\n\n\\begin{example}{Polynomial functions for $n=0,1,2$}{special_polynomials}\n\tThe following graphs represent the polynomial functions of degrees $n=0,1,2$ with coefficients $a_{0}=2,\\ a_{1}=1,\\ a_{2}=\\frac{1}{2}$:\n\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\tikzset{flbl/.style={draw=#1, thick, fill=white, rounded corners}}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tgraph2d,\n\t\t\t\t\twidth=9cm, height=9cm,\n\t\t\t\t\txmin=-9, xmax=9,\n\t\t\t\t\tymin=-9, ymax=9,\n\t\t\t\t\tdomain=-9:9,\n\t\t\t\t\trestrict y to domain=-9:9,\n\t\t\t\t\tdeclare function={p0(\\x)=2;},\n\t\t\t\t\tdeclare function={p1(\\x)=2+\\x;},\n\t\t\t\t\tdeclare function={p2(\\x)=2+\\x+0.5*\\x^2;},\n\t\t\t\t]\n\t\t\t\t\\addplot[function, xred] {p0(x)} node[flbl=xred, below, pos=0.15, yshift=-1mm] {$P_{0}(x)=1$};\n\t\t\t\t\\addplot[function, xblue] {p1(x)} node[flbl=xblue, below, pos=0.1, rotate=45, yshift=-1mm] {$P_{1}(x)=1+x$};\n\t\t\t\t\\addplot[function, xgreen] {p2(x)} node[flbl=xgreen, right, pos=0.2, xshift=-3mm, yshift=5mm] {$P_{2}(x)=1+x+\\frac{1}{2}x^{2}$};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{example}\n\nThe values $x\\in\\mathbb{R}$ for which $P(x)=0$ are called the \\emph{roots} (also: \\emph{zeros}) of the polynomial function.\n\n\\begin{example}{Roots of a polynomial function}{}\n\tThe polynomial function $P(x) = 24x - 50x^{2} + 35x^{3} - 10x^{4} + x^{5}$ has the following $5$ roots: $x_{0}=0,\\ x_{1}=1,\\ x_{2}=2,\\ x_{3}=3,\\ x_{4}=4$. In the following graph of $P(x)$ the roots are shown as black dots.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tgraph2d,\n\t\t\t\t\twidth=9cm, height=6cm,\n\t\t\t\t\txmin=-2, xmax=5,\n\t\t\t\t\tymin=-5, ymax=5,\n\t\t\t\t\tdomain=-2:5,\n\t\t\t\t\trestrict y to domain=-6:6,\n\t\t\t\t\tdeclare function={P(\\x)=\\x*(\\x-1)*(\\x-2)*(\\x-3)*(\\x-4);},\n\t\t\t\t]\n\t\t\t\t\\addplot[function, xred] {P(x)};\n\t\t\t\t\\addplot[black, only marks, mark=*, samples at={0,1,...,4}] {P(x)};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{example}\n\nThe maximum number of \\textbf{real} roots of a polynomial function with degree $n\\geq1$ is $n$, e.g. a polynomial of degree $n=4$ has at most $4$ real roots. This statement is a consequence of a very important theorem called \\emph{the fundamental theorem of algebra}, which due to its importance we will mention here without proof:\n\n\\begin{theorem}{The fundamental theorem of algebra}{fundamental}\n\tFor any $n\\geq1$, the polynomial function $P(z)=a_{0}+a_{1}z+a_{2}z^{2}+\\cdots+a_{n}z^{n}$, where $a_{0},a_{1},a_{2},\\dots,a_{n}$ are all \\textbf{complex numbers} and $a_{n}\\neq0$, has $n$ complex roots.\n\\end{theorem}\n\nGiven a polynomial function $P(x)$ with $n$ roots $r_{1},\\ r_{2},\\ \\cdots,\\ r_{n}$, the function can be written as a product of terms of the form $x-r_{i}$ (up to a constant), e.g. the polynomial function of degree $n=3$ with roots $-1,1,2$ can be written as\n\\begin{equation}\n\tP(x) = (x+1)(x-1)(x-2) = x^{3}-2x^{2}-x+2.\n\t\\label{eq:roots_form}\n\\end{equation}\n\n\\begin{example}{Higher order polynomial functions}{high_order_polynomials}\n\tThe following are the graphs of high-order polynomial functions ($n=3,4,5,6$):\n\n\t\\begin{figure}[H]\n\t\t\\captionsetup[subfigure]{labelformat=empty}\n\t\t\\centering\n\t\t\\begin{subfigure}[b]{0.475\\textwidth}\n\t\t\t\\centering\n\t\t\t\\begin{tikzpicture}\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\t\tgraph2d,\n\t\t\t\t\t\twidth=6cm, height=6cm,\n\t\t\t\t\t\txmin=-3, xmax=3,\n\t\t\t\t\t\tymin=-3, ymax=3,\n\t\t\t\t\t\tdomain=-3:3,\n\t\t\t\t\t\trestrict y to domain=-3:3,\n\t\t\t\t\t\tdeclare function={P3(\\x)=\\x^3-\\x^2-\\x;},\n\t\t\t\t\t]\n\t\t\t\t\t\\addplot[function, xred] {P3(x)};\n\t\t\t\t\\end{axis}\n\t\t\t\\end{tikzpicture}\n\t\t\t\\caption{\\textcolor{xred}{$\\bm{x^{3}-x^{2}-x}$}}\n\t\t\\end{subfigure}\n\t\t\\hfill\n\t\t\\begin{subfigure}[b]{0.475\\textwidth}\n\t\t\t\\centering\n\t\t\t\\begin{tikzpicture}\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\t\tgraph2d,\n\t\t\t\t\t\twidth=6cm, height=6cm,\n\t\t\t\t\t\txmin=-3, xmax=3,\n\t\t\t\t\t\tymin=-3, ymax=3,\n\t\t\t\t\t\tdomain=-3:3,\n\t\t\t\t\t\trestrict y to domain=-10:10,\n\t\t\t\t\t\tdeclare function={P4(\\x)=\\x^4-3*\\x^2+\\x+1;},\n\t\t\t\t\t]\n\t\t\t\t\t\\addplot[function, xblue] {P4(x)};\n\t\t\t\t\\end{axis}\n\t\t\t\\end{tikzpicture}\n\t\t\t\\caption{\\textcolor{xblue}{$\\bm{x^{4}-3x^{2}+x+1}$}}\n\t\t\\end{subfigure}\n\n\t\t\\begin{subfigure}[b]{0.475\\textwidth}\n\t\t\t\\centering\n\t\t\t\\begin{tikzpicture}\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\t\tgraph2d,\n\t\t\t\t\t\twidth=6cm, height=6cm,\n\t\t\t\t\t\txmin=-5, xmax=5,\n\t\t\t\t\t\tymin=-5, ymax=5,\n\t\t\t\t\t\tdomain=-5:5,\n\t\t\t\t\t\trestrict y to domain=-10:10,\n\t\t\t\t\t\tdeclare function={P5(\\x)=0.03*(\\x^5+3*\\x^4-11*\\x^3-27*\\x^2+10*\\x+24);},\n\t\t\t\t\t]\n\t\t\t\t\t\\addplot[function, xgreen] {P5(x)};\n\t\t\t\t\\end{axis}\n\t\t\t\\end{tikzpicture}\n\t\t\t\\caption{\\textcolor{xgreen}{$\\bm{\\frac{3}{100}\\left( x^{5}+3x^{4}-11x^{3}-27x^{2}+10x+24 \\right)}$}}\n\t\t\\end{subfigure}\n\t\t\\hfill\n\t\t\\begin{subfigure}[b]{0.475\\textwidth}\n\t\t\t\\centering\n\t\t\t\\begin{tikzpicture}\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\t\tgraph2d,\n\t\t\t\t\t\twidth=6cm, height=6cm,\n\t\t\t\t\t\txmin=-5, xmax=5,\n\t\t\t\t\t\tymin=-5, ymax=5,\n\t\t\t\t\t\tdomain=-5:5,\n\t\t\t\t\t\trestrict y to domain=-15:15,\n\t\t\t\t\t\tdeclare function={P6(\\x)=0.01*(x^6-x^5-26*x^4+15*x^3+150*x^2-25*x-5);},\n\t\t\t\t\t]\n\t\t\t\t\t\\addplot[function, xpurple] {P6(x)};\n\t\t\t\t\\end{axis}\n\t\t\t\\end{tikzpicture}\n\t\t\t\\caption{\\textcolor{xpurple}{$\\bm{\\frac{1}{100}\\left( x^{6}-x^{5}-26x^{4}+15x^{3}+150x^{2}-25x-5\\right)}$}}\n\t\t\\end{subfigure}\n\t\\end{figure}\n\\end{example}\n\nAs can be seen in \\autoref{:high_order_polynomials}, the maximal number of `bends' in a polynomial function of order $n$ is $n-1$ (i.e. one less than the order of the function).\n\nWe will continue to explore polynomial functions in more details in future chapters.\n", "meta": {"hexsha": "035daca9d093bfd4aedc507edc5d0a2cc9c8b010", "size": 8445, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/intro/polynomials.tex", "max_stars_repo_name": "JASory/maths_book", "max_stars_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-25T20:02:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T17:57:59.000Z", "max_issues_repo_path": "chapters/intro/polynomials.tex", "max_issues_repo_name": "JASory/maths_book", "max_issues_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2022-01-17T05:01:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-20T06:18:24.000Z", "max_forks_repo_path": "chapters/intro/polynomials.tex", "max_forks_repo_name": "JASory/maths_book", "max_forks_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2022-01-17T10:15:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-02T10:45:13.000Z", "avg_line_length": 41.3970588235, "max_line_length": 405, "alphanum_fraction": 0.6277087034, "num_tokens": 3284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.9196425273236, "lm_q1q2_score": 0.8478385262009079}}
{"text": "\\paragraph{Mean} \\hspace{0pt}\n\n\\vspace{-20pt}\n\\begin{gather*}\n\\mean = \\frac{1}{n}\\sum_{i=1}^n X_i\n\\end{gather*}\n\n\\paragraph{Mean for grouped data} \\hspace{0pt}\n\n\\vspace{-5pt}\n\\begin{gather*}\n\\mean = \\frac{1}{n}\\sum_{i=1}^n n_i x_i\n\\end{gather*}\n\nwhere $n_i$ is count of $i$th result values, and $x_i$ is the $i$th result value.\n\n%\\paragraph{Weighted mean} \\nodata\n\n\\paragraph{Median} \\hspace{0pt}\n\n\\vspace{-20pt}\n\\begin{gather*}\n\\med = \\frac{1}{2} \\left( X_{\\lfloor \\frac{n+1}{2} \\rfloor : n} + X_{\\lceil \\frac{n+1}{2} \\rceil : n} \\right) =\\\\ \n= \\begin{cases}\n X_{\\frac{n+1}{2} : n} \\mbox{ if } n \\mbox{ is odd} \\\\\n \\frac{1}{2} \\left( X_{\\frac{n}{2} : n} + X_{\\frac{n+2}{2} : n} \\right) \\mbox{ if } n \\mbox{ is even}\n\\end{cases}\n\\end{gather*}\n\nwhere $x_{k:n}$ is the $k$th sample element taken from sorted sample.\n\n\\paragraph{Weighted median}\n\\begin{gather*}\n\\med = X_{\\med}^L + \\frac{b}{n_{\\med}} \\left( \\frac{n}{2} - \\sum_{i=1}^{i_{\\med}-1} n_i \\right)\n\\end{gather*}\n\n\\paragraph{Mode}\nis an observation that appears most often.\n\n\\paragraph{Trimmed mean} \\hspace{0pt}\n\n\\vspace{-5pt}\n\\begin{gather*}\n\\mean_{t,k} = \\frac{1}{n - 2k} \\sum_{i=k+1}^{n-k} X_i\n\\end{gather*}\n\n\\paragraph{Winsorized mean}\nis thought to decrease the effect of outliers.\n\\begin{gather*}\n\\mean_{w,k} = \\frac{1}{n} \\left[ (k+1)X_{k+1} + \\sum_{i=k+2}^{n-k-1} + (k+1)X_{n-k} \\right]\n\\end{gather*}\n\n\\paragraph{Geometrical mean}\n\n\\[ \\mean_g = \\sqrt[n]{x_1 x_2 \\ldots x_n} \\]\n\n\\paragraph{Harmonic mean} \\hspace{0pt}\n\n\\vspace{-10pt}\n\\[ \\mean_h = \\frac{1}{ \\frac{1}{n} \\sum_{i=1}^n \\frac{1}{X_i} } \\]\n", "meta": {"hexsha": "4ca5a60ecb25be1d6f11943e7364f6fcb418906e", "size": 1565, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_2b_measures_central.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_2b_measures_central.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_2b_measures_central.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6557377049, "max_line_length": 114, "alphanum_fraction": 0.6230031949, "num_tokens": 668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.9073122132152183, "lm_q1q2_score": 0.8477881396274545}}
{"text": "\n\\subsection{Information}\n\n\\subsubsection{Criteria}\n\nSelf information measures surprise of outcome. also called a surprisal.\n\nWhen we observe an outcome we get information. We can develop a measure for how much information is associated with a specific measurement.\n\nRule 1: Information is always positive\n\nRule 2: If \\(P(x)=1\\), the the information for \\(I(P(x))=0\\).\n\nRule 3: If two events are independent, then their information is additive.\n\n\\begin{itemize}\n\\item \\(P(C)=P(A)P(B)\\)\n\\item \\(I(P(C))=I(P(A)P(B))\\)\n\\item \\(I(P(A))+I(P(B))=I(P(A)P(B))\\)\n\\end{itemize}\n\n\\subsubsection{Choice of function}\n\nA function which satisifes this is \\(I(P(A))=-\\log(P(A))\\)\n\nAny base can be used. 2 is most common, information is in units of bit then.\n\n", "meta": {"hexsha": "08f2bcc754d97be5fdf1fe912909ee71d7f4c1f0", "size": 743, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/entropy/01-01-information.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/entropy/01-01-information.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/entropy/01-01-information.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.5357142857, "max_line_length": 139, "alphanum_fraction": 0.7079407806, "num_tokens": 213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9643214532237354, "lm_q2_score": 0.8791467564270272, "lm_q1q2_score": 0.8477800777546443}}
{"text": "\\subsection{Product Rule}\r\n\\begin{lemma}\r\n\tLet $f$ and $g$ be differentiable functions. Then\r\n\t\\begin{equation}\r\n\t\t(fg)^\\prime = fg^\\prime + gf^\\prime.\r\n\t\\end{equation}\r\n\\end{lemma}\r\n\\begin{proof}\r\n\tApplying the definition of the derivative and limit properties,\r\n\t\\begin{align*}\r\n\t\t(fg)^\\prime &= \\lim_{h \\to 0}{\\frac{f(x+h)g(x+h) - f(x)g(x)}{h}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{\\frac{f(x+h)g(x+h)-f(x+h)g(x)+f(x+h)g(x)-f(x)g(x)}{h}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{\\frac{f(x+h)\\left(g(x+h)-g(x)\\right)}{h}} + \\lim_{h \\to 0}{\\frac{g(x)\\left(f(x+h)-f(x)\\right)}{h}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{f(x+h)} \\lim_{h \\to 0}{\\frac{g(x+h)-g(x)}{h}} + g(x)\\lim_{h \\to 0}{\\frac{f(x+h)-f(x)}{h}} \\\\\r\n\t\t&= fg^\\prime + gf^\\prime\r\n\t\\end{align*}.\r\n\\end{proof}\r\n\r\n\\begin{example}\r\n\tGiven the the derivative of $\\sin{(x)}$ is $\\cos{(x)}$, find the derivative of $x^2\\sin{(x)}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tUsing the product rule and power rule,\r\n\t\\begin{equation*}\r\n\t\tf^\\prime(x) = x^2\\cos{(x)} + \\sin{(x)}2x.\r\n\t\\end{equation*}\r\n\\end{answer}", "meta": {"hexsha": "d1e09a72eaa24d6a12306f2963549ba416062d00", "size": 1008, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/derivative_rules/product_rule.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/derivatives/derivative_rules/product_rule.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/derivatives/derivative_rules/product_rule.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 37.3333333333, "max_line_length": 122, "alphanum_fraction": 0.5654761905, "num_tokens": 432, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810496235896, "lm_q2_score": 0.8947894569842487, "lm_q1q2_score": 0.8477065749498593}}
{"text": "%\\newbreak\n\\section{KL divergence and cross-entropy}\nCross-entropy minimization is frequently used in optimization and rare-event probability estimation. When comparing a distribution    against a fixed reference distribution, cross-entropy and KL divergence are identical up to an additive constant. See more details in \\cite{murphy2012machine,kullback1951information,kullback1997information} and the reference therein.\n\nThe KL(Kullback--Leibler) divergence defines a special distance between two discrete probability distributions \n$$\np=\\left( \\begin{array}{ccc}\np_1\\\\\n\\vdots \\\\\np_k\n\\end{array} \\right),\\quad  q=\\left( \\begin{array}{ccc}\nq_1\\\\\n\\vdots \\\\\nq_k\n\\end{array} \\right)\n$$\nwith $0\\le p_i, q_i\\le1$ and $\\sum_{i=1}^{k}p_i=\\sum_{i=1}^{k}q_i=1$ by\n\\begin{equation}\n\\label{KL-divergence}\nD_{\\rm KL}(q,p)= \\sum_{i=1}^k q_i\\log \\frac{q_i}{p_i}.  \n\\end{equation}\n\n\\begin{lemma}\\mbox{}\n$D_{\\rm KL}(q,p)$ works like a ``distance\" without the symmetry:\n\t\\begin{enumerate}\n\t\t\\item $D_{\\rm KL}(q,p)\\ge0$;\t\t\n\t\t\\item $D_{\\rm KL}(q,p)=0$ if and only if $p=q$;\n\t\\end{enumerate}\n\\end{lemma}\n\n\\begin{proof}We first note that the elementary inequality\n\t\\begin{equation}\n\t\\log x \\le x - 1, \\quad\\mathrm{for\\ any\\ }x\\ge0,\n\t\\end{equation}\n\tand the equality holds if and only if $x=1$.\n\t\\begin{equation}\n\t-D_{\\rm KL}(q,p) = - \\sum_{i=1}^c q_i\\log \\frac{q_i}{p_i}   = \\sum_{i=1}^k q_i\\log \\frac{p_i}{q_i} \\le \\sum_{i=1}^k q_i( \\frac{p_i}{q_i}  - 1) = 0.\n\t\\end{equation}\n\tAnd the equality holds if and only if \n\t\\begin{equation}\n\t\\frac{p_i}{q_i} = 1 \\quad \\forall i = 1:k.\n\t\\end{equation}\n\\end{proof}\n\nDefine cross-entropy for distribution $p$ and $q$ by\n\\begin{equation}\\label{Cross-Entropy}\nH(q,p) = - \\sum_{i=1}^k q_i \\log p_i,\n\\end{equation}\nand the entropy for distribution $q$ by \n\\begin{equation}\\label{Entropy}\nH(q) = - \\sum_{i=1}^k q_i \\log q_i.\n\\end{equation}\nNote that\n\\begin{equation}\nD_{\\rm KL}(q,p)= \\sum_{i=1}^k q_i\\log \\frac{q_i}{p_i} =  \\sum_{i=1}^k q_i \\log q_i - \\sum_{i=1}^k q_i \\log p_i\n\\end{equation}\nThus, \n\\begin{equation}\\label{KLandEntropy}\nH(q,p) = H(q) + D_{\\rm KL}(q,p).\n\\end{equation} \nIt follows from the relation \\eqref{KLandEntropy} that\n\\begin{equation}\n\\label{EntropyandKL}\n\\mathop{\\arg\\min}_p D_{\\rm KL}(q,p)=\\mathop{\\arg\\min}_p H(q,p).\n\\end{equation}\n\nThe concept of cross-entropy  can be used to define a loss function in machine learning and optimization. \nLet us assume $y_i$ is the true label for $x_i$, for example $y_i = e_{k_i}$ if $x_i \\in A_{k_i}$. Consider the predicted distribution \n\\begin{equation}\\label{key}\n\\bm p(x; \\bm \\theta) = \\frac{1}{\\sum\\limits_{i=1}^k e^{w_i x+b_i}}\n\\begin{pmatrix}\ne^{w_1 x+b_1}\\\\\ne^{w_2 x+b_2}\\\\\n\\vdots\\\\\ne^{w_k x+b_k}\n\\end{pmatrix}\n= \\begin{pmatrix}\np_1(x; \\bm\\theta) \\\\\np_2(x; \\bm\\theta) \\\\\n\\vdots \\\\\np_k(x; \\bm\\theta)\n\\end{pmatrix}\n\\end{equation}\nfor any data $x \\in A$.\nBy \\eqref{EntropyandKL}, the minimization of KL divergence is equivalent to the minimization of the cross-entropy, namely\n\\begin{equation}\n\\mathop{\\arg\\min}_{\\theta} \\sum_{i=1}^N D_{\\rm KL}(y_i,\\bm p(x_i; \\bm \\theta)) = \\mathop{\\arg\\min}_{\\theta} \\sum_{i=1}^N H(y_i, \\bm p(x_i; \\bm \\theta)).\n\\end{equation} \nRecall that we have all data $D = \\{(x_1,y_1),(x_2,y_2),\\cdots, (x_N, y_N)\\}$.  Then, it is natural to consider the \nloss function as following:\n\\begin{equation}\n\\sum_{j=1}^N H(y_i, \\bm p(x_i; \\bm \\theta)),\n\\end{equation}\nwhich measures the distance between the real label and predicted one for all data.\nIn the meantime, we can check that\n\\begin{equation}\n\\begin{aligned}\n\\sum_{j=1}^N H(y_j, \\bm p(x_j; \\bm \\theta))&=-\\sum_{j=1}^N y_j  \\cdot \\log  \\bm p(x_j; \\bm \\theta )\\\\\n&=-\\sum_{j=1}^N  \\log p_{i_j}(x_i; \\bm \\theta) \\quad (\\text{because}~y_j = e_{i_j}~\\text{for}~x_j \\in A_{i_j})\\\\\n&=-\\sum_{i=1}^k \\sum_{x\\in A_i}  \\log p_{i}(x; \\bm \\theta) \\\\\n&=-\\log \\prod_{i=1}^k \\prod_{x\\in A_i}   p_{i}(x; \\bm \\theta)\\\\\n& = L(\\theta)\n\\end{aligned}\n\\end{equation}\nwith $L(\\theta)$ defined in \\eqref{logistic} as \n\\begin{equation}\nL(\\bm \\theta) = - \\sum_{i=1}^k \\sum_{x\\in A_i} \\log p_{i}(x;\\bm \\theta).\n\\end{equation}\n\nThat is to say, the logistic regression loss function defined by likelihood in \\eqref{logistic} is exact\nthe loss function defined by measuring the distance between real label and predicted one via cross-entropy.\nWe can note \n\\begin{equation}\\label{key}\n\\min_{\\bm \\theta} L_\\lambda(\\bm \\theta) \\Leftrightarrow \\min_{\\bm \\theta} \\sum_{j=1}^N H(y_i, \\bm p(x_i; \\bm \\theta)) + \\lambda R(\\|\\bm \\theta\\|) \n\\Leftrightarrow \\min_{\\bm \\theta} \\sum_{j=1}^N D_{\\rm KL}(y_i, \\bm p(x_i; \\bm \\theta)) + \\lambda R(\\|\\bm \\theta\\|).\n\\end{equation}\n\n\n\n\\endinput", "meta": {"hexsha": "c4b5497678d03ea2378a98c46fe5d9751e4dd618", "size": 4602, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/KL-CR-LR.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/KL-CR-LR.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/KL-CR-LR.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.35, "max_line_length": 367, "alphanum_fraction": 0.6760104302, "num_tokens": 1791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996142, "lm_q2_score": 0.899121377945727, "lm_q1q2_score": 0.8474279418881062}}
{"text": "\n\n\\section{ Gradient descent's algorithm }\n\\subsection{Introduction}\n\nGradient descent is a general technique for minimizing  differentiable functions through its slope. \\cite{LFD}\nIt is used to find local minimums. The start point is crucial in the search.  \n\nThe basic idea is to update the weights using the gradients until it is not possible to continuous minimizing the error.\n\n\n\\medskip\n\n\\subsection{Math}\n\nIn order to understand the algorithm we are going to define: \n\nLet $w(0) \\in \\mathbb{R}^d$ be an arbitrary initial point,\n$E : \\mathbb{R}^d \\times \\mathbb{R}^d \\longrightarrow \\mathbb R$\na differentiable function. The learning rate or step size $\\eta \\in \\mathbb{R}^+$\nis a experimental coefficient about how much are we going to follow the slope to obtain the new weight.  \nLet  $w(t) \\in \\mathbb{R}^d  \\quad t \\in \\mathbb N$ be the weight for $t$ iteration which is defined as\n\n\\begin{equation*}\n  w(t+1) = w(t) - \\eta \\nabla E_{in}(w(t))\n\\end{equation*}\n\n\\subsubsection{ Properties}\n\n\\begin{itemize}\n\\item This algorithm gives local minimums.\n\\item Convergence is not assured in a finite time, so it would be necessary some stop criteria. \n\\item For a convex function it would be a unique global minimum.\n\\item The convergence success (in time) depends on the learning rate, $\\eta$. \n\\end{itemize}\n\n\n\\subsection{Algorithm}\n\nThe following code snippet implements the algorithm, where $w(0)$ is the $\\texttt{initial\\_point}$, $E$ is the error, $\\nabla E_{in}(w)$\nis $\\texttt{gradient\\_function}$ and\nfinally $\\eta$ is $eta.$ The value $\\eta = 0.1$ is a heuristic based on purely practical observation \\cite{LFD}.\n\n\nIn order to avoid an infinite search, our stop criteria are a limit in the number of iterations $\\texttt{max\\_iter}$ and an error tolerance. \n\n\\begin{minted}{python} \n\n  def gradient_descent(initial_point, loss_function,\n                gradient_function,  eta, max_iter, target_error):\n    '''\n    initicial point: w_0 \n    E: error function \n    gradient_function\n    eta:  step size \n\n    ### stop conditions ###\n    max_iter\n    target_error\n\n    #### return ####\n    (w,iterations)\n    w: the coordenates that minimize E\n    it: the numbers of iterations needed to obtain w\n    \n    '''\n\n    iterations = 0\n    error = E( initial_point[0], initial_point[1])\n    w = initial_point\n  \n    while ( (iterations < max_iter) and(error > target_error)): \n\n        w = w - eta * gradient_function(w[0], w[1])\n        \n        iterations += 1\n        error = loss_function(w[0], w[1])\n \n    \n    return w, iterations\n        \n\\end{minted}\n\n\\subsection{Problem 1}\n\nWe want to solve the following problem: %\\\\\n\nUse gradient descent's algorithm to find a minimum for the\nfunction\n\n\n\\[E(u,v) = (u^3 e^{(v-2)} - 2* v^2 e^{-u})^2.\\]\n\nSet $(u,v)=(1,1)$ as initial point and use learning rate $\\eta = 0.1$.\n\n\\subsubsection{Compute analytically the gradient of $E(u,v)$}\n\n\n\\begin{multline*}\n  \\nabla E(u,v) = \\left( \\frac{\\partial}{\\partial u}(u^3 e^{(v-2)} - 2* v^2 e^{-u})^2 , \\frac{\\partial}{\\partial v} (u^3 e^{(v-2)} - 2 v^2 e^{-u})^2 \\right) = \\\\\n =  \\left(2(u^3 e^{(v-2)} - 2* v^2 e^{-u})(3u^2e^{(v-2)} + 2 v^2 e^{-u} ), 2(u^3 e^{(v-2)} - 2* v^2 e^{-u})(u^3 e^{(v-2)} - 4 v e^{-u}) \\right)\n\\end{multline*}\n\n\n\\subsubsection{Number of iterations and final coordinates.}\n\nFirstable we need to use 64-bits float, so we are going to use the data type $float64$ of numpy library \\cite{float64}.\n\nThe functions' declaration are:\n\n\\begin{minted}{python}\n  def dEu(u,v):\n    '''\n    Partial derivate of E with respect to the variable u\n    '''\n    return np.float64(\n        2\n        *( 3* u**2 * np.e**(v-2) + 2*v**2 * np.e**(-u) )\n        *( u**3 * np.e**(v-2) - 2*v**2 * np.e**(-u))\n    )\n    \ndef dEv(u,v):\n    '''\n    Partial derivate of E with respect to the variable v\n    '''\n    return np.float64(\n        2*\n        ( u**3 * np.e**(v-2) - 2*v**2 * np.e**(-u) )\n        *( u**3 * np.e**(v-2) - 4*v * np.e**(-u))\n    )\n\n\ndef gradE(u,v):\n    ''' \n        gradient of E\n    '''\n    return np.array([dEu(u,v), dEv(u,v)])\n\n\\end{minted}\n\nTo obtain the number of iterations and the final coordinates, the only thing we need to do is to call $\\texttt{gradien\\_descent}$ function with the initial conditions:\n\n\\begin{minted}{python}\neta = 0.01 \nmax_iter = 10000000000\ntarget_error = 1e-14\ninitial_point = np.array([1.0,1.0])\nw, it = gradient_descent( initial_point,\n                          E,\n                          gradE,\n                          eta,\n                          max_iter,\n                          target_error )\n\\end{minted}\n\nThe results are:\n\n\\begin{itemize}\n\\item Numbers of iterations: $178.$\n\\item Final coordinates: $( 1.162 ,  0.924 ).$\n\\end{itemize}\n\nA 3d graph with the result is \n\n\\includegraphics[width=\\linewidth]{1_graph.png}\n\n\n\n\\subsection{Problem 2}\n\n\nLet's define the function $f(x,y) = (x+2)^2 + 2(y-2)^2 + 2 \\sin (2 \\pi x) \\sin (2 \\pi y)$.\n\n\\subsubsection{ Use gradient descent to minimize $f$}\n\nThe initial point is $(x_0 = -1, y_0 = 1)$,\nlearning rate is $\\eta = 0.01$ and the maximum number of iterations must\nbe $50$.  Plot the result and repeat the experiment with  $\\eta = 0.1$. \n\nFirstly we are going to calculate partial derivatives and gradient of $f$.\n\n\\begin{equation*}\n  \\frac{\\partial }{\\partial x} f = 2 (x + 2) + 2 \\sin (2 \\pi y) \\cos ( 2 \\pi x) 2 \\pi =  2 (x + 2) +  4 \\pi \\sin (2 \\pi y) \\cos ( 2 \\pi x)   \n\\end{equation*}\n\n\\begin{equation*}\n  \\frac{\\partial }{\\partial y} f = 4 (y - 2) +  4 \\pi \\sin (2 \\pi x) \\cos ( 2 \\pi y)   \n\\end{equation*}\n\n\nIt is important to realise that $f(x,y) <0$ for some values in $\\mathbb R^3$ so the error target has been omitted in this algorithm.   \n\n\nNow the new algorithm is\n\\begin{minted}{python}\n  def gradient_descent_trace(initial_point, loss_function,\n    gradient_function,  eta, max_iter):\n    '''\n    initicial point: w_0 \n    loss_function: error function \n    gradient_function\n    eta:  step size \n\n    ### stop conditions ###\n    max_iter\n\n    #### return ####\n    (w,iterations)\n    w: the coordenates that minimize loss_function\n    it: the numbers of iterations needed to obtain w\n    \n    '''\n\n    iterations = 0\n    error = loss_function( initial_point[0], initial_point[1])\n    w = [initial_point]\n  \n    while iterations < max_iter: \n\n        new_w = w[-1] - eta * gradient_function(w[-1][0], w[-1][1])\n        \n        \n        iterations += 1\n        error = loss_function(new_w[0], new_w[1])\n        w.append( new_w ) \n    \n    return w, iterations\n  \n  \\end{minted}\n\n\n  After 50 iterations for  $\\eta = 0.01$, the  final coordinates are $(-1.269, 1.287)$ and their value is $-0.381$. The graph which shows the relation between iterations and the function minimization is\n\n\n  \\includegraphics[width=\\linewidth]{1_3_smaller_eta}\n\n  As far as we have seen, before the $10^{th}$ iteration we are really close to the minimum and stay there without fluctuating.\n\n  On the other hand, after 50 iterations for  $\\eta = 0.1$ the final coordinate is $(-2.939, 1.608)$ and its value is $f(-2.939, 1.608) = 0.724$, so as we can see, this result is worse than the last one.\n\n  In the following graph we can see how the images' value fluctuates iteration by iteration. \n\n  \\includegraphics[width=\\linewidth]{1_3_bigger_eta}.\n\n The reason for this irregularity  is that the step size is too big, so it skips the minimum.\n\n We can also  compare the two experiment in the following graph.\n \n\\includegraphics[width=\\linewidth]{1_3_comparation_eta}.\n\n\n    Moreover, based on its mathematical proof, which use Taylor's series, we know that it should be small, but if it is too small the algorithm will never reach the minimum in time.\n\n Let's see a new example: now $\\eta = 10^{-14}$, after 50 iterations  the final coordinates are $(-1, 1)$  and the value is $3$, so this new selection is even worse that the one with the bigger step's size, although it goes without oscillating.  \n\n \\includegraphics[width=\\linewidth]{1_3_epsilon_eta}\n \n \\includegraphics[width=\\linewidth]{1_3_eta_and_smaller.png}\n \n  As a conclusion, a priory, it is difficult to select a step's size value, each problem should have an appropriate one and the selection must be empirical. Even though some heuristic \\cite{LFD} tell that $\\eta = 0.01$ it is a good try.  \n\n \n  \n\n\\subsubsection{Minimum value }\n\n\nBefore running the algorithm is important to think about a good value for the learning rate $\\eta$. Based on the last section, $\\eta = 0.1$ is a good one. \n\n\nThe results are\n\n\\begin{center}\n  \\begin{tabular}{ |c|c|c| }\n    \\hline\n    Initial point  & Final coordinates & Final value  \\\\ \n    \\hline\n\n    (-0.5 -0.5) &  (-0.793 -0.126) &   9.125 \\\\\n(1 1) &  (0.677 1.29) &   6.437 \\\\\n( 2.1 -2.1) &  ( 0.149 -0.096 ) &   12.491 \\\\\n(-3  3) &  (-2.7315  2.713) &  -0.381 \\\\\n(-2  2) &  (-2.  2.) &  0 \\\\\n    \n \n \\hline\n\\end{tabular}\n\\end{center}\n\n\nThis example gives the idea that the local minimums found depend on the start point $w_0$ and a priory, unless we know some properties\nof the function such as convexity or monotony we are not able to assure that the minimum found is global.\n\n\nUnder a mathematical point of view, to study a function's monotony we need some more complex tools and conditions, such as solve equations; something that\nthe majority of times is impossible.\n\nFortunately, for the error functions such a the mean quadratic error, this is totally possible. \n\n\n\n\\subsection{ Final conclusion about finding global functions' minimum by gradient descent}  \n\nTo sum up this first chapter,  gradient descent's algorithm is a technique to minimize differentiable functions. It dramatically depends  on the initial point and the learning rate. Moreover, it does not give global  minimums unless the  function is convex.\n\nThe computational cost of the function is $\\mathcal O (N i)$ where $N$ is the size of the data set and $i$ the maximum number of iterations.\n\nSome useful examples of functions that can be successfully mimimized with used this algorithm are the mean quadratic's error or the logistic's function.\n\n\n\n", "meta": {"hexsha": "f743b4692a8503314b472832844c8d47262d7f28", "size": 10022, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "practica1/memory/gradient_descent.tex", "max_stars_repo_name": "BlancaCC/aprendizaje-automatico", "max_stars_repo_head_hexsha": "3a1288b951ffcf1121ee43aa37efe2daf7a06450", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "practica1/memory/gradient_descent.tex", "max_issues_repo_name": "BlancaCC/aprendizaje-automatico", "max_issues_repo_head_hexsha": "3a1288b951ffcf1121ee43aa37efe2daf7a06450", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-04T14:03:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-04T14:03:37.000Z", "max_forks_repo_path": "practica1/memory/gradient_descent.tex", "max_forks_repo_name": "BlancaCC/aprendizaje-automatico", "max_forks_repo_head_hexsha": "3a1288b951ffcf1121ee43aa37efe2daf7a06450", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1217948718, "max_line_length": 257, "alphanum_fraction": 0.6608461385, "num_tokens": 2930, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.9032942112597331, "lm_q1q2_score": 0.8474019962275265}}
{"text": "\\subsection{Arc length}\n\nLet $g(t)$ be a function that draws a curve.\nThe arc length from $g(a)$ to $g(b)$ is given by\n$$\\int_a^b|g'(t)|\\,dt$$\nwhere $|g'(t)|$ is the length of the tangent vector at $g(t)$.\nThe integral sums over all of the tangent lengths to arrive at the total length\nfrom $a$ to $b$.\nFor example, let us measure the length of the following curve.\n\n{\\color{blue}\n\\begin{verbatim}\nxrange = (0,1)\nyrange = (0,1)\ndraw(x^2)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.2]{arc.png}\n\\end{center}\n\n\\noindent\nA suitable $g(t)$ for the arc is\n$$g(t)=(t,t^2),\\quad0\\le t\\le1$$\nHence one Eigenmath solution for computing the arc length is\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nx = t\ny = t^2\ng = (x,y)\ndefint(abs(d(g,t)),t,0,1)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{1}{2}\\;5^{1/2}+\\tfrac{1}{4}\\log(5^{1/2}+2)$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nfloat\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle 1.47894$\n\n\\bigskip\n\\noindent\nAs expected, the result is greater than $\\sqrt2\\approx1.414$,\nthe length of the\ndiagonal from $(0,0)$ to $(1,1)$.\n\n\\bigskip\n\\noindent\nThe result seems rather complicated given that we\nstarted with a simple parabola.\nLet us inspect $|g'(t)|$ to see why.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\ng\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle g=\\begin{bmatrix}t\\\\ t^2\\end{bmatrix}$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nd(g,t)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\begin{bmatrix}1\\\\ 2t\\end{bmatrix}$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nabs(d(g,t))\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle (4t^2+1)^{1/2}$\n\n\\bigskip\n\\noindent\nThe following script does a discrete computation of the arc length\nby dividing the curve into 100 pieces.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\ng(t) = (t,t^2)\nh(k) = abs(g(k/100.0) - g((k-1)/100.0))\nsum(k,1,100,h(k))\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle 1.47894$\n\n\\bigskip\n\\noindent\nAs expected, the discrete result matches the analytic result.\n\n\\bigskip\n\\noindent\nFind the length of the curve $y=x^{3/2}$ from the origin to\n$x=\\tfrac{4}{3}$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nx = t\ny = x^(3/2)\ng = (x,y)\ndefint(abs(d(g,x)),x,0,4/3)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{56}{27}$\n\n\\bigskip\n\\noindent\nBecause of the way $t$ is substituted for $x$,\nthe following code yields the same result.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\ng = (t,t^(3/2))\ndefint(abs(d(g,t)),t,0,4/3)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{56}{27}$\n\n\\subsection{Line integrals}\nThere are two different kinds of line integrals,\none for scalar fields and one\nfor vector fields.\nThe following table shows how both are based on the calculation of\narc length.\n\n\\begin{center}\n\\begin{tabular}{|l|l|l|}\n\\hline\n& Abstract form\n& Computable form\n\\\\\n\\hline\n & &\\\\\nArc length\n& $\\displaystyle{\\int_C ds}$\n& $\\displaystyle{\\int_a^b |g'(t)|\\,dt}$\\\\\n & &\\\\\n\\hline\n & & \\\\\nLine integral, scalar field\n& $\\displaystyle{\\int_C f\\,ds}$\n& $\\displaystyle{\\int_a^b f(g(t))\\,|g'(t)|\\,dt}$\\\\\n& &\\\\\n\\hline\n & & \\\\\nLine integral, vector field\n& $\\displaystyle{\\int_C(F\\cdot u)\\,ds}$\n& $\\displaystyle{\\int_a^b F(g(t))\\cdot g'(t)\\,dt}$\\\\\n & & \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent\nFor the vector field form, the symbol $u$ is the unit tangent vector\n$$u=\\frac{g'(t)}{|g'(t)|}$$\nThe length of the tangent vector cancels with $ds$\nas follows.\n$$\\int_C(F\\cdot u)\\,ds\n=\\int_a^b\\bigg(F(g(t))\\cdot\\frac{g'(t)}{|g'(t)|}\\bigg)\\,\\bigg(|g'(t)|\\,dt\\bigg)\n=\\int_a^b F(g(t))\\cdot g'(t)\\,dt\n$$\n\n\\noindent\nEvaluate\n$$\\int_Cx\\,ds\\quad\\hbox{and}\\quad\\int_Cx\\,dx$$\nwhere $C$ is a straight line from $(0,0)$ to $(1,1)$.\n\n\\bigskip\n\\noindent\nWhat a difference the measure makes.\nThe first integral is over a scalar field and the second is over a vector field.\nThis can be understood when we recall that\n$$ds=|g'(t)|\\,dt\n$$\nHence for $\\int_Cx\\,ds$ we have\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nx = t\ny = t\ng = (x,y)\ndefint(x abs(d(g,t)),t,0,1)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\frac{1}{2^{1/2}}$\n\n\\bigskip\n\\noindent\nFor $\\int_Cx\\,dx$ we have\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nx = t\ny = t\ng = (x,y)\nF = (x,0)\ndefint(dot(F,d(g,t)),t,0,1)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{1}{2}$\n\n\\bigskip\n\\noindent\nThe following line integral problems are from\n{\\it Advanced Calculus, Fifth Edition} by Wilfred Kaplan.\n\n\\bigskip\n\\noindent\nEvaluate $\\int y^2\\,dx$ along the straight\nline from $(0,0)$ to $(2,2)$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nx = 2t\ny = 2t\ng = (x,y)\nF = (y^2,0)\ndefint(dot(F,d(g,t)),t,0,1)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{8}{3}$\n\n\\bigskip\n\\noindent\nEvaluate $\\int z\\,dx+x\\,dy+y\\,dz$\nalong the path\n$x=2t+1$, $y=t^2$, $z=1+t^3$, $0\\le t\\le 1$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nx = 2t+1\ny = t^2\nz = 1+t^3\ng = (x,y,z)\nF = (z,x,y)\ndefint(dot(F,d(g,t)),t,0,1)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{163}{30}$\n", "meta": {"hexsha": "37eaabc50f79216bd0229c80ad0dddc5e539f634", "size": 5016, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/line-integral.tex", "max_stars_repo_name": "franko/eigenmath", "max_stars_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-01-27T02:41:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-02T19:05:49.000Z", "max_issues_repo_path": "doc/line-integral.tex", "max_issues_repo_name": "franko/eigenmath", "max_issues_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-01-29T14:09:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-13T16:17:03.000Z", "max_forks_repo_path": "doc/line-integral.tex", "max_forks_repo_name": "franko/eigenmath", "max_forks_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-27T02:38:38.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-27T02:38:38.000Z", "avg_line_length": 20.3902439024, "max_line_length": 80, "alphanum_fraction": 0.6744417863, "num_tokens": 1877, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915913, "lm_q2_score": 0.9086178926024029, "lm_q1q2_score": 0.8472437655634754}}
{"text": "\\section{Matrix Factorization}\n\\begin{theo}\nIf Gaussian elimination can be performed on the linear system $Ax=b$ without row interchanges, then the matrix $A$ can be factored into the product of a lower-triangular maxtrix $L$ and an upper-triangular matrix $U$, that is $A=LU$, where $m_{ji}=a_{ji}^{(i)}/a_{ii}^{(i)}$\n\\[\nU=\n\\begin{pmatrix}\na_{11}^{(1)} & a_{12}^{(1)} & \\cdots       & a_{1n}^{(1)} \\\\\n0            & a_{22}^{(2)} & \\ddots       & \\vdots       \\\\\n\\vdots       & \\ddots       & \\ddots       & a_{n-1,n}^{(n-1)} \\\\\n0            & \\cdots       & 0            & a_{nn}^{(n)}\n\\end{pmatrix}\n\\quad\nU=\n\\begin{pmatrix}\n1            & 0            & \\cdots       & 0            \\\\\nm_{21}       & \\ddots       & \\ddots       & \\vdots       \\\\\n\\vdots       & \\ddots       & \\ddots       & 0            \\\\\nm_{n1}       & \\cdots       & m_{n,n-1}    & 1\n\\end{pmatrix}\n\\]\n\\end{theo}\n", "meta": {"hexsha": "c09e3a080b57f4f390f80ba6b7c570253a50b79f", "size": 884, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/6.5_Matrix_factorization.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/6.5_Matrix_factorization.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/6.5_Matrix_factorization.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.1818181818, "max_line_length": 274, "alphanum_fraction": 0.4739819005, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122696813394, "lm_q2_score": 0.8840392725805822, "lm_q1q2_score": 0.8468320660851058}}
{"text": "\\section{Vector and Matrix Derivatives}\n\\label{sec:derivatives}\n\nDerivatives involving matrices and vectors can look nonintuitive when the usual symbolic matrix notation is used, but can be derived handily when index notation is used. A very concise and helpful resource for this is \\citeasnoun{barnesmatrixdiff}. \n\n\n\\subsection{Jacobian}\nIt is particularly helpful to remember the Jacobian, which is the derivative of a function with respect of a vector. The Jacobian of some function $f: \\mathbb{R}^n \\rightarrow \\mathbb{R}^m$ is:\n\n\\begin{equation}\n\\frac{\\mathrm{d}  \\mathbf{f}(\\mathbf{x})}{\\mathrm{d} \\mathbf{x}}=\\left[\\frac{\\partial \\mathbf{f}}{\\partial x_1}, \\hdots, \\frac{\\partial \\mathbf{f}}{\\partial x_n} \\right]=\\left[\\begin{array}{ccc}\n\\frac{\\partial  f_1}{\\partial  x_1} & \\hdots & \\frac{\\partial  f_1}{\\partial  x_n} \\\\\n\\vdots & \\vdots & \\vdots \\\\\n\\frac{\\partial  f_m}{\\partial  x_1} & \\hdots & \\frac{\\partial  f_m}{\\partial  x_n} \\\\\n\\end{array}\\right]\n\\end{equation}\n\nI enjoy writing the gradient $\\frac{\\mathrm{d}}{\\mathrm{d}\\mathbf{x}}$ as $\\nabla_\\mathbf{x}$. The relationships below can all be derived as applications of the Jacobian.\n\n\\begin{equation}\n\\begin{array}{l}\n\\nabla_\\mathbf{x} \\left(\\mathbf{u}^T\\mathbf{x}\\right) = \\left[\\frac{\\partial }{\\partial x_1}\\left(\\sum_i u_i x_i\\right),...,\\frac{\\partial }{\\partial x_n}\\left(\\sum_i u_i x_i\\right)\\right] = \\mathbf{u}^T\\\\\n\\\\\n\\nabla_\\mathbf{x} \\left(\\mathbf{x}^T\\mathbf{u}\\right) = \\left[\\frac{\\partial }{\\partial x_1}\\left(\\sum_i u_i x_i\\right),...,\\frac{\\partial }{\\partial x_n}\\left(\\sum_i u_i x_i\\right)\\right] = \\mathbf{u}^T\\\\\n\\\\\n\\nabla_\\mathbf{x} \\left(\\mathbf{x}^T\\mathbf{x}\\right) = \\left[\\frac{\\partial }{\\partial x_1}\\left(\\sum_i x_i^2\\right),...,\\frac{\\partial }{\\partial x_n}\\left(\\sum_i x_i^2\\right)\\right] = 2\\mathbf{x}^T\\\\\n\\\\\n\\nabla_\\mathbf{x} \\left(\\mathbf{Ax}\\right) = \\left[\n\\begin{array}{ccc} \n\\underbrace{\\frac{\\partial }{\\partial x_1}\\left(\\sum_i A_{1i} x_i\\right)}_{A_{11}} &...& \\underbrace{\\frac{\\partial }{\\partial x_n}\\left(\\sum_i A_{1i} x_i\\right)}_{A_1n}\\\\\n\\vdots&\\vdots&\\vdots\\\\\n\\underbrace{\\frac{\\partial }{\\partial x_1}\\left(\\sum_i A_{ni} x_i\\right)}_{A_{n1}} &...& \\underbrace{\\frac{\\partial }{\\partial x_n}\\left(\\sum_i A_{ni} x_i\\right)}_{A_{nn}}\\\\\n\\end{array}\\right] = \\mathbf{A}\n\\end{array}\n\\end{equation}\n\n\n\\subsection{Inverse Function Theorem}\n\\label{sec:inverse_function_theorem}\nThe inverse function theorem gives a sufficient condition for the invertibility of a function near some point in its domain. If the derivative $f'$ of a function $f$ is continuous and non-zero near some point $a$ within its domain, then the function is invertible near that point. If $b = f(a)$, then:\n\n\\begin{equation}\n\\frac{d\\left[f^{-1}(b)\\right]}{dx} = \\frac{1}{\\frac{df(a)}{dx}}\n\\end{equation}\n\nThat is, the derivative of the inverse function at a point $b=f(a)$ of the range, is the reciprocal of the derivative of the function near the point $a$ in the domain. This extends to multivariable calculus. Given a function $\\mathbf{f}: \\mathbf{x} \\rightarrow \\mathbf{y}$:\n\n\\begin{equation}\n\\nabla_\\mathbf{y}\\left[\\mathbf{f}^{-1}\\right] = \\left[\\nabla_\\mathbf{x} \\mathbf{f} \\right]^{-1}\n\\end{equation}\n\nIn words: the Jacobian of the inverse function at the point $\\mathbf{b} = \\mathbf{f}(\\mathbf{a})$ is the matrix inverse of the Jacobian of the function at the point $\\mathbf{a}$. The sufficient condition is that the Jacobian $\\nabla_\\mathbf{x}\\mathbf{f}$ is continuous and \\textit{nonsingular} near $\\mathbf{a}$.\n\n\\subsection{Critical Points}\nCritical points are points where the Jacobian does not have maximal rank. In case of a square Jacobian, this means that the Jacobian is singular. \n\n\\subsection{Differential Volume Element, Change of Variables}\nThe Jacobian is used when transforming between different coordinate systems. Consider a transformation $\\mathbf{x} = \\mathbf{H}(\\mathbf{y})$, then:\n\n\\begin{equation}\n\\mathrm{d}^n x = \\left|\\nabla_\\mathrm{y} \\mathbf{H} \\right| \\mathrm{d}^n y\n\\end{equation}\n\nAnd:\n\n\\begin{equation}\n\\int_\\mathbf{x} \\mathrm{d}^n\\mathbf{x} f(\\mathbf{x}) = \\int_\\mathbf{y} \\mathrm{d}^n\\mathbf{y} \\left|\\nabla_\\mathrm{y} \\mathbf{H} \\right| f(\\mathbf{H}(\\mathbf{y}))\n\\end{equation}\n\nAlternatively, if $\\mathbf{y} = \\mathbf{H}^{-1}(\\mathbf{x})$:\n\n \\begin{equation}\n \\begin{array}{rl}\n \\mathrm{d}^n y &= \\left|\\nabla_\\mathrm{x} \\mathbf{H}^{-1}(\\mathbf{x})\\right| \\mathrm{d}^n x\\\\\n &= \\left| \\left[ \\nabla_\\mathrm{y} \\mathbf{H}(\\mathbf{y}) \\right]^{-1} \\right| \\mathrm{d}^n x\\\\\n \\mathrm{d}^n x &= \\frac{1}{\\left| \\left[ \\nabla_\\mathrm{y} \\mathbf{H}(\\mathbf{y}) \\right]^{-1} \\right|}  \\mathrm{d}^n y \n \\end{array}\n \\end{equation}\n\nThe Jacobian has to be nonsingular within the domain of integration. This implies that $\\mathbf{x}$ and $\\mathbf{y}$ have to have the same dimension. In the context of probability theory that sometimes requires artificially defining additional variables so that $\\mathbf{H}$ is bijective because the quantity of interest has lower dimension (for example, if you calculate the mean of a random variable). \n\n\\subsection{Hessian}\n\\label{sec:hessian}\n\nThe Hessian is the second derivative of a scalar valued function $f:\\mathbb{R}^{n} \\rightarrow \\mathbb{R}$ with respect to a vector, i.e. $\\nabla\\cdot\\nabla f$. The elements are $\\mathbf{H}(f)_{i,j} = \\frac{\\partial^2 f}{\\partial x_i\\partial x_j}$. \n\n\\begin{equation}\n\\mathbf{H}(f) = \\left[\\begin{array}{cccc}\n\\frac{\\partial^2f}{\\partial x_1^2}&\\frac{\\partial^2f}{\\partial x_1\\partial x_2} & \\hdots & \\frac{\\partial^2f}{\\partial x_1\\partial x_n}\\\\\n\\frac{\\partial^2f}{\\partial x_2\\partial x_1}&\\frac{\\partial^2f}{\\partial x_2^2} & \\hdots & \\frac{\\partial^2f}{\\partial x_1\\partial x_n}\\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\\frac{\\partial^2f}{\\partial x_n\\partial x_1}&\\frac{\\partial^2f}{\\partial x_n\\partial x_2} & \\hdots & \\frac{\\partial^2f}{\\partial x_n^2}\n\\end{array} \\right]\n\\end{equation}\n\nThe Hessian of a vector valued function $f:\\mathbb{R}^n \\rightarrow \\mathbb{R}^m$ is a third order tensor with elements  $\\mathbf{H}(\\mathbf{f})_{i,j,k} = \\frac{\\partial^2 f_k}{\\partial x_i\\partial x_j}$.\n\n\\subsubsection{Testing Convexity}\nThe definiteness (cf. section \\ref{sec:definite}) of the Hessian is used to test convexity.\n\n\\begin{tabular}{ll}\n$\\mathbf{H}\\succeq 0$ & convex\\\\\n$\\mathbf{H}\\succ 0$ & strictly convex\\\\\n$\\mathbf{H}\\preceq 0$ & concave\\\\\n$\\mathbf{H}\\prec 0$ & strictly concave\\\\\n\\end{tabular}\n\nIf this holds at a point, the property is local (for example at a local maximum or minimum), and if it holds everywhere on the domain, then the property is global.\n\n", "meta": {"hexsha": "ebf0be422adf42df3badd1039dc5cd14798d1f2f", "size": 6572, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/linalg_diff.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/linalg_diff.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/linalg_diff.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.7454545455, "max_line_length": 404, "alphanum_fraction": 0.7040474741, "num_tokens": 2261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.9059898127684335, "lm_q1q2_score": 0.8465524950518686}}
{"text": "\\section{Norm and distance}\n\\subsection{Norm} \n\\textit{Euclidean norm} (or just norm) is\\\\\n$||x||= \\sqrt{x_1^2+x_2^2+...+x_n^2}= \\sqrt{x^Tx}$\\\\\n\\textbf{Properties}\\\\\n\\textbullet homogeneity: $||\\beta x|| = |\\beta ||x|||$\\\\\n\\textbullet triangle inequality: $||x + y|| \\leq ||x|| + ||y||$\\\\\n\\textbullet non negativity: $||x|| \\geq 0$\\\\\n\\textbullet definiteness: $||x|| = 0$ only if x = 0\\\\\n\\textit{positive definiteness} = non negativity + definiteness\\\\\n\\textbf{rms}(x) = $\\sqrt{\\frac{x_1^2+...+x_n^2}{n}} = \\frac{||x||}{\\sqrt{n}}$ \\\\\n\\textbf{Norm of block vectors}\n$||(a,b,c)|| = \\sqrt{||a||^2 + ||b||^2 + ||c||^2} = ||(||a||, ||b||, ||c||)||$\\\\\n\\textbf{Chebyshev inequality}\n% Todo \nTodo\n\\subsection{Distance}\n$\\textbf{dist}(a,b) = ||a - b||$\\\\\n\\textit{Triangle Inequality}: $||a - c|| = ||(a - b) + (b - c)|| \\leq ||a-b|| + ||b-c||$\\\\\n$z_j$ is the nearest neighbor of x if $||x-z_j|| \\leq ||x-z_i||, i=1,..,m$\\\\\n\n\\subsection{Standard Deviation}\nde-meaned vector: $\\tilde{x} = x - \\textbf{avg}(x)\\textbf{1}$\\\\\nstandard deviation: \\textbf{std}(x) = \\textbf{rms}($\\tilde{x}$) = $\\frac{||x - (\\textbf{1}^Tx/n)\\textbf{1}||}{\\sqrt{n}}$\\\\\n${\\textbf{rms}(x)}^2 = {\\textbf{avg}(x)}^2 + {\\textbf{std}(x)}^2$\\\\\nBy Chebyshev inequality, $|x_i - \\textbf{avg}(x)| \\geq \\alpha \\textbf{std}(x)$ is no more than $1/\\alpha^2$ (for \n$\\alpha$ > 1)\n\\textit{Cauchy\u2013Schwarz inequality}: $|a^Tb| \\leq \\Vert a\\Vert \\Vert b \\Vert$\n\\subsection{Angle}\nangle between two nonzero vectors a, b defined as\\\\\n$\\angle(a,b) = arccos(\\frac{a^Tb}{\\Vert a \\Vert \\Vert b \\Vert})$\\\\\n$a^Tb = \\Vert a \\Vert \\Vert b \\Vert cos (\\angle(a,b))$\\\\\n\\textbf{Classification of angles}\\\\\n\n$\\theta = \\pi/2$: $a \\perp b$\\\\\n$\\theta = 0$: $a^Tb = \\Vert a \\Vert \\Vert b \\Vert$\\\\\n$\\theta = \\pi = 180^{\\circ}$ : $a^Tb = -\\Vert a \\Vert \\Vert b\\Vert$\\\\\n$\\theta \\leq \\pi/2 = 90^{\\circ} = a^Tb \\geq 0$\\\\\n$\\theta \\geq \\pi/2 = 90^{\\circ} = a^Tb \\leq 0$\\\\\n\\textbf{Correlation Coeficient}\n$\\rho = \\frac{\\tilde{a}^T\\tilde{b}}{\\Vert\\tilde{a}\\Vert\\Vert\\tilde{b}\\Vert}$\\\\\nWith $u = \\tilde{a}/\\textbf{std}(a)$ \\& $u = \\tilde{b}/\\textbf{std}(b)$, \\\\\n$\\rho = u^Tv/n$ where $\\Vert u \\Vert = \\Vert v \\Vert = n$\n\\subsection{Complexity}\n% Todo\nTodo\n", "meta": {"hexsha": "3728cacd68ca5a4323e37bba34503a0deaf15bdd", "size": 2173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter3.tex", "max_stars_repo_name": "ksb25395/COT5615", "max_stars_repo_head_hexsha": "d3f9d9375597ea2b15404ae5f46d21d9073b8697", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cheatsheet/inhalt/chapter3.tex", "max_issues_repo_name": "ksb25395/COT5615", "max_issues_repo_head_hexsha": "d3f9d9375597ea2b15404ae5f46d21d9073b8697", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter3.tex", "max_forks_repo_name": "ksb25395/COT5615", "max_forks_repo_head_hexsha": "d3f9d9375597ea2b15404ae5f46d21d9073b8697", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.2340425532, "max_line_length": 122, "alphanum_fraction": 0.5766221813, "num_tokens": 934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517061554855, "lm_q2_score": 0.880797085800514, "lm_q1q2_score": 0.8464034623767834}}
{"text": "\\subsection{Determinants}\r\n\\noindent\r\nThe determinant of a matrix is a signed number that tells by how much the transformation represented by a matrix scales volumes in a space.\r\nThe number is negative if the space was ``flipped'' during a transformation.\r\nThe number is zero if the dimension of the output space is less than that of the input space.\\\\\r\n\r\n\\noindent\r\nThe determinant is only defined for square matrices. It's easiest to understand the definition of a determinant recursively.\r\n\\begin{align*}\r\n\t\\det{\\left[ a \\right]} &= \\lvert a \\rvert = a \\\\\r\n\t\\det{\\left[\r\n\t\t\\begin{array}{cc}\r\n\t\t\ta & b \\\\\r\n\t\t\tc & d\r\n\t\t\\end{array}\r\n\t\t\\right]} &= \\begin{array}{|cc|}\r\n\t\ta & b \\\\\r\n\t\tc & d\r\n\t\\end{array} = ad - bc.\r\n\\end{align*}\r\nWe can define $a_{ij}$ as the entry in the ith row and jth column of matrix $A$ and $A_{ij}$ as the adjudicate matrix, which is the matrix $A$ if row $i$ and column $j$ were removed. This allows us to write a general formula for the determinant.\r\n\\begin{definition}\r\n\t\\begin{equation*}\r\n\t\t\\det{A} = \\sum_{j=1}^{n}{\\left(-1\\right)^{i+j}a_{ij}A_{ij}} \\text{ (for fixed i)} = \\sum_{i=1}^{n}{\\left(-1\\right)^{i+j}a_{ij}A_{ij}} \\text{ (for fixed j)}\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\\noindent\r\nThis formula allows us to use any row or column to calculate the determinant, which is especially useful if a certain row contains lots of 0's.\\\\\r\n\r\n\\noindent\r\nBelow are some properties of the determinant for some $n \\times n$ matrix $A$ and scalar $\\lambda$.\r\n\\begin{align*}\r\n\t\\det{I_n} &= 1 \\\\\r\n\t\\det{(A^T)} &= \\det{A} \\\\\r\n\t\\text{If $A$ is invertible, } \\det{(A^{-1})} &= \\frac{1}{\\det{A}} \\\\\r\n\t\\det{(\\lambda A)} &= \\lambda^n\\det{A} \\\\\r\n\t\\det{(AB)} &= \\det{A}\\det{B} \\\\\r\n\t\\text{If $A$ is triangular, } \\det{A} &= \\prod_{i=1}^{n}{a_{ii}}\r\n\\end{align*}\r\n\r\n\\begin{example}\r\n\tFind the determinant of the following 3 x 3 matrix.\r\n\t\\begin{equation*}\r\n\t\tA = \\begin{bmatrix}\r\n\t\t\t1 & 3 & 7 \\\\\r\n\t\t\t0 & 2 & -1 \\\\\r\n\t\t\t2 & 7 & 9\r\n\t\t\\end{bmatrix}\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nWe'll use the first column since it has only two non-zero entries.\r\n\\begin{equation*}\r\n\t\\begin{bmatrix}\r\n\t\t1 & 3 & 7 \\\\\r\n\t\t0 & 2 & -1 \\\\\r\n\t\t2 & 7 & 9\r\n\t\\end{bmatrix} = 1 \\text{ } \\begin{array}{|cc|}\r\n\t\t2 & -1 \\\\\r\n\t\t7 & 9\r\n\t\\end{array} + 2 \\text{ } \\begin{array}{|cc|}\r\n\t\t3 & 7 \\\\\r\n\t\t2 & -1\r\n\t\\end{array} = (18+7) + 2(-3-14) = -9.\r\n\\end{equation*}", "meta": {"hexsha": "47b4f21756f989e3640bd967ab82ce525225559c", "size": 2347, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/vectorsMatrices/determinants.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/vectorsMatrices/determinants.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/vectorsMatrices/determinants.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 36.1076923077, "max_line_length": 246, "alphanum_fraction": 0.6195142735, "num_tokens": 850, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104933824754, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.8463697386964459}}
{"text": "\\section{Parametric Inference}\n\nIn parametric inference, the quantity of interest might be some function $T(\\theta)$. The sought-after parameters are \\textit{parameters of interest} and additional parameters that emerge as part of the model are \\textit{nuisance parameters}. Parametric inference deals with creating parametric estimators.\n\n\\subsection{Method of Moments}\nThe method of moments relies on a system of linear equations to link estimators of moment to sample moments. The $j$th moment is given by:\n\n\\begin{equation}\n\\alpha_j = \\int x^j dF_{\\theta}(x)\n\\end{equation}\n\nThe $j$th sample moment is given by:\n\n\\begin{equation}\n\\hat{\\alpha}_j = \\frac{1}{n} \\sum_{i=1}^ n X_i^j\n\\end{equation}\n\n\nThe method of moments estimator $\\hat{\\theta}_n$ is defined to be the value of $\\theta$ so that:\n\n\\begin{equation}\n\\begin{array}{l}\n\\alpha_1(\\hat{\\theta}_n) = \\hat{\\alpha}_1\\\\\n\\alpha_2(\\hat{\\theta}_n) = \\hat{\\alpha}_2\\\\\n\\alpha_3(\\hat{\\theta}_n) = \\hat{\\alpha}_3\\\\\n\\alpha_4(\\hat{\\theta}_n) = \\hat{\\alpha}_4\\\\\n\\vdots\n\\end{array}\n\\end{equation}\n\nThe method of moments estimator satisfies:\n\n\\begin{enumerate}\n\\item The estimate $\\hat{\\theta}_n$ exists with probability tending to 1.\n\\item The estimate is consistent: $\\hat{\\theta}_n \\xrightarrow{P}\\theta$ (it converges in probability)\n\\item The estimate is asymptotically normal (cf. \\cite{wasserman2003all}, pp.122)\n\\end{enumerate}\n\n\n\\subsection{Maximum Likelihood Estimation}\n\nThe maximum likelihood estimator is the value $\\hat{\\theta}$ that maximizes the joint probability density of the data, called the likelihood function. \n\nFor i.i.d. random variables with pdf $f(x;\\theta)$, the likelihood function is:\n\n\\begin{equation}\n\\mathscr{L}_n(\\theta) = \\prod_{i=1}^n f(X_i;\\theta)\n\\end{equation}\n\nAnd the log likelihood functin is $l_n(\\theta) = \\log \\mathscr{L}_n(\\theta)$. Since $\\log$ is a monotonic function, maximizing the log-likelihood yields the same estimator as maximizing the likelihood directly. Log-likelihood is often easier to deal with, and alleviates numerical issues associated with the often sharply spiked likelihood function. \n\nMLE estimators have a flurry of desirable properties under certain smoothness conditions on the density function. \n\n\\begin{itemize}\n\\item Consistency: convergence in probability upon the true value\n\\item Equivariance: if $\\hat{\\theta}_n$ is the MLE of $\\theta$ then $g(\\hat{theta}_n)$ is the MLE of $g(\\theta)$\n\\item Asymptotically Normal\n\\item Asymptotically Optimal / Efficient: smallest variance, at least for large samples.\n\\item Approximately the Bayes estimator.\n\\end{itemize}\n\n\n\\subsection{Parametric Confidence Intervals}\n\nConfidence intervals for infered parameters in the parametric setting can be derived, for example, using the delta method (assuming that the estimators are asymptotically normal) or using parametric bootstrap. In the nonparametric case, bootstrap sampled from the empirical CDF. In the parametric case, bootstrap sample from the density $f(X;\\hat{\\theta})$ where $\\hat{\\theta}$ is the estimator.\n\n\n\\section{Score Function, Fisher Information}\nGiven some pdf $f(X;\\theta)$, the score function is given by: \n\n\\begin{equation}\ns(X;\\theta) \\frac{\\partial \\log f(X;\\theta)}{\\partial \\theta}\n\\end{equation}\n\nThe Fisher information is the variance of the score function at each datapoint:\n\n\\begin{equation}\nI_n(\\theta) = \\mathbb{V}_{\\theta} \\left(\\sum_{i=1}^n s(X_i ; \\theta) \\right)\n\\end{equation}\n\n\n", "meta": {"hexsha": "c14e62ae8513fbdc05f78263230fcc88bf0e6ecb", "size": 3422, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/stats_parametricinference.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/stats_parametricinference.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/stats_parametricinference.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.7317073171, "max_line_length": 395, "alphanum_fraction": 0.7574517826, "num_tokens": 931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660962919971, "lm_q2_score": 0.8872045981907006, "lm_q1q2_score": 0.8463631071482925}}
{"text": "\\section{Vector Spaces and Subspaces}\r\nLet $F$ be an arbitrary field.\r\n\\begin{definition}\r\n    An $F$-vector space (or a vector space over $F$) is an abelian group $(V,+)$ equipped with a function $F\\times V\\to V,(\\lambda,v)\\mapsto \\lambda v$ such that for any $v,v_1,v_2\\in V,\\lambda,\\mu\\in F$:\\\\\r\n    1. $\\lambda(v_1+v_2)=\\lambda v_1+\\lambda v_2$.\\\\\r\n    2. $(\\lambda_1+\\lambda_2)v=\\lambda_1v+\\lambda_2v$.\\\\\r\n    3. $\\lambda(\\mu v)=(\\lambda\\mu v)$.\\\\\r\n    4. $1v=v$.\\\\\r\n    This function is often called scalar multiplication of the vector space.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. Take $n\\in\\mathbb N$.\r\n    Then the set of $n$-tuples in $F$, denoted $F^n$, is a vector space under the operations\r\n    \\begin{align*}\r\n        (x_1,\\ldots,x_n)+(y_1,\\ldots,y_n)&=(x_1+y_1,\\ldots,x_n+y_n)\\\\\r\n        \\lambda(x_1,\\ldots,x_n)&=(\\lambda x_1,\\ldots,\\lambda x_n)\r\n    \\end{align*}\r\n    2. For any set $X$, write $\\mathbb R^X=\\{f:X\\to\\mathbb R\\}$.\r\n    It is a vector space over $\\mathbb R$ via\r\n    $$(f_1+f_2)(x)=f_1(x)+f_2(x),(\\lambda f)(x)=\\lambda f(x)$$\r\n    3. The set $M_{n,m}(F)$ consisting of $F$-valued $n\\times m$ matrices is a vector space by interpreting it as $F^{n\\times m}$.\r\n\\end{example}\r\n\\begin{remark}\r\n    The axioms of scalar multiplication imply that $0v=0$ for any $v\\in V$, as one can check.\r\n\\end{remark}\r\n\\begin{definition}[Subspace]\r\n    Let $V$ be a vector space over $F$.\r\n    A subset $U\\subset V$ is a subspace of $V$ (or $U\\le V$ as vector spaces) iff $U\\le V$ as subgroups and $\\forall\\lambda\\in F,u\\in U,\\lambda u\\in U$.\r\n\\end{definition}\r\nSo basically, a subgroup $U$ is a subspace if we can properly restrict the original scalar product to make it a vector space over $F$ as well.\r\nOne can also check oneself that a subspace of a subspace is also a subspace of the original space.\r\n\\begin{example}\r\n    Take $V=\\mathbb R^{\\mathbb R}$.\r\n    $C(\\mathbb R)\\le V$ (the set of continuous functions $\\mathbb R\\to\\mathbb R$) is a subspace of $V$, and the set of polynomials is a subspace of $C(\\mathbb R)$.\\\\\r\n    Take $V=\\mathbb R^3$, then a line is a subspace iff it passes through the origin.\r\n    A plane is a subspace iff it passes through the origin as well.\r\n\\end{example}\r\n\\begin{proposition}\r\n    Let $V$ be an $F$-vector space and $U,W\\le V$ as vector spaces, then $U\\cap W\\le V$ as vector spaces.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Just check.\r\n\\end{proof}\r\nHowever, the union of two subspaces is generally not a subspace unless one is contained in the other already.\r\n\\begin{example}\r\n    Take $V=\\mathbb R^2$ and $U,W$ two axes, then $(1,0)+(0,1)=(1,1)$ is already not in the union.\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $V$ be an $F$-vector space.\r\n    Let $U,W\\le V$.\r\n    The sum of $U$ and $W$ is the set $U+W=\\{u+w:u\\in U, w\\in W\\}$.\r\n\\end{definition}\r\n\\begin{example}\r\n    Take $V=\\mathbb R^2$ and $U,W$ two axes again, then $U+W=V$.\r\n\\end{example}\r\n\\begin{proposition}\r\n    The sum of two subspaces is a subspace.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\nJust to mention, one can easily check that $U+W$ is the smallest subspace of $V$ containing $U$ and $W$.\r\n\\begin{definition}\r\n    Let $V$ be an $F$-vector space and $U\\le V$.\r\n    The quotient space $V/U$ is the quotient group equipped with the scalar multiplication $\\lambda(v+U)=\\lambda v+U$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    This scalar multiplication is well-defined and makes $V/U$ a vector space.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Just check.\r\n\\end{proof}\r\n", "meta": {"hexsha": "f8d8e9f1ce832c577fd81d4409e77ab4aaf1b4bf", "size": 3517, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/spaces.tex", "max_stars_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_stars_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1/spaces.tex", "max_issues_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_issues_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1/spaces.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.1780821918, "max_line_length": 207, "alphanum_fraction": 0.6545351152, "num_tokens": 1177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.9086179025005187, "lm_q1q2_score": 0.8463435093391478}}
{"text": "%% Magic command to compile root document\n% !TEX root = ../../thesis.tex\n\n%% Reset glossary to show long gls names\n\\glsresetall\n\n%% Set path to look for the images\n\\graphicspath{{./Sections/Basics/Resources/}}\n\n% what is a ANN\n\nRoughly speaking, an \\gls{ann} is a non-linear function $f:\\mathbb{R}^D \\rightarrow \\mathbb{R}^L$, that maps an input $\\bs{x}\\in\\mathbb{R}^D$ with an output $\\bs{y}\\in\\mathbb{R}^L$. Of course, to consider $f$ as a \\gls{ann}, $f$ must have a specific form that will be address later. However, for the sake of this explanation, let us start by defining a simple function as follow\n\n\\begin{equation}\n  \\begin{split}\n    f(\\bs{x},\\bs{w}) &:= h \\left(w_0 + \\sum_{j=1}^{M-1}w_j\\phi_j(\\bs{x}) \\right) \\\\\n    &= h(\\bs{w}^T\\bs{\\phi}(\\bs{x})) \\\\\n    &:= h(z)\n  \\end{split}\n  \\label{eq:basics:slp}\n\\end{equation}\n\n\\noindent where $\\bs{\\phi}:\\mathbb{R}^{D+1} \\rightarrow \\mathbb{R}^M$ is an element-wise function, with $\\phi_0:=1$, know as \\hl{basis function}, $h:\\mathbb{R} \\rightarrow \\mathbb{R}$ is a function know as \\hl{activation function} and $\\bs{w}\\in\\mathbb{R}^M$ is the parameter vector. The parameters $w_j$, with $j\\in\\{1,\\dots M-1\\}$ are known as \\hl{weights}, while the parameter $w_0$ is know as \\hl{bias}.\n\nThen, an \\gls{ann} is composition of functions of the same form as \\ref{eq:basics:slp}, with non-linear \\hl{activation functions}, and where the basis functions are also of the same form as \\ref{eq:basics:slp} \\cite{bishop2006pattern}\n\n\\begin{equation}\n  F(\\bs{x}, \\bs{W}) :=\n  h_K(\\bs{w}^T_K h_{K-1}(\\bs{w}^T_{K-1} \\dots h_{0}(\\bs{w}^T_0 \\bs{x}) \\dots ))\n  \\label{eq:basics:ann}\n\\end{equation}\n\nThe subscript in the parameter vectors $\\bs{w}_k$ and the activation functions $h_k$, with $k\\in\\{0, \\dots, K\\}$, of \\ref{eq:basics:ann} represents the depth of the layers. Note that unlike the other layers, the base function of the \\hl{input layer} (k = 0) is the identity function. Furthermore, the activation function of the \\hl{output layer} $h_K$ does not necessarily have to be non-linear. Instead, it is chosen based on the type of function we want to approximate. In our case, since we have a regression problem (predicting \\gls{tr}), $h_K$ is chosen as the identity function.\n\nThere are different non-linear activation functions that can be chosen for the hidden units. However, all the models showed in this work use the \\gls{relu}\n\n\\begin{equation}\n  ReLU := max\\{0, x\\}\n\\end{equation}\n\nFigure \\ref{fig:basics:ann:relu} shows the \\gls{relu} activation function.\n\n% Figure made in notebook Preprocessing_resources.ipynb\n\\begin{figure}[!ht]\n  \\centering\n  \\includegraphics[width=0.6\\linewidth]{ReLU.jpg}\n  \\caption{\\gls{relu} activation function.}\n  \\label{fig:basics:ann:relu}\n\\end{figure}\n\nFigure \\ref{fig:basics:ann:ann} shows a graphical representation of a \\gls{ann}. The circles represent the activation function applied to what is inside it. Black colored circles represent the identity function, red colored circles the non-linear activation function for the hidden layers, while green any function for the output layer that suits the problem we want to solve. Note that values inside the circles of the hidden and output layers $z^k_i$, for $k\\in\\{0, \\dots, K\\}$ and $i$ representing one of the units of the $k$ layer, are the output of a function of the same form as \\ref{eq:basics:slp}. The lines connecting the circles represent the weights and biases corresponding to each layer $\\bs{W}_k$, for $k\\in\\{0, \\dots, K\\}$. The circles in the \\hl{hidden layers} are known as \\hl{hidden units}.\n\n\\begin{figure}[!ht]\n  \\centering\n  \\includegraphics[width=0.8\\linewidth]{Diagrams/ANN.jpg}\n  \\caption{Graphical representation of an \\gls{ann}. The color of the circles represents the type of activation function. Black means the identity, red a non-linear function for the hidden layers and green any function for the output layer.}\n  \\label{fig:basics:ann:ann}\n\\end{figure}\n\nStrictly speaking, equation \\ref{eq:basics:ann} and figure \\ref{fig:basics:ann:ann} represent a \\hl{fully connected feedforward neural network}. However, in this work we will refer to it just as \\gls{ann}, which in some literature is also known as \\gls{mlp}. Also, hidden layers are also known as \\hl{Dense layers}.\n\n\\subsubsection{Update rule}\n\nSow far we have introduced the general form an \\gls{ann} must have. Moreover, equation \\ref{eq:basics:ann} shows that an \\gls{ann} is simply a non-linear function controlled by a set of adjustable parameters $\\bs{W}$. Therefor the question is, how can we approximate this parameters?\n\nRecall that we are dealing with a supervised learning problem, which means that we can use both the input data (images of cell nucleus, $\\bs{X}$) and the output data (the \\glspl{tr}, $\\bs{Y}$) to approximate $\\bs{W}$. Therefore, we can fed the \\gls{ann} with $\\bs{X}$, and then measure its performance by comparing its output $\\hat{\\bs{Y}}$ against the true values $\\bs{Y}$.\n\nThis comparison is made by means of a \\hl{loss function} $\\mathcal{L}$ that must be chosen beforehand. The choice of $\\mathcal{L}$ depends mainly on the type of problem you are solving (regression, classification, etc.). However, even for each type, there are many different options. For now, let us just say that $\\mathcal{L}$ should return high values when $\\hat{\\bs{Y}}$ is far from the true values $\\bs{Y}$, and low when they are close.\n\nThen, we can fit the values of $\\bs{W}$, by minimizing the loss function $\\mathcal{L}$ each time the model is fed with an input value $\\bs{x}$. Since the gradient of $\\mathcal{L}$ with respect to $\\bs{W}$ (i.e., $ \\nabla_{\\bs{W}} \\mathcal{L}$) returns the direction in which the loss function grows the fastest, then we choose $- \\nabla_{\\bs{W}} \\mathcal{L}$ as the direction of our update rule\n\n\\begin{equation}\n  \\bs{W}_{new} = \\bs{W}_{old} - \\alpha \\nabla_{\\bs{W}} \\mathcal{L}(\\bs{W}_{old})\n  \\label{eq:basics:ann:learn_rule}\n\\end{equation}\n\n\\noindent where $\\alpha \\in \\mathbb{R}^+$ (known as \\hl{learning rate}) controls how much we move in the direction of $-\\nabla_{\\bs{W}} \\mathcal{L}(\\bs{W}_{old})$ on every step.\n\nThe iterative method in which \\ref{eq:basics:ann:learn_rule} is applied over elements of $\\bs{X}$ to optimize $\\bs{W}$ is known as \\gls{gd} \\cite{bishop2006pattern}.\nHowever, in practice \\ref{eq:basics:ann:learn_rule} is not applied for a single element of $\\bs{X}$ every time, but to a random subset of $\\bs{X}$ (known as a \\hl{Batch}) instead.\nThe number of elements in batch is fixed over all the iteration (training), and is an hyperparameter known as \\hl{Batch Size} $bs$\\footnote{Normally the training data is separated in disjoint batches, which means that it could happen that last batch to be smaller than the selected $bs$.}.\nAs a rule of thumb, $bs$ should be no less than 30 (for the selected sample to be representative of $\\bs{X}$). In practice $bs$ is usually chosen as a power of 2.\nThis process is known as \\gls{sgd} and computationally is less  expensive than \\gls{gd}.\n\nHowever, \\gls{gd} (\\gls{sgd}) has a downside, the choice of its hyperparameter $\\alpha$ (learning rate). In practice, it has been shown that the correct choice of $\\alpha$ is essential to train an \\gls{ann} successfully. Therefore, other algorithms (\\hl{optimizers}) have been proposed to mitigate this problem. The revision of these optimizers is out of the scope to this work. However, all of them follow the same idea proposed by \\gls{gd}. For example, instead of having a fixed learning rate $\\alpha$ as in \\gls{gd}, the \\gls{adam} optimizer adapts its learning rate dynamically during training depending on the mean and variance of the loss function \\cite{kingma2014adam}.\n\n\\subsubsection{Back propagation}\n\nNevertheless, there is still one question that needs to be answered, which is how to efficiently calculate the derivative of the loss function ($\\nabla_{\\bs{W}} \\mathcal{L}$) with respect to all the parameters of the \\gls{ann}. The answer to this is through an algorithm called \\hl{backpropagation}, which is performed during the \\hl{training process}. Again, there is a lot of literature that explains this in depth(for instance \\cite{Goodfellow-et-al-2016} or \\cite{bishop2006pattern}). Therefor, here we will just provide the intuition behind it.\n\nRecall that $\\mathcal{L}$ is a function of the true values $y$ and $\\hat{y}$ i.e., $\\mathcal{L}(y, \\hat{y})$. Also from equation \\ref{eq:basics:ann} and figure \\ref{fig:basics:ann:ann} note that\n\n\\begin{equation}\n  \\begin{split}\n    y &:= F(\\bs{x}, \\bs{W}) \\\\\n    &= h_K(\\bs{z}^K) \\\\\n    &= h_K(\\bs{W}_K^T h_{K-1}(\\bs{z}^{K-1}))\n  \\end{split}\n  \\label{eq:basics:ann:backprop_1}\n\\end{equation}\n\nand therefore\n\n\\begin{equation}\n  \\begin{split}\n    \\nabla_{\\bs{W}_K} \\mathcal{L} &= \\frac{\\partial \\mathcal{L}}{\\partial \\bs{W}_K} \\\\\n    &= \\frac{\\partial \\mathcal{L}}{\\partial \\hat{y}}\n    \\frac{\\partial \\hat{y}}{\\partial \\bs{z^K}}\n    \\frac{\\partial \\bs{z^K}}{\\partial \\bs{W}_K} \\\\\n  \\end{split}\n  \\label{eq:basics:ann:backprop_2}\n\\end{equation}\n\n\\noindent which is just the product of the derivative of the loss function w.r.t. $\\hat{y}$ (i.e., $\\frac{\\partial \\mathcal{L}}{\\partial \\hat{y}}$), the derivative of the activation function of the output layer w.r.t the argument of the last layer (i.e., $\\frac{\\partial \\hat{y}}{\\partial \\bs{z^K}}$) and the output of the layer $K-1$ (i.e., $\\frac{\\partial \\bs{z^K}}{\\partial \\bs{W}_K}=h_{K-1}(\\bs{z^{K-1}})$).\n\nNote that we can easily compute the gradient of $\\mathcal{L}$ w.r.t deeper parameters $\\bs{W}_k$ (for $k\\in\\{0, \\dots, K-1\\}$), just by extending \\ref{eq:basics:ann:backprop_1} and \\ref{eq:basics:ann:backprop_2}.\n\nThis shows how by means of the \\hl{chain rule}\\footnote{$(f \\circ g)'=(f \\circ g) \\cdot g'$, or equivalently $h'(x)=f'(g(x))g'(x)$, for $h(x):=f(g(x))$.}, the backpropagation algorithm can compute the gradient of the loss function w.r.t. a specific parameter, just by multiplying the derivative of the loss function, the derivative of the activation functions and some values computed during the evaluation of the \\gls{ann}.\n\n\\subsubsection{Model development}\n\nThe properties of \\glspl{ann} have been studied extensively before (\\cite{cybenko1989approximation}, \\cite{hornik1989multilayer}, \\cite{funahashi1989approximate}) and established in the \\hl{Universal approximation theorem}\n\n\\begin{theorem}[Universal approximation theorem]\n  An \\gls{mlp} with a linear output layer and one hidden layer can approximate any continuous function defined over a closed and bounded subset of $\\mathbb{R}^D$, under mild assumptions on the activation function (\\hl{squashing} activation function) and given the number of hidden units is large enough.\n\\end{theorem}\n\nFor this reason \\gls{ann} are known as \\hl{universal approximators}, since they are able to approximate any continuous function on a compact\\footnote{A set $A$ in a metric space is said to be \\hl{compact} if it is close (i.e., it contain all its limit points) and bounded (i.e., all its points lie within some fixed distance of each other) \\cite{bartle2000introduction}.} input domain with an arbitrary accuracy \\cite{bishop2006pattern}.\n\nThese means that, as long as a \\gls{ann} has a sufficiently large number of hidden units, the loss function can be reduced as much as desired. However, this nice property can also lead to an unwanted one known as \\hl{overfitting}.\nIntuitively this means that the \\gls{ann} \\hl{memorize} the data used to train it (low error/bias), and therefore it is not able to perform (or \\hl{generalize}) well when it is fed with new data (high error/bias and variance). This happens mainly when the \\gls{ann} is optimized/fed too many times with the same data.\n\nOn the other hand, \\hl{underfitting} means that the \\gls{ann} performs poorly on both new data and data used to train the network (high bias and low variance). This usually happens when the training time is insufficient or the \\gls{ann} is not complex enough (too few hidden units and/or layers).\n\nFigure \\ref{fig:basics:ann:fitting} shows synthetic data (blue circles), generated from a sine function (green line) and random noise sampled from a normal distribution.\nThe red line in figure \\ref{fig:basics:ann:fitting:under} represents a fitted model with high bias and low variance (underfitting), while in figure \\ref{fig:basics:ann:fitting:over} a model with low bias and high variance (overfitting). The red line in figure \\ref{fig:basics:ann:fitting:good}, represents a model with low bias and variance (good fit and good generalization).\n\n% this plots were extracted from page 7 (Bishop) and adapted in the file overfitting.odg\n\\begin{figure}[htb]\n  \\centering\n  \\begin{subfigure}[t]{.3\\linewidth}\n    \\includegraphics[width=\\linewidth]{Diagrams/underfitting.jpg}\n    \\caption{Underfitted model.}\n    \\label{fig:basics:ann:fitting:under}\n  \\end{subfigure}\n  \\vspace{3mm}\n  \\begin{subfigure}[t]{.3\\linewidth}\n    \\includegraphics[width=\\linewidth]{Diagrams/goodfit.jpg}\n    \\caption{Model with good fit and generalization.}\n    \\label{fig:basics:ann:fitting:good}\n  \\end{subfigure}\n  \\vspace{3mm}\n  \\begin{subfigure}[t]{.3\\linewidth}\n    \\includegraphics[width=\\linewidth]{Diagrams/overfitting.jpg}\n    \\caption{Overfitted model.}\n    \\label{fig:basics:ann:fitting:over}\n  \\end{subfigure}\n  \\caption{Representation of a model (red line) with underfitting \\subref{fig:basics:ann:fitting:under}), good fit \\subref{fig:basics:ann:fitting:good}) and overffiting \\subref{fig:basics:ann:fitting:over}), trained over synthetic data (blue small circles). The synthetic data was generating by adding random noise to a sine function (green line) on the interval $[0,1]$. Image source \\cite{bishop2006pattern}.}\n  \\label{fig:basics:ann:fitting}\n\\end{figure}\n\nIn practice, we seek to fit models that has low bias and low variance (i.e., good accuracy and good generalization). Therefore, to prevent overfitting we split the data into 3 different sets; \\hl{training}, \\hl{validation} and \\hl{test}, and train the model using only the first set. Then, during model training, we measure how well the model is generalizing by comparing the value of the loss function when it is evaluated in the training and validation set \\footnote{This is usually known as the \\hl{bias\u2013variance tradeoff}.}.\nDuring the model development, the \\hl{test} set is never evaluated and is only used at the end, to report the model performance. This methodology is shown in figure \\ref{fig:basics:model_train_process}\n\nFigure \\ref{fig:basics:bias_variance} shows this \\hl{bias\u2013variance tradeoff} between training and validation set. In practice, multiple versions of the model are saved during training and then the one with the lowest validation error is chosen (red dot on figure \\ref{fig:basics:bias_variance}).\n\n% figure taken from BL_070121_0942.ipynb\n\\begin{figure}[!ht]\n  \\centering\n  \\includegraphics[width=0.8\\linewidth]{bias_variance.png}\n  \\caption{Bias\u2013variance tradeoff. In orange (respectively blue) the loss function curve when it is evaluated in the validation (respectively training) set. The red dot shows the lowest loss for the validation set.}\n  \\label{fig:basics:bias_variance}\n\\end{figure}\n\n\\begin{figure}[!ht]\n  \\centering\n  \\includegraphics[width=0.8\\linewidth]{Diagrams/Model_methodologt.jpg}\n  \\caption{Model development methodology.}\n  \\label{fig:basics:model_train_process}\n\\end{figure}\n\nThe methodology shown in figure \\ref{fig:basics:model_train_process} is also used to optimize the hyperparameters of the model, like the number hidden units/layers or the activation function of the hidden layers.\n\n\\subsubsection{Batch Normalization}\n\nHowever, overfitting is not the only problem we may encounter when training an \\gls{ann}. Training \\gls{ann} with several layers can be complicates, since the distribution of the data can change from layer to layer. This means that the input and output distribution of a layer will not necessarily be the same. It has been empirically proven that this can affect the training performance, since it require the use of lower learning rates \\cite{ioffe2015batch}. This can also lead to \\hl{saturation}\\footnote{\\hl{Saturation} is a commonly used term to refer to the situation when the evaluation of a \"squashing\" function returns values close to some of its horizontal asymptotes most of the time. Remember that these \"squash\" functions (like \\hl{Sigmoid} or \\hl{tanh}) compress the real line $(-\\inf, \\inf)$ into an interval of finite length $(a, b)$.} of the activation functions, so a more careful initialization of the \\gls{ann} parameters is required. To address this problem Ioffe et al. \\cite{ioffe2015batch} proposed to normalize the layer inputs.\n\nRoughly speaking, batch normalization consist of two main steps; 1) the standardization of the layer input and 2) the normalization of the standardized data. For the first step the layer input is standardized using parameters extracted from the \\hl{batch}\n\n\\begin{equation}\n    \\bs{z}'_k := \\frac{\\bs{z}_k-\\bs{\\mu}_k}{\\sqrt{\\bs{\\sigma}_k^2-\\epsilon}}\n\\end{equation}\n\\noindent with\n\\begin{equation}\n  \\begin{split}\n    \\bs{\\mu}_k &= \\frac{1}{M}\\sum_{m=1}^M \\bs{z}_k \\\\\n    \\bs{\\sigma}_k^2 &= \\frac{1}{M}\\sum_{m=1}^M (\\bs{z}_k - \\bs{\\mu}_k)^2 \\\\\n  \\end{split}\n\\end{equation}\n\n\\noindent where $M$ is the \\hl{Batch} size and $k$, with $k \\in \\{0 \\dots K\\}$, denotes the layer.\n\nNote that for each layer $k$ we have different normalization parameters $\\bs{\\mu}_k$ and $\\bs{\\sigma}_k$. Moreover, this normalization parameters are vectors of the same shape as the layer size (i.e., one pair of normalization parameters per unit/neuron).\n\nThe second step in batch normalization consist on normalizing the standardized data $\\bs{z}'_k$ using parameters $\\bs{\\gamma}_k$ and $\\bs{\\beta}_k$ learned during training\n\n\\begin{equation}\n    \\overset{\\sim}{\\bs{z}}_k := \\bs{\\gamma}_k \\odot \\bs{z}'_k + \\bs{\\beta}_k\n\\end{equation}\n\n\\noindent where $\\odot$ denotes \\hl{element-wise} multiplication. At the beginning of the training $\\bs{\\gamma}_k=1$ and $\\bs{\\beta}_k=0$ are used for all the layers and units.\n\nDuring training, the normalization parameters of each epoch are stored, so the average ($\\bar{\\bs{\\gamma}}_k$ and $\\bar{\\bs{\\beta}}_k$) can be used during evaluation (when the model is not training).\n\n\\subsubsection{Residual Block V2}\n\nAs already mentioned, the \\hl{Universal approximation theorem} guarantees that the training error can be reduced by adding more layer to an \\gls{ann}. However, in practice it is not that simple. As we add layers to an \\gls{ann}, the training becomes more unstable and difficult as we can face vanishing or exploding gradients (when the value of the gradients become very close to 0 or $\\inf$ respectively during back propagation). To overcome this problem, He et al. (\\cite{he2015deep} and \\cite{he2016identity}) proposed the \\hl{residual blocks}, which have been empirically shown to make deep \\gls{ann} training more stable.\nThe core idea of residual blocks is to reformulate the layers as \\hl{learning residual functions} with reference to the layer inputs, by adding an \\hl{identity connection}. Then, if a layer is not longer beneficial to the \\gls{ann} (e.g. in case of gradient vanishing), the \\gls{ann} can just \"skip\" it. Figure \\ref{fig:basics:residual_block} shows a diagram of the second version of a residual block \\cite{he2016identity}.\n\n\\begin{figure}[!ht]\n  \\centering\n  \\includegraphics[width=\\linewidth]{Diagrams/Residual_block_v2.jpg}\n  \\caption{Residual block V2.}\n  \\label{fig:basics:residual_block}\n\\end{figure}\n", "meta": {"hexsha": "0bbbd8b7ee039b810a9552febc3305f978d4c1ed", "size": 19515, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Manuscript/Sections/Basics/Artificial_Neural_Networks.tex", "max_stars_repo_name": "andresbecker/master_thesis", "max_stars_repo_head_hexsha": "c67b8309b524ccfd02448573f2352ce57b5531cc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Manuscript/Sections/Basics/Artificial_Neural_Networks.tex", "max_issues_repo_name": "andresbecker/master_thesis", "max_issues_repo_head_hexsha": "c67b8309b524ccfd02448573f2352ce57b5531cc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Manuscript/Sections/Basics/Artificial_Neural_Networks.tex", "max_forks_repo_name": "andresbecker/master_thesis", "max_forks_repo_head_hexsha": "c67b8309b524ccfd02448573f2352ce57b5531cc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 86.3495575221, "max_line_length": 1053, "alphanum_fraction": 0.7419420958, "num_tokens": 5572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572777987970316, "lm_q2_score": 0.8840392725805822, "lm_q1q2_score": 0.8462711689060688}}
{"text": "\\section{K-Means Clustering}\nCLustering seeks to group similiar points of data together in a cluster. We\ndenote $c^{(i)}$ as the cluster for data point $i$ and $\\mu_j$ as the center\nfor cluster $j$. We denote $k$ as the number of clusters and $n$ as the\ndimension of our data.\n\\subsection{Algorithm}\nAfter randomly initializing the cluster centroids\n$\\mu_1, \\mu_2, \\hdots, \\mu_k \\in \\mathbb{R}^n$, repeat until convergence:\n\\begin{enumerate}\n  \\item For every data point $i$:\n    \\begin{equation}\n      c^{(i)}=\\underset{j}{\\textrm{arg min}}||x^{(i)}-\\mu_j||^2\n    \\end{equation}\n  \\item For each cluster $j$:\n    \\begin{equation}\n      \\mu_j=\\frac{\\displaystyle\\sum_{i=1}^m1_{\\{c^{(i)}=j\\}}x^{(i)}}{\\displaystyle\\sum_{i=1}^m1_{\\{c^{(i)}=j\\}}}\n    \\end{equation}\n\\end{enumerate}\nThe first step is known as cluster assignment, and the second updates the\ncluster center (i.e. the average of all points in the cluster). In order to\nsee if it converges, use the distortion function:\n\\begin{equation}\n  J(c,\\mu)=\\sum_{i=1}^m||x^{(i)}-\\mu_{c^{(i)}}||^2\n\\end{equation}\nThe distortion function $J$ is non-convex, and coordinate descent of $J$ is not\nguaranteed to converge to the global minimum (i.e. susceptible to local optima).\n\\subsection{Hierarchical Clustering}\nHierarchical clustering is a clustering algorithm with an agglomerative\nhierarchical approach that builds nested clusters in a successive manner. The\ntypes are:\n\\begin{enumerate}\n  \\item Ward Linkage: minimize within cluster distance\n  \\item Average Linkage: minimize average distance between cluster pairs\n  \\item Complete Linkage: minimize maximum distance between cluster pairs\n\\end{enumerate}\n\\subsection{Clustering Metrics}\nIn an unsupervised learning setting, it is often hard to assess the\nperformance of a model since we don't have the ground truth labels as was\nthe case in the supervised learning setting.\n\\paragraph{Silhouette coefficient} By noting $a$ and $b$ the\nmean distance between a sample and all other points in the same class,\nand between a sample and all other points in the next nearest cluster,\nthe silhouette coefficient $s$ for a single sample is defined as follows:\n\\begin{equation}\n  s = \\frac{b - a}{\\max(a, b)}\n\\end{equation}\n\\paragraph{Calinskli-Harabaz Index} By noting $k$ the number of clusters, $B_k$\nand $W_k$ the between and within-clustering dispersion matricies defined as:\n\\begin{equation}\n  B_k=\\sum_{j=1}^kn_{c^{(i)}}(\\mu_{c^{(i)}}-\\mu)(\\mu_{c^{(i)}}-\\mu)^T\n\\end{equation}\n\\begin{equation}\n  W_k=\\sum_{i=1}^m(x^{(i)}-\\mu_{c^{(i)}})(x^{(i)}-\\mu_{c^{(i)}})^T\n\\end{equation}\nthe Calinksli-Harabaz index $s(k)$ indicated how well a clustering model\ndefines its clusters, such that higher scores indicate more dense and well\nseparated cluster assignments. It is defined as:\n\\begin{equation}\n  s(k)=\\frac{\\textrm{Tr}(B_k)}{\\textrm{Tr}(W_k)}\\times\\frac{N-k}{k-1}\n\\end{equation}\n", "meta": {"hexsha": "d95b567c792964b1c605391d634d4a6d3e803077", "size": 2873, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/kmeans.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/kmeans.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/kmeans.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.0983606557, "max_line_length": 112, "alphanum_fraction": 0.7267664462, "num_tokens": 879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465098415278, "lm_q2_score": 0.9046505376715775, "lm_q1q2_score": 0.8461617230373716}}
{"text": "\nThe Weibull distribution may be useful for fitting fat-tailed\nempirical distributions.\n\nIn the literature, the Weibull is sometimes called a ``stretched\nexponential'' distribution when its shape parameter $\\tau$ is less\nthan 1. ``Stretched exponential'' distributions in the literature are\neither Weibull (PDF $ = \\lambda \\tau (\\lambda x)^\\tau exp\\left[-\n(\\lambda x)^tau \\right]$ or a more simple PDF $\\propto exp\\left[-\n{\\lambda(x-\\mu)}^tau \\right]$. Easel treats the latter form in the\n\\eslmod{stretchexp} module.\n\n\\subsection{Weibull densities}\n\nThe probability density function (PDF) is:\n\n\\begin{equation}\nP(X=x) = \\lambda \\tau [\\lambda(x - \\mu)]^{\\tau-1} e^{- [\\lambda(x-\\mu)]^{\\tau}}\n\\label{eqn:weibull_pdf}\n\\end{equation}\n\nThe cumulative distribution function (CDF) is:\n\n\\begin{equation}\nP(X \\leq x) = 1 - e^{- [\\lambda(x-\\mu)]^{\\tau}}\n\\label{eqn:weibull_cdf}\n\\end{equation}\n\nVariate $x$ ranges $\\mu \\leq x < \\infty$. (However, for $\\tau < 1$,\nthe PDF goes to infinity at $x=\\mu$, so evaluating at $x=\\mu$ may not\nbe desired.)\n\nLocation parameter $\\mu$ is unconstrained, $-\\infty < \\mu <\n\\infty$. (Weibull distributions are usually represented without an\nexplicit location parameter, implicitly assuming $\\mu = 0$.)\n\nScale parameter $\\lambda$ is nonnegative, $\\lambda >\n0$. (Alteratively, Weibull distributions are also sometimes\nrepresented with a scale parameter $b = \\frac{1}{\\lambda}$.)\n\nShape parameter $\\tau$ is nonnegative, $\\tau > 0$. \n\n\n\n\n\n\n", "meta": {"hexsha": "4b435a702ffa2bb5342ca81a1838627aab584581", "size": 1458, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hmmer-3.3/easel/esl_weibull.tex", "max_stars_repo_name": "WooMichael/Project_Mendel", "max_stars_repo_head_hexsha": "ff572f7ce7f9beca148f7351cf34dbf11d670bc8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hmmer-3.3/easel/esl_weibull.tex", "max_issues_repo_name": "WooMichael/Project_Mendel", "max_issues_repo_head_hexsha": "ff572f7ce7f9beca148f7351cf34dbf11d670bc8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hmmer-3.3/easel/esl_weibull.tex", "max_forks_repo_name": "WooMichael/Project_Mendel", "max_forks_repo_head_hexsha": "ff572f7ce7f9beca148f7351cf34dbf11d670bc8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.375, "max_line_length": 79, "alphanum_fraction": 0.7085048011, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067195846918, "lm_q2_score": 0.8976952873175982, "lm_q1q2_score": 0.8460838404363469}}
{"text": "\\section{Derivatives of VVFs}\r\n\\noindent\r\nJust like functions from Calc I and II, we can differentiate VVFs.\r\nIn fact, the limit definitions of the derivative are nearly identical.\r\nLet $\\vec{r}(t) = \\langle x(t), y(t), z(t) \\rangle$.\r\n\\begin{align*}\r\n\t\\vec{r^\\prime}(t) &= \\lim_{h\\to 0}{\\frac{\\vec{r}(t+h)-\\vec{r}(t)}{h}} \\\\\r\n\t&= \\lim_{h\\to 0}{\\bigg\\langle \\frac{x(t+h)-x(t)}{h}, \\frac{y(t+h)-y(t)}{h}, \\frac{z(t+h)-z(t)}{h} \\bigg\\rangle}.\r\n\\end{align*}\r\nThe limit distributes inside the vector, so\r\n\\begin{equation*}\r\n\t\\vec{r^\\prime}(t) = \\langle x^{\\prime}(t), y^{\\prime}(t), z^{\\prime}(t) \\rangle.\r\n\\end{equation*}\r\n\r\n\\noindent\r\nLike a position function from Calc I and II, the derivative of a VVF representing position gives a VVF representing velocity, and the 2nd derivative gives a VVF representing acceleration.\r\nThe magnitude of the velocity VVF, the speed, is commonly notated $v(t)$.\\\\\r\n\r\n\\noindent\r\nThere are 5 important properties of the derivatives of VVFs.\r\nThese properties are similar to single-variable derivatives.\r\nLet $\\vec{r}(t)$ and $\\vec{s}(t)$ be VVFs, $a(t)$ be a scalar function, and $c$ be a scalar.\r\n\\begin{enumerate}[label=]\r\n\t\\item \\textbf{Linearity}\r\n\t\\begin{equation*}\r\n\t\t\\frac{\\mathrm{d}}{\\mathrm{d}t}c\\vec{r}(t) = c\\vec{r^\\prime}(t)\r\n\t\\end{equation*}\r\n\t\\item \\textbf{Product Rule for Scalar Functions}\r\n\t\\begin{equation*}\r\n\t\t\\frac{\\mathrm{d}}{\\mathrm{d}t}a(t)\\vec{r}(t) = a(t)\\vec{r^\\prime}(t) + \\vec{r}(t)a^{\\prime}(t)\r\n\t\\end{equation*}\r\n\t\\item \\textbf{Dot Product Rul}e\r\n\t\\begin{equation*}\r\n\t\t\\frac{\\mathrm{d}}{\\mathrm{d}t}\\vec{s}(t)\\cdot\\vec{r}(t) = \\vec{s}(t)\\cdot\\vec{r^\\prime}(t) + \\vec{r}(t)\\vec{s^\\prime}(t)\r\n\t\\end{equation*}\r\n\t\\item \\textbf{Cross Product Rule}\r\n\t\\begin{equation*}\r\n\t\t\\frac{\\mathrm{d}}{\\mathrm{d}t}\\vec{s}(t)\\times\\vec{r}(t) = \\vec{s}(t)\\times\\vec{r^\\prime}(t) + \\vec{s^\\prime}(t)\\times\\vec{r}(t)\r\n\t\\end{equation*}\r\n\t\\item \\textbf{Chain Rule}\r\n\t\\begin{equation*}\r\n\t\t\\frac{\\mathrm{d}}{\\mathrm{d}t}\\vec{r}(a(t)) = \\vec{r^\\prime}(a(t))a^{\\prime}(t)\r\n\t\\end{equation*}\r\n\\end{enumerate}\r\nA quotient rule doesn't make sense because we don't have an operation for dividing two vectors by each other.\\\\\r\n\r\n\\noindent\r\nJust like in single variable calculus, we can use the derivative of VVFs to find tangent lines to the curve.\r\nSimilar to how $f^{\\prime}(a)$ represents the slope of $f$ at $a$, $\\vec{r^\\prime}(a)$ represents the direction of the tangent line at $a$.\r\nRemembering the VVF form of a line, the tangent line to $\\vec{r}$ at $t$ is \r\n\\begin{equation*}\r\n\t\\vec{l}(t)=\\vec{r}(t)+t\\vec{r^\\prime}(t).\r\n\\end{equation*}\r\nIn fact, tangent lines appear so often, that we have a special unit vector representing the direction of the tangent line.\r\n\\begin{equation*}\r\n\t\\hat{T}(t) = \\frac{\\vec{r^\\prime}(t)}{\\norm{\\vec{r^\\prime}(t)}}.\r\n\\end{equation*}\r\nYou can remember $\\hat{T}$ as the ``tangent'' vector.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.33]{Images/vectorValuedFunctions/TangentVector}\r\n\t\\caption{$\\hat{T}$ is $\\vec{r^\\prime}$ normalized.}\r\n\\end{figure}", "meta": {"hexsha": "6d27ff2a78565480246d19cf49eeb761af90057d", "size": 3035, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/DerivativesOfVVFs.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/vectorValuedFunctions/DerivativesOfVVFs.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/vectorValuedFunctions/DerivativesOfVVFs.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.421875, "max_line_length": 188, "alphanum_fraction": 0.6602965404, "num_tokens": 1072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191335436404, "lm_q2_score": 0.8856314828740729, "lm_q1q2_score": 0.8460607008582287}}
{"text": "\\lecture{Sept. 27}\n\n\\begin{defn}\n\\textbf{Interpretation} is a choice of a non-empty set u, and constant, functions and relations for each constant, function and relation symbol.\n\nAn \\textbf{Assignment} in u, $$\\alpha \\colon \\{\\text{variale symbols}\\}\\to u$$\n\nWe write $\\alpha (F) = 1$ when F is true in u under $\\alpha$.\n\nWe write $\\alpha (F) = 0$ when F is false in u under $\\alpha$.\n\nWe say F is true in u when $\\alpha (F) = 1$ for \\textbf{every} assignment $\\alpha \\in u$\n\\end{defn}\n\n\\begin{exmp}\nthe formula $x\\times y = y \\times x$ is true in $\\mathbb{Z}$ but not true in $n\\times n$ matrices.\n\\end{exmp}\n\n\\begin{defn}\nFor formulas F and G and a set of formulas S, we say that F is a \\textbf{tautology} and we write $\\vDash F$, when for every interpretation u and every assignment $\\alpha \\in u$, $\\alpha (F) = 1$\n\\end{defn}\n\n\\begin{defn}\nWe say that F and G are \\textbf{equivalent}, and we write $F\\equiv G$, when for every interpretation u, for every assignment $\\alpha \\in u$, $\\alpha (F) = \\alpha (G)$, we say that the argument ``F there fore G\" is valid, or that ``S induces G\", or that ``G is a consequences of S\", when for every interpretation u and for every assignment $\\alpha \\in u$, if $\\alpha (F) = 1$ for every $F\\in S$ then $\\alpha (G) = 1$\n\\end{defn}\n\n\\begin{defn}\nGiven a formula G and a set of formulas S, such that $S\\vDash G$, a \\textbf{derivation} for the valid argument $S\\vDash G$ is a list of valid arguments\n$$S_1\\vDash G_1,S_2\\vDash G_2,S_3\\vDash G_3,\\dots$$\nwhere for some index k we have $S_k=S$ and $G_k = G$, such that each valid argument in the list is obtained from previous valid arguments in the list by applying one of the basic validity rules.\n\\end{defn}\n\n\\section{Basic Validity Rules}\nEach basic validity rule is a formal and precise way of describing standard method of mathematical proof.\n\nRules V1, V2 and V3 are used in derivations because we make a careful distinction between \\textbf{premises} and \\textbf{conclusions}. In standard mathematical proofs we do not make a careful distinction.\n\n\\begin{enumerate}\n\\item[Premise V1.] If $F\\in S$ then $S\\vDash F$. In words, if we assume $F$, we can conclude $F$.\n\\item[V2.] If $S\\vDash F$ and $S\\subseteq \\mathcal{T}$ then $\\mathcal{T}\\vDash F$. In words, if we can prove $F$ without assuming $G$, then we can still prove $F$ if we assume $G$.\n\\item[Chain Rule V3.] If $S\\vDash F$ and $S\\cup \\{F\\}\\vDash G$ then $S\\vDash G$. In words, if we can prove $F$, and by assuming $F$ we can prove $G$, then we can prove $G$ directly without assuming $F$.\n\\item[Proof by Cases V4.] If $S\\cup \\{F\\}\\vDash G$ and $S\\cup \\{\\neg F\\}\\vDash G$ then $S\\vDash G$. In words, in either case $G$ is true.\n\\item[Contradiction V5.] If $S\\cup \\{\\neg F\\} \\vDash G$ and $S\\cup \\{\\neg F\\} \\vDash \\neg G$ then $S\\vDash F$. In words, to prove F by contradiction, we suppose, for a contradiction, that F is false, we choose a formula G, then we prove that G is true and we prove that G is false.\n\\item[V6.] If $S\\cup \\{ F\\} \\vDash G$ and $S\\cup \\{ F\\} \\vDash \\neg G$ then $S\\vDash \\neg F$\n\\item[V7.] If $S\\vDash F$ and $S\\vDash \\neg F$ then $S\\vDash G$\n\\item[Conjunction V8.] $S\\vDash F\\wedge G \\Longleftrightarrow (S\\vDash F \\text{ and } S\\vDash G)$\n\\item[V9.] If $S\\cup \\{F,G\\} \\vDash H$ then $S\\cup \\{F\\wedge G\\}\\vDash H$\n\\item[V10.] ...\n\\item[V11.] ...\n\\item[V12.] ...\n\\item[Disjunction V13.] $S\\vDash F\\vee G \\Longleftrightarrow S\\cup \\{\\neg F\\}\\vDash \\Longleftrightarrow S\\cup \\{\\neg G\\}\\vDash F$\n\\item[V14.] ...\n\\end{enumerate}\n\n\n", "meta": {"hexsha": "6d681be221df9409e11727fc7ef886730708a101", "size": 3500, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MATH 145/lecture/11.tex", "max_stars_repo_name": "Zhongweizhao/uw-notes", "max_stars_repo_head_hexsha": "bfb0f7b5f3607e9827f86092af5c5b9e2b875239", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-14T16:46:12.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-14T16:46:12.000Z", "max_issues_repo_path": "MATH 145/lecture/11.tex", "max_issues_repo_name": "Zhongweizhao/uw-notes", "max_issues_repo_head_hexsha": "bfb0f7b5f3607e9827f86092af5c5b9e2b875239", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATH 145/lecture/11.tex", "max_forks_repo_name": "Zhongweizhao/uw-notes", "max_forks_repo_head_hexsha": "bfb0f7b5f3607e9827f86092af5c5b9e2b875239", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.5, "max_line_length": 415, "alphanum_fraction": 0.6854285714, "num_tokens": 1163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374443, "lm_q2_score": 0.9073122244934722, "lm_q1q2_score": 0.8460262876014935}}
{"text": "\t\\chapter{Vector Spaces}\n\t\n\tA vector space is the general mathemtical structure we need to be able to talk about linear mappings. To introduce a vector space we need a lot of mathematical concepts. So we start with a group. \n\t\n\t\\begin{definition}\n\t\tA set $G$ of elements with an operation $+$: $G \\times G \\rightarrow G$ is called a group if the following properties hold: \n\t\\end{definition}\n\t\n\t\\begin{itemize}\n\t\t\\item[G1] Associativity: $ \\forall a, b, c \\in G$ : $(a + b) + c = a + (b + c) $\n\t\t\\item[G2] Identity element: $\\exists e \\in G: \\forall g \\in G: e + g = g + e = g $\n\t\t\\item[G3] Inverse element: $ \\forall a \\in G$, $ \\exists b \\in G : a + b = b + a = e$\n\t\\end{itemize}\n\t\n\tA group is called a commutative group (Abelian group) if we have additionally that $ \\forall a, b \\in G: a + b = b + a$ \\\\\n\t\n\t\\textbf{Examples}\n\t\n\t\\begin{itemize}\n\t\t\\item $(\\Re^n, +)$: This can be thought of as an $n$-dimensional vector with addition as the associated operation. The addition of three vectors can be done in any order and is thus associative. The identity element in this case is the zero vector. The inverse element is the negative of each element. Thus this combination forms a group. \n\t\t\n\t\t\\item $(\\Re^+, .)$: This is the set of positive real numbers with multiplication as the associated operation. This also forms a group. \n\t\t\n\t\t\\item $(\\Re^-, .)$: This is set of negative real numbers with associated operation as multiplication. It does not form a group, since multiplication of two negative real numbers gives us a positive real number and that is out of the set considered. We can also say that the set of negative real numbers is not closed with respect to multiplication. \n\t\t\n\t\\end{itemize}\n\n\t\\begin{definition}\n\t\tA set $F$ with two operation $ (+ , \\cdot) : F \\times F \\rightarrow F$ is called a field if the following properties hold: \n\t\\end{definition}\n\t\n\t\\begin{itemize}\n\t\t\\item[F1] $ (F, +) $ is a commutative group with identity element 0.\n\t\t\\item[F2] $(F \\setminus\\{0\\}, \\cdot)$ is a commutative group with identity element 1. \n\t\t\\item[F3] Distributivity:  $\\forall a, b, c \\in F: a \\cdot (b + c) = a \\cdot b + a \\cdot c$\n\t\\end{itemize}\n\n\tThe two most common fields are the ral numbers $(\\Re, +, \\cdot)$ and complex numbers $(\\mathbb{C}, +, \\cdot)$ with defined addition and multiplication.\n\t\n\t\\begin{definition}\n\t\tLet $F$ be a field with identity elements 0 and 1. A vector space over the field $F$ is a set $V$ with a mapping: $ (+) : V \\times V \\rightarrow V$ (vector addition)  and a mapping $(\\cdot) : F \\times V \\rightarrow V$ (scalar multiplication) such that: \n\t\\end{definition}\n\n\t\\begin{itemize}\n\t\t\\item[V1] $(V, +)$ is a commutative group.\n\t\t\\item[V2] Multiplicative identity: $\\forall v \\in V: 1 \\cdot v = v$\n\t\t\\item[V3] Distributive property: $\\forall a, b  \\in F$ and $ \\forall u, v \\in V$\n\t\t\t\\subitem $a \\cdot (u + v) = a \\cdot u + a \\cdot v$\n\t\t\t\\subitem $(a + b)u = a \\cdot u + b \\cdot u $ \t\n\t\\end{itemize}\n\n\tElements of $V$ are called vectors and elements of $F$ are called scalars. Depending on whether the field is real or complex we call the space as real vector space or complex vector space. \\\\\n\t\n\t\\textbf{Examples}\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $\\Re^n$ with standard operations of adding vectors and multiplying vectors with a scalar. \n\t\t\\item Function spaces: These are spaces which consists of functions. And essentially the whole field of functional analysis exploits the fact if you group them in a vector space, there are many properties that you can find about functions without even explicitly looking at what type of functions you are talking about. \n\t\t\\subitem $\\Re^\\chi$ : $\\{f: \\chi \\rightarrow \\Re\\}$ the space of all real valued functions on a set $\\chi$. No we define the two operations: \n\t\t\\subitem $ + : \\Re^\\chi \\times \\Re^\\chi \\rightarrow \\Re^\\chi$ , $(f + g)(x) := f(x) + g(x)$\n\t\t\\subitem $\\cdot : \\Re \\times \\Re^\\chi \\rightarrow \\Re^\\chi, (\\lambda \\cdot f)(x) := \\lambda \\cdot (f(x))$ \\\\\n\t\tThen $(\\Re^\\chi, +, \\cdot)$ is a vector space.\n\t\\end{itemize}", "meta": {"hexsha": "1bab9f875febbec15859019d018a058f3ecfd3b4", "size": 4013, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter-1-vector-spaces.tex", "max_stars_repo_name": "agupta54/maths-for-ml", "max_stars_repo_head_hexsha": "c5e54f14e4a24a389d31a613c34c7ef40e2bc0d1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter-1-vector-spaces.tex", "max_issues_repo_name": "agupta54/maths-for-ml", "max_issues_repo_head_hexsha": "c5e54f14e4a24a389d31a613c34c7ef40e2bc0d1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter-1-vector-spaces.tex", "max_forks_repo_name": "agupta54/maths-for-ml", "max_forks_repo_head_hexsha": "c5e54f14e4a24a389d31a613c34c7ef40e2bc0d1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.703125, "max_line_length": 351, "alphanum_fraction": 0.6837777224, "num_tokens": 1198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075722839015, "lm_q2_score": 0.8791467643431002, "lm_q1q2_score": 0.8458337591233874}}
{"text": "\n By \\textbf{Taylors Formula}, we have for $t,t_0 \\in I$:\n \n \\begin{equation}\n \\label{eq:taylor:n}\n  \\Vector{r}(t)\n  =\n  \\Vector{r}(t_0)\n  +\n  \\Vector{r}'(t_0)(t-t_0)\n  +\n  \\ldots+\n  \\frac{1}{n!} \\Vector{r}^{(n)}(t_0)(t-t_0)^n\n  +\n  \\Vector{\\epsilon}_n(t)\n \\end{equation}\n \n In fact, Taylors Formula ensures, that for $t>t_0$, $\\exists \\xi \\in [t_0,t]$, so that:\n \n \\[\n   |\\Vector{\\epsilon}_n(t)|\n   \\leq \n   \\frac{1}{(n+1)!}\n   |\\Vector{r}^{(n+1)}(\\xi)|(t-t_0)^{n+1}\n \\]\n \nHence, for the \\emph{Error Vector}, $\\Vector{\\epsilon}(t)$, we have:\n \n\\begin{equation}\n  \\lim_{t\\rightarrow t_0} \\frac{\\Vector{\\epsilon}_n(t)}{ (t-t_0)^n }\n \\label{eq:taylor:err:n}\n  =\n  \\Vector{0}\n\\end{equation}\n \n\\subsection{First Order Aproximation}\ninput{Introduction/First}\nDeriving:\n\n\\[\n v(t)=\\sqrt{ x'(t)^2+y'(t)^2},\n\\]\n\nwe observe:\n\n\\[\n  v'(t)\n  =\n  \\frac{x'(t)+y'(t)}{ \\sqrt{ x'(t)^2+y'(t)^2} }\n  =\n  \\frac{x'(t)+y'(t)}{ v }\n\\]\n\n\n\\subsection{Second Order Aproximation}\n\\input{Introduction/Second}\n \n\n ", "meta": {"hexsha": "0e37446cea83c5c7919fb12a1fa1ba0169539fb4", "size": 985, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Oids/Introduction/Taylor.tex", "max_stars_repo_name": "olesmith/SmtC", "max_stars_repo_head_hexsha": "dfae5097f02192b60aae05b9d02404fcfe893be3", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Oids/Introduction/Taylor.tex", "max_issues_repo_name": "olesmith/SmtC", "max_issues_repo_head_hexsha": "dfae5097f02192b60aae05b9d02404fcfe893be3", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Oids/Introduction/Taylor.tex", "max_forks_repo_name": "olesmith/SmtC", "max_forks_repo_head_hexsha": "dfae5097f02192b60aae05b9d02404fcfe893be3", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.6949152542, "max_line_length": 88, "alphanum_fraction": 0.5654822335, "num_tokens": 422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850442, "lm_q2_score": 0.9059898102301019, "lm_q1q2_score": 0.8456788083808133}}
{"text": "\n\\subsection{Transposition and conjugation}\n\n\\subsubsection{Transposition}\n\nA matrix of dimensions \\(m*n\\) can be transformed into a matrix \\(n*m\\) by transposition.\n\n\\(B=A^T\\)\n\n\\(b_{ij}=a{ji}\\)\n\n\\subsubsection{Transpose rules}\n\n\\((M^T)^T=M\\)\n\n\\((AB)^T=B^TA^T\\)\n\n\\((A+B)^T=A^T+B^T\\)\n\n\\((zM)^T=zM^T\\)\n\n\\subsubsection{Conjugation}\n\nWith conjugation we take the complex conjugate of each element.\n\n\\(B=\\overline A\\)\n\n\\(b_{ij}=\\overline a_{ij}\\)\n\n\\subsubsection{Conjugation rules}\n\n\\(\\overline {(\\overline A)}=A\\)\n\n\\(\\overline {(AB)}=(\\overline A)( \\overline B)\\)\n\n\\(\\overline {(A+B)}=\\overline A+\\overline B\\)\n\n\\(\\overline {(zM)}=\\overline z \\overline M\\)\n\n\\subsubsection{Conjugate transposition}\n\nLike transposition, but with conjucate.\n\n\\(B=A^*\\)\n\n\\(b_{ij}=\\bar{a_{ji}}\\)\n\nAlternatively, and particularly in physics, the following symbol is often used instead.\n\n\\((A^*)^T=A^\\dagger\\)\n\n", "meta": {"hexsha": "b9f12fb803696ce7bf8f432ca17eb3b27daa7f1d", "size": 884, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystems/04-06-keyResults.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/linearSystems/04-06-keyResults.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/linearSystemsOperations/04-04-keyResults.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.0, "max_line_length": 89, "alphanum_fraction": 0.6628959276, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065459, "lm_q2_score": 0.8947894731166139, "lm_q1q2_score": 0.8455713201858868}}
{"text": "\n\\subsection{Infinitum and supremum}\n\n\\subsubsection{Infinitum}\n\nConsider a subset \\(S\\) of a partially ordered set \\(T\\).\n\nThe infinitum of \\(S\\) is the greatest element in \\(T\\) that is less than or equal to all elements in \\(S\\).\n\nFor example:\n\n\\(\\inf [0,1]=0\\)\n\n\\(\\inf (0,1)=0\\)\n\n\\subsubsection{Supremum}\n\nThe supremum is the opposite: the smallest element in \\(T\\) which is greater than or equal to all elements in \\(S\\).\n\n\\(\\sup [0,1]=1\\)\n\n\\(\\sup (0,1)=1\\)\n\n\\subsubsection{Max and min}\n\nIf the infinitum of a set \\(S\\) is in \\(S\\), then the infinimum is the minimum of set \\(S\\). Otherwise, the minimum is not defined.\n\n\\(\\min [0,1]=0\\)\n\n\\(\\min (0,1)\\) isn't defined.\n\nSimilarly:\n\n\\(\\max [0,1]=1\\)\n\n\\(\\max (0,1)\\) isn't defined.\n\n", "meta": {"hexsha": "6954b04687782b5d56b1c72994bda7b0aae7df8a", "size": 736, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/orderingInfinite/01-03-infinitum.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/orderingInfinite/01-03-infinitum.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/orderingInfinite/01-03-infinitum.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.3684210526, "max_line_length": 131, "alphanum_fraction": 0.6426630435, "num_tokens": 242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813463747182, "lm_q2_score": 0.8840392893839085, "lm_q1q2_score": 0.845125070113378}}
{"text": "\\subsection{Complex Numbers}\r\n\\begin{definition}\r\n\t$i$ is called the imaginary unit. It's defined by $i^2 = -1$.\r\n\\end{definition}\r\n\r\n\r\n\\noindent\r\nThe set of complex numbers ($\\mathbb{C}$) is an extension of the real numbers. Complex numbers have the form $z = \\alpha + \\beta i$, where $\\alpha$ and $\\beta$ are real numbers. The $\\alpha$ part of $z$ is called the real part, so $\\Re(z) = \\alpha$. The $\\beta$ part of $z$ is called the imaginary part, so $\\Im(z) = \\beta i$.\\\\\r\n\r\n\\noindent\r\nOften, complex numbers are visualized as points or vectors in a 2D plane, called the complex plane, where $\\alpha$ is the x-component, and $\\beta$ is the y-component. Thinking of complex numbers like points helps us define the magnitude of complex numbers and compare them. Since a point $(x,y)$ has a distance $\\sqrt{x^2+y^2}$ from the origin, we can say the magnitude of $z$, $\\lvert z \\rvert$ is $\\sqrt{\\alpha^2 + \\beta^2}$. Thinking of complex numbers like vectors helps us understand adding two complex numbers, since you just add the components like vectors.\\\\\r\n\r\n\\noindent\r\nA common operation on complex numbers is the complex conjugate. The complex conjugate of $z = \\alpha + \\beta i$ is $\\overline{z} = \\alpha - \\beta i$. $z$ and $\\overline{z}$ are called a conjugate pair.\\\\\r\n\r\n\\noindent\r\nConjugate pairs have the following properties.\r\nLet $z, w \\in \\mathbb{C}$.\r\n\\begin{align*}\r\n\t\\overline{z \\pm w} &= \\overline{z} \\pm \\overline{w} \\\\\r\n\t\\overline{zw} &= \\overline{z}\\overline{w} \\\\\r\n\t\\overline{z} &= z \\Leftrightarrow z \\in \\mathbb{R} \\\\\r\n\tz\\overline{z} &= \\lvert z \\rvert^2 = \\lvert \\overline{z} \\rvert^2 \\\\\r\n\t\\overline{\\overline{z}} &= z \\\\\r\n\t\\overline{z}^n &= \\overline{z^n} \\\\\r\n\tz^{-1} &= \\frac{\\overline{z}}{\\lvert z \\rvert^2} \r\n\\end{align*}\r\n", "meta": {"hexsha": "863e6eef3e8b77987cff834116e2c9a4179d08b6", "size": 1750, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/algebraPreCalc/complexNumbers.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/algebraPreCalc/complexNumbers.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/algebraPreCalc/complexNumbers.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 62.5, "max_line_length": 567, "alphanum_fraction": 0.676, "num_tokens": 551, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813476288299, "lm_q2_score": 0.8840392863287585, "lm_q1q2_score": 0.8451250683013956}}
{"text": "We have already seen that given any logical expression $L$ with $n$ variables we can form a truth table with precisely $2^n$ rows documenting the output of $L$ when it is evaluated at each possible input. Now we want to answer the reverse question: if we have a table $Y$ of the format of a truth table with $2^n$ rows documenting some possible output with each input of $n$ variables, then is there a logical expression involving all $n$ variables and some of the binary logical operators introduced earlier for which its truth table is exactly the table $Y$? It turns out that this answer is yes, and in this section we will see why.\n\n\\subsection{The $\\land$ as an indicator function}\n\nSuppose that $x_1, \\dots, x_n$ are our boolean variables under consideration. Then the logical expression \n\\[L \\equiv x_1 \\land x_2 \\land \\cdots \\land x_n\\] evaluates to $T$ only if every variable $x_k$ is set to $T$. So $L$ can be seen as an indicator function which is true on only one possible input of logical variables. But what if I wanted an expression which evaluates to $T$ only if every variable except $x_1$ is set to $T$? This is not too much of a problem either, since the expression\n\\[K \\equiv (\\shortsim x_1) \\land x_2 \\land\\cdots \\land x_n\\] evaluates to $T$ in this case and $F$ otherwise. With these two examples it is clear how to make an ``indicator function'' which evaluates to true given one assignment of random variables and false otherwise. Simply take the expression\n%I need to think up better notation than this here..\n\\[\\bigwedge\\limits_{x_k \\rightarrow F}(\\shortsim x_k) \\land \\bigwedge\\limits_{x_j \\rightarrow T}x_j\\]\nwhere the big $\\land$ represents a logical and over all the variables in question where we want the variables to be $F$ or $T$. It is clear that this expression evaluates to $T$ only one one choice of variable assignment.\n\n\\subsection{The $\\lor$ as a join function}\n\nSo far we have demonstrated how to represent any truth table $Y$ with exactly one row of the table evaluating to $T$ as a logical expression. However, what about the rest? The remaining questions can be answered once we consider the act of conjoining equations using the $\\lor$ operator.\n\nFirst consider the logical expression $L$ in the previous subsection. For any other logical expression $M$, consider the logical expression $L \\lor M$. One thing we can say about $L \\lor M$ is that it evaluates to true when every variable $x_k$ is set to $T$. We don't know that much about its evaluation at any of the other variables though. If instead we considered the logical expression $L \\lor K$, where $K$ was defined in the previous section, then we see that $L \\lor K$ evaluates to $T$ at exactly two assignments, precisely those that made $L$ and $K$ evaluate to $T$.\n\nUsing these two concepts it is now clear how to represent any truth table $Y$ using a logical expression. First, consider for which assignments of variables $Y$ evaluates to $T$. For these assignments create indicator $\\land$ expressions $L_j$ which evaluate to true only when we have that specific variable assignment. Finally, take all such expressions $L_j$ and conjoin them with $\\lor$ expressions to create a final expression. \n\n\\begin{example}\nConsider the following truth table:\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{|l|l|l|}\n\\hline\n$p$ & $q$ & ??\\\\ \\hline\n$T$ & $T$ & $T$ \\\\ \\hline\n$T$ & $F$ & $F$ \\\\ \\hline\n$F$ & $T$ & $T$ \\\\ \\hline\n$F$ & $F$ & $F$ \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\nWe will create a logical expression whose truth table is the same as this truth table. Note that the this table only evaluates to true when $p \\equiv T, q \\equiv T$, and $p \\equiv F, q \\equiv T$. The associated indicator $\\land$ functions for these assignments are $p \\land q$ and $(\\shortsim p) \\land q$. Hence the final expression whose truth table is equal to the above truth table is\n\\[(p \\land q) \\lor ((\\shortsim p) \\land q).\\]\n\\end{example}\n\nOne can see that the process described above will always generate a logical expression whose truth table is equivalent to the given truth table. To see this, we observe that the expression we generate is several indicator expressions linked up with the $\\lor$ operator. If any one of these is true, then the whole expression is true. Conversely, if an assignment of variables goes to false in the original truth table then it does not match any of the indicator expressions, so the whole logical expression evaluates to false. The final expression that we obtain is said to be in \\textbf{disjunctive normal form}.\n\n\\subsection{Using $\\lor$ as an indicator function instead}\n\nNote that given $n$ boolean variables $x_1, \\dots, x_n$, the expression\n\\[x_1 \\lor \\cdots \\lor x_n\\] evaluates to $T$ for all variable assignments except for the assignment where every boolean variable is assigned $F$. Using similar ideas to the first subsection, we can create indicator logical expressions where every assignment evaluates to true except for one. To create a general expression we can take such indicator expressions and join them together with $\\land$ taking in mind that any logical expression $L$ will satisfy \n\\[L \\land F \\equiv F.\\]\nThe resulting expression obtained is said to be in \\textbf{conjunctive normal form}.", "meta": {"hexsha": "71a9062dd28aab3d54ce0ff8f68bc5e4e8649ec0", "size": 5238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch1/dnf_cnf.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch1/dnf_cnf.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch1/dnf_cnf.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 113.8695652174, "max_line_length": 635, "alphanum_fraction": 0.7569683085, "num_tokens": 1290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133557169236, "lm_q2_score": 0.8991213799730775, "lm_q1q2_score": 0.8450961934473264}}
{"text": "Suppose the discretization of a boundary value problem, such as the Poisson equation, leads to the matrix equation\n\\begin{align*}\nuA + Bu = f,\n\\end{align*}\nthat needs to be solved for $u$. Here $u$ is $n \\times m$, $A$ is $m \\times m$, $B$ is $n \\times n$, and $f$ is $n \\times m$.\n\n\\begin{questions}\n\n\\question{Assuming both $A$ and $B$ are non-defective matrices, with $A = V_A \\Lambda_AV_A^{-1}$ and $B = V_B \\Lambda_BV_B^{-1}$, show that the solution $u$ is given by $u = V_B UV_A^{-1}$, where\n\\begin{align*}\nU_{i,j} = \\frac{F_{i,j}}{\\alpha_j + \\beta_i},\n\\end{align*}\n$F = V_B^{-1}fV_A$, and $\\alpha_k$ and $\\beta_k$ are the diagonal entries of $\\Lambda_A$ and $\\Lambda_B$ respectively.\n }\n\n\\begin{solution}\n\nWe begin with,\n\\begin{align*}\n& uA + Bu = f \\\\\n\\Rightarrow ~& uV_A \\Lambda_AV_A^{-1} + V_B \\Lambda_BV_B^{-1} u = f~.\n\\end{align*}\nWe then multiple the entire equation by $V_B^{-1}$ from the left and $V_A$ from the right to obtain,\n\\begin{align*}\nV_B^{-1}uV_A\\Lambda_A + \\Lambda_B V_B^{-1} u V_A = V_B^{-1} f V_A~.\n\\end{align*}\nThen let $U = V_B^{-1}uV_A$ and $F = V_B^{-1} f V_A$ so that,\n\\begin{align*}\nU\\Lambda_A + \\Lambda_B U = F~.\n\\end{align*}\nWhich in matrix form,\n\\begin{align*}\n&\\begin{bmatrix}\n\\tilde{u}_{11}& \\cdots & \\tilde{u}_{1m} \\\\\n\\tilde{u}_{21}& \\cdots & \\tilde{u}_{2m} \\\\\n\\vdots& ~ & \\vdots \\\\\n\\tilde{u}_{n1}& \\cdots & \\tilde{u}_{nm}\n\\end{bmatrix} \\begin{bmatrix}\n\\alpha_1 & 0 & \\cdots & 0 \\\\\n0 & \\alpha_2 & ~ & \\vdots \\\\\n\\vdots & ~& \\ddots & ~ \\\\\n0 & \\cdots & 0 & \\alpha_m\n\\end{bmatrix} + \\begin{bmatrix}\n\\beta_1 & 0 & \\cdots & 0 \\\\\n0 & \\beta_2 & ~ & \\vdots \\\\\n\\vdots & ~& \\ddots & ~ \\\\\n0 & \\cdots & 0 & \\beta_m\n\\end{bmatrix}\\begin{bmatrix}\n\\tilde{u}_{11}& \\cdots & \\tilde{u}_{1m} \\\\\n\\tilde{u}_{21} & \\cdots & \\tilde{u}_{2m} \\\\\n\\vdots& ~ & \\vdots \\\\\n\\tilde{u}_{n1} & \\cdots & \\tilde{u}_{nm}\n\\end{bmatrix} = \\begin{bmatrix}\n\\tilde{f}_{11} & \\cdots & \\tilde{f}_{1m} \\\\\n\\tilde{f}_{21} & \\cdots & \\tilde{f}_{2m} \\\\\n\\vdots & ~ & \\vdots \\\\\n\\tilde{f}_{n1} & \\cdots & \\tilde{f}_{nm}\n\\end{bmatrix}~,\n\\end{align*}\nshows us,\n\\begin{align*}\n \\begin{cases} \\tilde{u}_{11}\\alpha_1 + \\beta_1 \\tilde{u}_{11} = \\tilde{f}_{11} \\\\ \\tilde{u}_{12}\\alpha_2 + \\beta_1 \\tilde{u}_{12} = \\tilde{f}_{12} \\\\ \\vdots \\end{cases} \\Rightarrow ~U_{i,j} = \\frac{F_{i,j}}{\\alpha_j + \\beta_i}~.\n\\end{align*}\nThen, to get back our solution, we use $u = V_B U V_A^{-1}$.\n\n\\end{solution}\n\n\\question{Using part (a), solve the Poisson equation $\\Delta u = \\sin(x)\\cos(100y)$ on $[0,1] \\times [0,1]$ (with zero Dirichlet boundary conditions) using 100 points in the $x$ direction and 300 in the $y$ direction. Estimate the accuracy of your solution.\n}\n\n\\begin{solution}\n\nFollowing the exact scheme above, we obtain a solution for $u$ depicted in the figure below,\n\n\\begin{figure}[H]\n\\center{\\includegraphics[scale=.5]{P2F2.eps}}\n\\caption{Surface of $u$}\n\\end{figure}\n\nThe error, found by comparing $uD2A + D2Bu$ and $f$, where $D2A$ and $D2B$ are the centered finite difference matrices for $x$ and $y$ respectively, is $2.2451e-12$. \n\n\\end{solution}\n\n\\end{questions}\n\n\\subsubsection*{MATLAB}\n\n    \\begin{verbatim}\n% % Laplacian with zero BCs\nm = 100;\nhA = 1/(m-1);\nD2A = (gallery('tridiag',m,1,-2,1))/(hA^2);\n[eVA,evalA] = eig(full(D2A)); lamA = diag(evalA);\nn = 300;\nhB = 1/(n-1);\nD2B = (gallery('tridiag',n,1,-2,1))/(hB^2);\n[eVB,evalB] = eig(full(D2B)); lamB = diag(evalB);\n\ny = linspace(0,1,300);\nx = linspace(0,1,100);\n[xx,yy] = meshgrid(x,y);\nf = sin(xx).*cos(100.*yy);\n\nF = eVB'*f*eVA;\n\nU = zeros(size(f));\n\nfor j = 1:m\n    U(:,j) = F(:,j)./(lamB + lamA(j));\nend\n\nu = eVB*U*eVA';\n\nsol = u*D2A' + D2B*u;\n\nerr = norm(sol - f,inf);\n\nfigure\nplot(xx,sol(1,:),'r*',xx,f(1,:),'bo'); hold on\nplot(xx,sol(2,:),'g*',xx,f(2,:),'mo')\nplot(xx,sol(end,:),'k*',xx,f(end,:),'yo')\ngrid on\n\nfigure\nsurf(xx,yy,u,'EdgeColor','none')\n\\end{verbatim}\n", "meta": {"hexsha": "fc7c99f2ed0f271e0d6dc8ccc1dad419e482eb48", "size": 3823, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/texfiles/problem2.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/texfiles/problem2.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/texfiles/problem2.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.1023622047, "max_line_length": 257, "alphanum_fraction": 0.6149620717, "num_tokens": 1539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.8991213718636754, "lm_q1q2_score": 0.845096183555193}}
{"text": "\n\n\\section{Computer exercises for the lab}\n\nThis week is a good time for\n\\begin{itemize}\n\\item[(a)] making sure you are comfortable with the mathematics behind matrices as well as:\n\\item[(b)] making sure you are comfortable with the matrix operators in R.   \n\\item[(c)]  Check that you are very very sure you can subscript R matrices, i.e. use things such as \\text{[,1]} to select column 1, \\text{[,-1]} to select everything \\emph{except} column 1, and \\text{[,2:3]} to select columns 2 and 3.\n\\end{itemize}\n\nAlthough we will use in built multivariate analysis functions in R, you should consider checking you understand the techniques by using R as a matrix calculator.\n  \n\\begin{enumerate}\n\n\\item Find (where possible) the determinants and the inverse of the following matrices:\n\n$C_{1} = \\left[ \\begin {array}{cc} 4& 4\\\\\\noalign{\\medskip} 4& 4\\end {array} \\right]$, $C_{2} = \\left[ \\begin {array}{cc} 4& 4.001\\\\\\noalign{\\medskip} 4.001& 4.002\\end {array} \\right]$ and $C_{3} = \\left[ \\begin {array}{cc} 4& 4.001\\\\\\noalign{\\medskip} 4.001& 4.002001\\end {array} \\right] $\n\nVery briefly comment on the magnitude of the difference between $C_{2}^{-1}$ and  $C_{3}^{-1}$ given the only difference between $C_{2}$ and $C_{2}$ amounts to a difference of $0.000001$ in the bottom right position.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> A <- matrix(c(4, 4, 4, 4), 2, 2)\n> A\n> det(A)\n> try(solve(A))\n> B <- matrix(c(4, 4.001, 4.001, 4.002), 2, 2)\n> B\n> det(B)\n> solve(B)\n> C <- matrix(c(4, 4.001, 4.001, 4.002001), 2, 2)\n> C\n> det(C)\n> solve(C)\n\\end{Sinput}\n\\end{Schunk}\n\n\n\\begin{itemize}\n  \\item What's going on here?\n\\end{itemize}\n\n\\textit{Note that A is singular, the determinant is zero and it can't be inverted.   Also note that the inverses of B and C are very very different - but this is something of a pathological example}\n\n\n\\item Matrix partitioning.   Consider Sterling's financial data held in the R object LifeCycleSavings (see \\verb+?LifeCycleSavings+).   To make life a little easier, reorder the columns using \\texttt{X <- LifeCycleSavings[,c(2,3,1,4,5)]}.\n  \n\n\\begin{itemize}\n\\item Find the correlation matrix of \\texttt{X} (longhand, using the centering matrix), call this matrix \\texttt{R}\n\n\n\\begin{Schunk}\n\\begin{Sinput}\n> data(LifeCycleSavings)\n> X <- LifeCycleSavings[, c(2, 3, 1, 4, 5)]\n> R <- cor(X)\n> R\n\\end{Sinput}\n\\end{Schunk}\n\n\n\\item Partition \\textit{R = cov(X)} following the scheme below such that $\\boldsymbol{R_{11}}$ is a $2 \\times 2$ matrix containing the covariance of \\texttt{pop15} and \\texttt{pop75}, and $\\boldsymbol{R_{22}}$ contains the covariance of \\texttt{sr}, \\texttt{dpi} and \\texttt{ddpi}\n\n\\begin{displaymath}\n\\boldsymbol{R} = \\left( \\begin{array}{l|l} \\boldsymbol{R_{11}} & \\boldsymbol{R_{12}} \\\\ \\hline    \\boldsymbol{R_{21}} & \\boldsymbol{R_{22}} \\end{array} \\right) \n\\end{displaymath}\n\nYou should find for example that  $\\boldsymbol{R_{11}}$ is given by:\n % latex table generated in R 2.3.1 by xtable 1.3-2 package\n% Wed Nov 15 22:15:30 2006\n\\begin{table}[ht]\n\\begin{center}\n\\begin{tabular}{rrr}\n\\hline\n & pop15 & pop75 \\\\\n\\hline\npop15 & 83.75 & $-$10.73 \\\\\npop75 & $-$10.73 & 1.67 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n\n\\begin{Schunk}\n\\begin{Sinput}\n> R11 <- R[1:2, 1:2]\n> R12 <- R[1:2, 3:5]\n> R21 <- R[3:5, 1:2]\n> R22 <- R[3:5, 3:5]\n> R11\n> R22\n> R21\n> R12\n> t(R21)\n\\end{Sinput}\n\\end{Schunk}\n\n\n\\item Find the matrix $\\boldsymbol{A}$, where:\n\n\\begin{displaymath}\n\\boldsymbol{A} = \\boldsymbol{R_{22}^{-1}R_{21}R_{11}^{-1}R_{12}}\n\\end{displaymath}\n\n\n\n\\begin{Schunk}\n\\begin{Sinput}\n> A <- solve(R22) %*% R21 %*% solve(R11) %*% R12\n\\end{Sinput}\n\\end{Schunk}\n\n\n%\\begin{itemize}\n\n\\item Are $\\boldsymbol{A}$ and $\\boldsymbol{B}$ symmetric?   What is the difference between symmetric and asymmetric matrices in terms of their eigenvalues and eigenvectors?\\\\\n\\textit{Note that they are both asymmetric matrices, it just so happens for these particular matrices that the eigenvalues are positive and the eigenvectors are real.   This isn't always the case for asymmetric matrices!}\n\n\\item Find the eigenvalues and eigenvectors of $\\boldsymbol{A}$ and $\\boldsymbol{B}$ then find the square roots of the eigenvalues.   \n\n\n\\begin{Schunk}\n\\begin{Sinput}\n> eigen(B)\n> sqrt(eigen(A)$values)\n> sqrt(eigen(B)$values)\n\\end{Sinput}\n\\end{Schunk}\n\n\n\\item Do you notice any similarities between the first two eigenvalues from either matrix?\\\\\n\\textit{Note that the square roots of the eigen values are identical.}\n\\end{itemize}\n\n\\item Revisit the \\texttt{wines} data in the \\texttt{Flury} package.   Consider only Y1, Y5, Y6, Y8 and Y9, use matrix algebra to find the means, correlation and covariance of these data.   Compare the eigenvalues and eigenvectors, and the determinants and inverse you get from the covariance matrix and the correlation matrix.\\\\\n\n\n  \n  \n\\end{enumerate} \n\n\n\\section{Summary of week 2}\n\n\\fbox{\\parbox[c]{0.9\\textwidth}{\\color{blue}\n    \n\\begin{itemize}\n\\item We have revised, and are comfortable with matrix multiplication, matrix inverse, (normalised) eigenvalues and eigenvectors.  We can center and scale matrices.  We can do this by hand and in R.\n\\item We are also comfortable using R as a matrix calculator if and when we wish.\n\\end{itemize}\n}}\n", "meta": {"hexsha": "110e531b8ea41d5ba04413d3cb4f2fdf10aa4ddf", "size": 5207, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "newworksheet/week2matrix.tex", "max_stars_repo_name": "phewson/mvstats", "max_stars_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "newworksheet/week2matrix.tex", "max_issues_repo_name": "phewson/mvstats", "max_issues_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-08-28T16:37:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-28T16:49:11.000Z", "max_forks_repo_path": "newworksheet/week2matrix.tex", "max_forks_repo_name": "phewson/mvstats", "max_forks_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.8116883117, "max_line_length": 329, "alphanum_fraction": 0.7015555982, "num_tokens": 1715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632916317103, "lm_q2_score": 0.9111797045849583, "lm_q1q2_score": 0.8449946101119163}}
{"text": "\\lab{Introduction to Matplotlib}{Introduction to Matplotlib}\n\\label{lab:Matplotlib}\n\\objective{\nMatplotlib is the most commonly used data visualization library in Python. Being able to visualize data helps to determine patterns, to communicate results, and is a key component of applied and computational mathematics.\nIn this lab we introduce techniques for visualizing data in 1, 2, and 3 dimensions.\nThe plotting techniques presented here will be used in the remainder of the labs in the manual.\n}\n\n\\section*{Line Plots} % =======================================================\n\nRaw numerical data is rarely helpful unless it can be visualized.\nThe quickest way to visualize a simple 1-dimensional array is via a \\emph{line plot}.\nThe following code creates an array of outputs of the function $f(x) = x^2$, then visualizes the array using the \\li{matplotlib} module.\\footnote{Like NumPy, Matplotlib is \\emph{not} part of the Python standard library, but it is included in most Python distributions.}\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from matplotlib import pyplot as plt\n\n>>> y = np.arange(-5,6)**2\n>>> y\narray([25, 16,  9,  4,  1,  0,  1,  4,  9, 16, 25])\n\n# Visualize the plot.\n>>> plt.plot(y)                     # Draw the line plot.\n<<[<matplotlib.lines.Line2D object at 0x1084762d0>]>>\n>>> plt.show()                      # Reveal the resulting plot.\n\\end{lstlisting}\n\nThe result is shown in Figure \\ref{fig:basic1}.\nJust as \\li{np} is a standard alias for NumPy, \\li{plt} is a standard alias for \\li{matplotlib.pyplot} in the Python community.\n\nThe call \\li{plt.plot(y)} creates a figure and draws straight lines connecting the entries of \\li{y} relative to the $y$-axis.\nThe $x$-axis is (by default) the index of the array, which in this case is the integers from $0$ to $10$.\nCalling \\li{plt.show()} then displays the figure.\n\n\\begin{figure}[H] % plt.plot(y) compared to plt.plot(x,y).\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/basic1.pdf}\n    \\caption{\\li{plt.plot(y)} uses the indices of\\\\the array for the $x$-axis.}\n    \\label{fig:basic1}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/basic2.pdf}\n    \\caption{\\li{plt.plot(x,y)} specifies both the\\\\domain and the range.}\n    \\label{fig:basic2}\n\\end{subfigure}\n\\caption{Plots of $f(x) = x^2$ over the interval $[-5,5]$.}\n\\end{figure}\n\n\\begin{problem} % Law of Large Numbers / NumPy review.\nNumPy's \\li{random} module has tools for sampling from probability distributions.\nFor instance, \\li{np.random.normal()} draws samples from the normal (Gaussian) distribution.\nThe \\li{size} parameter specifies the shape of the resulting array.\n\\begin{lstlisting}\n>>> np.random.normal(size=(2,3))    # Get a 2x3 array of samples.\narray([[ 1.65896515, -0.43236783, -0.99390897],\n       [-0.35753688, -0.76738306,  1.29683025]])\n\\end{lstlisting}\n%\nWrite a function that accepts an integer $n$ as input.\n\\begin{enumerate}\n\\item Use \\li{np.random.normal()} to create an $n\\times n$ array of values randomly sampled from the standard normal distribution.\n\\item Compute the mean of each row of the array.\n\\\\(Hint: Use \\li{np.mean()} and specify the \\li{axis} keyword argument.)\n\\item Return the variance of these means.\n\\\\(Hint: Use \\li{np.var()} to calculate the variance).\n\\end{enumerate}\nDefine another function that creates an array of the results of the first function with inputs $n = 100,\\ 200,\\ \\ldots,\\ 1000$.\nPlot (and show) the resulting array.\n% This result illustrates one version of the \\emph{law of large numbers}.\n\\end{problem}\n\n\\subsection*{Specifying a Domain} % -----------------------------------------\n\nAn obvious problem with Figure \\ref{fig:basic1} is that the $x$-axis does not correspond correctly to the $y$-axis for the function $f(x) = x^2$ that is being drawn.\nTo correct this, define an array \\li{x} for the domain, then use it to calculate the image \\li{y = f(x)}.\nThe command \\li{plt.plot(x,y)} plots \\li{x} against \\li{y} by drawing a line between the consecutive points \\li{(x[i], y[i])}.\n% Note that the arrays must have the same number of elements to be compatible.\n\nAnother problem with Figure \\ref{fig:basic1} is its poor resolution: the curve is visibly bumpy, especially near the bottom of the curve.\nNumPy's \\li{linspace()} function makes it easy to get a higher-resolution domain.\nRecall that \\li{np.arange()} return an array of evenly-spaced values in a given interval, where\n\n% NOTE: the \\noindent is to fix a page break problem in PythonEssentials.pdf.\n\n\\noindent the \\textbf{spacing} between the entries is specified.\nIn contrast, \\li{np.linspace()} creates an array of evenly-spaced values in a given interval where the \\textbf{number of elements} is specified.\n\n\\begin{lstlisting}\n# Get 4 evenly-spaced values between 0 and 32 (including endpoints).\n>>> np.linspace(0, 32, 4)\narray([  0.        ,  10.66666667,  21.33333333,  32.        ])\n\n# Get 50 evenly-spaced values from -5 to 5 (including endpoints).\n>>> x = np.linspace(-5, 5, 50)\n>>> y = x**2                        # Calculate the range of f(x) = x**2.\n>>> plt.plot(x, y)\n>>> plt.show()\n\\end{lstlisting}\n\nThe resulting plot is shown in Figure \\ref{fig:basic2}.\nThis time, the $x$-axis correctly matches up with the $y$-axis.\nThe resolution is also much better because \\li{x} and \\li{y} have $50$ entries each instead of only $10$.\n\nSubsequent calls to \\li{plt.plot()} modify the same figure until \\li{plt.show()} is executed, which displays the current figure and resets the system.\nThis behavior can be altered by specifying separate figures or axes, which we will discuss shortly.\n\n\\begin{info} % Interactive Mode.\nPlotting can seem a little mystical because the actual plot doesn't appear until \\li{plt.show()} is executed.\nMatplotlib's \\emph{interactive mode} allows the user to see the plot be constructed one piece at a time.\nUse \\li{plt.ion()} to turn interactive mode on and \\li{plt.ioff()} to turn it off.\nThis is very useful for quick experimentation.\nTry executing the following commands in IPython:\n\n\\begin{lstlisting}\n<g<In [1]:>g> import numpy as np\n<g<In [2]:>g> from matplotlib import pyplot as plt\n\n# Turn interactive mode on and make some plots.\n<g<In [3]:>g> plt.ion()\n<g<In [4]:>g> x = np.linspace(1, 4, 100)\n<g<In [5]:>g> plt.plot(x, np.log(x))\n<g<In [6]:>g> plt.plot(x, np.exp(x))\n\n# Clear the figure, then turn interactive mode off.\n<g<In [7]:>g> plt.clf()\n<g<In [8]:>g> plt.ioff()\n\\end{lstlisting}\n\nUse interactive mode \\textbf{only} with IPython.\nUsing interactive mode in a non-interactive setting may freeze the window or cause other problems.\n\\end{info}\n\n\\begin{problem} % Plot two lines (sin() and cos()).\nWrite a function that plots the functions $\\sin(x)$, $\\cos(x)$, and $\\arctan(x)$ on the domain $[-2\\pi, 2\\pi]$ (use \\li{np.pi} for $\\pi$).\n% Call \\li{plt.xlim(-2*np.pi, 2*np.pi)} before \\li{plt.show()} to stretch the $x$-axis appropriately.\nMake sure the domain is refined enough to produce a figure with good resolution.\n\\end{problem}\n\n\\section*{Plot Customization} % ===============================================\n\n\\li{plt.plot()} receives several keyword arguments for customizing the drawing.\nFor example, the color and style of the line are specified by the following string arguments.\n%\n\\begin{table}[H] % Color and style.\n\\begin{tabular}{r|l}\n    Key & Color \\\\\n    \\hline\n    \\li{'b'} & blue\\\\\n    \\li{'g'} & green\\\\\n    \\li{'r'} & red\\\\\n    \\li{'c'} & cyan\\\\\n    % \\li{'m'} & magenta\\\\\n    % \\li{'y'} & yellow\\\\\n    \\li{'k'} & black\\\\\n    % \\li{'w'} & white\n\\end{tabular}\n\\qquad\n\\begin{tabular}{r|l}\n    Key & Style \\\\\n    \\hline\n    \\li{'-'} & solid line\\\\\n    \\li{'--'} & dashed line\\\\\n    \\li{'-.'} & dash-dot line\\\\\n    \\li{':'} & dotted line\\\\\n    % \\li{'.'} & point marker\\\\\n    \\li{'o'} & circle marker\\\\\n    % \\li{'*'} & star marker\\\\\n    % \\li{'+'} & plus marker\n\\end{tabular}\n\\end{table}\n%\nSpecify one or both of these string codes as the third argument to \\li{plt.plot()} to change from the default color and style.\nOther \\li{plt} functions further customize a figure.\n%\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|l}\n    Function & Description\\\\\n    \\hline\n    % \\li{grid()} & Add grid lines\\\\\n    \\li{legend()} & Place a legend in the plot\\\\\n    % \\li{text()} & Add text at a given position on the plot\\\\\n    \\li{title()} & Add a title to the plot\\\\\n    \\li{xlim()} / \\li{ylim()} & Set the limits of the $x$- or $y$-axis\\\\\n    % \\li{xticks()} & set the location of the tick marks on the x axis, returns current locations if no arguments are given\\\\\n    % \\li{yticks()} & set the location of the tick marks on the y axis, returns current locations if no arguments are given\\\\\n    \\li{xlabel()} / \\li{ylabel()} & Add a label to the $x$- or $y$-axis\\\\\n\\end{tabular}\n\\end{table}\n\n\\begin{lstlisting}\n>>> x1 = np.linspace(-2, 4, 100)\n>>> plt.plot(x1, np.exp(x1), 'g:', linewidth=6, label=\"Exponential\")\n>>> plt.title(\"This is the title.\", fontsize=18)\n>>> plt.legend(loc=\"upper left\")    # plt.legend() uses the 'label' argument of\n>>> plt.show()                      # plt.plot() to create a legend.\n\n>>> x2 = np.linspace(1, 4, 100)\n>>> plt.plot(x2, np.log(x2), 'r*', markersize=4)\n>>> plt.xlim(0, 5)                  # Set the visible limits of the x axis.\n>>> plt.xlabel(\"The x axis\")        # Give the x axis a label.\n>>> plt.show()\n\\end{lstlisting}\n%\n\\begin{figure}[H] % Figure customizations.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/custom1.pdf}\n    \\label{fig:custom1}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/custom2.pdf}\n    \\label{fig:custom2}\n\\end{subfigure}\n\\label{fig:custom}\n\\end{figure}\n%\n% See Appendix \\ref{mpltables} for more comprehensive lists of colors, line styles, and figure customization routines.\n%\n\\begin{problem} % Line plots with different domains but uniform style.\nWrite a function to plot the curve $f(x) = \\frac{1}{x-1}$ on the domain $[-2,6]$.\n\\begin{enumerate}\n\\item\nAlthough $f(x)$ has a discontinuity at $x=1$, a single call to \\li{plt.plot()} in the usual way will make the curve look continuous.\nSplit up the domain into $[-2,1)$ and $(1,6]$.\nPlot the two sides of the curve separately so that the graph looks discontinuous at $x=1$.\n\\item Plot both curves with a dashed magenta line.\nSet the keyword argument \\li{linewidth} (or \\li{lw}) of \\li{plt.plot()} to $4$ to make the line a little thicker than the default setting.\n\\item Use \\li{plt.xlim()} and \\li{plt.ylim()} to change the range of the $x$-axis to $[-2,6]$ and the range of the $y$-axis to $[-6, 6]$.\n\\end{enumerate}\nThe plot should resemble the figure below.\n\n\\begin{figure}[H] % Solution.\n\\includegraphics[width=.5\\textwidth]{figures/discontinuousProblem.pdf}\n\\end{figure}\n\\end{problem}\n\n\\subsection*{Figures, Axes, and Subplots} % -----------------------------------\n\nThe window that \\li{plt.show()} reveals is called a \\emph{figure}, stored in Python as a \\li{plt.Figure} object.\nA space on a figure where a plot is drawn is called an \\emph{axes}, a \\li{plt.Axes} object.\nA figure can have multiple axes, and a single program may create several figures.\nThere are several ways to create or grab figures and axes with \\li{plt} functions.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|l}\n    Function & Description\\\\\n    \\hline\n    \\li{axes()} & Add an axes to the current figure\\\\\n    \\li{figure()} & Create a new figure or grab an existing figure\\\\\n    \\li{gca()} & Get the current axes\\\\\n    \\li{gcf()} & Get the current figure\\\\\n    \\li{subplot()} & Add a single subplot to the current figure\\\\\n    \\li{subplots()} & Create a figure and add several subplots to it\\\\\n\\end{tabular}\n\\end{table}\n\nUsually when a figure has multiple axes, they are organized into non-overlapping \\emph{subplots}.\nThe command \\li{plt.subplot(nrows, ncols, plot_number)} creates an axes in a subplot grid where \\li{numrows} is the number of rows of subplots in the figure, \\li{numcols} is the number of columns, and \\li{plot_number} specifies which subplot to modify.\nIf the inputs for \\li{plt.subplot()} are all integers, the commas between the entries can be omitted.\nFor example, \\li{plt.subplot(3,2,2)} can be shortened to \\li{plt.subplot(322)}.\n\n\\begin{figure}[H] % The layout created by subplots(23i).\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{framed}\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/layout_1.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/layout_2.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/layout_3.pdf}\n\\end{subfigure}\n\\\\\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/layout_4.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/layout_5.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/layout_6.pdf}\n\\end{subfigure}\n\\end{framed}\n\\caption{The layout of subplots with \\li{plt.subplot(2,3,i)} (2 rows, 3 columns), where \\li{i} is the index pictured above. The outer border is the figure that the axes belong to.}\n\\label{fig:subplots-layout}\n\\end{figure}\n\n\\begin{lstlisting}\n>>> x = np.linspace(.1, 2, 200)\n# Create a subplot to cover the left half of the figure.\n>>> ax1 = plt.subplot(121)\n>>> ax1.plot(x, np.exp(x), 'k', lw=2)\n>>> ax1.plot(x, np.exp(2*x), 'b', lw=2)\n>>> plt.title(\"Exponential\", fontsize=18)\n\n# Create another subplot to cover the right half of the figure.\n>>> ax2 = plt.subplot(122)\n>>> ax2.plot(x, np.log(x), 'k', lw=2)\n>>> ax2.plot(x, np.log(2*x), 'b', lw=2)\n>>> ax2.set_title(\"Logarithmic\", fontsize=18)\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H] % The layout created by plt.subplot(23i).\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{framed}\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/subplots_1.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/subplots_2.pdf}\n\\end{subfigure}\n\\end{framed}\n\\end{figure}\n\n\\begin{info}\nPlotting functions such as \\li{plt.plot()} are shortcuts for accessing the current axes on the current figure and calling a method on that \\li{Axes} object.\nCalling \\li{plt.subplot()} changes the current axis, and calling \\li{plt.figure()} changes the current figure.\nUse \\li{plt.gca()} to get the current axes and \\li{plt.gcf()} to get the current figure.\nCompare the following equivalent strategies for producing a figure with two subplots.\n\n\\begin{lstlisting}\n>>> x = np.linspace(-5, 5, 100)\n\n# 1. Use plt.subplot() to switch the current.\n>>> plt.subplot(121)\n>>> plt.plot(x, 2*x)\n>>> plt.subplot(122)\n>>> plt.plot(x, x**2)\n\n# 2. Use plt.subplot() to explicitly grab the two subplot axes.\n>>> ax1 = plt.subplot(121)\n>>> ax1.plot(x, 2*x)\n>>> ax2 = plt.subplot(122)\n>>> ax2.plot(x, x**2)\n\n# 3. Use plt.subplots() to get the figure and all subplots simultaneously.\n>>> fig, axes = plt.subplots(1, 2)\n>>> axes[0].plot(x, 2*x)\n>>> axes[1].plot(x, x**2)\n\\end{lstlisting}\n\n% Having direct access to the axes and figures as Python objects provides a great deal of flexibility for plot customization.\n% If you ever need access to the current axes for detailed customization, use \\li{plt.gca()}.\n\\end{info}\n\n\\begin{problem} % Subplots of sine functions.\nWrite a function that plots the functions $\\sin(x)$, $\\sin(2x)$, $2\\sin(x)$, and $2\\sin(2x)$ on the domain $[0, 2\\pi]$, each in a separate subplot of a single figure.\n\\begin{enumerate}\n    \\item Arrange the plots in a $2\\times 2$ grid of subplots.\n    \\item Set the limits of each subplot to $[0, 2\\pi]\\times[-2,2]$.\n    \\\\(Hint: Consider using \\li{plt.axis([xmin, xmax, ymin, ymax])} instead of \\li{plt.xlim()} and \\li{plt.ylim()} to set all boundaries simultaneously.)\n    \\item Use \\li{plt.title()} or \\li{ax.set_title()} to give each subplot an appropriate title.\n    \\item Use \\li{plt.suptitle()} or \\li{fig.suptitle()} to give the overall figure a title.\n    \\item Use the following colors and line styles.\n    \\begin{align*}\\begin{array}{lcl}\n    \\sin(x)\\text{: green solid line.} && \\sin(2x)\\text{: red dashed line.}\\\\ \\\\\n    2\\sin(x)\\text{: blue dashed line.} && 2\\sin(2x)\\text{: magenta dotted line.}\n    \\end{array}\\end{align*}\n\\end{enumerate}\n\\end{problem}\n\n\\begin{warn}\nBe careful not to mix up the following functions.\n\\begin{enumerate}\n    \\item \\li{plt.axes()} creates a new place to draw on the figure, while \\li{plt.axis()} (or \\li{ax.axis()}) sets properties of the $x$- and $y$-axis in the current axes, such as the $x$ and $y$ limits.\n    \\item \\li{plt.subplot()} (singular) returns a single subplot belonging to the current figure, while \\li{plt.subplots()} (plural) creates a new figure and adds a collection of subplots to it.\n\\end{enumerate}\n% The \\li{subplots()} function is especially useful for figures with many subplots.\n% \\begin{lstlisting}\n% # The subplot axes are organized in an array of the given shape.\n% >>> fig, ax = plt.sublplots(2,3)\n% >>> ax.shape\n% (2, 3)\n% >>> ax[1,1].plot([1,2,3],[4,5,6])\n% # ...\n% \\end{lstlisting}\n\\end{warn}\n\n\\section*{Other Kinds of Plots} % =============================================\n\nLine plots are not always the most illuminating choice of graph to describe a set of data.\nMatplotlib provides several other easy ways to visualize data.\n\n\\begin{itemize}\n\\item A \\emph{scatter plot} plots two 1-dimensional arrays against each other without drawing lines between the points.\nScatter plots are particularly useful for data that is not correlated or ordered.\n\nTo create a scatter plot, use \\li{plt.plot()} and specify a point marker (such as \\li{'o'} or \\li{'*'}) for the line style, or use \\li{plt.scatter()} (or \\li{ax.scatter()}).\nBeware that \\li{plt.scatter()} has slightly different arguments and syntax than \\li{plt.plot()}.\n\n\\item A \\emph{histogram} groups entries of a 1-dimensional data set into a given number of intervals, called \\emph{bins}.\nEach bin has a bar whose height indicates the number of values that fall in the range of the bin.\n% The more bins, the greater the detail, but having too many bins can also destroy the picture by creating interval gaps between values.\nHistograms are best for displaying distributions, relating data values to frequency.\n\nTo create a histogram, use \\li{plt.hist()} (or \\li{ax.hist()}).\nUse the argument \\li{bins} to specify the edges of the bins, or to choose a number of bins.\nThe \\li{<<range>>} argument specifies the outer limits of the first and last bins.\n\\end{itemize}\n\n\\begin{lstlisting}\n# Get 500 random samples from two normal distributions.\n>>> x = np.random.normal(scale=1.5, size=500)\n>>> y = np.random.normal(scale=0.5, size=500)\n\n# Draw a scatter plot of x against y, using transparent circle markers.\n>>> ax1 = plt.subplot(121)\n>>> ax1.plot(x, y, 'o', markersize=5, alpha=.5)\n\n# Draw a histogram to display the distribution of the data in x.\n>>> ax2 = plt.subplot(122)\n>>> ax2.hist(x, bins=np.arange(-4.5, 5.5))      # Or, equivalently,\n#   ax2.hist(x, bins=9, range=[-4.5, 4.5])\n\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H]\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{framed}\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/scatterplot.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/histogram.pdf}\n\\end{subfigure}\n\\end{framed}\n\\end{figure}\n\n% On the histogram, specifying 9 bins in the range $[-4.5, 4.5]$ creates a bin centered over each integer from $-4$ to $4$.\n\n\\begin{problem} % FARS data visualization.\nThe Fatality Analysis Reporting System (FARS) is a nationwide census that provides yearly data regarding fatal injuries suffered in motor vehicle traffic crashes.%\n\\footnote{See \\url{http://www.nhtsa.gov/FARS}.}\nThe array contained in \\texttt{FARS.npy} is a small subset of the FARS database from 2010--2014.\nEach of the 148,206 rows in the array represents a different car crash; the columns represent the hour (in military time, as an integer), the longitude, and the latitude, in that order.\n\nWrite a function to visualize the data in \\texttt{FARS.npy}.\nUse \\li{np.load()} to load the data, then create a single figure with two subplots:\n%\n\\begin{enumerate}\n\\item A scatter plot of longitudes against latitudes.\nBecause of the large number of data points, use black pixel markers (use \\li{\"k,\"} as the third argument to \\li{plt.plot()}).\nLabel both axes using \\li{plt.xlabel()} and \\li{plt.ylabel()} (or \\li{ax.set_xlabel()} and \\li{ax.set_ylabel()}).\n\\\\\n(Hint: Use \\li{plt.axis(\"equal\")} or \\li{ax.set_aspect(\"equal\")} so that the $x$- and $y$-axis are scaled the same way.\n\n\\item A histogram of the hours of the day, with one bin per hour.\nSet the limits of the $x$-axis appropriately.\nLabel the $x$-axis.\nYou should be able to clearly see which hours of the day experience more traffic.\n\\end{enumerate}\n\\end{problem}\n\nMatplotlib also has tools for creating other kinds of plots for visualizing 1-dimensional data, including bar plots and box plots.\nSee the Matplotlib Appendix for examples and syntax.\n\n\\subsection*{Visualizing 3-D Surfaces} % --------------------------------------\n\nLine plots, histograms, and scatter plots are good for visualizing $1$- and $2$-dimensional data, including the domain and range of a function $f:\\mathbb{R}\\rightarrow\\mathbb{R}$.\nHowever, visualizing $3$-dimensional data or a function $g:\\mathbb{R}^2\\rightarrow\\mathbb{R}$ (two inputs, one output) requires a different kind of plot.\nThe process is similar to creating a line plot but requires slightly more setup: first construct an appropriate domain, then calculate the image of the function on that domain.\n\nNumPy's \\li{np.meshgrid()} function is the standard tool for creating a 2-dimensional domain in the Cartesian plane.\nGiven two 1-dimensional coordinate arrays, \\li{np.meshgrid()} creates two corresponding coordinate matrices.\nSee Figure \\ref{fig:meshgrid}.\n\n\\begin{figure}[H] % np.meshgrid() visual demonstration.\n\\begin{tikzpicture}[>=stealth', shorten <= .1cm,shorten >=.1cm, dot/.style=\n    {circle,fill=black,minimum size=3pt,inner sep=0pt, outer sep=-1pt} ]\n\n\\foreach \\x/\\y in {0/0, 0/2, 0/4, 2/0, 2/2, 2/4, 4/0, 4/2, 4/4}\n    \\node[draw, dot]at(\\x,\\y){};\n\\foreach \\x/\\y in {0/0, 0/1, 0/2, 1/0, 1/1, 1/2, 2/0, 2/1, 2/2}\n    \\node[draw=none]at(\\x*2-.5, \\y*2+.3){(\\x,\\y)};\n\n\\foreach \\x/\\y in {0/0, 0/1, 0/2, 1/0, 1/1, 1/2, 2/0, 2/1, 2/2}\n    \\node[draw=none]at(\\x*.75+7, \\y*.75+.1){\\y};\n\\foreach \\x/\\y in {0/0, 0/1, 0/2, 1/0, 1/1, 1/2, 2/0, 2/1, 2/2}\n    \\node[draw=none]at(\\x*.75+7, \\y*-.75+3.9){\\x};\n\n\\draw[-, thick](6.7,-.25)--(6.7,1.95);\n\\draw[-, thick](8.8,-.25)--(8.8,1.95);\n\\draw[-, thick](6.7,2.05)--(6.7,4.25);\n\\draw[-, thick](8.8,2.05)--(8.8,4.25);\n\\draw[-, thick](8.8,4.14)--(8.7,4.14);\n\\draw[-, thick](8.8,2.16)--(8.7,2.16);\n\\draw[-, thick](6.7,4.14)--(6.8,4.14);\n\\draw[-, thick](6.7,2.16)--(6.8,2.16);\n\\draw[-, thick](8.8,1.84)--(8.7,1.84);\n\\draw[-, thick](8.8,-.135)--(8.7,-.135);\n\\draw[-, thick](6.8,1.84)--(6.7,1.84);\n\\draw[-, thick](6.8,-.135)--(6.7,-.135);\n\n\\node[draw=none](X)at(6.3,.9){\\texttt{Y}=};\n\\node[draw=none](y)at(6.3,3.15){\\texttt{X}=};\n\n\\node[draw=none](point1)at(-.3, -.6){\\texttt{x}=\\big[0,};\n\\node[draw=none, node distance=2.35cm](point2)\n    [right of=point1]{1,};\n\\node[draw=none, node distance=2cm](point3)\n    [right of=point2]{2\\big]};\n\\node[draw=none, rotate=270](point4)at(4.6,4.25)\n    {\\texttt{y}=\\big[2,};\n\\node[draw=none, rotate=270, node distance=2.35cm](point5)\n    [right of=point4]{1,};\n\\node[draw=none, rotate=270, node distance=2cm](point6)\n    [right of=point5]{0\\big]};\n\\end{tikzpicture}\n\\caption{\\li{np.meshgrid(x, y)}, returns the arrays \\li{X} and \\li{Y}.\nThe returned arrays give the $x$- and $y$-coordinates of the points in the grid formed by \\li{x} and \\li{y}.\nSpecifically, the arrays \\li{X} and \\li{Y} satisfy \\li{(X[i,j], Y[i,j]) = (x[i],y[j])}.}\n\\label{fig:meshgrid}\n\\end{figure}\n\n\\begin{lstlisting}\n>>> x, y = [0, 1, 2], [3, 4, 5]     # A rough domain over [0,2]x[3,5].\n>>> X, Y = np.meshgrid(x, y)        # Combine the 1-D data into 2-D data.\n>>> for xrow, yrow in zip(X,Y):\n...     print(xrow, yrow, sep='\\t')\n...\n[0 1 2]    [3 3 3]\n[0 1 2]    [4 4 4]\n[0 1 2]    [5 5 5]\n\\end{lstlisting}\n\nWith a 2-dimensional domain, $g(x,y)$ is usually visualized with two kinds of plots.\n\n\\begin{itemize}\n\\item A \\emph{heat map} assigns a color to each point in the domain, producing a 2-dimensional colored picture describing a 3-dimensional shape.\nDarker colors typically correspond to lower values while lighter colors typically correspond to higher values.\n\nUse \\li{plt.pcolormesh()} to create a heat map.\n\n\\item A \\emph{contour map} draws several \\emph{level curves} of $g$ on the $2$-dimensional domain.\nA level curve corresponding to the constant $c$ is the collection of points $\\left\\{(x,y)\\mid c = g(x,y)\\right\\}$.\nColoring the space between the level curves produces a discretized version of a heat map.\nIncluding more and more level curves makes a filled contour plot look more and more like the complete, blended heat map.\n\nUse \\li{plt.contour()} to create a contour plot and \\li{plt.contourf()} to create a filled contour plot.\nSpecify either the number of level curves to draw, or a list of constants corresponding to specific level curves.\n\\end{itemize}\n\nThese functions each receive the keyword argument \\li{cmap} to specify a color scheme (some of the better schemes are \\li{\"viridis\"}, \\li{\"magma\"}, and \\li{\"coolwarm\"}).\nFor the list of all Matplotlib color schemes, see \\url{http://matplotlib.org/examples/color/colormaps_reference.html}.\n\nFinally, \\li{plt.colorbar()} draws the color scale beside the plot to indicate how the colors relate to the values of the function.\n\n\\begin{lstlisting}\n# Create a 2-D domain with np.meshgrid().\n>>> x = np.linspace(-np.pi, np.pi, 100)\n>>> y = x.copy()\n>>> X, Y = np.meshgrid(x, y)\n>>> Z = np.sin(X) * np.sin(Y)       # Calculate g(x,y) = sin(x)sin(y).\n\n# Plot the heat map of f over the 2-D domain.\n>>> plt.subplot(131)\n>>> plt.pcolormesh(X, Y, Z, cmap=\"viridis\")\n>>> plt.colorbar()\n>>> plt.xlim(-np.pi, np.pi)\n>>> plt.ylim(-np.pi, np.pi)\n\n# Plot a contour map of f with 10 level curves.\n>>> plt.subplot(132)\n>>> plt.contour(X, Y, Z, 10, cmap=\"coolwarm\")\n>>> plt.colorbar()\n\n# Plot a filled contour map, specifying the level curves.\n>>> plt.subplot(133)\n>>> plt.contourf(X, Y, Z, [-1, -.8, -.5, 0, .5, .8, 1], cmap=\"magma\")\n>>> plt.colorbar()\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H] % heat map and contour plots.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{framed}\n\\begin{subfigure}{.33\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/heatmap.png}\n\\end{subfigure}%\n\\begin{subfigure}{.33\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/contour.pdf}\n\\end{subfigure}%\n\\begin{subfigure}{.33\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/contourf.pdf}\n\\end{subfigure}\n\\end{framed}\n\\end{figure}\n\n\\begin{problem} % Heat map / contour plot of a function f:R2->R.\n\\label{prob:heatmap}\nWrite a function to plot $g(x,y) = \\frac{\\sin(x)\\sin(y)}{xy}$ on the domain $[-2\\pi,2\\pi] \\times [-2\\pi,2\\pi]$.\n\n\\begin{enumerate}\n\\item Create 2 subplots: one with a heat map of $g$, and one with a contour map of $g$.\nChoose an appropriate number of level curves, or specify the curves yourself.\n\\item Set the limits of each subplot to $[-2\\pi,2\\pi] \\times [-2\\pi,2\\pi]$.\n\\item Choose a non-default color scheme.\n\\item Include the color scale bar for each subplot.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{comment}\n\\begin{info} % Note about plt.imshow().\nBlack-and-white pictures are usually stored as a $2$-dimensional array and colord pictures are stored as a $3$-dimensional array (a stack of 2-dimensional arrays, one for each RGB value).\nThis kind of data does not require a domain, and is easily visualized with \\li{plt.imshow()}.\n\\end{info}\n\\end{comment}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Further Reading and Tutorials} % ---------------------------------\n\nPlotting takes some getting used to.\nSee the following materials for more examples.\n\\begin{itemize}\n    \\item \\url{https://www.labri.fr/perso/nrougier/teaching/matplotlib/}.\n    \\item \\url{https://matplotlib.org/users/pyplot_tutorial.html}.\n    \\item \\url{http://www.scipy-lectures.org/intro/matplotlib/matplotlib.html}.\n    \\item The Matplotlib Appendix in this manual.\n\\end{itemize}\n\n\\subsection*{3-D Plotting} % --------------------------------------------------\n\nMatplotlib can also be used to plot 3-dimensional surfaces.\nThe following code produces the surface corresponding to $g(x,y) = \\sin(x)\\sin(y)$.\n\n\\begin{lstlisting}\n# Create the domain and calculate the range like usual.\n>>> x = np.linspace(-np.pi, np.pi, 200)\n>>> y = np.copy(x)\n>>> X, Y = np.meshgrid(x, y)\n>>> Z = np.sin(X) * np.sin(Y)\n\n# Draw the corresponding 3-D plot using some extra tools.\n>>> from mpl_toolkits.mplot3d import Axes3D\n>>> fig = plt.figure()\n>>> ax = fig.add_subplot(1,1,1, projection='3d')\n>>> ax.plot_surface(X, Y, Z)\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H]\n    \\includegraphics[width=.7\\textwidth]{figures/surface_plot.pdf}\n\\end{figure}\n\n\\subsection*{Animations} % ----------------------------------------------------\n\nLines and other graphs can be altered dynamically to produce animations.\nFollow these steps to create a Matplotlib animation:\n%\n\\begin{enumerate}\n    \\item Calculate all data that is needed for the animation.\n    \\item Define a figure explicitly with \\li{plt.figure()} and set its window boundaries.\n    \\item Draw empty objects that can be altered dynamically.\n    \\item Define a function to update the drawing objects.\n    \\item Use \\li{matplotlib.animation.FuncAnimation()}.\n\\end{enumerate}\n\nThe submodule \\li{matplotlib.animation} contains the tools for putting together and managing animations.\nThe function \\li{matplotlib.animation.FuncAnimation()} accepts the figure to animate, the function that updates the figure, the number of frames to show before repeating, and how fast to run the animation (lower numbers mean faster animations).\n\n\\begin{lstlisting}\nfrom matplotlib.animation import FuncAnimation\n\ndef sine_animation():\n    # Calculate the data to be animated.\n    x = np.linspace(0, 2*np.pi, 200)[:-1]\n    y = np.sin(x)\n\n    # Create a figure and set the window boundaries of the axes.\n    fig = plt.figure()\n    plt.xlim(0, 2*np.pi)\n    plt.ylim(-1.2, 1.2)\n\n    # Draw an empty line. The comma after 'drawing' is crucial.\n    drawing, = plt.plot([],[])\n\n    # Define a function that updates the line data.\n    def update(index):\n        drawing.set_data(x[:index], y[:index])\n        return drawing,                     # Note the comma!\n\n    a = FuncAnimation(fig, update, frames=len(x), interval=10)\n    plt.show()\n\\end{lstlisting}\n\nTry using the following function in place of \\li{update()}.\nCan you explain why this animation is different from the original?\n\n\\begin{lstlisting}\ndef wave(index):\n    drawing.set_data(x, np.roll(y, index))\n    return drawing,\n\\end{lstlisting}\n\n% \\begin{comment} % Too much.\nTo animate multiple objects at once, define the objects separately and make sure the update function returns both objects.\n\n\\begin{lstlisting}\ndef sine_cosine_animation():\n    x = np.linspace(0, 2*np.pi, 200)[:-1]\n    y1, y2 = np.sin(x), np.cos(x)\n\n    fig = plt.figure()\n    plt.xlim(0, 2*np.pi)\n    plt.ylim(-1.2, 1.2)\n\n    sin_drawing, = plt.plot([],[])\n    cos_drawing, = plt.plot([],[])\n\n    def update(index):\n        sin_drawing.set_data(x[:index], y1[:index])\n        cos_drawing.set_data(x[:index], y2[:index])\n        return sin_drawing, cos_drawing,\n\n    a = FuncAnimation(fig, update, frames=len(x), interval=10)\n    plt.show()\n\\end{lstlisting}\n% \\end{comment}\n\n\\begin{comment} % Too much.\nAnimations are very useful for describing parametrized curves, as the ``speed'' of the curve is displayed.\nThe code below animates the rose curve, parametrized by the angle $\\theta \\in [0, 2\\pi]$, given by the following equations.\n%\n\\[\\begin{array}{ccc}\nx(\\theta) = \\cos(\\theta)\\cos(6\\theta), && y(\\theta) = \\sin(\\theta)\\cos(6\\theta)\n\\end{array}\\]\n\n\\begin{lstlisting}\ndef rose_animation():\n    # Calculate the parametrized data.\n    theta = np.linspace(0, 2*np.pi, 200)\n    x = np.cos(theta)*np.cos(6*theta)\n    y = np.sin(theta)*np.cos(6*theta)\n\n    fig = plt.figure()\n    plt.xlim(-1.2, 1.2)\n    plt.ylim(-1.2, 1.2)\n    plt.gca().set_aspect(\"equal\")           # Make the figure exactly square.\n\n    drawing, = plt.plot([],[])\n\n    # Define a function that updates the line data.\n    def update(index):\n        drawing.set_data(x[:index], y[:index])\n        return drawing,\n\n    a = FuncAnimation(fig, update, frames=len(x), interval=10, repeat=False)\n    plt.show()              # repeat=False freezes the animation at the end.\n\\end{lstlisting}\n\\end{comment}\n\nAnimations can also be 3-dimensional.\nThe only major difference is an extra operation to set the 3-dimensional component of the drawn object.\nThe code below animates the space curve parametrized by the following equations:\n%\n\\[\\begin{array}{ccccc}\nx(\\theta) = \\cos(\\theta)\\cos(6\\theta), &&\ny(\\theta) = \\sin(\\theta)\\cos(6\\theta), &&\nz(\\theta) = \\frac{\\theta}{10}\n\\end{array}\\]\n\n\\begin{lstlisting}\ndef rose_animation_3D():\n    theta = np.linspace(0, 2*np.pi, 200)\n    x = np.cos(theta) * np.cos(6*theta)\n    y = np.sin(theta) * np.cos(6*theta)\n    z = theta / 10\n\n    fig = plt.figure()\n    ax = fig.gca(projection='3d')           # Make the figure 3-D.\n    ax.set_xlim3d(-1.2, 1.2)                # Use ax instead of plt.\n    ax.set_ylim3d(-1.2, 1.2)\n    ax.set_aspect(\"equal\")\n\n    drawing, = ax.plot([],[],[])            # Provide 3 empty lists.\n\n    # Update the first 2 dimensions like usual, then update the 3-D component.\n    def update(index):\n        drawing.set_data(x[:index], y[:index])\n        drawing.set_3d_properties(z[:index])\n        return drawing,\n\n    a = FuncAnimation(fig, update, frames=len(x), interval=10, repeat=False)\n    plt.show()\n\\end{lstlisting}\n\n% See \\url{https://matplotlib.org/2.0.0/examples/animation/index.html} for more examples.\n\n\\begin{comment} % TODO: An ORIGINAL example of using widgets\n\\subsection*{Interactive Plots} % ---------------------------------------------\n\nMatplotlib plots can be made interactive by adding \\emph{widgets}.\nConsider the following example, TAKEN FROM THE MATPLOTLIB DOCS BASICALLY AHHH\n\n\\begin{lstlisting}\n>>> from matplotlib import widgets as wg\n\n>>> ax = plt.subplot(111)\n>>> plt.subplots_adjust(bottom=.25)         # Make some space for a slider bar.\n>>> t = np.arange(0., 1., .001)\n>>> a0 = 5.\n>>> f0 = 3.\n>>> s = a0 * np.sin(2 * np.pi * f0 * t)\n>>> l = plt.plot(t, s)[0]\n>>> plt.axis([0, 1, -10, 10])\n>>> axfreq = plt.axes([.25, .05, .65, .03])\n>>> axamp = plt.axes([.25, .1, .65, .03])\n\n# Make some slider bars.\n>>> sfreq = wg.Slider(axfreq, 'Freq', .1, 30., valinit=f0)\n>>> samp = wg.Slider(axamp, 'Amp', .1, 10., valinit=a0)\n>>> def update(val):                        # Function for updating the plot.\n...     amp = samp.val                          # Read from one slider.\n...     freq = sfreq.val                        # Read from the other slider.\n...     l.set_ydata(amp * np.sin(2 * np.pi * freq * t))\n...     plt.draw()                              # Refresh the plot.\n>>> sfreq.on_changed(update)                # Connect the sliders to update().\n>>> samp.on_changed(update)\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H]\n\\includegraphics[width=.7\\textwidth]{figures/interactive_plot.pdf}\n\\end{figure}\n\\end{comment}\n\n% =============================================================================\n% =============================================================================\n% Stuff to move ===============================================================\n% =============================================================================\n% =============================================================================\n\n\\begin{comment}\n\\begin{info} % IPython Notebook inline plotting (move to notebook intro)\nIf you are executing these Matplotlib commands in an IPython shell, executing the \\li{plt.show()} method will open a new window with the plot.\nIf you are using IPython Notebook, you have the option to display the plots within your notebook.\nYou may opt into this feature by running \\li{\\%matplotlib inline} or \\li{\\%matplotlib notebook} in your IPython Notebook.\nThe \\li{inline} option shows the plot, whereas the \\li{notebook} option shows the plot and provides controls to interact with the plot.\nAdditionally, when using this option, the plot is displayed after running the \\li{plt.plot()} command; the \\li{plt.show()} command is not necessary.\n\\end{info}\n\\end{comment}\n", "meta": {"hexsha": "f0f1275916cd1db2340494b7cde1964f3b729a80", "size": 37252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/PythonEssentials/MatplotlibIntro/MatplotlibIntro.tex", "max_stars_repo_name": "DM561/dm561.github.io", "max_stars_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-13T13:22:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-13T13:22:41.000Z", "max_issues_repo_path": "acme-material/Labs/PythonEssentials/MatplotlibIntro/MatplotlibIntro.tex", "max_issues_repo_name": "DM561/dm561.github.io", "max_issues_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-10-18T19:57:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-31T19:00:36.000Z", "max_forks_repo_path": "acme-material/Labs/PythonEssentials/MatplotlibIntro/MatplotlibIntro.tex", "max_forks_repo_name": "DM561/dm561.github.io", "max_forks_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.2358276644, "max_line_length": 269, "alphanum_fraction": 0.6725008053, "num_tokens": 10802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.947381044980928, "lm_q1q2_score": 0.8448848774283725}}
{"text": "\\subsection{Time step selection}\nThe easier way to determine $\\Delta t$ is to select it as a constant for all the simulation iterations.\nFor visualization concerns we will sometimes use a constant $\\Delta t$ but, for simulation precision interests, it is better to compute a new time step for each iterations depending on the distance between the nearest bodies.\nThe following equation describes the variable $\\Delta t$ calculation:\n\\begin{equation}\n\\label{eq:dt1}\n\t\\|\\vec{v_i}(t) . \\Delta t + \\frac{\\vec{a_i}(t)}{2} . \\Delta t^2 \\| \\leq 0.1 \\times ||\\vec{r_{ij}}||,\n\\end{equation}\nwith $j$ the nearest body to the body $i$.\nFor each body $i$, a time step is calculated and the smallest one is chosen.\nEq.~\\ref{eq:dt1} traduces that the distance between $i(t)$ and $i(t + \\Delta t)$ must be below 10\\% of the $||\\vec{r_{ij}}||$ distance.\nThis equation assures that two masses cannot be closest than 20\\% between $t$ time and $t + \\Delta t$ time.\nHowever, Eq.~\\ref{eq:dt1} is not directly usable: this is a $4^{th}$ degree polynomial equation in $\\Delta t$.\nIt's why we will use the triangle inequality witch allows us to determine a new condition:\n\\begin{equation}\n\\label{eq:dt2}\n\t\\|\\vec{v_i}(t)\\| . \\Delta t + \\frac{\\|\\vec{a_i}(t)\\|}{2} . \\Delta t^2  \\leq 0.1 \\times ||\\vec{r_{ij}}||.\n\\end{equation}\nEq.~\\ref{eq:dt2} is a $2^{nd}$ degree equation: this is more reasonable in term of computational time.\n\n\\subsection{Time integration}\n\\sout{The integrator used to update the positions and velocities is a leapfrog-Verlet integrator (Verlet 1967) because it is applicable to this problem and is computationally efficient (it has a high ratio of accuracy to computational cost).}\n\nBody $i$ velocity characteristic at the $t + \\Delta t$ time depends on the velocity and the acceleration at the $t$ time:\n\\begin{equation}\n\\label{eq:velocity}\n\t\\vec{v_i}(t + \\Delta t) = \\vec{v_{i}}(t) + \\vec{a_i}(t) . \\Delta t.\n\\end{equation}\nAt the end, body $i$ position $q_i$ at the $t + \\Delta t$ time depends on the position, the velocity and the acceleration at the $t$ time:\n\\begin{equation}\n\\label{eq:position}\n\tq_i(t + \\Delta t) = q_{i}(t) + \\vec{v_{i}}(t) . \\Delta t + \\frac{\\vec{a_i}(t) . \\Delta t^2}{2}.\n\\end{equation}\nThanks to Eq.~\\ref{eq:acceleration}, \\ref{eq:velocity} and \\ref{eq:position}, it is now possible to compute the new position and the new velocity for all bodies at the $t + \\Delta t$ time.\n", "meta": {"hexsha": "d887c2bcf4506b65ba1359db953ba42a71422484", "size": 2399, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/murb/sections/time.tex", "max_stars_repo_name": "MisterFruits/MUrB", "max_stars_repo_head_hexsha": "b855332f3eb0fd4a8baa203c28dc0e8e5ce50538", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2017-07-08T16:45:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-23T08:45:01.000Z", "max_issues_repo_path": "doc/murb/sections/time.tex", "max_issues_repo_name": "MisterFruits/MUrB", "max_issues_repo_head_hexsha": "b855332f3eb0fd4a8baa203c28dc0e8e5ce50538", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-08T14:35:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-10T07:53:18.000Z", "max_forks_repo_path": "doc/murb/sections/time.tex", "max_forks_repo_name": "MisterFruits/MUrB", "max_forks_repo_head_hexsha": "b855332f3eb0fd4a8baa203c28dc0e8e5ce50538", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-09T07:08:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T07:08:08.000Z", "avg_line_length": 68.5428571429, "max_line_length": 242, "alphanum_fraction": 0.7094622759, "num_tokens": 741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768541530197, "lm_q2_score": 0.8947894717137996, "lm_q1q2_score": 0.8448395085319778}}
{"text": "\\subsubsection{Complex Eigenvalues}\r\n\\begin{theorem}\r\n\tIf an $n \\times n$ matrix $A$ is not defective, then for each pair of complex eigenvalues $\\alpha \\pm \\beta i$ with corresponding eigenvectors $\\vec{a} \\pm i\\vec{b}$, the corresponding fundamental solutions are $e^{\\alpha t}\\left(\\cos{(\\beta t)}\\vec{a}-\\sin{(\\beta t)\\vec{b}}\\right)$ and $e^{\\alpha t}\\left(\\sin{(\\beta t)}\\vec{a}+\\cos{(\\beta t)\\vec{b}}\\right)$.\r\n\\end{theorem}\r\n\r\n\\begin{example}\r\n\tFind the general solution to the system\r\n\t\\begin{equation*}\r\n\t\t\\vec{x}' = \\begin{bmatrix}\r\n\t\t\t2 & 3 \\\\\r\n\t\t\t-3 & 2\r\n\t\t\\end{bmatrix} \\vec{x}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nFinding the eigenvalues by finding the roots of the characteristic polynomial of $A$,\r\n\\begin{equation*}\r\n\tp(\\lambda) = \\det{(A - \\lambda I)} = (2-\\lambda)^2 + 9 \\implies \\lambda = 2 \\pm 3i.\r\n\\end{equation*}\r\nFinding the eigenvectors for $\\lambda = 2 + 3i$, remembering that once we have the two eigenvectors, we don't need to find them for the conjugate,\r\n\\begin{equation*}\r\n\t(A - (2+3i)I)\\vec{v} = \\vec{0} \\implies \\vec{v} = C_1\\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t1\r\n\t\\end{bmatrix} + C_2i\\begin{bmatrix}\r\n\t\t-1 \\\\\r\n\t\t0\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nSo, our solution is\r\n\\begin{equation*}\r\n\t\\vec{x} = C_1e^{2t}\\left(\\cos{(3t)}\\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t1\r\n\t\\end{bmatrix}-\\sin{(3t)}\\begin{bmatrix}\r\n\t\t-1 \\\\\r\n\t\t0\r\n\t\\end{bmatrix}\\right) + C_2e^{2t}\\left(\\sin{(3t)}\\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t1\r\n\t\\end{bmatrix}+\\cos{(3t)}\\begin{bmatrix}\r\n\t\t-1 \\\\\r\n\t\t0\r\n\t\\end{bmatrix}\\right).\r\n\\end{equation*}\r\nWe can rewrite this a little more elegantly as\r\n\\begin{equation*}\r\n\t\\vec{x} = \\begin{bmatrix}\r\n\t\t\\sin{(3t)} & - \\cos{(3t)} \\\\\r\n\t\t\\sin{(3t)} & \\cos{(3t)}\r\n\t\\end{bmatrix} \\begin{bmatrix}\r\n\t\tC_1 \\\\\r\n\t\tC_2\r\n\t\\end{bmatrix} e^{2t}.\r\n\\end{equation*}", "meta": {"hexsha": "df8535b79dcccccb4768a1275ddd90a6664e926a", "size": 1764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/homogeneousSystems/complexEigenvalues.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/linearSystems/homogeneousSystems/complexEigenvalues.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/linearSystems/homogeneousSystems/complexEigenvalues.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 32.0727272727, "max_line_length": 363, "alphanum_fraction": 0.6218820862, "num_tokens": 701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172688214137, "lm_q2_score": 0.8902942363098472, "lm_q1q2_score": 0.8448155751665865}}
{"text": "\\begin{solution}\nIn this problem we are asked approximate the first derivative of the function\n\\begin{align*}\nf(x)=\\frac{1+2x^2\\cos{x}}{x^{2.4}},\n\\end{align*}\nat a given point $x_0=33.3$. We can calculate the derivative analytically,\n\\begin{align*}\nf'(x)=\\frac{2x^2(2\\cos{x}-x\\sin{x})-2.4(1+2x^2\\cos{x})}{x^{3.4}},\n\\end{align*}\nand its value at $x_0$ is $f'(x_0)=-0.466342049195729$ using double precision in \\textsc{MATLAB}. We are asked to plot, in logarithmic scale, the truncation error of three different approximations versus the step $h$. The approximations to use are\n\\begin{itemize}\n\\item First order forward diffrences:\n\\begin{align*}\nf'_i=\\frac{f_{i+1}-f_i}{h}+\\mathcal{O}(h).\n\\end{align*}\n\\item Second order central diffrences:\n\\begin{align*}\nf'_i=\\frac{f_{i+1}-f_{i-1}}{2h}+\\mathcal{O}(h^2).\n\\end{align*}\n\\item Sixth order central differences:\n\\begin{align*}\nf'_i=\\frac{-f_{i-3}+9f_{i-2}-45f_{i-1}+45f_{i+1}-9f_{i+2}+f_{i+3}}{60h}+\\mathcal{O}(h^6).\n\\end{align*}\n\\end{itemize}\nOnce the value of each approximation is obtained, we can compute the error for every value of the step $h$ and show it in the next figure.\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace{-0.56in}\n\\includegraphics[scale=0.5]{IMAGES/problem2_1_edit.eps}\\caption{Error of the different approximations and reference lines.}\n\\end{figure}\n\nThe fact that the error describes a straight line of slope $m$ in logarithmic scale proves that that approximation is of order $m$ (since $\\log{(kh^m)}=\\log{k}+m\\log h$, a straight line of slope $m$). In our case, it is clear in the figure that the approximations are, from top to bottom, indeed of order one, two and six, respectively. However, this linear dependence is broken in two areas of the figure. \n\nFirst, when $h$ is sufficiently small, the \\textit{rounding-error} is dominant and we see it as a cloud of points that seem parallel to the line of slope negative one. This is due to the fact that the rounding error is of the order of $\\frac{\\epsilon}{h}$, where $\\epsilon$ is the well known machine epsilon. An error of that order is shown in logarithmic scale as a straight line of slope negative one (since $\\log{(\\frac{\\epsilon}{h})}=\\log{\\epsilon}-\\log{h}$ and $\\epsilon$ is constant). The point where the rounding error becomes dominant depends, of course, of the order of approximation. The higher the order, as we make $h$ small, the powers of $h$ are even smaller and when they get of the order of $\\epsilon$ the computer cannot differ well enough between numbers. \n\nOn the other hand, when $h$ is large, the terms of the error that are not the leading error term become more and more important as $h$ increases, reaching the point of not being neglectable. We can reach the point where the leading error term is not so anymore since we need $h$ to be small in order to assume that the remaining terms of the series are considerably smaller. We can see that effect in the top right corner of the figure.\n\n\\subsection*{Matlab code for the problem}\n\\section*{HOMEWORK 1 - FRANCISCO CASTILLO}\n\n\n\\subsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Problem 2\n\\end{itemize}\n\n\n\\subsection*{Problem 2}\n\n\\begin{verbatim}\nformat long;clear all;close all;clc\nx_0=33.3;\nf = @(x) (1+2*x^2*cos(x))/(x^(2.4));\nfp = @(x) (2*x^2*(2*cos(x)-x*sin(x))-2.4*(1+2*x^2*cos(x)))/(x^3.4);\nfor k = -3:1:25\n    H(k+4) = 2^(-k);\nend\nfor k = 1:length(H)\n    h = H(k);\n    df1(k) = (f(x_0+h)-f(x_0))/h;\n    df2(k) = (f(x_0+h)-f(x_0-h))/(2*h);\n    df6(k) = (45*(f(x_0+h)-f(x_0-h))-9*(f(x_0+2*h)-f(x_0-2*h))...\n        +(f(x_0+3*h)-f(x_0-3*h)))/(60*h);\nend\nlinewidth=2;\ndarkgreen=[0 0.6 0];\nfigure('units','normalized','outerposition',[0 0 1 1])\nloglog(H,abs(df1-fp(x_0)),'*',H,abs(df2-fp(x_0)),'*')\nhold on\nloglog(H,abs(df6-fp(x_0)),'*','Color',darkgreen)\nloglog(H,H/2,'b--',H,H.^(2)/6,'r--','linewidth',linewidth)\nloglog(H,H.^(6)/140,'--','Color',darkgreen,'linewidth',linewidth)\nloglog(H,eps./H,'k:','linewidth',linewidth)\nset(gca,'fontsize',14)\naxis([1e-8 1e1 1e-20 1e5])\ngrid on\nxlabel('$h$ (log scale)','fontsize',20,'interpreter','latex')\nylabel('Error (log scale)','fontsize',20,'interpreter','latex')\nsaveas(gcf,'IMAGES/problem2_1','epsc')\nsaveas(gcf,'IMAGES/problem2_1','fig')\n\\end{verbatim}\n\\end{solution}", "meta": {"hexsha": "2df83aee70775ab8744978cc7cf7db3af1d00a8b", "size": 4257, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/CFD/Homework 1/problem2.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/CFD/Homework 1/problem2.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/CFD/Homework 1/problem2.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.6785714286, "max_line_length": 774, "alphanum_fraction": 0.6983791402, "num_tokens": 1418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.9099070072595894, "lm_q1q2_score": 0.8447656768316292}}
{"text": "\\chapter{Dual Spaces}\nConsider a vector space $V$ over a field $\\mathbb{F}$ with basis $\\{\\vec{e}_\\mu\\}$.\nThe \\emph{Dual Space} of $V$, denoted $V^*$, is the set of all linear maps from $V$ to $\\mathbb{F}$:\n\\begin{align*}\n    V^* = \\{\\phi : \\phi(\\vec{v}) \\in \\mathbb{F}, \\phi \\text{ is linear}\\}.\n\\end{align*}\nElements of $V^*$ are known as \\emph{covectors}. Note that if we've created $V$, we don't need to do anything to create $V^*$; it is automatically created by $V$.\n\nThis dual space is itself a vector space, since we can give it a concept of addition and scalar multiplication, and the zero covector.\n\\begin{itemize}\n    \\item Addition: Consider covectors $\\Lambda$ and $Z$ of the dual space of $V$ (so they are linear maps from $V$ to $\\mathbb{F}$), and a vector $\\vec{v} \\in V$. We can say that $\\langle \\Lambda + Z, \\vec{v} \\rangle = \\langle \\Lambda,\\vec{v} \\rangle + \\langle Z, \\vec{v} \\rangle$.\n    \\item Scalar multiplication: Again with a covector (linear map) $\\Lambda$, we can say that $\\langle a\\Lambda, \\vec{v} \\rangle = a\\langle \\Lambda, \\vec{v} \\rangle$, where $a$ is a scalar from $\\mathbb{F}$.\n    \\item Zero vector: Consider the map which sends every vector to $0_\\mathbb{F}$; this can act as a `zero covector'.\n\\end{itemize}\n\n\\subsection{Dual Basis}\nWhen we create a vector space $V$ with basis $\\{\\vec{e}_\\mu\\}$, we automatically create a dual space $V^*$; since the dual space is also a vector space, it must have a basis. We call this basis $\\{\\vec{e}^\\mu\\}$, similar to the basis for the original vector space, but with a superscript index instead of a subscript.\nLike our choice for the basis of $V$, the choice of $\\{\\vec{e}^\\mu\\}$ is arbitrary.\nBut, while there isn't a specific basis created, we can choose our bases selectively.\nRemember that $\\vec{e}^\\mu$ are \\emph{linear maps} which can act upon $\\vec{e}_\\mu$;\nWe want to choose the basis for our dual space such that\n\\begin{align*}\n    \\langle \\vec{e}^0, \\vec{e}_0 \\rangle &= 1, \\\\\n    \\langle \\vec{e}^1, \\vec{e}_1 \\rangle &= 1, \\\\\n    &\\vdots \\\\\n    \\langle \\vec{e}^\\mu, \\vec{e}_\\mu \\rangle &= 1,\n\\end{align*}\nbut \n\\begin{align*}\n    \\langle \\vec{e}^0, \\vec{e}_1 \\rangle &= 0, \\\\\n    &\\vdots \\\\\n    \\langle \\vec{e}^\\mu, \\vec{e}_\\nu \\rangle &= 0.\n\\end{align*}\nWe can generalize this statement to\n\\begin{align*}\n    \\langle \\vec{e}^\\mu, \\vec{e}_\\nu \\rangle = \\delta^\\mu_\\nu,\n\\end{align*}\nwhere $\\delta^\\mu_\\nu$ is the Kronecker delta function,\n\\[\n    \\delta^\\mu_\\nu =\n    \\begin{cases}\n        1 & \\mu = \\nu \\\\\n        0 & \\mu \\not= \\nu\n    \\end{cases}.\n\\]\nThis choice is also rather arbitrary --- we just like dealing with the case when $\\langle \\vec{e}^\\mu, \\vec{e}_\\nu \\rangle = 1$ if and only if $\\mu = \\nu$, and is zero otherwise. It's also important to realize that exactly \\emph{which} linear maps $\\{\\vec{e}^\\mu\\}$ are is not specified; although the creation of $V$ implies the creation of $V^*$, there isn't (yet) a way to relate vectors in $V$ to vectors in $V^*$.\n\n\\subsection{The Dual Dual Space}\nSince the dual space $V^*$ is a vector space in its own right, it too must have a dual space, the set of all linear maps which send a vector in $V^*$ to $\\mathbb{F}$.\nIf we look at the bracket notation for what we're really doing, it becomes obvious what this space must be:\n\\begin{align*}\n    \\langle \\Lambda, \\cdot \\rangle &: V \\to \\mathbb{F} \\\\\n    \\langle \\cdot, A^\\mu \\vec{e}_\\mu \\rangle &: V^* \\to \\mathbb{F}.\n\\end{align*}\nIf \\emph{covectors} go from $V$ to $\\mathbb{F}$, then \\emph{vectors} go from $V^*$ to $\\mathbb{F}$, so $V^{**} = V$.\nJust like how we can build any vector in $V$ using Einstein summation over the basis of $V$, we can build a basis for $V^*$ in the same way. Since the basis vectors for $V^*$ are of the form $\\{\\vec{e}^\\mu\\}$, we write an arbitrary vector in the dual space as\n\\[ \\Lambda = A_\\mu \\vec{e}^\\mu \\in V^*. \\]\nThis makes the above definition for linear maps\n\\begin{align*}\n    \\langle A_\\mu \\vec{e}^\\mu, \\cdot \\rangle &: V \\to \\mathbb{F}, \\\\\n    \\langle \\cdot, A^\\mu \\vec{e}_\\mu \\rangle &: V^* \\to \\mathbb{F}.\n\\end{align*}\n\n\\subsection{Covariance and Contravariance}\nIf we start with a vector space $V$ and its corresponding dual space $V^*$ (again, which is which is a rather arbitrary choice, sense \\emph{both} are vector spaces), we say that elements of the vector space $V$ are \\emph{vectors}, and they are said to vary \\emph{contravariantly}, while elements of the dual space $V^*$ are \\emph{covectors} which vary \\emph{contravariantly}.\n\n\\subsection{Arbitrary Vectors and Mappings}\nImagine we have an arbitrary covector $B^\\mu \\vec{e}_\\mu$, and an arbitrary vector $A_\\nu \\vec{e}^\\nu$ upon which this covector acts. We write this as \n\\[ \\langle B_\\mu \\vec{e}^\\mu, A^\\nu \\vec{e}_\\nu \\rangle. \\]\nSince these mappings are linear, we can factor out the coefficients, leaving\n\\[ B_\\mu A^\\nu \\langle \\vec{e}^\\mu, \\vec{e}_\\nu \\rangle. \\]\nSince we know that $\\langle \\vec{e}^\\mu, \\vec{e}_\\nu \\rangle = \\delta^\\mu_\\nu$, we can simplify this into\n\\[ B_\\mu A^\\nu \\langle \\vec{e}^\\mu, \\vec{e}_\\nu \\rangle = B_\\mu A^\\nu \\delta^\\mu_\\nu = B_\\mu A^\\mu. \\]\nThis means that we can refer to the result of the covector-vector applications by just the coefficients, as long as we define the dual basis by the delta function.\nNote also that $B_\\mu A^\\mu$ is a member of the field $\\mathbb{F}$ over which $V$ and $V^*$ are taken.", "meta": {"hexsha": "9fac936a1d29b31d916ad8181001242739dd01ea", "size": 5347, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/dual_space.tex", "max_stars_repo_name": "jopetty/tensor-notes", "max_stars_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/dual_space.tex", "max_issues_repo_name": "jopetty/tensor-notes", "max_issues_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/dual_space.tex", "max_forks_repo_name": "jopetty/tensor-notes", "max_forks_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 71.2933333333, "max_line_length": 417, "alphanum_fraction": 0.668225173, "num_tokens": 1742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.9099070048165069, "lm_q1q2_score": 0.8447656727610715}}
{"text": "\\section{Brief primer on tensors}\\label{sec:tensor}\nThe material here is based on \\cite{lee-book-2000,dullemond-1991-tensor}.\n\n\nLet \\(V\\) be an \\(n\\)-dimensional vector space over the reals. A {\\em covector} on \\(V\\) is a real-valued linear functional \\(\\omega:V\\rightarrow \\Re\\). The space of all covectors is itself a real vector space  under pointwise addition and multiplication. It is written as \\(V^{\\star}\\) and called the {\\em dual space} to \\(V\\). \n\n\\begin{proposition}[\\cite{lee-book-2000} Proposition 4.1] For \\(V\\) an \\(n\\)-dimensional vector space and \\(E_1, \\ldots, E_n\\) a basis for \\(V\\), the covectors \\(\\epsilon^1, \\ldots, \\epsilon^n\\), defined by:\n  \\[\n  \\epsilon^i(E_j) = \\delta^i_j = \\left\\{\n  \\begin{array}{ll}\n    1 & \\mbox{if \\(i =j\\)} \\\\\n    0 & \\mbox{if \\(i\\not=j\\)}\n    \\end{array}\\right.\n    \\]\n\\noindent form a basis for \\(V^{\\star}\\), called the {\\em dual basis} to \\((E_i)\\).   \n\\end{proposition}\n%% TODO: Define canonical isomorphism.\nNote that it follows that the dimensionality of \\(V^{\\star}\\) is the same as that of \\(V\\). It is also the case that \\(V^{\\star\\star}\\) is canonically isomorphic to \\(V\\). \n\n\n\\begin{definition}[Tensor] For $V$ a finite-dimensional real vector space, a {\\em tensor} of rank \\((k,l)\\) over $V$ is a real-valued multilinear function of $k$ elements of \\(V^{\\star}\\) and \\(l\\) elements of \\(V\\). \\(k\\) is said to be its {\\em contravariant} rank, and \\(l\\) its {\\em covariant} rank. The {\\em rank} of the tensor is \\(k+l\\).\n\\end{definition}\nA matrix \\(M\\) is a \\((1,1)\\)-tensor, a vector \\(x\\) a \\((1,0)\\)-tensor, and a covector \\{a\\} a \\((0,1)\\)-tensor.\n\nLet \\(\\{{\\bf e}_j\\}\\) be a basis for \\(V\\), with canonical cobasis \\(\\{\\epsilon^i\\}\\) for \\(V^{\\star}\\). \nSuch a tensor \\(T\\) can be associated with an array with \\(k+l\\) dimensions, whose \\((i_1, \\ldots, i_k, j_1, \\ldots, j_l)\\)'th element written \\(T^{i_1\\ldots i_k}_{j_1, \\ldots, j_l}\\) is given by \\(T(\\epsilon^{i_1}, \\ldots, \\epsilon^{i_k}, {\\bf e}_{j_1}, \\ldots, {\\bf e}_{j_l})\\).\n\nThe meaning of the indices of a tensor is usually decided beforehand; it is conventional to write a tensor with its contravariant (upper) indices first and the covariant (lower) indices last, e.g.{} \\(T^{i,j}_k\\). For instance, a matrix \\(M\\) is a \\((1,1)\\)-tensor, and we can write \\(M_i^j\\) to make its indices explicit. This is the same as \\(M_j^k\\) -- the identity of indices does not matter. Also, basis vectors will be written with a lower index, and components of a vector with respect to this basis with an upper index; similarly basis covectors will be written with an upper index and components of a covector with a lower index. \n\nDenote the set of all \\((k,l)\\)-tensors over \\(V\\) by \\(T^k_l\\).\n$T^k_l(V)$ is a vector space under point-wise addition and scalar multiplication. Specifically:\n\\[\n\\begin{array}{l}\n  (\\alpha T)(X_1, \\ldots, X_k, Y_1, \\ldots, Y_l) = \\alpha(T(X_1, \\ldots, X_k, Y_1, \\ldots, Y_l))\\\\\n  (S+T)(X_1, \\ldots, X_k, Y_1, \\ldots, Y_l)=S(X_1, \\ldots, X_K, Y_1, \\ldots, Y_k) + T(X_1, \\ldots, X_k, Y_1, \\ldots, Y_l)\n\\end{array}\n\\]\n\n\n\n\\subsection{Tensor Contraction}\\label{sec:summation-convention}\nIn the following we shall adopt the {\\em Einstein summation convention}:\n\\begin{quotation}\n  If the same index name appears twice in any term, once as an upper index and once as a lower index, that term is understood to be summed over all possible values of that index, generally from \\(1\\) to the dimension of the space in question. If the indices belong to different tensors, their tensor product is taken first.\n\\end{quotation}\nThus for instance we can rewrite:\n\\[\n\\begin{array}{lcl}\n  \\Sigma_{\\nu=1}^n A_{\\mu\\nu}v^{\\nu} & \\rightarrow &   A_{\\mu\\nu}v_{\\nu}\\\\\n  \\Sigma_{\\beta=1}^n \\Sigma_{\\gamma=1}^n A _{\\alpha \\beta}B^{\\beta \\gamma}C_{\\gamma \\delta} & \\rightarrow & A_{\\alpha \\beta}B^{\\beta \\gamma}C_{\\gamma \\delta}\n\\end{array}\n\\]\n\nThe {\\em contraction} of a tensor is obtained by setting one upper and one lower index equal, thus indicating a summation per the convention above. The result of contracting a \\((k,l)\\)-tensor  is a \\((k-1,l-1)\\) tensor.\n\nThe contraction operation is invariant under coordinate changes.\n\n\n\\subsection{Working with tensors}\n  \nTensors can be ``partially'' evaluated. For \\(T\\) a tensor of rank \\(k\\) representing a predicate \\(p\\), and \\(a\\) a vector representing the value of argument \\(i\\), \\(T_{1\\ldots k}a^i\\) represents the predicate \\(\\lambda x_1, \\ldots, x_{i-1},x_{i+1},\\ldots x_k. p(x_1, \\ldots, x_{i-1}, a, x_{i+1}, \\ldots, x_k)\\). It can be thought of as {\\em contracting} \\(T\\) and \\(a\\) on index \\(i\\).\n  \n\n\\begin{example}\\label{ex:tc-1}\n  Consider the tensor representation of the boolean polynomial \\(p(x,y) = x(1-y)\\). Because \\(x,y\\in \\{0,1\\}\\) with the two values independent of each other, we will embed them in the two dimensional vector space \\(U=\\{0,1\\}^2\\), with ``one hot'' basis vectors \\({\\bf e}_1=(1,0)\\) and \\({\\bf e}_2=(0,1)\\) representing \\(0\\) and \\(1\\) respectively. Now the tensor \\(T_{1,2}\\) representing the binary predicate \\(\\lambda x,y. p(x,y)\\) is represented by the table:\n  \\[\n  \\begin{array}{l}\n    T({\\bf e}_1,{\\bf e}_1)=(0)(1-0)=0\\\\\n    T({\\bf e}_1,{\\bf e}_2)=(0)(1-1)=0\\\\\n    T({\\bf e}_2,{\\bf e}_1)=(1)(1-0)=1\\\\\n    T({\\bf e}_2,{\\bf e}_2)=(1)(0)=0\n  \\end{array}\n  \\]\n  We can use this representation to evaluate the predicate at different points through tensor contraction. For instance, \\(p(0,1)\\) is given, for \\(a={\\bf e}_1,b={\\bf e}_2\\) by \\(T_{1,2}a^1 b^2\\), which through the Einstein convention expands out to:\\footnote{Recall that for a vector \\(x\\) \\(x^j\\) represents its \\(j\\)th coordinate. Note that\n    in the term \\(T_{1,2}a^1b^2\\) the super-scripts of \\(a\\) and \\(b\\) are indices, whereas in\n    \\(T({\\bf e}_i,{\\bf e_j})a^i b^j\\) the super-scripts of \\(a\\) and \\(b\\) are component selections.}\n  \\[\\begin{array}{ll}\n  T_{1,2}a^1 b^2 &= \\Sigma_{j=1}^2 \\Sigma_{i=1}^2 T({\\bf e}_i,{\\bf e_j})a^i b^j \\\\\n  &= T({\\bf e}_1,{\\bf e}_1)(1)(0) + T({\\bf e}_1,{\\bf e}_2)(1)(1) +\n  T({\\bf e}_2,{\\bf e}_1)(0)(0) + T({\\bf e}_2,{\\bf e}_2)(0)(1) \\\\\n  & =T({\\bf e}_1,{\\bf e}_2)\\\\\n  & = 0\n  \\end{array}\n  \\]\n\\end{example}\n\nMore generally, we can compute tensor contraction symbolically. Let \\(x,y\\) be  unknown vectors in \\(U\\), and let \\(S\\) be a rank-2 tensor over \\(U\\). Then if \\(S\\) represents the predicate \\(q\\), the predication \\(q(x,y)\\) is represented by \\(S_{1,2}x^1 y^2\\) which expands out to:\n\\[\\begin{array}{ll}\n  [S(x,y)]&\\defeq  S_{1,2}x^1 y^2\\\\\n  & = \\Sigma_{j=1}^2 \\Sigma_{i=1}^2 S({\\bf e}_i,{\\bf e}_j)x^iy^j \\\\\n  & =S({\\bf e}_1,{\\bf e}_1)x^1y^1 + S({\\bf e}_1,{\\bf e}_2)x^1y^2 +\n      S({\\bf e}_2,{\\bf e}_1)x^2y^1 + S({\\bf e}_2,{\\bf e}_2)x^2y^2 \\\\\n  \\end{array}\n\\]\n\n\\begin{example}[Example~\\ref{ex:tc-1} contd]\n  Taking the value of \\(S\\) above to be \\(T\\), we get:\n  \\[\\begin{array}{ll}    \n      [T(x,y)] & = x^2y^1\\\\\n      & = [x=1][y=0]\n  \\end{array}\n  \\]\n\\end{example}\n\nThe representation of an arbitrary $k$-are predicate is similar, a tensor \\(T_k\\) represented by \\(n^k\\) numbers, for \\(U=\\{0,1\\}^n\\). \n", "meta": {"hexsha": "9281a3e1a8e6b9aaf36642b8c0e248408d684002", "size": 7034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendix-tensor-2.tex", "max_stars_repo_name": "saraswat/logic-nn", "max_stars_repo_head_hexsha": "79af16ead7d86e4eca0b3cfc88d1c3379485088f", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-05-13T15:55:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-11T12:28:48.000Z", "max_issues_repo_path": "appendix-tensor-2.tex", "max_issues_repo_name": "saraswat/logic-nn", "max_issues_repo_head_hexsha": "79af16ead7d86e4eca0b3cfc88d1c3379485088f", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "appendix-tensor-2.tex", "max_forks_repo_name": "saraswat/logic-nn", "max_forks_repo_head_hexsha": "79af16ead7d86e4eca0b3cfc88d1c3379485088f", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.358490566, "max_line_length": 639, "alphanum_fraction": 0.6407449531, "num_tokens": 2509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285007525904, "lm_q2_score": 0.9019206844384594, "lm_q1q2_score": 0.8444548148172315}}
{"text": "\\section*{Problem 4 Solution}\n\nThe number density of material $i$ can be found using the formula\n$$ n_i = \\frac{\\rho_i N_A}{M_i} $$\nwhere $\\rho_i$ is the partial density of material $i$, $M_i$ is the molar mass of $i$, and $N_A$ is Avogadro's number. We can reverse this formula to find the partial density of a material from the atomic density.\n$$ \\rho_i = \\frac{N_i M_i}{N_A} $$\nWe can use this formula for the three isotopes we are considering. We also note the following:\n\\begin{itemize}\n\\item $n_{\\text{O}} = 2(n_{\\text{U5}} + n_{\\text{U5}})$\n\\item $M_{\\text{U5}} = 235.04\\text{ g/mol}$\n\\item $M_{\\text{U8}} = 238.05\\text{ g/mol}$\n\\item $M_{\\text{O}} = 16.00\\text{ g/mol}$\n\\end{itemize}\n\n\\begin{multicols}{2}\n$$ \\rho_{\\text{U5}} = \\frac{n_{\\text{U5}}  M_{\\text{U5}} }{N_A} $$\n$$ \\rho_{\\text{U5}} = \\frac{(2.5\\times10^{21}\\text{ atoms/cm}^3)(235.04\\text{ g/mol}) }{6.022\\times10^{23}\\text{ atoms/mol}} $$\n$$\\boxed{ \\rho_{\\text{U5}} = 0.976\\text{ g/cm}^3 }$$\n\n\n$$ \\rho_{\\text{U8}} = \\frac{n_{\\text{U8}}  M_{\\text{U8}} }{N_A} $$\n$$ \\rho_{\\text{U8}} = \\frac{(2.0\\times10^{22}\\text{ atoms/cm}^3)(238.05\\text{ g/mol}) }{6.022\\times10^{23}\\text{ atoms/mol}} $$\n$$\\boxed{ \\rho_{\\text{U8}} = 7.91\\text{ g/cm}^3 }$$\n\n\\end{multicols}\n\n$$ \\rho_{\\text{O}} = \\frac{n_{\\text{O}}  M_{\\text{O}} }{N_A} $$\n$$ \\rho_{\\text{O}} = \\frac{2(n_{\\text{U5}} + n_{\\text{U5}})  M_{\\text{O}} }{N_A} $$\n$$ \\rho_{\\text{O}} = \\frac{2(2.25\\times10^{22}\\text{ atoms/cm}^{3})(16.00\\text{ g/mol}) }{6.022\\times10^{23}\\text{ atoms/mol}} $$\n$$\\boxed{ \\rho_{\\text{O}} = 1.20\\text{ g/cm}^3 }$$\n\nThe enrichment of $^{235}$U is therefore\n$\\frac{\\rho_{\\text{U5}}}{\\rho_{\\text{U5}}+\\rho_{\\text{U8}}} = 0.1098 \\quad\\Rightarrow \\quad\\boxed{10.98\\%}$\n\n", "meta": {"hexsha": "1bca5c422ebec71357270a3c4327d35c866fb67c", "size": 1709, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc02/disc02_solution04.tex", "max_stars_repo_name": "mitchnegus/NE150-discussion", "max_stars_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/drafts/disc02/disc02_solution04.tex", "max_issues_repo_name": "mitchnegus/NE150-discussion", "max_issues_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/drafts/disc02/disc02_solution04.tex", "max_forks_repo_name": "mitchnegus/NE150-discussion", "max_forks_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.8285714286, "max_line_length": 213, "alphanum_fraction": 0.6038619075, "num_tokens": 743, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.967899289579129, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.8443444026111684}}
{"text": "%!TEX root=ClassNotes.tex\n\n\\section{Taylor Series}\nTaylor series is a technique used to approximate functions using {\\it polynomials}.\n\n\\begin{definition}\n  \\label{def:Taylor_series}\nFor a positive integer $n$, a real number $a$, and an infinitely differentiable function $f$, the {\\bf n$^{th}$ Taylor polynomial/approximation centered at $a$}, denoted $T_nf (x)$, is a degree $n$ polynomial defined as\\\\\n  \\begin{align*}\n    T_nf (x) &= f(a)\n    + f'(a) \\cdot \\dfrac{(x-a)}{1}\n    + f''(a) \\cdot \\dfrac{(x-a)^2}{2!}\n    + \\dots\n    + f^{(n)}(a) \\cdot \\dfrac{(x-a)^n}{n!}\\\\\n  \\end{align*}\n  where $f^{(n)}(a)$ denotes the $n^{th}$ derivative of $f$ at $a$.\\footnote{Recall that $n! = n \\cdot (n-1) \\cdot (n-2) \\cdots 2 \\cdot 1 $.}\nThe limit $n \\rightarrow \\infty$ of the above series is called the {\\bf Taylor series $Tf(x)$}.\\\\\n\\begin{align*}\n  Tf(x) &= f(a)\n  + f'(a) \\cdot \\dfrac{(x-a)}{1}\n  + f''(a) \\cdot \\dfrac{(x-a)^2}{2!}\n  + f^{(3)}(a) \\cdot \\dfrac{(x-a)^3}{3!}\n  + \\dots\\\\\n\\end{align*}\n\\end{definition}\n\n\\begin{remark}\n  The Taylor series defined above is just a {\\it formal series}.\n  It is not always possible to plug in a value for $x$ because of convergence issues.\n  We'll discuss this in the later sections.\n\\end{remark}\n\nWe'll mostly be interested in the Taylor series centered at $a = 0$, \\\\\n\\begin{align*}\n  Tf(x)\n  &=\n  f(0)\n  + f'(0) \\cdot \\dfrac{x}{1}\n  + f''(0) \\cdot \\dfrac{x^2}{2!}\n  + f^{(3)}(0) \\cdot \\dfrac{x^3}{3!}\n  + \\dots\\\\\n\\end{align*}\nIn this case, $Tf(x)$ is called the $n^{th}$ {\\bf Maclaurin series}.\n\n\n\n\\begin{exercise}\n  For each of the following functions compute $f^{(n)}(0)$, for positive integers $n$, and use these to compute the Maclaurin series.\n  \\begin{multicols}{2}\n  \\begin{enumerate}\n    \\item $e^x$\n    \\item $\\sin x$\n    \\item $\\cos x$\n    \\item $\\ln {(1+x)}$\n    \\item $\\dfrac{1}{1-x}$\n    \\item (Optional) $\\tan^{-1} x$\n  \\end{enumerate}\n  \\end{multicols}\n\\end{exercise}\n\n\\begin{exercise}\n  This problem explains why the Definition \\ref{def:Taylor_series} is the ``correct'' definition for Taylor series.\n  \\begin{enumerate}\n    \\item Let $f(x) = x^k$. Compute $T_n f(x)$ centered at $0$ for\n    \\begin{enumerate}\n      \\item $n < k$\n      \\item $n \\ge k$\n    \\end{enumerate}\n    \\item More generally, let\n    \\begin{align*}\n      f(x) = a_0 + a_1 x + a_2 x^2 + \\dots + a_k x^k\n    \\end{align*}\n    Using the previous part, compute $T_n f(x)$ for\n    \\begin{enumerate}\n      \\item $n < k$\n      \\item $n \\ge k$\n    \\end{enumerate}\n     What is the Maclaurin series for this $f(x)$?\n  \\end{enumerate}\n\\end{exercise}\nThe above statement is more generally for all Taylor series centered at any point $a$.\n\\begin{exercise}{\\bf (Optional)}\n  Show that the Taylor series of $f(x) = x^n$, centered at a real number $a$, equals $x^n$. Argue that this is more generally true for an arbitrary polynomial $f(x)$.\n\\end{exercise}\n\n\\subsection{Remainder Term}\nAs mentioned earlier, Definition \\ref{def:Taylor_series} defines a \\textit{formal series} and it not possible to make sense of $Tf(x)$ for a real number $x$.\nThe two important questions that we need to answer are:\n\\begin{enumerate}\n  \\item  Does the limit $\\lim \\limits_{n \\rightarrow \\infty}T_n f(x)$ exist?\n  \\item Does the limit $\\lim \\limits_{n \\rightarrow \\infty}T_n f(x)$ equal $f(x)$?\n\\end{enumerate}\nUnless the answer to both the questions is {\\it yes} it is not possible to use Taylor polynomials for approximating the function $f(x)$.\n\nBoth the questions are in generally difficult to answer.\nTo tackle the first question we need techniques from series and sequences.\nIn this section, we'll focus on answering the second question which can be done using basic Calculus.\n\n\n\\begin{definition}\n  For a smooth function $f$ and real numbers $x$, $a$, the {\\bf $n^{th}$ error term} or the {\\bf $n^{th}$ remainder term $R_nf(x)$} is defined as\n  \\begin{align*}\n    R_nf(x)\n    &= f(x) - T_nf(x)\n  \\end{align*}\n  where $T_n f(x)$ is the $n^{th}$ Taylor approximation of $f$ centered at $a$, so that $f(x) = T_nf(x) + R_nf(x)$.\nThus we can say that\n\\begin{align*}\n  \\lim \\limits_{n \\rightarrow \\infty}T_n f(x) = f(x)\n\\end{align*}\nif and only if\n\\begin{align*}\n  \\lim \\limits_{n \\rightarrow \\infty}R_n f(x) = 0.\n\\end{align*}\n\\end{definition}\n\n\\newpage\n\nThe following Theorem allows us to compute this remainder term using integrals.\n\\begin{theorem}\n  \\label{thm:remainder_term}\n  With the notation as above, the remainder term is given by\n  \\begin{align*}\n    R_nf(x) = \\dfrac{1}{n!} \\cdot \\int_a^x {(x-t)^n \\cdot {f^{(n+1)}(t)} } \\: dt\n  \\end{align*}\n\\end{theorem}\n\n\\begin{exercise}\n  \\begin{enumerate}\n    \\item Using integration by parts (if necessary), compute\n    \\begin{enumerate}\n      \\item $\\int_0^x {f'(t)} \\: dt$\n      \\item $\\int_0^x (x-t) \\cdot {f''(t)} \\: dt$\n      \\item $\\int_0^x (x-t)^2 \\cdot {f^{(3)}(t)} \\: dt$\n    \\end{enumerate}\n    \\item{\\bf (Optional)} By repeatedly applying integration by parts, prove that\n    \\begin{align*}\n      \\dfrac{1}{n!} \\cdot \\int_0^x {(x-t)^n \\cdot {f^{(n+1)}(t)}} \\: dt\n    \\end{align*}\n    equals\n    \\begin{align*}\n      f(x) - \\left( f(0)\n      + f'(0) \\cdot \\dfrac{x}{1}\n      + f''(0) \\cdot \\dfrac{x^2}{2!}\n      + \\dots\n      + f^{(n)}(0) \\cdot \\dfrac{x^n}{n!}\n      \\right)\n    \\end{align*}\n    thereby proving Theorem \\ref{thm:remainder_term} for $a=0$.\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{\\bf (Optional)}\n  Prove Theorem \\ref{thm:remainder_term} for arbitrary real number $a$.\n\\end{exercise}\n\n\n\\newpage\n\\subsection{Computing using Taylor Series}\nWe can use the Taylor series (centered at 0) to do computations if\n\\begin{enumerate}\n  \\item we can compute all the derivatives $f^{(n)}(0)$ for all positive integers $n$\n  \\item $ \\lim \\limits_{n \\rightarrow \\infty}R_n f(x) = 0$.\n\\end{enumerate}\nThe condition $ \\lim \\limits_{n \\rightarrow \\infty}R_n f(x) = 0$ is highly non-trivial and not checking it leads to absurd results.\n\n\\begin{exercise}\n  Let $f(x) = \\dfrac{1}{1-x}$.\n  What happens to the value of the Maclaurin series $Tf(x)$ for $x=2$? What is $f(2)$?\n\\end{exercise}\nFor $f(x) = \\dfrac{1}{1-x}$ we can show that $ \\lim \\limits_{n \\rightarrow \\infty}R_n f(2) = \\infty$ (and not 0) and hence the difference between the Taylor series $Tf(2)$ and the function $f(2)$ blows up to infinity.\nIn the next section, we'll prove the following theorem which says that this does not happen for exponential and trigonometric functions.\n\\begin{theorem}\n  \\label{thm:Taylor_series_exponential}\n  If $f(x) = e^x$, $\\sin x$, and $\\cos x$, then $\\lim \\limits_{n \\rightarrow \\infty}R_n f(x) = 0$ for \\textit{all real numbers} x.\n\\end{theorem}\n\nHence, for all real numbers $x$, $\\lim \\limits_{n \\rightarrow \\infty}T_n f(x) = f(x)$ for exponential and trigonometric functions and we can use the Taylor series to approximate.\n\n\\begin{exercise}\n  Use the Maclaurin series of $e^x$ to compute the value of $e$ correct up to 2 decimal places.\n\\end{exercise}\n\n\\begin{exercise}\n  \\begin{enumerate}\n    \\item Theorem \\ref{thm:Taylor_series_exponential} is also true for $\\tan^{-1} x$, the proof is easy but technical. The Maclaurin series of $\\tan^{-1} x$ is given by\n    \\begin{align*}\n      x - \\dfrac{x^3}{3} + \\dfrac{x^5}{5} - \\dfrac{x^7}{7} + \\dfrac{x^9}{9} + - \\dots\n    \\end{align*}\n    Using this find an expression (as an infinite sum) for $\\pi$.\\hint{Use $x = 1$.}\n    \\item Use the first 10 terms of this sum to find an approximate value for $\\pi$.\n    This method for computing $\\pi$ is not used in practice as the \\textit{rate of convergence} of the Maclaurin series is very slow.\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n  Theorem \\ref{thm:Taylor_series_exponential} is true even if $x$ is a complex number (the proof requires complex analysis).\n  Compute the Taylor series of $e^{i\\theta}$, $\\cos \\theta$, $\\sin \\theta$. Use these to prove the {\\it Euler's identity},\n\\begin{align*}\n    e^{i\\theta} &= \\cos \\theta + i \\sin \\theta\n\\end{align*}\n\\end{exercise}\n\n\n\n\\subsection{Estimating the Remainder Term}\nFinally, we  want to prove Theorem \\ref{thm:Taylor_series_exponential}.\n\n\\begin{exercise} {\\bf (Optional)}\n  Let $x$ be a positive real number.\n   For each of the following functions $f(x)$, show that there is a constant $M$ such that for all $ t \\in (0,x)$  and all positive integers $n$ we have $|f^{(n)}(t)| < M$. (Note that $M$ can depend on $x$ but not on $n$ or $t$.)\n   \\begin{multicols}{2}\n     \\begin{enumerate}\n       \\item $e^x$\n       \\item $\\sin x$\n       \\item $\\cos x$\n     \\end{enumerate}\n   \\end{multicols}\n\\end{exercise}\nUsing the above problem, the proof of Theorem \\ref{thm:Taylor_series_exponential} will be complete once we prove the following Proposition.\n\\begin{prop}\n  Let $x$ be a positive real number. If there is a real number $M$ such that for all $ t \\in (0,x)$  and all positive integers $n$ we have $|f^{(n)}(x)| < M$ then $R_n f(x) \\rightarrow 0$ as $n \\rightarrow \\infty$.\n\\end{prop}\n\\begin{proof}\n  By definition,\n  \\begin{align*}\n    R_n f(x) = \\dfrac{1}{n!} \\cdot \\int_0^x {(x-t)^n \\cdot {f^{(n+1)}(t)}} \\: dt\n  \\end{align*}\n  Because $(x-t)^n < x^n$ and $|f^{(n+1)}(t)| < M$ for all $0 < t < x$  and all positive integers $n$, we get\n  \\begin{align*}\n    |R_n f(x)|\n    &=\n    \\left|\\dfrac{1}{n!} \\cdot \\int_0^x {(x-t)^n \\cdot {f^{(n+1)}(t)}} \\: dt \\right|\\\\\n    &< \\left|\\dfrac{1}{n!} \\cdot \\int_0^x x^n \\cdot M \\: dt \\right| \\\\\n    &=  \\left|\\dfrac{1}{n!} \\cdot x^n \\cdot M \\int_0^x 1 \\: dt \\right| \\\\\n    &=  \\left|\\dfrac{1}{n!} \\cdot x^n \\cdot M x \\right| \\\\\n    &= \\dfrac{M x^{n+1}}{n!}\n  \\end{align*}\n  One can show that for any real number $x$, $\\lim \\limits_{n \\rightarrow \\infty} x^{n+1} / n! = 0$ (this is easy, see if you can work out the details) so that\n\\begin{align*}\n    \\lim \\limits_{n \\rightarrow \\infty} |R_n f(x)|\n    &<\n    \\lim \\limits_{n \\rightarrow \\infty} \\dfrac{M x^{n+1}}{n!}\n    \\\\\n    &= {M}\\cdot \\lim \\limits_{n \\rightarrow \\infty} \\dfrac{x^{n+1}}{n!} \\\\\n    &= M \\cdot 0 = 0\n\\end{align*}\n\\end{proof}\n\nTo summarize, Taylor series provides us a tool for approximating functions using polynomials (in the cases where the remainder term tends to 0).\nThis is a very common technique in analysis: we try to approximate a function by a series of simpler functions and show that the difference between the two tends to 0.\nFourier series, for example, does this using trigonometric functions.\n", "meta": {"hexsha": "28efde8703bc0862b5ce297f024e82b9311394aa", "size": 10339, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/11Taylor.tex", "max_stars_repo_name": "apurvnakade/jhu2017-18-honors-single-variable-calculus", "max_stars_repo_head_hexsha": "5b6cb3dde364990abe868ce155a697dce78302fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2018/11Taylor.tex", "max_issues_repo_name": "apurvnakade/jhu2017-18-honors-single-variable-calculus", "max_issues_repo_head_hexsha": "5b6cb3dde364990abe868ce155a697dce78302fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2018/11Taylor.tex", "max_forks_repo_name": "apurvnakade/jhu2017-18-honors-single-variable-calculus", "max_forks_repo_head_hexsha": "5b6cb3dde364990abe868ce155a697dce78302fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.8656126482, "max_line_length": 229, "alphanum_fraction": 0.645807138, "num_tokens": 3495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248242542283, "lm_q2_score": 0.8991213847035618, "lm_q1q2_score": 0.8442973002544806}}
{"text": "%----------------------------------------------------------------------------------------\n%\tCHAPTER 2\n%----------------------------------------------------------------------------------------\n\n\\chapter{In-text Elements}\n\n\\section{Theorems}\\index{Theorems}\n\nThis is an example of theorems.\n\n\\subsection{Several equations}\\index{Theorems!Several Equations}\nThis is a theorem consisting of several equations.\n\n\\begin{theorem}[Name of the theorem]\nIn $E=\\mathbb{R}^n$ all norms are equivalent. It has the properties:\n\\begin{align}\n& \\big| ||\\mathbf{x}|| - ||\\mathbf{y}|| \\big|\\leq || \\mathbf{x}- \\mathbf{y}||\\\\\n&  ||\\sum_{i=1}^n\\mathbf{x}_i||\\leq \\sum_{i=1}^n||\\mathbf{x}_i||\\quad\\text{where $n$ is a finite integer}\n\\end{align}\n\\end{theorem}\n\n\\subsection{Single Line}\\index{Theorems!Single Line}\nThis is a theorem consisting of just one line.\n\n\\begin{theorem}\nA set $\\mathcal{D}(G)$ in dense in $L^2(G)$, $|\\cdot|_0$. \n\\end{theorem}\n\n%------------------------------------------------\n\n\\section{Definitions}\\index{Definitions}\n\nThis is an example of a definition. A definition could be mathematical or it could define a concept.\n\n\\begin{definition}[Definition name]\nGiven a vector space $E$, a norm on $E$ is an application, denoted $||\\cdot||$, $E$ in $\\mathbb{R}^+=[0,+\\infty[$ such that:\n\\begin{align}\n& ||\\mathbf{x}||=0\\ \\Rightarrow\\ \\mathbf{x}=\\mathbf{0}\\\\\n& ||\\lambda \\mathbf{x}||=|\\lambda|\\cdot ||\\mathbf{x}||\\\\\n& ||\\mathbf{x}+\\mathbf{y}||\\leq ||\\mathbf{x}||+||\\mathbf{y}||\n\\end{align}\n\\end{definition}\n\n%------------------------------------------------\n\n\\section{Notations}\\index{Notations}\n\n\\begin{notation}\nGiven an open subset $G$ of $\\mathbb{R}^n$, the set of functions $\\varphi$ are:\n\\begin{enumerate}\n\\item Bounded support $G$;\n\\item Infinitely differentiable;\n\\end{enumerate}\na vector space is denoted by $\\mathcal{D}(G)$. \n\\end{notation}\n\n%------------------------------------------------\n\n\\section{Remarks}\\index{Remarks}\n\nThis is an example of a remark.\n\n\\begin{remark}\nThe concepts presented here are now in conventional employment in mathematics. Vector spaces are taken over the field $\\mathbb{K}=\\mathbb{R}$, however, established properties are easily extended to $\\mathbb{K}=\\mathbb{C}$.\n\\end{remark}\n\n%------------------------------------------------\n\n\\section{Corollaries}\\index{Corollaries}\n\nThis is an example of a corollary.\n\n\\begin{corollary}[Corollary name]\nThe concepts presented here are now in conventional employment in mathematics. Vector spaces are taken over the field $\\mathbb{K}=\\mathbb{R}$, however, established properties are easily extended to $\\mathbb{K}=\\mathbb{C}$.\n\\end{corollary}\n\n%------------------------------------------------\n\n\\section{Propositions}\\index{Propositions}\n\nThis is an example of propositions.\n\n\\subsection{Several equations}\\index{Propositions!Several Equations}\n\n\\begin{proposition}[Proposition name]\nIt has the properties:\n\\begin{align}\n& \\big| ||\\mathbf{x}|| - ||\\mathbf{y}|| \\big|\\leq || \\mathbf{x}- \\mathbf{y}||\\\\\n&  ||\\sum_{i=1}^n\\mathbf{x}_i||\\leq \\sum_{i=1}^n||\\mathbf{x}_i||\\quad\\text{where $n$ is a finite integer}\n\\end{align}\n\\end{proposition}\n\n\\subsection{Single Line}\\index{Propositions!Single Line}\n\n\\begin{proposition} \nLet $f,g\\in L^2(G)$; if $\\forall \\varphi\\in\\mathcal{D}(G)$, $(f,\\varphi)_0=(g,\\varphi)_0$ then $f = g$. \n\\end{proposition}\n\n%------------------------------------------------\n\n\\section{Examples}\\index{Examples}\n\nThis is an example of examples.\n\n\\subsection{Equation and Text}\\index{Examples!Equation and Text}\n\n\\begin{example}\nLet $G=\\{x\\in\\mathbb{R}^2:|x|<3\\}$ and denoted by: $x^0=(1,1)$; consider the function:\n\\begin{equation}\nf(x)=\\left\\{\\begin{aligned} & \\mathrm{e}^{|x|} & & \\text{si $|x-x^0|\\leq 1/2$}\\\\\n& 0 & & \\text{si $|x-x^0|> 1/2$}\\end{aligned}\\right.\n\\end{equation}\nThe function $f$ has bounded support, we can take $A=\\{x\\in\\mathbb{R}^2:|x-x^0|\\leq 1/2+\\epsilon\\}$ for all $\\epsilon\\in\\intoo{0}{5/2-\\sqrt{2}}$.\n\\end{example}\n\n\\subsection{Paragraph of Text}\\index{Examples!Paragraph of Text}\n\n\\begin{example}[Example name]\n\\lipsum[2]\n\\end{example}\n\n%------------------------------------------------\n\n\\section{Exercises}\\index{Exercises}\n\nThis is an example of an exercise.\n\n\\begin{exercise}\nThis is a good place to ask a question to test learning progress or further cement ideas into students' minds.\n\\end{exercise}\n\n%------------------------------------------------\n\n\\section{Problems}\\index{Problems}\n\n\\begin{problem}\nWhat is the average airspeed velocity of an unladen swallow?\n\\end{problem}\n\n%------------------------------------------------\n\n\\section{Vocabulary}\\index{Vocabulary}\n\nDefine a word to improve a students' vocabulary.\n\n\\begin{vocabulary}[Word]\nDefinition of word.\n\\end{vocabulary}\n\n\n", "meta": {"hexsha": "fc5c759b2d701452d9a03debd9029021d1d0ecc9", "size": 4712, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter2.tex", "max_stars_repo_name": "karthikpoduval/camera-software-demystified", "max_stars_repo_head_hexsha": "904a28ebab51b1c5b1366bfdf8c81b2b2c3710fa", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter2.tex", "max_issues_repo_name": "karthikpoduval/camera-software-demystified", "max_issues_repo_head_hexsha": "904a28ebab51b1c5b1366bfdf8c81b2b2c3710fa", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter2.tex", "max_forks_repo_name": "karthikpoduval/camera-software-demystified", "max_forks_repo_head_hexsha": "904a28ebab51b1c5b1366bfdf8c81b2b2c3710fa", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.2052980132, "max_line_length": 222, "alphanum_fraction": 0.6120543294, "num_tokens": 1378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.8962513759047847, "lm_q1q2_score": 0.8439588345107335}}
{"text": "%-----------------------------------\n\\subsection{The conic frustrum}\n%-----------------------------------\nThe derivation of the surface area of conic frustrum.\nThe edge length $l$ is defined\n\\begin{equation}\n    l = \\sqrt{(x_r - x_l)^2 + (a_r - a_l)^2} = \\sqrt{\\Delta x^2 + \\Delta a^2}.\n\\end{equation}\nThe lateral area of the surface is found by integrating along surface of rotation:\n\\begin{align}\n    \\sigma_{\\text{lateral}}\n        &= \\int_{0}^{l} {2\\pi a(s)} \\deriv{s} \\nonumber \\\\\n        &= 2\\pi \\int_{0}^{l} {a_{\\ell} + \\frac{s}{l}\\left( a_r - a_\\ell \\right)} \\deriv{s} \\nonumber \\\\\n        &= 2\\pi \\left[ a_{\\ell}s + \\frac{s^2}{2l}\\left( a_r - a_\\ell \\right) \\right]_0^l \\nonumber \\\\\n        &= \\pi l \\left( a_{\\ell} + a_r \\right) \\nonumber \\\\\n        &= \\pi \\left( a_{\\ell} + a_r \\right) \\sqrt{\\Delta x^2 + \\Delta a^2}. \\label{eq:frustrum_area}\n\\end{align}\n\nThere are two degenerate cases of interest. The first is the \\emph{cylinder}, for which the radii at each end are euqal, i.e. $a_\\ell = a_r = a$. In this case the lateral area of the surface is\n\\begin{equation}\n    \\sigma_{\\text{lateral}} = 2\\pi a \\Delta x.\n\\end{equation}\nThe second is a cone, for which $a_\\ell=0$ and $a_r=a$:\n\\begin{equation}\n    \\sigma_{\\text{lateral}} = \\pi a \\sqrt{\\Delta x^2 + a^2}.\n\\end{equation}\n", "meta": {"hexsha": "81a04377c2f6db62dc7f51e03705b21a6d657a9a", "size": 1289, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/math/model/appendix.tex", "max_stars_repo_name": "kabicm/arbor", "max_stars_repo_head_hexsha": "cfab5fd6a2e6a211c097659c96dcc098ee806e68", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/math/model/appendix.tex", "max_issues_repo_name": "kabicm/arbor", "max_issues_repo_head_hexsha": "cfab5fd6a2e6a211c097659c96dcc098ee806e68", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-03-26T16:29:39.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-27T13:41:49.000Z", "max_forks_repo_path": "doc/math/model/appendix.tex", "max_forks_repo_name": "kabicm/arbor", "max_forks_repo_head_hexsha": "cfab5fd6a2e6a211c097659c96dcc098ee806e68", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-06T11:07:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T11:07:13.000Z", "avg_line_length": 47.7407407407, "max_line_length": 193, "alphanum_fraction": 0.5896043445, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9693241991754918, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.8438910000043052}}
{"text": "\\lab{Introduction to Matplotlib}{Matplotlib}\n\\label{lab:Matplotlib}\n\\objective{\nMatplotlib is the most commonly-used data visualization library in Python. Being able to visualize data helps to determine patterns, to communicate results, and is a key component of applied and computational mathematics.\nIn this lab we introduce techniques for visualizing data in 1, 2, and 3 dimensions.\nThe plotting techniques presented here will be used in the remainder of the labs in the manual.\n}\n\n\\section*{Line Plots} % =======================================================\n\nThe quickest way to visualize a simple 1-dimensional array is via a \\emph{line plot}.\nThe following code creates an array of outputs of the function $f(x) = x^2$, then visualizes the array using the \\li{matplotlib} module.\\footnote{Like NumPy, Matplotlib is \\emph{not} part of the Python standard library, but it is included in most Python distributions.}\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from matplotlib import pyplot as plt\n\n>>> y = np.arange(-5,6)**2\n>>> y\narray([25, 16,  9,  4,  1,  0,  1,  4,  9, 16, 25])\n\n# Visualize the plot.\n>>> plt.plot(y)                     # Draw the line plot.\n<<[<matplotlib.lines.Line2D object at 0x1084762d0>]>>\n>>> plt.show()                      # Reveal the resulting plot.\n\\end{lstlisting}\n\nThe result is shown in Figure \\ref{fig:basic1}.\nJust as \\li{np} is a standard alias for NumPy, \\li{plt} is a standard alias for \\li{matplotlib.pyplot} in the Python community.\n\nThe call \\li{plt.plot(y)} creates a figure and draws straight lines connecting the entries of \\li{y} relative to the $y$-axis.\nThe $x$-axis is by default the index of the array, namely the integers from $0$ to $10$.\nCalling \\li{plt.show()} then displays the figure.\n\n\\begin{figure}[H] % plt.plot(y) compared to plt.plot(x,y).\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/basic1.pdf}\n    \\caption{\\li{plt.plot(y)} uses the indices of\\\\the array for the $x$-axis.}\n    \\label{fig:basic1}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/basic2.pdf}\n    \\caption{\\li{plt.plot(x,y)} specifies both the\\\\domain and the range.}\n    \\label{fig:basic2}\n\\end{subfigure}\n\\caption{Simple plots of $f(x) = x^2$ over the interval $x\\in[-5,5]$.}\n\\end{figure}\n\n\\begin{problem} % Law of Large Numbers / NumPy review.\nWrite a function that accepts an integer $n$ as input.\n\\begin{enumerate}\n\\item Use \\li{np.random.randn()} or \\li{np.random.normal()} to create an $n\\times n$ array of values randomly sampled from the standard normal distribution.\n\\item Compute the mean of each row of the array.\n\\\\(Hint: use \\li{np.mean()} and specify the \\li{axis} keyword argument.)\n\\item Return the variance of these means.\n\\\\(Hint: use \\li{np.var()} to calcualte the variance).\n\\end{enumerate}\nDefine a new function that creates an array of the results of the first function with inputs $n = 100,\\ 200,\\ \\ldots,\\ 1000$.\nPlot (and show) the resulting array.\n\nThis result illustrates one version of the \\emph{Law of Large Numbers}.\n\\end{problem}\n\n\\subsection*{Specifying a Domain} % -----------------------------------------\n\nAn obvious problem with Figure \\ref{fig:basic1} is that the $x$-axis does not correspond correctly to the $y$-axis for the function $f(x) = x^2$ that is being drawn.\nTo correct this, we need an array for the domain as well as one for the range.\nFirst define an array \\li{x} for the domain, then use that array to calculate the range \\li{y} of $f$.\nThe command \\li{plt.plot(x,y)} then plots \\li{x} against \\li{y}.\nThat is, each point \\li{(x[i], y[i])} is drawn and consecutive points are connected.\n% Thus both arrays must have the same number of elements to be compatible.\n\nAnother problem with Figure \\ref{fig:basic1} is its poor resolution; the curve is visibly bumpy, especially near the bottom of the curve.\nNumPy's \\li{np.linspace()} function makes it easy to get a higher-resolution domain.\nRecall that \\li{range()} and \\li{np.arange()} return a list or array of evenly-spaced values in a given interval, where the \\emph{spacing} between the entries is specified.\nIn contrast, \\li{np.linspace()} creates an array of evenly-spaced values in a given interval where the \\emph{number of elements} is specified.\n\n\\begin{lstlisting}\n# 4 evenly-spaced values between 0 and 32 (including endpoints).\n>>> np.linspace(0, 32, 4)\narray([  0.        ,  10.66666667,  21.33333333,  32.        ])\n\n# Get 50 evenly-spaced values from -5 to 5 (including endpoints).\n>>> x = np.linspace(-5, 5, 50)\n>>> y = x**2                        # Calculate the range of f(x) = x**2.\n>>> plt.plot(x, y)\n>>> plt.show()\n\\end{lstlisting}\n\nThe resulting plot is shown in Figure \\ref{fig:basic2}.\nNote that this time, the $x$-axis is correctly aligned with the $y$-axis.\nThe resolution is also much better because \\li{x} and \\li{y} have $50$ entries each instead of only $10$.\n\nAll calls to \\li{plt} functions modify the same figure until \\li{plt.show()} is executed, which displays the current figure and resets the system.%\n\\footnote{Use \\li{plt.figure()} to manually create several figures at once.}\nThe next time a \\li{plt} function is called a new figure is created.\nThis makes it possible to plot several lines in a single figure.\n\n\n\\begin{problem} % Plot two lines (sin() and cos()).\nWrite a function that plots the functions $\\sin(x)$, $\\cos(x)$, and $\\arctan(x)$ on the domain $[-2\\pi, 2\\pi]$ (use \\li{np.pi} for $\\pi$).\n% Call \\li{plt.xlim(-2*np.pi, 2*np.pi)} before \\li{plt.show()} to stretch the $x$-axis appropriately.\nMake sure the domain is refined enough to produce a figure with good resolution.\n\\end{problem}\n\n\\begin{info} % Interactive Mode.\nPlotting can seem a little mystical because the actual plot doesn't appear until \\li{plt.show()} is executed.\nMatplotlib's \\emph{interactive mode} allows the user to see the plot be constructed one piece at a time.\nUse \\li{plt.ion()} to turn interactive mode on and \\li{plt.ioff()} to turn it off.\nThis is very useful for quick experimentation.\n\nTry executing the following commands in IPython:\n\n\\begin{lstlisting}\nIn [1]: import numpy as np\nIn [2]: from matplotlib import pyplot as plt\n\n# Turn interactive mode on and make some plots.\nIn [3]: plt.ion()\nIn [4]: x = np.linspace(1, 4, 100)\nIn [5]: plt.plot(x, np.log(x))\nIn [6]: plt.plot(x, np.exp(x))\n\n# Clear the figure, then turn interactive mode off.\nIn [7]: plt.clf()\nIn [8]: plt.ioff()\n\\end{lstlisting}\n\nUse interactive mode \\textbf{only} with IPython.\nUsing interactive mode in a non-interactive setting may freeze the window or cause other problems.\n\\end{info}\n\n\\section*{Plot Customization} % ===============================================\n\n\\li{plt.plot()} receives several keyword arguments for customizing the drawing.\nFor example, the color and style of the line are specified by the following string arguments.\n%\n\\begin{table}[H] % Color and style.\n\\begin{tabular}{r|l}\n    Key & Color \\\\\n    \\hline\n    \\li{'b'} & blue\\\\\n    \\li{'g'} & green\\\\\n    \\li{'r'} & red\\\\\n    \\li{'c'} & cyan\\\\\n    \\li{'m'} & magenta\\\\\n    % \\li{'y'} & yellow\\\\\n    \\li{'k'} & black\\\\\n    % \\li{'w'} & white\n\\end{tabular}\n\\qquad\n\\begin{tabular}{r|l}\n    Key & Style \\\\\n    \\hline\n    \\li{'-'} & solid line\\\\\n    \\li{'--'} & dashed line\\\\\n    \\li{'-.'} & dash-dot line\\\\\n    \\li{':'} & dotted line\\\\\n    % \\li{'.'} & point marker\\\\\n    \\li{'o'} & circle marker\\\\\n    % \\li{'*'} & star marker\\\\\n    \\li{'+'} & plus marker\n\\end{tabular}\n\\end{table}\n\nSpecify one or both of these string codes as an argument to \\li{plt.plot()} to change from the default color and style.\nOther \\li{plt} functions further customize a figure.\n%\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|l}\n    Function & \\multicolumn{1}{|c}{Description}\\\\\n    \\hline\n    % \\li{grid()} & Add grid lines\\\\\n    \\li{legend()} & Place a legend in the plot\\\\\n    % \\li{text()} & Add text at a given position on the plot\\\\\n    \\li{title()} & Add a title to the plot\\\\\n    \\li{xlim()} & Set the limits of the $x$-axis\\\\\n    \\li{ylim()} & Set the limits of the $y$-axis\\\\\n    % \\li{xticks()} & set the location of the tick marks on the x axis, returns current locations if no arguments are given\\\\\n    % \\li{yticks()} & set the location of the tick marks on the y axis, returns current locations if no arguments are given\\\\\n    \\li{xlabel()} & Add a label to the $x$-axis\\\\\n    \\li{ylabel()} & Add a label to the $y$-axis\n\\end{tabular}\n\\end{table}\n\n\\begin{lstlisting}\n>>> x1 = np.linspace(-2, 4, 100)\n>>> plt.plot(x1, np.exp(x1), 'g:', linewidth=6, label=\"Exponential\")\n>>> plt.title(\"This is the title.\", fontsize=18)\n>>> plt.legend(loc=\"upper left\")    # plt.legend() uses the 'label' argument of\n>>> plt.show()                      # plt.plot() to create a legend.\n\n>>> x2 = np.linspace(1, 4, 100)\n>>> plt.plot(x2, np.log(x2), 'r+', markersize=4)\n>>> plt.xlim(0, 5)                  # Set the visible limits of the x axis.\n>>> plt.xlabel(\"The x axis\")        # Give the x axis a label.\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H] % Figure customizations.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/custom1.pdf}\n    \\label{fig:custom1}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/custom2.pdf}\n    \\label{fig:custom2}\n\\end{subfigure}\n\\label{fig:custom}\n\\end{figure}\n\nSee Appendix \\ref{mpltables} for more comprehensive lists of colors, line styles, and figure customization routines.\n\n\\begin{problem} % Line plots with different domains but uniform style.\nWrite a function to plot the curve $f(x) = \\frac{1}{x-1}$ on the domain $[-2,6]$.\nAlthough $f(x)$ has a discontinuity at $x=1$, a single call to \\li{plt.plot()} will attempt to make the curve look continuous.\n\\begin{enumerate}\n\\item Split up the domain and plot the two sides of the curve separately so that the graph looks discontinuous at $x=1$.\n\\item Plot both curves with a thick, dashed magenta line.\\\\\nThe keyword arguments \\li{linewidth} or \\li{lw} specify the line thickness.\n\\item Change the range of the $y$-axis to be $[-6, 6]$.\n\\end{enumerate}\nThe plot should resemble the figure below.\n\n\\begin{figure}[H] % Solution.\n\\includegraphics[width=.5\\textwidth]{figures/discontinuousProblem.pdf}\n\\end{figure}\n\\end{problem}\n\n\\subsection*{Subplots} % ------------------------------------------------------\n\n\\emph{Subplots} are non-overlapping plots arranged in a grid within a single figure.\nTo create a figure with a grid of subplots, use \\li{plt.subplot(numrows, numcols, fignum)}.\nHere, \\li{numrows} is the number of rows of subplots in the figure, \\li{numcols} is the number of columns, and \\li{fignum} specifies which subplot to modify.\n% This index starts at 1 and increments across rows first.\nSee Figure \\ref{fig:subplots-layout}.\n\n\\begin{figure}[H] % The layout created by subplots(23i).\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.15\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/layout_1.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.15\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/layout_2.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.15\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/layout_3.pdf}\n\\end{subfigure}\n\\\\\n\\begin{subfigure}{.15\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/layout_4.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.15\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/layout_5.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.15\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/layout_6.pdf}\n\\end{subfigure}\n\\caption{The layout of subplots with \\li{plt.subplot(2,3,i)} (2 rows, 3 columns), where \\li{i} is the index pictured above.}\n\\label{fig:subplots-layout}\n\\end{figure}\n\nIf the inputs for \\li{plt.subplot()} are all integers, the commas between the entries can be omitted.\nFor example, \\li{plt.subplot(3,2,2)} and \\li{plt.subplot(322)} are equivalent.\n\n\\begin{lstlisting}\n>>> x = np.linspace(.1, 2, 200)\n\n>>> plt.subplot(121)                # Start drawing the first subplot.\n>>> plt.plot(x, np.exp(x), 'k', lw=2)\n>>> plt.plot(x, np.exp(2*x), 'b', lw=2)\n>>> plt.title(\"Exponential\", fontsize=18)\n\n>>> plt.subplot(122)                # Start drawing the second subplot.\n>>> plt.plot(x, np.log(x), 'k', lw=2)\n>>> plt.plot(x, np.log(2*x), 'b', lw=2)\n>>> plt.title(\"Logarithmic\", fontsize=18)\n\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H] % The layout created by plt.subplot(23i).\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/subplots_1.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/subplots_2.pdf}\n\\end{subfigure}\n\\end{figure}\n\n\\begin{problem} % Subplots of sine functions.\nWrite a function that plots the functions $\\sin(x)$, $\\sin(2x)$, $2\\sin(x)$, and $2\\sin(2x)$ on the domain $[0, 2\\pi]$, each in a separate subplot.\n\\begin{enumerate}\n    \\item Arrange the plots in a square grid of 4 subplots.\n    \\item Set the limits of each subplot to $[0, 2\\pi]\\times[-2,2]$.\n    \\\\(Hint: \\li{plt.axis()} can do this in one line, instead of using both\n    \\\\\\li{plt.xlim()} and \\li{plt.ylim()}.)\n    \\item Use \\li{plt.title()} to give each subplot an appropriate title.\n    \\item Use \\li{plt.suptitle()} to give the overall figure a title.\n    \\item Use the following colors and line styles.\n    \\begin{align*}\\begin{array}{rcl}\n    \\sin(x)\\text{: green solid line.} && \\sin(2x)\\text{: red dashed line.}\\\\ \\\\\n    2\\sin(x)\\text{: blue dashed line.} && 2\\sin(2x)\\text{: magenta dotted line.}\n    \\end{array}\\end{align*}\n\\end{enumerate}\n\\end{problem}\n\n\\section*{Other Kinds of Plots} % =============================================\n\nLine plots are not always the most illuminating choice graph to describe a set of data.\nMatplotlib provides several other easy ways to visualize data.\n\n\\begin{itemize}\n\\item A \\emph{scatter plot} plots two 1-dimensional arrays against each other without drawing lines between the points.\nScatter plots are particularly useful for data that is not inherently correlated or ordered.\n\nTo create a scatter plot, use \\li{plt.plot()} and specify a point marker (such as \\li{'o'} or \\li{'+'}) for the line style.%\n\\footnote{\\li{plt.scatter()} can also be used to create scatter plots, but it accepts slightly different arguments than \\li{plt.plot()}. We will explore the appropriate usage of this function in a later lab.}\n\n\\item A \\emph{histogram} groups entries of a 1-dimensional data set into a given number of intervals, called \\emph{bins}.\nEach bin has a bar whose height indicates the number of values that fall in the range of the bin.\n% The more bins, the greater the detail, but having too many bins can also destroy the picture by creating interval gaps between values.\nHistograms are best for displaying distributions, relating data values to frequency.\n\nTo create a histogram, use \\li{plt.hist()} instead of \\li{plt.plot()}.\nUse the argument \\li{bins} to specify the edges of the bins, or to choose a number of bins.\nThe \\li{<<range>>} argument specifies the outer limits of the first and last bins.\n\\end{itemize}\n\n\\begin{lstlisting}\n# Get 500 random samples from two normal distributions.\n>>> x = np.random.normal(scale=1.5, size=500)\n>>> y = np.random.normal(scale=0.5, size=500)\n\n# Draw a scatter plot of x against y, using a circle marker.\n>>> plt.subplot(121)\n>>> plt.plot(x, y, 'o', markersize=10)\n\n# Draw a histogram to display the distribution of the data in x.\n>>> plt.subplot(122)\n>>> plt.hist(x, bins=np.arange(-4.5, 5.5))      # Or, equivalently,\n#   plt.hist(x, bins=9, range=[-4.5, 4.5])\n\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H]\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/scatterplot.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/histogram.pdf}\n\\end{subfigure}\n\\end{figure}\n\n% On the histogram, specifying 9 bins in the range $[-4.5, 4.5]$ creates a bin centered over each integer from $-4$ to $4$.\n\n\\begin{problem} % FARS data visualization.\nThe Fatality Analysis Reporting System (FARS) is a nationwide census providing yearly data regarding fatal injuries suffered in motor vehicle traffic crashes.%\n\\footnote{See \\url{http://www.nhtsa.gov/FARS}.}\nThe array contained in \\texttt{FARS.npy} is a small subset of the FARS database from 2010--2014.\nEach of the 148,206 rows in the array represents a different car crash; the columns represent the hour (in military time, as an integer), the longitude, and the latitude, in that order.\n\nWrite a function to visualize the data in \\texttt{FARS.npy}.\nUse \\li{np.load()} to load the data, then create a single figure with two subplots:\n%\n\\begin{enumerate}\n\\item A scatter plot of longitudes against latitudes.\nBecause of the large number of data points, use black pixel markers (use \\li{\"k,\"} as the third argument to \\li{plt.plot()}).\nLabel both axes.\n\\\\\n(Hint: Use \\li{plt.axis(\"equal\")} to fix the axis ratio on the scatter plot).\n\n\\item A histogram of the hours of the day, with one bin per hour.\nSet the limits of the $x$-axis appropriately.\nLabel the $x$-axis.\n\\end{enumerate}\n\\end{problem}\n\n% Other kinds of plots for 1-dimensional data includes bar plots, box plots, and others.\n% See Appendix \\ref{mpltables} for examples and syntax.\n\n\\subsection*{Visualizing 3-D Surfaces} % --------------------------------------\n\nTo plot a function $f: \\mathbb{R}^2 \\rightarrow \\mathbb{R}$, we must choose and construct a 2-dimensional domain, then calculate the function at each point of that domain.\nThe standard tool for creating a 2-dimensional domain in the Cartesian plane is \\li{np.meshgrid()}.\nGiven two 1-dimensional coordinate arrays, \\li{np.meshgrid()} creates two corresponding coordinate matrices.\n%\n\\begin{figure}[H] % np.meshgrid() visual demonstration.\n\\begin{tikzpicture}[>=stealth', shorten <= .1cm,shorten >=.1cm, dot/.style=\n    {circle,fill=black,minimum size=3pt,inner sep=0pt, outer sep=-1pt} ]\n\n\\foreach \\x/\\y in {0/0, 0/2, 0/4, 2/0, 2/2, 2/4, 4/0, 4/2, 4/4}\n    \\node[draw, dot]at(\\x,\\y){};\n\\foreach \\x/\\y in {0/0, 0/1, 0/2, 1/0, 1/1, 1/2, 2/0, 2/1, 2/2}\n    \\node[draw=none]at(\\x*2-.5, \\y*2+.3){(\\x,\\y)};\n\n\\foreach \\x/\\y in {0/0, 0/1, 0/2, 1/0, 1/1, 1/2, 2/0, 2/1, 2/2}\n    \\node[draw=none]at(\\x*.75+7, \\y*.75+.1){\\y};\n\\foreach \\x/\\y in {0/0, 0/1, 0/2, 1/0, 1/1, 1/2, 2/0, 2/1, 2/2}\n    \\node[draw=none]at(\\x*.75+7, \\y*-.75+3.9){\\x};\n\n\\draw[-, thick](6.7,-.25)--(6.7,1.95);\n\\draw[-, thick](8.8,-.25)--(8.8,1.95);\n\\draw[-, thick](6.7,2.05)--(6.7,4.25);\n\\draw[-, thick](8.8,2.05)--(8.8,4.25);\n\\draw[-, thick](8.8,4.14)--(8.7,4.14);\n\\draw[-, thick](8.8,2.16)--(8.7,2.16);\n\\draw[-, thick](6.7,4.14)--(6.8,4.14);\n\\draw[-, thick](6.7,2.16)--(6.8,2.16);\n\\draw[-, thick](8.8,1.84)--(8.7,1.84);\n\\draw[-, thick](8.8,-.135)--(8.7,-.135);\n\\draw[-, thick](6.8,1.84)--(6.7,1.84);\n\\draw[-, thick](6.8,-.135)--(6.7,-.135);\n\n\\node[draw=none](X)at(6.3,.9){\\texttt{Y}=};\n\\node[draw=none](y)at(6.3,3.15){\\texttt{X}=};\n\n\\node[draw=none](point1)at(-.3, -.6){\\texttt{x}=\\big[0,};\n\\node[draw=none, node distance=2.35cm](point2)\n    [right of=point1]{1,};\n\\node[draw=none, node distance=2cm](point3)\n    [right of=point2]{2\\big]};\n\\node[draw=none, rotate=270](point4)at(4.6,4.25)\n    {\\texttt{y}=\\big[2,};\n\\node[draw=none, rotate=270, node distance=2.35cm](point5)\n    [right of=point4]{1,};\n\\node[draw=none, rotate=270, node distance=2cm](point6)\n    [right of=point5]{0\\big]};\n\\end{tikzpicture}\n\\caption{\\li{np.meshgrid(x, y)}, returns the arrays \\li{X} and \\li{Y}.\nThe returned arrays give the $x$- and $y$-coordinates of the points in the grid formed by \\li{x} and \\li{y}.\nSpecifically, the arrays \\li{X} and \\li{Y} satisfy \\li{(X[i,j], Y[i,j]) = (x[i],y[j])}.}\n\\label{fig:meshgrid}\n\\end{figure}\n\nWith a 2-dimensional domain, we usually visualize $f$ with two kinds of plots.\n\n\\begin{itemize}\n\\item A \\emph{heat map} assigns a color to each entry in the matrix, producing a 2-dimensional picture describing a 3-dimensional shape.\nDarker colors typically correspond to lower values while lighter colors typically correspond to higher values.\n\nUse \\li{plt.pcolormesh()} to create a heat map.\n\n\\item A \\emph{contour map} draws several \\emph{level curves} of $f$.\nA level curve corresponding to the constant $c$ is the collection of points $\\left\\{(x,y)\\mid c = f(x,y)\\right\\}$.\nColoring the space between the level curves produces a discretized version of a heat map.\nIncluding more and more level curves makes a filled contour plot look more and more like the complete, blended heat map.\n\nUse \\li{plt.contour()} to create a contour plot and \\li{plt.contourf()} to create a filled contour plot.\nSpecify either the number of level curves to draw, or a list of constants corresponding to specific level curves.\n\\end{itemize}\n\nThese three functions all receive the keyword argument \\li{cmap} to specify a color scheme (some of the better schemes are \\li{\"viridis\"}, \\li{\"magma\"}, and \\li{\"Spectral\"}).\nSee \\url{http://matplotlib.org/examples/color/colormaps_reference.html} for the list of all Matplotlib color schemes.\n\nFinally, to see how the colors in these plots relate to the values of the function, use \\li{plt.colorbar()} to draw the color scale beside the plot.\n\n\\begin{lstlisting}\n# Create a 2-D domain with np.meshgrid().\n>>> x = np.linspace(-np.pi, np.pi, 100)\n>>> y = x.copy()\n>>> X, Y = np.meshgrid(x, y)\n\n# Calculate z = f(x,y) = sin(x)sin(y) using the meshgrid coordinates.\n>>> Z = np.sin(X) * np.sin(Y)\n\n# Plot the heat map of f over the 2-D domain.\n>>> plt.subplot(131)\n>>> plt.pcolormesh(X, Y, Z, cmap=\"viridis\")\n>>> plt.colorbar()\n>>> plt.xlim(-np.pi, np.pi)\n>>> plt.ylim(-np.pi, np.pi)\n\n# Plot a contour map of f with 10 level curves.\n>>> plt.subplot(132)\n>>> plt.contour(X, Y, Z, 10, cmap=\"Spectral\")\n>>> plt.colorbar()\n\n# Plot a filled contour map, specifying the level curves.\n>>> plt.subplot(133)\n>>> plt.contourf(X, Y, Z, [-1, -.8, -.5, 0, .5, .8, 1], cmap=\"magma\")\n>>> plt.colorbar()\n\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H] % heat map and contour plots.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.33\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/heatmap.png}\n\\end{subfigure}%\n\\begin{subfigure}{.33\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/contour.pdf}\n\\end{subfigure}%\n\\begin{subfigure}{.33\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/contourf.pdf}\n\\end{subfigure}\n\\end{figure}\n\n\\begin{problem} % Heat map / contour plot of a function f:R2->R.\n\\label{prob:heatmap}\nWrite a function to plot $f(x,y) = \\frac{\\sin(x)\\sin(y)}{xy}$ on the domain $[-2\\pi,2\\pi] \\times [-2\\pi,2\\pi]$.\n\n\\begin{enumerate}\n\\item Create 2 subplots: one with a heat map of $f$, and one with a contour map of $f$.\nChoose an appropriate number of level curves, or specify the curves yourself.\n\\item Set the limits of each subplot to $[-2\\pi,2\\pi] \\times [-2\\pi,2\\pi]$.\n\\item Choose a non-default color scheme.\n\\item Include the color scale bar for each subplot.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{info} % Note about plt.imshow().\nImages are usually stored as either a 2-dimensional array (for black-and-white pictures) or a 3-dimensional array (a stack of 2-dimensional arrays, one for each RGB value).\nThis kind of data does not require a domain, and is easily visualized with \\li{plt.imshow()}.\n\\end{info}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{3-D Plotting} % --------------------------------------------------\n\nMatplotlib can also be used to plot 3-dimensional surfaces.\nThe following code produces the surface corresponding to $f(x,y) = \\sin(x)\\sin(y)$.\n\n\\begin{lstlisting}\n# Create the domain and calculate the range like usual.\n>>> x = np.linspace(-np.pi, np.pi, 200)\n>>> y = np.copy(x)\n>>> X, Y = np.meshgrid(x, y)\n>>> Z = np.sin(X)*np.sin(Y)\n\n# Draw the corresponding 3-D plot using some extra tools.\n>>> from mpl_toolkits.mplot3d import Axes3D\n>>> fig = plt.figure()\n>>> ax = fig.gca(projection='3d')\n>>> ax.plot_surface(X, Y, Z)\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H]\n    \\includegraphics[width=.7\\textwidth]{figures/surface_plot.pdf}\n\\end{figure}\n\n\\subsection*{Animations} % ----------------------------------------------------\n\nLines and other graphs can be altered dynamically to produce animations.\nFollow these steps to create a Matplotlib animation:\n%\n\\begin{enumerate}\n    \\item Calculate all data that is needed for the animation.\n    \\item Define a figure explicitly with \\li{plt.figure()} and set its window boundaries.\n    \\item Draw empty objects that can be altered dynamically.\n    \\item Define a function to update the drawing objects.\n    \\item Use \\li{matplotlib.animation.FuncAnimation()}.\n\\end{enumerate}\n\nThe submodule \\li{matplotlib.animation} contains the tools putting together and managing animations.\nThe function \\li{matplotlib.animation.FuncAnimation()} accepts the figure to animate, the function that updates the figure, the number of frames to show before repeating, and how fast to run the animation (lower numbers mean faster animations).\n\n\\begin{lstlisting}\nfrom matplotlib.animation import FuncAnimation\n\ndef sine_animation():\n    # Calculate the data to be animated.\n    x = np.linspace(0, 2*np.pi, 200)[:-1]\n    y = np.sin(x)\n\n    # Create a figure and set its window boundaries.\n    fig = plt.figure()\n    plt.xlim(0, 2*np.pi)\n    plt.ylim(-1.2, 1.2)\n\n    # Draw an empty line. The comma after 'drawing' is crucial.\n    drawing, = plt.plot([],[])\n\n    # Define a function that updates the line data.\n    def update(index):\n        drawing.set_data(x[:index], y[:index])\n        return drawing,                     # Note the comma!\n\n    a = FuncAnimation(fig, update, frames=len(x), interval=10)\n    plt.show()\n\\end{lstlisting}\n\nTry using the following function in place of \\li{update()}.\nCan you explain why this animation is different from the original?\n\n\\begin{lstlisting}\ndef wave(index):\n    drawing.set_data(x, np.roll(y, index))\n    return drawing,\n\\end{lstlisting}\n\nTo animate multiple objects at once, define the objects separately and make sure the update function returns both objects.\n\n\\begin{lstlisting}\ndef sine_cosine_animation():\n    x = np.linspace(0, 2*np.pi, 200)[:-1]\n    y1, y2 = np.sin(x), np.cos(x)\n\n    fig = plt.figure()\n    plt.xlim(0, 2*np.pi)\n    plt.ylim(-1.2, 1.2)\n\n    sin_drawing, = plt.plot([],[])\n    cos_drawing, = plt.plot([],[])\n\n    def update(index):\n        sin_drawing.set_data(x[:index], y1[:index])\n        cos_drawing.set_data(x[:index], y2[:index])\n        return sin_drawing, cos_drawing,\n\n    a = FuncAnimation(fig, update, frames=len(x), interval=10)\n    plt.show()\n\\end{lstlisting}\n\nAnimations are very useful for describing parametrized curves, as the ``speed'' of the curve is displayed.\nThe code below animates the rose curve, parametrized by the angle $\\theta \\in [0, 2\\pi]$, given by the following equations:\n%\n\\[\\begin{array}{ccc}\nx(\\theta) = \\cos(\\theta)\\cos(6\\theta), && y(\\theta) = \\sin(\\theta)\\cos(6\\theta)\n\\end{array}\\]\n\n\\begin{lstlisting}\ndef rose_animation():\n    # Calculate the parametrized data.\n    theta = np.linspace(0, 2*np.pi, 200)\n    x = np.cos(theta)*np.cos(6*theta)\n    y = np.sin(theta)*np.cos(6*theta)\n\n    fig = plt.figure()\n    plt.xlim(-1.2, 1.2)\n    plt.ylim(-1.2, 1.2)\n    plt.gca().set_aspect(\"equal\")           # Make the figure exactly square.\n\n    drawing, = plt.plot([],[])\n\n    # Define a function that updates the line data.\n    def update(index):\n        drawing.set_data(x[:index], y[:index])\n        return drawing,\n\n    a = FuncAnimation(fig, update, frames=len(x), interval=10, repeat=False)\n    plt.show()              # repeat=False freezes the animation at the end.\n\\end{lstlisting}\n\nAnimations can also be 3-dimensional.\nThe only major difference is an extra operation to set the 3-dimensional component of the drawn object.\nThe code below animates the space curve parametrized by the following equations:\n%\n\\[\\begin{array}{ccccc}\nx(\\theta) = \\cos(\\theta)\\cos(6\\theta), &&\ny(\\theta) = \\sin(\\theta)\\cos(6\\theta), &&\nz(\\theta) = \\frac{\\theta}{10}\n\\end{array}\\]\n\n\\begin{lstlisting}\ndef rose_animation_3D():\n    theta = np.linspace(0, 2*np.pi, 200)\n    x = np.cos(theta) * np.cos(6*theta)\n    y = np.sin(theta) * np.cos(6*theta)\n    z = theta / 10\n\n    fig = plt.figure()\n    ax = fig.gca(projection='3d')           # Make the figure 3-D.\n    ax.set_xlim3d(-1.2, 1.2)                # Use ax instead of plt.\n    ax.set_ylim3d(-1.2, 1.2)\n    ax.set_aspect(\"equal\")\n\n    drawing, = ax.plot([],[],[])            # Provide 3 empty lists.\n\n    # Update the first 2 dimensions like usual, then update the 3-D component.\n    def update(index):\n        drawing.set_data(x[:index], y[:index])\n        drawing.set_3d_properties(z[:index])\n        return drawing,\n\n    a = FuncAnimation(fig, update, frames=len(x), interval=10, repeat=False)\n    plt.show()\n\\end{lstlisting}\n\n\\begin{comment} % TODO: An ORIGINAL example of using widgets\n\\subsection*{Interactive Plots} % ---------------------------------------------\n\nMatplotlib plots can be made interactive by adding \\emph{widgets}.\nConsider the following example, TAKEN FROM THE MATPLOTLIB DOCS BASICALLY AHHH\n\n\\begin{lstlisting}\n>>> from matplotlib import widgets as wg\n\n>>> ax = plt.subplot(111)\n>>> plt.subplots_adjust(bottom=.25)         # Make some space for a slider bar.\n>>> t = np.arange(0., 1., .001)\n>>> a0 = 5.\n>>> f0 = 3.\n>>> s = a0 * np.sin(2 * np.pi * f0 * t)\n>>> l = plt.plot(t, s)[0]\n>>> plt.axis([0, 1, -10, 10])\n>>> axfreq = plt.axes([.25, .05, .65, .03])\n>>> axamp = plt.axes([.25, .1, .65, .03])\n\n# Make some slider bars.\n>>> sfreq = wg.Slider(axfreq, 'Freq', .1, 30., valinit=f0)\n>>> samp = wg.Slider(axamp, 'Amp', .1, 10., valinit=a0)\n>>> def update(val):                        # Function for updating the plot.\n...     amp = samp.val                          # Read from one slider.\n...     freq = sfreq.val                        # Read from the other slider.\n...     l.set_ydata(amp * np.sin(2 * np.pi * freq * t))\n...     plt.draw()                              # Refresh the plot.\n>>> sfreq.on_changed(update)                # Connect the sliders to update().\n>>> samp.on_changed(update)\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H]\n\\includegraphics[width=.7\\textwidth]{figures/interactive_plot.pdf}\n\\end{figure}\n\\end{comment}\n\n% =============================================================================\n% =============================================================================\n% Stuff to move ===============================================================\n% =============================================================================\n% =============================================================================\n\n\\begin{comment}\n\\begin{info} % IPython Notebook inline plotting (move to notebook intro)\nIf you are executing these Matplotlib commands in an IPython shell, executing the \\li{plt.show()} method will open a new window with the plot.\nIf you are using IPython Notebook, you have the option to display the plots within your notebook.\nYou may opt into this feature by running \\li{\\%matplotlib inline} or \\li{\\%matplotlib notebook} in your IPython Notebook.\nThe \\li{inline} option shows the plot, whereas the \\li{notebook} option shows the plot and provides controls to interact with the plot.\nAdditionally, when using this option, the plot is displayed after running the \\li{plt.plot()} command; the \\li{plt.show()} command is not necessary.\n\\end{info}\n\\end{comment}\n\n", "meta": {"hexsha": "07b3d3222601d93992647ccafe217674c455095a", "size": 32031, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Introduction/PlottingIntro/PlottingIntro.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Introduction/PlottingIntro/PlottingIntro.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Introduction/PlottingIntro/PlottingIntro.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 41.3837209302, "max_line_length": 269, "alphanum_fraction": 0.6690393681, "num_tokens": 9195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624259, "lm_q2_score": 0.9184802412359966, "lm_q1q2_score": 0.8436059520037928}}
{"text": "\\subsection{Green's Theorem for Circulation}\r\n\\begin{theorem}[Green's Theorem for Circulation]\r\n\tLet $C$ be a closed, counter-clockwise oriented curve in $\\mathbb{R}^2$. For any differentiable vector field,\r\n\t\\begin{equation*}\r\n\t\t\\vec{F}(x,y) = \\langle Q(x,y), R(x,y) \\rangle \\text{, } \\oint\\limits_{C}{R\\mathrm{d}x + Q\\mathrm{d}y} = \\iint\\limits_{D}{\\left(\\frac{\\partial Q}{\\partial x} - \\frac{\\partial R}{\\partial y}\\right)\\mathrm{d}x\\mathrm{d}y}\r\n\t\\end{equation*}\r\n\twhere $D$ is the interior of $C$.\r\n\\end{theorem}\r\n\\noindent\r\nOr, in more modern notation,\r\n\\begin{equation*}\r\n\t\\oint\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}} = \\iint\\limits_{D}{\\nabla\\times\\vec{F}\\mathrm{d}A}\r\n\\end{equation*}\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nThis is saying that summing up the interior of the derivative is the to summing up the boundary of the function, very similar to the FTC.\\\\\r\nOne can think of this in a physical sense as saying that the work done by the vector field in moving a particle counter-clockwise on $C$ is equal to the rotation (curl) inside of  $C$ ($D$).\\\\\r\nThis theorem also relates the idea of path independence and curl of a conservative vector field that we proved the 2D case for. The left side shows path independence and will be 0 for conservative vector fields, and the right side shows curl, which will also be 0 for conservative vector fields.\r\n\r\n\\begin{proof}[Partial Proof]\r\n\tWe will prove the 2D case, but the underlying argument is easily generalized.\r\n\t\\begin{equation*}\r\n\t\t\\oint\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}} = \\oint\\limits_{c}{\\langle P(x,y), 0 \\rangle \\cdot \\mathrm{d}\\vec{r}} + \\oint\\limits_{C}{\\langle 0, Q(x,y) \\rangle \\cdot \\mathrm{d}\\vec{r}}\r\n\t\\end{equation*}\r\n\tIf $D$ is convex, we an break $C$ into 2 curves on the same interval, $C_1$ and $C_2$ such that $C_1 : \\vec{r} \\langle x, h_1(x) \\rangle$ and $C_2 : \\vec{r} \\langle x, h_2(x) \\rangle$, where $x \\in [a,b]$.\r\n\t\r\n\t[INSERT IMAGE]\r\n\t\r\n\t\\begin{equation*}\r\n\t\t= \\int_{a}^{b}{P(x,h_1(x))\\mathrm{d}x} - \\int_{a}^{b}{P(x,h_2(x))\\mathrm{d}x}\r\n\t\\end{equation*} \\begin{equation*}\r\n\t\t= -\\int_{a}^{b}{P(x,h_2(x)) - P(x,h_1(x))\\mathrm{d}x}\r\n\t\\end{equation*} \\begin{equation*}\r\n\t\t= -\\int_{a}^{b}{P(x,y)\\rvert_{y=h_1(x)}^{y=h_2(x)}\\mathrm{d}x}\r\n\t\\end{equation*} \\begin{equation*}\r\n\t\t= -\\int_{a}^{b}{\\int_{h_1(x)}^{h_2(x)}{\\frac{\\partial P}{\\partial y}\\mathrm{d}y}\\mathrm{d}x}\r\n\t\\end{equation*} \\begin{equation*}\r\n\t\t= -\\iint\\limits_{D}{\\frac{\\partial P}{\\partial y}\\mathrm{d}A} + \\iint\\limits_{D}{\\frac{\\partial Q}{\\partial x}\\mathrm{d}A}\r\n\t\\end{equation*} \\begin{equation*}\r\n\t\t= \\iint\\limits_{D}{\\nabla \\times \\vec{F}\\mathrm{d}A}\r\n\t\\end{equation*}\r\n\\end{proof}\r\n\r\n\\noindent\r\nFor example, let's use Green's Theorem for Circulation to compute $\\oint\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}}$ where $\\vec{F} = \\langle x^2, xy + x^2 \\rangle$ and $C$ is the unit circle.\r\n\\begin{equation*}\r\n\t\\oint\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}} = \\iint\\limits_{D}{\\nabla \\times \\vec{F}\\mathrm{d}A}\t\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\nabla \\times \\vec{F} = y+2x\t\r\n\\end{equation*}\r\nSince $C$ is the unit circle, we'll evaluate the integral using polar coordinates. So \r\n\\begin{equation*}\r\n\t\\mathrm{d}A = r\\mathrm{d}r\\mathrm{d}\\theta\t\r\n\\end{equation*}\r\n\\begin{align*}\r\n\t\\iint\\limits_{D}{\\nabla \\times \\vec{F}\\mathrm{d}A} &= \\int_{0}^{2\\pi}{\\int_{0}^{1}{(r\\sin{\\theta} + 2r\\cos{\\theta})r\\mathrm{d}r}\\mathrm{d}\\theta} \\\\\r\n\t&= \\int_{0}^{2\\pi}{\\left(\\frac{\\sin{\\theta}}{3} + \\frac{2\\cos{\\theta}}{3}\\right)\\mathrm{d}\\theta} = 0\r\n\\end{align*}\r\nNote that although this particular circulation is 0, we know that the vector field is not conservative because the curl is not 0.\r\n\r\n\\input{./vectorAnalysis/areaClosedRegion}", "meta": {"hexsha": "a32e92223cb1f5f68da3865748113d3a004c8ae9", "size": 3696, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/greensTheoremCirculation.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/vectorAnalysis/greensTheoremCirculation.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/vectorAnalysis/greensTheoremCirculation.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.75, "max_line_length": 296, "alphanum_fraction": 0.663961039, "num_tokens": 1382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.9324533074525657, "lm_q1q2_score": 0.8435443907346954}}
{"text": "\\subsection{Eigenvalues \\& Eigenvectors}\r\n\\begin{definition}\r\n\tLet $A$ be an $n \\times n$ matrix. A scalar $\\lambda$ and a vector $\\vec{v}$ are an eigenvalue and eigenvector of $A$ if\r\n\t\\begin{equation*}\r\n\t\tA\\vec{v} = \\lambda\\vec{v}.\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\\noindent\r\nWe call $p(\\lambda) = \\det{(A - \\lambda I)}$ the characteristic polynomial of $A$. The eigenvalues for $A$ are the solutions to the equation\r\n\\begin{equation*}\r\n\tp(\\lambda) = \\det{(A - \\lambda I)} = 0.\r\n\\end{equation*}\r\nOnce we have an eigenvalue, we can find the basis vectors for the corresponding eigenspace by solving the equation\r\n\\begin{equation*}\r\n\t\\left( A - \\lambda I \\right)\\vec{v} = \\vec{0}.\r\n\\end{equation*}\r\nThe basis vectors of the eigenspace for $A$ are the union of the basis vectors of each eigenspace corresponding to each eigenvalue.\r\n\r\n\\begin{example}\r\n\tFind the eigenvalues and eigenvectors of\r\n\t\\begin{equation*}\r\n\t\tA = \\begin{bmatrix}\r\n\t\t\t2 & 1 & 3 \\\\\r\n\t\t\t1 & 2 & 3 \\\\\r\n\t\t\t3 & 3 & 20\r\n\t\t\\end{bmatrix}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{equation*}\r\n\tp(\\lambda) = \\begin{array}{|ccc|}\r\n\t\t2-\\lambda & 1 & 3 \\\\\r\n\t\t1 & 2-\\lambda & 3 \\\\\r\n\t\t3 & 3 & 20-\\lambda\r\n\t\\end{array} = \r\n\t-(\\lambda - 21)(\\lambda - 2)(\\lambda - 1) = 0 \\implies \\lambda = 1 \\text{, } 2 \\text{, and } 21.\r\n\\end{equation*}\r\nWhen $\\lambda = 1$,\r\n\\begin{equation*}\r\n\tA-\\lambda I = \\left[\r\n\t\\begin{array}{ccc|c}\r\n\t\t2-1 & 1 & 3 & 0 \\\\\r\n\t\t1 & 2-1 & 3 & 0 \\\\\r\n\t\t3 & 3 & 20-1 & 0\r\n\t\\end{array} \r\n\t\\right] \\to \\left[\r\n\t\\begin{array}{ccc|c}\r\n\t\t1 & 1 & 0 & 0 \\\\\r\n\t\t0 & 0 & 1 & 0 \\\\\r\n\t\t0 & 0 & 0 & 0\r\n\t\\end{array}\r\n\t\\right] \\implies \\vec{v_{1}} = t \\begin{bmatrix}\r\n\t\t-1 \\\\\r\n\t\t1 \\\\\r\n\t\t0\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nWhen $\\lambda = 2$,\r\n\\begin{equation*}\r\n\tA-\\lambda I = \\left[\r\n\t\\begin{array}{ccc|c}\r\n\t\t2-2 & 1 & 3 & 0 \\\\\r\n\t\t1 & 2-2 & 3 & 0 \\\\\r\n\t\t3 & 3 & 20-2 & 0\r\n\t\\end{array} \r\n\t\\right] \\to \\left[\r\n\t\\begin{array}{ccc|c}\r\n\t\t1 & 0 & 3 & 0 \\\\\r\n\t\t0 & 1 & 3 & 0 \\\\\r\n\t\t0 & 0 & 0 & 0\r\n\t\\end{array}\r\n\t\\right] \\implies \\vec{v_{2}} = \\begin{bmatrix}\r\n\t\t-3 \\\\\r\n\t\t-3 \\\\\r\n\t\t1\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nWhen $\\lambda = 21$,\r\n\\begin{equation*}\r\n\tA-\\lambda I = \\left[\r\n\t\\begin{array}{ccc|c}\r\n\t\t2-21 & 1 & 3 & 0 \\\\\r\n\t\t1 & 2-21 & 3 & 0 \\\\\r\n\t\t3 & 3 & 20-21 & 0\r\n\t\\end{array} \r\n\t\\right] \\to \\left[\r\n\t\\begin{array}{ccc|c}\r\n\t\t1 & 0 & -1/6 & 0 \\\\\r\n\t\t0 & 1 & -1/6 & 0 \\\\\r\n\t\t0 & 0 & 0 & 0\r\n\t\\end{array}\r\n\t\\right] \\implies \\vec{v_{21}} = \\begin{bmatrix}\r\n\t\t1 \\\\\r\n\t\t1 \\\\\r\n\t\t6\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nBonus: $A$'s diagonalization is\r\n\\begin{equation*}\r\n\tA = PDP^{-1} \\implies \\begin{bmatrix}\r\n\t\t2 & 1 & 3 \\\\\r\n\t\t1 & 2 & 3 \\\\\r\n\t\t3 & 3 & 20\r\n\t\\end{bmatrix} = \\begin{bmatrix}\r\n\t\t-1 & -3 & 1 \\\\\r\n\t\t1 & -3 & 1 \\\\\r\n\t\t0 & 1 & 6\r\n\t\\end{bmatrix} \\begin{bmatrix}\r\n\t\t1 & 0 & 0 \\\\\r\n\t\t0 & 2 & 0 \\\\\r\n\t\t0 & 0 & 21\r\n\t\\end{bmatrix} \\begin{bmatrix}\r\n\t\t-1/2 & 1/2 & 0 \\\\\r\n\t\t-3/19 & -3/19 & 1/19 \\\\\r\n\t\t1/38 & 1/38 & 3/19\r\n\t\\end{bmatrix}.\r\n\\end{equation*}", "meta": {"hexsha": "5517281295f44e5d0db5beb219a28cd139a1f24b", "size": 2899, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/vectorsMatrices/eigenvaluesEigenvectors.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/vectorsMatrices/eigenvaluesEigenvectors.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/vectorsMatrices/eigenvaluesEigenvectors.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 24.9913793103, "max_line_length": 141, "alphanum_fraction": 0.5367368058, "num_tokens": 1328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.93812402119614, "lm_q2_score": 0.8991213772699435, "lm_q1q2_score": 0.8434873619878911}}
{"text": "\n\\subsection{Expectation of OLS estimators}\n\n\\subsubsection{Expectation in terms of observables}\n\nWe have: \\(\\hat{\\theta }=(X^TX)^{-1}X^Ty\\)\n\nLet\u2019s take the expectation.\n\n\\(E[\\hat{\\theta }]=E[(X^TX)^{-1}X^Ty]\\)\n\n\\subsubsection{Expectation in terms of errors}\n\nLet\u2019s model \\(y\\) as a function of \\(X\\). As we place no restrictions on the error terms, this is not as assumption.\n\n\\(y=X\\theta +\\epsilon\\). \n\n\\(E[\\hat{\\theta }]=E[(X^TX)^{-1}X^T(X\\theta +\\epsilon)]\\)\n\n\\(E[\\hat{\\theta }]=E[(X^TX)^{-1}X^TX\\theta ]+E[(X^TX)^{-1}X^T \\epsilon)]\\)\n\n\\(E[\\hat{\\theta }]=\\theta +E[(X^TX)^{-1}X^T \\epsilon)]\\)\n\n\\(E[\\hat{\\theta }]=\\theta +E[(X^TX)^{-1}X^T]E[ \\epsilon]+cov [(X^TX)^{-1}X^T ,\\epsilon]\\)\n\n\\subsubsection{The Gauss-Markov: Expected error is \\(0\\)}\n\n\\(E[\\epsilon  =0]\\)\n\nThis means that:\n\n\\(E[\\hat{\\theta }]=\\theta + cov [(X^TX)^{-1}X^T ,\\epsilon]\\)\n\n\\subsubsection{The Gauss-Markov: Errors and indepedent variables are uncorrelated}\n\nIf the error terms and \\(X\\) are uncorrelated then \\(E[\\epsilon|X]=0\\) and therefore:\n\n\\(E[\\hat{\\theta }]=\\theta\\)\n\nSo this is an unbiased estimator, so long as the condition holds.\n\n\n", "meta": {"hexsha": "b62fd4edc23a86c4a7cc52eaaa9d51bc240add0d", "size": 1117, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/olsInference/01-01-moments.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/olsInference/01-01-moments.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/olsInference/01-01-moments.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.976744186, "max_line_length": 116, "alphanum_fraction": 0.6311548791, "num_tokens": 400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164656, "lm_q2_score": 0.8991213745668095, "lm_q1q2_score": 0.843487350119429}}
{"text": "\n\\subsection{Concave and convex functions}\n\n\\subsubsection{Convex functions}\n\nA convex function is one where:\n\n\\(\\forall x_1, x_2\\in \\mathbb{R} \\forall t \\in [0,1] [f(tx_1+(1-t)x_2 \\le tf(x_1)+(1-t)f(x_2)]\\)\n\nThat is, for any two points of a function, a line between the two points is above the curve.\n\nA function is strictly convex if the line between two points is strictly above the curve:\n\n\\(\\forall x_1, x_2\\in \\mathbb{R} \\forall t \\in (0,1) [f(tx_1+(1-t)x_2 < tf(x_1)+(1-t)f(x_2)]\\)\n\nAn example is \\(y=x^2\\).\n\n\\subsubsection{Concave functions}\n\nA concave function is an upside down convex function. The line between two points is below the curve.\n\n\\(\\forall x_1, x_2\\in \\mathbb{R} \\forall t \\in [0,1] [f(tx_1+(1-t)x_2 \\ge tf(x_1)+(1-t)f(x_2)]\\)\n\nA function is strictly concave if the line between two points is strictly below the curve:\n\n\\(\\forall x_1, x_2\\in \\mathbb{R} \\forall t \\in (0,1) [f(tx_1+(1-t)x_2 > tf(x_1)+(1-t)f(x_2)]\\)\n\nAn example is \\(y=-x^2\\).\n\n\\subsubsection{Affine functions}\n\nIf a function is both concave and convex, then the line between two points must be the function itself. This means the function is an affine function.\n\n\\(y=cx\\)\n\n", "meta": {"hexsha": "2471cdc542593afb5af04a430e856cca9ea6583e", "size": 1163, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/propertiesFunctions/01-05-analysisCon.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/propertiesFunctions/01-05-analysisCon.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/propertiesFunctions/01-05-analysisCon.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3055555556, "max_line_length": 150, "alphanum_fraction": 0.6990541702, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002789, "lm_q2_score": 0.9149009561531424, "lm_q1q2_score": 0.8434671701700166}}
{"text": "\\subsection{Quotient Rule}\r\n\\begin{lemma}\r\n\tLet $f$ and $g$ be differentiable functions where $g \\neq 0$. Then\r\n\t\\begin{equation}\r\n\t\t\\left(\\frac{f}{g}\\right)^\\prime = \\frac{gf^\\prime - fg^\\prime}{g^2}.\r\n\t\\end{equation}\r\n\\end{lemma}\r\n\\begin{proof}\r\n\tUsing the definition of the derivative and limit properties,\r\n\t\\begin{align*}\r\n\t\t\\left(\\frac{f}{g}\\right)^\\prime &= \\lim_{h\\to 0}{\\frac{\\frac{f(x+h)}{g(x+h)} - \\frac{f(x)}{g(x)}}{h}} \\\\\r\n\t\t&= \\lim_{h\\to 0}{\\frac{1}{h}\\frac{f(x+h)g(x) - f(x)g(x+h)}{g(x+h)g(x)}} \\\\\r\n\t\t&= \\lim_{h\\to 0}{\\frac{1}{h}\\hspace{3pt}\\frac{f(x+h)g(x) - f(x)g(x) + f(x)g(x) - f(x)g(x+h)}{g(x+h)g(x)}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{\\frac{1}{g(x+h)g(x)}\\hspace{3pt}\\frac{f(x+h)g(x)-f(x)g(x)+f(x)g(x)-f(x)g(x+h)}{h}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{\\frac{1}{g(x+h)g(x)}\\left(\\frac{f(x+h)g(x)-f(x)g(x)}{h}+\\frac{f(x)g(x)-f(x)g(x+h)}{h}\\right)} \\\\\r\n\t\t&= \\lim_{h \\to 0}{\\frac{1}{g(x+h)g(x)}} \\left(g(x)\\lim_{h \\to 0}{\\frac{f(x+h)-f(x)}{h}} - f(x)\\lim_{h\\to 0}{\\frac{g(x+h)-g(x)}{h}}\\right) \\\\\r\n\t\t&= \\frac{1}{g^2(x)}\\left(g(x)f^\\prime(x) - f(x)g^\\prime(x)\\right) \\\\\r\n\t\t&= \\frac{gf^\\prime - fg^\\prime}{g^2}.\r\n\t\\end{align*}\r\n\\end{proof}\r\n\r\n\\begin{example}\r\n\tGiven that the derivative of $\\sin{(x)}$ is $\\cos{(x)}$, find the derivative of $\\frac{\\sin{(x)}}{x^2}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tApplying the quotient and power rules,\r\n\t\\begin{equation*}\r\n\t\tf^\\prime(x) = \\frac{x^2\\cos{(x) - 2x\\sin{(x)}}}{x^4} = \\frac{x\\cos{(x)}-2\\sin{(x)}}{x^3}.\r\n\t\\end{equation*}\r\n\\end{answer}", "meta": {"hexsha": "c287607a16110db91bed12495b94335f304201e5", "size": 1477, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/derivative_rules/quotient_rule.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/derivatives/derivative_rules/quotient_rule.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/derivatives/derivative_rules/quotient_rule.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 49.2333333333, "max_line_length": 143, "alphanum_fraction": 0.5423155044, "num_tokens": 696, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768572945971, "lm_q2_score": 0.8933094145755219, "lm_q1q2_score": 0.8434420756455927}}
{"text": "\\subsection{Complex numbers}\nWhen Eigenmath starts up, it defines the symbol $i$ as $i=\\sqrt{-1}$.\nOther than that, there is nothing special about $i$.\nIt is just a regular symbol that can be redefined and used for some other purpose if need be.\n\nComplex quantities can be entered in either rectangular or polar form.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\na+i*b\n\\end{Verbatim}\n\n$\\displaystyle a+ib$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nexp(i*pi/3)\n\\end{Verbatim}\n\n$\\displaystyle \\exp(\\frac{1}{3}i\\pi)$\n\nConverting to rectangular or polar coordinates causes\nsimplification of mixed forms.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nA = 1+i\nB = sqrt(2)*exp(i*pi/4)\nA-B\n\\end{Verbatim}\n\n$1+i-2^{1/2}\\exp(\\frac{1}{4}i\\pi)$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nrect(last)\n\\end{Verbatim}\n\n$\\displaystyle 0$\n\nRectangular complex quantities, when raised to a power, are multiplied out.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n(a+i*b)^2\n\\end{Verbatim}\n\n$\\displaystyle a^2-b^2+2iab$\n\nWhen $a$ and $b$ are numerical and the power is negative, the evaluation is done as follows.\n$$i\n(a+ib)^{-n}\n=\\left[\\frac{a-ib}{(a+ib)(a-ib)}\\right]^n=\n\\left[\\frac{a-ib}{a^2+b^2}\\right]^n$$\nOf course, this causes $i$ to be removed from the denominator.\n%For $n=1$ we have\n%$${1\\over a+ib}={a-ib\\over a^2+b^2}$$\nHere are a few examples.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n1/(2-i)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{2}{5}+\\frac{1}{5}i$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n(-1+3i)/(2-i)\n\\end{Verbatim}\n\n$\\displaystyle -1+i$\n\nThe absolute value of a complex number returns its magnitude.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nabs(3+4*i)\n\\end{Verbatim}\n\n$\\displaystyle 5$\n\nSince symbols can have complex values, the absolute value\nof a symbolic expression is not computed.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nabs(a+b*i)\n\\end{Verbatim}\n\n$\\displaystyle {\\rm abs}(a+ib)$\n\nThe result is not $\\sqrt{a^2+b^2}$ because that would assume that\n$a$ and $b$ are real.\nFor example, suppose that $a=0$ and $b=i$.\nThen\n$$|a+ib|=|-1|=1$$\nand\n$$\\sqrt{a^2+b^2}=\\sqrt{-1}=i$$\nHence\n$$|a+ib|\\ne\\sqrt{a^2+b^2}\\quad\\hbox{for some $a,b\\in\\mathbb C$}$$\n\nThe $mag$ function can be used instead of $abs$.\nIt treats symbols like $a$ and $b$ as real.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nmag(a+b*i)\n\\end{Verbatim}\n\n$\\displaystyle (a^2+b^2)^{1/2}$\n\nThe imaginary unit can be changed from $i$ to $j$\nby defining $j=\\sqrt{-1}$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nj = sqrt(-1)\nsqrt(-4)\n\\end{Verbatim}\n\n$\\displaystyle 2j$\n", "meta": {"hexsha": "2876ffb289f16d71d62806e7df5036033eb13401", "size": 2664, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/complex.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/complex.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/complex.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.7857142857, "max_line_length": 93, "alphanum_fraction": 0.7012012012, "num_tokens": 909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172673767973, "lm_q2_score": 0.8887588052782736, "lm_q1q2_score": 0.8433585768617264}}
{"text": "\\section{Regression: OLS}\n\n\n\\formdesc{Form}\n\n\\begin{equation}\n\ty = \\beta_0 + \\beta_1 x\n\\end{equation}\n\ndescribes the true, unobserved model, while\n\n\\begin{equation}\n\t\\hat{y} = b_0 + b_1x\n\\end{equation}\n\ndescribes the estimated model. The estimate $\\hat{y}$ describes the average value around which subjects where $x = x_i$ will cluster.\n\\hformbar\n\n\n\n\\formdesc{Residuals}\n\n\\begin{equation}\n\te_i = y_i - \\hat{y}_i\n\\end{equation}\n\nis the residual of the $i$th observations $(x_i, y_i)$, the differences between the observed response $(y_i)$ and the prediction $\\hat{y}$\n\n\\hformbar\n\n\n\n\\formdesc{Correlation}\n\n\\begin{equation}\n\tr = \\frac{1}{n - 1} \\sum_{i=1}^n \\frac{x_i - \\bar{x}}{s_x} ~ \\frac{y_i - \\bar{y}}{s_y}\n\\end{equation}\n\ndescribes the strength of the linear relationship between two variables $x$ and $y$, where $0 \\leq r \\leq 1$, and $s$ is sample standard deviation\n\\hformbar\n\n\n\n\\formdesc{Least Squares Criterion}\n\n\\begin{equation}\n\t\\mathrm{arg\\,min} \\sum_{i=1}^n e_i^2  \\equiv e_1^2 + e_2^2 + \\ldots + e_n^2\n\\end{equation}\n\ndescribes the best fitting line, the \\textit{least squares line}, i.e., minimizes the sum of squared residuals. To calculate:\n\n\\begin{equation}\n\tb_1 = \\frac{s_y}{s_x} r\n\\end{equation}\n\nthen use the fact that the point $(\\bar{x}, \\bar{y})$ is on the least squares line to set $x_0 = \\bar{x}$ and $y_0 = \\bar{y}$ along with the slope $b_1$, solve for $x$ in:\n\n\\begin{equation}\n\ty - \\hat{y} = b_1 (x - \\hat{x})\n\\end{equation}\n\n\\subsection*{Assumptions}\n\n\\begin{enumerate}\n\t\\item \\textit{Linearity}. Data must show a linear trend\n\t\\item \\textit{Near normal residuals}\n\t\\item \\textit{Constant variability}. The variability of points around the least-squares line must be constant, e.g., the scale of $e$ cannot increase as $x$ increases producing a fanning pattern\n\t\\item \\textit{Independent observations}. \n\\end{enumerate}\n\n\\hformbar\n\n\n\n\\formdesc{$r^2$}\n\n\\begin{equation}\n\tr^2 = 1 - \\frac{ \\sum_{i=1}^n (y_i - \\hat{y}_i)^2 }{ \\sum_{i=1}^n (y_i - \\bar{y})^2 } = 1 - \\frac{SSE}{SST}\n\\end{equation}\n\n\\begin{itemize}\n\t\\item $SSE$ is summed squares of residuals:\n\t\\item $SSTO$ is total sum of squares\n\\end{itemize}\n\n\\hformbar\n\n\n\n\\formdesc{Regression: T-Test}\n\nTests to determine if null hypothesis $b_1 = 0$ is to be rejected\n\\hformbar\n\n\n\n\n\n\n\n\n\\newpage\n", "meta": {"hexsha": "9d105494dce86bff5005ade5569407975f28be16", "size": 2276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/ols.tex", "max_stars_repo_name": "benhorvath/math_notes", "max_stars_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/ols.tex", "max_issues_repo_name": "benhorvath/math_notes", "max_issues_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/ols.tex", "max_forks_repo_name": "benhorvath/math_notes", "max_forks_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.0970873786, "max_line_length": 195, "alphanum_fraction": 0.6924428822, "num_tokens": 796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671714, "lm_q2_score": 0.9073122226137632, "lm_q1q2_score": 0.8432926403436501}}
{"text": "%!TEX root = TTK4215-Summary.tex\n\\section{Preliminaries}\n\\subsection{Norms}\nWe say $x \\in \\mathcal{L}_p$ when $||x||_p$ exists.\n\\paragraph{General $p$-norm}\n\\begin{equation}\n\t||x||_p\n\t=\n\t\\left(\n\t\t\\int_{0}^{\\infty} |x(t)|^p \\dif t\n\t\\right)\n\t^{1/p}\n\\end{equation}\n\n\\paragraph{$\\mathcal{L}_\\infty$-norm}\n\\begin{equation}\n\t||x||_\\infty\n\t=\n\t\\sup_{t \\geq 0} |x(t)|\n\\end{equation}\n\n\n%!TEX root = TTK4215-Summary.tex\n\\subsection{Models for dynamic systems}\n\n\\begin{equation}\n\t\\V{\\dot{x}}\n\t=\n\t\\M{A} \\V{x}\n\t+\n\t\\M{B} \\V{u}\n\\end{equation}\n\n\\begin{equation}\n\t\\V{y}\n\t=\n\t\\M{C}\\T \\V{x}\n\\end{equation}\n\n\\paragraph{Controllability}\n\\begin{equation}\n\t\\M{P}_c\n\t\\triangleq\n\t\\begin{bmatrix}\n\t\t\\M{B} \\\\ \\M{AB} \\\\ \\vdots \\\\ \\M{A}^{n-1}\\M{B}\n\t\\end{bmatrix}\n\\end{equation}\n\nIf $\\M{P}_c$ is nonsingular, the system is controllable, and can be transformed to the \\emph{controllability canonical form} by\n\\begin{equation}\n\t\\V{x}_c\n\t=\n\t\\M{P}_c^{-1} \\V{x}\n\\end{equation}\n\n\\paragraph{Properness}\nA transfer function $\\M{G}(s) = \\frac{\\M{N}(s)}{\\M{D}(s)}$ is\n\\begin{itemize}\n\t\\item \\emph{proper} if $\\deg(\\M{N}) \\leq \\deg(\\M{D})$,\n\t\\item \\emph{biproper} if $\\deg(\\M{N}) = \\deg(\\M{D})$,\n\t\\item \\emph{stricly proper} if $\\deg(\\M{N}) < \\deg(\\M{D})$.\n\\end{itemize}\n\n\\subsection{Transfer function properties}\nConsider the polynomial\n\\begin{equation}\n\tX(s) = \\alpha_n s^n + \\alpha_{n-1} s^{n-1} + \\cdots + \\alpha_0\n\\end{equation}\nand the transfer function\n\\begin{equation}\n\tG(s) = \\frac{Z(s)}{R(s)}\n\t.\n\\end{equation}\n\n\\paragraph{Monic:} $X(s)$ is \\emph{monic} iff $\\alpha_n = 1$.\n\n\\paragraph{Hurwitz:} $X(s)$ is \\emph{Hurwitz} if all roots of $X(s) = 0$ are in the left half plane.\n\n\\paragraph{Minimum phase:} A system defined by the t.f. $G(s)$ is \\emph{minimum phase} iff $Z(s)$ is Hurwitz.\n\n\\paragraph{Stability:} A system defined by the t.f. $G(s)$ is \\emph{stable} if $R(s)$ is Hurwitz.\n\n\\paragraph{Coprime:} Two polynomials are \\emph{coprime} if they have no common factors other than a constant.\n\n\\subsection{(Strictly) positive real transfer functions}\n\n\\subsection{Positive Real (PR)}\n\\paragraph{Definition 3.5.1}\nA rational function $G(s)$ of the complex variable $s=\\sigma + j\\omega$ is called PR if\n\\begin{itemize}\n\t\\item $G(s)$ is real for real $s$\n\t\\item $\\Re[G(s)] \\geq 0 \\quad \\forall \\quad \\sigma > 0$\n\\end{itemize}\n\n\\paragraph{Lemma 3.5.1}\nA rational proper transfer function $G(s)$ is PR iff\n\\begin{itemize}\n\t\\item $G(s)$ is real for real $s$\n\t\\item $G(s)$ is analytic in $\\Re[s] \\geq 0$, and the poles on the $j\\omega$-axis are simple and such that the associated residues are real and positive.\n\t\\item For all real value $\\omega$ for which $s = j \\omega$ is not a pole of $G(s)$, one has $\\Re[G(j\\omega)]$\n\\end{itemize}\n\n\\subsection{Strict Positive Real (SPR)}\n\\paragraph{Definition 3.5.2}\nAssume $G(s)$ is not identically zero for all $s$. Then $G(s)$ is SPR if $G(s-\\epsilon)$ is PR for some $\\epsilon > 0$.\n\n\\paragraph{Theorem 3.5.2}\n(Necessary and sufficient conditions.) Assume that a rational function $G(s)$ of the complex variable $s = \\sigma + j\\omega$ is real for real $s$ and is not identically zero for all $s$. Let $n^*$ be the relative degree of $G(s) = Z(s) / R(s)$ with $|n^*| \\leq 1$. Then, $G(s)$ is SPR iff\n\\begin{itemize}\n\t\\item $G(s)$ is analytic for $\\sigma \\geq 0$\n\t\\item $\\Re[G(j\\omega)] > 0 \\quad \\forall \\quad \\omega$\n\t\\item When $n^* = 1, \\quad \\lim_{|\\omega| \\to \\infty} \\omega \\Re[G(j\\omega)] > 0 $\n\t\\item When $n^* = -1,\\quad \\lim_{|\\omega| \\to \\infty} \\frac{G(j\\omega)}{j\\omega} >0 $\n\\end{itemize}\n\n\\paragraph{Corollary 3.5.1}\n\\begin{itemize}\n\t\\item $G(s)$ is PR/SPR iff $1/G(s)$ is PR/SPR\n\t\\item If $G(s)$ is SPR, then, $|n^*| \\leq 1$, and the zeros and poles of $G(s)$ lie in $\\Re[s]<0$.\n\t\\item When $n^* = 1, \\quad \\lim_{|\\omega| \\to \\infty} \\omega \\Re[G(j\\omega)] > 0 $\n\t\\item When $n^* = -1,\\quad \\lim_{|\\omega| \\to \\infty} \\frac{G(j\\omega)}{j\\omega} >0 $\n\\end{itemize}\n\n\\paragraph{KYP Lemma (3.5.2)}\nGiven a square matrix $A$ with eigenvalues $\\Re(\\lambda) \\leq 0$, a vector $B$ such that $(A,B)$ controllable, a vector $C$, and scalar $d \\geq 0$, then the t.f.\n\\begin{equation}\n\tG(s) = d + C\\T (s \\mathrm{I} - A)^{-1} B\n\\end{equation}\nis PR iff $\\exists$ a symmetric pos. def. matrix $P$ and a vector $q$ such that\n\\begin{gather}\n\tA\\T P + P A = -q q\\T \\\\\n\tP B - C = \\pm \\sqrt{2d} \\cdot q\n\t.\n\\end{gather}\n\n\\paragraph{LKY Lemma (3.5.3)}\nGiven a stable matrix $A$, a vector $B$ such that $(A,B)$ controllable, a vector $C$ and a scalar $d \\geq 0$, then the t.f.\n\\begin{equation}\n\tG(s) = d + C\\T (s \\mathrm{I} - A)^{-1} B\n\\end{equation}\nis SPR iff for any pos. def. matrix $L$, $\\exists$ a symmetric pos. def. matrix $P$, a scalar $\\nu > 0$ and a vector $q$ such that\n\\begin{gather}\n\tA\\T P + P A = -q q\\T - \\nu L \\\\\n\tP B - C = \\pm q \\sqrt{2d}\n\t.\n\\end{gather}\n\n\\paragraph{MKY Lemma (3.5.4)}\nGiven a stable matrix $A$, vectors $B,C$, and a scalar $d \\geq 0$, we have: If\n\\begin{equation}\n\tG(s) = d + C\\T (s \\mathrm{I} - A)^{-1} B\n\\end{equation}\nis SPR, then for any $L = L\\T > 0$, $\\exists$ a scalar $\\nu > 0$, a vector $q$ and a $P = P\\T > 0$ such that\n\\begin{gather}\n\tA\\T P + P A = -q q\\T - \\nu L \\\\\n\tP B - C = \\pm q \\sqrt{2d}\n\t.\n\\end{gather}", "meta": {"hexsha": "2b3aad6c5ef4594117b272382a398cf4e3e6e718", "size": 5158, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4215 System identification and adaptive control/sec-preliminaries.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TTK4215 System identification and adaptive control/sec-preliminaries.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TTK4215 System identification and adaptive control/sec-preliminaries.tex", "max_forks_repo_name": "jakoblover/ntnu-course-summaries", "max_forks_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6455696203, "max_line_length": 288, "alphanum_fraction": 0.6297014347, "num_tokens": 2033, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.9005297847831081, "lm_q1q2_score": 0.8431525379239772}}
{"text": "\\section{Norm and distance}\n\\subsection{Norm} \n\\textit{Euclidean norm} (or just norm) is\\\\\n$||x||= \\sqrt{x_1^2+x_2^2+...+x_n^2}= \\sqrt{x^Tx}$\\\\\n\\textbf{Properties}\\\\\n\\textbullet homogeneity: $||\\beta x|| = |\\beta ||x|||$\\\\\n\\textbullet triangle inequality: $||x + y|| \\leq ||x|| + ||y||$\\\\\n\\textbullet non negativity: $||x|| \\geq 0$\\\\\n\\textbullet definiteness: $||x|| = 0$ only if x = 0\\\\\n\\textit{positive definiteness} = non negativity + definiteness\\\\\n\\textbf{rms}(x) = $\\sqrt{\\frac{x_1^2+...+x_n^2}{n}} = \\frac{||x||}{\\sqrt{n}}$ \\\\\n\\textbullet \\textit{Norm of a sum}:\\\\ \n$\\Vert a + b \\Vert^2 = (x + y)^T(x + y) = \\Vert x \\Vert^2 + 2x^Ty + \\Vert b \\Vert^2$\\\\\n\\textbf{Norm of block vectors}\n$||(a,b,c)|| = \\sqrt{||a||^2 + ||b||^2 + ||c||^2} = ||(||a||, ||b||, ||c||)||$\\\\\n\\textbf{Chebyshev inequality}\nk of its entries satisfy $|x_i| \\geq a$, \\\\then $\\frac{k}{n} \\leq (\\frac{\\textbf{rms}(x)}{a})^2$\n\\subsection{Distance}\n$\\textbf{dist}(a,b) = ||a - b||$\\\\\n\\textit{Triangle Inequality}: $||a - c||^2 = ||(a - b) + (b - c)|| \\leq ||a-b|| + ||b-c||$\\\\\n$z_j$ is the nearest neighbor of x if $||x-z_j|| \\leq ||x-z_i||, i=1,..,m$\\\\\n\n\\subsection{Standard Deviation}\nde-meaned vector: $\\tilde{x} = x - \\textbf{avg}(x)\\textbf{1}$\\\\\nstandard deviation: \\\\\\textbf{std}(x) = \\textbf{rms}($\\tilde{x}$) = $\\frac{||x - (\\textbf{1}^Tx/n)\\textbf{1}||}{\\sqrt{n}}$\\\\\n${\\textbf{rms}(x)}^2 = {\\textbf{avg}(x)}^2 + {\\textbf{std}(x)}^2$\\\\\nBy Chebyshev inequality, $|x_i - \\textbf{avg}(x)| \\geq \\alpha \\textbf{std}(x)$ then $k/n \\leq (std(x)/a)^2$. (This inequality is only interesting for $a > std(x)$) \\\\\n\\textit{Cauchy\u2013Schwarz inequality}: $|a^Tb| \\leq \\Vert a\\Vert \\Vert b \\Vert$\n\\subsection{Angle}\nangle between two nonzero vectors a, b defined as\\\\\n$\\angle(a,b) = arccos(\\frac{a^Tb}{\\Vert a \\Vert \\Vert b \\Vert})$\\\\\n$a^Tb = \\Vert a \\Vert \\Vert b \\Vert cos (\\angle(a,b))$\\\\\n\\textbf{Classification of angles}\\\\\n\n$\\theta = \\pi/2$: $a \\perp b$\\\\\n$\\theta = 0$: $a^Tb = \\Vert a \\Vert \\Vert b \\Vert$\\\\\n$\\theta = \\pi = 180^{\\circ}$ : $a^Tb = -\\Vert a \\Vert \\Vert b\\Vert$\\\\\n$\\theta \\leq \\pi/2 = 90^{\\circ} = a^Tb \\geq 0$\\\\\n$\\theta \\geq \\pi/2 = 90^{\\circ} = a^Tb \\leq 0$\\\\\n\\textbf{Correlation Coeficient ($\\rho$)}\n$\\rho = \\frac{\\tilde{a}^T\\tilde{b}}{\\Vert\\tilde{a}\\Vert\\Vert\\tilde{b}\\Vert}$\\\\\nWith $u = \\tilde{a}/\\textbf{std}(a)$ \\& $u = \\tilde{b}/\\textbf{std}(b)$, \\\\\n$\\rho = u^Tv/n$ where $\\Vert u \\Vert = \\Vert v \\Vert = n$\\\\\n\n$std(a+b) = \\\\\n\\sqrt{std(a)^2+ 2\\rho std(a)std(b) +std(b)^2}$\\\\\n\\textbf{Properties of standard deviation}\\\\\n\\textbullet  $\\textbf{std}(x+a1) = \\textbf{std}(x)$\\\\\n\\textbullet $\\textbf{std}(ax) = |a| std(x)$\\\\\n\\textbf{Standardization}\n$z = \\frac{1}{\\textbf{std}(x)}(x - \\textbf{avg}(x)\\textbf{1})$\n\n\\subsection{Complexity}\n\\textbullet \\textit{norm}: 2n\\\\\n\\textbullet \\textit{\\textbf{rms}}: 2n\\\\\n\\textbullet \\textit{\\textbf{dist}(a,b)}: 3n\\\\\n\\textbullet \\textit{$\\angle(a,b)$}: 6n\\\\\n", "meta": {"hexsha": "7ed3a3b53092e43a5a5b522df93e7affc47f84e3", "size": 2882, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter3.tex", "max_stars_repo_name": "meanmachin3/COT5615", "max_stars_repo_head_hexsha": "fa14d5a297b10e79cdc69e9aee67f8a1744d9340", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-10-03T00:00:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-26T00:44:47.000Z", "max_issues_repo_path": "cheatsheet/inhalt/chapter3.tex", "max_issues_repo_name": "meanmachin3/COT5615", "max_issues_repo_head_hexsha": "fa14d5a297b10e79cdc69e9aee67f8a1744d9340", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter3.tex", "max_forks_repo_name": "meanmachin3/COT5615", "max_forks_repo_head_hexsha": "fa14d5a297b10e79cdc69e9aee67f8a1744d9340", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-10-01T14:09:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-11T20:02:53.000Z", "avg_line_length": 49.6896551724, "max_line_length": 166, "alphanum_fraction": 0.5801526718, "num_tokens": 1242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.9005297861178929, "lm_q1q2_score": 0.8431525327696192}}
{"text": "\\section{First and Second Derivative Tests}\r\n\\subsection{First Derivative Test}\r\nAs we saw in previous sections, we can use the first derivative to find critical values, which allow us to find extrema.\r\n\\begin{theorem}[First Derivative Test]\r\n\tLet $f(x)$ be a continuous function.\r\n\tAt a critical point $c$,\r\n\t\\begin{enumerate}\r\n\t\t\\item If $f^\\prime$ changes sign from positive to negative ($f^\\prime(x) > 0$ for $x < c$ and $f^\\prime(x) < 0$ for $x > c$), then $f$ has a local maximum at $c$.\r\n\t\t\\item If $f^\\prime$ changes sign from negative to positive ($f^\\prime(x) < 0$ for $x < c$ and $f^\\prime(x) > 0$ for $x > c$), then $f$ has a local minimum at $c$.\r\n\t\t\\item If $f^\\prime$ does not change sign at $c$, then $f$ does not have a local extrema at $c$.\r\n\t\t\\item At a left endpoint $a$, if ($f^\\prime < 0$ / $f^\\prime > 0$), then $f$ has a local (maximum / minimum) at $a$.\r\n\t\t\\item At a right endpoint $b$, if ($f^\\prime < 0$ / $f^\\prime > 0$), then $f$ has a local (minimum / maximum) at $b$.\r\n\t\\end{enumerate}\r\n\\end{theorem}\r\n\r\n\\begin{example}\r\n\tFind the local extrema of $f(x) = x^3 - 12x - 5$.\r\n\tIdentify any absolute extrema.\r\n\\end{example}\r\n\\begin{answer}\r\n\tTaking the derivative,\r\n\t\\begin{equation*}\r\n\t\tf^\\prime(x) = 3x^2 - 12 = 3(x+2)(x-2).\r\n\t\\end{equation*}\r\n\t\r\n\tSo, the critical values are $x=-2$ and $x=2$.\r\n\t$f^\\prime$ is negative between these values and positive outside of them, so $x=-2$ is a local maximum, while $x=2$ is a local minimum.\r\n\t\\begin{equation*}\r\n\t\tf(-2) = 11 \\text{ and } f(2) = -21.\r\n\t\\end{equation*}\r\n\t\r\n\tAs $x$ approaches $\\infty$ (the right endpoint), $f$ also approaches $\\infty$, so there is no absolute maximum.\r\n\tSimilarly, as $x$ approaches $-\\infty$ (the left endpoint), $f$ also approaches $-\\infty$, so there is no absolute minimum.\r\n\\end{answer}\r\n\r\n\\subsection{Second Derivative Test}\r\nThe second derivative tells us how the derivative is changing.\r\nWhether the derivative is increasing or decreasing describes the concavity.\r\n\\begin{definition}\r\n\tOn some open interval $I$, the graph of a twice differentiable function $f(x)$ is\r\n\t\\begin{enumerate}\r\n\t\t\\item Concave up if $f^{\\prime\\prime} > 0$ on $I$.\r\n\t\t\\item Concave down if $f^{\\prime\\prime} < 0$ on $I$.\r\n\t\\end{enumerate}\r\n\\end{definition}\r\n\r\n\r\nConcave up portions of a graph tend to look like valleys, while concave down portions tend to look like hills.\r\nUnlike the first derivative, we can tell if a function is increasing or decreasing using concavity.\r\nWe can however say if the function is increasing or decreasing more or less rapidly.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{mvt}\r\n\t\\centering\r\n\t\\includegraphics[width = 0.5\\textwidth]{./applications_derivative/concavity.png}\r\n\t\\caption{\\hyperref{https://tutorial.math.lamar.edu/classes/calci/shapeofgraphptii.aspx}{}{}{Paul's Online Notes - The Shape of a Graph, Part II}}\r\n\\end{figure}\r\n\r\n\r\nThe points where a function changes concavity are called \"inflection points\".\r\nAt these points, the function is increasing or decreasing most rapidly, depending on the sign of the first derivative.\r\n\r\n\r\nRather than looking at the sign of $f^\\prime$ around critical values, we can look at the concavity at the critical point.\r\n\\begin{theorem}[Second Derivative Test]\r\n\tLet $c$ be a critical value of $f$.\r\n\t\\begin{enumerate}\r\n\t\t\\item If $f^{\\prime\\prime}(c) < 0$, then $c$ is a local maximum.\r\n\t\t\\item If $f^{\\prime\\prime}(c) > 0$, then $c$ is a local minimum.\r\n\t\t\\item If $f^{\\prime\\prime}(c) = 0$, then the test is inclusive.\r\n\t\\end{enumerate}\r\n\\end{theorem}\r\n\r\nIn other words, if we're at a critical point that's turning into a valley, then the critical point must be the top of a hill.\r\nIf we're at a critical point that's turning into a hill, then the critical point must be the bottom of a valley.\r\nThis test is particularly useful because you only need to know $f^{\\prime\\prime}$ at $c$ rather than an entire interval\\footnote{It also extends to higher dimensions much better than the first derivative test.}.\r\n\r\n\\begin{example}\r\n\tUse the second derivative test to find the local extreme values of $f(x) = x^3 - 12x - 5$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tFinding critical values,\r\n\t\\begin{align*}\r\n\t\tf^\\prime(x) &= 3x^2 - 12 = 3(x+2)(x-2). \\\\\r\n\t\tf^\\prime(x) &= 0\\text{ at } x=-2, x=2.\r\n\t\\end{align*}\r\n\t\r\n\tTaking the second derivative,\r\n\t\\begin{equation*}\r\n\t\tf^{\\prime\\prime}(x) = 6x.\r\n\t\\end{equation*}\r\n\t\r\n\tEvaluating the second derivative at the critical values,\r\n\t\\begin{equation*}\r\n\t\tf^{\\prime\\prime}(-2) = -12 \\text{ and } f^{\\prime\\prime}(2) = 12.\r\n\t\\end{equation*}\r\n\t\r\n\tSo, $x=-2$ is a local maximum and $x=2$ is a local minimum.\r\n\\end{answer}", "meta": {"hexsha": "dc2353bed1a577099913477f9e11f8dc3765710e", "size": 4602, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/applications_derivative/first_second_derivative_test.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/applications_derivative/first_second_derivative_test.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/applications_derivative/first_second_derivative_test.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.4848484848, "max_line_length": 212, "alphanum_fraction": 0.6823120382, "num_tokens": 1412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.936285003525698, "lm_q1q2_score": 0.8431525264719533}}
{"text": "\\section*{Exercise 20.3-5}\n\\subsection*{Running times for the modified operations}\n\nThe recursive procedures that implement the vEB tree operations have running times characterized by the recurrence\n$$\nT(u) \\leq T(u^{1/k}) + T(u^{1-1/k}) + O(1),\n$$\nwhere the first part is due to the number of clusters, and the second part is due to the size of the clusters, which are enumerated.\n\\\\\nBy letting $m=\\lg u$, such that $u=2^m$, then\n$$\nT(2^m) \\leq T(2^{m/k}) + T(u^{m-m/k}) + O(1)\n$$\nWe then rename $S(m)=T(2^m)$, which results in\n$$\nS(m) \\leq S(m/k) + S(m-m/k) + O(1) = S(m/k) + S\\left(\\frac{m(k-1)}{k}\\right) + O(1)\n$$\nFor $k>2$, the second part will dominate, so in terms of running time, we can \"ignore\" the first term. In this case, case 2 of the master theorem applies, and $S(m)$ has the solution $S(m)=O(\\lg m)$.\nBy changing back, we can conclude, that\n$$\nT(u) = T(2^m) = S(m) = O(\\lg m) = O(\\lg\\lg u)\n$$", "meta": {"hexsha": "46b5b51739210df03f1eacb1f460ad9975ff2c25", "size": 910, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge3/Ex.20.3-5.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge3/Ex.20.3-5.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge3/Ex.20.3-5.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.3636363636, "max_line_length": 199, "alphanum_fraction": 0.6428571429, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9724147209709196, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.8431183464627682}}
{"text": "\\chapter{Metric Definitions}\n\n\\section{Pixel Error}\nGiven two images, pixel error is defined as the mean of the absolute numerical distance between corresponding pixels in both images. Formally, we define:\n\n$$P(X, Y) = \\frac{\\sum_{\\bm{i} \\in S}{|X_{\\bm{i}} - Y_{\\bm{i}}|}}{|S|}$$\nfor tensors $X$ and $Y$ over all indexes $\\bm{i}$ in the index space $S$ for tensors $X$ and $Y$.\n\n\\section{Rand Score}\n\nThe version of the Rand Score used in this thesis is the Rand F Score. The Rand F Score essentially counts all the non-distinct pairs in an image that are correctly labeled as belonging to the same or different grouping with respect to a reference image. Formally, we define $S_1, S_2, ... S_n \\subseteq S$ to be the set of all groupings $S_i$ in an input volume (i.e. distinct labels in a segmentation)m and $T_1, T_2, ... T_n \\subseteq T$ to be the set of all groupings $T_i$ in a ground-truth volume. Let:\n\n$$ t_i = |T_i| $$\n$$ s_i = |S_i| $$\n$$ c_{i,j} = |S_i \\cap T_j| $$\n\nThen, the Rand F Score can be defined as:\n\n$$R_{\\mathsf{Full}}(S,T) = \\frac{\\sum_{i,j}{c_{i,j}}}{\\alpha \\sum_{i}{s_i^2} + (1 - \\alpha)\\sum_j{t_i^2}}$$ \n\n$$R_{\\mathsf{Merge}}(S,T) = \\frac{\\sum_{i,j}{c_{i,j}}}{\\sum_{i}{s_i^2}}$$  \n\n$$R_{\\mathsf{Split}}(S,T) = \\frac{\\sum_{i,j}{c_{i,j}}}{\\sum_{j}{t_j^2}}$$  \n\n\nwhere $N$ is the number of voxels in a volume. See \\url{https://github.com/seung-lab/segascorus/blob/master/segerror-manual.pdf} for more details of the Rand F Score.\n\n\\section{Cross Correlation}\n\nGiven two images, cross-correlation is defined as the mean of the prodiuct of corresponding pixels in both images. Formally, we define:\n\n$$C(X, Y) = \\frac{\\sum_{\\bm{i} \\in S}{|X_{\\bm{i}} \\times Y_{\\bm{i}}|}}{|S|}$$\nfor tensors $X$ and $Y$ over all indexes $\\bm{i}$ in the index space $S$ for tensors $X$ and $Y$.\n\n\\subsection{Smoothed Version}\n\nBecause standard Cross Correlation is not particularly continuous (i.e. two images will typically be highly correlated if they match exactly, and loosely correlated if they are translated or rotated), we define a somewhat more smoothed version that attempts to make the function more continuous. We define the function:\n\n$$C_s(X, Y) = \\frac{\\sum_{\\bm{i} \\in S}{|X_{\\bm{i}} \\times (G_{\\theta}(Y))_{\\bm{i}}|}}{|S|}$$\nfor tensors $X$ and $Y$ over all indexes $\\bm{i}$ in the index space $S$ for tensors $X$ and $Y$. The function $G_{\\theta}(\\cdot)$ is a smoothing function, which applies a Gaussian filter to its arguments based on parameters $\\theta$. The amount of smoothing that occurs determines how dontinuous the smoothed cross-correlation function is. Because the continuity of this function can be controlled, it makes for a more-useful loss function than standard Cross Correlation.", "meta": {"hexsha": "6786724bf84f5be1816a2f5cbc41d95f14ee5f3e", "size": 2717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/appendix.tex", "max_stars_repo_name": "beneisner/ugrad-thesis", "max_stars_repo_head_hexsha": "b6c819acca262e8578e638c43be8115447bdcdbf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/appendix.tex", "max_issues_repo_name": "beneisner/ugrad-thesis", "max_issues_repo_head_hexsha": "b6c819acca262e8578e638c43be8115447bdcdbf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/appendix.tex", "max_forks_repo_name": "beneisner/ugrad-thesis", "max_forks_repo_head_hexsha": "b6c819acca262e8578e638c43be8115447bdcdbf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.925, "max_line_length": 508, "alphanum_fraction": 0.7007729113, "num_tokens": 823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9744347838494567, "lm_q2_score": 0.865224072151174, "lm_q1q2_score": 0.843104431727976}}
{"text": "\\section{Theory}\n\\label{sec:theory}\n\n\\subsection{Gradient Descent}\nThe aim of Stochastic Gradient Descent is to minimize the neural network' cost function with respect to its weights.\nThe algorithm initializes the weights to random values.\nThen, it iteratively select some training example $\\nu$ from the training dataset $\\mathbb{D}_{train}$ and updates the weights by some fraction $\\eta$ (usually called learning rate) of the gradient $\\nabla_{w_j} e^\\nu$ of the cost function $e^\\nu$ with respect to the network's weights $w_j$:\n\\begin{equation}\n    \\label{eq:weights-update}\n    w_j \\leftarrow w_j - \\eta \\cdot \\nabla_{w_j} e^\\nu.\n\\end{equation}\n\nIn order to use this iterative procedure, we need to define a proper cost function for the regression problem.\nA common choice is to use the squared error for the current example $\\varepsilon^\\nu$:\n\\begin{equation}\n    \\label{eq:cost}\n    e^\\nu = \\frac{1}{2} (\\sigma(\\varepsilon^\\nu) - \\tau(\\varepsilon^\\nu))^2,\n\\end{equation}\nwhere $\\tau(\\varepsilon^\\nu))$ denotes the correct prediction for the current example.\n\nAnother possibility is to use all training examples (or a batch of them) to perform a single update, i.e. using the following cost function instead of $e$:\n\\begin{equation}\n    \\label{eq:cost-total}\n    E = \\frac{1}{2} \\frac{1}{M} \\sum_{\\mu = 1}^{M} (\\sigma(\\varepsilon^\\mu) - \\tau(\\varepsilon^\\mu))^2.\n\\end{equation}\nIn this case, we usually talk of Gradient Descent (or Batch Gradient Descent) instead of Stochastic Gradient Descent.\n\n\\subsection{Gradient Computation}\nThe hidden units in out network take as input the training examples $\\varepsilon$ and use the hyperbolic tangent as the activation function:\n\\begin{equation}\n    g(\\varepsilon) = tanh(w \\cdot \\varepsilon)\n\\end{equation}\n\nSince we have only $2$ hidden units and the output unit simply computes the sum of the outputs of the hidden layer, the final predicted value is computed as:\n\\begin{equation}\n    \\sigma (\\varepsilon) = tanh(w_1 \\cdot \\varepsilon) + tanh(w_2 \\cdot \\varepsilon),\n\\end{equation}\nwhere $w_1$ and $w_2$ are the weights' vectors.\n\nThe gradient of the cost function defined in \\cref{eq:cost} with respect to the weights $w_j$ for a single hidden unit $j$ can be computed as follows:\n\\begin{equation}\n    \\label{eq:gradient-gen-weight}\n    \\begin{split}\n        \\nabla_{w_j} e^\\nu =\\; & (tanh(w_1 \\cdot \\varepsilon^\\nu) + tanh(w_2 \\cdot \\varepsilon^\\nu) - \\tau(\\varepsilon^\\nu)) \\; \\cdot \\\\\n        & \\cdot (1 - tanh^2(w_j \\cdot \\varepsilon^\\nu)) \\cdot \\varepsilon^\\nu\n    \\end{split}\n\\end{equation}\n", "meta": {"hexsha": "96de672bfcf6f28c09e07aa274c991404d413689", "size": 2551, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_3/report/02_theory.tex", "max_stars_repo_name": "davidepedranz/neural_networks_assignments", "max_stars_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_3/report/02_theory.tex", "max_issues_repo_name": "davidepedranz/neural_networks_assignments", "max_issues_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_3/report/02_theory.tex", "max_forks_repo_name": "davidepedranz/neural_networks_assignments", "max_forks_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.1458333333, "max_line_length": 292, "alphanum_fraction": 0.7240297922, "num_tokens": 748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191259110588, "lm_q2_score": 0.8824278664544912, "lm_q1q2_score": 0.8430002180608651}}
{"text": "\\chapter{The Dot Product}\n% Reference for diagrams:https://www.mathsisfun.com/algebra/vectors-dot-product.html\n\nIf you have two vectors $u = [u_1, u_2, \\dots, w_n]$ and $v = [v_1, v_2,\\dots, v_n]$ , \nwe define the \\newterm{dot product} $u \\cdot v$ as \n\\begin{equation*}\n     u \\cdot v = (u_1 \\times v_1) + (u_2 \\times v_2) + \\dots + (u_n \\times v_n)\n\\end{equation*} \n\nSo, for example, \n\\begin{equation*}\n    [2,4, -3] \\cdot [5, -1, 1] = 2 \\times 5 + 4 \\times -1 + -3 \\times 1 = 3\n\\end{equation*}\\index{dot product}\n\nThis may not seem like a very powerful idea, but dot products are \\emph{incredibly} useful. \nThe enormous GPUs(Graphics Processing Unit) that let video games render scenes so quickly? \nThey are primarily function by computing huge numbers of dot products at mind-boggling speeds. \n\n\\begin{Exercise}[title={Basic dot products}, label=dot_products]\n    Compute the dot product of each pair of vectors:\n    \\begin{itemize}\n        \\item $[1, 2, 3]$, $[4, 5, -6]$\n        \\item $[\\pi, 2\\pi]$, $[2, -1]$\n        \\item $[0,0,0,0]$, $[10,10,10,10]$\n    \\end{itemize}\n\\end{Exercise}\n\\begin{Answer}[ref=dot_products]\n        \\begin{itemize}\n            \\item $[1, 2, 3] \\cdot [4, 5, -6] = 4 + 10 - 18 = -4$\n            \\item $[\\pi, 2\\pi] \\cdot [2, -1] = 2\\pi - 2\\pi = 0$\n            \\item $[0,0,0,0] \\cdot [10,10,10,10] = 0 + 0 + 0 + 0 = 0$ \n        \\end{itemize}\n\\end{Answer}\n\n\\section{Properties of the dot product}\n\nSometimes we need an easy way to say ``The vector of appropriate length is filled with zeros.''\nWe use the notation $\\vec{0}$ to represent this. Then, for any vector $v$, this is true:\n\n$$v \\cdot \\vec{0} = 0$$\n\nThe dot product is commutative:\n\n$$v \\cdot u = u \\cdot v$$\n\nThe dot product of a vector with itself is its magnitude squared:\n\n$$ v \\cdot v = |v|^2 $$\n\nIf you have a scalar $a$ then:\n\n    $$(v) \\cdot (a u) = a (v \\cdot u)$$\n\nSo, if $v$ and $w$ are vectors that go in the same direction,\n\n    $$v \\cdot w = |v| |w|$$\n\nIf $v$ and $w$ are vectors that go in opposite directions,\n\n    $$v \\cdot w = -|v| |w|$$\n\n\\section{Cosines and dot products}\n\nFurthermore, dot products' interaction with cosine makes them even more useful is what makes them so useful: \nIf you have two vectors $v$ and $u$,\n\n$$v \\cdot u = |v| |u| \\cos \\theta$$\n\nwhere $\\theta$ is the angle between them.\n\nSo, for example, if two vectors $v$ and $u$ are perpendicular, the angle between them is $\\pi/2$.  \nThe cosine of $\\pi/2$ is 0: The dot product of any two perpendicular vectors is always 0. In fact, if \nthe dot product of two non-zero vectors is 0, the vectors \\textit{must be} perpendicular.\n% diagram needed \n\n\\begin{Exercise}[title={Using dot products}, label=cos_dot_products]\n    What is the angle between these each pair of vectors:\n    \\begin{itemize}\n        \\item $[1, 0]$, $[0, 1]$\n        \\item $[3,4]$, $[4,3]$\n    \\end{itemize}\n\\end{Exercise}\n\\begin{Answer}[ref=cos_dot_products]\n        \\begin{itemize}\n            \\item $[1,0] \\cdot [0,1] = 0$.  The angle must be $\\pi/2$.\n            \\item $[3,4] \\cdot [4, 3] = 24$. $|[3,4]| |[4,3]| \\cos(\\theta) = 24$. \n            $\\cos(\\theta) = \\frac{24}{(5)(5)}$. $\\theta = \\arccos(\\frac{24}{25}) \\approx 0.284 \\text{ radians}$.\n        \\end{itemize}\n\\end{Answer}\n\nIf you have two non-zero vectors $v$ and $u$, you can always compute the angle between them:\\index{vectors!angle between}\n\n$$\\theta = \\arccos(\\frac{v \\cdot u}{|v| |u|})$$\n% Breif Description of arccos\n\\section{Dot products in Python}\n\nNumPy will let you do dot products using the the symbol @.  Open \\filename{first\\_vectors.py} \nand add the following to the end of the script:\n\n\\begin{Verbatim}\n    # Take the dot product\n    d = v @ u\n    print(\"v @ u =\", d)\n    \n    # Get the angle between the vectors\n    a = np.arccos(d / (mv * mu))\n    print(f\"The angle between u and v is {a * 180 / np.pi:.2f} degrees\")    \n\\end{Verbatim}\n\nWhen you run it you should get:\n\\begin{Verbatim}\nv @ u = 4\nThe angle between u and v is 78.55 degrees\n\\end{Verbatim}\n\n\\section{Work and Power}\n%diagram here\nEarlier, we mentioned that mechanical work is the product of the \nforce you apply to something and the amount it moves. For example, if you \npush a train with a force of 10 newtons as it moves 5 meters, you have done 50 joules of work.\n\nWhat if you try to push the train sideways? That is, it moves down the track 5 meters, \nbut you push it as if you were trying to derail it -- perpendicular to its motion.  \nYou have done no work because the train didn't move at all in the direction you were pushing.\n\nNow that you know about dot products: The work you do is the dot\nproduct of the force vector you apply and the displacement vector of the train. (The displacement\nvector is the vector that tells how the train moved while you pushed it.) \\index{work}\n\nSimilary, we mentioned that power is the product of the force you apply and the velocity of the\nmass you are applying it to. It is actually the dot product of the force vector and the velocity vector.\\index{power}\n\nFor example, if you are pushing sled with a force of 10 newtons and it is moving 2 meters per second, \nbut your push is 20 degrees off, you aren't transferring 20 watts of power to the sled.  \nYou are transferring $10 \\times 2 \\times \\cos(20 \\text{ degrees}) \\approx 18.8$ watts of power.\n%add ramps and sin", "meta": {"hexsha": "b7f494fea7aa713b22168b4b1006ee9e01176382", "size": 5295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/TrianglesCircles/dot-en_US.tex", "max_stars_repo_name": "hillegass/sequence", "max_stars_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/TrianglesCircles/dot-en_US.tex", "max_issues_repo_name": "hillegass/sequence", "max_issues_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/TrianglesCircles/dot-en_US.tex", "max_forks_repo_name": "hillegass/sequence", "max_forks_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 38.9338235294, "max_line_length": 121, "alphanum_fraction": 0.6602455146, "num_tokens": 1685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.9059898165759306, "lm_q1q2_score": 0.8429857077209101}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 3}\n\nProve that if the subtree rooted at node $i$ has $n$ nodes, the subtree rooted at either of its children has size at most $2n/3$.\n\n\\subsection*{Solution}\n\nThe objective is to find an upper bound on the number nodes of a subtree based on number of nodes of a subtree rooted at its parent.\nWe define $H$ as the height of the latter subtree rooted at node $i$.\n\nTo find the upper bound, we try to place as many nodes as possible on a subtree $L$ rooted at a child of $i$ while trying to maintain as few nodes as possible on subtree $R$ at the other child of $i$.\nThis practice is however restricted by definition of the heap that requires all higher levels of the tree be completely filled.\nThus the difference would be on the lowest level where we are allowed to add nodes from the left.\n\nThe imbalance between subtrees $L$ and $R$ will be most significant where last row is half full, in which case subtree $L$ will have height $(H-1)$ while subtree $R$ will have height $(H-2)$, due to the fact that both are completely filled.\n\nIf number of nodes of left and right subtrees be defined as $n(L)$ and $n(R)$, respectively, the following would hold.\n\n\\begin{equation}\\label{eq31}\nn(L) = 2^{(H-1)+1}-1 = 2^H - 1\n\\end{equation}\n\n\\begin{equation}\\label{eq32}\nn(R) = 2^{(H-2)+1}-1 = 2^{H-1} - 1\n\\end{equation}\n\nsince roots of subtrees $L$ and $R$ are immediate children of node $i$ we will also have\n\n\\begin{equation}\\label{eq33}\nn = 1 + n(L) + n(R)\n\\end{equation}\n\nwhere $n$ is total number of nodes of a subtree with root at node $i$.\n\nSubstituting \\ref{eq31} and \\ref{eq32} into \\ref{eq33},\n\n\\begin{equation}\\label{eq34}\n\\begin{aligned}\nn &= 2^H + 2^{H-1} - 1\\\\\n&= 2^{H} (1 + \\frac{1}{2}) - 1\\\\\n&= \\frac{3}{2} n(L) + \\frac{1}{2}\n\\end{aligned}\n\\end{equation}\n\nwhich proves that $n(L) < \\frac{2}{3}n$.\n", "meta": {"hexsha": "3eca0f314cfb649b3bf0739c48f1dd27f7afef0e", "size": 2175, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q03.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q03.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q03.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 41.8269230769, "max_line_length": 240, "alphanum_fraction": 0.6666666667, "num_tokens": 644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475683211324, "lm_q2_score": 0.8933094088947399, "lm_q1q2_score": 0.8427012586392411}}
{"text": "\\input{6DL/BarronSpace}\n\\subsection{Cosine function as activation function}\n\tConsider the Fourier transform:\n\t\\begin{equation}\n\t  \\label{Fourier}\n\t  \\hat f(\\omega)=\\frac{1}{(2\\pi)^d}\\int_{\\mathbb{R}^d}e^{-i\\omega\\cdot x}f(x)dx\n\t  \\quad \\forall \\omega \\in \\mathbb R^d.\n\t\\end{equation}\n\tWe write  \n\t$\\hat{f}(\\omega)=e^{i\\beta(\\omega)}|\\hat{f}(\\omega)|$. By Fourier inversion formula,\n\t\\begin{equation}\n\t\t\\label{eqn1}\n\t\tf(x)=\\int_{\\mathbb{R}^d}e^{i\\omega\\cdot x}\\hat{f}(\\omega)d\\omega\n\t\t=\\int_{\\mathbb{R}^d}e^{i(\\omega\\cdot x+\\beta(\\omega))}|\\hat{f}(\\omega)|d\\omega.\n\t\\end{equation}\nSince $f(x)$ is real-valued, it implies that, for $x$\n\t  \\begin{equation}\n\t\t\\label{key}\n\t\t\\begin{aligned}\n\t\t\tf(x)\n\t\t\t&={\\rm Re}\\int_{\\mathbb{R}^d}\n\t\t\te^{i\\omega\\cdot x} \n\t\t\t\\hat{f}(\\omega)d\\omega \\\\\n\t\t\t&={\\rm Re}\\int_{\\mathbb{R}^d}\n\t\t\te^{i\\omega\\cdot x}\n\t\t\te^{i\\beta\n\t\t\t\t(\\omega)}|\\hat{f}(\\omega)|d\\omega \\\\\n\t\t\t&=\\int_{\\mathbb{R}^d}\\cos(\\omega\\cdot\n\t\t\tx+\\beta(\\omega))|\\hat{f}(\\omega)|d\\omega.\n\t\t\\end{aligned}\n\t\\end{equation}\n\tThen we have \n\t\\begin{equation}\\label{key}\n\tf(x) =\\int_{\\mathbb{R}^d}k(x,\\omega)d\\omega,\n\t\\end{equation}\n\twith\n\t\\begin{equation}\\label{key}\n\tk(x,\\omega) = \\cos(\\omega\\cdot\n\tx+\\beta(\\omega))|\\hat{f}(\\omega)|.\n\t\\end{equation}\n\tLet \n\t$$\n\t\\rho(\\omega) = |\\hat f(\\omega)|,\\qquad \\lambda(\\omega)={\\rho(\\omega)\\over \\|\\rho(\\omega)\\|_{L^1}}={\\rho(\\omega)\\over \\|\\hat f\\|_{L^1}}.\n\t$$ \n\t\n\\begin{theorem}\nThere exist $\\omega_i \\in \\mathbb{R}^d$, s.t., $G = \\mathbb{R}$ and \n\\begin{equation}\\label{key}\n\\| f(x) - f_n(x)\\|_{L^2} \\le \\frac{1}{\\sqrt{n}} \\int_{\\mathbb{R}^d} |\\hat f(\\omega)| d \\omega,\n\\end{equation}\nwhere\n\\begin{equation}\\label{key}\nf_n(x)  = \\frac{\\|\\hat f\\|_{L^1}}{n} \\sum_{i=1}^n \\frac{ cos(\\omega^*_i \\cdot x + \\beta^*_i)}{\\rho(\\omega_i^*)}.\n\\end{equation}\n\\end{theorem}\nNote that \n\\begin{equation}\\label{key}\nf_n = \\frac{\\|\\hat f\\|_{L^1}}{n}\\sum_{i=1}^n \\frac{ cos(\\omega^*_i \\cdot x + \\beta^*_i)}{\\rho(\\omega_i^*)} \\in \\dnn(\\cos, n).\n\\end{equation} \n", "meta": {"hexsha": "9d0ef02799e11b8c454df4625b007532ecf63866", "size": 1965, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/FourierRepresentation.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/FourierRepresentation.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/FourierRepresentation.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.75, "max_line_length": 136, "alphanum_fraction": 0.6015267176, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.960361162033533, "lm_q2_score": 0.877476800298183, "lm_q1q2_score": 0.8426946395918293}}
{"text": "\n\\subsection{Definition}\nLet\u2019s add another function: addition. Defined by:\n\n\\(\\forall a \\in \\mathbb{N} (a+0=a)\\)\n\n\\(\\forall a b \\in \\mathbb{N} (a+s(b)=s(a+b))\\)\n\nThat is, adding zero to a number doesn\u2019t change it, and \\((a+b)+1=a+(b+1)\\).\n\n\\subsection{Example}\n\nLet\u2019s use this to solve \\(1+2\\):\n\n\\(1+2=1+s(1)\\)\n\n\\(1+s(1)=s(1+1)\\)\n\n\\(s(1+1)=s(1+s(0))\\)\n\n\\(s(1+s(0))=s(s(1+0))\\)\n\n\\(s(s(1+0))=s(s(1))\\)\n\n\\(s(s(1))=s(2)\\)\n\n\\(s(2)=3\\)\n\n\\(1+2=3\\)\n\nAll addition can be done iteratively like this.\n\n\\subsection{Commutative property of addition}\n\nAddition is commutative:\n\n\\(x+y=y+x\\)\n\n\\subsection{Associative property of addition}\n\nAddition is associative:\n\n\\(x+(y+z)=(x+y)+z\\)\n\n", "meta": {"hexsha": "63753b3a7d373809279b970dd782c8e8da96b218", "size": 671, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/peano/01-01-addition.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/peano/01-01-addition.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/peano/01-01-addition.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.9111111111, "max_line_length": 76, "alphanum_fraction": 0.5946348733, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9697854103128328, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.8425755201564393}}
{"text": "\\documentclass[11pt]{amsart}\n\\usepackage{amsmath,amsfonts,amsthm,amssymb, amsaddr}\n\n\n\\title{Vector Calculus: Grad, Div, and Curl}\n\n\\author{Joe Bentley}\n\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\newpage\n\n\\section{Directional Derivative and Gradient}\n\nConsider a scalar field in three dimensions, given by $f(x, y, z)$. The partial derivatives $\\frac{\\partial f}{\\partial x}$, $\\frac{\\partial f}{\\partial y}$, and $\\frac{\\partial f}{\\partial z}$, are taking the derivatives along the $x$, $y$, and $z$ directions respectively. In other words, they are just like normal derivatives of a curve along a direction; they give the rate of change of $f$ along the given direction. What if we want the derivative in a direction other than $x$, $y$, and $z$? We can define the derivative in an arbitrary direction given by $\\hat{n}$ as,\n\n\\begin{align*}\n  \\frac{\\partial f}{\\partial \\hat{n}} = \\lim_{\\epsilon \\to 0} \\frac{f(\\mathbf{r} + \\epsilon \\hat{n}) - f(\\mathbf{r})}{\\epsilon}\n\\end{align*}\n\nBy applying the chain rule to this, it follows,\n\n\\begin{align*}\n  \\frac{\\partial f}{\\partial \\hat{n}} &= \\frac{d}{d\\epsilon} f(x + \\epsilon n_x, y + \\epsilon n_y, z + \\epsilon n_z) \\\\\n                                      &= \\frac{\\partial f}{\\partial x} \\frac{d}{d\\epsilon} (x + \\epsilon n_x)\n                                       + \\frac{\\partial f}{\\partial y} \\frac{d}{d\\epsilon} (y + \\epsilon n_y)\n                                       + \\frac{\\partial f}{\\partial z} \\frac{d}{d\\epsilon} (z + \\epsilon n_z) \\\\\n                                      &= n_x \\frac{\\partial f}{\\partial x} + n_y \\frac{\\partial f}{\\partial y} + n_z \\frac{\\partial f}{\\partial z}\n\\end{align*}\n\nTherefore, the directional derivative in a given direction $\\hat{n}$ is given by,\n\n\\begin{align*}\n  \\frac{\\partial f}{\\partial \\hat{n}} = \\hat{n} \\cdot \\nabla f\n\\end{align*}\n\nWhere we define the gradient, $\\nabla f$ as,\n\n\\begin{align*}\n  \\nabla f = \\frac{\\partial f}{\\partial x} \\hat{\\imath} + \\frac{\\partial f}{\\partial y} \\hat{\\jmath} + \\frac{\\partial f}{\\partial z} \\hat{k}\n\\end{align*}\n\nNote that $\\frac{\\partial f}{\\partial \\hat{n}} = \\hat{n} \\cdot \\nabla f$ has its maximum value $|\\nabla f|$ when $\\hat{n}$ is parallel to $\\nabla f$. The maximum value is $|\\nabla f|$ as $|\\hat{n}| = 1$. Hence $\\hat{n} = \\nabla f / |\\nabla f|$ is the direction in which $f$ is increasing most rapidly.\n\n\\section{Physical Interpretation of $\\nabla \\cdot \\mathbf{A}$}\n\nConsider an infinitesimal cuboid situated at the position $(x, y, z)$ with sides of length $dx$, $dy$, $dz$. We denote the surface integral as,\n\n\\begin{align*}\n  \\oint_S \\mathbf{A} \\cdot d\\mathbf{S}\n\\end{align*}\n\nThe vector $\\mathbf{A} = A_x \\hat{\\imath} + A_y \\hat{\\jmath} + A_z \\hat{k}$. First we will consider two opposing faces of the cuboid both in the $\\hat{\\imath}$, denoted by the surfaces $S_1$ at $(x + dx, y, z)$ and $S_2$ at $(x, y, z)$. For the surface $S_1$, $d\\mathbf{S_1}$ is given by $d\\mathbf{S_1} = dy dz \\hat{\\imath}$. The vector $\\hat{\\imath}$ is the unit normal to the surface $S_1$. The surface integral is then given by,\n\n\\begin{align*}\n  \\oint_{S_1} \\mathbf{A} \\cdot d\\mathbf{S} = A_x(x + dx, y, z) dy dz\n\\end{align*}\n\nFor the surface $S_2$, the surface element $d_\\mathbf{S_2}$ is given by $d_\\mathbf{S_2} = -dy dz \\hat{\\imath}$. Note that this time the unit normal is in the opposite direction to the unit normal in $d_\\mathbf{S_1}$. The surface integral this time is,\n\n\\begin{align*}\n  \\oint_{S_2} \\mathbf{A} \\cdot d\\mathbf{S} = A_x(x, y, z) dy dz\n\\end{align*}\n\nBy adding together the two surface integrals,\n\n\\begin{align*}\n  \\int_{S_1 + S_2} \\mathbf{A} \\cdot d\\mathbf{S} &= \\left[A_x(x + dx, y, z) - A_x(x, y, z)\\right] dy dz \\\\\n                                                &= \\left[\\frac{\\partial A_x}{\\partial x} dx\\right] dy dz \\\\\n                                                &= \\frac{\\partial A_x}{\\partial x} dx dy dz = \\frac{\\partial A_x}{\\partial x} dV\n\\end{align*}\n\nIn ths second line we recognised that it is the definition of the derivative multiplied by $dx$, so we can rewrite it as we have done the line after.\n\nWe get similar contributions for each of the other pairs of surfaces which we consider to find the final complete result,\n\n\\begin{align*}\n  \\oint_S \\mathbf{A} \\cdot d\\mathbf{S} &= \\left[\\frac{\\partial A_x}{\\partial x} + \\frac{\\partial A_y}{\\partial y} + \\frac{\\partial A_z}{\\partial z}\\right] dx dy dz \\\\\n                                       &= \\nabla \\cdot \\mathbf{A} dV\n\\end{align*}\n\nThe divergence of $\\mathbf{A}$ is therefore just the flux per unit volume of $\\mathbf{A}$.\n\nWe can construct a finite volume $V$ from infinitesimal cuboids. The surface integral can then be calculated by adding up the formulae for each cuboid and noting that the integrals over the internal surfaces cancel each other out. We are left with only the outside surface. From this we get the divergence theorem, also known as Gauss' theorem,\n\n\\begin{align*}\n  \\oint_S \\mathbf{A} \\cdot d\\mathbf{S} = \\int_V (\\nabla \\cdot \\mathbf{A}) dV\n\\end{align*}\n\nwhere $S$ is the boundary of $V$. ($S = \\partial V$)\n\n\\section{The Continuity Equation}\n\nConsider a volume $V$ bounded by a surface $S = \\partial V$. The only way a conserved charge can change within the volume $V$ is if there is a current flow (flow of charge) across $S$. We can see that the rate of decrease of charge within $V$ is equal to the current flow across $S$,\n\n\\begin{align*}\n  \\frac{\\partial}{\\partial t} \\int_V \\rho dV = - \\oint_S \\mathbf{j} \\cdot d \\mathbf{S}\n\\end{align*}\n\nwhere $\\rho$ is the charge density and $\\mathbf{j}$ is the current density (per unit area). Using the divergence theorem gives that the right hand side can be written such that,\n\n\\begin{align*}\n  \\int_V \\frac{\\partial \\rho}{\\partial t} dV = - \\int_V \\nabla \\cdot \\mathbf{j} dV\n\\end{align*}\n\nWe have also taken the $\\partial/\\partial t$ into the integral. For this to be true for all volumes $V$, it is required that,\n\n\\begin{align*}\n  \\frac{\\partial \\rho}{\\partial t} + \\nabla \\cdot \\mathbf{j} = 0\n\\end{align*}\n\nA familiar case is electric charge, where the density $\\rho(\\mathbf{r}, t)$ is the charge density, and $\\mathbf{j}(\\mathbf{r}, t)$ is the current density. Another example would be fluid flow, where the density $\\rho(\\mathbf{r}, t)$ is just the mass density, and for a velocity field $\\mathbf{v}(\\mathbf{r}, t)$, the mass current is given by $\\mathbf{j}(\\mathbf{r}, t) = \\rho(\\mathbf{r}, t)\\mathbf{v}(\\mathbf{r}, t)$. Thus in this case, due to mass conservation,\n\n\\begin{align*}\n  \\frac{\\partial \\rho}{\\partial t} + \\nabla \\cdot (\\rho \\mathbf{V}) = 0\n\\end{align*}\n\nIn the case of an incompressible fluid flow, the density $\\rho$ is constant, and thus\n\n\\begin{align*}\n  \\nabla \\cdot \\mathbf{v} = 0\n\\end{align*}\n\n\\section{Physical Interpretation of $\\nabla \\times \\mathbf{A}$}\n\nConsider an infinitesimal rectangle in the $xy$-plane situation at $(x, y)$ with sides of length $dx$ and $dy$. In this case we can write the circulation (the closed line integral) around the infinitesimal loop as,\n\n\\begin{align*}\n  \\oint_C \\mathbf{A} \\cdot d\\mathbf{r} = \\int_{C_1 + C_2 + C_3 + C_4} \\mathbf{A} \\cdot d\\mathbf{r}\n\\end{align*}\n\nWhere each $C_n$ is each side of the infinitesimal rectangle. For the first side $C_1$ we can write an infinitesimal element $d\\mathbf{r_1}$ as $d\\mathbf{r_1} = dx \\hat{\\imath}$. The unit vector $\\hat{\\imath}$ is the unit normal to the line. We can then write the surface integral as,\n\n\\begin{align*}\n  \\int_{C_1} \\mathbf{A} \\cdot d\\mathbf{r_1} = A_x(x, y, z) dx\n\\end{align*}\n\nHere we have taken the dot product of $\\mathbf{A}$ and $d\\mathbf{r_1}$, and since this is only for $A_x$, there is no $\\hat{\\jmath}$ or $\\hat{k}$ component. For the side $C_3$ opposite the side $C_1$ we see that $d\\mathbf{r_3} = -dx \\hat{\\imath}$ as it is in the opposite direction to the unit normal of $C_1$. We can thus write the surface integral,\n\n\\begin{align*}\n  \\int_{C_3} \\mathbf{A} \\cdot d\\mathbf{r_3} = -A_x(x, y + dy, z) dx\n\\end{align*}\n\nBy adding together these two line integrals we then see that,\n\n\\begin{align*}\n  \\int_{C_1 + C_3} &= \\left[A_x(x, y, z) - A_x(x, y + dy, z)\\right] dx \\\\\n                   &= \\left[-\\frac{\\partial A_x}{\\partial y} dy\\right] dx = -\\frac{\\partial A_x}{\\partial y} dx dy\n\\end{align*}\n\nHere we have again noted that the $A_x$ terms are just the derivative of $A_x$ with respect to $y$, multiplied by $dy$.\n\nSimilarly we find that the other two sides $C_2$ and $C_4$ give,\n\n\\begin{align*}\n  \\int_{C_2 + C_4} \\mathbf{A} \\cdot d\\mathbf{r} &= \\left[A_y(x + dx, y, z) - A_y(x, y, z)\\right] dy \\\\\n                                                &= \\left[\\frac{\\partial A_y}{\\partial x} dx\\right] dy = \\frac{\\partial A_y}{\\partial x} dx dy\n\\end{align*}\n\nTherefore we can now calculate the integral over the entire rectangle,\n\n\\begin{align*}\n  \\oint_C \\mathbf{A} \\cdot d\\mathbf{r} = \\left[\\frac{\\partial A_y}{\\partial x} - \\frac{\\partial A_x}{\\partial y}\\right] dx dy\n\\end{align*}\n\nBy noting that in the square brackets is the cross product, we can also write it as the $z$ component of the cross product,\n\n\\begin{align*}\n  \\oint_C \\mathbf{A} \\cdot d\\mathbf{r} = {(\\nabla \\times \\mathbf{A})}_z dx dy\n\\end{align*}\n\nWe can also write the rectangle as a surface element $d\\mathbf{S}$ with a width $dx$ and height $dy$. We define the normal to this surface as being in the $\\hat{k}$ direction (this is where the cross product comes from) allowing to write the integral as,\n\n\\begin{align*}\n  \\oint_C \\mathbf{A} \\cdot d\\mathbf{r} = (\\nabla \\times \\mathbf{A}) \\cdot d\\mathbf{S}\n\\end{align*}\n\nNote that we no longer need just the $z$-component of the cross product as the dot product filters out just the component in the $\\hat{k}$ direction for us. From this result we can see that the $z$-component of the curl of $\\mathbf{A}$ is the circulation per unit area of $A$ in the $xy$-plane.\n\nGenerally, for an infinitesimal surface area $d\\mathbf{S} = \\hat{n} dS$ where $\\hat{n}$ is the unit normal, the circulation over the loop $C = \\partial S$ is given by,\n\n\\begin{align*}\n  \\oint_C \\mathbf{A} \\cdot d\\mathbf{r} = \\left(\\nabla \\times \\mathbf{A}\\right) \\cdot d\\mathbf{S}\n\\end{align*}\n\nWe can construct a finite surface $S$ from infinitestimal surface elements. We can do this by summing the above equation for each element and noting that the integrals over the internal loops cancel each other out. From this we get Stokes theorem,\n\n\\begin{align*}\n  \\oint_C \\mathbf{A} \\cdot d\\mathbf{r} = \\int_S \\left(\\nabla \\times \\mathbf{A}\\right) \\cdot d\\mathbf{S}\n\\end{align*}\n\n\\section{Using Divergence and Curl with Maxwell's Equations}\n\nWe can use the divergence theorem and Stokes theorem to find the integral versions of Maxwell's equations.\n\nThis example shows finding the integral version of Gauss' law. The electric field lines diverge from electric charges such that,\n\n\\begin{align*}\n  \\nabla \\cdot \\mathbf{E} = \\frac{\\rho(r)}{\\epsilon_0}\n\\end{align*}\n\nBy integrating both sides,\n\n\\begin{align*}\n  \\int_V \\nabla \\cdot \\mathbf{E} dV &= \\int_V \\frac{\\rho(r)}{\\epsilon_0} dV \\\\\n  \\oint_S \\mathbf{E} \\cdot d\\mathbf{S} &= \\frac{Q}{\\epsilon_0}\n\\end{align*}\n\nThis is the integral form of Gauss law.\n\nThis example shows finding the integral version of Amperes Law. The magnetic field lines curl around the electric currents,\n\n\\begin{align*}\n  \\nabla \\times \\mathbf{B} &= \\mu_0 \\mathbf{j}(\\mathbf{r}) \\\\\n  \\int_S \\left(\\nabla \\times \\mathbf{B}\\right) \\cdot d\\mathbf{S} &= \\int_S \\mu_0 \\mathbf{j}(\\mathbf{r}) d\\mathbf{S} \\\\\n  \\oint_C \\mathbf{B} \\cdot d\\mathbf{r} &= \\mu_0 I\n\\end{align*}\n\n\\section{Vector Calculus Identities}\n\nIn this section we will prove many of the identities that we might need to know in vector calculus. These include vector calculus of sums, products, and multiple derivatives. First we will list which identities we need, and then we will go through and prove them all. In the following text, $v$ will mean vector, and $s$ will mean scalar.\n\nFirst we will consider the sums. There are two types of summations possible for scalar and vector fields,\n\n\\begin{align*}\n  \\phi + \\psi \\qquad &\\text{(s + s = s)} \\\\\n  \\mathbf{A} + \\mathbf{B} \\qquad &\\text{(v + v = v)}\n\\end{align*}\n\nSo we will need the formula for,\n\n\\begin{align*}\n  &\\nabla(\\phi + \\psi) \\\\\n  &\\nabla \\cdot (\\mathbf{A} + \\mathbf{B}) \\\\\n  &\\nabla \\times (\\mathbf{A} + \\mathbf{B})\n\\end{align*}\n\nIn fact, we can consider general linear combinations of the scalar and vectors fields,\n\n\\begin{align}\n  \\label{eq:1}\n  &\\nabla(\\lambda \\phi + \\mu \\psi) \\\\\n  \\label{eq:2}\n  &\\nabla \\cdot (\\lambda \\mathbf{A} + \\mu \\mathbf{B}) \\\\\n  \\label{eq:3}\n  &\\nabla \\times (\\lambda \\mathbf{A} + \\mu \\mathbf{B})\n\\end{align}\n\nwhere $\\lambda$ and $\\mu$ are constants.\n\nNext we need the identities for products. There are four possible types of products,\n\n\\begin{align*}\n  \\phi\\psi \\qquad &\\text{s $\\times$ s = s} \\\\\n  \\phi\\mathbf{A} \\qquad &\\text{s $\\times$ v = v} \\\\\n  \\mathbf{A} \\cdot \\mathbf{B} \\qquad &\\text{v $\\times$ v = s} \\\\\n  \\mathbf{A} \\times \\mathbf{B} \\qquad &\\text{v $\\times$ v = v}\n\\end{align*}\n\nSo we will need the formula for,\n\n\\begin{align}\n  \\label{eq:4}\n  &\\nabla(\\phi\\psi) \\\\\n  \\label{eq:5}\n  &\\nabla\\cdot(\\phi\\mathbf{A}) \\\\\n  \\label{eq:6}\n  &\\nabla\\times(\\phi\\mathbf{A}) \\\\\n  \\label{eq:7}\n  &\\nabla(\\mathbf{A}\\cdot\\mathbf{B}) \\\\\n  \\label{eq:8}\n  &\\nabla\\cdot(\\mathbf{A}\\times\\mathbf{B}) \\\\\n  \\label{eq:9}\n  &\\nabla\\times(\\mathbf{A}\\times\\mathbf{B})\n\\end{align}\n\nAnd finally we need the multiple derivatives,\n\n\\begin{align}\n  \\label{eq:10}\n  &\\nabla\\cdot(\\nabla\\phi) \\\\\n  \\label{eq:11}\n  &\\nabla\\times(\\nabla\\phi) \\\\\n  &\\nabla(\\nabla\\cdot\\mathbf{A}) \\notag\\\\\n  \\label{eq:12}\n  &\\nabla\\cdot(\\nabla\\times\\mathbf{A}) \\\\\n  \\label{eq:13}\n  &\\nabla\\times(\\nabla\\times\\mathbf{A})\n\\end{align}\n\nSo now we will start and find the identity for expression.~\\ref{eq:1}. Since this is vector, we only need to prove this for one component,\n\n\\begin{align*}\n  &{\\left[\\nabla(\\lambda \\phi + \\mu \\psi)\\right]}_x = \\frac{\\partial}{\\partial x}\\left(\\lambda\\phi + \\mu\\psi\\right) \\\\\n  =& \\lambda \\frac{\\partial \\phi}{\\partial x} + \\mu \\frac{\\partial \\psi}{\\partial x} = \\lambda{[\\nabla\\phi]}_x + \\mu{[\\nabla \\psi]}_x \\\\\n  =& {\\left[\\lambda \\nabla \\phi + \\mu \\nabla \\psi\\right]}_x \\\\\n  \\implies& \\nabla[\\lambda \\phi + \\mu \\psi] = \\lambda\\nabla\\phi + \\mu\\nabla\\psi\n\\end{align*}\n\nFor the second identity, we have to prove for each component as this isn't a vector as it is the scalar product,\n\n\\begin{align*}\n  \\nabla\\cdot[\\lambda\\mathbf{A} + \\mu\\mathbf{B}] &= \\frac{\\partial}{\\partial x} {\\left[\\lambda \\mathbf{A} + \\mu \\mathbf{B}\\right]}_x + \\frac{\\partial}{\\partial y} {\\left[\\lambda \\mathbf{A} + \\mu \\mathbf{B}\\right]}_y + \\frac{\\partial}{\\partial z} {\\left[\\lambda \\mathbf{A} + \\mu \\mathbf{B}\\right]}_z \\\\\n                                                 &= \\frac{\\partial}{\\partial x} \\left[\\lambda A_x + \\mu B_x \\right] +\\frac{\\partial}{\\partial y} \\left[\\lambda A_y + \\mu B_y \\right] +\\frac{\\partial}{\\partial z} \\left[\\lambda A_z + \\mu B_z \\right] \\\\\n                                                 &= \\lambda \\frac{\\partial A_x}{\\partial x} + \\mu \\frac{\\partial B_x}{\\partial x} + \\lambda \\frac{\\partial A_y}{\\partial y} + \\mu \\frac{\\partial B_y}{\\partial y} + \\lambda \\frac{\\partial A_z}{\\partial z} + \\mu \\frac{\\partial B_z}{\\partial z} \\\\\n                                                 &= \\lambda \\left(\\frac{\\partial A_x}{\\partial x} + \\frac{\\partial A_y}{\\partial y} + \\frac{\\partial A_z}{\\partial z}\\right) + \\mu \\left(\\frac{\\partial B_x}{\\partial x} + \\frac{\\partial B_y}{\\partial y} + \\frac{\\partial B_z}{\\partial z}\\right) \\\\\n                                                 &= \\lambda \\nabla \\cdot \\mathbf{A} + \\mu \\nabla \\cdot \\mathbf{B}\n\\end{align*}\n\nTherefore we have for expression.~\\ref{eq:2},\n\n\\begin{align*}\n  \\nabla\\cdot[\\lambda\\mathbf{A} + \\mu\\mathbf{B}] = \\lambda \\nabla \\cdot \\mathbf{A} + \\mu \\nabla \\cdot \\mathbf{B}\n\\end{align*}\n\nFor the third identity, we again have another vector as we are taking the cross product, so we only need to prove it for one component,\n\n\\begin{align*}\n  {\\left[\\nabla\\times(\\lambda\\mathbf{A}+\\mu\\mathbf{B})\\right]}_x &= \\frac{\\partial}{\\partial y}{[\\lambda\\mathbf{A}+\\mu\\mathbf{B}]}_z - \\frac{\\partial}{\\partial z}{[\\lambda\\mathbf{A}+\\mu\\mathbf{B}]}_y \\\\\n                                                                 &= \\frac{\\partial}{\\partial y}[\\lambda A_z+\\mu B_z] - \\frac{\\partial}{\\partial z}[\\lambda A_y+\\mu B_y] \\\\\n                                                                 &= \\lambda\\left(\\frac{\\partial A_z}{\\partial y} - \\frac{\\partial A_y}{\\partial z}\\right) + \\mu\\left(\\frac{\\partial B_z}{\\partial y} - \\frac{\\partial B_y}{\\partial z}\\right) \\\\\n                                                                 &= \\lambda{(\\nabla\\times\\mathbf{A})}_x + \\mu{(\\nabla\\times\\mathbf{A})}_x \\\\\n                                                                 &= {[\\lambda(\\nabla\\times\\mathbf{A}) + \\mu(\\nabla\\times\\mathbf{A})]}_x\n\\end{align*}\n\nTherefore we have shown that,\n\n\\begin{align*}\n  \\nabla\\times(\\lambda\\mathbf{A} + \\mu\\mathbf{B}) = \\lambda \\nabla\\times\\mathbf{A} + \\mu \\nabla\\times\\mathbf{B}\n\\end{align*}\n\nNext we have our fourth identity and our first product identity, from expression.~\\ref{eq:4},\n\n\\begin{align*}\n  {[\\nabla(\\phi\\psi)]}_x &= \\frac{\\partial}{\\partial x}(\\phi\\psi) \\\\\n                         &= \\frac{\\partial \\phi}{\\partial x}\\psi + \\phi\\frac{\\partial\\psi}{\\partial x} \\\\\n                         &= {[\\nabla\\phi]}_x\\psi + \\phi{[\\nabla\\psi]}_x \\\\\n                         &= {[(\\nabla\\phi)\\psi + \\phi(\\nabla\\psi)]}_x\n\\end{align*}\n\nTherefore we have our fourth identity,\n\n\\begin{align*}\n  \\nabla(\\phi\\psi) = (\\nabla\\phi)\\psi + \\phi(\\nabla\\psi)\n\\end{align*}\n\nNow for our fifth expression, which is a scalar so we have to prove for all components,\n\n\\begin{align*}\n  \\nabla\\cdot(\\phi\\mathbf{A}) &= \\frac{\\partial}{\\partial x}{(\\phi\\mathbf{A})}_x + \\frac{\\partial}{\\partial y}{(\\phi\\mathbf{A})}_y + \\frac{\\partial}{\\partial z}{(\\phi\\mathbf{A})}_z \\\\\n                              &= \\frac{\\partial}{\\partial x}(\\phi A_x) + \\frac{\\partial}{\\partial y}(\\phi A_y) + \\frac{\\partial}{\\partial z}(\\phi A_z) \\\\\n                              &= \\frac{\\partial\\phi}{\\partial x} A_x + \\frac{\\partial\\phi}{\\partial y} A_y + \\frac{\\partial\\phi}{\\partial z} A_z + \\frac{\\partial A_x}{x} \\phi + \\frac{\\partial A_y}{y} \\phi + \\frac{\\partial A_z}{z} \\phi \\\\\n                              &= (\\nabla\\phi)\\cdot\\mathbf{A} + \\phi \\nabla\\cdot\\mathbf{A}\n\\end{align*}\n\nWe now have the fifth identity,\n\n\\begin{align*}\n  \\nabla\\cdot(\\phi\\mathbf{A}) = (\\nabla\\phi)\\cdot\\mathbf{A} + \\phi \\nabla\\cdot\\mathbf{A}\n\\end{align*}\n\nFor our sixth expression, we have a vector and thus only have to prove one component,\n\n\\begin{align*}\n  {[\\nabla\\times(\\phi\\mathbf{A})]}_x &= \\frac{\\partial}{\\partial y}{(\\phi\\mathbf{A})}_z - \\frac{\\partial}{\\partial z}{(\\phi\\mathbf{A})}_y \\\\\n                                     &= \\frac{\\partial}{\\partial y}(\\phi A_z) - \\frac{\\partial}{\\partial z}(\\phi A_y) \\\\\n                                     &= \\frac{\\partial\\phi}{\\partial y}A_z - \\frac{\\partial\\phi}{\\partial z}A_y + \\phi\\frac{\\partial A_z}{y} - \\phi\\frac{\\partial A_y}{z} \\\\\n                                     &= {[\\nabla\\phi\\times\\mathbf{A}]}_x + {[\\phi\\nabla\\times\\mathbf{A}]}_x \\\\\n                                     &= {[\\nabla\\phi\\times\\mathbf{A} + \\phi\\nabla\\times\\mathbf{A}]}_x\n\\end{align*}\n\nTherefore we have our sixth identity,\n\n\\begin{align*}\n  \\nabla\\times(\\phi\\mathbf{A}) = (\\nabla\\phi)\\times\\mathbf{A} + \\phi(\\nabla\\times\\mathbf{A})\n\\end{align*}\n\nFor the rest of the proofs of the identities see canvas or written notes (the proofs are long and I cannot be bothered to type them up), but I will state all of the identities here,\n\n\\begin{align*}\n  \\nabla(\\mathbf{A}\\cdot\\mathbf{B}) &= (\\mathbf{B}\\cdot\\mathbf{A})\\mathbf{A}+\\mathbf{B}\\times(\\nabla\\times\\mathbf{A})+(\\mathbf{A}\\cdot\\nabla)\\mathbf{B}+\\mathbf{A}\\times(\\nabla\\times\\mathbf{B}) \\\\\n  \\nabla\\cdot(\\mathbf{A}\\times\\mathbf{B}) &= \\mathbf{B}\\cdot(\\nabla\\times\\mathbf{A}) - \\mathbf{A}\\cdot(\\nabla\\times\\mathbf{B}) \\\\\n  \\nabla\\times(\\mathbf{A}\\times\\mathbf{B}) &= (\\mathbf{B}\\cdot\\nabla)\\mathbf{A}-(\\mathbf{A}\\cdot\\nabla)\\mathbf{B}+\\mathbf{A}(\\nabla\\cdot\\mathbf{B})-\\mathbf{B}(\\nabla\\cdot\\mathbf{A}) \\\\\n  \\nabla\\cdot(\\nabla\\psi) &= \\nabla^2 \\psi \\\\\n  \\nabla\\times(\\nabla\\psi) &= \\mathbf{0} \\\\\n  \\nabla\\cdot(\\nabla\\times\\mathbf{A}) &= \\mathbf{0} \\\\\n  \\nabla\\times(\\nabla\\times\\mathbf{A}) &= \\nabla(\\nabla\\cdot\\mathbf{A}) - \\nabla^2 \\mathbf{A}\n\\end{align*}\n\n\\section{Using Vector Calculus Identities: Maxwell's Equations and Continuity}\n\nFrom Coulomb's law, Biot Savart law, and Faraday's laws we can derive the differential form of Maxwell's equations,\n\n\\begin{alignat*}{2}\n  \\nabla \\cdot \\mathbf{E} &= \\frac{\\rho}{\\epsilon_0} \\qquad &&\\nabla \\times \\mathbf{E} = -\\frac{\\partial\\mathbf{B}}{\\partial t} \\\\\n  \\nabla \\cdot \\mathbf{B} &= 0 \\qquad &&\\nabla \\times \\mathbf{B} = \\mu_0 \\mathbf{J}\n\\end{alignat*}\n\nOur equation, $\\nabla\\times\\mathbf{B} = \\mu_0 \\mathbf{J}$, known as Ampere's circuital law is incomplete as it does not obey the continuity equation. The continuity equation describes that,\n\n\\begin{align*}\n  \\frac{\\partial\\rho}{\\partial t} + \\nabla\\cdot\\mathbf{J} = 0\n\\end{align*}\n\nbut we see that if we take the divergence of $\\mathbf{J}$ we have zero,\n\n\\begin{align*}\n  \\mu_0 \\nabla\\cdot\\mathbf{J} = \\nabla\\cdot(\\nabla\\times\\mathbf{B}) = 0.\n\\end{align*}\n\nby our identity that the divergence of a curl of a vector field is always zero. This implies that the rate of change of charge density, $\\frac{\\partial\\rho}{\\partial t}$ must always be equal to zero for the continuity equation to hold, but this is not necessary to be true for example with a current flowing through a wire. Therefore we must have that,\n\n\\begin{align*}\n  \\nabla\\cdot\\mathbf{J} = -\\frac{\\partial\\rho}{\\partial t}\n\\end{align*}\n\nTherefore, by applying this,\n\n\\begin{align*}\n  \\mu_0\\nabla\\cdot\\mathbf{J} = -\\mu_0\\frac{\\partial\\rho}{\\partial t} = -\\mu_0\\epsilon_0\\nabla\\cdot\\frac{\\partial\\mathbf{E}}{\\partial t}\n\\end{align*}\n\nHere we have recognised that the rate of change of charge density is given in the time derivative of Gauss' law. It follows that the continuity equation can be satisfied by writing,\n\n\\begin{align*}\n  \\nabla\\times\\mathbf{B} = \\mu_0\\left(\\mathbf{J} + \\epsilon_0 \\frac{\\partial \\mathbf{E}}{\\partial t}\\right)\n\\end{align*}\n\nThis new term is called the displacement current, and this is known as Maxwell's addition to Ampere's circuit law.\n\n\\section{Using Vector Calculus Identities: Electromagnetic Wave Equation}\n\nMaxwell's equations in free space, that is space where there are no charges or currents reduce to,\n\n\\begin{alignat*}{2}\n  \\nabla\\cdot\\mathbf{E} &= 0 \\qquad &&\\nabla\\times\\mathbf{E} = -\\frac{\\partial \\mathbf{B}}{\\partial t} \\\\\n  \\nabla\\cdot\\mathbf{B} &= 0 \\qquad &&\\nabla\\times\\mathbf{B} = \\mu_0\\epsilon_0\\frac{\\partial\\mathbf{E}}{\\partial t}\n\\end{alignat*}\n\nTaking the curl of $\\nabla\\times\\mathbf{E}$ gives that,\n\n\\begin{align*}\n  \\nabla\\times(\\nabla\\times\\mathbf{E}) = \\nabla\\times\\left(-\\frac{\\partial\\mathbf{B}}{\\partial t}\\right) = -\\frac{\\partial}{\\partial t} \\left(\\nabla\\times\\mathbf{B}\\right) = -\\mu_0\\epsilon_0\\frac{\\partial^2\\mathbf{E}}{\\partial t^2}\n\\end{align*}\n\nTherefore we have using our vector identity for the curl of a curl of a vector field,\n\n\\begin{align*}\n  \\nabla(\\nabla\\cdot\\mathbf{E}) - \\nabla^2 \\mathbf{E} = -\\mu_0\\epsilon_0\\frac{\\partial^2\\mathbf{E}}{\\partial t^2}\n\\end{align*}\n\nFrom our free space version of Gauss' law we can see that the first term goes to zero, so that\n\n\\begin{align*}\n  \\nabla^2\\mathbf{E} = \\mu_0\\epsilon_0\\frac{\\partial^2\\mathbf{E}}{\\partial t^2}\n\\end{align*}\n\nThis is just the wave equation, just as in classical wave theory. The only difference between this and how we remember the wave equation from the first year is that instead of taking the second derivative with respect to position in one direction, we now take the second derivative in all directions, which is just the Laplacian. We therefore see that $\\mathbf{E}$ satisfies the wave equation with velocity $c = \\frac{1}{\\sqrt{\\mu_0\\epsilon_0}}$.\n\nWe can do the same thing with the $\\mathbf{B}$-field by computing $\\nabla\\times(\\nabla\\times\\mathbf{B})$,\n\n\\begin{align*}\n  \\nabla\\times(\\nabla\\times\\mathbf{B}) &= \\mu_0\\epsilon_0\\frac{\\partial}{\\partial t}(\\nabla\\times\\mathbf{E}) \\\\\n  \\nabla(\\nabla\\cdot\\mathbf{B}) - \\nabla^2\\mathbf{B} &= \\mu_0\\epsilon_0\\frac{\\partial}{\\partial t}\\left(-\\frac{\\partial\\mathbf{B}}{\\partial t}\\right)\n\\end{align*}\n\nHere we have used that $\\nabla\\times\\mathbf{E} = -\\frac{\\partial\\mathbf{B}}{\\partial t}$. Again we can say that the first term $\\nabla(\\nabla\\cdot\\mathbf{B})$ is zero as Gauss' law for magnetism tells us, so finally we have,\n\n\\begin{align*}\n  \\nabla^2\\mathbf{B} = \\mu_0\\epsilon_0\\frac{\\partial^2\\mathbf{B}}{\\partial t^2}\n\\end{align*}\n\nWhich is again the same form of the wave equation satisfied by the electric field. We therefore see that we now have two fields, the magnetic field and the electric field, which both satisfy the classical wave equation of the same form.\n\n\n\n\\end{document}\n", "meta": {"hexsha": "dbbf1f1622fb60472388ee8002ee78063a18cca9", "size": 25070, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maths/vectorcalc/vectorcalc.tex", "max_stars_repo_name": "unanimousarc/physics", "max_stars_repo_head_hexsha": "7bc9cbd428defb7615f5a2e241d86fae71ece7b3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-03-13T14:28:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-06T14:27:57.000Z", "max_issues_repo_path": "maths/vectorcalc/vectorcalc.tex", "max_issues_repo_name": "unanimousarc/physics", "max_issues_repo_head_hexsha": "7bc9cbd428defb7615f5a2e241d86fae71ece7b3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "maths/vectorcalc/vectorcalc.tex", "max_forks_repo_name": "unanimousarc/physics", "max_forks_repo_head_hexsha": "7bc9cbd428defb7615f5a2e241d86fae71ece7b3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-29T08:14:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-29T08:14:51.000Z", "avg_line_length": 52.0124481328, "max_line_length": 575, "alphanum_fraction": 0.6502193857, "num_tokens": 8427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.9173026601509101, "lm_q1q2_score": 0.8425243793280248}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} Show that $1+i,2+i$ are the only two roots to\n\\begin{equation*}\np(x) =x^{2}-(3+2i) x+(1+3i)\n\\end{equation*}\nHence complex zeros do not necessarily come in conjugate pairs if the coefficients of the equation\nare not real.\n\\begin{sol}\n\\[\n(x-(1+i)) (x-(2+i))\n= x^{2}-(3+2i) x+1+3i\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Give the solutions to the following quadratic equations having real\ncoefficients.\n\n\\begin{enumerate}\n\\item $x^{2}-2x+2=0$\n\n\\item $3x^{2}+x+3=0$\n\n\\item $x^{2}-6x+13=0$\n\n\\item $x^{2}+4x+9=0$\n\n\\item $4x^{2}+4x+5=0$\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\\item Solution is: $1+i,1-i$\n\\item Solution is: $\\frac{1}{6}i\\sqrt{35}-\\frac{1}{6},-\\frac{%\n1}{6}i\\sqrt{35}-\\frac{1}{6}$\n\\item Solution is: $3+2i,3-2i$\n\\item Solution is: $i\\sqrt{5}-2,-i\\sqrt{5}-2$\n\\item Solution is: $-\\frac{1}{2}+i,-\\frac{1}{2}-i$\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Give the solutions to the following quadratic equations having complex\ncoefficients.\n\n\\begin{enumerate}\n\\item $x^{2}+2x+1+i=0$\n\n\\item $4x^{2}+4ix-5=0$\n\n\\item $4x^{2}+(4+4i) x+1+2i=0$\n\n\\item $x^{2}-4ix-5=0$\n\n\\item $3x^{2}+(1-i) x+3i=0$\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\\item Solution is : $x=-1+\\frac{1}{2}\\sqrt{2}-\\frac{1}{2}i\n\\sqrt{2},\\;\\;x=-1-\\frac{1}{2}\\sqrt{2}+\\frac{1}{2}i\\sqrt{2}$\n\\item Solution is : $x=1-\\frac{1}{2}i,\\;x=-1-\\frac{1}{2}i$\n\\item Solution is : $x=-\\frac{1}{2},\\;x=-\\frac{1}{2}-i$\n\\item Solution is : $x=-1+2i,\\;\\;x=1+2i$\n\\item Solution is : $x=-\\frac{1}{6}+\\frac{1}{6}\\sqrt{19}+\\paren{\\frac{1}{6}-\\frac{1}{6}\\sqrt{19}} i,\\;\\;x=-\\frac{1}{6}-\\frac{1}{6}\\sqrt{19}+\\paren{\\frac{1}{6}+\\frac{1}{6}\\sqrt{19}}i$\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} \\label{exer-complex3}Prove the fundamental theorem of algebra for\nquadratic polynomials having coefficients in $\\C$. That is, show\nthat an equation of the form \\\\ $ax^{2}+bx+c=0$ where $a,b,c$ are complex\nnumbers, $a\\neq 0$ has a complex solution. \\textbf{Hint: }Consider the fact,\nnoted earlier that the expressions given from the quadratic formula do in\nfact serve as solutions.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "a98cc81b169cc2533f25be5d34fd5b7415fb889b", "size": 2100, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/ComplexNumbers-Quadratic.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/exercises/ComplexNumbers-Quadratic.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/exercises/ComplexNumbers-Quadratic.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 26.582278481, "max_line_length": 182, "alphanum_fraction": 0.6385714286, "num_tokens": 889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.9184802434674242, "lm_q1q2_score": 0.8425243763389958}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 2}\n\nShow that the second smallest of $n$ elements can be found with $n + \\lceil \\log n \\rceil - 2$ comparisons in the worst case.\n\n\\subsection*{Solution}\n\nWe begin by comparing elements of the array two by two, each time putting the minimum number in a new array of size $\\lceil \\frac{n}{2} \\rceil$.\nWe will repeat the procedure for the new array until our new array will have only one element which is the element with minimum value.\nTo calculate the number of comparisons it takes to find the element with minimum value, we use the analogy of a tree with $n$ nodes at height $H$, in which case the number of comparisons would be equal to number of nodes at levels greater than $0$ which is $n - 1$.\n\nThe second smallest element is the smallest of all other nodes except the root.\nTherefore, there has been a comparison in which this element has lost to the element with minimum value.\nAs the latter is compared $\\lceil \\log n \\rceil$ times, we can compare all its losers to eachother to obtain the second smallest element, a procedure which takes $\\lceil \\log n \\rceil - 1$ comparisons.\n\nTherefore the total number of comparisons would be $n + \\lceil \\log n - 2$.\n", "meta": {"hexsha": "08df56585c7f0ed069a4018ce89beb7f0ea35d57", "size": 1540, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q02.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q02.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q02.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 66.9565217391, "max_line_length": 265, "alphanum_fraction": 0.6967532468, "num_tokens": 358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480666, "lm_q2_score": 0.9284087936225136, "lm_q1q2_score": 0.8423566402186775}}
{"text": "\\section*{Ex.2.6}\n\\subsection*{Multiply-mod-prime hash function where $a=0$ is possible}\n\n\\emph{Show it is not universal.}\n\nTo be a universal hash function it must hold that for all distinct keys $P(h(x)=h(y))\\leq 1/m$.\n\nWe will give a concrete example where the above probability is not fulfilled:\n\\\\\nSet $p=3$, $m=2$, $x=0$, $y=1$. Then the possible values for $a,b\\in\\{0,1,2\\}$. The table below shows the hash value for $x$ and $y$ with the value set above.\n\n\\begin{center}\n\\begin{tabular}{l|cc|r}\n              & $h(x)$ & $h(y)$ & collision\\\\\n\\hline\n $(a,b)=(0,0)$& 0 & 0 & true\\\\\n $(a,b)=(0,1)$& 1 & 1 & true\\\\\n $(a,b)=(0,2)$& 0 & 0 & true\\\\\n $(a,b)=(1,0)$& 0 & 1 & false\\\\\n $(a,b)=(1,1)$& 1 & 0 & false\\\\\n $(a,b)=(1,2)$& 0 & 0 & true\\\\\n $(a,b)=(2,0)$& 0 & 0 & true\\\\\n $(a,b)=(2,1)$& 1 & 0 & false\\\\\n $(a,b)=(2,2)$& 0 & 1 & false\n\\end{tabular}\t\n\\end{center}\n\nIt can be seen that for 5 out of the 9 possibilities, there is a collision. Hence the probability for collision is\n$$\nP(h(0)=h(1)) = \\frac{5}{9} > \\frac{1}{2} = \\frac{1}{m}\n$$\nSo we have found an instance where this hash function is not universal.\n\n\\emph{Prove that it is always 2-universal}\n\nFirst note that for $a=0$, then $P(h_{0,b}(x)=h_{0,b}(y)) = 1$ for all values of $b, x, y$. The probability $P(a=0)=1/p$. To prove 2-universal we see that\n\\begin{align*}\nP(h_{a,b}(x) = h_{a,b}(y)) &= P([(a=0)\\cap(h_{a,b}(x) = h_{a,b}(y))]\\cup [(a>0)\\cap(h_{a,b}(x) = h_{a,b}(y))])\\\\\n&= P((a=0)\\cap(h_{0,b}(x) = h_{0,b}(y))) + P((a>0)\\cap(h_{a,b}(x) = h_{a,b}(y)))\\\\\n&= \\frac{1}{p} + P((a>0)\\cap(h_{a,b}(x) = h_{a,b}(y))) \\\\\n&< \\frac{1}{p} + \\frac{1}{m} \\\\\n&< \\frac{1}{m} + \\frac{1}{m} \\\\\n&= \\frac{2}{m}\n\\end{align*}\nHence we have shown that the hash function is 2-universal.", "meta": {"hexsha": "90af8407c97184bdf8db328590d7a5a3604ea8d2", "size": 1731, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge3/Ex.2.6.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge3/Ex.2.6.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge3/Ex.2.6.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.4666666667, "max_line_length": 158, "alphanum_fraction": 0.5632582322, "num_tokens": 730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.9124361598816666, "lm_q1q2_score": 0.8422143143613255}}
{"text": "\n\\subsection{Modelling non-linear functions as linear}\n\n\\subsubsection{Polynomials}\n\nThe function \\(y=x^2\\) is not linear, however we can model is as linear, by including \\(x^2\\) as a variable.\n\nWe can expand this, and using linear models to estimate parameters for functions such as:\n\n\\(y=ax^3+bx^2+xz\\)\n\n\\subsubsection{Logarithms and exponentials}\n\nWe can also transform data using logarithms and exponents.\n\nFor example we can model\n\n\\(\\ln y=\\theta \\ln x\\)\n\n", "meta": {"hexsha": "33076ab73550e02bb06c3ded56825ecb76a88d17", "size": 461, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/ols/01-03-nonLinear.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/ols/01-03-nonLinear.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/ols/01-03-nonLinear.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.05, "max_line_length": 108, "alphanum_fraction": 0.748373102, "num_tokens": 120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9669140225647107, "lm_q2_score": 0.8705972717658209, "lm_q1q2_score": 0.8417927100769526}}
{"text": "\n\\subsection{Empty set}\n\nWe can use this to define the empty set - the set with no members.\n\n\\(\\varnothing =\\{\\}\\)\n\nUsing the above definition this is the same as writing:\n\n\\(\\forall x \\neg (x\\in \\varnothing )\\)\n\n\n", "meta": {"hexsha": "616efcc8af010b5fddabe7b658c97f5441a6dabd", "size": 214, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/setsSpecification/01-04-empty.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/setsSpecification/01-04-empty.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/setsSpecification/01-04-empty.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.4615384615, "max_line_length": 66, "alphanum_fraction": 0.6822429907, "num_tokens": 59, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9669140235181257, "lm_q2_score": 0.8705972616934406, "lm_q1q2_score": 0.8417927011678673}}
{"text": "\\section{Smoothing and Penalized Least Squares }\nIn Section 4.4.1 we saw that the smoothing spline solution to a\npenalized least squares is a linear smoother.\n\nUsing the notation of Section 4.4.1, we can write the penalized\ncriterion as \n\\[\n(\\by - \\bB\\bg{\\theta})'(\\by - \\bB\\bg{\\theta}) +\n\\lambda\\bg{\\theta}'\\bg{\\Omega}\\bg{\\theta}\n\\]\n\nSetting derivatives with respect to $\\bg{\\theta}$ equal to 0 gives\nthe estimating equation:\n\\[\n(\\bB'\\bB + \\lambda\\bg{\\Omega})\\bg{\\theta} = \\bB'\\by\n\\]\nthe $\\hat{\\bg{\\theta}}$ that solves this equation will give us the\nestimate $\\hat{\\g} = \\bB \\hat{\\bg{\\theta}}$.\n\n\nWrite:\n\\[\n\\hat{\\g} = \\bB \\bg{\\theta} = \\bB(\\bB'\\bB + \\lambda \\bg{\\Omega})^{-1}\n\\bB'\\by =  ({\\mathbf I} + \\lambda {\\mathbf K})^{-1}\\by\n\\]\nwhere ${\\mathbf K} = \\bB'^{-} \\bg{\\Omega} \\bB^{-}$. \n\nNotice we can\nwrite the penalized criterion as\n\\[\n(\\by - \\g)'(\\by - \\g) + \\lambda \\g' {\\mathbf K} \\g\n\\]\n\nIf we plot the rows of this linear smoother we will see that it is\nlike a kernel smoother.\n\n\n\n\\begin{figure}[htb]\n\\caption{Kernels of a smoothing spline.}\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-03.ps,angle=270,width=\\textwidth}\n\\end{center}\n\\end{figure}\n\nNotice that for any linear smoother  with a symmetric and nonnegative\ndefinite $\\bS$, i.e. there $\\bS^{-}$ exists, then \nwe can argue in reverse: $\\hat{\\f}=\\bS\\by$ is the value that minimizes the\npenalized least squares criteria of the form\n\\[\n(\\by - \\f)'(\\by - \\f) + \\f'(\\bS^{-} - I)\\f.\n\\]\n\nSome of the smoothers presented in this class are not symmetrical but\nare close. In fact for many of them one can show that asymptotically\nthey are symmetric.\n\n\n\n\n", "meta": {"hexsha": "a8ffda97187ccc2ac91b182a46c1432e31f838d0", "size": 1610, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-06-02.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-06-02.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-06-02.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 26.393442623, "max_line_length": 74, "alphanum_fraction": 0.6652173913, "num_tokens": 541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.9005297841157157, "lm_q1q2_score": 0.8414506772921225}}
{"text": "\\section{Non-Parametric Estimation of the CDF and Statistical Functionals}\n\n\\subsection{Empirical Distribution Function}\nIt may be necessary to perform non-parametric estimation of the CDF $F$ of a set of random variables $X_1, X_2, ... , X_n \\sim F$. \n\nThe empirical distribution function $\\hat{F}_n$ is the CDF that puts mass $1/n$ at each point $X_i$.\n\n\\begin{equation}\n\\hat{F}_n(x) = \\frac{\\sum_{i=1}^n I(X_i \\leq x)}{n}\n\\end{equation}\n\nWhere $I(X_i \\leq x) = \\left\\{\\begin{array}{c} 1\\ \\mathrm{if\\ } X_i \\leq x\\\\ 0\\ \\mathrm{if\\ } X_i > x \\end{array} \\right.$. \n\nThe empirical CDF is discrete, even when the random variable it is based on may be continuous. \n\nAt a given point $x$, $\\hat{F}_n(x)$ is an unbiased estimator of $F(x)$. \n\n\\begin{itemize}\n\\item $\\mathbb{E}\\hat{F}_n(x) = F(x)$\n\\item $\\mathbb{V}\\hat{F}_n(x) = 0+\\mathrm{MSE} = \\frac{F(x)(1-F(x))}{n}$\n\\item $\\hat{F}_n(x) \\xrightarrow{P} F(x)$\n\\end{itemize}\n\nThe Glivenko-Cantelli Theorem guarantees that, if $X_1,X_2,...,X_n \\sim F$, then:\n\n\\begin{equation}\n\\sup_x |\\hat{F}_n(x) - F(x)|\\xrightarrow{P} 0\n\\end{equation}\n\n\\subsection{Confidence Measures for the Empirical CDF}\nA confidence interval for the empirical CDF is given through the Dvoretzky-Kiefer-Wolfowitz (DKW) Inequality:\n\n\\begin{equation}\n\\mathbb{P}\\left(\\sup_x|F(x) - \\hat{F}_n(x)|>\\epsilon \\right)\\leq 2 e^{-2n\\epsilon^2}\n\\end{equation}\n\nA nonparametric $1-\\alpha$ confidence band is then:\n\n\\begin{equation}\n\\begin{array}{c}\nL(x) = \\max\\{\\hat{F}_n -\\epsilon_n, 0 \\}\\\\\n\\\\\nU(x) = \\min\\{\\hat{F}_n + \\epsilon_n, 1\\}\n\\end{array}\n\\end{equation}\n\nwith $\\epsilon_n = \\sqrt{\\frac{1}{2n}\\log\\left(\\frac{2}{\\alpha}\\right)}$.\n\n\\begin{equation}\n\\mathbb{P}\\left(L(x) \\leq F(x) \\leq U(x) \\right) \\geq 1-\\alpha\n\\end{equation}\n\t\n\n\n\\subsection{Statistical Functionals}\nA functional is, roughly speaking, a function of a function. The fourier transform of a function is a functional. A \\textit{statistical functional} is any function of the CDF, $F$. Examples are the mean, the variance, or the median. \n\n\\subsection{Plug-in Estimator}\nThe plug-in estimator of $\\theta = T(F)$ is given by $\\hat{\\theta} = T(\\hat{F}_n)$. In other words, the estimate of the CDF is used instead of the true $F$, resulting in an estimator.\n\n\\subsection{Linear Functionals}\nFunctionals of the form $T(F) = \\int r(x) dF(x)$ are linear functionals.  \n\n\\subsection{Plug-in Estimator for Linear Functionals}\n\\begin{equation}\nT(\\hat{F}_n) = \\int r(x) d\\hat{F}_n(x) = \\frac{1}{n}\\sum^{n}_{i=1}r(X_i)\n\\end{equation}\n\n\\subsection{Examples: Mean, Variance, Sample Variance, Sample Correlation}\n\\citeasnoun{wasserman2013all} pp. 100\n", "meta": {"hexsha": "8a09ede0ac4149965eac85c64b232e920601f611", "size": 2614, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/stats_functionals.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/stats_functionals.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/stats_functionals.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.8169014085, "max_line_length": 233, "alphanum_fraction": 0.6931905126, "num_tokens": 920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.907312219480915, "lm_q1q2_score": 0.8414080536812211}}
{"text": "\\section{Limit Definition}\r\n\\begin{definition}\r\n\tLet $f : D \\subseteq \\R \\to \\R$.\r\n\tLet $c \\in R$ be a limit point (ie $c \\in D$ or $c$ is on the boundary of $D$).\r\n\t$f$ has a limit $L$ as $x$ approaches $c$ if for any given positive real number $\\epsilon$, there is a positive real number $\\delta$ such that for all $x \\in D$,\r\n\t\\begin{equation}\r\n\t\t0 < \\abs{x-c} < \\delta \\implies \\abs{f(x) - L} < \\epsilon.\r\n\t\\end{equation}\r\n\tWe write this as\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x \\to c}{f(x)} = L.\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\r\n\\begin{figure}[H]\r\n\t\\label{epsilon_delta}\r\n\t\\centering\r\n\t\\includegraphics[width = 0.5\\textwidth]{./limits_continuity/limit_epsilon_delta.png}\r\n\t\\caption{\\hyperref{https://en.wikipedia.org/wiki/(\\%CE\\%B5,\\_\\%CE\\%B4)-definition\\_of\\_limit}{}{}{Wikipedia - $(\\epsilon, \\delta)\\text{-definition of limit}$}}\r\n\\end{figure}\r\n\r\nVisually, what this means is that for any ``error bound'' of $y$ values $\\epsilon$, I can give you a corresponding error bound of $x$ values $\\delta$ such that all values of $f(z)$ for $z \\in (c -\\delta, c+ \\delta)$ bound are between $L - \\epsilon$ and $L + \\epsilon$.\r\n\r\n\r\nWe don't use this definition of the limit very often because it's a bit cumbersome.\r\nHowever, it's important to know that when we use the limit, this is the formal definition making things work.\r\n\r\n\\begin{example}\r\n\tUse the $(\\epsilon, \\delta)$ definition of the limit to show that\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x\\to 0}{x\\sin{\\frac{1}{x}}} = 0.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tLetting $\\epsilon > 0$, we need to find corresponding $\\delta > 0$ that satisfies the definition for $L = 0$.\r\n\tKnowing that $\\sin$ is bounded between -1 and 1,\r\n\t\\begin{equation*}\r\n\t\t\\abs{x\\sin{\\frac{1}{x}} - 0} = \\abs{x\\sin{\\frac{1}{x}}} = \\abs{x}\\abs{\\sin{\\frac{1}{x}}} \\leq \\abs{x}.\r\n\t\\end{equation*}\r\n\t\r\n\tLetting $\\delta = \\epsilon$, if $0 < \\abs{x - 0} < \\delta$, then $\\abs{x\\sin{\\frac{1}{x}} - 0} \\leq \\abs{x} < \\epsilon$, as required by the definition.\r\n\\end{answer}", "meta": {"hexsha": "1fa0d9577de8cc515ab36c3b6271642365fa6fc1", "size": 1998, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/limits_continuity/limit_definition.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/limits_continuity/limit_definition.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/limits_continuity/limit_definition.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 47.5714285714, "max_line_length": 269, "alphanum_fraction": 0.6491491491, "num_tokens": 673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966686936261, "lm_q2_score": 0.8887587927558434, "lm_q1q2_score": 0.8412961124948501}}
{"text": "\n\\subsection{Limit points and closure}\n\n\\subsubsection{Limit points}\n\nA point \\(x\\) in the topological set \\(X\\) is a limit point for \\(S\\subset X\\) if every neighbourhood of \\(x\\) contains another point in \\(S\\).\n\nFor example \\(-1\\) is a limit point for the real numbers where \\(S\\) is \\([0,1]\\) (or \\((0,1)\\).\n\n\\subsubsection{Closure}\n\nThe closure of a subset of a topological space is the subset itself along with all limit points.\n\nSo the closure of \\(|x|<1\\) includes \\(-1\\) and \\(1\\).\n\n", "meta": {"hexsha": "27f97354f35009fedbd35e83759c2c8b2740f873", "size": 492, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/topologyFinite/02-01-closure.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/topologyFinite/02-01-closure.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/topologyFinite/02-01-closure.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.75, "max_line_length": 143, "alphanum_fraction": 0.6788617886, "num_tokens": 137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750400464604, "lm_q2_score": 0.8824278710924295, "lm_q1q2_score": 0.8411964641537485}}
{"text": "% !TeX root = ../main.tex\n% Add the above to each chapter to make compiling the PDF easier in some editors.\n\n\\chapter{Groups and Homomorphisms}\n\\section{Groups}\n\\begin{defn}[Semigroup, Monoid, and Group]\\leavevmode\n\\begin{defnlist}\n    \\item A set $G$ with a mapping $\\cdot$ on $G$ (that is, $\\cdot: G \\times G \\to G$) is named \\begin{itemize}\n        \\item \\emph{semigroup}\\index{semigroup} if $\\forall a, b, c \\in G.\\ (a \\cdot b) \\cdot c = a \\cdot (b \\cdot c)$; \\margintag{\\emph{associativity}\\index{associativity}}\n        \\item \\mbox{\\emph{monoid}\\index{monoid} if it is a semigroup and $\\exists e \\in G.\\ \\forall a \\in G.\\ e \\cdot a = a \\cdot e = a$; \\margintag{$e$ is called \\emph{neutral element}\\index{neutral element}}}\n        \\item \\emph{group}\\index{group} if it is a monoid and $\\forall a \\in G.\\ \\exists a' \\in G.\\ a \\cdot a' = a' \\cdot a = e$. \\margintag{$a'$ is the \\emph{inverse element}\\index{inverse element} of $a$}\n    \\end{itemize}\n    \n    \\item A group $(G,\\cdot)$ is named \\emph{abelian}\\index{abelian group} or \\emph{commutative}\\index{commutativity} if the group operation $\\cdot$ is commutative under elements of $G$, \\begin{align}\n        \\forall a, b \\in G.\\quad a \\cdot b = b \\cdot a.\n    \\end{align}\n    \n    \\begin{marginfigure}\n        We denote groups by $(G,\\cdot)$. If the group operation $\\cdot$ is clear from context, we refer to the group simply as $G$. Subsequently, we also write $a b$ instead of $a \\cdot b$.\n    \\end{marginfigure}\n\\end{defnlist}\n\\end{defn}\n\n\\begin{rmk}\nLet $G$ be a group. Then, \\begin{rmklist}\n    \\item there is exactly one neutral element $e \\in G$ and for every $a \\in G$ there is exactly one inverse element $a' \\in G$, which we call $\\inv{a}$;\n    \\item the mapping on $G$, which we refer to by $\\cdot$, may be resembled by any symbol;\n    \\item if $G$ is abelian, often \\begin{itemize}\n        \\item $+$ is used instead of $\\cdot$,\n        \\item $0$ is used instead of $e$, and\n        \\item $-a$ is used instead of $\\inv{a}$.\n    \\end{itemize}\n\\end{rmklist}\n\\end{rmk}\n\n\\begin{ex}{Semigroups, monoids, and groups}{}\n\\begin{center}\n\\setlength\\tabcolsep{5pt}\n\\begin{tabular}{lrrrrr}\n\\toprule\n & $(\\NO,+)$ & $(\\NZ,+)$ & $(\\Z,+)$ & $(\\Z,\\cdot)$ & $(\\woZ{\\Q},\\cdot)$ \\\\\n \\midrule\n semigroup & yes & yes & yes & yes & yes \\\\\n \\addlinespace\n monoid & no & yes & yes & yes & yes \\\\\n \\addlinespace\n group & yes & no & yes & no & yes \\\\\n \\bottomrule\n\\end{tabular}\n\\end{center}\n\\end{ex}\n\n\\begin{ex}{General linear and special linear group}{}\nThe \\emph{general linear group}\\index{general linear group} $\\GL{n}{K}$ is the group of invertible\\marginfootnote{Recall from linear algebra that a matrix $\\mA$ is invertible iff $\\det{\\mA} \\neq 0$.} ${n \\times n}$ linear maps over a field\\marginfootnote[1\\baselineskip]{A \\emph{field}\\index{field} is a set of elements with well-defined operations for addition, subtraction, multiplication, and division. We give a formal definition in \\cref{defn:field}. Examples of fields are the rational numbers $\\Q$, the real numbers $\\R$, and the complex numbers $\\C$.} $K$, \\begin{align}\n    \\GL{n}{K} \\defeq \\{\\mA \\in K^{n \\times n} \\mid \\det{\\mA} \\neq 0\\}.\n\\end{align}\n\nThe \\emph{special linear group}\\index{special linear group} $\\SL{n}{K}$ is the group of normed linear maps over the field $K$, \\begin{align}\n    \\SL{n}{K} \\defeq \\{\\mA \\in K^{n \\times n} \\mid \\det{\\mA} = 1\\}.\n\\end{align}\n\nThe group operation of $\\GL{n}{K}$ and $\\SL{n}{K}$ is matrix multiplication. Their neutral element is the identity matrix $\\mI$, and the inverse elements are the matrix inverses $\\inv{\\mA}$.\n\\end{ex}\n\n\\begin{ex}{Abelian groups}{}\n\\begin{itemize}\n    \\item $(\\Z,+)$\n    \\item $(\\Q,+)$\n    \\item $(\\R,+)$\n    \\item $(\\woZ{\\R},\\cdot)$\n\\end{itemize}\n\\end{ex}\n\n\\begin{ex}{Symmetric group}{}\nThe \\emph{symmetric group}\\index{symmetric group} $S_n$ is the group of bijections on the set $[n]$, \\begin{align}\n    S_n \\defeq \\{\\sigma : [n] \\to [n] \\mid \\text{$\\sigma$ is bijective}\\},\n\\end{align} with the function composition ``$\\circ$'' as mapping.\n\nElements of the symmetric group ${\\sigma \\in S_n}$ are called \\emph{permutations}\\index{permutation}. The neutral element of the symmetric group is the identity $\\id$, which maps each input to itself.\n\nThere are multiple ways of representing permutations. Perhaps the most natural representation of ${\\sigma \\in S_n}$ is a mapping in \\emph{two-line notation}\\index{two-line notation}, \\begin{align}\n    \\sigma = \\begin{pmatrix}\n        1 & 2 & \\cdots & n \\\\\n        \\sigma(1) & \\sigma(2) & \\cdots & \\sigma(n) \\\\\n    \\end{pmatrix},\n\\end{align} or in \\emph{one-line notation}\\index{one-line notation} by simply omitting the first line, \\begin{align}\n    \\sigma = (\\sigma(1)\\ \\sigma(2)\\ \\cdots\\ \\sigma(n)).\n\\end{align}\n\nAn alternative characterization of a permutation is as a product of (disjoint) cycles. A \\emph{cycle}\\index{cycle} ${\\rho \\in S_n}$ is a permutation that maps a subset of numbers ${\\{i_1, i_2, \\dots, i_r\\} \\subseteq [n]}$ in a cyclic fashion. That is, \\begin{align}\n    \\rho(i_1) = i_2,\\quad \\rho(i_2) = i_3,\\quad \\cdots\\quad \\rho(i_{r-1}) = i_r,\\quad \\rho(i_r) = i_1,\n\\end{align} leaving all other ${j \\in [n]}$ fixed. We denote such a cycle by \\begin{align}\n    \\rho = (i_1\\ i_2\\ \\cdots\\ i_r).\n\\end{align} A cycle of length $r$, is also called \\emph{$r$-cycle}. 2-cycles are called \\emph{transpositions}\\index{transposition}.\n\nEvery permutation ${\\sigma \\in S_n}$ can be written as a ``product'' (i.e., composition), \\begin{align}\n    \\sigma = \\rho_1 \\cdots \\rho_s,\n\\end{align} where $\\rho_i$ are cycles with pairwise disjunct elements. This is also known as the \\emph{cycle notation}\\index{cycle notation} of $\\sigma$. Note that the ordering of $\\rho_1, \\dots \\rho_s$ does not matter, as their elements are disjoint.\n\nThe cycle lengths $r_1, \\dots, r_s$ (in descending order) of $\\rho_1, \\dots, \\rho_s$ are the \\emph{cycle type}\\index{cycle type} of $\\sigma$.\n\n\\begin{rmk}\nThe symmetric group is not abelian.\n\\end{rmk}\\vspace{-20pt}\\begin{proof}\nWe have $(1\\ 2)(2\\ 3) = (2\\ 3\\ 1)$ and $(2\\ 3)(1\\ 2) = (1\\ 3\\ 2)$.\n\\end{proof}\n\\end{ex}\n\n\\begin{lem}[Notation and Rules]\nLet $(G,\\cdot)$ be a group. \\begin{lemlist}\n    \\item For $a \\in G, n \\in \\NZ$, we write \\begin{itemize}\n        \\item $a^n \\defeq \\underbrace{a \\cdot a \\cdots a}_{\\text{$n$ many}}$,\n        \\item $a^0 \\defeq e$, and\n        \\item $a^{-n} \\defeq \\underbrace{\\inv{a} \\cdot \\inv{a} \\cdots \\inv{a}}_{\\text{$n$ many}}$.\n    \\end{itemize}\n    \n    \\item $\\forall a, b \\in G.\\ \\forall m, n \\in \\Z.$ \\begin{nestedlemlist}\n        \\item $\\inv{(\\inv{a})} = a$\n        \\item $a^m \\cdot a^n = a^{m+n}$, $(a^m)^n = a^{m \\cdot n}$\n        \\item $\\inv{(a \\cdot b)} = \\inv{b} \\cdot \\inv{a}$\n    \\end{nestedlemlist}\n\\end{lemlist}\n\\end{lem}\n\\begin{proof}[Proof of (b)(iii)] $(a \\cdot b) \\cdot \\inv{b} \\cdot \\inv{a} = a \\cdot \\underbrace{(b \\cdot \\inv{b})}_{=e} \\cdot \\inv{a} = a \\cdot \\inv{a} = e$.\n\\end{proof}\n\n\\begin{defn}[Subgroup]\\label{defn:subgroup}\nA subset $U \\subseteq G$ is called a \\emph{subgroup}\\index{subgroup} of a group $G$ (denoted $U \\subgroup G$) if $U$ itself is a group with mapping $\\cdot$. That is, $U$ is a subgroup iff \\begin{defnlist}\n    \\item $e \\in U$; \\margintag{$U$ contains the neutral element}\n    \\item $\\forall a, b \\in U.\\quad a \\cdot b \\in U$; and \\margintag{the mapping $\\cdot$ is closed wrt. $U$}\n    \\item $\\forall a \\in U.\\quad \\inv{a} \\in U.$ \\margintag{the mapping $\\inv{(\\dots)}$ is closed wrt. $U$}\n\\end{defnlist} Associativity follows from $G$ being a group.\n\\end{defn}\n\n\\begin{ex}{Subgroups}{}\n\\begin{itemize}\n    \\item $\\{e\\}, G \\subgroup G$ (\\emph{trivial subgroups}\\index{trivial subgroups})\n    \\item $\\SL{n}{K} \\subgroup \\GL{n}{K}$\n    \\item Let $2\\Z \\defeq \\{2m \\mid m \\in \\Z\\}$, then $(2\\Z,+) \\subgroup (\\Z,+)$\n\\end{itemize}\n\\end{ex}\n\n\\begin{rmk}\\label{rmk:cap_subgroup}\nIf $\\{U_i\\}_{i \\in I}$ are subgroups of $G$, then $\\bigcap_{i \\in I} U_i \\subgroup G$.\n\\end{rmk}\n\n\\begin{defn}[Generated Subgroup]\nFor any $M \\subseteq G$, \\begin{align}\n    \\gen{M} \\defeq \\bigcap_{\\substack{U \\subgroup G \\\\ M \\subseteq U}} U \\subgroup G, \\margintag{by \\cref{rmk:cap_subgroup}}\n\\end{align} is the \\emph{subgroup generated by $M$}\\index{generated subgroup}. In particular, $\\gen{M}$ is the ``smallest'' subgroup that includes $M$.\n\\end{defn}\n\n\\begin{lem}\nFor $M \\neq \\emptyset$, we have \\begin{align}\n    \\gen{M} = \\{a_1 \\cdot a_2 \\cdots a_n \\mid n \\in \\N, \\text{$a_i \\in M$ or $\\inv{a_i} \\in M$}\\}.\n\\end{align}\n\\end{lem} \\begin{proof}[Proof (sketch)]\\leavevmode\nLet $N \\defeq \\{a_1 \\cdot a_2 \\cdots a_n \\mid n \\in \\N, \\text{$a_i \\in M$ or $\\inv{a_i} \\in M$}\\}$.\n\\begin{itemize}\n    \\item \\underline{$\\gen{M} \\subseteq N$}: $N \\subgroup G$ and $M \\subseteq N \\implies \\gen{M} \\subseteq N$ \\margintag{using that $\\gen{M}$ is the smallest subgroup including $M$}\n    \\item \\underline{$N \\subseteq \\gen{M}$}: if $U \\subgroup G$ with $M \\subseteq U$, then $U$ includes all of these products $\\implies N \\subseteq U \\implies N \\subseteq \\gen{M}$ \\qedhere\n\\end{itemize}\n\\end{proof}\n\n\\begin{ex}{Generated subgroup}{}\n$S_3 = \\{\\id, \\underbrace{(1\\ 2)}_{\\tau_1}, \\underbrace{(1\\ 3)}_{\\tau_2}, \\underbrace{(2\\ 3)}_{\\tau_3}, \\underbrace{(1\\ 2\\ 3)}_{\\sigma_1}, \\underbrace{(1\\ 3\\ 2)}_{\\sigma_2}\\} = \\gen{\\{\\underbrace{(1\\ 2)}_{\\tau_1}, \\underbrace{(1\\ 2\\ 3)}_{\\sigma_1}\\}}$.\n\\end{ex}\n\n\\begin{defn}[Cyclic Group]\nA group $G$ is \\emph{cyclic}\\index{cyclic group} if $\\exists a \\in G$ with \\begin{align}\n    G = \\gen{a} \\defeq \\gen{\\{a\\}} = \\{a^m \\mid m \\in \\Z\\}.\n\\end{align} Such an $a \\in G$, is called a \\emph{generator}\\index{generator} of $G$.\n\\end{defn}\n\n\\begin{marginfigure}\n    \\includegraphics[width=\\textwidth]{c_cyclic_subgroup.png}\n    \\caption{An illustration of the cyclic subgroup $\\gen{i}$ in the complex plane.}\n\\end{marginfigure}\n\n\\begin{ex}{Cyclic groups}{}\n\\begin{itemize}\n    \\item $\\gen{i} = \\{i^m \\mid m \\in \\Z\\}$ is a cyclic subgroup of $(\\woZ{\\C},\\cdot)$, \\begin{align*}\n        \\gen{i} &= \\{\\dots, \\underbrace{i^{-2}}_{=-1}, \\underbrace{i^{-1}}_{=-i}, 1, i, \\underbrace{i^2}_{=-1}, \\underbrace{i^3}_{=-i}, \\underbrace{i^4}_{=1}, \\underbrace{i^5}_{=i}, \\dots\\} \\\\\n                &= \\{1, i, -1, -i\\}.\n    \\end{align*}\n    \\item $(\\Z,+) = \\gen{1} = \\{\\dots, -2, -1, 0, 1, 2, \\dots\\}$ is cyclic\n\\end{itemize}\n\\end{ex}\n\n\\begin{defn}[Order]\\index{order}\nLet $G$ be a group.\n\\begin{defnlist}\n    \\item The cardinality $|G| \\in \\wInfty{\\N}$ is called \\emph{order} of the group $G$.\n    \\item For any $a \\in G$, $o(a) \\defeq |\\gen{a}|$ is the \\emph{order} of the element $a$.\n\\end{defnlist} If $|G| < \\infty$, $G$ is called \\emph{finite}\\index{finite group}.\n\\end{defn}\n\n\\begin{lem}\nIf $k \\defeq o(a) < \\infty$, we have \\begin{lemlist}\n    \\item $o(a) = \\min\\{j \\in \\N \\mid a^j = e\\}$;\n    \\item $\\gen{a} = \\{e, a, a^2, \\dots, a^{k-1}\\}$; and\n    \\item\\label{lem:order_identity} For any $j \\in \\Z$, $a^j = e \\iff \\divides{o(a)}{j}$.\\footnote{We use $\\divides{a}{b}$ to denote that $a$ divides $b$.}\n\\end{lemlist}\n\\end{lem} \\begin{proof}\nWe write $m \\defeq \\min\\{j \\in \\N \\mid a^j = e\\}$. \\begin{itemize}\n    \\item \\underline{$\\{e, a, a^2, \\dots, a^{m-1}\\} \\subseteq \\gen{a}$}: Let us fix an arbitrary $j \\in \\N$. We have, \\begin{align*}\n        o(a) = |\\gen{a}| < \\infty &\\implies \\exists j' > j.\\ a^j = a^{j'} \\margintag{as the order of $a$ is finite} \\\\\n                                  &\\implies a^{j'-j} = e \\margintag{by multiplying from the right with $a^{-j}$} \\\\\n                                  &\\implies \\text{$m$ exists and $\\{e, a, a^2, \\dots, a^{m-1}\\} \\subseteq \\gen{a}$}. \\margintag{as $j'-j \\in \\N$ is again a natural number}\n    \\end{align*}\n    \\item \\underline{$\\gen{a} \\subseteq \\{e, a, a^2, \\dots, a^{m-1}\\}$}: We fix any $n \\in \\Z$. Then, by \\emph{long division}\\index{long division}, there exist $q, r \\in \\Z$ and $0 \\leq r < m$ with $n = q \\cdot m + r$. This yields, \\begin{align*}\n        a^n = a^{q \\cdot m + r} = \\underbrace{(a^m)^q}_{=e} \\cdot a^r = a^r \\in \\{e, a, a^2, \\dots, a^{m-1}\\}.\n    \\end{align*}\n\\end{itemize} This proves that $m = o(a)$ and $\\gen{a} = \\{e, a, a^2, \\dots, a^{m-1}\\}$. It also follows that \\begin{align*}\n    a^n = e \\iff r = 0 \\iff \\divides{m}{n}. &\\qedhere\n\\end{align*}\n\\end{proof}\n\n\\begin{rmk}\nFor a finite cyclic group $\\gen{a} = \\{e, a, a^2, \\dots, a^{k-1}\\}$ of order $k$, we have $a^{k-j} = a^{-j}$.\n\\end{rmk}\n\n\\begin{ex}{Order}{}\n\\begin{itemize}\n    \\item Let us consider $\\GL{2}{\\R}$. Then, \\begin{align*}\n        \\mA = \\begin{bmatrix}\n            2 & 0 \\\\\n            0 & 2 \\\\\n        \\end{bmatrix} &\\implies \\forall n \\in N.\\ \\mA^n = \\begin{bmatrix}\n            2^n & 0 \\\\\n            0 & 2^n \\\\\n        \\end{bmatrix} \\neq \\mI \\\\ &\\implies o(\\mA) = \\infty, \\\\\n        \\mB = \\begin{bmatrix}\n            0 & 1 \\\\\n            -1 & 0 \\\\\n        \\end{bmatrix} &\\implies \\begin{multlined}[t]\\mB^2 = \\begin{bmatrix}\n            -1 & 0 \\\\\n            0 & -1 \\\\\n        \\end{bmatrix}, \\\\ \\mB^3 = -\\mB = \\begin{bmatrix}\n            0 & -1 \\\\\n            1 & 0 \\\\\n        \\end{bmatrix}, \\mB^4 = (\\mB^2)^2 = \\mI\\end{multlined} \\\\ &\\implies o(\\mB) = 4.\n    \\end{align*}\n    \n    \\item $|S_n| = |\\{\\sigma : [n] \\to [n] \\mid \\text{$\\sigma$ is bijective}\\}| = n!$\n\\end{itemize}\n\\end{ex}\n\n\\begin{ex}{Subgroups of $S_3$}{s3_subgroups}\nLet us find the subgroups of \\begin{align*}\n    S_3 = \\{\\id, (1\\ 2), (1\\ 3), (2\\ 3), (1\\ 2\\ 3), (1\\ 3\\ 2)\\}.\n\\end{align*} We immediately obtain the trivial subgroups $\\{\\id\\}$ and $S_3$ or order $1$ and $6$, respectively. It is a simple exercise to confirm the following cyclic subgroups: \\begin{itemize}\n    \\item $\\gen{(1\\ 2)} = \\{\\id, (1\\ 2)\\}$\n    \\item $\\gen{(1\\ 3)} = \\{\\id, (1\\ 3)\\}$\n    \\item $\\gen{(2\\ 3)} = \\{\\id, (2\\ 3)\\}$\n    \\item $\\gen{(1\\ 2\\ 3)} = \\gen{(1\\ 3\\ 2)} = \\{\\id, (1\\ 2\\ 3), (1\\ 3\\ 2)\\}$\n\\end{itemize} The first three subgroups generated by 2-cycles are of order 2, the last subgroup generated by the 3-cycles is of order 3.\n\nObserve that the subgroup orders are divisors of the group order. This is not coincidental, we will make this precise in the following. In doing so, we will also find that our list of subgroups of $S_3$ was indeed exhaustive.\n\\end{ex}\n\n\\begin{marginfigure}\n    \\includegraphics[width=\\textwidth]{s3_subgroup_graph.png}\n    \\caption{Subgroup graph of the symmetric group $S_3$. The order of the subgroups is shown in orange.}\\label{fig:s3_subgroup_graph}\n\\end{marginfigure}\n    \nThe subgroup structure of a group $G$ can be graphically represented in a \\emph{subgroup graph}\\index{subgroup graph}. Subgroups of $G$ are represented as vertices. Groups $U$ and $V$ are connected if $U \\subgroup V$ and there exists no subgroup ``between'' $U$ and $V$. An example is given in \\cref{fig:s3_subgroup_graph}.\n\n\\begin{defn}[Cosets and Index]\nLet $U \\subgroup G$ be a subgroup.\n\\begin{defnlist}\n    \\item For $a \\in G$, \\begin{align}\n        aU &\\defeq \\{a \\cdot u \\mid u \\in U\\}, \\label{eq:left_coset} \\\\\n        Ua &\\defeq \\{u \\cdot a \\mid u \\in U\\},\n    \\end{align} are the left\\index{left coset} and right\\index{right coset} \\emph{coset}\\index{coset} of $U$ in $G$, respectively.\n    \\item\\label{defn:index} The \\emph{index}\\index{index} $[G : U] \\defeq |\\{aU \\mid a \\in G\\}|$ of $U$ in $G$ is defined as the number of cosets of $U$ in $G$.\\footnote{The number of left cosets is identical to the number of right cosets.}\n\\end{defnlist}\n\\end{defn}\n\n\\begin{lem}\nFor all $a, b \\in G$, we have\n\\begin{lemlist}\n    \\item $aU = U \\iff a \\in U$\n    \\item\\label{lem:cosets_eq} $aU = bU \\iff \\inv{a} b \\in U$\n    \\item $aU \\cap bU \\neq \\emptyset \\iff aU = bU$\n    \\item $G = \\bigcup_{a \\in G} aU$\n    \\item\\label{lem:cosets_size} $|aU| = |U|$\n\\end{lemlist}\n\\end{lem} \\begin{proof}[Proof of (e)]\n$U \\to aU, u \\mapsto a \\cdot u$ is a bijective mapping. Hence, domain and codomain are of the same size.\n\\end{proof}\n\n\\begin{thm}[Lagrange's Theorem]\\index{Lagrange's theorem}\\label{thm:lagrange}\nIf $G$ is a finite group and $U \\subgroup G$ is some subgroup, then \\begin{align}\n    |G| = |U| \\cdot [G : U].\n\\end{align} In particular, $|U|$ and $[G : U]$ are divisors of $|G|$.\n\\end{thm} \\begin{proof}\nLet $r \\defeq \\Index{G}{U}$. Then we can write $G$ as a disjoint union of cosets, \\begin{align*}\n    G = a_1 U \\cupdot a_2 U \\cupdot \\cdots \\cupdot a_r U.\n\\end{align*} We have, \\begin{align*}\n    |G| = \\sum_{i=1}^r |a_i U| = r \\cdot |U| = \\Index{G}{U} \\cdot |U|. \\margintag{using that $|a_i U| = |U|$ by \\cref{lem:cosets_size}} &\\qedhere\n\\end{align*}\n\\end{proof}\n\n\\begin{cor}\nLet $G$ be a finite group. Then we have for any $a \\in G$, \\begin{corlist}\n    \\item $\\divides{o(a)}{|G|}$\n    \\item $a^{|G|} = e$ \\quad (\\emph{Fermat's little theorem}\\index{Fermat's little theorem})\n\\end{corlist}\n\\end{cor} \\begin{proof}\n\\leavevmode\\begin{corlist}\n\\item By \\hyperref[thm:lagrange]{Lagrange's theorem}, $\\divides{|\\gen{a}|}{|G|}$.\n\\item By \\cref{lem:order_identity}, $a^{|G|} = e \\iff \\divides{o(a)}{|G|}$. \\qedhere\n\\end{corlist}\n\\end{proof}\n\n\\begin{cor}\\label{cor:prime_group_is_cyclic}\nLet $G$ be a group such that $|G| = p$ where $p$ is prime. Then, $G$ is cyclic.\n\\end{cor} \\begin{proof}\n\\begin{align*}\n    |G| > 1 &\\implies \\exists a \\in G \\setminus \\{e\\} \\\\\n            &\\implies \\divides{1 \\neq |\\gen{a}|}{|G|} \\margintag{using that $o(a) \\geq 2$ if $a \\neq e$ and \\hyperref[thm:lagrange]{Lagrange's theorem}} \\\\[5pt]\n            &\\implies |\\gen{a}| = p = |G|. \\margintag{using that $|G|$ only has divisors $1$ and $p$}\n\\end{align*} Therefore, $\\gen{a} = G$.\n\\end{proof}\n\n\\begin{ex}{Subgroups of $S_3$ (continued)}{}\nWe will now see that $S_3$ has exactly four non-trivial subgroups, proving that we have found all subgroups of $S_3$ in \\cref{ex:s3_subgroups}.\n\nLet ${U \\subgroup S_3}$ be a non-trivial subgroup. By \\hyperref[thm:lagrange]{Lagrange's theorem}, we have ${\\divides{|U|}{|S_3| = 3! = 6}}$. As we have excluded the trivial subgroups $\\{\\id\\}$ and $S_3$, we know that ${|U| \\neq 1, 6}$. This leaves us with ${|U| \\in \\{2,3\\}}$.\n\nObserve that $2$ and $3$ are prime, hence, by \\cref{cor:prime_group_is_cyclic} $U$ must be cyclic. Recall that we have already enumerated all (four) cyclic subgroups of $S_3$ in \\cref{ex:s3_subgroups}.\n\\end{ex}\n\n\\section{Homomorphisms}\nWe will now consider two groups $(G,\\cdot)$ and $(H,\\cdot)$. To understand the relationship between $G$ and $H$, it is useful to look at mappings between the two groups. A special mapping that (as we will see) preserves the structure of a group, is the group homomorphism.\n\n\\begin{defn}[(Group) Homomorphism]\n\\leavevmode\\begin{defnlist}\n    \\item The mapping $\\varphi : G \\to H$ is called a \\emph{(group) homomorphism}\\index{homomorphism}\\index{group homomorphism} if \\begin{align}\n        \\forall a, b \\in G.\\quad \\varphi(a \\cdot b) = \\varphi(a) \\cdot \\varphi(b). \\label{eq:homomorphism}\n    \\end{align} The homomorphism $\\psi : G \\to G$ is called \\emph{endomorphism}\\index{endomorphism} of $G$.\n    \\item The set of elements that are mapped to the neutral element $e_H$, \\begin{align}\n        \\ker{\\varphi} \\defeq \\{a \\in G \\mid \\varphi(a) = e_H\\} \\subseteq G, \\label{eq:kernel}\n    \\end{align} is called the \\emph{kernel}\\index{kernel} of $\\varphi$.\n    \\item The set of elements in the codomain $H$ that $\\varphi$ maps to, \\begin{align}\n        \\im{\\varphi} \\defeq \\{\\varphi(a) \\mid a \\in G\\} \\subseteq H,\n    \\end{align} is called the \\emph{image}\\index{image} of $\\varphi$.\n\\end{defnlist}\n\\end{defn}\n\n\\begin{ex}{Homomorphisms}{homomorphisms}\n\\begin{itemize}\n    \\item ${\\varphi : G \\to H, a \\mapsto e_H}$ is the \\emph{trivial homomorphism}\\index{trivial homomorphism}\n    \n    \\item For any field $K$, ${\\det : \\GL{n}{K} \\to \\woZ{K}, \\mA \\mapsto \\det{\\mA}}$ is a homomorphism due to the multiplicativity of the determinant.\\marginfootnote{Recall that $\\det{(\\mA \\cdot \\mB)} = \\det{\\mA} \\cdot \\det{\\mB}$.} We have for its kernel, \\begin{align}\n        \\ker{\\det} = \\{\\mA \\in \\GL{n}{K} \\mid \\det{\\mA} = 1\\} = \\SL{n}{K}. \\label{eq:det_kernel}\n    \\end{align}\n    \n    \\item Let us consider the \\emph{sign}\\index{sign} of a permutation, \\begin{align}\n        \\sgn : S_n \\to \\{-1, 1\\}, \\sigma \\mapsto (-1)^{N(\\sigma)},\n    \\end{align} where $N(\\sigma)$ is the number of inversions in $\\sigma$. An \\emph{inversion}\\index{inversion} in $\\sigma$ is a pair of elements that is out of order. More formally, \\begin{align}\n        N(\\sigma) = |\\{(i,j) \\mid \\text{$i < j$ and $\\sigma(i) > \\sigma(j)$}\\}|.\n    \\end{align} For an $r$-cycle the sign reduces to, \\begin{align}\n        \\sgn{\\underbrace{(i_1\\ \\cdots\\ i_r)}_{\\text{$r$-cycle}}} = (-1)^{r-1}.\n    \\end{align}\n    \n    It can be shown that $\\sgn$ is a homomorphism, that is, \\begin{align}\n        \\forall \\sigma, \\tau \\in S_n.\\quad \\sgn{(\\sigma \\circ \\tau)} = \\sgn{\\sigma} \\cdot \\sgn{\\tau}.\n    \\end{align} The kernel of $\\sgn$ is the set of permutations with positive sign, \\begin{align}\n        \\ker{\\sgn} = \\{\\sigma \\in S_n \\mid \\sgn{\\sigma} = 1\\} \\eqdef A_n. \\label{eq:alternating_group}\n    \\end{align} This set forms again a group, which is known as the \\emph{alternating group}\\index{alternating group} $A_n$.\n    \n    \\item Within the group $(\\Z,+)$, $\\varphi : \\Z \\to \\Z, m \\mapsto 2 m$ is an endomorphism.\n\\end{itemize}\n\\end{ex}\n\n\\begin{lem}[Properties of Homomorphisms]\nLet $\\varphi : G \\to H$ be a homomorphism. Then,\n\\begin{lemlist}\n    \\item $\\varphi(e_G) = e_H$\n    \\item $\\forall g \\in G.\\ \\varphi(\\inv{g}) = \\inv{\\varphi(g)}$\n    \\item\\label{lem:homomorphism_kernel_subgroup} $\\ker{\\varphi} \\subgroup G$ and $\\im{\\varphi} \\subgroup H$\n    \\item $\\text{$\\varphi$ injective} \\iff \\ker{\\varphi} = \\{e_G\\}$\n    \\item if $\\psi : H \\to K$ is a homomorphism, then $\\psi \\circ \\varphi : G \\to K$ is a homomorphism\n\\end{lemlist}\n\\end{lem} \\begin{marginfigure}\n    \\includegraphics[width=\\textwidth]{injective_surjective.png}\n    \\caption{An illustration of \\emph{injectivity}\\index{injective} and \\emph{surjectivity}\\index{surjective}. When a function $\\varphi$ is injective, $\\varphi(a) = \\varphi(b)$ implies $a = b$. We call a function \\emph{bijective}\\index{bijective} is it is both injective and surjective, i.e., a one-to-one mapping.}\n\\end{marginfigure} \\begin{proof}\n\\leavevmode\\begin{lemlist}\n    \\item We have $\\varphi(e_G) = \\varphi(e_G \\cdot e_G) = \\varphi(e_G) \\cdot \\varphi(e_G)$, using the compatibility of a homomorphism with the group structure \\eqref{eq:homomorphism}. By multiplying with $\\inv{\\varphi(e_G)}$ from one side, we obtain that this statement is true if and only if $\\varphi(e_G) = e_H$.\n    \n    \\item Again, using the homomorphism property, we have, \\begin{align*}\n        e_H = \\varphi(e_G) = \\varphi(g \\cdot \\inv{g}) = \\varphi(g) \\cdot \\varphi(\\inv{g}).\n    \\end{align*} By multiplying from the left with $\\inv{\\varphi(g)}$, we obtain that this statement is true if and only if $\\inv{\\varphi(g)} = \\varphi(\\inv{g})$.\n    \n    \\item Let us confirm the properties of subgroups for $\\ker{\\varphi} \\subgroup G$. The proof is analogous for $\\im{\\varphi} \\subgroup H$. By \\cref{defn:subgroup}, we need to show, \\begin{nestedlemlist}\n        \\item $e_G \\in \\ker{\\varphi}$ follows immediately from (a)\n        \\item $\\forall a, b \\in \\ker{\\varphi}.\\ \\varphi(a \\cdot b) = \\varphi(a) \\cdot \\varphi(b) = e_H \\cdot e_H = e_H$. Therefore, $\\ker{\\varphi}$ is closed under the group operation, $a \\cdot b \\in \\ker{\\varphi}$.\n        \\item $\\forall a \\in \\ker{\\varphi}.\\ \\varphi(\\inv{a}) = \\inv{\\varphi(a)} = \\inv{e_H} = e_H$. Therefore, $\\ker{\\varphi}$ is closed under inversion, $\\inv{a} \\in \\ker{\\varphi}$.\n    \\end{nestedlemlist}\n    $\\implies \\ker{\\varphi} \\subgroup G$.\n    \n    \\item \\begin{itemize}\n        \\item \\underline{``$\\Rightarrow$''}: Let $\\varphi$ be injective. We want to show that $\\ker{\\varphi} = \\{e_G\\}$. Note that (a) already implies $\\{e_G\\} \\subseteq \\ker{\\varphi}$. To show $\\ker{\\varphi} \\subseteq \\{e_G\\}$, let $a \\in \\ker{\\varphi}$. Then, \\begin{align*}\n            \\varphi(a) = e_H \\overset{(a)}{=} \\varphi(e_H).\n        \\end{align*} As $\\varphi$ is injective, it follows that $a = e_H$.\n        \\item \\underline{``$\\Leftarrow$''}: Let $\\ker{\\varphi} = \\{e_G\\}$. We want to show that $\\varphi$ is injective. Let $a, b \\in G$ with $\\varphi(a) = \\varphi(b)$. By multiplying from the right with $\\inv{\\varphi(b)}$, we obtain, \\begin{align*}\n            e_H = \\varphi(a) \\cdot \\inv{\\varphi(b)} = \\varphi(a) \\cdot \\varphi(\\inv{b}) = \\varphi(a \\cdot \\inv{b}).\n        \\end{align*} As the kernel of $\\varphi$ only contains $e_G$, we follow, \\begin{align*}\n            e_G = a \\cdot \\inv{b} \\overset{\\cdot b}{\\implies} a = b \\implies \\text{$\\varphi$ injective}.\n        \\end{align*}\n    \\end{itemize}\n    \n    \\item Let $a, b \\in G$. Then, \\begin{align*}\n        (\\psi \\circ \\varphi)(a \\cdot b) &= \\psi(\\varphi(a \\cdot b)) = \\psi(\\varphi(a) \\cdot \\varphi(b)) \\margintag{using that $\\varphi$ is a homomorphism} \\\\\n        &= \\psi(\\varphi(a)) \\cdot \\psi(\\varphi(b)) = (\\psi \\circ \\varphi)(a) \\cdot (\\psi \\circ \\varphi)(b). \\margintag{using that $\\psi$ is a homomorphism} \\qedhere\n    \\end{align*}\n\\end{lemlist}\n\\end{proof}\n\n\\begin{defn}[Isomorphism]\n\\leavevmode\\begin{defnlist}\n    \\item The mapping $\\varphi : G \\to H$ is called an \\emph{isomorphism}\\index{isomorphism} if $\\varphi$ is a homomorphism and bijective. The isomorphism $\\psi : G \\to G$ is called an \\emph{automorphism}\\index{automorphism} of $G$.\n    \\item $G$ and $H$ are called \\emph{isomorphic} (denoted $G \\isom H$) if there exists an isomorphism $\\varphi : G \\to H$.\n    \\item $\\Aut{G} \\defeq \\{\\psi : G \\to G \\mid \\text{$\\psi$ automorphism}\\}$ forms a group under function composition ``$\\circ$''. This group is called the \\emph{automorphic group}\\index{automorphic group} of $G$.\n\\end{defnlist}\n\\end{defn}\n\n\\begin{rmk}\nIf $\\varphi : G \\to H$ is an isomorphism, then $\\inv{\\varphi} : H \\to G$ is an isomorphism.\n\\end{rmk}\n\n\\begin{ex}{Isomorphisms}{}\n\\begin{itemize}\n    \\item Given a group $G$ and an arbitrary element $g \\in G$, \\begin{align}\n        i_g : G \\to G, x \\mapsto g \\cdot x \\cdot \\inv{g},\n    \\end{align} is the \\emph{inner automorphism}\\index{inner automorphism} of the so-called \\emph{conjugating element}\\index{conjugating element} $g$. This isomorphism corresponds to the conjugation group action (also called \\emph{(left) conjugation}\\index{conjugation} by $g$), which we will encounter again in \\cref{sec:groups:actions}.\n    \n    \\item $\\exp : (\\R,+) \\to (\\RgZ,\\cdot), x \\mapsto e^x$ is an isomorphism.\\marginfootnote{$\\exp$ is a homomorphism due to $e^{x+y} = e^x e^y$. As $\\exp$ is strictly monotonically increasing, it is bijective.}\n\\end{itemize}\n\\end{ex}", "meta": {"hexsha": "6819c359149b24df8d0069fdf318e541cf2a103a", "size": 26480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/01_groups_and_homomorphisms.tex", "max_stars_repo_name": "jonhue/algebra", "max_stars_repo_head_hexsha": "b91da0f3fff239010d0584535f1b5f0d4f0184aa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/01_groups_and_homomorphisms.tex", "max_issues_repo_name": "jonhue/algebra", "max_issues_repo_head_hexsha": "b91da0f3fff239010d0584535f1b5f0d4f0184aa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/01_groups_and_homomorphisms.tex", "max_forks_repo_name": "jonhue/algebra", "max_forks_repo_head_hexsha": "b91da0f3fff239010d0584535f1b5f0d4f0184aa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.7742663657, "max_line_length": 578, "alphanum_fraction": 0.6274924471, "num_tokens": 9693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.912436157500568, "lm_q1q2_score": 0.8411948125962436}}
{"text": "\n\\subsection{Cumulative distribution functions}\n\n\\subsubsection{Definition}\n\nRandom variables all valued as real numbers, and so we can write:\n\n\\(P(X\\le x)=P({\\omega |X(\\omega)\\le x})\\)\n\nOr:\n\n\\(F_X(x)=\\int_{-\\infty}^x f_X(u)du\\)\n\n\\(F_X(x)=\\sum_{x_i\\le x}P(X=x_i) \\)\n\n\\subsubsection{Partitions}\n\n\\(P(X\\le x)+P(X\\ge x)-P(X=x)=1\\)\n\n\\subsubsection{Interval}\n\n\\(P(a< X\\le b)=F_X(b)-F_X(a)\\)\n\n", "meta": {"hexsha": "afe39b514f1df7663b0255aaf0f2eb176ff8cc00", "size": 387, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityVariables/01-03-cumulative.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/probabilityVariables/01-03-cumulative.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/probabilityVariables/01-03-cumulative.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.125, "max_line_length": 65, "alphanum_fraction": 0.6434108527, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377237352755, "lm_q2_score": 0.8774767762675405, "lm_q1q2_score": 0.8410945917540559}}
{"text": "\n\\subsection{Defining linear models}\n\n\\subsubsection{Defining}\n\nOne option for \\(f(X)\\) is a linear model.\n\n\\(f(X_i)=\\hat{Y_i}= \\beta_0+\\sum_{j=1}^p\\beta_iX_{ij}\\)\n\nThe values for \\(\\beta \\) are the regression coefficients.\n\nSo we have:\n\n\\(Y_i=\\beta_0+\\sum_{j=1}^p\\beta_iX_{ij}+e(X_i)+e_i\\)\n\nWe define the error of the estimate as:\n\n\\(\\epsilon_i=Y_i-\\hat{Y_i}\\)\n\n\\(\\epsilon_i=e(X_i)+e_i \\)\n\nSo:\n\n\\(Y_i=\\beta_0+\\sum_{j=1}^p\\beta_iX_{ij}+\\epsilon_i\\)\n\nThe linear model could be wrong for two reasons. No linear model could be appropriate, or the wrong coefficients could be provided for a linear model.\n\nLinear regression if \\(f\\) is a linear function on \\(w\\). NB: not linear in \\(x\\) necessarily. could have \\(x^2\\) etc, but still linear in \\(w\\).\n\n", "meta": {"hexsha": "b8521e1a91852753ede2219111b3722f54f6014f", "size": 749, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/ols/01-01-linearModels.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/ols/01-01-linearModels.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/ols/01-01-linearModels.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.9666666667, "max_line_length": 150, "alphanum_fraction": 0.6889185581, "num_tokens": 245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9658995772325382, "lm_q2_score": 0.870597273444551, "lm_q1q2_score": 0.8409095383598922}}
{"text": "\\section{Limit Properties}\r\nLimit have many nice properties all allow us to make useful simplifications when evaluating a limit.\r\nLet\r\n\\begin{equation*}\r\n\t\\lim_{x \\to c}{f(x)} = L \\text{ and } \\lim_{x \\to c}{g(x)} = M.\r\n\\end{equation*}\r\n\\begin{align*}\r\n\t\\textbf{Sum and Difference Rule: }& \\lim_{x\\to c}{\\left(f(x) \\pm g(x)\\right)} = L \\pm M \\\\\r\n\t\\textbf{Product Rule: }& \\lim_{x\\to c}{\\left(f(x)g(x) \\right)} = LM \\\\\r\n\t\\textbf{Constant Multiple Rule: }& \\lim_{x \\to c}{k\\cdot f(x)} = k \\lim_{x \\to c}{f(x)} = kL \\\\\r\n\t\\textbf{Quotient Rule: }& \\lim_{x \\to c}{\\frac{f(x)}{g(x)}} = \\frac{\\lim_{x \\to x}{f(x)}}{\\lim_{x \\to c}{g(x)}} = \\frac{L}{M} \\text{, if} M \\neq 0 \\\\\r\n\t\\textbf{Power Rule: }& \\text{If } n \\neq  \\in \\R \\text{, } \\lim_{x\\to c}{\\left(f(x)\\right)^n} = \\left(\\lim_{x \\to c}{f(x)}\\right)^n = L^n\r\n\\end{align*}\r\n\r\n\\subsection{``Substitution Rule''}\r\nAlthough it may seem obvious from our idea that limits describe behavior at a point that if $f(x)$ is defined at $x=c$, then $\\lim_{x\\to c}{f(x)} = f(c)$.\r\nHowever, this is \\textit{not} always the case.\r\nRemember that our definition of a limit required these $\\epsilon$ and $\\delta$ neighborhoods around the limit point.\r\nIf $f(x)$ is defined at $x=c$, but $(c, f(c))$ is not a point in these neighborhoods for any $\\epsilon > 0$, then the limit will not evaluate to $f(c)$.\r\n\r\n\\begin{example}\r\n\tFind the limit of $f(x)$ as $x$ approaches $2$ for the following function.\r\n\t\\begin{equation*}\r\n\t\tf(x) = \\begin{cases}\r\n\t\t\tx^2 & x \\neq 2 \\\\\r\n\t\t\t0 & x = 2\r\n\t\t\\end{cases}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe can clearly see that $f(2) =  0$, but for $\\epsilon = 0.1$, for example, there is no $\\delta$ that can satisfy our definition, as points like $(2 - \\delta, 4 - 2\\delta + \\delta^2)$ would outside the neighborhood around $(2,0)$.\r\n\tIn fact, the correct limit value is $4$, the same as if $f(x) = x^2$ for all $x$.\r\n\tThere are some more nuances we'll need to describe before we can say when it's OK to substitute to evaluate a limit.\r\n\\end{answer}", "meta": {"hexsha": "20bc6debecae62f7cbd65bdfa4b70f78dce6ff97", "size": 2026, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/limits_continuity/limit_properties.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/limits_continuity/limit_properties.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/limits_continuity/limit_properties.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 59.5882352941, "max_line_length": 232, "alphanum_fraction": 0.6322803554, "num_tokens": 711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362486, "lm_q2_score": 0.8962513655129178, "lm_q1q2_score": 0.8407949319165776}}
{"text": "\\section{Integer Linear Programming Model}\n\tIn this section will be presented the model implemented using Cplex as solver.\n\t\\subsection{Network Flow Model Representation}\n\t\tThe problem can be represented on a complete weighted graph $G=(N, A)$ where $N$ is the set of nodes (holes on the board) and $A$ is the set of the arcs $(i, j), \u2200 i, j \u2208 N$ (trajectory of the drill moving from hole $i$ to hole $j$).To each arc will be associated a weight $c_{ij}$ that represents the time needed to move from starting hole to destination.\n\t\t\n\t\tUsing this representation the problem is equivalent to determine the minimum weight hamiltonian cycle on G, so it is like the very popular Travelling Salesman Problem (TSP).\n\t\t\n\t\tTo solve the TSP problem we can formulate it as a network flow model on G. Given a starting node $0 \u2208 N$, let $|N|$ be the amount of its output flow, the problem can be solved by finding the path for which:\n\t\t\\begin{itemize}\n\t\t\t\\item Each node receives 1 unit of flow\n\t\t\t\\item Each node is visited once\n\t\t\t\\item The sum of costs in selected arcs is minimum\n\t\t\\end{itemize}\n\t\t\n\t\\subsection{Variables and Constraints}\n\t\tThe problem can then be represented like this:\\\\\n\t\t\\newline\n\t\t\\textbf{SETS:}\\\\\n\t\t\\begin{addmargin}[2em]{0em}\n\t\t\t$N$ = the graph nodes (holes)\\\\\n\t\t\t$A$ = arcs in the form $(i, j), \u2200 i, j \u2208 N$ (trajectories between holes)\\\\\n\t\t\\end{addmargin}\n\t\t\\textbf{PARAMETERS:}\\\\\n\t\t\\begin{addmargin}[2em]{0em}\n\t\t\t$c_{ij}$ = time taken by the drill to move from $i$ to $j$, $\u2200 (i, j) \u2208 A$\\\\\n\t\t\t$0$ = starting hole, $0 \u2208 N$\\\\\n\t\t\\end{addmargin}\n\t\t\\textbf{DECISION VARIABLES:}\\\\\n\t\t\\begin{addmargin}[2em]{0em}\n\t\t\t$x_{ij}$ = amount of the flow shipped from $i$ to $j$, $\u2200 (i, j) \u2208 A$\\\\\n\t\t\t$y_{ij}$ = 1 if arc $(i, j)$ ships some flow, 0 otherwise, $\u2200 (i, j) \u2208 A$\\\\\n\t\t\\end{addmargin}\n\t\t\\textbf{OBJECTIVE FUNCTION:}\\\\\n\t\t\\[min \\sum_{i, j | (i, j) \u2208 A} c_{ij} \\cdot y_{ij}\\]\\\\\n\t\t\\textbf{CONSTRAINTS:}\n\t\t\\begin{align*}\n\t\t\t&\\sum_{j | (0,j) \u2208 A} x_{0j} = |N|\\\\\n\t\t\t\\\\\n\t\t\t&\\sum_{i | (i, k) \u2208 A} x_{ik} - \\sum_{j | (k, j) \u2208 A} x_{kj} = 1 & \u2200 k \u2208 N \\setminus \\{0\\}\\\\\n\t\t\t\\\\\n\t\t\t&\\sum_{j | (i, j) \u2208 A} y_{ij} = 1 & \u2200 i \u2208 N\\\\\n\t\t\t\\\\\n\t\t\t&\\sum_{i | (i, j) \u2208 A} y_{ij} = 1 & \u2200 j \u2208 N\\\\\n\t\t\t\\\\\n\t\t\t&x_{ij} \\leq |N| \\cdot y_{ij} & \u2200 (i, j) \u2208 A\\\\\n\t\t\t\\\\\n\t\t\t&x_{ij} \u2208 \\mathbb{Z}_{+} & \u2200 (i, j) \u2208 A\\\\\n\t\t\t\\\\\n\t\t\t&y_{ij} \u2208 \\{0, 1\\} & \u2200 (i, j) \u2208 A\n\t\t\\end{align*}\n\n\t\t\n\t\t", "meta": {"hexsha": "5a8595b509289c836497c4f5b8270c8a5f20a7fe", "size": 2348, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/ilp_model.tex", "max_stars_repo_name": "abeccaro/MeMOC-project", "max_stars_repo_head_hexsha": "74d6b79ac72ed573c280478820a221424fc138f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-02-07T13:28:49.000Z", "max_stars_repo_stars_event_max_datetime": "2018-02-07T13:28:49.000Z", "max_issues_repo_path": "report/sections/ilp_model.tex", "max_issues_repo_name": "abeccaro/MeMOC-project", "max_issues_repo_head_hexsha": "74d6b79ac72ed573c280478820a221424fc138f5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/sections/ilp_model.tex", "max_forks_repo_name": "abeccaro/MeMOC-project", "max_forks_repo_head_hexsha": "74d6b79ac72ed573c280478820a221424fc138f5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.3018867925, "max_line_length": 358, "alphanum_fraction": 0.6086030664, "num_tokens": 886, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9637799420543366, "lm_q2_score": 0.8723473879530491, "lm_q1q2_score": 0.8407509150126415}}
{"text": "\\begin{questions}\n\\question{Consider the predictor-corrector time-stepping scheme:\n\\begin{align*}\n& y_{n+1}^p = y_n + \\frac{\\Delta t}{12}(23f_n - 16f_{n-1}+5f_{n-2}), \\\\\n&y_{n+1} = y_n + \\frac{\\Delta t}{12}(5f(t_{n+1},y_{n+1}^p) + 8f)n - f_{n-1})~.\n\\end{align*}\nHere $f_n = f(t_n,y_n)$ and $y'(t) = f(t,y)$, $y(0) = y_0$. Plot the stability region for this scheme.\n }\n\n\\begin{solution}\n\nLet $y_{n+1}^p = P$ for simplicity. Then, for stability purposes, $f = \\lambda y$. Finally, let $a = \\frac{\\Delta t \\lambda}{12}$. Then,\n\\begin{align*}\n\\begin{cases}\nP = y^n + a(23y^n - 16y^{n-1}+5y^{n-1} \\\\\ny^{n+1} = y^n + a(5P + 8y^n - y^{n-1})\n\\end{cases} \\Rightarrow y^{n+1} = y^n + a \\left[ 5(y^n + a(23y^n- 16y^{n-1}+5y^{n-1})) + 8y^n - y^{n-1} \\right]~.\n\\end{align*} \n\nNow assume $y^{n+1} = gy^n$, and thus $y^n = g^2y^{n-2}$. Plugging this in, we get\n\\begin{align*}\ngy^n = y^n +a\\left[ 5y^n + 115ay^n - 80\\frac{a}{g}y^n + 25\\frac{a}{g^2}y^n\\right] + 8ay^n - \\frac{a}{g}y^n~.\n\\end{align*}\nSolving for $a$, we get\n\\begin{align*}\n&(115g^2 - 80g +25)a^2 + (13g^2-g)a + (g^2-g^3) = 0 \\\\\n& \\Rightarrow a = \\frac{-(13g^2 - g) \\pm \\sqrt{(13g^2-g)^2 - 4(115g^2 - 80g+25)(g^2-g^3)}}{2(115g^2 - 80g +25)}~.\n\\end{align*}\nLastly we let $z = 12a$ and plot the solution into Matlab to get the following stability region:\n\n\\begin{figure}[H]\n\\center{\\includegraphics[scale=.5]{P3F1.eps}}\n\\end{figure}\n\n\n\\end{solution}\n\n\\subsection*{MATLAB}\n\n\\begin{verbatim}\nclose all; clear variables;\n\ntheta = linspace(0,2*pi,100);\ng = exp(1i*theta);\na = 115*g.^2 - 80*g+25;\nb = 13*g.^2 - g;\nc = g.^2-g.^3;\nsq = sqrt(b.^2 - 4*a.*c);\n\nzp = 12*((-b + sq)./(2*a));\nzn = 12*((-b - sq)./(2*a));\n\nfigure\nplot(real(zp),imag(zp),'.r',real(zn),imag(zn),'.b')\nlegend('positive square root','negative square root')\ngrid on\n\\end{verbatim}\n\n\n\\end{questions}", "meta": {"hexsha": "2174f35eb2811ee302af6ff07b92328a39592549", "size": 1807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/tex_files/problem3camille.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/tex_files/problem3camille.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/tex_files/problem3camille.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.1166666667, "max_line_length": 136, "alphanum_fraction": 0.5843940232, "num_tokens": 807, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741281688026, "lm_q2_score": 0.8824278695464501, "lm_q1q2_score": 0.8405779585050637}}
{"text": "\\subsection{Eigenvalue for rotation transformation}\n\n\\textbf{\\textit{Claim:}} \nIf $0< \\theta <2\\pi$ then transformation $R_\\theta : \\R^2\\rightarrow \\R^2$ only has an eigenvector when $\\theta=\\pi$ (when $\\lambda=-1$).\n\\newline \\noindent\n\\textbf{\\textit{Proof:}}\n\\noindent\nThe matrix is $A=\\begin{bmatrix}\\cos\\theta & -\\sin\\theta\\\\\\sin\\theta & \\cos\\theta\\end{bmatrix}$. Following by the definition of an eigenvector:\n\n\\[\n    \\begin{aligned}\n        A \\tb{v} &=\\lambda v \\Longleftrightarrow \\\\\n        A \\tb{v}-\\lambda \\tb{v} &=\\overrightarrow{0} \\Longleftrightarrow \\\\\n        A \\tb{v}-\\lambda(I \\tb{v}) &=\\overrightarrow{0} \\Longleftrightarrow \\\\\n        A \\bar{v}-(\\lambda I) \\tb{v} &=\\overrightarrow{0} \\Longleftrightarrow \\\\\n        (A-\\lambda I) \\tb{v} &=\\overrightarrow{0} \\Longleftrightarrow \\\\\n            \\operatorname{det}(A-\\lambda I)&=0\n        \\end{aligned}    \n\\]\n\nThus,\n\n\\[\n    \\begin{aligned}\n        \\operatorname{det}(A-\\lambda I) &=0 \\\\\n        \\operatorname{det}\\left(\\begin{array}{cc}\n        \\cos \\theta-\\lambda & -\\sin \\theta \\\\\n        \\sin \\theta & \\cos \\theta-\\lambda\n        \\end{array}\\right) &=0 \\\\\n        \\lambda^{2}-2 \\lambda \\cos \\theta+\\cos ^{2} \\theta+\\sin ^{2} \\theta &=0 \\\\\n        \\lambda^{2}-2 \\lambda \\cos \\theta+1 &=0\n        \\end{aligned}    \n\\]\n\nThe discriminant of this quadratic ($b^2-4ac$) is $4\\cos^2\\theta-4$, so for a real solution $4\\cos^2\\theta-4\\geq 0$. It then follows\nthat:\n\n\\begin{align*}\n    4\\cos^2\\theta-4&\\geq 0\\\\\n    \\cos^2\\theta&\\geq 1\\\\\n    \\cos^2\\theta&=\\pm 1\\\\\n    \\theta&=\\pi\n\\end{align*}\n\nNote that because $(A-\\lambda I)\\tb{v}=\\tb{0}$ implies a nontrivial kernel for $A-\\lambda I$, $\\mathrm{det}(A-\\lambda I)=0$.\n\n\\subsection{Characteristic Polynomials}\n\nCharacteristic polynomial is for $\\mathrm{det}(A-\\lambda I)$ with variable $\\lambda$: \n\n\\[\\boxed{P_A(\\lambda)=\\mathrm{det}(A-\\lambda I)}\\]\n\nGeneral polynomial for $A=\\begin{bmatrix}a&b\\\\c&d\\end{bmatrix}$:\n\n\\[\n    \\begin{aligned}\n        p_{A}(\\lambda) &=\\operatorname{det}(A-\\lambda I) \\\\\n        &=\\operatorname{det}\\left(\\begin{array}{cc}\n        a-\\lambda & b \\\\\n        c & d-\\lambda\n        \\end{array}\\right) \\\\\n        &=(a-\\lambda)(d-\\lambda)-b c \\\\\n        &=\\lambda^{2}-(a+b) \\lambda+(a d-b c)    \n    \\end{aligned}\n\\]\n\nEnds up that $\\mathrm{tr}(A)=a+d$ and $\\mathrm{det}(A)=ad-bc$:\n\n\\[\\boxed{p_{A}(\\lambda)=\\lambda^{2}-\\operatorname{tr} A \\lambda+\\operatorname{det} A}\\]\n\n\\subsubsection{General formula}\n\nIn general, if $A$ is an $n\\times n$ matrix, then\n\n\\[\\boxed{p_{A}(\\lambda)=(-1)^{n} \\lambda^{n}+(-1)^{n-1} \\operatorname{tr} A \\lambda^{n-1}+\\cdots+\\operatorname{det} A}\\]\n\nConjectures:\n\\begin{itemize}\n    \\item By FTLA, degree $n$ polynomial will have $n$ complex roots so at least $n$ real eigenvalues\n    \\item If all $n$ roots are real, then $\\mathrm{tr}(A)$ is sum of eigenvalues and determinant is the product of them\n    \\item Since roots are either real or in complex conjugate pairs, ($a+bi$ or $a-bi$) then when $n$ is odd $A$ has at least 1 real eigenvalue\n\\end{itemize}", "meta": {"hexsha": "6757e4b72756d63c0872dc501cb8425357e9fd85", "size": 3017, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/18_matrix-eigenvalues.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear-algebra/tex/18_matrix-eigenvalues.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "linear-algebra/tex/18_matrix-eigenvalues.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.7926829268, "max_line_length": 143, "alphanum_fraction": 0.6135233676, "num_tokens": 1038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.8933094003735664, "lm_q1q2_score": 0.840416329753902}}
{"text": "\\chapter{Minimum Spanning Tree}\n\nGiven an undirected, connected graph where each edge has positive\nweight, the \\emph{Minimum Spanning Tree} (MST) is a connected subgraph on the same \nvertex set with minimal weight. Intuitively, the MST is the lightest possible\nconnected subgraph. The MST is not necessarily unique, \nfor proof of this, consider a graph where all edges are of equal weight. \nAny tree is an MST of such a graph. \n\n\\section{Kruskal's Algorithm}\n\n%The idea of this algorithm is to begin with the vertex list and an\n%empty edge list, and maintain a forest, adding the edge of minimum\n%weight that does not make a cycle until the forests are connected.\n\nKruskal's algorithm for computing the MST relies on the simple observation\nthat the smallest edge in a graph $G$ is part of \\emph{some} MST of $G$.\nKruskal's algorithm starts by constructing a min-heap containing all $m$ edges\nin $G$, and a collection of disjoint sets, each containing one of the\n$n$ vertices of $G$. We also construct an empty list $T$ that will hold\nall the edges of the MST. We then get the minimum edge from the heap, check if\nthe two nodes the edge joins are from the same set, and if not add \nthe edge to $T$, and $union$ the two sets that the edge joins.\nWe repeat this until $T$ contains $n-1$ edges. \n\nBecause this algorithm uses\nstructures we already know and understand, analysis will be fairly easy.\nWe require $O(m) + O(n)$ time to construct the initial sets and heap. We also\nrequire $O(m \\log m)$ to extract the minimums from the heap. Our $n-1$ unions\nand $n-1$ finds can be done in $(n \\log n + n)$ time. Therefore this algorithm\ntakes $O(m \\log m + n \\log n)$.\n\n\\section{Prim's Algorithm}\nPrim's algorithm for computing the MST is fairly similar to Kruskal's. However,\ninstead of working with all of the edges and vertices at once, it picks one\nvertice and builds from that. We start by constructing an empty list $A$ which\nwill hold all the vertices that are part of the MST so far, a list $T$ which\nwill hold all the edges in the MST so far, a min-heap $V$ which will contain all\nthe vertices not in $A$. At first every node is given a key of infinity. \nWe then pick a random vertex $v$ from $V$ and move it from $V$ \nto $A$. Next we look at all the edges of $v$ and set the\nkeys of the corresponding nodes to the weight of these edges. Now we retrieve\nthe minimum node $u$ from $V$ and move it to $A$, and its key edge to $T$. \nNext we look at all the edges on $u$ and if their weight is smaller than\nthe current key of their corresponding edge, set the key to that weight. Then\nwe simply retrieve another node from the heap and repeat. After $n-1$ iterations\nwe will have a complete MST.\n\nThis algorithm requires $O(n)$ time to construct the initial heap and \ninitialize the first node, and since we must update at most $m$ keys in the\nheap of $n$ elements, it requires $O(m \\log n)$ time to do this. Therefore the\nentire algorithm takes $O(n + m \\log n)$ time.\n\n", "meta": {"hexsha": "432dc0e0686ccf0bdd6ee7b70ffa8333d649f9f7", "size": 2967, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mst.tex", "max_stars_repo_name": "SteamedPears/AllTheAlgorithms", "max_stars_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-12T19:16:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-01T03:13:05.000Z", "max_issues_repo_path": "mst.tex", "max_issues_repo_name": "SteamedPears/AllTheAlgorithms", "max_issues_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mst.tex", "max_forks_repo_name": "SteamedPears/AllTheAlgorithms", "max_forks_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.9444444444, "max_line_length": 83, "alphanum_fraction": 0.7499157398, "num_tokens": 771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.9173026612812897, "lm_q1q2_score": 0.8403497949748778}}
{"text": "\\section{Matrices}\nIn the previous section we described linear transformations in a rather abstract way: what they are, how they behave qualitatively and how they look like in 2- and 3-dimensions. In this section we introduce a numerical method of representing linear transformations: matrices.\n\n\\subsection{Linear transformation of basis vectors}\nRecall that any vector $\\vec{v}\\in\\Rs{n}$ can be written as a linear combination of basis vectors $\\vec{b}_{1}, \\vec{b}_{2}, \\dots, \\vec{b}_{n}$:\n\\begin{equation}\n\t\\vec{v} = \\sum\\limits_{i=1}^{n}\\alpha_{i}\\vec{b}_{i} = \\alpha_{1}\\vec{b}_{1} + \\alpha_{2}\\vec{b}_{2} + \\cdots + \\alpha_{n}\\vec{b}_{n}.\n\\end{equation}\n\nApplying a linear transformation $T$ on $\\vec{v}$ yields, using the properties of linear transformations,\n\\begin{align}\n\tT\\left(\\vec{v}\\right) &= T\\left(\\alpha_{1}\\vec{b}_{1} + \\alpha_{2}\\vec{b}_{2} + \\cdots + \\alpha_{n}\\vec{b}_{n}\\right)\\nonumber\\\\\n\t\\tikz[baseline=-0.5ex]{\\draw[-stealth, xred] (0,0) -- (1,0) node[pos=-0.1, anchor=east] {additivity}}\n\t\t\t\t\t\t  &= T\\left(\\alpha_{1}\\vec{b}_{1}\\right) + T\\left(\\alpha_{2}\\vec{b}_{2}\\right) + \\cdots + T\\left(\\alpha_{n}\\vec{b}_{n}\\right)\\nonumber\\\\\n    \\tikz[baseline=-0.5ex]{\\draw[-stealth, xblue] (0,0) -- (1,0) node[pos=-0.1, anchor=east] {scalability}}\n\t\t\t\t\t\t  &= \\alpha_{1}T\\left(\\vec{b}_{1}\\right) + \\alpha_{2}T\\left(\\vec{b}_{2}\\right) + \\cdots + \\alpha_{n}T\\left(\\vec{b}_{n}\\right).\n\t\\label{eq:transfom_by_basis}\n\\end{align}\n\nThis result is pretty neat: it means that by knowing how a linear transformation $T$ changes the basis vectors, we know exactly how any vector is transformed by $T$. This true for any basis, and thus specifically to the standard basis, where the coefficients $\\alpha_{1},\\alpha_{2},\\dots,\\alpha_{n}$ are actually the components of the vector, i.e. $v_{1},v_{2},\\dots,v_{n}$. Thus in the standard basis:\n\\begin{equation}\n\tT\\left(\\vec{v}\\right) = v_{1}T\\left(\\eb{1}\\right) + v_{2}T\\left(\\eb{2}\\right) + \\cdots + v_{n}T\\left(\\eb{n}\\right).\n\\end{equation}\n\n\\begin{example}{Vector transformation via a basis}{}\n\tApplying the transformation $T:\\Rs{3}\\to\\Rs{3}$, defined as\n\t\\[\n\t\tT\\left(\\colvec{x;y;z}\\right)=\\colvec{x+y-2z;2x+z;-x-y-z}\n\t\\]\n\ton the vector $\\vec{v}=\\colvec{2;-1;3}$ yields the following vector:\n\t\\[\n\t\tT\\left(\\vec{v}\\right) = T\\left(\\colvec{2;-1;3}\\right) = \\colvec{2+(-1)-2\\cdot3;2\\cdot2+3;-2-(-1)-3} = \\colvec{2-1-6;4+3;-2+1-3} = \\colvec{-5;7;-4}.\n\t\\]\n\n\tNow, let us apply $T$ first to the three standard basis vectors $\\hat{x},\\hat{y},\\hat{z}$:\n\t\\begin{align*}\n\t\tT\\left( \\hat{x} \\right) &= T\\left(\\colvec{1;0;0}\\right) = \\colvec{1+0-\\cancel{2\\cdot0};2\\cdot1+0;-1-0-0} = \\colvec{1;2;-1},\\\\\n\t\tT\\left( \\hat{y} \\right) &= T\\left(\\colvec{0;1;0}\\right) = \\colvec{0+1-\\cancel{2\\cdot0};\\cancel{2\\cdot0}+0;-0-1-0} = \\colvec{1;0;-1},\\\\\n\t\tT\\left( \\hat{z} \\right) &= T\\left(\\colvec{0;0;1}\\right) = \\colvec{0+0-2\\cdot1;\\cancel{2\\cdot0}+1;-0-0-1} = \\colvec{-2;1;-1}.\n\t\\end{align*}\n\n\tTaking these results and applying \\autoref{eq:transfom_by_basis} yields\n\t\\begin{align*}\n\t\tT\\left( \\vec{v} \\right) &= 2T \\left( \\hat{x} \\right) -T \\left( \\hat{y} \\right) + 3T \\left( \\hat{z} \\right)\\\\\n\t\t\t\t\t\t\t\t&= 2\\colvec{1;2;-1} - \\colvec{1;0;-1} + 3\\colvec{-2;1;-1}\\\\\n\t\t\t\t\t\t\t\t&= \\colvec{2;4;-2} - \\colvec{1;0;-1} + \\colvec{-6;3;-3}\\\\\n\t\t\t\t\t\t\t\t&= \\colvec{2-1-6;4-0+3;-2-(-1)+(-3)}\\\\\n\t\t\t\t\t\t\t\t&= \\colvec{-5;7;-4},\n\t\\end{align*}\n\twhich is indeed what we got when we applied $T$ directly to $\\vec{v}$.\n\\end{example}\n\n\\subsection{From transformations to matrices}\nThe most general linear transformation $T:\\Rs{2}\\to\\Rs{2}$ has the following form:\n\\begin{equation}\n\tT \\left( \\colvec{x;y} \\right) = \\colvec{ax+by;cx+dy},\n\t\\label{eq:generic_R2_LT}\n\\end{equation}\nwhere $a,b,c,d\\in\\mathbb{R}$. If we apply this transformation to $\\hat{x}$ and $\\hat{y}$ we get, respectively,\n\\begin{equation}\n\tT \\left( \\hat{x} \\right) = \\colvec{a;c},\\quad T \\left( \\hat{y} \\right) = \\colvec{b;d}.\n\t\\label{eq:}\n\\end{equation}\nWe can now collect these two vectors to form a new structure, which we call a \\emph{matrix} (in this specific casr a $2\\times2$ matrix):\n\\begin{equation}\n\tA = \\begin{bNiceMatrix} a&b\\\\c&d \\end{bNiceMatrix}.\n\t\\label{eq:matrix}\n\\end{equation}\n\nWe then define the product of $M$ with a vector $\\vec{v}=\\colvec{x;y}$ to yield $T \\left( \\vec{v} \\right)$, i.e.\n\\begin{equation}\n\tA\\vec{v} = \\begin{bNiceMatrix} a&b\\\\c&d \\end{bNiceMatrix} \\cdot\\colvec{x;y} = \\colvec{ax+by;cx+dy}.\n\t\\label{eq:matrix_vector_product_2x2}\n\\end{equation}\nThis defintion can be re-written as following:\n\\begin{equation}\n\tA\\vec{v} = \\begin{bNiceMatrix} a&b\\\\c&d \\end{bNiceMatrix} \\cdot\\colvec{x;y} = \\colvec{A_{1}\\cdot\\vec{v};A_{2}\\cdot\\vec{v}},\n\t\\label{eq:matrix_vector_product_as_dot_product}\n\\end{equation}\ni.e. the $i$-th component of the resulting vector is the scalar product of the $i$-th \\textbf{row} of the matrix with the vector $\\vec{v}$.\n\n\\begin{example}{Matrix-vector product}{}\n\tSome matrix-vector products:\n\n\t\\begin{align*}\n\t\t\\begin{bNiceMatrix}\n\t\t\t1 & -2 \\\\\n\t\t\t0 & 5\n\t\t\\end{bNiceMatrix}\\colvec{-3;2} &= \\colvec{1\\cdot(-3) + (-2)\\cdot2;\\cancel{0\\cdot(-3)}+5\\cdot2} = \\colvec{-7;10},\\\\[5mm]\n\t\t\\begin{bNiceMatrix}\n\t\t\t1 & 2 \\\\\n\t\t\t1 & 2\n\t\t\\end{bNiceMatrix}\\colvec{5;-4} &= \\colvec{1\\cdot5+2\\cdot(-4);1\\cdot5+2\\cdot(-4)} = \\colvec{-3;-3},\\\\[5mm]\n\t\t\\begin{bNiceMatrix}\n\t\t\t1 & 0 \\\\\n\t\t\t0 & 2\n\t\t\\end{bNiceMatrix}\\colvec{2;-2} &= \\colvec{2\\cdot2+\\cancel{0\\cdot(-2)};\\cancel{0\\cdot2}+2\\cdot(-2)} = \\colvec{4;-4}.\n\t\\end{align*}\n\\end{example}\n\n\\begin{challenge}{Proof of linearity}{}\n\tProve that the transformation $T$ in \\autoref{eq:generic_R2_LT} is indeed linear.\n\\end{challenge}\n\nThe most general form of a linear transformation is $T:\\Rs{n}\\to\\Rs{m}$, i.e. a transformation which takes $n$-dimensional vectors as input and returns $m$-dimensional vectors as output:\n\\begin{equation}\n\tT \\left( \\colvec{\\tikzmark{N}x_{1};x_{2};\\vdots;x_{n}} \\right) = \\colvec{\n\t\t\\Ma{1}{1}x_{1}+\\Ma{1}{2}x_{2}+\\cdots+\\Ma{1}{n}x_{n};\n\t\t\\Ma{2}{1}x_{1}+\\Ma{2}{2}x_{2}+\\cdots+\\Ma{2}{n}x_{n}\\tikzmark{M};\n\t\t\\vdots;\n\t\t\\Ma{m}{1}x_{1}+\\Ma{m}{2}x_{2}+\\cdots+\\Ma{m}{n}x_{n}\n\t},\n\t\\label{eq:}\n\\end{equation}\n\\begin{tikzpicture}[overlay, remember picture]\n\t\\node[xblue] (Ntxt) at ($(pic cs:N)+(-1.5cm,-2mm)$) {$\\Rs{n}\\ni$};\n\t\\draw[-stealth, xblue] (Ntxt) to [out=45, in=90] ($(pic cs:N)+(1mm,2.5mm)$);\n\t\\node[xred] (Mtxt) at ($(pic cs:M)+(2.5cm,5mm)$) {$\\in\\Rs{m}$};\n\t\\draw[-stealth, xred] (Mtxt) to [out=180, in=0] ($(pic cs:M)+(2.5mm,0)$);\n\\end{tikzpicture}\n\nwhere $\\Ma{i}{j}\\in\\mathbb{R},\\ \\textcolor{xred}{i}=1,2,3,\\dots,m$ and $\\textcolor{xblue}{j}=1,2,3,\\dots,n$.\n\n\\begin{challenge}{Proof of linearity}{}\n\tProve that the above transformation $T$ is indeed linear.\n\\end{challenge}\n\nRespectively, we define an $\\textcolor{xred}{m}\\times \\textcolor{xblue}{n}$ matrix (\\textcolor{xred}{$m$} rows by \\textcolor{xblue}{$n$} columns) by collecting all the coefficients $\\Ma{i}{j}$ into a single structure:\n\\begin{equation}\n\tA =\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\\end{bNiceMatrix}. \n\t\\label{eq:mxn_matrix}\n\\end{equation}\nThe product $M\\vec{v}$ (where $\\vec{v}\\in\\Rs{n}$) is then defined as\n\\begin{equation}\n\tA\\vec{v} =\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\\end{bNiceMatrix}\\colvec{x_{1};x_{2};\\vdots;x_{n}} = \\colvec{\n\t\\Ma{1}{1}x_{1}+\\Ma{1}{2}x_{2}+\\cdots+\\Ma{1}{n}x_{n};\n\t\\Ma{2}{1}x_{1}+\\Ma{2}{2}x_{2}+\\cdots+\\Ma{2}{n}x_{n};\n\t\\vdots;\n\t\\Ma{m}{1}x_{1}+\\Ma{m}{2}x_{2}+\\cdots+\\Ma{m}{n}x_{n}\n\t}.\n\t\\label{eq:matrix_vector_product}\n\\end{equation}\nAgain, note that the $i$-th component of the resulting vector is the scalar product $A_{i}\\cdot\\vec{v}$.\n\n\\begin{note}{When is a matrix-vector product defined}{}\n\tIn order for a matrix-vector product to be defined, the vector must be of the same dimension as the number of \\textbf{columns} in the matrix - i.e. given an $a\\times b$ matrix, a vector must be $b$-dimensional for the product to be defined.\n\\end{note}\n\n\\begin{example}{Some matrix-vector products}{}\n\t\\blindtext[2]\n\\end{example}\n\nThe structure of an $m\\times n$ matrix $A$ has a nice property: given that the transformation in represented in some basis $B=\\left\\{ \\vec{b}_{1},\\vec{b}_{2},\\dots,\\vec{b}_{n} \\right\\}$, the $i$-th column of the matrix always shows how $\\vec{b}_{i}$ is transformed by the product $A\\vec{b}_{n}$. This is easy to see in the case of the standard basis, which we anyway use througout this chapter:\n\n\\vspace{1cm}\n\\begin{equation*}\n\t\\setlength{\\arraycolsep}{2.7mm}\n\tA =\n\t\\begin{bNiceMatrix}\n\t\t\\tikzmark{A1}\\Ma{1}{1} & \\tikzmark{B1}\\Ma{1}{2} & \\cdots & \\tikzmark{N1}\\Ma{1}{n}\\\\\n\t    \\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots\\\\\n\t\t\\Ma{m}{1}\\tikzmark{A2} & \\Ma{m}{2}\\tikzmark{B2} & \\cdots & \\Ma{m}{n}\\tikzmark{N2}\n\t\\end{bNiceMatrix}.\n\\end{equation*}\n\\tikzset{\n\thighlight/.style={thick, draw=#1, rounded corners, draw opacity=1, fill=#1, fill opacity=0.2},\n\thltxt/.style={highlight=#1, draw opacity=1, text=black, text opacity=1, above, yshift=1.5cm},\n\tnrtxt/.style={black, opacity=1, text opacity=1},\n\thlarrow/.style={-stealth, thick, #1},\n}\n\\tikz[overlay, remember picture, blend mode=multiply]{\n\t\\draw[highlight={xgreen}]  ($(pic cs:A1)+(-2pt,7pt)$) rectangle node[hltxt={xgreen} ](Atxt){$T \\left( \\eb{1} \\right)$}($(pic cs:A2)+(2pt,-5pt)$);\n\t\\draw[highlight={xpurple}] ($(pic cs:B1)+(-2pt,7pt)$) rectangle node[hltxt={xpurple}](Btxt){$T \\left( \\eb{2} \\right)$}($(pic cs:B2)+(2pt,-5pt)$);\n\t\\draw[highlight={xorange}] ($(pic cs:N1)+(-2pt,7pt)$) rectangle node[hltxt={xorange}](Ntxt){$T \\left( \\eb{n} \\right)$}($(pic cs:N2)+(2pt,-5pt)$);\n\n\t\\draw[hlarrow={xgreen}]  (Atxt.south) -- ++(0,-5mm);\n\t\\draw[hlarrow={xpurple}] (Btxt.south) -- ++(0,-5mm);\n\t\\draw[hlarrow={xorange}] (Ntxt.south) -- ++(0,-5mm);\n}\n\n\\begin{example}{Matrices}{}\n\tThe product of the following matrix $A$ with each of the vectors $\\eb{1},\\eb{2},\\eb{3}$ (i.e. $\\hat{x},\\hat{y}$ and $\\hat{z}$, respectively) returns the respective column of the matrix:\n\t\\begin{align*}\n\t\tA\\eb{1}=\n\t\t\\begin{bNiceMatrix}\n\t\t\t 1 & 2 & 0\\\\\n\t\t\t-1 & 3 & 4\\\\\n\t\t\t 0 & 1 & 3\\\\\n\t\t \\end{bNiceMatrix}\\colvec{1;0;0} &= \\colvec{1\\cdot1+\\cancel{2\\cdot0}+\\cancel{\\cancel{0\\cdot0}};-1\\cdot1+\\cancel{3\\cdot0}+\\cancel{4\\cdot0};\\cancel{0\\cdot1}+\\cancel{1\\cdot0}+\\cancel{3\\cdot0}} = \\colvec{1;-1;0},\\\\[3mm]\n\t\tA\\eb{2}=\n\t\t\\begin{bNiceMatrix}\n\t\t\t 1 & 2 & 0\\\\\n\t\t\t-1 & 3 & 4\\\\\n\t\t\t 0 & 1 & 3\\\\\n\t\t\\end{bNiceMatrix}\\colvec{0;1;0} &= \\colvec{\\cancel{1\\cdot0}+2\\cdot1+\\cancel{\\cancel{0\\cdot0}};-\\cancel{1\\cdot0}+3\\cdot1+\\cancel{4\\cdot0};\\cancel{\\cancel{0\\cdot0}}+1\\cdot1+\\cancel{3\\cdot0}} = \\colvec{2;3;1},\\\\[3mm]\n\t\tA\\eb{3}=\n\t\t\\begin{bNiceMatrix}\n\t\t\t 1 & 2 & 0\\\\\n\t\t\t-1 & 3 & 4\\\\\n\t\t\t 0 & 1 & 3\\\\\n\t\t\\end{bNiceMatrix}\\colvec{0;0;1} &= \\colvec{\\cancel{1\\cdot0}+\\cancel{2\\cdot0}+\\cancel{0\\cdot1};-\\cancel{1\\cdot0}+\\cancel{3\\cdot0}+4\\cdot1;\\cancel{\\cancel{0\\cdot0}}+\\cancel{1\\cdot0}+3\\cdot1} = \\colvec{0;4;3}.\n\t\\end{align*}\n\\end{example}\n\n\\subsection{Matrix representation of the basic linear transformations (2D)}\nWe can now represent all of the basic linear transformations in $\\Rs{2}$ mentioned in the previous section (\\autoref{fig:basicLinearTrans}) as $2\\times2$ matrices. We do this by observing how the basis vectors $\\hat{x}$ and $\\hat{y}$ change after the application of each transformation.\n\n\\begin{descitemize}\n\t\\item[Identity] both basis vectors remain the same: $\\colvec{1;0}\\to\\colvec{1;0},\\ \\colvec{0;1}\\to\\colvec{0;1}$. Therefore the matrix $I$ representing the identity transformation is\n\t\t\\begin{equation}\n\t\t\tI = \\begin{bNiceMatrix} 1&0 \\\\ 0&1 \\end{bNiceMatrix}.\n\t\t\\end{equation}\n\n\t\\item[Scaling by $\\bm{s}$ in the $\\bm{x}$-direction] the basis vector $\\hat{x}$ is streched by $s$: $\\colvec{1;0}\\to\\colvec{s;0}$. The basis vector $\\hat{y}=\\colvec{0;1}$ stays the same. Therefore the matrix $S_{x}$ representing the transformation is\n\t\t\\begin{equation}\n\t\t\tS_{x} = \\begin{bNiceMatrix} s&0 \\\\ 0&1 \\end{bNiceMatrix}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\t\n\t\\item[Scaling by $\\bm{s}$ in the $\\bm{y}$-direction] much like with $S_{x}$, now the basis vector $\\hat{y}$ is the one getting streched, by $\\beta$: $\\colvec{0;1}\\to\\colvec{0;s}$. The basis vector $\\hat{x}=\\colvec{1;0}$ stays the same. Therefore the matrix $S_{y}$ representing the transformation is\n\t\t\\begin{equation}\n\t\t\tS_{y} = \\begin{bNiceMatrix} 1&0 \\\\ 0&s \\end{bNiceMatrix}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\n\t\\item[Rotating by $\\bm{\\theta}$ counter-clockwise about the origin] \\autoref{fig:rotationT} shows how do $\\hat{x}$ and $\\hat{y}$ transformed by the rotation. In the case of $\\hat{x}$, the resulting vector is $R_{\\theta} \\left( \\hat{x} \\right)=\\colvec{\\cos(\\theta),\\sin(\\theta)}$, since thiese are the respective sides of a right triangle of hypotenous $1$ and angle $\\theta$. The components of $R_{\\theta}\\left(\\hat{y}\\right)$ can be calculated by rotating $\\hat{x}$ by $\\theta+\\frac{\\pi}{2}$ ($\\theta+\\ang{90}$): $\\cos \\left( \\theta+\\frac{\\pi}{2} \\right) = -\\sin(\\theta)$, and $\\sin \\left( \\theta+\\frac{\\pi}{2} \\right) = \\cos \\left( \\theta \\right)$. Therefore we get\n\t\t\\begin{equation}\n\t\t\t\\colvec{1;0} \\to \\colvec{\\cos(\\theta);\\sin(\\theta)},\\ \\colvec{0;1} \\to \\colvec{-\\sin(\\theta);\\cos(\\theta)}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\n\t\tAltogether the rotation matrix $R_{\\theta}$ is\n\t\t\\begin{equation}\n\t\t\tR_{\\theta} = \\begin{bNiceMatrix} \\cos(\\theta)&-\\sin(\\theta) \\\\ \\sin(\\theta)&\\cos(\\theta) \\end{bNiceMatrix}.\n\t\t\t\\label{eq:2D_rotation_matrix}\n\t\t\\end{equation}\n\n\t\t\\begin{figure}\n\t\t\t\\centering\n\t\t\t\\begin{tikzpicture}\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\tvector plane,\n\t\t\t\t\twidth=10cm, height=10cm,\n\t\t\t\t\txmin=-1.3, xmax=1.3,\n\t\t\t\t\tymin=-1.3, ymax=1.3,\n\t\t\t\t\txtick={-1,0,1},\n\t\t\t\t\tytick={-1,0,1},\n\t\t\t\t\tyticklabel pos=right,\n\t\t\t\t\tyticklabel style={anchor=west},\n\t\t\t\t]\n\t\t\t\t\\pgfmathsetmacro{\\t}{30};\n\t\t\t\t\\draw[black!20] (1,0) arc (0:360:1);\n\t\t\t\t\\tikzset{point/.style={circle, fill=#1, inner sep=0pt, minimum size=3pt}}\n\n\t\t\t\t% x\n\t\t\t\t\\draw[vector, xred] (0,0) -- (1,0) node[midway, below] {$\\hat{x}$};\n\t\t\t\t\\draw[vector, xred, dashed] (0,0) -- ({cos(\\t)},{sin(\\t)}) node[midway, above, rotate=\\t] {$R_{\\theta} \\left( \\hat{x} \\right)$};\n\t\t\t\t\\fill[xpurple, opacity=0.15] (0,0) -- (1,0) arc (0:\\t:1) -- cycle;\n\t\t\t\t\\draw[vector, xpurple, dashed] (1,0) arc (0:\\t:1) node[point={xred}] (rx) {};\n\t\t\t\t\\node[text=xpurple] at ({1.1*cos(\\t/2)},{1.1*sin(\\t/2)}) {$\\theta$};\n\t\t\t\t\n\t\t\t\t% y\n\t\t\t\t\\draw[vector, xblue] (0,0) -- (0,1) node[midway, right] {$\\hat{y}$};\n\t\t\t\t\\draw[vector, xblue, dashed] (0,0) -- ({-sin(\\t)},{cos(\\t)}) node[midway, below, rotate={\\t-90}] {$R_{\\theta} \\left( \\hat{y} \\right)$};\n\t\t\t\t\\fill[xpurple, opacity=0.15] (0,0) -- (0,1) arc (90:{90+\\t}:1) -- cycle;\n\t\t\t\t\\draw[vector, xpurple, dashed] (0,1) arc (90:{90+\\t}:1) node[point={xblue}] (ry) {};\n\t\t\t\t\\node[text=xpurple] at ({-1.1*sin(\\t/2)},{1.1*cos(\\t/2)}) {$\\theta$};\n\t\t\t\t\\end{axis}\n\t\t\t\t\\node[xred, anchor=west, yshift=5pt]  at (rx) {$\\left(  \\Ctrig,\\Strig \\right)$};\n\t\t\t\t\\node[xblue, anchor=east, xshift=-4pt] at (ry) {$\\left( -\\Strig,\\Ctrig \\right)$};\n\t\t\t\\end{tikzpicture}\n\t\t\t\\caption{Rotation of $\\textcolor{xred}{\\hat{x}}$ and $\\textcolor{xblue}{\\hat{y}}$ by an angle $\\textcolor{xpurple}{\\theta}$ counter-clockwise about the origin. The notations $\\Ctrig,\\Strig$ stand for $\\cos(\\textcolor{xpurple}{\\theta})$ and $\\sin(\\textcolor{xpurple}{\\theta})$, respectively.}\n\t\t\t\\label{fig:rotationT}\n\t\t\\end{figure}\n\t\n\t\\item[Skew by $\\bm{k}$ in the $\\bm{x}$-direction] what differentiates this transformation from scaling in the $x$-direction is that a skew changes only $\\hat{y}$ by adding to it some horizontal displacement $\\vec{K}=k\\hat{x}$ (see \\autoref{fig:skew_in_x}). Therefore $\\hat{x}$ remains the same while $\\hat{y}$ is transformed as $\\hat{y}\\to\\hat{y}+\\vec{k}=\\hat{y}+k\\hat{x}=\\colvec{0;1}+\\colvec{k;0}=\\colvec{k;1}$, and altogether the matrix is\n\t\t\\begin{equation}\n\t\t\tK_{x} = \\begin{bNiceMatrix} 1&k \\\\ 0&1 \\end{bNiceMatrix}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\t\t\n\t\t\\begin{figure}\n\t\t\t\\centering\n\t\t\t\\begin{tikzpicture}\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\tvector plane,\n\t\t\t\t\twidth=10cm, height=10cm,\n\t\t\t\t\txmin=-1.3, xmax=1.3,\n\t\t\t\t\tymin=-1.3, ymax=1.3,\n\t\t\t\t\tticks=none,\n\t\t\t\t]\n\t\t\t\t\\draw[vector, xred]  (0,0) -- (1,0) node[midway, below] {$\\hat{x}, K_{x}\\left(\\hat{x}\\right)$};\n\t\t\t\t\\draw[vector, xblue] (0,0) -- (0,1) node[midway, right] {$\\hat{y}$};\n\t\t\t\t\\draw[vector, xblue, dashed] (0,0) -- (0.5,1) node[midway, right] {$K_{x}\\left( \\hat{y} \\right)$};\n\t\t\t\t\\draw[vector, xpurple, dashed] (0,1) -- (0.5,1) node [midway, above] {$\\vec{k}=k\\hat{x}$};\n\t\t\t\t\\end{axis}\n\t\t\t\\end{tikzpicture}\n\t\t\t\\caption{Skew in the $x$-direction.}\n\t\t\t\\label{fig:skew_in_x}\n\t\t\\end{figure}\n\n\t\\item[Skew by $\\bm{k}$ in the $\\bm{y}$-direction] same idea, except the roles of the axes are reveresed:\n\t\t\\[\n\t\t\t\\colvec{1;0}\\to\\colvec{1;k},\\ \\colvec{0;1}\\to\\colvec{0;1}.\n\t\t\\]\n\t\tThus the matrix is\n\t\t\\begin{equation}\n\t\t\tK_{y} = \\begin{bNiceMatrix} 1&0 \\\\ k&1 \\end{bNiceMatrix}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\n\t\\item[Reflections across a line going through the origin] in the case of reflections across the $x$-axis, $\\hat{x}$ stays the same, while $\\hat{y}$ is flipped (see \\autoref{fig:ref_x_axis}), i.e. $\\colvec{0;1}\\to-\\colvec{0;1}=\\colvec{0;-1}$. Therefore the matrix is\n\t\t\\begin{equation}\n\t\t\t\\Refl_{x} = \\begin{bNiceMatrix} 1&0 \\\\ 0&-1 \\end{bNiceMatrix}.\n\t\t\\end{equation}\n\t\t\n\t\tSimilarily, a reflection across the $y$-axis flipps $\\hat{x}$ while keeping $\\hat{y}$ the same (see \\autoref{fig:ref_y_axis}), i.e.\n\t\t\\begin{equation}\n\t\t\t\\Refl_{y} = \\begin{bNiceMatrix} -1&0 \\\\ 0&1 \\end{bNiceMatrix}. \n\t\t\\end{equation}\n\t\t\n\t\tAnother special case of these kinds of reflections is done across the line rotated by $\\frac{\\pi}{4}=\\ang{45}$ relative to the $x$-axis, i.e the line $y=x$. In this case $\\hat{x}$ and $\\hat{y}$ are swapped, giving\n\t\t\\begin{equation}\n\t\t\t\\Refl_{\\frac{\\pi}{4}} = \\begin{bNiceMatrix} 0&1 \\\\ 1&0 \\end{bNiceMatrix}. \n\t\t\\end{equation}\n\n\t\tThe most general reflection is made across a line of angle $\\theta$ relative to the $x$-axis (see \\autoref{fig:ref_line}):\n\t\t\\begin{equation}\n\t\t\t\\Refl_{\\theta} = \\begin{bNiceMatrix} \\cos \\left( 2\\theta \\right) & \\sin \\left( 2\\theta \\right) \\\\ \\sin \\left( 2\\theta \\right) & -\\cos \\left( 2\\theta \\right) \\end{bNiceMatrix}.\n\t\t\t\\label{eq:reflect_general_2x2}\n\t\t\\end{equation}\n\t\tA way to calculate this matrix will be shown later in the chapter.\n\n\t\tWe can translate the matrix to be based on the slope $m$ of the line instead of its angle $\\theta$ relative to the $x$-axis by using the relation $m=\\tan\\left(\\theta\\right)$ and the two trigonomentric identities for double angles (\\autoref{eq:tan_double_angles}):\n\t\t\\begin{align*}\n\t\t\t\\begin{bNiceMatrix} \\cos \\left( 2\\theta \\right) & \\sin \\left( 2\\theta \\right) \\\\ \\sin \\left( 2\\theta \\right) & -\\cos \\left( 2\\theta \\right) \\end{bNiceMatrix} &= \\begin{bNiceMatrix} \\frac{1-\\tan^{2} \\left( \\theta \\right) }{1+\\tan^{2} \\left( \\theta \\right) } & \\frac{2\\tan \\left( \\theta \\right) }{1+\\tan^{2} \\left( \\theta \\right) } \\\\ \\frac{2\\tan \\left( \\theta \\right) }{1+\\tan^{2} \\left( \\theta \\right) } & \\frac{\\tan^{2} \\left( \\theta \\right)-1 }{1+\\tan^{2} \\left( \\theta \\right) } \\end{bNiceMatrix}\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{1}{1+\\tan^{2} \\left( \\theta \\right)}\\begin{bNiceMatrix} 1-\\tan^{2} \\left( \\theta \\right) & 2\\tan \\left( \\theta \\right) \\\\ 2\\tan \\left( \\theta \\right) & \\tan^{2} \\left( \\theta \\right) -1  \\end{bNiceMatrix}\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{1}{1+m^{2}} \\begin{bNiceMatrix} 1-m^{2} & 2m \\\\ 2m & m^{2}-1 \\end{bNiceMatrix}.\n\t\t\\end{align*}\t\n\n\t\t\\begin{figure}\n\t\t\t\\centering\n\t\t\t\\begin{subfigure}[c]{0.45\\textwidth}\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{tikzpicture}\n\t\t\t\t\t\\begin{axis}[\n\t\t\t\t\t\tvector plane,\n\t\t\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\t\t\txmin=-1.5, xmax=1.5,\n\t\t\t\t\t\tymin=-1.5, ymax=1.5,\n\t\t\t\t\t\tticks=none,\n\t\t\t\t\t]\n\t\t\t\t\t\\draw[vector, xred]  (0,0) -- (1,0) node[below] {$\\hat{x},\\ \\Refl_{x}\\left(\\hat{x}\\right)$};\n\t\t\t\t\t\\draw[vector, xblue] (0,0) -- (0,1) node[right] {$\\hat{y}$};\n\t\t\t\t\t\\draw[vector, xblue, dashed] (0,0) -- (0,-1) node[right] {$\\Refl_{x}\\left(\\hat{y}\\right)$};\n\t\t\t\t\t\\end{axis}\n\t\t\t\t\\end{tikzpicture}\t\n\t\t\t\\end{center}\n\t\t\t\\caption{Reflection across the $x$-axis.}\n\t\t\t\\label{fig:ref_x_axis}\n\t\t\t\\end{subfigure}\n\t\t\t\\hfill\n\t\t\t\\begin{subfigure}[c]{0.45\\textwidth}\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{tikzpicture}\n\t\t\t\t\t\\begin{axis}[\n\t\t\t\t\t\tvector plane,\n\t\t\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\t\t\txmin=-1.5, xmax=1.5,\n\t\t\t\t\t\tymin=-1.5, ymax=1.5,\n\t\t\t\t\t\tticks=none,\n\t\t\t\t\t]\n\t\t\t\t\t\\draw[vector, xred]  (0,0) -- (1,0) node[below] {$\\hat{x}$};\n\t\t\t\t\t\\draw[vector, xred, dashed] (0,0) -- (-1,0) node[below] {$\\Refl_{y}\\left(\\hat{x}\\right)$};\n\t\t\t\t\t\\draw[vector, xblue] (0,0) -- (0,1) node[right] {$\\hat{y},\\ \\Refl_{y}\\left(\\hat{y}\\right)$};\n\t\t\t\t\t\\end{axis}\n\t\t\t\t\\end{tikzpicture}\t\n\t\t\t\\end{center}\n\t\t\t\\caption{Reflection across the $y$-axis.}\n\t\t\t\\label{fig:ref_y_axis}\n\t\t\t\\end{subfigure}\n\t\t\t\\begin{subfigure}[c]{0.45\\textwidth}\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{tikzpicture}\n\t\t\t\t\t\\begin{axis}[\n\t\t\t\t\t\tvector plane,\n\t\t\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\t\t\txmin=-1.5, xmax=1.5,\n\t\t\t\t\t\tymin=-1.5, ymax=1.5,\n\t\t\t\t\t\tticks=none,\n\t\t\t\t\t]\n\t\t\t\t\t% original vectors\n\t\t\t\t\t\\draw[vector, xred]  (0,0) -- (1,0) node[below] {$\\hat{x}$};\n\t\t\t\t\t\\draw[vector, xblue] (0,0) -- (0,1) node[right] {$\\hat{y}$};\n\t\t\t\t\t\n\t\t\t\t\t% reflection line\n\t\t\t\t\t\\draw[thick, black!75, dashed] (-1.5,-0.5) -- (1.5,0.5);\n\n\t\t\t\t\t% reflected vectors\n\t\t\t\t\t\\draw[vector, xred, dashed]  (0,0) -- (0.8,0.6) node[below, anchor=west, yshift=5pt] {$\\Refl_{\\theta}\\left(\\hat{x}\\right)$};\n\t\t\t\t\t\\draw[vector, xblue, dashed, anchor=west] (0,0) -- (0.6,-0.8) node[right] {$\\Refl_{\\theta}\\left(\\hat{y}\\right)$};\n\n\t\t\t\t\t% angles\n\t\t\t\t\t\\fill[xpurple, opacity=0.2] (0,0) -- (0.5,0) arc (0:18.435:0.5) node (A) {} -- cycle;\n\t\t\t\t\t\\fill[xgreen, opacity=0.2]  (0,0) -- (A) arc (18.435:36.87:0.5) -- (0,0);\n\t\t\t\t\t\\fill[xpurple, opacity=0.2] (0,0) -- (0,0.5) arc (90:198.435:0.5) node (B) {} -- cycle;\n\t\t\t\t\t\\fill[xgreen, opacity=0.2]  (0,0) -- (B) arc (198.435:306.87:0.5) -- (0,0);\n\t\t\t\t\t\\end{axis}\n\t\t\t\t\\end{tikzpicture}\t\n\t\t\t\\end{center}\n\t\t\t\\caption{Reflection across a line going through the origin. Notice how in both cases the purple and green angles are the same: this shows that both $\\hat{x}$ and $\\hat{y}$ are reflected across the line.}\n\t\t\t\\label{fig:ref_line}\n\t\t\t\\end{subfigure}\n\t\t\t\\caption{Reflections across different lines going through the origin.}\n\t\t\t\\label{fig:reflections}\n\t\t\\end{figure}\n\t\t\n\t\\item[Reflection across the origin] in this case both $\\hat{x}$ and $\\hat{y}$ are flipped, i.e.\n\t\t\\[\n\t\t\t\\colvec{1;0}\\to\\colvec{-1;0},\\ \\colvec{0;1}\\to\\colvec{0;-1},\n\t\t\\]\n\t\tand the matrix is essentially a rotation by $\\pi$ ($\\ang{180}$) around the origin:\n\t\t\\begin{equation}\n\t\t\tR = \\begin{bNiceMatrix} -1&0 \\\\ 0&-1 \\end{bNiceMatrix}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\\end{descitemize}\n\nTable \\autoref{tab:matrix_basic_LTs} summarizes all the matrices of the basic linear transformations.\n\n\\begin{longtable}{lcccc}\n\t% !!! vvv MUST FIND WHY THESE DON'T WORK vvv !!! %\n\t% \\caption{my caption}\\\\\n\t% \\label{tab:matrix_basic_LTs}\n\t% !!! ^^^ THESE TWO LINES ^^^ !!! %\n\t\\toprule\n\tTransformation & Trans Tapir & $T \\left( \\hat{x} \\right)$ & $T \\left( \\hat{y} \\right)$ & Matrix\\\\\n\t\\midrule\n\tIdentity & \\tikz[baseline=-0.5ex]{\\tapirTransComp{1}{0}{0}{1}{0}{0}{}} & $\\colvec{1;0}$ & $\\colvec{0;1}$ & $\\begin{bNiceMatrix} 1&0 \\\\ 0&1 \\end{bNiceMatrix}$\\\\\n\tScale in $x$ & \\tikz[baseline=-0.5ex]{\\tapirTransComp{1.3}{0}{0}{1}{0}{0}{}} & $\\colvec{s;0}$ & $\\colvec{0;1}$ & $\\begin{bNiceMatrix} s&0 \\\\ 0&1 \\end{bNiceMatrix}$\\\\\n\tScale in $y$ & \\tikz[baseline=-0.5ex]{\\tapirTransComp{1}{0}{0}{1.4}{0}{0}{}} & $\\colvec{1;0}$ & $\\colvec{0;s}$ & $\\begin{bNiceMatrix} 1&0 \\\\ 0&s \\end{bNiceMatrix}$\\\\\n\tRotation & \\tikz[baseline=-0.5ex]{\\tapirTransComp{0.866}{0.5}{-0.5}{0.866}{0}{0}{}} & $\\colvec{\\Ctrig;-\\Strig}$ & $\\colvec{\\Strig;\\Ctrig}$ & $\\begin{bNiceMatrix} \\Ctrig & -\\Strig \\\\ \\Strig & \\Ctrig \\end{bNiceMatrix}$\\\\\n\tSkew in $x$ & \\tikz[baseline=-0.5ex]{\\tapirTransComp{1}{0}{0.5}{1}{0}{0}{}} & $\\colvec{1;0}$ & $\\colvec{k;1}$ & $\\begin{bNiceMatrix} 1&0 \\\\ k&1 \\end{bNiceMatrix}$\\\\\n\tSkew in $y$ & \\tikz[baseline=-0.5ex]{\\tapirTransComp{1}{0.35}{0}{1}{0}{0}{}} & $\\colvec{1;k}$ & $\\colvec{0;1}$ & $\\begin{bNiceMatrix} 1&k \\\\ 0&1 \\end{bNiceMatrix}$\\\\\n\tReflection by $x$ & \\tikz[baseline=-0.5ex]{\\tapirTransComp{1}{0}{0}{-1}{0}{0}{}} & $\\colvec{1;0}$ & $\\colvec{0;-1}$ & $\\begin{bNiceMatrix} 1&0 \\\\ 0&-1 \\end{bNiceMatrix}$\\\\\n\tReflection by $y$ & \\tikz[baseline=-0.5ex]{\\tapirTransComp{-1}{0}{0}{1}{0}{0}{}} & $\\colvec{-1;0}$ & $\\colvec{0;1}$ & $\\begin{bNiceMatrix} -1&0 \\\\ 0&1 \\end{bNiceMatrix}$\\\\\n\tReflection by line & \\tikz[baseline=-0.5ex]{\\tapirTransComp{0.882}{0.471}{0.471}{-0.882}{0}{0}{};\\draw[very thick, dashed, xpurple](-2,-0.5)--(2,0.5)node[pos=-0.05, anchor=east] {$y=mx$}} & $\\colvec{\\Ctrig_{2};\\Strig_{2}}$ & $\\colvec{\\Strig_{2};-\\Ctrig_{2}}$ & $\\begin{bNiceMatrix} \\Ctrig_{2}&\\Strig_{2} \\\\ \\Strig_{2}&-\\Ctrig_{2} \\end{bNiceMatrix}$\\\\\n\tReflection about origin & \\tikz[baseline=-0.5ex]{\\tapirTransComp{-1}{0}{0}{-1}{0}{0}{}} & $\\colvec{-1;0}$ & $\\colvec{0;-1}$ & $\\begin{bNiceMatrix} -1&0 \\\\ 0&-1 \\end{bNiceMatrix}$\\\\\n\t\\bottomrule\n\\end{longtable}\n\n\\subsection{Matrix representation of the basic linear transformations (3D)}\nIn 3-dimensions, the respective matrices are very similar. For example, the matrix for scaling by $\\alpha$ in the $x$-direction, $\\beta$ in the $y$-direction and $\\gamma$ in the $z$-direction is\n\\begin{equation}\n\tS = \n\t\\begin{bNiceMatrix}\n\t\t\\alpha & 0 & 0\\\\\n\t\t0 & \\beta & 0\\\\\n\t\t0 & 0 & \\gamma\n\t\\end{bNiceMatrix}.\n\t\\label{eq:3d_scale_matrix}\n\\end{equation}\n\nAs mentioned in the previous section, in 3-dimensions there are infinitely many rotations: the axis of rotation can be any line going through the origin (i.e. any vector except $\\vec{0}$ can represent an axis of rotation). Let us start with constructing rotations around the three axes $x,y$ and $z$ first. When rotating around the $x$ axis it stays stationary, while the rotation itself is done in the $yz$-plane. This means that we can take the $2\\times2$ rotation matrix (\\autoref{eq:2D_rotation_matrix}) and expand it such that it affects only the $yz$-plane:\n\n\\vspace{2em}\n\\begin{equation}\n\tR^{x}_{\\theta} =\n\t\\begin{bNiceMatrix}\n\t\t\\tikzmark{D1}1 & 0 & 0\\\\\n\t\t0 & \\tikzmark{E1} \\cos \\left( \\theta \\right) & -\\sin \\left( \\theta \\right) \\\\\n\t\t0\\tikzmark{D2} & \\sin \\left( \\theta \\right) & \\cos \\left( \\theta \\right)\\tikzmark{E2}\n\t\\end{bNiceMatrix}.\n\t\\label{eq:rotation_matrix_x}\n\\end{equation}\n\\begin{tikzpicture}[overlay, remember picture, blend mode=multiply]\n\t\\small\n\t\\draw[highlight={xred}] ($(pic cs:D1)+(-4pt,9pt)$) rectangle node[hltxt={xred}, above right, anchor=east, xshift=-1cm] (Atxt) {$\\hat{x}$ doesn't change} ($(pic cs:D2)+(4pt,-5pt)$);\n\t\\draw[hlarrow={xred}] (Atxt.east) to [out=0, in=90] ($(pic cs:D1) + (3pt,10pt)$);\n\t\\draw[highlight={xgreen}] ($(pic cs:E1)+(-4pt,9pt)$) rectangle node[hltxt={xgreen}, below left, anchor=west, yshift=-3cm, xshift=9mm] (Btxt) {2D rotation matrix} ($(pic cs:E2)+(4pt,-5pt)$);\n\t\\draw[hlarrow={xgreen}] (Btxt.west) to [out=180, in=-90] ($(pic cs:E1) + (35pt,-20pt)$);\n\\end{tikzpicture}\n\n\\vspace{3em}\nA graphical representation of the rotation can be seen in \\autoref{fig:rotation_in_yz}.\n\n\\begin{figure}\n\t\\centering\n\t\\def\\angThe{75}\n\t\\def\\angPhi{45}\n\t\\tdplotsetmaincoords{\\angThe}{\\angPhi}\n\t\\begin{tikzpicture}[tdplot_main_coords]\n\t\t\\draw[stealth-, very thick] (-3,0,0) -- (0,0,0);\n\t\t\\begin{scope}[canvas is yz plane at x=0]\n\t\t\t\\fill[fill=xgreen, fill opacity=0.2] (-2,2) -- (2,2) -- (2,-2) -- (-2,-2) -- cycle;\n\t\t\t\\draw[step=0.5, xdarkgreen!30] (-2,-2) grid (2,2);\n\t\t\t\\draw[vector, xgreen] (-1,0) arc (180:350:1);\n\t\t\t\\draw[vector, xgreen] (1,0) arc (0:170:1);\n\t\t\\end{scope}\n\t\t\\draw[stealth-stealth, very thick] (0,-3,0) -- (0,3,0) node[pos=1.05] {$y$};\n\t\t\\draw[stealth-stealth, very thick] (0,0,-3) -- (0,0,3) node[pos=1.05] {$z$};\n\t\t\\begin{scope}[canvas is yz plane at x=2]\n\t\t\t\\draw[vector, xgreen] (-0.5,0) arc (180:350:0.5);\n\t\t\\end{scope}\n\t\t\\draw[-stealth, very thick] (0,0,0) -- (3,0,0) node[pos=1.05] {$x$};\n\t\t\\begin{scope}[canvas is yz plane at x=2]\n\t\t\t\\draw[vector, xgreen] (0.5,0) arc (0:170:0.5);\n\t\t\\end{scope}\n\t\\end{tikzpicture}\n\t\\caption{In $\\Rs{3}$, rotation around the $x$-axis is a rotation in the $yz$-plane (i.e. $x=0$).}\n\t\\label{fig:rotation_in_yz}\n\\end{figure}\n\nThe rotation matrices around the $y$- and $z$-axes follow the same structure:\n\\begin{align}\n\tR^{y}_{\\varphi} &=\n\t\t\\begin{bNiceMatrix}\n\t\t\t\\cos \\left( \\varphi \\right) & 0 & \\sin \\left( \\varphi \\right)\\\\\n\t\t\t0 & 1 & 0 \\\\\n\t\t\t-\\sin \\left( \\varphi \\right) & 0 & \\cos \\left( \\varphi \\right)\n\t\t\\end{bNiceMatrix},\\\\\n\tR^{z}_{\\psi} &=\n\t\t\\begin{bNiceMatrix}\n\t\t\t\\cos \\left( \\psi \\right) & -\\sin \\left( \\psi \\right) & 0\\\\\n\t\t\t\\sin \\left( \\psi \\right) & \\cos \\left( \\psi \\right)  & 0\\\\\n\t\t\t0 & 0 & 1\n\t\t\\end{bNiceMatrix}.\n\t\\label{eq:rotation_y_z}\n\\end{align}\n\n\\begin{note}{Direction of the $y$-axis}{}\n\tThe signs of $\\sin \\left( \\varphi \\right)$ in $R^{y}_{\\varphi}$ are flipped compared to $R^{x}_{\\theta}$ and $R^{z}_{\\psi}$, for the same reason a similar thing happens in the $y$-component of the cross product: it is due to the use of a right-handed system.\n\\end{note}\n\nThe most general rotation in $\\Rs{3}$, i.e. around an axis represented by the unit vector $\\hat{u}=\\colvec{u_{x};u_{y};u_{z}}$ counter-clockwise by an angle $\\theta$, is given in matrix form as\n\\begin{equation}\n\tR_{\\theta}=\n\t\\begin{bNiceMatrix}\n\t\t\\cos \\left( \\theta \\right) +u_{x}^{2}\\left[1-\\cos \\left( \\theta \\right) \\right] & u_{x}u_{y}\\left[1-\\cos \\left( \\theta \\right) \\right]-u_{z}\\sin \\left( \\theta \\right)  & u_{x}u_{z}\\left[1-\\cos \\left( \\theta \\right) \\right]+u_{y}\\sin \\left( \\theta \\right) \\\\\n\t\tu_{y}u_{x}\\left[1-\\cos \\left( \\theta \\right) \\right]+u_{z}\\sin \\left( \\theta \\right)  & \\cos \\left( \\theta \\right) +u_{y}^{2}\\left[1-\\cos \\left( \\theta \\right) \\right] & u_{y}u_{z}\\left[1-\\cos \\left( \\theta \\right) \\right]-u_{x}\\sin \\left( \\theta \\right) \\\\\n\t\tu_{z}u_{x}\\left[1-\\cos \\left( \\theta \\right) \\right]-u_{y}\\sin \\left( \\theta \\right)  & u_{z}u_{y}\\left[1-\\cos \\left( \\theta \\right) \\right]+u_{x}\\sin \\left( \\theta \\right)  & \\cos \\left( \\theta \\right) +u_{z}^{2}\\left[1-\\cos \\left( \\theta \\right) \\right]\\end{bNiceMatrix}.\n\t\\label{eq:}\n\\end{equation}\nFor the moment the derivation of this matrix is not presented.\n\nTBW: REFLECTIONS IN 3D.\n\n\\subsection{Matrix operations}\nAn important operation that can be performed on a matrix is the \\emph{transpose}: this operation \"rotates\" all rows of the matrix to columns, and wise-versa:\n\\begin{equation}\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\\end{bNiceMatrix}\n\t\\xrightarrow[] {\\text{transpose}}\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{2}{1} & \\cdots & \\Ma{n}{1}\\\\\n\t\t\\Ma{1}{2} & \\Ma{2}{2} & \\cdots & \\Ma{n}{2}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{1}{m} & \\Ma{2}{m} & \\cdots & \\Ma{n}{m}\n\t\\end{bNiceMatrix}.\n\t\\label{eq:transpose}\n\\end{equation}\nMathematically, the transpose takes any element $\\Ma{i}{j}$ of the matrix and exchanges its indeces, yielding $\\Ma{j}{i}$. If the original matrix has dimensions $\\rhl{m}\\times \\bhl{n}$, then the transposed matrix has dimensions $\\rhl{n}\\times \\bhl{m}$. The notation for the transpose of a matrix $A$ is $A^{\\top}$.\n\n\\begin{example}{Transposing matrices}{}\n\tThe following presents three matrices each with its transpose. The elements in each matrix on the left hand side are highlighted column-wise, and these colors remain with the elements after the transpose. That way, the effect of the transpose is clear: columns in the original matrix become rows in the transposed matrix and vice-versa. In addition, the dimensions of each matrix are written below it.\n\n\t\\begin{align*}\n\t\t\\begin{bNiceMatrix}[name=T1]\n\t\t\t1 & 2 & 3\\\\\n\t\t\t4 & 5 & 6\\\\\n\t\t\t7 & 8 & 9\\\\\n\t\t\\end{bNiceMatrix}^{\\top} &=\n\t\t\\begin{bNiceMatrix}[name=T2]\n\t\t\t1 & 4 & 7\\\\\n\t\t\t2 & 5 & 8\\\\\n\t\t\t3 & 6 & 9\\\\\n\t\t\\end{bNiceMatrix}\\\\[10mm]\n\t\t\\begin{bNiceMatrix}[name=T3]\n\t\t\t0 & 1 & -1\\\\\n\t\t\t2 & -3 & 5\\\\\n\t\t\\end{bNiceMatrix}^{\\top} &=\n\t\t\\begin{bNiceMatrix}[name=T4]\n\t\t\t0  & 2\\\\\n\t\t\t1  & -3\\\\\n\t\t\t-1 & 5\\\\\n\t\t\\end{bNiceMatrix}\\\\[10mm]\n\t\t\\begin{bNiceMatrix}[name=T5]\n\t\t\t1\\\\\n\t\t\t2\\\\\n\t\t\t-1\\\\\n\t\t\t0\\\\\n\t\t\t7\\\\\n\t\t\t-4\\\\\n\t\t\\end{bNiceMatrix}^{\\top} &=\n\t\t\\begin{bNiceMatrix}[name=T6]\n\t\t\t1 & 2 & -1 & 0 & 7 & -4\\\\\n\t\t\\end{bNiceMatrix}\n\t\\end{align*}\n\\begin{tikzpicture}[overlay, remember picture, blend mode=multiply, node distance=15pt]\n\t% ---- T1 ---- %\n\t\\MatHL{(T1-1-1),(T1-2-1),(T1-3-1)}{xred!20}\n\t\\MatHL{(T1-1-2),(T1-2-2),(T1-3-2)}{xorange!20}\n\t\\MatHL{(T1-1-3),(T1-2-3),(T1-3-3)}{xgreen!20}\n\t\\node[below of=T1-3-2] {$3\\times3$};\n\t% ---- T2 ---- %\n\t\\MatHL{(T2-1-1),(T2-1-2),(T2-1-3)}{xred!20}\n\t\\MatHL{(T2-2-1),(T2-2-2),(T2-2-3)}{xorange!20}\n\t\\MatHL{(T2-3-1),(T2-3-2),(T2-3-3)}{xgreen!20}\n\t\\node[below of=T2-3-2] {$3\\times3$};\n\t\n\t% ---- T3 ---- %\n\t\\MatHL{(T3-1-1),(T3-2-1)}{xred!20}\n\t\\MatHL{(T3-1-2),(T3-2-2)}{xorange!20}\n\t\\MatHL{(T3-1-3),(T3-2-3)}{xgreen!20}\n\t\\node[below of=T3-2-2] {$2\\times3$};\n\t% ---- T4 ---- %\n\t\\MatHL{(T4-1-1),(T4-1-2)}{xred!20}\n\t\\MatHL{(T4-2-1),(T4-2-2)}{xorange!20}\n\t\\MatHL{(T4-3-1),(T4-3-2)}{xgreen!20}\n\t\\node[below of=T4-3-1, xshift=10pt] {$3\\times2$};\n\t\n\t% ---- T5 ---- %\n\t\\MatHL{(T5-1-1),(T5-2-1),(T5-3-1),(T5-4-1),(T5-5-1),(T5-6-1)}{xred!20}\n\t\\node[below of=T5-6-1] {$6\\times1$};\n\t% ---- T6 ---- %\n\t\\MatHL{(T6-1-1),(T6-1-2),(T6-1-3),(T6-1-4),(T6-1-5),(T6-1-6)}{xred!20}\n\t\\node[below of=T6-1-3, xshift=10pt] {$1\\times6$};\n\\end{tikzpicture}\n\\end{example}\n\nSince for the main diagonal elements of a matrix the row and column have equal indeces, the transpose operation does not affect their position in the matrix, i.e. $\\Ma{i}{i}\\xrightarrow[] {\\text{transpose}}\\Ma{i}{i}$. This means that $\\tr{A}=\\tr{A^{\\top}}$. Also, diagonal matrices are not affected by a transpose. The transpose of a transposed matrix is the original matrix, i.e. $\\left(A^{\\top}\\right)^{\\top} = A$.\n\nMuch like vectors, a matrix can be scaled by a real number, and two matrices can be added together if their dimensions are identical. The rules for scaling a matrix by a scalar and the addition of two matrices are the same as with vectors, namely everything is dome element wise:\n\\begin{descitemize}\n\t\\item[Scaling] given a matrix\n\t\t\\[\n\t\t\tA = \n\t\t\t\\begin{bNiceMatrix}\n\t\t\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\t\t\\end{bNiceMatrix}\n\t\t\\]\n\t\tand a scalar $\\gamma\\in\\mathbb{R}$, their product is\n\t\t\\begin{equation}\n\t\t\t\\gamma A = \n\t\t\t\\begin{bNiceMatrix}\n\t\t\t\t\\gamma\\cdot\\Ma{1}{1} & \\gamma\\cdot\\Ma{1}{2} & \\cdots & \\gamma\\cdot\\Ma{1}{n}\\\\\n\t\t\t\t\\gamma\\cdot\\Ma{2}{1} & \\gamma\\cdot\\Ma{2}{2} & \\cdots & \\gamma\\cdot\\Ma{2}{n}\\\\\n\t\t\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\t\t\\gamma\\cdot\\Ma{m}{1} & \\gamma\\cdot\\Ma{m}{2} & \\cdots & \\gamma\\cdot\\Ma{m}{n}\n\t\t\t\\end{bNiceMatrix}.\n\t\t\t\\label{eq:matrix_scaling}\n\t\t\\end{equation}\n\n\t\\item[Addition] given two matrices,\n\t\t\\[\n\t\t\tA = \n\t\t\t\\begin{bNiceMatrix}\n\t\t\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\t\t\\end{bNiceMatrix},\\quad\n\t\t\tB = \n\t\t\t\\begin{bNiceMatrix}\n\t\t\t\t\\Mb{1}{1} & \\Mb{1}{2} & \\cdots & \\Mb{1}{n}\\\\\n\t\t\t\t\\Mb{2}{1} & \\Mb{2}{2} & \\cdots & \\Mb{2}{n}\\\\\n\t\t\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\t\t\\Mb{m}{1} & \\Mb{m}{2} & \\cdots & \\Mb{m}{n}\n\t\t\t\\end{bNiceMatrix}, \n\t\t\\]\n\t\ttheir sum is\n\t\t\\begin{equation}\n\t\t\tA+B = \n\t\t\t\\begin{bNiceMatrix}\n\t\t\t\t\\Ma{1}{1}+\\Mb{1}{1} & \\Ma{1}{2}+\\Mb{1}{2} & \\cdots & \\Ma{1}{n}+\\Mb{1}{n}\\\\\n\t\t\t\t\\Ma{2}{1}+\\Mb{2}{1} & \\Ma{2}{2}+\\Mb{2}{2} & \\cdots & \\Ma{2}{n}+\\Mb{2}{n}\\\\\n\t\t\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\t\t\\Ma{m}{1}+\\Mb{m}{1} & \\Ma{m}{2}+\\Mb{m}{2} & \\cdots & \\Ma{m}{n}+\\Mb{m}{n}\n\t\t\t\\end{bNiceMatrix}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\\end{descitemize}\n\n\\begin{note}{Matrix addition}{}\n\tSince matrix addition is done \\textbf{element wise} it is comutative, i.e. for any two $m\\times n$ matrices $A$ and $B$,\n\t\\[\n\t\tA+B = B+A.\n\t\\]\n\\end{note}\n\n\\subsection{Types of matrices}\nAny matrix $A$ which represents a transformation of the type $\\Rs{n}\\to\\Rs{n}$ (i.e. from a space onto itself) has the same number of rows and columns (i.e. its dimension is $n\\times n$):\n\\begin{equation}\n\tA =\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{n}{1} & \\Ma{n}{2} & \\cdots & \\Ma{n}{n}\n\t\\end{bNiceMatrix}. \n\t\\label{eq:square_matrix}\n\\end{equation}\n\nDue to their shape, such matrices are called \\emph{square matrices}. The elements $\\Ma{1}{1},\\Ma{2}{2},\\Ma{3}{3},\\dots,\\Ma{n}{n}$ of a square matrix jointly form its \\emph{main diagonal} (also: \\emph{principal diagonal}):\n\n\\vspace{1em}\n\\begin{equation}\n\tA =\n\t\\begin{bNiceMatrix}[name=A_diag]\n\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\Ma{1}{3} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\Ma{2}{3} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\Ma{3}{1} & \\Ma{3}{2} & \\Ma{2}{3} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{n}{1} & \\Ma{n}{2} & \\Ma{n}{3} & \\cdots & \\Ma{n}{n}\n\t\\end{bNiceMatrix}. \n\t\\label{eq:square_matrix_main_diag}\n\\end{equation}\n\\begin{tikzpicture}[overlay, remember picture, blend mode=multiply]\n\t\\foreach \\k in {1,...,3,5}{\n\t\t\\node[fill=xgreen!25, rectangle, minimum width=13pt, minimum height=10pt] at (A_diag-\\k-\\k) {};\n\t}\n\\end{tikzpicture}\n\nThe sum of the main diagonal elements is called the \\emph{trace} of the matrix:\n\\begin{equation}\n\t\\tr \\left( A \\right) = \\sum\\limits_{i=1}^{n}\\Ma{i}{i}.\n\t\\label{eq:trace}\n\\end{equation}\n\n\\emph{Triangular matrices} are matrices in which the elements above or below the main diagonal are all zeros, e.g.\n\n\\begin{center}\n\t\\def\\bperc{25}\n\t\\begin{tabular}{p{-1mm}cp{5mm}p{-1mm}c}\n\t\t$U=$ &\n\t\t$\\begin{bmatrix}\n\t\t\t1 & 6 & 6 & -3 \\\\\n\t\t\t\\textcolor{black!\\bperc}{0} & 2 & 7 & 1 \\\\\n\t\t\t\\textcolor{black!\\bperc}{0} & \\textcolor{black!\\bperc}{0} & 3 & 5 \\\\\n\t\t\t\\textcolor{black!\\bperc}{0} & \\textcolor{black!\\bperc}{0} & \\textcolor{black!\\bperc}{0} & -4\n\t\t\\end{bmatrix},$\n\t\t\t & &\n\t\t$L=$ &\n\t\t$\\begin{bmatrix}\n\t\t\t1 & \\textcolor{black!\\bperc}{0} & \\textcolor{black!\\bperc}{0} & \\textcolor{black!\\bperc}{0} \\\\\n\t\t\t\\tikzmark{LT1} 2 & 3 & \\textcolor{black!\\bperc}{0} & \\textcolor{black!\\bperc}{0} \\\\ \n\t\t\t5 & 1 & -5 & \\textcolor{black!\\bperc}{0} \\\\\n\t\t\t-4 & 1 & 2\\tikzmark{LT2} & -3\n\t\t\\end{bmatrix}.$\n\t\t\\\\[2.5em]\n\t\t\t & upper triangular & & & lower triangular\n\t\\end{tabular}\n\\end{center}\n\nA somewhat formal way of defining the elements \"above\" the main diagonal is all elements $\\Ma{i}{j}$ for which $j<i$. Similarily, when $j>i$ the element $\\Ma{i}{j}$ is \"below\" the main diagonal. Note that the transpose of an upper triangular matrix is a lower triangular matrix and vice-versa.\n\n\\begin{challenge}{Upper/lower triangular matrices}{}\n\tShow that if $A$ is an upper triangular matrix then $A^{\\top}$ is a lower triangular matrix, and if $B$ is a lower triangular matrix then $B^{\\top}$ is an upper triangular matrix.\n\\end{challenge}\n\nA \\emph{diagonal matrix} $A$ is a matrix in which all the non-main diagonal elements, i.e. $\\Ma{i}{j}$ where $\\textcolor{xred}{i}\\neq \\textcolor{xblue}{j}$, equal zero. These matrices can be thought of as scaling matrices: each entry $\\Ma{i}{i}$ tells us how the sapce is scaled in the $i$-th dimension.\n\n\\begin{example}{Diagonal matrices}{}\n\tText.\n\\end{example}\nAs we saw in the cases of $\\Rs{2}$ and $\\Rs{3}$, diagonal matrices are \\emph{scaling matrices}: each entry $a_{ii}$ tells us by how much space is scaled in the $i$-th direction.\n\nA very important family of \\textbf{square} matrices are the \\emph{identity matrices}. These matrices have a unique structure: their main diagonal elements are all $1$, while the rest of the elements (the \\emph{off-diagonal elements}) are all $0$:\n\n\\vspace{1em}\n\\begin{equation}\n\tI_{n} =\n\t\\begin{bNiceMatrix}\n\t\t\\tikzmark{I11} 1 & 0 & 0 & \\cdots & 0\\tikzmark{I1n}\\\\\n\t\t0 & 1 & 0 & \\cdots & 0\\\\\n\t\t0 & 0 & 1 & \\cdots & 0\\\\\n\t\t\\vdots & \\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\tikzmark{In1}0 & 0 & 0 & \\cdots & 1\\tikzmark{Inn}\n\t\\end{bNiceMatrix}\n\t\\label{eq:}\n\\end{equation}\n\\begin{tikzpicture}[overlay, remember picture]\n\t  \\draw [xred, thick, decorate, decoration={brace, amplitude=3pt, raise=7pt}] (pic cs:I1n) -- (pic cs:Inn) node[midway, right, xshift=10pt]{$n$ rows};\n\t  \\draw [xblue, thick, decorate, decoration={brace, amplitude=3pt, raise=10pt}] (pic cs:I11) -- (pic cs:I1n) node[midway, above, yshift=13pt]{$n$ columns};\n\\end{tikzpicture}\n\nSometimes for clarity large areas of zero-value elements in a matrix are depicted together. In that form, the identity matrix is written as\n\\[\n\tI_{n} =\n\t\\begin{bNiceMatrix}\n\t1   &       & \\Block{2-3}<\\huge>{0} \\\\\n\t\t&   1   &        &      &       \\\\\n\t\t&       &   1    &      &       \\\\\n\t\\Block{2-3}<\\huge>{0}\n\t\t&       &       & \\Ddots    &   \\\\\n\t\t&       &       &      &   1   \\\\\n\t\\end{bNiceMatrix}.\n\\]\nIn such a depiction, the off-diagonal elements are each written using a single zero. This kind of notation will come in handy in later sections. Yet another way of defining the identity matrix is by using the \\emph{Kronecker delta}, which takes two integers $i,j$ and returns $1$ if they are equal, otherwise it returns $0$:\n\\begin{equation}\n\t\\delta_{ij} =\n\t\\begin{cases}\n\t\t1 & i=j,\\\\\n\t\t0 & i\\neq j.\n\t\\end{cases}\n\t\\label{eq:kronecker_delta}\n\\end{equation}\nUsing the Kronecker delta, each element $a_{ij}$ of the identity matrix $I_{n}$ simply equals $\\delta_{ij}$.\n\nAn identity matrix of dimension $n$ represents the identity transformation in $\\Rs{n}$: each standard basis vector $\\eb{i}$ is left unchanged by the transformation.\n\n\\begin{example}{Identity matrices}{}\n\tThe following are the identity matrices of $\\Rs{2},\\Rs{3},\\dots,\\Rs{6}$, where in each matrix the main diagonal is highlighted:\n\n\t\\centering\n\t\\setlength\\tabcolsep{3pt}\n\t\\begin{tabular}{ccccc}\n\t\t\\IdentityHl{2}{I2}{xred!30} & \\IdentityHl{3}{I3}{xblue!30} & \\IdentityHl{4}{I4}{xgreen!30} & \\IdentityHl{5}{I5}{xpurple!30} & \\IdentityHl{6}{I6}{xorange!30} \\\\\n\t\t$I_{2}$ & $I_{3}$ & $I_{4}$ & $I_{5}$ & $I_{6}$\n\t\\end{tabular}\n\\end{example}\nIn the next section we will see the importance of the identity matrices.\n\nAnother important family of matrices are the \\emph{orthogonal matrices} (also \\emph{orthonormal matrices}): we say that a matrix $Q$ is an orthogonal matrix if all of its columns, when viewed as column vectors, form an orthonormal set. For example, the identity matrices are all orthogonal matrices. Another orthogonal matrix is the matrix\n\\begin{equation}\n\tB = \\frac{1}{\\sqrt{2}}\\begin{bmatrix}1&1\\\\1&-1\\end{bmatrix},\n\t\\label{eq:}\n\\end{equation}\nsince both $\\frac{1}{\\sqrt{2}}\\colvec{1;1}$ and $\\frac{1}{\\sqrt{2}}\\colvec{1;-1}$ are unit vectors, and they are orthogonal to each other (as seen in REF).\n\nA \\emph{symmetric matrix} is a square matrix for which\n\\begin{equation}\n\tA^{\\top} = A.\n\t\\label{eq:symmetric_matrix}\n\\end{equation}\n\"Graphically\", the symmetry of such matrices can be seen in respect to their main diagonal: if we imagine placing a mirror on the main diagonal, each element $\\Ma{i}{j}$ would be \"reflected\" across the mirror, and thus be equal to $\\Ma{j}{i}$ (see example below).\n\n\n\\begin{example}{Symmetric matrix}{}\n\tThe following matrix $S$ is a symmetric $4\\times4$ matrix, in which the elements $a_{ij},a_{ji}$ are higlighted with the same color:\n\n\t\\centering\n\t\\begin{tikzpicture}[node distance=1.6cm]\n\t\t\\node (Seq) {$S=$};\n\t\t\\matrix (S) [matrix of nodes, right of=Seq, left delimiter={[}, right delimiter={]}]{\n\t\t\t1 & 3 & 5 & 7\\\\\n\t\t\t3 & 0 & 1 & 3\\\\\n\t\t\t5 & 1 & 4 & 2\\\\\n\t\t\t7 & 3 & 2 & 6\\\\\n\t\t};\n\t\t\\tikzset{every node/.style={inner sep=0}}\n\t\t\\scoped[on background layer]{\n\t\t\t\\foreach \\k in {1,...,4}\n\t\t\t\t\\node[fill=white, fit=(S-\\k-\\k)(S-\\k-\\k)] {};\n\t\t\t\\node[fill=xred!20, fit=(S-1-2)(S-1-2)] {};\n\t\t\t\\node[fill=xred!20, fit=(S-2-1)(S-2-1)] {};\n\t\t\t\\node[fill=xblue!20, fit=(S-1-3)(S-1-3)] {};\n\t\t\t\\node[fill=xblue!20, fit=(S-3-1)(S-3-1)] {};\n\t\t\t\\node[fill=xgreen!20, fit=(S-1-4)(S-1-4)] {};\n\t\t\t\\node[fill=xgreen!20, fit=(S-4-1)(S-4-1)] {};\n\t\t\t\\node[fill=xpurple!20, fit=(S-2-3)(S-2-3)] {};\n\t\t\t\\node[fill=xpurple!20, fit=(S-3-2)(S-3-2)] {};\n\t\t\t\\node[fill=xorange!20, fit=(S-2-4)(S-2-4)] {};\n\t\t\t\\node[fill=xorange!20, fit=(S-4-2)(S-4-2)] {};\n\t\t\t\\node[fill=xpink!20, fit=(S-3-4)(S-3-4)] {};\n\t\t\t\\node[fill=xpink!20, fit=(S-4-3)(S-4-3)] {};\n\t\t}\n\t\\end{tikzpicture}\n\\end{example}\n\\begin{note}{Transpose of a symmetric matrix}{}\n\tA symmetric matrix is its own transpose, i.e. if $A$ is a symmetric matrix then $A^{\\top}=A$.\n\\end{note}\n\nA rather non-interesting family of matrices are the \\emph{zero matrices}: these are matrices which have only zero-elements, i.e.\n\\begin{equation}\n\t\\bm{0}_{n} =\n\t\\begin{bNiceMatrix}\n\t\t\\tikzmark{z1}0 & 0 & \\cdots & 0\\tikzmark{z2}\\\\\n\t\t0 & 0 & \\cdots & 0\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t0 & 0 & \\cdots & 0\\tikzmark{z3}\n\t\\end{bNiceMatrix}.\n\t\\label{eq:}\n\\end{equation}\n\\begin{tikzpicture}[overlay, remember picture]\n\t  \\draw [xred, thick, decorate, decoration={brace, amplitude=3pt, raise=7pt}] (pic cs:z2) -- (pic cs:z3) node[midway, right, xshift=10pt]{$m$ rows};\n\t  \\draw [xblue, thick, decorate, decoration={brace, amplitude=3pt, raise=10pt}] (pic cs:z1) -- (pic cs:z2) node[midway, above, yshift=13pt]{$n$ columns};\n\\end{tikzpicture}\nThe zero matrices are called that way since for a given matrix $A$,\n\\begin{align}\n\tA + \\bm{0} &=\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\\end{bNiceMatrix}\n\t+\n\t\\begin{bNiceMatrix}\n\t\t0 & 0 & \\cdots & 0\\\\\n\t\t0 & 0 & \\cdots & 0\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t0 & 0 & \\cdots & 0\n\t\\end{bNiceMatrix}\\nonumber\\\\\n\t\t\t   &=\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1}+0 & \\Ma{1}{2}+0 & \\cdots & \\Ma{1}{n}+0\\\\\n\t\t\\Ma{2}{1}+0 & \\Ma{2}{2}+0 & \\cdots & \\Ma{2}{n}+0\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{m}{1}+0 & \\Ma{m}{2}+0 & \\cdots & \\Ma{m}{n}+0\n\t\\end{bNiceMatrix}\\nonumber\\\\\n\t\t\t   &=\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\\end{bNiceMatrix}\n\t= A.\n\\end{align}\nI.e. much like the number zero and the zero vector, the zero matrix is neutral in respect to addition.\n\n\\subsection{The determinant}\nAs mentioned in \\autoref{sec:LS_developing_intuition}, linear transformation scale all volumes by the same amount\\footnote{remember that 2-dimensional volumes are areas.}. This scaling factor is encapsulated in the matrix representing the transformation by a number called the \\emph{determinant} of the matrix. The determinant of a matrix $A$ is written as $|A|$ and sometimes $\\det(A)$.\n\n\\begin{example}{The determinant as a scaling factor}{}\n\tIn the following transformation, represented by the matrix $A=\\begin{bmatrix}\\frac{1}{2}&0\\\\0&1\\end{bmatrix}$, areas are scaled by a factor of $\\frac{1}{2}$ and therefore $|A|=\\frac{1}{2}$ (the number inside each shapes is its area):\n\n\t\\center\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=7cm, height=7cm,\n\t\t\txmin=-5, xmax=5,\n\t\t\tymin=-5, ymax=5,\n\t\t\tminor tick num=1,\n\t\t\tticklabel style={font=\\tiny},\n\t\t]\n\t\t\t\\draw[thick, xred, fill=xred!20] (-4,-4) rectangle (-3,-3) node[shnode] {$1$};\n\t\t\t\\draw[thick, xgreen, fill=xgreen!20] (-4,4) rectangle (-2,1) node[shnode] {$6$};\n\t\t\t\\draw[thick, xpurple, fill=xpurple!20] (4,2) arc (0:360:1.2616) node[black, xshift=-7mm] {$5$};\n\t\t\\end{axis}\n\t\t\\pgftransformcm{1}{0}{0}{1}{\\pgfpoint{7cm}{0}}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=7cm, height=7cm,\n\t\t\txmin=-10, xmax=10,\n\t\t\tymin=-5, ymax=5,\n\t\t\tminor x tick num=2,\n\t\t\tminor y tick num=1,\n\t\t\txtick={-8,-4,...,8},\n\t\t\txticklabels={-4,-2,2,4},\n\t\t\tticklabel style={font=\\tiny},\n\t\t]\n\t\t\\draw[thick, xred, fill=xred!20] (-4,-4) rectangle (-3,-3) node[shnode] {$\\frac{1}{2}$};\n\t\t\\draw[thick, xgreen, fill=xgreen!20] (-4,4) rectangle (-2,1) node[shnode] {$3$};\n\t\t\\draw[thick, xpurple, fill=xpurple!20] (4,2) arc (0:360:0.8921) node[black, xshift=-2.5mm] {$\\frac{5}{2}$};\n\t\t\\end{axis}\n\t\t\\draw[vector] (-1.3cm,3.5cm) -- ++(1cm,0) node[midway, above] {$A$} node[midway, below] {$|A|=\\frac{1}{2}$};\n\t\\end{tikzpicture}\n\\end{example}\n\nSince there is not much sense in discussing volume changes between different spaces (e.g. $\\Rs{5}\\to\\Rs{7}$), only square matrices, which as you recall represent linear transformations from a space onto itself, have determinants. Determinants can take any real number as values, including zero and negative numbers.\n\nWhat does a zero determinant mean? Since in $\\Rs{2}$ determinants tells us the scaling factor of areas by the transformation, if the matrix representing the linear transformation has a zero determinant, it means that somehow all areas are \"squashed\" by the transformation to zero. There are two possible relevant shapes of zero area: a line going through the origin, or the origin itself which is a point. See \\autoref{fig:zero_det_R2} for a visualization.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=6cm, height=6cm,\n\t\t\txmin=-2, xmax=2,\n\t\t\tymin=-2, ymax=2,\n\t\t\txticklabels={,},\n\t\t\tyticklabels={,},\n\t\t]\n\t\t\t\\fill[xpurple, opacity=0.2] (0,0) rectangle (1,1) node[midway, anchor=center, opacity=1] {$S=1$};\n\t\t\t\\draw[vector, xred] (0,0) -- (1,0) node[midway, below] {$\\hat{x}$};\n\t\t\t\\draw[vector, xblue] (0,0) -- (0,1) node[midway, left] {$\\hat{y}$};\n\t\t\\end{axis}\n\t\t\\pgftransformcm{1}{0}{0}{1}{\\pgfpoint{7cm}{0}}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=6cm, height=6cm,\n\t\t\txmin=-2, xmax=2,\n\t\t\tymin=-2, ymax=2,\n\t\t\txticklabels={,},\n\t\t\tyticklabels={,},\n\t\t]\n\t\t\t\\draw[vector, xred] (0,0) -- (2,1) node[midway, above] {$\\hat{x}$};\n\t\t\t\\draw[vector, xblue] (0,0) -- (-1,-0.5) node[midway, below] {$\\hat{y}$};\n\t\t\\end{axis}\n\t\t\\draw[vector] (-2cm,3cm) -- ++(1.6cm,0) node[midway, above] {$|A|=0$};\n\t\\end{tikzpicture}\n\t\\caption{A transformation which \"squashes\" all areas into a line is represented by a matrix $A$ with $|A|=0$. Note how the unit volume defined by $\\cxhat$ and $\\cyhat$ is transformed into a shape of zero area: a line going through the origin. Also note that $\\cxhat$ and $\\cyhat$ are linearly dependent, since they lie on the same line. Cf. \\autoref{fig:det_2x2}.}\n\t\\label{fig:zero_det_R2}\n\\end{figure}\n\nSimilarily, in $\\Rs{3}$ the determinant tells us how volumes are scaled by a linear transformation, and thus a $3\\times3$ matrix with zero determinant means that all the transformation represented by the matrix \"squashes\" all volumes to one of three relevant shapes with zero volume: a plane going through the origin, a line going through the origin, or the origin point itself. See \\autoref{fig:zero_det_R3} for a visualization.\n\nDISCUSSION OF NEGATIVE DETERMINANTS\\ldots\n\nTo calculate the determinant of a matrix, we start with the simplest case: $2\\times2$ matrices. Since all areas are equaly scaled by a linear transformation, we look at the unit sqaure defined by $\\hat{x}$ and $\\hat{y}$ (see \\autoref{fig:det_2x2}). After the application of the transformation represented by the generic matrix $A=\\begin{bmatrix}a&c\\\\b&d\\end{bmatrix}$ (where $a,b,c,d\\in\\mathbb{R}$), these basis vectors are transformed into the vectors \n\\begin{equation}\n\tA\\hat{x}=\\colvec{a;b} \\mkern9mu \\text{and} \\mkern9mu A\\hat{y}=\\colvec{c;d},\n\t\\label{eq:}\n\\end{equation}\nrespectively.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=6cm, height=6cm,\n\t\t\txmin=-1, xmax=3,\n\t\t\tymin=-1, ymax=3,\n\t\t\txticklabels={,},\n\t\t\tyticklabels={,},\n\t\t]\n\t\t\t\\fill[xpurple, opacity=0.2] (0,0) rectangle (1,1);\n\t\t\t\\node[xpurple, anchor=center] at (0.5,0.5) {$S=1$};\n\t\t\t\\draw[vector, xred] (0,0) -- (1,0) node[midway, below] {$\\hat{x}$};\n\t\t\t\\draw[vector, xblue] (0,0) -- (0,1) node[midway, left] {$\\hat{y}$};\n\t\t\t\\draw[vector, xred!50, dashed] (0,1) -- (1,1);\n\t\t\t\\draw[vector, xblue!50, dashed] (1,0) -- (1,1);\n\t\t\\end{axis}\n\t\t\n\t\t\\pgftransformcm{1}{0}{0}{1}{\\pgfpoint{7cm}{0}}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=6cm, height=6cm,\n\t\t\txmin=-1, xmax=3,\n\t\t\tymin=-1, ymax=3,\n\t\t\txticklabels={,},\n\t\t\tyticklabels={,},\n\t\t]\n\t\t\t\\coordinate (Ax) at (0.5,1.5);\n\t\t\t\\coordinate (Ay) at (1.5,0.5);\n\t\t\t\\coordinate (Axy) at (2,2);\n\t\t\t\\fill[xpurple, opacity=0.2] (0,0) -- (Ax) -- (Axy) -- (Ay) -- cycle;\n\t\t\t\\node[xpurple, anchor=center] at (1,1) {$S=|A|$};\n\t\t\t\\draw[vector, xred] (0,0) -- (Ax) node[pos=1.1, xshift=-6pt] {$A\\hat{x}$};\n\t\t\t\\draw[vector, xblue] (0,0) -- (Ay) node[pos=1.1, xshift=5pt, yshift=-3pt] {$A\\hat{y}$};\n\t\t\t\\draw[vector, xred!50, dashed] (Ay) -- (Axy);\n\t\t\t\\draw[vector, xblue!50, dashed] (Ax) -- (Axy);\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{Unit area defined by the vectors $\\hat{x}$ and $\\hat{y}$ before application of a linear transformation represented by the matrix $A$ (left) and the parallelogram defined by the vectors $A\\hat{x}$ and $A\\hat{y}$ after application of the transformation (right).}\n\t\\label{fig:det_2x2}\n\\end{figure}\n\nThe unit square defined by $\\hat{x}$ and $\\hat{y}$ is therefore transformed into the parallelogram defined by $A\\hat{x}$ and $A\\hat{y}$. \\autoref{eq:cross_product_2d_algebraic} tells us that the area of the parallelogram is $S=ad-bc$. Therefore, the determinant - which equals the change in area after application of $A$, is\n\\begin{equation}\n\t|A| = ad-bc\n\t\\label{eq:determinant_2x2}\n\\end{equation}\nas well.\n\n\\begin{example}{Determinants of $\\bm{2\\times2}$ matrices}{}\n\tSome $2\\times2$ matrices and their determinants:\n\n\t\\begin{align*}\n\t\t\\begin{bmatrix} 1&-2\\\\0&3 \\end{bmatrix} &\\longrightarrow 1\\cdot3-(-2)\\cdot0 = 3.\\\\\n\t\t\\begin{bmatrix} 1&5\\\\1&3 \\end{bmatrix} &\\longrightarrow 1\\cdot3-1\\cdot5 = -2.\\\\\n\t\t\\begin{bmatrix} 1&2\\\\1&2 \\end{bmatrix} &\\longrightarrow 1\\cdot2-1\\cdot2 = 0.\\\\\n\t\t\\begin{bmatrix} 1&2\\\\2&4 \\end{bmatrix} &\\longrightarrow 1\\cdot4-2\\cdot2 = 0.\\\\\n\t\t\\begin{bmatrix} 0&7\\\\0&-3 \\end{bmatrix} &\\longrightarrow \\cancel{0\\cdot(-3)}-\\cancel{0\\cdot7} = 0.\\\\\n\t\\end{align*}\n\\end{example}\n\nCalculating the determinant of a $3\\times3$ matrix is based on the calculation of the determinant of a $2\\times2$ matrix. First, we should define an idea called a \\emph{minor} of a matrix. The $ij$-minor of a $3\\times3$ matrix $A$ is the determinant of the $2\\times2$ matrix resulting by the removal of the $i$-th row and $j$-th column of $A$, e.g. let\n\\newcommand{\\Aminor}[1]{\n\t\\begin{bNiceMatrix}[name=#1]\n\t\t2 & -5 & 4\\\\\n\t\t-3 & 0 & 2\\\\\n\t\t3 & 3 & 2\\\\\n\t\\end{bNiceMatrix}\n}\n\\[\n\tA = \\Aminor{A00},\n\\]\nthen \\autoref{tab:minors_of_A} shows all the minors of $A$.\n\n\\begin{table}\n\t\\centering\n\t\\caption{All the minors of the matrix $A$.}\n\t\\label{tab:minors_of_A}\n\t\\begin{tabular}{lcccr}\n\t\t\\toprule\n\t\t$i$ & $j$ & $3\\times3$-matrix & $2\\times2$ determinant & value\\\\\n\t\t\\midrule\n\t\t$1$ & $1$ & $\\Aminor{A11}$ & $\\begin{vmatrix}0&2\\\\3&2\\end{vmatrix}$   & $-6 $\\\\[10mm]\n\t\t$1$ & $2$ & $\\Aminor{A12}$ & $\\begin{vmatrix}-3&2\\\\3&2\\end{vmatrix}$  & $-12$\\\\[10mm]\n\t\t$1$ & $3$ & $\\Aminor{A13}$ & $\\begin{vmatrix}-3&0\\\\3&3\\end{vmatrix}$  & $-9 $\\\\[10mm]\n\t\t$2$ & $1$ & $\\Aminor{A21}$ & $\\begin{vmatrix}-5&4\\\\3&2\\end{vmatrix}$  & $-22$\\\\[10mm]\n\t\t$2$ & $2$ & $\\Aminor{A22}$ & $\\begin{vmatrix}2&4\\\\3&2\\end{vmatrix}$   & $-8 $\\\\[10mm]\n\t\t$2$ & $3$ & $\\Aminor{A23}$ & $\\begin{vmatrix}2&-5\\\\3&3\\end{vmatrix}$  & $ 21$\\\\[10mm]\n\t\t$3$ & $1$ & $\\Aminor{A31}$ & $\\begin{vmatrix}-5&4\\\\0&2\\end{vmatrix}$  & $-10$\\\\[10mm]\n\t\t$3$ & $2$ & $\\Aminor{A32}$ & $\\begin{vmatrix}2&4\\\\-3&2\\end{vmatrix}$  & $ 16$\\\\[10mm]\n\t\t$3$ & $3$ & $\\Aminor{A33}$ & $\\begin{vmatrix}2&-5\\\\-3&0\\end{vmatrix}$ & $-15$\\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\t\\begin{tikzpicture}[overlay, remember picture]\n\t\t\\MatMinor{A11}{3}{1}{1}\n\t\t\\MatMinor{A12}{3}{1}{2}\n\t\t\\MatMinor{A13}{3}{1}{3}\n\t\t\\MatMinor{A21}{3}{2}{1}\n\t\t\\MatMinor{A22}{3}{2}{2}\n\t\t\\MatMinor{A23}{3}{2}{3}\n\t\t\\MatMinor{A31}{3}{3}{1}\n\t\t\\MatMinor{A32}{3}{3}{2}\n\t\t\\MatMinor{A33}{3}{3}{3}\n\t\\end{tikzpicture}\n\\end{table}\n\nUsing the its minors, the determinant of a $3\\times3$ matrix can be calculated using the following formula:\n\\begin{equation}\n\t|A| = a_{11}m_{11} - a_{12}m_{12} + a_{13}m_{13},\n\t\\label{eq:determinant_3x3}\n\\end{equation}\nwhere $a_{ij}$ and $m_{ij}$ are the elements and minors of the matrix, respectively. For example, using the above matrix $A$, we get that\n\\begin{align*}\n\t|A| &= a_{11}m_{11} - a_{12}m_{12} + a_{13}m_{13}\\\\\n\t\t&= 2\\begin{vmatrix}0&2\\\\3&2\\end{vmatrix} - (-5)\\begin{vmatrix}-3&2\\\\3&2\\end{vmatrix} + 4\\begin{vmatrix}-3&0\\\\3&3\\end{vmatrix}\\\\\n\t\t&= 2\\cdot(-6) - (-5)\\cdot(-12) + 4\\cdot(-9)\\\\\n\t\t&= -12 - 60 - 36 = -108.\n\\end{align*}\n\n\\begin{example}{Determinants of $3\\times3$ matrices}{}\n\t\\ldots\n\\end{example}\n\nThe determinant of a $4\\times4$ matrix follows the same pattern, i.e.\n\\begin{equation}\n\t|A| = a_{11}m_{11} - a_{12}m_{12} + a_{13}m_{13} - a_{14}m_{14},\n\t\\label{eq:}\n\\end{equation}\nwhere again $a_{ij}$ and $m_{ij}$ are, respectively, the elements and minors of a matrix. Much like with the case of a minor of a $3\\times3$ matrix being a determinant of a $2\\times2$ matrix, the minor of a $4\\times4$ matrix is a determinant of a $3\\times3$ matrix, itself calculated using determinants of $2\\times2$ matrices. This pattern continues to higher dimensions, i.e. the calculation of the determinant of a $5\\times5$ matrix uses determinants of $5$ $4\\times4$ matrices, the calculation of the determinant of a $6\\times6$ matrix uses $6$ determinants of $5\\times5$ matrices, and so forth. Therefore, the total number of $2\\times2$ determinants needed for the calculation of the determinant of an $n\\times n$ matrix is\n\\begin{equation}\n\td = n\\times(n-1)\\times(n-2)\\times\\cdots\\times5\\times4\\times3 = \\frac{n!}{2}.\n\t\\label{eq:num_of_2x2_dets_in_n_dim_matrix}\n\\end{equation}\n\nSome properties of determinants:\n\\begin{itemize}\n\t\\item In any case where the columns of a matrix form a linearly dependent set, the determinant is zero. This is due to the loss of dimensionality (i.e. at least one basis vector is mapped to a vector which can be written as a linear combination of the other vectors). One obvious case is where there is one or more columns of zeros in the matrix.\n\t\\item The determinant of the transpose of a matrix is the same as the determinant of the original matrix, i.e. $|A|=|A^{\\top}|$. This is due to the fact that all ideas discussed here can be applied directly to row vectors (as mentioned in the previous sections), and the transpose operation essentially switches between these forms: the columns of the original matrix become the rows in its transposed format. Therefore, the previous property applies to the rows of a matrix as well: e.g. a row of zeros means that the determinant is zero.\n\\end{itemize}\n\n\\subsection{Matrix-vector products}\nAs discussed in the first part of this section, matrices represent linear transformations - in fact, we define a matrix in such a way that its product with a vector gives the result of applying the transformation the matrix represents on the vector (see \\autoref{eq:matrix_vector_product}). Let us now review this idea and elaborate a bit on the process of calculating matrix-vector products.\n\nGiven an $m\\times n$ matrix $A$ and an $n$-dimensional vector $\\vec{v}$, the product $A\\vec{v}$ is an $m$-dimensional vector, in which each element $v_{i}$ is the scalar product between the $i$-th \\textbf{row} of $A$ (interpreted as a vector) and the vector $\\vec{v}$ itself. To illustrate this, we use the following $4\\times3$ matrix $A$ and $3$-dimensional vector $\\vec{v}$:\n\\newcommand{\\Amatv}[1]{\n\t\\begin{bNiceMatrix}[name=#1]\n\t\t1 & 0 & 2\\\\\n\t\t-1 & 3 & -1\\\\\n\t\t2 & 4 & 0\\\\\n\t\t6 & 1 & -3\\\\\n\t\\end{bNiceMatrix}\n}\n\\newcommand{\\Vvec}[1]{\n\t\\begin{bNiceMatrix}[name=#1]\n\t\t2\\\\\n\t\t5\\\\\n\t\t-3\\\\\n\t\\end{bNiceMatrix}\n}\n\\[\n\tA=\\Amatv{A0},\\quad\\vec{v}=\\Vvec{v0}\n\\]\n(note that the number of \\textbf{columns} in $A$ is the same as the number of elements of $\\vec{v}$, namely $3$).\n\nThe resulting vector $\\vec{u}$ is then given by the following formula:\n\\[\n\tu_{i} = \\tikzmark{A}A^{i}\\cdot \\vec{v}.\n\\]\n\\tikz[overlay, remember picture, node distance=15pt]{\n\t\\coordinate (Anode) at ($(pic cs:A)+(5pt,-2pt)$);\n\t\\node[below of=Anode, anchor=center, draw=xgreen, fill=xgreen!20, rounded corners, font=\\small] (Atxt) {$i$-th row of $A$};\n\t\\draw[-stealth, xgreen] (Atxt) -- (Anode);\n}\n\n\\vspace{1em}\nIn the following illustration, each row of $A$ is scalar multiplied with the vector $\\vec{v}$, yielding the respective element of $\\vec{u}$. The respective rows of $A$ and elements of $\\vec{v}$ are color-coded for clarity.\n\n\\[\n\t\\renewcommand{\\arraystretch}{1.5}\n\t\\begin{bNiceMatrix}[name=Av1]\n\t\t1 & 0 & 2\\\\\n\t\t0 & 3 & 1\\\\\n\t\t2 & 4 & 0\\\\\n\t\t6 & 1 & 3\\\\\n\t\\end{bNiceMatrix}\n\t\\quad\\quad\\quad\n\t\\begin{bNiceMatrix}[name=vv1]\n\t\t2\\\\5\\\\0\n\t\\end{bNiceMatrix}\n\t\\quad\\quad\\quad\n\t\\begin{bNiceMatrix}[name=u1]\n\t\t1\\cdot2+\\cancel{0\\cdot5}+\\cancel{2\\cdot0}\\\\\n\t\t\\cancel{0\\cdot2}+3\\cdot5+\\cancel{1\\cdot0}\\\\\n\t\t2\\cdot2+4\\cdot5+\\cancel{\\cancel{0\\cdot0}}\\\\\n\t\t6\\cdot2+1\\cdot5+\\cancel{3\\cdot0}\\\\\n\t\\end{bNiceMatrix}\n\t\\quad\\quad\n\t\\begin{bNiceMatrix}[name=u2]\n\t\t2\\\\15\\\\24\\\\17\n\t\\end{bNiceMatrix}\n\\]\n\\tikz[overlay, remember picture, blend mode=multiply]{\n\t% \\node[mathl={xorange!20}, fit=(vv1-1-1)(vv1-3-1)] {};\n\t\\node[below of=Av1-4-2, yshift=2pt] (Av1-txt) {$A$};\n\t\\node[below of=vv1-3-1, yshift=-6pt] (vv1-txt) {$\\vec{v}$};\n\t\\node[below of=u1-4-1, yshift=2pt] (u1-txt) {$\\vec{u}$};\n\t\\node[below of=u2-4-1, yshift=2pt] (u2-txt) {$\\vec{u}$};\n\t\\foreach \\r in {1,...,4}{\n\t\t\\node[mathl={xcol\\r!25}, fit=(Av1-\\r-1)(Av1-\\r-3)] {};\n\t\t\\node[mathl={xcol\\r!25}, fit=(u1-\\r-1)(u1-\\r-1)] {};\n\t\t\\node[mathl={xcol\\r!25}, fit=(u2-\\r-1)(u2-\\r-1)] {};\n\t\t\\pgfmathsetmacro{\\a}{(\\r-2.5)*8}\n\t\t\\draw[thick, -stealth, xcol\\r] ($(Av1-\\r-3.east)+(7pt,0pt)$) to [out=0, in=180] ($(vv1-2-1.west)-(7pt,\\a pt)$);\n\t\t\\draw[thick, -stealth, xcol\\r] ($(vv1-2-1.east)+(7pt,-\\a pt)$) to [out=0, in=180] ($(u1-\\r-1.west)-(7pt,0)$);\n\t\t\\draw[thick, -stealth, xcol\\r] ($(u1-\\r-1.east)+(7pt,0)$) to ($(u2-\\r-1.west)-(7pt,0)$);\n\t}\n}\n\n\\vspace{2em}\n\\begin{example}{Matrix-vector products}{}\n\tThe following are some examples of matrix-vector products. Note how in each product the number of columns in the matrix is the same as the number of elements of the vector.\n\n\t\\begin{align*}\n\t\t&\\begin{bmatrix}1 & 0 & 2\\\\3 & -1 & 5\\end{bmatrix}\\cdot\\colvec{2;-7;4} = \\colvec{1\\cdot2+\\cancel{0\\cdot(-7)}+2\\cdot4;3\\cdot2-1\\cdot(-7)+5\\cdot4} = \\colvec{10;33}.\\\\[5mm]\n\t\t&\\begin{bmatrix}0 & 4 & -5\\\\4 & 6 & -2\\\\-2 & 2 & 0\\\\\\end{bmatrix} \\cdot \\colvec{0;-3;-2} = \\colvec{\\cancel{\\cancel{0\\cdot0}}+4\\cdot(-3)-5\\cdot(-2);\\cancel{4\\cdot0}+6\\cdot(-3)-2\\cdot(-2);-\\cancel{2\\cdot0}+2\\cdot(-3)+\\cancel{0\\cdot(-2)}} = \\colvec{-2;-14;-6}.\\\\[5mm]\n\t\t&\\begin{bmatrix}-2 & -1\\\\-2 & 1\\\\\\end{bmatrix} \\cdot \\colvec{0;-1} = \\colvec{-\\cancel{2\\cdot0}-1\\cdot(-1);-\\cancel{2\\cdot0}+1\\cdot(-1)} = \\colvec{1;-1}.\\\\[5mm]\n\t\t&\\begin{bmatrix}6 & -1\\\\5 & 0\\\\\\end{bmatrix} \\cdot \\colvec{2;2} = \\colvec{6\\cdot2-1\\cdot2;5\\cdot2+\\cancel{0\\cdot2}} = \\colvec{10;10}.\\\\[5mm]\n\t\t&\\begin{bmatrix}2 & -1 & -2 & -2\\\\2 & 0 & 0 & 5\\\\\\end{bmatrix} \\cdot \\colvec{0;-2;2;4} = \\colvec{\\cancel{2\\cdot0}-1\\cdot(-2)-2\\cdot2-2\\cdot4;\\cancel{2\\cdot0}+\\cancel{0\\cdot(-2)}+\\cancel{0\\cdot2}+5\\cdot4} = \\colvec{-10;20}.\\\\[5mm]\n\t\t&\\begin{bmatrix}3 & 4 & -1 & 1\\\\-2 & 5 & 6 & -2\\\\4 & 5 & -1 & 3\\\\\\end{bmatrix} \\cdot \\colvec{6;3;0;4} = \\colvec{3\\cdot6+4\\cdot3-\\cancel{1\\cdot0}+1\\cdot4;-2\\cdot6+5\\cdot3+\\cancel{6\\cdot0}-2\\cdot4;4\\cdot6+5\\cdot3-\\cancel{1\\cdot0}+3\\cdot4} = \\colvec{34;-5;51}.\n\t\\end{align*}\n\\end{example}\n\n\\subsection{Matrix-matrix products}\nSince the product of a matrix and a vector is itself a vector, one can take the resulting vector and multiply it by another matrix, i.e. given the matrices $A,B$ and a vector $\\vec{v}$, the expression\n\n\\[\n\tB\\cdot \\left( A\\cdot\\vec{v} \\right)\n\\]\nis a vector as well.\n\nOf course, the dimensions of all participating objects must align for the products to be properly defined: if $A$ is an $m\\times n$ matrix, then $\\vec{v}$ must be an $n$-dimensional vector. The result of the product $A\\cdot\\vec{v}$ is then an $m$-dimensional vector which we can call $\\vec{u}$. Thus, for the product $B\\cdot\\vec{u}$ to be properly defined, $B$ must have the same number of columns as $\\vec{u}$ has elements, namely $m$ columns. The number of rows is free, and can be any natural number $k$. Therefore, $B$ is a $k\\times n$ matrix, and the product $B\\cdot\\vec{u}$ is a $k$-dimensional vector.\n\n\\begin{example}{Multiple matrix-vector products}{}\n\tLet\n\t\\[\n\t\tA=\\begin{bmatrix}2 & -1 & 0\\\\5 & 4 & 3\\end{bmatrix},\\quad B=\\begin{bmatrix} 5 & 2\\\\6 & -7\\\\-1 & 0\\end{bmatrix},\\quad \\vec{v}=\\colvec{1;2;5},\n\t\\]\n\tthen\n\t\\[\n\t\t\\vec{u} = A\\cdot\\vec{v} = \\colvec{2\\cdot1-1\\cdot2+\\cancel{0\\cdot5};5\\cdot1+4\\cdot2+3\\cdot5} = \\colvec{0;28}.\n\t\\]\n\tThe product $B\\cdot\\vec{u}$ is defined, since $\\vec{u}$ has the same number of elements as $B$ has columns (namely $2$). Its result is the $3$-dimensional vector\n\t\\[\n\t\t\\vec{w} = B\\cdot\\vec{u} = \\colvec{\\cancel{5\\cdot0}+2\\cdot28;\\cancel{6\\cdot0}-7\\cdot28;-\\cancel{1\\cdot0}+\\cancel{0\\cdot2}8} = \\colvec{56;-196;0}.\n\t\\]\n\\end{example}\n\nMultiple matrix-vector product therefore represent application of multiple linear transformations on an initial vector, in the order the matrix-vector products are performed. For example, consider the vector $\\vec{v}=\\colvec{1;1}$. Rotating $\\vec{v}$ by $\\frac{\\pi}{2}\\ (=\\ang{90})$ counter-clockwise around the origin and then scaling the result by $2$ should yield the vector $\\vec{w}=\\colvec{-2;2}$:\n\\[\n\t\\colvec{1;1} \\xrightarrow[] {\\text{rotation by $\\frac{\\pi}{2}$}} \\colvec{-1;1} \\xrightarrow[] {\\text{scaling by $2$}} \\colvec{-2;2}.\n\\]\n\nUsing the respective matrix representation of each transformation, we get the following:\n\\[\n\t\\begin{bNiceMatrix}[name=mp1] 2 & 0\\\\0 & 2\\end{bNiceMatrix} \\cdot \\left( \\begin{bNiceMatrix}[name=mp2] 0 & 1\\\\-1 & 0 \\end{bNiceMatrix} \\cdot \\begin{bNiceMatrix}[name=mpv1]1\\\\1\\end{bNiceMatrix} \\right) = \\begin{bNiceMatrix}[name=mp3] 2 & 0\\\\0 & 2 \\end{bNiceMatrix} \\cdot \\begin{bNiceMatrix}[name=mpv2] -1\\\\1 \\end{bNiceMatrix} = \\colvec{-2;2}.\n\\]\n\\tikz[overlay, remember picture, blend mode=multiply]{\n\t\\node[mathl={xred!20}, fit=(mp1-1-1)(mp1-2-2)] {};\n\t\\node[mathl={xgreen!20}, fit=(mp2-1-1)(mp2-2-2)] {};\n\t\\node[mathl={xgreen!20}, fit=(mpv1-1-1)(mpv1-2-1)] {};\n\t\\node[mathl={xred!20}, fit=(mp3-1-1)(mp3-2-2)] {};\n\t\\node[mathl={xgreen!20}, fit=(mpv2-1-1)(mpv2-2-1)] {};\n}\n(note that the matrix-vector products are performed from right to left)\n\nMore generally, there could be several products made successionally, i.e.\n\\[\n\tA_{n} \\left( A_{n-1} \\left( A_{n-2} \\cdots \\left( A_{2} \\left( A_{1}\\vec{v} \\right)  \\right)  \\right)  \\right).\n\\]\nMatrix-vector products are most commonly written without the paranthesis nor the dot symbol, i.e. as\n\\[\n\tA_{n}A_{n-1}A_{n-2}\\cdots A_{2}A_{1}\\vec{v},\n\\]\nand the order of multiplication is from left to right, i.e. $A_{1}$ is the first matrix to be multiplied by $\\vec{v}$, then $A_{2}$ is multiplied by the result of the product $A_{1}\\vec{v}$, then $A_{3}$ is multiplied by the result of $A_{2}A_{1}\\vec{v}$ and so on.\n\nAt this point one should wonder whether instead of doing this long chain of products on each individual vector, perhaps the matrices themselves could be multiplied first, yielding a matrix representing the total transformation applied to a vector, as a composition of the separate transformations in the correct order. The answer is of course yes!\\footnote{otherwise this subsection would not be called \"Matrix-matrix products\", after all.}\n\nLet us define the product of two matrices: given the an $m\\times n$ matrix $A$ and an $n\\times k$ matrix $B$, the product $C=AB$ is itself a matrix, having the dimension $m\\times k$, in which every element $c_{ij}$ is the scalar product of the row $A^{i}$ and the column $B_{j}$, i.e.\n\\begin{equation}\n\tc_{ij} = A^{i}\\cdot B_{j} = \\sum_{k=1}^{n}a_{ik}b_{kj} = a_{i1}b_{1j} + a_{i2}b_{2j} + \\dots + a_{in}b_{nj}.\n\t\\label{eq:matrix_matrix_product_elements}\n\\end{equation}\n\n\\autoref{fig:matrix_matrix_product_elements} illustrates this idea graphically.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\matrix [mat] (left) {\n\t\t\t|[draw, fill=xred!30]|a_{11} & |[draw, fill=xred!30]|a_{12}\\\\\n\t\t\ta_{21} & a_{22}\\\\\n\t\t\t|[draw, fill=xblue!30]|a_{31} & |[draw, fill=xblue!30]|a_{32}\\\\\n\t\t};\n\t\t\\matrix [mat] (top) at (4,3.7) {\n\t\t\t|[draw, fill=xred!30]|b_{11} & b_{12} & b_{13} & |[draw, fill=xblue!30]|b_{14} & b_{15}\\\\\n\t\t\t|[draw, fill=xred!30]|b_{21} & b_{22} & b_{23} & |[draw, fill=xblue!30]|b_{24} & b_{25}\\\\\n\t\t};\n\n\t\t\\matrix [mat, text=white] (center) at (4,0) {\n\t\t\t|[draw, black, fill=xred!30]|c_{11} & 0 & 0 & 0 & 0\\\\\n\t\t\t0 & 0 & 0 & 0 & 0\\\\\n\t\t\t0 & 0 & 0 & |[draw, black, fill=xblue!30]|c_{34} & 0\\\\\n\t\t};\n\n\t\t\\node[left=of left, xshift=7mm] {\\huge$A$};\n\t\t\\node[above=of top, yshift=-4mm] {\\huge$B$};\n\t\t\\node[below=of center, yshift=1cm] {\\huge$C=AB$};\n\n\t\t\\draw[boxarr, xred] (left-1-2) -- (center-1-1);\n\t\t\\draw[boxarr, xblue] (left-3-2) -- (center-3-4);\n\t\t\\draw[boxarr, xred] (top-2-1) -- (center-1-1);\n\t\t\\draw[boxarr, xblue] (top-2-4) -- (center-3-4);\n\n\t\t\\draw[line width=3pt, xred] (left-1-1.north west) rectangle (left-1-2.south east);\n\t\t\\draw[line width=3pt, xblue] (left-3-1.north west) rectangle (left-3-2.south east);\n\t\t\\draw[line width=3pt, xred] (top-1-1.north west) rectangle (top-2-1.south east);\n\t\t\\draw[line width=3pt, xblue] (top-1-4.north west) rectangle (top-2-4.south east);\n\t\\end{tikzpicture}\n\t\\caption{The element $c_{ij}$ of the matrix $C=AB$ is the scalar product of the $i$-th row of $A$ and the $j$-th column of $B$.}\n\t\\label{fig:matrix_matrix_product_elements}\n\\end{figure}\n\nUsing the previous example, instead of calculating the $\\frac{pi}{2}$ rotation of the vector $\\colvec{1;1}$ and then scaling it by $2$, we calculate the product of the two matrices representing these transformations, and then apply them to the vector:\n\\[\n\tC=\\begin{bmatrix} 0 & -1\\\\1 & 0 \\end{bmatrix}\\begin{bmatrix} 2 & 0\\\\0 & 2 \\end{bmatrix} =\n\t\\begin{bmatrix}\n\t\t\\cancel{0\\cdot2}-\\cancel{1\\cdot0} & \\cancel{\\cancel{0\\cdot0}}-1\\cdot2\\\\\n\t\t1\\cdot2+\\cancel{\\cancel{0\\cdot0}} & \\cancel{1\\cdot0}+\\cancel{0\\cdot2}\n\t\t\\end{bmatrix} = \\begin{bmatrix} 0 & -2\\\\2 & 0 \\end{bmatrix}.\n\\]\nWe then apply $C$ to the vector and get the expected result:\n\\[\n\tC\\vec{v} = \\begin{bmatrix} 0 & -2\\\\2 & 0 \\end{bmatrix} \\colvec{1;1} = \\colvec{\\cancel{0\\cdot1}-2\\cdot1;2\\cdot1+\\cancel{0\\cdot1}} = \\colvec{-2;2}.\n\\]\n\n\\begin{example}{Matrix-matrix products}{}\n\tTBW\n\\end{example}\n\nRecall that the order of composition of linear transformations matters: $T_{1}\\circ T_{2} \\neq T_{2}\\circ T_{1}$. Therefore, matrix-matrix products, which represent such compositions, are non-commutative, i.e.\n\\begin{equation}\n\tAB\\neq BA.\n\t\\label{eq:matrix_matrix_product_non_commutative}\n\\end{equation}\n\n\\begin{example}{Non-commutativity of matrix-matrix products}{}\n\t\n\\end{example}\n\nOf course, there are special cases where $AB=BA$, but these are the exception and not the norm. An example is the the rotation and scaling of the vector $\\colvec{1;1}$ we saw above: if we flip the order of application of the two linear transformations we get the same result. This is true for any vector:\n\n\\centering\n\\begin{tikzpicture}[node distance=2cm]\n\t\\node (xy) {$\\colvec{x;y}$};\n\t\\node[right of=xy, xshift=2cm] (res) {$\\colvec{-2y;2x}$};\n\t\\node at ($(xy)!0.5!(res)+(0,1cm)$) (in1) {$\\colvec{-y;x}$};\n\t\\node at ($(xy)!0.5!(res)-(0,1cm)$) (in2) {$\\colvec{2x;2y}$};\n\t\\draw[-stealth, thick] (xy)  -- (in1) node[midway, above, rotate=30]  {rotate};\n\t\\draw[-stealth, thick] (xy)  -- (in2) node[midway, below, rotate=-30] {scale};\n\t\\draw[-stealth, thick] (in1) -- (res) node[midway, above, rotate=-30] {scale};\n\t\\draw[-stealth, thick] (in2) -- (res) node[midway, below, rotate=30]  {rotate};\n\\end{tikzpicture}\n\\flushleft\n\nWe can see that fact by multiplying the two matrices directly, in both directions:\n\\begin{align*}\n\t\\begin{bmatrix}0&-1\\\\1&0\\end{bmatrix}\\begin{bmatrix}2&0\\\\0&2\\end{bmatrix} &= \\begin{bmatrix}\\cancel{0\\cdot2}-\\cancel{1\\cdot0} & \\cancel{\\cancel{0\\cdot0}}-1\\cdot2 \\\\1\\cdot2+\\cancel{\\cancel{0\\cdot0}}&\\cancel{1\\cdot0}+\\cancel{0\\cdot2}\\end{bmatrix} = \\begin{bmatrix}0&-2\\\\2&0\\end{bmatrix},\\\\\n\t\\begin{bmatrix}2&0\\\\0&2\\end{bmatrix}\\begin{bmatrix}0&-1\\\\1&0\\end{bmatrix} &= \\begin{bmatrix}\\cancel{2\\cdot0}+\\cancel{0\\cdot1}&2\\cdot(-1)+\\cancel{\\cancel{0\\cdot0}}\\\\1\\cdot2+\\cancel{\\cancel{0\\cdot0}}&\\cancel{1\\cdot0}+\\cancel{0\\cdot2}\\end{bmatrix} = \\begin{bmatrix}0&-2\\\\2&0\\end{bmatrix}.\n\\end{align*}\n\nLater in this chapter we will analyze the conditions for such commutativity to occur.\n\nThe determinant of a matrix-matrix product $AB$ equals the product of the determinants of the separate matrices, i.e.\n\\begin{equation}\n\t|AB| = |A|\\times|B|.\n\t\\label{eq:determinant_AB}\n\\end{equation}\nThe reason is that the change in volume after application of two consecutive transformations is the product of the change in volume for each separate transformation. This also mean that $|AB|=|BA|$. The trace of a matrix-matrix product behaves the same as well:\n\\begin{equation}\n\t\\tr\\left(AB\\right) = \\tr\\left(BA\\right).\n\t\\label{eq:}\n\\end{equation}\n\n\\begin{proof}{Trace of a matrix-matrix product}{}\n\tProve the above behaviour of the trance operator.\n\\end{proof}\n\nOn the other hand, the traspose operator doesn't behave so \"nicely\":\n\\begin{equation}\n\t\\left(AB\\right)^{\\top} = B^{\\top}A^{\\top}.\n\t\\label{eq:}\n\\end{equation}\n\n\\subsection{Inverse matrices}\nSome linear transformations are invertible. For example, given a transformation which rotates any vector in $\\Rs{2}$ by $\\theta$ \\textbf{counter-clockwise} around the origin, its inverse transformation is one that rotates any vector in $\\Rs{2}$ by $\\theta$ \\textbf{clockwise} around the origin (or equivalently by $-\\theta$ counter-clockwise). \\autoref{fig:trans_and_inverses} illustrates such transformation.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{tikzpicture}[node distance=1pt]\n\t\t\\pgfmathsetmacro{\\tha}{15}\n\t\t\\pgfmathsetmacro{\\thb}{80}\n\t\t\\pgfmathsetmacro{\\thas}{\\tha+3}\n\t\t\\pgfmathsetmacro{\\thbs}{\\thb-3}\n\t\t\\pgfmathsetmacro{\\R}{2.5}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=10cm, height=10cm,\n\t\t\txmin=-0.5, xmax=3,\n\t\t\tymin=-0.5, ymax=3,\n\t\t\txticklabels={,},\n\t\t\tyticklabels={,},\n\t\t]\n\t\t\t\\coordinate (v) at ({\\R*cos(\\tha)},{\\R*sin(\\tha)});\n\t\t\t\\coordinate (u) at ({\\R*cos(\\thb)},{\\R*sin(\\thb)});\n\t\t\t\\draw[vector, xred]  (0,0) -- (v) node[pos=1.05] {$\\vec{u}$};\n\t\t\t\\draw[vector, xblue] (0,0) -- (u) node[pos=1.05] {$\\vec{v}$};\n\t\t\t\\draw[vector, xpurple] ({0.4*\\R*cos(\\thas)},{0.4*\\R*sin(\\thas)}) arc (\\thas:\\thbs:{0.4*\\R});\n\t\t\t\\draw[vector, xpurple] ({0.65*\\R*cos(\\thbs)},{0.65*\\R*sin(\\thbs)}) arc (\\thbs:\\thas:{0.65*\\R});\n\t\t\t\\node[draw=xpurple, thick, fill=xpurple!20, rounded corners, text=xpurple] at (0.75,0.75) {$T$};\n\t\t\t\\node[draw=xpurple, thick, fill=xpurple!20, rounded corners, text=xpurple] at (1.2,1.2) {$T^{-1}$};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{The transformation $T$ rotates a vector $\\vu$ by $\\ath$ counter-clockwise, turning it into the vector $\\vv$. Its inverse, $T^{-1}$, turns the vector $\\vv$ back into $\\vu$.}\n\t\\label{fig:trans_and_inverses}\n\\end{figure}\n\nRecall that a transformations (function) is only invertible if and only if it is bijective (\\autoref{sec:relations_and_functions}). Specifically to our case, a non-bijective linear transformation is a transformation $T:\\Rs{m}\\to\\Rs{n}$ for which some two vectors $\\vec{u},\\vec{v}\\in\\Rs{m}$ are mapped to the same vector $\\vec{w}\\in\\Rs{n}$.\n\n\\begin{example}{Two vectors mapped to the same vector}{}\n\tLet $T$ be a linear transformation represented by the matrix\n\t\\[\n\t\tA=\n\t\t\\begin{bmatrix}\n\t\t\t1 & 0 & 2\\\\\n\t\t\t0 & 1 & 0\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\\end{bmatrix}.\n\t\\]\n\t\n\tThe two vectors $\\vec{u}=\\colvec{2;0;0}$ and $\\vec{v}=\\colvec{0;0;1}$ are mapped by $T$ to the same vector:\n\t\\begin{align*}\n\t\tA\\vec{u} &= \\colvec{1\\cdot2+\\cancel{\\cancel{0\\cdot0}}+\\cancel{2\\cdot0};\\cancel{0\\cdot2}+\\cancel{1\\cdot0}+\\cancel{\\cancel{0\\cdot0}};\\cancel{0\\cdot2}+\\cancel{\\cancel{0\\cdot0}}+\\cancel{\\cancel{0\\cdot0}}} = \\colvec{2;0;0}.\\\\\n\t\tA\\vec{v} &= \\colvec{\\cancel{1\\cdot0}+\\cancel{0\\cdot0}+2\\cdot1;\\cancel{0\\cdot0}+\\cancel{1\\cdot0}+\\cancel{0\\cdot1};\\cancel{0\\cdot0}+\\cancel{0\\cdot0}+\\cancel{0\\cdot2}} = \\colvec{2;0;0}.\\\\\n\t\\end{align*}\n\\end{example}\n\nIn fact, when a linear transformation maps two vectors in its domain to a single vector in is image - it actually maps \\textbf{infinitely many} vectors to that point: let $T$ be a linear transformation and $\\vec{u},\\vec{v}$ two vectors in its domain that are mapped to the same output $\\vec{w}$, i.e.\n\\[\n\tT \\left( \\vec{u} \\right) = T \\left( \\vec{v} \\right) = \\vec{w}.\n\\]\n\nDue to the properties of linear transformations, on one side we get\n\\begin{align}\n\tT \\left( \\alpha\\vec{v}+\\beta\\vec{u} \\right) &= T \\left( \\alpha\\vec{u} \\right) + T \\left( \\beta\\vec{v} \\right)\\\\ \n\t\t\t\t\t\t\t\t\t\t\t\t&= \\alpha T \\left( \\vec{u} \\right)  + \\beta T\\left(\\vec{w}\\right)\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t&= \\alpha\\vec{w} + \\beta\\vec{w}\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t&= (\\alpha+\\beta)\\vec{w}.\n\\end{align}\n(for any $\\alpha\\in\\mathbb{R}$)\n\nThus, for example, the linear combination $2\\vec{u}+6\\vec{v}$ will be mapped to the same output as $6\\vec{u}+2\\vec{v},\\ 3\\vec{u}+9\\vec{v},\\ 0.5\\vec{u}+11.5\\vec{v}$, etc. - the linear combination using any two coefficients $\\alpha,\\beta$ which add up to $12$ would be mapped to $12\\vec{w}$. This is of course true for any real number, and so for each scale of $\\vec{w}$ there are infinitely many linear combinations that are mapped to it.\n\nIn fact, the only way in which a linear transformation can be non-bijective is by \"loosing\" a dimension, i.e. when it maps $\\Rs{3}$ to a single plane/line/point. As we saw earlier, these kind of transformations are represented by matrices for which the determinant is zero, i.e.\n\\begin{equation}\n\t|A|=0 \\Leftrightarrow \\nexists A^{-1}.\n\t\\label{eq:determinant_zero_no_inverse}\n\\end{equation}\nwhich in words mean that if (and only if!) the determinant of a matrix is zero then it has no iverse, and vice-versa (the symbol $\\nexists$ means \"does not exist\"). On the other hand, if the determinant isn't zero, then the inverse must exist.\n\nThe product of a matrix and its inverse is the respective identity matrix, since the composition of the respective linear transformations represented by the matrices is the identity transformation. In mathematic terms:\n\\begin{equation}\n\tAA^{-1} = A^{-1}A = I.\n\t\\label{eq:matrix_inverse_identity}\n\\end{equation}\n\n\\begin{example}{Inverse matrices}{}\n\tTBW: give a $3\\times3$ matrix, show that its determinant is non-zero, present its inverse and demonstrate it on a specific vector.\n\\end{example}\n\nMatrices with zero determinant are also known as a \\emph{singular} or \\emph{degenerate} matrix. For obvious reason, we will not use the latter term in this book\\footnote{nor should you use it in general, in my opinion.}.\n\nWhile the identity matrix is its own inverse (since $I\\cdot I=I$), it is not the only matrix which shows such behaviour. For example, consider the matrix\n\\[\n\tA =\n\t\\begin{bmatrix}\n\t\t-1 & 0 & 0\\\\\n\t\t 0 & 1 & 0\\\\\n\t\t 0 & 0 & 1\\\\\n\t\\end{bmatrix}.\n\\]\nGeometrically, $A$ takes a vector in $\\Rs{3}$ and flips its $x$-component. In other words it mirrors any vector across the $yz$-plane (see \\autoref{fig:mirror_yz}). If we take a vector $\\vec{u}=\\colvec{x;y;z}$ and multiply it by $A$ we get the vector $\\vec{v}=\\colvec{-x;y;z}$ (tip: calculate the product $A\\vec{v}$ directly for practice). If we take $\\vec{v}$ and multiply it by $A$, we get the vector $\\colvec{x;y;z}$ - i.e. we retrieved back $\\vec{u}$. Since this is true for any vector in $\\Rs{3}$, $A$ is its own inverse. We can check this directly by calculating the product of $A$ with itself:\n\\begin{align*}\n\tA\\cdot A &=\n\t\\begin{bmatrix}\n\t\t-1 & 0 & 0\\\\\n\t\t 0 & 1 & 0\\\\\n\t\t 0 & 0 & 1\\\\\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\t\t-1 & 0 & 0\\\\\n\t\t 0 & 1 & 0\\\\\n\t\t 0 & 0 & 1\\\\\n\t\\end{bmatrix}\\\\\n\t\t\t &=\n\t\\begin{bmatrix}\n\t\t-1\\cdot(-1) + \\cancel{\\cancel{0\\cdot0}}+\\cancel{\\cancel{0\\cdot0}} & -\\cancel{1\\cdot0}+\\cancel{0\\cdot1}+\\cancel{\\cancel{0\\cdot0}} & -\\cancel{1\\cdot0}+\\cancel{\\cancel{0\\cdot0}}+\\cancel{0\\cdot1}\\\\\n\t\t \\cancel{0\\cdot(-1)} + \\cancel{\\cancel{0\\cdot0}}+\\cancel{\\cancel{0\\cdot0}} &  \\cancel{0\\cdot1}+1\\cdot1+\\cancel{\\cancel{0\\cdot0}} &  \\cancel{\\cancel{0\\cdot0}}+\\cancel{0\\cdot1}+\\cancel{\\cancel{0\\cdot0}}\\\\\n\t\t \\cancel{0\\cdot(-1)} + \\cancel{\\cancel{0\\cdot0}}+\\cancel{0\\cdot1} &  \\cancel{\\cancel{0\\cdot0}}+\\cancel{0\\cdot1}+\\cancel{\\cancel{0\\cdot0}} &  \\cancel{\\cancel{0\\cdot0}}+\\cancel{\\cancel{0\\cdot0}}+1\\cdot1\\\\\n\t\\end{bmatrix}\\\\\n\t\t\t &=\n\t\\begin{bmatrix}\n\t\t1 & 0 & 0\\\\\n\t\t0 & 1 & 0\\\\\n\t\t0 & 0 & 1\\\\\n\t\\end{bmatrix}\\\\\n\t\t\t &= I_{3}.\n\\end{align*}\n\nA matrix which is its own inverse is known as an \\emph{involutory matrix}. Such matrices must be square (challange to the reader: why is that true?).\n\nHow do we calculate the inverse of a matrix? In general, non-square matrices don't have so-called \"complete\" inverses, so we focus on calculating the inverses of square matrices only. The general formula for an inverse matrix $A^{-1}$ is\n\\begin{equation}\n\tA^{-1} = \\frac{1}{|A|}\\adj(A),\n\t\\label{eq:inverse_matrix_calc}\n\\end{equation}\nwhere $\\adj(A)$ is the \\emph{adjugate} of the matrix $A$. The adjugate of a matrix is calculated using its minors, as follows: let \\[\n\tA=\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\\end{bNiceMatrix},\n\\]\nthen its adjugate is the matrix\n\\[\n\t\\adj(A)=\n\t\\begin{bNiceMatrix}\n\t\t+\\Mm{1}{1} & -\\Mm{1}{2} & \\cdots & \\pm\\Mm{1}{n}\\\\\n\t\t-\\Mm{2}{1} & +\\Mm{2}{2} & \\cdots & \\mp\\Mm{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\pm\\Mm{m}{1} & \\mp\\Mm{m}{2} & \\cdots & \\pm\\Mm{m}{n}\n\t\\end{bNiceMatrix}^{\\top}\n\\]\n(where $\\Mm{i}{j}$ is the $\\textcolor{xred}{i}\\textcolor{xblue}{j}$-minor of $A$).\n\n\\begin{example}{Adjugate of a matrix}{}\n\tLet\n\t\\[\n\t\tC=\n\t\t\\begin{bmatrix}\n\t\t\t1 & 7 & -3\\\\\n\t\t\t2 & 5 &  0\\\\\n\t\t\t0 & 1 &  1\\\\\n\t\t\\end{bmatrix},\n\t\\]\n\tthen\n\t\\begin{align*}\n\t\t\\adj(C)&=\n\t\t\\begin{bmatrix}\n\t\t\t+\\Mm{1}{1} & -\\Mm{1}{2} & +\\Mm{1}{3}\\\\\n\t\t\t-\\Mm{2}{1} & +\\Mm{2}{2} & -\\Mm{2}{3}\\\\\n\t\t\t+\\Mm{3}{1} & -\\Mm{3}{2} & +\\Mm{3}{3}\\\\\n\t\t\\end{bmatrix}^{\\top}\\\\\n\t\t\t   &=\n\t\t\t   \\begin{bmatrix}\n\t\t\t\t   +\\begin{vmatrix}5&0\\\\1&1\\end{vmatrix} & -\\begin{vmatrix}2&0\\\\0&1\\end{vmatrix} & +\\begin{vmatrix}2&5\\\\0&1\\end{vmatrix}\\\\\n\t\t\t\t   -\\begin{vmatrix}7&-3\\\\1&1\\end{vmatrix} & +\\begin{vmatrix}1&-3\\\\0&1\\end{vmatrix} & -\\begin{vmatrix}1&7\\\\0&1\\end{vmatrix}\\\\\n\t\t\t\t   +\\begin{vmatrix}7&-3\\\\5&0\\end{vmatrix} & -\\begin{vmatrix}1&-3\\\\2&0\\end{vmatrix} & +\\begin{vmatrix}1&7\\\\2&5\\end{vmatrix}\\\\\n\t\t\t   \\end{bmatrix}^{\\top}\\\\\n\t\t\t   &=\n\t\t\t   \\begin{bmatrix}\n\t\t\t\t   5\\cdot1-\\cancel{1\\cdot0} & -2\\cdot1+\\cancel{\\cancel{0\\cdot0}} & 2\\cdot1-\\cancel{0\\cdot5}\\\\\n\t\t\t\t   -(7\\cdot1+1\\cdot3) & 1\\cdot1+\\cancel{3\\cdot0} & -(1\\cdot1-\\cancel{7\\cdot0})\\\\\n\t\t\t\t   \\cancel{7\\cdot0}+3\\cdot5 & -(\\cancel{1\\cdot0}+3\\cdot2) & 1\\cdot5-2\\cdot7\\\\\n\t\t\t   \\end{bmatrix}^{\\top}\\\\\n\t\t\t   &=\n\t\t\t   \\begin{bmatrix}\n\t\t\t\t   5 & -2 & 2\\\\\n\t\t\t\t   -10 & 1 & -1\\\\\n\t\t\t\t   15 & -6 & -9\\\\\n\t\t\t   \\end{bmatrix}^{\\top}\\\\ \n\t\t\t   &=\n\t\t\t   \\begin{bmatrix}\n\t\t\t\t   5 & -10 & 15\\\\\n\t\t\t\t   -2 & 1 & -6\\\\\n\t\t\t\t   2 & -1 & -9\n\t\t\t   \\end{bmatrix}.\n\t\\end{align*}\n\\end{example}\n\nWe can use the above example to calculate the inverse of the matrix $C$.\n\n\\begin{example}{Inverse of a matrix}{}\n\tThe determinant of $C$ is\n\t\\[\n\t\t|C| = \\Mm{1}{1} -7\\Mm{1}{2} -3\\Mm{1}{3} = 5-14-6 = -15.\n\t\\]\n\tTherefore the inverse of $C$ is\n\t\\begin{align*}\n\t\tC^{-1} &= \\frac{1}{|C|}\\adj(C)\\\\\n\t\t\t   &= -\\frac{1}{15}\n\t\t\t   \\begin{bmatrix}\n\t\t\t\t   5 & -10 & 15\\\\\n\t\t\t\t   -2 & 1 & -6\\\\\n\t\t\t\t   2 & -1 & -9\n\t\t\t   \\end{bmatrix}\\\\\n\t\t\t   &=\n\t\t\t   \\begin{bmatrix}\n\t\t\t\t   -\\frac{1}{3} & -\\frac{2}{3} & -1\\\\\n\t\t\t\t   \\frac{2}{15} & -\\frac{1}{15} & \\frac{6}{15}\\\\\n\t\t\t\t   -\\frac{2}{15} & \\frac{1}{15} & \\frac{3}{5}\\\\\n\t\t\t   \\end{bmatrix}.\n\t\\end{align*}\n\\end{example}\n\nIn the case of $2\\times2$ matrices, the adjugate has a rather simple formula:\n\\begin{equation}\n\t\\adj\\left( \\begin{bmatrix}a&b\\\\c&d\\end{bmatrix}  \\right) = \\begin{bmatrix} d&-b\\\\-c&a \\end{bmatrix}.\n\t\\label{eq:adjugate_2x2}\n\\end{equation}\n\n\\begin{note}{Minors of $\\bm{2\\times2}$ matrices}{}\n\tThe minors of a $2\\times2$ matrix $A=\\begin{bmatrix}a&b\\\\c&d\\end{bmatrix}$ are simply\n\t\\begin{align*}\n\t\t\\Mm{1}{1} &= d,\\ \\Mm{1}{2} = c,\\\\\n\t\t\\Mm{2}{1} &= b,\\ \\Mm{2}{2} = a.\n\t\\end{align*}\n\\end{note}\n\nTherefore, the inverse of a $2\\times2$ matrix $A=\\begin{bmatrix}a&b\\\\c&d\\end{bmatrix}$ is\n\\begin{equation}\n\tA^{-1} = \\frac{1}{|A|}\\begin{bmatrix}d&-b\\\\-c&a\\end{bmatrix} = \\frac{1}{ad-cb}\\begin{bmatrix}d&-b\\\\-c&a\\end{bmatrix}.\n\t\\label{eq:inverse_2x2}\n\\end{equation}\n\nWe can check that \\autoref{eq:inverse_2x2} is correct by directly calculating the products $AA^{-1}$ and $A^{-1}A$:\n\\begin{align*}\n\tAA^{-1} &= \\frac{1}{|A|}\\begin{bmatrix}a&b\\\\c&d\\end{bmatrix}\\begin{bmatrix}d&-b\\\\-c&a\\end{bmatrix}\\\\\n\t\t\t&= \\frac{1}{ad-cb}\\begin{bmatrix} ad-bc & \\cancel{-ab+ba} \\\\ \\cancel{cd-dc} & -cb+da \\end{bmatrix}\\\\\n\t\t\t&= \\begin{bmatrix}\\frac{ad-bc}{ad-cb} & 0 \\\\ 0 & \\frac{da-cb}{ad-bc}\\end{bmatrix}\\\\\n\t\t\t&= \\begin{bmatrix} 1&0 \\\\ 0&1 \\end{bmatrix}\\\\\n\t\t\t&= I_{2}.\\\\\n\t\t\t\\\\\n\tA^{-1}A &= \\frac{1}{|A|}\\begin{bmatrix}d&-b\\\\-c&a\\end{bmatrix}\\begin{bmatrix}a&b\\\\c&d\\end{bmatrix}\\\\\n\t\t\t&= \\frac{1}{ad-cb}\\begin{bmatrix} da-bc & \\cancel{db-bd} \\\\ \\cancel{-ca+ac} & -cb+ad \\end{bmatrix}\\\\\n\t\t\t&= \\begin{bmatrix} \\frac{da-bc}{ad-cb} & 0 \\\\ 0 & \\frac{ad-cb}{ad-cb} \\end{bmatrix}\\\\\n\t\t\t&= \\begin{bmatrix} 1&0 \\\\ 0&1 \\end{bmatrix}\\\\\n\t\t\t&= I_{2}.\n\\end{align*}\n\n\\begin{example}{Inverting a $\\bm{2\\times2}$ matrix}{}\n\tThe inverse of the matrix\n\t\\[\n\t\tA = \\begin{bmatrix}1&-3 \\\\ 2&0\\end{bmatrix}\n\t\\]\n\tis\n\t\\begin{align*}\n\t\tA^{-1} &= \\frac{1}{|A|}\\begin{bmatrix}0&3 \\\\ -2&1\\end{bmatrix}\\\\\n\t\t\t   &= \\frac{1}{1\\cdot0-(-3)\\cdot2} \\begin{bmatrix}0&3 \\\\ -2&1\\end{bmatrix}\\\\\n\t\t\t   &= \\frac{1}{6}\\begin{bmatrix}0&3 \\\\ -2&1\\end{bmatrix}.\n\t\\end{align*}\n\\end{example}\n\n\\begin{example}{Inverse of the $2$-dimensional rotation matrix}{}\n\tWe can use \\autoref{eq:inverse_2x2} to calculate the inverse of the $2$-dimensional rotation matrix\n\t\\[\n\t\tR \\left( \\theta \\right) = \\begin{bmatrix} \\cos(\\theta) & -\\sin(\\theta) \\\\ \\sin(\\theta) & \\cos(\\theta) \\end{bmatrix}.\n\t\\]\n\tSince the rotation matrix rotates all vector by $\\theta$ counter-clockwise around the origin, we expect its inverse to rotate all vectors by $-\\theta$ counter-clockwise around the origin. Let's show that this is indeed the case: we first calculate the determinant of $R$:\n\t\\[\n\t\t|R| = \\cos(\\theta)\\cdot\\cos(\\theta) + \\sin(\\theta)\\sin(\\theta) = \\cos(\\theta)^{2}+\\sin(\\theta)^{2} = 1.\n\t\\]\n\tThis result makes sense - rotation does not change areas. We can now use $|R|$ to calculate $R^{-1}$:\n\t\\begin{align*}\n\t\tR^{-1} \\left( \\theta \\right) &= \\frac{1}{|R|}\\begin{bmatrix} \\cos(\\theta) & \\sin(\\theta) \\\\ -\\sin(\\theta) & \\cos(\\theta)  \\end{bmatrix}\\\\\n\t\t\t\t\t\t\t\t\t &= \\begin{bmatrix} \\cos(\\theta) & \\sin(\\theta) \\\\ -\\sin(\\theta) & \\cos(\\theta)  \\end{bmatrix}. \n\t\\end{align*}\n\tSince $\\cos(-\\theta)=\\cos(\\theta)$ and $\\sin(-\\theta)=-\\sin(\\theta)$, the above matrix is exactly a rotation by $-\\theta$ counter-clockwise around the origin, as we expected.\n\\end{example}\n\nWe can use the rotation matrix and its inverse to calculate the general $2\\times2$ reflection matrix around a line going through the origin (\\autoref{eq:reflect_general_2x2}), represented by its angel $\\theta$. We do this by taking the following steps (see \\autoref{fig:building_reflect_2x2} for a graphical illustration):\n\\begin{enumerate}\n\t\\item Rotate space by $-\\theta$ such that the reflection line aligns with the horizontal axis.\n\t\\item Reflect space across the horizontal line.\n\t\\item Rotate space by $\\theta$ to bring back space to its original orientation.\n\\end{enumerate}\n\nThe order of application of the above transformations is 1-2-3. Therefore, in matrix form we write them from \\textbf{left to right}, i.e. $\\bm{3}\\cdot\\bm{2}\\cdot\\bm{1}$:\n\n\\vspace{1em}\n\\centering\n\\tikz[node distance=2.75cm]{\n\t\\node (RefD) {$\\Refl(\\theta)$};\n\t\\node[right of=RefD, xshift=-2cm] (eq1) {$=$};\n\t\\node[fill=xgreen!20, right of=eq1] (rot2) {$\\begin{bmatrix} \\cos(\\theta)&-\\sin(\\theta) \\\\ \\sin(\\theta)&\\cos(\\theta) \\end{bmatrix}$};\n\t\\node[fill=xblue!20, right of=rot2] (ref) {$\\begin{bmatrix} 1&0 \\\\ 0&-1 \\end{bmatrix}$};\n\t\\node[fill=xred!20, right of=ref] (rot1) {$\\begin{bmatrix} \\cos(\\theta)&\\sin(\\theta) \\\\ -\\sin(\\theta)&\\cos(\\theta) \\end{bmatrix}$};\n\t\n\t\\node at ($(rot2.east)!0.5!(ref.west)$) {$\\cdot$};\n\t\\node at ($(ref.east)!0.5!(rot1.west)$) {$\\cdot$};\n\n\t\\tikzset{node distance=1.5cm}\n\t\\node[fill=xgreen!20, above of=rot2] (rot2txt) {3. rotate back};\n\t\\node[fill=xblue!20, above of=ref] (reftxt) {2. flip vertically};\n\t\\node[fill=xred!20, above of=rot1] (rot1txt) {1. rotate};\n\n\t\\draw[vector, xgreen!20] (rot2txt) -- (rot2);\n\t\\draw[vector, xblue!20] (reftxt) -- (ref);\n\t\\draw[vector, xred!20] (rot1txt) -- (rot1);\n\n\t\\tikzset{node distance=2.75cm}\n\t\\node[below of=eq1, yshift=1cm] (eq2) {$=$};\n\t\\node[right of=eq2, xshift=3mm] {$\\begin{bmatrix} \\cos \\left( 2\\theta \\right) & \\sin \\left( 2\\theta \\right) \\\\ -\\sin \\left( 2\\theta \\right) & \\cos \\left( 2\\theta \\right) \\end{bmatrix}.$};\n}\n\\flushleft\n\n\\renewcommand\\thesubfigure{\\arabic{subfigure}}\n\\setcounter{subfigure}{-1} % <-- why doesn't this work? :(\n\\begin{figure}[]\n\t\\centering\n\t\\begin{subfigure}[c]{0.45\\textwidth}\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\tvector plane,\n\t\t\t\twidth=6cm, height=6cm,\n\t\t\t\txlabel={},\n\t\t\t\tylabel={},\n\t\t\t\txticklabels={,},\n\t\t\t\tyticklabels={,},\n\t\t\t\taxis line style={draw=none},\n\t\t\t\ttick style={draw=none},\n\t\t\t\tgrid=none,\n\t\t\t]\n\t\t\t\\node at (0,0) {\\includesvg[scale=0.75]{figures/linear_algebra/tapir_transform2}};\n\t\t\t\\addplot[thick, dashed] {0.5*\\x};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{Original space.}\n\t\\end{subfigure}\n\t\\begin{subfigure}[c]{0.45\\textwidth}\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\tvector plane,\n\t\t\t\twidth=6cm, height=6cm,\n\t\t\t\txlabel={},\n\t\t\t\tylabel={},\n\t\t\t\txticklabels={,},\n\t\t\t\tyticklabels={,},\n\t\t\t\taxis line style={draw=none},\n\t\t\t\ttick style={draw=none},\n\t\t\t\tgrid=none,\n\t\t\t]\n\t\t\t\\pgftransformcm{0.8945}{-0.4472}{0.4472}{0.8945}{\\pgfpoint{0}{0}}\n\t\t\t\\node at (0,0) {\\includesvg[scale=0.75]{figures/linear_algebra/tapir_transform2}};\n\t\t\t\\addplot[thick, dashed] {0.5*\\x};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{Rotation by $\\theta$ such that the mirror line is aligned with the horizontal axis.}\n\t\\end{subfigure}\n\t\\hfill\n\t\\begin{subfigure}[c]{0.45\\textwidth}\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\tvector plane,\n\t\t\t\twidth=6cm, height=6cm,\n\t\t\t\txlabel={},\n\t\t\t\tylabel={},\n\t\t\t\txticklabels={,},\n\t\t\t\tyticklabels={,},\n\t\t\t\taxis line style={draw=none},\n\t\t\t\ttick style={draw=none},\n\t\t\t\tgrid=none,\n\t\t\t]\n\t\t\t\\pgftransformcm{1}{0}{0}{-1}{\\pgfpoint{0}{0}}\n\t\t\t\\pgftransformcm{0.8945}{-0.4472}{0.4472}{0.8945}{\\pgfpoint{0}{0}}\n\t\t\t\\node at (0,0) {\\includesvg[scale=0.75]{figures/linear_algebra/tapir_transform2}};\n\t\t\t\\addplot[thick, dashed] {0.5*\\x};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{Mirroring across the mirror line.}\n\t\\end{subfigure}\n\t\\begin{subfigure}[c]{0.45\\textwidth}\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\tvector plane,\n\t\t\t\twidth=6cm, height=6cm,\n\t\t\t\txlabel={},\n\t\t\t\tylabel={},\n\t\t\t\txticklabels={,},\n\t\t\t\tyticklabels={,},\n\t\t\t\taxis line style={draw=none},\n\t\t\t\ttick style={draw=none},\n\t\t\t\tgrid=none,\n\t\t\t]\n\t\t\t\\pgftransformcm{0.8945}{0.4472}{-0.4472}{0.8945}{\\pgfpoint{0}{0}}\n\t\t\t\\pgftransformcm{1}{0}{0}{-1}{\\pgfpoint{0}{0}}\n\t\t\t\\pgftransformcm{0.8945}{-0.4472}{0.4472}{0.8945}{\\pgfpoint{0}{0}}\n\t\t\t\\node at (0,0) {\\includesvg[scale=0.75]{figures/linear_algebra/tapir_transform2}};\n\t\t\t\\addplot[thick, dashed] {0.5*\\x};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{Rotating back to the original orientation (i.e. by $-\\theta$).}\n\t\\end{subfigure}\n\t\\caption{Constructing a general $2\\times2$ reflection matrix as the composition of rotating, mirroring and rotating back.}\n\t\\label{fig:building_reflect_2x2}\n\\end{figure}\n\n\\subsection{Kernel and null space}\nWhile the determinant of a matrix tells us whether the matrix is reversible or not, it doesn't quantify the loss in dimensionality resulting from applying it: a matrix which \"squishes\" $\\Rs{3}$ in to a plane has the same determinant as a matrix which \"squishes\" it into a line or the the a single point (the origin): $0$. To find a measurement that does quantify this characteristic, we can look at the set of all vectors which the matrix (and thus the transformation it represents) map to $\\vec{0}$. We call this set the \\emph{kernel} of the matrix/transformation (denoted $\\ker(A)$ or $\\ker(T)$, respectively). More formally - given an $m\\times n$ matrix representing a transformation $T:\\Rs{n}\\to\\Rs{m}$,\n\\begin{equation}\n\t\\ker(A) = \\left\\{ \\vec{v}\\in\\Rs{n} \\mid A\\vec{v}=\\vec{0}_{m} \\right\\},\n\t\\label{eq:kernel_matrix}\n\\end{equation}\nand equivalently,\n\\begin{equation}\n\t\\ker(T) = \\left\\{ \\vec{v}\\in\\Rs{n} \\mid T \\left( \\vec{v} \\right) =\\vec{0}_{m} \\right\\}\n\t\\label{eq:kernel_transformation}\n\\end{equation}\n\nIn the language of matrices, the kernel is sometimes refered to as their \\emph{null space}.\n\n\\begin{note}{Matrix/Transformation duality}{}\n\tFrom now on in this subsection we will discuss matrices only, however everything discussed here can be applied directly to the transformations they represent. We also use the term kernel instead of null space, as these two concepts are practially equivalent in our context.\n\\end{note}\n\n\\begin{example}{Kernel of a matrix}{}\n\tThe vector\n\t\\[\n\t\t\\vec{v}=\\colvec{0;-2;1}\n\t\\]\n\tis in the kernel of the matrix\n\t\\[\n\t\tA=\n\t\t\\begin{bmatrix}\n\t\t\t 0 & 1 & 2\\\\\n\t\t\t-1 & 3 & 6\\\\\n\t\t\t 2 & 2 & 4\\\\\n\t\t\\end{bmatrix},\n\t\\]\n\tsince\n\t\\begin{align*}\n\t\tA\\vec{v} &= \n\t\t\\begin{bmatrix}\n\t\t\t 0 & 1 & 2\\\\\n\t\t\t-1 & 3 & 6\\\\\n\t\t\t 2 & 2 & 4\\\\\n\t\t \\end{bmatrix}\\colvec{0;-2;1}\\\\\n\t\t\t\t &= \\colvec{0\\cdot0+1\\cdot(-2)+2\\cdot1;-1\\cdot0+3\\cdot(-2)+6\\cdot1;2\\cdot0+2\\cdot(-2)+4\\cdot1}\\\\\n\t\t\t\t &= \\colvec{0-2+2;0-6+6;0-2+4}\\\\\n\t\t\t\t &= \\colvec{0;0;0}.\n\t\\end{align*}\n\\end{example}\n\nTwo properties of the kernel of a matrix are relatively straight-forward:\n\\begin{itemize}\n\t\\item The (dimentially correct) zero vector is always in the kernel of any matrix. This is because the zero vector of a transformation's domain is always mapped to the zero vector in its image (stated in \\autoref{sec:intuitive_linear_trans} as the fact that linear transformations preserve the origin).\n\t\\item Any linear combination of vectors in the kernel of a matrix is also in the kernel of the matrix. This is easily proved using the basic properties of linear transformations (which we show in matrix form):\n\\begin{proof}{Linear combinations of kernel vectors}{}\n\tLet $A$ be a matrix, and $\\vec{u},\\vec{v}$ two vectors in its kernel. Then\n\t\\begin{align*}\n\t\tA\\cdot \\left( \\alpha\\vec{u}+\\beta\\vec{v} \\right) &= A\\cdot \\left( \\alpha\\vec{u} \\right) + A\\cdot \\left( \\beta\\vec{v} \\right)\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t &= \\alpha A\\vec{u} + \\beta A\\vec{v}\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t &= \\alpha\\vec{0} + \\beta\\vec{0}\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t &= \\vec{0} + \\vec{0}\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t &= \\vec{0}.\n\t\\end{align*}\n\tTherefore $\\vec{w}=\\alpha\\vec{u}+\\beta\\vec{v}$ is also in the kernel of $A$.\n\\end{proof}\n\\end{itemize}\n\nThe kernel of a matrix forms a subspace of its domain (see \\autoref{fig:kernel_subspace}). Therefore, we can quantify the dimension of the kernel, sometimes called its \\emph{nullity}:\n\\begin{equation}\n\t\\Null(A) = \\dim(\\ker(A)).\n\t\\label{eq:nullity}\n\\end{equation}\n\n\\begin{example}{Kernel space of a matrix}{}\n\tThe matrix\n\t\\[\n\t\tA=\n\t\t\\begin{bmatrix}\n\t\t\t0 &  1 & 2\\\\\n\t\t\t0 &  2 & 4\\\\\n\t\t\t0 & -3 & -6\\\\\n\t\t\\end{bmatrix} \n\t\\]\n\thas the following two vectors in its kernel:\n\t\\[\n\t\t\\vec{u}=\\colvec{1;0;0},\\ \\vec{v}=\\colvec{0;-2;1}.\n\t\\]\n\tThese two vectors are linearly independant, and span the kernel of $A$, having dimension $\\dim(V)=2$. All the vectors in $\\ker(A)$ are of the form\n\t\\[\n\t\t\\vec{w} = \\alpha\\vec{u} + \\beta\\vec{v},\n\t\\]\n\ti.e. the linear combinations of $\\vec{u}$ and $\\vec{v}$.\n\\end{example}\n\nAll the vectors which are not in $\\ker(A)$ also span a subspace of its domain, called the \\emph{column space} of $A$. The dimension of the column space is called the \\emph{rank} of $A$, $\\rank(A)$. The kernel and column space of a matrix are complementary: together they span $\\Rs{n}$.\n\nThis means that we can split the domain of a matrix to two separate subspaces, which together give us a lot of information about the image of the matrix: in one subspace are all the vectors that will be \"squished\" by the transformation into the origin, and the other subspace is composed of all the vectors that are transformed to a non-zero vector. If we limit the domain of the transformation to its column space, it becomes reversible - no two vectors in the column space are mapped to a single vector. On the other hand, the transformation on the kernel is always inversible.\n\nAlltogether, the nullity and rank of a matrix add up to the dimension of its domain, i.e.\n\\begin{equation}\n\t\\Null(A) + \\rank(A) = n.\n\t\\label{eq:}\n\\end{equation}\n\n\\begin{figure}[]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\node[ellipse, draw=black, thick, fill=xred!50, minimum width=2cm, minimum height=4cm, label={[label distance=-1cm]90:$\\Rs{n}$}] (domain) {};\n\t\t\\node[circle, draw=black, thick, fill=xblue!50, minimum size=1cm] (kernel) {$\\ker(A)$};\n\n\t\t\\node[ellipse, draw=black, thick, fill=xgreen!50, minimum width=2cm, minimum height=3cm, label={[label distance=-1cm]90:$\\Rs{m}$}] (image) at (4cm,0) {};\n\t\t\\node[circle, fill=black] (zero) at (4cm,0) {};\n\t\t\\node[right=of zero, xshift=-1cm] {$\\vec{0}$};\n\n\t\t\\draw[thick, densely dotted] (domain.north) -- (image.north);\n\t\t\\draw[thick, densely dotted] (domain.south) -- (image.south);\n\t\t\\draw[thick, densely dotted] (kernel.north) -- (zero.north);\n\t\t\\draw[thick, densely dotted] (kernel.south) -- (zero.south);\n\n\t\t\\draw[vector] (1,2.3) -- node [midway, above] {$A$} ++(2,0);\n\t\\end{tikzpicture}\n\t\\caption{The kernel of a matrix $A$ is a subspace of its domain $\\Rs{n}$. It is mapped exclusively to $\\vec{0}_{m}$ in its image. The set $\\Rs{n}\\setminus\\ker(A)$, i.e. $\\Rs{n}$ minus the kernel (shown in red), is in fact the column space of the matrix.}\n\t\\label{fig:kernel_subspace}\n\\end{figure}\n\nTBD: figure to illustrate the kernel and column space of a matrix as complementary.\n\nIf the rank of an $m\\times n$ matrix $A$ is equal to $n$, its kernel space must have the dimension\n\\[\n\t\\Null(A) = n-\\rank(A) = n-n = 0,\n\\]\ni.e. the matrix has no vectors mapped to $\\vec{0}$ (except the zero vector itself), and thus the matrix is invertible (non-singular), and so its determinant is non-zero. This is true in the other direction: a matrix with non-zero determinant is invertible, and thus its kernel contains only $\\vec{0}$ and the nullity of the matrix is $0$. This means that the column space of the matrix must equal $n$. Alltogether, these facts can be written succinctly as\n\\begin{equation}\n\t\\rank(A) = n \\Leftrightarrow |A|\\neq0.\n\t\\label{eq:rank_det}\n\\end{equation}\n\n%TBW: how matrix-matrix product changes the right-side matrix (i.e. exchanging rows/columns, scaling, etc.).\n", "meta": {"hexsha": "4316e7e90d95a8827c35dd66be4f589a71bc9616", "size": 98816, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/linear_algebra_intuitive/matrices.tex", "max_stars_repo_name": "pelegs/maths_book", "max_stars_repo_head_hexsha": "d1bebf3516a5821772d8807ce3d222a3caff1360", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-25T20:02:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T17:57:59.000Z", "max_issues_repo_path": "chapters/linear_algebra_intuitive/matrices.tex", "max_issues_repo_name": "pelegs/maths_book", "max_issues_repo_head_hexsha": "d1bebf3516a5821772d8807ce3d222a3caff1360", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2022-01-17T05:01:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-20T06:18:24.000Z", "max_forks_repo_path": "chapters/linear_algebra_intuitive/matrices.tex", "max_forks_repo_name": "pelegs/maths_book", "max_forks_repo_head_hexsha": "d1bebf3516a5821772d8807ce3d222a3caff1360", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2022-01-17T10:15:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-02T10:45:13.000Z", "avg_line_length": 49.8064516129, "max_line_length": 727, "alphanum_fraction": 0.6414953044, "num_tokens": 38490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.918480237330998, "lm_q1q2_score": 0.8403184420139628}}
{"text": "\n\\subsection{Hydrogen wavefunctions}\nHydrogen wavefunctions $\\psi$ are solutions to the differential equation\n$${\\psi\\over n^2}=\\nabla^2\\psi+{2\\psi\\over r}$$\nwhere $n$ is an integer representing the quantization of total energy and\n$r$ is the radial distance of the electron.\nThe Laplacian operator in spherical coordinates is\n\n$$\\nabla^2={1\\over r^2}{\\partial\\over\\partial r}\n\\left(r^2{\\partial\\over\\partial r}\\right)\n+{1\\over r^2\\sin\\theta}{\\partial\\over\\partial\\theta}\n\\left(\\sin\\theta{\\partial\\over\\partial\\theta}\\right)\n+{1\\over r^2\\sin^2\\theta}{\\partial^2\\over\\partial\\phi^2}$$\n\nThe general form of $\\psi$ is\n\n$$\\psi=r^le^{-r/n}L_{n-l-1}^{2l+1}(2r/n)\nP_l^{|m|}(\\cos\\theta)e^{im\\phi}$$\n\nwhere $L$ is a Laguerre polynomial, $P$ is a Legendre polynomial and\n$l$ and $m$ are integers such that\n\n$$1\\le l\\le n-1,\\qquad -l\\le m\\le l$$\n\nThe general form can be expressed as the product of a radial\nwavefunction $R$ and a spherical harmonic $Y$.\n\n$$\\psi=RY,\\qquad R=r^le^{-r/n}L_{n-l-1}^{2l+1}(2r/n),\\qquad\nY=P_l^{|m|}(\\cos\\theta)e^{im\\phi}$$\n\nThe following script checks $E=K+V$ for $n,l,m=7,3,1$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nlaplacian(f) = 1/r^2*d(r^2*d(f,r),r)+\n  1/(r^2*sin(theta))*d(sin(theta)*d(f,theta),theta)+\n  1/(r*sin(theta))^2*d(f,phi,phi)\nn = 7\nl = 3\nm = 1\nR = r^l*exp(-r/n)*laguerre(2*r/n,n-l-1,2*l+1)\nY = legendre(cos(theta),l,abs(m))*exp(i*m*phi)\npsi = R*Y\nE = psi/n^2\nK = laplacian(psi)\nV = 2*psi/r\nsimplify(E-K-V)\n\\end{Verbatim}\n\nThis is the result when the script runs.\n\n$\\displaystyle 0$\n", "meta": {"hexsha": "4782bd7a59fd497a42ea9778727a2cb04549fd18", "size": 1534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/hydrogen-wavefunctions.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/hydrogen-wavefunctions.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/hydrogen-wavefunctions.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5, "max_line_length": 73, "alphanum_fraction": 0.6727509778, "num_tokens": 606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.973240712157665, "lm_q2_score": 0.8633916152464016, "lm_q1q2_score": 0.8402878704933646}}
{"text": "\n\\subsection{Maclaurin series}\n\nA Taylor series around \\(c=0\\).\n\n\\(f(x)=\\sum_{i=0}^\\infty (x-c)^i \\dfrac{f^i(c)}{i!}\\)\n\n\\(f(x)=\\sum_{i=0}^\\infty (x)^i \\dfrac{f^i(0)}{i!}\\)\n\nFor example, for:\t   \n\n\\(f(x)=(1-x)^{-1}\\)\n\n\\(f^i(0)=i!\\)\n\nSo, around \\(x=0\\):\n\n\\(f(x)=\\sum_{i=0}^\\infty (x)^i\\)\n\n", "meta": {"hexsha": "b56d419f97f5eabc79f4f94f7b0a704e9b2c5241", "size": 287, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/transformations/02-03-maclaurin.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/transformations/02-03-maclaurin.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/transformations/02-03-maclaurin.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.35, "max_line_length": 53, "alphanum_fraction": 0.4947735192, "num_tokens": 143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109784205502, "lm_q2_score": 0.8840392893839086, "lm_q1q2_score": 0.8402006459855685}}
{"text": "\n\\subsection{Cayley's theorem}\n\nCayley's theorem states that every group \\(G\\) is isomorphic to a subgroup of the symmetric group acting on \\(G\\).\n\nMultiplication by a member of \\(G\\) is a bijective function, as for each \\(g\\) there is also a \\(g^{-1}\\).\n\nThis means that multiplication of each member of \\(G\\) is a permutation, and so is a subset of the symmetric group on \\(G\\).\n\n", "meta": {"hexsha": "6d65eda61e56bb365cc99e407c0817622aca32db", "size": 382, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/06-01-cayley.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/groups/06-01-cayley.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/groups/06-01-cayley.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2, "max_line_length": 124, "alphanum_fraction": 0.7120418848, "num_tokens": 98, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542840900508, "lm_q2_score": 0.8757869948899665, "lm_q1q2_score": 0.8400148480990628}}
{"text": "\n\\subsection{Basis vectors}\n\n\\subsubsection{Basis}\n\nWe can write vectors as combinations of other vectors.\n\n\\(v=\\sum_i \\alpha_i v_i\\)\n\nA subset which spans the vector space, and which is also linearly independent, is a basis of the vector space.\n\nFor an arbitrary vector of size \\(n\\), we cannot use less than \\(n\\) elementary vectors. We could use more, but these would be redundant.\n\nIf we use \\(n\\) elementary vectors, there is a unique solution of weights of elementary vectors.\n\nIf we use more than \\(n\\) elementary vectors, there will be linear dependence, and so there will not be a unique solution.\n\n", "meta": {"hexsha": "8506515ec8a2741518b15db04d2e11c7ce8fa488", "size": 608, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/linearAlgebra/01-04-linearCombinations.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/linearAlgebra/01-04-linearCombinations.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/linearAlgebra/01-04-linearCombinations.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7777777778, "max_line_length": 137, "alphanum_fraction": 0.7565789474, "num_tokens": 140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9518632329799586, "lm_q2_score": 0.8824278587245935, "lm_q1q2_score": 0.8399506344771737}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath,amssymb}\n\\newcommand\\setdef[2]{\\left\\{\\left.{#1}\\,\\right|\\,{#2}\\right\\}}\n\\newcommand\\card[1]{\\left|#1\\right|}\n\\begin{document}\n\n\\section[Probability space]{Probability space $(\\Omega, \\mathcal A, \\mathbb P)$}\n\\begin{description}\n  \\item[$\\Omega$] is the set of outcomes ($n$-tuples, 1 of 365 days for $n$ people)\n    \\[ \\Omega = \\left\\{(d_1, d_2, \\dots, d_n): 1 \\leq d_i \\leq 365 \\: \\forall i \\in \\{1, \\dots, n\\}\\right\\} \\]\n  \\item[$\\mathcal A$] is the set of events (power set of $\\Omega$)\n    \\[ \\mathcal A = \\mathcal P(\\Omega) \\]\n    \\begin{align*}\n      \\{\\} &\\in \\mathcal A \\\\\n      \\Omega &\\in \\mathcal A \\\\\n      \\{(d_1, d_2, \\dots, d_n): d_i = d_j \\text{ for any } i \\neq j\\} &\\in \\mathcal A \\\\\n      \\{(d_1, d_2, \\dots, d_n): d_i \\neq d_j \\forall i \\neq j\\} &\\in \\mathcal A\n    \\end{align*}\n  \\item[$\\mathbb P$] is the probability measure for given $A \\in \\mathcal A$\n    \\[ \\mathbb P(\\{\\}) = 0 \\]\n    \\[ \\mathbb P(\\Omega) = 1 \\]\n    \\[ \\mathbb P(\\{(d_1, d_2, \\dots, d_n): d_i \\neq d_j \\forall i \\neq j\\}) = \\frac{n! \\cdot {365 \\choose n}}{365^n} \\]\n    \\[ \\mathbb P(\\{(d_1, d_2, \\dots, d_n): d_i = d_j \\text{ for any } i \\neq j\\}) = 1 - \\frac{n! \\cdot {365 \\choose n}}{365^n} \\]\n    where ${365 \\choose n}$ is the number of possibilities to assign $n$ people to 365 dates without collision. Once you have chosen $n$ slots, there are $n!$ ways to permute the specific assignment for person $1$ to $n$. As usual we divide the number of desired outcomes by the number of possible outcomes. The possible outcomes are left. We have $365^n$ ways to assign one of $365$ days to $n$ people.\n\\end{description}\n\n\\subsection{Whiteboard solution for (a)}\n\\[ \\mathbb P((x_1, \\dots, x_n)) = 365^n \\]\n\\[ \\mathbb P(X \\geq 2) = 1 - \\mathbb P(X = 1) \\]\nEvent $A = \\setdef{(x_1, \\dots, x_n) \\in \\Omega}{\\text{at least two $x_i$ are equal}}$.\n\\[ A^C = \\setdef{(x_1, \\dots, x_n) \\in \\Omega}{x_i \\neq x_j, j \\neq i} \\]\n\\[ \\mathbb P(A^C) = \\frac{\\card{A^C}}{\\card{\\Omega}} = \\frac{365 \\cdot 364 \\cdot \\dots \\cdot (365-n+1)}{365^n} \\]\n\n\\section{Find $n$ such that $\\mathbb P(A) > 0.5$ with $|A| = 1$}\n\nUsing R:\n\n\\begin{verbatim}\n# via https://stackoverflow.com/a/40527881\nramanujan <- function(n){\n  n*log(n) - n + log(n*(1 + 4*n*(1+2*n)))/6 + log(pi)/2\n}\nbignchoosek <- function(n,k){\n  exp(ramanujan(n) - ramanujan(k) - ramanujan(n-k))\n}\nf <- function (n) { 1 - factorial(n) * bignchoosek(365, n)/365^n }\nf(5)\n# [1] 0.02713187\nfor (i in 1:365) {\n  if (f(i) > 0.5) {\n    print(i)\n    break\n  }\n}\n# [1] 23\n\\end{verbatim}\n\nUsing Python:\n\n\\begin{verbatim}\n>>> import math\n>>> fac = math.factorial\n>>> f = lambda n: 1 - fac(n) * (fac(365) / (fac(n) * fac(365 - n))) / 365.0**n\n>>> for i in range(1,365):\n...     if f(i) > 0.5:\n...         print(i)\n...         break\n... \n23\n\\end{verbatim}\n\nAnswer: 23\n\n\\section{Find $n$ such that $\\mathbb P(A) > 0.99$ with $|A| = 1$}\n\nUsing R:\n\n\\begin{verbatim}\nfor (i in 1:365) {\n  if (f(i) > 0.99) {\n    print(i)\n    break\n  }\n}\n# [1] 57\n\\end{verbatim}\n\nUsing Python:\n\n\\begin{verbatim}\n>>> for i in range(1,365):\n...     if f(i) > 0.99:\n...         print(i)\n...         break\n... \n57\n\\end{verbatim}\n\n\\end{document}", "meta": {"hexsha": "2c1ce755f17e75da0e8efc3bc71ca24e349c6413", "size": 3205, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability_theory_practicals/ex5/solution.tex", "max_stars_repo_name": "prokls/math-lecture-notes", "max_stars_repo_head_hexsha": "d1a94e128d13ce4399a9cc55323b2f8e0d9494fd", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2015-11-25T01:49:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T14:47:36.000Z", "max_issues_repo_path": "probability_theory_practicals/ex5/solution.tex", "max_issues_repo_name": "prokls/math-lecture-notes", "max_issues_repo_head_hexsha": "d1a94e128d13ce4399a9cc55323b2f8e0d9494fd", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-05-22T07:56:03.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-02T09:32:40.000Z", "max_forks_repo_path": "probability_theory_practicals/ex5/solution.tex", "max_forks_repo_name": "prokls/math-lecture-notes", "max_forks_repo_head_hexsha": "d1a94e128d13ce4399a9cc55323b2f8e0d9494fd", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-03-24T14:42:30.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-25T11:00:11.000Z", "avg_line_length": 32.05, "max_line_length": 403, "alphanum_fraction": 0.5803432137, "num_tokens": 1273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671712, "lm_q2_score": 0.903294216466424, "lm_q1q2_score": 0.8395581430796922}}
{"text": "\\chapter{Functions}\n\n\\index{function}\n\nIn a pure mathematical sense, a function is defined as taking an input and determining some output based on that input. A function allows us to group a piece of code that we expect to re-use many times.\n\n\\section{Inputs and Outputs}\n\nA simple example might be a function that finds the absolute value of a number. That is, it gets rid of the negative sign if the number is negative, or else it leaves it alone.\n\n\\codejs{\\source{js/absolute.js}}\n\nLet's take a look at all the elements of how we create functions in JavaScript. The \\texttt{var absolute} is a variable just like any other variable. It is how we are going to refer to this particular function later on in the program. The assignment \\texttt{=} is simply stating that once I create the function, that variable will hold a reference to it.\\\\\n\n\\index{arguments of a function}\n\nNext, I use the \\texttt{function} keyword to state that I am defining a new function. What follows is an open and closed set of parenthesis. This defines the argument list to the function: the inputs to the function, and how I will refer to them from within the function. \\texttt{function(x)} means that this function will have 1 input, and we will refer to that input as \\texttt{x} within the function as if it is a variable. However, \\texttt{x} is not accessible outside the function, only inside of it.\\\\\n\nWhat follows the argument list is a set of open and closed curly brackets \\texttt{\\{\\}}. All of the code between these brackets is what is run whenever the function is called. This is where I put any of the control structures or calls to other functions I wish to occur to complete the task this function is supposed to perform.\\\\\n\n\\index{return statement}\n\nThe \\texttt{return} statement causes the function to stop executing the function code, and return immediately back to where the function was called. A single value can also be returned to that point as in this example. The absolute value function checks to see if the number is negative. If it is, it returns the negation of the number causing it to return a positive number. Otherwise it will return the original number, which I know must already be a positive number.\\\\\n\nI can put a \\texttt{return} statement in multiple places within the function code, but only one of them will be called during a particular call to the function since it will immediately terminate the function as soon as it's reached. So, if it returns the negation of a negative number inside the \\texttt{if} statement, it will never reach the other \\texttt{return} statement.\\\\\n\nAfter the closing bracket of the function is a semi-colon, which is placed there because of the assignment operation that assigned this function into the variable \\texttt{absolute}, just like every other assignment operation such as \\texttt{var z = 4;}.\\\\\n\nOnce the function is defined, I can call the function by referring to it using the \\texttt{absolute} variable. Calling the function is performed by placing an open and closed set of parenthesis with the values I wish the arguments to have inside the function, in exactly the same order as they appeared in the argument list when the function was defined. In this example I find the absolute value of \\texttt{-3.5} by calling the function with that as the value of the \\texttt{x} argument: \\texttt{absolute(-3.5)}. This is such a useful function that it is a part of JavaScript already, and can be called by referring to \\texttt{Math.abs(x)}.\\\\\n\n\\section{Function Scope}\n\n\\index{function scope}\n\nI can put any code inside a function that I wish, including defining new variables. However, when I define a variable in a function, that variable is not directly accessible outside of the function. This is called function scope. This prevents causing confusion when using the same variable name in different functions.\\\\\n\n\\codejs{\\source{js/sqrt.js}}\n\nThis example shows one particular way of approximately computing the square root of a number using iteration. JavaScript has a square root function already as \\texttt{Math.sqrt(x)}, but lets look at how this function works.\\\\\n\nIt begins just like the \\texttt{absolute} function, by declaring a new variable \\texttt{var sqrt = } to name the \\texttt{function}, and an argument list \\texttt{(...)} naming a single input \\texttt{x}. However, this \\texttt{x} is not the same as the previous \\texttt{x}. The argument is only referenced inside of the function, and since this is a different function the argument can have the same name.\\\\\n\nThe first thing done when the function is called is to declare a variable \\texttt{guess}, which will end up being the approximate value of the square root of the input. The initial value of \\texttt{guess} is not super important, but I know that the square root of a number is less than the number itself, so starting with a guess of half the original number is a good start.\\\\\n\nAnother variable \\texttt{max\\_error} is then declared to hold a value of how accurate I want the answer to be. I might be tempted to just put zero here, but if I did that then the function may not ever finish running! Basically, if I want a more accurate answer, the function will take longer to run since it will have to iterate more times. So, I just pick a value of the error that is small compared to the numbers I am interested in.\\\\\n\nThese variables are not accessible outside of the function. They don't exist until the function is called, and once the function stops they in effect disappear. So, if I want a variable declared in a function to have a particular value, then I have to assign it within the function. If I want to know what the value was once the function returns, then I have to make sure there is another way to access it, such as using the \\texttt{return} statement to return the value the variable contained.\\\\\n\nA while-loop control structure is then used to implement the iteration. The loop should continue to iterate until the error is less-than or equal to the maximum error that I specified. To do that, the square of the \\texttt{guess} is computed by multiplying it by itself, and then subtracting from what should be the true value of the square, which was the original number. If the guess was exactly equal to the square root of \\texttt{x}, then this difference would be zero. However, it could be more or less than the true value since it is only approximate.\\\\\n\nThe difference \\texttt{guess*guess - x} is then fed into the \\texttt{absolute()} function from earlier because the difference could be negative, and I only care about how big it is in magnitude so that I can use the comparison operator to see if it's bigger than the maximum error I want.\\\\\n\nNotice that I did some math inside of the argument list of the \\texttt{absolute()} function. That is ok! Before \\texttt{absolute} is called, all of the operations inside there are performed to result in a single number that is then assigned as the argument to the function, and only then is \\texttt{absolute} actually called. Also, notice that \\texttt{absolute} is really a variable declared outside of the \\texttt{sqrt} function, but I am referring to it from inside the \\texttt{sqrt} function. Function scope works like a one-way mirror: it can see all the variables declared outside, but no-one on the outside can see the variables that are inside.\\\\\n\nInside the while loop the \\texttt{guess} is made better by using some mathematical magic based on the previous guess and the original number. Every time through the loop the \\texttt{guess} gets closer and closer to the real deal, and eventually it's close enough that the loop condition causes the loop to stop.\\\\\n\nAfter the loop is done I just need to return the value of \\texttt{guess} back to where the function was called. At this point the variables \\texttt{guess} and \\texttt{max\\_error} can no longer be referenced from anywhere, but the returned value is assigned into the variable \\texttt{y} in this example, so that is where it is now stored.\\\\\n\n\\section{Recursion}\n\n\\index{recursion}\n\nThe code inside a function can call other functions, including itself. When a function calls itself, or results in another call to itself, this is called recursion. This is a form of iteration since the same code is executed repeatedly, and so must have some condition when it will stop, just like with a loop.\\\\\n\n\\codejs{\\source{js/factorial.js}}\n\nThis example shows a recursive function that computes the factorial of an integer: \\(n! = n(n-1)(n-2)...(3)(2)1\\). The first thing it does is see if the argument to the function is  0, since factorial of 0 is 1. If it's not 0, then it computes the factorial of 1 less than the argument by calling itself on \\texttt{n-1}, multiplies the result by \\texttt{n} and returns that. It can call itself because the variable \\texttt{factorial} is already defined, and the function will be defined before it gets called the first time.\\\\\n\nWhy does this work? The first time the function is called, the argument is equal to the number it's actually computing the factorial of. Say it's the number 5. We know that \\(5! = 5*4*3*2*1\\), and we noticed that \\(4! = 4*3*2*1\\). So we can re-write the original problem as \\(5! = 5*4!\\). Translating that into code means that the factorial of a number can be computed by calling the same function on 1 less than that number, and multiplying the result by the number.\\\\\n\nWhen the function is called the second time, the argument n has a value of 4. Technically speaking, the first call to the function hasn't even finished yet. It's waiting for the second call of the function to return before it can multiply by it's version of n to return the total answer. This is ok because every time the function is called it creates an entirely new \\texttt{n} to work with, so the computer doesn't get confused about which one is which. That is called a stack frame, and every recursive call creates a new frame on the stack of all the previous calls that are waiting on this particular call to the function to finish.\\\\\n\nTo complete this call, the same logic applies as the first time. \\(4! = 4 * 3!\\). This keeps working until it gets down to zero. \\(1! = 1 * 0!\\), but then what is \\(0!\\)? If we let the function keep doing the same thing it would think that \\(0! = 0 * (-1)!\\), and then \\((-1)! = (-1)*(-2)!\\)  and so on. For one thing that's just wrong. For another, it would never stop! That is what the if-statement is for: it's a terminating condition for when it reaches 0.\\\\\n\nOnce the terminating condition is reached, it returns a value without having to call itself anymore. All the previous calls to the function on the call stack that are waiting can then be completed in the reverse order. \\texttt{factorial(0)} returns 1. Then \\texttt{factorial(1)} returns 1. Then \\texttt{factorial(2)} returns 2. \\texttt{factorial(3)} returns 6. \\texttt{factorial(4)} returns 24. And finally \\texttt{factorial(5)} returns 120, which was the first thing to get called and is the final answer.\\\\\n\nAs an exercise, lets see what would happen if we called \\texttt{factorial(-1)}? You can code it up and just see. But lets also think about it logically why what happens, happens. If the argument starts out as -1, the first thing it does is check to see if it's equal to 0. It's not, so it does the recursive call sending in \\texttt{n-1}, which is -2. As stated before, this will cause an infinite recursion because the terminating condition \\texttt{n === 0} will never be reached. However, it won't run forever. What will happen is that it continues to pile recursive calls onto the call stack, potentially thousands of times, but at some point the computer will say that the maximum size of the stack was reached and will terminate the program, called a stack overflow.\\\\\n\n\\section{Exception Handling}\n\n\\index{exceptions}\n\\index{throw statement}\n\nThe function call \\texttt{factorial(-1)} never returns, but it doesn't run forever either. It simply exhausts the resources of the computer and crashes the program. For one, factorial isn't really even defined for -1. So it shouldn't have even attempted to compute it. This is an undefined scenario. The way I might deal with that is by throwing an exception from THE function to tell whoever tried to compute \\((-1)!\\) that they're not suppose to do that.\\\\\n\n\\codejs{\\source{js/factorial_exception.js}}\n\nThe \\texttt{throw} keyword works similarly to \\texttt{return}: The function will stop executing, and a value will be associate with the termination. In this case I send a message about what happened. When something is thrown, however, it is an error, and causes what is called a program exception (something that isn't supposed to happen). If that exception is not handled by whatever called the function, then the whole program will terminate. This prevents the undefined behavior from happening unknown to anyone. The stack overflow was also an exception, but the exception I add should catch the problem sooner and give more information about what the issue is.\\\\\n\nThe way we can handle possible exceptions from a function is called a try-catch block. I put the code that might cause an exception inside the braces of the \\texttt{try}. If no exception occurs, then everything proceeds as if there is no exception handling at all. However, if that code results in an exception, then execution in the try block terminates, and the catch block begins executing and the \\texttt{err} argument contains the value that was specified at the \\texttt{throw} statement.\\\\\n\n\\index{try-catch}\n\n\\codejs{\\source{js/factorial_exception_handled.js}}\n\n\\section{Side-effects}\n\n\\index{side effects of a function}\n\nSince the code inside a function can access the variables declared outside of the function, it can also alter the values stored in those variables. Since those variables are not arguments to the function, nor are they assigned from the \\texttt{return} from the function, we call this type of alteration a \\textit{side-effect} of calling the function.\n\n\\codejs{\\source{js/increment.js}}\n\nIn this example \\texttt{increment} is a function that has no arguments, and does not return anything. However, when it is called it alters the variable \\texttt{i} by adding 1 to its current value. Since \\texttt{i} is declared outside of the function, it can be accessed directly even after the function returns.\\\\\n\nThis type of behavior is very useful and powerful, but it must be used carefully. Since side-effects can have consequences far away from where the function is actually called, as opposed to the return statement, and persist after the function returns, someone that didn't write the function may not understand what it's doing. Documentation should be used to describe what is happening if a function has side-effects.\\\\\n\n\\section{Closure}\n\n\\index{closure}\n\nA closure happens when one function is defined inside the scope of another function, but is still callable after the outer function has already returned. It is also a way of using the power of function side-effects without any of the dangers by containing the side effects to a particular function scope.\n\n\\codejs{\\source{js/increment_closure.js}}\n\nI've taken the code for the \\texttt{increment} function, and placed it inside another function called \\texttt{makeIncrement}. When \\texttt{makeIncrement} is called, it creates a new instance of \\texttt{increment}, which is returned. However, since \\texttt{increment} has to have access to the variable \\texttt{i} to work, a closure is formed around that function scope so that it still has access to the version of \\texttt{i} created at the same time the function was, even after \\texttt{makeIncrement} has returned.\\\\\n\nWhen \\texttt{makeIncrement} returns the inner function, it is stored in a new variable. Whenever that version of \\texttt{increment} is called it is working with its own version of \\texttt{i}. I can call \\texttt{makeIncrement} again, creating a new version of \\texttt{increment} with its own version of \\texttt{i}, independent of the other one. That is because each call to \\texttt{makeIncrement} creates its own scope, and a new closure when it returns.\\\\\n\nNo matter which order the two versions of the function are called, it remembers how many times that particular version has already been called independent from the other one. However, I cannot directly access the variable \\texttt{i} because it was inside the function scope of \\texttt{makeIncrement}. It is basically a hidden variable that can be used to keep track of some information between function calls, and so as the creator of \\texttt{makeIncrement} I don't have to worry about anyone messing with that variable or making any assumptions about it.\\\\", "meta": {"hexsha": "50bab6aa69aec7aea39a120da85ea1ae471ae997", "size": 16709, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TeX_files/Functions.tex", "max_stars_repo_name": "kcdodd/ecsp-book", "max_stars_repo_head_hexsha": "371e0e07140bc2fa5a8e3d424510900f368f885a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-07-27T18:34:02.000Z", "max_stars_repo_stars_event_max_datetime": "2015-07-27T18:34:02.000Z", "max_issues_repo_path": "TeX_files/Functions.tex", "max_issues_repo_name": "kcdodd/ecsp-book", "max_issues_repo_head_hexsha": "371e0e07140bc2fa5a8e3d424510900f368f885a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TeX_files/Functions.tex", "max_forks_repo_name": "kcdodd/ecsp-book", "max_forks_repo_head_hexsha": "371e0e07140bc2fa5a8e3d424510900f368f885a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 139.2416666667, "max_line_length": 772, "alphanum_fraction": 0.7782033635, "num_tokens": 3820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.9073122244934722, "lm_q1q2_score": 0.8394724467959492}}
{"text": "\n\\subsection{Assumtions}\n\nGenerally, k states, markov chain?\n\nAssumptions are:\n\n+ Lasting immunity\n+ No births/other deaths\n\nComponents:\n\n+ \\(S(t)\\) - Susceptible\n+ \\(I(t)\\) - Infected\n+ \\(R(t)\\) - Removed (recovered or died)\n\nProportion of people who recover each period - \\(\\gamma \\).\n\nEach period, infected can transmit to \\(\\beta \\) people. Total of \\(I\\beta \\).\n\nNot everyone susceptible though, so \\(I\\beta \\dfrac{S}{N}\\)\n\nDynamics:\n\n+ \\(\\dfrac{dR}{dt} = \\gamma I\\)\n+ \\(\\dfrac{dS}{dt} = -\\beta I \\dfrac{S}{N}\\)\n+ \\(\\dfrac{dI}{dt} = \\beta I \\dfrac{S}{N} - \\gamma I\\)\n\nNote that \\(dfrac{dR}{dt} + dfrac{dI}{dt} + \\dfrac{dS}{dt} = 0\\)\n\nWe can then work out \\(\\dfrac{dI}{dS}\\)\n\n\\(\\dfrac{dI}{dS} = \\dfrac{\\dfrac{dI}{dt}}{\\dfrac{dS}{dt}}\\)\n\n\\(\\dfrac{dI}{dS} = \\dfrac{\\beta I \\dfrac{S}{N} - \\gamma I}{-\\beta I \\dfrac{S}{N}}\\)\n\n\\(\\dfrac{dI}{dS} = \\dfrac{\\beta S - \\gamma N}{-\\beta S}\\)\n\n\\(\\dfrac{dI}{dS} = - 1 + \\dfrac{\\gamma }{\\beta }\\dfrac{N}{S}\\)\n\nWe can then work out \\(\\dfrac{dS}{dR}\\)\n\n\\(\\dfrac{dS}{dR} = \\dfrac{\\dfrac{dS}{dt}}{\\dfrac{dR}{dt}}\\)\n\n\\(\\dfrac{dS}{dR} = \\dfrac{-\\beta I \\dfrac{S}{N}}{\\gamma I}\\)\n\n\\(\\dfrac{dS}{dR} = -\\dfrac{\\beta }{\\gamma }\\dfrac{S}{N}\\)\n\nWe can rewrite the infection dynamic:\n\n+ \\(\\dfrac{dI}{dt} = \\beta I \\dfrac{S}{N} - \\gamma I\\)\n+ \\(\\dfrac{dI}{dt} = I(\\beta \\dfrac{S}{N} - \\gamma )\\)\n+ \\(\\dfrac{dI}{dt} = I\\gamma (\\dfrac{\\beta }{\\gamma }\\dfrac{S}{N} - 1)\\)\n\nThis means that outbreak if \\(\\dfrac{\\beta }{\\gamma } > \\dfrac{S}{N}\\)\n\n\\(R_0 = \\dfrac{\\beta }{\\gamma }\\)\n\nWhat is steady state?\n\n\\(\\dfrac{dI}{dt} = I(\\beta \\dfrac{S}{N} - \\gamma )\\)\n\n\\(\\dfrac{dI}{dt} = 0\\)\n\n\\(R_0 \\dfrac{S}{N} = 1 )\\)\n\n\\(\\dfrac{S}{N} = \\dfrac{1}{R_0} )\\)\n\n\\(\\dfrac{\\beta }{\\gamma } > \\dfrac{S}{N}\\)\n\n\n\\subsection{Vaccinations}\n\nWhat proportion need vaccination?\n\n\n", "meta": {"hexsha": "4281ec5a47bea6ba9e4b19f39c59c02a1d8c7908", "size": 1776, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/biology/SIR/01-01-SIR.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/biology/SIR/01-01-SIR.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/biology/SIR/01-01-SIR.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.0649350649, "max_line_length": 83, "alphanum_fraction": 0.5698198198, "num_tokens": 769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341975270267, "lm_q2_score": 0.8774767922879693, "lm_q1q2_score": 0.839424307038991}}
{"text": "\\subsection{Fubini's Theorem for Z-simple Regions}\r\n\\noindent\r\nThere is another case of Fubini\u2019s Theorem that arises in 3D.\\\\\r\n\\begin{theorem}[Fubini's Theorem for Z-simple Regions]\r\n\tLet $D \\subset \\mathbb{R}^3$ and let $\\Omega = \\left\\{(x,y,z) \\mid (x,y) \\in D, g(x,y) \\leq z \\leq h(x,y) \\right\\}$ be a z-simple region.\r\n\t\\begin{equation*}\r\n\t\t\\iiint\\limits_{\\Omega}{f(x,y,z)\\mathrm{d}V} = \\iint\\limits_{D}{\\int_{g(x,y)}^{h(x,y)}{f(x,y,z)\\mathrm{d}z}\\mathrm{d}A}\r\n\t\\end{equation*}\r\n\\end{theorem}\r\n\r\n\\noindent\r\nIn other words, dependent variables must be integrated before the independent variables on which they rely, but the order of integration of independent variables doesn't matter.\\\\\r\n\r\n\\noindent\r\nFor example, we an express the unit sphere as a z-simple region where $D = \\left\\{(x,y) \\mid x^2 + y^2 \\leq 1\\right\\}$ and $-\\sqrt{1 - x^2 - y^2} \\leq z \\leq \\sqrt{1 - x^2 - y^2}$. Note that $D$ is a Type I Region.\r\n\\begin{equation*}\r\n\tV_{\\text{sphere}} = \\int_{-1}^{1}{\\int_{-\\sqrt{1-x^2}}^{\\sqrt{1-x^2}}{\\int_{-\\sqrt{1-x^2-y^2}}^{\\sqrt{1-x^2-y^2}}{\\mathrm{d}z}\\mathrm{d}x}\\mathrm{d}x} = \\frac{4\\pi}{3}\r\n\\end{equation*}", "meta": {"hexsha": "08702181edf046895149f2f8c84a0362c3d20988", "size": 1125, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/multipleIntegrals/fubinisTheoremZSimpleRegions.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/multipleIntegrals/fubinisTheoremZSimpleRegions.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/multipleIntegrals/fubinisTheoremZSimpleRegions.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 62.5, "max_line_length": 215, "alphanum_fraction": 0.6488888889, "num_tokens": 435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.956634196290671, "lm_q2_score": 0.8774767842777551, "lm_q1q2_score": 0.8394242982912727}}
{"text": "The homogeneous rigid transform is an extremely useful tool used to represent various things in robotics. \nFirst, the rigid transform is defined as a transformation $T$ that when acting on any vector $v$, produces a transformed vector $T(v)$ of the form: \n\\begin{equation}\n\tT(v) = R v + t\n\\end{equation}\n\nwhere $R^T R^{-1}$, and $t$ is a vector giving the translation of the origin. \nThis concept can be represented in a form called a {\\it homogeneous transformation matrix}. \nA homogeneous transformation matrix $T \\in \\mathbb{R}^{4 \\times 4}$ is a member of special euclidean group $SE(3)$, and can be written in the form:\n\\begin{equation}\n\tT = \\begin{bmatrix}\n\t\tR & t \\\\\n\t\t\\bf{0} & 1\n\t\\end{bmatrix}\n\\end{equation}\nwhere $R \\in \\mathbb{R}^{3 \\times 3}$ is a rotation matrix, and $t \\in \\mathbb{R}^3$ is a translation vector. \nThe inverse of a homogeneous transformation matrix is:\n\\begin{align}\n\tT^{-1} &= \n\t\\begin{bmatrix}\n\t\tR^T & -R^Tt \\\\\n\t\t\\bf{0} & 1\n\t\\end{bmatrix} \\\\\n\tT T^{-1} &= \\bf{I}\n\\end{align}\nWhen using super and subscripts to specify the frames we are referring to, then $T_b^a = (T_a^b)^{-1}$.\nWe can use a homogeneous transformation to operate on homogeneous points $p, q \\in \\mathbb{R}^4$, \n\\begin{align}\n\tq &= Tp \\\\\n\t\\begin{bmatrix} \n\t\tx_q \\\\ \n\t\ty_q \\\\\n\t\tz_q \\\\\n\t\t1\n\t\\end{bmatrix}\n\t&= \\begin{bmatrix}\n\t\tR & t \\\\\n\t\t\\bf{0} & 1\n\t\\end{bmatrix} \n\t\\begin{bmatrix}\n\t\tx_p \\\\\n\t\ty_p \\\\\n\t\tz_p \\\\\n\t\t1\n\t\\end{bmatrix}.\n\\end{align}\n\nIn general, there are three interpretations for homogeneous transformations:\n\\begin{enumerate}\n\t\\item A description of relative orientation and translation between frames. \n\t\\item A coordinate transform between frames. \n\tSpecifically, $T_j^i$ is a transform from frame ${j}$ to frame ${i}$:\n\t\\begin{equation}\n\t\tP^i = T_j^i P^j\n\t\\end{equation}\n\t\\item A motion of a point (or a collection of points) within a single frame. For example, as we saw above point $p$ can be moved to point $q$:\n\t\\begin{align}\n\t\tq &= Tp \\\\\n\t\tP_2^i &= T_j^i P^i_1\n\t\\end{align}\n\tSimilarly, a homogeneous transform can represent a motion from one frame to another.\n\tSpecifically, $T_j^i$ moves frame $i$ to frame $j$. \n\\end{enumerate}\nIt is important to specify which of these interpretations you are using within your program, as it can get confusing what these transformations represent if people aren't on the same page. \n\nAdditionally, one must pay attention to the frame that the operand is in, as this determines the function of the transform to some degree. \n$P_2^i = T^i_j P_1^i$ is a motion that operates on point $P_1^i$ within frame $i$ whereas $P^i = T_j^i P^j$ is a coordinate transformation from $j$ to $i$, and therefore if we feed a point in frame $j$ to this transformation, the point will not move, but the coordinates will be transformed into frame $i$, which is often desired.  \n\n\\subsection{Transforming between frames}\nWe can chain together homogeneous transforms to represent a traversal through frames. \n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{images/frame_traversal.png}\n\t\\caption{Traversing through different coordinate frames represented by rigid transformation matrices.}\n\t\\label{fig: frames}\n\\end{figure}\n\nSay we want the transform from $a$ to $d$:\n\\begin{equation}\n\tT_d^a = T^a_b T^b_c T^c_d.\n\\end{equation}\nNotice that the bottom subscript and the following top subscript \"cancel\" out when multiplying frames together. \nAdditionally when composing transforms like this, the \"source\" frame (in this case $d$) is included in the right most transform, and the \"destination\" frame $a$, is included in the left most. \n\nUsing this knowledge we can represent frames that are related in this way by a pose graph, or pose tree consisting of parent and child relationships between each frame. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{images/pose_graph.png}\n\t\\caption{Frames and their transforms can be represented in graph form.}\n\t\\label{fig: poses}\n\\end{figure}", "meta": {"hexsha": "1abebc00b4ca4fb7248b4911653d67f5bb8d2b2f", "size": 3951, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/math/core/core_transform.tex", "max_stars_repo_name": "bkolligs/pyrobo", "max_stars_repo_head_hexsha": "341687cbed96f839fae682f9ec1c58524d7b35b4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-06-20T15:40:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-11T03:20:29.000Z", "max_issues_repo_path": "docs/math/core/core_transform.tex", "max_issues_repo_name": "bkolligs/pyrobo", "max_issues_repo_head_hexsha": "341687cbed96f839fae682f9ec1c58524d7b35b4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-07-06T01:31:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-31T00:05:39.000Z", "max_forks_repo_path": "docs/math/core/core_transform.tex", "max_forks_repo_name": "bkolligs/robotics-prototyping", "max_forks_repo_head_hexsha": "ac7766921c7e8b2c51792697ddf2166ab9a46c82", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.9456521739, "max_line_length": 332, "alphanum_fraction": 0.7266514806, "num_tokens": 1147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322216, "lm_q2_score": 0.8872045877523147, "lm_q1q2_score": 0.8391192287136076}}
{"text": "\n\\subsection{Mean Squared Error (MSE) and Root Mean Squared Error (RMSE) of an estimator}\n\n\\subsubsection{Mean squared error}\n\nMean squared error\n\n\\(MSE = E[(\\hat \\theta - \\theta )^2]=E[((\\hat \\theta - E[\\hat \\theta ])+(E[\\hat \\theta ]-\\theta ))^2]\\)\n\n\\(MSE = E[(\\hat \\theta - \\theta )^2]=E[(\\hat \\theta - E[\\hat \\theta ])^2+(E[\\hat \\theta ]-\\theta )^2+2(E[\\hat \\theta ]-\\theta )(\\hat \\theta- E[\\hat \\theta ])]\\)\n\n\\(MSE = E[(\\hat \\theta - \\theta )^2]=E[(\\hat \\theta - E[\\hat \\theta ])^2]+E[(E[\\hat \\theta ]-\\theta)^2] +E[2(E[\\hat \\theta ]-\\theta )(\\hat \\theta- E[\\hat \\theta ])]\\)\n\n\\(MSE = E[(\\hat \\theta - \\theta )^2]=Var(\\hat \\theta )+(E[\\hat \\theta ]-\\theta)^2 +2(E[\\hat \\theta ]-\\theta )E[\\hat \\theta- E[\\hat \\theta ]]\\)\n\n\\(MSE = E[(\\hat \\theta - \\theta )^2]=Var(\\hat \\theta )+Bias (\\hat \\theta )^2\\)\n\n\\subsubsection{Root Mean Square Error (RMSE)}\n\nThis is the square root of the MSE.\n\nIt is also called the Root Mean Square Deviation (RMSD)\n\n", "meta": {"hexsha": "3a764255198607bc903c4ffb9fbfb652651ea705", "size": 947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/generative/02-02-MSE.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/generative/02-02-MSE.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/generative/02-02-MSE.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.4583333333, "max_line_length": 166, "alphanum_fraction": 0.5923970433, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506726044381, "lm_q2_score": 0.8902942217558213, "lm_q1q2_score": 0.8391082921633093}}
{"text": "\\section{Linear Systems of Equations}\n\\label{sec:linearequations}\n\n(Real numbers only this time.)\n\nLinear equations are of the form $Ax = b$ where $A$ is a matrix and $x$ and $b$ are vectors. The rows of $A$ and $b$ form a system of equations that must be simultaneously satisfied by the entries of $x$. If $x,b\\in\\mathbb{R}^n$, then the solutions to the equation of a single row corresponds to an $n-1$-dimensional hyperplane. If the rows of $A$ are linearly independent, then solutions that simultaneously satisfy the equations in $k$-rows correspond to the $n-k$-dimensional intersection of $k$ $n$-dimensional hyperplanes. The solution of $x$ that satisfies all $n$ equations is a $n-n = 0$-dimensional point, and so $x$ is uniquely determined. If any two rows of $A$ are not linearly independent, then the hyperplanes that correspond to values of $x$ that satisfy them overlap exactly, and their intersection is $n$ dimensional, rather than $n-1$ dimensional. In this case, the value of $x$ that satisfies all rows of $A$ is not narrowed down to a single point. The system of equations is said to be *underdetermined*:. This is equivalently the case when $A$ has $m<n$ rows.  \n\n\\subsection{$A\\in\\mathbb{R}^{n\\times n}$ Square Matrices}\nIf $A\\in\\mathbb{R}^{nxn}$, then the solution to the system is formally $x = A^{-1}b$, where $A^{-1}$ is the matrix inverse, satisfying $A^{-1}A=I$, where $I$ is the identity matrix. \n\nSince $Ax=b$ is the same as expressing $b$ in terms of a linear combination of the columns of $A$, the entries of $x$ can be interpreted as the coefficients resulting from the projection of $b$ into the column space of $A$. Therefore, for an orthonormal matrix, the $A^{-1}$ is simply $A^T$ \n\n\\subsection{$A\\in\\mathbb{R}^{m\\times n}$ Rectangular Matrices, Overdetermined Case}\nIf $A\\in\\mathbb{R}^{mxn}$ with $m>n$ rows, then there need not be any point $x\\in\\mathbb{R}^n$ in which the $m$ hyperplanes all intersect. In that case, the system does not have a solution $x\\in\\mathbb{R}^n$, and the system is considered *overdetermined*. (The intersection of $m$ distinct hyperplanes in $n$ dimensional space would have negative dimension $(n-m)<0$ if $m>n$, which my feeble brain can't make sense of.)\n\\\\\n\nIn the overdetermined case $A^{mxn}$ with $m>n$, the columns of $A$ do not span $\\mathbb{R}^m$ and therefore $b\\in\\mathbb{R}^m$ may have some component $\\epsilon$ that lies outside of the column space of $A$. In that case, no linear combination $x$ of the columns of $A$ can express $b$ perfectly, but we might look for approximate solutions $\\hat{x}$ so that:\n\n\\begin{equation}\nA\\hat{x} + \\epsilon = b\n\\end{equation}\n\nSo that the error $||\\epsilon||_{\\alpha}$ is minimized. This is the starting point for linear regression from the linear algebra perspective. In practice, the approximation is usually approximated by applying an iterative gradient descent algorithm to minimize the \\textit{loss function} $||\\epsilon||_{\\alpha}$. The choice of metric $||\\cdot||_{\\alpha}$ is essentially a design choice. For $\\alpha=2$, the metric is the $L^2$ norm (cf. section \\ref{sec:l2norm}) and an analytic solution exists, named the \\textit{normal equations}. The solution minimizes the least squares error and corresponds to the projection of $\\mathbf{b}$ into the column space of $a$. The procedure is better known as ordinary least squares regression and therefore I will move a more elaborate discussion to chapter \\ref{chap:linearregression}.\n\n\\subsection{$A\\in\\mathbb{R}^{n\\times m}$ Rectangular Matrices, Underdetermined Case}\nFor an underdetermined system with $m<n$, there is either no solution (if the $m$ hyperplanes don't intersect), or there are infinitely many possible solutions that lie on an $n-m$ dimensional hyperplane. One idea is to pick the solution that minimizes $||\\hat{x}||_2$ based on the idea that it might generalize better. The least norm solution is $\\hat{x} = A^T\\left(AAT\\right)^{-1}b$, which is the projection of $\\vec{0}$ on the solution set.\n", "meta": {"hexsha": "5fac06cf1059867186fe01bbfa2ad4b4ab84d3ed", "size": 3997, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/linalg_linearequations.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/linalg_linearequations.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/linalg_linearequations.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 148.037037037, "max_line_length": 1082, "alphanum_fraction": 0.7413059795, "num_tokens": 1097, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810451666345, "lm_q2_score": 0.8856314858927011, "lm_q1q2_score": 0.8390304827375067}}
{"text": "\\section{Richardson's Extrapolation}\nSuppose that for each number $h\\neq 0$, we have a formula $N_1(h)$ that approximates an unknown constant $M$ with truncation error $O(h)$\n\\begin{align*}\n    M-N_1(h) &= K_1h+K_2h^2+K_3h^3+\\ldots \\\\\n    M-N_1\\left(\\frac{h}{2}\\right) &= K_1h+K_2\\frac{h^2}{4}+K_3\\frac{h^3}{8}+\\ldots \\\\\n\\end{align*}\nIf we subtract the first equation from the second equation, then we'll get\n\\begin{align*}\n    & M=N_1\\left(\\frac{h}{2}\\right)+\\left[N_1\\left(\\frac{h}{2}-N_1(h)\\right)\\right] + K_2\\left(\\frac{h^2}{2}-h^2\\right) + K_3\\left(\\frac{h^3}{4}-h^3\\right) + \\ldots \\\\\n    \\Rightarrow & N_2(h) = N_1\\left(\\frac{h}{2}\\right) + \\left[N_1\\left(\\frac{h}{2}-N_1(h)\\right)\\right] \\\\\n    \\Rightarrow & M = N_2(h) - \\frac{K_2}{2}h^2 - \\frac{3K_3}{4}h^3 + \\ldots \\qquad \\text{with truncation error $O(h^2)$}\n\\end{align*}\n\\begin{align*}\n    & M=N_2\\left(\\frac{h}{2}\\right)+\\left[N_2\\left(\\frac{h}{2}-N_2(h)\\right)\\right]/3 + \\frac{K_3}{8}h^3 + \\ldots \\\\\n    \\Rightarrow & N_3(h) = N_2\\left(\\frac{h}{2}\\right) + \\left[N_2\\left(\\frac{h}{2}-N_2(h)\\right)\\right]/3 \\\\\n    \\Rightarrow & M = N_3(h) - \\frac{K_3}{8}h^3 + \\frac{7K_3}{48}h^4 + \\ldots \\qquad \\text{with truncation error $O(h^3)$}\n\\end{align*}\n", "meta": {"hexsha": "9505a4d03e492f23591d5dbf3359452ce9eec0a1", "size": 1213, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/4.2_richardson_extrapolation.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/4.2_richardson_extrapolation.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/4.2_richardson_extrapolation.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.3888888889, "max_line_length": 167, "alphanum_fraction": 0.6215993405, "num_tokens": 548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.8856314813647587, "lm_q1q2_score": 0.8390304771320799}}
{"text": "\\section{Eigenvectors of Circulant Matrices}\n\n\nDefine the $n \\times n$ matrix $A$ by\n\\begin{equation}\nA = \\begin{bmatrix*}[r] -2 & 1 & 0 & 0 & \\dots & 0 & 0 & 1 \\\\ 1 & -2 & 1 & 0 & \\dots& 0 & 0 & 0 \\\\ 0 & 1 & -2 & 1 & \\cdots&0 & 0 & 0 \\\\ 0 & 0 & 1 & -2 & \\cdots&0 & 0 & 0 \\\\ \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots & \\vdots \\\\ 0 & 0 & 0 & 0 & \\cdots & -2 & 1 & 0 \\\\ 0 & 0 & 0 & 0 & \\cdots & 1 & -2 & 1\\\\ 1 & 0 & 0 & 0 & \\cdots & 0 & 1 & -2 \\end{bmatrix*}\n\\end{equation}\nIn this project, you will explore (and explain) the behavior of the iterative map\n    \\begin{equation}\n      \\label{eq:eigen-iterative}\n      \\bm{x}^{(k+1)} = \\left(I + \\eta A\\right) \\bm{x}^{(k)}\n    \\end{equation}\n    for various initial vectors $\\bm{x}^{(0)}$, and for $\\eta = 0.1$. \n\\begin{enumerate}[(a)]\n  \\item Create a function that takes in the argument $n$ and returns the $n \\times n$ matrix $A$.  \\textit{Hint:} The built-in functions \\texttt{diag(...)} (Matlab), or \\texttt{np.diag(...)} (Python), or \\texttt{diagm(...)} (Julia) may be useful.\n  \\item Let $n = 32$. Create the $n$ dimensional initial vector $\\bm{x}^{(0)}= (1,0,0,\\dots,0)$ and plot $\\bm{x}^{(0)}$, $\\bm{x}^{(1)}$, $\\bm{x}^{(2)}, \\dots $. Repeat a selection of initial vectors until you can qualitatively describe the behavior of the map $\\bm{x} \\to (I + \\eta A)\\bm{x}$? \n  \\item Compute the eigenvectors of $(I+\\eta A)$ by using the function \\texttt{[X,V]=eig(...)} (Matlab), \\texttt{V,X = np.linalg.eig(...)} (Python), or \\texttt{V,X=eigen(...)} (Julia).\n  \\item \\sloppy Plot enough of the eigenvectors so you get a sense for what they look like.\\\\ \\textit{Hint:} If your software returned complex-valued eigenvectors, it may be helpful to plot real and imaginary components separately, for example, in Julia, this would be \\texttt{plot(real(X[k,:]))} and \\texttt{plot(imag(X[k,:]))}. \n  \\item[($\\ast$)] \\textit{Bonus:} Propose a closed form representation for the eigenvectors. Can you prove that every symmetric circulant matrix has eigenvectors in this form? \n  \\item[($\\ast$)] \\textit{(Bonus:)} Let $C$ be an (arbitrary) circulant matrix. One of the (many) expressions for the $k$\\textsuperscript{th} eigenvector of a circulant matrix is \n\t  \\begin{equation}\n\t\t  \\label{eq:circulant-eig-vector}\n\t\t  \\bm{v}_k = \\begin{pmatrix} e^{(2 \\pi i) 0k/n}\\\\ e^{(2 \\pi i)1k/n}\\\\e^{(2 \\pi i) 2k/n} \\\\ \\vdots \\\\ e^{( 2 \\pi i) (n-1)k/n} \\end{pmatrix}\n\t\t \\end{equation}\n\t\t with corresponding eigenvalues given by the product of $c$, the first row of $C$, with the eigenvector,\n\t\t \\begin{equation}\n\t\t\t \\label{eq:circulant-eig-value}\n\t\t\t \\lambda_k = c v_k \n\t\\end{equation}\n\tVerify that $\\bm{x}_k$ as defined in equation (\\ref{eq:circulant-eig-vector}) is an eigenvector of an aribitrary circulant matrix, and that the corresponding eigenvalue is $\\lambda_k$, as give by equation (\\ref{eq:circulant-eig-value}).\n\t \\item The $n \\times n$ \\textit{Fourier Matrix} is the $n \\times n$ matrix whose columns are the eigenvectors $\\bm{v}_0$, $\\bm{v}_1$,\\ldots, $\\bm{v}_{n-1}$.  Write a function that takes argument $n$ and returns the $n\\times n$ Fourier matrix, $F$. \n  \\item Without any further computation, and by only considering eigenvectors and their corresponding eigenvalues, describe the evolution of the iterative map in equation (\\ref{eq:eigen-iterative}) for an initial vector in the form\n\\begin{equation*}\n\t\\bm{x}^{(0)} = \\big(\\, \\cos(2\\pi j / n) + 5 \\cos( 4 \\cdot 2\\pi j / n), \\text{ for } j = 1,...,n\\,\\big).\n\\end{equation*}\n\\end{enumerate}\nRepeat these steps for the $n \\times n$ matrix $B$, defined by\n\\begin{equation}\nB = \\begin{bmatrix*}[r] 0 & 1 & 0 & 0 & \\dots & 0 & 0 & -1 \\\\ -1 & 0 & 1 & 0 & \\dots& 0 & 0 & 0 \\\\ 0 & -1 & 0 & \\phantom{+}1 & \\cdots&0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 & \\cdots&0 & 0 & 0 \\\\ \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots & \\vdots \\\\ 0 & 0 & 0 & 0 & \\cdots & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 0 & \\cdots & -1 & 0 & 1\\\\ 1 & 0 & 0 & 0 & \\cdots & 0 & -1 & 0 \\end{bmatrix*}\n\\end{equation}\n", "meta": {"hexsha": "1d085ed36dea81cb6179453a05508d40aeadd9cf", "size": 3984, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "circulant-matrices.tex", "max_stars_repo_name": "colinlclark/integration_workshop", "max_stars_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "circulant-matrices.tex", "max_issues_repo_name": "colinlclark/integration_workshop", "max_issues_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "circulant-matrices.tex", "max_forks_repo_name": "colinlclark/integration_workshop", "max_forks_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-07-25T18:18:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-27T01:10:02.000Z", "avg_line_length": 97.1707317073, "max_line_length": 383, "alphanum_fraction": 0.6212349398, "num_tokens": 1511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810451666345, "lm_q2_score": 0.8856314798554444, "lm_q1q2_score": 0.8390304770179241}}
{"text": "\n\\subsection{Boolean algebra}\n\n\\subsubsection{Boolean algebra in propositional logic}\n\nWe previously discussed properties of normal form, and the results from these properties.\n\nIf another structure shares these properties then they will also share the results.\n\n\\subsubsection{Sets satisfy the definitions of a boolean algebra}\n\nIf a mathematical structure has the following properties, it shares the results from normal form, and is a boolean algebra.\n\n\\begin{itemize}\n\\item Both binary operators are commutitive - \\(A\\land B=B\\land A\\) and \\(A\\lor B=B\\lor A\\)\n\\item Both binary operators are associative - \\((A\\land B)\\land C=A\\land (B\\land C)\\) and \\((A\\lor B)\\lor C=A\\lor (B\\lor C)\\)\n\\item Completements - \\(A\\land \\neg A=\\emptyset \\) and \\(A\\lor \\neg A=U\\)\n\\item Absorption - \\(A\\land (A\\lor B)=A\\) and \\(A\\lor (A\\land B)=A\\)\n\\item Identity - \\(A\\land U=A\\) and \\(A\\lor \\emptyset =A\\)\n\\item Distributivity - \\(A\\land (B\\lor C)=(A\\land B)\\lor (A\\land C)\\) and \\(A\\lor (B\\land C)=(A\\lor B)\\land(A\\lor C)\\)\n\\end{itemize}\n\nThese hold for sets, and so boolean algebra holds for sets.\n\n", "meta": {"hexsha": "af7bc8dc7065a661c0218e6e26ac8dcf3a522c0c", "size": 1086, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/setsBasic/01-03-boolean.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/setsBasic/01-03-boolean.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/setsBasic/01-03-boolean.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.44, "max_line_length": 125, "alphanum_fraction": 0.711786372, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122744874228, "lm_q2_score": 0.8757870046160258, "lm_q1q2_score": 0.8389271215582643}}
{"text": "\\section{Derivatives of Trig Functions}\r\nLet's find the derivative of $f(x) = \\sin{x}$.\r\nUsing the limit definition of the derivative,\r\n\\begin{align*}\r\n\tf^\\prime(x) &= \\lim_{h \\to 0}{\\frac{\\sin{(x+h)}-\\sin{x}}{h}} \\\\\r\n\t&= \\lim_{h\\to 0}{\\frac{\\sin{x}\\cos{h} + \\cos{x}\\sin{h} - \\sin{x}}{h}} \\\\\r\n\t&= \\lim_{h \\to 0}{\\frac{\\sin{x}\\left(\\cos{h}-1\\right) + \\cos{x}\\sin{h}}{h}} \\\\\r\n\t&= \\sin{x}\\lim_{h\\to 0}{\\frac{\\cos{h}-1}{h}} + \\cos{x}\\lim_{h\\to 0}{\\frac{\\sin{h}}{h}} \\\\\r\n\t&= \\sin{x}\\cdot 0 + \\cos{x}\\cdot{1} \\\\\r\n\t&= \\cos{x}.\r\n\\end{align*}\r\n\r\n\r\nWe can now use the chain rule to get the derivative of $\\cos{x}$.\r\n\\begin{align*}\r\n\tf(x) &= \\cos{x} \\\\\r\n\t&= \\sin{\\left(\\frac{\\pi}{2}-x\\right)} \\\\\r\n\tf^\\prime(x) &= \\cos{\\left(\\frac{\\pi}{2}-x\\right)}\\cdot -1 \\\\\r\n\t&= -\\sin{x}.\r\n\\end{align*}\r\n\r\n\r\nThe rest of the derivatives of the common trig functions follow from these results and the quotient rule.\r\n\\begin{table}[H]\r\n\t\\begin{center}\r\n\t\t\\begin{tabular}{ l l l }\r\n\t\t\t$\\begin{aligned}\\dd{}{x}\\sin{x}=\\cos{x}\\end{aligned}$ & $\\begin{aligned}\\dd{}{x}\\sec{x}=\\sec{x}\\tan{x}\\end{aligned}$ & $\\begin{aligned}\\dd{}{x}\\tan{x}=\\sec^2{x}\\end{aligned}$ \\\\\r\n\t\t\t& & \\\\\r\n\t\t\t$\\begin{aligned}\\dd{}{x}\\cos{x}=-\\sin{x}\\end{aligned}$ & $\\begin{aligned}\\dd{}{x}\\csc{x}=-\\csc{x}\\cot{x}\\end{aligned}$ & $\\begin{aligned}\\dd{}{x}\\cot{x}=-\\csc^2{x}\\end{aligned}.$\r\n\t\t\\end{tabular}\r\n\t\\end{center}\r\n\\end{table}\r\n\r\n\\begin{example}\r\n\tUse the identity $\\cos{2x} = \\cos^2{x} - \\sin^2{x}$ to find the derivative of $\\cos{2x}$. Express your answer in terms of $\\sin{2x}$. Does this answer the same as what you'd expect by finding the derivative using the chain rule?\r\n\\end{example}\r\n\\begin{answer}\r\n\tTaking the derivative of $\\cos^2{x}$,\r\n\t\\begin{equation*}\r\n\t\t\\dd{}{x}\\cos^2{x} = \\cos{x}\\cdot-\\sin{x} + \\cos{x}\\cdot-\\sin{x} = -2\\sin{x}\\cos{x} = -\\sin{2x}.\r\n\t\\end{equation*}\r\n\t\r\n\tTaking the derivative of $\\sin^2{x}$,\r\n\t\\begin{equation*}\r\n\t\t\\dd{}{x}\\sin^2{x} = \\sin{x}\\cos{x} + \\sin{x}\\cos{x} = 2\\sin{x}\\cos{x} = \\sin{2x}.\r\n\t\\end{equation*}\r\n\t\r\n\tCombining these results to get the derivative of $\\cos{2x}$,\r\n\t\\begin{equation*}\r\n\t\t\\dd{}{x}\\cos{2x} = \\dd{}{x}\\cos^2{x} - \\dd{}{x}\\sin^2{x} = -\\sin{2x} - \\sin{2x} = -2\\sin{2x}.\r\n\t\\end{equation*}\r\n\t\r\n\tThis answer is indeed the same one we'd expect using the chain rule.\r\n\\end{answer}", "meta": {"hexsha": "43d407af0b71b363f9b161889f516c47c13737e7", "size": 2284, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/derivatives_trig_functions.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/derivatives/derivatives_trig_functions.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/derivatives/derivatives_trig_functions.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 42.2962962963, "max_line_length": 230, "alphanum_fraction": 0.5788091068, "num_tokens": 915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.9099070017626536, "lm_q1q2_score": 0.838863126756603}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=1}^\\infty \\left(\\frac{2\\pi+\\cos n}{n}\\right)^n$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution}\r\n\r\nWe consider the Root Test, based on the shape of the terms. (Note that all terms are positive.)\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\left(\\frac{2\\pi+\\cos n}{n}\\right)^n \\right|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left(\\frac{2\\pi+\\cos n}{n}\\right)^n }\\\\\r\n&= \\lim_{n \\to \\infty}\\frac{2\\pi+\\cos n}{n}\r\n\\end{align*}\r\nWe cannot evaluate the limit of the sequence above using L'Hopital's rule. (Note the numerator does not go to either $0$ or $\\infty$.) Instead, we set up the following for the Squeeze Theorem. Note that\r\n\\[ -1 \\leq \\cos n \\leq 1\\]\r\nso by adding $2\\pi$ to all sides,\r\n\\[ 2\\pi-1 \\leq 2\\pi+\\cos n \\leq 2\\pi+1\\]\r\nand by dividing,\r\n\\[ \\frac{2\\pi-1}{n} \\leq \\frac{2\\pi+\\cos n}{n} \\leq \\frac{2\\pi+1}{n}\\]\r\nSince\r\n\\[ \\lim_{n \\to \\infty} \\frac{2\\pi-1}{n}  = 0 \\quad\\text{and}\\quad \\lim_{n \\to \\infty} \\frac{2\\pi+1}{n}  = 0,\\]\r\nby the Squeeze Theorem,\r\n\\[\\lim_{n \\to \\infty}\\frac{2\\pi+\\cos n}{n}=0.\\]\r\nSince $L < 1$, by the Root Test, the series $\\displaystyle \\sum_{n=1}^\\infty \\left(\\frac{2\\pi+\\cos n}{n}\\right)^n$ converges absolutely.\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "375316ab0afe1c1734743ea89ef3c5322741b26d", "size": 1957, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/k6.tex", "max_stars_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_stars_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "key/series/k6.tex", "max_issues_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_issues_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "key/series/k6.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 38.3725490196, "max_line_length": 203, "alphanum_fraction": 0.6310679612, "num_tokens": 730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.9073122176012061, "lm_q1q2_score": 0.8384851602717294}}
{"text": "\n\\subsection{Averaging regression predictions}\n\nIf we have multiple predictions, we can take an average of these, possibly weighted.\n\nWe have \\(m\\) regressors \\(g_j(\\mathbf x_i)\\).\n\nOur output is:\n\n\\(h(\\mathbf x_i)=\\sum_j w_jg_j(\\mathbf x_i)\\)\n\n", "meta": {"hexsha": "aa052622df27ae3a8d7b80cfa476f5efa2b29763", "size": 245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/ensemble/01-02-regression.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/ensemble/01-02-regression.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/ensemble/01-02-regression.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.4166666667, "max_line_length": 84, "alphanum_fraction": 0.7265306122, "num_tokens": 70, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.971129093053712, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.8384647162644175}}
{"text": "\\subsection{Definition and uniqueness}\n\nWe now define a matrix operation which in some ways plays the role\nof division. We cannot divide by a matrix, but we can multiply by the\ninverse of a matrix, which is almost as good.\n\n\\begin{definition}{The inverse of a matrix}{invertible-matrix}\n  Let $A$ and $B$ be $n\\times n$-matrices. We say that $B$ is an\n  \\textbf{inverse}%\n  \\index{inverse!of a matrix}%\n  \\index{matrix!inverse} of $A$ if\n  \\begin{equation*}\n    BA=I\\quad\\mbox{and}\\quad\n    AB=I.\n  \\end{equation*}\n  If this is the case, we also write $B=A^{-1}$. When a matrix has an\n  inverse, it is called \\textbf{invertible}%\n  \\index{matrix!invertible}%\n  \\index{invertible matrix}.\n\\end{definition}\n\n\\begin{example}{Verifying the inverse of a matrix}{verifying-inverse}\n  Let $A=\\begin{mymatrix}{rr}\n    1 & 1 \\\\\n    1 & 2\n  \\end{mymatrix}$. Check that $B=\\begin{mymatrix}{rr}\n    2 & -1 \\\\\n    -1 & 1\n  \\end{mymatrix}$ is an inverse of $A$.\n\\end{example}\n\n\\begin{solution}\n  To check this, multiply\n  \\begin{equation*}\n    AB = \\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      1 & 2\n    \\end{mymatrix} \\begin{mymatrix}{rr}\n      2 & -1 \\\\\n      -1 & 1\n    \\end{mymatrix} =\\allowbreak \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1\n    \\end{mymatrix} = I\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    BA = \\begin{mymatrix}{rr}\n      2 & -1 \\\\\n      -1 & 1\n    \\end{mymatrix} \\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      1 & 2\n    \\end{mymatrix} =\\allowbreak \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1\n    \\end{mymatrix} = I.\n  \\end{equation*}\n  This shows that $B$ is indeed an inverse of $A$.\n\\end{solution}\n\nUnlike multiplication of scalars, it can happen that $A\\neq 0$ but $A$\ndoes not have an inverse. This is illustrated in the following\nexample.\n\n\\begin{example}{A non-zero matrix with no inverse}{non-invertible-matrix}\n  Let $A=\\begin{mymatrix}{rr}\n    1 & 1 \\\\\n    1 & 1\n  \\end{mymatrix}$. Show that $A$ is not invertible.\n\\end{example}\n\n\\begin{solution}\n  One might think $A$ has an inverse because it does not equal zero.\n  However, note that\n  \\begin{equation*}\n    \\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      1 & 1\n    \\end{mymatrix} \\begin{mymatrix}{r}\n      -1 \\\\\n      1\n    \\end{mymatrix} =\\begin{mymatrix}{r}\n      0 \\\\\n      0\n    \\end{mymatrix}.\n  \\end{equation*}\n  If an inverse $A^{-1}$ existed, we would have the following:\n  \\begin{eqnarray*}\n    \\begin{mymatrix}{r}\n      -1 \\\\\n      1\n    \\end{mymatrix}\n    &=&\n        I\\begin{mymatrix}{r}\n          -1 \\\\\n          1\n        \\end{mymatrix} \\\\\n    &=&\n        (A^{-1}A) \\begin{mymatrix}{r}\n          -1 \\\\\n          1\n        \\end{mymatrix} \\\\\n    &=&\n        A^{-1}\\paren{A\\begin{mymatrix}{r}\n            -1 \\\\\n            1\n          \\end{mymatrix}} \\\\\n    &=&\n        A^{-1}\\paren{\\begin{mymatrix}{r}\n            0 \\\\\n            0\n          \\end{mymatrix}} \\\\\n    &=&\n        \\begin{mymatrix}{r}\n          0 \\\\\n          0\n        \\end{mymatrix}.\n\\end{eqnarray*}\n  This says that\n  \\begin{equation*}\n    \\begin{mymatrix}{r}\n      -1 \\\\\n      1\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r}\n      0 \\\\\n      0\n    \\end{mymatrix},\n  \\end{equation*}\n  which is impossible! Therefore, $A$ does not have an inverse.\n\\end{solution}\n\nCan a matrix have more than one inverse? It turns out that this is not\nthe case: the following theorem shows that if $A$ has an inverse, then\nthe inverse is unique. We can therefore speak of ``the'' inverse,\nrather than just ``an'' inverse, of $A$.\n\n\\begin{theorem}{Uniqueness of inverse}{unique-inverse}\n  Suppose $A$ is an $n\\times n$-matrix such that both $B$ and $C$ are\n  inverses of $A$. Then $B=C$.\n\\end{theorem}\n\n\\begin{proof}\n  By assumption, both $B$ and $C$ are inverses of $A$, so we have\n  $AB=I$, $BA=I$, $AC=I$, and $CA=I$. Using the associative and unit\n  properties of matrix multiplication, we have:\n  \\begin{equation*}\n    B = BI = B(AC) = (BA)C = IC = C.\n  \\end{equation*}\n  Therefore, $B=C$, as desired.\n\\end{proof}\n", "meta": {"hexsha": "d96a03d6dfb8f7bb244e8b5894039842884ac931", "size": 3951, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Inverses-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-Inverses-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-Inverses-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 25.6558441558, "max_line_length": 73, "alphanum_fraction": 0.583143508, "num_tokens": 1394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.9433475780765632, "lm_q1q2_score": 0.8384084525558271}}
{"text": "\n\\subsection{Divisors and Greatest Common Divisors (GCD)}\n\n\\subsubsection{Divisors}\n\nThe divisors \\(d\\) of a natural number \\(n\\) are the natural numbers such that \\(\\dfrac{n}{d}\\in \\mathbb{N}\\).\n\nFor example, for \\(6\\) the divisors are \\(1, 2, 3, 6\\).\n\nDivisors cannot be bigger than the number they are dividing.\n\n\\subsubsection{Universal divisors}\n\nFor any number \\(n \\in \\mathbb{N}^+\\):\n\n\\(\\dfrac{n}{n}=1\\)\n\n\\(\\dfrac{n}{1}=n\\)\n\nBoth \\(1\\) and \\(n\\) are divisors.\n\n\\subsubsection{Common divisors}\n\nA common divisor is a number which is a divisor to two supplied numbers.\n\n\\subsubsection{Greatest common divisor}\n\nThe greatest common divisor of \\(2\\) numbers is as the name suggests.\n\nSo \\(GCD(18,24)=6\\)\n\n", "meta": {"hexsha": "46f90eee7613428ebbe252776eaf568048217b00", "size": 708, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/GCD_LCM/01-01-GCD.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/GCD_LCM/01-01-GCD.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/GCD_LCM/01-01-GCD.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.125, "max_line_length": 110, "alphanum_fraction": 0.6949152542, "num_tokens": 210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542852576265, "lm_q2_score": 0.8740772286044094, "lm_q1q2_score": 0.8383749194620292}}
{"text": "%\n% Chapter 2.5\n%\n\n\\section*{2.5 Chain Rule}\n\n\\subsection*{Definition of the Chain Rule}\n\nIf \\(g\\) is differentiable at \\(x\\) and \\(f\\) is differentiable at \\(g(x)\\), then the composite function \\(F=f \\circ g\\) defined by \\(F(x)=f(g(x))\\) is differentiable at \\(x\\) and \\(F'\\) is given by the product \n$$F'(x)=f'(g(x)) \\times g'(x)$$\nIn Leibniz notation, if \\(y=f(u)\\) and \\(u=g(x)\\) are both differentiable functions, then\n$$ \\frac{dy}{dx}=\\frac{dy}{du}\\frac{du}{dx} $$\n\n\\subsection*{Power Rule with the Chain Rule}\n\nIf \\(n\\) is any real number and \\(u=g(x)\\) is differentiable, the \n$$\\frac{d}{dx}(u^n)=nu^{n-1}\\frac{du}{dx} \\Leftrightarrow \\frac{d}{dx}{[g(x)]}^n=n{[g(x)]}^{n-1} \\times g'(x)$$\n", "meta": {"hexsha": "3a704660eff6106b5a2a16631c1bf1f58ae753dc", "size": 697, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2-5.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/2-5.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/2-5.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.7222222222, "max_line_length": 211, "alphanum_fraction": 0.612625538, "num_tokens": 257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.9019206745523101, "lm_q1q2_score": 0.8382815194884717}}
{"text": "\\textbf{Find all the roots of $f(z) = z^8 + 15z^4 \u2212 16$ on the complex plane.}\n\n\\vspace{0.3in}\n\nIn order to use the angle to distinguish the different roots, none of them should share the same angle. To find out if this is the case we compute the roots manually, which is easily done by factorizing the polynomial\n\\begin{align*}\nz^8 + 15z^4 \u2212 16=(z-1)(z+1)(z^2+1)(z^4+16)=0.\n\\end{align*}\nHence, the roots are\n\\begin{align*}\nx_k=-1,1,\\pm i,\\sqrt{2}(1\\pm i),\\sqrt{2}(-1\\pm i).\n\\end{align*}\nand are shown in the next figure. Note that the angle can be computed as the arc tangent of quotient of the imaginary and real part of the complex roots, and its different for every root.\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.55]{prob2roots.eps}}\n\\caption{Newton's method performance.}\n\\end{figure}\n\nAfter obtaining the different roots depending on the initial guess we can plot the angle of the Newton's method solution and obtain the following fractals.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace*{\\fill}\n\\subfigure[Angle fractal]{\\includegraphics[scale=0.55]{colormap.eps}}\n\\hspace*{\\fill}\n\\subfigure[Iterations fractal]{\\includegraphics[scale=0.55]{colormap2.eps}}\n\\hspace*{\\fill}\n\\caption{Fractals obtained with Newton's method.}\n\\end{figure}\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 2\nn = 200;\n\n[x,y]=meshgrid(linspace(-3,3,n));\nz = x+y*1i;\nz_roots = [1, -1, -1i, 1i, ...\n    sqrt(2)*(1+1i),sqrt(2)*(1-1i),sqrt(2)*(-1+1i),sqrt(2)*(-1-1i)];\n\n% We now compute the roots using Newton's method:\nr = nan(size(z)); niter = r; conv = r; % allocate memory\nf = @(z) z^8+15*z^4-16;\ndf = @(z) 8*z^7+60*z^3;\nfor k = 1:n\n    for j = 1:n\n        [r(k,j),niter(k,j),conv(k,j)] = newton(f,df,z(k,j),1e-16,200);\n    end\nend\n%%\n% Plotting the angle of the Newton's method solution, we obtain a fractal:\nclose all\nfigure\npcolor(x, y, round(angle(r),3));\nmp = colormap;\ncolormap jet\nshading interp\nhold on\nplot(z_roots, 'k.','markersize',20); axis equal; axis tight; hold off;\naxis([-2 2 -2 2])\nxlabel('$\\Re(x_k)$','interpreter','latex','fontsize',labelfontsize)\nylabel('$\\Im(x_k)$','interpreter','latex','fontsize',labelfontsize)\nsaveas(gcf,'Latex/FIGURES/colormap','epsc')\n\n% Plot the number of iterations required in a colormap\nfigure\npcolor(x, y, niter);\nshading flat, hold on\nplot(z_roots, 'k.','markersize',20); axis equal; axis tight; hold off;\naxis([-2 2 -2 2])\ncolorbar\nxlabel('$\\Re(x_k)$','interpreter','latex','fontsize',labelfontsize)\nylabel('$\\Im(x_k)$','interpreter','latex','fontsize',labelfontsize)\nsaveas(gcf,'Latex/FIGURES/colormap2','epsc')\n\n% Plot the roots in the complex plane\nfigure\nplot(real(z_roots),imag(z_roots),'b.','markerSize',12)\ngrid on\naxis([-1.5 1.5 -1.5 1.5])\nset(gca,'fontsize',axisfontsize)\nxlabel('$\\Re(x_k)$','interpreter','latex','fontsize',labelfontsize)\nylabel('$\\Im(x_k)$','interpreter','latex','fontsize',labelfontsize)\nsaveas(gcf,'Latex/FIGURES/prob2roots','epsc')\n\\end{verbatim}", "meta": {"hexsha": "016d7445c033eb33b82d0217d3943bc8c073366d", "size": 2980, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 4/Latex/problem2.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 4/Latex/problem2.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 4/Latex/problem2.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0588235294, "max_line_length": 217, "alphanum_fraction": 0.6946308725, "num_tokens": 989, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.9252299514223379, "lm_q1q2_score": 0.8382489081083303}}
{"text": "\\section{Linear Equations with Constant Equations}\n\n\\subsection{Auxiliary Equation}\n\nLinear homogeneous DE with constant coefficients can be expressed as\n\n\\begin{equation}\n    a_{0} \\frac{d^{n} y}{d x^{n}}+a_{1} \\frac{d^{n-1} y}{d x^{n-1}}+\\cdots+a_{n-1} \\frac{d y}{d x}+a_{n} y=0\n\\end{equation}\n\nCan be written in the form\n\n\\begin{equation}\n    f(D)y=0\n\\end{equation}\n\nwhere $f(D)$ is a linear differential operator. If the algebraic eqn $f(m)=0$\nthen we know $f(D)e^{mx}=0\\implies y=e^{mx}$ is a solution to the form above.\n$f(m)=0$ is the auxiliary equation associated with the DE.\nSince the DE is of order $n$, the auxiliary equation is of degree $n$ with\nroots $m_1,\\ldots,m_n$.\n\nThus we have $n$ solutions $y_1=\\exp(m_1x),\\ldots,y_n=\\exp(m_nx)$ assuming\nthe roots are \\textbf{real} and \\textbf{distinct} are then \\textbf{linearly independent}.\nThe general solution is thus\n\n\\begin{equation}\n    y=c_1\\exp(m_1x)+\\cdots+c_n\\exp(m_nx)\n\\end{equation}\n\nwith arbitrary constants $c_1,\\ldots,c_n$.\n\n\\subsubsection{Derivation}\n\nWe can say that $y^{(k)}$ is the $k$th derivative of $y$, so say the general form is\n\n$$\na_ny^{(n)}+a_{n-1}y^{(n-1)}+\\cdots+a_1y^\\prime +a_0y=0\n$$\n\nIf we take $y=e^{rx}$, then observe $y^{(n)}=r^ne^{rx}$. So rewrite the general form as\n\n\\begin{align*}\n    a_nr^ne^{rx}+a_{n-1}r^{n-1}e^{rx}+\\cdots+a_1re^{rx}+a_0e^{rx}&=0\\\\\n    a_nr^n+a_{n-1}r^{n-1}+\\cdots+a_1r+a_0&=0\n\\end{align*}\n\nSolving for the roots $r$ in this characteristic equation helps us obtain the general solution.\n\n\\subsection{Auxiliary Equation Repeated Roots}\n\nNeed method for obtaining $n$ linearly independent solutions for $n$ equal roots of auxiliary equation.\nSuppose auxiliary equation $f(m)=0$ has $n$ roots $m_1=m_2=\\cdots=m_n=b$.\nThus, the operator function $f(D)$ has a factor $(D-b)^n$. Want to find $n$ linearly independent $y$ for which $(D-b)^ny=0$.\nUse the substitution $y_k=x^ke^{bx}$ such that\n\n\\begin{equation}\n    (D-b)^n(x^ke^{bx})=0,\\;k=0,1,2,\\ldots,n-1\n\\end{equation}\n\nThe functions $y_k=x^ke^{bx}$ are linearly independent because the respective powers $x^0,\\ldots,x^k$ are linearly independent.\nSo the general solution takes form\n\n\\begin{equation}\n    y=c_1e^{bx}+c_2xe^{bx}+\\cdots+c_nx^{n-1}e^{bx}\n\\end{equation}", "meta": {"hexsha": "bc97a2238e876e50b3dc20e57fe4cbbc48324795", "size": 2229, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "differential-equations/tex/unit-3.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "differential-equations/tex/unit-3.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "differential-equations/tex/unit-3.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7727272727, "max_line_length": 127, "alphanum_fraction": 0.6922386721, "num_tokens": 808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766224, "lm_q2_score": 0.8918110382493034, "lm_q1q2_score": 0.838225095869615}}
{"text": "\\chapter{Probability}\n\n\n\\section{Shuffle}\nEqual probability shuffle algorithm.\n\n\\subsection{Incorrect naive solution}\nSwap current card $A_i$ with a random card from the deck. \n\\begin{java}\nfor (int i = 0; i < N; i++) {\n   int j = (int) Math.random()*N;\n   swap(a[i], a[j]);\n}\n\\end{java}\nThe easiest proof that this algorithm does not produce a uniformly random permutation is that it generates 27 possible outcomes, but there are only 3! = 6 permutations. Since $27\\%3 \\neq 0$, there must be some permutation is that is picked too much, and some that is picked to little.\n\\subsection{Knuth Shuffle}\nKnuth (aka Fisher-Yates) shuffling algorithm guarantees to rearrange the elements in uniformly random order. \n\\\\\nCore clues:\n\\begin{enumerate}\n\\item choose index uniformly $\\in [i, N)$\n\\end{enumerate}\n\\begin{java}\npublic void shuffle(Object[] a) {\n    int N = a.length;\n    for (int i = 0; i < N; i++) {\n        // choose index uniformly in [i, N)\n        int j = i + (int) (Math.random() * (N - i));\n        swap(a[i], a[j]);\n    }\n}\n\\end{java}\n\n\\section{Expected Value}\n\\subsection{Roll dice until expected value.}\n\n", "meta": {"hexsha": "a52a3ab9d23aceed93370aec2b79c7080f1c7358", "size": 1118, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterProbability.tex", "max_stars_repo_name": "li77leprince/Algo-Quicksheet", "max_stars_repo_head_hexsha": "1736bc0ee1d73b0b06dcf3823a65ea0f8c286108", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapterProbability.tex", "max_issues_repo_name": "li77leprince/Algo-Quicksheet", "max_issues_repo_head_hexsha": "1736bc0ee1d73b0b06dcf3823a65ea0f8c286108", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapterProbability.tex", "max_forks_repo_name": "li77leprince/Algo-Quicksheet", "max_forks_repo_head_hexsha": "1736bc0ee1d73b0b06dcf3823a65ea0f8c286108", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.2162162162, "max_line_length": 284, "alphanum_fraction": 0.6815742397, "num_tokens": 307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.914900952092573, "lm_q1q2_score": 0.8381495535031566}}
{"text": "\\section{Motivation: from finite element to neural network}\\label{FE2NN}\nIn this section, we will introduce the so-called shallow neural network \n(deep neural network with one hidden layer) from the viewpoint of finite element method.\n\nLet us recall the linear finite element functions on the unit interval $\\bar{\\Omega}=[0,1]$ in Section \\ref{linearFE}. \nConsider a set of equidistant girds $\\mathcal T_\\ell$ of level $\\ell$ and mesh length $h_\\ell = 2^{-\\ell}$. The grid points $x_{\\ell,i}$ are given by\n\\begin{equation}\nx_{\\ell,i}:=ih_\\ell,\\quad 0\\le i\\le 2^\\ell.\n\\end{equation} \nFor $\\ell=1$, we denote the special hat function by $\\varphi(x)$ and any nodal basis function in \\eqref{1dbasis:function} on grid $\\mathcal T_\\ell$ by $\\varphi_{\\ell,i} $ as below\n\\begin{equation}\\label{def_g}\n\\varphi(x) = \n\\begin{cases}\n2x \\quad &x\\in [0,\\frac{1}{2}] \\\\\n2(1-x) \\quad &x\\in [\\frac{1}{2}, 1] \\\\\n0, \\quad &\\text{others} \n\\end{cases},\\qquad\n\\varphi_{\\ell,i} = \\varphi(\\frac{x - x_{\\ell,i-1}}{2h_\\ell}) = \\varphi(w_\\ell x + b_{\\ell,i}).\n\\end{equation} \nThat is to say, any $\\varphi_{\\ell,i}(x)$ can be obtained from $\\varphi(x)$ by scaling \n(dilation) and translation with \n\\begin{equation}\\label{key}\nw_\\ell = 2^{\\ell-1}, \\quad b_{\\ell,i} = \\frac{-(i-1)}{2},\n\\end{equation}\nin $\\varphi_{\\ell,i} = \\varphi(w_\\ell x + b_{\\ell,i})$. \n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=4cm]{1dbasis1.pdf}\\qquad\n\\includegraphics[width=5cm]{basisfunction.pdf}\n\\caption{Diagram of $\\varphi(x)$ (left) and $\\varphi_{\\ell,i}(x)$ (right).}\n\\end{figure} \n\n\nLet us recall the finite element interpolation in Section \\ref{linearFE} as\n\\begin{equation}\\label{key}\nu(x) \\approx u_\\ell(x) := \\sum_{ 0\\le i \\le 2^\\ell} u(x_{\\ell,i}) \\varphi_{\\ell,i}(x),\n\\end{equation}\nfor any smooth function $u(x)$ on $(0,1)$. The above interpolation will converge as $\\ell \\to \\infty$, which shows that\n\\begin{equation}\\label{key}\n{\\rm span} \\left\\{  \\varphi(w_\\ell x + b_{\\ell,i}) \\right\\} \\quad \\text{is dense in} \\quad H^1(0,1).\n\\end{equation}\nThus, we may have the next concise relation:\n\\begin{equation}\\label{key}\n\\begin{split}\n\\text{FE space} =  &{\\rm span} \\left\\{  \\varphi(w_\\ell x + b_{\\ell,i}) ~|~ 0\\le i \\le 2^\\ell, \\ell = 1, 2, \\cdots \\right\\} \n\\\\\n\\subset  &{\\rm span} \\left\\{  \\varphi(w x + b) ~|~  w, b \\in \\mathbb{R} \\right\\}.\n\\end{split}\n\\end{equation}\nIn other words, the finite element space can be understood as the linear combination of $\\varphi(w x + b)$ with certain special choice of $w$ and $b$. \n\nHere, we need to point out that this ${\\rm span} \\left\\{  \\varphi(w x + b) ~|~  w, b \\in \\mathbb{R} \\right\\}$ is exact the deep neural networks with one hidden layer (shallow neural networks) with activation function $\\varphi(x)$. More precisely, \n\\begin{equation}\\label{key}\nf \\in {\\rm span} \\left\\{  \\varphi(w x + b) ~|~  w, b \\in \\mathbb{R} \\right\\},\n\\end{equation}\nmeans there exist positive integer $N$ and $w_j, b_j \\in \\mathbb{R}$ such that \n\\begin{equation}\\label{key}\nf = \\sum_{j=1}^N a_j \\varphi(w_j x + b_j),\n\\end{equation}\nwhich is also called one hidden neural network function with $N$ neurons.\n\n\\begin{remark}\n\t\\begin{enumerate}\n\t\t\\item By making $w_\\ell$ and $b_{\\ell,i}$ in \\eqref{def_g} arbitrary, we get a much larger class of \n\t\tfunction which is exact a special neural network with activation function $\\varphi(x)$.\n\t\t\\item Generalizations: \n\t\t\\begin{enumerate}\n\t\t\t\\item activation function $\\varphi$ can be different, such as ${\\rm ReLU}(x) = \\max\\{0,x\\}$.\n\t\t\t\\item There is a natural extension for high dimension $d$ as\n\t\t\t\\begin{equation}\\label{key}\n\t\t\t\\left\\{  \\varphi(w\\cdot x + b) \\right \\},\n\t\t\t\\end{equation}\n\t\t\twhere $w\\in \\mathbb{R}^d$, $b\\in \\mathbb{R}$ and $\\displaystyle w\\cdot x = \\sum_{i=1}^d w_i x_i$.\n\t\t\tThis is called ``deep'' neural network with one hidden layer.\n\t\t\\end{enumerate}\n\t\\end{enumerate}\n\\end{remark}\n\n\n%\\input{3FEM/2dFEM}\n", "meta": {"hexsha": "a8b047d332bfb2433fa25172e9df97a7580804b6", "size": 3863, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/7 Deep Neural network Functions/7.1-FEM2DNN.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/7 Deep Neural network Functions/7.1-FEM2DNN.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/7 Deep Neural network Functions/7.1-FEM2DNN.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.6913580247, "max_line_length": 247, "alphanum_fraction": 0.6733108983, "num_tokens": 1372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.8976952927915968, "lm_q1q2_score": 0.837936446870219}}
{"text": "\\section{Mathematical Preliminaries}\n\\subsection{Directed Graph}\nA directed graph $\\mathcal{G}$, consists of a pair of finite sets, $(\\emph{V},\\emph{E})$. The elements of $\\emph{V}$ are the vertices and the elements of $\\emph{E}$ are the edges. An edge is a set formed by pairs of vertices. Further to this, there is a function, $\\tau$, that associates an ordered pair of vertices for each edge in $\\emph{E}$. The direction of an edge $\\emph{e} = \\{v_1, v_2\\}$, is said to be $\\tau(\\emph{e}) = (v_1, v_2)$, where $\\tau_{1}(e) = v_1$ is the source vertex and $\\tau_{2}(e) = v_2$ is the target vertex. \n\nWith our definitions, there comes a constraint for the function $\\tau$. \n\\begin{itemize}\n\\item There are no self-loops, that is for each $\\emph{e} \\in \\emph{E}$, if $\\tau(\\emph{e}) = (v_1, v_2)$ then $v_1 \\neq v_2$.\n\\end{itemize}\n\nThere may exist neurons that are reciprocally connected, that is, there may be edges whereby we have $\\emph{e}, \\emph{e}^\\prime \\in \\emph{E}$ such that $\\tau(\\emph{e})=(v_1,v_2)$ and $\\tau(\\emph{e}^\\prime) = (v_2,v_1)$.\n\nA vertex $\\emph{v} \\in \\mathcal{G}$ is said to be a sink if there exists no $\\emph{e} \\in \\emph{E}$ such that $\\emph{v}=\\tau_1(\\emph{e})$, but there is at least one edge $\\emph{e}^\\prime \\in \\emph{E}$ such that $\\tau_2(\\emph{e}^\\prime) = \\emph{v}$. Similarly, \\emph{v} is said to be a source if there exists no $\\emph{e} \\in \\emph{E}$ such that $\\emph{v} = \\tau_2(\\emph{e})$, but there is at least one $\\emph{e}^\\prime \\in \\emph{E}$ such that $\\tau_1(\\emph{e}^\\prime) = \\emph{v}$. \n\nA path in a directed graph consists of a sequence of edges $(e_1, e_2, ..., e_n)$ such that for all $1 \\leq k \\leq n$, the target of $e_k$ is $e_{k+1}$, i.e.~$\\tau_2(\\emph{e}_k) = \\tau_1(\\emph{e}_{k+1})$. The length of the path $(e_1, e_2, ..., e_n)$ is n. \n\nIf the target of $e_n$ is the source of $e_1$, that is $\\tau_2(\\emph{e}_n) = \\tau_1(\\emph{e}_1)$, then $(e_1, ..., e_n)$ is an oriented cycle. A directed graph that contains no oriented cycle is said to be acyclic.\n\nA directed graph is said to be fully connected if for every pair of distinct vertices, there exists a path from one to the other, in at least one direction.\n\\subsection{Simplices}\nThe singular of simplices is simplex. A simplex is a generalisation of the notion of a point, a line, a triangle up to some arbitrary dimension. The simplex is named as such since it is the simplest possible polytope in any given space.\n\nWe have, for example, the following possible simplices:\n\n\\begin{itemize}\n    \\item A 0 simplex which consists of a vertex.\n    \\item A 1 simplex which consists of two vertices and an edge with direction.\n    \\item A 2 simplex which consists of three vertices and three edges all having direction. There is also a clear source and a clear sink. An example is given below.\n    \\item A 3 simplex consists of 4 vertices and 6 edges all having direction and where we have a clear source and a clear sink.\n\\end{itemize}\nTo generalise this, a k-simplex is the convex hull of the k+1 vertices it contains \\cite{2018}. \n\\begin{figure}[H]%\n    \\centering\n    \\captionsetup{justification=centering}\n    \\subfloat[\\centering 0 Simplex]{{\\includegraphics[width=3cm]{graph/0simplex.png} }}%\n    \\qquad\n    \\subfloat[\\centering 1 Simplex]{{\\includegraphics[width=3cm]{graph/1simplex.png} }}%\n    \\qquad\n    \\subfloat[\\centering 2 Simplex]{{\\includegraphics[width=3cm]{graph/2simplex.png} }}%\n    \\qquad\n    \\subfloat[\\centering 3 Simplex]{{\\includegraphics[width=3cm]{graph/3simplex.png} }}%\n    \\caption{Simplices from dimension 0 through to 3}%\n    \\label{fig:example}%\n\\end{figure}\n\n\\subsection{Simplicial Complex}\nAn abstract simplicial complex $\\emph{S}$, is a collection of finite sets. These sets are closed under taking subsets, that is, every subset of a set in the family is also in the family. As an example, in a 2 dimensional simplicial complex, we have triangles, which are sets of size 3, their edges, which are sets of size 2 and their vertices which are sets of size 1 \\cite{2008Gregarxiv:0809.4221}.\n\nHowever, we have a slight variation on this in that we have an abstract $\\emph{directed}$ simplicial complex. This is where we again have a collection of sets denoted $\\emph{S}$. However, this time, the sets are finite and ordered with the property that if $\\sigma \\in \\emph{S}$, then every subset $\\tau$ of $\\sigma$, with the natural ordering inherited from $\\sigma$, is also a member of $\\emph{S}$.\n\nThe elements $\\sigma$ of a simplicial complex, as mentioned before, are simplices. The set of all simplices of $\\emph{S}$ is denoted $\\emph{S}_n$. A simplex $\\tau$ is said to be a face of $\\sigma$ if $\\tau$ is a subset of $\\sigma$ with a strictly smaller cardinality than $\\sigma$. As an example, lets take Figure 3(c). This shows a simplex $\\sigma$ of dimension 2, however, we can also consider the edge from vertex 1 to vertex 3 as a face of the 2 dimensional simplex, since this is defined using $\\tau$(e) = ($v_1, v_3$) where $\\tau$ is a subset of $\\sigma$. \n\nThese simplices may be joined along these faces. A simplex that is not the face of any other simplex is said to be maximal. Again, with the 2-simplex above, we can see that the maximal dimension of this is 2, and that the edges and vertices that construct this object are faces of the 2-simplex and faces of faces of the 2-simplex respectively. Thus, the set of all maximal simplices of a simplicial complex determines the entire simplicial complex since this is made up entirely of maximal simplicial complexes or a face of a simplicial complex.\n\n\\subsection{Simplicial Complex applied to Directed Graphs}\nThe directed graph $\\mathcal{G}$ naturally creates the directed simplicial complex. The directed simplicial complex that is associated to the directed graph $\\mathcal{G}$ is called the directed flag complex of $\\mathcal{G}$. \n\nThe directed flag complex is defined to be the ordered simplicial complex whose n-simplices are all ordered (n+1)-cliques. So, let it be that $\\sigma = (v_0, v_1, ...v_n)$, such that $v_i \\in \\emph{V}$ $\\forall i$ and ($v_i, v_j) \\in \\emph{E}$ for $i < j$. Then the ordered set of these completes the directed flag complex. Further to this, we note that $v_0$ is the initial vertex, or the source of $\\sigma$, and that $v_n$ is the final or sink of $\\sigma$. \n\nOne final thing of note is that because of our assumption on $\\tau$, an n-simplex in $\\emph{S}$ is characterised by the ordered sequence $(v_o, v_1, ..., v_n)$ and not by the vertices. By example, $(v_0, v_1, v_2)$ and $(v_0, v_2, v_1)$ are two distinct 2-simplices that contain the same set of vertices.\n\n\\subsection{Directionality}\nThe directionality \\cite{Reimann_2017} of a directed graph $\\mathcal{G}$ is given by:\n\\begin{equation}\n    \\Dr(\\mathcal{G}) = \\sum_{v \\in V} \\sd(\\emph{v})^2 \\enspace{,}\n\\end{equation}\nwhere\n\\begin{equation}\n    \\sd(\\emph{v}) = \\Indeg(\\emph{v}) - \\outd(\\emph{v})\\enspace{.}\n\\end{equation}\nIn words, the signed degree ($\\sd$) is given as the in-degree minus the out-degree for each vertex in $\\mathcal{G}$. Following on from this, the directionality of $\\mathcal{G}$ is the sum of the squares of all the signed degrees for each vertex in the directed graph $\\mathcal{G}$. \n\nFurther to this, we can note that the sum of the signed degree for a finite graph is zero. That is,\n\\begin{equation}\n    \\sum_{v \\in \\mathcal{G}}\\sd(\\emph{v}) = 0 \\enspace{.}\n\\end{equation}\n\\subsection{Homology}\nSimplicial homology arose as a way to study topological spaces. The building blocks of which are our n-simplices. On top of this, we have further numerical quantities in order to describe the abstract directed flag complex. These include Betti numbers and the Euler Characteristic. These are described below. \n\\subsection{Euler Characteristic}\nThe Euler Characteristic is simply defined as the alternating sum of the number of simplices in each dimension. This can also be applied to Betti numbers in each dimension, however, for the Betti numbers for our models and even the Erdos-Renyi model in dimensions 1 through 3,  this is not computationally viable since the required memory to compute the Betti numbers in these dimensions is upwards of 16GB. \n\nSo, algebraically, the Euler Characteristic is given as follows:\n\\begin{equation*}\n    \\chi = k_0 - k_1 + k_2 - k_3 + ... \n\\end{equation*}\n\\begin{equation}\n    \\Rightarrow \\chi = \\sum_{k \\geq 0} (-1)^k \\abs{S_k} \\enspace{.} \n\\end{equation}\nAs a side note, there is a close relationship between the Euler Characteristic and Betti numbers \\cite{Reimann_2017}, that are defined in the next section. This relationship is as follows:\n\\begin{equation}\n    \\chi(\\emph{S}) = \\sum_{k\\geq 0}(-1)^k \\beta_{k}(\\emph{S})\n\\end{equation}\n\n\n\\subsection{Betti Numbers}\nInformally, the $k^{th}$ Betti number refers to the number of k-dimensional holes on a topological space, where a k-dimensional hole is a k-dimensional cycle that is not a boundary of a (k+1)-dimensional object. \n\nThe definitions of the first few Betti numbers are as follows;\n\\begin{itemize}\n    \\item $\\beta_0$ is the number of connected components\n    \\item $\\beta_1$ is the number of 1-dimensional or `circular' holes.\n    \\item $\\beta_2$ is the number of 2-dimensional `voids' or `cavities'.\n\\end{itemize}\nBy example, lets take our triangular prism in Figure 4. We can see that the vertices are all connected as one object. This, as well as with the Bio-M MC, takes the zeroth Betti number to be 1. That is, $\\beta_0 = 1$. Next, we take the informal definition of the 1-dimensional Betti number. We can see here that there are no holes that are of dimension 1, so $\\beta_1 = 0$. Finally, we look at the second dimensional definition of a Betti number. We are looking for holes or cavities that are entirely enclosed by 2-dimensional objects. We can see that we have a hole that is enclosed by triangles. Therefore, $\\beta_2 = 1$. Applying the Euler Characteristic to the Betti numbers of this example, we have,\n\\begin{equation}\n    \\beta_0 - \\beta_1 + \\beta_2 = 1 - 0 + 1 = 2\n\\end{equation}\nSo if we take the classical usage of the Euler characteristic, we can see the relationship, as stated above in the Euler characteristic section, is also 2 as follows:\n\\begin{equation}\n    V - E + F = 6 - 8 + 12 = 2\n\\end{equation}\n\n\\begin{figure}[H]%\n    \\centering\n    \\captionsetup{justification=centering}\n{{\\includegraphics[width=12cm]{graph/simplex_structure.png} }}%\n    \\caption{Triangular Prism}\n    \\label{fig:example}%\n\\end{figure}\n\nNow, informally, let $\\mathbb{F}_2$ denote a field of two elements. Let S be a simplicial complex. Define the chain complex C*(S, $\\mathbb{F}_2$) to be the sequence ($C_n$ = $C_n$(S,$\\mathbb{F}_2$))$_{n\\geq0}$, such that $C_n$ is the $\\mathbb{F}_2$-Vector space whose basis elements are the n-simplices $\\sigma \\in  S_n$, for each $n\\geq0$. In other words, the elements of $C_n$ are formal sums of n-simplices in S. \n\nFor each $n\\geq1$, there is a linear transformation called a \\textit{differential}.\n\\begin{equation}\n    \\partial_n : C_n \\rightarrow C_{n-1} \\enspace{.}\n\\end{equation}\nspecified by $\\partial_n(\\sigma) = \\sigma^0 + \\sigma^1 + ... + \\sigma^n$ for every n-simplex $\\sigma$, where $\\sigma^i$ is the $i^{th}$ face of $\\sigma$. Having defined $\\partial_n$ on the basis, one then extends it linearly to the entire vector space $C_n$. The $n^{th}$ Betti number $\\beta_n$(S) of a simplicial complex S is the $\\mathbb{F}$2-vector space dimension of its $n^{th}$ mod-2 homology group, which is defined by,\n\\begin{equation}\n    \\mathbb{H}_n(S, \\mathbb{F}_2) = \\frac{\\Ker(\\partial_n)}{ \\ime(\\partial_{n+1})} \\enspace{,}\n\\end{equation}\nfor  $n\\geq 1$ and\n\\begin{equation}\n    \\mathbb{H}_0(S, \\mathbb{F}_2) = C_0/\\ime(\\partial_{1}) \\enspace{.}\n\\end{equation}\nFor all $n\\geq1$, there is an inclusion of vector subspaces i.e.~$\\ime(\\partial_{n+1}) \\subseteq \\Ker(\\partial_{n}) \\subseteq C_n$, and thus the definition of homology makes sense.\n\nComputing Betti numbers of a simplicial complex is conceptually very easy. Let $|S_n|$ denote the number of n-simplices in the simplicial complex S. If one encodes the differential $\\partial_{n}$ as a $(|S_n-1| \\times |S_n|)$-matrix $D_n$ with entries in $\\mathbb{F}_2$, then one can easily compute its \\textit{nullity}, null($\\partial_n$), and its rank, rk($\\partial_n$), which are the $\\mathbb{F}_2$ dimensions of the null-space and the column space of $D_n$ respectively. The Betti numbers of S are then a sequence of natural numbers defined by,\n\\begin{equation}\n    \\beta_0(S) = \\text{dim}_{\\mathbb{F}_2}(C_0) - \\text{rk}(\\partial_1) \\enspace{,}\n\\end{equation}\n\\begin{equation}\n    \\beta_{n}(S) = \\text{null}(\\partial_{n}) - \\text{rk}(\\partial_{n+1}) \\enspace{.}\n\\end{equation}\n    \nSince Im($\\partial_{n+1}$) $\\subseteq$ Ker($\\partial_n$) for all $n\\geq 1$, the Betti numbers are always non negative. The $n^{th}$ Betti number $\\beta_n$ gives an indication of the n-dimensional cavities in the geometric realisation of S \\cite{Reimann_2017}.\n\n\\subsection{Blocks}\nWithin the MC we have a set of neurons and a set of synapses, represented by vertices and directed edges respectively. Now, when we take into account the direction of information flow, an edge has with it a pair of ordered vertices. \n\nNow, when we subdivide the MC on a layer by layer basis, we are left with 25 subsets of ordered pairs of vertices, each belonging to a ``block''. An example of a block is L1-L4. That is, we have a set of ordered vertices where the pre-synaptic neurons set is from Layer 1 and the post-synaptic neurons are from Layer 4. \n\nThis is not to say that there are a specific set of neurons that are pre-synaptic or post-synaptic, but rather, the neuron's state is determined by the order in which it appears in the ordered pair $\\emph{e}$.\n\n\n\\subsection{Total Variation distance}\nHere, we use the Total Variation (TV) distance to quantify statistical differences between distributions obtained from our models.\n\nLet $f$ and $g$ be two discrete distributions over a common support set $\\{1,2,\\ldots,n\\}$.\nThus, $\\sum_{i=1}^{n}f_{i} = 1$ and $\\sum_{i=1}^{n}f_{i} = 1$.\n\nTypically, we want to compare distribution $f$ obtained from a model with the distribution $g$ obtained from the Bio-M MC. To compare the distance between these two distributions, we take:\n\\begin{equation}\n\\delta(f, g) = \\sum_{i=1}^{n}(|f_{i} - g_{i}|)\\enspace{.}\n\\end{equation}\n\nThis will output a value in the range $[0, 2]$. \nClearly $\\delta(f, g)=0$ if $f=g$ and $\\delta(f, g)=2$ if $f$ and $g$ have no common events.", "meta": {"hexsha": "a49d0e6d959164f9444aeb5712188478741eb5fb", "size": 14486, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2020UUMScKieranBarber/tex_files/mathematicalPreliminaries.tex", "max_stars_repo_name": "lamastex/working-manuscript-TopologicalDataAnalysisOnABrainNetwork", "max_stars_repo_head_hexsha": "c43b0a79e6d17a069b3d1297a7de248a01050045", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2020UUMScKieranBarber/tex_files/mathematicalPreliminaries.tex", "max_issues_repo_name": "lamastex/working-manuscript-TopologicalDataAnalysisOnABrainNetwork", "max_issues_repo_head_hexsha": "c43b0a79e6d17a069b3d1297a7de248a01050045", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-02-12T15:21:35.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-12T15:51:42.000Z", "max_forks_repo_path": "2020UUMScKieranBarber/tex_files/mathematicalPreliminaries.tex", "max_forks_repo_name": "lamastex/working-manuscript-TopologicalDataAnalysisOnABrainNetwork", "max_forks_repo_head_hexsha": "c43b0a79e6d17a069b3d1297a7de248a01050045", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 87.265060241, "max_line_length": 704, "alphanum_fraction": 0.7226977772, "num_tokens": 4385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.8947894703109854, "lm_q1q2_score": 0.8377779643534019}}
{"text": "\\section{Gaussian Quadrature}\n\\subsection{Legendre Polynomial}\n\\begin{theo}\nSuppose $x_1,x_2\\ldots,x_n$ are the roots of the $n$th Legendre polynomial $P_n(x)$ and that for $i=1,2,\\ldots,n$ the number $C_i$ are defined by\n\\[\nC_i = \\int_{-1}^1\\prod_{j=1\\atop j\\neq i}^n\\left(\\frac{x-x_j}{x_i-x_j}\\right)\\D x.\n\\]\nIf $P(x)$ is any polynomial of degree less than $2n$, then\n\\[\n\\int_{-1}^1P(x)\\D x = \\sum_{i=1}^nC_iP(x_i)\n\\]\n\\end{theo}\n\n\\begin{proof}\n\\begin{enumerate}[(1)]\n    \\item $P(x)$ is of degree less than $n$.\n        \\begin{align*}\n        \\int_{-1}^1P(x)\\D x &= \\int_{-1}^1\\sum_{i=1}^{n}P(x_i)L_i(x)\\D x = \\int_{-1}^1\\sum_{i=1}^n\\prod_{j=1\\atop j\\neq i}^n\\left(\\frac{x-x_j}{x_i-x_j}\\right)P(x_i)\\D x\\\\\n        &= \\sum_{i=1}^n\\left[\\int_{-1}^1\\prod_{j=1\\atop j\\neq i}^n\\left(\\frac{x-x_j}{x_i-x_j}\\right)\\D x\\right]P(x_i) = \\sum_{i=1}^nC_iP(x_i).\n        \\end{align*}\n    \\item $P(x)$ is of degree at least $n$ but less than $2n$.\n        \\begin{align*}\n        P(x_i)=Q(x_i)P_n(x_i)+R(x_i)=R(x_i)\\quad\\text{(degree less than $n$)}.\n        \\end{align*}\n\\end{enumerate}\n\\end{proof}\n\n\\subsection{Gaussian Quadrature on Arbitrary Intervals}\nAn integral $\\int_a^bf(x)\\D x$ over an arbitrart $[a,b]$ can be transformed into an integral over $[-1,1]$\n\\[\n\\int_a^bf(x)\\D x = \\int_{-1}^1f\\left(\\frac{(b-a)t+(b+a)}{2}\\right)\\frac{(b-a)}{2}\\D t.\n\\]\n", "meta": {"hexsha": "df170fadd9a0e93c264b58f3aa6963c501594622", "size": 1343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/4.7_Gaussian_quadrature.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/4.7_Gaussian_quadrature.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/4.7_Gaussian_quadrature.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.696969697, "max_line_length": 170, "alphanum_fraction": 0.60908414, "num_tokens": 584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816423, "lm_q2_score": 0.894789454880027, "lm_q1q2_score": 0.8377779546780828}}
{"text": "\\chapter{Mathematic Core Functions(MathCore)}\n\\section{logistic() and logit()}\n\\noindent Formula:\n\n$$logistic(x,x0,L,k)=\\frac{L}{1+e^{-k(x-x0)}}$$\n$$logistic(x)=\\frac{1}{1+e^{-x}}$$\n$$logit(x)=\\ln(\\frac{x}{1-x})$$\n\n\\noindent Defination:\n\\begin{lstlisting}\ntemplate<typename T>\ninline T logistic(T x, T x0 , T L = 1, T k = 1);\n\ninline double logistic(double x);\n\ninline double logit(double x);\n\\end{lstlisting}\n\n\\section{softmax() and sigmoid()}\n\\noindent Formula:\n\n$$softmax(\\mathbf{x})=\\frac{e^{x_i}}{\\sum e^{x_k}}$$\n$$sigmoid(x_i)=\\frac{1}{1+e^{-x_i}}$$\n\nOne can see that sigmoid function is simply element-wise logistic function.\n\n\\noindent Defination:\n\\begin{lstlisting}\ntemplate<typename EigenV>\ninline EigenV softmax(EigenV x);\n\ntemplate<typename EigenV>\ninline EigenV sigmoid(EigenV x);\n\\end{lstlisting}\n", "meta": {"hexsha": "6d0dee1a82ebd57d584b72be3ec4aa3101e24f93", "size": 811, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/MathCore.tex", "max_stars_repo_name": "kilasuelika/SciStaLib", "max_stars_repo_head_hexsha": "103a75e6a433c2b873abb7ecd4da675028b782db", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Documentation/MathCore.tex", "max_issues_repo_name": "kilasuelika/SciStaLib", "max_issues_repo_head_hexsha": "103a75e6a433c2b873abb7ecd4da675028b782db", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Documentation/MathCore.tex", "max_forks_repo_name": "kilasuelika/SciStaLib", "max_forks_repo_head_hexsha": "103a75e6a433c2b873abb7ecd4da675028b782db", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1714285714, "max_line_length": 75, "alphanum_fraction": 0.6966707768, "num_tokens": 256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611643025386, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.8377685452029684}}
{"text": "\\lab{Algorithms}{Nested and Lambda Functions}{Nested and Lambda Functions}\n\n\\objective{Learn about nested and lambda functions}\n\n\\section*{Nested functions}\nSo far all the functions we have been defining are called \\emph{global} functions.  This means that these functions are accessible to any program that imports your module.  In Python, it is possible to define nested functions (functions inside of functions).  Nested functions are called \\emph{local} functions.  They have access to all the variables that the parent function has, but they are not accessible outside of the parent function.  Consider an example where you reuse a specific block of code many times inside a single function.  This block of code would be a good candidate for a nested function.  Nested functions, and functions in general, must be defined before they are called. Realize that nested functions do have overhead, so only use them when necessary.  Here's an example of pseudocode for Newton's Method:\n\n\\begin{lstlisting}\ndef NewtonsMethod(f,x0):   \n    def derivative(f):\n        #Our nested function is defined first.\n        #It is usally good practice to define\n        #your functions as early as possible\n\n        #calculate derivative of f\n        return derivative\n    \n    #Perform Newton's Method\n    #we need the deriviative of f\n    df = derivative()\n\n    #more calculations\n    return roots\n\\end{lstlisting}\n\nOur nested function \\li{derivative} has access to the variables \\li{f} and \\li{x0}.  Even though we have access to \\li{f}, it would still be a good idea to define our nested to function to take one argument, \\li{f}.  Our nested function \\li{derivative} however, is not accessible outside of \\li{NewtonsMethod}.\n\n\\section*{Lambda Functions}\nA lambda function allows us to create simple, one expression functions. The syntax is illustrated by this example.  Lambda functions are defined as \\emph{lambda} functions.\n\n\\begin{lstlisting}\n: from math import sin, cos\n: sincos = lambda x: sin(x) + cos(x)\n\\end{lstlisting}\n\nNow we can find the value of $\\sin(x) + \\cos(x)$ by simply typing \\li{sincos(x)}.\n\nOftentimes in real applications we are attempting to do operations on a function. Examples would include root finding, minimization, integration or solving differential equations. Python allows you to pass entire functions as arguments to another function.  If you recall in the beginning of this book, our timing context is a function that accepts another function as input.  Define the following function in Python.\n\\begin{lstlisting}\n: def myFunc(a,b):\n....: return a**b\n: myFunc\n<function myFunc at 0x8b33f44>\n: m = lambda x, y: x**y\n: m\n<function <lambda> at 0x8b45534>\n\\end{lstlisting}\n\nNotice how lambda functions are much more compact. We are essentially defining the lambda function on-the-fly.  Note that lambda functions cannot have a return statement and must be a single line (even though it does have a colon).\n\\begin{lstlisting}\n: from timer import timer\n: with timer(loops=1000) as t:\n....: t.timer(myFunc, 3,5)\n....: t.timer(lambda x,y: x**y, 3,5)\n\\end{lstlisting}\n\nLet's look at another example of a function that accepts a function as an argument.\n\\begin{lstlisting}\n: from scipy import integrate\n: integrate.quad(lambda x: sp.exp(-x**2/2.0), 0, 2)\n(1.1962880133226084, 1.3281464964738456e-14)\n\\end{lstlisting}\n\nThis code will calculate the integral of $e^{-\\frac{x^2}{2}}$ between zero and two. Here we used a lambda function to get the job done. \n\n\\begin{problem}\nWrite a function that accepts a number $n$, creates a random polynomial of degree $n$ and then finds a zero of that polynomial. If there is no zero then have the function return a local minimum instead. You will need to create function handles and use the function \\li{scipy.optimize.bisect}.\n\\end{problem}\n\n\\begin{problem}\nThe Lambert W-function is defined as the inverse of the function $f(x) = xe^x$. The W-function has important applications in atomic physics and differential equations. It has no closed-form solution. Create a function that estimates the Lambert W-function (you'll need to use \\li{bisect} again).\n\\end{problem}\n\n\\begin{problem}\nRead the help file on the function \\li{scipy.integrate.odeint}. Use \\li{odeint} to find the solution of the differential equation\n\\begin{equation*}\n        x'' = -3x \\quad x(0) = 1 \\quad x'(0) = 0\n\\end{equation*}\n\nTo do this, you will want to convert the higher order system into a lower order system of more variables. Try letting $x_1 = x$ and $x_2 = x'$.\nNow plot the output. What do you find? Is this what you expect?\n\\end{problem}\n\n\\begin{problem}\nNewton's method is an iterative root-finding method. It generally converges very quickly, and is very important in non-linear optimization. Newton's method starts with an initial guess $x_0$ for a root and then calculates the next guess using the following method:\n\\begin{equation*}\nx_{i+1} = x_i - \\frac{f(x_i)}{f'(x_i)}\n\\end{equation*}\n\nThis procedure repeats until a tolerance is reached (either $x_i - x_{i+1}$ or $f(x_{i+1})$ is small enough)\nOne of the important advantages to Newton's method as opposed to functions like \\li{bisect} is that they are more robust when functions have asymptotes (try to use \\li{bisect} on \\li{tan} to see this). Also, Newton's method is generally much faster, and is generalizable to higher dimensions.\nWrite your own Newton's method. Have it accept as arguments f, f', $x_0$ and tol. Remember that f and f' (which you'll probably have to name something like df or fPrime) will be function handles that are passed in. Hint: Use a while loop that tests for reaching the tolerances.\n\\end{problem}\n", "meta": {"hexsha": "d11ccb9a763afa760b7d9707b82703dec086108c", "size": 5627, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Functions/Functions2.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/Functions/Functions2.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/Functions/Functions2.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-21T23:06:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T23:06:27.000Z", "avg_line_length": 59.8617021277, "max_line_length": 828, "alphanum_fraction": 0.7533321486, "num_tokens": 1420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.9273632926354616, "lm_q1q2_score": 0.8376818825047042}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 6}\n\nProve that if there are positive constants $a$ and $c$ such that\n\\begin{equation}\nT(n) = \\sum_{j=2}^{n}(a + (j-1)c)\n\\end{equation}\nthen there are constants $A$, $B$ and $C$ such that\n\\begin{equation}\nT(n) = An^2 + Bn + C\n\\end{equation}\nOf course, $A$, $B$ and $C$ depend on $a$ and $c$, but do not depend on $n$.\nYou should show also that $A > 0$.\n\n\\subsection*{Solution}\n\n\\begin{equation}\n\\begin{aligned}\nT(n) &= \\sum_{j=2}^{n}(a + (j-1)c)\\\\\n&=(a-c)\\sum_{j=2}^{n}1+c\\sum_{j=2}^{n}j\\\\\n&=(a-c)(n-1)+c\\frac{n(n-1)}{2}-c\\\\\n&=(0.5c)n^2+(a-1.5c)n-a\n\\end{aligned}\n\\end{equation}\n\nWhere $A = 0.5c$, $B = (a - 1.5c)$ and $C = -a$.\nSince $c$ is positive, $A$ is positive as well.\n", "meta": {"hexsha": "a1016862f6edb941d0130b15ab250dc4576a50f0", "size": 1049, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q06.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q06.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q06.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 30.8529411765, "max_line_length": 76, "alphanum_fraction": 0.5538608198, "num_tokens": 385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474181553805, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.8376809420138863}}
{"text": "\\chapter{Conditional Probability}\nIn general, the occurrence of an event $B$ changes the probability that another\nevent $A$ occurs, $\\Pr_{\\Distribution{D}}(A \\cond B)$ denotes the latter\nprobability. More formally, $\\Pr(A \\cond B) = \\Pr(A \\cap B) / \\Pr(B)$, where\n$(\\Omega, \\Distribution{D})$ is a finite discrete probability space, \n$A, B \\subseteq \\Omega$, and $\\Pr_{\\Distribution{D}}(B) \\neq 0$.\nWe say that $\\Pr_{\\Distribution{D}}(A \\cond B)$ is the conditional probability\nthat $A$ occurs given that $B$ occurs.\n\nFor example, let us consider $\\Omega = [6]^2$ and the uniform distribution\n$\\Uniform{\\Omega}$ on $\\Omega$; i.e., we consider an experiment consisting of\nrolling two dice. Let us compute the probability that the sum of numbers on the\ndice exceeds $6$ given that the first dice's number is $3$. In other words we\nneed to compute $\\Pr_{\\Uniform{\\Omega}}(A \\cond B)$, where \n$A = \\set[i + j > 6]{(i, j) \\in [6]^2}$ and \n$B = \\set[{j \\in [6]}]{(3, j)}$. It is clear that $\\Pr_{\\Uniform{\\Omega}}(B) = \n1 / 6$ and\n$\\Pr_{\\Uniform{\\Omega}}(A \\cap B) = \\set{(3, 4), (3, 5), (3, 6)} = 1 / 12$. \nHence, $\\Pr_{\\Uniform{\\Omega}}(A \\cond B) = 1 / 2$.\n\n\\begin{exercise}\n  A family has two children. What is the probability that both are boys, given\n  at least one is a boy? What if it is given that \\emph{the first child} is a\n  boy. (You assume that the probability distribution of families is uniform.)\n\\end{exercise}\n\nLet us consider another example known as ``Monty Hall Problem''. On the\ntelevision game \\emph{Let\u2019s make a deal}, a contestant is presented with a\nchoice of three closed doors. Behind exactly one door is a prize; the other\ndoors conceal cheap items. First, the contestant is asked to choose a door. Then\nMonty Hall, the host of the show,  shows the contestant one of the worthless\nprizes behind one of the other doors. At this point, there are two closed\ndoors, and the contestant is given the opportunity to switch from his original\nchoice to the other closed door. The question is, is it better for the\ncontestant to stick to his original choice or to switch doors?\n\n\nLet us analyze this question using the conditional probabilities. Without loss\nof generality, we may assume that the contestant chooses door $1$.\nNote that the sample space is equal to $\\set{(1, 2), (1, 3), (2, 3), (3, 2)}$,\nwhere the first number denotes the door with the prize and the second number\ndenotes the door opened by the host. The probability distribution is equal to \n\\[\n  \\Distribution{D}(x) = \n  \\begin{cases}\n    1 / 6 & \\text{if } x = (1, 2) \\\\\n    1 / 6 & \\text{if } x = (1, 3) \\\\\n    1 / 3 & \\text{if } x = (2, 3) \\\\\n    1 / 3 & \\text{if } x = (3, 2)\n  \\end{cases}\n\\]\nsince in the first two cases Monty has two possible choices to show a door\nwithout the prize.\nSuppose the host revealed the door number $2$ (the probability of this is\n$3 / 6$). Then the probability that we win the price if we stick to the original\nchoice is $(1 / 6) / (3 / 6) = 1 / 3$. However, the probability to win the prize\nin case of us swithcing the door is $(1 / 3) / (3 / 6) = 2 / 3$. Which implies,\nparadoxically, that it is beneficial to switch the door!\n\n\\begin{theorem}[Bayes\u2019 Rules]\n  Let $(\\Omega, \\Distribution{D})$ be a finite discrete probability space. \n  \\begin{itemize}\n    \\item Let $A, B \\subseteq \\Omega$ be two events such that\n      $\\Pr_{\\Distribution{D}}(A) > 0$ and\n      $\\Pr_{\\Distribution{D}}(B) > 0$. Then $\\Pr_{\\Distribution{D}}(A \\cond B) = \n      \\frac{\\Pr_{\\Distribution{D}}(B \\cond A)\n        \\Pr_{\\Distribution{D}}(B)}{\\Pr_{\\Distribution{D}}(A)}$.\n    \\item Let $A, B \\subseteq \\Omega$ be two events such that\n      $\\Pr_{\\Distribution{D}}(A) < 1$ and\n      $\\Pr_{\\Distribution{D}}(B) < 1$; i.e., \n      $\\Pr_{\\Distribution{D}}(\\bar{A}) > 0$ and \n      $\\Pr_{\\Distribution{D}}(\\bar{B}) > 0$, where\n      $\\bar{A} = \\Omega \\setminus A$ and $\\bar{B} = \\Omega \\setminus B$.\n      Then $\\Pr_{\\Distribution{D}}(A) = \n        \\Pr_{\\Distribution{D}}(A \\cond B)\\Pr_{\\Distribution{D}}(B) + \n        \\Pr_{\\Distribution{D}}(A \\cond \\bar{B})\\Pr_{\\Distribution{D}}(\\bar{B})$.\n  \\end{itemize}\n\\end{theorem}\n\n\nUsefulness of this result can be illustrated with the following example. Assume\nthat there is a rare disease that has the property that if a patient is affected\nby the disease, then the test is positive in $99\\%$ of the cases. However, it\nhappens in $2\\%$ of the cases that a healthy patient tests positive. Statistical\ndata shows that one person out of $1000$ has the disease. What is the\nprobability for a patient with a positive test to be affected by the disease?\n\nLet $(\\Omega, \\Distribution{D})$ be a finite discrete probability space from\nthis problem.\nLet $S$ be the event that the patient has the disease, and $P$ and $N$ the\nevents that the test is positive or negative. We know that\n$\\Pr_{\\Distribution{D}}(S) = 0.001$,\n$\\Pr_{\\Distribution{D}}(P \\cond S) = 0.99$, and \n$\\Pr_{\\Distribution{D}}(P \\cond S) = 0.02$, where $\\bar{S}$ is the\nevent that the patient does not have the desease. Therefore \n$\\Pr_{\\Distribution{D}}(S \\cond P) = \n\\frac{\n  \\Pr_{\\Distribution{D}}(P \\cond S) \\Pr_{\\Distribution{D}}(S)\n}{\n  \\Pr_{\\Distribution{D}}(P)\n}$ \nand \n$\\Pr_{\\Distribution{D}}(P) = \n  \\Pr_{\\Distribution{D}}(P \\cond S) \\Pr_{\\Distribution{D}}(S) + \n  \\Pr_{\\Distribution{D}}(P \\cond \\bar{S}) \\Pr_{\\Distribution{D}}(\\bar{S})$. \nAs a result $\\Pr_{\\Distribution{D}}(S \\cond P) =  \n\\frac{0.99 \\cdot 0.001}{0.99 \\cdot 0.001 + 0.02 \\cdot 0.999} \\approx \\frac{1}{20}$.\n", "meta": {"hexsha": "bbb0239823ef01d9ca1918d67e04d78ac09bd92e", "size": 5477, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_3/chapter_15_conditional_probability.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_3/chapter_15_conditional_probability.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_3/chapter_15_conditional_probability.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 50.712962963, "max_line_length": 83, "alphanum_fraction": 0.6693445317, "num_tokens": 1766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067179697694, "lm_q2_score": 0.8887587927558434, "lm_q1q2_score": 0.8376611328270843}}
{"text": "\\subsection{Exponentials \\& Logarithms}\r\n\\begin{definition}\r\n\te is the base of the natural logarithm. It's definied by the limit\r\n\t\\begin{equation*}\r\n\t\te = \\lim\\limits_{n\\rightarrow\\infty}{\\left(1+\\frac{1}{n}\\right)^n}\r\n\t\\end{equation*}\r\n\\end{definition}\r\n$\\exp{x} = e^x$ and $\\ln{x}$ are inverse functions of each other such that\r\n\\begin{equation*}\r\n\te^{\\ln{x}} = x \\text{, } \\ln{e^x} = x\r\n\\end{equation*}\r\n\r\n\\noindent\r\nJust like other exponents, the normal rules for adding, subtracting, and multiplying powers apply.\r\n\\begin{equation*}\r\n\te^xe^y = e^{x+y}\\text{, }\\frac{e^x}{e^y}=e^{x-y}\\text{, and }\\left(e^x\\right)^k=e^{xk}\r\n\\end{equation*}\r\n\r\n\\noindent\r\nSimilar rules apply for logarithms.\r\n\\begin{equation*}\r\n\t\\ln{x}+\\ln{y} = \\ln{xy}\\text{, }\\ln{x}-\\ln{y} = \\ln{\\left(\\frac{x}{y}\\right)}\\text{, and }\\ln{\\left(a^b\\right)}=b\\ln{a}\r\n\\end{equation*}\r\n\r\n\\noindent\r\nYou can also change a logarithm of any base to a natural logarithm.\r\n\\begin{equation*}\r\n\t\\log_{b}{a} = \\frac{\\ln{a}}{\\ln{b}}\r\n\\end{equation*}\r\n\r\n\\noindent\r\n$e$ is also unique in that it is the only real number $a$ satisfying the equation\r\n\\begin{equation*}\r\n\t\\frac{\\mathrm{d}}{\\mathrm{d}x}a^x = a^x\r\n\\end{equation*}\r\nmeaning $e^x$ is its own derivative.", "meta": {"hexsha": "50c9695b6cff67c2ad150ee72c61f5a157b738c5", "size": 1220, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/backgroundReview/algebraPreCalc/exponentsLogarithms.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/backgroundReview/algebraPreCalc/exponentsLogarithms.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/backgroundReview/algebraPreCalc/exponentsLogarithms.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.8888888889, "max_line_length": 121, "alphanum_fraction": 0.6508196721, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075690244281, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.8376082295832697}}
{"text": "\\section{Question 1}\n\\begin{enumerate}[label=(\\alph*)]\n    \\item Write down the definition of \\textbf{norm} for a vector space.\n        \\begin{solution}{}{}\n            Let $\\mX$ be a real vector space. A nonnegative-valued function $\\norm{\\cdot}: \\mX\\to\\RR$ is called a norm if $\\forall\\vx,\\vy\\in\\mX, \\lambda\\in\\RR$\n            \\begin{itemize}\n                \\item $\\norm{\\lambda\\vx}=\\abs{\\lambda}\\norm{\\vx}$ (absolutely homogeneous);\n                \\item $\\norm{\\vx+\\vy}\\leq\\norm{\\vx}+\\norm{\\vy}$ (triangle inequality);\n                \\item $\\norm{\\vx}=0\\Rightarrow\\vx =\\va{0}$ (positive definite).\n            \\end{itemize}\n            Moreover, the vector norm $\\norm{\\cdot}_p$ for $p=1,2,\\ldots$ is defined as\n            \\[\n                \\norm{\\vx}_p = \\qty(\\sum_{1\\leq i\\leq n}\\abs{x_i}^p)^{1/p}.\n            \\]\n            And the pair $(\\mX, \\norm{\\cdot})$ is called a normed space.\n        \\end{solution}\n    \\item Given $\\vx\\in\\RR^n$, show that followings are norm on $\\RR^n$.\n        \\begin{enumerate}[label=\\roman*.]\n            \\item $\\norm{\\vx}_\\infty=\\max_{1\\leq i\\leq n}\\abs{x_i}$;\n                \\begin{solution}{}{}\n                    \\begin{itemize}\n                        \\item $\\norm{\\lambda\\vx}_\\infty=\\max_{1\\leq i\\leq n}\\abs{\\lambda x_i}=\\abs{\\lambda}\\max_{1\\leq i\\leq n}\\abs{x_i}=\\abs{\\lambda}\\norm{\\vx}_\\infty$\n                        \\item $\\norm{\\vx+\\vy}_\\infty=\\max_{1\\leq i\\leq n}\\abs{x_i+y_i}\\leq\\max_{1\\leq i\\leq n}\\abs{x_i}+\\max_{1\\leq i\\leq n}\\abs{y_i}=\\norm{\\vx}_\\infty+\\norm{\\vy}_\\infty$\n                        \\item $\\norm{\\vx}_\\infty=\\max_{1\\leq i\\leq n}\\abs{x_i}=0\\Rightarrow\\abs{x_i}=0\\text{ where $1\\leq i\\leq n$}\\Rightarrow\\vx =\\va{0}$\n                    \\end{itemize}\n                \\end{solution}\n            \\item $\\norm{\\vx}_1=\\sum_{1\\leq i\\leq n}\\abs{x_i}$;\n                \\begin{solution}{}{}\n                    \\begin{itemize}\n                        \\item $\\norm{\\lambda\\vx}_1=\\sum_{1\\leq i\\leq n}\\abs{\\lambda x_i}=\\abs{\\lambda}\\sum_{1\\leq i\\leq n}\\abs{x_i}=\\abs{\\lambda}\\norm{\\vx}_1$\n                        \\item $\\norm{\\vx+\\vy}_1=\\sum_{1\\leq i\\leq n}\\abs{x_i+y_i}\\leq\\sum_{1\\leq i\\leq n}\\abs{x_i}+\\sum_{1\\leq i\\leq n}\\abs{y_i}=\\norm{\\vx}_1+\\norm{\\vy}_1$\n                        \\item $\\norm{\\vx}_1=\\sum_{1\\leq i\\leq n}\\abs{x_i}=0\\Rightarrow\\abs{x_i}=0\\text{ where $1\\leq i\\leq n$}\\Rightarrow\\vx =\\va{0}$\n                    \\end{itemize}\n                \\end{solution}\n            \\item $\\norm{\\vx}_2=\\qty(\\sum_{1\\leq i\\leq n}\\abs{x_i}^2)^{1/2}$.\n                \\begin{solution}{}{}\n                    \\begin{itemize}\n                        \\item $\\norm{\\lambda\\vx}_2=\\qty(\\sum_{1\\leq i\\leq n}\\abs{\\lambda x_i}^2)^{1/2}=\\abs{\\lambda}\\qty(\\sum_{1\\leq i\\leq n}\\abs{x_i}^2)^{1/2}=\\abs{\\lambda}\\norm{\\vx}_2$\n                        \\item $\\norm{\\vx+\\vy}_2=\\qty(\\sum_{1\\leq i\\leq n}\\abs{x_i+y_i}^2)^{1/2}\\leq\\qty(\\sum_{1\\leq i\\leq n}\\abs{x_i}^2)^{1/2}+\\qty(\\sum_{1\\leq i\\leq n}\\abs{y_i}^2)^{1/2} = \\norm{\\vx}_2+\\norm{\\vy}_2$\n                        \\item $\\norm{\\vx}_2=\\qty(\\sum_{1\\leq i\\leq n}\\abs{x_i}^2)^{1/2}=0\\Rightarrow\\sum_{1\\leq i\\leq n}\\abs{x_i}^2\\Rightarrow\\vx =\\va{0}$\n                    \\end{itemize}\n                \\end{solution}\n        \\end{enumerate}\n        Plot the regions for $\\norm{\\vx}_p\\leq 1$ in $\\RR^2$ for $p=\\infty,1,2$ respectively.\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width=.9\\textwidth]{figures/1-1}\n            \\caption{Please refer to Appendix~\\ref{S:appendix-1}}\n        \\end{figure}\n    \\item Given the vector norm $\\norm{\\cdot}_p$ for $\\RR^n$, the induced norm for matrices $\\mA\\in\\RR^{n\\times n}$ is defined as\n        \\[\n            \\norm{\\mA}_p = \\max_{\\vx\\neq 0}\\frac{\\norm{\\mA\\vx}_p}{\\norm{\\vx}_p} = \\max_{\\norm{\\vx}_p=1}\\norm{\\mA\\vx}_p.\n        \\]\n        Show that\n        \\begin{enumerate}[label=\\roman*.]\n            \\item $\\norm{\\mA}_\\infty=\\max_{1\\leq i\\leq n}\\sum_{j=1}^n\\abs{a_{ij}}$;\n                \\begin{solution}{}{}\n                    \\begin{align*}\n                        \\norm{\\mA}_\\infty &= \\max_{\\norm{\\vx}_\\infty=1}\\norm{\\mA\\vx}_\\infty \\\\\n                        &= \\max_{\\max_{1\\leq j\\leq n}\\abs{x_j}=1}\\max_{1\\leq i\\leq n}\\sum_{j=1}^n\\abs{a_{ij}x_j} \\\\\n                        &\\leq \\max_{1\\leq i\\leq n}\\sum_{j=1}^n\\abs{a_{ij}} \\\\\n                    \\end{align*}\n                    The equality holds when $x_j=\\pm 1$ for $j=1,2,\\ldots,n$.\n                \\end{solution}\n            \\item $\\norm{\\mA}_1=\\max_{1\\leq j\\leq n}\\sum_{i=1}^n\\abs{a_{ij}}$;\n                \\begin{solution}{}{}\n                    \\begin{align*}\n                        \\norm{\\mA}_1 &= \\max_{\\norm{\\vx}_1=1}\\norm{\\mA\\vx}_1 \\\\\n                        &= \\max_{\\sum_{j=1}^n\\abs{x_j}=1}\\sum_{i=1}^n\\sum_{j=1}^n\\abs{a_{ij}x_j} \\\\\n                        &\\leq \\max_{\\sum_{j=1}^n\\abs{x_j}=1}\\sum_{j=1}^n\\sum_{i=1}^n\\abs{a_{ij}}\\abs{x_j} = \\max_{\\sum_{j=1}^n\\abs{x_j}=1}\\sum_{j=1}^n\\abs{x_j}\\sum_{i=1}^n\\abs{a_{ij}} \\\\\n                        &\\leq \\max_{\\sum_{j=1}^n\\abs{x_j}=1}\\sum_{j=1}^n\\abs{x_j}\\max_{1\\leq j\\leq n}\\sum_{i=1}^n\\abs{a_{ij}} = \\max_{1\\leq j\\leq n}\\sum_{i=1}^n\\abs{a_{ij}}\n                    \\end{align*}\n                    The equality holds when $j=\\argmax_{1\\leq j\\leq n}\\sum_{i=1}^n\\abs{a_{ij}}$.\n                \\end{solution}\n            \\item $\\norm{\\mA}_2=\\sqrt{\\lambda_{\\max}\\qty(\\mA^T\\mA)}$.\n                \\begin{solution}{}{}\n                    $\\mA$ can be decomposed as $\\vb{U}\\vb*{\\Sigma}\\vb{V}^T$ by singular value decomposition, and the singular values on the diagonal are decreasing from top left to bottom right.\n                    \\begin{align*}\n                        \\norm{\\mA}_2^2 &= \\max_{\\norm{\\vx}_2=1} \\norm{\\mA\\vx}_2^2 \\\\\n                        &= \\max_{\\norm{\\vx}_2=1} \\qty(\\mA\\vx)^T\\mA\\vx = \\max_{\\norm{\\vx}_2=1}\\vx^T\\vb{V}\\vb*{\\Sigma}^2\\vb{V}^T\\vx \\\\\n                        &= \\max_{\\norm{\\vx}_2=1}\\vy^T\\vb*{\\Sigma}\\vy = \\max_{\\norm{\\vx}_2=1}\\sum_{i=1}^n\\sigma_iy_i^2 \\\\\n                        &\\leq \\max_{\\norm{\\vx}_2=1}\\max_{1\\leq i\\leq n}\\sigma_i \\vy^T\\vy = \\max_{\\norm{\\vx}_2=1}\\max_{1\\leq i\\leq n}\\sigma_i \\vx^T\\vx\\\\\n                        &= \\max_{1\\leq i\\leq n}\\sigma_i = \\lambda_{\\max}\\qty(\\mA^T\\mA).\n                    \\end{align*}\n                    The equality holds when $\\vx=\\vb{V}\\vb{e}_1$, where $\\vb{e}_1=[1,0,\\ldots,0]^T$.\n                \\end{solution}\n        \\end{enumerate}\n\\end{enumerate}\n\n\n\n\\section{Question 2}\n\\begin{enumerate}[label=(\\alph*)]\n    \\item Use the method of undetermined coefficients to design third order accurate approximation to $u'(\\bar{x})$ by using the discrete points $\\bar{x}+h$, $\\bar{x}$, $\\bar{x}-h$, $\\bar{x}-2h$.\n        \\begin{solution}{}{}\n            According to Appendix~\\ref{S:appendix-1}, we have\n            \\[\n                u'(\\bar{x}) = \\frac{1}{h}\\qty(\\frac{u(\\bar{x}-2h)}{6}-u(\\bar{x}-h)+\\frac{u(\\bar{x})}{2}+\\frac{u(\\bar{x}+h)}{3}).\n            \\]\n        \\end{solution}\n    \\item Assuming $u(x)$ is smooth enough, compute the truncation error (leading term) for the finite difference formula above.\n        \\begin{solution}{}{}\n            The leading term of the truncation error is of $\\order{h^3}$, that is\n            \\[\n                \\frac{h^3}{12}u^{(4)}(\\bar{x}).\n            \\]\n        \\end{solution}\n    \\item What is the truncation error if $u(x) = 4x^4 + 12x^3 + 6x^2 + x/2 + \\pi$.\n        \\begin{solution}{}{}\n            \\begin{align*}\n                u'(\\bar{x}) &= \\frac{1}{h}\\qty(\\frac{u(\\bar{x}-2h)}{6}-u(\\bar{x}-h)+\\frac{u(\\bar{x})}{2}+\\frac{u(\\bar{x}+h)}{3}) \\\\\n                &= 16\\bar{x}^3 + 36\\bar{x}^2 + 12\\bar{x} + \\frac{1}{2}\n            \\end{align*}\n            We have $u'(x)=16x^3 + 36x^2 + 12x + 1/2$, that is, the truncation error of this given function is $0$.\n        \\end{solution}\n\\end{enumerate}\n\n\n\n\\section{Question 3}\n\\begin{enumerate}[label=(\\alph*)]\n    \\item For the following $N\\times N$ matrix, show that all eigenvalues are given by $\\lambda_p = a+2b\\cos\\tfrac{\\pi p}{N+1}$ for $p=1,2,\\ldots,N$.\n        \\[\n            \\qty[\\begin{NiceArray}{CCCC}\n                a & b      &        &   \\\\\n                b & \\Ddots & \\Ddots &   \\\\\n                  & \\Ddots & \\Ddots & b \\\\\n                  &        & b      & a \\\\\n            \\end{NiceArray}]_{N\\times N}\n        \\]\n        \\begin{solution}{}{}\n            Please refer to Section~\\ref{Q:4-1}.\n        \\end{solution}\n\\end{enumerate}\n\n\n\n\\section{Question 4}\\label{Q:4-1}\n\\begin{enumerate}[label=(\\alph*)]\n    \\item For the following $N\\times N$ matrix, show that all eigenvalues are given by $\\lambda_p = a+2\\sqrt{bc}\\cos\\tfrac{\\pi p}{N+1}$ for $p=1,2,\\ldots,N$ and $bc>1$.\n        \\[\n            \\mA = \\qty[\\begin{NiceArray}{CCCC}\n                a & c      &        &   \\\\\n                b & \\Ddots & \\Ddots &   \\\\\n                  & \\Ddots & \\Ddots & c \\\\\n                  &        & b      & a \\\\\n            \\end{NiceArray}]_{N\\times N}\n        \\]\n        \\begin{solution}{}{}\n            The eigenvalues are $\\lambda_p = a+2\\sqrt{bc}\\cos\\tfrac{\\pi p}{N+1}$, and the corresponding eigenvector $\\vx^p$ has $j$th component\n            \\[\n                \\vx^p_j = \\qty(\\sqrt{\\frac{b}{c}})^j \\sin\\qty(\\frac{p\\pi j}{N+1}).\n            \\]\n            And $\\vx^p_0=\\vx^p_{N+1}=0$, if we want to show that $\\mA\\vx^p=\\lambda_p\\vx_p$, then we just need to show that $b\\vx^p_{j-1}+a\\vx^p_j+c\\vx^p_{j+1}=\\lambda_px^p_j$ for $j=1,2,\\ldots,N$. We use the method of subtracting two sides to determine whether the two sides are equal by judging whether the result is zero. That is,\n            \\begin{align*}\n                & b\\vx^p_{j-1}+a\\vx^p_j+c\\vx^p_{j+1}-\\lambda_px^p_j \\\\\n                =& b\\vx^p_{j-1}-2\\sqrt{bc}\\cos\\frac{\\pi p}{N+1}\\vx^p_j+c\\vx^p_{j+1} \\\\\n                =& \\qty(\\frac{b}{c})^{(j-1)/2}\\qty(b\\sin\\qty(\\frac{\\pi p(j-1)}{N+1})+b\\sin\\qty(\\frac{\\pi p(j+1)}{N+1})-2b\\sin\\qty(\\frac{\\pi pj}{N+1})\\cos\\qty(\\frac{\\pi p}{N+1})) \\\\\n                =& \\qty(\\frac{b}{c})^{(j-1)/2}b\\qty(\\sin\\qty(\\frac{\\pi p(j-1)}{N+1})+\\sin\\qty(\\frac{\\pi p(j+1)}{N+1})-2\\sin\\qty(\\frac{\\pi pj}{N+1})\\cos\\qty(\\frac{\\pi p}{N+1})) \\\\\n                =& 0.\n            \\end{align*}\n            The last step relies on $\\sin(x+y)=\\sin(x)\\cos(y)+\\cos(x)\\sin(y)$. Since $N\\times N$ matrix has at most $N$ eigenvalues, then $\\lambda_p = a+2\\sqrt{bc}\\cos\\tfrac{\\pi p}{N+1}$ is all the eigenvalues the matrix has.\n        \\end{solution}\n\\end{enumerate}\n\n\n\n\\section{Question 5}\nFor the 2-point BVP with Neumann boundary conditions:\n\\[\n    \\begin{cases}\n        u''(x) = f(x), & x\\in(0, 1) \\\\\n        u'(0) = u'(1) = 0 & \\\\\n    \\end{cases}\n\\]\n\\begin{enumerate}[label=(\\alph*)]\n    \\item Set the grid points as $x_j=jh$ for $j=0,1,\\ldots,N$ and $h=1/N$. Write down the central FD scheme for the main equation with using $u_j$ to approximate $u(x_j)$.\n        \\begin{solution}{}{}\n            According to the central finite difference scheme, for $j=1,2,\\ldots,N-1$ we have\n            \\[\n                u''(x_j) = \\frac{u(x_{j+1})-2u(x_j)+u(x_{j-1})}{h^2} = f(u_j)\n            \\]\n            If we use $u'(\\bar{x})=(u(\\bar{x}+h)-u(\\bar{x}))/h$ or $u'(\\bar{x})=(u(\\bar{x})-u(\\bar{x})-h)/h$, we can approximate $u(x_0)$ by $u(x_1)$ and $u(x_N)$ by $u(x_{N-1})$. That is\n            \\[\n                \\frac{1}{h^2}\n                \\qty[\\begin{NiceArray}{RRRRR}\n                    -1 & 1      &        &        &    \\\\\n                    1  & -2     & \\Ddots &        &    \\\\\n                       & \\Ddots & \\Ddots & \\Ddots &    \\\\\n                       &        & \\Ddots & -2     & 1  \\\\\n                       &        &        & 1      & -1 \\\\\n                \\end{NiceArray}]_{N-1\\times N-1}\n                \\begin{bNiceMatrix}\n                    u_1 \\\\ u_2 \\\\ \\Vdots \\\\ \\Vdots \\\\ u_{-1})\n                \\end{bNiceMatrix}\n                =\n                \\begin{bNiceMatrix}\n                    f(x_1) \\\\ f(x_2) \\\\ \\Vdots \\\\ \\Vdots \\\\ f(x_{N-1})\n                \\end{bNiceMatrix}.\n            \\]\n        \\end{solution}\n    \\item\\label{tmp-1} Add two ``ghost'' points as $x_{-1}=-h$ and $x_{N+1}=1+h$, and two more variables $u_{-1}$ and $u_{N+1}$. Treat the boundary condition as $(u_1-u_{-1})/2h=0$, $(u_{N+1}-u_{N-1})/2h=0$. Assemble all the equations as $\\mA\\vb{U}=\\vb{F}$ where $\\vb{U}=[u_0, u_1, \\ldots, u_N]^T$.\n        \\begin{solution}{}{}\n            If we treat the boundary condition as the given way, we can approximate $u(x_{-1})$ by $u(x_1)$ and $u(x_{N+1})$ by $u(x_{N-1})$. Then all the equations can be assemble as $\\mA\\vb{U}=\\vb{F}$ where $\\vb{U}=[u_0,u_1,\\ldots,u_N]^T$ and $\\vb{F}=[f(x_0),f(x_1),\\ldots,f(x_N)]^T$. Also, we have\n            \\[\n                \\mA = \\frac{1}{h^2}\n                \\qty[\\begin{NiceArray}{RRRRR}\n                    -2 & 2      &        &        &    \\\\\n                    1  & \\Ddots & 1      &        &    \\\\\n                       & \\Ddots & \\Ddots & \\Ddots &    \\\\\n                       &        & 1      & \\Ddots & 1  \\\\\n                       &        &        & 2      & -2 \\\\\n                \\end{NiceArray}]_{N+1\\times N+1}\n            \\]\n        \\end{solution}\n    \\item Show that $\\mA$ is singular, and find out when the system $\\mA\\vb{U}=\\vb{F}$ has solutions.\n        \\begin{solution}{}{}\n            We can first check the validity of the conclusion by MATLAB.\n            \\begin{matlabcode}{}\nA = @(N) -2*eye(N+1) + diag([2, ones(1, N-1)], 1) + diag([ones(1, N-1), 2], -1);\nfor N = 1 : 99\n    if det(A(N)) ~= 0\n        disp(N);\n    end\nend\n            \\end{matlabcode}\n            Then, we notice that the row sum of $\\mA$ is 0, which means $\\rank\\mA\\neq N$, this leads to the conclusion that $\\mA$ is singular. As for when the system $\\mA\\vb{U}=\\vb{F}$ has solutions, through the knowledge of linear algebra, we know that $\\vb{F}$ must in the range space\\footnote{In linear algebra, range space refers to the column space of a matrix, which is the set of all possible linear combinations of its column vectors.} of $\\mA$.\n        \\end{solution}\n    \\item Find the kernel space of $\\mA$.\n        \\begin{solution}{}{}\n            The kernel space\\footnote{The definition of kernel space is also appears in the computer field: System memory in Linux can be divided into two distinct regions: kernel space and user space. Kernel space is where the kernel (i.e., the core of the operating system) executes (i.e., runs) and provides its services.} is also called the null space, which is defined as\n            \\[\n                \\nullspace{\\mA_{n\\times n}} = \\qty{\\vx\\in\\RR^n \\mid \\mA\\vx=\\va{0}}.\n            \\]\n            Therefor, the kernel space of $\\mA$ is\n            \\[\n                \\spanof\\qty{\n                    \\qty[\\begin{NiceArray}{C}\n                        1 \\\\ 1 \\\\ \\Vdots \\\\ 1\n                    \\end{NiceArray}]_{N+1\\times 1}\n                }.\n            \\]\n        \\end{solution}\n    \\item Find out all eigenvalues and eigenvectors for the matrix $\\mA$ given in \\ref{tmp-1}.\\todo[inline,color=green!40]{todo: re-derive it later.}\n        \\begin{solution}{}{}\n            The non-zero eigenvalues of the matrix $\\mA_{N+1\\times N+1}$ is\n            \\[\n                \\lambda_p = -2 + 2\\cos\\frac{\\pi p}{N},\n            \\]\n            and the corresponding eigenvector $\\vx^p$ has $j$th component\n            \\[\n                \\vx^p_j = \\cos\\qty(\\frac{p\\pi(j-1)}{N})\n            \\]\n            for $p=0,1,\\ldots,N$. We can then check the correctness of the result by MATLAB.\n            \\begin{matlabcode}{}\nA = @(N) -2*eye(N+1) + diag([2, ones(1, N-1)], 1) + diag([ones(1, N-1), 2], -1);\nlambda = @(N, p) -2 + 2*cos(pi*p/N);\nx = @(N, p) cos(pi*p*(0:N)/N)';\nerror = @(N) N^2 * eps;\nfor N = 1 : 99\n    for p = 0 : N\n        delta = A(N)*x(N, p) - lambda(N, p)*x(N, p);\n        if norm(delta, 1) > error(N)\n            disp(['N=', num2str(N), '; p=', num2str(p), '; error=', num2str(norm(delta, 1))]);\n        end\n    end\nend\n            \\end{matlabcode}\n        \\end{solution}\n\\end{enumerate}\n\n\n\n\\clearpage\n\\section{Appendix}\\label{S:appendix-1}\n\\begin{appendices}\n    \\pythonfile{code/hw1.py}{\\texttt{hw1.py}}\n    \\pythonfile{code/1_2.py}{\\texttt{1\\_2.py}}\n    \\pythonfile{code/1_2_sympy.py}{\\texttt{1\\_2\\_sympy.py}}\n\\end{appendices}\n", "meta": {"hexsha": "0c93e4356ec94ecb8005affced98fd35fd421d6c", "size": 16184, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MA325/numerical/parts/1.tex", "max_stars_repo_name": "iydon/homework", "max_stars_repo_head_hexsha": "253d4746528ef62d33eba1de0b90dcb17ec587ed", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-10-20T08:18:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-11T12:14:56.000Z", "max_issues_repo_path": "MA325/numerical/parts/1.tex", "max_issues_repo_name": "iydon/homework", "max_issues_repo_head_hexsha": "253d4746528ef62d33eba1de0b90dcb17ec587ed", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2022-01-13T03:04:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:49:10.000Z", "max_forks_repo_path": "MA325/numerical/parts/1.tex", "max_forks_repo_name": "iydon/homework", "max_forks_repo_head_hexsha": "253d4746528ef62d33eba1de0b90dcb17ec587ed", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-11-02T05:46:01.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T23:11:28.000Z", "avg_line_length": 57.5943060498, "max_line_length": 453, "alphanum_fraction": 0.496045477, "num_tokens": 5695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810451666346, "lm_q2_score": 0.8840392893839085, "lm_q1q2_score": 0.8375220659448962}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=1}^\\infty \\frac{n!}{(2n)!}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution}\r\n\r\n\\begin{align*}\r\nL\r\n&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&=\\lim_{n \\to \\infty} \\left|\\frac{(n+1)!}{(2(n+1))!} \\cdot \\frac{(2n)!}{n!}\\right|\\\\\r\n&=\\lim_{n \\to \\infty} \\left|\\frac{(n+1)!}{(2n+2)!} \\cdot \\frac{(2n)!}{n!}\\right|\\\\\r\n&=\\lim_{n \\to \\infty} \\left|\\frac{(n+1) \\cdot n!}{(2n+2) \\cdot (2n+1) \\cdot (2n)!} \\cdot \\frac{(2n)!}{n!}\\right|\\\\\r\n&=\\lim_{n \\to \\infty} \\left|\\frac{(n+1)}{(2n+2)(2n+1)}\\right|\\\\\r\n&=\\lim_{n \\to \\infty} \\frac{n+1}{4n^2+6n+2}\\\\\r\n&=\\lim_{n \\to \\infty} \\frac{1}{8n+6} \\text{ by L'hopital}\\\\\r\n&= 0\r\n\\end{align*}\r\n\r\nSince $L< 1$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{n!}{(2n)!}$ converges absolutely by the Ratio Test.\r\n\r\n\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\right|\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "9b8c3cab0f29eeb646c45e05f6451a1f52c92a26", "size": 1726, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/m9.tex", "max_stars_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_stars_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "key/series/m9.tex", "max_issues_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_issues_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "key/series/m9.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 29.7586206897, "max_line_length": 116, "alphanum_fraction": 0.5886442642, "num_tokens": 706, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.8991213833519949, "lm_q1q2_score": 0.8374978578055942}}
{"text": "\n\n\n\n\\documentclass{article}\n\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{mathtools}\n\\usepackage{tikz}\n\\usepackage[a4paper, total={8in, 11in}]{geometry}\n\n\n\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{lemma}{Lemma}\n\\newtheorem{definition}{Definition}\n\\DeclareMathOperator*{\\argmin}{\\arg\\!\\min}\n\\DeclareMathOperator*{\\argmax}{\\arg\\!\\max}\n\\DeclareMathOperator{\\E}{\\mathbb{E}}\n\\DeclareMathOperator{\\p}{\\mathbb{P}}\n\\DeclareMathOperator{\\pr}{\\mathbb{P}}\n\\newlength{\\dhatheight}\n\\newcommand{\\doublehat}[1]{%\n    \\settoheight{\\dhatheight}{\\ensuremath{\\hat{#1}}}%\n    \\addtolength{\\dhatheight}{-0.15ex}%\n    \\hat{\\vphantom{\\rule{1pt}{\\dhatheight}}%\n    \\smash{\\hat{#1}}}}\n\n\n\n\n\n\\begin{document}\n\nAfter my talk on Thursday, some people asked how to improve Hoeffding's inequality, and how it could be made to give confidence-intervals that do not exceed the data's bounds.\nHoeffding's inequality is easy to use and can be essential in some formal proofs. But my research has led me to know that there are better bounds. And if my learning is usefull for someone else, then I regard that as a best kind of outcome!\\\\\n\nThe easiest way to show how Hoeffding's inequality can be improved is to show how a better bound can be created by omitting an approximation in its derivation - ie. creating a universally more powerfull bound.\\\\\nHoeffding's inequality is an example of a Chernoff bound, which uses Markov's inequality:\\\\\n\n\\begin{lemma}[Markov's Inequality] for any non-negative random variable $X$ and any $a>0$ that: $\\p(X\\ge a)\\le \\E[X]/a$ \n\\end{lemma}\n\n\n\\begin{lemma}[Chernoff Bound]\\label{chernoff1}\nIf $\\hat{\\mu} = \\frac{1}{n}\\sum_{i=1}^nx_i$ is sample mean of $n$ independent and identically distributed samples of random variable $X$ ($x_i\\sim X$), then for any $s,t>0$: $\\p(\\hat{\\mu}\\ge t)\\le\\E\\left[\\exp(sX)\\right]^n\\exp(-snt)$\n\\end{lemma}\n\\begin{proof}\n$\\p(\\hat{\\mu}\\ge t) =  \\p\\left(\\exp\\left(s\\sum_{i=1}^nx_i\\right)\\ge \\exp(snt)\\right)$ hence by Markov's inequality $\\p(\\hat{\\mu}\\ge t)\\le \\E\\left[\\exp\\left(s\\sum_{i=1}^nx_i\\right)\\right]\\exp(-snt)$\\\\\nThe result follows as we assume that our samples are independant (for any independant variables $A,B$ that $\\E[AB]=\\E[A]\\E[B]$).\n\\end{proof}\n%Many phenominally powerfull probability bounds follow by finding upper bounds for $\\E\\left[\\exp(sX)\\right]$ - which is also called the moment generating function; including Hoeffing's bound:\n\n\n\\begin{theorem}[Hoeffding's inequality for mean zero]\\label{hoeffdings_inequality}\nLet $X$ be a random variable that is bounded $a\\le X\\le b$, with a mean $\\mu=0$.  Then letting $D=b-a$, then for any $t>0$, the mean $\\hat{\\mu}$ of $n$ independent samples of $X$ is bounded:\n$\\p(\\hat{\\mu}\\ge t)\\le \\exp\\left(\\frac{-2nt^2}{D^2}\\right)$\n\\end{theorem}\n\\begin{proof}\nTo prove Hoeffding's inequality we develop an upper bound for $\\E[\\exp(sX)]$, if we assume variable $X$ has a probability density function $f(x)$, then we can fit a line over $\\exp(sx)$ as:\n$\\label{Hoeffdings_line_fitting}\\E[\\exp(sX)] = \\int_a^bf(x)\\exp(sx)dx \\le \\int_a^bf(x)(\\frac{x-a}{b-a}e^{sb} + \\frac{b-x}{b-a}e^{sa})dx$\\\\\nUsing the fact that the mean $\\mu = \\int_a^bf(x)xdx = 0$ thus:\n$\\E[\\exp(sX)] \\le \\frac{1}{sb-sa}\\left(sb\\exp(sa) - sa\\exp(sb) \\right)$\\\\\nGiven the fact that for any $\\kappa,\\gamma$:\n$\\frac{1}{\\kappa-\\gamma}(\\kappa\\exp(\\gamma)-\\gamma\\exp(\\kappa))\\le \\exp\\left(\\frac{1}{8}(\\kappa-\\gamma)^2\\right)~~~~~\\refstepcounter{equation}(\\theequation)\\label{Hoeffdings_lemma} $\\\\\nThus $\\label{hoeffdings_lemma_eq}\\E[\\exp(sX)] \\le \\exp\\left(\\frac{1}{8}s^2(b-a)^2 \\right)$\nand by our Chernoff bound (lemma \\ref{chernoff1}) we get:\n$ \\p(\\hat{\\mu}\\ge t) \\le \\exp\\left(\\frac{1}{8}s^2(b-a)^2 n-snt\\right) $\nAnd minimising with respect to $s$ gives the result.\n\\end{proof}\n\\-\\hspace{1cm}\\\\\nAt a first glance, the most limiting feature of this derivation is the requirement that the mean is zero, however this is ultimately immaterial and simplifies the derivation. We just consider our data as if it were shifted to have a mean of zero, leaving $D$ unchanged. hence we get the equation we know and love:\\\\\n\n\\begin{theorem}[Hoeffding's inequality]\\label{Hoeffdings_inequality_proper}\nLet $X$ be a real-valued random variable that is bounded $a\\le X\\le b$.  Then for $D=b-a$ and any $t>0$, the mean $\\hat{\\mu}$ of $n$ independent samples of $X$ is probability bounded by:\\\\\n\\begin{equation}\\p(\\hat{\\mu}-\\mu\\ge t)\\le \\exp\\left(-2nt^2/D^2\\right)\n\\quad\\text{Or by rearranging:}\\quad\n\\p\\left(\\hat{\\mu}-\\mu\\ge \\sqrt{D^2\\log(1/t)/(2n)}\\right)\\le t\\end{equation}\n\\end{theorem}\n\\-\\hspace{1cm}\\\\\nHowever we can easily do better.\\\\\n\n\\begin{theorem}\\label{hoeffdings_inequality22}\nLet $X$ be a real-valued random variable that is bounded $a\\le X\\le b$, with a mean $\\mu$ of zero.  Then for $t>0$, the mean $\\hat{\\mu}$ of $n$ independent samples of $X$ is probability bounded by:\n\\begin{equation}\\p(\\hat{\\mu}\\ge t)\\le \\left( \\frac{b}{b-a}\\left(\\frac{b(a-t)}{a(b-t)}\\right)^{\\frac{a-t}{b-a}} -\\frac{a}{b-a}\\left(\\frac{b(a-t)}{a(b-t)}\\right)^{\\frac{b-t}{b-a}}  \\right)^n\n\\end{equation}\n\\end{theorem}\n\\begin{proof}\nExactly the same proof as Theorem \\ref{hoeffdings_inequality} except do not use Equation \\ref{Hoeffdings_lemma}, leading to:\\\\\n$ \\p(\\hat{\\mu}\\ge t) \\le (b\\exp(sa) - a\\exp(sb))^n\\exp(-snt)(b-a)^{-n} $ and minimising with respect to $s$ gives the result.\n%$$ s = \\frac{1}{b-a}\\log\\left(\\frac{b(a - t)}{a(b - t)}\\right) $$\n\\end{proof}\n\\-\\hspace{1cm}\\\\\nNow, this concentration inequality is more powerful but more difficult to manipulate, we also dont usually know $a$ or $b$ (since that would correspond to knowing the mean itself). But we usually know that our data is bounded, for instance if we are dealing with binary data then we know that, our variable $X$ (not shifted to have a zero mean) is bounded $0<X<1$, and we directly get:\\\\\n\n\\begin{theorem}[Also called Hoeffding's inequality]\\label{hoeffdings_inequality23}\nLet $X$ be a real-valued random variable that is bounded $0\\le X\\le 1$, with mean $\\mu$. Then for $t>0$, the mean $\\hat{\\mu}$ of $n$ independent samples of $X$ is probability bounded by:\n\\begin{equation}\\p(\\hat{\\mu}-\\mu\\ge t)\\le \\left[\\left(\\frac{1-\\mu}{1-t-\\mu}\\right)^{1-t-\\mu}  \\left(\\frac{\\mu}{t+\\mu}\\right)^{t+\\mu}\\right]^n\n\\end{equation}\n\\end{theorem}\n\\begin{proof}Follows directly from Theorem \\ref{hoeffdings_inequality22} with the substitution $a=-\\mu$ and $b=1-\\mu$.\n\\end{proof}\n\nThis eqution is also credited to Hoeffding and is found widely in literature.\nSo, if you have binary data and your sample mean $\\hat{\\mu}$ and you want know how likely it is at underestimating the data mean $\\mu$ by $t$ then this equation gives this (the equivalent inequality for overestimation is similar)\n\n\\pagebreak\n\nSo, how much improvement is given by Theorem \\ref{hoeffdings_inequality23} over our Hoeffding's inequality Theorem \\ref{Hoeffdings_inequality_proper} over what might be achieved perfectly?\\\\ Consider the following figure:\n\\-\\hspace{1cm}\\\\\n\n\n\n\\begin{figure}[h]\n\\centering\n\n\\begin{tikzpicture}[xscale=18.7, yscale=3]\n\\draw[->] (-0.1,0) -- (0.3,0) node[anchor=north] {$t$};\n\\draw[->] (0,0) -- (0,1.1) node[anchor=east] {};\n\\draw[smooth, domain=0:0.3, color=black, line width=0.20mm, samples=100] \n    plot (\\x,{e^(-2*9*(\\x*\\x))}) node [above] {};\n\\draw[smooth, domain=0:0.15, color=red, line width=0.20mm, samples=100] \n    plot (\\x,{((((1-0.85)/(1-\\x-0.85))^(1-\\x-0.85)) * (((0.85)/(\\x+0.85))^(\\x+0.85)))^9}) node [right] {};\n\n%\\draw[smooth, domain=0:0.85, color=black, line width=0.20mm] \n%    plot (0,0)(1,1) node [above] {};\n\n\\draw [color=blue] plot coordinates {((0, 1.0) (0.01, 0.5858470553103369) (0.02, 0.541116769443986) (0.03, 0.4940266224163914) (0.04, 0.4448836480573838) (0.05, 0.39410018156932936) (0.060000000000000005, 0.34221013038093756) (0.07, 0.2898869021427757) (0.08, 0.23796310401811177) (0.09, 0.1874521323190363) (0.09999999999999999, 0.13957177653389025) (0.10999999999999999, 0.09576996688795385) (0.11999999999999998, 0.057752799775041316) (0.12999999999999998, 0.02751498069314216) (0.13999999999999999, 0.007372829712548668) (0.15, 0.0)\n};\n\n\\draw (0.1,-0.1) -- (0.1,0.1);\n\\draw\t(0.1,-0.25) node{{\\scriptsize $0.1$}};\n\n\\draw (0.05,-0.1) -- (0.05,0.1);\n\\draw\t(0.05,-0.25) node{{\\scriptsize $0.05$}};\n\n\\draw (0.15,-0.1) -- (0.15,1);\n\\draw\t(0.15,-0.25) node{{\\scriptsize $0.15$}};\n\n\\draw\t(0.0,-0.25) node{{\\scriptsize $0$}};\n\n\\draw\t(-0.01,1) node{{\\scriptsize $1$}};\n\n\\end{tikzpicture}\n\n\\caption{for binary data, if your sample mean is $\\hat{\\mu}=0.85$, the probability envelopes of Hoeffdings inequality (black) and from Theorem \\ref{hoeffdings_inequality23} (red) above a hypothetical minimum (blue) for $n=9$ }\n\\label{fig:graph111}\n\\end{figure}\n\nAnd from this figure, we can see that the bound derived from Theorem \\ref{hoeffdings_inequality23} as the red line is below the black line corresponding to Hoeffding's inequality (Theorem \\ref{Hoeffdings_inequality_proper}).\nThe ideal blue bound (or atleast what I currently suspect is ideal (!) - contact me if you might like to do collaboration or something) is as follows:\n\n$$\\p(\\hat{\\mu}-\\mu>t)\\le\\max\\left(\\left(1+\\frac{t}{\\hat{\\mu}-1}\\right)^n,\\sum_{m=0}^{\\lfloor \\hat{\\mu}n\\rfloor}\\binom{n}{m}\n\\left(\\frac{(\\hat{\\mu}+t-1)(n-\\lfloor \\hat{\\mu}n \\rfloor)}{n(1-\\hat{\\mu})}\\right)^{n-m}\n\\left(1-\\frac{(\\hat{\\mu}+t-1)(n-\\lfloor \\hat{\\mu}n \\rfloor)}{n(1-\\hat{\\mu})}\\right)^{m}\n\\right)$$\n\nWhich I anticipate is the result of Optimal Uncertainty Quantification procedure \\cite{doi:10.1137/10080782X} - which basically is the process of searching directly for the worst case probability distribution for your random variables constrained by what you know.\\\\\n\nIn anycase, the literature on concentration inequalities is simply vast, and there are lots of improvements to be made, and an array of techniques which can be applied.\nSticking to the original Hoeffding's inequality is safe for publication purposes - as people understand and know it.\nbut there is no reason to stay bound to what we are familiar with.\n\n\\section{an additional note}\nSo, in deriving (most, but importantly not all) concentration inequalities (such as Hoeffding's) we start with the assumption of distribution parameters and then deduce the likely error of sampling statistics from that. However the way in which we often use these inequalities is in reverse, starting from knowledge of sampling statistics and then making inferences about the distribution parameters.\nAnd if you are a baysian like I am, you should be very worried... as this is technically invalid use.\nHowever, I understand that ultimately the same problem is part of statistical hypothesis testing generally.\n\n\n\\bibliographystyle{plain}\n%\\bibliographystyle{authordate1}\n\\bibliography{bib}\n\n\n\\end{document}\n", "meta": {"hexsha": "2d5b1a3326409b5a3d01d01de8ddcbf36d8c75c2", "size": 10736, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "note/note.tex", "max_stars_repo_name": "Markopolo141/Engineered-Empirical-Burnstein-Bound", "max_stars_repo_head_hexsha": "cb848d808c924c57c759fb42136e8e781a2de5fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "note/note.tex", "max_issues_repo_name": "Markopolo141/Engineered-Empirical-Burnstein-Bound", "max_issues_repo_head_hexsha": "cb848d808c924c57c759fb42136e8e781a2de5fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "note/note.tex", "max_forks_repo_name": "Markopolo141/Engineered-Empirical-Burnstein-Bound", "max_forks_repo_head_hexsha": "cb848d808c924c57c759fb42136e8e781a2de5fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.6444444444, "max_line_length": 536, "alphanum_fraction": 0.7106929955, "num_tokens": 3605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.9073122288794594, "lm_q1q2_score": 0.8374847215076721}}
{"text": "\n\\subsection{The infinite cyclic group (\\(Z\\))}\n\n\\subsubsection{The additive group of integers}\n\n\\subsubsection{Generating cyclic groups}\n\nWe can generate a group with a single element, it is a cyclic group.\n\nFor example, we can define a group \\(G=<1>\\) which gives us the additive group of integers.\n\n\\subsubsection{Infinite cyclic groups are isomorphic to the additive group of integers}\n\nMore generally, any infinite cyclic group is isomorphic to the additive group of integers.\n\nConsider the multiplicative group of \\(< i >\\).\n\nThis contains \\(\\{1,-1,i,-i \\} \\).\n\nThis is also automorphic to the natural number and modulo addition group above.\n\nWe can define finite cyclic groups of size \\(n\\) using the generating element \\(z^{\\dfrac{1}{n}}\\). This is isomorphic to the general cyclic group \\(C_n\\), and to \\(Z/nZ\\).\n\n\\subsubsection{Abelian cyclic groups}\n\nCyclic groups are abelian.\n\n", "meta": {"hexsha": "0ab79460c768f3d3ca7fb1405ef48a8ab9e4116b", "size": 890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/04-02-cyclicInf.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/groups/04-02-cyclicInf.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/groups/04-02-cyclicInf.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7857142857, "max_line_length": 172, "alphanum_fraction": 0.7460674157, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954105, "lm_q2_score": 0.8933094060543488, "lm_q1q2_score": 0.8372192122825775}}
{"text": "\\documentclass[oneside, 11pt]{article}\n\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\\usepackage{bm}\n\\usepackage{cleveref}\n\\usepackage{txfonts}\n\n\\DeclareMathOperator{\\cov}{cov}\n\n\\allowdisplaybreaks\n\n\\begin{document}\n\nConsider regression with Gaussian Processes. It relies on a matrix $K$ that represents the assumed covariance between samples. If we have two samples $\\mathbf{x}$ and $\\mathbf{x}'$, the covariance $\\cov\\left[f(\\mathbf{x}),f(\\mathbf{x}')\\right] = k(\\mathbf{x}, \\mathbf{x}')$ for some $k$ that we assume. Usually \\[\n    \\lim_{\\left\\|\\mathbf{x} - \\mathbf{x}'\\right\\| \\to 0}k(\\mathbf{x}, \\mathbf{x}') = 1\n\\] and \\[\n    \\lim_{\\left\\|\\mathbf{x} - \\mathbf{x}'\\right\\| \\to \\infty}k(\\mathbf{x}, \\mathbf{x}') = 0 \\text{.}\n\\]\n\nThis works well when we know $\\mathbf{x}$ and $\\mathbf{x}'$ exactly, but fails if we only know them up to an uncertainty. Suppose all we know if that $\\mathbf{x}$ is a sample from $\\mathcal{N}(\\bm{\\mu}, \\Sigma)$ and $\\mathbf{x}'$ is a sample from $\\mathcal{N}(\\bm{\\mu}', \\Sigma')$ for some small $\\|\\bm{\\mu} - \\bm{\\mu}'\\|$ and very large spreads $\\Sigma$ and $\\Sigma'$. By our na\\\"ive definition,\\[\n    \\cov\\left[f(\\mathbf{x}),f(\\mathbf{x}')\\right] = k(\\bm{\\mu}, \\bm{\\mu}') \\approx 1 \\text{.}\n\\] However, for $\\Sigma$ and $\\Sigma'$ large enough, we expect\\[\n    \\cov\\left[f(\\mathbf{x}),f(\\mathbf{x}')\\right] \\approx 0 \\text{.}\n\\]\n\nIt is thus desirable to extend the definition of kernels $k$ such that they are not just a function $k(\\mathbf{x}, \\mathbf{x}')$ of known values, but a function $k(\\mathcal{P}_\\mathbf{x}, \\mathcal{P}_{\\mathbf{x}'})$ of their probability distributions. This permits us to account for uncertainties of input data in scientific contexts. We derive this extended definition.\n\nFor known values $\\mathbf{x}$ and $\\mathbf{x}'$, the definition of $\\cov[f(\\mathbf{x}),f(\\mathbf{x}')]$ is \\begin{align*}\n    \\cov\\left[f(\\mathbf{x}),f(\\mathbf{x}')\\right] &= \\mathbb{E}\\left[\\left(f\\left(\\mathbf{x}\\right) - \\mathbb{E}\\left[f\\left(\\mathbf{x}\\right)\\right]\\right)\\left(f\\left(\\mathbf{x}'\\right) - \\mathbb{E}\\left[f\\left(\\mathbf{x}'\\right)\\right]\\right)\\right] \\\\\n    &= \\mathbb{E}\\left[f\\left(\\mathbf{x}\\right)f\\left(\\mathbf{x}'\\right)\\right] \\\\\n    &= \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} y y' p\\left(y = f\\left(\\mathbf{x}\\right), y' = f\\left(\\mathbf{x}'\\right)\\right) dy'dy \\\\\n    &= k(\\mathbf{x}, \\mathbf{x}')\n\\end{align*} since $\\mathbb{E}[f(\\mathbf{x})] = \\mathbb{E}[f(\\mathbf{x}')] = 0$ by the Gaussian process prior.\n\nFor values of $\\mathbf{x}$ and $\\mathbf{x}'$ sampled from $\\mathcal{P}_\\mathbf{x}$ and $\\mathcal{P}_{\\mathbf{x}'}$ respectively,  \\begin{align*}\n    \\cov\\left[f(\\mathbf{x}),f(\\mathbf{x}')\\right] &= \\mathbb{E}\\left[\\left(f\\left(\\mathbf{x}\\right) - \\mathbb{E}\\left[f\\left(\\mathbf{x}\\right)\\right]\\right)\\left(f\\left(\\mathbf{x}'\\right) - \\mathbb{E}\\left[f\\left(\\mathbf{x}'\\right)\\right]\\right)\\right] \\\\\n    &= \\mathbb{E}\\left[f\\left(\\mathbf{x}\\right)f\\left(\\mathbf{x}'\\right)\\right] \\\\\n    &= \\int_{\\mathcal{X}}\\int_{\\mathcal{X}}\\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} y y' p\\left(y = f\\left(\\mathbf{x}\\right), y' = f\\left(\\mathbf{x}'\\right)\\right) \\mathcal{P}_{\\mathbf{x}}(\\mathbf{x}) \\mathcal{P}_{\\mathbf{x}'}(\\mathbf{x}') dy'dyd\\mathbf{x}d\\mathbf{x}' \\\\\n    &= \\int_{\\mathcal{X}}\\int_{\\mathcal{X}}\\mathcal{P}_{\\mathbf{x}}(\\mathbf{x}) \\mathcal{P}_{\\mathbf{x}'}(\\mathbf{x}')\\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} y y' p\\left(y = f\\left(\\mathbf{x}\\right), y' = f\\left(\\mathbf{x}'\\right)\\right)  dy'dyd\\mathbf{x}d\\mathbf{x}' \\\\\n    &= \\int_{\\mathcal{X}}\\int_{\\mathcal{X}}\\mathcal{P}_{\\mathbf{x}}(\\mathbf{x}) \\mathcal{P}_{\\mathbf{x}'}(\\mathbf{x}')k(\\mathbf{x}, \\mathbf{x}')d\\mathbf{x}d\\mathbf{x}' \\text{,}\n\\end{align*} where $k(\\mathbf{x}, \\mathbf{x}')$ is the kernel defined on $\\mathbf{x}$ and $\\mathbf{x}'$ with no uncertainty.\n\nFor $\\mathcal{P}_\\mathbf{x} = \\mathcal{N}(\\bm{\\mu}, \\Sigma)$ and $\\mathcal{P}_{\\mathbf{x}'} = \\mathcal{N}(\\bm{\\mu}', \\Sigma')$, and for the Gaussian kernel $k(\\mathbf{x}, \\mathbf{x}') = \\exp(-\\frac12(\\mathbf{x} - \\mathbf{x}')^\\top S^{-1} (\\mathbf{x} - \\mathbf{x}')$, our kernel with uncertainty \\begin{align*}\n    k(\\mathcal{P}_\\mathbf{x}, \\mathcal{P}_{\\mathbf{x}'}) \\\\\n    &= \\int_{\\mathcal{X}}\\int_{\\mathcal{X}}\\mathcal{P}_{\\mathbf{x}}(\\mathbf{x}) \\mathcal{P}_{\\mathbf{x}'}(\\mathbf{x}')k(\\mathbf{x}, \\mathbf{x}')d\\mathbf{x}d\\mathbf{x}' \\\\\n    &= \\sqrt{\\frac{\\det S}{\\det\\left(\\Sigma + \\Sigma' + S\\right)}} \\exp\\left(-\\frac{1}{2}\\left(\\bm{\\mu}' - \\bm{\\mu}\\right)^\\top \\left( \\Sigma + \\Sigma' + S\\right)^{-1}\\left(\\bm{\\mu}' - \\bm{\\mu}\\right)\\right) \\text{.}\n\\end{align*} See \\cref{sec:integral} for the derivation.\n\n\\appendix\n\\section{Finding the integral}\n\\label{sec:integral}\n\n    We want to find the integral\\begin{align*}\n        &\\int_{\\mathbb{R}^d} \\det(2\\pi\\Sigma)^{-1/2} \\exp\\left(-\\frac12 \\left(\\mathbf{x}-\\bm{\\mu}\\right)^\\top \\Sigma^{-1} \\left(\\mathbf{x}-\\bm{\\mu}\\right) \\right) \\\\\n        &\\hspace{30pt} \\int_{\\mathbb{R}^d} \\det(2\\pi\\Sigma')^{-1/2} \\exp\\left(-\\frac12 \\left(\\mathbf{x}'-\\bm{\\mu}'\\right)^\\top \\Sigma'^{-1} \\left(\\mathbf{x'}-\\bm{\\mu}'\\right) \\right) \\\\\n        &\\hspace{60pt}\\exp\\left(-\\frac12 \\left(\\mathbf{x}'-\\mathbf{x}\\right)^\\top S^{-1} \\left(\\mathbf{x}'-\\mathbf{x}\\right) \\right) d\\mathbf{x}' d\\mathbf{x} \\text{.}\n    \\end{align*}\n\n    We first tackle the inner integral, \\begin{align*}\n        &\\int_{\\mathbb{R}^d} \\det(2\\pi\\Sigma')^{-1/2} \\exp\\left(-\\frac12 \\left(\\mathbf{x}'-\\bm{\\mu}'\\right)^\\top \\Sigma'^{-1} \\left(\\mathbf{x'}-\\bm{\\mu}'\\right) \\right) \\\\\n        &\\hspace{60pt}\\exp\\left(-\\frac12 \\left(\\mathbf{x}'-\\mathbf{x}\\right)^\\top S^{-1} \\left(\\mathbf{x}'-\\mathbf{x}\\right) \\right) d\\mathbf{x}' \\text{,}\n    \\end{align*} where we treat $\\mathbf{x}$ as a constant.\n\n    Changing variables, \\[\n        \\mathbf{y}' \\coloneqq S^{-1/2} (\\mathbf{x}' - \\mathbf{x}) \\text{,}\n    \\] so\\[\n        \\mathbf{x}' = S^{1/2} \\mathbf{y}' + \\mathbf{x} \\text{.}\n    \\] We note that \\[\n        d\\mathbf{y}' = S^{-1/2} d\\mathbf{x}' \\text{.}\n    \\]\n\n    Then \\begin{align*}\n        &\\int_{\\mathbb{R}^d} \\det(2\\pi\\Sigma')^{-1/2} \\exp\\left(-\\frac12 \\left(\\mathbf{x}'-\\bm{\\mu}'\\right)^\\top \\Sigma'^{-1} \\left(\\mathbf{x'}-\\bm{\\mu}'\\right) \\right) \\\\\n        &\\hspace{60pt}\\exp\\left(-\\frac12 \\left(\\mathbf{x}'-\\mathbf{x}\\right)^\\top S^{-1} \\left(\\mathbf{x}'-\\mathbf{x}\\right) \\right) d\\mathbf{x}' \\\\\n        &= \\det(2\\pi\\Sigma')^{-1/2} \\left|\\det S^{1/2}\\right| \\int_{\\mathbb{R}^d} \\exp\\left(-\\frac12 \\left(S^{1/2} \\mathbf{y}' + \\mathbf{x} - \\bm{\\mu}'\\right)^\\top \\Sigma'^{-1} \\left(S^{1/2} \\mathbf{y}' + \\mathbf{x} - \\bm{\\mu}'\\right) \\right) \\\\\n        &\\hspace{150pt}\\exp\\left(-\\frac12 \\mathbf{y}'^\\top \\mathbf{y}' \\right)  d\\mathbf{y}' \\text{.}\n    \\end{align*}\n\n    Setting \\[\n        C' \\coloneqq S^{\\frac12}\\Sigma'^{-1}S^{\\frac12}\n    \\] and \\[\n        \\mathbf{m'} \\coloneqq -S^{-\\frac12} (\\mathbf{x} - \\bm{\\mu}') \\text{,}\n    \\] this changes to \\begin{align*}\n        &\\int_{\\mathbb{R}^d} \\exp\\left(-\\frac12 \\left(S^{1/2} \\mathbf{y}' + \\mathbf{x} - \\bm{\\mu}'\\right)^\\top \\Sigma'^{-1} \\left(S^{1/2} \\mathbf{y}' + \\mathbf{x} - \\bm{\\mu}'\\right) \\right) \\exp\\left(-\\frac12 \\mathbf{y}'^\\top \\mathbf{y}' \\right)  d\\mathbf{y}' \\\\\n        &= \\int_{\\mathbb{R}^d} \\exp\\left(-\\frac12 \\left(\\mathbf{y}' - \\mathbf{m}'\\right)^\\top C' \\left(\\mathbf{y}' - \\mathbf{m}'\\right) \\right) \\exp\\left(-\\frac12 \\mathbf{y}'^\\top \\mathbf{y}' \\right)  d\\mathbf{y}' \\text{.}\n    \\end{align*}\n\n    In the 1-dimensional case we get \\begin{align*}\n        &\\int_{-\\infty}^{\\infty} \\exp\\left(-\\frac{c'}2 \\left(y' - m'\\right)^2 \\right) \\exp\\left(-\\frac12 y'^2 \\right)  dy \\\\\n        &= \\frac{\\sqrt{2\\pi}}{\\sqrt{1 + c'}} \\exp\\left(-\\frac{1}{2}\\frac{c'}{1+c'}m'^2 \\right) \\text{.}\n    \\end{align*}\n\n    In the 2-dimensional case, \\begin{align*}\n        &\\int_{\\mathbb{R}^2} \\exp\\left(-\\frac12 \\left(\\mathbf{y}' - \\mathbf{m}'\\right)^\\top C' \\left(\\mathbf{y}' - \\mathbf{m}'\\right) \\right) \\exp\\left(-\\frac12 \\mathbf{y}'^\\top \\mathbf{y}' \\right)  d\\mathbf{y}' \\\\\n        &= 2 \\pi \\sqrt{\\frac{1}{\\det(I + C')}} \\exp\\left(-\\frac{1}{2}\\mathbf{m}'^\\top \\left(C'^{-1} + I\\right)^{-1}\\mathbf{m}'\\right) \\text{.}\n    \\end{align*}\n\n    In the 3-dimensional case Mathematica shits itself and outputs hundreds of lines of symbols. For a simplified scenario where $C'$ is diagonal, we get\\begin{align*}\n        &\\int_{\\mathbb{R}^3} \\exp\\left(-\\frac12 \\left(\\mathbf{y}' - \\mathbf{m}'\\right)^\\top C' \\left(\\mathbf{y}' - \\mathbf{m}'\\right) \\right) \\exp\\left(-\\frac12 \\mathbf{y}'^\\top \\mathbf{y}' \\right)  d\\mathbf{y}' \\\\\n        &= (2 \\pi)^{3/2} \\sqrt{\\frac{1}{\\det(I + C')}} \\exp\\left(-\\frac{1}{2}\\mathbf{m}'^\\top \\left(C'^{-1} + I\\right)^{-1}\\mathbf{m}'\\right) \\text{.}\n    \\end{align*}\n\n    We recognise the pattern, \\begin{align*}\n        &\\int_{\\mathbb{R}^d} \\exp\\left(-\\frac12 \\left(\\mathbf{y}' - \\mathbf{m}'\\right)^\\top C' \\left(\\mathbf{y}' - \\mathbf{m}'\\right) \\right) \\exp\\left(-\\frac12 \\mathbf{y}'^\\top \\mathbf{y}' \\right)  d\\mathbf{y}' \\\\\n        &= (2 \\pi)^{d/2} \\sqrt{\\frac{1}{\\det(I + C')}} \\exp\\left(-\\frac{1}{2}\\mathbf{m}'^\\top \\left(C'^{-1} + I\\right)^{-1}\\mathbf{m}'\\right) \\text{.}\n    \\end{align*}\n\n    Substituting back,\\begin{align*}\n        &(2 \\pi)^{d/2} \\sqrt{\\frac{1}{\\det(I + C')}} \\exp\\left(-\\frac{1}{2}\\mathbf{m}'^\\top \\left(C'^{-1} + I\\right)^{-1}\\mathbf{m}'\\right) \\\\\n        &= (2 \\pi)^{d/2} \\sqrt{\\frac{1}{\\det\\left(I + S^{\\frac12}\\Sigma'^{-1}S^{\\frac12}\\right)}} \\exp\\left(-\\frac{1}{2}\\mathbf{m}'^\\top \\left(S^{-\\frac12}\\Sigma'S^{-\\frac12} + I\\right)^{-1}\\mathbf{m}'\\right) \\\\\n        &= (2 \\pi)^{d/2} \\sqrt{\\frac{1}{\\det\\left(I + S^{\\frac12}\\Sigma'^{-1}S^{\\frac12}\\right)}} \\exp\\left(-\\frac{1}{2}\\left(-S^{-\\frac12} \\left(\\mathbf{x} - \\bm{\\mu}'\\right)\\right)^\\top \\left(S^{-\\frac12}\\Sigma'S^{-\\frac12} + I\\right)^{-1}\\left(-S^{-\\frac12} \\left(\\mathbf{x} - \\bm{\\mu}'\\right)\\right)\\right) \\\\\n        &= (2 \\pi)^{d/2} \\sqrt{\\frac{1}{\\det\\left(I + S^{\\frac12}\\Sigma'^{-1}S^{\\frac12}\\right)}} \\exp\\left(-\\frac{1}{2}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)^\\top \\left(\\Sigma' + S\\right)^{-1}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)\\right) \\text{.}\n    \\end{align*}\n\n    Hence, \\begin{align*}\n        &\\int_{\\mathbb{R}^d} \\det(2\\pi\\Sigma')^{-1/2} \\exp\\left(-\\frac12 \\left(\\mathbf{x}'-\\bm{\\mu}'\\right)^\\top \\Sigma'^{-1} \\left(\\mathbf{x'}-\\bm{\\mu}'\\right) \\right) \\\\\n        &\\hspace{60pt}\\exp\\left(-\\frac12 \\left(\\mathbf{x}'-\\mathbf{x}\\right)^\\top S^{-1} \\left(\\mathbf{x}'-\\mathbf{x}\\right) \\right) d\\mathbf{x}' \\\\\n        &= \\det(2\\pi\\Sigma')^{-1/2} \\left|\\det S^{1/2}\\right| \\int_{\\mathbb{R}^d} \\exp\\left(-\\frac12 \\left(S^{1/2} \\mathbf{y}' + \\mathbf{x} - \\bm{\\mu}'\\right)^\\top \\Sigma'^{-1} \\left(S^{1/2} \\mathbf{y}' + \\mathbf{x} - \\bm{\\mu}'\\right) \\right) \\\\\n        &\\hspace{150pt}\\exp\\left(-\\frac12 \\mathbf{y}'^\\top \\mathbf{y}' \\right)  d\\mathbf{y}' \\\\\n        &= \\det(2\\pi\\Sigma')^{-1/2} \\left|\\det S^{1/2}\\right| (2 \\pi)^{d/2} \\sqrt{\\frac{1}{\\det\\left(I + S^{\\frac12}\\Sigma'^{-1}S^{\\frac12}\\right)}} \\exp\\left(-\\frac{1}{2}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)^\\top \\left(\\Sigma' + S\\right)^{-1}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)\\right) \\\\\n        &=  \\sqrt{\\frac{\\det S}{\\det\\Sigma'\\det\\left(I + S^{\\frac12}\\Sigma'^{-1}S^{\\frac12}\\right)}} \\exp\\left(-\\frac{1}{2}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)^\\top \\left(\\Sigma' + S\\right)^{-1}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)\\right) \\\\\n        &=  \\sqrt{\\frac{1}{\\det\\left(\\Sigma'S^{-1} + I\\right)}} \\exp\\left(-\\frac{1}{2}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)^\\top \\left(\\Sigma' + S\\right)^{-1}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)\\right)\n    \\end{align*}\n\n    Now tackling the outer integral, \\begin{align*}\n        &\\int_{\\mathbb{R}^d} \\det(2\\pi\\Sigma)^{-1/2} \\exp\\left(-\\frac12 \\left(\\mathbf{x}-\\bm{\\mu}\\right)^\\top \\Sigma^{-1} \\left(\\mathbf{x}-\\bm{\\mu}\\right) \\right) \\\\\n        &\\hspace{30pt} \\int_{\\mathbb{R}^d} \\det(2\\pi\\Sigma')^{-1/2} \\exp\\left(-\\frac12 \\left(\\mathbf{x}'-\\bm{\\mu}'\\right)^\\top \\Sigma'^{-1} \\left(\\mathbf{x'}-\\bm{\\mu}'\\right) \\right) \\\\\n        &\\hspace{60pt}\\exp\\left(-\\frac12 \\left(\\mathbf{x}'-\\mathbf{x}\\right)^\\top S^{-1} \\left(\\mathbf{x}'-\\mathbf{x}\\right) \\right) d\\mathbf{x}' d\\mathbf{x} \\\\\n        &= \\int_{\\mathbb{R}^d} \\det(2\\pi\\Sigma)^{-1/2} \\exp\\left(-\\frac12 \\left(\\mathbf{x}-\\bm{\\mu}\\right)^\\top \\Sigma^{-1} \\left(\\mathbf{x}-\\bm{\\mu}\\right) \\right) \\\\\n        &\\hspace{30pt} \\sqrt{\\frac{1}{\\det\\left(\\Sigma'S^{-1} + I\\right)}} \\exp\\left(-\\frac{1}{2}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)^\\top \\left(\\Sigma' + S\\right)^{-1}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)\\right) d\\mathbf{x} \\\\\n        &= \\det(2\\pi\\Sigma)^{-1/2} \\sqrt{\\frac{1}{\\det\\left(\\Sigma'S^{-1} + I\\right)}} \\\\\n        &\\hspace{30pt}\\int_{\\mathbb{R}^d} \\exp\\left(-\\frac12 \\left(\\mathbf{x}-\\bm{\\mu}\\right)^\\top \\Sigma^{-1} \\left(\\mathbf{x}-\\bm{\\mu}\\right) \\right) \\exp\\left(-\\frac{1}{2}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)^\\top \\left(\\Sigma' + S\\right)^{-1}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)\\right) d\\mathbf{x} \\text{.}\n    \\end{align*}\n\n    As before, we change variables with \\[\n        \\mathbf{y} \\coloneqq \\left(\\Sigma' + S\\right)^{-\\frac12}\\left(\\mathbf{x} - \\bm{\\mu}'\\right) \\text{,}\n    \\] which implies \\[\n        \\mathbf{x} = \\left(\\Sigma' + S\\right)^{\\frac12}\\mathbf{y} + \\bm{\\mu}' \\text{,}\n    \\] so \\[\n        d\\mathbf{x} = \\left(\\Sigma' + S\\right)^{\\frac12}d\\mathbf{y} \\text{.}\n    \\] Then \\begin{align*}\n        &\\int_{\\mathbb{R}^d} \\exp\\left(-\\frac12 \\left(\\mathbf{x}-\\bm{\\mu}\\right)^\\top \\Sigma^{-1} \\left(\\mathbf{x}-\\bm{\\mu}\\right) \\right) \\exp\\left(-\\frac{1}{2}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)^\\top \\left(\\Sigma' + S\\right)^{-1}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)\\right) d\\mathbf{x} \\\\\n        &= \\left|\\det(\\Sigma' + S)^{\\frac12} \\right|\\int_{\\mathbb{R}^d} \\exp\\left(-\\frac12 \\left(\\left(\\Sigma' + S\\right)^{\\frac12}\\mathbf{y} + \\bm{\\mu}'-\\bm{\\mu}\\right)^\\top \\Sigma^{-1} \\left(\\left(\\Sigma' + S\\right)^{\\frac12}\\mathbf{y} + \\bm{\\mu}'-\\bm{\\mu}\\right) \\right) \\\\\n        &\\hspace{120pt}\\exp\\left(-\\frac{1}{2}\\mathbf{y}^\\top\\mathbf{y}\\right) d\\mathbf{y} \\text{.}\n    \\end{align*}\n\n    Setting \\[\n        C \\coloneqq \\left(\\Sigma' + S\\right)^{\\frac12} \\Sigma^{-1} \\left(\\Sigma' + S\\right)^{\\frac12}\n    \\] and \\[\n        \\mathbf{m} \\coloneqq -\\left(\\Sigma' + S\\right)^{-\\frac12} (\\bm{\\mu}' - \\bm{\\mu}) \\text{,}\n    \\] we get \\begin{align*}\n        &\\int_{\\mathbb{R}^d} \\exp\\left(-\\frac12 \\left(\\left(\\Sigma' + S\\right)^{\\frac12}\\mathbf{y} + \\bm{\\mu}'-\\bm{\\mu}\\right)^\\top \\Sigma^{-1} \\left(\\left(\\Sigma' + S\\right)^{\\frac12}\\mathbf{y} + \\bm{\\mu}'-\\bm{\\mu}\\right) \\right) \\exp\\left(-\\frac{1}{2}\\mathbf{y}^\\top\\mathbf{y}\\right) d\\mathbf{y} \\\\\n        &= \\int_{\\mathbb{R}^d} \\exp\\left(-\\frac12 \\left(\\mathbf{y} - \\mathbf{m}\\right)^\\top C \\left(\\mathbf{y} - \\mathbf{m}\\right) \\right) \\exp\\left(-\\frac{1}{2}\\mathbf{y}^\\top\\mathbf{y}\\right) d\\mathbf{y} \\text{.}\n    \\end{align*}\n\n    By our previous result, \\begin{align*}\n        &\\int_{\\mathbb{R}^d} \\exp\\left(-\\frac12 \\left(\\mathbf{y} - \\mathbf{m}\\right)^\\top C \\left(\\mathbf{y} - \\mathbf{m}\\right) \\right) \\exp\\left(-\\frac{1}{2}\\mathbf{y}^\\top\\mathbf{y}\\right) d\\mathbf{y} \\\\\n        &= (2 \\pi)^{d/2} \\sqrt{\\frac{1}{\\det(I + C)}} \\exp\\left(-\\frac{1}{2}\\mathbf{m}^\\top \\left(C^{-1} + I\\right)^{-1}\\mathbf{m}\\right) \\\\\n        &= (2 \\pi)^{d/2} \\sqrt{\\frac{1}{\\det\\left(I + \\left(\\Sigma' + S\\right)^{\\frac12} \\Sigma^{-1} \\left(\\Sigma' + S\\right)^{\\frac12}\\right)}} \\exp\\left(-\\frac{1}{2}\\mathbf{m}^\\top \\left(\\left(\\Sigma' + S\\right)^{-\\frac12} \\Sigma \\left(\\Sigma' + S\\right)^{-\\frac12} + I\\right)^{-1}\\mathbf{m}\\right) \\\\\n        &= (2 \\pi)^{d/2} \\sqrt{\\frac{1}{\\det\\left(I + \\left(\\Sigma' + S\\right)^{\\frac12} \\Sigma^{-1} \\left(\\Sigma' + S\\right)^{\\frac12}\\right)}} \\\\\n        &\\hspace{60pt}\\exp\\left(-\\frac{1}{2}\\left(\\left(\\Sigma' + S\\right)^{-\\frac12} \\left(\\bm{\\mu}' - \\bm{\\mu}\\right)\\right)^\\top \\left(\\left(\\Sigma' + S\\right)^{-\\frac12} \\Sigma \\left(\\Sigma' + S\\right)^{-\\frac12} + I\\right)^{-1}\\left(\\left(\\Sigma' + S\\right)^{-\\frac12} \\left(\\bm{\\mu}' - \\bm{\\mu}\\right)\\right)\\right) \\\\\n        &= (2 \\pi)^{d/2} \\sqrt{\\frac{1}{\\det\\left(I + \\left(\\Sigma' + S\\right)^{\\frac12} \\Sigma^{-1} \\left(\\Sigma' + S\\right)^{\\frac12}\\right)}} \\exp\\left(-\\frac{1}{2}\\left(\\bm{\\mu}' - \\bm{\\mu}\\right)^\\top \\left( \\Sigma + \\Sigma' + S\\right)^{-1}\\left(\\bm{\\mu}' - \\bm{\\mu}\\right)\\right) \\text.\n    \\end{align*}\n\n    Then \\begin{align*}\n        &\\det(2\\pi\\Sigma)^{-1/2} \\sqrt{\\frac{1}{\\det\\left(\\Sigma'S^{-1} + I\\right)}} \\\\\n        &\\hspace{30pt}\\int_{\\mathbb{R}^d} \\exp\\left(-\\frac12 \\left(\\mathbf{x}-\\bm{\\mu}\\right)^\\top \\Sigma^{-1} \\left(\\mathbf{x}-\\bm{\\mu}\\right) \\right) \\exp\\left(-\\frac{1}{2}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)^\\top \\left(\\Sigma' + S\\right)^{-1}\\left(\\mathbf{x} - \\bm{\\mu}'\\right)\\right) d\\mathbf{x} \\\\\n        &= \\det(2\\pi\\Sigma)^{-1/2} \\sqrt{\\frac{1}{\\det\\left(\\Sigma'S^{-1} + I\\right)}} \\left|\\det(\\Sigma' + S)^{\\frac12} \\right| (2 \\pi)^{d/2} \\sqrt{\\frac{1}{\\det\\left(I + \\left(\\Sigma' + S\\right)^{\\frac12} \\Sigma^{-1} \\left(\\Sigma' + S\\right)^{\\frac12}\\right)}} \\\\\n        &\\hspace{30pt} \\exp\\left(-\\frac{1}{2}\\left(\\bm{\\mu}' - \\bm{\\mu}\\right)^\\top \\left( \\Sigma + \\Sigma' + S\\right)^{-1}\\left(\\bm{\\mu}' - \\bm{\\mu}\\right)\\right) \\\\\n        &= \\sqrt{\\frac{\\det S}{\\det\\left(\\Sigma + \\Sigma' + S\\right)}} \\exp\\left(-\\frac{1}{2}\\left(\\bm{\\mu}' - \\bm{\\mu}\\right)^\\top \\left( \\Sigma + \\Sigma' + S\\right)^{-1}\\left(\\bm{\\mu}' - \\bm{\\mu}\\right)\\right) \\text{.}\n    \\end{align*}\n\n    Hence,\\begin{align*}\n        &\\int_{\\mathbb{R}^d} \\det(2\\pi\\Sigma)^{-1/2} \\exp\\left(-\\frac12 \\left(\\mathbf{x}-\\bm{\\mu}\\right)^\\top \\Sigma^{-1} \\left(\\mathbf{x}-\\bm{\\mu}\\right) \\right) \\\\\n        &\\hspace{30pt} \\int_{\\mathbb{R}^d} \\det(2\\pi\\Sigma')^{-1/2} \\exp\\left(-\\frac12 \\left(\\mathbf{x}'-\\bm{\\mu}'\\right)^\\top \\Sigma'^{-1} \\left(\\mathbf{x'}-\\bm{\\mu}'\\right) \\right) \\\\\n        &\\hspace{60pt}\\exp\\left(-\\frac12 \\left(\\mathbf{x}'-\\mathbf{x}\\right)^\\top S^{-1} \\left(\\mathbf{x}'-\\mathbf{x}\\right) \\right) d\\mathbf{x}' d\\mathbf{x} \\\\\n        &= \\sqrt{\\frac{\\det S}{\\det\\left(\\Sigma + \\Sigma' + S\\right)}} \\exp\\left(-\\frac{1}{2}\\left(\\bm{\\mu}' - \\bm{\\mu}\\right)^\\top \\left( \\Sigma + \\Sigma' + S\\right)^{-1}\\left(\\bm{\\mu}' - \\bm{\\mu}\\right)\\right) \\text{.}\n    \\end{align*}\n\n    Functionally, this makes sense. For our uncertain kernel, if $\\Sigma=\\Sigma'=0$, then we fall back to the original case. However, if they are large, then that places an upper bound on the maximum covariance that we assume. It is also a function of the difference $\\bm{\\mu}' - \\bm{\\mu}$, instead of taking each in to account separately. It is symmetric in $\\Sigma$ and $\\Sigma'$ and $\\bm{\\mu}$ and $\\bm{\\mu}'$.\n\n\\end{document}\n", "meta": {"hexsha": "4489834c55e84f634cec46cddc8ea009fb71b499", "size": 18516, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "projects/jakub-uncertainty-kernels/kernels.tex", "max_stars_repo_name": "chengsoonong/mclass-sky", "max_stars_repo_head_hexsha": "98219221c233fa490e78246eda1ead05c6cf7c17", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-06-01T12:09:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-16T05:28:01.000Z", "max_issues_repo_path": "projects/jakub-uncertainty-kernels/kernels.tex", "max_issues_repo_name": "alasdairtran/mclearn", "max_issues_repo_head_hexsha": "98219221c233fa490e78246eda1ead05c6cf7c17", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 165, "max_issues_repo_issues_event_min_datetime": "2015-01-28T10:37:34.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-23T06:55:13.000Z", "max_forks_repo_path": "projects/jakub-uncertainty-kernels/kernels.tex", "max_forks_repo_name": "alasdairtran/mclearn", "max_forks_repo_head_hexsha": "98219221c233fa490e78246eda1ead05c6cf7c17", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2015-01-24T16:27:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-01T08:54:31.000Z", "avg_line_length": 100.6304347826, "max_line_length": 413, "alphanum_fraction": 0.5719377835, "num_tokens": 7618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109713976399, "lm_q2_score": 0.8807970873650403, "lm_q1q2_score": 0.8371192154068198}}
{"text": "\\textbf{Download the program \\textsc{wave2D\\_leap\\_frog.m}. This code solves the wave equation,\n\\begin{align*}\nu_{tt}=u_{xx}+u_{yy},~~~~(x,y)\\in [-1,1]\\times [-1,1],~~t>0,\n\\end{align*}\nwith homogeneous Dirichlet boundary conditions and initial conditions\n\\begin{align*}\nu(0,x,y) = exp(-40((x\u22120.2)^2+y^2)),~~ u_t(0, x, y) = 0.\n\\end{align*}\nModify this code to solve the same problem but with homogeneous Neumann boundary instead of Dirichlet. Plot your solution at time $t= 10$. How accurate is your solution? (number of digits)\n}\n\\newline\n\nTo impose homogeneous Neumann boundary conditions we can simply ignore some rows and colums on our matrix multiplications. Taking $u_{yy}$:\n\\begin{align*}\nu_{yy} = DDu = Du_y,\n\\end{align*}\nwhere $D$ is the Chebyshev differentiation matrix. We know that $u_y$ has zero components in the first and last rows. This allows us to ignore the first and last rows of $D$ when taking the first multiplication. In addition, we can also ignore the first and last column of the second multiplication. Hence, we can simply impose Neumann boundary conditions by making,\n\\begin{align*}\nu_{yy} = D(:,2:N)D(2:N,:)u,\n\\end{align*}\nfollowing \\textsc{Matlab} notation. Analogous discussion can be made about $u_{xx}$, obtaining\n\\begin{align*}\nu_{yy} = uD(2:N,:)'D(:,2:N)',\n\\end{align*}\nwhere the $D'$ represents the transpose of $D$. The solution at $t=10$ is shown in the next figure.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{P4.png}\\caption{Numerical solution to the wave equation with homogeneous Neumann boundary conditions at $t=10$.}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Homework 4, Problem 4 -  Francisco Castillo\nclear all; close all; clc\nlabelfontsize = 14;\n%% 2D wave equation Chebyshev+Leap-frog, ZERO Neumann BC'S\nN = 64;\n[D,x] = cheb(N);\n% x = x(2:end-1);\n% D2 = D^2;\n% D2 = D2(2:end-1,2:end-1);\n \n% 2D grid\n[X,Y] = meshgrid(x);\n \n% Initial condition\nu0 = exp(-40*((X-0.2).^2+Y.^2));\nu = u0;\n \nh = 1-x(2);\ndt = h/2;\nt = 0;\ntf = 10;\ncount=0;\n\nwhile t<tf\n    if t+dt>tf\n        dt = tf-t;\n    else\n        dt = h/2;\n    end\n    uyy = D(:,2:N)*D(2:N,:)*u;\n    uxx = u*D(2:N,:)'*D(:,2:N)';\n    u2 = 2*u- u0 + dt^2*(uxx+uyy);\n    u0 = u;\n    u = u2;\n    \n    if count == 10 \n        surf(X,Y,u)\n        zlim([-1 1])\n        drawnow\n        shg\n        count = 0;\n    end\n        \n    count = count+1;\n    t = t+dt;\n    \n    if t == tf\n        surf(X,Y,u)\n        zlim([-1 1])\n        drawnow\n        shg\n        xlabel('$x$','interpreter','latex','fontsize',labelfontsize)\n        ylabel('$y$','interpreter','latex','fontsize',labelfontsize)\n        zlabel('$u(x,y)$','interpreter','latex','fontsize',labelfontsize)\n        set(get(gca,'ZLabel'),'Rotation',0)\n        saveas(gcf,'Latex/FIGURES/P4','png')\n    end\nend\n\\end{verbatim}", "meta": {"hexsha": "5326aab9fe6e428c4f04f9deb2f519fa753afd69", "size": 2813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework4/Latex/problem4.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework4/Latex/problem4.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework4/Latex/problem4.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.5760869565, "max_line_length": 366, "alphanum_fraction": 0.6338428724, "num_tokens": 932, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.912436169406061, "lm_q1q2_score": 0.8369801290239834}}
{"text": "%================================\n\\section{Metrizability}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t[metric spaces]\n\t\\label{def: metric spaces}\n\tLet $X$ be any set. A \\textit{metric} $\\rho$ on $X$ is a function $\\rho: X \\times X \\to \\mathbb R$ satisfying the following conditions: for all $x,y,z \\in X$\n\t\\begin{enumerate}[(i)]\n\t\t\\item $\\rho(x,y) \\ge 0$, and $\\rho(x,y) = 0$ iff $x = y$;\n\t\t\\item $\\rho(x,y) = \\rho(y,z)$;\n\t\t\\item $\\rho(x,z) + \\rho(z,y) \\ge \\rho(x,y)$.\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[balls]\n\t\\label{def: balls}\n\tLet $(X, \\rho)$ be a metric space, let $x \\in X$, and let $\\varepsilon \\in \\mathbb R_{> 0}$. The \\textit{open $\\varepsilon$-ball about $x$} or just \\textit{$\\varepsilon$-ball about $x$} is defined to be\n\t$$\n\tB(x, \\varepsilon) = \\left\\{ y \\in X : \\rho(x,y) < \\varepsilon \\right\\}.\n\t$$\n\tThe \\textit{closed $\\varepsilon$-ball about $x$} is defined to be\n\t$$\n\t\\overline B (x, \\varepsilon) = \\{ y \\in X : \\rho(x,y) \\le \\varepsilon \\}.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t\\label{eg: Euclidean metrics}\n\tLet $X$ be any set, and let metric $\\rho_p$ on $X^n$ ($n \\in \\mathbb Z_{>0}$) defined by\n\t$$\n\t\\rho_p (x,y) = \\left( \\sum_{i = 1}^n |x_i - y_i|^p \\right)^\\frac{1}{p},\n\t$$\n\twhere $p \\in \\mathbb R_{\\ge 1}$. $\\rho_2$ is so called the \\textit{standard Euclidean metric}. If $X = \\mathbb R$, then the metric space $(\\mathbb R^n, \\rho_2)$ is so-called \\textit{Euclidean $n$-space}.\n\t\n\tFor all $p,q \\in \\mathbb R_{\\ge 1}$, if $p < q$, then for all $\\varepsilon \\in \\mathbb R_{> 0}$ and for all $x,y \\in X$, $\\rho_p(x,y) \\ge \\rho_q(x,y)$; in particular, $\\rho_p = \\rho_q$ iff there is a unique $k \\in \\{1, \\ldots, n\\}$, such that for all $i \\in \\{1, \\ldots, n\\} \\setminus \\{k\\}$, $x_i = 0$. As $\\rho_p(x,y)$ is always ``overestimated'' than $\\rho_q(x,y)$, we have $B_{\\rho_p}(x, \\varepsilon) \\supseteq B_{\\rho_q}(x,\\varepsilon)$.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t\\label{eg: discrete metric}\n\tLet $X$ be any set. The \\textit{discrete metric} $\\rho$ on $X$ is defined to be\n\t$$\n\t\\rho(x,y) =\n\t\\begin{cases}\n\t\t0 & \\text{if $x = y$}, \\\\\n\t\t1 & \\text{otherwise}.\n\t\\end{cases}\n\t$$\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tLet $a,b \\in \\mathbb R$ with $a< b$, and let metric $\\rho_p$ on $C[a,b]$ defined by\n\t$$\n\t\\rho_p (f, g) = \\left( \\int_a^b |f(t) - g(t)|^p dt \\right)^\\frac{1}{p},\n\t$$\n\twhere $p \\ge 1$. In particular,\n\t$$\n\t\\rho_\\infty (f,g) = \\sup_{t \\in [a,b]} |f(t) - g(t)|.\n\t$$\n\\end{example}\n%--------------------------------\n\n% todo: more examples\n% 1. Hamming metric\n% 2. Great circle metric\n% 3. Hausdorff metric\n\n\n%--------------------------------\n\\begin{theorem}\n\tLet $(X, \\rho)$ be a metric space, and let\n\t$$\n\t\\mathcal T_\\rho = \\left\\{ \\bigcup_{x \\in U} B_\\rho (x, \\varepsilon) : U \\subseteq X \\land \\varepsilon \\in \\mathbb R_{> 0} \\right\\}.\n\t$$\n\t$(X, \\mathcal T_\\rho)$ is a topological space; i.e., $\\mathcal T_\\rho$ satisfies the open set axioms (Definition \\ref{def: topology}).\n\t\n\t\\begin{proof}\n\t\tFor O1. Apparently, there exists (for any) $\\varepsilon \\in \\mathbb R_{> 0}$,\n\t\t$$\n\t\tX = \\bigcup_{x \\in X} B(x, \\varepsilon).\n\t\t$$\n\t\t\n\t\tFor O2. Let $I$ be an index set, and let $U_i \\in T$ for all $i \\in I$. There exists $\\varepsilon \\in \\mathbb R_{> 0}$ we can define\n\t\t$$\n\t\tU = \\bigcup_{i \\in I} U_i = \\bigcup_{i \\in I} \\bigcup_{x \\in U_i} B(x, \\varepsilon) = \\bigcup_{x \\in U} B(x, \\varepsilon).\n\t\t$$\n\t\tThen, for all $x \\in U$, there exists $B(x, \\varepsilon) \\ni x$. Thus $U \\in \\mathcal T$.\n\t\t\n\t\tFor O3. Let $U, V \\in \\mathcal T$. If $U \\cap V = \\emptyset$, then the proof is done. Suppose $U \\cap V \\ne \\emptyset$, and let $x \\in U \\cap V$. $U$ is open and $x \\in U$, so there exists $r_1 \\in \\mathbb R_{> 0}$ such that $B(x, r_1) \\subseteq U$; $V$ is open and $x \\in V$, so there exists $r_2 \\in \\mathbb R_{> 0}$ such that $B(x, r_2) \\subseteq V$.\n\t\t\n\t\tIf $r_1 = r_2$, then $B(x, r_1) = B(x, r_2)$. If $r_1 \\ne r_2$, say $r_1 < r_2$, then $B(x, r_1) \\subseteq B(x, r_2) \\subseteq V$. Above all, for any $x \\in U \\cap V$, there exits $r \\in \\mathbb R_{>0}$ such that $B(x, r) \\subseteq U \\cap V$. Thus, there exists $\\varepsilon \\in \\mathbb R_{> 0}$ such that\n\t\t$$\n\t\tU \\cap V = \\bigcup_{x \\in U \\cap V} B(x, \\varepsilon),\n\t\t$$\n\t\ti.e., $U \\cap V \\in \\mathcal T_\\rho$.\n\t\\end{proof}\n\\end{theorem}\n%--------------------------------\n\n\n\n%--------------------------------\n\\begin{theorem}\n\t\\label{prop: metric spaces are Hausdorff}\n\tLet $(X, \\rho)$ be a metric space, then for all $x, y \\in X$ ($x \\ne y$), there is an $\\varepsilon > 0$ such that $B(x, \\varepsilon) \\cap B (y, \\varepsilon) = \\emptyset$.\n\t\n\t\\begin{proof}\n\t\tSuppose for all $\\varepsilon > 0$, $B(x, \\varepsilon) \\cap B(y, \\varepsilon) \\ne \\emptyset$, then there must be a $z \\in X$ such that $z \\in B(x, \\varepsilon) \\cap B(y, \\varepsilon)$. $z \\in B(x, \\varepsilon)$ only if $\\rho(x,z) < \\varepsilon$, and $z \\in B(y, \\varepsilon)$ only if $\\rho (z,y) < \\varepsilon$. Thus\n\t\t$$\n\t\t\\rho(x, z) + \\rho(y,z) < 2\\varepsilon.\n\t\t$$\n\t\tAs the assumption holds for all $\\varepsilon > 0$, we may put\n\t\t$$\n\t\t\\varepsilon = \\frac{\\rho(x,y)}{2}.\n\t\t$$\n\t\tThen, we have\n\t\t$$\n\t\t\\rho(x,z) + \\rho(y,z) < \\rho(x,y),\n\t\t$$\n\t\twhich is impossible.\n\t\\end{proof}\n\\end{theorem}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[induced topologies]\n\t\\label{def: induced topologies}\n\tLet $(X, \\rho)$ be a metric space. A topology $\\mathcal T$ on $X$ is said to be \\textit{induced} by $\\rho$ iff for all $\\varepsilon > 0$, any $U \\in \\mathcal T$ is the union of ball(s) in $X$; i.e.,\n\t$$\n\t\\mathcal T = \\left\\{ U \\subseteq X :  U = \\bigcup_{x \\in X} B(x, \\varepsilon) \\right\\}.\n\t$$\n\t\n\tIn this case, $\\mathcal T$ is called the \\textit{underlying topology} of $\\rho$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[metrizable spaces]\n\t\\label{def: metrizable spaces}\n\tLet $(X, \\mathcal T)$ be a topological space. If there is any $\\rho$ induce $\\mathcal T$, then $(X, \\mathcal T)$ is said to be \\textit{metrizable}.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[Lipschitz equivalence]\n\t\\label{def: Lipschitz equivalence}\n\tLet $X$ be any set, and let $\\rho$ and $\\rho'$ be metrics on $X$. $\\rho$ and $\\rho'$ are said to be \\textit{Lipschitz equivalent} iff there exist $c, C > 0$, such that for all $x,y \\in X$,\n\t$$\n\tc \\rho(x,y) \\le \\rho'(x,y) \\le C \\rho(x,y).\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{theorem}\n\t\\label{prop: Lipschitz equivalence is a equivalence relation}\n\tLipschitz equivalence is an equivalence relation.\n\t\n\t\\begin{proof}\n\t\tClearly, Definition \\ref{def: Lipschitz equivalence} also holds for $\\rho = \\rho'$. So, Lipschitz equivalence is reflexive. In Definition \\ref{def: Lipschitz equivalence}, the relation also holds for $\\frac{1}{C} \\rho' \\le \\rho \\le \\frac{1}{c} \\rho'$. So Lipschitz equivalence is symmetric.\n\t\t\n\t\tIf there is another $\\rho''$ be Lipschitz equivalent to $\\rho'$, then there is $r, R > 0$, such that for all $x,y \\in X$,\n\t\t$$\n\t\tr\\rho''(x,y) \\le \\rho'(x,y) \\le R\\rho''(x,y).\n\t\t$$\n\t\tBy the conditions in Definition \\ref{def: Lipschitz equivalence}, we have\n\t\t$$\n\t\t\\frac{c}{r} \\rho(x,y) \\le \\rho''(x,y) \\le  \\frac{C}{R} \\rho(x,y),\n\t\t$$\n\t\ti.e., $\\rho$ and $\\rho''$ are also Lipschitz equivalent. So Lipschitz equivalence is transitive.\n\t\t\n\t\tAbove all, Lipschitz equivalence is an equivalence relation.\n\t\\end{proof}\n\\end{theorem}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{theorem}\n\t\\label{prop: Lipschitz equivalent metrics induces the same topology}\n\tLet $X$ be any set, and let $\\rho$ and $\\rho'$ be metrics on $X$. If $\\rho$ and $\\rho'$ are Lipschitz equivalent, then $\\rho$ and $\\rho'$ induce the same topology.\n\t\n\t\\begin{proof}\n\t\tAs $\\rho$ and $\\rho'$ are Lipschitz equivalent, by Definition \\ref{def: Lipschitz equivalence}, there is a $c > 0$ such that for all $x,y \\in X$,\n\t\t$$\n\t\tc \\rho(x,y) \\le \\rho'(x,y).\n\t\t$$\n\t\t\n\t\tGiven $r \\in \\mathbb R_{> 0}$ and for all $x \\in X$, we have\n\t\t$$\n\t\tB_{\\rho'}(x, cr) \\subseteq B_{c \\rho}(x, r) = B_\\rho \\left( x, \\frac{1}{c} r \\right).\n\t\t$$\n\t\tFor all $U \\in \\mathcal T_\\rho$, for all $x \\in U$, there is an $\\varepsilon \\in \\mathbb R_{> 0}$, such that\n\t\t$$\n\t\tB_{\\rho'} (x, \\varepsilon) \\subseteq B_{\\rho}(x, \\varepsilon) \\subseteq U.\n\t\t$$\n\t\tSo $U \\in \\mathcal T_\\rho'$. Then we have $\\mathcal T_{\\rho} \\subseteq \\mathcal T_{\\rho'}$.\n\t\t\n\t\tSimilarly, $U \\in \\mathcal T_{\\rho'}$ only if $U \\in \\mathcal T_\\rho$. Then we have $\\mathcal T_{\\rho'} \\subseteq \\mathcal T_{\\rho}$.\n\t\t\n\t\tAbove all, $\\mathcal T_{\\rho} = \\mathcal T_{\\rho'}$.\n\t\\end{proof}\n\\end{theorem}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tIn this proposition, $\\mathcal T_\\rho$ and $\\mathcal T_{\\rho'}$ are said to be homeomorphic or topologically equivalent (see Definition \\ref{def: homomorphic}). And $\\rho$ and $\\rho'$ are also said to be topologically equivalent.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tIn Example \\ref{eg: Euclidean metrics}, for all $p,q \\ge 1$, all $\\rho_p$ and $\\rho_q$ induce the same topology. Let $X$ be any subset of $\\mathbb R^n$, then for all $x,y \\in X$, if $p < q$, then\n\t$$\n\t\\rho_p (x,y) \\ge \\rho_q (x,y).\n\t$$\n\tThus, if $\\rho_1$ and $\\rho_\\infty$ are Lipschitz equivalent, then any other $\\rho_p$ and $\\rho_q$ are Lipschitz equivalent. We have\n\t$$\n\t\\rho_1 (x,y) = \\sum_{i = 1}^n |x_i - y_i| \\ge \\max_{i \\in \\{1, \\ldots, n\\}} |x_i - y_i| = \\rho_\\infty (x,y).\n \t$$\n \tClearly,\n \t$$\n \t\\rho_\\infty (x,y) \\le \\rho_1 (x,y) \\le n \\rho_\\infty (x,y).\n \t$$\n \tBy Definition \\ref{def: Lipschitz equivalence}, $\\rho_1$ and $\\rho_\\infty$ are Lipschitz equivalent, hence for all $p, q \\ge 1$, $\\rho_p$ and $\\rho_q$ are Lipschitz equivalent. Thus, by Proposition \\ref{prop: Lipschitz equivalent metrics induces the same topology}, they induce the same topology.\n\\end{example}\n%--------------------------------\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "332e779573589ae0f48f10520cef892ba61ad34b", "size": 10341, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/metrizable-spaces.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-v0/metrizable-spaces.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-v0/metrizable-spaces.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5406360424, "max_line_length": 443, "alphanum_fraction": 0.5585533314, "num_tokens": 3705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.9111797045849582, "lm_q1q2_score": 0.8369005574180759}}
{"text": "\\section{Some Matrix Groups}\r\n\\begin{definition}\r\n    Let $\\mathbb F$ be a field (e.g. $\\mathbb C,\\mathbb Z/p\\mathbb Z$), then we define\r\n    $$\\operatorname{GL}_n(\\mathbb F)=\\{M\\in\\mathcal M_{n\\times n}(\\mathbb F):\\det M\\neq 0\\}$$\r\n    $$\\operatorname{SL}_n(\\mathbb F)=\\{M\\in\\mathcal M_{n\\times n}(\\mathbb F):\\det M\\neq 0\\}=\\ker\\det|_{\\operatorname{GL}_n(\\mathbb F)}\\unlhd\\operatorname{GL}_n(\\mathbb F)$$\r\n\\end{definition}\r\nNote that $Z=Z(\\operatorname{GL}_n(\\mathbb F))$ is the set of scalar matrices.\r\n\\begin{definition}\r\n    $$\\operatorname{PGL}_n(\\mathbb F)=\\operatorname{GL}_n(\\mathbb F)/Z$$\r\n    $$\\operatorname{PSL}_n(\\mathbb F)=\\operatorname{SL}_n(\\mathbb F)/(Z\\cap \\operatorname{SL}_n(\\mathbb F))\\cong Z\\operatorname{SL}_n(\\mathbb F)/Z\\le\\operatorname{PGL}_n(\\mathbb F)$$\r\n\\end{definition}\r\n\\begin{example}\r\n    Let $G=\\operatorname{GL}_n(\\mathbb Z/p\\mathbb Z)$.\r\n    A list of $n$ vectors in $(\\mathbb Z/p\\mathbb Z)^n$ are the columns of some $A\\in G$ iff they are linearly independent.\r\n    Hence\r\n    $$|G|=(p^n-1)(p^n-p)(p^n-p^2)\\cdots (p^n-p^{n-1})=p^{n(n-1)/2}\\prod_{i=1}^n(p^i-1)$$\r\n    So the Sylow $p$-subgroups have order $p^{n(n-1)/2}$.\r\n    Indeed, the subgroup of upper-triangular matrices with $1$'s on the diagonal gives one (hence all by conjugation) of such subgroups.\r\n\\end{example}\r\nJust like $\\operatorname{PSL}_2(\\mathbb C)$ act on $\\mathbb C\\cup\\{\\infty\\}$ by Mobius transformations, the group $\\operatorname{PSL}_2(\\mathbb Z/p\\mathbb Z)$ can act on $\\mathbb Z/p\\mathbb Z\\cup\\{\\infty\\}$ in this way as well:\r\n$$\\begin{pmatrix}\r\n    a&b\\\\\r\n    c&d\r\n\\end{pmatrix}:z\\mapsto\\frac{az+b}{cz+d}$$\r\nwhere the infinity cases are dealt with in the same way.\r\n\\begin{lemma}\\label{psl_mobius}\r\n    The permutation representation $\\operatorname{PSL}_2(\\mathbb Z)\\to S_{p+1}$ by Mobius transformation is injective.\r\n\\end{lemma}\r\nAnd indeed, by considering the size, for $p=2,3$, this is an isomorphism.\r\n\\begin{proof}\r\n    Suppose there is some $a,b,c,d$ such that $\\forall z\\in\\mathbb C,z=(az+b)/(cz+d)$, then putting $z=0$ gives $b=0$, and $z=\\infty$ gives $c=0$, and $z=1$ gives $a=d$, but these only gives one element that is the identity of $\\operatorname{PSL}_2(\\mathbb Z/p\\mathbb Z)$.\r\n    Done.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    If $p$ is an odd prime, then $|\\operatorname{PSL}_2(\\mathbb Z/p\\mathbb Z)|=p(p-1)(p+1)/2$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    We already know that\r\n    $$|\\operatorname{GL}_2(\\mathbb Z/p\\mathbb Z)|=p(p-1)(p^2-1)$$\r\n    Then by Isomorphism Theorem\r\n    $$|\\operatorname{SL}_2(\\mathbb Z/p\\mathbb Z)|=|\\operatorname{GL}_2(\\mathbb Z/p\\mathbb Z)|/|(\\mathbb Z/p\\mathbb Z)^\\star|=p(p-1)(p+1)$$\r\n    And\r\n    $$|\\operatorname{PSL}_2(\\mathbb Z/p\\mathbb Z)|=|\\operatorname{SL}_2(\\mathbb Z/p\\mathbb Z)|/|\\{\\pm I\\}|=\\frac{p(p-1)(p+1)}{2}$$\r\n    Here $Z\\cap\\operatorname{SL}_2(\\mathbb Z/p\\mathbb Z)=\\{\\pm I\\}$ because $a^2\\equiv 1\\pmod{p}$ only has two solutions, namely $\\pm 1$, as $p$ is prime.\r\n\\end{proof}\r\nNote that for $p=2$, things go wrong on the fact that in this case $I=-I$.\r\n\\begin{example}\r\n    Consider the group $G=\\operatorname{PSL}_2(\\mathbb Z/5\\mathbb Z)$, then $|G|=60=2^2\\cdot3\\cdot5$.\r\n    We shall show that $G$ is simple, and in fact, it is isomorphic to $A_5$.\\\\\r\n    Let $G$ act on $\\mathbb Z/5\\mathbb Z\\cup\\{\\infty\\}$ by Mobius transformation.\r\n    By Lemma \\ref{psl_mobius}, we have an injective group homomorphism $\\phi:G\\to S_6$.\\\\\r\n    Our first claim that, if we embed $G$ into $S_6$, then $G\\le A_6$.\r\n    Equivalently the map $\\psi: G\\to S_6\\to \\{\\pm 1\\}$ is trivial, where the first arrow is $\\phi$ and the second is the signature.\\\\\r\n    Note that for odd $m$, we have $\\psi(g)=1\\iff\\psi(g^m)=1$, so it suffices to study the elements of order being a power of $2$, but this means to study the elements contained in every Sylow $2$-subgroup of $G$, but all of them are conjugate, it is enough to check one of them (since $\\{\\pm 1\\}$ is abelian).\r\n    We spot the following one\r\n    $$H=\\left\\{\\pm\\begin{pmatrix}\r\n        2&0\\\\\r\n        0&3\r\n    \\end{pmatrix},\r\n    \\pm\\begin{pmatrix}\r\n        0&1\\\\\r\n        4&0\r\n    \\end{pmatrix}\\right\\}$$\r\n    By simple computation, $\\psi$ does vanish on $H$, so indeed we have $G\\le A_6$.\r\n    By a result in Example Sheet 1, if $G\\le A_6$ and $|G|=60$, then $G\\cong A_5$, which completes the proof.\r\n\\end{example}\r\nThe following facts will not be proved in the course, but are very important:\r\n\\begin{proposition}\r\n    $\\operatorname{PSL}_n(\\mathbb Z/p\\mathbb Z)$ is simple for $n\\ge 2$ and $p$ prime except if $(n,p)=(2,2)$ or $(n,p)=(2,3)$.\r\n    Also, the two smallest nonabelian simple groups are $A_5\\cong\\operatorname{PSL}_2(\\mathbb Z/5\\mathbb Z)$ with order $60$ and $\\operatorname{PSL}_2(\\mathbb Z/7\\mathbb Z)\\cong\\operatorname{GL}_3(\\mathbb Z/2\\mathbb Z)$ with order $168$.\r\n\\end{proposition}", "meta": {"hexsha": "a5753f9ec5caa7107c0671b23a391b2af63c647b", "size": 4811, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/matrix.tex", "max_stars_repo_name": "david-bai-notes/IB-Groups-Rings-and-Modules", "max_stars_repo_head_hexsha": "f4d4cc7141d30f03f775a67afc5a724db6a35da6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/matrix.tex", "max_issues_repo_name": "david-bai-notes/IB-Groups-Rings-and-Modules", "max_issues_repo_head_hexsha": "f4d4cc7141d30f03f775a67afc5a724db6a35da6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/matrix.tex", "max_forks_repo_name": "david-bai-notes/IB-Groups-Rings-and-Modules", "max_forks_repo_head_hexsha": "f4d4cc7141d30f03f775a67afc5a724db6a35da6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.7605633803, "max_line_length": 311, "alphanum_fraction": 0.6528788194, "num_tokens": 1771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.9099070158103778, "lm_q1q2_score": 0.8367891891523123}}
{"text": "\\section{Schur Decomposition}\n\nFor any square matrix $\\mathbf{A}$, there exist a unitary matrix $\\mathbf{H}$ so that:\n\n\\begin{equation}\n\\mathbf{T} = \\mathbf{U}^{\\dagger}\\mathbf{A}\\mathbf{U}\n\\end{equation}\n\nWhere $\\mathbf{T}$ is an upper triangular matrix. This concept is the same as saying that every square matrix is similar to an upper triangular matrix.\n", "meta": {"hexsha": "766bb56df4e11a83bb2fec3d9ba09f27abbf5a6f", "size": 358, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/linalg_schur.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/linalg_schur.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/linalg_schur.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.8, "max_line_length": 151, "alphanum_fraction": 0.7402234637, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731147976794, "lm_q2_score": 0.8688267677469952, "lm_q1q2_score": 0.8363961707265998}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 3}\n\nProve that $\\log_a x = O(log_b x)$ for any $a > 0$ and $b > 0$.\n\n\\subsection*{Solution}\nIt suffices to introduce two constants $c$ and $x_0$ such that\n\n\\begin{equation}\n\\log_a x \\leq c\\times \\log_b x\n\\label{eq7}\n\\end{equation}\n\nfor any $x \\geq x_0$.\nTo make Equation \\ref{eq7} into equality, $c$ is obtained as\n\n\\begin{equation}\nc = \\frac{log_a x}{log_b x} = log_a b\n\\end{equation}\n\nThus Equation \\ref{eq7} is valid for all $x > x_0 = 0$ and for any $c \\geq log_a b$.\n", "meta": {"hexsha": "6eeac89051903d126bcfcc6f174eb1b4e3b4f10c", "size": 846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q03.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q03.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q03.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 30.2142857143, "max_line_length": 84, "alphanum_fraction": 0.5933806147, "num_tokens": 263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480347, "lm_q2_score": 0.8933094067644466, "lm_q1q2_score": 0.8363922030472234}}
{"text": "\n\\subsection{Examples of linear operators on real functions}\n\nFor a function \\(v\\) we can define operators \\(Ov\\).\n\nHere we consider some examples and their properties.\n\n\\subsubsection{Real multiplication}\n\n\\(Rv = rf(x)\\)\n\nThis operator is hermitian. This is equivalent to a finite operator of the form \\(rI\\).\n\n\\subsubsection{Multiplication by underlying real number}\n\n\\(Xv = xf(x)\\)\n\nThis operator is hermitian. This is equivalent to a finite operator of the form \\(M_{ii}=i\\) and \\(M_{ij}=0\\).\n\n\\subsubsection{Differentiation}\n\n\\(Dv = \\dfrac{\\delta }{\\delta x}f(x)\\)\n\nWhile this operator is not hermitian, the following is:\n\n\\(-iDv = \\dfrac{\\delta }{\\delta x}[-if(x)]\\)\n\n", "meta": {"hexsha": "18d7e8e5534db1846d54737df97dadee9bf1f7b7", "size": 674, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/functionalAnalysis/02-02-operatorExamples.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/functionalAnalysis/02-02-operatorExamples.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/functionalAnalysis/02-02-operatorExamples.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0714285714, "max_line_length": 110, "alphanum_fraction": 0.7106824926, "num_tokens": 185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474168650673, "lm_q2_score": 0.8757869867849167, "lm_q1q2_score": 0.8360677846582616}}
{"text": "\\section{General ReLU DNN as linear finite element functions}\n\nHere we will show that any ReLU DNN function can be viewed as linear finite element function. \nLet us first consider a ReLU DNN function with $L$ hidden layers\n\\begin{equation}\\label{key}\nf(x) = \\theta^{L}\\circ \\sigma \\circ \\theta^{L-1} \\circ \\sigma \\cdots \\circ \\theta^1 \\circ \\sigma \\circ \\theta^0(x),\n\\end{equation}\nfor any $X \\in \\mathbb{R}^d$.\nBased on the property of ${\\rm ReLU}$ activation function, we know that $f(x)$ is a continuous \npiecewise linear function. More precisely, let us consider a closed bounded domain, for example $\\Omega = [-1, 1]^d$ and \n\\begin{equation}\\label{key}\n\\left. f(x) \\right|_{E_i} = \\ell_i(x),  \\quad \\text{ for } i =1,2,\\cdots M,\n\\end{equation}\nfor any $x\\in \\Omega$, where $\\ell_i(x) = w_i x + b_i$ is a linear function on $\\mathbb{R}^d$ and \n$\\{E_i\\}_{i=1}^M$ are the domains which consist a partition of $\\Omega$. \nFurthermore, we know that the boundary of $E_i$ consists of some hyperplanes \nof $d$-dimensional space and $E_i \\cap E_j = \\emptyset$ or $E_i \\cap E_j $ belongs to\nhyperplanes of lower dimensional space.\n\nThen we have the following representation theory to represent any ReLU DNN function\nby linear finite element function.\n\\begin{theorem}\nAny ReLU DNN function on $[-1,1]^d$ can be represent\nby a linear finite element function.\n\\end{theorem}\nThe proof of this theorem can be found in~\\cite{he2020approximation}.\n\n\nHere we show a brief description of the main steps in the proof, which will appear in~\\cite{he2020approximation}.\n\\begin{enumerate}\n\t\\item Based on the discussion before, we have a partition of $\\Omega$ as\n\t\\begin{equation}\\label{key}\n\t\\Omega = \\bigcup_{i=1}^M E_i.\n\t\\end{equation}\n\t\\item We can extend all the $d$-dimensional hyperplanes on the boundary of all $E_i$ to achieve\n\ta fine partition of $\\Omega$ noted as\n\t\\begin{equation}\\label{key}\n\t\\Omega = \\bigcup_{i=1}^{\\tilde M} \\tilde E_i,\n\t\\end{equation}\n\twith an important feature that each $\\tilde E_i$ is a convex n-dimensional polytope.\n\t\\item For these $\\{\\tilde E_i\\}_{i=1}^{\\tilde M}$, we can further partition each $\\tilde E_i$\n\tto be a collection of n-dimensional simples. Finally, we can rewrite the continuous\n\tpiecewise linear function $f(x)$ on a simplicial mesh of $\\Omega$, which means that $f(x)$\n\twill can be written as a linear finite element function.\n\\end{enumerate}\n\n\n\n", "meta": {"hexsha": "95b78cf5f2d4606609ddfda9eaeb97f3c89654bc", "size": 2383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ReLUDNN2FEM.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/ReLUDNN2FEM.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/ReLUDNN2FEM.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.6326530612, "max_line_length": 121, "alphanum_fraction": 0.7276542174, "num_tokens": 723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.913676521650809, "lm_q1q2_score": 0.8359235222129892}}
{"text": "\\section{Multistep Method}\n\\begin{defn}\nAn $m$-step multistep method for solving the initial-value problem\n\\[\ny'=f(t,y),\\quad a\\leq t\\leq b,\\quad y(a)=\\alpha\n\\]]\nhas a difference equation for finding the approximation $\\omega_{i+1}$ at the mesh point $t_{i+1}$ represented by the following equation, where $m$ is an integer greater than 1:\n\\begin{align*}\n    \\omega_{i+1} =& a_{m-1}\\omega_{i}+a_{m-2}\\omega_{i-1}+\\cdots+a_{0}\\omega_{i+1-m} \\\\\n    & + h\\left[b_{m}f(t_{i+1},\\omega_{i+1})+b_{m-1}f(t_{i},\\omega_{i})\\right. \\\\\n    \\left.+\\cdots+b_{0}f(t_{i+1-m},\\omega_{i+1-m})\\right]\n\\end{align*}\nfor $i=m-1,m,\\cdots,N-1$, where $h=\\frac{b-a}{N}$, the $a_0,a_1,\\cdots a_{m-1}$ and $b_0,b_1,\\cdots,b_m$ are constant, and the starting values\n\\[\n\\omega_{0}=\\alpha_{0},\\quad\\omega_{1}=\\alpha_{1},\\cdots,\\omega_{m-1}=\\alpha_{m-1}\n\\]\nare specified.\n\n\\begin{equation*}\n    \\begin{cases}\n    \\text{When $b_m=0$, the method is called explicit, or open.} \\\\\n    \\text{When $b_m\\neq 0$, the method is called implicit, or closed.}\n    \\end{cases}\n\\end{equation*}\n\\end{defn}", "meta": {"hexsha": "0c637822b10608c6400286289db7da8688a0a203", "size": 1059, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/5.6_Multistep_method.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/5.6_Multistep_method.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/5.6_Multistep_method.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.36, "max_line_length": 177, "alphanum_fraction": 0.6477809254, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726544, "lm_q2_score": 0.9136765228260895, "lm_q1q2_score": 0.8359235211682274}}
{"text": "\n\\subsection{Kronecker product}\n\nThe Kronecker product takes the concept of the outer product and applies to to matrices.\n\nWe can essentially repace every element in the matrix on the left with the element multiplied by the entire matrix on the right.\n\nLike outer products, Kronecker products are written as:\n\n\\(u\\otimes v=w\\)\n\n", "meta": {"hexsha": "ab931b28399b43b7a6811f993b199775c9b6ae11", "size": 328, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/tensors/05-02-kronProduct.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/tensors/05-02-kronProduct.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/tensors/05-02-kronProduct.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.3333333333, "max_line_length": 128, "alphanum_fraction": 0.7896341463, "num_tokens": 73, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9525741254760639, "lm_q2_score": 0.8774767986961401, "lm_q1q2_score": 0.8358616941435119}}
{"text": "\\documentclass[12pt]{scrartcl}\n\n\\input{preamble}\n\n\\makeatletter\n\\title{Hack 5.0}\\let\\Title\\@title\n\\subtitle{Computer Science I\\\\\n{\\small\n\\vskip1cm\nDepartment of Computer Science \\& Engineering \\\\\nUniversity of Nebraska--Lincoln}\n\\vskip-1cm}\n%\\author{Dr.\\ Chris Bourke}\n\\date{~}\n\\makeatother\n\n\\begin{document}\n\n\\maketitle\n\n\\hrule\n\n\\input{instructions.tex}\n\n\\section*{Problem Statement}\n\nTo get some practice designing and using functions, you will \ncreate a small library of utility functions by implementing\nthe following functions with the given prototypes and specified \nfunctionality.\n\\begin{enumerate}\n  \\item \\mintinline{c}{double degreesToRadians(double degree);} - Write a \n  \tfunction to convert degrees to radians using the formula \n\t\t$$\\frac{d\\cdot \\pi}{180}$$\n  \\item Write a function to compute the air distance between two locations \n    identified by their latitude/longitude.  \n\\begin{minted}{c}\ndouble getAirDistance(double originLatitude, \n                      double originLongitude, \n                      double destinationLatitude, \n                      double destinationLongitude);\n\\end{minted}  \nThe air distance between two latitude/longitude points can be calculated \nusing the Spherical Law of Cosines:\n $$d = \\arccos{(\\sin(\\varphi_1) \\sin(\\varphi_2) + \\cos(\\varphi_1) \\cos(\\varphi_2) \\cos(\\Delta) )} \\cdot R$$\nwhere\n\\begin{itemize}\n  \\item $\\varphi_1$ is the latitude of location $A$, $\\varphi_2$ is the latitude of location $B$\n  \\item $\\Delta$ is the difference between location $B$'s longitude and location $A$'s longitude\n  \\item $R$ is the (average) radius of the earth, 6,371 kilometers\n\\end{itemize}\nNote: the formula above assumes that latitude and longitude are measured \nin radians $r$, $-\\pi \\leq r \\leq \\pi$, but the function will expect \nthe latitude/longitude to be in degrees.  Latitude should be in the range \n$[-90, 90]$ and longitude in the range $[-180, 180]$.  Negative values \ncorrespond to the southern and western hemispheres.\n\n  \\item An object traveling at a velocity $v$ experiences time dilation\n  relative to a stationary object which is quantified by the Lorentz equation:\n  $$T = \\frac{t}{\\sqrt{(1-\\frac{v^2}{c^2})}}$$\n  where $t$ is the normal amount of lapsed time (stationary object) \n  and $T$ is the dilated time experienced by the traveling object.  \n  For small velocities, the dilation is small, but for velocities\n  approaching a \\emph{percentage} (on the scale $[0, 1]$) of the \n  speed of light, $c$, the dilation becomes significant.\n  \n  For example, at 25\\% the speed of light, a year for the object \n  traveling would correspond to 1.032796 years at the stationary object \n  (or nearly 12 extra days).   A person traveling at high velocity \n  would experience ``slowed'' time\n  relative to the stationary \\emph{frame}.  \n  \n  Implement a function to compute the dilated time given the \n  normal time $t$ (units may vary) and the \\emph{percentage}\n  (i.e.\\ $\\frac{v}{c}$) of the speed of light.\n\\begin{minted}{c}\ndouble lorentzTimeDilation(double t, double percentC);\n\\end{minted}\n\n\\end{enumerate}  \n\n\\section*{Instructions}\n\n\\begin{itemize}\n  \\item You are encouraged to collaborate any number of students \n  before, during, and after your scheduled hack session.  \n  \\item Design at least 3 test cases for each function\n  \\emph{before} you begin\n  designing or implementing your program.  Test cases are \n  input-output pairs that are known to be correct using means\n  other than your program.\n  \\item Include the name(s) of everyone who worked together on\n  this activity in your source file's header.\n  \\item Place your prototypes and documentation in a header file \n  named \\mintinline{text}{utils.h} and your source in a file\n  named \\mintinline{text}{utils.c}.\n  \\item In addition, implement all of your test cases in a\n  \\emph{test driver} file named \\mintinline{text}{utilsTester.c}\n  which should output the expected output, the actual output and\n  a message on whether or not the test case passed.  You must have\n  at least 3 test cases for \\emph{each} of your functions.\n  You should \\emph{not} prompt for input or use command line \n  arguments.  Your test cases should be hardcoded in your test \n  driver's \\mintinline{c}{main} function.  \n  \\item Turn in all of your files via webhandin, making sure that \n  it runs and executes correctly in the webgrader.  Each individual \n  student will need to hand in their own copy and will receive \n  their own individual grade.\n\\end{itemize}\n  \n\n\n\\end{document}\n", "meta": {"hexsha": "a05907fd6bb97ea5103d271eadafeeac5e9d1fea", "size": 4491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hacks/hack5.0.tex", "max_stars_repo_name": "bobbys131/ComputerScienceI", "max_stars_repo_head_hexsha": "93e22289e966386f208c477ee319837877bbe62a", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 68, "max_stars_repo_stars_event_min_datetime": "2018-05-14T20:29:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T10:05:16.000Z", "max_issues_repo_path": "hacks/hack5.0.tex", "max_issues_repo_name": "bobbys131/ComputerScienceI", "max_issues_repo_head_hexsha": "93e22289e966386f208c477ee319837877bbe62a", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-05-11T01:30:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-02T04:34:10.000Z", "max_forks_repo_path": "hacks/hack5.0.tex", "max_forks_repo_name": "bobbys131/ComputerScienceI", "max_forks_repo_head_hexsha": "93e22289e966386f208c477ee319837877bbe62a", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 204, "max_forks_repo_forks_event_min_datetime": "2018-10-17T18:35:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T16:51:50.000Z", "avg_line_length": 39.3947368421, "max_line_length": 107, "alphanum_fraction": 0.7327989312, "num_tokens": 1188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942145139149, "lm_q2_score": 0.9252299637925935, "lm_q1q2_score": 0.8357548733887686}}
{"text": "\\section{Conics in Polar Coordinates}\\label{sec:Conics in Polar Coordinates}\nA \\dfont{conic section}\\index{conic section}\\index{polar coordinates!conic section} is a curve obtained as the intersection of a \ncone and a plane. One useful geometric definition that only involves the plane\nis that a conic consists of those points whose distances to some point, called a \n\\dfont{focus}, and some line, called a \\dfont{directrix}, are in a fixed ratio, \ncalled the \\dfont{eccentricity}.\n\nThe three types of conic sections are the ellipse, parabola and hyperbola (with the circle being a degenerate case of an ellipse).\n\n$$\\includegraphics[width=3in]{images/ConicSections}$$\n\nLet $F$ be a fixed point (the focus), $L$ be a line (the directrix) not containing $F$ and $e$ be a nonnegative real number (the eccentricity).\nThe conics sections are obtained by the set of all points $P$ whose distance to $F$ equals $e$ times their distance to $L$, that is:\n$$\\frac{|PF|}{|PL|}=e.$$\nIn the case that:\n\\begin{itemize}\\setlength{\\itemsep}{0 in}\n\\item $e<1$ we obtain an ellipse (and when $e=0$ we obtain the degenerate case: A circle),\n\\item $e=1$ we obtain a parabola,\n\\item $e>1$ we obtain a hyperbola.\n\\end{itemize}\n\nTo obtain a simple polar equation we place the focal point at the origin.\nThe formulation for a conic section is then given in the polar form by\n$$r=\\frac{pe}{1\\pm e\\cos\\theta}\\qquad\\mbox{and}\\qquad r=\\frac{pe}{1\\pm e\\sin\\theta}$$\nwhere $e$ is the eccentricity and $p$ is the focal parameter representing the distance from the focus (or one of the two foci) to the directrix.\n\nThe three different types of conic sections are shown below. Focal points corresponding to all conic sections are placed at the origin.\nFirst is the parabola.\n$$\\includegraphics[width=5in]{images/conics-polar1}$$\nNext is the ellipse.\n$$\\includegraphics[width=5in]{images/conics-polar2}$$\nFinally, we have the hyperbola.\n$$\\includegraphics[width=5in]{images/conics-polar3}$$\n\nSome things to keep in mind with respect to the denominator of polar equations of various conics are the following:\n\\begin{itemize}\\setlength{\\itemsep}{0 in}\n\\item If the denominator is $1 + e \\sin\\theta$, it has a horizontal directrix above the focal point.\n\\item If the denominator is $1 - e \\sin\\theta$, it has a horizontal directrix below the focal point.\n\\item If the denominator is $1 + e \\cos\\theta$, it has a vertical directrix to the right of the focal point.\n\\item If the denominator is $1 - e \\cos\\theta$, it has a vertical directrix to the left of the focal point. \n\\end{itemize}\n\n\\begin{example}{Polar Equations for a Parabola}{polareqnparabola}\nFind the equation of a parabola with focus at the origin and whose directrix is the line $x=-1$.\n\\end{example}\n\n\\begin{solution}\nSince we have a parabola, $e=1$.\nFurthermore, $p=1$.\nSince the graph has a vertical directrix, the equation will use $1 - e \\cos\\theta$ in the denominator.\nThus, the equation is:\n$$r=\\frac{2}{1-\\sin\\theta}$$\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Conics in Polar Coordinates}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\n\\noindent Identify the following conics and find the eccentricity.\n\\begin{multicols}{2}\n\\begin{enumerate}\n\t\\item\t$\\ds r=\\frac{2}{1+\\sin\\theta}$\n\t\\item\t$\\ds r=\\frac{4}{2+\\cos\\theta}$\n\t\\item\t$\\ds r=\\frac{3}{1-\\sin\\theta}$\n\t\\item\t$\\ds r=\\frac{5}{2+2\\sin\\theta}$\n\\end{enumerate}\n\\end{multicols}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nWrite the polar equation of a parabola with focus at the origin and directrix $x=3$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nWrite the polar equation of a hyperbola with focus at the origin, directrix $x=4$ and eccentricity $2$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nWrite the polar equation of an ellipse with focus at the origin, directrix $x=4\\sec\\theta$ and eccentricity $1/2$.\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "d0dacd7fc743afdd4640ec5f823600db89dd15d5", "size": 3895, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11-polar-coord-parametric-eq/11-6-conics-in-polar-coord.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11-polar-coord-parametric-eq/11-6-conics-in-polar-coord.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11-polar-coord-parametric-eq/11-6-conics-in-polar-coord.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.3369565217, "max_line_length": 144, "alphanum_fraction": 0.7268292683, "num_tokens": 1151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832974, "lm_q2_score": 0.8962513807543223, "lm_q1q2_score": 0.8357125638727143}}
{"text": "\\textbf{Theorem 6 makes a prediction about the geometric rate of convergence in the third pane of Output 12. Exactly what is this prediction? How well does it match the observed rate of convergence?}\n\\newline\n\n\nSince $f(x) = \\frac{1}{1+x^2}$ is analytic everywhere exept $x=\\pm i$, where it has singularities, it is analytic on and inside the ellipse with foci $\\{-1,1\\}$ and semiminor axis $b < 1$ on which the Chebishev potential takes the value\n\\begin{align*}\n\\phi_f = \\log\\left(\\frac{1}{2}(a+b)\\right) \\approx \\log\\left(\\frac{1}{2}(\\sqrt{2}+1)\\right),\n\\end{align*}\nwhere we have obtained a from the foci identity $ f = a^2 - b^2$. Hence, by \\textsc{Theorem 6}, the convergence should be\n\\begin{align*}\n|w_j-u^{(v)}(x_j)| = \\mathcal{O}\\left(e^{-N(\\phi_f+\\log{2})}\\right) = \\mathcal{O}\\left(e^{-(\\sqrt{2}+1)N}\\right),\n\\end{align*}\nwhich is proved to be right by the next figure.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{P6_7.png}\\caption{Acuracy of the Chebishev spectral derivative for $f(x) = \\frac{1}{1+x^2}$.}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 3 - 6.7 Trefethen\nNmax = 50; E = zeros(Nmax,1);\nfor N = 1:Nmax\n    [D,x] = cheb(N);\n    v = 1./(1+x.^2); vprime = -2*x.*v.^2;    % analytic in [-1,1]\n    E(N) = norm(D*v-vprime,inf);\nend\n% Define ellipse and potential on it.\na = sqrt(2) ; b = 1;\nphif = log(0.5*(a+b));\n% Plot results:\nfigure\nsemilogy(1:Nmax,E(:),'r*')\nhold on\nsemilogy(1:Nmax,exp(-(phif+log(2))*(1:Nmax)))\naxis([0 Nmax 1e-16 1e3]), grid on\nset(gca,'xtick',0:10:Nmax,'ytick',(10).^(-15:5:0))\nxlabel N, ylabel error\ntxt='Latex/FIGURES\\P6_7';\nsaveas(gcf,txt,figformat)\n\\end{verbatim}\n", "meta": {"hexsha": "0dd1b7bf6eb3842b4b974b7f80869988385f9de3", "size": 1666, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework3/Latex/problem3.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework3/Latex/problem3.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework3/Latex/problem3.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.6666666667, "max_line_length": 236, "alphanum_fraction": 0.6680672269, "num_tokens": 609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.9294404003923944, "lm_q1q2_score": 0.8356797303787353}}
{"text": "\n\\subsection{Maximum Likelihood Estimator (MLE) and OLS equivalence}\n\n\\subsubsection{The OLS estimator}\n\n\\(\\hat \\theta_{OLS}=(X^TX)^{-1}X^Ty\\)\n\n\\(E[\\hat \\theta_{OLS}]=w\\)\n\n\\(Var[\\hat \\theta_{OLS}]=\\sigma^2 (X^TX)^{-1}\\)\n\n\\subsubsection{The MLE estimator}\n\n\\(y_i=\\mathbf x_i\\theta +\\epsilon_i \\)\n\n\\(P(y=y_i|x=x_i)=P(\\epsilon_i=y_i-\\mathbf x_i \\theta )\\)\n\nIf we assume \\(\\epsilon_i \\sim N(0, \\sigma^2_\\epsilon )\\) we have:\n\n\\(P(y=y_i|x=x_i)=\\dfrac{1}{\\sqrt {2\\pi \\sigma^2_\\epsilon }}e^{-\\dfrac{(y_i-\\mathbf x_i\\theta )^2}{2\\sigma_\\epsilon^2}}\\)\n\n\\(L(X, \\theta )=\\prod_{i=1}^n\\dfrac{1}{\\sqrt {2\\pi \\sigma^2_\\epsilon }}e^{-\\dfrac{(y_i-\\mathbf x_i\\theta )^2}{2\\sigma_\\epsilon^2}}\\)\n\n\\(l(X, \\theta )=\\sum_{i=1}^n -\\dfrac{1}{2}\\ln (2\\pi \\sigma_\\epsilon^2)-\\dfrac{(y_i-\\mathbf x_i\\theta )^2}{2\\sigma_\\epsilon^2}\\)\n\n\\(\\dfrac{\\delta l}{\\delta \\theta_j }=\\sum_{i=1}^n2x_{ij}\\dfrac{y_i-\\mathbf x_{i}\\theta }{2\\sigma^2_\\epsilon}\\)\n\n\\(\\sum_{i=1}^nx_{ij}(y_i-\\hat \\theta_{MLE}\\mathbf x_{i} )=0\\)\n\n\\(X^T(y-X\\hat \\theta_{MLE} )=0\\)\n\n\\(X^Ty=X^TX\\hat \\theta_{MLE} \\)\n\n\\(\\hat \\theta_{MLE}=(X^TX)^{-1}X^Ty\\)\n\n\\subsubsection{Equivalence}\n\nIf errors are normally IID then:\n\n\\(\\hat \\theta_{OLS}=\\hat \\theta_{MLE}\\)\n\n", "meta": {"hexsha": "810def5a1dc819ef079c0319095fa07549715624", "size": 1192, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/olsInference/03-01-MLE.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/olsInference/03-01-MLE.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/olsInference/03-01-MLE.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.380952381, "max_line_length": 132, "alphanum_fraction": 0.6258389262, "num_tokens": 510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620585273153, "lm_q2_score": 0.8705972784807408, "lm_q1q2_score": 0.8355662361429541}}
{"text": "\\section{Hermite Interpolation}\nThe osculating polynomial approximating a function $f\\in C^m[a,b]$ at $x_i$ for each $i=0:n$, of which the derivatives of order less than or equal to $m_i$, then the degree of this osculating polynomial is at most $M=\\sum_{i=0}^{n}m_i+n$.\n\\[\n\\diff{^kP(x_i)}{x^k}\\,=\\,\\diff{^kf(x_i)}{x^k},\\quad\\text{for each $i=0:n$, $k=0:m_i$}.\n\\]\n\\begin{equation*}\n    \\begin{cases}\n    n=0 & \\text{$m_0$ Taylor polynomial for $f$ at $x_0$} \\\\\n    m_i=0(\\text{each $i$}) & \\text{$n$th Lagrange polynomial}\n    \\end{cases}\n\\end{equation*}\n\n\\subsection{Hermite Polynomials}\n\\begin{theo}\n$f\\in C'[a,b]$ and $x_0,\\cdots,x_n\\in [a,b]$, the unique polynomial of least degree agreeing with $f$ and $f'$ at $x_0,\\cdots,x_n$ is the Hermite polynomial of degree at most $2n+1$.\n\\begin{align*}\n    H_{2n+1}(x)\\,=\\,\\sum_{j=0}^nf(x_j)H_{n,j}(x) + \\sum_{j=0}^nf'(x_j)\\hat{H}_{n,j}(x) \\\\\n    \\begin{cases}\n    H_{n,j}(x) &= \\left[1-2(x-x_j)L_{n,j}'(x_j)\\right]L_{n,j}^2(x) \\\\\n    \\hat{H}_{n,j}(x) &= (x-x_j)L_{n,j}^2(x)\n    \\end{cases}\n\\end{align*}\nMoreover, if $f\\in C^{2n+2}[a,b]$, then\n\\[\nf(x)=H_{2n+1}(x)+\\frac{(x-x_0)^2\\cdots(x-x_n)^2}{(2n+2)!}f^{(2n+2)}\\left(\\xi(x)\\right).\n\\]\n\\end{theo}\n\\begin{proof}\n\\begin{align*}\n    & H_{n,j}(x_i)=\\delta_{i,j} & & \\hat{H}_{n,j}(x_i)=0 & \\\\\n    & H_{n,j}'(x_i)=0 & & \\hat{H}_{n,j}'(x_i)=\\delta_{i,j} & \\\\\n\\end{align*}\n\\end{proof}\n\n\\subsection{Hermite Polynomials Using Divided Differences}\nSuppose that the distinct numbers $x_0,\\cdots,x_n$ are given together with values of $f$ and $f'$. Define a new sequence $z_0,\\cdots,z_{2n+1}$ by\n\\[\nz_{2i} = z_{2i+1} = x_i\\quad\\text{for $i=0:n$}.\n\\]\nWe have $H_{2n+1}(x)=f[z_0]+\\sum_{k=1}^{2n+1}f[z_0,\\cdots,z_k](x-z_0)\\cdots(x-z_{k-1})$.\n\\vspace{1cm}\\\\\n\\begin{tabular}{@{}llll@{}}\n\\toprule\n$z$ & $f(z)$ & First divided differences & $\\cdots$ \\\\ \\midrule\n$z_0=x_0$ & $f[z_0]=f(x_0)$ & $f[z_0,z_1]=f'(x_0)$ & $\\vdots$ \\\\\n$z_1=x_0$ & $f[z_1]=f(x_0)$ & $f[z_1,z_2]=\\frac{f[z_2]-f[z_1]}{z_2-z_1}$ & $\\vdots$ \\\\\n$z_2=x_1$ & $f[z_2]=f(x_1)$ & $f[z_2,z_3]=f'(x_1)$ & $\\vdots$ \\\\\n$z_3=x_1$ & $f[z_3]=f(x_1)$ & $f[z_3,z_4]=\\frac{f[z_3]-f[z_4]}{z_3-z_4}$ & $\\vdots$ \\\\\n$z_4=x_2$ & $f[z_4]=f(x_2)$ & $f[z_4,z_5]=f'(x_2)$ &  \\\\\n$z_5=x_2$ & $f[z_5]=f(x_2)$ &  &  \\\\ \\bottomrule\n\\end{tabular}\n", "meta": {"hexsha": "be5857132aae69956ead82966fb6532235ad2555", "size": 2265, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/3.4_Hermite_interpolation.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/3.4_Hermite_interpolation.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/3.4_Hermite_interpolation.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.5576923077, "max_line_length": 238, "alphanum_fraction": 0.5849889625, "num_tokens": 1078, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465170505204, "lm_q2_score": 0.8933094003735663, "lm_q1q2_score": 0.8355538362879041}}
{"text": "\n\\subsection{Inequalities}\n\n\\subsubsection{Less than or equal}\n\nOrderings define relations between elements in a set, where one element can preceed the other. \n\nOrderings are antisymmetric. That is, the only case where the relation is satisfied in both directions is if the elements are equal.\n\n\\((a\\le b)\\land (b\\le a)\\rightarrow (a=b)\\)\n\nOrderings are transitive. That is: \n\n\\((a\\le b)\\land (b\\le c)\\rightarrow (a\\le c)\\)\n\n\\subsubsection{Greater than or equal}\n\n\\subsubsection{Less than and greater than}\n\nThe relation \\(\\le \\) is refered to as non-strict.\n\nThere is a similar strict relation relation, \\(<\\):\n\n\\((a\\le b)\\land \\neg (b\\le a)\\rightarrow (a < b)\\)\n\n\n", "meta": {"hexsha": "cd5a167971fe040991b4075363317bf92fdd44d7", "size": 666, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/orderings/01-01-inequalities.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/orderings/01-01-inequalities.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/orderings/01-01-inequalities.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.6666666667, "max_line_length": 132, "alphanum_fraction": 0.7192192192, "num_tokens": 186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109798251322, "lm_q2_score": 0.8791467643431002, "lm_q1q2_score": 0.8355507377094206}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let $X=\\begin{mymatrix}{rrr}\n    -1 & -1 & 1\n  \\end{mymatrix}$ and $Y=\\begin{mymatrix}{rrr}\n    0 & 1 & 2\n  \\end{mymatrix}$. Find $X^TY$ and $XY^T$ if\n  possible.\n  \\begin{sol}\n    $X^TY = \\begin{mymatrix}{rrr}\n      0 & -1 & -2 \\\\\n      0 & -1 & -2 \\\\\n      0 & 1 & 2\n    \\end{mymatrix}$, $XY^T = 1$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the matrices\n  \\begin{equation*}\n    A =\\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      3 & 2 \\\\\n      1 & -1\n    \\end{mymatrix},\n    \\quad\n    B=\\begin{mymatrix}{rrr}\n      2 & -5 & 2 \\\\\n      -3 & 2 & 1\n    \\end{mymatrix},\n    \\quad\n    C =\\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      5 & 0\n    \\end{mymatrix},\n    \\quad\n    D=\\begin{mymatrix}{rr}\n      -1 & 1 \\\\\n      4 & -3\n    \\end{mymatrix},\n    \\quad\n    E=\\begin{mymatrix}{r}\n      1 \\\\\n      3\n    \\end{mymatrix}.\n  \\end{equation*}\n  Find the following if possible. If it is not possible explain why.\n  \\begin{enumerate}\n  \\item $-3A{^T}$.\n  \\item $3B - A^T$.\n  \\item $E^TB$.\n  \\item $EE^T$.\n  \\item $B^TB$.\n  \\item $CA^T$.\n  \\item $D^TBE$.\n  \\end{enumerate}\n\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item $\\begin{mymatrix}{rrr}\n        -3 & -9 & -3 \\\\\n        -6 & -6 & 3\n      \\end{mymatrix}$.\n    \\item $\\begin{mymatrix}{rrr}\n        5 & -18 & 5 \\\\\n        -11 & 4 & 4\n      \\end{mymatrix}$.\n    \\item $\\begin{mymatrix}{rrr}\n        -7 & 1 & 5\n      \\end{mymatrix}$.\n    \\item $\\begin{mymatrix}{rr}\n        1 & 3 \\\\\n        3 & 9\n      \\end{mymatrix}$.\n    \\item $\\begin{mymatrix}{rrr}\n        13 & -16 & 1 \\\\\n        -16 & 29 & -8 \\\\\n        1 & -8 & 5\n      \\end{mymatrix}$.\n    \\item $\\begin{mymatrix}{rrr}\n        5 & 7 & -1 \\\\\n        5 & 15 & 5\n      \\end{mymatrix}$.\n    \\item Not possible because $B$ is a $2\\times 3$-matrix and $E$ is\n      a $2\\times 1$-matrix, cannot multiply $BE$.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Which of the following matrices are symmetric, antisymmetric, both,\n  or neither?\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      -1 & 0 \\\\\n    \\end{mymatrix},\n    \\quad\n    B = \\begin{mymatrix}{rr}\n      2 & 1 \\\\\n      1 & 3 \\\\\n    \\end{mymatrix},\n    \\quad\n    C = \\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      -2 & 0 \\\\\n    \\end{mymatrix},\n    \\quad\n    D = \\begin{mymatrix}{rr}\n      0 & 0 \\\\\n      0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    $A$ is antisymmetric, $B$ is symmetric, $C$ is neither, and $D$ is both.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $A$ is a matrix that is both symmetric and\n  antisymmetric. Show that $A=0$.\n  \\begin{sol}\n    We have $A=A^T=-A$. Therefore, each entry $a_{ij}$ of $A$ is equal\n    to its own negation. This implies that $a_{ij}=0$, and therefore\n    $A$ is the zero matrix.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $A$ be an $n\\times n$-matrix. Show $A$ equals the sum of a\n  symmetric and an antisymmetric matrix.  \\textbf{Hint:} Show that\n  $\\frac{1}{2}(A^T+A)$ is symmetric and then consider using\n  this as one of the matrices.\n  \\begin{sol}\n    $A=\\frac{1}{2}(A+A^T)+\\frac{1}{2}(A-A^T)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Show that the main diagonal of every antisymmetric matrix consists\n  of only zeros. Recall that the main diagonal consists of every entry\n  of the matrix which is of the form $a_{ii}$.\n  \\begin{sol}\n    If $A$ is antisymmetric then $A=-A^T$. It follows that\n    $a_{ii}=-a_{ii}$ and so each $a_{ii}=0$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Show that for $m \\times n$-matrices $A,B$ and scalars $r, s$, the\n  following holds:\n  \\begin{equation*}\n    (rA + sB)^T = rA^T + sB^T.\n  \\end{equation*}\n  \\vspace{-4ex}\n  \\begin{sol}\n    This follows from properties {\\ref{matrix-transpose-2}} and\n    {\\ref{matrix-transpose-3}} of\n    Proposition~\\ref{prop:transpose-properties}.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex} \\label{exer-Rn3}  Let $A$ be a real $m\\times n$-matrix and\n  let $\\vect{u}\\in \\R^n$ and $\\vect{v}\\in \\R^m$. Show\n  $(A\\vect{u})\\dotprod \\vect{v}=\\vect{u}\\dotprod (A^T\\vect{v})$.\n  \\begin{sol}\n    $(A\\vect{u})\\dotprod \\vect{v} = (A\\vect{u})^T\\vect{v} =\n    (\\vect{u}^TA^T)\\vect{v}  = \\vect{u}^T(A^T\\vect{v}) =\n    \\vect{u}\\dotprod (A^T\\vect{v})$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Show that if $A$ is an invertible $n\\times n$-matrix, then so is\n  $A^T$ and $(A^T)^{-1}=(A^{-1})^T$.\n  \\begin{sol}\n    We need to show that $(A^{-1})^T$ is the inverse of\n    $A^T$. From properties of the transpose,\n    \\begin{eqnarray*}\n      A^T(A^{-1})^T &=& (A^{-1}A)^T=I^T=I, \\\\\n      (A^{-1})^TA^T &=& (AA^{-1})^T=I^T=I.\n    \\end{eqnarray*}\n    Hence $A^T$ is invertible and $(A^T)^{-1}=(A^{-1})^T$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $A$ is invertible and symmetric. Show that $A^{-1}$ is\n  symmetric.\n  \\begin{sol}\n    We have $(A^{-1})^T = (A^T)^{-1} = A^{-1}$, and therefore $A^{-1}$\n    is equal to its own transpose, hence symmetric.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "f88add425fe242143b74263e6c0ba0897ebb196e", "size": 4857, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Matrices-Transpose.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Matrices-Transpose.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Matrices-Transpose.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 24.654822335, "max_line_length": 76, "alphanum_fraction": 0.5355157505, "num_tokens": 1990, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383029, "lm_q2_score": 0.9073122150949273, "lm_q1q2_score": 0.8354437244135644}}
{"text": "\\chapter{From Abstract Algebra to Finite Fields}\n\\label{app:A}\n% handbook of applied cryptography\n\nIn this Appendix we recall basic formal definitions from \\cite{Menezes97handbookof} to properly understand what a finite field is.\n\n\\section{Groups}\n\\begin{mydef} A binary operation $*$ on a set $S$ is a mapping  $S \\times S$ to $S$. That is, $*$ is a rule which assigns to each ordered pair of elements from $S$ an element of $S$. \\end{mydef}\n\n\\begin{mydef} \n\tA group $(G, *)$ consists of a set $G$ with a binary operation $*$ on $G$ satisfying\n\tthe following three axioms.\n\t\\begin{itemize}\n\t\t\\item[(i)] The group operation is associative. That is, $a* (b * c) = (a* b) * c \\quad \\forall a, b, c \\in G$.\n\t\t\\item[(ii)] There is an element $1 \\in G$, called the identity element, such that $a * 1 = 1 * a = a \\quad \\forall a \\in G$.\n\t\t\\item[(iii)] For each $a \\in G $ there exists an element $a^{-1} \\in G$, called the inverse of $a$, such that $a *a^{-1}= a^{-1} * a = 1$.\n\t\\end{itemize}\n\tA group G is Abelian (or commutative) if, furthermore,\n\t\\begin{itemize}\n\t\t\\item[(iv)] $a * b = b * a \\quad \\forall a, b \\in G$. \n\t\\end{itemize}\n\\end{mydef}\n\n\\begin{mydef} \n\tA group $G$ is finite if $|G|$ is finite. The number of elements in a finite group is called its order.\n\\end{mydef}\n\n\\begin{myexample} \n\tThe set of integers $\\mathbb{Z}$ with the operation of addition forms a group. \n\tThe identity element is 0 and the inverse of an integer $a$ is the integer $-a$. \n\\end{myexample}\n\n\\begin{myexample} \n\tThe set $\\mathbb{Z}_n=\\{a \\in \\mathbb{Z} | 0 \\leq a \\leq n - 1\\}$, with the operation of addition modulo $n$, forms a group of order $n$. \n\tThe set $\\mathbb{Z}_n$ with the operation of multiplication modulo $n$ is not a group, since not all elements have multiplicative inverses. \n\\end{myexample}\n\n\\begin{mydef} \n\tThe multiplicative group of $\\mathbb{Z}_n$ is $\\mathbb{Z}_n^* = \\{a \\in \\mathbb{Z}_n | gcd(a, n) = 1\\}$. \n\tIn particular, if n is a prime, then $\\mathbb{Z}_n^* = \\{a | 1 \\leq a \\leq n - 1\\}$.\n\\end{mydef}\n\n\\begin{myexample} \n\tThe set $\\mathbb{Z}_n^*$ is a group under the operation of multiplication modulo $n$, with identity element 1.\\end{myexample}\n\n\\begin{mydef}\n\tA non-empty subset $H$ of a group $G$ is a subgroup of $G$ if $H$ is itself a group\n\twith respect to the operation of $G$. If $H$ is a subgroup of $G$ and $H \\neq G$, then $H$ is called a proper subgroup of $G$.\n\\end{mydef}\n\n\\begin{mydef} \n\tA group $G$ is cyclic if there is an element $\\alpha \\in G $such that for each $b \\in G$ there is an integer $i$ with $b= \\alpha^i$. Such an element $\\alpha$ is called a generator of $G$. \n\\end{mydef}\n\n\\section{Rings}\n\n\\begin{mydef} \n\tA ring $(R,+,\\times)$ consists of a set $R$ with two binary operations arbitrarily denoted $+$ (addition) and $\\times$ (multiplication) on $R$, satisfying the following axioms.\n\t\\begin{itemize}\n\t\t\\item[(i)] $(R, +)$ is an abelian group with identity denoted $0$.\n\t\t\\item[(ii)] The operation $\\times$ is associative. That is, $a \\times (b \\times c) = (a \\times b)\\times c \\quad \\forall a, b, c \\in R$.\n\t\t\\item[(iii)] There is a multiplicative identity denoted $1$, with $1 \\neq 0$, such that $1 \\times a = a \\times 1 = a \\forall a \\in R.$.\n\t\t\\item[(iv)] The operation $\\times$ is distributive over $+$. That is, $a \\times (b+c) = (a \\times b)+(a \\times c) \\textmd{ and } (b + c) \\times a = (b \\times a) + (c \\times a) \\quad \\forall a, b, c \\in R.$\n\t\t\n\t\\end{itemize} \n\tThe ring is a commutative ring if $a \\times b = b \\times a \\quad \\forall a, b \\in R$.\n\\end{mydef}\n\n\\begin{myexample}\n\tThe set $\\mathbb{Z}_n$ with addition and multiplication performed modulo $n$ is a commutative ring.\n\\end{myexample}\n\n\\begin{mydef} \n\tAn element $a$ of a ring $R$ is called a unit or an invertible element if there is an element $b \\in R $ such that $a \\times b = 1$. \n\tThe set of units in a ring $R$ forms a group under multiplication, called the group of units of $R$.\n\\end{mydef}\n\n\\begin{myexample} \n\tThe group of units of the ring $\\mathbb{Z}_n$ is $\\mathbb{Z}_n^*$. \n\\end{myexample}\n\n\n\\section{Fields}\n\n\\begin{mydef} \n\tA field is a commutative ring in which all non-zero elements have multiplicative inverses.  \n\\end{mydef}\n\n\\begin{mydef} \n\tThe characteristic of a field is 0 if $\\overbrace{1+1+\\dots+1}^{m times}$ is never equal to $0$ for any $m \\geq 1$. Otherwise, the characteristic of the field is the least positive integer $m$ such that $\\sum_{i=1}^{m}1 = 0$.\n\\end{mydef}\n\n\\begin{myexample} \nthe rational numbers $\\mathbb{Q}$, the real numbers $\\mathbb{R}$ and the complex numbers $\\mathbb{C}$ form fields of characteristic $0$ under the usual operations. \n\\end{myexample}\n\n\\begin{myexample} \n\t$\\mathbb{Z}_n$ is a field (under the usual operations of addition and multiplication modulo $n$) if and only if $n$ is a prime number. If $n$ is prime, then $\\mathbb{Z}_n$ has characteristic $n$. \n\\end{myexample}\n\n\\section{Finite Fields}\n\n\\begin{mydef} \n\tA finite field is a field $F$ which contains a finite number of elements. The order of $F$ is the number of elements in $F$. \\end{mydef}\n\n\\begin{myprop}\n\t(existence and uniqueness of finite fields)\n\t\\begin{itemize}\n\t\t\\item[(i)] If $F$ is a finite field, then $F$ contains $p^m$ elements for some prime $p$ and integer $m \\geq 1$.\n\t\t\\item[(ii)] For every prime power order $p^m$, there is a unique (up to isomorphism) finite field of order $p^m$. This field is denoted by $\\mathbb{F}_{p^m}$, or sometimes by $GF(p^m)$\\footnote{Galois Field}.\n\t\\end{itemize}\n\tInformally speaking, two fields are isomorphic if they are structurally the same, although the representation of their field elements may be different. Note that if $p$ is a prime then $\\mathbb{Z}_p$ is a field, and hence every field of order $p$ is isomorphic to $\\mathbb{Z}_p$. Thus the finite field $\\mathbb{F}_p$ can be identified with $\\mathbb{Z}_p$.\n\\end{myprop}", "meta": {"hexsha": "0f775df36eabc2661c1f49bb72d6703dc8747144", "size": 5824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix/AppendixA.tex", "max_stars_repo_name": "LeoComandini/Thesis", "max_stars_repo_head_hexsha": "d5754ae5c05f110e1fba115dc011f240878933f3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2018-04-09T03:42:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-20T10:25:26.000Z", "max_issues_repo_path": "Appendix/AppendixA.tex", "max_issues_repo_name": "LeoComandini/Thesis", "max_issues_repo_head_hexsha": "d5754ae5c05f110e1fba115dc011f240878933f3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Appendix/AppendixA.tex", "max_forks_repo_name": "LeoComandini/Thesis", "max_forks_repo_head_hexsha": "d5754ae5c05f110e1fba115dc011f240878933f3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-04-06T17:48:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-19T09:36:36.000Z", "avg_line_length": 51.5398230088, "max_line_length": 356, "alphanum_fraction": 0.6816620879, "num_tokens": 1917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.9207896704568164, "lm_q1q2_score": 0.8354437213080911}}
{"text": "\\subsection{Linear algebra}\n\nThe $dot$ function is used to multiply tensors.\nFor example, let\n\\begin{equation*}\nA=\\begin{pmatrix}1&2\\\\3&4\\end{pmatrix}\n\\quad{\\rm and}\\quad x=\\begin{pmatrix}x_1\\\\x_2\\end{pmatrix}\n\\end{equation*}\n\n\\noindent\nThe product $Ax$ is computed as follows.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((1,2),(3,4))\nx = (x1,x2)\ndot(A,x)\n\\end{verbatim}\n}\n\n\\noindent\n$\\begin{bmatrix}\nx_1+2x_2\\\\\n3x_1+4x_2\n\\end{bmatrix}$\n\n\\bigskip\n\\noindent\nThe following example shows how to use $dot$ and $inv$ to solve for\nthe vector $X$ in $AX=B$.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((3,7),(1,-9))\nB = (16,-22)\nX = dot(inv(A),B)\nX\n\\end{verbatim}\n}\n\n\\noindent\n$X=\\begin{bmatrix}-\\tfrac{5}{17}\\\\ \\\\ \\tfrac{41}{17}\\end{bmatrix}$\n\n\\bigskip\n\\noindent\nThe $dot$ function can have more than two arguments.\nFor example, $dot(A,B,C)$ can be used for the dot product of three tensors.\n\n\\bigskip\n\\noindent\nSquare brackets are used for component access.\nIndex numbering starts with 1.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\nA[1,2] = -A[1,1]\nA\n\\end{verbatim}\n}\n\n\\noindent\n$\\begin{bmatrix}a&-a\\\\c&d\\end{bmatrix}$\n\n\\bigskip\n\\noindent\nThe following example demonstrates the relation\n$A^{-1}=\\frac{\\operatorname{adj}A}{\\operatorname{det}A}$.\n\n{\\color{blue}\n\\begin{verbatim}\nA = ((a,b),(c,d))\ninv(A)\n\\end{verbatim}\n}\n\n\\noindent\n$\\begin{bmatrix}\\frac{d}{ad-bc} & -\\frac{b}{ad-bc}\\\\-\\frac{c}{ad-bc} & \\frac{a}{ad-bc}\\end{bmatrix}$\n\n{\\color{blue}\n\\begin{verbatim}\nadj(A)\n\\end{verbatim}\n}\n\n\\noindent\n$\\begin{bmatrix}d & -b\\\\-c & a\\end{bmatrix}$\n\n{\\color{blue}\n\\begin{verbatim}\ndet(A)\n\\end{verbatim}\n}\n\n\\noindent\n$ad-bc$\n\n{\\color{blue}\n\\begin{verbatim}\ninv(A) - adj(A)/det(A)\n\\end{verbatim}\n}\n\n\\noindent\n$\\begin{bmatrix}0 & 0\\\\0 & 0\\end{bmatrix}$\n\n\\bigskip\n\\noindent\nSometimes a calculation will be simpler if it can be reorganized to use\n$adj$ instead of $inv$.\nThe main idea is to try to prevent the determinant from appearing as a\ndivisor.\nFor example, suppose for matrices $A$ and $B$ you want to check that\n\\begin{equation*}\n{A}-{B}^{-1}=0\n\\end{equation*}\nDepending on the complexity of $\\mathop{\\rm det}B$, the software\nmay not be able to find a simplification that yields zero.\nShould that occur, the following alternative formulation can be tried.\n\\begin{equation*}\nA\\operatorname{det}B-\\operatorname{adj}B=0\n\\end{equation*}\n", "meta": {"hexsha": "eb66b49ca295770334f6f6a8a40200cceac56de4", "size": 2318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/linear-algebra.tex", "max_stars_repo_name": "franko/eigenmath", "max_stars_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2019-09-29T03:15:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T00:57:51.000Z", "max_issues_repo_path": "doc/linear-algebra.tex", "max_issues_repo_name": "franko/eigenmath", "max_issues_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2019-11-12T00:57:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T23:46:46.000Z", "max_forks_repo_path": "doc/linear-algebra.tex", "max_forks_repo_name": "franko/eigenmath", "max_forks_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2019-10-03T13:23:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T13:28:00.000Z", "avg_line_length": 18.8455284553, "max_line_length": 100, "alphanum_fraction": 0.6885245902, "num_tokens": 831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870766, "lm_q2_score": 0.8824278587245935, "lm_q1q2_score": 0.8353032701017287}}
{"text": "\\def\\fac{{\\left(k^*/k\\right)^\\alpha}}\n\n\\subsection{Convergence}\n\nFollowing \\cite{Dunkley2008}, we model the power spectrum of each variate as:\n\n\\begin{equation}\nP(k) = P_0 {{\\fac\\over{\\fac + 1}}}\n\\end{equation}\n\n$P_0$ is an estimate of the sample variance, and $k^*$ is the\nwavenumber where the power spectrum turns over to white noise.\n\n{\\bf Implementation Notes}\n\nWe fit the power spectrum to this function, for which we require the\nderivatives w.r.t. $P_0$, $k^*$ and $\\alpha$.  Letting\n\n\\begin{equation}\nf = \\fac,\n\\end{equation}\n\nwe have:\n\n\\begin{eqnarray}\\nonumber\n{df}\\over{dk^*} &=& f\\,{{\\alpha}\\over{k^*}}\\\\\\nonumber\n{df}\\over{d\\alpha} &=& f\\,\\ln{(k^*/k)}\n\\end{eqnarray}\n\nand \n\n\\begin{eqnarray}\\nonumber\n{{dP}\\over{dP_0}} &=& {{f}\\over{f+1}}\\\\\\nonumber\n{{dP}\\over{dk^*}} = {{dP}\\over{df}}{{df}\\over{dk^*}} &=& {{f}\\over{f+1}}\\times P_0\\left[1 - {{f}\\over{f+1}}\\right]{{\\alpha}\\over{k^*}}\\\\\\nonumber\n{{dP}\\over{d\\alpha}} = {{dP}\\over{df}}{{df}\\over{d\\alpha}} &=& {{f}\\over{f+1}}\\times P_0\\left[1 - {{f}\\over{f+1}}\\right]{\\ln{(k^*/k)}}\n\\end{eqnarray}\n\nNote that the convergence test relies on using the power spectrum of\nthe chain $\\tilde{P}(k)$ to estimate the true sample variance $P_0$.\nThus the power spectrum should be normalized so that $P(k=0)$ is an\nestimate of the sample variance.  For real transforms in FFTW, the\ndiscrete Fourier transform is unnormalized, or\n\n\\begin{equation}\nY_k = \\sum^{N-1}_{j=0}{X_j e^{-2\\pi jk\\sqrt{-1}/N}}\n\\end{equation}\n\nFor $k=0$, we see that \n\n\\begin{equation}\nY_0 = \\sum^{N-1}_{j=0}{X_j},\n\\end{equation}\n\nand\n\n\\begin{eqnarray}\nY^2_0 &=& \\left(\\sum^{N-1}_{j=0}{X_j}\\right)^2\\\\\n &=& \\sum_j{X^2_j} + \\sum_i\\sum_{j\\neq i}{X_iX_j}\\\\\n &=& N \\left<X^2\\right> + 0,\n\\end{eqnarray}\n\nassuming the $X_i$ and $X_j$ are uncorrelated.  Therefore, in order\nfor the power spectrum to reflect the variance, we instead compute the\npower spectrum of the normalized samples $X_j^\\prime = X_j/\\sqrt{N}$.\n\nOnce $P_0$\n", "meta": {"hexsha": "7858221da14790492fd375bcf827ab6be31fa692", "size": 1940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "help/convergence.tex", "max_stars_repo_name": "erikleitch/climax", "max_stars_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-01T05:15:31.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-01T05:15:31.000Z", "max_issues_repo_path": "docs/convergence.tex", "max_issues_repo_name": "erikleitch/climax", "max_issues_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/convergence.tex", "max_forks_repo_name": "erikleitch/climax", "max_forks_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-02T19:35:55.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-07T00:54:51.000Z", "avg_line_length": 28.9552238806, "max_line_length": 145, "alphanum_fraction": 0.6567010309, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9674102542943774, "lm_q2_score": 0.8633915976709975, "lm_q1q2_score": 0.8352538850585285}}
{"text": "\\section{Linear Classifier}\nFeature vectors $x$, labels $y$\n\\begin{align*}\nx \\in \\mathbb{R}^d\\\\\ny \\in \\{-1,1\\}\n\\end{align*}\nTraining set\n\\begin{align*}\nS_n = \\{(x^{(i)}, y^{(i)}), i=1,...,n\\}\n\\end{align*}\n\nClassifier\n\\begin{align*}\nh: \\mathbb{R}^d \\rightarrow \\{-1,1\\}\\\\\n\\chi^{+} = \\{x \\in \\mathbb{R}^d: h(x) =1\\}\\\\\n\\chi^{-} = \\{x \\in \\mathbb{R}^d: h(x) =-1\\}\n\\end{align*}\n\nTraining error\n\\begin{align*}\n\\varepsilon_n(h)= \\frac{1}{n} \\sum_{i=1}^n \\textbf{1}\\{h(x^{(i)}) \\neq y^{(i)} \\}\n\\end{align*}\n\nTest error (over disjoint set of examples)\n\n\\begin{align*}\n\\varepsilon(h)\n\\end{align*}\n\nSet of classifiers\n\\begin{align*}\nh \\in H\n\\end{align*}\n\n\\subsection{Linear classifiers through origin}\n\nSet of all points that satisfies a line through the origin.\n\n\\begin{align*}\n\\theta &= \\begin{bmatrix}\n           \\theta_{1} \\\\\n           \\theta_{2}\n         \\end{bmatrix}\\\\\nX &= \\begin{bmatrix}\n           x_{1} \\\\\n           x_{2}\n         \\end{bmatrix}\\\\\n\\end{align*}\n\nDecision Boundary\n\\begin{align*}\n\\{x&: \\theta_1 x_1 + \\theta_2 x_2 = 0\\}\\\\\n\\{x&: \\theta \\cdot X=0\\}\n\\end{align*}\n\nLinear Classifier through origin\n\\begin{align*}\nh(x,\\theta)=sign(\\theta \\cdot X)\\\\\n\\Theta \\in \\mathbb{R}^d\n\\end{align*}\n\n\\subsection{Linear classifiers}\nGeneral linear Classifier (with Intercept)\n\\begin{align*}\n\\theta &= \\begin{bmatrix}\n           \\theta_{1} \\\\\n           \\theta_{2}\n         \\end{bmatrix}\\\\\nX &= \\begin{bmatrix}\n           x_{1} \\\\\n           x_{2}\n         \\end{bmatrix}\\\\\n\\end{align*}\n\nDecision Boundary\n\\begin{align*}\n\\{x&: \\theta \\cdot X + \\theta_0 = 0\\}\n\\end{align*}\n\nLinear Classifier through origin\n\\begin{align*}\nh(x,\\Theta, \\theta_0)=sign(\\theta \\cdot X + \\theta_0)\\\\\n\\theta \\in \\mathbb{R}^d\\\\\n\\theta_0 \\in \\mathbb{R}\n\\end{align*}\n\n\\subsection{Linear Separation}\n\nTraning examples $S_n = \\{(x^{(i)}, y^{(i)}), i=1,...,n\\}$ are linear separable if there exists a parameter vector $\\hat{\\theta}$ and offset parameter $\\hat{\\theta}_0$ such that $y^{(i)}(\\hat{\\theta} \\cdot x^{(i)} + \\hat{\\theta}_0 )>0$ for all $i=1,\\cdots,n$.\n\n\\begin{align*}\n(\\hat{\\theta} \\cdot x^{(i)})>0\n\t\\begin{cases}\n\t\t y^{(i)}>0 \\text{ and } \\theta \\cdot x^{(i)} >0\\\\\n\t\t y^{(i)}<0 \\text{ and } \\theta \\cdot x^{(i)} <0\\\\\n\t\\end{cases}\n\\end{align*}\n\n$y^{(i)}(\\theta \\cdot x^{(i)})>0$ if label and classified result match. This leads to a new definition of the \\textbf{Training error}:\n\n\\begin{align*}\n\\varepsilon_n(\\theta)&= \\frac{1}{n} \\sum_{i=1}^n \\textbf{1}\\{y^{(i)}(\\theta \\cdot x^{(i)}) \\leq 0\\}\\\\\n\\varepsilon_n(\\theta,\\theta_0)&= \\frac{1}{n} \\sum_{i=1}^n \\textbf{1}\\{y^{(i)}(\\theta \\cdot x^{(i)} + \\theta_0) \\leq 0\\}\n\\end{align*}\n\n\\subsection{Perceptron through Origin}\n\\textbf{Perceptron}$\\displaystyle \\left(\\big \\{ (x^{(i)}, y^{(i)}), i=1,...,n\\big \\} , T \\right):$\n\\begin{enumerate}[\\indent {}]\n\t\\item initialize  $\\theta=0$ (vector);\n\t\\begin{enumerate}[\\indent {}]\n\t\t\\item for $t=1,\\cdots,T$ do\n\t\t\\begin{enumerate}[\\indent {}]\n\t\t\t\\item for $i=1,\\cdots,n$ do\n\t\t\t\\begin{enumerate}[\\indent {}]\n\t\t\t\t\\item if $y^{(i)}(\\theta \\cdot x^{(i)})\\leq 0$ then \n\t\t\t\t\\item update $\\theta = \\theta + y^{(i)}x^{(i)}$\n\t\t\t\\end{enumerate}\n\t\t\\end{enumerate}\n\t\\end{enumerate}\n\\end{enumerate}\n\n\\subsection{Perceptron with Offset}\n\n\\textbf{Perceptron}$\\displaystyle \\left(\\big \\{ (x^{(i)}, y^{(i)}), i=1,...,n\\big \\} , T \\right):$\n\\begin{enumerate}[\\indent {}]\n\t\\item initialize  $\\theta=0$ (vector); $\\theta_0=0$ (scalar)\n\t\\begin{enumerate}[\\indent {}]\n\t\t\\item for $t=1,\\cdots,T$ do\n\t\t\\begin{enumerate}[\\indent {}]\n\t\t\t\\item for $i=1,\\cdots,n$ do\n\t\t\t\\begin{enumerate}[\\indent {}]\n\t\t\t\t\\item if $y^{(i)}(\\theta \\cdot x^{(i)} + \\theta_0)\\leq 0$ then\n\t\t\t\t\\item update $\\theta = \\theta + y^{(i)}x^{(i)}$\n\t\t\t\t\\item update $\\theta_0=\\theta_0 + y^{(i)}$\n\t\t\t\\end{enumerate}\n\t\t\\end{enumerate}\n\t\\end{enumerate}\n\\end{enumerate}\n\n\\subsection{Margin Boundary}\n\nThe Margin Boundary is the set of points  $x$  which satisfy $\\theta \\cdot x + \\theta _0= \\pm 1$. So, the distance (with signed direction) from the decision boundary to the margin boundary is $\\displaystyle \\frac{1}{\\mid \\mid \\theta \\mid \\mid }$.\n\n$\\frac{y^{(i)}(\\theta \\cdot x^{(i)} + \\theta _0)}{\\mid \\mid \\theta \\mid \\mid }=\\frac{1}{\\mid \\mid \\theta \\mid \\mid }.$\n\n\\textbf{Hinge Loss (agreement)}\n\\begin{align*}\nAgreement &= z = y^{(i)}(\\theta \\cdot x^{(i)} + \\theta _0)\\\\\nLoss_h(z) &= \n\\begin{cases}\n\t\t 0 \\text{ if } z \\geq 1\\\\\n\t\t 1-z \\text{ if } z < 1\n\\end{cases} \n\\end{align*}\n\n\\textbf{Regularization} means pushing out the margin boundaries by adding $max(\\frac{1}{\\mid \\mid \\theta \\mid \\mid })$ or $min(\\frac{1}{2}\\mid \\mid \\theta \\mid \\mid^2)$ to the objective function.\n\nAlternatively, the sum of the hinge losses can be calculated by\n$\\sum _{i=1}^{n} \\max \\{ 0, 1 - y^{(i)} (\\theta \\cdot x^{(i)} + \\theta _0)\\}$\n\n\\textbf{Objective Function}\n\nObjective function = average loss + regularization\\\\\n\nObjective function is minimized, learning becomes an optimization problem. Using hinge loss and margin boundaries is called \\textbf{Support Vector Machine} or \\textbf{Large margin linear classification}:\n\n\\begin{align*}\nJ(\\theta , \\theta _0) = \\frac{1}{n} \\sum _{i=1}^{n} \\text {Loss}_ h (z) + \\frac{\\lambda }{2} \\mid \\mid \\theta \\mid \\mid ^2.\n\\end{align*}\n\nWhere $\\lambda > 0$ is called the regularization parameter that regulates how important the margin boundaries are in comparison to the average hinge loss.\n\n\\textbf{Cost:} is an averaged loss.\n\n\\subsection{Gradient Descent}\n\nAssume $\\theta \\in \\mathbb{R}$ the goal is to find $\\theta$ that minimizes $J(\\theta , \\theta _0) = \\frac{1}{n} \\sum _{i=1}^{n} \\text {Loss}_ h (y^{(i)} (\\theta \\cdot x^{(i)} + \\theta _0 )) + \\frac{\\lambda }{2} \\mid \\mid \\theta \\mid \\mid ^2$ through gradient descent.\\\\\n\nIn other words, we will\n\\begin{itemize}\n\\item Start $\\theta$ at an arbitrary location: $\\theta \\leftarrow \\theta _{start}$\n\\item Update $\\theta$ repeatedly with $\\theta \\leftarrow \\theta - \\eta \\frac{\\partial J(\\theta , \\theta _0)}{\\partial \\theta }$ until $\\theta$ does not change significantly.\n\\end{itemize}\n\nWhere $\\eta >0$ is called the stepsize or \\textbf{learning parameter}.\n\n\\subsection{Stochastic Gradient Descent}\n\n\\begin{align*}\nJ(\\theta , \\theta _0) &= \\frac{1}{n} \\sum _{i=1}^{n} \\text {Loss}_ h (z) + \\frac{\\lambda }{2} \\mid \\mid \\theta \\mid \\mid ^2\\\\\n&= \\frac{1}{n} \\sum _{i=1}^{n}\\big [ \\text {Loss}_ h (z) + \\frac{\\lambda }{2} \\mid \\mid \\theta \\mid \\mid ^2 \\big ]\n\\end{align*}\n\nWith stochastic gradient descent, we choose $i \\in \\big \\{ 1,...,n \\big \\}$ at random and update $\\theta$ such that\\\\\n\n\\begin{align*}\n\\theta \\leftarrow \\theta - \\eta \\nabla _{\\theta } \\big [\\text {Loss}_ h(z) + \\frac{\\lambda }{2}\\mid \\mid \\theta \\mid \\mid ^2 \\big ]\n\\end{align*}\n", "meta": {"hexsha": "4b630975ae4f9139309adff782832c319f374ffe", "size": 6640, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/basic_concepts.tex", "max_stars_repo_name": "sharov-am/MITx_capstone_2", "max_stars_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "content/basic_concepts.tex", "max_issues_repo_name": "sharov-am/MITx_capstone_2", "max_issues_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content/basic_concepts.tex", "max_forks_repo_name": "sharov-am/MITx_capstone_2", "max_forks_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.3668341709, "max_line_length": 269, "alphanum_fraction": 0.6188253012, "num_tokens": 2446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8947894703109853, "lm_q1q2_score": 0.8352240642870676}}
{"text": "\\subsubsection{Real Distinct Eigenvalues}\r\n\\noindent\r\nReal, distinct eigenvalues are the simplest case, similar to real, distinct roots of an auxiliary equation.\r\n\\begin{theorem}\r\n\tLet $\\left\\{\\lambda_1, \\ldots, \\lambda_n\\right\\}$ be the set of unique eigenvalues and $\\left\\{\\vec{v_1}, \\ldots, \\vec{v_n}\\right\\}$ be the corresponding set of non-zero, unique, eigenvectors for an $n \\times n$ matrix $A$. Then the set of fundamental solutions to the system $\\vec{x}' = A\\vec{x}$ is $\\left\\{e^{\\lambda_1 t}\\vec{v_1}, \\ldots, e^{\\lambda_n t}\\vec{v_n} \\right\\}$\r\n\\end{theorem}\r\n\r\n\\begin{example}\r\n\tFind the general solution to the system\r\n\t\\begin{equation*}\r\n\t\t\\vec{x}' = \\begin{bmatrix}\r\n\t\t\t3 & 0 & 0 \\\\\r\n\t\t\t-5 & -2 & 0 \\\\\r\n\t\t\t1 & 1 & -1\r\n\t\t\\end{bmatrix} \\vec{x}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nFor a triangular matrix, the eigenvalues are simply the diagonal entries.\r\n\\begin{equation*}\r\n\t\\lambda = 3, -2, -1.\r\n\\end{equation*}\r\nFinding the eigenvector for $\\lambda = 3$,\r\n\\begin{equation*}\r\n\t(A - 3I)\\vec{v} = \\vec{0} \\implies \\vec{v} = C_1\\begin{bmatrix}\r\n\t\t-1 \\\\\r\n\t\t1 \\\\\r\n\t\t0\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nFinding the eigenvector for $\\lambda = -2$,\r\n\\begin{equation*}\r\n\t(A + 2I)\\vec{v} = \\vec{0} \\implies \\vec{v} = C_2\\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t-1 \\\\\r\n\t\t1\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nFinding the eigenvector for $\\lambda = -1$,\r\n\\begin{equation*}\r\n\t(A + I)\\vec{v} = \\vec{0} \\implies \\vec{v} = C_3\\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t0 \\\\\r\n\t\t1\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nSo, our general solution is\r\n\\begin{equation*}\r\n\t\\vec{x} = C_1e^{3t}\\begin{bmatrix}\r\n\t\t-1 \\\\\r\n\t\t1 \\\\\r\n\t\t0\r\n\t\\end{bmatrix} + C_2e^{-2t}\\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t-1 \\\\\r\n\t\t1\r\n\t\\end{bmatrix} + C_3e^{-t}\\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t0 \\\\\r\n\t\t1\r\n\t\\end{bmatrix}.\r\n\\end{equation*}", "meta": {"hexsha": "1f21fa7de22c5ad924d8d690910db68b747e3617", "size": 1765, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/homogeneousSystems/realDistinctEigenvalues.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/linearSystems/homogeneousSystems/realDistinctEigenvalues.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/linearSystems/homogeneousSystems/realDistinctEigenvalues.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 28.4677419355, "max_line_length": 379, "alphanum_fraction": 0.6152974504, "num_tokens": 705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632916317102, "lm_q2_score": 0.900529795461386, "lm_q1q2_score": 0.8351182753315016}}
{"text": "The $\\Delta{}t$ component represents the time that it takes for the sound emitted by source $S$ to reach the position of virtual microphone $m$. Following from (\\ref{distance}), the value of $d_{\\vec{mS}}$ when combined with the speed of sound constant $c$ can be used to find the time-domain component.\n\n\\subsubsection{Calculating the speed of sound}\n\nThe speed of sound in real spaces is generally considered to be ~\\SI[per-mode=fraction]{343}{\\m\\per\\s}. However, it is not a constant. The speed of sound can change based on a number of environmental parameters. To account for this, the speed of sound can be adjusted by some value, $\\Delta{}c$, which is implemented in this version as a number $\\Delta{}c = [-10, 10]$; so that:\n\n\\begin{equation}\\label{speedofsound}\nc = 343 + \\Delta{}c\n\\end{equation}\n\nFollowing the usual formula for time:\n\n\\begin{equation}\\label{timeFormula}\nt = \\frac{d}{c}\n\\end{equation}\n\nSubstitutions can be made based on (\\ref{distance}) and (\\ref{speedofsound}) to give the expansion of $\\Delta{}t$:\n\n\\begin{equation}\\label{deltat}\n\\Delta{}t = \\frac{d_{\\vec{v}}}{343 + \\Delta{}c}\n\\end{equation}\n", "meta": {"hexsha": "d04e8e731f2487227dc5882eab25e9f251b88eb0", "size": 1123, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Technical Documentation/deltatcalc.tex", "max_stars_repo_name": "jmclark85/StereoPairsEmulator", "max_stars_repo_head_hexsha": "a78161b4b99b50e481c133ba8a5049d548561954", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Technical Documentation/deltatcalc.tex", "max_issues_repo_name": "jmclark85/StereoPairsEmulator", "max_issues_repo_head_hexsha": "a78161b4b99b50e481c133ba8a5049d548561954", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-26T18:24:14.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-26T18:24:14.000Z", "max_forks_repo_path": "Technical Documentation/deltatcalc.tex", "max_forks_repo_name": "jmclark85/StereoPairsEmulator", "max_forks_repo_head_hexsha": "a78161b4b99b50e481c133ba8a5049d548561954", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.0454545455, "max_line_length": 378, "alphanum_fraction": 0.7310774711, "num_tokens": 313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9693241947446617, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.8351098259293965}}
{"text": "\\chapter{Description of the Problem}\nLet $f: D \\rightarrow \\mdr$ with $D \\subseteq \\mdr$ be a polynomial function and $P \\in \\mdr^2$\nbe a point. Let $d_{P,f}: \\mdr \\rightarrow \\mdr_0^+$\nbe the Euklidean distance of $P$ to a point $\\left (x, f(x) \\right )$\non the graph of $f$:\n\\[d_{P,f} (x) := \\sqrt{(x - x_P)^2 + (f(x) - y_P)^2}\\]\n\nNow there is finite set $M = \\Set{x_1, \\dots, x_n} \\subseteq D$ of minima for given $f$ and $P$:\n\\[M = \\Set{x \\in D | d_{P,f}(x) = \\min_{\\overline{x} \\in D} d_{P,f}(\\overline{x})}\\]\n\nBut minimizing $d_{P,f}$ is the same as minimizing\n$d_{P,f}^2 = (x_p^2 - 2x_p x + x^2) + (y_p^2 - 2y_p f(x) + f(x)^2)$.\n\nIn order to solve the minimal distance problem, Fermat's theorem\nabout stationary points will be tremendously usefull:\n\n\\begin{theorem}[Fermat's theorem about stationary points]\\label{thm:fermats-theorem}\n    Let $x_0$ be a local extremum of a differentiable function $f: \\mathbb{R} \\rightarrow \\mathbb{R}$.\n\n    Then: $f'(x_0) = 0$.\n\\end{theorem}\n\nSo in fact you can calculate the roots of $(d_{P,f}(x))'$ or $(d_{P,f}(x)^2)'$ to get\ncandidates for minimal distance.\n$(d_{P,f}(x)^2)'$ is a polynomial if $f$ is a polynomial. So if $f$\nis a polynomial, we can always get a finite number of candidates by\nfinding roots of $(d_{P,f}(x)^2)'$. But this gets difficult when $f$\nhas degree 3 or higher as explained in Theorem~\\ref{thm:no-finite-solution}.\nAnother problem one has to bear in mind is that these candidates\ninclude all points with minimal distance, but might also contain\nmore. Example~\\ref{ex:false-positive} shows such a situation.\n\nLet $S_n$ be the function that returns the set of solutions for a\npolynomial $f$ of degree $n$ and a point $P$:\n\n\\[S_n: \\Set{\\text{Polynomials of degree } n \\text{ defined on } \\mdr} \\times \\mdr^2 \\rightarrow \\mathcal{P}({\\mdr})\\]\n\\[S_n(f, P) := \\underset{x\\in\\mdr}{\\arg \\min d_{P,f}(x)} = M\\]\n\nIf possible, I will explicitly give this function.\n", "meta": {"hexsha": "2f51c23febbdca53fb2c59df8fd7db49ac9eb9d2", "size": 1926, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/math-minimal-distance-to-cubic-function/problem-description.tex", "max_stars_repo_name": "RalfGuder/LaTeX-examples", "max_stars_repo_head_hexsha": "a1bf9fe422969be1ca4674394ebd2170c07f7693", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1231, "max_stars_repo_stars_event_min_datetime": "2015-01-07T04:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T17:43:29.000Z", "max_issues_repo_path": "documents/math-minimal-distance-to-cubic-function/problem-description.tex", "max_issues_repo_name": "DoubleL61/LaTeX-examples", "max_issues_repo_head_hexsha": "cd0d97f85fadb59b7c6e9062b37a8bf7d725ba0c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2015-05-10T13:10:47.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-02T21:28:49.000Z", "max_forks_repo_path": "documents/math-minimal-distance-to-cubic-function/problem-description.tex", "max_forks_repo_name": "DoubleL61/LaTeX-examples", "max_forks_repo_head_hexsha": "cd0d97f85fadb59b7c6e9062b37a8bf7d725ba0c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 400, "max_forks_repo_forks_event_min_datetime": "2015-01-05T06:22:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T04:07:59.000Z", "avg_line_length": 48.15, "max_line_length": 117, "alphanum_fraction": 0.6744548287, "num_tokens": 663, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191335436404, "lm_q2_score": 0.8740772368049823, "lm_q1q2_score": 0.835022708514755}}
{"text": "\n\\subsection{Defing sine and cosine using Euler's formula}\n\n\\subsubsection{Euler's formula}\n\nPreviously we showed that:\n\n\\(e^x=\\sum_{i=0}^\\infty \\dfrac{x^i}{i!}\\)\n\nConsider:\n\n\\(e^{i\\theta }\\)\n\n\\(e^{i\\theta }=\\sum_{j=0}^\\infty \\dfrac{(i\\theta )^j}{j!}\\)\n\n\\(e^{i\\theta }=[\\sum_{j=0}^\\infty \\dfrac{(\\theta )^{4j}}{(4j)!}-\\sum_{j=0}^\\infty \\dfrac{(\\theta )^{4j+2}}{(4j+2)!}]+i[\\sum_{j=0}^\\infty \\dfrac{(\\theta )^{4j+1}}{(4j+1)!}-\\sum_{j=0}^\\infty \\dfrac{(\\theta )^{4j+3}}{(4j+3)!}]\\)\n\nWe then use this to define \\(\\sin \\) and \\(\\cos \\) functions.\n\n\\(\\cos (\\theta ):=\\sum_{j=0}^\\infty \\dfrac{(\\theta )^{4j}}{(4j)!}-\\sum_{j=0}^\\infty \\dfrac{(\\theta )^{4j+2}}{(4j+2)!}\\)\n\n\\(\\sin (\\theta ):=\\sum_{j=0}^\\infty \\dfrac{(\\theta )^{4j+1}}{(4j+1)!}-\\sum_{j=0}^\\infty \\dfrac{(\\theta )^{4j+3}}{(4j+3)!}\\)\n\nSo:\n\n\\(e^{i\\theta }=\\cos (\\theta )+i\\sin (\\theta )\\)\n\n\\subsubsection{Alternative formulae for sine and cosine}\n\nWe know\n\n\\(e^{i\\theta }=\\cos (\\theta )+i\\sin (\\theta )\\)\n\n\\(e^{-i\\theta }=\\cos (\\theta )-i\\sin (\\theta )\\)\n\nSo\n\n\\(e^{i\\theta }+e^{-i\\theta }=cos (\\theta )+i\\sin (\\theta )+\\cos (\\theta )-i\\sin (\\theta )\\)\n\n\\(\\cos (\\theta )=\\dfrac{e^{i\\theta }+e^{-i\\theta }}{2}\\)\n\nAnd\n\n\\(e^{i\\theta }-e^{-i\\theta }=cos (\\theta )+i\\sin (\\theta )-\\cos (\\theta )+i\\sin (\\theta )\\)\n\n\\(\\sin (\\theta )=\\dfrac{e^{i\\theta }-e^{-i\\theta }}{2i}\\)\n\n\\subsubsection{Sine and cosine are odd and even functions}\n\nSine is an odd function.\n\n\\(\\sin (-\\theta )=-\\sin (\\theta )\\)\n\nCosine is an even function.\n\n\\(\\cos (-\\theta )=\\cos (\\theta )\\)\n\n", "meta": {"hexsha": "8742617de3a934ba61894fd1bb1c09f35847b37e", "size": 1510, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/trigonometry/01-01-trigCS.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/trigonometry/01-01-trigCS.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/trigonometry/01-01-trigCS.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0344827586, "max_line_length": 225, "alphanum_fraction": 0.5589403974, "num_tokens": 650, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191284552529, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.8350227009334458}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find the matrix for the linear transformation that\n  rotates every vector in $\\R^2$ by an angle of $\\pi /3$.\n  \\begin{sol}\n    $\\begin{mymatrix}{cc}\n      \\cos \\paren{\n        \\frac{\\pi}{3}} & -\\sin \\paren{\\frac{\\pi}{3}} \\\\\n      \\sin \\paren{\\frac{\\pi}{3}} & \\cos \\paren{\\frac{\\pi}{3}}%\n    \\end{mymatrix} = \\begin{mymatrix}{cc}\n      \\frac{1}{2} & -\\frac{1}{2}\\sqrt{3} \\\\\n      \\frac{1}{2}\\sqrt{3} & \\frac{1}{2}\n    \\end{mymatrix}$\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the matrix for the linear transformation that reflects every\n  vector in $\\R^2$ about the $x$-axis.\n\\end{ex}\n\n\\begin{ex}\n  Find the matrix for the linear transformation that reflects every\n  vector in $\\R^2$ about the line $y=-x$.\n\\end{ex}\n\n\\begin{ex}\n  Find the matrix for the linear transformation that stretches $\\R^2$\n  by a factor of $3$ in the vertical direction.\n\\end{ex}\n\n\\begin{ex}\n  Find the matrix of the linear transformation that reflects every\n  vector in $\\R^3$ about the $xy$-plane.\n\\end{ex}\n\n\\begin{ex}\n  Find the matrix of the linear transformation that reflects every\n  vector in $\\R^3$ about plane $x=z$.\n\\end{ex}\n\n\\begin{ex}\n  Describe the linear transformation that is given by each of the\n  following matrices. Draw a before-and-after picture for each.\n  \\begin{equation*}\n    (a)\\quad\n    A = \\begin{mymatrix}{rr}\n      1 & -1 \\\\\n      1 &  1 \\\\\n    \\end{mymatrix},\\quad\n    (b)\\quad\n    B = \\begin{mymatrix}{rr}\n      0 & 2 \\\\\n      1 & 0 \\\\\n    \\end{mymatrix},\\quad\n    (c)\\quad\n    C = \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      -1 & 1 \\\\\n    \\end{mymatrix},\\quad\n    (d)\\quad\n    D = \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Let $\\vect{u}=\\begin{mymatrix}{r} a \\\\ b \\end{mymatrix}$ be a unit\n  vector in $\\R^2$. Find the matrix%\n  \\index{reflection!about a given vector} that reflects all vectors\n  about this vector, as shown in the following picture.\n  \\begin{center}\n    \\begin{tikzpicture}[rotate=45]\n      \\draw[->](0,0)--(2,1.5);\n      \\draw[blue, ->](0,0) -- (3,0) node [right] {$\\vect{u}$};\n      \\draw[->](0,0)--(2,-1.5);\n    \\end{tikzpicture}\n  \\end{center}\n  \\begin{sol}\n    First, we compute $\\vect{v}'$, the projection of $\\vect{v}$ onto\n    $\\vect{u}$.\n    \\begin{center}\n      \\begin{tikzpicture}[rotate=45]\n        \\draw[->](0,0) -- node[left] {$\\vect{v}$} (2,1.5);\n        \\draw[blue, ->](0,0) -- (3,0) node [right] {$\\vect{u}$};\n        \\draw[red, ->](0,0) --  node [above] {$\\vect{v}'$} (2,0);\n        \\draw[->](0,0) -- node[below] {$T(\\vect{v})$} (2,-1.5);\n        \\draw[dashed,gray] (2,1.5) -- (2,-1.5);\n      \\end{tikzpicture}\n    \\end{center}\n    We have\n    \\begin{equation*}\n      \\vect{v}'\n      = \\proj_{\\vect{u}} \\vect{v}\n      = \\frac{\\vect{u}\\dotprod\\vect{v}}{\\norm{\\vect{u}}^2}\\,\\vect{u}.\n    \\end{equation*}\n    But since $\\vect{u}$ is a unit vector, this simplifies to\n    $\\vect{v}' = (\\vect{u}\\dotprod\\vect{v})\\vect{u}$.\n    From the above picture, we see that $T(\\vect{v}) = \\vect{v} +\n    2(\\vect{v}'-\\vect{v}) = 2\\vect{v}' - \\vect{v} =\n    2(\\vect{u}\\dotprod\\vect{v})\\vect{u} - \\vect{v}$.\n    To get the matrix of this linear transformation, we must compute\n    the image of the standard basis vectors:\n    \\begin{equation*}\n      T(\\vect{e}_1) = 2(\\vect{u}\\dotprod\\vect{e}_1)\\vect{u} - \\vect{e}_1\n      = 2a\\begin{mymatrix}{c} a\\\\b \\end{mymatrix} - \\begin{mymatrix}{c} 1\\\\0 \\end{mymatrix}\n      = \\begin{mymatrix}{c} 2a^2-1\\\\2ab \\end{mymatrix}\n    \\end{equation*}\n    \\begin{equation*}\n      T(\\vect{e}_2) = 2(\\vect{u}\\dotprod\\vect{e}_2)\\vect{u} - \\vect{e}_2\n      = 2b\\begin{mymatrix}{c} a\\\\b \\end{mymatrix} - \\begin{mymatrix}{c} 0\\\\1 \\end{mymatrix}\n      = \\begin{mymatrix}{c} 2ab\\\\2b^2-1 \\end{mymatrix}.\n    \\end{equation*}\n    Therefore, the matrix is\n    \\begin{equation*}\n      A = \\begin{mymatrix}{cc}\n        2a^2-1 & 2ab \\\\\n        2ab & 2b^2-1 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "766445eee093316a9f21ab0a9ae0b485ba43cc10", "size": 3966, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/LinearTransformationsRn-Geometric.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/LinearTransformationsRn-Geometric.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/LinearTransformationsRn-Geometric.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 31.2283464567, "max_line_length": 91, "alphanum_fraction": 0.5693393848, "num_tokens": 1535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362849986365572, "lm_q2_score": 0.8918110540642805, "lm_q1q2_score": 0.8349893115386415}}
{"text": "\\chapter{Combinatorics}\n\\section{Basics}\n\\subsection{Considerations}\n\\begin{enumerate}\n\\item Does \\textbf{order} matter?\n\\item Are the objects \\textbf{repeatable}?\n\\item Are the objects partially \\textbf{duplicated}?\n\\end{enumerate}}\nIf order does not matter, you can pre-set the order. \n\\subsection{Basic formula}\n\\begin{eqnarray*}\n&& {n \\choose k} = \\frac{n!}{k!(n-k)!} \\\\\n&& {n \\choose k} = {n \\choose n-k} \\\\\n&& {n\\choose k} = {n-1\\choose k} + {n-1 \\choose k-1}\n\\end{eqnarray*}\n\n\\subsection{N objects, K ceils}\nWhen $N=10, K=3$:\n$$\nx_1 + x_2 + x_3 = 10\n$$\nis equivalent to\n$$\n*****|**|***\n$$\n\n, notice that $*$ are non-order, and it is possible to have \n$$\n*****||*****\n$$\n\\\\\nthen the formula is:\n$$\n{n+r \\choose r}\n$$\n\n,where $r=k-1$. \n\\\\\nIntuitively, the meaning is to choose $r$ objects from $n+r$ objects to become the $|$.\n\n\\runinhead{Unique paths.} Given a $m \\times n$ matrix, starting from $(0, 0)$, ending at $(m-1, n-1)$, can only goes down or right. What is the number of unique paths?\n\nThere are total \n\n\\subsection{N objects, K types} \\label{N_objects_K_types}\nWhat is the number of permutation of $N$ objects with $K$ different types:\n\\begin{align*}\nret &= \\frac{A_N^N}{\\prod_{k=1}^K{A_{sz(k)}^{sz(k)}}} \\\\\n&= \\frac{N!}{\\prod_{k} sz[k]!}\n\\end{align*}\n\n\\subsection{Inclusion\u2013Exclusion Principle}\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=0.50]{500px-Inclusion-exclusion}}\n\\caption{Inclusion\u2013exclusion principl}\n\\label{fig:500px-Inclusion-exclusion}\n\\end{figure}\n\\begin{eqnarray*}\n|A \\cup B \\cup C| = |A| + |B| + |C| \\\\ - |A \\cap B| - |A \\cap C| - |B \\cap C| \\\\ + |A \\cap B \\cap C|\n\\end{eqnarray*}\nGenerally,\n$$\n\\Biggl|\\bigcup_{i=1}^n A_i\\Biggr| = \\sum_{k = 1}^{n} (-1)^{k+1} \\left( \\sum_{1 \\leq i_{1} < \\cdots < i_{k} \\leq n} \\left| A_{i_{1}} \\cap \\cdots \\cap A_{i_{k}} \\right| \\right)\n$$\n\\section{Combinations with Duplicated Objects}\nDetermine the number of combinations of 10 letters (order does not matter) that can be formed from 3A, 4B, 5C. \n\n\\subsection{Basic Solution}\nIf there are no restrictions on the number of any of the letter, it is ${10+2 \\choose 2}$; then we get the universal set, \n$$\n|U|={10+2 \\choose 2}\n$$\n\nLet $P_A$ be the set that a 10-combination has more than 3A. $P_B$...4B. $P_C$...5C. \n\nThe result is:\n\\begin{align*}\n|3A \\cap 4B \\cap 5C| = & |U|\\\\\n& - sum(|P_i|\\cdot \\forall i) \\\\\n& + sum(|P_i \\cap P_j|\\cdot \\forall i,j)\\\\\n& - sum(|P_i \\cap P_j \\cap P_k|\\cdot \\forall i,jk)\n\\end{align*}\n\nTo calculate $|P_i|$, take $|P_A|$ as an example. \\textbf{Pre-set} 4A -- if we take any one of these 10-combinations in $P_A$ and remove 4A we are left with a 6-combination with unlimited on the numbers of letters; thus,\n$$\n|P_A|={6+2 \\choose 2}\n$$\n\nSimilarly, we can get $P_B, P_C$.\n\nTo calculate $|P_i \\cap P_j}|$, take $|P_A \\cap P_B|$ as an example. \\textbf{Pre-set} 4A and 5B; thus,\n$$\n|P_A \\cap P_B| = {1+2 \\choose 2}\n$$\n\nSimilarly, we can get other $|P_i \\cap P_j|$.\n\nSimilarly, we can get other $|P_i \\cap P_j \\cap P_k|$.\n\\subsection{Algebra Solution}\nThe number of 10-combinations that can be made from 3A, 4B, 5C is found from the coefficient of $x^{10}$ in the expansion of:\n$$\n(1+x+x^2+x^3)(1+x+x^2+x^3+x^4)(1+x+x^2+x^3+x^4+x^5)\n$$\n\nAnd we know:\n\\begin{eqnarray*}\n1+x+x^2+x^3         = (1-x^4)/(1-x)  \\\\\n1+x+x^2+x^3+x^4     = (1-x^5)/(1-x)  \\\\\n1+x+x^2+x^3+x^4+x^5 = (1-x^6)/(1-x)  \\\\\n\\end{eqnarray*}\n\n\nWe expand the formula, although the  naive way of getting the coefficient of $x^{10}$ is tedious. \n\n\\section{Permutation}\n\n\\subsection{$k$-th permutation}\nGiven $n$ and $k$, return the $k$-th permutation sequence. $k\\in [1, n!]$. $O(nk)$ in time complexity is easy, can you do it in $O(n^2)$ or less?\n\nReversed Cantor Expansion\n\nCore clues:\n\\begin{enumerate}\n\\item \\pyinline{A = [1, 2, ..., n]}\n\nSuppose for $n$ element, the $k$-th permutation is:\n\n\\pyinline{ret = [a0, a1, a2, ..., an-1]}\n\\item \\rih{Basic case.} Since \\pyinline{[a1, a3, ..., an-1]} has $(n-1)!$ permutations,\nif $k < (n-1)!, a_0 = A_0$ (first element in array), else $a_0 = A_{k/(n-1)!}$\n\n\\item Recursively, (or iteratively), calculate the values at each position. Similar to Radix. \n\\begin{enumerate}\n\\item $a_0 = A_{k_0/(n-1)!}$, where $k_0 = k$\n\\item $a_1 = A_{k_1/(n-2)!}$, where $k_1 = k_0\\%(n-1)!$ in the remaining array $A$\n\\item $a_2 = A_{k_2/(n-3)!}$, where $k_2 = k_1\\%(n-2)!$ in the remaining array $A$\n\\end{enumerate}\n\\end{enumerate}\n\\begin{python}\ndef getPermutation(self, n, k):\n    k -= 1  # start from 0\n\n    A = range(1, n+1)\n    k %= math.factorial(n)\n    ret = []\n    for i in xrange(n-1, -1, -1):\n        idx, k = divmod(k, math.factorial(i))\n        ret.append(A.pop(idx))\n\n    return \"\".join(map(str, ret))\n\\end{python}\n\n\\subsection{Numbers counting}\n\\runinhead{Count numbers with unique digit.} Given a non-negative integer n, count all numbers with unique digits, $x$, where $0 \\leq x < 10^n$.\n\nDigit by digit: \n\\begin{enumerate}\n\\item The 1st digit has 10 possibilities. The 2nd digit has 9 possibilities. Therefore it seems to be $A_{10}^n$.\n\\item Exception: The first digit cannot be 0. Therefore it is $9\\times 9\\times 8\\times ...\\times (10-i)$\n\\end{enumerate}\n\n\n\n\\section{Catalan Number}\\label{section:catalanNumber}\n\\subsection{Math}\n\\runinhead{Definition.}\n$$\nC_n = {2n\\choose n} - {2n\\choose n+1} = {1\\over n+1}{2n\\choose n} \\quad\\text{ for }n\\ge 0\n$$\n\\runinhead{Proof.} Proof of Calatan Number $C_n ={2n\\choose n} - {2n\\choose n+1}$. Objective: count the number of paths in $n\\times n$ grid without exceeding the main diagonal. \n\\begin{itemize}\n\\begin{figure}[]\n    \\centerline{\\includegraphics[height = 1.6in]{catalan_proof}}\n    \\caption{Monotonic Paths}\n  \\label{fig:catalanProof}\n\\end{figure}\n\\item monotonic paths - $n$ right, $n$ up\n$$\n{2n\\choose n}\n$$\n\\item flip at the line just above the diagonal line - $n-1$ right, $n+1$ up\n$$\n{n-1+n+1\\choose n-1}\n$$\n\\item thus, the number of path without \\textit{exceedance} (i.e. passing the diagonal line) is: \n\\begin{align*}\nC_n &= {2n\\choose n} - {2n\\choose n-1}\\\\ \n&={2n\\choose n} - {2n\\choose n+1}\n\\end{align*}\n\\end{itemize}\n\n\\subsection{Applications}\nThe paths in Figure \\ref{fig:catalanProof} can be abstracted to anything that at any time \\#right $\\geq$ \\#up. \n\\runinhead{\\#Parentheses.}Number of different ways of adding parentheses. At any time, \\#\\pyinline{(} $\\geq$ \\#\\pyinline{)}.\n\\runinhead{\\#BSTs.}Number of different BSTs. Consider it as a set of same binary operators with their operands. Reduce this problem to \\#Parentheses. \n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=2.00]{Catalan_number_binary_tree_example}}\n\\caption{\\#BSTs. Circles are operators; crescents are operands.}\n\\label{fig:NumberOfBSTs}\n\\end{figure}\n\n\\section{Stirling Number}\na Stirling number of the second kind (or Stirling partition number) is the number of ways to partition a set of n objects into k non-empty subsets and is denoted by $S(n,k)$ or  $\\lbrace{n\\atop k}\\rbrace$.\n\n$$\n\\left\\{ {n \\atop k}\\right\\} = \\frac{1}{k!}\\sum_{j=0}^{k} (-1)^{k-j} \\binom{k}{j} j^n.\n$$\n", "meta": {"hexsha": "e83ec7a4402cba55b850ed77bdc98b5e32cb3459", "size": 7002, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterCombinatorics.tex", "max_stars_repo_name": "algorhythms/Algo-Quicksheet", "max_stars_repo_head_hexsha": "c5d219a96f195adf1d19d2d701986e01fc9b8195", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 902, "max_stars_repo_stars_event_min_datetime": "2015-08-16T08:25:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T05:23:50.000Z", "max_issues_repo_path": "chapterCombinatorics.tex", "max_issues_repo_name": "andysli6590/Algo-Quicksheet", "max_issues_repo_head_hexsha": "c5d219a96f195adf1d19d2d701986e01fc9b8195", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2015-07-06T17:24:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-12T00:01:38.000Z", "max_forks_repo_path": "chapterCombinatorics.tex", "max_forks_repo_name": "andysli6590/Algo-Quicksheet", "max_forks_repo_head_hexsha": "c5d219a96f195adf1d19d2d701986e01fc9b8195", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 92, "max_forks_repo_forks_event_min_datetime": "2015-10-09T03:13:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-20T00:57:08.000Z", "avg_line_length": 33.3428571429, "max_line_length": 220, "alphanum_fraction": 0.6573836047, "num_tokens": 2568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.931462503162843, "lm_q2_score": 0.8962513689768735, "lm_q1q2_score": 0.8348245436103234}}
{"text": "\\subsection{Bounds on eigenvalues}\n\n\\begin{Lemma}{bound-by-norm}\n  Let $\\norm{\\cdot}$ be a vector norm and denote by the same symbol\n  a consistent norm for matrices. Then, for any matrix $\\mata\\in\\Cnn$\n  and for any eigenvalue $\\lambda\\in\\sigma(\\mata)$ there holds\n  \\begin{gather}\n    \\abs{\\lambda} \\le \\norm{\\mata}.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{Lemma}{pre-gershgorin}\n  Let $\\mata,\\matb\\in\\Cnn$ and let $\\norm{\\cdot}$ be an operator norm\n  on the space of matrices corresponding to a vector norm denoted by\n  $\\norm{\\cdot}$ as well. Then, for any eigenvalue\n  $\\lambda\\in\\sigma(\\mata)$ such that $\\lambda\\not\\in\\sigma(\\matb)$\n  there holds\n  \\begin{gather}\n    \\norm*{(\\lambda\\id-\\matb)^{-1}(A-B)} \\ge 1.\n  \\end{gather}\n\\end{Lemma}\n\n\n\\begin{Theorem*}{gershgorin}{Gershgorin circle theorem}\n  All eigenvalues of a matrix $\\mata\\in\\Cnn$ are contained in the\n  union of the \\define{Gershgorin Circle}s\n  \\begin{gather}\n    G_j = \\left\\{ z\\in \\C \\middle| \\abs{z-a_{jj}} \\le \\sum_{k\\neq j} \\abs{a_{jk}}\\right\\}. \n  \\end{gather}\n  Furthermore, if there is a subset of $m$ circles disjoint from the\n  other circles, then this subset contains $m$ eigenvalues.\n\\end{Theorem*}\n\n\\subsection{The Rayleigh quotient}\n\n\\begin{Definition}{rayleigh-quotient}\n  For a matrix $\\mata\\in\\Cnn$ and a vector $\\vx\\in\\C^n$, the\n  \\define{Rayleigh quotient} is defined as\n  \\begin{gather}\n    R_\\mata(\\vx) = \\frac{\\scal(\\mata\\vx,\\vx)}{\\scal(\\vx,\\vx)}.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{Theorem*}{minmax}{Courant-Fischer min-max theorem}\n  Let $\\mata\\in\\Cnn$ be Hermitian with eigenvalues\n  $\\lambda_1 \\le \\lambda_2\\le\\dots\\le \\lambda_n$. Then, for $k=1,\\dots,n$\n  \\begin{align}\n    \\lambda_k\n    &= \\min_{\\substack{V \\subset \\C^n\\\\\\dim V = k}} \\max_{\\vx\\in V} R_\\mata(\\vx),\\\\\n    &= \\max_{\\substack{V \\subset \\C^n\\\\\\dim V = n-k+1}} \\min_{\\vx\\in V} R_\\mata(\\vx).\n  \\end{align}\n  In particular,\n  \\begin{gather}\n    \\lambda_{\\min}(\\mata) = \\min_{\\vx\\in\\C^n} R_\\mata(\\vx),\n    \\qquad\n    \\lambda_{\\max}(\\mata) = \\max_{\\vx\\in\\C^n} R_\\mata(\\vx).\n  \\end{gather}\n\\end{Theorem*}\n\n\\subsection{Conditioning of the eigenvalue problem}\nIn this section, we study the conditioning of finding eigenvalues and\neigenvectors. While we will not cover the full theory, we will provide\nexamples for ill-posed problems as well as exemplary proofs for\nwell-posedness.\n\nIn all cases, we will investigate the change of eigenvalues or\neigenvectors when the matrix $\\mata$ is perturbed by a small matrix\n$\\mate$ of norm $\\epsilon$.\n\n\\begin{Example}{characteristic-polynomial}\n  Take a matrix of dimension 20 with eigenvalues $1,2,\\ldots,20$. Its\n  characteristic polynomial is\n  \\begin{gather}\n    \\chi(\\lambda) = (\\lambda-1)\\dots(\\lambda-20).\n  \\end{gather}\n  The coefficient in front of $\\lambda^{20}$ is one, the constant term is $20! > 10^{19}$.\n  We perturbe it in the form\n  \\begin{gather}\n    \\tilde \\chi(\\lambda) = \\chi(\\lambda) - 10^{-23}\\lambda^{19}.\n  \\end{gather}\n  Their greatest roots are\n  \\begin{gather}\n    \\begin{array}{l@{\\qquad}l@{\\,}c@{\\,}l}\n      \\multicolumn{1}{c}{\\chi}&\n      \\multicolumn{3}{c}{\\tilde \\chi}\\\\\n      20&20.847\\\\\n      19,18&19.502&\\pm&1.940i\\\\\n      17,16&16.731&\\pm&2.813i\\\\\n      15,14&13.992&\\pm&2.519i\\\\\n    \\end{array}\n  \\end{gather}\n  {\\tiny Source: \\cite{DeuflhardHohmann08}}\n\\end{Example}\n\n\\begin{Example}{conditioning-Jordan-block}\n  Consider the matrix\n  \\begin{gather}\n  \\mata_\\epsilon =\n      \\begin{pmatrix}\n        0&1\\\\\n        &0&1\\\\\n        &&\\ddots&\\ddots\\\\\n        &&&0&1\\\\\n        \\epsilon &&&&0\n      \\end{pmatrix}\n      \\in\\C^{n\\times n},\n  \\end{gather}\n  For $\\epsilon=0$, it has a single eigenvalue of geometric multiplicity one and algebraic multiplicity $n$.\n  \n  For $\\epsilon>0$, it has $n$ simple eigenvalues\n  \\begin{gather}\n      \\lambda_j = \\sqrt[n]{\\epsilon} \\,e^{2\\frac jni\\pi}\n  \\end{gather}\n\\end{Example}\n\n\\begin{proof}\n  For $\\epsilon=0$, the matrix is the generic Jordan-block of an eigenvalue which is not semi-simple, thus the ill-posedness of this example implies the ill-posedness for not semi-simple eigenvalues in the general case. Note that this statement holds notwithstanding that special perturbations may be benign.\n  \n  The characteristic polynomial of this matrix is\n  \\begin{gather}\n      \\chi(\\lambda) = \\det(\\mata-\\lambda\\id)\n      = \\det\\begin{pmatrix}\n      -\\lambda&1\\\\  \n        &\\ddots&\\ddots\\\\\n        &&-\\lambda&1\\\\\n        \\epsilon &&&-\\lambda\n      \\end{pmatrix}.\n  \\end{gather}\n  Applying Laplace expansion to the first column yields\n  \\begin{gather}\n      \\chi(\\lambda)\n      = -\\lambda \\det\\begin{pmatrix}\n        -\\lambda&1\\\\\n        &\\ddots&\\ddots\\\\\n        &&-\\lambda&1\\\\\n        &&&-\\lambda\n      \\end{pmatrix}\n      + (-1)^{n+1} \\epsilon\\det\\begin{pmatrix}\n        1 \\\\\n        -\\lambda &1\\\\\n        &\\ddots&\\ddots\\\\\n        &&-\\lambda&1\n      \\end{pmatrix},\n  \\end{gather}\n  where both matrices are of dimension $n-1$. Since they are triangular, recursion of Laplace expansion is particularly simple and yields the product of the diagonal elements. Thus\n  \\begin{gather}\n      \\chi(\\lambda) = (-1)^n \\lambda^n\n      + (-1)^{n+1} \\epsilon.\n  \\end{gather}\n  Its roots are determined by the condition\n  \\begin{gather}\n      \\lambda^n = \\epsilon.\n  \\end{gather}\n  Thus, $\\lambda$ can be computed as an $n$th root of unity times the (real) $n$th root of $\\epsilon$.\n\\end{proof}\n\n\\begin{Theorem}{Jordan-block-ill-conditioned}\n  The eigenvalue problem for eigenvalues which are not semi-simple is\n  in general ill-posed.\n\\end{Theorem}\n\n\\begin{proof}\n  The analysis in \\slideref{Example}{conditioning-Jordan-block} is\n  generic in the sense that it applies to nonzero eigenvalues and also\n  to matrices which are similar to such a block. Thus, we can conclude\n  that for every matrix $\\mata$ which is similar to a matrix with a\n  nontrivial Jordan block for eigenvalue $\\lambda$, there is a\n  perturbation $\\mate$ such that the derivative of the function\n  $\\lambda(\\epsilon) = \\lambda(A+\\epsilon\\mate)$ at zero is unbounded.\n\\end{proof}\n\n\\begin{Theorem*}{bauer-fike}{Bauer-Fike}\n  Let $\\mata\\in \\Cnn$ be diagonalizable with matrix of eigenvectors\n  $\\matv \\in \\Cnn$ and diagonal matrix\n  $\\matlambda = \\diag(\\lambda_1\\dots,\\lambda_n)$. Let $\\mata+\\mate$ be\n  a perturbation of $\\mata$. Then, for any eigenvalue $\\mu$ of\n  $\\mata+\\mate$, there is an eigenvalue $\\lambda_i$ of $\\mata$ such\n  that\n  \\begin{gather}\n    \\abs{\\mu-\\lambda_i} \\le \\cond_2(\\matv) \\norm{\\mate}_2.\n  \\end{gather}\n\\end{Theorem*}\n\n\\begin{proof}\n  Wikipedia\n\\end{proof}\n\n\\begin{Corollary}{conditioning-eigenvalues-normal}\n  The eigenvalue problem of a normal matrix $\\mata\\in\\Cnn$ is\n  well-conditioned in the sense that for every eigenvalue $\\mu$ of the\n  perturbed matrix $\\mata+\\mate$, there is an eigenvalue $\\lambda$ of\n  $\\mata$ such that\n  \\begin{gather}\n    \\abs{\\mu-\\lambda} \\le \\norm{E}_2.\n  \\end{gather}\n\\end{Corollary}\n\nThe Bauer-Fike theorem provides a general estimate for diagonalizable\nmatrices in terms of the condition number of the matrix of\neigenvectors. The following theorem is less general, since it only\napplies to simple eigenvalues, but it provides geometric intuition of\nthe issue.\n\n\\begin{Theorem}{conditioning-eigenvalue-single}\n  Let $\\mata_\\epsilon = \\mata+\\epsilon\\mate\\in\\Cnn$ be a perturbation\n  of $\\mata\\in\\Cnn$. Let $\\lambda(0)$ and let $\\lambda(0)$ be a single\n  eigenvalue of $\\mata$. Then, there exists a uniquely defined\n  differentiable continuation $\\lambda(\\epsilon)$ for small $\\epsilon$\n  such that $\\lambda(\\epsilon) \\in \\sigma(\\mata_\\epsilon)$ and with\n  its left and right eigenvectors $u$, and $w$, respectively, there\n  holds\n  \\begin{gather}\n    \\abs*{\\tfrac{d}{d\\epsilon} \\lambda(0)}\n    \\le \\norm{E}_2\\frac{\\norm{u}_2\\norm{w}_2}{\\abs{\\scal(u,w)}}\n    = \\norm{E}_2 \\frac1{\\cos\\angle(u,w)}.\n  \\end{gather}\n\\end{Theorem}\n\n\\subsection{Conditioning of eigenvectors and eigenspaces}\n\n\\begin{intro}\n  Positive results on the conditioning of eigenvectors require\n  additional tools which go beyond the exposition planned for this\n  class. We will thus only discuss this question at hand of an example\n  and conclude a rule of thumb.\n\\end{intro}\n\n\\begin{Example}{conditioning-eigenvectors}\n  Consider the two matrices\n  \\begin{gather}\n    A =\n    \\begin{pmatrix}\n      1-\\epsilon & 0\\\\ 0 & 1+\\epsilon\n    \\end{pmatrix},\n    \\qquad\n    B =\n    \\begin{pmatrix}\n      1&\\epsilon\\\\\\epsilon&1\n    \\end{pmatrix}.\n  \\end{gather}\n  Their eigenvalues are $1-\\epsilon$ and $1+\\epsilon$, but their\n  eigenvectors differ by an angle of $\\pi/4$ independent of\n  $\\epsilon$.\n\\end{Example}\n\n\\begin{Remark}{conditioning-eigenvectors}\n  The problem of finding eigenvectors for tight clusters of\n  eigenvalues is ill-posed. Nevertheless, finding the invariant\n  subspace associated to all eigenvalues in such a cluster is\n  well-posed.\n\n  Conditioning of the eigenvector problem depends on the separation of\n  eigenvalues.\n\\end{Remark}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "dc339ea617f7c61c14e17f2399ff621588900c6c", "size": 8971, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nla/conditioning.tex", "max_stars_repo_name": "guidokanschat/notes", "max_stars_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nla/conditioning.tex", "max_issues_repo_name": "guidokanschat/notes", "max_issues_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "nla/conditioning.tex", "max_forks_repo_name": "guidokanschat/notes", "max_forks_repo_head_hexsha": "d13f1265ad5be4d584265b7579fc267df8ebe78a", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-05-15T19:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-05T19:07:29.000Z", "avg_line_length": 34.5038461538, "max_line_length": 308, "alphanum_fraction": 0.6772935013, "num_tokens": 2855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.9111796991580949, "lm_q1q2_score": 0.8347404883671211}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 9}\n\nLet us guess that perhaps $T(n)$ can be expressed as an affine function of $n$:\n\\begin{equation}\nT(n) = \\alpha n + \\beta\n\\end{equation}\nWe have already seen that this is a reasonable guess.\nSubstitute equation 3 in the equation 1 and 2 and solve the two resulting equations $\\alpha$ and $\\beta$.\n\n\\subsection*{Solution}\n\nTo obtain an intuition, we begin by formulating $T(n)$ for $n = 1$ and $n=2$.\n\nIf $n = 1$, there are no nodes in left and right subtrees.\n\\begin{equation}\n\\begin{aligned}\nT(1) &= c + T(0) + T(0) + v\\\\\n&= (2c + v) \\times 1 + c\n\\end{aligned}\n\\end{equation}\nIf $n = 2$, there is 1 node in one subtree and no node in the other subtree.\n\\begin{equation}\n\\begin{aligned}\nT(2) &= c + T(1) + T(0) + v\\\\\n&= (2c + v) \\times 2 + c\n\\end{aligned}\n\\end{equation}\nTherefore, we prove the statement by induction on number of nodes $n$.\nWe form the inductive hypothesis as for a tree with $k$ nodes ($k \\leq k_t$), $T(n)$ is as described as in Equation \\ref{eq93}.\n\\begin{equation}\nT(k) = (2c + v) \\times k + c\n\\label{eq93}\n\\end{equation}\nNow we show that the statement holds true for $k = k_t + 1$.\nIn this case, we assume there are $l$ nodes in the left subtree and $r = k_t - l - 1$ nodes in the right subtree.\nSince $l, r \\leq k$, Equation \\ref{eq94} would be valid.\n\\begin{equation}\n\\begin{aligned}\nT(k) &= c + T(l) + T(r) + v\\\\\n&= c + (2c + v) \\times l + c + (2c + v) \\times r + c + v\\\\\n&= (2c + v) + (2c + v)(l + r) + c\\\\\n&= (2c + v) \\times k + c\n\\end{aligned}\\label{eq94}\n\\end{equation}\nTherefore,\n\\begin{align}\n\\alpha &= 2c + v\\\\\n\\beta &= c\n\\end{align}\\label{eq95}\n", "meta": {"hexsha": "bb2d97d11159c5e0d938b8f014a23f63c3509184", "size": 1956, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q09.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q09.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q09.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 34.3157894737, "max_line_length": 127, "alphanum_fraction": 0.6129856851, "num_tokens": 659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.9161096084360388, "lm_q1q2_score": 0.8347404851441924}}
{"text": "\\subsection{Chain Rule}\r\n\\begin{lemma}\r\n\tLet $f$ and $g$ be differentiable functions. Then\r\n\t\\begin{equation}\r\n\t\t\\dd{}{x}f(g(x)) = f^\\prime(g(x))g^\\prime(x).\r\n\t\\end{equation}\r\n\tEquivalently, if $f$ is a function of $g$ and $g$ is a function of $x$,\r\n\t\\begin{equation}\r\n\t\t\\dd{f}{x} = \\dd{f}{g}\\hspace{3pt}\\dd{g}{x}.\r\n\t\\end{equation}\r\n\\end{lemma}\r\n\\begin{proof}\r\n\tApplying the limit definitions of the derivative,\r\n\t\\begin{align*}\r\n\t\t\\dd{f}{x} &= \\lim_{h \\to 0}{\\frac{f(g(x+h))-f(g(x))}{h}} \\\\\r\n\t\t&= \\lim_{h\\to 0}{\\frac{f(g(x+h))-f(g(x))}{g(x+h)-g(x)}\\hspace{3pt}\\frac{g(x+h)-g(x)}{h}} \\\\\r\n\t\t&= \\lim_{h\\to 0}{\\frac{f(g(x+h))-f(g(x))}{g(x+h)-g(x)}} \\hspace{3pt} \\lim_{h\\to 0}{\\frac{g(x+h)-g(x)}{h}} \\\\\r\n\t\t&= \\left(\\lim_{h\\to 0}{\\frac{f(g(x+h))-f(g(x))}{g(x+h)-g(x)}}\\right) \\hspace{3pt} \\dd{g}{x} \\\\\r\n\t\t&= \\dd{f}{g}\\hspace{3pt}\\dd{g}{x}.\r\n\t\\end{align*}\r\n\\end{proof}\r\n\r\n\\begin{example}\r\n\tFind the derivative of $y = (x^2 + 1)^5$ using the chain rule.\r\n\\end{example}\r\n\\begin{answer}\r\n\t$y$ is a composition of the two functions $x^5$ and $x^2 + 1$.\r\n\tApplying the chain rule, \r\n\t\\begin{equation*}\r\n\t\ty^\\prime = \\dd{}{(x^2+1)}(x^2+1)^5 \\hspace{3pt} \\dd{}{x}(x^2+1)\r\n\t\\end{equation*}\r\n\t\r\n\tMaking the substitution $u = x^2 + 1$,\r\n\t\\begin{align*}\r\n\t\ty^\\prime &= \\dd{}{u}u^5 \\hspace{3pt} \\dd{}{x}(x^2+1) \\\\\r\n\t\t&= 5u^{4}2x\r\n\t\\end{align*}\r\n\t\r\n\tSubstituting back,\r\n\t\\begin{align*}\r\n\t\ty^\\prime &= 5(x^2+1)^{4}2x \\\\\r\n\t\t&= 10x(x^2+1)^4.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{$u$ Substitutions}\r\nAs we did in the example, we can substitute a variable, usually called $u$ when applying the chain rule.\r\n\\begin{example}\r\n\tGiven that the derivative of $\\sin{x}$ is $\\cos{x}$, find the derivative of $f(x)=\\sin^5{x}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\t$f$ is a composition of $x^5$ and $\\sin$.\r\n\tSubstituting $u=\\sin{x}$, we can rewrite $f$ as $u^5$.\r\n\tApplying the chain rule,\r\n\t\\begin{align*}\r\n\t\t\\dd{f}{x} &= \\dd{f}{u} \\hspace{3pt} \\dd{u}{x} \\\\\r\n\t\t&= 5u^4 \\hspace{3pt} \\cos{x} \\\\\r\n\t\t&= 5\\sin^4{x}\\cos{x}.\r\n\t\\end{align*}\r\n\\end{answer}", "meta": {"hexsha": "594b6b04c3b4b361ff6b718abb73e8e0d09e4b2f", "size": 2021, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/derivative_rules/chain_rule.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/derivatives/derivative_rules/chain_rule.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/derivatives/derivative_rules/chain_rule.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.6833333333, "max_line_length": 111, "alphanum_fraction": 0.5685304305, "num_tokens": 891, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897442783527, "lm_q2_score": 0.8872045974451017, "lm_q1q2_score": 0.8346729863529561}}
{"text": "\\subsection{Gradient Descent}\r\n\\noindent\r\nRemember that if we have a multidimensional function, taking a step in the direction of the gradient results in the maximum possible increase of the function, and taking a step in the opposite direction of the gradient results in the maximum possible decrease of the function. Gradient descent is a method to find minima of functions.\\\\\r\n\r\n\\noindent\r\nLet's say we're trying to minimize $J(\\vec{x})$ with gradient descent. Here are the steps we would take:\r\n\\begin{enumerate}\r\n\t\\item Pick (or guess) a starting point $\\vec{x_0}$ and a learning rate (step size) $\\delta$.\r\n\t\\item $\\vec{x_{n+1}} = \\vec{x_n} - \\delta J(\\vec{x_n})$\r\n\t\\item Repeat step 2 until some stopping criteria is met, like $\\norm{\\delta \\nabla J(\\vec{x_n}) - \\delta \\nabla J(\\vec{x_{n+1}})}<.01$.\r\n\\end{enumerate}\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nThis method will lead you arbitrarily close to a local minimum, but does not guarantee finding the global minimum. More advanced versions of gradient descent exists that try to help with this, like giving the point \u201cmomentum\u201d to be able to move out of local mins.\r\nThis method also has a trade off between speed and accuracy. Although increasing $\\delta$ means fewer iterations of gradient descent are needed to narrow in on a local minimum, one is more likely to be stuck in a local min than they had used a smaller $\\delta$.\\\\\r\n\r\n\\noindent\r\nIn the real world, the function you are trying to minimize will likely not be well defined enough to take its partial derivatives to find the gradient, so they too are approximated by doing something like\r\n\\begin{equation*}\r\n\tJ_{k} = \\frac{J(k+.0001, \\ldots) - J(k, \\ldots)}{.0001}\r\n\\end{equation*}", "meta": {"hexsha": "3194f053e9397750233d26f187b98ff3e3d6b9c2", "size": 1698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/gradientDescent.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/gradientDescent.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/gradientDescent.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.8260869565, "max_line_length": 337, "alphanum_fraction": 0.746171967, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951142215838086, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.8346052190395045}}
{"text": "\n\\subsection{Cartesian product}\n\nThe cartesian product takes two sets, and creates a set containing all ordered pairs of \\(a\\) and \\(b\\).\n\n\\(a\\times b\\)\n\n", "meta": {"hexsha": "7712e735fec2f72b0cb59431146091d5b22c66ef", "size": 154, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sets/03-03-cartesian.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sets/03-03-cartesian.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sets/03-03-cartesian.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.25, "max_line_length": 104, "alphanum_fraction": 0.7142857143, "num_tokens": 39, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9458012701768144, "lm_q2_score": 0.8824278695464501, "lm_q1q2_score": 0.8346013998564528}}
{"text": "\\section{Adam algorithm}\nAdam (Kingma and Ba, 2014) is yet another adaptive learning rate optimization algorithm. Adam optimization is an extension to stochastic gradient decent and can be used in place of classical stochastic gradient descent to update network weights more efficiently. The name ``Adam'' derives from the phrase \\emph{Adaptive Moment Estimation}, which adapts both learning rate $\\eta$ and subgradient $g$.\n\n\n\nLet $g$ be the gradient of the stochastic objective $f$ with parameters $x$. We wish to estimate its  first order moment vector (the mean of gradients), and second order moment vector (the uncentered variance of gradients)  using an exponential moving average of the squared gradient, with decay rate $\\beta_1$ and $\\beta_2$, respectively. Let $g_1$, $g_2$, $\\cdots$, $g_T$ be the gradients at subsequent timesteps. \nUse moving average of both $g$ and $g^2$ (here $g^2$ indicates the element-wise square% $g \\bigodot g$\n) to compute first order moment vector  \n\\begin{equation}\nm_t  =\\sum_{i=1}^{t} w_i g_i,\\quad w_i={\\beta_1^{t-i} \\over \\sum_{i=1}^t\\beta_1^{t-i}},\n\\end{equation}\nand second order moment vector  \n\\begin{equation}\nv_t  =\\sum_{i=1}^{t}r_i g^2_i,\\quad r_i={\\beta_2^{t-i} \\over \\sum_{i=1}^t\\beta_2^{t-i}}.\n\\end{equation}\nHere $\\beta_1 = 0.9$, $\\beta_2 = 0.99$.\n\nThe iterate can be written as \n\\begin{equation}\\label{Adam}\nx_{t+1}=x_t-\\frac{\\eta}{\\sqrt{v_t}+\\delta} m_t,\n\\end{equation}\nwhere $\\eta$ is stepsize, $\\delta$ is some small constant and $x$ is the parameter vector. Another way to represent the first and second order moment vector  is \n\\begin{align}\nm_t=\\frac{\\tilde m_t}{1-\\beta_1^t} &\\mbox{ with }\\ \\tilde m_t  =\\beta_1 \\tilde m_{t-1} + (1-\\beta_1) g_t,\\\\\nv_t=\\frac{\\tilde v_t}{1-\\beta_2^t}&\\mbox{ with }\\ \\tilde v_t  =\\beta_2 \\tilde v_{t-1} + (1-\\beta_2) g_t^2,\t\n\\end{align}\nwhich is usually used in implementation as in the following algorithm.\n\n\\begin{algorithm}[H]\n\\caption{Adam Optimization}\n\\label{alg:Adam}\n{\\bf Input}: \n\\begin{enumerate}\n\\item small constant $\\delta$ (can be $10^{-8}$), \n\\item decay rate for moment estimates $\\beta_1$ and $\\beta_2$ (suggested defaults: 0.9 and 0.999 respectively)\n\\item initial first moment vector $m_0=0$ and initial second moment vector $v_0=0$\n\\item initial timestep $t=0$, initial parameter vector $x_0$ and stepsize $\\eta$\n\\end{enumerate}\n{\\bf Steps}: \n\nCompute the gradient on $B_{i_t}$:\n\\begin{equation}\ng_t = \\nabla_{x} \\frac{1}{m} \\sum_{i \\in B_{i_t}} f_i(x_{t}),\\quad B_{i_t} \\subset \\{1, 2, \\cdots, N \\},\\ \\#B_{i_t} =m\n\\end{equation}\nUpdate biased first moment estimate:\n\\begin{equation}\nm_t = \\beta_1 m_{t-1} + (1-\\beta_1)g_t.\n\\end{equation}\nUpdate biased second moment estimate:\n\\begin{equation}\nv_t = \\beta_2 v_{t-1} + (1-\\beta_2)g_t \\circ g_t.\n\\end{equation}\nCorrect bias in first moment:\n\\begin{equation}\n\\tilde m_t = \\frac{m_t}{1 - \\beta_1^{t}}.\n\\end{equation}\nCorrect bias in second moment:\n\\begin{equation}\n\\tilde v_t = \\frac{v_t}{1 - \\beta_2^{t}}.\n\\end{equation}\nCompute update:\n\\begin{equation}\n\\Delta x_t =  -\\frac{\\eta}{\\sqrt{\\tilde v_t} + \\delta} \\otimes \\tilde m_t\n\\end{equation}\nUpdate $w$:\n\\begin{equation}\nx_{t+1} = x_t + \\Delta x_t.\n\\end{equation}\n\\end{algorithm}\n", "meta": {"hexsha": "014df2904b7cbfd6b7ff86dd746d1b01a6bf911c", "size": 3192, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/adam.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/adam.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/adam.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.6, "max_line_length": 416, "alphanum_fraction": 0.7086466165, "num_tokens": 1097, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012655937034, "lm_q2_score": 0.8824278571786139, "lm_q1q2_score": 0.8346013841146728}}
{"text": "Now we prove from the Well Ordering principle the Principle of Mathematical Induction. The idea will be as follows: we will consider the \\textit{smallest} element such that a proposition is false, and then we will use the assumptions of the Priniciple of Mathematical Induction to derive contradictions. Hence the Principle of Mathematical Induction is true as stated.\n\nIn fact, if we assume the Principle of Mathematical Induction as a given statement, we can use it to show the well ordering principle of the natural numbers. But to give a rigorous proof we need the Principle of Strong Induction, which we will prove from the Principle of Weak Induction later.\n\n\\begin{theorem}\nSuppose that $P: \\mathbb{N} \\to \\{T, F\\}$ is a boolean function with the following properties:\n\\begin{itemize}\n\t\\item $P(1) \\equiv T$\n\t\\item $P(n) \\equiv T \\implies P(n + 1) \\equiv T$ for all $n \\in \\mathbb{N}$.\n\\end{itemize}\nThen $P(n) \\equiv T$ for all $n \\in \\mathbb{N}$.\n\\end{theorem}\n\n\\begin{proof}\nAssume for the sake of contradiction that there is some $s \\in \\mathbb{N}$ such that $P(s) \\equiv F$. Let $S$ be the set of all $s$ where $P(s) \\equiv F$. By assumption, $S \\neq \\varnothing$, and hence by the well ordering principle there is a minimal element $r \\in S$. We see that $r \\neq 1$ because $P(1) \\equiv T$ by assumption. So $r - 1 \\in \\mathbb{N}$. But since $r \\in S$ is minimal, we must have that $P(r - 1) \\equiv T$ (or else our assumption about $r$ being the minimal element in $S$ would be wrong). But since $P(r - 1) \\equiv T$, this implies that $P(r) \\equiv T$ (by modus ponens). This is a contradiction and the conclusion follows.\n\\end{proof}\n\nTo prove the other direction (namely, that the Principle of Mathematical Induction implies the Well Ordering Principle), we need the stronger principle of Strong Induction. So what we will do is use the Principle of Mathematical Induction to prove the Principle of Strong Induction first.\n\n\\begin{theorem}\nSuppose that the Principle of Mathematical Induction is true. Suppose that $P: \\mathbb{N} \\to \\{T, F\\}$ is a boolean function with the following properties:\n\\begin{itemize}\n\t\\item $P(1) \\equiv T$\n\t\\item If $P(k) \\equiv T$ for all $1 \\leq k \\leq n$ for $n \\geq 1$, then $P(n + 1) \\equiv T$.\n\\end{itemize}\n\nThen $P(n) \\equiv T$ for all $n \\in \\mathbb{N}$.\n\\end{theorem}\n\n\\begin{proof}\nDefine an auxiliary function $Q: \\mathbb{N} \\to \\{T, F\\}$ by the following:\n\\[Q(n) \\equiv \\begin{cases} T & \\text{$P(k) \\equiv T$ for $1 \\leq k \\leq n$}\\\\ F & \\text{otherwise.}\\end{cases}\\]\nThen by assumption, $Q(1) \\equiv T$ and $Q(k) \\equiv T$ implies that $P(n + 1)$ is true, which together with $Q(n)$ implies that $Q(n + 1) \\equiv T$. Hence by the Principle of Mathematical Induction we have that $Q(n)$ is true for all $n \\in \\mathbb{N}$ which implies that $P(n)$ is true for all $n \\in \\mathbb{N}$, as desired.\n\\end{proof}\n\nThe converse statement is also true, this will be left as an exercise. Now that we have the principle of strong induction, we can use it now to prove the well ordering principle. This will show that the Well Ordering Principle and the Principle of Mathematical Induction are equivalent.\n\n\\begin{theorem}\nThe Strong Induction Principle implies the Well Ordering Principle. Hence the Well Ordering Principle and the Principle of Mathematical Induction are equivalent.\n\\end{theorem}\n\\begin{proof}\nSuppose that $S \\subset \\mathbb{N}$ is a non-empty set with no least element. Let $P$ be the following proposition:\n\\[P(n) = \\begin{cases}T & n \\not\\in S \\\\ F & n \\in S\\end{cases}.\\]\nSo the proposition $P(n)$ reflects whether or not $n$ is in the set $S$. Since $1$ is the least element in $\\mathbb{N}$, we know that $1 \\not\\in S$ or else $S$ would have a least element. So $P(1) \\equiv T$. Now suppose for any $n \\in \\mathbb{N}$ that $P(k) \\equiv T$ for $1 \\leq k \\leq n$. Then by the definition of $P$ no natural number less than or equal to $n$ is in $S$. It follows that $n + 1 \\not\\in S$ or else $n + 1$ would be the least element in $S$. It follows that $P(n + 1) \\equiv T$.\n\nBy the Principle of Strong Induction it follows that $P(n) \\equiv T$ for all $n \\in \\mathbb{N}$. This implies that no element $n \\in \\mathbb{N}$ is in $S$. So $S = \\varnothing$. The Well Ordering Principle follows, as desired.\n\\end{proof}\n\n\\section{Exercises}\n\\input{ch5/wopIndExercises}", "meta": {"hexsha": "4f28021f2e04f1b303bafb154ac24fbed1b36868", "size": 4331, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch5/proving_wind.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch5/proving_wind.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch5/proving_wind.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 86.62, "max_line_length": 649, "alphanum_fraction": 0.7146155622, "num_tokens": 1289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.908617906212312, "lm_q1q2_score": 0.834547592168594}}
{"text": "\n\\subsection{Axiom of extensionality}\n\nIf two sets contain the same elements, they are equal.\n\n\\(\\forall x \\forall y[\\forall z(z\\in x \\leftrightarrow z\\in y)\\rightarrow x=y]\\)\n\nThis is an axiom, not a definition, because equality was defined as part of first-order logic.\n\nNote that this is not bidirectional. \\(x=y\\) does not imply that \\(x\\) and \\(y\\) contain the same elements. This is appropriate as \\(\\dfrac{1}{2}= \\dfrac{2}{4}\\) for example, even though they are written differently as sets.\n\n\\subsubsection{Reflexivity of equality}\n\nThe reflexive property is:\n\n\\(\\forall x(x=x)\\)\n\nWe can replace the instance of \\(y\\)  with \\(x\\):\n\n\\(\\forall x [\\forall z(z\\in x \\leftrightarrow z\\in x)\\rightarrow x=x]\\)\n\nWe can show that the following is true:\n\n\\(\\forall z(z\\in x \\leftrightarrow z\\in x)\\)\n\nTherefore:\n\n\\(\\forall x [T \\rightarrow x=x]\\)\n\n\\(x=x\\)\n\n\\subsubsection{Symmetry of equality}\n\nThe symmetry property is:\n\n\\(\\forall x \\forall y[(x=y)\\leftrightarrow (y=x)]\\)\n\nWe know that the following are true:\n\n\\(\\forall x \\forall y[\\forall z(z\\in x \\leftrightarrow z\\in y)\\rightarrow x=y]\\)\n\n\\(\\forall x \\forall y[\\forall z(z\\in x \\leftrightarrow z\\in y)\\rightarrow y=x]\\)\n\nSo:\n\n\\(\\forall x \\forall y[\\forall z(z\\in x \\leftrightarrow z\\in y)\\rightarrow (x=y\\land y=x)]\\)\n\n\\subsubsection{Transitivity of equality}\n\nThe transitive property is:\n\n\\(\\forall x \\forall y \\forall z[(x=y \\land y=z) \\rightarrow x=z]\\)\n\n\\subsubsection{Substitution for functions}\n\nThe substitutive property for functions is:\n\n\\(\\forall x \\forall y[(x=y)\\rightarrow (f(x)=f(y))]\\)\n\n\\subsubsection{Substitution for formulae}\n\nThe substitutive property for formulae is:\n\n\\(\\forall x \\forall y[((x=y)\\land P(x))\\rightarrow P(y)]\\)\n\nDoesn\u2019t this require iterating over predicates? Is this possible in first order logic??\n\n\\subsubsection{Result 1: The empty set is unique}\n\nWe can now show the empty set is unique.\n\n\\subsubsection{Result 2: Every element of a set exists}\n\nIf an element did not exist, the set containing it would be equal to a set which did not contain that element.\n\n\\subsubsection{Result 3: Sets are unique}\n\n\n", "meta": {"hexsha": "933545eb84f4ce86037b8f784c449133b06257f7", "size": 2098, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/setsExtensionality/01-01-equality.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/setsExtensionality/01-01-equality.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/setsExtensionality/01-01-equality.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.5569620253, "max_line_length": 224, "alphanum_fraction": 0.714013346, "num_tokens": 573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.9019206673024666, "lm_q1q2_score": 0.8344840184491857}}
{"text": "\\section{Formula Sheet}\n\\subsection{Basics}\n\\paragraph{Standard Deviation} $$SD(x) = \\sqrt{\\frac{1}{n-1}\\Sigma_i (x_i - \\bar{x})^2}$$\n\\paragraph{Variance} $$Var(x) = \\frac{1}{n-1}\\Sigma_i (x_i - \\bar{x})^2$$\n\\paragraph{Covariance} $$Cov(x,y) = \\frac{1}{n-1}\\Sigma_i (x_i - \\bar{x})(y_i - \\bar{y})$$\n\\paragraph{Normal Distribution} $$f(x) = \\frac{1}{\\sigma \\sqrt{2\\pi}}e^{-\\frac{(x-\\mu)^2}{2\\sigma^2}}$$\nstandardized: $$Z = \\frac{X - \\mu}{\\sigma}$$\n\\paragraph{Probability density function (pdf): f(x)} $$f(x) = P(X = x)$$\n\n\\paragraph{Cumulative distribution fuction (cdf): F(x)} $$F(x) = P(X \\leq x)$$ $$P(X \\geq x) = 1 - F(x)$$  $$P(x_1 \\leq X \\leq x_2) = F(x_2) - F(x_1)$$\n\\paragraph{Confidence Interval} $$CI = \\left[ \\bar{X} - z_{(1 - \\frac{\\alpha}{2})}\\cdot \\frac{\\sigma}{\\sqrt{n}} , \\bar{X} + z_{(1 - \\frac{\\alpha}{2})}\\cdot \\frac{\\sigma}{\\sqrt{n}} \\right] $$\n$$CI = \\left[ \\bar{X} - t_{(1 - \\frac{\\alpha}{2})}\\cdot \\frac{s}{\\sqrt{n}} , \\bar{X} + t_{(1 - \\frac{\\alpha}{2})}\\cdot \\frac{s}{\\sqrt{n}} \\right] $$\n\\subsection{Linear Regression}\n\\subsubsection{First Order Linear Model}\n\n$$Y = \\beta_0 + \\beta_1 X + \\varepsilon$$\n\n\\paragraph{OLS Estimator}\n\n\\begin{align*}\n\t\\hat{\\beta}_1 &= \\dfrac{\\frac{1}{n-1}\\Sigma_i (x_i - \\bar{x})(y_i - \\bar{y})}{\\frac{1}{n-1}\\Sigma_i (x_i - \\bar{x})^2} = \\frac{Cov(x,y)}{Var(x)} \\\\ \\ \\\\\n\t\\hat{\\beta}_0 &= \\bar{y} - \\hat{\\beta}_1\\cdot \\bar{x} \\\\ \\ \\\\\n\t\\hat{y} &= \\hat{\\beta}_0 + \\hat{\\beta}_1 x\n\\end{align*}\t\n\n\\subsubsection{Multiple Linear Regression Model}\n$$Y = \\beta_0 + \\beta_1 X_1 + \\beta_2 X_2 + \\dots + \\beta_k X_k + \\varepsilon$$\nFormulation in \\textbf{matrix form}:\n$$\\begin{bmatrix}\ny_1 \\\\ y_2 \\\\ \\vdots \\\\ y_m\n\\end{bmatrix} = \\begin{bmatrix}\n1 & X_11 &X_12 &\\dots &X_1k \\\\\n1 & X_21 &X_22 &\\dots &X_2k \\\\\n\\vdots & \\vdots &\\vdots &\\vdots &\\vdots \\\\\n1 & X_m1 &X_m2 &\\dots &X_mk\n\\end{bmatrix} \\begin{bmatrix}\n\\beta_0 \\\\ \\beta_1 \\\\ \\beta_2 \\\\ \\vdots \\\\ \\beta_k\n\\end{bmatrix} + \\begin{bmatrix}\n\\varepsilon_1 \\\\ \\varepsilon_2 \\\\ \\vdots \\\\ \\varepsilon_m\n\\end{bmatrix}$$\n$$[m \\times 1] = [m \\times (k+1)] \\cdot [(k+1) \\times 1] + [m \\times 1]$$\n\n\\paragraph{OLS Estimator} \n\\begin{itemize}\n\t\\item Model:\n\t\\begin{align*}\n\t\tRSS  &= e^{T} e = (y - X\\hat{\\beta})^T (y - X\\hat{\\beta}) \\rightarrow \\min \\\\\n\t\t\\rightarrow  &\\frac{\\partial RSS}{\\partial \\beta} = -2X^Ty + 2X^TX\\beta= 0\n\t\\end{align*}\n\t\n\t\\item Solution:\n\t\\begin{align*}\n\t\t\\hat{\\beta} &= (X^TX)^{-1}X^Ty \\\\ \n\t\t\\hat{y} &= X(X^TX)^{-1}X^Ty\n\t\\end{align*}\n\n\t\n\n\n\\end{itemize}\n\\subsubsection{Quality Metrics of Linear Regression Models}\n\\paragraph{Residual Sum of Squares (RSS)}\nAn \\textbf{unbiased} estimator of RSS of the population is given by \n$$RSS = \\Sigma_{i=1}^{n} (y_i - \\hat{y}_i)^2$$\n\n\\paragraph{Mean Squared Error (MSE)}\n$$MSE = \\frac{RSS}{N}$$\n\\paragraph{Root Mean Squared Error (RMSE)}\n$$RMSE = \\sqrt{MSE}$$\n\\paragraph{Total Sum of Squares (TSS)} sum of Explained Sum of Squares(ESS) and Residual Sum of Squares(RSS).\n\\begin{align*}\n\t\\Sigma (y - \\bar{y})^2 &= \\Sigma (\\hat{y} - \\bar{y})^2 + \\Sigma (y - \\hat{y})^2 \\\\\n\tTSS &= ESS + RSS\n\\end{align*}\n\\paragraph{R-squared $\\mathbf{R^2}$} the proportional of explained variablity from the model\n$$R^2 = \\frac{TSS - RSS}{TSS} = 1 - \\frac{RSS}{TSS} = \\frac{ESS}{TSS}$$ \n\n\n\\subsection{Logistic Regression \\& Poisson Regression}\n\\subsubsection{The Logistic Regression Model}\nThe \\textbf{binary} logistic regression model described in \\textbf{log odds/logit}:\n$$log\\_odds  =  \\ln(\\frac{p(X)}{1 - p(X)}), \\quad  \\ln(\\frac{p(X)}{1 - p(X)}) = \\beta_0 + \\beta_1 X + \\varepsilon$$\n\nThe logistic regression model described in \\textbf{odds}: \n$$odds = \\frac{p(X)}{1 - p(X)}, \\quad \\frac{p(X)}{1 - p(X)} = e^{\\beta_0 + \\beta_1 X}$$\n\n\\subsubsection{The Logistic Function}\n$$Pr[Y|X] = p(X) = \\dfrac{e^{\\beta_0 + \\beta_1 X}}{1 + e^{\\beta_0 + \\beta_1 X}}$$\n\n\\subsubsection{Multiple Logistic Regression Model}\n$$\\ln(\\frac{p(X)}{1 - p(X)}) = \\beta_0 + \\beta_1 X_1 + \\beta_2 X_2 + \\dots + \\beta_k X_k$$\n\nThe logistic function can also be described as a \\textbf{sigmoid function} in form $S(x) = \\frac{e^x}{1 + e^x} = \\sigma(x)$\n$$P(X) = \\sigma(\\beta_0 + \\beta_1 X)$$\n\\subsubsection{The Likelihood Function and Maximum Likelihood Estimator}\n\\paragraph{likelihood function for Logistic Regression Model}\n\\begin{align*}\n\tL &= \\Pi_{i=1} p^{y_i}(1-p)^{1-y_i} \\\\\n\t&= \\Pi_{i=1} \\sigma(\\beta_0 + \\beta_1 X)^{y_i} \\cdot (1 - \\sigma(\\beta_0 + \\beta_1 X))^{1-y_i}\n\\end{align*}\n\\paragraph{Log of Likelihood Function}\n$$LL = \\ln(L) = \\Sigma_{i=1} ( y_{i} \\ln(p) + (1 - y_i)\\ln(1-p))$$\n\\paragraph{Maximum Likelihood Estimator}\n\\begin{align*}\n\t\\beta = \\arg\\max_{\\beta}(LL) &= \\arg\\max_{\\beta} [\\Sigma_{i=1} ( y_{i} \\ln(p) + (1 - y_i)\\ln(1-p))] \\\\\n\t&= \\arg\\max_{\\beta} [\\Sigma_{i=1} ( y_{i} \\ln(\\sigma(\\beta_0+\\beta_1X)) + (1 - y_i)\\ln(1-\\sigma(\\beta_0 + \\beta_1X)))]\n\\end{align*}\n\n\\paragraph{Gradient(partial derivatives) of the LL-Function}: \\textbf{chain rule}\n\nwith $z = \\beta_0+\\beta_1X$\n\n$$\\frac{\\partial LL}{\\beta_j} = \\Sigma_{i=1} \\frac{\\partial LL}{\\partial p} \\cdot \\frac{\\partial p}{\\partial z} \\cdot \\frac{\\partial z}{\\partial \\beta_j}$$\n\\begin{align*}\n\t\\frac{\\partial LL}{\\partial p} &= \\frac{y_i}{p} - \\frac{1 - y_i}{1 - p} \\\\\n\t\\frac{\\partial p}{\\partial z} &= \\sigma(z) \\cdot(1 - \\sigma(z)) \\\\\n\t\\frac{\\partial z}{\\partial \\beta_0} &= 1 \\text{, } \\frac{\\partial z}{\\partial \\beta_j} = x_j\\\\\t\t \n\\end{align*}\n\\begin{align*}\n\t\\frac{\\partial LL}{\\beta_0} &= \\left[ \\frac{y_i}{p} - \\frac{1 - y_i}{1 - p}\\right]  \\sigma(z) \\cdot(1 - \\sigma(z)) = \\left[ y_i - \\sigma(X\\beta) \\right] \\\\\n\t\\frac{\\partial LL}{\\beta_j} &= \\left[ \\frac{y_i}{p} - \\frac{1 - y_i}{1 - p}\\right]  \\sigma(z) \\cdot(1 - \\sigma(z))\\cdot x_j = \\left[ y_i - \\sigma(X\\beta) \\right] x_j\n\\end{align*}\n\n\\subsubsection{Poisson Regression Model}\n$$ln(\\mu(x)) = \\beta_0 + \\beta_1 X_1 + \\dots \\beta_j X_i$$\n\n\\paragraph{random component(dependent variable)}\n$$Pr(Y|X) = p(X) = \\dfrac{e^{-\\mu} \\mu^y}{y!} = \\dfrac{e^{\\beta xy} e^{-e^{\\beta x}}}{y!}$$\n\n\\paragraph{likelihood function}\n$$L(\\beta|X,Y) = \\Pi_{i=1} p = \\Pi_{i=1} \\dfrac{e^{\\beta x_iy_i} e^{-e^{\\beta x}}}{y_i!}$$\n\n\\paragraph{The Maximum Likelihood Estimator} \n$$\\log L(\\beta | X,Y) = \\Sigma_{i=1} (\\beta x_iy_i - e^{\\beta x_i} - \\log(y_i!))$$\n\n\n\n\n\n\\subsection{Naive Bayes \\& Bayesian Network}\n\\subsubsection{Bayes Theorem}\n\\begin{itemize}\n\t\\item single evidence: $$Pr(h|e) = \\frac{Pr(h \\cap e)}{Pr(e)} = \\dfrac{Pr(e|h) \\cdot Pr(h)}{Pr(e)}$$\n\t\\item multiple evidence: \n\t\\begin{align*}\n\t\tPr(h|e_1, e_2, \\dots, e_k) &= \\dfrac{Pr(e_1 | h) \\cdot Pr(e_2 | h) \\dots Pr(e_k | h) \\cdot Pr(h)}{Pr(e_1, e_2, \\dots, e_k)} \\\\ \n\t\t&= \\frac{\\Pi_{i=1}^k Pr(e_i|h) \\cdot Pr(h)}{Pr(e_1,e_2, \\dots e_k)}\n\t\\end{align*}\n\\end{itemize}\n\n\t\n\\subsubsection{Pr(e)}\n\\begin{itemize}\n\t\\item If the prior probability $Pr(e_i)$ is \\textbf{known}: \n\t$$Pr(e_1, e_2, \\dots, e_k) = Pr(e_1)\\cdot Pr(e_2)\\dots Pr(e_k)$$\n\t\\item If the prior probability $Pr(e_i)$ is \\textbf{unknown}: law of total probability\n\t$$Pr(e_1, e_2, \\dots, e_k) = Pr(e_1, e_2, \\dots, e_k|h)\\cdot Pr(h) + Pr(e_1, e_2, \\dots, e_k | \\neg h) \\cdot Pr(\\neg h)$$\n\\end{itemize}\n\n\\subsubsection{Chain Rule}\nAccording to the \\textbf{directed acyclic graph}, derive the \\textbf{joint probability distribution} \n\n$$Pr(e_1, e_2, \\dots, e_k) = \\Pi_{i=1} Pr(e_i| e_{i-1}, \\dots, e_1) = \\Pi_{i=1} Pr(e_i| \\text{Parents}(e_i))$$\n\n\\subsubsection{Conditional Independence}\n\\paragraph{conditional independence between hypothesis and evidence} the hypothesis $h$ is only dependent on $e_1, e_2, e_3$, not on $e_4$ (redundant), then \n$$Pr(h | e_1, e_2, e_3, e_4) = Pr(h | e_1, e_2, e_3) $$\n\n\\paragraph{conditional independence between hypotheses}\n\nif two hypotheses are \\textbf{independent} from each other, then\n$$Pr(h_1, h_2 | e_1, e_2) = Pr(h_1|e_1,e_2) \\cdot Pr(h_2|e_1,e_2)$$\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Decision Tree}\n\\paragraph{Entropy} $\\in [0,1]$, measures how much \\textbf{additional information required} in \\textbf{bits}\n\t$$\\text{entropy}(p_1, \\dots, p_n) = - \\Sigma_{i=1} ^n p_i \\cdot \\log_{2} p_i$$\n\t\n\\paragraph{Information of Each Attribute Value}\n\t\n\t$$\\text{info}([c_1, \\dots, c_n]) = \\text{entropy}(\\frac{c_1}{C}, \\dots, \\frac{c_n}{C})$$ \n\t\n\\paragraph{Information of the Attribute} the \\textbf{weighted average} of the \\textbf{information needed} from each attribute value. \n\nSay an attribute has $m$ attribute values/branches,\n\n$$\\text{info}([c_1, \\dots, c_n]_1, \\dots, [c_1, \\dots, c_n]_m) = \\Sigma_{i=1}^m  \\frac{C_m}{N} \\cdot \\text{info}([c_1, \\dots, c_n])_m$$\n\n\\paragraph{Information Gain of the Attribute} \n\n$$\\text{Information\\_Gain(attribute)} = \\text{info(before split by attribute)} - \\text{info(after split by attribute)}$$ \n\n\\paragraph{Intrinsic Information of a Attribute} s: size of a leaf from each branch\n$$\\text{intrinsic\\_info}([s_1, \\dots, s_n]) = \\text{info}([s_1, \\dots, s_n])$$\n\n\\paragraph{Gain Ratio of a Attribute}\n\n$$\\text{Gain\\_Ratio(attribute)} = \\dfrac{\\text{Gain(attribute)}}{\\text{Intrinsic\\_Info(attribute)}}$$\n\n\n\\subsection{Evaluation}\n\n\\paragraph{Accuracy} $$\\text{Accuracy} = \\frac{TP + TN}{N}$$\n\\paragraph{Error Rate} $$\\text{Error Rate} = 1 - \\text{Accuracy} = \\frac{FP + FN}{N}$$\n\n\\paragraph{True Positive Rate / Recall / Hit Rate} $$\\text{True Positive Rate/Recall} = \\frac{TP}{TP + FN}$$\n\\paragraph{True Negative Rate / Specificity} $$\\text{True Negative Rate/Specificity} = \\frac{TN}{TN + FP}$$\n\\paragraph{False Positive Rate / False Alarm Rate} $$\\text{False Positive Rate/False Alarm Rate} = 1- \\text{Specificity} = \\frac{FP}{TN + FP}$$\n\n\\paragraph{Precision} $$\\text{Precision} = \\frac{TP}{TP + FP}$$\n\n\\subsection{Clustering: Expectation Maximization}\n\\paragraph{Expectation Step} calculate the probability for \\textbf{all instances} in \\textbf{each cluster}.\n$$Pr(A|x) = \\frac{Pr(x|A) \\cdot Pr(A)}{Pr(x)} ,\\quad Pr(x|A) = \\frac{1}{\\sqrt{2\\pi} \\cdot \\sigma_A} e^{-\\frac{(x - \\mu_A)^2}{2\\sigma_A^2}}$$\n$$Pr(B|x) = \\frac{Pr(x|B) \\cdot Pr(B)}{Pr(x)} ,\\quad Pr(x|B) = \\frac{1}{\\sqrt{2\\pi} \\cdot \\sigma_B} e^{-\\frac{(x - \\mu_B)^2}{2\\sigma_B^2}}$$\n\n\\paragraph{Maximization Step} calculate the weighted mean and weighted variance using \\textbf{all instances}. \n$$w_{iA} = Pr(A|x), \\quad  w_{iB} = Pr(B|x)$$\n$$\\mu_A = \\frac{w_{1A}x_1 + w_{2A}x_2 + \\dots + w_{nA}x_n}{w_{1A} + w_{2A} + \\dots + w_{nA}}$$\n$$\\sigma_A = \\sqrt{\\frac{w_{1A} (x_1 - \\mu_A)^2 + \\dots + w_{nA} (x_n - \\mu_A)^2}{w_{1A} + w_{2A} + \\dots + w_{nA}}}$$\nanalog to $\\mu_B$ and $\\sigma_B$\n\n$$Pr(A) = \\frac{\\Sigma w_A}{\\Sigma w_A + \\Sigma w_B}, \\quad Pr(B) = 1 - Pr(A)$$\n\n\\subsection{Principal Component Analysis \\& Restoring Original Data}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{dimreduce.png}\n\\end{figure}\n\\newpage\n\\subsection{Recommendation Systems: Association Rules}\n\\paragraph{Support of a Rule}\n\\item support of \\textbf{a rule}: the support of all item sets it contains. \n$$supp(A,B \\Rightarrow C,D) = supp(\\{A,B,C,D\\})$$\n\n\\paragraph{Confidence of a Rule}  the probability that X and Y coexist given that X exists.\n$$conf(R: X \\Rightarrow Y) = \\frac{supp(X \\cup Y)}{supp(X)}$$\n\n\\paragraph{Lift of a Rule} indicates \\textbf{by how much (ratio)} the \\textbf{confidence of a rule} surpasses the \\textbf{expected value}. \n$$Lift(R: X \\Rightarrow Y) = \\frac{conf(R)}{expConf(R)} = \\dfrac{\\frac{supp(X \\cup Y)}{supp(X)}}{supp(Y)} = \\frac{supp(X \\cup Y)}{supp(X)\\cdot supp(Y)}$$\n\\subsection{Recommendation Systems: Collaborative Filtering}\n\\paragraph{Weighted Correlation}\n$$w_{a,u} = s_{a,u} \\cdot c_{a,u}$$ \n$$c_{a,u} = \\frac{Cov(r_{a}, r_{u})}{\\sigma_{r_{a}} \\cdot \\sigma_{r_{u}}}$$\n$$Cov(r_{a}, r_{u}) = \\frac{1}{m-1}\\cdot \\Sigma (r_a - \\bar{r}_a) (r_u - \\bar{r}_u)$$\n\n\\paragraph{Rating Prediction}\n$$p_{a,i} = \\bar{r}_a + \\Sigma_{u = 1}^k \\dfrac{w_{a,u} \\cdot (r_{u,i} - \\bar{r}_u)}{\\Sigma_{u=1}^k |w_{a,u}|}$$\n\n\\subsection{Recommendation Systems: SVD}\n\\paragraph{Rating Prediction}\n$$r_{u,i} = \\bar{r}_u + U(user) \\cdot S \\cdot V^T(item)$$\n\n\n\\subsection{Neural Network}\n\\paragraph{Forward Pass}\n\\begin{align*}\n\tz^{[1]} &= W^{[1]}\\cdot a^{[0]} + b^{[1]} =  W^{[1]}\\cdot x + b^{[1]}\\\\\n\ta^{[1]} &= g^{[1]}(z^{[1]}) = \\sigma(z^{[1]}) \\\\\n\tz^{[2]} &= W^{[2]}\\cdot a^{[1]} + b^{[2]} \\\\\n\ta^{[2]} &= g^{[2]}(z^{[2]}) = \\sigma(z^{[2]})\n\\end{align*}\n\n\\paragraph{Loss Function} If we evaluate the model using \\textbf{cross-entropy loss}: the calculation for $y \\ln\\hat{y}$ is a dot product(element-wise multiplication).\n$$l(y,\\hat{y}) = - [y \\ln \\hat{y} + (1-y)\\ln(1 - \\hat{y})]$$\n\\paragraph{Empirical Risk}  \\textbf{average} the loss.\n$$\\mathcal{L}(y,\\hat{y}) = \\frac{1}{n} \\cdot \\Sigma l(y,\\hat{y})$$\n\n\\paragraph{Backpropagation}\n\nexample in updating layer 2:\n\\begin{align*}\n\tW^{[2]}_{t+1} &= W^{[2]}_t - \\alpha \\cdot dW =W^{[2]}_t - \\alpha \\cdot \\frac{\\partial L}{\\partial W^{[2]}} \\\\\n\tb^{[2]}_{t+1} &= b^{[2]}_t - \\alpha \\cdot db =b^{[2]}_t - \\alpha \\cdot \\frac{\\partial L}{\\partial b^{[2]}} \n\\end{align*}\n\n\t\n$$\\frac{\\partial L_n}{\\partial W} = \\frac{\\partial L_n}{\\partial a_{n}} \\cdot \\frac{\\partial a_{n}}{\\partial z_{n}} \\cdot \\frac{\\partial z_n}{\\partial W}$$\n\n\\begin{align*}\n\tL_n &= \\frac{1}{2} (y_{n} - g(w_{kl}a_{kn} + b_l))^2 = \\frac{1}{2} (y_n - a_{ln})^2, \\quad &\\frac{\\partial L_n}{\\partial a_{ln}} &= -(y_n - a_{ln})\\\\\n\ta_{ln} &= g(z_{ln}) , \\quad &\\frac{\\partial L_n}{\\partial z_{ln}} &= g'(z_{ln}) \\\\\n\tz_{ln} &= w_{kl}a_{kn} + b_l, \\quad &\\frac{\\partial L_n}{\\partial w_{ln}} &= a_{kn} \t\n\\end{align*}\n\nIf the activation is a sigmoid activation: $\\sigma(x) = \\frac{e^x}{1 + e^x}$, $\\sigma'(x) = \\sigma(x)(1 - \\sigma(x))$.\n$$dW^{[2]} = -(y- a^{[2]})\\cdot a^{[1]^{T}} = (a^{[2]} - y) \\cdot a^{[1]^{T}}$$\n\n\\paragraph{Gradient Descent}\n\n\t\\subparagraph{fixed step size}\n\t$$\\begin{bmatrix}\n\tx_n \\\\y_n\n\t\\end{bmatrix} = \\begin{bmatrix}\n\tx_{n-1} \\\\ y_{n-1}\n\t\\end{bmatrix} - \\alpha \\cdot \\nabla f(x_{n-1}, y_{n-1})$$\n\t\\subparagraph{dynamic step size}\n\t$$\\begin{bmatrix}\n\tx_n \\\\y_n\n\t\\end{bmatrix} = \\begin{bmatrix}\n\tx_{n-1} \\\\ y_{n-1}\n\t\\end{bmatrix} - \\alpha_{n} \\cdot \\nabla f(x_{n-1}, y_{n-1})$$\n\t\n\t\\subparagraph{Momentum}\n\t\\begin{align*}\n\t\td_n &= \\beta \\cdot d_{n-1} + \\alpha \\cdot\\nabla f(x_{n-1})\\\\\n\t\tx_n &= x_{n-1} - d_n\n\t\\end{align*}\n\n\n", "meta": {"hexsha": "b809ceadb525c4acb3dc8d4a881e14f1133d9d3f", "size": 14037, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Business Analytics/lectures/formulasheet.tex", "max_stars_repo_name": "YourPsychiatrist/TUM", "max_stars_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 225, "max_stars_repo_stars_event_min_datetime": "2019-10-02T10:49:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T22:25:38.000Z", "max_issues_repo_path": "Business Analytics/lectures/formulasheet.tex", "max_issues_repo_name": "YourPsychiatrist/TUM", "max_issues_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-02-16T12:22:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-31T19:35:57.000Z", "max_forks_repo_path": "Business Analytics/lectures/formulasheet.tex", "max_forks_repo_name": "YourPsychiatrist/TUM", "max_forks_repo_head_hexsha": "12e60881c225408d057b8637594c37fa54c3bcfa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 69, "max_forks_repo_forks_event_min_datetime": "2019-10-02T21:46:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T19:27:50.000Z", "avg_line_length": 43.865625, "max_line_length": 190, "alphanum_fraction": 0.6212153594, "num_tokens": 5648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.970687770944576, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.8344650897443253}}
{"text": "\\chapter{Various Ways of Sorting}\nThe objective of this challenge is sorting given algebraic (in this case,\n\\imc{double}) elements of an aray in incrasing order. Some elements may be of\nequal value.\n\n\\section{Quick Sort}\n\\imb[4][16]{../Algorithms/sorting.cpp}\n\\imb[87][89]{../Algorithms/sorting.cpp}\n\\imb[91][94]{../Algorithms/sorting.cpp}\n\\imb[120][121]{../Algorithms/sorting.cpp}\nQuick Sort is a recursive algorithm that does the following:\n\\begin{enumerate}\n\\item Choose a ``pivot\" element: \\texttt{Line 6}\n\\item Swap elements that are larger than the pivot with elements that are\n    smaller but on the righthand side of the chosen element: \\texttt{Lines 8:14}\n\\item Continue until all elements are sorted, then recursively proceed with the\n    left and right subarrays of the pivot: \\texttt{Lines 15, 16}\n\\end{enumerate}\nUsing two half-recursions results in the following time complexity analysis: \\[\nT(n)=2T\\left(\\frac{n}{2}\\right)+n=2^kT\\left(\\frac{n}{2^k}\\right)+kn=O(n\\log n)\\]\n\n\\section{Merge Sort}\n\\imb[18][37]{../Algorithms/sorting.cpp}\n\\imb[87][89]{../Algorithms/sorting.cpp}\n\\imb[96][99]{../Algorithms/sorting.cpp}\n\\imb[120][121]{../Algorithms/sorting.cpp}\nMerge Sort is also a recursive algorithm dependent on two half-recursions. Time\ncomplexity analysis goes: \\[ T(n)=2T\\left(\\frac{n}{2}\\right)+n=2^kT\\left(\\frac\n{n}{2^k}\\right)+kn=O(n\\log n) \\]\n\n\\section{Insertion Sort}\n\\imb[46][55]{../Algorithms/sorting.cpp}\n\\imb[87][89]{../Algorithms/sorting.cpp}\n\\imb[101][104]{../Algorithms/sorting.cpp}\n\\imb[120][121]{../Algorithms/sorting.cpp}\nInsertion Sort is a double-loop algorithm, therefore time complexity analysis is\nas follows: \\[ T(n)=\\sum_{i=1}^n\\sum_{j=1}^i\\epsilon=O(n^2) \\]\n\n\\section{Stooge Sort}\n\\imb[57][67]{../Algorithms/sorting.cpp}\n\\imb[87][89]{../Algorithms/sorting.cpp}\n\\imb[106][109]{../Algorithms/sorting.cpp}\n\\imb[120][121]{../Algorithms/sorting.cpp}\nStooge Sort is a recursive algorithm of three subarrays. The time complexity is:\n\\[ T(n)=3T\\left(\\frac{3}{2}n\\right)+1,~\\therefore T(n)\\approx\nO\\left(n^{2.7}\\right) \\]\n\n\\section{Heap Sort}\n\\imb[69][79]{../Algorithms/sorting.cpp}\n\\imb[87][89]{../Algorithms/sorting.cpp}\n\\imb[111][118]{../Algorithms/sorting.cpp}\n\\imb[120][121]{../Algorithms/sorting.cpp}\nHeap sort is a loop-and-recursive algorithm of time complexy analysis \\[ T(n)=\nO(n\\log n) \\]\n", "meta": {"hexsha": "870a301d6500d6dd39dc1332a58e523e0b5af25c", "size": 2330, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/03_sorting.tex", "max_stars_repo_name": "thekpaul/Programming-Methodology", "max_stars_repo_head_hexsha": "949e798206f79d26f5f69bda8ab5a546369a8d2b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-06-10T19:00:48.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-11T04:09:31.000Z", "max_issues_repo_path": "Algorithms/03_sorting.tex", "max_issues_repo_name": "thekpaul/Programming-Methodology", "max_issues_repo_head_hexsha": "949e798206f79d26f5f69bda8ab5a546369a8d2b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-06-11T04:10:44.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-11T08:43:32.000Z", "max_forks_repo_path": "Algorithms/03_sorting.tex", "max_forks_repo_name": "thekpaul/Programming-Methodology", "max_forks_repo_head_hexsha": "949e798206f79d26f5f69bda8ab5a546369a8d2b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-06-10T19:00:51.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-10T19:00:51.000Z", "avg_line_length": 42.3636363636, "max_line_length": 80, "alphanum_fraction": 0.717167382, "num_tokens": 738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954105, "lm_q2_score": 0.8902942261220292, "lm_q1q2_score": 0.8343933531225618}}
{"text": "\n\\subsection{Spearman rank correlation}\n\nFor each of \\(2\\) variables we create a ranking of them.\n\nFrom \\(X\\) and \\(Y\\) we then have \\(R_X\\) and \\(R_Y\\).\n\nWe then calculate the Pearson correlation coefficient between the rankings.\n\n\\(r_S=\\dfrac{cov(R_X, R_Y)}{\\sigma_{R_X}\\sigma_{R_Y}}\\)\n\n", "meta": {"hexsha": "eb2afd4ce022730d93356f4dc013194aaff93e05", "size": 289, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/summaryMultiple/02-02-spearman.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/summaryMultiple/02-02-spearman.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/summaryMultiple/02-02-spearman.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0833333333, "max_line_length": 75, "alphanum_fraction": 0.6989619377, "num_tokens": 83, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9603611597645271, "lm_q2_score": 0.8688267813328976, "lm_q1q2_score": 0.8343874953553427}}
{"text": "\r\n\\chapter{Estimation}\r\n\r\nHere a linear discrete-time model is assumed with scalar measurements, to avoid the tedious matrix calculations that are ultimately a distraction to the derivation.\r\n\r\n\\begin{equation}\r\nx_{k+1} = a x_k + w_k\r\n\\end{equation}\r\n\\begin{equation}\r\ny_k = x_k + v_k\r\n\\end{equation}\r\n\\begin{equation}\r\nw_k \\sim \\gauss{0}{q},\r\nv_k \\sim \\gauss{0}{r}\r\n\\end{equation}\r\n\r\n\\section{Equivalence of the batch and recursive forms of the Kalman filter}\r\n\r\nFrom Ref. \\cite{sorenson1970}, the batch linear estimate for $x_k$ is optimal with respect to the following cost function:\r\n\r\n\\begin{equation}\r\nJ = \\frac{1}{2} \\quadr{(\\vest{x}_0-\\vec{\\mu})}{P_0^{-1}} + \r\n\\frac{1}{2} \\sum_{k=1}^N \\quadr{(\\veas{y}_k - H_k \\vest{x}_k)}{R^{-1}} + \r\n\\frac{1}{2} \\sum_{k=1}^N \\quadr{(\\vest{x}_k - \\Phi_{k-1} \\vest{x}_{k-1})}{Q^{-1}}\r\n\\end{equation}\r\n\r\nFor the scalar problem with $N = 2$, the first-order necessary conditions for optimality with respect to $\\vest{x}_0,\\vest{x}_1,\\vest{x}_2$ yield the following linear expression:\r\n\r\n\\begin{equation}\r\n\\begin{bmatrix}\r\n\\inv{p_0}+\\frac{a^2}{q} & -\\frac{a}{q} & 0\\\\\r\n-\\frac{a}{q} & \\inv{r} + \\inv{q} + \\frac{a^2}{q} & -\\frac{a}{q} \\\\\r\n0 & -\\frac{a}{q} & \\inv{q}+\\inv{r}\r\n\\end{bmatrix}\r\n\\begin{bmatrix}\r\n\\est{x}_0 \\\\ \\est{x}_1 \\\\ \\est{x}_2\r\n\\end{bmatrix} = \\begin{bmatrix}\r\n\\frac{\\mu}{p_0} \\\\ \\frac{\\meas{y}_1}{r} \\\\ \\frac{\\meas{y}_2}{r}\r\n\\end{bmatrix}\r\n\\end{equation}\r\n\r\nSolving for $\\est{x}_2$ yields the following expression:\r\n\r\n\\begin{equation}\r\n\\est{x}_2 = \\inv{p_0a^4r + a^2qr + p_0a^2q + p_0a^2r + q^2 + 2qr + r^2} \\begin{bmatrix}\r\na^2q^2 & \r\np_0ra^3 + qra & \r\nqr + q^2 + a^2p_0q + a^4p_0r + a^2qr\r\n\\end{bmatrix}\\begin{bmatrix}\r\n\\mu \\\\ \\meas{y}_1 \\\\ \\meas{y}_2\r\n\\end{bmatrix}\r\n\\label{eq:batchkf}\r\n\\end{equation}\r\n\r\nBut this is exactly the expression obtained from recursion of the standard Kalman filter:\r\n\r\n\\begin{equation}\r\n\\est{x}_0 = \\mu\r\n\\end{equation}\r\n\\begin{equation}\r\np_1^{-} = a^2 p_0 + q\r\n\\end{equation}\r\n\\begin{equation}\r\nk_1 = \\frac{p_1^{-}}{r+p_1^{-}}\r\n\\end{equation}\r\n\\begin{equation}\r\n\\est{x}_1 = a\\est{x}_0 + k_1(\\meas{y}_1-a\\est{x}_0)\r\n\\end{equation}\r\n\\begin{equation}\r\np_1^{+} = (1-k_1)p_1^{-}\r\n\\end{equation}\r\n\\begin{equation}\r\np_2^{-} = a^2 p_1^{+} + q\r\n\\end{equation}\r\n\\begin{equation}\r\nk_2 = \\frac{p_2^{-}}{r+p_2^{-}}\r\n\\end{equation}\r\n\\begin{equation}\r\n\\est{x}_2 = a\\est{x}_1 + k_2(\\meas{y}_2 - a\\est{x}_1)\r\n\\label{eq:x2_lkf}\r\n\\end{equation}\r\n\r\nThe algebra required to prove the equivalence of Eqs. \\ref{eq:batchkf} and \\ref{eq:x2_lkf} is tedious even for the scalar case.\r\n\r\n\\section{MATLAB code for showing the equivalence of the first two recursions}\r\n\r\nThe following code will compute the first two recursions of the sequential filter and compute the symbolic difference between the sequential value and the batch value for $N = 1$ and $N = 2$.\r\nThe code can readily be extended for higher recursions if readers think that is necessary.\r\n\r\n\\begin{verbatim}\r\nclear variables;\r\nclose all;\r\n\r\nsyms mu p0 q r a y1 y2 real;\r\n\r\n%% solution for the recursive KF\r\nx0s = mu;\r\n% propagated covariance at t1-\r\np1s = a^2*p0 + q;\r\nk1 = p1s/(r+p1s);\r\nx1s = a*x0s + k1*(y1-a*x0s);\r\n% propagated covariance at t1+\r\np1sp = (1-k1)*p1s;\r\n% propagated covariance at t2-\r\np2s = a^2*p1sp + q;\r\nk2 = p2s/(r+p2s);\r\nx2s = a*x1s + k2*(y2-a*x1s);\r\n\r\n%% solution for the batch KF with 1 measurement\r\nM = [1/p0+a^2/q -a/q;\r\n-a/q 1/r+1/q];\r\nb = [mu/p0;\r\ny1/r];\r\nxsol1 = M\\b;\r\n\r\n% print the error between the recursive and batch estimate\r\nsimplify(xsol1(2) - x1s)\r\n\r\n%% solution for the batch KF with 2 measurements\r\nM = [1/p0 + a^2/q -a/q 0;\r\n-a/q 1/r+1/q+a^2/q -a/q;\r\n0 -a/q 1/r+1/q];\r\nb = [mu/p0;y1/r;y2/r];\r\nxsol2 = M\\b;\r\n\r\n% print the error between the recursive and batch estimate\r\nsimplify(xsol2(3) - x2s)\r\n\\end{verbatim}", "meta": {"hexsha": "9ae2f450b0a8b130740cef1c2bc23f8427943eac", "size": 3771, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "batch-recursive-equivalence.tex", "max_stars_repo_name": "fatadama/study-summaries", "max_stars_repo_head_hexsha": "38649d903420549d75005ca39860f164dab106ee", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "batch-recursive-equivalence.tex", "max_issues_repo_name": "fatadama/study-summaries", "max_issues_repo_head_hexsha": "38649d903420549d75005ca39860f164dab106ee", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "batch-recursive-equivalence.tex", "max_forks_repo_name": "fatadama/study-summaries", "max_forks_repo_head_hexsha": "38649d903420549d75005ca39860f164dab106ee", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4609375, "max_line_length": 192, "alphanum_fraction": 0.6449217714, "num_tokens": 1444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.8791467643431002, "lm_q1q2_score": 0.8342375388934576}}
{"text": "\\chapter{Resultant and Discriminant of a Polynomial}\n\\label{chap:appB}\nWe begin with some useful definitions regarding polynomials. The reason why we refer resultant is that we can calculate the discriminant of the polynomial through this tool, especially when the degree of polynomial is large. First of all, we give a definition of resultant\\citep{healy2002resultants}:\n\\begin{definition}\nLet $R$ be an integral domain, given two polynomials $f(x),g(x)\\in R[x]$ with roots $\\alpha_1,\\dots,\\alpha_m$ and $\\beta_1,\\dots,\\beta_n$ respectively, then the resultant $\\operatorname{Res}(f,g)$ of $f,g$ is defined to be $$\\operatorname{Res}(f,g)=l(f)^nl(g)^m\\prod_{i,j}(\\alpha_i-\\beta_j)$$ which is equivalent to both $$\\operatorname{Res}(f,g)=l(f)^n\\prod_{i}^m g(\\alpha_i)$$ and $$\\operatorname{Res}(f,g)=(-1)^{n m}l(g)^m\\prod_{i}^n f(\\beta_i)$$\n\\end{definition}\nFrom this definition, on can easily see that $f,g$ have a common root in some if and only if $\\operatorname{Res}(f,g)=0$.\nAn important proposition shows the relationship of this definition to the \\textbf{Sylvester's matrix} (Some books take that as definition): Let $S$ be the Sylvester's matrix of polynomials $f(x)$ and $g(x)$, then $\\operatorname{Res}(f,g)=\\det(S)$.\n\nAlso for convenience, I choose a definition of normalized discriminant \\citep{janson2007resultant} of polynomial as follows in this paper.\n\n\\begin{definition}\nLet $f$ be a polynomial of degree $n\\geq1$ with coefficients in a field $F$. Let $F_1$ be an extension of $F$ where $f$ splits, and let $r_1,\\dots,r_n$ be the roots of $f$ in $F_1$. Then the discriminant of $f$ is $$\\operatorname{Disc}(f):=\\prod_{1\\leq i<j\\leq n}(r_i-r_j)^2$$\n\\end{definition}\n\nNote further that $\\operatorname{Disc}(cf)=\\operatorname{Disc}(f)$ for any nonzero constant. The following theorem give the relation between the discriminant and resultant.\n\n\\begin{proposition}\\label{prop:disctri}\nLet $f=a_nx^n+\\cdots+a_0$ be polynomial of degree $n\\geq1$ with coefficients in a field $F$. The the discriminant of $f$ is given by \n$$\\operatorname{Disc}(f)=(-1)^{n(n-1)/2}a^{-(2n-1)}_n \\operatorname{Res}(f,f')$$\n\\end{proposition}\n\n\\begin{example}\\label{for:nxpxq}\nLet $f(x)=x^n+px+q$ for $n\\geq2$, then $f'(x)=nx^{n-1}+p$, then from the Proposition \\ref{prop:disctri}, we have $$\\operatorname{Disc}(f)=(-1)^{(n-1)(n-2)/2}(n-1)^{n-1p^n}+(-1)^{n(n-1/2)}n^nq^{n-1}$$\n\\end{example}\n\n", "meta": {"hexsha": "28a4bbcbc5d51a98ae70988d746964f856d66b70", "size": 2379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/chap-appB.tex", "max_stars_repo_name": "daidahao/sustcthesis", "max_stars_repo_head_hexsha": "af536c6559c5a8a3c1315438b99d166153665187", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2019-03-17T08:46:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-12T02:50:26.000Z", "max_issues_repo_path": "chapter/chap-appB.tex", "max_issues_repo_name": "daidahao/sustcthesis", "max_issues_repo_head_hexsha": "af536c6559c5a8a3c1315438b99d166153665187", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter/chap-appB.tex", "max_forks_repo_name": "daidahao/sustcthesis", "max_forks_repo_head_hexsha": "af536c6559c5a8a3c1315438b99d166153665187", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-06-17T06:55:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-17T01:21:27.000Z", "avg_line_length": 88.1111111111, "max_line_length": 449, "alphanum_fraction": 0.7171080286, "num_tokens": 777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896737173119, "lm_q2_score": 0.9059898146721821, "lm_q1q2_score": 0.8342260658432065}}
{"text": "\n\\subsection{Sample mean}\n\nWe previously defined the population mean is defined as \\(\\mu=E[X]\\).\n\nThe sample mean is defined as \\(\\bar x = \\dfrac{1}{n}\\sum_i x_i\\).\n\n\\subsubsection{Centred mean}\n\nWe can subtract the mean from each entry in the sample. This will leave a new mean of \\(0\\). This is convenient for many calculations.\n\n", "meta": {"hexsha": "3693ff7bd4990ae88ca824e83f8155167f224201", "size": 332, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/summary/02-01-mean.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/summary/02-01-mean.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/summary/02-01-mean.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6666666667, "max_line_length": 134, "alphanum_fraction": 0.7259036145, "num_tokens": 86, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9702399051935107, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.8340800775372452}}
{"text": "\\section{Built-in functions}\n\n\\section*{abs}\nabs($x$) returns the absolute value or vector length of $x$.\nThe mag function should be used for complex $x$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nP = (x,y)\nabs(P)\n\\end{Verbatim}\n\n$\\displaystyle (x^2+y^2)^{1/2}$\n\n\\section*{adj}\nadj($m$) returns the adjunct of matrix $m$.\n\n\\section*{and}\nand($a,b,\\ldots$) returns the logical ``and'' of predicate expressions.\n\n\\section*{arccos}\narccos($x$) returns the inverse cosine of $x$.\n\n\\section*{arccosh}\narccosh($x$) returns the inverse hyperbolic cosine of $x$.\n\n\\section*{arcsin}\narcsin($x$) returns the inverse sine of $x$.\n\n\\section*{arcsinh}\narcsinh($x$) returns the inverse hyperbolic sine of $x$.\n\n\\section*{arctan}\narcttan($x$) returns the inverse tangent of $x$.\n\n\\section*{arctanh}\narctanh($x$) returns the inverse hyperbolic tangent of $x$.\n\n\\section*{arg}\narg($z$) returns the angle of complex $z$.\n\n\\section*{ceiling}\nceiling($x$) returns the smallest integer not less than $x$.\n\n\\section*{check}\ncheck($x$) In a script, if the predicate $x$ is true then continue, else stop.\n\n\\section*{choose}\nchoose($n,k$) returns $\\displaystyle\\binom{n}{k}$\n\n\\section*{circexp}\ncircexp($x$) returns expression $x$ with circular functions converted\nto exponential forms.\nSometimes this will simplify an expression.\n\n\\section*{coeff}\ncoeff($p,x,n$) returns the coefficient of $x^n$ in polynomial $p$.\n\n\\section*{cofactor}\ncofactor($m,i,j$) returns of the cofactor of matrix $m$ with respect to row $i$ and column $j$.\n\n\\section*{conj}\nconj($z$) returns the complex conjugate of $z$.\n\n\\section*{contract}\n\\index{trace}\ncontract($a,i,j$) returns tensor $a$ summed over indices $i$ and $j$.\nIf $i$ and $j$ are omitted then indices 1 and 2 are used.\ncontract($m$) is equivalent to the trace of matrix $m$.\n\n\\section*{cos}\ncos($x$) returns the cosine of $x$.\n%If $x$ is a floating point number then $\\cos(x)$ is evaluated numerically.\n\n\\section*{cosh}\ncosh($x$) returns the hyperbolic cosine of $x$.\n\n\\section*{cross}\ncross($u,v$) returns the cross product of vectors $u$ and $v$.\n\n\\section*{curl}\ncurl($u$) returns the curl of vector $u$.\n\n\\section*{d}\nd($f,x$) returns the derivative of $f$ with respect to $x$.\n\n\\section*{defint}\ndefint($f,x,a,b,\\ldots$)\nreturns the definite integral of $f$ with respect to $x$ evaluated from $a$ to $b$.\nThe argument list can be extended for multiple integrals.\nFor example, $d(f,x,a,b,y,c,d)$.\n\n\\section*{deg}\ndeg($p,x$) returns the degree of polynomial $p$ in $x$.\n\n\\section*{denominator}\ndenominator($x$) returns the denominator of expression $x$.\n\n\\section*{det}\ndet($m$) returns the determinant of matrix $m$.\n\n\\section*{do}\ndo($a,b,\\ldots$) evaluates the argument list from left to right.\nReturns the result of the last argument.\n\n\\section*{dot}\ndot($a,b,\\ldots$) returns the dot product of tensors.\n\n\\section*{draw}\ndraw($f,x$) draws the function $f$ with respect to $x$.\n\n\\section*{erf}\nerf($x$) returns the error function of $x$.\n\n\\section*{erfc}\nerf($x$) returns the complementary error function of $x$.\n\n\\section*{eval}\neval($f,x,n$) returns $f$ evaluated at $x=n$.\n\n\\section*{exp}\nexp($x$) returns $e^x$.\n\n\\section*{expand}\nexpand($r,x$) returns the partial fraction expansion of the ratio of\npolynomials $r$ in $x$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nexpand(1/(x^3+x^2),x)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{1}{x^2}-\\frac{1}{x}+\\frac{1}{x+1}$\n\n\\section*{expcos}\nexpcos($x$) returns the cosine of $x$ in exponential form.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nexpcos(x)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{1}{2}\\exp(-ix)+\\frac{1}{2}\\exp(ix)$\n\n\\section*{expsin}\nexpsin($x$) returns the sine of $x$ in exponential form.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nexpsin(x)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{1}{2}i\\exp(-ix)-\\frac{1}{2}i\\exp(ix)$\n\n\\section*{factor}\nfactor($n$) factors the integer $n$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nfactor(12345)\n\\end{Verbatim}\n\n$\\displaystyle 3\\times 5\\times 823$\n\n$factor(p,x)$ factors polynomial $p$ in $x$.\nThe last argument can be omitted for polynomials in $x$.\nThe argument list can be extended for multivariate polynomials.\nFor example, factor($p,x,y$) factors $p$ over $x$ and then over $y$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nfactor(125*x^3-1)\n\\end{Verbatim}\n\n$\\displaystyle (5x-1)(25x^2+5x+1)$\n\n\\section*{factorial}\nExample:\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n10!\n\\end{Verbatim}\n\n$\\displaystyle 3628800$\n\n\\section*{filter}\nfilter($f,a,b,\\ldots$) returns $f$ with terms involving $a$, $b$, etc. removed.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\n1/a+1/b+1/c\n\\end{Verbatim}\n\n$\\displaystyle \\frac{1}{a}+\\frac{1}{b}+\\frac{1}{c}$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nfilter(last,a)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{1}{b}+\\frac{1}{c}$\n\n\\section*{float}\nfloat($x$) converts $x$ to a floating point value.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nsum(n,0,20,(-1/2)^n)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{699051}{1048576}$\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nfloat(last)\n\\end{Verbatim}\n\n$\\displaystyle 0.666667$\n\n\\section*{floor}\nfloor($x$) returns the largest integer not greater than $x$.\n\n\\section*{for}\nfor($i,j,k,a,b,\\ldots$) For $i$ equals $j$ through $k$ evaluate $a$, $b$, etc.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nx = 0\ny = 2\nfor(k,1,9,x=sqrt(2+x),y=2*y/x)\nfloat(y)\n\\end{Verbatim}\n\n$\\displaystyle 3.14159$\n\n\\section*{gcd}\ngcd($a,b,\\ldots$) returns the greatest common divisor.\n\n\\section*{hermite}\nhermite($x,n$) returns the $n$th Hermite polynomial in $x$.\n\n\\section*{hilbert}\nhilbert($n$) returns a Hilbert matrix of order $n$.\n\n\\section*{imag}\nimag($z$) returns the imaginary part of complex $z$.\n\n\\section*{inner}\ninner($a,b,\\ldots$) returns the inner product of tensors.\nSame as the dot product.\n\n\\section*{integral}\nintegral($f,x$) returns the integral of $f$ with respect to $x$.\n\n\\section*{inv}\ninv($m$) returns the inverse of matrix $m$.\n\n\\section*{isprime}\nisprime($n$) returns 1 if $n$ is prime, zero otherwise.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nisprime(2^53-111)\n\\end{Verbatim}\n\n$\\displaystyle 1$\n\n\\section*{laguerre}\nlaguerre($x,n,a$) returns the $n$th Laguerre polynomial in $x$.\nIf $a$ is omitted then $a=0$ is used.\n\n\\section*{lcm}\nlcm($a,b,\\ldots$) returns the least common multiple.\n\n\\section*{leading}\nleading($p,x$) returns the leading coefficient of polynomial $p$ in $x$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nleading(5x^2+x+1,x)\n\\end{Verbatim}\n\n$\\displaystyle 5$\n\n\\section*{legendre}\nlegendre($x,n,m$) returns the $n$th Legendre polynomial in $x$.\nIf $m$ is omitted then $m=0$ is used.\n\n\\section*{log}\nlog($x$) returns the natural logarithm of $x$.\n\n\\section*{mag}\nmag($z$) returns the magnitude of complex $z$.\n\n\\section*{mod}\nmod($a,b$) returns the remainder of $a$ divided by $b$.\n\n\\section*{not}\nnot($x$) negates the result of predicate expression $x$.\n\n\\section*{nroots}\nnroots($p,x$) returns all of the roots, both real and complex, of\npolynomial $p$ in $x$.\nThe roots are computed numerically.\nThe coefficients of $p$ can be real or complex.\n\n\\section*{numerator}\nnumerator($x$) returns the numerator of expression $x$.\n%\\begin{itemize}\n%\\item[$\\scriptstyle1$]{\\tt numerator(a/b+b/a)}\n%\\item[$\\scriptstyle2$]\\hspace{50pt} $a^2+b^2$\n%\\end{itemize}\n\n\\section*{or}\nor($a,b,\\ldots$) returns the logical ``or'' of predicate expressions.\n\n\\section*{outer}\nouter($a,b,\\ldots$) returns the outer product of tensors.\n\nExample 1.\n\\[\n\\begin{pmatrix}\n1\\\\\n0\n\\end{pmatrix}\n\\otimes\n\\begin{pmatrix}\n1\\\\\n0\n\\end{pmatrix}\n=\\begin{pmatrix}\n1 & 0\\\\\n0 & 0\n\\end{pmatrix}\n\\]\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nouter((1,0),(1,0))\n\\end{Verbatim}\n\n$\\displaystyle\n\\begin{pmatrix}\n1 & 0\\\\\n0 & 0\n\\end{pmatrix}\n$\n\n\\bigskip\nExample 2. From the identity\n\\[\n|A\\rangle=\\sum_i|i\\rangle\\langle i|A\\rangle\n\\]\nit follows that\n\\[\n\\sum_i|i\\rangle\\langle i|=\\bf I\n\\]\nFor a two-state system with basis vectors\n\\[\n|1\\rangle=\\begin{pmatrix}1/\\sqrt2\\\\i/\\sqrt2\\end{pmatrix},\n\\hbox{\\quad and\\quad}\n|2\\rangle=\\begin{pmatrix}1/\\sqrt2\\\\-i/\\sqrt2\\end{pmatrix}\n\\]\nthe following code computes $\\sum|i\\rangle\\langle i|$.\n\\begin{Verbatim}[formatcom=\\color{blue}]\nX1 = (1/sqrt(2),i/sqrt(2))\nX2 = (1/sqrt(2),-i/sqrt(2))\nouter(conj(X1),X1) + outer(conj(X2),X2)\n\\end{Verbatim}\n$\\displaystyle\n\\begin{pmatrix}\n1 & 0\\\\\n0 & 1\n\\end{pmatrix}\n$\n\n\\bigskip\nThe following code uses a different approach.\nFirst, tensor $T$ is computed such that\n\\[\nT=\\begin{pmatrix}\n|1\\rangle\\langle1| & |1\\rangle\\langle2| \\\\\n|2\\rangle\\langle1| & |2\\rangle\\langle2|\n\\end{pmatrix}\n\\]\nThen contraction is used to sum the diagonal elements.\n\\begin{Verbatim}[formatcom=\\color{blue}]\nX1 = (1/sqrt(2),i/sqrt(2))\nX2 = (1/sqrt(2),-i/sqrt(2))\nX = (X1,X2)\nT = outer(conj(X),X)\nT = transpose(T,2,3)\ncontract(T)\n\\end{Verbatim}\n$\\displaystyle\n\\begin{pmatrix}\n1 & 0\\\\\n0 & 1\n\\end{pmatrix}\n$\n\\begin{Verbatim}[formatcom=\\color{blue}]\n-- verify components of T\nT[1,1] == outer(conj(X1),X1)\nT[1,2] == outer(conj(X1),X2)\nT[2,1] == outer(conj(X2),X1)\nT[2,2] == outer(conj(X2),X2)\n\\end{Verbatim}\n$1$\\\\\n$1$\\\\\n$1$\\\\\n$1$\n\n\\section*{polar}\npolar($z$) converts complex $z$ to polar form.\n\n\\section*{prime}\nprime($n$) returns the $n$th prime number, $1\\le n\\le10{,}000$.\n\n\\section*{print}\nprint($a,b,\\ldots$) evaluates expressions and prints the results..\nUseful for printing from inside a ``for'' loop.\n\n\\section*{product}\nproduct($i,j,k,f$) returns $\\displaystyle\\prod_{i=j}^k f$\n\n\\section*{quote}\nquote($x$) returns expression $x$ unevaluated.\n\n\\section*{quotient}\nquotient($p,q,x$) returns the quotient of polynomials in $x$.\n\n\\section*{rank}\nrank($a$) returns the number of indices that tensor $a$ has.\nA scalar has no indices so its rank is zero.\n\n\\section*{rationalize}\nrationalize($x$) puts everything over a common denominator.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nrationalize(a/b+b/a)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{a^2+b^2}{ab}$\n\n\\section*{real}\nreal($z$) returns the real part of complex $z$.\n\n\\section*{rect}\nrect($z$) returns complex $z$ in rectangular form.\n\n\\section*{roots}\nroots($p,x$) returns the values of $x$ such that the polynomial $p(x)=0$.\nThe polynomial should be factorable over integers.\n\n\\section*{simplify}\nsimplify($x$) returns $x$ in a simpler form.\n\n\\section*{sin}\nsin($x$) returns the sine of $x$.\n\n\\section*{sinh}\nsinh($x$) returns the hyperbolic sine of $x$.\n\n\\section*{sqrt}\nsqrt($x$) returns the square root of $x$.\n\n\\section*{stop}\nIn a script, it does what it says.\n\n\\section*{subst}\nsubst($a,b,c$) substitutes $a$ for $b$ in $c$ and returns the result.\n\n\\section*{sum}\nsum($i,j,k,f$) returns $\\displaystyle\\sum_{i=j}^k f$\n\n\\section*{tan}\ntan($x$) returns the tangent of $x$.\n\n\\section*{tanh}\ntanh($x$) returns the hyperbolic tangent of $x$.\n\n\\section*{taylor}\ntaylor($f,x,n,a$) returns the Taylor expansion of $f$ of $x$ at $a$.\nThe argument $n$ is the degree of the expansion.\nIf $a$ is omitted then $a=0$ is used.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\ntaylor(1/cos(x),x,4)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{5}{24}x^4+\\frac{1}{2}x^2+1$\n\n\\section*{test}\ntest($a,b,c,d,\\ldots$)\nIf $a$ is true then $b$ is returned else if $c$ is true then $d$ is returned, etc.\nIf the number of arguments is odd then the last argument is returned when all else fails.\n\n\\section*{transpose}\ntranspose($a,i,j$) returns the transpose of tensor $a$ with respect to indices $i$ and $j$.\nIf $i$ and $j$ are omitted then 1 and 2 are used.\nHence a matrix can be transposed with a single argument.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nA = ((a,b),(c,d))\ntranspose(A)\n\\end{Verbatim}\n\n$\\displaystyle \\begin{bmatrix}a & c\\\\ b & d\\end{bmatrix}$\n\n\\section*{unit}\nunit($n$) returns an $n\\times n$ identity matrix.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nunit(2)\n\\end{Verbatim}\n\n$\\displaystyle \\begin{bmatrix}1&0\\\\0&1\\end{bmatrix}$\n\n\\section*{zero}\nzero($i,j,\\ldots$) returns a null tensor with dimensions $i$, $j$, etc.\nUseful for creating a tensor and then setting the component values.\n", "meta": {"hexsha": "3bfeaaac6d04e763cf13192a2b4aa60bb73d7c3b", "size": 12144, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/list-of-functions.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/list-of-functions.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/list-of-functions.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.905511811, "max_line_length": 95, "alphanum_fraction": 0.6947463768, "num_tokens": 4174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109770159682, "lm_q2_score": 0.877476793890012, "lm_q1q2_score": 0.8339635769898457}}
{"text": "\n\\subsection{Hermitian (self-adjoint) matrices}\n\nA matrix where \\(M=M^*\\)\n\nFor matrices over the real numbers, these are the same as symmetric matrices.\n\n\\subsubsection{Sesqulinear forms on Hermitian matrices}\n\n\\(\\phi (u,v)=u^*Mv\\)\n\n\\((u^*Mv)^*=v^*M^*u=v^*Mu\\)\n\n\\(\\phi (u,v)=\\overline {\\phi (v,u)}\\)\n\n\\subsubsection{The forms on the same vector are always real}\n\n\\((v^*Mv)^*=v^*M^*v=v^*Mv\\)\n\nSo we have:\n\n\\((v^*Mv)^*=v^*Mv\\)\n\nWhich is only satisfied for reals.\n\n\\subsubsection{If \\(A\\) and \\(B\\) are Hermitian}\n\nIf \\(A\\) and \\(B\\) are Hermitian, \\(AB\\) is Hermitian if and only if \\(AB\\) commutes.\n\n\\((AB)^*=B^*A^*=BA\\)\n\nIf it commutes then\n\n\\((AB)^*=AB\\)\n\n\\subsubsection{Real eigenvalues}\n\nHermitian matrices have real eigenvalues.\n\n\\(Hv=\\lambda v\\)\n\n\\(v^*Hv=\\lambda v^*v\\)\n\n\\(v^*Hv=\\lambda \\)\n\n\\subsubsection{Skew-Hermitian matrices}\n\nThese are also known as anti-Hermitian matrices.\n\n\\(M^*=-M\\)\n\n\\subsubsection{If eigenvalues are different, eigenvectors are orthogonal}\n\n\n", "meta": {"hexsha": "7aa2e71d7dd9daf0e9f47f925c2e690951a14c4d", "size": 975, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/04-02-hermitian.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/forms/04-02-hermitian.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/forms/04-02-hermitian.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.7272727273, "max_line_length": 85, "alphanum_fraction": 0.6574358974, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138559, "lm_q2_score": 0.8840392832736084, "lm_q1q2_score": 0.8339563095845454}}
{"text": "\\section{Linear Algebra}\n\n\\subsection{Plane equation}\nAssume that we know point, which belongs to plane $P_0=(x_0,y_0,z_0)$ and \nwe have a normal vector to the plane $\\vec{n}=(a,b,c)$. Now assume that $P=(x,y,z)$\nis any point in the plane. Define position vectors $\\vec{r_0}$ and $\\vec{r}$\nfrom our coord. system to points $P_0$ and $P$ on the plane respectively. Vector $\\vec{r_0} - \\vec{r}$\nlies in our plane. Then $\\vec{n} \\cdot (\\vec{r_0} - \\vec{r}) = 0$ is our plane equation.\n\n\t\n\n\\subsection{Distance}\n\nConsider a line  $L$  in  $\\mathbb{R}^2$  given by the equation $L:\\theta \\cdot x + \\theta_0=$ where $\\theta$ is a vector normal to the line $L$. Let the point $P$ be the endpoint of a vector $x_0$(so the coordinates of $P$  equal the components of $x_0$).\\\\\n\nThe shortest distance $d$ between the line $L$ and the point $P$ is:\n\\begin{align*}\nd= \\displaystyle \\frac{\\mid \\theta \\cdot x_0+ \\theta _0\\mid }{\\mid \\mid \\theta \\mid \\mid }\n\\end{align*}", "meta": {"hexsha": "c7bb9e131cd91e60c4ff0cfa976c3865c662ae61", "size": 956, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/linear_algebra.tex", "max_stars_repo_name": "sharov-am/MITx_capstone_2", "max_stars_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "content/linear_algebra.tex", "max_issues_repo_name": "sharov-am/MITx_capstone_2", "max_issues_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content/linear_algebra.tex", "max_forks_repo_name": "sharov-am/MITx_capstone_2", "max_forks_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.3157894737, "max_line_length": 258, "alphanum_fraction": 0.6788702929, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813526452772, "lm_q2_score": 0.8723473846343394, "lm_q1q2_score": 0.8339478327393056}}
{"text": "%!TEX root = TTK4150-Summary.tex\n\\section{Math}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Metric norms}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{General $p$-norm}\n\\begin{equation}\n\t\\norm{x}_p\n\t=\n\t\\left(\n\t\t\\sum_{i=1}^{n} \\abs{x_i}^p\n\t\\right)\n\t^{1/p}\n\\end{equation}\n\n\\paragraph{Taxicab norm ($p=1$)}\n\\begin{equation}\n\t\\norm{x}_1\n\t=\n\t\\sum_{i=1}^{n} \\abs{x_i}\n\\end{equation}\n\n\\paragraph{Euclidean norm ($p=2$)}\n\\begin{equation}\n\t\\norm{x}_2\n\t=\n\t\\sqrt{x_1^2 + \\cdots + x_n^2}\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection[\\texorpdfstring{Boundedness and $\\mathcal{L}_p$-norms}\n\t{Boundedness and Lp-norms}]\n\t{Boundedness and $\\mathcal{L}_p$-norms}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{$\\mathcal{L}_p$-norm}\n\\begin{equation}\n\t\\norm{f}_p\n\t=\n\t\\left(\n\t\t\\int_a^b \\abs{f(\\tau)}^p \\dif \\tau\n\t\\right)^{1/p}\n\\end{equation}\n\n\\paragraph{$\\mathcal{L}_\\infty$-norm}\n\\begin{equation}\n\t\\norm{f}_\\infty\n\t=\n\t\\sup_{a \\leq t \\leq b} \\abs{f(t)}\n\\end{equation}\n\n\\paragraph{Boundedness}\n\\begin{equation}\n\tf \\in \\mathcal{L}_p \\Leftrightarrow \\norm{f}_p < \\infty\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Properties of norms}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{H\u00f6lder's inequality}\n\\begin{equation}\n\t\\norm{fg}_1 \\leq \\norm{f}_p \\norm{g}_q\n\\end{equation}\nwith $\\frac{1}{p} + \\frac{1}{q} = 1$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Matrix properties}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{Singular} A matrix is \\emph{singular} iff its determinant is zero.\n\n\\paragraph{Skew-symmetry} A matrix $A$ is \\emph{skew-symmetric} iff\n\\begin{equation}\n\t-A = A\\T\n\t.\n\\end{equation}\n\n\\paragraph{Jacobian} The \\emph{Jacobian} matrix is defined by\n\\begin{equation}\n\tJ\n\t=\n\t\\od{f}{x}\n\t=\n\t\\begin{bmatrix}\n\t\t\\pd{f_1}{x_1} & \\cdots & \\pd{f_1}{x_n} \\\\\n\t\t\\vdots        & \\ddots & \\vdots        \\\\\n\t\t\\pd{f_m}{x_1} & \\cdots & \\pd{f_m}{x_n}\n\t\\end{bmatrix}\n\t.\n\\end{equation}\n\n\\paragraph{Hurwitz}\nA matrix $A$ is \\emph{Hurwitz} if all eigenvalues of $A$ satisfy $\\Re \\lambda_i < 0$.\n\n\\paragraph{Positive definite} A matrix being \\emph{positive definite} is equivalent to\n\\begin{itemize}\n\t\\item all its eigenvalues being positive,\n\t\\item all its leading principal minors being positive.\n\\end{itemize}\nIn addition, we have\n\\begin{equation}\n\t\\lambda\\sub{min}(H) x\\T x \\leq x\\T H x \\leq \\lambda\\sub{max}(H) x\\T x\n\\end{equation}\nfor a positive definite $x\\T H x$.\n", "meta": {"hexsha": "d00f41aa114e1c80072be648c89444d60822dd9c", "size": 2354, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4150 Nonlinear control systems/sec-math.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TTK4150 Nonlinear control systems/sec-math.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TTK4150 Nonlinear control systems/sec-math.tex", "max_forks_repo_name": "jakoblover/ntnu-course-summaries", "max_forks_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.6346153846, "max_line_length": 86, "alphanum_fraction": 0.601104503, "num_tokens": 889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9637799430946808, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.8338856086967139}}
{"text": "\n\\subsection{Coefficient of determination (\\(R^2\\))}\n\n\\(R^2= 1-\\dfrac{RSS}{TSS}\\)\n\n", "meta": {"hexsha": "1f5775ba8ebdfc9619fc42310bfd95b7f78feb25", "size": 83, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/parametric/01-02-R2.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/parametric/01-02-R2.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/parametric/01-02-R2.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.8333333333, "max_line_length": 51, "alphanum_fraction": 0.6265060241, "num_tokens": 32, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9597620596782469, "lm_q2_score": 0.8688267796346598, "lm_q1q2_score": 0.8338669795257795}}
{"text": "\\chapter{The Metric Tensor}\nWe've created this idea of the inner product $(\\cdot,\\cdot)$, which maps from $V \\times V$ to $\\mathbb{F}$.\nThere is a striking similarity between this function and rank $(0,2)$ tensors, which also map from $V \\times V$ to $\\mathbb{F}$.\nIn fact, the inner product is one such tensor.\nThe $\\tps{T}^0_2$ tensor $g_{\\mu\\nu} \\vec{e}^\\mu \\otimes \\vec{e}^\\nu$ which acts as the inner product is known as the \\emph{metric tensor}.\nWe can then define the inner product based on the component of this tensor, so $(\\vec{e}_\\mu,\\vec{e}_\\nu) = g_{\\mu\\nu}$.\nWhat these values \\emph{are} exactly is a more complicated part of the story, and doesn't necessarily have a single definite answer in the context of general relativity, but the point is that we can use this metric tensor as a representation of the inner product.\nThen by the linearity of $g_{\\mu,\\nu}$ and the inner product,\n\\[ (A^\\alpha \\vec{e}_\\alpha, B^\\beta \\vec{e}_\\beta) = g_{\\mu\\nu} A^\\alpha \\langle \\vec{e}^\\mu, \\vec{e}_\\alpha \\rangle B^\\beta \\langle \\vec{e}^\\nu, \\vec{e}_\\beta \\rangle = A^\\mu B^\\nu g_{\\mu\\nu}, \\]\nand so we can extend the inner product to arbitrary vectors with the metric tensor.\n\n\\section{Linking $V$ and $V^*$}\nUp until this point, we've established that by creating a vector space $V$, we automatically get the dual space $V^*$ without having to do anything else.\nHowever, although these two spaces are clearly related to one another, there hasn't been a canonical way to relate vectors in $V$ to covectors in $V^*$.\nThe only way we've related them thus far is that we prefer to select a basis for $V^*$ such that $\\langle \\vec{e}^\\nu, \\vec{e}_\\mu \\rangle = \\delta_\\mu^\\nu$, but this is just a choice we made for convenience; its not an implicit law of mathematics that this must be the basis we choose for the dual space.\nWhat this means is that if we take an arbitrary vector $A^\\mu \\vec{e}_\\mu$, we haven't been able to associate it with any particular covector in $V^*$.\nAll of this changes, however, with the promotion of $V$ to a metric space and the creation of the metric tensor.\n\nWe start with an arbitrary vector $A^\\alpha \\vec{e}_\\alpha \\in V$, and the metric tensor for $V$, $g_{\\mu\\nu} \\vec{e}^\\mu \\otimes \\vec{e}^\\nu \\in V^* \\otimes V^*$.\nThe metric tensor normally takes two vectors as arguments, but in this case we will supply it with only the vector we've previously chosen.\nIf we apply the metric tensor to this vector, something interesting happens; we see that\n\\begin{align}\n    g_{\\mu\\nu} \\vec{e}^\\mu \\otimes \\vec{e}^\\nu (A^\\alpha \\vec{e}_\\alpha, \\cdot) &=\n    g_{\\mu\\nu} A^\\alpha \\langle \\vec{e}^\\mu, \\vec{e}_\\alpha \\rangle \\langle \\vec{e}^\\nu, \\cdot \\rangle\\label{eqn:metric-index-lowering} \\\\\n    &= g_{\\mu, \\nu} A^\\alpha \\delta^\\mu_\\alpha \\langle \\vec{e}^\\nu, \\cdot \\rangle \\nonumber \\\\\n    &= A^\\mu g_{\\mu\\nu} \\langle \\vec{e}^\\nu, \\cdot \\rangle \\nonumber \\\\\n    &= A^\\mu g_{\\mu\\nu} \\vec{e}^\\nu \\in V^* \\nonumber.\n\\end{align}\nThe result is a covector (since it has a basis of $\\vec{e}^\\nu$ and a component of $A^\\mu g_{\\mu\\nu}$) which will map a vector to $\\mathbb{F}$.\nThus the metric tensor allows us to take a vector and find a corresponding covector from the dual space.\nSince the component $A^\\mu g_{\\mu\\nu}$ is already being summed over the $\\mu$ index, we often simplify this for brevity's sake into $A_\\nu$, making our final covector $A_\\nu \\vec{e}^\\nu$. \nNotice how we started with an upper index component $A^\\mu$ and ended up with a lower index component, $A_\\nu$; this is known as \\emph{contracting} against the metric tensor.\nUsed in this way, the metric tensor kind of has two different functional definitions,\n\\begin{align*}\n    g_{\\mu\\nu} &: V \\times V \\to \\mathbb{F}, \\\\\n    g_{\\mu\\nu} &: V \\to V^*.\n\\end{align*}\n", "meta": {"hexsha": "8062eb19d473a13635f0856cd97b0a2cfb609cf0", "size": 3760, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/metric_tensor.tex", "max_stars_repo_name": "jopetty/tensor-notes", "max_stars_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/metric_tensor.tex", "max_issues_repo_name": "jopetty/tensor-notes", "max_issues_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/metric_tensor.tex", "max_forks_repo_name": "jopetty/tensor-notes", "max_forks_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 98.9473684211, "max_line_length": 305, "alphanum_fraction": 0.7029255319, "num_tokens": 1152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660949832346, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.833840051437812}}
{"text": "\\section*{RandQS}\n\\subsubsection*{For any given key $x$ in $S$, bound the expected depth of $x$ in the search tree generated by RandQS}\n\nLet the key $x$ in $S$ have rank $i$ and denote it with $s_{(i)}$. Let $s_{(j)}$ be another key in $S$ with rank $j$ where $j>i$. \nThen $s_{(j)}$ is only an ancestor to $s_{(i)}$ if $s_{(j)}$ is chosen as the pivot element before any of the elements in $S_{(ij)} = \\{s_{(i)},\\ldots,s_{(j)}\\}$. For $j<i$ the $s_{(j)}$ element is an ancestor if it is the first element chosen in $S_{(ji)}$.\n\nDefine the random variable \n$$\nX_{ij}=\n\\begin{cases}\n1, & s_{(j)} \\text{ is ancestor to } s_{(i)}\\\\\n0, &\\text{else}\n\\end{cases}.\n$$\n\nFor $j>i$ \n\\\\\nThe probability that $P(X_{ij}) = 1/(j-i+1)$.\n\\\\\nFor $j=i$ \n\\\\\nThe probability that $P(X_{ij}) = 0$.\n\\\\\nFor $j<i$ \n\\\\\nThe probability that $P(X_{ij}) = 1/(i-j+1)$.\n\nThe sum $\\sum_{j=1}^n X_{ij}$ will count the number of ancestors of $s_{(i)}$, and the number of ancestors tells us at which depth the $s_{(i)}$ are in the BST.\n\nSo the expected depth $s_{(i)}$ is\n\\begin{align*}\nE \\sum_{j=1}^n X_{ij} &=  \\sum_{j=1}^n EX_{ij} \\\\\n                      &= \\sum_{j<i} EX_{ij} + \\sum_{j>i} EX_{ij} \\\\\n\t\t\t\t\t\t\t\t\t\t\t&= \\sum_{j<i} P(X_{ij}) + \\sum_{j>i} P(X_{ij})\\\\\n\t\t\t\t\t\t\t\t\t\t\t&= \\sum_{j<i} \\frac{1}{i-j+1} + \\sum_{j>i} \\frac{1}{j-i+1}\\\\\n\t\t\t\t\t\t\t\t\t\t\t&= \\sum_{k=2}^i \\frac{1}{k} + \\sum_{k=2}^{n-i+1} \\frac{1}{k}\\\\\n\t\t\t\t\t\t\t\t\t\t\t&\\leq \\sum_{k=1}^n \\frac{1}{k} + \\sum_{k=1}^{n} \\frac{1}{k}\\\\\n\t\t\t\t\t\t\t\t\t\t\t&= 2\\sum_{k=1}^n \\frac{1}{k} = 2H_n = O(\\ln(n))\n\\end{align*}\nWhere $H_n$ is defined as in the notes.\n\nHence the expected depth of any key $x$ in $S$ is bounded by $O(\\ln(n))$", "meta": {"hexsha": "a7c509dee3a26cda9579464f615991cad69d3026", "size": 1634, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge2/RandQS.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge2/RandQS.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge2/RandQS.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9047619048, "max_line_length": 258, "alphanum_fraction": 0.5569155447, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542185, "lm_q2_score": 0.8991213826762114, "lm_q1q2_score": 0.833812170430032}}
{"text": "Let us define a data stream as a function $F(t): \\mathbb{N} \\rightarrow \\R{1}{n} \\times \\R{1}{m}$ that, for $t \\in \\mathbb{N}$,\ncan be defined as \n\\begin{equation} \n  F(t) := (\\varphi_t, y_t)\n\\end{equation}\nwhere $\\varphi_t$ and $y_t$ are related according to \n\\begin{equation}\n  y_t = \\varphi_t \\Theta + \\epsilon_t, \\quad \\mathbb{E}\\left[\\epsilon_t\\right] = 0\n\\end{equation} \nNote that we assume that the output of the underlying linear model with true\nparameters $\\Theta$ is corrupted at each time step by some additive, zero-mean\nwhite noise $\\epsilon_t$. Since the purpose of this note is not to explore the\nstatistical properties of recursive least squares, we skip over further\nclarification of the properties of this noise; results follow from the standard\nstatistical analysis of linear regression~\\cite{bishop2006pattern}. \n\n\\subsection{Static Least Squares}\nIf we wait to observe $T \\in \\mathbb{N}$ time steps of input-output pairs, we can assemble the matrices $X_T$ and $Y_T$ by vertically stacking the $\\varphi_t$ and $y_t$ observations for $t = 1,\\ldots,T$. Given these matrices, the least squares estimation problem is formulated as\n\\begin{align}\n  \\min_{\\hat\\Theta} &=  \\sum_{t=1}^\\top ||y_t - \\varphi_t\\hat\\Theta||_2^2\\\\\n                    &=  ||Y_T - X_T\\hat\\Theta||_2^2\n\\end{align}\nIt is well known (see, e.g.,~\\cite{bishop2006pattern}) that the solution to\nthis problem is given by the ``normal equation''\n\\begin{equation}\n  \\label{eq:theta_ls}\n  \\hat\\Theta_{LS}(T) := \\left(X_T^\\top X_T\\right)^{-1}X_T^\\top Y_T\n\\end{equation}\n", "meta": {"hexsha": "60329f21df0274cb4ec52dce94489c16d011b8c0", "size": 1548, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup/src/formulation.tex", "max_stars_repo_name": "cannontwo/rls", "max_stars_repo_head_hexsha": "b2ebd2fd5f2c7e48b522c27aa5ac1b4e32e5fe8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "writeup/src/formulation.tex", "max_issues_repo_name": "cannontwo/rls", "max_issues_repo_head_hexsha": "b2ebd2fd5f2c7e48b522c27aa5ac1b4e32e5fe8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "writeup/src/formulation.tex", "max_forks_repo_name": "cannontwo/rls", "max_forks_repo_head_hexsha": "b2ebd2fd5f2c7e48b522c27aa5ac1b4e32e5fe8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.3793103448, "max_line_length": 279, "alphanum_fraction": 0.7177002584, "num_tokens": 477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811611608241, "lm_q2_score": 0.863391611731321, "lm_q1q2_score": 0.833501996669698}}
{"text": "\n\n\\section{Miscellaneous}\n\n\\subsection{FFT Frequency}\n\nIt is surprisingly hard to remember the frequency samples that match the unshifted two-sided discrete Fast Fourier Transform (FFT) for odd or even length signals. Let $f_s$ be the sample frequency and $N$ be the number of points, then the discrete frequencies of the FFT are:\n\n$N$ even:\n\\begin{equation}\nf[k] = \\dfrac{f_s}{N}\\begin{cases}\n    k,& k = 0,..., \\dfrac{N}{2} - 1\\\\\n    k-N, & k = \\dfrac{N}{2}, ..., N-1 \n\\end{cases}\n\\end{equation}\n\n$N$ odd:\n\\begin{equation}\nf[k] = \\dfrac{f_s}{N}\\begin{cases}\n    k,& k = 0,..., \\dfrac{N-1}{2} \\\\\n    k-N, & k = \\dfrac{N+1}{2}, ..., N-1 \n\\end{cases}\n\\end{equation}\n\nThe routine \\texttt{fftfreq} takes as input the sampling rate, $f_s$, and number of points, $N$, and returns the discrete frequencies $f[k]$ that correspond to the unshifted two-sided FFT of odd or even $N$.\n\n{\\footnotesize\n\\VerbatimInput{\\code/Misc/fftfreq.m}\n}\n\n\n\n\\subsection{Phase wrapping}\n\nPhase wrapping is easily done with $\\angle \\exp(i\\phi)$, but there is a fun variation that uses nearest integer rounding written in terms of elementary functions: \n\\begin{eqnarray}\n\\Phi(\\phi) & = & \\phi - 2\\pi\\left[\\dfrac{\\phi}{2\\pi} \\right] \\\\\n\\ & = & -2\\arctan\\cot\\left(\\dfrac{\\phi}{2} + \\dfrac{\\pi}{2}\\right) \n\\end{eqnarray} \n\n\\noindent where $[\\cdot ]$ means round to the nearest integer so that $-\\pi \\le \\Phi \\le \\pi$. %In principle, this can be differentiated away from the wrap points.  \n\n{\\footnotesize\n\\VerbatimInput{\\code/Misc/wrap.m}\n}\n\n%http://functions.wolfram.com/IntegerFunctions/Round/introductions/FloorRelated/ShowAll.html\n\n%\n%\\subsection{Complex Standard Normal Distribution}\n%\n%The complex standard normal distribution is defined\n%\n%\\begin{equation}\n%\\gamma = \\dfrac{1}{\\sqrt{2}}\\left( \\mathcal{N}(0,1) + i \\mathcal{N}(0,1)\\right)\n%\\end{equation}\n%\n%\\noindent where $\\mathcal{N}(0,1)$ is a normal distribution with zero mean and unit variance.  This is used to add noise to complex signals or to seed power spectral densities (PSD) in the frequency domain. For the later, we require $\\gamma$ to have conjugate symmetry if the inverse Fourier transform is to yield a real valued signal. Because the Fourier transform of a Gaussian random variable is also Gaussian, a lazy way to ensure conjugate symmetry is to take the DFT of an array loaded with the real valued standard normal. However, a faster and more practical way to generate a signal from a PSD is simply to seed the PSD with the complex standard normal, without conjugate symmetry, and take the real part after the IFFT.  \n%\n%The routines \\texttt{gamman} and \\texttt{gammanw} return the complex standard normal and frequency domain complex standard normal, respectively, for an arbitrary number of dimensions of sizes $N_1$, $N_2$, etc.  The frequency domain version is computed with the DFT, which requires division by the dimension lengths.  It can be verified that for both the real and imaginary parts of each functions that the mean and variance are $0$ and $1/\\sqrt{2}$, respectively.  In \\texttt{gammanw}, we set the DC component to zero to guarantee zero mean.  \n%\n%{\\footnotesize\n%\\VerbatimInput{\\code/Misc/gamman.m}\n%}\n%\n%{\\footnotesize\n%\\VerbatimInput{\\code/Misc/gammanw.m}\n%}\n\n\\clearpage\n\\newpage\n\\subsection{Cubic Roots}\n\nThe roots of a cubic polynomial are known analytically. Let the cubic be written\n\\eq{a x^3 + b x^2 + c x + d = 0}\n\nand define\n\\ea{w &=& -\\dfrac{b}{3a} \\\\\nQ &=& \\dfrac{3ac - b^2}{9a^2} \\\\\nR&=& \\dfrac{9abc - 27a^2d - 2b^3}{54a^3} \\\\\nD &=& Q^3 + R^2}\n\nWhen $D\\ge0$, there is one real root and two complex conjugate roots. For this case, define\n\\ea{S &=& \\sqrt[3]{R + \\sqrt{D}} \\\\\nT &=&  \\sqrt[3]{R - \\sqrt{D}} }\n\nWhen $D < 0$, there are three real roots and the following is used\n\\ea{S &=& \\sqrt[3]{\\rho}e^{i \\theta/3} \\\\\nT &=&  \\sqrt[3]{\\rho}e^{-i \\theta/3} \\\\\n\\rho &=& \\sqrt{-Q^3} \\\\\n\\theta &=& \\arccos\\left(\\dfrac{R}{\\rho}\\right)}\n\nIn all instances, the positive roots of $\\sqrt[3]{}$ and $\\sqrt{}$ are used. The roots of the cubic are then given by \n\\ea{x_1 &=& w + S + T \\\\\nx_2 &=& w -\\dfrac{1}{2}(S +T) + i\\dfrac{\\sqrt{3}}{2}(S-T) \\\\\nx_3 &=& w -\\dfrac{1}{2}(S +T) - i\\dfrac{\\sqrt{3}}{2}(S-T) }\n\n\\noindent where $x_1$ is always real.\n\nThe routine \\texttt{cubicroots} is a vectorized implementation of the solution above that computes the roots of multiple cubic polynomials simultaneously. Coefficient arrays can be any size. When \\texttt{nargout == 1}, the routine returns the guaranteed real root $x_1$. The key difference between this routine and Matlab's \\texttt{roots} is that \\texttt{roots} is not vectorized and only solves one polynomial at a time, otherwise, the two routines produce the same solutions.\n\n{\\footnotesize\n\\VerbatimInput{\\code/Misc/cubicroots.m}\n}\n\n\\subsection{Quartic Roots}\n\nLike the cubic, the roots of a quartic polynomial are known analytically, \\cite{weisstein_quartic}.  Let the quartic be written \n\\eq{a x^4 + b x^3 + c x^2 + d x + e = 0}\n\nThis is put in standard form by dividing the leading coefficient\n\\eq{x^4 + a_3 x^3 + a_2 x^2 + a_1 x + a_0 = 0}\n\n\\noindent where $a_3 = b/a$, $a_2 = c/a$, $a_1 = d/a$ and $a_0 = e/a$.  This has resolvent cubic\n\\eq{y^3 - a_2y^2 + (a_1a_3-4a_0) y + (4 a_2 a_0 - a_1^2-a_3^2 a_0) = 0 \\label{resolvecube}}\n\nIf $y_1$ is any real root of \\eqref{resolvecube} (there is always at least one), then the roots of the quartic are given by \n\\ea{x_{1,2} &=& w + \\dfrac{1}{2}R \\pm \\dfrac{1}{2}D \\\\\nx_{3,4} &=& w - \\dfrac{1}{2}R \\pm \\dfrac{1}{2}E }\n\n\\noindent where\n\\ea{ D &=& \\begin{cases}  \\sqrt{T - R^2 + \\dfrac{U}{R}}, \\quad R\\ne 0 \\\\ \\sqrt{T + V},\\quad \\quad \\quad \\quad R = 0 \\end{cases} \\\\\nE &=& \\begin{cases}  \\sqrt{T - R^2 - \\dfrac{U}{R}}, \\quad R\\ne 0 \\\\ \\sqrt{T - V}, \\quad \\quad \\quad \\quad R = 0 \\end{cases} }\n\nand\n\\ea{w &=& -\\dfrac{1}{4} a_3 \\\\\nR &=& \\sqrt{\\dfrac{a_3^2}{4} - a_2 + y_1} \\\\\nT &=& \\dfrac{3 a_3^2}{4} - 2 a_2\\\\\nU &=& \\dfrac{4a_3a_2-8a_1-a_3^3}{4} \\\\\nV &=& 2 \\sqrt{y_1^2 - 4 a_0} }\n\n\nThe routine \\texttt{quarticroots} is a vectorized implementation of the solution above that computes the roots of multiple quartic polynomials simultaneously. Coefficient arrays can be any size. The real cubic root, $y_1$, comes from \\texttt{cubicroots}. Again, Matlab's \\texttt{roots} only solves one polynomial at a time, otherwise the two routines produce the same solutions.\n\n{\\footnotesize\n\\VerbatimInput{\\code/Misc/quarticroots.m}\n}\n\n\\clearpage\n\\newpage\n\\subsection{Uniform Points on a Sphere}\n\nA quick approximation of uniform points on a sphere is based on the disco ball. Points are distributed mostly evenly at discrete latitudes centered on a prime meridian. This avoids crowding at the poles that happens with uniform sampling in spherical coordinates. Specifically, the number of lines of latitude is chosen which are divided equally between $\\theta = [0, \\pi]$, then each circle of constant latitude is divided by the latitude spacing as many times as it will go.\n\nThe routine \\texttt{discoball} takes as input the number of latitude lines \\texttt{nlat} and returns the spherical coordinates of the points $(\\theta,\\phi)$.  \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=3.5in]{Utilities/Figures/discoball}\n\\caption{Disco ball approximation for uniform points on a sphere}\n\\end{figure}\n\n{\\footnotesize\n\\VerbatimInput{\\code/Misc/discoball.m}\n}\n\n\\clearpage\n\\newpage\n\n\\subsection{Uniformly Random Points on a Sphere}\n\nTo create a set of points that are uniformly random over the unit sphere, it is not correct to draw from a uniformly random distribution of spherical angles $(\\theta,\\phi)$, because this leads to crowding at the poles.  Instead, the following transformation is used, \\cite{randsphere}, \n\\begin{eqnarray}\n\\phi &=& 2\\pi U(0,1) \\\\\n\\theta &=& \\arccos(2V(0,1)-1)\n\\end{eqnarray}\n\n\\noindent where $U(0,1)$ and $V(0,1)$ are uniform random variables from $[0,1]$.  \n\nThe routine \\texttt{randsphere} takes as input the total number of points, $N$, and returns the spherical $(\\theta,\\phi)$ coordinates of the points.  \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=3.5in]{Utilities/Figures/uniformrand}\n\\caption{Uniformly random points on a sphere, $N = 1000$. }\n\\end{figure}\n\n{\\footnotesize\n\\VerbatimInput{\\code/Misc/randsphere.m}\n}\n\n%\n%\\subsection{$\\log_b(x)$}\n%\n%Matlab doesn't have this.\n%\n%\\begin{equation}\n%\\log_b(x) = \\log(x)/\\log(b)\n%\\end{equation}\n%\n%{\\footnotesize\n%\\VerbatimInput{\\code/Misc/logb.m}\n%}\n%\n%\\subsection{Triangle Function}\n%\n%The standard triangle function is given by\n%\n%\\begin{align}\n%\\textrm{tri}(t) = \n%& = \\max(1 - |t|, 0) \\\\\n%&= \n%\\begin{cases}\n%1 - |t|, & |t| < 1 \\\\\n%0, & \\mbox{otherwise} \n%\\end{cases}\n%\\end{align}\n%\n%This can be generalized to a triangle with arbitrary width, height, horizontal and vertical offsets as\n%\n%\\begin{equation}\n%\\textrm{tri}(t) = \\max\\left(b\\left(1-\\left\\vert \\dfrac{x-x_o}{a} \\right\\vert \\right) + y_o, y_o\\right)\n%\\end{equation}\n\n%\n%{\\footnotesize\n%\\VerbatimInput{\\code/Misc/triangle.m}\n%}\n\n", "meta": {"hexsha": "48dccab797d44a31a14ecb31d7a0d842f446738e", "size": 8933, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/Utilities/Miscellaneous.tex", "max_stars_repo_name": "nasa-jpl/Waveport", "max_stars_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-08-29T13:29:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T20:09:47.000Z", "max_issues_repo_path": "Tex/Utilities/Miscellaneous.tex", "max_issues_repo_name": "ruzakb/Waveport", "max_issues_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tex/Utilities/Miscellaneous.tex", "max_forks_repo_name": "ruzakb/Waveport", "max_forks_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-08-29T13:28:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-08T19:58:04.000Z", "avg_line_length": 40.6045454545, "max_line_length": 732, "alphanum_fraction": 0.6999888056, "num_tokens": 2895, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.8918110540642805, "lm_q1q2_score": 0.8333039397059608}}
{"text": "\\section{Task B}\n\\label{sec:task-b}\n\nFor a constant strain triangle (CST) element, the shape functions can be defined as\n\\begin{equation}\n  \\label{eq:shape-func}\n  N_{1} = 1 - \\xi - \\eta, \\quad N_{2} = \\xi, \\quad N_{3} = \\eta\n\\end{equation}\n\nAccording to equations \\eqref{eq:material-shape-grad}, the \\textit{material}\ngradient of shape function reads\n\\begin{equation} \\tag{9.6ab} \\label{eq:material-shape-grad}\n  \\ubar{\\nabla}_{0}N_{a} = \\frac{\\partial N_{a}}{\\partial \\ubar{\\bm{X}}} = \n  \\left( \\frac{\\partial \\ubar{\\bm{X}}}{\\partial \\ubar{\\bm{\\xi}}} \\right)^{-T}\n  \\frac{\\partial N_{a}}{\\partial \\ubar{\\bm{\\xi}}} =\n  \\left( \\frac{\\partial \\ubar{\\bm{X}}}{\\partial \\ubar{\\bm{\\xi}}} \\right)^{-T}\n  \\cdot \\ubar{\\nabla}_{\\xi} N_{a}, \\quad\n  \\frac{\\partial \\ubar{\\bm{X}}}{\\partial \\ubar{\\bm{\\xi}}} \n  = \\sum_{a=1}^{n} \\ubar{\\bm{X}}_{a} \\otimes \\ubar{\\nabla}_{\\xi}N_{a}\n\\end{equation}\n%\n\\begin{equation}\n  \\ubar{\\nabla}_{\\xi} N_{a} = \\left[\n    \\begin{array}{c}\n      \\dfrac{\\partial N_{a}}{\\partial \\xi} \\\\\n      \\dfrac{\\partial N_{a}}{\\partial \\eta} \\\\\n\t\\end{array} \\right] =\n  \\left[\n    \\begin{array}{c c c}\n      \\dfrac{\\partial N_{1}}{\\partial \\xi} & \\dfrac{\\partial N_{2}}{\\partial \\xi} & \\dfrac{\\partial N_{3}}{\\partial \\xi}\\\\\n      \\dfrac{\\partial N_{1}}{\\partial \\eta} & \\dfrac{\\partial N_{2}}{\\partial \\eta} & \\dfrac{\\partial N_{3}}{\\partial \\eta}\\\\\n\t\\end{array} \\right]  =\n  \\left[\n    \\begin{array}{c c c}\n      -1 & 1 & 0 \\\\\n      -1 & 0 & 1 \\\\\n\t\\end{array} \\right]\n\\end{equation}\nSimilarly, the \\textit{spatial} shape function gradients are given as\n\\begin{equation} \\tag{9.11ab}\n  \\label{eq:spatial-shape-grad}\n  \\ubar{\\nabla} N_{a} = \\frac{\\partial N_{a}}{\\partial \\ubar{\\bm{x}}} =\n  \\left( \\frac{\\partial \\ubar{\\bm{x}}}{\\partial \\ubar{\\bm{\\xi}}} \\right)^{-T}\n  \\cdot \\ubar{\\nabla}_{\\xi} N_{a}, \\quad\n  \\frac{\\partial \\ubar{\\bm{x}}}{\\partial \\ubar{\\bm{\\xi}}} \n  = \\sum_{a=1}^{n} \\ubar{\\bm{x}}_{a} \\otimes \\ubar{\\nabla}_{\\xi}N_{a}\n\\end{equation}\nLastly, the deformation gradient can be expressed as\n\\begin{equation} \\tag{9.5}\n  \\label{eq:deform-grad}\n  \\utilde{F} = \\sum_{a=1}^{n} \\ubar{\\bm{x}}_{a} \\otimes \\ubar{\\nabla}_{0} N_{a}\n\\end{equation}\n\nThe Matlab implementation of this task can be found in \\texttt{shape\\_gradients.m}\n(see section \\ref{app:matlab-code}).\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../main\"\n%%% End:\n", "meta": {"hexsha": "7fa326f572ea02c2d8d95773bbc6b17b5ccc13b5", "size": 2352, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/sec/task_b.tex", "max_stars_repo_name": "iamrosk/hyperelasticity", "max_stars_repo_head_hexsha": "b4f33e0c4f79473df47f29cce398b61e264f204b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-14T00:14:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-14T00:14:05.000Z", "max_issues_repo_path": "doc/sec/task_b.tex", "max_issues_repo_name": "iamrosk/hyperelasticity", "max_issues_repo_head_hexsha": "b4f33e0c4f79473df47f29cce398b61e264f204b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/sec/task_b.tex", "max_forks_repo_name": "iamrosk/hyperelasticity", "max_forks_repo_head_hexsha": "b4f33e0c4f79473df47f29cce398b61e264f204b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-14T03:19:55.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-14T03:19:55.000Z", "avg_line_length": 38.5573770492, "max_line_length": 125, "alphanum_fraction": 0.6105442177, "num_tokens": 914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067228145365, "lm_q2_score": 0.8840392741081574, "lm_q1q2_score": 0.8332129590790212}}
{"text": "\\subsection{SVD as a change of basis}\n\nNext thing to remember, are the specially nice properties of orthogonal\nmatrices. By definition they are square matrices ($n \\times n$), and\ntheir columns form an orthonormal basis of \\R{n}; this property\nimplies that they are invertible, but also, that the inverse is\nspecially easy to compute: it is just the transpose. In addition,\northogonal matrices are an special case of change of basis matrices:\nif $Q$ is an orthogonal matrix, then it can be seen as a function\nwhich takes vectors in the coordinates of its column basis, and that\nspits as result the coordinates in the canonical basis. On the same\nline, $\\inv{Q}$ does represent the opposite change of basis\n(from the canonical coordinates to those in terms of the columns of\n$Q$). \\\\\n\nHaving set the proper context, let us restate the SVD factorization as\na sequence of successive transformations:\n\n\\begin{enumerate}\n\\item Start with a vector $\\vec{x} \\in \\R{n}$ in canonical coordinates.\n\\item Perform a change of basis using matrix \\trans{V}, from the\n  canonical coordinates to those in terms of the columns of $V$.\n\\item Once expressed as coordinates of columns of $V$, apply the\n  linear transformation $\\Sigma$; this not only converts the vector\n  from \\R{n} to \\R{m}, but also expresses the coordinates in terms of\n  the columns of $U$.\n\\item Once transformed, perform another change of basis using matrix\n  $U$; from the coordinates of columns of $U$ to the canonical ones\n  We end then with a vector in \\R{m}.\n\\end{enumerate}\n\\hfill\n", "meta": {"hexsha": "a27bab46ed884a3c1f172543faadd5643566bff9", "size": 1541, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-intuit-cbasis.tex", "max_stars_repo_name": "rzavalet/svd-lsi-project-master", "max_stars_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "svd-intuit-cbasis.tex", "max_issues_repo_name": "rzavalet/svd-lsi-project-master", "max_issues_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "svd-intuit-cbasis.tex", "max_forks_repo_name": "rzavalet/svd-lsi-project-master", "max_forks_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.15625, "max_line_length": 71, "alphanum_fraction": 0.7650876055, "num_tokens": 375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012655937034, "lm_q2_score": 0.8807970670261976, "lm_q1q2_score": 0.8330589807245997}}
{"text": "\\lab{Least Squares and Computing Eigenvalues}{Least Squares and Computing Eigenvalues}\n\\label{lab:qr-applications}\n\\objective{Because of its numerical stability and convenient structure, the QR decomposition is the basis of many important and practical algorithms.\nIn this lab, we introduce linear least squares problems, tools in Python for computing least squares solutions, and two fundamental algorithms for computing eigenvalue.\nThe QR decomposition makes solving several of these problems quick and numerically stable.\n% \\\\ \\indent As in the previous lab, we restrict ourselves to real matrices and therefore use the transpose in place of the Hermitian conjugate.\n}\n\n\\section*{Least Squares} % ====================================================\n\nA linear system $A\\x = \\b$ is \\emph{overdetermined} if it has more equations than unknowns.\nIn this situation, there is no true solution, and $\\x$ can only be approximated.\n\nThe \\emph{least squares solution} of $A\\x = \\b$, denoted $\\widehat{\\x}$, is the ``closest'' vector to a solution, meaning it minimizes the quantity $\\|A\\widehat{\\x} - \\b\\|_2$.\n% \\footnote{The choice of the 2-norm is significant.}\nIn other words, $\\widehat{\\x}$ is the vector such that $A\\widehat{\\x}$ is the projection of $\\b$ onto the range of $A$, and can be calculated by solving the \\emph{normal equations},%\n\\footnote{See Volume 1 for a formal derivation of the normal equations.}\n\\[A\\trp A\\widehat{\\x} = A\\trp \\b.\\]\n\nIf $A$ is full rank (which it usually is in applications) its QR decomposition provides an efficient way to solve the normal equations.\nLet $A = \\widehat{Q}\\widehat{R}$ be the reduced QR decomposition of $A$, so $\\widehat{Q}$ is $m \\times n$ with orthonormal columns and $\\widehat{R}$ is $n \\times n$, invertible, and upper triangular.\nSince $\\widehat{Q}\\trp \\widehat{Q} = I$, and since $\\widehat{R}\\trp$ is invertible, the normal equations can be reduced as follows (we omit the hats on $\\widehat{Q}$ and $\\widehat{R}$ for clarity).\n\\begin{align}\n\\nonumber\nA\\trp A\\widehat{\\x} &= A\\trp \\b \\\\ \\nonumber\n(Q R)\\trp Q R  \\widehat{\\x}\n&= (Q R)\\trp \\b \\\\ \\nonumber\n R\\trp Q\\trp Q R  \\widehat{\\x}\n&=  R\\trp Q\\trp \\b \\\\ \\nonumber\n R\\trp R \\widehat{\\x}\n&=  R\\trp Q\\trp \\b \\\\\n R \\widehat{\\x}\n&= Q\\trp \\b \\label{eq:normal-equation-via-qr}\n\\end{align}\n\nThus $\\widehat{\\x}$ is the least squares solution to $A\\x=\\b$ if and only if $\\widehat{R}\\widehat{\\x} = \\widehat{Q}\\trp\\b.$\nSince $\\widehat{R}$ is upper triangular, this equation can be solved quickly with back substitution.\n\n\\begin{problem} % Solve the normal equations with QR.\nWrite a function that accepts an $m \\times n$ matrix $A$ of rank $n$ and a vector $\\b$ of length $n$.\nUse the QR decomposition and (\\ref{eq:normal-equation-via-qr}) to solve the normal equations corresponding to $A\\x = \\b$.\n\nYou may use either SciPy's QR routine or one of your own QR routines.\nIn addition, you may use \\li{la.solve_triangular()}, SciPy's optimized routine for solving triangular systems.\n\\label{prob:lstsq-via-qr}\n\\end{problem}\n\n\\subsection*{Fitting a Line} % ------------------------------------------------\n\nThe least squares solution can be used to find the best fit curve of a chosen type to a set of points.\nConsider the problem of finding the line $y = ax + b$ that best fits a set of $m$ points $\\{(x_k, y_k)\\}_{k=1}^m$.\nIdeally, we seek $a$ and $b$ such that $y_k = ax_k + b$ for all $k$.\nThese equations can be simultaneously represented by the linear system\n\\begin{equation}\nA\\x =\n\\left[\\begin{array}{cc}\nx_1 & 1 \\\\\nx_2 & 1 \\\\\nx_3 & 1 \\\\\n\\vdots & \\vdots \\\\\nx_m & 1\n\\end{array}\\right]\n\\left[\\begin{array}{c} a \\\\ b \\end{array}\\right]\n=\n\\left[\\begin{array}{c} y_1 \\\\ y_2 \\\\ y_3 \\\\ \\vdots \\\\ y_m \\end{array}\\right]\n= \\b.\n\\label{eq:linear-least-squares}\n\\end{equation}\n%\nNote that $A$ has full column rank as long as not all of the $x_k$ values are the same.\n\nBecause this system has two unknowns, it is guaranteed to have a solution if it has two or fewer equations.\nHowever, if there are more than two data points, the system is overdetermined if any set of three points is not collinear.\nWe therefore seek a least squares solution, which in this case means finding the slope $\\widehat{a}$ and $y$-intercept $\\widehat{b}$ such that the line $y = \\widehat{a}x+\\widehat{b}$ best fits the data.\n\nFigure \\ref{fig:line-fit-example} is a typical example of this idea where $\\widehat{a} \\approx \\frac{1}{2}$ and $\\widehat{b} \\approx -3$.\n\n\\begin{figure}[H] % Linear regression example (without code).\n    \\includegraphics[width=.7\\textwidth]{figures/line_fit_example.pdf}\n    \\caption{A linear least squares fit.}\n    \\label{fig:line-fit-example}\n\\end{figure}\n\n\\begin{problem}\nThe file \\texttt{housing.npy} contains the purchase-only housing price index, a measure of how housing prices are changing, for the United States from 2000 to 2010.%\n\\footnote{See \\url{http://www.fhfa.gov/DataTools/Downloads/Pages/House-Price-Index.aspx}.}\nEach row in the array is a separate measurement; the columns are the year and the price index, in that order.\nTo avoid large numerical computations, the year measurements start at 0 instead of 2000.\n\nFind the least squares line that relates the year to the housing price index (i.e., let year be the $x$-axis and index the $y$-axis).\n\n\\begin{enumerate}\n    \\item Construct the matrix $A$ and the vector $\\b$ described by (\\ref{eq:linear-least-squares}).\\\\\n    (Hint: \\li{np.vstack()}, \\li{np.column_stack()}, and/or \\li{np.ones()} may be helpful.)\n    \\item Use your function from Problem \\ref{prob:lstsq-via-qr} to find the least squares solution.\n    \\item Plot the data points as a scatter plot.\n    \\item Plot the least squares line with the scatter plot.\\\\\n\\end{enumerate}\n\\end{problem}\n\n\\begin{info} % scipy.stats.linregress().\nThe least squares problem of fitting a line to a set of points is often called \\emph{linear regression}, and the resulting line is called the \\emph{linear regression line}.\nSciPy's specialized tool for linear regression is \\li{scipy.stats.linregress()}.\nThis function takes in an array of $x$-coordinates and a corresponding array of $y$-coordinates, and returns the slope and intercept of the regression line, along with a few other statistical measurements.\n\nFor example, the following code produces Figure \\ref{fig:line-fit-example}.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy.stats import linregress\n\n# Generate some random data close to the line y = .5x - 3.\n>>> x = np.linspace(0, 10, 20)\n>>> y = .5*x - 3 + np.random.randn(20)\n\n# Use linregress() to calculate m and b, as well as the correlation\n# coefficient, p-value, and standard error. See the documentation for\n# details on each of these extra return values.\n>>> a, b, rvalue, pvalue, stderr = linregress(x, y)\n\n>>> plt.plot(x, y, 'k*', label=\"Data Points\")\n>>> plt.plot(x, a*x + b, label=\"Least Squares Fit\")\n>>> plt.legend(loc=\"upper left\")\n>>> plt.show()\n\\end{lstlisting}\n\\end{info}\n\n\\subsection*{Fitting a Polynomial} % ------------------------------------------\n\nLeast squares can also be used to fit a set of data to the best fit polynomial of a specified degree.\nLet $\\{(x_k, y_k)\\}_{k=1}^m$ be the set of $m$ data points in question.\nThe general form for a polynomial of degree $n$ is\n\\[\np_n(x) = c_n x^n + c_{n-1} x^{n-1} + \\cdots + c_2 x^2 + c_1 x + c_0 = \\sum_{i=0}^n c_i x^i.\n\\]\nNote that the polynomial is uniquely determined by its $n+1$ coefficients $\\{c_i\\}_{i=0}^n$.\nIdeally, then, we seek the set of coefficients $\\{c_i\\}_{i=0}^n$ such that\n\\[\ny_k = c_n x_k^n + c_{n-1} x_k^{n-1} + \\cdots + c_2 x_k^2 + c_1 x_k + c_0\n\\]\nfor all values of $k$.\nThese $m$ linear equations yield the linear system\n\\begin{equation}\nA\\x =\n\\left[\\begin{array}{cccccc}\nx_1^n & x_1^{n-1} & \\cdots & x_1^2 & x_1 & 1 \\\\\nx_2^n & x_2^{n-1} & \\cdots & x_2^2 & x_2 & 1 \\\\\nx_3^n & x_3^{n-1} & \\cdots & x_3^2 & x_3 & 1 \\\\\n\\vdots & \\vdots & & \\vdots & \\vdots & \\vdots \\\\\nx_m^n & x_m^{n-1} & \\cdots & x_m^2 & x_m & 1 \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{c}\nc_n \\\\ c_{n-1} \\\\ \\vdots \\\\ c_2 \\\\ c_1 \\\\ c_0\n\\end{array}\\right]\n=\n\\left[\\begin{array}{c} y_1 \\\\ y_2 \\\\ y_3 \\\\ \\vdots \\\\ y_m \\end{array}\\right]\n= \\b.\n\\label{eq:polynomial-least-squares}\n\\end{equation}\n%\nIf $m > n+1$ this system is overdetermined, requiring a least squares solution.\n\n\\subsubsection*{Working with Polynomials in NumPy} % - - - - - - - - - - - - -\n\nThe $m \\times (n+1)$ matrix $A$ of (\\ref{eq:polynomial-least-squares}) is called a \\emph{Vandermonde matrix}.%\n\\footnote{Vandermonde matrices have many special properties and are useful for many applications, including polynomial interpolation and discrete Fourier analysis.}\n% a matrix with entries $a_{ij} = x_i^{n-j+1}$.\nNumPy's \\li{np.vander()} is a convenient tool for quickly constructing a Vandermonde matrix, given the values $\\{x_k\\}_{k=1}^m$ and the number of desired columns.\n\n\\begin{lstlisting}\n>>> print(np.vander([2, 3, 5], 2))\n[[2 1]                              # [[2**1, 2**0]\n [3 1]                              #  [3**1, 3**0]\n [5 1]]                             #  [5**1, 5**0]]\n\n>>> print(np.vander([2, 3, 5, 4], 3))\n[[ 4  2  1]                         # [[2**2, 2**1, 2**0]\n [ 9  3  1]                         #  [3**2, 3**1, 3**0]\n [25  5  1]                         #  [5**2, 5**1, 5**0]\n [16  4  1]]                        #  [4**2, 4**1, 4**0]\n\\end{lstlisting}\n\nNumPy also has powerful tools for working efficiently with polynomials.\nThe class \\li{np.poly1d} represents a 1-dimensional polynomial.\nInstances of this class are callable like a function.%\n\\footnote{Class instances can be made callable by implementing the \\lif{__call__()} magic method.}\nThe constructor accepts the polynomial's coefficients, from largest degree to smallest.\n\nTable \\ref{table:numpy-poly1d} lists some attributes and methods of the \\li{np.poly1d} class.\n% For more on NumPy's polynomial routines, see \\url{http://docs.scipy.org/doc/numpy/reference/routines.polynomials.html}.\n\n\\begin{table}[H]\n\\begin{tabular}{r|l}\n    Attribute & Description \\\\\n    \\hline\n    \\li{coeffs} & The $n+1$ coefficients, from greatest degree to least. \\\\\n    \\li{order} & The polynomial degree ($n$). \\\\\n    \\li{roots} & The $n-1$ roots. \\\\\n    \\\\\n    Method & Returns \\\\\n    \\hline\n    \\li{deriv()} & The coefficients of the polynomial after being differentiated. \\\\\n    \\li{integ()} & The coefficients of the polynomial after being integrated (with $c_0 = 0$).\n\\end{tabular}\n\\caption{Attributes and methods of the \\li{np.poly1d} class.}\n\\label{table:numpy-poly1d}\n\\end{table}\n%\n\\begin{lstlisting}\n# Create a callable object for the polynomial f(x) = (x-1)(x-2) = x^2 - 3x + 2.\n>>> f = np.poly1d([1, -3, 2])\n>>> print(f)\n   2\n1 x - 3 x + 2\n\n# Evaluate f(x) for several values of x in a single function call.\n>>> f([1, 2, 3, 4])\narray([0, 0, 2, 6])\n\\end{lstlisting}\n% # Evaluate f(x) at 1, 2, 3, and 4 without creating f(x) explicitly.\n% >>> np.polyval([1, -3, 2], [1, 2, 3, 4])\n% array([0, 0, 2, 6])\n\n\\begin{problem} % Polynomial fitting.\nThe data in \\texttt{housing.npy} is nonlinear, and might be better fit by a polynomial than a line.\n\nWrite a function that uses (\\ref{eq:polynomial-least-squares}) to calculate the polynomials of degree $3$, $6$, $9$, and $12$ that best fit the data.\nPlot the original data points and each least squares polynomial together in individual subplots.\n\\\\(Hint: define a separate, refined domain with \\li{np.linspace()} and use this domain to smoothly plot the polynomials.)\n\nInstead of using Problem \\ref{prob:lstsq-via-qr} to solve the normal equations, you may use SciPy's least squares routine, \\li{scipy.linalg.lstsq()}.\n\n\\begin{lstlisting}\n>>> from scipy import linalg as la\n\n# Define A and b appropriately.\n\n# Solve the normal equations using SciPy's least squares routine.\n# The least squares solution is the first of four return values.\n>>> x = la.lstsq(A, b)[0]\n\\end{lstlisting}\n\nCompare your results to \\li{np.polyfit()}.\nThis function receives an array of $x$ values, an array of $y$ values, and an integer for the polynomial degree, and returns the coefficients of the best fit polynomial of that degree.\n\n\\begin{comment}\n\\begin{lstlisting}\n# Generate some random data close to the line y = x^2 - 3x + 2.\n>>> x = np.linspace(0, 10, 20)\n>>> y = x**2 - 3*x + 2 + np.random.randn(20)\n\n# Use np.polyfit() to calculate the best fit 2nd degree polynomial.\n>>> coeffs = np.polyfit(x, y, 2)\n\n>>> domain = np.linspace(0, 10, 200)\n>>> plt.plot(x, y, 'k*')\n>>> plt.plot(domain, np.polyval(coeffs, domain))\n>>> plt.show()\n\\end{lstlisting}\n\\end{comment}\n\n\\label{prob:polynomial-least-squares}\n\\end{problem}\n\n\\begin{warn} % Overfitting\nHaving more parameters in a least squares model is not always better.\nFor a set of $m$ points, the best fit polynomial of degree $m-1$ \\emph{interpolates} the data set, meaning that $p(x_k) = y_k$ exactly for each $k$.\nIn this case there are enough unknowns that the system is no longer overdetermined.\nHowever, such polynomials are highly subject to numerical errors and are unlikely to accurately represent true patterns in the data.\n\nChoosing to have too many unknowns in a fitting problem is (fittingly) called \\emph{overfitting}, and is an important issue to avoid in any statistical model.\n\\end{warn}\n\n\\subsection*{Fitting a Circle} % ----------------------------------------------\n\nSuppose the set of $m$ points $\\{(x_k, y_k)\\}_{k=1}^m$ are arranged in a nearly circular pattern.\nThe general equation of a circle with radius $r$ and center $(c_1, c_2)$ is\n\\begin{equation}\n(x-c_1)^2 + (y-c_2)^2 = r^2.\n\\label{eq:standard-circle}\n\\end{equation}\n\nThe circle is uniquely determined  by $r$, $c_1$, and $c_2$, so these are the parameters that should be solved for in a least squares formulation of the problem.\nHowever, (\\ref{eq:standard-circle}) is not linear in any of these variables.\n%\n\\begin{align}\n\\nonumber (x - c_1)^2 + (y - c_2)^2 &= r^2 \\\\\n\\nonumber x^2 - 2c_1 x + c_1^2 + y^2 - 2c_2y + c_2^2 &= r^2 \\\\\nx^2 + y^2 & = 2c_1 x + 2c_2 y + r^2 - c_1^2 - c_2^2\n\\label{eq:circle-expanded}\n\\end{align}\n\nThe quadratic terms $x^2$ and $y^2$ are acceptable because the points $\\{(x_k, y_k)\\}_{k=1}^m$ are given.\nTo eliminate the nonlinear terms in the unknown parameters $r$, $c_1$, and $c_2$, define a new variable $c_3 = r^2 - c_1^2 - c_2^2$.\nThen for each point $(x_k, y_k)$, (\\ref{eq:circle-expanded}) becomes\n\\[2c_1x_k + 2c_2y_k + c_3 = x_k^2 + y_k^2.\\]\nThese $m$ equations are linear in $c_1$, $c_2$, and $c_3$, and can be written as the linear system\n\\begin{align}\n\\left[\\begin{array}{ccc}\n2 x_1 & 2 y_1 & 1 \\\\\n2 x_2 & 2 y_2 & 1 \\\\\n\\vdots & \\vdots & \\vdots \\\\\n2 x_m & 2 y_m & 1\n\\end{array}\\right]\n\\left[\\begin{array}{c} c_1 \\\\ c_2 \\\\ c_3 \\end{array}\\right]\n=\n\\left[\\begin{array}{c}\nx_1^2 + y_1^2 \\\\\nx_2^2 + y_2^2 \\\\\n\\vdots \\\\\nx_m^2 + y_m^2\n\\end{array}\\right].\n\\label{eq:circle-least-squares}\n\\end{align}\n\nAfter solving for the least squares solution, $r$ can be recovered with the relation $r = \\sqrt{c_1^2 + c_2^2 + c_3}$.\nFinally, plotting a circle is best done with polar coordinates.\nUsing the same variables as before, the circle can be represented in polar coordinates by setting\n\\begin{equation}\nx = r\\cos(\\theta) + c_1, \\qquad\ny = r\\sin(\\theta) + c_2, \\qquad\n\\theta\\in [0,2\\pi].\n\\label{eq:circle-polar-rep}\n\\end{equation}\nTo plot the circle, solve the least squares system for $c_1$, $c_2$, and $r$, define an array for $\\theta$, then use (\\ref{eq:circle-polar-rep}) to calculate the coordinates of the points the circle.\n\n\\begin{lstlisting}\n# Load some data and construct the matrix A and the vector b.\n>>> xk, yk = np.load(\"circle.npy\").T\n>>> A = np.column_stack((2*xk, 2*yk, np.ones_like(xk)))\n>>> b = xk**2 + yk**2\n\n# Calculate the least squares solution and solve for the radius.\n>>> c1, c2, c3 = la.lstsq(A, b)[0]\n>>> r = np.sqrt(c1**2 + c2**2 + c3)\n\n# Plot the circle using polar coordinates.\n>>> theta = np.linspace(0, 2*np.pi, 200)\n>>> x = r*np.cos(theta) + c1\n>>> y = r*np.sin(theta) + c2\n>>> plt.plot(x, y)                  # Plot the circle.\n>>> plt.plot(xk, yk, 'k*')          # Plot the data points.\n>>> plt.axis(\"equal\")\n\\end{lstlisting}\n\n\\begin{figure}[H]\n    \\includegraphics[width=.7\\textwidth]{figures/circle_fit_example.pdf}\n\\end{figure}\n\n\\begin{problem}\nThe general equation for an ellipse is \\[ax^2 + bx + cxy + dy + ey^2 = 1.\\]\nWrite a function that calculates the parameters for the ellipse that best fits the data in the file \\texttt{ellipse.npy}.\nPlot the original data points and the ellipse together, using the following function to plot the ellipse.\n\n\\begin{lstlisting}\ndef plot_ellipse(a, b, c, d, e):\n    \"\"\"Plot an ellipse of the form ax^2 + bx + cxy + dy + ey^2 = 1.\"\"\"\n    theta = np.linspace(0, 2*np.pi, 200)\n    cos_t, sin_t = np.cos(theta), np.sin(theta)\n    A = a*(cos_t**2) + c*cos_t*sin_t + e*(sin_t**2)\n    B = b*cos_t + d*sin_t\n    r = (-B + np.sqrt(B**2 + 4*A)) / (2*A)\n    plt.plot(r*cos_t, r*sin_t, lw=2)\n    plt.gca().set_aspect(\"equal\", \"datalim\")\n\\end{lstlisting}\n\\end{problem}\n\n\\section*{Computing Eigenvalues} % ============================================\n\nThe eigenvalues of an $n \\times n$ matrix $A$ are the roots of its characteristic polynomial $\\det(A - \\lambda I)$.\nThus, finding the eigenvalues of $A$ amounts to computing the roots of a polynomial of degree $n$.\nHowever, for $n \\ge 5$, it is provably impossible to find an algebraic closed-form solution to this problem.%\n\\footnote{This result, called \\emph{Abel's impossibility theorem}, was first proven by Niels Heinrik Abel in 1824.}\nIn addition, numerically computing the roots of a polynomial is a famously ill-conditioned problem, meaning that small changes in the coefficients of the polynomial (brought about by small changes in the entries of $A$) may yield wildly different results.\nInstead, eigenvalues must be computed with iterative methods.\n\n\\subsection*{The Power Method} % ----------------------------------------------\n\nThe \\emph{dominant eigenvalue} of the $n \\times n$ matrix $A$ is the unique eigenvalue of greatest magnitude, if such an eigenvalue exists.\nThe \\emph{power method} iteratively computes the dominant eigenvalue of $A$ and its corresponding eigenvector.\n\nBegin by choosing a vector $\\x_0$ such that $\\|\\x_0\\|=1$, and define\n\\[\\x_{k+1}=\\frac{A\\x_k}{\\|A\\x_k\\|}.\\]\nIf $A$ has a dominant eigenvalue $\\lambda$, and if the projection of $\\x_0$ onto the subspace spanned by the eigenvectors corresponding to $\\lambda$ is nonzero, then the sequence of vectors $(x_k)_{k=0}^\\infty$ converges to an eigenvector $\\x$ of $A$ corresponding to $\\lambda$.\n\nSince $\\x$ is an eigenvector of $A$, $A\\x = \\lambda \\x$.\nLeft multiplying by $\\x\\trp$ on each side gives $\\x\\trp A\\x = \\lambda \\x\\trp\\x$, and hence $\\lambda = \\frac{\\x\\trp A\\x}{\\x\\trp\\x}$.\nThis ratio is called the \\emph{Rayleigh quotient}.\nHowever, since each $\\x_k$ is normalized, $\\x\\trp\\x = \\|\\x\\|^2 = 1$, so $\\lambda = \\x\\trp A\\x$.\n\nThe entire algorithm is summarized below.\n\n\\begin{algorithm}[H] % The Power Method\n\\begin{algorithmic}[1]\n\\Procedure{Power Method}{$A$}\n    \\State $m, n \\gets \\shape{A}$\n        \\Comment{$A$ is square so $m = n$.}\n    \\State $\\x_0 \\gets \\text{random}(n)$\n        \\Comment{A random vector of length $n$}\n    \\State $\\x_0 \\gets \\x_0/\\|\\x_0\\|$\n        \\Comment{Normalize $\\x_0$}\n    \\For{$k = 1,\\ 2,\\ \\ldots,\\ N-1$}\n        \\label{step:power-method-stopping-criterion}\n        \\State $\\x_{k+1} \\gets A\\x_k$\n        \\State $\\x_{k+1} \\gets \\x_{k+1}/\\|\\x_{k+1}\\|$\n    \\EndFor\n    \\State \\pseudoli{return} $\\x_N\\trp A \\x_N,\\ \\x_N$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\label{Alg:power-method}\n\\end{algorithm}\n\nThe power method is limited by a few assumptions.\nFirst, not all square matrices $A$ have a dominant eigenvalue.\nHowever, the Perron-Frobenius theorem guarantees that if all entries of $A$ are positive, then $A$ has a dominant eigenvalue.\nSecond, there is no way to choose an $\\x_0$ that is guaranteed to have a nonzero projection onto the span of the eigenvectors corresponding to $\\lambda$, though a random $\\x_0$ will almost surely satisfy this condition.\nEven with these assumptions, a rigorous proof that the power method converges is most convenient with tools from spectral calculus.\n% See the Volume 1 text for details.\n\n\\begin{problem} % Implement the power method.\nWrite a function that accepts an $n \\times n$ matrix $A$, a maximum number of iterations $N$, and a stopping tolerance \\li{tol}.\nUse Algorithm \\ref{Alg:power-method} to compute the dominant eigenvalue of $A$ and a corresponding eigenvector.\nContinue the loop in step \\ref{step:power-method-stopping-criterion} until either $\\|\\x_{k+1} - \\x_k\\|$ is less than the tolerance \\li{tol}, or until iterating the maximum number of times $N$.\n\nTest your function on square matrices with all positive entries, verifying that $A\\x = \\lambda\\x$.\nUse SciPy's eigenvalue solver, \\li{scipy.linalg.eig()}, to compute all of the eigenvalues and corresponding eigenvectors of $A$ and check that $\\lambda$ is the dominant eigenvalue of $A$.\n\n\\begin{lstlisting}\n# Construct a random matrix with positive entries.\n>>> A = np.random.random((10,10))\n\n# Compute the eigenvalues and eigenvectors of A via SciPy.\n>>> eigs, vecs = la.eig(A)\n\n# Get the dominant eigenvalue and eigenvector of A.\n# The eigenvector of the kth eigenvalue is the kth column of 'vecs'.\n>>> loc = np.argmax(eigs)\n>>> lamb, x = eigs[loc], vecs[:,loc]\n\n# Verify that Ax = lambda x.\n>>> np.allclose(A @ x, lamb * x)\n<<True>>\n\\end{lstlisting}\n\\end{problem}\n\n\\subsection*{The QR Algorithm} % ----------------------------------------------\n\nAn obvious shortcoming of the power method is that it only computes one eigenvalue and eigenvector.\nThe QR algorithm, on the other hand, attempts to find all eigenvalues of $A$.\n\nLet $A_0 = A$, and for arbitrary $k$ let $Q_kR_k = A_k$ be the QR decomposition of $A_k$.\nSince $A$ is square, so are $Q_k$ and $R_k$, so they can be recombined in reverse order:\n\\[A_{k+1}=R_kQ_k.\\]\nThis recursive definition establishes an important relation between the $A_k$:\n\\[Q_k^{-1}A_kQ_k = Q_k^{-1}(Q_kR_k)Q_k = (Q_k^{-1}Q_k)(R_kQ_k) = A_{k+1}.\\]\nThus, $A_k$ is orthonormally similar to $A_{k+1}$, and similar matrices have the same eigenvalues.\n% Furthermore, since each of the $Q_k$ are orthonormal, the computation is numerically stable.\nThe series of matrices $(A_k)_{k=0}^\\infty$ converges to the block matrix\n\n\\[\nS =\n\\left[\\begin{array}{cccc}\nS_1    & *      & \\cdots & *      \\\\\n\\0     & S_2    & \\ddots & \\vdots \\\\\n\\vdots & \\ddots & \\ddots & *      \\\\\n\\0     & \\cdots &     \\0 & S_m\n\\end{array}\\right].\n\\qquad\n\\text{For example,}\\ S =\n\\left[\\begin{array}{ccccc}\n\\arrayrulecolor{lightgray}\ns_1 & *       & *       & \\cdots & *      \\\\\n0   & s_{2,1} & s_{2,2} & \\cdots & *      \\\\\n    & s_{2,3} & s_{2,4} & \\cdots & *      \\\\\n    &         &         & \\ddots & \\vdots \\\\\n    &         &         &        & s_m    \\\\\n\\end{array}\\right].\n\\]\nEach $S_i$ is either a $1\\times1$ or $2\\times2$ matrix.%\n\\footnote{If all of the $S_i$ are $1\\times1$ matrices, then the upper triangular $S$ is called the \\emph{Schur form} of $A$.\nIf some of the $S_i$ are $2\\times2$ matrices, then $S$ is called the \\emph{real Schur form} of $A$.}\nIn the example above on the right, since the first subdiagonal entry is zero, $S_1$ is the $1\\times 1$ matrix with a single entry, $s_1$.\nBut as $s_{2,3}$ is not zero, $S_2$ is $2\\times 2$.\n\nSince $S$ is block upper triangular, its eigenvalues are the eigenvalues of its diagonal $S_i$ blocks.\nThen because $A$ is similar to each $A_k$, those eigenvalues of $S$ are the eigenvalues of $A$.\n\n% Second, each iteration of the algorithm transfers some of the ``mass'' from the lower to the upper triangle.\n% This is what makes $A_0, A_1, A_2, \\ldots$ converge to a matrix $S$ which has the described form.\n\nWhen $A$ has real entries but complex eigenvalues, $2 \\times 2$ $S_i$ blocks appear in $S$.\nFinding eigenvalues of a $2 \\times 2$ matrix is equivalent to finding the roots of a 2nd degree polynomial,\n\\begin{align}\n% \\nonumber S_i=\\left[\\begin{array}{cc}a&b\\\\c&d\\end{array}\\right] \\\\\n\\det(S_i - \\lambda I) =\n\\left|\\begin{array}{cc}\na - \\lambda & b           \\\\\nc           & d - \\lambda\n\\end{array}\\right|\n= (a - \\lambda)(d - \\lambda) - bc\n= \\lambda^2 - (a+d)\\lambda + (ad - bc),\n\\label{eq:qr-algorithm-roots}\n\\end{align}\nwhich has a closed form solution via the quadratic equation.\nThis implies that complex eigenvalues come in conjugate pairs.\n\n\\subsubsection*{Hessenberg Preconditioning} % - - - - - - - - - - - - - - - - -\n\nThe QR algorithm works more accurately and efficiently on matrices that are in upper Hessenberg form, as upper Hessenberg matrices are already close to triangular.\nFurthermore, if $H = QR$ is the QR decomposition of upper Hessenberg $H$ then $RQ$ is also upper Hessenberg, so the almost-triangular form is preserved at each iteration.\nPutting a matrix in upper Hessenberg form before applying the QR algorithm is called \\emph{Hessenberg preconditioning}.\n\n% Second, an iteration of the QR algorithm can be computed in $\\mathcal{O}(n^2)$ time on an upper Hessenberg matrix, as opposed to $\\mathcal{O}(n^3)$ time on a regular matrix.\n% This is because so many entries of an upper Hessenberg matrix are 0.\n% If we apply the QR algorithm to an upper Hessenberg matrix $H$, then this speed-up happens in each iteration of the algorithm, since if $H = QR$ is the QR decomposition of $H$ then $RQ$ is also upper Hessenberg.\n\nWith preconditioning in mind, the entire QR algorithm is as follows.\n\n\\begin{algorithm}[H] % The Power Method\n\\begin{algorithmic}[1]\n\\Procedure{QR Algorithm}{$A$, $N$}\n    \\State $m, n \\gets \\shape{A}$\n    \\State $S \\gets \\text{hessenberg}(A)$ \\label{step:qr-alg-hessenberg}\n        \\Comment{Put $A$ in upper Hessenberg form.}\n    \\For{$k = 0,\\ 1,\\ \\ldots,\\ N-1$} \\label{step:qr-alg-niters}\n        \\State $Q, R \\gets \\text{qr}(S)$ \\label{step:qr-alg-qr-S}\n            \\Comment{Get the QR decomposition of $A_k$.}\n        \\State $S \\gets RQ$\n            \\Comment{Recombine $R_k$ and $Q_k$ into $A_{k+1}$.}\n    \\EndFor\n    \\State \\texttt{eigs} $\\gets$ \\texttt{[]}\n        \\Comment{Initialize an empty list of eigenvalues.}\n    \\State $i \\gets 0$\n    \\While{$i < n$}\n        \\If{$S_i$ is $1 \\times 1$} \\label{step:qr-alg-S_i-1x1-or-2x2}\n            \\State Append the only entry $s_i$ of $S_i$ to \\texttt{eigs}\n        \\ElsIf{$S_i$ is $2 \\times 2$}\n            \\State Calculate the eigenvalues of $S_i$\n                \\label{step:qr-alg-S_i-eigs}\n            \\State Append the eigenvalues of $S_i$ to \\texttt{eigs}\n            \\State $i \\gets i + 1$\n        \\EndIf\n        \\State $i \\gets i + 1$\n            \\Comment{Move to the next $S_i$.}\n    \\EndWhile\n    \\State \\pseudoli{return} \\texttt{eigs}\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\label{Alg:qr-algorithm}\n\\end{algorithm}\n\n\\begin{problem}\nWrite a function that accepts an $n \\times n$ matrix $A$, a number of iterations $N$, and a tolerance \\li{tol}.\nUse Algorithm \\ref{Alg:qr-algorithm} to implement the QR algorithm with Hessenberg preconditioning, returning the eigenvalues of $A$.\n\nConsider the following implementation details.\n\\begin{itemize}\n    \\item Use \\li{scipy.linalg.hessenberg()} or your own Hessenburg algorithm to reduce $A$ to upper Hessenberg form in step \\ref{step:qr-alg-hessenberg}.\n    \\item The loop in step \\ref{step:qr-alg-niters} should run for $N$ total iterations.\n    \\item Use \\li{scipy.linalg.qr()} or one of your own QR factorization routines to compute the QR decomposition of $S$ in step \\ref{step:qr-alg-qr-S}.\n    Note that since $S$ is in upper Hessenberg form, Givens rotations are the most efficient way to produce $Q$ and $R$.\n    \\item Assume that $S_i$ is $1 \\times 1$ in step \\ref{step:qr-alg-S_i-1x1-or-2x2} if one of two following criteria hold:\n    \\begin{itemize}\n        \\item $S_i$ is the last diagonal entry of $S$.\n        \\item The absolute value of element below the $i$th main diagonal entry of $S$ (the lower left element of the $2\\times 2$ block) is less than \\li{tol}.\n    \\end{itemize}\n    \\item If $S_i$ is $2 \\times 2$, use the quadratic formula and \\eqref{eq:qr-algorithm-roots} to compute its eigenvalues.\n    Use the function \\li{cmath.sqrt()} to correctly compute the square root of a negative number.\n\\end{itemize}\n\nTest your function on small random symmetric matrices, comparing your results to SciPy's \\li{scipy.linalg.eig()}.\nTo construct a random symmetric matrix, note that $A + A\\trp$ is always symmetric.\n% How many iterations are necessary?\n% How small does \\li{tol} have to be?\n% How large can $A$ be?\n\\end{problem}\n\n\\begin{info}\nAlgorithm \\ref{Alg:qr-algorithm} is theoretically sound, but can still be greatly improved.\nMost modern computer packages instead use the \\emph{implicit QR algorithm}, an improved version of the QR algorithm, to compute eigenvalues.\n\nFor large matrices, there are other iterative methods besides the power method and the QR algorithm for efficiently computing eigenvalues.\nThey include the Arnoldi iteration, the Jacobi method, the Rayleigh quotient method, and others.\n% We will return to this subject after studying spectral calculus and Krylov subspaces.\n\\end{info}\n\n\\begin{comment} % TODO: WLS, other norms?, QR alg improvements\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Weighted Least Squares} % ----------------------------------------\n\nA \\emph{weighted 2-norm} $\\|\\cdot\\|_W$ is defined by the nonsingular matrix $W$ as follows.\n\\[\\|\\x\\|_W = \\|W\\x\\|_2 = \\sqrt{\\x\\trp W\\trp W\\x}\\]\nTypically $W$ is chosen to be a diagonal matrix, in which case the product $W\\trp W$ is also diagonal.\nGiven the overdetermined system $A\\x = \\b$, the problem of choosing $\\widehat\\x$ to minimize $\\|A\\widehat\\x - \\b\\|_W$ is called a \\emph{weighted least squares} problem.\nThis problem has a slightly different set of normal equations.\n\\[A\\trp W\\trp W A \\widehat{\\x} = A\\trp W\\trp W \\b\\]\n\nLetting $C = W A$ and $\\z = W \\b$, this equation reduces to the usual normal equations.\n\\[C\\trp C \\widehat{\\x} = C\\trp \\z\\]\n\nLeft multiplying $A$ by the diagonal matrix $W$ multiplies the rows of $A$ by the diagonal entries of $W$.\nThus the weighted least squares problem can be solved efficiently by representing $W$ as a 1-D array of its diagonal entries and using array broadcasting.\n\n\\begin{lstlisting}\n>>> C = np.vstack(w) * A\n>>> z = w * b\n>>> x = la.lstsq(C, z)[0]\n\\end{lstlisting}\n\nWeighted least squares is useful when some points in a data set are considered more important than others.\nConsider the problem of fitting data to an exponential curve $y = ae^{kx}$ where points $(x_k,y_k)$ are known.\nTaking the natural log of both sides gives $\\log(y) = \\log(a) + kx$, so the least squares problem is as follows.\n\\[\nA\\x =\n\\left[\\begin{array}{cc}\nx_1 & 1 \\\\\nx_2 & 1 \\\\\n\\vdots & \\vdots \\\\\nx_m & 1\n\\end{array}\\right]\n\\left[\\begin{array}{c} k \\\\ \\log(a) \\end{array}\\right]\n=\n\\left[\\begin{array}{c}\n\\log(y_1) \\\\ \\log(y_2) \\\\ \\vdots \\\\ \\log(y_m)\n\\end{array}\\right]\n= \\b\n\\]\n\n% TODO: Finish this section with some exponential data and showing how WLS works better than OLS in this case.\n\n\\subsection*{Using other Norms} % ---------------------------------------------\n\nIn these Least Squares problems, we have found best fit lines and ellipses relative to the 2-norm.\nIt is possible to generalize the idea of best fit curves relative to other norms.\nSee Figure \\ref{fig:lstsq-many-norms} for an illustration of this.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=.7\\textwidth]{figures/ellipsefit.pdf}\n    % TODO: where did this picture come from? CVXOPT?\n    \\label{fig:lstsq-many-norms}\n\\end{figure}\n\n\\subsection*{Improvements to the QR Algorithm} % ------------------------------\n\n\\end{comment}\n", "meta": {"hexsha": "ac4fe03d7d76e3c7bc5827daf6823f3427e3759d", "size": 31685, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume1/LeastSquares_Eigenvalues/LeastSquares_Eigenvalues.tex", "max_stars_repo_name": "DM561/dm561.github.io", "max_stars_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-13T13:22:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-13T13:22:41.000Z", "max_issues_repo_path": "acme-material/Labs/Volume1/LeastSquares_Eigenvalues/LeastSquares_Eigenvalues.tex", "max_issues_repo_name": "DM561/dm561.github.io", "max_issues_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-10-18T19:57:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-31T19:00:36.000Z", "max_forks_repo_path": "acme-material/Labs/Volume1/LeastSquares_Eigenvalues/LeastSquares_Eigenvalues.tex", "max_forks_repo_name": "DM561/dm561.github.io", "max_forks_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.5966257669, "max_line_length": 278, "alphanum_fraction": 0.6774814581, "num_tokens": 9674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.9294404086988677, "lm_q1q2_score": 0.8330122451178656}}
{"text": "\n\\subsection{\\(L_p\\) regularisation}\n\n\\subsubsection{Introduction}\n\nWe can generalise this to:\n\n\\(w_{l_p} = \\arg \\min ||y-Xw||^2_2+\\lambda ||w||^p_p\\)\n\nFor ridge regression there is always a solution.\n\nFor least squares there is a solution if \\(X^TX\\) is invertible\n\nFor Lasso we must use numerical optimisation.\n\nlasso and \\(L_1\\) induces sparcity\n\nGoal is \\(min ||y - f(x)|| + \\lambda g(w)\\)\n\nRidge regression: \\(g(w)=||w||\\)\n\nIf \\(\\lambda =0\\), OLS, if infinite, \\(w\\) goes to \\(0\\).\n\nNormal equation changes to: \\(\\lambda I + X^TX)^{-1}X^Ty\\)\n\nWe can preprocess to avoid processing of 1s. shift mean of \\(y\\) to \\(0\\). normalise \\(x\\) mean \\(0\\) var \\(1\\).\n\n\n", "meta": {"hexsha": "098bd3952b78592724e41829cba14c8913382ecb", "size": 663, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/linearML/03-03-lp.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/linearML/03-03-lp.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/linearML/03-03-lp.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.8620689655, "max_line_length": 112, "alphanum_fraction": 0.6440422323, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9732407175907054, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.8329491915818941}}
{"text": "\\section{Clustering}\n\n\\subsection{Clustering}\n\\subsection{A clustering Objective}\n$G_{j} \\subset \\{ i| c_{i}=j \\}$ where $G_{j}$ is set of all indices i for which $c_{i}=j$\\\\\n\\textbullet Group representatives: n-vectors $z_1,..,z_k$\n\n\\textbullet Clustering objective is\\\\\n$J^{clust} = \\frac{1}{N} \\sum_{i=1}^N\\Vert x_i - Z_{c_i}\\Vert^2$\\\\\n\\textbullet mean square distance from vectors to associated representative\\\\\n\\textbullet goal: choose clustering $c_i$ and representatives $z_j$\nto minimize $J_clust$\n% Group representatives: We want each rep to be close to the vectors, i.e $||x_{i}-z_{c_{i}}||$ where $x_{i}$ is in group $j=c_{i}$ so $z_{c_{i}}$ is the representative vector associated with data vector $x_{i}$ \\\\ \n% $J^{clust}=(||x_{1}-z_{c_{1}}||^2 + ...+||x_{N}-z_{c_{N}}||^2)/N$\\\\\n% Partitioning vectors with representatives fixed: $||x_{i}-z_{c_{i}}||=\\min\\limits_{j=1,....,k} ||x_{i}-z_{j}||$\\\\\n% $J^{clust}=\\Big(\\min\\limits_{j=1,....,k} ||x_{1}-z_{j}||^{2}+....+\\min\\limits_{j=1,....,k} ||x_{N}-z_{j}||^{2}\\Big)/N$\\\\\n% Optimizing group representatives with assignment fixed: $J^{clust}=J_{1}+...+J_{k}$ where $J_{j}=\\big(1/N\\big)\\sum\\limits_{i\\in G_{j}}||x_{i}-z_{j}||^{2}$\\\\\n% To minimize mean square distance $z_{j}=\\big(1/|G_{j}|\\big))\\sum\\limits_{i\\in G_{j}}x_{i}$ where $|G_{j}|$ is standard notation for number of elements in set $G_{j}$\n\\subsection{The k-means algorithm}\n\\rule{\\linewidth}{0.4pt}\n\\textbf{given} $x_1,..,x_N \\in \\textbf{R}^n$ and $z_1,...,z_k \\in \\textbf{R}^n$\\\\\n\\textbf{repeat}\\\\\n-- \\textit{Update partition}: assign i to $G_j$, $j = argmin_{j'} \\Vert x_i - z_{j'} \\Vert_2$\\\\\n-- \\textit{Update centroids}: $Z_j = \\frac{1}{|G_j|}\\sum_{i \\in G_j}x_i$\\\\\n\\textbf{until} $z1,...,zk$ stop changing\\\\\n\\rule{\\linewidth}{0.4pt}\n\n\n", "meta": {"hexsha": "6fa20cbbe0a6f6844c9b7da9fefaaa0652dd5462", "size": 1759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter4.tex", "max_stars_repo_name": "Bharat-Kulkarni/COT5615", "max_stars_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cheatsheet/inhalt/chapter4.tex", "max_issues_repo_name": "Bharat-Kulkarni/COT5615", "max_issues_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter4.tex", "max_forks_repo_name": "Bharat-Kulkarni/COT5615", "max_forks_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.6551724138, "max_line_length": 215, "alphanum_fraction": 0.637293917, "num_tokens": 698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.9032942119105695, "lm_q1q2_score": 0.8327666591963113}}
{"text": "\\chapter{Parabolic PDEs}\n\nHeat equation:\n\n\\begin{equation*}\n\\frac{\\partial u}{\\partial t} (x, t) = c \\Delta u(x,t) + f(x, t), \\quad (x, t) \\in \\Omega \\times [0, T]\n\\end{equation*}\n\nwhere $\\Omega$ is an open subject of $\\mathbb{R}^d \\; (d = 1, 2, \\text{ or } 3)$ (interprets a body), $[0, T]$, in a time interval.\n$u$ represents temperature; $c$ depends on conductivity, specific heat and density of the body $\\Omega$; $f$ represents sources or sinks of heat.\n\nWe have to add:\n\\begin{itemize}\n\t\\item boundary conditions: $u(x, t)=0, \\quad (x,t) \\in \\Gamma \\times [0, T]$ where $T$ is the border of $\\Omega$;\n\t\\item initial condition: $u(x, 0) = u_0(x), \\quad x \\in \\Omega$\n\\end{itemize}\n\nThe problem: given $c, f, u_0$, find $u$!\n\n\\section{Numerical solution of the heat equation}\n\nConsider $\\Omega = (0, 1)^2$, $h=\\frac{1}{N}$, with $N$ positive integer.\nThen we have $\\Omega_h, \\Gamma_h, \\Delta_h$.\n\nThe discrete problem is:\n\n\\begin{equation*}\n\\frac{\\partial}{\\partial t} u_h((x, y), t) = \\Delta_h u_h(x, y) + f(x, y),\n\\quad (x, y) \\in \\Omega_h\n\\end{equation*}\n\n\\begin{equation*}\nu_h((x, y), t) = 0, \\quad (x, y) \\in \\Gamma_h\n\\end{equation*}\n\n\\begin{equation*}\nu_h((x,y), 0) = u_0(x, y), \\quad (x, y) \\in \\Omega_h\n\\end{equation*}\n\nThis is a linear system of $(N-1)^2$ scalar linear differential equations in the $(N-1)^2$ unknown functions:\n\n\\begin{equation*}\nu_h ((x, y), \\cdot): [0, T] \\rightarrow \\mathbb{R}, \\quad (x, y) \\in \\Omega_h\n\\end{equation*}\n\nThis is only a \\textit{semi-discretization} because the time is not discretized (it's called \\textit{method of lines} since the lines are the unknown functions).\nFor a full discretization we need a numerical method for the time-integration.\n\nThe simplest method to solve ODEs of type\n\\begin{equation*}\ny'(t) = f(t, y(t)), \\quad t \\in [0, T]\n\\end{equation*}\nis the Explicit Euler (also called Forward Euler) method, which scheme is $y_{m+1} = y_m + k f(t_m, y_m), \\quad m=0, \\dots, M-1$.\n\nThere's also the Implicit Euler (also called Backward Euler) method: $y_{m+1} = y_m + f(t_{m+1}, y_{m-})$.\n\nAnd also the Trapezoidal Rule: $y_{m+1} = y_m + \\frac{1}{2} (f(t_m, y_m) + f(t_{m+1}, y_{m+1})$.\n\nWe consider the \\textit{1D} case:\n\n\\begin{equation*}\n\\frac{\\partial}{\\partial t} u(x, t) = \\frac{\\partial^2}{\\partial x^2} u(x, t) + f(x, t), \\quad (x, t) \\in \\overbrace{(0, 1)}^{= \\Omega} \\times [0, T]\n\\end{equation*}\n\n\\begin{equation*}\nu(0, t) = u(1, t) = 0\n\\end{equation*}\n\\begin{equation*}\nu(x, 0) = u_0(x), \\quad x \\in (0, 1)\n\\end{equation*}\n\nwith: $\\Omega = (0, 1)$, $\\Omega_h = \\{nh: n \\in \\{1, \\dots, N-1\\} \\}$ and $\\Gamma_h = \\{0, 1\\}$.\n\nWe discretize in space by the centered difference scheme for the second derivative in space and in time by the forward difference scheme for the first derivative in time. We use $h = \\frac{1}{N}$ as space stepsize and $k = \\frac{T}{M}$ as time stepsize.\ndiscrete point in space: $nh$ with $n \\in \\{1, \\dots, N-1\\}$ \ndiscrete point in time: $mk$ with $k \\in \\{1, \\dots, u\\}$ \n\n$U_n^m$ denotes two discrete approximation of $u(nh, mk)$.\nAt the point $(nh, mk)$, $n \\in \\{1, \\dots, N-1\\}$ and $m \\in \\{0, 1, \\dots, M-1\\}$ we have the discrete equation:\n\n\\begin{equation*}\n\\underbrace{\\frac{U_n^{m+1} - U_n^{m}}{k}}_{\\approx \\frac{\\partial u}{\\partial t}(x, t) \\text{ with } x=nh,\\,t=mk } = c \\underbrace{\\frac{U_{n-1}^{m} - 2U_n^{m} + U_{n+1}^{m}}{h^2}}_{\\approx \\frac{\\partial u}{\\partial x^2}(x, t)} + \\underbrace{f_n^m}_{= f(nk, mk)}\n\\end{equation*}\n\n\\begin{equation*}\nU_n^{m+1} = \\frac{c k}{h^2} U_{n-1}^m + (1 - \\frac{2 c k}{h^2}) U_n^m + \\frac{c k}{h^2} U_{n+1}^m + k f_n^m =\n\\end{equation*}\n\n\\begin{equation*}\n= U_n^m + \\frac{ck}{h^2}U_{n-1}^m - \\frac{2 c k}{h^2} U_n^m + \\frac{c k}{h^2}U_{n+1}^m\n\\end{equation*}\n\nConsider:\n\\begin{equation*}\nU^m = (U_1^m, \\dots, U_{N-1}^m), f^m = (f_1^m, \\dots, f_{N-1}^m)\n\\end{equation*}\n\n\\begin{equation*}\nU^{m+1} = U^m + k(\\Delta_h U^m + f^m)\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n\n\\begin{equation*}\n\\end{equation*}\n", "meta": {"hexsha": "f8379cc49367d31b0bd62b91d0d848257b785825", "size": 6278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/ch04.tex", "max_stars_repo_name": "bebosudo/advanced-numerical-analysis", "max_stars_repo_head_hexsha": "a46aea05b7bef661c689ca5facf10d5ea4a85d30", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/ch04.tex", "max_issues_repo_name": "bebosudo/advanced-numerical-analysis", "max_issues_repo_head_hexsha": "a46aea05b7bef661c689ca5facf10d5ea4a85d30", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/ch04.tex", "max_forks_repo_name": "bebosudo/advanced-numerical-analysis", "max_forks_repo_head_hexsha": "a46aea05b7bef661c689ca5facf10d5ea4a85d30", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.5163398693, "max_line_length": 264, "alphanum_fraction": 0.6462249124, "num_tokens": 2541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392797, "lm_q2_score": 0.8902942319436397, "lm_q1q2_score": 0.8327336009759959}}
{"text": "\\subsubsection{Derivatives}\r\nThe derivative of a function $y = f(x)$, notated $f'(x)$, gives the slope of the tangent line to $f$ at $x$.\r\n\\begin{definition}\r\n\t\\begin{equation*}\r\n\t\tf'(x) = \\lim\\limits_{h \\to 0}{\\frac{f(x+h) - f(x)}{h}}\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\r\n\\noindent\r\nBelow are some properties of the derivative. Let $f$ and $g$ be functions of $x$ and $p$ a scalar.\r\n\\begin{enumerate}[label=]\r\n\t\\item Linearity\r\n\t\\begin{equation*}\r\n\t\t\\left( pf \\pm g \\right)' = pf' \\pm g'\r\n\t\\end{equation*}\r\n\t\\item Product Rule\r\n\t\\begin{equation*}\r\n\t\t\\left( fg \\right)' = f'g + fg'\r\n\t\\end{equation*}\r\n\t\\item Quotient Rule\r\n\t\\begin{equation*}\r\n\t\t\\left( \\frac{f}{g} \\right)' = \\frac{f'g - fg'}{g^2}\r\n\t\\end{equation*}\r\n\t\\item Chain Rule\r\n\t\\begin{equation*}\r\n\t\t\\left( f \\circ g \\right)' = \\left( f' \\circ g \\right) \\cdot g'\r\n\t\\end{equation*}\r\n\t\\item Power Rule\r\n\t\\begin{equation*}\r\n\t\t\\dd{x} p^x = px^{p-1} \\text{, } p \\neq 0\r\n\t\\end{equation*}\r\n\t\\item Exponent Rule\r\n\t\\begin{equation*}\r\n\t\t\\dd{x} p^x = p^x \\ln{p} \\text{, } p > 0\r\n\t\\end{equation*}\r\n\t\\item The Power Rule and Exponent Rule are two cases of the same rule\r\n\t\\begin{equation*}\r\n\t\t\\dd{x} f^g = gf^{g-1}f' + f^g\\ln{f}g'\r\n\t\\end{equation*}\r\n\\end{enumerate}\r\nUsing the definition of the derivative and these rules, we can find the derivatives to some common functions\\\\\r\n\\begin{center}\r\n\t\\begin{tabular}{c | c}\r\n\t\t\\large{$\\dd{}{x} p = 0$} \t\t\t\t& \\large{$\\dd{}{x} e^x = e^x$} \t\t\t\\\\ [0.75em]\r\n\t\t\\large{$\\dd{}{x} \\ln{x} = \\frac{1}{x}$} & \\large{$\\dd{}{x} \\sin{x} = \\cos{x}$} \t\\\\ [0.75em]\r\n\t\t\\large{$\\dd{}{x} \\cos{x} = -\\sin{x}$} \t& \\large{$\\dd{}{x} \\tan{x} = \\sec^2{x}$}\r\n\t\\end{tabular}\r\n\\end{center}\r\n", "meta": {"hexsha": "d98837a3239564a2a70443bcd09f21a50b3543ca", "size": 1652, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/backgroundReview/singleVariableCalc/derivatives.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/backgroundReview/singleVariableCalc/derivatives.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/backgroundReview/singleVariableCalc/derivatives.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7142857143, "max_line_length": 111, "alphanum_fraction": 0.5853510896, "num_tokens": 690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392795, "lm_q2_score": 0.8902942268497306, "lm_q1q2_score": 0.8327335962114257}}
{"text": "\\section{Definition of the Derivative}\r\n\\begin{definition}\r\n\tThe derivative of a function $f(x)$, notated $f^\\prime(x)$, is the slope of $f$ at any point along $f$.\r\n\tThis is also the slope of the tangent line to $f$ at this point, which is also the instantaneous rate of change of $f$ at this point.\r\n\t\\begin{equation}\r\n\t\tf^\\prime(x) = \\lim_{h \\to 0}{\\frac{f(x+h)-f(x)}{h}} \\text{ (assuming the limit exists).}\r\n\t\\end{equation}\r\n\\end{definition}\r\n\r\n\\begin{example}\r\n\tFind the derivative of $f(x)=x^2+4$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tApplying the definition,\r\n\t\\begin{align*}\r\n\t\tf^\\prime(x) &= \\lim_{h\\to 0}{\\frac{f(x+h)-f(x)}{h}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{\\frac{(x+h)^2+4 - x^2 - 4}{h}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{\\frac{x^2 + 2xh + h^2 + 4 - x^2 - 4}{h}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{\\frac{2xh + h^2}{h}} \\\\\r\n\t\t&= \\lim_{h\\to 0}{2x + h} \\\\\r\n\t\t&= 2x.\\footnotemark\r\n\t\\end{align*}\r\n\\end{answer}\r\n\\footnotetext{Note that the constant term 4 didn't contribute anything to the outcome. It was canceled immediately when subtracting $f(x)$.}\r\n\r\n\r\nThere are a couple different notations that all mean the derivative of $y = f(x)$.\r\nYou should be familiar with all of them.\r\n\\begin{table}[H]\r\n\\begin{center}\r\n\\begin{tabular}{ l l l }\r\n\t$\\begin{aligned}y^\\prime\\end{aligned}$ & & $\\begin{aligned}\\dd{y}{x}\\end{aligned}$ \\\\\r\n\t& & \\\\\r\n\t$\\begin{aligned}\\dd{f}{x}\\end{aligned}$ & & $\\begin{aligned}\\dd{}{x}f(x)\\end{aligned}$\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n\r\n\\subsection{Derivative at a Point}\r\nThe formula given in the definition is useful because it gives a function that can give the derivative at any point, but it may not be useful or feasible to use this formula.\r\nInstead, we can use a formula to just give us the derivative at one point.\r\n\\begin{equation}\r\n\tf^\\prime(a) = \\lim_{x \\to a}{\\frac{f(x)-f(a)}{x-a}}.\r\n\\end{equation}\r\n\r\n\\begin{example}\r\n\tFind the derivative of $f(x) = \\frac{1}{x}$ at $x=2$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tApplying the formula for the derivative at a point,\r\n\t\\begin{align*}\r\n\t\tf^\\prime(2) &= \\lim_{x \\to 2}{\\frac{f(x)-f(2)}{x-2}} \\\\\r\n\t\t&= \\lim_{x \\to 2}{\\frac{1/x - 1/2}{x-2}} \\\\\r\n\t\t& = \\lim_{x \\to 2}{\\frac{-(x-2)}{2x(x-2)}} \\\\\r\n\t\t&= \\lim_{x \\to 2}{\\frac{-1}{2x}} \\\\\r\n\t\t&= \\frac{-1}{4}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsection{Left \\& Right Hand Derivatives}\r\nThe normal derivative is defined in terms of a two-sided limit, meaning that the left and right hand limits are equal.\r\nHowever, we can also calculate left and right hand derivatives at every point along the function's domain, which may be useful if the left and right hand derivatives are not equal or the point in question is on the boundary of the domain.\r\n\r\n\\begin{example}\r\n\tFind the left and high hand derivatives of the following function at $x=1$.\r\n\tSay if the derivative at this point exists and why.\r\n\t\\begin{equation*}\r\n\t\tf(x) = \\begin{cases}\r\n\t\t\tx^2 + x & x \\leq 1 \\\\\r\n\t\t\tx+1 & x > 1\r\n\t\t\\end{cases}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tEvaluating the left hand limit,\r\n\t\\begin{align*}\r\n\t\tf^\\prime(1^-) &= \\lim_{x \\to 1^-}{\\frac{f(x)-f(1)}{x-1}} \\\\\r\n\t\t&= \\lim_{x \\to 1^-}{\\frac{x^2 + x - 2}{x-1}} \\\\\r\n\t\t&= \\lim_{x \\to 1^-}{\\frac{(x-1)(x+2)}{x-1}} \\\\\r\n\t\t&= \\lim_{x \\to 1^-}{x+2} \\\\\r\n\t\t&= 3.\r\n\t\\end{align*}\r\n\t\r\n\tEvaluating the right hand limit,\r\n\t\\begin{align*}\r\n\t\tf^\\prime(1^+) &= \\lim_{x \\to 1^+}{\\frac{f(x)-f(1)}{x-1}} \\\\\r\n\t\t&= \\lim_{x \\to 1^+}{\\frac{x + 1 - 2}{x-1}} \\\\\r\n\t\t&= \\lim_{x \\to 1^+}{\\frac{x-1}{x-1}} \\\\\r\n\t\t&= 1.\r\n\t\\end{align*}\r\n\t\r\n\tSince $f^\\prime(1^-) \\neq f^\\prime(1^+)$, the derivative does not exist at $x=1$.\r\n\\end{answer}", "meta": {"hexsha": "25a9340c301882ecb5bec1c2111f13ba73541d7d", "size": 3558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/definition_of_derivative.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/derivatives/definition_of_derivative.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/derivatives/definition_of_derivative.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 38.2580645161, "max_line_length": 239, "alphanum_fraction": 0.6124227094, "num_tokens": 1336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172587090974, "lm_q2_score": 0.8774767810736693, "lm_q1q2_score": 0.8326528616773091}}
{"text": "\\chapter{Math Symbols, Notations, and Identities}\n\n\\section{Symbols and Notations}\nHere are the symbols and notations that you must absolutely know!\n\n\\subsection{Sets of Numbers}\n\\begin{symbollist}\n    \\item[$\\mathbb{N}$] = Set of all Natural Numbers.\n    \\item[$\\mathbb{Z}$] = Set of all Integers.\n    \\item[$\\mathbb{Q}$] = Set of all Rational Numbers.\n    \\item[$\\mathbb{R}$] = Set of all Real Numbers.\n    \\item[$\\mathbb{C}$] = Set of all Complex Numbers.\n\\end{symbollist}\n\n\\subsection{Propositional Logic}\n\\begin{symbollist}\n    \\item[$\\neg P$] = Negation of the proposition, \\emph{P}.\n    \\item[$P \\wedge Q$] = Conjunction of the propositions \\emph{P and Q}.\n    \\item[$P \\vee Q$] = Disjunction of the propositions \\emph{P and Q}.\n    \\item[$P \\oplus Q$] = P XOR Q (Exclusive Or).\n    \\item[$P \\rightarrow Q$] = \"If P, then Q\" (Conditional).\n    \\item[$P \\leftrightarrow Q$] = \"P if and only if Q\" (Biconditional).\n    \\item[$P \\Leftrightarrow Q$] = P is equivalent to Q.\n\\end{symbollist}\n\n% This would prevent LaTeX from \"spreading out\" the text to fill up the whole\n% page, which I personally prefer, but isn't necessary\n\n% \\vfill\n\n\\subsection{Set Theory}\n\\begin{symbollist}\n    \\item[$\\emptyset$] = Empty Set.\n    \\item[$ x \\in \\mathbb{Q}$] = x belongs to a rational number.\n    \\item[$A \\subset B$] = Set A is a subset of set B.\n    \\item[$S = \\{1,2,3,4\\}$] =  An example of a set in roster form.\n    \\item[$S = \\{x \\mid 1 \\leq x \\leq 4, x \\in \\mathbb{Z}\\}$] = An example of a\n        set in set-builder form.\n    \\item[$A \\cup B$] = A union B.\n    \\item[$A \\cap B$] = A intersection B.\n    \\item[$A - B$] = A minus B (Set difference).\n    \\item[$\\overline{A}$] = Complement of A.\n    \\item[$\\mid A \\mid$] = Number of elements in A (Cardinality).\n\\end{symbollist}\n\n\n\\subsection{Functions}\n\\begin{symbollist}\n    \\item[$\\lceil x \\rceil $] = Ceiling of x.\n    \\item[$\\lfloor x \\rfloor$] = Floor of x.\n    \\item[$O(f(x))$] = Big-O of the function \\emph{f}.\n    \\item[$\\Omega(f(x))$] = Big-Omega of the function \\emph{f}.\n    \\item[$\\Theta(f(x))$] = Big-Theta of the function \\emph{f}.\n\\end{symbollist}\n\n\\subsection{Number Theory}\n\\begin{symbollist}\n    \\item[$a / b$] = a divides b.\n    \\item[$a \\equiv b \\lbrack m \\rbrack$] = a is congruent to b modulo m.\n\\end{symbollist}\n\n\\subsection{Miscellaneous}\n\\begin{symbollist}\n    \\item[$\\sum_{i = 1} ^ {n} i$] = Sum of first n terms.\n    \\item[$\\prod_{i = 1} ^ {n} i$] = Product of first n terms.  $n!$ = \\emph{n}\n        factorial.\n    \\item[$\\forall x \\in \\mathbb{Z}, P(x)$] = For all x in the set of integers,\n        P(x) is true.\n    \\item[$\\exists x \\in \\mathbb{Z}, P(x)$] = There exists an x such that P(x)\n        is true.\n\\end{symbollist}\n\n\\pagebreak[4]\n\n\\section{Important Identities}\n\\indent \\indent I have compiled a bunch of identities that are going to prove\nto be very useful for proofs or problem solving. Again, I have broken them down\ninto chapters for better reference \\footnote{I haven't included basic\nconjunctions and disjunctions of propositions because you should be knowing\nthem by now!}.\n\n\\subsection{Simple Mathematical Identities}\n\\begin{symbollist}\n    \\item $(a + b)^{2} = a^{2} + 2ab + b^{2}$\n    \\item $(a - b)^{2} = a^{2} - 2ab + b^{2}$\n    \\item $a^{2} - b^{2} = (a + b)\\times(a - b)$\n    \\item $a^{m} \\times a^{n} = a^{m + n}$\n    \\item $(a^{m})^{n} = a^{mn}$\n    \\item $\\log(a \\times b) = \\log(a) + \\log(b)$\n    \\item $\\log(a^{b}) = b \\times \\log(a)$\n\\end{symbollist}\n\n\\subsection{Propositional Logic}\n\\begin{symbollist}\n    \\item $\\neg (\\neg P) = P$\n    \\item $P \\oplus Q = (P \\vee Q) \\wedge (\\neg(P \\wedge Q))$\n    \\item $\\neg(P \\wedge Q) = \\neg P \\vee \\neg Q$\n    \\item $\\neg(P \\vee Q) = \\neg P \\wedge \\neg Q$\n    \\item $P \\vee P = P$\n    \\item $P \\wedge P = P$\n    \\item $P \\wedge Q = Q \\wedge P$\n    \\item $P \\vee Q = Q \\vee P$\n    \\item $(P \\wedge Q) \\wedge R = P \\wedge (Q \\wedge R)$\n    \\item $(P \\vee Q) \\vee R = P \\vee (Q \\vee R)$\n    \\item $P \\wedge (Q \\vee R) = (P \\vee Q) \\wedge (P \\vee R)$\n    \\item $P \\vee (Q \\wedge R) = (P \\wedge R) \\vee (P \\wedge R)$\n    \\item $P \\leftrightarrow Q \\Leftrightarrow (P \\rightarrow Q) \\wedge (Q\n    \\rightarrow P)$\n    \\item $P \\rightarrow Q = \\neg P \\vee Q$\n\\end{symbollist}\n\n\\subsection{Functions}\n\\begin{symbollist}\n    \\item $ x - 1 < \\lfloor x \\rfloor \\leq x \\leq \\lceil x \\rceil < x + 1$\n    \\item $ \\lfloor - x \\rfloor = - \\lceil x \\rceil$\n    \\item $ \\lceil -x \\rceil = - \\lfloor x \\rfloor$\n    \\item $ \\lfloor x + n \\rfloor = \\lfloor x \\rfloor + n$, for some \\emph{n}\n        $\\in \\mathbb{Z}$\n    \\item $ \\lceil x + n \\rceil = \\lceil x \\rceil + n$, for some \\emph{n} $\\in\n        \\mathbb{Z}$\n    \\item $(\\exists n \\in \\mathbb{Z})(\\exists \\epsilon \\in \\mathbb{R}) \\lfloor\n        x \\rfloor = n + \\epsilon$, where $ 0 \\leq \\epsilon \\leq 1$\n    \\item $f(x) = O(g(x)) \\rightarrow (\\exists k \\in \\mathbb{Z})(\\exists c \\in\n        \\mathbb{R^{+}})(\\forall x > k)[f(x) \\leq c \\times g(x)]$\n    \\item $f(x) = \\Omega(g(x)) \\rightarrow (\\exists k \\in \\mathbb{Z})(\\exists c \\in\n        \\mathbb{R^{+}})(\\forall x > k)[f(x) \\geq c \\times g(x)]$\n    \\item $f(x) = \\Theta(g(x)) \\rightarrow [f(x) = O(g(x))] \\wedge [f(x) =\n        \\Omega(g(x))]$\n\\end{symbollist}\n\n\\subsection{Number Theory}\n\\begin{symbollist}\n    \\item $a / b \\rightarrow (\\exists c \\in \\mathbb{Z})[a = b \\times c]$\n    \\item $a / b \\wedge a / c \\rightarrow a / (b + c)$\n    \\item $a/ b \\wedge b / c \\rightarrow a / c $\n    \\item $\\gcd(a, b) = am + bn$, for some $m, n \\in \\mathbb{Z}$\n        (\\textbf{Bezout's Identity})\n    \\item $\\gcd(a, b) \\times \\mathrm{lcm}(a, b) = a \\times b$\n    \\item $a \\equiv b[m] \\wedge c \\equiv d[m] \\rightarrow (a + b) \\equiv (c +\n        d)[m]$\n    \\item $a \\equiv b[m] \\wedge c \\equiv d[m] \\rightarrow (ab) \\equiv\n        (cd)[m]$\n    \\item If \\emph{p} is a prime number, then $a^{p} \\equiv a[p]$\n        (\\textbf{Fermat's Little Theorem})\n    \\item If \\emph{p} is a prime number and $p / ab$, then $p / a \\vee p / b$\n        (\\textbf{Euclid's Identity})\n\\end{symbollist}\n\n\\subsection{Counting}\n\\begin{symbollist}\n    \\item $\\mid A \\cup B \\mid$ =  $\\mid A \\mid + \\mid B \\mid - \\mid A \\cap B\n        \\mid$\n    \\item $P(n,r) \\frac{n!}{(n - r)!}$ (\\textbf{Permutations})\n    \\item $C(n,r)$ or $\\binom{n}{r}$ = $\\frac{n!}{r!(n - r)!}$\n        (\\textbf{Combinations})\n\\end{symbollist}\n", "meta": {"hexsha": "436fc28ec08b91669f9bef0674dc6a143f9c6cb0", "size": 6308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ECS 20 Study Guide/Symbols.tex", "max_stars_repo_name": "UC-Davis-CS-Tutoring/Study-Guides", "max_stars_repo_head_hexsha": "3123a6e883b7379c865df9287da2b969e7af20bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ECS 20 Study Guide/Symbols.tex", "max_issues_repo_name": "UC-Davis-CS-Tutoring/Study-Guides", "max_issues_repo_head_hexsha": "3123a6e883b7379c865df9287da2b969e7af20bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2018-12-19T03:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-30T05:45:28.000Z", "max_forks_repo_path": "ECS 20 Study Guide/Symbols.tex", "max_forks_repo_name": "UC-Davis-CS-Tutoring/Study-Guides", "max_forks_repo_head_hexsha": "3123a6e883b7379c865df9287da2b969e7af20bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-06-19T01:54:16.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-19T01:54:16.000Z", "avg_line_length": 40.178343949, "max_line_length": 83, "alphanum_fraction": 0.5818008878, "num_tokens": 2364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741268224333, "lm_q2_score": 0.8740772236840656, "lm_q1q2_score": 0.8326233481262255}}
{"text": "\n\\subsection{Jacobian matrix}\n\nIf we have \\(n\\) inputs and \\(m\\) functions such that:\n\n\\(f_i(\\mathbf x)\\)\n\nThe Jacobian is a matrix where:\n\n\\(J_{ij}= \\dfrac{\\delta f_i}{\\delta x_j}\\)\n\n", "meta": {"hexsha": "42a01d5b7397035781d4f94685313be74cc416e0", "size": 184, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/multiCalculus/01-01-jacobian.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/multiCalculus/01-01-jacobian.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/multiCalculus/01-01-jacobian.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.3333333333, "max_line_length": 54, "alphanum_fraction": 0.652173913, "num_tokens": 59, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104924150546, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.8325995703641933}}
{"text": "\n\\subsection{Moments}\n\n\\subsubsection{Moments}\n\nThe \\(n\\)th moment of variable \\(X\\) is defined as:\n\n\\(E[X^n]=\\sum_i x_i^n P(x_i)\\)\n\nThe mean is the first moment.\n\n\\subsubsection{Central moments}\n\nThe \\(n\\)th central moment of variable \\(X\\) is defined as:\n\n\\(\\mu_n=E[(X-E[X])^n]=\\sum_i (x_i-E[X])^n P(x_i)\\)\n\nThe variance is the second central moment.\n\n\\subsubsection{Standardised moments}\n\nThe \\(n\\)th standardised moment of variable \\(X\\) is defined as:\n\n\\(\\dfrac{E[(X-E[X])^n]}{(E[(X-E[X])^2]^\\frac{n}{2}}=\\dfrac{\\mu_n}{\\sigma^n}\\)\n\n\\subsubsection{Kertosis}\n\nKertosis is the third standardised moment.\n\n\\subsubsection{Skew}\n\nSkew is the fourth standardised moment.\n\n", "meta": {"hexsha": "fae7426a29ab76ee90363a14a0ffc0dece4d5fed", "size": 670, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityMomentsHigher/01-01-singleMoments.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/probabilityMomentsHigher/01-01-singleMoments.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/probabilityMomentsHigher/01-01-singleMoments.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.7058823529, "max_line_length": 77, "alphanum_fraction": 0.6835820896, "num_tokens": 213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9728307668889047, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.8325983222816807}}
{"text": "\\chapter{Sequences and Series}\n\\section{Sequences and Series}\nAn infinite sequence is the sequence whose domain lines is defined on all\n$x\\in(0,\\infty)$.  It is defined as follows:\n\\begin{equation}\na_1,a_2,a_3,...,a_n,...\n\\end{equation}\n\nIf the sequence were to only contain the first $n$ terms, it would be a\n\\textit{finite sequence}.\n\n\\section{Summation Notation}\nTo define the series that we expressed above, we can use a notation known as\n\"summation notation\", which involves the use of the Greek letter\n\\textit{sigma}.  Let's define the sequence that we did earlier, this time using\nsummation notation:\n\n\\begin{equation}\n\\sum_{i=1}^na_i=a_1+a_2+a_3+a_4+...+a_n+...\n\\end{equation}\n\n\\subsection{Properties of Sums}\n\\begin{equation}\n\\sum_{i=1}^nc=cn\n\\end{equation}\n\n\\begin{equation}\n\\sum_{i=1}^nca_i=c\\sum_{i=1}^{n}a_i\n\\end{equation}\n\n\\begin{equation}\n\\sum_{i=1}^{n}(a_i \\pm b_i)=\\sum_{i=1}^{n}a_i\\pm\\sum_{i=1}^{n}b_i\n\\end{equation}\n\n\\subsection{A Distinction}\nThere is an important distinction to be made: The first $n$ terms of any\nsequence is referred to as the finite series, or a partial sum of teh entier\nsequence, and is denoted by the following expression:\n\\begin{equation}\n\\sum_{i=1}^{n}a_i=a_1+a_2+a_3+a_4+...+a_n\n\\end{equation}\n\nHowever, the infinite sries is all of the terms in an infinite sequence, and is\nexpressed by the following:\n\\begin{equation}\n\\sum_{i=1}^{\\infty}a_i=a_1+a_2+a_3+a_4+...+a_n+...\n\\end{equation}\n\nConsider the following two examples.  The first is a partial sum, and the second\nis the sum of a series:\n\\begin{align*}\n\\sum_{i=1}^{3}\\frac{3}{10^i}=\\frac{3}{10^1}+\\frac{3}{10^2}+\\frac{3}{10^3}\\\\\n=\\frac{3}{10}+\\frac{3}{100}+\\frac{3}{1000}\\\\\n=0.3+0.03+0.003\\\\\n=0.333\n\\end{align*}\n\n\\begin{align*}\n\\sum_{i=1}^{\\infty}\\frac{3}{10^i}=\\frac{3}{10^1}+\\frac{3}{10^2}+\\frac{3}{10^3}+...\n\\\\\n=\\frac{3}{10}+\\frac{3}{10}+\\frac{3}{100}+...\\\\\n=0.3+0.03+0.003+...\\\\\n=0.333...\n=\\frac{1}{3}.\n\\end{align*}\n\n\\section{Arithmetic Sequences}\nAn arithmetic sequence is one where the differences between consecutive terms\nare the same.  The sequence takes the following progression:\n\\begin{equation}\n  a_1,a_1+d,a_1+2d,a_1+3d...\n\\end{equation}\n\n\\subsection{$n$-th term}\nTherefore, the formula for the $n$th term is:\n\\begin{equation}\n  a_1+(n-1)d\n\\end{equation}\n\n\\subsection{$n$-th partial sum}\nTo calculuate the $n$-th partial sum of the series, use the following formula:\n\\begin{equation}\n  S_n=\\frac{n}{2}(a_1+a_n)\n\\end{equation}\n\n\\section{Geometric Sequences}\nA series is geometric when each consecutive is related by a ratio to the\nprevious term.  Consider the following example:\n\\begin{equation}\n  a_1,a_1r,a_1r^2,...,a_1r^{n-1}\n\\end{equation}\n\n\\subsection{$n$-th term}\nTherefore, the $n$-th term is defined as follows:\n\\begin{equation}\n  a_n=a_1r^{n-1}\n\\end{equation}\n\n\\subsection{Summations of Finite Series}\nThe sum of a finite geometric series is given as follows:\n\\begin{equation}\n  S_n=\\sum_{i=1}^{n}a_1r^{i-1}=a_1\\Big(\\frac{1-r^n}{1-r}\\Big)\n\\end{equation}\n\n\\subsection{Summations of Infinite Series}\nThe sum of an infinite geometric series is given as follows:\n\\begin{equation}\n  S=\\sum_{i=1}^{\\infty}a_1r^i=\\frac{a_1}{1-r}\n\\end{equation}\n", "meta": {"hexsha": "01c7afd202b0f5ffac9943850a98bf380c4bcff8", "size": 3160, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pre_calculus_h/chapters/7_sequences_series.tex", "max_stars_repo_name": "ttaylorr/finals", "max_stars_repo_head_hexsha": "41f6a03e4a082768c10b9a77a0e042cfce2a6d7f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pre_calculus_h/chapters/7_sequences_series.tex", "max_issues_repo_name": "ttaylorr/finals", "max_issues_repo_head_hexsha": "41f6a03e4a082768c10b9a77a0e042cfce2a6d7f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pre_calculus_h/chapters/7_sequences_series.tex", "max_forks_repo_name": "ttaylorr/finals", "max_forks_repo_head_hexsha": "41f6a03e4a082768c10b9a77a0e042cfce2a6d7f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.7272727273, "max_line_length": 82, "alphanum_fraction": 0.7091772152, "num_tokens": 1157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8947894668039496, "lm_q1q2_score": 0.8325642497679511}}
{"text": "\\section{Application: Dynamical systems}\n\nThe migration matrices discussed above give an example of a discrete\ndynamical system. We call them discrete because they involve discrete\nvalues taken at a sequence of points rather than on a continuous\ninterval of time.\n\nAn example of a situation which can be studied in this way is a\npredator prey model. Consider the following model where $x$ is the\nnumber of prey and $y$ the number of predators in a certain area at a\ncertain time. These are functions of $n\\in \\N$ where $n=1,2,\\ldots$\nare the ends of intervals of time which may be of interest in the\nproblem. In other words, $x (n)$ is the number of prey at the end of\nthe $n\\th$ interval of time.  An example of this situation may be\nmodelled by the following equation\n\\begin{equation*}\n  \\begin{mymatrix}{c}\n    x(n+1) \\\\\n    y(n+1)\n  \\end{mymatrix} =\\begin{mymatrix}{rr}\n    2 & -3 \\\\\n    1 & 4\n  \\end{mymatrix} \\begin{mymatrix}{c}\n    x(n) \\\\\n    y(n)\n  \\end{mymatrix}.\n\\end{equation*}\nThis says that from time period $n$ to $n+1$, $x$ increases if there\nare more $x$ and decreases as there are more $y$. In the context of\nthis example, this means that as the number of predators increases,\nthe number of prey decreases. As for $y$, it increases if there are\nmore $y$ and also if there are more $x$.\n\nThis is an example of a matrix recurrence which we define now.\n\n\\begin{definition}{Matrix recurrence}{matrix-recurrence}\n  Suppose a dynamical system is given by\n  \\begin{eqnarray*}\n    x_{n+1} &=& a x_n + b y_n \\\\\n    y_{n+1} &=& c x_n + d y_n\n  \\end{eqnarray*}\n  This system can be expressed as $V_{n+1} = A V_{n}$ where\n  $V_{n} = \\begin{mymatrix}{r}\n    x_n \\\\\n    y_n\n  \\end{mymatrix}$ and $A = \\begin{mymatrix}{rr}\n    a & b \\\\\n    c & d\n  \\end{mymatrix}$.\n\\end{definition}\n\nIn this section, we will examine how to find solutions to a dynamical\nsystem given certain initial conditions. This process involves several\nconcepts previously studied, including matrix diagonalization and\nMarkov matrices. The procedure is given as follows. Recall that when\ndiagonalized, we can write $A^{n} = PD^{n}P^{-1}$.\n\n\\begin{procedure}{Solving a dynamical system}{solving-dynamical}\n  Suppose a dynamical system is given by\n  \\begin{eqnarray*}\n    x_{n+1} &=& a x_n + b y_n \\\\\n    y_{n+1} &=& c x_n + d y_n\n  \\end{eqnarray*}\n  Given initial conditions $x_0$ and $y_0$, the solutions to the\n  system are found as follows:\n  \\begin{enumerate}\n  \\item Express the dynamical system in the form $V_{n+1} = AV_n$.\n  \\item Diagonalize $A$ to be written as $A = PDP^{-1}$.\n  \\item Then $V_{n} = PD^{n} P^{-1} V_{0}$ where $V_{0}$ is the vector\n    containing the initial conditions.\n  \\item If given specific values for $n$, substitute into this\n    equation. Otherwise, find a general solution for $n$.\n  \\end{enumerate}\n\\end{procedure}\n\nWe will now consider an example in detail.\n\n\\begin{example}{Solutions of a discrete dynamical system}{solutions-dynamical-system}\n  Suppose a dynamical system is given by\n  \\begin{eqnarray*}\n    x_{n+1} &=& 1.5 x_n - 0.5y_n\\\\\n    y_{n+1} &=& 1.0 x_n\n  \\end{eqnarray*}\n\n  Express this system as a matrix recurrence and find solutions to the\n  dynamical system for initial conditions $x_0=20, y_0=10$.\n\\end{example}\n\n\\begin{solution}\n  First, we express the system as a matrix recurrence.\n  \\begin{eqnarray*}\n    V_{n+1} &=& AV_{n}\\\\\n    \\begin{mymatrix}{c}\n      x(n+1) \\\\\n      y(n+1)\n    \\end{mymatrix} &=&\\begin{mymatrix}{rr}\n      1.5 & -0.5 \\\\\n      1.0 & 0\n    \\end{mymatrix} \\begin{mymatrix}{c}\n      x(n) \\\\\n      y(n)\n    \\end{mymatrix}.\n  \\end{eqnarray*}\n  Then\n  \\begin{equation*}\n    A\n    =\n    \\begin{mymatrix}{rr}\n      1.5 & -0.5 \\\\\n      1.0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  You can verify that the eigenvalues of $A$ are $1$ and $0.5$. By\n  diagonalizing, we can write $A$ in the form\n  \\begin{equation*}\n    P^{-1} D P =\n    \\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      1 & 2\n    \\end{mymatrix} \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 0.5\n    \\end{mymatrix} \\begin{mymatrix}{rr}\n      2 & -1 \\\\\n      -1 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  Now given an initial condition\n  \\begin{equation*}\n    V_0 = \\begin{mymatrix}{c}\n      x_{0} \\\\\n      y_{0}\n    \\end{mymatrix},\n  \\end{equation*}\n  the solution to the dynamical system is given by\n  \\begin{eqnarray*}\n    V_n &=& P D^n P^{-1} V_0\\\\\n    \\begin{mymatrix}{c}\n      x(n) \\\\\n      y(n)\n    \\end{mymatrix} &=&\\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      1 & 2\n    \\end{mymatrix} \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 0.5\n    \\end{mymatrix} ^{n}\\begin{mymatrix}{rr}\n      2 & -1 \\\\\n      -1 & 1\n    \\end{mymatrix} \\begin{mymatrix}{c}\n      x_{0} \\\\\n      y_{0}\n    \\end{mymatrix} \\\\\n        &=& \\begin{mymatrix}{rr}\n          1 & 1 \\\\\n          1 & 2\n        \\end{mymatrix} \\begin{mymatrix}{rr}\n          1 & 0 \\\\\n          0 & (0.5) ^{n}\n        \\end{mymatrix} \\begin{mymatrix}{rr}\n          2 & -1 \\\\\n          -1 & 1\n        \\end{mymatrix} \\begin{mymatrix}{c}\n          x_{0} \\\\\n          y_{0}\n        \\end{mymatrix} \\\\\n        &=&\\begin{mymatrix}{c}\n          y_{0}((0.5) ^{n}-1) -x_{0}((0.5)\n          ^{n}-2) \\\\\n          y_{0}(2(0.5) ^{n}-1) -x_{0}(2(0.5)\n          ^{n}-2)\n        \\end{mymatrix}.\n  \\end{eqnarray*}\n  If we let $n$ become arbitrarily large, this vector approaches\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      2x_{0}-y_{0} \\\\\n      2x_{0}-y_{0}\n    \\end{mymatrix}.\n  \\end{equation*}\n  Thus for large $n$,\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      x(n) \\\\\n      y(n)\n    \\end{mymatrix} \\approx \\begin{mymatrix}{c}\n      2x_{0}-y_{0} \\\\\n      2x_{0}-y_{0}\n    \\end{mymatrix}.\n  \\end{equation*}\n  Now suppose the initial condition is given by\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      x_{0} \\\\\n      y_{0}\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r}\n      20 \\\\\n      10\n    \\end{mymatrix}.\n  \\end{equation*}\n  Then, we can find solutions for various values of $n$. Here are the\n  solutions for values of $n$ between $1$ and $5$:\n  \\begin{equation*}\n    n=1:\n    \\begin{mymatrix}{r}\n      25.0 \\\\\n      20.0\n    \\end{mymatrix},\n    n=2: \\begin{mymatrix}{r}\n      27.5 \\\\\n      25.0\n    \\end{mymatrix},\n    n=3: \\begin{mymatrix}{r}\n      28.75 \\\\\n      27.5\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{equation*}\n    n=4: \\begin{mymatrix}{r}\n      29.375 \\\\\n      28.75\n    \\end{mymatrix},\n    n=5: \\begin{mymatrix}{r}\n      29.688 \\\\\n      29.375\n    \\end{mymatrix}.\n  \\end{equation*}\n  Notice that as $n$ increases, we approach the vector given by\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      2x_{0}-y_{0} \\\\\n      2x_{0}-y_{0}\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r}\n      2(20)- 10\\\\\n      2(20)-10\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r}\n      30\\\\\n      30\n    \\end{mymatrix}.\n  \\end{equation*}\n  These solutions are graphed in the following figure.\n  \\begin{center}\n    \\begin{tikzpicture}[font=\\small]\n      \\draw[<->](0,2) --(0,0)--(2,0);\n      \\draw (0.5, -0.05)--(0.5,0.05);\n      \\draw (1, -0.05)--(1,0.05);\n      \\draw (1.5, -0.05)--(1.5,0.05);\n      \\draw (-0.05, 0.5)--(0.05,0.5);\n      \\draw (-0.05, 1)--(0.05,1);\n      \\draw (-0.05, 1.5)--(0.05,1.5);\n      \\draw[fill] (0.8,0.75) circle [radius=0.025];\n      \\draw[fill] (1.2,1.3) circle [radius=0.025];\n      \\draw[fill] (1.45,1.6) circle [radius=0.025];\n      \\node[right] at (2,0){x};\n      \\node[right] at (0,2){y};\n      \\node[below] at (0.5,0){$28$};\n      \\node[below] at (1,0){$29$};\n      \\node[below] at (1.5,0){$30$};\n      \\node[left] at (0,0.5){$27$};\n      \\node[left] at (0,1){$28$};\n      \\node[left] at (0,1.5){$29$};\n    \\end{tikzpicture}\n  \\end{center}\n\\end{solution}\n\nThe following example demonstrates another system which exhibits some\ninteresting behavior. When we graph the solutions, it is possible for\nthe ordered pairs to spiral around the origin.\n\n\\begin{example}{Finding solutions to a dynamical system}{find-solutions-dynamical-system}\n  Suppose a dynamical system is of the form\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      x(n+1) \\\\\n      y(n+1)\n    \\end{mymatrix} =\\begin{mymatrix}{rr}\n      0.7 & 0.7 \\\\\n      -0.7 & 0.7\n    \\end{mymatrix} \\begin{mymatrix}{c}\n      x(n) \\\\\n      y(n)\n    \\end{mymatrix}.\n  \\end{equation*}\n  Find solutions to the dynamical system for given initial conditions.\n\\end{example}\n\n\\begin{solution}\n  Let\n  \\begin{equation*}\n    A\n    =\n    \\begin{mymatrix}{rr}\n      0.7 & 0.7 \\\\\n      -0.7 & 0.7\n    \\end{mymatrix}.\n  \\end{equation*}\n  To find solutions, we must diagonalize $A$. You can verify that the\n  eigenvalues of $A$ are complex and are given by\n  $\\eigenvar_1 = 0.7+0.7i$ and $\\eigenvar_2 = 0.7-0.7i$. The eigenvector\n  for $\\eigenvar_1 = 0.7+0.7i$ is\n  \\begin{equation*}\n    \\begin{mymatrix}{r}\n      1 \\\\\n      i\n    \\end{mymatrix}\n  \\end{equation*}\n  and that the eigenvector for $\\eigenvar_2 = 0.7-0.7i$ is\n  \\begin{equation*}\n    \\begin{mymatrix}{r}\n      1 \\\\\n      -i\n    \\end{mymatrix}.\n  \\end{equation*}\n  Thus the matrix $A$ can be written in the form\n  \\begin{equation*}\n    \\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      i & -i\n    \\end{mymatrix} \\begin{mymatrix}{cc}\n      0.7+0.7i & 0 \\\\\n      0 & 0.7-0.7i\n    \\end{mymatrix} \\begin{mymatrix}{rr}\n      \\frac{1}{2} & -\\frac{1}{2}i \\\\\n      \\frac{1}{2} & \\frac{1}{2}i\n    \\end{mymatrix},\n  \\end{equation*}\n  and so\n  \\begin{eqnarray*}\n    V_n &=& PD^nP^{-1}V_0 \\\\\n    \\begin{mymatrix}{c}\n      x(n) \\\\\n      y(n)\n    \\end{mymatrix} &=&\\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      i & -i\n    \\end{mymatrix} \\begin{mymatrix}{cc}\n      (0.7+0.7i) ^{n} & 0 \\\\\n      0 & (0.7-0.7i) ^{n}\n    \\end{mymatrix} \\begin{mymatrix}{rr}\n      \\frac{1}{2} & -\\frac{1}{2}i \\\\\n      \\frac{1}{2} & \\frac{1}{2}i\n    \\end{mymatrix} \\begin{mymatrix}{c}\n      x_{0} \\\\\n      y_{0}\n    \\end{mymatrix}.\n  \\end{eqnarray*}\n  The explicit solution is given by\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      x_{0}(\\frac{1}{2}(0.7-0.7i) ^{n}+\\frac{1}{2}\n      (0.7+0.7i) ^{n}) + \\allowbreak y_{0}(\\frac{1}{2}\n      i(0.7-0.7i) ^{n}-\\frac{1}{2}i (\n      0.7+0.7i)  ^{n}) \\\\\n      y_{0}(\\frac{1}{2} (0.7-0.7i) ^{n}+\\frac{1}{2}\n      (0.7+0.7i) ^{n}) -  x_{0}(\\frac{1}{2}\n      i(0.7-0.7i) ^{n}-\\frac{1}{2}i(\n      0.7+0.7i) ^{n})\n    \\end{mymatrix}.\n  \\end{equation*}\n  Suppose the initial condition is\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      x_{0} \\\\\n      y_{0}\n    \\end{mymatrix} =\\begin{mymatrix}{r}\n      10 \\\\\n      10\n    \\end{mymatrix}.\n  \\end{equation*}\n  Then one obtains the following sequence of values which are graphed\n  below by letting $n=1,2,\\ldots,20$\n\n  \\begin{center}\n    \\includegraphics[bb=0 0 800 800,scale=.2]{figures/4dec.eps}\n  \\end{center}\n\n  In this picture, the dots are the values and the dashed line is to\n  help to picture what is happening.\n\n  These points are getting gradually closer to the origin, but they\n  are circling the origin in the clockwise direction as they do so. As\n  $n$ increases, the vector $\\begin{mymatrix}{c}\n    x(n) \\\\\n    y(n)\n  \\end{mymatrix}$ approaches $ \\begin{mymatrix}{r}\n    0 \\\\\n    0\n  \\end{mymatrix}$.\n\\end{solution}\n\n", "meta": {"hexsha": "273f64e30cc5a75c972950da82039ccfdfc9aa78", "size": 11057, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryApplicationsDiagonalizationDynamicalSystems.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/spectraltheoryApplicationsDiagonalizationDynamicalSystems.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/spectraltheoryApplicationsDiagonalizationDynamicalSystems.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 27.8513853904, "max_line_length": 89, "alphanum_fraction": 0.5791806096, "num_tokens": 4242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582574225518, "lm_q2_score": 0.8947894541786198, "lm_q1q2_score": 0.8325642362951149}}
{"text": "\\lab{Python}{Symbolic Computation in Python}{SymPy}\n\\label{lab:SymPy}\n\n\\objective{Become familiar with some of the basic tools available in SymPy}\n\nPython is good for more than just analysis of numerical data.\nThere are several packages available which allow symbolic computation in Python.\nOne such package is SymPy.\nSymPy is designed to be a fully featured computer algebra system in Python.\nIt is actually used for much of the symbolic computation in Sage.\nAn example of what we mean by \"symbolic computation\" is the following:\n\\begin{lstlisting}\nimport sympy as sy\nx = sy.symbols(`x')\nsy.expand((x+1)**10)\n\\end{lstlisting}\nwhich will return the following:\n\\begin{lstlisting}\nx**10 + 10*x**9 + 45*x**8 + 120*x**7 + 210*x**6 + 252*x**5 + 210*x**4 + 120*x**3 + 45*x**2 + 10*x + 1\n\\end{lstlisting}\nWhen used properly, this package can simplify large amounts of algebra for you.\nThis can be incredibly useful in a wide variety of situations.\nAs you may have guessed, such packages generally have a wide variety of features. \nIf you want to know how to do something, consider checking the documentation  at the SymPy website (\\url{http://sympy.org/en/index.html}).\nThis lab should teach you to do some basic symbolic manipulations in SymPy, but keep in mind that this introduction is not comprehensive.\n\n\\section*{Basic Number Types}\nSymPy has some good built in datatypes which can be used to represent rational numbers and arbitrary precision floating point numbers.\nArbitrary precision floating point operations are supported through the package \\li{mpmath}.\nThese can be useful if you need to do computation to a very high precision, or to avoid possible overflow error in computation.\nThey are, however, much more costly to compute.\n\nYou can declare a rational number $\\frac{a}{b}$ using \\li{sy.Rational(a, b)}.\nA real number $r$ of precision $n$ can be declared using $sy.Float(r,n)$.\n\nA nice example of the use of these datatypes is the following function which computes $\\pi$ to the $n$th digit.\n\\begin{lstlisting}\ndef mypi(n):\n    #calculates pi to n decimal points.\n    tot = sy.Rational(0, 1)\n    term = 1\n    bound = sy.Rational(1, 10)**(n+1)\n    i = 0\n    while bound <= term:\n        term = 6 * sy.Rational(sy.factorial(2*i), 4**i*(sy.factorial(i))**2*(2*i+1)*2**(2*i+1))\n        tot += term\n        i += 1\n    return sy.Float(tot, n)\n\\end{lstlisting}\nThis function works by evaluating the Taylor Series for $6\\arcsin\\left(\\frac{1}{2}\\right)$.\nWe used a rather crude error estimate to ensure that we were close enough to break the loop.\n\n\\begin{problem}\nWrite a function which evaluates $e$ to the $n$th digit.\nUse the series \n\\begin{equation*}\ne=\\sum_{n=0}^{\\infty} \\frac{1}{n!}\n\\end{equation*}\nUse the same condition as above to determine when to break your while loop.\n\\end{problem}\n\n\\section*{Symbolic Manipulation}\nIn SymPy, you need to declare symbolic objects before you use them.\nTo define a symbol $x$, we write \\li{x = sy.symbols(`x')}.\nThis can also be used to define multiple variables at once, as in \\li{x, y, z = sy.symbols(`x,y,z')}.\nThe string form of each variable on the right is used for showing expressions that involve the variable.\nYou will need to be careful about capitalization and that last `s' in the name of the function.\nCalling \\li{sy.Symbol()} will allow you to create a single symbolic variable, but \\li{sy.symbol} is a submodule and cannot be called at all.\n\nSymPy can be used to solve difficult expressions for given variables.\nNot everything can be solved, but SymPy's algorithms are pretty good and can often save a great deal of time.\nWe consider the following equation:\n\\begin{equation*}\n\\frac{w}{w-x}+\\frac{x}{x-y}+\\frac{y}{y-z}+\\frac{z}{z-w}=0\n\\end{equation*}\nSay we need an explicit solution for a given variable. \nSince the expression is symmetrical, it doesn't really matter which one, but we can solve this in the following way:\n\\begin{lstlisting}\nimport sympy as sy\nw, x, y, z = sy.symbols(`w, x, y, z')\nexpr = w/(w-x) + x/(x-y) + y/(y-z) + z/(z-w)\nsy.solve(expr, w)\n\\end{lstlisting}\nIn any variable, this expression is quadratic, but each coefficient will depend on the other 3 variables.\nThis would be a terrible pain to do by hand, but SymPy can take care of that for us.\nIt is worth noting that SymPy cannot do everything, but if we keep in mind what we are doing and are familiar with the tools it has, it can make complex algebraic operations a great deal faster. \nWe should also note that \\li{solve()} returns a list of expressions.\nIf we want an expression to work with, we must take an item from the list.\n\nIn this particular example, you will notice that we only used a symbolic expression and not a full equation.\nWhat SymPy did was set the expression equal to zero, solve for the variable we wanted, then return the result.\nSymPy also supports equation objects (and inequalities), but this approach is often easier.\nIf you need to declare equations, they can be declared using something like \\li{equation = Eq(x,  y)} which represents the equation $x=y$\n\n\\begin{problem}\nUse SymPy to solve the equation $y=e^x+x$ for $x$.\nThe answer will be in terms of the Lambert W function, which is a special function available in most major symbolic math libraries.\nIt is included in both SciPy and SymPy and is defined as the inverse of $y=x e^x$.\n\\end{problem}\n\nSymPy can also be used to expand and simplify different symbolic expressions.\nAs an example we will simplify the expression\n\\begin{equation*}\n\\frac{w x^2 y^2 - w x^2 - w y^2 + w - x^2 y^2 z + 2 x^2 y^2 + x^2 z - 2 x^2 + y^2 z - 2 y^2 - z + 2}{w x y - w x - w y + w - x y z + 2 x y + x z - 2 x + y z - 2 y - z + 2}\n\\end{equation*}\n\\begin{lstlisting}\nw, x, y, z=sy.symbols(`w, x, y, z')\nexpr = (w*x**2*y**2 - w*x**2 - w*y**2 + w - x**2*y**2*z + 2*x**2*y**2 + x**2*z - 2*x**2 + y**2*z - 2*y**2 - z + 2)/(w*x*y - w*x - w*y + w - x*y*z + 2*x*y + x*z - 2*x + y*z - 2*y - z + 2)\nexpr.simplify()\n\\end{lstlisting}\nWhen we evaluate this cell, we can see that the expression simplifies to $x y + x + y +1$.\n\\li{simplify()} is the general simplification method for a SymPy expression.\nIt can be called as a function from the module, i.e. as \\li{sy.simplify()} or it can be used as a method for an object as in the example above.\nYou can also tell SymPy to do more specific types of simplification, for example if you want to factor an expression, you can use \\li{factor()}.\nIf you want to tell it to expand an expression you can use \\li{expand()}, if you want it to focus purely on simplifying the trigonometric aspects of the expression you can use \\li{trigsimp()}.\nIf you want SymPy to cancel variable expressions in the numerator and denominator of all rational sub-expressions, use \\li{cancel()}.\nThere are several other kinds of algebraic manipulations you can do in SymPy, see the documentation for a more comprehensive list.\nMany of these more important functions in SymPy are also available as methods to expressions.\nThis is the case with all of the above examples.\n\nBe sure to be careful when writing out symbolic expressions.\nPython floating point numbers are still floating point numbers and Python integers are still integers.\nA simple example is the expression \\li{(3/4)*sy.sin(x)} which evaluates to 0, and should probably have been written as \\li{3*sy.sin(x)/4} or \\li{sy.Rational(3,4)*sy.sin(x)}.\nBe careful about using floating points as well.\nThe expression \\li{(3./4.)*sy.sin(x)} will evaluate to \\li{.75*sy.sin(x)}, and the floating point calculations will be carry through to the rest of your symbolic work with that expression.\n\nAnother useful feature is substitution.\nSubstitution can be done using the \\li{subs()} method of an expression.\n%As of this writing, there is no subs function, though one has been discussed.\n%I deliberately left the ambiguity here for compatibility with future releases.\nYou can substitute numbers and variables in for variables and even expressions.\nFor example, if you want to see what an expression looks like if $x$ is set to zero, you can use:\n\\begin{lstlisting}\nexpr.subs(x, 0)\n\\end{lstlisting}\nwhere \\li{expr} is the expression you have already defined.\nNote that none of these operations modify the expression in place.\nThey return a modified version of the expression, but do not actually change the original.\n\nSubstitution also can be used (to some extent) to substitute one expression for another .\nFor example, if you want to apply the double angle identity to replace products of sines and cosines, you could use the following:\n\\begin{lstlisting}\nexpr.subs(sy.sin(x) * sy.cos(x), sy.sin(2*x)/2)\n\\end{lstlisting}\nIf you want to eliminate higher powers of a variable in an expression you can use something like:\n\\begin{lstlisting}\nexpr.subs(x**3, 0)\n\\end{lstlisting}\nwhich will eliminate all terms of the expression involving $x^3$.\nAt present time this will not eliminate terms involving $x^4$ or higher powers of $x$ that are not divisible by 3.\n\n\\begin{problem}\nProblems of the following form are useful in proving that finite difference schemes remain bounded as the number of iterations increases.\nThis property is called stability and will be discussed later in Volume 4.\nHere we will just walk you through the symbolic manipulations necessary to show that a scheme is stable.\nConsider the Crank-Nicolson finite difference scheme for the partial differential equation $u_t+a u_x=0$.\n\\begin{equation*}\n\\frac{v_{m}^{n+1}-v_{m}^{n}}{k}+a \\frac{v_{m+1}^{n+1}-v_{m-1}^{n+1}+v_{m+1}^{n}-v_{m-1}^{n}}{4h}=0\n\\end{equation*}\nDue to an important result by Von Neumann, we know that this scheme will be stable if and only if when we make the following substitutions, the absolute value of the amplification factor $g$ is always less than or equal to 1.\nProve that this scheme is stable in the following way:\n\\begin{itemize}\n\\item Substitute $g^a e^{i b \\theta}$ for $v_a^b$.\nNote that when you have solved the expression for $g$, $g$ will be a function of $\\theta$.\nYou are free to assume that $\\theta$, $h$, and $k$ are real.\nYou can tell SymPy that these variables are real by including the argument \\li{real=True} in the \\li{symbols} function when you declare them.\n$g$ may or may not be real, depending on the problem.\n\\li{sy.I} is the imaginary unit $i$.\n\\item Use SymPy to cancel redundant terms, simplify the expression, and solve for $g$.\nSince the whole expression is set to zero, factor it, look at the factors and cancel all you can.\nYou will want to apply Euler's formula before you solve for $g$.\nIn this case we only want to make this particular substitution, so do this using the \\li{subs()} method.\n\\item Once you have an expression for $g$, we may consider $\\abs{g}^2$, which can be found by multiplying $g$ by the complex conjugate of $g$. \nYou can take the conjugate of an expression using the \\li{.conjugate()} method.\nIn this case, $\\abs{g}$ should always be $1$, which shows that this scheme is stable for any $h$ and $k$.\n\\end{itemize}\n\\end{problem}\n\n\\section*{Calculus in SymPy}\nSymPy can also be used to take limits, integrals, and derivatives.\nAgain, this can be very helpful when doing things that would be difficult to do by hand.\nFor example, the following equation takes the 20'th partial derivative with respect to $x$ of \n\\begin{equation*}\n\\prod_{i=1}^{23} \\left(x+i y\\right)\n\\end{equation*}\n\\begin{lstlisting}\nx, y, i = sy.symbols(`x, y, i')\nexpr = sy.product((x+i*y), (i, 1, 23))\nexpr = expr.expand()\nexpr.diff(x, 20)\n\\end{lstlisting}\n\nWe can also integrate difficult things, for example, if we want to integrate $e^x\\sin(x)\\sinh(x)$, this can be done with one line in SymPy.\n\\begin{lstlisting}\nsy.Integral(sy.sin(x) * sy.exp(x) * sy.sinh(x), x).doit()\n\\end{lstlisting}\nNotice the \\li{.doit()} method.\nThis tells SymPy to evaluate all derivatives, integrals, limits, etc. inside the expression.\n\nDerivatives can be taken using the \\li{sy.Derivative()} function, or the \\li{.diff()} method of a SymPy expression.\nAs an example, we will take the 20'th derivative of the Lambert W function we saw earlier.\nThis can be done like this:\n\\begin{lstlisting}\nfrom sympy.functions.elementary.exponential import LambertW\nsy.Derivative(LambertW(x), x, 20).doit()\n\\end{lstlisting}\nor, equivalently, like this:\n\\begin{lstlisting}\nfrom sympy.functions.elementary.exponential import LambertW\nLambertW(x).diff(x, 20).doit()\n\\end{lstlisting}\nthe second argument is the number of derivatives to take.\nIf it is omitted, one derivative will be taken.\nYou can also pass additional variables as arguments, for example, if we want to take $\\frac{\\partial}{\\partial x} \\left( \\frac{\\partial}{\\partial y}\\sin\\left(x y\\right)\\right)$, we can do it in this way:\n\\begin{lstlisting}\nexpr = sy.sin(x*y)\nexpr.diff(x,y)\n\\end{lstlisting}\nThese tricks also work with integrals, with the exception of taking multiple integrals in the same variable.\nYou can integrate two different variables along two different bounds, as in:\n\\begin{lstlisting}\nsy.integrate(y**2*x**2, (x, -1, 1), (y, -1, 1))\n\\end{lstlisting}\nand you can integrate with respect to multiple variables, as in:\n\\begin{lstlisting}\nsy.integrate(y**2 * x**2, x, y)\n\\end{lstlisting}\nBut, as of this writing, you can \\emph{not} do something of the sort:\n\\begin{lstlisting}\nsy.integrate(x**3, x, 20)\n\\end{lstlisting}\nYou would have to do this with some sort of for loop, or, simply by passing 20 $x$'s as arguments to the function.\n\nSymPy also supports numerical integration and differentiation. \nIf you want to evaluate a definite integral, something like this will work.\n\\begin{lstlisting}\nsy.Integral(sy.sin(x)*sy.exp(x)*sy.sinh(x), (x, -1, 1)).doit()\n\\end{lstlisting}\nThis sort of thing will still return a purely symbolic expression, but you can get an actual value for it by either converting it to a SymPy \\li{Float} object, or by using the \\li{sy.N()} function, which numerically evaluates expressions as best as it can.\nSymPy can also evaluate integrals numerically without finding a symbolic solution. That can be done like this:\n\\begin{lstlisting}\nsy.N(sy.Integral(sy.sin(x)*sy.exp(x)*sy.sinh(x), (x, -1, 1)))\n\\end{lstlisting}\nIf for some reason you wanted to evaluate the expression to more digits of precision, you can add the number of significant digits as an argument to \\li{sy.N()}.\n\n\\begin{problem}\nUse SymPy to symbolically evaluate \n\\begin{equation*}\n\\int_0^\\infty \\sin^2 \\left(x\\right) dx\n\\end{equation*}\nIn SymPy, positive infinity is represented by the object \\li{sy.oo}\n\\end{problem}\n\n\\begin{problem}\nUse SymPy to numerically estimate $\\frac{\\partial}{\\partial x}e^{\\sin\\left(\\cos\\left(x\\right)\\right)}$ at $x=1$.\n\\end{problem}\n\nYou can also use SymPy to solve some sorts of basic ordinary differential equations.\nThis will solve the equation $y_{xx}-2*y_x+y=\\sin\\left(x\\right)$\n\\begin{lstlisting}\nx = sy.symbols(`x')\nf = sy.Function(`f')\neq = f(x).diff(x, 2) - 2*f(x).diff(x) + f(x) - sy.sin(x)\nsy.dsolve(eq)\n\\end{lstlisting}\nor, equivalently,\n\\begin{lstlisting}\nx = sy.symbols(`x')\nf = sy.Function(`f')\neq = f(x).diff(x, 2) - 2*f(x).diff(x) + f(x) - sy.sin(x)\nsy.dsolve(eq)\n\\end{lstlisting}\n\\begin{problem}\nUse SymPy to solve the following differential equation:\n\\begin{equation*}\n\\begin{split}\n y_{xxxxxx} & + 3y_{xxxx} + 3y_{xx} + y = \\\\\n& x^{10}e^x + x^{11}\\sin\\left(x\\right) + x^{12}e^x\\sin\\left(x\\right) -x^{13}\\cos\\left(2x\\right) + x^{14}e^x\\cos\\left(3x\\right)\n\\end{split}\n\\end{equation*}\nYou may recall from your last class on differential equations that this sort of problem is solved by the method of undetermined coefficients. \nImagine how terrible this would be to do by hand!\n\\end{problem}\n\nIn addition, SymPy includes several integral transforms, such as the Laplace, Fourier, Sine, and Cosine Transforms.\nSymPy also allows you to do simple separation of variables on PDEs, Taylor Series, Laurent Series, Fourier Series, and many, \\textit{many} other things.\n\n\\section*{Interfacing With Numerical Software}\nSymPy also has a variety of built in ways to take an expression and turn it into a python function that can be evaluated quickly.\nYou can numerically evaluate expressions using \\li{subs} to substitute in values like you would symbols, but this can be slow for large arrays.\nA simple way to evaluate an expression more quickly is the \\li{lambdify} function in \\li{sympy.utilities.lambdify}.\nIt takes an expression and makes it into a callable python function. \nIt allows you to specify which library to use to compute the function, so if you would like to operate on arrays, you can use NumPy functions for $\\sin$, $\\cos$, etc.\nIt also allows you to tell it to use functions from the math library, SymPy itself, and mpmath.\nWe can take an expression in $x$ and $y$ and make a corresponding python function \\li{fc} which uses NumPy as its backend in the following way:\n\\begin{lstlisting}\nimport sympy as sy\nfrom sympy.utilities.lambdify import lambdify\nimport numpy as np\nx, y = sy.symbols(`x, y')\nexpr = sy.sin(x) * sy.exp(x) - sy.cosh(x)\nfc = lambdify([x, y], expr, `numpy')\n\\end{lstlisting}\nThis interoperability allows us to move quickly between symbolic calculations in SymPy and faster numerical evaluation on arrays in NumPy.\n\nSymPy also has built in ways that allow you to make functions that iterate over arrays using F2PY, Cython, or Theano.\nUsing these other libraries can result in very fast numerical evaluation of symbolic expressions with relatively little effort.\nThese automatic wrapping features depend on other libraries and may require some setup.\n\n\\begin{problem}\nUse the \\li{lambdify} function to make a NumPy-dependent function for your solution to the previous problem. Set all the constants that would come from the initial conditions equal to 1.\nThe solution to the differential equation is an equality, but you can get the right hand side of the equality using \\li{expr.rhs}.\nUse the function you have just defined to plot the solution from -3 to 3. \nIt should be very large, and should look kind of like a sine curve.\n\\end{problem}\n\nSympy also includes a simplified plotting wrapper around Matplotlib.\nA simple example is:\n\\begin{lstlisting}\nx = sy.symbols(`x')\nexpr = sy.sin(x)*sy.exp(x)\nsy.plot(expr, (x, -3, 3))\n\\end{lstlisting}\nwhich will plots $\\sin\\left(x\\right) e^x$ for values of $x$ from -3 to 3.\n\nIt is also worth noting that SymPy has several nice options for printing equations.\nIf you want to get a rough idea of what the equation looks like, you can use \\li{sy.pprint()}.\nIt can interface with IPython to display the formula more clearly as well.\nIf you are using IPython, you can enable pretty printing by loading the extension that comes with SymPy.\nIn SymPy 7.2 this is done like this:\n\\begin{lstlisting}\n%load_ext sympy.interactive.ipythonprinting\n\\end{lstlisting}\nIn SymPy 7.3 it is:\n\\begin{lstlisting}\nimport sympy as sy\nsy.init_printing()\n\\end{lstlisting}\nIf you need to write the formula in \\LaTeX, the function \\li{sy.latex()} will convert it to \\LaTeX{} for you.\nSymPy has many more useful features.\nWhen in doubt, take a look at the SymPy documentation.", "meta": {"hexsha": "13aecb52008bcca425acee0bff311d2f9a0fbc0c", "size": 18973, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/sympy/sympylab.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Python/sympy/sympylab.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Python/sympy/sympylab.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.6392961877, "max_line_length": 256, "alphanum_fraction": 0.7441627576, "num_tokens": 5184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765328159727, "lm_q2_score": 0.9111797051879431, "lm_q1q2_score": 0.8325235138084001}}
{"text": "\\section{Differential Equations}\r\nDifferential equations are equations, or sometimes systems of equations where we are given how a function relates to its derivatives and would like to find satisfying functions or families of functions.\r\nDifferential equations land themselves well to modeling real-world phenomena and are still an area of active mathematical study.\r\nWe'll see some very basic differential equations and how what we've learned about integrals can be used to solve them.\r\n\r\n\\subsection{Separable Differential Equations}\r\nIf we can break up a first-order (just involving a first derivative) ordinary differential equation into the following form,\r\n\\begin{equation*}\r\n\t\\dd{y}{x} = f(x)g(y)\r\n\\end{equation*}\r\nthen we say the differential equation is separable and may be able to be solved using a technique called separation of variables.\r\nThe steps to solve a separable differential equation are:\r\n\\begin{enumerate}\r\n\t\\item Write the equation in differential form (i.e using $\\dd{y}{x}$)\r\n\t\\item Separate the variables ($\\frac{\\d{y}}{g(y)}=f(x)\\d{x}$)\r\n\t\\item Integrate both sides\r\n\t\\item Solve for $y$ in terms of $x$, if possible\r\n\t\\item Find the general solution\r\n\t\\item Find a particular solution, given any initial conditions\r\n\\end{enumerate}\r\n\r\n\\begin{example}\r\n\tSolve the following differential equation.\r\n\t\\begin{equation*}\r\n\t\t\\dd{y}{x} = (xy)^2, y(1)=1.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tSeparating and integrating,\r\n\t\\begin{align*}\r\n\t\t\\dd{y}{x} &= (xy)^2 = x^2y^2 \\\\\r\n\t\t\\frac{\\d{y}}{y^2} &= x^2\\d{x} \\\\\r\n\t\t\\frac{1}{y} &= \\frac{x^3}{3} + C. \\\\\r\n\t\\end{align*}\r\n\t\r\n\tSolving for $C$,\r\n\t\\begin{align*}\r\n\t\t\\frac{-1}{1} &= \\frac{1^3}{3} + C \\\\\r\n\t\tC &= \\frac{-4}{3}.\r\n\t\\end{align*}\r\n\t\r\n\tSolving for $y$,\r\n\t\\begin{align*}\r\n\t\t\\frac{-1}{y} &= \\frac{x^3}{3} - \\frac{4}{3} \\\\\r\n\t\ty &= \\frac{-3}{x^3 - 4}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Exponential Growth \\& Decay}\r\nWe can use differential equations to model growth and decay.\r\n\r\n\\begin{example}\r\n\tImagine we have some money in a bank account earning interest.\r\n\tThe more money in the bank, the more the more the account will receive in interest.\r\n\tSo, the rate of growth of the account value is proportional to the current account value.\r\n\tIn the language of differential equations,\r\n\t\\begin{equation*}\r\n\t\t\\dd{y}{t} = ky.\r\n\t\\end{equation*}\r\n\twhere $k$ is some constant of proportionality.\r\n\\end{example}\r\n\\begin{answer}\r\n\tThis equation is separable, so we'll try to solve it using separation of variables.\r\n\t\\begin{align*}\r\n\t\t\\frac{\\d{y}}{t} &= k\\d{x} \\\\\r\n\t\t\\ln{\\abs{y}} &= kt + C \\\\\r\n\t\t\\abs{y} &= Ce^{kt} \\\\\r\n\t\ty &= Ce^{kt} \\\\\r\n\t\ty(0) &= Ce^{k\\cdot 0} = C \\\\\r\n\t\ty &= y_0e^{kt}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\nThis is exactly the equation for continually compounding interest: $y_0$ is the principle and $k$ is an interest rate.\r\n\r\n\r\nNote that $k$ could theoretically be negative, meaning the amount would decrease proportionally to the remaining amount.\r\n\\begin{example}\r\n\tThe half-life of Pu-239 is 24360 years.\r\n\tSuppose that 10g of Pu-239 were released in a nuclear accident, how long would it take to decay to 1g?\r\n\\end{example}\r\n\\begin{answer}\r\n\tOur \"principle\" is 10g.\r\n\tWe know that half-life follows the exponential decay differential equation, so it's modeled by $y = 10e^{kt}$.\r\n\tWe also know that $y(24360)=5$, which should give us enough information to solve for $k$.\r\n\t\\begin{align*}\r\n\t\t5 &= 10e^{k\\cdot 24360} \\\\\r\n\t\t\\frac{1}{2} &= e^{k\\cdot 24360} \\text{ (see the ``half\" in half-life?)} \\\\\r\n\t\t\\ln{\\frac{1}{2}} &= 24360k \\\\\r\n\t\t-\\ln{2} &= 24360k \\\\\r\n\t\tk &= \\frac{-\\ln{2}}{24360}. \r\n\t\\end{align*}\r\n\t\r\n\tWe now can plug $k$ back into our equation to get the full model.\r\n\t\\begin{align*}\r\n\t\ty &= 10e^{\\frac{-\\ln{2}}{24360}t} \\\\\r\n\t\t&= 10\\left(e^{\\ln{2}}\\right)^{\\frac{-t}{24360}} \\\\\r\n\t\t&= 10\\cdot2^{-\\frac{-t}{24360}}.\r\n\t\\end{align*}\r\n\t\r\n\tWe can now plug in 1 for $y$ and solve for $t$\r\n\t\\begin{align*}\r\n\t\t1 &= 10\\cdot2^{-\\frac{t}{24360}} \\\\\r\n\t\t\\frac{1}{10} &= 2^{-\\frac{t}{24360}} \\\\\r\n\t\t\\log_{2}{\\frac{1}{10}} &= -\\frac{t}{24360} \\\\\r\n\t\t\\log_{2}{10} &= \\frac{t}{24360} \\\\\r\n\t\tt &= 24360\\log_{2}{10} \\approx 80922\\text{yr}.\r\n\t\\end{align*}\r\n\t\r\n\tIf you're familiar with half-life equations, this is exactly $t=t_{1/2}\\log_{2}{\\frac{N_0}{N_f}}$.\r\n\\end{answer}\r\n\r\n\\subsubsection{Logistic Growth \\& Decay}\r\nAlthough our differential equations assuming that growth is proportional to amount work well for things like bank accounts, bacteria or radioactive particles that can grow and decay without limits, that model is a little too simplistic to model populations that are limited by resources.\r\n\r\n\\begin{example}\r\n\tImagine that we have a population of animals in a forest.\r\n\tIf the forest has lots of resources to support to animal population, then they can grow basically like normal.\r\n\tHowever, as the population grows, resources become more scarce, so population growth would slow down, or some of the population would starve.\r\n\tWe can model this with the following differential equation.\r\n\t\\begin{equation*}\r\n\t\t\\dd{P}{t} = kP(M-P)\r\n\t\\end{equation*}\r\n\twhere $k$ is some constant of proportionality and $M$ is some maximum population before growth starts to decline.\r\n\\end{example}\r\n\\begin{answer}\r\n\tThis differential equation is also separable, so let's try to solve it.\r\n\t\\begin{align*}\r\n\t\t\\dd{P}{t} &= kP(M-P) \\\\\r\n\t\t\\frac{\\d{P}}{P(M-P)} &= k\\d{t} \\\\\r\n\t\t\\d{P}\\left(\\frac{1/M}{P}+\\frac{1/M}{M-P}\\right) &= k\\d{t} \\text{ (using partial fractions)} \\\\\r\n\t\t\\frac{1}{M}\\left(\\ln{\\abs{P}} - \\ln{\\abs{M-P}}\\right) &= kt + C \\\\\r\n\t\t\\ln{\\abs{\\frac{P}{M-P}}} &= Mkt + C \\\\\r\n\t\t\\frac{P}{M-P} &= Ce^{Mkt} \\text{ (b/c $P \\geq 0$)} \\\\\r\n\t\tP &= CMe^{Mkt} - CPe^{Mkt} \\\\\r\n\t\tP\\left(1+Ce^{Mkt}\\right) &= CMe^{Mkt} \\\\\r\n\t\tP &= \\frac{CMe^{Mkt}}{1+Ce^{Mkt}} \\\\\r\n\t\t&= \\frac{M}{1+Ce^{-Mkt}}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\begin{figure}[H]\r\n\t\\label{logistic}\r\n\t\\centering\r\n\t\\includegraphics[width=0.5\\textwidth]{./applications_integrals/logistic_growth.png}\r\n\t\\caption{\\hyperref{}{}{}{Logistic Growth}}\r\n\\end{figure}\r\n\r\nLooking at a graph of this function, we can see that it starts growing like an exponential curve but begins to flatten, obtaining a maximum value of $M$, which is called the carrying capacity.\r\nThe population is growing the fastest when $P=M/2$, which you can verify by finding the global maxima of $\\dd{P}{t}$ using a first derivative test.\r\n\r\n\\subsection{Slope Fields \\& Euler's Method}\r\nUnfortunately, not all differential equations are as easy to solve as separable differential equations.\r\nIn fact, some are impossible to get nice, closed-form solutions.\r\n\\subsubsection{Slope Fields}\r\nWe may still be able to visualize what the graph of a solution might look like by drawing lines that have the same slope as a solution.\r\nAny solution that passes through the points where we draw the sloped lines must be tangent to these lines, meaning a solution will follow the ``flow\" of these lines.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{slope_field}\r\n\t\\centering\r\n\t\\includegraphics[width=0.75\\textwidth]{./applications_integrals/slope_field.png}\r\n\t\\caption{\\hyperref{}{}{}{Slope field of $\\dd{y}{x}=-x/y$ with a possible solution}}\r\n\\end{figure}\r\n\r\n\\subsubsection{Euler's Method}\r\nIf your differential equation also has an initial condition, you can start at the initial point and follow the slope field to find an approximate solution.\r\nThis is what Euler's Method tries to accomplish.\r\nIt can approximate the value of a solution at some $x$ value by starting at some point, usually given by the initial condition, and iteratively taking small steps of size $\\Delta x$ in the direction determined by the slope field.\r\n\\begin{align*}\r\n\tx_{n+1} &= x_n + \\Delta x \\\\\r\n\ty_{n+1} &= y_n + \\Delta x\\dd{y}{x}_{(x_n,y_n)}.\r\n\\end{align*}\r\n\r\nThe smaller the steps, the more accurate the approximation.\r\n\\begin{figure}[H]\r\n\t\\label{eulers_method}\r\n\t\\centering\r\n\t\\includegraphics[width=0.55\\textwidth]{./applications_integrals/Eulers-Approximation.png}\r\n\t\\includegraphics[width=0.35\\textwidth]{./applications_integrals/Eulers-Approximation2.png}\r\n\t\\caption{\\hyperref{https://calcworkshop.com/first-order-differential-equations/eulers-method-table/}{}{}{Calc Workshop - Euler's Method};\\hspace{5pt}\\hyperref{https://en.wikipedia.org/wiki/Euler\\_method}{}{}{Wikipedia - Euler Method}}\r\n\\end{figure}\r\n\r\n\\begin{example}\r\n\tGiven that $\\dd{y}{x}=3-x$ and $y(4)=2$, approximate the value of $y(5)$ using Euler's method with increments of $\\Delta x = 0.25$.\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{table}[H]\r\n\t\t\\begin{center}\r\n\t\t\t\\begin{tabular}{|c|c|c|c|c|}\r\n\t\t\t\t\\hline\r\n\t\t\t\t$(x,y)$ & $\\dd{y}{x}$ & $\\Delta x$ & $\\Delta y = \\Delta x\\dd{y}{x}$ & $(x+\\Delta x, y+\\Delta y)$ \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t$(4,2)$ & $-1$ & $0.25$ & $-0.25$ & $(4.25,1.75)$ \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t$(4.25,1.75)$ & $-1.25$ & $0.25$ & $-0.3125$ & $(4.5,1.4375)$ \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t$(4.5,1.4375)$ & $-1.5$ & $0.25$ & $-0.375$ & $(4.75,1.0625)$ \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t$(4.75,1.0625)$ & $-1.75$ & $0.25$ & $-0.4375$ & $(5,0.625)$ \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\\end{tabular}\r\n\t\t\\end{center}\r\n\t\\end{table}\r\n\t\r\n\tSo, Euler's Method yields an approximate\\footnote{The actual value of the solution is $(5,0.5)$, so not too far off.} value of $(5,0.625)$.\r\n\\end{answer}", "meta": {"hexsha": "3fcb1d862742290b7114a74377f3536347234469", "size": 9171, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/applications_integrals/diff_eq.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/applications_integrals/diff_eq.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/applications_integrals/diff_eq.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.3043478261, "max_line_length": 288, "alphanum_fraction": 0.6697197688, "num_tokens": 2940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.9019206791658465, "lm_q1q2_score": 0.832508113784616}}
{"text": "\n\\section{Support vector machines}\n\nKey idea:\n\\begin{itemize}\n  \\item find the widest separating strip between the points\nbelonging to the two classes.\n  \\item Find a vector $w$ that is perpendicular to the median line to the\nstrip.\n  \\item For any unknown $u$, classify as positive example if \n    $f(u) = w\\cdot u + b \\geq 0$\n\\end{itemize}\n\n\\subsection{Derivation of result}\n\nAssume the following constraints:\n\n\\begin{math}\n  c_i = \\begin{cases}\n    f(x_{+}) = w \\cdot x_{+} + b \\geq 1 & for \\medspace x_{+} \\\\\n    f(x_{-}) = w \\cdot x_{-} + b \\leq -1 & for \\medspace x_{-} \n  \\end{cases}\n\\end{math}\n\nThe constraint can be generalized introducing:\n\n\\begin{math}\n  y_i = \\begin{cases}\n    1 & x_{+} \\\\\n    -1 & x_{-}\n  \\end{cases}\n\\end{math}\n\nSo to obtain:\n\\begin{math}\n  c_i: y_i(w \\cdot x_i + b) - 1 \\geq 0\n\\end{math}\n\nAlso, assume that the constraint is satisfied with equality for\nobservations at the edge of the strip.\n\n\\paragraph{Finding the width of the strip} For any two points at\nthe edge of the strip, one negative and one positive observation,\nit holds that:\n\n\\begin{equation}\n  \\begin{aligned}\n    width &= (x_{+} - x_{-}) \\cdot \\frac{w}{\\|w\\|} \\\\\n          &= (1-b) + (1+b) \\\\\n          &= \\frac{2}{\\|w\\|}\n  \\end{aligned}\n\\end{equation}\n\n\\paragraph{Objective} Maximize the width of the strip, \nreformulated as: \n\\begin{equation}\n  objective = \\frac{1}{2}\\|w\\|^2\n\\end{equation}\n\n\\subsection{Constrained optimization}\n\nThe problem can be formulated as: \n\n\\begin{equation}\n  L(w) = \\frac{1}{2}\\|w\\|^2 - \n  \\sum_{i}{\\alpha_{i}\\left[ y_i(w \\cdot x_i + b) - 1 \\right]}\n\\end{equation}\n\n\\begin{equation}\n  \\begin{cases}\n    \\frac{\\varDelta L}{w}: w - \\sum{\\alpha_{i}y_ix_i} = 0  \\\\\n    \\frac{\\varDelta L}{b}: \\sum_{i}{\\alpha_{i}y_i } = 0\n  \\end{cases}\n\\end{equation}\n\nPlugging the first f.o.c. into the Lagrangean, we obtain:\n\\begin{equation}\n  L = \\sum_i{a_i} - \\frac{1}{2}\n    \\sum_{i}\\sum_{j}{a_ia_jy_iy_j (x_i \\cdot x_j)}\n\\end{equation}\n\nThen check the sign of:\n\n\\begin{equation}\n  f(u) = \\left(\\sum{a_i y_i (x_i u)}\\right) + b\n\\end{equation}\n\nThus:\n\\begin{itemize}\n  \\item $w$ is a linear sum of the samples. \n  \\item Learning ($w$) depends only on the the dot product \n    of observation pairs\n  \\item Classification depends only on the the dot product \n    of observations with the unkown\n  \\item Exclusive reliance on dot products enables approach \n    to problems in which samples cannot be separated by a\n    straight line\n\\end{itemize}\n\nWhen the classes are not linearly separable, handle\nnon-linearities by applying a transformation $\\Phi$ - the\n\\textbf{kernel} to the dot products of the samples, \nso to solve the problem in a higher dimensional space. \n\nCommon kernels are:\n\\begin{itemize}\n  \\item Polynomial: $(u \\cdot v + 1)^n$\n  \\item Radial basis: $e^{-\\frac{u-v}{\\sigma}}$\n\\end{itemize}\n", "meta": {"hexsha": "e0a9a881ba6ded99cd15220a8135eafd088089e6", "size": 2813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svm.tex", "max_stars_repo_name": "Calcifer777/mit-6034", "max_stars_repo_head_hexsha": "9a0939aba7fa3bba0339c4f30f716b41b3bc878b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "svm.tex", "max_issues_repo_name": "Calcifer777/mit-6034", "max_issues_repo_head_hexsha": "9a0939aba7fa3bba0339c4f30f716b41b3bc878b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "svm.tex", "max_forks_repo_name": "Calcifer777/mit-6034", "max_forks_repo_head_hexsha": "9a0939aba7fa3bba0339c4f30f716b41b3bc878b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5727272727, "max_line_length": 73, "alphanum_fraction": 0.663348738, "num_tokens": 931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258009, "lm_q2_score": 0.8918110468756548, "lm_q1q2_score": 0.8324439054672101}}
{"text": "\\section{Composite Numerical Integration}\nTo calculate an aribitrary integral $\\int_a^bf(x)\\D x$, choose an even integer $n$, subdivide the interval $[a,b]$ into $n$ subinterval, and apply Simpson's rule on each consecutive pair of subintervals. With $h=(b-a)/h$ and $x_j=a+jh$, for $j=0,1,\\ldots,n$, we have\n\\begin{align*}\n    \\int_a^bf(x)\\D x &= \\sum_{j=1}^{n/2}\\int_{x_{2j-2}}^{x_{2j}}f(x)\\D x \\\\\n    &= \\sum_{j=1}^{n/2}\\left\\{\\frac{h}{3}\\left[f(x_{2j-2})+4f(x_{2j-1})+f(x_{2j})\\right]-\\frac{h^5}{90}f^{(4)}(\\xi_j)\\right\\} \\\\\n    &= \\frac{h}{3}\\left[f(x_0)+2\\sum_{j=1}^{n/2-1}f(x_{2j})+4\\sum_{j=1}^{n/2}f(x_{2j-1})+f(x_n)\\right] - \\frac{h^5}{90}\\sum_{j=1}^{n/2}f^{(4)}(\\xi_j) \\\\\n    &= \\frac{h}{3}\\left[\\cdots\\cdots\\right]-\\frac{h^5}{90}\\left(\\frac{n}{2}\\right)f^{(4)}(\\mu) \\\\\n    &= \\frac{h}{3}\\left[\\cdots\\cdots\\right]-\\frac{(b-a)}{180}h^4f^{(4)}(\\mu) \\\\\n\\end{align*}\n\n\\begin{theo}[Composite Simpson's Rule]\nLet $f\\in C^4[a,b]$, $n$ be even, $h=\\frac{b-a}{n}$, and $x_j=a+jh$ for $j=0,1,\\ldots,n$.\nThere exists a $\\mu\\in(a,b)$ s.t. with $n$ subintervals\n\\begin{align*}\n\\int_a^bf(x)\\D x =& \\frac{h}{3}\\left[f(a)+2\\sum_{j=1}^{n/2-1}f(x_{2j})+4\\sum_{j=1}^{n/2}f(x_{2j-1})+f(b)\\right] \\\\\n&- \\frac{b-a}{180}h^4f^{(4)}(\\mu).\n\\end{align*}\n\\end{theo}\n\n\\begin{theo}[Composite Trapezoidal Rule]\nLet $f\\in C^2[a,b]$, $n$ be even, $h=\\frac{b-a}{n}$, and $x_j=a+jh$ for $j=0,1,\\ldots,n$.\nThere exists a $\\mu\\in(a,b)$ s.t. with $n$ subintervals\n\\[\n\\int_a^bf(x)\\D x=\\frac{h}{2}\\left[f(a)+2\\sum_{j=1}^{n-1}f(x_j)+f(b)\\right] - \\frac{b-a}{12}h^2f''(\\mu).\n\\]\n\\end{theo}\n\n\\begin{theo}[Composite Midpoint Rule]\nLet $f\\in C^2[a,b]$, $n$ be even, $h=\\frac{b-a}{n+2}$, and $x_j=a+(j+1)h$ for $j=-1,0,\\ldots,n+1$.\nThere exists a $\\mu\\in(a,b)$ s.t. with $n+2$ subintervals\n\\[\n\\int_a^bf(x)\\D x=2h\\sum_{j=0}^{n/2}f(x_{2j}) + \\frac{b-a}{6}h^2f''(\\mu).\n\\]\n\\end{theo}\n\n\\subsection{Round-off Error Stability}\n\\begin{align*}\n    e(h) &= \\abs{\\frac{h}{3}\\left[e_0+2\\sum_{j=1}^{n/2-1}e_{2j}+4\\sum_{j=1}^{n/2}e_{2j-1}+e_n\\right]} \\\\\n    &\\leq \\frac{h}{3}\\left[\\abs{e_0}+2\\sum_{j=1}^{n/2-1}\\abs{e_{2j}}+4\\sum_{j=1}^{n/2}\\abs{e_{2j-1}}+\\abs{e_n}\\right] \\\\\n    &\\leq \\frac{h}{3}\\left[\\varepsilon+2(\\frac{n}{2}-1)\\varepsilon+4(\\frac{n}{2})\\varepsilon+\\varepsilon\\right]=\\frac{h}{3}3h\\varepsilon = nh\\varepsilon \\\\\n    &= (b-a)\\varepsilon.\n\\end{align*}\nIf the round-off errors are uniformly bounded by $\\varepsilon$.", "meta": {"hexsha": "9a958094e4944225acfecf8ba15768fe0b8d14d5", "size": 2381, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/4.4_Composite_numerical_integration.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/4.4_Composite_numerical_integration.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/4.4_Composite_numerical_integration.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.3720930233, "max_line_length": 266, "alphanum_fraction": 0.585048299, "num_tokens": 1152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990283, "lm_q2_score": 0.9086178956955642, "lm_q1q2_score": 0.8323935872450043}}
{"text": "\\subsection{Gaussian Process Regression}\n\\label{supp: GPR}\n\nA \\textit{Gaussian process} is a collection of random variables, any finite number of which have a joint Gaussian distribution. \nWe define mean function $\\mu(\\mathbf{x})$  and covariance function $k(\\mathbf{x}, \\mathbf{x}^\\prime)$ of a real process $f(\\mathbf{x})$ as\n\\begin{align}\n    \\mu(\\mathbf{x}) &= \\mathbb{E}[f(\\mathbf{x})]\\\\\n    k(\\mathbf{x}, \\mathbf{x}^\\prime) &= \\mathbb{E}[(f(\\mathbf{x}) - \\mu(\\mathbf{x}))(f(\\mathbf{x}^\\prime) - \\mu(\\mathbf{x}^\\prime))].\n\\end{align}\n\nA Gaussian process is specified by its mean function and convariance function as $f(\\mathbf{x}) \\sim \\mathcal{G} \\mathcal{P}\\left(\\mu(\\mathbf{x}), k\\left(\\mathbf{x}, \\mathbf{x}^{\\prime}\\right)\\right)$.\nWe consider the case where the observations are noisy, i.e. $\\{(\\mathbf{x}_i, y_i)| i = 1, \\dots, n\\}$, where $y_i = f(\\mathbf{x}_i) + \\epsilon$ with $\\epsilon \\sim \\mathcal{N}(0, \\alpha^2)$. \nThe Gaussian noise is independent identically distributed, and the prior on the noisy observations is then $\\operatorname{cov}\\left(y_{p}, y_{q}\\right)=k\\left(\\mathbf{x}_{p}, \\mathbf{x}_{q}\\right)+\\alpha^{2} \\delta_{p q}$,\nwhere $\\delta_{pq}$ is a Kronecker delta which is one if $p = q$ and zero otherwise.\nIt is equivalent to a diagonal matrix $\\alpha^2 I$ on the kernel matrix evaluated on the training points.\n\nFor $n_\\ast$ test points $X_\\ast$, we assume the prior over the functions values as a random Gaussian vector $\\mathbf{f}_\\ast \\sim \\mathcal{N}(\\mathbf{0}, K(X_\\ast, X_\\ast))$.\nThen the joint distribution of the observed target values and the function values at the test points under the prior as \n\\begin{align}\n    \\left[\\begin{array}{l}\\mathbf{y} \\\\ \\mathbf{f}_{*}\\end{array}\\right] \\sim \\mathcal{N}\\left(\\mathbf{0},\\left[\\begin{array}{cc}K(X, X)+\\alpha^{2} I & K\\left(X, X_{*}\\right) \\\\ K\\left(X_{*}, X\\right) & K\\left(X_{*}, X_{*}\\right)\\end{array}\\right]\\right)\n\\end{align}\nwhere $K(X, X_\\ast)$ denotes the $n \\times n_\\ast$ covariance/Kernel matrix evaluated at all pairs of training and testing points, similarly for other kernel matrices.\nThen the posterior of the test points (i.e. predictive distributions) is given by the conditional distribution $\\mathbf{f}_\\ast | X, \\mathbf{y}, X_\\ast \\sim \\mathcal{N}(\\bar{\\mathbf{f}}_\\ast, cov(\\mathbf{f}_\\ast))$, where\n\\begin{align}\n   \\overline{\\mathbf{f}}_{*} & \\triangleq \\mathbb{E}\\left[\\mathbf{f}_{*} \\mid X, \\mathbf{y}, X_{*}\\right]=K\\left(X_{*}, X\\right)\\left[K(X, X)+\\alpha^{2} I\\right]^{-1} \\mathbf{y} \\\\\n   \\label{Eq: predicted variance}\n   \\operatorname{cov}\\left(\\mathbf{f}_{*}\\right) &=K\\left(X_{*}, X_{*}\\right)-K\\left(X_{*}, X\\right)\\left[K(X, X)+\\alpha^{2} I\\right]^{-1} K\\left(X, X_{*}\\right) \n\\end{align}\nFor noisy test targets $\\mathbf{y}_\\ast$, we can compute the predictive distribution by adding $\\alpha^2 I$ to the variance term $cov(\\mathbf{f}_\\ast)$ in Eq. (\\ref{Eq: predicted variance}).\n% We now introduce the marginal likelihood (or evidence) $p(\\mathbf{y}|X)$, is which the integral of the likelihood times the prior \n% \\begin{align}\n%     p(\\mathbf{y} \\mid X)=\\int p(\\mathbf{y} \\mid \\mathbf{f}, X) p(\\mathbf{f} \\mid X) d \\mathbf{f}\n% \\end{align}\n\n\n\n\\subsection{Choices of Kernels}\n\nThe choice of covariance function is critical for the performance of Gaussian process regression, we show a number of different string kernels tested in this study below:\n\n\\begin{itemize}\n    \\item \\textit{Spectrum Kernel.}\n    \\begin{align}\n        k_\\ell^{\\text{Spec}}(X, X^\\prime) =\\left\\langle\\phi_{\\ell}^{\\mathrm{Spec}}(\\mathbf{x}), \\phi_{\\ell}^{\\mathrm{Spec}}\\left(\\mathbf{x}^{\\prime}\\right)\\right\\rangle = \\phi_{\\ell}^{\\mathrm{Spec}}(\\mathbf{x})^T \\phi_{\\ell}^{\\mathrm{Spec}}\\left(\\mathbf{x}^{\\prime}\\right).\n    \\end{align}\n     where $\\mathbf{x}, \\mathbf{x}^\\prime$ are two RBS sequences in $\\mathcal{D}$ over an alphabet $\\Sigma$. We denote the number of letters in the alphabet as $|\\Sigma|$. \n    $\\phi_{\\ell}^{\\mathrm{spec}}(\\mathbf{x})$ maps the sequence $X$ into a $|\\Sigma|^\\ell$ dimensional feature space, where each dimension is the count of the number of one of the $|\\Sigma|^\\ell$ possible strings $s$ of length $\\ell$. \n    Let $X, X^\\prime$ be two metrics which include $n$ sequences, and $\\Phi_d^{Spec}(X) \\in \\mathbb{R}^{n \\times |\\Sigma|^{\\ell}}$, then the spectrum kernel over metrics is \n    \\begin{align}\n         K_\\ell^{\\text{Spec}}(X, X^\\prime) = \\Phi_{\\ell}^{\\mathrm{Spec}}(X) \\Phi_{\\ell}^{\\mathrm{Spec}}\\left(X^{\\prime}\\right)^T.\n    \\end{align}\n    \n    \\item \\textit{Sum of Spectrum Kernel,} considers weighted sum over different parts of the string. \n    \n    \\item \\textit{Mixed Spectrum Kernel,} considers weighted sum over different substring length, with $\\beta_d = \\frac{2(\\ell - d + 1)}{\\ell(\\ell+1)}$,\n        \\begin{align}\n            k_\\ell^{MixedSpec}(\\mathbf{x}, \\mathbf{x}^\\prime) \n            = \\sum_{d=1}^{\\ell} \\beta_d k_d^{Spec}(\\mathbf{x}, \\mathbf{x}^\\prime)\n        \\end{align}\n    \\item \\textit{Weighted Degree Kernel,} considers positional information. WD kernel counts the match of kmers at corresponding positions in two sequences.\n    For sequences with fixed length $L$ and weighted degree kernel considers substrings starting at each position $l = 1, ..., L$, with $\\beta_d = \\frac{2(\\ell - d + 1)}{\\ell(\\ell+1)}$, \\\\\n    \\begin{align}\n        k_\\ell^{WD}(\\mathbf{x}, \\mathbf{x}^\\prime) \n        &= \\sum_{d=1}^{\\ell} \\beta_d \\sum_{l=1}^{L-d+1} \\gamma_l k_d^{Spec}(\\mathbf{x}_{[l:l+d]}, \\mathbf{x}_{[l:l+d]}^\\prime)\\\\\n        &= \\sum_{d=1}^{\\ell} \\beta_d \\sum_{l=1}^{L-d+1} \\gamma_l \\phi_d^{Spec}(\\mathbf{x}_{[l:l+d]})^T \\phi_d^{Spec}(\\mathbf{x}_{[l:l+d]}^\\prime)\\\\\n        &= \\sum_{d=1}^{\\ell} \\beta_d \\sum_{l=1}^{L-d+1} \\gamma_l \\mathbb{I}(\\mathbf{x}_{[l:l+d]} = \\mathbf{x}_{[l:l+d]}^\\prime),\n    \\end{align}\n    where $\\mathbb{I}(\\text{true}) = 1$ and 0 otherwise. \n    \n    \\item \\textit{Weighted Degree Kernel With Shift.}\n    \\begin{align}\n        k_\\ell^{WDS}(\\mathbf{x}, \\mathbf{x}^\\prime) \n        &= \\sum_{d=1}^{\\ell} \\beta_d \\sum_{l=1}^{L-d+1} \\gamma_l \\sum_{s = 0, s + l \\leq L}^{S(l)} \\delta_s\n        \\left(k_d^{Spec}(\\mathbf{x}_{[l+s:l+s+d]}, \\mathbf{x}_{[l:l+d]}^\\prime) + (k_d^{Spec}(\\mathbf{x}_{[l:l+d]}, \\mathbf{x}_{[l+s:l+s+d]}^\\prime)\\right)\\\\\n        &= \\sum_{d=1}^{\\ell} \\beta_d \\sum_{l=1}^{L-d+1} \\gamma_l \\sum_{s = 0, s + l \\leq L}^{S(l)} \\delta_s\n        \\left(\\mathbb{I}(\\mathbf{x}_{[l+s:l+s+d]} = \\mathbf{x}_{[l:l+d]}^\\prime) + (\\mathbb{I}(\\mathbf{x}_{[l:l+d]}= \\mathbf{x}_{[l+s:l+s+d]}^\\prime)\\right),\n    \\end{align}\n    where $\\beta_d = \\frac{2(\\ell - d + 1)}{\\ell(\\ell+1)}, \\delta_s = \\frac{1}{2(s+1)}$, $\\gamma_l$ is a weighting over the position in the\n    sequence, where we choose to use a uniform weighting over the sequences, i.e. $\\gamma_l = 1/L$. $S(l)$ determines the shift\n    range at position $l$.\n\\end{itemize}\n\n\\textbf{From kernel to distance}:\n$$d(\\mathbf{x}, \\mathbf{x}^\\prime) = \\sqrt{k(\\mathbf{x}, \\mathbf{x}) + k(\\mathbf{x}^\\prime, \\mathbf{x}^\\prime) - 2 k(\\mathbf{x}, \\mathbf{x}^\\prime)} $$\n\n\\subsubsection{Normalisation of Kernel}\n\\label{supp: Normalisation of Kernel}\n\nAs part of data pre-processing,\nthe range of all features should be normalised so that each feature contributes approximately proportionately to the predictive model. \nThe kernel matrix is represented by the inner product of the underlying feature vectors, it needs to be normalised before being used in the downstream regression models. \nUp-scaling (down-scaling) features can be understood as down-scaling (up-scaling) regularizers such that they penalise the features less (more). \n\nHere we consider two approaches for kernel normalisation: centering and unit norm. \nWe will show how to convert the normalisation in terms of feature vectors to normalisation in terms of kernel matrices. \nAs defined before, consider $\\mathbf{x}, \\mathbf{x}^\\prime$ are two RBS sequences in $\\mathcal{D}$ over an alphabet $\\Sigma$.\nWe denote $\\phi(\\mathbf{x}_i)$ as a column feature vector of sequence $\\mathbf{x}_i$, \nwhere a feature function $\\phi: \\mathbf{x} \\rightarrow \\mathbb{R}^d$. Assume there is total of $n$ sequences in the data $X$ ($n'$ sequences in the data $X'$). \nWe illustrate centering and unit norm normalisation below. \n\n\\begin{itemize}\n    \\item Centering. \n    Defining the mean vector as $\\bar{\\Phi}(X) = \\frac{1}{n} \\sum_{s = 1}^n \\phi(\\mathbf{x}_s) \\in \\mathbb{R}^d$, the centered feature vector $\\phi^C(\\mathbf{x}_i) \\in \\mathbb{R}^d$ of $\\mathbf{x}_i$ is\n    \\begin{align}\n        \\phi^{C}(\\mathbf{x}_i) = \\phi(\\mathbf{x}_i) - \\bar{\\Phi}(X) = \\phi(\\mathbf{x}_i) - \\frac{1}{n'} \\sum_{s = 1}^{n'} \\phi(\\mathbf{x}_s).\n    \\end{align}\n    The corresponding centering kernel value between $\\mathbf{x}_i$ and $\\mathbf{x}_j$ is then \n    \\begin{align}\n        k^C(\\mathbf{x}_i, \\mathbf{x}_j) &= <\\phi^C(\\mathbf{x}_i), \\phi^C(\\mathbf{x}_j)>\\\\\n        &= \\left( \\phi(\\mathbf{x}_i) - \\frac{1}{n} \\sum_{s = 1}^n \\phi(\\mathbf{x}_s)\\right)^T \\left( \\phi(\\mathbf{x}_j) - \\frac{1}{n'} \\sum_{s' = 1}^{n'} \\phi(\\mathbf{x}_{s'})\\right)\\\\\n        &= \\phi(\\mathbf{x}_i)^T \\phi(\\mathbf{x}_j) - \\left( \\frac{1}{n} \\sum_{s = 1}^n \\phi(\\mathbf{x}_s)\\right)^T \\phi(\\mathbf{x}_j) - \\phi(\\mathbf{x}_i)^T \\left(\\frac{1}{n} \\sum_{s' = 1}^{n'} \\phi(\\mathbf{x}_{s'})\\right) + \\left( \\frac{1}{n} \\sum_{s = 1}^n \\phi(\\mathbf{x}_s)\\right)^T \\left(\\frac{1}{n'} \\sum_{s' = 1}^{n'} \\phi(\\mathbf{x}_{s'})\\right)\\\\\n        &= k(\\mathbf{x}_i, \\mathbf{x}_j) - \\frac{1}{n} \\sum_{s=1}^n k(\\mathbf{x}_s, \\mathbf{x}_j) - \\frac{1}{n'} \\sum_{s'=1}^{n'} k(\\mathbf{x}_i, \\mathbf{x}_{s'}) + \\frac{1}{n^2} \\sum_{s = 1}^n \\sum_{s'=1}^{n'} k(\\mathbf{x}_s, \\mathbf{x}_{s'})\n    \\end{align}\n    \n    \\item Unit Norm. Define the ($l_2$) norm of a feature vector as $||\\phi(\\mathbf{x})|| = \\sqrt{\\sum_{m = 1}^d \\phi_d(\\mathbf{x})^2} = \\sqrt{k(\\mathbf{x}, \\mathbf{x})} \\in \\mathbb{R}^+$, then the unit norm feature vector $\\phi^{UN}(\\mathbf{x}_i) \\in \\mathbb{R}^d$ of $\\mathbf{x}_i$ is \n    \\begin{align}\n        \\phi^{UN}(\\mathbf{x}_i) = \\frac{\\phi(\\mathbf{x}_i)}{||\\phi(\\mathbf{x}_i)||}.\n    \\end{align}\n    The corresponding unit norm kernel value between $\\mathbf{x}_i$ and $\\mathbf{x}_j$ is then \n    \\begin{align}\n        k^{UN}(\\mathbf{x}_i, \\mathbf{x}_j) &= <\\frac{\\phi(\\mathbf{x}_i)}{||\\phi(\\mathbf{x}_i)||}, \\frac{\\phi(\\mathbf{x}_j)}{||\\phi(\\mathbf{x}_j)||}>\\\\\n        &= \\frac{\\phi(\\mathbf{x}_i)^T \\phi(\\mathbf{x}_j)}{||\\phi(\\mathbf{x}_i)|| \\times ||\\phi(\\mathbf{x}_j)||}\\\\\n        &= \\frac{k(\\mathbf{x}_i, \\mathbf{x}_j)}{\\sqrt{k(\\mathbf{x}_i, \\mathbf{x}_i)  k(\\mathbf{x}_j, \\mathbf{x}_j)}}\n    \\end{align}\n    \n     \\item Unit Variance. \n    After the centering and unit norm normalisation, the kernel matrix is unit variance as well. \n    In the following, we show transformations of the unit variance (with centering) normalisation.\n    Define the variance vector ${Var}(\\Phi(X)) = \\frac{1}{n} \\sum_{s=1}^n ||\\phi(\\mathbf{x}_s) - \\bar{\\Phi}(X)||^2 = \\frac{1}{n} \\sum_{s=1}^n ||\\phi(\\mathbf{x}_s) - \\sum_{s'=1}^n \\left(\\phi(\\mathbf{x}_s')\\right)||^2 = \\frac{1}{n} \\sum_{s=1}^n  k^C(\\mathbf{x}_s, \\mathbf{x}_s)  \\in \\mathbb{R}$, the unit variance feature vector $\\phi^{UV}(\\mathbf{x}_i) \\in \\mathbb{R}^d$ of $\\mathbf{x}_i$ is\n    \\begin{align}\n        \\phi^{UV}(\\mathbf{x}_i) = \\frac{\\phi(\\mathbf{x}_i)}{\\sqrt{Var(\\Phi(X))}}.\n    \\end{align}\n    The corresponding kernel representation is \n    \\begin{align}\n        k^{UV}(\\mathbf{x}_i, \\mathbf{x}_j) &= <\\frac{\\phi(\\mathbf{x}_i)}{\\sqrt{Var(\\Phi(X))}}, \\frac{\\phi(\\mathbf{x}_j)}{\\sqrt{Var(\\Phi(X'))}}>\\\\\n        &= \\frac{\\phi(\\mathbf{x}_i)^T \\mathbf{x}_j}{\\sqrt{Var(\\Phi(X)) Var(\\Phi(\\mathbf{X'}))}}\\\\\n        &= \\frac{k(\\mathbf{x}_i, \\mathbf{x}_j)}{\\sqrt{ \\frac{1}{n} \\sum_{s=1}^n  k^C(\\mathbf{x}_s, \\mathbf{x}_s)  \\frac{1}{n} \\sum_{s'=1}^{n'}  k^C(\\mathbf{x}_{s'}, \\mathbf{x}_{s'})}}\n    \\end{align}\n    After centering and unit norm, $ \\frac{1}{n} \\sum_{s=1}^n  k^C(\\mathbf{x}_s, \\mathbf{x}_s) = k(\\mathbf{x}_i, \\mathbf{x}_i)$, which implies that after centering and unit norm, the kernel matrix is already unit variance normalised. \n\\end{itemize}\nFor the Gaussian Process regression, we make of use of two kernel matrices: the kernel function between the training data itself, i.e. $K(X_{train}, X_{train})$; and\nthe kernel function taking the training data and testing data as inputs, i.e. $K(X_{test}, X_{train})$. \n%It is straightforward to normalise a square kernel which same input, i.e. $n = n'$ and $k(\\mathbf{x}_i, \\mathbf{x}_i),  k(\\mathbf{x}_j, \\mathbf{x}_j)$ taken from the diagonal of the matrix. \n%The second one (between train and test) is a little bit tricky. The different is not only that $n \\neq n'$. \nWe will state two ways of normalisation those two kind of matrices:\n\\begin{itemize}\n    \\item Normalise training and testing data separately.\n    This approach is preferred for most of the machine learning algorithms since it follows the rule that we have no information about testing data while training.\n    Then for centering, one should subtract the mean vector over the training data for both kinds of matrices.\n    For unit norm normalisation, when one calculates $K^{UN}(X_{test}, X_{train})$, the two terms inside of square root: $k(\\mathbf{x}_i, \\mathbf{x}_i)$ is taken from $K(X_{test}, X_{test})[i,i]$, and $k(\\mathbf{x}_j, \\mathbf{x}_j)$ is taken from $K(X_{train}, X_{train})[j,j]$.\n    \n    \\item Normalise training and testing data together, i.e. normalise $K(X_{train+test}, X_{train+test})$, then extra the parts we need from the normalised matrix. \n    This approach is suitable in a case where one already knows the whole of testing features. \n    For centering, one should subtract the mean vector over the whole matrix $\\Phi(X_{train+test})$. \n    The unit norm normalisation is the same as in the previous case. \n\\end{itemize}\n\nFor our experiment, we fix the design space before training, i.e. the testing features are already known before testing. \nSo we choose to normalise the kernel matrix over the training and testing data together,\nby first applying centering and then unit norm normalisation. \n\n\\subsection{Batch Recommendation}\n\nFor recommending RBS sequences to label, we consider the Upper Confidence Bound (UCB) algorithm, \n%which is based on the \\textit{optimism in the face of uncertainty}, \nselecting RBS sequences with the maximum upper confidence bound at round $t$, i.e.\n\\begin{align}\n    \\operatorname{argmax}_{\\mathbf{x}_i \\in \\mathcal{D}} \\left( \\mu_{t-1}(\\mathbf{x}_i) + \\beta_t \\sigma_{t-1}(\\mathbf{x}_i)\\right),\n    \\tag{\\ref{Eq: GPUCB}}\n\\end{align}\nwhere $\\beta_t$ is a hyperparmeter balancing the exploitation and exploration, \n$\\mu_t(\\mathbf{x}_i), \\sigma_t(\\mathbf{x}_i)$ are the predicted mean and standard deviation at round $t$ for the sequence $\\mathbf{x}_i$.\n\nSince labelling sequences is time-consuming, it is unrealistic to recommend sequence sequentially (i.e. one-by-one) and waiting for the label after each prediction.\nTherefore we consider recommending sequences in batch and using Gaussian Process Batch Upper Confidence Bound (GP-BUCB) algorithm  \\cite{desautels2014parallelizing}.\nWith batches of size $B$, the feedback mapping $fb[t] = \\lfloor(t-1) / B\\rfloor B$, i.e. \n\\begin{align}\n    \\mathrm{fb}[t]=\\left\\{\\begin{array}{cl}\n    0 & : t \\in\\{1, \\ldots, B\\} \\\\\n    B & : t \\in\\{B+1, \\ldots, 2 B\\} \\\\\n    2 B & : t \\in\\{2 B+1, \\ldots, 3 B\\} \\\\\n    & \\vdots\n    \\end{array}\\right.\n\\end{align}\n\n\nA key property of Gaussian Process regression is that the predictive variance in Eq. (\\ref{Eq: predicted variance}) only depends on observed points (i.e. features), but not on the labels of these observed points. \nSo one can compute the posterior variance without actually observing the labels. \nThe GP-BUCB policy is to select sequences that\n\\begin{align}\n    \\operatorname{argmax}_{\\mathbf{x}_i \\in \\mathcal{D}} \\left( \\mu_{fb[t]}(\\mathbf{x}_i) + \\beta_t \\sigma_{t-1}(\\mathbf{x}_i)\\right).\n\\end{align}\nAnd only update $y_{t^{\\prime}}=f\\left(\\boldsymbol{x}_{t^{\\prime}}\\right)+\\varepsilon_{t^{\\prime}} \\text { for } t^{\\prime} \\in\\{\\mathrm{fb}[t]+1, \\ldots, \\mathrm{fb}[t+1]\\}$ at the end of each batch ($\\mathrm{fb}[t]<\\mathrm{fb}[t+1]$). \nThis is equivalent to sequential GP-UCB with \\textit{hallucinated observations} $\\boldsymbol{y}_{\\mathrm{fb}[t]+1: t-1}=\\left[\\mu_{\\mathrm{fb}[t]}\\left(\\boldsymbol{x}_{\\mathrm{fb}[t]+1}\\right), \\ldots, \\mu_{\\mathrm{fb}[t]}\\left(\\boldsymbol{x}_{t-1}\\right)\\right]$, while the posterior variance decreases. \n\n\n\\subsection{Machine Learning Design Pipeline}\n\\label{sec: ML design pipeline}\nIn this section, we report in details about our machine learning design pipeline.\nThe raw TIR is calculated as a derivative of GFP fluoresence divided by OD600 of culture over 4h counting from the start of log phase of growth. \n\n\\mengyan{explain somewhere why we have a different pipeline for round 0.}\n\\mengyan{add some analysis on literature data?\nto verify 1) our library is \"better\" 2) it's hard to do ML on available library. some analysis in my mind (for literature data): number of data points, number of replicates (I remembered there only one replicates, if not, then std), label histogram, coverage of RBS.\nAnd we need to address the label in literature data and ours is \"different\", in the way that our pipeline is different for bandit-0 design}\n\n\\textbf{Bandit-0: } the design of round-0 is based on the literature data \\cite{jervis2018machine}.\nWe first normalise the raw TIR to values between 0 and 1. \nWe applied the Gaussian Process Regression with noise parameter $\\alpha = 1e-10$. \nWe chose to use one of the basic string kernels, the \\textit{spectrum kernel} \\cite{leslie2001spectrum} to process the core 6bp and dot product kernel \\cite{Rasmussen2004} (with one-hot embedding) to process the 7bp flanking sequences both upstream and downstream of the core sequence.\nThe design size is 60 with UCB parameter $\\beta = 1$.\\\\\n\\textbf{Bandit-1 to Bandit-3: }\nthe t + 1 round design is based on the $t^th$ ($t \\geq 1$) round result, where each sequence has 6 replicates with TIR labels.\nWe pre-processed the data by taking a logarithm transformation and standardisation of the raw TIR label for each replicates respectively.\nAfter normalisation, each replicate has zero mean and unit variance. \nFor prediction, we use Gaussian process regression, with training on all normalised replicates and predicting on the design space (6-base core part design) except known sequences. \nWe assume the observation are noisy, where the noise is under centered normal distribution with standard deviation $\\alpha$.  \nWe model the covariance matrix using the weighted degree kernel with shift. \nWe normalise the kernel with centering and unit norm in terms of the whole kernel constructed by both first round result and design space. \nThe hyperparameter for kernel, including maximum substring length  $l$, maximum shift length $s$, and the noise standard deviation $\\alpha$ of Gaussian process model are choose based on 10-repeat 5-fold cross validation. \nWe choose $l=6, s= 1, \\alpha = 2$ for the second round design. \nFor recommendation, we use batch upper confidence bound introduced by GP-BUCB algorithm \\cite{desautels2014parallelizing}. \nThe upper confidence bound is constructed by predicted mean plus 2 predicted standard deviation.   \nWe recommend 90 sequences from the design space. \n\n\\subsection{Statistics of the core vs non-core regions of the RBS}\n\nIn our study, we have tested a set of sequnces designed to confirm the notion that changing bases within the RBS core (6 bases) is statistically more influencing the TIR than the changes made outside the core.\nThis hypothesis has been build based on reported biases towards certain bases present in the core of the RBS but absent outside of it.\nFor example, according to \\cite{SHULTZABERGER2001} there is a strong bias towards A and G bases in the core region of the RBS.\nSimilarly outside of the 6 bases of the core in the wider 20 bp context of the RBS there is no significant bias towards any particular base which suggest that these bases do not contribute to the overal TIR of a given RBS. \nThis effect is shown in (Figure \\ref{fig:core_vs_noncore}), which shows results for our set X of sequences.\nThe value of Welch's t-test between the mean TIR in core and non-core groups is -4.8780 with p-value $<$ 0.0001 and 34 degrees of Freedom.\n\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[scale=0.4]{plots/Supplementary/core_vs_noncore.pdf}\n    \\caption{\\textbf{Comparison of base change impact on TIR in core versus non-core region.} The core region is highligthed in light green and the lines are rolling averages for each base. The top dotted line shows the TIR for the benchmark sequence, where dots represent a change at a given position to a given base, which is colour coded.}\n    \\label{fig:core_vs_noncore}\n\\end{figure}\n\n\\subsection{Other Evaluation}\n\n\\textbf{How much more efficient we are by using GP-UCB?}\n\nrandom = {set of TIR that are in UNI and PPM}\nbandit = {set of TIR that are in bandit 0,1,2,3}\n\nThe ratio of the max random to the max bandit: 0.67/1.34 = 0.5\nThe ratio of the 0.9 quantile random to the 0.9 quantile bandit: 0.49/0.82 = 0.598\n\nwe can also calculate an average regret of TIRs which are higher than SD? The regret for one sequences is calculated based on the difference between the benchmark (1) and TIR.\n\nreciprocal would make a better story. I.e. bandit is 2x better than random.\n\n\\textbf{zoom-in tSNE?}\n\n1) supplementary website.\n2) eLife is now offering submissions of interactive papers with Jupyter notebooks. More of a trivia than useful information in our case.\nhttps://elifesciences.org/labs/ad58f08d/introducing-elife-s-first-computationally-reproducible-article\n\n\n\\subsection{Mixture of Absolute Gaussian}\n\nThe raw TIR scores in each round are positive and  have two modes. \nWe assume they are mixture of two absolute Gaussian distributions. \nIf we can fit the mixture of absolute Gaussian distributions, we can answer the following questions:\n\\begin{itemize}\n    \\item is the left peak decreasing in height with each round?\n\t\\item is the left peak going left?\n\t\\item Is the right peak increasing in height with each round?\n\t\\item is the right peak going right?\n\\end{itemize}\n\nThe density of absolute Gaussian (also called \\textit{folded normal distribution}) is \n\\begin{align}\n    f_{Y}\\left(x ; \\mu, \\sigma^{2}\\right)=\\frac{1}{\\sqrt{2 \\pi \\sigma^{2}}} e^{-\\frac{(z-\\mu)^{2}}{2 \\sigma^{2}}}+\\frac{1}{\\sqrt{2 \\pi \\sigma^{2}}} e^{-\\frac{(x+\\mu)^{2}}{2 \\sigma^{2}}}\n\\end{align}\nfor $x \\geq 0$ and $0$ everywhere else. \nThe mean and variance of the absolute Gaussian distribution is \n\\begin{align}\n    \\mu_{Y} &=\\sigma \\sqrt{\\frac{2}{\\pi}} \\exp \\left(\\frac{-\\mu^{2}}{2 \\sigma^{2}}\\right)+\\mu \\operatorname{erf}\\left(\\frac{\\mu}{\\sqrt{2 \\sigma^{2}}}\\right);\\\\\n    \\sigma_{Y}^{2} &=\\mu^{2}+\\sigma^{2}-\\mu_{Y}^{2},\n\\end{align}\nwhere $\\operatorname{erf}$ is the error function \n$\\operatorname{erf} z=\\frac{2}{\\sqrt{\\pi}} \\int_{0}^{z} e^{-t^{2}} d t$.\n\nWe consider the model of the mixture of two absolute Gaussian distributions as \n\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[scale = 0.25]{plots/Supplementary/clustering.png}\n    \\caption{TSNE of RBS sequences in design space with clustering. The distance is calculated based on the weighted degree kernel on RBS sequences. Colours indicate different groups, shapes indicate different clusters.}\n\\end{figure}", "meta": {"hexsha": "e97431138a883ff6098c16319e386a733a0c007d", "size": 23405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/archive_supp.tex", "max_stars_repo_name": "mholowko/Solaris", "max_stars_repo_head_hexsha": "25f65e72667f1e92e0d5c26bc9cbe159a6a15ace", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/archive_supp.tex", "max_issues_repo_name": "mholowko/Solaris", "max_issues_repo_head_hexsha": "25f65e72667f1e92e0d5c26bc9cbe159a6a15ace", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/archive_supp.tex", "max_forks_repo_name": "mholowko/Solaris", "max_forks_repo_head_hexsha": "25f65e72667f1e92e0d5c26bc9cbe159a6a15ace", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.6088435374, "max_line_length": 390, "alphanum_fraction": 0.6875026704, "num_tokens": 7433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122684798184, "lm_q2_score": 0.8688267694452331, "lm_q1q2_score": 0.8322598216352753}}
{"text": "\n\\subsection{Leverage}\n\n\\subsubsection{Introduction}\n\nLeverage measures how much the predicted value of \\(y_i\\), \\(\\hat y_i\\), changes as \\(y_i\\) changes.\n\nWe have:\n\n\\(\\mathbf y = \\mathbf X \\theta +\\mathbf u\\)\n\n\\(\\hat \\theta =X(X^TX)^{-1}X^Ty\\)\n\n\\(\\hat \\theta =P_Xy\\)\n\nThe leverage score is defined as:\n\n\\(h_i=P_{ii}\\)\n\n\n", "meta": {"hexsha": "4f7cbca987b5594f23771839e7b998686223d19e", "size": 321, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/ols/02-04-leverage.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/ols/02-04-leverage.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/ols/02-04-leverage.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.2857142857, "max_line_length": 100, "alphanum_fraction": 0.6448598131, "num_tokens": 111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9702399086356109, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.8322408460522711}}
{"text": "\\chapter{Tensor Product Spaces}\nSo far we have considered the tensor product space $V^* \\otimes V^*$, constructed from a vector space $V$ over a field $\\mathbb{F}$.\nElements of this tensor product space map from $V \\times V$ to $\\mathbb{F}$, and has $16$ basis vectors $\\vec{e}^\\mu \\otimes \\vec{e}^\\nu$, meaning any given tensor can be written as $T_{\\mu\\nu} \\vec{e}^\\mu \\otimes \\vec{e}^\\nu$.\nWe can (almost trivially) generalize this specific type of tensor product space to arbitrary combinations of $V$ and $V^*$.\nThis works exactly as you think it does; if we want to map from $V \\times V \\times V$ to $\\mathbb{F}$, we construct a tensor in the following way:\n\\[ T_{\\lambda\\mu\\nu} \\in V^* \\otimes V^*\\otimes V^* : V \\times V \\times V \\to \\mathbb{F}. \\]\nWe can do the exact same thing if we want to map 4-tuples of vectors in $V$ to the real numbers; such a tensor would be an element of the tensor product space $V^* \\otimes V^* \\otimes V^* \\otimes V^*$, and would have dimension $n^4$, where $n = \\dim(V)$. This is a prime example of why Einstein summation is so useful; once we start talking about tensor product spaces with multiple constituent parts, we start needing to sum over lots of different indices; the tensor $T_{\\lambda\\mu\\nu}$ would more properly be written as\n\\[ \\sum_{i=0}^{\\lambda}\\sum_{j=0}^{\\mu}\\sum_{k=0}^{\\nu} T_{\\lambda\\mu\\nu} \\vec{e}^\\lambda \\otimes \\vec{e}^\\mu \\otimes \\vec{e}^\\nu, \\]\nwhich graphically represents the exact same information as the condensed form as long as we've agreed upon what basis to use beforehand.\n\n\\subsection{Types of Simple Tensors}\nSo far, we've dealt with tensors which are elements of the $n$\\textsuperscript{th} tensor product of the dual space; they map $n$-tuples of \\emph{vectors} to a scalar field.\nHowever, there is nothing stopping us from considering tensors which map $n$-tuples of \\emph{covectors} to a scalar field.\nSuch tensors would be elements of the $n$\\textsuperscript{th} tensor product of the vector space.\n\\begin{align*}\n    T_{\\mu\\nu} &\\in V^* \\otimes V^* : V \\times V \\to \\mathbb{F} \\tag{vectors $\\to$ scalar field} \\\\\n    T^{\\mu\\nu} &\\in V \\otimes V : V^* \\times V^* \\to \\mathbb{F} \\tag{covectors $\\to$ scalar field}\n\\end{align*}\nNotice that tensors which map tuples of covectors to a scalar field are identified with superscripts, not subscripts.\nThis is because the basis for such a tensor is the tensor product of basis vectors of $V$, not $V^*$, and so to sum over them, we must identify the components by upper indicies, not lower, as shown below:\n\\[ T^{\\mu\\nu} \\equiv T^{\\mu\\nu} \\vec{e}_\\mu \\otimes \\vec{e}_\\nu. \\]\nLet's compare how these tensors act on their arguments. First, the ``regular'' tensors we've dealt with up until this point, which map from vectors to the scalar field. Let $T_{\\mu\\nu}$ be such a tensor, build from $V$ and $\\mathbb{F}$, and let it act on the two vectors $A^\\alpha \\vec{e}_\\alpha,\\,B^\\beta \\vec{e}_\\beta \\in V$.\n\\begin{align*}\n    T_{\\mu\\nu} \\vec{e}^\\mu \\otimes \\vec{e}^\\nu \\left( A^\\alpha \\vec{e}_\\alpha, B^\\beta \\vec{e}_\\beta \\right) &= T_{\\mu\\nu} \\langle \\vec{e}^\\mu, A^\\alpha \\vec{e}_\\alpha \\rangle \\langle \\vec{e}^\\nu, B^\\beta \\vec{e}_\\beta \\rangle \\\\\n    &= T_{\\mu\\nu} \\left( A^\\alpha \\delta^\\mu_\\alpha \\right) \\left( B^\\beta \\delta^\\nu_\\beta \\right) \\\\\n    &= T_{\\mu\\nu}A^\\mu B^\\nu.\n\\end{align*}\nNext, consider the tensor $T^{\\mu\\nu}$, built from the same $V$ and $\\mathbb{F}$ as before. Let $A_\\alpha \\vec{e}^\\alpha,\\,B_\\beta \\vec{e}^\\beta \\in V^*$ be the two arguments for this tensor. \n\\begin{align*}\n    T^{\\mu\\nu} \\vec{e}_\\mu \\otimes \\vec{e}_\\nu \\left(A_\\alpha \\vec{e}^\\alpha,B_\\beta \\vec{e}^\\beta\\right) &= T^{\\mu\\nu} \\langle A_\\alpha \\vec{e}^\\alpha, \\vec{e}_\\mu \\rangle \\langle B_\\beta \\vec{e}^\\beta, \\vec{e}_\\nu \\rangle \\\\\n    &= T^{\\mu\\nu} \\left(A_\\alpha \\delta^\\alpha_\\mu\\right) \\left(B_\\beta \\delta^\\beta_\\nu\\right) \\\\\n    &= T^{\\mu\\nu}A_\\mu B_\\nu.\n\\end{align*}\nThe two tensors act in almost identical ways, which makes sense as $V$ are $V^*$ are so tightly coupled.\nNotice also that, if we start with a tensor whose components have two lower indices ($T_{\\mu\\nu}$), we end up summing over the product of it and coefficients with \\emph{matching upper} indices ($A^\\mu B^\\nu$); the same goes for tensors with upper indices; they get coefficients with \\emph{matching lower} indices.\n\n\\subsection{Mixed Tensors}\nAt this point, we've considered tensors which map from the Cartesian product of vectors spaces to a scalar field, and we've considered tensors which map from the Cartesian product of dual spaces to a scalar field; we will now combine them to get a \\emph{mixed tensor}, which maps $n$-tuples of vectors and covectors to a field.\n\nLet's start with our trusty vector space $V$ and its dual space $V^*$, both defined over a scalar field $\\mathbb{F}$, and construct the following two tensors:\n\\begin{align}\n    \\tensor{T}{_{\\mu}^\\nu} \\vec{e}^\\mu \\otimes \\vec{e}_\\nu \\in V^* \\otimes V : V \\times V^* \\to \\mathbb{F} \\\\\n    \\tensor{T}{^{\\mu}_{\\nu}} \\vec{e}_\\mu \\otimes \\vec{e}^\\nu \\in V \\otimes V^* : V^* \\times V \\to \\mathbb{F}\\label{eqn:correct-notation}\n\\end{align}\nThe first maps a vector and a covector ordered pair to $\\mathbb{F}$; the second maps a covector and a vector ordered pair to $\\mathbb{F}$.\nAlthough they look very similar, they are \\emph{entirely different tensors}.\nThe order of the arguments and the order of their definition matters.\nIt's also important to note that the scalar components of the tensor convey this information; the order of the indices indicates the order of the tensor products, so\n\\begin{align*}\n    \\tensor{T}{_{\\mu}^\\nu} \\implies \\text{a basis of }\\vec{e}^\\mu \\otimes \\vec{e}_\\nu, \\\\\n    \\tensor{T}{^{\\mu}_\\nu} \\implies \\text{a basis of }\\vec{e}_\\mu \\otimes \\vec{e}^\\nu.\n\\end{align*}\nLet's take a closer look at how a tensor similar to \\eqref{eqn:correct-notation} would operate.\nIt's first argument must be a covector (remember, linear map) of the form $A_\\alpha e^\\alpha$, while its second argument must be a vector, like $B^\\beta e_\\beta$.\n\\begin{align*}\n    \\tensor{T}{^{\\mu}_{\\nu}} \\vec{e}_\\mu \\otimes \\vec{e}^\\nu \\qty(A_\\alpha \\vec{e}^\\alpha, B^\\beta \\vec{e}_\\beta) &= \\tensor{T}{^{\\mu}_{\\nu}} \\langle A_\\alpha \\vec{e}^\\alpha, \\vec{e}_\\mu \\rangle \\langle \\vec{e}^\\nu, B^\\beta \\vec{e}_\\beta \\rangle \\\\\n    &= \\tensor{T}{^{\\mu}_{\\nu}} \\qty(A_\\alpha \\delta^\\alpha_\\mu) \\qty(B^\\beta \\delta_\\beta^\\nu) \\\\\n    &= \\tensor{T}{^{\\mu}_{\\nu}} A_\\mu B^\\nu\n\\end{align*}\nNotice how the order of the remaining coefficients matches that of the tensor's indices: first, $\\mu$ and then $\\nu$.\n", "meta": {"hexsha": "490e686009575f6fb5f3ee3f7b1bbb522ff20526", "size": 6560, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/tensor_product_spaces.tex", "max_stars_repo_name": "jopetty/tensor-notes", "max_stars_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/tensor_product_spaces.tex", "max_issues_repo_name": "jopetty/tensor-notes", "max_issues_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/tensor_product_spaces.tex", "max_forks_repo_name": "jopetty/tensor-notes", "max_forks_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 107.5409836066, "max_line_length": 522, "alphanum_fraction": 0.6914634146, "num_tokens": 2129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.963779943094681, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.8321195218106018}}
{"text": "\\section{Clustering}\n\n\\subsection{Clustering}\n\\subsection{A clustering Objective}\n$G_{j}= \\{ i| c_{i}=j \\}$ where $G_{j}$ is set of all indices i for which $c_{i}=j$\\\\\nGroup representatives: We want each rep to be close to the vectors, i.e $||x_{i}-z_{c_{i}}||$ where $x_{i}$ is in group $j=c_{i}$ so $z_{c_{i}}$ is the representative vector associated with data vector $x_{i}$ \\\\ \n$J^{clust}=(||x_{1}-z_{c_{1}}||^2 + ...+||x_{N}-z_{c_{N}}||^2)/N$\\\\\nPartitioning vectors with representatives fixed: $||x_{i}-z_{c_{i}}||=\\min\\limits_{j=1,....,k} ||x_{i}-z_{j}||$\\\\\n$J^{clust}=\\Big(\\min\\limits_{j=1,....,k} ||x_{1}-z_{j}||^{2}+....+\\min\\limits_{j=1,....,k} ||x_{N}-z_{j}||^{2}\\Big)/N$\\\\\nOptimizing group representatives with assignment fixed: $J^{clust}=J_{1}+...+J_{k}$ where $J_{j}=\\big(1/N\\big)\\sum\\limits_{i\\in G_{j}}||x_{i}-z_{j}||^{2}$\\\\\nTo minimize mean square distance $z_{j}=\\big(1/|G_{j}|\\big))\\sum\\limits_{i\\in G_{j}}x_{i}$ where $|G_{j}|$ is standard notation for number of elements in set $G_{j}$\n\\subsection{The k-means algorithm}\n\\subsection{Examples}\n\\subsection{Applications}\n\n\n", "meta": {"hexsha": "7e1408d7cf2fcf4271d9e3a2084a3f3badc5e74b", "size": 1093, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter4.tex", "max_stars_repo_name": "ksb25395/COT5615", "max_stars_repo_head_hexsha": "d3f9d9375597ea2b15404ae5f46d21d9073b8697", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cheatsheet/inhalt/chapter4.tex", "max_issues_repo_name": "ksb25395/COT5615", "max_issues_repo_head_hexsha": "d3f9d9375597ea2b15404ae5f46d21d9073b8697", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter4.tex", "max_forks_repo_name": "ksb25395/COT5615", "max_forks_repo_head_hexsha": "d3f9d9375597ea2b15404ae5f46d21d9073b8697", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.2941176471, "max_line_length": 213, "alphanum_fraction": 0.6276303751, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144274, "lm_q2_score": 0.8740772466456689, "lm_q1q2_score": 0.8320019926727873}}
{"text": "\n\\subsection{\\(L_p\\) norms (\\(p\\)-norms)}\n\\subsubsection{\\(L^P\\) norm}\n\nThis generalises the Euclidian norm.\n\n\\(||x||_p=(\\sum_{i=1}^{n}|x|^p_i)^{1/p}\\)\n\nThis can defined for different values of \\(p\\). Note that the absolute value of each element in the vector is used.\n\nNote also that:\n\n\\(||x||_2\\)\n\nIs the Euclidian norm.\n\n\\subsubsection{Taxicab norm}\n\nThis is the \\(L^1\\) norm. That is:\n\n\\(||x||_1=\\sum_{i=1}^{n}|x|_i\\)\n\n\\subsubsection{Angles}\n\n\\subsubsection{Cauchy-Schwarz}\n\n", "meta": {"hexsha": "07484182d413511592c3caed9db604252d64ad1f", "size": 479, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/affineEuclid/03-01-Lp.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/affineEuclid/03-01-Lp.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/affineEuclid/03-01-Lp.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.7407407407, "max_line_length": 115, "alphanum_fraction": 0.6576200418, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632247867717, "lm_q2_score": 0.8740772286044094, "lm_q1q2_score": 0.8320019695320774}}
{"text": "\\subsection*{Ex.29.4-1}\n\nWe have the following linear program\n$$\n\\begin{aligned}\n & \\max & 18x_1 && + && 12.5x_2 & \n\\\\\n & \\ \\text{s.t.} & x_1 && + && x_2 & \\leq 20\n\\\\\n & & x_1 && && & \\leq 12\n\\\\\n & & && && x_2 & \\leq 16\n\\\\\n & & && && x_1,x_2 & \\geq 0\n\\end{aligned}\n$$\nTo form the dual, we need to \n\\\\\n- change the maximization to a minimization,\n\\\\\n- switch the coefficients of the objective function and the coefficients on the right-hand sides of the inequalities, and\n\\\\\n- replace every $\\leq$ with $\\geq$.\n\nThe original linear program (in standard form) can be rewritten in a compact form as\n$$\n\\begin{aligned}\n & \\max & c^Tx & \n\\\\\n & \\ \\text{s.t.} & Ax & \\leq b\n\\\\\n & & x & \\geq 0,\n\\end{aligned}\n$$\nwhere $c=\\begin{pmatrix}18 \\\\12.5 \\end{pmatrix}$, $A=\\begin{pmatrix}1 & 1 & 0 \\\\1 & 0 & 1 \\end{pmatrix}$, $b=\\begin{pmatrix}20 \\\\12 \\\\16 \\end{pmatrix}$, and $x=\\begin{pmatrix}x_1 \\\\x_2 \\end{pmatrix}$.\n\nThese vectors and matrix are exactly what we need for the dual:\n$$\n\\begin{aligned}\n & \\min & 20y_1 && + && 12y_2 && + && 16y_3 & \n\\\\\n & \\ \\text{s.t.} & y_1 && + && y_2 && && & \\geq 18\n\\\\\n & & y_1 && && && + && y_3 & \\geq 12.5\n\\\\\n & & && && && && y_1,y_2,y_3 & \\geq 0\n\\end{aligned}\n$$", "meta": {"hexsha": "6cd5fc52235d9eceeef72503d8c403f6ea1b0ca2", "size": 1189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge2/Ex.29.4-1.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge2/Ex.29.4-1.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge2/Ex.29.4-1.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7708333333, "max_line_length": 200, "alphanum_fraction": 0.56686291, "num_tokens": 487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.8902942253943279, "lm_q1q2_score": 0.831886617446585}}
{"text": "\n\\subsection{Kernels and images}\n\nThe kernel of a linear operator is the set of vectors such that:\n\n\\(Mv=0\\)\n\nThe kernel is also called the nullspace.\n\nThis can be shown as \\(\\ker (M)\\)\n\nThe image of a linear operator is the set of vectors \\(w\\) such that:\n\n\\(Mv=w\\).\n\nThis can be shown as \\(\\Im (M)\\)\n\nWe also know that:\n\n\\(span (M)=\\ker (M)+\\Im (M)\\)\n\n", "meta": {"hexsha": "f00a8de6014886fce1d55a411ab3cfdaaa3c4cb8", "size": 354, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/endomorphisms/01-04-kernelImage.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/endomorphisms/01-04-kernelImage.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/endomorphisms/01-04-kernelImage.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.0909090909, "max_line_length": 69, "alphanum_fraction": 0.6553672316, "num_tokens": 107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9719924761487654, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.8318808719817316}}
{"text": "\\section*{Ex.2.4}\n\\subsection*{What is the expected number of elements in $L[h(x)]$ if $x \\in S$}\n\nThe expected number of elements is\n\\begin{align*}\nE\\left[ \\abs*{L[(h(x))]} \\right] \n       &= \\sum_{y\\in S} P(h(y) = h(x)) \\\\\n       &= 1 + \\sum_{y\\in S\\backslash\\{x\\}} P(h(y) = h(x)) \\\\\n       &\\leq 1 + \\frac{n-1}{m} < 2\n\\end{align*}\nThe first equality is the same as in the notes. For the next equality we used the assumption that $x\\in S$, which will give a collision with probability 1. Hence that element is extracted. The last equality comes from the fact that $h$ is universal hence each collision probability is less than $1/m$ and there are $n-1$ elements in the sum.\n\n\\emph{What is the bound if $h$ is 2 universal?}\n\\\\\nThe calculations would be the same, the only thing that will change is where the inequality sign is. For 2 universal the probability is $P(h(x)=h(y))\\leq \\frac{2}{m}$. There are $n-1$ of those probabilities in the sum, hence the result would be\n$$\nE\\left[ \\abs*{L[(h(x))]} \\right]  \\leq 1 + \\frac{2(n-1)}{m}\n$$", "meta": {"hexsha": "532d01c8c9bbec1e928b1de618d3bd91e92cf3a6", "size": 1038, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge3/Ex.2.4.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge3/Ex.2.4.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge3/Ex.2.4.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.6666666667, "max_line_length": 341, "alphanum_fraction": 0.6608863198, "num_tokens": 344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897459384732, "lm_q2_score": 0.8840392802184581, "lm_q1q2_score": 0.831695089836354}}
{"text": "\n\\subsection{Tensor contraction}\n\nWe have a vector \\(v\\in V\\) and \\(w\\in V^*\\).\n\n\\(\\mathbf v=\\sum_i v^i \\mathbf e_i\\)\n\n\\(\\mathbf w=\\sum_i w_i \\mathbf f^i\\)\n\n\\(\\mathbf w\\mathbf v=[\\sum_i v^i \\mathbf e_i][\\sum_i w_i \\mathbf f^i]\\)\n\n\\(\\mathbf w\\mathbf v=\\sum_i \\sum_j [v^i \\mathbf e_i][w_j \\mathbf f^j]\\)\n\n\\(\\mathbf w\\mathbf v=\\sum_i \\sum_j v^i w_j \\mathbf e_i\\mathbf f^j\\)\n\nWe use the dual basis so:\n\n\\(\\mathbf w\\mathbf v=\\sum_i \\sum_j v^i w_j \\mathbf e_i\\mathbf e^j\\)\n\n\\(\\mathbf w\\mathbf v=\\sum_i \\sum_j v^i w_j \\delta_i^j\\)\n\nWe can see that this value is unchanged when there is a change in basis.\n\nWhat if these were both from \\(V\\)?\n\n\\(\\mathbf v=\\sum_i v^i \\mathbf e_i\\)\n\n\\(\\mathbf w=\\sum_i w^i \\mathbf e_i\\)\n\n\\(\\mathbf w\\mathbf v=[\\sum_i v^i \\mathbf e_i][\\sum_i w^i \\mathbf e_i]\\)\n\n\\(\\mathbf w\\mathbf v=\\sum_i \\sum_j v^i w^j \\mathbf e_i\\mathbf e_i\\)\n\nThis term is dependent on the basis, and so we do not contract.\n\nSo if we have \\(v_iw^i\\), we can contract, because the result (calculated from the components) does not depend on the basis.\n\nBut if we have \\(v_iw_i\\), the result (calcualted from the components) will change depending on the choice of basis.\n\nWe define a new object\n\n\\(c=\\sum_i w^iv_i\\)\n\nThis new term, c, does not depend on \\(i\\), and so we have contracted the index.\n\n", "meta": {"hexsha": "446a0345980db1e408d341214124f113b899d0df", "size": 1290, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/tensors/03-03-contraction.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/tensors/03-03-contraction.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/tensors/03-03-contraction.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0434782609, "max_line_length": 124, "alphanum_fraction": 0.6782945736, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.8947894654011352, "lm_q1q2_score": 0.8316534803009533}}
{"text": "\n\\subsection{Random variables}\n\n\\subsubsection{Defining variables}\n\nWe have a sample space, \\(\\Omega \\). A random variable \\(X\\) is a mapping from the sample space to the real numbers:\n\n\\(X: \\Omega \\rightarrow \\mathbb{R}\\)\n\nWe can then define the set of elements in \\(\\Omega \\). As an example, take a coin toss and a die roll. The sample space is:\n\n\\(\\{H1,H2,H3,H4,H5,H6,T1,T2,T3,T4,T5,T6\\}\\)\n\nA random variable could give us just the die value, such that:\n\n\\(X(H1)=X(T1)=1\\)\n\nWe can define this more precisely using set-builder notation, by saying the following is defined for all\t \\(c\\in \\mathbb{R}\\):\n\n\\(\\{\\omega |X(\\omega )\\le c\\}\\)\n\nThat is, for any number random variable map \\(X\\), there is a corresponding subset of \\(\\Omega \\) containing the \\(\\omega \\)s in \\(\\Omega \\) which map to less than \\(c\\).\n\n\\subsubsection{Multiple variables}\n\nMultiple variables can be defined on the sample space. If we rolled a die we could define variables for\n\n\\begin{itemize}\n\\item Whether it was odd/even\n\\item Number on the die\n\\item Whether it was less than 3\n\\end{itemize}\n\nWith more die we could add even more variables\n\n\\subsubsection{Derivative variables}\n\nIf we define a variable \\(X\\), we can also define another variable \\(Y=X^2\\).\n\n", "meta": {"hexsha": "15310eb3e11469a9db52611dabe2dd77840e03a1", "size": 1234, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityVariables/01-01-variables.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/probabilityVariables/01-01-variables.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/probabilityVariables/01-01-variables.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.85, "max_line_length": 170, "alphanum_fraction": 0.7131280389, "num_tokens": 345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9674102571131691, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.8316475299116699}}
{"text": "\\section{Implementation}\n\\label{sec:implementation}\n\n\\subsection{Dataset Generation}\nWe use an artificially generated dataset with $P$ examples and $N$ features with normally distributed values.\nThe labels are not chosen randomly, but determined using a teacher weights vector $\\bm{\\mathsf{w}}^*$ as $S^\\mu = sign(\\mathsf{w}^{*} \\cdotp \\xi^\\mu)$.\nThe obtained dataset is by construction linearly separable for $\\bm{\\mathsf{w}} = \\bm{\\mathsf{w}}^*$.\n\nWe chose $\\bm{\\mathsf{w}}^*$ such that its norm is constant, for example $||\\bm{\\mathsf{w}}^*||^2 = N$.\nSince we initialize $\\bm{\\mathsf{w}} = \\overrightarrow{0}$, we have that the distance between the student and the teacher perceptron is constant:\n\\begin{gather*}\n    \\bm{\\mathsf{w}} = \\overrightarrow{0} \\in \\mathbb{R}^N \\\\\n    distance(\\bm{\\mathsf{w}}, \\bm{\\mathsf{w}}^*) = || \\bm{\\mathsf{w}} - \\bm{\\mathsf{w}}^* || = || \\bm{\\mathsf{w}}^*|| = \\sqrt{N}\n\\end{gather*}\nFor simplicity, we chose $\\bm{\\mathsf{w}^*} = \\overrightarrow{1} \\in \\mathbb{R}^N$.\n\n\\subsection{Perceptron Training}\nTo implement the MinOver algorithm we started from the code written for the Rosenblatt perceptron in the last assignment.\nAs for the Rosenblatt perceptron, we initialize the weights vector of the student perceptron with zeros.\nThen, we run the training procedure for number of epochs (where $epochs = n_{max} * P$).\nAt each epoch, we compute the stability of each example in the dataset (for performance reasons and to avoid the division by the norm of $\\bm{\\mathsf{w}}$, we parallelize the computation as matrix operations instead of iterating over the elements in the dataset) and update the weights using the example with the minimum stability.\nWe terminate the training if the last update of the weights (normalized by the current norm) is smaller than a certain threshold (we chose $min_{update} = 0.001$), since the update is in practice never equal to zero for numerical problems.\n\nThe algorithm differs from the Rosenblatt's one since it performs an update at each step, whether the perceptron is already giving the correct classification or not (it could not have reached the optimum stability).\n\n\\subsection{Experiments}\nFor a fixed value of $P$ and $N$, $n_D$ independent datasets are generated.\nA new perceptron is trained on each dataset for at most $epochs = n_{max} * P$ epochs.\nFor each dataset, we compute the generalization error $\\epsilon_g(t_{max})$ as:\n\\begin{equation}\n    \\epsilon_g(t_{max}) = \\frac{1}{\\pi} \\arccos \\bigg(\\frac{\\bm{\\mathsf{w}}(t_{max})\\;\\cdotp \\bm{\\mathsf{w}}^*}{|| \\bm{\\mathsf{w}}(t_{max}) || \\cdot || \\bm{\\mathsf{w}}^* ||} \\bigg)\n    \\label{eq:generalization_error}\n\\end{equation}\n$\\epsilon_g(t_{max})$ measures the distance of the student from the teacher perceptron and gives an indication on the accuracy for the classification of previously unseen data.\n\nMultiple experiments are run for different values of $P$ and $N$ in order to compute $\\epsilon_g(t_{max})$ as a function of $\\alpha = P / N$.\nIn other words, we study the accuracy of the perceptron in classifying previously unseen inputs as a function of the rate between the number of examples and the dimension of the input.\n\n\\subsection{Noisy dataset}\nIn real classification problems the data contains some noise.\nIt is therefore interesting to investigate the performances of the MinOver and Rosenblatt training algorithms on noisy data.\nThe implementation consists in a small change of the function that generates the dataset (\\cref{code:dataset_noise}).\nWe generate $P$ random values and then define a noise vector which contains a label $-1$ if the the randomly generated number is smaller than $\\lambda$ and $+1$ otherwise.\nThe real labels are then multiplied element-wise with the noise vector.\n", "meta": {"hexsha": "6c6753b245efcc2b5022960b56cf447be81a1e43", "size": 3743, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_2/report/03_implementation.tex", "max_stars_repo_name": "davidepedranz/neural_networks_assignments", "max_stars_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_2/report/03_implementation.tex", "max_issues_repo_name": "davidepedranz/neural_networks_assignments", "max_issues_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_2/report/03_implementation.tex", "max_forks_repo_name": "davidepedranz/neural_networks_assignments", "max_forks_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.1777777778, "max_line_length": 331, "alphanum_fraction": 0.7453913973, "num_tokens": 973, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.8976952859490984, "lm_q1q2_score": 0.8315384847366466}}
{"text": "\n\\subsection{Zero to the zero power}\nThe following example draws a graph of the function $f(x)=|x^x|$.\nThe graph shows why the convention $0^0=1$ makes sense.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nf(x) = abs(x^x)\nxrange = (-2,2)\nyrange = (-2,2)\ndraw(f,x)\n\\end{Verbatim}\n\n\\begin{center}\n\\includegraphics[scale=0.2]{zerozero.png}\n\\end{center}\n\nWe can see how $0^0=1$ results in a continuous line through $x=0$.\nNow let us see how $x^x$ behaves in the complex plane.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nf(t) = (real(t^t),imag(t^t))\nxrange = (-2,2)\nyrange = (-2,2)\ntrange = (-4,2)\ndraw(f,t)\n\\end{Verbatim}\n\n\\begin{center}\n\\includegraphics[scale=0.2]{zerozero2.png}\n\\end{center}\n", "meta": {"hexsha": "296e7a5bfd554d44bd5a23cb9eb0c3e40a468752", "size": 712, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/zerozero.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/zerozero.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/zerozero.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.9677419355, "max_line_length": 66, "alphanum_fraction": 0.691011236, "num_tokens": 251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029487, "lm_q2_score": 0.8872045892435128, "lm_q1q2_score": 0.8314977152212406}}
{"text": "%\n% Chapter 2.1\n%\n\n\\section*{2.1 Derivative and Rates of Change}\n\n\\subsection*{Tangents}\n\nThe \\textbf{tangent line} to the curve \\(y=f(x)\\) at the point \\(P(a, f(a))\\) is the line through \\(P\\) with slope \n$$m=\\lim_{x \\to a}\\frac{f(x)-f(a)}{x-a} \\Leftrightarrow m=\\lim_{h \\to 0}\\frac{f(a+h)-f(a)}{h}$$\nas long as the limit exists.\n\n\\subsection*{Velocities}\n\n$$\\text{average velocity}=\\frac{\\text{displacement}}{\\text{time}}=\\frac{f(a+h)-f(a)}{h}$$\\\\\nInstantaneous velocity at time \\(t = a\\) is defined as \n$$v(a) = \\lim_{h \\to 0}\\frac{f(a+h)-f(a)}{h}$$\n\n\\subsection*{Derivatives}\n\nThe derivative of a function \\(f\\) at a number \\(a\\), denoted by \\(f'(a)\\), is \n$$f'(a)=\\lim_{h \\to 0}\\frac{f(a+h)-f(a)}{h}$$\nif the limit exists.\n\n\\subsection*{Rates of Change}\n\nThe average rate of change of \\(y\\) with respect to \\(x\\) over the interval \\([x_1, x_2]\\) is the difference quotient\n$$\\frac{\\Delta x}{\\Delta y}=\\frac{f(x_2)-f(x_1)}{x_2-x_1}$$\n\\\\\nThe instantaneous rate of change of \\(y\\) with respect to \\(x\\) is \n$$\\lim_{\\Delta x \\to 0}\\frac{\\Delta y}{\\Delta x}=\\lim_{x_2 \\to x_1}\\frac{f(x_2)-f(x_1)}{x_2-x_1}$$\nThe derivative \\(f'(a)\\) is the instantaneous rate of change of \\(y=f(x)\\) with respect to \\(x\\) when \\(x=a\\).\n\n", "meta": {"hexsha": "5c88695fb1c6591f5e32b5a5bd7396c0dc977e49", "size": 1220, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2-1.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/2-1.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/2-1.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.8823529412, "max_line_length": 117, "alphanum_fraction": 0.6286885246, "num_tokens": 463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810496235895, "lm_q2_score": 0.8774767874818409, "lm_q1q2_score": 0.8313048799448818}}
{"text": "\\section*{Ex.3.5}\n\\subsection*{Estimate the size of the symmetric difference}\nThe symmetric difference is $(B\\backslash C)\\cup (C \\backslash B)$.\n\nWe have that \n$$\n(B\\backslash C)\\cup (C \\backslash B) = (B \\cup C)\\backslash (C \\cap B)\n$$\nHence\n\\begin{align*}\nS_{h,t}((B\\backslash C)\\cup (C \\backslash B)) \n  &= S_{h,t}((B \\cup C)\\backslash (C \\cap B))\\\\\n  &= ((S_{h,t}(B) \\cup S_{h,t}(C))\\backslash (S_{h,t}(C) \\cap S_{h,t}(B)))\n\\end{align*}\nHence the estimate would be\n$$\n[\\left|S_{h,t}(B) \\cup S_{h,t}(C)\\right| - \\left|S_{h,t}(C) \\cap S_{h,t}(B)\\right|]\\frac{m}{t}\n$$", "meta": {"hexsha": "257cfceb97850c0e96471560f239757aa0f9a6f5", "size": 570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge3/Ex.3.5.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge3/Ex.3.5.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge3/Ex.3.5.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.6666666667, "max_line_length": 94, "alphanum_fraction": 0.6070175439, "num_tokens": 238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377249197138, "lm_q2_score": 0.8670357477770336, "lm_q1q2_score": 0.8310864730982606}}
{"text": "\\subsubsection{Flux}\r\n\\noindent\r\nWe can rewrite the surface integral because $\\hat{n} = \\frac{\\vec{r_u} \\times \\vec{r_v}}{\\norm{\\vec{r_u} \\times \\vec{r_v}}}$ and $\\mathrm{d}s = \\norm{\\vec{r_u} \\times \\vec{r_v}}$.\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nSo,\r\n\\begin{equation*}\r\n\t\\iint\\limits_{S}{\\vec{F} \\cdot \\mathrm{d}s} = \\iint\\limits_{D}{\\left(\\vec{F}\\circ\\vec{r}\\right) \\cdot \\left(\\vec{r_u} \\times \\vec{r_v}\\right)\\mathrm{d}u\\mathrm{d}v}\r\n\\end{equation*}\r\nwhere $D$ is the domain of $S$ in uv-space (a uv-plane), and $\\vec{r}(u,v)$ parameterizes the surface $S$. This quantity is called the ``directed surface area integral'' or ``flux'' through $S$.\\\\\r\n\r\n\\noindent\r\nFlux tells us how much a vector field penetrates a surface. If the field is parallel to the surface (perpendicular to the normal vector) then the flux is 0. As the field and normal vector to the surface become more aligned, the flux increases. \\\\\r\n\r\n\\noindent\r\nFlux has many practical applications. One of the fundamental equations governing electricity and magnetism talks about electric flux: the amount of an electric field that goes through a surface. We will investigate this equation later.\\\\\r\n\r\n\\noindent\r\nFor example, let an electric field be $\\vec{E} = \\langle x, y, 0 \\rangle \\text{ N}/ \\text{C}$. Compute the electric flux, $\\Phi_{E}$, through the portion of the paraboloid $z=25-x^2-y^2$ above the xy-plane. Assume a unit distance of 1 meter.\r\n\\indent\r\nWe will take advantage of a paraboloid's radial symmetry and use cylindrical coordinates.\r\n\\begin{equation*}\r\n\t\\vec{r}(u,v) = \\langle u\\cos{v}, u\\sin{v}, 25 - u^2 \\rangle \\text{ where } 0 \\leq u \\leq 5 \\text{ and } 0 \\leq v \\leq 2\\pi\\end{equation*}\r\n\\begin{equation*}\r\n\t\\vec{r_u} = \\langle \\cos{v}, \\sin{v}, -2u \\rangle \\text{ and } \\vec{r_v}=\\langle -u\\sin{v}, u\\cos{v}, 0 \\rangle\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\vec{r_u} \\times \\vec{r_v} = \\langle 2u^2\\cos{v}, 2u^2\\sin{v}, 0 \\rangle\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\vec{E}\\circ\\vec{r} = \\langle u\\cos{v}, u\\sin{v}, 0 \\rangle\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\left(\\vec{E}\\circ\\vec{r}\\right) \\cdot (\\vec{r_u}) \\times \\vec{r_v}) = 2u^3\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\Phi_{E} = \\int_{0}^{2\\pi}{\\int_{0}^{5}{2u^3\\mathrm{d}u}\\mathrm{d}v} = 2\\pi\\left(\\frac{u^4}{2}\\right)\\rvert_{0}^{5} = 625\\text{ Nm}^2/\\text{C}\r\n\\end{equation*}", "meta": {"hexsha": "6abe7ca2329b3aabd497fa9dcb9c527d354f76c0", "size": 2331, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/flux.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/lineSurfaceIntegrals/flux.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/lineSurfaceIntegrals/flux.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 58.275, "max_line_length": 247, "alphanum_fraction": 0.6731016731, "num_tokens": 854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331958, "lm_q2_score": 0.8902942341267435, "lm_q1q2_score": 0.8310280723131928}}
{"text": "\\section{Derivatives of Inverse Trig Functions}\r\nInverse trig functions are defined so that composing them with their corresponding trig function gives you the identity.\r\nFor example $\\arcsin{(\\sin{x})} = x$.\r\nThe inverse of a function $f$ can be obtained by reflecting the graph of $f$ across the line $y=x$, effectively swapping the $x$ and $y$ coordinates of each point along the graph.\r\nFor functions that repeat $y$ values (i.e are not injective), we have to limit the domain of the inverse functions so they don't repeat $x$ values.\r\nSince the trig functions don't have any cusps or corners, neither will the inverse trig functions.\r\nThe slope $f^{-1}$ will the the reciprocal of the slope of $f$, since the change in $x$ in $f$ becomes the change in $y$ of $f^{-1}$ and the change in $y$ of $f$ becomes the change in $x$ of $f^{-1}$.\r\n\\begin{equation*}\r\n\t\\dd{f^{-1}}{x}\\biggr\\rvert_{f(a)} = \\frac{1}{\\dd{f}{a}\\bigr\\rvert_{a}}\r\n\\end{equation*}\r\n\r\n\r\nThis leads us to a theorem that will help us derive the derivatives of the inverse trig functions.\r\n\\begin{theorem}\r\n\tIf $f$ is differentiable at every point along an interval $I$ and its derivative is never 0 along $I$, then $f^{-1}$ exists and is differentiable on every point in $f(I)$.\r\n\\end{theorem}\r\n\r\n\\subsection{$\\arcsin$, $\\arctan$, and $\\arcsec$}\r\nLet's apply this theorem and our differentiation rules to find the derivative of $y = \\arcsin{x}$.\r\nFrom $-\\frac{\\pi}{2} < x < \\frac{\\pi}{2}$, the derivative of $f(x)=\\sin{x}$, $f^\\prime(x)=\\cos{x}$ is never 0.\r\nSo, we know by the previous theorem that $f^{-1}(x)=\\arcsin{x}$ exists and is differentiable along every point in $\\sin(-\\frac{\\pi}{2} < x < \\frac{\\pi}{2}) = -1 < x < 1$.\r\nSo, we can rearrange the equation and implicitly differentiate to find the derivative of $\\arcsin{x}$ in this interval.\r\n\\begin{align*}\r\n\ty &= \\arcsin{x} \\\\\r\n\t\\sin{y} &= x \\\\\r\n\t\\cos{(y)}y^\\prime &= 1 \\\\\r\n\ty^\\prime &= \\frac{1}{\\cos{y}} \\\\\r\n\t&= \\frac{1}{\\sqrt{1-\\sin^2{y}}} \\\\\r\n\t&= \\frac{1}{\\sqrt{1-x^2}}, -1 < x < 1.\r\n\\end{align*}\r\n\r\n\r\nWe can use the same method to find the derivative of $\\arctan{x}$, which is differentiable for all real numbers.\r\n\\begin{align*}\r\n\ty &= \\arctan{x} \\\\\r\n\t\\tan{y} &= x \\\\\r\n\t\\sec^2{(y)}y^\\prime &= 1 \\\\\r\n\ty^\\prime &= \\frac{1}{\\sec^2{y}} \\\\\r\n\t&= \\frac{1}{1+\\tan^2{y}} \\\\\r\n\t&= \\frac{1}{1+x^2}.\r\n\\end{align*}\r\n\r\n\r\nAlthough we generally use the same method for $\\arcsec$, which is differentiable for $\\abs{x}>1$, we have to be careful with out trig identities.\r\n\\begin{align*}\r\n\ty &= \\arcsec{x} \\\\\r\n\t\\sec{y} &= x \\\\\r\n\t\\sec{(y)}\\tan{(y)}y^\\prime &= 1 \\\\\r\n\ty^\\prime &= \\frac{1}{\\sec{(y)}\\tan{(y)}} \\\\\r\n\t&= \\frac{1}{x\\tan{(y)}} \\\\\r\n\t&= \\frac{1}{\\pm x\\sqrt{\\sec^2{y}-1}} \\\\\r\n\t&= \\frac{1}{\\pm x\\sqrt{x^2-1}} \\\\\r\n\t&= \\begin{cases}\r\n\t\t\\frac{1}{x\\sqrt{1-x^2}} & x > 1 \\\\\r\n\t\t\\frac{-1}{x\\sqrt{1-x^2}} & x < -1\r\n\t\\end{cases} \\\\\r\n\t&= \\frac{1}{\\abs{x}\\sqrt{1-x^2}}, \\abs{x} > 1.\r\n\\end{align*}\r\n\r\n\\subsection{$\\arccos$, $\\arccot$, and $\\arccsc$}\r\nNow that we've derived derivatives of $\\arcsin$, $\\arctan$, and $\\arcsec$, finding the derivatives of the arc-co-functions is much easier.\r\nSince trig functions and their co-functions are $\\pi/2$ radians different on the $x$-axis, arc-trig functions will be $\\pi/2$ radians different on the y-axis.\r\n\\begin{equation*}\r\n\t\\text{arccxx{($x$)}} = \\frac{\\pi}{2} - \\text{arcxxx}{(x)}.\r\n\\end{equation*}\r\nUsing our constant and sum and difference derivative rules, we can derive that the derivatives of the arc-co-functions are simply the opposite of the derivatives of their corresponding arc-functions.\r\n\\begin{table}[H]\r\n\t\\begin{center}\r\n\t\t\\begin{tabular}{ l l l }\r\n\t\t\t$\\begin{aligned}\\dd{}{x}\\arccos{x}=\\frac{-1}{\\sqrt{1-x^2}},-1<x<1\\end{aligned}$ & $\\begin{aligned}\\dd{}{x}\\arccot{x}=\\frac{-1}{1+x^2}\\end{aligned}$ & $\\begin{aligned}\\dd{}{x}\\arccsc{x}=\\frac{-1}{\\abs{x}\\sqrt{1-x^2}},\\abs{x}>1\\end{aligned}.$ \\\\\r\n\t\t\\end{tabular}\r\n\t\\end{center}\r\n\\end{table}", "meta": {"hexsha": "cd9d241f123039471ae21c9fd9659183a503dfcb", "size": 3908, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/derivatives_inv_trig_functions.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/derivatives/derivatives_inv_trig_functions.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/derivatives/derivatives_inv_trig_functions.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.5342465753, "max_line_length": 247, "alphanum_fraction": 0.636642784, "num_tokens": 1340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.8902942333990421, "lm_q1q2_score": 0.8310280650391728}}
{"text": "\\part{Antiderivatives}\n\n\\chapter{The Indefinite Integral}\n\n\\section{The Indefinite Integral}\n\nHow do we undo a derivative? If we were given the derivative of a function $ f'(x) $, how could we find the original function $ f(x) $? The answer is called the antiderivative of $ f(x) $, which we will denote by the associated capital letter $ F(x) $. \\\\\n\nAnother way to think about this question is: \"What function do I have to take the derivative of in order to get the answer?\" The antiderivative of $ f(x) = 2x $ is $ x^2 $. \\\\\n\nBut what about $ F(x) = x^2 + 1 $? This works too! In fact, since when we take the derivative of a constant, we get zero. We could have chosen any constant. As a result, we report our antiderivative in its most general form $ x^2 + C $. The constant $ C $ is an important part of the antiderivative. \\\\\n\nNotationally, we denote the operation of take the antiderivative (known as integration) as: \\\\\n\n$$\n    \\int 2x \\ dx = x^2 + C\n$$\n\nThis is also called the indefinite integral of the function $ f(x) $, or sometimes just the integral of $ f(x) $, where $ f(x) $ is called the integrand. \\\\\n\nThat was a pretty simple example, so how do we find antiderivatives of more complicated expressions? In much the same way as we did with derivatives, we can generate a set of rules for finding antiderivatives, derived simply by thinking of our familiar derivative rules in reverse. \\\\\n\n\\section{Basic Antiderivative Rules}\n\nThe power rule for derivatives multiplies by the power and then subtracts one from the power. Reversing these operations means that we add one to the power and divide by the new power. \\\\\n\n\\subsection{Reverse Power Rule}\n\n\\begin{theorem}[Reverse Power Rule]\n    \\begin{align}\n        \\int x^n \\ dx = {x^{n+1} \\over n+1} + C,\\ where\\ n \\ne -1\n    \\end{align}\n\\end{theorem}\n\n\\begin{exercise}\\nonumber\n    Find the anitiderivatives. \\\\\n\n    (a)\n    \\begin{align}\n         & \\int x^6 \\ dx \\\\\n        \\\\\n    \\end{align}\n\n    (b)\n    \\begin{align}\n         & \\int \\sqrt[4]{t} \\ dt \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (c)\n    \\begin{align}\n         & \\int {1 \\over x^{5/3}} \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\n\\subsection{Antiderivative of Zero}\n\n\\begin{theorem}[Antiderivative of Zero]\n    \\begin{align}\n        \\int 0 \\ dx = C\n    \\end{align}\n\\end{theorem}\n\n\\subsection{Antiderivative of a Constant}\n\n\\begin{theorem}[Antiderivative of a Constant]\n    \\begin{align}\n        \\int k \\ dx = kx + C,\\ where\\ k\\ is\\ any\\ constant\n    \\end{align}\n\\end{theorem}\n\n\\begin{exercise}\\nonumber\n    Find the anitiderivatives.\n\n    \\begin{align}\n         & \\int \\pi \\ dx \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\n\\subsection{Multiplicative Constants}\n\n\\begin{theorem}[Multiplicative Constantst]\n    \\begin{align}\n        \\int kf(x) \\ dx = k \\int f(x) \\ dx\n    \\end{align}\n\\end{theorem}\n\n\\begin{exercise}\\nonumber\n    Find the anitiderivatives. \\\\\n\n    (a)\n    \\begin{align}\n         & \\int 4x^7 \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (b)\n    \\begin{align}\n         & \\int {\\pi \\over \\sqrt{t}} \\ dt \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\n\\subsection{Sum / Difference}\n\n\\begin{theorem}[Sum / Difference]\n    \\begin{align}\n        \\int (f(x) \\pm g(x)) \\ dx = \\int f(x) \\ dx \\pm \\int g(x) \\ dx\n    \\end{align}\n\\end{theorem}\n\n\\begin{exercise}\\nonumber\n    Find the anitiderivatives. \\\\\n\n    (a)\n    \\begin{align}\n         & \\int (3x^2 + 5) \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (b)\n    \\begin{align}\n         & \\int \\left({1 \\over x^3} - {2 \\over x^2}\\right) \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\n\\subsection{Trigonometric Functions}\n\n\\begin{theorem}[Trigonometric Functions]\n    \\begin{align}\n        \\int sin(x) \\ dx       & = -cos(x) + C \\\\\n        \\int cos(x) \\ dx       & = sin(x) + C  \\\\\n        \\int csc^2(x) \\ dx     & = -cot(x) + C \\\\\n        \\int sec^2(x) \\ dx     & = tan(x) + C  \\\\\n        \\int sec(x)tan(x) \\ dx & = sec(x) + C  \\\\\n        \\int csc(x)cot(x) \\ dx & = -csc(x) + C\n    \\end{align}\n\\end{theorem}\n\n\\subsection{Exponential / Logarithmic}\n\n\\begin{theorem}[Exponential / Logarithmic]\n    \\begin{align}\n        \\int a^xln(a) \\ dx         & = a^x + C      \\\\\n        \\int e^xln(e) \\ dx         & = e^x + C      \\\\\n        \\int {1 \\over xln(a)} \\ dx & = log_a|x| + C \\\\\n        \\int {1 \\over x} \\ dx      & = ln|x| + C\n    \\end{align}\n\\end{theorem}\n\n\\begin{exercise}\\nonumber\n    Find the anitiderivatives. \\\\\n\n    (a)\n    \\begin{align}\n         & \\int 4^xln(4) + 5e^x - {6 \\over x} \\ dx \\\\\n        \\\\\n    \\end{align}\n\n    (b)\n    \\begin{align}\n         & \\int 3^z \\ dz \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\nSometimes we need to manipulate the integral a little bit before we can apply the rules. \\\\\n\n\\begin{exercise}\\nonumber\n    Find the anitiderivatives. \\\\\n\n    (a)\n    \\begin{align}\n         & \\int {2s^3 - 5s^4 \\over 3s^2} \\ ds \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (b)\n    \\begin{align}\n         & \\int \\left({1 \\over x} + {1 \\over x^2}\\right)\\left(3 + 2x^2\\right) \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\n\\chapter{Chain Rule in Reverse}\n\n\\section{Chain Rule in Reverse}\n\nThe derivative of $ f(u(x)) $ is $ f'(u(x))u'(x) $, so \\\\\n\n\\begin{theorem}[Chain Rule in Reverse]\n    \\begin{align}\n        \\int f'(u(x))u'(x) \\ dx = f(u(x)) + C\n    \\end{align}\n\\end{theorem}\n\nNotice that in the integration, the $ u'(x) $ piece disappears, being absorbed back into $ f(x) $. The steps for finding the antiderivative of composition functions are as follows: \\\\\n\n\\begin{enumerate}\n    \\item\n          Identify the core layer $ u(x) $. \\\\\n\n    \\item\n          Identify the derivative of the core layer $ u'(x) $. \\\\\n\n    \\item\n          Identify the outer layer $ f' $, and integrate $ f' $ leaving $ u(x) $ inside. \\\\\n\\end{enumerate}\n\n\\begin{exercise}\\nonumber\n    Find the anitiderivatives. \\\\\n\n    (a)\n    \\begin{align}\n         & \\int (6x^2 + 1)sin(2x^3 + x) \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (b)\n    \\begin{align}\n         & \\int sec^2(4t) \\ dt \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (c)\n    \\begin{align}\n         & \\int 4x^3(3x^4 - 1)^{14} \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (d)\n    \\begin{align}\n         & \\int {e^{1 \\over x} \\over 4x^2} \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\n\\begin{exercise}\\nonumber\n    Integrate in one step. \\\\\n\n    \\begin{align}\n         & \\int e^{-2t} + sin(3t) + cos\\left({1 \\over 4}t\\right) \\ dt \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\n\\chapter{The Method of Substitution}\n\n\\section{The Method of Substitution}\n\nThe idea behind the method of substitution is to change a difficult integral in terms of one variable into an easier integral in terms of some other variable using a substitution. \\\\\n\n\\begin{theorem}[The Method of Substitution]\n    \\begin{align}\n        \\int f'(u(x)) \\ {du \\over dx} = \\int f'(u) \\ du\n    \\end{align}\n\\end{theorem}\n\n\\begin{exercise}\\nonumber\n    The method of substitution.\n\n    \\begin{align}\n        \\int (6x + 4)(3x^2 + 4x)^5 \\ dx\n    \\end{align}\n\n    \\begin{enumerate}\n        \\item\n              Identify the core layer $ u(x) = 3x^2 +4x $. \\\\\n\n        \\item\n              Find the derivative of the core $ {du \\over dx} = 6x + 4 $. \\\\\n\n        \\item\n              Transform from an integral in $ x $ to an integral in the new variable $ u $ using the change of variable theorem. \\\\\n              \\begin{align}\n                   & \\int (6x + 4)(3x^2 + 4x)^5 \\ dx \\\\\n                   & = \\int {du \\over dx}u^5 \\ dx    \\\\\n                   & = \\int u^5 \\ du                 \\\\\n                   & = {u^6 \\over 6} + C\n              \\end{align}\n\n        \\item\n              Convert back to the original variable by substituting $ u(x) $ back in.\n              \\begin{align}\n                   & {u^6 \\over 6} + C             \\\\\n                   & = {(3x^2 + 4x)^6 \\over 6} + C\n              \\end{align}\n    \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\\nonumber\n    Calculate using the method of substitution. \\\\\n\n    (a)\n    \\begin{align}\n         & \\int sin(x)e^{5cos(x)} \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (b)\n    \\begin{align}\n         & \\int {x \\over (5x + 7)^3} \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (c)\n    \\begin{align}\n         & \\int xsec(3x^2)tan(3x^2) \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (d)\n    \\begin{align}\n         & \\int {-{1 \\over t^2} + 1 \\over \\sqrt{{1 \\over t} + t}} \\ dt \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (e)\n    \\begin{align}\n         & \\int (1 + 900x)^{1/15000} \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (f)\n    \\begin{align}\n         & \\int sin(\\theta)(cos^3\\theta - cos^5\\theta) \\ d\\theta \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (g)\n    \\begin{align}\n         & \\int {7x \\over 4x^2 + 9} \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (h)\n    \\begin{align}\n         & \\int (2x + 5) \\cdot \\sqrt[3]{3x + 1} \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\n\\chapter{Definite Integrals}\n\n\\section{Riemann Sum}\n\nSuppose we wanted to find the area underneath the graph of a straight line that lies above the x-axis, between $ x = a $ and $  x = b $. Since we have formulas for finding the area of basic shapes, we can easily figure this out. \\\\\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}\n        \\fill[yellow](1,0) -- (1,2) -- (3.5,4.5) to[out=45,in=35] (4,4.8) -- (4,0) -- cycle;\n        \\draw[thick,-latex] (-2,0) -- (6,0);\n        \\draw[thick,-latex] (0,-1) -- (0,6);\n        \\draw[very thick,black] (-0.8,0.2) -- (3.5,4.5) to[out=45,in=135] node[pos=0.5,above,font=\\large]{$ f(x) $} (5,4.5);\n        \\draw[very thick,dashed,gray]\n        (1,0) node[below,black] {$a$} -- (1,2)\n        (4,0) node[below,black] {$b$} -- (4,4.8);\n    \\end{tikzpicture}\n\\end{figure}\n\nBut what about finding the area underneath the graph of a general curve $ y = f(x) $ and above the x-axis between $  x = a $ and $ x = b $? \\\\\n\nBernhard Riemann's idea was to carve up the desired area into rectangle and user their area to estimate the true area. He called this the Riemann Sum and it goes as follows: \\\\\n\n\\begin{enumerate}\n    \\item\n          Create a partition $ P $, dividing up the interval $ [a, b] $ into n subintervals $ I_1, I_2, \\dots, I_n $. \\\\\n\n    \\item\n          Choose an x-value (called it $ x_k $) in each subinterval $ I_k $. \\\\\n\n    \\item\n          For each $ x_k $ we choose, draw a rectangle with height $ f(x_k) $ and a width spanning $ I_k $ ($ \\Delta x_k $). \\\\\n\\end{enumerate}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=1.2]\n        \\def\\a{1.7}\n        \\def\\b{5.7}\n        \\def\\c{3.7}\n        \\def\\L{0.5} % width of interval\n\n        \\pgfmathsetmacro{\\Va}{2*sin(\\a r+1)+4} \\pgfmathresult\n        \\pgfmathsetmacro{\\Vb}{2*sin(\\b r+1)+4} \\pgfmathresult\n        \\pgfmathsetmacro{\\Vc}{2*sin(\\c r+1)+4} \\pgfmathresult\n\n        \\draw[->,very thick] (-0.5,0) -- (7,0) coordinate (x axis) node[below] {$x$};\n        \\draw[->,very thick] (0,-0.5) -- (0,7) coordinate (y axis) node[left] {$y$};\n        \\foreach \\f in {1.7,2.2,...,6.2} {\\pgfmathparse{2*sin(\\f r+1)+4} \\pgfmathresult\n                \\draw[fill=blue!20] (\\f-\\L/2,\\pgfmathresult |- x axis) -- (\\f-\\L/2,\\pgfmathresult) -- (\\f+\\L/2,\\pgfmathresult) -- (\\f+\\L/2,\\pgfmathresult |- x axis) -- cycle;}\n        \\node at (\\a-\\L/2,-5pt) {\\footnotesize{$a$}};\n        \\node at (\\b+\\L/2+\\L,-5pt) {\\footnotesize{$b$}};\n        \\draw[blue,very thick,smooth,samples=100,domain=1.45:6.2] plot(\\x,{2*sin(\\x r+1)+4});\n    \\end{tikzpicture}\n\\end{figure}\n\nThe area of rectangle $ k $ is:\n$$\n    f(x_k) \\cdot \\Delta x_k\n$$\n\nThe total area of all the rectangles is:\n$$\n    f(x_1) \\cdot \\Delta x_1 + f(x_2) \\cdot \\Delta x_2 + \\dots + f(x_n) \\cdot \\Delta x_n = \\sum_{k=1}^{n} f(x_k) \\cdot \\Delta x_k\n$$\n\n\\begin{exercise}\\nonumber\n    Use the Riemann Sum to estimate the area below $ y = sin({1 \\over 2}x) $ and above the x-axis, between $ x = 0 $ and $ x = 2\\pi $. Use a partition of 4 subintervals. \\\\\n\n    \\begin{figure}[H]\n        \\centering\n        \\begin{tikzpicture}[\n                declare function={\n                        f(\\x)=sin(deg(0.5*\\x));\n                    },\n                xscale=0.5\n            ]\n            \\begin{axis}[\n                    axis lines = middle,\n                    xtick ={1,4},\n                    ytick ={0},\n                    xticklabels = {$a$,$b$},\n                    ymin = -0.2,\n                    ymax = 2,\n                    xmin = -0.2,\n                    xmax = 7,\n                    x=2cm,y=2cm,\n                    axis line style = thick,\n                ]\n\n                \\addplot [\n                    domain=0:6.3,\n                    samples=300,\n                    line width=1pt,\n                    fill=red, draw=none,\n                    fill opacity=0.2\n                ] {f(x)} \\closedcycle;\n\n                \\addplot [\n                    domain=0:6.3,\n                    samples=300,\n                    line width = 1pt, red\n                ] {f(x)};\n\n                \\addplot [\n                    ycomb, thick, red,\n                    no markers,\n                    samples at={1,3,5}\n                ] {f(x)};\n            \\end{axis}\n            \\draw[dashed,red] (2.4, 1.3) -- (0.3, 1.3);\n            \\draw[dashed,red] (6.1, 2.4) -- (2.4, 2.4) -- (2.4, 0);\n            \\draw[dashed,red] (10.2, 1.55) -- (6.4, 1.55);\n            \\draw[dashed,red] (12.9, 0.4) -- (10.4, 0.4);\n        \\end{tikzpicture}\n    \\end{figure}\n\n    \\begin{align}\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\nSo, what happens as make the rectangles skinnier? \\\\\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=0.6,\n            declare function={\n                    f(\\x)=2+sin(deg(\\x-2))+sin(deg(3*\\x))/2+sin(deg(5*\\x))/8 + sin(deg(7*\\x))/28;\n                }\n        ]\n        \\begin{axis}[\n                axis lines = middle,\n                xtick ={1,4},\n                ytick ={0},\n                xticklabels = {$a$,$b$},\n                ymin = -0.2,\n                ymax = 3.7,\n                xmin = -0.2,\n                xmax = 5.2,\n                x=2cm,y=2cm,\n                axis line style = thick,\n            ]\n\n            \\addplot [\n                domain=1:4,\n                samples=300,\n                line width=1pt,\n                fill=red, draw=none,\n                fill opacity=0.2\n            ] {f(x)} \\closedcycle;\n\n            \\addplot [\n                domain=0:5,\n                samples=300,\n                line width = 1pt, red\n            ] {f(x)};\n\n            \\addplot [\n                ycomb, thick, red,\n                no markers,\n                samples at={1,2,...,4}\n            ] {f(x)};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=0.6,\n            declare function={\n                    f(\\x)=2+sin(deg(\\x-2))+sin(deg(3*\\x))/2+sin(deg(5*\\x))/8 + sin(deg(7*\\x))/28;\n                }\n        ]\n        \\begin{axis}[\n                axis lines = middle,\n                xtick ={1,4},\n                ytick ={0},\n                xticklabels = {$a$,$b$},\n                ymin = -0.2,\n                ymax = 3.7,\n                xmin = -0.2,\n                xmax = 5.2,\n                x=2cm,y=2cm,\n                axis line style = thick,\n            ]\n\n            \\addplot [\n                domain=1:4,\n                samples=300,\n                line width=1pt,\n                fill=red, draw=none,\n                fill opacity=0.2\n            ] {f(x)} \\closedcycle;\n\n            \\addplot [\n                domain=0:5,\n                samples=300,\n                line width = 1pt, red\n            ] {f(x)};\n\n            \\addplot [\n                ycomb, thick, red,\n                no markers,\n                samples at={1,1.5,...,4}\n            ] {f(x)};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=0.6,\n            declare function={\n                    f(\\x)=2+sin(deg(\\x-2))+sin(deg(3*\\x))/2+sin(deg(5*\\x))/8 + sin(deg(7*\\x))/28;\n                }\n        ]\n        \\begin{axis}[\n                axis lines = middle,\n                xtick ={1,4},\n                ytick ={0},\n                xticklabels = {$a$,$b$},\n                ymin = -0.2,\n                ymax = 3.7,\n                xmin = -0.2,\n                xmax = 5.2,\n                x=2cm,y=2cm,\n                axis line style = thick,\n            ]\n\n            \\addplot [\n                domain=1:4,\n                samples=300,\n                line width=1pt,\n                fill=red, draw=none,\n                fill opacity=0.2\n            ] {f(x)} \\closedcycle;\n\n            \\addplot [\n                domain=0:5,\n                samples=300,\n                line width = 1pt, red\n            ] {f(x)};\n\n            \\addplot [\n                ycomb, thick, red,\n                no markers,\n                samples at={1,1.1,...,4}\n            ] {f(x)};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{figure}\n\nAs the width of the rectangles decreases, the accuracy of the estimate increases. So, what happens if we let the width of all the rectangles in the partition approach 0? \\\\\n\nNotationally:\n\n$$\n    \\lim\\limits_{\\substack{n \\rightarrow \\infty \\\\ \\left\\|p\\right\\| \\rightarrow 0}} \\sum_{k=1}^{n} f(x_k) \\cdot \\Delta x_k\n$$\n\nWe should get the exact area, that is, our estimate is no longer just an estimate. \\\\\n\nNotationally, instead of limit, we write it as: \\\\\n\n\\begin{theorem}[Definite Integral]\n    \\begin{align}\n        \\int_{x = a}^{b} f(x) \\ dx\n    \\end{align}\n\\end{theorem}\n\n\\section{Definite Integral}\n\nFor all of the following, suppose that $ k $, $ a $, $ b $, and $ c $ are constants with $ a < b < c $, and that $ f $ and $ g $ are integrable functions on the domain of integration. \\\\\n\n\\begin{theorem}[Definite Integral]\n    \\begin{align}\n        \\int_a^b k \\ dx = (b - a)k\n    \\end{align}\n\\end{theorem}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=0.6,\n            declare function={\n                    f(\\x)=2;\n                }\n        ]\n        \\begin{axis}[\n                axis lines = middle,\n                xtick ={1,4},\n                ytick ={0},\n                xticklabels = {$a$,$b$},\n                ymin = -0.2,\n                ymax = 3.7,\n                xmin = -0.2,\n                xmax = 5.2,\n                x=2cm,y=2cm,\n                axis line style = thick,\n            ]\n\n            \\addplot [\n                domain=1:4,\n                samples=300,\n                line width=1pt,\n                fill=red, draw=none,\n                fill opacity=0.2\n            ] {f(x)} \\closedcycle;\n\n            \\addplot [\n                domain=0:5,\n                samples=300,\n                line width = 1pt, red\n            ] {f(x)};\n\n            \\addplot [\n                ycomb, thick, red,\n                no markers,\n                samples at={1,4}\n            ] {f(x)};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{figure}\n\n\\begin{theorem}[Definite Integral]\n    \\begin{align}\n        \\int_a^a f(x) \\ dx = 0\n    \\end{align}\n\\end{theorem}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=0.6,\n            declare function={\n                    f(\\x)=0.5 * sin(deg(\\x)) + 2;\n                }\n        ]\n        \\begin{axis}[\n                axis lines = middle,\n                xtick ={1},\n                ytick ={0},\n                xticklabels = {$a$},\n                ymin = -0.2,\n                ymax = 3.7,\n                xmin = -0.2,\n                xmax = 5.2,\n                x=2cm,y=2cm,\n                axis line style = thick,\n            ]\n\n            \\addplot [\n                domain=0:5,\n                samples=300,\n                line width = 1pt, red\n            ] {f(x)};\n\n            \\addplot [\n                ycomb, thick, red,\n                no markers,\n                samples at={1}\n            ] {f(x)};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{figure}\n\n\\begin{theorem}[Definite Integral]\n    \\begin{align}\n        \\int_b^a f(x) \\ dx = -\\int_a^b f(x) \\ dx\n    \\end{align}\n\\end{theorem}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=0.6,\n            declare function={\n                    f(\\x)=0.5 * sin(deg(\\x)) + 2;\n                }\n        ]\n        \\begin{axis}[\n                axis lines = middle,\n                xtick ={1,4},\n                ytick ={0},\n                xticklabels = {$a$,$b$},\n                ymin = -0.2,\n                ymax = 3.7,\n                xmin = -0.2,\n                xmax = 5.2,\n                x=2cm,y=2cm,\n                axis line style = thick,\n            ]\n\n            \\addplot [\n                domain=1:4,\n                samples=300,\n                line width=1pt,\n                fill=red, draw=none,\n                fill opacity=0.2\n            ] {f(x)} \\closedcycle;\n\n            \\addplot [\n                domain=0:5,\n                samples=300,\n                line width = 1pt, red\n            ] {f(x)};\n\n            \\addplot [\n                ycomb, thick, red,\n                no markers,\n                samples at={1,4}\n            ] {f(x)};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{figure}\n\n\\begin{theorem}[Definite Integral]\n    \\begin{align}\n        \\int_a^c f(x) \\ dx = \\int_a^b f(x) \\ dx + \\int_b^c f(x) \\ dx\n    \\end{align}\n\\end{theorem}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=0.6,\n            declare function={\n                    f(\\x)=0.5 * sin(deg(\\x)) + 2;\n                }\n        ]\n        \\begin{axis}[\n                axis lines = middle,\n                xtick ={1,2,4},\n                ytick ={0},\n                xticklabels = {$a$,$b$,$c$},\n                ymin = -0.2,\n                ymax = 3.7,\n                xmin = -0.2,\n                xmax = 5.2,\n                x=2cm,y=2cm,\n                axis line style = thick,\n            ]\n\n            \\addplot [\n                domain=1:2,\n                samples=300,\n                line width=1pt,\n                fill=red, draw=none,\n                fill opacity=0.2\n            ] {f(x)} \\closedcycle;\n\n            \\addplot [\n                domain=2:4,\n                samples=300,\n                line width=1pt,\n                fill=blue, draw=none,\n                fill opacity=0.2\n            ] {f(x)} \\closedcycle;\n\n            \\addplot [\n                domain=0:5,\n                samples=300,\n                line width = 1pt, red\n            ] {f(x)};\n\n            \\addplot [\n                ycomb, thick, red,\n                no markers,\n                samples at={1,2,4}\n            ] {f(x)};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{figure}\n\n\\begin{theorem}[Definite Integral]\n    \\begin{align}\n        \\int_a^b kf(x) \\ dx = k \\int_a^b f(x) \\ dx\n    \\end{align}\n\\end{theorem}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=0.6,\n            declare function={\n                    f(\\x)=0.5 * sin(deg(\\x)) + 2;\n                    g(\\x)=0.5 * sin(deg(\\x)) + 1;\n                }\n        ]\n        \\begin{axis}[\n                axis lines = middle,\n                xtick ={1,4},\n                ytick ={0},\n                xticklabels = {$a$,$b$},\n                ymin = -0.2,\n                ymax = 3.7,\n                xmin = -0.2,\n                xmax = 5.2,\n                x=2cm,y=2cm,\n                axis line style = thick,\n            ]\n\n            \\addplot [\n                domain=0:5,\n                samples=300,\n                line width = 1pt, red\n            ] {f(x)};\n\n            \\addplot [\n                domain=0:5,\n                samples=300,\n                line width = 1pt, red\n            ] {g(x)};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{figure}\n\n\\begin{theorem}[Definite Integral]\n    \\begin{align}\n        \\int_a^b (f(x) \\pm g(x))  \\ dx = \\int_a^b f(x) \\ dx \\pm \\int_a^b g(x) \\ dx\n    \\end{align}\n\\end{theorem}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=0.6,\n            declare function={\n                    f(\\x)=0.5 * sin(deg(\\x)) + 1;\n                    g(\\x)=2;\n                    h(\\x)=0.5 * sin(deg(\\x)) + 3;\n                }\n        ]\n        \\begin{axis}[\n                axis lines = middle,\n                xtick ={1,4},\n                ytick ={0},\n                xticklabels = {$a$,$b$},\n                ymin = -0.2,\n                ymax = 3.7,\n                xmin = -0.2,\n                xmax = 5.2,\n                x=2cm,y=2cm,\n                axis line style = thick,\n            ]\n\n            \\addplot [\n                domain=0:5,\n                samples=300,\n                line width = 1pt, red\n            ] {f(x)};\n\n            \\addplot [\n                domain=0:5,\n                samples=300,\n                line width = 1pt, red\n            ] {g(x)};\n            \\addplot [\n                domain=0:5,\n                samples=300,\n                line width = 1pt, red\n            ] {h(x)};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{figure}\n\n\\begin{exercise}\\nonumber\n    Evaluate. \\\\\n\n    (a)\n    \\begin{align}\n         & \\int_1^2 {1 \\over t} \\ dt \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (b)\n    \\begin{align}\n         & \\int_{-2}^1 x^3 \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\                   \\\\\n    \\end{align}\n\n    (c)\n    \\begin{align}\n         & \\int_1^5 s(s^2 + 1) \\ ds \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (d)\n    \\begin{align}\n        \\int_{\\sqrt{ln(2)}}^{\\sqrt{ln(4)}} xe^{x^2} \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (e)\n    \\begin{align}\n         & \\int_x^{x^2} sin(t) \\ dt \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\n    (f)\n    \\begin{align}\n        \\int_5^{13} (x + 1)\\sqrt{2x - 1} \\ dx \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\n\\chapter{Area Under a Curve}\n\n\\section{Area Under a Curve}\n\n\\begin{exercise}\\nonumber\n    Find the area below the curve $ f(x) = sin(x) $ and above the x-axis between $ x = {\\pi \\over 2} $ and $ x = \\pi $. \\\\\n\n    \\begin{figure}[H]\n        \\centering\n        \\begin{tikzpicture}[scale=0.8,yscale=0.2]\n            \\draw[->] (-1,0) -- (8,0) node[right] {$ x $};\n            \\draw[->] (0,-10) -- (0,30) node[above] {$ y $};\n            \\draw[very thick,color=red,domain=-1:7] plot (\\x,{-2 * (\\x - 3.14) ^ 2 + 20});\n            \\draw[-,very thick,red] (3.14, 0) -- (3.14,20);\n            \\node at (1.5,-2) [] {$ \\pi \\over 4 $};\n            \\node at (3.14,-2) [] {$ \\pi \\over 2 $};\n            \\node at (4.8,-2) [] {$ 3\\pi \\over 4 $};\n            \\node at (6,-2) [] {$ \\pi $};\n        \\end{tikzpicture}\n    \\end{figure}\n\n    \\begin{align}\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\nWhat if we have a more interesting situation where many curves are involved? For instance, how do we find the area between two curves $ f $ and $ g $? \\\\\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}\n        \\begin{axis}[\n                xlabel={$x$},\n                ylabel={$y$},\n                xtick={-3,0,1},\n                ytick={2},\n                samples=100,\n                domain=-4:1,\n                xmin=-4,xmax=2,\n                ymin=-1,ymax=3,\n            ]\n            \\addplot[name path=func, red, very thick, mark=none, ] {sqrt(-x+1)};\n            \\addplot[name path=line, red, very thick] {2};\n            \\addplot fill between[\n                    of = func and line,\n                    soft clip={domain=-3:0},\n                    every even segment/.style  = {gray,opacity=.4}\n                ];\n            \\draw[thick,dashed,brown] (axis cs:-3,0) -- (axis cs:-3,2);\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{figure}\n\n$$\n    \\text{Area under Upper} - \\text{Area under Lower} = \\text{Area expected}\n$$\n\n\\begin{exercise}\\nonumber\n    Calculate the area bounded by $ y = 2x + 1 $ and $ y = x^2 - 2x - 3 $. \\\\\n\n    \\begin{figure}[H]\n        \\centering\n        \\begin{tikzpicture}[scale=0.8,yscale=0.4]\n            \\draw[->] (-2,0) -- (7,0) node[right] {$ x $};\n            \\draw[->] (0,-5) -- (0,15) node[above] {$ y $};\n            \\draw[very thick,color=red,domain=-2:6] plot (\\x,{2 * (\\x) + 1});\n            \\draw[very thick,color=red,domain=-2:5] plot (\\x,{(\\x) ^ 2 - 2 * \\x - 3});\n        \\end{tikzpicture}\n    \\end{figure}\n\n    \\begin{align}\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\n\\begin{exercise}\\nonumber\n    Calculate the area bounded by $ y = -x $, $ y = \\sqrt{x} $, and $ y = -x^2 + 2 $ between $ x = 0 $ and $ x = 2 $. \\\\\n\n    \\begin{figure}[H]\n        \\centering\n        \\begin{tikzpicture}[scale=0.8]\n            \\draw[->] (-2,0) -- (5,0) node[right] {$ x $};\n            \\draw[->] (0,-4) -- (0,4) node[above] {$ y $};\n            \\draw[very thick,color=red,domain=-2:4] plot (\\x,{-(\\x)});\n            \\draw[very thick,color=red,domain=0:5,samples=300] plot (\\x,{\\x ^ (1/2)});\n            \\draw[very thick,color=red,domain=-2:2.3] plot (\\x,{-(\\x) ^ 2 + 2});\n            \\draw[dashed, very thick,color=blue] (1, 1) -- (1, -1);\n            \\node at (0.6, 0.2) [blue] {$ A_1 $};\n            \\node at (1.3, -0.5) [blue] {$ A_2 $};\n        \\end{tikzpicture}\n    \\end{figure}\n\n    \\begin{align}\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n    \\end{align}\n\\end{exercise}\n\n\\begin{exercise}\\nonumber\n    Find the area bounded by $ y^2 = x + 4 $ and $ y = {1 \\over 2}x + {1 \\over 2} $. \\\\\n\n    \\begin{figure}[H]\n        \\centering\n        \\begin{tikzpicture}[scale=0.8]\n            \\draw[->] (-5,0) -- (6,0) node[right] {$ x $};\n            \\draw[->] (0,-3) -- (0,3) node[above] {$ y $};\n            \\draw[very thick,color=red,domain=-4:6] plot (\\x,{0.5 * \\x + 0.5});\n            \\draw[very thick,color=red,domain=-4:6,samples=300] plot (\\x,{(\\x + 4) ^ (1/2)});\n            \\draw[very thick,color=red,domain=-4:6,samples=300] plot (\\x,{-(\\x + 4) ^ (1/2)});\n            \\draw[dashed,blue] (-3,1) -- (0,1) -- (0,0.5) -- (-3,0.5) -- (-3,1);\n        \\end{tikzpicture}\n    \\end{figure}\n\n    \\begin{align}\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n        \\\\\n                                         \\\\\n                                         \\\\\n                                         \\\\\n                                         \\\\\n    \\end{align}\n\\end{exercise}", "meta": {"hexsha": "839b6248fe9c3d4c4007815797d2ee099ed56d5a", "size": 32800, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/parts/part5.tex", "max_stars_repo_name": "xdai02/Calculus", "max_stars_repo_head_hexsha": "45e2774a19879e687e0ca9cc8ada28cf290ce2ec", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Calculus/parts/part5.tex", "max_issues_repo_name": "xdai02/Calculus", "max_issues_repo_head_hexsha": "45e2774a19879e687e0ca9cc8ada28cf290ce2ec", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Calculus/parts/part5.tex", "max_forks_repo_name": "xdai02/Calculus", "max_forks_repo_head_hexsha": "45e2774a19879e687e0ca9cc8ada28cf290ce2ec", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.4411326379, "max_line_length": 302, "alphanum_fraction": 0.4100609756, "num_tokens": 9735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294984, "lm_q2_score": 0.8902942173896132, "lm_q1q2_score": 0.8310280533928592}}
{"text": "\n\\subsection{First-order conditions}\n\nWe have a utility function:\n\n\\(U=f(\\mathbf x)\\)\n\nAnd the constraint:\n\n\\(\\sum_i (x_i-c_i)p_i\\le 0\\)\n\nThis gives us the constrained optimisation problem:\n\n\\(L=f(\\mathbf x)-\\lambda \\sum_i (x_i-c_i)p_i\\)\n\nThe first-order conditions are:\n\n\\(L_{x_i}=\\dfrac{\\delta }{\\delta x_i}f(\\mathbf x)-\\lambda p_i=0\\)\n\nOr:\n\n\\(\\lambda = \\dfrac{MU(x_i)}{p_i}\\)\n\nThis means for any pair we have:\n\n\\(\\dfrac{MU(x_i)}{p_i}=\\dfrac{MU(x_j)}{p_j}\\)\n\nFor the Cobb-Douglas utility function the first-order conditions are:\n\n\\(\\dfrac{\\delta }{\\delta x_1}f(\\mathbf x) = \\dfrac{1}{x_1}\\alpha_1\\prod_i x_i^{\\alpha_i}\\)\n\n\\(L_{x_i}=\\dfrac{\\delta }{\\delta x_i}f(\\mathbf x)-\\lambda p_i=0\\)\n", "meta": {"hexsha": "00fe2a8cda45311efeef1b3535d8f2968e5acdd9", "size": 690, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/consumer/02-01-firstOrder.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/consumer/02-01-firstOrder.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/consumer/02-01-firstOrder.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9090909091, "max_line_length": 90, "alphanum_fraction": 0.6710144928, "num_tokens": 254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.960361162033533, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.8309276003567868}}
{"text": "\\subsection{Power Rule}\r\n\\begin{lemma}\r\n\tLet $f(x) = x^n$ where $n$ is a positive integer. Then\r\n\t\\begin{equation}\r\n\t\tf^\\prime(x) = nx^{n-1}.\r\n\t\\end{equation}\r\n\\end{lemma}\r\n\\begin{proof}\r\n\tApplying the limit definition of the derivative,\r\n\t\\begin{equation*}\r\n\t\tf^\\prime(x) = \\lim_{h \\to 0}{\\frac{(x+h)^n - x^n}{h}}.\r\n\t\\end{equation*}\r\n\tApplying the binomial theorem (think Pascal's Triangle),\r\n\t\\begin{align*}\r\n\t\tf^\\prime(x) &= \\lim_{h \\to 0}{\\frac{x^n + nhx^{n-1} + \\ldots + {n \\choose k}h^{k}x^{n-k} + \\ldots + h^n - x^n}{h}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{nx^{n-1} + \\ldots + {n \\choose k}h^{k-1}x^{n-k} + \\ldots + h^{n-1}} \\\\\r\n\t\t&= nx^{n-1}.\r\n\t\\end{align*}\r\n\\end{proof}\r\n\r\nWe'll revisit the power rule after we discover some more detailed rules to show that $n$ can be any real number, not just a positive integer.", "meta": {"hexsha": "8e12f7114778e37a9ae647550f0cad46d319ee75", "size": 811, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/derivative_rules/power_rule.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/derivatives/derivative_rules/power_rule.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/derivatives/derivative_rules/power_rule.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 38.619047619, "max_line_length": 141, "alphanum_fraction": 0.6004932182, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9643214460461698, "lm_q2_score": 0.8615382076534743, "lm_q1q2_score": 0.8307997702284237}}
{"text": "\n\\subsection{Group order}\n\nFor finite groups, each element \\(e\\) has:\n\n\\(e^n=I\\)\n\nFor some \\(n\\in \\mathbb{N}\\)\n\nWhere \\(I\\) is the identity element.\n\nThe order of the group is the smallest value of \\(n\\) such that that holds for all elements.\n\nFor example in the multiplicative group \\(G=\\{-1,1\\}\\) the order is \\(2\\).\n\nOr:\n\n\\(|G|=2\\)\n\nAdditionally\n\n\\(|-1|=2\\)\n\n\\(|1|=1\\)\n\n", "meta": {"hexsha": "a2ade87c62e86d274cf20915026464b0f3c0688b", "size": 373, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/01-05-groupOrder.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/groups/01-05-groupOrder.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/groups/01-05-groupOrder.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.3461538462, "max_line_length": 92, "alphanum_fraction": 0.6273458445, "num_tokens": 118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109770159682, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.8307326037368066}}
{"text": "\n\\subsection{Cosets and normal subgroups}\n\n\nA coset is defined between a group and a subgroup of the group.\n\nFor a group \\(G\\), and its subgroup \\(H\\):\n\n\\begin{itemize}\n\\item The left coset is \\(\\{gH\\}\\)\n\\item The right coset is \\(\\{Hg\\}\\)\n\\end{itemize}\n\nFor \\(\\forall g\\in G\\).\n\nFor abellian groups, the left and right cosets are the same.\n\nThe left and right cosets can also be the same, even if the group \\(G\\) is not abelian.\n\n\\subsubsection{Normal subgroups}\n\nIf the left and right cosets are the same then \\(H\\) is a normal subgroup.\n\n\\subsubsection{Cosets divide a group.}\n\nConsider two left cosets, \\(aH\\) and \\(bH\\), with a common element.\n\nThis means that \\(ah_i=bh_j\\).\n\nWe can use this to get:\n\n\\(a=bh_jh_i^{-1}\\)\n\n\\(b=ah_ih_j^{-1}\\)\n\nWe know that:\n\n\\(ah\\in aH\\)\n\n\\(bh\\in bH\\)\n\nSo:\n\n\\(bh_jh_i^{-1}h\\in aH\\)\n\n\\(ah_ih_j^{-1}h\\in bH\\)\n\nAnd so:\n\n\\(bH\\subset aH\\)\n\n\\(aH\\subset bH\\)\n\nTherefore:\n\n\\(aH=bH\\)\n\n\\subsubsection{Example 1}\n\nConsider the group \\(\\{-1,1\\},\\times \\)\n\nFor the subgroup \\(\\{1\\},\\times \\), the left coset is \\(\\{gH\\}=\\{1,-1\\}\\).\n\nThe right coset is the same.\n\n\\subsubsection{Example 2}\n\nConsider the group of integers and addition: \\((Z,+)\\)\n\nFor subgroup \\((mZ,+)\\), the left and right cosets are the same because the group is abelian.\n\nThe coset of the subgroup is the subgroup multiplied by each element in \\(G\\).\n\nThis is \\(mZ\\), \\(mZ+1\\), \\(mZ+2\\) and so on.\n\nOnce we reach \\(mZ+m\\) this has looped, and is already a coset, so we only need the sets upto \\(mZ+m-1\\).\n\n", "meta": {"hexsha": "db31d61919d524f2404cdc7e3a631af750d72344", "size": 1499, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/05-01-cosets.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/groups/05-01-cosets.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/groups/05-01-cosets.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.2179487179, "max_line_length": 105, "alphanum_fraction": 0.6571047365, "num_tokens": 501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8947894597898777, "lm_q1q2_score": 0.8307304055683108}}
{"text": "\\subsection{The Split-Step Fourier method}\nThe Split-Step Fourier method can be used to solve nonlinear partial differential equations. The result is obtained by evolving the system in both the time and the frequency domain. Therefore the differential equation is split into a linear and a nonlinear part, which can be considered/regarded separately by using sufficiently small steps. The transformation between time and frequency domain can be achieved efficiently by a fast Fourier transform (FFT) algorithm, which makes this method desirable.\n\nIn order to solve the GPE we first take a look at the time-dependent Schr\\\"odinger equation (\\ref{eqn:Schroedinger}).\nIn one spatial dimension its solution is\n\\begin{align}\n\\psi(z,t+\\Delta t) = \\exp\\left[\\alpha \\left( -\\frac{\\hbar^2}{2m}\\nabla^2 + V(z)\\right) \\right]\\psi(z,t).\n\\end{align}\nWe defined $\\displaystyle \\alpha := -\\frac i \\hbar \\Delta t $ simply for convenience.\nSince the terms in the exponent do not commute, one cannot simply split the exponential function up. But if one rewrites the solution as\n\\begin{align}\n\\psi (z,t + \\Delta t) = \\exp\\left(\\frac \\alpha 2 V(z)\\right) \\cdot \n\\exp\\left( -\\alpha\\frac{\\hbar^2}{2m}\\nabla^2\\right) \\cdot\n\\exp\\left(\\frac \\alpha 2 V(z) \\right) \\cdot \\psi(z,t),\n\\end{align}\nthe error is of $\\mathcal{O}(\\Delta t^3)$, which is accurate enough in our case and allows us to treat the two steps separately. Due to the fact, that $V$ is diagonal in the time domain and $\\nabla^2$ is diagonal in the frequency domain, they simply become multiplications by $V(z)$ and the squared wavevector $k^2$, respectively. Combined with the speed of the FFT this enables a faster and more efficient way to obtain the result than calculating everything in the time domain would be.\nPutting everything together yields\n\\begin{align}\n\\psi (z,t + \\Delta t) = \\exp\\left(\\frac \\alpha 2 V(z)\\right) \\cdot \\mathcal{F}^{-1} \\left[\n\\exp\\left( -\\frac{\\alpha\\hbar^2}{2m}k^2\\right) \\cdot \\mathcal{F} \\left[\n \\exp\\left(\\frac \\alpha 2 V(z) \\right) \\cdot \\psi(z,t) \\right] \\right].\n\\end{align}\n\nAlthough we used the linear Schr\\\"odinger equation with time-independent Hamiltonian, the result is also true for the GPE if one replaces $V(x)$ by $V(x) + g\\norm{\\psi}^2$. By using the latest result in every step of the calculation one can ensure that the error does not exceed $\\mathcal{O}(\\Delta t^3)$.\n\nAnother important characteristic of the Split-Step Fourier method is, that it conserves the norm of the initial density distribution. To prove this for our implementation we normalized different initial constellations to 1 and plotted the norm after every time step during the evolution. The result is depicted in the following.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale = 0.25]{figures/norm}\n\t\\caption{Proving the conservation of the norm by our implementation of the Split-Step Fourier method for different initial constellations.}\n\\end{figure}\nAs one can see, for our implementation the norm ist conserved within a limit of $\\mathcal{O}(10^{-13})$.", "meta": {"hexsha": "62540091992defb68e37f65d1cdca2a45e64244d", "size": 3023, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Final Project/Report/content/011_split_step_fourier.tex", "max_stars_repo_name": "mathieukaltschmidt/CompQD", "max_stars_repo_head_hexsha": "b31c07614e7821bf76213a1cc1f5e6688fbdffa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-07-04T17:13:47.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-29T16:56:58.000Z", "max_issues_repo_path": "Final Project/Report/content/011_split_step_fourier.tex", "max_issues_repo_name": "mathieukaltschmidt/CompQD", "max_issues_repo_head_hexsha": "b31c07614e7821bf76213a1cc1f5e6688fbdffa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Final Project/Report/content/011_split_step_fourier.tex", "max_forks_repo_name": "mathieukaltschmidt/CompQD", "max_forks_repo_head_hexsha": "b31c07614e7821bf76213a1cc1f5e6688fbdffa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-04-23T19:58:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-26T16:58:06.000Z", "avg_line_length": 94.46875, "max_line_length": 502, "alphanum_fraction": 0.7558716507, "num_tokens": 806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.9032942119105695, "lm_q1q2_score": 0.8307077754396858}}
{"text": "\\section{Forward and Futures}\n\n\n\\subsection*{Forward Interest rates}\nThe forward interest rate between time $t-1$ and $t$ satisfies:\\\\\n$ (1+r_t)^t = (1+r_{t-1})^{t-1}(1+f_t) $ \\\\\n$ f_t = \\frac{B_{t-1}}{B_t} -1 =\\frac{(1+r_t)^t}{(1+r_{t-1})^{t-1}} -1 $\n\n\n\\subsection*{Forward price}\n$F_T=e^{(r-y)T} S_0$\n\n\n\\subsection*{Swaps}\nThe swap rate is a weighted average of forward rates: \\\\\n$r_s = \\frac{\\sum_{t=1}^{T}B_t f_t}{\\sum_{u=1}^{T}B_u} = \\sum_{t=1}^{T} w_t  f_t$ , \nwith the weights $w_t = \\frac{B_t}{\\sum_{u=1}^{T} B_u}$ \\\\\n\nAlternative method: $r_S=\\frac{1-B_T}{\\sum_{u=1}^{T}B_u}$ in the 3 year case: $r_S=\\frac{1-B_3}{B_1+B_2+B_3}=\\frac{1-1/(1+r_3)^2}{1/(1+r_1)+1/(1+r_2)^2+1/(1+r_3)^3}$ \n\n\n\\subsection*{R11Q1:Forward Interest Rates and Arbitrage }Question 1: \nProblem is to find arbitrage from 2 spot rates and 1 forward rate, the general approach to solving this problem is to:\n1. Invest $x$ at spot rate, $r_1$\n2. Invest $y$ at spot rate, $r_2$\n3. Invest $z$ at 1-yr forward rate in year 1, $f_1$\n(a) Pays \\$100 today and nothing in the future:\n$-x-y = 100$ |\n$(1 + r_1)x -z = 0$ |\n$(1 + r_2)^2y + (1 + f_1)z = 0$ then solve system to find amounts.\n\n\\subsection*{R11Q3: Currency Forward}\nSuppose that USD/JPY is trading at 105, and the 1-year forward on USD/JPY\nis trading at 106. The risk-free rate in the US is 1\\%, and in Japan it is 3\\%.\nConstruct an arbitrage strategy that gives you \\$100 today and nothing in the\nfuture. {\\bf solution}: Year 1 income in JPY = Year 1 liabilities in JPY\n$105\\times 1.03 \\times (x - 100) = 106 \\times 1.01 \\times x$\nSolving yields $x= 9922 USD$", "meta": {"hexsha": "6aec6da595a435034a79fd6c8fec7d6d8a7d395c", "size": 1590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15.415.2x/assets/week_11.tex", "max_stars_repo_name": "j053g/cheatsheets", "max_stars_repo_head_hexsha": "22f7a84879c04d44de40467ddcc0f6e551b812c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-12-14T08:49:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T17:26:15.000Z", "max_issues_repo_path": "15.415.2x/assets/week_11.tex", "max_issues_repo_name": "j053g/cheatsheets", "max_issues_repo_head_hexsha": "22f7a84879c04d44de40467ddcc0f6e551b812c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "15.415.2x/assets/week_11.tex", "max_forks_repo_name": "j053g/cheatsheets", "max_forks_repo_head_hexsha": "22f7a84879c04d44de40467ddcc0f6e551b812c7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.8421052632, "max_line_length": 166, "alphanum_fraction": 0.6572327044, "num_tokens": 630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.8918110375304408, "lm_q1q2_score": 0.8306885447598462}}
{"text": "\\textbf{Modify Program 20 to make use of matricves instead of FFT. Make sure to do this elegantly, using matrix-matrix multiplications rather than explicit loops. You will find that the code gets much shorter, and faster, too. How much faster is it? Does increasing $N$ from 24 to 48 tip the balance}\n\\newline\n\nIn the following table we have the times spent by the different codes to compute the first derivative (the plotting section was commented out). It can be seen that as $N$ gets large using matrices is more expensive.\n\n\\begin{table}[h]\n\\centering\n \\begin{tabular}{||c c c||} \n \\hline\n $N$ & FFT & Matrices \\\\ [0.5ex] \n \\hline\\hline\n 24 & 0.1420280 & 0.0113390 \\\\ \n \\hline\n 48 & 1.0236130 & 3.7638280 \\\\ [1ex] \n \\hline\n\\end{tabular}\n\\caption{Time spent in computing the first derivative of $f$ using FFTs and matrices.}\n\\end{table}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\nformat long\n% Grid and initial data:\nNvector = [24,48];\ntime = zeros(length(Nvector),1);\nfor k = 1:length(Nvector)\n    N=Nvector(k);\n    [D,x] = cheb(N);  y = x;\n    D2 = D^2;\n    D2 = D2(2:end-1,2:end-1);\n    L = kron(eye(N-1),D2)+kron(D2,eye(N-1));\n    dt = 6/N^2;\n    [xx,yy] = meshgrid(x(2:N),y(2:N));\n    x = xx(:); y = yy(:);\n\n    plotgap = round((1/3)/dt); dt = (1/3)/plotgap;\n    u = exp(-40*((x-.4).^2 + y.^2));\n    uold = u; \n\n    % Time-stepping by leap frog formula:\n    [ay,ax] = meshgrid([.56 .06],[.1 .55]); clf\n    tic\n    for n = 0:3*plotgap\n        t = n*dt;\n%         if rem(n+.5,plotgap)<1     % plots at multiples of t=1/3\n%           uu = reshape(u,N-1,N-1);\n%           i = n/plotgap+1;\n%           subplot('position',[ax(i) ay(i) .36 .36])\n%           [xxx,yyy] = meshgrid(-1:1/16:1,-1:1/16:1);\n%           uuu = interp2(xx,yy,uu,xxx,yyy,'cubic');\n%           mesh(xxx,yyy,uuu), axis([-1 1 -1 1 -0.15 1])\n%           colormap(1e-6*[1 1 1]); title(['t = ' num2str(t)]), drawnow\n%         end\n    % -------------------- %    \n    % -- Using matrices -- %\n    % -------------------- %    \n        unew = 2*u - uold + dt^2*L*u; \n        uold = u; u = unew;\n    % --------------- %\n    % -- Using fft -- % Done in Program 20\n    % --------------- %\n    %     uxx = zeros(N+1,N+1); uyy = zeros(N+1,N+1);\n    %     ii = 2:N;\n    %     for i = 2:N                % 2nd derivs wrt x in each row\n    %       v = vv(i,:); V = [v fliplr(v(ii))];\n    %       U = real(fft(V));\n    %       W1 = real(ifft(1i*[0:N-1 0 1-N:-1].*U)); % diff wrt theta\n    %       W2 = real(ifft(-[0:N 1-N:-1].^2.*U));    % diff^2 wrt theta\n    %       uxx(i,ii) = W2(ii)./(1-x(ii).^2) - x(ii).* ... \n    %                      W1(ii)./(1-x(ii).^2).^(3/2);\n    %     end\n    %     for j = 2:N                % 2nd derivs wrt y in each column\n    %       v = vv(:,j); V = [v; flipud(v(ii))];\n    %       U = real(fft(V));\n    %       W1 = real(ifft(1i*[0:N-1 0 1-N:-1]'.*U));% diff wrt theta   \n    %       W2 = real(ifft(-[0:N 1-N:-1]'.^2.*U));   % diff^2 wrt theta\n    %       uyy(ii,j) = W2(ii)./(1-y(ii).^2) - y(ii).* ...\n    %                      W1(ii)./(1-y(ii).^2).^(3/2);\n    %     end\n    end\n    time(k) = toc;\nend\n\\end{verbatim}", "meta": {"hexsha": "f3919b373b2eefad0b086eb4fde66a452b988798", "size": 3130, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework3/Latex/problem4.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework3/Latex/problem4.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework3/Latex/problem4.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.7108433735, "max_line_length": 300, "alphanum_fraction": 0.496485623, "num_tokens": 1141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.897695283896349, "lm_q1q2_score": 0.8305745708519311}}
{"text": "\\chapter{Functional Derivatives}\\label{app:functional-derivatives}\n\nA functional is just a function of a function -- i.e.\\ some rule $F$ that maps a function $f$ into a number $F[f]$.  Definite integrals are a common example.\nIn order to optimize a functional $F$ with respect to its argument $f$, one needs to take a \\textit{functional derivative}.\\footnote{\\url{http://en.wikipedia.org/wiki/Functional_derivative}}\nTo motivate the definition of a functional derivative, first consider the definition of an ordinary derivative\n\\begin{align}\n  \\fd{f(x)}{x}\n\\equiv\n  \\lim_{\\e\\rightarrow0}\n  \\fr{f(x+\\e)-f(x)}{\\e}\n\\end{align}\nand note the following identity, which you can verify using\n$\n  f(x+\\e)\n=\n  f(x)\n+\n  \\dfd{f(x)}{x}\n  \\e\n+\n  \\mc{O}(\\e^2)\n$.\n\\begin{align}\\label{eq:scalar-derivative-trick}\n  \\lim_{\\e\\rightarrow0}\n  \\fr{f(x+\\e)-f(x)}{\\e}\n=&\\\n\\left.\n  \\fr{df(x+\\e)}{d\\e}\n\\right|_{\\e=0}\n\\end{align}\nFor multivariate functions, we have the concept of a \\textit{directional derivative}\n\\begin{align}\\label{eq:directional-derivative}\n  \\bo{y}\\cdot\n  \\pd{f(\\bo{x})}{\\bo{x}}\n=\n  \\lim_{\\e\\rightarrow0}\n  \\fr{f(\\bo{x}+\\e\\bo{y}) - f(\\bo{x})}{\\e}\n\\end{align}\nwhich measures the change in $f(\\bo{x})$ in the direction $\\bo{y}$.\nUsing equation \\ref{eq:scalar-derivative-trick}, the directional derivative can be evaluated as an ordinary scalar derivative with respect to $\\e$.\n\\begin{align}\\label{eq:vector-derivative-trick}\n  \\bo{y}\\cdot\n  \\pd{f(\\bo{x})}{\\bo{x}}\n=\n  \\left.\n  \\fd{f(\\bo{x} + \\e\\bo{y})}{\\e}\n  \\right|_{\\e=0}\n\\end{align}\nThe functional derivative $\\dfr{\\d F}{\\d f}$ is defined to satisfy an equation analogous to \\ref{eq:directional-derivative}, playing the role of the gradient.\n\\begin{align}\n  \\int_{-\\infty}^{\\infty}\n  dx'\\,\n  g(x')\n  \\fr{\\d F[f]}{\\d f(x')}\n\\equiv\n  \\lim_{\\e\\rightarrow0}\n  \\fr{F[f+\\e g] - F[f]}{\\e}\n\\end{align}\nThis left-hand side could be called a \\textit{functional directional derivative}, giving the change in $F$ upon displacing its argument along the function $g$.\nHere, the integral takes the role of the dot product in \\ref{eq:directional-derivative}.\nUsing the same trick as in equation \\ref{eq:vector-derivative-trick}, the functional derivative can be expressed as an ordinary scalar derivative.\n\\begin{align}\n\\label{eq:functional-derivative-trick}\n  \\int_{-\\infty}^{\\infty}\n  dx'\\,\n  g(x')\n  \\fr{\\d F[f]}{\\d f(x')}\n=\n  \\left.\n  \\fd{F[f+\\e g]}{\\e}\n  \\right|_{\\e=0}\n\\end{align}\nThe standard procedure for evaluating the functional derivative is to first evaluate the right-hand side of equation~\\ref{eq:functional-derivative-trick} for an arbitrary $g$ and then infer what $\\dfr{\\d F[f]}{\\d f(x)}$ must be by comparing to the left-hand side.\nEquivalently, $g(x')$ can be replaced with a Dirac delta $\\d(x-x')$ in order to arrive at $\\dfr{\\d F[f]}{\\d f(x)}$ directly.\n\nUsing eq. \\ref{eq:functional-derivative-trick} and the lemma in \\cref{app:fundamental-lemma-of-calculus-of-variations}, we find that the stationarity condition for a functional\n\\begin{align}\n  \\fr{\\d F[f]}{\\d f}\n\\overset{!}{=}\n  0\n\\end{align}\nis equivalent to the following condition.\n\\begin{align}\n  \\left.\n  \\fd{F[f+\\e g]}{\\e}\n  \\right|_{\\e=0}\n\\overset{!}{=}\n  0\n&&\n  \\text{for all $g(x)$}\n\\end{align}\n", "meta": {"hexsha": "fc10d80f7fa18f3ba272a07e70272b079538e15b", "size": 3211, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/sections/functional-derivatives.tex", "max_stars_repo_name": "GQCG-edu/chem-8950", "max_stars_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "handouts/sections/functional-derivatives.tex", "max_issues_repo_name": "GQCG-edu/chem-8950", "max_issues_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-13T12:11:58.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-13T15:31:47.000Z", "max_forks_repo_path": "handouts/sections/functional-derivatives.tex", "max_forks_repo_name": "GQCG-edu/chem-8950", "max_forks_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.902173913, "max_line_length": 263, "alphanum_fraction": 0.6823419495, "num_tokens": 1073, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539661028358093, "lm_q2_score": 0.8705972616934408, "lm_q1q2_score": 0.8305202768772189}}
{"text": "\\vfill~\\columnbreak\n\n\\section{Useful math}\n\n% ===\n\\emph{Probabilities}\n\n$\\mathbb{E}_x[X] = \\begin{cases}\n   \\int x \\cdot p(x) \\diff x  & \\text{if continuous}\\\\\n   \\sum_x x \\cdot p(x) & \\text{discrete}\n  \\end{cases}$\n\n$\\operatorname{Var}[X] = \\mathbb{E}[(X-\\mu_X)^2] = \\mathbb{E}[X^2] - \\mathbb{E}[X]^2$\n\n\\textbf{Bayes Rule:} (using \\textbf{chain} rule)\n\n\\highlight*{$P(A\\vert B) = \\frac{P(B\\vert A) \\cdot P(A)}{P(B)}$},\n\\enskip\n$P(Z\\vert X,\\theta) = \\frac{ P(X,Z\\vert\\theta) }{ P(X\\vert\\theta) }$\n\n% ===\n\\emph{p-Norm:}\n$\\norm{x}_p = (\\sum_{i=1}^n \\abs{x_i}^p)^{\\frac{1}{p}}$, $1 \\leq p < \\infty$\n\n% ===\n\\emph{Some gradients}\n\n$\\nabla\\!_x \\norm{x}_2^2 = 2 x$\n\n$f(x) = x^\\top A x$; $\\nabla\\!_x f(x) = (A + A^\\top) x$\n\nE.g. $\\nabla\\!_w \\log(1+\\exp(-y w^\\top x)) = ...$\\\\\n\\phantom{E.g.} $=\\frac{1}{1+\\exp(-y w^\\top x)} \\cdot \\exp(-y w^\\top x) \\cdot (-y x)$\\\\\n\\phantom{E.g.} $=\\frac{1}{1 + \\exp(y w^\\top x)} \\cdot(-yx)$\n\n% ===\n\\emph{Convex / Jensen's inequality}\n\n$f(x) \\textbf{ \\normalcolor convex }\n\\myiff f''(x)\\!>\\!0\n\\myiff x_i\\!\\in\\!\\mathbb{R}, \\lambda\\!\\in\\![0,1]: \nf(\\lambda x_1 + (1\\!-\\!\\lambda) x_2) \\leq \\lambda f(x_1) + (1\\!-\\!\\lambda) f(x_2)$\n\n\\textbf{Jensen's inequality:}\n$g(\\mathbb{E}[X]) \\leq \\mathbb{E}[g(X)]$\n\n% ===\n\\emph{Gaussian / Normal distribution}\n\n$\\highlight{\\mathcal{N}(\\mu,\\sigma^2)} \\sim \\frac{1}{\\sqrt{2\\pi\\sigma^2}} \\exp\\big( \\!-\\frac{(x-\\mu)^2}{2\\sigma^2} \\big)$\n\n\\textbf{Multivariate Gaussian:}\\\\\n$f(x) = \\frac{1}{2\\pi\\sqrt{\\abs{\\Sigma}}} \\exp\\left( \\frac{1}{2} (x-\\mu)^\\top \\Sigma^{-1} (x-\\mu) \\right)$\\\\\nwith $\\textstyle \\Sigma =\n\\begin{bmatrix}\n\t\\sigma_{11}^2\t& \\sigma_{12}\\\\\n\t\\sigma_{21}\t\t& \\sigma_{22}^2\n\\end{bmatrix}$\nand $\\mu =\n\\begin{bmatrix}\n\t\\mu_1 \\\\ \\mu_2\n\\end{bmatrix}$\n\n% ===\n\\emph{Multivariate Gaussian}\n\n$\\Sigma =$ covariance matrix, $\\mu$ = mean\\\\\n$f(x) = \\frac{1}{2\\pi \\sqrt{|\\Sigma|}} e^{- \\frac{1}{2} (x-\\mu)^T \\Sigma^{-1} (x-\\mu)}$\\\\\nEmpirical: $\\Sigma = \\frac{1}{n}\\sum_{i=1}^n x_i x_i^T$ (needs centered data points)\n\n% ===\n\\emph{Positive semi-definite matrices}\n\n$M \\in \\mathbb{R}^{n\\times n}$ is psd $\\Leftrightarrow$\\\\\n$\\forall x \\in \\mathbb{R}^n: x^TMx \\geq 0 \\Leftrightarrow$\\\\\nall eigenvalues of $M$ are positive: $\\lambda_i\\geq 0$\n\n", "meta": {"hexsha": "e39e6850462bd40857935cc316f95d33c31c625a", "size": 2189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/IML19/sections/Math.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/IML19/sections/Math.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/IML19/sections/Math.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0641025641, "max_line_length": 121, "alphanum_fraction": 0.5719506624, "num_tokens": 987, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620562254525, "lm_q2_score": 0.8652240860523328, "lm_q1q2_score": 0.8304092479253748}}
{"text": "\n\\subsection{Normal equation}\n\n\\subsubsection{Least squares}\n\nThe square error is \\(\\sum_i (\\hat{y_i}-y_i)^2\\).\n\nThe differential of this with respect to \\(\\hat{\\theta_j }\\) is:\n\n\\(2\\sum_i \\dfrac{\\delta \\hat{y_i}}{\\delta \\hat{\\theta_j}}(\\hat{y_i}-y_i)\\)\n\nThe stationary point is where this is zero:\n\n\\(\\sum_i \\dfrac{\\delta \\hat{y_i}}{\\delta \\hat{\\theta_j}}(\\hat{y_i}-y_i)=0\\)\n\n\\subsubsection{Linear least squares}\n\nHere, \\(\\hat{y_i}= \\sum_j x_{ij}\\hat{\\theta_j}\\)\n\nTherefore: \\(\\dfrac{\\delta \\hat{y_i}}{\\delta \\hat{\\theta_j}}=x_{ij}\\)\n\nAnd so the stationary point is where\n\n\\(\\sum_i x_{ij}( \\sum_j x_{ij}\\hat{\\theta_j }-y_i)=0\\)\n\n\\(\\sum_i x_{ij}( \\sum_j x_{ij}\\hat{\\theta_j)}= \\sum_i x_{ij}y_i\\)\n\n\\subsubsection{Normal equation}\n\nWe can write this in matrix form.\n\n\\(X^TX\\hat{\\theta }=X^Ty\\)\n\nWe can solve this as:\n\n\\(\\hat{\\theta }=(X^TX)^{-1}X^Ty\\)\n\n\\subsubsection{Perfectly correlated variables}\n\nIf variables are perfectly correlated then we cannot solve the normal equation.\n\nIntuitively, this is because for perfectly correlated variables there is no single best parameter, as changes to one parameter can be counteracted by changes to another.\n\n", "meta": {"hexsha": "b27eb877ec6bc6a212898af39dc6e5dbb6eea638", "size": 1151, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/ols/02-01-normal.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/ols/02-01-normal.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/ols/02-01-normal.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.1590909091, "max_line_length": 169, "alphanum_fraction": 0.7002606429, "num_tokens": 363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620619801095, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.8304092479012659}}
{"text": "\\textbf{Suppose the discretization of a boundary value problem, such as the Poisson equation, leads to the matrix equation}\n\\begin{align*}\nuA + Bu = f,\n\\end{align*}\n\\textbf{that needs to be solved for $u$. Here $u$ is $n \\times m$, $A$ is $m \\times m$, $B$ is $n \\times n$, and $f$ is $n \\times m$.}\n\n\\textbf{Assuming both $A$ and $B$ are non-defective matrices, with $A = V_A \\Lambda_AV_A^{-1}$ and $B = V_B \\Lambda_BV_B^{-1}$, show that the solution $u$ is given by $u = V_B UV_A^{-1}$, where}\n\\begin{align*}\nU_{i,j} = \\frac{F_{i,j}}{\\alpha_j + \\beta_i},\n\\end{align*}\n\\textbf{$F = V_B^{-1}fV_A$, and $\\alpha_k$ and $\\beta_k$ are the diagonal entries of $\\Lambda_A$ and $\\Lambda_B$ respectively.}\n\nWe start with the eigenvalue decomposition of the matrices $A$ and $B$,\n\\begin{align*}\nuV_A \\Lambda_AV_A^{-1} + V_B \\Lambda_BV_B^{-1} u = f,\n\\end{align*}\nand premultiplying by $V_B^{-1}$ multiplying from the right by $V_A$,\n\\begin{align*}\nV_B^{-1}uV_A\\Lambda_A + \\Lambda_B V_B^{-1} u V_A = V_B^{-1} f V_A.\n\\end{align*}\nThen let $U = V_B^{-1}uV_A$ and $F = V_B^{-1} f V_A$ so that. Therefore, we have\n\\begin{align*}\nU\\Lambda_A + \\Lambda_B U = F,\n\\end{align*}\nwhich in matrix form is\n\\begin{align*}\n&\\begin{bmatrix}\n\\tilde{u}_{11}& \\cdots & \\tilde{u}_{1m} \\\\\n\\tilde{u}_{21}& \\cdots & \\tilde{u}_{2m} \\\\\n\\vdots& ~ & \\vdots \\\\\n\\tilde{u}_{n1}& \\cdots & \\tilde{u}_{nm}\n\\end{bmatrix} \\begin{bmatrix}\n\\alpha_1 & 0 & \\cdots & 0 \\\\\n0 & \\alpha_2 & ~ & \\vdots \\\\\n\\vdots & ~& \\ddots & ~ \\\\\n0 & \\cdots & 0 & \\alpha_m\n\\end{bmatrix} + \\begin{bmatrix}\n\\beta_1 & 0 & \\cdots & 0 \\\\\n0 & \\beta_2 & ~ & \\vdots \\\\\n\\vdots & ~& \\ddots & ~ \\\\\n0 & \\cdots & 0 & \\beta_m\n\\end{bmatrix}\\begin{bmatrix}\n\\tilde{u}_{11}& \\cdots & \\tilde{u}_{1m} \\\\\n\\tilde{u}_{21} & \\cdots & \\tilde{u}_{2m} \\\\\n\\vdots& ~ & \\vdots \\\\\n\\tilde{u}_{n1} & \\cdots & \\tilde{u}_{nm}\n\\end{bmatrix} = \\begin{bmatrix}\n\\tilde{f}_{11} & \\cdots & \\tilde{f}_{1m} \\\\\n\\tilde{f}_{21} & \\cdots & \\tilde{f}_{2m} \\\\\n\\vdots & ~ & \\vdots \\\\\n\\tilde{f}_{n1} & \\cdots & \\tilde{f}_{nm}\n\\end{bmatrix}.\n\\end{align*}\nWe can infer from the matrix equation above that\n\\begin{align*}\nU_{i,j} = \\frac{F_{i,j}}{\\alpha_j + \\beta_i}.\n\\end{align*}\nThen, to get back our solution, we use $u = V_B U V_A^{-1}$.\n\n\\textbf{Using part (a), solve the Poisson equation $\\Delta u = \\sin(x)\\cos(100y)$ on $[0,1] \\times [0,1]$ (with zero Dirichlet boundary conditions) using 100 points in the $x$ direction and 300 in the $y$ direction. Estimate the accuracy of your solution.}\n\nCoding into \\textsl{Matlab} the previous method, we obtain a solution for $u$ shown in the figure below,\n\n\\begin{figure}[H]\n\\center{\\includegraphics[scale=.75]{problem2_u.png}}\n\\caption{Solution0 $u$ of the poisson equation.}\n\\end{figure}\n\nThe error, found by comparing $uD2A + D2Bu$ and $f$, where $D2A$ and $D2B$ are the centered finite difference matrices for $x$ and $y$ respectively, is $2.10806\\cdot 10^{-12}$. \n\n\\subsection*{Matlab code for this part}\n\\begin{verbatim}\n%% Problem 2\nNx=100; Ny=300;\nhx=1/(Nx-1); hy=1/(Ny-1);\n\nD2x=gallery('tridiag',Nx,1,-2,1)/(hx^2);\nD2y=gallery('tridiag',Ny,1,-2,1)/(hy^2);\n\n[Vx,LambdaX]=eig(full(D2x));\n[Vy,LambdaY]=eig(full(D2y));\n[x,y]=meshgrid(linspace(0,1,100),linspace(0,1,300));\nf=sin(x).*cos(100*y);\nF=Vy'*f*Vx;\nU=zeros(size(f));\nlambdax=diag(LambdaX);\nlambday=diag(LambdaY);\n% whos U F lambdax lambday\nfor j=1:Nx\n    U(:,j)=F(:,j)./(lambday+lambdax(j));\nend\n\nu=Vy*U*Vx';\n% Calculate error\nerr=norm(u*D2x+D2y*u-f,inf)\nfigure\nsurf(x,y,u)\nshading interp\nxlabel('$x$','Interpreter','latex')\nylabel('$y$','Interpreter','latex')\nset(get(gca,'ylabel'),'rotation',0)\ntxt=[path,'problem2_u'];\nsaveas(gcf,txt,'png')\n\n\\end{verbatim}", "meta": {"hexsha": "d10e150a1551dd7ed70126f22e83f548dafcc859", "size": 3644, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/problem2.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/problem2.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/problem2.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.7047619048, "max_line_length": 256, "alphanum_fraction": 0.642974753, "num_tokens": 1430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632329799586, "lm_q2_score": 0.8723473713594992, "lm_q1q2_score": 0.8303553891838215}}
{"text": "\\subsubsection{The gramian matrix $\\trans{A}A$}\n\nWe brought the \\cref{fig:fund} not only to illustrate the\nFundamental Theorem of Linear Algebra, but also to justify the\nintroduction of the matrix $\\trans{A}A$ (also called the gramian\nmatrix of $A$). From the figure, it can be seen that the matrix $A$\ntakes the row space \\C{\\trans{A}} into the column space \\C{A}; and we\nknow that both subspaces have the same dimension $r =\n\\func{rank}(A)$. As Strang explains in \\cite{strang88}, the\ndimensions of the domain \\R{n} and codomain \\R{m} do not tell the real\nstory about the linear transformation behind $A$; it is rather the\ndimensions of \\C{\\trans{A}} and \\C{A}. \\\\\n\nIf we just pay attention to\nthose subspaces, then the matrix $A$ behaves like a bijection (this is\nproved in \\cite{strang88}); that is, if we took the submatrix of\ndimensions $r \\times r$ that results from eliminating dependent rows\nand columns in $A$, such matrix would be invertible and the inverse would\ntake the column space \\C{A} into the row space \\C{\\trans{A}}. \nThus, the real information of matrix $A$ lies in the one-to-one\ntransformation of \\C{\\trans{A}} into \\C{A}; the null spaces in both\nsides (\\N{A} and \\N{\\trans{A}}) do not contribute much to the\nthe transformation $A$, as they just get compressed to the zero vector. \\\\\n\nAlright, putting aside the null spaces and focusing only in the\nbijection that $A$ performs between the row and column spaces, one may\nbe tempted to think from \\cref{fig:fund} that the transpose of $A$\n(denoted as \\trans{A}), is actually the inverse of $A$ in the context\nof those subspaces. But as Strang promptly clarifies in\n\\cite{strang88}, that honor belongs only to the actual inverse of\nA. We refer to the inverse here, not in the regular sense, but\nrestricted to the subspaces \\C{\\trans{A}} and \\C{A} (that is, we are\ntalking about the inverse of the submatrix of $k \\times k$ that we\nmentioned above). The effect of \\trans{A} is \ncorrect at the level of the whole subspace \\C{A}; it takes it back to\n\\C{\\trans{A}}. But the vectors that were originally mapped by $A$, are\nnot necessarily recovered after applying \\trans{A} to that image\n$A\\vec{x}$. \\\\\n\nOne particular way of reinforcing the fact that \\trans{A} is not the\ninverse, is by an indirect measure. If we take the dot product between\nthe starting point \\vec{x} in \\R{n}, and the result of applying\n\\trans{A} to its image $A\\vec{x}$, that would give us an indication of\nhow close or distant they are (in the end, the dot product and the\northogonal projection are intimately related). If the starting and\nfinal vectors happen to be the same, the cited dot product shall be\n$\\norm{x}_2^2$ (where $\\norm{.}_2$ represents the known euclidean\ndistance). Let us confirm ourselves that is not the case: \\\\\n\n\\begin{align*}\n& \\vec{x} \\cdot (\\trans{A} A\\vec{x}) &= \\\\\n& \\trans{\\vec{x}} (\\trans{A} A\\vec{x}) &= \\\\\n& (\\trans{\\vec{x}} \\trans{A}) (A\\vec{x}) &= \\\\\n& \\trans{(A\\vec{x})} (A\\vec{x}) &= \\\\\n& (A\\vec{x}) \\cdot (A\\vec{x}) &= \\\\\n  & \\norm{A\\vec{x}}_2^2 &\\le \n& \\norm{A}_2^2 \\norm{\\vec{x}}_2^2\n\\end{align*}\n\\hfill\n\nFrom the above development, we can see indeed that $\\vec{x}\n\\cdot (\\trans{A} A\\vec{x}) \\ne \\norm{x}_2^2$; actually, in the last step\nwe used a general property of matrix norms, which in particular applies\nto the extension of the vector norm $\\norm{.}_2$ to matrices. We will not\ndefine it formally, but it suffices to keep the intuition that norm of\n$A$, denoted as $\\norm{A}_2$, is a measure of the distortion that the linear\ntransformation $A$ does on the space (is actually the maximum\ndistortion on the unit sphere). In the last step we can see that \nsuch measure of distortion, is precisely one of the factors that\nprevents that simply taking the transpose \\trans{A} as a way back,\nsends us to the starting point in the row space. \\\\\n\nAbove reasoning is a further argument for $\\trans{A} \\ne \\inv{A}$;\nsuch special property only applies to orthogonal matrices (like the\n$U$ and $V$, which appear in the SVD factorization). For orthogonal\nmatrices, $\\trans{A} A = I$, where $I$ is the identity matrix; and\nthough that does not occur in general for an arbitrary matrix $A$, the\nfunction composition represented by $\\trans{A}A$ is quite interesting;\nit may not be the identity function, but at least it has one of its\nproperties: \\\\\n\n\\[\n\\trans{(\\trans{A}A)} = \\trans{A}\\trans{(\\trans{A})} = \\trans{A}A\n\\]\n\\hfill\n\nThe matrix $\\trans{A}A$ (called gramian) is equal to its transpose, which is the\ndefinition of a symmetric matrix. This particular symmetric matrix\nis quite important for us, as it represents the bridge between the SVD\nfactorization and the Spectral Theorem; in short, the Spectral Theorem\nguarantees that any symmetric matrix is diagonalizable, and applying such\nfactorization to our special matrix $\\trans{A}A$, give us the two bases\nthat we need to build the SVD factorization (which happen contain, the\nbases of the four subspaces of $A$). These details will be developed in\nthe next two sections. For the moment, we will just finish the current one\nby establishing a few more facts about $\\trans{A}A$, which\nshow its close connection with $A$. \\\\\n\nIs not hard to show that $\\trans{A}A$ and $A$ share the same null\nspace; and that actually implies that the rank of both matrices is\nthe same. Let us state that in a theorem and prove it:\n\n\\begin{theorem}[Rank of the Gramian Matrix]\n\\label{thm:gramr}\nLet $A$ be a real matrix of rank $r$ $\\implies$ its gramian matrix\n$\\trans{A}A$ has the same rank $r$.\n\\end{theorem}\n\\hfill\n\n\\begin{proof}\nLet us begin proving that \\N{A} = \\N{\\trans{A}A}.  Let \\vec{x} $\\in\n\\N{A}$, then: \\\\ \n\n\\[\nA\\vec{x} = \\vec{0} \\ds{\\iff} \\trans{A}(A\\vec{x}) = \\trans{A}\\vec{0}\n\\ds{\\iff} \\trans{A}A\\vec{x} = \\vec{0}\n\\]\n\\hfill\n\nAbove just proves that $\\N{A} \\subset \\N{\\trans{A}A}$, but the other\ncontention can also be deduced. Let $\\vec{x} \\in \\N{\\trans{A}A}$, then: \\\\\n\n\\begin{align*}\n& \\trans{A}A\\vec{x} = \\vec{0} &\\iff \\\\\n& \\trans{\\vec{x}}\\trans{A}A\\vec{x} = \\trans{\\vec{x}}\\vec{0} &\\iff \\\\\n& \\trans{(A\\vec{x})} A\\vec{x} = 0 & \\iff \\\\\n& (A\\vec{x}) \\cdot (A\\vec{x}) = 0 & \\iff \\\\\n& \\norm{A\\vec{x}}_2^2 = 0 & \\iff \\\\\n& A\\vec{x} = \\vec{0} & \\iff \\\\\n& \\vec{x} \\in \\N{A}\n\\end{align*}\n\\hfill\n\nThe two developments above show that $\\N{\\trans{A}A} = \\N{A}$, that in\nparticular means that $\\dim{\\N{\\trans{A}A}} = \\dim{\\N{A}}$. If we\napply the \\cref{thm:ortdim} theorem to each matrix, we get the same\ndimension for the row space (the row spaces of both matrices live in\n\\R{n}, which has dimension $n$ of course): \\\\\n\n\\[\n\\dim{\\C{\\trans{A}}} = n - \\dim{\\N{A}} = n - \\dim{\\N{\\trans{A}A}} = \\dim{\\C{\\trans{(\\trans{A}A)}}}\n\\]\n\\hfill\n\nKnowing that the dimension of the row spaces is the same, we just need\nto recall that $\\dim{\\C{\\trans{A}}} = \\func{rank}(A)$, and then we can\nconclude that $\\func{rank}(A) = \\func{rank}(\\trans{A}A)$.\n\\end{proof}\n\\hfill\n\nAnother useful result about the matrix $\\trans{A}A$, that we will need\nwhen proving the SVD theorem, talks about the qualities of its\neigenvalues. \\\\\n\n\\begin{theorem}\n\\label{thm:grameig}\nLet $A$ be a real matrix of rank $r$, then its gramian matrix\n$\\trans{A}A$ has $r$ positive eigenvalues. \n\\end{theorem}\n\\hfill\n\nBesides reusing \\cref{thm:gramr}, the key step in proving \nthis result, has to do with the previously \nused fact that $\\trans{\\vec{x}}\\trans{A}A\\vec{x} = \n\\norm{A}_2^2 \\ge 0$; which implies that $\\trans{A}A$ is not only symmetric\nbut also semipositive-definite (by definition). And it turns out, that\nsemipositive-definite matrices have the desired property of having $r$\npositive eigenvalues. We will not prove this theorem here, but\n\\cite{strang88} can be consulted for further details. \n\n\n\n\n", "meta": {"hexsha": "9d9ed3e72e9a64389e8cfcfb6e1dcf6fe1651b5d", "size": 7674, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-proof-spec-gram.tex", "max_stars_repo_name": "rzavalet/svd-lsi-project-master", "max_stars_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "svd-proof-spec-gram.tex", "max_issues_repo_name": "rzavalet/svd-lsi-project-master", "max_issues_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "svd-proof-spec-gram.tex", "max_forks_repo_name": "rzavalet/svd-lsi-project-master", "max_forks_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.1034482759, "max_line_length": 97, "alphanum_fraction": 0.7073234298, "num_tokens": 2374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.9124361688107863, "lm_q1q2_score": 0.8302320603342928}}
{"text": "\\chapter{Preface}\nThis manuscript is devoted to a mathematical introduction to deep\nneural networks (DNN) through the lens of finite element and multigrid\nmethods.  Deep neural networks is the core tool in the most important class of\nmachine learning, namely deep learning, that have been successfully\napplied to many artificial intelligence (AI) tasks such as image\nclassification and natural language processing.  Despite of its great\nsuccess in practical applications, deep learning has thus far very\nlimited mathematical theories.\n%\nOn the other hand, finite element and multigrid methods are two major\nnumerical methods for solving partial differential equations arising\nfrom science and engineering.  Both finite element and multigrid\nmethod also have rich mathematical theories.\n%\nIn this manuscript, we will introduce and study deep neural networks\nthrough the lens of finite element and multigrid methods in many\ndifferent ways.  After we give brief introduction to finite element\nmethod, general iterative methods and then multigrid method, we will\nthen introduce shallow neural network as a natural generalization of\nfinite element method.  More specifically, we will illustrate that the\nmost widely used deep neural network, ReLU-DNN, is identically the\nsame as the set of all linear finite element functions.  We will\nfurther derive convolutional neural networks (CNN) as some simple\nvariations of multigrid method.\n\nWith the aforementioned mathematical relationships between deep neural\nnetworks and finite element and multigrid method, this manuscript will\nprovide an easy introduction to machine learning, especially deep\nlearning to readers with background in numerical analysis, especially\nnumerical partial differential equations.  On the other hand, this\nset of notes will be a good references for readers who are mainly working in\nthe applications of deep learning but wish to gain some mathematical\nunderstanding the relevant machine learning models.\n\nWhile there is a vast and rapidly growing literature in machine\nlearning and especially deep learning, there are relatively very few\nbooks in deep learning, see, for examples,\n\\cite{goodfellow2016deep,deng2014deep,nielsen2015neural}.\nThis manuscript will be the first manuscript to present deep neural networks\nfrom more a mathematical viewpoint.  \n\nThe reading of this book requires some basic knowledge of\nmultivariable calculus, linear algebra, and numerical analysis.  Some\nchapters, especially those chapters involving approximation theory of\nDNN require some basic knowledge of real analysis, functional analysis\nand approximation theory.  Some special efforts have been made to make\nthe presentations self-contained. \n\nThe manuscript currently, as the first draft, consists of 16\nchapters.   The first three chapters cover some basics of machine\nlearning. \n\nChapter 1 gives some mathematical discussions of the concept of\nlinearly separable sets and two linear models, namely logistic\nregression and support vector machine (SVM).\n\nChapter 2  gives a brief introduction to machine learning for its\napplication to image classification, and also simple\ndescriptions of some popular data sets, including MNIST, CIFAR and\nImageNet.  \n\nChapter 3 discusses some optimization algorithms, including the widely\nused gradient descent method, stochastic gradient descent method and\nsome convergence theory.\n\nChapter 4\n\n\nChapter 5 introduces the basic artificial neural network, deep neural\nnetwork (DNN) from the view of the finite element methods and gives a\ndiscussion about the relation between the linear finite element and\nthe general ReLU DNN.\n\nChapters 6-8 discusses some iterative methods and\npreconditioning techniques for a general system of equation which is\nwidely used in FEM and deep learning.  Especially, iterative methods\nbased on expanded systems are given in Chapter 7 to illustrate the\neffectiveness of over-parameterization in the solution of quadratic\noptimization. \n\nChapter 9 discusses a special class of multigrid algorithm for solving\n2nd order elliptic boundary value problem on the unit square\ndiscretized by piecewise linear finite element function.  One special\nfeature of such a presentation is the the multigrid method and its\nrelevant components are given in terms of discrete convolutions that\nare used in machine learning.\n\nChapter 10 gives some simple descriptions of  \nconvolutional operations and some examples of convolution filters and\nconvolutional neural network (CNN) models.\n\nChapter 11 presents a special class of convolutional neural networks, namely\nMgNet, by making some minor modification of the multigrid method\npresented in Chapter 8.  Such a special derivation of MgNet directly\nfrom multigrid method is hoped to give some mathematical insight to\nthe convolutional neural network for which mathematical understanding\nis still very limited.\n\nChapter 12 discusses basic initialization and normalization\ntechniques that are used in deep learning. \n\n\nChapter 12 presents some error estimates and adaptivity of finite\nelement methods. These results will be used by and compared with the corresponding\nerror estimates for neural networks in the later chapters. \n\nChapter 13-15 discusses the approximation properties of shallow neural\nnetworks, including the qualitative approximation and some asymptotic\napproximation properties.  The materials in these chapters are\nrelatively more theoretical than the other chapters. \n\nChapter 16 discuss some applications of deep neural network  functions\nin the numerical solution of partial differential equations. \n\nThis manuscript is based on notes accumulated from the lectures given in the following two\nsummer schools:\n(1) Summer school on numerical methods of partial differential\nequations, Guangzhou, China, 2017; (2)\nMATH 497: Deep Learning Alogrithms and Analysis, PSU, United States, 2020\nand also the following courses offered at Penn State\n(1) MATH 497: An Introduction to Deep Learning in Summer 2019; \n(2) MATH 597: Deep Learning in  Spring 2019;\n(3) MATH 556: Finite Element Methods in Fall 2018; and\n(4) MATH 597: Hierarchical Algorithms and Deep Learning in Fall 2017  \n\nMany of my former students, postdocs and collaborators have helped in\nthe preparations of the aforementioned lectures and in particular the\nset of notes, including Jianhong Chen, Juncai He, Qingguo Hong, Li\nJiang, Limin Ma, Jonathan Siegel and Lian Zhang.  I would also like to\nacknowledge that support by the Verne M. William Professorship Fund\nfrom Penn State University and the National Science Foundation (Grant\nNo. DMS-1819157) for the research related to this manuscript. \n\n\\bigskip\n\n\\noindent Jinchao Xu\n\n\\noindent December 2020 State College\n", "meta": {"hexsha": "145a9b41f849f4415bd2bf4670348492f92ffc21", "size": 6693, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/preface2020.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/preface2020.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/preface2020.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.8071428571, "max_line_length": 90, "alphanum_fraction": 0.8248916779, "num_tokens": 1394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897459384731, "lm_q2_score": 0.8824278618165527, "lm_q1q2_score": 0.8301790839274247}}
{"text": "\\chapter{Constrained Optimization}\\label{app:constrained-optimization}\n\nThe standard method of optimizing a function subject to a constraint is called Lagrangian optimization.\nTaking a function of two variables $f(x,y)$ as an example, suppose we want to optimize it subject to a constraint of the form $g(x,y)=c$.\nIn this approach, we define the ``Lagrangian function'' $\\mc{L}$ as\n\\begin{align}\n  \\mc{L}(x,y,\\la)\n\\equiv\n  f(x,y)\n-\n  \\la(g(x,y)-c)\n\\end{align}\nwhere the parameter $\\la$ is called the Lagrange multiplier.\nThe constrained optimization problem can be solved solved by optimizing $\\mc{L}$ with respect to $x$, $y$, and $\\la$.\nTo see why, consider the stationarity conditions for $\\mc{L}$.\n\\begin{align}\n  \\pd{\\mc{L}}{x}\n=\n  \\pd{f}{x}\n-\n  \\la\\pd{g}{x}\n\\overset{!}=0\n&&\n  \\pd{\\mc{L}}{y}\n=\n  \\pd{f}{y}\n-\n  \\la\\pd{g}{y}\n\\overset{!}=0\n&&\n  \\pd{\\mc{L}}{\\la}\n=\n  c\n-\n  g(x,y)\n\\overset{!}=0\n\\end{align}\nThe last equation is simply the requirement that the constraint $g(x,y)=c$ be satisfied -- i.e.\\ that the point $(x,y)$ lies along the contour of $g(x,y)$ specified by $g(x,y)=c$.\nThe first two equations correspond to the requirement that the gradients of the function $f(x,y)$ and the constraint surface $g(x,y)$ be parallel\n\\begin{align}\n  \\nabla f\n=\n  \\la\\nabla g\n\\end{align}\nwhich is always true at the point $(x,y)$ of closest approach along the line $g(x,y)=c$ to a minimum or maximum of the function $f(x,y)$.\nThis is best understood visually.\n\\begin{center}\n  \\includegraphics[width=0.5\\linewidth]{lagrangian-optimization}\n\\end{center}\nIf the gradients were not parallel, we could move along $g(x,y)=c$ to a higher contour of $f(x,y)$ by following the component of $\\nabla f$ parallel to $g(x,y)=c$.\n", "meta": {"hexsha": "f02562dc8347ec3b7e34e8f87c520f99c2929f99", "size": 1716, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/sections/constrained-optimization.tex", "max_stars_repo_name": "GQCG-edu/chem-8950", "max_stars_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "handouts/sections/constrained-optimization.tex", "max_issues_repo_name": "GQCG-edu/chem-8950", "max_issues_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-13T12:11:58.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-13T15:31:47.000Z", "max_forks_repo_path": "handouts/sections/constrained-optimization.tex", "max_forks_repo_name": "GQCG-edu/chem-8950", "max_forks_repo_head_hexsha": "a5f58a5feacbae16b02fddd2c74723da1486b8d2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.6470588235, "max_line_length": 179, "alphanum_fraction": 0.6905594406, "num_tokens": 540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158417, "lm_q2_score": 0.8840392741081574, "lm_q1q2_score": 0.8301348149521122}}
{"text": "\n\\subsection{Weak law of large numbers}\n\nThe sample mean is:\n\n\\(\\bar X_n=\\dfrac{1}{n}\\sum_{i=1}^nX_i\\)\n\nThe variance of this is:\n\n\\(Var[\\bar X_n]=Var[\\dfrac{1}{n}\\sum_{i=1}^nX_i]\\)\n\n\\(Var[\\bar X_n]=\\dfrac{1}{n^2}nVar[X]\\)\n\n\\(Var[\\bar X_n]=\\dfrac{\\sigma^2}{n} \\)\n\nWe know from Chebyshev\u2019s inequality:\n\n\\(P(|X-\\mu | \\ge k\\sigma )\\le \\dfrac{1}{k^2}\\)\n\nUse \\(\\bar X_n\\) as \\(X\\):\n\n\\(P(|\\bar X_n-\\mu | \\ge \\dfrac{k\\sigma }{\\sqrt n})\\le \\dfrac{1}{k^2}\\)\n\nUpdate \\(k\\) so \\(k:=\\dfrac{k\\sqrt n}{\\sigma}\\)\n\n\\(P(|\\bar X_n-\\mu | \\ge k)\\le \\dfrac{\\sigma^2}{nk^2}\\)\n\nAs \\(n\\) increases, the chance that the sample mean lies outside a given distance from the population mean approaches \\(0\\).\n\n", "meta": {"hexsha": "b19e3654bddf0839c72ffc742630b86944b5e8cb", "size": 680, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/iidWLLN/01-03-IIDLLN.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/iidWLLN/01-03-IIDLLN.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/iidWLLN/01-03-IIDLLN.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.6666666667, "max_line_length": 124, "alphanum_fraction": 0.6029411765, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191309994468, "lm_q2_score": 0.8688267796346599, "lm_q1q2_score": 0.8300068441096311}}
{"text": "\\textit{CLRS appendix A page 1145}\n\n\\subsection{Linearitet}\nFor any real number $ c $ and any finite sequences $ a_1,a_2,\\ldots,a_n $ and $ b_1,b_2,\\ldots,b_n $,\n$$ \\sum_{k=1}^{n}\\left( ca_k+b_k\\right) = c \\sum_{k=1}^{n}a_k + \\sum_{k=1}^{n}b_k. $$\n\n\\subsection{Arithmetic series}\nThe summation\n$$ \\sum_{k=1}^{n}k = 1+2+\\cdots+n $$\nis an \\textbf{\\textit{arithmetic series}} and has the value\n\\begin{align*}\n\\sum_{k=1}^{n}k &= \\dfrac{1}{2}n(n+1)\\\\\n&= \\Theta\\left( n^2\\right) .\n\\end{align*}\n\n\\subsection{Sums of squares and cubes}'\nWe have the following summations of squares and qubes:\n\\begin{align*}\n\\sum_{k=0}^{n}k^2&=\\dfrac{n(n+1)(2n+1)}{6}\\\\\n\\sum_{k=0}^{n}k^3&=\\dfrac{n^2(n+1)^2}{4}.\n\\end{align*}\n\n\\subsection{Geometric series}\nFor real $ x \\neq 1 $, the summation\n$$ \\sum_{k=0}^{n}x^k = 1+x+x^2+\\cdots+x^n $$\nis a \\textit{\\textbf{geometric}} or \\textbf{\\textit{exponential series}} and has the value\n$$ \\sum_{k=0}^{n}x^k = \\dfrac{x^{n+1}-1}{x-1} $$\n", "meta": {"hexsha": "a0dc8e16a9e13be2b99d1464c0f575384cfbbae9", "size": 952, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms and Data Structures - Reference/summations.tex", "max_stars_repo_name": "simwir/notes", "max_stars_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-02-12T22:22:23.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-12T22:22:23.000Z", "max_issues_repo_path": "Algorithms and Data Structures - Reference/summations.tex", "max_issues_repo_name": "simwir/notes", "max_issues_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms and Data Structures - Reference/summations.tex", "max_forks_repo_name": "simwir/notes", "max_forks_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-01-17T10:57:21.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-17T10:57:21.000Z", "avg_line_length": 34.0, "max_line_length": 101, "alphanum_fraction": 0.6355042017, "num_tokens": 417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191309994467, "lm_q2_score": 0.8688267779364222, "lm_q1q2_score": 0.8300068424872721}}
{"text": "\n\\subsection{Matrix rank}\n\\subsubsection{Rank function}\n\nThe rank of a matrix is the dimension of the span of its component columns.\n\n\\(rank (M)=span(m_1,m_2,...,m_n)\\)\n\n\\subsubsection{Column and row span}\n\nThe span of the rows is the same as the span of the columns.\n\n\n", "meta": {"hexsha": "55424160dd351f203157b4cb43e16842daf7dc78", "size": 270, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystems/02-01-rank.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/linearSystems/02-01-rank.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/linearSystems/02-01-rank.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.2857142857, "max_line_length": 75, "alphanum_fraction": 0.7333333333, "num_tokens": 72, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9553191335436404, "lm_q2_score": 0.8688267660487573, "lm_q1q2_score": 0.8300068333412219}}
{"text": "\\subsection{General activation functions}\nAssume that $\\sigma$ is a locally Riemann integrable nonzero function \nand $\\sigma\\in L^1(\\mathbb{R})$ and thus the Fourier transform of\n $\\sigma$ is well-defined and continuous. \n Since $\\sigma$ is non-zero and \n \\begin{equation}\\label{key}\n \\hat \\sigma(\\omega) = \\int_{\\mathbb{R}} \\sigma(t)e^{-2\\pi i\\omega t}dt,\n \\end{equation}\n this implies that $\\hat{\\sigma}(a)\\neq 0$ for\n some $a\\neq 0$. Via a change of variables $t = \\omega\\cdot x + b$ and $dt = db$,\n  this means that for all $x$ and $\\omega$, we have\n \\begin{equation}\n \\begin{aligned}\n  0\\neq \\hat{\\sigma}(a)&= \\int_{\\mathbb{R}}\\sigma(\\omega\\cdot x+b)e^{-2\\pi ia(\\omega\\cdot x+b)}db \\\\\n & = e^{-2\\pi ia\\omega \\cdot x} \\int_{\\mathbb{R}}\\sigma(\\omega\\cdot x+b)e^{-2\\pi iab}db ,\n \\end{aligned}\n \\end{equation}\n and so\n \\begin{equation}\n  e^{2\\pi ia\\omega \\cdot x} = \\frac{1}{\\hat{\\sigma}(a)}\\int_{\\mathbb{R}}\\sigma(\\omega\\cdot x+b)e^{-2\\pi iab}db.\n \\end{equation}\n Likewise, since the growth condition also implies that $\\sigma^{(k)}\\in L^1$, we can differentiate the above expression  under the integral with respect to $x$.\n\n This allows us to write the Fourier mode $e^{2\\pi ia\\omega \\cdot x}$ as an integral of neuron output functions. We substitute this\n into the Fourier representation of $u$\n (note that the assumption we make implies that $\\hat{u}\\in L^1$ so this\n is rigorously justified for a.e. $x$) to get\n \\begin{equation}\\label{integral_representation}\n \\begin{split}\n  u(x) &= \\int_{\\mathbb{R}^d} e^{2\\pi i\\omega\\cdot x}\\hat{u}(\\omega)d\\omega = \n  \\int_{\\mathbb{R}^d}\\int_\\mathbb{R}\\frac{1}{ \\hat{\\sigma}(a)}\n  \\sigma\\left(a^{-1}{\\omega}\\cdot\n    x+b\\right)\\hat{u}(\\omega)e^{-2\\pi iab}dbd\\omega\n\\\\\n&=  \\int_{\\mathbb{R}^d}\\int_\\mathbb{R} k(x,\\theta) dbd\\omega \n\\end{split}\n \\end{equation}\nwhere $\\theta=(\\omega, b)$ \nand   \n$$\nk(x,\\theta)= \\frac{1}{ \\hat{\\sigma}(a)}\n  \\sigma\\left(a^{-1}{\\omega}\\cdot\n    x+b\\right)\\hat{u}(\\omega)e^{-2\\pi iab}.\n$$", "meta": {"hexsha": "3c45a68aa9a4f7970eaef1483f4ea209a95425e8", "size": 1962, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DoubleFourier.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/DoubleFourier.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/DoubleFourier.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.5909090909, "max_line_length": 161, "alphanum_fraction": 0.6595310907, "num_tokens": 708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572777987970316, "lm_q2_score": 0.867035758084294, "lm_q1q2_score": 0.8299940819772486}}
{"text": "\n\\subsection{Euler's totient function}\n\nThis functions counts numbers up to \\(n\\) which are relatively prime\n\neg for 10 we have \\(1\\), \\(3\\), \\(7\\), \\(9\\).\n\nSo \\(\\phi (10)=4\\)\n\n", "meta": {"hexsha": "297e3d1f6847782b51dbe4bed4caa6d65db9a288", "size": 177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/primes/01-03-totient.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/primes/01-03-totient.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/primes/01-03-totient.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.7, "max_line_length": 68, "alphanum_fraction": 0.6214689266, "num_tokens": 57, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9532750360641186, "lm_q2_score": 0.8705972734445508, "lm_q1q2_score": 0.8299186472401775}}
{"text": "\\chapter{Perceptron}\n\n\\section{Linear Classifier}\nA linear classifier implements a decision boundary represented by a straight line in the multidimensional feature space.\nThe discriminant function:\n\\begin{equation*}\n\\begin{split}\nf(\\mathbf{x}) &=\\sum_{i=0}^{I} w_i x_i \\\\\n&= \\mathbf{w^{T}x}\n\\end{split}\n\\end{equation*}\nThe decision boundary is given by:\n$$f(\\mathbf{x})=0$$\n\n\\section{Simple Perceptron}\nNet synaptic input:\n$$\\mathbf{u} = \\sum_{i=0}^{I} x_i w_i $$\n\\begin{center}where $w_0 = \\theta$ and $x_0=-1$ \\end{center}\nThe output of the neuron unit is:\n$$y = \\Phi(\\mathbf{u})$$\nFor the rest of this section, we look at learning algorithm for discrete perceptron, using hard limiter as the output activation function.\n\n\\subsection{Basic Perceptron Learning Algorithm (Minsky)}\nIn each iteration, the weight is updated by:\n$$w_{new} =\n\\begin{cases} \n    w_{old} + x & y=0\\ and\\ d=1 \\\\\n    w_{old} - x & y=1\\ and\\ d=0 \\\\\n    w_{old} & if y==d\n\\end{cases}\n$$\n\n\\subsection{Modified Perceptron Learning Algorithm}\nThe weights change proportional to the difference between the desired output and perceptron output:\n$$Error, \\varepsilon = d - \\Phi(u)$$\n$$\\mathbf{w}^{new}=\\mathbf{w}^{old} + \\alpha \\varepsilon \\mathbf{x}$$\n\\begin{center} \nwhere learning factor ($0< \\alpha \\le 1$) and \n$\\varepsilon \\in \\{+1, 0, 1\\}$\n\\end{center}\n\\section{Continuous Perceptron}\nThe adjustment of weight vector is resolved by using \\emph{gradient descent} algorithm:\n$$\\mathbf{\\triangle w} = - \\alpha \\frac{\\partial E(\\mathbf{w})}{\\partial \\mathbf{w}}$$\n\\begin{equation}\n\\begin{split}\n\\mathbf{w^{new}} &= \\mathbf{w^{old} + \\triangle w } \\\\\n&= \\mathbf{w^{old}} - \\alpha \\frac{\\partial E(\\mathbf{w})}{\\partial w}\n\\end{split}\n\\label{weight_update}\n\\end{equation}\nThe error function is:\n$$E(\\mathbf{w})=\\frac{1}{2}(d-o)^{2}$$\n\\begin{center}\nwhere \n$o = f(u)$,\n$u=\\mathbf{w^{T}x}$\n\\end{center}\nThe gradient of error function:\n\\begin{equation}\n\\begin{split}\n\\frac{\\partial E(\\mathbf{w})}{\\partial \\mathbf{w}} &= \\frac{1}{2} \\frac{\\partial (d-o)^{2}}{\\partial \\mathbf{w}} \\\\\n&= - (d-o) \\frac{\\partial f(u)}{\\partial \\mathbf{w}} \\\\\n&= - (d-o) \\frac{\\partial f(u)}{\\partial u} \\frac{\\partial u}{\\partial \\mathbf{w}}\n\\end{split}\n\\label{error_derive}\n\\end{equation}\nThe synaptic input is:\n\\begin{equation}\n\\begin{split}\nu &= \\sum_{i=0}^{I} w_i x_i \\\\\n\\frac{\\partial u}{\\partial w_i} &= x_i \\\\\n\\frac{\\partial u}{\\partial \\mathbf{w}} &= \\mathbf{x}\n\\end{split}\n\\label{input_derive}\n\\end{equation}\n\\noindent Substituting \\ref{input_derive} to \\ref{error_derive}:\n\\begin{equation}\n\\frac{\\partial E(\\mathbf{w})}{\\partial \\mathbf{w}} = - (d-o) \\frac{\\partial f(u)}{\\partial u} \\mathbf{x}\n\\label{error_derive_input_derive}\n\\end{equation}\n\\noindent Substituting \\ref{error_derive_input_derive} to \\ref{weight_update}\n\\begin{equation}\n\\begin{split}\n\\mathbf{w}^{new} &= \\mathbf{w}^{old} + \\alpha (d-o) \\frac{\\partial f(u)}{\\partial u} \\mathbf{x} \\\\\n\\mathbf{w}^{new} &= \\mathbf{w}^{old} + \\alpha \\delta \\mathbf{x}\n\\end{split}\n\\label{weight_update_2}\n\\end{equation}\n\\begin{center}where $\\delta = (d-o) \\frac{\\partial f(u)}{\\partial u}$\\end{center}\n\n\\subsubsection{Unipolar Sigmoid Function}\n$$f(u) = o = \\frac{a}{1+exp(-bu)}$$\n$$\\frac{\\partial f(u)}{\\partial u} = by \\Big(1- \\frac{y}{a}\\Big)$$\n\n\\subsubsection{Bipolar Sigmoid Function}\n$$f(u) = o = \\frac{a(1-exp(-bu))}{1+exp(-bu)}$$\n$$\\frac{\\partial f(u)}{\\partial u} = \\frac{ab}{2} \\Big(1-\\frac{o^{2}}{a^{2}}\\Big)$$\n\n\\section{Limitation of Perceptron}\n\\begin{itemize}\n\\item A perceptron can perform pattern classification only on linearly separable patterns\n\\item The algorithm may stuck in local minima, sensitive to the starting point\n\\end{itemize}\n", "meta": {"hexsha": "b12a66862977db6981c3f9184fcbbddfb915638f", "size": 3660, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter2.tex", "max_stars_repo_name": "Andyccs/neural-network-summary", "max_stars_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter2.tex", "max_issues_repo_name": "Andyccs/neural-network-summary", "max_issues_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter2.tex", "max_forks_repo_name": "Andyccs/neural-network-summary", "max_forks_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.1923076923, "max_line_length": 138, "alphanum_fraction": 0.6767759563, "num_tokens": 1291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.9032941988938413, "lm_q1q2_score": 0.8296578782422718}}
{"text": "\\section{Parametric \\& Vector Functions}\r\nUp to this point, almost all the graphs we have worked with have been of the form $y=f(x)$, defining the $y$ coordinate in terms of the $x$ coordinate.\r\nThese sorts of functions are limited in the types of graphs they can draw.\r\nIf we instead let both the $x$ and $y$ coordinates be defined in terms of another variable $t$, like $(x(t),y(t))$, then we can draw much more interesting graphs.\r\nFor example, a unit circle, which can't be defined with a single function $y=f(x)$, would be $(\\cos{t}, \\sin{t})$. \\\\\r\n\r\n\r\nWe are always able to translate a function of the form $y=f(x)$ into a parametric function as $(t, f(t))$.\r\nSometimes, but not always, we are also able to translate parametric functions into $y$ as a function of $x$.\r\n\r\n\\begin{example}\r\n\tGiven the following parametric function, find $y$ as a function of $x$.\r\n\t\\begin{equation*}\r\n\t\t(\\sqrt{t}, t-2).\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tSquaring both sides of the $x$ equation,\r\n\t\\begin{equation*}\r\n\t\tx^2 = t.\r\n\t\\end{equation*}\r\n\t\r\n\tSubstituting our expressing for $t$ in terms of $x$ into the $y$ equation,\r\n\t\\begin{equation*}\r\n\t\ty = x^2 - 2.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\subsection{Vector Functions}\r\nVector and parametric functions are essentially the same thing.\r\nIn fact, in multivariable calculus, we drop the idea of parametric functions almost completely and exclusively talk about vector-valued functions.\r\nBoth can graph the exact same functions.\r\nVisually, you might imagine an arrow rooted at the origin tracing out the graph of a vector function. \r\nYou're more likely to see vector functions written in the following form\r\n\\begin{equation*}\r\n\t\\vec{r}(t) = \\langle x(t), y(t) \\rangle.\r\n\\end{equation*}\r\n\r\nAll the normal vector operations, like addition and subtraction, scalar multiplication, and dot products work exactly the same.\r\nIf we think of $\\vec{r}(t)$ as a position function,\r\n\\begin{align*}\r\n\t\\textbf{Velocity: }& \\vec{v}(t) = \\vec{r^\\prime}(t) = \\langle x^\\prime(t), y^\\prime(t) \\rangle \\\\\r\n\t\\textbf{Speed: }& \\abs{\\vec{v}(t)} = \\sqrt{\\left(x^\\prime(t)\\right)^2 + \\left(y^\\prime(t)\\right)^2} \\\\\r\n\t\\textbf{Acceleration: }& \\vec{a}(t) = \\vec{v^\\prime}(t) = \\langle x^{\\prime\\prime}(t), y^{\\prime\\prime}(t) \\rangle \\\\\r\n\t\\textbf{Direction: }& \\frac{\\vec{v}(t)}{\\abs{\\vec{v}(t)}}.\r\n\\end{align*}\r\n\r\n\\subsection{Slope \\& Concavity}\r\nJust like with functions like $y=f(x)$, we can find the slope and concavity of parametric functions using first and second derivatives respectively.\r\nWe just apply the chain rule.\r\n\\begin{align*}\r\n\t\\dd{y}{x} &= \\frac{\\dd{y}{t}}{\\dd{x}{t}} \\\\\r\n\t\\dd{^2y}{x^2} &= \\dd{y^\\prime}{x} = \\frac{\\d{y^\\prime}/\\d{t}}{\\d{x}/\\d{t}}.\r\n\\end{align*}\r\n\r\n\\begin{example}\r\n\tConsider the following parametric function:\r\n\t\\begin{equation*}\r\n\t\t(t^2-5, 2\\sin{t}), 0\\leq t\\leq\\pi.\r\n\t\\end{equation*}\r\n\tFind the first and second derivatives of $y$ with respect to $x$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tDifferentiating both $x$ and $y$ with respect to $t$,\r\n\t\\begin{align*}\r\n\t\tx^\\prime(t) &= 2t \\\\\r\n\t\ty^\\prime(t) &= 2\\cos{t} \\\\\r\n\t\t\\dd{y}{x} &= \\frac{2\\cos{t}}{2t} = \\frac{\\cos{t}}{t}.\r\n\t\\end{align*}\r\n\tFinding the derivative of $y^\\prime$ with respect to $t$,\r\n\t\\begin{align*}\r\n\t\t\\dd{}{t}y^\\prime &= \\dd{}{t}\\frac{\\cos{t}}{t} \\\\\r\n\t\t&= \\frac{-t\\sin{t}-\\cos{t}}{t^2} \\\\\r\n\t\t\\dd{^2y}{x^2} &= \\frac{\\d{y^\\prime}/\\d{t}}{\\d{x}/\\d{t}} \\\\\r\n\t\t&= \\frac{\\frac{-t\\sin{t}-\\cos{t}}{t^2}}{2t} \\\\\r\n\t\t&= -\\frac{t\\sin{t}+\\cos{t}}{2t^3}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsection{Arc Length}\r\nRemember that we had the following formula for $\\d{s}$ when deriving arc length.\r\n\\begin{equation*}\r\n\t\\d{s} = \\sqrt{\\left(\\d{x}\\right)^2 + \\left(\\d{y}\\right)^2}.\r\n\\end{equation*}\r\nSince we now have $x$ and $y$ as functions of $t$, we can rewrite this formula to get a formula for arc length of a parametric function.\r\n\\begin{align*}\r\n\t\\d{s} &= \\sqrt{\\left(\\dd{x}{t}\\right)^2 + \\left(\\dd{y}{t}\\right)^2}\\d{t} \\\\\r\n\ts &= \\int_{a}^{b}{\\sqrt{\\left(\\dd{x}{t}\\right)^2 + \\left(\\dd{y}{t}\\right)^2}\\d{t}}.\r\n\\end{align*}\r\n\r\nWhen talking about vector-valued functions or working in a more physics-based context, you might hear the term ``distance traveled'' instead of arc length and see the following formula.\r\nThey are equivalent ideas.\r\n\\begin{equation*}\r\n\ts = \\int_{a}^{b}{\\abs{\\vec{v}(t)}\\d{t}}.\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tA circle of radius $r$ is defined parametrically as\r\n\t\\begin{equation*}\r\n\t\t(r\\cos{t}, r\\sin{t}), 0 \\leq t \\leq 2\\pi.\r\n\t\\end{equation*}\r\n\tUse this definition to find its circumference.\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\t\t\\dd{x}{t} &= -r\\sin{t} \\\\\r\n\t\t\\left(\\dd{x}{t}\\right)^2 &= r^2\\sin^2{t} \\\\\r\n\t\t\\dd{y}{t} &= r\\cos{t} \\\\\r\n\t\t\\left(\\dd{y}{t}\\right)^2 &= r^2\\cos^2{t} \\\\\r\n\t\tC &= \\int_{0}^{2\\pi}{\\sqrt{r^2\\sin^2{t}+r^2\\cos^2{t}}\\d{t}} \\\\\r\n\t\t&= \\int_{0}^{2\\pi}{r\\sqrt{\\sin^2{t}+\\cos^2{t}}\\d{t}} \\\\\r\n\t\t&= \\int{0}^{2\\pi}{r\\d{t}} \\\\\r\n\t\t&= 2\\pi r.\r\n\t\\end{align*}\r\n\\end{answer}", "meta": {"hexsha": "4f9600b19ca4cfdd1a20b5eacd541e496b26c021", "size": 4937, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/parametric_vector_polar/parametric_vector.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/parametric_vector_polar/parametric_vector.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/parametric_vector_polar/parametric_vector.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 42.9304347826, "max_line_length": 186, "alphanum_fraction": 0.6352035649, "num_tokens": 1764, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164656, "lm_q2_score": 0.8840392832736084, "lm_q1q2_score": 0.829338478143951}}
{"text": "\n\\subsection{Gaussian elimination}\n\n\\subsubsection{Simultaneous equations}\n\nMatricies can be used to solve simultaneous equations. Condsider the following set of equations.\n\n\\begin{itemize}\n\\item \\(2x+y-z=8\\)\n\\item \\(-3x-y+2z=-11\\)\n\\item \\(-2x+y+2z=-3\\)\n\\end{itemize}\n\nWe can write this in matrix form.\n\n\\(Ax=y\\)\n\n\\(A=\\begin{bmatrix}2 & 1&-1\\\\-3 & -1&2\\\\-2&1&2\\end{bmatrix}\\)\n\n\\(x=\\begin{bmatrix}x \\\\y \\\\z\\end{bmatrix}\\)\n\n\\(y=\\begin{bmatrix}8 \\\\-11 \\\\-3\\end{bmatrix}\\)\n\n\\subsubsection{Augmented matrix}\n\nConsider a form for summarising these equations. This is the augmented matrix.\n\n\\((A|y)=\\begin{bmatrix}2 & 1&-1&|&-8\\\\-3 & -1&2&|&-11\\\\-2&1&2&|&-3\\end{bmatrix}\\)\n\nWe can take this and recovery our original \\(A\\) and \\(y\\).\n\nHowever we can also do things to this augmented matrix which preserve solutions to the set of equations. These are:\n\nUndertaking combinations of these can make it easier to solve the equation. In particular, if we can arrive at the form:\n\n\\((A|y)=\\begin{bmatrix}1 & 0&0&|&a\\\\0 & 1&0&|&b\\\\0&0&1&|&c\\end{bmatrix}\\)\n\nThe solutions for \\(x,y,z\\) are \\(a,b,c\\).\n\n\\subsubsection{Echeleon / triangular form}\n\nWe first aim for:\n\n\\((A|y)=\\begin{bmatrix}a_{11} & a_{12}&a_{13}&|&a\\\\0 & a_{22}&a_{23}&|&b\\\\0&0&a_{33}&|&c\\end{bmatrix}\\)\n\nIf this cannot be reached there is no single solution. There may be infinite or no solutions.\n\n\\subsubsection{Solving}\n\nOnce we have the triangular form, we can easily solve.\n\n\\((A|y)=\\begin{bmatrix}a_{11} & a_{12}&a_{13}&|&a\\\\0 & a_{22}&a_{23}&|&b\\\\0&0&a_{33}&|&c\\end{bmatrix}\\)\n\n\\((A|y)=\\begin{bmatrix}1 & 0&0&|&a\\\\0 & 1&0&|&b\\\\0&0&1&|&c\\end{bmatrix}\\)\n\nThis process is back substitution (or forward substitution if the matrix is triangular the other way).\n\n\\subsubsection{Matrix inversion}\n\nWe can think of the inverse of a matrix as one which which takes a series of reverible operations and does these to a matrix then arriving at the identity matrix.\n\nThat is, only the three elementary row operations, and combinations of them, can transform a matrix in a way in which it can be reversed. As such All reversible matricies are combinations of the identity matrix and a series of elementary row operations. The inverse matrix is then those series of row operations, in reverse.\n\nWe can find identify an inversion by undertaking gaussian elimination. Each step done on the matrix is done to the identify matrix, reversing the process. The end result is the inverted matrix.\n\nInstead of:\n\n\\((A|y)=\\begin{bmatrix}2 & 1&-1&|&-8\\\\-3 & -1&2&|&-11\\\\-2&1&2&|&-3\\end{bmatrix}\\)\n\nTake:\n\n\\((A|I)=\\begin{bmatrix}2 & 1&-1&|&1&0&0\\\\-3 & -1&2&|&0&1&0\\\\-2&1&2&|&0&0&1\\end{bmatrix}\\)\n\nWhen we solve this we get:\n\n\\((I|A^{-1})=\\begin{bmatrix}1 & 0&0&|&\\dfrac{3}{4}&\\dfrac{1}{2}&\\dfrac{1}{4}\\\\0& 1&0&|&\\dfrac{1}{2}&1&\\dfrac{1}{2}\\\\0&0&1&|&\\dfrac{1}{4}&\\dfrac{1}{2}&\\dfrac{3}{4}\\end{bmatrix}\\)\n\n", "meta": {"hexsha": "7560e90399bdbc0cca850a6de38bdbb92ae51829", "size": 2834, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystems/03-04-linearGauss.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/linearSystems/03-04-linearGauss.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/linearSystems/03-04-linearGauss.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.3333333333, "max_line_length": 324, "alphanum_fraction": 0.6803105152, "num_tokens": 1015, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654263, "lm_q2_score": 0.8902942261220292, "lm_q1q2_score": 0.8292756901089104}}
{"text": "\\section{Projection Operator: Continuous Fourier Expansion}\n\t\\vspace{0.2cm}\n\t\t\n\tWe define the projection operator denoted as $\\mathcal{P}_N$ as the truncated Fourier series, i.e.,\n\t\\begin{equation}\n\t\\label{proyection_operator}\n\t\t\\mathcal{P}_N u(x) \\equiv  \\displaystyle \\sum_{ |n| \\leq \\frac {N}{2}} \\hat{u}_{n} e^{inx}.\n\t\\end{equation}\t\n\tWe will denote to $\\hat{B}_N$ as the finite subset of $B = span\\{e^{inx}: |n| \\leq \\infty \\}$ on which it is projected the function, represented as follows\n\t\\begin{align*}\n\t\t\\hat{B}_{N} = span \\left\\{e^{inx}: |n| \\leq \\frac {N}{2} \\right\\},\\hspace{0.2cm} dim(\\hat{B}_{N}) = N + 1.\n\t\\end{align*}\n\tThen by the orthogonality relation (\\ref{ortho_phi}), it can be seen that for $u(x) \\in L^2 [0, 2\\pi]$\n\t\\begin{align*}\n\t\t\\langle \\mathcal{P}_N u, v \\rangle = \\langle u, v \\rangle, \\hspace{3mm} \\forall v \\in S_N.\n\t\\end{align*}\n\tThis shows that $\\mathcal{P}_N u$ is the orthogonal projection of $u$ upon the space of the trigonometric polynomials of degree $N$.\\\\\n\t\n\tEquivalently, $\\mathcal{P}_N u$ is the closest element to $u$ in $\\hat{B}_N$ with respect to the inner product\n\t\\begin{align*}\n\t\t\\langle u, v \\rangle = \\displaystyle \\int_{0}^{2 \\pi} u(x) \\overline{v(x)} dx,\n\t\\end{align*}\n\tand this also defines the norm\n\t\\begin{align}\n\t\\label{L2_dot}\n\t\t\\| u \\|^2 = \\displaystyle \\int_{0}^{2 \\pi} |u(x)|^2 dx.\n\t\\end{align}\n\t\n\tA full characterization of the functions for which the Fourier series is convergent is the framework of Lebesgue integration for convergence in mean. This convergence can be defined in $L^2 (0, 2 \\pi)$ (square-integrable functions), also is a complex Hilbert space with inner product defined by (\\ref{L2_dot}). Then for $u \\in L^2 (0, 2 \\pi)$ the Fourier series $F(u)$ given by (\\ref{fourier_series}) is said to be convergent in mean (or $L^2$-convergent) to $u$ if\n\t\\begin{align}\n\t\t\\label{L2_mean}\n\t\t\\displaystyle \\int_{0}^{2 \\pi} |u(x) - \\mathcal{P}_N u(x) |^2 dx \\rightarrow 0, \\hspace{2mm} \\text{as} \\hspace{2mm} N \\rightarrow \\infty,\n\t\\end{align}\n\t\n\tThen the Functions in $L^2 (0, 2 \\pi)$ can be characterized in terms of their Fourier coefficients, according to the Riesz theorem, in the following sense. If $u \\in L^2 (0, 2 \\pi)$, then its Fourier series converges to $u$ in the sense of (\\ref{L2_mean}), and by Parseval's identity show us that\n\t\\begin{align}\n\t\\label{parseval}\n\t\t\\| u \\|^2 = 2 \\pi \\displaystyle \\sum^{\\infty}_{-\\infty} |\\hat{u}_n|^2.\n\t\\end{align}\n\tConversely, if for any complex sequence $\\{\\hat{u}_n \\}$, $n = 0, \\pm 1, \\dots $, and $\\sum^{\\infty}_{n=-\\infty} |\\hat{u}_n|^2 < \\infty$, there exists a unique function $u \\in L^2 (0, 2 \\pi)$ such that its Fourier coefficients are precisely the $\\hat{u}_n$$'$s for any $n$. Thus, for any function $u \\in L^2 (0, 2 \\pi)$ can be written as\n\t\\begin{align}\n\t\tu = \\displaystyle \\sum^{\\infty}_{n=-\\infty} \\hat{u}_n \\phi_n.\n\t\\end{align}\n\t\n\tThe Riesz theorem states that the finite Fourier transform is an isomorphism between $L^2 (0, 2\\pi)$ and the space $l^2$ of complex sequences $\\{\\hat{u}_n \\}$, $n = 0, \\pm1, \\pm2, \\dots$, such that $\\sum^{\\infty}_{n=-\\infty} |\\hat{u}_n|^2 < \\infty$. The above can be summed up in the following theorem. \n\t\n\t\\begin{teor}\n\t\t If the sum of squares of the Fourier coefficients is bounded\n\t\t\\begin{align*}\n\t\t\t\\displaystyle \\sum_{ |n| \\leq \\infty} |\\hat{u}_n|^2 < \\infty\n\t\t\\end{align*}\n\t\tthen the truncated series converges in the $L^2$ norm\n\t\t\\begin{align*}\n\t\t\t\\|u -  \\mathcal{P}_N u \\|_{L^2 [0, 2\\pi]} \\rightarrow 0 \\hspace{0.5cm} \\text{as} \\hspace{0.5cm} N \\rightarrow \\infty.\n\t\t\\end{align*}\n\t\tIf, moreover, the sum of the absolute values of the Fourier coefficients is bounded\n\t\t\\begin{align*}\n\t\t\t\\displaystyle \\sum_{ |n| \\leq \\infty} |\\hat{u}_n| < \\infty\n\t\t\\end{align*}\n\t\tthen the truncated series converges uniformly \n\t\t\\begin{align*}\n\t\t\t\\|u -  \\mathcal{P}_N u \\|_{L^{\\infty} [0, 2\\pi]} \\rightarrow 0 \\hspace{0.5cm} \\text{as} \\hspace{0.5cm} N \\rightarrow \\infty. \n\t\t\\end{align*}\n\t\\end{teor}\n\t\n\tNote that if the truncated sum converges implies that the error is dominated by the tail of the series, i.e.,\n\t\\begin{align*}\n\t\t\\|u -  \\mathcal{P}_N u \\|^2_{L^2 [0, 2\\pi]} = 2 \\pi\t\\displaystyle \\sum_{ |n| > \\frac{N}{2} } |\\hat{u}_n|^2,\n\t\\end{align*}\t\n\tand\t\n\t\\begin{align*}\n\t\t\\|u -  \\mathcal{P}_N u \\|_{L^{\\infty} [0, 2\\pi]} \\leq \n\t\t\\displaystyle \\sum_{|n| > \\frac{N}{2}} |\\hat{u}_n|. \n\t\\end{align*}\n\tThus, the error committed by replacing $u(x)$ with its $N$th-order Fourier series depends solely on how fast the expansion coefficients of $u(x)$ decay. \\\\\n\t\n\tTo appreciate this, suppose that $u(x) \\in L^2_p [0, 2 \\pi]$ and that its derivative $u'(x) \\in L^2_p [0, 2\\pi]$, where the subscript $p$ indicate that the function is periodic. then for $n \\neq 0$ we have to\n\t\\begin{align*}\n\t\t2\\pi \\hat{u}_N &= \\displaystyle \\int_{0}^{2\\pi} u(x) e^{-inx} dx \\\\\n\t\t&= - \\frac{1}{in} (u(2\\pi) - u(0)) - \\frac{1}{in} \\displaystyle \\int_{0}^{2\\pi} u'(x) e^{inx} dx, \n\t\\end{align*}\n\ttherefore\n\t\\begin{align*}\n\t\t|\\hat{u}_N| \\propto \\frac{1}{n}.\n\t\\end{align*}\n\t\n\tIn general, if for $u(x)$ and its derivatives $(m - 1)$, and its periodic extensions are all continuous, and also if its derivative $m$th is measurable at $[0, 2 \\pi]$, also known in the literature as the regularity of the function, in this particular case in $L^2_p$, we have to $\\forall n \\neq 0$, repeating the previous procedure successively, the behavior of Fourier coefficients $\\hat{u}_n$ of $u(x)$ is similar, i.e.,\n\t\\begin{align*}\n\t\t|\\hat{u}_n| \\propto \\left(\\frac{1}{n}\\right)^m.\n\t\\end{align*}\n\t\n\t This is known as spectral convergence, which means that the smoother the function, the series converges faster.\\\\\n\t \n\t This result is important since it will allow us to investigate the convergence rate of the methods, which we will define in detail later. Therefore, we will focus on periodic functions expanded in Fourier series since its rapid decay of the coefficients implies that the Fourier series truncated after just a few more terms represents an exceedingly good approximation of the function. However, in practice, this decay is not exhibited until there are enough coefficients to represent all the essential structures of the function but in general, functions can be described both through their values in physical space and through their coefficients in transform space. The following examples illustrate the previous results. \\\\\n\t \n\t\\begin{example}\n\t    Consider the function $u(x) \\in C^{\\infty} [0, 2 \\pi]$ given by\n    \t\\begin{align}\n    \t\t\\label{Example1} \n    \t    u(x) = \\frac{1}{5 - 4 \\cos(x)}   \n    \t\\end{align}\n    \twith its expansion coefficients\n    \t\\begin{align*}\n    \t     \\hat{u}_{n} = \\frac{2^{-|n|}}{3}.\n    \t\\end{align*}\n    \n    \tIn Figure \\ref{fig1} we can clearly observe the convergence of the Fourier series and that in addition, the convergence of the approximation is almost uniform. This is due to the periodicity of the function and its derivatives.\n    \t\n    \t\\begin{figure}[H]\n        \\includegraphics[width=\\textwidth]{preliminaries/figures/example21.png}\n        \\caption{(a) Continuous Fourier series approximation of the equation (\\ref{Example1}). (b) The Pointwise error of approximation.}\n        \\label{fig1}\n        \\end{figure}\n\t\\end{example} \n\t\n\t\\begin{example}\n\t    The expansion coefficients of the function\n    \t\\begin{align}\n    \t\t\\label{Example2} \n    \t    u(x) = \\frac{\\pi}{2} \\sin(\\frac{x}{2})\n    \t\\end{align}\n    \tare given by\n    \t\\begin{align*}\n    \t     \\hat{u}_{n} = \\frac{1}{(1 - 4n^2)}.\n    \t\\end{align*}\n    \t\n    \tNote that is infinitely differentiable in $[0, 2 \\pi]$, but $u'(0) \\ne u' (2 \\pi)$. In Figure \\ref{fig2} we can see that the convergence is much slower than in the Example \\ref{Example1}, as expected\t\n    \t\\begin{figure}[H]\t\n        \\includegraphics[width=\\textwidth]{preliminaries/figures/example22.png}\n        \\caption{(a) Continuous Fourier series approximation of the equation (\\ref{Example2}). (b) The Pointwise error of approximation for increasing resolution.}\n        \\label{fig2}\n    \t\\end{figure}\n\t\\end{example} \n\t\n\t\\subsection{Differentiation of the Continuous Expansion}\n\n\tTo find solutions of partial differential equations using the spectral methods, in addition to approximating a function $u(x)$ by the finite Fourier series $\\mathcal{P}_N u$, we also need to obtain its derivatives. Due to the linearity of the derivative and that these functions are exponential, we can easily obtain the derivatives of $\\mathcal{P}_N u$ by simply differentiating the basis functions term by term. Therefore, if we have the following series truncated \\\\\n \t\\begin{align*}\n   \t\t\\mathcal{P}_N u(x) =  \\displaystyle \\sum_{ |n| \\leq \\frac {N}{2}} \\hat{u}_{n} e^{inx},\n   \t\\end{align*}\n    from this, we can get\n   \t\\begin{align*}\n   \t\t\\frac{d^q}{dx^q} \\mathcal{P}_N u(x) = \\displaystyle \\sum_{ |n| \\leq \\frac {N}{2}} \\hat{u}_{n} \\frac{d^q}{dx^q} e^{inx} = \\displaystyle \\sum_{ |n| \\leq \\frac {N}{2}} (in)^q \\hat{u}_{n}e^{inx}.\n   \t\\end{align*}\n    Therefore the projection and differentiation operators commute, i.e.,\n    \t\\begin{align*}\n    \t\\mathcal{P}_N \\frac{d^q}{dx^q} u = \\frac{d^q}{dx^q}\\mathcal{P}_N u.\n    \t\\end{align*}\n    This property implies that for any differentiation operator $\\mathcal{L}$ with constant coefficients,\t\n    \t\\begin{align*}\n    \t\\mathcal{P}_N \\mathcal{L} (I - \\mathcal{P}_N)u\n    \t\\end{align*}\n     vanishes, which known as the truncation error. Thus, the Fourier approximation to the equation $u_t = \\mathcal{L}u$ is exactly the projection of the analytic solution. \n\n    \\subsection{Approximation theory for Continuous Expansion.}\n    \n    The behavior of the functions and their derivatives that we have shown is relevant when the solutions of the differential equations are approximated using spectral methods since it allows us to investigate how fast and precise they can be. In this subsection, we will present these properties based in \\cite{gottlieb2007} as detailed as possible some useful results for our main objective regarding the analysis of the projection operator already defined above. \\\\\n    \n    When using the Fourier approximation to discretize the spatial part of the equation\n    \\begin{align*}\n        u_t = \\mathcal{L}u,\n    \\end{align*}\n    it is important that our approximation, both to $u$ and to $\\mathcal{L}u$, be accurate,i.e., we must consider not only the difference between $u$ and $\\mathcal{P}_N u$ if not also the distance between $\\mathcal{L} u$ and $\\mathcal{L} \\mathcal{P}_N u$, measured in an appropriate norm. This is because the actual rate of convergence is determined by the truncation error    \n    \\begin{align*}\n    \t\\mathcal{P}_N \\mathcal{L} (I - \\mathcal{P}_N)u.\n    \\end{align*}\n   \tThus, the error is determined not only by the behavior of the Fourier approximations of the function but also of its derivatives, as we have seen previously. Therefore, the Sobolev $q$-norm denoted by $H^q_p [0, 2\\pi]$, It is appropriate to estimate the truncation error since it measures the smoothness of the derivatives and the function. This norm is defined as follows\n    \\begin{align}\n    \\label{sobolev_norm}\n    \t \\|u\\|^2_{H^q_p [0, 2\\pi]} = \\displaystyle \\sum^{q}_{m=0} \\int^{2\\pi}_{0} \\left| u^m (x) \\right|^2 dx.\n    \\end{align}\n    The subscript $p$ indicates the fact that all functions are periodic. By substituting the Fourier expansion for each derivative in (\\ref{sobolev_norm}), the Sobolev norm can be written as\n    \t\\begin{align*}\n    \t    \\|u\\|^2_{H^q_p [0, 2\\pi]} = 2\\pi \\displaystyle \\sum^{q}_{m=0} \\sum_{|n| \\leq \\infty} |n|^{2m} |\\hat{u}_n|^2 = 2\\pi \\sum_{|n| \\leq \\infty} \\left(\\sum^{q}_{m=0} |n|^{2m} \\right) |\\hat{u}_n|^2,\n    \t\\end{align*}\n    where the interchange of the summation is allowed provided $u(x)$ has sufficient smoothness. \\\\\n    \n   Before starting the analysis, without loss of generality, we first consider the continuous Fourier series given by\n        \\begin{align*}\n            \\displaystyle \\mathcal{P}_{2N} u(x) = \\sum_{|n| \\leq N} \\hat{u}_n e^{in x}.\n        \\end{align*}\n    The first important result is the estimate in $L^2$ for the distance between $u$ and its trigonometric approximation $\\mathcal{P}_{2N} u$, which shows everything we've seen previously. \n    \\\\\n    \\begin{teor}\n    \\label{estimating_error_PN_L2}\t\n    For any $u(x) \\in H_p^r [0, 2\\pi]$, there exists a positive constant $C$, independent of $N$, such that\n        \\begin{align*}\n    \t    \\|u - \\mathcal{P}_{2N} u \\|_{L^2 [0, 2\\pi]} \\leq C N^{-q} \\|u^{(q)}\\|_{L^2 [0, 2\\pi]},\n    \t\\end{align*}\n    provided $0 \\leq q \\leq r$.\n    \\end{teor}\n    \\begin{proof}\t\n    By Parseval\u2019s identity given by (\\ref{parseval}) we get\n    \t\\begin{align*}\n    \t    \\|u - \\mathcal{P}_{2N} u \\|^2_{L^2 [0, 2\\pi]} = 2\\pi \\displaystyle \\sum_{|n| > N} |\\hat{u}_n|^2.\n    \t\\end{align*}\n    We rewrite this summation as follows\n    \t\\begin{align*}\n    \t    \\displaystyle \\sum_{|n| > N} |\\hat{u}_n|^2 &= \\sum_{|n| > N} \\frac{n^{2q}}{n^{2q}} |\\hat{u}_n|^2 \\\\\n    \t    &\\leq N^{-2q} \\sum_{|n| > N} n^{2q} |\\hat{u}_n|^2 \\\\\n    \t    &\\leq N^{-2q} \\sum_{|n| \\geq 0} n^{2q} |\\hat{u}_n|^2 \\\\\n    \t    &= \\frac{1}{2\\pi} N^{-2q} \\|u^{(q)}\\|^2_{L^2 [0, 2\\pi]}.\n    \t\\end{align*}\n    Putting all the above together and taking out the square root, we get our result.\n\t\\end{proof}\n    \n    \\noindent Note that the smoother the function, the larger the value of $q$ and therefore, the better the approximation, as seen before. Now let's notice the following. Suppose that $u(x)$ is analytical, so we have to\n    \t\\begin{align*}\n    \t\t u^{(q)} = \\displaystyle \n    \t\t \\sum_{ |n| \\leq \\infty} (in)^q \\hat{u}_{n}e^{inx}.\n    \t\\end{align*}\n    Since $u^{(q)} \\in W^q_p$, and by (\\ref{parseval})\n        \\begin{align*}\n            \\|u^{(q)}\\|_{L^2 [0, 2\\pi]} = \\sum_{ |n| \\leq \\infty} |n|^{2q} |\\hat{u}_{n}|^2 \\leq C q! \\sum_{ |n| \\leq \\infty} |\\hat{u}_{n}|^2 \\leq C q! \\| u \\|_{L^2 [0, 2\\pi]},\n        \\end{align*}\n    and so by the previous theorem\n        \\begin{align*}\n            \\|u - \\mathcal{P}_{2N} u \\|_{L^2 [0, 2\\pi]} \\leq  N^{-q} \\|u^{(q)}\\|_{L^2 [0, 2\\pi]} \\leq C \\frac{q!}{N^{q}} \\| u \\|_{L^2 [0, 2\\pi]}.\n        \\end{align*}\n    Using Stirling\u2019s formula, $q! \\sim q^q e^{-q}$, and assuming that $q \\propto N$, we obtain\n        \\begin{align*}\n            \\|u - \\mathcal{P}_{2N} u \\|_{L^2 [0, 2\\pi]} \\leq \\sim C \\left(\\frac{q}{N}\\right)^q e^{-q} \\| u \\|_{L^2 [0, 2\\pi]} \\sim K e^{-c N} \\| u \\|_{L^2 [0, 2\\pi]}.\n        \\end{align*}\n    Thus, for an analytic function, its spectral convergence is exponential convergence. \\\\\n    \n    We must not forget that the theory we have previously presented is with the assumption that the functions and their derivatives are all periodic. But it is possible to do a similar analysis considering some other class of functions, such as functions that vanish at the borders. However, these kinds of functions belong to spaces very similar to those we have studied, and it is possible to use the same results.", "meta": {"hexsha": "15c7b61ae43fe0e7b5e68455bcad097dad644cf3", "size": 14909, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/preliminaries/Projection_Operator.tex", "max_stars_repo_name": "alanmatzumiya/Maestria", "max_stars_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-12-29T10:44:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T11:18:45.000Z", "max_issues_repo_path": "docs/preliminaries/Projection_Operator.tex", "max_issues_repo_name": "alanmatzumiya/spectral-methods", "max_issues_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/preliminaries/Projection_Operator.tex", "max_forks_repo_name": "alanmatzumiya/spectral-methods", "max_forks_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T13:29:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:29:56.000Z", "avg_line_length": 65.9690265487, "max_line_length": 728, "alphanum_fraction": 0.657522302, "num_tokens": 4987, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.9073122132152183, "lm_q1q2_score": 0.8289898750193747}}
{"text": "% !TEX root = Main.tex\n\\section{K-means Algorithm}\n\\textbf{Target:} $\\min_{\\mathbf{U}, \\mathbf{Z}} J(\\mathbf{U}, \\mathbf{Z}) = \\|\\mathbf{X} - \\mathbf{U} \\mathbf{Z}\\|_F^2$\\\\\n$= \\sum_{n=1}^N \\sum_{k=1}^K \\mathbf{z}_{k,n} \\|\\mathbf{x}_n - \\mathbf{u}_k\\|_2^2$\\\\\n1. \\textbf{Initiate:} choose $K$ centroids $\\mathbf{U} = [\\mathbf{u}_1, \\ldots, \\mathbf{u}_K]$\\\\\n2. \\textbf{Assign:} data points to clusters. $k^\\star(\\mathbf{x}_n) = \\argmin_k \\{ \\|\\mathbf{x}_n - \\mathbf{u}_k\\|_2 \\}$ returns cluster $k^\\star$, whose centroid $\\mathbf{u}_{k^\\star}$ is closest to data point $\\mathbf{x}_n$. Set $\\mathbf{z}_{k^\\star,n} = 1$, and for $ l \\neq k^\\star~ \\mathbf{z}_{l,n}=0$.\\\\\n3. \\textbf{Update} centroids: $\\mathbf{u}_k = \\frac{\\sum_{n=1}^N z_{k,n} \\mathbf{x}_n}{\\sum_{n=1}^N z_{k,n}}$.\\\\\n4. Repeat from step 2, stops if $\\|\\mathbf{Z} - \\mathbf{Z}^\\text{new}\\|_0 = \\|\\mathbf{Z} - \\mathbf{Z}^\\text{new}\\|^2_F = 0$.\\\\\nComputational cost: $O(k\\cdot n \\cdot d)$\n", "meta": {"hexsha": "a042a1f13ac10b5ffd5709026377efdaedc0fefc", "size": 947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "KMeans.tex", "max_stars_repo_name": "phil9987/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "6c4986f399ca40c2270b8fc01150a69f89650db7", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-09-24T20:33:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-21T15:52:46.000Z", "max_issues_repo_path": "KMeans.tex", "max_issues_repo_name": "phil9987/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "6c4986f399ca40c2270b8fc01150a69f89650db7", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "KMeans.tex", "max_forks_repo_name": "phil9987/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "6c4986f399ca40c2270b8fc01150a69f89650db7", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-14T16:21:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-18T17:17:10.000Z", "avg_line_length": 94.7, "max_line_length": 309, "alphanum_fraction": 0.6019007392, "num_tokens": 435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075766298657, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.8288924405599326}}
{"text": "\n\\subsection{The Naive Bayes posterior}\n\n\\subsubsection{Bayes theorem}\n\nConsider Bayes' theorem\n\n\\(P(y|x_1,x_2,...,x_n)=\\dfrac{P(x_1,x_2,...,x_n|y)P(y)}{P(x_1,x_2,...,x_n)}\\)\n\nHere, \\(y\\) is the label, and \\(x_1,x_2,...,x_n\\) is the evidence. We want to know the probability of each label given evidence.\n\nThe denominator, \\(P(x_1,x_2,...,x_n)\\), is the same for all, so we only need to identify:\n\n\\(P(y|x_1,x_2,...,x_n)\\propto P(x_1,x_2,...,x_n|y)P(y)\\)\n\n\\subsubsection{The assumption of Naive Bayes}\n\nWe assume each \\(x\\) is independent. Therefore:\n\n\\(P(x_1,x_2,...,x_n|y)=P(x_1|y)P(x_2|y)...P(x_n|y)\\)\n\n\\(P(y|x_1,x_2,...,x_n)\\propto P(x_1|y)P(x_2|y)...P(x_n|y)P(y)\\)\n\n", "meta": {"hexsha": "2180a35815e5da15bc2265b57ee3e7b59397d221", "size": 671, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/supervisedNaiveBayes/01-01-naiveBayesPosterior.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/supervisedNaiveBayes/01-01-naiveBayesPosterior.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/supervisedNaiveBayes/01-01-naiveBayesPosterior.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.9583333333, "max_line_length": 128, "alphanum_fraction": 0.6408345753, "num_tokens": 276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075744568837, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.8288924369776204}}
{"text": "\\chapter{Linear Discriminant Analysis}\n\\newpage\n\n\\section{Binary LDA}\n    Linear Discriminant Analysis aims at projecting data samples onto a hyperplane, such that samples of the same class get as close to each other as possible, while samples of different classes get as far from each other as possible.\n\n    \\subsection{Within- and Between- class Distances}\n        Let $\\mu_1$ and $\\mu_2$ be the mean value of two classes.\n        \\[ \\mu_1 = \\frac{1}{N_1}\\sum_{i\\in C_1}x^{(i)} \\qquad \\mu_2 = \\frac{1}{N_2}\\sum_{i\\in C_2}x^{(i)} \\]\n\n        \\subsubsection{Between-class Distance}\n        Let $w$ be the linear mapping,\n        \\[ d_{between} = |w^Tu_1 - w^Tu_2| \\]\n        We want to maximize $d_{between}$, which is equivalent to maximizing\n        \\[ \\|d_{between}\\|^2 = w^T(\\mu_1-\\mu_2)(\\mu_1-\\mu_2)^Tw\\]\n\n        \\subsubsection{Within-class Distance}\n        We also want to minimize\n        \\[ d_{within}^{(i)} = \\sum_{j\\in C}|w^Tx^{(j)} -w^T\\mu_i| \\]\n        for all $j$, which is equivalent to minimizing\n        \\[ \\|d_{within}^{(i)}\\|^2 = \\sum_{j\\in C}w^T(x^{(j)}-\\mu_i)(x^{(j)}-\\mu_i)^Tw = w^T\\Sigma_iw \\]\n        where $\\Sigma_i$ is the covariance matrix of the $i$-th class.\n\n        Therefore define\n        \\[ d_{within}^2 = \\sum_i (d_{within}^{(i)})^2 \\]\n\n    \\subsection{Opimization Formulation}\n        Notice that we have two objective functions, the key is to combine the two objective into one single objective funtion.\n\n        This can be done by simply setting the objective function to be\n        \\[ \\max J = \\frac{d_{between}}{d_{within}} = \\frac{w^T(\\mu_1-\\mu_2)(\\mu_1-\\mu_2)^Tw}{w^T(\\Sigma_1 + \\Sigma_2)w} \\]\n\n        We define the \\textbf{within-class scatter matrix} and \\textbf{between-class scatter matrix} by\n        \\[ S_w = \\Sigma_1 + \\Sigma_2 \\]\n        \\[ S_b = (\\mu_1 - \\mu_2)(\\mu_1-\\mu_2)^T \\]\n\n        Therefore\n        \\[ J = \\frac{w^TS_bw}{w^TS_ww} \\]\n        this is also known as the \\textbf{generalized Rayleight quotient}.\n\n    \\subsection{Solution}\n        \\[ J = \\frac{w^TS_bw}{w^TS_ww} \\]\n        Notice that both the numerator and denominator are quadratic, so the norm of $w$ does not matter.\n\n        \\subsubsection{By Lagrangian}\n        Since the norm of $w$ does not matter, the problem is equivalent to\n        \\begin{align*}\n            \\min &\\quad -w^TS_bw\\\\\n            \\text{s.t.} &\\quad w^TS_ww=1\n        \\end{align*}\n        By Lagrangian multipliers\n        \\[ S_bw = \\lambda S_ww \\]\n\n        Notice that $(\\mu_1-\\mu_2)^Tw$ is a scalar, and therefore $S_bw$ is parallel with $\\mu_1-\\mu_2$. WLOG let\n        \\[ S_bw = \\lambda(\\mu_1-\\mu_2) \\]\n\n        And therefore\n        \\[ w = S_w^{-1}(\\mu_0-\\mu_1) \\]\n\n        \\begin{remark}\n            For numerical stability we usually compute the inverse by SVD.\n        \\end{remark}\n\n        \\subsubsection{By Gradient}\n        We can directly take gradient w.r.t. $w$.\n        \\[ \\nabla J = \\frac{2(w^TS_ww)S_bw-2(w^TS_bw)S_ww}{(w^TS_ww)^2} \\]\n        which yields\n        \\[ S_bw=JS_ww \\Longrightarrow S_w^{-1}S_bw = Jw \\]\n        and it becomes a eigenvalue decomposition problem.\n\n        To solve this, we perform eigenvalue decomposition on $S_w^{-1}S_b$, and choose the eigenvector with the largest eigenvalue.\n\n        Or alternatively, we can take more than one eigenvectors.\n\n\n\\section{Multi-class LDA}\n    We introduce the \\textbf{total scatter matrix} $S_T$\n    \\[ S_T = \\sum_{i=1}^N(x^{(i)}-\\mu)(x^{(i)}-\\mu)^T \\]\n    where $\\mu$ is the mean vector of all samples.\n\n    \\begin{align*}\n        S_T &= \\sum_{j=1}^{K}\\sum_{i\\in C_j}(x^{(i)}-\\mu_j+\\mu_j-\\mu)(x^{(i)}-\\mu_j+\\mu_j-\\mu)^T\\\\\n        &= \\sum_j\\sum_{i\\in C_j}(x^{(i)}-\\mu_j)(x^{(i)}-\\mu_j)^T\\\\\n        &\\quad + \\sum_j\\sum_i(\\mu_j-\\mu)(\\mu_j-\\mu)^T + 2 \\sum_j\\sum_i(x^{(i)}-\\mu_j)(x^{(i)}-\\mu_j)^T\\\\\n        &= S_w + S_b\n    \\end{align*}\n    Notice that the last term is zero.\n\n    The solution is the same as the binary case.\n\n    However, notice that\n    \\[ S_b = \\sum_{j=1}^k N_j(\\mu_j-\\mu)(\\mu_j-\\mu)^T \\]\n    has at most $k-1$ positive eigenvalues, and therefore we can at most reduce the dimension to $k-1$, but not $k$.\n", "meta": {"hexsha": "d2d8e1492e9c42261a892a2c26e43ed2a0ab9f3e", "size": 4102, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Machine Learning/LinearDiscriminantAnalysis.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Machine Learning/LinearDiscriminantAnalysis.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Machine Learning/LinearDiscriminantAnalysis.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 43.6382978723, "max_line_length": 234, "alphanum_fraction": 0.5992198927, "num_tokens": 1377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.9059898279984214, "lm_q1q2_score": 0.8288909546452989}}
{"text": "\\section{The Diffie-Hellman key exchange}\nSince public key cryptosystems are relatively slowly compared to private key ones, it is often more realistic to use them in conjunction with classical schemes, giving them the limited role of key exchange and agreement.\n\nA major flaw of symmetric cryptosystems, in fact, is that key establishment must be done through secure means, and \\textbf{information cannot directly be sent over the channel}. The two parts must have prior knowledge and trust of each other, and cannot publicly share information. \n\nThis can be solved encrypting a symmetric key using a public key algorithm, so that after the decryption it can be used by both parts to encrypt and decrypt using the symmetric cipher. \n\nThe first published proposal for a \\textbf{key exchange based on public cryptography} is attributed to W. Diffie and M. E. Hellman, and was based on the discrete logarithm problem.\n\nThe process involves two individuals agreeing on an arbitrary starting number which does not have to be kept secret, while each one secretly chooses another value to keep to himself. Then, the secret is mixed with the public key, and the result is exchanged. \n\nFinally, the received output is once again combined with the other secret, giving the original message. If a third party listened to the exchange, it would only know the common number and the mixed one, with the inability to retrieve the original value in an efficient way.\n\nDiffie-Hellman is not an encryption algorithm, but rather a \\textit{protocol} defining the necessary series of step in order to achieve the exchange of encrypted information between two parties through asymmetrical cryptography. \n\nThe basic idea behind the Diffie-Hellman Key Exchange (DHKE) is that exponentiation in $\\mathbb{Z}^*_p$ with $p$ prime is a one-way function and the exponentiation is commutative, i.e.:\n$$k = (a^x)^y \\equiv (a^y)^x \\mod p$$\n\nThe value $k$ is the joint secret which can be used as session key between the two parties. \n\nThe set-up protocol consists of the following steps:\n\\begin{enumerate}\n\t\\item Choose a large prime $p$;\n\t\\item Choose an integer $\\alpha \\in \\{2, 3, \\dots, p - 2\\}$, which ideally should be a generator;\n\t\\item Publish $p$ and $\\alpha$ (domain parameters).\n\\end{enumerate}\n\nIf Alice and Bob both know the public parameters $p$ and $\\alpha$, they can generate a joint secret key $k$ with the DHKE protocol:\n\n\\begin{figure}[h]\n\t\\includegraphics[scale=0.35]{DiffieHellmanPaar.png}\n\t\\centering\n\\end{figure}\n\nEnciphering and deciphering between Alice and Bob can now be performed by both parts:\n$$k_{AB} = k^{k_{pr, A}}_{k_{pub, B}} \\equiv B^a \\mod p$$\n$$k_{AB} = k^{k_{pr, B}}_{k_{pub, A}} \\equiv A^b \\mod p$$\n\nThe correctness of this protocol is simple to prove: \n\\begin{itemize}\n\t\\item Alice computes $B^a \\equiv (\\alpha^b)^a \\equiv \\alpha^{ab} \\mod p$;\n\t\\item Bob computes $A^b \\equiv (\\alpha^a)^b \\equiv \\alpha^{ab} \\mod p$.\n\\end{itemize}\nNow both of them share the session key $k_{AB} \\equiv \\alpha^{ab} \\mod p$ which can be used to establish a secure connection for a symmetric algorithm. \n\nThis protocol can also be extended with more than two parties: any number of users can take part in the exchange by performing more iterations of the algorithm and exchanging intermediate data.\n\n\\subsection{Security of Diffie-Hellman}\nBasic Diffie-Hellman protocol is not secure against active attacks: messages can be either modified or falsely generated by a malicious third part, harming its security through a so called man-in-the-middle attack. \n\nHowever, if generators and finite groups are chosen carefully and large enough, the protocol is considered secure. \n\nPassive attacks. i.e.\\ ones in which an attacker can only listen but not alter information, take place trying to compute the session key $k_{AB}$ shared between Alice and Bob. \n\nJust by observing the protocol, one could obtain:\n\\begin{itemize}\n\t\\item $\\alpha$ and $p$, since those are public parameters;\n\t\\item Values $A = k_{pub, A}$ and $B = k_{pub, B}$ by eavesdropping on the channel during an execution of a key exchange.\n\\end{itemize}\nThe question is whether $k = \\alpha^{ab}$ can be computed as well, assuming that $\\alpha$, $p$, $A \\equiv \\alpha^a \\mod p$ and $B \\equiv \\alpha^b \\mod p$ are known.\n\nThe previously stated problem is called the Diffie-Hellman problem, and can be generalized to arbitrary finite cyclic groups.\n\nGiven a finite cyclic group $G$ of order $n$, a primitive element $\\alpha \\in G$ and two elements $A = \\alpha^a$ and $B = \\alpha^b$ in $G$, the Diffie-Hellman problem is to find the group element $\\alpha^{ab}$.\n\nOne general approach to solve it consists in considering the DHP in the multiplicative group $\\mathbb{Z}^*_p$, and requires an effective way to compute discrete logarithms within it. Then, the key can be found with those steps:\n\\begin{enumerate}\n\t\\item Computing Alice's private key $a = k_{pr, A}$ by solving $a \\equiv \\log_\\alpha A \\mod p$;\n\t\\item Computing the session key $k_{A, B} \\equiv B^a \\mod p$.\n\\end{enumerate}\n\nIt is unknown whether solving the DLP is the only way to crack the Diffie-Hellman protocol without computing the discrete logarithm, but at the moment this is the only available method. \n\nThe order of the finite group cardinality should have a large prime factor $p$ to prevent usage of attacking algorithms to obtain the exponent. For this reason, so called safe primes $q$ are used to calculate $p = 2q + 1$, such that the order of the group is only divisible by 2 and $q$.\n\nHence, in order to ensure security in practice, there must be the assumption that this problem cannot be solved in an efficient way, choosing $p$ sufficiently large to make the computation infeasible. \n\nFurthermore, private keys should always stem from a true random generator in order to prevent an attacker to guess them.\n\n$p$ is consequently generated using a probabilistic prime-finding algorithm, and should have a length of at least 1024 bits in order to provide strong security.\n\n\\subsubsection{Key generation}\nThe session key $k_{AB}$ is supposedly a large randomly chosen integer (or a collection of such). Since the algorithm has application within large finite fields, random numbers need to be adjusted with a modulo operation, associating an integer in $[0, p - 1]$.\n\nWhen the field corresponds to $\\mathbb{Z}^*_p$, not all elements have an inverse. \n\nNevertheless, it should have the same length as $p$; to improve computational speed, it can also be used as symmetric key taking the first 128 most significant bits or hashed. \n\n$A$, $B$ and the session key can be calculated using the repeated squares algorithm. Public keys are typically precomputed, and the main computation is therefore the exponentiation for the session key.\n\nThe integer $\\alpha$ needs to have a special property: it should be a primitive element.\n\n\\subsubsection{Applications}\nDHKE is implemented in many open and commercial cryptographic protocols such as \\textbf{SSH}, \\textbf{TLS} and \\textbf{IPSec}. \n\nSSH offers Diffie-Hellman as an option, since it implements all of the standard cryptographic algorithms.\n\nTLS, on the other hand, primarily relies on Diffie-Hellman. The \\textit{TLS handshake} between client and server begins with a negotiation to determine the crypto algorithms used for the session. The client sends a list of supported ciphersuites, them being different versions of Diffie-Hellman within a message, specifying a key exchange algorithm and other primitives. \n\nThe server arbitrarily selects an algorithm from the client\u2019s list and signals it, along with selecting the Diffie-Hellman parameters. It chooses a group $(p, g)$, computes $g^b$, and sends a message containing a signature using the long-term signing key from its certificate. \n\nThe client then verifies the signature and responds with a message containing $g^a$.To ensure agreement on the negotiation messages, each party computes the TLS master secret from $g^{ab}$ and calculates a MAC of its view of the handshake transcript. \n\nThese MACs are exchanged and verified by the recipients. Thereafter, client and server start exchanging application data, protected by an authenticated encryption scheme with keys also derived from $g^{ab}$.\n\nHowever, much internet traffic uses one of a handful of commonly-known groups that involves primes having less than 1024 bits. There are good reasons for this: using a standard set of groups reduces implementation complexity, ensures interoperability between different pieces of software, and enables the research community to focus its cryptanalytic effort on a few important groups.\n\nThese facts, however, can be exploited to attack TLS, find the session key and therefore compromising a large amount of servers along with their security. An attacker can perform preprocessing attacks knowing which groups will be used, doing precomputation of possible values to then find discrete logarithm in a much shorter amount of time.\n\nIn fact, in 2015 the \\textbf{Logjam} attack was exploited, taking advantage of the Number Field Sieve algorithm and Diffie-Hellman vulnerabilities to both perform a man-in-the-middle and compute the discrete logarithm of a 512-bit key. 1024-bit keys are still considered secure.\n\n\n", "meta": {"hexsha": "d62d1984c394798d45dd7cc347a0d939ecf85fb7", "size": 9235, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/diffie-hellman.tex", "max_stars_repo_name": "mrahtapot/TUM", "max_stars_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 225, "max_stars_repo_stars_event_min_datetime": "2019-10-02T10:49:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T22:25:38.000Z", "max_issues_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/diffie-hellman.tex", "max_issues_repo_name": "mrahtapot/TUM", "max_issues_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-02-16T12:22:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-31T19:35:57.000Z", "max_forks_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/diffie-hellman.tex", "max_forks_repo_name": "mrahtapot/TUM", "max_forks_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 69, "max_forks_repo_forks_event_min_datetime": "2019-10-02T21:46:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T19:27:50.000Z", "avg_line_length": 81.7256637168, "max_line_length": 384, "alphanum_fraction": 0.7771521386, "num_tokens": 2147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.8918110540642805, "lm_q1q2_score": 0.8288852244711279}}
{"text": "%\n% Chapter 2.9\n%\n\n\\section*{2.9 Linear Approximation and Differentials}\n\n\\textbf{Linear approximation} (tangent line approximation) is a way of finding the slope of a curve using the tangent line at point \\((a, f(a))\\) as an approximation to the curve \\(y=f(x)\\) when \\(x\\) is near \\(a\\).\\\\\\\\\nThe linear function whose graph is the tangent line of \\(f(x)\\) at \\((a, f(a))\\) is called the \\textbf{linearization} of \\(f\\) at \\(a\\).\n\n$$ L(x) = f(a) + f'(a)(x-a) $$\n\n\\subsection*{Differentials}\n\nIf \\(y=f(x)\\) is a differentiable function, then differential \\(dx\\) is an independent variable. The differential \\(dy\\) is defined in terms of \\(dx\\) by the equation\n$$ dy=f'(x)dx $$\n", "meta": {"hexsha": "1874e9d166588cbc67e35c16f57e1497dcb0e6c0", "size": 677, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2-9.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/2-9.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/2-9.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.3125, "max_line_length": 219, "alphanum_fraction": 0.6646971935, "num_tokens": 203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813463747182, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.8288700228642538}}
{"text": "\n\\subsection{Complements and disjoint sets}\n\n\\subsubsection{Disjoint sets}\n\nSets are disjoint is there is no overlap in their elements. Two sets are \\(s_i\\) and \\(s_j\\) are mutually exclusive if:\n\n\\(s_i\\land s_j=\\emptyset\\)\n\nA collection of events \\(s\\) are all mutually exclusive if all pairs are mutually exclusive. That is:\n\n\\(\\forall s_i \\in s\\forall s_j\\in s[s_i\\land s_j\\ne \\emptyset \\rightarrow s_i=s_j]\\)\n\n\\subsubsection{Complement function}\n\n\\(x^C\\) is the completement. It is defined such that:\n\n\\(\\forall x [x\\land x^C=\\varnothing ]\\)\n\nFor a set \\(b\\), the complement with respect to \\(a\\) is all elements in \\(a\\) which are not in \\(b\\).\n\n\\(\\forall x \\in a \\forall y \\in b [x \\in (a \\setminus b) \\land y\\in (a \\setminus b)]\\)\n\n\\(b\\land (a \\setminus b)= \\varnothing \\)\n\nThat is, \\(b\\) and \\(a \\setminus b\\) are disjoint.\n\n\\subsubsection{Existence of the complement}\n\nFor two sets \\(a\\) and \\(b\\) we can write \\((a \\setminus b)\\). This is the set of elements of \\(a\\) which are not in \\(b\\).\n\nConsider the axiom of specification:\n\n\\(\\forall x \\forall a \\exists s[(P(x)\\land x\\in a )\\leftrightarrow (x\\in s)]\\)\n\nWe can also write\n\n\\(\\forall x \\forall a \\forall b\\exists s[(x\\not\\in b\\land x\\in a )\\leftrightarrow (x\\in s)]\\)\n\nWhich provides the complement, \\(s\\).\n\n", "meta": {"hexsha": "22bf82af4fd9a6ebea64d4fd68c94c4597153527", "size": 1274, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/setsBasic/01-02-complement.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/setsBasic/01-02-complement.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/setsBasic/01-02-complement.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3333333333, "max_line_length": 123, "alphanum_fraction": 0.6781789639, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250325, "lm_q2_score": 0.8947894569842487, "lm_q1q2_score": 0.828846808191383}}
{"text": "Consider the differential equation\n\\begin{align*}\ny' = \\sin(t)(y^2 - \\cos^2(t) -1),~~y(0)=1,~~t>0.\n\\end{align*}\nThe exact solution to this nonlinear ODE is $y(t) = \\cos(t)$.\n\n\\begin{questions}\n\n\\question{Use \\texttt{rk4} to solve this equation for $t \\in [0,50]$. Plot the error vs. values of $\\Delta t$ (use \\texttt{loglog}). Does the error decay as $\\mathcal{O}(\\Delta t^4)$? }\n\n\\begin{solution}\n\n\\begin{figure}[H]\n\\center{\\includegraphics[scale=.5]{P1F1.eps}}\n\\caption{Error Vs. $\\Delta t$}\n\\end{figure}\n\nThe figure above shows that the error does indeed seem to decay as $\\mathcal{O}(\\Delta t^4)$.\n\n\\end{solution}\n\n\\question{You will now compare \\texttt{rk4}, forward-Euler, and modified Euler methods. Solve the problem with these three methods for several $\\Delta t$. on a \\texttt{loglog} plot, show the error vs. the number of function evaluations used by eahc method. Using the number of function evaluations as a measure of cost, is it worth using several stages in RK methods? }\n\n\\begin{solution}\n\n\\begin{figure}[H]\n\\center{\\includegraphics[scale=.5]{P1F2.eps}}\n\\caption{Error Vs. cost}\n\\end{figure}\n\nThe figure above indicates that it is indeed worth it to use several stages in RK methods despite their cost. Even evaluated at 4 times the cost, RK4 still performs markedly better than euler and modified euler, equivalent to RK1 and RK2 respectively. \n\n\\end{solution}\n\n\\end{questions}\n\n\\subsection*{MATLAB}\n\n\\subsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item part b\n\\end{itemize}\n\\begin{verbatim}\nclose all; clear variables;\n% Part a\n\nN = 2.^(4:12);\nerr = 0*N;\nf = @(t,y) sin(t)*(y^2 - (cos(t))^2 - 1);\n\nfor k = 1:length(N)\n    [t,w] = rk4(f,[0 50],1,N(k));\n    err(k) = norm(w - cos(t),inf);\nend\ndt = 50./N;\n\nfigure\nloglog(dt,err,'*',dt,1e5*N.^(-4),'--')\ngrid on\n\\end{verbatim}\n\n\n\\subsection*{part b}\n\n\\begin{verbatim}\nfor k = 1:length(N)\n    [t,w] = rk4(f,[0 50],1,N(k));\n    err(k) = norm(w - cos(t),inf);\n    [t,w] = euler(f,[0 50],1,N(k));\n    err1(k) = norm(w - cos(t),inf);\n    [t,w] = modified_euler(f,[0 50],1,N(k));\n    err2(k) = norm(w - cos(t),inf);\nend\n\nfigure\nloglog(N,err1,'b',2*N,err2,'r',4*N,err,'g')\nlegend('euler','modified_euler','rk4')\ngrid on\n\\end{verbatim}\n\n\\subsection*{rk4.m}\n\n    \\begin{verbatim}\nfunction [t,w] = rk4(dydt,tspan,y0,N)\n\nh = diff(tspan)/N;\nt = tspan(1) + h*(0:N)';\nw = zeros(length(y0),N+1);\nw(:,1) = y0(:).';\n\nfor i = 1:N\n    k1 = h*dydt(t(i)    , w(:,i)     );\n    k2 = h*dydt(t(i)+h/2, w(:,i)+k1/2);\n    k3 = h*dydt(t(i)+h/2, w(:,i)+k2/2);\n    k4 = h*dydt(t(i)+h  , w(:,i)+k3  );\n    w(:,i+1) = w(:,i) + (k1 + 2*k2 + 2*k3 + k4)/6;\nend\nw = w.';\nend\n\\end{verbatim}\n\n\\subsection*{euler.m}\n\n    \\begin{verbatim}\nfunction [t,w] = euler(dydt,tspan,y0,N)\n\nh = diff(tspan)/N;\nt = tspan(1) + h*(0:N)';\nw = zeros(length(y0),N+1);\nw(:,1) = y0(:).';\n\nfor i = 1:N\n    k1 = h*dydt(t(i)    , w(:,i)     );\n    w(:,i+1) = w(:,i) + k1;\nend\nw = w.';\nend\n\\end{verbatim}\n\n\\subparagraph*{modified euler.m}\n\n    \\begin{verbatim}\nfunction [t,w] = modified_euler(dydt,tspan,y0,N)\n\nh = diff(tspan)/N;\nt = tspan(1) + h*(0:N)';\nw = zeros(length(y0),N+1);\nw(:,1) = y0(:).';\n\nfor i = 1:N\n    k1 = h*dydt(t(i)    , w(:,i)     );\n    k2 = h*dydt(t(i)+h, w(:,i)+k1);\n    w(:,i+1) = w(:,i) + (k1 + k2)/2;\nend\nw = w.';\nend\n\\end{verbatim}", "meta": {"hexsha": "042fa21ef7a426bb238ac878916acd68e2af0d93", "size": 3284, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/texfiles/problem1.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/texfiles/problem1.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/texfiles/problem1.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.6258992806, "max_line_length": 369, "alphanum_fraction": 0.6035322777, "num_tokens": 1228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.9161096175976053, "lm_q1q2_score": 0.8287590557707459}}
{"text": "\n\\subsection{Momentum gradient descent}\n\n\\subsubsection{Batch gradient descent}\n\n:= used to denote an update of variable. Used in programming, eg x=x+1.\n\n\\(\\theta _j := \\alpha \\dfrac{\\delta }{\\delta \\theta _j}J(\\theta _0,\\theta _1)\\)\n\n\\(\\alpha \\) sets rate of descent.\n\n\\(\\theta 0 := \\theta 0 - \\alpha/m \\sum(h0(x) - y)\\)\n\n\\(\\theta j := \\theta j - \\alpha/m \\sum(h0(x) - y)xj\\)\n\nCan check if j theta increasing, means bad methodology, lower alpha\n\nGet run for x iterations,evaluate j(theta)\n\nCan use matrices to do each step\n\nCan check convergence by checking cost over last 1000 or so, rather than all\n\nSmaller learning rate can get to better solution, as can circle drain for small samples\n\nSlowly decreasing learning rate can get better solutions\n\n\\(\\alpha = const1/(i + cost2)\\)\n\nDo gradient descent on all samples\n\nThe standard gradient descent algorithm above is also known as batch gradient descent. There are other implementations.\n\n\\subsubsection{Mini-batch gradient descent}\n\nUse \\(b\\) samples on each iteration, \\(b\\) is parameter, between stochastic and batch\n\n\\(b=2-100\\) for example\n\n\\subsubsection{Stochastic gradient descent}\n\nDo gradient descent on one (?!) sample only\n\nNot guaranteed for each step to go towards minimum, but each step much faster\n\n\\subsubsection{Stochastic gradient descent with momentum}\n\nThe gradient we use is not just determined by the single sample, it is a moving average of past samples.\n\n\\subsubsection{Epochs}\n\nThis refers to the number of times the whole dataset has been run.\n\n", "meta": {"hexsha": "94b3b056c7b9b5b9b8bf6e889a5c42c0b28256ad", "size": 1523, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/optimisationGradientDescent/01-02-gradientDescentVariants.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/computer/optimisationGradientDescent/01-02-gradientDescentVariants.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/computer/optimisationGradientDescent/01-02-gradientDescentVariants.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2037037037, "max_line_length": 119, "alphanum_fraction": 0.7478660538, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.8887587868629345, "lm_q1q2_score": 0.8287260715890724}}
{"text": "\\subsection{Exponential Rule}\r\nLet's find the derivative of the most natural exponential function: $f(x) = e^x$.\r\nUsing the limit definition of the derivative,\r\n\\begin{align*}\r\n\tf^\\prime(x) &= \\lim_{h \\to 0}{\\frac{e^{x+h}-e^x}{h}} \\\\\r\n\t&= \\lim_{h \\to 0}{\\frac{e^x\\left(e^h - 1\\right)}{h}} \\\\\r\n\t&= e^x \\lim_{h \\to 0}{\\frac{e^h - 1}{h}}\r\n\\end{align*}\r\nRemembering the following definition of $e$,\r\n\\begin{equation*}\r\n\te = \\lim_{n \\to \\infty}{\\left(1+\\frac{1}{n}\\right)^n}.\r\n\\end{equation*}\r\nSubstituting $h = 1/n$,\r\n\\begin{equation*}\r\n\te = \\lim_{h \\to 0}{\\left(1+h\\right)^{1/h}}.\r\n\\end{equation*}\r\nPutting substituting this definition for $e$ into our work,\r\n\\begin{align*}\r\n\tf^\\prime(x) &= e^x \\lim_{h \\to 0}{\\frac{\\left(\\left(1+h\\right)^{1/h}\\right)^h-1}{h}} \\\\\r\n\t&= e^x \\lim_{h \\to 0}{\\frac{\\left(1+h\\right)-1}{h}} \\\\\r\n\t&= e^x \\lim_{h \\to 0}{\\frac{h}{h}} \\\\\r\n\t&= e^x.\r\n\\end{align*}\r\nAmazingly, this function is equal to it's own derivative. In fact, aside from the trivial example of $0$, $e^x$ is the only function with this property. \\\\\r\n\r\n\r\nWe can apply the chain rule to find the derivative of $b^x$ for real, positive values of $b$.\r\n\\begin{equation*}\r\n\tf(x) = b^x\t= e^{x\\ln{b}}.\r\n\\end{equation*}\r\nLet $u(x) = x\\ln{b}$.\r\n\\begin{equation*}\r\n\tf(x) = b^x = e^{u(x)}.\r\n\\end{equation*}\r\nApplying the chain rule,\r\n\\begin{align*}\r\n\tf^\\prime(x) &= \\dd{}{u}e^u \\hspace{3pt} \\dd{}{x}x\\ln{b}. \\\\\r\n\t&= e^u \\ln{b} \\\\\r\n\t&= e^{x\\ln{b}} \\ln{b} \\\\\r\n\t&= b^x \\ln{b}.\r\n\\end{align*}\r\n\r\n\\begin{example}\r\n\tFind the derivative of $f(x) = 2^{x^2}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tLet $u(x) = x^2$.\r\n\t\\begin{equation*}\r\n\t\tf(x) = e^u(x).\r\n\t\\end{equation*}\r\n\tUsing the exponential and chain rules,\r\n\t\\begin{align*}\r\n\t\tf^\\prime(x) &= \\dd{f}{u} \\hspace{3pt} \\dd{u}{x} \\\\\r\n\t\t&= \\dd{}{u}e^u \\hspace{3pt} \\dd{}{x}x^2 \\\\\r\n\t\t&= 2^u \\ln{(2)} 2x \\\\\r\n\t\t&= 2^{x^2} \\ln{(2)} 2x \\\\\r\n\t\t&=  2x\\ln{(2)}2^{x^2}.\r\n\t\\end{align*}\r\n\\end{answer}", "meta": {"hexsha": "6ad3615bf473da79978db0624fbe2b17db935c01", "size": 1903, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/derivative_rules/exponential_rule.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/derivatives/derivative_rules/exponential_rule.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/derivatives/derivative_rules/exponential_rule.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2542372881, "max_line_length": 156, "alphanum_fraction": 0.5669994745, "num_tokens": 828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897459384731, "lm_q2_score": 0.880797085800514, "lm_q1q2_score": 0.828644866573613}}
{"text": "\\chapter{Transformation of variables}\nFor this chapter we will show tranformation of variables from a distribution to another distribution. From \\cite{casella2002statistical} we have a theorem for tranformation of variables The theorem in one dimension is given as follows.\n\\begin{theorem}\nLet $X$ have pdf $f_X (x)$, let $Y=g(X)$, where $g$ is a monotone function. Let $\\mathcal{X} = \\{x: f_X (x) > 0\\}$ and $\\mathcal{Y} = \\{ y: y = g(x)$ for some $x \\in \\mathcal{X} \\}$. Suppose that $f_x(x)$ is continuous on $\\mathcal{X}$ and that $g^{-1}(y)$ has a continuous derivative on $\\mathcal{y}$. Then the pdf of $Y$ is given by\n\\begin{equation}\nf_Y (y) = \n\\begin{cases}\nf_X(g^{-1}(y)) \\left| \\frac{d}{dy} g^{-1}(y) \\right| & y \\in \\mathcal{Y} \\\\\n0 & \\text{otherwise.}\n\\end{cases}\n\\end{equation}\n\\end{theorem}\nFor multivariate the pdf of $Y$ is given by\n\\begin{equation}\nf_Y (y) = \n\\begin{cases}\nf_X(g^{-1}(y)) \\left| J(g^{-1}(y)) \\right| & y \\in \\mathcal{Y} \\\\\n0 & \\text{otherwise,}\n\\end{cases}\n\\end{equation}\nwhere $J$ is the Jacobian matrix. The determinant of Jacobian matrix can be rewritten to $\\left| J(g^{-1}(y)) \\right| = \\left| J(g(y)) \\right|^{-1}$\n\n", "meta": {"hexsha": "1b11dcc9e8343ab6aa88cd93b6a80eb546bc86fb", "size": 1157, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapters/changevariables.tex", "max_stars_repo_name": "mariufa/ProsjektOppgave", "max_stars_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Thesis/chapters/changevariables.tex", "max_issues_repo_name": "mariufa/ProsjektOppgave", "max_issues_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Thesis/chapters/changevariables.tex", "max_forks_repo_name": "mariufa/ProsjektOppgave", "max_forks_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.3043478261, "max_line_length": 334, "alphanum_fraction": 0.6620570441, "num_tokens": 401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.8807970779778824, "lm_q1q2_score": 0.8286448650630783}}
{"text": "\\section{Mathematical Symbols and Sets}\n\\subsection{Logical Statements and their Truth Value}\nWe start our discussion with the simplest mathematical concept: a \\emph{proposition}. A proposition is simply a statement that might be either \\true\\ or \\false.\n\\begin{example}{Truth of propositions}{}\n\t\\begin{itemize}\n\t\t\\item $3>1$ (\\true)\n\t\t\\item $-2=5-7$ (\\true)\n\t\t\\item $7<5$ (\\false)\n\t\t\\item The radius of the earth is bigger than that of the moon. (\\true)\n\t\t\\item The word `House' starts with the letter `G'. (\\false)\n\t\\end{itemize}\n\\end{example}\n\nWe can group together propositions using \\emph{logical operators}. Two of the most common logical operators are \\emph{AND} and \\emph{OR}.\n\nThe \\AND{} operator returns a \\true\\ statement only if \\textbf{both} the statements it groups are themselves \\true, otherwise it returns \\false.\n\n\\begin{example}{The AND operator}{}\n\t\\begin{itemize}\n\t\t\\item $2+4=6$ is \\true, $4-2=2$ is \\true. $\\left(2+4=6\\ \\text{\\AND{}}\\ 4-2=2\\right)$ is therefore \\true.\n\t\t\\item $2+4=6$ is \\true, $2>6$ is \\false. $\\left(2+4=6\\ \\text{\\AND{}}\\ 2>6\\right)$ is therefore \\false.\n\t\t\\item $\\frac{10}{2}=1$ is \\false, $2^{4}=16$ is \\true. $\\left( \\frac{10}{2}=1\\ \\text{\\AND{}}\\ 2^{4}=16 \\right)$ is therefore \\false.\n\t\t\\item $7<5$ is \\false, $10+2=13$ is \\false. $\\left( 7<5\\ \\text{\\AND{}}\\ 10+2=13 \\right)$ is therefore \\false.\n\t\\end{itemize}\n\\end{example}\n\nThe \\OR{} operator returns \\true\\ if \\textbf{at least} one of the statements it groups is true.\n\\begin{example}{The OR operator}{}\n\t\\begin{itemize}\n\t\t\\item $2+4=6$ is \\true, $4-2=2$ is \\true. $\\left(2+4=6\\ \\text{\\OR{}}\\ 4-2=2\\right)$ is therefore \\true.\n\t\t\\item $2+4=6$ is \\true, $2>6$ is \\false. $\\left(2+4=6\\ \\text{\\OR{}}\\ 2>6\\right)$ is therefore \\true.\n\t\t\\item $\\frac{10}{2}=1$ is \\false, $2^{4}=16$ is \\true. $\\left( \\frac{10}{2}=1\\ \\text{\\OR{}}\\ 2^{4}=16 \\right)$ is therefore \\true.\n\t\t\\item $7<5$ is \\false, $10+2=13$ is \\false. $\\left( 7<5\\ \\text{\\OR{}}\\ 10+2=13 \\right)$ is therefore \\false.\n\t\\end{itemize}\n\\end{example}\n\nThe behaviour of both operators can be summarized using a \\emph{truth table} (see \\autoref{tab:AND_OR_truth_table} below).\n\\begin{table}\n\t\\centering\n\t\\caption{The truth table for the operators \\AND{} and \\OR{}.}\n\t\\label{tab:AND_OR_truth_table}\n\t\\begin{tabular}{llll}\n\t\t\\toprule\n\t\t$A$ & $B$ & $A$ AND $B$ & $A$ OR $B$\\\\\n\t\t\\midrule\n\t\t\\true & \\true & \\true & \\true \\\\\n\t\t\\true & \\false & \\false & \\true \\\\\n\t\t\\false & \\true & \\false & \\true \\\\\n\t\t\\false & \\false & \\false & \\false \\\\\n\t\t\\midrule\n\t\\end{tabular}\n\\end{table}\n\nWhen writing, it is convenient to use \\emph{notations} to represent operators: the \\AND{} operator is denoted by $\\opand$, while the \\OR{} operator is denoted by $\\opor$.\n\n\\begin{example}{Using the notations for \\AND{} and \\OR{}}{}\n\t\\begin{align*}\n\t\t(\\falseprop{2+2=5}) &\\opand (\\trueprop{1-1=0}) \\Rightarrow \\false\\\\\n\t\t(\\falseprop{2+2=5}) &\\opor  (\\trueprop{1-1=0}) \\Rightarrow \\true\n\t\\end{align*}\n\\end{example}\n\n\\subsection{Common mathematical notations}\n\nSeveral more common mathematical notations are given in \\autoref{tab:common_math_notations}.\n  \n\\begin{table}\n\t\\centering\n\t\\caption{Common mathematical notations used in this Book.}\n\t\\label{tab:common_math_notations}\n\t\\begin{tabular}{ll}\n\t\t\\toprule\n\t\tSymbol & In words\\\\\n\t\t\\midrule\n\t\t$\\neg a$ & \\textbf{not} $a$\\\\\n\t\t$a \\opand b$ & $a$ \\textbf{and} $b$\\\\\n\t\t$a \\opor b$ & $a$ \\textbf{or} $b$\\\\\n\t\t$a \\Rightarrow b$ & $a$ \\textbf{implies} $b$\\\\\n\t\t$a \\Leftrightarrow b$ & $a$ \\textbf{is equivalent to} $b$\\\\\n\t\t$\\forall x$ & \\textbf{For all} $x$ (...)\\\\\n\t\t$\\exists x$ & \\textbf{There exists} $x$ \\textbf{such that} (...)\\\\\n\t\t$a\\defeq b$ & $a$ \\textbf{is defined to be} $b$\\\\\n\t\t$a\\equiv b$ & $a$ \\textbf{is equivalent to} $b$\\\\\n\t\t\\midrule\n\t\\end{tabular}\n\\end{table}\n\nThe notation $\\Rightarrow$ need a bit of clarification: implication means that we can directly derive a proposition from another proposition. For example, if $x=3$ then $x>2$. The opposite implication can be a \\false{} statement, i.e. for the example above $x>2$ does not imply $x=3$ (denoted as $x>2 \\nRightarrow x=3$). Sometimes implication is expressed by using the word \\textit{if}: in the above example $x>2$ if $x=3$, but the other way around is not \\true{}.\n\nWe say that two propositions are \\emph{equivalent} when they imply each other. For example: $x=2$ implies that $\\frac{x}{2}=1$, while $\\frac{x}{2}=1$ implies that $x=2$. We can write this as\n\\[\n\t\\frac{x}{2}=1 \\Leftrightarrow x=2.\n\\]\nInstead of the word \\textit{equivalent}, the phrase \\textit{if and only if} (sometimes shortened to \\emph{iff}) is commonly used, e.g.\n\\[\n\tx=2\\ \\text{iff}\\ \\frac{x}{2}=1.\n\\]\n\n\\subsection{Sets and subsets}\nThe concept of \\emph{sets} is perhaps one of the most basic ideas in modern mathematics. Much of the material covered in this book will be built upon sets and their properties. However, as with the rest of the material presented here - our description of sets will not be thorough nor precise.\n\nFor our purposes, a set is a collection of \\emph{elements}. These elements can be any concept - be it physical (a chair, a bicycle, a tapir) or abstract (a number, an idea). However, we will consider only sets comprised of numbers. Sets can have finite of infinite number of elements in them.\n\nWe denote sets by using curly brackets, and if the number of elements in them is not too big - we display the elements, separated by commas, inside the brackets. In other cases we can express the sets as a sentence or a mathematical proposition.\n\n\\begin{example}{Simple sets}{}\n\t\\[\n\t\t\\left\\{ 1,2,3,4 \\right\\}\\qquad\\left\\{ -4,\\frac{3}{7},0,\\pi,0.13,-2.5,\\frac{e}{3},2^{-\\pi} \\right\\}\\qquad\\left\\{ \\text{all even numbers} \\right\\}\n\t\\]\n\\end{example}\n\nSets have two important properties:\n\\begin{enumerate}\n\t\\item Elements in a set do not repeat. i.e each element is unique. \n\t\\item The order of elements in a set does not matter.\n\\end{enumerate}\n\n\\begin{example}{Important set properties}{}\n\tExamples demonstrating the two aforementioned important properties of sets:\n\t\\begin{enumerate}\n\t\t\\item The following is not a set:\n\t\t\\[\n\t\t\t\\left\\{ 1,1,0,1,0,0,-1,0,0,-1,-1,1 \\right\\}\n\t\\]\n\n\t\t\\item The following sets are all identical:\n\t\t\\[\n\t\t\t\\left\\{ 1,2,3,4 \\right\\}\\qquad\\left\\{ 1,3,2,4  \\right\\}\\qquad\\left\\{ 3,4,1,2 \\right\\}\\qquad\\left\\{ 1,3,2,4 \\right\\}\\qquad\\left\\{ 4,3,2,1 \\right\\}\n\t\t\\]\n\t\\end{enumerate}\n\t\n\\end{example}\n\nSets can be denoted using \\emph{conditions}, with the symbol $|$ representing the phrase \"such that\".\n\n\\begin{example}{Defining a set using a condition}\n\tThe following set contains all the odd whole numbers between $0$ and $10$, including both:\n\t\\[\n\t\t\\left\\{ 0 < x < 10 \\mid x\\ \\text{is an odd number}\\right\\}.\n\t\\]\n\tThe definition of this set can be read as\n\n\t\\vspace{3mm}\n\t\\centering\n\t\\textit{all numbers $x$ that are bigger than $0$ and are smaller than $10$, such that $x$ is odd.}\n\n\t\\flushleft{}\n\t(note that the requirement of $x$ to be an odd number means that it is necessarily a whole number as well)\n\n\t\\vspace{1em}\n\tThis set can be written explicitly as\n\t\\[\n\t\t\\left\\{ 1,3,5,7,9 \\right\\}.\n\t\\]\n\\end{example}\n\nSets are usually denoted with an uppercase Latin letter ($A,B,C,\\dots$), while their elements are denoted as lowercase letters ($a,b,\\alpha,\\phi,\\dots$). When we want to denote that an element belongs to a set we use the following symbol: $\\in$. Conversely, $\\notin$ is used to denote that an element \\textit{does not} belong to a set.\n\t\n\\begin{example}{Elements in sets}{}\n\tFor the two sets\n\t\\[\n\t\tA = \\left\\{ 1,2,5,7 \\right\\},\\quad B=\\left\\{ \\text{even numbers} \\right\\},\n\t\\]\n\tall the following propositions are \\true{}:\n\t\\begin{align*}\n\t\t&1\\in A,\\quad 2\\in A,\\quad 5\\in A,\\quad 7\\in A,\\\\\n\t\t&2\\in B,\\quad 1\\notin B,\\quad 5\\notin B,\\quad 7\\notin B.\n\t\\end{align*}\n\\end{example}\n\nThe number of elements in a set, also called its \\emph{cardinality} is denoted using two vertical bars (similar to the way absolute values are denoted).\n\n\\begin{example}{Cardinality}{}\n\tFor $S=\\left\\{ -3,0,-2,7,1,\\frac{1}{2},5 \\right\\},\\ |S|=7$.\n\\end{example}\n\nAn important special set is the \\emph{empty set}, which is the set containing no elements. It is denoted by $\\emptyset$, and has the unique property that $|\\emptyset|=0$.\n\n\\subsection{Intersection, union, difference and complement sets}\n\nTwo sets are equal if they both contain the exact same elements and only these elements, i.e.\n\\begin{equation}\n\tA = B \\Longleftrightarrow x\\in A \\Leftrightarrow x\\in B.\n\t\\label{eq:set_equality}\n\\end{equation}\nThis proposition reads `The sets $A$ and $B$ are equal \\underline{\\textit{if and only if}} any element $x$ in $A$ is also in $B$, and any element $x$ in $B$ is also in $A$'. When all the elements of a set $B$ are also elements of another set $A$, we say that $B$ is a \\emph{subset} of $A$, and we denote that as $B\\subset A$. In mathematical notation, we write\n\n\\begin{equation}\n\tB\\subset A \\Leftrightarrow \\forall x\\in B, x\\in A.\n\t\\label{eq:subset_def}\n\\end{equation}\ni.e. $B$ is a subset of $A$ \\textbf{iff} the following is true: any element in $B$ is also an element in $A$.\n\n\\begin{note}{(not so) Surprising properties of subsets}{subset_properties}\n\tThe definition of a subset (\\autoref{eq:subset_def}) gives rise to two interesting properties:\n\t\\begin{itemize}\n\t\t\\item The empty set $\\emptyset$ is a subset of any set.\n\t\t\\item Any set is a  subset of itself.  %perhaps clarification of a proper vs improper subset? Unless that is outside the scope of the work. \n\t\\end{itemize}\n\\end{note}\n\n\\begin{note}{The uniqueness of $\\emptyset$}{}\n\tThere is only a single empty set, as any set that has no elements is equivalent to any other set with no elements (i.e. they have the same elements). Due to the way subsets are defined, the empty set is a subset of any set (including itself!).\n\\end{note}\n\nOf course, since we have a definition for a subset, the opposite concept also exists: if $B$ is a subset of $A$, then we say that $A$ is a \\emph{superset} of $B$.\n\nA very useful way of illustrating the relationship between two or more sets is by using \\emph{Venn diagrams}, where sets are represented by circles (or other 2D shapes).\n\n\\begin{example}{Subsets and Venn diagrams}{}\n\tA Venn diagram depicting the set $\\textcolor{xblue}{B=\\left\\{ 0,2 \\right\\}}$ as a subset of $\\textcolor{xred}{A=\\left\\{ 0,1,2,3,4,\\dots,9 \\right\\}}$:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\def\\firstcircle{(0,0) circle (2)}\n\t\t\t\\def\\secondcircle{(0.3,0.8) circle (1)}\n\t\t\t\\fill[xred!50]\\firstcircle;\n\t\t\t\\fill[xblue!50]\\secondcircle;\n\t\t\t\\Large\n\t\t\t\\draw \\firstcircle node[below left, xshift=-18mm, yshift=11mm] (A) {};\n\t\t\t\\draw \\secondcircle node[right of=A, xshift=7mm] (B) {};\n\n\t\t\t% Elements\n\t\t\t\\small\n\t\t\t\\tikzset{node distance={5mm}}\n\t\t\t\\node at (0.57,1.02) {0};\n\t\t\t\\node at (-1.04,-1.25) {1};\n\t\t\t\\node at (0.16,0.4) {2};\n\t\t\t\\node at (-0.1,-0.82) {3};\n\t\t\t\\node at (-0.92,-0.49) {4};\n\t\t\t\\node at (-1.36,0.06) {5};\n\t\t\t\\node at (1.13,-1.16) {6};\n\t\t\t\\node at (1.50,0.62) {7};\n\t\t\t\\node at (-1.08,1.3) {8};\n\t\t\t\\node at (1.32,-0.79) {9};\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{example}\n\nIf for two sets $A,B$ both $A\\subset B$ and $B\\subset A$, then $A=B$. We can write this fact as a mathematical proposition:\n\\begin{equation}\n\t(A\\subset B) \\opand (B\\subset A) \\Leftrightarrow A=B.\n\t\\label{eq:subset_equal}\n\\end{equation}\n\nThe \\emph{intersection} of two sets $A$ and $B$, denoted $A\\cup B$, is the set of all elements $x$ such that $x\\in A$ \\AND{} $x\\in B$:\n\\begin{equation}\n\tA\\cup B = \\left\\{ x \\mid x\\in A \\opand x\\in B \\right\\}.\n\t\\label{eq:intersection}\n\\end{equation}\n\n\\begin{example}{Intersection of sets}{}\n\tThe intersection of the sets $A=\\left\\{ 1,2,3,4 \\right\\}$ and $B=\\left\\{ 3,4,5,6 \\right\\}$ is the set $A\\cup B=\\left\\{ 3,4 \\right\\}$.\n\n\tThe intersection of the sets $C=\\left\\{ 0,1,2,6,7 \\right\\}$ and $D=\\left\\{ 3,9,-4,5 \\right\\}$ is the empty set $\\emptyset$, since no element is in both sets.\n\\end{example}\n  \nThe following Venn diagram depicts the intersection of two sets (the green area):\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\def\\firstcircle{(0,0) circle (2)}\n\t\t\\def\\secondcircle{(2.3,0) circle (1.5)}\n\t\t\\fill[xred!50]\\firstcircle;\n\t\t\\fill[xblue!50]\\secondcircle;\n\t\t\\begin{scope}\n\t\t\t\\clip \\firstcircle;\n\t\t\t\\fill[xgreen!50]\\secondcircle;\n\t\t\\end{scope}\n\t\t\\draw\\firstcircle node[left] {$A$};\n\t\t\\draw\\secondcircle node[right] {$B$};\n\t\t\\draw (1.4,-0.2) node[above] {$A\\cap B$};\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\begin{note}{Disjoint sets}{}\n\tWhen the intersection of two sets is the empty set, we say that the set is \\emph{disjoint}.\n\\end{note}\n\nThe \\emph{union} of two sets (denoted using the symbol $\\cup$) is the set composed of all the elements that belong to any of the sets, including elements that are in both sets:\n\\begin{equation}\n\tA\\cup B = \\left\\{ x \\mid x\\in A \\opor x\\in B \\right\\}.\n\t\\label{eq:union}\n\\end{equation}\n\n\\begin{example}{Union of sets}{}\n\tThe union of the sets $A=\\left\\{ 1,2,3,4 \\right\\}$ and $B=\\left\\{ 3,4,5,6 \\right\\}$ is the set $A\\cup B=\\left\\{ 1,2,3,4,5,6 \\right\\}$.\n\n\tThe union of the sets $C=\\left\\{ 0,1,2,6,7 \\right\\}$ and $D=\\left\\{ 3,9,-4,5 \\right\\}$ is the set $C\\cup D=\\left\\{ 0,1,2,3,-4,5,6,7,9 \\right\\}$.\n\\end{example}\n\nThe following Venn diagram depicts the union of two sets (the purple area):\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\def\\firstcircle{(0,0) circle (2)}\n\t\t\\def\\secondcircle{(2.3,0) circle (1.5)}\n\t\t\\fill[xpurple!50, draw=black]\\firstcircle;\n\t\t\\fill[xpurple!50, draw=black]\\secondcircle;\n\t\t\\draw\\firstcircle node {$A$};\n\t\t\\draw\\secondcircle node {$B$};\n\t\t\\node[text=xpurple,font=\\Large] at (1.5cm,2.5cm) {$A\\cup B$};\n\t\\end{tikzpicture}\n\\end{figure}\n\nNaively, the number of elements of a union $A\\cup B$ is simply the sum of the number of elements in $A$ and the number of elements in $B$. However, this naive approach might count the elements in both sets twice: once for $A$ and once for $B$ (see \\autoref{fig:union_counting}) - this is exactly the set $A\\cap B$. We therefore subtract the number of elements in $A\\cap B$ and get\n\\begin{equation}\n\t|A\\cup B| = |A|+|B|-|A\\cap B|.\n\t\\label{eq:number_of_elements_in_union}\n\\end{equation}\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\Large\n\t\t\\tikzset{node distance=18mm}\n\t\t\\draw[xred] (-1cm,0) circle (2) node (A) {};\n\t\t\\draw[xblue] (1cm,0) circle (1.5) node (B) {};\n\t\t\\node[xred, above of=A, yshift=5mm] {$A$};\n\t\t\\node[xblue, above of=B]{$B$};\n\n\t\t\\def\\rdot{0.1}\n\t\t% A\n\t\t\\fill[xred] (-1.15,-0.12) circle (\\rdot);\n\t\t\\fill[xred] (-1.82,-1.01) circle (\\rdot);\n\t\t\\fill[xred] (-1.28,-1.03) circle (\\rdot);\n\t\t\\fill[xred] (-1.68,+\\rdot) circle (\\rdot);\n\t\t\\fill[xred] (-0.51,-1.25) circle (\\rdot);\n\t\t\\fill[xred] (-1.41,+0.25) circle (\\rdot);\n\t\t\\fill[xred] (-1.60,+1.25) circle (\\rdot);\n\t\t%\tB\n\t\t\\fill[xblue] (1.70,0.54) circle (\\rdot);\n\t\t\\fill[xblue] (1.48,0.06) circle (\\rdot);\n\t\t\\fill[xblue] (1.51,-0.94) circle (\\rdot);\n\t\t%fill[\n\t\t\\fill[xgreen!75] (-0.16,0.24) circle (\\rdot);\n\t\t\\fill[xgreen!75] (0.13,0.53) circle (\\rdot);\n\t\t\\fill[xgreen!75] (0.06,-0.78) circle (\\rdot);\n\t\\end{tikzpicture}\n\t\\caption{Counting the number of elements in the union of two sets: \\textcolor{xred}{$A$} has 10 elements (\\textcolor{xred}{red} + \\textcolor{xgreen}{green} dots), while \\textcolor{xblue}{$B$} has 6 elements (\\textcolor{xblue}{blue} + \\textcolor{xgreen}{green} dots). If we count both we get 16 elements, but this counts the joint elements (\\textcolor{xgreen}{green dots}) twice. Therefore we should subtract the number of joint points, and get that there are only 13 elements in the union.}\n\t\\label{fig:union_counting}\n\\end{figure}\n\nWhen two sets $A,B$ are disjoint, then $|A\\cap B|=0$, and so $|A\\cup B| = |A|+|B|$.\n\nThe definitions of intersections and unions can be easily extended to any whole number of sets.\n\n\\begin{example}{Intersection and union of 3 sets}{}\n\tThe intersection of 3 sets $A=\\left\\{ 1,2,3,4,5 \\right\\},\\ B=\\left\\{ -2,-1,0,1,2 \\right\\}$ and $C=\\left\\{ 2,3,4,5,6 \\right\\}$ is the set of all elements that are in $A$ and in $B$ and in $C$, i.e.\\ the set $A\\cap B\\cap C = \\left\\{2\\right\\}$.\n\n\tThe union of these sets is the set of all elements that are in either of the sets, i.e. $A\\cup B\\cup C = \\left\\{ -2,-1,0,1,2,3,4,5,6 \\right\\}$.\n\\end{example}\n\nThe most general definition of an intersection of $n$ sets (where $n$ is a whole number), which we will call $A_{1},A_{2},A_{3},\\cdots,A_{n}$ is\n\\begin{equation}\n\tA_{1}\\cap A_{2}\\cap A_{3}\\cap \\cdots \\cap A_{n} = \\left\\{ x \\mid (x\\in A_{1}) \\opand (x\\in A_{2}) \\opand (x\\in A_{3}) \\opand \\cdots \\opand (x \\in A_{n})\\right\\}.\n\t\\label{eq:intersection_n_sets}\n\\end{equation}\n\nThe left hand side of \\autoref{eq:intersection_n_sets} can be written as\n\\begin{equation}\n\tA_{1}\\cap A_{2}\\cap A_{3}\\cap \\cdots \\cap A_{n} = \\bigcap\\limits_{i=1}^{n}A_{i}.\n\t\\label{eq:intersection_n_sets_big_notation}\n\\end{equation}\n(clarifying the notation? i.e. indexing, etc.)\n\nSimilarly, the union of $n$ different sets is defined as\n\\begin{align}\n\t\\bigcup\\limits_{i=1}^{n}A_{i} &= A_{1}\\cup A_{2}\\cup A_{3}\\cup \\cdots \\cup A_{n}\\nonumber\\\\\n\t&= \\left\\{ x \\mid (x\\in A_{1}) \\opor (x\\in A_{2}) \\opor (x\\in A_{3}) \\opor \\cdots \\opor (x\\in A_{n})\\right\\}.\n\t\\label{eq:union_n_sets}\n\\end{align}\n\n\\begin{example}{Venn diagrams: intersection and union of 3 sets}{}\n\tThe following Venn diagram shows all possible intersections between three sets:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\tikzset{\n\t\t\t\tevery node/.style={text=black, text opacity=1},\n\t\t\t}\n\t\t\t\\def\\sq{1.15}\n\t\t\t\\Large\n\t\t\t\\begin{scope}[blend group=hard light]\n\t\t\t\t\\fill[xred!40!white] (-\\sq,\\sq) circle (2) node (A) {$A$};\n\t\t\t\t\\fill[xblue!40!white] (\\sq,\\sq) circle (2) node (B) {$B$};\n\t\t\t\t\\fill[xgreen!40!white] (0,-\\sq) circle (2) node (C) {$C$};\n\t\t\t\\end{scope}\n\t\t\t\\footnotesize\n\t\t\t\\node[yshift=5mm, rotate=90] at ($(A)!0.5!(B)$) {$A\\cap B$};\n\t\t\t\\node[xshift=-4mm, yshift=-2mm, rotate=+30] at ($(A)!0.5!(C)$) {$A\\cap C$};\n\t\t\t\\node[xshift=+4mm, yshift=-2mm, rotate=-30] at ($(B)!0.5!(C)$) {$B\\cap C$};\n\t\t\t\\node[align=center] at (0,4mm) {$A\\cap B\\cap C$};\n\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\n\t\\vspace{2em}\n\t...and the following Venn diagram depicts the union of the same three sets:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\tikzset{\n\t\t\t\tevery node/.style={text=black, text opacity=1},\n\t\t\t}\n\t\t\t\\def\\sq{1.15}\n\t\t\t\\Large\n\t\t\t\\fill[xpurple!40!white] (-\\sq,+\\sq) circle (2) node (A) {$A$};\n\t\t\t\\fill[xpurple!40!white] (\\sq,+\\sq) circle (2) node (B) {$B$};\n\t\t\t\\fill[xpurple!40!white] (0,-\\sq) circle (2) node (C) {$C$};\n\n\t\t\t\\node at (0,0) {$A\\cup B\\cup C$};\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{example}\n\nThe \\emph{difference} of two sets $A$ and $B$ (written $A-B$ or $A\\setminus B$) is, in a sense, the opposite of their intersection: it is the set of all elements in $A$ that are \\underline{not} in $B$. Note that $A-B$ doesn't necessarily equal $B-A$, i.e. it is not \\emph{commutative}.\n\n\\begin{example}{Difference of two sets}{}\n\tGiven the two sets $A=\\{1,2,3,4,5\\}$ and $B=\\{3,4,5,6,7,8,9\\}$,\n\t\\begin{align*}\n\t\tA-B &= \\{1,2\\},\\\\\n\t\tB-A &= \\{6,7,8,9\\}.\n\t\\end{align*}\n\t(note how in this case $A-B\\neq B-A$)\n\\end{example}\n\nGiven a set $A$ and a subset of $A$, $B\\subset A$, we can define the \\emph{complement} of $B$ in relation to $A$ (notation: $\\stcomp{B}$) as all the elements in $A$ that are \\underline{not} in $B$. As the name suggest, the elements of $\\stcomp{B}$ complete $B$: $B\\cup\\stcomp{B}=A$.\n\n\\begin{example}{Complement of a set}{}\n\tGiven the set $A=\\mathbb{Z}$ and $B=\\{x\\in \\mathbb{Z} \\mid x\\ \\text{is odd}\\}$, the complement $\\stcomp{B}$ in relation to $A$ is the set of all even numbers. The reason is that any integer number can be either odd (in which case it belongs in $B$) or even (in which case it belongs in $\\stcomp{B}$).\n\\end{example}\n\nGiven a set $A$ with $|A|$ elements - how many different subsets does it have? We'll start by looking at a practical example: $A=\\left\\{ 1,2,3 \\right\\}$. We can imminently see that any set which contains just one of the elements of $A$ is a subset of $A$, i.e. $\\{1\\},\\{2\\},\\{3\\}$ are all subsets of $A$. In addition, any set which contains only two elements from $A$ is a subset of $A$, i.e. $\\left\\{ 1,2 \\right\\}, \\left\\{ 1,3 \\right\\}, \\left\\{ 2,3 \\right\\}$. Of course, we must not forget the empty set and $A$ itself - both subsets of $A$ (see \\autoref{note:subset_properties}). Thus altogether $A$ has $8$ subsets:\n\\[\n\t\\emptyset, \\left\\{ 1 \\right\\}, \\left\\{ 2 \\right\\}, \\left\\{ 3 \\right\\}, \\left\\{ 1,2 \\right\\}, \\left\\{ 1,3 \\right\\}, \\left\\{ 2,3 \\right\\}, \\left\\{ 1,2,3 \\right\\}.\n\\]\n\nGenerally, any set $A$ with $|A|$ elements has $2^{|A|}$ different subsets. The set of all these subsets is called the \\emph{power set} of $A$, and is denoted as $P(A)$.\n\n\\begin{example}{Power set}{power_set}\n\tThe power set of $A=\\left\\{ 1,2,3 \\right\\}$ is\n\t\\[\n\t\tP(A) = \\left\\{ \\emptyset, \\left\\{ 1 \\right\\}, \\left\\{ 2 \\right\\}, \\left\\{ 3 \\right\\}, \\left\\{ 1,2 \\right\\}, \\left\\{ 1,3 \\right\\}, \\left\\{ 2,3 \\right\\}, \\left\\{ 1,2,3 \\right\\}\\right\\}.\n\t\\]\n\\end{example}\n\n\\subsection{Important number sets}\nIt is now time to introduce some important number sets. We begin with the simplest of these sets: the \\emph{natural numbers}, denoted by $\\mathbb{N}$. These are the numbers $1,2,3,4,\\dots$. Adding the opposites to the natural numbers and adding $0$ to the set yields the \\emph{integers}, denoted by $\\mathbb{Z}$. Loosely speaking, we can define the integers as\n\\begin{equation}\n\t\\mathbb{Z}=\\left\\{ 0,\\pm1,\\pm2,\\pm3,\\pm4,\\dots \\right\\}.\n\t\\label{eq:integers}\n\\end{equation}\n\nThis makes the integers a superset of the natural numbers, i.e.\n\\begin{equation}\n\t\\mathbb{N} \\subset \\mathbb{Z}.\n\t\\label{eq:naturals_subset_integers}\n\\end{equation}\n\nOne can think of the integers as all the number needed for solving an equation of the form $a+x=b$, where $a$ and $b$ are integers themselves, and $x$ is an unknown. No matter which integer values we put in $a$ and $b$, the unknown $x$ will always be an integer as well (whether it be positive, negative or zero depends on the values of $a$ and $b$). However, when one wishes to solve an equation of the sort $ax=b$, the integers are not longer sufficient: for example, if $a=2$ and $b=1$, then $x$ is not an integer.\n\nTo solve $ax=b$ (where $a,b\\in\\mathbb{Z}$) we must introduce the \\emph{rational numbers}: numbers with values that are ratios of two integers. We denote the set of rational numbers with the symbol $\\mathbb{Q}$, and write\n\\begin{equation}\n\t\\mathbb{Q} = \\left\\{ \\frac{a}{b} \\ \\middle\\vert\\ a,b\\in\\mathbb{Z} \\opand b\\neq0  \\right\\}.\n\t\\label{eq:rationals}\n\\end{equation}\n(TBW: discuss briefly why $b\\neq0$)\n\nFor some combinations of $a$ and $b$ the ratio $\\frac{a}{b}$ is an integer. For example: $\\frac{3}{1},\\ \\frac{8}{4},\\ \\frac{-2}{2}$. This makes the integers a subset of the rational numbers, i.e.\n\\begin{equation}\n\t\\mathbb{Z}\\subset\\mathbb{Q}.\n\t\\label{eq:integers_subset_rationals}\n\\end{equation}\n\nAbout 2500 years ago it was discovered that some numbers are not rational (and thus also not integers). The most famous example is the number $\\sqrt{2}$ - there are not two integers $a,b$ such that $\\frac{a}{b}=\\sqrt{2}$. We call some of these numbers \\emph{algebraic numbers} (denoted by $\\mathbb{A}$), and what makes them special is that they are solutions to \\emph{polynomial equations}, which we will not define yet (see section xxx). Instead, here is an example for a 2nd order polynomial equation (called a \\emph{quadratic equation}):\n\\begin{equation}\n\tx^{2} - 2x - 1 = 0.\n\t\\label{eq:quadratic_equation}\n\\end{equation}\n\nSimilar to what we saw before, the rational numbers are a subset of the algebraic numbers, i.e.\n\\begin{equation}\n\t\\mathbb{Q}\\subset\\mathbb{A}.\n\t\\label{eq:rationals_subset_algebraic}\n\\end{equation}\n\nThe algebraic numbers together with other non-rational numbers, such as $\\pi$ and $e$, form the set of \\emph{real numbers}, denoted as $\\mathbb{R}$. The definition of real numbers is way beyond the scope of this book, but it is important to understand that the progression we used so far still holds, i.e.\n\\begin{equation}\n\t\\mathbb{A}\\subset\\mathbb{R}.\n\t\\label{eq:algebraic_subset_reals}\n\\end{equation}\n\nThe final set of numbers we will touch upon here is the set of \\emph{complex numbers}, denoted $\\mathbb{C}$, which we can define as\n\\begin{equation}\n\t\\mathbb{C} = \\left\\{ a+\\iu b \\mid a,b\\in\\mathbb{R},\\ \\iu=\\sqrt{-1} \\right\\}.\n\t\\label{eq:complex_numbers_def}\n\\end{equation}\n\nWhen $b=0$, \\autoref{eq:complex_numbers_def} becomes just a single real number - and so\n\\begin{equation}\n\t\\mathbb{R}\\subset\\mathbb{C}.\n\t\\label{eq:reals_subset_complex}\n\\end{equation}\n(\\autoref{sec:complex numbers} is dedicated to complex numbers)\n\nEquations \\ref{eq:naturals_subset_integers}-\\ref{eq:reals_subset_complex} can be merged together to the following single equation:\n\\begin{equation}\n\t\\mathbb{N} \\subset \\mathbb{Z} \\subset \\mathbb{Q} \\subset \\mathbb{A} \\subset \\mathbb{R} \\subset \\mathbb{C}.\n\t\\label{eq:numbers_subsets}\n\\end{equation}\n\nThere are more advanced constructions that generalize the complex numbers (i.e. create supersets of the complex number set). These include \\emph{quaternions} and \\emph{Clifford algebras}. However, as stated before, we will not consider them in this book.\n\n\\subsection{Intervals on the real number line}\nAn important concept that is easily defined over the set $\\mathbb{R}$ is an \\emph{interval}. A \\emph{closed interval} $\\left[ a,b \\right]$ is a subset of $\\mathbb{R}$ which is defined as\n\\begin{equation}\n\t\\left[ a,b \\right] = \\left\\{ x\\in\\mathbb{R} \\mid a\\leq x\\leq b \\right\\}.\n\t\\label{eq:closed_interval}\n\\end{equation}\n\nAn \\emph{open interval} $\\left( a,b \\right)$ is a subset of $\\mathbb{R}$ which is defined as\n\\begin{equation}\n\t\\left( a,b \\right) = \\left\\{ x\\in\\mathbb{R} \\mid a<x<b \\right\\}.\n\t\\label{eq:open_interval}\n\\end{equation}\n\nThe difference between closed and open intervals is the inclusion and exclusion, respectively, of the edge point: in a closed interval the points $a,b$ are included, while they are not included in an open interval. Of course, we can also create \\emph{half open intervals}, i.e.\n\\begin{align}\n\t\\left[ a,b \\right) &= \\left\\{ x\\in\\mathbb{R} \\mid a\\leq x < b \\right\\},\\nonumber\\\\\n\t\\left( a,b \\right] &= \\left\\{ x\\in\\mathbb{R} \\mid a < x\\leq b \\right\\},\n\t\\label{eq:half_open_intervals}\n\\end{align}\nwhere the first interval includes $a$ but not $b$, and the second interval includes $b$ but not $a$.\n\n\\vspace{2em}\n\\begin{example}{Intervals}{intervals}\n\tIntervals can be drawn as colored line segments on top of the real number line:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}[node distance=15mm]\n\t\t\t\\begin{axis}[Interval]\n\t\t\t\t% NOTE: there must be a way to set this globally!\n\t\t\t\t\\addplot[xred] table[y expr=4, meta index=1, header=false] {\n\t\t\t\t-2 c\n\t\t\t\t3 c\n\t\t\t\t} node [right] {$\\left[ -2,3 \\right]$};\n\t\t\t\t\\addplot[xblue] table[y expr=3, meta index=1, header=false] {\n\t\t\t\t-4 o\n\t\t\t\t0 o\n\t\t\t\t} node [right] {$\\left( -4,0 \\right)$};\n\t\t\t\t\\addplot[xgreen] table[y expr=2, meta index=1, header=false] {\n\t\t\t\t-1 c\n\t\t\t\t4 o\n\t\t\t\t} node [right] {$\\left[ -1,4 \\right)$};\n\t\t\t\t\\addplot[xpurple] table[y expr=1, meta index=1, header=false] {\n\t\t\t\t1 o\n\t\t\t\t3 c\n\t\t\t\t} node [right] {$\\left( 1,3 \\right]$};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\n\tNote how a full point denotes a closed edge, while an empty point denotes an open edge.\n\\end{example}\n\nIn some cases, it is necessary to use intervals that are infinite in one side, i.e. the left or the right edge are at infinity. In these cases, we use the symbol $\\infty$ to denote infinity, and always keep the interval open at that end:\n\\begin{align}\n\t\\left( -\\infty,b \\right) &= \\left\\{ x \\mid x<b \\right\\},\\nonumber\\\\\n\t\\left( -\\infty,b \\right] &= \\left\\{ x \\mid x\\leq b \\right\\},\\nonumber\\\\\n\t\\left( a,\\infty \\right) &= \\left\\{ x \\mid x>a \\right\\},\\nonumber\\\\\n\t\\left[ a,\\infty \\right) &= \\left\\{ x \\mid x\\geq a \\right\\}.\n\t\\label{eq:infinite_intervals}\n\\end{align}\n\n\\subsection{Cartesian Products}\nThe \\emph{Cartesian product}\\index{Cartesian product} of two sets $A,B$ (denoted $A\\times B$) is the set of all possible \\emph{ordered} pairs, where the first component is an element of $A$ and the second component is an element of $B$:\n\\begin{equation}\n\tA\\times B = \\left\\{ (a,b) \\mid a\\in A,\\ b\\in B \\right\\}.\n\t\\label{eq:Cartesian_product}\n\\end{equation}\n\n\\begin{example}{Cartesian products}{Cartesian_products}\n\tConsider $A=\\left\\{ 1,2,3 \\right\\},\\ B=\\left\\{ x, y \\right\\}$. Then\n\t\\[\n\t\tA\\times B = \\left\\{ \\left( 1,x \\right),\\ \\left( 1,y \\right),\\ \\left( 2,x \\right),\\ \\left( 2,y \\right),\\ \\left( 3,x \\right),\\ \\left( 3,y \\right) \\right\\}\n\t\\]\n\\end{example}\n\nThe concept of `ordered pairs' is paramount: if we reverse the order of the elements in a pair the result might not be in the Cartesian product. We therefore say that the Cartesian product is \\emph{not commutative}.\n\n\\begin{example}{Non-commutativity of the Cartesian product}{}\n\tThe elements $(x,1),\\ (y,1),\\ (x,2)$ and so on \\textbf{are not} in the Cartesian product $A\\times B$ as defined in the previous example, since in each one of the pairs the first element is from $B$ and the second element is from $A$.\n\\end{example}\n\nThe number of elements in a Cartesian product is the product of the number of elements in each of the sets it is composed of, i.e.\n\\begin{equation}\n\t|A\\times B| = |A|\\cdot|B|.\n\t\\label{eq:number_of_elements_Cartesian_product}\n\\end{equation}\n\n\\begin{example}{Number of elements in a Cartesian product}{}\n\tThe Cartesian product described in the previous two examples has in total $3\\cdot2=6$ elements, as seen in \\autoref{:Cartesian_products}.\n\\end{example}\n\nAs with intersections and unions, the definition of a Cartesian product can be expanded into any natural number of sets:\n\\begin{equation}\n\tA_{1}\\times A_{2}\\times \\cdots \\times A_{n} = \\left\\{ \\left( x_{1},x_{2},\\dots,x_{n} \\right) \\mid x_{1}\\in A_{1},\\ x_{2}\\in A_{2},\\ \\dots, x_{n}\\in A_{n} \\right\\}.\n\t\\label{eq:Cartesian_product_multiple_sets}\n\\end{equation}\n\n\\begin{example}{Cartesian product of three sets}{}\n\tThe Cartesian product of the sets $A=\\{1,2,3\\},\\ B=\\{x,y\\},\\ C=\\{\\alpha,\\beta\\}$ is\n\t\\begin{align*}\n\t\tA\\times B\\times C = \\{\n\t\t\t&(1,x,\\alpha),\\ (1,x,\\beta),\\ (1,y,\\alpha),\\ (1,y,\\beta)\\\\\n\t\t\t&(2,x,\\alpha),\\ (2,x,\\beta),\\ (2,y,\\alpha),\\ (2,y,\\beta)\\\\\n\t\t\t&(3,x,\\alpha),\\ (3,x,\\beta),\\ (3,y,\\alpha),\\ (3,y,\\beta)\n\t\t\\}.\n\t\\end{align*}\n\\end{example}\n\nAn element in a cartesian product is sometimes called a \\emph{tuple}. A tuple can be tought of as a set where the order of elements does matter, and thus elements can repeat. A tuple with $n$-elements is called an $n$-tuple.\n\n\\begin{example}{Tuples}{}\n\t\\centering\n\t\\begin{tabular}{lll}\n\t\t\\toprule\n\t\t$n$ & Name & Example\\\\\n\t\t\\midrule\n\t\t$0$  & empty tuple & $()$\\\\\n\t\t$1$  & monpule\t & $(-5)$\\\\\n\t\t$2$  & couple\t & $(-5,-3)$\\\\\n\t\t$3$  & triple\t & $(-7,-2,8)$\\\\\n\t\t$4$  & quadruple & $(1,3,3,7)$\\\\\n\t\t$5$  & quintuple & $(-8,8,-9,-5,8)$\\\\\n\t\t$6$  & sextuple  & $(-7,7,1,1,0,-5)$\\\\\n\t\t$7$  & septuple  & $(5,8,0,-8,-3,7,-7)$\\\\\n\t\t$8$  & octuple\t & $(-9,8,5,-5,2,-5,-1,2)$\\\\\n\t\t$9$  & nonuple\t & $(2,4,-3,-1,5,-1,-5,-4,-7)$\\\\\n\t\t$10$ & decuple\t & $(2,-3,7,2,3,-7,0,-1,-9,8)$\\\\ \n\t\t$\\vdots$ & $\\vdots$ & $\\vdots$\\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{example}\n\nA special case of Cartesian products are those products for which all the sets composing them are the same set. We denote these as the respective integer power, for example the Cartesian product $\\mathbb{R}\\times\\mathbb{R}$ is denoted as $\\Rs{2}$, the Cartesian product $\\mathbb{R}\\times\\mathbb{R}\\times\\mathbb{R}$ is denoted as $\\Rs{3}$, etc.\n\nSpecifically, the Cartesian product $\\Rs{2}$ can be interpreted as the two-dimensional \\emph{Euclidean space}, which is the space used to draw graphs in one-dimensional calculus and shapes in two-dimensional analytical geometry. We will explore this idea (and higher dimensional spaces) in more details in upcoming chapters.\n", "meta": {"hexsha": "01e8ee7d6b76f8c9e41d1df70d8613c68082737e", "size": 31769, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/intro/math_symbols_sets.tex", "max_stars_repo_name": "pelegs/maths_book", "max_stars_repo_head_hexsha": "d1bebf3516a5821772d8807ce3d222a3caff1360", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-25T20:02:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T17:57:59.000Z", "max_issues_repo_path": "chapters/intro/math_symbols_sets.tex", "max_issues_repo_name": "pelegs/maths_book", "max_issues_repo_head_hexsha": "d1bebf3516a5821772d8807ce3d222a3caff1360", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2022-01-17T05:01:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-20T06:18:24.000Z", "max_forks_repo_path": "chapters/intro/math_symbols_sets.tex", "max_forks_repo_name": "pelegs/maths_book", "max_forks_repo_head_hexsha": "d1bebf3516a5821772d8807ce3d222a3caff1360", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2022-01-17T10:15:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-02T10:45:13.000Z", "avg_line_length": 48.8753846154, "max_line_length": 618, "alphanum_fraction": 0.6725109383, "num_tokens": 11232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.8976952873175982, "lm_q1q2_score": 0.8286079135067655}}
{"text": "\\subsection{$u$ Substitution (Reversing the Chain Rule)}\r\nThe chain rule tells us that $\\dd{}{x}f(g(x)) = f^\\prime(g(x))g^\\prime(x)$.\r\nSo, if we see that we are integrating a function that contains within it a function and its derivative, we might want to try running the chain rule in reverse.\r\n\\begin{example}\r\n\tSolve the following indefinite integral:\r\n\t\\begin{equation*}\r\n\t\t\\int{x^2\\cdot 2x\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tSince we know that $\\dd{x^2}{x} = 2x$, or in differential form $\\d{x^2} = 2x\\d{x}$, we can make a substitution.\r\n\tLetting $u = x^2$,\r\n\t\\begin{align*}\r\n\t\t\\int{x^2\\cdot 2x\\d{x}} &= \\int{u\\d{u}} \\\\\r\n\t\t&= \\frac{u^2}{2} + C \\\\\r\n\t\t&= \\frac{x^4}{2} + C.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\r\nSometimes the derivative itself won't be there, but a constant multiple of the derivative.\r\n\\begin{example}\r\n\tSolve the following indefinite integral:\r\n\t\\begin{equation*}\r\n\t\t\\int{\\frac{x^2}{1-x^3}\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tA good way to spot that there might be the possibility of a $u$-substitution here is the fact that the denominator is a polynomial of one higher degree than the numerator.\r\n\tSo, if we took the derivative of the denominator, we'd get a polynomial of the same degree as the numerator.\r\n\tLet $u = 1-x^3$.\r\n\tThen $\\d{u} = -3x^2\\d{x}$; $x^2\\d{x} = -\\d{u}/3$.\r\n\t\\begin{align*}\r\n\t\t\\int{\\frac{x^2}{1-x^3}\\d{x}} &= \\int{\\frac{-\\d{u}}{u}} \\\\\r\n\t\t&= -\\ln{\\abs{u}} + C \\\\\r\n\t\t&= -\\ln{\\abs{1-x^3}} + C.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\r\nWe can also apply $u$-substitutions to definite integrals.\r\nWe'll need to change the bounds of integration to be in terms of $u$ before we evaluate.\r\n\\begin{example}\r\n\tSolve the following definite integral:\r\n\t\\begin{equation*}\r\n\t\t\\int_{0}^{1}{15x^2\\sqrt{5x^3+4}\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tLet $u = 5x^3 + 4$.\r\n\tThen $\\d{u} = 15x^2\\d{x}$.\r\n\tWhen $x=1$, $u=5(0)^3 + 4 = 4$; when $x=1$, $u = 5(1)^3  +4 = 9$.\r\n\t\\begin{align*}\r\n\t\t\\int_{0}^{1}{15x^2\\sqrt{5x^3+4}\\d{x}} &= \\int_{4}^{9}{\\sqrt{u}\\d{u}} \\\\\r\n\t\t&= \\frac{2u\\sqrt{u}}{3} \\biggr\\rvert_{4}^{9} \\\\\r\n\t\t&= \\frac{2(9)\\sqrt{9}}{3} - \\frac{2(4)\\sqrt{4}}{3} \\\\\r\n\t\t&= \\frac{54}{3} - \\frac{16}{3} \\\\\r\n\t\t&= \\frac{38}{3}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Trig Functions}\r\nWe can get the integrals of some of the trig functions by simply applying the derivatives for trig functions in reverse.\r\n\\begin{table}[H]\r\n\t\\begin{center}\r\n\t\t\\begin{tabular}{ l l }\r\n\t\t\t$\\begin{aligned}\\int{\\sin{x}\\d{x}}=-\\cos{x} + C\\end{aligned}$ & $\\begin{aligned}\\int{\\cos{x}\\d{x}}=\\sin{x}+C\\end{aligned}$\r\n\t\t\\end{tabular}\r\n\t\\end{center}\r\n\\end{table}\r\n\r\n\r\nWe can get the integrals of $\\tan{x}$ and $\\cot{x}$ using basic $u$-substitutions.\r\n\\begin{align*}\r\n\t\\int{\\tan{x}\\d{x}} &= \\int{\\frac{\\sin{x}}{\\cos{x}}\\d{x}} \\\\\r\n\tu = \\cos{x} &\\text{ and } \\d{u} = -\\sin{x}\\d{x} \\\\\r\n\t&= \\int{\\frac{-\\d{u}}{u}} \\\\\r\n\t&= -\\ln{\\abs{u}} + C \\\\\r\n\t&= -\\ln{\\abs{\\cos{x}}} + C.\r\n\\end{align*}\r\n\\begin{align*}\r\n\t\\int{\\cot{x}\\d{x}} &= \\int{\\frac{\\cos{x}}{\\sin{x}}\\d{x}} \\\\\r\n\tu = \\sin{x} &\\text{ and } \\d{u} = \\cos{x}\\d{x} \\\\\r\n\t&= \\int{\\frac{\\d{u}}{u}} \\\\\r\n\t&= \\ln{\\abs{u}} + C \\\\\r\n\t&= \\ln{\\abs{\\sin{x}}} + C.\r\n\\end{align*}\r\n\r\n\r\nWe can also get the integrals of $\\sec{x}$ and $\\csc{x}$ using $u$-substitutions, but we have to be a bit more clever and multiply the integrand by a strange-looking fraction that equals 1.\r\n\\begin{align*}\r\n\t\\int{\\sec{x}\\d{x}} &= \\int{\\sec{x}\\frac{\\sec{x} + \\tan{x}}{\\tan{x}+\\sec{x}}\\d{x}} \\\\\r\n\t&= \\int{\\frac{\\sec^2{x}+\\sec{x}\\tan{x}}{\\tan{x}+\\sec{x}}} \\\\\r\n\tu = \\tan{x} + \\sec{x} &\\text{ and } \\d{u} = (\\sec^2{x} + \\sec{x}\\tan{x})\\d{x} \\\\\r\n\t&= \\int{\\frac{\\d{u}}{u}} \\\\\r\n\t&= \\ln{\\abs{u}} + C \\\\\r\n\t&= \\ln{\\abs{\\tan{x} + \\sec{x}}} + C.\r\n\\end{align*}\r\n\\begin{align*}\r\n\t\\int{\\csc{x}\\d{x}} &= \\int{\\csc{x}\\frac{\\csc{x}+\\cot{x}}{\\cot{x}+\\csc{x}}\\d{x}} \\\\\r\n\t&= \\int{\\frac{\\csc^2{x}+\\csc{x}\\cot{x}}{\\cot{x}+\\csc{x}}\\d{x}} \\\\\r\n\tu = \\cot{x} + \\csc{x} &\\text{ and } \\d{u} = -(\\csc^2{x}+\\csc{x}\\cot{x})\\d{x} \\\\\r\n\t&= \\int{\\frac{-\\d{u}}{u}} \\\\\r\n\t&= -\\ln{\\abs{u}} + C \\\\\r\n\t&= -\\ln{\\abs{\\cot{x}+\\csc{x}}} + C.\r\n\\end{align*}", "meta": {"hexsha": "e834f8a7ccaaac51de6d0d91bd8bde87fbea8bc2", "size": 4082, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/integrals/usub.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/integrals/usub.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/integrals/usub.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 38.5094339623, "max_line_length": 190, "alphanum_fraction": 0.5622243998, "num_tokens": 1673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029486, "lm_q2_score": 0.8840392909114835, "lm_q1q2_score": 0.828531163466453}}
{"text": "\\section{Code listing}\nThe below code from my Text Simlarity assignment in the Data Science class \\parencite{dsc-text-similarity}.\\\\\n\n\\begin{lstlisting}[language=Python]\n# # Vectorisation of Text Data\n# The process of converting or transforming a data set into a set of Vectors is called Vectorization.\n\n# import libraries\nimport pandas as pd\nimport sklearn as sk\nimport math \n\n# Calculate dot product of two vectors, divide it by the magnitudes to find the cos(angle between them)\n# Use the result as a correlation coefficient \nfrom collections import Counter\n\ndef cosine(vector1, vector2):\n     # calculate nominator as a dot product\n     intersect = set(vector1.keys()) & set(vector2.keys())\n     numerator = sum([vector1[x] * vector2[x] for x in intersect])\n    \n     # calculate the denominator \n     sum1 = sum([vector1[x] ** 2 for x in list(vector1.keys())])\n     sum2 = sum([vector2[x] ** 2 for x in list(vector2.keys())])\n    \n     denominator = math.sqrt(sum1) * math.sqrt(sum2)\n     if not denominator:\n         return 0.0\n     else:\n         return float(numerator)/denominator\n\n\n# # Assignment\nwith open('textfiles/A.txt', 'r', encoding='utf8', errors='ignore') as a:\n    A = a.read().replace('\\n', '')\nwith open('textfiles/B.txt', 'r', encoding='utf8', errors='ignore') as b:\n    B = b.read().replace('\\n', '')\nwith open('textfiles/C.txt', 'r', encoding='utf8', errors='ignore') as c:\n    C = c.read().replace('\\n', '')\n    \nA1 = A.split(\" \") \nB1 = B.split(\" \") \nC1 = C.split(\" \") \n\n# join the sets of words to remove duplications\nall= set(A1).union(set(B1).union(C1))\n#print(all)\n\ndef convertTextToVector(text):\n    x = dict.fromkeys(all, 0) \n    for word in text:\n        x[word]+=1\n    return x\n\ndef compareVectors():\n    AVector = convertTextToVector(A1)\n    BVector = convertTextToVector(B1)\n    CVector = convertTextToVector(C1)\n    \n    corrAB = cosine(AVector, BVector)\n    print(\"Similarity on A and B: \", corrAB)\n    \n    corrAC = cosine(AVector, CVector)\n    print(\"Similarity on A and C: \", corrAC)\n    \n    corrBC = cosine(BVector, CVector)\n    print(\"Similarity on B and C: \", corrBC)\n    \n    suggestion = \"\"\n    \n    highest = 0\n    corrarray = [corrAB, corrAC, corrBC]\n    for i in corrarray:\n        if highest < i:\n            highest = i\n            \n    if highest == corrAB:\n        suggestion = \"Text A = X, Text B = X, Text C = Y\"\n    elif highest == corrAC:\n        suggestion = \"Text A = X, Text B = Y, Text C = X\"\n    else:\n        suggestion = \"Text A = Y, Text B = X, Text C = X\"\n    return suggestion\n\nsuggestion = compareVectors()\nprint(suggestion)\n\\end{lstlisting}", "meta": {"hexsha": "043375e34c3788d069be3dc37b776606563fc815", "size": 2610, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/chapters/codelisting.tex", "max_stars_repo_name": "SOFT2021-UFO/Assignment-2-Professional-Typesetting-using-LaTeX", "max_stars_repo_head_hexsha": "27b667feebaf777b89f5e18cac7c15d683a68019", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pages/chapters/codelisting.tex", "max_issues_repo_name": "SOFT2021-UFO/Assignment-2-Professional-Typesetting-using-LaTeX", "max_issues_repo_head_hexsha": "27b667feebaf777b89f5e18cac7c15d683a68019", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pages/chapters/codelisting.tex", "max_forks_repo_name": "SOFT2021-UFO/Assignment-2-Professional-Typesetting-using-LaTeX", "max_forks_repo_head_hexsha": "27b667feebaf777b89f5e18cac7c15d683a68019", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0, "max_line_length": 109, "alphanum_fraction": 0.6367816092, "num_tokens": 716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693674025232, "lm_q2_score": 0.8723473630627235, "lm_q1q2_score": 0.8284415684350359}}
{"text": "\n\\subsection{Least Absolute Shrinkage and Selection Operator (LASSO)}\n\n\\subsubsection{Introduction}\n\nWith LASSO we add a constraint to \\(\\hat \\theta \\).\n\n\\(\\sum_i \\hat \\theta_i \\le t\\)\n\nRegularisation of LLS. Sum of thetas are constrained to be below hyperparameter \\(t\\)\n\nL1 regularisation\n\nThis is also known as sparce regression, because many weights are set to \\(0\\).\n\nThis now looks like:\n\n\\(w_{lasso} = \\arg \\min ||y-Xw||^2_2+\\lambda ||w||_1\\)\n\n\\subsubsection{Hyperparameter}\n\n\\(t\\) is a hyperparameter.\n\n", "meta": {"hexsha": "65684b21a85bef2b0df40c83e136717ebd74e479", "size": 511, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/linearML/02-01-lasso.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/linearML/02-01-lasso.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/linearML/02-01-lasso.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.2916666667, "max_line_length": 85, "alphanum_fraction": 0.7201565558, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.945801267121407, "lm_q2_score": 0.8757869932689566, "lm_q1q2_score": 0.8283204479622263}}
{"text": "\\section{Piecewise linear functions on multilevel\n  grids in 2D}\\label{sec:functions}\nAn image can be viewed as a function on a grid.  Images with different\nresolutions can then be viewed as functions on grids of different\nsizes.  The use of such multiple-grids is a main technique used in the\nstandard multigrid method for solving discretized partial differential\nequations, and it can also be interpreted as a main ingredient used in\nconvolutional neural networks (CNN) for image calssification.\n\nAn image can be viewed as a function on a grid \\cite{krizhevsky2012imagenet} on \na rectangle  domain $\\Omega\\in \\mathcal R^2$.  Without loss of generality,\n we assume that the grid, $\\mathcal T$, is of size\n$$\nm=2^{s}+1~~~n=2^{t}+1 \n$$\nfor some integers $s, t\\ge 1$.\nStarting from $\\mathcal T_1=\\mathcal T$,  we consider a sequence of\ncoarse grids with $J=\\min (s,t)$ (as depicted in Fig.~\\ref{mgrid} with $J=4$):\n\\begin{equation}\n\\label{grids}\n\\mathcal T_1, \\mathcal T_2, \\ldots, \\mathcal T_J\n\\end{equation}\nsuch that ${\\cal T}_\\ell$ consist of $m_\\ell\\times n_\\ell$ grid\npoints, with \n\\begin{equation}\n\\label{mn-ell}\n m_\\ell=2^{s-\\ell+1}+1,~~ n_\\ell=2^{t-\\ell+1}+1.   \n\\end{equation}\n\\begin{figure}[!htbp]\\label{mgrid}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.15\\textwidth]{grid2.png} \\quad \n\t\t\\includegraphics[width=0.15\\textwidth]{grid1.png} \\quad \n\t\t\\includegraphics[width=0.15\\textwidth]{grid0.png} \\quad \n\t\t\\includegraphics[width=0.15\\textwidth]{grid.png} \n\t\\end{center}\n\t$$ \n\\hskip0.05 in \\mathcal T_1\\hskip 0.7in \\mathcal T_2\\hskip 0.7in  \\mathcal T_3\\hskip 0.7in \\mathcal T_4\n\t$$\n\t\\caption{multilevel grids for piecewise linear functions}\n\\end{figure}\n\n\n\n\nThe grid points of these grids can be given by\n$$\nx_i^{\\ell}=i h_{\\ell}, y_j^{\\ell}=j h_{\\ell},  i=0, \\ldots, m_\\ell-1,\nj=0, \\ldots, n_\\ell-1.\n$$\nHere $h_{\\ell} = 2^{-s + \\ell -1}a$ for some $a >0$. The above geometric coordinates $(x_i^\\ell, y_j^\\ell)$\nare usually not used in image precess literatures, but they are relevant\nin the context of multigrid method for numerical solution of PDEs.\nWe now consider piecewise bilinear (or linear) functions on the sequence of grids\n\\eqref{grids} and we obtain a nested sequence of linear vector spaces\n\\begin{equation}\n\\label{Vk}\n\\mathcal V_1\\supset\\mathcal V_2\\supset\\ldots\\supset \\mathcal\nV_J.\n\\end{equation}\n\n\n\n\n", "meta": {"hexsha": "08e72ebefe6fd7b25cd89d6e407255b6a1f0495b", "size": 2326, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.8-2DFEM.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.8-2DFEM.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.8-2DFEM.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.34375, "max_line_length": 107, "alphanum_fraction": 0.7287188306, "num_tokens": 806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8872045877523148, "lm_q1q2_score": 0.8281441011806722}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS671: Machine Learning\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 2}\n\nWhat is the Vapnik-Chervonenkis dimension of the class of rhombi defined above?\n\n\\subsection*{Solution}\n\nLet $\\mathcal{R}$ be the set of all rhombi with ratio $c/d$.\nWe claim that the Vapnik-Chervonenkis Dimension  (VCD) of $\\mathcal{R}$ is two.\nTo support this claim, we first show that any set $ S = \\{x, y\\}$ where $x y \\in \\mathbb{R}^2$ can be shattered by rhombi of ratio $c/d$.\nAs well, we need to show that there is a set $S = \\{x_1, x_2, x_3\\}$ impossible to be shattered by $\\mathcal{R}$.\n\n\\begin{enumerate}\n\\item VCD($\\mathcal{R}$) is at least one, because for any point $P(x,y)$ where $x, y \\in \\mathbb{R}$, we can choose a rhombus with center $(0,0)$ and diagonals $2c$ and $2d$ where $min\\{c,d\\} > (x^2 + y^2)$ to enclose the point.\nAs well, we can be sure that any rhombus with $min\\{c,d\\} < (x^2 + y^2)$ does not contain $P(x,y)$.\nThus $\\mathcal{R}$ shatters sets of size 1.\n\n\\item VCD($\\mathcal{R}$) is at least two, because for any two points $P_1(x_1,y_1)$ and $P_2(x_2,y_2)$, there exists $\\epsilon \\in \\mathbb{R}$ such that a rhombus with a center $P_s(x,y)$ and diagonals of length $x+\\epsilon$ and $y+\\epsilon$ can enclose $P_s$ but no other point.\n\nAs well, diagonals $2c_0$ and $2d_0$ can be found such that $min\\{c,d\\} > max\\{x_1,x_2\\}^2 + max\\{y_1, y_2\\}^2$ to make sure a rhombus with center $(0,0)$ and diagonals $2c > 2c_0$ and $2d > 2d_0$ will contain both $P_1(x_1,y_1)$ and $P_2(x_2,y_2)$.\n\n\\item VCD($\\mathcal{R}$) is not three because three points $P_1(x_1,y_1)$, $P_2(x_2,y_2)$ and $P_3(x_3,y_3)$ can be given such that no rhombus with ratio $c/d$ can shatter them.\nTo show this point, take $P_1(x_1,y_1)$ and $P_2(x_2,y_2)$ at any two arbitrary points $P_1 \\neq P_2$.\n\nIt is always possible to construct a rhombus with ratio $c/d$ such that $P_1$ and $P_2$ are on its edges.\nIf $P_3$ now be chosen inside this rhombus, no rhombus with fixed ratio of $c/d$ can shatter these points anymore.\nMathematically, any choice of $P_3(x_3,y_3)$ such that $x_1 < x_3 < x_2$ and $max\\{y_3/y_1, y_3/y_2\\} < c/d$ will prevent $\\mathcal{R}$ to shatter the three points.\n\\end{enumerate}\n\nTherefore Vapnik-Chervonenkis Dimension of $\\mathcal{R}$ is only 2.\n", "meta": {"hexsha": "ca0c7d27f312c5d079efd98d048884a60ac51154", "size": 2548, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-2015s/src/tex/hw02/hw02q02.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs671-2015s/src/tex/hw02/hw02q02.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs671-2015s/src/tex/hw02/hw02q02.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 68.8648648649, "max_line_length": 279, "alphanum_fraction": 0.6605180534, "num_tokens": 913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.9099070054272775, "lm_q1q2_score": 0.8279307679732913}}
{"text": "\\include{config/config}\n\n\\begin{document}\n% ========== Edit your name here\n\\title{MATH 2901 Basic Probability Lecture Notes 3}\n\\author{Instructor: Richard Kleeman}\n\\date{}\n\\maketitle\n\n%\\medskip\n\n% ========== Contents begin here ==============\n\\section{Probability mass functions}\n\\begin{definition}\nThe \\textbf{(probability) mass function} (p.m.f.) of a discrete random variable $X$ is the function $f: \\R \\to[0, 1]$ given by $f(x) = \\Prob(X = x)$. \n\\end{definition}\n\nNotice that $f(x)$ is not discontinuous. The distribution and mass functions are related by\n\\begin{equation*}\n    F(x) = \\sum_{i: x_i \\leq x} f(x_i), \\quad f(x) = F(x) - \\lim_{y\\uparrow x} F(y).\n\\end{equation*}\n\n\\begin{lemma}\nThe probability mass function $f: \\R \\to [0, 1]$ satisfies: \n\\begin{enumerate}[(a)]\n    \\item the set of $x$ such that $f(x) \\neq 0$ is \\textbf{countable},\n    \\item $\\sum_{i} f(x_i) = 1$, where $x_1, x_2, \\dots$ are the values of $x$ such that $f(x)\\neq 0$.\n\\end{enumerate}\n\\end{lemma}\n\n\\begin{example}\n\\textbf{Binomial distribution.} A coin is tossed $n$ times, and a head turns up each time with probability $p (= 1 - q)$. Then $\\Omega = \\{H, T\\}^n \\}$. The total number $X$ of heads takes values in the set $\\{0, 1, 2, \\dots , n\\}$ and is a discrete random variable. Its probability mass function $f(x) = \\Prob(X = x)$ satisfies \n\\begin{equation*}\n    f(k)= \\binom{n}{k} p^{k}(1-p)^{n-k}, \\quad k=0,1, \\ldots, n.\n\\end{equation*}\nThe random variable $X$ is said to have the \\textbf{binomial distribution} with parameters $n$ and $p$, It is the sum $X = Y_1 + Y_2 + \\dots + Y_n$ of $n$ Bernoulli variables.\n\\end{example}\n\n\\begin{example}\n\\textbf{Poisson distribution.} If a random variable $X$ takes values in the set $\\{O, 1, 2, \\dots \\}$ with mass function\n\\begin{equation*}\n    f(k) = \\frac{\\lambda^k}{k!} e^{-\\lambda}, \\quad k = 0, 1, 2, \\dots, \n\\end{equation*}\nwhere $\\lambda > 0$, then $X$ is said to have the \\textbf{Poisson distribution} with parameter $\\lambda$. Figure \\ref{fig:poisson} shows how p.m.f varies with $k$.\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[scale=0.18]{plots/poisson.png}\n    \\caption{p.m.f of Poisson distribution}\n    \\label{fig:poisson}\n\\end{figure}\n\n\\begin{remark}\nThe interpretation of Poisson distribution can be found via this link: \\href{https://towardsdatascience.com/the-poisson-distribution-and-poisson-process-explained-4e2cb17d459}{The Poisson Distribution and Poisson Process Explained}.\n\\end{remark}\n\\end{example}\n\n\n\\section{Independence of discrete random variables}\nRecall that events $A$ and $B$ are called ``independent\" if and only if $\\Prob(A \\cap B) = \\Prob(A)\\Prob(B)$. \n\n\\begin{definition}\nDiscrete variables $X$ and $Y$ are \\textbf{independent} if the events $\\{X = x\\}$ and $\\{Y = y\\}$ are independent for \\textbf{all} $x$ and $y$. \n\\end{definition}\n\nLet $A: = \\{ \\omega \\spacevert X(\\omega) = x \\}$ and $B:= \\{ \\omega \\spacevert Y(\\omega) = y \\}$. Then we can write $P(A) = f_X(x), P(B) = f_Y(y)$ and $P(A \\cap B) = f(x, y)$. Therefore, $A$ and $B$ are independent if and only if $f(x,y) = f_X(x) f_Y(y)$ for all $x$ and $y$.\n\n\\begin{remark}\nThe equality $f(x,y) = f_X(x) f_Y(y)$ can be used as the criterion to determine whether two discrete random variables $X$ and $Y$ are independent or not. But \\textbf{we need to be careful with it when dealing with continuous random variables} as there will be additional assumptions to determine the independence of continuous random variables using this equality.\n\\end{remark}\n\n\\begin{theorem}\nIf $X$ and $Y$ are independent and $g, h: \\R \\to \\R$, then $g(X)$ and $h(Y)$ are independent also. \n\\end{theorem}\n\nMore generally, we say that a family $\\{ X_i \\spacevert i \\in I\\}$ of (discrete) random variables is independent if the events $\\{X_i = x_i \\}, i \\in I$, are independent for all possible choices of the set $\\{x_i \\spacevert i \\in I\\}$ of the values of the $X_i$ . That is to say, $\\{X_i \\spacevert i \\in I \\}$ is an independent family if and only if \n\\begin{equation*}\n    \\Prob(X_i = x_i \\text{ for all }i\\in J) = \\prod_{i\\in J} \\Prob(X_i = x_i)\n\\end{equation*}\nfor all sets $\\{x_i \\spacevert i \\in I\\}$ and for all finite subsets $J$ of $I$.\n\n\n\\section{Probability density functions}\nRecall that a random variable $X$ is continuous if its distribution function $F(x) = \\Prob(X \\leq x)$ can be written as\\footnote{This is just a general integral, $f(u)$ may or may not be continuous.}\n\\begin{equation*}\n    F(x) = \\int_{\\infty}^x f(u)du\n\\end{equation*}\nfor some integrable $f: \\R \\to [0, \\infty)$.\n\n\\begin{definition}\nThe function $f$ is called the \\textbf{(probability) density function} (p.d.f.) of the continuous random variable $X$. \n\\end{definition}\n\n\\begin{remark}\nThe function $f$ is \\textbf{NOT} unique. We can add some separate points or a countable set of points which has zero measure to $f$. This doesn't change the value of the integral. However, if $F$ is differentiable at $u$ then we shall normally set $f(u) = F'(u)$. \n\\end{remark}\n\nNext, we assume $f$ is continuous, then from the basic theorem of calculus, $F$ must be differentiable. Recall \n\\begin{equation*}\n    P(a < X(\\omega) \\leq b) = F(b) - F(a) = \\int_{a}^b f(u)du.\n\\end{equation*}\nThen $P(X=x) = F(x) - \\lim_{y \\uparrow x} F(y)$. $F$ is \\textbf{absolutely continuous} for continuous random variables. Thus we have\n\\begin{equation*}\n    \\lim_{y\\uparrow x} F(y) = F(x) \\quad \\Rightarrow \\quad P(X=x) = 0 \\quad \\forall x\\in\\R.\n\\end{equation*}\nThis means \\textbf{the probability of a continuous random variable $X$ taking value at a certain point is 0}. Very roughly speaking, this lies in the observation that there are uncountably many possible values for $X$; this number is so large that the probability of $X$ taking any particular value cannot exceed zero. \n\nThe numerical value $f(x)$ is \\textbf{NOT} a probability. Check the probability $\\Prob(x < X \\leq x + dx)$ for a very small $dx$:\n\\begin{equation*}\n    \\Prob(x < X \\leq x + dx) = F(x + dx) - F(x) \\approx f(x) dx. \n\\end{equation*}\nSince $dx$ is a very small interval rather a number, we cannot say $f(x)$ is the probability of something.\n\n\\begin{lemma}\nIf $X$ has density function $f$, then\n\\begin{enumerate}[(a)]\n    \\item $\\int_{-\\infty}^\\infty f(x)dx = 1$,\n    \\item $\\Prob(X=x) = 0$ for all $x \\in \\R$,\n    \\item $\\Prob(a < X \\leq b) = \\int_a^b f(x)dx$.\n\\end{enumerate}\n\\end{lemma}\n\n\\section{Independence of continuous random variables}\n\\subsection{Independence of general random variables}\n\\begin{definition}\nRandom variables $X$ and $Y$ are called \\textbf{independent} if $\\{ X \\leq x\\}$ and $\\{Y \\leq y\\}$ are independent events for all $x, y \\in \\R$. \n\\end{definition}\nNote that this definition is the \\textbf{general} definition of the independence of any two variables $X$ and $Y$, \\textbf{regardless of their types}. The independence of discrete random variables is included in this definition. \n\nRecall the marginalization. If two random variables $X$ and $Y$ are independent, we have\n\\begin{equation*}\n    \\Prob(X\\leq x) = \\lim_{y\\to\\infty}F(x, y) \\equiv F_X(x), \\quad \n    \\Prob(Y \\leq y) = \\lim_{x\\to\\infty}F(x, y) \\equiv F_Y(y).\n\\end{equation*}\nTherefore,\n\\begin{equation}\n    \\label{eq:*}\n    \\tag{*}\n    F(x,y) = \\Prob(X \\leq x, Y \\leq y) = \\Prob(X\\leq x) \\Prob(Y \\leq y) = F_X(x) F_Y(y). \n\\end{equation}\nNote that we are dealing with distribution function in \\eqref{eq:*}. \\eqref{eq:*} can be used as the general criterion to determine whether two random variables are independent or not.\n\n\\subsection{Independence of continuous variables}\nIf $X, Y$ are continuous, then we have\n\\begin{equation*}\n    F(x, y) = \\int_{-\\infty}^x \\int_{-\\infty}^y f(x,y) dx dy.\n\\end{equation*}\n\\begin{equation*}\n    F_X(x) = \\int_{-\\infty}^x \\int_{-\\infty}^\\infty f(x, y)dx dy \\quad \\Rightarrow \\quad f_X(x) = \\int_{-\\infty}^\\infty f(x,y)dy,\n\\end{equation*}\nwhere $f_X(x)$ is called the \\textbf{marginal probability density function} of $X$. Similarly, we can define $F_Y(y)$ and $f_Y(y)$.\n\nAssume $f(x,y)$ is continuous, then $F(x,y)$ must be twice differentiable w.r.t. $x$ and $y$. Therefore, from \\eqref{eq:*}, we can derive a \\emph{very practical criterion} to determine the independence of two continuous random variables:\n\\begin{equation}\n    \\label{eq:**}\n    \\tag{**}\n    f(x,y) = \\frac{\\partial^2 F(x,y)}{\\partial x \\partial y} = \\frac{\\partial}{\\partial x \\partial y} F_X(x) F_Y(y) = f_X(x) f_Y(y).\n\\end{equation}\n\n\\begin{remark}\nNote that the prerequisite of \\eqref{eq:**} is that \\textbf{$f(x,y)$ is continuous}.\n\\end{remark}\n\n\\begin{example}\n\\textbf{Uniform distribution.} The random variable $X$ is uniform on $[a, b]$ if it has distribution function\n\\begin{equation*}\n    F(x) = \\begin{cases} \n        0 & x \\leq x, \\\\ \\frac{x-a}{b-a} & a < x \\leq b, \\\\ 1 & x > b\n    \\end{cases}.\n\\end{equation*}\nThe density function is\n\\begin{equation*}\n    f(x) = \\begin{cases} \\frac{1}{b-a} & a < x \\leq b \\\\ 0 & o.w. \\end{cases}\n\\end{equation*}\n\\end{example}\n\n\\begin{example}\n\\textbf{Exponential distribution}. The random variable $X$ is exponential with parameter $\\lambda(> 0)$ if it has distribution function \n\\begin{equation*}\n    F(x) = 1 - e^{-\\lambda x}, \\quad x \\geq 0.\n\\end{equation*}\nThe density function is\n\\begin{equation*}\n    f(x) = \\begin{cases} \\lambda e^{-\\lambda x} & x > 0 \\\\ 0 & o.w.\n    \\end{cases}\n\\end{equation*}\nNote that $F(x)$ is not differentiable at $x=0$. This means $f$ has discontinuity at $x=0$. Thus we need to choose some value for $f(0)$. It doesn't matter what value we choose as it doesn't affect the integral. Figure \\ref{fig:exponential} shows the p.d.f. of Exponential distribution.\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[scale=0.25]{plots/exponential.png}\n    \\caption{p.d.f. of Exponential distribution}\n    \\label{fig:exponential}\n\\end{figure}\n\n\\begin{remark}\nThe interpretation of Exponential distribution can be found via \\href{https://www.probabilitycourse.com/chapter4/4_2_2_exponential.php}{Exponential distribution 1} and \\href{https://www.statlect.com/probability-distributions/exponential-distribution}{Exponential distribution 2}. Pay attention to the connection between Exponential distribution and Poisson distribution.\n\\end{remark}\n\\end{example}\n\n\\begin{example}\n\\textbf{Normal (or Gaussian) distribution.} The most important continuous distribution, which has two parameters $\\mu$ and $\\sigma^2$ and density function\n\\begin{equation*}\n    f(x) = \\frac{1}{\\sqrt{2\\pi\\sigma^2}} \\exp \\left( -\\frac{(x-\\mu)^2}{2\\sigma^2} \\right), \\quad x\\in\\R. \n\\end{equation*}\nIt is denoted by $N(\\mu, \\sigma^2)$. If $\\mu=0$ and $\\sigma^2=1$, then\n\\begin{equation*}\n    f(x) = \\frac{1}{\\sqrt{2\\pi}} e^{-\\frac{1}{2}x^2}, \\quad x\\in\\R.\n\\end{equation*}\nis the density of the standard normal distribution. It is easy to generalize 2D case to multivariable case. Suppose $\\mathbf{x} \\in \\R^n$, $\\mathbf{\\mu} \\in \\R^n$ is the mean vector and $\\mathbf{\\sigma}^2 \\in \\R^{n\\times n}$ is the covariance matrix. Then\n\\begin{equation*}\n    f(\\mathbf{x}) = \\frac{1}{\\sqrt{(2\\pi)^n} \\det(\\mathbf{\\sigma}^2)} \\exp \\left( -\\frac{1}{2} (\\mathbf{x}-\\mathbf{\\mu})^T (\\mathbf{\\sigma}^2)^{-1} (\\mathbf{x}-\\mathbf{\\mu}) \\right), \\quad \\mathbf{x} \\in \\R^n.\n\\end{equation*}\n\n\\begin{remark}\nFor 2D case, if $\\sigma^2$ is diagonal, then $f(x,y) = f(x)f(y)$. Therefore, $\\sigma^2$ is a measure of independence. For multivariable cases, if $\\sigma^2$ is diagonal, then all random variables are independent with each other.\n\\end{remark}\n\\end{example}\n\n\n\\end{document}", "meta": {"hexsha": "4e8a23027688425234aad5d7408b54d7a6b64bb5", "size": 11456, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_drafts/MATH 2901/notes_3.tex", "max_stars_repo_name": "yuhan-zhao/freshman21-v1", "max_stars_repo_head_hexsha": "e4c5f7983a768554399193f47e8426976205330f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_drafts/MATH 2901/notes_3.tex", "max_issues_repo_name": "yuhan-zhao/freshman21-v1", "max_issues_repo_head_hexsha": "e4c5f7983a768554399193f47e8426976205330f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_drafts/MATH 2901/notes_3.tex", "max_forks_repo_name": "yuhan-zhao/freshman21-v1", "max_forks_repo_head_hexsha": "e4c5f7983a768554399193f47e8426976205330f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.3105022831, "max_line_length": 370, "alphanum_fraction": 0.6791201117, "num_tokens": 3770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.9099070023734244, "lm_q1q2_score": 0.8279307607486135}}
{"text": "\\documentclass[12pt]{scrartcl}\n\n\\input{preamble}\n\n\\makeatletter\n\\title{Hack 5.0}\\let\\Title\\@title\n\\subtitle{Computer Science I -- Honors\\\\\n{\\small\n\\vskip1cm\nDepartment of Computer Science \\& Engineering \\\\\nUniversity of Nebraska--Lincoln}\n\\vskip-1cm}\n%\\author{Dr.\\ Chris Bourke}\n\\date{~}\n\\makeatother\n\n\\begin{document}\n\n\\maketitle\n\n\\hrule\n\n\\input{instructions.tex}\n\n\\section*{Problem Statement}\n\nTo get some practice designing and using functions, you will \ncreate a small library of utility functions by implementing\nthe following functions with the given prototypes and specified \nfunctionality.\n\\begin{enumerate}\n  \\item Write a method to convert degrees to radians using the formula \n\t\t$$\\frac{d\\cdot \\pi}{180}$$\n\tYour method should have the following signature.\n\t\n\t\\mintinline{java}{public static double degreesToRadians(double degree)}\n  \\item Write a function to compute the air distance between two locations \n    identified by their latitude/longitude. Your method should have the \n    following signature.\n\n\\begin{minted}{java}\npublic static double getAirDistance(double originLatitude, \n                                    double originLongitude, \n                                    double destinationLatitude, \n                                    double destinationLongitude)\n\\end{minted}  \nThe air distance between two latitude/longitude points can be calculated \nusing the Spherical Law of Cosines:\n $$d = \\arccos{(\\sin(\\varphi_1) \\sin(\\varphi_2) + \\cos(\\varphi_1) \\cos(\\varphi_2) \\cos(\\Delta) )} \\cdot R$$\nwhere\n\\begin{itemize}\n  \\item $\\varphi_1$ is the latitude of location $A$, $\\varphi_2$ is the latitude of location $B$\n  \\item $\\Delta$ is the difference between location $B$'s longitude and location $A$'s longitude\n  \\item $R$ is the (average) radius of the earth, 6,371 kilometers\n\\end{itemize}\nNote: the formula above assumes that latitude and longitude are measured \nin radians $r$, $-\\pi \\leq r \\leq \\pi$, but the function will expect \nthe latitude/longitude to be in degrees.  Latitude should be in the range \n$[-90, 90]$ and longitude in the range $[-180, 180]$.  Negative values \ncorrespond to the southern and western hemispheres.\n\n  \\item An object traveling at a velocity $v$ experiences time dilation\n  relative to a stationary object which is quantified by the Lorentz equation:\n  $$T = \\frac{t}{\\sqrt{(1-\\frac{v^2}{c^2})}}$$\n  where $t$ is the normal amount of lapsed time (stationary object) \n  and $T$ is the dilated time experienced by the traveling object.  \n  For small velocities, the dilation is small, but for velocities\n  approaching a \\emph{percentage} of the speed of light, $c$, the \n  dilation becomes significant.\n  \n  For example, at 25\\% the speed of light, a year for the object \n  traveling would correspond to 1.032796 years at the stationary object \n  (or nearly 12 extra days).   A person traveling at high velocity \n  would experience ``slowed'' time\n  relative to the stationary \\emph{frame}.  Implement a function to \n  compute the dilated time given the normal time $t$ (units may vary)\n  and the percentage of the speed of light.\n\\begin{minted}{java}\npublic static double lorentzTimeDilation(double t, double percentC);\n\\end{minted}\n\n\\end{enumerate}  \n\n\\section*{Instructions}\n\n\\begin{itemize}\n  \\item You are encouraged to collaborate any number of students \n  before, during, and after your scheduled hack session.  \n  \\item Design at least 3 test cases for each function\n  \\emph{before} you begin\n  designing or implementing your program.  Test cases are \n  input-output pairs that are known to be correct using means\n  other than your program.\n  \\item Include the name(s) of everyone who worked together on\n  this activity in your source file's header.\n  \\item Place your methods with documentation in a source file named \n    \\mintinline{text}{Utils.java}.\n\n  \\item In addition, implement all of your test cases in a \n    \\emph{test driver} file named \\mintinline{text}{UtilsTester.java} \n    which should output the expected output, the actual\n    output and a message on whether or not the test case passed. You\n    must have at least 3 test cases for \\emph{each} of your functions. You\n    should \\emph{not} prompt for input or use command line arguments. Your\n    test cases should be hardcoded in your test driver's \\mintinline{java}{main()} method.\n    \n  \\item Turn in all of your files via webhandin, making sure that it runs\n    and executes correctly in the webgrader. Each individual student\n    will need to hand in their own copy and will receive their own\n    individual grade.\n\\end{itemize}\n  \n\n\n\\end{document}\n", "meta": {"hexsha": "2baa482ba1e8be5fe600a10803865289739c3e57", "size": 4593, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "honors/hacks/hack5.0.tex", "max_stars_repo_name": "bobbys131/ComputerScienceI", "max_stars_repo_head_hexsha": "93e22289e966386f208c477ee319837877bbe62a", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 68, "max_stars_repo_stars_event_min_datetime": "2018-05-14T20:29:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T10:05:16.000Z", "max_issues_repo_path": "honors/hacks/hack5.0.tex", "max_issues_repo_name": "hrithik125/ComputerScienceI", "max_issues_repo_head_hexsha": "40be47f15817a50497f6c6f7cdca9ee1db429b00", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-05-11T01:30:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-02T04:34:10.000Z", "max_forks_repo_path": "honors/hacks/hack5.0.tex", "max_forks_repo_name": "hrithik125/ComputerScienceI", "max_forks_repo_head_hexsha": "40be47f15817a50497f6c6f7cdca9ee1db429b00", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 204, "max_forks_repo_forks_event_min_datetime": "2018-10-17T18:35:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T16:51:50.000Z", "avg_line_length": 39.5948275862, "max_line_length": 107, "alphanum_fraction": 0.7311125626, "num_tokens": 1165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.9252299524531926, "lm_q1q2_score": 0.8278860047942656}}
{"text": "\\section{Parareal}\n\nWe would like to solve the autonomous ordinary differential equation:\n\\begin{equation*}\n  \\begin{cases}\n    u'(t) = f(u), & t \\in [t_0, t_f] \\\\\n    u(t_0) = u_0\n  \\end{cases}\n\\end{equation*}\nwhere $f : \\mathbb{R}^d \\to \\mathbb{R}^d$ and $u: \\mathbb{R} \\to \\mathbb{R}^d$.\n\nParareal is an iterative scheme to approximate $u$ for the above, which can be\nderived from the concept of \\textit{multiple shooting} methods. The idea behind\nthese methods are to turn the problem into a nonlinear optimization problem,\nwhich then can be solved via Newton-Raphson. \\cite{gandervandewalle}\n\nTake our time domain $[t_0, t_f]$ and partition it into $N$ pieces $0 = t_0 <\n\\dots < t_N = t_f$. Looking specifically at the interval $[t_n, t_{n+1}]$, we\npose the new ODE:\n\\[\n  \\begin{cases}\n    u'_n = f(u_n), & t \\in [t_n, t_{n+1}] \\\\\n    u(t_n) = U_n\n  \\end{cases}\n\\]\nwhere $U_n$ is such that $U_n - u_{n-1}(t_n, U_{n-1}) = 0$, i.e. the initial\ncondition satisfies the solution to the previous time slice. The conditions on\n$U_i$ form a nonlinear system $F(U) = 0$, which we can approximate using\nNewton-Raphson, so we recieve the iteration $U^{k+1} = U^k -\nJ_F^{-1}(U^k)F(U^k)$. As it turns out, as seen in Gander and Vandewalle\n\\cite{gandervandewalle}, that we can actually change this into the form:\n\\[\n  \\begin{cases}\n    U_0^{k+1} = u_0 \\\\\n    U_{n+1}^{k+1} = u_n(t_{n+1}, U_n^k) + \\frac{\\partial u_n}{\\partial\n    U_n}(t_{n+1}, U_n^k)(U_n^{k+1} - U_n^k)\n  \\end{cases}\n\\]\nIf we were to then, call $u_n(t_{n+1}, U_n^k) = \\fine(t_{n+1}, t_n, U_n^k)$\nwhere $F$ is some near truth integrator and were to approximate the second\nterm with another integrator $\\coarse(t_{n+1},t_n,U_n^{k+1}) -\n\\coarse(t_{n+1},t_n, U_n^k)$, then we would recieve the iteration:\n\\[\n  \\begin{cases}\n    U_0^{k+1} = u_0 \\\\\n    U_{n+1}^{k+1} = \\fine(t_{n+1}, t_n, U_n^k) + \\coarse(t_{n+1},t_n,U_n^{k+1})\n    - \\coarse(t_{n+1},t_n, U_n^k)\n  \\end{cases}\n\\]\nThis is precisely what we call parareal iteration. Alternatively, you can think\nabout this as the predictor-corrector scheme:\n\\[\n  \\begin{cases}\n    U_0^{k+1} = u_0 \\\\\n    U_{n+1}^{k+1} = \\coarse(t_{n+1},t_n,U_n^{k+1}) + \\left(\\fine(t_{n+1}, t_n,\n    U_n^k) - \\coarse(t_{n+1},t_n, U_n^k)\\right)\n  \\end{cases}\n\\]\nRegardless, we notice that this iteration, which is an approximation to our\nsolution as $k \\to \\infty$, has a term which is decoupled from the current\niteration step, $\\fine$. Furthermore, it satisfies a \\textit{first same as last}\nproperty with the coarse integrators $\\coarse$. The idea behind the parareal\nmethod is to take advantage of both of these properties.\n", "meta": {"hexsha": "50edb1d96662c2abf2e7c3fa328d338e10c22cde", "size": 2611, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/TeXsrc/src/parareal.tex", "max_stars_repo_name": "abhijit-c/Parareal", "max_stars_repo_head_hexsha": "e64c8ae44577da7e92720aa12b12f28acb3fc473", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-08-01T19:31:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-08T13:54:15.000Z", "max_issues_repo_path": "Report/TeXsrc/src/parareal.tex", "max_issues_repo_name": "abhijit-c/Parareal", "max_issues_repo_head_hexsha": "e64c8ae44577da7e92720aa12b12f28acb3fc473", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/TeXsrc/src/parareal.tex", "max_forks_repo_name": "abhijit-c/Parareal", "max_forks_repo_head_hexsha": "e64c8ae44577da7e92720aa12b12f28acb3fc473", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-25T00:02:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T00:02:33.000Z", "avg_line_length": 40.796875, "max_line_length": 80, "alphanum_fraction": 0.6656453466, "num_tokens": 963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766224, "lm_q2_score": 0.880797085800514, "lm_q1q2_score": 0.8278729349842627}}
{"text": "\\chapter{Orbits}\n\nA satellite stays in orbit around the planet because the pull of the\nplanet's gravity causes it to accerate toward the center of the\nplanet. The satellite must be moving a very particular speed to keep a\nconstant distance from the planet -- to travel in a circular orbit.\nIf it is moving too slowly, it will get closer to the planet.  If it\nis going too fast, it will get farther from the planet.\n\nThe radius of the earth is about 6.37 million meters. A satellite that\nis in a low orbit is typically about 2 million meters above the\nground. At that distance, the acceleration due to gravity is more like\n$6.8 m/s^2$, instead of the $9.8 m/s^2$ that we experience on the\nsurface of the planet.\n\nHow fast does the satellite need to be moving in a circle with a\nradius of 8.37 million meters to have an acceleration of $6.8 m/s^2$? Real fast.\n\nRecall that the acceleration vector is\n\n$$a = \\frac{v^2}{r}$$\n\nThus the velocity $v$ needs to be:\n\n$$v = \\sqrt{a r} = \\sqrt{6.8(8.37 x 10^6} = 7,544 \\text{ m/s}$$\n\n(That's 16,875 miles per hour.)\n\nWhen a satellite falls out of orbit, it enters the atmosphere at that\n7,544 m/s.  The air rushing by generates so much friction that the\nsatellite gets very, very hot and usually disintegrates.\n\n\\section{Astronauts are \\emph{not} weightless}\n\nSome people see astronauts floating inside an orbiting spacecraft and\nthink there is no gravity: that the astronauts are so far away that\nthe gravity of the planet doesn't affect them. This is incorrect.  The\ngravity might be slightly less (Maybe 6 newtons per kg instead of 9.8\nnewtons per kg), but the weightless they experience is because they\nand the spacecraft are in free fall.  They are just moving so fast (in\na direction perpendicular to gravity) that they don't collide with the\nplanet.\n\n\\begin{Exercise}[title={Mars Orbit}, label=mars_orbit]\n  \n  The radius of Mars is 3.39 million meters. The atmosphere goes up\n  another 11 km.  Let's say you want to put a satellite in a circular\n  orbit around Mars with a radius of 3.4 million meters.\n\n  The acceleration due to gravity on the surface of Mars is $3.721\n  m/s^2$. We can safely assume that it is approximately the same 11 km\n  above the surface.\n\n  How fast does the satellite need to be traveling in its orbit?  How\n  long will each orbit take?\n\n\\end{Exercise}\n\\begin{Answer}[ref=circular]\n  $$v = \\sqrt{3.721(3.4 \\times 10^6)} = 3,557\\text{ m/s}$$\n\n  The circular orbit is $2\\pi(3.4 \\times 10^6) = 21.4 \\times 10^6$ meters in circumference.\n\n  The period of the orbit is $(21.4 \\times 10^6)/3,557 \\approx 6,000$ seconds.\n\\end{Answer}\n\n\\section{Geosynchronous Orbits}\n\nThe planet earth rotates once a day.  Satellites in low orbits circle\nthe earth many times in a day. Satellites in very high orbits circle\nless than once per day. There is a radius at which a satellite orbits\nexactly once per day.  Satellites at this radius are known as\n``geosynchronous'' or ``geostationary'' because they are always\ndirectly over a place on the planet.\n\nThe radius of a circular geosynchronous orbit is 42.164 million\nmeters. (About 36 km above the surface of the earth.)\n\nA geosynchronous satellite travels at a speed of 3,070 m/s.\n\nGeosynchronous satellites are used for the Global Positioning\nSatellite system, weather monitoring system, and communications\nsystem.\n\n\n\n\n", "meta": {"hexsha": "a433d13b1c2797479ebde440410661792ef289b1", "size": 3325, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Oscillations/orbits-en_US.tex", "max_stars_repo_name": "hillegass/sequence", "max_stars_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/Oscillations/orbits-en_US.tex", "max_issues_repo_name": "hillegass/sequence", "max_issues_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/Oscillations/orbits-en_US.tex", "max_forks_repo_name": "hillegass/sequence", "max_forks_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 38.2183908046, "max_line_length": 91, "alphanum_fraction": 0.7542857143, "num_tokens": 901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475794701961, "lm_q2_score": 0.8774767842777551, "lm_q1q2_score": 0.8277656004897117}}
{"text": "\\chapter{Time Complexity}\n\n\\section{Basic Counts}\n\\rih{Double for-loops} \n$$\n\\sum_{i=1}^N{\\sum_{j=i}^N{1}} = {N \\choose 2} \\sim \\frac{1}{2} N^2\n$$\n$$\n\\sum_{i=1}^N{\\sum_{j=i}^N{1}} \\sim \\int_{x=1}^N \\int_{y=x}^N  \\mathrm{d}y\\, \\mathrm{d}x\n$$\n\\rih{Triple for-loops}\n$$\n\\sum_{i=1}^N{\\sum_{j=i}^N{\\sum_{k=1}^N{1}}} = {N \\choose 3} \\sim \\frac{1}{6} N^3\n$$\n$$\n\\sum_{i=1}^N{\\sum_{j=i}^N{\\sum_{k=1}^N{1}}} \\sim \\int_{x=1}^N \\int_{y=x}^N \\int_{z=y}^N \\mathrm{d}z\\,\n\\mathrm{d}y\\, \\mathrm{d}x\n$$\n\n\\section{Solving Recurrence Equations}\nBasic recurrence equation solving techniques:\n\\begin{enumerate}\n\\item Guessing and validation\n\\item Telescoping\n\\item Recursion tree\n\\item Master Theorem\n\\end{enumerate}\n\n\\subsection{Master Theorem}\nRecurrence relations:\n$$T(n) = a \\; T\\!\\left(\\frac{n}{b}\\right) + f(n)\\mbox{, where }a \\geq 1 \\mbox{, } b > 1$$\n\nNotice that $b>1$ rather than $b\\geq1$.\n\n\\subsubsection*{Case 1}\nIf:\n$$f(n) = o(n^{\\log_b a})$$\n\n, where in the condition it is $o$ rather than $O$. \\\\\\\\\nThen:\n$$T(n) = \\Theta(n^{\\log_b a})$$\n\\subsubsection*{Case 2}\nIf:\n$$f(n) = \\Theta(n^{\\log_b a} \\log^{k} n)$$\n\n, for some constant $k \\geq 0$\\\\\\\\\nThen:\n$$\nT(n) = \\Theta(n^{\\log_b a} \\log^{k+1} n)\n$$\n\n, typically $k=0$ in most cases. \n\\subsubsection*{Case 3}\nIf:\n$$f(n) = \\omega(n^{\\log_b a})$$\n\n, where in the condition it is $\\omega$ rather than $\\Omega$. \\\\\\\\\nAnd with regularity condition:\n$$f(\\frac{n}{b}) \\le k f(n)$$\n\n, for some constant $k < 1$ and sufficiently large $n$\\\\\\\\\nThen:\n$$T\\left(n \\right) = \\Theta\\left(f(n) \\right)$$\n\\section{Useful Math Equations}\nEuler:\n$$\n\\frac{1}{2}+\\frac{1}{3}+\\frac{1}{4} + ... + \\frac{1}{n} = \\ln{n}\n$$\nLogarithm power: \n$$\na^{\\log_b^n} &= n^{\\log_b^a}\n$$\n\nproof:\n\\begin{align*}\na^{\\log_b^n} &= n^{\\log_b^a} \\\\\n\\Leftarrow \\ln{a^{\\log_b^n}} &= \\ln{n^{\\log_b^a}}\\\\\n\\Leftarrow  \\frac{\\ln n}{\\ln b}\\ln a &=\\frac{\\ln a}{\\ln b}\\ln n\n\\end{align*}\n", "meta": {"hexsha": "88c7ade59bb9911fa5504e0e65c614720a4dd184", "size": 1874, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterTimeComplexity.tex", "max_stars_repo_name": "li77leprince/Algo-Quicksheet", "max_stars_repo_head_hexsha": "1736bc0ee1d73b0b06dcf3823a65ea0f8c286108", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapterTimeComplexity.tex", "max_issues_repo_name": "li77leprince/Algo-Quicksheet", "max_issues_repo_head_hexsha": "1736bc0ee1d73b0b06dcf3823a65ea0f8c286108", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapterTimeComplexity.tex", "max_forks_repo_name": "li77leprince/Algo-Quicksheet", "max_forks_repo_head_hexsha": "1736bc0ee1d73b0b06dcf3823a65ea0f8c286108", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.425, "max_line_length": 101, "alphanum_fraction": 0.5901814301, "num_tokens": 822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551515780319, "lm_q2_score": 0.8577680977182187, "lm_q1q2_score": 0.827621967942712}}
{"text": "\n\\chapter{Key Mathematical Results}\n\nThere are a number of key results that you are expected to know. These\nwill have been covered in previous courses. For rigorous statements\nand proofs you should consult books on the reading list or basic\ncalculus or linear algebra texts.\n\n\\section{Linear Algebra}\n\nA vector $\\bv$ of length $N$ is a set of $N$ numbers ordered either as\na row or column. In either case the notation $v_i$ is used to denote\nthe coefficients.\n\nThe dot product of a row vector $\\bx$ with a column vector $\\by$ is\ngiven by\n%\n\\begin{equation}\n  \\label{eq:key_la1}\n  \\bx \\cdot \\by = \\sum_{i=1}^n x_i \\cdot y_i.\n\\end{equation}\n\nA matrix $A$ of size $N$ is a set of $N^2$ numbers ordered into $N$\nrows and $N$ columns. These numbers are called the coefficients,\ndenoted $a_{ij}$, $i$ indicating the row and $j$ the column.\n\nMatrix-matrix multiplication written $A B = C$ defines the\ncoefficients of the matrix $C$ in terms of the (given) matrix\ncoefficients of $A$ and $B$ by\n%\n\\begin{equation}\n  \\label{eq:key_la2}\n  c_{ij} = \\sum_{l = 1}^n a_{i l} b_{l j}.\n\\end{equation}\n%\nIn other words, the $c_{ij}$ coefficient is given by the dot product\nof the $i^{\\text{th}}$ row of $A$ with the $j^{\\text{th}}$ column of\n$B$.\n\nMatrix-vector multiplication $A \\bx = \\bb$ defines the coefficients of\nthe column vector $\\bb$ in terms of the gives matrix $A$ and column\nvector $\\bx$; as expected this is given by\n%\n\\begin{equation}\n  \\label{eq:key_la3}\n  b_{i} = \\sum_{l = 1}^n a_{i l} x_{l}.\n\\end{equation}\n\nThe system of linear equations $A \\bx = \\bb$ where $A, \\bb$ are known\nand $\\bx$ is unknown, has a unique solution if, and only if, the\ndeterminant of the matrix $A$ is non-zero.\n\nEigenvectors of a matrix $A$ are any vector $\\bx$ such that $A \\bx =\n\\lambda \\bx$. The value $\\lambda$ is called an eigenvalue. Eigenvalues\ncan be found from the characteristic polynomial $\\det(A - \\lambda I) =\n0$, where $I$ is the $N \\times N$ identity matrix (this is not a\npractical way of computing eigenvalues when $N$ is\nlarge). Eigenvectors are only defined up to a multiplicative constant\n(i.e., if $\\bx$ is an eigenvector then $\\alpha \\bx$ is an eigenvector\nwith the same eigenvalue, provided $\\alpha \\ne 0$).\n\nA \\emph{basis} is a set of $N$ independent vectors $\\be_i$ such that\nany vector $\\bx$ can be expressed as a linear combination\n%\n\\begin{equation}\n  \\label{eq:key_la4}\n  \\bx = \\alpha_1 \\be_1 + \\dots \\alpha_N \\be_N.\n\\end{equation}\n%\nA particularly useful case is when the eigenvectors of a matrix $A$\nform a basis.\n\n\\section{Taylor's theorem}\n\nIf $f$ is a continuous function on $x \\in [a, b]$ and the\n$(n+1)^{\\text{th}}$ derivative exists on $(a, b)$, then for any point\n$c \\in [a, b]$, we can express $f(x)$ (for any point $x \\in [a, b]$)\nas\n%\n\\begin{equation}\n  \\label{eq:key_taylor}\n  f(x) = \\left\\{\\sum_{k=0}^n \\frac{1}{k!} f^{(k)}(c) \\, (x - c)^k\n  \\right\\} + E_n(x),\n\\end{equation}\n%\nwhere, for some point $\\xi$ between $c$ and $x$, the \\emph{error} or\n\\emph{remainder} $E_n$ can be expressed as\n%\n\\begin{equation}\n  \\label{eq:key_taylor2}\n  E_n(x) = \\frac{1}{(n+1)!} f^{(n+1)}(\\xi) \\, (x - c)^{n+1}.\n\\end{equation}\n%\nHere the notation $f^{(n)}$ means the $n^{\\text{th}}$ derivative of\n$f$.\n\nFor our purposes, the most useful way of writing this will be in the\nform of a Maclaurin series where $c=0$. We shall also often consider\ncases where $x \\rightarrow h$, $|h| \\ll 1$, leading to\n%\n\\begin{equation}\n  \\label{eq:key_taylor3}\n  f(h) = f(0) + h f^{(1)}(0) + \\frac{h^2}{2} f^{(2)}(0) +\n  \\frac{h^3}{3!} f^{(3)}(0) + \\dots + \\order{h^n}.\n\\end{equation}\n%\nThe notation $\\order{h^n}$ means that the remaining terms contain\npowers of $h$ at least as big as $n$; when $h$ is small it is usually\nreasonable to neglect these terms.\n\n\\section{Triangle inequality}\n\nFor any normed vector space $V$ with elements $\\bx, \\by \\in V$, the\ntriangle inequality states that\n%\n\\begin{equation}\n  \\label{eq:key_triangle}\n  \\| \\bx + \\by \\| \\leq \\| \\bx \\| + \\| \\by \\|.\n\\end{equation}\n\nFor our purposes we will mostly be concerned with real numbers where\n$\\| \\bx \\|$ has the simple interpretation as the absolute value of the\nnumber $x$. In this case the triangle inequality simply says that the\nsum of the lengths of any two sides of a triangle must be greater than\nor equal to the length of the remaining side.\n\n\\section{Difference equations}\n\nFor linear constant coefficient ODEs\n%\n\\begin{equation}\n  \\label{eq:key_DE}\n  a_n y^{(n)}(x) + \\dots + a_1 y^{(1)}(x) + a_0 y(x) = 0\n\\end{equation}\n%\nthere is a simple solution method in terms of the \\emph{characteristic\npolynomial}\n%\n\\begin{equation}\n  \\label{eq:key_DE2}\n  a_n \\lambda^n + \\dots + a_1 \\lambda + a_0 = 0.\n\\end{equation}\n%\nThe characteristic polynomial follows from substituting the assumption\n$y(x) = \\exp[\\lambda x]$ into equation~(\\ref{eq:key_DE}); $\\lambda$ is\nthen a root of the characteristic polynomial. The general solution is\nthe general linear combination of all solutions found from the\ncharacteristic polynomial. Note that repeated roots complicate the\nanalysis slightly.\n\nThe same approach can be used for \\emph{difference equations}. These\nare equations that define sequences (of e.g.\\ real numbers or\nvectors), usually written in the form\n%\n\\begin{equation}\n  \\label{eq:key_DE3}\n  a_k y_n + \\dots + a_1 y_{n-k+1} + a_0 y_{n-k} = 0.\n\\end{equation}\n%\nSubstituting the assumption $y_n = \\lambda^n$ gives the characteristic\npolynomial\n%\n\\begin{equation}\n  \\label{eq:key_DE4}\n  a_n \\lambda^n + \\dots + a_1 \\lambda + a_0 = 0.\n\\end{equation}\n%\nAssuming all roots are distinct, the solution is a linear combination\nof the simple solutions $\\lambda^n$. If $\\mu$ is a root with\nmultiplicity $k$ then the sequences\n%\n\\begin{equation}\n  \\label{eq:key_DE5}\n  y^{\\{l\\}}_n = \\dv[(l-1)]{}{\\lambda} \\left[\n    \\lambda^n \\right], \\quad l = 0, \\dots, k\n\\end{equation}\n%\nare all solutions.\n\nFor our purposes the key is that for the solution of a difference\nequation to be \\emph{bounded} (i.e., $y_n$ is bounded as $n \\rightarrow\n\\infty$) we need all roots $\\lambda$ to satisfy $|\\lambda| \\le 1$ (and\nif the root is repeated we need $|\\lambda| < 1$).\n", "meta": {"hexsha": "0361c544b3279367a8be2f816e8af040c287cdde", "size": 6099, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/KeyMaths.tex", "max_stars_repo_name": "josh-gree/NumericalMethods", "max_stars_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 76, "max_stars_repo_stars_event_min_datetime": "2015-02-12T19:51:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T15:34:11.000Z", "max_issues_repo_path": "Notes/tex/KeyMaths.tex", "max_issues_repo_name": "josh-gree/NumericalMethods", "max_issues_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-05-24T19:49:52.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-23T21:40:42.000Z", "max_forks_repo_path": "Notes/tex/KeyMaths.tex", "max_forks_repo_name": "josh-gree/NumericalMethods", "max_forks_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2015-01-05T13:30:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T09:59:39.000Z", "avg_line_length": 33.1467391304, "max_line_length": 71, "alphanum_fraction": 0.6925725529, "num_tokens": 1969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.8976952989498448, "lm_q1q2_score": 0.8276048990743553}}
{"text": "\\lab{Trust-Region Methods}{Trust-Region Methods}\n\\label{lab:trust_region}\n\n\\objective{Explore Trust-Region methods for optimization.}\n\nWhen it comes to optimizing high-dimensional functions, a common strategy is to break\nthe problem up into a series of smaller, easier tasks, leading to a sequence of\nsuccessive approximations to the optimizer. This is the approach taken by Line-Search\nalgorithms such as Newton's method or conjugate gradient.\nThe class of algorithms known as trust-region methods are also based on this\nstrategy, although they differ from line-search methods in some important ways.\n\n\\section*{Overview of the Trust-Region Approach}\nSuppose we wish to minimize a function $f$.\nGiven some particular point $x_k$ in the domain of $f$, how do we\nselect a new point $x_{k+1}$ that better minimizes the function? A line-search\nalgorithm solves this sub-problem by first choosing a search direction $d_k$\n(often related to the gradient of $f$), and then a step length $\\alpha_k$ so\nas to minimize $f$ along the direction $d_k$. The next point, then, is simply\n\\[\nx_{k+1} := x_k + \\alpha_k d_k.\n\\]\n\nA trust-region algorithm, on the other hand, does away with a search direction and\nstep length, and instead approximates the function $f$ with some simpler function\n$m_k$ (called the \\emph{model function}) in a neighborhood of $x_k$.\nThe model $m_k$ will likely not be close to $f$ over the entire\ndomain, and so we must restrict our attention to a ball of radius $r_k$ centered at\nthe point $x_k$, inside of which $m_k$ is reasonably close to $f$. We then minimize\n$m_k$ over this ball, and set $x_{k+1}$ equal to this minimizer. That is, we compute $x_{k+1}$ by\nsolving the sub-problem\n\\[\nx_{k+1} := \\underset{x \\in B(x_k, r_k)}{\\text{argmin}} m_k(x).\n\\]\nThe ball $B(x_k, r_k)$ is called the \\emph{trust region} because we trust that the\nmodel function $m_k$ gives a reasonably accurate approximation of $f$ on this region.\nNote that it is also possible to use other types of trust regions, such as\nellipsoidal or box-like regions.\n\n\\subsection*{The Model Function}\nThe model function is commonly taken to be a linear or quadratic approximation of\n$f$ based on its Taylor Series expansion about the point $x_k$. In the linear case,\nour model function has the form\n\\[\nf(x_k) + (y-x_k)^T \\nabla f(x_k).\n\\]\nIn the quadratic case, we simply add on a quadratic term to obtain\n\\[\nf(x_k) + (y-x_k)^T \\nabla f(x_k) + \\frac{1}{2}(y - x_k)^T B_k (y-x_k),\n\\]\nwhere $B_k$ is the Hessian matrix of $f$ at $x_k$, or some approximation thereof.\nGiven a trust region with radius $r_k$, note that our sub-problem can be\nwritten in the following way:\n\\begin{align*}\nx_{k+1} &= \\underset{x \\in B(x_k, r_k)}{\\text{argmin}} m_k(x)\\\\\n&= x_k + p_k,\n\\end{align*}\nwhere\n\\begin{equation}\np_k = \\underset{\\|p\\| < r_k}{\\text{argmin}}\\, \\{f(x_k) + p^T \\nabla f(x_k) + \\frac{1}{2}p^T B_k p\\}\n\\label{eq:step}\n\\end{equation}\n($p_k$ is called a \\emph{step}).\nFor the remainder of the lab, we define\n\\[\nm_k(p) = f(x_k) + p^T \\nabla f(x_k) + \\frac{1}{2}p^T B_k p,\n\\]\nand refer to \\emph{this} function as the model function.\n\n\\subsection*{The Trust-Region Radius}\nA crucial aspect of trust-region algorithms is the choice of radius $r_k$. If $r_k$ is too small, then the algorithm will\nmake slow progress toward the minimizer of $f$. If $r_k$ is too large, the model function will be a poor fit for the objective\nfunction $f$, and the next iterate $x_{k+1}$ may fail to decrease $f$.\nOf course, whether the radius is too small or large depends on the local behavior of $f$, which may change as the algorithm\nconverges. A reasonably robust trust-region algorithm must therefore be able to adaptively choose the trust-region radius.\n\nOur strategy for choosing an appropriate radius $r_{k+1}$ for the $(k+1)$-th iterate involves evaluating the accuracy\nof the model function at the $k$-th iterate. If the model was accurate and a large step was taken, we can optimistically choose $r_{k+1}$ to be larger\nthan $r_k$ in the hopes of achieving faster convergence.\nTo prevent the radius from growing too large, we set an overall bound $r_{max}$ on the trust-region radii.\nIf the model was very inaccurate, we make $r_{k+1}$ smaller than\n$r_k$, since the model function can't be trusted over such a large region. If the model was neither particularly accurate\nnor inaccurate, we simply choose $r_{k+1} = r_k$.\n\nWe measure the accuracy of the model by computing the following value:\n\\[\n\\rho_k = \\frac{f(x_k)-f(x_k+p_k)}{m_k(0) - m_k(p_k)}.\n\\]\nThis value is the ratio of the \\emph{actual reduction} to the \\emph{predicted reduction} in the objective function. The closer\n$\\rho_k$ is to $1$, the more accurate the model.\nNote that if $\\rho_k$ is negative or below a certain positive threshold $\\eta$,\nthen the point $x_k+p_k$ is a poor improvement over $x_k$ (and perhaps is worse).\nIn this case, we reject the new point and set $x_{k+1} = x_k$.\n\n\\subsection*{The Trust-Region Algorithm}\nWe now combine the two steps of minimizing the model function and choosing the trust-region radius to build the algorithm.\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Trust-Region Algorithm}{}\n    \\State Choose initial point $x_0$, initial radius $r_0$, and threshold $\\eta \\in [0,0.25)$.\n    \\For{$k=0, 1, 2, \\ldots$}\n        \\State Solve the sub-problem in Equation \\ref{eq:step}.\n        \\State Compute $\\rho_k$.\n        \\If{$\\rho_k < 0.25$}\n            \\State $r_{k+1} = 0.25r_k$\n\n        \\Else\n            \\If{$\\rho_k > 0.75$ and $\\|p_k\\| = r_k$}\n                \\State $r_{k+1} = \\min(2r_k, r_{max})$\n            \\Else\n                \\State $r_{k+1} = r_k$\n            \\EndIf\n        \\EndIf\n        \\If{$\\rho_k > \\eta$}\n            \\State $x_{k+1} = x_k + p_k$\n        \\Else\n            \\State $x_{k+1} = x_k$\n        \\EndIf\n    \\EndFor\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Trust-Region Algorithm}\n\\label{alg:trustregion}\n\\end{algorithm}\nIn practice, we halt the algorithm once $\\|\\nabla f(x_k)\\|$ is less than some threshold value.\n\\begin{problem}\nImplement the trust-region algorithm using the following function declaration.\n\\begin{lstlisting}\ndef trustRegion(f,grad,hess,subprob,x0,r0,rmax,eta,gtol=1e-5):\n    \"\"\"\n    Minimize a function using the trust-region algorithm.\n\n    Parameters\n    ----------\n    f : callable function object\n        The objective function to minimize\n    g : callable function object\n        The gradient (or approximate gradient) of the objective function\n    hess : callable function object\n        The hessian (or approximate hessian) of the objective function\n    subprob: callable function object\n        Returns the step p_k\n    x0 : numpy array of shape (n,)\n        The initial point\n    r0 : float\n        The initial trust-region radius\n    rmax : float\n        The max value for trust-region radii\n    eta : float in [0,0.25)\n        Acceptance threshold\n    gtol : float\n        Convergence threshold\n\n    Returns\n    -------\n    x : the minimizer of f\n\n    Notes\n    -----\n    The functions f, g, and hess should all take a single parameter.\n    The function subprob takes as parameters a gradient vector, hessian matrix, and radius.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\\end{problem}\n\n\\subsection*{Solving the Sub-problem: the Dogleg Method}\nOur trust-region algorithm is as yet incomplete, since we do not have a viable means solving the subproblem\ngiven by Equation \\ref{eq:step}.\nWe may be tempted to search for the true minimizer of the model function over the trust region, but it turns out\nthat we can get away with just an approximate minimizer.\nWe will employ the ``dogleg\" method when selecting an approximate minimizer of the model function.\nThis method works by minimizing the model function along a particular path extending from the origin out\nto the boundary of the trust region.\nThis path is piecewise linear and has a shape vaguely reminiscent of a dog's leg, which explains the peculiar name of the method.\n\nTo calculate the dogleg minimizer of the model function, we first solve the unconstrained minimizer of the model function,\n\\[\np^B = -B_k^{-1}\\nabla f(x_k).\n\\]\nWe then calculate the direction of steepest descent for the model function, given by\n\\[\np^U = -\\frac{\\nabla f(x_k)^T\\nabla f(x_k)}{\\nabla f(x_k)^TB_k\\nabla f(x_k)}\\nabla f(x_k).\n\\]\nWe define the dogleg path using these two points as follows:\n\\[\n\\gamma(\\tau) =  \\left\\{\n     \\begin{array}{lr}\n       \\tau p^U, & 0\\leq \\tau \\leq 1\\\\\n       p^U+(\\tau-1)(p^B-p^U), & 1\\leq \\tau\\leq 2\n     \\end{array}\n   \\right.\n\\]\n\n\\begin{figure}\n\\centering\n    \\begin{subfigure}[b]{0.3\\textwidth}\n            \\includegraphics[width=\\textwidth]{dogleg3}\n            \\caption{Dogleg path completely within the trust region.}\n            \\label{fig:dl3}\n    \\end{subfigure}%\n    ~ %add desired spacing between images, e. g. ~, \\quad, \\qquad, \\hfill etc.\n      %(or a blank line to force the subfigure onto a new line)\n    \\begin{subfigure}[b]{0.3\\textwidth}\n            \\includegraphics[width=\\textwidth]{dogleg1}\n            \\caption{Intersection in the first leg of the path.}\n            \\label{fig:dl1}\n    \\end{subfigure}\n    ~ %add desired spacing between images, e. g. ~, \\quad, \\qquad, \\hfill etc.\n      %(or a blank line to force the subfigure onto a new line)\n    \\begin{subfigure}[b]{0.3\\textwidth}\n            \\includegraphics[width=\\textwidth]{dogleg2}\n            \\caption{Intersection in the second leg of the path.}\n            \\label{fig:dl2}\n    \\end{subfigure}\n    \\caption{Relationships between the dogleg path (black solid line),\n    the trust region boundary (red dashed circle), and the dogleg minimizer (blue dot).}\n    \\label{fig:dogleg}\n\\end{figure}\n\nIt can be shown that the model function decreases along this path. Thus,\nthe dogleg minimizer is either the endpoint of the path if it lies completely within the trust region,\nor the point of intersection between the path and the boundary of the trust region.\nSee Figure \\ref{fig:dogleg} for an illustration of the three salient cases. We consider each case in turn.\n\\begin{itemize}\n\\item\nWhen the path lies completely within the trust region, the dogleg minimizer is simply the endpoint, namely $p^B$.\nThis is the case when $\\|p^B\\| \\leq r_k$. See Figure \\ref{fig:dl3}.\n\\item\nWhen the path intersects the boundary of the trust region in the first line segment, the dogleg minimizer is\n$r_kp^U/\\|p^U\\|$.\nThis is the case when $\\|p^U\\| \\geq r_k$. See Figure \\ref{fig:dl1}.\n\\item\nWhen the path intersects the boundary of the trust region in the second line segment, the dogleg minimizer is\ngiven by $p^U + (\\tau^*-1)(p^B-p^U)$, where $\\tau^*$ satisfies the quadratic equation\n\\[\n\\|p^U + (\\tau^*-1)(p^B-p^U)\\|^2 = r_k^2.\n\\]\nSee Figure \\ref{fig:dl2}.\n\\end{itemize}\n\n\\begin{problem}\nImplement the dogleg method using the following function declaration.\nRemember to avoid calculating the inverse of a matrix.\n\\begin{lstlisting}\ndef dogleg(gk,Bk,rk):\n    \"\"\"\n    Calculate the dogleg minimizer of the quadratic model function.\n\n    Parameters\n    ----------\n    gk : ndarray of shape (n,)\n        The current gradient of the objective function\n    Bk : ndarray of shape (n,n)\n        The current (or approximate) hessian\n    rk : float\n        The current trust region radius\n\n    Returns\n    -------\n    pk : ndarray of shape (n,)\n        The dogleg minimizer of the model function.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\n\n\\end{problem}\n\nTest your implementation of the trust-region algorithm on the Rosenbrock function contained the {\\tt scipy.optimize} module.\nCompare your answer with that obtained by SciPy's trust-region implementation. The code to accomplish this, together with the\ncorrect results, is given below.\n\\begin{lstlisting}\n>>> x = np.array([10.,10])\n>>> rhat=2.\n>>> r=.25\n>>> eta=1./16\n>>> tol=1e-5\n>>> opts = {'initial_trust_radius':r, 'max_trust_radius':rhat, 'eta':eta, 'gtol':tol}\n>>> sol1 = op.minimize(op.rosen, x, method='dogleg', jac=op.rosen_der, hess=op.rosen_hess, options=opts)\n>>> sol2 = trustRegion(op.rosen, op.rosen_der, op.rosen_hess, dogleg, x, r, rhat, eta, gtol=tol)\n>>> print np.allclose(sol1.x, sol2)\nTrue\n\\end{lstlisting}\n\n\\subsection*{Solving Systems of Nonlinear Equations}\nTrust-region methods can be used to find solutions of systems of nonlinear equations, which arise in applications across science and engineering.\nSuppose we have a vector function $r : \\mathbb{R}^n \\rightarrow \\mathbb{R}^n$, written as\n\\[\nr(x) = \\begin{bmatrix}\nr_1(x)\\\\\nr_2(x)\\\\\n\\vdots\\\\\nr_n(x)\n\\end{bmatrix},\n\\]\nwhere each $r_i$ is a nonlinear smooth function mapping from $\\mathbb{R}^n$ into $\\mathbb{R}$.\nOur goal is to find $x \\in \\mathbb{R}^n$ that satisfies $r(x) = 0$; such an $x$ is called a solution\nor root of the nonlinear system. In general, there may be several roots (even infinitely many), or there\nmay be none at all. Solving the equations by hand can range from arduous to impossible, so we turn\nto trust-region methods for help.\n\nIn order to use our trust-region method to find the roots of a system\nof equations, we need to come up with an objective function whose minima correspond to roots of the\nsystem. As such, we consider the \\emph{merit function}\n\\[\nf(x) = \\frac{1}{2}\\|r(x)\\|_2^2 = \\frac{1}{2}\\sum_{i=1}^nr_i(x)^2,\n\\]\nwhich, roughly speaking, measures how close a point $x$ is to being a root of $r$. Note that $f(x) = 0$\nif and only if $r(x) = 0$. Thus, if we can successfully find a global minimum of $f$, we will have\nfound a root to the nonlinear system.\n\nNow that we have an objective function, we need to create a quadratic model function. If we let\n$J_k$ be the Jacobian matrix of $r$ at the point $x_k$, i.e.\n\\[\nJ_k = \\begin{bmatrix}\n\\nabla r_1(x_k)^T\\\\\n\\nabla r_2(x_k)^T\\\\\n\\vdots\\\\\n\\nabla r_n(x_k)^T\n\\end{bmatrix},\n\\]\nthen we can write the gradient $\\nabla f(x_k) = J_k^Tr(x_k)$ and the Hessian $B_k = J_k^TJ_k$.\nWe can now use the same model function described earlier.\n\nLet's work through an example. Consider the system\n\\[\nr(x,y) = \\begin{bmatrix}\n-\\sin x\\cos y - 2\\cos x\\sin y\\\\\n-\\sin y\\cos x - 2\\cos y\\sin x\n\\end{bmatrix}.\n\\]\nObserve that the Jacobian takes the form\n\\[\nJ(x) = \\begin{bmatrix}\n-\\cos x\\cos y + 2\\sin x\\sin y & \\sin x\\sin y - 2\\cos x\\cos y\\\\\n\\sin y\\sin x - 2\\cos y\\cos x & -\\cos y\\cos x + 2\\sin y \\sin x\n\\end{bmatrix}.\n\\]\nIn Python, we initialize all of the requisite functions and then find a root as follows:\n\\begin{lstlisting}\n>>> # define the system of equations\n>>> def r(x):\n>>>     return np.array([-sin(x[0])*cos(x[1]) - 2*cos(x[0])*sin(x[1]),\n>>>                      -sin(x[1])*cos(x[0]) - 2*cos(x[1])*sin(x[0])])\n>>>\n>>> # define the merit function\n>>> def f(x):\n>>>     return .5*(r(x)**2).sum()\n>>>\n>>> # define the jacobian function\n>>> def J(x):\n>>>     return np.array([[-cos(x[0])*cos(x[1]) + 2*sin(x[0])*sin(x[1]),\n>>>                       sin(x[0])*sin(x[1]) - 2*cos(x[0])*cos(x[1])],\n>>>                      [sin(x[1])*sin(x[0]) - 2*cos(x[1])*cos(x[0]),\n>>>                       -cos(x[1])*cos(x[0]) + 2*sin(x[1])*sin(x[0])]])\n>>>\n>>> # define the gradient function\n>>> def g(x):\n>>>     return J(x).dot(r(x))\n>>>\n>>> # define the Hessian function\n>>> def B(x):\n>>>     return J(x).T.dot(J(x))\n>>>\n>>> # set trust-region parameters\n>>> rhat=2.\n>>> rr=.25\n>>> eta=1./16\n>>> tol=1e-5\n>>> # set initial point\n>>> x = np.array([3.5, -2.5])\n>>> # find a minimizer of f\n>>> xstar = trustRegion(f,g,B,dogleg,x,rr,rhat,eta,gtol=tol)\n>>> print xstar\n[ 3.14159265 -3.14159265]\n>>> # verify that it is a root of r\n>>> print r(xstar)\n[ -7.75116117e-09   7.75147025e-09]\n\\end{lstlisting}\n\nOf course, we are not guaranteed to always find a root, as convergence depends on the choice of initial point.\nHowever, by running the algorithms with several randomly selected starting points, we are more likely to \nbe successful.\n\n\\begin{problem}\nSome problem involving system of nonlinear equations. Consult http://www-sop.inria.fr/coprin/logiciels/ALIAS/Benches/ \nfor ideas.\n\\end{problem}\n", "meta": {"hexsha": "a99ed3d60addfc979f123b2ba32ddefe2f029ce5", "size": 15910, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/TrustRegion/TrustRegion.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/TrustRegion/TrustRegion.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/TrustRegion/TrustRegion.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 40.7948717949, "max_line_length": 150, "alphanum_fraction": 0.6874921433, "num_tokens": 4692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455085, "lm_q2_score": 0.8976952859490985, "lm_q1q2_score": 0.8276048890144461}}
{"text": "\\chapter{Linear Regression}\n\\label{chap:linreg}\n\nIn regression problems, we take a variable (or multiple variables) as input, and try to fit the output to a continuous expected result function. \n\n\n\n\\section{Univariate Linear Regression}\n\\label{chaplinreg-sect:univar}\n\nIn univariate linear regression, we want to predict a single output value $\\hat{y}$ from a single input value $x$. Since this is supervised learning, we already have an idea about what the input/output relationship should look like. \n\n\n\n\\subsection{The Hypothesis Function}\n\\label{chaplinreg-sectunivar-subsect:hypfunct}\n\nImagine we have a problem where the input is $x$ and the output is $y$. In order to do machine learning, there should exist a relationship (a pattern) between the input and output variables. Let's say this function is $y = f\\left( x \\right)$. In this situation, $f$ is known as the target function. However, this function $f$ is unknown to us, so we need to try and guess what it is. To do that, we form a \\textit{hypothesis} function $h\\left( x \\right)$ that approximates the unknown $f\\left( x \\right)$. \n\nFor single variable linear regression, our hytothesis function takes two parameters: $\\theta_0$ and $\\theta_1$. As such, we often write it as $h_\\theta\\left( x \\right)$, and it takes the form\n\\begin{equation}\n\\hat{y} = h_\\theta\\left( x \\right) = \\theta_0 + \\theta_1 x\n\\end{equation}\n\nNote that this is the equation of a straight line ($y = mx + b$). We're trying to find the values for $\\theta_0$ and $\\theta_1$ to get our estimated output $\\hat{y}$. In other words, we're trying to determine the function $h_\\theta$ that maps our input data (the $x$'s) to our output data (the $y$'s). \n\nSuppose we have the following set of training data:\n\n\\begin{center}\n\\begin{tabular}{c | c}\n\\textbf{Input } $x$ & \\textbf{Output } $y$ \\\\\n\\hline\n0 & 4 \\\\\n1 & 7 \\\\\n2 & 7 \\\\\n3 & 8 \\\\\n\\end{tabular}\n\\end{center}\n\nWe can plot these points, as shown in Figure \\ref{fig:linregeg-justpoints}. Let's make a random guess at our hypothesis function: $\\theta_0  = 2$ and $\\theta_1 = 2$, making our hypothesis function $h_\\theta\\left( x \\right) = 2 + 2x$, as shown in Figure \\ref{fig:linregeg-hypotguess1}.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n\t\t\\centering\n\t\t\\graphicspath{{./Figures/}}\n\t\t\\includegraphics[scale=0.5]{linreg_eg1_plotpoints_noline.pdf}\n\t\t\\caption{Plotting our example points.}\n\t\t\\label{fig:linregeg-justpoints}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n\t\t\\centering\n\t\t\\graphicspath{{./Figures/}}\n\t\t\\includegraphics[scale=0.5]{linreg_eg1_plotpoints_line1.pdf}\n\t\t\\caption{Plotting our example points.}\n\t\t\\label{fig:linregeg-hypotguess1}\n\t\\end{subfigure}\n\\end{figure}\n\nUsing this hypothesis function for $x = 1$, we have $\\hat{y} = h_\\theta\\left( 1 \\right) = 2 + 2 \\cdot 1 = 4$. In this case, $\\hat{y} = 4$, but $y = 7$, so mabe this isn't the best fit hypothesis.  \n\n\n\\subsection{The Cost Function}\n\\label{chaplinreg-sectunivar-subsect:costfxn}\n\nThe cost function,\\footnote{The cost function can also be called the loss function.} is a function used for parameter estimation, where the input to the cost function is some function of the difference between estimated and the true values for an instance of data. In this case, we can use the cost function to measure the accuracy of our hypothesis function. \n\nThe cost function looks at something similar to an average\\footnote{It's actually something a bit fancier than a standard average.} of all the results of the hypothesis with inputs from the $x$'s compared to the actual output $y$'s. We define our cost function as follows:\n\n\\begin{equation}\nJ\\left( \\theta_0, \\theta_1 \\right) = \\frac{1}{2m} \\sum_{i=1}^m \\left(\\hat{y}_i - y_i \\right)^2 = \\frac{1}{2m} \\sum_{i=1}^m \\left(h_\\theta\\left( x_i \\right) - y_i \\right)^2\n\\end{equation}\n\nThis is known as the \\textbf{mean squared error}. If we set $\\bar{x}$ equal to the mean of the squares all the $ h_\\theta \\left( x_i \\right) - y_i$, then the cost function is just the mean of $\\bar{x}$. The term $\\frac{1}{2m}$ is merely a convenience for the computation of gradient descent, which we'll see very shortly. \n\n\n\\subsection{Gradient Descent}\n\\label{chaplinreg-sectunivar-subsect:graddsc}\n\nWe now have our hypothesis function defined, as well as a way of measuring how well it fits the data. Now, we have to estimate the parameters in the hypothesis function, and that's where gradient descent comes in. \n\nLet's graph our cost function as a function of the parameter estimates. This can be somewhat confusing, as we are moving up to a higher level of abstraction. We are not graphing $x$ and $y$ itself, but the parameter range of our hypothesis function and the cost resulting from selecting particular sets of parameters. We put $\\theta_0$ on the $x$-axis, and $\\theta_1$ on the $y$-axis, with the cost function on the vertical $z$-axis.\n\n\\begin{figure}[h] %  figure placement: here, top, bottom, or page\n   \\centering\n    \\graphicspath{{./Figures/}} %Use this to import an image from a subfolder.\n   \\includegraphics[scale=0.4]{linreg_eg2_cost_func_over_thetas.pdf} \n   \\caption[]{Plot of the cost function $J\\left(\\theta_0, \\theta_1 \\right)$ using our hypothesis $h_\\theta\\left( x \\right)$.}\n   %If using \\listoffigures command, then use \\caption[short]{long}, where the short caption will appear in the list of figures, and the long caption will appear next to the figure.\n   \\label{s}\n\\end{figure}\n\nOur goal is to take the parameters $\\theta_0$ and $\\theta_1$ for when the cost function is at its minimum. We can calculate this value by taking the derivative of the cost function, which gives us direction of the steepest gradient to move towards. Take a step in that direction, and repeat.The step size is determined by the parameter $\\alpha$, which is called the \\textbf{learning rate}. The gradient descent algorithm is:\n\n\\textbf{Repeat until convergence:}\n\\begin{equation}\n\\theta_j := \\theta_j - \\alpha \\frac{\\partial}{\\partial \\theta_j} J\\left( \\theta_0, \\theta_1 \\right)\n\\end{equation}\n\nwhere $j = 0, 1$ represents the feature index number. \n\n\\subsubsection{Gradient Descent for Linear Regression}\nWhen specifically applied to the case of univariate linear regression, we can derive another form of the gradient descent equation. If we substitute our actual hypothesis function and cost function, we can modify the equation to\n\n\\textbf{Repeat until convergence: \\{ }\n\\begin{equation}\n\\begin{aligned}\n\\theta_0 &:= \\theta_0 - \\alpha \\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left( x_i \\right) - y_i \\right) \\\\\n\\theta_1 &:= \\theta_1 - \\alpha \\frac{1}{m} \\sum_{i=1}^m \\left( \\left( h_\\theta \\left( x_i \\right) - y_i \\right) x_i \\right)\n\\end{aligned}\n\\end{equation}\n\n\\textbf{ \\} }\n\n\\noindent where $m$ is the size of the training set, $\\theta_0$ is a constant that will be changing simultaneously with $\\theta_1$, and $x_1$, $y_i$ are values of the given training set. Note that we have separated out the two cases for $\\theta_j$ into separate equations for $\\theta_0$ and $\\theta_1$, and that for $\\theta_1$ we are multiplying $x_i$ at the end due to the derivative. \n\n\n\\section{Multivariate Linear Regression}\n\\label{chaplinreg-sect:multivarreg}\nLet's start by looking at some sample housing data with multiple features. \\\\\n\n\\begin{tabular}{c | c | c | c | c }\nSize (feet$^2$) & \\# of Bedrooms & \\# of Floors & Age (years) & Price (in 1000's of \\$) \\\\ \n$x_1$ & $x_2$ & $x_3$ & $x_4$ & $y$ \\\\ \\hline\n2104 & 5 & 1 & 45 & 460 \\\\\n1416 & 3 & 2 & 40 & 232 \\\\\n1534 & 3 & 2 & 30 & 315 \\\\\n852 & 2 & 1 & 36 & 178 \\\\ \n560 & 1 & 1 & 12 & 155\n\\end{tabular}\n\nIn this, we can introduce some notation:\n\\begin{itemize*}\n\\item The variables $x_1$, $x_2$, etc. are the features. \n\\item The variable $y$ is the output variable.\n\\item The number of input features is denoted $n$. In this example, $n = 4$. \n\\item $m$ specifies the number of training examples (rows). Here, $m = 5$.\n\\item $x^{\\left( i \\right)}$ is the input (features) of the $i^{th}$ training example. So $x^{\\left( 2 \\right)}$ is the column vector $[1416, 3, 2, 40, 232]$. \n\\item $x_j^{\\left( i \\right)}$ is feature $j$ in the $i^{th}$ training example. Here, $x_1^{\\left( 4 \\right)} = 852$. \n\\end{itemize*}\n\nAt this point, we can define the multivariable form of the hypothesis function for linear regression:\n\\begin{equation}\nh_\\theta\\left( x \\right) = \\theta_0 + \\theta_1 x_1 + \\theta_2 x_2 + \\theta_3 x_3 + \\cdots + \\theta_n x_n\n\\end{equation}\n\nFor convenience of notation, we will define $x_0 = 1$ for all feature vectors ($x_0^{\\left( i \\right)} = 1$). So now, if we include $x_0$, our hypothesis function takes the form:\n\n\\begin{equation}\nh_\\theta\\left( x\\right) = \\sum_{i=0}^n \\theta_i x_i\n\\end{equation}\nNow, we can also write the $x$ values and $\\theta$ values as vectors:\n$$\n\\vec{x} = \\left[ \\begin{array}{c}\nx_0 \\\\\nx_1 \\\\\nx_2 \\\\\n\\vdots \\\\\nx_n\n\\end{array} \\right] \\in \\mathbb{R}^{n+1} \n~~\\mbox{\\;\\;\\;\\;\\;\\;\\;\\;\\;\\; and \\;\\;\\;\\;\\;\\;\\;\\;\\;\\;}~~\n\\vec{\\theta} = \\left[\\begin{array}{c}\n\\theta_0 \\\\\n\\theta_1 \\\\\n\\theta_2 \\\\\n\\vdots \\\\\n\\theta_n \\end{array}\\right] \\in \\mathbb{R}^{n+1}\n$$\nIn vector notation, this is \n\\begin{equation}\nh_\\theta\\left( x \\right) = \\vec{\\theta}^\\intercal\\vec{x}\n\\end{equation}\nwhere we transpose $\\vec{\\theta}$ into a row vector so we're able to take the inner product. \n\nNow that we have our vector $\\vec{\\theta} \\in \\mathbb{R}^{n+1}$, the cost function is\n\\begin{equation}\nJ\\left(\\vec{\\theta}\\right) = \\frac{1}{2m}\\sum_{i=1}^m \\left( h_\\theta\\left( x^{\\left( i \\right)} \\right) - y^{\\left( i \\right)} \\right)^2\n\\end{equation}\n\n\\subsection{Gradient Descent for Multiple Variables}\nUsing our expanded hypothesis and cost functions, the gradient descent algorithm becomes:\n\n\n\\textbf{Repeat until convergence: \\{ }\n\\begin{equation}\n\\theta_j := \\theta_j - \\alpha\\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left( x^{\\left(i\\right)} \\right) - y^{\\left(i\\right)} \\right) \\cdot x_j^{\\left( i \\right)} ~~\\mbox{\\;\\;\\;\\;\\;\\;\\;\\;\\;\\; for } j = 0, 1, \\cdots, n\n\\end{equation}\n\\textbf{ \\} }\n\n\\subsection{Feature Scaling}\nWhen features are in very different ranges, it can slow down gradient descent dramatically (and also mess up our machine learning algorithms!), because $\\theta$ will descend quickly on small ranges and slowly on large ranges, and so will oscillate inefficiently down to the minimum. The way to prevent this is to ensure that all the ranges are roughly the same, ideally:\n$$ -1 \\leq x \\leq 1 $$\n\nTwo techniques to accomplish this are \\textbf{feature scaling} and \\textbf{mean normalization}. Feature scaling involved dividing the input values by the range (max value minus the min value) of the input variable, resulting in a new range of just 1. \n\n\\begin{figure}[h] %  figure placement: here, top, bottom, or page\n   \\centering\n    \\graphicspath{{./Figures/}} %Use this to import an image from a subfolder.\n   \\includegraphics[scale=0.6]{linreg_eg3_why_need_feature_scaling.pdf} \n   \\caption[]{When one feature is on a much larger scale than the other, the plot of the cost function will be stretched out in the direction of the larger feature. Here, imagine that $\\theta_1$ is the number of bedrooms a house has, and $\\theta_2$ is the size in square feet. }\n   %If using \\listoffigures command, then use \\caption[short]{long}, where the short caption will appear in the list of figures, and the long caption will appear next to the figure.\n   \\label{s}\n\\end{figure}\n\nMean normalization involves subtracting the mean value for an input variable from the value for that input variable, resulting in a new mean of zero. To implement both of these simultaneously, use the following formula:\n\\begin{equation}\nx_i := \\frac{x_i - \\mu_i}{s_i}\n\\end{equation}\nwhere $\\mu_i$ is the average value of $x_i$, and $s_i$ can either be the range ($x_\\text{max} - x_\\text{min}$) or the standard deviation. \n\n\n\\subsection{Tips for Gradient Descent}\nHere are some of Professor Andrew Ng's tips on implementing gradient descent. \n\n\\begin{enumerate}\n\\item \\textbf{Plot \\boldmath$J\\left(\\theta\\right)$.} If you plot $J\\left(\\theta\\right)$ as the ordinate and the number of iterations as the abscissa,\\footnote{On a Cartesian coordinate plane, the ordinate is the $y$-axis and the abscissa is the $x$-axis.} the graph should be steadily decreasing with increasing number of iterations. If $J\\left(\\theta\\right)$ ever increases, then $\\alpha$ is probably too large. \n\\item If $J\\left(\\theta\\right)$ decreases by less then $E$ in one iteration, where $E$ is some very small number, such as $10^{-3}$, then you can declare convergence. \n\\item For sufficiently small $\\alpha$, $J\\left(\\theta\\right)$ should decrease with every iteration. To choose $\\alpha$, try a range of values for $\\alpha$ with threefold increases, such as:\n$$ \\cdots \\to 0.001 \\to 0.003 \\to 0.01 \\to 0.03 \\to 0.1 \\to 0.3 \\to 1 \\to 3 \\to \\cdots$$\n\\item Sometimes, it's better to define new features instead of using the ones given. For example, if we have a house with features frontage\\footnote{The width of the land in the front of the house.} and depth,\\footnote{The width of the land on the side of the house.} you can combine these into a new feature called area, which is how much land the house sits on.\n\\end{enumerate}\n\n\n\\subsection{Polynomial Regression}\nThe form of the hypothesis doesn't necessarily need to be linear of that doesn't fit the data well. We can change the behavior or curve of our hypothesis function by making it quadratic, cubic, square root, or some other form. \n\nFor example, if our hypothesis function is $h_\\theta \\left(x \\right) = \\theta_0 + \\theta_1 x_1$, we can create additional features based on $x_1$, to get the quadratic function $h_\\theta\\left(x\\right) = \\theta_0 + \\theta_1 x_1 + \\theta_2 x_1^2$, or the cubic function $h_\\theta\\left(x\\right) = \\theta_0 + \\theta_1 x_1 + \\theta_2 x_1^2 + \\theta_3 x_1^3$.\n\nWhen thinking about nonlinear features, it is important to keep in mind that features scaling becomes even more essential than it was for linear regression. If $x_1$ has a range of $1$ to $1000$, the $x_1^2$ has a range of $1$ to $1,000,000$.\n\n\n\n\\section{Vectorized Equations}\nLet's revisit our housing example from \\S \\ref{chaplinreg-sect:multivarreg}. Recall that we looked at the the following example data, and we'll add an extra column for $x_0$ that always takes a value of one: \\\\\n\n\\begin{tabular}{c | c | c | c | c | c }\n{} & Size (feet$^2$) & \\# Bedrooms & \\# Floors & Age (years) & Price (in \\$1000's) \\\\ \n$x_0$ & $x_1$ & $x_2$ & $x_3$ & $x_4$ & $y$ \\\\ \\hline\n1 & 2104 & 5 & 1 & 45 & 460 \\\\\n1 & 1416 & 3 & 2 & 40 & 232 \\\\\n1 & 1534 & 3 & 2 & 30 & 315 \\\\\n1 & 852 & 2 & 1 & 36 & 178 \\\\ \n1 & 560 & 1 & 1 & 12 & 155\n\\end{tabular}\n\nFrom this, we construct a matrix $X$ that contains all of the features from the training data, and a vector $\\vec{y}$ of all the output data. \n\n$$\nX = \\left[\\begin{array}{ccccc}\n1 & 2104 & 5 & 1 & 45 \\\\\n1 & 1416 & 3 & 2 & 40 \\\\\n1 & 1534 & 3 & 2 & 30 \\\\\n1 & 852 & 2 & 1 & 36 \\\\ \n1 & 560 & 1 & 1 & 12\n\\end{array}\\right]\n~~\\mbox{\\;\\;\\;\\;\\;\\;\\;\\;\\;\\; and \\;\\;\\;\\;\\;\\;\\;\\;\\;\\;}~~\n\\vec{y} = \\left[\\begin{array}{c}\n460 \\\\ 232 \\\\ 315 \\\\ 178 \\\\ 155\n\\end{array}\\right]\n$$\n\nHere, $X$ is a $m \\times \\left(n + 1\\right)$ matrix, and $\\vec{y}$ is a $m$-dimensional vector. \n\nLet's go through this again, but this time in full abstraction. Say we have $m$ examples $\\left(x^{\\left(1\\right)}, y^{\\left(1\\right)}\\right),  \\left(x^{\\left(2\\right)}, y^{\\left(2\\right)}\\right), \\dots, \\left(x^{\\left(m\\right)}, y^{\\left(m\\right)}\\right)$ and each $x^{\\left(i\\right)}$ has $n$ features. Then, we have an $\\left(n + 1\\right)$-dimensional feature vector:\n\n\\begin{equation}\nx^{\\left(i\\right)} = \\left[\\begin{array}{c} x_0^{\\left(i\\right)} \\\\ x_1^{\\left(i\\right)} \\\\ x_2^{\\left(i\\right)} \\\\ \\vdots \\\\ x_n^{\\left(i\\right)} \\end{array}\\right] \\in \\mathbb{R}^{n+1}\n\\end{equation}\n\nThe matrix $X$, which is also called the \\textbf{design matrix}, is constructed by taking the transpose of each vector $x^{\\left(i\\right)}$. Each feature vector $x^{\\left(i\\right)}$ becomes a row in the design matrix. Just as previously, the output vector $\\vec{y}$ is obtained by taking all the labels and stacking them up into an $m$-dimensional vector, and the vector $\\vec{\\theta}$ is created from stacking all of the parameters for the hypothesis function. \n\n\\begin{equation}\nX = \\left[\\begin{array}{ccccc}\n-- & -- & \\left(x^{\\left(1\\right)}\\right)^\\intercal & -- & -- \\\\\n-- & -- & \\left(x^{\\left(2\\right)}\\right)^\\intercal & -- & -- \\\\\n-- & -- & \\left(x^{\\left(3\\right)}\\right)^\\intercal & -- & -- \\\\\n-- & -- & \\left(x^{\\left(4\\right)}\\right)^\\intercal & -- & -- \\\\\n-- & -- & \\vdots & -- & -- \\\\\n-- & -- & \\left(x^{\\left(m\\right)}\\right)^\\intercal & -- & -- \n\\end{array}\\right]\n~~\\mbox{\\;\\;\\;\\;\\;}~~\n\\vec{y} = \\left[\\begin{array}{c} y^{\\left(1\\right)} \\\\ y^{\\left(2\\right)} \\\\ y^{\\left(3\\right)} \\\\ y^{\\left(4\\right)} \\\\ \\vdots \\\\ y^{\\left(m\\right)} \\end{array}\\right]\n~~\\mbox{\\;\\;\\;\\;\\;}~~\n\\vec{\\theta} = \\left[\\begin{array}{c} \\theta_0 \\\\ \\theta_1 \\\\ \\theta_2 \\\\ \\theta_3 \\\\ \\vdots \\\\ \\theta_n \\end{array}\\right]\n\\end{equation}\n\nThink back to the start of this section when we separated our table into the design matrix $X$ and the output vector $y$. The design matrix is simply the data as stored in a table put into a matrix. \n\nIn our matrix notation for multivariate regression, the hypothesis function takes the form\n\\begin{equation}\nh_\\theta\\left(X\\right) = X\\vec{\\theta}\n\\end{equation}\nThis will always work since $X$ is an $m\\times n$ matrix, and $\\vec{\\theta}$ is an $n \\times 1$ vector. In a similar fashion, the cost function in matrix notation is\n\\begin{equation}\nJ\\left(\\vec{\\theta}\\right) = \\frac{1}{2m} \\left(X\\vec{\\theta} - \\vec{y}\\right)^\\intercal \\left(X\\vec{\\theta} - \\vec{y}\\right)\n\\end{equation}\n\nThe gradient descent rule can be expressed as\n\\begin{equation}\n\\vec{\\theta} := \\vec{\\theta} - \\alpha \\nabla J\\left(\\theta\\right) \n\\end{equation}\n\nThere $\\nabla$ is the gradient (vector derivative) operator. If we solve this out using our vectorized hypothesis function, we get\n\\begin{equation}\n\\vec{\\theta} := \\vec{\\theta} - \\frac{\\alpha}{m}X^\\intercal \\left(X\\vec{\\theta} - \\vec{y} \\right) \n\\end{equation}\n\n\\section{The Normal Equation}\nThe normal equation is a method of solving for the optimal $\\theta$ analytically, that is, without iteration. From calculus, if we want to find the minimum of a quadratic equation, we set the derivative equal to zero, and solve. We can apply the same logic to the cost function. If we take the partial derivative $\\partial/\\partial \\theta_j J\\left(\\theta\\right)$ and set this equal to zero for all values of $j$, we'll analytically solve for the minimum. \n\nThe derivation of the normal equation is fairly involved from a linear algebra perspective, so at this point just take it as a fact:\n\\begin{equation}\n\\vec{\\theta} = \\left( X^\\intercal X \\right) ^{-1} X^\\intercal \\vec{y}\n\\end{equation}\n\nWhen deciding whether to use gradient descent of the normal equation, consider the following:\n\n\\begin{tabular}{| l | l |} \\hline\n\\textbf{Gradient Descent} & \\textbf{Normal Equation} \\\\\n\\hline \\hline\nNeed to choose $\\alpha$ & No need to choose $\\alpha$ \\\\ \\hline\nNeeds many iterations & No need to iterate \\\\ \\hline\n$O\\left( kn^2 \\right)$ & $O\\left(n^3\\right)$, need to calculate $X^\\intercal X$ \\\\ \\hline\nWorks well when $n$ is large & Slow if $n$ is very large \\\\ \\hline\n\\end{tabular}\n\nWith the normal equation, computing the inverse has complexity $O\\left( n^3 \\right)$. If we have a large number of features, this will cause the normal equation to perform slowly. In practice, when $n$ exceeds $10,000$, it would probably be a good idea to use gradient descent. \n\n\\subsection{Normal Equation Noninvertibility}\nWhen implementing the normal equation, sometimes the matrix $X^\\intercal X$ is noninvertible. The common causes are:\n\\begin{itemize}\n\\item Redundant features, where two or more features are linearly dependent\n\\item Too many features (i.e. $m \\leq n$). In this case, delete some features or use regularization (which we'll get to later)\n\\end{itemize}\n\nWe typically avoid this problem by coding a pseudoinverse, instead of taking the actual inverse. \n\n\\section{Homework}\n\n\\subsection*{Introduction}\nIn this exercise, you will implement linear regression and get to see it work on data. Before starting on this programming exercise, we strongly recommend watching the video lectures and completing the review questions for the associated topics. To get started with the exercise, you will need to download the starter code and unzip its contents to the directory where you wish to complete the exercise. If needed, use the cd command in Octave/MATLAB to change to this directory before starting this exercise. You can also find instructions for installing Octave/MATLAB in the Environment Setup Instructions\" of the course website. \\\\\n\nTo start our code, we'll need to import a few modules that we'll be using.\n\n\\begin{minted}{python}\nimport numpy as np\nimport pandas as pd\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n%matplotlib inline\t# Use this if you're using Jupyter Notebooks\n\\end{minted}\n\n\n\\subsubsection*{Simple Octave/MATLAB Function}\nThe first part of {\\texttt ex1.m} gives you practice with Octave/MATLAB syntax and the homework submission process. In the file {\\texttt warmUpExercise.m}, you will find the outline of an Octave/MATLAB function. Modify it to return a 5 x 5 identity matrix.\n\n\\begin{minted}{python}\nA = np.eye(5)\nprint(A)\n\\end{minted}\n\n\n\\subsection*{Linear Regression with One Variable}\nIn this part of this exercise, you will implement linear regression with one variable to predict profits for a food truck. Suppose you are the CEO of a restaurant franchise and are considering different cities for opening a new outlet. The chain already has trucks in various cities and you have data for profits and populations from the cities. You would like to use this data to help you select which city to expand to next.\n\n\\subsubsection*{Plotting the Data}\nBefore starting on any task, it is often useful to understand the data by visualizing it. For this dataset, you can use a scatter plot to visualize the data, since it has only two properties to plot (profit and population). (Many other problems that you will encounter in real life are multi-dimensional and can't be plotted on a 2-d plot.)\n\nWe start by loading the data\n\\begin{minted}{python}\ndatafile = 'ex1\\\\ex1data1.txt'\ndf = pd.read_csv(datafile, header=None, names=['Population', 'Profit'])\n\\end{minted}\n\nThen we define a function to plot the data and call this function.\n\\begin{minted}{python}\ndef plot_data(x, y):\n    plt.figure(figsize=(10, 6))\n    plt.plot(x, y, '.', label='Training Data')\n    plt.xlabel(\"Population of City in 10,000s\")\n    plt.ylabel(\"Profit in $10,000s\")\n\nplot_data(df['Population'], df['Profit'])\n\\end{minted}\n\n\\begin{figure}[h] %  figure placement: here, top, bottom, or page\n\t\\centering\n\t\\graphicspath{{./Figures/}} %Use this to import an image from a subfolder.\n\t\\includegraphics[scale=0.5]{linreg_hw_2_1_plot_data.pdf} \n%\t\\caption[]{One-vs-all classification. We're selecting one class to be our positive class, and the rest all become the negative class.}\n\t\\label{linreg_hw_2_1_plot_data.pdf}\n\\end{figure}\n\n\\subsection*{Gradient Descent}\nIn this part, you will fit the linear regression parameters $\\theta$ to our dataset using gradient descent.\n\n\\subsection*{Update Equations}\nThe objective of linear regression is to minimize the cost function\n$$\nJ\\left( \\theta \\right) = \\frac{1}{2m} \\sum_{i=1}^m \\left( h_\\theta \\left( x^{\\left( i\\right)} \\right) - y^{\\left( i \\right)} \\right)^2\n$$\nwhere $h_\\theta\\left( x \\right)$ is the hypothesis given by the linear model\n$$\nh_\\theta\\left( x \\right) = \\theta^\\intercal x = \\theta_0 + \\theta_1 x_1\n$$\nRecall that the parameters of your model are the $\\theta_j$ values. These are the values you will adjust to minimize cost $J(\\theta)$. One way to do this is to use the batch gradient descent algorithm. In batch gradient descent, each iteration performs the update\n$$\n\\theta_j := \\theta_j - \\alpha\\frac{1}{m}\\sum_{i=1}^m \\left( h_\\theta\\left( x^{\\left( i\\right)} \\right) - y^{\\left(i\\right)}\\right) x_j^{\\left(i\\right)} \\;\\;\\;\\;\\;\\;\\;\\;\\;\\; \\text{simultaneously update } \\theta_j \\text{ for all } j \\text{.}\n$$\nWith each step of gradient descent, your parameters $\\theta_j$ come closer to the optimal values that will achieve the lowest cost $J(\\theta)$.\n\n\\subsection*{Implementation}\nIn the following lines, we add another dimension to our data to accommodate the $\\theta_0$ intercept term.\n\n\\begin{minted}{python}\n# set the number of training examples\nm = len(df['Population'])\n\n# create an array from the dataframe (missing column for x_0 values)\nX = df['Population'].values\n\n# add in the first column of the array for x_0 values\nX = X[:, np.newaxis]\nX = np.insert(X, 0, 1, axis=1)\n\ny = df['Profit'].values\ny = y[:, np.newaxis]\n\\end{minted}\n\n\\subsection*{Computing the Cost $J\\left(\\theta\\right)$}\nNow, we can define our actual hypothesis function for linear regression with a single variable. \n\\begin{minted}{python}\n# define the hypothesis\ndef h(theta, X):\n    \"\"\"Takes the dot product of the matrix X and the vector theta,\n    yielding a predicted result.\n    \"\"\"\n    return np.dot(X, theta)\n\n\ndef compute_cost(X, y, theta):\n    \"\"\"Takes the design matrix X and output vector y, and computes the cost of\n    the parameters stored in the vector theta.\n    \n    The dimensions must be as follows:\n    - X must be m x n\n    - y must be m x 1\n    - theta must be n x 1\n    \n    \"\"\"\n    m = len(y)\n    \n    J = 1 / (2*m) * np.dot((np.dot(X, theta) - y).T, (np.dot(X, theta) - y))\n    return J\n\\end{minted}\n\n\nOnce you have completed the function, the next step % {\\texttt compute_cost} \nonce using $\\theta$  initialized to zeros, and you will see the cost printed to the screen. You should expect to see a cost of 32.07.\n\n\\begin{minted}{python}\n# define column vector theta = [[0], [0]]\ntheta = np.zeros((2, 1))\n\n# compute the cost function for our existing X and y, with our new theta vector\n# verify that the cost for our theta of zeros is 32.07\ncompute_cost(X, y, theta)\n\\end{minted}\n\nThis gives us our expected value of $32.07273388$.\n\n\\subsection*{Gradient Descent}\nNow we'll actually implement the gradient descent algorithm. Keep in mind that the cost $J(\\theta)$ is parameterized by the vector $\\theta$, not $X$ and $y$. That is, we minimize $J(\\theta)$ by changing $\\theta$. We initialize the initial parameters to 0 and the learning rate alpha to 0.01.\n\n\\begin{minted}{python}\ndef gradient_descent(X, y, theta, alpha, num_iters):\n    m = len(y)\n    J_history = []\n    theta_history = []\n    \n    for i in range(num_iters):\n        J_history.append(float(compute_cost(X, y, theta)))\n        theta_history.append(theta)\n        theta = theta - (alpha / m) * np.dot(X.T, (np.dot(X, theta) - y))\n    \n    return theta, J_history, theta_history\n\n\n# set up some initial parameters for gradient descent\ntheta_initial = np.zeros((2, 1))\niterations = 1500\nalpha = 0.01\n\n\n# run our gradient descent function\ntheta_final, J_hist, theta_hist = gradient_descent(X, y, \n                                                   theta_initial, \n                                                   alpha, iterations)\n\n\\end{minted}\n\n\n\\begin{figure}[h] %  figure placement: here, top, bottom, or page\n\t\\centering\n\t\\graphicspath{{./Figures/}} %Use this to import an image from a subfolder.\n\t\\includegraphics[scale=0.5]{linreg_hw_2_3_plot_lin_reg.pdf} \n%\t\\caption[]{One-vs-all classification. We're selecting one class to be our positive class, and the rest all become the negative class.}\n\t\\label{linreg_hw_2_3_plot_lin_reg.pdf}\n\\end{figure}\n\n\n\\subsection*{Visualizing $J\\left(\\theta\\right)$}\nAfter running the batch gradient descent algorithm, we can plot the convergence of $J\\left(\\theta\\right)$ over the number of iterations.\n\\begin{minted}{python}\ndef plot_cost_convergence(J_history):\n    abscissa = list(range(len(J_history)))\n    ordinate = J_history\n\n    plt.figure(figsize=(10, 6))\n    plt.plot(abscissa, ordinate, '.')\n    plt.title('Convergence of the Cost Function', fontsize=18)\n    plt.xlabel('Iteration Number', fontsize=14)\n    plt.ylabel('Cost Function', fontsize=14)\n    plt.xlim(min(abscissa) - max(abscissa) * 0.05, 1.05 * max(abscissa))\n\n\nplot_cost_convergence(J_hist)\nplt.ylim(4.3, 6.9)\n\\end{minted}\n\n\\begin{figure}[h] %  figure placement: here, top, bottom, or page\n\t\\centering\n\t\\graphicspath{{./Figures/}} %Use this to import an image from a subfolder.\n\t\\includegraphics[scale=0.5]{linreg_hw_2_4_viz_j_of_theta.pdf} \n%\t\\caption[]{One-vs-all classification. We're selecting one class to be our positive class, and the rest all become the negative class.}\n\t\\label{linreg_hw_2_4_viz_j_of_theta.pdf}\n\\end{figure}\n\nNow, let's plot the cost minimization on the surface of $J\\left(\\theta\\right)$. \n\n\\begin{minted}{python}\nfrom mpl_toolkits.mplot3d import axes3d, Axes3D\nfrom matplotlib import cm\n\ntheta_0_hist = [x[0] for x in theta_hist]\ntheta_1_hist = [x[1] for x in theta_hist]\ntheta_hist_end = len(theta_0_hist) - 1\n\nfig = plt.figure(figsize=(12, 12))\nax = fig.gca(projection='3d')\n\ntheta_0_vals = np.linspace(-10, 10, 100)\ntheta_1_vals = np.linspace(-1, 4, 100)\n\ntheta1, theta2, cost = [], [], []\n\nfor t0 in theta_0_vals:\n    for t1 in theta_1_vals:\n        theta1.append(t0)\n        theta2.append(t1)\n        theta_array = np.array([[t0], [t1]])\n        cost.append(compute_cost(X, y, theta_array))\n\nscat = ax.scatter(theta1, theta2, cost, \n                  c=np.abs(cost), cmap=plt.get_cmap('rainbow'))\n\nplt.plot(theta_0_hist, theta_1_hist, J_hist, 'r',\n         label='Cost Minimization Path')\nplt.plot(theta_0_hist[0], theta_1_hist[0], J_hist[0], 'ro',\n         label='Cost Minimization Start')\nplt.plot(theta_0_hist[theta_hist_end],\n         theta_1_hist[theta_hist_end],\n         J_hist[theta_hist_end], 'co', label='Cost Minimization Finish')\n\nplt.xlabel(r'$\\theta_0$', fontsize=24)\nplt.ylabel(r'$\\theta_1$', fontsize=24)\nplt.title(r'Cost Function Minimization', fontsize=24)\nplt.legend()\n\\end{minted}\n\n\\begin{figure}[h] %  figure placement: here, top, bottom, or page\n\t\\centering\n\t\\graphicspath{{./Figures/}} %Use this to import an image from a subfolder.\n\t\\includegraphics[scale=0.5]{linreg_hw_2_4_plot_surface_plot.pdf} \n%\t\\caption[]{One-vs-all classification. We're selecting one class to be our positive class, and the rest all become the negative class.}\n\t\\label{linreg_hw_2_4_plot_surface_plot.pdf}\n\\end{figure}\n\n\\section{Python Labs: Coding Linear Regression}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "81d4d13145d754fd20e189c8409d0ffc0b994479", "size": 30535, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX Notes/Chapters/2-Linear_Regression.tex", "max_stars_repo_name": "Sz593/coursera_ml_notes", "max_stars_repo_head_hexsha": "098e0bd81759312b2c14640772112e9accb63a93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LaTeX Notes/Chapters/2-Linear_Regression.tex", "max_issues_repo_name": "Sz593/coursera_ml_notes", "max_issues_repo_head_hexsha": "098e0bd81759312b2c14640772112e9accb63a93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LaTeX Notes/Chapters/2-Linear_Regression.tex", "max_forks_repo_name": "Sz593/coursera_ml_notes", "max_forks_repo_head_hexsha": "098e0bd81759312b2c14640772112e9accb63a93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.8937908497, "max_line_length": 634, "alphanum_fraction": 0.7072867202, "num_tokens": 9085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.903294206053042, "lm_q1q2_score": 0.8275165019270192}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 8}\n\nAssume you had some kind of super-hardware that, when given two lists of length $n$ that are sorted, merges them into one sorted list, and takes only $n^c$ steps where $c \\geq 0$.\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Write down a recursive algorithm that uses this hardware to sort lists of length $n$.\n\\item Write down a recurrence to describe the run time.\n\\item For what values of $c$ does this algorithm perform substantially better than $\\mathcal{O}(n \\log n)$? Why is it highly implausible that this kind of super-hardware could exist for these values of $c$?\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Inspired by \\textsc{MergeSort}, the proposed algorithm \\textsc{Super-Merger-Sort} is given as Algorithm 3.\n\nThe call to the super-hardware is performed by calling the \\textsc{Super-Merge} method.\nUsing this algorithm, we can sort an array of length $n$ by a top level call of \\textsc{Super-Merger-Sort}(A, $1$, $n$).\n\n\\begin{algorithm}[H]\n\\caption{\\textsc{Super-Merger-Sort}($A$, $p$, $r$)}\n\\begin{algorithmic}[1]\n\\If {$p < r$}\n\\State $q \\leftarrow \\lfloor \\frac{p+r}{2} \\rfloor$\n\\State \\textsc{Super-Merger-Sort}($A$, $p$, $q$)\n\\State \\textsc{Super-Merger-Sort}($A$, $q+1$, $r$)\n\\State \\textsc{Super-Merge}($A$,$p$,$q$,$r$)\n\\EndIf\n\\end{algorithmic}\n\\end{algorithm}\n\n\\item As the original \\textsc{MergeSort} algorithm has hardly been modified, the recursion tree will be the same as the recursion tree for \\textsc{MergeSort} (Figure 3 of Lecture note 2), the only difference being that the constant runtime of each level of the tree would this time be $n^c$.\n\n\\item Based on this fact, the total runtime of the proposed \\textsc{Super-Merger-Sort} algorithm with be $\\mathcal{O}(n^{c}\\log n)$ for sorting an array of length $n$.\n\nThe proposed algorithm would therefore perform better when $c < 1$.\nThis is of course highly implausible because any such super-hardware should at least read once all $n$ elements of the two merged lists to sort them and this itself is $\\mathcal{O}(n)$.\n\n\\end{enumerate}\n", "meta": {"hexsha": "5b340bbcda0f59e5c205203393872469cae48f0d", "size": 2429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q08.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q08.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q08.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 52.8043478261, "max_line_length": 291, "alphanum_fraction": 0.6965829559, "num_tokens": 680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.917302654499012, "lm_q1q2_score": 0.8273342379829646}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 1}\n\nProve that the depth of a binary tree with $L$ leaves is $\\Omega(\\log L)$.\n\n\\subsection*{Solution}\n\nWe know that the binary tree is a special kind of tree with at most 2 children for each node.\nSince we are interested in the lower bound of the depth of the tree, we will assume the case where every parent has two children which leads to a full binary tree.\nWe showed before that a full binary tree with depth $H$ has $2^H$ leaves.\nTherefore the minimum depth of a binary tree with $L$ leaves will be $\\lceil \\log L \\rceil$ leading to a lower bound of $\\Omega (\\log L)$ for the depth of the tree.\n", "meta": {"hexsha": "99c603d1ca27a02a840dbd71b39385ea092290be", "size": 975, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q01.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q01.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 54.1666666667, "max_line_length": 164, "alphanum_fraction": 0.6502564103, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9481545274901875, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.827120112845323}}
{"text": "\\lab{Algorithm}{Change of Basis}{Change of Basis}\n\\label{lab:ChangeBasis}\n\n\\objective{Understand how to change the basis of a set of points.}\n\n\\section*{Basis}\n\nA basis for a vector space is a set of vectors such that every vector in the space can be expressed uniquely as a linear combination of the basis vectors. In this lab we will take the coordinates in 2-d space and do various affine transformations. For all these exercises we will use the points\n\\begin{lstlisting}\nx=np.array([-1.5,-1.,-.5,0.,.5,1.,1.5,.75,-.75])\ny=np.array([0.,-1.,-2.,-2.,-2.,-1.,0.,2.,2.])\n\\end{lstlisting}\nLet be the matrix where each column in a point and M is the matrix that will change the basis. So $M*A$ will be the set of points in the new basis. In our cases the first row of $A$ is $x$ and the second row, $y$. \n\n\\section*{Strench}\nTo strech a set of points M will be a diagonal matrix where the value in each position is the streach in that direction\n\n\\begin{problem}\nWrite a function that will accepts a matrix of points and how much to strench them in each direction. Have the function plot the transformed points.\n\\end{problem}\n\n\\section*{Rotation}\nTo do a rotation clockwise of angle $\\theta$ let\n\\[\nM = \\begin{pmatrix}\n\\cos(\\theta) & -\\sin(\\theta) \\\\\n\\sin(\\theta) & \\cos(\\theta) \n\\end{pmatrix}\n\\]\n\n\n\\begin{problem}\nWrite a function that will accepts a matrix of points and how many radians to rotate the points. Have the function plot the transformed points.\n\\end{problem}\n\n\\section*{Shift}\nIn order to shift a set of points you add to the coordinate how much you would shift it in that direction. You can use array brodcasting to do this.\n\n\\begin{problem}\nWrite a function that will accepts a matrix of points and how much to shift them in each direction. Have the function plot the transformed points.\n\\end{problem}\n\n\\section*{Combination}\nSay you have points in a rotated basis and you want to stretch them along that basis. You left mutiply the strech matrix $S$ by the rotation matrix $R$. So $R*S*A$ will strench the points in the rotation in R. \n\n\\begin{problem}\nWrite a function that will accepts a matrix of points and strench, rotate and shift them.\n\\end{problem}\n\n\n\\section*{Images}\n\nAn Image is a 3d array where the first two demensions are the location and the 3rd demension is the RGB content. To apply the above tranformations one would need to moved the position of the RGB arrays to match where the new transformation would have them. Strenching is done by\n interpolation.\n\\begin{problem}\nWrite a function that will accepts an image and how many radians to rotate the image. The function will rotate the image around the center of the image and then show the rotated image. HINTS: Make an array of ones that is $1.5$ times greater than the max of the hieght and width of the original image. Change the x,y cordinates in the original image so the the center is $(0,0)$. Rotate the image and then center the image. You might need to use for loops. Allow your test cases to be small images.\n\\end{problem}\n\n\n", "meta": {"hexsha": "97921bdccad041501b32a699edf782af661063cd", "size": 3017, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/ChangeBasis/ChangeBasis.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/ChangeBasis/ChangeBasis.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/ChangeBasis/ChangeBasis.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.2833333333, "max_line_length": 498, "alphanum_fraction": 0.7557176003, "num_tokens": 773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297967961706, "lm_q2_score": 0.9184802479302793, "lm_q1q2_score": 0.8271188310299508}}
{"text": "\\section{Estimator} \\label{sec:estimator}\nConsider the commonly used Kullback-Leibler (KL) divergence between two\ndistributions $p(x)$ and $g(x)$:\n\\beq\n    \\kl{p}{q} = \\int p(x)~\\log\\frac{p(x)}{q(x)}~{\\rm d}x. \n\\eeq\nThe KL divergence between the posterior $p = p(\\theta \\given D, m)$ and prior\n$\\pi = p(\\theta | m)$ is then \n\\beq\n    \\kl{p}{\\pi} = \\int p(\\theta \\given D, m)~\\log\\frac{p(\\theta \\given D, m)}{p(\\theta | m)}~{\\rm d}\\theta. \n\\eeq\nIf we use Bayes' Theorem to substitute for $p(\\theta \\given D, m)$ in the\nnumerator, we can rewrite this as \n\\begin{align}\n    \\kl{p}{\\pi} &= \\int p(\\theta \\given D,\n    m)~\\log\\frac{p(D \\given \\theta, m)}{p(D | m)}~{\\rm d}\\theta\\\\ \n        &= -\\log p(D\\given m) + \\int p(\\theta \\given D, m)~\\log p(D \\given \\theta, m)~{\\rm d}\\theta. \n\\end{align}\nThe first term of the right hand side is the log evidence and the second term\nis the expectation value of the log likelihood under the posterior, $\\big\\langle\n\\log \\mathcal{L} \\big\\rangle$. In standard Bayesian analyses in astronomy where\nwe use MCMC to sample the posterior, $\\big\\langle \\log \\mathcal{L} \\big\\rangle$\ncan be easily derived with these samples using Monte Carlo integration: \n\\beq\n\\big\\langle \\log \\mathcal{L} \\big \\rangle \\approx \\frac{1}{n}\n\\sum\\limits_{i=1}^{n} \\log \\mathcal{L}(\\theta^{(i)})\n\\eeq\nTherefore, if we can estimate the KL divergence between the posterior and prior\nwe can also estimate the evidence: \n\\beq \\label{eq:estimator}\n\\log p(D\\given m) = \\big\\langle \\log \\mathcal{L} \\big\\rangle - \\kl{p(D \\given \\theta, m)}{\\pi}.\n\\eeq\n\nTo estimate the divergence, we can make use of non-parametric divergence\nestimators, which have been applied to Support Distribution Machines and \nused in the machine learning and astronomical literature~\\citep[\\emph{e.g.}][]{poczos2011,\npoczos2012, poczos2012a, xu2013, ntampaka2015, ntampaka2016, ravanbakhsh2017,\nhahn2019}. These estimators allow us to estimate the divergence between \ndistributions $p$ and $q$, $D(p\\,||\\,q)$ using samples drawn from them. In \nour case, $p$ and $q$ are the posterior and prior distributions. Again,\nstandard analyses already sample the posterir distribution; the prior \ndistribution is typcially straightforward to sample. \n\nFor the KL divergence, we use the $k$-Nearest Neighbor (NN) estimator presented in\n\\cite{wang2009}. Let $X_{1:n} = \\{ X_1, ... X_n \\}$ and $Y_{1:m} = \\{ Y_1, ... Y_m \\}$\nbe $n$ and $m$ samples drawn from the $p$ and $q$ $d$-dimensional distributions, respectively. \nThen the divergence between $p$ and $q$ can be estimated as: \n\\beq \\label{eq:div_est}\n\\kl{p}{q} \\approx \\widehat{D_{\\rm KL}}(p\\,||\\,q) = \\frac{d}{n}\n\\sum\\limits_{i=1}^n \\Big[\\log \\frac{\\nu_{\\ell_i}(i)}{\\rho_{k_i}(i)} \\Big] +\n\\frac{1}{n} \\sum\\limits_{i=1}^n\\Big[\\psi(\\ell_i) - \\psi(k_i)\\Big] + \\log\n\\frac{m}{n-1}. \n\\eeq\nIn the first term, $\\rho_k(i)$ denotes the Euclidean distance between $X_i$ and \nthe $k^\\mathrm{th}$-NN of $X_i$ in sample $\\{X_j\\}_{i\\neq j}$. $\\nu_\\ell(i)$\ndenotes the Euclidean distance between $X_i$ and the $\\ell^\\mathrm{th}$ NN of\n$X_i$ in the sample $Y_{1:m}$. In the second term, $\\psi$ is the Digamma function: \n$\\psi(k) = \\Gamma'(k)/\\Gamma(k)$.\nThis term corrects for the estimation bias that comes from nonuniformity of \nthe distribution near each sample point and guarantees that the estimator is\nasymptotically unbiased. Furthermore, while some $k$-NN estimators require \nchome choice in $k$ and $\\ell$~\\citep[\\emph{e.g.}][]{poczos2012}, the \n\\cite{wang2009} estimator adaptively determines $\\ell_i$ and $k_i$ as the number \nof samples $X_{1:n}$ and $Y_{1:m}$), respectively, contained in $B(X_i, \\epsilon(i))$, \na Euclidean ball centered at $X_i$ with radius $\\epsilon(i)$. \n\\beq\n\\epsilon(i) = \\max(\\rho(i), \\nu(i)) \n\\eeq\nwhere \n\\begin{align}\n    \\rho(i) &= \\min_{j \\neq i} || X_i - X_j|| \\\\\n    \\nu(i) &= \\min_{j \\neq i} || X_i - Y_j||.\n\\end{align}\nFor further details on the estimator and proofs that the estimator is\nasymptotically unbiased and mean-square consistent we refer readers to\n\\cite{wang2009}.\n", "meta": {"hexsha": "cecd3a688d407147d0bf3f52f77abc0de3e0cff5", "size": 4021, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/estimator.tex", "max_stars_repo_name": "changhoonhahn/nevin", "max_stars_repo_head_hexsha": "2b29c645e0c8fbfe2b6ca09ac963a2fd9d6019a8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-11T18:17:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-11T18:17:54.000Z", "max_issues_repo_path": "doc/estimator.tex", "max_issues_repo_name": "changhoonhahn/nevin", "max_issues_repo_head_hexsha": "2b29c645e0c8fbfe2b6ca09ac963a2fd9d6019a8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/estimator.tex", "max_forks_repo_name": "changhoonhahn/nevin", "max_forks_repo_head_hexsha": "2b29c645e0c8fbfe2b6ca09ac963a2fd9d6019a8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.2207792208, "max_line_length": 108, "alphanum_fraction": 0.6868938075, "num_tokens": 1372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587141, "lm_q2_score": 0.8791467595934565, "lm_q1q2_score": 0.8270922595195389}}
{"text": "\n\\subsection{Matrix exponentials}\n\nThe exponential of a complex number is defined as:\n\n\\(e^x=\\sum \\dfrac{1}{j!}x^j\\)\n\nWe can extend this definition to matrices.\n\n\\(e^X:=\\sum \\dfrac{1}{j!}X^j\\)\n\nThe dimension of a matrix and its exponential are the same.\n\n", "meta": {"hexsha": "a0d47cc2551f2f75dcba8d70714e5d9d03feefd7", "size": 255, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystemsOperations/02-02-matrixExponential.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/linearSystemsOperations/02-02-matrixExponential.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/linearSystemsOperations/02-02-matrixExponential.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.2142857143, "max_line_length": 59, "alphanum_fraction": 0.7058823529, "num_tokens": 79, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9706877658567787, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.8269801637824223}}
{"text": "\\section{Line search and gradient descent method}\n\\subsection{Gradient descent method}\nFor simplicity, let us just consider a general optimization problem\n\\begin{equation}\\label{optmodel}\n\\min_{x\\in \\mathbb{R}^n } f(x).\n\\end{equation}\n\n\\begin{figure}[H] \n\t\\centering\n\t\\centering\\includegraphics[height = 5cm, width=7cm]{figures/diag_GD.png} \n\\end{figure}\n\n\n\\paragraph{A general approach:  line search method}\nGiven any initial guess $x_1$, the line search method uses the following algorithm\n$$\n\\eta_t=\\argmin_{\\eta\\in \\mathbb{R}^1} f(x_t - \\eta p_t)\\qquad \\mbox{\\scriptsize(1D minimization problem)}\n$$ \n to produce $\\{ x_{t}\\}_{t=1}^{\\infty}$\n\\begin{equation}\\label{line-search}\nx_{t+1} = x_{t} - \\eta_t p_t.\n\\end{equation}\nHere $\\eta_t$ is called the step size in optimization and also learning\nrate in machine learning, $p_t$ is called the descent direction, which\nis the critical component of this algorithm. And $x_t$ tends to \n$$\nx^*=\\argmin_{x\\in \\mathbb{R}^n} f(x) \\iff f(x^*)=\\min_{x\\in \\mathbb{R}^n} f(x)\n$$ \nas $t$ tends to infinity. There is a series of optimization\nalgorithms which follow the above form just using different choices of $p_t$.\n\nThen, the next natural question is what a good choice of $p_t$ is? \nWe have the following theorem to show why gradient direction is a good choice for $p_t$.\n\\begin{lemma}\nGiven  $x \\in \\mathbb{R}^n$, if $\\nabla f(x)\\neq 0$, the fast descent direction of $f$ at $x$ is the negative gradient direction, namely\n\\begin{equation}\\label{key}\n-\\frac{\\nabla f(x)}{\\|\\nabla f(x)\\|} = \\mathop{\\arg\\min}_{ p \\in \\mathbb{R}^n, \\|p\\|=1} \\left. \\frac{\\partial f(x + \\eta p)}{\\partial \\eta} \\right|_{\\eta=0}.\n\\end{equation}\nIt means that $f(x)$ decreases most rapidly along the negative gradient direction.\n\\end{lemma}\n \n\\begin{proof}\nLet $p$ be a direction in $\\mathbb{R}^{n},\\|p\\|=1$. Consider the local decrease of the function $f(\\cdot)$ along direction $p$\n$$\n\\Delta(p)=\\lim _{\\eta \\downarrow 0} \\frac{1}{\\eta}\\left(f(x+\\eta p)-f(x)\\right)=\\left. \\frac{\\partial f(x + \\eta p)}{\\partial \\eta} \\right|_{\\eta=0}.\n$$\nNote that \n\\begin{equation}\n\\begin{split}\n\\left. \\frac{\\partial f(x + \\eta p)}{\\partial \\eta} \\right|_{\\eta=0}=\\sum_{i=1}^n\\left. \\frac{\\partial f}{\\partial x_i}(x + \\eta p)p_i \\right|_{\\eta=0} =(\\nabla f, p),\n\\end{split}\n\\end{equation}\nwhich means that \n$$\nf(x+\\eta p)-f(x)=\\eta(\\nabla f(x), p)+o(\\eta) .\n$$ \nTherefore\n$$\n\\Delta(p)=(\\nabla f(x), p).\n$$\nUsing the Cauchy-Schwarz inequality\n$\n-\\|x\\| \\cdot\\|y\\| \\leq( x, y) \\leq\\|x\\| \\cdot\\|y\\|,\n$\nwe obtain \n$$\n-\\|\\nabla f(x)\\| \\le (\\nabla f(x), p)\\le \\|\\nabla f(x)\\| .\n$$ \nLet us take\n$$\n\\bar{p}=-\\nabla f(x) /\\|\\nabla f(x)\\|.\n$$\nThen\n$$\n\\Delta(\\bar{p})=-(\\nabla f(x), \\nabla f(x)) /\\|\\nabla f(x)\\|=-\\|\\nabla f(x)\\|.\n$$\nThe direction $-\\nabla f(x)$ (the antigradient) is the direction of the fastest local decrease of the function $f(\\cdot)$ at point $x.$ \n\\end{proof}\n\nHere is a simple diagram for this property.\n\t\\begin{figure}[H]\n\t\t\\centering{\\includegraphics[width=5cm]{figures/gradientfast.png}}\n\t\t\\caption{Negative Gradient Direction: $ x_t$ is current point, $ p_t$ is the negative gradient of $ x_t$, i.e., $- \\nabla f( x_t)$.}\n\t\t\\label{functiongradient}\n\t\\end{figure}\n\nSince at each point,  $f(x)$ decreases most rapidly along the negative\ngradient direction, it is then natural to choose the search direction\nin \\eqref{line-search} in the negative gradient direction and the\nresulting algorithm is the so-called gradient descent method.\n\\begin{algorithm}[H]\n\\caption{Gradient Descent Method} \n\\label{alg:LR-R}\nGiven the initial guess $x_0$, learning rate $\\eta_t>0$\n\n\t{\\bf For} t=1,2,$\\cdots$, \\\\\n\t\\begin{equation}\\label{key}\n\tx_{t+1} =  x_{t} - \\eta_{t} \\nabla f({x}_{t}), \n\\end{equation}\n\\end{algorithm}\n\nIn practice, we need a ``stopping criterion'' that determines when the above gradient descent\nmethod to stop.  One possibility is \n\\begin{quote}\n\t{\\bf While} $S(x_t; f) = \\|\\nabla f(x_t)\\|\\le \\epsilon$ or $t \\ge T$  \n\\end{quote}\nfor some small tolerance $\\epsilon>0$ or maximal number of iterations\n$T$.   In general, a good stopping criterion is hard to come by and it\nis a subject that has called a lot of research in optimization for\nmachine learning. \n\nIn the gradient method, the scalar factors for the gradients, $\\eta_{t},$ are called the step sizes. Of course, they must be positive. There are many variants of the gradient method, which differ one from another by the step-size strategy. Let us consider the most important examples.\n\\begin{enumerate}\n\\item The sequence $\\left\\{\\eta_t\\right\\}_{t=0}^{\\infty}$ is chosen in advance. For example,\n(constant step)\n$$\n\\eta_t=\\frac{\\eta}{\\sqrt{t+1}};\n$$\n\\item Full relaxation:\n$$\n\\eta_t=\\arg \\min _{\\eta \\geq 0} f\\left(x_t-\\eta \\nabla f\\left(x_t\\right)\\right);\n$$\n\\item The Armijo rule: Find $x_{t+1}=x_t-\\eta \\nabla f\\left(x_t\\right)$ with $\\eta>0$ such that\n$$\n\\alpha\\left(\\nabla f\\left(x_t\\right), x_t-x_{t+1}\\right) \\leq f\\left(x_t\\right)-f\\left(x_{t+1}\\right),\n$$\n$$\n\\beta\\left(\\nabla f\\left(x_t\\right), x_t-x_{t+1}\\right) \\geq f\\left(x_t\\right)-f\\left(x_{t+1}\\right),\n$$\nwhere $0<\\alpha<\\beta<1$ are some fixed parameters.\n\\end{enumerate}\nComparing these strategies, we see that \n\\begin{enumerate}\n\\item The first strategy is the simplest one. It is often used in the context of convex optimization. In this framework, the behavior of functions is much more predictable than in the general nonlinear case.\n\\item The second strategy is completely theoretical. It is never used in practice since even in one-dimensional case we cannot find the exact minimum in finite time.\n\\item The third strategy is used in the majority of practical algorithms. It has the following geometric interpretation. Let us fix $x \\in \\mathbb{R}^{n}$ assuming that $\\nabla f(x) \\neq 0$. Consider the following function of one variable:\n$$\n\\phi (\\eta)=f(x-\\eta \\nabla f(x)),\\quad \\eta\\ge0.\n$$\nThen the step-size values acceptable for this strategy belong to the part of the graph of $\\phi$ which is located between two linear functions:\n$$\n\\phi_{1}(\\eta)=f(x)-\\alpha \\eta\\|\\nabla f(x)\\|^{2}, \\quad \\phi_{2}(\\eta)=f(x)-\\beta \\eta\\|\\nabla f(x)\\|^{2}\n$$\nNote that $\\phi(0)=\\phi_{1}(0)=\\phi_{2}(0)$ and $\\phi^{\\prime}(0)<\\phi_{2}^{\\prime}(0)<\\phi_{1}^{\\prime}(0)<0 .$ Therefore, the\nacceptable values exist unless $\\phi(\\cdot)$ is not bounded below. There are several very fast one-dimensional procedures for finding a point satisfying the Armijo conditions. However, their detailed description is not important for us now.\n\\end{enumerate}\n", "meta": {"hexsha": "15bed4cdf4cec478ad68bee15e414e23a4f7a1b2", "size": 6499, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/4 Training Algorithms/4.1-DL-GD.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/4 Training Algorithms/4.1-DL-GD.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/4 Training Algorithms/4.1-DL-GD.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.2108843537, "max_line_length": 284, "alphanum_fraction": 0.6953377443, "num_tokens": 2136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392786908831, "lm_q2_score": 0.9353465066875933, "lm_q1q2_score": 0.8268830510981372}}
{"text": "\\paragraph{Tutte-Berge formula}\nThe theorem states that the size of a maximum matching of a graph $G=(V,E)$ equals\n\n$${\\frac {1}{2}}\\min _{U\\subseteq V}\\left(|U|-\\operatorname {odd} (G-U)+|V|\\right)\\,,$$\nwhere $\\operatorname {odd} (H)$ counts how many of the connected components of the graph $H$ have an odd number of vertices.\n\n\\paragraph{Tutte theorem}\n\nA graph, $G = (V, E)$, has a perfect matching if and only if for every subset $U$ of $V$, the subgraph induced by $V-U$ has at most $|U|$ connected components with an odd number of vertices.\n\n\\paragraph{Hall's marriage theorem}\n\nA family $S$ of finite sets has a transversal if and only if $S$ satisfies the marriage condition.\n\n", "meta": {"hexsha": "4a5124c34cb7963b9e6ac21888ffb6f3b23c14bc", "size": 686, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/graph/matching/matching.tex", "max_stars_repo_name": "Nisiyama-Suzune/LMR", "max_stars_repo_head_hexsha": "16325b9efcb71240111ac12ea55c0cb45b0c5834", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2018-08-15T11:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T23:38:29.000Z", "max_issues_repo_path": "src/graph/matching/matching.tex", "max_issues_repo_name": "Nisiyama-Suzune/LMR", "max_issues_repo_head_hexsha": "16325b9efcb71240111ac12ea55c0cb45b0c5834", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/graph/matching/matching.tex", "max_forks_repo_name": "Nisiyama-Suzune/LMR", "max_forks_repo_head_hexsha": "16325b9efcb71240111ac12ea55c0cb45b0c5834", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2019-07-18T10:27:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-08T13:03:47.000Z", "avg_line_length": 45.7333333333, "max_line_length": 190, "alphanum_fraction": 0.7128279883, "num_tokens": 195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620562254526, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.8268716782822175}}
{"text": "%================================\n\\section{Limit Points}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t[limit points]\n\t\\label{def: limit points}\n\tLet $(X, \\mathcal T_X)$ be a topological space, and let $A \\subseteq X$. A point $x \\in X$ is called a \\textit{limit point} of $A$ iff for all neighbourhood $N_x$ of $x$, $N_x \\setminus \\{x\\}$ intersects $A$.\n\\end{definition}\n%--------------------------------\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: limit points are always in the closure}\n\tLet $A$ be any set, and let $x$ be a limit point of $A$, then $x$ is an element of the closure of $A$.\n\t\n\t\\begin{proof}\n\t\tIf $A$ is empty, then this is vacuously true. So, suppose $A$ is not empty.\n\t\n\t\tBy Definition \\ref{def: limit points}, for all neighbourhood $N_x$ of $x$, $N_x \\setminus \\{x\\} \\cap A$ is not empty. Naturally, $N_x \\cap A$ is not empty.\n\t\t\n\t\tAssume that $x \\notin \\overline A$, then $X \\setminus \\overline A$ is a neighbourhood of $x$, by Definition \\ref{def: neighbourhood}, and is disjoint from $A$. This is contradicted to the conditions.\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tIn this proof, the proposition also holds for $N_x \\cap A^\\circ = \\emptyset$. Because if it is true, then\n\t$$\n\t\\begin{aligned}\n\t\tN_x \\cap \\partial A \\supseteq (N_x \\cap A) \\setminus (N_x \\cap A^\\circ) = N_x \\cap A.\n\t\\end{aligned}\n\t$$\n\tThis implies that $A \\subseteq \\partial A$. In this case, $\\overline A = \\partial A$, for\n\t\n\tAssume that $x\\notin \\partial A$, then we have the same conclusion.\n\t\n\tThen $A^\\circ = A \\setminus \\partial A = \\emptyset$. \n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tA set is closed iff it contains all its limit point.\n\t\n\t\\begin{proof}\n\t\tLet $A$ be a set. By proposition \\ref{prop: limit points are always in the closure}, for every limit point of $A$, it is also an element of the closure $\\overline A$. And $A$ is closed iff $A = \\overline A$.\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n\\\n\n\\\n\n%--------------------------------\n\\begin{definition}\n\t[convergent sequences]\n\t\\label{def: convergent sequences}\n\tLet $(X, \\mathcal T_X)$ be a topological space. A sequence $\\{x_n\\}$ in $X$ is said to be \\textit{convergence} in $X$ iff there is an open set $U$ contains all but finite terms of $\\{x_n\\}$.\n\\end{definition}\n%--------------------------------", "meta": {"hexsha": "076b581ef126a762523cd771487a2d1ed30a5f26", "size": 2500, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/limit-points.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-v0/limit-points.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-v0/limit-points.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.7647058824, "max_line_length": 209, "alphanum_fraction": 0.572, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.9059898267292558, "lm_q1q2_score": 0.8266578875610158}}
{"text": "% Chapter I: Preliminaries: Set theory and categories\n\\chapter{Preliminaries: Set theory and categories}\n\n\\section{Naive set theory}\n\\begin{xca}\nLet $U = \\{ x \\mid x \\not\\in x \\}$. Then, $U \\not\\in U \\iff U \\in U$, a\ncontradiction. This is Russell's paradox. Either we assume the \\emph{set of all\nsets} doesn't exist, or we need to give up the axiom of \\emph{unrestricted\ncomprehension} in set theory.\n\\end{xca}\n\n\\begin{xca}\nSuppose $\\sim$ is an equivalence relation on a set $S$. For every element $a \\in\nS$, define the \\emph{equivalence class} of $a$ (with respect to $\\sim$) by\n\\begin{center}\n$[a]_{\\sim} := \\{ b \\in S \\mid b \\sim a \\}$.\n\\end{center}\nThen, we note that due to \\emph{reflexivity}, the equivalence class\n$[a]_{\\sim}$ of every element $a \\in S$ contains $a$, and hence, is nonempty.\nAlso, $[a]_{\\sim} \\subset S$, and therefore, $\\bigcup_{a \\in S} [a]_{\\sim} =\nS$. Finally, we show the equivalence classes are mutually disjoint. Indeed, for\nany two elements $a, b \\in S$, if $[a]_{\\sim}$ and $[b]_{\\sim}$ are disjoint,\nthen there is nothing to prove. So, suppose $[a]_{\\sim} \\cap [b]_{\\sim}$ is\nnonempty. Then, there exists some $c \\in S$ that belongs to such an\nintersection. Thus, $c \\sim a$ and $c \\sim b$. By symmetry, $a \\sim c$, and\nthus, by transitivity, $a \\sim b$, which by symmetry again, implies $b \\sim a$.\nTherefore, for all $x \\in [a]_{\\sim}$, we have $x \\sim a$, and since $a \\sim\nb$, by transitivity, $x \\sim b$, which implies $x \\in [b]_{\\sim}$, from which\nwe conclude $[a]_{\\sim} \\subset [b]_{\\sim}$. We can similarly show $[b]_{\\sim}\n\\subset [a]_{\\sim}$. Hence, $[a]_{\\sim} = [b]_{\\sim}$. This establishes\nequivalence classes are mutually disjoint. Hence, the set $\\mathscr{P}_{\\sim}$\nof equivalence classes of $S$ is indeed a partition of $S$.\n\\end{xca}\n\n\\begin{xca}\nSuppose $\\mathscr{P}$ is a partition on a set $S$. Define a relation $\\sim$ on\n$S$ as follows: For any two elements $a, b \\in S$, $a \\sim b$ iff $a$ and $b$\nbelong to the same set in the partition. Then, it is easy to check $\\sim$ is\nindeed an equivalence relation on $S$. $\\mathscr{P}$ is, therefore, the\ncorresponding partition of the aforesaid equivalence relation, and we are done.\n\\end{xca}\n\n\\begin{xca}\nNote the set of equivalence relations on a set $S$ are in a one-to-one\ncorrespondence with the set of partitions of $S$. Thus, the number of different\nequivalence relations that may be defined on $S = \\{ 1, 2, 3\\}$ equals the\nnumber of partitions of $S$, and this number equals $5$, since the partitions\nof $S$ are\n\\begin{center}\n    $\\{ \\{ 1 \\}, \\{ 2 \\}, \\{ 3 \\} \\}, \\{ \\{ 1, 2 \\}, \\{ 3 \\} \\}, \\{ \\{ 1, 3 \\},\n    \\{ 2 \\} \\}, \\{ \\{ 2, 3 \\}, \\{ 1 \\} \\}, \\{ \\{ 1, 2, 3 \\} \\}$.\n\\end{center}\nThe above partitions are also written as $1|2|3, 12|3, 13|2, 23|1, 123$.\n\\end{xca}\n\n\\begin{xca}\nAn example of a relation $R$ (defined on a set $S$) that is reflexive and\nsymmetric but not transitive is the following:\n\\begin{center}\n$R = \\{ (1,1), (2,2), (3,3), (1,2), (2,1), (2,3), (3,2) \\}$, where\n$S = \\{ 1,2,3 \\}$.\n\\end{center}\n\\end{xca}\n\n\\begin{xca}\nDefine a relation $\\sim$ on the set $\\R$ of real numbers by setting\n\\begin{center}\n $a \\sim b \\iff b - a \\in \\mathbb{Z}$.\n\\end{center}\nWe claim $\\sim$ is an equivalence relation. To that end, note, for all $a \\in\n\\R$, we have $a \\sim a$, since $a - a = 0 \\in \\Z$. Therefore, $\\sim$ is\nreflexive. Also, if $a \\sim b$, then $b - a \\in \\Z$, which implies $a - b \\in\n\\Z$, and thus, $b \\sim a$. Therefore, $\\sim$ is symmetric. Finally, suppose $a\n\\sim b$ and $b \\sim c$. Then, $b - a, c - b \\in \\Z$, and thus, $c - a = (c - b)\n+ (b - a) \\in \\Z$. Thus, $\\sim$ is transitive. Therefore, $\\sim$ is an\nequivalence relation on $\\R$.\n\n(Description of $\\sim$) Note all reals that have the same decimal expansion\nbelong to the same equivalence class under $\\sim$. Thus, $[0]_{\\sim} = \\Z$, and\nfor any $0 < \\alpha < 1, [\\alpha]_{\\sim} = \\{ n + \\alpha \\mid n \\in \\Z \\}$. This\ntakes care of all the reals, since each real can always be written as $n +\n\\alpha$, for some $n \\in \\Z$ and $0 < \\alpha < 1$. Therefore, a `compelling'\ndescription for $\\R/{\\sim}$ is the unit interval $[0,1]$, such that the\nendpoints, $0$ and $1$, are `glued' together. In other words, it is a `loop'\nor a 1-sphere.\\\\\n\nDefine a relation $\\approx$ on the plane $\\R \\times \\R$ as follows:\n\\begin{center}\n$(a_1, a_2) \\approx (b_1, b_2) \\iff b_1 - a_1 \\in \\Z \\text{ and }\nb_2 - a_2 \\in \\Z$.\n\\end{center}\nThen, just as above, it is easy to show $\\approx$ defines an equivalence\nrelation on $\\R \\times \\R$. We note $[(0,0)]_{\\sim} = \\{ (m,n) \\mid m,n \\in \\Z\n\\}$, and for any $0 < \\alpha, \\beta < 1, [(\\alpha, \\beta)]_{\\sim} = \\{ (m +\n\\alpha, n + \\beta) \\mid m,n \\in \\Z \\}$. Thus, a `compelling' description of $\\R\n\\times \\R/{\\approx}$ is the unit square $[0,1] \\times [0,1]$ with the four\ncorners joined together, so that it forms a 2-sphere.\n\\end{xca}\n\n\\section{Functions between sets}\n\\begin{xca}\nWe claim the number of bijections from a set $S$ with $n$ elements to itself is\n$n!$. To begin with, any element in $S$ can be mapped to any of the $n$ possible\nelements in $S$. Then, the next element in $S$ can be mapped to any of the\nremaining $n-1$ elements in $S$, and so on, with the last element in $S$ being\nmapped to the last remaining element in $S$. Thus, the number of bijections\nequals $n \\cdot (n-1) \\cdot \\ldots \\cdot 1 = n!$, which proves our claim.\n\\end{xca}\n\n\\begin{xca}\nAssume $A \\neq \\emptyset$, and let $f: A \\to B$ be a function. We claim $f$ has\na right inverse iff it is surjective.\n\n($\\impliedby$) Suppose $f$ has a right inverse, $g: B \\to A$, say. Then,\n$f \\circ g = 1_B$. Thus, for all $b \\in B$, $b = 1_B(b) = (f \\circ g)(b) =\nf(g(b)) = f(a)$, where $g(b) = a \\in A$. This shows $f$ is surjective.\n\n($\\implies$) Suppose $f$ is surjective. Then, for any $b \\in B$, the fiber of\n$f$ over $b$ is nonempty. Thus, $\\{ f^{-1}(b) \\}_{b \\in B}$ is a family of\nnonempty sets, and therefore, using the \\emph{axiom of choice}, we can construct\na function $g : B \\to A$ as follows: For all $b \\in B$, $g(b) = a$ for some\n$a \\in f^{-1}(b)$. Hence, for all $b \\in B, (f \\circ g) (b) = f(g(b)) = f(a) =\nb = 1_{B} (b)$, and so, $f \\circ g = 1_B$. This establishes $g$ is the right\ninverse of $f$, and we are done.\n\\end{xca}\n\n\\begin{xca}\nSuppose $f : A \\to B$ is a bijection. Then, $f$ has an inverse $f^{-1}: B \\to A$\nsuch that $f^{-1} \\circ f = 1_A$ and $f \\circ f^{-1} = 1_B$. Clearly, $f$ is an\ninverse of $f^{-1}$, showing $f^{-1}$ is also a bijection.\n\nSuppose $f: A \\to B$ and $g: B \\to C$ are bijections. We claim $g \\circ f: A \\to\nC$ is also a bijection. To that end, we show $f^{-1} \\circ g^{-1}: C \\to A$ is\nthe inverse of $g \\circ f$. Indeed, $(g \\circ f) \\circ (f^{-1} \\circ g^{-1}) =\ng \\circ (f \\circ f^{-1}) \\circ g^{-1} = g \\circ 1_B \\circ g^{-1} = g \\circ\ng^{-1} = 1_C$. And, $(f^{-1} \\circ g^{-1}) \\circ (g \\circ f) = f^{-1} \\circ\n(g^{-1} \\circ g) \\circ f = f^{-1} \\circ 1_B \\circ f = f^{-1} \\circ f = 1_A$,\nand we are done.\n\\end{xca}\n\n\\begin{xca}\nWe show `isomorphism' is an equivalence relation on any set of sets.\\\\\n(Reflexivity) For all sets $A, 1_A : A \\to A$ is a natural bijection, and thus,\n$A \\cong A$.\\\\\n(Symmetry) Suppose $A \\cong B$ for any two sets $A, B$. Then,\nthere exists a bijection $f : A \\to B$, such that its inverse $f^{-1} : B \\to\nA$ is also a bijection (as shown in the above exercise.) Thus, $B \\cong A$.\\\\\n(Transitivity) Finally, suppose for any three sets, $A, B$ and $C$, $A \\cong B$\nand $B \\cong C$, with $f : A \\to B$ and $g: B \\to C$ as bijections. Then, from\nthe previous exercise, $g \\circ f : A \\to C$ is also a bijection, and thus $A\n\\cong C$.\\\\\nThus, our original claim is established.\n\\end{xca}\n\n\\begin{xca}\n(\\emph{\\textbf{Epimorphism}}) A function $f : A \\to B$ is an \\emph{epimorphism}\n(or \\emph{epi}) if the following holds: For all sets $Z$ and all functions\n$\\alpha ', \\alpha '' : B \\to Z$,\n\\begin{center}\n$\\alpha ' \\circ f = \\alpha '' \\circ f \\Longrightarrow \\alpha ' = \\alpha ''$.\n\\end{center}\nIn other words, an epimorphism $f$ is \\emph{right cancellative}.\\\\\n\n\\emph{Proposition}: A function is surjective iff it is an epimorphism.\n\n\\emph{Proof}. ($\\implies$) Suppose $f: A \\to B$ is an epimorphism. Assume, for\nthe sake of contradiction, $f$ is \\emph{not} surjective. Then, there exists an\nelement $b_0 \\in B$, such that, for all $a \\in A$, $f(a) \\neq b_0$. We now\nconstruct two distinct functions $\\alpha', \\alpha'' : B \\to \\{ 0, 1 \\}$ as\nfollows:\n\\begin{center}\n\\[\n\\alpha'(b) = 0\n\\]\n\n\\[\n\\alpha''(b) =\n    \\begin{cases}\n        0 & \\text{if } b \\neq b_0 \\\\\n        1 & \\text{if } b = b_0\n    \\end{cases}\n\\]\n\\end{center}\nThen, it is easy to check that, for all $a \\in A$,\n$(\\alpha'' \\circ f)(a) = \\alpha''(f(a)) = 0 = \\alpha'(f(a)) = (\\alpha' \\circ\nf)(a)$, which implies $\\alpha' \\circ f = \\alpha'' \\circ f$. However, $\\alpha'\n\\neq \\alpha''$, which contradicts our assumption that $f$ is an epimorphism.\nHence, we conclude $f$ is surjective.\n\n($\\impliedby$) Suppose $f: A \\to B$ is surjective. Then, it has a right inverse\n$g: B \\to A$ such that $f \\circ g = 1_B$. Now, assume, for any set $Z$ and any\ntwo functions $\\alpha', \\alpha'': B \\to Z$, $\\alpha' \\circ f = \\alpha'' \\circ\nf$. Then, $\\alpha' = \\alpha' \\circ 1_B = \\alpha' \\circ (f \\circ g) = (\\alpha'\n\\circ f) \\circ g = (\\alpha'' \\circ f) \\circ g = \\alpha'' \\circ (f \\circ g) =\n\\alpha'' \\circ 1_B = \\alpha''$, thus proving $f$ is an epimorphism.\n\\end{xca}\n\n\\begin{xca}\nAny function $f: A \\to B$ determines a section $g: A \\to A \\times B$ of $\\pi_A:\nA \\times B \\to A$ by defining $g$ as follows:\n\\begin{center}\n    $a \\mapsto (a, f(a))$\n\\end{center}\nThen, for all $a \\in A$, $(\\pi_A \\circ g)(a) = \\pi_A(g(a)) = \\pi_A(a, f(a)) =\na = 1_A(a)$, which implies $\\pi_A \\circ g = 1_A$, thereby showing $g$ as\ndefined above is indeed a section of $\\pi_A$.\n\\end{xca}\n\n\\begin{xca}\nLet $f: A \\to B$ by any function. We show the graph $\\Gamma_f$ of $f$ is\nisomorphic to $A$. First, recall the definition of $\\Gamma_f$:\n\\begin{center}\n    $\\Gamma_f := \\{ (a, b) \\in (A, B) \\mid b = f(a) \\} \\subseteq A \\times B$.\n\\end{center}\nWe define a function $g: A \\to \\Gamma_f$ by\n\\begin{center}\n    $a \\mapsto (a, f(a))$.\n\\end{center}\nThen, for any $(a, b) \\in \\Gamma_f$, we have $b = f(a)$, which implies $g(a) =\n(a, f(a)) = (a, b)$, proving $g$ is surjective. Next, for any $a', a'' \\in A$,\nsuppose $g(a') = g(a'')$. This implies $(a', f(a')) = (a'', f(a''))$, which\nimplies $a' = a''$, thus proving $g$ is injective. Hence, $g$ is an isomorphism,\nand so, $A \\cong \\Gamma_f$.\n\\end{xca}\n\n\\begin{xca}\nWe describe below explicitly all the terms in the canonical decomposition of the\nfunction $f: \\R \\to \\C$ defined by\n\\begin{center}\n    $r \\mapsto e^{2\\pi ir}$.\n\\end{center}\nNote $f$ determines an equivalence relation $\\sim$ on $\\R$ as follows: For all\n$r', r'' \\in \\R$,\n\\begin{center}\n    $r' \\sim r'' \\iff f(r') = f(r'')$.\n\\end{center}\nNow, $f(r') = f(r'')$ whenever $e^{i2\\pi r'} = e^{i2\\pi r''}$, \\emph{i.e.}\n$e^{i2\\pi(r' - r'')} = e^0$; that is, $2\\pi(r' - r'') = 2\\pi k$, where $k \\in\n\\Z$. In other words, $f(r') = f(r'')$ iff $r' - r'' = k$, where $k \\in \\Z$.\nThis implies\n\\begin{center}\n    $r' \\sim r'' \\iff r' - r'' \\in \\Z$.\n\\end{center}\nThe above equivalence relation matches the one stated in Exercise 1.6 of\nChapter 1. And, from the solution to the aforesaid exercise, we note that all\nequivalence classes are of the form $[\\alpha]_{\\sim}$, where $\\alpha \\in [0,\n1)$. Therefore, the isomorphism $\\tilde{f}: \\R/{\\sim} \\xrightarrow{\\sim}\n\\opn{im} f$ is defined by\n\\begin{center}\n    $\\tilde{f}(\\alpha) = e^{2\\pi i\\alpha}, \\, \\alpha \\in [0, 1)$.\n\\end{center}\nAlso, note $\\opn{im} f$ is the unit circle on the complex plane. So, the entire\ndecomposition of $f: \\R \\to \\C$ is as shown below:\n\\[\n\\begin{tikzcd}\n    \\R \\arrow[r, two heads]\n       \\arrow[rrr, bend left, \"f\"]\n       & \\R/{\\sim} \\arrow[r, \"\\sim\"]{r}[swap]{\\tilde{f}}\n                   & \\opn{im} f \\arrow[r, hook]\n                                & \\C\n\\end{tikzcd},\n\\]\nwhere $\\R/{\\sim}$ is a `loop' (1-sphere.)\n\\end{xca}\n\n\\begin{xca}\nSuppose $A' \\cong A''$ and $B' \\cong B''$, and further $A' \\cap B' = \\emptyset$\nand $A'' \\cap B'' = \\emptyset$. Then, there exist isomorphisms $f: A' \\to A''$\nand $g: B' \\to B''$. Define a piecewise function $h: A' \\cup B' \\to A'' \\cup\n B''$ as follows:\n\\[\n    h(x) =\n    \\begin{cases}\n        f(x) & \\text{if } x \\in A' \\\\\n        g(x) & \\text{if } x \\in B'\n    \\end{cases}\n\\]\nWe claim $h$ is an isomorphism. Indeed, let $y \\in A'' \\cup B''$. Since $A''$\nand $B''$ are disjoint, there are two cases to consider. Either, $y \\in A''$,\nin which case, since $f$ is surjective there exists some $x_1 \\in A'$ such that\n$f(x_1) = y$, which implies $h(x_1) = y$. Or, $y \\in B''$, in which case, since\n$g$ is surjective there exists some $x_2 \\in B'$ such that $g(x_2) = y$, which\nimplies $h(x_2) = y$. Thus, in either case, $h$ maps some $x \\in A' \\cup B'$ to\n$y \\in A'' \\cup B''$, thus showing $h$ is surjective.\\\\\nNow, suppose $h(x_1) = h(x_2)$ for any $x_1, x_2 \\in A' \\cup B'$. There are\nthree cases to consider. First, if both $x_1, x_2 \\in A'$, then $f(x_1) =\nf(x_2)$, and since $f$ is injective, $x_1 = x_2$. Second, if both $x_1, x_2 \\in\nB'$, then $g(x_1) = g(x_2)$, and since $g$ is injective, $x_1 = x_2$. Finally,\nwithout loss of generality, we can assume $x_1 \\in A'$ and $x_2 \\in B'$, which\nimplies $f(x_1) = g(x_2)$, but this is impossible, since $f(x_1) \\in A''$ and\n$f(x_2) \\in B''$, but $A'', B''$ are disjoint. Thus, we conclude $h$ is\ninjective.\\\\\nHence, $h$ is an isomorphism.\n\nThe above demonstrates the \\emph{disjoint union} operation $A \\amalg B$ for any\ntwo sets $A$ and $B$ is, indeed, well-defined \\emph{up to isomorphism}.\n\\end{xca}\n\n\\begin{xca}\nSuppose $A$ and $B$ are finite sets. Then, any one of the $|A|$ elements in $A$\ncan be mapped to any one of the $|B|$ elements in $B$. Thus, there are\nexactly $|B|^{|A|}$ ways of constructing a function $A \\to B$. Hence, $|B^A| =\n|B|^{|A|}$.\n\\end{xca}\n\n\\begin{xca}\nLet $A$ be a set, and let $2^A$ denote the set of functions from $A$ to $2 = \\{\n0, 1\\}$. Then, define a mapping $f: 2^A \\to \\mc{P}A$, where $\\mc{P}A$ is the\npowerset of $A$, as follows: Any function $A \\to 2$ is mapped to the subset\nconsisting of all those elements of $A$ that are mapped to $1$ under such a\nfunction. Then, it is easy to check $f$ is both surjective and injective, and\nhence, a bijection.\n\\end{xca}\n\n\\section{Categories}\n\\begin{xca}\nLet $\\mc{C}$ be a category. Consider a structure $\\mc{C}^{op}$ with\n\\begin{itemize}\n    \\item $\\opn{Obj}(\\mc{C}^{op}) := \\opn{Obj}(\\mc{C})$;\n    \\item for $A, B$ objects of $\\mc{C}^{op}$ (hence objects of $\\mc{C}$),\n    $\\Hom_{\\mc{C}^{op}}(A, B) := \\Hom_{\\mc{C}}(B, A)$.\n\\end{itemize}\nWe can make $\\mc{C}^{op}$ into a category as follows.\n\\begin{itemize}\n    \\item For every object $A$ of $\\mc{C}^{op}$, its identity morphism in\n    $\\mc{C}^{op}$ is defined as the identity morphism $1_A$ in $\\mc{C}$.\n    \\item For any two morphisms $f \\in \\Hom_{\\mc{C}^{op}}(A, B)$ and $g \\in\n    \\Hom_{\\mc{C}^{op}}(B, C)$, the composite $g \\circ f \\in\n    \\Hom_{\\mc{C}^{op}}(A, C)$ is defined as the composite $f \\circ g$ in\n    $\\mc{C}$.\n    \\item The associativity of composition in $\\mc{C}^{op}$ is a direct\n    consequence of associativity of composition in $\\mc{C}$.\n    \\item The fact that identity morphisms in $\\mc{C}^{op}$ are identities with\n    respect to composition is a direct consequence of identity morphisms in\n    $\\mc{C}$ being identities with respect to composition.\n\\end{itemize}\nThe above construction, thus, shows $\\mc{C}^{op}$ is a category. This\n\\emph{\\textbf{opposite category}} is simply obtained by `reversing all the\narrows' in $\\mc{C}$.\n\\end{xca}\n\n\\begin{xca}\nIf $A$ is a finite set, then $|\\End_{\\catname{Set}}(A)| = |A^A| = |A|^{|A|}$.\n\\end{xca}\n\n\\begin{xca}\nIn Example 3.3, to say $1_a = (a, a)$ is the identity of element $a \\in S$ with\nrespect to composition means that any $f = (a, b) \\in \\Hom(a, b)$ remains\nunchanged when composed with $1_a$ or $1_b$ in the appropriate manner. In the\nfirst case, we have $a \\sim a$ and $a \\sim b$, and thus, by transitivity, $a\n\\sim b$, from which we conclude $f 1_a = (a, b) = f$. Similarly, in the second\ncase, we conclude $1_b f = f$.\n\\end{xca}\n\n\\begin{xca}\nSuppose we can define a category in the style of Example 3.3 using the relation\n$<$ on the set $\\Z$. Then, any element (object) $n \\in \\Z$ will have an identity\nmorphism $1_n = (n, n)$ that would imply $n < n$, which is impossible. Hence,\nwe can't define such a category using the relation $<$ on the set $\\Z$.\n\\end{xca}\n\n\\begin{xca}\nExample 3.4 is an instance of the categories considered in Example 3.3 in the\nsense that set inclusion $\\subseteq$ (morphisms) between subsets of $S$\n(objects) satisfies the reflexivity and transitivity axioms for $\\sim$.\n\\end{xca}\n\n\\begin{xca}\n(Assuming some familiarity with linear algebra.) Define a category $\\mathsf{V}$\nby taking $\\opn{Obj}(\\mathsf{V}) = \\N$ and letting $\\Hom_{\\mathsf{V}}(n, m) =$\nthe set of $m \\times n$ matrices with real entries, for all $n, m \\in \\N$.\nComposition is defined as products of matrices. Note, for all $n \\in \\N$,\n\\[\n\\Hom_{\\mathsf{V}}(n, 0) = \\emptyset = \\Hom_{\\mathsf{V}}(0, n).\n\\]\nThis category does \\emph{not} `feel' familiar, since it is quite unlike any of\nthe other categories we have seen before. Objects of $\\mathsf{V}$ are not like\nthe usual sets or elements we have encountered so far, and its morphisms are\nmatrices which are not the typical set-theoretic functions.\n\\end{xca}\n\n\\begin{xca}\nLet $\\mc{C}$ be a category, and $A$ an object of $\\mc{C}$. We define a category\n$\\mc{C}^A$ as follows:\n\\begin{itemize}\n    \\item $\\opn{Obj}(\\mc{C}^A) :=$ collection of all morphisms from $A$ to any\n    object of $\\mc{C}$; that is, an object of $\\mc{C}^A$ is a morphism $f \\in\n    \\Hom_{\\mc{C}}(A, B)$ for some object $B$ of $\\mc{C}$.\n    \\item For any two objects $f_1: A \\to B$ and $f_2: A \\to C$ of $\\mc{C}^A$,\n    morphisms $f_1 \\to f_2$ are defined to be commutative diagrams\n    \\[\n    \\begin{tikzcd}\n        & A \\arrow[dl, swap, \"f_1\"]\n            \\arrow[dr, \"f_2\"]\n            & \\\\\n            B \\arrow[rr, swap, \"\\sigma\"]\n              & & C\n    \\end{tikzcd}\n    \\]\n    in the `ambient' category $\\mc{C}$. That is, morphisms $f_1 \\to f_2$\n    correspond precisely to those morphisms $\\sigma: B \\to C$ in $\\mc{C}$ such\n    that $\\sigma \\circ f_1 = f_2$.\n\\end{itemize}\n\n(Composition) Two morphisms $f_1 \\to f_2$ and $f_2 \\to f_3$ in $\\mc{C}^A$\ncorrespond to putting two commutative diagrams side-by-side:\n\\[\n\\begin{tikzcd}\n    & A \\arrow[dl, swap, \"f_1\"]\n        \\arrow[d, swap, \"f_2\"]\n        \\arrow[dr, \"f_3\"]\n        & \\\\\n    B \\arrow[r, swap, \"\\sigma\"]\n      & C \\arrow[r, swap, \"\\tau\"]\n          & D\n\\end{tikzcd}\n\\]\nThen, the diagram obtained by removing the central arrow, \\emph{i.e.}\n\\[\n\\begin{tikzcd}\n    & A \\arrow[dl, swap, \"f_1\"]\n        \\arrow[dr, \"f_3\"]\n        & \\\\\n    B \\arrow[rr, swap, \"\\tau \\circ \\sigma\"]\n      & & D\n\\end{tikzcd}\n\\]\nalso commutes, since $\\mc{C}$ is a category.\n\\end{xca}\n\n\\begin{xca}\nA \\emph{subcategory} $\\mc{C}'$ of a category $\\mc{C}$ consists of a collection\nof objects of $\\mc{C}$, with morphisms $\\Hom_{\\mc{C}'}(A, B) \\subseteq\n\\Hom_{\\mc{C}}(A, B)$ for all objects $A, B$ in $\\opn{Obj}(\\mc{C}')$, such that\nidentities and compositions in $\\mc{C}$ make $\\mc{C}'$ into a category. A\nsubcategory $\\mc{C}'$ is \\emph{full} if $\\Hom_{\\mc{C}'}(A, B) =\n\\Hom_{\\mc{C}}(A, B)$ for all $A, B$ in $\\opn{Obj}(\\mc{C}')$.\n\nWe can construct a category of \\emph{infinite sets} as follows. The objects of\nthis category are all infinite sets from $\\catname{Set}$, and morphisms from an\ninfinite set $A$ to another infinite set $B$ are just the usual set-functions.\nThen, it is clear that this category is indeed a full subcategory of\n$\\catname{Set}$.\n\\end{xca}\n\n\\begin{xca}\n% TODO: Chapter I - Exercise 3.9\n\\end{xca}\n\n\\begin{xca}\nGiven any set $A$ in $\\catname{Set}$, the subsets (subobjects) of $A$ are in a\none-to-one correspondence with functions $A \\to \\{ 0, 1\\}$. Thus, $\\Omega =\n\\{ 0, 1 \\}$ is a \\emph{subobject classifier} of $\\catname{Set}$.\n\\end{xca}\n\n\\begin{xca}\nThe category $\\mc{C}^{A, B}$ consists of the following pieces of data:\n\\begin{itemize}\n    \\item $\\opn{Obj}(\\mc{C}^{A, B})$ = diagrams\n    \\[\n    \\begin{tikzcd}\n        A \\arrow[rd, \"f\"] & \\\\\n        & Z \\\\\n        B \\arrow[ru, swap, \"g\"]\n    \\end{tikzcd}\n    \\]\n    \\item morphisms $(f_1: A \\to Z_1, g_1: B \\to Z_1) \\to (f_2: A \\to Z_2,\n    g_2: B \\to Z_2)$ are commutative diagrams\n    \\[\n    \\begin{tikzcd}\n        A \\arrow[rd, \"f_1\"]\n          \\arrow[rrd, bend left, \"f_2\"]\n          & & \\\\\n        & Z_1 \\arrow[r, swap, \"\\sigma\"]\n              & Z_2 \\\\\n        B \\arrow[ru, swap, \"g_1\"]\n          \\arrow[rru, swap, bend right, \"g_2\"]\n          & &\n    \\end{tikzcd}\n    \\]\n    \\item (Composition) Given commutative diagrams\n    \\[\n    \\begin{tikzcd}\n        A \\arrow[rd, \"f_1\"]\n          \\arrow[rrd, bend left, \"f_2\"]\n          \\arrow[rrrd, bend left, \"f_3\"]\n          & & & \\\\\n        & Z_1 \\arrow[r, swap, \"\\sigma\"]\n              & Z_2 \\arrow[r, swap, \"\\tau\"]\n              & Z_3 \\\\\n        B \\arrow[ru, swap, \"g_1\"]\n          \\arrow[rru, swap, bend right, \"g_2\"]\n          \\arrow[rrru, swap, bend right, \"g_3\"]\n          & & &\n    \\end{tikzcd},\n    \\]\n    the following diagram commutes:\n    \\[\n    \\begin{tikzcd}\n        A \\arrow[rd, \"f_1\"]\n        \\arrow[rrd, bend left, \"f_3\"]\n        & & \\\\\n        & Z_1 \\arrow[r, swap, \"\\tau \\circ \\sigma\"]\n        & Z_2 \\\\\n        B \\arrow[ru, swap, \"g_1\"]\n        \\arrow[rru, swap, bend right, \"g_3\"]\n        & &\n    \\end{tikzcd}\n    \\]\n    \\item (Identities) The identity morphism of\n    \\[\n    \\begin{tikzcd}\n        A \\arrow[rd, \"f\"] & \\\\\n          & Z \\\\\n        B \\arrow[ru, swap, \"g\"]\n    \\end{tikzcd}\n    \\]\n    is $Z \\xrightarrow{1_Z} Z$, thus making the following diagram commute:\n    \\[\n    \\begin{tikzcd}\n        A \\arrow[rd, \"f_1\"]\n          \\arrow[rrd, bend left, \"f_1\"]\n          & & \\\\\n        & Z_1 \\arrow[r, swap, \"1_Z\"]\n              & Z_1 \\\\\n        B \\arrow[ru, swap, \"f_2\"]\n          \\arrow[rru, swap, bend right, \"f_2\"]\n          & &\n        \\end{tikzcd}\n    \\]\n    \\end{itemize}~\\\\\n\n    Given a category $\\mc{C}$ and two fixed morphisms $\\alpha: C \\to A$ and\n    $\\beta: C \\to B$, the category $\\mc{C}^{\\alpha, \\beta}$ consists of the\n    following pieces of data:\n    \\begin{itemize}\n        \\item $\\opn{Obj}(\\mc{C}^{\\alpha, \\beta})$ = commutative diagrams\n        \\[\n        \\begin{tikzcd}\n            & A \\arrow[rd, \"f\"] & \\\\\n            C \\arrow[ru, \"\\alpha\"]\n              \\arrow[rd, swap, \"\\beta\"]\n              & & Z \\\\\n            & B \\arrow[ru, swap, \"g\"] &\n        \\end{tikzcd}\n        \\]\n        in $\\mc{C}$.\n        \\item Morphisms correspond to commutative diagrams\n        \\[\n        \\begin{tikzcd}\n            & A \\arrow[rd, \"f_1\"]\n                \\arrow[rrd, bend left, \"f_2\"] & \\\\\n            C \\arrow[ru, \"\\alpha\"]\n              \\arrow[rd, swap, \"\\beta\"]\n              & & Z_1 \\arrow[r, swap, \"\\sigma\"]\n                      & Z_2 \\\\\n            & B \\arrow[ru, swap, \"g1\"]\n                \\arrow[rru, swap, bend right, \"g_2\"] &\n        \\end{tikzcd}\n        \\]\n        \\item Composition and identities are defined in the obvious way.\n        \\item The usual composition and identity laws for $\\mc{C}^{\\alpha,\n        \\beta}$ follow from the composition and identity laws in $\\mc{C}$.\n    \\end{itemize}\n\\end{xca}\n\n\\section{Morphisms}\n\\begin{xca}\nSuppose $A_0 \\xrightarrow{f_1} A_1 \\xrightarrow{f_2} A_2 \\xrightarrow{f_3}\n\\ldots \\xrightarrow{f_n} A_n$ is a sequence of $n > 0$ morphisms in a\ncategory $\\mc{C}$. We claim any choice of placement of parentheses for $f_n\nf_{n-1} \\ldots f_1$ equals\n\\[(\\ldots ((f_n f_{n-1}) f_{n-2}) \\ldots) f_1.\\]\n\nWe use induction on $n$ to prove our claim.\n\n(Base cases) We note $f_1 = (f_1)$. And, also $f_2 f_1 = (f_2) f_1$. So the\nstatement holds for $n = 1, 2$.\n\n(Inductive case) Suppose the statement holds for some $n > 1$. Now, consider\nthe placement of parentheses for the expression $E = f_{n+1} f_n f_{n-1} \\ldots\nf_1$. Any such choice will correspond to a representation of $E$ in the form\n$e e'$, where both $e$ and $e'$ contain at least one term. This also implies\nboth $e$ and $e'$ contain at most $n$ terms. So, assume $e$ contains the terms\n$f_{n+1}, f_n, \\ldots, f_i$ and $e'$ contains the terms $f_{i-1}, \\ldots, f_1$\nfor some $1 < i \\le n + 1$. Then, by the inductive hypothesis,\n\\begin{align*}\n    e &= (((f_{n+1} f_n) \\ldots) f_i) \\\\\n    e' &= (f_{i-1}(\\ldots (f_2 f_1)))\n\\end{align*}\nThen, through repeated use of the associativity of morphisms under composition,\nwe have $E$ \\\\\n\\begin{tabular}{l l}\n    &= $e e'$ \\\\\n    &= $e (f_{i-1}(\\ldots (f_2 f_1)))$ \\\\\n    &= $((((e f_{i-1}) f_{i-2}) f_{i-3}) \\ldots) f_1$ \\\\\n    &= $(\\ldots ((f_{n+1} f_n) f_{n-1}) \\ldots) f_1$\n\\end{tabular}\n~\\\\\n\nSo, the statement holds for $n+1$ as well, and hence, by induction, the\nstatement holds for all naturals $n > 0$. And, we are done.\n\\end{xca}\n\n\\begin{xca}\nWe claim if a set $S$ is endowed with an equivalence relation $\\sim$, then the\ncorresponding category $\\mc{C}$ is a groupoid. Indeed, if $a \\to b$ is a\nmorphism in $\\mc{C}$, then $a \\sim b$, which (by symmetry) implies $b \\sim a$.\nThus, $b \\to a$, and since there is at most one morphism from any object\n(element) to another, we must have\n\\begin{align*}\n    a \\to b \\to a &= 1_a \\\\\n    b \\to a \\to b &= 1_b\n\\end{align*}\nHence, $a \\to b$ is an isomorphism, for all elements $a, b \\in S$, and thus,\n$\\mc{C}$ is a groupoid.\n\\end{xca}\n\n\\begin{xca}\nLet $A, B$ be objects of a category $\\mc{C}$, and let $f \\in \\Hom_{\\mc{C}}(A,\nB)$ be a morphism.\n\\begin{itemize}\n    \\item Suppose $f$ has a right inverse, $g: B \\to A$, say. Then, $f \\circ g\n    = 1_B$. Assume $Z$ is an object of $\\mc{C}$ and $\\beta, \\beta': B \\to Z$\n    morphisms such that $\\beta \\circ f = \\beta' \\circ f$. Then, $\\beta = \\beta\n    \\circ 1_B = \\beta \\circ (f \\circ g) = (\\beta \\circ f) \\circ g = (\\beta'\n    \\circ f) \\circ g = \\beta' \\circ (f \\circ g) = \\beta' \\circ 1_B = \\beta'$,\n    thus showing $f$ is an epimorphism.\n    \\item In $(\\Z, \\le)$, considered as a category, any morphism is an\n    epimorphism, but the same does not have a right inverse. For example, $1 \\le\n    2$, \\emph{i.e.} $1 \\to 2$. But, if the latter were to have a right inverse,\n    then we would have $2 \\to 1$, which would then imply $2 \\le 1$, clearly a\n    contradiction.\n\\end{itemize}\n\\end{xca}\n\n\\begin{xca}\nSuppose $A \\xrightarrow{f} B$ and $B \\xrightarrow{g} C$ are both monomorphisms\nin a category $\\mc{C}$. Let $Z$ be any object of $\\mc{C}$, and let $\\alpha',\n\\alpha'': Z \\to A$ be morphisms such that\n\\begin{center}\n    $(g \\circ f) \\circ \\alpha' = (g \\circ f) \\circ \\alpha''$.\n\\end{center}\nThen, $g \\circ (f \\circ \\alpha') = g \\circ (f \\circ \\alpha'')$, which implies\n$f \\circ \\alpha' = f \\circ \\alpha''$, which implies $\\alpha' = \\alpha''$. Hence,\n$g \\circ f$ is a monomorphism. This demonstrates the composition of two\nmonomorphisms is a monomorphism.\n\nNow, it is easy to check identity morphisms in $\\mc{C}$ are monomorphisms. Thus,\none can define a subcategory $\\mc{C}_{\\text{mono}}$ of a category $\\mc{C}$ by\ntaking the same objects as in $\\mc{C}$ and defining\n$\\Hom_{\\mc{C}_{\\text{mono}}}$ to be the subset of $\\Hom_{\\mc{C}}(A, B)$\nconsisting of monomorphisms, for all objects $A, B$ of $\\mc{C}$.\\\\\n\n(Epimorphisms) Suppose $A \\xrightarrow{f} B$ and $B \\xrightarrow{g} C$ are both\nepimorphisms in a category $\\mc{C}$. Let $Z$ be any object of $\\mc{C}$, and let\n$\\beta', \\beta'': C \\to Z$ be morphisms such that\n\\begin{center}\n    $\\beta' \\circ (g \\circ f) = \\beta'' \\circ (g \\circ f)$.\n\\end{center}\nThen, $(\\beta' \\circ g) \\circ f = (\\beta'' \\circ g) \\circ f$, which implies\n$\\beta' \\circ g = \\beta'' \\circ g$, which implies $\\beta' = \\beta''$, thus\nshowing $g \\circ f$ is an epimorphism. In a manner similar to the one shown\nabove, one can define a subcategory $\\mc{C}_{\\text{epi}}$ of a category\n$\\mc{C}$.\n\\end{xca}\n\n\\begin{xca}\n% TODO: Chapter I - Exercise 4.5\n\\end{xca}\n\n\\section{Universal properties}\n\\begin{xca}\nSuppose $F$ is a final object in a category $\\mc{C}$. Then, for all objects $A$\nof $\\mc{C}$, there exists a unique morphism $A \\to F$ in $C$, which implies for\nall objects $A$ of $\\mc{C}^{op}$, there exists a unique morphism $F \\to A$ in\n$\\mc{C}^{op}$. We thus conclude $F$ is initial in the opposite category\n$\\mc{C}^{op}$.\n\\end{xca}\n\n\\begin{xca}\nFor any set $A$, the function\n\\begin{center}\n    $\\emptyset \\xrightarrow{(\\emptyset, A, \\emptyset)} A$\n\\end{center}\n is the unique\nfunction from $\\emptyset$ to $A$. Thus, $\\emptyset$ is initial in\n$\\catname{Set}$. Now, suppose $I$ is a set that's also initial in\n$\\catname{Set}$. Then, $\\emptyset \\cong I$. Therefore, $|I| = |\\emptyset| = 0$,\nwhich implies $I = \\emptyset$. Hence, $\\emptyset$ is the unique initial object\nin $\\catname{Set}$.\n\\end{xca}\n\n\\begin{xca}\nSuppose $F_1$ and $F_2$ are final objects in a category $\\mc{C}$. Then, there\nare unique morphisms $F_1 \\to F_2$ and $F_2 \\to F_1$. So, we must have\n\\begin{center}\n    $F_1 \\to F_2 \\to F_1 = 1_{F_1}$ \\\\\n    $F_2 \\to F_1 \\to F_2 = 1_{F_2}$\n\\end{center}\nThus, $F_1 \\cong F_2$, and hence, we conclude final objects are unique up to\nisomorphism.\n\\end{xca}\n\n\\begin{xca}\nIn the category $\\catname{Set}^*$ of pointed sets, any object $(\\{*\\}, *)$ is\nboth an initial and a final object.\n\\end{xca}\n\n\\begin{xca}\nThe final objects considered in the category considered in \\textsection 5.3 are\n$A \\to \\{ \\bullet \\}$.\n\\end{xca}\n\n\\begin{xca}\nConsider the category corresponding to endowing the set $\\Z^+$ of positive\nintegers with the \\emph{divisibility} relation. Then, for any two positive\nintegers $m, n$, if their product $m \\times n$ exists, then $m \\times n$\ndivides both $m$ and $n$, and further, if some positive integer $d$ divides\nboth $m$ and $n$, then $d$ divides $m \\times n$. $\\gcd(m, n)$ satisfies the\naforesaid condition, and hence, it is the product of $m$ and $n$. Similarly, it\nis easy to check $\\lcm(m, n)$ is the coproduct of any two positive integers $m$\nand $n$.\n\\end{xca}\n\n\\begin{xca}\nSuppose $A' \\cong A''$ and $B' \\cong B''$, and further, $A' \\cap B' = \\emptyset$\nand $A'' \\cap B'' = \\emptyset$. Then, there exist isomorphisms $k: A' \\to B'$\nand $l: B' \\to B''$, say. We claim\n\\[\nA' \\xrightarrow{i_{A'}} A' \\cup B' \\xleftarrow{i_{B'}} B',\n\\]\nwhere $i_{A'}, i_{B'}$ are inclusion functions, is the coproduct of $A'$ and\n$B'$.\n\nToward that end, for any set $C$ and functions $A' \\xrightarrow{f} C\n\\xleftarrow{g} B'$, we define a function $h: A' \\cup B' \\to C$ by\n\\[\nh(x) =\n    \\begin{cases}\n        f(x) & \\text{if } x \\in A' \\\\\n        g(x) & \\text{if } x \\in B'\n    \\end{cases}\n\\]\nThen, it is easy to check the following diagram commutes:\n\\[\n\\begin{tikzcd}\n    & C & \\\\\n    A' \\arrow[r, swap, \"i_{A'}\"]\n       \\arrow[ur, \"f\"]\n       & A' \\cup B' \\arrow[u, swap, dashed, \"h\"]\n                    & B' \\arrow[l, \"i_{B'}\"]\n                         \\arrow[ul, swap, \"g\"]\n\\end{tikzcd}\n\\]\nAlso, $h$ is necessarily the unique function $A' \\cup B' \\to C$ that makes the\nabove diagram commute.\n\nWe next verify\n\\[\nA' \\xrightarrow{k \\circ i_{A'}} A'' \\cup B'' \\xleftarrow{l \\circ i_{B'}} B'\n\\]\nis also a coproduct of $A'$ and $B'$. Indeed, for any set $C$ and functions\n$A' \\xrightarrow{f} C \\xleftarrow{g} B'$, we define a function $h': A'' \\cup B''\n\\to C$ by\n\\[\nh'(x) =\n    \\begin{cases}\n        f \\circ k^{-1}(x) & \\text{if } x \\in A'' \\\\\n        g \\circ l^{-1}(x) & \\text{if } x \\in B''\n    \\end{cases}\n\\]\nIt is, again, easy to check the following diagram commutes:\n\\[\n\\begin{tikzcd}\n    & C & \\\\\n    A' \\arrow[r, swap, \"k \\circ i_{A'}\"]\n       \\arrow[ur, \"f\"]\n       & A'' \\cup B'' \\arrow[u, swap, dashed, \"h'\"]\n                    & B' \\arrow[l, \"l \\circ i_{B'}\"]\n                         \\arrow[ul, swap, \"g\"]\n\\end{tikzcd}\n\\]\nAlso, $h''$ is necessarily the unique function $A'' \\cup B'' \\to C$ that makes\nthe above diagram commute.\n\nThus, we see both $A' \\cup B'$ and $A'' \\cup B''$ along with their associated\nfunctions are coproducts of $A'$ and $B'$, and hence, we conclude they are\nisomorphic to each other.\n\\end{xca}\n\n\\begin{xca}\nSuppose $\\mc{C}$ is a category and $A, B$ are objects of $\\mc{C}$. Assume the\nproducts $A \\leftarrow A \\times B \\to B$ and $B \\leftarrow B \\times A \\to A$\nexist. Then, for all sets $C$ and functions $A \\xleftarrow{f} C \\xrightarrow{g}\nB$, there exists a unique function $\\langle f, g \\rangle: C \\to A \\times B$\nsuch that the following diagram commutes:\n\\[\n\\begin{tikzcd}\n    & C \\arrow[ld, swap, \"f\"]\n        \\arrow[rd, \"g\"]\n        \\arrow[d, dashed, \"\\langle {f, g} \\rangle\"] & \\\\\n    A & A \\times B \\arrow[l]\n                   \\arrow[r]\n                   & B\n\\end{tikzcd}\n\\]\nThis implies there is a unique function $\\langle g, f \\rangle: C \\to B \\times A$\nsuch that the following diagram commutes:\n\\[\n\\begin{tikzcd}\n    & C \\arrow[ld, swap, \"g\"]\n        \\arrow[rd, \"f\"]\n        \\arrow[d, dashed, \"\\langle {g, f} \\rangle\"] & \\\\\n    B & B \\times A \\arrow[l]\n                   \\arrow[r]\n                   & A\n\\end{tikzcd}\n\\]\nWe thus see both $A \\leftarrow A \\times B \\to B$ and $B \\leftarrow B \\times A\n\\to A$ satisfy the universal property for the product of $A$ and $B$. That is,\nthey are both final objects in the corresponding category, and hence, by\nProposition 5.4, they are isomorphic.\n\\end{xca}\n\n\\begin{xca}\nLet $\\mc{C}$ be a category with products. For any three objects $A, B, C$ of\n$\\mc{C}$, their product $A \\times B \\times C$ satisfies the following\nproperty:\\\\\nThe product is equipped with morphisms $A \\times B \\times C \\to A$, $A \\times B\n\\times C \\to B$ and $A \\times B \\times C \\to C$ such that, for all objects $D$\nand morphisms $f: D \\to A$, $g: D \\to B$ and $h: C \\to C$, there is a unique\nmorphism $\\langle f, g, h \\rangle: D \\to A \\times B \\times C$, making the\nfollowing diagram commute:\n\\[\n\\begin{tikzcd}\n    & D \\arrow[ddl, swap, bend right, \"f\"]\n        \\arrow[ddd, bend left, crossing over, \"g\", near end]\n        \\arrow[ddr, bend left, \"h\"]\n        \\arrow[d, swap, dashed, \"\\langle {f, g, h} \\rangle\"]\n        & \\\\\n    & A \\times B \\times C \\arrow[dl]\n                          \\arrow[dd]\n                          \\arrow[dr, crossing over]\n                          & \\\\\n    A & & C \\\\\n    & B &\n\\end{tikzcd}\n\\]\nA routine check can verify $\\langle f, \\langle g, h \\rangle \\rangle: D \\to\nA \\times (B \\times C)$ satisfies the aforesaid universal property, and so does\n$\\langle \\langle f, g \\rangle, h \\rangle: D \\to (A \\times B) \\times C$. Hence,\n$A \\times (B \\times C)$ and $(A \\times B) \\times C$ are isomorphic.\n\\end{xca}\n\n\\begin{xca}\n(Product) Let $\\mc{C}$ be a category, and let $\\{ A_i \\}_{i \\in I}$ be a family\nof objects $A_i$ of $\\mc{C}$ indexed by some set $I$. The product of the\nfamily of objects $A_i$ ($i \\in I$) is an object\n\\[\n\\prod_{i \\in I} A_i\n\\]\nof $\\mc{C}$ equipped with a family of morphisms\n\\[\np_j : \\prod_{i \\in I} A_i \\to A_j \\q (j \\in I)\n\\]\nsuch that, for all objects $Z$ and morphisms $q_j : Z \\to A_j$ ($j \\in I$),\nthere exists a unique morphism $h: Z \\to \\prod_{i \\in I} A_i$ such that\n\\[\np_j \\circ h = q_j \\q (j \\in I)\n\\]\n\n(Coproduct) The coproduct of the family of objects $A_i$ ($i \\in I$) is an\nobject\n\\[\n\\coprod_{i \\in I} A_i\n\\]\nof $\\mc{C}$ equipped with a family of morphisms\n\\[\np_j : A_j \\to \\coprod_{i \\in I} A_i \\q (j \\in I)\n\\]\nsuch that, for all objects $Z$ and morphisms $q_j : A_j \\to Z$ ($j \\in I$),\nthere exists a unique morphism $h: \\coprod_{i \\in I} A_i \\to Z$ such that\n\\[\nh \\circ p_j = q_j \\q (j \\in I)\n\\]\n\nThese exist in $\\catname{Set}$ if we assume the \\emph{axiom of choice}.\n\\end{xca}\n\n\\begin{xca}\nLet $A$, resp. $B$, be a set, endowed with an equivalence relation $\\sim_A$,\nresp. $\\sim_B$. Define a relation $\\sim$ on $A \\times B$ by setting\n\\[\n(a_1, b_1) \\sim (a_2, b_2) \\iff a_1 \\sim_A a_2 \\text{ and } b_1 \\sim_B b_2\n\\]\nWe can easily check $\\sim$ is an equivalence relation on $A \\times B$.\n\\begin{itemize}\n    \\item The composite of the first projection function $\\pi_A: A \\times B \\to\n    A$ and the natural surjection $\\pi_{\\sim_A}: A \\to A/{\\sim_A}$ is a\n    function $A \\times B \\xrightarrow{\\pi_{\\sim_A} \\circ \\pi_A} A/{\\sim_A}$.\n    Note, if $(a_1, b_1) \\sim (a_2, b_2)$, then $a_1 \\sim_A a_2$, and thus,\n    $\\pi_{\\sim_A} \\circ \\pi_A (a_1, b_1) = \\pi_{\\sim_A}(a_1) = [a_1]_{\\sim_A}\n    = [a_2]_{\\sim_A} = \\pi_{\\sim_A} \\circ \\pi_A (a_2, b_2)$. That is,\n    equivalent elements in $A \\times B$ have the same image in $A/{\\sim_A}$\n    under the map $\\pi_{\\sim_A} \\circ \\pi_A$. Therefore, by the universal\n    property of quotients, there exists a unique function $\\varphi_A: A \\times\n    B /{\\sim} \\to A/{\\sim_A}$, given by\n    \\[\n    \\varphi_A([(a, b)]_{\\sim}) = \\pi_{\\sim_A} \\circ \\pi_A (a, b)\n    \\]\n    such that the following diagram commutes:\n    \\[\n    \\begin{tikzcd}\n        A \\times B /{\\sim} \\arrow[rr, \"\\varphi_A\"]\n                           & & A/{\\sim_A} \\\\\n        & & \\\\\n        & A \\times B \\arrow[uul, \"\\pi_{\\sim_{A \\times B}}\"]\n                     \\arrow[uur, swap, \"\\pi_{\\sim_A} \\circ \\pi_A\"]\n                     &\n    \\end{tikzcd}\n    \\]\n    Similarly, by the universal property of quotients, there exists a unique\n    function $\\varphi_B: A \\times B /{\\sim} \\to B/{\\sim_B}$, given by\n    \\[\n    \\varphi_B([(a, b)]_{\\sim}) = \\pi_{\\sim_B} \\circ \\pi_B (a, b)\n    \\]\n    such that the following diagram commutes:\n    \\[\n    \\begin{tikzcd}\n        A \\times B /{\\sim} \\arrow[rr, \"\\varphi_B\"]\n                           & & B/{\\sim_B} \\\\\n    & & \\\\\n    & A \\times B \\arrow[uul, \"\\pi_{\\sim_{A \\times B}}\"]\n                 \\arrow[uur, swap, \"\\pi_{\\sim_B} \\circ \\pi_B\"]\n                 &\n    \\end{tikzcd}\n    \\]\n    The above, thus, demonstrates there are functions $A \\times B /{\\sim} \\to\n    A/{\\sim_A}$ and $A \\times B /{\\sim} \\to B/{\\sim_B}$.\n\n    \\item We now claim $A/{\\sim_A} \\xleftarrow{\\varphi_A} A \\times B /{\\sim}\n    \\xrightarrow{\\varphi_B} B/{\\sim_B}$ is the product of $A/{\\sim_A}$ and\n    $B/{\\sim_B}$.\n\n    To that end, suppose $C$ is any set, endowed with an equivalence relation\n    $\\sim_C$. Let $A/{\\sim_A} \\xleftarrow{f} C \\xrightarrow{g} B/{\\sim_B}$ be\n    functions, such that, for all $c_1, c_2 \\in C$,\n    \\begin{center}\n        $c_1 \\sim_C c_2 \\implies f(c_1) = f(c_2)$ and $g(c_1) = g(c_2)$. \\\\\n    \\end{center}\n\n    Now, define a function $h: C \\to A \\times B /{\\sim}$ by\n    \\begin{align*}\n        h(c) &= [(a, b)]_{\\sim}, \\text{ where} \\\\\n        f(c) &= [a]_{\\sim_A} \\text{ for some } a \\in A, \\text{ and} \\\\\n        g(c) &= [b]_{\\sim_B} \\text{ for some } b \\in B.\n    \\end{align*}\n    Then, $h$ is the unique function $C \\to A \\times B /{\\sim}$ that makes the\n    following diagram commute:\n    \\[\n    \\begin{tikzcd}\n        & C \\arrow[ddl, swap, \"f\"]\n            \\arrow[ddr, \"g\"]\n            \\arrow[dd, dashed, \"h\"]\n            & \\\\\n        & & \\\\\n        A/{\\sim_A} & A \\times B /{\\sim} \\arrow[l, \"\\varphi_A\"]\n                                        \\arrow[r, swap, \"\\varphi_B\"]\n                                        & B/{\\sim_B}\n    \\end{tikzcd}\n    \\]\n    We can easily verify, for all $c \\in C$,\n    \\begin{align*}\n        \\varphi_A \\circ h(c) &= \\varphi_A([(a, b)]_{\\sim}) \\\\\n                             &= \\pi_{\\sim_A} \\circ \\pi_A (a, b) \\\\\n                             &= \\pi_{\\sim_A}(a) \\\\\n                             &= [a]_{\\sim_A} \\\\\n                             &= f(c)\n    \\end{align*}\n    That is, $\\varphi_A \\circ h = f$. Similarly, it is easy to check\n    $\\varphi_B \\circ h = g$. Also, it is necessarily the case that $h$ as\n    defined is unique. Hence, our claim is proved.\n\n    \\item From the previous proof, it immediately follows\n    \\[\n    A \\times B /{\\sim} \\cong (A/{\\sim_A}) \\times (B/{\\sim_B}).\n    \\]\n\\end{itemize}\n\\end{xca}\n\n\\begin{xca}\nLet $\\mc{C}$ be a category, and let $X \\xrightarrow{\\alpha} Z \\xleftarrow{\\beta}\nY$ be two fixed morphisms in $\\mc{C}$.\n\nThen, the \\emph{fibered product} of $\\alpha$ and $\\beta$ is a final object\n$X \\xleftarrow{f} P \\xrightarrow{g} Y$ in the category $\\mc{C}_{\\alpha, \\beta}$.\nThat is, for all objects $X \\xleftarrow{f_1} Q \\xrightarrow{g_1} Y$ that makes\nthe following diagram commute\n\\[\n\\begin{tikzcd}\n    Q \\arrow[ddr, swap,  bend right, \"f_1\"]\n      \\arrow[drr, bend left, \"g_1\"]\n      & & \\\\\n    & & Y \\arrow[d, \"\\beta\"] \\\\\n    & X \\arrow[r, swap, \"\\alpha\"]\n      & Z\n\\end{tikzcd}\n\\]\nthere exists a unique morphism $h: Q \\to P$ that makes the following diagram\ncommute\n\\[\n\\begin{tikzcd}\n    Q \\arrow[ddr, swap,  bend right, \"f_1\"]\n      \\arrow[drr, bend left, \"g_1\"]\n      \\arrow[dr, dashed, \"h\"]\n      & & \\\\\n    & P \\arrow[r, \"g\"]\n        \\arrow[d, swap, \"f\"]\n        & Y \\arrow[d, \"\\beta\"] \\\\\n    & X \\arrow[r, swap, \"\\alpha\"]\n        & Z\n\\end{tikzcd}\n\\]\n\nIn $\\catname{Set}$, the fibered product of two functions $X \\xrightarrow{\\alpha}\nZ \\xleftarrow{\\beta} Y$ is the object\n\\[\nX \\xleftarrow{\\pi_X} X \\times_Z Y \\xrightarrow{\\pi_Y} Y,\n\\]\nwhere $X \\times_Z Y := \\{ (x, y) \\in X \\times Y \\mid \\alpha(x) = \\beta(y) \\}$,\nand $\\pi_X$ and $\\pi_Y$ are the canonical projection functions. \\\\\n\nLet $\\mc{C}$ be a category, and let $X \\xleftarrow{\\alpha} Z \\xrightarrow{\\beta}\nY$ be two fixed morphisms in $\\mc{C}$. Then, the \\emph{fibered coproduct} of\n$\\alpha$ and $\\beta$ is an initial object $X \\xrightarrow{f} P \\xleftarrow{g}\nY$ in the category $\\mc{C}^{\\alpha, \\beta}$.\n\\end{xca}\n", "meta": {"hexsha": "992cf4f8fc44a7a526235034034b1d0821ca2f95", "size": 41301, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/set-theory-and-categories.tex", "max_stars_repo_name": "vishallama/algebra-chapter0", "max_stars_repo_head_hexsha": "cef5cc84416953797e93b8da3ccf13d436b192be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-02-05T20:56:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T09:21:00.000Z", "max_issues_repo_path": "chapters/set-theory-and-categories.tex", "max_issues_repo_name": "vishallama/algebra-chapter0", "max_issues_repo_head_hexsha": "cef5cc84416953797e93b8da3ccf13d436b192be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/set-theory-and-categories.tex", "max_forks_repo_name": "vishallama/algebra-chapter0", "max_forks_repo_head_hexsha": "cef5cc84416953797e93b8da3ccf13d436b192be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7507218479, "max_line_length": 80, "alphanum_fraction": 0.5953366747, "num_tokens": 14976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8976952825278492, "lm_q1q2_score": 0.8265885443451008}}
{"text": "\n\\subsection{Bilinear forms}\n\nA bilinear form takes two vectors and produces a scalar from the underyling field.\n\nThis is in contrast to a linear form, which only has one input.\n\nIn addition, the function is linear in both arguments.\n\n\\(\\phi (au+x, bv+y)=\\phi (au,bv)+\\phi (au,y)+\\phi (x,bv)+\\phi (x,y)\\)\n\n\\(\\phi (au+x, bv+y)=ab\\phi (u,v)+a\\phi (u,y)+b\\phi (x,v)+\\phi (x,y)\\)\n\n\\subsubsection{Representing bilinear forms}\n\nThey can be represented as:\n\n\\(\\phi (u,v)=v^TMu\\)\n\n\\(f(M)=f([v_1,v_2])\\)\n\nWe introduce \\(e_i\\), the element vector. This is \\(0\\) for all entries except for \\(i\\) where it is \\(1\\). Any vector can be shown as a sum of these vectors multiplied by a scalar.\n\n\\(f(M)=f([\\sum^m_{i=1}a_{1i}e_i,\\sum^m_{i=1}a_{2i}e_i])\\)\n\n\\(f(M)=\\sum_{k=1}^mf([a_{1k}e_k,\\sum^m_{i=1}a_{2i}e_i])\\)\n\n\\(f(M)=\\sum_{k=1}^m\\sum^m_{i=1}f([a_{1k}e_k,a_{2i}e_i])\\)\n\nBecause this in linear in scalars:\n\n\\(f(M)=\\sum_{k=1}^m\\sum^m_{i=1}a_{1k}a_{2i}f([e_k,e_i])\\)\n\n\\(f(M)=\\sum_{k=1}^m\\sum^m_{i=1}a_{1k}a_{2i}e_k^TMe_i\\)\n\n\\subsubsection{Orthonormal basis and \\(M=I\\)}\n\n\\(f(M)=\\sum_{k=1}^m\\sum^m_{i=1}a_{1k}a_{2i}e_k^Te_i\\)\n\n\\(f(M)=\\sum_{k=1}^m\\sum^m_{i=1}a_{1k}a_{2i}\\delta_i^k\\)\n\n\\(f(M)=\\sum^m_{i=1}a_{1i}a_{2i}\\)\n\n", "meta": {"hexsha": "225caa208f00ee66a064e4f533da273fa53b8ba2", "size": 1201, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/02-01-bilinearForms.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/forms/02-01-bilinearForms.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/forms/02-01-bilinearForms.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2954545455, "max_line_length": 181, "alphanum_fraction": 0.6278101582, "num_tokens": 544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191271831559, "lm_q2_score": 0.8652240947405564, "lm_q1q2_score": 0.8265651270053845}}
{"text": "\\chapter{Introduction, Wiener-Hopf Equations, and Normal Equations}\n\\label{ch:intro_WHE_NE}\n\\section{Review of the Basics}\n\\subsection{Linear Algebra}\n\\subsubsection{Notation}\nAn $N$-dimensional vector is written as\n\\bmath\n  \\vect{x} = \\bbmtx x_1 \\\\ x_2 \\\\ \\vdots \\\\ x_N \\ebmtx = \\bbmtx x_1 & x_2 & \\cdots & x_N \\ebmtx^T\n\\emath\nwhere $(\\cdot)^T$ denotes the transpose. An $N\\times M$-dimensional matrix is written as\n\\bmath\n  \\vect{A} =\n  \\bbmtx\n    a_{11} & \\cdots & a_{1M}\\\\\n    \\vdots & \\ddots & \\vdots\\\\\n    a_{N1} & \\cdots & a_{NM}\\\\\n  \\ebmtx\\ .\n\\emath\n\\subsubsection{Matrix Properties}\nLet $\\vect{A}$ be a square matrix. We then have that\n\\begin{alignat}{3}\n  &\\vect{A}\\text{ is orthogonal}    &\\ &\\iff &\\ \\vect{A}^T&=\\vect{A}^{-1}\\ \\iff\\ \\vect{I} = \\vect{AA}^T =  \\vect{A}^T\\vect{A}\\\\\n  &\\vect{A}\\text{ is symmetric}     &\\ &\\iff &\\ \\vect{A}^T&=\\vect{A}\\\\\n  &\\vect{A}\\text{ is skew-symmetric}&\\ &\\iff &\\ \\vect{A}^T&=-\\vect{A}\\ .\n\\end{alignat}\nLet $Q(\\vect{x}) = \\vect{x}^T\\vect{Ax}$ where $\\vect{A}$ is a square and symmetric matrix. We then have that\n\\begin{alignat*}{4}\n  &\\vect{A}\\text{ is positive definite (p.d.)}      &\\ &\\iff &\\ Q(\\vect{x})&>    0   &\\quad &\\forall\\ \\vect{x}\\neq 0\\\\\n  &\\vect{A}\\text{ is positive semidefinite (p.s.d.)}&\\ &\\iff &\\ Q(\\vect{x})&\\geq 0   &\\quad &\\forall\\ \\vect{x}\\\\\n  &\\vect{A}\\text{ is negative definite (n.d.)}      &\\ &\\iff &\\ Q(\\vect{x})&<    0   &\\quad &\\forall\\ \\vect{x}\\neq 0\\\\\n  &\\vect{A}\\text{ is negative semidefinite (n.s.d.)}&\\ &\\iff &\\ Q(\\vect{x})&\\leq 0   &\\quad &\\forall\\ \\vect{x}\\\\\n  &\\vect{A}\\text{ is indefinite otherwise.}         & &      &             &         &\\quad &\n\\end{alignat*}\nThe interested reader can find more on linear algebra in for example \\cite{Lay2005} and \\cite{Strang2009}.\n\n\\subsection{Optimisation}\n\\label{ssec:optimisation}\n\\subsubsection{Gradiant and Hessian}\nLet $f(\\vect{x})$ be a scalar function with continuous second-order partial derivatives. The gradient vector of $f(\\vect{x})$ is defined as\n\\bmath\n  \\vect{g}(\\vect{x}) = \\vect{\\nabla}f(\\vect{x}) = \\frac{\\partial f}{\\partial\\vect{x}} = \\bbmtx\\frac{\\partial f}{\\partial x_1} & \\frac{\\partial f}{\\partial x_2} & \\cdots & \\frac{\\partial f}{\\partial x_N}\\ebmtx^T\\ .\n\\emath\nThe Hessian matrix of $f(\\vect{x})$ is symmetric and defined as\n\\begin{align}\n  \\vect{H}(\\vect{x}) &= \\vect{\\nabla}[\\vect{g}^T(\\vect{x})] = \\vect{\\nabla}[\\vect{\\nabla}^Tf(\\vect{x})] = \\frac{\\partial^2 f}{\\partial\\vect{x}\\partial\\vect{x}^T}\\notag\\\\\n  &= \n  \\bbmtx\n    \\frac{\\partial^2 f}{\\partial x_1^2} & \\cdots & \\frac{\\partial^2 f}{\\partial x_1\\partial x_N}\\\\\n    \\vdots & \\ddots & \\vdots\\\\\n    \\frac{\\partial^2 f}{\\partial x_N\\partial x_1} & \\cdots & \\frac{\\partial^2 f}{\\partial x_N^2}\n   \\ebmtx\\ .\n\\end{align}\nWhen $f(\\vect{x})$ consists of a constant term, we have that\n\\bmathnt\n  f(\\vect{x}) = \\vect{c}\\ \\implies\n  \\begin{cases}\n    \\vect{g}(\\vect{x})=\\vect{0}\\\\\n    \\vect{H}(\\vect{x})=\\vect{0}\\\\\n  \\end{cases}\\ .\n\\emathnt\nWhen $f(\\vect{x})$ consists of a linear term, we have that\n\\bmathnt\n  f(\\vect{x}) = \\vect{v}^T\\vect{x} = \\vect{x}^T\\vect{v}\\ \\implies\n  \\begin{cases}\n    \\vect{g}(\\vect{x})=\\vect{v}\\\\\n    \\vect{H}(\\vect{x})=\\vect{0}\\\\\n  \\end{cases}\\ .\n\\emathnt\nWhen $f(\\vect{x})$ consists of a quadratic term, we have that\n\\bmathnt\n  f(\\vect{x}) = \\vect{x}^T\\vect{Ax}\\ \\implies\n  \\begin{cases}\n    \\vect{g}(\\vect{x})=(\\vect{A}+\\vect{A}^T)\\vect{x} = 2\\vect{Ax}\\\\\n    \\vect{H}(\\vect{x})=\\vect{A}+\\vect{A}^T = 2\\vect{A}\\\\\n  \\end{cases}\n\\emathnt\nwhere the last equality for the gradient and the Hessian holds if and only if $\\vect{A}$ is symmetric.\n\\subsubsection{Unconstrained Optimisation}\nWe can solve an unconstrained optimisation problem by following a five step recipe.\n\\begin{enumerate}\n  \\item Construct the cost function $f(\\vect{x})$.\n  \\item Find the gradient $\\vect{g}(\\vect{x})=\\frac{\\partial f}{\\partial\\vect{x}}$.\n  \\item Solve $\\vect{g}(\\vect{x})=\\vect{0}$ for $\\vect{x}$. The solutions $\\{\\vect{x}_i\\}$ are called critical points.\n  \\item Find the Hessian $\\vect{H}(\\vect{x})=\\frac{\\partial^2 f}{\\partial\\vect{x}\\partial\\vect{x}^T}$ and compute it for all the critical points. If\n\\begin{alignat*}{3}\n  &\\vect{H}(\\vect{x}_i)\\text{ is p.d}           &\\ &\\implies &\\ &f(\\vect{x}_i)\\text{ is a local minimum}\\\\\n  &\\vect{H}(\\vect{x}_i)\\text{ is n.d}           &\\ &\\implies &\\ &f(\\vect{x}_i)\\text{ is a local maximum}\\\\\n  &\\vect{H}(\\vect{x}_i)\\text{ is indefinite}    &\\ &\\iff     &\\ &f(\\vect{x}_i)\\text{ is a saddle point}\\\\\n  &\\vect{H}(\\vect{x}_i)\\text{ is p.s.d or n.s.d}&\\ &\\iff     &\\ &\\text{further analysis is necessary \\cite[p.~41]{Antoniou2007}}\n\\end{alignat*}\n  \\item Find the global minimiser/maximiser by evaluating $f(\\vect{x}_i)$ for every critical point.\n\\end{enumerate}\nIf $f(\\vect{x})$ is a convex\\footnote{If we should be completely accurate, we should distinguish between weakly and strictly convex functions. However, in this note, we only use convexity in the strict sense.} function, we have the following useful fact \\cite[p.~57]{Antoniou2007}\n\\bmathnt\n  f(\\vect{x})\\text{ is a convex function}\\ \\iff\\ \\vect{H}(\\vect{x})\\text{ is p.d. }\\forall\\ \\vect{x}\\ .\n\\emathnt\nThus, there is only one critical point corresponding to a minimum if and only if $f(\\vect{x})$ is a convex function.\n\nThe interested reader can find more on optimisation in for example \\cite{Antoniou2007} and \\cite{Boyd2004}.\n\n\\subsection{Stochastic Processes}\nLet $X(n)$ for $n=n_0,n_0+1,\\ldots,n_0+N-1$ be a stochastic process with joint probability density function (pdf) $p_X(x(n_0),x(n_0+1),\\ldots,x(n_0+N-1))$.\n\\subsubsection{Mean, Covariance and Correlation}\nThe mean, covariance and correlations sequences are defined as\n\\begin{alignat}{2}\n  &\\text{Mean sequence:}       &\\quad \\mu_X(n)  ={}&E[X(n)] = \\int x(n)p_X(x(n))dx(n)\\\\\n  &\\text{Covariance sequence:} &\\quad c_X(n,n+k)={}&\\text{cov}(X(n),X(n+k))\\notag\\\\\n  &                            &\\quad           ={}& E[(X(n)-\\mu_X(n)) (X(n+k)-\\mu_X(n+k))]\\\\\n  &\\text{Correlation sequence:}&\\quad r_X(n,n+k)={}& E[X(n)X(n+k)]\\ ,\n\\end{alignat}\nand they are related by\n\\bmath\n  c_X(n,n+k) = r_X(n,n+k) - \\mu_X(n)\\mu_X(n+k)\\ .\n\\emath\nFor a finite number of observation, we may define the mean vector\n\\bmath\n  \\vect{\\mu}_X = \\bbmtx\\mu_X(n_0) &\\mu_X(n_0+1)&\\cdots & \\mu_X(n_0+N-1)\\ebmtx^T\\ ,\n\\emath\nthe covariance matrix\n\\bmath\n  \\vect{C}_X =\n  \\bbmtx\n    c_X(n_0,n_0) & \\cdots & c_X(n_0,n_0+N-1)\\\\\n    \\vdots & \\ddots & \\vdots\\\\\n    c_X(n_0+N-1,n_0) & \\cdots & c_X(n_0+N-1,n_0+N-1)\\\\\n  \\ebmtx\\ ,\n\\emath\nand the correlation matrix\n\\bmath\n  \\vect{R}_X =\n  \\bbmtx\n    r_X(n_0,n_0) & \\cdots & r_X(n_0,n_0+N-1)\\\\\n    \\vdots & \\ddots & \\vdots\\\\\n    r_X(n_0+N-1,n_0) & \\cdots & r_X(n_0+N-1,n_0+N-1)\\\\\n  \\ebmtx\\ .\n\\emath\nThey are related by\n\\bmath\n  \\vect{C}_X = \\vect{R}_X - \\vect{\\mu}_X\\vect{\\mu}_X^T\\ .\n\\emath\n$\\vect{C}_X$ and $\\vect{R}_X$ are symmetric and p.s.d. They are p.d. if $X(n)$ is \\textit{not} perfectly predictable.\n\\subsubsection{Stationarity and Wide Sense Stationarity (WSS)}\n\\begin{alignat*}{3}\n  &X(n)\\text{ is stationary} &\\ &\\iff &\\ & p_X(x(n_0+m),x(n_0+1+m),\\ldots,x(n_0+N-1+m))\\\\\n  &{}\\qquad\\Downarrow        &  &     &  &{}\\ =p_X(x(n_0),x(n_0+1),\\ldots,x(n_0+N-1))\\quad \\forall\\  n_0,m,N\\\\\n  &X(n)\\text{ is WSS}        &\\ &\\iff &\\ &\n  \\begin{cases}\n    \\mu_X(n) = \\mu_X & \\text{(a constant)}\\\\\n    r_X(n,n+k) = r_X(0,k) & \\text{(a function of $k$ not $n$)}\n  \\end{cases}\n\\end{alignat*}\nSince $r_X(0,k)$ does not depend on $n$, it is often written as $r_X(k)$. A Venn diagram for all stochastic processes is shown in Fig.~\\ref{fig:rand_proc_relation}.\n\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/rand_proc_relation}\n  \\caption{A Venn diagram for all stochastic processes.}\n  \\label{fig:rand_proc_relation}\n\\end{figure}\n\nLet $Y(n)$ be another stochastic process.\n\\bmathnt\n  X(n) \\text{ and } Y(n) \\text{ are jointly WSS }\\iff\\ \n  \\begin{cases}\n    X(n) \\text{ is WSS}\\\\\n    Y(n) \\text{ is WSS}\\\\\n    r_{X,Y}(n,n+k) = r_{X,Y}(0,k)\n  \\end{cases}\n\\emathnt\nwhere $r_{X,Y}(n,n+k)$ is the cross-correlation sequence.\n\\subsubsection{Estimation of Statistics}\nOften, we wish to estimate the statistics of $X(n)$ from a single realisation $x(n)$. If $X(n)$ is (wide sense) stationary and \\textit{ergodic}\\footnote{Ergodicity basically means that we can infer something about the statistics of a stochastic process from a single realisation of it.} in some sense (for example, in mean, in correlation, in power, or in distribution), we may estimate some or all of its statistics from a single realisation $x(n)$. Examples are the unbiased estimators of the mean\n\\bmath\n  \\hat{\\mu}_X = \\frac{1}{N}\\sum_{n=n_0}^{n_0+N-1} x(n)\n\\emath\nand the correlation sequence\n\\bmath\n  \\hat{r}_X(k) = \\frac{1}{N-k}\\sum_{n=n_0}^{n_0+N-1-k} x(n)x(n+k)\\ .\n\\emath\n\nThe interested reader can find more on stochastic processes in for example \\cite{Kay2005} and \\cite{Leon-Garcia2008}.\n\n\\section{Block Diagram of Adaptive Filtering}\nThe adaptive filtering problem is shown in Fig.~\\ref{fig:wss_block_diagram}.\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/wss_block_diagram}\n  \\caption{Block Diagram of Adaptive Filtering in a WSS environment.}\n  \\label{fig:wss_block_diagram}\n\\end{figure}\nFrom the figure, we have that\n\\begin{itemize}\n  \\item[$u(n)$:] zero-mean, WSS input signal\n  \\item[$w_m$:] $M$-tap FIR-filter with impulse response $w_0,w_1,\\ldots,w_{M-1}$\n  \\item[$y(n)$:] output signal given by \n  \\bmath\n    y(n) = \\sum_{m=0}^{M-1}w_m u(n-m)\n  \\emath\n  \\item[$d(n)$:] zero-mean, WSS desired signal\n  \\item[$e(n)$:] error signal\n\\end{itemize}\nMoreover, $u(n)$ and $d(n)$ are assumed to be jointly WSS.\n\\subsection{Mean-Squared Error and Squared Error cost functions}\nDefine\n\\begin{align}\n  \\vect{w} &= \\bbmtx w_0 & w_{1} & \\cdots & w_{M-1}\\ebmtx^T\\\\\n  \\vect{u}(n)&= \\bbmtx u(n) & u(n-1) & \\cdots & u(n-M+1)\\ebmtx^T\\\\\n  \\vect{R}_u &= E[\\vect{u}(n)\\vect{u}^T(n)]\\\\\n  \\vect{r}_{ud} &= E[\\vect{u}(n)d(n)]\\ .\n\\end{align}\nHere, $\\vect{R}_u$ is the correlation matrix of the input signal vector $\\vect{u}(n)$, and $\\vect{r}_{ud}$ is the cross-correlation vector between the input signal vector $\\vect{u}(n)$ and the desired signal $d(n)$.\n\nFor $n=n_0,n_0+1,\\ldots,n_0+K-1$ with $K\\geq M$, define\n\\begin{align}\n  \\vect{A} &= \\bbmtx \\vect{u}(n_0) & \\vect{u}(n_0+1) & \\cdots & \\vect{u}(n_0+K-1)\\ebmtx^T\\label{eq:ls_phi}\\\\\n  \\vect{d} &= \\bbmtx d(n_0) & d(n_0+1) & \\cdots & d(n_0+K-1)\\ebmtx^T\\label{eq:ls_d}\\\\\n  \\vect{e} &= \\bbmtx e(n_0) & e(n_0+1) & \\cdots & e(n_0+K-1)\\ebmtx^T\\label{eq:ls_e}\\ .\n\\end{align}\nThen\n\\bmath\n  e(n) = d(n) - \\vect{u}^T(n)\\vect{w}\\quad\\iff\\quad d(n) = \\vect{u}^T(n)\\vect{w} + e(n)\n\\emath\nand\n\\bmath\n  \\vect{e} = \\vect{d}-\\vect{A}\\vect{w}\\quad\\iff\\quad\\vect{d}=\\vect{A}\\vect{w}+\\vect{e}\\ .\n  \\label{eq:ls_model}\n\\emath\nWe observe the input signal $u(n)$ and the desired signal $d(n)$, and we wish to find the filter vector $\\vect{w}$ which minimises the error in some sense. Two popular choices for the cost function of this problem are\n\\begin{alignat}{3}\n &\\text{Mean-squared error:} &\\qquad J_1(\\vect{w}) &= E[e(n)^2] &\\qquad &\\text{(statistics is known)}\\\\\n &\\text{Squared error:} &\\qquad J_2(\\vect{w}) &= \\sum_{n=n_0}^{n_0+K-1}e^2(n)=\\vect{e}^T\\vect{e} &\\qquad &\\text{(statistics is unknown)}\n  \\label{eq:cf_squared_error}\n\\end{alignat}\nIf $\\rank{\\vect{A}}>M$, \\eq{eq:ls_model} constitutes an overdetermined system of equations which do not have an exact solution that makes $J_2(\\vect{w})=0$. The problem of minimising the squared error is often referred to as \\textit{the method of least-squares}, and the argument minimising the squared error is referred to as \\textit{the least-squares solution}. Moreover, the squared error divided by the number of elements in the error vector $\\vect{e}$ can be seen as an unbiased estimate of the mean-squared error when $u(n)$ and $d(n)$ are assumed to be jointly WSS. That is,\n\\bmath\n  E\\left[\\frac{1}{K}J_2(\\vect{w})\\right] = J_1(\\vect{w})\\ .\n\\emath\n\n\\section{The Wiener-Hopf Equations}\nWe want to solve the following unconstrained optimisation problem\n\\bmath\n  \\vect{w}_o = \\argmin_{\\vect{w}} J_1(\\vect{w})\n\\emath\nwhere $\\vect{w}_o$ is the vector containing the optimal filter coefficients. We use the five step recipe in Sec.~\\ref{ssec:optimisation} to solve the optimisation problem.\n\\begin{enumerate}\n  \\item Construct the cost function\n  \\begin{align}\n    J_1(\\vect{w}) &= E[e(n)^2] = E[(d(n)-\\vect{u}^T(n)\\vect{w})^2] = E[(d(n)-\\vect{u}^T(n)\\vect{w})^T(d(n)-\\vect{u}^T(n)\\vect{w})]\\notag\\\\\n    &= E[d(n)^2]+E[\\vect{w}^T\\vect{u}(n)\\vect{u}^T(n)\\vect{w}]-E[d(n)\\vect{u}^T(n)\\vect{w}]-E[\\vect{w}^T\\vect{u}(n)d(n)]\\notag\\\\\n    &= E[d(n)^2]+\\vect{w}^TE[\\vect{u}(n)\\vect{u}^T(n)]\\vect{w}-2\\vect{w}^TE[\\vect{u}(n)d(n)]\\notag\\\\\n    &= \\sigma_d^2 + \\vect{w}^T\\vect{R}_u\\vect{w}-2\\vect{w}^T\\vect{r}_{ud}\\quad\\text{(quadratic cost function)}\n  \\end{align}\n  \\item Find the gradient\n  \\bmath\n    \\vect{g}(\\vect{w}) = (\\vect{R}_u+\\vect{R}_u^T)\\vect{w}-2\\vect{r}_{ud}=2\\vect{R}_u\\vect{w}-2\\vect{r}_{ud}\n  \\emath\n  \\item Solve $\\vect{g}(\\vect{w})=\\vect{0}$ for $\\vect{w}$\n  \\begin{alignat}{3}\n    &&\\qquad \\vect{g}(\\vect{w}) &= \\mathrlap{2\\vect{R}_u\\vect{w}-2\\vect{r}_{ud} = \\vect{0}}\\notag\\\\\n    \\ArrowBetweenLines\n    &&\\qquad \\alignedbox{\\vect{R}_u\\vect{w}}{=\\vect{r}_{ud}}  &\\qquad &\\text{(Wiener-Hopf Equations)}\\\\\n    \\ArrowBetweenLines\n    &&\\qquad           \\vect{w} &= \\vect{R}_u^{-1}\\vect{r}_{ud} &\\qquad &\\text{(If }\\vect{R}_u\\text{ is invertible)}\n  \\end{alignat}\n  \\item Find the Hessian\n  \\bmath\n    \\vect{H}(\\vect{w}) = 2\\vect{R}_u\n  \\emath\n  which is p.d. for all $\\vect{w}$ if $u(n)$ is not perfectly predictable.\n  \\item This implies that\n  \\begin{itemize}\n    \\item $J_1(\\vect{w})$ is a convex function,\n    \\item $\\vect{R}_u$ is invertible,\n    \\item $\\vect{w}_o = \\vect{R}_u^{-1}\\vect{r}_{ud}$ is the global minimiser, and\n    \\item $J_1(\\vect{w}_o) = \\sigma_d^2-\\vect{r}_{ud}^T\\vect{R}_u^{-1}\\vect{r}_{ud}$\\ .\n  \\end{itemize}\n\\end{enumerate}\nThe solution $\\vect{w}_o$ is often referred to as the least-mean-squares solution.\n\n\\subsection{Principle of Orthogonality}\nThe Wiener-Hopf equations can also be derived from the principle of orthogonality. For $m=0,1,\\ldots,M-1$, the principle of orthogonality states\n\\bmath\n  0=E[u(n-m)e_o(n)]\\ \\iff\\ 0=E[y_o(n)e_o(n)]\\ \\iff\\ \\vect{w}_o = \\vect{R}_u^{-1}\\vect{r}_{ud}\\ .\n\\emath\nwhere $e_o(n)$ and $y_o(n)$ are the error and the filter output, respectively, when the filter is optimised in the mean-squared sense.\n\n\\subsection{The Modified Yule-Walker Equations}\nThe Wiener-Hopf equations are closely related to the Modified Yule-Walker equations. To see this, let $d(n)=u(n+1)$. Then\n\\bmath\n  \\vect{r}_{ud} = E[\\vect{u}(n) d(n)] = E[\\vect{u}(n) u(n+1)] = \\vect{p}_u\n\\emath\nwhich implies that\n\\bmath\n  \\vect{R}_u\\vect{w} = \\vect{p}_u \\qquad \\text{(Modified Yule-Walker Equations)}\\ .\n\\emath\n\n\\section{The Normal Equations}\nWe want to solve the following unconstrained optimisation problem\n\\bmath\n  \\vect{w}_o = \\argmin_{\\vect{w}} J_2(\\vect{w})\n\\emath\nwhere $\\vect{w}_o$ is the vector containing the optimal filter coefficients. We use the five step recipe in Sec.~\\ref{ssec:optimisation} to solve the optimisation problem.\n\\begin{enumerate}\n  \\item Construct the cost function\n  \\begin{align}\n    J_2(\\vect{w}) &= \\vect{e}^T\\vect{e} = (\\vect{d}-\\vect{A w})^T(\\vect{d}-\\vect{A w})\\notag\\\\\n    &= \\vect{d}^T\\vect{d}+\\vect{w}^T\\vect{A}^T\\vect{A w}-2\\vect{w}^T\\vect{A}^T\\vect{d}\\quad\\text{(quadratic cost function)}\n  \\end{align}\n  \\item Find the gradient\n  \\bmath\n    \\vect{g}(\\vect{w}) = (\\vect{A}^T\\vect{A}+\\vect{A}^T\\vect{A})\\vect{w}-2\\vect{A}^T\\vect{d}=2\\vect{A}^T\\vect{A}\\vect{w}-2\\vect{A}^T\\vect{d}\n  \\emath\n  \\item Solve $\\vect{g}(\\vect{w})=\\vect{0}$ for $\\vect{w}$\n  \\begin{alignat}{3}\n    &&\\qquad \\vect{g}(\\vect{w}) &= \\mathrlap{2\\vect{A}^T\\vect{A}\\vect{w}-2\\vect{A}^T\\vect{d} = \\vect{0}}\\notag\\\\\n    \\ArrowBetweenLines\n    &&\\qquad \\alignedbox{\\vect{A}^T\\vect{A}\\vect{w}}{=\\vect{A}^T\\vect{d}}  &\\qquad &\\text{(Normal Equations)}\\\\\n    \\ArrowBetweenLines\n    &&\\qquad           \\vect{w} &= (\\vect{A}^T\\vect{A})^{-1}\\vect{A}^T\\vect{d} &\\qquad &\\text{(If }\\vect{A}\\text{ has full rank)}\n  \\end{alignat}\n  \\item Find the Hessian\n  \\bmath\n    \\vect{H}(\\vect{w}) = 2\\vect{A}^T\\vect{A}\n  \\emath\n  which is p.d. for all $\\vect{w}$  if $\\vect{A}$ has full rank.\n  \\item This implies that\n  \\begin{itemize}\n    \\item $J_2(\\vect{w})$ is a convex function,\n    \\item $\\vect{w}_o = (\\vect{A}^T\\vect{A})^{-1}\\vect{A}^T\\vect{d}$ is the global minimiser, and\n    \\item $J_2(\\vect{w}_o) = \\vect{d}^T(\\vect{I}-\\vect{P}_u)\\vect{d} = \\vect{d}^T\\vect{P}_u^{\\perp}\\vect{d}$ where $\\vect{P}_u=\\vect{A}(\\vect{A}^T\\vect{A})^{-1}\\vect{A}^T$ is the orthogonal projection matrix and $\\vect{P}_u^{\\perp}$ is the complementary projection matrix to $\\vect{P}_u$.\n  \\end{itemize}\n\\end{enumerate}\nThe solution $\\vect{w}_o$ is often referred to as the least-squares solution.\n\n\\subsection{Principle of Orthogonality}\n\\begin{figure}\n  \\centering\n  \\inputTikZ{figures/orthogonality_principle}\n  \\caption{The principle of orthogonality for the squared error cost function.}\n  \\label{fig:orthogonality_principle}\n\\end{figure}\nThe normal equations can also be derived from the principle of orthogonality\n\\bmath\n  \\vect{0}=\\vect{A}^T\\vect{e}_o\\ \\iff\\ \\vect{0}=\\vect{y}_o^T\\vect{e}_o\\ \\iff\\ \\vect{w}_o = (\\vect{A}^T\\vect{A})^{-1}\\vect{A}^T\\vect{d}\\ .\n\\emath\nwhere $\\vect{e}_o$ and $\\vect{y}_o$ are the error vector and the filter output vector, respectively, when the filter is optimised in the squared sense. Fig.~\\ref{fig:orthogonality_principle} illustrates the principle of orthogonality.\n\n\\subsection{Estimation of the (Cross-)Correlation}\nComparing the normal equations with the Wiener-Hopf equations, we see that\n\\begin{align}\n  \\hat{\\vect{R}}_u &= \\frac{1}{K}\\vect{A}^T\\vect{A}\\label{eq:ls_Ru_est}\\\\\n  \\hat{\\vect{r}}_{ud} &= \\frac{1}{K}\\vect{A}^T\\vect{d}\\label{eq:ls_rud_est}\n\\end{align}\nare the build in estimates of the correlation matrix and the cross-correlation vector, respectively, in the method of least-squares.\n\n\\subsection{Data Windowing}\nRecall the definition of $\\vect{A}^T$ in \\eq{eq:ls_phi} with $n_0=1$ and $K=N+M-1$.\n\\bmathnt\n\\left[\n  \\begin{array}{@{}c@{}|c@{}|c@{}}\n    \\begin{matrix}\n      u(1)    & \\cdots & u(M-1)\\\\\n      u(0)    & \\cdots & u(M-2)\\\\\n      \\vdots  & \\ddots & \\vdots\\\\\n      u(2-M)  & \\cdots & u(0)\\\\\n    \\end{matrix} &\n    \\begin{matrix}\n      u(M)    & \\cdots & u(N)\\\\\n      u(M-1)  & \\cdots & u(N-1)\\\\\n      \\vdots  & \\ddots & \\vdots\\\\\n      u(1)    & \\cdots & u(N-M+1)\\\\\n    \\end{matrix} &\n    \\begin{matrix}\n      u(N+1)  & \\cdots & u(N+M-1)\\\\\n      u(N)    & \\cdots & u(N+M-2)\\\\\n      \\vdots  & \\ddots & \\vdots\\\\\n      u(N-M+2)& \\cdots & u(N)\\\\\n    \\end{matrix}\n  \\end{array}\n  \\right]\n\\emathnt\nIn real-world applications, we only observe a finite amount of data. Assume that we observe $u(n)$ for $n=1,\\ldots,N$ while the remaining data for $n\\leq 0$ and $n>N$ are unobserved. If we set the unobserved data equal to zero, we obtain the structure for $\\vect{A}$ shown in Fig~\\ref{fig:ls_windowing}.\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/ls_windowing}\n  \\caption{Four different data windowing methods.}\n  \\label{fig:ls_windowing}\n\\end{figure}\nThe various choices for $\\vect{A}$ are\n\\begin{alignat*}{3}\n  &\\vect{A}_1\\text{ - covariance method:}   &\\qquad n_0&=M &\\qquad K&=N-M+1\\\\\n  &\\vect{A}_2\\text{ - autocorrelation method:}  &\\qquad n_0&=1 &\\quad K&=N+M-1\\\\\n  &\\vect{A}_3\\text{ - prewindowing method:} &\\qquad n_0&=1 &\\quad K&=N    \\\\\n  &\\vect{A}_4\\text{ - postwindowing method:}&\\qquad n_0&=M &\\quad K&=N\n\\end{alignat*}\nThe cost function and the length of $\\vect{e}$ in \\eq{eq:ls_e} and $\\vect{d}$ in \\eq{eq:ls_d} must be adjusted according to the windowing method. The covariance method leads to unbiased estimates of $\\vect{R}_u$ and $\\vect{r}_{ud}$ in \\eq{eq:ls_Ru_est} and \\eq{eq:ls_rud_est}, respectively.\n", "meta": {"hexsha": "bee760d3adebee524eb398df152a7bd8f54fcc76", "size": 19854, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture_notes/lectures/intro_WHE_NE.tex", "max_stars_repo_name": "jkjaer/adaptiveFilteringLectureNotes", "max_stars_repo_head_hexsha": "194706662078f810c163e403548395a532471d0c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-07-22T19:46:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T07:10:32.000Z", "max_issues_repo_path": "lecture_notes/lectures/intro_WHE_NE.tex", "max_issues_repo_name": "jkjaer/adaptiveFilteringLectureNotes", "max_issues_repo_head_hexsha": "194706662078f810c163e403548395a532471d0c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture_notes/lectures/intro_WHE_NE.tex", "max_forks_repo_name": "jkjaer/adaptiveFilteringLectureNotes", "max_forks_repo_head_hexsha": "194706662078f810c163e403548395a532471d0c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.0100755668, "max_line_length": 581, "alphanum_fraction": 0.6432960612, "num_tokens": 7671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.9046505344582186, "lm_q1q2_score": 0.8265579531017215}}
{"text": "\\chapter{How to Make a Map}\\label{chap:maps}\n\\section{Notation}\nLet's start with a four dimensional real vector space $V$.\nAssociated with it, we have some set of basis vectors, so we can say that any vector $\\vec{m} = a\\vec{w} + b\\vec{v} + c\\vec{p} + d\\vec{q}$.\nOut of the infinite possibilities for a basis for $V$, let's pick an arbitrary basis, and call each element $e$, using a \\emph{subsecript} to identify which of the four basis vectors it is; so our basis is $\\{\\vec{e}_0, \\vec{e}_1, \\vec{e}_2, \\vec{e}_3\\}$.\nIf we want to talk about a general basis vector, we'll call it $\\{\\vec{e}_\\mu\\}$. Notice that the identifier for basis vectors in on the \\emph{bottom}. This will be a very important idea.\n\nLet's consider a vector $\\vec{A} \\in V$; We can write $\\vec{A}$ in the following way.\n\\begin{align*}\n    \\vec{A} &= a\\vec{e}_0 + b\\vec{e}_1 + c\\vec{e}_2 + d\\vec{e}_3 \\\\\n            &= A^0\\vec{e}_0 + A^1\\vec{e}_1 + A^2\\vec{e}_2 + A^3\\vec{e}_3 \\\\\n            &= \\sum A^\\mu \\vec{e}_\\mu \\\\\n            &= A^\\mu \\vec{e}_\\mu.\n\\end{align*}\nThis is an example of \\emph{Einstein Summation Convention}, where adjacent upper and lower indices are automatically summed over.\n\n\\section{Maps}\nLet's create two vector spaces, a four dimensional real vector space $V$ with basis $\\{\\vec{e}_\\mu\\}$ and a 10 dimensional real vector space $W$ with basis $\\{\\vec{f}_\\mu\\}$.\nNow let's create a \\emph{linear}\\footnote{Recall that a linear map $\\Lambda : D \\to R$ satisfies the following: $\\Lambda(0_D) = 0_R$, $\\Lambda(\\vec{u} + \\vec{v}) = \\Lambda(\\vec{u}) + \\Lambda(\\vec{v})$, and $\\Lambda(\\alpha\\vec{v}) = \\alpha\\Lambda(\\vec{v})$.} map $\\Lambda$ which takes any vector in $V$ and assigns it to a vector in $W$.\nWe write this as $\\Lambda : V \\to W$.\nIf we want to show how this map acts on a particular domain vector, we can write it in several different ways:\n\\begin{align*}\n    \\Lambda : V &\\to W \\tag{Definition} \\\\\n    \\Lambda\\vec{v} &= \\vec{w} \\tag{Operator notation} \\\\\n    \\Lambda(\\vec{v}) &= \\vec{w} \\tag{Function notation} \\\\\n    \\langle \\Lambda,\\vec{v} \\rangle &= \\vec{w}. \\tag{Bracket notation}\n\\end{align*}\nThis last notation is the most useful one for discussing tensors.\nIt has several benefits for us: if we write something like $\\langle \\Lambda, \\cdot \\rangle$, it looks like a function waiting to accept a certain vector in order to get an output $\\vec{w}$; conversely, if we write $\\langle \\cdot, \\vec{v} \\rangle$, it looks like we're looking for a certain map to act upon $\\vec{v}$ in order to get $\\vec{w}$.\n\nNow let's consider what happens when we apply this map to each of the basis vectors $\\vec{e}_\\mu$:\n\\begin{align*}\n    \\langle \\Lambda, \\vec{e}_0 \\rangle &= 3\\vec{f}_1 + 2\\vec{f}_4 + 5\\vec{f}_9 \\\\\n    \\langle \\Lambda, \\vec{e}_1 \\rangle &= \\pi \\vec{f}_3 + \\vec{f}_0 \\\\\n    \\langle \\Lambda, \\vec{e}_2 \\rangle &= \\vec{f}_2 \\\\\n    \\langle \\Lambda, \\vec{e}_3 \\rangle &= \\vec{f}_3 + \\vec{f}_5 + \\vec{f}_7 + \\vec{f}_9\n\\end{align*}\nObviously, this is a rather random mapping. The outputs here are completely arbitrary. The important thing to note is that this map is linear, so $\\langle \\Lambda, \\alpha\\vec{v} + \\beta\\vec{p} \\rangle = \\alpha\\langle \\Lambda, \\vec{v} \\rangle + \\beta\\langle \\Lambda, \\vec{p} \\rangle$. Notice that, in the left hand side of the equation, the addition operation is the one from $V$ ($+_V$), while in the right hand side, it is the addition operation from $W$ ($+_W$), since $\\langle \\Lambda, \\alpha\\vec{v} \\rangle,\\langle \\Lambda, \\beta\\vec{p} \\rangle \\in W$.\n\nIf we apply $\\Lambda$ to the arbitrary vector $\\vec{A}$ we defined previously, we see that \n\\begin{align*}\n    \\langle \\Lambda, \\vec{A} \\rangle &= \\langle \\Lambda, A^\\mu \\vec{e}_\\mu \\rangle \\\\\n    &= A^\\mu \\langle \\Lambda, \\vec{e}_\\mu \\rangle\n\\end{align*}\nSince we already know how $\\langle \\Lambda, \\vec{e}_\\mu \\rangle$ transforms, we can express what happens to any vector under $\\Lambda$ this way.\n", "meta": {"hexsha": "fcef56f8e45e483695bd3f582c042416b78f266b", "size": 3898, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/maps.tex", "max_stars_repo_name": "jopetty/tensor-notes", "max_stars_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/maps.tex", "max_issues_repo_name": "jopetty/tensor-notes", "max_issues_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/maps.tex", "max_forks_repo_name": "jopetty/tensor-notes", "max_forks_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.7391304348, "max_line_length": 556, "alphanum_fraction": 0.6672652642, "num_tokens": 1269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9724147193720648, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.8265244767080611}}
{"text": "\\section{Inequalities}\r\n\\begin{theorem}[Markov's Inequality]\r\n    Suppose we have a nonnegative random variable $X$, then for any $a>0$,\r\n    $$\\mathbb P(X\\ge a)\\le\\frac{\\mathbb E[X]}{a}$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Observe that $X\\ge a1_{X\\ge a}$ by checking each $\\omega\\in\\Omega$, then we take expectation to get the inequality.\r\n\\end{proof}\r\n\\begin{theorem}[Chebyshev's Inequality]\r\n    Let $X$ be a random variable with finite expectation, then for all $a>0$,\r\n    $$\\mathbb P(|X-\\mathbb E[X]|\\ge a)\\le\\frac{\\operatorname{Var}(X)}{a^2}$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $$\\mathbb P(|X-\\mathbb E[X]|\\ge a)=\\mathbb P((X-\\mathbb E[X])^2\\ge a^2)\\le\\frac{\\operatorname{Var}(X)}{a^2}$$\r\n    by Markov's Inequality.\r\n\\end{proof}\r\n\\begin{theorem}[Cauchy-Schwarz Inequality]\r\n    Let $X,Y$ be random variables, then $\\mathbb E[|XY|]\\le\\sqrt{\\mathbb E[X^2]\\mathbb E[Y^2]}$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    It suffices to prove the case where $X,Y$ are nonnegative, in which case we can discard the absolute value.\r\n    Also it is trivial when one of $\\mathbb E[X^2],\\mathbb E[Y^2]$ is infinite, so we assume that they are finite afterwards.\r\n    So $\\mathbb E[XY]\\le (\\mathbb E[X^2]+\\mathbb E[Y^2])/2$ is also finite.\r\n    Also if $\\mathbb E[X^2]\\mathbb E[Y^2]=0$ then the (in)equality is trivial, so we assume henceforth that they are both positive.\r\n    There we have $0\\le (X-tY)^2=X^2-2tXY+t^2Y^2$, from where taking expectation on both sides then yields $\\mathbb E[X^2]-2t\\mathbb E[XY]+t^2\\mathbb E[Y^2]\\ge 0$ for any $t$.\r\n    The inequality follows by taking determinant, also equality happens iff $X=tY$ for some $t$, i.e. $X,Y$ are linearly dependent.\r\n\\end{proof}\r\n\\begin{theorem}[Jensen's Inequality]\r\n    Let $f$ be a convex function defined on $\\mathbb R$, that is for any $x,y\\in\\mathbb R, t\\in[0,1]$,\r\n    $$f(tx+(1-t)y)\\le tf(x)+(1-t)f(y)$$\r\n    Then if $X$ is a random variable,\r\n    $$\\mathbb E[f(X)]\\ge f(\\mathbb E[X])$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    A convex function is equal to the supremum of all lines lying below it.\r\n    That is, $\\forall m\\in\\mathbb R,\\exists a,b\\in\\mathbb R$ such that $f(m)=am+b$ and $\\forall x\\in\\mathbb R,ax+b\\le f(x)$.\r\n    This is obvious by choosing $x,y$ with $x<m<y$ and apply the definition of convex functions, whence $\\exists a\\in\\mathbb R$,\r\n    $$\\frac{f(m)-f(x)}{m-x}\\le a\\le \\frac{f(y)-f(m)}{y-m}$$\r\n    For any $x$ it gives $f(x)\\ge a(x-m)+f(m)$, so we just take $b=-am+f(m)$.\\\\\r\n    Now we go back to our proof.\r\n    Let $m=\\mathbb E[X]$, then we can choose $a,b$ such that $f(X)\\ge aX+b$ and $f(m)=am+b$, taking expectation gives $f(\\mathbb E[X])=a\\mathbb E[X]+b\\le \\mathbb E[f(X)]$.\r\n\\end{proof}\r\nObviously we want to know when does the equality case hold in Jensen's Inequality.\r\nLet $f$ be a convex function, assume that $\\exists m\\in\\mathbb R$ such that $f(m)=am+b$ and $f(x)>ax+b$ for some $a,b$ real.\r\nSuppose $m=\\mathbb E[X]$, then consider $Y=f(X)-(aX+b)$ which is a nonnegative random variable.\r\nAssume that $\\mathbb E[f(X)]=f(\\mathbb E[X])$, then $\\mathbb E[Y]=0$, so $\\mathbb P(Y=0)=1$, hence $\\mathbb P(f(X)=aX+b)=1$, therefore $\\mathbb P(X=m)=1$.\r\n\\begin{corollary}\r\n    Let $f$ be convex and let $x_1,\\ldots,x_n$ be real, then\r\n    $$\\frac{1}{n}\\sum_{k=1}^nf(x_k)\\ge f\\left(\\frac{1}{n}\\sum_{k=1}^nx_k \\right)$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Take $X$ be a random variable taking values uniformly in $x_1,\\ldots,x_n$ and apply Jensen's Inequality.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    For positive $x_1,\\ldots,x_n$,\r\n    $$\\frac{1}{n}\\sum_{k=1}^nx_k\\ge \\left( \\prod_{k=1}^nx_k \\right)^{1/n}$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Take $f=-\\log$.\r\n\\end{proof}\r\n", "meta": {"hexsha": "fc76f595afc4c56f7189593bcb21527ccaff057e", "size": 3655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/ineq.tex", "max_stars_repo_name": "david-bai-notes/IA-Probability", "max_stars_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/ineq.tex", "max_issues_repo_name": "david-bai-notes/IA-Probability", "max_issues_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/ineq.tex", "max_forks_repo_name": "david-bai-notes/IA-Probability", "max_forks_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.9180327869, "max_line_length": 176, "alphanum_fraction": 0.6432284542, "num_tokens": 1312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.8933094053442511, "lm_q1q2_score": 0.826516617251343}}
{"text": "\\textbf{Modify the code \\texttt{fluidflowFD.m} to solve the equations}\n\\begin{align*}\n w_t + \\psi_y w_x - \\psi_xw_y &= Pr \\Delta w + RaPrT_x, \\\\\n T_t + \\psi_y T_x - \\psi_xT_y &= \\Delta T, \\\\\n\\Delta \\psi &= -w,\n\\end{align*}\n\\textbf{where $(x,y) \\in (0,1) \\times (0,1)$ and $t>0$. For this exercise, set $Ra = 2 \\times 10^5$ and $Pr = 0.71$ (air).}\n\n\\textbf{The fluid is at rest at $t=0$, with $T = \\psi = w = 0$. The boundary conditions for the stream function is $\\psi_{\\Gamma} = 0$, which implies that there is no mass transfer through the boundary $\\Gamma$. The value of the vorticity at the walls is expressed as $w_{\\Gamma} = -\\Delta \\psi_{\\Gamma}$ and the temperature at $\\Gamma$ is defined by}\n\\begin{align*}\nT(t,x,y) = \\begin{cases}\n2^9\\tanh^4(100t)x^5(x-1)^4,& y =0,~0\\leq x \\leq 1,~t>0, \\\\\n0, & (x,y) \\in \\Gamma,~y\\neq 0,~t>0.\n\\end{cases}\n\\end{align*}\n\nBy replicating the code given to solve the fluid flow, adding the extra step of the temperature, we obtain the following result.\n\n\\begin{figure}[H]\n\\center{\\includegraphics[scale=.75]{solutionProblem4.eps}}\n\\caption{Solution at $t=1$ second}\n\\end{figure}\n\n\\subsection*{Matlab code for shit part}\n\\begin{verbatim}\n%% Problem 4\nRa=2e5;\nPr=0.71;\nProblem4(Ra,Pr)\n\n% Fluid flow in a cavity (Navier-Stokes equations)\n% Stream-function and vorticity formulation\n%\n% Rodrigo Platte, Arizona State University, April 2013.\n\nfunction Problem4(Ra,Pr)\n% Parameters\npath='Latex/FIGURES/';\nN = 150;\ndt = 1e-5;\n\nh = 1/N; % N+1 points in each direction\n[xx,yy] = meshgrid(0:h:1); % 2D gridpoints\n\n% Laplacian with zero BCs\no = ones(N-1,1);\nD2 = (diag(-2*o) + diag(o(1:N-2),-1)+ diag(o(1:N-2),1))/h^2;\n% We need evals and evects to solve Poisson equation\n[eV,eval] = eig(D2); lam = diag(eval); \n\n% Initial condition & pre-allocate memory (start with zeros at t = 0)\nu = 0*xx; v = u; w = u; str = u; T=u;\n\n% boundary condition\nii = 2:N; jj = 2:N;  % index for interior nodes\nwi = zeros(N-1,N-1); % interior values of vorticity\nTi = zeros(N-1,N-1); % interior values of temperature\n\ncount = 0;\ntime = 0;\noutputTime=[1];\nendtime=outputTime(end);\nn=1;\n% main loop\nwhile time<endtime\n\tif ( time < outputTime(n) && time+dt >= outputTime(n) ) %#ok<ALIGN>\n        dt=outputTime(n)-time;\n        n=n+1;\n    else\n        dt = 1e-5;\n    end\n   % update vorticity at boundary\n   w = BCw(u,v,w);\n   % update Temperature at boundary\n   T = BCT(xx,time,T);\n   \n   % advance vorticity and temperature with forward Euler\n    [rhsT,Tx]=Trhs(u,v,T);\n    Ti = Ti + dt*rhsT;\n    T(ii,jj)=Ti;\n    wi = wi + dt*wrhs(u,v,w,Pr,Ra,Tx);\n    w(ii,jj) = wi;\n   \n   % compute stream function with conjugate gradient\n   str(2:end-1,2:end-1) = SolvePoisson(wi);\n   \n   % update velocity (interior nodes only)\n   u(ii,jj) =  (str(ii+1,jj)-str(ii-1,jj))/(2*h);\n   v(ii,jj) = -(str(ii,jj+1)-str(ii,jj-1))/(2*h);\n   \n   time = time+dt;\n   count = count + 1;\n   \n   % Plot results every now and then\n   if ismember(time,outputTime);\n       plotresults(u,v,str,w,T);    \n   end\n\nend\n\n    % Solve Poisson equation (Sylvester equation)\n    function S = SolvePoisson(wi)\n        ff = -eV'*wi*eV;\n        S = ff;\n        for j = 1:N-1\n            S(:,j) = ff(:,j)./(lam(j)+lam);\n        end\n        S = eV*S*eV';\n    end\n\n    % Right-hand side of vorticity equation\n    function rhs = wrhs(u,v,w,Pr,Ra,Tx)\n        wx = (w(ii,jj+1)-w(ii,jj-1))/(2*h);\n        wy = (w(ii+1,jj)-w(ii-1,jj))/(2*h);\n        Lw = (w(ii,jj+1)+w(ii,jj-1)+w(ii+1,jj)+w(ii-1,jj)-4*w(ii,jj))/h^2;\n        rhs = -u(ii,jj).*wx - v(ii,jj).*wy + Pr*Lw+Ra*Pr*Tx;          \n    end\n    % Right-hand side of temperature equation\n    function [rhs, Tx] = Trhs(u,v,T)\n        Tx = (T(ii,jj+1)-T(ii,jj-1))/(2*h);\n        Ty = (T(ii+1,jj)-T(ii-1,jj))/(2*h);\n        LT = (T(ii,jj+1)+T(ii,jj-1)+T(ii+1,jj)+T(ii-1,jj)-4*T(ii,jj))/h^2;\n        rhs = -u(ii,jj).*Tx - v(ii,jj).*Ty + LT;          \n    end\n\n    % Enforce boundary condition (vorticity)\n    function w = BCw(u,v,w)\n        % three point sided FD formula (second order accurate)\n        w(1,:) = -(-3*u(1,:)+4*u(2,:)-u(3,:))/(2*h);      % = -u_y @ y = 0\n        w(N+1,:) = (-3*u(N+1,:)+4*u(N,:)-u(N-1,:))/(2*h); % = -u_y @ y = 1\n        w(:,1) = (-3*v(:,1)+4*v(:,2)-v(:,3))/(2*h);       % =  v_x @ x = 0\n        w(:,N+1) = -(-3*v(:,N+1)+4*v(:,N)-v(:,N-1))/(2*h);% =  v_x @ x = 1\n    end\n    % Enforce boundary condition (temperature)\n    function T = BCT(xx,t,T)\n        T(1,:)=2^9*tanh(100*t)^4*xx(1,:).^5.*(xx(1,:)-1).^4;\n    end\n\n    % Plot results\n    function plotresults(u,v,str,w,T)\n        % Use a subset of gridpoints\n       ip = 1:3:N+1;\n       up = u(ip,ip); vp = v(ip,ip);\n       xp = xx(ip,ip); yp = yy(ip,ip);\n       \n       % Velocity\n       subplot(2,2,1)\n       quiver(xp,yp,up,vp,10)\n       axis([0 1 0 1]), axis square\n       title('velocity field','fontsize',16)\n       \n       % Normalized velocity\n       subplot(2,2,2)\n       contourf(xx,yy,T)\n       axis([0 1 0 1]), axis square\n       title('normalized velocity','fontsize',16)\n       \n       % Stream function\n       subplot(2,2,3) \n       mp = max(max(str));\n       mm = min(min(str));\n       contour(xx,yy,str,-logspace(-10,log10(-mm),30),'r'),  hold on\n       contour(xx,yy,str, logspace(-10,log10(mp),20),'k'),   hold off\n       axis square, title('streamlines (logscale)','fontsize',16)\n       \n       % Vorticity\n       subplot(2,2,4)\n       logw = log10(abs(w));    logw(abs(w)==0) = nan;\n       contourf(xx,yy,logw,-3:0.5:2), \n       H = colorbar; set(H,'fontsize',16)\n       set(gca,'position',[0.5703 0.1100 0.3347 0.3412])\n       axis square, title('vorticity (log(abs(w))','fontsize',16) \n       drawnow\n        txt=[path,'solutionProblem4'];\n        saveas(gcf,txt,'epsc')\n    end\n\nend\n\n\\end{verbatim}", "meta": {"hexsha": "729621b3e07183f4e7156721c08b68c387119a2e", "size": 5711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/problem4.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/problem4.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/problem4.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7277777778, "max_line_length": 351, "alphanum_fraction": 0.5617229907, "num_tokens": 2076, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422199928904, "lm_q2_score": 0.868826771143471, "lm_q1q2_score": 0.8263778238946559}}
{"text": "\\section{Implementation of Feed-Forward Neural Network (30 points) }\nHere, you will implement a simple one-layer feed-forward neural network (perceptron) from scratch to solve a classification task. To recap, a fully connected layer can be represented as a function parameterized by weight $\\mathbf{W}$ and bias $b$, such that for row vector $\\mathbf{x}$:\n\\begin{align}\nf_{\\mathbf{W},b}(\\mathbf{x}) = \\mathbf{x}\\mathbf{W} + b\n\\end{align}\nFor classification tasks, one of the most common practice is to use a softmax function followed by a cross entropy loss. As shown in section 13.2.5 of the textbook, for a vector $\\mathbf{x}=[x_1, x_2, \\dotsc, x_n]$, the softmax function is defined as:\n\\begin{align}\n\\mu (\\mathbf{x})_i = \\frac{e^{x_i}}{\\sum_j e^{x_j}}\n\\end{align}\n\\begin{align}\n\\mu (\\mathbf{x}) = \\left[\\frac{e^{x_1}}{\\sum_j e^{x_j}}, \\dotsc, \\frac{e^{x_n}}{\\sum_j e^{x_j}}\\right]\n\\end{align}\n\nAs shown in section 13.2.9 of the textbook, for target probability distribution $\\mathbf{p}=[p_1, p_2, \\dotsc, p_n]$ and a different probability distribution $\\mathbf{q}=[q_1, q_2, \\dotsc, q_n]$, the cross entropy $L(\\mathbf{p}, \\mathbf{q})$ is defined as:\n\\begin{align}\nL(\\mathbf{p}, \\mathbf{q}) = - \\sum_{i=1}^{n} p_i \\log q_i\n\\end{align}\n\nNote that in supervised learning, the target probability distribution $\\mathbf{p}$ is usually represented as a one-hot vector, where $p_i=1$ shows that the corresponding input belongs to the $i$-th class with probability 1.\n\nWe can now represent our one-layer feed-forward neural network as a function $f_N$, such that for input vector $\\mathbf{x}$ and its one-hot label vector $\\mathbf{y}$:\n\\begin{align}\nf_N(\\mathbf{x}) = \\mu(f_{\\mathbf{W},b}(\\mathbf{x}))\n\\end{align}\n\nThe loss for this input is thus $L(\\mathbf{y}, f_N(\\mathbf{x}))$. For a dataset $\\mathcal{D}$ of size $N$, the loss is:\n\\begin{align}\nL(\\mathcal{D}) = \\frac{1}{N} \\sum_{i=1}^N L(\\mathbf{y_i}, f_N(\\mathbf{x_i}))\n\\end{align}\n\nIn order to minimize the loss function, we need to obtain the gradient with respect to weight $\\mathbf{W}$ and bias $b$. In the next questions you will derive these gradient expressions using the chain rule.\n\n\\subquestion{(a) [5 Points]}\n\n\\task{What is $\\frac{\\partial L(\\mathbf{y}, \\mathbf{q})}{\\partial q_i}$, the gradient of cross entropy loss $L(\\mathbf{y}, \\mathbf{q})$ with respect to $q_i$?}\n\n\n\\subquestion{(b) [5 Points]}\n\\task{What is $\\frac{\\partial \\mu(\\mathbf{x})_j}{\\partial x_i}$, the gradient of softmax function $\\mu(\\mathbf{x})_j$ with respect to $x_i$? You should consider both $i=j$ and $i\\neq j$.}\n\n\n\n\\subquestion{(c) [5 Points]}\n\\task{What is $\\frac{\\partial f_{\\mathbf{W},b}(\\mathbf{x})}{\\partial W_{ij}}$ and $\\frac{\\partial f_{\\mathbf{W},b}(\\mathbf{x})}{\\partial b}$, the gradient of fully connected layer $f_{\\mathbf{W},b}(\\mathbf{x})$ with respect to the $ij$-th entry of weight $\\mathbf{W}$ and bias $b$?}\n\n\\bigskip\n\nNow, you should be able to assemble the full gradient of weight and bias $\\frac{\\partial L(\\mathcal{D})}{\\partial W_{ij}}$, $\\frac{\\partial L(\\mathcal{D})}{\\partial b}$ using chain rule and the gradients you derived above. \n\n\\subquestion{(d) [15 Points]}\n\nNext, let's go ahead and implement the one-layer neural network. Implement both the forward pass $L(\\mathcal{D})$ and the backward gradient $\\frac{\\partial L(\\mathcal{D})}{\\partial W_{ij}}$ and $\\frac{\\partial L(\\mathcal{D})}{\\partial b}$. For optimization, we will implement Minibatch gradient descent and compare different batch sizes. \\textbf{For this problem, you are allowed to keep the dataset in memory, and you do not need to use Spark. You are also allowed to use any external library, but we encourage you to implement gradients from scratch to deepen your understanding.}\n\n\\bigskip\n\n\n\\textbf{Mini batch gradient descent}: Go through the dataset in batches of predetermined size and update the parameters as follows:\n\\begin{algorithmic}\n\\WHILE {convergence criteria not reached}\n\\STATE Randomly pick $n=batch\\_size$ random samples $\\mathbf{x_k}$ from the training data\n\n\\FOR {$k = 1,...,n$}\n\\STATE Update $W_{ij} \\leftarrow W_{ij} - \\eta \\frac{\\partial L(\\mathcal{D})}{\\partial W_{ij}}$ for all i, j in $\\mathbf{W}$\n\\STATE Update $b \\leftarrow b - \\eta \\frac{\\partial L(\\mathcal{D})}{\\partial b}$\n\\ENDFOR\n\\ENDWHILE\n\\end{algorithmic}\nwhere $\\eta$ is the learning rate and $batch\\_size$ is the number of training samples considered in each batch. \\\\\n\nFor \\textbf{convergence criteria}, you should stop learning when the cross entropy loss on \\textbf{all data samples} is smaller than $0.4$. You are encouraged to vectorize your loss function and gradient calculation, but it's not required. \n\nYou will compare the performance of 3 different batch sizes.\n\\begin{enumerate}\n    \\item $batch\\_size=1$. This is equivalent to stochastic gradient descent. Please use $\\eta=0.1$.\n    \\item $batch\\_size=20$. Please use $\\eta=0.1$.\n    \\item $batch\\_size=N$, where N is the total number of data samples. This is equivalent to full batch gradient descent. Please use $\\eta=0.25$.\n\\end{enumerate}\n\nRun your implementation on the data set in \\textbf{q1/data}. The data set contains the following files :\n\\begin{enumerate}\n\\item \\texttt{features.txt} : Each line contains features (comma-separated values) for a single datapoint. It has 6414 datapoints (rows) and 122 features (columns). \n\n\\item \\texttt{targets.txt} : Each line contains the target variable (y = 0 or 1) for the corresponding row in \\texttt{features.txt}.\n\\end{enumerate}\n\n\n\\task{Plot the value of cross entropy loss on \\textbf{all data samples} $L(\\mathcal{D})$ vs. the number of iterations ($k$) for all three batch sizes  until \\textbf{convergence}. Report the total wall-clock runtime (second) taken for convergence by each of the batch size. Comment on the plots and the time for convergence. What can you infer from them?}\n\nThe diagram should have graphs from all the three batch sizes on the same plot. \n\n\\bigskip\n\\textbf{Important Note}\n\\begin{itemize}\n    \\item You should initialize your weight $\\mathbf{W}$ following a normal distribution with mean 0 and standard deviation 1. You should initialize your bias $b$ to zeros. To make sure we have a fair comparison, please use the same initialization of weight and bias for all three runs. \n    \\item When computing the loss, remember to divide the total summed loss and gradient by the number of data points (i.e., batch size). This has been shown in Equation 6.\n    \\item You should calculate your cross entropy loss on \\textbf{all data samples} for plotting and identifying convergence, not on the mini-batch of data samples.\n    \n\\end{itemize}\nAs a sanity check, using batch size $N$ should converge in 10-400 iterations, batch size 20 between 400-1000 iterations and batch size 1 between 1000-2500 iterations. However, the number of iterations may vary greatly due to the high randomness of this problem. If your implementation consistently takes longer iterations though, you may have a bug.\n\n\n\\subsection*{What to submit}\n\\begin{enumerate}[(i)]\n\t\\item Equation for part (a)\n\t\\item Equation for part (b)\n\t\\item Two equations for part (c)\n\t\\item Plots for the cross entropy loss $L(\\mathcal{D})$ vs. the number of iterations ($k$) for all three batch sizes 1, 20 and $N$. Total time taken for convergence by each of the batch size.  Interpretation of plot and convergence times. [part (d)]\n\t\\item Submit the code on Gradescope submission website. [part (d)]\n\\end{enumerate}\n\n", "meta": {"hexsha": "7527b39578d38bb66c3d53b0adf4498379cbb69c", "size": 7436, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw4-bundle/hw4-bundle/HW4 source/hw4_nn.tex", "max_stars_repo_name": "x3pi/mining-massive-datasets", "max_stars_repo_head_hexsha": "36d1f8ab437ea75d7437fc3e28593c2bb907ddd9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-12-24T01:06:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T10:54:57.000Z", "max_issues_repo_path": "hw4-bundle/hw4-bundle/HW4 source/hw4_nn.tex", "max_issues_repo_name": "x3pi/mining-massive-datasets", "max_issues_repo_head_hexsha": "36d1f8ab437ea75d7437fc3e28593c2bb907ddd9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw4-bundle/hw4-bundle/HW4 source/hw4_nn.tex", "max_forks_repo_name": "x3pi/mining-massive-datasets", "max_forks_repo_head_hexsha": "36d1f8ab437ea75d7437fc3e28593c2bb907ddd9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-09-11T17:31:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T20:33:33.000Z", "avg_line_length": 66.990990991, "max_line_length": 582, "alphanum_fraction": 0.7307692308, "num_tokens": 2112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951142217223021, "lm_q2_score": 0.8688267677469952, "lm_q1q2_score": 0.8263778182575877}}
{"text": "\\lab{Applications}{Markov Chains I}{Markov Chains I}\n\\label{lab:MarkovGraph}\n\n\\objective{This section teaches about two simple applications of Linear Algebra.\nFirst, it teaches about Markov Chains, which, in this context, represent discrete random transitions.\nSecond, it teaches about Graph Theory, which can be used to represent many physical problems.}\n\n\\section*{Markov Chains}\n\n%Lab \\ref{Markov}\n\nA Markov Chain describes a particular type of random variable.\nThis sort of random variable is characterized by the fact that all relevant information is related to its current state.\nWe can easily model this type of random variable using matrices.\nWe will start with a canonical example of a frog jumping from one lilypad to another.\n\nFredo the Frog hops around between the three lily pads 1, 2, and 3.\nIf he's on lily pad 1 and jumps, there is a 25\\% chance that he will land back on lily pad 1, a 25\\% chance that he will land on lily pad 2, and a 50\\% chance that he will land on lily pad 3.\nWe can find similar probabilities if he starts on lily pad 2 or 3.\nIn figure \\ref{markov1} we have a transition diagram that reflects the various probabilities that Fredo will go from one lily pad to another.\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[scale = 1.4]{markov1}\n\\end{center}\n\\caption{Transition diagram for Fredo the Frog}\n\\label{markov1}\n\\end{figure}\n\nWe can convert our transition diagram into a transition matrix, where the $(i,j)$-entry of the matrix corresponds to the probability that Fredo jumps from the $j^{th}$ lily pad to the $i^{th}$ lily pad (where $1$ is the first lily pad, 2 is the second, and so on).\nIn Fredo's case, the transition matrix is\n\\[\nA = \\begin{pmatrix}\n1/4 & 1/2 & 1/2\\\\\n1/4 & 1/6 & 1/2\\\\\n1/2 & 1/3 & 0\n\\end{pmatrix}\n\\]\nNote that all of the columns add up to one.\nThis is important.\n\nIf Fredo is on lily pad 1, where will he be after two jumps?\nBy multiplying the matrix $A$ by itself, we have (approximately)\n\n\\[\nA^2 = \\begin{pmatrix}\n0.4375 & 0.3750 & 0.3750\\\\\n0.3542 & 0.3194 & 0.2083\\\\\n0.2083 & 0.3056 & 0.4167\n\\end{pmatrix}\n\\]\nFrom this, we infer that there is a 43.75\\% chance he will still be on lily pad 1 after two jumps.\nNote that he might have jumped from 1 to 1 to 1, denoted $1 \\rightarrow 1 \\rightarrow 1$, or he could have jumped to one of the other lily pads and then back again, that is, either $1 \\rightarrow 2 \\rightarrow 1$ or $1 \\rightarrow 3 \\rightarrow 1$.\nIn addition, there is a 35.42\\% chance he will be on lily pad 2 and a 20.83\\% chance that he will be on lily pad 3.\nUsing Python, we can type in our transition matrix and see where Fredo will be after 5, 10, 20 or 100 jumps.\n\n\\begin{lstlisting}[style=python]\n#Remember, the 1.'s in the numerator force floating point division\n: A = sp.array([[1./4,1./2,1./2],[1./4,1./6,1./2],[1./2,1./3,0]])\n: np.linalg.matrix_power(A,5)\n: np.linalg.matrix_power(A,10)\n: np.linalg.matrix_power(A,20)\n: np.linalg.matrix_power(A,100)\n\\end{lstlisting}\n\nNote that in the limit that the number of jumps goes to infinity, we get\n\\[\nA^\\infty = \\begin{pmatrix}\n0.4 & 0.4 & 0.4\\\\\n0.3 & 0.3 & 0.3\\\\\n0.3 & 0.3 & 0.3\n\\end{pmatrix}\n\\]\nThis means that after several jumps, the probability that we will find Fredo on a given lily pad will have nothing to do with where he started initially.\n \n\\section*{Markov Chains}\n\nWe can generalize this notion beyond that of frogs and lily pads.\nLet the state of our system be represented by a probability vector\n\\[\n\\x = \\begin{bmatrix}\nx_1\\\\\nx_2\\\\\n\\vdots\\\\\nx_n\n\\end{bmatrix}\n\\]\nwhere each entry represents the probability of being in that state.\nNote that each entry is nonnegative and the sum of all the entries adds up to one.\nFor example, in the case of Fredo, if we know initially that he is on lily pad 1, then we have the state vector\n\\[\n\\x_0 = \\begin{bmatrix}\n1\\\\\n0\\\\\n0\n\\end{bmatrix}\n\\]\nbecause we know for certainty (100\\%) that Fredo is in the first state.\nAfter one jump, we have\n\\[\n\\x_1 = A \\x_0 = \\begin{bmatrix}\n0.25\\\\\n0.25\\\\\n0.50\n\\end{bmatrix}\n\\]\nAfter two jumps, we have\n\\[\n\\x_2 = A \\x_1 = A^2 \\x_0 = \\begin{bmatrix}\n0.4375\\\\\n0.3542\\\\\n0.2083\n\\end{bmatrix}\n\\]\nAfter a large number of jumps $(n>>1)$, we have\n\\[\n\\x_n = A \\x_{n-1} = \\dots = A^n \\x_0 \\approx \\begin{bmatrix}\n0.4\\\\\n0.3\\\\\n0.3\n\\end{bmatrix}\n\\]\nSince all of the columns are the same for $A^\\infty$, then for any initial probability vector $\\x_0$, we get the same limiting output, or in other words, all initial vectors converge to the same point, call it $\\x_\\infty$.\nMoreover, we have that\n\\[\n\\x_\\infty = A \\x_\\infty\n\\]\nThis is called a stable fixed point.\nHow can we check that a stable fixed point exists?\nHint: Think eigenvalues and eigenvectors.\n\n\\section*{Example}\n\nConsider the Markov chain given by\n\\[\nA = \\begin{pmatrix}\n0.5 & 0.3 & 0.4\\\\\n0.2 & 0.2 & 0.3\\\\\n0.3 & 0.5 & 0.3\n\\end{pmatrix}.\n\\]\nWe show that it has a stable fixed point by checking that it has a single eigenvalue $\\lambda=1$.\nWe do this via Python:\n\\begin{lstlisting}[style=python]\n: A = sp.array([[.5,.3,.4],[.2,.2,.3],[.3,.5,.3]])\n: V = la.eig(A)[1]\n\\end{lstlisting}\nNote that the entries in the $\\lambda=1$ eigenvector do not generally add up to one.\nIndeed, any multiple of an eigenvector is an eigenvector.\nSo we need to multiply it by the appropriate constant so that all of the entries add up to one.\n\\begin{lstlisting}[style=python]\n: x = V[:,0]\n: x = x/sp.sum(x);x\narray([ 0.41836735,  0.23469388,  0.34693878])\n\\end{lstlisting}\nWe can check this answer by taking $A$ to a high exponent, say $A^{100}$.\n\n\\begin{problem}\nSuppose a basketball player's success at shooting free throws can be described with the following Markov chain\n\\[\nA = \\begin{pmatrix}.75&.50\\\\.25&.50\\end{pmatrix}\n\\]\nwhere the first state corresponds to success and the second state to failure.\n\\begin{enumerate}\n\\item If the player makes his first free throw, what is the probability that he also makes his third one?\n\\item What is the player's average free throw percentage?\n\\end{enumerate}\n\\end{problem}\n\n\\begin{problem}\nConsider the Markov process given by the transition diagram in Figure \\ref{markov2}.\n\\begin{enumerate}\n\\item Find the transition matrix.\n\\item If the Markov process is in state 1 initially, find the probability that it is in state 2 after 2 periods.\n\\item Find the stable fixed point if it exists.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[scale = 1.4]{markov2}\n\\end{center}\n\\caption{Transition diagram}\n\\label{markov2}\n\\end{figure}\n\n\\newpage\n\n\\section*{Graph Theory}\n\\begin{figure}[h!]\n\\includegraphics[scale = .4]{graphExample}\n\\caption{A simple graph}\n\\label{markov:example_graph}\n\\end{figure}\n\nGraph theory is an important branch of mathematics and computer science.\nIt describes how objects are connected to one another.\nIn a rigorous sense, a graph is composed of two sets: a set of nodes and a set of edges that connect these nodes. \n\nA graph is directed if connections are uni-directional, and undirected if they are bi-directional.\nFigure \\ref{markov:example_graph} shows a simple undirected graph.\nWe can write a matrix that describes this type of graph.\nWe let each row of our matrix represent our starting point and each column represent our destination.\nWe put a 1 if there is a path and a 0 if there is not.\nFor the above graph we generate the following matrix:\n\n\\[\nA = \\begin{pmatrix}\n0 & 1 & 0 & 0 & 1 & 0\\\\\n1 & 0 & 1 & 0 & 1 & 0\\\\\n0 & 1 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 1 & 1\\\\\n1 & 1 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 0 & 1 & 0 & 0\n\\end{pmatrix}\n\\]\n\nThis matrix is called an adjacency matrix.\nThis matrix is symmetric since the graph is undirected.\n\nWhat happens if we square an adjacency matrix?\nIt turns out that raising an adjacency matrix to the $n$ power yields the number of paths of length $n$ between two vertices.\nFor example, by squaring the above matrix Python gives:\n\\begin{lstlisting}[style=python]\n: np.linalg.matrix_power(A,2)\narray([[2, 1, 1, 1, 1, 0],\n       [1, 3, 0, 2, 1, 0],\n       [1, 0, 2, 0, 2, 1],\n       [1, 2, 0, 3, 0, 0],\n       [1, 1, 2, 0, 3, 1],\n       [0, 0, 1, 0, 1, 1]])\n\\end{lstlisting}\n\nNow try to find the number of connections of length 6 from node 3 to itself.\nThis is simple to do in Python:\n\\begin{lstlisting}[style=python]\n: np.linalg.matrix_power(A,6)\narray([[45, 54, 38, 45, 54, 16],\n       [54, 86, 29, 77, 51, 11],\n       [38, 29, 55, 15, 70, 27],\n       [45, 77, 15, 75, 31,  4],\n       [54, 51, 70, 31, 93, 34],\n       [16, 11, 27,  4, 34, 14]])\n\\end{lstlisting}\nIt turns out that there are 55 unique paths of length 6 from node 3 to itself.\nImagine trying to count all of those paths by hand!\nIt would be very easy to count incorrectly.\nHowever, this method makes it very simple to count paths without any mistakes.\n\n\\begin{problem}\nLet the following matrix represent a directed graph\n\\[\nA = \\begin{pmatrix}\n0 & 0 & 1 & 0 & 1 & 0 & 1\\\\\n1 & 0 & 0 & 0 & 0 & 1 & 0\\\\\n0 & 0 & 0 & 0 & 0 & 1 & 0\\\\\n1 & 0 & 0 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 0 & 1 & 0 & 0 & 0\\\\\n0 & 0 & 1  & 0 & 0& 0 & 1\\\\\n0 & 1 & 0 & 0 & 0 & 0 & 0\n\\end{pmatrix}\n\\]\nThe greatest number of paths of length five are from which node to each node?\nFrom which node to which node is their no path of length seven?\n\\end{problem}\n\nIt turns out that the study of graphs and connectivity has a variety of applications.\nFor example, connections between web pages can be described as graphs.\nSo can flights between airports or friends on social networking sites.\nThe same ideas are applied frequently in computer chip design and in the preservation of endangered species.\n\nWe can use an adjacency matrix to map out paths from one part of our graph to another.\nConsider the following maze:\n\n\\begin{figure}\n\\includegraphics[width=.8\\textwidth]{maze.pdf}\n\\caption{A maze for problem \\ref{maze_prob}.}\n\\label{maze_fig}\n\\end{figure}\n\nWith this lab we have included the file \\li{maze.npy} containing the adjacency matrix of this graph.\n\n\\begin{problem} \\label{maze_prob}\nWrite a function that, given the numbers of two different nodes and an adjacency matrix for a graph, will find a shortest path (there may be more than one, just return one) between any two nodes in the graph.\nUse the function you just wrote to solve the maze shown in figure \\ref{maze_fig}.\n\nHere is how this can be done:\n\\begin{itemize}\n\\item make a copy of the adjacency matrix\n\\item make a list containing the new aray\n\\item while the second node is not connected to the first node, update the copy to be itself times the adjacency matrix (using matrix multiplication) and append the new matrix to the end of the list.\nDo not update your arrays in place because you need to be appending different arrays to the end of your list.\n\\item Once the second node is connected to the first node, work through your list of arrays. \nMake a path starting at your first node and then consider all points that are one step away from the first node.\nAt least one of them should be connected to the final node in the second to the last matrix in the list.\nAdd one such node to your path and then continue in the same manner until you have a path between the nodes.\n\\end{itemize}\n\nHave your function raise an error if there is no path between the nodes it is given.\nOne way to do this is to have it raise an error if it has found no connection after raising the adjacency matrix to the power of the number of nodes involved.\nEssentially, if your paths are long enough to hit every node in the system and the two nodes you want to connect are still not connected, no connection can be found.\n\nThis is still not a fully optimized algorithm for solving this problem, but it works pretty well for small systems.\n\\end{problem}\n\n", "meta": {"hexsha": "348ba4216355028107202f36eeb79409bacc151b", "size": 11601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/MarkovGraph/MarkovGraph_C.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/MarkovGraph/MarkovGraph_C.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/MarkovGraph/MarkovGraph_C.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9117647059, "max_line_length": 264, "alphanum_fraction": 0.7197655375, "num_tokens": 3528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.90192067059785, "lm_q1q2_score": 0.8262581990954585}}
{"text": "\n\\subsection{Mean value theorem}\n\n\\subsubsection{Mean value theorem}\n\nTake a real function \\(f(x)\\) on closed interval \\([a,b]\\), differentiable on \\((a,b,)\\).\n\nThe mean value theorem states that:\n\n\\(\\exists c\\in(a,b) (f\u2019(c)=\\dfrac{f(b)-f(a)}{b-a})\\)\n\n", "meta": {"hexsha": "dc01b5335bc7a61d342d67abd7ccb6817f45b4a3", "size": 252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/calculus/01-08-meanValueTheorem.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/calculus/01-08-meanValueTheorem.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/calculus/01-08-meanValueTheorem.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.0, "max_line_length": 89, "alphanum_fraction": 0.6468253968, "num_tokens": 82, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.971992476960077, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.8261655883720749}}
{"text": "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Discrete Optimal Transport}\n\nMonge's original formulation of the OT problem corresponds to minimizing the cost for transporting a distribution $\\mu_X$ onto another distribution $\\mu_Y$ using a map $T$\n\\eql{ \n\t\\min_{T} \\int_X c(x,T(x)) \\d \\mu_X(x),   \n\t\\qwhereq\n\t T\\#\\mu_X=\\mu_Y.\n}\nHere, $\\mu_X,\\mu_Y$ are measures in $\\RR^d$, $T: \\RR^d \\rightarrow \\RR^d$ is a $\\mu_X$-measurable function, $c : \\RR^d \\times \\RR^d \\rightarrow \\RR^+$ is a $\\mu_X \\otimes \\mu_Y$-measurable function, and $\\#$ is the push forward operator. \n\nWe focus here on the case where the measures are discrete, have the same number of points, and all points have the same mass, thus \n\\eq{\n\t\\mu_X = \\frac{1}{N} \\sum_{i=1}^{N} \\delta_{X_i} \n\t\\qandq\n\t\\mu_Y = \\frac{1}{N} \\sum_{j=1}^{N} \\delta_{Y_j},\n}\nwhere $\\delta_x$ is the Dirac measure at location $x \\in \\RR^d$, and where the position of the supporting points are $X = (X_i)_{i=1}^N$, and $Y = (Y_j)_{j=1}^N$, where  $X_i,Y_j \\in \\RR^d$. In this context, the transport between $X$ and $Y$ is a one-to-one assignment,  i.e. \n% \\todo{It was written $T(X_i) = X_{\\sigma(i)}$ ! } \n$T(X_i) = Y_{\\sigma(i)}$ where $\\sigma$ is a permutation of $\\{1,\\ldots,N\\}$, which can be encoded using a permutation matrix $\\Sigma$ such that\n\\eq{ \\Sigma_{i,j} = \n \t\\choice{ \n\t\t1 \\qifq j=\\sigma(i), \\\\ \n\t\t0 \\quad \\text{otherwise}.  \n\t}\n} \nA more compact way to denote the transport is $T(X_i)=\\left(\\Sig Y\\right)_i, \\forall i=\\{1,\\ldots,N\\}$. Introducing the cost matrix\n\\eq{\n\tC_{X,Y} \\in \\RR^{N \\times N}\n\t\\qwhereq\n\t\\foralls (i,j) \\in \\{1,\\ldots,N\\}^2, \\quad (C_{X,Y})_{i,j} = c(X_i,Y_j),\n}\nthis permutation matrix $\\Sig$ is thus the solution to the following optimization problem\n\\eql{\n\t\\umin{\\Sig \\in \\Perm}  \n\t\t\\dotp{C_{X,Y}}{\\Sigma} = \\sum_{i,j=1}^N c(X_i,Y_j)  \\Sig_{i,j},\n\\label{eqW}} \nwhere $\\Perm$ is the set of permutation matrices  \n\\eq{\n\t\\Perm = \\enscond{\\Sig \\in \\RR^{N \\times N}}{ \\Sig^* \\U = \\U, \\Sig \\U = \\U, \\Sig_{i,j} \\in \\{0,1\\}},\n} \nsee~\\cite{Villani03} for more details. We have denoted $\\U=(1,\\ldots,1)^* \\in  \\RR^N$, and $A^*$ as the adjoint of the matrix $A$, that for real matrices amounts to the transpose operation.  \n \n\nIn the special case where \n\\eq{\n\t\\left(C_{X,Y}\\right)_{i,j} = c(X_i,Y_j)=\\norm{X_i-Y_j}^{\\al}\n} where $\\norm{\\cdot}$ is the Euclidean norm in $\\RR^d$ and $\\al \\ge 1$,  the value of the optimization problem~\\eqref{eqW} is called the $L^\\alpha$-Wasserstein distance (to the power $\\alpha$), and is denoted $W_\\alpha(\\mu_X,\\mu_Y)^\\alpha$. It can be shown that $W_\\alpha$ defines a distance on the set of distributions that have moments of order $\\al$.\n\n%  Note that computing the Wasserstein distance requires the computation of the transport map $T(X)=\\Sig X$.\n\n%%%\n\\paragraph{ Kantorovich OT formulation}\n\nThe set of permutation matrices $\\Perm$ is not convex.  Its convex hull is the set of bi-stochastic matrices\n\\eq{\n\t\\Matr_1 = \\enscond{\\Sig \\in \\RR^{N \\times N}}{ \\Sig \\U = \\U, \\Sig^* \\U = \\U, \\Sig_{i,j} \\in [0,1]}.\n}\nOne can show that the relaxation\n\\eql{\\label{eqMK}\n\t\\min_{\\Sig \\in \\Matr_1}  \\dotp{C_{X,Y}}{\\Sigma}\n} \nof~\\eqref{eqW} is tight, meaning that there exists a solution of~\\eqref{eqMK} which is a binary matrix, hence being also a solution of the original non-convex problem~\\eqref{eqW}, see~\\cite{Villani03}.\n", "meta": {"hexsha": "8ce837f0b87fc3fbace789d8a0772994de4a2a5b", "size": 3334, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/sec-transport.tex", "max_stars_repo_name": "gpeyre/2013-SIIMS-regularized-ot", "max_stars_repo_head_hexsha": "4d20033657717e3e0d744e3ce95fbc9afc6e5096", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-06-27T03:15:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-19T17:21:04.000Z", "max_issues_repo_path": "paper/sections/sec-transport.tex", "max_issues_repo_name": "gpeyre/2013-SIIMS-regularized-ot", "max_issues_repo_head_hexsha": "4d20033657717e3e0d744e3ce95fbc9afc6e5096", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/sections/sec-transport.tex", "max_forks_repo_name": "gpeyre/2013-SIIMS-regularized-ot", "max_forks_repo_head_hexsha": "4d20033657717e3e0d744e3ce95fbc9afc6e5096", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-10-12T17:29:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-04T01:52:32.000Z", "avg_line_length": 51.2923076923, "max_line_length": 354, "alphanum_fraction": 0.650869826, "num_tokens": 1185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561135, "lm_q2_score": 0.89181104831338, "lm_q1q2_score": 0.8260878935126295}}
{"text": "\\subsection{Surface Integrals of Scalar Functions}\r\n\\begin{definition}\r\n\tThe surface integral of a scalar function $f(x,y,z)$ is\r\n\t\\begin{equation*}\r\n\t\t\\iint\\limits_{S}{f(x,y,z)\\mathrm{d}s} = \\iint\\limits_{D}{(f\\circ\\vec{r})\\norm{\\vec{r_u} \\times \\vec{r_v}}\\mathrm{d}A}\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\r\n\\noindent\r\nLet\u2019s apply a surface integral to a real problem. Let the cap of the sphere or radius $8\\text{m}$ centered at the origin between $z = 7$ and $z = 8$ have a charge density $\\sigma(x,y,z) = z \\text{ } \\mu \\text{C}/ \\text{m}^2$. Find the total charge $Q$ on the cap.\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nWe will parameterize the cap using spherical coordinates.\r\n\\begin{equation*}\r\n\tD = \\left\\{(\\rho, \\theta, \\phi) \\mid \\rho=8, 0 \\leq \\theta \\leq 2\\pi, 0 \\leq \\phi \\leq \\cos^{-1}{\\left(\\frac{7}{8}\\right)}\\right\\}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\vec{r}(\\theta,\\phi) = \\langle 8\\sin{\\phi}\\cos{\\theta}, 8\\sin{\\phi}\\sin{\\theta}, 8\\cos{\\phi}\\rangle\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\vec{r_\\theta} = \\langle -8\\sin{\\phi}\\sin{\\theta}, 8\\sin{\\phi}\\cos{\\theta}, 0\\rangle \\text{, }\r\n\t\\vec{r_\\phi} = \\langle 8\\cos{\\phi}\\cos{\\theta}, 8\\cos{\\phi}\\sin{\\theta}, -8\\sin{\\phi}\\rangle\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\sigma\\circ\\vec{r} = 8\\cos{\\phi} \\text{, }\r\n\t\\norm{\\vec{r_\\theta} \\times \\vec{r_\\phi}} = 64\\sin{\\phi}\t\r\n\\end{equation*}\r\n\\begin{align*}\r\n\tQ &= \\int_{0}^{2\\pi}{\\int_{0}^{\\cos^{-1}{7/8}}{64\\sin{\\phi} \\cdot8 \\mathrm{d}\\phi\\mathrm{d}\\theta}} \\\\\r\n\t& = 8^3 2\\pi \\int_{0}^{\\cos^{-1}{7/8}}{\\sin{\\phi}\\mathrm{d}\\phi} \\\\\r\n\t&= 8^3 2\\phi(-\\cos{\\phi})\\rvert_{0}^{cos^{-1}{7/8}} = 8^3 2\\pi\\left(-7/8 + 1\\right) = 128\\pi\\text{ }\\mu\\text{C}\r\n\\end{align*}", "meta": {"hexsha": "36ae377a596391b6ac6418f6ee4307d934343feb", "size": 1668, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/surfaceIntegralsScalarFunctions.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/lineSurfaceIntegrals/surfaceIntegralsScalarFunctions.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/lineSurfaceIntegrals/surfaceIntegralsScalarFunctions.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.0588235294, "max_line_length": 264, "alphanum_fraction": 0.6163069544, "num_tokens": 694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.9005297927918166, "lm_q1q2_score": 0.82605837192823}}
{"text": "\n\\subsection{Morphism}\n\nMorphisms are functions which preserve the relationships between members of a set, and specified functions.\n\nThat is, if:\n\n\\(a\\odot b=c\\)\n\nThen \\(f(x)\\) is morphism if:\n\n\\(f(a)\\odot f(b)=f(a\\odot b)\\)\n\nHere we discuss morphisms in the context of groups, but we can define morphisms for sets with more than one function, for example with addition and multiplication.\n\nMorphisms are also known as homomorphisms.\n\nThe following are morphisms of the additive group of integers.\n\nWhere we refer to \\(c\\), \\(c\\ne 0\\in \\mathbb{I}\\).\n\n\\begin{itemize}\n\\item \\(f(x)=0\\)\n\\item \\(f(x)=x\\)\n\\item \\(f(x)=cx\\)\n\\item Converting natural numbers to integers\n\\end{itemize}\n\nThe following are not morphisms\n\n\\begin{itemize}\n\\item \\(f(x)=x+1\\)\n\\end{itemize}\n\n\n\\subsubsection{Isomorphism}\n\nAn isomorphism is a morphism which has an inverse.\n\nThis means the function is bijective.\n\nThe following are isomorphisms:\n\n\\begin{itemize}\n\\item \\(f(x)=x\\)\n\\item \\(f(x)=cx\\)\n\\item Converting natural numbers to integers\n\\end{itemize}\n\nThe following are not isomorphisms\n\n\\begin{itemize}\n\\item \\(f(x)=0\\)\n\\item \\(f(x)=x+1\\)\n\\end{itemize}\n\n\\subsubsection{Endomorphism}\n\nAn endomorphism is one where the domain and codomain are the same.\n\nThe following are endomorphisms:\n\n\\begin{itemize}\n\\item \\(f(x)=0\\)\n\\item \\(f(x)=x\\)\n\\item \\(f(x)=cx\\)\n\\end{itemize}\n\nThe following are not endomorphisms\n\n\\begin{itemize}\n\\item Converting natural numbers to integers\n\\item \\(f(x)=x+1\\)\n\\end{itemize}\n\n\\subsubsection{Automorphism}\n\nAn endomorphism which is also an isomorphism\n\nThe following are automorphisms:\n\\begin{itemize}\n\\item \\(f(x)=x\\)\n\\item \\(f(x)=cx\\)\n\\end{itemize}\n\nThe following are not automorphisms\n\n\\begin{itemize}\n\\item \\(f(x)=0\\)\n\\item \\(f(x)=x+1\\)\n\\item Converting natural numbers to integers\n\\end{itemize}\n\n\\subsubsection{Monomorphism}\n\nA morphism which is injective. That is:\n\n\\(f(a)=f(b)\\rightarrow a=b\\)\n\nThe following are monomorphisms:\n\n\\begin{itemize}\n\\item \\(f(x)=x\\)\n\\item \\(f(x)=cx\\)\n\\item Converting natural numbers to integers\n\\end{itemize}\n\nThe following are not monomorphisms:\n\n\\begin{itemize}\n\\item \\(f(x)=0\\)\n\\item \\(f(x)=x+1\\)\n\\end{itemize}\n\n", "meta": {"hexsha": "aa9270259090835114ede8c16678862eca57b035", "size": 2152, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/02-02-morphisms.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/groups/02-02-morphisms.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/groups/02-02-morphisms.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.7130434783, "max_line_length": 163, "alphanum_fraction": 0.7146840149, "num_tokens": 678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8887587942290704, "lm_q1q2_score": 0.8260483360744564}}
{"text": "%---------------------------Scaled Jacobian-----------------------------\n\\section{Scaled Jacobian\\label{s:tri-scaled-jacobian}}\n\nFirst, let $L_{\\max}$ be the product of the lengths of the 2 longest edges:\n\\[\n  L_{\\max} = \\max\\left\\{\n    \\normvec{ L_0} \\normvec{ L_1},\n    \\normvec{ L_0} \\normvec{ L_2},\n    \\normvec{ L_1} \\normvec{ L_2}\n  \\right\\}\n\\]\nLet $J^{\\prime}$ be the Jacobian of the triangle.\nIf the triangle surface normal $\\hat n$ is evaluated at the center of the triangle\nand $\\hat n\\cdot\\left(\\vec L_2\\times\\vec L_1\\right) < 0$, then take $J = -J^{\\prime}$.\nOtherwise take $J = J^{\\prime}$.\nThe scaled Jacobian is then\n\\[\n  q = \\frac{2\\sqrt{3}}{3} \\frac{J}{L_{\\max}}\n\\]\nwhich is normalized so that a unit equilateral triangle has value $1$.\n\nNote that if $L_{\\max} \\leq DBL\\_MIN$, we set $q = 0$.\n\n\\trimetrictable{scaled Jacobian}%\n{$1$}%                                                Dimension\n{$[0.5,\\frac{2\\sqrt{3}}{3}]$}%                        Acceptable range\n{$[-\\frac{2\\sqrt{3}}{3},\\frac{2\\sqrt{3}}{3}]$}%       Normal range\n{$[-DBL\\_MAX,DBL\\_MAX]$}%                             Full range\n{$1$}%                                                Unit equilateral triangle value\n{\\cite{knu:00}}%                                      Reference(s)                   \n{v\\_tri\\_scaled\\_jacobian}%                            Verdict function name\n\n", "meta": {"hexsha": "b271ff06fd808940d3574d3da3a27896752084be", "size": 1362, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriScaledJacobian.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriScaledJacobian.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriScaledJacobian.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 41.2727272727, "max_line_length": 86, "alphanum_fraction": 0.5183553598, "num_tokens": 410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947163538935, "lm_q2_score": 0.8740772482857831, "lm_q1q2_score": 0.8259983813152154}}
{"text": "\n\\subsection{Softmax}\n\nThe softmax function is often used in the last layer of a classification network.\n\nIt takes a vector of dimension \\(k\\) and returns another vector of the same size. Only, this time all numbers are between \\(0\\) and \\(1\\) and the values sum to \\(1\\).\n\nThe softmax function is based on the sigmoid function.\n\n\\(a_j(z)=\\dfrac{e^{z_j}}{\\sum_{i}e^{z_i}}\\)\n\n\\subsection{Temperature for Softmax}\n\n\n", "meta": {"hexsha": "0efcb835bf5a587d9fa95536bec26b8def4434f4", "size": 414, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/glmMulti/01-07-softmax.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/glmMulti/01-07-softmax.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/glmMulti/01-07-softmax.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6, "max_line_length": 166, "alphanum_fraction": 0.7222222222, "num_tokens": 108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9763105245649665, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.825902497136554}}
{"text": "\\section{Discrete Fourier Transform Basics}\n\n\\begin{enumerate}[label=\\alph*), leftmargin=*]\n%% a)\n\\item\n%\nThe Fourier Transform (FT) of a sine wave at $f_{0}=20Hz$ is discrete, since the time series is periodic, comprising of Dirac $\\delta$ functions at $\\pm f_{0}$,\nprovided at figure \\ref{fig:1_1_a}. Since the windowing (multiplication) operation in time domain is equivalent to convolution in the frequency domain,\nthe Discrete Time Fourier Transform (DTFT) of a windowed sine wave at $20Hz$ is derived by convolution of the ideal FT of the sine wave,\nDirac $\\delta$ functions, with the FT of the rectangular window, $sinc$ function, illustrated at figure \\ref{fig:1_1_a} for different window lengths $\\tau$.\nThe spectrum leakage is demonstrated, as well as the trade-off between side-lobes peak and window length $\\tau$ (inverse relationship).\n%\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/discete-fourier-transform-basics/assets/a/sine-ideal-spectrum}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/discete-fourier-transform-basics/assets/a/dtft-theoretical-window}\n    \\end{subfigure}\n    \\caption{Ideal magnitude spectrum (left) and theoretical DTFT (right) of $20Hz$ sine wave.}\n    \\label{fig:1_1_a}\n\\end{figure}\n\n\n%% b)\n\\item\n%\nThe Discrete Fourier Transform (DFT) spectrum of a finite length sine wave at $f_{0}=20Hz$ is considered. The signal can be treated as\na windowed and sampled version of the continuous, infinite length sine wave. Consequently, its DFT is expected to be a sampled version of the DTFT shown\nin figure \\ref{fig:1_1_a}, at frequency intervals defined by the frequency resolution $\\Delta f = \\frac{F_{s}}{K}$, where $F_{s}$ and $K$ the sampling frequency\nand the sequence length, respectively. In case of $K=100$, we obtain $F_{s}=1000Hz$ and $\\Delta f = 10Hz$, leading to elimination of spectrum leakage or\n\\textbf{coherent sampling}, since at the integer multiples of the frequency resolution $10Hz$, the $sinc$ function is zero, excluding the peaks at $\\pm f_{0}$.\nWe highlight that this is not the same with the ideal FT spectrum, but just the result of frequency quantisation. If $f_{0}$ or $F_{s}$ are slightly perturbed\nthen the leakage will be inevitable. When zero-padding is performed and $K=1000$, then $\\Delta f = 1Hz$ and the impact of the spectrum leakage is evident.\nFigure \\ref{fig:1_1_b} illustrated the DFT spectra of those experiments.\n%\n\\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/discete-fourier-transform-basics/assets/b/dft-f0_20-K_100}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/discete-fourier-transform-basics/assets/b/dft-f0_20-K_1000}\n    \\end{subfigure}\n    \\caption{$20Hz$ sampled sine wave DFT spectra and coherent sampling.}\n    \\label{fig:1_1_b}\n\\end{figure}\n\n\n%% c)\n\\item\n%\nThe experiment is repeated for a finite length sine wave at $f_{1}=24Hz$ and its spectra are provided at \\ref{fig:1_1_c}.\nAs expected this time for both $K=100$ and $K=1000$ spectral leakage is unavoidable. However, especially in case of $K=100$\nwhen $\\Delta f = 10Hz$, we note that the peaks at $\\pm f_{1} = \\pm 24Hz$ are undetected and therefore the sequence is\nincoherently sampled. Increasing the zero-padding samples, such that the frequency resolution $\\Delta f$ is a factor of $f_{1}$\nresolves this issue, therefore nothing can be done for the spectral leakage effect. Candidate values for $K$ then are:\n$125, \\frac{1000}{6}, 250, 500, 1000, \\cdots$.\n%\n\\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/discete-fourier-transform-basics/assets/c/dft-f0_24-K_100}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/spectrum-estimation/discete-fourier-transform-basics/assets/c/dft-f0_24-K_1000}\n    \\end{subfigure}\n    \\caption{$24Hz$ sampled sine wave DFT spectra and incoherent sampling.}\n    \\label{fig:1_1_c}\n\\end{figure}\n\\end{enumerate}", "meta": {"hexsha": "e1e1c31ad2254cec7c359cb865699c6152000f08", "size": 4406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/spectrum-estimation/discete-fourier-transform-basics/index.tex", "max_stars_repo_name": "filangel/ASPMI", "max_stars_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-02-20T14:43:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-13T21:13:02.000Z", "max_issues_repo_path": "tex/report/spectrum-estimation/discete-fourier-transform-basics/index.tex", "max_issues_repo_name": "AmjadHisham/ASPMI", "max_issues_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/report/spectrum-estimation/discete-fourier-transform-basics/index.tex", "max_forks_repo_name": "AmjadHisham/ASPMI", "max_forks_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-07-17T08:32:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-12T18:26:18.000Z", "avg_line_length": 54.3950617284, "max_line_length": 160, "alphanum_fraction": 0.7349069451, "num_tokens": 1254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.918480249045993, "lm_q1q2_score": 0.8258252265174739}}
{"text": "\\section{Theory}\n\\label{sec:fundamentals}\n\nThe perceptron is the first mathematical model of a biological neuron.\nLike a neuron, it has $N$ incoming connections, which represents the input, and $1$ outgoing connection, which represents the output (i.e. the class of the given example).\nThe output $S$ is a function of the input $\\xi$, defined as the sign of the weighted sum of the input vector:\n\\begin{equation}\n    S = sign(\\mathsf{\\bm{w}} \\cdotp \\xi) = \\pm 1,\n    \\label{eq:perceptron-activation}\n\\end{equation}\nwhere $\\mathsf{\\bm{w}}$ is an $N$-dimensional vector.\nThe $sign$ function simulates the activation function of the biological neuron and forces the possible output values to $\\pm 1$.\n\nThe training process aims at learning the optimal weights vector $\\mathsf{\\bm{w}}$ to classify correctly all examples.\nAt time $t$, an example $\\xi^t$ is presented to the perceptron:\nif the output equals to the correct class $S^t$, $\\mathsf{\\bm{w}}$ is not changed;\nif the output is wrong, a learning step is performed to correct $\\mathsf{\\bm{w}}$.\nThe procedure is repeated until the perceptron correctly classifies all the training dataset or until some maximum number of iterations is reached.\n\nThe Rosenblatt Perceptron training procedure is formally defined as:\n\\begin{gather}\n    \\label{eq:perceptron-weight-update}\n    \\mathsf{\\bm{w}}(t+1) = \\mathsf{\\bm{w}}(t) + \\frac{1}{N} \\Theta \\big[c - E^{v(t)}\\big] \\xi^{v(t)} S^{v(t)}, \\\\\n    \\Theta[c - E^{\\mu}] =  \\begin{cases} \\label{eq:heaviside-fun}\n        1 & E^{\\mu} \\leq c \\\\\n        0 & E^{\\mu} > c\n    \\end{cases},\n\\end{gather}\nwhere $E^{v(t)} = \\mathsf{\\bm{w}}(t) \\cdot \\xi^{v(t)} S^{v(t)}$.\nThe weights are initialized as $\\mathsf{\\bm{w}}(0) = 0$.\nThe product $\\xi^{v(t)} S^{v(t)}$ is called Hebbian term.\n\nThe performances of the perceptron are related to the storage capacity of the hyperplane defined by its weights.\nFor a random dataset with $P$ examples and $N$ dimensions (where $S^\\mu = 1$ with probability $1/2$), the theoretical probability of linear separability $P_{l.s.}(P,N)$ is given by:\n\\begin{equation}\n    P_{l.s.}(P,N) =\n    \\begin{cases}\n        \\hfil 1 & \\text{for} \\; P \\leq N \\\\\n        2^{1-P} \\sum^{N-1}_{i=0} \\binom{P - 1}{i} & \\text{for} \\; P > N       \n    \\end{cases}\n    \\label{eq:prob-lin-sep}\n\\end{equation}\n\nFor $N \\rightarrow \\infty$, $P_{l.s.}(P,N)$ has a well-defined behavior:\n\\begin{equation} \\label{eq:prob-lin-sep-alpha}\n    P_{l.s.}(P,N) =\n    \\begin{cases}\n        1 & \\text{for} \\; \\alpha \\leq 2 \\\\\n        0 & \\text{for} \\; \\alpha > 2\n    \\end{cases},\n\\end{equation}\nwhere $\\alpha = P / N$.\n", "meta": {"hexsha": "10f5d0b5c91ca82025dfd97c3593e862cb2a4ac5", "size": 2593, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_1/report/02_theory.tex", "max_stars_repo_name": "davidepedranz/neural_networks_assignments", "max_stars_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_1/report/02_theory.tex", "max_issues_repo_name": "davidepedranz/neural_networks_assignments", "max_issues_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_1/report/02_theory.tex", "max_forks_repo_name": "davidepedranz/neural_networks_assignments", "max_forks_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.9245283019, "max_line_length": 181, "alphanum_fraction": 0.660624759, "num_tokens": 836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377237352755, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.8258168673635513}}
{"text": "\n\\subsection{The direct product of groups}\n\nIf we have two groups \\(G\\) and \\(H\\) we can form new group \\(G\\times H\\).\n\nFor every \\(g\\in G\\) and \\(h\\in H\\) there is \\((g,h)\\in G\\times H\\).\n\nThe binary operation we have is:\n\n\\((g_1, h_1)(g_2,h_2)=(g_1g_2,h_1,h_2)\\)\n\n", "meta": {"hexsha": "ed6438416048917e40904b75031bb42e9a54d331", "size": 266, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/03-02-directProduct.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/groups/03-02-directProduct.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/groups/03-02-directProduct.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.1666666667, "max_line_length": 74, "alphanum_fraction": 0.6278195489, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731158685837, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.8257502960736256}}
{"text": "\\chapter{The Tensor Product}\nConsider the Cartesian product of a vector space $V$ and itself, $V \\times V$. A \\emph{tensor}~$T$ is a \\emph{multilinear map} from this product and the field $\\mathbb{F}$ over which the vector spaces are taken, where multilinear simply means that the map is linear in each component of the domain. Explicitly, it acts in the following way:\n\\[ T : V \\times V \\to \\mathbb{F} : (\\vec{v}, \\vec{w}) \\mapsto \\langle \\Lambda, \\vec{v} \\rangle\\langle \\Gamma, \\vec{w} \\rangle. \\]\nSince we already have tools which map vectors in $V$ to $\\mathbb{F}$ in a linear fashion --- covectors from the dual space --- we define a tensor by using combinations of these covectors using the \\emph{tensor product}~$\\otimes$.\nConsider the Cartesian produt $V \\times V$; if we want to send the ordered pair $(\\vec{v}, \\vec{w})$ to $\\mathbb{F}$, we take two covectors, $\\beta$ and $\\alpha$, and take their tensor product to get\n\\[ \\beta \\otimes \\alpha : V \\times V \\to \\mathbb{F} : (\\vec{v},\\vec{w}) \\mapsto \\langle \\beta, \\vec{v} \\rangle\\langle \\alpha, \\vec{w} \\rangle. \\]\nSeveral things:\n\\begin{itemize}\n    \\item First, notice that the result of multilinear tensors are multiplied together, where the multiplication is the multiplication operation defined for that field.\n    \\item This is only a single type of tensor --- there are many others, including regular covectors and regular vectors.\n    \\item This tensor is an element of $V^* \\times V^*$, while it takes an argument of $V \\times V$.\n\\end{itemize}\n\n\\section{Addition \\& the Tensor Product Space}\nConsider again the vector space $V$ and its dual space $V^*$. Let's consider two tensors, $\\alpha \\otimes \\beta$ and $\\gamma \\otimes \\delta$, both elements of $V^* \\times V^*$.\nSince tensors are multilinear maps, we want tensor addition to act linearly. \nWe define tensor addition to act as follows:\n\\begin{align*}\n    [\\alpha \\otimes \\beta + \\gamma \\otimes \\delta](\\vec{v},\\vec{w}) &= \\alpha\\otimes\\beta (\\vec{v},\\vec{w}) + \\gamma\\otimes\\delta(\\vec{v},\\vec{w}) \\\\\n    &= \\langle \\alpha, \\vec{v} \\rangle\\langle \\beta, \\vec{w} \\rangle + \\langle \\gamma, \\vec{v} \\rangle\\langle \\delta,\\vec{w} \\rangle\n\\end{align*}\nLikewise with addition, if we introduce scalar factors from $\\mathbb{F}$, we define tensors such that\n\\[\\lambda_1\\alpha\\otimes\\lambda_2\\beta(\\vec{v},\\vec{w}) = \\lambda_1\\lambda_2\\langle \\alpha, \\vec{v} \\rangle\\langle \\beta, \\vec{w} \\rangle.\\]\nSince the components of a tensor are members of the dual space, if we choose them to be the zero maps, we have created the `zero tensor'. \nThis, combined with the above two facts, means that the set of all possible tensors of a certain number of components (called rank) form a vector space. \nThis space is called the \\emph{tensor product space}, and since all elements of vector spaces are vectors, this means that tensors are vectors \\emph{and} vectors are tensors!\\footnote{It's vector spaces all the way down!}\n\n\\section{Review \\& Formalism}\nWe begin with a vector space $V$ over a field $\\mathbb{F}$ with a basis $\\{\\vec{e}_\\nu\\}$, which implies the existence of a dual space $V^*$ with a basis $\\{\\vec{e}^\\mu\\}$.\nThis gives us a special type of tensor product space, $ V^* \\otimes V^*$, whose elements are bilinear in $V \\times V$.\nBecause $V^* \\otimes V^*$ is a vector space, it has addition and scalar multiplication, and is also taken over the same field $\\mathbb{F}$.\nWe select the basis of the vector and dual space such that\n\\[ \\langle \\vec{e}^\\mu, \\vec{e}_\\nu \\rangle = \\delta^\\mu_\\nu. \\]\nSince the tensor product space is a vector space, it too has a basis.\nAs tensors in $V^* \\otimes V^*$ are composed of linear maps from $V^*$, the basis for the tensor product space is $\\vec{e}^\\mu \\otimes \\vec{e}^\\nu$.\nNote that, in this basis, the index $\\mu$ does not always equal $\\nu$.\nThese tensors can be defined by\n\\[ A_\\mu \\vec{e}^\\mu \\otimes B_\\nu \\vec{e}^\\nu : V \\times V \\to \\mathbb{F} : (C^\\alpha \\vec{e}_\\alpha, D^\\beta \\vec{e}_\\beta) \\mapsto A_\\mu C^\\mu B_\\nu D^\\nu. \\]\nNote that if our original vector space as four dimensional, the tensor product space will have dimension $4 \\times 4 = 16$, which means that there are 16 basis vectors encapsulated by $\\vec{e}^\\mu \\otimes \\vec{e}^\\nu$.\nBecause of the linearity of tensors, we can simplify the way we write a tensor into a single coefficient, using multiple indicies:\n\\[ A_\\mu \\vec{e}^\\mu \\otimes B_\\nu \\vec{e}^\\nu \\equiv T_{\\mu\\nu} \\vec{e}^\\mu \\otimes \\vec{e}^\\nu. \\]\nBecause Physicists and Mathematicians are fundamentally lazy people, and more importantly because \\emph{any} tensors from the same tensor product space specified with the same vectors will differ only by the coefficient, we often adopt the convention of dropping the basis when discussing a specific tensor, and refer to it only by this coefficient; the above tensor would be called $T_{\\mu\\nu}$. These leading coefficients are often called the tensor's \\emph{components}.\n", "meta": {"hexsha": "472e51ca75e28d2d9cb1b420016a9942ed6ef3a2", "size": 4927, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/tensor_product.tex", "max_stars_repo_name": "jopetty/tensor-notes", "max_stars_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/tensor_product.tex", "max_issues_repo_name": "jopetty/tensor-notes", "max_issues_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/tensor_product.tex", "max_forks_repo_name": "jopetty/tensor-notes", "max_forks_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 114.5813953488, "max_line_length": 472, "alphanum_fraction": 0.7176781003, "num_tokens": 1442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.962673109443157, "lm_q2_score": 0.8577680977182186, "lm_q1q2_score": 0.8257502818115392}}
{"text": "\n\\subsection{The binomial data generating process}\n\n\\subsubsection{Introduction}\n\nFor linear regression our data generating process is:\n\n\\(y=\\alpha + \\beta x +\\epsilon \\)\n\nFor linear classification our data generating process is:\n\n\\(z=\\alpha + \\beta x +\\epsilon \\)\n\nAnd set \\(y\\) to \\(1\\) if \\(z>0\\)\n\nOr:\n\n\\(y=\\mathbf I[\\alpha+\\beta x+\\epsilon >0]\\)\n\n\\subsubsection{Probability of each class}\n\nThe probability that an invididual with characteristics \\(x\\) is classified as \\(1\\) is:\n\n\\(P_1=P(y=1|x)\\)\n\n\\(P_1=P(\\alpha + \\beta x+\\epsilon >0)\\)\n\n\\(P_1=\\int \\mathbf I [\\alpha + \\beta x+\\epsilon >0]f(\\epsilon )d\\epsilon \\)\n\n\\(P_1=\\int \\mathbf I [\\epsilon >-\\alpha-\\beta x ]f(\\epsilon )d\\epsilon \\)\n\n\\(P_1=\\int_{\\epsilon=-\\alpha-\\beta x}^\\infty f(\\epsilon )d\\epsilon \\)\n\n\\(P_1=1-F(-\\alpha-\\beta x) \\)\n\n\\subsubsection{Example: The logistic function}\n\nDepending on the probability distribution of \\(epsilon \\) we have different classifiers.\n\nFor the logistic case we then have\n\n\\(P(y=1|x)=\\dfrac{e^{\\alpha + \\beta x}}{1+e^{\\alpha + \\beta x}}\\)\n\n", "meta": {"hexsha": "b25355ac3423894024aca6fbbf2c6d8ce9e62fe1", "size": 1038, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/glm/03-01-binomial.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/glm/03-01-binomial.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/glm/03-01-binomial.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5909090909, "max_line_length": 88, "alphanum_fraction": 0.6685934489, "num_tokens": 322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9736446448596305, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.8256192650877903}}
{"text": "\n\n\\section{Important probability distributions}\n\n\\subsection*{Table}\n\n\\begin{figure*}\n\\resizebox{\\linewidth}{!}{%\n\\begin{tabular}{ l  l  l  l l  l  l l  l l}\n\n Dist & Param & PDF & CDF & Mean & var & F($\\theta$) & MLE & Likeleyhood $= \\displaystyle  L_ n(X_1, \\ldots , X_ n, \\theta )$  & Log likelyhood \\\\ \n\\hline \n \n %BERN\n Ber(p) coin flip \n &\n $p \\in[0,1]$ \n &\n $ p_x(k)=\t\\begin{cases} p,&\\text{if k = 1}\\\\(1-p),&\\text{if k = 0} \\end{cases}$ \n &\n None \n &\n p \n &\n p(1-p) \n &\n $I(p) = \\frac{1}{p(1-p)}$ \n &\n $\\hat{p}_{MLE} = \\frac{\\sum^n_{i=1}(X_i)}{n}$ \n &\n $ p^{\\sum _{i = 1}^ n X_ i} (1 -p)^{{\\color{blue}{n - }} \\sum _{i = 1}^ n X_ i}$  \n &\n $\\ell_n (p)  = \\ln  \\left( p \\right) \\sum _{i=1}^{n}X_{{i}}+ \\left( n-\\sum _{i=1}^{n}X_{{i}} \\right) \\ln  \\left( 1-p \\right)$\n \\\\\\hline \n   \n \n %BINOM\n Binom(p) (n coin flips)\n &\n $p \\in[0,1]$ \n &\n $p_x(k) = {\\binom{n}{k}} {p}^{k} (1-p )^{n-k}$, $k=0...n$ \n &\n None \n &\n $n*p$ \n &\n $n p(1-p)$ \n &\n $I(p) = \\frac{n}{p(1-p)}$\n &\n MLE \n & \n $\\displaystyle   \\left( \\prod _{i = 1}^ n \\binom {K}{X_ i} \\right) \\theta ^{\\sum _{i = 1}^ n X_ i} (1 - \\theta )^{nK - \\sum _{i = 1}^ n X_ i }$ \n &\n $\\ell_n (\\theta) = C + \\left( \\sum _{i = 1}^ n X_ i \\right) \\log \\theta + \\left( nK - \\sum _{i = 1}^ n X_ i \\right) \\log (1 - \\theta )$  \n \\\\\\hline \n \n\n \n $Geometric(p) \\\\ T trials for 1st success. $\n &\n $p \\in[0,1]$ \n &\n $p_T(t) = (1-p)^{t-1}, t=1,2..$\n &\n None\n &\n $\\frac{1}{p}$\n &\n $\\frac{1-p}{p^2}$\n &\n Fisher\n &\n MLE\n &\n LIKEHOD\n &\n LOG LIKEH\n \n \\\\\\hline \n \n \n $ Multinomial(p_0...p_r,n) $\n &\n $n>0$ and $p_1, \\ldots, p_r$\n &\n $p_x(x_1...x_n)=\\frac{n!}{x_1!,\\ldots,x_n!} p_1, \\ldots, p_r$\n &\n None\n &\n $n p_i$\n &\n$n * p_i(1-p_i)$\n &\n Fisher\n &\n MLE\n &\n \\thead{$p_x(x)= \\prod _{j=1}^{n}{p_{{j}}}^{T_{{j}}}$, where $T^j=\\mathbbm{1}( X_i=j)$  \\\\ is the count how often an outcome is seen in trials.}\n &\n $\\ell_n= \\sum _{j=2}^{n}T_{{j}}\\ln  \\left( p_{{j}} \\right)$\n \n \\\\\\hline \n \n\n\n Poisson($\\lambda$)  Discrete \n &\n $\\lambda > 0$ \n &\n $\\mathbf{p_x}(k)=exp(-\\lambda)\\frac{\\lambda^k}{k!}$ for $k=0,1, \\ldots,$\n &\n CDF\n &\n $\\lambda$\n &\n $\\lambda$\n &\n $I(\\lambda)= \\frac{1}{\\lambda}$\n &\n $\\hat{\\lambda}_{MLE} = \\frac{1}{n} \\sum^n_{i=1}(X_i)$\n &\n $ \\prod _{i = 1}^ n \\frac{\\lambda^{\\sum_{i=1}^{n} x_i}}{\\prod _{i = 1}^ n x_i!} e^{-n\\lambda}$\n & \n $\\ell_n (\\lambda)=  -n\\lambda + log(\\lambda)(\\sum_{i=1}^n x_i)) - log(\\prod _{i = 1}^ n x_i!)$\n \n \\\\\\hline \n \n Exp(\\lambda)  Dist \n &\n $\\lambda$ >0\n &\n $ f_x(x)=\n\t\\begin{cases}\n\t\t \\lambda exp(-\\lambda x),&\\text{if x >= 0}\\\\\n\t\t0,&\\text{o.w.}\\\\\n\t\\end{cases}\n $\n &\n $ \\begin{cases}\n\t\t1-exp(-\\lambda x),{if x >= 0}\\\\\n\t\t0,\\quad{o.w.}\\\\\n\t\tP(X>a)= exp(-\\lambda a)\n\t\\end{cases}\n $\n &\n $\\frac{1}{\\lambda}$\n &\n $\\frac{1}{\\lambda^2}$\n &\n $I(\\lambda)= \\frac{1}{\\lambda^2}$\n &\n $\\hat{\\lambda}_{MLE}= \\frac{n}{\\sum^{n}_{i=1}(X_i)}$\n &\n $\\lambda^n\\exp\\left(-\\lambda\\sum_{i=1}^n X_i\\right)$\n &\n $\\ell_n (\\lambda)= n ln(\\lambda) - \\lambda \\sum_{i=1}^n (X_i)$\n \\\\\\hline \n \n \n Shifted Exp (b,a) Dist \n &\n Parameters $\\lambda, a \\in \\mathbb{R}$\n &\n $ f_x(x)=\n\t\\begin{cases}\n\t\t \\lambda exp(-\\lambda(x - a )),&{x >= a}\\\\\n\t\t0,&{x <= a}\\\\\n\t\\end{cases}\n$\n\n &\n $ \t\\begin{cases}\n\t\t 1-exp(-\\lambda(x-a)),\\quad{if x >= a}\\\\\n\t\t0,\\quad{x <= a}\\\\\n\t\\end{cases}\n$\n &\n $a + \\frac{1}{\\lambda}$\n &\n $\\frac{1}{\\lambda^2}$\n &\n F($\\theta$)\n &\n $ \\begin{cases} \n {\\lambda } = \\frac{1}{\\overline{X}_ n - \\hat{a}}\\\\\n {a} = \\min(X_ i)\n \\end{cases}\n $\n &\n $ \\lambda ^ n \\exp \\left( -\\lambda \\sum _{i = 1}^ n (X_ i - a) \\right) \\mathbf{1}_{\\min _{i = 1, \\ldots , n}(X_ i) \\geq a}.$\n &\n $\\ell (\\lambda , a) := n \\ln \\lambda - \\lambda \\sum _{i = 1}^ n X_ i + n \\lambda a$ \n \\\\\\hline \n \n \n \n  Uniform(a,b) \n &\n $a$ and $b$\n &\n $ \\mathbf{f_x}(x)=\n\t\\begin{cases}\n\t\t \\frac{1}{b-a},&\\text{if a < x <b}\\\\\n\t\t0,&\\text{o.w.}\\\\\n\t\\end{cases}\n$\n &\n $ \\mathbf{F_x}(x)=\n\t\\begin{cases}\n\t\t 0,&for x \\leq a\\\\\n\t\t \\frac{x-a}{b-a},& x \\in [a,b)\\\\\n\t\t1,&x \\geq b\\\\\n\t\\end{cases}\n$\n &\n $\\frac{a+b}{2}$\n &\n $\\frac{(b-a)^2}{12}$\n &\n F($\\theta$)\n &\n MLE\n &\n $\\frac{\\max_i (x_i \\leq b)} {b^n}$\n &\n $ln(\\frac{\\max_i (x_i \\leq b)} {b^n})$\n \\\\\\hline \n \n \n\n \n Normal(\\mu, \\sigma)  Dist  \n &\n $\\mu$ and $\\sigma^2 >0$\n &\n $f(x)= \\frac{1}{\\sqrt(2 \\pi \\sigma^2)} exp(-\\frac{(x-\\mu)^2}{2\\sigma^2})$ \n &\n $\\Phi (z) = \\int _{-\\infty }^ z \\frac{1}{\\sqrt{2 \\pi }} e^{-x^2/2} \\,  dx$\n &\n $\\mu$ \n &\n $\\sigma^2$\n &\n $I(\\mu , \\sigma ^2) = \\begin{pmatrix}  \\frac{1}{\\sigma ^2} &  0 \\\\ 0 &  \\frac{1}{2 \\sigma ^4} \\end{pmatrix}$ \n &\n $\\hat\\mu = \\bar X_ n, \\quad \\widehat{\\sigma ^2} = \\frac{1}{n} \\sum _{i=1}^{n} (X_ i - \\bar X_ n)^2$\n &\n $ \\dfrac{1}{\\left(\\sigma\\sqrt{2\\pi}\\right)^n}\\exp{\\left(-\\dfrac{1}{2\\sigma^2}\\sum_{i=1}^n (X_i-\\mu)^2 \\right)}$\n  & \n  $\\ell_n (\\mu,\\sigma^2)= -n log(\\sigma\\sqrt{2\\pi})-\\frac{1}{2\\sigma^2}\\sum_{i=1}^n (X_i-\\mu)^2 $\n  \\\\\\hline \n  \n  \n Hypergeom  Dist \n & Param & PDF & CDF & Mean & var & F($\\theta$) & MLE & Likeleyhood & Log likelyhood  \\\\\\hline \n \n \n Negative Binom  Dist  & Param & PDF & CDF & Mean & var & F($\\theta$) & MLE & Likeleyhood & Log likelyhood  \\\\\\hline \n \n Beta  Dist  & Param & PDF & CDF & Mean & var & F($\\theta$) & MLE & Likeleyhood & Log likelyhood  \\\\\\hline \n \n \n\\end{tabular}\n} %resize End \n\n\\end{figure*}\n\n\n\\subsection*{Univariate Gaussians}\n\nCanonical exponential form:\\\\\n\nGaussians are invariant under affine transformation:\\\\\n\n$aX+b \\sim N(X+b,a^2\\sigma^2)$\\\\\n\nSum of independent gaussians:\\\\\n\nLet $X {\\sim} N(\\mu_X,\\sigma_X^2)$ and $Y {\\sim} N(\\mu_Y,\\sigma_Y^2)$\\\\\n\nIf $Y = X + Z$, then $Y \\sim N(\\mu_X + \\mu_Y, \\sigma_X + \\sigma_Y)$\\\\\n\nIf $U = X - Y$, then $U \\sim N(\\mu_X - \\mu_Y,\\sigma_X + \\sigma_Y)$\\\\\n\nSymmetry:\\\\\n\nIf $X \\sim\\ N(0,\\sigma^2),$ then $-X \\sim N(0,\\sigma^2)$\\\\\n\n$\\mathbb{P}(|X|>x) = 2\\mathbb{P}(X>x)$\\\\\n\nStandardization:\\\\\n\n$Z= \\frac{X-\\mu}{\\sigma} \\sim N(0,1)$\\\\\n\n$\\mathbf{P}\\left(X\\leq t\\right) = \\displaystyle \\mathbf{P}\\left(Z\\leq \\frac{t-\\mu}{\\sigma}\\right)$\n\nHigher moments:\\\\\n\n$\\mathbb{E}[X^2] = \\mu^2 + \\sigma^2$\\\\\n$\\mathbb{E}[X^3] = \\mu^3 + 3\\mu\\sigma^2$\\\\\n$\\mathbb{E}[X^4] = \\mu^4 + 6\\mu^2\\sigma^2 +3\\sigma^4$\\\\\n\nQuantiles:\\\\\n\n\\subsection*{Uniform}\n\n\n\\subsection*{Cauchy}\ncontinuous, parameter $m$,\n\n$f_ m(x) = \\frac{1}{\\pi } \\frac{1}{1 + (x - m)^2}$\\\\\n\n$\\mathbb{E}[X]=not defined!$\\\\\n$Var(X)=not defined!$\\\\\n\n$\\text {med}(X) = P(X > M) = P(X < M)\\\\ = 1/2 = \\displaystyle \\int _{1/2}^{\\infty } \\frac{1}{\\pi } \\cdot \\frac{1}{1 + (x-m)^2} \\,  dx$\n\n\\subsection*{Chi squared}\nThe $\\chi _ d^2$ distribution with $d$ degrees of freedom is given by the distribution of $Z_1^2 + Z_2^2 + \\cdots + Z_ d^2,$ where $Z_1, \\ldots , Z_ d \\stackrel{iid}{\\sim } \\mathcal{N}(0,1)$\n\nIf $V \\sim \\chi^2_k:$\\\\\n\n$\\mathbb{E}= \\mathbb{E}[Z_1^2] + \\mathbb{E}[Z_2^2] + \\ldots + \\mathbb{E}[Z_d^2] = d$\\\\ \n\n$Var(V) = Var(Z_1^2) + Var(Z_2^2) + \\ldots + Var(Z_d^2) = 2d$\n\n\\subsection*{Student's T Distribution}\n\n$T_ n := \\frac{Z}{\\sqrt{V/n}}$ where $Z \\sim \\mathcal{N}(0,1)$, and $Z$ and $V$ are independent\n\n\n\n\n\n\\subsection*{Poisson}\nParameter $\\lambda$. discrete, approximates the binomial PMF when $n$ is large, $p$ is small, and $\\lambda = np$.\\\\\n\n\nCanonical exponential form:\\\\\n\n$ f_{\\theta}(y) = \\exp\\big(y\\theta - \\underbrace{e^\\theta}_{b(\\theta)} \\underbrace{- \\ln y!}_{c(y, \\phi)}\\big)$\\\\\n$\\theta = \\ln \\lambda$\\\\\n$\\phi = 1$\\\\\n\n\nPoisson process:\\\\\nk arrivals in t slots\n$\\mathbf{p_x}(k,t) = \\mathbb{P}(N_t=k)=e^{-\\lambda t} \\frac{(\\lambda t)^k}{k!}$\\\\\n\n$\\mathbb{E}[N_t]=\\lambda t$\\\\\n\n$Var(N_t)=\\lambda t$\n\n\\subsection*{Exponential}\n$\\mathbb{E}[X^2]=\\frac{2}{\\lambda^2}$\nCanonical exponential form:\\\\\n$f_{\\theta}(y) = \\exp\\big(y\\theta - \\underbrace{(-\\ln(-\\theta))}_{b(\\theta)} + \\underbrace{0}_{c(y, \\phi)}\\big)$\\\\\n$\\theta = -\\lambda = -\\frac1{\\mu}$\\\\\n$\\phi = 1$\n\n\n\n\\subsection{Bern}\nCanonical exponential form:\\\\\n$f_{\\theta}(y)=\\exp\\big(y\\theta - \\underbrace{\\ln(1 + e^\\theta)}_{b(\\theta)} + \\underbrace{0}_{c(y, \\phi)}\\big) \\quad$\\\\\n$\\theta = \\ln\\left(\\frac{p}{1-p}\\right)$\\\\\n$\\phi = 1$\\\\\n\n\\subsection*{Binomial}\nCanonical exponential form:\\\\\n$f_ p(y) =\\\\  \nexp (y \\underbrace{(\\ln (p)-\\ln (1-p))}_{\\theta } + \\underbrace{n\\ln (1-p)}_{-b(\\theta )} +\\underbrace{\\ln(\\binom {n}{y})}_{c(y,\\phi )} )$\n\n\n\n\\subsection*{Pascal}\n\nThe negative binomial or Pascal distribution is a generalization of the geometric distribution. It relates to the random experiment of repeated independent trials until observing $m$ successes. I.e. the time of the kth arrival.\n\n$Y_k=T_1+...T_k$\\\\\n\n$T_i \\sim iid Geometric(p)$\\\\\n\n$\\mathbb{E}[Y_k]=\\frac{k}{p}$\\\\\n\n$Var(Y_k)= \\frac{k(1-p}{p^2}$\n\n$p_{Y_k}(t) ={\\binom{t-1}{ k-1}}p^k(1-p)^{t-k}$, $t=k,k+1,...$\n\n\n\\subsection*{Shifted Exponential}\n\n", "meta": {"hexsha": "f01a43bed5031dba9b966c5b7f9a340d85ce6f42", "size": 8521, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/probability_distribution_table.tex", "max_stars_repo_name": "kpsunkara/MITx_capstone_1", "max_stars_repo_head_hexsha": "ee5ef547e144011edd1bd4f03def0a24a31f69bf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "content/probability_distribution_table.tex", "max_issues_repo_name": "kpsunkara/MITx_capstone_1", "max_issues_repo_head_hexsha": "ee5ef547e144011edd1bd4f03def0a24a31f69bf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content/probability_distribution_table.tex", "max_forks_repo_name": "kpsunkara/MITx_capstone_1", "max_forks_repo_head_hexsha": "ee5ef547e144011edd1bd4f03def0a24a31f69bf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-20T06:07:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-20T06:07:28.000Z", "avg_line_length": 21.5721518987, "max_line_length": 227, "alphanum_fraction": 0.5309236005, "num_tokens": 3767, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002491, "lm_q2_score": 0.8933093989533708, "lm_q1q2_score": 0.8255445700201972}}
{"text": "\n\\subsection{Introduction}\n\nThe outcome of a Bernoulli trial is either \\(0\\) or \\(1\\). We can describe it as:\n\n\\(P(1)=p\\)\n\n\\(P(0)=1-p\\)\n\nWith a single parameter \\(p\\).\n\n\\subsection{Moments of the Bernoulli distribution}\n\nThe mean of a Bernoulli trial is \\(E[X]=(1-p)(0)+(p)(1)=p\\).\n\nThe variance of a Bernoulli trial is \\(E[(X-\\mu)^2]=(1-p)(0-\\mu)^2+(p)(1-\\mu)^2=(1-p)p^2+p(1-p)^2]=p(1-p)\\).\n\n", "meta": {"hexsha": "00c78bd750f2ea271bd3764877fd8dd708d3689a", "size": 393, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/distributions/01-01-bernoulli.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/distributions/01-01-bernoulli.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/distributions/01-01-bernoulli.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.8333333333, "max_line_length": 108, "alphanum_fraction": 0.6106870229, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897509188344, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.8255211698392855}}
{"text": "\\section{Linear Support Vector Classifier} \\label{section:svc}\n\nGiven $n$ training points, where each input $x_i$ has $m$ attributes, i.e., is of dimensionality $m$, and is in one of two classes $y_i=\\pm1$, i.e., our training data is of the form:\n\n\\begin{equation}\n\t\\{(x_i,y_i), x_i\\in\\Re^m, y_i=\\pm1, i=1, \\dots, n\\} \\label{eq:svc_data}\n\\end{equation}\n\nFor simplicity we first assume that data are (not fully) linearly separable in the input space $x$, meaning that we can draw a line separating the two classes when $m=2$, a plane for $m=3$ and, more in general, a hyperplane for an arbitrary $m$.\n\nSupport vectors are the examples closest to the separating hyperplane and the aim of support vector machines is to orientate this hyperplane in such a way as to be as far as possible from the closest members of both classes, i.e., we need to maximize this margin.\n\nThis hyperplane is represented by the equation $w^T x + b=0$. So, we need to find $w$ and $b$ so that our training data can be described by:\n\n\\begin{equation} \\label{eq:svc_consts}\n\t\\begin{aligned}\n\t\t& w^T x_i + b \\geq +1 - \\xi_i, \\forall y_i=+1 \\\\\n    \t& w^T x_i + b \\leq -1 + \\xi_i, \\forall y_i=-1 \\\\\n    \t& \\xi_i \\geq 0 \\ \\forall_i\n\t\\end{aligned}\n\\end{equation}\n\nwhere the positive slack variables $\\xi_i$ are introduced to allow misclassified points. In this way data points on the incorrect side of the margin boundary will have a penalty that increases with the distance from it.\n\nThese two equations can be combined into:\n\n\\begin{equation} \\label{eq:svc_const}\n\t\\begin{aligned}\n    \t& y_i (w^T x_i + b) \\geq 1 - \\xi_i \\ \\forall_i \\\\\n    \t& \\xi_i\\geq 0 \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\nThe margin is equal to $\\displaystyle \\frac{1}{\\| w \\|}$ and maximizing it subject to the constraint in~\\eqref{eq:svc_const} while as we are trying to reduce the number of misclassifications is equivalent to finding:\n\n\\begin{equation} \\label{eq:svc_obj}\n    \\begin{aligned}\n        \\min_{w,b,\\xi} \\quad & \\| w \\| + C \\sum_{i=1}^n \\xi_i \\\\\n            \\text{subject to} \\quad & y_i (w^T x_i + b) \\geq 1 - \\xi_i \\ \\forall_i \\\\ & \\xi_i \\geq 0 \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\nMinimizing $\\| w \\|$ is equivalent to minimizing $\\displaystyle \\frac{1}{2} \\| w \\|^2$, but in this form we will deal with a 1-strongly convex regularization term that has more desirable convergence properties. So we need to find:\n\n\\begin{equation} \\label{eq:quad_svc_obj}\n    \\begin{aligned}\n        \\min_{w,b,\\xi} \\quad & \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\xi_i \\\\\n            \\text{subject to} \\quad & y_i (w^T x_i + b) \\geq 1 - \\xi_i \\ \\forall_i \\\\ & \\xi_i \\geq 0 \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\nwhere the parameter $C$ controls the trade-off between the slack variable penalty and the size of the margin.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[scale=0.6]{img/linear_dual_l1_svc_hyperplane}\n\t\\caption{Linear SVC hyperplane}\n\t\\label{fig:linear_dual_l1_svc_hyperplane}\n\\end{figure}\n\n\\pagebreak\n\n\\subsection{Hinge loss}\n\nThe \\emph{hinge} loss is defined as:\n\n\\begin{equation} \\label{eq:hinge_loss1}\n\t\\mathcal{L}_1 = \\max(0, 1 - y (w^T x + b))\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation} \\label{eq:hinge_loss2}\n\t\\mathcal{L}_1 = \n\t\\begin{cases}\n\t\t0 & \\text{if} \\ y (w^T x + b) \\geq 1 \\\\\n\t\t1 - y (w^T x + b) & \\text{otherwise} \\\\\n\t\\end{cases}\n\\end{equation}\n\nand it is a nondifferentiable convex function due to its nonsmoothness in 1, but has a subgradient that is given by:\n\n\\begin{equation} \\label{eq:hinge_loss_der}\n    \\partial_w \\mathcal{L}_1=\n        \\begin{cases}\n            -y x & \\text{if} \\ y (w^T x + b) < 1 \\\\\n            0 & \\text{otherwise} \\\\ \n        \\end{cases}\n\\end{equation}\n\n\\subsubsection{Primal formulation}\n\nThe general primal unconstrained formulation takes the form:\n\n\\begin{equation} \\label{eq:primal_svm}\n    \\min_{w,b} \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\mathcal{L}(w,b;x_i,y_i)\n\\end{equation}\n\nwhere $\\displaystyle \\frac{1}{2} \\| w \\|^2$ is the \\emph{regularization term} and $\\mathcal{L}(w,b;x_i,y_i)$ is the \\emph{loss function} associated with the observation $(x_i,y_i)$~\\cite{piccialli2018nonlinear}.\n\nThe quadratic optimization problem~\\eqref{eq:quad_svc_obj} can be equivalently formulated as:\n\n\\begin{equation} \\label{eq:primal_l1_svc}\n    \\min_{w,b} \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\max(0, 1 - y_i (w^T x_i + b))\n\\end{equation}\n\nwhere we make use of the \\emph{hinge} loss~\\eqref{eq:hinge_loss1} or~\\eqref{eq:hinge_loss2}.\n\nThe above formulation penalizes slacks $\\xi$ linearly and is called $\\mathcal{L}_1$-SVC.\n\n\\begin{figure}[h!]\n\t\\centering\n  \t\\includegraphics[scale=0.4]{img/l1_svc_loss}\n  \t\\caption{Hinge loss with different optimization steps}\n  \t\\label{fig:l1_svc_loss}\n\\end{figure}\n\nTo simplify the notation and so also the design of the algorithms, the simplest approach to learn the bias term $b$ is that of including that into the \\emph{regularization term}; so we can rewrite~\\eqref{eq:primal_svm} as follows:\n\n\\begin{equation} \\label{eq:reg_bias_primal_svm1}\n    \\min_{w,b} \\frac{1}{2} (\\| w \\|^2 + b^2) + C \\sum_{i=1}^n \\mathcal{L}(w,b;x_i,y_i)\n\\end{equation}\n\nor, equivalently, by augmenting the weight vector $w$ with the bias term $b$ and each instance $x_i$ with an additional dimension, i.e., with constant value equal to 1:\n\n\\begin{equation} \\label{eq:reg_bias_primal_svm2}\n    \\begin{aligned}\n        \\min_{w} \\quad & \\frac{1}{2} \\| \\hat{w} \\|^2 + C \\sum_{i=1}^n \\mathcal{L}(\\hat{w};\\hat{x}_i,y_i) \\\\\n            \\text{where} \\quad & \\hat{w}^T = [w^T, b] \\\\ & \\hat{x}_i^T = [x_i^T, 1]\n    \\end{aligned}\n\\end{equation}\n\nwith the advantages of having convex properties of the objective function useful for convergence analysis and the possibility to directly apply algorithms designed for models without the bias term.\n\nIn the specific case of the $\\mathcal{L}_1$-SVC the objective~\\eqref{eq:primal_l1_svc} become:\n\n\\begin{equation} \\label{eq:reg_bias_primal_l1_svc}\n    \\min_{w,b} \\frac{1}{2} (\\| w \\|^2 + b^2) + C \\sum_{i=1}^n \\max(0, 1 - y_i (w^T x_i + b))\n\\end{equation}\n\nNote that in terms of numerical optimization the formulation~\\eqref{eq:primal_l1_svc} is not equivalent to~\\eqref{eq:reg_bias_primal_l1_svc} since in the first one the bias term $b$ does not contribute to the \\emph{regularization term}, so the SVM formulation is based on an unregularized bias term $b$, as highlighted by the \\emph{statistical learning theory}. But, in machine learning sense, numerical experiments in~\\cite{hsu2002simple} show that the accuracy does not vary much when the bias term $b$ is embedded into the weight vector $w$.\n\n\\subsubsection{Wolfe dual formulation}\n\nTo reformulate the~\\eqref{eq:quad_svc_obj} as a \\emph{Wolfe dual}, we need to allocate the Lagrange multipliers $\\alpha_i, \\mu_i \\geq 0 \\ \\forall_i$:\n\n\\begin{equation} \\label{eq:svc_wolfe_dual}\n    \\max_{\\alpha,\\mu} \\min_{w,b,\\xi} \\mathcal{W}(w,b,\\xi,\\alpha,\\mu) = \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\xi_i-\\sum_{i=1}^n \\alpha_i(y_i(w^T x_i + b)-1+\\xi_i)-\\sum_{i=1}^n\\mu_i\\xi_i\n\\end{equation}\n\nWe wish to find the $w$, $b$ and $\\xi_i$ which minimizes, and the $\\alpha$ and $\\mu$ which maximizes $\\mathcal{W}$, provided $\\alpha_i\\geq 0, \\mu_i \\geq 0 \\ \\forall_i$. We can do this by differentiating $\\mathcal{W}$ wrt $w$ and $b$ and setting the derivatives to 0:\n\n\\begin{equation} \\label{eq:svc_wolfe_der_w}\n\t\\frac{\\partial \\mathcal{W}}{\\partial w}=w-\\sum_{i=1}^n \\alpha_i y_i x_i \\Rightarrow w=\\sum_{i=1}^n \\alpha_i y_i x_i\n\\end{equation}\n\n\\begin{equation} \\label{eq:svc_wolfe_der_b}\n\t\\frac{\\partial \\mathcal{W}}{\\partial b}=-\\sum_{i=1}^n \\alpha_i y_i\\Rightarrow\\sum_{i=1}^n \\alpha_i y_i=0\n\\end{equation}\n\n\\begin{equation} \\label{eq:svc_wolfe_der_xi}\n\t\\frac{\\partial \\mathcal{W}}{\\partial\\xi_i}=0\\Rightarrow C=\\alpha_i+\\mu_i\n\\end{equation}\n\nSubstituting~\\eqref{eq:svc_wolfe_der_w} and~\\eqref{eq:svc_wolfe_der_b} into~\\eqref{eq:svc_wolfe_dual} together with $\\mu_i\\geq 0 \\ \\forall_i$, which implies that $\\alpha\\leq C$, gives a new formulation being dependent on $\\alpha$. We therefore need to find:\n\n\\begin{equation} \\label{eq:svc_max_wolfe_dual}\n\t\\begin{aligned}\n    \t\\max_{\\alpha} \\mathcal{W}(\\alpha) &= \\sum_{i=1}^n \\alpha_i - \\frac{1}{2}\\sum_{i,j}\\alpha_i\\alpha_j y_i y_j \\langle x_i, x_j \\rangle \\\\\n    \t&= \\sum_{i=1}^n \\alpha_i - \\frac{1}{2}\\sum_{i,j}\\alpha_i Q_{ij}\\alpha_j \\ \\text{where} \\ Q_{ij} = y_i y_j \\langle x_i, x_j \\rangle \\\\\n    \t&= \\sum_{i=1}^n \\alpha_i - \\frac{1}{2}\\alpha^T Q\\alpha \\ \\text{subject to} \\ 0\\leq\\alpha_i\\leq C \\ \\forall_i, \\sum_{i=1}^n \\alpha_i y_i=0 \n\t\\end{aligned}\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation} \\label{eq:svc_min_wolfe_dual}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2}\\alpha^T Q\\alpha+q^T\\alpha \\\\\n            \\text{subject to} \\quad & 0\\leq\\alpha_i\\leq C \\ \\forall_i \\\\ & y^T\\alpha=0\n    \\end{aligned}\n\\end{equation}\n\nwhere $q^T = [1, \\dots, 1]$.\n\nBy solving~\\eqref{eq:svc_min_wolfe_dual} we will know $\\alpha$ and, from~\\eqref{eq:svc_wolfe_der_w}, we will get $w$, so we need to calculate $b$.\n\nWe know that any data point satisfying~\\eqref{eq:svc_wolfe_der_b} which is a support vector $x_s$ will have the form:\n\n\\begin{equation} \\label{eq:svc_sv_const1}\n\ty_s(w^T x_s + b)=1\n\\end{equation}\n\nand, by substituting in~\\eqref{eq:svc_wolfe_der_w}, we get:\n\n\\begin{equation} \\label{eq:svc_sv_const2}\n\ty_s\\big(\\sum_{m\\in S}\\alpha_m y_m \\langle x_m, x_s \\rangle +b\\big)=1\n\\end{equation}\n\nwhere $s$ denotes the set of indices of the support vectors and is determined by finding the indices $i$ where $\\alpha_i>0$, i.e., nonzero Lagrange multipliers.\n\nMultiplying through by $y_s$ and then using $y_s^2=1$ from~\\eqref{eq:svc_consts}:\n\n\\begin{equation} \\label{eq:svc_sv_squared_const2}\n\ty_s^2\\big(\\sum_{m\\in S}\\alpha_m y_m \\langle x_m, x_s \\rangle +b\\big)=y_s\n\\end{equation}\n\n\\begin{equation} \\label{eq:svc_b}\n\tb=y_s-\\sum_{m\\in S}\\alpha_m y_m \\langle x_m, x_s \\rangle\n\\end{equation}\n\nInstead of using an arbitrary support vector $x_s$, it is better to take an average over all of the support vectors in $S$:\n\n\\begin{equation} \\label{eq:svc_b_avg}\n\tb=\\frac{1}{N_s}\\sum_{s\\in S} y_s-\\sum_{m\\in S}\\alpha_m y_m \\langle x_m, x_s \\rangle\n\\end{equation}\n\nWe now have the variables $w$ and $b$ that define our separating hyperplane's optimal orientation and hence our support vector machine. Each new point $x'$ is classified by evaluating:\n\n\\begin{equation} \\label{eq:svc_pred}\n    y'=\\operatorname{sign}\\big(\\sum_{i=1}^n\\alpha_i y_i\\langle x_i, x' \\rangle+b\\big)\n\\end{equation}\n\nFrom~\\eqref{eq:svc_min_wolfe_dual} we can notice that the equality constraint $y^T \\alpha = 0$ arises form the stationarity condition $\\partial_{{b}} \\mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. We report below the box-constrained dual formulation~\\cite{hsu2002simple} that arises from the primal~\\eqref{eq:reg_bias_primal_svm1} or~\\eqref{eq:reg_bias_primal_svm2} where the bias term $b$ is embedded into the weight vector $w$:\n\n\\begin{equation} \\label{eq:svc_min_bcqp_wolf_dual}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T (Q + yy^T)\\alpha+q^T\\alpha \\\\\n            \\text{subject to} \\quad & 0\\leq\\alpha_i\\leq C \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\n\\subsubsection{Lagrangian dual formulation}\n\nIn order to relax the constraints in the \\emph{Wolfe dual} formulation~\\eqref{eq:svc_min_wolfe_dual} we define the problem as a \\emph{Lagrangian dual} relaxation by embedding them into objective function, so we need to allocate the Lagrange multipliers $\\mu$ and $\\lambda_+, \\lambda_- \\geq 0$:\n\n\\begin{equation} \\label{eq:l1_svc_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda_+,\\lambda_-} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\mu,\\lambda_+,\\lambda_-) &= \\frac{1}{2} \\alpha^T Q\\alpha+q^T\\alpha + \\mu^T (y^T \\alpha) + \\lambda_+^T (ub - \\alpha) - \\lambda_-^T \\alpha \\\\\n    &= \\frac{1}{2} \\alpha^T Q\\alpha + (q + \\mu y^T + \\lambda_+ - \\lambda_-)^T \\alpha + \\lambda_+^T ub \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda_+, \\lambda_- \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nwhere the upper bound $ub^T = [C, \\dots, C]$.\n\nTaking the derivative of the Lagrangian $\\mathcal{L}$ wrt $\\alpha$ and settings it to 0 gives:\n\n\\begin{equation} \\label{eq:svc_lagrangian_der_a}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\alpha}=0\\Rightarrow Q \\alpha + (q + \\mu y^T + \\lambda_+ - \\lambda_-) = 0\n\\end{equation}\n\nWith $\\alpha$ optimal solution of the linear system:\n\n\\begin{equation} \\label{eq:l1_svc_lagrangian_sol}\n    Q \\alpha = - (q + \\mu y^T + \\lambda_+ - \\lambda_-)\n\\end{equation}\n\nthe gradients wrt $\\mu$, $\\lambda_+$ and $\\lambda_-$ are:\n\n\\begin{equation} \\label{eq:svc_lagrangian_der_mu}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\mu}=-y \\alpha\n\\end{equation}\n\n\\begin{equation} \\label{eq:svc_lagrangian_der_lp}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\lambda_+}=\\alpha - ub\n\\end{equation}\n\n\\begin{equation} \\label{eq:svc_lagrangian_der_lm}\n    \\frac{\\partial \\mathcal{L}}{\\partial \\lambda_-}=-\\alpha\n\\end{equation}\n\nFrom~\\eqref{eq:svc_min_wolfe_dual} we can notice that the equality constraint $y^T \\alpha = 0$ arises form the stationarity condition $\\partial_{{b}} \\mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. In this way the dimensionality of~\\eqref{eq:l1_svc_lagrangian_dual} is reduced by removing the multipliers $\\mu$ which was allocated to control the equality constraint $y^T \\alpha=0$, so we will end up solving exactly the problem~\\eqref{eq:svc_min_bcqp_wolf_dual}.\n\n\\begin{equation} \\label{eq:l1_svc_bcqp_lagrangian_dual}\n\t\\begin{aligned}\n    \t\\max_{\\lambda_+,\\lambda_-} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\lambda_+,\\lambda_-) &= \\frac{1}{2} \\alpha^T (Q + yy^T)\\alpha+q^T\\alpha + \\lambda_+^T (ub - \\alpha) - \\lambda_-^T \\alpha \\\\\n    &= \\frac{1}{2} \\alpha^T (Q + yy^T)\\alpha + (q + \\lambda_+ - \\lambda_-)^T \\alpha + \\lambda_+^T ub \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda_+, \\lambda_- \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nwhere, again, the upper bound $ub^T = [C, \\dots, C]$.\n\nNow, taking the derivative of the Lagrangian $\\mathcal{L}$ wrt $\\alpha$ and settings it to 0 gives:\n\n\\begin{equation} \\label{eq:l1_svc_bcqp_lagrangian_der_a}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\alpha}=0\\Rightarrow (Q + yy^T) \\alpha + (q + \\lambda_+ - \\lambda_-) = 0\n\\end{equation}\n\nWith $\\alpha$ optimal solution of the linear system:\n\n\\begin{equation} \\label{eq:l1_svc_bcqp_lagrangian_sol}\n    (Q + yy^T) \\alpha = - (q + \\lambda_+ - \\lambda_-)\n\\end{equation}\n\nthe gradients wrt $\\lambda_+$ and $\\lambda_-$ are:\n\n\\begin{equation} \\label{eq:l1_svc_bcqp_lagrangian_der_lp}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\lambda_+}=\\alpha - ub\n\\end{equation}\n\n\\begin{equation} \\label{eq:l1_svc_bcqp_lagrangian_der_lm}\n    \\frac{\\partial \\mathcal{L}}{\\partial \\lambda_-}=-\\alpha\n\\end{equation}\n\n\\bigskip\n\nNote that since the Hessian matrix $Q$ of the $\\mathcal{L}_1$-SVC is not strictly positive definite, i.e., the Lagrangian function is not strictly convex since it will be linear along the eigenvectors correspondent to the null eigenvalues and so it will be unbounded below, the Lagrangian dual relaxation, i.e.,~\\ref{eq:l1_svc_lagrangian_sol} and~\\ref{eq:l1_svc_bcqp_lagrangian_sol}, will be nondifferentiable, so it will have infinite solutions and for each of them it will have a different subgradient. In order to compute an approximation of the gradient, we will choose $\\alpha$ in such a way as the one that minimizes the 2-norm since it is good almost like the gradient:\n\n\\begin{equation} \\label{eq:svc_lagrangian_krylov_sol}\n\t\\min_{\\alpha_n \\in K_n(Q, b)} \\| Q \\alpha_n - b \\|\n\\end{equation}\n\nSince we are dealing with a symmetric system we will choose a well-known Krylov method that performs the Lanczos iterate, i.e., symmetric Arnoldi iterate, called \\emph{minres}, i.e., symmetric \\emph{gmres}, to compute the vector $\\alpha_n$ that minimizes the norm of the residual $r_n = Q \\alpha_n - b$ among all vectors in $K_n(Q, b) = span(b, Qb, Q^2b, \\dots, Q^{n-1}b)$.\n\n\\bigskip\n\nSince the linear algebra methods in the ML context are crucial and also in order to deal with a per-iteration cost equals to the other algorithms described later to provide a coherent comparison of all at the end, we will solve it with a primal-dual optimization method and we modify its definition by adding a strictly convex augmentation term, i.e., a penalty term, in order to improve the actual convergence of the algorithms. So, if we consider a general quadratic optimization problem subject to linear constraints, i.e., equality and inequality constraints, defined as:\n\n\\begin{equation}\n    \\begin{aligned} \n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T Q \\alpha + q^T \\alpha \\\\\n            \\textrm{subject to} \\quad & A \\alpha = b \\\\ & G \\alpha \\leq h \\\\ & lb \\leq \\alpha \\leq ub\n    \\end{aligned}\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T Q \\alpha + q^T \\alpha \\\\\n            \\textrm{subject to} \\quad & A \\alpha = b \\\\ & \\hat{G} \\alpha \\leq \\hat{h}\n    \\end{aligned}\n\\end{equation}\n\nwhere $\\hat{G} =\n\\begin{bmatrix}\n G \\\\\n-I \\\\\n I \n\\end{bmatrix}$ and $\\hat{h} =\n\\begin{bmatrix}\nh & -lb & ub\n\\end{bmatrix}$; we give the following \\emph{augmented Lagrangian dual}:\n\n\\begin{equation} \\label{eq:svc_gen_aug_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda} \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T Q \\alpha + q^T \\alpha + \\mu^T (A \\alpha - b) + \\lambda^T (\\hat{G} \\alpha - \\hat{h}) + \\frac{\\rho}{2} \\| A \\alpha - b \\|^2 + \\frac{\\rho}{2} \\| \\hat{G} \\alpha - \\hat{h} \\|^2 \\\\\n    \\text{subject to} \\quad & \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nwith $\\rho > 0$.\n\n\\bigskip\n\nAccording to this definition, we change the formulation~\\ref{eq:l1_svc_lagrangian_dual} as:\n\n\\begin{equation} \\label{eq:l1_svc_aug_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\mu,\\lambda) &= \\frac{1}{2} \\alpha^T Q\\alpha+q^T\\alpha + \\mu^T (y^T \\alpha) + \\lambda^T (\\hat{G} \\alpha - \\hat{h}) + \\frac{\\rho}{2} \\| y^T \\alpha \\|^2 + \\frac{\\rho}{2} \\| \\hat{G} \\alpha - \\hat{h} \\|^2 \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nand the formulation~\\ref{eq:l1_svc_bcqp_lagrangian_dual} as:\n\n\\begin{equation} \\label{eq:l1_svc_bcqp_aug_lagrangian_dual}\n\t\\begin{aligned}\n    \t\\max_{\\lambda} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\lambda) &= \\frac{1}{2} \\alpha^T (Q + yy^T) \\alpha + q^T \\alpha + \\lambda^T (\\hat{G} \\alpha - \\hat{h}) + \\frac{\\rho}{2} \\| \\hat{G} \\alpha - \\hat{h} \\|^2 \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nwhere $\\hat{G} =\n\\begin{bmatrix}\n-I \\\\\n I \n\\end{bmatrix}$ and $\\hat{h} =\n\\begin{bmatrix}\n-lb & ub\n\\end{bmatrix}$ with $lb^T = [0, \\dots, 0]$, $ub^T = [C, \\dots, C]$ and $\\rho > 0$.\n\n\\pagebreak\n\n\\subsection{Squared hinge loss}\n\nThe \\emph{squared hinge} loss is defined as:\n\n\\begin{equation} \\label{eq:squared_hinge_loss2}\n\t\\mathcal{L}_2 = \\max(0, 1 - y (w^T x + b))^2\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation} \\label{eq:squared_hinge_loss1}\n\t\\mathcal{L}_2 = \n\t\\begin{cases}\n\t\t0 & \\text{if} \\ y (w^T x + b) \\geq 1 \\\\\n\t\t(1 - y (w^T x + b))^2 & \\text{otherwise} \\\\\n\t\\end{cases}\n\\end{equation}\n\nIt is a strictly convex function and its gradient is given by:\n\n\\begin{equation} \\label{eq:squared_hinge_loss_der}\n    \\nabla_w \\mathcal{L}_2=\n        \\begin{cases}\n            - 2 \\max(0, 1 - y (w^T x + b)) y x & \\text{if} \\ y (w^T x + b) < 1 \\\\\n            0 & \\text{otherwise} \\\\ \n        \\end{cases}\n\\end{equation}\n\n\\subsubsection{Primal formulation}\n\nSince smoothed versions of objective functions may be preferred for optimization, we can reformulate~\\eqref{eq:primal_l1_svc} as:\n\n\\begin{equation} \\label{eq:primal_l2_svc}\n    \\min_{w,b} \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\max(0, 1 - y_i (w^T x_i + b))^2\n\\end{equation}\n\nwhere we make use of the \\emph{squared hinge} loss that quadratically penalized slacks $\\xi$ and is called $\\mathcal{L}_2$-SVC.\n\nThe $\\mathcal{L}_2$-SVC objective~\\eqref{eq:primal_l2_svc} can be rewritten in form~\\eqref{eq:reg_bias_primal_svm1} or~\\eqref{eq:reg_bias_primal_svm2} as:\n\n\\begin{equation} \\label{eq:reg_bias_primal_l2_svc}\n    \\min_{w,b} \\frac{1}{2} (\\| w \\|^2 + b^2) + C \\sum_{i=1}^n \\max(0, 1 - y_i (w^T x_i + b))^2\n\\end{equation}\n\n\\begin{figure}[h!]\n\t\\centering\n  \t\\includegraphics[scale=0.4]{img/l2_svc_loss}\n  \t\\caption{Squared hinge loss with different optimization steps}\n  \t\\label{fig:l2_svc_loss}\n\\end{figure}\n\n\\subsubsection{Wolfe dual formulation}\n\nAs done for the $\\mathcal{L}_1$-SVC we can derive the \\emph{Wolfe dual} formulation of the $\\mathcal{L}_2$-SVC by obtaining:\n\n\\begin{equation} \\label{eq:wolfe_dual_l2_svc}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2}\\alpha^T (Q + D)\\alpha+q^T\\alpha \\\\\n            \\text{subject to} \\quad & \\alpha_i\\geq 0 \\ \\forall_i \\\\ & y^T\\alpha=0\n    \\end{aligned}\n\\end{equation}\n\nor, alternatively, with the regularized bias term by obtaining:\n\n\\begin{equation} \\label{eq:reg_bias_wolfe_dual_l2_svc}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2}\\alpha^T (Q + yy^T + D) \\alpha + q^T \\alpha \\\\\n            \\text{subject to} \\quad & \\alpha_i \\geq 0 \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\nwhere the diagonal matrix $\\displaystyle D_{ii} = \\frac{1}{2C} \\ \\forall_i$.\n\n\\subsubsection{Lagrangian dual formulation}\n\nIn order to relax the constraints in the $\\mathcal{L}_2$-SVC \\emph{Wolfe dual} formulation~\\eqref{eq:wolfe_dual_l2_svc} we define the problem as a \\emph{Lagrangian dual} relaxation by embedding them into objective function, so we need to allocate the Lagrange multipliers $\\mu$ and $\\lambda \\geq 0$:\n\n\\begin{equation} \\label{eq:l2_svc_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\mu,\\lambda) &= \\frac{1}{2} \\alpha^T (Q+D)\\alpha+q^T\\alpha + \\mu^T (y^T \\alpha) - \\lambda^T \\alpha \\\\\n    &= \\frac{1}{2} \\alpha^T (Q+D)\\alpha + (q + \\mu y^T - \\lambda)^T \\alpha \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nTaking the derivative of the Lagrangian $\\mathcal{L}$ wrt $\\alpha$ and settings it to 0 gives:\n\n\\begin{equation} \\label{eq:l2_svc_lagrangian_der_a}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\alpha}=0\\Rightarrow (Q+D) \\alpha + (q + \\mu y^T - \\lambda) = 0\n\\end{equation}\n\nWith $\\alpha$ optimal solution of the linear system:\n\n\\begin{equation} \\label{eq:l2_svc_lagrangian_sol}\n    (Q+D) \\alpha = - (q + \\mu y^T - \\lambda)\n\\end{equation}\n\nthe gradients wrt $\\mu$ and $\\lambda$ are:\n\n\\begin{equation} \\label{eq:l2_svc_lagrangian_der_mu}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\mu}=-y \\alpha\n\\end{equation}\n\n\\begin{equation} \\label{eq:l2_svc_lagrangian_der_lambda}\n    \\frac{\\partial \\mathcal{L}}{\\partial \\lambda}=-\\alpha\n\\end{equation}\n\nFrom~\\eqref{eq:svc_min_wolfe_dual} we can notice that the equality constraint $y^T \\alpha = 0$ arises form the stationarity condition $\\partial_{{b}} \\mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. In this way the dimensionality of~\\eqref{eq:l2_svc_lagrangian_dual} is reduced by removing the multipliers $\\mu$ which was allocated to control the equality constraint $y^T \\alpha=0$, so we will end up solving exactly the problem~\\eqref{eq:reg_bias_wolfe_dual_l2_svc}.\n\n\\begin{equation} \\label{eq:l2_svc_lb_lagrangian_dual}\n\t\\begin{aligned}\n    \t\\max_{\\lambda} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\lambda) &= \\frac{1}{2} \\alpha^T (Q + yy^T + D) \\alpha+q^T\\alpha - \\lambda^T \\alpha \\\\\n    &= \\frac{1}{2} \\alpha^T (Q + yy^T + D) \\alpha + (q - \\lambda)^T \\alpha \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nNow, taking the derivative of the Lagrangian $\\mathcal{L}$ wrt $\\alpha$ and settings it to 0 gives:\n\n\\begin{equation} \\label{eq:l2_svc_lb_lagrangian_der_a}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\alpha}=0\\Rightarrow (Q + yy^T + D) \\alpha + (q - \\lambda) = 0\n\\end{equation}\n\nWith $\\alpha$ optimal solution of the linear system:\n\n\\begin{equation} \\label{eq:l2_svc_lb_lagrangian_sol}\n    (Q + yy^T + D) \\alpha = - (q - \\lambda)\n\\end{equation}\n\nthe gradient wrt $\\lambda$ is:\n\n\\begin{equation} \\label{eq:l2_svc_lb_lagrangian_der_l}\n    \\frac{\\partial \\mathcal{L}}{\\partial \\lambda}=-\\alpha\n\\end{equation}\n\n\\bigskip\n\nNote that since the Hessian matrix $Q$ of the $\\mathcal{L}_2$-SVC is symmetric and strictly positive definite, we can find the unique solution of the Lagrangian dual relaxation, i.e.,~\\ref{eq:l2_svc_lagrangian_sol} and~\\ref{eq:l2_svc_lb_lagrangian_sol}, by solving the system with the Cholesky factorization.\n\n\\bigskip\n\nSince the linear algebra methods in the ML context are crucial and also in order to deal with a per-iteration cost equals to the other algorithms described later to provide a coherent comparison of all at the end, we will solve it with a primal-dual optimization method and we modify its definition by adding a strictly convex augmentation term, i.e., a penalty term, in order to improve the actual convergence of the algorithms. So, if we consider a general quadratic optimization problem subject to linear constraints, i.e., equality and inequality constraints, defined as:\n\n\\begin{equation}\n    \\begin{aligned} \n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T Q \\alpha + q^T \\alpha \\\\\n            \\textrm{subject to} \\quad & A \\alpha = b \\\\ & G \\alpha \\leq h \\\\ & lb \\leq \\alpha \\leq ub\n    \\end{aligned}\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T Q \\alpha + q^T \\alpha \\\\\n            \\textrm{subject to} \\quad & A \\alpha = b \\\\ & \\hat{G} \\alpha \\leq \\hat{h}\n    \\end{aligned}\n\\end{equation}\n\nwhere $\\hat{G} =\n\\begin{bmatrix}\n G \\\\\n-I \\\\\n I \n\\end{bmatrix}$ and $\\hat{h} =\n\\begin{bmatrix}\nh & -lb & ub\n\\end{bmatrix}$; we give the following \\emph{augmented Lagrangian dual}:\n\n\\begin{equation} \\label{eq:l2_svc_gen_aug_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda} \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T Q \\alpha + q^T \\alpha + \\mu^T (A \\alpha - b) + \\lambda^T (\\hat{G} \\alpha - \\hat{h}) + \\frac{\\rho}{2} \\| A \\alpha - b \\|^2 + \\frac{\\rho}{2} \\| \\hat{G} \\alpha - \\hat{h} \\|^2 \\\\\n    \\text{subject to} \\quad & \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nwith $\\rho > 0$.\n\n\\bigskip\n\nAccording to this definition, we change the formulation~\\ref{eq:l2_svc_lagrangian_dual} as:\n\n\\begin{equation} \\label{eq:l2_svc_aug_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\mu,\\lambda) &= \\frac{1}{2} \\alpha^T (Q + D) \\alpha+q^T\\alpha + \\mu^T (y^T \\alpha) + \\lambda^T (\\hat{G} \\alpha - \\hat{h}) + \\frac{\\rho}{2} \\| y^T \\alpha \\|^2 + \\frac{\\rho}{2} \\| \\hat{G} \\alpha - \\hat{h} \\|^2 \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nand the formulation~\\ref{eq:l2_svc_lb_lagrangian_dual} as:\n\n\\begin{equation} \\label{eq:l2_svc_lb_aug_lagrangian_dual}\n\t\\begin{aligned}\n    \t\\max_{\\lambda} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\lambda) &= \\frac{1}{2} \\alpha^T (Q + yy^T + D) \\alpha + q^T \\alpha + \\lambda^T (\\hat{G} \\alpha - \\hat{h}) + \\frac{\\rho}{2} \\| \\hat{G} \\alpha - \\hat{h} \\|^2 \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nwhere $\\hat{G} =\n\\begin{bmatrix}\n-I\n\\end{bmatrix}$ and $\\hat{h} =\n\\begin{bmatrix}\n-lb\n\\end{bmatrix}$ with $lb^T = [0, \\dots, 0]$ and $\\rho > 0$.", "meta": {"hexsha": "1fefa38d7f32604d4693a06157412688120cddde", "size": 27377, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebooks/optimization/tex/linear_svc.tex", "max_stars_repo_name": "DonatoMeoli/NumericalOptimization", "max_stars_repo_head_hexsha": "e60144458026a6ddbe1612f92b838c342db572eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-22T09:17:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T18:23:56.000Z", "max_issues_repo_path": "notebooks/optimization/tex/linear_svc.tex", "max_issues_repo_name": "DonatoMeoli/NumericalOptimization", "max_issues_repo_head_hexsha": "e60144458026a6ddbe1612f92b838c342db572eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-25T08:29:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-25T09:03:13.000Z", "max_forks_repo_path": "notebooks/optimization/tex/linear_svc.tex", "max_forks_repo_name": "DonatoMeoli/NumericalOptimization", "max_forks_repo_head_hexsha": "e60144458026a6ddbe1612f92b838c342db572eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-10-10T13:38:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-13T20:23:37.000Z", "avg_line_length": 46.3231810491, "max_line_length": 676, "alphanum_fraction": 0.6838952405, "num_tokens": 9626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.9111797130267452, "lm_q1q2_score": 0.8255195445421241}}
{"text": "\\subsection{Introduction}\nIn this section, we will be dealing with differential equations of the form $P\\p{x, y} + Q\\p{x, y}y' = 0$, which we will write as $P\\p{x, y}\\,\\diff{x} + Q\\p{x, y}\\,\\diff{y} = 0$.\n\nOur goal is to find a real-valued function $F\\p{x, y}$ such that $F\\p{x, y} = C$ implicitly defines a solution to the differential equation. To illustrate this, consider the following example.\n\n\\textit{Example:} \\\\\nLet $P\\p{x, y} = x$, $Q\\p{x, y} = y$. We claim that the equation\n\\begin{equation}\n\tF\\p{x, y} = x^2 + y^2 = C\t\n\\end{equation}\nimplicitly defines a solution to the exact differential equation\n\\[\n\tx\\,\\diff{x} + y\\,\\diff{y} = 0.\n\\]\nTaking the derivative with respect to $x$ on both sides of (1) yields\n\\begin{align*}\n\t2x + 2y\\frac{\\diff{y}}{\\diff{x}} &= 0 \\\\\n\t2x\\,\\diff{x} + 2y\\,\\diff{y} &= 0 \\\\\n\tx\\,\\diff{x} + y\\,\\diff{y} &= 0\n\\end{align*}\nas we wanted to show.\n\nSo, $x^2 + y^2 = C$ are solutions to the problem, which are circles of radius $\\sqrt{C}$ centered at the origin.\n\n\\begin{definition}\n\tSuppose that the solutions for the differential equation $P\\p{x, y} + Q\\p{x, y}y' = 0$ are implicitly given by $F\\p{x, y} = C$. Then the set $\\left\\{\\p{x, y} \\in \\mathbb{R}^2 \\mid F\\p{x, y} = C \\right\\}$ are called the \\textbf{integral curves} of the differential equation.\t\n\\end{definition}\n\n", "meta": {"hexsha": "353bfe6c57d29a783541b32e6aa7c2b32d44d3ed", "size": 1308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/exact.tex", "max_stars_repo_name": "stevenktruong/differential-equations-intro", "max_stars_repo_head_hexsha": "d320cb4cecd6d611687e9a58abf999a7d6e067e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sections/exact.tex", "max_issues_repo_name": "stevenktruong/differential-equations-intro", "max_issues_repo_head_hexsha": "d320cb4cecd6d611687e9a58abf999a7d6e067e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/exact.tex", "max_forks_repo_name": "stevenktruong/differential-equations-intro", "max_forks_repo_head_hexsha": "d320cb4cecd6d611687e9a58abf999a7d6e067e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.1034482759, "max_line_length": 275, "alphanum_fraction": 0.6475535168, "num_tokens": 466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.9111797148356995, "lm_q1q2_score": 0.82551953924239}}
{"text": "\n\\subsection{Binomial expansion}\n\nHow can we expand\n\n\\((a+b)^n, n\\in \\mathbb{N}\\)\n\nWe know that:\n\n\\((a+b)^n=(a+b)(a+b)^{n-1}\\)\n\n\\((a+b)^n=a(a+b)^{n-1}+b(a+b)^{n-1}\\)\n\nEach time this is done, the terms split, and each terms is multiplied by either \\(a\\) or \\(b\\). That means at the end there are \\(n\\) total multiplications.\n\nThis can be shown as:\n\n\\((a+b)^n=\\sum_{i=1}^n a^i b^{n-i} c_i\\)\n\nSo we want to identify \\(c_i\\).\n\nEach term can be shown as a series of \\(n\\) \\(a\\)s and \\(b\\)s. For example:\n\n\\begin{itemize}\n\\item \\(aaba\\)\n\\item \\(baaa\\)\n\\end{itemize}\n\nFor any of these, there are \\(n!\\) ways or arranging the sequence, but this includes duplicates. If we were given \\(n\\) unique terms to multiply there would indeed by \\(n!\\) different ways this could have arisen, but we can swap \\(a\\)s and \\(b\\)s, as they were only generated once. So let's count duplicates.\n\nThere are duplicates in the \\(a\\)s. If there are  \\(i\\) \\(a\\)s, then there are \\(i!\\) ways of rearranging this. Similarly, if there are \\(n-i\\) \\(b\\)s, then there are \\((n-i)!\\) ways or arranging this.\n\nAs a result the number of actual observed instances, \\(c_i\\), is:\n\n\\(c_i=\\dfrac{n!}{i!(n-i)!}\\)\n\nAnd so:\n\n\\((a+b)^n=\\sum^n_{i=0} a^i b^{n-i} \\dfrac{n!}{i!(n-i)!}\\)\n\nWe can also write this last term as:\n\n\\(\\begin{pmatrix}n\\\\i\\end{pmatrix}\\)\n\n", "meta": {"hexsha": "8ecec528234063a80ed198a2ed344a0bcb849e8e", "size": 1315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/algebra/01-02-binomial.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/algebra/01-02-binomial.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/algebra/01-02-binomial.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2222222222, "max_line_length": 308, "alphanum_fraction": 0.6342205323, "num_tokens": 448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506726044381, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.8254351409050529}}
{"text": "% Project for Integration Workshop. Dept. Mathematics. UArizona\n% A little linearalgebra with non square matrices.\n\n\\section{The Fredholm Alternative \\& Least Squares Solutions}\nSometimes we focus too much on solving the matrix equation $A \\bm{x} = \\bm{b}$ for situations where $A$ is a square matrix,  and we ignore situations where $A$ is not square. In many practical applications,  $A$ is an $m \\times n$ matrix with $m \\neq n$. \nIn this project, you are going to explore what we mean by \\textit{solutions to the matrix equation for non-square matrices}.\n\n\\subsubsection*{The Fredholm Alternative}\nThe Fredholm alternative states that for the matrix equation $Ax=b$, exactly one of the following statements is true:\n\\begin{itemize}\n    \\item (Either) There exists an $x$ that solves the matrix equation $Ax=b$.\n    \\item (Or) There exists a $y$ that solves $A^\\top y = 0$ such that $y^\\top b \\neq 0$.\n\\end{itemize}\nLet $A_m$ be the $3 \\times m$ matrix (below), and let $b'$ and $b''$ be the $3 \\times 1$ vectors (below).\n\\begin{equation*}\nA_m = \\begin{bmatrix} 1 & 1 & 1 & \\cdots & 1\\\\ 1 & 1 & 1 & \\cdots & 1 \\\\ 1 & 2 & 3 &  \\cdots & m \\end{bmatrix}, \\quad  \\quad b' = \\begin{bmatrix} -1 \\\\ -1 \\\\ +1 \\end{bmatrix}, \\quad b'' = \\begin{bmatrix*}[r] -1 \\\\ 0 \\\\ +1 \\end{bmatrix*}\n % A_n = \\begin{bmatrix} 1 & 1 & 1 \\\\ 1 & 1 & 2 \\\\ \\vdots & \\vdots & \\vdots \\\\ 1 & 1 & n \\end{bmatrix}, \\quad  \\quad b_1 = \\begin{bmatrix} 0 & 0 & -1 \\end{bmatrix}, \\quad b_2 = \\begin{bmatrix} 1 \\\\ -1 \\\\ 0 \\end{bmatrix}\n\\end{equation*}\n\n\\begin{enumerate}[(a)]\n    \\item Plot the vectors that make the columns of $A_m$ for $m = 5$, and use your figure to describe the column space of $A_m$.\n    \\item Use pencil-and-paper to verify the Fredholm Alternative for $b'$ and for $b''$.\n    \\item Plot the vectors $b'$ and $b''$ on the same figure from part (a), and use your figure to provide an intuitive explanation for the Fredholm Alternative.\n\\end{enumerate}\n\n\n\\subsubsection*{Pseudo-inverses \\& Least Squares Solutions}\nWhen there is no solution to the matrix equation $Ax = b$, we may have to look for the `next best thing'. Your co-worker suggests the following matrix algebra to find the `next best thing'.\n\\begin{equation*}\nAx = b \\quad \\Rightarrow \\quad A^\\top A x = A^\\top b \\quad \\Rightarrow \\quad x = (A^\\top A)^{-1} A^\\top b\n\\end{equation*}\n\\begin{enumerate}[(a), resume]\n    \\item What are the dimensions of the matrix $(A^\\top A)$? What are requirements on $A$ for the matrix $(A^\\top A)$ to be invertable?\n    \\item For $m = 2$, find the matrix $A^\\dagger:=(A_m^\\top A_m) A_m^\\top$ and compute the vectors $x': = A^\\dagger b'$ and $x'':=A^\\dagger b''$.\n    \\item Does $Ax' = b'$? What about $Ax'' = b''$? Can you describe what we mean when we say that $A^\\dagger$ gives the `next best thing'?\n    \\item[($\\ast$)] \\textit{Bonus:} Use some calculus to verify your answer in part (f).\n\\end{enumerate}\n\n", "meta": {"hexsha": "86a9767b091adebc6c0d0a652621fb869e2bb96f", "size": 2891, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fredholm-alternative_least-squares.tex", "max_stars_repo_name": "colinlclark/integration_workshop", "max_stars_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fredholm-alternative_least-squares.tex", "max_issues_repo_name": "colinlclark/integration_workshop", "max_issues_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fredholm-alternative_least-squares.tex", "max_forks_repo_name": "colinlclark/integration_workshop", "max_forks_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-07-25T18:18:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-27T01:10:02.000Z", "avg_line_length": 74.1282051282, "max_line_length": 255, "alphanum_fraction": 0.6703562781, "num_tokens": 936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.9136765193002482, "lm_q1q2_score": 0.8253187114425099}}
{"text": "\\chapter{Math}\n\n\\section{Functions}\n\\rih{Equals.} Requirements for equals\n\\begin{enumerate}\n\\item Reflexive\n\\item Symmetric\n\\item Transitive\n\\item Non-null\n\\end{enumerate}\n\\rih{Compare.} Requirements for compares (total order):\n\\begin{enumerate}\n\\item Antisymmetry\n\\item Transitivity\n\\item Totality\n\\end{enumerate}\n\\section{Divisor}\n\\runinhead{gcd.} Greatest common divisor.\n\n\\begin{python}\ndef gcd(a, b):\n    while b:\n        a, b = b, a%b\n\n    return a\n\\end{python}\n\nProof. Euclidean Algorithm. Proove the following recursive form:\n$$\ngcd(a,b) = gcd(b, r)\n$$\n\\section{Prime Numbers}\n\\subsection{Sieve of Eratosthenes}\n\\subsubsection{Basics}\nTo find all the prime numbers less than or equal to a given integer n by Eratosthenes' method:\n\\begin{enumerate}\n\\item Create a   list of consecutive integers from 2 through n: (2, 3, 4, ..., n).\n\\item Initially, let $p$ equal 2, the first prime number.\n\\item Starting from $p$, enumerate its multiples by counting to n in increments of  $p$, and mark them in the list (these will be $2p$, $3p$, $4p$, ... ; the $p$ itself should not be marked).\n\\item Find the first number greater than $p$ in the list that is not marked. If there was no such number, stop. Otherwise, let $p$ now equal this new number (which is the next prime), and repeat from step 3.\n\\end{enumerate}\n\nWhen the algorithm terminates, the numbers remaining not marked in the list are all the primes below $n$.\n\n\\subsubsection{Refinements}\nThe main idea here is that every value for $p$ is prime, because we have already marked all the multiples of the numbers less than $p$. Note that some of the numbers being marked may have already been marked earlier (e.g., 15 will be marked both for 3 and 5).\n\nAs a refinement, it is sufficient to mark the numbers in step 3 starting from $p^2$, because all the smaller multiples of $p$ will have already been marked at that point by the previous smaller prime factor other than $p$. From $p^2$, $p$ becomes the smaller prime factor of a composite number. This means that the algorithm is allowed to terminate in step 4 when $p^2$ is greater than n.\n\nAnother refinement is to initialize list odd numbers only, (3, 5, ..., n), and count in increments of $2p$ in step 3, thus marking only odd multiples of $p$. This actually appears in the original algorithm. This can be generalized with wheel factorization, forming the initial list only from numbers coprime with the first few primes and not just from odds (i.e., numbers coprime with 2), and counting in the correspondingly adjusted increments so that only such multiples of $p$ are generated that are coprime with those small primes, in the first place.\n\nTo summarized, the refinements include:\n\\begin{enumerate}\n\\item Starting from $p^2$; thus $p$ is the smaller prime factor. \n\\item Preprocessing even numbers and then only process odd numbers; thus the increment becomes $2p$.\n\\end{enumerate}}\n\n\\subsubsection{code}\n\\begin{python}\ndef countPrimes(n):\n    \"\"\"\n    Find prime using Sieve's algorithm\n    :type n: int\n    :rtype: int\n    \"\"\"\n    if n < 3: return 0\n    is_prime = [False if i%2 == 0 else True \n                for i in xrange(n)]\n    is_prime[0], is_prime[1] = False, False\n    for i in xrange(3, int(math.sqrt(n))+1, 2):\n        if is_prime[i]:\n            for j in xrange(i*i, n, 2*i):\n                is_prime[j] = False\n\n    return is_prime.count(True)\n\\end{python}\n\n\\subsection{Factorization}\nBacktracking: Section-\\ref{factorization}.\n\n\\section{Median}\n\\subsection{Basic DualHeap}\nDualHeap to keep track the median when a method to find median is called multiple times.\n\nHere we use the negation of the value as a trick to convert min-heap to max-heap.\n\\begin{python}\nimport heapq\n\nclass DualHeap(object):\n  def __init__(self):\n    self.min_h = []\n    self.max_h = []  # need to negate the value \n\n  def insert(self, num):\n    if not self.min_h or num > self.min_h[0]:\n      heapq.heappush(self.min_h, num)\n    else:\n      heapq.heappush(self.max_h, -num)\n    self.balance()\n\n  def balance(self):\n    l1 = len(self.min_h)\n    l2 = len(self.max_h)\n    if l1-l2 > 1:\n      heapq.heappush(self.max_h, \n                     -heapq.heappop(self.min_h))\n      self.balance()\n    elif l2-l1 > 1:\n      heapq.heappush(self.min_h, \n                     -heapq.heappop(self.max_h))\n      self.balance()\n    return\n\n  def get_median(self):\n    \"\"\"Straightforward\"\"\"\n\\end{python}\n\n\\subsection{DualHeap with Lazy Deletion}\\label{dh_lazy_del}\nClues:\n\\begin{enumerate}\n\\item Wrap the value and wrap the heap\n\\item When delete a value, mark it with tombstone. \n\\item When negate the value, only change the value, not the reference. \n\\item When heap pop, clean the op first. \n\\end{enumerate}\n\\begin{python}\nimport heapq\nfrom collections import defaultdict\n\n\nclass Value(object):\n    def __init__(self, val):\n        self.val = val\n        self.deleted = False\n\n    def __neg__(self):\n        \"\"\"negate without creating new instance\"\"\"\n        self.val = -self.val\n        return self\n\n    def __cmp__(self, other):\n        assert isinstance(other, Value)\n        return self.val - other.val\n\n    def __repr__(self):\n        return repr(self.val)\n\n\nclass Heap(object):\n    def __init__(self):\n        self.h = []\n        self.len = 0\n\n    def push(self, item):\n        heapq.heappush(self.h, item)\n        self.len += 1\n\n    def pop(self):\n        self._clean_top()\n        self.len -= 1\n        return heapq.heappop(self.h)\n\n    def remove(self, item):\n        \"\"\"lazy delete\"\"\"\n        item.deleted = True\n        self.len -= 1\n\n    def __len__(self):\n        return self.len\n\n    def _clean_top(self):\n        while self.h and self.h[0].deleted:\n            heapq.heappop(self.h)\n\n    def peek(self):\n        self._clean_top()\n        return self.h[0]\n\n\nclass DualHeap(object):\n    def __init__(self):\n        self.min_h = Heap()  # represent right side\n        self.max_h = Heap()  # represent left side\n    # others similar as the previous section's above DualHeap\n\\end{python}\n\n\\section{Modular}\n\\subsection{Power of 4}\nTo check whether a number of the power of 4, we can check whether it mod 3 equals 1.\n\\begin{align*}\n4^a &\\equiv 1^a\\mod 3 \\\\\n&\\equiv 1 \\mod 3\n\\end{align*}\n\nAlternatively, we can use bit manipulation based on the power of 4 in the binary form of \\pyinline{repeat n 1 << 2}. \n\n\\section{Ord}\n\\runinhead{Number in lexical order.} Given an integer n, return 1 - n in lexicographical order. For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].\n\n\\begin{python}\ndef gen():\n    i = 1\n    for _ in xrange(n):\n        yield i\n        if i * 10 <= n:\n            i *= 10  # * 10\n        elif i % 10 != 9 and i + 1 <= n:\n            i += 1  # for current digit\n        else:\n            while i % 10 == 9 or i + 1 > n:\n                i /= 10\n            i += 1\n\\end{python}\n", "meta": {"hexsha": "218dd8387a9647799da1ee1c48486f7d5248d0ff", "size": 6805, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterMath.tex", "max_stars_repo_name": "algorhythms/Algo-Quicksheet", "max_stars_repo_head_hexsha": "c5d219a96f195adf1d19d2d701986e01fc9b8195", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 902, "max_stars_repo_stars_event_min_datetime": "2015-08-16T08:25:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T05:23:50.000Z", "max_issues_repo_path": "chapterMath.tex", "max_issues_repo_name": "andysli6590/Algo-Quicksheet", "max_issues_repo_head_hexsha": "c5d219a96f195adf1d19d2d701986e01fc9b8195", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2015-07-06T17:24:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-12T00:01:38.000Z", "max_forks_repo_path": "chapterMath.tex", "max_forks_repo_name": "andysli6590/Algo-Quicksheet", "max_forks_repo_head_hexsha": "c5d219a96f195adf1d19d2d701986e01fc9b8195", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 92, "max_forks_repo_forks_event_min_datetime": "2015-10-09T03:13:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-20T00:57:08.000Z", "avg_line_length": 31.7990654206, "max_line_length": 555, "alphanum_fraction": 0.6665686995, "num_tokens": 1860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904956, "lm_q2_score": 0.9136765222384493, "lm_q1q2_score": 0.8253186998248752}}
{"text": "\\section*{Things To Remember}\n$ln(x) \\leq x - 1, x>0$; $||x||_2 = \\sqrt{x^T x}$; $\\nabla_x ||x||_2^2 = 2 x$%; $||x||_p = (\\sum_{i=1}^n|x_i|^p)^{\\frac{1}{p}}$, $1 \\leq p < \\infty$\n\n$f(x) = x^T A x$; $\\nabla_x f(x) = (A + A^T) x$\n\n%$D_{KL} = \\mathbb{E}_p[log(\\frac{p(x)}{q(x)})]$; $D_{KL} (P||Q) = \\sum_{x \\in X}P(x) \\cdot log \\frac{P(x)}{Q(x)} =  \\int_{-\\infty}^{+\\infty} p(x) log \\frac{p(x)}{q(x)} \\, dx $ always nonneg\n\nStandard Gaussian: CDF: $\\Phi(x) = \\int_{-\\infty}^{x} \\phi(t) \\partial t$;\\\\ %CDF: cumulative distribution function; PDF: standard normal probability density function, $\\mu = 0$, $\\sigma = 1$\nPDF: $\\phi(x) = \\frac{1}{\\sqrt{2\\pi}} e^{-(1/2)x^2}$; $\\int \\phi(x) \\partial x = \\Phi(x) + c$;\\\\\n$\\int x \\phi(x) = -\\phi(x) + c$; $\\int x^2 \\phi(x) \\partial x = \\Phi(x) -x \\phi(x) + c$\n\n", "meta": {"hexsha": "db4d4202455baf8edef256dfcc240a373aa31fe5", "size": 799, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/Important.tex", "max_stars_repo_name": "meck93/intro_ml_ethz", "max_stars_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-04-24T14:58:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-19T14:02:08.000Z", "max_issues_repo_path": "source/Important.tex", "max_issues_repo_name": "meck93/intro_ml_ethz", "max_issues_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Important.tex", "max_forks_repo_name": "meck93/intro_ml_ethz", "max_forks_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.5833333333, "max_line_length": 191, "alphanum_fraction": 0.5193992491, "num_tokens": 377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104924150547, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.8252302386702955}}
{"text": "\\subsection{Useful to know}\n\n\\subsubsection{Min of iid exponential r.v}\nLet  $X_1$,...,$X_nn$  be i.i.d. $Exp(\\lambda)$ random variables.\n\nDistribution of $min_i(Xi)$ \n\n\\begin{align*}\n   \\mathbf{P}(\\min _ i (X_ i)\\leq t) &=\\\\\n&=1-\\mathbf{P}(\\min _ i (X_ i)\\geq t)\\\\\n&=1-(\\mathbf{P}(X_1\\geq t))(\\mathbf{P}(X_2\\geq t))\\ldots (\\mathbf{P}(X_ n\\geq t))\\\\\n&=1-(1-F_ X(t))^ n \\, =\\, 1-e^{-n\\lambda x}\n\\end{align*}\n\nDifferentiate w.r.t $x$ to get the pdf of $min_i(Xi)$:\n\n\\begin{align*}\nf_{\\text {min}}(x)= (n\\lambda ) e^{-(n\\lambda ) x}\n\\end{align*}\n\n\n\\subsubsection{Counting Committees}\n\nOut of  $2n$  people, we want to choose a committee of $n$ people, one of whom will be its chair. In how many different ways can this be done?\" \n\n$$n\\binom {2n}{n}=2n\\binom {2n-1}{n-1}.$$\n\n\u201cIn a group of  2n  people, consisting of  n  boys and  n  girls, we want to select a committee of  n  people. In how many ways can this be done?\"\n\n$$\\binom {2n}{n}=\\sum _{i=0}^ n \\binom {n}{i}\\binom {n}{n-i}$$\n\n\u201cHow many subsets does a set with  2n  elements have?\" \n\n$$2^{2n}=\\sum _{i=0}^{2n}\\binom {2n}{i}$$\n\n\u201cOut of  $n$  people, we want to form a committee consisting of a chair and other members. We allow the committee size to be any integer in the range $1$,$2$,...,$n$ . How many choices do we have in selecting a committee-chair combination?\"\n\n$$n2^{n-1}=\\sum _{i=0}^ n \\binom {n}{i}i.$$\n\n\\subsection{Finding Joint PDFS}\n\n$f_{X,Y}(x,y)=f_ X(x)f_{Y|X}(y\\mid x)$", "meta": {"hexsha": "9965b0eece0b2a21dec072a136d42fa3e2ddca92", "size": 1441, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/notes.tex", "max_stars_repo_name": "kpsunkara/MITx_capstone_1", "max_stars_repo_head_hexsha": "ee5ef547e144011edd1bd4f03def0a24a31f69bf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "content/notes.tex", "max_issues_repo_name": "kpsunkara/MITx_capstone_1", "max_issues_repo_head_hexsha": "ee5ef547e144011edd1bd4f03def0a24a31f69bf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content/notes.tex", "max_forks_repo_name": "kpsunkara/MITx_capstone_1", "max_forks_repo_head_hexsha": "ee5ef547e144011edd1bd4f03def0a24a31f69bf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-20T06:07:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-20T06:07:28.000Z", "avg_line_length": 34.3095238095, "max_line_length": 240, "alphanum_fraction": 0.6294240111, "num_tokens": 568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.8251895073861275}}
{"text": "\\textbf{Consider the wave propagation PDE solved in HW 3,}\n\\begin{align*}\nu_t&=p_x,\\\\\np_t&=u_x,\\quad x\\in(0,\\pi),t>0,\n\\end{align*}\n\\textbf{with boundary conditions $u(t,0)=u(t,\\pi)=0$ and initial conditions $u(0,x)=e^{-30(x-\\pi/2)^2}$ and $p(0,x)=0$.}\n\\vskip.00005in\n\\noindent\\rule{\\textwidth}{1pt}\n\\vspace{0.1in}\n\\begin{enumerate}\n\\item[a)] \\textbf{Show that the eigenvalues of the differential operator $\\mathcal{L}$ are integers in the imaginary axis.}\n\n\\proof By making use of the PDE,\n\\begin{align*}\nu_{xx}=\\lambda p_x=\\lambda^2u.\n\\end{align*}\nLet $\\lambda^2=-k^2$. Then, \n\\begin{align*}\nu=A\\cos(kx)+iB\\sin(kx).\n\\end{align*}\nApplying the boundary conditions,\n\\begin{align*}\nu(t,0)=A=0,\n\\end{align*}\nand\n\\begin{align*}\nu(t,\\pi)=iB\\sin(k\\pi)=0,\n\\end{align*}\nwhich implies either $B=0$ (trivial solution) or $\\sin(k\\pi)=0$. Hence we get\n\\begin{align*}\nk=0,\\pm 1,\\pm 2,...~\\Rightarrow~\\lambda=0,\\pm i,\\pm 2i,...\n\\end{align*}\nsince $\\lambda=\\pm\\sqrt{-k^2}=\\pm k i$.\n\n\\item[b)] \\textbf{Consider the finite difference discretization used in HW3 for the spatial derivatives. The eigenvectors of the discrete FD matrix are}\n$$\nV^k=\\begin{bmatrix}i\\sin(kx_1)\\\\i\\sin(kx_2)\\\\\\vdots\\\\i\\sin(kx_{N-1})\\\\cos(kx_{1/2})\\\\cos(kx_{3/2})\\\\\\vdots\\\\cos(kx_{N-1/2})\\\\\\end{bmatrix},\\quad k=-(N-1),\\ldots, -1, 0, 1, \\ldots, N-1.\n$$\n\\textbf{Find the analytical expression for the eigenvalues and check it with \\texttt{eig(M)} in \\textsl{Matlab}.}\n\nFrom the matrix $M$ given and the $k$-th eigenvector above, we can compute $MV^k$,\n\\begin{align*}\nMV^k = \\begin{cases} \n-V_{j+N-1}^k + V_{j+n}^k & j \\leq N-1 \\\\\nV_1^k & j=N \\\\\n-V_{j-N}^k + V_{j-N+1}^k & N+1 \\leq j < 2N-1 \\\\\n-V_{N-1}^k & j = 2N-1\n\\end{cases}~,\n\\end{align*}\nwhere $V^k$ represents the $k$-th eigenvector, and $j$ is the column inside the vector. From here we can solve for the eigenvalues for the different values of $j$. Let $j \\leq N-1$. Then,\n\\begin{align*}\nMV^k &= \\frac{1}{h}\\left[-V_{j+N-1}^k + V_{j+n}^k\\right] \\\\ \n&= -\\cos(kx_{j-1/2}) + \\cos(kx_{j+1/2}) \\\\\n& = -\\cos\\left(k\\left(j-\\frac{1}{2}\\right)h\\right)+\\cos\\left(k\\left(j+\\frac{1}{2}\\right)h\\right) \\\\\n& = -2\\sin(kjh)\\sin\\left(k\\frac{h}{2}\\right),\n\\end{align*}\nwhere we have used the identity $\\cos(a+b) - \\cos(a - b) = -2\\sin(a)(b)$. Then, since we are looking for the eigenvalue that satisfies $MV^k=\\lambda^kV^k$, we have\n\\begin{align*}\n&-2\\sin(kjh)\\sin\\left(k\\frac{h}{2}\\right) = ih\\sin(kjh)\\lambda_j \\\\ &\\Rightarrow \\lambda_j^k = \\frac{2i}{h}\\sin\\left(k\\frac{h}{2}\\right)=\\lambda^k.\n\\end{align*}\nNote that the $k$-th eigenvalue does not depend on $j$. This is the desired result since the $k$-th eigenvalue is the same for the each entry of the $k$-th eigenvector. \n\nNext let $j = N$. Then,\n\\begin{align*}\n& MV^k = \\frac{1}{h}V_1^k = \\frac{i}{h}\\sin(kh)~,\n\\end{align*}\nand\n\\begin{align*}\n& \\lambda_N^kV^k = \\lambda^k_N\\cos(kx_{1/2}) = \\lambda^k_N\\cos\\left(k\\frac{h}{2}\\right)~,\n\\end{align*}\nwhich implies\n\\begin{align*}\n& \\frac{i}{h}\\sin(kh) = \\lambda^k_N\\cos\\left(k\\frac{h}{2}\\right) \\\\\n& \\Rightarrow i\\sin(kh) = \\lambda^k_Nh\\cos\\left(k\\frac{h}{2}\\right) \\\\\n& \\Rightarrow 2i\\sin\\left(k\\frac{h}{2}\\right)\\cos\\left(k\\frac{h}{2}\\right) = \\lambda^k_Nh \\cos\\left(k\\frac{h}{2}\\right) \\\\\n& \\Rightarrow \\lambda^k_N =\\frac{2i}{h}\\sin\\left(k\\frac{h}{2}\\right)=\\lambda^k.\n\\end{align*}\nNow, let $j \\in [N+1,2N-1)$, then\n\\begin{align*}\nMV^k &= \\frac{1}{h}\\left[-V_{j-N}^k + V_{j-N+1}^k \\right]\\\\ \n&= \\frac{i}{h}\\left[-\\sin\\left(kx_{j-N}\\right)+\\sin\\left(kx_{j-N+1}\\right)\\right] \\\\\n& = \\frac{i}{h}\\left[\\sin(k(j-N+1)h) - \\sin(k(j-N)h)\\right]~,\n\\end{align*}\nand\n\\begin{align*}\n\\lambda^k_j V_j^k = \\lambda^k_j\\cos(kx_{j-N+1/2}) = \\lambda^k_j \\cos(k(j-N+1/2)h)~.\n\\end{align*}\nThis gives us\n\\begin{align*}\n& \\frac{i}{h}\\left[\\sin(k(j-N+1)h) - \\sin(k(j-N)h)\\right] = \\lambda^k_j \\cos(k(j-N+1/2)h) \\\\\n& \\Rightarrow \\frac{2i}{h}\\cos(k(j-N+1/2)h)\\sin\\left(k\\frac{h}{2}\\right) = \\lambda^k_j \\cos(k(j-N+1/2)h) \\\\\n& \\Rightarrow \\lambda^k_j = \\frac{2i}{h}\\sin\\left(k\\frac{h}{2}\\right)=\\lambda^k.\n\\end{align*}\nFinally, for the last entry of the vector, let $j= 2N-1$, then\n\\begin{align*}\nMV^k & = -\\frac{1}{h}V_{N-1}^k = -\\frac{i}{h}\\sin(kx_{N-1}) = -\\frac{i}{h}\\sin(k(N-1)h) = -\\frac{i}{h}\\sin(k\\pi - kh) \\\\\n& = -\\frac{i}{h}\\sin(k\\pi)\\cos(kh) + \\frac{i}{h}\\sin(kh)\\cos(k\\pi) = \\frac{i}{h}\\sin(kh)\\cos(k\\pi)~,\n\\end{align*}\nand\n\\begin{align*}\n\\lambda^k_{2N-1}V^k &= \\lambda^k_{2N-1}\\cos(k(N-1/2)h) = \\lambda^k_{2N-1}\\cos\\left(knh - k\\frac{h}{2}\\right) = \\lambda^k_{2N-1}\\cos\\left(k\\pi - k\\frac{h}{2}\\right) \\\\\n& = \\lambda^k_{2N-1}\\left[\\cos(k\\pi)\\cos\\left(k\\frac{h}{2}\\right) - \\sin(k\\pi)\\sin\\left(k\\frac{h}{2}\\right)\\right] = \\lambda^k_{2N-1}\\cos(k\\pi)\\cos\\left(k\\frac{h}{2}\\right)~.\n\\end{align*}\nJoining the two results we get the following equation,\n\\begin{align*}\n& \\lambda^k_{2N-1}\\cos\\left(k\\pi - k\\frac{h}{2}\\right) = \\frac{i}{h}\\sin(kh)\\cos(k\\pi) \\\\\n& \\Rightarrow \\lambda^k_{2N-1} = \\frac{2i}{h}\\sin\\left(k\\frac{h}{2}\\right)=\\lambda^k.\n\\end{align*}\nThus,\n\\begin{align*}\n\\boxed{\\lambda^k= \\frac{2i}{h}\\sin\\left(k\\frac{h}{2}\\right)}~.\n\\end{align*}\n\\subsection*{Matlab code for this part}\n\\begin{verbatim}\n%% Problem 2b\nclear variables\nclose all\n\nN=100;\nh=pi/N;\n\nDu = gallery('tridiag',N,-1,1,0)/h; % In sparse form.\nDu(:,end)=[];\nDp = gallery('tridiag',N,0,-1,1)/h; % In sparse form.\nDp(end,:)=[];\nZ1 = zeros(N-1,N-1);\nZ2 = zeros(N,N);\n\nM = [Z1 Dp ; Du Z2];\n\nE=eig(full(M));\nE=sort(E);\nk=-(N-1):(N-1);\nE_analytic=2*1i/h*sin(k*h/2)';\nE_analytic=sort(E_analytic); \n\ndifference=norm(E-E_analytic,inf) \n% The expression in part b is correct\n\\end{verbatim}\n\\item[c)] \\textbf{Show that the eigenvalues of $M$ are $\\mathcal{O}(h^2)$.}\n\\proof We can prove the state ment by simply Taylor expanding the previous expression for the eigenvalues :\n\\begin{align*}\n\\lambda_k(h) &= \\lambda_k(0) + h\\lambda'_k(0) + \\frac{h^2}{2}\\lambda''_k(0) + \\frac{h^3}{6} \\lambda'''_k(0) + \\cdots \\\\\n& = \\frac{ik}{h}h - \\frac{h^3}{6}i\\frac{k^3}{4h} + \\mathcal{O}(h^4) \\\\\n& = ik\\left[ 1 + \\frac{k^2h^2}{6} + \\mathcal{O}(h^4) \\right].\n\\end{align*}\nNote that we have dropped the $k$ for convenience. Thus,\n\\begin{align*}\n\\lambda_k(h)  = ik\\left[1 + \\mathcal{O}((kh)^2)\\right].\n\\end{align*}\n\n\\item[d)] \\textbf{Show that}\n\\begin{align*}\n\\lambda_{\\pm(N-1)} = \\pm \\frac{2i}{h}\\cos(h/2), ~~\\text{and}~~|\\lambda_{\\pm(N-1)}| < \\frac{2}{h} = \\frac{2}{\\pi}N~.\n\\end{align*}\nBy simply plugging $\\pm(N-1)$ into the eigenvalue equation,\n\\begin{align*}\n\\lambda_{\\pm (N-1)} &= \\frac{2i}{h}\\sin\\left(\\pm N\\frac{h}{2} \\mp \\frac{h}{2} \\right) = \\frac{2i}{h} \\sin \\left( \\pm \\frac{\\pi}{2} \\mp \\frac{h}{2}\\right) \\\\\n& = \\frac{2i}{h} \\left[\\sin\\left(\\pm \\frac{\\pi}{2}\\right)\\cos\\left(\\mp\\frac{h}{2}\\right) + \\cos\\left(\\pm \\frac{\\pi}{2}\\right)\\sin\\left(\\mp\\frac{h}{2}\\right) \\right] \\\\\n& = \\pm \\frac{2i}{h}\\cos\\left(\\frac{h}{2}\\right)~.\n\\end{align*}\n\nUsing this, we note that $0 \\leq |\\cos\\left(\\frac{\\pi}{2N}\\right)| < 1$ and $|i| = 1$, so,\n\\begin{align*}\n|\\lambda_{\\pm (N-1)}| =\\left|\\pm \\frac{2i}{h}\\cos\\left(\\frac{h}{2}\\right)\\right| < \\frac{2}{h} = \\frac{2N}{\\pi}~.\n\\end{align*}\n\\item[e)] \\textbf{Use \\texttt{RK4} to time-step this PDE. Plot the stability region of \\texttt{RK4} and find a stable $\\Delta t$. Find the growth function $g$ for this method and plot $|g|$ using contour.}\n\nTo obtain the growth function $g(z)$ let $z = \\Delta t \\lambda$ and $f(t,y) = \\lambda y$. Then,\n \\begin{align*}\n & k_1 = zy^n \\\\\n& k_2 = \\left(z + \\frac{z^2}{2}\\right)y^n \\\\\n & k_3 = \\left(z + \\frac{1}{2}\\left(z^2 + \\frac{z^3}{2}\\right)\\right)y^n \\\\\n & k_4 = \\left(z + z\\left(z + \\frac{1}{2} \\left(z^2+\\frac{z^3}{2}\\right)\\right)\\right)y^n ~,\n \\end{align*}\nand\n\\begin{align*}\ny^{n+1} &= y^n + \\frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4)y^n\\\\\n&=\\left(1 + \\frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4)\\right)y^n\\\\\n&=\\left[1 + \\frac{1}{6}\\left(6z+3z^2+z^3+\\frac{z^4}{4}\\right)\\right]y^n.\n\\end{align*}\nHence,\n\\begin{align*}\ng(z) = 1 + \\frac{1}{6}\\left(6z+3z^2+z^3+\\frac{z^4}{4}\\right).\n\\end{align*}\n\nWe can plot $g(z)$ in \\textsl{Matlab} to obtain the stability region, shown in part f).\n\n\\item[f)] \\textbf{Assuming that the boundary of the stability region crosses the imaginary axis approximately at $\\pm 2.81i$, estimate the stability requirement on $\\Delta t$ (use part $(4)$ to find $c$ so that $\\Delta t < ch$ for stability). For $N = 100$, plot the eigenvalues of $M$ multiplied by $\\Delta t$ together with the stability region and verify that they fall inside the stability region.}\n\nFor stability we know that\n\\begin{align*}\n\\left|\\Delta t \\lambda_k\\right|<2.81,\n\\end{align*}\nfor all the eigenvalues $\\lambda_k$. Since the largest eigenvalue is going to be the one from part d),\n\\begin{align*}\n\\frac{2.81}{|\\lambda_k|} > \\frac{2.81}{|\\lambda_{\\pm (N-1)}|} > \\frac{2.81}{2}h > \\Delta t.\n\\end{align*}\nThus,\n\\begin{align*}\n\\Delta t < 1.405h.\n\\end{align*}\n\nThe figure below shows that $1.405h \\lambda_k$ falls within the stability region for all $\\lambda_k$.\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.75]{P2_ef.eps}}\n\\caption{Stability region and eigenvalues.}\n\\end{figure}\n\n\\subsection*{Matlab code for this part}\n\\begin{verbatim}\na=-20;\nb=20;\nc=-20;\nd=20;\ndx=0.1;\ndy=dx;\n\n[zr,zi]=meshgrid(a:dx:b,c:dy:d);\nz=zr+1i*zi;\ng=1+1/6*(6*z+3*z.^2+z.^3+z.^4/4);\ndt=1.405*h;\nlambda=dt*E;\n\nfigure\ncontourf(zr,zi,abs(g),[-inf 1 inf], 'k'), colorbar\nhold on\ngrid on\nplot(real(lambda),imag(lambda),'r*')\nxlabel('$x(t)$','interpreter','latex','fontsize',16)\nylabel('$y(t)$','interpreter','latex','fontsize',16)\naxis('image', [-4 1 -3 3])\nset(gca,'fontsize',12)\ntxt='Latex/FIGURES/P2_ef';\nsaveas(gcf,txt,'epsc')\n\\end{verbatim}\n\n\\item[g)] \\textbf{With $N=100$, solve the PDE using \\texttt{RK4} and plot your solution at times $t = \\pi/2$, $\\pi,3$, $\\pi/2$, $2\\pi$.}\n\nWe can see the solutions at those values of time in the next figure.\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace*{\\fill}\n\\subfigure[Solutions at $t = \\pi/2$.]{\\includegraphics[scale=0.55]{P2_g1}}\n\\hfill\n\\subfigure[Solutions at $t = \\pi$.]{\\includegraphics[scale=0.55]{P2_g2}}\n\\hspace*{\\fill}\n\n\\hspace*{\\fill}\n\\subfigure[Solutions at $t = 3\\pi/2$.]{\\includegraphics[scale=0.55]{P2_g3}}\n\\hfill\n\\subfigure[Solutions at $t = 2\\pi$.]{\\includegraphics[scale=0.55]{P2_g4}}\n\\hspace*{\\fill}\n\\caption{Solutions of the acoustic equation.}\n\\end{figure}\n\\subsection*{Matlab code for this part}\n\\begin{verbatim}\n%% Problem 2g\nclear variables\nclose all\nformat long\nclc\n\nlinewidth=1.7;\nlegendfontsize=14;\naxisfontsize=14;\n\nN=100;\nL=pi;\nh=L/N;\nxu=linspace(0,pi,N+1);\nxp=linspace(0+h/2,pi-h/2,N);\n\nDu = gallery('tridiag',N,-1,1,0); % In sparse form.\nDu(:,end)=[];\nDu=Du/h;\nDp = gallery('tridiag',N,0,-1,1); % In sparse form.\nDp(end,:)=[];\nDp=Dp/h;\nZ1 = zeros(N-1,N-1);\nZ2 = zeros(N,N);\nM = [Z1 Dp ; Du Z2];\n\nu0 = exp(-30*(xu-pi/2).^2)';\np0 = zeros(N,1);\nV0 = [u0(2:end-1) ; p0];\n\nt = 0:pi/200:2*pi;\ndydt = @(t,V) M*V;\n[t,V] = rk4(dydt,[0 2*pi],V0,length(t)-1);\n% Plots\nfigure(1)\nplot(xu,[0 V(101,1:N-1) 0],'linewidth',linewidth)\nhold on\nplot(xp,V(101,N:2*N-1),'linewidth',linewidth)\ngrid on\naxis([0 pi -1 1])\nxlabel('$x(t)$','interpreter','latex')\nlegend({' $u(x,t)$',' $p(x,t)$'},...\n 'Interpreter','latex','fontsize',legendfontsize)\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P2_g1';\nsaveas(gcf,txt,'epsc')\n\n\nfigure(2)\nplot(xu,[0 V(201,1:N-1) 0],'linewidth',linewidth)\nhold on\nplot(xp,V(201,N:2*N-1),'linewidth',linewidth)\ngrid on\naxis([0 pi -1 1])\nxlabel('$x(t)$','interpreter','latex')\nlegend({' $u(x,t)$',' $p(x,t)$'},...\n 'Interpreter','latex','fontsize',legendfontsize)\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P2_g2';\nsaveas(gcf,txt,'epsc')\n\nfigure(3)\nplot(xu,[0 V(301,1:N-1) 0],'linewidth',linewidth)\nhold on\nplot(xp,V(301,N:2*N-1),'linewidth',linewidth)\ngrid on\naxis([0 pi -1 1])\nxlabel('$x(t)$','interpreter','latex')\nlegend({' $u(x,t)$',' $p(x,t)$'},...\n 'Interpreter','latex','fontsize',legendfontsize)\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P2_g3';\nsaveas(gcf,txt,'epsc')\n\nfigure(4)\nplot(xu,[0 V(401,1:N-1) 0],'linewidth',linewidth)\nhold on\nplot(xp,V(401,N:2*N-1),'linewidth',linewidth)\ngrid on\naxis([0 pi -1 1])\nxlabel('$x(t)$','interpreter','latex')\nlegend({' $u(x,t)$',' $p(x,t)$'},...\n 'Interpreter','latex','fontsize',legendfontsize)\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P2_g4';\nsaveas(gcf,txt,'epsc')\n\\end{verbatim}\n\n\\item[h)] \\textbf{With $N=100$, run you code with $\\Delta t$ that is slightly bigger than the optimal (stable) choice, is the computation stable?}\n\nWith a choice of $\\Delta t=1.471 h$, the solution is unstable as we can see in the next figure.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.75]{P2_h.eps}}\n\\caption{Unstable solution.}\n\\end{figure}\n\n\\subsection*{Matlab code for this part}\n\\begin{verbatim}\n%% Problem 2h\nt = 0:1.48*h:2*pi;\ndydt = @(t,V) M*V;\n[t,V] = rk4(dydt,[0 2*pi],V0,length(t)-1);\nfigure \nplot(xu,[0 V(end,1:N-1) 0])\nhold on\nplot(xp,V(end,N:2*N-1))\ngrid on\n% axis([0 pi -1 1])\nxlim([0 pi])\nxlabel('$x(t)$','interpreter','latex')\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P2_h';\nsaveas(gcf,txt,'epsc')\n\\end{verbatim}\n\n\\item[i)] \\textbf{Using the stability criteria for choosing $\\Delta t$, plot the error at $t = 2\\pi$ for several values of $N$ and verify that the error decays as $\\mathcal{O}(h^2)$. Conclude that the error is dominated by the spatial discretization in this case.}\n\nThe spatial discretization dominates the error since the method used is second order in space and fourth order in time, which means the spatial discretization leads the error. However, we can see in the following figure that the observed order of convergence is not the theoretical one. We have obtained a observed order of convergence of $3.998$ for $u$ and $1.993$ for $p$ using the infinity norm for the errors of both. For the interpolation we have not used the first two data points.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace*{\\fill}\n\\subfigure[Error of $u$ with $N$.]{\\includegraphics[scale=0.55]{P2_iu}}\n\\hfill\n\\subfigure[Error of $p$ with $N$.]{\\includegraphics[scale=0.55]{P2_ip}}\n\\hspace*{\\fill}\n\\caption{Order of convergence.}\n\\end{figure}\n\\subsection*{Matlab code for this part}\n\\begin{verbatim}\n%% Problem 2i\nclear variables\nclose all\nformat long\nclc\n%Calculate exact solution with a large number of N\naxisfontsize=14;\nL=pi;\n\n% Check order of convergence\nNvector=[50 100 200 400 800 1600];\nfor i=1:length(Nvector)\n    N=Nvector(i)\n    h=L/N;\n    xu=linspace(0,pi,N+1);\n    xp=linspace(0+h/2,pi-h/2,N);\n    \n    Du = gallery('tridiag',N,-1,1,0); % In sparse form.\n    Du(:,end)=[];\n    Du=Du/h;\n    Dp = gallery('tridiag',N,0,-1,1); % In sparse form.\n    Dp(end,:)=[];\n    Dp=Dp/h;\n    Z1 = zeros(N-1,N-1);\n    Z2 = zeros(N,N);\n    M = [Z1 Dp ; Du Z2];\n    \n    u0 = exp(-30*(xu-pi/2).^2)';\n    p0 = zeros(N,1);\n    V0 = [u0(2:end-1) ; p0];\n    dt=h;\n    t = 0:dt:2*pi;\n    dydt = @(t,V) M*V;\n    [t,V] = rk4(dydt,[0 2*pi],V0,length(t)-1);\n    \n    difNormu(i)=norm(V(end,1:N-1)'-u0(2:end-1),inf);\n    index=find(xp>=pi/2,1);\n    difNormp(i)=norm(V(end,N:2*N-1)'-p0,inf);\nend\n% Order of convergence of u and p\nhvector=pi/1600:1e-5:pi/50;\nNvectorCont=20:500:7e3;\n\n% Fitting curves for the error.\n% Ignore first 2 points. No asymptotic regime.\n\ncu=polyfit(log(Nvector(3:end)),log(difNormu(3:end)),1);\nufit=exp(cu(2))*NvectorCont.^cu(1);\ncp=polyfit(log(Nvector(3:end)),log(difNormp(3:end)),1);\npfit=exp(cp(2))*NvectorCont.^cp(1);\ncu(1)\ncp(1)\n\nfigure\nloglog(Nvector,difNormu,'r*')\nhold on\nloglog(NvectorCont,ufit,'linewidth',2)\ngrid on\nxlim([30 2000])\nset(gca,'fontsize',axisfontsize)\nxlabel('$N$','interpreter','latex','fontsize',16)\nylabel('$e_u$','interpreter','latex','fontsize',16)\ntxt='Latex/FIGURES/P2_iu';\nsaveas(gcf,txt,'epsc')\n\nfigure\nloglog(Nvector,difNormp,'r*')\nhold on\nloglog(NvectorCont,pfit,'linewidth',2)\ngrid on\nxlim([30 2000])\nset(gca,'fontsize',axisfontsize)\nxlabel('$N$','interpreter','latex','fontsize',16)\nylabel('$e_p$','interpreter','latex','fontsize',16)\ntxt='Latex/FIGURES/P2_ip';\nsaveas(gcf,txt,'epsc')\n\\end{verbatim}\n\n\\item[j)] \\textbf{Repeat part g), but use 3rd order Adams-Bashforth for time-stepping. Use \\texttt{RK4} to compute the first 2 time levels. Use a $\\Delta t$ that is close to the stability limit for \\texttt{AB3}.}\nFirst we calculate the stability region for 3rd order Adams-Bashforth, which has the following form,\n\\begin{align*}\ny^{n+1} = y^n = \\frac{\\Delta t}{12}(23f^n - 16f^{n-1} + 5f^{n-2}).\n\\end{align*}\nWe begin with the substitution $f^n = \\lambda y^n$: \n\\begin{align*}\ny^{n+1} = y^n = \\frac{\\lambda \\Delta t}{12}(23y^n - 16y^{n-1} + 5y^{n-2}).\n\\end{align*}\nNote that $y^n = gy^{n-1}$ and let $z = \\lambda \\Delta t$,\n\\begin{align*}\ngy^n = y^n + \\frac{z}{12}\\left(23y^n - 16\\frac{y^n}{g} + 5\\frac{y^n}{g^2}\\right).\n\\end{align*}\nFactoring out $y^n$ we get\n\\begin{align*}\ng^3 = g^2 + \\frac{z}{12}(23g^2 - 16g +5),\n\\end{align*}\nand solving for $z$,\n\\begin{align*}\nz = 12 \\left( \\frac{g^3-g^2}{23g^2-16g+5} \\right).\n\\end{align*}\n\n\nUsing Matlab, we find the stability region crosses the imaginary axis just shy of $\\pm 0.72$. Thus we calculate a stable time step to be\n\\begin{align*}\n\\Delta t\\leq 0.36h.\n\\end{align*}\nWe will choose in the code $\\Delta t = 0.36h$. In the next figure we can see how all the eigenvalues are inside the stability region for the time step chosen.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.55]{P2_jRegion.eps}}\n\\caption{Stability region and eigenvalues.}\n\\end{figure}\n\nFinally, in the next figure we can see that we obtained the same solution as in part g).\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace*{\\fill}\n\\subfigure[Solutions at $t = \\pi/2$.]{\\includegraphics[scale=0.55]{P2_j1}}\n\\hfill\n\\subfigure[Solutions at $t = \\pi$.]{\\includegraphics[scale=0.55]{P2_j2}}\n\\hspace*{\\fill}\n\n\\hspace*{\\fill}\n\\subfigure[Solutions at $t = 3\\pi/2$.]{\\includegraphics[scale=0.55]{P2_j3}}\n\\hfill\n\\subfigure[Solutions at $t = 2\\pi$.]{\\includegraphics[scale=0.55]{P2_j4}}\n\\hspace*{\\fill}\n\\caption{Solutions of the acoustic equation.}\n\\end{figure}\n\\subsection*{Matlab code for this part}\n\\begin{verbatim}\n%% Problem 2j\nclear variables\nclose all\nclc\n\nlegendfontsize=14;\naxisfontsize=14;\n\nL=pi;\nN=100;\nh=L/N;\n\ntheta=linspace(0,2*pi,N);\ng=exp(1i*theta);\nz=12*(g.^3-g.^2)./(23*g.^2-16*g+5);\n\nxu=linspace(0,pi,N+1);\nxp=linspace(0+h/2,pi-h/2,N);\n\nDu = gallery('tridiag',N,-1,1,0); % In sparse form.\nDu(:,end)=[];\nDu=Du/h;\nDp = gallery('tridiag',N,0,-1,1); % In sparse form.\nDp(end,:)=[];\nDp=Dp/h;\nZ1 = zeros(N-1,N-1);\nZ2 = zeros(N,N);\nM = [Z1 Dp ; Du Z2];\n\ne=eig(full(M));\ndt=0.36*h;\nlambdadt=dt*e;\n\n%Plot eigenvalues in stability region\nfigure\nplot(z,'b','linewidth',2)\nhold on\nplot(real(lambdadt),imag(lambdadt),'r*')\ngrid on\nxlabel('$\\Re(z)$','interpreter','latex'...\n    ,'fontsize',16)\nylabel('$\\Im(z)$','interpreter','latex'...\n    ,'fontsize',16)\ntxt='Latex/FIGURES/P2_jRegion';\nsaveas(gcf,txt,'epsc')\n\n\nu0 = exp(-30*(xu-pi/2).^2)';\np0 = zeros(N,1);\nV0 = [u0(2:end-1) ; p0];\n\n\nF2=@(t,v) M*v;\n\n[t,V]=rk4(F2,[0 2*dt],V0,2);\n\nF1=@(v) M*v;\nf0=F1(V(1,:)');\nf1=F1(V(2,:)');\nf=F1(V(3,:)');\n\nV=V(3,:)'+dt/12*(23*f-16*f1+5*f0);\n\nt=t(end);\noutputTime=[pi/2 pi 3*pi/2 2*pi];\nn=1;\nwhile t<2*pi\n    if (t < outputTime(n) && t+dt >= outputTime(n))\n        dt=outputTime(n)-t;\n    else\n        dt=0.36*h;\n    end\n    f=F1(V);\n    V=V+dt/12*(23*f-16*f1+5*f0);\n    %Advance variables\n    f0=f1;\n    f1=f;\n    t=t+dt;\n    if (t==outputTime(n))\n        figure\n        plot(xu',[0; V(1:N-1); 0],'linewidth',2)\n        hold on\n        plot(xp',V(N:2*N-1),'linewidth',2)\n        grid on\n        legend({' $u(x,t)$',' $p(x,t)$'},...\n        'Interpreter','latex','fontsize',legendfontsize)\n        set(gca,'fontsize',axisfontsize)\n        xlabel('$x(t)$','interpreter','latex','fontsize',16)\n        axis([0 pi -1 1])\n        txt=['Latex/FIGURES/P2_j' num2str(n)];\n        saveas(gcf,txt,'epsc')\n        n=n+1;\n    end\nend\n\\end{verbatim}\n\\end{enumerate}", "meta": {"hexsha": "3fd1939ee9ad5f494a78f85c0d197ef9bd1859e0", "size": 19877, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/problem2.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/problem2.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/problem2.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1634304207, "max_line_length": 488, "alphanum_fraction": 0.6367158022, "num_tokens": 7807, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742805, "lm_q2_score": 0.901920681802153, "lm_q1q2_score": 0.8251681014797063}}
{"text": "\n\\subsection{Fran\\c cois Vi\\`ete}\nFran\\c cois Vi\\`ete was the first to discover an exact formula for $\\pi$.\nHere is his formula.\n\\begin{displaymath}\n{2\\over\\pi}={\\sqrt2\\over2}\\times{\\sqrt{2+\\sqrt2}\\over2}\\times\n{\\sqrt{2+\\sqrt{2+\\sqrt2}}\\over2}\\times\\cdots\n\\end{displaymath}\n%We can flip it around and write the formula like this.\n%\\begin{displaymath}\n%\\pi=2\\times{2\\over\\sqrt2}\\times{2\\over\\sqrt{2+\\sqrt2}}\\times\n%{2\\over\\sqrt{2+\\sqrt{2+\\sqrt2}}}\\times\\cdots\n%\\end{displaymath}\nLet $a_0=0$ and $a_{n}=\\sqrt{2+a_{n-1}}$.\nThen we can write\n\\begin{displaymath}\n{2\\over\\pi}={a_1\\over2}\\times{a_2\\over2}\\times\n{a_3\\over2}\\times\\cdots\n\\end{displaymath}\n%\nSolving for $\\pi$ we have\n\\begin{displaymath}\n\\pi=2\\times{2\\over a_1}\\times{2\\over a_2}\\times{2\\over a_3}\\times\\cdots=2\\prod_{k=1}^\\infty\n{2\\over a_k}\n\\end{displaymath}\n%\nLet us now use Eigenmath to compute $\\pi$ according to Vi\\`ete's formula.\nOf course, we cannot calculate all the way out to infinity, we have to stop somewhere.\nIt turns out that nine factors are just enough to get six digits of accuracy.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\na(n)=test(n=0,0,sqrt(2+a(n-1)))\nfloat(2*product(k,1,9,2/a(k)))\n\\end{Verbatim}\n\n$\\displaystyle 3.14159$\n\nThe function $a(n)$ calls itself $n$ times so overall there are\n54 calls to $a(n)$.\nBy using a different algorithm with temporary variables, we can get the\nanswer in just nine steps.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\na = 0\nb = 2\nfor(k,1,9,a=sqrt(2+a),b=b*2/a)\nfloat(b)\n\\end{Verbatim}\n\n$\\displaystyle 3.14159$\n", "meta": {"hexsha": "5e4f3e88f3e1e1fb558088384a67c5c2dafb9f93", "size": 1550, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/francois-viete.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/francois-viete.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/francois-viete.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3921568627, "max_line_length": 91, "alphanum_fraction": 0.7161290323, "num_tokens": 571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620585273154, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.8250726439292313}}
{"text": "\n\\subsection{Identifying upper and lower bounds of linear programming}\n\nIn min/max problem, any feasibly solution is an upper/lower bound.\n\ncan we get a bound at the other side?\nyes, by doing linear combinations of inequalities\neg maximise\n\\(30x + 100y\\)\nsubject to:\n\\(4x + 10y <= 40\\)\n\\(x >=3 \\)\n\nWe can identify a lower bound by inputting something which works, for example \\(x=3\\) and \\(y=0\\). This gives us a lower bound of \\(90\\).\n\nTo get an upper bound we can manipulate the constraints:\n\\(40x + 100y<=400\\)\n\\(10x>=30\\)\nAnd then:\n\\(40x+100y<=370+30\\)\n\\(40x+100y<=370+10x\\)\n\\(30x+100y<=370\\)\n\nSo we have an upper bound of \\(370\\).\n\nThis lower bound is a result of doing linear combinations of the inequalities. For different combinations, we could have a lower lower bound.\n\nThis is the dual problem. How do we choose the linear combination of inequalities such that the resulting lower bound is minimised?\n\n", "meta": {"hexsha": "f20b2ca4555efea328abc97f68563c3809ac7c96", "size": 913, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/optimisationMulti/07-02-bounds.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/optimisationMulti/07-02-bounds.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/optimisationMulti/07-02-bounds.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.4333333333, "max_line_length": 141, "alphanum_fraction": 0.7294633078, "num_tokens": 250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.8947894639983208, "lm_q1q2_score": 0.8249259444582978}}
{"text": "\\Appendix{Mathematical Preliminaries}\\label{sec:intro-app}\n\nIn the analysis of distributed algorithms, we will encounter power towers and iterated logarithms.\n\n\\subsection{Power Tower}\n\nWe write power towers with the notation\n\\[\n    {}^i 2 = 2^{2^{\\cdot^{\\cdot^2}}},\n\\]\nwhere there are $i$ twos in the tower. Power towers grow very fast; for example,\n\\begin{align*}\n    {}^1 2 &= 2,\\\\\n    {}^2 2 &= 4,\\\\\n    {}^3 2 &= 16,\\\\\n    {}^4 2 &= 65536,\\\\\n    {}^5 2 &= 2^{65536} > 10^{19728}.\n\\end{align*}\n\n\\subsection{Iterated Logarithm}\n\nThe iterated logarithm of $x$, in notation $\\log^* x$ or $\\log^*(x)$, is defined recursively as follows:\n\\[\n    \\log^*(x) = \\begin{cases}\n        0 & \\text{ if $x \\le 1$}, \\\\\n        1 + \\log^*(\\log_2 x) & \\text{ otherwise}.\n    \\end{cases}\n\\]\nIn essence, this is the inverse of the power tower function. For all positive integers $i$, we have\n\\[\n    \\log^*({}^i 2) = i.\n\\]\nAs power towers grow very fast, iterated logarithms grow very slowly; for example,\n\\begin{align*}\n    \\log^* 2 &= 1, &\n    \\log^* 16 &= 3, &\n    \\log^* 10^{10} &= 5, \\\\\n    \\log^* 3 &= 2, &\n    \\log^* 17 &= 4, &\n    \\log^* 10^{100} &= 5, \\\\\n    \\log^* 4 &= 2, &\n    \\log^* 65536 &= 4, &\n    \\log^* 10^{1000} &= 5, \\\\\n    \\log^* 5 &= 3, &\n    \\log^* 65537 &= 5, &\n    \\log^* 10^{10000} &= 5, \\dotsc\n\\end{align*}\n\n", "meta": {"hexsha": "aa4cb6781f5f0f8cacddca897a0068f9b46732e6", "size": 1318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "book/ch01a.tex", "max_stars_repo_name": "suomela/da2020", "max_stars_repo_head_hexsha": "874238b4e1d395769fc89d0d3a9453366056ad1d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-12-11T00:47:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T15:46:43.000Z", "max_issues_repo_path": "book/ch01a.tex", "max_issues_repo_name": "suomela/da2020", "max_issues_repo_head_hexsha": "874238b4e1d395769fc89d0d3a9453366056ad1d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-17T18:31:27.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-17T18:42:16.000Z", "max_forks_repo_path": "book/ch01a.tex", "max_forks_repo_name": "suomela/da2020", "max_forks_repo_head_hexsha": "874238b4e1d395769fc89d0d3a9453366056ad1d", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-06-22T03:53:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:33:40.000Z", "avg_line_length": 26.8979591837, "max_line_length": 104, "alphanum_fraction": 0.5500758725, "num_tokens": 511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810407096791, "lm_q2_score": 0.8705972616934408, "lm_q1q2_score": 0.8247873398221287}}
{"text": "\\chapter{Back-Propagation}\\label{backprop}\n\nOne of the most common algorithms used for deep feedforward neural network learning is the \\VUname{back-propagation} algorithm (\\cite{rumelhart_learning_1986}), sometimes called \\VUname{backprop}. This term is often misunderstood as meaning the whole learning algorithm, whereas in fact this name refers only to the algorithm used for computing the gradient of the network, which is then used by the actual learning algorithm, such as gradient descent (\\cite{cauchy_methode_1847}), stochastic gradient descent or more advanced algorithms such as ADAM (\\cite{kingma_adam:_2014}).\n\nWhile back-propagation is commonly used for computing the gradient of a feedforward neural network, it is not limited to this task. Given a function \\( f \\left( \\VUvec{x}, \\VUvec{y} \\right) \\), the back-propagation algorithm can be used to compute the gradient of such a function with respect to \\( \\VUvec{x} \\), i. e. \\( \\nabla_{\\VUvec{x}} f \\left( \\VUvec{x}, \\VUvec{y} \\right) \\). To use the back-propagation algorithm, it is useful to describe the function with a \\VUname{computational graph}. A computational graph is a connected directed acyclic graph with nodes representing variables and edges representing operations, that is functions describing how to compute said variables. For example the equation \\( y = f \\left( x \\right) \\) is represented by two nodes, \\( x \\) and \\( y \\), and a directed edge from \\( x \\) to \\( y \\). The node representing \\( y \\) is labelled \\( f \\). This label is applied to the end node as the operation can in general have multiple input variables. Some of these labels may be omitted if the itermediary values are not of interest.\n\n\\section{Chain Rule of Calculus}\n\\begin{theorem}\\label{chain_rule}\n\tLet \\( x \\) be a real number, \\( f : \\VUfield{R} \\to \\VUfield{R} \\), \\( g : \\VUfield{R} \\to \\VUfield{R} \\). Let \\( y = f \\left( x \\right) \\) and \\( z = g \\left( y \\right) \\). Then\n\t\\[ \\frac{\\mathrm{d} z}{\\mathrm{d} x} = \\frac{\\mathrm{d} z}{\\mathrm{d} y} \\frac{\\mathrm{d} y}{\\mathrm{d} x} \\]\n\\end{theorem}\n\nThis theorem can be generalized for vectors:\n\n\\begin{theorem}\\label{chain_rule_vector}\n\tLet \\( \\VUvec{x} \\in \\VUfield{R}^n \\), \\( f : \\VUfield{R}^n \\to \\VUfield{R}^m \\), \\( g : \\VUfield{R}^m \\to \\VUfield{R} \\). Let \\( \\VUvec{y} = f \\left( \\VUvec{x} \\right) \\) and \\( z = g \\left( \\VUvec{y} \\right) \\). Then\n\t\\[ \\frac{\\partial z}{\\partial x_i} = \\sum_{j = 1}^{m} \\frac{\\partial z}{\\partial y_j} \\frac{\\partial y_j}{\\partial x_i} \\]\n\tor, in vector notation\n\t\\[ \\nabla_{\\VUvec{x}} z = \\left( \\frac{\\partial \\VUvec{y}}{\\partial \\VUvec{x}} \\right)^T \\nabla_{\\VUvec{y}} z \\]\n\twhere \\( \\frac{\\partial \\VUvec{y}}{\\partial \\VUvec{x}} \\) is the Jacobian matrix of \\( f \\).\n\\end{theorem}\n\nAnd this theorem can in turn be similarly generalized for tensors:\n\n\\begin{theorem}\\label{chain_rule_tensor}\n\tLet \\( \\VUmat{X} \\) be a tensor, \\( f \\) and \\( g \\) functions. Let \\( \\VUmat{Y} = f \\left( \\VUmat{X} \\right) \\) and \\( z = g \\left( \\VUmat{Y} \\right) \\). Then\n\t\\[ \\nabla_{\\VUmat{X}} z = \\sum_j \\left( \\nabla_{\\VUmat{X}} Y_j \\right) \\frac{\\partial z}{\\partial Y_j} \\]\n\twhere \\( j \\) is a tuple of indices for \\( \\VUmat{Y} \\).\n\\end{theorem}\n\n\\section{Applying the chain rule}\n\nIn a computational graph, if there exists a directed edge from \\( x \\) to \\( y \\), the influence changing \\( x \\) has on \\( y \\) is represented by \\( \\frac{\\partial y}{\\partial x} \\). To compute such influence between two variables which are not directly connected by an edge the chain rule can be used. This is trivial if there is only a singular directed path between the variables. However, consider the following problem:\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=150pt]{images/diamond/diamond.pdf}\n\t\\caption{Diamond-style computational graph}\\label{diamond}\n\\end{figure}\n\n\\begin{example}\n\tLet \\( x \\), \\( y \\), \\( z \\) and \\( w \\) be real numbers such that \\( y = f \\left( x \\right) \\), \\( z = g \\left( x \\right) \\) and \\( w = h \\left( y, z \\right) \\). The computational graph for this set of variables and operations is in figure \\ref{diamond}. The derivative \\( \\frac{\\partial w}{\\partial x} \\) cannot be computed directly by applying theorem \\ref{chain_rule}. Instead a sum over both directed paths must be used:\n\t\\[ \\frac{\\partial w}{\\partial x} = \\frac{\\partial w}{\\partial y} \\frac{\\partial y}{\\partial x} + \\frac{\\partial w}{\\partial z} \\frac{\\partial z}{\\partial x} \\]\n\tThis is the result of theorem \\ref{chain_rule_vector} where \n\t\\[ h : \\VUfield R^2 \\to \\VUfield R : \n\t\\begin{pmatrix}\n\t\ty \\\\\n\t\tz\n\t\\end{pmatrix} \\mapsto w \\]\n\nGenerally, in order to find the derivative \\( \\frac{\\partial y}{\\partial x} \\) the sum of chains of partial derivatives over all directed paths from \\( x \\) to \\( y \\) must be taken. This approach becomes computationally infeasible as the number of combinations of all edges increases very quickly with the length of the path. Back-propagation tries to overcome this explosive growth of the number of summands by performing factorization. Therefore, even when an edge is a part of several paths, its gradient is only computed once. This approach reduces computational complexity at the cost of higher memory requirements, a trade-off which may or may not be beneficial depending on the type of problem. For deep feedforward neural networks, the computational graphs are usually complicated and heavily interconnected, which makes such a trade-off a necessity.\n\nThe back-propagation algorithm is used to compute a gradient of a given single output variable \\( y \\) with respect to a set of given input variables \\( x^{(i)} \\), that is \\( \\frac{\\partial y}{\\partial x^{(i)}} \\text{ for } i \\in \\left\\{ 1, \\dots, n \\right\\} \\). The algorithm can be seen as successively assigning to each node \\( u \\) of the computational graph the gradient \\( \\frac{\\partial y }{\\partial u} \\). There are two simplifications to be made for the computational graph:\n\n\\begin{remark}\\label{backprop-no-dead-ends}\n\tIt can be assumed without loss of generality that from all nodes \\( u \\) of a given computation graph, there exists a directed path from \\( u \\) to the output node \\( y \\). If it were not so, then the gradient for such a node would be \\( \\frac{\\partial y}{\\partial u} = 0 \\)\n\\end{remark}\n\\begin{remark}\n\tThe computational graph can without loss of generality be assumed to only contain such nodes \\( u \\) that\n\t\\[ \\left( \\exists i \\in \\left\\{ 1, \\dots, n \\right\\} \\right) \\left( \\exists \\text{ a directed path from } x^{(i)} \\text{ to } u \\right) \\]\n\tThis assumption only serves as an optimisation as the excluded nodes do not affect the result of the algorithm and thus can be omitted.\n\\end{remark}\n\nAs a result of the fact that the computational graph is acyclic, all the nodes \\( u_1, \\dots, u_k \\) can be ordered in such a way that if there exists an edge from \\( u_j \\) to \\( u_i \\), then \\( i < j \\) (Reverse topological ordering). Moreover as a result of remark \\ref{backprop-no-dead-ends} and the fact that the graph is connected, there holds \\( y = u_1 \\) and so \\( \\frac{\\partial y}{\\partial u_1} = 1 \\).\n\nThen, for each node \\( u_i \\) of the computational graph, its gradient can be written as\n\\[ \\frac{\\partial y}{\\partial u_i} = \\sum_{u_j \\in \\mathrm{Desc} \\left( u_i \\right)} \\frac{\\partial y}{\\partial u_j} \\frac{\\partial u_j}{\\partial u_i} \\]\nwhere\n\\[ \\mathrm{Desc} \\left( u_i \\right) = \\left\\{ u \\middle| \\exists \\text{ a directed edge from } u_i \\text{ to } u \\right\\} \\]\nIf the nodes are reverse topologically ordered and the gradients computed in this order, then each of the necessary partial derivatives needed to compute \\( \\frac{\\partial y}{\\partial u_i} \\) has already been computed. Using this approach, the gradient for each node is computed only once during the run of the algorithm. The general algorithm for back-propagation is described in algorithm \\ref{backprop_algo} (A simplified version of algorithm 6.5 from \\cite{goodfellow_deep_2016}).\n\n\\begin{algorithm}\n\t\\caption{The general back-propagation algorithm for computational graphs}\n\t\\label{backprop_algo}\n\t\\begin{algorithmic}\n\t\t\\Require $ \\mathcal{G} $ \\Comment A pruned computational graph\n\t\t\\Require $ \\left\\{ x^{(i)} \\right\\}_{i = 1}^n $ \\Comment A set of input variables\n\t\t\\Require $ y $ \\Comment An output variable\n\t\t\\Statex\n\t\t\\Function{build\\_grad}{$ x, \\mathcal{G}, grad\\_table $}\n\t\t\t\\If{$ x \\in grad\\_table $}\n\t\t\t\t\\Return $ grad\\_table[x] $\n\t\t\t\\EndIf\n\t\t\t\\State $ i \\gets 1 $\n\t\t\t\\For{$ d \\in \\Call{Desc}{ x, \\mathcal{G}} $} \\Comment Descendants of $ x $\n\t\t\t\t\\State $ op \\gets \\Call{get\\_operation}{d} $ \\Comment Operation producing $ d $\n\t\t\t\t\\State $ D \\gets \\Call{build\\_grad}{d, \\mathcal{G}, grad\\_table} $\n\t\t\t\t\\State $ G^{(i)} \\gets \\Call{op.backprop}{\\Call{get\\_inputs}{d, \\mathcal{G}}, x, D} $ \\Comment Back-propagation over a single edge\n\t\t\t\t\\State $ i \\gets i + 1 $\n\t\t\t\\EndFor\n\t\t\t\\State $ grad\\_table[x] \\gets \\sum_i G^{(i)} $\n\t\t\\EndFunction\n\t\t\\Statex\n\t\t\\State $ grad\\_table[z] \\gets 1 $ \\Comment A table associating variables and their gradients\n\t\t\\For{$ x^{(i)} $}\n\t\t\t\\Call{build\\_grad}{$ x^{(i)}, \\mathcal{G}, grad\\_table $}\n\t\t\\EndFor\n\t\t\\Return $ grad\\_table $\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\section{Application of back-propagation to deep feedforward neural networks}\\label{backprop_application}\n\nA deep feedforward neural network (also known as a \\VUname{multilayer perceptron}) can be seen as a special case of a computational graph. The \\( i \\)-th layer of such a network can be represented as:\n\\[ \\VUvec h^{(i)} = f^{(i)} \\left( \\VUvec{h}^{(i - 1)} ; \\VUvec{\\theta}^{(i)} \\right) = \\sigma^{(i)} \\left( {\\VUmat{W}^{(i)}}^T \\VUvec h^{(i - 1)} + \\VUvec{b}^{(i)} \\right) \\]\nwhere \\( \\VUvec{h}^{(i - 1)} \\) is the input of the layer, \\( \\VUvec{h}^{(i)} \\) its output and\n\\[ \\VUvec{\\theta}^{(i)} = \\left( {\\VUmat{W}^{(i)}}^T \\middle| \\VUvec{b}^{(i)} \\right)^T \\]\nare the parameters of the layer (the weights \\( \\VUmat{W}^{(i)} \\) and the bias \\( \\VUvec{b}^{(i)} \\)).\n\nIn such a notation, a neural network with input \\( \\VUvec{x} \\) can be represented as\n\\[ \\widehat{\\VUvec{y}} = f^{(n)} \\circ f^{(n - 1)} \\circ \\dots \\circ f^{(1)} \\left( \\VUvec{x} \\right) \\]\nwhere for each layer \\( f^{(i)} \\) there exist corresponding parameters \\( \\VUvec{\\theta}^{(i)} \\). If \\( L \\) denotes the loss function of the network and \\( \\VUvec{y} \\) is the desired output of the network for the input \\( \\VUvec{x} \\), then the back-propagation algorithm is used to minimize the loss \\( J = L \\left( \\widehat{\\VUvec{y}}, \\VUvec{y} \\right) \\).\n\nFor simplicity, in the following text the input and predicted output are also denoted as\n\\[ \\VUvec{h}^{(0)} = \\VUvec{x} \\qquad \\text{and} \\qquad \\VUvec{h}^{(n)} = \\widehat{\\VUvec{y}} \\]\n\nFirst, the derivative of the loss with respect to the predicted output is taken:\n\\[ \\nabla_{\\widehat{\\VUvec{y} }} J = \\nabla_{\\widehat{\\VUvec{y}}} L \\left( \\widehat{\\VUvec{y}}, \\VUvec{y} \\right) \\]\nThen, for the \\( i \\)-th layer, theorem \\ref{chain_rule_tensor} is used for the activation function \\( \\sigma^{(i)} \\):\n\\[ \\nabla_{\\VUvec{a}^{(i)}} J = \\nabla_{\\VUvec{h}^{(i)}} J \\odot {\\sigma^{(i)}}' \\left( \\VUvec{a}^{(i)} \\right) \\]\nwhere \n\\[ \\VUvec{a}^{(i)} = {\\VUmat{W}^{(i)}}^T \\VUvec h^{(i - 1)} + \\VUvec{b}^{(i)} \\]\nFrom this value, the gradient with respect to the parameters of the layer can be computed as\n\\[ \\nabla_{\\VUmat{W}^{(i)}} J = \\nabla_{\\VUvec{a}^{(i)}} J {\\VUvec{h}^{(i - 1)}}^T \\]\n\\[ \\nabla_{\\VUvec{b}^{(i)}} J = \\nabla_{\\VUvec{a}^{(i)}} J \\]\nAnd for computing the gradients of the layer below:\n\\[ \\nabla_{\\VUvec{h}^{(i - 1)}} J = {\\VUmat{W}^{(i)}}^T \\nabla_{\\VUvec{a}^{(i)}} J \\]\nIf the gradients are computed backwards to the order of layers, this ordering is a reverse topological ordering of the computational graph and thus all the values required in each step of the algorithm have already been computed.\n\nThis chapter has been sourced from \\cite{goodfellow_deep_2016} and \\cite{olah_calculus_2015}.\n\\end{example}\n", "meta": {"hexsha": "dc145c4b7c0f451a65192a91f4c47c7c3ba410f8", "size": 11936, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "backpropagation.tex", "max_stars_repo_name": "marekdedic/VU-text", "max_stars_repo_head_hexsha": "f24cb31a2b9ba92656a9f7af9ec74f24c5bdde1c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "backpropagation.tex", "max_issues_repo_name": "marekdedic/VU-text", "max_issues_repo_head_hexsha": "f24cb31a2b9ba92656a9f7af9ec74f24c5bdde1c", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "backpropagation.tex", "max_forks_repo_name": "marekdedic/VU-text", "max_forks_repo_head_hexsha": "f24cb31a2b9ba92656a9f7af9ec74f24c5bdde1c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 90.4242424242, "max_line_length": 1069, "alphanum_fraction": 0.6827245308, "num_tokens": 3775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.8991213678089741, "lm_q1q2_score": 0.8247664199488258}}
{"text": "\\section{Gaussian integral}\n\n\\textbf{Normal distribution}, a term often appeared in statistics, is defined\nby equation (\\ref{gauss-distr})\n\n\\begin{equation}\n\tp(x)={1\\over\\sigma\\sqrt{2\\pi}}\n\te^{-\\frac12\\left(x-\\mu\\over\\sigma\\right)^2}\n\t\\label{gauss-distr}\n\\end{equation}\n\nin which $\\sigma$ is the standard deviation (Accordingly, $\\sigma^2$ is the\nvariance), and $\\mu$ is the mean value. Since normal distribution is a\n\\textbf{probability density function}, it should always satisfies (\\ref{pdf1})\nand (\\ref{pdf2}), where set $\\mathbb{X}$ denotes all possible values of the\ncontinuous variable $x$.\n\n\\begin{equation}\n\t\\forall x\\in\\mathbb{X},p(x)\\ge0\n\t\\label{pdf1}\n\\end{equation}\n\\begin{equation}\n\t\\int_{x\\in\\mathbb{X}} p(x)dx=1\n\t\\label{pdf2}\n\\end{equation}\n\nIt is very easy to prove that $p(x)>0$ because the exponential function is\nalways positive for all real input. In this section, Condition in equation\n(\\ref{pdf2}) will be proven.\n\n\\subsection{Perform substitution to simplify the integral}\n\nBy simplifying the exponential function, we make the following substitutions.\n\n$$\n\\begin{aligned}\n\t\\frac12\\left(x-\\mu\\over\\sigma\\right)^2=u^2 \\\\\n\tu={1\\over\\sqrt2}\\left(x-\\mu\\over\\sigma\\right) \\\\\n\tdu={dx\\over\\sigma\\sqrt2} \\\\\n\t\\therefore dx=\\sigma\\sqrt2du\n\\end{aligned}\n$$\n\nWith the substitutions applied, the integral is transformed.\n\n\\begin{equation}\n\t{1\\over\\sigma\\sqrt{2\\pi}}\\int_{-\\infty}^\\infty\n\te^{-\\frac12\\left(x-\\mu\\over\\sigma\\right)^2}dx=\n\t{1\\over\\sigma\\sqrt{2\\pi}}\\cdot\\sigma\\sqrt2\\int_{-\\infty}^\\infty\n\te^{-u^2}du\n\t={1\\over\\sqrt\\pi}\\int_{-\\infty}^\\infty e^{-u^2}du\n\t\\label{gauss-distr-int}\n\\end{equation}\n\nBy proving $\\int_{-\\infty}^\\infty e^{-u^2}du$, the Gaussian integral, is the\nsquare root of $\\pi$, we can then testify the normal distribution satisfies the\nsecond identity of probability density functions.\n\n\\subsection{Find the square of the Gaussian integral}\n\nSquaring the integral turns it into a double integral over the\ncartesian plane of $(u,v)$, which is also visualized in figure \\ref{gauss-3d}.\n\n$$\n\\begin{aligned}\n\t\\left(\\int_{-\\infty}^\\infty e^{-u^2}du\\right)^2\n\t&=\\int_{-\\infty}^\\infty e^{-u^2}du\\int_{-\\infty}^\\infty e^{-v^2}dv \\\\\n\t&=\\int_{-\\infty}^\\infty\\int_{-\\infty}^\\infty e^{-(u^2+v^2)}dudv\n\\end{aligned}\n$$\n\n\\begin{figure}[ht]\n\t\\centering{\\includegraphics[width=4in]{graphics/gauss-3d.png}}\n\t\\caption{Plot of function $z=e^{-(u^2+v^2)}$}\\label{gauss-3d}\n\\end{figure}\n\n\\subsection{Simplify the integral by converting coordinate systems}\n\nOstensibly, the integral problem seems to become more complicated; however, it\nbecomes easier with the transformation from Cartesian coordinates to polar\ncoordinates via applying the rules in equation (\\ref{car-to-pol}).\n\n\\begin{equation}\n\t\\begin{cases}\n\t\tu=r\\cos\\theta \\\\\n\t\tv=r\\sin\\theta\n\t\\end{cases}\n\t\\label{car-to-pol}\n\\end{equation}\n\nSince it is replacing two variables at the same time, the transformation itself\ncan be interpreted as a vector-valued function. Because $u$ and $v$ are\nnon-linearly transformed, a function will be needed to transform the tiny piece\n$dudv$. Although it is a non-linear transform, a linear approximation for this\ntransform is made possible by \\textbf{Jacobian matrix}.\n\n$$\nJ=\n\\begin{bmatrix}\n\t{\\partial u\\over\\partial r} & {\\partial u\\over\\partial\\theta} \\\\\n\t{\\partial v\\over\\partial r} & {\\partial v\\over\\partial\\theta}\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n\t\\cos\\theta & -r\\sin\\theta \\\\\n\t\\sin\\theta & r\\cos\\theta\n\\end{bmatrix}\n$$\n\nAccordingly, $dxdy$ is approximated by the absolute value of the\n\\textbf{Jacobian determinant}.\n\n$$\n\\left|\\det(J)\\right|=\\left|r\\cos^2\\theta+r\\sin^2\\theta\\right|=r\n$$\n\nAs a result, the complicated double integral over Cartesian plane becomes an\neasier double integral over polar regions.\n\n$$\n\\int_{-\\infty}^\\infty\\int_{-\\infty}^\\infty e^{-(u^2+v^2)}dudv\n=\\int_0^{2\\pi}\\int_0^\\infty e^{-r^2}rdrd\\theta\n$$\n\n\\pagebreak\n\\subsection{Evaluate the double integral}\n\nSince the inner function does not depend on the variable $\\theta$, the outer\nintegral is treated separately.\n\n$$\n\\int_0^{2\\pi}\\int_0^\\infty e^{-r^2}rdrd\\theta\n=\\int_0^{2\\pi}d\\theta\\int_0^\\infty e^{-r^2}rdr=2\\pi\\int_0^\\infty e^{-r^2}rdr\n$$\n\nNow, let $a\\triangleq-r^2$ so that the exponent is further simplified.\n\n$$\n\\begin{aligned}\n\t\\because a=-r^2 \\\\\n\t\\therefore da=-2rdr \\\\\n\\end{aligned}\n$$\n$$\n\\begin{aligned}\n\t2\\pi\\int_0^\\infty e^{-r^2}rdr\n\t&=\\pi\\int_{-\\infty}^0 e^ada \\\\\n\t&=\\pi\\cdot\\left.e^a\\right|_{-\\infty}^0=\\pi\\cdot1=\\pi\n\\end{aligned}\n$$\n\n\\subsection{Calculate Gaussian integral from the double integral}\n\nTake the square root of the double integral yields the answer to the original\nGaussian integral.\n\n$$\\int_{-\\infty}^\\infty e^{-u^2}du=\\sqrt\\pi$$\n\nPlugging the above result into equation (\\ref{gauss-distr-int}) makes\n(\\ref{gauss-distr}) a genuine probability density function.\n\n$$\n{1\\over\\sqrt\\pi}\\int_{-\\infty}^\\infty e^{-u^2}du\n={1\\over\\sqrt\\pi}\\cdot\\sqrt\\pi=1\n$$\n", "meta": {"hexsha": "a67b9f266b3443a4a1d2fe680f1dcce362181451", "size": 4869, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "integrate-gauss.tex", "max_stars_repo_name": "TravorLZH/mathcol-doc", "max_stars_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-17T04:58:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-17T04:58:27.000Z", "max_issues_repo_path": "integrate-gauss.tex", "max_issues_repo_name": "TravorLZH/mathcol-doc", "max_issues_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "integrate-gauss.tex", "max_forks_repo_name": "TravorLZH/mathcol-doc", "max_forks_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-07T07:20:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T07:20:36.000Z", "avg_line_length": 29.3313253012, "max_line_length": 79, "alphanum_fraction": 0.7155473403, "num_tokens": 1629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995703, "lm_q2_score": 0.8976952927915968, "lm_q1q2_score": 0.8245153835710034}}
{"text": "\\chapter{Finding Derivatives using Fourier Spectral Methods}\nSpectral methods are a class of numerical techniques that often utilize the FFT. Spectral methods can be implemented easily in Matlab, but there are some conventions to note. First note that Matlab's ``fft'' and ``ifft'' functions store wave numbers in a different order than has been used so far. The wave numbers in Matlab and in most other FFT packages are ordered, $0,1,...,\\frac{n}{2},-\\frac{n}{2}+1,-\\frac{n}{2}+2,...,-1$. Secondly, Matlab does not take full advantage of real input data. The DFT of real data satisfies the symmetry property $\\hat{v}(-k)=\\hat{v}(k)$, so it is only necessary to compute half of the wave numbers. Matlab's ``fft\" command does not take full advantage of this property and wastes memory storing both the positive and negative wave numbers. Third, spectral accuracy (exponential decay of the magnitude of the Fourier coefficients) is better for smooth functions, so where possible be sure your initial conditions are smooth -- \\textbf{When using a Fourier spectral method this requires that your initial conditions are periodic}.\n%%%%%%%%\n% subsection\n%%%%%%%%\n\\section{Taking a Derivative in Fourier Space}\nLet $u(x)$ be a function which is sampled at the $n$ discrete points $x_i \\in {h,2h,...,ih,..,2\\pi-h,2\\pi}$ and $h=2\\pi/n$ in real space. Now take the FFT\n\\begin{eqnarray}\n\\text{FFT}(u_j) \\equiv \\hat{u}_k \\qquad \\text{where} \\quad k \\in {\\frac{-n}{2}+1,...\\frac{n}{2}}.\n\\end{eqnarray}\nThe Fourier transform of $\\frac{\\partial^2 u_j}{\\partial x^2}$ can be easily computed from $\\hat{u}_k$\\footnote{More details can be found in Trefethen~\\cite[Chap. 3]{Tre00}}:\n\\begin{eqnarray}\n\\textrm{FFT}(\\frac{\\partial^\\nu u_j}{\\partial x^\\nu}) \\equiv (ik)^\\nu \\hat{u}_k \\qquad \\text{where} \\quad \\hat{u}_{n/2}=0 \\quad, \\text{if \\quad $\\nu$ \\quad \\text{is odd}}. \\label{eq:Spectral_Method_Deriv}\n\\end{eqnarray}\nThus, differentiation in real space becomes multiplication in Fourier space. We can then take the inverse fast Fourier Transform (IFFT) to yield a solution in real space. In the next section we will use this technique to implement forward Euler and backward Euler timestepping schemes to compute solutions for several PDEs.\n\n%subsection\n\\subsection{Exercises}\n\\begin{enumerate}\n\\item[1)] Let $u(x)=\\sum_k \\hat{u}_k \\exp(ikx)$ be the Fourier series representation of a function $u(x)$. Explain why \n$$\\frac{\\mathrm{d}^{\\nu}u}{\\mathrm{d}x^{\\nu}}=\\sum (ik)^{\\nu}\\hat{u}_k,$$\nprovided the series converges.\n\\item[2)] \\footnote{This question was prompted by an REU and UROP project due to Sudarshan Balakrishan which is available at \\url{http://www.math.lsa.umich.edu/undergrad/REU/projects.html}.} Consider the linear KdV equation\n$$u_t+u_{xxx}=0$$\nwith periodic boundary conditions for $x\\in(0,2\\pi]$ and the initial data\n\\begin{align*}\n&{} u(x,0)= \\left\\{{0\\quad\\textup{ if } 0< x\\leq\\pi}\\atop{1\\quad\\textup{ if } \\pi<x\\leq2\\pi }\\right.\n\\end{align*}\n\\begin{enumerate}\n\\item[a)] Using separation of variables, show that the ``solution'' is\n$$u(t,x)=\\frac{1}{2}-\\frac{2}{\\pi}\\sum_{j=0}^{\\infty}\\frac{\\sin((2j+1)x-(2j+1)^3t)}{2j+1}.$$\nQuotation marks are used because the expression for the solution that is given does not converge when differentiated either once in time or twice in space.\n\\item[b)] As explained by Olver~\\cite{Olv10}, this solution has a fractal structure at times that are an irrational multiple of $\\pi$ and a quantized structure at times that are rational multiples of $\\pi$. The Matlab program in listing \\ref{lst:DispQuant} uses the Fast Fourier transform to find a solution to the linearized KdV equation.  Explain how this program finds a solution to the linearized KdV equation.\n\\item[c)] Compare the numerical solution produced by the Matlab program with the analytical solution. Try to determine which is more accurate and see if you can find evidence or an explanation to support your suggestions.\n\\end{enumerate}\n\n\\lstinputlisting[style=matlab_style,label=lst:DispQuant,caption={A Matlab program which solves the linearized KdV equation using the Fast Fourier transform.}]{./FindingDerivatives/Programs/DispQuant.m}\n \n\\end{enumerate}\n", "meta": {"hexsha": "b9ca2a37f9f8dab56d03c2feff44e816c2fe17bf", "size": 4161, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "FindingDerivatives/FindingDerivatives.tex", "max_stars_repo_name": "bcloutier/PSNM", "max_stars_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_stars_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-01-05T14:22:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T23:51:25.000Z", "max_issues_repo_path": "FindingDerivatives/FindingDerivatives.tex", "max_issues_repo_name": "bcloutier/PSNM", "max_issues_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_issues_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-29T12:35:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-01T07:31:32.000Z", "max_forks_repo_path": "FindingDerivatives/FindingDerivatives.tex", "max_forks_repo_name": "bcloutier/PSNM", "max_forks_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_forks_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2015-01-05T14:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-09T06:55:01.000Z", "avg_line_length": 104.025, "max_line_length": 1064, "alphanum_fraction": 0.7454938717, "num_tokens": 1180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.9073122182277756, "lm_q1q2_score": 0.8244001150972403}}
{"text": "\n\\subsection{Set union and intersection}\n\nWe discuss functions. Just because we can write a function of sets which exist, does not mean the results of the functions exist. For that we need axioms discussed later.\n\n\\subsubsection{Union function}\n\nWe define a function on two sets, \\(a\\lor b\\), such that the result contains all elements from either sets.\n\n\\(\\forall a \\forall x \\forall y [a\\in (x\\lor y) \\leftrightarrow (a\\in x \\lor a\\in y)]\\)\n\nThis is commutative: \\(a\\lor b = b\\lor a\\)\n\nThis is associative: \\((a\\lor b)\\lor c = a\\lor (b\\lor c)\\)\n\n\\subsubsection{Intersection function}\n\nWe define a function, \\(a\\land b\\), on two sets, such that the result contains all elements which are in both.\n\n\\(\\forall a \\forall x \\forall y [a\\in (x\\land y) \\leftrightarrow (a\\in x \\land a\\in y)]\\)\n\nThis is commutative: \\(a\\land b = b\\land a\\)\n\nThis is associative: \\((a\\land b)\\land c = a\\lor (b\\land c)\\)\n\n\\subsubsection{Distribution of union and intersection}\n\nUnion is distributive over intersection: \\(a\\lor (b\\land c)=(a\\lor b)\\land (a\\lor c)\\)\n\nIntersection is distributive over union: \\(a\\land (b\\lor c)=(a\\land b)\\lor (a\\land c)\\)\n\n", "meta": {"hexsha": "77e646f6884acef25aa84d3e66da1e99daf4598a", "size": 1132, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/setsBasic/01-01-intersection.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/setsBasic/01-01-intersection.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/setsBasic/01-01-intersection.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.375, "max_line_length": 170, "alphanum_fraction": 0.7040636042, "num_tokens": 338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9697854138058637, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.8242896483081377}}
{"text": "\\documentclass[12pt,letterpaper]{article}\n\n\\usepackage{amsmath,amsfonts,amssymb,bbm}\n\\usepackage{palatino}\n\\usepackage[linkcolor=blue]{hyperref}\n\\usepackage{fullpage}\n\\usepackage{color}\n\\usepackage{enumitem}\n\\usepackage{titlesec}\n\\usepackage[textsize=tiny]{todonotes}\n\\usepackage{multirow}\n\n\\newcommand{\\TODO}[1]{\\todo[inline]{#1}}\n\\newcommand{\\R}{\\mathbbm{R}}\n\\newcommand{\\mba}{\\mathbf{a}}\n\\newcommand{\\mbb}{\\mathbf{b}}\n\\newcommand{\\mbx}{\\mathbf{x}}\n\\newcommand{\\mbxt}{\\tilde{\\mathbf{x}}}\n\\newcommand{\\Sigmat}{\\tilde{\\Sigma}}\n\\newcommand{\\mbz}{\\mathbf{z}}\n\\newcommand{\\mbw}{\\mathbf{w}}\n\\newcommand{\\mcN}{\\mathcal{N}}\n\\newcommand{\\mcP}{\\mathcal{P}}\n\\newcommand{\\eps}{\\epsilon}\n\\newcommand{\\trans}{\\intercal}\n\\newcommand{\\Ut}{\\tilde{U}}\n\\DeclareMathOperator*{\\argmax}{arg\\,max}\n\\newcommand{\\angstrom}{\\textup{\\AA}}\n\\newcommand{\\E}{\\mathbb{E}}\n\\newcommand{\\var}{\\mathrm{var}}\n\\newcommand{\\cov}{\\mathrm{cov}}\n\\newcommand{\\p}{\\partial}\n\n\\renewcommand{\\v}[1]{\\boldsymbol{\\mathbf{#1}}}\n\n\\begin{document}\n\n\\begin{center}\n\\LARGE{CS 182 Fall 2018 Math Review Notes}\n\\end{center}\n\n\\section{Probability Review}\n\nA {\\bf{random variable}} $X$ is a variable which could take on various values with specified probabilities (its distribution). The possible outcomes of $X$ are described through {\\bf{events}}. For instance, an event $A$ could be that $X$ takes on the value $2$, or that $X < 4$. \\\\\n\n\\noindent The probability that $A$ happens is denoted as $P(A)$. For continuous random variables $X$, the probability that $X$ attains some value $x$ is described by a function $p$, called the {\\bf{probability density function (PDF)}}. Similarly, for discrete random variables $X$, it is called the {\\bf{probability mass function (PMF)}}. We won't be too strict about only writing events as arguments to the probability function $p$; we will use $p(X)$ to mean the distribution of $X$, and $p(x)$ to mean $p(X = x)$. \\\\\n\n\\noindent Events can be constructed from other events. For instance, given two events $A$ and $B$, we may be interested in the event $C = (A \\; and \\; B)$ or $C = A \\cap B$ (the event that both events happen) or the event $D = (A \\; or \\;  B)$ or $D = A \\cup B$ (the event that either of the events happens). \\\\\n\n\\noindent Two events $A$ and $B$ are {\\bf{independent}} if the occurence of one does not influence the probability of the other. This can be expressed as $P(A \\cap B) = P(A) P(B)$. Similarly, two random variables $X$ and $Y$ are independent if $p(x, y) = p(x)p(y)$.\\\\\n\n\\noindent  The {\\bf{expected value}} (or {\\bf{expectation, mean}}) $\\E[X]$  of a random variable $X$ can be thought of as the ``weighted average'' of the possible outcomes of the random variable. It is often represented by $\\mu$. \\\\\n\n\\noindent For discrete random variables:\n\\begin{align*}\n  \\E[X] &= \\sum_{x \\in \\mathcal{X}} x \\cdot p(x) \\\\\n  \\E[f(X)] &= \\sum_{x \\in \\mathcal{X}} f(x) p(x)\n\\end{align*}\nFor continuous random variables:\n\\begin{align*}\n  \\E[X] &= \\int_{\\mathcal{X}} x \\cdot p(x) dx \\\\\n  \\E[f(X)] &= \\int_{\\mathcal{X}} f(x) p(x) dx\n\\end{align*}\n\n\\bigskip\n\n\\noindent One of the important properties of expected values is the \\textbf{linearity of expectation}. For any two random variables $X$ and $Y$, scaling coefficients $a$ and $b$, and some constant $c$, the following property of holds:\n$$\\E[aX + bY + c] = a\\E[X] + b\\E[Y] + c$$\nThis is easy to show from the definition above, and is true regardless of whether $X$ and $Y$ are dependent or independent. \\\\\n\n\\noindent The {\\bf{variance}} of a random variable is its expected squared deviation from its mean:\n$$\\var(X) = \\E[ (X - \\E[X])^2 ] = \\E[X^2] - (\\E[X])^2$$ \n\n\\noindent The {\\bf{standard deviation}} of a random variable is the square root of the variance:\n$$\\sigma(X) = \\sqrt{\\var(X)}$$\n\n\\noindent Now consider probability distributions over multiple variables. Let $X$ and $Y$ be two random variables (for instance, each can correspond to the rolls of two regular 6-sided dice). Then, the probability of an event that depends on both $X$ and $Y$ (for example, the event that $X == 1$ and $Y == 2$) will be given by a value in the {\\bf{joint probability distribution}} $p(x, y)$. \\\\\n\n\\noindent The {\\bf{marginal probability distribution}} is the probability distribution of a subset of variables from a {\\bf{joint probability distribution}}. For example, the marginal probability distribution $p(y)$ can be found by summing across all values of $x$ in $p(x, y)$:\n\\begin{align*}\np(x) = \\sum_{y \\in \\mathcal{Y}} p(x, y) \\\\\np(x) = \\int_{\\mathcal{Y}} p(x,y) dy\n\\end{align*}\n\n\\noindent When we know that an event $B$ has happened, that could influence the probability of another event $A$. The new probability of $A$ given $B$ is the {\\bf{conditional probability}} $P(A|B)$. If $B$ changes the distribution of a random variable $X$, we write the new random variable as $X|B$, and the new distribution $P(X|B)$ is the conditional distribution. \\\\\n\n\\noindent The conditional probability can be defined as:\n$$ P(A | B) = \\frac{P(A \\;\\; \\text{and} \\;\\; B)}{P(B)}$$\n\n\\noindent Note that this has some direct implications: for instance, if $A$ is the event $X == x$ and $B$ is the event $Y == y$, we have an expression relating distributions (sometimes called the {\\bf{product rule}}):\n$$ p(x | y) = \\frac{p(x, y)}{p(y)}$$\nwhich implies that\n$$ p(x, y) = p(x | y) p(y) = p(y | x) p(x)$$\n\n\\noindent Remember recursion? If there are more variables in the distribution, the above statement can be recursively extended:\n\\begin{align*}\np(x_1,...,x_n)&= p(x_1|x_2,...,x_n)p(x_2,...,x_n)\\\\\n&= ... = p(x_1|x_2,...,x_n)...p(x_{n-1}|x_n)p(x_n)\n\\end{align*}\n\n\\noindent Finally, you may have heard of {\\bf{Bayes' Theorem}} (also known as {\\bf{Bayes' Rule}} or {\\bf{Bayes' Law}}), a very prominent statement that relates conditional probabilities between events. For any two events $A$ and $B$ such that $P(B) > 0$,\n$$ P(A | B) = \\frac{P(B | A) P(A)}{P(B)} $$\nAs before, if we set events $A$ to be $X == x$ and $B$ to be $Y == y$, we get another common form of Bayes' Law:\n$$ p(x | y) = \\frac{p(y | x) p(x)}{p(y)} $$ \\\\\nIn machine learning, we are often looking for parameters $\\theta$ based on the distribution of data $y$. Then, we interpret $p(\\theta)$ as the {\\bf{prior}} (the distribution of $\\theta$ without knowing about $y$), $p(y)$ as the {\\bf{evidence}} (the overall probability of this data without considering our parameters), $p( y | \\theta)$ as the {\\bf{likelihood}} (how likely are we to collect this data given the parameters?) and $p( \\theta | y)$ as the {\\bf{posterior}} (the distribution of $\\theta$ after knowing about $y$).\n\\begin{align*}\n\\underbrace{p(\\theta | y)}_{\\text{posterior}}\n&= \\frac{\\overbrace{ p(y | \\theta) }^{\\text{likelihood}} \n\t\\overbrace{ p(\\theta) }^{\\text{prior}}}\n{\\underbrace{p(y)}_{\\text{evidence}}}\n\\end{align*}\n\n%\\begin{align*}\n%p(x | y) &= \\frac{p(y | x) p(x)}{p(y)} \\\\\n%&= \\frac{p(y | x) p(x)}{ \\int_{\\mathcal{X}} p(x,y) dx}\n%\\end{align*}\n\n%\\noindent Note that $\\E[X|Y]$ is a random variable (this is one form of $f(Y)$). Adam's law (law of iterated expectations) gives\n%\\begin{align*}\n%\\E[X]=\\E[\\E[X|Y]]\n%\\end{align*}\n%There is an analogous property for variances (Eve's Law, or law of total variance)\n%\\begin{align*}\n%\\var[X] = \\E[ \\var[X|Y] ] + \\var[ \\E[X | Y] ]\n%\\end{align*}\n\n\n\\section{Linear Algebra}\n\nWe write a {\\bf{vector}} as\n$$  \\mathbf{x} = (x_1, \\dots, x_D)^\\top $$\nwhere $D$ is the dimension of the vector, and $x_1, \\ldots, x_D$ are elements of the vector. We use column vectors by default. \\\\\n\n\\noindent We may commonly write $\\mathbf{x} \\in \\R^D$. The symbol \"$\\R$\" refers to the space of real numbers, \"$\\R^D$\" refers to the D-dimensional space of real numbers, and the symbol \"$\\in$\" means \"in\", so this is a concise way to say that $x$ is in the D-dimensional space of real numbers. \\\\\n\n\\noindent The size of a vector is measured with the vector norm. Usually, we are referring to the function:\n\\[\n||x||_2 = \\sqrt{x_1^2 + x_2^2 + \\dots + x_D^2}\n\\]\nWe call this the 2-norm or $\\L^2$-norm, and it is actually just one of many $\\L^p$ norms. You may also see the 1-norm or the infinity-norm:\n\\begin{align*}\n&||x||_1 = |x_1| + |x_2| + \\dots |x_D| \\\\\n&||x||_{\\infty} = \\max (|x_1|, |x_2|, \\dots, |x_D|)\n\\end{align*}\n\n\\noindent An $n \\times m$ {\\bf{matrix}} $\\mathbf{A}$ has $n$ rows and $m$ columns:\n\\[\n\\left(\\begin{array}{c c c c}\na_{1, 1} & a_{1, 2} & \\dots & a_{1, m} \\\\\na_{2, 1} & a_{2, 2} & \\dots & a_{2, m} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\na_{n, 1} & a_{n, 2} & \\dots & a_{n, m} \\\\\n\\end{array}\\right)\n\\]\n\n\\noindent An $n \\times m$ matrix can be thought of as a linear transformation from $\\R^n$ to $\\R^m$, and, similarly to the vectors, we write $A \\in \\R^{n \\times m}$.\n\n\n\\section{Multivariate Calculus}\n%Often we are interested in functions $f: \\mathcal{X} \\rightarrow \\mathcal{Y}$ and their derivatives to fit a model from observations.  The most salient is the objective function\n%\\begin{align*}\n%  E_D(\\mathbf{w}) &= \\sum_{n=1}^N (t_n - \\mathbf{w}^\\trans \\mathbf{x}_n)^2\n%\\end{align*}\n%This section will focus on functions from many inputs (e.g. $\\mathcal{X} = \\R^D$ for some large $D$). We will consider $\\mathcal{Y} = \\R^M$, but the case of $M=1$ will be the most common and useful.\n\nTo review mathematical notation, we may write a function $f$ as\n$$f: \\mathcal{X} \\in R^n \\to \\mathcal{Y} \\in R^m$$\nThis means that the function's {\\bf{domain}}, or set of legals inputs, is a set $\\mathcal{X}$ of real-valued $n$-dimensional vectors, and the function returns a real-valued $m$-dimensional vector in the output set (or {\\bf{range}}) $\\mathcal{Y}$. \\\\\n\n\\noindent Recall the rules for {\\bf{differentiation}} of a function with respect to one variable:\n\\begin{align*}\n\\text{Chain rule: } & \\frac{d}{d x} f(g(x))= f'(g(x))g'(x)\\\\\n\\text{Product rule: }& \\frac{d}{d x} f(x)g(x) = f'(x)g(x) + f(x)g'(x)\\\\\n\\text{Quotient rule: }& \\frac{d}{d x} \\frac{f(x)}{g(x)} = \\frac{f'(x)g(x) - f(x)g'(x)}{g(x)^2}\n\\end{align*}\n\n\\noindent When calculating partial derivatives of a function of multiple variables, we write the {\\bf{gradient vector}} as\n\\begin{align*}\n  \\nabla f(\\mathbf{x}) &= \\left( \\frac{\\p f(\\mathbf{x})}{\\p x_1}, \\dots, \\frac{\\p f(\\mathbf{x})}{\\p x_D} \\right)^\\top\n\\end{align*}\nSometimes we only wish to differentiate with respect to some variables in the input. For example, $f(\\mathbf{x},\\alpha)$, then the derivative with respect to $\\mathbf{x}$ is denoted\n\\begin{align*}\n  \\nabla_{\\mathbf{x}} f(\\mathbf{x},\\alpha) = \\frac{d f(\\mathbf{x},\\alpha)}{d \\mathbf{x}} = \\left( \\frac{\\p f(\\mathbf{x},\\alpha)}{\\p x_1}, \\dots, \\frac{\\p f(\\mathbf{x},\\alpha)}{\\p x_D} \\right)^\\top\n\\end{align*}\nThe gradient vector points towards the direction of greatest ascent in $f(\\mathbf{x})$ with respect to the parameters being differentiated. \\\\\n\n\\noindent If the function we are interested in has multiple outputs (it maps a vector $[x_1, \\dots, x_m]$ to a vector $[f_1, \\dots, f_n]$), we can generalize the gradient vector to the {\\bf{Jacobian matrix}}:\n\\begin{align*}\n\\frac{d \\mathbf{f}(\\mathbf{x})}{d \\mathbf{x}} = \\begin{bmatrix}\n\\frac{\\p f_1(\\mathbf{x})}{\\p x_1} & \\cdots & \\frac{\\p f_1(\\mathbf{x})}{\\p x_m} \\\\\n\\vdots & \\ddots & \\vdots \\\\\n\\frac{\\p f_n(\\mathbf{x})}{\\p x_1} & \\cdots & \\frac{\\p f_n(\\mathbf{x})}{\\p x_m}\n\\end{bmatrix}\n\\end{align*}\n\n\\noindent For a function that has a single output $f(\\mathbf{x})$, the {\\bf{Hessian matrix}} is the generalization of the second derivative:\n\\begin{align*}\nH(f(\\mathbf{x}))=\\begin{bmatrix}\n\\frac{\\p^2 f(\\mathbf{x})}{\\p x_1^2} & \\frac{\\p^2 f(\\mathbf{x})}{\\p x_1 \\p x_2} & \\cdots &  \\frac{\\p^2 f(\\mathbf{x})}{\\p x_1 \\p x_n}\\\\\n\\frac{\\p^2 f(\\mathbf{x})}{\\p x_2 \\p x_1} & \\frac{\\p^2 f(\\mathbf{x})}{\\p x_2^2} & \\cdots & \\frac{\\p^2 f(\\mathbf{x})}{\\p x_1 \\p x_n}\\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\\frac{\\p^2 f(\\mathbf{x})}{\\p x_n \\p x_1} & \\frac{\\p^2 f(\\mathbf{x})}{\\p x_n \\p x_2} & \\cdots & \\frac{\\p^2 f(\\mathbf{x})}{\\p x_n^2}\\\\\n\\end{bmatrix}\n\\end{align*}\n\n\\noindent To find the local minima (or maxima) of a function $f(\\mathbf{x})$, we can set the gradient equal to zero: $\\nabla f(\\mathbf{x})=0$. However, we may not always be able to find a closed-form solution. {\\bf{Gradient descent}} is a numerical way to solve this problem. We start with an initial guess $\\mathbf{x}_0$, and iteratively take small steps in the direction of greatest descent until we reach a point where the gradient is close to zero. Since this direction is exactly opposite the direction of the gradient vector, the \"update\" of our guess at each iteration is\n\\begin{align*}\n\\mathbf{x}_{i+1} = \\mathbf{x}_i - \\gamma \\nabla f(\\mathbf{x}_i)\n\\end{align*}\nwhere $\\gamma$ determines our step size. This algorithm forms the basis for much of optimization -- many of the common algorithms used within machine learning and other fields are variants and extensions of gradient descent. \\\\\n\n%This matrix is symmetric and we can diagonalize it to find its eigenvalues. If all eigenvalues are positive, then we are at a local minimum. If all eigenvalues are negative, then we are at a local maximum. If there is a mix of positive and negative eigenvalues, then we are at a saddle point. If there are zero-eigenvalues, then there are directions in which $f(\\mathbf{w})$ has no second order change. Besides allowing us to deduce the nature of turning points, the inverse of the Hessian matrix can also be used to aid gradient descent by using the update rule\n%\\begin{align*}\n%\\mathbf{x}_{i+1} = \\mathbf{x}_i - [H(f(\\mathbf{x}))]^{-1} \\nabla f(\\mathbf{x}_i)\n%\\end{align*}\n\n%While we will not dive into optimization in this class, some of these concepts may be mentioned.\n\n\n%A single output function $f(\\mathbf{x})$ is convex if it satisfies Jensen's inequality\n%\\begin{align*}\n%f\\left( \\sum_{n=1}^N a_n \\mathbf{x}_n\\right) \\leq  \\sum_{n=1}^N a_n f\\left( \\mathbf{x}_n\\right)\n%\\end{align*}\n%for all $\\mathbf{x}_n\\in \\mathcal{X}$ and $\\sum_{n=1}^N a_n=1$. Similarly, $f(\\mathbf{x})$ is concave if the sign of the inequality is flipped. $f(\\mathbf{x})$ is called strongly convex/concave if the inequalities are converted to strict inequalities. \\\\\n%Strongly convex and concave functions have the benefit of having global minimums and maximums respectively, and so are easy to do gradient descent on.\n\n\\end{document}", "meta": {"hexsha": "c05c822ba943f985f5d05ef7664b5be6da0c175d", "size": 14218, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Section_01/tex/math_review.tex", "max_stars_repo_name": "Harvard-CS182-F18/courseware", "max_stars_repo_head_hexsha": "b1c5cc83dd45091c0ab74e0252405bc79ce51718", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Section_01/tex/math_review.tex", "max_issues_repo_name": "Harvard-CS182-F18/courseware", "max_issues_repo_head_hexsha": "b1c5cc83dd45091c0ab74e0252405bc79ce51718", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Section_01/tex/math_review.tex", "max_forks_repo_name": "Harvard-CS182-F18/courseware", "max_forks_repo_head_hexsha": "b1c5cc83dd45091c0ab74e0252405bc79ce51718", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.6343612335, "max_line_length": 578, "alphanum_fraction": 0.6759741173, "num_tokens": 4706, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.9032942034496964, "lm_q1q2_score": 0.8241982969275506}}
{"text": "\\newpage\t\t\r\n\t\\section*{}\r\n\t\\textbf{Task}\\\\\r\n\tLet $f_n$ be the Fibonacci sequence. Prove that\r\n\t\\begin{gather*}\r\n\t\tf_{n-1} f_{n+1}-f_{n}^{2}=(-1)^{n}\r\n\t\\end{gather*}\r\n\t\\\\\r\n\t\\textbf{Solution}\\\\\r\n\tBinet's formula:\r\n\t\\begin{gather*}\r\n\t\tf_{n} = \r\n\t\t\\frac\r\n\t\t{\\left(\\frac{1+\\sqrt{5}}{2}\\right)^{n} - \\left(\\frac{1-\\sqrt{5}}{2}\\right)^{n}}\r\n\t\t{\\sqrt{5}}\r\n\t\\end{gather*}\r\n\tThen\r\n\t\\begin{gather*}\r\n\t\tf_{n-1} f_{n+1}-f_{n}^{2} = \r\n\t\t\\\\\r\n\t\t\\\\\r\n\t\t\\frac{\\left(\\frac{1+\\sqrt{5}}{2}\\right)^{n-1} - \\left(\\frac{1-\\sqrt{5}}{2}\\right)^{n-1}}{\\sqrt{5}} \r\n\t\t\\cdot\r\n\t\t\\frac{\\left(\\frac{1+\\sqrt{5}}{2}\\right)^{n+1} - \\left(\\frac{1-\\sqrt{5}}{2}\\right)^{n+1}}{\\sqrt{5}} \r\n\t\t-\r\n\t\t\\left(\\frac{\\left(\\frac{1+\\sqrt{5}}{2}\\right)^{n} - \\left(\\frac{1-\\sqrt{5}}{2}\\right)^{n}}{\\sqrt{5}}\\right)^2 = \r\n\t\t\\\\\r\n\t\t\\\\\r\n\t\t\\frac{1}{5}\r\n\t\t\\left(\r\n\t\t\t\\left(\r\n\t\t\t\t\\left(\\frac{1+\\sqrt{5}}{2}\\right)^{n-1} - \\left(\\frac{1-\\sqrt{5}}{2}\\right)^{n-1}\r\n\t\t\t\\right) \r\n\t\t\t\\cdot\r\n\t\t\t\\left(\r\n\t\t\t\t\\left(\\frac{1+\\sqrt{5}}{2}\\right)^{n+1} - \\left(\\frac{1-\\sqrt{5}}{2}\\right)^{n+1}\r\n\t\t\t\\right)\r\n\t\t\t-\r\n\t\t\t\\left(\r\n\t\t\t\t\\left(\\frac{1+\\sqrt{5}}{2}\\right)^{n} - \\left(\\frac{1-\\sqrt{5}}{2}\\right)^{n}\r\n\t\t\t\\right)^2\r\n\t\t\\right) = \r\n\t\t\\\\\r\n\t\t\\\\\r\n\t\t\\frac{1}{2^{2n} \\cdot 5}\r\n\t\t\\left(\r\n\t\t\t\\left(\r\n\t\t\t\t(1+\\sqrt{5})^{n-1} - (1-\\sqrt{5})^{n-1}\r\n\t\t\t\\right)\r\n\t\t\t\\cdot\r\n\t\t\t\\left(\r\n\t\t\t\t(1+\\sqrt{5})^{n+1} - (1-\\sqrt{5})^{n+1}\r\n\t\t\t\\right)\r\n\t\t\t-\r\n\t\t\t\\left(\r\n\t\t\t\t(1+\\sqrt{5})^{n} - (1-\\sqrt{5})^{n}\r\n\t\t\t\\right)^2\r\n\t\t\\right) = \r\n\t\t\\\\\r\n\t\t\\\\\r\n\t\t\\frac{1}{2^{2n} \\cdot 5}\r\n\t\t\\Big(\r\n\t\t\t\\left(\r\n\t\t\t\t(1+\\sqrt{5})^{2n} + (1-\\sqrt{5})^{2n} - (1+\\sqrt{5})^{n-1}(1-\\sqrt{5})^{n+1} - (1+\\sqrt{5})^{n+1}(1-\\sqrt{5})^{n-1}\r\n\t\t\t\\right)\r\n\t\t\t-\\\\\r\n\t\t\t\\left(\r\n\t\t\t\t(1+\\sqrt{5})^{2n} + (1-\\sqrt{5})^{2n} - 2(1+\\sqrt{5})^{n}(1-\\sqrt{5})^{n}\r\n\t\t\t\\right)\r\n\t\t\\Big) = \r\n\t\t\\\\\t\r\n\t\t\\\\\r\n\t\t\\frac{1}{2^{2n} \\cdot 5}\r\n\t\t\\Big(\r\n\t\t\t(1+\\sqrt{5})^{2n}\r\n\t\t\t+ (1-\\sqrt{5})^{2n}\r\n\t\t\t- (1+\\sqrt{5})^{n-1}(1-\\sqrt{5})^{n+1}\\\\\r\n\t\t\t- (1+\\sqrt{5})^{n+1}(1-\\sqrt{5})^{n-1}\r\n\t\t\t- (1+\\sqrt{5})^{2n}\r\n\t\t\t- (1-\\sqrt{5})^{2n}\r\n\t\t\t+ 2(1+\\sqrt{5})^{n}(1-\\sqrt{5})^{n}\r\n\t\t\\Big) = \r\n\t\t\\\\\t\r\n\t\t\\\\\r\n\t\t\\frac{1}{2^{2n} \\cdot 5}\r\n\t\t\\Big(\r\n\t\t\t2(1+\\sqrt{5})^{n}(1-\\sqrt{5})^{n}\r\n\t\t\t- (1+\\sqrt{5})^{n-1}(1-\\sqrt{5})^{n+1}\r\n\t\t\t- (1+\\sqrt{5})^{n+1}(1-\\sqrt{5})^{n-1}\r\n\t\t\\Big) = \r\n\t\t\\\\\t\r\n\t\t\\\\\r\n\t\t\\frac{(1 - 5)^{n-1}}{2^{2n} \\cdot 5}\r\n\t\t\\Big(\r\n\t\t\t2 (1-\\sqrt{5})(1+\\sqrt{5})\r\n\t\t\t- (1-\\sqrt{5})^{2}\r\n\t\t\t- (1+\\sqrt{5})^{2}\r\n\t\t\\Big) =\r\n\t\t\\\\\t\r\n\t\t\\\\\r\n\t\t\\frac{(-4)^{n-1}}{4^{n} \\cdot 5}\r\n\t\t\\Big(\r\n\t\t\t2 (1-\\sqrt{5})(1+\\sqrt{5})\r\n\t\t\t- (6 - 2\\sqrt{5})\r\n\t\t\t- (6 + 2\\sqrt{5})\r\n\t\t\\Big) =  \r\n\t\t\\\\\t\r\n\t\t\\\\\r\n\t\t\\frac{(-4)^{n-1}}{4^{n} \\cdot 5}\r\n\t\t\\Big(\r\n\t\t\t-8\r\n\t\t\t- 6\r\n\t\t\t- 6\r\n\t\t\\Big) =\r\n\t\t\\\\\r\n\t\t\\\\\r\n\t\t\\frac{(-4)^{n-1}}{4^{n} \\cdot 5} (-20) = \r\n\t\t(-1)^{n} \r\n\t\\end{gather*}", "meta": {"hexsha": "8acef5f763e43155037e55f9d3e7ec8f5e12b72d", "size": 2704, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/1st term/Discrete Math/Spr_Mid/Body/P4.tex", "max_stars_repo_name": "Vladm0z/github.io", "max_stars_repo_head_hexsha": "e4ca87ac40286659eeb9b75493e6e73398cf1dec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/1st term/Discrete Math/Spr_Mid/Body/P4.tex", "max_issues_repo_name": "Vladm0z/github.io", "max_issues_repo_head_hexsha": "e4ca87ac40286659eeb9b75493e6e73398cf1dec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/1st term/Discrete Math/Spr_Mid/Body/P4.tex", "max_forks_repo_name": "Vladm0z/github.io", "max_forks_repo_head_hexsha": "e4ca87ac40286659eeb9b75493e6e73398cf1dec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.7226890756, "max_line_length": 120, "alphanum_fraction": 0.4056952663, "num_tokens": 1475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741241296944, "lm_q2_score": 0.8652240964782011, "lm_q1q2_score": 0.8241900858786286}}
{"text": "\n\\subsection{Line integral of vector fields}\n\nWe may wish to integrate along a curve in a vector field.\n\nWe previously showed that we can write a curve as a function on the real line:\n\n\\(r:[a,b]\\rightarrow C\\)\n\nThe integral is therefore the sum of the function at all points, with some weighting. We write this:\n\n\\(\\int_C f(r) ds=\\lim_{\\Delta s rightarrow 0 }\\sum_{i=0}^n f(r(t_i))\\Delta s_i\\)\n\nIn a vector field we use\n\n\\(\\int_C f(r) ds =\\int_a^b f(r(t)).r'(t) dt\\)\n\n", "meta": {"hexsha": "17cf16c905bf358bcac98ac4893a306b05c0ebcb", "size": 468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/multiCalculusIntegration/01-01-lineIntegralVector.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/multiCalculusIntegration/01-01-lineIntegralVector.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/multiCalculusIntegration/01-01-lineIntegralVector.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0, "max_line_length": 100, "alphanum_fraction": 0.7008547009, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966747198242, "lm_q2_score": 0.870597270087091, "lm_q1q2_score": 0.824104480884597}}
{"text": "% based on example 8 in pythontex_gallery\n% https://github.com/gpoore/pythontex/\n\n\\documentclass[12pt]{pylatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Step-by-step integration}\n\nThis is another nice example drawn from the Pythontex gallery, see\n\\ \\url{https://github.com/gpoore/pythontex}.\n\nIt shows the step-by-step computations of a simple triple integral.\n\n\\begin{python}\n   from sympy import *\n\n   x, y, z = symbols('x,y,z')\n   f = Symbol('f(x,y,z)')\n\n   # Define limits of integration\n   x_max = 2;   y_max = 3;   z_max = 4;\n   x_min = 0;   y_min = 0;   z_min = 0;\n\n   lhs = Integral(f, (x, x_min, x_max),\n                     (y, y_min, y_max),\n                     (z, z_min, z_max))                   # py(lhs.01,lhs)\n\n   f = x*y + y*sin(z) + cos(x+y)\n\n   rhs = Integral(f, (x, x_min, x_max),\n                     (y, y_min, y_max),\n                     (z, z_min, z_max))                   # py(rhs.01,rhs)\n   rhs = Integral(Integral(f, (x, x_min, x_max)).doit(),\n                              (y, y_min, y_max),\n                              (z, z_min, z_max))          # py(rhs.02,rhs)\n   rhs = Integral(Integral(f, (x, x_min, x_max),\n                              (y, y_min, y_max)).doit(),\n                              (z, z_min, z_max))          # py(rhs.03,rhs)\n   rhs = Integral(f, (x, x_min, x_max),\n                     (y, y_min, y_max),\n                     (z, z_min, z_max)).doit()            # py(rhs.04,rhs)\n\n   # And now, a numerical approximation\n   rhs = N(rhs)                                           # py(rhs.05,rhs)\n\n\\end{python}\n\n\\begin{minipage}[t]{0.65\\textwidth}\n\\begin{align*}\n   \\py{lhs.01} &= \\py{rhs.01}\\\\\n               &= \\py{rhs.02}\\\\\n               &= \\py{rhs.03}\\\\\n               &= \\py{rhs.04}\\\\[8pt]\n               &\\approx \\py{rhs.05}\n\\end{align*}\n\\end{minipage}\n\\hskip 1cm\n\\lower16pt\\hbox{%\n\\begin{minipage}[t]{0.35\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      \\py{lhs.01} &= \\py{rhs.01}\\\\\n                  &= \\py{rhs.02}\\\\\n                  &= \\py{rhs.03}\\\\\n                  &= \\py{rhs.04}\\\\[8pt]\n                  &\\approx \\py{rhs.05}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}}\n\n\\end{document}\n", "meta": {"hexsha": "abb9863d099dcd0aeb14cbdbdac6edff0523e583", "size": 2165, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "python/examples/example-03.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "python/examples/example-03.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "python/examples/example-03.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 29.2567567568, "max_line_length": 74, "alphanum_fraction": 0.4766743649, "num_tokens": 688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582574225517, "lm_q2_score": 0.8856314798554444, "lm_q1q2_score": 0.8240431234648525}}
{"text": "\\section{Algebra}\nAbsolute Value Inequalities:\\\\\n$ |f(x)| < a  \\Rightarrow  -a < f(x) < a$\\\\ \n$|f(x)| > a  \\Rightarrow f(x) > a$ or $f(x) < -a$\\\\\n\\section{Matrixalgebra}\n\n$\\displaystyle  \\displaystyle \\left\\lVert \\mathbf{A}\\mathbf{x}\\right\\rVert ^2 = \\displaystyle (\\mathbf{A}\\mathbf{x})^ T(\\mathbf{A}\\mathbf{x})\\, =\\, \\mathbf{x}^ T\\mathbf{A}^ T\\mathbf{A}\\mathbf{x} = \\displaystyle \\mathbf{x}^ T\\mathbf{A}^ T\\mathbf{A}\\mathbf{x}\\qquad$\n\n\\section{Calculus}\n\nDifferentiation under the integral sign\\\\\n$\\frac{\\text{d}}{\\text{d}x}\\left( \\int_{a(x)}^{b(x)}f(x,t)\\text{d}t \\right ) = f(x,b(x))b'(x)-f(x,a(x))a'(x)+\\int_{a(x)}^{b(x)}f_x(x,t)\\text{d}t.$\n\n\\subsection*{Concavity in 1 dimension}\nIf $g:I \\to \\mathbb {R}$ is twice differentiable in the interval $I$:\n\nconcave:\\\\ \nif and only if $g^{\\prime \\prime }(x) {\\color{blue}{\\leq }}  0$ for all $x \\in I$\\\\\n\nstrictly concave:\\\\\nif $g^{\\prime \\prime }(x) {\\color{blue}{<}}  0$ for all $x \\in I$\\\\\n\nconvex:\\\\ \nif and only if $g^{\\prime \\prime }(x) {\\color{blue}{\\geq }}  0$ for all $x \\in I$\\\\\n\nstrictly convex if:\\\\\n$g^{\\prime \\prime }(x) {\\color{blue}{>}}  0$ for all $x \\in I$\\\\\n\n\\subsection*{Multivariate Calculus}\nThe Gradient $\\nabla$ of a twice differntiable function $f$ is defined as:\n\n$\\nabla f:\\mathbb {R}^ d \\rightarrow \\mathbb {R}^ d $\\\\\n$\\displaystyle \\theta =\\begin{pmatrix} \\theta _1\\\\ \\theta _2\\\\ \\vdots \\\\ \\theta _ d\\end{pmatrix} \\displaystyle \\mapsto \\displaystyle \\left.\\begin{pmatrix}  \\frac{\\partial f }{\\partial \\theta _1}\\\\ \\frac{\\partial f }{\\partial \\theta _2}\\\\ \\vdots \\\\ \\frac{\\partial f }{\\partial \\theta _ d}\\end{pmatrix}\\right|_{\\theta }$\\\\\n\\textbf{Hessian}\\\\\n\nThe Hessian of $f$ is a symmetric matrix of second partial derivatives of $f$\\\\\n\n$\\mathbf{H} h(\\theta )= \\nabla ^{2} h(\\theta )= \\\\\n\\left(\\begin{array}{ c c c }\n\\frac{\\partial ^{2} h}{\\partial \\theta _{1} \\partial \\theta _{1}} (\\theta ) & \\cdots  & \\frac{\\partial ^{2} h}{\\partial \\theta _{1} \\partial \\theta _{d}} (\\theta )\\\\\n & \\vdots  & \\\\\n\\frac{\\partial ^{2} h}{\\partial \\theta _{d} \\partial \\theta _{1}} (\\theta ) & \\cdots  & \\frac{\\partial ^{2} h}{\\partial \\theta _{d} \\partial \\theta _{d}} (\\theta )\n\\end{array}\\right) \\in \\mathbb{R}^{d\\times d}$\\\\\n\nA symmetric (real-valued) $d\\times d$  matrix $\\mathbf{A}$ is:\\\\\n\nPositive semi-definite:\\\\\n$\\mathbf{x}^ T \\, \\mathbf{A}\\, \\mathbf{x} \\geq 0\\qquad \\text {for all }\\,  \\mathbf{x}\\in \\mathbb {R}^ d.$\\\\\n\nPositive definite:\\\\\n$\\mathbf{x}^ T \\, \\mathbf{A}\\, \\mathbf{x}> 0$ for all non-zero vectors $\\mathbf{x}\\in \\mathbb {R}^ d$\\\\\n\nNegative semi-definite (resp. negative definite):\\\\\n\n$\\mathbf{x}^ T \\, \\mathbf{A}\\, \\mathbf{x}$ is negative for all $\\mathbf{x}\\in \\mathbb {R}^ d-\\{ \\mathbf{0}\\}$.\\\\\n\nPositive (or negative) definiteness implies positive (or negative) semi-definiteness.\\\\\n\nIf the Hessian is positive definite then $f$ attains a local minimum at $a$ (convex).\\\\\n\nIf the Hessian is negative definite at $a$, then f attains a local maximum at $a$ (concave).\\\\\n\nIf the Hessian has both positive and negative eigenvalues then $a$ is a saddle point for $f$.\n\n%\\subsection*{Lagrange Multiplier}", "meta": {"hexsha": "c1f0c3db077d43d1bfe006af94c88dd35fcb8335", "size": 3090, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/algebra.tex", "max_stars_repo_name": "kpsunkara/MITx_capstone_2", "max_stars_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2019-04-24T02:24:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T10:26:41.000Z", "max_issues_repo_path": "content/algebra.tex", "max_issues_repo_name": "kpsunkara/MITx_capstone_2", "max_issues_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-07T20:24:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-06T08:24:47.000Z", "max_forks_repo_path": "content/algebra.tex", "max_forks_repo_name": "kpsunkara/MITx_capstone_2", "max_forks_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2019-03-11T14:20:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T16:31:34.000Z", "avg_line_length": 47.5384615385, "max_line_length": 320, "alphanum_fraction": 0.6323624595, "num_tokens": 1166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222395, "lm_q2_score": 0.8774767778695834, "lm_q1q2_score": 0.8239724696395301}}
{"text": "% !TeX root = ../solution.tex\n\n\\hypertarget{he22.31}{%\n\\chapter{[HE22.31] Casino}\\label{he22.31}}\n\n\\begin{marginfigure}\n\t\\includegraphics[width=49mm]{level7/challenge31.jpg}\n\\end{marginfigure}\n\\section{Intro}\nWanna try your luck in our new casino?\n\n\\noindent To prove we're not cheating, we are publishing our source code.\n\n\\noindent Connect to the server and start gamblin'!\n\n\\noindent \\verb+nc 46.101.107.117 2212+\n\n\\noindent Note: The service is restarted every hour at x:00.\n\n\\noindent File: \\verb+server.sage+\n\\subsection{Hint}\nThe casino is run by the NSA and they have made sure that they can always win.\n\n\\noindent P and Q are related somehow.\n\n\\section{Solution}\\label{hv22.31solution}\n\nThe file given shows the casino code that makes use of an elliptic curve pseudo random number generator to ``roll the dice''.  When these generators were standardized by NIST, some flaws were identified quickly -- namely that if the two constants $P$ and $Q$ are related, then the internal state of the rng can be obtained from observing a series of outputs.   There is ample literature on the topic, \\emph{e.g.} \\href{http://bugcharmer.blogspot.com/2014/03/how-dual-ec-drbg-backdoor-works.html}{How the Dual EC DRBG Backdoor Works}.  The crucial part of the code is\n\n\\begin{fullwidth}\n{\\tiny\n\\begin{minted}{python}\nclass RNG:\n    def __init__(self):\n        p = 115792089210356248762697446949407573530086143415290314195533631308867097853951\n        b = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b\n        self.curve = EllipticCurve(GF(p), [-3,b])\n\n        self.P = self.curve.lift_x(15957832354939571418537618117378383777560216674381177964707415375932803624163)\n        self.Q = self.curve.lift_x(66579344068745538488594410918533596972988648549966873409328261501470196728491)\n        \n        self.state = randint(1, 2**256)\n        \n    def next(self):\n        r = (self.state * self.P)[0].lift()\n        self.state = (r * self.P)[0].lift()\n        return (r * self.Q)[0].lift() >> 8\n\\end{minted}\n}\n\\end{fullwidth}\n\n\\noindent The rng is standard, except that even more of the result $R\\times Q$ is leaked than in the NIST proposal.  The first step is to find if $P$ and $Q$ are related; a simple brute forcing finds that $P = 1337 Q$ and from this it follows that given the result $R Q$ (the output of the rng), $R P$ can be calculated as $1337 R Q$, which is almost the internal state of the rng.\n\nEntering the casino, we are greeted with a friendly message that gives us the first $R Q$ shifted right by eight bits\n{\\small\n\\begin{minted}{python}\n class Casino:\n    def __init__(self, rng):\n        self.rng = rng\n        self.balance = 10\n\n    def play(self):\n        print(\"Your bet: \", end='')\n        bet = input()\n        if (bet in [\"0\", \"1\"]):\n            bet = Integer(bet)\n            if (self.rng.next() % 2 == bet):\n                self.balance += 1\n            else:\n                self.balance -= 1\n                if (self.balance == 0):\n                    print(\"You are broke... play again\")\n                    exit()\n            print(f\"Your current balance: {self.balance}\")\n        else:\n            print(\"Invalid bet option, use either 0 or 1\")\n            \n    def buy_flag(self):\n        if (self.balance >= 1337):\n           print(\"here is your flag!\")\n            exit(0)\n        else:\n            print(\"No flag for the poor. Gamble more\")\n\ndef main():\n    rng = RNG()\n    casino = Casino(rng)\n\n    print(\"Welcome to the Casino\")\n    print(f\"Your id is {rng.next()}\")\n    print(\"What would you like to do?\")\n    print(\"(p)lay and win some money\")\n    print(\"(b)uy the flag\")\n\n    while (True):\n        print(\"> \", end='')\n        option = input()\n\n        if (not option in [\"b\", \"p\"]):\n            print(\"Unknown option, use 'b' or 'p'\")\n        elif (option == \"b\"):\n            casino.buy_flag()\n        elif (option == \"p\"):\n            casino.play()\n\\end{minted}\n}\n\nFrom the true value $R Q$, only eight bits have been destroyed and so we can build up a collection of 256 possible $R Q$, calculate $R P$ and derive the internal state for the corresponding rng.  Then start betting and observe which rngs predict the outcome correctly until only one rng is left.  Now we have the state identified correctly and can predict the outcome of all future rolls.  Start betting until we have enough money to buy the flag.  To decrypt the flag we have again to know the rng, but this is straigtforward and can be implemented in sage:\n\n{\\small\n\\begin{minted}{python}\ndef build_candidates(r):\n    rng = RNG()\n    e = 1337\n    candidates = []\n    for i in range(256):\n        try:\n            qr = rng.curve.lift_x(r + i)\n            pr = (qr*e)[0].lift()\n            candidates.append(RNG(pr))\n        except ValueError:\n            pass\n\n    return candidates\n\ndef purge(rngs, bit):\n    retVal = []\n    for r in rngs:\n        if r.next() % 2 == bit:\n            retVal.append(r)\n    return retVal\n\ndef play(io, bit, money):\n    io.read_until(b'> ')\n    io.write(b'p\\n')\n    io.write(str(bit).encode('ascii')+b'\\n')\n    \n    io.read_until(b'balance: ')\n    m = int(io.read_until(b'\\n'))\n    if m > money:\n        return bit, m\n    else:\n        if bit == 1:\n            return 0, m\n        else:\n            return 1, m\n\ndef buy_flag(io, rng):\n    io.read_until(b'> ')\n    io.write(b'b\\n')\n    flag_enc = io.read_until(b'\\n')[:-1].decode('ascii')\n    print(flag_enc)\n    key = SHA256.new(str(rng.next()).encode('ascii')).digest()\n    cipher = AES.new(key, AES.MODE_ECB)\n    flag = cipher.decrypt(bytes.fromhex(flag_enc))\n    print(\"here is your flag!\")\n    if ord(flag[-1:]) < 16:\n        flag = flag[:-ord(flag[-1:])]\n    print(f'{flag}')\n\n\ndef solve():\n    with Telnet(\"46.101.107.117\",\"2212\") as io:\n        io.read_until(b'Your id is')\n        r = Integer(io.read_until(b'\\n')) * 256\n        candidates = build_candidates(r)\n\n        money = 10\n        while len(candidates) > 1:\n            print(len(candidates))\n            bit, money = play(io, 1, money)\n            candidates = purge(candidates, bit)\n\n        print('now the state is known')\n\n        rng = candidates[0]\n        while money < 1337:\n            bit = rng.next() % 2\n            bit2, money = play(io, bit, money)\n            assert(bit == bit2)\n            if money % 100 == 0:\n                print(money)\n        print(money)\n        buy_flag(io, rng)\n\nif __name__ == '__main__':\n    solve()\n\\end{minted}\n}\n\nCompared to the server code, the only difference is that the RNG can be instantiated with an explicit state, not a random state.  Then the script runs to completion and prints the flag.\n\n\\noindent\\verb+he2022{C4S1N0_B4CKD00R_ST0NK5}+.\n", "meta": {"hexsha": "7aad362fcf4e1f0a7fc19f2a02a37e812603f5a2", "size": 6666, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HackyEaster/he2022/level7/ch31.tex", "max_stars_repo_name": "tbrup/ctf-writeups", "max_stars_repo_head_hexsha": "dfac11abb3051af657ed3384c3c389c14a40c10e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HackyEaster/he2022/level7/ch31.tex", "max_issues_repo_name": "tbrup/ctf-writeups", "max_issues_repo_head_hexsha": "dfac11abb3051af657ed3384c3c389c14a40c10e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HackyEaster/he2022/level7/ch31.tex", "max_forks_repo_name": "tbrup/ctf-writeups", "max_forks_repo_head_hexsha": "dfac11abb3051af657ed3384c3c389c14a40c10e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.3608247423, "max_line_length": 566, "alphanum_fraction": 0.6215121512, "num_tokens": 1817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954105, "lm_q2_score": 0.8791467580102418, "lm_q1q2_score": 0.8239458257504745}}
{"text": "\n\\subsection{Writing first-order logic}\n\n\\subsubsection{Existential quantifier}\n\nWe introduce a shorthand for \u201cat least one term satisfies a predicate\u201d, that is:\n\n\\(P(x_0)\\lor P(x_1)\\lor P(x_2)\\lor P(x_2)\\lor P(x_3)...\\)\n\nThe short hand is:\n\n\\(\\exists x P(x)\\)\n\n\\subsubsection{niversal quantifier}\n\nWe introduce another shorthand, this time for:\n\n\\(P(x_0)\\land P(x_1)\\land P(x_2)\\land P(x_2)\\land P(x_3)...\\)\n\nThe shorthand is\n\n\\(\\forall x P(x)\\)\n\n\\subsubsection{Free and bound variables}\n\nA bound variable is one which is quantified in the formula. A free variable is one which is not. Consider:\n\n\\(\\forall x P(x,y)\\)\n\nIn this, \\(x\\) is bound while \\(y\\) is free.\n\nFree variables can be interpreted differently, while bound variables cannot.\n\nWe can also bind a specific variable to a value. For example \\(0\\) can be defined to be bound.\n\n\\subsubsection{Ground terms}\n\nA ground term does not contain any free variables. A ground formula is one which only includes ground terms.\n\n\\(\\forall x\\ x\\) is a ground term.\n\n\\(\\forall x P(x)\\) is a ground formula.\n\n", "meta": {"hexsha": "3bba20cc0702915ccb7afa3ea83e6f5d5c66bafc", "size": 1057, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/preteriteLogic/02-01-firstWriting.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/preteriteLogic/02-01-firstWriting.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/preteriteLogic/02-01-firstWriting.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0227272727, "max_line_length": 108, "alphanum_fraction": 0.7180700095, "num_tokens": 286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731126558705, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.8239048858513329}}
{"text": "\\input{../header.tex}\n\\title{\\vspace{-2cm}INF3490/INF4490 Exercise Solutions - Simple search algorithms}\n\\author{Ole Herman S. Elgesem\\input{../author_footnote.tex}}\n\\date{}\n\n% Removing paragraph indents is sometimes useful:\n\\setlength\\parindent{0pt}\n% ==============================================================================\n\n% ================================= DOCUMENT ===================================\n\\begin{document}\n    \\renewcommand\\marginsymbol[1][0pt]{%\n  \\tabto*{0cm}\\makebox[-1cm][c]{$\\mathbb{P}$}\\tabto*{\\TabPrevPos}}\n\n\\maketitle\n\\input{../intro.tex}\n\n\\section{Simple search algorithms}\n\nGiven the function \\(f(x) = -x^4 + 2x^3 + 2x^2 - x\\):\n\n\\subsection{Derivative}\nWhat is its derivative \\(f'(x)\\) ?\\\\\n\n\\textit{Answer:}\n\\[f'(x) = -4x^3 + 6x^2 + 4x - 1\\]\n\n\\subsection{Plotting \\marginsymbol}\nPlot the function, and its gradient(derivative) from \\(x=-2\\) to \\(x=3\\).\nUse python, wolfram alpha or another plotting tool of your choice.\\\\\n\n\\textit{Plot:}\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{eps/w1e1b.eps}\n\\caption{\\(f(x)\\) and it's derivative.}\n\\label{fig:w1e1b}\n\\end{center}\n\\end{figure}\n\n\\textit{Source code (Python 3):}\n\\inputminted{Python}{py/w1e1b.py}\n\n\\subsection{Gradient Ascent \\marginsymbol}\n\\label{subsec:grada}\nMaximize using gradient ascent.\nYou can try step size 0.1 and start somewhere in the range [-2, 3].\nHow does the choice of starting point and step size affect the algorithm's performance?\nIs there a starting point where the algorithm would not even be able to find a local maximum?\\\\\n\n\\textit{Answer:}\n\nBoth starting position and step size affects where the algorithm ends:\n\\begin{itemize}\n    \\item Starting Position\n    \\begin{itemize}\n        \\item \\textit{Left side:} Should converge on left maximum\n        \\item \\textit{Center:} Stops immediately, gradient is zero.\n        \\item \\textit{Right side:} Should converge on right maximum\n    \\end{itemize}\n    \\item Step Size\n    \\begin{itemize}\n        \\item \\textit{Too low:} Converges slowly (poor performance)\n        \\item \\textit{Too high:} Overshoot, bounce over solutions. Doesn't converge, might not terminate.\n    \\end{itemize}\n\\end{itemize}\n\n\\textit{Plot:}\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{eps/w1e1c.eps}\n\\caption{Result of gradient ascent}\n\\label{fig:w1e1c}\n\\end{center}\n\\end{figure}\n\n\\textit{Source code (Python 3):}\n\\inputminted{Python}{py/w1e1c.py}\n\n\\subsection{Exhaustive Search \\marginsymbol}\n\\label{subsec:exhaust}\nAssume that we are only interested in maxima of \\(f(x)\\) where\n\\(-2\\leq x \\leq 3\\), and \\(x\\) increases in steps of length 0.5.\n(\\(\\Delta x = 0.5\\)). Perform an exhaustive search to\nmaximize \\(f(x)\\) and plot the result.\\\\\n\n\\textit{Plot:}\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{eps/w1e1d.eps}\n\\caption{Result of exhaustive search}\n\\label{fig:w1e1c}\n\\end{center}\n\\end{figure}\n\n\\textit{Source code (Python 3):}\n\\inputminted{Python}{py/w1e1d.py}\n\n\\subsection{Greedy Search and Hill Climbing}\nIn what way would greedy search and hill climbing differ for the maximization problem in Problem \\ref{subsec:grada}?\nCan you identify a starting position where the two algorithms might give different results?\\\\\n\n\\textit{Answer:}\n\nGreedy search will check all neighbors and always go in most promising direction.\nHill climber will randomly find a decent neighbor and walk there.\nIf both algorithms started in center ( \\(x = 0.5\\) ),\ngreedy search always go right,\nwhile hill climber could go right and left ( 50/50 ) as both are \\emph{up}.\n\n\\subsection{Possible improvements}\nGradient ascent, greedy search and hill climbing are quite similar,\nand are all based almost exclusively on exploitation.\nCan you think of any additions to these algorithms in order to do more exploration?\\\\\n\n\\textit{Answer:}\n\nRun the algorithm several times with random starting positions,\nthis will \\emph{explore} the solution space and find several local optima.\nAnother option is to add more random movement to either algorithm.\nThis can be done after a solution is found, or at a probability while searching.\nCould also do backtrack + random jump after a solution is found.\n\n\\subsection{Exhaustive search vs. simulated annealing}\nWhich algorithm do you think is the most efficient at maximizing \\(f(x)\\) under the conditions in Problem \\ref{subsec:exhaust}: exhaustive search or simulated annealing?\nExplain.\\\\\n\n\\textit{Answer:}\n\nExhaustive search is better for this case.\nIt takes few iterations to go through the one dimensional solution space.\nFor problems in higher dimensions or more complex functions with smaller step size exhaustive search becomes impractical and simulated annealing will outperform.\n\n\\input{../contact.tex}\n\\end{document}\n% ==============================================================================\n", "meta": {"hexsha": "46499e97c83ee9d058c8732401b6b66ce024a689", "size": 4829, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "material/week1/inf3490-sol1.tex", "max_stars_repo_name": "mpambasange/MachineLearning", "max_stars_repo_head_hexsha": "8b813345264513a57934317b01e1311628dc5b01", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2016-09-01T08:50:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T20:56:07.000Z", "max_issues_repo_path": "material/week1/inf3490-sol1.tex", "max_issues_repo_name": "olehermanse/INF3490-PythonAI", "max_issues_repo_head_hexsha": "8b813345264513a57934317b01e1311628dc5b01", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-10-20T09:36:19.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-29T00:28:54.000Z", "max_forks_repo_path": "material/week1/inf3490-sol1.tex", "max_forks_repo_name": "olehermanse/INF3490-PythonAI", "max_forks_repo_head_hexsha": "8b813345264513a57934317b01e1311628dc5b01", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2016-10-31T12:30:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-15T12:12:50.000Z", "avg_line_length": 35.2481751825, "max_line_length": 169, "alphanum_fraction": 0.7092565749, "num_tokens": 1313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.9149009578933863, "lm_q1q2_score": 0.8238955639307866}}
{"text": "\\section{Linear Regression}\nLinear Regression seeks to approximate a real valued label $y$ as a\nlinear function of $x$:\n\\begin{equation}\n  h_{\\theta}(x) = \\theta_0 + \\theta_1 \\cdot x_1 + \\cdots + \\theta_n \\cdot x_n\n\\end{equation}\nThe $\\theta_i$'s are the parameters, or weights. If we include the\nintercept term via $x_0=1$, we can write our model more compactly as:\n\\begin{equation}\n  h(x) = \\sum_{i=0}^{n} \\theta_i \\cdot x_i = \\theta^T x\n\\end{equation}\nHere $n$ is the number of input variables, or features. In Linear Regression,\nwe seek to make $h(x)$ as close to $y$ for a set of training examples. We\ndefine the cost function as:\n\\begin{equation}\n  J(\\theta) = \\frac{1}{2} \\sum_{i=1}^{m} \\left( h \\left(x^{(i)}\\right) - y^{(i)}\\right)^2\n\\end{equation}\n\\subsection{LMS Algorithm}\nWe seek to find a set of $\\theta$ such that we minimize $J(\\theta)$ via a\nsearch algorithm that starts at some initial guess for our parameters and takes\nincremental steps to make $J(\\theta)$ smaller until convergence. This is know\nas gradient descent:\n\\begin{equation}\n  \\theta_j := \\theta_j - \\alpha \\frac{\\partial}{\\partial \\theta_j}J(\\theta)\n\\end{equation}\nHere, $\\alpha$ is the learning rate. We can derive the partial derivative as:\n\\begin{equation}\n  \\begin{split}\n    \\frac{\\partial}{\\partial \\theta_{j}}J(\\theta) \\quad =& \\quad \\frac{\\partial}{\\partial \\theta_{j}}\\frac{1}{2} \\left( h(x)-y \\right)^{2} \\\\\n    =& \\quad 2\\cdot \\frac{1}{2} \\left(h(x) - y \\right) \\cdot \\frac{\\partial}{\\partial \\theta_{j}} (h(x) - y) \\\\\n    =& \\quad \\left(h(x) - y \\right) \\cdot \\frac{\\partial}{\\partial \\theta_{j}} \\left(\\sum_{i=0}^{n} \\theta_{i} x_{i} - y \\right) \\\\\n    =& \\quad \\left( h ( x ) - y \\right) x _ { j } \\\\\n\\end{split}\n\\end{equation}\nHence, for a single example (stochastic gradient descent):\n\\begin{equation}\n  \\theta _ { j } : = \\theta _ { j } + \\alpha \\left( y ^ { ( i ) } - h \\left( x ^ { ( i ) } \\right) \\right) x _ { j } ^ { ( i ) }\n\\end{equation}\nThis is called the LMS update rule. For a batched version, we can evaluate the\ngradient on a set of examples (batch gradient descent), or the full set\n(gradient descent).\n\\begin{equation}\n  \\theta _ { j } : = \\theta _ { j } + \\alpha \\sum _ { i = 1 } ^ { m } \\left( y ^ { ( i ) } - h \\left( x ^ { ( i ) } \\right) \\right) x _ { j } ^ { ( i ) }\n\\end{equation}\n\\subsection{The Normal Equations}\nWe can also directly minimize $J$ without using an iterative algorithm. We\ndefine $X$ as the matrix of all samples of size $m$ by $n$.\nWe let $\\vec{y}$ be a $m$ dimensional vector of all target values. We can\ndefine our cost function $J$ as:\n\\begin{equation}\n  J(\\theta) = \\frac { 1 } { 2 } ( X \\theta - \\vec { y } ) ^ { T } ( X \\theta - \\vec { y } ) = \\frac { 1 } { 2 } \\sum _ { i = 1 } ^ { m } \\left( h \\left( x ^ { ( i ) } \\right) - y ^ { ( i ) } \\right) ^ { 2 }\n\\end{equation}\nWe then take the derivative and find its roots.\n\n\\begin{equation}\n  \\begin{split}\n    \\nabla _ { \\theta } J ( \\theta ) \\quad =& \\quad \\nabla _ { \\theta } \\frac { 1 } { 2 } ( X \\theta - \\vec { y } ) ^ { T } ( X \\theta - \\vec { y } ) \\\\\n    =& \\quad \\frac { 1 } { 2 } \\nabla _ { \\theta } \\left( \\theta ^ { T } X ^ { T } X \\theta - \\theta ^ { T } X ^ { T } \\vec { y } - \\vec { y } ^ { T } X \\theta + \\vec { y } ^ { T } \\vec { y } \\right) \\\\\n    =& \\quad \\frac { 1 } { 2 } \\nabla _ { \\theta } \\left( \\operatorname { tr } \\theta ^ { T } X ^ { T } X \\theta - 2 \\operatorname { tr } \\vec { y } ^ { T } X \\theta \\right) \\\\\n    =& \\quad \\frac { 1 } { 2 } \\left( X ^ { T } X \\theta + X ^ { T } X \\theta - 2 X ^ { T } \\vec { y } \\right) \\\\\n    =& \\quad X ^ { T } X \\theta - X ^ { T } \\vec { y } \\\\\n  \\end{split}\n\\end{equation}\nTo minimize $J$, we set its derivatives to zero, and obtain the normal\nequations:\n\\begin{equation}\n  X ^ { T } X \\theta = X ^ { T } \\vec { y }\n\\end{equation}\nWhich solves $\\theta$ for a value that minimizes $J(\\theta)$ in closed form:\n\\begin{equation}\n  \\theta = \\left( X ^ { T } X \\right) ^ { - 1 } X ^ { T } \\vec { y }\n\\end{equation}\n\\subsection{Probabilistic Interpretation}\nWhy does linear regression use the least-squares cost function? Assume that\nthe target variables and inputs are related via:\n\\begin{equation}\n  y ^ { ( i ) } = \\theta ^ { T } x ^ { ( i ) } + \\epsilon ^ { ( i ) }\n\\end{equation}\nHere, $\\epsilon^{(i)}$ is an error term for noise. We assume each\n$\\epsilon^{(i)}$ is independently and identically distributed according to a\nGaussian distribution with mean zero and some variance $\\sigma^2$. Hence,\n$\\epsilon^{(i)} \\sim \\mathcal { N } \\left( 0 , \\sigma ^ { 2 } \\right)$, so\nthe density for any sample $x^{(i)}$ with label $y^{(i)}$ is\n$y^{(i)} | x^{(i)}; \\theta \\sim \\mathcal{N} \\left( \\theta^T x^{(i)}, \\sigma^{2} \\right)$.\nThis implies:\n\\begin{equation}\n  p \\left( y ^ { ( i ) } | x ^ { ( i ) } ; \\theta \\right) = \\frac { 1 } { \\sqrt { 2 \\pi } \\sigma } \\exp \\left( - \\frac { \\left( y ^ { ( i ) } - \\theta ^ { T } x ^ { ( i ) } \\right) ^ { 2 } } { 2 \\sigma ^ { 2 } } \\right)\n\\end{equation}\nThe probability of a dataset $X$ is quantified by a likelihood function:\n\\begin{equation}\n  L ( \\theta ) = L ( \\theta ; X , \\vec { y } ) = p ( \\vec { y } | X ; \\theta )\n\\end{equation}\nSince we assume independence on each noise term (and samples), we can write\nthe likelihood function as:\n\\begin{equation}\n  \\begin{aligned}\n    L ( \\theta ) & = \\prod _ { i = 1 } ^ { m } p \\left( y ^ { ( i ) } | x ^ { ( i ) } ; \\theta \\right) \\\\\n    & = \\prod _ { i = 1 } ^ { m } \\frac { 1 } { \\sqrt { 2 \\pi } \\sigma } \\exp \\left( - \\frac { \\left( y ^ { ( i ) } - \\theta ^ { T } x ^ { ( i ) } \\right) ^ { 2 } } { 2 \\sigma ^ { 2 } } \\right)\n  \\end{aligned}\n\\end{equation}\nTo get the best choice of parameters $\\theta$, we perform maximum likelihood\nestimation such that $L(\\theta)$ is maximized. Usually we take the negative log\nand minimize:\n\\begin{equation}\n  \\begin{aligned}\n    \\ell ( \\theta ) & = - \\log L ( \\theta ) \\\\\n    & = - \\log \\prod _ { i = 1 } ^ { m } \\frac { 1 } { \\sqrt { 2 \\pi } \\sigma } \\exp \\left( - \\frac { \\left( y ^ { ( i ) } - \\theta ^ { T } x ^ { ( i ) } \\right) ^ { 2 } } { 2 \\sigma ^ { 2 } } \\right) \\\\\n    & = - \\sum _ { i = 1 } ^ { m } \\log \\frac { 1 } { \\sqrt { 2 \\pi } \\sigma } \\exp \\left( - \\frac { \\left( y ^ { ( i ) } - \\theta ^ { T } x ^ { ( i ) } \\right) ^ { 2 } } { 2 \\sigma ^ { 2 } } \\right) \\\\\n    & = - m \\log \\frac { 1 } { \\sqrt { 2 \\pi } \\sigma } + \\frac { 1 } { \\sigma ^ { 2 } } \\cdot \\frac { 1 } { 2 } \\sum _ { i = 1 } ^ { m } \\left( y ^ { ( i ) } - \\theta ^ { T } x ^ { ( i ) } \\right) ^ { 2 }\n  \\end{aligned}\n\\end{equation}\nHence, maximizing $L(\\theta$) is the same as minimizing the negative log\nlikelihood $\\ell(\\theta)$, which for linear regression is the least squares\ncost function:\n\\begin{equation}\n  \\frac { 1 } { 2 } \\sum _ { i = 1 } ^ { m } \\left( y ^ { ( i ) } - \\theta ^ { T } x ^ { ( i ) } \\right) ^ { 2 }\n\\end{equation}\nUnder the previous probabilistic assumptions on the data, least-squares\nregression corresponds to finding the maximum likelihood estimate of $\\theta$.\nThis is thus one set of assumptions under which least-squares regression\ncan be justified as performing maximum likelihood estimation. Note that $\\theta$\nis independent of $\\sigma^2$.\n\\subsection{Locally Weighted Linear Regression}\nLocally Weighted Regression, also known as LWR, is a variant of\nlinear regression that weights each training example in its cost function by\n$w^{(i)}(x)$, which is defined with parameter $\\tau \\in \\mathbb{R}$ as:\n\\begin{equation}\n  w^{(i)}(x)=\\exp\\left(-\\frac{(x^{(i)}-x)^2}{2\\tau^2}\\right)\n\\end{equation}\nHence, in LWR, we do the following:\n\\begin{enumerate}\n  \\item Fit $\\theta$ to minimize $\\sum_i w^{(i)} \\left( y^{(i)} - \\theta^{T} x^{(i)} \\right)^{2}$\n  \\item Output $\\theta^T x$\n\\end{enumerate}\nThis is a non-parametric algorithm, where non-parametric refers to the fact\nthat the amount of information we need to represent the hypothesis $h$ grows\nlinearly with the size of the training set.\n", "meta": {"hexsha": "cec3f920f5c46ca1995394b8e8fc42805c3f1ace", "size": 7887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/linear_regression.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/linear_regression.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/linear_regression.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.152173913, "max_line_length": 219, "alphanum_fraction": 0.5900849499, "num_tokens": 2786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067147399244, "lm_q2_score": 0.8740772253241802, "lm_q1q2_score": 0.8238236540692817}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 3}\n\nIn a max-heap of size $n$, represented as discussed in class, in what index(es) can the smallest element reside? Explain carefully.\nAssume all the $n$ numbers are different.\n\n\\subsection*{Solution}\n\nParent elements in a in a max-heap data structure are always larger than their children.\nThus, smallest element resides in indices of leaves, i.e. nodes of height $0$.\nWe know some leaves are at height $H$ and some at height $H-1$.\nSince row $(H-1)$ is inevitably filled out, number of leaves in height $H$ is $n - (2^H - 1)$ and number of leaves in height $(H-1)$ is $(2^H-1)-\\lfloor \\frac{n}{2} \\rfloor$.\nTherefore, there are $\\lceil \\frac{n}{2} \\rceil$ leaves in total so indices in which smallest element may reside are $A[n - \\lceil \\frac{n}{2} \\rceil]$ to $A[n]$.\n", "meta": {"hexsha": "83eab4bf928cd234011b142160aecda13f53bb42", "size": 1147, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/m01/m01q03.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/m01/m01q03.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/m01/m01q03.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 57.35, "max_line_length": 174, "alphanum_fraction": 0.6425457716, "num_tokens": 302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314624993576758, "lm_q2_score": 0.8840392924390587, "lm_q1q2_score": 0.8234494488656768}}
{"text": "\\subsection{Motivation}\n\nConsider a system of linear equations in two variables, such as\n\n\\begin{align*}\ny_1 &= ax_1 + bx_2 \\\\\ny_2 &= cx_1 + dx_2.\n\\end{align*}\n\nWe would like to solve for $x_1$ and $x_2$ in terms of $y_1$ and $y_2$. Presumably, these solutions will have expressions involving $a$, $b$, $c$, and $d$. To solve this equation for $x_1$, we first eliminate the second variable by multiplying the first and second equations by appropriate constants, respectively:\n\n\\begin{align*}\ndy_1 &= adx_1 + bdx_2 \\\\\nby_2 &= bcx_1 + bdx_2.\n\\end{align*}\n\nSubtracting the second equation from the first, and solving for $x_1$, we get\n\\[x_1 = \\frac{dy_1 - by_2}{(ad-bc)}.\\]\nIn a similar manner we can solve for $x_2$ as well.\n\nNow consider an alternative perspective. We can rewrite the system of linear equations that we are considering as a matrix vector equation\n\\[\\begin{bmatrix}y_1 \\\\ y_2 \\end{bmatrix} = \\begin{bmatrix}a & b \\\\ c & d\\end{bmatrix}\\begin{bmatrix}x_1 \\\\ x_2\\end{bmatrix}.\\]\n\nThen in the language of determinants, we find that \n\\[x_1 = \\frac{\\det{ \\begin{bmatrix}y_1 & b \\\\ y_2 & d\\end{bmatrix}}}{\\det \\begin{bmatrix}a & b \\\\ c & d\\end{bmatrix}}\\] and\n\\[x_2 = \\frac{\\det{ \\begin{bmatrix}a & y_1 \\\\ c& y_2\\end{bmatrix}}}{\\det \\begin{bmatrix}a & b \\\\ c & d\\end{bmatrix}}.\\]\n\nThis is the $2$ dimensional case of \\textit{Cramer's Rule}.", "meta": {"hexsha": "d5f79d0d755a1e263e9cc0437b47364a59ba5835", "size": 1348, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch8/cramer.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch8/cramer.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch8/cramer.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.1428571429, "max_line_length": 314, "alphanum_fraction": 0.6958456973, "num_tokens": 467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012747599251, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.8234120142018613}}
{"text": "\\subsection{Gradient Descent}\r\n\\noindent\r\nRemember that if we have a multidimensional function, taking a step in the direction of the gradient results in the maximum possible increase of the function, and taking a step in the opposite direction of the gradient results in the maximum possible decrease of the function.\r\nGradient descent is a method to find minima of functions.\\\\\r\n\r\n\\noindent\r\nLet's say we're trying to minimize $J(\\vec{x})$ with gradient descent. Here are the steps we would take:\r\n\\begin{enumerate}\r\n\t\\item Pick (or guess) a starting point $\\vec{x_0}$ and a learning rate (step size) $\\delta$.\r\n\t\\item $\\overrightarrow{x_{n+1}} = \\overrightarrow{x_n} - \\delta J(\\overrightarrow{x_n})$\r\n\t\\item Repeat step 2 until some stopping criteria is met, like $\\norm{\\delta \\nabla J(\\overrightarrow{x_n}) - \\delta \\nabla J(\\overrightarrow{x_{n+1}})} < \\epsilon$.\r\n\\end{enumerate}\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.5\\textwidth]{./differentialMultivariableCalculus/gradient_descent.png}\r\n\t\\caption{Path of several iterations of gradient descent}\r\n\\end{figure}\r\n\r\n\\noindent\r\nThis method will lead you arbitrarily close to a local minimum, but does not guarantee finding the global minimum.\r\nMore advanced versions of gradient descent exists that try to help with this, like giving the point ``momentum'' to be able to move out of local mins.\r\nThis method also has a trade off between speed and accuracy.\r\nAlthough increasing $\\delta$ means fewer iterations of gradient descent are needed to narrow in on a local minimum, one is more likely to be stuck in a local min than if they had used a smaller $\\delta$.\\\\\r\n\r\n\\noindent\r\nIn the real world, the function you are trying to minimize will likely not be well defined enough to take its partial derivatives to find the gradient, so they too are approximated by doing something like\r\n\\begin{equation*}\r\n\tJ_{k} = \\frac{J(k+.0001, \\ldots) - J(k, \\ldots)}{.0001}.\r\n\\end{equation*}", "meta": {"hexsha": "1aee29619423d4075f05365a26de85ec18852026", "size": 1956, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/gradientDescent.tex", "max_stars_repo_name": "wmboyles/Math-Summaries", "max_stars_repo_head_hexsha": "94732081a5b6913d84e11c62a3989b63f9934b56", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/gradientDescent.tex", "max_issues_repo_name": "wmboyles/Math-Summaries", "max_issues_repo_head_hexsha": "94732081a5b6913d84e11c62a3989b63f9934b56", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/gradientDescent.tex", "max_forks_repo_name": "wmboyles/Math-Summaries", "max_forks_repo_head_hexsha": "94732081a5b6913d84e11c62a3989b63f9934b56", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 65.2, "max_line_length": 277, "alphanum_fraction": 0.7556237219, "num_tokens": 488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768144, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.8234120022730927}}
{"text": "\n\\subsection{Autocovariance and autocorrelation}\n\n\\subsubsection{Autocovariance}\n\n\\(AC(a,b)=cov(X_a, X_b)\\)\n\n\\subsubsection{Autocorrelation}\n\nThe autocorrelation between two time periods is their covariance, normlised by their variances\n\n\\(AC(a,b)=\\dfrac{E[(X_a-\\mu_a)(X_b-\\mu_b)]}{\\sigma_a \\sigma_b}\\)\n\nThis is also called serial correlation.\n\n", "meta": {"hexsha": "2b09a90d316f552bdd1ff168383b66eb61ab355d", "size": 345, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stochastic/01-05-autocovariance.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/stochastic/01-05-autocovariance.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/stochastic/01-05-autocovariance.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.5625, "max_line_length": 94, "alphanum_fraction": 0.7594202899, "num_tokens": 103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9597620550745211, "lm_q2_score": 0.8577681068080748, "lm_q1q2_score": 0.8232532809674992}}
{"text": "% Principal Component Analysis\n\\section{Principal Component Analysis (PCA)}\n\\label{sec:pca}\n\nPrincipal Component Analysis (PCA) is a decomposition of data into linearly uncorrelated components, ordered by their explained variance. It turns out that these axes are the right-singular eigenvectors $\\mathbf{V}$ that are found from SVD. SVD and PCA have correspondence (cf. section \\ref{sec:pcasvd}). My guess is that the advantage of PCA is that its results are interpretable in terms of commonly used summary statistics of the distribution (namely the variances or Pearson correlations of the data).\n\\\\\n\nMore elaborately, for a data matrix $\\mathbf{X}\\in\\mathbb{R}^{N\\times p}$, PCA extracts the ordered, rank-$p$, orthonormal basis in which the $p\\times p$ covariance matrix of $\\mathbf{X}$ is diagonal. The basis vectors are called the principal axes or principal directions of the data, and their ordering is by the magnitude of the variance that they explain. \n\\\\\n\nThe property that the covariance matrix is diagonal in the principal component basis means that projecting the data onto any of the basis vectors extracts a linearly uncorrelated component of the data that has variance corresponding to the corresponding eigenvalue of the covariance matrix.\n\\\\\n\nJust like with SVD, the ordering of the principal component basis in terms of their explained variance allows for lower-rank approximations of the data matrix to be constructed (section \\ref{sec:svd}). Just like SVD, the lower rank approximations $\\mathbf{X}$ are the best possible approximations with respect to the Frobenius Norm (cf. section \\ref{sec:frobenius}). \n\\\\\n\nThe $p\\times p$ covariance matrix  $\\mathbf{C}$ of $\\mathbf{X}$ is:\n\n\\begin{equation}\n\\mathbf{C} = \\frac{\\left(\\mathbf{X}-\\left<\\mathbf{X}\\right>\\right)^T\\left(\\mathbf{X}-\\left< \\mathbf{X}\\right>\\right)}{n-1}\n\\end{equation}\n\nWhere $\\left(\\mathbf{X}-\\left<\\mathbf{X}\\right>\\right)^T$ is often referred to as the \\textit{centered} data matrix. The covariance matrix is a symmetric, positive-definite matrix that can be diagonalized with orthonormal eigenvectors $\\mathbf{V}$ and positive (or vanishing) eigenvalues $\\lambda_i$:\n\n\\begin{equation}\n\\mathbf{C} = \\mathbf{V}\\mathbf{\\Lambda}\\mathbf{V}^T\n\\end{equation}\n\nWhere the eigenvectors in $V$ are ordered so that the eigenvectors along the diagonal of $\\mathbf{\\Lambda}$ have decreasing magnitude. The eigenvectors are the principal axes or principal directions of the data.\n\\\\\nThat PCA corresponds to the diagonalization of the covariance matrix implies a description of the underlying data in terms of a multivariate Gaussian distribution. In other words, it assumes normally distributed noise, and the components describe best-fit linear subspaces in the data under the $L^2$ norm. Whenever the Gaussian assumption is unjustified, it makes sense to look for best-fit linear subspaces under different norms. For example, $L^1$-PCA is more robust to outliers (cf. section \\ref{sec:l1pca}). \n\n\n% Relationship between PCA and SVD\n\\subsection{Relationship between PCA and SVD}\n\\label{sec:pcasvd}\nThis is based on a great Stack Exchange answer \\cite{amoeba2015svdpca}.\n\nLet the singular value decomposition of the centered data matrix be:\n\n\\begin{equation}\n\\left(\\mathbf{X}-\\left<\\mathbf{X}\\right>\\right) = \\mathbf{U}\\mathbf{\\Sigma}\\mathbf{V}^T\n\\end{equation}\n\nThen:\n\n\\begin{equation}\n\\mathbf{C} = \\frac{\\mathbf{V\\Sigma U}^T\\mathbf{U\\Sigma V}^T}{n-1} = \\mathbf{V}\\frac{\\Sigma^2}{n-1}\\mathbf{V}^T\n\\end{equation}\n\nThat means that:\n\n\\begin{itemize}\n\\item The principal axes are the right-singular vectors $\\mathbf{V}$ that are obtained during SVD.\n\\item The singular values and the eigenvalues of the covariance matrix are related via $\\lambda_i = \\frac{\\sigma_i^2}{n-1}$.\n\\end{itemize}\n\n\n\n\\subsection{Tracking Principal Components over Time}\nGiven the direct parallel between PCA and SVD, the identical issue with sign flips emerges with the principal component basis, and the remedy is the same. See section \\ref{sec:svd_tracking}.\n\n\n\\subsection{$L^1$-Norm Principal Component Analysis ($L^1$ PCA)}\n\\label{sec:l1pca}\n\n$L1$-Norm Principal Component Analysis is an alternative to conventional PCA that aims to provide better robustness to outliers. While L2-PCA is uniquely defined, a cursory search reveals a zoo of approaches to what $L^1$ PCA is supposed to be \\cite{brooks2012pcal1}. $L^1$-PCA may also be a natural choice in situations in which the $L^1$ norm is the proper way of measuring distances in a space, for example in cellular automata models or perhaps even in case of categorical data. \n\n\\citeasnoun{brooks2014pure} establishes that the PCA under $L^1$ norm is found by successive fitting of hyperplanes under $L^1$ error in progressively smaller subspaces. Much like the $L^2$ distance of a point to a hyperplane is given by the radius of a circle around that point, the $L^1$ distance of a point to a hyperplane is given by its intersection of a rhombus. This has the (kind of quirky) consequence that the distance of all points to a hyperplane is always measured directly along one of the coordinate axes (and it is the same coordinate axes for each of the points). This, in turn, implies, that in some subspace $\\mathbb{R}^m$, the $L^1$ best-fit hyperplane can be found by performing an $L^1$ regression with each of the $m$ dimensions serving as the explanatory variable, and then selecting the regression result that had the smallest residual. \n\nIt is worth noting that this approach is within the spirit of minimizing the taxicab-like distances of a point to some sub-space, which assigns great significance to the coordinate grid. This goes against the spirit of PCA, in that it typically aims to extract some kind of natural coordinate system from the data, irrespective of the coordinate system in which the raw data was expressed. \\possessivecite{brooks2014pure} method is within keeping of the definition of the $L^1$ norm, but its different from simply avoiding assigning quadratic importance to far-away points to achieve greater robustness.\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=0.4\\textwidth]{l1pca.png}\n    \\caption{Distance of a point to a hyperplane in $L^1$ and $L^2$. The $L^1$ distance in this case is just the distance along the $x$ axis. If the hyperplane was cutting a shallower angle, then the distance would be measured along the $y$ axis. The best fit hyperplane to many points in $\\mathbb{R}^2$ would be found by regressing the data points once with $y = \\beta x + \\epsilon$ and once with $x = \\beta y + \\epsilon$ and selecting the result with the smaller $||\\epsilon||_1$. (The figure is from J. P. Brooks (2014).}\n    \\label{fig:l1pca}\n\\end{figure}\n", "meta": {"hexsha": "516e6b85a20edeecfef2567486785abce746152d", "size": 6691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/unsup_pca.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/unsup_pca.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/unsup_pca.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.6962025316, "max_line_length": 862, "alphanum_fraction": 0.7722313556, "num_tokens": 1721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.9086179000259899, "lm_q1q2_score": 0.8231985726544603}}
{"text": "\\section{Runge-Kutta Methods}\n\\begin{theo}\nSuppose that $f(t,y)$ and all its partial derivatives of order less or equal to $n+1$ are continuous on $D=\\left\\{(t,y)|a\\leq t\\leq b,c\\leq y\\leq d\\right\\}$ ($D=[a,b]\\times [c,d]$) and let $(t_0,y_0)\\in D$. For every $(t,y)\\in D$, there exists $\\xi$ between $t$ and $t_0$ and $\\mu$ between $y$ and $y_0$ with\n\\[\nf(t,y) = P_n(t,y)+R_n(t,y)\n\\]\nwhere\n\\begin{align*}\n  P_n(t,y) &= f(t_0,y_0)+\\left[(t-t_0)\\partialD{f}{t}(t_0,y_0)+(y-y_0)\\partialD{f}{y}(t_0,y_0)\\right] \\\\\n  &+ \\left[\\frac{(t-t_0)^2}{2}\\partialD{^2f}{t^2}(t_0,y_0)+(t-t_0)(y-y_0)\\partialD{^2f}{t\\partial y}(t_0,y_0)+\\frac{(y-y_0)^2}{2}\\partialD{^2f}{y^2}(t_0,y_0)\\right] \\\\\n  &+ \\left[\\frac{1}{n!}\\sum_{j=0}^{n+1}\\binom{n}{j}(t-t_0)^{n-j}(y-y_0)^j\\partialD{^{n+1}f}{t^{n+1}\\partial y^i}(t_0,y_0)\\right]\n\\end{align*}\n\\[\nand\\quad R_n(t,y)=\\frac{1}{(n+1)!}\\sum_{j=0}^{n+1}\\binom{n+1}{j}(t-t_0)^{n+1-j}(y-y_0)\\partialD{^{n+1}f}{t^{n+1}\\partial y^i}(\\xi,\\mu)\n\\]\nThe function $P_n(t,y)$ is called the \\emph{$n$th Taylor polynomial in two variables} for the function $f$ about $(t_0,y_0)$, and $R_n(t,y)$ is the remainder term associated with $P_n(t,y)$.\n\\end{theo}\n\\subsection{Runge-Kutta Methods of Order Two}\n\\begin{equation*}\n  \\begin{cases}\n    y_{n+1}=y_n+h(c_1k_1+c_2k_2) &\\\\\n    k1 = f(x_n,y_n) &\\\\\n    k1 = f(x_n+\\lambda_2h,y_n+\\mu_{21}hk_1)\n  \\end{cases}\n\\end{equation*}\n\\begin{align*}\n  T_{n+1} &= y(x_{n+1})-y(x_n)-h\\left[c_1f(x_n,y_n)+c_2f(x_n+\\lambda_2h,y_n+\\mu_{21}hf_n)\\right] \\\\\n  &= hf_n+\\frac{h^2}{2}\\left[f_x'(x_n,y_n)+f_y'(x_n,y_n)f_n\\right] \\\\\n  &\\quad -h\\left[c_1f_n+c_2\\left(f_n+\\lambda_2f_x'(x_n,y_n)h+\\mu_{21}f_y'(x_n,y_n)f_nh\\right)\\right]+O(h^3) \\\\\n  &= (1-c_1-c_2)f_nh+\\left(\\frac{1}{2}-c_2\\lambda_2\\right)f_x'(x_n,y_n)h^2 \\\\\n  &\\quad +\\left(\\frac{1}{2}-c_2\\mu_{21}\\right)f_y'(x_n,y_n)f_nh^2+O(h^3) \\\\\n  \\Rightarrow & y_{n+1}=y_n+hf\\left(x_n+\\frac{h}{2},y_n+\\frac{h}{2}f(x_n,y_n)\\right)\n\\end{align*}\n\n\\subsection{Midpoint Method}\n\\begin{equation*}\n  \\begin{cases}\n    \\omega_0=\\alpha & \\\\\n    \\omega_{i+1}=\\omega_i+hf\\left(t_i+\\frac{h}{2},\\omega_i+\\frac{h}{2}f(t_i,\\omega_i)\\right) & \\text{for $i=0,\\cdots,N-1$}\n  \\end{cases}\n\\end{equation*}\nLocal truncation error: $O(h^2)$.\n\n\\subsection{Modified Euler Method} \\begin{equation*}\n  \\begin{cases}\n    \\omega_0=\\alpha & \\\\\n    \\omega_{i+1}=\\omega_i+\\frac{h}{2}\\left[f(t_i,\\omega_i),f\\left(t_{i+1},\\omega_i+hf(t_i,\\omega_i)\\right)\\right] & \\text{for $i=0,\\cdots,N-1$}\n  \\end{cases}\n\\end{equation*}\n\n\\subsection{Higher-Order Runge-Kutta Methods}\nRunge-Kutta Order Three:\n\\begin{equation*}\n  \\begin{cases}\n    \\omega_0=\\alpha &\\\\\n    k_1=hf(t_i,\\omega_i) &\\\\\n    k_2=hf(t_i+\\frac{h}{2},\\omega_i+\\frac{1}{2}k_1) &\\\\\n    k_3=hf(t_i+h,\\omega-k_1+2k_2) &\\\\\n    \\omega_{i+1}=\\omega_i+\\frac{1}{6}(k_1+4k_2+k_3) &\\\\\n  \\end{cases}\n\\end{equation*}\n\nRunge-Kutta Order Four:\n\\begin{equation*}\n  \\begin{cases}\n    \\omega_0=\\alpha &\\\\\n    k_1=hf(t_i,\\omega_i) &\\\\\n    k_2=hf(t_i+\\frac{h}{2},\\omega_i+\\frac{1}{2}k_1) &\\\\\n    k_3=hf(t_i+\\frac{h}{2},\\omega-k_1+\\frac{1}{2}k_2) &\\\\\n    k_4=hf(t_i+h,\\omega_i+k_3) &\\\\\n    \\omega_{i+1}=\\omega_i+\\frac{1}{6}(k_1+2k_2+2k_3+k_4) &\\\\\n  \\end{cases}\n\\end{equation*}\n\n\\subsection{Computational Comparisons}\n\\begin{table}[H]\n\\begin{tabular}{|c|c|c|c|c|}\n\\hline\nEvaluations per step & $n\\in[2,4]$ & $n\\in[5,7]$ & $n\\in[8,9]$ & $n\\in[10,\\infty]$ \\\\ \\hline\nBest possible local truncation error & $O(h^n)$ & $O(h^{n-1})$ & $O(h^{n-2})$ & $O(h^3)$ \\\\ \\hline\n\\end{tabular}\n\\end{table}", "meta": {"hexsha": "a91733e20e6b51d70177f66e7a7a53782f731090", "size": 3473, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/5.4_Runge-kutta_methods.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/5.4_Runge-kutta_methods.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/5.4_Runge-kutta_methods.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.3536585366, "max_line_length": 308, "alphanum_fraction": 0.6127267492, "num_tokens": 1643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.9059898127684335, "lm_q1q2_score": 0.8231985628040173}}
{"text": "\\chapter{Partitions}\n\\label{chapter:partitions}\nThe main question we study in this chapter is as follows:\n``how many ways to put $n$ objects into $k$ boxes''.\nNote that there are four modes for this question:\n\\begin{enumerate}\n  \\item the objects and boxes are identical,\n  \\item the objects are identical but boxes are different,\n  \\item the objects are different but boxes are identical,\n  \\item the objects and boxes are different.\n\\end{enumerate}\nWe are going to study the question in all these modes.\nThe Table~\\ref{table:partitions} summarizes the results we are going\nto prove for the cases when all the boxes are not empty.\n\\begin{table}[h!]\n  \\centering\n  \\begin{tabular}{l l l}\n    \\toprule\n    Object's name & Parameters & Formula \\\\\n    \\midrule\n    \\multirow{4}{*}{Surjections}\n                       & $n$ distinct objects &\n                       \\multirow{2}{*}{$\\stirlingTwo{n}{k} k!$} \\\\\n                       & $k$ distinct boxes   &  \\\\\n    \\rule{0pt}{2ex}\n                       & $n$ distinct objects & \\multirow{2}{*}{$\\sum_{k = i}^n\n                       \\stirlingTwo{n}{k} k!$} \\\\\n                       & any number of boxes  & \\\\\n    \\rule{0pt}{4ex}\n    \\multirow{4}{*}{Compositions}\n                       & $n$ identical objects & \\multirow{2}{*}{$\\binom{n - 1}{k - 1}$} \\\\\n                       & $k$ distinct boxes   &  \\\\\n   \\rule{0pt}{2ex}\n                       & $n$ identical objects & \\multirow{2}{*}{$2^{n - 1}$} \\\\\n                       & any number of boxes  & \\\\\n   \\rule{0pt}{4ex}\n   \\multirow{4}{*}{Set partitions}\n                      & $n$ distinct objects &\n                      \\multirow{2}{*}{$\\stirlingTwo{n}{k}$} \\\\\n                      & $k$ identical boxes   &  \\\\\n    \\rule{0pt}{2ex}\n                      & $n$ distinct objects & \\multirow{2}{*}{$B(n)$} \\\\\n                      & any number of boxes  & \\\\\n    \\rule{0pt}{4ex}\n    \\multirow{4}{*}{Integer partitions}\n                       & $n$ identical objects & \\multirow{2}{*}{$p_k(n)$} \\\\\n                       & $k$ identical boxes   &  \\\\\n    \\rule{0pt}{2ex}\n                       & $n$ identical objects & \\multirow{2}{*}{$p(n)$} \\\\\n                       & any number of boxes  & \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\caption{Formulas for the numbers of ways to put $n$ objects into $k$ boxes\n  so that the boxes are not empty}\n  \\label{table:partitions}\n\\end{table}\n\\section{Set Partitions}\nThis section considers the case when objects are not identical.\n\nFirst, we define a notion that allows us to compute the answer in case when\nall the boxes are the same.\n\\begin{definition}\n  A partition of the set $[n]$ is a collection of non-empty\n  blocks so that each element of $[n]$ belongs to exactly\n  one of these blocks. The number of partitions of $[n]$\n  into $k$ nonempty blocks is denoted by $\\stirlingTwo{n}{k}$.\n  The numbers $\\stirlingTwo{n}{k}$ are called the \\emph{Stirling numbers\n  of the second kind}.\n\\end{definition}\n\\nomenclature[C]{$\\stirlingTwo{n}{k}$}{denotes the Stirling number\nof the second kind; i.e. the number of partitions\nof $[n]$ into $k$ nonempty blocks}\n\nIt is easy to see that $\\stirlingTwo{n}{1} = 1$ and $\\stirlingTwo{n}{n} = 1$.\nMoreover, $\\stirlingTwo{n}{k} = 0$ if $k > n$ or $k \\le 0$.\n\nLet us find the value in a more complicated setting, we\nclaim that $\\stirlingTwo{n}{n - 1} = \\binom{n}{2}$. Indeed, any\npartition of $[n]$ into $n - 1$ blocks consists of\n$n - 1$ singletons and one set with two elements, thus we\njust need to select these two elements.\n\nUsing double counting, one may prove a recursive formula\nfor Stirling numbers of the second kind.\n\\begin{theorem}\n  For any $n > k > 0$,\n  \\[\n    \\stirlingTwo{n}{k} = \\stirlingTwo{n - 1}{k - 1} + k \\cdot \\stirlingTwo{n - 1}{k}.\n  \\]\n\\end{theorem}\n\\begin{proof}\n  Let us consider $n$, note that there are two cases either $n$ forms a\n  singleton in a partition or it is not the only element in the part.\n\n  It is easy to see that there are $\\stirlingTwo{n - 1}{k - 1}$ partitions where $n$ is\n  a singleton and $k \\cdot \\stirlingTwo{n - 1}{k}$ partitions where $n$ is not a singleton\n  (we multiply by $k$ since there are $k$ possible ways to add $n$ to a\n  partition of $\\range{n - 1}$).\n\\end{proof}\n\nUsing this notation, we can express the number of surjections.\n\\begin{lemma}\n  There are exactly $k! \\stirlingTwo{n}{k}$ surjective functions from\n  $\\range{n}$ to $\\range{k}$.\n\\end{lemma}\n\\begin{proof}\n  Let $\\mathcal{S}(n, k)$ be the set of surjections from $\\range{n}$ to $\\range{k}$,\n  $\\mathcal{P}(n, k)$ be the set of partitions with non-empty blocks, and\n  $F : \\mathcal{S}(n, k) \\to \\mathcal{P}(n, k)$ such that\n  $F(f) = \\set{f^{-1}(1), \\dots, f^{-1}(k)}$.\n\n  It is easy to see that $F(f) = F(g)$ iff there is $h : \\range{k} \\to \\range{k}$ \n  such that $f \\circ h = g$. Hence, $F^{-1}(f) = k!$ for any $f \\in \\mathcal{S}(n, k)$.\n  Thus $\\cardinality{\\mathcal{S}(n, k)} = k! \\cardinality{\\mathcal{P}(n, k)}$.\n\\end{proof}\nNote that the number of surjections from $\\range{n}$ to $\\range{k}$ is equal to the\nnumber of ways to put $n$ different objects into $k$ different boxes.\n\nUsing this equality, we can prove a surprising result.\n\\begin{theorem}\n\\label{theorem:stirling-numbers-and-polynomials}\n  For any real $x$ and positive integer $n$,\n  \\[\n    x^n = \\sum_{k = 0}^n \\stirlingTwo{n}{k} \\numberOfPermutations[k]{x},\n  \\]\n  where $\\numberOfPermutations[k]{x} = \\prod_{i = 0}^{k - 1} (x - i)$.\n\\end{theorem}\n\nTo prove the statement we need the following statement.\n\\begin{theorem}\n  Let $p$ and $q$ be real polynomials. If $p(\\ell) = q(\\ell)$ for all\n  natural numbers $\\ell$, then $p(x) = q(x)$ for all real numbers $x$.\n\\end{theorem}\n\n\\begin{proof}[Proof of Theorem~\\ref{theorem:stirling-numbers-and-polynomials}]\n  Using the previous result, it is enough to prove that\n  for any integer $\\ell > 0$,\n  \\[\n    \\ell^n = \\sum_{k = 0}^n \\stirlingTwo{\\ell}{k} \\numberOfPermutations[k]{\\ell}.\n  \\]\n\n  Clearly $\\ell^n$ denotes the number of ways to put $n$ different\n  objects into $\\ell$ different boxes. Note that if we have $k$ nonempty\n  boxes, then there are $\\binom{n}{k}$ ways to select these boxes and\n  $k! \\stirlingTwo{\\ell}{k}$ ways to put objects in these $k$ boxes. Thus formula in\n  the left is equal to the formula on the right.\n\\end{proof}\n\n\\begin{definition}\n  The number of all set partitions of $\\range{n}$ into nonempty parts\n  is denoted by $B(n)$, and is called the \\emph{$n$th Bell number}.\n  (We define $B(0) = 0$).\n\\end{definition}\n\\nomenclature[C]{$B(n)$}{denotes the $n$th Bell number; i.e.\nthe number of partitions of $\\range{n}$ into nonempty blocks}\n\n\nIt is easy to see that the following theorem holds.\n\\begin{theorem}\n  For any $n \\ge 0$,\n  \\[\n    B(n) = \\sum_{k = 0}^n \\stirlingTwo{n}{k}.\n  \\]\n\\end{theorem}\n\nHowever, it is also possible to express the Bells numbers in terms\nof themselves.\n\\begin{theorem}\n  For any $n \\ge 0$,\n  \\[\n    B(n + 1) = \\sum_{i = 0}^n \\binom{n}{i} B(i).\n  \\]\n\\end{theorem}\n\\begin{proof}\n  Note that there are $B(n + 1)$ ways to split $\\range{n + 1}$ into\n  non-empty blocks. At the same time there are $\\binom{n}{n - i}$\n  ways to select elements to put with $n + 1$ in the same block\n  (if we know that there are $n - i$ elements with $n + 1$ in the block)\n  and $B(i)$ ways to split the rest into blocks. As a result,\n  there are $\\sum_{i = 0}^n \\binom{n}{i} B(i)$ to split $\\range{n + 1}$\n  into nonempty blocks.\n\\end{proof}\n\n\\section{Composition}\nThis section answers the question in the case when the objects\nare the same but boxes are different. Since all the objects\nare identical, only the number of objects in each box matters.\n\n\\begin{definition}\n  A sequence $(a_1, \\dots, a_k)$ of nonnegative integers such\n  that $a_1 + \\dots + a_k = n$ is called a \\emph{weak composition}\n  of $n$ into $k$. If, in addition, all the numbers are positive,\n  the sequence is called a \\emph{composition}.\n\\end{definition}\n\nUsing the binomial coefficients we can find the number of weak\ncompositions.\n\\begin{theorem}\n  For all positive integers $n$ and $k$,\n  the number of weak compositions of $n$ into $k$ is equal to\n  $\\binom{n + k - 1}{n}$.\n\\end{theorem}\n\\begin{proof}\n  Let us consider $k$ boxes in line one after each other. Note that if we\n  put balls inside of the boxes we see a line consisting of $n$ balls and\n  $k - 1$ walls separating the $k$ boxes from each other. Note that simply\n  knowing in which order the n identical balls and $k - 1$ separating walls\n  follow each other is the same as knowing the number of balls in each box.\n  So our problem is equivalent to counting the number of ways to put $k - 1$\n  walls on one of $n + k - 1$ positions.\n\\end{proof}\n\nAs a result, we can count the number of compositions.\n\\begin{corollary}\n  For all positive integers $n$ and $k$,\n  the number of compositions of $n$ into $k$ is equal to\n  $\\binom{n - 1}{k - 1}$.\n\\end{corollary}\n\n\\begin{exercise}\n  Let $\\ell_1$, \\dots, $\\ell_k$ be some nonnegative numbers\n  such that $\\ell_1 + \\dots + \\ell_k = \\ell$.\n  Find the number of weak compositions (in terms of $\\ell$, $k$, and $n$)\n  $(a_1, \\dots, a_k)$ of $n$ into $k$ such that $a_i \\ge \\ell_i$.\n\\end{exercise}\n\n\\begin{corollary}\n  The number of all compositions of $n$ is equal to $2^{n - 1}$.\n\\end{corollary}\n\n\\section{Integer Partitions}\nNow consider the case when both objects and boxes are identical. In this case,\nas in the previous we are only interested in numbers of objects in boxes, but\nin addition, we are not interested in an order of these numbers.\n\n\\begin{definition}\n  Let $n$ and $a_1 \\ge a_2 \\ge \\dots \\ge a_k \\ge 1$ be integers so that\n  $a_1 + \\dots a_k = n$. Then the sequence $(a_1, \\dots, a_k)$ is called\n  a \\emph{partition}\\footnote[][-3cm]{%\n    Note that we used the word partition in two different meanings: one to\n    denote a partition of a set $[n]$ and another to denote the partition of\n    an integer $n$. In most of the cases the meaning is clear from the context;\n    however, if it is necessary to emphasize that we mean partition of a set,\n    we say set-partition. Note that in some languages there are two different\n    words for these two notions; e.g in French ``partition'' is used for\n    set-partitions, and ``partage'' for partitions of the integer n).\n  } of the integer $n$ into $k$ parts.\n\n  The number of all the partitions is denoted by $p(n)$ and the number of\n  partitions of $n$ into $k$ parts is denoted by $p_k(n)$.\n\\end{definition}\n\n\\nomenclature[C]{$p_k(n)$}{denotes the number of all the partitions of $n$ into\n$k$ blocks}\n\\nomenclature[C]{$p(n)$}{denotes the number of all the partitions of $n$}\n\n\nThere is no good formula allowing to find the value of $p(n)$. Nevertheless, we will\nprove some properties of $p(n)$. The main tool to explain proofs we are going to\ndiscuss are Young diagrams\\footnote{%\n  A small variation of these diagrams is called Ferrers shapes after an\n  American mathematician Norman Macleod Ferrers.\n}.\nA Young diagram for a partition $(a_1, \\dots, a_k)$ consists of $k$ columns of\nsquares called ``boxes'' such that in the $i$th column there are $a_i$ boxes\n(an example of such a diagram is depicted on \\ref{figure:young-diagram-example}).\n\\begin{figure}\n  \\centering\n  \\subfloat[The Young diagram for the partition $(4, 3, 1, 1)$.]{\n    \\qquad\\qquad$\\yng(4,2,2,1)$\\qquad\\qquad\n  }\n  \\qquad\\qquad\n  \\subfloat[The conjugate of the Young diagram for the partition $(4, 3, 1, 1)$.]{\n    \\qquad\\qquad$\\yng(4,3,1,1)$\\qquad\\qquad\n  }\n  \\caption[][1cm]{Young diagrams.}\n  \\label{figure:young-diagram-example}\n\\end{figure}\nWe can reflect a Young diagram of a partition of $n$ with respect to its main\ndiagonal, we get another shape, representing the \\emph{conjugate} partition of\n$n$ (an example of such transformation is also depicted on\n\\ref{figure:young-diagram-example}).\n\nUsing these diagrams, it is easy to show the following theorem.\n\\begin{theorem}\n  The number of partitions of $n$ into at most $k$ parts is equal to that of\n  partitions of $n$ into parts not larger than $k$.\n\\end{theorem}\n\\begin{proof}\n  Note that if a partition has at most $k$ parts, then the conjugate of this\n  partition has all the parts of size at most $k$. As, a result, the number\n  of partitions of $n$ into at most $k$ parts is equal to that of\n  partitions of $n$ into parts not larger than $k$.\n\\end{proof}\n\n\\begin{chapterendexercises}\n  \\exercise How many sets $S \\subseteq \\range{n}$ such that $S$ does not contain\n    two successive integers (i.e., if $x \\in S$, then $x + 1 \\not\\in S$)?\n  \\exercise How many numbers in $\\range{999999}$ have the sum of digits at most\n    $47$?\n  \\exercise Let $k \\in \\N$. How many sets $S \\subseteq \\range{n}$ of size $k$\n    such that $S$ does not contain two successive integers (i.e., if $x \\in S$,\n    then $x + 1 \\not\\in S$)?\n  \\exercise\n    Let $q(n)$ be the number of partitions of $n$ in which each part is at least\n    two. Then $q(n) = p(n) - p(n - 1)$, for all positive integers $n \\ge 2$.\n  \\exercise[recommended] Find a formula for $\\stirlingTwo{n}{2}$.\n  \\exercise Find a formula for $\\stirlingTwo{n}{3}$.\n    \\begin{solution}\n      In this problem it is easier to find the number of surjections from \n      $\\range{n}$ to $\\range{3}$. There are $3^n$ functions from $\\range{n}$ to\n      $\\range{3}$, there are $3 \\cdot 2^n$ functions from $\\range{n}$ to\n      $\\range{3}$ such that the image has $2$ elements, and there are $3$\n      functions such that their image has $1$ element. Therefore, by the\n      inclusion-exclusion principle, there are $3^n - 3 \\cdot 2^n + 3$\n      surjections from $\\range{n}$ to $\\range{3}$. As a result, \n      $\\stirlingTwo{n}{3} = \\frac{1}{6}(3^n - 3 \\cdot 2^n + 3)$.\n    \\end{solution}\n  \\exercise Find a formula for $\\stirlingTwo{n}{n - 2}$.\n    \\begin{solution}\n      Note that there two variants how we can split $n$ elements into $n - 2$ subsets: \n      \\begin{enumerate}\n        \\item all subsets except one are singletons, there are $\\binom{n}{3}$\n          ways to do this;\n        \\item all subsets except two are singletons, there are $\\binom{n}{4} \\cdot\n          \\binom{4}{2} \\frac{1}{2}$ (we divide by two since the order ot these two\n          sets of size $2$ is not important).\n      \\end{enumerate}\n      Hence, the answer is $\\binom{n}{3} + \\binom{n}{4} \\cdot \\binom{4}{2} \\frac{1}{2}$.\n    \\end{solution}\n  \\exercise[recommended] Show that $B(n) \\le n!$.\n  \\exercise Let $m \\ge n$ be positive integers. Show that\n    \\[\n      \\stirlingTwo{m}{n} = \\sum_{i = 1}^m \\stirlingTwo{m - i}{n - 1} n^{i - 1}.\n    \\]\n  \\exercise Prove that the number of partitions of $n$ into exactly $k$\n    parts is equal to the number of partitions of $n$ in which the\n    largest part is exactly $k$.\n  \\exercise[recommended] Prove that the number of partitions of $n$ into at most\n    $k$ parts is equal to that of partitions of $n + k$ into exactly $k$ parts.\n  \\exercise[recommended] We call a partition $\\set{P_1, \\dots, P_k}$ of\n    $\\range{n}$ nice iff $(j + 1) \\not\\in P_i$ for every $i \\in \\range{k}$ and\n    $j \\in P_i$.\n    Prove that number of nice partitions is equal to $B(n - 1)$.\n    \\begin{solution}\n      Let $\\mathcal{P}_n$ be the set of all partitions of $\\range{n}$ and let\n      $\\mathcal{M}_n$ be the set of all nice partitions of $\\range{n}$. We are\n      going to construct a bijection\n      \\[\n        f : \\mathcal{P}_{n - 1} \\to \\mathcal{M}_n.\n      \\]\n\n      Notice that we can obtain every nice partition of $\\range{n}$ by:\n      \\begin{enumerate}\n        \\item First adding a singleton block $\\set{n}$ to any partition of\n          $\\range{n}$.\n        \\item Then, in each block of that partition of $\\range{n - 1}$, we locate\n          consecutive integers $i, i + 1, \\dots, i + j$ and if $j$ is odd place\n          every other integer, i.e $i, i + 2, i + 4, \\dots, i + j - 1$, into\n          the block with $n$, if $j$ is even we put $i + 1, \\dots, i + j - 1$ into\n          the block with $n$. We do this for each consecutive sequence of each\n          block of each partition of $\\range{n - 1}$ to obtain all possible nice\n          partitions of $\\range{n}$.\n      \\end{enumerate}\n      Note that the resulting partition is nice, since $i + j \\le n - 1$, hence\n      $i + j - 1 < n - 1$.\n\n      For each nice partition of $\\range{n}$ obtained this way we can have an\n      inverse transformation $f^{-1}$ that takes every nice partition of\n      $\\range{n}$ and gives the corresponding original partition of \n      $\\range{n - 1}$ by:\n      \\begin{enumerate}\n        \\item Taking every element except $n$ in the block that contains\n          $n$ and placing each element $i$, in order, into a block that contains\n          $i - 1$.\n        \\item We then remove the block of $n$ from our partition resulting in a\n          partition of $\\range{n - 1}$.\n      \\end{enumerate}\n\n      It can be seen that applying $f^{-1}$ to every partition of $\\mathcal{M}_n$ gives us\n      every partition of $\\mathcal{P}_n$. Thus $f$ forms a bijection between\n      $\\mathcal{M}_n$ and $\\mathcal{P}_{n - 1}$.\n    \\end{solution}\n\\end{chapterendexercises}\n", "meta": {"hexsha": "c9c2f54f3e0aafbb3b31e094bdb6b8b4d6d90191", "size": 17055, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_4/chapter_21_partitions.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_4/chapter_21_partitions.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_4/chapter_21_partitions.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 44.2987012987, "max_line_length": 91, "alphanum_fraction": 0.6446203459, "num_tokens": 5213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.9059898114992677, "lm_q1q2_score": 0.8231985526832384}}
{"text": "\\lab{Algorithms}{Givens Rotations}{Givens Rotations}\n\\label{Ch:Givens Rotations}\n\n\\objective{Learn how to use Givens rotations in numerical computing.}\n\\section*{Givens rotations}\n\nThe matrix $\\begin{pmatrix} cos(\\theta) & -sin(\\theta) \\\\ sin(\\theta) & cos(\\theta) \\end{pmatrix}$ rotates a vector counterclockwise by $\\theta$. Given a vector $x = \\begin{pmatrix} a \\\\ b \\end{pmatrix}$, we can rotate $x$ into the range of $e_1$ by choosing the correct $\\theta$. The problem is equivalent to solving for $c = cos(\\theta)$ and $s = sin(\\theta)$ in the system\n\\begin{equation}\n\\label{eq:Givens rotation system}\n\\begin{pmatrix} c & -s \\\\ s & c \\end{pmatrix} \\begin{pmatrix}a\\\\b\\end{pmatrix} \n= \\begin{pmatrix}r\\\\0\\end{pmatrix}\n\\end{equation}\n In fact, it's not necessary to compute $\\theta$; we solve for $c$ and $s$ directly. An obvious solution is $c = \\frac{a}{\\sqrt{a^2 + b^2}}$ and $s = \\frac{b}{\\sqrt{a^2+b^2}}$. However, a more numerically stable method is \n \n \\begin{pseudo}{Givens rotation solver}{a,b}\n \\label{Alg:Givens rotation solver}\n\\IF b=0 \\THEN c \\GETS copysign(1,a); s \\GETS 0 \n\\ELSEIF a=0 \\THEN c \\GETS 0;s \\GETS -copysign(1,b)\n\\ELSEIF abs(b)>abs(a) \\THEN\n\\BEGIN\n\tt \\GETS a/b\\\\\n\tu \\GETS copysign(sqrt(1+t*t),b)\\\\\n\ts \\GETS -1/u\\\\\n\tc \\GETS -s*t\n\\END\n\\ELSE\n\\BEGIN\n\tt \\GETS b/a \\\\\n\tu \\GETS copysign(sqrt(1+t*t),a)\\\\\n\tc \\GETS 1/u\\\\\n\ts \\GETS -c*t \n\\END\n\\end{pseudo}\\\\\nwhere \\li{copysign(a,b)} returns \\li{a} with the sign of \\li{b} (if this function is not available, use \\li{a*sign(b)}).\n\n\\subsection*{Givens triangularization}\n\nLike Householder, the Givens $QR$ algorithm, \\emph{triangularizes} a matrix $A$ using \\emph{orthogonal transformations}. The Householder $QR$ algorithm worked one column at a time; Givens works one element at a time. Each nonzero below the main diagonal can be zeroed out with a Givens rotation. If we solve for $c$ and $s$ as above, the matrix\n\\begin{equation*}\nG(i,j,c,s) = \n\\begin{pmatrix}\n1   & \\cdots & 0 & \\cdots & 0 & \\cdots & 0 \\\\\n \\vdots & \\ddots & \\vdots &  & \\vdots & & \\vdots \\\\\n0   & \\cdots &    c   & \\cdots &    -s   & \\cdots &    0   \\\\\n \\vdots &        & \\vdots & \\ddots & \\vdots &        & \\vdots \\\\\n 0   & \\cdots &   s   & \\cdots &    c   & \\cdots &    0   \\\\\n\\vdots &        & \\vdots &        & \\vdots & \\ddots & \\vdots \\\\\n0   & \\cdots &    0   & \\cdots &    0   & \\cdots &    1 \n\\end{pmatrix}\n\\end{equation*}\nwhere\n\\[ \\begin{array}{ll}\ng_{i\\, i} = c  & g_{j\\, i}= -s   \\\\\ng_{j\\, j} = c &  g_{i\\, j}= s  \\\\\n\\end{array}\\]\nrotates by $\\theta$ in the $i,j$ plane. Also, it's easy to check that $G(i,j,c,s)$ is orthogonal. Left-multiplying $A$ by $G(i,j,c,s)$ zeroes out $A_{i\\, j}$. For example, \n\n\\[\n\\begin{array}{ccccccc}\n\\begin{pmatrix}\n*&*&*\\\\\n*&*&*\\\\\n*&*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(3,1)}\n&\\begin{pmatrix}\n*&*&*\\\\\n*&*&*\\\\\n0&*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(2,1)}\n&\\begin{pmatrix}\n*&*&*\\\\\n0&*&*\\\\\n0&*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(3,2)}\n&\\begin{pmatrix}\n*&*&*\\\\\n0&*&*\\\\\n0&0&*\n\\end{pmatrix}\n\\end{array}\n\\]\n\nThe Givens QR method is often slower than Householder, because it works one element at a time. But it is faster than Householder when $A$ is sparse, and it is very parallelizable.\n\n\\begin{problem}\nWrite a script that uses Givens rotations to do QR decomposition. By performing successive Givens rotations, triangularize $A$ to find $R$. You can find $Q$ using the chain of rotations.\n\nTo find each rotation, you will have to solve \\eqref{eq:Givens rotation system} for $c$ and $s$. Let $b$ be the element you want to zero out, say $A_{i\\,j}$. Then $a$ is in the same \\emph{column} as $b$, and in the \\emph{row} you want to rotate into (it's like we're squishing the whole vector into $a$'s spot.) You can choose $a$ to be the diagonal element above $b$.\n\\end{problem}\n\n\\begin{problem} \nCompare the MGS, Householder, and Givens algorithms for $QR$ decomposition on various matrices. Try different sizes and different levels of sparsity. Which is the fastest? Which is the most stable?\n\\end{problem}", "meta": {"hexsha": "0caf841bd219248a26ffbbe5c0408c82cd37eced", "size": 3985, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Givens/Givens.tex", "max_stars_repo_name": "jasongrout/numerical_computing", "max_stars_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/Givens/Givens.tex", "max_issues_repo_name": "jasongrout/numerical_computing", "max_issues_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/Givens/Givens.tex", "max_forks_repo_name": "jasongrout/numerical_computing", "max_forks_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-21T23:06:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T23:06:27.000Z", "avg_line_length": 40.2525252525, "max_line_length": 375, "alphanum_fraction": 0.6496863237, "num_tokens": 1435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.9230391611283337, "lm_q1q2_score": 0.8231765113035486}}
{"text": "\\section{Signal-to-noise maximisation}\n\\label{sec:GEVD_SNR}\n\nSuppose all training samples $\\z\\train_t$ are gathered and divided over two\ndata matrices $\\Sm \\in \\reals^{C \\cross N_s}$ and $\\Nm \\in \\reals^{C \\cross\nN_n}$, where $\\Sm$ (for `signal') contains all $N_s$ samples of $\\z\\train_t$\nwhere an SWR was present, and $\\Nm$ (for `noise') contains all $N_n$ other\nsamples. (These matrices can be constructed by simply concatenating all\nsegments in $\\z\\train_t$ where an SWR was present, and all segments where\nthere was no SWR present).\n\nAs described in the previous section, we project the data onto the weight\nvector $\\w$. For the data matrices, this becomes, in vector notation:\n%\n\\begin{align*}\n\\y_s &= \\w^T \\Sm \\\\\n\\y_n &= \\w^T \\Nm,\n\\end{align*}\nwhere each element of the row vectors $\\y_s$ and $\\y_n$ corresponds to one\n(multichannel) sample of $\\Sm$ or $\\Nm$. \\Cref{fig:GEVD_principle} (right)\nshows the distribution of the values in two example data vectors $\\y_s$ and\n$\\y_n$.\n\nWe want to find the weight vector $\\what$ that maximises the variance of\n$\\y_s$ versus the variance of $\\y_n$, i.e.\n%\n\\begin{align}\n\\what &= \\argmax_{\\w} \\frac{\\Var(\\y_s)}\n                           {\\Var(\\y_n)}  \\nonumber \\\\[1em]\n      &= \\argmax_{\\w} \n         \\frac{\\frac{1}{N_s} \\y_s \\y_s^T}\n              {\\frac{1}{N_n} \\y_n \\y_n^T}   \\label{eq:argmax_SNR} \\\\[1em]\n      &= \\argmax_{\\w}\n         \\frac{\\frac{1}{N_s} \\w^T \\Sm \\Sm^T \\w}\n              {\\frac{1}{N_n} \\w^T \\Nm \\Nm^T \\w}  \\nonumber\n\\end{align}\n\nThe signal and noise covariance matrices $\\Rss \\in \\reals^{C \\cross C}$ and\n$\\Rnn \\in \\reals^{C \\cross C}$ are defined as:\\footnotemark{}\n%\n\\begin{align}\n\\Rss &= \\frac{1}{N_s} \\Sm \\Sm^T \\label{eq:covariance_s}\\\\\n\\Rnn &= \\frac{1}{N_n} \\Nm \\Nm^T \\label{eq:covariance_n}\n\\end{align}\n%\n($\\Rss$ and $\\Rnn$ are symmetric. The diagonal elements yield the variance of\neach channel, and the off-diagonal elements yield the covariance between\npairs of channels).\n\n\\footnotetext{To be precise, these are only estimates of the `true'\ncovariance matrices of two random, \\emph{ergodic} variables $\\z_{s,t}$ and\n$\\z_{n,t}$, of which the data in $\\Sm$ and $\\Nm$ are some samples.\n\\Cref{eq:covariance_s,eq:covariance_n} are then correct definitions only in\nthe limit for $N_s \\to \\infty$ and $N_n \\to\n\\infty$.}\n\nThe expression for the optimal weight vector (\\cref{eq:argmax_SNR}) then\nbecomes:\n%\n\\begin{equation}\n\\label{eq:argmax_R}\n\\what = \\argmax_{\\w}\n       \\frac{\\w^T \\Rss \\w}\n            {\\w^T \\Rnn \\w}\n\\end{equation}\n%\nThis quotient of quadratic forms is the `generalised Rayleigh quotient' of\n$\\Rss$ and $\\Rnn$. It reaches its maximum when $\\w$ is the first so caled\n`generalised eigenvector' of $\\Rss$ and $\\Rnn$. The following section defines\nthese terms, and proves the ``$\\argmax$'' --- ``first generalised\neigenvector'' correspondence.\n", "meta": {"hexsha": "7a2fb8a831eae59f98ca38c65b08d32802ca0201", "size": 2829, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/Scraps/GEVD/Max_SNR.tex", "max_stars_repo_name": "tfiers/master-thesis", "max_stars_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-23T01:39:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-23T01:39:24.000Z", "max_issues_repo_path": "modules/Scraps/GEVD/Max_SNR.tex", "max_issues_repo_name": "tfiers/master-thesis", "max_issues_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 46, "max_issues_repo_issues_event_min_datetime": "2018-09-18T16:38:12.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-10T22:37:35.000Z", "max_forks_repo_path": "modules/Scraps/GEVD/Max_SNR.tex", "max_forks_repo_name": "tfiers/master-thesis", "max_forks_repo_head_hexsha": "3e97128eeb18827b03da90817fe6f6985c84ad80", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.2916666667, "max_line_length": 77, "alphanum_fraction": 0.6726758572, "num_tokens": 922, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8757870013740061, "lm_q1q2_score": 0.8231638941955031}}
{"text": "\\subsection{Right-handed systems of vectors}\n\nWe begin with a discussion of right-handed systems of vectors in\n$3$-dimensional space.%\n\\index{right-handed system of vectors}%\n\\index{vector!right-handed system of}\n\n\\begin{definition}{Right-handed system of vectors}{right-hand}\n  Three vectors, $\\vect{u},\\vect{v},\\vect{w}$ form a right-handed\n  system if when you extend the thumb of your right hand in the\n  direction of $\\vect{u}$ and your index finger in the direction of\n  $\\vect{v}$, your relaxed middle finger points roughly in the\n  direction of $\\vect{w}$.\n  \\begin{center}\n    \\raisebox{0.25in}{\n      \\begin{tikzpicture}\n        \\draw[->](0,0,0) -- node[right] {$\\vect{u}$} (0,2,0);\n        \\draw[->](0,0,0) -- node[above] {$\\vect{v}$} (-2,0,0);\n        \\draw[->](0,0,0) -- node[right] {$\\vect{w}$} (0,0,3);\n      \\end{tikzpicture}\n    }\n    \\hspace{1in}\n    \\includegraphics[height=1.8in]{figures/right-handed}\n  \\end{center}\n\\end{definition}\n\nYou should consider how a right-handed system would differ from a\nleft-handed system. Try using your left hand and you will see that the\nvector $\\vect{w}$ would need to point in the opposite direction.\n\nRecall the special vectors $\\vect{i}=\\mat{1,0,0}^T$,\n$\\vect{j}=\\mat{0,1,0}^T$, and $\\vect{k}=\\mat{0,0,1}^T$ we saw in\nSection~\\ref{sec:linear-combinations-rn}. We always assume that our\ncoordinate system is drawn in such a way that the vectors $\\vect{i}$,\n$\\vect{j}$, $\\vect{k}$ form a right-handed system. Thus, if the thumb\nof your right hand points along the $x$-axis and your index finger\npoints along the $y$-axis, your middle finger should point along the\n$z$-axis.\n\n\\begin{center}\n  \\begin{tikzpicture}\n    \\draw[->, thick] (0,0,0)--(2,0,0);\n    \\draw[->, thick] (0,0,0)--(0,2,0);\n    \\draw[->, thick] (0,0,0)--(0,0,2);\n    \\node[below right] at (2,0,0){$\\vect{j}$};\n    \\node[below left] at (0,0,2){$\\vect{i}$};\n    \\node[above right] at (0,2,0){$\\vect{k}$};\n  \\end{tikzpicture}\n\\end{center}\n\n\\noindent\nWhen all three vectors lie in a plane, then we say that the vectors\nare \\textbf{coplanar}%\n\\index{coplanar vectors}%\n\\index{vector!coplanar}. In this case, the system is neither\nright-handed nor left-handed.\n", "meta": {"hexsha": "3bfacb6aee4644242cf27e78b51d3fecd65df005", "size": 2177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-CrossProduct-Righthanded.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Vectors-CrossProduct-Righthanded.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Vectors-CrossProduct-Righthanded.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 38.1929824561, "max_line_length": 70, "alphanum_fraction": 0.6651355076, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005327, "lm_q2_score": 0.911179702173019, "lm_q1q2_score": 0.8230633438669377}}
{"text": "\\section{Identication Trees}\n\n\\paragraph{Identication Tree} An identification tree is a\nrepresntation, that is a decision tree in which:\n\\begin{itemize}\n  \\item Each set of possible conclusion is established implicitly\n    by a list of samples of known class\n\\end{itemize}\n\n\\paragraph{Average disorder}\n\\begin{math}\n  Average(disorder) =\n  \\sum_{b}{\\frac{n_b}{n_t} \\sum_{c}{-\\frac{n_{bc}}{n_b}\\log_{2}\\frac{n_{bc}}{n_b}}}\n\\end{math}\nwhere:\n\\begin{itemize}\n  \\item $n_b$ is the number of samples in brench $b$\n  \\item $n_t$ is the total number of samples in all branches\n  \\item $n_bc$ is the total of samples in branch $b$ of class $c$\n\\end{itemize}\n\nTo generate an identification tree using SPROUTER:\n\\begin{itemize}\n  \\item Until each leaf node is populated by as homogeneous a\n    sample set as possible:\n    \\begin{itemize}\n      \\item Select a leaf node with an inhomogeneous sample set\n      \\item Replace that leaf node by a test node that divides the\n        inhomogeneous sample set into minimally inhomogeneous\n        subsets, according to some measure of disorder\n    \\end{itemize}\n\\end{itemize}\n\nTo convers an identification tree into a rule set, execute the\nfollowing procedure - PRUNER:\n\\begin{itemize}\n  \\item Create one rule for each root-to-leaf path in the\n    identification tree\n  \\item Simplify each rule by discarding antecedents that have no\n    effect on the conclusion reached by the rule\n  \\item Replace those rules that share the most common consequent\n    by a default rule that is triggered when no other rule is\n    triggered. In the eventi of a tie, use some heuristic tie\n    breaker to choose a default rule\n\\end{itemize}\n\n", "meta": {"hexsha": "62385d763522b29427266eff294ef0b3b30dda21", "size": 1657, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "identification_trees.tex", "max_stars_repo_name": "Calcifer777/mit-6034", "max_stars_repo_head_hexsha": "9a0939aba7fa3bba0339c4f30f716b41b3bc878b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "identification_trees.tex", "max_issues_repo_name": "Calcifer777/mit-6034", "max_issues_repo_head_hexsha": "9a0939aba7fa3bba0339c4f30f716b41b3bc878b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "identification_trees.tex", "max_forks_repo_name": "Calcifer777/mit-6034", "max_forks_repo_head_hexsha": "9a0939aba7fa3bba0339c4f30f716b41b3bc878b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.2553191489, "max_line_length": 83, "alphanum_fraction": 0.7386843693, "num_tokens": 444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475778774728, "lm_q2_score": 0.8723473779969194, "lm_q1q2_score": 0.8229267861011581}}
{"text": "\\lab{Essentials}{NumPy}{NumPy}\n\\label{lab:Essentials_NumPy}\n\n\\section*{Why Arrays?}\nLet's begin with a simple demonstration of why arrays are important for numerical computation.\nWhy use arrays when Python already has a reasonably efficient list object?\nIn this demonstration, we will try squaring a matrix.\nThe matrix will be represented as a two dimensional list (i.e. a list of lists).\n\nThe following is a function that will accept two matrices (two dimensional list), $A$ and $B$, and return $AB$ following the usual rules of matrix multiplication.\n\\lstinputlisting[style=python,name=]{arr_mult.py}\nWe can initialize a $k \\times k$ ``array\" of integers like this:\n\\begin{lstlisting}\n: k = 10\n: A = [range(i, i+k) for i in range(0, k**2, k)]\n\\end{lstlisting}\n\n\\begin{problem}\nTime how long this function takes to square matrices for increasing values of \\li{k}.\nIn IPython you can time how long it takes for a line of code to execute by prefacing it with \\li{\\%timeit}, as in \\li{\\%timeit range(100)}.\n\nNow import NumPy and create a NumPy array, \\li{A}, and square it.\n\\li{A*A} does \\emph{not} square the array, but rather multiplies \\li{A} with itself element by element.\nTo get matrix multiplication for NumPy arrays, you must use \\li{np.dot} or the \\li{dot()} method of an array like this:\n\\begin{lstlisting}\nimport numpy as np\nA = np.array([range(i, i+k) for i in range(0, k**2, k)])\nnp.dot(A, A)\n\\end{lstlisting}\nTime how long NumPy takes to square arrays for increasing sizes of \\li{k}.\nWhat do you notice about the time needed to square a two dimensional list vs. a two dimensional NumPy array?\n\\end{problem}\n\n% Below is a comparison of runtimes needed to square a matrix\n% \\begin{center}\n% \\begin{tabular}{|c|l|l|}\n% \\hline\n%  Data Structure & Size & Time (s) \\\\ \\hline\n%  Python List & $1\\times1$ & 0.0000181198 \\\\ \\cline{2-3}\n%       & $10\\times10$ & 0.0002758503 \\\\ \\cline{2-3}\n%       & $100\\times100$ & 0.1336028576 \\\\ \\cline{2-3}\n%       & $1000\\times1000$ & 200.4009799957 \\\\ \\hline \\hline\n%  NumPy Array & $1\\times1$ & 0.0000298023 \\\\ \\cline{2-3}\n%       & $10\\times10$ & 0.0000109673 \\\\ \\cline{2-3}\n%       & $100\\times100$ & 0.0009210110 \\\\ \\cline{2-3}\n%       & $1000\\times1000$ & 2.1682999134 \\\\ \\hline\n% \\end{tabular}\n% \n% \\end{center}\n\nThe reason for the drastic speed difference is that Python, as a high level interpreted language, tends to be slower than lower level compiled languages.\nThe algorithms implemented in NumPy are heavily optimized and are usually implemented in C or Fortran.\nInstead of operating purely in Python, they use Python to run code that is written and optimized in other languages.\nNumPy interfaces with some of the best known packages for doing computational linear algebra and can be used to write relatively fast programs.\n\nLists are still faster for anything that involves a varying lengths of data.\nIf you are appending to your data or deleting items, consider using lists instead of arrays since both of these operations require the creation of a new array.\n\n\\section*{NumPy}\nNumPy is a fundamental package for scientific computing with Python.\nIt provides an efficient $n$-dimensional (arbitrary dimensional) array object for fast computations.\nThese arrays are commonly known as \\emph{ndarrays}.\nThis lab will focus on how to use these powerful objects.\nNumPy is commonly imported as shown below.\nNumPy also provides a matrix object which is designed to behave like matrices in MATLAB.\nIt is strongly encouraged to use NumPy arrays instead of NumPy matrices, despite their convenience.\n\\begin{lstlisting}\n: import numpy as np\n\\end{lstlisting}\nFirst, it will be useful to explain certain concepts and terms used to describe NumPy arrays.\n\n\\subsection*{Arbitrary Dimensions}\nOne, two, and three dimensional arrays are easy to visualize.\nBut how do we visualize a four, ten, or fifteen dimensional array?\nNumPy arrays are best thought of as arrays within arrays.\nA one dimensional array consists of only elements.\nA two dimensional array is really just an array containing arrays which contain elements.\nExtending this metaphor, a three dimensional array is an array of arrays of arrays.\nCan you guess what a five dimensional array is?\nLet's define a random three dimensional array.\n\\begin{lstlisting}\n: arr = np.random.randint(50, size=(5, 4, 3))\n\\end{lstlisting}\nArrays are objects in Python.\nFor those who are familiar with object oriented programming, it is worth noting that many of the functions we discuss here are also implemented as methods of \\li{ndarray} objects.\nTwo simple attributes of arrays that describe the number of elements in an array are \\li{shape} and \\li{size}\n\\li{shape} gives information about the size of the array in each dimension.\n\\li{Size} gives the total number of elements in every dimension of the array.\n\\begin{lstlisting}\n: arr.shape\n(5, 4, 3)\n: arr.size\n60\n\\end{lstlisting}\n\nIf we want to know how much memory an array uses to store its elements, we can use \\li{arr.nbytes}.\nThe number of bytes is dependent on the data type or \\emph{dtype} of the array.\nThe data types that NumPy uses are different from Python data types.\nAn integer in NumPy is not the same as an integer Python.\nRemembering this is vital.\nNumPy uses low level data types to speed up calculations.\nHowever, these data types are susceptible to a problem called \\emph{overflow}.\nA 64 bit integer has enough bits to represent integers between $-2^{63}$ (that's $-9,223,372,036,854,775,808$) and $2^{63} - 1$.\nIf we have an array with $-2^{63}$ and we decide to subtract 1, the integer wraps around and becomes $2^{63} - 1$!  If we wish to reduce memory usage, we can use smaller integer types.\nNumPy has support for 8, 16, 32, and 64 bit integers. \n\\begin{lstlisting}\n: arr.dtype\ndtype('int64')\n: arr.nbytes\n480\n: arr.astype('int32').nbytes\n240\n\\end{lstlisting}\n\nEach element of the array has a unique address that describes its location.\nIndexing always starts at $0$.\nAlso, like Python lists, negative indices are valid and count backwards from the end of the array.\nWe will discuss indexing in more detail later in this lab.\n\\begin{lstlisting}\n: arr[0, 0, 0] #returns the first element of arr\n: arr[-1, -1, -1] #returns the last element of arr\n\\end{lstlisting}\n\n\\section*{Creating Arrays}\nNumPy has several functions for creating and initializing arrays.\nWhen creating an array, we can, optionally, specify the data type that is stored in the array.\nNumPy arrays are homogeneous, meaning that all elements in an array must have the same datatype.\nThe array order dictates how the array is laid out in memory.\nTwo common layouts are C order and Fortran order.\nC ordered arrays are also known as row-major arrays.\nThis means that the fastest changing index corresponds to the rows of the array.\nThis is because rows are stored in contiguous blocks in memory.\nFortran ordered arrays are column-major.\nAnother common way of saying this is that an array is C contiguous or Fortran contiguous.\nNot all arrays are C contiguous or Fortran contiguous, but it is useful to understand the distinction.\nLet's look at a few of the ways we can create arrays in NumPy.\n\\begin{itemize}\n\\item \\li{np.array}: Makes an array from a Python list or tuple.\nCan also be used to make a new array based on an old one, possibly with a changed datatype.\n\\item \\li{np.empty}: Allocates an array of a specific size without initializing the elements.\n\\item \\li{np.empty_like}: Allocates a new uninitialized array with the same shape and type as the input array.\n\\item \\li{np.ones}: Allocates and array and initializes each element to $1$.\n\\item \\li{np.ones_like}: Allocates a new array of ones with the same shape and type as the input array.\n\\item \\li{np.zeros}: Allocates an array and initializes each element to $0$.\n\\item \\li{np.zeros_like}: Allocates a new array of zeros with the same shape and type as the input array.\n\\item \\li{np.identity}: Allocates a 2D array with ones along the main diagonal and zeros everywhere else.\n\\item \\li{np.random.rand}: Allocates an array of random floating point values between 0 and 1.\n\\end{itemize}\n\n\\subsection*{Universal Functions (ufuncs)}\nNumPy and SciPy include a wide variety of functions that are designed to operate on arrays.\nThere are simple examples like \\li{sin}, \\li{cos}, \\li{sqrt}, \\li{exp}, and \\li{log} all the way to special functions like \\li{polygamma} in the \\li{scipy.misc} submodule.\nThere are far more functions available in NumPy than could possibly be included here, so you will want to become familiar with the NumPy and SciPy documentation at \\url{docs.scipy.org/doc/}.\nIf you need to do any sort of simple operation on an array, there is very often a function there to do it.\nThese functions are almost always faster and more convenient than iterating through the whole array.\n\nMost of these functions also allow you to specify an array for the output.\nIt is useful in cases where you would like to avoid unnecessary memory allocation.\nThe output array does need to be the correct shape to store the output.\nFor example:\n\\begin{lstlisting}\n: np.exp(A, out=A) #take exp(A) and store result in A\n\\end{lstlisting}\n\nOther useful examples are \\li{max}, \\li{min}, \\li{absolute}, and \\li{average}.\nEach of these operations also allows you to specify whether you want to operate across a particular axis or over the whole array.\nFor example:\n\\begin{lstlisting}\n: np.max(A, axis=0) #max along axis 0\n\\end{lstlisting}\nThe above example returns a row of A which represents the maximum of all the rows of A.\nIf we had set \\li{axis=1}, it would have taken the maximum of all the columns.\nIf, for purposes of broadcasting (discussed later) you need the output of one of these functions to have the same number of dimensions as the original array, you can also include the argument \\li{keepdims=True}.\n\n\\subsection*{Indexing Arrays}\n\\subsubsection*{Array Views and Copies}\nBefore we begin accessing arrays, it is important to understand that NumPy has two ways of slicing an array.\nSlice operations always return a \\emph{view} and fancy indexing always returns a \\emph{copy}.\nUnderstand that even though they may look the same, views and copies are very different.\n\nViews are special arrays that reference other arrays.\nChanging elements in a view changes the array it references.\nBelow, we demonstrate the behavior of a view.\nNotice that \\li{c} looks like a copy of \\li{b} even though it is not.\n\\begin{lstlisting}\n: b = np.reshape(np.arange(25), (5,5))\n: b\narray([[ 0,  1,  2,  3,  4],\n       [ 5,  6,  7,  8,  9],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19],\n       [20, 21, 22, 23, 24]])\n: c = b[:] #looks like c is a copy of b\n: c\narray([[ 0,  1,  2,  3,  4],\n       [ 5,  6,  7,  8,  9],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19],\n       [20, 21, 22, 23, 24]])\n: id(c) == id(b) #We have unique objects\nFalse\n: c[2] = 500\n: c\narray([[  0,   1,   2,   3,   4],\n       [  5,   6,   7,   8,   9],\n       [500, 500, 500, 500, 500],\n       [ 15,  16,  17,  18,  19],\n       [ 20,  21,  22,  23,  24]])\n: b #changing c also changed b!\narray([[  0,   1,   2,   3,   4],\n       [  5,   6,   7,   8,   9],\n       [500, 500, 500, 500, 500],\n       [ 15,  16,  17,  18,  19],\n       [ 20,  21,  22,  23,  24]])\n\\end{lstlisting}\nThe reason that changing the array \\li{c} also changed the array \\li{b} is because \\li{c} and \\li{b} share the same memory, even though they are different Python objects.\nViews reduce the overhead of making copies of arrays and are useful when we want to change certain parts of the array.\n\nA copy of an array is a separate array that is allocated separately.\nAn array can be copied using the \\li{copy()} function.\n\\begin{lstlisting}\n: b = np.reshape(np.arange(25), (5, 5))\n: b\narray([[ 0,  1,  2,  3,  4],\n       [ 5,  6,  7,  8,  9],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19],\n       [20, 21, 22, 23, 24]])\n: c = np.copy(b)\n: c is b #we still have separate objects\nFalse\n: c[2] = 500\n: c\narray([[  0,   1,   2,   3,   4],\n       [  5,   6,   7,   8,   9],\n       [500, 500, 500, 500, 500],\n       [ 15,  16,  17,  18,  19],\n       [ 20,  21,  22,  23,  24]])\n: b\narray([[ 0,  1,  2,  3,  4],\n       [ 5,  6,  7,  8,  9],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19],\n       [20, 21, 22, 23, 24]])\n\\end{lstlisting}\nChanging the data in a copy of an array, doesn't change the data in the original array.\nThe two arrays address different locations in memory.\n\n\\subsubsection*{Slices}\nEach element of an array has a unique address that we can use to retrieve that element.\nIndexing and slicing of NumPy arrays follows syntax that is similar to the syntax used with Python lists.\nWe will demonstrate on a simple 2D array.\nRemember that slicing arrays always return a view of an array.\n\\begin{lstlisting}\n: arr = np.reshape(np.arange(25), (5,5))\n: arr\narray([[ 0,  1,  2,  3,  4],\n       [ 5,  6,  7,  8,  9],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19],\n       [20, 21, 22, 23, 24]])\n: arr[0, 0] #access the first element\n0\n: arr[-1, -1] #access the last element\n24\n: arr[0] #access the first row\narray([0, 1, 2, 3, 4])\n\\end{lstlisting}\nWe can access ranges of elements using Python lists.\nWe can also more concisely select ranges using the \\li{arr[start:stop:step]} range notation.\n\\begin{lstlisting}\n: arr[::2] #get every other row, equivalent to arr[range(0, len(arr), 2)]\narray([[ 0,  1,  2,  3,  4],\n       [10, 11, 12, 13, 14],\n       [20, 21, 22, 23, 24]])\n: arr[::2, ::2] #get every other row and every other column\narray([[ 0,  2,  4],\n       [10, 12, 14],\n       [20, 22, 24]])\n: arr[3:, 3:] #extract lower right 2x2 subarray\narray([[18, 19],\n       [23, 24]])\n: arr[:, 1] #extract second column\narray([ 1,  6, 11, 16, 21])\n\\end{lstlisting}\nOperations like those above are called array slicing.\nArray slices are views of portions of the data of the original array.\nThey do not copy any data.\n\n\\subsubsection*{Fancy Indexing}\nWhen the indexing object is a list or an array, NumPy behaves a little differently.\nThis feature is commonly referred to as fancy indexing.\nOne difference is that fancy indices always return a copy of an array instead of a view.\nThere are two types of fancy indexing: boolean and integer.\nBoolean indexing returns an array of \\li{True} or \\li{False} values depending on some evaluating condition.\n\\begin{lstlisting}\n: bmask = (arr > 15) & (arr < 23)\n: bmask\narray([[False, False, False, False, False],\n       [False, False, False, False, False],\n       [False, False, False, False, False],\n       [False,  True,  True,  True,  True],\n       [ True,  True,  True,  False,  False]], dtype=bool)\n: arr[bmask]\narray([16, 17, 18, 19, 20, 21, 22])\n: arr[(arr > 15) & (arr < 23)] #this is the shortened form\narray([16, 17, 18, 19, 20, 21, 22])\n: arr[~bmask] #invert the mask\narray([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 23, 24])\n\\end{lstlisting}\n\\begin{lstlisting}\n: arr[(0, 2, 4), (0, 2, 4)] #grab every other element of diagonal\narray([ 0, 12, 24])\n: arr[range(0, 5, 2), range(0, 5, 2)] #same as above, but with ranges\narray([ 0, 12, 24])\n: arr[:, [0, -1]] #grab first and last column\narray([[ 0,  4],\n       [ 5,  9],\n       [10, 14],\n       [15, 19],\n       [20, 24]])\n\\end{lstlisting}\n\nThough fancy indexing does not return a view of the array, it \\emph{can} be used for assignment.\nFor example, we will set all values of an array that are less than .5 to 0 as follows:\n\\begin{lstlisting}\n: from numpy.random import rand\n: A = rand(10, 10)\n: A[A<.5] = 0.\n\\end{lstlisting}\n\n\\begin{problem}\nGenerate a random $1000 \\times 1000$ array \\li{A}.\nNow create an uninitialized array \\li{B} with all the same attributes as \\li{A}.\nNow do the following 100 times:\n\\begin{itemize}\n\\item Overwrite \\li{B} so that it is an array of new random values like \\li{A}.\nThis can be done like this: \\li{B[:] = rand(1000,1000)}\n\\item Use fancy indexing to make \\li{A} the maximum of \\li{A} and \\li{B}.\n\\end{itemize}\nNow take \\li{exp(A)} and have NumPy store the output directly in \\li{A}.\nTake the maximum along the vertical axis and average the result.\nThe final number should be very close to $e$.\n\\end{problem}\n\n\\section*{The Transpose and Other Useful Operations}\nYou may have noticed that we already used the \\li{reshape()} function.\nIt allows us to make a new view of our array with a desired shape.\nThe new shape must make an array of the same size as the original array.\nIf we need to take the transpose of an array \\li{A}, we can use the transpose attribute of the array, \\li{A.T}, which will give us a new view of the same array with the order of the dimensions reversed.\nThe NumPy \\li{transpose()} function will also do this.\nRemember that both of these methods will return views of the original array and not new arrays.\n\nThe functions \\li{flatten}, \\li{vstack}, \\li{hstack}, and \\li{copy} are examples of functions that will return new arrays.\nGiven a $3 \\times 3$ array, \\li{flatten} will return a new copy of the array with shape \\li{(9,)}, \\li{vstack} will return a new copy of the array with shape \\li{(9,1)}, \\li{hstack} will return a new copy of the array  with shape \\li{(1,9)}, and \\li{copy} will return an exact copy of the array.\n\nThe syntax \\li{A[:]} will return a new view of \\li{A} that is identical to \\li{A}.\nThis doesn't sound all that useful, but if you want to override the values in an array this syntax can be extremely useful.\nFor example:\n\\begin{lstlisting}\n: import numpy as np\n: from numpy.random import rand\n: A = rand(100)\n: B = rand(100)\n: A[:] = 0 #sets each entry in A to 0\n: A[:] = B #copies the data from B into A\n\\end{lstlisting}\n\n\\begin{problem}\nOperations that create completely new arrays are generally slower than operations that create views because they have to copy all of the data from the original array.\nCreate a $1000 \\times 1000$ array \\li{A} of floating point values.\nCompare the speed of the operations \\li{A.reshape(A.size)} and \\li{A.flatten()} (here we are calling the methods of the arrays, these are the same as \\li{np.reshape(A, A.size)}, and \\li{np.flatten(A)} respectively).\nWhy is there such a difference in speed?\nWhat is the difference between their output?\nWhat about \\li{A.reshape((1,A.size))}?\n\nNow let \\li{A} be the an array with shape \\li{(1,1000000)}.\nWhat is the difference in the output between \\li{np.vstack(A)} and \\li{A.T}?\nWhich of the two is faster?\n\\end{problem}\n\n\\begin{problem}\nOne good application of array slicing is the Jacobi method for solving Laplace's equation on a square.\nThis is an example of a simple iterative method.\nIn this case we will modify our array in place.\nMake a function that accepts an array and a tolerance as input and does the following:\n\\begin{itemize}\n\\item Copy the array\n\\item Make a variable representing the difference between the arrays.\nInitialize it as the tolerance.\n\\item While the difference is less than or equal to the tolerance\n\\begin{itemize}\n\t\\item set all points that are not on an edge of the new array equal to the average of their 4 immediate neighbors.\nUse the values from the old array for this computation.\nThis should only take one line and should be based entirely on array slicing.\n\t\\item update the difference to be the maximum of the absolute value of the new array minus the old one.\n\t\\item copy the values from the new array into the old one (without creating a new array).\n\\end{itemize}\n\\end{itemize}\n\nNow use the following code to generate a plot of your results\n\\begin{lstlisting}\n: from matplotlib import pyplot as plt\n: from mpl_toolkits.mplot3d import Axes3D\n: n = 100\n: tol = .0001\n: U = np.ones((n, n))\n: U[:,0] = 100\n: U[:,-1] = 100\n: U[0] = 0\n: U[-1] = 0\n: laplace(U, tol)\n: X = np.linspace(0, 1, n)\n: Y = np.linspace(0, 1, n)\n: X, Y = np.meshgrid(X, Y)\n: fig = plt.figure()\n: ax = fig.gca(projection='3d')\n: ax.plot_surface(X, Y, U, rstride=5)\n: plt.show()\n\\end{lstlisting}\n\\end{problem}\n\n\\section*{Array Broadcasting}\nArray broadcasting allows NumPy to work effectively with arrays of sizes that don't match exactly.\nThere are four basic rules to determine the behavior of broadcasted arrays.\n\\begin{remunerate}\n\\item All input arrays of lesser dimension than the input array with largest dimension have 1's prepended to their shapes.\n\\item The size in each dimension of the output shape is the maximum of all the input sizes in that dimension.\n\\item An input can be used in the calculation if its size in a particular dimension either matches the output size in that dimension, or has a value exactly 1.\n\\item If an input has a dimension size of 1 in its shape, the first data entry in that dimension will be used for all calculations along that dimension.\n\\end{remunerate}\nTo broadcast arrays, at least one of the following must be true.\n\\begin{remunerate}\n\\item All input arrays have exactly the same shape.\n\\item All input arrays are of the same dimension and the length of corresponding dimensions match or is 1.\n\\item All input arrays of fewer dimension can have 1 prepended to their shapes to satisfy the second criterion.\n\\end{remunerate}\n\nOne simple example is multiplying a two dimensional array by a set of numbers along its rows or columns.\nRun the following lines of code and consider their output:\n\\begin{lstlisting}\n: import numpy as np\n: A = np.ones((3, 3))\n: B = np.vstack(np.array([1, 2, 3,]))\n: A * B #multiplies the rows of A by each entry of B\narray([[ 1.,  1.,  1.],\n       [ 2.,  2.,  2.],\n       [ 3.,  3.,  3.]])\n: A * B.T #multiplies the columns of A by each entry of B\narray([[ 1.,  2.,  3.],\n       [ 1.,  2.,  3.],\n       [ 1.,  2.,  3.]])\n\\end{lstlisting}\n\nFor a more detailed description of array broadcasting rules, see \\url{http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html}.\n\nWhen working with multi-dimensional arrays, it can be useful to create new views of your arrays that change the order of the dimensions.\nThis will give you greater control over how different arrays are broadcast together.\nThis can be done by taking a transpose, using the \\li{rollaxis} function, or using the \\li{swapaxes} function.\nThe \\li{rollaxis} function will take a given axis and change the ordering of the axes of the array so that that particular axis appears at a new place.\nThe order of the other axes will not be changed.\nThe \\li{swapaxes} function will swap the placement of two axes.\nNote that all three of these options create views of the previous array.\nThere is no copying of data involved.\n\n\\begin{problem}\nExplore array broadcasting.\nCreate an example for each of the three cases where arrays are broadcasted.\nDon't use the example already given.\n\\end{problem}\n\n\\section*{Saving Arrays}\nIt is often useful to save an array as a file.\nNumPy provides several easy methods for saving and loading array data.\n\\begin{table*}[h]\n\\begin{tabular}{|l|l|}\n\\hline\n\\li{np.save(file, arr)} & Save an array to a binary file \\\\\n\\li{np.savez(file, *arrs)} & Save multiple arrays to a binary file \\\\\n\\li{np.savetxt(file, arr)} & Save an array to a text file \\\\\n\\hline\n\\end{tabular}\n\\end{table*}\n\n\\begin{table*}[h]\n\\begin{tabular}{|l|l|}\n\\hline\n\\li{np.load(file)} & Load and return an array from a binary file \\\\\n\\li{np.loadtxt(file)} & Load and return an array from text file \\\\\n\\hline\n\\end{tabular}\n\\end{table*}\n\nLet's practice saving an array to a file and loading it again.\nNote that, when saving an array, NumPy automatically appends the extension \\li{.npy} if it is not already present.\n\\begin{lstlisting}\na = np.arange(30)\nnp.save('test_arr', a)\nnew_a = np.load('test_arr.npy')\nnp.savez('test_multi', a=a, new_a=new_a)\narrs = np.load('test_multi.npz')\n\\end{lstlisting}\nThe variable \\li{arrs} points to a dictionary object with the keys \\li{a} and \\li{new_a} which reference the arrays that have been saved.\nThe \\li{.npz} file extension is the file type used to store multiple arrays.\n\n\\section*{SciPy}\nSciPy is a Python library that provides many easy-to-use, efficient algorithms for all types of scientific computing.\nIt is designed to work with NumPy arrays.\nIt is therefore important to master the use of NumPy arrays.\nMany of the algorithms needed to solve problems in these lab manuals are implemented in SciPy.\nScipy is organized into packages grouped by problem type.\nThere are packages for statistics, optimization, signal processing, linear algebra, etc.\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{|l|l|}\n\\hline\ncluster & Clustering package \\\\\nconstants & Physical and mathematical constants and units \\\\\nfftpack & Fast Fourier transforms \\\\\nintegrate & Integration package \\\\\ninterpolate & Interpolation package \\\\\nio & Data input/output from various formats \\\\\nlinalg & Linear algebra functions \\\\\nmisc & Various utilities that can't be classified elsewhere \\\\\nndimage & Multi-dimensional image processing \\\\ \nodr & Orthogonal distance regression \\\\\noptimize & Optimization and root finding \\\\\nsignal & Signal processing package \\\\\nsparse & Two dimensional sparse matrices \\\\\nsparse.linalg & Sparse matrix linear algebra functions \\\\\nsparse.csgraph & Fast graph algorithms based on sparse matrices \\\\\nspatial & Spatial algorithms and data structures \\\\ \nspecial & Special functions \\\\ \nstats & Statistical functions \\\\\nmstats & Statistical functions for masked arrays \\\\\n\\hline\n\\end{tabular}\n\\caption{SciPy subpackages}\n\\end{table}\n\nOne of the primary packages that we will be using is \\li{scipy.linalg}.\nEven though NumPy also has \\li{numpy.linalg}, using \\li{scipy.linalg} is preferred.  \nReasons for this include the fact that \\li{scipy.linalg} is more fully featured and is always compiled with BLAS/LAPACK support (this support is optional in NumPy).\nNumPy's linear algebra library should only be used to avoid adding scipy as a dependency.\nLet's look at a few of the routines in SciPy's linear algebra module.\n\\begin{lstlisting}\n: import numpy as np\n: from scipy import linalg as la\n: arr = np.array([[2, 3], [5, 7]])\n: la.det(arr) #find the determinant of arr\n-1.0000000000000018\n: la.inv(arr) #find the inverse of arr\narray([[-7.,  3.],\n       [ 5., -2.]])\n: la.eig(arr) #return eigenvalues and corresponding eigenvectors\n(array([-0.10977223+0.j,  9.10977223+0.j]),\n array([[-0.81797819, -0.38876264],\n       [ 0.57524923, -0.92133794]]))\n\\end{lstlisting}\n\nThere are also many extension packages for more specialized problems such as machine learning and natural language processing.\nThese packages are called \\emph{SciKits}.\nThese kits augment the functionality of SciPy.\nThey are designed to work efficiently with NumPy arrays.\nSome portions of these packages may someday be included in SciPy itself, but many of these packages are still incomplete or in development.\nHowever, they can still be useful.\nThe following are some of the packages currently included as scikits.\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{|l|l|}\n\\hline\nscikit-aero & Aeronautical engineering routines \\\\\nscikit-commpy & Digital communications in Python \\\\\nscikit-fmm & Fast marching method implementation \\\\\nscikit-image & Image processing functions \\\\\nscikit-learn & Machine learning and data mining routines \\\\\nscikit-rf & RF/Microwave engineering routines \\\\\nann & Approximate nearest neighbor search using KDTrees \\\\\naudiolab & Make noise from NumPy arrays \\\\\nbootstrap & Bootstrap confidence interval estimation \\\\\nbvp1lg & Multi-point boundary value problem solver \\\\\nbvp\\_solver & Two-point boundary value problem solver \\\\\ncuda & Python interface to CUDA libraries \\\\\ndatasmooth & Data smoothing routines \\\\\neartho & Earth observation functions \\\\\nfitting & Data fitting framework \\\\\nhydroclimpy & Environmental time series for Python \\\\\nodes & Ordinary differential equation solver for Python \\\\\nsamplerate & High quality audio resampling \\\\\nscattpy & Light scattering methods for Python \\\\\nsparse & Sparse matrix package \\\\\nstatsmodels & Statistical computations and models \\\\\ntalkbox & Set of routines for speech/signal processing \\\\\ntimeseries & Time series manipulation \\\\\nvectorplot & Vector fields plotting algorithms \\\\\n\\hline\n\\end{tabular}\n\\caption{SciKits extend the functionality of SciPy.}\n\\end{table}\n", "meta": {"hexsha": "be31140953b2bbcd051d9c81a01661cd4bfa1f3c", "size": 28023, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/Arrays/Arrays.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Python/Arrays/Arrays.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Python/Arrays/Arrays.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.705, "max_line_length": 295, "alphanum_fraction": 0.7229061842, "num_tokens": 7867, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278602705732, "lm_q2_score": 0.9324533083911025, "lm_q1q2_score": 0.8228227777257775}}
{"text": "\\section{Properties of Norms}\n\n\\section{$L^p$ Lebesgue Vector Norms}\n\\label{sec:lpnorms}\n\nLet $p\\geq1$ be a real number, then the $p$-norm or $L^p$ norm of a vector $\\mathbf{x}\\in\\mathbb{C}^n$ is defined as:\n\n\\begin{equation}\n||\\mathbf{x}||^p = \\left[ \\sum^n_i |x_i|^p \\right]^{1/p}\n\\end{equation}\n\nThe expression can still be useful for $0<p<1$, but in that case the result is not a proper norm, because it is not subadditive (does not satisfy $f(x+y) \\leq f(x) + f(y)$). $p$-norms are closely related to expressions for the generalized mean.\n\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{unitsets.png}\n    \\caption{Unit Circles: Level sets $\\{\\mathbf{x}: ||\\mathbf{x}||_q = 1\\}$ for different $L^q$ norms.}\n    \\label{fig:unitsets}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{dispersionmetrics.png}\n    \\caption{Distance metrics base for different $L^q$ norms.}\n    \\label{fig:unitsets}\n\\end{figure}\n\n\n\\subsection{$L^{1}$ Taxicab / Manhattan Norm}\n\\label{sec:l1norm}\n\\begin{equation}\n||\\mathbf{x}||^1 = \\sum_i |x_i|\n\\end{equation}\n\nIn the context of regression, $L^1$ loss gives the maximum likelihood estimator under the assumption of Laplacian (double exponential) distributed errors. For a dataset $\\mathbf{x}\\in S$, minimizing $\\argmin_{\\mathbf{s}} \\sum_{\\mathbf{x}\\in S}||\\mathbf{x}-\\mathbf{s}||_{1}$ gives the median.\n\n\n\\subsection{$L^{2}$ Euclidian Norm}\n\\label{sec:l2norm}\n\\begin{equation}\n||\\mathbf{x}||^2 = \\sum_i |x_i|^2\n\\end{equation}\n\n\nIn the context of regression, $L^2$ loss gives the maximum likelihood estimator under the assumption of normally distributed errors. For a dataset $\\mathbf{x}\\in S$, minimizing $\\argmin_{\\mathbf{s}} \\sum_{\\mathbf{x}\\in S}||\\mathbf{x}-\\mathbf{s}||_{2}$ gives the mean.\n\nI believe that $L^2$ norm should be the only norm that preserves the distance between two points under rotations of the coordinate system.\t\n\n\\subsection{$L^{\\infty}$ Maximum Norm} \n\n\\begin{equation}\n||\\mathbf{x}||^{\\infty} = \\max(x_1,x_2,...,x_n)\n\\end{equation}\n\nFor a dataset $\\mathbf{x}\\in S$, minimizing $\\argmin_{\\mathbf{s}} \\sum_{\\mathbf{x}\\in S}||\\mathbf{x}-\\mathbf{s}||_{\\infty}$ gives the average of the maximum and the minimum value of the dataset.\n\n\n\\subsection{$L^{-\\infty}$ Minimum Norm} \n\nFormally, I only came across values $0<p$, but it is my opinion that $-\\infty$ picks out the minimum value:\n\n\\begin{equation}\n||\\mathbf{x}||^{-\\infty} = \\min(x_1,x_2,...,x_n)\n\\end{equation}\n\n\n\n\n\n\\section{Operator and Matrix Norms}\n\\label{sec:norms}\n\nMatrix norms are functions $||\\cdot||: K^{m\\times n} \\rightarrow \\mathbb{R}$ where $K$ is a field of real or complex numbers. They satisfy:\n\n\\begin{itemize}\n\\item $||\\alpha A|| = |a| ||A||$ (absolutely homogenous)\n\\item $||A+B|| \\leq ||A|| + ||B||$ (triangle inequality, subadditivity)\n\\item $||A||\\geq 0$ (positive valued)\n\\item $||A||=0 \\implies A_{n,m}=0$ (definiteness)\n\\end{itemize}\n\nA norm is submultiplicative if it satisfies $||AB||\\leq||A||||B||$, which \\citeasnoun{rgeraNotes} calls a requirement of \"useful matrix norms\".\n\n\\subparagraph{} \nThe main risk of confusion is that norms for operators and vectors are different animals. Norms for operators normally measure some relationship between input and output. Norms for vectors are normally some kind of size, length or distance metric. In as far as matrices can be thought of as both operators and multidimensional vectors, norms of either type may be applied to them. People's notation and language is all over the place. Below I've used $||\\cdot||_{(\\alpha)}$ to denote norms in the operator sense and $||\\cdot||_{\\alpha}$ in the vector sense. \n\n\\subsection{$||\\mathbf{A}||_{(\\alpha)}$ Operator Norm}\n\\label{sec:operatornorm}\nThe operator norm describes the largest change in size that it may impart on any of its inputs. That means that the operator norm is defined with respect to a definition of size in both domain and codomain. I.e., for an operator $\\mathbf{A}$ and a given way of measuring size $||\\cdot||_{\\alpha}$:\n\n\\begin{equation}\n||\\mathbf{A}||_{(\\alpha)} = \\sup\\left\\{\\frac{||\\mathbf{A}\\mathbf{v}||_{\\alpha}}{||\\mathbf{x}||_{\\alpha}}: \\mathbf{v} \\in V\\right\\}\n\\end{equation}\n\nWhen the operator is given by a matrix $\\mathbf{A}$, and the length of the vector $\\mathbf{x}$ is measured using the usual euclidian 2-norm ($||\\cdot||_{2}$), then the operator norm is given by the square root of the largest eigenvalue of $\\mathbf{A^T A}$. In that case, the operator norm is the same as the 2-norm (cf. section \\ref{sec:2norm}).\n\nTo re-emphasize, $||A||_{(q)}$ and $||A||_q$ are two different things. The former measures the change in input size, where the size of the input is measured according to the latter. That is the reason for why the 1-Norm and 2-Norms are so different from the vector norms $L_1$ and $L_2$.\n\nOperators that preserve the length of a vector with respect to some norm $||\\cdot||_{\\alpha}$ satisfy $||\\mathbf{A}||_{(\\alpha)} = 1$ and are called isometries (cf. section \\ref{sec:isometric}). \n\n% q-norm\n\\subsection{$||\\mathbf{A}||_q$ $q$-Norms}\n\\label{sec:qnorms}\n\nThe $q$ norms for a matrix $\\mathbf{A} \\in \\mathbb{R}^{m\\times n}$ with entries $a_{i,j}$ in row $i$ and column $j$ are defined:\n\n\\begin{equation}\n||\\mathbf{A}||_q = \\left(\\sum_{i}\\sum_{j} a^q_{i,j}\\right)^{1/q}\n\\end{equation}\n\nFor $q=2$, this becomes the Frobenius norm (section \\ref{sec:frobenius}). For vectors $\\mathbf{v}\\in\\mathbb{R}^{n}$, the $q$-norm is more known as $p$-norm or $L^p$ norm (cf. section \\ref{sec:lpnorms}). \n\n\n% frobenius\n\\subsection{$||\\mathbf{A}||_F$ Frobenius Norm}\n\\label{sec:frobenius}\nThe Frobenius Norm is the sum of the squares of all entries of a matrix. Let $\\mathbf{A} \\in \\mathbb{R}^{m\\times n}$ be a matrix with entires $a_{i,j}$ in row $i$ and column $j$, then:\n\n\\begin{equation}\n||\\mathbf{A}||_F = \\sqrt{\\sum_{i}\\sum_{j} a^2_{i,j}}\n\\end{equation}\n\nThe Frobenius norm is invariant under rotations, and $||\\mathbf{A}||_F = \\sqrt{\\sum_i \\sigma_i^2}$ where $\\sigma_i$ are the singular values of $\\mathbf{A}$. \n\n\\subsection{$||\\mathbf{A}||_{(1)}$ (1)-Norm}\nLet $\\mathbf{A}$ be a matrix with entires $a_{i,j}$ in row $i$ and column $j$, then:\n\n\\begin{equation}\n||\\mathbf{A}||_{(1)} = \\max_{1\\leq j \\leq n} \\sum^m_{i=1} |a_{i,j} |\n\\end{equation}\n\nThat is, it is the maximum of the sums of the absolute values of any of the columns of $\\mathbf{A}$.\n\n\\subsection{$||\\mathbf{A}||_{(\\infty)}$ ($\\infty$)-Norm}\n\nLet $\\mathbf{A}$ be a matrix with entires $a_{i,j}$ in row $i$ and column $j$, then:\n\n\\begin{equation}\n||\\mathbf{A}||_{(\\infty)} = \\max_{1\\leq i \\leq m} \\sum^n_{j=1} |a_{i,j} |\n\\end{equation}\n\nThat is, it is the maximum of the sums of the absolute values of any of the rows of $\\mathbf{A}$.\n\n\\subsection{$||\\mathbf{A}||_{(2)}$ (2)-Norm}\n\\label{sec:2norm}\n\nLet $\\mathbf{A} \\in \\mathbb{R}^{m\\times n}$ be a matrix with entires $a_{i,j}$ in row $i$ and column $j$, then:\n\n\\begin{equation}\n||A||_{(2)} = \\max_{\\mathbf{x}\\neq 0} \\frac{||\\mathbf{Ax}||_2}{||\\mathbf{x}||_2}\n\\end{equation}\n\nWhich is the square root of the largest eigenvalue of $A^T A$. Or, equivalently, $||A||_{(2)} = \\sigma_1$, where $\\sigma_1$ is the largest singular value of the SVD of $\\mathbf{A} = \\mathbf{U\\Sigma V}^T$. That means that $||A^{-1}|| = \\frac{1}{\\sigma_n}$, where $\\sigma_n$ is the smallest singular value of the SVD of $\\mathbf{A}$. \n\n\n% nuclear norm\n\\subsection{$||\\mathbf{A}||_{*}$ Nuclear Norm}\n\\label{sec:nuclearnorm}\nThe nuclear norm of a matrix is the sum of its singular values. This is equivalent to the Schatten-1 Norm. Optimization problems that involve rank restriction tend to be non-convex. The nuclear norm is a convex alternative that can make such problems tractable.\n\n\\begin{equation}\n||\\mathbf{A}||_{*} = \\sum_i \\sigma_i \n\\end{equation}\n\n", "meta": {"hexsha": "f328de921fa11b49adbf76271889feb5ccebe2cc", "size": 7763, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/linalg_norms.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/linalg_norms.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/linalg_norms.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.765060241, "max_line_length": 558, "alphanum_fraction": 0.6883936622, "num_tokens": 2578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178928, "lm_q2_score": 0.9136765240013699, "lm_q1q2_score": 0.8227929247398934}}
{"text": "\\subsection{Draw}\n\n$draw(f,x)$ draws a graph of the function $f$ of $x$.\nThe second argument can be omitted when the dependent variable\nis literally $x$ or $t$.\nThe vectors $xrange$ and $yrange$ control the scale of the graph.\n\n{\\color{blue}\n\\begin{verbatim}\ndraw(x^2)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.2]{parabola.png}\n\\end{center}\n\n{\\color{blue}\n\\begin{verbatim}\nxrange = (-1,1)\nyrange = (0,2)\ndraw(x^2)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.2]{parabola2.png}\n\\end{center}\n\n\\noindent\nParametric drawing occurs when a function returns a vector.\nThe vector $trange$ controls the parametric range.\nThe default is $trange=(-\\pi,\\pi)$.\nIn the following example, $draw$ varies $theta$\nover the default range $-\\pi$ to $+\\pi$.\n\n{\\color{blue}\n\\begin{verbatim}\nxrange = (-10,10)\nyrange = (-10,10)\nf = (cos(theta),sin(theta))\ndraw(5 f,theta)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.2]{circle.png}\n\\end{center}\n\n\\noindent\nIn the following example, $trange$ is reduced\nto draw a quarter circle instead of a full circle.\n\n{\\color{blue}\n\\begin{verbatim}\ntrange = (0,pi/2)\nf = (cos(theta),sin(theta))\ndraw(5 f,theta)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.2]{circle2.png}\n\\end{center}\n\n\\noindent\nHere are a couple of interesting curves and the code for drawing them.\nFirst is a lemniscate.\n\n{\\color{blue}\n\\begin{verbatim}\ntrange = (-pi,pi)\nX = cos(t)/(1 + sin(t)^2)\nY = sin(t) cos(t)/(1 + sin(t)^2)\nf = (X,Y)\ndraw(5 f,t)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.2]{lemniscate.png}\n\\end{center}\n\n\\noindent\nNext is a cardioid.\n\n{\\color{blue}\n\\begin{verbatim}\nr = (1 + cos(t))/2\nu = (cos(t),sin(t))\nxrange = (-1,1)\nyrange = (-1,1)\ntrange = (0,2 pi)\ndraw(r u,t)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.2]{cardioid.png}\n\\end{center}\n", "meta": {"hexsha": "8ecb1b65e496305d2647986761726171d8a2ac98", "size": 1831, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/draw.tex", "max_stars_repo_name": "franko/eigenmath", "max_stars_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-01-27T02:41:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-02T19:05:49.000Z", "max_issues_repo_path": "doc/draw.tex", "max_issues_repo_name": "franko/eigenmath", "max_issues_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-01-29T14:09:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-13T16:17:03.000Z", "max_forks_repo_path": "doc/draw.tex", "max_forks_repo_name": "franko/eigenmath", "max_forks_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-27T02:38:38.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-27T02:38:38.000Z", "avg_line_length": 18.1287128713, "max_line_length": 70, "alphanum_fraction": 0.6897870016, "num_tokens": 616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.8872045966995028, "lm_q1q2_score": 0.8227609733649691}}
{"text": "\\chapter{Solving Quadratics}\n\nA quadratic function has three terms: $ax^2 + bx + c$. $a$, $b$, and\n$c$ are known as the \\textit{coefficents}. The coefficients can be any\nconstant, except that $a$ can never be zero. (If $a$ is zero, it is a linear\nfunction, not a quadratic.)\n\nWhen you have an equation with a quadratic function on one side and a\nzero on the other, you have a quadratic equation. For example:\n\n$$72x^2 - 12x + 1.2 = 0$$\n\nHow can you find the values of $x$ that will make this equation true?\n\nYou can always reduce a quadratic equation so that the first\ncoefficient is 1, so that your equation looks like this:\n\n$$x^2 +bx + c = 0$$\n\nFor example, if you are asked to solve $4x^2 + 8x - 19 = -2x^2 - 7$\n\\begin{multline*}\n  4x^2 + 8x - 19 = -2x^2 - 7 \\\\\n  6x^2 + 8x -12 = 0 \\\\\n  x^2 + \\frac{4}{3}x - 2 = 0\n\\end{multline*}\nHere, $b = \\frac{4}{3}$ and $c = -2$.\n\n\\begin{mdframed}[style=important]\n$x^2 + bx + c = 0$ when\n\\begin{equation*}\nx = -\\frac{b}{2} \\pm \\frac{\\sqrt{b^2 - 4c}}{2}  \n\\end{equation*}\n\\end{mdframed}\n\nWhat does this mean?\n\nFor any $b$ and $c$, the graph of $x^2 + bx + c$ is a parabola\nthat goes up on each end. Its low point is at $x = -\\frac{b}{2}$.\n\nIf there are no real roots ($b^2 - 4c < 0$), that means the\nparabola never gets low enough to cross the $x$-axis:\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-0.5,xmax=2.75,\n        ymin=-1,ymax=5,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n      ]\n      \\addplot[no marks,sdkblue] expression[domain=-0.25:2.5,samples=100]{x^2 - 2* x + 3} node[above, xshift=-1cm] {$x^2 - 2x + 3$};\n      \\addplot[dashed,gray] coordinates {(1,-1)(1,3)};\n    \\end{axis}\n\\end{tikzpicture}\n\nIf there is one real root ($b^2 - 4c = 0$), it means that the parabola just touches the x-axis.\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-0.5,xmax=3.75,\n        ymin=-0.5,ymax=5,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n      ]\n      \\addplot[no marks,sdkblue] expression[domain=-0.25:3.5,samples=100]{x^2 - 4*x + 4} node[above, xshift=-1cm] {$x^2 - 4x + 4$};\n      \\addplot[dashed,gray] coordinates {(2,-0.5)(2,1)};\n    \\end{axis}\n\\end{tikzpicture}\n\nIf there are two real roots ($b^2 - 4c > 0$), it means that the parabola crosses the x-axis twice as it dips below and then returns:\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-0.5,xmax=3.75,\n        ymin=-2,ymax=5,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$x$},\n        ylabel={$y$},\n      ]\n      \\addplot[no marks,sdkblue] expression[domain=-0.25:3.5,samples=100]{x^2 - 3*x + 1} node[above, xshift=-1cm] {$x^2 - 4x + 4$};\n      \\addplot[dashed,gray] coordinates {(1.5,-2)(1.5,1)};\n    \\end{axis}\n\\end{tikzpicture}\n\n\\begin{Exercise}[title={Roots of a Quadratic}, label=solve_quadratic]\n\n  In the last chapter, you found that the function for the height of your flying hammer is:\n\n  $$p = -\\frac{1}{2}9.8 t^2 + 12t + 2$$\n\n  At what time will the hammer hit the ground?\n\n  \n\\end{Exercise}\n\\begin{Answer}[ref=solve_quadratic]\n\n  For what $t$ is  $-4.9 t^2 + 12t + 2 = 0$?  Start by dividing both sides of the equation by -4.9.\n\n  $$t^2 - 2.45 t - 0.408 = 0$$\n\n  The roots of this are at\n\n  $$x = -\\frac{b}{2} \\pm \\frac{\\sqrt{b^2 - 4c}}{2} = -\\frac{-2.45}{2} \\pm \\frac{\\sqrt{(-2.45)^2 - 4(-0.408)}}{2} = 1.22 \\pm 1.36$$\n\n  We only care about the root after we release the hammer ($t > 0$).\n\n  $1.22 + 1.36 = 2.58$ seconds after releasing the hammer, it will hit the ground.\n\n  \n\\end{Answer}\n\n\n\\section{The Traditional Quadratic Formula}\n\nI like the approach I just showed you. I find it easier to remember\nand easier to prove than the traditional quadratic fomula, but you\nshould probably know the traditional quadratic formula.\n\n\\begin{mdframed}[style=important, frametitle={The Quadratic Formula}]\n\n$ax^2 + bx + c = 0$ when\n\\begin{equation*}\n  x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}\n\\end{equation*}\n\n\\end{mdframed}\n", "meta": {"hexsha": "f391c4fa8d2c4e5b6c5fe005e80d64989e7767fc", "size": 4081, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/MatterEnergy/solving_quadratics-en_US.tex", "max_stars_repo_name": "rajivjhoomuck/sequence", "max_stars_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/MatterEnergy/solving_quadratics-en_US.tex", "max_issues_repo_name": "rajivjhoomuck/sequence", "max_issues_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/MatterEnergy/solving_quadratics-en_US.tex", "max_forks_repo_name": "rajivjhoomuck/sequence", "max_forks_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 30.4552238806, "max_line_length": 132, "alphanum_fraction": 0.615535408, "num_tokens": 1484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.8705972784807408, "lm_q1q2_score": 0.8227098241904109}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  For each of the following matrices, find the eigenvectors and\n  eigenvalues. Use this to visualize the linear transformation\n  $T:\\R^2\\to\\R^2$ that is described by the matrix.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      2 & 1 \\\\\n    \\end{mymatrix},\n    \\quad\n    B = \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      2 & -1 \\\\\n    \\end{mymatrix},\n    \\quad\n    C = \\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      0 & 2 \\\\\n    \\end{mymatrix},\n    \\quad\n    D = \\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      1 & 1 \\\\\n    \\end{mymatrix},\n    \\quad\n    E = \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      -1 & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  If $A$ is the matrix of a linear transformation that rotates all\n  vectors in $\\R^2$ by $60^{\\circ}$, explain why $A$ cannot have any\n  real eigenvalues. Is there an angle such that rotation by this\n  angle would have a real eigenvalue? What eigenvalues would be\n  obtainable in this way?\n  \\begin{sol}\n    A rotation by $60^{\\circ}$ cannot map any non-zero vector to a\n    scalar multiple of itself. The only rotations of $\\R^2$ that have\n    real eigenvalues are rotations by $180^{\\circ}$ and $0^{\\circ}$.\n    The former has eigenvalue $-1$, and the latter has eigenvalue $1$\n    (with all vectors being eigenvectors).\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $T$ be the linear transformation that reflects vectors about\n  the $x$-axis. Find a matrix for $T$ and then find its eigenvalues and\n  eigenvectors.\n  \\begin{sol}\n    The matrix of $T$ is $\\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & -1\n    \\end{mymatrix}$. The eigenvectors and eigenvalues are:\n    \\begin{equation*}\n      \\set{\\begin{mymatrix}{c}\n          0 \\\\\n          1\n        \\end{mymatrix}} ~\\mbox{for eigenvalue}~ {-1},\n      \\quad\\set{\\begin{mymatrix}{c}\n          1 \\\\\n          0\n        \\end{mymatrix}} ~\\mbox{for eigenvalue}~ {1}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $T$ be the linear transformation that reflects vectors about the\n  line $x=y$. Find a matrix of $T$ and then find eigenvalues and\n  eigenvectors.\n  \\begin{sol}\n    The matrix of $T$ is $\\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      1 & 0\n    \\end{mymatrix}$. The eigenvectors and eigenvalues are:\n    \\begin{equation*}\n      \\set{\\begin{mymatrix}{c}\n          1 \\\\\n          1\n        \\end{mymatrix}} ~\\mbox{for eigenvalue}~ {-1},\n      \\quad\\set{\\begin{mymatrix}{c}\n          -1 \\\\\n          1\n        \\end{mymatrix}} ~\\mbox{for eigenvalue}~ {1}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $T$ be the linear transformation that reflects all vectors in\n  $\\R^3$ about the $xy$-plane. Find a matrix for $T$ and then\n  obtain its eigenvalues and eigenvectors.\n  \\begin{sol}\n    The matrix of $T$ is $\\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & -1\n    \\end{mymatrix}$\n    The eigenvectors and eigenvalues are:\n    \\begin{equation*}\n      \\set{\\begin{mymatrix}{c}\n          0 \\\\\n          0 \\\\\n          1\n        \\end{mymatrix}} ~\\mbox{for eigenvalue $-1$},\n      \\quad\\set{\\begin{mymatrix}{c}\n          1 \\\\\n          0 \\\\\n          0\n        \\end{mymatrix},\n        \\begin{mymatrix}{c}\n          0 \\\\\n          1 \\\\\n          0\n        \\end{mymatrix}} ~\\mbox{for eigenvalue $1$}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "ba9b1c84ea1942c0209d6a52a50aa01096931bf2", "size": 3339, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Eigenvalues-Geometric.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Eigenvalues-Geometric.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Eigenvalues-Geometric.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 26.712, "max_line_length": 71, "alphanum_fraction": 0.565738245, "num_tokens": 1152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8991213853793452, "lm_q1q2_score": 0.822607020396936}}
{"text": "\\textbf{Consider the first order linear initial boundary value problem\n\\begin{align*}\nu_t=u_x, ~~~~x\\in[-1,1],~~t>0,~~u(\\pm 1,t)=u(x,0)=0,\n\\end{align*}\nwith initial data $u(x,0) = \\exp(-60(x-1/2)^2)$. Write a program to solve this problem by a matrix-based Chebyshev spectral discretization in $x$ coupled with the third order Adams-Bashforth formula in $t$, \n\\begin{align*}\nu^{(n+3)} = u^{(n+2)}+\\frac{1}{12}\\Delta t\\left(23f^{(n+2)}-16f^{(n+1)}+5f^{(n)}\\right).\n\\end{align*}\nInitial values can be supplied from the exact solution. Take $N=50$ and \\newline $\\Delta t=\\nu N^{-2}$, where $\\nu$ is a parameter. For each of the two choices $\\nu = 7$ and $\\nu = 8$, produce one plot of the computed solution at $t=1$ and another that superimposes the stability region in the $\\lambda\\Delta t$-plane, the eigenvalues of the spatial discretization matrix, and its $\\epsilon$-pseudospectra fpr $\\epsilon=10^{-2},10^{-3},\\dots,10^{-6}$. Comment on the results.\n}\n\\newline\n\nWe start by finding the exact solution using characteristics,\n\n\\begin{align*}\nu(x,t) = \n\\begin{cases}\n       e^{-60(x+t-1/2)^2},& x\\geq -t,\\\\\n       e^{-60(x+t+1/2)^2},& x\\leq -t.\n\\end{cases}\n\\end{align*}\n\nFurther, we use Chebyshev differentiation matrices,\n\\begin{align*}\nu_t &= u_x,\\\\\nu_t &= Du = f,\n\\end{align*}\nand the AB time-stepping method:\n\\begin{align*}\nu^{(n+3)} &= u^{(n+2)}+\\frac{1}{12}\\Delta t\\left(23f^{(n+2)}-16f^{(n+1)}+5f^{(n)}\\right),\\\\\n&= u^{(n+2)}+\\frac{1}{12}\\Delta tD\\left(23u^{(n+2)}-16u^{(n+1)}+5u^{(n)}\\right).\n\\end{align*}\nTo start the simulation we use the exact solution. The results obtained are shown in the following figure. In the top two figures we see the exact solution (red) superposed with the numberical solution (blue). As we can see, for $\\nu=7$ (left) we have a correct numerical solution while for $\\nu=8$ (right) the numerical solution blows up. This can be further understood looking at the bottom figures. As we can see in the bottom left graph, the eigenvalues near the border of the stability region are susceptible to perturbations. Hence, by just increasing $\\nu$ to 8, those eigenvalues are now outside of the stability region (bottom-right figure), giving us an understanding of why the numerical simulation is unstable.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1.2]{P2.png}\\caption{Numerical and analytical solution of the PDE for $\\nu = 7$ and $\\nu = 8$ (top) and pseudo-spectra with stability regions and eigenvalues in the $\\lambda\\Delta t$-plane for those two values of $\\nu$ (bottom).}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Homework 4, Problem 2 - Francisco Castillo'\nclear all; close all; clc;\nlabelfontsize = 14;\nmarkersize = 4;\nlinewidth = 2;\n\nN = 50;\nV = [7,8];\nlevels = log10([1e-2 1e-3 1e-4 1e-5 1e-6]);\n% figure('units','normalized','outerposition',[0 0 1 1])\nfor j=1:length(V)\n    v = V(j);\n    dt = v/N^2;\n    tf = 1;\n\n    [D,x] = cheb(N); % D:(N+1)x(N+1), x:(N+1)x1\n    D = D (2:end,2:end);\n    u_n = analytic_sol(x(2:end),0);\n    u_n1 = analytic_sol(x(2:end),dt);\n    u_n2 = analytic_sol(x(2:end),2*dt);\n\n    t = 2*dt;\n    while t<tf\n        if (t+dt>tf)\n            dt=tf-t;\n            t=t+dt;\n        else\n            t=t+dt;\n        end\n\n        u_n3 = u_n2+dt*D*(23*u_n2-16*u_n1+5*u_n)/12;\n        u = [analytic_sol(1,t);u_n3];\n\n        u_n = u_n1;\n        u_n1 = u_n2;\n        u_n2 = u_n3;\n\n        res = analytic_sol(x,t);\n\n        subplot(2,2,j)\n        plot(x,u,'b*')\n        hold on\n        plot(x,u,'b')\n        plot(x,res,'r*')\n        plot(x,res,'r')\n        grid on\n        axis([-1 1 0 1])\n        xlabel('$x$','interpreter','latex','fontsize',labelfontsize)\n        ylabel('$u(x,t)$','interpreter','latex','fontsize',labelfontsize)\n        hold off\n        shg\n    end\n    %%\n    % Adams-Bashforth stability region and pseudo-spectra of this problem\n    dt = v/N^2;\n    ee = eig(D);\n    dtee = dt*ee;\n    xr = 6.5*linspace(min(real(dtee)),0.1,50);\n    yr = 2*linspace(min(imag(dtee)),max(imag(dtee)),50);\n    [xx,yy] = meshgrid(xr,yr);\n    zz = xx+1i*yy;\n    ps = 0*zz;\n    for k=1:numel(zz)\n        ps(k) = min(svd(eye(size(D))*zz(k)-dt*D));\n    end\n\n    z = exp(1i*pi*(0:200)/100); r = z-1;\n    s = (23-16./z+5./z.^2)/12;\n\n\n    subplot(2,2,j+2)\n    contourf(xx,yy,log10(ps),levels)\n    c = colorbar;\n    hold on\n    plot([-8,8],[0,0],'k')\n    plot([0,0],[-8,8],'k')\n    plot(real(dtee),imag(dtee),'r*','markersize',markersize)\n    plot(r./s,'b','linewidth',linewidth)\n    xlabel('$\\Re(\\lambda)$','interpreter','latex','fontsize',labelfontsize)\n    ylabel('$\\Im(\\lambda)$','interpreter','latex','fontsize',labelfontsize)\n    axis([-1 0.1 -1 1])\n    grid on\nend\n\nsaveas(gcf,'Latex/FIGURES/P2','png')\n\nfunction res = analytic_sol(x,t)\n    res = zeros(size(x));\n    res(x>=-t) = exp(-60*(x(x>=-t)+t-0.5).^2);\n    res(x<-t) = exp(-60*(x(x<-t)+t+0.5).^2);\nend\n\\end{verbatim}\n", "meta": {"hexsha": "c5e22ac89beb3da1884ee87fb966e9c259270ded", "size": 4870, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework4/Latex/problem2.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework4/Latex/problem2.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework4/Latex/problem2.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6165413534, "max_line_length": 722, "alphanum_fraction": 0.6125256674, "num_tokens": 1690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539553, "lm_q2_score": 0.8991213698363247, "lm_q1q2_score": 0.8226070061766115}}
{"text": "\\subsubsection{Dimension Reduction using PCA}\n\\label{sec:reducpca}\nPrincipal Component Analysis (PCA) is a mathematical tool used in data analysis to simplify and extract the most relevant features in a complex data set. This technique is used to create entries composed of linearly independent `principal components'. These are the eigenvectors of the covariance matrix $\\Sigma$ applied to the centered data, eq.\\eqref{eq:covariance}, ordered from the largest to the smallest eigenvalue, $\\lambda_1 \\ge \\lambda_2 \\ge ... \\ge \\lambda_n$, where $\\overline{\\boldsymbol{X}}$ is the mean value of each original feature, eq.\\eqref{eq:xmean}. The projection of the data onto the principal component space ensures a maximal variance on the direction of the first component. Each subsequent principal component is orthogonal to the previous ones and points in the direction of maximal variance in the residual sub-space \\citep{Shlens2014}.\n\n\\begin{align}\n\\overline{\\boldsymbol{X}} & = \\frac{1}{m} \\sum_{i=1}^{m} \\boldsymbol{X}_i \\label{eq:xmean} \\\\\n\\Sigma & = \\frac{1}{m} \\sum_{i=1}^{m} \\left( \\boldsymbol{X}_i - \\overline{\\boldsymbol{X}} \\right)\\left( \\boldsymbol{X}_i - \\overline{\\boldsymbol{X}} \\right) \\label{eq:covariance}\n\\end{align}\n\nThe PCA transformation creates as many components in the transformed space, $\\boldsymbol{\\tilde{X}}$, as features in the original data space $\\boldsymbol{X}$. However, components with small eigenvalues belong to a dimension where the variance is so small that it is impossible to separate points in the data. It is a general practice in data reduction to keep only the first $k$ components that explain at least a significant portion of the total variance of the data, $\\lambda_{i=1..k}/\\text{Tr}(\\Sigma) > \\epsilon$. This allows for a selection of information that will effectively differentiate data points, and for a reduction of the amount of data to process during analysis. Many techniques have been suggested for the selection of the values of $k$ and the cut-off $\\epsilon$ \\citep{Rea2016}. We use the value of $k=3$ to simplify the comparison among the different models, but for a detailed study of the solar wind, if a PCA transformation is applied, it is important to use a fixed criteria for the selection of the cut-offs.\n\nFig. \\ref{fig:dimreduc} (A) is a 3D scatter plot of all the data points, colored by the Xu classification, projected on the first three PCA components. The features used to create this figure are presented in section \\ref{sec:fourmodels}. Panel (B) contains the same data colored by the Zhao classification. These projections show that the Xu and Zhao classification are defined by hyper-planes separating the points, even if the data has been linearly transformed by the PCA. Class 2, ICMEs-ejecta, is restricted to a small domain in this coordinate system (for both the Xu and Zhao classification). The lateral plots on panel (A) are 2D histograms of the point distribution on the three main PCA planes. They show that the concentration of points is not homogeneous and different zones can be isolated using unsupervised classification techniques. There is a clear segregation of points in the (1st,2nd)-component plane: as we will see in subsequent sections, one of the features of the solar wind presents a strong bimodal distribution that is prioritized by the PCA.\n\n\\subsubsection{Dimension Reduction Using Autoencoders}\n\\label{sec:reducae}\nPCA has a limitation: the principal components are a linear combination of the original properties of the solar wind. An alternative to data reduction is the use of autoencoders (AE). These are machine learning techniques that can create non-linear combinations of the original features projected on a latent space with less dimensions \\citep{Hinton2006}. This is accomplished by creating a system where an encoding function, $\\phi$, maps the original data $\\boldsymbol{X}$ to a latent space, $\\boldsymbol{\\mathcal{F}}$, eq.\\eqref{eq:encoder}. A decoder function, $\\psi$, then maps the latent space back to the original input space, eq.\\eqref{eq:decoder}. The objective of the autoencoder is to minimize the error between the original data and the data produced by the compression-decompression procedure as shown in eq.\\eqref{eq:aeminimization}.\n\n\\begin{align}\n\\phi: & \\boldsymbol{X} \\rightarrow \\boldsymbol{\\mathcal{F}} \\label{eq:encoder}\\\\\n\\psi: & \\boldsymbol{\\mathcal{F}} \\rightarrow \\boldsymbol{X} \\label{eq:decoder} \\\\\n\\phi,\\psi = & \\underset{\\phi,\\psi}{\\arg \\min} \\left\\lVert \\boldsymbol{X} - (\\phi \\circ \\psi) \\boldsymbol{X} \\right\\rVert^2 \\label{eq:aeminimization}\n\\end{align}\n\nAutoencoders can be represented as feed-forward neural networks, where fully connected layers lead to a central bottleneck layer with few nodes and then expands to reach again the input layer size. An encoded element, $\\boldsymbol{z} \\in \\boldsymbol{\\mathcal{F}}$, can be obtained from a data entry, $\\boldsymbol{x} \\in \\boldsymbol{X}$, following the standard neural network function, eq.\\eqref{eq:encodex}, where $\\boldsymbol{W}$ is the weights matrix, $\\boldsymbol{b}$ is the bias, and $\\sigma$ is the non-linear activation function.\n\n\\begin{align}\n\\boldsymbol{z} & = \\sigma \\left( \\boldsymbol{W}\\boldsymbol{x} + \\boldsymbol{b} \\right) \\label{eq:encodex} \\\\\n\\boldsymbol{\\hat{x}} & = \\sigma' \\left( \\boldsymbol{W'}\\boldsymbol{z} + \\boldsymbol{b'} \\right) \\label{eq:decodez} \\\\ \n\\mathcal{L}(\\boldsymbol{x}, \\boldsymbol{\\hat{x}}) & =  \\left\\lVert \\boldsymbol{x}- \\boldsymbol{\\hat{x}} \\right\\rVert^2 \\label{eq:aeloss}\n\\end{align}\n\nThe decoding procedure, shown in eq.\\eqref{eq:decodez}, transforms $\\boldsymbol{z}\\rightarrow\\boldsymbol{\\hat{x}}$, where the prime quantities are associated with the decoder. The loss function, $\\mathcal{L}(\\boldsymbol{x}, \\boldsymbol{\\hat{x}})$, is the objective to be minimized by the training of the neural network using gradient descent. Once training is completed, the vector $\\boldsymbol{z}$ is a projection of the input vector $\\boldsymbol{x}$ onto the lower dimensional space $\\boldsymbol{\\mathcal{F}}$.\n\nAdditional enhancements and variations of this simple autoencoder setup exist in the literature, including multiple regularization techniques to minimize overfitting \\citep{7407967}, Variational Autoencoders (VAE) that produce encoded Gaussian distribution functions \\citep{Kingma2013}, and Generative Adversarial Networks (GAN) that produce new (unseen) data \\citep{Goodfellow2014}. In this work we use the most basic form of autoencoders, presented above.\n\nThe second column of Fig.\\ref{fig:dimreduc}, panels (C) and (\nD), contains the same information as the first column, but with the data set encoded in the three dimensional latent space $\\boldsymbol{\\mathcal{F}}$. Panel (C) shows that all the classes in the Xu and Zhao classification are easy to distinguish, including ICMEs-ejecta (class 2) that is difficult to discern in the PCA. This projection also shows that class 4 from the Zhao classification in the bottom panels, overlaps with class 3 (sector reversal origin), and partially with class 2 (ejecta) in the Xu classification on the top panels. Panel (C) shows, on the side planes, 2D histograms of the density of points. These can be seen as the volume integral of the point density in each direction. Here again it is possible to observe multiple zones of high concentration, suggesting that multiple types of solar wind are present in the data and that they can be differentiated using an unsupervised classification technique. \n\n\\subsubsection{Clustering Techniques}\n\\label{sec:clustering}\nThe goal of unsupervised machine learning is to group data points in a limited number of clusters in the N-dimensional space $\\Omega\\in\\Bbb R^N$, where N is the number of features (components or properties) in the data set. Multiple techniques can be used to perform multi-dimensional clustering. We present in Fig. \\ref{fig:clustering} the three clustering techniques used to classify our 3D reduced data. The panels in the first column show the data projected in the PCA reduced space, $\\boldsymbol{\\tilde{X}}$, while the second column shows the data in the latent AE space, $\\boldsymbol{\\mathcal{F}}$. Each row corresponds to a different clustering method. The colors in the top panels (A) and (D) were obtained using the $k$-means method \\citep{1056489}, the colors in the middle panels (B) and (E) were obtained using the Gaussian Mixture Model (GMM) \\citep{bishop2006machine}. The bottom panels are colored by the classes from the Self-Organizing Maps described later in section \\ref{sec:som}.\n\nThe $k$-means technique has already been used in a recent publication for the determination of solar wind states \\citep{Roberts2020}. To our knowledge other clustering methods have never been used in the literature to classify the solar wind, but \\citep{Dupuis2020} has used the GMM to characterize magnetic reconnection regions in simulations using their velocity distribution information.\n\nThe colors used in Fig.\\ref{fig:clustering} are assigned randomly by each clustering technique. The most glaring issue with them is that different methods can lead to different clusters of points. The GMM and the $k$-means agree on their classification in the PCA space, but show dissimilar results in the AE space. Moreover, for a single method, e.g. $k$-means, slight modifications of the clustering parameters, e.g. using a different seed for the random number generator, can lead to very different results. We address this last issue using an algorithm that launches the $k$-means and GMM algorithms 500 times until the methods converge to a quasi-steady set of clusters. But we warn that the results are implementation dependent.\n\nIn the present data set, the cloud of points is convex and well distributed in all three components. This raises one additional issue, observed more clearly in the first column of Fig.\\ref{fig:clustering}: when classical clustering methods are applied to relatively homogeneously dense data, it divides the feature space in Vorono\\\"i regions with linear hyper-plane boundaries. This is an issue with all clustering techniques based on discrimination of groups using their relative distances (to a centroid or to the mean of the distribution). To avoid this problem density-based techniques, such as DBSCAN \\citep{ester1996density}, and agglomeration clustering methods, use a different approach. However, we can not apply them here because in such homogeneous cloud of points these techniques lead to a trivial solution where all data points are assigned to a single class.\n\nThere is no guarantee that a single classification method, with a particular set of parameters will converge to a physically meaningful classification of the data if the points in the data do not have some level of separability, or have multiple zones of high density. This is also true for other classification methods based on `supervised learning'. In those applications same issues will be observed if the training data uses target classes derived from dense data clouds using simple hyper-plane boundaries, as done for the Zhao and Xu classes. An example of such application was published by \\citep{Camporeale2017b}. The authors used the Xu classification to train a Gaussian Process classifier.\n\n\\subsubsection{Self-Organizing Maps}\n\\label{sec:som}\n\n\\paragraph{Classical SOM}\n\nFollowing the definitions and notations by \\citep{Villmann2006}, a class can be defined as $C_i\\overset{\\text{def}}{=} \\{x\\in\\Omega | \\Phi(x)=\\boldsymbol{w}_i\\}$, where $\\Phi$ is a function from $\\Omega$ to a finite subset of $k$ points $\\{\\boldsymbol{w}_i\\in\\Bbb R^N\\}_{i=1..k}$. A cluster $C_i$ is then a partition of $\\Omega$, and $\\{\\boldsymbol{w}_i\\}$ are the code words (also known as nodes, weights or centroids) associated. The mapping from the data space to the code word set, $\\Phi: \\Omega\\rightarrow\\mathcal{W}$, is obtained by finding the closest neighbor between the points $\\boldsymbol{x}$ and the code words $\\boldsymbol{w}$, eq.\\eqref{eq:winner}. The code word $\\boldsymbol{w_s}$, the closest node to the input $\\boldsymbol{x_s}$, is called the `winning element'. The class $C_i$ corresponds to a Vorono\\\"i region of $\\Omega$ with center in $\\boldsymbol{w}_i$.\n\n\\begin{equation}\n\\Phi: x \\rightarrow  \\underset{i\\in\\mathcal{N}}{\\arg\\min}\\left( \\left\\lVert x - \\boldsymbol{w}_i \\right\\rVert \\right) \\label{eq:winner}\n\\end{equation}\n\nA Self-Organizing Map (SOM) also composed of structured nodes arranged in a lattice, and assigned to a fixed position $\\boldsymbol{p}_i$ in $\\Bbb R^q$, where $q$ is the dimension of the lattice (generally $q=2$). The map nodes are characterized by their associated code words. The SOM learns by adjusting the code words $\\boldsymbol{w}_i$ as input data $x$ is presented.\n\nThe SOM is the ensemble of code words and nodes $A_i = \\{ \\boldsymbol{w}_i, \\boldsymbol{p}_i\\} \\in (\\Omega \\times \\Bbb R^q)$. For a particular entry $\\boldsymbol{x_s}$, the code word $s \\in \\mathcal{N}$ is associated to the winning node $\\boldsymbol{p_s}$ if the closest word to $\\boldsymbol{x_s}$ is $\\boldsymbol{w_s}$. At every iteration of the method, all code words of the SOM are shifted towards $x$ following the rule:\n\n\\begin{equation}\n\\Delta \\boldsymbol{w}_i = \\epsilon(t)h_\\sigma(t,i,s)(x-\\boldsymbol{w}_i) \\label{eq:learnsom}\n\\end{equation}\n\nwith $h_\\sigma(t,i,j)$ defined as the lattice neighbor function:\n\n\\begin{equation}\nh_\\sigma(t,i,j) = e^{-\\frac{\\left\\lVert \\boldsymbol{p}_i - \\boldsymbol{p}_j \\right\\rVert^2}{2\\sigma^2(t)}} \\label{eq:neigsom}\n\\end{equation}\n\nwhere $\\epsilon(t)$ is the time dependent learning rate, eq.\\eqref{eq:epsilon}, and $\\sigma(t)$ is the time dependent lattice neighbor width, eq.\\eqref{eq:sigma}. The training of the SOM is an iterative process where each data point in the data set is presented to the algorithm multiple times $t={0, 1,..,t_f}$. In these equations the subscript $0$ refers to initial values at $t=0$ and the subscript $f$ to values at $t=t_f$.\n\n\\begin{align}\n\\epsilon(t) & = \\epsilon_0 \\left(\\frac{\\epsilon_f}{\\epsilon_0}\\right)^{t/t_f} \\label{eq:epsilon} \\\\\n\\sigma(t) & = \\sigma_0 \\left(\\frac{\\sigma_f}{\\sigma_0}\\right)^{t/t_f} \\label{eq:sigma}\n\\end{align}\n\nThis procedure places the code words in the data space $\\Omega$ in such a way that neighboring nodes in the lattice are also neighbors in the data space. The lattice can be presented as a $q$-dimensional image, called map, where nodes sharing similar properties are organized in close proximity.\n\nThe main metric for the evaluation of the performance of the SOM is called the quantization error:\n\n\\begin{equation}\nQ_E = \\frac{1}{M} \\sum_{i=1}^M \\left\\lVert x_i - w_{x_i} \\right\\rVert\n\\end{equation}\n\nwhere $M$, is the total number of entries in the data set.\n\nOnce the training of the SOM is finished, the code words $\\boldsymbol{w}_i$ can be grouped together using any clustering technique, e.g. k-means. The nodes of the SOM with close properties will be made part of the same class. The classes thus created are an ensemble of Vorono\\\"i subspaces, allowing a complex non-linear partitioning of the data space $\\Omega$.\n\nThe final number of clusters is an input of the algorithm, but can also be calculated autonomously. The Within Cluster Sum of Squares (WCSS) can be used as a metric of the compactness of the clustered nodes. As its name implies the WCSS is the sum of the squred distances from each node to their cluster point. If only one class is selected, the large spread of the nodes would produce a high WCSS. The lowest possible value of the WCSS is obtained for a very high number of classes, when the number of classes is equal to the number of nodes. But such extreme solution is also unpractical. The optimal number of clusters can be obtained using the Kneedle class number determination \\citep{5961514}. In the present work we do not use this technique: we will perform comparisons with previous publications that propose a fixed number of solar wind types. We will explore the use of an automatic class number selection in a future publication.\n\n\\paragraph{Dynamic SOM}\nThe time dependence of the SOM training allows the code words $\\boldsymbol{w}_i$ to reach steady coordinates by slowing down their movement over the iterations. Due to the minimization of the distance in eq.\\eqref{eq:winner} code words tend to agglomerate around high density zones of the feature space. The Dynamic Self-Organizing Map (DSOM), introduced by \\citep{Rougier2011}, eliminate the time dependence and allows to cover larger zones of the space outside of the high density regions.\n\nThe DSOM is a variation of the SOM where the learning function \\eqref{eq:learnsom} and the neighbor function \\eqref{eq:neigsom} are replaced by eqs. \\eqref{eq:learndsom} and \\eqref{eq:neigdsom} respectively:\n\n\\begin{align}\n\\Delta \\boldsymbol{w}_i & = \\epsilon \\left\\lVert x - \\boldsymbol{w}_i \\right\\rVert_\\Omega h_\\eta(i,s,x)(x-\\boldsymbol{w}_i) \\label{eq:learndsom} \\\\\nh_\\eta(i,s,x) & = e^{-\\frac{1}{\\eta^2}\\frac{\\left\\lVert \\boldsymbol{p}_i - \\boldsymbol{p}_j \\right\\rVert^2}{\\left\\lVert x - \\boldsymbol{w}_s \\right\\rVert_\\Omega^2}} \\label{eq:neigdsom} \n\\end{align}\n\nwhere $\\epsilon$ is a constant learning rate, $h_\\eta(i,s,x)$ is defined as the new lattice neighbor function, and $\\eta$ is the `elasticity' parameter. In their work \\citep{Rougier2011} show that DSOM can be used to better sample the feature space $\\Omega$, reducing the agglomeration of code words around high density zones. The DSOM does not converge to a steady solution, due to the lack of a temporal damping factor.\n\n\\paragraph{Visualization of SOM and DSOM}\nClustering techniques do not necessarily convergence to a steady immutable solution. Differences in the training parameters or slight changes in the data can have an important impact on the final classification. These tools can be used for statistical analysis, comparisons, data visualization and training of supervised methods. But it will be practically impossible to claim the existence of a general objective set of states discovered only by the use of these basic clustering techniques.\n\nHowever, SOMs and DSOMs provide an important tool for the study of the solar wind: the maps are composed of nodes that share similar properties with its immediate neighbors. This allows for visual identification of patterns and targeted statistical analysis.\n\nFig.\\ref{fig:maps} shows the basic types of plots and maps that can be generated using the SOM/DSOM techniques. This figure uses data from the model Amaya-21 which has been encoded, using AE, into a set of entries, $\\boldsymbol{z}_i$, each one composed of three components. Panel (A) shows a histogram of the first two components of the feature space $\\Omega$, with dots marking the position of the code words $\\boldsymbol{w}_i$. The colors of the dots represent their SOM classification. The red lines connect a single code word $\\boldsymbol{w}_s$ with its six closest neighbors. The panel (B) shows the `hit map' of the SOM. It contains the lattice nodes $\\boldsymbol{p}_i$ associated to the code words $\\boldsymbol{w}_i$. They are depicted as hexagons with sizes representing the number of data points connected to each node and colored by their SOM class. The thickness of the lines between lattice nodes represent the relative distance to its neighbors in the feature space $\\Omega$. Red lines connect the node $\\boldsymbol{p}_s$, associated to the code word $\\boldsymbol{w}_s$ in panel (A), to its closest neighbors.\n\nPanel (C) of Fig.\\ref{fig:maps} corresponds to the value of a single feature associated to each node; as an example we use the ionized oxygen ratio $O^{7+}/O^{7+}$ (`O7to6'). To improve visualization all hexagon sizes have been set to their maximum and the inter-node distance line has been colored white. In order to obtain the correct value for each node, we must first perform a decoding of the data from the latent space, $\\Omega=\\boldsymbol{\\mathcal{F}}$, to the original data set space, $\\boldsymbol{X}$.\n\nPanel (D) of Fig.\\ref{fig:maps} shows that the nodes of the lattice can also be used to present data that has not been used in the training of the SOM. The method keeps track of the points in the data set associated to each lattice node, it is then possible to perform independent statistical operations on those points alone. Moreover, it is possible to activate the SOMs with just a subset of the data, i.e. with points that feature a specific solar wind type. In this case, as an example, we have colored the map using the average oxygen charge state $\\left<Q_{O}\\right>$ (`avqO'), and we have set the size of the nodes to represent the frequency of points with solar wind type Xu=2 (ejecta). The dark line between the lattice nodes designate the boundaries between different SOM classes.\n\nThese four representations are only a few examples of the variety of data that can be represented using SOMs. The most important aspect of the SOMs is that data is represented in simple 2D lattices where the nodes share properties with their neighbors. Here we also decided to use hexagonal nodes, connecting 6 equidistant nodes, but other types of representations are also valid, e.g. squared or triangular nodes.\n\nThe bottom row of Fig.\\ref{fig:maps} displays all three components of the code words $\\boldsymbol{w}_i$ associated with each one of the $\\boldsymbol{p}_i$ nodes. In the first panel they have been mapped to the basic colors Red, Green and Blue (RGB). The remaining panels have been colored using each individual component. The first panel is then the RGB composition of the three remaining ones where the boundaries between the SOM classes have been highlighted.\n\n\\subsubsection{The Full Architecture}\n\\label{sec:fullarchi}\nThe previous sections introduced all the individual pieces that we use for the present work. Here we give a global view of the full model. Fig.\\ref{fig:architecture} shows how all the components are interconnected. The data set is composed of clean and processed entries. We tested the PCA transformation in cases Amaya-21 and Roberts-8, keeping only the first three principal components. This possible setup is presented on the left of the figure. It is also possible to perform an unsupervised clustering directly on the un-processed data, as shown on the top of the figure, but it is not recommended. For the remaining of this manuscript we present only the cases where the non-linear AE encoding, shown at the right of Fig.\\ref{fig:architecture}. The bottleneck of the AE network is three nodes, i.e. the data is encoded in three components. The transformed data is then used to train the SOM.\n\nAfter training, the code words of the SOM are then clustered to group together nodes that share similar properties. This second level classification is done using the $k$-means++ algorithm with 500 re-initializations (it is in general recommended to use between 100 and 1000 iterations). The total number of classes selected is an input of the model and has been set to 8. This arbitrary choice was made following the results presented by \\citep{Roberts2020}. All the software was implemented in Python using as main libraries PyTroch, Scikit-learn and Pandas.\n\n\\paragraph{Autoencoder architecture}\nWe use a basic, fully connected feed-forward neural network for the encoding-decoding process. The bottleneck of the network has been fixed to three neurons in order to simplify the visualization. This arbitrary choice is another parameter of the models that need further investigation. The neural network is symmetric in size but the weights of the encoder, $\\boldsymbol{W}$, and the decoder, $\\boldsymbol{W'}$, are not synchronized (see eqs.\\eqref{eq:encodex}, \\eqref{eq:decodez}). We use multiple fully connected hidden layers, where the central layer is the size of the bottleneck. Each layer is composed of a linear regressor, followed by batch normalization and a ReLU activation function. The output layer of the network contains a linear regressor followed by a hyperbolic tangent activation function. The autoencoder has been coded in python using the PyTorch framework.\n\nWe use an Adam optimizer \\citep{Kingma2014} for the gradient descent with a learning rate of 0.001 and a weight decay of 0.0001 for regularization. The loss function is the Mean Squared Error (MSE). We train the network for 30 epochs, after which we see no additional improvement in the loss function. The full data set was randomly divided 50\\%/50\\% between training and testing sets.\n\n\\paragraph{Two Models of Solar Wind Classification}\n\\label{sec:fourmodels}\nWe have tested the two models presented in Table \\ref{tab:features}. The models are inspired by the work of \\citep{Roberts2020}. We call these cases Amaya-21 and Roberts-8.  The table lists all the features used in each model. A detailed description of each feature can be found in the \\href{http://www.srl.caltech.edu/cgi-bin/dib/rundibviewmultil2/ACE/ASC/DATA/level2/multi}{ACE Level 2 documentation}. To spread the data over a larger range of values in each component, we have used the logarithm of all the quantities, except of those marked with an asterisk in the table.\n\nFeatures 15 to 20 contain an additional suffix, corresponding to a statistical operation performed on the corresponding feature. The operations include the mean, the range, the standard deviation and the auto-correlation of quantities over a window of time of 6 hours. This window allows to capture temporal (spatial) fluctuations in some of the solar wind parameters.\n\nOn the lower part of Table \\ref{tab:features} we present the range of dates used for each model. For Amaya-21 we use the full data set, while for the model Roberts-8 we try to replicate as much as possible the choices made in \\citep{Roberts2020}. The same table also contains the hyper-parameters selected to run the two models. The number of neurons per layer in the encoding half of the neural network is listed in the table and was manually selected to minimize the final loss value of the AE.\n\nAll the figures presented until now correspond to the processing of data from model Amaya-21. The amount of data and figures produced in this work is very large and is not possible to include all of them in the present document. We will present in the next section some highlights, but more detailed analysis of each one of the cases will be presented in future publications.\n\n\\paragraph{Budget}\nMachine learning models require fine tuning of different parameters, from the selection and testing of multiple methods, to the parameterization of the final architecture. \\citep{Dodge2019} suggests that every publication in machine learning should include a section on the budget used for the development and training of the method. The budget is the amount of resources used in the data processing, the selection of the model hyper-parameters (HP), and its training.\n\nThe most time-consuming task in the present work has been the data preparation, the model setup and debugging and the writing of the SOM visualization routines. All the techniques described in the previous sections have been coded in python and are freely accessible in the repositories listed in section \\ref{sec:repos}. We estimate the effort to bring this work from scratch to a total of 2 persons month. Of these, one person week was dedicated to the manual testing an selection of different model HPs (autoencoder architecture, feature selection, learning rates, initialization methods, number of epochs for training, selection of data compression method, size of the time windows, etc.).\n\nAll classic clustering techniques presented in section \\ref{sec:clustering} require only a few lines of code and can be trained in minutes on a mid-range workstation (e.g. Dell Precission T5600, featuring two Intel(R) Xeon(R) CPU E5-2643 0 @ 3.30GHz with four cores and eight threads each). The most time consuming tasks of our models are the training of the autoencoder (5\\% od the total run time), the multiple passages of the clustering algorithms (15\\% of the run time), and the optimization of the SOM hyper-parameters (80\\% of the run time). The training of the SOM is performed in less than a minute.\n\nFor reference, the total run-time for each one of the models used in this work are: 60 minutes for the Amaya-21 model and 20 minutes for the Roberts-8 model.\n\n\\paragraph{Hyper-Parameter Optimization}\nOur main goal in this manuscript is to introduce the use of the SOMs for the classification of solar wind data. SOMs require the selection of four main Hyper-Parameters (HPs): the size of the lattice, $(m\\times n)$, the initial learning rate, $\\epsilon_0$, and the initial neighbor radius, $\\sigma_0$. In the case of the DSOM algorithm, these two last HPs are replaced by the constant learning rate, $\\epsilon$, and the elasticity, $\\eta$. The automatic selection of the best HP for machine learning model is called Hyper-Parameter Optimization (HPO).\n\nWe use the library `optuna' \\citep{Akiba2019} to perform an automatic optimization of the four HPs. The optimization is based on a technique called Tree-structured Parzen Estimator (TPE) \\citep{pmlr-v28-bergstra13}. The objective function of the optimizer was set to minimize the expression:\n\n\\begin{equation}\n\\mathcal{H}\\left(\\sigma, \\eta, m, n\\right) = Q_E(\\sigma, \\eta, m, n) + \\alpha \\frac{m}{m_{max}} + \\beta \\frac{n}{n_{max}} + \\gamma m n \\label{eq:hpo}\n\\end{equation}\n\nwhere $Q_E$ is the SOM quantization error, $m$ and $n$ are the number of lattice nodes in each dimension, and $m_{max}$ and $n_{max}$ are the given maximum number of possible nodes. The weight factors $\\alpha$, $\\beta$ and $\\gamma$ are used to impose more or less restictions on each term. This optimization objective allows to minimize the quantization error, but also the number of nodes in the SOM. The squaring term $\\gamma m n$ forces the map to be as squared as possible.\n\nAfter a total of 100 trial runs of the model using different HPs, the optimizer selected the parameters presented in the lower section of table \\ref{tab:features}. The total run time for the HPO of the case Amaya-21 is about 40 minutes. HPO is, understandably, one of the most expensive procedures in all our setup.", "meta": {"hexsha": "7f06659b8dd336cb0873387fd7c5da7bf640223a", "size": 30201, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/2020-Frontiers/sections/methods.tex", "max_stars_repo_name": "murci3lag0/swinsom", "max_stars_repo_head_hexsha": "586e81e9b2e6829c0d56127a2209891675e29fcd", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-27T07:45:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-16T20:06:24.000Z", "max_issues_repo_path": "papers/2020-Frontiers/sections/methods.tex", "max_issues_repo_name": "murci3lag0/swinsom", "max_issues_repo_head_hexsha": "586e81e9b2e6829c0d56127a2209891675e29fcd", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-04-26T10:31:07.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-29T12:33:59.000Z", "max_forks_repo_path": "papers/2020-Frontiers/sections/methods.tex", "max_forks_repo_name": "murci3lag0/swinsom", "max_forks_repo_head_hexsha": "586e81e9b2e6829c0d56127a2209891675e29fcd", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-04-27T07:46:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-27T13:20:51.000Z", "avg_line_length": 183.0363636364, "max_line_length": 1122, "alphanum_fraction": 0.7812324095, "num_tokens": 7223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474168650673, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.8224652227700048}}
{"text": "\\section{Logistic Regression}\nWe can extend this learning to classification problems, where we have binary\nlabels $y$ that are either $0$ or $1$.\n\\subsection{The Logistic Function}\nFor logistic regression, our new hypothesis for estimating the class of a\nsample $x$ is:\n\\begin{equation}\n  h( x ) = g \\left( \\theta ^ { T } x \\right) = \\frac { 1 } { 1 + e ^ { - \\theta ^ { T } x } }\n\\end{equation}\nwhere $g(z)$ is the logistic or sigmoid function:\n\\begin{equation}\n  g ( z ) = \\frac { 1 } { 1 + e ^ { - z } }\n\\end{equation}\nThe sigmoid function is bounded between $0$ and $1$, and tends towards $1$ as\n$z \\rightarrow \\infty$. It tends towards $0$ when $z \\rightarrow -\\infty$.\nA useful property of the sigmoid function is the form of its derivative:\n\\begin{equation}\n  \\begin{aligned} g ^ { \\prime } ( z ) \\quad & = \\quad \\frac { d } { d z } \\frac { 1 } { 1 + e ^ { - z } } \\\\\n    & = \\quad \\frac { 1 } { \\left( 1 + e ^ { - z } \\right) ^ { 2 } } \\left( e ^ { - z } \\right) \\\\\n    & = \\quad \\frac { 1 } { \\left( 1 + e ^ { - z } \\right) } \\cdot \\left( 1 - \\frac { 1 } { \\left( 1 + e ^ { - z } \\right) } \\right) \\\\\n    & = \\quad g ( z ) ( 1 - g ( z ) )\n  \\end{aligned}\n\\end{equation}\n\\subsection{Cost Function}\nTo fit $\\theta$ for a set of training examples, we assume that:\n\\begin{equation}\n  \\begin{aligned}\n    P ( y = 1 | x ; \\theta ) & = h( x ) \\\\\n    P ( y = 0 | x ; \\theta ) & = 1 - h( x )\n  \\end{aligned}\n\\end{equation}\nThis can be written more compactly as:\n\\begin{equation}\n  p ( y | x ; \\theta ) = \\left( h ( x ) \\right) ^ { y } \\left( 1 - h ( x ) \\right) ^ { 1 - y }\n\\end{equation}\nAssume $m$ training examples generated independently, we define the likelihood\nfunction of the parameters as:\n\\begin{equation}\n  \\begin{aligned}\n    L ( \\theta ) \\quad & = \\quad p \\left( \\vec{y} | X ; \\theta \\right) \\\\\n    & = \\quad \\prod _ { i = 1 } ^ { m } p \\left( y ^ { ( i ) } | x ^ { ( i ) } ; \\theta \\right) \\\\\n    & = \\quad \\prod _ { i = 1 } ^ { m } \\left( h \\left( x ^ { ( i ) } \\right) \\right) ^ { y ^ { ( i ) } } \\left( 1 - h  \\left( x ^ { ( i ) } \\right) \\right) ^ { 1 - y ^ { ( i ) } }\n  \\end{aligned}\n\\end{equation}\nAnd taking the negative log likelihood to minimize:\n\\begin{equation}\n  \\begin{aligned}\n    \\ell ( \\theta ) \\quad & = \\quad -\\log L ( \\theta ) \\\\\n    & = \\quad -\\sum _ { i = 1 } ^ { m } y ^ { ( i ) } \\log h \\left( x ^ { ( i ) } \\right) + \\left( 1 - y ^ { ( i ) } \\right) \\log \\left( 1 - h \\left( x ^ { ( i ) } \\right) \\right) \\\\\n    & = \\quad -\\sum_{i=1}^{m} y^{(i)} \\theta^T x^{(i)} - \\log \\left( 1 + e^{\\theta^T x^{(i)}} \\right)\n  \\end{aligned}\n\\end{equation}\nThis is known as the binary cross-entropy loss function.\n\\subsection{Gradient Descent}\nLet\u2019s start by working with just one training example (x,y), and take\nderivatives to derive the stochastic gradient ascent rule:\n\\begin{equation}\n  \\begin{aligned}\n    \\frac { \\partial } { \\partial \\theta _ { j } } \\ell ( \\theta ) \\quad & = \\quad - \\left( y \\frac { 1 } { g \\left( \\theta ^ { T } x \\right) } - ( 1 - y ) \\frac { 1 } { 1 - g \\left( \\theta ^ { T } x \\right) } \\right) \\frac { \\partial } { \\partial \\theta _ { j } } g \\left( \\theta ^ { T } x \\right) \\\\\n    & = \\quad - \\left( y \\frac { 1 } { g \\left( \\theta ^ { T } x \\right) } - ( 1 - y ) \\frac { 1 } { 1 - g \\left( \\theta ^ { T } x \\right) } \\right) g \\left( \\theta ^ { T } x \\right) \\left( 1 - g \\left( \\theta ^ { T } x \\right) \\right) \\frac { \\partial } { \\partial \\theta _ { j } } \\theta ^ { T } x \\\\\n    & = \\quad - \\left( y \\left( 1 - g \\left( \\theta ^ { T } x \\right) \\right) - ( 1 - y ) g \\left( \\theta ^ { T } x \\right) \\right) x _ { j } \\\\\n    & = \\quad - \\left( y - h ( x ) \\right) x _ { j }\n  \\end{aligned}\n\\end{equation}\nThis therefore gives us the stochastic gradient ascent rule:\n\\begin{equation}\n  \\theta _ { j } : = \\theta _ { j } + \\alpha \\left( y ^ { ( i ) } - h \\left( x ^ { ( i ) } \\right) \\right) x _ { j } ^ { ( i ) }\n\\end{equation}\nWe must use gradient descent for logistic regression since there is no closed\nform solution for this problem.\n\\subsection{Newton-Raphson Algorithm}\nThe Hessian matrix for logistic regression is:\n\\begin{equation}\n  \\frac{\\partial^2 \\ell(\\theta)}{\\partial \\theta \\partial \\theta} = -\\sum_{i=1}^m x^{(i)} x^{(i) T} \\cdot h\\left(x^{(i)}\\right) \\cdot \\left(1-h\\left(x^{(i)}\\right)\\right)\n\\end{equation}\nHence the second order update is:\n\\begin{equation}\n  \\theta := \\theta - \\left( \\frac{\\partial^2 \\ell(\\theta)}{\\partial \\theta \\partial \\theta} \\right)^{-1} \\frac{\\partial \\ell(\\theta)}{\\partial \\theta}\n\\end{equation}\n", "meta": {"hexsha": "380ea8b6bb3109023408ebb216edd619fc0747bb", "size": 4502, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/logistic_regression.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/logistic_regression.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/logistic_regression.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.275, "max_line_length": 302, "alphanum_fraction": 0.5593069747, "num_tokens": 1651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.8757869819218865, "lm_q1q2_score": 0.8223857137944587}}
{"text": "\\subsection{Recap}\n\nPreviously we defined addition and multiplication in terms of successive use of the sucessor function. That is, the definition of addition was:\n\n\\(\\forall a \\in \\mathbb{N} (a+0=a)\\)\n\n\\(\\forall a b \\in \\mathbb{N} (a+s(b)=s(a+b))\\)\n\nAnd similarly for multiplication:\n\n\\(\\forall a \\in \\mathbb{N} (a.0=0)\\)\n\n\\(\\forall a b \\in \\mathbb{N} (a.s(b)=a.b+a)\\)\n\nAdditional functions could also be defined, following the same pattern:\n\n\\(\\forall a \\in \\mathbb{N} (a\\oplus _n 0=c)\\)\n\n\\(\\forall a b \\in \\mathbb{N} (a\\oplus _{n} s(b)=(a\\oplus_{n} b)\\oplus_{n-1}a)\\)\n\n\\subsection{Powers}\n\nPowers can also be defined:\n\n\\(\\forall a \\in \\mathbb{N} a^0=1\\)\n\n\\(\\forall a b \\in \\mathbb{N} a^{s(b)}=a^b.a\\)\n\n\\subsection{Example}\n\nSo \\(2^2\\) can be calculated like:\n\n\\(2^2=2^{s(1)}\\)\n\n\\(2^{s(1)}=2.2^1\\)\n\n\\(2.2^1=2.2.2^0\\)\n\n\\(2.2.2^0=2.2.1\\)\n\n\\(2.2.1=4\\)\n\nUnlike addition and multiplication, exponention is not commutative. That is\n\n\\(a^b\\ne b^a\\)\n\n\\subsection{Exponential rules}\n\n\\(a^ba^c=a^{b+c}\\)\n\n\\((a^b)^c=a^{bc}\\)\n\n\\((ab)^c=a^cb^c\\)\n\n", "meta": {"hexsha": "3438cc85e0975bf3dd15eb3f5ea7622bfb97b8e3", "size": 1036, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/algebra/01-01-powers.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/algebra/01-01-powers.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/algebra/01-01-powers.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.8363636364, "max_line_length": 143, "alphanum_fraction": 0.6206563707, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341999997378, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.8223837373588413}}
{"text": "\n\\subsection{Intermediate value theorem}\n\nTake a real function \\(f(x)\\) on closed interval \\([a,b]\\), continuous on \\([a,b,]\\).\n\nIVT says that for all numbers \\(u\\) between \\(f(a)\\) and \\(f(b)\\), there is a corresponding value \\(c\\) in \\([a,b]\\) such that \\(f(c)=u\\).\n\nThat is:\n\n\\(\\forall u \\in [min(f(a),f(b)),max(f(a),f(b))] \\exists c \\in [a,b] (f(c)=u)\\)\n\n", "meta": {"hexsha": "eac7b5db2a49e7e86d10fc20f79e28999dd6fcd6", "size": 359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/02-04-intermediate.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/02-04-intermediate.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/02-04-intermediate.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9166666667, "max_line_length": 138, "alphanum_fraction": 0.5821727019, "num_tokens": 121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587141, "lm_q2_score": 0.8740772302445241, "lm_q1q2_score": 0.8223228982744971}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 2}\n\nDecide whether each of the following statements is true or false.\nProve that your conclusion is correct.\n\\begin{enumerate}[label=(\\alph*)]\n\\item $2^{n+1} = O(2^n)$\n\\item $f(n) = O(g(n))$ implies $2^{f(n)} = O(2^{g(n)})$\n\\end{enumerate}\n\n\\subsection*{Solution}\n\\begin{enumerate}[label=(\\alph*)]\n\\item \\textit{true}.\nFor all sufficiently large $n$ ($n \\geq 0$), there exists a constant $c = 2$ such that\n\n\\begin{equation}\n2 \\times 2^n = f(n) \\leq c \\times g(n) = c \\times 2^n\n\\end{equation}\n\n\\item \\textit{true}.\nSince $f(n) = O(g(n))$, there exists constants $c$ and $x_0$ such that $f(n) \\leq c \\times g(n)$ for any $n \\geq x_0$.\nSince $h(x) = 2^x$ is an ever-increasing function, we can write\n\n\\begin{equation}\nf(n) \\leq c \\times g(n) \\Rightarrow 2^{f(n)} \\leq 2^{c \\times g(n)} = 2^c \\times 2^{g(n)}\n\\end{equation}\n\nThus $2^{f(n)} \\leq d \\times 2^{g(n)}$ always holds true for all $n \\geq x_1 = x_0$ when choosing $d \\geq 2^c$.\n\n\\end{enumerate}\n", "meta": {"hexsha": "e3ebe464607f8171c2f6e4e9d9c44f34d7de2c20", "size": 1325, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q02.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q02.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q02.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 35.8108108108, "max_line_length": 118, "alphanum_fraction": 0.5969811321, "num_tokens": 447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897442783527, "lm_q2_score": 0.874077230244524, "lm_q1q2_score": 0.8223228939212766}}
{"text": "\\chapter{Rank of a Tensor Product Space}\nThe \\emph{rank} of a tensor product space, along with all the tensors which live in it, is the number of vector spaces and dual spaces involved in creating it.\nThis is quite simple when the tensors are simple tensors (there are only vector spaces or only dual spaces involved).\nIn that instance, we just count the number of spaces, and put that number where the indices on the component would normally go.\nConsider these two tensors,\n\\begin{align*}\n    &T^\\mu e_\\mu \\in V : V^* \\to \\mathbb{F}, \\\\\n    &T_\\nu e^\\nu \\in V^* : V \\to \\mathbb{F}.\n\\end{align*}\nBoth are known as rank 1 tensors, since only a single space is involved.\n\nRank gets slightly more complicated if the tensors are mixed.\nIn this instance, we just put number in both indices, so a tensor with a single vector space and a single dual space would be a rank $(1,1)$. We say such a tensor would live in the tensor product space $\\tps{T}^1_1$. The problem comes when trying to identify the ordering of these two spaces; should $\\tps{T}^1_1$ mean $V \\otimes V^*$ or $V^* \\otimes V$? The answer is simply a matter of convection. Tensor product spaces \\emph{always} begin with vector spaces, and then move on to dual spaces.\nThis means that a rank $(p,q)$ tensor product space $\\tps{T}^p_q$ will be as follows:\n\\[ \\tps{T}^p_q = \\underbrace{V \\otimes V \\otimes \\cdots}_{\\text{$p$ times}} \\underbrace{V^* \\otimes V^* \\otimes \\cdots}_{\\text{$q$ times}}. \\]\nWhile tensor product spaces with the vector and dual spaces in different orders (even all shuffled about) still transform in exactly the same way, we insist on only defining tensors to have the proper order of $V \\otimes V^*$ to rectify the ambiguity of ordering.\n", "meta": {"hexsha": "8f9cfbe1ae63fb6c2c5e07fe6e1201ab000804a9", "size": 1720, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/tps_rank.tex", "max_stars_repo_name": "jopetty/tensor-notes", "max_stars_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/tps_rank.tex", "max_issues_repo_name": "jopetty/tensor-notes", "max_issues_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/tps_rank.tex", "max_forks_repo_name": "jopetty/tensor-notes", "max_forks_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 101.1764705882, "max_line_length": 494, "alphanum_fraction": 0.7377906977, "num_tokens": 461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068041, "lm_q2_score": 0.8652240704135291, "lm_q1q2_score": 0.8223184516688987}}
{"text": "\n\\subsection{Matrix powers}\n\nFor a square matrix \\(M\\) we can calculate \\(MMMM...\\), or \\(M^n\\) where \\(n\\in \\mathbb{N}\\).\n\n\\subsection{Powers of diagonal matrices}\n\nGenerally, calculating a matrix to an integer power can be complicated. For diagonal matrices it is trivial.\n\nFor a diagonal matrix \\(M=D^n\\), \\(m_{ij}=d_{ij}^n\\).\n\n", "meta": {"hexsha": "53f4add5c339b43ddd5bdaff328c34fe47be2011", "size": 331, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystemsOperations/02-01-powers.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/linearSystemsOperations/02-01-powers.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/linearSystemsOperations/02-01-powers.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5833333333, "max_line_length": 108, "alphanum_fraction": 0.6918429003, "num_tokens": 90, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284087926320945, "lm_q2_score": 0.8856314647623015, "lm_q1q2_score": 0.8222280389169617}}
{"text": "\\subsubsection{Circulations}\r\n\\begin{definition}\r\n\tIf $C$ is a simple, closed curve, then $\\int\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}}$ is the circulation of $\\vec{F}$ on $C$.\r\n\\end{definition}\r\n\\noindent\r\nWe notate that we are taking a circulation as $\\oint\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}}$.\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nFor example, let's find the circulation of $\\vec{F}(x,y,z) = \\langle yz, xz, xy \\rangle$ on the circle of radius 1 centered at $(0,0,1)$ in the $z = 1$ plane in the counter-clockwise direction.\r\n\\begin{equation*}\r\n\t\\vec{r}(t) = \\langle \\cos{t}, \\sin{t}, 1 \\rangle, 0 \\leq t \\leq 2\\pi\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\vec{F}\\circ\\vec{r} = \\langle \\sin{t}, \\cos{t}, \\sin{t}\\cos{t} \\rangle\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\left(\\vec{F}\\circ\\vec{r}\\right) \\cdot \\vec{r^\\prime}(t) = \\cos{(2t)}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\oint\\limits_{C}{\\vec{F}\\cdot\\mathrm{d}\\vec{r}} = \\int_{0}^{2\\pi}{\\cos{(2t)}\\mathrm{d}t} = \\frac{1}{2}\\sin{(2t)}\\rvert_{0}^{2\\pi} = 0\r\n\\end{equation*}", "meta": {"hexsha": "84af7dc66e938072f3aba03fa2a29cc900b9065b", "size": 1031, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/circulations.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/lineSurfaceIntegrals/circulations.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/lineSurfaceIntegrals/circulations.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 44.8260869565, "max_line_length": 194, "alphanum_fraction": 0.6314258002, "num_tokens": 420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.8918110440002044, "lm_q1q2_score": 0.8221800740286653}}
{"text": "\\chapter{Division from plus, times, and norm}\n\n\\begin{abstract}\n    Dividing \\(n\\) by \\(d\\) is finding\n    \\((q,r)\\) that satisfies \\(n = q \\times d + r\\)\n    and minimizes the norm of \\(r\\).\n    Integer division and set division are special cases of that division.\n\\end{abstract}\n\n\\section{Terminology}\n\nIn \\(n / d = q\\),\nwe call \\(n\\) the dividend,\n\\(d\\) the divisor,\nand \\(q\\) the quotient.\nThe dividend is the thing that is divided.\nThe divisor is the thing that divides.\n\nIn \\(a \\times b = c\\),\nwe call \\(a\\) the multiplier, \\(b\\) the multiplicand, and \\(c\\) the product.\nThe multiplicand is the thing that is repeated.\nThe multiplier is how many times the multiplicand is repeated.\nTherefore \\(2 \\times 3 = 3+3\\) and \\(3 \\times 2 = 2+2+2\\).\n\nThe word `quotient' comes from the Latin word `quotiens' that means `how many times'.\nThe quotient describes \\emph{how many times} we must repeat the divisor to obtain the dividend.\nTherefore \\(6/2 = 3\\) because \\(2+2+2 = 6\\)\nand \\(6/3 = 2\\) because \\(3+3 = 6\\).\n\nThe divisor in a division\nbecomes the multiplicand in the related multiplication.\nFormally, \\(n / d = q\\) means the same thing as \\(n = q \\times d\\).\nTo obtain the related multiplication of a division,\n\\emph{right}-multiply each side of the equation by the divisor.\nRight multiplication cancels right division.\n\nWhen we write \\(p \\times q\\), we say that we \\emph{left-multiply \\(q\\) by \\(p\\)}\nor \\emph{right-multiply \\(p\\) by \\(q\\)}.\nThe `left' and `right' tell us where the multiplier is.\nIn a left multiplication, the multiplier (the thing that multiplies)\nis on the left side of the multiplicand (the thing that is multiplied).\nWe say that we left-multiply or right-multiply a multiplicand \\emph{by} a multiplier.\n\nIn the case of left division and right division,\nthe `left' and `right' tell us where the divisor is.\nLeft division means the divisor is on the left side of the dividend.\n\nIf \\(p \\times (q \\times r) = r\\), we call \\(p\\)\nthe \\emph{left inverse} of \\(q\\) because \\(p\\)\ncancels a multiplication where \\(q\\) is on the \\emph{left} side.\nWe also say that we \\emph{left-divide} \\(q \\times r\\) by \\(q\\).\nWe also write \\(q \\backslash (q \\times r) = r\\).\n\nSimilarly, if \\((p \\times q) \\times r = p\\), we call \\(r\\)\nthe \\emph{right inverse} of \\(q\\) because it\ncancels a multiplication where \\(q\\) is on the \\emph{right} side.\nWe write \\((p \\times q) / q = p\\).\n\nTo \\emph{left-divide} a dividend by a divisor is\nto \\emph{left-multiply} the dividend by the \\emph{left-inverse} of the divisor.\nTo \\emph{right-divide} a dividend by a divisor is\nto \\emph{right-multiply} the dividend by the \\emph{right-inverse} of the divisor.\n\nThe consequence of those definitions is that\nwe have \\(6 / 2 = 3\\)\nbecause \\(3 \\times 2 = 6\\),\nnot because \\(2 \\times 3 = 6\\).\n\nA problem with this division is that\nit is not always defined for every non-zero divisor.\nThat's where the remainder comes into play.\nIt allows us to extend the definition of division.\nThe remainder is the smallest thing that we must add to satisfy the equation\nafter we find the quotient.\nIf the remainder is zero, we say that the divisor \\emph{divides} the dividend.\n\nWe define \\(n/d = q\\) where \\(n = q \\times d + r\\)\nsuch that \\(r\\) is \\emph{minimal} in a way.\n\n\\section{Structure}\n\nLet there be a ring-like structure.\nLet there be a type \\(R\\),\nan addition \\(+\\),\na multiplication \\(\\times\\),\nand a norm \\(m : R \\to [ 0,\\infty )\\).\nThe operations do not have to have identities.\nThey do not have to be invertible.\nThey do not have to commute.\n\nDividing \\(n\\) by \\(d\\) is finding \\((q,r)\\) such that \\(n = q \\times d + r\\)\nand making sure that such \\((q,r)\\) is unique.\nHowever, there may be many \\((q,r)\\) that satisfies that equation.\nWe want at most one pair.\nWhich pair should we choose as the result of the division?\n\nIf \\(\\R = \\Nat\\), we choose the smallest \\(r\\).\nIf \\(R = \\Int\\), we choose the \\(r\\) that minimizes \\(|r|\\),\nthe absolute value of \\(r\\).\nIf \\(R\\) is the type of sets, we choose the \\(r\\)\nthat minimizes \\(|r|\\), the size of \\(r\\).\nThe common thing here is that we can define a \\emph{norm}.\nThe division then picks the pair that minimizes the norm of the remainder.\nHere we write \\(|r|\\) (the norm of \\(r\\))\nto mean the distance between zero (the additive identity) and \\(r\\).\nThe norm of a natural number is the number itself.\n\nThat equation is a special case of the linear equation\n\\( b = a_1 \\cdot x_1 + \\ldots + a_p \\cdot x_p \\)\nwhere \\(b = n\\), \\(p = 2\\), \\(a = (d,1)\\), \\(x = (q,r)\\).\n\n\\section{Generalization}\n\nTo understand division,\nfirst we look at following example about the natural numbers.\nLater we will generalize the division to also work on sets.\n\nSuppose that we want to divide \\(n\\) by \\(d\\).\nWhenever we divide \\(n\\) by \\(d\\),\nwhat we actually do is we\nfind \\(q\\) and \\(m\\) that satisfy\n\\(n = q \\times d + m\\)\nwhere \\(q\\) is \\emph{maximal}\nand \\(m\\) is \\emph{minimal}\nin the sense that there are no bigger \\(q\\) and smaller \\(m\\)\nthat satisfy the equation.\nWe call \\(n\\) the \\emph{dividend} (the thing that is divided),\n\\(d\\) the \\emph{divisor} (the thing that divides),\n\\(q\\) the \\emph{quotient},\nand \\(m\\) the \\emph{modulus} or the \\emph{remainder}.\n\nNow consider the integers.\nGiven \\(n \\neq 0\\) and \\(d \\neq 0\\),\nthere are infinitely many \\((q,m)\\) pairs that satisfy \\( n = q \\times d + m \\).\nWhich one should we choose?\n\nWe have just defined natural number division in terms of multiplication, addition, and natural ordering.\nIf we can define set multiplication, set addition, and set ordering, then we can define set division.\n\nWe can define the multiplication of two sets as their Cartesian product.\nWe can define the addition of two sets as their union.\nWe can define that a set is less than another iff the former is a proper subset of the latter.\nWe then define the remainder as the smallest set that we must add to satisfy the equation.\nFormally,\n\\begin{align}\n    Q \\times D &= \\{ (q,d) ~|~ q : Q, ~ d : D \\}\n    \\\\\n    A + B &= \\{ x ~|~ x : A \\vee x : B \\}\n    \\\\\n    A \\le B &\\iff A \\subseteq B\n    \\\\\n    N &= Q \\times D + R \\text{ such that \\(R\\) is minimal.}\n\\end{align}\n\nTo compute the quotient and the modulus,\nwe solve \\(N = Q \\times D + R\\)\nwith the constraint that \\(R\\) is \\emph{minimal}\nin the sense that there are no smaller \\(R\\)\nthat satisfies that equation.\n\nSimilar to \\(n/d = q\\), we define \\( N / D = Q \\).\nIt seems that all we did was rewrite everything using capital letters.\nIt's just that now the variables represent sets instead of numbers.\n\\emph{Indeed if we can define multiplication, addition, and maximum,\nthen we can define division.}\n\nNote that unlike natural number multiplication,\nset multiplication does not commute.\n\n\\section{Example}\n\nLet's say we have these:\n\\begin{align*}\n    N &= \\{ a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc \\}\n    \\\\\n    D &= \\{ a, b \\}\n\\end{align*}\nWe compute:\n\\begin{align*}\n    N &= Q \\times D + M\n    \\\\\n    N &= \\{ a, b, c \\} \\times \\{ a, b \\} + \\{ c, ac, bc, cc \\}\n\\end{align*}\nWe can't shrink \\(M\\) anymore\nso we claim:\n\\begin{align*}\n    Q &= \\{ a, b, c \\}\n    \\\\\n    M &= \\{ a, b, c, ac, bc, cc \\}\n\\end{align*}\n\nLet's say we have a polynomial \\(x^2 + 2x + 3\\) and we want to divide it with \\(x + 1\\).\n\\begin{align*}\n    n &= x^2 + 2x + 3\n    \\\\\n    d &= x + 1\n    \\\\\n    q &= x + 1\n    \\\\\n    r &= 1\n\\end{align*}\nWe define \\(p \\le q\\) iff \\(\\deg~p \\le \\deg~q\\) or \\(p_1 \\le q_1 \\wedge \\ldots\\).\n\nThe left quotient (Brzozowsky derivative)\nof a language \\(L\\) with respect to a string \\(p\\) is \\(\\{p\\} \\backslash L\\).\nIt is the special case of left-division of languages\nwhere the divisor has only one element.\n\\begin{align}\n    \\{p\\} \\backslash L = \\{ x ~|~ px : L \\}\n\\end{align}\n\n\\begin{align}\n    px : L &\\vdash x : \\{p\\} \\backslash L\n\\end{align}\n\nThe expression \\(2 \\times 3\\) means \\(3+3\\), not \\(2+2+2\\).\nThey both evaluates to \\(6\\), but they mean different things.\nFor natural numbers this sounds pedantic,\nbut this is important when the multiplication does not commute,\nsuch as set multiplication that we shall see later.\n", "meta": {"hexsha": "dbb8831ea3843051ddb10f91cb3c8d3cf9e95333", "size": 8028, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/division.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/division.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/division.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 36.3257918552, "max_line_length": 104, "alphanum_fraction": 0.6670403587, "num_tokens": 2403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8807970685907242, "lm_q1q2_score": 0.8221631220870443}}
{"text": "\\chapter{Sufficient statistics}\nIn this chapter the theory of sufficient statistics are introduced.\nFirst we begin with understanding of a statistic. Information about this subject can be found in \\cite{casella2002statistical}. A statistic is a function that returns a summary of the data. Examples of this can be mean value and standard deviation of the sample. Lets assume our data is from a distribution depending on some parameters $\\Theta$. The statistics we are interested in are those who contain information about the parameters $\\Theta$. This leads us to sufficient statistics. A sufficient statistic is a statistic that captures all information about the parameters $\\Theta$ and discard the rest. From \\cite{casella2002statistical} we have the following. \n\\begin{defn}\n(Sufficient statistic definition) A statistic $T(\\boldsymbol{X})$ is sufficient statistic for $\\Theta$ if the conditional distribution of sample $\\boldsymbol{X}$ gives the value for $T(\\boldsymbol{X})$ does not depend on $\\Theta$.\n\\end{defn}\nTo find sufficient statistics can be difficult, however one can use the factorization theorem to find the statistics. The theorem is as follows.\n\\begin{theorem} % s276\n(Factorization theorem) Let $f(\\boldsymbol{x}| \\Theta)$ denote the joint pdf or pmf of a sample $\\boldsymbol{X}$. A statistic $T(\\boldsymbol{X})$ is a sufficient statistic for $\\Theta$ if and only if there exist functions $g(t|\\Theta)$ and $h(\\boldsymbol{x})$ such that, for all sample points $\\boldsymbol{x}$ and all parameter points $\\Theta$,\n\\begin{equation*}\nf(\\boldsymbol{x}|\\Theta) = g(T(\\boldsymbol{x})| \\Theta)h(\\boldsymbol{x}).\n\\end{equation*}\n\\end{theorem}\n$h(\\boldsymbol{x})$ should not be dependent on $\\Theta$. Then the remaining part will be $g(T(\\boldsymbol{x})| \\Theta)$ and from this we can see the sufficient statistic.\n\n\\section{Sufficient statistics in NHPP}\n\\label{sec:sufstat}\nTo find the sufficient statistics for our NHPP one can use the likelihood function as shown in equation \\ref{eq:like} and from \\cite{lee1980testing}. The likelihood function can be found by\n\\begin{equation*}\nP(t_1,..., t_n) = P(t_1,...,t_n|N(\\tau)=n)P(N(\\tau)=n). \n\\end{equation*}\nFrom equation \\ref{eq:NHPPdens} the probability density of a event $t_i$ given number of events $n$ is\n\\begin{equation*}\nP(t_i|n) = \\frac{\\lambda(t_i)}{\\Lambda(\\tau)}.\n\\end{equation*}\nHence the joint probability given  $n$\n\\begin{equation*}\nP(t_1,...,t_n| N(\\tau) = n) = n! \\prod_{i = 1}^{n} \\frac{\\lambda(t_i)}{\\Lambda(\\tau)}.\n\\end{equation*}\nThe term $n!$ is included because the time runs are ordered.\nThe probability of $N=n$ events is as shown in equation \\ref{eq:NumNHPP} with $t = \\tau$. The joint probability of  $\\boldsymbol{t}$ becomes\n\\begin{equation*}\nP(t_1,...,t_n) = e^{-\\Lambda(\\tau)} \\frac{\\Lambda(\\tau)^n}{n!} n! \\prod_{i=1}^n \\frac{\\lambda(t_i)}{\\Lambda(\\tau)} = e^{-\\Lambda(\\tau)} \\prod_{i=1}^n \\lambda(t_i).\n\\end{equation*}\nFrom this the log likelihood function becomes\n\\begin{equation}\nl = -\\Lambda(\\tau) + n\\log(a) + n\\log(b) + (b-1)\\sum_{i=1}^{n} \\log(t_i) + c\\sum_{i=1}^{n} t_i.\n\\label{eq:loglike}\n\\end{equation}\nFrom the factorization theorem we can set $u(t) = 1$. Then we get the sufficient statistics $(n,\\displaystyle\\sum_{i=1}^{n} t_i, \\displaystyle\\sum_{i=1}^{n} \\log(t_i))$. \nThe last statistic can be rewritten to $\\displaystyle\\prod_{i=1}^{n} t_i$.\n", "meta": {"hexsha": "db73b34252a86ea718810d836db86a59de4ca84a", "size": 3352, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapters/sufficientstats.tex", "max_stars_repo_name": "mariufa/ProsjektOppgave", "max_stars_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Thesis/chapters/sufficientstats.tex", "max_issues_repo_name": "mariufa/ProsjektOppgave", "max_issues_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Thesis/chapters/sufficientstats.tex", "max_forks_repo_name": "mariufa/ProsjektOppgave", "max_forks_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.8095238095, "max_line_length": 665, "alphanum_fraction": 0.7279236277, "num_tokens": 989, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8962513821399044, "lm_q1q2_score": 0.822133780546729}}
{"text": "\\subsection{Translation into a Graph}\n\n\\begin{frame}\n  \\frametitle{Translation into a Graph}\n\n  \\scriptsize\n\n  The constraint $\\quad x - y \\leq c \\quad$ says that \n  \n  \\begin{center}\n    ``the distance between $x$ and $y$ is at most $c$''\n  \\end{center}\n\n  This can be encoded as $(x,y;c)$\n\n  \\begin{center}\n    \\input{arc}\n  \\end{center}\n\n  \\pause\n  \\vfill\n  So, a set $\\babst{\\mu}$ can be encoded as a graph. Concrete example:\n\n  \\begin{columns}\n\n    \\begin{column}{.3\\textwidth}\n      \\ra{1.3}\n      $$\n      \\begin{array}{rcr}\n\tx - y & \\leq & 8   \\\\\n\ty - z & \\leq & -1  \\\\\n\tz - x & \\leq & -6  \\\\\n\tz - w & \\leq & 2   \\\\\n\tw - x & \\leq & -10 \\\\\n\tw - t & \\leq & 0   \\\\\n\tt - x & \\leq & 3     \n      \\end{array}\n      $$\n    \\end{column}\n\n    \\begin{column}{.6\\textwidth}\n      \\begin{center}\n\t\\input{example}\n      \\end{center}\n    \\end{column}\n\n  \\end{columns}\n  \\vfill\n  $G( V, E )$: $V = \\{ x, y, z, w, t \\}$, $E = \\{ (x,y;8), (y,z;-1), (z,x;-6), (z,w;2), (w,x;-10), \\ldots \\}$ \n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Translation into a Graph}\n\n  \\scriptsize\n\n    \\begin{theorem}[Translation]\n      \\label{the:idl}\n      $\\babst{\\mu}$ is \\Idl-unsatisfiable \n      \\begin{center}\n      iff\n      \\end{center}\n      there is a {\\bf negative cycle} in the corresponging graph $G(V,E)$\n    \\end{theorem}\n\n  \\pause\n  \\vfill\n  E.g.:\n\n  \\begin{columns}\n\n    \\begin{column}{.3\\textwidth}\n      \\ra{1.3}\n      $$\n      \\begin{array}{rcr}\n\t\\coloneat{x - y}{3-} & \\coloneat{\\leq}{3-} & \\coloneat{8}{3-}   \\\\\n\t\\coloneat{y - z}{3-} & \\coloneat{\\leq}{3-} & \\coloneat{-1}{3-}  \\\\\n\t\\colfouat{z - x}{3-} & \\colfouat{\\leq}{3-} & \\colfouat{-6}{3-}  \\\\\n\t\\coloneat{z - w}{3-} & \\coloneat{\\leq}{3-} & \\coloneat{2}{3-}   \\\\\n\t\\coloneat{w - x}{3-} & \\coloneat{\\leq}{3-} & \\coloneat{-10}{3-} \\\\\n\t\\colfouat{w - t}{3-} & \\colfouat{\\leq}{3-} & \\colfouat{0}{3-}   \\\\\n\t\\colfouat{t - x}{3-} & \\colfouat{\\leq}{3-} & \\colfouat{3}{3-}     \n      \\end{array}\n      $$\n    \\end{column}\n\n    \\begin{column}{.6\\textwidth}\n      \\begin{center}\n\t\\begin{overlayarea}{.5\\textwidth}{3cm}\n\t  \\only<2|handout:0>{\\input{example}}\n\t  \\only<3->{\\input{example_hl}}\n\t\\end{overlayarea}\n      \\end{center}\n    \\end{column}\n\n  \\end{columns}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Translation into a Graph}\n\n  We use the following lemma to aid the proof\n\n  \\begin{lemma}[Farka's Lemma for \\Idl]\n    $\\babst{\\mu}$ is unsatisfiable iff there exists a subset \n    $\\babst{\\nu} = \\{\\ \\coltwo{x_1} - x_2 \\leq c_1,\\ x_2 - x_3 \\leq c_2,\\ \\ldots,\\ x_n - \\coltwo{x_1} \\leq c_n\\ \\}$ of $\\babst{\\mu}$\n    such that $c_1 + \\ldots + c_n < 0$\n  \\end{lemma}\n  \\pause\n  \\vfill\n  The proof of Theorem is now trivial\n  \\begin{proof}\n  $\\babst{\\mu}$ is unsatisfiable iff \\colfou{by Farka's Lemma for \\Idl} \\\\\n  there exists $\\babst{\\nu} \\subseteq \\babst{\\mu}$ with $c_1 + \\ldots + c_n < 0$ iff \\colfou{by our translation} \\\\\n  there exists a negative cycle in $G(V,E)$\n  \\end{proof}\n\n\\end{frame}\n", "meta": {"hexsha": "a1dd6428891497bf0378335c361f97ab8f2b1ab8", "size": 2932, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture5/translation.tex", "max_stars_repo_name": "formalmethods/smtlectures", "max_stars_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-11-07T19:34:12.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-24T08:05:50.000Z", "max_issues_repo_path": "lecture5/translation.tex", "max_issues_repo_name": "formalmethods/smtlectures", "max_issues_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture5/translation.tex", "max_forks_repo_name": "formalmethods/smtlectures", "max_forks_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-06T00:40:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-06T00:40:41.000Z", "avg_line_length": 24.2314049587, "max_line_length": 132, "alphanum_fraction": 0.5535470668, "num_tokens": 1197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.9173026624116694, "lm_q1q2_score": 0.8221337631395945}}
{"text": "\n\\subsection{Pauli matrices}\n\nPauli matrices are \\(2\\times 2\\) matrices which are unitary and hermitian.\n\nThat is, \\(P^*=P^{-1}\\).\n\nAnd \\(P^*=P\\).\n\n\\subsubsection{The Pauli matrices}\n\nThe matrices are:\n\n\\(\\sigma_1 =\\begin{bmatrix} 0&1  \\\\ 1&0  \\end{bmatrix}\\)\n\n\\(\\sigma_2 =\\begin{bmatrix} 0&-i \\\\ i&0  \\end{bmatrix}\\)\n\n\\(\\sigma_3 =\\begin{bmatrix} 1&0  \\\\ 0&-1 \\end{bmatrix}\\)\n\nThe identity matrix is often considered alongside these as:\n\n\\(\\sigma_0 =\\begin{bmatrix} 1&0  \\\\ 0&1  \\end{bmatrix}\\)\n\n\\subsubsection{Pauli matrices are their own inverse}\n\n\\(\\sigma_i^2 =\\sigma_i\\sigma_i\\)\n\n\\(\\sigma_i^2 =\\sigma_i\\sigma_i^*\\)\n\n\\(\\sigma_i^2 =\\sigma_i\\sigma_i^{-1}\\)\n\n\\(\\sigma_i^2 =I\\)\n\n\\subsubsection{Determinants and trace of Pauli matrices}\n\n\\(\\det \\sigma_i =-1\\)\n\n\\(Tr (\\sigma_i) =0\\)\n\nAs the sum of eigenvalues is the trace, and the product is the determinant, the eigenvalues are \\(1\\) and \\(-1\\).\n\n", "meta": {"hexsha": "fbe807c1c8bd229da8f9267068060fa955283a0f", "size": 896, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/04-03-pauli.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/forms/04-03-pauli.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/forms/04-03-pauli.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.3333333333, "max_line_length": 113, "alphanum_fraction": 0.6595982143, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545377452443, "lm_q2_score": 0.8670357512127872, "lm_q1q2_score": 0.8220838818997609}}
{"text": "\n\\subsection{Interest}\n\n\\subsubsection{Interest}\n\nAn alternative measure for finding rules is to use interest.\n\n\\(Interest(A\\rightarrow B)=\\dfrac{P(A\\land B)}{P(A)P(B)}\\)\n\n\\(Interest(A\\rightarrow B)=\\dfrac{supp(A\\land B)}{P(supp(A))P(supp(B))}\\)\n\nIf this is \\(1\\), then they are independent.\n\nIf this is greater than \\(1\\), they are positively dependent.\n\nIf this is less than \\(1\\), they are negatively dependent.\n\n", "meta": {"hexsha": "627037edb5d7080f9b48cdf8d356b8e2a9a58b9c", "size": 416, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/association/01-07-interest.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/association/01-07-interest.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/association/01-07-interest.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1111111111, "max_line_length": 73, "alphanum_fraction": 0.7019230769, "num_tokens": 120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9763105314577313, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.8218832489372545}}
{"text": "%\\subsection{Bilinear element}\n\n%\\noindent\\textbf{Bilinear element}\n\nContinuous bilinear finite element discretization of\n\\eqref{laplace} on the right mesh in \nFig. \\ref{fig:2dpartition}. The discrete space for linear finite element is \n$$\n\\mathcal V_h=\\{v_h: v_h|_K\\in \\{1,\\ x,\\ y,\\ xy \\} \\text{ and } v_h \\text{ is globally continuous}\\}.\n$$ \n%It is easy to see that on the element $K$ with four vertice $(x_i, y_j)$, $(x_i,y_{j+1})$, $(x_{i+1},y_j)$ and $(x_{i+1},y_{j+1})$, the nodal basis functions \n%%associate with each $(x_i,y_j)$   \n%(satisfying \\eqref{NodalBasis}) are given by \n%\\begin{equation}\n%  \\label{BilinearNodalBasis}\n%  \\begin{array}{llll}\n%\\phi_{i,j}(x,y)&=  \\frac{(x_{i+1}-x)(y_{j+1}-y)}{h^2}, \n%&\\phi_{i, j+1}(x,y)&= \\frac{(x_{i+1}-x)(y-y_j)}{h^2}, \\\\\n%\\phi_{i+1,j}(x,y)&=  \\frac{(x-x_i)(y_{j+1}-y)}{h^2}, \n%& \\phi_{i+1,j+1}(x,y)&= \\frac{(x-x_i)(y-y_j)}{h^2}.\n%\\end{array}\n%\\end{equation}\nFor bilinear element case, we have \n\\begin{equation}\n\\begin{split}\n(\\nabla \\mathbf u_h, \\nabla \\mathbf v_h)&=\\sum\\limits_{i,j=1}^{n}\\int_{E_{i,j}}\\nabla \\mathbf u_h, \\nabla \\mathbf v_h dxdy\\\\\n&=\\sum\\limits_{i,j=1}^{n}\\int_{E_{i,j}} \\left(\\frac{(u_{i+1,j}-u_{i,j})(y_{j+1}-y)}{h^2}\n+\\frac{(u_{i,j+1}-u_{i+1,j+1})(y-y_j)}{h^2}\\right)\\\\\n&~\\qquad\\qquad\\left(\\frac{(v_{i+1,j}-v_{i,j})(y_{j+1}-y)}{h^2}\n+\\frac{(v_{i,j+1}-v_{i+1,j+1})(y-y_j)}{h^2}\\right)\\\\\n&~~\\quad\\qquad+\\left(\\frac{(u_{i,j+1}-u_{i,j})(x_{i+1}-x)}{h^2}\n+\\frac{(u_{i+1,j}-u_{i+1,j+1})(x-x_i)}{h^2}\\right)\\\\\n&~\\qquad\\qquad \\left(\\frac{(v_{i,j+1}-v_{i,j})(x_{i+1}-x)}{h^2}\n+\\frac{(v_{i+1,j}-v_{i+1,j+1})(x-x_i)}{h^2}\\right)dxdy\\\\\n&=(A\\ast u, v)_{l^2}.\n\\end{split}\n\\end{equation}\nwhere $A=\\left(\n\\begin{matrix}\n-1&-1&-1\\\\\n-1&8&-1\\\\\n-1&-1&-1\\\\\n\\end{matrix}\n\\right)$ \nand $A\\ast u$ is given by \\eqref{2d-fe1}.\n\nAnd we have\n\\begin{equation}\n  \\label{2d-fe1}\nA\\ast u=8u_{ij}-(u_{i+1,j}+u_{i-1,j}+u_{i,j+1}+u_{i,j-1}+u_{i+1,j+1}+u_{i-1,j-1}+u_{i-1,j+1}+u_{i+1,j-1})=f_{i,j},\n\\end{equation}\nand \n$\nu_{i,j}=0~~\\hbox{if}~~i ~~\\hbox{or}~~ j\\in \\{0, n+1\\}.\n$\n", "meta": {"hexsha": "c2e8378ec102d8bd6a91485a0d39a07457d517a4", "size": 2018, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.7-bilinear.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.7-bilinear.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.7-bilinear.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.0357142857, "max_line_length": 159, "alphanum_fraction": 0.5867195243, "num_tokens": 1002, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953966101527047, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.8218782486632509}}
{"text": "\\subsubsection{Area of a Closed Region}\r\n\\noindent\r\nThe area inside of $D$ is \r\n\\begin{align*}\r\n\tA &= \\iint\\limits_{D}{\\mathrm{d}x\\mathrm{d}y} \\\\\r\n\t&= \\iint\\limits_{D}{\\left(\\nabla \\times \\vec{F}\\right)\\mathrm{d}x\\mathrm{d}y}\r\n\\end{align*}\r\nif $\\nabla \\times \\vec{F} = 1$. One such vector field is $\\vec{F} = \\langle -y/2, x/2 \\rangle$.\r\n\\begin{equation*}\r\n\t= \\oint_{C}{(-y/2)\\mathrm{d}x + (x/2)\\mathrm{d}y}\r\n\\end{equation*}\r\nby Green's Theorem for Circulation.\r\n\\begin{equation*}\r\n\t= \\frac{1}{2}\\oint\\limits_{C}{xy^\\prime - yx^\\prime}\t\r\n\\end{equation*}\r\nSo, if we have some counter-clockwise oriented parametric function $(x(t), y(t))$ where $t_0 \\leq t \\leq t_1$ that parameterizes $C$, then \r\n\\begin{equation*}\r\n\tA = \\frac{1}{2}\\int_{t_0}^{t_1}{\\left(x\\frac{\\mathrm{d}y}{\\mathrm{d}t} - y\\frac{\\mathrm{d}x}{\\mathrm{d}t}\\right)\\mathrm{d}t}\r\n\\end{equation*}\r\n\r\n\\noindent\r\nWe can also choose different vector field where $\\nabla \\times \\vec{F} = 1$ so that\r\n\\begin{equation*}\r\n\t A = \\oint\\limits_{C}{xy^\\prime} = \\oint\\limits_{C}{yx^\\prime}\r\n\\end{equation*}\r\n\r\n\\noindent\r\nFor example, let's compute the area of a circle with radius $R$.\r\nWe'll parameterize the circle as $(R\\cos{t}, R\\sin{t}), t \\in [0,2\\pi]$.\\\\\r\n\\begin{align*}\r\n\tA &= \\frac{1}{2}\\int_{0}^{2\\pi}{((R\\cos{t})(R\\cos{t}) - (R\\sin{t})(-R\\sin{t}))\\mathrm{d}t} \\\\\r\n\t&= \\frac{1}{2}\\int_{0}^{2\\pi}{R^2\\mathrm{d}t} \\\\\r\n\t&= \\frac{1}{2}R^2 2\\pi \\\\\r\n\t&= \\pi R^2\r\n\\end{align*}", "meta": {"hexsha": "af092f755df366cb235409b5eed7e8d2bef604d5", "size": 1429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/areaClosedRegion.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/vectorAnalysis/areaClosedRegion.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/vectorAnalysis/areaClosedRegion.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.8285714286, "max_line_length": 140, "alphanum_fraction": 0.6158152554, "num_tokens": 604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037384317887, "lm_q2_score": 0.8872045937171068, "lm_q1q2_score": 0.8218209319140123}}
{"text": "\\subsubsection{Linear Factors}\r\n\\noindent\r\nThis is the the most basic type where the degree of the numerator is less than the degree of the denominator and the denominator factors into all linear factors with no repeated roots. In this case we can write\r\n\\begin{equation*}\r\n\t\\frac{P(x)}{Q(x)} = \\frac{A_1}{(x-a_1)} + \\ldots + \\frac{A_n}{(x-a_n)}.\r\n\\end{equation*}\r\n\r\n\\noindent\r\nMultiplying each side by $Q(x)$,\r\n\\begin{equation*}\r\n\tP(x) = A_1(x-a_2) \\ldots (x-a_n) + \\ldots + A_n(x-a_1) \\ldots (x-a_{n-1}).\r\n\\end{equation*}\r\n\r\n\\noindent\r\nWe can then find each $A_i$ by evaluating both sides at $x=a_i$, since every term except the ith has an $(x-a_i)$ factor that will go to 0. So,\r\n\\begin{equation*}\r\n\tA_i = \\frac{P(a_i)}{(x-a_i) \\ldots (x-a_{i-1})(x-a_{i+1}) \\ldots (x-a_n)}.\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tFind the partial fraction decomposition of the following expression:\r\n\t\\begin{equation*}\r\n\t\t\\frac{2x-1}{x^3-6x^2+11x-6}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nFactoring,\r\n\\begin{equation*}\r\n\tx^3 - 6x^2 + 11x - 6 = (x-1)(x-2)(x-3).\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\frac{2x-1}{x^3-6x^2+11x-6} = \\frac{A_1}{x-1}+\\frac{A_2}{x-2}+\\frac{A_3}{x-3}.\r\n\\end{equation*}\r\nMultiplying each side by the denominator,\r\n\\begin{equation*}\r\n\t2x-1 = A_1(x-2)(x-3)+A_2(x-1)(x-3)+A_3(x-1)(x-2).\r\n\\end{equation*}\r\nAt $x=1$,\r\n\\begin{equation*}\r\n\t1 = A_1(1-2)(1-3) \\implies A_1 = \\frac{1}{2}.\r\n\\end{equation*}\r\nAt $x=2$,\r\n\\begin{equation*}\r\n\t3 = A_2(2-1)(2-3) \\implies A_2 = -3.\r\n\\end{equation*}\r\nAt $x=3$,\r\n\\begin{equation*}\r\n\t5 = A_3(3-1)(3-2) \\implies A_3 = \\frac{5}{2}.\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\frac{2x-1}{x^3-6x^2+11x-6} = \\frac{1/2}{x-1} + \\frac{-3}{x-2} + \\frac{5/2}{x-3},\r\n\\end{equation*}\r\njust as was shown in the previous example.", "meta": {"hexsha": "7162e6aecb2036ec1a1d8149939e569f99e105f4", "size": 1768, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/algebraPreCalc/linearFactors.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/algebraPreCalc/linearFactors.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/algebraPreCalc/linearFactors.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 32.1454545455, "max_line_length": 211, "alphanum_fraction": 0.628959276, "num_tokens": 760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552536, "lm_q2_score": 0.8902942268497306, "lm_q1q2_score": 0.8217764447905356}}
{"text": "\\subsection{Right and left inverses}\n\nSo far, we have only talked about the inverses of square matrices. But\nwhat about matrices that are not square? Can they be invertible? It\nturns out that non-square matrices can never be invertible. However,\nthey can have left inverses or right inverses.\n\n\\begin{definition}{Left and right inverses}{left-and-right-inverse}\n  Let $A$ be an $m\\times n$-matrix and $B$ an $n\\times m$-matrix.  We\n  say that $B$ is a \\textbf{left inverse}%\n  \\index{inverse!left inverse}%\n  \\index{left inverse}%\n  \\index{matrix!left inverse}%\n  \\index{matrix!inverse!left inverse} of $A$ if\n  \\begin{equation*}\n    BA=I.\n  \\end{equation*}\n  We say that $B$ is a \\textbf{right inverse}%\n  \\index{inverse!right inverse}%\n  \\index{right inverse}%\n  \\index{matrix!right inverse}%\n  \\index{matrix!inverse!right inverse} of $A$ if\n  \\begin{equation*}\n    AB=I.\n  \\end{equation*}\n  If $A$ has a left inverse, we also say that $A$ is\n  \\textbf{left invertible}. Similarly, if $A$ has a right inverse, we\n  say that $A$ is \\textbf{right invertible}.\n\\end{definition}\n\n\\begin{example}{Right inverse}{right-inverse}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    B = \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1 \\\\\n      0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Show that $B$ is a right inverse, but not a left inverse, of $A$.\n\\end{example}\n\n\\begin{solution}\n  We compute\n  \\begin{equation*}\n    AB\n    ~=~ \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1 \\\\\n      0 & 0 \\\\\n    \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{rrr}\n      1 & 0 \\\\\n      0 & 1 \\\\\n    \\end{mymatrix}\n    ~=~ I,\n  \\end{equation*}\n  \\begin{equation*}\n    BA\n    ~=~ \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1 \\\\\n      0 & 0 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n    \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & 0 \\\\\n    \\end{mymatrix}\n    ~\\neq~ I.\n  \\end{equation*}\n  Therefore, $B$ is a right inverse, but not a left inverse, of $A$.\n\\end{solution}\n\nRecall from Definition~\\ref{def:invertible-matrix} that $B$ is called\nan \\textbf{inverse}%\n\\index{inverse!of a matrix}%\n\\index{matrix!inverse} of $A$ if it is both a left inverse and a right\ninverse. A crucial fact is that invertible matrices are always square.\n\n\\begin{theorem}{Invertible matrices are square}{invertible-square}\n  Let $A$ be an $m\\times n$-matrix.\n  \\begin{itemize}\n  \\item If $A$ is left invertible, then $m\\geq n$.\n  \\item If $A$ is right invertible, then $m\\leq n$.\n  \\item If $A$ is invertible, then $m=n$.\n  \\end{itemize}\n  In particular, only square matrices can be invertible.\n\\end{theorem}\n\n\\begin{proof}\n  To prove the first claim, assume that $A$ is left invertible, i.e.,\n  assume that $BA=I$ for some $n\\times m$-matrix $B$. We must show\n  that $m\\geq n$. Assume, for the sake of obtaining a contradiction,\n  that this is not the case, i.e., that $m<n$. Then the matrix $A$ has\n  more columns than rows. It follows that the homogeneous system of\n  equations $A\\vect{x}=\\vect{0}$ has a non-trivial solution; let\n  $\\vect{x}$ be such a solution. We obtain a contradiction by a\n  similar method as in\n  Example~\\ref{exa:non-invertible-matrix}. Namely, we have\n  \\begin{equation*}\n    \\vect{x} ~=~ I\\,\\vect{x} ~=~ (BA)\\vect{x} ~=~ B(A\\vect{x}) ~=~ B\\vect{0} ~=~\n    \\vect{0},\n  \\end{equation*}\n  contradicting the fact that $\\vect{x}$ was non-trivial.  Since we\n  got a contradiction from the assumption that $m<n$, it follows that\n  $m\\geq n$.\n\n  The second claim is proved similarly, but exchanging the roles of\n  $A$ and $B$.  The third claim follows directly from the first two\n  claims, because every invertible matrix is both left and right\n  invertible.\n\\end{proof}\n\nOf course, not all square matrices are invertible. In particular, zero\nmatrices are not invertible, along with many other square matrices.\n", "meta": {"hexsha": "5d0caea8e54be57f51c33b848a14c13a49b73b0f", "size": 4063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Inverses-RightLeft.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-Inverses-RightLeft.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-Inverses-RightLeft.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 31.2538461538, "max_line_length": 80, "alphanum_fraction": 0.6391828698, "num_tokens": 1388, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.9230391627161538, "lm_q1q2_score": 0.8217764343639168}}
{"text": "\\section{The quadratic formula}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Use the Quadratic Formula to find the complex roots of a\n    quadratic equation.\n  \\end{enumerate}\n\\end{outcome}\n\nThe roots (or solutions) of a quadratic equation $ax^{2}+bx+c=0$ where $a,b,c$ are real numbers are\nobtained by solving the familiar quadratic formula\ngiven by\n\\index{quadratic formula}\n\\begin{equation*}\nx=\n\\frac{-b\\pm \\sqrt{b^{2}-4ac}}{2a}\n\\end{equation*}\n\nWhen working with real numbers, we cannot solve this formula if\n$b^{2}-4ac<0$. However, complex numbers allow us to find square roots\nof negative numbers, and the quadratic formula remains valid for\nfinding roots of the corresponding quadratic equation.   In this case\nthere are exactly two distinct (complex) square roots of $b^{2}-4ac$, which are\n$i\\sqrt{4ac-b^{2}}$ and $-i\\sqrt{4ac-b^{2}}$.\n\nHere is an example.\n\n\\begin{example}{Solutions to quadratic equation}{quadratic-equation}\nFind the solutions to $x^{2}+2x+5=0$.\n\\end{example}\n\n\\begin{solution}\nIn terms of the quadratic equation above, $a=1$, $b=2$, and $c=5$.\nTherefore, we can use the quadratic formula with these values, which becomes\n\\begin{equation*}\nx=\n\\frac{-b\\pm \\sqrt{b^{2}-4ac}}{2a}\n=\n\\frac{-2 \\pm \\sqrt{(2)^{2} - 4 (1)(5)}}{2(1)}\n\\end{equation*}\nSolving this equation, we see that the solutions are given by\n\\begin{equation*}\nx=\\frac{-2i\\pm \\sqrt{4-20}}{2}=\\frac{-2\\pm 4i}{2}=-1\\pm 2i\n\\end{equation*}\n\nWe can verify that these are solutions of the original equation.\nWe will show $x = -1+2i$ and leave $x = -1-2i$ as an exercise.\n\n\\begin{eqnarray*}\nx^{2}+2x+5\n&=& (-1+2i)^2 + 2(-1+2i) + 5 \\\\\n&=& 1 - 4i - 4 -2 + 4i + 5 \\\\\n&=& 0\n\\end{eqnarray*}\n\nHence $x = -1+2i$ is a solution.\n\\end{solution}\n\nWhat if the coefficients of the quadratic equation are actually complex\nnumbers? Does the formula hold even in this case? The answer is yes. This is\na hint on how to do Problem~\\ref{exer-complex3} below, a special case of the\nfundamental theorem of algebra, and an ingredient in the proof of some\nversions of this theorem.\n\nConsider the following example.\n\n\\begin{example}{Solutions to quadratic equation}{quadratic-equation-complex}\nFind the solutions to $x^{2}-2ix-5=0$.\n\\end{example}\n\n\\begin{solution}\nIn terms of the quadratic equation above, $a=1$, $b=-2i$, and $c=-5$.\nTherefore, we can use the quadratic formula with these values, which becomes\n\\begin{equation*}\nx=\n\\frac{-b\\pm \\sqrt{b^{2}-4ac}}{2a}\n=\n\\frac{2i \\pm \\sqrt{(-2i)^{2} - 4 (1)(-5)}}{2(1)}\n\\end{equation*}\nSolving this equation, we see that the solutions are given by\n\\begin{equation*}\nx=\\frac{2i\\pm \\sqrt{-4+20}}{2}=\\frac{2i\\pm 4}{2}=i\\pm 2\n\\end{equation*}\n\nWe can verify that these are solutions of the original equation.\nWe will show $x = i + 2$ and leave $x = i-2$ as an exercise.\n\n\\begin{eqnarray*}\nx^{2}-2ix-5\n&=& (i+2)^2 - 2i (i+2) - 5 \\\\\n&=& -1 + 4i + 4 + 2 - 4i - 5 \\\\\n&=& 0\n\\end{eqnarray*}\n\nHence $x = i+2$ is a solution.\n\\end{solution}\n\nWe conclude this section by stating an essential theorem.\n\n\\begin{theorem}{The fundamental theorem of algebra}{fund-theorem}\nAny polynomial of degree at least $1$ with complex coefficients has a root which is a complex number.\n\\end{theorem}\n", "meta": {"hexsha": "b9e9e75d3e00dc1246f0d721a4f6d0b7fe083d88", "size": 3173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/complexnumbersQuadratic.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/complexnumbersQuadratic.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/complexnumbersQuadratic.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 30.8058252427, "max_line_length": 101, "alphanum_fraction": 0.6974472108, "num_tokens": 1072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122762897041, "lm_q2_score": 0.8577681122619883, "lm_q1q2_score": 0.8216666049456037}}
{"text": "\\section{Boolean Functions}\n\n\\subsection{Binary Fields and Functions}\nLet $\\field{}$ denote the finite field with two elements. For a positive integer $n$ let $\\field{n}$ denote the vector space over $\\field{}$ of dimension $n$. An $n$-bit \\emph{Boolean function} is a function mapping $\\field{n}$ to $\\field{}$. The set of all $n$-bit Boolean functions is denoted by $\\BF{n}$. The \\emph{value vector} $\\valvec{f}$ of a Boolean function $f$ is the vector of length $2^n$ consisting of the values of $f$ on all possible inputs in the lexicographic order.\n$\\fzero,\\fone$ denote the two constant functions.\n\nFor $n \\in \\ZZplus$ let $\\fielde{n}$ denote the field with $2^n$ elements. Such field is defined as the set of polynomials with coefficients from $\\field{}$ and degree at most $n-1$. The field addition is the usual addition of polynomials, and the field multiplication is the multiplication of polynomials modulo a fixed irreducible polynomial of degree $n$. It can be summarized by the isomorphism\n$$\n\\fielde{n} \\simeq \\field{}[X]/P(x),\n$$\nwhere $P(x)$ is an irreducible polynomial, i.e. $P(x)$ cannot be factored into polynomials of strictly lower degree.\n\n\\subsection{Vectors and Weights}\nElements in vectors are indexed starting from 1. For a vector $v$ from $\\field{n}$ it is written $v = (v_1, \\ldots, v_n)$. $|X|$ denotes the size of the vector/set $X$. The \\emph{weight} of a vector $v$ is the number of nonzero entries in it and is denoted $\\wt(v)$. \\emph{Weight} of a Boolean function is the weight of its value vector. An $n$-bit Boolean function is said to be \\emph{balanced}, if its weight is equal to $2^{n-1}$.\n\nThe \\emph{correlation} of a vector $v \\in \\field{t}$ is defined as\n\\begin{align*}\n& \\cor(v) \\eqdef 2\\cdot\\wt(v)/t-1,~~ -1 \\le \\cor(v) \\le 1.\n\\end{align*}\nThe \\emph{correlation}\nof a Boolean function $f\\colon \\field{n} \\to \\field{}$ is defined as the correlation\nof its value vector $\\valvec{f}$:\n$$\\cor(f) \\eqdef \\cor(\\valvec{f}) = \\wt(f)/2^{n-1}-1.$$\n\nFor any $n \\in \\ZZplus$, $\\idvec{n} \\in \\field{n}$ denotes the all-one vector $(1,1,\\ldots,1)$. For $j \\in \\ZZplus,1\\le j \\le n$, the $j$-th unit vector $e_j$ is the vector having 1 at position $j$ and 0 otherwise. $e_1, \\ldots, e_n$ form a linear basis of $\\field{n}$.\n\n\n\\subsection{Bit-wise Arithmetic}\nLet $\\land,\\lor,\\oplus,\\lnot$ denote the Boolean operations \\tand{}, \\tor{}, \\txor{} and \\tnot{} respectively. The corresponding operations on $\\field{n}$ are defined  component-wise, e.g.\n$$\n(x_1, \\ldots, x_n) \\land (y_1, \\ldots, y_n) \\eqdef (x_1 \\land y_1, \\ldots, x_n \\land y_n).\n$$\nThe operation of addition modulo $2^w$ is denoted $\\boxplus$, and $w$ should be clear from the context; the bits in a vector are ordered in the decreasing order of significance (see~\\SecRef{implicit}). The rotations a vector $x$ to the left and to the right are denoted by $\\lll$ and $\\ggg$ respectively. \n\nFor $x, y \\in \\field{n}$ the \\emph{inner product} of $x$ and $y$ is defined as\n$$\n\\inprod{x,y} \\eqdef \\bigoplus_{i=1}^n x_i y_i \\in \\field{}.\n$$\nThis notion is generalized to more arguments. Let $x_1,\\dots,x_d \\in \\field{n}$. Then define\n$$\n\\inprod{x_1,\\dots,x_d} \\eqdef \\bigoplus_{i=1}^{n} \\prod_{j=1}^d x_{j,i} \\in \\field{}.\n$$\n\nFor $x, y \\in \\field{n}$, $x^y$ is defined as (note $0^0 = 1$)\n$$\nx ^ y \\eqdef x_1^{y_1}x_2^{y_2}\\ldots x_n^{y_n} \\eqdef \nx \\lor \\lnot y = \\idvec{n} \\oplus y \\land (x \\oplus \\idvec{n}) \\in \\field{}.\n$$\n\nLet $\\preceq$ be the partial relation on $(\\field{n})^2$ defined by $x \\preceq y$ if and only if, for all $i \\in \\{1,\\ldots,n\\}$, $x_i \\leq y_i$. I remark that\n$$\nx \\preceq y ~\\Leftrightarrow~\ny^x = 1 ~\\Leftrightarrow~\n(\\lnot x)^{\\lnot y} = 1.\n$$\n\n\n\\SubSecDef{implicit}{Implicit Isomorphisms}\nFor any $n,m \\in \\ZZplus$, the vector spaces $\\field{n+m}$ and $\\field{n}\\times \\field{m}$ are considered to be the same with an implicit isomorphism splitting an $(n+m)$-bit vector $v \\in \\field{n+m}$ into two components: $n$ leftmost bits $l\\in \\field{n}$ and $m$ rightmost bits $r \\in \\field{m}$.\n\nFor any $n \\in \\ZZplus$, the vectors from $\\field{n}$ can be implicitly represented as integers, such that the leftmost bits correspond to the most significant bits. Let $v \\in \\field{n}$. Then, by abuse of notation, it can be written:\n$$\nv = (v_1, \\ldots, v_n) \\in \\field{n},\n~~\\Leftrightarrow~~\nv = \\sum_{i=1}^n v_i2^{n-i} \\in \\ZZ_n.$$\nA hexadecimal vector notation may be used and indicated by a monospace font, for example\n$$\n163 \\in \\ZZn{256} = \\hex{a3} \\in \\field{8} = (1, 0, 1, 0, 0, 0, 1, 1) \\in \\field{8}.\n$$\n\nAnother implicit isomorphism is allowed between the vector space $\\field{n}$ and the polynomial ring $\\field{}[X]$:\n$$\nv = (v_1, \\ldots, v_n) \\in \\field{n}\n~~\\Leftrightarrow~~\n\\sum_{i=1}^n v_i X^{n-i} \\in \\field{}[X].\n$$\nFor example,\n$$\n\\hex{a3} \\in \\field{8} = (X^7 + X^5 + X + 1) \\in \\field{}[X]\n$$\nAssuming that an irreducible polynomial $P(x)$ defining\n$$\n\\fielde{n} \\simeq \\field{}[X]/(P(x))\n$$\nis clear from the context, the multiplication operation in the finite field is denoted $\\fmult$. The division in the finite field is denoted by $\\fdiv$. \n\n\n\\subsection{Algebraic Normal Form}\nAny Boolean function $f\\colon \\field{n} \\to \\field{}$ has a unique representation of the form\n$$\nf(x) = \\bigoplus_{u \\in \\field{n}} a_u x^u,~\nf(x) \\in \\field{}[x_1,\\ldots,x_n]/(x_1^2 + x_1, \\ldots, x_n^2 + x_n)\n$$\ncalled the \\emph{algebraic normal form (ANF)}. Here $x^u$ is a shorthand for $x_1^{u_1}\\ldots x_n^{u_n}$ and such products are called \\emph{monomials}. Let $\\coef{u}{f}\\in \\field{}$ denote the coefficient of the monomial $x^u$ in the ANF of $f$. It can be computed by the \\Mobius{} transform:\n$$\n\\coef{u}{f} \\eqdef a_u = \\bigoplus_{z \\in \\field{n}, z \\preceq u} f(z).\n$$\n\nThe \\emph{algebraic degree} of a Boolean function $f$ is the maximum Hamming weight of all $u$ such that $a_u=1$. Equivalently, it is the maximum degree of a monomial in the ANF of $f$.  It is denoted $\\deg{f}$. The zero-function is said to have the algebraic degree $-\\infty$. The set of all Boolean functions with $n$ input bits and degree at most $d$ is denoted by $\\BF{n,d}$. A Boolean function of algebraic degree at most 1 is called an \\emph{affine} function. An affine Boolean function $f$ is said to be \\emph{linear} if $f(0) = 0$. Any affine Boolean function $f\\colon \\field{n} \\to \\field{}$ can be expressed as $f(x) = \\inprod{a,x} + c$ for unique $a\\in \\field{n}$ and $c \\in \\field{}$, where $c = 0$ if and only if $f$ is linear.\n\n\n\\subsection{Derivatives}\nFor a Boolean function $f\\colon \\field{n} \\to \\field{}$ and a vector $\\alpha \\in \\field{n}$, I denote the function $\\delta_\\alpha f\\colon \\field{n} \\to \\field{}$ to be the \\emph{derivative} of $f$ with respect to $\\alpha$, given by\n$$\n\\delta_\\alpha f(x) \\eqdef f(x) \\oplus f(x\\oplus \\alpha).\n$$\nIt is well known that $\\deg{\\delta_\\alpha f} \\le \\max(-1, \\deg{f} - 1)$ for any Boolean function $f$ and any $\\alpha$, see~\\cite{Lai1994}. The derivation can be iterated multiple times resulting in a \\emph{higher-order derivative}. For $d$ linearly independent vectors $\\alpha_1, \\ldots, \\alpha_{d} \\in \\field{n}$ it holds that\n$$\n\\delta_{\\alpha_1}\\ldots \\delta_{\\alpha_{d}}f(x) = \\bigoplus_{z \\in \\Span(\\alpha_1, \\ldots, \\alpha_{d})} f(x \\oplus z).\n$$\nIf the vectors $\\alpha_1, \\ldots, \\alpha_{d}$ are linearly dependent, then the derivative is equal to zero.\n\n\n\\section{Vectorial Boolean Functions}\nA \\emph{Vectorial} Boolean function $S$ is a function mapping $\\field{n}$ to $\\field{m}$ for some positive integers $n,m$. When $n$ is relatively small, such functions are often called \\emph{S-Boxes}. Each output bit of a vectorial Boolean function naturally defines a Boolean function. The corresponding $m$ Boolean functions are called \\emph{coordinates} of $S$. For any nonzero $a \\in \\field{m}$ the mapping $x \\mapsto \\inprod{a, S(x)}$ is called a \\emph{component} of $S$ and is denoted by $S_a$. A component is a linear combination of coordinates of $S$. The function $S$ is said to be \\emph{balanced}, if each $y \\in \\field{m}$ has exactly $2^{n-m}$ preimages. In particular, $S$ is a bijection if and only if $m = n$ and $S$ is balanced.\n\nA vectorial function $S\\colon \\field{n} \\to \\field{m}$ can be given by the vector of its values using the following notation:\n$$\n\\lookup{S} \\eqdef (S(0), S(1), \\ldots, S(2^n-1)), ~\\text{where}~ S(x) \\in \\field{m}.\n$$\n\nThe \\emph{algebraic degree} of a vectorial Boolean function is defined to be the maximum algebraic degree of its coordinates.\n\nFor any $n \\in \\ZZplus$ the following maps are defined:\n\\eq{\n    &\\Left\\colon \\field{n} \\times \\field{n} \\to \\field{n},~~(a,b) \\mapsto a,\\\\\n    &\\Right\\colon \\field{n} \\times \\field{n} \\to \\field{n},~~(a,b) \\mapsto b,\\\\\n    &\\Swap\\colon \\field{n} \\times \\field{n} \\to \\field{n} \\times \\field{n},~~(a,b) \\mapsto (b,a).\n}\n\n\\subsection{Linear maps}\nThe vectors from $\\field{n}$ are considered as column vectors. The transpose of a vector or matrix $v$ is denoted $v^{\\top}$. The $n\\times n$ identity matrix is denoted $\\idmat{n}$. \n\nA vectorial Boolean function $S\\colon \\field{n} \\to \\field{m}$ is called \\emph{linear} (resp. \\emph{affine}) if all its coordinates are linear (resp. affine). If $S$ is affine, then it can be expressed as $S(x) = A \\times x \\oplus b$ for a unique $m \\times n$ matrix $A$ over $\\field{}$ and $b = S(0) \\in \\field{m}$, where $b = 0$ if and only if $S$ is linear.\n\nFor $m,n \\in \\ZZplus$, the set of all $m \\times n$ matrices over $\\field{}$ is denoted $\\linmap{n}{m}$. Any such matrix $M$ defines a linear map from $\\field{n}$ to $\\field{m}$, given by $x \\mapsto M\\times x$. The set of all bijective linear maps are denoted $\\linbij{n} \\subseteq \\linmap{n}{n}$. The set of all bijective affine maps is denoted $\\affbij{n}$.\n\n\n\\subsection{Equivalence Notions}\nThere are several important notions of \\emph{equivalence} between vectorial Boolean functions. Let $S_1,S_2\\colon \\field{n} \\to \\field{m}$ be vectorial Boolean functions. Let\n$$\\Gamma_1 = \\pset{(x, S_1(x)) \\mid x \\in \\field{n}} \\subseteq \\field{n+m},$$ \n$$\\Gamma_2 = \\pset{(x, S_2(x)) \\mid x \\in \\field{n}} \\subseteq \\field{n+m}$$\nbe the functional graphs of $S_1$ and $S_2$ respectively.\n\n\\begin{itemize}\n    \\item $S_1, S_2$ are \\emph{linear} (resp. \\emph{affine}) equivalent if there exist linear (resp. affine) mappings $A,B$ such that $S_2 = B \\circ S_1 \\circ A$.\n    \n    \\item $S_1, S_2$ are \\emph{extended-affine} equivalent (EA-equivalent) if there exist affine mappings $A,B,C$ such that $S_2 = B \\circ S_1 \\circ A \\oplus C$.\n    \n    \\item $S_1, S_2$ are \\emph{CCZ-equivalent} if there exists an affine mapping $L$ such that $\\Gamma_2 = L(\\Gamma_1) \\eqdef \\pset{L(x) \\mid x \\in \\Gamma_1}$, i.e. the functional graphs of $S_1$ and $S_2$ are affine equivalent.\n\\end{itemize}\n\n\n\n\\section{Set Indicators and Subspaces}\nLet $V \\subseteq \\field{n}$. The \\emph{indicator} of the set $V$ is defined as\n\\begin{align*}\n& \\Ind_V\\colon \\field{n} \\to \\field{},\\\\\n& \\Ind_V(x) :=\n    \\begin{cases}\n    1 &\\text{if } x \\in V, \\\\\n    0 &\\text{if } x \\notin V.\n    \\end{cases}\n\\end{align*}\nThe \\emph{degree} of the set $V$ is defined as the algebraic degree of its indicator:\n$$\n\\deg{V} \\eqdef \\deg{\\Ind_V}.\n$$\nIn the case of \\emph{multiset} over $\\field{n}$, only the elements with an even multiplicity are considered.\n\nA set $V \\subseteq \\field{n}$ is said to be a \\emph{linear subspace} if $V$ is closed under the addition in $\\field{n}$ (i.e., under the \\txor{} operation). A set $U \\subseteq \\field{n}$ is said to be an \\emph{affine subspace} if there exists $a \\in \\field{n}$ such that $V \\eqdef a \\oplus U \\eqdef \\pset{a \\oplus u \\mid u \\in U}$ is a linear subspace. It is then said that $U = a \\oplus V$ is a \\emph{coset} of the linear subspace $V$. Such $a$ may not be unique, but the corresponding linear subspace is unique.\n\nLet $U$ be any affine subspace. The \\emph{dimension} of $U$ is the maximum number of linearly independent vectors in the linear part of $U$; it is denoted $\\dim{U}$. Furthermore, $U$ has $2^{\\dim{U}}$ elements. $U$ can be viewed a solution to a system of $k \\eqdef n-\\dim{U}$ linear equations defined by affine functions $l_1,\\ldots,l_k$:\n$$\nU = \\{x \\in \\field{n} \\mid l_1(x) = 0, \\ldots, l_k(x) = 0\\}.\n$$\nIt follows that the indicator of $U$ is affine equivalent to a monomial function of degree $n - \\dim{U}$, i.e. it has the following form:\n$$\n\\Ind_U(x) = (l_1(x)+1)\\cdot \\ldots \\cdot (l_k(x)+1).\n$$\n\nConsider a Boolean function $f\\colon \\field{n} \\to \\field{}, f \\ne 0$ and let $d = \\deg{f}$. The minimum possible weight of $f$ is equal to $2^{n-d}$, i.e.\n$$\\wt(f) \\ge 2^{n-\\deg{f}}.$$\n%The equality holds if and only if $f$ is an indicator of an affine subspace, i.e. is affine equivalent to a monomial function.\n", "meta": {"hexsha": "ea072f0a8bfddd4886bff1c4a076139a6b9148e8", "size": 12695, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/2_Prelim/1Boolean.tex", "max_stars_repo_name": "hellman/thesis", "max_stars_repo_head_hexsha": "6ba1c2b241e63c07cf76108481c1b67f21a50f12", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2019-05-16T19:55:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T15:36:12.000Z", "max_issues_repo_path": "thesis-source/2_Prelim/1Boolean.tex", "max_issues_repo_name": "hellman/thesis", "max_issues_repo_head_hexsha": "6ba1c2b241e63c07cf76108481c1b67f21a50f12", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-08-09T11:26:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-09T11:26:45.000Z", "max_forks_repo_path": "thesis-source/2_Prelim/1Boolean.tex", "max_forks_repo_name": "hellman/thesis", "max_forks_repo_head_hexsha": "6ba1c2b241e63c07cf76108481c1b67f21a50f12", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-05T19:40:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T19:40:16.000Z", "avg_line_length": 68.6216216216, "max_line_length": 744, "alphanum_fraction": 0.6786136274, "num_tokens": 4312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.8215968052030805}}
{"text": "\\section{Strange Phenomenon in Training with Gradient Descent}\n\nWe want to use gradient descent to solve the Poisson equations.\n\\begin{equation}\n  \\label{BilinearNodalBasis}\n  \\left\\{\n  \\begin{array}{ll}\n-u''=f, \\quad on [0,1], \\\\\nu(0)=u(1)=0.\n\\end{array}\n\\right.\n\\end{equation}\n\nFor a given $f=\\pi^2sin(\\pi x) $, we can calculate the true solution as $u=sin(\\pi x)$. We also want to use gradient descent to calculate the numerical solution to compare the error.\n\nWe divide the unit interval into $n$ intervals equally and denote the boundary points as $x_i=\\frac{i}{n+1}, i=0,1,...,n+1$. Then the interpolation of the true solution is $u_i=sin(\\pi x_i)$. \n\nTo compute the numerical solution, we first define \n\\begin{equation}\nJ(v_h)=\\frac12\\int_0^1|v_h'|^2dx-\\int_0^1fv_hdx.\n\\end{equation}\nLet \n$$\n\\displaystyle v_h=\\sum_{i=1}^n\\nu_i\\varphi_i,\n$$\nthen \n$$\nJ(v_h)=I(\\nu)=\\frac12\\nu^TA\\ast\\nu-b^T\\nu\n$$\nand \n$$\n\\nabla I(\\nu) =A\\ast \\nu -b.\n$$\nHere $A=(-1,2,-1)/h$\nAt the same time, let $\\displaystyle u_h=\\sum_{i=1}^n\\mu_i\\varphi_i,$\n\\begin{equation}\\label{min}\n\\displaystyle u_h=\\argmin_{v_h\\in V_h} J(v_h)\\Leftrightarrow \\mu=\\argmin_{\\nu \\in R^n} I(\\nu)\n\\end{equation}\n\nTherefore, we choose a random $u_0$, then in $i$-th iteration we update\n\\begin{equation}\nu^i=u^{i-1}+\\eta(b-A * u^{i-1}).\n\\end{equation}\nWe plot the graph of the $H_1$-norm of the error, $||u^i-u||$, vs the number of iteration $i$.\n\nWhen we choose $k=4$ and $ \\eta=\\frac{h}{4},\\frac{h}{8},\\frac{h}{16},\\frac{h}{32}$ respectively, the graphs of the $H_1$-norm of the error, $||u^i-u||$, vs the number of iteration $i$ are as follows.\n\\begin{figure}[!htbp]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.45\\textwidth]{./figures/h-4}  \\quad \n\t\t\\includegraphics[width=0.45\\textwidth]{./figures/h-8} \\\\ \n\t\t\\includegraphics[width=0.45\\textwidth]{./figures/h-16} \\quad \n\t\t\\includegraphics[width=0.45\\textwidth]{./figures/h-32} \n\t\\end{center}\n\t\\caption{error vs number of iteration for $\\eta=\\frac{h}{4},\\frac{h}{8},\\frac{h}{16},\\frac{h}{32}$}\n\\end{figure}\n\nThere is a spike in  the graphs, where the error decreases very fast below $10^{-8}$ and then increase. Moreover, as $ \\eta$ decreases, the number of iteration where the spike happens also increases. \n\nOne explanation is that it's a special case when the interpolation of the true solution is a eigenvector of the matrix $A$. What we can do is to decrease the $ \\eta$ accordingly to a very small value.", "meta": {"hexsha": "33206ad19635041baba77fdd63915d2db4769ff7", "size": 2419, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/gd-suddendrop.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/gd-suddendrop.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/gd-suddendrop.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.0, "max_line_length": 200, "alphanum_fraction": 0.6932616784, "num_tokens": 853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.8774767986961401, "lm_q1q2_score": 0.8215683695109827}}
{"text": "\\chapter{Logistic Regression}\n\n\n\\section{Representation}\nLogistic regression can be binomial or multinomial. The \\textbf{binomial logistic regression} model has the following form\n\\begin{equation}\np(y|\\vec{x},\\vec{w})=\\mathrm{Ber}(y|\\mathrm{sigm}(\\vec{w}^T\\vec{x}))\n\\end{equation}\nwhere $\\vec{w}$ and $\\vec{x}$ are extended vectors, i.e., $\\vec{w}=(b, w_1, w_2,\\cdots, w_D)$, $\\vec{x}=(1, x_1, x_2,\\cdots, x_D)$.\n\n\n\\section{Optimization}\n\\label{sec:binomial-LR-Optimization}\n\n\\subsection{MLE}\n\\begin{align}\n\\ell(\\vec{w}) &= \\log\\left\\{\\prod\\limits_{i=1}^N{\\left[\\pi(\\vec{x}_i)\\right]^{y_i}\\left[1-\\pi(\\vec{x}_i)\\right]^{1-y_i}}\\right\\} \\nonumber \\\\\n              & \\quad \\text{, where } \\pi(\\vec{x}) \\triangleq P(y=1|\\vec{x},\\vec{w}) \\nonumber \\\\\n           &= \\sum\\limits_{i=1}^N\\left[y_i\\log\\pi(\\vec{x}_i)+(1-y_i)\\log(1-\\pi(\\vec{x}_i))\\right] \\label{eqn:cross-entropy-error} \\nonumber \\\\\n\t\t   &= \\sum\\limits_{i=1}^N\\left[y_i\\log\\dfrac{\\pi(\\vec{x}_i)}{1-\\pi(\\vec{x}_i)}+\\log(1-\\pi(\\vec{x}_i))\\right] \\nonumber \\\\\n\t\t   &= \\sum\\limits_{i=1}^N\\left[y_i(\\vec{w}\\cdot\\vec{x}_i)-\\log(1+\\exp(\\vec{w}\\cdot\\vec{x}_i))\\right] \\nonumber \\\\\nJ(\\vec{w}) & \\triangleq \\mathrm{NLL}(\\vec{w})= -\\ell(\\vec{w}) \\nonumber \\\\\n           & = -\\sum\\limits_{i=1}^N\\left[y_i(\\vec{w}\\cdot\\vec{x}_i)-\\log(1+\\exp(\\vec{w}\\cdot\\vec{x}_i))\\right] \n\\end{align}\n\nEquation \\ref{eqn:cross-entropy-error} is also called the \\textbf{cross-entropy} error function (see Equation \\ref{eqn:cross-entropy}).\n\nUnlike linear regression, we can no longer write down the MLE in closed form. Instead, we need to use an optimization algorithm to compute it, see Appendix \\ref{chap:Optimization-methods}. For this, we need to derive the gradient and Hessian.\n\nIn the case of logistic regression, one can show that the gradient and Hessian of this are given by the following\n\\begin{align}\n\\vec{g}(\\vec{w}) &= \\dfrac{\\mathrm{d} J}{\\mathrm{d} \\vec{w}} = \\sum\\limits_{i=1}^N \\left[\\pi(\\vec{x}_i) - y_i \\right]\\vec{x}_i = \\vec{X}(\\vec{\\pi}-\\vec{y})\\\\\n\\vec{H}(\\vec{w}) &= \\dfrac{\\mathrm{d} \\vec{g}^T}{\\mathrm{d} \\vec{w}}= \\dfrac{\\mathrm{d}}{\\mathrm{d} \\vec{w}} (\\vec{\\pi}-\\vec{y})^T\\vec{X}^T \\nonumber \\\\\n        &= \\dfrac{\\mathrm{d}}{\\mathrm{d} \\vec{w}} \\vec{\\pi}^T\\vec{X}^T \\nonumber \\\\\n\t\t&= (\\pi(\\vec{x}_i)(1-\\pi(\\vec{x}_i))\\vec{x}_i, \\cdots,)\\vec{X}^T \\nonumber \\\\\n\t\t&= \\vec{X}\\vec{S}\\vec{X}^T, \\quad \\vec{S} \\triangleq \\mathrm{diag}(\\pi(\\vec{x}_i)(1-\\pi(\\vec{x}_i))\\vec{x}_i)\n\\end{align}\n\n\n\\subsubsection{Iteratively reweighted least squares (IRLS)}\n\\label{sec:IRLS}\nTODO\n\n\n\\subsection{MAP}\nJust as we prefer ridge regression to linear regression, so we should prefer MAP estimation for logistic regression to computing the MLE. \n$\\ell_2$ regularization\n\nwe can use $\\ell_2$ regularization, just as we did with ridge regression. We note that the new objective, gradient and Hessian have the following forms:\n\\begin{align}\nJ'(\\vec{w}) & \\triangleq \\mathrm{NLL}(\\vec{w})+\\lambda \\vec{w}^T\\vec{w} \\\\\n\\vec{g}'(\\vec{w}) &= \\vec{g}(\\vec{w})+\\lambda\\vec{w} \\\\\n\\vec{H}'(\\vec{w}) &= \\vec{H}(\\vec{w})+\\lambda\\vec{I}\n\\end{align}\n\nIt is a simple matter to pass these modified equations into any gradient-based optimizer.\n\n\n\\section{Multinomial logistic regression}\n\n\n\\subsection{Representation}\n\\textbf{Multinomial logistic regression} model is also called a \\textbf{maximum entropy classifier}, which has the following form\n\\begin{align}\np(y=c|\\vec{x},\\vec{W}) & =\\dfrac{\\exp(\\vec{w}_c^T\\vec{x})}{\\sum_{c=1}^C \\exp(\\vec{w}_c^T\\vec{x})}\n\\end{align}\n\n\n\\subsection{MLE}\nLet $\\vec{y}_i=(\\mathbb{I}(y_i=1),\\mathbb{I}(y_i=1),\\cdots, \\mathbb{I}(y_i=C))$, $\\vec{\\mu}_i=(p(y=1|\\vec{x}_i,\\vec{W}),p(y=2|\\vec{x}_i,\\vec{W}),\\cdots, p(y=C|\\vec{x}_i,\\vec{W}))$, then the log-likelihood function can be written as\n\\begin{align}\n\\ell(\\vec{W}) & =\\log\\prod\\limits_{i=1}^N\\prod\\limits_{c=1}^C \\mu_{ic}^{y_{ic}}=\\sum\\limits_{i=1}^N\\sum\\limits_{c=1}^C y_{ic}\\log \\mu_{ic} \\\\\n     & = \\sum\\limits_{i=1}^N\\left[\\left(\\sum\\limits_{c=1}^C y_{ic}\\vec{w}_c^T\\vec{x}_i\\right)-\\log\\left(\\sum\\limits_{c=1}^C \\exp(\\vec{w}_c^T\\vec{x}_i)\\right)\\right]\n\\end{align}\n\nDefine the objective function as NLL\n\\begin{equation}\nJ(\\vec{W})=\\mathrm{NLL}(\\vec{W})=-\\ell(\\vec{W})\n\\end{equation}\n\nDefine $\\vec{A} \\otimes \\vec{B}$ be the \\textbf{kronecker product} of matrices $\\vec{A}$ and $\\vec{B}$.If $\\vec{A}$ is an $m \\times n$ matrix and $\\vec{B}$ is a $p \\times q$ matrix, then $\\vec{A} \\otimes \\vec{B}$ is the $mp \\times nq$ block matrix\n\\begin{equation}\n\\vec{A} \\otimes \\vec{B} \\triangle \\left(\\begin{array}{ccc}\na_{11}\\vec{B} & \\cdots & a_{1n}\\vec{B} \\\\\n\\vdots & \\vdots & \\vdots \\\\\na_{m1}\\vec{B} & \\cdots & a_{mn}\\vec{B}\n\\end{array}\\right)\n\\end{equation}\n\nThe gradient and Hessian are given by\n\\begin{align}\n\\vec{g}(\\vec{W}) & =\\sum\\limits_{i=1}^N (\\vec{\\mu}-\\vec{y}_i) \\otimes \\vec{x}_i \\\\\n\\vec{H}(\\vec{W}) & =\\sum\\limits_{i=1}^N (\\mathrm{diag}(\\vec{\\mu}_i)-\\vec{\\mu}_i\\vec{\\mu}_i^T) \\otimes (\\vec{x}_i\\vec{x}_i^T)\n\\end{align}\nwhere $\\vec{y}_i=(\\mathbb{I}(y_i=1),\\mathbb{I}(y_i=1),\\cdots, \\mathbb{I}(y_i=C-1))$ and $\\vec{\\mu}_i=(p(y=1|\\vec{x}_i,\\vec{W}),p(y=2|\\vec{x}_i,\\vec{W}),\\cdots, p(y=C-1|\\vec{x}_i,\\vec{W}))$ are column vectors of length $C-1$.\n\nPass them to any gradient-based optimizer.\n\n\n\\subsection{MAP}\nThe new objective\n\\begin{align}\nJ'(\\vec{W}) & =\\mathrm{NLL}(\\vec{w})-\\log{p(\\vec{W})} \\\\\n            & \\quad \\text{, where } p(\\vec{W}) \\triangleq \\prod\\limits_{c=1}^C \\mathcal{N}(\\vec{w}_c|\\vec{0},\\vec{V}_0) \\nonumber \\\\\n   & = J(\\vec{W})+\\dfrac{1}{2}\\sum\\limits_{c=1}^C \\vec{w}_c\\vec{V}_0^{-1}\\vec{w}_c \\\\\n\\end{align}\n\nIts gradient and Hessian are given by\n\\begin{align}\n\\vec{g}'(\\vec{w}) & =\\vec{g}(\\vec{W})+\\vec{V}_0^{-1}\\left(\\sum\\limits_{c=1}^C \\vec{w}_c\\right) \\\\\n\\vec{H}'(\\vec{w}) & =\\vec{H}(\\vec{w})+\\vec{I_C} \\otimes \\vec{V}_0^{-1}\n\\end{align}\n\nThis can be passed to any gradient-based optimizer to find the MAP estimate. Note, however, that the Hessian has size $((CD)\u00d7(CD))$, which is $C$ times more row and columns than in the binary case, so limited memory BFGS is more appropriate than Newton\u2019s method.\n\n\n\\section{Bayesian logistic regression}\nIt is natural to want to compute the full posterior over the parameters, $p(\\vec{w}|\\mathcal{D})$, for logistic regression models. This can be useful for any situation where we want to associate confidence intervals with our predictions (e.g., this is necessary when solving contextual bandit problems, discussed in Section TODO).\n\nUnfortunately, unlike the linear regression case, this cannot be done exactly, since there is no convenient conjugate prior for logistic regression. We discuss one simple approximation below; some other approaches include MCMC (Section TODO), variational inference (Section TODO), expectation propagation (Kuss and Rasmussen 2005), etc. For notational simplicity, we stick to binary logistic regression.\n\n\n\\subsection{Laplace approximation}\n\n\n\\subsection{Derivation of the BIC}\n\n\n\\subsection{Gaussian approximation for logistic regression}\n\\label{sec:Gaussian-approximation-for-logistic-regression}\n\n\n\\subsection{Approximating the posterior predictive}\n\n\n\\subsection{Residual analysis (outlier detection) *}\n\n\n\\section{Online learning and stochastic optimization}\nTraditionally machine learning is performed \\textbf{offline}, however, if we have \\textbf{streaming data}, we need to perform \\textbf{online learning}, so we can update our estimates as each new data point arrives rather than waiting until \u201cthe end\u201d (which may never occur). And even if we have a batch of data, we might want to treat it like a stream if it is too large to hold in main memory. Below we discuss learning methods for this kind of scenario.\n\nTODO\n\n\n\\subsection{The perceptron algorithm}\n\n\\subsubsection{Representation}\n\\begin{equation}\n\\mathcal{H}:y=f(\\vec{x})=\\text{sign}(\\vec{w}^T\\vec{x}+b)\n\\end{equation}\nwhere $\\text{sign}(x)=\\begin{cases}+1, & x \\geq 0\\\\-1, & x<0\\\\\\end{cases}$, see Fig. \\ref{fig:perceptron}\\footnote{\\url{https://en.wikipedia.org/wiki/Perceptron}}.\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.50]{perceptron.png}\n\\caption{Perceptron}\n\\label{fig:perceptron} \n\\end{figure}\n\n\n\\subsubsection{Evaluation}\n\\begin{eqnarray}\nL(\\vec{w},b)&=&-y_i(\\vec{w}^T\\vec{x}_i+b)\\\\\nR_{emp}(f)&=&-\\sum\\limits_i y_i(\\vec{w}^T\\vec{x}_i+b)\\\\\n\\end{eqnarray}\n\n\n\\subsubsection{Optimization}\n\\textbf{Primal form}\n\\begin{algorithm}[htbp]\n\\caption{Perceptron learning algorithm, primal form, using SGD}\n  \n    $\\vec{w} \\leftarrow 0;\\; b \\leftarrow 0;\\; k \\leftarrow 0$\\;\n    \\While{no mistakes made within the for loop}{\n        \\For{$i\\leftarrow 1$ \\KwTo $N$}{\n\t\t\t\\If{$y_i(\\vec{w} \\cdot \\vec{x}_i+b) \\leq 0$}{\n\t\t\t\t$\\vec{w} \\leftarrow \\vec{w}+\\eta y_i \\vec{x}_i$\\;\n\t\t\t\t$b \\leftarrow b+\\eta y_i$\\;\n\t\t\t\t$k \\leftarrow k+1$\\;\n\t\t\t}\n\t\t}\n    }\n\\end{algorithm}\n\n\\textbf{Convergency}\n\\begin{theorem}\n(\\textbf{Novikoff}) If traning data set $\\mathcal{D}$ is linearly separable, then\n\\begin{enumerate}\n\\item There exists a hyperplane denoted as $\\widehat{\\vec{w}}_{opt} \\cdot \\vec{x}+b_{opt}=0$ which can correctly seperate all samples, and \n\\begin{equation}\n\\exists\\gamma>0,\\; \\forall i, \\; y_i(\\vec{w}_{opt} \\cdot \\vec{x}_i+b_{opt}) \\geq \\gamma\n\\end{equation}\n\\item \\begin{equation}k \\leq \\left(\\dfrac{R}{\\gamma}\\right)^2,\\text{ where } R=\\max\\limits_{1 \\leq i \\leq N} \\abs{\\abs{\\widehat{\\vec{x}}_i}}\n\\end{equation}\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\n(1) let $\\gamma=\\min\\limits_{i} y_i(\\vec{w}_{opt} \\cdot \\vec{x}_i+b_{opt})$, then we get $y_i(\\vec{w}_{opt} \\cdot \\vec{x}_i+b_{opt}) \\geq \\gamma$.\n\n(2) The algorithm start from $\\widehat{\\vec{x}}_0=0$, if a instance is misclassified, then update the weight. Let $\\widehat{\\vec{w}}_{k-1}$ denotes the extended weight before the k-th misclassified instance, then we can get\n\\begin{eqnarray}\ny_i(\\widehat{\\vec{w}}_{k-1} \\cdot \\widehat{\\vec{x}_i})&=&y_i(\\vec{w}_{k-1} \\cdot \\vec{x}_i+b_{k-1}) \\leq 0\\\\\n\\widehat{\\vec{w}}_k&=&\\widehat{\\vec{w}}_{k-1}+\\eta y_i \\widehat{\\vec{x}_i}\n\\end{eqnarray}\n\nWe could infer the following two equations, the proof procedure are omitted.\n\\begin{enumerate}\n\\item $\\widehat{\\vec{w}}_k \\cdot \\widehat{\\vec{w}}_{opt} \\geq k\\eta\\gamma$\n\\item $\\abs{\\abs{\\widehat{\\vec{w}}_k}}^2 \\leq k\\eta^2R^2$\n\\end{enumerate}\n\nFrom above two equations we get\n\\begin{eqnarray}\n\\nonumber k\\eta\\gamma & \\leq & \\widehat{\\vec{w}}_k \\cdot \\widehat{\\vec{w}}_{opt} \\leq \\abs{\\abs{\\widehat{\\vec{w}}_k}}\\abs{\\abs{\\widehat{\\vec{w}}_{opt}}} \\leq \\sqrt k \\eta R \\\\\n\\nonumber k^2\\gamma^2 & \\leq & kR^2 \\\\\n\\nonumber \\text{i.e. } k & \\leq & \\left(\\dfrac{R}{\\gamma}\\right)^2\n\\end{eqnarray}\n\\end{proof}\n\n\n\\textbf{Dual form}\n\\begin{eqnarray}\n\\vec{w}&=&\\sum\\limits_{i=1}^{N} \\alpha_iy_i\\vec{x}_i \\\\\nb&=&\\sum\\limits_{i=1}^{N} \\alpha_iy_i \\\\\nf(\\vec{x})&=&\\text{sign}\\left(\\sum\\limits_{j=1}^{N} \\alpha_jy_j\\vec{x}_j \\cdot \\vec{x}+b\\right)\n\\end{eqnarray}\n\n\\begin{algorithm}[htbp]\n    %\\SetAlgoLined\n    \\SetAlgoNoLine\n  \n    $\\vec{\\alpha} \\leftarrow 0;\\; b \\leftarrow 0;\\; k \\leftarrow 0$\\;\n    \\While{no mistakes made within the for loop}{\n        \\For{$i\\leftarrow 1$ \\KwTo $N$}{\n\t\t\t\\If{$y_i\\left(\\sum\\limits_{j=1}^{N} \\alpha_jy_j\\vec{x}_j \\cdot \\vec{x}_i+b\\right) \\leq 0$}{\n\t\t\t\t$\\vec{\\alpha} \\leftarrow \\vec{\\alpha}+\\eta$\\;\n\t\t\t\t$b \\leftarrow b+\\eta y_i$\\;\n\t\t\t\t$k \\leftarrow k+1$\\;\n\t\t\t}\n\t\t}\n    }\n\\caption{Perceptron learning algorithm, dual form}\n\\end{algorithm}\n\n\n\\section{Generative vs discriminative classifiers}\n\n\n\\subsection{Pros and cons of each approach}\n\\begin{itemize}\n\\item{\\textbf{Easy to fit?} As we have seen, it is usually very easy to fit generative classifiers. For example, in Sections \\ref{sec:NBC-Optimization} and \\ref{sec:MLE-for-discriminant-analysis}, we show that we can fit a naive Bayes model and an LDA model by simple counting and averaging. By contrast, logistic regression requires solving a convex optimization problem (see Section \\ref{sec:binomial-LR-Optimization} for the details), which is much slower.}\n\n\\item{\\textbf{Fit classes separately?} In a generative classifier, we estimate the parameters of each class conditional density independently, so we do not have to retrain the model when we add more classes. In contrast, in discriminative models, all the parameters interact, so the whole model must be retrained if we add a new class. (This is also the case if we train a generative model to maximize a discriminative objective Salojarvi et al. (2005).)}\n\n\\item{\\textbf{Handle missing features easily?} Sometimes some of the inputs (components ofx) are not observed. In a generative classifier, there is a simple method for dealing with this, as we discuss in Section \\ref{sec:Dealing-with-missing-data}. However, in a discriminative classifier, there is no principled solution to this problem, since the model assumes that $\\vec{x}$is always available to be conditioned on (although see (Marlin 2008) for some heuristic approaches).}\n\n\\item{\\textbf{Can handle unlabeled training data?} There is much interest in \\textbf{semi-supervised learning}, which uses unlabeled data to help solve a supervised task. This is fairly easy to do using generative models (see e.g., (Lasserre et al. 2006; Liang et al. 2007)), but is much harder to do with discriminative models.}\n\n\\item{\\textbf{Symmetric in inputs and outputs?} We can run a generative model \u201cbackwards\u201d, and infer probable inputs given the output by computing $p(\\vec{x}|y)$. This is not possible with a discriminative model. The reason is that a generative model defines a joint distribution on $\\vec{x}$ and $y$, and hence treats both inputs and outputs symmetrically.}\n\n\\item{\\textbf{Can handle feature preprocessing?} A big advantage of discriminative methods is that they allow us to preprocess the input in arbitrary ways, e.g., we can replace $\\vec{x}$ with $\\phi(\\vec{x})$, which could be some basis function expansion, etc. It is often hard to define a generative model on such pre-processed data, since the new features are correlated in complex ways.}\n\n\\item{\\textbf{Well-calibrated probabilities?} Some generative models, such as naive Bayes, make strong independence assumptions which are often not valid. This can result in very extreme posterior class probabilities (very near 0 or 1). Discriminative models, such as logistic regression, are usually better calibrated in terms of their probability estimates.}\n\\end{itemize}\n\nSee Table \\ref{tab:List-of-various-models-for-classification} for a summary of the classification and regression techniques we cover in this book.\n\n\\begin{table*}\n\\centering\n\\begin{tabular}{lllll}\n\\hline\\noalign{\\smallskip}\n\\textbf{Model} & \\textbf{Classif/regr} & \\textbf{Gen/Discr} & \\textbf{Param/Non} & \\textbf{Section} \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nDiscriminant analysis & Classif & Gen & Param & Sec. \\ref{sec:Linear-discriminant-analysis}, \\ref{sec:MLE-for-discriminant-analysis} \\\\\nNaive Bayes classifier & Classif & Gen & Param & Sec. \\ref{sec:NBC}, \\ref{sec:Bayesian-naive-Bayes} \\\\\nTree-augmented Naive Bayes classifier & Classif & Gen & Param & Sec. 10.2.1 \\\\\nLinear regression & Regr & Discrim & Param & Sec. 1.4.5, 7.3, 7.6 \\\\\nLogistic regression & Classif & Discrim & Param & Sec. 1.4.6, \\ref{sec:IRLS}, \\ref{sec:Gaussian-approximation-for-logistic-regression}, 21.8.1.1 \\\\\nSparse linear/ logistic regression & Both & Discrim & Param & Ch. 13 \\\\\nMixture of experts & Both & Discrim & Param & Sec. 11.2.4 \\\\\nMultilayer perceptron (MLP)/ Neural network & Both & Discrim & Param & Ch. 16 \\\\\nConditional random field (CRF) & Classif & Discrim & Param & Sec. 19.6 \\\\\n\\noalign{\\smallskip}\\hline \\\\\n$K$ nearest neighbor classifier & Classif & Gen & Non & Sec. TODO, TODO \\\\\n(Infinite) Mixture Discriminant analysis & Classif & Gen & Non & Sec. 14.7.3 \\\\\nClassification and regression trees (CART) & Both & Discrim & Non & Sec. 16.2 \\\\\nBoosted model & Both & Discrim & Non & Sec. 16.4 \\\\\nSparse kernelized lin/logreg (SKLR) & Both & Discrim & Non & Sec. 14.3.2 \\\\\nRelevance vector machine (RVM) & Both & Discrim & Non & Sec. 14.3.2 \\\\\nSupport vector machine (SVM) & Both & Discrim & Non & Sec. 14.5 \\\\\nGaussian processes (GP) & Both & Discrim & Non & Ch. 15 \\\\\nSmoothing splines & Regr & Discrim & Non & Section 15.4.6 \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\caption{List of various models for classification and regression which we discuss in this book. Columns are as follows: Model name; is the model suitable for classification, regression, or both; is the model generative or discriminative; is the model parametric or non-parametric; list of sections in book which discuss the model. See also \\url{http://pmtk3.googlecode.com/svn/trunk/docs/tutorial/html/tutSupervised.html} for the PMTK equivalents of these models. Any generative probabilistic model (e.g., HMMs, Boltzmann machines, Bayesian networks, etc.) can be turned into a classifier by using it as a class conditional density}\n\\label{tab:List-of-various-models-for-classification}\n\\end{table*}\n\n\n\\subsection{Dealing with missing data}\n\\label{sec:Dealing-with-missing-data}\nSometimes some of the inputs (components of $\\vec{x}$) are not observed; this could be due to a sensor failure, or a failure to complete an entry in a survey, etc. This is called the \\textbf{missing data problem} (Little. and Rubin 1987). The ability to handle missing data in a principled way is one of the biggest advantages of generative models.\n\nTo formalize our assumptions, we can associate a binary response variable $r_i \\in \\{0,1\\}$ that specifies whether each value $\\vec{x}_i$ is observed or not. The joint model has the form $p(\\vec{x}_i,r_i|\\vec{\\theta},\\vec{\\phi})=p(r_i|\\vec{x}_i,\\vec{\\phi})p(\\vec{x}_i|\\vec{\\theta})$, where $\\vec{\\phi}$ are the parameters controlling whether the item is observed or not. \n\\begin{itemize}\n\\item{If we assume $p(r_i|\\vec{x}_i,\\vec{\\phi})=p(r_i|\\vec{\\phi})$, we say the data is \\textbf{missing completely at random} or \\textbf{MCAR}.}\n\\item{If we assume $p(r_i|\\vec{x}_i,\\vec{\\phi})=p(r_i|\\vec{x}_i^o,\\vec{\\phi})$, where $\\vec{x}_i^o$ is the observed part of $\\vec{x}_i$, we say the data is \\textbf{missing at random} or \\textbf{MAR}.}\n\\item{If neither of these assumptions hold, we say the data is \\textbf{not missing at random} or \\textbf{NMAR}. In this case, we have to model the missing data mechanism, since the pattern of missingness is informative about the values of the missing data and the corresponding parameters. This is the case in most collaborative filtering problems, for example.}\n\\end{itemize}\n\nSee e.g., (Marlin 2008) for further discussion. We will henceforth assume the data is MAR.\n\nWhen dealing with missing data, it is helpful to distinguish the cases when there is missingness only at test time (so the training data is \\textbf{complete data}), from the harder case when there is missingness also at training time. We will discuss these two cases below. Note that the class label is always missing at test time, by definition; if the class label is also sometimes missing at training time, the problem is called semi-supervised learning.\n\n\n\\subsubsection{Missing data at test time}\nIn a generative classifier, we can handle features that are MAR by marginalizing them out. For example, if we are missing the value ofx1, we can compute\n\\begin{align}\np(y=c|\\vec{x}_{2:D},\\vec{\\theta}) & \\propto p(y=c|\\vec{\\theta})p(\\vec{x}_{2:D}|y=c,\\vec{\\theta}) \\\\\n      & = \\propto p(y=c|\\vec{\\theta})\\sum\\limits_{x_1}p(x_1, \\vec{x}_{2:D}|y=c,\\vec{\\theta})\n\\end{align}\n\nSimilarly, in discriminant analysis, no matter what regularization method was used to estimate the parameters, we can always analytically marginalize out the missing variables (see Section \\ref{sec:Inference-in-jointly-Gaussian-distributions}):\n\\begin{equation}\np(\\vec{x}_{2:D}|y=c,\\vec{\\theta})=\\mathcal{N}(\\vec{x}_{2:D}|\\vec{\\mu}_{c,2:D},\\vec{\\Sigma}_{c,2:D})\n\\end{equation}\n\n\n\\subsubsection{Missing data at training time}\nMissing data at training time is harder to deal with. In particular, computing the MLE or MAP estimate is no longer a simple optimization problem, for reasons discussed in Section TODO. However, soon we will study are a variety of more sophisticated algorithms (such as EM algorithm, in Section 11.4) for finding approximate ML or MAP estimates in such cases.\n\n\n\\subsection{Fisher\u2019s linear discriminant analysis (FLDA) *}\nTODO", "meta": {"hexsha": "c1a2e0dbe15ddf71a3ef9720215e50e18207658c", "size": 20221, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterLogisticRegression.tex", "max_stars_repo_name": "Alexoner/Statistical-formula", "max_stars_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-15T17:00:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-24T13:46:00.000Z", "max_issues_repo_path": "mlapp/chapterLogisticRegression.tex", "max_issues_repo_name": "Alexoner/Statistical-formula", "max_issues_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mlapp/chapterLogisticRegression.tex", "max_forks_repo_name": "Alexoner/Statistical-formula", "max_forks_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-02-25T15:40:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T04:26:03.000Z", "avg_line_length": 60.3611940299, "max_line_length": 633, "alphanum_fraction": 0.7058503536, "num_tokens": 6562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.8774767842777551, "lm_q1q2_score": 0.8215683544512259}}
{"text": "\\section{Bilinar Forms}\r\n\\begin{definition}\r\n    Let $U,V$ be vector spaces over $F$, then $\\phi:U\\times V\\to F$ is a bilinear form if $\\phi(u,\\cdot)\\in V^\\ast$ and $\\phi(\\cdot,v)\\in U^\\ast$ for any $u\\in U,v\\in V$.\r\n\\end{definition}\r\nWe write $\\phi_L\\in L(U,V^\\ast)$ to be the map $u\\mapsto\\phi(u,\\cdot)$ and $\\phi_R\\in L(V,U^\\ast)$ as $v\\mapsto\\phi(\\cdot,v)$.\r\nIn particular, $\\phi_L(u)(v)=\\phi(u,v)=\\phi_R(v)(u)$.\r\n\\begin{example}\r\n    1. The map $V\\times V^\\ast\\to F$ via $(v,\\theta)\\mapsto \\theta$ is a bilinear form.\\\\\r\n    2. The scalar product on $F^n$, that is\r\n    $$\\left( \\begin{pmatrix}\r\n        x_1\\\\\r\n        \\vdots\\\\\r\n        x_n\r\n    \\end{pmatrix}, \\begin{pmatrix}\r\n        y_1\\\\\r\n        \\vdots\\\\\r\n        y_n\r\n    \\end{pmatrix}\\right)\\mapsto \\sum_{i=1}^nx_iy_i$$\r\n    is a bilinear form.\\\\\r\n    3. Take $U=V=C([0,1],\\mathbb R)$, then\r\n    $$(f,g)\\mapsto\\int_0^1f(t)g(t)\\,\\mathrm dt$$\r\n    is a bilinear form.\r\n\\end{example}\r\n\\begin{definition}\r\n    Take a basis $B=\\{e_1,\\ldots,e_m\\}$ of $U$ and $C=\\{f_1,\\ldots,f_n\\}$ basis of $V$ and $\\phi:U\\times V\\to F$ a bilinear form, then the matrix of $\\phi$ with respect to $B,C$ is\r\n    $$[\\phi]_{B,C}=(\\phi(e_i,f_j))_{1\\le i\\le m,1\\le j\\le n}$$\r\n\\end{definition}\r\n\\begin{lemma}\r\n    We have $\\phi(u,v)=[u]_B^\\top[\\phi]_{B,C}[v]_C$ for any $u\\in U,v\\in V$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If $u=\\sum_i\\lambda_ie_i$ and $v=\\sum_j\\mu_jf_j$, then by linearity,\r\n    $$\\phi(u,v)=\\sum_{i=1}^n\\sum_{j=1}^n\\lambda_i\\mu_j\\phi(e_i,f_j)=[u]_B^\\top[\\phi]_{B,C}[v]_C$$\r\n    by simple expansion.\r\n\\end{proof}\r\n\\begin{remark}\r\n    The matrix $[\\phi]_{B,C}$ is the unique matrix such that the previous lemma holds.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    Take a basis $B=\\{e_1,\\ldots,e_m\\}$ of $U$ and the dual basis $B^\\ast=\\{\\epsilon_1,\\ldots,\\epsilon_m\\}$ of $U^\\ast$.\r\n    Similarly take a basis $C=\\{f_1,\\ldots,f_n\\}$ of $v$ and the dual basis $\\{\\eta_1,\\ldots,\\eta_n\\}$ of $V^\\ast$.\r\n    If $A=[\\phi]_{B,C}$ where $\\phi:U\\times V\\to F$ is a bilinear form, then $[\\phi_R]_{C,B^\\ast}=A$ and $[\\phi_L]_{B,C^\\ast}=A^\\top$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Completely trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    $\\ker\\phi_L$ is called the left kernel of $\\phi$ and $\\ker\\phi_R$ is called the right kernel of $\\phi$.\\\\\r\n    $\\phi$ is nondegenerate if both kernels are $\\{0\\}$.\r\n    Otherwise, we say $\\phi$ is degenerate.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    Let $B,C$ be bases of $U,V$ respectively and $\\phi:U\\times V\\to F$ be bilinear.\r\n    Let $A=[\\phi]_{B,C}$, then $\\phi$ is nondegenerate iff $A$ is invertible.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Immediate from the preceding lemma.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $\\phi$ is nondegenerate, then $\\dim U=\\dim V$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    All invertible matrices are square.\r\n\\end{proof}\r\n\\begin{example}\r\n    So the dot product on $\\mathbb R^n$ is nondegenerate.\r\n\\end{example}\r\n\\begin{corollary}\r\n    If $U,V$ are finite dimensional vector spaces over $F$, then choosing a nondegenerate bilinear form $U\\times V\\to F$ is just choosing an isomorphism $\\phi_L:U\\to V^\\ast$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\begin{definition}\r\n    For $T\\subset U$, we define $T^\\perp=\\{v\\in V:\\forall t\\in T,\\phi(t,v)=0\\}$ and for $S\\subset V$ we define ${}^\\perp S=\\{u\\in U:\\forall s\\in S,\\phi(u,s)=0\\}$\r\n\\end{definition}\r\nOf course we want to change the basis.\r\n\\begin{proposition}\\label{bilinear_change_of_basis}\r\n    Let $B,B'$ be bases of $U$ and $P=[\\operatorname{id}]_{B',B}$ and $C,C'$ be basis of $V$ and $Q=[\\operatorname{id}]_{C',C}$ and let $\\phi:U\\times V\\to F$ be a bilinear form.\r\n    Then $[\\phi]_{B',C'}=P^\\top[\\phi]_{B,C}Q$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    We have\r\n    $$\\phi(u,v)=[u]_B^\\top[\\phi]_{B,C}[v]_C=(P[u]_{B'})^\\top [\\phi]_{B,C}(Q[v]_{C'})=[u]_{B'}^\\top (P^\\top[\\phi]_{B,C}Q)[v]_{C'}$$\r\n    So necessarily $[\\phi]_{B',C'}=P^\\top[\\phi]_{B,C}Q$.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    The rank of the matrix of $\\phi$ in any basis is fixed.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{definition}\r\n    The rank $r(\\phi)$ of $\\phi$ is the rank of its matrix in any basis.\r\n\\end{definition}\r\n\\begin{remark}\r\n    We have $r(\\phi)=r(\\phi_R)=r(\\phi_L)$.\r\n\\end{remark}", "meta": {"hexsha": "828cd4c5d0f5d3135c5344cf206fddb9b9652c3b", "size": 4241, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10/bilinear.tex", "max_stars_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_stars_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "10/bilinear.tex", "max_issues_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_issues_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "10/bilinear.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.2755102041, "max_line_length": 181, "alphanum_fraction": 0.6085828814, "num_tokens": 1593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.9136765275272112, "lm_q1q2_score": 0.821506090400115}}
{"text": "\\section{Generation of Random Variables}\r\n\\begin{example}\r\n    Suppose $U\\sim\\operatorname{Unif}(0,1)$ and set $Y=-\\log U$, so $\\mathbb P(Y\\le x)=\\mathbb P(U\\ge e^{-x})=1-e^{-x}$ which is $\\operatorname{Exp}(1)$.\r\n\\end{example}\r\n\\begin{theorem}\r\n    Let $X$ be a continuous random variable with distribution $F$ and $U\\sim\\operatorname{Unif}(0,1)$, then $F^{-1}(U)$ has the same distribution as $X$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\nAnother way to generate is called the rejection sampling.\r\nSuppose $A\\subset [0,1]^d$ (measurable) and $f(x)=1_{A}(x)/|A|$ where $|A|$ is the volume of $A$.\r\nWe want a random variables $X$ to have density $f$.\r\nLet $U_n$ be an i.i.d. sequence of $d$-dimensional uniforms, i.e. $U_n=(U_{k,n}:k=1,\\ldots,d)$ where $U_{k,n}$ are i.i.d. $\\operatorname{Unif}[0,1]$.\r\nLet $N=\\min\\{n\\ge 1:U_n\\in A\\}$ and set $X=U_N$.\r\n\\begin{proposition}\r\n    Let $B\\in[0,1]^d$, then $\\mathbb P(X\\in B)=|B\\cap A|/|A|$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    \\begin{align*}\r\n        \\mathbb P(X\\in B)&=\\sum_{n=1}^\\infty\\mathbb P(X\\in B,N=n)\\\\\r\n        &=\\sum_{n=1}^\\infty\\mathbb P(U_n\\in A\\cap B,U_{n-1}\\notin A,\\ldots,U_1\\notin A)\\\\\r\n        &=\\sum_{n=1}^\\infty |A\\cap B|(1-|A|)^{n-1}\\\\\r\n        &=\\frac{|A\\cap B|}{|A|}\\\\\r\n        &\\left(=\\int_Bf(x)\\,\\mathrm dx\\right)\r\n    \\end{align*}\r\n    As desired.\r\n\\end{proof}\r\nLet $f$ be a bounded density on $[0,1]^{d-1}$, that is $\\exists\\lambda,\\sup f\\le\\lambda$ and we want to find $X\\sim f$.\r\nConsider $A=\\{(x_1,\\ldots,x_d)\\in [0,1]^d:x_d\\in f(x_1,\\ldots,x_{n-1})/\\lambda\\}$.\r\nLet $Y=(X_1,\\ldots,X_d)$ be uniform on $A$ generated as above and set $X=(X_1,\\ldots,X_{d-1})$.\r\n\\begin{proposition}\r\n    $X\\sim f$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Let $B\\subset [0,1]^{d-1}$, then\r\n    \\begin{align*}\r\n        \\mathbb P(X\\in B)&=\\mathbb P((X_1,\\ldots,X_d)\\in (B\\times [0,1])\\cap A)\\\\\r\n        &=\\frac{(B\\times [0,1]\\cap A)}{|A|}\\\\\r\n        &=\\frac{1}{|A|}\\int\\cdots\\int_{[0,1]^d}1_{(B\\times [0,1])\\cap A}((x_1\\cdots x_d))\\,\\mathrm dx_1\\cdots\\mathrm dx_n\\\\\r\n        &=\\frac{1}{|A|}\\int\\cdots\\int_{[0,1]^d}1_{B}((x_1,\\ldots ,x_{d-1}))\\frac{f(x_1,\\ldots,x_{d-1})}{\\lambda}\\,\\mathrm dx_1\\cdots\\mathrm dx_n\\\\\r\n        &=\\int_Bf(x)\\,\\mathrm dx\r\n    \\end{align*}\r\n    which is what we wanted.\r\n\\end{proof}", "meta": {"hexsha": "fbfb9602136dea6580279b33bd541e6af7ee7126", "size": 2280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11/genrv.tex", "max_stars_repo_name": "david-bai-notes/IA-Probability", "max_stars_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11/genrv.tex", "max_issues_repo_name": "david-bai-notes/IA-Probability", "max_issues_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11/genrv.tex", "max_forks_repo_name": "david-bai-notes/IA-Probability", "max_forks_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.6666666667, "max_line_length": 154, "alphanum_fraction": 0.5846491228, "num_tokens": 949, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541610257063, "lm_q2_score": 0.8723473813156294, "lm_q1q2_score": 0.8214495414757409}}
{"text": "If you haven't downloaded and unzipped \\href{https://libaoj.in/courses/2021f/MATH3341/zip/Math.3341.zip}{\\texttt{Math.3341.zip}}. Download and unzip it under \\verb|H:| (H Drive if you are working on the Remote Lab). Change the current working directory by typing \\verb|cd H:\\Math.3341\\Math.3341.Lab.09| in the Command Window, and type \\verb|edit lab_09_script| in the Command Window to edit \\verb|lab_09_script.m|.\n\n%---------------------------------------------\n\\section{Ill-Conditioned Systems}\n%---------------------------------------------\n\\begin{enumerate}[(a)]\n    \\item Open the function file \\verb|lab_09_function.m|.\n    \\item Generate an $n \\times n$ Hilbert matrix \\verb`A`.\n    \\item Create an $n \\times 1$ all-one vector \\verb`b`.\n    \\item Now solve the ill-conditioned linear system $A x = b$ for $x$ by means of $x = A^{-1} b$:\n        \\begin{itemize}\n            \\item Use \\verb|invhilb| to find $A^{-1}$, and store the exact solution $x$ to \\verb|x_exact|.\n            \\item Use \\verb|\\| to solve the linear system and store the approximate solution $\\hat{x}$ to \\verb|x_backslash|.\n            \\item Use \\verb|inv| to find $A^{-1}$, and store the approximate solution $\\hat{x}$ to \\verb|x_inv|.\n        \\end{itemize}\n    \\item Calculate the infinity norm of relative error of \\verb|x_backslash| and \\verb|x_inv| using the formula below, and store each relative error to \\verb|error_backslash| and \\verb|error_inv|, respectively.\n        $$\n        \\mathrm{error}_{\\mathrm{relative}} = \\frac{\\|\\hat{x} - x\\|_{\\infty}}{\\|x\\|_{\\infty}}.\n        $$\n    \\item Calculate the 1-norm condition number of matrix \\verb`A` using \\verb|cond| and store the result to \\verb`cond_A`.\n    \\item Next, go to \\verb|lab_09_script.m|, create a vector named \\verb|n|: \\verb|n = [9, 11, 13, 15]|. Using a for-loop to call \\verb|lab_09_function| by passing each entry of \\verb|n| as the input argument. What do you notice about the results?\n\\end{enumerate}\n%---------------------------------------------\n\\section{Finite Precision Arithmetic}\n%---------------------------------------------\n\\begin{enumerate}[(a)]\n    \\item Use either a for-loop or \\verb|sum| to calculate\n            $$\n            s = \\sum_{i=1}^{10} 0.1 = 0.1 + 0.1 + \\cdots + 0.1.\n            $$\n            Then calculate the error \\verb|error_1 = abs(s - 1)|.\n    \\item Calculate\n            $$\n            b = 2 - 3 \\left(\\frac{4}{3} - 1\\right).\n            $$\n            Then calculate the error \\verb|error_2 = abs(b - 1)|.\n    \\item Calculate each side of the following equation in the variables \\verb|lhs| and \\verb|rhs|:\n            $$\n            1 + a + a^2 + a^3 + a^4 + a^5 = \\frac{1 - a^6}{1 - a},\n            $$\n            for the value $a = 0.3$. Then calculate the error \\verb|error_3 = abs(lhs - rhs)|. Hint: you can use either a for-loop or \\verb`polyval` to calculate \\verb|lhs|.\n    \\item Calculate the following and compare their output.\n            % \\begin{verbatim}\n            \\begin{lstlisting}{style=MATLAB}\nx = 1e16 + 1 - 1e16;\ny = 1e16 - 1e16 + 1;\nz = 1e16 - (1e16 - 1);\n            \\end{lstlisting}\n            % \\end{verbatim}\n    \\item Calculate the following and compare their output.\n            % \\begin{verbatim}\n            \\begin{lstlisting}{style=MATLAB}\nu = 1 + 0.1 - 1;\nv = 1 - 1 + 0.1;\nw = 1 - (1 - 0.1);\n            \\end{lstlisting}\n            % \\end{verbatim}\n\\end{enumerate}\n\nOnce you finish, call \\verb|diary('lab_09_output.txt')|, then run the script file \\verb|lab_09_script.m|, and call \\verb|diary off| to save the resulting output. Then you need to upload files \\verb|lab_09_script.m|, \\verb|lab_09_function.m|, and \\verb|lab_09_output.txt| to Overleaf, and answer the corresponding questions in \\verb|body.tex|.\n", "meta": {"hexsha": "a715644cdcf2281b4c384ac96334cea95ac5e6bc", "size": 3732, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.09/exercise/body.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.09/exercise/body.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.09/exercise/body.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.1803278689, "max_line_length": 414, "alphanum_fraction": 0.5983386924, "num_tokens": 1116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.9416541634817872, "lm_q1q2_score": 0.8214495373681424}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Consider the following collection of points in $\\R^2$:\n  \\begin{equation*}\n    \\set{\n      \\begin{mymatrix}{r} 1 \\\\ -1 \\end{mymatrix},\n      \\begin{mymatrix}{r} -2 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 3 \\\\ -2 \\end{mymatrix},\n      \\begin{mymatrix}{r} 2 \\\\ -2 \\end{mymatrix},\n      \\begin{mymatrix}{r} -2 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 3 \\\\ -1 \\end{mymatrix},\n      \\begin{mymatrix}{r} -3 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 3 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ -2 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  Find the 1-dimensional subspace that best approximates this\n  collection of points. What is the total squared distance of the\n  points to the subspace? Sketch the subspace and the points.\n\\end{ex}\n\n\\begin{ex}\n  Consider the following collection of points in $\\R^3$:\n  \\begin{equation*}\n    \\set{\n      \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 9 \\end{mymatrix},\n      \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ -3 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 1 \\end{mymatrix}\n      \\begin{mymatrix}{r} 0 \\\\ 5 \\\\ -4 \\end{mymatrix},\n      \\begin{mymatrix}{r} 6 \\\\ -2 \\\\ 13 \\end{mymatrix},\n      \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 2 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 2 \\\\ 0 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 4 \\\\ 0 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 1 \\\\ -3 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 4 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  \\begin{enumerate}\n  \\item Find the 1-dimensional subspace that best approximates this\n    collection of points.\n  \\item Find the 2-dimensional subspace that best approximates this\n    collection of points.\n  \\item What is the 3-dimensional subspace that best approximates this\n    collection of points?\n  \\end{enumerate}\n  In each case, what is the total squared distance of the points to\n  the subspace?\n\\end{ex}\n\n\\begin{ex}\n  Find the principal components of the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{ccccccccc}\n      0 & 0 & 0 & 0 & -1 & 0 & 3 & 0 & 1 \\\\\n      0 & 1 & 0 & 0 & 2 & 3 & 0 & 2 & -1 \\\\\n      1 & -1 & -3 & 3 & -1 & 0 & 0 & -2 & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Compute the centroid of the following collection of points:\n  \\begin{equation*}\n    \\set{\n      \\begin{mymatrix}{r} 2 \\\\ -1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 4 \\\\ -3 \\end{mymatrix},\n      \\begin{mymatrix}{r} -4 \\\\ -4 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ -2 \\end{mymatrix},\n      \\begin{mymatrix}{r} -2 \\\\ -1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ -2 \\end{mymatrix},\n      \\begin{mymatrix}{r} -2 \\\\ -4 \\end{mymatrix},\n      \\begin{mymatrix}{r} 3 \\\\ -1 \\end{mymatrix},\n      \\begin{mymatrix}{r} -5 \\\\ -5 \\end{mymatrix}\n    }.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Consider the following collection of points in $\\R^2$:\n  \\begin{equation*}\n    \\set{\n      \\begin{mymatrix}{r} 4 \\\\ -3 \\end{mymatrix},\n      \\begin{mymatrix}{r} 10 \\\\ -9 \\end{mymatrix},\n      \\begin{mymatrix}{r} 4 \\\\ -7 \\end{mymatrix},\n      \\begin{mymatrix}{r} -2 \\\\ 3 \\end{mymatrix},\n      \\begin{mymatrix}{r} 10 \\\\ -3 \\end{mymatrix},\n      \\begin{mymatrix}{r} 4 \\\\ -3 \\end{mymatrix},\n      \\begin{mymatrix}{r} 5 \\\\ -3 \\end{mymatrix},\n      \\begin{mymatrix}{r} 4 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} -2 \\\\ -3 \\end{mymatrix},\n      \\begin{mymatrix}{r} 3 \\\\ -3 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  Compute the centroid, and then find the 1-dimensional affine\n  subspace that best approximates this collection of points. What is\n  the total squared distance of the points to the subspace?\n\\end{ex}\n\n\\begin{ex}\n  Consider the following collection of points in $\\R^3$:\n  \\begin{equation*}\\scriptstyle\n    \\set{\n      \\begin{mymatrix}{r} 0 \\\\ -2 \\\\ 2 \\end{mymatrix},\n      \\begin{mymatrix}{r} 6 \\\\ 2 \\\\ 2 \\end{mymatrix},\n      \\begin{mymatrix}{r} 2 \\\\ 2 \\\\ 6 \\end{mymatrix},\n      \\begin{mymatrix}{r} 3 \\\\ 2 \\\\ 2 \\end{mymatrix},\n      \\begin{mymatrix}{r} 3 \\\\ 0 \\\\ 5 \\end{mymatrix},\n      \\begin{mymatrix}{r} 5 \\\\ 0 \\\\ 2 \\end{mymatrix},\n      \\begin{mymatrix}{r} 4 \\\\ -2 \\\\ -2 \\end{mymatrix},\n      \\begin{mymatrix}{r} 5 \\\\ 0 \\\\ 2 \\end{mymatrix},\n      \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 2 \\end{mymatrix},\n      \\begin{mymatrix}{r} 3 \\\\ 0 \\\\ -1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 3 \\\\ 0 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 3 \\\\ 0 \\\\ 3 \\end{mymatrix},\n      \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 2 \\end{mymatrix},\n      \\begin{mymatrix}{r} 3 \\\\ -2 \\\\ 2 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  Find the 1- and 2-dimensional affine subspaces that best approximate\n  this collection of points. What is the total squared\n  distance of the points to each subspace?\n\\end{ex}\n", "meta": {"hexsha": "5c8fc2f80860ae46c0728ee4df7d953daa01747a", "size": 4868, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/InnerProductSpaces-Application-PrincipalComponentAnalysis.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/InnerProductSpaces-Application-PrincipalComponentAnalysis.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/InnerProductSpaces-Application-PrincipalComponentAnalysis.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 38.03125, "max_line_length": 70, "alphanum_fraction": 0.5879211175, "num_tokens": 1914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895028, "lm_q2_score": 0.8887587942290704, "lm_q1q2_score": 0.8213391677641357}}
{"text": "\\section{Bifurcation Diagrams as Tangent Fields}\n\\label{appendix:tangent-fields}\n\nLet each component of the vector function $\\rates$ in the model \\eqref{eq:model} implicitly define a surface embedded in $\\Reals^{N+1}$. Let's assume that the intersection of these $N$ surfaces exists and is not null or degenerate, then the steady states of \\eqref{eq:model} must be a set of one dimensional space curves in $z\\in\\Reals^{N+1}$ defined by\n\\begin{align}\n    \\rates(z) = 0\n\\end{align}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=5cm]{implicit-surfaces}\n\\caption{Two implicit surfaces $f_{\\theta}(z)=0$ and $g_{\\theta}(z)=0$ in $\\mathbb{R}^3$ intersecting to form a space curve which is tangent to field $\\tangent(z)$ and perpendicular to gradients $\\partial_{z}f_{\\theta}$ and $\\partial_{z}g_{\\theta}$}\n\\label{fig:implicit-surfaces}\n\\end{figure}\nAn expression for the field $\\tangent(z)$ tangent to the set of curves would allow us to take derivatives and integrals along the bifurcation curve. This is exactly what we need to do to evaluate our cost function \\ref{eq:loss}. Fortunately the tangent field can be constructed by ensuring it is perpendicular to the gradient $\\partial_z$ of each component of $\\rates$ as illustrated by an example two component system in Figure \\ref{fig:implicit-surfaces}. The tangent field $\\tangent(z)$ can be constructed perpendicular to all gradient vectors using the properties of the determinant \\cite{Goldman2005CurvatureSurfaces}\n\\begin{align}\n    \\tangent(z):=\n    \\label{eq:tangent-field}\n    \\left|\\begin{matrix}\n        \\hat{z} \\\\\n        \\,\\partial_{z}\\rates\\,\n    \\end{matrix}\\right|\n    \\qquad\\tangent : \\Reals^{N+1}\\rightarrow\\Reals^{N+1}\\\\\n    =\\sum_{i=1}^{N+1}\\hat{z}_{i}(-1)^{i+1} \\left|\\frac{\\partial \\rates}{\\partial(z\\setminus z_{i}) }\\right|\n\\end{align}\nwhere $\\hat{z}$ is a collection of unit basis vectors in the $\\Reals^{N+1}$ space and $\\partial_{z}\\rates$ is an $N\\times(N+1)$ rectangular Jacobian matrix of partial derivatives and $z\\setminus z_{i}$ denotes the $N$ dimensional vector $z$ with component $z_{i}$ removed. This construction ensures perpendicularity to any gradients of $\\rates$\n\\begin{align}\n    \\tangent(z)\\cdot\\partial_z f_{\\theta} =\n    \\left|\\begin{matrix}\n        \\partial_z f_{\\theta} \\\\\n        \\,\\partial_{z}\\rates\\,\n    \\end{matrix}\\right|\n    \\quad =0 \\quad\\forall f_{\\theta}\\in \\rates\n\\end{align}\nsince the determinant of any matrix with two identical rows or columns is zero. Note that the tangent field $\\tangent(z)$ is actually defined for all values of $z$ where adjacent field lines trace out other level sets where $\\rates(z)\\neq0$. Furthermore deformations with respect to $\\theta$ are always orthogonal to the tangent\n\\begin{align} % \\todo{numerically true. analytic proof?}\n    \\tangent(z)\\cdot\\frac{d\\tangent}{d\\theta}=0\n\\end{align}\n\\begin{figure}\n\\centering\n\\includegraphics[width=13cm]{determinant-field}\n\\caption{Left/Right : Determinant $\\Det$ and tangent field $\\tangent(z)$ for the saddle-node/pitchfork models for some set values of $\\theta$ revealing that $\\Det=0$ defines bifurcations}\n\\label{fig:determinant-field}\n\\end{figure}\nFigure \\ref{fig:determinant-field} shows how the bifurcation curve defined by $\\rates(z)=0$ picks out one of many level sets or traces in tangent field $\\tangent(z)$ for the saddle and pitchfork. The tangent field $\\tangent(z)$ can always be analytically evaluated by taking the determinant in \\eqref{eq:tangent-field}. We will proceed with calculations on $\\tangent(z)$ in the whole space $z$ and pick out a single trace by solving $\\rates(z)=0$ later. For our two models\n\\begin{align}\n    \\underset{\\mathrm{saddle-node\\,\\,model}}{\n    \\tangent(z)=\\hat{u}-(\\,3\\theta_2 u^2+\\theta_1\\,)\\,\\hat{p}}\n    \\qquad\\qquad\n    \\underset{\\mathrm{pitchfork\\,\\,model}}{\n    \\tangent(z)=u\\hat{u}-(\\,3\\theta_2 u^2+p\\,)\\,\\hat{p}}\n    \\label{eq:tangent-field-examples}\n\\end{align}\nFigure \\ref{fig:determinant-field} reveals that $\\Det=0$ is also a level set and that the intersection with level set $\\rates(z)=0$ defines the bifurcations at specific parameter $\\theta$. In this particular setting we can see that the tangent field $\\tangent(z)$ only folds when $\\Det=0$. Plotting the value of the determinant along $\\rates(z)=0$ from Figure \\ref{fig:determinant-field} would give rise to Figures \\ref{fig:minimal-models}. The directional derivative of the determinant $\\Det$ along the tangent field $\\tangent(z)$ is defined as\n\\begin{align}\n    \\frac{d}{ds}\\Det := \\hat{\\tangent}(z) \\cdot \\frac{\\partial}{\\partial z}\\Det \n\\end{align}\nwhere $\\hat{\\tangent}(z)$ is the unit tangent field.\n\n\\section{Bifurcation Measure Properties}\n\\label{appendix:conditions}\nConsider a vector $v(s)\\in\\Reals^N$ parametrised by $s\\in\\Reals$ that is tangent to an equilibrium manifold defined by $\\rates(u)=0$. The conditions for a non-degenerate static bifurcation at $s^*$ along such a tangent can be expressed in terms of an eigenvalue $\\lambda(s)$ of the state-space Jacobian crossing zero with a finite slope. A bifurcation exists at $s^*$ if\n\\begin{align}\n    \\frac{\\partial\\rates}{\\partial u}v(s)=\\lambda(s) \\,v(s)\n    \\quad\\exists\\lambda:\\quad\n    \\left.\\lambda(s)\\right|_{s=s^*}=0\n    \\qquad\n    \\left.\\frac{d\\lambda}{ds}\\right|_{s=s^*}\\neq 0\n    \\label{eq:conditions}\n\\end{align}\nThese conditions are necessary and sufficient for a non-degenerate static local breakdown of stability. For now we do not consider dynamic bifurcations involving limit cycles or imaginary parts of eigenvalues and restrict $\\lambda\\in\\Reals$. Cases where both $\\left.\\lambda(s)\\right|_{s=s^*}=0$ and $\\left.\\frac{d\\lambda}{ds}\\right|_{s=s^*}=0$ require investigation into higher order derivatives $\\frac{d^n\\lambda}{ds^n}$. These are the cases we refer to as \\emph{degenerate} and are not considered here.\n\nInstead of considering conditions on each eigenvalue individually it is possible to use the determinant of the state-space Jacobian to detect whether the conditions \\eqref{eq:conditions} are satisfied. The determinant can be expressed as the product of eigenvalues\n\\begin{equation}\n    \\Det=\\prod_{n=1}^N\\lambda_n(s)\n    \\label{eq:determinant}\n\\end{equation}\nApplying the product rule when differentiating yields\n\\begin{align}\n    \\frac{d}{ds}\\Det&=\n    \\sum_{n=1}^N\\frac{d\\lambda_n}{ds}\\prod_{n'\\neq n}\\lambda_{n'}(s)\\\\\n    &=\\Det\\sum_{n=1}^N\\frac{d\\lambda_n}{ds}\\lambda_{n}(s)^{-1}\n\\end{align}\nSubstituting this expression into measure \\eqref{eq:measure}\n\\begin{equation}\n    \\measure(s)=\n    \\left(1+\\left|\\sum_{n=1}^N\\frac{d\\lambda_n}{ds}\\lambda_{n}(s)^{-1}\\right|^{-1}\\right)^{-1}\n\\end{equation}\nWhich implies the following\n\\begin{equation}\n    \\exists\\lambda:\\quad\n    \\begin{cases}\n        \\,\\lambda(s)=0 \\quad\\frac{d\\lambda}{ds}\\neq 0\\\\\n        \\,\\lambda(s)\\neq0 \\quad\\frac{d\\lambda}{ds}\\rightarrow\\pm\\infty\n    \\end{cases}\n    \\implies\n    \\measure(s)=1\n    \\label{eq:measure-conditions}\n\\end{equation}\nIf there exists an eigenvalue that satisfies conditions \\eqref{eq:conditions} then the measure is equal to one. The measure also approaches one in cases where the rate of change of an eigenvalue with respect to a manifold $s$ location  diverges while not crossing zero. This gives rise to finite gradients in the eigenvalue term in regimes far away from any bifurcation.\n\n\\section{Leibniz Rule for Space Curves}\n\\label{appendix:leibniz-rule}\n\nSuppose there exists a one dimensional space curve $\\mathcal{C(\\theta)}$ embedded in $z\\in\\Reals^{N+1}$ whose geometry changes depending on input parameters $\\theta\\in\\Reals^M$. This curve could be open or closed and changes in $\\theta$ could change the curve topology as well. Let the function $\\gamma_{\\theta}:\\Reals\\rightarrow\\Reals^{N+1}$ be a parametrisation of the position vector along the curve within a fixed domain $s\\in\\mathcal{S}$. Note that the choice of parametrisation is arbitrary and our results should not depend on this choice. Furthermore, if we parametrise the curve $\\mathcal{C}(\\theta)$ with respect to a fixed domain $\\mathcal{S}$ the dependence on $\\theta$ is picked up by the parametrisation $\\gamma_{\\theta}(s)$. We can write a line integral of any scalar function $L_{\\theta}:\\Reals^{N+1}\\rightarrow\\Reals$ on the curve as\n\\begin{align}\n    L(\\theta):=\n    \\int_\\mathcal{C(\\theta)}\\! L_{\\theta}(z)\\,\\mathrm{d}z\n    =\\int_\\mathcal{S}\\! L_{\\theta}(z)\\left|\\frac{d\\gamma_{\\theta}}{ds}\\right|\\mathrm{d}s_{\\,\\,z=\\gamma_{\\theta}(s)}\n\\end{align}\nwhere $\\left|\\frac{d\\gamma_{\\theta}}{ds}\\right|$ is the magnitude of tangent vectors to the space curve and we remind ourselves that the integrand is evaluated at $z=\\gamma_{\\theta}(s)$. We would like to track how this integral changes with respect to $\\theta$. The total derivative with respect to $\\theta$ can be propagated into the integrand \\cite{Flanders1973DifferentiationSign} as long as we keep track of implicit dependencies\n\\begin{align}\n    \\frac{dL}{d\\theta} &=\\int_\\mathcal{S}\n    \\left|\\frac{d\\gamma_{\\theta}}{ds}\\right|\n    \\left(\n        \\frac{\\partial L}{\\partial\\theta}+\n        \\frac{\\partial L}{\\partial z}\\cdot\n        \\frac{dz}{d\\theta}\n    \\right)\n    +L_{\\theta}(z)\\frac{d}{d\\theta}\\left|\\frac{d\\gamma_{\\theta}}{ds}\\right|\n    \\mathrm{d}s_{\\,\\,z=\\gamma_{\\theta}(s)}\n\\end{align}\nHere we applied the total derivative rule in the first term due to the implicit dependence of $z$ on $\\theta$ through $z=\\gamma_{\\theta}(s)$. Applying the chain rule to the second term\n\\begin{align}\n    \\frac{d}{d\\theta}\\left|\\frac{d\\gamma_{\\theta}}{ds}\\right|=\n    \\left|\\frac{d\\gamma_{\\theta}}{ds}\\right|^{-1}\n    \\frac{d\\gamma_{\\theta}}{ds}\\cdot\\frac{d}{d\\theta}\n    \\left(\\frac{d\\gamma_{\\theta}}{ds}\\right)\n\\end{align}\nBy choosing an $s$ that has no implicit $\\theta$ dependence we can commute derivatives\n\\begin{align}\n    \\frac{d}{d\\theta}\\left(\\frac{d\\gamma_{\\theta}}{ds}\\right)\n    = \\frac{d}{ds}\\left(\\frac{d\\gamma_{\\theta}}{d\\theta}\\right)\n    \\quad\\Rightarrow\\quad\n    \\frac{d}{d\\theta}\\left|\\frac{d\\gamma_{\\theta}}{ds}\\right|=\n    \\left|\\frac{d\\gamma_{\\theta}}{ds}\\right|^{-1}\n    \\frac{d\\gamma_{\\theta}}{ds}\\cdot\\frac{d}{d s}\n    \\left(\\frac{d\\gamma_{\\theta}}{d\\theta}\\right)\n\\end{align}\nTo proceed we note that the unit tangent vector can be written as an evaluation of a tangent field $\\hat{T}_{\\theta}(z)$ defined in the whole domain $z\\in\\Reals^{N+1}$ along the parametric curve $z=\\gamma_{\\theta}(s)$. The unit tangent field may disagree with the tangent given by $\\frac{d\\gamma_{\\theta}}{ds}$ up to a sign\n\\begin{align}\n    \\left.\\hat{\\tangent}(z)\\right|_{z=\\gamma_{\\theta}(s)}=\n    \\pm\\left|\\frac{d\\gamma_{\\theta}}{ds}\\right|^{-1}\\frac{d\\gamma_{\\theta}}{d s}\n\\end{align}\nthis leads to\n\\begin{align}\n    \\frac{d}{d\\theta}\\left|\\frac{d\\gamma_{\\theta}}{ds}\\right|=\n    \\left|\\frac{d\\gamma_{\\theta}}{ds}\\right|\\left(\n   \\hat{\\tangent}(z)\\cdot\\frac{\\partial }{\\partial z}\\left(\\frac{d\\Gamma_{\\theta}}{d \\theta}\\right)\\cdot\n   \\hat{\\tangent}(z)\n    \\right)_{z=\\gamma_\\theta(s)}\n    \\label{eq:divergence-term}\n\\end{align}\nIt is possible to find the normal deformation of the implicit space curves due to changes in $\\theta$. This can be done by taking the total derivative of the implicit equation defining the level set\n\\begin{align}\n    \\frac{d\\rates(z)}{d\\theta}=\\frac{\\partial F}{\\partial\\theta}+\n    \\frac{\\partial F}{\\partial z}\\cdot\\frac{d z}{d \\theta}\n\\end{align}\nWe can rearrange for $\\frac{d z}{d \\theta}$ using the Moore-Penrose inverse of the rectangular Jacobian matrix $\\frac{\\partial F}{\\partial z}$ which appeared in equation \\eqref{eq:tangent-field}. Since the level set is defined by $\\rates(z)=0$ the total derivative along the level set $d\\rates(z)=0$ and we arrive at an expression for the deformation field \\cite{Jos2011OnSurface}\n\\begin{align}\n    \\frac{d z}{d \\theta} = - \\frac{\\partial F}{\\partial z}^\\top\n    \\left(\\,\n        \\frac{\\partial F}{\\partial z}\\,\\frac{\\partial F}{\\partial z}^\\top\n    \\right)^{-1}\n    \\frac{\\partial F}{\\partial\\theta}\n\\end{align}\nThe tangential component of the deformation field is not uniquely determined because there is no unique way of parametrising a surface. This is the subject of many computer graphics papers \\cite{Jos2011OnSurface,Tao2016Near-IsometricTracking,Fujisawa2013CalculationInvariance}. We are however not interested in the continuous propagation of a mesh - as is the subject of those papers. In fact we are looking for a deformation field that is orthogonal to the tangent vector $\\hat{\\tangent}(z) \\cdot\\frac{d z}{d\\theta} =0$ for the space curve, and therefore letting the tangential component of the deformation equal zero is a valid choice and we can it instead of the parametrised deformation\n\\begin{align}\n    \\frac{d \\gamma_{\\theta}}{d\\theta} \\rightarrow \\frac{d z}{d\\theta}\n\\end{align}\nTo summarise we now have the gradient of our line integral only in terms of the implicit function defining the integration region.\n\\begin{align}\n    \\frac{d L}{d\\theta} =\\int_{\\rates(z)=0}\n        \\frac{\\partial L}{\\partial\\theta}+\n        \\frac{\\partial L}{\\partial z}\\cdot\n        \\varphi_{\\theta}(z)\n    +L_{\\theta}(z)\\,\\,\n    \\hat{\\tangent}(z)\\cdot\\frac{\\partial \\varphi}{\\partial z}\\cdot\\hat{\\tangent}(z)\n    \\,\\mathrm{d}z\\qquad\\qquad\\\\\n    \\mathrm{where}\\quad\n    \\hat{\\tangent}(z):= \\frac{\\tangent(z)}{|\\tangent(z)|}\n    \\qquad\n    \\tangent(z):=\n    \\left|\\begin{matrix}\n        \\hat{z} \\\\\n        \\,\\partial_{z}\\rates\\,\n    \\end{matrix}\\right|\n    \\qquad\n    \\varphi_{\\theta}(z) :=\n- \\frac{\\partial F}{\\partial z}^\\top\n    \\left(\\,\n        \\frac{\\partial F}{\\partial z}\\,\\frac{\\partial F}{\\partial z}^\\top\n    \\right)^{-1}\n    \\frac{\\partial F}{\\partial\\theta}\n\\end{align}\nWe have settled on choosing normal deformations which we will call $\\varphi_\\theta(z)$. The above result can be seen a the generalised Leibniz rule \\cite{Flanders1973DifferentiationSign} for the case of line integration regions. The last integrand term can be seen as the divergence the vector field $\\varphi_\\theta(z)$ projected onto the one dimensional space curve.\n\n\\clearpage\n\n\\section{Application of Bifurcation Inference to a Complex Model}\n\\label{appendix:double-exclusive}\n\nTo demonstrate the wider reaching applicability of our method we optimise the \\emph{double exclusive reporter} \\cite{Grant2020InterpretationCircuit}, a synthetic gene circuit in \\emph{E. coli} that was designed to exhibit a cusp bifurcation. The circuit behaviour is observed by measuring a fluorescent protein whose expression is controlled by transcription factors (regulatory proteins) LacI $(L)$ and TetR $(T)$, whose expression is in turn controlled by externally controllable \\emph{input} signals $c_{6}$ and $c_{12}$. To apply the method, we consider one of the input signals be the control condition $c_{6}=p$, with the other packed together with the remaining 20 parameters into vector $\\theta$. Once the optima $\\theta^*$ have been obtained, we perform dimensionality reduction using \\texttt{GigaSOM.jl} \\cite{Kratochvil2020GigaSOM.jl:Datasets} so that the results can be visualised in a two dimensional embedding (Figure \\ref{fig:double-exclusive-optima:parameters}).\n\nThe embedding reveals four optimal parameter regions. We find that, as with the two-state model in the main text \\eqref{eq:two-state}, there are two qualitatively distinct regimes: mutual activation (region 1) and inhibition (regions 2-4). The mutual inhibition region can be further subdivided into three regions that are geometrically equivalent, but kinetically distinct: region 3 has swapped kinetic roles for regulatory proteins LacI and TetR compared to region 2, and region 4 has additional damped oscillations in the dynamics across the whole range of \\emph{input} $c_{6}$ (Figure \\ref{fig:double-exclusive-optima:models}). The two dimensional embedding of sampled optima $\\theta^*$ enables navigation the space of qualitative behaviours of the \\emph{double exclusive reporter} and organisation in terms of geometric and kinetic equivalence.\n\n\\begin{figure}[ht]\n\\centering\n\\setlength\\unitlength{1cm}\n{\\phantomsubcaption\\label{fig:double-exclusive-optima:parameters}}\n{\\phantomsubcaption\\label{fig:double-exclusive-optima:models}}\n\\includegraphics[width=13cm]{double-exclusive-optima}\n\\begin{picture}(0,0) \\put(-13,7){\\subref{fig:double-exclusive-optima:parameters}} \\end{picture}\n\\begin{picture}(0,0) \\put(-7,7){\\subref{fig:double-exclusive-optima:models}}\n\\end{picture}\n\\caption{Bifurcation inference for the \\emph{double exclusive reporter}. \\subref{fig:double-exclusive-optima:parameters}. Optimal parameter estimates $\\theta^*$ for the targets $\\targets=\\{1,2\\}$ (indicated by yellow lines in panel B) reveal four regions  with two geometrically different regimes: mutual activation (region 1) and mutual inhibition (regions 2-4). \\subref{fig:double-exclusive-optima:models}. Example bifurcation diagrams indicate that region 2 has swapped kinetics between $L$ and $T$ to region 3. Region 4 has models with non-zero imaginary parts to eigenvalues indicating damped oscillations (shown in light green).}\n\\label{fig:double-exclusive-optima}\n\\end{figure}\n\nThese results were obtained with a modification of the bifurcation measure \\eqref{eq:measure} to improve convergence rates. In parameter regimes where bifurcations are not present, according to conditions \\eqref{eq:measure-conditions}, maximising the measure $\\measure(s)$ can lead to a divergence in directional derivative $\\frac{d\\lambda}{ds}\\rightarrow\\pm\\infty$ rather than a creation of a bifurcation. To discourage this from happening we can flatten out the gradients in that regime by applying the $\\tanh$ non-linearity to the determinant. This leads to\n\\begin{align}\n    \\measure(s):=\n    \\left(1+\\left|\\frac{\\tanh\\Det}{\\frac{d}{ds}\\tanh\\Det}\\right|\\right)^{-1}\n    \\label{eq:measure-tanh}\n\\end{align}\n\n\\clearpage\n\\section{Extension for Hopf Bifurcations}\n\\label{appendix:hopf}\n\nIn order to detect bifurcations involving limit cycles, the measure must be extended to detect changes in the real part $\\Re\\mathrm{e}[\\lambda(s)]$ for any eigenvalue of the Jacobian. These conditions can no longer be compactly written in terms of the determinant. Instead, the measure can be defined as the sum of eigenvalue terms \n\\begin{align}\n    \\measure(s):=\\sum_{\\lambda(s)\\in\\frac{\\partial\\rates}{\\partial u}}\n    \\left(\\left|\\frac{d}{ds}\\log\\Re\\mathrm{e}[\\lambda(s)]\\right|^{-1}+1\\right)^{-1}\n    \\label{eq:hopf-measure}\n\\end{align}\n\nThe directional derivative of the logarithm diverges under two conditions: when eigenvalues vanish $\\lambda(s)=0$ and when the directional derivative $\\frac{d}{ds}\\Re\\mathrm{e}[\\lambda(s)]$ diverges. These properties are sufficient for detecting the onset of damped oscillations and emergence of limit cycles via Hopf bifurcation as shown in Figure \\ref{fig:hopf-measure}. Eigenvalues with negative real part which gain a finite imaginary part give rise to damped oscillations. At this onset we observe a discontinuity in the derivative $\\frac{d}{ds}\\Re\\mathrm{e}[\\lambda(s)]$ which is detected by equation \\eqref{eq:hopf-measure}. Once damped oscillations exist, flipping the stability of the stable fixed point gives rise to a limit cycle, which can be detected by inspecting $\\Re\\mathrm{e}[\\lambda(s)]$.\n\n\\begin{figure}[H]\n\\centering\n    \\includegraphics[width=60mm]{hopf-measure}\n    \\caption{Bifurcation measure $\\measure(s)$ and eigenvalues $\\lambda(s)$ along the arclength $s$ for two different bifurcation curves demonstrating how the measure detects non-zero imaginary parts $\\Im\\mathrm{m}[\\lambda]$ (onset of damped oscillations marked by circle) and sign changes in real parts $\\Re\\mathrm{e}[\\lambda]$ (Hopf bifurcations marked by stars)}\n    \\label{fig:hopf-measure}\n\\end{figure}\n\nIn principle it is possible to construct measures to detect a variety of bifurcations as long as the conditions can be expressed in terms of derivatives with respect to fixed-point manifold direction $s$. Measures can be used sequentially or in parallel to encourage optimisers to run through a sequence of bifurcations or place specific bifurcation types next to each other.\n", "meta": {"hexsha": "55cf2cb9e5568c37f79de50bbe37f96db1ec5c41", "size": 20012, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/appendix.tex", "max_stars_repo_name": "gszep/BifurcationFit.jl", "max_stars_repo_head_hexsha": "49b1efb0bd73377cfd4d9eea50552fef22f1c7e4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-06-11T14:34:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-04T16:43:31.000Z", "max_issues_repo_path": "docs/appendix.tex", "max_issues_repo_name": "gszep/FluxContinuation.jl", "max_issues_repo_head_hexsha": "49b1efb0bd73377cfd4d9eea50552fef22f1c7e4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-10-13T01:54:05.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-11T10:48:48.000Z", "max_forks_repo_path": "docs/appendix.tex", "max_forks_repo_name": "gszep/BifurcationInference.jl", "max_forks_repo_head_hexsha": "49b1efb0bd73377cfd4d9eea50552fef22f1c7e4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-10-13T19:48:12.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-22T11:04:01.000Z", "avg_line_length": 81.020242915, "max_line_length": 978, "alphanum_fraction": 0.733359984, "num_tokens": 5705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.8807970826714614, "lm_q1q2_score": 0.8213021541715658}}
{"text": "\n\\subsection{Cubes}\n\nVolume of a cube:\n\n\\(V=r^3\\)\n\nSurface area of a cube:\n\n\\(A=6r^2\\)\n\n", "meta": {"hexsha": "48ecf6359c0706512063cb9550da0706db6e1095", "size": 88, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/polygon3D/01-02-cube.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/polygon3D/01-02-cube.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/polygon3D/01-02-cube.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 7.3333333333, "max_line_length": 23, "alphanum_fraction": 0.6022727273, "num_tokens": 34, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9706877675527112, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.8211459778341541}}
{"text": "\\section{Problem Statement}\n\n\\subsection{Input}\n\n\\begin{enumerate}\n    \\item a directed acyclic graph $\\graph = \\tuple{\\vertices,\\edges}$;\n    \\item a multi-dimensional weight function $\\function{\\weight}{\\vertices}{\\weightCodomain}$, where $\\wn \\in \\natural$;\n        \\subitem We will usually write $\\weightE = \\apply{\\weight}{\\solutionE}$\n    \\item a maximum capacity of the knapsack $\\maximumWeight \\in \\weightCodomain$;\n\\end{enumerate}\n\nBesides that, one requires the input to satisfy the constraints below \\cite{bib:constrained-knapsack}, otherwise the problem would be trivial:\n\n\\begin{enumerate}\n    \\item $\\weightE \\leqslant \\maximumWeight$: the weight of each vertex must be smaller than the knapsack capacity;\n    \\item $\\Sum{\\solutionE \\in \\vertices}{}{\\weightE} \\geqslant \\maximumWeight$: the weight of all vertices combined must be greater than the knapsack capacity;\n\\end{enumerate}\n\n\\subsubsection{Partial Order}\n\n\\begin{defn}[Partial Order on Directed Acyclics Graph]\n    Given a directed acyclic graph $\\graph = \\tuple{\\vertices,\\edges}$, we define the set:\n    \\begin{equation}\n        \\partialLower\n        \\ =\n        \\SetOf\n            {\\tuple{\\solutionE, \\solutionE'}}\n            {\\mbox{there is a path from the first to the second}}\n    \\end{equation}\n    and so $\\partialLower$ is a partial order over the set $\\vertices$.\n\\end{defn}\n\n\\begin{figure}[ht!]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{images/directed acyclic graph.png}\n    \\caption{Example of a directed acyclic graph. The black dot indicates the root vertices. For this case, the induced partial order satisfy: $v5 \\partialLower v2$, $v7 \\partialLower v1$, $v14 \\partialLower v10$.}\n\\end{figure}\n\n\\subsection{Output}\n\nA subset $\\solution \\subseteq \\vertices$ of the vertices which satisfy:\n\n\\begin{equation}\n    \\label{eq:capacity-constraint}\n    \\Sum\n        {\\solutionE \\in \\solution}\n        {}\n        {\\weightE}\n    \\leqslant\n    \\maximumWeight\n\\end{equation}\n\n\\begin{equation}\n    \\label{eq:precedence-constraint}\n    \\forAll\n        {\\solutionE}\n        {\\ifThen\n            {\\solutionE \\in \\solution}\n            {\\forAll\n                {\\solutionEp}\n                {\\ifThen\n                    {\\solutionEp \\partialLower \\solutionE}\n                    {\\solutionEp \\in \\solution}\n                }\n            }\n        }\n\\end{equation}\n\n\\eqref{eq:capacity-constraint} is the maximum weight constraint, the total weight of all vertices in the solution set $\\solution$ must not be greater than the weight limit $\\maximumWeight$. It is called Capacity-Constraint.\n\n\\eqref{eq:precedence-constraint}\\footnote{It is a First-order logic expression \\cite{bib:logic}.} says that, if a $\\solutionE$ is included in the solution, then all the $\\solutionEp$ lower than it (in the sense of the partial order $\\partialLower$) must also be included. It is called Precedence-Constraint.\n\n\\subsection{Objective}\n\nFind $\\solution$ that maximizes $\\abs{\\solution}$. In other words: find the solution with the maximum number of vertices.\n", "meta": {"hexsha": "21670d7ebd414bded4ae519b4b26e24e179e1c46", "size": 3034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project/report/textual/problem_statement.tex", "max_stars_repo_name": "lucasguesserts/MO824A-combinatorial-optimization", "max_stars_repo_head_hexsha": "a88569e4496c0ed4f89a4e8bac7ab8f42f6cb7d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "project/report/textual/problem_statement.tex", "max_issues_repo_name": "lucasguesserts/MO824A-combinatorial-optimization", "max_issues_repo_head_hexsha": "a88569e4496c0ed4f89a4e8bac7ab8f42f6cb7d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project/report/textual/problem_statement.tex", "max_forks_repo_name": "lucasguesserts/MO824A-combinatorial-optimization", "max_forks_repo_head_hexsha": "a88569e4496c0ed4f89a4e8bac7ab8f42f6cb7d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.9210526316, "max_line_length": 307, "alphanum_fraction": 0.683586025, "num_tokens": 773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.8962513814471134, "lm_q1q2_score": 0.8210645128947986}}
{"text": "\\lab{K-Means Clustering}{K-Means Clustering}\n\\objective{Understand the basics of \\emph{k-means} clustering, and apply to the problem of clustering earthquake epicenters.}\n\n\\subsection*{Clustering}\nIn Lab \\ref{lab:pca}, we analyzed the iris dataset using PCA; we have reproduced the first two principal components of the iris data in Figure \\ref{fig:iris_data}.\nUpon inspection, a human can easily see that there are two very distinct groups of irises.\nCan we create an algorithm to identify these groups without human supervision?\nThis task is called \\emph{clustering}, an instance of \\emph{unsupervised learning}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{iris_pca.pdf}\n\\caption{The first two principal components of the iris dataset.}\n\\label{fig:iris_data}\n\\end{figure}\n\nThe objective of clustering is to find a partition of the data such that points in the same subset will be ``close'' according to some metric.\nThe metric used will likely depend on the data, but some obvious choices include Euclidean distance and angular distance.\nThroughout this lab we will use the metric $d(x,y) = \\|x-y\\|_2$, the Euclidean distance between $x$ and $y$.\n\nMore formally, suppose we have a collection of $\\mathbb{R}^K$-valued observations $X = \\{x_1,x_2,\\ldots,x_n\\}$.\nLet $N \\in \\mathbb{N}$ and let $\\mathcal{S}$ be the set of all $N$-partitions of $X$, where an $N$-partition is a partition with exactly $N$ nonempty elements.\nWe can represent a typical partition in $\\mathcal{S}$ as $S = \\{S_1,S_2,\\ldots,S_N\\}$, where\n\\[\nX = \\bigcup_{i=1}^N S_i\n\\]\nand\n\\[\n|S_i| > 0, \\qquad i=1,2,\\ldots,N.\n\\]\nWe seek the $N$-partition $S^*$ that minimizes the within-cluster sum of squares, i.e.\n\\[\nS^* = \\underset{S\\in\\mathcal{S}}{\\arg\\min} \\sum_{i=1}^N\\sum_{x_j\\in S_i}\\|x_j-\\mu_i\\|_2^2,\n\\]\nwhere $\\mu_i$ is the mean of the elements in $S_i$, i.e.\n\\[\n\\mu_i = \\frac{1}{|S_i|}\\sum_{x_j\\in S_i}x_j.\n\\]\n\n\\subsection*{The \\emph{K-Means} Method}\nFinding the global minimizing partition $S^*$ is generally intractable since the set of partitions can be very large indeed,\nbut the \\emph{k-means} algorithm is a heuristic approach that can often provide reasonably accurate results.\n\n\nWe begin by specifying an initial cluster mean $\\mu_i^{(1)}$ for each $i = 1, \\cdots, N$ (this can be done by random initialization, or according to some heuristic).\nFor each iteration, we adopt the following procedure.\nGiven a current set of cluster means $\\mu^{(t)}$, we find a partition $S^{(t)}$ of the observations such that\n\\begin{equation*}\nS_{i}^{(t)} = \\{x_j \\; : \\; \\|x_j - \\mu_{i}^{(t)}\\|_2^2 \\leq \\|x_j - \\mu_{l}^{(t)}\\|_2^2,\\,\\,\\,  l = 1, \\cdots, N\\}.\n\\end{equation*}\nWe then update our cluster means by computing for each $i = 1, \\cdots, N$.\nWe continue to iterate in this manner until the partition ceases to change.\n\n\n\nExamine Figure \\ref{fig:iris_clusterings}, which shows two different clusterings of the iris data produced by the \\emph{k-means} algorithm.\nNote that the quality of the clustering can depend heavily on the initial cluster means.\nWe can use the within-cluster sum of squares as a measure of the quality of a clustering (a lower sum of squares is better).\nWhere possible, it is advisable to run the clustering algorithm several times, each with a different initialization of the means,\nand keep the best clustering.\nNote also that it is possible to have very slow convergence.\nThus, when implementing the algorithm, it is a good idea to terminate after some specified maximum number of iterations.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{tabular}{cc}\n\t\\includegraphics[width=.49\\textwidth]{iris_means_1.pdf} &\n\t\\includegraphics[width=.49\\textwidth]{iris_means_2.pdf}\n\t\\end{tabular}\n\t\\caption{Two different K-Means clusterings for the iris dataset.\n            Notice that the clustering on the left predicts the flower species to a high degree of accuracy,\n            while the clustering on the right is less effective.}\n    \\label{fig:iris_clusterings}\n\\end{figure}\n\n\\begin{problem}\nImplement the \\emph{k-means} algorithm using the following function declaration.\n\n\\begin{lstlisting}\ndef kmeans(data,n_clusters,init='random',max_iter=300):\n    \"\"\"\n    Cluster a dataset using the k-means algorithm.\n\n    Parameters\n    ----------\n    data : ndarray of shape (n,k)\n        Each row is an observation.\n    n_clusters : int\n        The number of clusters.\n    init : string or ndarray of shape (n_clusters,k)\n        If init is the string 'random', then randomly initialize the cluster means.\n        Else, the initial cluster means are given by the rows of init.\n    max_iter : int\n        The maximum allowable number of iterations.\n\n    Returns\n    -------\n    means : ndarray of shape (n_cluster,k)\n        The final cluster means, given as the rows.\n    labels : ndarray of shape (n,)\n        The i-th entry is an integer in [0,n_clusters-1] indicating\n        which cluster the i-th row of data belongs to relative to\n        the rows of means.\n    measure : float\n        The within-cluster sum of squares quality measure.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\nTest your function on the first two principal components of the iris dataset.\nRun it 10 times, using a different random initialization of the means each time.\nRetain the clustering with the smallest within-cluster sum of squares.\nYour clustering should be similar to the first clustering in Figure \\ref{fig:iris_clusterings}.\n\\end{problem}\n\n\\subsection*{Detecting Active Earthquake Regions}\nSuppose we are interested in learning about which regions are prone to experience frequent earthquake activity.\nWe could make a map of all earthquakes over a given period of time and examine it ourselves, but this, as an unsupervised learning problem, can be solved using our k-means clustering tool.\n\nOur data is contained in 6 text files, each with earthquake data throughout the world covering a time period of one month, giving us data from January 2010 through June 2010.\nThese files contain a lot of information which isn't of interest to us at the present time; all we would like to extract from them is the location of each earthquake, which appears in characters $21$ through $33$ of each line.\nCharacters $21$ through $26$ contain the latitude of each epicenter, character $26$ denoting North or South, and characters $27$ through $33$ contain the longitude of each epicenter, character $33$ denoting East or West.\nWe need to divide each value by $1,000$ to represent these as degrees and decimals.\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{earthquakes.png}\n\t\\caption{Earthquake epicenters over a 6 month period.}\n\t\\label{fig:earthquakes}\n\\end{figure}\n\\begin{problem}\nLoad the earthquake data into a $n\\times 2$ array, where each row gives the longitude and latitude of an earthquake in degrees.\nMultiply South latitudes and West longitudes by $-1$.\nCreate a scatter plot of the resulting data. You should be able to see the outlines of some of the continents and tectonic plates (since these are often areas of significant seismic activity). Your plot should match Figure \\ref{fig:earthquakes}.\n\\end{problem}\n\nWe want to cluster this data into active earthquake regions.\nFor this task, we might think that we can regard any epicenter as a point in $\\mathbb{R}^{2}$ with coordinates being their latitude and longitude.\nThis, however, would be incorrect, because the earth is not flat. We must recognize that latitude and longitude are best viewed as a variation of spherical coordinates in $\\mathbb{R}^{3}$, and we should interpret them as such.\nSince our \\emph{k-means} algorithm is based on Euclidean distance, we need to transform our data into 3-dimensional Euclidean coordinates.\n\nA simple way to accomplish this transformation is to first transform the latitude and longitude values to spherical coordinates, and then to Euclidean coordinates.\nRecall that a spherical coordinate in $\\mathbb{R}^3$ is a triple $(r,\\theta,\\varphi)$, where $r$ is the distance from the origin, $\\theta$ is the radial angle in the $xy$-plane from the $x$-axis,\nand $\\varphi$ is the angle from the $z$-axis. In our earthquake data, the longitude is already the appropriate $\\theta$ value, and the $\\varphi$ value (in degrees) is simply $90^\\circ$ minus the latitude.\nFor simplicity, we can take $r=1$, since the earth is roughly a sphere.\nWe can then transform to Euclidean coordinates using the following relationships:\n\\begin{align*}\nr & = \\sqrt{x^{2} + y^{2} + z^{2}} & x & = r \\sin \\varphi \\cos \\theta \\\\\n\\varphi & = \\arccos \\frac{z}{r} & y & = r \\sin \\varphi \\sin \\theta \\\\\n\\theta & = \\arctan \\frac{y}{x} & z & = r \\cos \\varphi\n\\end{align*}\n\n\\begin{problem}\nTransform your earthquake data into three dimensional Euclidean coordinates.\nBe sure to consider if and when you need to transform your data from degrees to radians.\n\\end{problem}\n\nWe are now ready to cluster the earthquake data using the Euclidean coordinates.\nWe need to address one further issue, however.\nNotice that each earthquake data point has norm 1 in Euclidean coordinates, since it lies on the surface of a sphere of radius 1.\nWe also need to ensure that our cluster means have norm 1.\nOtherwise, the means can't be interpreted as locations on the surface of the earth.\nFurthermore, the \\emph{k-means} algorithm will struggle to find good clusters.\nA solution to this problem is to normalize the mean vectors at each iteration, so that they are always unit vectors.\nThus, we need to add optional functionality to our \\li{kmeans} function.\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{earthquake_clusters.png}\n\t\\caption{Earthquake epicenter clusters with $N = 15$.}\n\t\\label{fig:earthquakeclusters}\n\\end{figure}\n\n\\begin{problem}\nAdd a keyword argument \\li{normalize=False} to your \\li{kmeans} function, and add code to normalize the means at each iteration, should this argument be set to \\li{True}.\nUse your function to cluster the earthquake data into 15 clusters. Run this 10 times, keeping the best clustering.\nTransform the cluster means back to latitude and longitude coordinates (when calculating $\\theta$ using the inverse tangent, use \\li{numpy.arctan2} or \\li{math.arctan2},\nso that that correct quadrant is chosen).\nCreate a scatter plot showing each cluster mean, along with the earthquake epicenters color-coded according to their cluster. Your plot should resemble that of Figure \\ref{fig:earthquakeclusters}.\n\\end{problem}\n\nThough plotting our results in two dimensions gives us a good picture, we can see that this is not entirely accurate.  There are points that appear to be closer to a different cluster center than the one to which they belong.  This comes from viewing the results in only two dimensions.  When viewing in three dimensions, we can see more clearly the accuracy of our results.  \n\\begin{problem}\nAdd a keyword argument \\li{3d=False} to your \\li{kmeans} function, and add code to show the three-dimensional plot instead of the two-dimensional scatter plot should this argument be set to \\li{True}.  Maintain the same color-coding scheme as before.  Use \\li{mpl_toolkits.mplot3d.Axes3D} to make your plot.\n\\end{problem}\n\n\n\\subsection*{Spectral Clustering}\nWe now turn to another method for solving a clustering problem, namely that of Spectral Clustering.  As you can see in Figure ???, it can cluster data not just by its location on a graph, but can even separate shapes that overlap others into distinct clusters.  It does so by utilizing the spectral properties of a Laplacian matrix.  Different types of Laplacian matrices can be used.  In order to construct a Laplacian matrix, we first need to create a graph of vertices and edges from our data points.  This graph can be represented as a symmetric matrix $W$ where $w_{ij}$ represents the edge from $x_i$ to $x_j$.  In the simplest approach, we can set $w_{ij} = 1$ if there exists an edge and $w_{ij} = 0$ otherwise.  However, we are interested in the similarity of points, so we will weight the edges by using a \\emph{similarity measure}.  Points that are similar to one another are assigned a high similarity measure value, and dissimilar points a low value.  One possible measure is the \\emph{Gaussian similarity function}, which defines the similarity between distinct points $x_i$ and $x_j$ as\n\\begin{equation*}\ns(x_i,x_j) = e^{- \\frac{\\| x_i - x_j \\| ^2}{2 \\sigma ^2}}\n\\end{equation*}\nfor some set value $\\sigma$.\n\nNote that some similarity functions can yield extremely small values for dissimilar points.  We have several options for dealing with this possibility.  One is simply to set all values which are less than some $\\epsilon$ to be zero, entirely erasing the edge between these two points.  Another option is to keep only the $T$ largest-valued edges for each vertex.  Whichever method we choose to use, we will end up with a weighted \\emph{similarity matrix} $W$.  Using this we can find the diagonal \\emph{degree matrix} $D$, which gives the number of edges found at each vertex.  If we have the original fully-connected graph, then $D_{ii} = n-1$ for each $i$.  If we keep the $T$ highest-valued edges, $D_{ii} = T$ for each $i$.\n\nAs mentioned before, we may use different types of Laplacian matrices.  Three such possibilities are:\n\\begin{enumerate}\n    \\item The \\emph{unnormalized Laplacian}, $L = D - W$\n    \\item The \\emph{symmetric normalized Laplacian}, $L_{sym} = I - D^{-1/2}WD^{-1/2}$\n    \\item The \\emph{random walk normalized Laplacian}, $L_{rw} = I - D^{-1}W$.\n \\end{enumerate}\n\nGiven a similarity measure, which type of Laplacian to use, and the desired number of clusters $k$, we can now proceed with the Spectral Clustering algorithm as follows:\n\n\\begin{itemize}\n    \\item Compute $W$, $D$, and the appropriate Laplacian matrix.\n    \\item Compute the first $k$ eigenvectors $u_1, \\cdots , u_k$ of the Laplacian matrix.\n    \\item Set $U = [u_1, \\cdots , u_k]$, and if using $L_{sym}$ or $L_{rw}$ normalize $U$ so that each row is a unit vector in the Euclidean norm.\n    \\item Perform $k$-means clustering on the $n$ rows of $U$.\n    \\item The $n$ labels returned from your \\li{kmeans} function correspond to the label assignments for $x_1, \\cdots, x_n$.\n\\end{itemize}\n\nAs before, we need to run through our $k$-means function multiple times to find the best measure when we use random initialization.  Also, if you normalize the rows of $U$, then you will need to set the argument \\li{normalize = True}.\n\n\\begin{problem}\nImplement the Spectral Clustering Algorithm by calling your \\li{kmeans} function, using the following function declaration:\n\\begin{lstlisting}\ndef specClus(measure,Laplacian,args,arg1=None,kiters=10):\n    \"\"\"\n    Cluster a dataset using the k-means algorithm.\n\n    Parameters\n    ----------\n    measure : function\n        The function used to calculate the similarity measure.\n    Laplacian : int in {1,2,3}\n        Which Laplacian matrix to use. 1 corresponds to the unnormalized,\n        2 to the symmetric normalized, 3 to the random walk normalized.\n    args : tuple\n        The arguments as they were passed into your k-means function,\n        consisting of (data, n_clusters, init, max_iter, normalize). Note\n        that you will not pass 'data' into your k-means function.\n    arg1 : None, float, or int\n        If Laplacian==1, it should remain as None\n        If Laplacian==2, the cut-off value, epsilon.\n        If Laplacian==3, the number of edges to retain, T.\n    kiters : int\n        How many times to call your kmeans function to get the best\n        measure.\n\n    Returns\n    -------\n    labels : ndarray of shape (n,)\n        The i-th entry is an integer in [0,n_clusters-1] indicating\n        which cluster the i-th row of data belongs to.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\\end{problem}\n\nYou may use the following code to test your function.  This will generate random data for up to six concentric circles, and will show the results using both Spectral Clustering and $k$-means.  Note that it may take several tries to correctly classify the data, and will take a long time to run.  As arguments for this function, you need to pass in two lists giving the radii and number of points for each concentric circle, respectively, which Laplacian, and the additional argument \\li{arg1} as described previously. If using \\li{radii = [2.,6.]} and \\li{pts = [300,700]},  your results should be similar to Figure ???.\n\\begin{lstlisting}\ndef test_specClus(radii,pts,Laplacian,arg1=None,kiters=10):\n    n_clusters = len(radii)\n    def measure(xi,xj):\n        return np.exp(-(la.norm(xi-xj)**2))\n    \n    def circles(radii,pts):\n        ttl_pts = np.sum(pts)\n        positions = np.random.choice(range(ttl_pts),ttl_pts,replace=False)\n        data = np.empty((ttl_pts,2))\n        place = 0\n        for i in xrange(n_clusters):\n            randnessx = np.random.random(pts[i])-.5\n            randnessy = np.random.random(pts[i])-.5\n            data0 = 2*np.pi*np.random.random(pts[i])\n            datax = radii[i]*np.cos(data0)+randnessx\n            datay = radii[i]*np.sin(data0)+randnessy\n            data[positions[place:place+pts[i]],0] = datax\n            data[positions[place:place+pts[i]],1] = datay\n            place += pts[i]\n        return data\n    \n    data = circles(radii,pts)    \n    init = 'random'\n    max_iters = 300\n    normalize = False\n    if Laplacian != 1:\n        normalize = True\n    args = (data,n_clusters,init,max_iters,normalize)\n    \n    spec_clus_labels = specClust(measure,Laplacian,args,arg1,kiters)\n    kmeans_labels = kmeans(data,n_clusters,init,max_iters,normalize)[1]\n    colors = ['r.','g.','b.','k.','c.','y.']\n    \n    plt.subplot(121)\n    for i in xrange(n_clusters):\n        rel_data_pos = np.where(spec_clus_labels==i)[0]\n        plt.plot(data[rel_data_pos,0],data[rel_data_pos,1],colors[i])\n    plt.subplot(122)\n    for i in xrange(n_clusters):\n        rel_data_pos = np.where(kmeans_labels==i)[0]\n        plt.plot(data[rel_data_pos,0],data[rel_data_pos,1],colors[i])\n    plt.show()\n\\end{lstlisting}\n\n", "meta": {"hexsha": "a45fbb93696167b09f8bb8e8baddfae680352084", "size": 17969, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/KMeans/kmeans.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/KMeans/kmeans.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/KMeans/kmeans.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.7060810811, "max_line_length": 1101, "alphanum_fraction": 0.7308698314, "num_tokens": 4653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.9161096181702032, "lm_q1q2_score": 0.8210645032259613}}
{"text": "\\section{Nonlinear Support Vector Machines}\n\nWhen applying our SVC to \\emph{linearly separable} data in~\\eqref{eq:svc_max_wolfe_dual}, we have started by creating a matrix $Q$ from the dot product of our input variables:\n\n\\begin{equation} \\label{eq:svc_hessian}\n\tQ_{ij} = y_i y_j k(x_i,x_j)\n\\end{equation}\n\nor, a matrix $K$ from the dot product of our input variables in the SVR case~\\eqref{eq:svr_min_wolfe_dual}:\n\n\\begin{equation} \\label{eq:svr_hessian}\n\tK_{ij} = k(x_i,x_j)\n\\end{equation}\n\nwhere $k(x_i,x_j)$ is an example of a family of functions called \\emph{kernel functions}.\n\nFor any positive definite kernel function $k$ (a so called Mercer kernel), it is guaranteed that there exists a mapping $\\phi$ into a Hilbert space $\\mathcal{H}$, such that:\n\n\\begin{equation} \\label{eq:kernel_function}\n\tk(x_i,x_j) = \\langle \\phi(x_i), \\phi(x_j) \\rangle = \\phi(x_i)^T \\phi(x_j)\n\\end{equation}\n\nwhere $\\langle \\cdot, \\cdot \\rangle$ denotes the inner product in the Hilbert space and $\\phi(\\cdot)$ is the identity function.\n\nThe reason that this \\emph{kernel trick} is useful is that there are many classification/regression problems that are nonlinearly separable/regressable in the \\emph{input space}, which might be in a higher dimensionality \\emph{feature space} given a suitable mapping $x \\rightarrow \\phi(x)$.\n\n\\subsection{Polynomial kernel}\n\nThe \\emph{polynomial} kernel is defined as:\n\n\\begin{equation} \\label{eq:poly_kernel}\n\tk(x_i,x_j)=(\\gamma \\langle x_i, x_j\\rangle + r)^d\n\\end{equation}\n\nwhere $\\gamma$ define how far the influence of a single training example reaches (low values meaning \u2018far\u2019 and high values meaning \u2018close\u2019).\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{img/poly_dual_l1_svc_hyperplane}\n\t\t\\caption{Polynomial SVC hyperplane}\n\t\t\\label{fig:poly_dual_l1_svc_hyperplane}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\captionsetup{justification=centering}\n\t\t\\includegraphics[width=\\textwidth]{img/poly_dual_l1_svr_hyperplane}\n\t\t\\caption{Polynomial SVR hyperplane}\n\t\t\\label{fig:poly_dual_l1_svr_hyperplane}\n\t\\end{subfigure}\n\\caption{Polynomial SVM hyperplanes}\n\\end{figure}\n\n\\pagebreak\n\n\\subsection{Gaussian kernel}\n\nThe \\emph{gaussian} kernel is defined as:\n\n\\begin{equation} \\label{eq:gaussian_kernel1}\n\tk(x_i,x_j)=\\exp(-\\frac{\\|x_i-x_j\\|_2^2}{2\\sigma^2})\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation} \\label{eq:gaussian_kernel2}\n\tk(x_i,x_j)=\\exp(-\\gamma \\|x_i-x_j\\|_2^2)\n\\end{equation}\n\nwhere $\\displaystyle \\gamma=\\frac{1}{2\\sigma^2}$ define how far the influence of a single training example reaches (low values meaning \u2018far\u2019 and high values meaning \u2018close\u2019).\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{img/gaussian_dual_l1_svc_hyperplane}\n\t\t\\caption{Gaussian SVC hyperplane}\n\t\t\\label{fig:gaussian_dual_l1_svc_hyperplane}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\captionsetup{justification=centering}\n\t\t\\includegraphics[width=\\textwidth]{img/gaussian_dual_l1_svr_hyperplane}\n\t\t\\caption{Gaussian SVR hyperplane}\n\t\t\\label{fig:gaussian_dual_l1_svr_hyperplane}\n\t\\end{subfigure}\n\\caption{Gaussian SVM hyperplanes}\n\\end{figure}\n\n\\subsection{Laplacian kernel}\n\nThe \\emph{laplacian} kernel is defined as:\n\n\\begin{equation} \\label{eq:laplacian_kernel1}\n\tk(x_i,x_j)=\\exp(-\\frac{\\|x_i-x_j\\|_1}{2\\sigma^2})\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation} \\label{eq:laplacian_kernel2}\n\tk(x_i,x_j)=\\exp(-\\gamma \\|x_i-x_j\\|_1)\n\\end{equation}\n\nwhere $\\displaystyle \\gamma=\\frac{1}{2\\sigma^2}$ define how far the influence of a single training example reaches (low values meaning \u2018far\u2019 and high values meaning \u2018close\u2019).\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{img/laplacian_dual_l1_svc_hyperplane}\n\t\t\\caption{Laplacian SVC hyperplane}\n\t\t\\label{fig:laplacian_dual_l1_svc_hyperplane}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\captionsetup{justification=centering}\n\t\t\\includegraphics[width=\\textwidth]{img/laplacian_dual_l1_svr_hyperplane}\n\t\t\\caption{Laplacian SVR hyperplane}\n\t\t\\label{fig:laplacian_dual_l1_svr_hyperplane}\n\t\\end{subfigure}\n\\caption{Laplacian SVM hyperplanes}\n\\end{figure}", "meta": {"hexsha": "e5be322db6f4f15dfcb01867fdcd1e1625777998", "size": 4302, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebooks/optimization/tex/nonlinear_svm.tex", "max_stars_repo_name": "DonatoMeoli/NumericalOptimization", "max_stars_repo_head_hexsha": "e60144458026a6ddbe1612f92b838c342db572eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-22T09:17:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T18:23:56.000Z", "max_issues_repo_path": "notebooks/optimization/tex/nonlinear_svm.tex", "max_issues_repo_name": "DonatoMeoli/NumericalOptimization", "max_issues_repo_head_hexsha": "e60144458026a6ddbe1612f92b838c342db572eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-25T08:29:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-25T09:03:13.000Z", "max_forks_repo_path": "notebooks/optimization/tex/nonlinear_svm.tex", "max_forks_repo_name": "DonatoMeoli/NumericalOptimization", "max_forks_repo_head_hexsha": "e60144458026a6ddbe1612f92b838c342db572eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-10-10T13:38:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-13T20:23:37.000Z", "avg_line_length": 34.9756097561, "max_line_length": 291, "alphanum_fraction": 0.7617387262, "num_tokens": 1386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.8962513668985, "lm_q1q2_score": 0.8210644975139075}}
{"text": "\\section{Relative Growth Rates}\r\nIn many practical applications, like the run times of computer algorithms for example, we often want to know if a function grows slower, the same, or faster than another.\r\n\\begin{definition}\r\n\tIf\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x \\to \\infty}{\\frac{f(x)}{g(x)}} = \\infty \\Leftrightarrow \\lim_{x \\to \\infty}{\\frac{g(x)}{f(x)}} = 0,\r\n\t\\end{equation*}\r\n\tthen $f$  grows faster than $g$.\r\n\tIf\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x \\to \\infty}{\\frac{f(x)}{g(x)}} = c \\Leftrightarrow \\lim_{x \\to \\infty}{\\frac{g(x)}{f(x)}} = \\frac{1}{c}\r\n\t\\end{equation*}\r\n\tfor some non-zero constant $c$, then $f$ and $g$ grow at the same rate.\r\n\\end{definition}\r\n\r\n\\begin{example}\r\n\tCompare $e^x$ and $x^{100}$.\r\n\tDoes one grow faster than the other, or do they grow at the same rate?\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\t\t\\lim_{x\\to\\infty}{\\frac{e^x}{x^{100}}} &= \\lim_{x\\to\\infty}{\\frac{e^x}{100x^{99}}} \\\\\r\n\t\t&= \\vdots \\text{ (after many applications of L'H\\^{o}pital's Rule)} \\\\\r\n\t\t&= \\lim_{x\\to\\infty}{\\frac{e^x}{100!}}\r\n\t\t&= \\infty.\r\n\t\\end{align*}\r\n\t\r\n\tSo, $e^x$ grows faster than $x^{100}$.\r\n\tIn fact, any exponential $b^x$ grows faster than any polynomial, as long as $b > 1$.\r\n\\end{answer}\r\n\r\n\\subsection{Transitive Grow Rates}\r\nFor sufficiently large $x$, growth rates are transitive.\r\nThat is, if $f$ grows the same/faster/slower/ than $g$, and $g$ grows the same/slower/faster than $h$, then $f$ also grows the same/faster/slower than $h$.\r\n\r\n\\begin{example}\r\n\tShow that $f(x)=\\sqrt{x^2+5}$ and $g(x)=\\left(2\\sqrt{x}-1\\right)^2$ grow at the same rate.\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe'll show that both $f$ and $g$ grow at the same rate as $h(x)=x$.\r\n\tStarting with $f$ and $h$,\r\n\t\\begin{align*}\r\n\t\t\\lim_{x\\to\\infty}{\\frac{f(x)}{h(x)}} &= \\lim_{x\\to\\infty}{\\frac{\\sqrt{x^2+5}}{x}} \\\\\r\n\t\t&= \\lim_{x\\to\\infty}{\\sqrt{\\frac{x^2+5}{x^2}}} \\\\\r\n\t\t&= \\sqrt{\\lim_{x\\to\\infty}{\\frac{x^2+5}{x^2}}} \\text{ (by the Power Rule)} \\\\\r\n\t\t&= \\sqrt{1} \\\\\r\n\t\t&= 1.\r\n\t\\end{align*}\r\n\t\r\n\tSo, $f$ and $h$ grow at the same rate.\r\n\tMoving on to $g$ and $h$,\r\n\t\\begin{align*}\r\n\t\t\\lim_{x\\to\\infty}{\\frac{g(x)}{h(x)}} &= \\lim_{x\\to\\infty}{\\frac{\\left(2\\sqrt{x}-1\\right)^2}{x}} \\\\\r\n\t\t&= \\lim_{x\\to\\infty}{\\left(\\frac{2\\sqrt{x}-1}{\\sqrt{x}}\\right)^2} \\\\\r\n\t\t&= \\left(\\lim_{x\\to\\infty}{\\frac{2\\sqrt{x}-1}{\\sqrt{x}}}\\right)^2 \\text{ (by the Power Rule)} \\\\\r\n\t\t&= \\left(2\\right)^2 \\\\\r\n\t\t&= 4.\r\n\t\\end{align*}\r\n\t\r\n\tSo, $g$ and $h$ grow at the same rate.\r\n\tSince $f$ and $g$ both grow at the same rate as $h$, $f$ and $g$ must grow at the same rate as each other.\r\n\\end{answer}\r\n\r\n\\subsection{Growth Rate Hierarchy ($n^n$FEPL)}\r\nFor most of the common types of functions we see, we can establish families of functions and rank these families by their growth rates from fastest-growing to slowest-growing.\r\nIf two functions are in different families, we can be sure that one grows faster than the other.\r\nIf two functions are in the same family, we'll have to do more work to compare them.\r\nThese families are summarized by the acronym $n^n$FEPL\\footnote{You might recognize these families as a sort of Big-O family from computer science.}.\r\n\\begin{itemize}[align=left, leftmargin=0.66in]\r\n\t\\item[$\\textbf{n}^\\textbf{n}$] These are functions that have a variable both in the base and exponent.\r\n\t\\item[\\textbf{F}actorials] These are functions that have an $n!$ term.\r\n\t\\item[\\textbf{E}xponentials] These are functions that have a constant base and a variable exponent.\r\n\t\tNote that if the variable base if less than 1, the function actually gets smaller for larger $n$.\r\n\t\\item[\\textbf{P}olynomials] These are functions with a variable base and constant exponent.\r\n\t\tCertain polynomials can still grow faster than others.\r\n\t\tFor example, $x^2$ grows faster than $x$, which grows faster than $\\sqrt{x}$.\r\n\t\\item[\\textbf{L}ogarithms] These are functions that have a log of a polynomial.\r\n\\end{itemize}\r\n\r\nAlthough these rules are indeed true, don't just apply them blindly.\r\nYou should try to simplify a function first before figuring out to which family it belongs.\r\nFor example, although $\\ln{x^x}$ contains an $x^x$ and a $\\ln$, it's neither in the $n^n$ family nor in the logarithms family.\r\nIn fact, although this function is not a polynomial, it grows faster than $x$ but slower than $x^2$. \\\\\r\n\r\n\r\nA function belongs to the family of its fastest-growing positive term.\r\nNegative terms can either be ignored or used to simplify other terms.\r\nFor example, although $x^3 + e^x$ contains a polynomial $x^3$ term, for very large $x$, the $e^x$ term dominates the growth, meaning this function is part of the exponentials family.", "meta": {"hexsha": "09aca7c050f34524a6d7dc450daf62e9693a0341", "size": 4618, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/sequences_lhopital_improper/relative_growth_rates.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/sequences_lhopital_improper/relative_growth_rates.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/sequences_lhopital_improper/relative_growth_rates.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 52.4772727273, "max_line_length": 182, "alphanum_fraction": 0.6715028151, "num_tokens": 1528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223265, "lm_q2_score": 0.9304582583867416, "lm_q1q2_score": 0.8210623072809285}}
{"text": "\\subsection{The box product}\n\nIn this section, we explore another application of the cross product.\nRecall that we can use the cross product to find the the area of a\nparallelogram. As we will now show, we can also use the cross product\ntogether with the dot product to find the volume of a\nparallelepiped. We begin with a definition.\n\n\\begin{definition}{Parallelepiped}{parallelepiped}\n  The parallelepiped%\n  \\index{parallelepiped} determined by three vectors $\\vect{u}$,\n  $\\vect{v}$, and $\\vect{w}$ consists of the set of points of the form\n  \\begin{equation*}\n    r\\/\\vect{u}+s\\/\\vect{v}+t\\/\\vect{w},\n  \\end{equation*}\n  where $r,s,t$ are real numbers between $0$ and $1$, inclusive. The\n  parallelepiped is a $3$-dimensional body bounded by parallelograms\n  as shown in this picture.\n  \\begin{center}\n    \\begin{tikzpicture}[scale=1.2]\n      \\fill[blue!20] (0,0,0) -- (2,0,0) -- (3.5,1.5,0) -- (1.5,1.5,0) -- cycle;\n      \\fill[blue!35] (2,0,0) -- ++(1.5,1.5,0) -- ++(1,0,-1.5) -- ++(-1.5,-1.5,0) -- cycle;\n      \\fill[blue!12] (1.5,1.5,0) -- ++(2,0,0) -- ++(1,0,-1.5) -- ++(-2,0,0) -- cycle;\n      \\draw[blue,->](0,0,0) -- node [below, near end] {$\\vect{u}$} (2,0,0); %% u\n      \\draw[red,dashed,->](0,0,0) -- node [above left, near end] {$\\vect{v}$} (1,0,-1.5); %% v\n      \\draw[green!50!black,->](0,0,0) -- node [left, near end] {$\\vect{w}$} (1.5,1.5,0); %% w\n      \\draw[dashed](1,0,-1.5)--(3,0,-1.5);\n      \\draw[dashed](1,0,-1.5)--(2.5,1.5,-1.5);\n      \\draw(1.5,1.5,0)--(3.5,1.5,0)--(4.5,1.5,-1.5)--(2.5,1.5,-1.5)--(1.5,1.5,0);\n      \\draw(3.5,1.5,0)--(2,0,0)--(3,0,-1.5)--(4.5,1.5,-1.5);\n    \\end{tikzpicture}\n  \\end{center}\n\\end{definition}\n\nNotice that the base of the parallelepiped is the parallelogram\ndetermined by the vectors $\\vect{u}$ and $\\vect{v}$. Therefore, its\narea is equal to $\\norm{\\vect{u}\\times\\vect{v}}$. The height of the\nparallelepiped is $\\norm{\\vect{w}}\\cos\\theta$, where $\\theta$ is the\nangle between $\\vect{w}$ and $\\vect{u}\\times\\vect{v}$, as shown in\nthis picture.\n\\begin{center}\n  \\begin{tikzpicture}[scale=1]\n    \\filldraw[fill=green!20,draw=green!50!black] (0,0) -- (45:8mm) arc (45:90:8mm) -- cycle;\n    \\fill[blue!20] (0,0,0) -- (2,0,0) -- (3.5,1.5,0) -- (1.5,1.5,0) -- cycle;\n    \\fill[blue!35] (2,0,0) -- ++(1.5,1.5,0) -- ++(1,0,-1.5) -- ++(-1.5,-1.5,0) -- cycle;\n    \\fill[blue!12] (1.5,1.5,0) -- ++(2,0,0) -- ++(1,0,-1.5) -- ++(-2,0,0) -- cycle;\n    \\draw[blue,->](0,0,0) -- node [below, near end] {$\\vect{u}$} (2,0,0); %% u\n    \\draw[red,dashed,->](0,0,0) -- node [above left, near end] {$\\vect{v}$} (1,0,-1.5); %% v\n    \\draw[green!50!black,->](0,0,0) -- node [left, near end] {$\\vect{w}$} (1.5,1.5,0); %% w\n    \\draw[->](0,0,0) -- node[left] {$\\vect{u}\\times\\vect{v}$} (0,2.5,0);\n    \\draw[dashed](1,0,-1.5)--(3,0,-1.5);\n    \\draw[dashed](1,0,-1.5)--(2.5,1.5,-1.5);\n    \\draw(1.5,1.5,0)--(3.5,1.5,0)--(4.5,1.5,-1.5)--(2.5,1.5,-1.5)--(1.5,1.5,0);\n    \\draw(3.5,1.5,0)--(2,0,0)--(3,0,-1.5)--(4.5,1.5,-1.5);\n    \\node at (67.5:5mm){$\\theta$};\n  \\end{tikzpicture}\n\\end{center}\nThe volume of this parallelepiped is the area of the base times the\nheight which is just\n\\begin{equation*}\n  \\norm{\\vect{u}\\times \\vect{v}} \\norm{\\vect{w}} \\cos \\theta =\n  (\\vect{u}\\times\\vect{v}) \\dotprod \\vect{w}.\n\\end{equation*}\nThis expression is known as the \\textbf{box product}%\n\\index{box product} and is sometimes written as\n$\\boxprod{\\vect{u},\\vect{v},\\vect{w}}$.\n\nConsider what happens if you interchange $\\vect{v}$ with $\\vect{w}$ or\n$\\vect{u}$ with $\\vect{w}$.  Geometrically, we can see that this\nmerely introduces a minus sign. We find that the box product of three\nvectors equals the volume of the parallelepiped determined by the\nthree vectors if the three vectors form a right-handed system, and the\nnegative of the volume if the vectors form a left-handed system.\nWe summarize this in the following proposition:\n\n\\begin{proposition}{The box product}{box-product}\n  Let $\\vect{u}, \\vect{v}, \\vect{w}$ be three vectors in $\\R^3$ that\n  define a parallelepiped. The box product\n  $(\\vect{u}\\times\\vect{v}) \\dotprod \\vect{w}$ is equal to:\n  \\begin{itemize}\n  \\item The volume%\n    \\index{box product!volume of parallelepiped}%\n    \\index{volume!of parallelepiped}%\n    \\index{parallelepiped!volume} of the parallelepiped, if\n    $\\vect{u}, \\vect{v}, \\vect{w}$ form a right-handed system.\n  \\item The negative of the volume of the parallelepiped, if\n    $\\vect{u}, \\vect{v}, \\vect{w}$ form a left-handed system.\n  \\end{itemize}\n  In any case, the volume of the parallelepiped can be computed as the\n  absolute value of the box product, given by\n  $\\abs{(\\vect{u}\\times\\vect{v}) \\dotprod \\vect{w}}$.\n\\end{proposition}\n\n\\begin{example}{Volume of a parallelepiped}{parallelepiped-volume}\n  Find the volume of the parallelepiped determined by the vectors\n  \\begin{equation*}\n    \\vect{u}\n    =\n    \\begin{mymatrix}{r}\n      1 \\\\\n      2 \\\\\n      -5\n    \\end{mymatrix}, \\quad\n    \\vect{v}\n    =\n    \\begin{mymatrix}{r}\n      1 \\\\\n      3 \\\\\n      -6\n    \\end{mymatrix}, \\quad\n    \\vect{w}\n    =\n    \\begin{mymatrix}{r}\n      3 \\\\\n      2 \\\\\n      3\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  According to the above discussion, we can take the cross product of\n  any two of these vectors, and then the dot product with the third\n  vector. The result will be either plus or minus the desired\n  volume. Therefore we can obtain the volume by taking the absolute value.\n\n  We first compute the cross product of $\\vect{u}$ and $\\vect{v}$:\n  \\begin{equation*}\n    \\vect{u} \\times \\vect{v}\n    =\n    \\begin{mymatrix}{r}\n      1 \\\\\n      2 \\\\\n      -5\n    \\end{mymatrix}\n    \\times\n    \\begin{mymatrix}{r}\n      1 \\\\\n      3 \\\\\n      -6\n    \\end{mymatrix} \\\\\n    =\\begin{mymatrix}{c}\n      (2)(-6) - (-5)(3) \\\\\n      (-5)(1) - (1)(-6) \\\\\n      (1)(3)  - (2)(1)  \\\\\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{r}\n      3 \\\\\n      1 \\\\\n      1\n    \\end{mymatrix}\n  \\end{equation*}\n  Then we take the dot product of this vector with $\\vect{w}$:\n  \\begin{equation*}\n    (\\vect{u} \\times \\vect{v}) \\dotprod \\vect{w}\n    =\n    \\begin{mymatrix}{r}\n      3 \\\\\n      1 \\\\\n      1\n    \\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{r}\n      3 \\\\\n      2 \\\\\n      3\n    \\end{mymatrix} \\\\\n    = 9+2+3\n    = 14.\n  \\end{equation*}\n  Thus, the volume of the parallelepiped is 14 cubic units.\n\\end{solution}\n\nThe following is a consequence of Proposition~\\ref{prop:box-product}:\n\n\\begin{corollary}{Right- and left-handed systems of vectors}{box-product-right-handed}\n  The box product $(\\vect{u}\\times\\vect{v}) \\dotprod \\vect{w}$ is:\n  \\begin{itemize}\n  \\item Positive, if $\\vect{u},\\vect{v},\\vect{w}$ form a right-handed system.\n  \\item Negative, if $\\vect{u},\\vect{v},\\vect{w}$ form a left-handed system.\n  \\item Zero, if $\\vect{u},\\vect{v},\\vect{w}$ are coplanar.\n  \\end{itemize}\n\\end{corollary}\n\n\\begin{example}{Right- and left-handed systems of vectors}{box-product-right-handed}\n  Which of the following systems of vectors\n  $\\vect{u},\\vect{v},\\vect{w}$ is right-handed? Which one is left-handed?\n  Which one is coplanar?\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item $\\vect{u}=\\mat{1,2,0}^T$, $\\vect{v}=\\mat{0,0,1}^T$, $\\vect{w}=\\mat{1,-1,1}^T$.\n    \\item $\\vect{u}=\\mat{1,1,1}^T$, $\\vect{v}=\\mat{1,2,3}^T$, $\\vect{w}=\\mat{0,1,1}^T$.\n    \\item $\\vect{u}=\\mat{0,1,2}^T$, $\\vect{v}=\\mat{1,2,2}^T$, $\\vect{w}=\\mat{1,1,0}^T$.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{example}\n\n\\begin{solution}\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item We have\n      $\\boxprod{\\vect{u},\\vect{v},\\vect{w}} = (\\vect{u}\\times\\vect{v})\n      \\dotprod \\vect{w} = \\mat{2,-1,0}^T\\dotprod\\mat{1,-1,1}^T=3$, so\n      the box product is positive and the system of vectors\n      $\\vect{u},\\vect{v},\\vect{w}$ is right-handed.\n    \\item We have\n      $\\boxprod{\\vect{u},\\vect{v},\\vect{w}} = (\\vect{u}\\times\\vect{v})\n      \\dotprod \\vect{w} = \\mat{1,-2,1}^T\\dotprod\\mat{0,1,1}^T=-1$, so\n      the box product is negative and the system is left-handed.\n    \\item We have\n      $\\boxprod{\\vect{u},\\vect{v},\\vect{w}} = (\\vect{u}\\times\\vect{v})\n      \\dotprod \\vect{w} = \\mat{-2,2,-1}^T\\dotprod\\mat{1,1,0}^T=0$, so\n      the box product is zero and the vectors are coplanar.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{solution}\n\nWe finish this section with a law involving the dot product and the\ncross product. It represents a fundamental observation that comes\ndirectly from the geometric definition of the box product.\n\n\\begin{proposition}{Box product law}{order-of-product}\n  Let $\\vect{u}$, $\\vect{v}$, and $\\vect{w}$ be vectors. Then\n  $(\\vect{u}\\times\\vect{v}) \\dotprod \\vect{w}=\\vect{u}\\dotprod\n  (\\vect{v}\\times \\vect{w})$.\n\\end{proposition}\n\n\\begin{proof}\n  This follows from observing that both\n  $(\\vect{u}\\times \\vect{v}) \\dotprod \\vect{w}$ and\n  $\\vect{u}\\dotprod (\\vect{v}\\times \\vect{w})$ compute the same\n  box product, i.e., they either both give the volume of the\n  parallelepiped or they both give the negative of the volume.\n\n  Alternatively, we can calculate each product explicitly:\n  \\begin{eqnarray*}\n    (\\vect{u}\\times \\vect{v}) \\dotprod \\vect{w}\n    &=&\n        u_2v_3w_1 - u_3v_2w_1\n        + u_3v_1w_2 - u_1v_3w_2\n        + u_1v_2w_3 - u_2v_1w_3, \\\\\n    \\vect{u}\\dotprod (\\vect{v}\\times \\vect{w})\n    &=&\n        u_2v_3w_1 - u_3v_2w_1\n        + u_3v_1w_2 - u_1v_3w_2\n        + u_1v_2w_3 - u_2v_1w_3.\n  \\end{eqnarray*}\n  In Chapter~\\ref{cha:determinants}, you will learn that these\n  expressions are a special case of a determinant.\n\\end{proof}\n\n", "meta": {"hexsha": "70ae97cabfd10fa838beff5a095d30d98a024670", "size": 9549, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-CrossProduct-BoxProduct.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Vectors-CrossProduct-BoxProduct.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Vectors-CrossProduct-BoxProduct.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 37.743083004, "max_line_length": 94, "alphanum_fraction": 0.6095926275, "num_tokens": 3704, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.9219218289556671, "lm_q1q2_score": 0.8207816812550914}}
{"text": "%\\section*{Appendix II: Zeros and Poles}\n%\nThe zeros and poles of a 2nd order low-shelving filter are\n\\begin{align}\ns_{0} = \\omega_\\mathrm{c} \\:g_\\mathrm{B}^{\\pm\\frac{1}{4}} \\: \\e^{\\im\\alpha}\\qquad\ns_{\\infty} = \\omega_\\mathrm{c} \\: g_\\mathrm{B}^{\\mp\\frac{1}{4}} \\: \\e^{\\im\\alpha},\n\\end{align}\nand the respective complex conjugates $s_{0}^{\\ast}$ and $s_{\\infty}^{\\ast}$.\nThe sign in the exponents is again determined\nby the shelving level $G_\\mathrm{B}$.\nThe polar angle $\\alpha$ in the complex $s$-plane (Laplace domain)\nrelates to\n\\begin{align}\nQ = \\frac{-1}{2\\cos\\alpha}.\n\\end{align}\nFor stable and causal filters,\nthe poles must be in the left-half $s$-plane $\\Re(s_{\\infty}) < 0$,\ntherefore $\\frac{\\pi}{2} < \\alpha < \\frac{3\\pi}{2}$.\nThe corresponding $Q$-factor is always positive\nand varies within $[\\frac{1}{2}, \\infty)$.\nThis paper mainly considers Butterworth \\cite{Ballou2008} $Q=\\frac{1}{\\sqrt{2}}$\nwhich leads to $\\alpha=\\frac{3}{4} \\pi$\nas illustrated in Fig.~\\ref{fig:pzmap}.\nIf $Q=\\frac{1}{2}$, i.e. $\\alpha=\\pi$,\nthe poles and zeros lie on the real axis,\nthus double real poles $s_{0} = s_{0}^{\\ast}$ and\n$s_{\\infty} = s_{\\infty}^{\\ast}$ are obtained.\n%\nIn this case the 2nd order frequency\nresponse is identical to that of the 1st order shelving filter, although\nobtained by different pole/zero-configurations.\n%\nThus, it is sufficient to discuss the present filter design based on\n2nd order filters\n%\n\\NewL In the case of high-shelving filters, the poles and zeros are exchanged. %,\n%\\begin{align}\n%s_{0} &= \\omega_{c,\\mu} \\: g_\\mathrm{B}^{\\mp\\frac{1}{4}} \\: e^{i\\alpha}\\\\\n%s_{\\infty} &= \\omega_{c,\\mu} \\: g_\\mathrm{B}^{\\pm\\frac{1}{4}} \\: e^{i\\alpha}.\n%\\end{align}\nNotice that a high-shelving filter with a shelving gain $\\pm g_\\mathrm{B}$\nhas the same poles and zeros as the low-shelving filter with $\\mp g_\\mathrm{B}$.\nThe system functions only differ by a scaling factor of $\\pm g_\\mathrm{B}$\ndue to the leading coefficients $b_{2}$ and $a_{2}$.\n", "meta": {"hexsha": "1a78f84eea695783c678a36c203b836fa5f3b661", "size": 1968, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/poles-and-zeros.tex", "max_stars_repo_name": "spatialaudio/aes148-shelving-filter", "max_stars_repo_head_hexsha": "a11de97d6be79c23ffc55084ca95d9da15f3e3eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-06-04T12:28:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T12:35:54.000Z", "max_issues_repo_path": "paper/poles-and-zeros.tex", "max_issues_repo_name": "spatialaudio/aes148-shelving-filter", "max_issues_repo_head_hexsha": "a11de97d6be79c23ffc55084ca95d9da15f3e3eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/poles-and-zeros.tex", "max_forks_repo_name": "spatialaudio/aes148-shelving-filter", "max_forks_repo_head_hexsha": "a11de97d6be79c23ffc55084ca95d9da15f3e3eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-18T06:19:37.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-18T06:19:37.000Z", "avg_line_length": 43.7333333333, "max_line_length": 82, "alphanum_fraction": 0.6844512195, "num_tokens": 685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.8840392695254319, "lm_q1q2_score": 0.8207498378640202}}
{"text": "\\subsection{Planes}\r\n\\noindent\r\nA plane can also be formed using a point in the plane, $P$, and a vector perpendicular to the plane, $\\vec{n}$. All vectors $\\langle x,y,z \\rangle$ that originate from $P$ and remain in the plane must be perpendicular to $\\vec{n}$, so their dot product with $\\vec{n}$ would be 0. So, the point-normal form of a plane is\\footnote{Note: Conventionally, $\\vec{n}$ is a unit vector, $\\hat{n}$.}\r\n\\begin{equation*}\r\n\t\\vec{n}\\cdot\\left(\\langle x,y,z \\rangle - \\vec{P}\\right) = 0\r\n\\end{equation*}\r\n\r\n\\begin{figure}[h]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.5]{Images/vectorValuedFunctions/PlaneNormalVector}\r\n\\end{figure}\r\n\r\n\\noindent\r\nOne can also construct a plane from 3 non-collinear points in the plane. One can still take advantage of point-normal form here by choosing 1 point to be $P_0$ and drawing vectors from this point to the two other points. The cross product of these two vectors is $\\vec{n}$.\r\n\\begin{equation*}\r\n\t\\left(\\left(\\vec{P_1} - \\vec{P_0}\\right) \\times \\left(\\vec{P_2} - \\vec{P_0}\\right)\\right) \\cdot \\left(\\langle x,y,z \\rangle - \\vec{P_0}\\right) = 0\r\n\\end{equation*}\r\nwhere $P_0$, $P_1$, and $P_2$ are the three points in the plane.\\\\\r\n\r\n\\noindent\r\nOne can also construct a plane from a point in the plane, $P_0$, and a line in the plane, $\\vec{r}(t) = \\vec{P_1} + t\\vec{v}$, that doesn't pass through $P_0$. One can get this setup into point-normal form by choosing a an output of $\\vec{r}(t)$, like $\\vec{P_1}$, and constructing a vector that points from $\\vec{P_1}$ to $\\vec{P_0}$, $\\vec{P_1}-\\vec{P_0}$, and crossing this with $\\vec{v}$ to find $\\vec{n}$.\r\n\\begin{equation*}\r\n\t\\left(\\vec{v} \\times \\left(\\vec{P_1} - \\vec{P_0}\\right)\\right) \\cdot \\left(\\langle x,y,z \\rangle - \\vec{P_0}\\right) = 0\t\r\n\\end{equation*}\r\n\r\n\\noindent\r\nOne can also construct a plane from two intersecting lines, $\\vec{r_1}(t) = \\vec{P_0} + t\\vec{v_1}$ and $\\vec{r_2}(t) = \\vec{P_0} + t\\vec{v_2}$, where $P_0$ is where the two lines intersect. One can cross $\\vec{v_1}$ with $\\vec{v_2}$ to get the normal vector.\r\n\\begin{equation*}\r\n\t\\left(\\vec{v_1} \\times \\vec{v_2}\\right) \\cdot \\left(\\langle x,y,z \\rangle - \\vec{P-0}\\right) = 0\r\n\\end{equation*}", "meta": {"hexsha": "a72ac8c4a440a25e6b529401d990069edc971a0c", "size": 2181, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/planes.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/vectorValuedFunctions/planes.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/vectorValuedFunctions/planes.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 72.7, "max_line_length": 411, "alphanum_fraction": 0.6804218249, "num_tokens": 761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.9086179068309441, "lm_q1q2_score": 0.8207492889823498}}
{"text": "\\chapter{0411notes}\nIterative methods for solving:\n\\begin{enumerate}\n\\item \\begin{equation}\n\\min_{\\theta} f(\\theta) \n \\end{equation}\n\\item \\begin{equation}Au=g \\end{equation}\n\\end{enumerate}\n\nWe have dynamic system approach:\n(1) Optimization:\n\\begin{equation}\\theta^*\\in \\arg\\min_{\\theta} f(\\theta)\\to \\nabla f(\\theta^*)=0 \\end{equation}\n\\begin{equation}\\frac{d\\theta}{dt}=-\\nabla f(\\theta(t)) \\end{equation}\nBy Euler's method,\n\\begin{equation}\\frac{\\theta^{i+1}-\\theta^i}{\\eta}=-\\nabla f(\\theta^i) \\end{equation}\n\\begin{equation}\\theta^{i+1}=\\theta^i-\\eta\\nabla f(\\theta^i) \\end{equation}\n(2) \\begin{align}\nAu&=g  \\\\\\notag\nu&=u(t) \\\\\\notag\nu_t&=g-Au\\\\\\notag\nu^*&=\\lim_{t\\to \\infty}u(t)\\\\\\notag\ng-Au^*&=0\n\\end{align}\n\nMoreover,\n\\begin{equation}Au=g \\Leftrightarrow B(Au-g)=0, \\end{equation} where $B$ is nonsingular. \nA simple choice for $B$ is $B=D^{-1}$, where $D=\\diag(A)$.\n\nFor Euler's method,\n\\begin{equation}\\frac{u^{i+1}-u^i}{\\eta}=B(g-Au^i)\\equiv r_i \\end{equation}\n\\begin{equation} u^{i+1}=u^i+\\eta r_i. \\end{equation}\n\nWhy do we consider the residual?\nFor $Au=g$, we want to know whether $u^i \\to u^{i+1}$.\nConsider $Ae=r=g-Au^i$, we have the update $u^{i+1}=u^i+e$.\nAfter solving $Ae=r$ 'approximately', say \n\\begin{equation} \\hat{e}=Br, B\\approx A^{-1}. \\end{equation} \nWe have \n\\begin{equation} u^{i+1}=u^i+\\hat{e}=u^i+B(g-Au^i) \\end{equation}\n\nApply the numerical ODE methods.\n(1) Apply the machine learning to Euler's method.\nFor $\\min_{\\theta} f(\\theta)$, the explicit Euler's method is\n\\begin{equation} \\theta^{i+1}=\\theta^i-\\eta_i\\nabla f(\\theta^i). \\end{equation}\nThe implicit Euler's method is\n\\begin{equation} \\theta^{i+1}=\\theta^i-\\eta_i\\nabla f(\\theta^{i+1}). \\end{equation}\n(2) Multistep method.\n\\begin{equation} u^{i+1}=u^i+\\eta_i r_i+\\eta_{i-1} r_{i-1}+...+\\eta_0 r_0). \\end{equation}\nThen we can apply the explicit Euler's method to ResNet and the multi-step ODE solvers to the Dense-Net.\nThere are some examples,\n\\begin{enumerate}\n\\item LeNet\n\\item AlexNet\n\\item ResNet\n\\item DenseNet\n\\item MgNet\n\\end{enumerate}\n\n", "meta": {"hexsha": "95b52e7afa14b76276678ee4fd3ec8341c447f03", "size": 2042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/jianhong.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/jianhong.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/jianhong.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.6101694915, "max_line_length": 104, "alphanum_fraction": 0.6821743389, "num_tokens": 800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474220263197, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.8206757866661195}}
{"text": "%\n% Chapter 2.8\n%\n\n\\section*{2.8 Related Rates}\n\n\\subsubsection*{Example}\n\nAir is being pumped into a spherical balloon so that its volume increases at a rate of 100 cm\\(^3\\)/s. How fast is the radius of the balloon increasing when the diameter is 50 cm?\n\n\\subsubsection*{Solution}\n\nIdentify given information and the unknown value.\n$$ \\frac{dV}{dt} = 100 \\text{ cm}^3/\\text{s} $$\n$$ \\frac{dr}{dt} =\\text{? when } r = 25 \\text{ cm} $$\nRelate \\(V\\) and \\(r\\) by a formula.\n$$ V=\\frac{4}{3} \\pi r^3 $$\nDifferentiate both sides of the equation with respect to \\(t\\).\n$$ \\frac{dV}{dt}=\\frac{dV}{dr}\\frac{dr}{dt}=4 \\pi r^2 \\frac{dr}{dt} $$\nSolve for the unknown value.\n$$ \\frac{dr}{dt} = \\frac{1}{4 \\pi r^2} \\frac{dV}{dt} $$\nIf we put \\(r=25\\) and \\(\\frac{dV}{dt}=100\\) in the equation, we get\n$$ \\frac{dr}{dt} = \\frac{1}{4 \\pi {(25)}^2}100=\\frac{1}{25 \\pi} \\text{ cm/s} $$ \n", "meta": {"hexsha": "c6d27661ed9e2c13d6b1beb7d4090a04968a7d00", "size": 870, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2-8.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/2-8.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/2-8.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.25, "max_line_length": 179, "alphanum_fraction": 0.6275862069, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341975270266, "lm_q2_score": 0.8577681049901036, "lm_q1q2_score": 0.820570302781486}}
{"text": "\n\\subsection{Characteristic of a ring}\n\nThe characteristic of a ring is the number of times the multiplicative identity must be added to get the additive identity.\n\nIf this never happens, the characteristic is \\(0\\).\n\n\\subsubsection{Example}\n\nThe integer mod \\(2\\) ring, the characteristic is \\(2\\).\n\n", "meta": {"hexsha": "2ac60f24708943287649627a26646acedf13b795", "size": 301, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/rings/04-01-ringCharacteristic.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/rings/04-01-ringCharacteristic.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/rings/04-01-ringCharacteristic.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0833333333, "max_line_length": 123, "alphanum_fraction": 0.7607973422, "num_tokens": 65, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996142, "lm_q2_score": 0.8705972633721708, "lm_q1q2_score": 0.8205437721862617}}
{"text": "\\chapter{Week 1: The vector}\n\n\\section{What is a vector?}\nA vector is an array of $d$ numbers, and also can be thought as functions that maps from $\\{0, 1, \\ldots, d-1\\}$ to $\\fF$ with $\\fF^{d}$ as the notation.\n\nA vector most of whose values are zero is called a \\textsl{sparse} vector. If no more than $k$ of the entries are nonzero, we say the vector is $k$-sparse. A $k$-sparce vector can be represented using space proportional to $k$.\n\n\\section{Vector addition and scalar-vector multiplication}\n\\begin{definition}[Vector addition]\n  \\begin{equation*}\n    [u_1, u_2, \\ldots, u_n] + [v_1, v_2, \\ldots, v_n] = [u_1+v_1, u_2+v_2, \\ldots, u_n+v_n]\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}[Zero vector]\n  The $D$-vector whose entries are all zero is the zero vector, written $\\vzero_D$ or just $\\vzero$.\n  \\begin{equation*}\n    \\vv + \\vzero = \\vv\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}[Associativity]\n  \\begin{equation*}\n    (\\vx + \\vy) + \\vz = \\vx + (\\vy + \\vz)\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}[Commutativity]\n  \\begin{equation*}\n    \\vx + \\vy = \\vy + \\vx\n  \\end{equation*}\n\\end{definition}\n\nFor vectors, we refer to field elements as scalars, we use them to scale vectors: $\\alpha\\vv$. Greek letters (e.g. $\\alpha,\\beta,\\gamma$) denote scalars.\n\n\\begin{definition}\n  Multiplying a vector $\\vv$ by a scalar $\\alpha$ is defined as multiplying each entry of $\\vv$ by $\\alpha$.\n  \\begin{equation*}\n    \\alpha [\\vv_1, \\ldots, \\vv_n] = [\\alpha\\vv_1, \\ldots, \\alpha\\vv_n]\n  \\end{equation*}\n\\end{definition}\n\nThe set of points $\\{ \\alpha\\vv : \\alpha\\in\\R \\}$ forms the line through the origin and $\\vv$.\n\nAn expression of the form $\\alpha\\vu + \\beta\\vv$ where $0 \\le \\alpha \\le 1, 0 \\le \\beta \\le 1$, and $\\alpha + \\beta = 1$ is called a \\emph{convex combination} of $\\vu$ and $\\vv$. An expression of the form $\\alpha\\vu + \\beta\\vv$ where $\\alpha+\\beta=1$ is called and \\emph{affine combination} of $\\vu$ and $\\vv$.\n\n% ================================================================\n\n\\section{Dot-product}\n\\begin{definition}[Dot-product of two $D$-vectors]\n  Dot-product of two $D$-vectors is the sum of product of corresponding entries:\n  \\begin{equation*}\n    \\vu \\cdot \\vv = \\sum_{k\\in\\{1, \\ldots, D\\}} \\vu_k \\vv_k\n  \\end{equation*}\n\\end{definition}\n\n\\subsection{Linear equations}\n\\begin{definition}\n  A linear equation is an equation of the form\n  \\begin{equation*}\n    \\va \\cdot \\vx = \\beta\n  \\end{equation*}\n  where $\\va$ is a vector, $\\beta$ is a scalar, and $\\vx$ is a vector of variables.\n\\end{definition}\n\nAlgebraic properties of dot-product:\n\\begin{itemize}\n\\item Commutativity $\\vv \\cdot \\vx = \\vx \\cdot \\vv$\n\\item Homogeneity $(\\alpha\\vu)\\cdot\\vv = \\alpha(\\vu\\cdot\\vv)$\n\\item Distributive law $(\\vv_1 + \\vv_2)\\cdot\\vx = \\vv_1\\cdot\\vx + \\vv_2\\cdot\\vx$\n\\end{itemize}\n", "meta": {"hexsha": "183f0dcdcb2f3030314a92b3d179834e6e4068d7", "size": 2825, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/week1.tex", "max_stars_repo_name": "aanzolaavila/coding-the-matrix-notes", "max_stars_repo_head_hexsha": "b4c0426ed1f1d0aff19a945d92880be0e9a5f69e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/week1.tex", "max_issues_repo_name": "aanzolaavila/coding-the-matrix-notes", "max_issues_repo_head_hexsha": "b4c0426ed1f1d0aff19a945d92880be0e9a5f69e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapters/week1.tex", "max_forks_repo_name": "aanzolaavila/coding-the-matrix-notes", "max_forks_repo_head_hexsha": "b4c0426ed1f1d0aff19a945d92880be0e9a5f69e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.2361111111, "max_line_length": 310, "alphanum_fraction": 0.6587610619, "num_tokens": 946, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.8856314632529871, "lm_q1q2_score": 0.8203637208698072}}
{"text": "\\section{Sequences}\r\n\\begin{definition}\r\n\tA sequence $\\left\\{a_n\\right\\} = \\left\\{a_1, a_2, \\ldots, a_n\\right\\}$ is an ordered list of numbers.\r\n\tEach element of a sequences is called a term and is identified by its index in the sequence.\r\n\tSequences can be finite or infinite.\r\n\\end{definition}\r\n\r\n\\begin{example}\r\n\tThe nth term of a sequence is defined by the following formula:\r\n\t\\begin{equation*}\r\n\t\ta_n = \\frac{(-1)^n}{n^2+1}.\r\n\t\\end{equation*}\r\n\tFind the 1st, 2nd, and 100th terms of the sequence.\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\t\ta_1 &= \\frac{(-1)^1}{1^2 + 1} = \\frac{-1}{2} \\\\\r\n\t\ta_2 &= \\frac{(-1)^2}{2^2 + 1} = \\frac{1}{5} \\\\\r\n\t\ta_{100} &= \\frac{(-1)^{100}}{100^2 + 1} = \\frac{1}{10001}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\nThe above sequence was defined explicitly, meaning that we have a formula for the nth term of the sequence only in terms of n.\r\nHowever, sequences can also be defined recursively, meaning the formula for subsequent terms of the sequence contains previous terms.\r\nFor a recursive sequence to be properly defined, there need to be one or more base terms that aren't defined recursively.\r\nFor example, the Fibonacci sequence, one of the most famous recursive sequences, as $a_1$ and $a_2$ as base terms.\r\n\\begin{equation*}\r\n\ta_n = \\begin{cases}\r\n\t\t1 & n = 1, 2 \\\\\r\n\t\ta_{n-1} + a_{n-2} & n \\geq 3\r\n\t\\end{cases}.\r\n\\end{equation*}\r\n\r\n\\subsection{Common Types of Sequences}\r\nThere are some common types of sequences that you should be familiar with.\r\nYou might recognize these types of sequences and some of the formulas surrounding them from previous math classes.\r\n\r\n\\subsubsection{Arithmetic Sequences}\r\n\\begin{definition}\r\n\tAn arithmetic sequence is one where $a_{n+1} - a_{n} = d$, a common difference, for all terms.\r\n\\end{definition}\r\n\r\nThat is, to get the next term, we simply add some number $d$ (which could be negative) to the previous term.\r\nArithmetic sequences can be defined either explicitly or recursively.\r\nLet $a_0$ be the starting term of the sequence.\r\n\\begin{align*}\r\n\ta_n &= dn + a_0 \\\\\r\n\t&= \\begin{cases}\r\n\t\ta_0 & n = 0 \\\\\r\n\t\td + a_{n-1} & n \\geq 1\r\n\t\\end{cases}.\r\n\\end{align*}\r\nAs we can see from the explicit formula, if we graphed values of an arithmetic sequence on in the plane with $x$ coordinate $n$ and $y$ coordinate $a_n$, all points would lie on a line with slope $d$ and $y$ intercept $a_0$.\r\n\r\n\\begin{example}\r\n\tWrite an explicit formula for the following arithmetic sequence.\r\n\t\\begin{equation*}\r\n\t\t\\left\\{\\ln{2}, \\ln{6}, \\ln{18}, \\ldots\\right\\}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tSince we are given that this sequence is arithmetic, we'll find the common difference.\r\n\t\\begin{equation*}\r\n\t\td = \\ln{6} - \\ln{2} = \\ln{\\frac{6}{2}} = \\ln{3}.\r\n\t\\end{equation*}\r\n\t\r\n\tSo, applying the explicit formula for an arithmetic sequence with starting term $\\ln{2}$ and common difference $\\ln{3}$,\r\n\t\\begin{equation*}\r\n\t\ta_n = \\ln{(3)}n + \\ln{2}, n\\geq 0.\r\n\t\\end{equation*}\r\n\t\r\n\tWe might have also noticed that each term inside the $\\ln$ is triple the previous one, meaning we can write an explicit formula and then simplify to the same answer as before.\r\n\t\\begin{align*}\r\n\t\ta_n &= \\ln{(3^{n}\\cdot 2)}, n\\geq 0 \\\\\r\n\t\t&= \\ln{3^n} + \\ln{2}, n \\geq 0 \\\\\r\n\t\t&= \\ln{(3)}n + \\ln{2}, n \\geq 0.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Geometric Sequences}\r\n\\begin{definition}\r\n\tA geometric sequence is one where $\\frac{a_{n+1}}{a_n} = r$, a common ratio, for all terms.\r\n\\end{definition}\r\n\r\nThat is, to get the next term, we simply multiply some number $r$ (which could be negative) by the previous term.\r\nGeometric sequences can also be defined explicitly or recursively.\r\nLet $a_0$ be the starting term of the sequence.\r\n\\begin{align*}\r\n\ta_n &= a_0(r)^n \\\\\r\n\t&= \\begin{cases}\r\n\t\ta_0 & n = 0 \\\\\r\n\t\tra_{n-1} & n \\geq 1\r\n\t\\end{cases}.\r\n\\end{align*}\r\n\r\nAs we can see with the explicit formula, if we graphed terms of a geometric sequence for positive $r$, the points would lie on an exponential curve with $y$ intercept $a_0$ and exponential base $r$.\r\n\r\n\\begin{example}\r\n\tWrite an explicit formula for the following geometric sequence.\r\n\t\\begin{equation*}\r\n\t\t\\left\\{2,-6,18,-54,\\ldots\\right\\}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tSince we are given that this sequence is geometric, we'll find the common ratio.\r\n\t\\begin{equation*}\r\n\t\tr = \\frac{-6}{2} = 3.\r\n\t\\end{equation*}\r\n\t\r\n\tSo, applying the explicit formula for a geometric sequence with starting term 2 and common ratio -3,\r\n\t\\begin{equation*}\r\n\t\ta_n = 2(-3)^n.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\subsection{Limits of a Sequence}\r\nOnce we have a formula for a sequence, we might be interested to know if $a_n$ tends towards some value as $n$ gets large.\r\n\\begin{definition}\r\n\tLet $L$ be a real number, the sequence $\\left\\{a_n\\right\\}$ as limit $L$ as $n$ approaches infinity if given any real $\\epsilon > 0$, there is some index $m$ such that for all $n > m$\r\n\t\\begin{equation*}\r\n\t\t\\abs{a_n - L} < \\epsilon.\r\n\t\\end{equation*}\r\n\tWe notate this as \r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{a_n} = L\r\n\t\\end{equation*}\r\n\tand say the sequence converges to $L$.\r\n\tIf the sequence does not have a limit, then we say the sequences diverges.\r\n\\end{definition}\r\n\r\n\r\nThe following rules we gave for limits of a function: Sum and Difference Rule, Product Rule, Constant Multiple Rule, and Quotient Rule, all still apply to limits of sequences.\r\nThe only rule that doesn't still hold is the Power Rule because of the following sort of problem:\r\n\\begin{align*}\r\n\ta_n &= (-1)^n \\\\\r\n\t\\lim_{n\\to\\infty}{a_n^2} &= 1 \\\\\r\n\t\\left(\\lim_{n\\to\\infty}{a_n}\\right)^2 &= \\text{DNE} \\\\\r\n\t1 &\\neq \\text{DNE}.\r\n\\end{align*}\r\n\r\n\\subsubsection{The Sandwich Theorem for Sequences}\r\n\\begin{theorem}[Sandwich Theorem for Sequences]\r\n\tIf $\\lim_{n\\to\\infty}{a_n} = \\lim_{n\\to\\infty}{c_n} = L$ and there is an integer $m$ such that $a_n \\leq b_n \\leq c_n$ for all $n > m$, then $\\lim_{n\\to\\infty}{b_n} = L$.\r\n\\end{theorem}\r\n\r\nThis is essentially the same as the Sandwich Theorem for limits of a function.\r\nThe only added caveat is that we have to find some index $m$ for which the sandwiching inequality always holds for terms after the $m$th.\r\n\r\n\\begin{example}\r\n\tDetermine if the following sequence converges or diverges.\r\n\tIf it converges, find its limit.\r\n\t\\begin{equation*}\r\n\t\ta_n = (-1)^n\\frac{n-1}{2}, n\\geq 1.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe see that as $n$ grows large $\\abs{a_n}$ approaches 1.\r\n\tHowever, $a_n$ bounces between 1 and -1 depending on whether $n$ is even or odd.\r\n\tThus, we could let $\\epsilon = 1/2$, which would show that the limit diverges.\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tDetermine if the following sequences converges or diverges.\r\n\tIf it converges, find its limit.\r\n\t\\begin{equation*}\r\n\t\ta_n = \\frac{\\cos{n}}{n}, n\\geq 1.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tIt might at first seem that this limit diverges because $\\cos$ bounces between -1 and 1.\r\n\tHowever, we can use the Sandwich Theorem to show that the limit converges.\r\n\t\\begin{align*}\r\n\t\t\\frac{-1}{n} &\\leq \\frac{\\cos{n}}{n} \\leq \\frac{1}{n}, n\\geq 1 \\\\\r\n\t\t\\lim_{n\\to\\infty}{\\frac{-1}{n}} &\\leq \\lim_{n\\to\\infty}{\\frac{\\cos{n}}{n}} \\leq \\lim_{n\\to\\infty}{\\frac{1}{n}} \\\\\r\n\t\t0 &\\leq \\lim_{n\\to\\infty}{\\frac{\\cos{n}}{n}} \\leq 0 \\\\\r\n\t\t\\lim_{n\\to\\infty}{\\frac{\\cos{n}}{n}} &= 0.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Absolute Value Theorem}\r\nWe can apply the Sandwich Theorem to show that sequences whose absolute value converges to 0 must also converge to 0.\r\n\\begin{theorem}[Absolute Value Theorem]\r\n\tIf $\\lim_{n\\to\\infty}{\\abs{a_n}} = 0$, then $\\lim_{n\\to\\infty}{a_n} = 0$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n\tFor all $n$,\r\n\t\\begin{equation*}\r\n\t\t-\\abs{a_n} \\leq a_n \\leq \\abs{a_n}.\r\n\t\\end{equation*}\r\n\tApplying the Sandwich Theorem and limit properties,\r\n\t\\begin{align*}\r\n\t\t-\\lim_{n\\to\\infty}{\\abs{a_n}} &\\leq \\lim_{n\\to\\infty}{a_n} \\leq \\lim_{n\\to\\infty}{\\abs{a_n}} \\\\\r\n\t\t-0 &\\leq \\lim_{n\\to\\infty}{a_n} \\leq 0 \\\\\r\n\t\t\\lim_{n\\to\\infty}{a_n} &= 0.\r\n\t\\end{align*}\r\n\\end{proof}", "meta": {"hexsha": "80263a642b67e96cbc70ed29738a7c16c58d6912", "size": 8018, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/sequences_lhopital_improper/sequences.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/sequences_lhopital_improper/sequences.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/sequences_lhopital_improper/sequences.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 40.9081632653, "max_line_length": 225, "alphanum_fraction": 0.6754801696, "num_tokens": 2648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868804, "lm_q2_score": 0.8887587993853654, "lm_q1q2_score": 0.8203591775708854}}
{"text": "\\section{Quantifying uncertainty}\n\n\\subsection{Conditional probability}\n\n\\begin{equation}\n    P(a|b) = \\frac{a \\wedge B)}{P(b)}  \\implies P(A \\wedge B) = P(a|b) P(b)\n\\end{equation}\n\n\\begin{equation}\n    P(a) = \\sum_{b}{P(a, b)} = \\sum_{b}{P(a|b)P(b)}\n\\end{equation}\n\nChain rule\n\\begin{equation}\n    P(x_1, x_2, \\cdots, x_n) = \\prod_{i}{P(x_i|x_{i-1}, x_{i-2}, \\cdots x_1)}\n\\end{equation}\n\n\\subsection{Independence}\n\nTwo r.v. are independent if and only if $P(a, b) == P(a)P(b)$\n\n\\subsection{Bayes' Rule}\n\n\n\\begin{equation}\n\\begin{aligned}\n    P(a|b) &= \\frac{P(a, b)}{P(b)} \\\\\n    &= \\frac{P(b|a)P(a)}{P(b)} \\\\\n    &= \\frac{P(b|a)P(a)}{\\sum_{i}{P(B|a_i)}} \\\\\n    &\\propto P(b|a)P(a) \\thinspace  (w.r.t. a) \n\\end{aligned}\n\\end{equation}\n\n\n\n", "meta": {"hexsha": "cec214da6d411a0d67057dfd4fd23e86d561acd1", "size": 739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/quantifiyng_uncertainty.tex", "max_stars_repo_name": "Calcifer777/columbia-ai", "max_stars_repo_head_hexsha": "aaa7173bca6f2bc9edfe6fe55b5a1a37ab310066", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/quantifiyng_uncertainty.tex", "max_issues_repo_name": "Calcifer777/columbia-ai", "max_issues_repo_head_hexsha": "aaa7173bca6f2bc9edfe6fe55b5a1a37ab310066", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/quantifiyng_uncertainty.tex", "max_forks_repo_name": "Calcifer777/columbia-ai", "max_forks_repo_head_hexsha": "aaa7173bca6f2bc9edfe6fe55b5a1a37ab310066", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.5277777778, "max_line_length": 77, "alphanum_fraction": 0.5805142084, "num_tokens": 314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551525886193, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.820099066551601}}
{"text": "%\n% Chapter 5.5\n%\n\n\\section*{5.5 Average Value of a Function}\n\nThe average value of \\(x\\) on \\([a, b]\\) is\n\\[ f_{avg} = \\frac{1}{b-a} \\int_a^b f(x)dx \\]\n\n\\subsection*{Mean Value Theorem for Integrals}\n\nIf \\(f\\) is continuous on \\([a, b]\\), then there exists a number \\(c\\) in \\([a, b]\\) such that\n\\[ f(c) = f_{avg} = \\frac{1}{b-a} \\int_a^b f(x)dx \\]\n", "meta": {"hexsha": "35e708dc818dcb3c2a423d3c85ebf07bf8ea856c", "size": 350, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/5-5.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/5-5.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/5-5.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0, "max_line_length": 94, "alphanum_fraction": 0.58, "num_tokens": 138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850128595114, "lm_q2_score": 0.8757869981319862, "lm_q1q2_score": 0.8199862408081996}}
{"text": "\\subsection{Test 3}\r\n\\begin{enumerate}\r\n\t\\item Evaluate each of the following integrals as they appear or by changing coordinate systems. Sketch and/or describe the region geometrically to help in choosing an appropriate coordinate system.\r\n\t\\begin{enumerate}[label=\\alph*.]\r\n\t\t\\item \\begin{equation*}\r\n\t\t\t\\int_{0}^{3}{\\int_{0}^{2}{\\int_{0}^{1}{ze^{x+y+z^2}\\mathrm{d}x}\\mathrm{d}y}\\mathrm{d}x}\r\n\t\t\\end{equation*}\r\n\t\tWe can use a simple u-substitution.\r\n\t\t\\begin{align*}\r\n\t\t\tu &= z^2 + x + y, \\mathrm{d}u = 2z\\mathrm{d}z \\\\\r\n\t\t\tI &= \\int_{0}^{3}{\\int_{0}^{2}{\\int_{x+y}^{x+y+1}{\\frac{1}{2}e^{u}\\mathrm{d}u}\\mathrm{d}y}\\mathrm{d}x} \\\\\r\n\t\t\t&= \\frac{1}{2}\\int_{0}^{3}{\\int_{0}^{2}{e^{x+y+1} - e^{x+y}\\mathrm{d}y}\\mathrm{d}x} \\\\\r\n\t\t\t&= \\frac{1}{2}\\int_{0}^{3}{\\left((e^{3+x}-e^{2+x}) - (e^{1+x}-e^{x})\\right)\\mathrm{d}x} \\\\\r\n\t\t\t&= \\frac{1}{2}(e^6 - e^5 - e^4 + e^2 + e - 1)\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\t\\item \\begin{equation*}\r\n\t\t\t\\int_{0}^{\\sqrt{2}}{\\int_{-\\sqrt{2-x^2}}^{\\sqrt{2-x^2}}{\\int_{0}^{5}{z\\mathrm{d}z}\\mathrm{d}y}\\mathrm{d}x}\r\n\t\t\\end{equation*}\r\n\t\tThe region we are integrating is a half-cylinder, so we will use cylindrical coordinates.\r\n\t\t\\begin{align*}\r\n\t\t\tI &= \\int_{-\\pi/2}^{\\pi/2}{\\int_{0}^{\\sqrt{2}}{\\int_{0}^{5}{rz\\mathrm{d}z}\\mathrm{d}r}\\mathrm{d}\\theta} \\\\\r\n\t\t\t&= \\pi\\int_{0}^{\\sqrt{2}}{r\\mathrm{d}r}\\cdot\\int_{0}^{5}{z\\mathrm{d}z} \\\\\r\n\t\t\t&= \\pi\\left(\\frac{\\sqrt{2}^{2}}{2} - \\frac{0^2}{2}\\right) \\cdot \\left(\\frac{5^2}{2} - \\frac{0^2}{2}\\right) \\\\\t\r\n\t\t\t&= \\frac{25\\pi}{2}\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\t\\item \\begin{equation*}\r\n\t\t\t\\int_{-3}^{3}{\\int_{0}^{\\sqrt{9 - x^2}}{\\int_{0}^{\\sqrt{9 - x^2 - y^2}}{z\\mathrm{d}z}\\mathrm{d}y}\\mathrm{d}x}\r\n\t\t\\end{equation*}\r\n\t\tThe region we are integrating is a quarter sphere, so we will use spherical coordinates.\r\n\t\t\\begin{align*}\r\n\t\t\tI &= \\int_{0}^{3}{\\int_{0}^{\\pi}{\\int_{0}^{\\pi/2}{\\rho^2\\sin{\\phi}\\cos{\\phi}\\mathrm{d}\\phi}\\mathrm{d}\\theta}\\mathrm{d}\\rho} \\\\\r\n\t\t\t&= \\int_{0}^{3}{\\rho^3\\mathrm{d}\\rho}\\cdot\\int_{0}^{\\pi}{\\mathrm{d}\\theta} \\cdot \\int_{0}^{\\pi/2}{\\sin{\\phi}\\cos{\\phi}\\mathrm{d}\\phi} \\\\\r\n\t\t\t&= \\frac{3^4}{4} \\cdot \\pi \\cdot \\frac{1}{2} = \\frac{81\\pi}{8} \t\t\r\n\t\t\\end{align*}\r\n\t\\end{enumerate}\r\n\t\r\n\t\\item Let $\\Omega \\subset \\mathbb{R}^3$ be a spherical ball of radius $R$ centered at the origin. Set up and evaluate $\\iiint\\limits_{\\Omega}{\\mathrm{d}V}$.\\\\\r\n\tSince we are finding the volume of a ball, we'll use spherical coordinates.\r\n\t\\begin{align*}\r\n\t\t\\mathrm{d}V &= \\rho^2\\sin{\\phi}\\mathrm{d}\\rho\\mathrm{d}\\theta\\mathrm{d}\\phi \\\\\r\n\t\tI &= \\int_{0}^{R}{\\int_{0}^{2\\pi}{\\int_{0}^{\\pi}{\\rho^2\\sin{\\phi}\\mathrm{d}\\phi}\\mathrm{d}\\theta}\\mathrm{d}\\rho} \\\\\r\n\t\t&= \\int_{0}^{R}{\\rho^2\\mathrm{d}\\rho} \\cdot \\int_{0}^{2\\pi}{\\mathrm{d}\\theta} \\cdot \\int_{0}^{\\pi}{\\sin{\\phi}\\mathrm{d}\\phi} \\\\\r\n\t\t&= \\frac{R^3}{3} \\cdot 2\\pi \\cdot 2 = \\frac{4\\pi}{3}R^3\t\r\n\t\\end{align*}\r\n\t\r\n\t\\item A plane lamina with density $\\sigma(x,y) = \\sqrt{x^2+y^2}$ occupies the region $D$, the region bounded by the Archimedian spiral $r = \\theta$ and the half line $\\theta = \\alpha, r \\geq 0$, where $\\alpha$ is an unknown angle in radians. Find $\\alpha$ such that the average density $\\bar{\\sigma}$ of the lamina is $\\pi / 2$.\r\n\t\\begin{equation*}\r\n\t\t\t\\bar{\\sigma} = \\frac{\\iint\\limits_{D}{\\sigma\\mathrm{d}A}}{\\iint\\limits_{D}{\\mathrm{d}A}} = \\frac{\\pi}{2}\r\n\t\\end{equation*}\r\n\t\\begin{equation*}\r\n\t\tD = \\left\\{(r,\\theta) \\mid 0 \\leq \\theta \\leq \\alpha, 0 \\leq r \\leq \\theta \\right\\}, \\sigma(r,\\theta) = r\r\n\t\\end{equation*}\r\n\t\\begin{align*}\r\n\t\t\\bar{\\sigma} &= \\frac{\\int_{0}^{\\alpha}{\\int_{0}^{\\theta}{r^2\\mathrm{d}r}\\mathrm{d}\\theta}}{\\int_{0}^{\\alpha}{\\int_{0}^{\\theta}{r\\mathrm{d}r}\\mathrm{d}\\theta}} \\\\\r\n\t\t&= \\frac{\\int_{0}^{\\alpha}{\\frac{\\theta^3}{3}\\mathrm{d}\\theta}}{\\int_{0}^{\\alpha}{\\frac{\\theta^2}{2}\\mathrm{d}\\theta}} \\\\\r\n\t\t&= \\frac{\\alpha^4/12}{\\alpha^3/6} = \\frac{\\alpha}{2} \\\\\r\n\t\t\\frac{\\alpha}{2} &= \\frac{\\pi}{2} \\\\\r\n\t\t&\\implies \\alpha = \\pi\t\t\r\n\t\\end{align*}\r\n\t\r\n\t\\item Consider the 2D Gaussian function $f(x,y) = e^{-(x^2+y^2)}$. Evaluate $\\iint\\limits_{D}{f(x,y)\\mathrm{d}A}$, where $D$ is a disk of radius $a$ centered at the origin. Use the results to evaluate $\\iint\\limits_{\\mathbb{R}^2}{f(x,y)\\mathrm{d}A}$.\r\n\t\\begin{equation*}\r\n\t\tD = \\left\\{(r,\\theta) \\mid 0 \\leq r \\leq a, 0 \\leq \\theta \\leq 2\\pi \\right\\}\r\n\t\\end{equation*}\r\n\t\\begin{equation*}\r\n\t\tf(x,y) = \\exp{(-x^2-y^2)} = \\exp{(-r^2)}\t\r\n\t\\end{equation*}\r\n\t\\begin{align*}\r\n\t\t\\iint\\limits_{D}{f(x,y)\\mathrm{d}A} &= \\int_{0}^{2\\pi}{\\int_{0}^{a}{e^{-r^2}r\\mathrm{d}r}\\mathrm{d}\\theta} \\\\\r\n\t\t&= \\int_{0}^{2\\pi}{\\mathrm{d}\\theta} \\cdot \\frac{-1}{2}\\int_{0}^{-a^2}{e^{u}\\mathrm{d}u} \\\\\r\n\t\t&= 2\\pi \\cdot \\frac{-1}{2} \\cdot \\left(e^{-a^2} - 1\\right) \\\\\r\n\t\t&= \\pi\\left(1 - e^{-a^2}\\right)\r\n\t\\end{align*}\r\n\t\\begin{equation*}\r\n\t\t\\iint\\limits_{\\mathbb{R}^2}{f(x,y)\\mathrm{d}A} = \\lim_{a \\to \\infty}{\\pi\\left(1 - e^{-a^2}\\right)} = \\pi\r\n\t\\end{equation*}\r\n\\end{enumerate}", "meta": {"hexsha": "86ba10def200b17219ecbdd8819b41169704f8b7", "size": 4853, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/additionalMaterials/test3.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/additionalMaterials/test3.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/additionalMaterials/test3.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.4303797468, "max_line_length": 330, "alphanum_fraction": 0.5775808778, "num_tokens": 2160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8962513786759491, "lm_q1q2_score": 0.8199812381052108}}
{"text": "\n\\subsection{Complex conjugate}\n\nWe have \\(z=a+bi\\).\n\nThe complex conjugate is:\n\n\\(\\bar z=a-bi\\)\n\n", "meta": {"hexsha": "995418b7a9082e6fc4845ea7a95eb6f2d38bd9e7", "size": 98, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/complex/02-02-conjugate.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/complex/02-02-conjugate.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/complex/02-02-conjugate.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 9.8, "max_line_length": 30, "alphanum_fraction": 0.6530612245, "num_tokens": 32, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122696813392, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.8198303129398015}}
{"text": "\n\\subsection{Maximising the likelihood function}\n\nWe have a likelihood function of the data.\n\n\\(L(\\theta ; X)=P(X|\\theta )\\)\n\nWe choose values for \\(\\theta \\) which maximise the likelihood function.\n\n\\(argmax_\\theta P(X|\\theta )\\)\n\nThat is, for which values  of \\(\\theta \\) was the observation we saw most likely?\n\nThis is a mode estimate.\n\n\\subsection{IID}\n\n\\(L(\\theta ; X)=\\prod_i P(x_i|\\theta )\\)\n\n\\subsection{Logarithms}\n\nWe can take logarithms, which preserve stationary points. As logarithms are defined on all values above \\(0\\), and all probabilities are also above zero (or zero), this preserves solutions.\n\nThe non-zero stationary points of:\n\n\\(\\ln L(\\theta ; X)=\\ln \\prod_i P(x_i|\\theta )\\)\n\n\\(\\ln L(\\theta ; X)=\\sum_i \\ln P(x_i|\\theta )\\)\n\n\\subsection{Example: Coin flip}\n\nLet\u2019s take our simple example about coins. Heads and tails are the only options, so \\(P(H)+P(T)=1\\). \n\n\\(P(H|\\theta )=\\theta \\)\n\n\\(P(T|\\theta )=1-\\theta \\)\n\n\\(\\ln L(\\theta ; X)=\\sum_i \\ln P(x_i|\\theta )\\)\n\nIf we had \\(5\\) heads and \\(5\\) tails we would have:\n\n\\(\\ln L(\\theta ; X)=5\\ln (\\theta )+ 5\\ln (1-\\theta )\\)\n\nSo \\(P(H)=\\dfrac{1}{2}\\) is the value which makes our observation most likely.\n\n", "meta": {"hexsha": "53f0c233d727c4f82e75866effa7011caf9f8247", "size": 1181, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/MLE/01-01-MLE.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/MLE/01-01-MLE.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/MLE/01-01-MLE.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6739130435, "max_line_length": 189, "alphanum_fraction": 0.6655376799, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630935, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.8198015417998517}}
{"text": "%%%%%%%%%%%%%\n% Lp Spaces %\n%%%%%%%%%%%%%\n\n\\section{\\texorpdfstring{$L_p$}\\ \\ Spaces}\n\n\\begin{theorem}{}{H\\\"older's Inequality}\n\n    Let $f,g: \\Omega \\to \\overline{\\mathbb{R}}$ be measurable functions, then\n\n        \\begin{align*}\n            \\int_{\\Omega} |fg| \\, d\\mu \\leq \\Norm{f}_p \\Norm{g}_q \\quad \\textrm{for } p \\geq 1,\n        \\end{align*}\n\n    where\n\n        \\begin{align*}\n            q \\coloneqq \n            \\begin{cases}\n                \\frac{p}{p - 1} & p > 1, \\\\\n                \\infty & p = 1\n            \\end{cases}.\n        \\end{align*}\n\n\\end{theorem}\n\n\\begin{theorem}{}{H\\\"older's Inequality for Expectations}\n\n    Let $X,Y$ be random variables, then\n\n        \\begin{align*}\n            E|XY| \\leq (E|X|^p)^{\\frac{1}{p}} (E|Y|^q)^{\\frac{1}{q}}\n        \\end{align*}\n\n    where\n\n        \\begin{align*}\n            q \\coloneqq \n            \\begin{cases}\n                \\frac{p}{p - 1} & p > 1, \\\\\n                \\infty & p = 1\n            \\end{cases}.\n        \\end{align*}\n\n\\end{theorem}\n\n\\begin{proposition}{}{Finite Second Momenta Implication}\n\n    Let $X, Y$ be random variables with finite second momenta. Then $E|XY| < \\infty$.\n\n    \\Hint Use H\\\"older's Inequality with $p = 2$ on $E|XY| = \\int_{\\Omega} |XY| \\, dP$.\n\n\\end{proposition}\n\n\n\\begin{lemma}{4.4}{Borel-Cantelli Lemma}\n\n    Let $(A)_{n=1}^{\\infty}$ be a sequence of sets $A_n \\in \\CalF$ such that $\\sum_{n=1}^{\\infty} \\mu(A_n) < \\infty$, i.e. the series of measures of $A_n$ converges. Then for:\n\n        \\begin{align*}\n            A \\coloneqq \\limsup_{n \\to \\infty} A_n \\coloneqq \\bigcap_{n=1}^{\\infty} \\bigcup_{k=n}^{\\infty} A_k,\n        \\end{align*}\n\n    we have $\\mu(A) = 0$.\n\n    \\Hint Define $B_n \\coloneqq \\bigcup_{k=n}^{\\infty} A_k$, then $(B_n)_{n=1}^\\infty$ is decreasing and so $\\bigcap_{n=1}^{\\infty} B_n = \\lim_{n \\to \\infty} B_n$ and realize that $\\sum_{n=1}^{\\infty} \\mu(A_n) < \\infty$ $\\Rightarrow$ tail sums $\\sum_{k=n}^{\\infty} \\mu(A_k) \\to 0$ as $n \\to \\infty$.\n\n\\end{lemma}\n", "meta": {"hexsha": "f6e92977baa12e4b20bec3b9afcad2236dac6ec0", "size": 1977, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/lp-spaces.tex", "max_stars_repo_name": "smueksch/measure-theory-overview", "max_stars_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/lp-spaces.tex", "max_issues_repo_name": "smueksch/measure-theory-overview", "max_issues_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/lp-spaces.tex", "max_forks_repo_name": "smueksch/measure-theory-overview", "max_forks_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-02T15:34:51.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-02T15:34:51.000Z", "avg_line_length": 28.652173913, "max_line_length": 299, "alphanum_fraction": 0.5260495701, "num_tokens": 735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8902942275774319, "lm_q1q2_score": 0.8197737293882296}}
{"text": "In general, there are three kinds of claim ``structures'' which encompass the vast majority of claims that people want to prove. These are the ``object has property'' structure, the ``hypothesis implies conclusion'' structure, and the ``situations are equivalent'' structure. We expand more on these below.\n\nAn ``object has property'' structure concerns some specific object or collection of objects, with certain properties known beforehand. The nature of the claim is that the object has some other property, which is usually not totally obvious from the properties that are known beforehand. Here is an example of such a claim:\n\\begin{proposition}\nThe set of natural numbers $\\mathbb{N}$ are countable.\n\\end{proposition}\nHere the object in question is specific, being the set of natural numbers $\\mathbb{N}$ and the property is the property of countability of a set. However, based on the definition of countability, this claim is trivially true based on the definition of countability. Is there anything we might glean from it? Here is another similar claim, but instead with a collection of objects.\n\\begin{proposition}\nAny subset of the natural numbers $\\mathbb{N}$ is countable.\n\\end{proposition}\nHere, the property remains the same, but we have expanded to a collection of objects, namely the subset of natural numbers. However, this claim is still trivially true based on the definition of countability. Maybe there is a more general claim which is not immediately obvious? There is, once we replace $\\mathbb{N}$ with any countable set.\n\\begin{proposition}\nAny subset of a countable set is countable.\n\\end{proposition}\nWe use this set of examples to indicate that a claim involving a very specific object (the natural numbers) can be made into a claim that is much more general (and not immediately obvious). In this way, a lot of mathematics is built from the ``ground up'' from small examples which get more general.\n\n\\subsection{Hypothesis implies Conclusion}\n\nThe other type of claim usually investigated has a ``hypothesis implies conclusion'' structure. With these claims, the hypothesis usually involves one or several objects with various properties, and the claim is that some given conclusion will follow. That is, these types of claims usually go the following way: ``Suppose A, B, \\ldots satisfy the following properties or relations. Then a certain conclusion follows.'' Here is a more specific example:\n\n\\begin{proposition}\nSuppose $A$, $B$, and $C$ are sets with $A \\subset B$ and $B \\subset C$. Then $A \\subset C$.\n\\end{proposition}\n\nHere, the objects are $A$, $B$, and $C$ with some properties involving subset relations. The conclusion is another property involving subset relations.\n\n\\subsection{Situations are Equivalent}\n\nSimilarly to the ``hypothesis implies conclusion'' proof structure, the ``situations are equivalent'' structure involves a set of two or more hypotheses. The claim is that each of these hypotheses implies the other. Usually these claims will have the following form:\n\n\\begin{proposition}\nThe following are equivalent:\n\\begin{itemize}\n\t\\item Situation A\n\t\\item Situation B\n\\end{itemize}\n\\end{proposition}\n\nTo prove this proposition is true is the same as showing both the claims ``Situation A implies Situation B'' and ``Situation B implies Situation A''. \n\nFor the situation with $3$ or more hypotheses, one might imagine that one needs to show a lot more than two claims, and the situation may get out of hand quickly. However, this is not the case, since it turns out implication is transitive. That is, if ``Situation A implies Situation B'' and ``Situation B implies Situation C'', then it follows that ``Situation A implies Situation C''. So if we are to show situations A, B, and C are equivalent, one possible way to show this is to show the following claims to be true:\n\n\\begin{itemize}\n\t\\item Situation A implies Situation B\n\t\\item Situation B implies Situation C\n\t\\item Situation C implies Situation A.\n\\end{itemize}\n\n", "meta": {"hexsha": "361fa663c529de1632f911505eb25f9ddcf6fa29", "size": 3980, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch4/proofforms.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch4/proofforms.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch4/proofforms.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 81.2244897959, "max_line_length": 520, "alphanum_fraction": 0.7824120603, "num_tokens": 882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990283, "lm_q2_score": 0.8947894696095782, "lm_q1q2_score": 0.8197252331984944}}
{"text": "\\section{Data normalization in DNNs and CNNs}\n\n\\subsection{Normalization for input data of DNNs}\nConsider that we have the all training data as\n\\begin{equation}\\label{eq:trainingdata}\n(X,Y) := \\{(x_i, y_i)\\}_{i=1}^N,\n\\end{equation}\nfor $x_i \\in \\mathbb{R}^d$ and $y_i \\in \\mathbb{R}^k$.\n\nBefore we input every data into a DNN model, we will apply the following normalization\nfor all data $x_i$ for each component.\nLet denote\n\\begin{equation}\\label{key}\n[x_i]_j \\longleftrightarrow \\text{ the j-th component of data } x_i.\n\\end{equation}\nThen we have following formula of for all $j = 1, 2, \\cdots, d$\n\\begin{equation}\\label{key}\n[\\tilde x_i]_j  = \\frac{[x_i]_j - [\\mu_X]_j }{\\sqrt{[\\sigma_X]_j}},\n\\end{equation}\nwhere \n\\begin{equation}\\label{key}\n[\\mu_X]_j =\\mathbb{E}_{x \\sim X}[[x]_j] = \\frac{1}{N}\\sum_{i=1}^N [x_i]_j, \n\\quad  [\\sigma_X]_j = \\mathbb{V}_{x\\sim X}[[x]_j] = \\frac{1}{N} \\sum_{i=1}^N ( [x_i]_j - [\\mu_X]_j)^2.\n\\end{equation}\nHere $x \\sim X$ means that $x$ is a discrete random variable on $X$\nwith probability\n\\begin{equation}\\label{key}\n\\mathbb P( x = x_i ) = \\frac{1}{N},\n\\end{equation}\nfor any $x_i \\in X$.\n\nFor simplicity, we rewrite the element-wise definition above as the following\ncompact form\n\\begin{equation}\\label{eq:normlizationData}\n\\tilde x_i = \\frac{x_i - \\mu_X }{\\sqrt{\\sigma_X}},\n\\end{equation}\nwhere\n\\begin{equation}\\label{key}\nx_i , \\tilde x_i , \\mu_X, \\sigma_X \\in \\mathbb{R}^d,\n\\end{equation}\ndefined as before and all operations in \\eqref{eq:normlizationData} are element-wise.\n\n\nHere we note that, by normalizing the data set, we have the next properties \nfor new data $\\tilde x \\in \\tilde X$ with component $j = 1,2,\\cdots,d$,\n\\begin{equation}\\label{key}\n\\mathbb{E}_{\\tilde X}[[\\tilde x]_j] = \\frac{1}{N} \\sum_{i=1}^N [\\tilde x_i]_j = 0,\n%\\begin{pmatrix}\n%0\\\\0\\\\\\vdots\\\\0 \n%\\end{pmatrix} \\in \\mathbb{R}^d,\n\\end{equation}\nand \n\\begin{equation}\\label{key}\n\\mathbb{V}_{\\tilde X}[[\\tilde x]_j] = \\frac{1}{N} \\sum_{i=1}^N ([\\tilde x_i]_j - \\mathbb{E}_{\\tilde X}[[\\tilde x]_j] )^2 = 1.\n%\\begin{pmatrix}\n%1\\\\1\\\\\\vdots\\\\1 \n%\\end{pmatrix} \\in \\mathbb{R}^d.\n\\end{equation}\n\nFinally, we will have a ``new'' data set \n\\begin{equation}\\label{key}\n\\tilde X = \\{\\tilde x_1, \\tilde x_2, \\cdots, \\tilde x_N \\},\n\\end{equation}\nwith unchanged label set $Y$. For the next sections, without special notices, we use $X$ data set\nas the normalized one as default. \n\n\n\\subsection{Data normalization for images in CNNs}\nFor images, consider we have a color image data set $(X,Y) := \\{(x_i, y_i)\\}_{i=1}^N$ where\n\\begin{equation}\\label{key}\nx_i \\in \\mathbb{R}^{3 \\times m\\times n}.\n\\end{equation}\nWe further denote these the $(s,t)$ pixel value for data $x_i$ at channel $j$ as:\n\\begin{equation}\\label{key}\n[x_i]_{j;st} \\longleftrightarrow (s,t) \\text{ pixel value for } x_i \\text{ at channel } j,\n\\end{equation}\nwhere $1\\le i \\le N, 1\\le j\\le 3, 1\\le s \\le m$, and  $1\\le j\\le n$.\n\nThen, the normalization for $x_i$ is defined by\n\\begin{equation}\\label{key}\n[\\tilde x_i]_{{j;st}} = \\frac{[x_i]_{{j;st}} - [\\mu_X]_j }{\\sqrt{[\\sigma_X]_j}},\n\\end{equation}\nwhere %$\\bm 1 \\in \\mathbb{R}^{m\\times n}$ with all elements equal to $1$ and\n\\begin{equation}\\label{key}\n[x_i]_{{j;st}}, [\\tilde x_i]_{{j;st}}, [\\mu_X]_j, [\\sigma_X]_j \\in \\mathbb{R}.\n\\end{equation}\nHere \n\\begin{equation}\\label{key}\n[\\mu_X]_j = \\frac{1}{m\\times n\\times N} \\sum_{ 1 \\le i \\le N} \\sum_{1\\le s \\le m, 1 \\le t \\le n} [x_i]_{j;st}.\n\\end{equation}\nand \n\\begin{equation}\\label{key}\n[\\sigma_X]_j = \\frac{1}{ N \\times m\\times n} \\sum_{ 1 \\le i \\le N} \\sum_{1\\le s \\le m, 1 \\le t \\le n} ([x_i]_{j;st} -[\\mu_X]_j )^2.\n\\end{equation}\nIn batch normalization, we confirmed with Lian by both numerical test and code checking that BN also use the above \nformula to compute the variance in CNN for each channel.\n\n\nAnother way to compute the variance over each channel is to compute the standard deviation on each channel for every data,\nand then average them in the data direction.\n\\begin{equation}\\label{key}\n\\sqrt{[\\tilde \\sigma_X]_j} = \\frac{1}{ N} \\sum_{ 1 \\le i \\le N}  \\left( \\frac{1}{m\\times n}\\sum_{1\\le s \\le m, 1 \\le t \\le n} ([x_i]_{j;st} - [\\mu_i]_j )^2 \\right)^{\\frac{1}{2}},\n\\end{equation}\nwhere\n\\begin{equation}\\label{key}\n[\\mu_i]_j  = \\frac{1}{m\\times n} \\sum_{1\\le s \\le m, 1 \\le t \\le n} [x_i]_{j;st}.\n\\end{equation}\n\n\\subsection{Comparison of $\\sqrt{[\\sigma_X]_j}$ and  $\\sqrt{[\\tilde \\sigma_X]_j}$ on CIFAR10.}\n\nThey share the same $\\mu_X$ as\n\\begin{equation}\\label{key}\n\\mu_X = \\begin{pmatrix}\n0.49140105 & 0.48215663 & 0.44653168\n\\end{pmatrix}.\n\\end{equation}\nBut they had different standard deviation estimates:\n\\begin{equation}\n\\begin{aligned}\n\\sqrt{[\\sigma_X]_j} &= \\begin{pmatrix}\n0.24703284 & 0.24348499 & 0.26158834\n\\end{pmatrix} \\\\\n%\\sqrt{[\\bar \\sigma_X]_j} &= \\begin{pmatrix}\n%0.12835675 & 0.12578563 & 0.1533168\n%\\end{pmatrix} \\\\\n\\sqrt{[\\tilde \\sigma_X]_j} &= \\begin{pmatrix}\n0.20220193 & 0.19931635 & 0.20086373\n\\end{pmatrix} \n\\end{aligned}\n\\end{equation}\n\n\\section{Initialization for deep neural networks}\n\n\\subsection{Xavier's Initialization}\nThe goal of Xavier initialization~\\cite{glorot2010understanding} is to initialize the deep neural network to avoid gradient vanishing or blowup when the input is white noise.\n\nLet us denote the DNN models as:\n\\begin{equation}\n\\begin{cases}\nf^1(x) &= W^1 x + b^1 \\\\\nf^{\\ell}(x) &= W^\\ell \\sigma(f^{\\ell-1}(x)) + b^\\ell \\quad \\ell = 2:L \\\\\nf(x) &= f^{L} \\\\\n\\end{cases},\n\\end{equation}\nwith $x \\in \\mathbb{R}^{n_0}$ and $f^{\\ell} \\in \\mathbb{R}^{n_\\ell}$. More precisely, we have\n\\begin{equation}\\label{key}\nW^\\ell \\in \\mathbb{R}^{n_{\\ell} \\times n_{\\ell-1}}.\n\\end{equation}\n\nThe basic assumptions that we make are:\n\\begin{itemize}\n\t%% \\item The input $x$ is a mean $0$ random variable with identity covariance, i.e. $\\mathbb{E}(x) = 0$, $\\mathbb{E}(x_ix_j) = 0$ if $i\\neq j$, and $\\mathbb{E}(x_i^2) = 1$\n\t% \\item \\blue{The input $x$ is a mean $0$ random vector with the same variance for each component, i.e. $\\mathbb{E}[[x]_i] = 0$ and $\\mathbb{E}[[x]_i^2] (\\mathbb{V} [[x]_i]) =$ $\\mathbb{E}[[x]_j^2] (\\mathbb{V}[[x]_j])$. }\n\t% (Here we notice that, after data normalization as discussed before this assumption holds directly.)\n\t\\item The initial weights $W^\\ell_{ij}$ are i.i.d symmetric random variables with mean $0$, namely the \n\tprobability density function of $W^\\ell_{ij}$ is even.\n\t\\item The initial bias $b^\\ell = 0$.\n\\end{itemize}\n\n\nNow we choose the variance of the initial weights to ensure that the features $f^L$ and gradients don't blow up or vanish. To this end we have the following lemma.\n\n\\begin{lemma}\\label{lemm:init}\n\tUnder the previous assumptions $f^\\ell_i$  is a symmetric random variable with $\\mathbb{E}[f^\\ell] = 0$.\n\tMoreover, we have the following identity\n\t\\begin{equation}\\label{eq:FWini}\n\t\\mathbb{E}[(f^{\\ell}_i)^2] = \\sum_{k}\\mathbb{E}[(W^\\ell_{ik})^2]\\mathbb{E}[\\sigma(f^{\\ell-1}_k)^2].\n\t\\end{equation}\n\t% \\begin{equation}\\label{key}\n\t%  \\mathbb V [f^{L}_i] =  \\left(\\Pi_{\\ell=1}^{L} n_{\\ell-1} {\\rm Var} [W^\\ell_{st}] \\right)\\mathbb V [x_j].\n\t% \\end{equation}\n\\end{lemma}\n%Note that here we don't have that $f^\\ell_i$ and $f^\\ell_j$ are actually independent, just that they are `linearly' independent.\n\n\n\nNow, if $\\sigma  = id$, we can prove by induction from $\\ell = 1$ that\n\t\\begin{equation}\\label{key}\n\t\\mathbb V [f^{L}_i] =  \\left(\\Pi_{\\ell=2}^{L} n_{\\ell-1} {\\rm Var} [W^\\ell_{st}] \\right) \\left(\\mathbb{V}[W^1_{st}]\\sum_{k}\\mathbb{E}[( [x]_k)^2] \\right).\n\t\\end{equation}\nWe make this assumption that $\\sigma  = id$, which is pretty reasonably since most activation functions in use at the time (such as the hyperbolic tangent) were close to the identity near $0$.\n\nNow, if we set \n\\begin{equation}\\label{key}\n\\mathbb{V}[W^\\ell_{ik}] = \\frac{1}{n_{\\ell-1}}, \\quad \\forall \\ell \\ge 2,\n\\end{equation}\nwe will obtain\n\\begin{equation}\n\\mathbb V [f^{L}_i] = \\mathbb V [f^{L-1}_j] = \\cdots =  \\mathbb V [f^{1}_k] = \\mathbb{V}[W^1_{st}]\\sum_{k}\\mathbb{E}[( [x]_k)^2].\n\\end{equation}\n\nThus, in pure DNN models, it is enough to just control $\\sum_{k}\\mathbb{E}[( [x]_k)^2]$.\n\nA similar analysis of the propagation of the gradient ($\\frac{\\partial L(\\theta)}{\\partial f^\\ell}$) suggests that we set \n\\begin{equation}\\label{key}\n\\mathbb{V}[W^\\ell_{ik}] = \\frac{1}{n_{\\ell}}.\n\\end{equation}\n\n\nThus, the {\\bf Xavier's initialization} suggests to initialize $W^\\ell_{ik}$ with variance as:\n\\begin{itemize}\n\t\\item To control $\\mathbb V [f^{\\ell}_i] $:\n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[W^\\ell_{ik}] = \\frac{1}{n_{\\ell-1}}.\n\t\\end{equation}\n\t\\item To control $\\mathbb{V}[\\frac{\\partial L(\\theta)}{\\partial f_i^\\ell}]$:\n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[W^\\ell_{ik}] = \\frac{1}{n_{\\ell}}.\n\t\\end{equation}\n\t\\item Trade-off to control $\\mathbb{V} [\\frac{\\partial L(\\theta)}{\\partial W_{ik}^\\ell}]$: \n\t\\begin{equation}\\label{key}\n\t{\\rm Var}[W^\\ell_{ik}] = \\frac{2}{n_{\\ell-1} + n_\\ell}.\n\t\\end{equation}\n\\end{itemize}\n\nHere we note that, this analysis works for all symmetric type distribution around zero, \nbut we often just choose uniform distribution $\\mathcal U(-a,a)$ and normal distribution $\\mathcal N(0,s^2)$.\nThus, the final version of Xavier's initialization takes the trade-off type as\n\\begin{equation}\nW^{\\ell}_{ik} \\sim \\mathcal{U}(-\\sqrt{\\frac{6}{n_\\ell+n_{\\ell-1}}}, \\sqrt{\\frac{6}{n_\\ell+n_{\\ell-1}}}),\n\\end{equation}\nor\n\\begin{equation}\nW^{\\ell}_{ik} \\sim \\mathcal{N}(0,  {\\frac{2}{n_\\ell+n_{\\ell-1}}}).\n\\end{equation}\n\n\n%\\subsection{Variance analysis in backward propagation phase}\n%See the separate file in {``6DL/HandWrittenNotes/InitBackward.pdf''}\n%\\includepdf[pages=-,pagecommand={}]{HandWrittenNotes/InitBackward.pdf}\n%\\includepdf[pages=-,pagecommand={}]{497/handwritten_notes/MultidimensionalVariance.pdf}\n\n\n\\subsection{Kaiming's initialization}\nIn~\\cite{he2015delving}, Kaiming He and others extended this analysis to get an \\textit{exact} result when the activation function is the {\\bf ReLU}.\n\nWe first have the following lemma for symmetric distribution.\n\\begin{lemma}\n\tIf $X_i \\in \\mathbb{R}$ for $i=1:n$ are i.i.d with symmetric probability density function $p(x)$, i.e. $p(x)$ is even.\n\tThen for any nonzero random vector $Y = (Y_1, Y_2, \\cdots, Y_n) \\in \\mathbb{R}^n$ which is independent with $X_i$, \n\tthe following random variable\n\t\\begin{equation}\\label{key}\n\tZ = \\sum_{i=1}^n X_i Y_i,\n\t\\end{equation} \n\tis also symmetric.\n\\end{lemma}\n\n\nThen state the following result for ReLU function and random variable with \nsymmetric distribution around $0$.\n\\begin{lemma}\n\tIf $X$ is a random variable on $\\mathbb{R}$ with symmetric probability density $p(x)$ around zero, i.e., \n\t\\begin{equation}\\label{key}\n\tp(x) = p(-x).\n\t\\end{equation}\n\tThen we have $\\mathbb{E} X = 0$ and \n\t\\begin{equation}\\label{key}\n\t\\mathbb{E}[[{\\rm ReLU}(X)]^2] = \\frac{1}{2}{\\rm Var}[X].\n\t\\end{equation}\n\\end{lemma}\n\n\nBased on the previous Lemma~\\ref{lemm:init}, we know that $f^{\\ell-1}_k$ is a symmetric distribution around $0$.\nThe most important observation in Kaiming's paper~\\cite{he2015delving} is that:\n\\begin{equation}\\label{key}\n\\mathbb{V}[ f^\\ell_i ] = n_{\\ell-1}  \\mathbb{V}[W^\\ell_{ij}] {\\mathbb{E}[[\\sigma(f^{\\ell-1}_j)]^2]} = n_{\\ell-1} \\mathbb{V}[W^\\ell_{ik}] {\\frac{1}{2} \\mathbb{V}[f^{\\ell-1}_k]},\n\\end{equation}\n{if $\\sigma = {\\rm ReLU}$}.\nThus, Kaiming's initialization suggests to take:\n\\begin{equation}\\label{key}\n\\mathbb{V}[W^\\ell_{ik}] = \\frac{2}{n_{\\ell-1}}, \\quad \\forall \\ell \\ge 2.\n\\end{equation}\n\nFor the first layer $\\ell=1$, by definition\n\\begin{equation}\\label{key}\nf^1 = W^1 x + b^1,\n\\end{equation}\nthere is no ReLU, thus it should be $\\mathbb{V}[W^1_{ik}] = \\frac{1}{d}$. \nFor simplicity, they still use $\\mathbb{V}[W^1_{ik}] = \\frac{2}{d}$ in the paper~\\cite{he2015delving}.\nSimilarly, an analysis of the propagation of the gradient suggests that we set \n$\\mathbb{V}[W^\\ell_{ik}] = \\frac{2}{n_{\\ell}}$.\nHowever, in paper~\\cite{he2015delving} authors did not suggest to take the trade-off version, they just chose \n\\begin{equation}\\label{key}\n\\mathbb{V}[W^\\ell_{ik}] = \\frac{2}{n_{\\ell-1}},\n\\end{equation} as default.\n\nThus, the final version of Kaiming's initialization takes the forward type as\n\\begin{equation}\nW^{\\ell}_{ik} \\sim \\mathcal{U}(-\\sqrt{\\frac{6}{n_{\\ell-1}}}, \\sqrt{\\frac{6}{n_{\\ell-1}}}),\n\\end{equation}\nor\n\\begin{equation}\nW^{\\ell}_{ik} \\sim \\mathcal{N}(0,  {\\frac{2}{n_{\\ell-1}}}).\n\\end{equation}\n\n%And another difference is that Xavier use the uniform distribution but He use the Gaussian distribution. \n%More precisely, \n%However, in Pytorch implementation, the uniform distribution is also applied.\n\n\n\n\\subsection{Initialization in CNN models and experiments}\nFor CNN models, following the analysis above we have the next iterative scheme in CNNs\n\\begin{equation}\\label{key}\nf^{\\ell,i} = K^{\\ell,i} \\ast \\sigma (f^{\\ell,i-1}),\n\\end{equation}\nwhere $f^{\\ell,i-1} \\in \\mathbb{R}^{c_\\ell\\times n_\\ell \\times m_\\ell }$, $f^{\\ell,i} \\in \\mathbb{R}^{h_\\ell\\times n_\\ell \\times m_\\ell}$ and $K \\in \\mathbb{R}^{(2k+1) \\times (2k+1) \\times h_\\ell \\times c_\\ell}$.\nThus we have\n\\begin{equation}\\label{key}\n[f^{\\ell,i}]_{h;p,q} = \\sum_{c=1}^{c_\\ell}\\sum_{s,t=-k}^k K^{\\ell,i}_{h,c;s,t} \\ast \\sigma ([f^{\\ell,i-1}]_{c;p+s,q+t}).\n\\end{equation}\nTake variance on both sides, we will get\n\\begin{equation}\\label{key}\n\\mathbb{V} [[f^{\\ell,i}]_{h;p,q}] = c_\\ell (2k+1)^2 \\mathbb{V}[K^{\\ell,i}_{h,o;s,t}] \\mathbb{E}[([f^{\\ell,i-1}]_{o;p+s,q+t})^2],\n\\end{equation}\nthus we have the following initialization strategies:\n\\begin{description}\n\t\\item[Xavier's initialization] \n\t\\begin{equation}\\label{key}\n\t\\mathbb{V}[K^{\\ell,i}_{h,o;s,t}] = \\frac{2}{ (c_\\ell + h_\\ell) (2k+1)^2}.\n\t\\end{equation}\n\t\\item[Kaiming's initialization]\n\t\\begin{equation}\\label{key}\n\t\\mathbb{V}[K^{\\ell,i}_{h,o;s,t}] = \\frac{2}{c_\\ell (2k+1)^2}.\n\t\\end{equation}\n\\end{description}\n\nHere we can take this Kaiming's initialization as:\n\\begin{itemize}\n\t\\item Double the Xavier's choice, and get\n\t\\begin{equation}\\label{key}\n\t\\mathbb{V}[K^{\\ell,i}_{h,o;s,t}] = \\frac{4}{(c_\\ell + h_\\ell )(2k+1)^2}.\n\t\\end{equation}\n\t\\item Then pick $c_\\ell$ or $h_\\ell$ for final result\n\t\\begin{equation}\\label{key}\n\t\\mathbb{V}[K^{\\ell,i}_{h,o;s,t}] = \\frac{4}{(c_\\ell + h_\\ell )(2k+1)^2} = \\frac{2}{c_\\ell (2k+1)^2}.\n\t\\end{equation}\n\\end{itemize}\n\nAnd they have the both uniform and normal distribution type.\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.45\\linewidth]{converge_22layers}\n\t\\end{center}\n\t\\caption{The convergence of a \\textbf{22-layer} large model. The x-axis is the number of training epochs. The y-axis is the top-1 error of 3,000 random val samples, evaluated on the center crop. Use ReLU as the activation for both cases. Both Kaiming's initialization (red) and ``\\emph{Xavier's}'' (blue) \\cite{glorot2010understanding} lead to convergence, but Kaiming's initialization starts reducing error earlier.}\n\t\\label{fig:converge_22layers}\n\t%\\end{figure}\n\t%\\begin{figure}[t]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.45\\linewidth]{converge_30layers}\n\t\\end{center}\n\t\\caption{The convergence of a \\textbf{30-layer} small model (see the main text). Use ReLU as the activation for both cases. Kaiming's initialization (red) is able to make it converge. But ``\\emph{Xavier's}'' (blue) \\cite{glorot2010understanding} completely stalls - It is also verified that that its gradients are all diminishing. It does not converge even given more epochs.}\n\t\\label{fig:converge_30layers}\n\\end{figure}\n\nGiven a 22-layer model, in cifar10 the convergence with Kaiming's initialization is faster than Xavier's, \nbut both of them are able to converge and the validation accuracies with two different initialization \nare about the same(error is 33.82,33.90).\n\nWith extremely deep model with up to 30 layers, \nKaiming's initialization is able to make the model convergence. On the contrary, Xavier's method completely stalls the learning.\n\n\n\\section{Batch Normalization in DNN and CNN}\n\\subsection{Recall the original DNN model}\nConsider the classical (fully connected)  artificial deep neural network (DNN) $f^L$,\n\\begin{equation}\\label{nn}\n\\begin{cases}\nf^1&= \\theta^1 (x) := W^1 x+b^1,\\\\\nf^\\ell &= \\theta^{\\ell} \\circ \\sigma (f^{\\ell-1}) :=W^\\ell  \\sigma (f^{\\ell-1}) +b^\\ell,\\ \\ell=2,...,L.\n\\end{cases}\n\\end{equation}\nwhere $x\\in\\mathbb{R}^n$ is the input vector, $\\sigma$ is a non-linear function (activation).  \n\n\n\\subsection{``Real'' Batch Normalization and ``new'' model}\n\\paragraph{Definition of BN operation based on the batch}\nFollowing the idea in normalization, we consider that we have the all\ntraining data as\n\\begin{equation}\\label{eq:trainingdata}\n(X,Y) := \\{x_i, y_i\\}_{i=1}^N.\n\\end{equation}\n\nSince the normalization is applied to\neach activation independently, let us focus on a particular activation $ [f^\\ell]_k$ and omit $k$ as $f^\\ell$ for clarity. \nWe have $N$ values of this activation\nin the batch,\n$$ X=\\{x_1, \\cdots, x_N\\}.$$ \nLet the normalized values be\n$\\hat f^\\ell$, and their linear transformations be $\\tilde f^\\ell$. \n\\begin{equation}\\label{def:BNeq}\n\\begin{aligned}\n\\mu^\\ell_{ X} & \\leftarrow \\mathbb{E}_{x \\sim X} [f^\\ell(x)] =  \\frac{1}{N}\\sum_{i=1}^N f^\\ell(x_i) & \\text{ batch mean}& \\\\\n\\sigma^\\ell_{ X} & \\leftarrow \\mathbb{E}_{x \\sim X}  \\left[(f^\\ell(x)-\\mathbb{E}_{x \\sim X}[ f^\\ell(x)])^2 \\right] = \\frac{1}{N}\\sum_{i=1}^N (f^\\ell(x_i)-\\mu_{ X})^2 &  \\text{ batch variance}&\\\\\n\\hat f^\\ell (x) & \\leftarrow \\frac{f^\\ell(x)-\\mu^\\ell_{ X}}{\\sqrt{\\sigma^\\ell_{ X}+\\epsilon}}   &\\text{ normalize}&\\\\\n\\tilde f^\\ell(x)  & \\leftarrow \\gamma^\\ell \\hat f^\\ell (x) + \\beta^\\ell \n&\\text{ scale and shift}&\n\\end{aligned}\n\\end{equation}\nHere we note that all these operations in the previous equation are defined by element-wise.\nThen at last, we define the BN operation based on the batch set as\n\\begin{equation}\\label{eq:BNop}\n{\\rm BN}_{X}({f^\\ell(x)}) = \\tilde f^\\ell(x) := \\gamma^\\ell  \\frac{f^\\ell(x)-\\mu^\\ell_{ X}}{\\sqrt{\\sigma^\\ell_{ X}+\\epsilon}}  + \\beta^\\ell  ,\n\\end{equation}\nwhere $\\tilde f^\\ell(x)$, $\\mu^\\ell_{ X}$ and $\\sigma^\\ell_{ X}$  are given above.\n\n\\paragraph{``New\" model for BN}\nIn summary, we have the new DNN model with BN as:\n\\begin{equation}\\label{nn-BN0}\n\\begin{cases}\n\\tilde f^1(x_i)&= (\\theta^1 (x_i) ),\\\\\n\\tilde f^\\ell &= \\theta^{\\ell} \\circ \\sigma \\circ {\\rm BN}_{ X}(\\tilde f^{\\ell-1}), \\quad  \\ell=2,...,L.\n\\end{cases}\n\\end{equation}\n%Here we would like to notice that all these input data \n%$x_i \\in X$, it is already normalized over all the original data set with \n%the same fashion.\n%Thai is to say\n%$$\n%x_i = {\\rm BN}_{\\bar X}(\\bar x_i),\n%$$\n%for the original data $\\bar x_i \\in \\bar X$.\n\nFor a more comprehensive notation, \nwe can use the next notation\n\\begin{equation}\n\\sigma_{\\rm BN} := \\sigma \\circ {\\rm BN}_{ X}.\n\\end{equation}\n\nHere one thing is important that we need to mention is that because of the new\nscale $\\gamma^\\ell$ and shift $\\beta^\\ell$ added after the BN operation. \nWe can remove the basis $b^\\ell$ in $\\theta^\\ell$, thus to say the real model we will compute should be\n\\begin{equation}\\label{nn-BN}\n\\begin{cases}\n\\tilde f^1(x_i)&= W^1 x_i ,\\\\\n\\tilde f^\\ell &= W^{\\ell}  \\sigma_{\\rm BN}(\\tilde f^{\\ell-1}), \\quad  \\ell=2,...,L.\n\\end{cases}\n\\end{equation}\n\nCombine the two definition, we note\n\\begin{equation}\n\\tilde \\Theta := \\{W, \\gamma, \\beta\\},\n\\end{equation}\nwhere\n$W = \\{W^1, \\cdots, W^l \\}$, $\\gamma := \\{\\gamma^2, \\cdots, \\gamma^L\\}$ and $\\beta := \\{\\beta^2, \\cdots, \\beta^L\\}$.\n\n\nFinally, we have the loss function as:\n\\begin{equation}\\label{eq:loss-BN}\n\\mathcal L(\\tilde \\Theta) = \\mathbb{E}_{(x,y)\\sim (X,Y)} \\approx \\frac{1}{N}\\sum_{i=1}^N \\ell(\\tilde f^L(x_i; \\tilde \\Theta), y_i).\n\\end{equation}\n\nA key observation in \\eqref{eq:loss-BN} and the new BN model \\eqref{nn-BN} is that\n\\begin{equation}\\label{eq:threeExpectation}\n\\begin{aligned}\n\\mu^\\ell_{ X} \n%& \\leftarrow \\frac{1}{N}\\sum_{i=1}^N f^\\ell(x_i)  \n&= \\mathbb{E}_{x \\sim X} [f^\\ell(x)],\\\\\n\\sigma^\\ell_{ X}\n%& \\leftarrow \\frac{1}{N}\\sum_{i=1}^N (f^\\ell(x_i)-\\mu_{ X})^2  \n&=  \\mathbb{E}_{x \\sim X}  \\left[(f^\\ell(x)-\\mathbb{E}_{x \\sim X}[ f^\\ell(x)])^2 \\right], \\\\\n\\mathcal L(\\tilde \\Theta) \n%&= \\sum_{i=1}^N L(\\tilde f^J(x_i; \\tilde \\Theta), y_i)   \n&=  \\mathbb{E}_{(x,y)\\sim (X,Y)}  \\left[\\ell(\\tilde f^L(x_i; \\tilde \\Theta), y_i) \\right].\n\\end{aligned}\n\\end{equation}\nHere we need to mention that\n$$\nx \\sim X\n$$\nmeans $x$ subject to the discrete distribution of all data $X$. \n%For example:\n%$$\n%{p}_{X}(x = x_i) = \\frac{1}{N}.\n%$$\n%or more mathematically we can use the Dirac distribution as:\n%$$\n%p_{X}(x) = \\frac{1}{N} \\sum_{i=1}^N\\delta(x - x_i).\n%$$\n\n\n%Similar with the case from (batch) gradient descent to stochastic gradient descent.\n%Therefore, BN makes the second simplification: since we use mini-batches \n%in stochastic gradient training, {\\em each mini-batch produces estimates of the mean and variance} of each\n%activation for whole batch. \n\n\\subsection{BN: some ``modified\" SGD on new batch normalized model}\nFollowing the key observation in \\eqref{eq:threeExpectation}, and recall the \nsimilar case in SGD, we do the the sampling trick in \\eqref{eq:loss-BN} and\nobtain the mini-batch SGD:\n\\begin{equation}\\label{eq:mini-batch-sample}\nx \\sim X \\approx x \\sim \\mathcal B,\n\\end{equation}\nhere $\\mathcal B$ is a mini-batch of batch $X$ with $\\mathcal B \\subset X$.\n\nHowever, for problem in \\eqref{eq:loss-BN}, it is very difficult to find some \nsubtle sampling method because of the composition of $\\mu^\\ell_{\\mathcal X}$\nand $[\\sigma^\\ell_{\\mathcal X}]^2 $. However, one simple way for sampling \n\\eqref{eq:loss-BN} can be chosen as taking \\eqref{eq:mini-batch-sample} for\nall the expectation case in \\eqref{eq:loss-BN} and \\eqref{eq:threeExpectation}.\n\nThis is to say, in training process ($t$-th step for example), once we choose $B_t \\subset X$\nas the mini-batch, then the model becomes\n\\begin{equation}\\label{nn-BN-training}\n\\begin{cases}\n\\tilde f^1(x_i)&= W^1 x_i ,\\\\\n\\tilde f^\\ell &= W^{\\ell}  \\sigma_{\\rm BN}(\\tilde f^{\\ell-1}), \\quad  \\ell=2,...,L.\n\\end{cases}\n\\end{equation}\nwhere\n\\begin{equation}\n\\sigma_{\\rm BN} := \\sigma \\circ {\\rm BN}_{\\mathcal B_t},\n\\end{equation}\nor we can say that $X$ is replaced by $\\mathcal B_t$ in this case.\n\nHere ${\\rm BN}_{\\mathcal B_t}$ is defined by\n\\begin{equation}\\label{def:BNeq-traning}\n\\begin{aligned}\n\\mu^\\ell_{\\mathcal B_t} & \\leftarrow \\frac{1}{m}\\sum_{i=1}^m f^\\ell(x_i) & \\text{ mini-batch mean}& \\\\\n\\sigma^\\ell_{\\mathcal B_t} & \\leftarrow \\frac{1}{m}\\sum_{i=1}^m (f^\\ell(x_i)-\\mu_{\\mathcal B_t})^2 &  \\text{ mini-batch variance}&\\\\\n\\hat f^\\ell (x) & \\leftarrow \\frac{f^\\ell(x)-\\mu^\\ell_{\\mathcal B_t}}{\\sqrt{\\sigma^\\ell_{\\mathcal B_t}+\\epsilon}}   &\\text{ normalize}&\\\\\n{\\rm BN}_{\\mathcal B_t}(\\tilde f^{\\ell}) := \\tilde f^\\ell(x) & \\leftarrow \\gamma^\\ell \\hat f^\\ell (x) + \\beta^\\ell \n&\\text{ scale and shift}&\n\\end{aligned}\n\\end{equation}\n\n\nHere BN operation introduce some new parameters as $\\gamma$ and $\\beta$. \nThus to say, for training phase, if we choose mini-batch as $\\mathcal B_t$ in $t$-th training\nstep, we need to take gradient as\n\\begin{equation}\n\\frac{1}{m}\\nabla_{\\tilde \\Theta} \\sum_{i \\in \\mathcal B_t} \\ell(\\tilde f^L(x_i; \\tilde \\Theta), y_i),\n\\end{equation}\nwhich needs us the to take gradient for $\\mu_{B}^\\ell$ or $[\\sigma_B^\\ell]^2$\nw.r.t $w^i$ for $i \\le \\ell$.\n\n\n{\\bf Questions:} To derive the new gradient formula for BN step because of the fact that \n$$\n\\mu^\\ell_{\\mathcal B_t}, \\quad \\text{and} \\quad \\sigma^\\ell_{\\mathcal B_t},\n$$\ncontain the output of $\\tilde f^{\\ell-1}$. \n\nThis is exact the batch normalization method described in \\cite{ioffe2015batch}.\n\n\n\\subsection{Testing phase in Batch-Normalized DNN}\nOne key problem is that, in the BN operator, we need to compute the mean and variance \nin a data set (batch or mini-batch). However, in the inference step, we just input one data \ninto this DNN, how to compute the BN operator in this situation. \n\nActually,  the $\\gamma$ and $\\beta$ parameter is fixed after training, the only problem is\nto compute the mean $\\mu$ and variance $\\sigma^2$. \nAll the mean $ \\mu_{\\mathcal B_t}  $ and variance $\\sigma^2_{\\mathcal B_t} $ during the training phase \nare just the approximation of the mean and variance of whole batch i.e.  $ \\mu_{X}  $ and $\\sigma^2_{X}$ \nas shown in \\eqref{eq:threeExpectation}. \n\nOne natural idea might be just use the BN operator w.r.t to the whole training data set, thus to say\njust compute $\\mu_X$ and $\\sigma_X^2$ by definition in \\eqref{def:BNeq}.\n\n\nHowever, there are at least the next few problems:\n\\begin{itemize}\n\t\\item computation cost,\n\t\\item ignoring the statistical approximation (don't make use of the $ \\mu_{\\mathcal B_t}  $ and  $\\sigma^2_{\\mathcal B_t} $ in training phase).\n\\end{itemize}\n\nConsidering that we have the statistical approximation for $ \\mu_{X}  $ and $\\sigma^2_{X}$\nduring each SGD step, moving average might be a more straightforward way.\nThus two say, we define the $\\mu^\\ell$ and $[\\sigma^\\ell]^2$ for the inference (test) phase\nas\n\\begin{equation}\n\\mu^\\ell = \\frac{1}{T}\\sum_{t=1}^T \\mu^\\ell_{\\mathcal B_t}, \n\\quad \\sigma^\\ell =\\frac{1}{T} \\frac{m}{m-1}\\sum_{t=1}^T\\sigma^\\ell_{\\mathcal B_t}.\n\\end{equation}\nHere we take Bessel's correction for unbiased variance.\nThe above moving average step is found in the original paper of BN in \\cite{ioffe2015batch}. \n\nAnother way to do this is to call the similar idea in momentum. \nAt each time step we update the running averages for mean and variance using an exponential decay based on the momentum parameter:    \n\\begin{equation}\n\\begin{aligned}\n\\mu^\\ell_{\\mathcal B_t} &=\\alpha \\mu^\\ell_{\\mathcal B_{t-1}} + (1-\\alpha)\\mu^\\ell_{\\mathcal B_t} \\\\\n\\sigma^\\ell_{\\mathcal B_t} &=\\alpha \\sigma^\\ell_{\\mathcal B_{t-1}} + (1-\\alpha)\\sigma^\\ell_{\\mathcal B_t},\n\\end{aligned}\n\\end{equation}\n$\\alpha$ is close to $1$, we can take it as $0.9$ generally. Then we all take bath mean and variance as\n$\\mu^\\ell_X  \\approx \\mu^\\ell_{\\mathcal B_T}$  and $\\sigma^\\ell_X  \\approx \\sigma^\\ell_{\\mathcal B_T}$.\n\nMany people argue that the variance here should also use Bessel's correction.\n\n\\subsection{Batch Normalization for CNN}\nOne key idea in BN is to do normalization with each scalar features (neurons) \nseparately along a mini-batch. \nThus to say, we need one to identify what is neuron in CNN. \nThis is a historical problem, some people think neuron in CNN\nshould be the pixel in each channel some thing that each channel is just \none neuron. BN choose the later one. \n{\\bf One (most ?) important reason for this choice is the fact of computation cost. }\n\nFor convolutional layers, BN additionally wants the normalization\nto  obey the convolutional property -- so that different elements\nof the same feature map, at different locations, are normalized in the\nsame way. \nTo compute $\\mu^\\ell_{\\mathcal B_t}$, we take mean of the set of all values in a feature map across both the\nelements of a mini-batch and spatial locations -- so for a mini-batch\nof size $m$ and feature maps of size $m_\\ell \\times n_\\ell$ (image geometrical size), \nwe use the effective mini-batch of size $ m m_\\ell n_\\ell$. \nWe learn a pair of parameters $\\gamma_k$ and $\\beta_k$ per feature map (k-th channel), rather than per activation.\n\n\nFor simplicity, then have the following BN scheme for CNN\n\\begin{equation}\\label{def:BNeq-traningCNN}\n\\begin{aligned}\n[\\mu^\\ell_{\\mathcal B_t}]_{j} & \\leftarrow \\frac{1}{m \\times m_\\ell \\times n_\\ell }\\sum_{i=1}^m \\sum_{1\\le s\\le m_\\ell, 1\\le t \\le n_\\ell} [f^\\ell(x_i)]_{j;st} \n&&\\text{ mean on channel }j \\\\\n[\\sigma^\\ell_{\\mathcal B_t}]_{j} & \\leftarrow \\frac{1}{m \\times m_\\ell \\times n_\\ell }\\sum_{i=1}^m \\sum_{1\\le s\\le m_\\ell, 1\\le t \\le n_\\ell}\n([f^\\ell(x_i)]_{j;st}-[\\mu^\\ell_{\\mathcal B_t}]_j)^2   &&\\text{ variance on channel }j\\\\\n[\\hat f^\\ell (x)]_{j;st} & \\leftarrow \\frac{[f^\\ell(x)]_{j,st}-[\\mu^\\ell_{\\mathcal B_t}]_j}{\\sqrt{[\\sigma^\\ell_{\\mathcal B_t}]_j+\\epsilon}}   &&\\text{ normalize }\\\\\n[{\\rm BN}_{\\mathcal B_t}(\\tilde f^{\\ell})]_{j;st} &:= [\\tilde f^\\ell(x)]_{j;st}  \\leftarrow [\\gamma^\\ell]_j [\\hat f^\\ell (x)]_{j;st} + [\\beta^\\ell]_{j} \n&&\\text{ scale and shift on channel}\n\\end{aligned}\n\\end{equation}\n", "meta": {"hexsha": "1b65cdbb05262a401fc7b18b2a36e8cc090a4242", "size": 28015, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Init_BN_intro.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/Init_BN_intro.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/Init_BN_intro.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.8958333333, "max_line_length": 418, "alphanum_fraction": 0.6819560949, "num_tokens": 9962, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.8947894632969137, "lm_q1q2_score": 0.819725223316565}}
{"text": "\\section{Exponentiation by Binary Decomposition}\\label{sec:decomposition}\nThis section covers the computation of $x^n$ for a nonnegative integer $n$\nas in section \\texttt{11-3} of \\emph{Hackers's Delight}\n\\cite{Warren:2012:HD:2462741} (p. \\texttt{288}).\nThe base $x$ can be of any type\nwith an associative operation $\\cdot$ defined on it.\nTherefore the method presented here\nis not only applicable to multiplication on integers and floating points,\nbut also i.e.\\ concatenation of strings\n($(\\text{'ab'})^3 = \\text{'ababab'}$).\n\nThe goal is to reduce the number of required operations\nwith the most primitive approach taking $(n-1)$ steps.\nWhatever the operation may be,\nit will be referred to as ``multiplication'' below.\n\nUsing the identities $x^{(a+b)} = x^a \\cdot x^b$\nand $(x^a)^b = x^{(a \\cdot b)}$,\na decomposition of the exponent $n$ can be achieved\nand thereby the number of required multiplications is reduced up to a minimum.\nConsider these examples\\footnote{\nHenry Warren \\cite{Warren:2012:HD:2462741} mentions $x^{15} = (x^3)^5$\nwhich requires 6 (one more) multiplications.\nThe decomposition shown here was selected as a replacement to demonstrate that\nsimply chaining prime factors isn't necessarily the optimal solution.\n}:\n\\[ x^{15} = x^3 \\cdot ((x^3)^2)^2 \\hspace{4ex} x^{27} = ((x^3)^3)^3\u00a0\\]\n\n\\begin{quotation}\\noindent\n``Perhaps surprisingly, there is no known simple method that, for all $n$,\nfinds the optimal sequence of multiplications to compute $x^n$.\nThe only known methods involve an extensive search.''\\\\\n\\phantom{a} \\hfill -- Hacker's Delight\n\\cite{Warren:2012:HD:2462741} (p. \\texttt{289})\n\\end{quotation}\n\nThis circumstance leads to the question, which decomposition\nis simple to obtain and a relatively good approximation of the optimum.\nThe binary representation of $n$ is cheap\nwhen already operating in a low level coding environment.\nConsider the same examples as before:\n\\[ x^{15} = x^8 \\cdot x^4 \\cdot x^2 \\cdot x \\hspace{4ex}\nx^{27} = x^{16} \\cdot x^8 \\cdot x^2 \\cdot x \\]\n\nIn comparison, binary decomposition takes\nfor $n := 15$ a total of $6$ ($\\log_2 8 + 3$)\ninstead of $5$ ($2 + 1 + 1 + 1$) operations\nand for $n := 27$ a total of $7$ ($\\log_2 16 + 3$)\ninstead of $6$ ($2 + 2 + 2$) multiplications.\n\nThe algorithm for this computation\\footnote{\nSee \\url{https://hackersdelight.org/hdcodetxt/iexp.c.txt}\n\\cite{Warren:HD:Website}\n} scans the binary representation from right to left,\nby isolating the least significant bit (\\lstinline$n&1$)\nand right-shifting it (\\lstinline$n = n >> 1$).\nFor every new bit, a factor \\lstinline$p$ (that starts as $x$)\nis squared and therefore equals $x, x^2, x^4, \\dots$ throughout the cycles.\nIt is multiplied onto the final result \\lstinline$y$ (which starts as $1$)\nif and only if the bit in that cycle is \\lstinline$1$.\n", "meta": {"hexsha": "bfee6318be4435294780c254eca3eecd90560167", "size": 2799, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/A-decomposition.tex", "max_stars_repo_name": "LucasForster/hackers-delight", "max_stars_repo_head_hexsha": "28a8558a9e230bf614b9ae41e1d9e0b4a8a3e1a7", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-11T12:10:40.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-11T12:10:40.000Z", "max_issues_repo_path": "content/A-decomposition.tex", "max_issues_repo_name": "LucasForster/hackers-delight", "max_issues_repo_head_hexsha": "28a8558a9e230bf614b9ae41e1d9e0b4a8a3e1a7", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-25T23:16:11.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-25T23:16:11.000Z", "max_forks_repo_path": "content/A-decomposition.tex", "max_forks_repo_name": "LucasForster/hackers-delight", "max_forks_repo_head_hexsha": "28a8558a9e230bf614b9ae41e1d9e0b4a8a3e1a7", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-12-16T11:05:07.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-23T22:08:23.000Z", "avg_line_length": 45.8852459016, "max_line_length": 78, "alphanum_fraction": 0.7277599143, "num_tokens": 834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.8947894541786198, "lm_q1q2_score": 0.8197252149632085}}
{"text": "\\section{Angles between planes and lines}\\label{s:angles}\nIn this section, we figure out how to check whether lines and planes are parallel or perpendicular, and then how to find the line perpendicular to a plane going through a given point, and vice versa. All those operations are very easy with our representation of planes and lines.\n\n\\subsection{Between two planes}\nThe angle between two planes is equal to the angle between their normals. Since usually two angles of distinct amplitudes $\\theta$ and $\\pi-\\theta$ are formed, we take the smaller of the two, in $[0,\\frac{\\pi}{2}]$.\n\n\\centerFig{para-perp-0}\n\nWe can find it with the following code. We take the minimum with 1 to avoid \\lstinline|nan| in case of imprecisions.\n\\begin{lstlisting}\ndouble smallAngle(p3 v, p3 w) {\n    return acos(min(abs(v|w)/abs(v)/abs(w), 1.0));\n}\ndouble angle(plane p1, plane p2) {\n    return smallAngle(p1.n, p2.n);\n}\n\\end{lstlisting}\n\nIn particular, we can check whether two planes are parallel/perpendicular by checking if their normals are parallel/perpendicular:\n\\begin{lstlisting}\nbool isParallel(plane p1, plane p2) {\n    return p1.n*p2.n == zero;\n}\nbool isPerpendicular(plane p1, plane p2) {\n    return (p1.n|p2.n) == 0;\n}\n\\end{lstlisting}\n\n\\subsection{Between two lines}\nThe situation with lines is exactly the same: their angle is equal to the angle between their direction vectors. Note that the lines aren't necessarily in the same plane, so the angle is taken as if they were moved until they touch.\n\n\\centerFig{para-perp-1}\n\n\\begin{lstlisting}\ndouble angle(line3d l1, line3d l2) {\n    return smallAngle(l1.d, l2.d);\n}\nbool isParallel(line3d l1, line3d l2) {\n    return l1.d*l2.d == zero;\n}\nbool isPerpendicular(line3d l1, line3d l2) {\n    return (l1.d|l2.d) == 0;\n}\n\\end{lstlisting}\n\n\\subsection{Between a plane and a line}\nThe situation when considering a plane and a line is a bit different.\nLet's consider a plane $\\Pi$ of normal $\\vv{n}$ and a line $l$ of direction vector $\\vv{d}$.\nWhen they are perpendicular, $\\vv{n}$ is parallel to $\\vv{d}$, and inversely when they are parallel, $\\vv{n}$ is perpendicular to $\\vv{d}$. In general, if the angle between $\\vv{n}$ and $\\vv{d}$ is $\\theta \\in [0,\\frac{\\pi}{2}]$, then the angle between the plane and the line is $\\frac{\\pi}{2}-\\theta$.\n\n\\centerFig{para-perp-2}\n\n\\begin{lstlisting}\ndouble angle(plane p, line3d l) {\n    return M_PI/2 - smallAngle(p.n, l.d);\n}\nbool isParallel(plane p, line3d l) {\n    return (p.n|l.d) == 0;\n}\nbool isPerpendicular(plane p, line3d l) {\n    return p.n*l.d == zero;\n}\n\\end{lstlisting}\n\n\\subsection{Perpendicular through a point}\nThe line perpendicular to a plane $\\Pi$ of normal $\\vv{n}$ and going through a point $O$ is simply the line going through $O$ and whose direction vector is $\\vv{n}$, or equivalently the line going through $O$ and $O+\\vv{n}$.\n\n\n\\centerFig{para-perp-3}\n\n\\begin{lstlisting}\nline3d perpThrough(plane p, p3 o) {return line(o, o+p.n);}\n\\end{lstlisting}\n\nThe plane perpendicular to a line $l$ of direction vector $\\vv{d}$ and going through a point $O$ is simply the plane containing $O$ and whose normal is $\\vv{d}$.\n\n\\centerFig{para-perp-4}\n\n\\begin{lstlisting}\nplane perpThrough(line3d l, p3 o) {return plane(l.d, o);}\n\\end{lstlisting}\n", "meta": {"hexsha": "3c42cb272770165bb991e3bd4a9f3d1a64bcd112", "size": 3243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/3d/para-perp.tex", "max_stars_repo_name": "cbarnson/UVa", "max_stars_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_stars_repo_licenses": ["Unlicense", "MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-07T17:00:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-05T02:08:35.000Z", "max_issues_repo_path": "archives/codelibraries/cp-geo-master/3d/para-perp.tex", "max_issues_repo_name": "cbarnson/UVa", "max_issues_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_issues_repo_licenses": ["Unlicense", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "archives/codelibraries/cp-geo-master/3d/para-perp.tex", "max_forks_repo_name": "cbarnson/UVa", "max_forks_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_forks_repo_licenses": ["Unlicense", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.5487804878, "max_line_length": 302, "alphanum_fraction": 0.7181621955, "num_tokens": 936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629193, "lm_q2_score": 0.8688267813328976, "lm_q1q2_score": 0.8196056425330709}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} Determine which matrices are in {\\rref}.\n\n  \\begin{enumerate}\n  \\item $\\begin{mymatrix}{rrr}\n      1 & 2 & 0 \\\\\n      0 & 1 & 7\n    \\end{mymatrix}$\n\n  \\item $\\begin{mymatrix}{rrrr}\n      1 & 0 & 0 & 0 \\\\\n      0 & 0 & 1 & 2 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}$\n\n  \\item $\\begin{mymatrix}{rrrrrr}\n      1 & 1 & 0 & 0 & 0 & 5 \\\\\n      0 & 0 & 1 & 2 & 0 & 4 \\\\\n      0 & 0 & 0 & 0 & 1 & 3\n    \\end{mymatrix}$\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item This one is not.\n    \\item This one is.\n    \\item This one is.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Reduce each of the matrices from Exercise~\\ref{ex:rr-ef} to {\\rref}.\n\\end{ex}\n\n\\begin{ex} Use Gauss-Jordan elimination to solve the system of equations\n  $-8x+2y+5z=18,-8x+3y+5z=13$, and $-4x+y+5z=19$.\n  \\begin{sol}\n    Solution is: $\\mat{x=-1,y=-5,z=4}$\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex} Use Gauss-Jordan elimination to solve the system of equations $3x-y-2z=3$,\n  $y-4z=0$, and $-2x+y=-2$.\n  \\begin{sol}\n    Solution is: $\\mat{x=2t+1,y=4t,z=t}$\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex} Use Gauss-Jordan elimination to solve the system of equations\n  $-9x+15y=66,-11x+18y=79$, $-x+y=4$, and $z=3$.\n  \\begin{sol}\n    Solution is: $\\mat{x=1,y=5,z=3}$\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex} Use Gauss-Jordan elimination to solve the system of equations $-19x+8y=-108$,\n  $-71x+30y=-404$, $-2x+y=-12$, $4x+z=14$.\n  \\begin{sol}\n    Solution is: $\\mat{x=4,y=-4,z=-2}$\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Solve the following two systems of equations simultaneously, by\n  using a single augmented matrix with two constant vectors.\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l@{~}}\n      x  + 2y -  z &=& 0 \\\\\n      2x + 3y +  z &=& 3 \\\\\n      x  -  y + 2z &=& 3 \\\\\n    \\end{array}\n    \\quad\\quad\n    \\begin{array}{r@{~}c@{~}l@{~}}\n      x  + 2y -  z &=& 1 \\\\\n      2x + 3y +  z &=& 7 \\\\\n      x  -  y + 2z &=& 4 \\\\\n    \\end{array}\n  \\end{equation*}\n\n  \\begin{sol}\n    The rank of the coefficient matrix is $3$, so both systems have a\n    unique solution. The solution of the first system is\n    $(x,y,z)=(1,0,1)$, and the solution of the second system is\n    $(x,y,z)=(1,1,2)$.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "42c1c15e99f7f4055a0292a396a7068560a7653e", "size": 2209, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/SystemsofEquations-GaussJordanElimination.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/SystemsofEquations-GaussJordanElimination.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/SystemsofEquations-GaussJordanElimination.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 24.8202247191, "max_line_length": 88, "alphanum_fraction": 0.5518334088, "num_tokens": 922, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.905989826094673, "lm_q1q2_score": 0.819604183301525}}
{"text": "\\chapter{Probability Distributions}\n\n\\section*{Exercise 2.1 $\\star$}\nVerify that the Bernoulli distribution (2.2) satisfies\nthe following properties\n\\begin{equation}\\label{eq:2.257}\\tag{2.257}\n    \\sum_{x=0}^{1} p(x | \\mu) = 1\n\\end{equation}\n\\vspace{-1em}\n\\begin{equation}\\label{eq:2.258}\\tag{2.258}\n    \\mathbb{E}[x] = \\mu\n\\end{equation}\n\\vspace{-1em}\n\\begin{equation}\\label{eq:2.259}\\tag{2.259}\n    \\text{var}[x] = \\mu(1 - \\mu)\n\\end{equation}\nShow that the entropy $H[x]$ of a Bernoulli distributed\nrandom binary variable $x$ is given by\n\\begin{equation}\\label{eq:2.260}\\tag{2.260}\n    H[x] = -\\mu \\ln \\mu - (1 - \\mu) \\ln(1 - \\mu)\n\\end{equation}\n\n\\vspace{1em}\n\n\\begin{proof}\n    The Bernoulli distribution is given by\n    \\begin{equation}\\label{eq:2.2}\\tag{2.2}\n        \\text{Bern}(x | \\mu) = \\mu^x (1 - \\mu)^{1-x}\n    \\end{equation}\n    The properties are easily verified:\n    \\[\n        \\sum_{x=0}^{1} p(x | \\mu) = p(x = 0 | \\mu) + p(x = 1 | \\mu)\n        = \\mu^0(1 - \\mu)^1 + \\mu^1(1 - \\mu)^0 = 1 \\tag{2.257}\n    \\] \n    \\[\n        \\mathbb{E}[x] = \\sum_{x=0}^{1} xp(x | \\mu)\n        = 0 \\cdot p(x = 0 | \\mu) + 1 \\cdot p(x = 1 | \\mu)\n        = \\mu \\tag{2.258}\n    \\] \n    \\[\n        \\text{var}[x] = \\mathbb{E}[x^2] - \\mathbb{E}[x]^2\n        = \\sum_{x=0}^{1} x^2 p(x|\\mu) - \\mu^2\n        = 0^2 \\cdot p(x = 0 | \\mu) + 1^2 \\cdot p(x = 1 | \\mu) - \\mu^2\n        = \\mu(1 - \\mu) \\tag{2.259}\n    \\] \n    The entropy is also straightforward to derive: \n    \\begin{align*}\n        H[x] = -\\sum_{x=0}^{1} p(x | \\mu) \\ln p(x | \\mu)\n        &= -p(x = 0 | \\mu)\\ln p(x = 0 | \\mu) - p(x = 1 | \\mu) \\ln p(x = 1 | \\mu) \\\\\n        &= -\\mu \\ln \\mu - (1 - \\mu) \\ln(1 - \\mu)\n    \\end{align*}\n\\end{proof}\n\n\\section*{Exercise 2.2 $\\star \\star$}\nThe form of the Bernoulli distribution given by ($\\ref{eq:2.2}$)\nis not symmetric between the two values of $x$. In some situations,\nit will be more convenient to use an equivalent formulation for which\n$x \\in \\{-1 , 1\\}$, in which case the distribution can be written\n\\begin{equation}\\label{eq:2.261}\\tag{2.261}\n    p(x | \\mu) = \\bigg(\\frac{1 - \\mu}{2}\\bigg)^{(1 - x)/2} \\bigg(\\frac{1 + \\mu}{2}\\bigg)^{(1 + x)/2}\n\\end{equation}\nwhere $\\mu \\in [-1, 1].$ Show that the distribution ($\\ref{eq:2.261}$) is normalized,\nand evaluate its mean, variance and entropy.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The distribution is normalized since\n    \\[\n        \\sum_{x} p(x | \\mu) = p(x = -1 | \\mu) + p(x = 1 | \\mu) \n        = \\frac{1 - \\mu}{2} + \\frac{1 + \\mu}{2} = 1\n    \\] \n    The other properties are also easily derived:\n    \\[\n        \\mathbb{E}[x] = \\sum_{x} xp(x | \\mu) \n        = p(x = 1 | \\mu) - p(x = -1 | \\mu)\n        = \\frac{1 + \\mu}{2} - \\frac{1 - \\mu}{2}\n        = \\mu\n    \\] \n    \\begin{align*}\n        \\text{var}[x] = \\mathbb{E}[x^2] - \\mathbb{E}[x]^2\n        &= \\sum_{x} x^2 p(x | \\mu) - \\mu^2\n        = p(x = -1 | \\mu) + p(x = 1 | \\mu) - \\mu^2 \\\\\n        &= \\frac{1+\\mu}{2} + \\frac{1-\\mu}{2} - \\mu^2\n        = (1 - \\mu)(1 + \\mu)\n    \\end{align*}\n\n    \\begin{align*}\n        H[x] = -\\sum_{x} p(x | \\mu) \\ln p(x | \\mu)\n        &= -p(x = -1 | \\mu) \\ln p(x = -1 | \\mu) - p(x = 1 | \\mu) \\ln p(x = 1 | \\mu) \\\\\n        &= -\\frac{1 - \\mu}{2} \\ln\\bigg(\\frac{1 - \\mu}{2}\\bigg)\n        - \\frac{1 + \\mu}{2} \\ln\\bigg(\\frac{1 + \\mu}{2}\\bigg)\n    \\end{align*}\n\\end{proof}\n\n\\section*{Exercise 2.3 $\\star \\star$}\nIn this exercise, we prove that the binomial distribution ($\\ref{eq:2.9}$)\nis normalized. First use the definition (2.10) of the number of combinations of\n$m$ identical objects chosen from a total of $N$ to show that\n\\begin{equation}\\label{eq:2.262}\\tag{2.262}\n    \\binom{N}{m} + \\binom{N}{m-1} = \\binom{N+1}{m}\n\\end{equation}\nUse this result to prove by induction the following result\n\\begin{equation}\\label{eq:2.263}\\tag{2.263}\n    (1 + x)^N = \\sum_{m=0}^{N} \\binom{N}{m}x^m\n\\end{equation}\nwhich is known as the $\\emph{binomial theorem}$, and which is valid \nfor all real values of $x$. \nFinally, show that the binomial distribution is normalized, so that\n\\begin{equation}\\label{eq:2.264}\\tag{2.264}\n    \\sum_{m=0}^{N} \\binom{N}{m} \\mu^m(1 - \\mu)^{N - m} = 1 \n\\end{equation}\nwhich can be done by first pulling out a factor $(1 - \\mu)^N$ out of the summation\nand then making use of the binomial theorem.\n\n\\begin{proof}\n    The binomial distribution is given by\n    \\begin{equation}\\label{eq:2.9}\\tag{2.9}\n        \\text{Bin}(m | N, \\mu) = \\binom{N}{m} \\mu^m (1-\\mu)^{N - m}\n    \\end{equation}\n    By using $(2.10)$, we prove ($\\ref{eq:2.262}$)\n    \\begin{align*}\n        \\binom{N}{m} + \\binom{N}{m - 1} \n        &= \\frac{N!}{(N - m)!m!} + \\frac{N!}{(N - m + 1)!(m - 1)!} \\\\\n        &= \\frac{(N - m + 1)N!}{(N - m + 1)!m!} + \\frac{mN!}{(N - m + 1)!m!} \\\\\n        &= \\frac{(N + 1)!}{(N - m + 1)!m!} \\\\\n        &= \\binom{N + 1}{m} \\tag{2.262}\n    \\end{align*}\n    We aim to prove ($\\ref{eq:2.263}$) by induction. The base \n    case for $N=1$ is obviously true since $$1+x = \\binom{1}{0} + \\binom{1}{1}x$$\n    Now, suppose that the case for $N=k \\in \\mathbb{N}^*$ is true, i.e.\n    \\[\n        (1 + x)^k = \\sum_{m=0}^{k} \\binom{k}{m} x^m \n    \\] \n    By using this and $(\\ref{eq:2.262})$, we show that \n    \\begin{align*}\n        (1 + x)^{k + 1} \n        &= (1 + x) \\sum_{m=0}^{k} \\binom{k}{m} x^m \\\\\n        &= \\sum_{m=0}^{k} \\binom{k}{m} x^m + \\sum_{m=0}^{k} \\binom{k}{m} x^{m+1} \\\\\n        &= 1 + \\sum_{m=1}^{k} \\binom{k}{m} x^m + \\sum_{m=1}^{k + 1} \\binom{k}{m - 1} x^m \\\\\n        &= \\binom{k+1}{0} + \\binom{k+1}{k+1}x^{k + 1} + \\sum_{m=1}^{k} \\bigg\\{\\binom{k}{m} + \\binom{k}{m-1}\\bigg\\}x^m \\\\\n        &= \\sum_{m=0}^{k+1} \\binom{k+1}{m} x^m \n    \\end{align*}\n    which by induction proves that $(\\ref{eq:2.263})$ is indeed true. \n\n    Finally, we use this result to show that the Binomial distribution is normalized:\n    \\begin{align*}\n        \\sum_{m=0}^{N} \\binom{N}{m} \\mu^m(1 - \\mu)^{N - m}\n        &= (1 - \\mu)^N \\sum_{m=0}^{N} \\binom{N}{m} \\bigg(\\frac{\\mu}{1 - \\mu}\\bigg)^m \\\\\n        &= (1 - \\mu)^N \\bigg(1 + \\frac{\\mu}{1 - \\mu}\\bigg)^N \\\\\n        &= 1 \\tag{2.264}\n    \\end{align*}\n\\end{proof}\n\n\\section*{Exercise 2.4 $\\star \\star$}\nShow that the mean of the binomial distribution is given by\n($\\ref{eq:2.11}$). To do this, differentiate both sides of the normalization condition\n($\\ref{eq:2.264}$) with respect to $\\mu$ and then rearrange to obtain an\nexpression for the mean of $m$. Similarly, by differentiating ($\\ref{eq:2.264}$)\ntwice with respect to $\\mu$ and making use of the result ($\\ref{eq:2.11}$) for the mean\nof the binomial distribution prove the result (2.12) for the variance of the binomial.\n\n\\begin{proof}\n    We start by differentiating both sides of ($\\ref{eq:2.264}$)\n    with respect to $\\mu$:\n    \\begin{align*}\n        \\pdv{\\mu} \\sum_{m=0}^{N} \\binom{N}{m} \\mu^m(1-\\mu)^{N - m} &= 0 \\\\\n        \\sum_{m=0}^{N} \\binom{N}{m} \\mu^m(1 - \\mu)^{N - m}\n        \\bigg(\\frac{m}{\\mu} + \\frac{m-N}{1-\\mu}\\bigg) &= 0 \\\\\n        \\bigg(\\frac{1}{\\mu} + \\frac{1}{1 - \\mu}\\bigg)\n        \\sum_{m=0}^{N} m \\binom{N}{m} \\mu^m(1 - \\mu)^{N - m} \n        - \\frac{N}{1-\\mu} \\sum_{m=0}^{N} \\binom{N}{m} \\mu^m(1 - \\mu)^{N - m} &= 0\n    \\end{align*}\n    We recognize the expression of the binomial distribution and\n    use the fact that it is normalized, to obtain:\n    \\begin{align*}\n        \\bigg(\\frac{1}{\\mu} + \\frac{1}{1 - \\mu}\\bigg)\n        \\sum_{m=0}^{N} m\\text{Bin}(m | N, \\mu) \n        &= \\frac{N}{1-\\mu} \\sum_{m=0}^{N} \\text{Bin}(m | N, \\mu) \\\\\n        \\bigg(\\frac{1 - \\mu}{\\mu} + 1\\bigg) \\mathbb{E}[m] &= N\n    \\end{align*}\n    which directly gives us the desired result, that is\n    \\begin{equation}\\label{eq:2.11}\\tag{2.11}\n        \\mathbb{E}[m] = \\sum_{m=0}^{N} m\\text{Bin}(m | N, \\mu) = N\\mu\n    \\end{equation}\n\n    To derive the variance, we differentiate twice both sides\n    of ($\\ref{eq:2.264}$), so\n    \\begin{align*}\n        \\pdv[2]{\\mu} \\sum_{m=0}^{N} \\binom{N}{m} \\mu^m(1 - \\mu)^{N - m} &= 0 \\\\\n        \\frac{1}{\\mu^2(1 - \\mu)^2} \\sum_{m=0}^{N} \\text{Bin}(m | N, \\mu) \n            \\{m^2 + m(2\\mu - 2N\\mu - 1) + (N - 1)N\\mu^2\\} &=0 \\\\\n        \\sum_{m=0}^{N} \\text{Bin}(m | N, \\mu) (m - N\\mu)^2\n            + (2\\mu - 1)\\sum_{m=0}^{N} m\\text{Bin}(m | N, \\mu)\n            - N\\mu^2 \\sum_{m=0}^{N} \\text{Bin}(m | N, \\mu) &= 0 \\\\\n        \\text{var}[m] + (2\\mu - 1)\\mathbb{E}[m] - N\\mu^2 &= 0\n    \\end{align*}\n    which gives us the desired result, i.e.\n    \\begin{equation}\\label{eq:2.12}\\tag{2.12}\n        \\text{var}[m] \\equiv \\sum_{m=0}^{N} (m - \\mathbb{E}[m])^2 \\text{Bin}(m | N, \\mu) = N\\mu(1 - \\mu)\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 2.5 $\\star \\star$}\nIn this exercise, we prove that the beta distribution, given by\n($\\ref{eq:2.13}$), is correctly normalized, so that (2.14) holds.\nThis is equivalent to showing that\n\\begin{equation}\\label{eq:2.265}\\tag{2.265}\n    \\int_{0}^{1} \\mu^{a-1}(1 - \\mu)^{b - 1} \\diff \\mu = \\frac{\\Gamma(a)\\Gamma(b)}{\\Gamma(a+b)}\n\\end{equation}\nFrom the definition ($\\ref{eq:1.141}$) of the gamma function,\nwe have \n\\begin{equation}\\label{eq:2.266}\\tag{2.266}\n    \\Gamma(a)\\Gamma(b) = \\int_{0}^{\\infty} \\exp(-x)x^{a - 1} \\diff x +\n    \\int_{0}^{\\infty} \\exp(-y)y^{b - 1} \\diff y\n\\end{equation}\nUse this expression to prove ($\\ref{eq:2.265}$) as follows. First\nbring the integral over $y$ inside the integrand of the integral \nover $x$, next make the change of variable $t = y + x$, where $x$\nis fixed, then interchange the order of the $x$ and $t$ integrations,\nand finally make the change of variable $x = t\\mu$ where $t$ is fixed. \n\n\\vspace{1em}\n\n\\begin{proof}\n    The problem is easily solved by following the provided steps.\n    By bringing the integral over $y$ inside the integrand of \n    the integral over $x$ we obtain that\n    \\[\n        \\Gamma(a)\\Gamma(b) = \\int_{0}^{\\infty} \\int_{0}^{\\infty}\n        \\exp\\{-(x + y)\\} x^{a - 1} y^{b - 1} \\diff y \\diff x\n    \\] \n    We know use the change of variable $t = y+x$ with $x$ fixed\n    to get\n    \\[\n        \\Gamma(a)\\Gamma(b) = \\int_{0}^{\\infty} \\int_{0}^{\\infty}\n        \\exp(-t) x^{a - 1} (x - t)^{b - 1} \\diff t \\diff x\n    \\] \n    Interchanging the order of integrations yields\n    \\[\n        \\Gamma(a)\\Gamma(b) = \\int_{0}^{\\infty} \\int_{0}^{\\infty}\n        \\exp(-t) x^{a - 1} (x - t)^{b - 1} \\diff x \\diff t\n    \\] \n    which by making the change of variable $x = t\\mu$ with $t$ fixed\n    becomes\n    \\[\n        \\Gamma(a)\\Gamma(b) = \\int_{0}^{\\infty} \\int_{0}^{\\infty}\n        \\exp(-t) (t\\mu)^{a - 1} (t\\mu - t)^{b - 1} t \\diff \\mu \\diff t\n    \\] \n    By separating the $t$ terms from the first integral, we have that\n     \\[\n         \\Gamma(a)\\Gamma(b) = \\int_{0}^{\\infty} \n         \\exp(-t) t^{a + b - 1} \\diff t\n         \\int_{0}^{\\infty} \\mu^{a - 1}(1 - \\mu)^{b - 1} \\diff \\mu\n    \\] \n    Finally, we notice that the first integral is equal to $\\Gamma(a+b)$ \n    and by noting the fact that $\\mu$ is a probability, so its\n    range is $[0, 1]$, we obtain the desired result:\n    \\begin{equation}\\tag{2.265}\n        \\int_{0}^{1} \\mu^{a-1}(1 - \\mu)^{b - 1} \\diff \\mu = \\frac{\\Gamma(a)\\Gamma(b)}{\\Gamma(a+b)}\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 2.6 $\\star$} \nMake use of the result ($\\ref{eq:2.265}$) to show that the mean,\nvariance, and mode of the beta distribution ($\\ref{eq:2.13}$) are given \nrespectively by \n\\begin{equation}\\label{eq:2.267}\\tag{2.267}\n    \\mathbb{E}[\\mu] = \\frac{a}{a + b}\n\\end{equation}\n\\begin{equation}\\label{eq:2.268}\\tag{2.268}\n    \\text{var}[\\mu] = \\frac{ab}{(a + b)^2(a + b + 1)}\n\\end{equation}\n\\begin{equation}\\label{eq:2.269}\\tag{2.269}\n    \\text{mode}[\\mu] = \\frac{a - 1}{a + b - 2}\n\\end{equation}\n\n\\vspace{1em}\n\n\\begin{proof}\n    The beta distribution is given by\n    \\begin{equation}\\label{eq:2.13}\\tag{2.13}\n        \\text{Beta}(\\mu | a, b) = \\frac{\\Gamma(a + b)}{\\Gamma(a)\\Gamma(b)} \\mu^{a - 1}(1 - \\mu)^{b - 1}\n    \\end{equation}\n    By using $(\\ref{eq:2.265})$ and the fact that $\\Gamma(x + 1) = x\\Gamma(x)$, we \n    obtain the mean of the Beta distribution:\n    \\begin{align*}\n        \\mathbb{E}[\\mu] \n        = \\int_{0}^{1} \\mu \\text{Beta}(\\mu | a, b) \\diff \\mu \n        = \\frac{\\Gamma(a + b)}{\\Gamma(a)\\Gamma(b)} \\int_{0}^{1} \\mu^a (1 - \\mu)^{b - 1} \\diff \\mu \n        = \\frac{\\Gamma(a+b)}{\\Gamma(a)\\Gamma(b)} \\cdot \\frac{\\Gamma(a + 1)\\Gamma(b)}{\\Gamma(a + b + 1)}\n        = \\frac{a}{a + b}\n        \\tag{2.267}\n    \\end{align*}\n    From this result, we can also easily get the variance:\n    \\begin{align*}\n        \\text{var}[\\mu] \n        &= \\int_{0}^{1} \\bigg(\\mu - \\frac{a}{a + b}\\bigg)^2 \\text{Beta}(\\mu | a,b) \\diff \\mu \\\\\n        &= \\int_{0}^{1} \\mu^2 \\text{Beta}(\\mu | a, b) \\diff \\mu \n        - \\frac{2a}{a + b} \\int_{0}^{1} \\mu\\text{Beta}(\\mu | a, b) \\diff \\mu\n        + \\frac{a^2}{(a + b)^2} \\int_{0}^{1} \\text{Beta}(\\mu | a, b) \\diff \\mu \\\\\n        &= \\frac{\\Gamma(a+b)}{\\Gamma(a)\\Gamma(b)} \\cdot \\frac{\\Gamma(a + 2)\\Gamma(b)}{\\Gamma(a + b + 2)}\n        - \\frac{2a}{a+b} \\cdot \\frac{a}{a + b} + \\frac{a^2}{(a+b)^2} \\\\\n        &= \\frac{a(a + 1)}{(a + b)(a + b + 1)} - \\frac{2a^2}{a + b} + \\frac{a^2}{(a + b)^2} \\\\\n        &= \\frac{ab}{(a + b)^2(a + b + 1)}\n        \\tag{2.267}\n    \\end{align*}\n    Finally, the mode of the distribution is given by getting the value of\n    $\\mu$ for which the derivative of the distribution is 0,\n    \\begin{align*}\n        \\pdv{\\mu} \\text{Beta}(\\mu | a, b) = 0 \n        &\\iff \\pdv{\\mu} \\mu^{a - 1}(1 - \\mu)^{b - 1} = 0 \\\\\n        &\\iff (a - 1)\\mu^{a - 2}(1 - \\mu)^{b - 1} + (b - 1)\\mu^{a - 1}(1 - \\mu)^{b - 2} = 0 \\\\\n        &\\iff \\mu^{a - 2}(1 - \\mu)^{b - 2}\\{(a - 1)(1 - \\mu) + (b - 1)\\mu\\} = 0 \\\\\n        &\\iff (a - 1)(1 - \\mu) + (b - 1)\\mu = 0 \\\\\n        &\\iff \\mu = \\frac{a - 1}{a + b - 2}\n    \\end{align*}\n    so indeed\n    \\[\n        \\text{mode}[\\mu] = \\frac{a - 1}{a + b - 2} \\tag{2.268}\n    \\] \n\\end{proof}\n\n\\section*{Exercise 2.7 $\\star \\star$}\nConsider a binomial random variable $x$ given by $(\\ref{eq:2.9})$, with\nprior distribution for $\\mu$ given by the beta distribution $(\\ref{eq:2.13})$,\nand suppose we have observed $m$ occurences of $x=1$ and $l$ occurences \nof $x=0$. Show that the posterior mean value of $\\mu$ lies between the prior\nmean and the maximum likelihood estimate for $\\mu$. To do this,\nshow that the posterior mean can be written as $\\lambda$ times the prior\nmean plus $(1 - \\lambda)$ times the maximum likelihood estimate, \nwhere  $0 \\leq \\lambda \\leq 1$. This illustrates the concept of\nthe posterior distribution being a compromise between the prior\ndistribution and the maximum likelihood solution.\n\n\\begin{proof}\n    The prior mean is $\\displaystyle \\frac{a}{a + b}$, the posterior mean is \n    $\\displaystyle \\frac{a + m}{a + m + b + l}$ and the maximum likelihood \n    estimate is $\\displaystyle \\frac{m}{m + l}$. Suppose that our hypothesis\n    is true, i.e. there exists a $\\lambda$ such that we can have our equality\n    and $0 \\leq \\lambda \\leq 1$. Then we'd have that:\n    \\begin{align*}\n        \\frac{a + m}{a + m + b + l} &= \\frac{\\lambda m}{m + l} + \\frac{(1 - \\lambda)a}{a + b} \\\\\n        \\frac{a + m}{a + m + b + l} - \\frac{a}{a + b} &= \\lambda\\bigg(\\frac{m}{m + l} + \\frac{a}{a + b}\\bigg) \\\\\n        \\lambda &= \\frac{bm - al}{(a + b)(a + m + b + l)} \\cdot \\frac{(a + b)(a + m)}{bm - al} \\\\\n        \\lambda &= \\frac{l + m}{a + m + b + l}\n    \\end{align*}\n    This $\\lambda$ obviously exists and $0 \\leq \\lambda \\leq 1$, so our hypothesis is\n    true and the posterior mean value of $x$ lies between the prior mean\n    and the maximum likelihood estimate for $\\mu$.\n\\end{proof}\n\n\\section*{Exercise 2.8 $\\star$}\nConsider two variables $x$ and $y$ with joint distribution $p(x, y)$.\nProve the following two results\n\\begin{equation}\\label{eq:2.270}\\tag{2.270}\n    \\mathbb{E}[x] = \\mathbb{E}_y[\\mathbb{E}_x[x | y]]\n\\end{equation}\n\\vspace{-1em}\n\\begin{equation}\\label{eq:2.271}\\tag{2.271}\n    \\text{var}[x] = \\mathbb{E}_y[\\text{var}_x[x | y]] + \\text{var}_y[\\mathbb{E}_x[x|y]]\n\\end{equation}\nHere $\\mathbb{E}_x[x | y]$ denotes the expectation of $x$ under the conditional\ndistribution $p(x | y)$, with a similar notation for the conditional\nvariance.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The first is straightforward to derive:\n    \\begin{align*}\n        \\mathbb{E}[x] \n        = \\iint x p(x, y) \\diff x \\diff y\n        = \\iint x p(x | y) p(y) \\diff x \\diff y\n        &= \\int\\bigg(\\int x p(x | y) \\diff x\\bigg) p(y) \\diff y \\\\\n        &= \\int \\mathbb{E}_x[x | y] p(y) \\diff y \n        = \\mathbb{E}_y[\\mathbb{E}_x[x | y]]\n        \\tag{2.270}\n    \\end{align*}\n    However, proving ($\\ref{eq:2.271}$) is slightly more complicated.\n    We'll compute each term separately:\n    \n\\end{proof}\n\n\\section*{Exercise 2.10 $\\star \\star$}\nUsing the property $\\Gamma(x+1) = x\\Gamma(x)$ of the gamma function,\nderive the following results for the mean, variance, and covariance\nof the Dirichlet distribution given by $(\\ref{eq:2.38})$\n\\begin{equation}\\label{eq:2.273}\\tag{2.273}\n    \\mathbb{E}[\\mu_j] = \\frac{\\alpha_j}{\\alpha_j}\n\\end{equation}\n\\begin{equation}\\label{eq:2.274}\\tag{2.274}\n    \\text{var}[\\mu_j] = \\frac{\\alpha_j(\\alpha_0 - \\alpha_j)}{\\alpha_0^2(\\alpha_0 + 1)}\n\\end{equation}\n\\begin{equation}\\label{eq:2.275}\\tag{2.275}\n    \\text{cov}[\\mu_j\\mu_l] = -\\frac{\\alpha_j\\alpha_l}{\\alpha_0^2(\\alpha_0 + 1)},\n    \\hspace{3em} j \\neq l\n\\end{equation}\nwhere $\\alpha_0$ is defined by  (2.39).\n\n\\vspace{1em}\n\n\\begin{proof}\n    The Dirichlet distribution is given by\n    \\begin{equation}\\label{eq:2.38}\\tag{2.38}\n        \\text{Dir}(\\bm{\\mu} | \\bm{\\alpha})\n        = \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_1)\\ldots\\Gamma(\\alpha_K)}\n        \\prod_{k = 1}^K \\mu_k^{\\alpha_k - 1}\n    \\end{equation}\n    Besides the property that $\\Gamma(x+1) = x\\Gamma(x)$, we'll be using the fact that the distribution is normalized,\n    specifically that\n    \\[\n        \\int \\prod_{k = 1}^K \\mu_k^{\\alpha_k - 1} \\diff \\bm{\\mu}\n        = \\frac{\\Gamma(\\alpha_1)\\Gamma(\\alpha_2)\\ldots\\Gamma(\\alpha_K)}{\\Gamma(\\alpha_0)},\n    \\]\n    where $\\alpha_0$ is defined by (2.39).\n\n    The expected value is then given by\n    \\begin{align*}\n        \\mathbb{E}[\\mu_j] \n        &= \\int \\mu_j \\text{Dir}(\\bm{\\mu} | \\bm{\\alpha}) \\diff \\bm{\\mu} \\\\\n        &= \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_1)\\Gamma(\\alpha_2)\\ldots\\Gamma(\\alpha_K)}\n        \\int \\mu_1^{\\alpha_1 - 1}\\dots\\mu_j^{\\alpha_j}\\ldots\\mu_K^{\\alpha_K - 1} \\diff \\bm{\\mu} \\\\\n        &= \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_1)\\Gamma(\\alpha_2)\\ldots\\Gamma(\\alpha_K)}\n        \\cdot \\frac{\\Gamma(\\alpha_1)\\ldots\\Gamma(\\alpha_j + 1)\\ldots\\Gamma(\\alpha_K)}\n        {\\Gamma(\\alpha_0 + 1)} \\\\\n        &= \\frac{\\alpha_j}{\\alpha_0} \n        \\tag{2.273}\n    \\end{align*}\n    This can now be used to derive the variance:\n    \\begin{align*}\n        \\text{var}[\\mu_j] \n        &= \\int (\\mu_j - \\mathbb{E}[\\mu_j])^2 \\text{Dir}(\\bm{\\mu} | \\bm{\\alpha}) \\diff \\bm{\\mu} \\\\\n        &= \\int \\bigg(\\mu_j - \\frac{\\alpha_j}{\\alpha_0}\\bigg)^2 \n        \\text{Dir}(\\bm{\\mu} | \\bm{\\alpha}) \\diff \\bm{\\mu} \\\\\n        &= \\int \\mu_j^2 \\text{Dir}(\\bm{\\mu} | \\bm{\\alpha}) \\diff \\bm{\\mu}\n        - \\frac{2\\alpha_j}{\\alpha_0}\\int \\mu_j\\text{Dir}(\\bm{\\mu} | \\bm{\\alpha}) \\diff \\bm{\\mu}\n        + \\frac{\\alpha_j^2}{\\alpha_0^2} \\int \\text{Dir}(\\bm{\\mu} | \\bm{\\alpha}) \\diff \\bm{\\mu} \\\\\n        &= \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_1)\\Gamma(\\alpha_2)\\ldots\\Gamma(\\alpha_K)}\n        \\int \\mu_1^{\\alpha_1 - 1}\\dots\\mu_j^{\\alpha_j + 1}\\ldots\\mu_K^{\\alpha_K - 1} \\diff \\bm{\\mu} \n        - \\frac{2\\alpha_j}{\\alpha_0} \\mathbb{E}[\\mu_j] + \\frac{\\alpha_j^2}{\\alpha_0^2} \\\\\n        &= \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_1)\\Gamma(\\alpha_2)\\ldots\\Gamma(\\alpha_K)}\n        \\cdot \\frac{\\Gamma(\\alpha_1)\\ldots\\Gamma(\\alpha_j + 2)\\ldots\\Gamma(\\alpha_K)}\n        {\\Gamma(\\alpha_0 + 2)} - \\frac{\\alpha_j^2}{\\alpha_0^2} \\\\\n        &= \\frac{\\alpha_j(\\alpha_j + 1)}{\\alpha_0(\\alpha_0 + 1)} - \\frac{\\alpha_j^2}{\\alpha_0^2} \\\\\n        &= \\frac{\\alpha_j(\\alpha_0 - \\alpha_j)}{\\alpha_0^2(\\alpha_0 + 1)}\n        \\tag{2.275}\n    \\end{align*}\n    The covariance is given by\n    \\[\n    \\text{cov}[\\mu_j\\mu_l] \n    = \\mathbb{E}[\\mu_j\\mu_l] - \\mathbb{E}[\\mu_j]\\mathbb{E}[\\mu_l]\n    = \\mathbb{E}[\\mu_j\\mu_l] - \\frac{\\alpha_j\\alpha_l}{\\alpha_0^2}\n    \\] \n    By computing the expectation separately, we find that\n    \\begin{align*}\n        \\mathbb{E}[\\mu_j\\mu_l]\n        &= \\int \\mu_j\\mu_l \\text{Dir}(\\bm{\\mu} | \\bm{\\alpha}) \\diff \\bm{\\mu} \\\\\n        &= \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_1)\\Gamma(\\alpha_2)\\ldots\\Gamma(\\alpha_K)}\n        \\int \\mu_1^{\\alpha_1 - 1}\\dots\\mu_j^{\\alpha_j}\\ldots\\mu_l^{\\alpha_l}\n        \\ldots\\mu_K^{\\alpha_K - 1} \\diff \\bm{\\mu} \\\\\n        &= \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_1)\\Gamma(\\alpha_2)\\ldots\\Gamma(\\alpha_K)}\n        \\cdot \\frac{\\Gamma(\\alpha_1)\\ldots\\Gamma(\\alpha_j + 1)\\ldots\\Gamma(\\alpha_l + 1)\\ldots\n        \\Gamma(\\alpha_K)}{\\Gamma(\\alpha_0 + 2)}\\\\\n        &= \\frac{\\alpha_j\\alpha_l}{\\alpha_0(\\alpha_0 + 1)}\n    \\end{align*}\n    Finally, the covariance becomes\n    \\[\n        \\text{cov}[\\mu_j\\mu_l] \n        = \\frac{\\alpha_j\\alpha_l}{\\alpha_0(\\alpha_0 + 1)} - \\frac{\\alpha_j\\alpha_l}{\\alpha_0^2}\n        = -\\frac{\\alpha_j\\alpha_l}{\\alpha_0^2(\\alpha_0 + 1)}\n        \\tag{2.275}\n    \\] \n\\end{proof}\n\n\\section*{Exercise 2.11 $\\star$}\nBy expressing the expectation of $\\ln \\mu_j$ under the Dirichlet\ndistribution ($\\ref{eq:2.38}$) as a derivative with respect\nto $\\alpha_j$, show that\n\\begin{equation}\\label{eq:2.276}\\tag{2.276}\n    \\mathbb{E}[\\ln \\mu_j] = \\psi(\\alpha_j) - \\psi(\\alpha_0)\n\\end{equation}\nwhere $\\alpha_0$ is given by (2.39) and\n\\begin{equation}\\label{eq:2.277}\\tag{2.277}\n    \\psi(a) \\equiv \\dv{a} \\ln \\Gamma(a)\n\\end{equation}\nis the $\\emph{digamma}$ function.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We start by taking the partial derivative of the Dirichlet\n    distribution with respect to $\\alpha_j$:\n    \\begin{align*}\n        \\pdv{\\alpha_j} \\text{Dir}(\\bm{\\mu} | \\bm{\\alpha})\n        &= \\pdv{\\alpha_j}\\bigg(\\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_1)\\Gamma(\\alpha_2)\\ldots\\Gamma(\\alpha_K)}\n        \\prod_{k = 1}^K \\mu_k^{\\alpha_k - 1}\\bigg) \\\\\n        &= \\bigg(\\pdv{\\alpha_j}\\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_1)\\Gamma(\\alpha_2)\\ldots\\Gamma(\\alpha_K)}\\bigg) \\prod_{k = 1}^K \\mu_k^{\\alpha_k - 1} +\n        \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_1)\\Gamma(\\alpha_2)\\ldots\\Gamma(\\alpha_K)}\n        \\bigg(\\pdv{\\alpha_j}\\prod_{k = 1}^K \\mu_k^{\\alpha_k - 1}\\bigg)\n    \\end{align*}\n    Our goal is to compute both terms separately. Firstly, since\n    a small change in one of the sum terms is equivalent to a small\n    change in the sum itself, i.e.\n    \\[\n        \\pdv{\\alpha_j} \\Gamma(\\alpha_0) = \\pdv{\\alpha_0} \\Gamma(\\alpha_0)\n    \\] \n    we have that\n    \\begin{align*}\n        \\pdv{\\alpha_j} \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_j)}\n        &= \\frac{\\pdv{\\alpha_j}\\Gamma(\\alpha_0) - \\pdv{\\alpha_j}\\Gamma(\\alpha_j)}{\\Gamma(\\alpha_j)^2} \\\\\n        &= \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_j)} \\bigg(\\frac{\\pdv{\\alpha_j} \\Gamma(\\alpha_0)}\n            {\\Gamma(\\alpha_0)} - \\frac{\\pdv{\\alpha_j} \\Gamma(\\alpha_j)}{\\Gamma(\\alpha_j)}\\bigg) \\\\\n        &= \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_j)}\n        \\bigg(\\pdv{\\alpha_0} \\ln \\Gamma(\\alpha_0) - \\pdv{\\alpha_j} \\ln \\Gamma(\\alpha_j)\\bigg) \\\\\n        &= \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_j)}(\\psi(\\alpha_0) - \\psi(\\alpha_j))\n    \\end{align*}\n    and therefore, that\n    \\[\n        \\bigg(\\pdv{\\alpha_j}\\frac{\\Gamma(\\alpha_0)}\n        {\\Gamma(\\alpha_1)\\Gamma(\\alpha_2)\\ldots\\Gamma(\\alpha_K)}\\bigg) \n        \\prod_{k = 1}^K \\mu_k^{\\alpha_k - 1}\n        = (\\psi(\\alpha_0) - \\psi(\\alpha_j))\\text{Dir}(\\bm{\\mu} | \\bm{\\alpha})\n    \\] \n    Now, since \n    \\[\n        \\pdv{\\alpha_j} \\prod_{k = 1}^K \\mu_k^{\\alpha_k - 1}\n        = (\\mu_1^{\\alpha_1 - 1}\\ldots\\mu_{j - 1}^{\\alpha_{j - 1} - 1}\n        \\mu_{j + 1}^{\\alpha_{j + 1} - 1}\n        \\ldots \\mu_K^{\\alpha_K - 1}) \\pdv{\\alpha_j} \\mu_j^{\\alpha_j - 1}\n        = \\ln \\mu_j \\prod_{k = 1}^K \\mu_k^{\\alpha_k - 1}\n    \\] \n    it follows that\n    \\[\n        \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\alpha_1)\\Gamma(\\alpha_2)\\ldots\\Gamma(\\alpha_K)}\n        \\bigg(\\pdv{\\alpha_j}\\prod_{k = 1}^K \\mu_k^{\\alpha_k - 1}\\bigg)\n        = \\ln \\mu_j \\text{Dir}(\\bm{\\mu} | \\bm{\\alpha})\n    \\] \n    By substituting into the initial expression,\n    \\[\n        \\pdv{\\alpha_j} \\text{Dir}(\\bm{\\mu} | \\bm{\\alpha})\n        = \\text{Dir}(\\bm{\\mu} | \\bm{\\alpha}) (\\ln \\mu_j + \\psi(\\alpha_0) - \\psi(\\alpha_j))\n    \\] \n    and then integrating with respect to $\\bm{\\mu}$, we obtain the \n    desired result:\n    \\[\n        \\mathbb{E}[\\ln{\\mu_j}] = \\psi(\\alpha_j) - \\psi(\\alpha_0) \n        \\tag{2.276}\n    \\] \n\\end{proof}\n\n\n", "meta": {"hexsha": "8e5276e063e92e1f9b3f7f699946ff50d525dc14", "size": 24370, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter2_distributions.tex", "max_stars_repo_name": "thesstefan/bishop_prml", "max_stars_repo_head_hexsha": "22c3e04e54f0ff91fa043d46aa0d760998094d1b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/chapter2_distributions.tex", "max_issues_repo_name": "thesstefan/bishop_prml", "max_issues_repo_head_hexsha": "22c3e04e54f0ff91fa043d46aa0d760998094d1b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter2_distributions.tex", "max_forks_repo_name": "thesstefan/bishop_prml", "max_forks_repo_head_hexsha": "22c3e04e54f0ff91fa043d46aa0d760998094d1b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.068716094, "max_line_length": 155, "alphanum_fraction": 0.5520722199, "num_tokens": 9723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.9059898121338505, "lm_q1q2_score": 0.8196041660138269}}
{"text": "\\textbf{Consider again the approximation of $f(x)=3/(5\u22124cos(x))$, $x\\in[-\\pi,\\pi]$. Let $N$ be the number of nodes in Fourier and polynomial interpolation of this function.\n\\begin{enumerate}[label=\\alph*)]\n\\item Plot the error as a function of $N$ (on the same figure) for both Chebyshev and Fourier. Notice\nthat Fourier converges at a faster rate in this case.\n\\item Now consider that maximum spacing between nodes: $h=max|x_{i+1}-x_i|$. Plot the error for\npolynomial and Fourier approximations as a function of $h$ and notice that the rates of convergence\nare now nearly the same.\n\\item Show that the ratio $h_{cheb}/h_{Fourier}$ is about $\\pi/2$.\n\\end{enumerate}\n$~$}\n\\newline\n\nFor the first part we look at the next figure. We can see that, in fact, Fourier converges at a faster rate in this function.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{P7_a.png}\\caption{Convergence of the Chebyshev and Fourier interpolants to $f(x)= \\frac{3}{54\\cos{x}}$.}\n\\end{figure}\n\nWe continue by scaling the Chebyshev points to be withing $[-\\pi,\\pi]$ and calculate $h$ for both Chebishev and Fourier, for each $N$. We obtain the following figure, which shows that the rates of convergence are nearly the same.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{P7_b.png}\\caption{Convergence of the Chebyshev and Fourier interpolants to $f(x)= \\frac{3}{54\\cos{x}}$.}\n\\end{figure}\n\nLastly, in the following figure we see that, once is large enough, $h_{Cheb}/h_{Fourier}\\approx \\pi/2$.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{P7_c.png}\\caption{$h_{Cheb}/h_{Fourier}$ for $f(x)= \\frac{3}{54\\cos{x}}$.}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 7\nclose all\nf = chebfun('3/(5-4*cos(x))',[-pi,pi]);\nplot(f)\ngrid on\nN = 2:2:50;\nfor k = 1:length(N)\n    fcheb = chebfun('3/(5-4*cos(x))',[-pi,pi],N(k));\n    ffour = chebfun('3/(5-4*cos(x))',[-pi,pi],N(k),\"trig\");\n    errcheb(k) = norm(f-fcheb,inf);\n    errfour(k) = norm(f-ffour,inf);\n    % b\n    [~,x] = cheb(N(k)); x = pi*x;\n    hcheb(k) = max(abs(x(2:end)-x(1:end-1)));\n    hfour(k) = 2*pi/(N(k));\nend\n% a\nfigure\nsemilogy(N,errcheb,'b',N,errfour,'r')\nhold on\nsemilogy(N,errcheb,'b*',N,errfour,'r*')\ngrid on\nxlabel('$N$','interpreter','latex')\nylabel('$Error$','interpreter','latex')\nset(gca,'fontsize',labelfontsize)\nlegend('Chebishev', 'Fourier')\ntxt='Latex/FIGURES/P7_a';\nsaveas(gcf,txt,figformat)\n% b\nfigure\nsemilogy(hcheb.^(-1),errcheb,'b',hfour.^(-1),errfour,'r')\nhold on\nsemilogy(hcheb.^(-1),errcheb,'b*',hfour.^(-1),errfour,'r*')\ngrid on\nxlabel('$1/h$','interpreter','latex')\nylabel('$Error$','interpreter','latex')\nset(gca,'fontsize',labelfontsize)\nlegend('Chebishev', 'Fourier')\ntxt='Latex/FIGURES/P7_b';\nsaveas(gcf,txt,figformat)\n% c\nfigure\nplot(N,hcheb./hfour,'r*')\ngrid on\naxis([0 50 0 pi])\nxlabel('$N$','interpreter','latex')\nylabel('$h_{Cheb}/h_{Fourier}$','interpreter','latex')\nset(gca,'fontsize',labelfontsize)\nlegend('Chebishev', 'Fourier')\ntxt='Latex/FIGURES/P7_c';\nsaveas(gcf,txt,figformat)\n\\end{verbatim}", "meta": {"hexsha": "2e74dc5f7d63587459d0ac7afc666fb58032e25c", "size": 3043, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework3/Latex/problem7.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework3/Latex/problem7.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework3/Latex/problem7.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.3837209302, "max_line_length": 229, "alphanum_fraction": 0.6910943148, "num_tokens": 1026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.9073122125886486, "lm_q1q2_score": 0.8195698605789095}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find the matrix for the linear transformation that reflects every\n  vector in $\\R^2$ about the $x$-axis and then reflects about the\n  $y$-axis.\n\\end{ex}\n\n\\begin{ex}\n  Find the matrix for the linear transformation that rotates every\n  vector in $\\R^2$ by an angle of $2\\pi/3$ and then reflects\n  about the $x$-axis.\n  \\begin{sol}\n    \\begin{equation*}\n      \\def\\arraystretch{1.2}\n      \\begin{mymatrix}{rr}\n        1 & 0 \\\\\n        0 & -1\n      \\end{mymatrix} \\begin{mymatrix}{cc}\n        \\cos \\paren{\\frac{2\\pi}{3}}  & -\\sin \\paren{\\frac{2\\pi}{3}}\n        \\\\\n        \\sin \\paren{\\frac{2\\pi}{3}}  & \\cos \\paren{\\frac{2\\pi}{3}}\n      \\end{mymatrix} = \\begin{mymatrix}{cc}\n        -\\frac{1}{2} & -\\frac{1}{2}\\sqrt{3} \\\\\n        -\\frac{1}{2}\\sqrt{3} & \\frac{1}{2}\n      \\end{mymatrix}\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the matrix for the linear transformation that rotates every\n  vector in $\\R^2$ by an angle of $\\pi /6$ and then reflects\n  about the $x$-axis followed by a reflection about the $y$-axis.\n  \\begin{sol}\n    \\begin{equation*}\n      \\def\\arraystretch{1.2}\n      \\begin{mymatrix}{rr}\n        -1 & 0 \\\\\n        0 & 1\n      \\end{mymatrix} \\begin{mymatrix}{cc}\n        \\cos \\paren{\\frac{\\pi}{6}}  & -\\sin \\paren{\\frac{\\pi}{6}}  \\\\\n        \\sin \\paren{\\frac{\\pi}{6}}  & \\cos \\paren{\\frac{\\pi}{6}}\n      \\end{mymatrix} = \\begin{mymatrix}{cc}\n        -\\frac{1}{2}\\sqrt{3} & \\frac{1}{2} \\\\\n        \\frac{1}{2} & \\frac{1}{2}\\sqrt{3}\n      \\end{mymatrix}\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the matrix for the linear transformation that reflects every\n  vector in $\\R^2$ about the $x$-axis and then rotates by an angle\n  of $\\pi/4$.\n  \\begin{sol}\n    \\begin{equation*}\n      \\def\\arraystretch{1.2}\n      \\begin{mymatrix}{cc}\n        \\cos \\paren{\\frac{\\pi}{4}}  & -\\sin \\paren{\\frac{\\pi}{4}}  \\\\\n        \\sin \\paren{\\frac{\\pi}{4}}  & \\cos \\paren{\\frac{\\pi}{4}}\n      \\end{mymatrix} \\begin{mymatrix}{rr}\n        1 & 0 \\\\\n        0 & -1\n      \\end{mymatrix} = \\begin{mymatrix}{cc}\n        \\frac{1}{2}\\sqrt{2} & \\frac{1}{2}\\sqrt{2} \\\\\n        \\frac{1}{2}\\sqrt{2} & -\\frac{1}{2}\\sqrt{2}\n      \\end{mymatrix}\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the matrix of the linear transformation that rotates every\n  vector in $\\R^3$ counterclockwise about the $z$-axis when viewed\n  from the positive $z$-axis by an angle of 30 degrees and then\n  reflects about the $xy$-plane.\n  \\begin{sol}\n    \\begin{equation*}\n      \\def\\arraystretch{1.2}\n      \\begin{mymatrix}{rrr}\n        1 & 0 & 0 \\\\\n        0 & 1 & 0 \\\\\n        0 & 0 & -1\n      \\end{mymatrix} \\begin{mymatrix}{ccc}\n        \\cos \\paren{\\frac{\\pi}{6}}  & -\\sin \\paren{\\frac{\\pi}{6}}  & 0\n        \\\\\n        \\sin \\paren{\\frac{\\pi}{6}}  & \\cos \\paren{\\frac{\\pi}{6}}  & 0\n        \\\\\n        0 & 0 & 1\n      \\end{mymatrix} = \\begin{mymatrix}{ccc}\n        \\frac{1}{2}\\sqrt{3} & -\\frac{1}{2} & 0 \\\\\n        \\frac{1}{2} & \\frac{1}{2}\\sqrt{3} & 0 \\\\\n        0 & 0 & -1\n      \\end{mymatrix}\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Prove the three properties in\n  Proposition~\\ref{prop:properties-linear-transformation}, using only\n  the definition of a linear transformation (i.e., the fact that it\n  preserves addition and scalar multiplication).\n  \\begin{sol}\n    (a) $T(\\vect{0}) = T(0\\vect{0}) = 0T(\\vect{0}) = \\vect{0}$.\n    (b) $T(-\\vect{v}) = T((-1)\\vect{v}) = (-1)T(\\vect{v}) = -T(\\vect{v})$.\n    (c) $T(a_1\\vect{v}_1 + \\ldots + a_k \\vect{v}_k)\n    = T(a_1\\vect{v}_1) + \\ldots + T(a_k \\vect{v}_k)\n    = a_1T(\\vect{v}_1) + \\ldots + a_kT(\\vect{v}_k)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $T$ be the linear transformation with matrix\n  $A = \\begin{mymatrix}{rr}\n    3 & 1 \\\\\n    -1 & 2\n  \\end{mymatrix}$ and $S$ the linear transformation with matrix\n  $B = \\begin{mymatrix}{rr}\n    0 & -2 \\\\\n    4 & 2\n  \\end{mymatrix}$. Find the matrix of $S \\circ T$. Compute\n  $(S \\circ T) (\\vect{v})$ for\n  $\\vect{v} = \\begin{mymatrix}{r}\n    2 \\\\\n    -1\n  \\end{mymatrix}$.\n  \\begin{sol}\n    The matrix of $S \\circ T$ is given by\n    \\begin{equation*}\n      BA = \\begin{mymatrix}{rr}\n        0 & -2 \\\\\n        4 & 2\n      \\end{mymatrix} \\begin{mymatrix}{rr}\n        3 & 1 \\\\\n        -1 & 2\n      \\end{mymatrix} = \\begin{mymatrix}{rr}\n        2 & -4 \\\\\n        10 & 8\n      \\end{mymatrix}.\n    \\end{equation*}\n    Now,\n    \\begin{equation*}\n      (S \\circ T) (\\vect{v}) = BA\\vect{v}\n      =\n      \\begin{mymatrix}{rr}\n        2 & -4 \\\\\n        10 & 8\n      \\end{mymatrix}\n      \\begin{mymatrix}{r}\n        2 \\\\\n        -1\n      \\end{mymatrix}\n      =\n      \\begin{mymatrix}{r}\n        8 \\\\\n        12\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $T$ be a linear transformation and suppose\n  $T \\paren{\\begin{mymatrix}{r}\n      1 \\\\\n      -4\n    \\end{mymatrix}} = \\begin{mymatrix}{r}\n    2 \\\\\n    -3\n  \\end{mymatrix}$. Suppose $S$ is the linear transformation with\n  matrix $B = \\begin{mymatrix}{rr}\n    1 & 2 \\\\\n    -1 & 3\n  \\end{mymatrix}$. Find $(S \\circ T) (\\vect{v})$ for\n  $\\vect{v} = \\begin{mymatrix}{r}\n    1 \\\\\n    -4\n  \\end{mymatrix}$.\n  \\begin{sol}\n    We have\n    \\begin{equation*}\n      (S \\circ T) (\\vect{v})\n      = S(T(\\vect{v}))\n      = B(T(\\vect{v}))\n      = \\begin{mymatrix}{rr}\n        1 & 2 \\\\\n        -1 & 3\n      \\end{mymatrix}\n      \\begin{mymatrix}{r}\n        2 \\\\\n        -3\n      \\end{mymatrix}\n      = \\begin{mymatrix}{r}\n        -4 \\\\\n        -11\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  What is the inverse of a reflection? Rotation? Shearing? Scaling?\n  \\begin{sol}\n    The inverse of a reflection is a reflection, namely, itself. (For\n    example, reflecting twice about the $x$-axis returns each vector\n    to its original position). The inverse of a rotation is a rotation\n    by the same angle in the opposite direction. The inverse of a\n    shearing is a shearing in the opposite direction. The inverse of a\n    scaling by factor $a$ is a scaling by factor $1/a$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $T$ be a linear transformation with matrix\n  $A = \\begin{mymatrix}{rr}\n    2 & 1 \\\\\n    5 & 2\n  \\end{mymatrix}$. Find the matrix of $T^{-1}$.\n  \\begin{sol}\n    The matrix of $T^{-1}$ is $A^{-1}$.\n    \\begin{equation*}\n      \\begin{mymatrix}{rr}\n        2 & 1 \\\\\n        5 & 2\n      \\end{mymatrix}^{-1} =\n      \\begin{mymatrix}{rr}\n        -2 & 1 \\\\\n        5 & -2\n      \\end{mymatrix}\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $T$ be the linear transformation given by\n  $T\\paren{\\begin{mymatrix}{c} x\\\\y \\end{mymatrix}} =\n  \\begin{mymatrix}{c} 4x-3y\\\\2x-2y \\end{mymatrix}$.  Find the matrix\n  of $T^{-1}$.\n  \\begin{sol}\n    The matrix of $T$ is\n    $A = \\begin{mymatrix}{rr}\n    4 & -3 \\\\\n    2 & -2\n  \\end{mymatrix}$. The matrix of $T^{-1}$ is $A^{-1} =\n  \\begin{mymatrix}{cc}\n    1 & -3/2 \\\\\n    1 & -2\n  \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex} Let $T$ be a linear transformation and suppose $T \\paren{\\begin{mymatrix}{r}\n      1 \\\\\n      2\n    \\end{mymatrix}} = \\begin{mymatrix}{r}\n    9 \\\\\n    8\n  \\end{mymatrix}$ and $T \\paren{\\begin{mymatrix}{r}\n      0 \\\\\n      -1\n    \\end{mymatrix}} = \\begin{mymatrix}{r}\n    -4 \\\\\n    -3\n  \\end{mymatrix}$.\n  Find the matrix of $T$ and the matrix of $T^{-1}$.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "247f47a8c0f5713a8bc2266c0d80033c69173a62", "size": 7334, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/LinearTransformationsRn-Properties.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/LinearTransformationsRn-Properties.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/LinearTransformationsRn-Properties.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 26.9632352941, "max_line_length": 87, "alphanum_fraction": 0.5374965912, "num_tokens": 2835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.9019206864156891, "lm_q1q2_score": 0.8195012795230655}}
{"text": "\n\\subsection{Partial Adjustment Model}\n\n\\subsubsection{Estimating a static model}\n\nWe start by estimating a static model.\n\n\\(y_t=\\alpha + \\theta x_t + \\gamma_t\\)\n\n\\subsubsection{Equilibrium}\n\nWe then use this form an equilibrium for \\(y_t\\), \\(y_t^*\\).\n\n\\(y_t^*=\\hat \\alpha + \\hat \\theta x_t \\)\n\nThe process depends on the difference from this equilibrium.\n\n\\(y_t-y_{t-1}=\\beta (y_{t}^*-y_{t-1})+\\epsilon_t \\)\n\n\\(y_t-y_{t-1}=\\beta (\\hat \\alpha + \\hat \\theta x_t -y_{t-1})+\\epsilon_t \\)\n\n\\(y_t=\\beta \\hat \\alpha + \\beta \\hat \\theta x_t + (1-\\beta )y_{t-1}+\\epsilon_t \\)\n\n\\(y_t=\\alpha y_{t-1}+(1-\\beta )(y_{t}^*-y_{t-1})+\\epsilon \\)\n\nThe higher \\(\\beta \\), the slower the adjustment.\n\nIf stationary, can we can use OLS.\n\n", "meta": {"hexsha": "a1ae694e4b4288b7eded46f42e7ba92abdc64810", "size": 719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/forecastingMulti/04-03-PAM.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/forecastingMulti/04-03-PAM.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/forecastingMulti/04-03-PAM.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.9666666667, "max_line_length": 81, "alphanum_fraction": 0.6495132128, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951142221377825, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.8194453663201091}}
{"text": "\n\\subsection{Permutations and the symmetric group}\n\nA permutation is defined as a bijection from a set to itself.\n\nFor a set of size \\(n\\), the number of permutations is \\(n!\\). This is because there are \\(n\\) possibilities for the first item, \\(n-1\\) for the second and so on.\n\n\\subsubsection{The symmetric group}\n\nThe set of all permutations forms a group, the symmetric group. This forms a group because:\n\n\\begin{itemize}\n\\item There is an identity element\n\\item Each combination of permutations is also in the group.\n\\item Each permutation has an inverse in the group.\n\\end{itemize}\n\n\\subsubsection{Permutation groups}\n\nA subgroup of the symmetric group is called a permutation group.\n\n\n", "meta": {"hexsha": "dcef858cb7e47e4b87b9b3c3bdc787f83254e5aa", "size": 691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/02-01-permutation.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/groups/02-01-permutation.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/groups/02-01-permutation.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0434782609, "max_line_length": 162, "alphanum_fraction": 0.7641099855, "num_tokens": 159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422158380862, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.8194453615474124}}
{"text": "\\section{The Elementary Theory of Initial-Value Problems}\n\\begin{defn}[Lipschitz Condition]\nA function $f(t,y)$ is said to satisfy a \\emph{Lispschitz condition} in the variable $Y$ on a set $D\\subset\\mathbb{R}^2$ if a constant $L>0$ exists with\n\\[\n\\abs{f(t,y_1)-f(t,y_2)}\\leq L\\abs{y_1-y_2}\n\\]\nwhenever $(t_1,y_1)$, $(t_2,y_2)$ are in $D$. The constant $L$ is called a \\emph{Lipschitz constant} for $f$.\n\\end{defn}\n\\begin{defn}[Convex]\nA set $D\\subset\\mathbb{R}^2$ is said to be convex if whenever $(t_1,y_1),(t_2,y_2)\\in D$, then for every $\\lambda\\in [0,1]$,\n\\[\n((1-\\lambda)t_1+\\lambda t_2, (1-\\lambda)y_1+\\lambda y_2) \\in D.\n\\]\n\\end{defn}\n\\begin{theo}\nSuppose $f(t,y)$ is defined on a convex set $D\\subset\\mathbb{R}^2$, if a constant $L>0$ exists with\n\\[\n\\abs{\\frac{\\partial f}{\\partial y}(t,y)}\\leq L\n\\]\nfor all $(t,y)\\in D$, then $f$ satisfies a Lipschitz condition on $D$ in the variable $y$ with Lipschitz constant $L$.\n\\end{theo}\n\\begin{theo}\nSuppose that $D=\\left\\{(t,y)|a\\leq t\\leq b,y\\in\\mathbb{R}\\right\\}$ and $f(t,y)$ is continuous on $D$. If $f$ satisfies a Lipschitz condition on $D$ in the variable $y$, then the initial-value problem\n\\begin{align*}\n  \\begin{cases}\n    y'(t)=f(t,y) & a\\leq t\\leq b \\\\\n    y(a)=\\alpha\n  \\end{cases}\n\\end{align*}\nhas a unique solution $y(t)$ for $a\\leq t\\leq b$.\n\\end{theo}\n\\subsection{Well-Posed Problems}\n\\begin{theo}[Well-Posed]\nSuppose that $D=\\left\\{(t,y)|a\\leq t\\leq b,y\\in\\mathbb{R}\\right\\}$ and $f(t,y)$, if $f$ is continuous and satisfies a Lipschitz condition in the variable $y$ on the set $D$, then the initial-value problem\n\\[\n\\frac{\\D y}{\\D t}=f(t,y),\\quad a\\leq t\\leq b,\\quad y(a)=\\alpha\n\\]\nis well-posed.\n\\end{theo}", "meta": {"hexsha": "1ae21056aae6efb7c8f775263fb21a591fda2c99", "size": 1679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/5.1_The_elementary_theory_of_initial_value_problems.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/5.1_The_elementary_theory_of_initial_value_problems.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/5.1_The_elementary_theory_of_initial_value_problems.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.0512820513, "max_line_length": 204, "alphanum_fraction": 0.6634901727, "num_tokens": 673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.9173026533686325, "lm_q1q2_score": 0.8194350832418146}}
{"text": "\\subsection{Solving Inequalities that Contain Absolute Values}\r\nWe start by solving an equality that contains an absolute value.\r\nTo do so, we recall that if $a\\geq 0$ then the solution to \r\n$|x|=a$ is $x=\\pm a$. In cases where we are not sure if the right \r\nside is positive or negative, we must perform a check at the end. \\\\\r\n\r\n\\begin{example}{Absolute Value Equality}{AbsoluteValueEquality}\r\nSolve for $x$ in $|2x+3|=2-x$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nThis means that either:\r\n\\[\\begin{array}{rclcrcl}\r\n\t2x+3 & = & 2-x & \\hspace{5mm} \\text{or} \\hspace{5mm} & \\hspace{3mm} 2x+3 & = & -(2-x)\\\\\r\n\t2x+3 & = & 2-x &  & 2x+3 & = & -2+x\\\\\r\n\t3x & = & -1 &  & x & = & -5\\\\\r\n\tx & = &-1/3 &  & x & = & -5\\\\\r\n\\end{array}\\]\r\nSince we do not know if the right side $``2-x\"$ is positive or negative, we must perform a check of our answers and omit any that are incorrect.\\\\\r\n\r\nIf $x=-1/3$, then we have \r\n\r\n\\hspace{4cm} $\\begin{array}{rcl}\r\n\\displaystyle{\\left| 2 (-1/3) +3 \\right|} & = & \\displaystyle{2-\\left( -1/3 \\right)} \\\\\r\n\\displaystyle{\\left| -2 /3 \\, +3\\right|} & = & \\displaystyle{2+ \\, 1/3 } \\\\\r\n\t\\displaystyle{ \\left| 7 / 3 \\right|} & = & \\displaystyle{ 7/3 } \\\\\r\n\t\\displaystyle{ 7/3 } & = &  \\displaystyle{ 7/3 } \\\\\r\n\\end{array} $\t\r\n\t\r\n\r\n% \\left( \\frac{-1}{3} \\right)+3\\right|}\r\n\r\nSince the left hand side of the equation equals the right hand side, $x=-1/3$ is a solution.\\\\\r\n\r\nNow checking to see if $x=-5$ satisfies the expression. We have\r\n\r\n\\hspace{4cm} $\\begin{array}{rcl}\r\n\\displaystyle{\\left| 2 (-5) +3 \\right|} & = & \\displaystyle{2-\\left( -5 \\right)} \\\\\r\n\\displaystyle{\\left| -10 \\, +3\\right|} & = & \\displaystyle{2+ \\, 5 } \\\\\r\n\t\\displaystyle{ \\left| -7 \\right|} & = & \\displaystyle{ 7 } \\\\\r\n\t\\displaystyle{ 7 } & = &  \\displaystyle{ 7 } \\\\\r\n\\end{array} $\t\r\n\r\nSince the left hand side equals the right hand side,  $x=-5$ is a solution.\\\\\r\nTherefore, the solution to the absolute value equality is $x=-5, \\, -1/3$. \r\n\\end{solution}\r\n\r\nWe next look at absolute values and inequalities. \\\\\r\n\r\n\\begin{example}{Absolute Value Inequality}{AbsoluteValueInequality}\r\nSolve $|x-5|<7$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nThis simply means $-7<x-5<7$.\r\nAdding $5$ to each gives $-2<x<12$.\r\nTherefore the solution is the interval $(-2,12)$.\r\n\\end{solution}\r\n\r\nIn some questions you must be careful when multiplying by a negative number as in the next problem. \\\\\r\n\r\n\\begin{example}{Absolute Value Inequality}{AbsoluteValueInequality2}\r\nSolve $|2-z|<7$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nThis simply means $-7<2-z<7$.\r\nSubtracting $2$ gives: $-9<-z<5$.\r\nNow multiplying by $-1$ gives: $9>z>-5$. \\ifont{Remember to reverse the inequality signs!}\r\nWe can rearrange this as $-5<z<9$.\r\nTherefore the solution is the interval $(-5,9)$.\r\n\\end{solution}\r\n\r\n\\bigskip\r\n\r\n\\begin{example}{Absolute Value Inequality}{AbsoluteValueInequality3}\r\nSolve $|2-z|\\geq 7$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nRecall that for $a>0$, $|x|\\geq a$ means $x\\leq -a$ or $x\\geq a$.\r\nThus, either $2-z\\leq -7$ \\ifont{or} $2-z\\geq 7$.\r\nEither $9\\leq z$ \\ifont{or} $-5 \\geq z$.\r\nEither $z\\geq 9$ \\ifont{or} $z \\leq -5$.\r\nIn interval notation, either $z$ is in $[9,\\infty)$ \\ifont{or} $z$ is in $(-\\infty,-5]$.\r\nAll together, we get our solution to be: $(-\\infty,-5]\\cup [9,\\infty)$.\r\n\\end{solution}\r\n\r\nIn the previous two examples the \\ifont{only} difference is that one had $<$ in \r\nthe question and the other had $\\geq$. Combining the two solutions gives the \r\n\\ifont{entire} real number line! \\\\\r\n\r\n\\begin{example}{Absolute Value Inequality}{AbsoluteValueInequality4}\r\nSolve $0<|x-5|\\leq 7$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe split this into two cases.\r\n\r\n(1) For $0<|x-5|$ note that we always have that an absolute value is positive or zero (i.e., $0\\leq |x-5|$ is always true).\r\nSo, for this part, we need to avoid $0=|x-5|$ from occurring. \r\nThus, $x$ \\ifont{cannot} be $5$, that is, $x\\neq 5$.\\\\\r\n\r\n(2) For $|x-5|\\leq 7$, we have $-7\\leq x-5\\leq 7$.\r\nAdding $5$ to each gives $-2\\leq x\\leq 12$.\r\nTherefore the solution to $|x-5|\\leq 7$ is the interval $[-2,12]$.\r\n\r\nTo combine (1) and (2) we need combine $x\\neq 5$ with $x\\in[-2,12]$.\r\nOmitting $5$ from the interval $[-2,12]$ gives our solution to be: $[-2,5)\\cup(5,12]$.\r\n\\end{solution}\r\n", "meta": {"hexsha": "771fbe1f88d633d44f501f61675e1a563b8acc04", "size": 4236, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-1-6-absolute-value-and-inequalities.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1-review/1-1-6-absolute-value-and-inequalities.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1-review/1-1-6-absolute-value-and-inequalities.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.1621621622, "max_line_length": 147, "alphanum_fraction": 0.6343248347, "num_tokens": 1534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.9099069968764882, "lm_q1q2_score": 0.8193983557134182}}
{"text": "\\chapter{Probability}\\label{sec:probability}\nThis course will use probability theory quite a lot, but we will often use\na fairly informal notation. Bayesian\nstatistics is really just probability theory used for a particular purpose,\nto describe uncertainty. The two most important rules of probability are given below,\nfor reference.\n\n\\section{The Product Rule}\nThe first important rule of probability is the\nproduct rule. This tells us how to calculate the probability that any two\npropositions or hypotheses, $A$ and $B$, are {\\bf both} true.\nThe probability of $A$ {\\bf and}\n$B$, will be denoted $P(A, B)$. This can be calculated by first finding the\nprobability that $A$ is true, and then multiplying by the probability that $B$\nis true {\\it given} that $A$ is true.\n\\begin{eqnarray}\nP(A, B) &=& P(A)P(B|A)\\label{product1}\n\\end{eqnarray}\nWe could also have done this the other way around: first finding the\nprobability that $B$ is true and then the probability that $A$ is true given\nthat $B$ is true:\n\\begin{eqnarray}\nP(A, B) &=& P(B)P(A|B).\\label{product2}\n\\end{eqnarray}\n\nWhen using the product rule (or any rule of probability, for that matter), you\nmust ensure that the statements to the right of the ``given'' sign (or the\nabsence of any statements) are consistent throughout. For example,\n$P(A, B|C) = P(A|C)P(B|A, C)$ is a valid use of the product rule, since\n``given $C$'' is part of the background information in all of the terms.\n\nYou may be familiar with the idea of a {\\it tree diagram} from earlier\nstatistics courses or maybe even high school. A tree diagram is a helpful way\nto work with the product rule. If you find tree diagrams helpful, feel free to\nuse them, although tree diagrams themselves will not be examinable.\nAn example tree diagram is given in Figure~\\ref{fig:tree_diagram}.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.9]{Figures/tree_diagram.pdf}\n\\caption{\\it A tree diagram.\\label{fig:tree_diagram}}\n\\end{center}\n\\end{figure}\n\nThe product rule can also be applied to more than two propositions, like so:\n\\begin{eqnarray}\nP(A, B, C) &=& P(A)P(B|A)P(C|B,A).\n\\end{eqnarray}\nYou can also apply the product rule in a situation where there is a common\nstatement in the ``given part'' of all probabilities in the expression. For\nexample, the following is also valid:\n\\begin{eqnarray}\nP(A, B, C | D) &=& P(A |D)P(B|A,D)P(C|B,A,D).\n\\end{eqnarray}\nIn fact, it's best to regard even ``unconditional'' probabilities such\nas $P(A)$ as being conditional on some prior information $I$, which is just\nleft out to keep the notation simple.\n\n\\subsection{Bayes' Rule}\nLooking at Equations~\\ref{product1} and~\\ref{product2}, they are both equations\nfor the same\nthing, $P(A,B)$. Therefore we can equate the right hand sides. Doing this gives\na result known as Bayes' rule:\n\\begin{eqnarray}\nP(A|B) &=& \\frac{P(A)P(B|A)}{P(B)}. \\label{bayes}\n\\end{eqnarray}\nBayes' rule will be used extensively throughout this course. You will need to\nknow it and know how to use it!\n\n\\section{The Sum Rule}\nThe sum rule is the second important rule of probability. A general statement\nof the sum rule is\n\\begin{align}\nP(A \\vee B) &= P(A) + P(B) - P(A, B).\\label{eqn:sum_rule}\n\\end{align}\nwhere $\\vee$ means logical {\\em or}.\n\nThe sum rule is often used to calculate the\nprobability of some statement\n$A$ when we only know the probability of $A$ conditional on some\nsome other statement $B$. Then we\ncan use the sum rule like this:\n\\begin{eqnarray}\nP(A) &=& P(A, B) + P(A, \\neg B)\\\\\n&=& P(B)P(A|B) + P(\\neg B)P(A|\\neg B).\n\\end{eqnarray}\nwhere the $\\neg$ symbol means ``not'', i.e. $\\neg B$ is the statement that\n$B$ is false. To understand\nthis formula, imagine we want to know the probability of $A$. There are\ntwo mutually exclusive ways that could happen: via $B$ being true, or via $B$\nbeing false. The first way has probability $P(B)P(A|B)$, and the second way\nhas probability $P(\\neg B)P(A|\\neg B)$.\n\nIf, instead of just two mutually exclusive and exhaustive\npathways $B$ and $\\neg B$, there are many, such as $B_1, ..., B_n$.\nThen the sum rule takes the form\n\\begin{eqnarray}\nP(A) &=& \\sum_{i=1}^n P(B_i)P(A|B_i).\n\\end{eqnarray}\nAs an exercise, you can try proving this version of the sum rule\nstarting from the simpler version of Equation~\\ref{eqn:sum_rule}.\n\nIn Bayesian statistics the sum rule is most often used to calculate the\nmarginal likelihood $P(D)$, and to marginalise out ``nuisance\nparameters'' from the posterior distribution. In STATS 331 we will mostly use\nMCMC to do the latter.\n\n\\section{Random Variables}\nThroughout this course I will use the term ``probability distribution'' to\nrefer to both the probability mass function for a discrete random variable, and\nthe probability density function for a continuous random variable. I will also\nuse a common shorthand notation.\n\n\\subsection{Discrete Random Variables}\nWe will also see quite a lot of random variables in this course (although\nwithout using that terminology very much, as I consider the word ``random'' to be\nworse than useless). A discrete\nrandom variable is just a quantity $X$ that has a countable number of possible\nvalues. A discrete random variable has a {\\it probability mass function}\nthat tells you the probability as a function of the {\\it possible} values $x$.\nFor example, the equation for the Poisson distribution (a useful discrete\ndistribution) is:\n\\begin{eqnarray}\nP(X=x) &=& \\frac{\\lambda^x e^{-\\lambda}}{x!}\\label{eq:poisson}\n\\end{eqnarray}\nfor $x \\in \\{0, 1, 2, 3, ...\\}$. The actual random variable is named $X$, and\n$x$ is just used so we can write the probabilities ($P(X=0), P(X=1), ...)$ as\na formula.\n\n\\subsection{Continuous Random Variables}\nContinuous random variables are those where the set of possibilities is\ncontinuous. For example, with a normal distribution, technically any real value\nis possible. Therefore it doesn't make sense to ask, for example, the probability\nthat $X=1.32$. The answer is zero because the total probability of 1 has to be\nspread among an infinite number of possibilities. Instead, we can ask the probability\nthat $X$ is in some region that has a nonzero size. In general, if $X$ has a\nprobability density function $f(x)$, then the probability that $X \\in [a, b]$ is:\n\\begin{eqnarray}\nP(a \\leq X \\leq b) &=& \\int_a^b f(x) \\, dx.\n\\end{eqnarray}\nNote the lower case $x$ in the probability density function. This is analogous\nto the lower case $x$ in the probability mass function of a discrete random\nvariable. Note that I won't often get you to do an integral analytically. One\nof the major reasons why MCMC is so awesome is that you can get away without\nhaving to do hard integrals!\n\n\\subsection{Shorthand Notation}\nThe notation of random variables can be cumbersome. For example, consider\ninferring a (discrete) parameter $Y$ from (discrete) data $X$. Bayes' rule gives us:\n\\begin{eqnarray}\nP(Y=y | X=x) &=& \\frac{P(Y=y)P(X=x|Y=y)}{P(X=x)}.\n\\end{eqnarray}\nThat's very verbose, so instead we use the shorthand:\n\\begin{eqnarray}\np(y | x) &=& \\frac{p(y)p(x|y)}{p(x)}.\n\\end{eqnarray}\nIn this notation we don't distinguish between the symbol for the random variable\nand the dummy variables that allow us to write the probability distribution as\na formula, we just use the lower case for everything. Despite this simplification,\neverything still works. Just read\n$p(y|x)$ as ``the probability distribution for $y$ given $x$'' and everything\nwill be fine. Astute readers may have noticed that when I gave the Poisson formula\n(Equation~\\ref{eq:poisson}), ``given $\\lambda$'' was implicit throughout.\n\nTo be clear when we are talking about a simple probability and when we are\ntalking about the probability distribution for a variable, I will use upper case\n$P$ for the former and lower-case $p$ for the latter.\n\n\\section{Useful Probability Distributions}\nIn the course we will study Bayesian models which involve the following\ndiscrete probability distributions: general (all probabilities given explicitly,\nsuch as in a Bayes' Box), binomial, Poisson, discrete uniform,\nnegative binomial, multinomial.\nWe may also use the following continuous distributions: uniform, normal,\nCauchy, student-$t$, beta, log-uniform, exponential, gamma, Dirichlet.\n\nWikipedia is an excellent resource for looking up all the properties of these\ndistributions, but I will also give various properties (e.g. the mean of a beta\ndistribution) and describe the distributions when we need them.\n\n", "meta": {"hexsha": "4e5589cbb47a207cdd3b8e30ed1d66fa98240abf", "size": 8421, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability.tex", "max_stars_repo_name": "xulinpan/stat331", "max_stars_repo_head_hexsha": "7ca22bf3ce2c43d1a3b5fd8ff22842bdeb87ecf5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 55, "max_stars_repo_stars_event_min_datetime": "2015-03-09T18:03:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-25T03:36:54.000Z", "max_issues_repo_path": "probability.tex", "max_issues_repo_name": "xulinpan/stat331", "max_issues_repo_head_hexsha": "7ca22bf3ce2c43d1a3b5fd8ff22842bdeb87ecf5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-07-07T05:00:32.000Z", "max_issues_repo_issues_event_max_datetime": "2015-07-10T08:48:27.000Z", "max_forks_repo_path": "probability.tex", "max_forks_repo_name": "xulinpan/stat331", "max_forks_repo_head_hexsha": "7ca22bf3ce2c43d1a3b5fd8ff22842bdeb87ecf5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2015-07-29T14:34:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-04T20:04:47.000Z", "avg_line_length": 46.5248618785, "max_line_length": 85, "alphanum_fraction": 0.7486046788, "num_tokens": 2281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.8991213664574069, "lm_q1q2_score": 0.8192611459540926}}
{"text": "\\section{Linear Mappings}\n\n\\subsection{Exercise 1}\n(a) $x \\in X \\implies x = \\sum_{i=1}^{n} k_i x_i \\implies T(x) = \\sum_{i=1}^{n} k_i T(x_i) \\in U$.\n\n(b) $T(x), T(y) \\in U \\implies T(x + y) \\in U \\implies x + y \\in X$.\n\n\\subsection*{Theorem 1}\n$x \\in X, y \\in N_T \\implies T(x + y) = T(x) + T(y) = T(x)$.\n\n\\subsection{Exercise 2}\n(a) Differentiation constant and sum rules imply linearity, and multiplication by $s$ is distributive.\nTake $p(s) = 1$ to see that $ST \\neq TS$.\n\n(b) Rotation by 90 degrees amounts to swapping and negating coordinates, which is linear.\nTake $p = (1, 1, 0)$ to see that $ST \\neq TS$.\n\n\\subsection{Exercise 3}\n(i) $T^{-1} (T(a + b)) = T^{-1} (T(a) + T(b)) = a + b = T^{-1} (T(a)) + T^{-1} (T(b))$.\n\n(ii) Composition of isomorphisms is an isomorphism, hence $ST$ is invertible.\n\n\\subsection{Exercise 4}\n(i) Let $T: X \\to U,\\: S: U \\to V$ and $l_v \\in V'$. \nThen $(ST)' (l_v) = l_v (ST) = (l_v S) T = (S' l_v) T = T' S' l_v$,\nsince $S' l_v \\in U'$. \n\n(ii) Follows from linearity of transpose (definition).\n\n(iii) Let $T: X \\to U$ be an isomorphism. Then $l_x = l_u T \\implies l_x T^{-1} = l_u$\nfor $l_u \\in U', \\: l_x \\in X'$.\n\n\\subsection{Exercise 5}\n$T''(l_{x'}) = l_{x'}T'$ where $l_{x'} \\in X''$ and $l_{x'}T' \\in U''$.\nSince we can identify elements in $X''$ and $U''$ with elements in $X$ and $ U$\nrespectively, we have that $T''$ assigns elements of $U$ to $X$.\n\n\\subsection*{Theorem 2'}\nSince $T': U' \\to X'$ we have $l_u \\in N_{T'} \\implies T'(l_u) = l_u T = 0$.\n$N_{T'}^{\\perp}$ consists of elements $l_{u'} | l_{u'} (l_u) = 0$.\nFrom $l_u Tx = 0$ we have that each $l_{u'}$ is identified with a $u \\in R_T$.\n\n\\subsection{Exercise 6}\nThe first two elements of $x$ are already 0 after applying $P$, so $P^2 = P$.\nLinearity follows from linearity of vector addition.\n\n\\subsection{Exercise 7}\n$P$ is linear since function addition is linear.\n$P^2 f = \\frac{f(x) + f(-x)}{4} + \\frac{f(x) + f(-x)}{4} = P f$.\n", "meta": {"hexsha": "e77b52bff04eff8acb87bfe7f347adb2958b0b3d", "size": 1940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear_Algebra_Lax/chapter_3.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Linear_Algebra_Lax/chapter_3.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Linear_Algebra_Lax/chapter_3.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.8, "max_line_length": 102, "alphanum_fraction": 0.6020618557, "num_tokens": 771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.8191558356605242}}
{"text": "\\section{Fields}\nWe begin our dive into the rigorous analysis of linear algebra by defining an algebraic construction call a \\emph{field}, which we need in order to properly define vector spaces later. In essence, a field has most of the important properties of the real numbers, namely the closure, commutativity, associativity, identity and inverse of addition and multiplication of any two elements in the field (except the product inverse of the field equivalent object for the number $0$). In a later section we will use fields to construct the general notion of \\emph{vector spaces}.\n\n\\setenumerate[1]{label*=\\arabic*.}\n\\begin{definition}{Field}{}\n\tA field $\\mathbb{F}$ is a set of objects together with two operations called \\emph{addition} and \\emph{multiplication} (denoted $+$ and $\\cdot$, respectively), for which the following axioms hold:\n\n\t\\begin{descitemize}\n\t\t\\item[Closure of under addition and multiplication] for any $a,b\\in\\mathbb{F}$,\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item $(a+b)\\in\\mathbb{F}$,\n\t\t\t\t\\item $(a\\cdot b)\\in\\mathbb{F}$.\n\t\t\t\\end{enumerate}\n\n\t\t\\item[Commutativity under addition multiplication] for any $a,b\\in\\mathbb{F}$,\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item $a+b=b+a$,\n\t\t\t\t\\item $a\\cdot b=b\\cdot a$.\n\t\t\t\\end{enumerate}\n\n\t\t\\item[Associativity under addition and multiplication] for any $a,b,c\\in\\mathbb{F}$,\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item $a+(b+c)=(a+b)+c$,\n\t\t\t\t\\item $a\\cdot(b\\cdot c)=(a\\cdot b)\\cdot c$.\n\t\t\t\\end{enumerate}\n\n\t\t\\item[Additive and multiplicative identity] there exist an element in $\\mathbb{F}$ called the \\textit{additive identity} and denoted by $0$, for which $a+0=a$ for any $a\\in\\mathbb{F}$.\n\t\t\t\n\t\t\tSimilarity, there exists an element in $\\mathbb{F}$ called the \\textit{multiplicative identity} and denoted by $1$, for which $a\\cdot1=a$ for any $a\\in\\mathbb{F}$.\n\n\t\t\\item[Additive and multiplicative inverses] for any element $a\\in\\mathbb{F}$ (except the additive identity) there exists:\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item $b\\in\\mathbb{F}$ such that $a+b=0$, and\n\t\t\t\t\\item $c\\in\\mathbb{F}$ such that $a\\cdot c=1$.\n\t\t\t\\end{enumerate}\n\t\t\t(usually $b$ is denoted as $-a$, while $c$ is denoted as $a^{-1}$)\n\n\t\t\\item[Distributivity of multiplication over addition] for any $a,b,c\\in\\mathbb{F}$,\n\t\t\t\\[\n\t\t\t\ta\\cdot(b+c) = (a\\cdot b) + (a\\cdot c).\n\t\t\t\\]\n\t\\end{descitemize}\n\\end{definition}\n\n\\subsection{Infinite fields}\nWe start with one of the most obvious examples of a field: the real numbers together with the standard addition and product.\n\n\\begin{theorem}{$\\bm{\\mathbb{R}}$ as a field}{R as a field}\n\tThe set of real numbers $\\mathbb{R}$ forms a field together with the standard addition and product.\n\\end{theorem}\n\nWe leave the proof of \\autoref{theorem:R as a field} to the reader, as it is pretty straight forward using the known properties of the standard addition and product over $\\mathbb{R}$ (and rather uninteresting). Instead, we jump forward to using \\autoref{theorem:R as a field} for proving the same idea about the complex numbers:\n\n\\begin{theorem}{$\\bm{\\mathbb{C}}$ as a field and more more more}{C as a field}\n\tThe set of complex numbers $\\mathbb{C}$ forms a field together with the addition and product operations as defined in \\autoref{sec:complex numbers} (namely \\autoref{eq:complex_addition}, \\autoref{eq:complex_product} and \\autoref{eq:complex_product_geometric}).\n\\end{theorem}\n\n\\begin{proof}{$\\bm{\\mathbb{C}}$ as a field}{C as a field}\n\t(note: in the following proof, equalities marked with $!$ use the respective property of the real numbers)\n\n\t\\begin{descitemize}\n\t\t\\item[Closure under both operations] for any two complex numbers $z_{1}=a+\\iu b$ and $z_{2}=c+\\iu d$,\n\t\t\t\\begin{listitemize}\n\t\t\t\\item[Addition] since addition in $\\mathbb{R}$ is closed, $(a+c)\\in\\mathbb{R}$ and $(b+d)\\in\\mathbb{R}$. Therefore\n\t\t\t\t\\[\n\t\t\t\t\tz = z_{1}+z_{2} = a+c + (b+d)\\iu\n\t\t\t\t\\]\n\t\t\t\tis also a complex number with $\\Re(z)=a+c$ and $\\Im(z)=b+d$.\n\t\t\t\\item[Multiplication] since multiplication in $\\mathbb{R}$ is also closed, $(ac-bd)\\in\\mathbb{R}$ and $(ad+bc)\\in\\mathbb{R}$. Therefore\n\t\t\t\t\\[\n\t\t\t\t\tz = z_{1} \\cdot z_{2} = ac-bd + (ad+bc)\\iu\n\t\t\t\t\\]\n\t\t\t\tis a complex number with $\\Re(z)=ac-bdc$ and $\\Im(z)=ad+bc$.\n\t\t\t\\end{listitemize}\n\t\t\n\t\t\\item[Commutativity of both operation] for any two complex numbers $z_{1}=a+\\iu b$ and $z_{2}=c+\\iu d$,\n\t\t\t\\begin{listitemize}\n\t\t\t\\item[Addition] since addition in $\\mathbb{R}$ is commutative, $a+c=c+a$ and $b+d=d+b$. Therefore\n\t\t\t\t\\[\n\t\t\t\t\tz_{1} + z_{2} = a+c + (b+d)\\iu \\overset{!}{=} c+a + (d+b)\\iu = z_{2}+z_{2}.\n\t\t\t\t\\]\n\t\t\t\\item[Multiplication] since multiplication in $\\mathbb{R}$ is also commutative, $ac-bd = ca-db$ and $ad+bc=da+cb$. Therefore\n\t\t\t\t\\[\n\t\t\t\t\tz_{1} \\cdot z_{2} = ac-bd + (ad+bc)\\iu \\overset{!}{=} ca-db + (da+cb)\\iu = z_{2} \\cdot z_{1}.\n\t\t\t\t\\]\n\t\t\t\\end{listitemize}\n\t\t\n\t\t\\item[Associativity of both operation] for any three complex numbers $z_{1}=a+\\iu b,\\ z_{2}=c+\\iu d$ and $z_{3}=g+\\iu h$ (where $a,b,c,d,g,h\\in\\mathbb{R}$\\footnote{The letters $g$ and $h$ are used instead of $e$ and $f$ to avoid confusion with Eurler's constant and the common notation for real functions, respectively.}),\n\t\t\t\\begin{listitemize}\n\t\t\t\\item[Addition] since addition in $\\mathbb{R}$ is associative, $a+(c+g)=(a+c)+g$ and $b+(d+h)=(b+d)+h$. Therefore\n\t\t\t\t\\[\n\t\t\t\t\tz_{1} + (z_{2}+z_{3}) = a+(c+g) + [b+(d+h)]\\iu \\overset{!}{=} (a+c)+g + [(b+d)+h]\\iu = (z_{1}+z_{2}) + z_{3}.\n\t\t\t\t\\]\n\t\t\t\\item[Multiplication] since multiplication in $\\mathbb{R}$ is also associative, the following equalities apply:\n\t\t\t\t\\begin{align*}\n\t\t\t\t\ta\\cdot(c\\cdot g) &= (a\\cdot c)\\cdot g,\\\\\n\t\t\t\t\tb\\cdot(c\\cdot h) &= (b\\cdot c)\\cdot h,\\\\\n\t\t\t\t\ta\\cdot(d\\cdot h) &= (a\\cdot d)\\cdot h,\\\\\n\t\t\t\t\tb\\cdot(d\\cdot g) &= (b\\cdot d)\\cdot g,\\\\\n\t\t\t\t\ta\\cdot(c\\cdot h) &= (a\\cdot c)\\cdot h,\\\\\n\t\t\t\t\ta\\cdot(d\\cdot g) &= (a\\cdot d)\\cdot g,\\\\\n\t\t\t\t\tb\\cdot(c\\cdot g) &= (b\\cdot c)\\cdot g,\\\\\n\t\t\t\t\tb\\cdot(d\\cdot h) &= (b\\cdot d)\\cdot h.\\\\\n\t\t\t\t\\end{align*}\n\t\t\t\tTherefore,\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tz_{1}\\cdot(z_{2} \\cdot z_{3}) &= a\\cdot(c\\cdot g) - a\\cdot(d\\cdot h) - b\\cdot(c\\cdot h) - b\\cdot(d\\cdot g)\\\\ &+[a\\cdot(c\\cdot h) + a\\cdot(d\\cdot g) + b\\cdot(c\\cdot g) - b\\cdot(d\\cdot h)]\\iu\\\\\n\t\t\t\t\t&\\overset{!}{=} (a\\cdot c)\\cdot g - (a\\cdot d)\\cdot h - (b\\cdot c)\\cdot h - (b\\cdot d)\\cdot g\\\\ &+[(a\\cdot c)\\cdot h + (a\\cdot d)\\cdot g + (b\\cdot c)\\cdot g - (b\\cdot d)\\cdot h]\\iu\\\\\n\t\t\t\t\t&= (z_{1} \\cdot z_{2}) \\cdot z_{3}.\n\t\t\t\t\\end{align*}\n\t\t\t\\end{listitemize}\n\n\t\t\\item[Identity for both operations]~\\\\\n\t\t\t\\begin{listitemize}\n\t\t\t\\item[Addition] the complex number $0=0+0i$ is the complex addition identity: for any real number $x\\in\\mathbb{R},\\ x+0=x$. Therefore, for any complex number $z=a+\\iu b$,\n\t\t\t\t\\[\n\t\t\t\t\tz+0 = a+\\iu b + 0+0i = a+0 + (b+0)\\iu \\overset{!}{=} a+\\iu b.\n\t\t\t\t\\]\n\t\t\t\\item[Multiplication] the complex number $1=1+0\\iu$ is the complex multiplication identity: for any real number $x\\in\\mathbb{R},\\ x\\cdot1=x$ and $x\\cdot0=0$. Therefore, for any complex number $z=a+\\iu b$,\n\t\t\t\t\\[\n\t\t\t\t\tz\\cdot1 = (a+\\iu b)\\cdot(1+0\\iu) \\overset{!}{=}a\\cdot1-\\cancel{b\\cdot0\\iu^{2}} + (\\cancel{a\\cdot0\\iu}+b\\cdot1)\\iu = a+\\iu b.\n\t\t\t\t\\]\n\n\t\t\t\\end{listitemize}\n\t\t\n\t\t\\item[Inverse for both operations]~\\\\\n\t\t\t\\begin{listitemize}\n\t\t\t\\item[Addition] for any complex number $z_{1}=a+\\iu b$, the number $z_{2}=-a-\\iu b$ is also a complex number for which\n\t\t\t\t\\[\n\t\t\t\t\tz_{1} + z_{2} = a+\\iu b + -a-\\iu b \\overset{!}{=} a-a + (b-b)\\iu = 0 + 0\\iu = 0.\n\t\t\t\t\\]\n\t\t\t\\item[Multiplication] for any complex number $z=r\\eu^{\\theta i}$ where $r\\neq0$, the number $z^{-1}=\\frac{1}{r}\\eu^{-\\iu\\theta}$ is also a complex number for which\n\t\t\t\t\\[\n\t\t\t\t\tz \\cdot z^{-1} = r\\eu^{\\iu\\theta} \\cdot \\frac{1}{r}\\eu^{-\\iu\\theta} \\overset{!}{=} \\frac{r}{r}\\eu^{\\cancel{\\iu\\theta - \\iu\\theta}} = 1\\cdot1 = 1.\n\t\t\t\t\\]\n\t\t\t\t\n\t\t\tNote: for $z=a+\\iu b$,\n\t\t\t\\[\n\t\t\t\tz^{-1} = \\frac{1}{r}\\eu^{-\\iu\\theta} = \\frac{1}{|z|}\\cdot\\frac{a-\\iu b}{|z|} = \\frac{1}{|z|}\\cdot\\frac{\\conj{z}}{|z|} = \\frac{\\conj{z}}{|z|^{2}}.\n\t\t\t\\]\n\t\t\tTherefore, for any $z\\neq0,\\ z^{-1} = \\frac{\\conj{z}}{|z|^{2}}$.\n\t\t\t\\end{listitemize}\n\n\t\t\\item[Distributivity of multiplication over addition] for any $z_{1}=a+\\iu b,\\ z_{2}=c+\\iu d$ and $z_{3}=g+\\iu h$,\n\t\t\t\\begin{align*}\n\t\t\t\tz_{1}\\cdot(z_{2}+z_{3}) &= (a+\\iu b)\\cdot(c+\\iu d + g+\\iu h) = (a+\\iu b)\\cdot(c+g + [d+h]\\iu)\\\\\n\t\t\t\t&= ac + ag + (bd)\\iu^{2} + (bh)\\iu^{2}\\\\\n\t\t\t\t&+ (ad)\\iu + (ah)\\iu + (bc)\\iu + (bg)\\iu\\\\\n\t\t\t\t&= ac + ag - bd - bh + (ad + ah + bc + bg)\\iu\\\\\n\t\t\t\t&= ac-bd + (ad+bc)\\iu + ag-bh + (ah+bg)\\iu\\\\\n\t\t\t\t&= (z_{1}\\cdot z_{2}) + (z_{1}\\cdot z_{3}).\n\t\t\t\\end{align*}\n\t\\end{descitemize}\n\\end{proof}\n\nThe sets $\\mathbb{R}$ and $\\mathbb{C}$ are examples of \\emph{infinite fields}, since they each have infinite number of elements. The set $\\mathbb{Q}$ (rational numbers) can be shown to also be an infinite field, however unlike $\\mathbb{R}$ and $\\mathbb{C}$ it has \\textbf{countable} number of elements, i.e. each number in $\\mathbb{Q}$ can be assigned an index $1,2,3,\\dots$\\footnote{For proof, see \\ldots}.\n\n\\begin{challenge}{$\\bm{\\mathbb{Q}}$ as a field}{Q as a field}\n\tProve that $\\mathbb{Q}$ (together with the usual addition and product operation) is indeed a field.\n\\end{challenge}\n\n\\subsection{Finite fields}\nWhile all three examples of fields we encountered so far have each an infinite number of elements, some fields only have a finite number of elements (called their \\emph{order}). For example, consider the set $S=\\{0,1,a,b\\}$ and the addition and product operations described using the following tables (left table describes addition, right table describes multiplication):\n\n\\centering\n\\begin{tabular}[]{>{\\bfseries}c|cccc}\n\t\\rowstyle{\\bfseries} % why doesn't this work? :(\n\t$\\bm{+}$ & 0 & 1 & a & b\\\\\n\t\\hline\n\t\\rule{0em}{2.65ex}%\n\t0 & 0 & 1 & a & b\\\\\n\t1 & 1 & 0 & b & a\\\\\n\ta & a & b & 0 & 1\\\\\n\tb & b & a & 1 & 0\\\\\n\\end{tabular}\\hspace{2cm}\n\\begin{tabular}[]{>{\\bfseries}c|cccc}\n\t\\rowstyle{\\bfseries}\n\t$\\bm{\\cdot}$ & 0 & 1 & a & b\\\\\n\t\\hline\n\t\\rule{0em}{2.65ex}%\n\t0 & 0 & 0 & 0 & 0\\\\\n\t1 & 0 & 1 & a & b\\\\\n\ta & 0 & a & b & 1\\\\\n\tb & 0 & b & 1 & a\\\\\n\\end{tabular}\n\n\\flushleft\nBy examining the tables above, several points become clear:\n\\begin{itemize}\n\t\\item all the possible combinations of operands in both addition and multiplication give elements from $S$ itself, meaning that the set is closed under both these operations.\n\t\\item both tables are symmetric around their main diagonal, meaning that both addition and multiplication are commutative operations.\n\t\\item in the addition table, the first row and first column both show that $x+0=x$ for any $x\\in S$, meaning that $0$ is the additive identity in $S$.\n\t\\item in the product table, the second row and second column both show that $x\\cdot1=x$ for any $x\\in S$, meaning that $1$ is the multiplicative identity in $S$.\n\t\\item in the addition table, the element $0$ appears in each row and each column exactly once. This means that every element $x$ has a single additive inverse $y\\in S$.\n\t\\item in the product table, the element $1$ appears in each row and each column exactly once, except for the first row and first column. This means that every element $x\\neq 0$ has a single multiplicative inverse $z\\in S$.\n\\end{itemize}\n\nWe therefore only need to prove two points to show that $S$ is a field together with the operations described by the above tables: associativity of both operations and distributivity of multiplication over addition. We leave these proofs as a challenge to the reader. Such a field is sometime denoted as $\\mathbb{F}_{4}$. There are, of course, infinitely many finite fields.\n\n\\subsection{Modulo fields}\nAnother example of finite fields are sets of integers of the form $\\{0,1,2,3,\\dots,n\\}$ where $n$ is a prime, together with \\emph{modular addition} and \\emph{modular product}. To understand modular arithmetics, we recall the fact that on a circle, an angle can have a negative value but also greater than $\\ang{360}$ values are possible (see \\autoref{fig:angles equivalency}): $\\ang{390}$ is equivalent to $\\ang{30}$, $\\ang{-30}$ is equivalent to $\\ang{330}$, etc. The set of integer values $\\ang{0},\\ang{1},\\ang{2},\\dots,\\ang{359}$ on a circle is an example of a modular set: if for example we add together two angles of values $\\deg{100}$ and $\\ang{300}$ we get the equivalent angle $\\deg{60}$. If we subtract $\\deg{300}$ from $\\deg{100}$ the result is an angle of $\\deg{160}$.\n\nWe say that on a circle, the values $\\ang{360}, \\ang{720}, -\\ang{360}$ etc. are all \\emph{congruent} to $0$ modulo $360$. In mathematical notation we represent this fact as e.g.\n\\begin{equation}\n\t720 \\equiv 0 \\pmod{360}.\n\t\\label{eq:mod 360}\n\\end{equation}\n\nNote that from this point forward we drop the degrees unit, and deal with pure integers.\nThe notation for the set $\\{0,1,2,\\dots,359\\}$ is $\\mathbb{Z}_{360}$. Generally speaking, the set $\\{0,1,2,\\dots,n\\}$ is denoted as $\\Z{n}$.\n\n\\begin{note}{About modulo set notation}{}\n\tIt is not common to use the notation $\\Z{n}$ for the modulo-$n$ set, since it is also used for a different algebraic construct, namely the $n$-adic ring. However, due to the simplicity of the notation, and the fact that we don't discuss rings in this chapter we are using it in this book. Common notations for the set are $\\mathbb{Z}\\mathbin{/} n\\mathbb{Z}$ and $\\mathbb{Z}\\mathbin{/} n$.\n\\end{note}\n\nAddition and multiplication on $\\Z{n}$ is done by the following rather straight forward definition:\n\\begin{definition}{Operations in $\\bm{\\Z{n}}$}{operations in Zn}\n\tIn the set $\\Z{n}$ addition and multiplication are defined as the following:\n\t\\begin{descitemize}\n\t\\item[Addition] for any two elements $a,b\\in\\Z{n},\\ a+b\\coloneqq(a+b)\\pmod{n}$.\n\t\\item[Multiplication] for any two elements $a,b\\in\\Z{n},\\ a\\cdot b\\coloneqq(a\\cdot b)\\pmod{n}$.\n\t\\end{descitemize}\n\\end{definition}\n\n\\begin{example}{Operations in $\\bm{\\Z{n}}$}{}\n\tThe tables below show addition and multiplication results of numbers in different modulo sets $\\Z{n}$ for some values of $n$:\n\n\t\\vspace{1em}\n\t\\centering\n\t\\begin{tabular}[]{lll}\n\t\t\\toprule\n\t\t$n$ & $2+3$ & $2\\cdot3$\\\\\n\t\t\\midrule\n\t\t$4$  & $1$ & $2$\\\\\n\t\t$5$  & $0$ & $1$\\\\\n\t\t$6$  & $5$ & $0$\\\\\n\t\t$7$  & $5$ & $6$\\\\\n\t\t$8$  & $5$ & $6$\\\\\n\t\t$9$  & $5$ & $6$\\\\\n\t\t$10$ & $5$ & $6$\\\\\n\t\t$11$ & $5$ & $6$\\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\t\\hspace{1cm}\n\t\\begin{tabular}[]{lll}\n\t\t\\toprule\n\t\t$n$ & $4+7$ & $4\\cdot7$\\\\\n\t\t\\midrule\n\t\t$8$  & $3$  & $4$\\\\\n\t\t$9$  & $2$  & $1$\\\\\n\t\t$10$ & $1$  & $8$\\\\\n\t\t$15$ & $11$ & $13$\\\\\n\t\t$20$ & $11$ & $8$\\\\\n\t\t$27$ & $11$ & $1$\\\\\n\t\t$28$ & $11$ & $0$\\\\\n\t\t$30$ & $11$ & $28$\\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{example}\n\n\\autoref{fig:Z5 periodic} shows the equivalency between integers and the elements of $\\Z{5}$.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\pgfmathsetmacro{\\d}{1.75}\n\t\t\\pgfmathsetmacro{\\h}{-1.3}\n\t\t\\foreach \\k in {-10,-9,...,9}{\n\t\t\t\\pgfmathsetmacro{\\kp}{int(mod(\\k+20,5))}\n\t\t\t\\node (\\k) at ({\\k/\\d},0) {$\\k$};\n\t\t\t\\node (z5\\k) at ({\\k/\\d},\\h) {$\\kp$};\n\t\t\t\\draw[->, >=stealth, densely dashed, xblue] (\\k.south) -- (z5\\k.north);\n\t\t}\n\t\t\\node (Zdots) at ({-11/\\d},0) {$\\dots$};\n\t\t\\node (Z5dots) at ({-11/\\d},\\h) {$\\dots$};\n\t\t\\node at ({10/\\d},0) {$\\dots$};\n\t\t\\node at ({10/\\d},\\h) {$\\dots$};\n\t\t\\node[left of=Zdots] (Z) {$\\mathbb{Z}$};\n\t\t\\node[left of=Z5dots] (Z5) {$\\Z{5}$};\n\t\t\\draw[->, >=stealth, densely dashed, xblue] (Z.south) -- (Z5.north);\n\t\\end{tikzpicture}\n\t\\caption{An example of the periodicity of $\\Z{5}$: the top numbers are the ordinary integers, each showing their respective congruent modulo $5$ below (blue dashed arrow).}\n\t\\label{fig:Z5 periodic}\n\\end{figure}\n\nOnly the sets $\\Z{n}$ for which $n$ is a prime number are also fields. Let's define this property precisely:\n\n\\begin{theorem}{$\\bm{\\Z{p}}$ is a field}{Zp is a field}\n\tAny modulo set $\\Z{p}$ where $p$ is a prime number greater than $1$ is also a field together with the operations as defined in \\autoref{def:operations in Zn}.\n\\end{theorem}\n\nIn order to prove \\autoref{theorem:Zp is a field} we use two lemmas: the first is known as \\emph{B\\'ezout\u2019s lemma}:\n\\begin{lemma}{B\\'ezout's lemma}{bezout}\n\tFor any two positive integers $a,b$ there exist two integers $x,y$ such that\n\t\\[\n\t\t\\gcd{a}{b} = xa+yb.\n\t\\]\n\\end{lemma}\n\n\\begin{note}{$\\bm{\\gcd{a}{b}}$}{gcd}\n\t$\\gcd{a}{b}$ is the \\emph{greatest common divisor} of the two integers $a$ and $b$. For example, $\\gcd{36}{24}=12$ since the divisors of $36$ are $1,\\ 2,\\ 3,\\ 4,\\ 6,\\ 9,\\ 12,\\ 18,\\ 36$,\\ and the divisors of $24$ are $1,\\ 2,\\ 3,\\ 4,\\ 6,\\ 8,\\ 12,\\ 24$.\n\\end{note}\n\nAn example of B\\'ezout's lemma is the following:\n\n\\begin{example}{B\\'ezout's lemma in action}{bezout}\n\tFor the two positive integers $a=60,\\ y=114$\n\t\\[\n\t\t\\gcd{60}{114}=6.\n\t\\]\n\tTherefore, B\\'ezout's lemma says that there exist two integers $x,y$ such that\n\t\\[\n\t\t6 = 60x + 114y.\n\t\\]\n\tIndeed, two such integers exist: $x=2$ and $y=-1$.\n\\end{example}\n(SHOULD WE PROVE THE LEMMA?..)\n\nThe second lemma we use is the following:\n\\begin{lemma}{$\\bm{\\gcd{n}{p}=1}$}{gcd(n,p)=1}\n\tGiven a positive prime number $p$, then for any positive integer $n<p$,\n\t\\[\n\t\t\\gcd{p}{n}=1.\n\t\\]\n\\end{lemma}\n\nProving the lemma:\n\\begin{proof}{$\\bm{\\gcd{n}{p}=1}$}{gcd(n,p)=1}\n\tWe assume that $\\gcd{p}{n} \\neq 1$. Then there exist an integer $a\\leq n<p$ which divides both $n$ and $p$, meaning that $p$ has a divider, contrary to the assumption that $p$ is a prime number. Therefore $\\gcd{n}{p}$ must equal $1$.\n\\end{proof}\n\nNow we can proceed to the proof of \\autoref{theorem:Zp is a field}:\n\n\\begin{proof}{$\\bm{\\Z{p}}$ is a field}{}\n\t\\begin{descitemize}\n\t\\item[Closure under both operations] the definition of the modulo operator limit any $M\\pmod{p}$ (where $M\\in\\mathbb{Z}$) to be in $[0,p-1]$. Therefore the result of using the operators given in \\autoref{def:operations in Zn} must be within the same range, and thus in $\\Z{p}$.\n\n\t\\item[Commutativity and associativity of both operations] for any two numbers $a,b\\in\\Z{p}$ the result $a+b$ and $a\\cdot b$ under $\\mathbb{Z}$ is both commutative and associative. Therefore the result modulo $n$ is the same no matter the order of operations.\n\n\t\\item[Additive identity] the number $0\\in\\Z{p}$ is the additive identity, since for each $a\\in\\Z{p},\\ a+0=a$.\n\t\n\t\\item[Multiplicative identity] the number $1\\in\\Z{p}$ is the additive identity, since for each $a\\in\\Z{p},\\ a\\cdot1=a$.\n\n\t\\item[Additive inverse] for each $a\\in\\Z{p}$ the element $n=p-a$ is in $\\Z{p}$ since $p>a$. Adding $n$ to $a$ results in $0$:\n\t\t\\[\n\t\t\ta+n = a+(p-a) = p \\equiv 0\\pmod{p}.\n\t\t\\]\n\t\n\t\\item[Multiplicative inverse] let $a\\in\\Z{p}$ and $a\\neq0$. Since $p$ is a prime, $\\gcd{a}{p}=1$ and from B\\'ezout's theorem we know that there exist two integers $x,y$ such that\n\t\t\\[\n\t\t\txa + yp = 1.\n\t\t\\]\n\t\tRearrangement gives $p = \\frac{1-xa}{y}$ meaning that $p$ divides $1-xa$, and thus\n\t\t\\[\n\t\t\txa\\equiv1\\pmod{p}.\n\t\t\\]\n\t\tTherefore $x$ is the multiplicative inverse of $a$.\n\t\n\t\\item[Distributivity of multiplication over addition] \\ldots\n\t\\end{descitemize}\n\\end{proof}\n\nThe only part of the proof that uses the fact that $p$ is a prime number is the multiplicative inverse. When $n$ is not a prime, $\\Z{n}$ is not a field.\n\n\\begin{challenge}{$\\bm{\\Z{n}}$ is not a field when $n$ is not a prime number}{}\n\tProve that the modulo set $\\Z{n}$ where $n$ is \\textbf{not} a prime number, is not a field.\n\n\t(\\textbf{hint}: what property of prime numbers is used in the above proof to show that there is always a multiplicative inverse in $\\Z{p}$ where $p$ is prime?)\n\\end{challenge}\n", "meta": {"hexsha": "ad662a0317d9f2f49305e7defc378e2aaaee180a", "size": 19325, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/linear_algebra_rigorous/fields.tex", "max_stars_repo_name": "JASory/maths_book", "max_stars_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-25T20:02:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T17:57:59.000Z", "max_issues_repo_path": "chapters/linear_algebra_rigorous/fields.tex", "max_issues_repo_name": "JASory/maths_book", "max_issues_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2022-01-17T05:01:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-20T06:18:24.000Z", "max_forks_repo_path": "chapters/linear_algebra_rigorous/fields.tex", "max_forks_repo_name": "JASory/maths_book", "max_forks_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2022-01-17T10:15:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-02T10:45:13.000Z", "avg_line_length": 52.2297297297, "max_line_length": 779, "alphanum_fraction": 0.6481241915, "num_tokens": 6921, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.8976953003183444, "lm_q1q2_score": 0.8190896573756671}}
{"text": "\n\\subsection{Cantors theorem}\n\nThe cardinality of the powerset is strictly greater than the cardinality of the underlying set.\n\nThat is, \\(|P(s)|<|s|\\).\n\nThis applies to finite sets and infinite sets. In particular, this means that the powerset of the natural numbers is bigger than the natural numbers.\n\n\\subsubsection{Proof}\n\nIf one set is at least as big as another, then then is a surjection from that set to the other.\n\nThat is, if we can prove that there is no surjection from a set to its powerset, then we have proved the theorem.\n\nWe consider \\(f(s)\\). If there is a surjection, then for every subset of \\(s\\) there should be a mapping from \\(s\\) to that subset.\n\nWe take set \\(s\\) and have the powerset of this, \\(P(s)\\).\n\nConsider the set:\n\n\\(A=\\{x\\in s|x\\not\\in f(x)\\}\\)\n\nThat is, the set of all elements of \\(s\\) which do not map to the surjection.\n\n", "meta": {"hexsha": "bbf442b2578ad6d21e009a23ff3484e862f9998a", "size": 863, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sets/02-03-cantor.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sets/02-03-cantor.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sets/02-03-cantor.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.1923076923, "max_line_length": 149, "alphanum_fraction": 0.7230590962, "num_tokens": 225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308036221031, "lm_q2_score": 0.8774767762675405, "lm_q1q2_score": 0.8190638524311427}}
{"text": "\\section{Information Theory}\nInformation Theory revolves around quantifying how much information is present\nin a signal. The basic intuition lies in the fact that learning an unlikely\nevent has occured is more informative than learning that a likely event has\noccured. The basics are:\n\\begin{enumerate}\n  \\item Likely events should have low information content, and in the extreme\n  case, events that are guaranteed to happen should have no information content\n  whatsoever.\n  \\item Less likely events should have higher information content.\n  \\item Independent events should have additive information.\n\\end{enumerate}\nWe satisfy all three properties by defining self-information of an event $x$\nfor a probability distribution $P$ as:\n\\begin{equation}\n  I(x) = -\\log P(x)\n\\end{equation}\nWe can quantify the amount of uncertainty in a\ndistribution using Shannon entropy:\n\\begin{equation}\n  H ( P ) = \\mathbb { E } _ { \\mathrm { x } \\sim P } [ I ( x ) ] = - \\mathbb { E } _ { \\mathrm { x } \\sim P } [ \\log P ( x ) ]\n\\end{equation}\nWhich in the discrete setting is written as:\n\\begin{equation}\n  H ( P ) = -\\sum_{x} P(x) \\log P(x)\n\\end{equation}\nIn other words, the Shannon entropy of a distribution is the expected amount\nof information in an event drawn from that distribution. It gives a lower bound\non the number of bits needed on average to encode symbols drawn\nfrom a distribution $P$. If we have two separate probability distributions\n$P(x)$ and $Q(x)$ over the same random variable $\\mathrm{x}$, we can measure how\ndifferent these two distributions are using the Kullback-Leibler (KL)\ndivergence:\n\\begin{equation}\n  \\begin{split}\n    D _ { \\mathrm { KL } } ( P \\| Q ) \\quad =& \\quad \\mathbb { E } _ { \\mathbf { x } \\sim P } \\left[ \\log \\frac { P ( x ) } { Q ( x ) } \\right]\\\\\n    \\\\\n    =& \\quad \\mathbb { E } _ { \\mathbf { x } \\sim P } \\left[ \\log P ( x ) - \\log Q ( x ) \\right] \\\\\n    \\\\\n    =& \\quad \\sum_x P(x) \\frac{\\log P(x)}{\\log Q(x)} \\\\\n  \\end{split}\n\\end{equation}\nIn the case of discrete variables, it is the extra amount of information\nneeded to send a message containing symbols drawn from probability distribution\n$P$, when we use a code that was designed to minimize the length of messages\ndrawn from probability distribution $Q$. The KL divergence is always\nnon-negative, and is $0$ if and only if $P$ and $Q$ are the same. We can\nrelate the KL divergence to cross-entropy.\n\\begin{equation}\n  \\begin{split}\n    H(P, Q) \\quad =& \\quad H(P) + D _ { \\mathrm { KL } } ( P \\| Q ) \\\\\n    \\\\\n    =& \\quad - \\mathbb { E } _ { \\mathbf { x } \\sim P } \\left[ \\log Q ( x ) \\right]\\\\\n    \\\\\n    =& \\quad -\\sum_x P(x) \\log Q(x) \\\\\n  \\end{split}\n\\end{equation}\nMinimizing the cross-entropy with respect to $Q$ is equivalent to\nminimizing the KL divergence, because $Q$ does not participate in the\nomitted term (entropy is constant).\n", "meta": {"hexsha": "7edf6db30541ac3dedd2649eb2e55088acafdaae", "size": 2839, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/information_theory.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/information_theory.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/information_theory.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.5409836066, "max_line_length": 145, "alphanum_fraction": 0.6882705178, "num_tokens": 796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897542390751, "lm_q2_score": 0.8705972650509008, "lm_q1q2_score": 0.8190489870284479}}
{"text": "\\chapter{One-Dimensional Discrete Fourier Transforms}\n\\footnote{For more detail, see Olver and Shakiban~\\cite{OlvSha06}.} The discrete Fourier transform (DFT) takes a function sampled at a finite number of points and finds the coefficients for the linear combination of trigonometric polynomials that best approximates the function; the number of trigonometric polynomials used is equal to the number of sample points.  Suppose we have a function $f(x)$ which is defined on the interval $a \\leq x \\leq b$. Due to memory limitations, a computer can only store values at a finite number of sample points, i.e. $a \\leq x_0 < x_1 < ... <x_n \\leq b$. For our purposes these points will be equally spaced, for example $x_1-x_0=x_3-x_2$, and so we can write\n\\begin{eqnarray}\nx_j = a +jh, \\qquad j=0,1,2,...,n\n\\end{eqnarray}\nwhere $x_j$ are the \\emph{sample points}, $n$ is the number of sample points and\n\\begin{eqnarray}\n h=\\frac{b-a}{n}.\n\\end{eqnarray}\nIt is convenient to use the \\emph{standard interval}, for which $0 \\leq x \\leq 2\\pi$. Rewriting $x$ in terms of standard interval yields\n\\begin{eqnarray}\nx_0=0,x_1=\\frac{2\\pi}{n},x_2=\\frac{4\\pi}{n},x_j=\\frac{2j\\pi}{n},...,x_{n-1}=\\frac{2(n-1) \\pi}{n}\n\\end{eqnarray}\nNotice how $x_n=2\\pi$ is omitted;  periodicity implies that the value of the function at $2\\pi$ is the same as the value of the function at $0$, so it need not be included. We will introduce the DFT using the language of linear algebra. Much of this formalism carries over to continuous functions that are being approximated. It also makes it easier to understand the computer implementation of the algorithms. Many computer packages and programs are optimized to perform calculations through matrix operations, so the formalism is also useful when actually calculating transforms. We write the approximation to $f(x)$ at the sample points as a finite dimensional vector\n\\begin{eqnarray}\n\\bm{f}=(f_0,f_1,...,f_{n-1})^{T}=(f(x_0),f(x_1), ... ,f(x_{n-1}))\n\\end{eqnarray}\nwhere\n\\begin{eqnarray}\n f_j=f(x_j)=f \\left(\\frac{2 j \\pi}{n} \\right).\n\\end{eqnarray}\nThe DFT decomposes the sampled function $f(x)$ into a linear combination of complex exponentials, $\\exp(ikx)$ where $k$ is an index. Since\n\\begin{eqnarray}\n\\exp(ikx)=\\cos(kx)+i\\sin(kx),\n\\end{eqnarray}\nwe also obtain an expansion in trigonometric functions, which may be more familiar from courses in calculus and differential equations. Since the function is sampled at $n$ points, the highest frequency of oscillation that can be resolved will have $n$ oscillations. Any frequencies higher than $n$ in the original function are not adequately resolved and cause an \\emph{aliasing} error (see, for example, Boyd~\\cite{Boy01} or Uecker~\\cite{Uec09} for more on this). This error can be reduced by sampling at a greater number of points so that the number of approximating exponentials functions can also be increased. There is a tradeoff between increasing the accuracy of the simulation and the time required for the simulation to complete. For many cases of scientific and practical interest, simulations with up to thousands of grid points can be computed relatively quickly. Below we explain how a function $f(x)$ can be approximated by an interpolating trigonometric polynomial $p(x)$ so that \n\\begin{eqnarray}\nf(x) \\approx p(x)=c_0+c_1e^{2ix}+c_2e^{2ix}+...+c_{n-1} e^{(n-1)ix}=\\sum\\limits_{k=0}^{n-1} c_k e^{ikx}\n\\end{eqnarray} \nThe $\\approx$ symbol means that $f(x)$ and $p(x)$ agree on each sample point, i.e., $f(x_j)=p(x_j)$ for each $j=0,1,...n-1$, but the interpolated polynomial $p(x)$ is only an approximation of the true solution $f(x)$ away from the sample points.. The $c_n$ are called discrete \\emph{Fourier coefficients} and are what we will be looking to solve for. $p(x)$ represents the values of interpolating trigonometric polynomial of degree $\\leq n-1$, so if we have the values of these coefficients then we have a function we can use as an approximation of $f(x)$. Since we are working in a finite-dimensional vector space, a useful approach is to rewrite the discrete Fourier series as a vector. We let\n\\begin{eqnarray}\n\\bm{\\omega_k}&=&(e^{ikx_0},e^{ikx_1},e^{ikx_2},...,e^{ikx_n})^T \\\\\n&=& (1,e^{2k \\pi i/n},e^{4k\\pi i/n},...,e^{2(n-1)k\\pi i/n})^T,\n\\end{eqnarray}\nwhere $k=0,1,...,n-1$. The interpolation conditions, $f(x_j)=p(x_j)$, can also be rewritten in vectorial form\n\\begin{eqnarray}\\label{eq:FourExp}\n\\bm{f}=c_0\\bm{\\omega_0}+c_1\\bm{\\omega_1}+...+c_{n-1} \\bm{\\omega_{n-1}}.\n\\end{eqnarray}\nHere $\\bm f$ is a vector evaluated at the sample points, which is decomposed into vectors $\\bm{\\omega}_k$, much as a vector in three dimensional space can be decomposed into the components in the $x$, $y$ and $z$ directions. The DFT allows us to compute the coefficients $c_i$ given the value of the function at the sample points. This may at first seem unmotivated, but in many applications, such as solving differential equations, it is easier to manipulate a linear combination of trigonometric polynomials,  $\\bm{\\omega_0},...,\\bm{\\omega_{n-1}}$, than it is to work with the original function. In order to solve for $c_k$, we use the orthonormality of the basis elements $\\bm{\\omega_0},...,\\bm{\\omega_{n-1}}$. We now explain how this is done \\footnote{For a more detailed explanation see Olver and Shakiban~\\cite{OlvSha06}.}. \n\nDefine $\\xi_n=e^{2\\pi i/n}$. We observe that \n\\begin{equation}\n\\left(\\xi_n\\right)^n=\\exp\\left(\\frac{2\\pi i n}{n}\\right)=\\cos(2\\pi ) +i\\sin(2\\pi )=1\n\\end{equation}\nFor this reason $\\xi_n$ is known as the primitive $n^{\\text{th}}$ root of unity. Note also that for $0\\leq k < n$, we have that $(\\xi_n^k)^n=1$, so all other roots of unity when taken to the power $n$ can be obtained from the primitive $n^{\\text{th}}$ root of unity. We will use this to perform the DFT algorithm to calculate the coefficients $c_0,...,c_{k-1}$ in eq.\\ \\eqref{eq:FourExp}. The main idea behind the DFT algorithm is to use orthogonality of the vectors $\\bm \\omega_k$. To show the orthogonality between the vectors $\\bm \\omega_k$ and $\\bm \\omega_l$, we let $\\bm \\omega_l^*$ denote the complex conjugate of $\\bm \\omega_l$, and then take the inner product of $\\bm \\omega_k$ and $\\bm \\omega_l$ and find that\n\\begin{align*}\n\\left<\\bm \\omega_k, \\bm \\omega_l \\right>&{}=\\frac{1}{n}\\sum_{m=0}^{n-1}\\exp\\left(\\frac{2\\pi ik m}{n}\\right)\\left[\\exp(\\frac{2\\pi il m}{n})\\right]^*\n\\\\&{}=\\frac{1}{n}\\sum_{m=0}^{n-1}\\exp\\left(\\frac{2\\pi i(k-l) m}{n}\\right)\n\\\\&{}=\\frac{1}{n}\\sum_{m=0}^{n-1}\\cos\\left(\\frac{\\pi(k-l)m}{n}\\right)+i\\sin\\left(\\frac{\\pi(k-l)m}{n}\\right)\n\\\\&{}=\\left\\{{1\\quad\\textup{if } k=l}\\atop{0\\quad\\textup{otherwise}}\\right.\n\\end{align*}\nTo deduce the last part, if $k=l$ then $\\exp(0)=1$, and if $k\\ne l$, then we are sampling the sine and cosine functions at equally spaced points on over an integral number of wavelengths. Since these functions have equal magnitude positive and negative parts, they sum to zero, much as the integral of a sine or cosine over an integral number of wavelengths is zero. This implies that we can compute the Fourier coefficients in the discrete Fourier sum by taking inner products \n\\begin{eqnarray}\nc_k=<\\bm{f},\\bm{\\omega_k}>=\\frac{1}{n} \\sum\\limits_{m=0}^{n-1} \\xi_n^{-mk}f_j.\n\\end{eqnarray} \nWe note the close connection between the continuous and discrete settings, where an integral is replaced by a sum.\n\n%%%%%%%%\n%subsection\n%%%%%%%%\n\\section{Fast Fourier Transform}\nComputing the Fourier coefficients, $c_0,...,c_{n-1}$ using the DFT from the definition can be very slow for large values of $n$. Computing the Fourier coefficients $c_0,...c_{n-1}$ requires $n^2-n$ complex multiplications and $n^2-n$ complex additions. In 1960, Cooley and Tukey~\\cite{CooTuk65} rediscovered a much more efficient way of computing DFT by developing an algorithm known as the Fast Fourier Transforms (FFT) -- the method was known to Gauss, but received little attention since he did not publish it~\\cite{HeiJohBur84}. The FFT cuts the number of arithmetic operations down to $O(n\\log n)$. For large values of $n$, this can make a huge difference in computation time compared to the standard DFT. The reason why the FFT is so important is that it is heavily used in spectral methods. The basic FFT algorithm used by Cooley and Tukey~\\cite{CooTuk65} is well documented in many places, however, there are other implementations of the algorithm and the best version of the algorithm to use depends heavily on computer architecture. We therefore do not give further descriptions here.\n", "meta": {"hexsha": "84d3d3841b6c283180edbeeaad3aff9a671f9e28", "size": 8507, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1dDFT/1dDFT.tex", "max_stars_repo_name": "bcloutier/PSNM", "max_stars_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_stars_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-01-05T14:22:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T23:51:25.000Z", "max_issues_repo_path": "1dDFT/1dDFT.tex", "max_issues_repo_name": "bcloutier/PSNM", "max_issues_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_issues_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-29T12:35:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-01T07:31:32.000Z", "max_forks_repo_path": "1dDFT/1dDFT.tex", "max_forks_repo_name": "bcloutier/PSNM", "max_forks_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_forks_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2015-01-05T14:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-09T06:55:01.000Z", "avg_line_length": 135.0317460317, "max_line_length": 1095, "alphanum_fraction": 0.7363347831, "num_tokens": 2535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.8188888910991851}}
{"text": "\\section{Derivation of the cell age distribution}\n\\label{supp_cell_age_dist}\n\nE. O. Powell first derive in 1956 the distribution of cell age for a cell\npopulation growing steadily in the exponential phase \\cite{Powell1956}. This\ndistribution is of the form\n\\begin{equation}\n  P(a) = \\ln(2) \\cdot 2^{1 - a},\n\\end{equation}\nwhere $a \\in [0, 1]$ is the fraction of the cell cycle, 0 being the moment right\nafter the mother cell divides, and 1 being the end of the cell cycle just before\ncell division. In this section we will reproduce and expand the details on each\nof the steps of the derivation.\n\nFor an exponentially growing bacterial culture, the cells satisfy the growth law\n\\begin{equation}\n  {\\dt{n}} = \\mu n,\n  \\label{seq_growth_ode}\n\\end{equation}\nwhere $n$ is the number of cells and $\\mu$ is the growth rate in units of\ntime$^{-1}$. We begin by defining $P(a)$ to be the probability density function\nof a cell having age $a$. At time zero of a culture in exponential growth, i.e.\nthe time when we start considering the growth, not the initial condition of the\nculture, there are $NP(a)da$ cells with age range between $[a, a + da]$. In\nother words, for $N \\gg 1$ and $da \\ll a$\n\\begin{equation}\n  N P(a \\leq x \\leq a + da) \\approx N P(a)da.\n\\end{equation}\nWe now define\n\\begin{equation}\n  F(\\tau) = \\int_\\tau^\\infty f(\\xi) d\\xi,\n\\end{equation}\nas the fraction of cells whose division time is greater than $\\tau$. This is\nbecause in principle not all cells divide exactly after $\\tau$ minutes, but\nthere is a distribution function $f(\\tau)$ for the division time after birth.\nEmpirically it has been observed that a generalize Gamma distribution fits well\nto experimental data on cell division time, but we will worry about this\nspecific point later on.\n\nFrom the definition of $F(\\tau)$ we can see that if a cell reaches an age $a$,\nthe probability of surviving to an age $a + t$ without dividing is given by\n\\begin{equation}\n  P(\\text{age} = (a + t) \\mid \\text{age} = a) = F(a + t \\mid a) =\n  {F(a + t) \\over F(a)}.\n  \\label{seq_prob_a+t_give_a}\n\\end{equation}\nThis result comes simply from the definition of conditional probability. Since\n$F(a)$ is the probability of surviving $a$ or more minutes without dividing, by\nthe definition of conditional probability we have that\n\\begin{equation}\n  F(a + t \\mid a) = {F(a, a + t) \\over F(a)},\n\\end{equation}\nwhere $F(a, a + t)$ is the joint probability of surviving $a$ minutes and $a +\nt$ minutes. But the probability of surviving $a + t$ minutes or more implies\nthat the cell already survived $a$ minutes, therefore the information is\nredundant and we have\n\\begin{equation}\n  F(a, a + t) = F(a + t).\n\\end{equation}\nThis explains \\eref{seq_prob_a+t_give_a}. From this equation we can find that\nout of the $N P(a)da$ cells with age $a$ only a fraction\n\\begin{equation}\n  \\left[ NP(a)da \\right] F(a + t \\mid a) = NP(a) {F(a + t)\\over F(a)} da\n\\end{equation}\nwill survive without dividing until time $a + t$. During that time interval $t$\nthe culture has passed from $N$ cells to $N e^{\\mu t}$ cells given the\nassumption that they are growing exponentially. The survivors $NP(a)F(a + t \\mid\na)da$ then represent a fraction of the total number of cells\n\\begin{equation}\n  {\\text{\\# survivors} \\over \\text{\\# total cells}} =\n  {\\left[ NP(a)da \\right] F(a + t \\mid a) \\over Ne^{\\mu t}} =\n  P(a){F(a + t)\\over F(a)}da {1 \\over e^{\\mu t}},\n\\end{equation}\nand their ages lie in the range $[a+t, a+t+da]$. Since we assume that the\nculture is in steady state then it follows that the fraction of cells that\ntransitioned from age $a$ to age $a + t$ must be $P(a + t)da$. Therefore we have\na difference equation - the discrete analogous of a differential equation - of\nthe form\n\\begin{equation}\n  P(a + t) da = P(a) {F(a + t) \\over F(a)}e^{-\\mu t} da.\n  \\label{seq_difference_eq}\n\\end{equation}\nWhat this equation shows is a relationship that connects the probability of\nhaving a life time of $a + t$ with a probability of having a shorter life time\n$a$ and the growth of the population. If we take $t$ to be very small,\nspecifically if we assume $t \\ll \\mu^{-1}$ we can Taylor expand around $a$ the\nfollowing terms:\n\\begin{equation}\n  F(a + t) \\approx F(a) + {dF \\over da} t,\n\\end{equation}\n\\begin{equation}\n  P(a + t) \\approx P(a) + {dP \\over da} t,\n\\end{equation}\nand\n\\begin{equation}\n  e^{-\\mu t} \\approx 1 - \\mu t.\n\\end{equation}\nSubstituting these equations into \\eref{seq_difference_eq} gives\n\\begin{equation}\n  P(a) + {dP \\over da} t = P(a) \\left( {F(a) + {dF \\over da}t \\over\n  F(a)} \\right) (1 - \\mu t).\n\\end{equation}\nThis can be rewritten as\n\\begin{equation}\n  {1 \\over P(a)} {dP \\over da} =\n  {1 \\over F(a)} {dF \\over da} - \\mu - {\\mu t \\over F(a)} {dF \\over da}.\n\\end{equation}\nSince we assumed $t \\ll \\mu^{-1}$ we then approximate the last term to be close\nto zero. We can then simplify this result into\n\\begin{equation}\n  {1 \\over P(a)} {dP \\over da} = {1 \\over F(a)} {dF \\over da} - \\mu.\n\\end{equation}\nIntegrating both sides of the equation with respect to $a$ gives\n\\begin{equation}\n  \\ln P(a) = \\ln F(a) - \\mu a + C,\n\\end{equation}\nwhere $C$ is the integration constant. Exponentiating both sides gives\n\\begin{equation}\n  P(a) = C' F(a)e^{-\\mu a}.\n\\end{equation}\nWhere $C' \\equiv e^C$. To obtain the value of the unknown constant we recall\nthat $F(0) = 1$ since the probability of having a life equal or longer than zero\nmust add up to one, therefore we have that $P(0) = C'$. This gives then\n\\begin{equation}\n  P(a) = P(0) e^{-\\mu a} F(a).\n  \\label{seq_Pa_result}\n\\end{equation}\nSubstituting the definition of $F(a)$ gives\n\\begin{equation}\n  P(a) = P(0) e^{-\\mu a} \\int_a^\\infty f(\\xi) d\\xi.\n  \\label{seq_Pa_result_int}\n\\end{equation}\nThe last step of the derivation involves writing $P(0)$ and the growth rate\n$\\mu$ in terms of the cell cycle length distribution $f(\\tau)$.\n\nThe growth rate of the population cell number (not the growth of cell mass) is\ndefined as the number of cell doublings per unit time divided by the number of\ncells. This is more clear to see if we write \\eref{seq_growth_ode} as a finite\ndifference\n\\begin{equation}\n  {N(t + \\Delta t) - N(t) \\over \\Delta t} = \\mu N(t).\n\\end{equation}\nIf the time $\\Delta t$ is the time interval it takes to go from $N$ to $2N$\ncells we have\n\\begin{equation}\n  {2N - N \\over \\Delta t} = \\mu N.\n\\end{equation}\nSolving for $\\mu$ gives\n\\begin{equation}\n  \\mu = \\overbrace{{2N - N \\over \\Delta t}}\n  ^{\\text{\\# doubling events per unit time}}\n  \\overbrace{{1 \\over N}}^{{1 \\over \\text{population size}}}.\n\\end{equation}\nWe defined $F(a)$ to be the probability of a cell reaching an age $a$ or\ngreater. For a cell to reach an age $a + da$ we can then write\n\\begin{equation}\n  F(a + da) = \\int_{a + da}^{\\infty} f(\\xi) d\\xi\n  = \\int_a^{\\infty} f(\\xi) d\\xi - \\int_a^{a + da} f(\\xi) d\\xi.\n\\end{equation}\nWe can approximate the second term on the right hand side to be\n\\begin{equation}\n  \\int_a^{a + da} f(\\xi) d\\xi \\approx f(a) da,\n\\end{equation}\nfor $da \\ll a$, obtaining\n\\begin{equation}\n  F(a + da) \\approx F(a) - f(a)da.\n\\end{equation}\nWhat this means is that from the original fraction of cells $F(a)$ with age $a$\nor greater a fraction $f(a)da / F(a)$ will not reach age $(a + da)$ because they\nwill divide. So out of the $NP(a)$ cells that reached exactly age $a$, the\nnumber of doubling events on a time interval $da$ is given by\n\\begin{equation}\n  {\\text{\\# doublings of cells of age } a {\\text{ on interval } da}} =\n  \\overbrace{NP(a)}^{\\text{\\# cells of age }a}\n  \\overbrace{f(a) da \\over F(a)}^{\\text{fraction of doublings per unit time}}.\n\\end{equation}\nThe growth rate then is just the sum (integral) of each age contribution to the\ntotal number of doublings. This is\n\\begin{equation}\n  \\mu = {1 \\over N} \\int_0^\\infty NP(a) {f(a)da \\over F(a)}.\n\\end{equation}\nSubstituting \\eref{seq_Pa_result} gives\n\\begin{equation}\n  \\mu = \\int_0^\\infty [P(0) e^{-\\mu a} F(a)] {f(a)da \\over F(a)}\n  = \\int_0^\\infty P(0) e^{-\\mu a} f(a)da.\n  \\label{seq_mu_integral}\n\\end{equation}\nWe now have the growth rate $\\mu$ written in terms of the cell cycle length\nprobability distribution $f(a)$ and the probability $P(0)$. Since $P(a)$ is a\nprobability distribution it must be normalized, i.e.\n\\begin{equation}\n  \\int_0^\\infty P(a) da = 1.\n\\end{equation}\nSubstituting \\eref{seq_Pa_result} into this normalization constraint gives\n\\begin{equation}\n  \\int_0^\\infty P(0) e^{-\\mu a} F(a) da = 1.\n\\end{equation}\nFrom here we can integrate the left hand side by parts. We note that given the\ndefinition of $F(a)$, the derivative with respect to $a$ is $-f(a)$ rather than\n$f(a)$. This is because if we write the derivative of $F(a)$ we have\n\\begin{equation}\n  {dF(a) \\over da} \\equiv \\lim_{da \\rightarrow 0}\n  {F(a + da) - F(a) \\over da}.\n\\end{equation}\nSubstituting the definition of $F(a)$ gives\n\\begin{equation}\n  {dF(a) \\over  da} = \\lim_{da \\rightarrow 0} {1 \\over da}\n  \\left[\\int_{a + da}^\\infty f(\\xi) d\\xi - \\int_a^\\infty f(\\xi) d\\xi \\right].\n\\end{equation}\nThis difference in the integrals can be simplified to\n\\begin{equation}\n  \\lim_{da \\rightarrow 0} {1 \\over da} \\left[ \\int_{a + da}^\\infty f(\\xi) d\\xi -\n  \\int_a^\\infty f(\\xi) d\\xi \\right]\\approx {-f(a)da \\over da} = -f(a).\n\\end{equation}\nTaking this into account we now perform the integration by parts obtaining\n\\begin{equation}\n P(0) \\left[ {e^{-\\mu t} \\over -\\mu} F(a) \\right]^\\infty_0\n - P(0) \\int_0^\\infty {e^{-\\mu a} \\over -\\mu} (-f(a)) da = 1.\n \\label{seq_inte_byparts}\n\\end{equation}\nOn the first term on the left hand side we have that as $a \\rightarrow \\infty$,\nboth terms $e^{-\\mu a}$ and $F(a)$ go to zero. We also have that $e^{\\mu 0} = 1$\nand $F(0) = 1$. This results in\n\\begin{equation}\n  {P(0) \\over \\mu} - P(0) \\int_0^\\infty {e^{-\\mu a} \\over \\mu} f(a) da = 1.\n\\end{equation}\nThe second term on the left hand side is equal to \\eref{seq_mu_integral} since\n\\begin{equation}\n  \\mu = \\int_0^\\infty P(0) e^{-\\mu a} f(a)da \\Rightarrow\n  1 = \\int_0^\\infty P(0) {e^{-\\mu a} \\over \\mu} f(a)da.\n\\end{equation}\nThis implies that on \\eref{seq_inte_byparts} we have\n\\begin{equation}\n  {P(0) \\over \\mu} - 1 = 1 \\Rightarrow P(0) = 2 \\mu.\n\\end{equation}\nWith this result in hand we can rewrite \\eref{seq_Pa_result_int} as\n\\begin{equation}\n  P(a) = 2\\mu e^{-\\mu a} \\int_a^\\infty f(\\xi) d\\xi.\n  \\label{seq_Pa_Posubs}\n\\end{equation}\nAlso we can rewrite the result for the growth rate $\\mu$ on\n\\eref{seq_mu_integral} as\n\\begin{equation}\n  \\mu = 2 \\mu \\int_0^\\infty e^{-\\mu a} f(a) da \\Rightarrow\n  2 \\int_0^\\infty e^{-\\mu a} f(a) da = 1.\n  \\label{seq_fa_int}\n\\end{equation}\n\nAs mentioned before the distribution $f(a)$ has been empirically fit to a\ngeneralize Gamma distribution. But if we assume that our distribution has almost\nnegligible dispersion around the mean average doubling time $a = \\tau_d$, we can\napproximate $f(a)$ as\n\\begin{equation}\n  f(a) = \\delta(a - \\tau_d),\n\\end{equation}\na Dirac delta function. Applying this to \\eref{seq_fa_int} results in\n\\begin{equation}\n  2 \\int_0^\\infty e^{-\\mu a} \\delta(a - \\tau_a) da = 1\n  \\Rightarrow 2 e^{-\\mu \\tau_d} = 1.\n\\end{equation}\nSolving for $\\mu$ gives\n\\begin{equation}\n  \\mu = {\\ln 2 \\over \\tau_d}.\n\\end{equation}\nThis delta function approximation for $f(a)$ has as a consequence that\n\\begin{equation}\n  F(a) =\n  \\begin{cases}\n    1 \\text{ for } a \\in [0, \\tau_d],\\\\\n    0 \\text{ for } a > \\tau_d.\n  \\end{cases}\n\\end{equation}\nFianlly we can rewrite \\eref{seq_Pa_Posubs} as\n\\begin{equation}\n  P(a) = 2 \\left( {\\ln 2 \\over \\tau_d} \\right)\n  e^{- {\\ln 2 \\over \\tau_d} a} \\int_a^\\infty \\delta(\\xi - \\tau_d) d\\xi\n  \\Rightarrow = 2 \\ln 2 \\cdot 2^{-a \\over \\tau_d}.\n\\end{equation}\nSimplifying this we obtain\n\\begin{equation}\n  P(a) =\n  \\begin{cases}\n    \\ln 2 \\cdot 2^{1 - {a \\over \\tau_d}} \\text{ for } a \\in [0, \\tau_d],\\\\\n    0 \\text{ otherwise}.\n  \\end{cases}\n\\end{equation}\nThis is the equation we aimed to derive. The distribution of cell ages over\nthe cell cycle.\n", "meta": {"hexsha": "6ba1d6baec7e7163ab27d3cb4686029729fc9753", "size": 11890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/appendix_cell_age_dist.tex", "max_stars_repo_name": "RPGroup-PBoC/chann_cap", "max_stars_repo_head_hexsha": "f2a826166fc2d47c424951c616c46d497ed74b39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-08-21T04:06:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T07:36:58.000Z", "max_issues_repo_path": "doc/appendix_cell_age_dist.tex", "max_issues_repo_name": "RPGroup-PBoC/chann_cap", "max_issues_repo_head_hexsha": "f2a826166fc2d47c424951c616c46d497ed74b39", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/appendix_cell_age_dist.tex", "max_forks_repo_name": "RPGroup-PBoC/chann_cap", "max_forks_repo_head_hexsha": "f2a826166fc2d47c424951c616c46d497ed74b39", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-29T17:43:28.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-09T00:20:16.000Z", "avg_line_length": 41.1418685121, "max_line_length": 80, "alphanum_fraction": 0.6814970563, "num_tokens": 4038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.9136765181249676, "lm_q1q2_score": 0.8188838365013953}}
{"text": "\\paragraph{Quantiles}\nare points taken at regular intervals from the cumulative distribution function.\n\n% \\noindent\nQuantiles have two equivalent notations:\n\\begin{itemize}[noitemsep,nolistsep]\n\n  \\item Not parametrized, $p$th quantile is equivalent to argument value for which c.d.f. has value\n  $p$, where $p \\in \\mathbb{R} \\cap [0,1]$.\n\n  \\item Parametrized with number of intervals equal $q$, these are called q-quantiles. For each $q$, there\n  are $q-1$ q-quantiles: $\\qquantile{1}$, $\\qquantile{2}$, \\ldots , $\\qquantile{q}$.\n\n\\end{itemize}\n\n\\vspace{-10pt}\n\\begin{gather*}\n\\quantile{q}{k} \\equiv \\qqquantile{k/q}\n\\end{gather*}\n\nQuantiles of Standard Normal distribution ($\\distnormal(0,1)$) are denoted by $z$, for example: $z_{0.5}$ is a median of $\\distnormal(0,1)$ \n\n\\paragraph{Quartiles}\nare 4-quantiles. They are denoted as follows: \n\n$Q_1 \\equiv \\quantile{4}{1} \\equiv \\qqquantile{0.25}$\n\n$Q_2 \\equiv \\quantile{4}{2} \\equiv \\qqquantile{0.5} \\equiv \\med$\n\n$Q_3 \\equiv \\quantile{4}{3} \\equiv \\qqquantile{0.75}$\n\n\\paragraph{Deciles}\nare 10-quantiles, denoted by $D_1, \\ldots , D_9$.\n\n\\paragraph{Percentiles}\nare 100-quantiles, denoted by $P_{1}, \\ldots , P_{99}$.\n\n% \\begin{align*}\n% \\textrm{Median: } & Med = \n% \\left\\{ \\begin{array}{cc}\n% \\textrm{odd }n\\textrm{: } & x_{\\frac{n+1}{2}} \\\\ %(n+1)/2  n/2  n/2 + 1\n% \\textrm{even }n\\textrm{: } & \\frac{1}{2} \\left( x_{\\frac{n}{2} } + x_{\\frac{n}{2}+1} \\right)\n% \\end{array} \\right\\} \\\\\n% \\textrm{Mode: } & \\textrm{observation that appears most often} \\\\\n% \\textrm{Quantiles: } & \\ldots\n% \\end{align*}\n\n% \\subsubsection{Means}\n% \\begin{align*}\n% \\textrm{Average: } & \\bar{x} = \\frac{1}{n}\\sum_{i=1}^n x_i \\\\\n% \\textrm{Trimmed: } & \\sum_{i=1}^n \\ldots \\\\\n% \\textrm{Windsorized: } & \\sum_{i=1}^n \\ldots \\\\\n% \\textrm{Geometrical: } & \\ldots \\\\\n% \\textrm{Harmonic: } & \\ldots\n% \\end{align*}\n", "meta": {"hexsha": "df6a0bb97a84728fc0078331e499d7bf0e73a6cc", "size": 1843, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_2c_measures_position.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_2c_measures_position.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_2c_measures_position.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.9107142857, "max_line_length": 140, "alphanum_fraction": 0.6527400977, "num_tokens": 730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.9136765210631689, "lm_q1q2_score": 0.8188838315389184}}
{"text": "\\section{Probability}\n\n\\formdesc{Assumptions}\n\n\\begin{center}\n  \\begin{tabular}{c}\n    $0 \\leq P(E) \\leq 1$ \\\\\n    $P(S) = 1$ \\\\\n    $P(S) = \\sum_{i=1}^{\\infty} P(E_i)$ \\\\\n  \\end{tabular}\n\\end{center}\n\nSample space $S$ contains each event $E_i$, e.g., $E = \\{$all outcomes in $S$ starting with a $3\\}$\n\n\\hformbar\n\n\n\n\\formdesc{Unions and Intersections}\n\n\\begin{equation}\n\tE \\cup F\n\\end{equation}\n\nis the union of the two sets $E$ and $F$, i.e., the event where either $E$ or $F$ occurs. The intersection of two events, the outcomes in both $E$ and $F$ is\n\n\\begin{equation}\n\tE \\cap F.\n\\end{equation}\n\n\\begin{center}\n  \\begin{tabular}{lc}\n    Commutative  & $E \\cup F = F \\cup E$ \\\\\n                 & $E \\cap F = F \\cap E$ \\\\\n    Associative  & $(E \\cup F) \\cup G = E \\cup (F \\cup G) $ \\\\\n                 & $(E \\cap F) \\cap G = E \\cap (F \\cap G)$ \\\\\n    Distributive & $(E \\cup F) \\cap G = (E \\cap G) \\cap (F \\cap G)$  \\\\\n                 & $(E \\cap F) \\cup G = (E \\cup G)(F \\cup G)$\n  \\end{tabular}\n\\end{center}\n\\hformbar\n\n\n\n\\formdesc{Independent Events}\n\n\n\nTwo events are independent if knowing the outcome of one provides no useful information about the outcome of the other.\n\\hformbar\n\n\n\\formdesc{Mutually Exclusive Events}\n\n\\begin{equation}\n   P(A \\cap B) = 0\n\\end{equation}\n\n\\vspace{.63em}\nare disjoint events, when $A$ and $B$ are mutually exclusive and there is no intersection---it is not possible for both to happen.\n\\hformbar\n\n\n\n\\formdesc{Union and Addition Rule}\n\n\\begin{equation}\n    P(A \\cup B) \\equiv P(A \\vee B) \\equiv \\{x: x \\in A \\vee x \\in B\\}\n\\end{equation}\n\n\\begin{center}\n  \\begin{tabular}{ll}\n    Independent         & $P(A \\cup B) = P(A) + P(B) - P(A \\cap B)$   \\\\\n    Mutually exclusive  & $P(A \\cup B) = P(A) + P(B)$                 \\\\\n  \\end{tabular}\n\\end{center}\n\n\\hformbar\n\n\n\n\\formdesc{Intersection and Multiplication Rules}\n\n\\begin{equation}\n    P(A \\cap B) \\equiv P(A \\wedge B) \\equiv \\{x: x \\in A \\wedge x \\in B\\}\n\\end{equation}\n\n\\begin{center}\n  \\begin{tabular}{ll}\n    Independent         & $P(A \\cap B) = P(A) \\cdot P(B)$   \\\\\n    Mutually exclusive  & $P(A \\cap B) = 0$                 \\\\\n    Dependent           & $P(A \\cap B) = P(A) \\cdot P(B|A)$ \\\\\n  \\end{tabular}\n\\end{center}\n\n\\hformbar\n\n\n\\formdesc{Complement and Subtraction Rule}\n\n\\begin{eqnarray}\nP(A') \\equiv P(A^c) \\equiv P(\\neg A) &\\equiv& \\{x: x \\notin A\\} \\equiv 1 - P(A) \\\\\nP(A') &=& 1 - P(A)\n\\end{eqnarray}\n\nSome implications:\n\n\\begin{center}\n  \\begin{tabular}{c}\n    $P(A \\cup A^c) = 1$ \\\\\n    $P(A) = 1 - P(A^c)$ \\\\\n    $P(A|B) = 1 - P(A^c | B)$ \\\\\n  \\end{tabular}\n\\end{center}\n\\hformbar\n\n\n\n\n\\formdesc{Conditional Probability Rule}\n\n\\begin{equation}\n\tP(A|B) = \\frac{P(A \\cap B)}{P(B)}\n\\end{equation} \n\nis the probability of the outcome of event A given condition B.\n\\hformbar\n\n\n\n\\formdesc{Bayes Theorem}\n\n\\begin{equation}\n  P(A|B) = \\frac{P(A) ~P(B|A)}{ P(A) ~ P(B|A) + P(A) ~ P(B|A)}\n\\end{equation}\n\\hformbar\n\n\n\n\n\\formdesc{The Fundamental Principle of Counting}\n\nIf an operation can be performed in $n_1$ ways, and if for each of these a second operation can be performed $n_2$ ways, and for each of the first two a third operation can be performed in $n_3$ ways, $\\ldots$, then the sequence of $k$ operations can be performed in $n_1 n_2 \\mdots n_k$ ways.\n\n\\hformbar\n\n\n\n\\formdesc{Factorial}\n\n\\begin{equation}\n    n! = n (n-1) (n-2) (2) (1)\n\\end{equation}\n\nwith $0! = 1$.\n\\hformbar\n\n\n\n\\formdesc{Permutation}\n\nA permutation $\\sigma$ any finite set $A$ is a one-to-one mapping of $A$ onto itself. An element mapped to itself in the permutation is a \\textit{fixed point}.\n\n\\subsection*{Example}\n\nOne permutation of the set $A = \\{a, b, c\\}$ is:\n\n\\begin{equation}\n    \\sigma = \\begin{pmatrix}\n                  a & b & c \\\\ \n                  b & c & a\n             \\end{pmatrix}\n\\end{equation}\n\nwhere $a$ is sent to $b$, $b$ to $c$, and $c$ to $a$.\n\\hformbar\n\n\n\\formdesc{Permutations of $n$ elements}\n\n\\begin{equation}\n    n!\n\\end{equation}\n\nis the number of permutations of $n$ objects, that is, the number of arrangements of a set containing $n$ elements.\n\\hformbar\n\n\n\n\\formdesc{Permutations: $n$ taken $r$ at a time}\n\n\\begin{equation}\n    \\perm{n}{k}=\\frac{n!}{(n-k)!}\n\\end{equation}\n\nrepresents the number of permutations of $n$ distinct objects taken $r$ at a time.\n\\hformbar\n\n\n\n\\formdesc{Stirling's Approximation of $n!$}\n\n\\begin{equation}\n    n^n e^{-n} \\sqrt{2 \\pi n}\n\\end{equation}\n\nis a sequence asymptotically equal to $n!$.\n\\hformbar\n\n\n\n\\formdesc{Combinations}\n\n\\begin{equation}\n    \\comb{n}{j} = \\begin{pmatrix} n \\\\ j \\end{pmatrix} = \\frac{n!}{j! (n - j)!}\n\\end{equation}\n\nis the number of subsets of size $j$ that can be assembled given a set of $n$ elements, for integers $n$ and $j$ such that $0 < j < n$.\n\\hformbar\n\n\n\n\\formdesc{Bernoulli Trials Process}\n\nA sequence of $n$ experiments such that\n\n\\begin{itemize}\n    \\item Each experiment has two possible outcomes, called \\textit{success} and \\textit{failure}\n    \\item The probability of $p$ of success of each experiment is the same for each, and is independent of previous experiments\n\\end{itemize}\n\nThe probability of failure is $q = 1 - p$.\n\\hformbar\n\n\n\\formdesc{Binomial Probabilities}\n\n\\begin{equation}\n    b(n, p, j) = \\comb{n}{j} p^j (1 - p)^{n - j}\n\\end{equation}\n\nrepresents the probability that in $n$ Bernoulli trials there are exactly $j$ successes, given $n$ trials, and each trials' success rate is $p$.\n\\hformbar\n\n\n\n\\formdesc{Binomial Distribution}\n\n\\begin{equation}\n    B \\sim b(n, p, k)\n\\end{equation}\n\ngives the probability of the number of successes $k$ in a sequence of Bernoulli trials with parameters $p$ and $n$.\n\\hformbar\n\nPDF P. 107\n\n\\newpage\n", "meta": {"hexsha": "87c4566d600bad4b5cf30750ca5e355a01163c4e", "size": 5638, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/probability.tex", "max_stars_repo_name": "benhorvath/math_notes", "max_stars_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/probability.tex", "max_issues_repo_name": "benhorvath/math_notes", "max_issues_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/probability.tex", "max_forks_repo_name": "benhorvath/math_notes", "max_forks_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.7683397683, "max_line_length": 293, "alphanum_fraction": 0.6277048599, "num_tokens": 1933, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067163548471, "lm_q2_score": 0.8688267762381843, "lm_q1q2_score": 0.8188750719534186}}
{"text": "\\subsection{Using the inverse to solve a system of equations}\n\nOne way in which the inverse of a matrix is useful is to find the\nsolution of a system of linear equations.  Recall from Definition~\\ref{def:matrix-form} that we can write a system of equations in\nmatrix form, which is in the form\n\\begin{equation*}\n  A\\vect{x}=\\vect{b}.\n\\end{equation*}\nSuppose we find the inverse $A^{-1}$ of the matrix $A$. Then we can\nmultiply both sides of this equation by $A^{-1}$ on the left and\nsimplify to obtain\n\\begin{equation*}\n  \\vect{x} = A^{-1}\\vect{b}.\n\\end{equation*}\nTherefore we can find $\\vect{x}$, the solution to the system, by\ncomputing $\\vect{x} = A^{-1}\\vect{b}$. Note that once we have found\n$A^{-1}$, we can easily get the solution for different right-hand\nsides (different $\\vect{b}$). It is always just $A^{-1}\\vect{b}$.\n\n\\begin{example}{Using the inverse to solve a system of equations}{inverse-to-solve-system}\n  Consider the following system of equations. Use the inverse of a\n  suitable matrix to solve this system.\n  \\begin{equation*}\n    \\begin{array}{c}\n      x+z=1 \\\\\n      x-y+z=3 \\\\\n      x+y-z=2\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  First, we can write the system in matrix form\n  \\begin{equation*}\n    A\\vect{x} =\n    \\begin{mymatrix}{rrr}\n      1 & 0 & 1 \\\\\n      1 & -1 & 1 \\\\\n      1 & 1 & -1\n    \\end{mymatrix} \\begin{mymatrix}{r}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix} =\\begin{mymatrix}{r}\n      1 \\\\\n      3 \\\\\n      2\n    \\end{mymatrix} = \\vect{b}.\n  \\end{equation*}\n  The inverse of $A$ is\n  \\begin{equation*}\n    A^{-1} =\n    \\def\\arraystretch{1.2}\n    \\begin{mymatrix}{rrr}\n      0 & \\frac{1}{2} & \\frac{1}{2} \\\\\n      1 & -1 & 0 \\\\\n      1 & -\\frac{1}{2} & -\\frac{1}{2}\n    \\end{mymatrix}.\n  \\end{equation*}\n  From here, the solution to the system $A\\vect{x}=\\vect{b}$ is found\n  by $\\vect{x}=A^{-1}\\vect{b}$, i.e.,\n  \\begin{equation*}\n    \\def\\arraystretch{1.2}\n    \\begin{mymatrix}{r}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rrr}\n      0 & \\frac{1}{2} & \\frac{1}{2} \\\\\n      1 & -1 & 0 \\\\\n      1 & -\\frac{1}{2} & -\\frac{1}{2}\n    \\end{mymatrix} \\begin{mymatrix}{r}\n      1 \\\\\n      3 \\\\\n      2\n    \\end{mymatrix} =\\begin{mymatrix}{r}\n      \\frac{5}{2} \\\\\n      -2 \\\\\n      -\\frac{3}{2}\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nWhat if the right-hand side had been $\\vect{b}=\\begin{mymatrix}{r}\n  0 \\\\\n  1 \\\\\n  3\n\\end{mymatrix}$? In this case, the solution would be given by\n\\begin{equation*}\n  \\def\\arraystretch{1.2}\n  \\begin{mymatrix}{r}\n    x \\\\\n    y \\\\\n    z\n  \\end{mymatrix} = \\begin{mymatrix}{rrr}\n    0 & \\frac{1}{2} & \\frac{1}{2} \\\\\n    1 & -1 & 0 \\\\\n    1 & -\\frac{1}{2} & -\\frac{1}{2}\n  \\end{mymatrix} \\begin{mymatrix}{r}\n    0 \\\\\n    1 \\\\\n    3\n  \\end{mymatrix} =\\begin{mymatrix}{r}\n    2 \\\\\n    -1 \\\\\n    -2\n  \\end{mymatrix}.\n\\end{equation*}\nThis illustrates that for a system $A\\vect{x}=\\vect{b}$ where $A^{-1}$ exists,\nit is easy to find the solution when the vector $\\vect{b}$ is changed.\n", "meta": {"hexsha": "b4c4b313293e722dd69a0027ab4ba5e7cd572f9b", "size": 3030, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Inverses-SystemOfEquations.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-Inverses-SystemOfEquations.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-Inverses-SystemOfEquations.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 26.814159292, "max_line_length": 130, "alphanum_fraction": 0.5772277228, "num_tokens": 1125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801889, "lm_q2_score": 0.8902942239389253, "lm_q1q2_score": 0.8187524355569424}}
{"text": "%---------------------------------------------------------------------------------\n% Monte Carlo Simulations\n%---------------------------------------------------------------------------------\n\n\\section{Monte Carlo Simulations}\n\n\\subsection{Approximation of $\\pi$}\n\nWe will use this toy example as a brief introduction to Monte Carlo Simulations. Lets assume that we are trying to find an approximation for $\\pi$. We can still do this using the same randomization-based process as before. We will use the statistical and programming software R for our process. This is a particularly interesting example, as there are very little conditions to actually be satisfied. The only condition that needs to be met as has been said time again is that the sample is representative of the population. In our case, the population is the points $x,y\\in\\mathscr{R}: x,y\\sim U(-0.5,0.5)$. \n\\begin{center}\n    \\begin{lstlisting}[language = R]\n        ```{r}\n        runs <- 100000\n        x <- runif(runs,min=-0.5,max=0.5)\n        y <- runif(runs,min=-0.5,max=0.5)\n        in.circle <- x^2 + y^2 <= 0.5^2\n        mc.pi <- (sum(in.circle)/runs)*4\n        ```\n    \\end{lstlisting}\n\\end{center}\n\\newline\\\\\nWe've made sure that that $x$ and $y$ are representative of each population by selecting a random value from $U(-0.5,0.5)$ using the \\textbf{runif()} command which stands for \"random uniform\". Rather than a least squares estimator, in this case, our test statistic will be the Bernoulli random variable representing whether a point is contained within the circle which inscribes our population distribution. Now that we have our test statistics, we can approximate $\\pi$. Empirically, $A_{square}=(2r)^2=4r^2$. Suppose we don't know a value for $\\pi$, but instead know that $A_{circle}\\propto r^2$. That is, $A_{circle}=cr^2$ where $c$ is a positive constant. We can now approximate $\\pi$ where $c$ is our approximation. This is as simple as taking the proportion of $A_{circle}$ and $A_{square}$.\n\n$$\n\\frac{A_{circle}}{A_{square}} = \\frac{cr^2}{4r^2} = \\frac{c}{4}\\longrightarrow\\frac{4\\cdot A_{circle}}{A_{square}}\n$$\n\\\\\nThe simulated $A_{circle}$ that we have is just the total number of points inside of the circle while $A_{square}$ will be the total number of points that we sampled. The approximation for $\\pi$ in this example is $3.14252$, not too far off from the true value of $3.14159$.\n\n\\begin{figure}[htpb!] % Defines figure environment\n    \\centering % Centers your figure\n\\includegraphics[scale=0.4]{figure/monteCarloCircle.png} % Includes your figure and defines the size\n    \\caption{Plot of sampling distribution and inscribed circle} % For your caption\n    \\label{fig:my_label} % If you want to label your figure for in-text references\n\\end{figure}\n\n\\subsection{Monte Carlo Simulation and RBI}\n\nThe Monte Carlo simulation is a do-it-all kind of method which has many useful applications in statistics and mathematics in general. For randomization based inference, Monte Carlo simulations manifest themselves as a streamlined way to get the asymptotically correct p-value we want. The process is applied as follows: First, instead of taking $n!$ permutations of our data, we take a random sample of permutations usually between 5 to 100. We then calculate the proportion of those permutations that yield a test statistics that are as or more extreme than our original test statistic. Now we have our random variable $P$ (the aforementioned proportion) with which we create a 95\\% confidence interval using the largest possible binomial standard deviation, $\\sqrt{n*(0.5)(1-0.5)}$. Thus, we create a sufficiently wide confidence interval that, if created over and over again, will contain the true p-value for our effect 95\\% of the time. \n", "meta": {"hexsha": "bdec4c797e9e73e32dbcd7b1463ded1c720f2473", "size": 3744, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project/Math%20420%20Final%20Paper/content/5-MonteCarloSim.tex", "max_stars_repo_name": "jake-caldwell/Math420Proj", "max_stars_repo_head_hexsha": "460deedb53a0a18509bc412c012f33e04440e9bb", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Project/Math%20420%20Final%20Paper/content/5-MonteCarloSim.tex", "max_issues_repo_name": "jake-caldwell/Math420Proj", "max_issues_repo_head_hexsha": "460deedb53a0a18509bc412c012f33e04440e9bb", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Project/Math%20420%20Final%20Paper/content/5-MonteCarloSim.tex", "max_forks_repo_name": "jake-caldwell/Math420Proj", "max_forks_repo_head_hexsha": "460deedb53a0a18509bc412c012f33e04440e9bb", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 93.6, "max_line_length": 942, "alphanum_fraction": 0.7107371795, "num_tokens": 914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8902942181173145, "lm_q1q2_score": 0.8187524282423612}}
{"text": "\\section{Running-mean/moving average}\nSince we have no replicates and we want to force $s(x)$ to be smooth\nwe can use the motivation that under some stastical model, for any\n$x_0$ values of $f(x)=\\E[Y|X=x]$ for \n$x$ close to $x_0$ are similar. \n\nHow do we define close? \nA formal definition is the {\\it symmetric nearest neighborhood}\n\\[\nN^S(x_i) = \\{ \\max(i-k,1),\\dots,i-1,i,i+1,\\min(i+k,n) \\}\n\\]\n\nWe may now define running mean as:\n\\[\ns(x_i) = \\ave_{j \\in N^S(x_i)} \\{ y_j \\}\n\\]\n\nWe can also forget about the symmetric part and simply define the\nnearest $k$ neighbors. \n\n\n\\begin{figure}[htp]\n\\caption{\\label{f2.4} CD4 cell count since seroconversion for HIV infected men.}\n\\centerline{\\epsfig{figure=Plots/plot-02-04.ps,angle=270,width=.8\\textwidth}}\n\\end{figure}\n\nThis usually too wiggly to be considered useful.  Why do you think?\n\nNotice we can also fit a line instead of a constant. This procedure is\ncalled running-line.\n\nCan you write out the recipe for $s(x_i)$ for the running-line smoother?\n\n\n\n\n", "meta": {"hexsha": "37c6e2aa29f5d0969c57cd5a6341554a98d73e91", "size": 1006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-02-03.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-02-03.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-02-03.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 27.1891891892, "max_line_length": 80, "alphanum_fraction": 0.7127236581, "num_tokens": 308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217417, "lm_q2_score": 0.8856314647623015, "lm_q1q2_score": 0.81844906627465}}
{"text": "\\section{Posterior Probability Criteria}\nObjections have been raised that minimizing Akaike's criterion does\nnot produce asymptotically consistent estimates of the correct model\nNotice that if \nwe consider Model($p^*$) as the correct model then we have\nfor any $p>p*$ \n\\begin{equation}\n\\label{prob}\n\\Pr\\left[ AIC(p) < AIC(p^*) \\right] = \\Pr\\left[ 2 \\{l(\\bbh_{p}) - l(\\bbh_{p^*})\n\\} > 2(p - p^*)\\right].\n\\end{equation}\nNotice that, in this case, the random variable $2\\{l(\\bbh_{p}) -\nl(\\bbh_{p^*})\\}$ is  \nthe logarithm of the likelihood ratio of two competing models which,\nunder certain regularity \nconditions, is known to converge in \ndistribution to $\\chi^2_{p-p^*}$, and thus it follows that the\nprobability in Equation (\\ref{prob}) is not 0\nasymptotically.  \nSome have suggested multiplying\nthe penalty term in the \nAIC by some increasing function of $n$, say $a(n)$, that makes the\nprobability\n\\[\n \\Pr\\left[ 2 \\{l(\\bbh_{p}) - l(\\bbh_{p^*})\n\\} > 2a(n)(p - p^*)\\right] \n\\]\nasymptotically equal to 0. There are many choices of $a(n)$ that would\nwork in this context. However, some of the choices made in the\nliterature seem arbitrary.\n\nSchwarz (1978) \\nocite{schw:1978} and Kashyap (1982) \\nocite{kash:1982} suggest using a\nBayesian approach \nto the problem of model selection which, in the IID case,  results in a \ncriterion that is similar to AIC in that it is based on a penalized\nlog-likelihood function evaluated at the maximum likelihood estimate\nfor the model in question. The\npenalty term in the Bayesian Information Criteria (BIC) obtained by\nSchwarz (1978) \\nocite{schw:1978} \nis the AIC penalty term $p$ multiplied by the function $a(n)\n=\\frac{1}{2}\\log(N)$.   \n\nThe Bayesian approach to model selection is based on maximizing the\nposterior probabilities of the alternative models, given the\nobservations. To do this we must define a strictly positive prior\nprobability \n$\\pi_p = \\Pr[\\mbox{Model}(p)] $ for each model and a conditional prior\n$d\\mu_p(\\bb)$ for the parameter given it is in $\\Omega_p$, the subspace\ndefined by Model(p). Let $\\bY = (Y_1,\\dots,Y_n)$ be the\nresponse variable and define the distribution given $\\bb$\nfollowing (\\ref{parsimodel}) \n\\[\nf_{\\bY}(\\by| \\bX,\\bb) \\equiv \\prod_{i=1}^n f(y_i;\\bx_i,\\bb)\n\\]\nThe posterior probability that we look to\nmaximize is  \n\\[\n\\Pr\\left[\\mbox{Model}(p) | \\bY=\\by \\right] = \n\\frac{\\int_{\\Omega_p} \\pi_p f_{\\bY}(\\by|\\bX,\\bb) d\\mu_p(\\bb)}\n{\\sum_{q=1}^P \\int_{\\Omega_q} \\pi_q f_{\\bY}(\\by|\\bX,\\bb) d\\mu_q(\\bb)}\n\\]\nNotice that the denominator depends neither on the model nor the data,\nso we need only to maximize the numerator when choosing models.\n\nSchwarz (1978) \\nocite{schw:1978} and Kashyap (1982)\n\\nocite{kash:1982} suggest criteria derived \nby taking a Taylor expansion of the log posterior probabilities of the \nalternative models. Schwarz (1978) \\nocite{schw:1978} presents the following\napproximation for the IID case\n\\[\n\\log \\int_{\\Omega_p} \\pi_p f_{\\bY}(\\by|\\bX,\\bb) d\\mu_p(\\bb)\n\\approx  l(\\bbh_{p}) - \\frac{1}{2} p\n\\log n \n\\] \nwith $\\bbh_p$ the maximum likelihood estimate obtained under Model(p).\n\nThis fact leads to the Bayesian Information Criteria (BIC) which is\n\\begin{equation}\n\\label{BIC}\n\\mbox{BIC}(p) = - 2 l(\\bbh_{p}) + p\\log n\n\\end{equation}\n\n\n\\subsection{Kyphosis Example}\nThe AIC\nand BIC obtained for the gam are: \n\n\n\\begin{verbatim}\nAIC(Age) =  83              BIC(Age) = 90\nAIC(Age,Start) = 64         BIC(Age,Start) = 78\nAIC(Age,Number) = 73        BIC(Age,Number) = 86\nAIC(Age,Start,Number) = 60  BIC(Age,Start,Number) = 81\n\\end{verbatim}  \n", "meta": {"hexsha": "a11b7af8781f913e0a13728f0cb4f9c98a76e9b0", "size": 3535, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-09-03.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-09-03.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-09-03.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 37.2105263158, "max_line_length": 87, "alphanum_fraction": 0.71145686, "num_tokens": 1153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.8933094039240554, "lm_q1q2_score": 0.8183693307986333}}
{"text": "\\section{The Peano Axioms}\r\nWe know what the natural numbers are, or do we?\r\nIn school, we were often told a rather vague idea of the notion of natural numbers.\r\nWe know that they are $1,2,3,\\ldots$, but what actually are they?\r\nAs every mathematical discipline, we do not know what is it until we define it using axioms.\r\nIn the case of natural numbers, this is done by the Peano axioms:\r\n\\begin{definition}\r\n    Natural numbers is a triple $(\\mathbb N, 1, +1)$, where $\\mathbb N$ is a set, $1\\in\\mathbb N$ its element, and $+1:\\mathbb N\\to\\mathbb N$ an operation on $\\mathbb N$.\r\n    It satisfies the following axioms:\\\\\r\n    1. For any $n\\in\\mathbb N$, $n+1\\neq 1$.\\\\\r\n    2. For $n,m\\in\\mathbb N$, if $n\\neq m$, then $n+1\\neq m+1$.\\\\\r\n    3. Let $P$ be a proposition on $\\mathbb N$. If $P(1)$ is true and $P(n)\\implies P(n+1)$ for all $n\\in\\mathbb N$, then $P(n)$ is true for all $n\\in\\mathbb N$.\r\n\\end{definition}\r\n\\begin{definition}[Addition]\r\n    We define the operation $+k$ inductively by $n+(k+1)=(n+k)+1$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    The operation $+k$ is defined for all natural number $k$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Induction.\r\n\\end{proof}\r\nSimilarly, using induction, we can define multiplication, exponentiation and order ($a<b\\iff\\exists k\\in\\mathbb N, a+k=b$) in the obvious way.\r\n\\begin{proposition}\r\n    1. $(a+b)+c=a+(b+c)$.\\\\\r\n    2. $a+b=b+a$.\\\\\r\n    3. $(ab)c=a(bc)$.\\\\\r\n    4. $ab=ba$.\\\\\r\n    5. $a(b+c)=ab+ac$.\\\\\r\n    6. $a<b\\land b<c\\implies a<c$.\\\\\r\n    7. $\\lnot(a<a)$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Induction. Induction. Induction. Induction. Induction. Induction. Induction.\r\n\\end{proof}\r\nThere is a more useful form of induction.\r\nInduction says that if we have some proposition $P$ such that $P(1)$ is true and $P(n)\\implies P(n+1)$, then $P(n)$ is true.\r\nBut in fact, we can have a ``stronger'' induction hypothesis.\r\n\\begin{theorem}[Strong induction]\r\n    Suppose that $P$ is a proposition on $\\mathbb N$.\r\n    If $P(1)$ is true and for any $n\\in\\mathbb N$,\r\n    $$\\forall k\\le n, P(k)\\implies P(n+1)$$\r\n    Then $P(n)$ is true for any $n\\in\\mathbb N$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Apply our usual induction on the proposition $Q(n)$ meaning\r\n    $\\forall k\\le n, P(k)$\r\n\\end{proof}\r\nTechnically, we do not need to check the base case.\r\nBut it is often safer to check it.\r\nIf we want to use strong induction on $P$, we can prove $P(n)$ assuming the case for smaller numbers, as induction says if it would help to assume $P(m)$ for some $m<n$, feel free to do so.\r\nThere are a few equivalent forms of strong induction which can be pretty useful.\r\n\\begin{corollary}\r\n    If some $n$ has $P(n)$ false, then there exists an $n$ with $P(n)$ false but $P(m)$ true for every $m<n$.\r\n\\end{corollary}\r\nThat is, if there is a counterexample, then there is a minimal counterexample.\r\n\\begin{corollary}[Well-ordering Principle]\r\n    If some $n$ has $P(n)$ true, then there exists a minimal $n$ with $P(n)$ true.\r\n\\end{corollary}", "meta": {"hexsha": "2d3e9dd8bd8f579180ab28fd29ff54704cd45404", "size": 2994, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/peano.tex", "max_stars_repo_name": "david-bai-notes/Numbers-and-Sets", "max_stars_repo_head_hexsha": "2c8ca0c4983c1d575b5f55f2a91d34d6ef534845", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-15T21:17:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-15T21:17:29.000Z", "max_issues_repo_path": "1/peano.tex", "max_issues_repo_name": "david-bai-notes/Numbers-and-Sets", "max_issues_repo_head_hexsha": "2c8ca0c4983c1d575b5f55f2a91d34d6ef534845", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1/peano.tex", "max_forks_repo_name": "david-bai-notes/Numbers-and-Sets", "max_forks_repo_head_hexsha": "2c8ca0c4983c1d575b5f55f2a91d34d6ef534845", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.7457627119, "max_line_length": 190, "alphanum_fraction": 0.6603206413, "num_tokens": 975, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.8824278633625322, "lm_q1q2_score": 0.8183312062239385}}
{"text": "\\newpage\n\\subsection{Supper approximation of $x^2$ via composition}\nWe consider a set of equidistant girds $\\Omega_\\ell$ of level $\\ell$ on the unit interval $\\bar{\\Omega}=[0,1]$ and mesh length $h_\\ell = 2^{-\\ell}$. The grid points $x_{\\ell,i}$ are given by\n\\begin{equation}\nx_{\\ell,i}:=ih_\\ell,\\quad 0\\le i\\le 2^\\ell.\n\\end{equation} \n\nA key observation about the connections between linear finite element functions and ReLU DNNs in \\cite{he2020relu} is that\n\\begin{equation}\\label{def_g}\ng(x) = 2{\\rm ReLU}(x) - 4{\\rm ReLU}({x-\\frac{1}{2}}) + 2{\\rm ReLU}(x-1)\\in {{\\rm DNN}}_{1}^{3},\n\\end{equation}\nfor $x \\in \\mathbb{R}$. The nodal basis functions on $\\Omega_\\ell$ are defined as\n\\begin{equation}\n\\phi_{\\ell,i}(x):=\n\\begin{cases}\ng\\left(\\frac{x-(i-1)h_\\ell}{2h_\\ell}\\right)\\quad &x\\in [x_{\\ell,i}-h_\\ell,x_{\\ell,i}+h_\\ell],\\\\\n0 \\quad &\\text{otherwise}.\n\\end{cases}\n\\end{equation}\nBy definition, we have $\\phi_{1,1}(x) = g(x)$ for $x \\in[0,1]$. Besides, for $\\ell=0$, we have these next two basis functions\n\\begin{equation}\\label{key}\n\\phi_{0,0} = 1- x \\quad \\text{and} \\quad \\phi_{0,1} = x, \\quad \\forall x \\in [0,1].\n\\end{equation}\n\nThese basis functions are used to define the piecewise linear function space\n\\begin{equation}\nV_\\ell :=\\mbox{span}\\{\\phi_{\\ell,i}: 0 \\le i\\le 2^\\ell\\} .\n%\\subset H_0^1(0,1).\n\\end{equation}\nThen, let's define the the piecewise linear interpolation on $\\Omega_\\ell$ as:\n\\begin{equation}\n\\Pi_\\ell u = \\sum_{i=0}^{2^\\ell}u(x_{\\ell,i}) \\phi_{\\ell,i}. \n\\end{equation}\nThus, we also have the next so-called hierarchical decomposition for $L \\ge 1$\n\\begin{equation}\n\\begin{aligned}\n\\Pi_L u(x) &=\\Pi_0 u +  \\sum_{\\ell=1}^L  (\\Pi_\\ell - \\Pi_{\\ell-1})u \\\\\n&=\\Pi_0 u +  \\sum_{\\ell}^L \\sum_{i\\in I_\\ell}\\mu_{\\ell,i}\\phi_{\\ell,i},\n\\end{aligned}\n\\end{equation}\nwhere\n\\begin{equation}\nI_\\ell = \\{i\\in \\mathbb{N}~:~1\\le i\\le 2^\\ell-1, ~i ~\\text{ is odd} \\}.\n\\end{equation}\nFurthermore, we have \n\\begin{equation}\\label{key}\n(\\Pi_\\ell - \\Pi_{\\ell-1})u = \\sum_{i\\in I_\\ell}\\mu_{\\ell,i}\\phi_{\\ell,i} = \\sum_{i\\in I_\\ell} \\left( u(x_{\\ell,i}) - \\frac{1}{2}\\left( u(x_{\\ell,i-1})  + u(x_{\\ell,i+1})  \\right) \\right)\\phi_{\\ell,i}.\n\\end{equation}\n\nThe key observation here is that there exist a special decomposition form once we take $u(x) = x^2$. \nBy the hierarchical decomposition above, we have\n\\begin{equation}\n\\begin{aligned}\n(\\Pi_{\\ell} - \\Pi_{\\ell-1})u &= \\sum_{i\\in I_\\ell}\\left( u(x_{\\ell,i}) - \\frac{1}{2}\\left( u(x_{\\ell,i-1})  + u(x_{\\ell,i+1})  \\right) \\right)\\phi_{\\ell,i}(x)\\\\\n&=\\sum_{i\\in I_\\ell}\\left(x_{\\ell,i}^2 - \\frac{1}{2}(x_{\\ell,i-1}^2 + x_{\\ell,i+1}^2)\\right)\\phi_{\\ell,i}(x)\\\\\n&= \\sum_{i\\in I_\\ell}\\left(x_{\\ell,i}^2 - \\frac{1}{2}\\left((x_{\\ell,i}-h_\\ell)^2 + (x_{\\ell,i}+h_\\ell)^2\\right) \\right)\\phi_{\\ell,i}(x) \\\\\n&=-h_\\ell^2\\sum_{i\\in I_\\ell}\\phi_{\\ell,i}(x).\n\\end{aligned}\n\\end{equation}\nNote $\\Pi_0 u = u(0)\\phi_{0,0} + u(1)\\phi_{0,1} = x$, we have\n\\begin{equation}\n\\Pi_L u = \\Pi_0 u + \\sum_{\\ell=1}^L  (\\Pi_\\ell - \\Pi_{\\ell-1})u = x -\\sum_{\\ell=1}^\\ell h^2_\\ell \\sum_{i\\in I_\\ell}\\phi_{\\ell,i}(x) = x -\\sum_{\\ell=1}^\\ell h^2_\\ell g_\\ell(x),\n\\end{equation}\nwhere\n\\begin{equation}\\label{key}\ng_\\ell(x) := \\sum_{i\\in I_\\ell}\\phi_{\\ell,i}(x).\n\\end{equation}\n\nBy definition, we have the next diagram of $g_\\ell(x)$:\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=0.6\\textwidth]{figures/hierachybasis_gl}\n\t\\caption{The figure of $g_\\ell(x)$}\n\t\\label{fig:gl}\n\\end{figure}\n\nThe next property plays the crucial role for the connection between ReLU DNN and hierarchical basis functions:\n\\begin{equation}\\label{func:glinduction}\ng_\\ell(x)=g(g_{\\ell-1}(x)),\\quad \\ell=2,...,L, \\quad \\forall x \\in [0,1],\n\\end{equation}\nwith $g_1(x) = g(x)$ as defined in~\\ref{def_g}. Thus, we have the next key relation by the  property of composition\n\\begin{equation}\\label{key}\ng_\\ell \\in {\\rm DNN}_\\ell^{3}.\n\\end{equation}\nBased on the definition of $\\widehat{{\\rm DNN}}_{\\ell}^{3}$, the above relation leads to \n\\begin{equation}\\label{key}\nx -\\sum_{\\ell=1}^L h^2_\\ell g_\\ell(x) \\in \\widehat{{\\rm DNN}}_{L}^{3},\n\\end{equation}\nwhere $f \\in \\widehat{{\\rm DNN}}_{L}$ is a modified DNN structure as:\n\\begin{equation}\\label{def:ReLUDNN2}\n\\begin{cases}\nf^{1}(x) &= \\sigma \\circ \\theta^1 (x) \\\\\nf^{\\ell}(x) &= \\sigma \\circ  \\theta^{\\ell} ([x, f^{\\ell-1}(x)]) \\quad \\ell = 2:L \\\\\nf(x) &= \\theta^{L+1}( [x, f^1, \\cdots, f^L] ) \\\\\n\\end{cases}.\n\\end{equation}\n\n\n", "meta": {"hexsha": "acb93ecfb01faf9fce469665d90c909811982310", "size": 4379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/WhyDeepX2.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/WhyDeepX2.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/WhyDeepX2.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.2323232323, "max_line_length": 200, "alphanum_fraction": 0.6412422928, "num_tokens": 1803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768145, "lm_q2_score": 0.8652240930029118, "lm_q1q2_score": 0.8183300461497363}}
{"text": "\n\\subsection{Type-I - Gumbel distribution}\n\nThe probability function is:\n\n\\(f(x)=\\dfrac{1}{\\beta }e^{-(\\dfrac{x-\\mu}{\\beta }+e^{-\\dfrac{x-\\mu }{\\beta }})}\\)\n\nWe can use:\n\n\\(z=\\dfrac{x-\\mu }{\\beta }\\)\n\nTo get:\n\n\\(f(x)=\\dfrac{1}{\\beta }e^{-(z+e^{-z})}\\)\n\n\\subsubsection{Link to the logistic function}\n\nThe difference between two draws from a Gumbel distribution is drawn from the logistic function.\n\n", "meta": {"hexsha": "7e326ce7be4271eb9674d106a98734381c4b784e", "size": 398, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/distributionsExtreme/01-01-EV1.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/distributionsExtreme/01-01-EV1.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/distributionsExtreme/01-01-EV1.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.9, "max_line_length": 96, "alphanum_fraction": 0.6432160804, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144274, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.8182823088174683}}
{"text": "\\chapter{Week 3: The matrix}\n\n\\section{What is a matrix}\nThe traditional notion of a matrix: a two dimensional array\n\\begin{equation*}\n  \\mA = \n  \\begin{bmatrix}\n    a & b & c \\\\\n    d & e & f\n  \\end{bmatrix}\n\\end{equation*}\nwhere $\\mA$ is a $2 \\times 3$ matrix.\n\nFor a matrix $\\mA$, the $i, j$ element of $\\mA$ is the element in row $i$, column $j$. It is traditionally written as $\\mA_{i, j}$\n\n\\begin{definition}\n  For finite sets $\\sR$ and $\\sC$, and $\\sR \\times \\sC$ matrix over field $\\fF$ is a function from $\\sR \\times \\sC$ to $\\fF$.\n\\end{definition}\n\n\\begin{definition}\n  $D \\times D$ identity matrix is the matrix $\\mathds{1}_D$ such that $\\mathds{1}_D[k, k] = 1$ for all $k \\in \\{1, , \\ldots, D\\}$ and zero elsewhere.\n\\end{definition}\n\nUsually we omit the subscript when $D$ is clear from the context.\nOften letter $\\mI$ is used instead of $\\mathds{1}$\n\n\\subsection{Column space and row space}\nOne simple role for a matrix: packing together a bunch of columns or rows.\n\\begin{definition}\n  Two vectors associated with a matrix $\\mM$:\n  \\begin{itemize}\n  \\item Column space of $\\mM = \\Span\\{\\text{columns of }\\mM\\}$. Written $\\Col \\mM$.\n  \\item Row space of $\\mM = \\Span\\{\\text{rows of }\\mM\\}$. Written $\\Row \\mM$.\n  \\end{itemize}\n\\end{definition}\n\n\\subsection{Transpose}\nTranspose swaps rows and columns. It is written as $\\mA^{\\top}$.\n\\begin{equation*}\n  \\mA = \n  \\begin{bmatrix}\n    a & b & c \\\\\n    d & e & f\n  \\end{bmatrix}\n\\end{equation*}\n\n\\begin{equation*}\n  \\mA^{\\top} = \n  \\begin{bmatrix}\n    a & d \\\\\n    b & e \\\\\n    c & f\n  \\end{bmatrix}\n\\end{equation*}\n\n\\subsection{Matrices as vectors}\nA matrix can be interpreted as a vector:\n\\begin{itemize}\n\\item an $\\sR \\times \\sS$ matrix is a function from $\\sR \\times \\sS$ to $\\fF$,\n\\item it can be interpreted as and $\\sR \\times \\sS$--vector:\n  \\begin{itemize}\n  \\item scalar-vector multiplication\n  \\item vector addition\n  \\end{itemize}\n\\end{itemize}", "meta": {"hexsha": "1106522319597c509464e2dbf1bdc0b3955c4426", "size": 1914, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/week3.tex", "max_stars_repo_name": "aanzolaavila/coding-the-matrix-notes", "max_stars_repo_head_hexsha": "b4c0426ed1f1d0aff19a945d92880be0e9a5f69e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/week3.tex", "max_issues_repo_name": "aanzolaavila/coding-the-matrix-notes", "max_issues_repo_head_hexsha": "b4c0426ed1f1d0aff19a945d92880be0e9a5f69e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapters/week3.tex", "max_forks_repo_name": "aanzolaavila/coding-the-matrix-notes", "max_forks_repo_head_hexsha": "b4c0426ed1f1d0aff19a945d92880be0e9a5f69e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4461538462, "max_line_length": 149, "alphanum_fraction": 0.6525600836, "num_tokens": 648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.960361158630024, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.8181823872162692}}
{"text": "\\documentclass[11pt,a4paper]{report}\n\\usepackage{amsmath,amsfonts,amssymb,amsthm,epsfig,epstopdf,titling,url,array}\n\\usepackage{changepage}\n\\usepackage{graphicx}\n\\usepackage[utf8]{inputenc}\n\\theoremstyle{plain}\n\\newtheorem{thm}{Theorem}[section]\n\\newtheorem{lem}[thm]{Lemma}\n\\newtheorem{prop}[thm]{Proposition}\n\\newtheorem*{cor}{Corollary}\n\\theoremstyle{definition}\n\\newtheorem{defn}{Definition}[section]\n\\newtheorem{conj}{Conjecture}[section]\n\\newtheorem{exmp}{Example}[section]\n\\newtheorem{exercise}{Exercise}[section]\n\\theoremstyle{remark}\n\\newtheorem*{rem}{Remark}\n\\newtheorem*{note}{Note}\n\\begin{document}\n\n\\section*{Problem}\nFind a function $f(x_0, ..., x_{n-1})$ that maps finite sequences $<x_1, ..., x_{n-1}>$ of positive integers one-to-one into the integers.  From a programmer's perspective, this means find a function that takes a variable number of positive integer parameters and returns a value that is unique to the sequence.  For example, the function $f(x_0, ..., x_{n-1}) = \\sum_{i=0}^{n-1}{x_i}$ does not work, since with $f$ defined this way $f(1,2,3)$ returns the same value as $f(3,3)$.\n\nWhat I am asking you to define here is essentially a \\textit{guaranteed unique} hash function.\n\n\\section*{Solution}\nLet $p_0, p_1, ..., p_n, p_{n+1}, ...$ be a list of the (infinitely many) prime numbers in ascending order.  So $p_0 = 2, p_1 = 3$ and so on.  Define \n$$f(x_0, ..., x_{n-1}) = p_0^{x_0}p_1^{x_1}...p_{n-1}^{x_{n-1}}$$\n$f$ maps $<x_1, ..., x_{n-1}>$ to the product of the first $n-1$ primes with exponents equal to the corresponding numbers in the sequence.  For example, $f(3,2,1) = 2^{3} \\times 3^{2} \\times 5^{1} = 380.$\nThis function is 1-1 because of the uniqueness of prime factorization (the Fundamental Theorem of Arithmetic).  If $f(x_0, ..., x_{n-1}) = f(y_0, ..., y_{m-1})$ then $p_0^{x_0}p_1^{x_1}...p_{n-1}^{x_{n-1}} = p_0^{y_0}p_1^{y_1}...p_{m-1}^{x_{m-1}}$; but this means that both of these expressions are prime factorizations of the same number.  By the uniqueness of prime factorization, it follows that $n = m$ and all of the exponents are the same, which means for all $i = 0, ..., n-1, x_i = y_i$, i.e., the sequences are the same.\n\n\\textit{Remark:} Above would actually be a bad hash function because it would overflow very quickly. Hash functions are not guaranteed unique partly because they in general can't be: their range is a finite subset of the positive integers.\n\n\\end{document}", "meta": {"hexsha": "722861e3f5d0c2d8ae77d3aa0600ffb408727cff", "size": 2436, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "godelNumbers/godelNumbers.tex", "max_stars_repo_name": "psteitz/problems", "max_stars_repo_head_hexsha": "c231561593ef7de6264c21d2c78d736866c1b341", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "godelNumbers/godelNumbers.tex", "max_issues_repo_name": "psteitz/problems", "max_issues_repo_head_hexsha": "c231561593ef7de6264c21d2c78d736866c1b341", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-03T21:08:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T21:08:11.000Z", "max_forks_repo_path": "godelNumbers/godelNumbers.tex", "max_forks_repo_name": "psteitz/problems", "max_forks_repo_head_hexsha": "c231561593ef7de6264c21d2c78d736866c1b341", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 71.6470588235, "max_line_length": 529, "alphanum_fraction": 0.7146962233, "num_tokens": 810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069962657177, "lm_q2_score": 0.8991213867309121, "lm_q1q2_score": 0.818116840278591}}
{"text": "% !TEX root = cs1textbook.tex\n\n\\chapter{Number Systems}\n\\label{appendix:numbersystems}\n\n\\minitoc\n\nThis appendix explains why programmers seem to choose to represent numbers in a different base, or \\textit{radix}, than what you may be used to, and how you can try to convert between different radices.\n\n\\setcounter{section}{9}\n\\section{Decimal Numbers}\nThe numbers that the average person encounters in his or her daily life are all represented as \\textit{decimal} numbers.  The Latin root \\textit{dec-} refers to the number 10, as illustrated in the words for a collection of ten years (\\textit{decade}) or a collection of ten units of loudness (\\textit{decibel}).\n\nEach digit in a decimal number has a place name - the ones place, the tens place, the hundreds place, etc. - that describes the meaning of the digit.  For instance, in the decimal number 3502, we're meant to understand that there are three thousands, five hundreds, no tens, and two ones, or:\n\n\\[ 3502 = 3 \\cdot 1000 + 5 \\cdot 100 + 0 \\cdot 10 + 2 \\cdot 1 \\]\n\nNotice that each of these place names corresponds to a power of 10, so we can also write 3502 as:\n\n\\begin{equation}\\label{base10}3502 = 3 \\cdot 10^3 + 5 \\cdot 10^2 + 0 \\cdot 10^1 + 2 \\cdot 10^0\\end{equation}\n\nThis leads to the description of decimal numbers as \\textit{base ten} numbers, because the base in each of those exponential expressions in Equation \\ref{base10} is 10.  Notice also that the base ten system provides ten digits.  Any number composed of a sequence of only the last digit, like 99, or 999,999, will be followed by a number composed of a 1 followed by a sequence of zeroes, like 100 or 1,000,000.\n\n\\setcounter{section}{1}\n\\section{Binary Numbers}\nThe decimal number system is not, however, the most convenient way to discuss computer systems.  The state of any component of a computer can usually be described in one of two ways -- open or closed, high voltage or low voltage, magnetically north or magnetically south, etc.  For this reason, data storage and transmission are often described instead using \\textit{binary} numbers, from the Latin root \\textit{bi-} for two (\\textit{bicycle}, \\textit{bidirectional}, \\textit{binaural}).  The \\textbf{binary number system}\\index{Binary}, also called \\textit{base two}, defines numbers in a two-digit system, where each exponent's base is 2.  For instance, the binary number 11101 represents this idea:\n\n\\begin{equation}\n    \\begin{array}{ccccccccccc}\n    11101_2 &=& 1 \\cdot 2^4 &+& 1 \\cdot 2^3 &+& 1 \\cdot 2^2 &+& 0 \\cdot 2^1 &+& 1 \\cdot 2^0\\\\\n    &=& 16 &+& 8 &+& 4 &+& 0 &+& 1\\\\\n    &=& 29\n\\end{array}\n\\end{equation}\n\nSince the largest binary digit is 1, any binary number composed of all 1s will be followed by a number consisting of a 1 and a sequence of zeros; for instance, $111_2 + 1 = 1000_2$.\n\nNotice that the most correct term for a \\underline{bi}nary digi\\underline{t} is \\textit{bit}.\n\n\\setcounter{section}{15}\n\\section{Hexadecimal Numbers}\n\nAs one counts upward in binary numbers, the length in bits grows exponentially compared to the length of their decimal equivalents.  Even a relatively small decimal number like 351 turns into the nine-bit number $101011111_2$.  It is incredibly difficult for humans to read long sequences of zeros and ones such as this.  However, it is also difficult to convert between base two and base ten, in either direction, in one's head.  There is no pattern to follow, and the amount of memorization required is way out of proportion with the usefulness of such a task.\n\nThere is, however, a way to represent these numbers in a shorter format, that supports much easier conversion.  The term \\textbf{hexadecimal}\\index{Hexadecimal} was composed from the Greek root \\textit{hexa-} for 6 and the Latin root \\textit{dec-} for ten, to help us talk about numbers in \\textit{base sixteen}.  The sixteen digits in hexadecimal are the ten decimal digits 0-9, and then the first six letters of the alphabet, so that $10_{10} =$ A$_{16}$, $11_{10} =$ B$_{16}$, and so on.  Since $16 = 2^4$, each hex digit corresponds to a unique four-bit sequence.  With a little bit of practice, even a novice programmer can become accustomed to interpreting \\verb-0011- as \\verb-3-, \\verb-1010- as \\verb-A-, and \\verb-1111- as \\verb-F-, and so any binary number can be written as a hex number using no more than 25\\% of the digits.\n\nIt follows, then, that any byte -- which represents a number in the range $2^0 \\le n < 2^8$ -- can be written using two hex digits, since $0_{10} = 00000000_2 = 00_{16}$, and $255_{10} = 11111111_2 = $ FF$_{16}$.  For instance, using the examples from the previous paragraph, the number $00111010_2$ is equal to the number 3A$_{16}$.\n\n\\setcounter{section}{7}\n\\section{Octal Numbers}\n\nWhile less frequently used, it is useful to mention here that \\textit{base eight} digits, called \\textbf{octal}\\index{Octal} (think about an \\textit{octagon}) can represent a three-bit sequence.  The commands to alter a file's permissions in Unix take advantage of octal numbers.  Unix file permissions come in three varieties -- read permission, write permission, and execute permission -- and in three groups -- what the file's owner is allowed to do, what members of the owner's group are allowed to do, and what other users on the system are allowed to do.  Each permission can be thought of as a \\textit{flag}, or a Boolean setting: a 1 means permission is granted, and a 0 means that permission is not granted.  So, to give the owner of a file called \\texttt{foo.txt} permission to read and write a file, but not to execute it (\\texttt{110}), and to allow others only to read the file (\\texttt{100}), the Unix command would look like:\n\n\\begin{center}\\texttt{chmod 644 foo.txt}\\end{center}\n\nsince $6_8 = 110_2$ and $4_8 = 100_2$.\n\n\\section*{Number Systems Compared}\n\nThe following table shows how to write the decimal numbers 0 through 16 in binary, octal, and hex.\n\n\\begin{center}\n\\begin{tabular}{rrrr}\n\\textbf{Binary} & \\textbf{Octal} & \\textbf{Decimal} & \\textbf{Hexadecimal}\\\\\n\\hline\n0 & 0 & 0 & 0\\\\\n1 & 1 & 1 & 1\\\\\n10 & 2 & 2 & 2\\\\\n11 & 3 & 3 & 3\\\\\n100 & 4 & 4 & 4\\\\\n101 & 5 & 5 & 5\\\\\n110 & 6 & 6 & 6\\\\\n111 & 7 & 7 & 7\\\\\n1000 & 10 & 8 & 8\\\\\n1001 & 11 & 9 & 9\\\\\n1010 & 12 & 10 & A\\\\\n1011 & 13 & 11 & B\\\\\n1100 & 14 & 12 & C\\\\\n1101 & 15 & 13 & D\\\\\n1110 & 16 & 14 & E\\\\\n1111 & 17 & 15 & F\\\\\n10000 & 20 & 16 & 10\\\\\n\\end{tabular}\n\\end{center}\n", "meta": {"hexsha": "f8a1f4a7c9f6d2926c5694abd5abcad2a455e9e1", "size": 6383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendix-numbers.tex", "max_stars_repo_name": "cmerlo441/cs1textbook", "max_stars_repo_head_hexsha": "203bd7e03ccc01470e420c40de43551f8bdaa04b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "appendix-numbers.tex", "max_issues_repo_name": "cmerlo441/cs1textbook", "max_issues_repo_head_hexsha": "203bd7e03ccc01470e420c40de43551f8bdaa04b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "appendix-numbers.tex", "max_forks_repo_name": "cmerlo441/cs1textbook", "max_forks_repo_head_hexsha": "203bd7e03ccc01470e420c40de43551f8bdaa04b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.0941176471, "max_line_length": 940, "alphanum_fraction": 0.727714241, "num_tokens": 1902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8918110562208682, "lm_q1q2_score": 0.8180606577516928}}
{"text": "\n\\subsection{Multiples and Lowest Common Multiples (LCM)}\n\n\\subsubsection{Multiples}\n\nThe multiple of a number is it added to itself iteratively.\n\nThe multiples of \\(18\\) for example are:\n\n\\([18,36,54,72,90,...]\\)\n\nAnd for \\(24\\):\n\n\\([24,48,72,96,120,...]\\)\n\n\\subsubsection{Common multiples}\n\n\\subsubsection{Lowest common multiple}\n\nThe lowest common multiple of \\(2\\) numbers is again as the name suggests.\n\nSo \\(LCM(18,24)=72\\).\n\t\n", "meta": {"hexsha": "eefca052b68ae5bdc8c24e7a877b3f476d16f93c", "size": 433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/GCD_LCM/01-02-LCM.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/GCD_LCM/01-02-LCM.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/GCD_LCM/01-02-LCM.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.0416666667, "max_line_length": 74, "alphanum_fraction": 0.6997690531, "num_tokens": 124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.8840392924390585, "lm_q1q2_score": 0.8179396366110664}}
{"text": "\\section{Spectral Theory}\r\nSpectral Theory is the study of spectrum (eigen-stuff) of operators, which is very important in boths maths and physics.\r\nFix an inner product space $V$.\r\nRecall that an opeator $\\alpha\\in L(V)$ is self-adjoint if $\\alpha=\\alpha^\\ast$.\r\n\\begin{lemma}\r\n    A self-adjoint opeator $\\alpha\\in L(V)$ has real eigenvalues and eigenvectors with different eigenvalues are orthogonal.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If $v\\neq 0$ and $\\alpha(v)=\\lambda v$, then $\\lambda\\|v\\|^2=\\langle \\lambda v,v\\rangle=\\langle\\alpha(v),v\\rangle=\\langle v,\\alpha(v)\\rangle=\\langle v,\\lambda(v)\\rangle=\\bar\\lambda\\|v\\|^2$, so $\\lambda=\\bar\\lambda\\implies\\lambda\\in\\mathbb R$.\\\\\r\n    Now if $v,w\\neq 0,\\lambda\\neq\\mu$ have $\\alpha(v)=\\lambda v,\\alpha(w)=\\mu w$, then $\\lambda,\\mu\\in\\mathbb R$ and hence $\\lambda\\langle v,w\\rangle=\\langle\\alpha(v),w\\rangle=\\langle v,\\alpha(w)\\rangle=\\langle v,\\mu w\\rangle=\\bar\\mu\\langle v,w\\rangle=\\mu\\langle v,w\\rangle\\implies\\langle v,w\\rangle=0$ since $\\lambda\\neq\\mu$.\r\n\\end{proof}\r\n\\begin{theorem}[Spectral Theorem for Self-Adjoint Operators in Finite Dimensions]\r\n    Let $V$ be a finite dimensional inner product space over $F=\\mathbb R$ or $\\mathbb C$ and $\\alpha\\in L(V)$ is self-adjoint.\r\n    Then $V$ has an orthogonal basis of eigenvectors of $\\alpha$.\r\n\\end{theorem}\r\nConsequently, $\\alpha$ can be diagonalised in an orthonormal basis of $V$.\r\n\\begin{proof}\r\n    We proceed by induction on $n=\\dim V$.\r\n    $n=1$ is trivial.\r\n    Now assume it is true for $n-1$.\r\n    Let $\\lambda$ be a root of $\\chi_A$ (exists by FTA).\r\n    Now $\\lambda\\in\\mathbb R$ by the preceding lemma.\r\n    Choose $v\\in V\\setminus\\{0\\}$ such that $\\alpha(v)=\\lambda v$.\r\n    By normalising we can assume $v$ is unit.\r\n    Let $U=\\langle \\{v\\}\\rangle^\\perp\\le V$.\r\n    Then obviously $\\alpha(U)\\le U$ since $\\langle\\alpha(u),v\\rangle=\\langle u,\\alpha(v)\\rangle=\\langle u,\\lambda v\\rangle=\\bar\\lambda\\langle u,v\\rangle=0$ for any $u\\in U$.\r\n    Also $\\dim U=n-1$.\r\n    Adding $v$ to the basis of $U$ in the induction hypothesis completes the induction process.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $V$ is a finite dimensional inner product space and $\\alpha\\in L(V)$ is self-adjoint, then $V$ is the orthogonal direct sum of all the eigenspaces of $\\alpha$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Follows directly.\r\n\\end{proof}\r\nRecall that $\\alpha\\in L(V)$ is an isometry iff $\\alpha^\\ast\\circ\\alpha=\\operatorname{id}$.\r\nIt is called unitary when $V$ is a vector space over $\\mathbb C$.\r\n\\begin{lemma}\r\n    Let $V$ be a complex inner product space and $\\alpha\\in L(V)$ be unitary.\r\n    Then:\\\\\r\n    (i) All eigenvalues of $\\alpha$ are in the unit circle $S^1$.\\\\\r\n    (ii) Eigenvectors with distinct eigenvalues are orthogonal.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If $v\\neq 0,\\alpha(v)=\\lambda v$ we have $\\lambda\\neq 0$ as $\\alpha\\neq 0$ and that $\\lambda\\|v\\|^2=\\langle\\alpha(v),v\\rangle=\\langle v,\\alpha^{-1}(v)\\rangle=\\langle v, \\lambda^{-1}(v)\\rangle=\\bar{\\lambda}^{-1}\\|v\\|^2$, so $\\lambda\\bar\\lambda=1\\implies\\lambda\\in S^1$.\\\\\r\n    Now if $v,w\\neq 0$ and $\\alpha(v)=\\lambda v,\\alpha(w)=\\mu v$ for $\\lambda\\neq\\mu$, then $\\lambda\\langle v,w\\rangle=\\langle\\alpha(v),w\\rangle=\\langle v,\\alpha^{-1}(w)\\rangle=\\langle v,\\mu w\\rangle=\\bar{\\mu}^{-1}\\langle v,w\\rangle=\\mu\\langle v,w\\rangle\\implies\\langle v,w\\rangle=0$.\r\n\\end{proof}\r\n\\begin{theorem}[Spectral Theorem for Unitary Operators in Finite Dimensions]\r\n    Let $V$ be a finite dimensional inner product space over $F=\\mathbb C$ and $\\alpha\\in L(V)$ is unitary.\r\n    Then $V$ has an orthogonal basis of eigenvectors of $\\alpha$.\r\n\\end{theorem}\r\nEquivalently, $\\alpha$ can be diagonalised in an orthonormal basis.\r\n\\begin{proof}\r\n    Same idea as in the case for self-adjoint operators.\r\n\\end{proof}\r\nSadly, we cannot tell the same tale for real orthogonal matrices since it can have complex eigenvalues.", "meta": {"hexsha": "012d514e54152131f93a427ad7e3489660db0f43", "size": 3883, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "23/spectral.tex", "max_stars_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_stars_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "23/spectral.tex", "max_issues_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_issues_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "23/spectral.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.3392857143, "max_line_length": 327, "alphanum_fraction": 0.6837496781, "num_tokens": 1233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303295, "lm_q2_score": 0.8840392817460333, "lm_q1q2_score": 0.8179396248949271}}
{"text": "\\section{Reparameterization \\& Arc Length}\r\n\\noindent\r\nVVFs can be reparameterized to trace out the same curve at different speeds by replacing $t$ in $\\vec{r}(t)$ with any non-decreasing function of $t$.\r\nThis fact can come in handy to make the bounds of an integration problem more convenient.\\\\\r\n\r\n\\noindent\r\nThe integral of the derivative of a VVF gives the displacement vector because\r\n\\begin{equation*}\r\n\t\\int_{a}^{b}{\\vec{r^\\prime}(t)\\mathrm{d}t}=\\vec{r}(b)-\\vec{r}(a).\r\n\\end{equation*}\r\nThis is exactly like how $\\text{veclvity} \\cdot \\text{time} = \\text{displacment}$.\r\n\r\n\\noindent\r\nIf we integrate the magnitude of $\\vec{r^\\prime}(t)$, we can use the fact that $\\text{distance} = \\text{speed} \\cdot \\text{time}$ to find the arc length of $\\vec{r}(t)$ as\r\n\\begin{equation*}\r\n\ts=\\int{\\norm{\\vec{r^\\prime}(t)}\\mathrm{d}t}=\\int{\\sqrt{\\left(\\frac{\\mathrm{d}x}{\\mathrm{d}t}\\right)^2+\\left(\\frac{\\mathrm{d}y}{\\mathrm{d}t}\\right)^2+\\left(\\frac{\\mathrm{d}z}{\\mathrm{d}t}\\right)^2}\\mathrm{d}t}.\r\n\\end{equation*}\r\nWe can also write this as an arclength function,\r\n\\begin{equation*}\r\n\ts(t)=\\int_{0}^{t}{\\norm{\\vec{r^{\\prime}}(\\tau)}\\mathrm{d}\\tau}.\r\n\\end{equation*}\r\n\r\n\\noindent\r\nIf we have a function\r\n\\begin{equation*}\r\n\tf(t)=s(t)=\\int_{0}^{t}{\\norm{\\vec{r^{\\prime}}(\\tau)}\\mathrm{d}\\tau},\r\n\\end{equation*}\r\nwhere $s$ is strictly increasing, then $f$ has an inverse by the horizontal line test.\r\nThat is, $t(s) = f^{-1}(s)$ exists and is also non-decreasing.\r\nIf we reparameterize $\\vec{r}(t)$ to $\\vec{r}(t(s))$, which is called the arc length parameterization, the parameterization will have a constant speed.", "meta": {"hexsha": "0bd5cc0a88026c175c7159056fb4a7e2e93d2ee6", "size": 1611, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/ReparameterizationArcLength.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorValuedFunctions/ReparameterizationArcLength.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorValuedFunctions/ReparameterizationArcLength.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 53.7, "max_line_length": 211, "alphanum_fraction": 0.6809435133, "num_tokens": 544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475778774728, "lm_q2_score": 0.8670357580842941, "lm_q1q2_score": 0.8179160823219773}}
{"text": "\n\\section{Dispersion Relation Coefficients}\\label{sec:coefficients}\n\nIn \\eqref{laplacian} and \\eqref{gamma determination} we give the definition and how to determine the $\\gamma_s^{(\\nstep)}$ coefficients that give us finite difference formulas.\nThis is done by matching the expansion of the cosine to the continuum dispersion\n\\begin{align}\n\tp^2\n\t&\\mapsto\n\t- \\frac{1}{\\epsilon^2}\\sum_{s=0}^{n_s} \\gamma_s^{(n_s)} \\cos(s p \\epsilon)\n\t=\n\t\\frac{1}{\\epsilon^2}\\sum_{s=0}^{n_s} \\sum_{m=0}^\\infty \\gamma_s^{(n_s)}\\frac{(-)^m}{(2m)!} (s p \\epsilon)^{2m}\n\t\\overset{!}{=}\n\tp^2 \\left[ 1 + \\mathcal O \\left( (\\epsilon p)^{2 n_s} \\right) \\right]\n\t\\, .\n\\end{align}\nMatching this expression order by order in $\\epsilon p$ or equivalently $m \\leq n_s$ effectively results in a matrix equation for the coefficients $\\gamma_s^{(n_s)}$\n\\begin{align}\n\tA_{ms} &\\equiv \\frac{(-)^m}{(2m)!} s^{2m}\n\t\\, , &\n\t\\sum_{s=0}^{n_s} A_{m s} \\gamma_s^{(n_s)}\n\t\\overset{!}{=}\n\tv_m\n\t&=\n\t\\begin{cases}\n\t\t1 & m=1 \\\\ 0 & \\text{otherwise}\n\t\\end{cases}\n\t\\, , &\n\t\\vec \\gamma^{(n_s)}\n\t&= A^{-1} \\vec v\n\\end{align}\nResults for order $n_s \\leq 4$ are displayed in \\tabref{dispersion coefficients}.\n\n\\begin{table}[ht]\n    \\caption{Values for $\\gamma_s^{(\\nstep)}$ for a variety of different $\\nstep$s that give the optimal approximation $\\omega^{(\\nstep)}(p,\\epsilon) = (\\epsilon p)^2\\left[1+ \\order{(\\epsilon p)^{2 \\nstep}}\\right]$.}\n    \\label{tab:dispersion coefficients}\n    \\begin{tabular}{c | ccccc}\n        $\\gamma_s^{(\\nstep)}$   &   $s=0$   &   $s=1$   &   $s=2$   &   $s=3$       &   $s=4$   \\\\ \\hline\n        $\\nstep=1$              &   $2$     &   $-2$    &           &               &           \\\\\n        $\\nstep=2$              &   $5/2$   &   $-8/3$  &   $1/6$   &               &           \\\\\n        $\\nstep=3$              &   $49/18$ &   $-3$    &   $3/10$  &   $-1/45$     &           \\\\\n        $\\nstep=4$              &   $205/72$&   $-16/5$ &   $2/5$   &   $-16/315$   &   $1/280$\n    \\end{tabular}\n\\end{table}\n", "meta": {"hexsha": "3bead5e4803351cba94bea7ccf0286c6c24892b6", "size": 1990, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/luescher-nd/section/dispersion-coefficients.tex", "max_stars_repo_name": "ckoerber/luescher-nd", "max_stars_repo_head_hexsha": "d1bc6bff0c6ee9f4dc0d1d0bb4bcfa842c44cceb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-12T22:19:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-26T14:06:49.000Z", "max_issues_repo_path": "paper/luescher-nd/section/dispersion-coefficients.tex", "max_issues_repo_name": "ckoerber/luescher-nd", "max_issues_repo_head_hexsha": "d1bc6bff0c6ee9f4dc0d1d0bb4bcfa842c44cceb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-12-16T19:49:19.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-02T00:50:31.000Z", "max_forks_repo_path": "paper/luescher-nd/section/dispersion-coefficients.tex", "max_forks_repo_name": "ckoerber/luescher-nd", "max_forks_repo_head_hexsha": "d1bc6bff0c6ee9f4dc0d1d0bb4bcfa842c44cceb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.2272727273, "max_line_length": 216, "alphanum_fraction": 0.535678392, "num_tokens": 759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475778774728, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.8179160774603128}}
{"text": "\\subsection{Localization}\\label{subsec:localization}\n\n\\begin{definition}\\label{def:ring_localization}\\mcite[428]{Knapp2016BasicAlgebra}\n  Let \\( S \\subseteq R \\) be closed under multiplication.\n\n  Define the following equivalence relation on \\( R \\times S \\):\n  \\begin{equation*}\n    (r, s) \\cong (r', s') \\iff \\exists t \\in S: t(rs' - sr') = 0.\n  \\end{equation*}\n\n  Define the ring\n  \\begin{equation*}\n    S^{-1} R \\coloneqq R \\times S / \\cong\n  \\end{equation*}\n  with operations inherited from \\( R \\) using the injection\n  \\begin{balign*}\n     & \\iota: R \\to S^{-1} R        \\\\\n     & \\iota(r) \\coloneqq [(r, 1)].\n  \\end{balign*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:ring_localization_universal_property}\\mcite[431]{Knapp2016BasicAlgebra}\n  Let \\( S \\subseteq R \\) be closed under multiplication. The ring \\hyperref[def:ring_localization]{localization} \\( S^{-1} R \\) satisfies the following universal mapping property: if \\( T \\) is a nontrivial commutative unital ring and \\( \\varphi: R \\to T \\) is a unital ring homomorphism such that \\( \\varphi(S) \\) are units in \\( T \\), there exists a unique ring homomorphism \\( \\hat \\varphi \\) such that the following diagram commutes:\n\n  \\begin{alignedeq}\\label{thm:ring_localization_universal_property/diagram}\n    \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n      beginfig(1);\n      input metapost/graphs;\n\n      v1 := thelabel(\"$S^{-1} R$\", origin);\n      v2 := thelabel(\"$T$\", (2, 0) scaled u);\n      v3 := thelabel(\"$R$\", (1, 1) scaled u);\n\n      a1 := straight_arc(v3, v2);\n      a2 := straight_arc(v3, v1);\n\n      d1 := straight_arc(v1, v2);\n\n      draw_vertices(v);\n      draw_arcs(a);\n\n      drawarrow d1 dotted;\n\n      label.urt(\"$\\varphi$\", straight_arc_midpoint of a1);\n      label.ulft(\"$\\iota$\", straight_arc_midpoint of a2);\n      label.top(\"$\\hat\\varphi$\", straight_arc_midpoint of d1);\n      endfig;\n    \\end{mplibcode}\\fi\n  \\end{alignedeq}\n\\end{proposition}\n\n\\begin{proposition}\\label{thm:ring_localization_preserves_ideals}\\mcite[432]{Knapp2016BasicAlgebra}\n  If \\( I \\) is an ideal in \\( R \\), then\n  \\begin{equation*}\n    S^{-1} I \\coloneqq \\{ s^{-1} x \\mid s \\in S, x \\in I \\}\n  \\end{equation*}\n  is an ideal in the \\hyperref[def:ring_localization]{localization} \\( S^{-1} R \\).\n\\end{proposition}\n\n\\begin{definition}\\label{def:local_ring}\n  If \\( R \\) has a unique \\hyperref[def:maximal_ring_ideal]{maximal ideal}, we say that it is a \\term{local ring}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:localization_of_prime_is_local}\\mcite[cor. 8.50]{Knapp2016BasicAlgebra}\n  Fix a prime ideal \\( P \\). Its complement\n  \\begin{equation*}\n    S \\coloneqq \\BbbZ \\setminus P\n  \\end{equation*}\n  is closed under multiplication and we can perform \\hyperref[def:ring_localization]{localization}.\n\n  In this case, the ring \\( S^{-1} R \\) is a local \\hyperref[def:local_ring]{ring} and \\( M \\coloneqq S^{-1} P \\) is its unique maximal ideal.\n\\end{proposition}\n\n\\begin{example}\\label{ex:ring_localization}\\mcite[430]{Knapp2016BasicAlgebra}\n  Let \\( p \\) be a prime \\hyperref[def:prime_number]{number} and \\( P = \\braket p \\) be the corresponding \\hyperref[def:prime_ring_ideal]{prime ideal}. Denote its complement by \\( S \\).\n\n  The ring \\( S^{-1} R \\) then consists of all rational \\hyperref[def:set_of_rational_numbers]{numbers} whose denominators are not divisible by \\( p \\).\n\n  In particular, if \\( p = 2 \\), then \\( S^{-1} R \\) is the set of all rational numbers with odd denominators.\n\\end{example}\n\n\\begin{definition}\\label{def:field_of_fractions}\n  The \\term{field of fractions} of \\( R \\) is defined as the \\hyperref[def:ring_localization]{localization} of \\( R \\) by the set\n  \\begin{equation*}\n    S \\coloneqq R \\setminus \\{ 0 \\}.\n  \\end{equation*}\n\\end{definition}\n\\begin{proof}\n  This is indeed a field since all nonzero elements are invertible.\n\\end{proof}\n", "meta": {"hexsha": "cf9f6302f5f5f71dcdaa7b236b8df99993e22212", "size": 3849, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/localization.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/localization.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/localization.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.2967032967, "max_line_length": 438, "alphanum_fraction": 0.6786178228, "num_tokens": 1229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.8962513675912912, "lm_q1q2_score": 0.8177721481309533}}
{"text": "The SHA-256 algorithm \\cite{SHA_NIST_FIPS} is a secure hash algorithm that\nreceives input data of any size up to $2^{64}$ bits and computes an output of\n256 bits. This output is called a message digest.\nThe SHA-256 algorithm has two main stages: preprocessing and hash\ncomputation.\n\n\\subsection{Preprocessing}\n\\label{subsec:preprocessing}\nThe preprocessing stage pads the input data to obtain an input size multiple of\n512 bits. Given a message $M$ of size $\\lambda$ bits. The padding process\nappends the bit \"1\" to the end of the message, followed by $\\delta$ \"0\" bits\nsuch that $\\delta$ is the smallest positive integer that\nsolves~(\\ref{eq:sha_padding}).\n\n\\begin{equation}\n\\lambda + 1 + \\delta \\equiv 448 \\mod 512.\n\\label{eq:sha_padding}\n\\end{equation}\n\nAfter the padded zeroes, the message is appended with the 64-bit representation\nof the size of the original message $\\lambda$. At the end of this process, the \npadded message size is a multiple of 512 bits. The padded input splits into\nblocks of 512 bits. Each blocks forms a set of sixteen words of 32 bits. \n\nThe preprocessing stage also sets the initial state for the hash value. The hash\nstate values are a set of eight 32 bit words. For the SHA-256 algorithm, the\ninitial values are the first 32 bits of the fractional part of the square root\nof the first eight prime numbers.\n\n\\subsection{Hash Computation}\n\\label{subsec:hash_computation}\n\nFigure~\\ref{fig:hash_flowchart} presents the hash computation stage which\nprocesses one message block at a time. For each iteration $i$, the hash stage\nvalues $H_{0}^{(i+1)}, H_{1}^{(i+1)},..., H_{7}^{(i+1)}$ are updated using a\nmessage schedule of sixty-four 32 bit words $W_0, W_1,..., W_{63}$, the\nprevious hash state values $H_{0}^{(i)}, H_{1}^{(i)},..., H_{7}^{(i)}$ and 64\nconstants $K_{0},K_{1},...,K_{63}$ of 32 bit each.\n\n\\begin{figure}[!htbp]\n    \\centerline{\\includegraphics[width=14cm]{./figures/crypto_hashblock_flowchart.pdf}}\n    \\vspace{0cm}\\caption{SHA-256 hash function flowchart.}\n    \\label{fig:hash_flowchart}\n\\end{figure}\n\nThe initial hash state values and the message block words come from the \npreprocessing stage as described in section~\\ref{subsec:preprocessing}.\nThe 64 constants $K_{t}$ are the 32 fractional bits of the cubic roots of the\nfirst 64 prime numbers.\n\nThe sixty-four message schedule words are the sixteen 32 bit words from the\ninput message block plus 48 generated words. Each generated word $W_{t}$ is\ncomputed by the operations presented in~(\\ref{eq:gen_w}). The addition is\nmodulo $2^{32}$.\n\n\\begin{equation}\n    W_{t} = \\sigma_{1}(W_{t-2}) + W_{t-7} + \\sigma_{0}(W_{t-15}) + W_{t-16}, \\ \\ \\ 16 \\leq t \\leq 63.\n\\label{eq:gen_w}\n\\end{equation}\n\nWhere $\\sigma_{0}()$ and $\\sigma_{1}()$ functions are a set of logic operations\ndefined in~(\\ref{eq:sigma_funcs}). $ROTR^{n}(x)$ is a rotate right $n$ bits\nfunction and $SHR^{n}(x)$ is a right shift $n$ bits operation.\n\n\\begin{align}\n    \\begin{split}\n        \\sigma_{0}(x) &= ROTR^{7}(x) \\oplus ROTR^{18}(x) \\oplus SHR^{3}(x), \\\\\n        \\sigma_{1}(x) &= ROTR^{17}(x) \\oplus ROTR^{19}(x) \\oplus SHR^{10}(x).\n    \\end{split}\n\\label{eq:sigma_funcs}\n\\end{align}\n\nThe initial hash state values initialize a set of working variables $a, b, c,\nd, e, f, g, h$:\n\n\\begin{align}\n    \\begin{split}\n        a &= H_{0}^{(i-1)} \\\\\n        b &= H_{1}^{(i-1)} \\\\\n        c &= H_{2}^{(i-1)} \\\\\n        d &= H_{3}^{(i-1)} \\\\\n        e &= H_{4}^{(i-1)} \\\\\n        f &= H_{5}^{(i-1)} \\\\\n        g &= H_{6}^{(i-1)} \\\\\n        h &= H_{7}^{(i-1)}.\n    \\end{split}\n\\label{eq:init_state}\n\\end{align}\n\nThe working variables are updated for 64 iterations ($ 0 \\leq t \\leq 63$),\nfollowing the algorithm in~(\\ref{eq:hash_iter}). The functions $\\Sigma_1(x)$,\n$Ch(x,y,z)$, $\\Sigma_0(x)$ and $Maj(x,y,z)$ are defined\nin~(\\ref{eq:Sigma_Ch_Maj}). $Ch(x,y,z)$ is a choice operation: if $x$ is 1, the\noutput is $z$, otherwise outputs $y$. $Maj(x,y,z)$ outputs the most common\nvalue between the three inputs.\n\n\\begin{align}\n    \\begin{split}\n        T_1 &= h + \\Sigma_1(e) + Ch(e,f,g) + K_{t} + W_{t} \\\\\n        T_2 &= h + \\Sigma_0(a) + Maj(a,b,c) \\\\\n        h &= g \\\\\n        g &= f \\\\\n        f &= e \\\\\n        e &= d + T_1 \\\\\n        d &= c \\\\\n        c &= b \\\\\n        b &= a \\\\\n        a &= T_1 + T_2.\n    \\end{split}\n\\label{eq:hash_iter}\n\\end{align}\n\n\\begin{align}\n    \\begin{split}\n        \\Sigma_{0}(x) &= ROTR^{2}(x) \\oplus ROTR^{13}(x) \\oplus ROTR^{22}(x), \\\\\n        \\Sigma_{1}(x) &= ROTR^{6}(x) \\oplus ROTR^{11}(x) \\oplus ROTR^{25}(x), \\\\\n        Ch(x,y,z) &= (x \\land y) \\oplus ( \\neg x \\land z), \\\\\n        Maj(x,y,z) &= (x \\land y) \\oplus (x \\land z) \\oplus (y \\land z).\n    \\end{split}\n\\label{eq:Sigma_Ch_Maj}\n\\end{align}\n\nThe results $H_{0}^{(i+1)}, H_{1}^{(i+1)},..., H_{7}^{(i+1)}$ of hashing\niteration $i$ are the final values of the working variables $a,..., h$.\nThe resulting hash state values of one iteration are the input of the next.\nThis process repeats for all message blocks. The hash state values at the final\niteration concatenated form the message digest.\n\n\n", "meta": {"hexsha": "d57cfc2cbe4689d2ce2d38ad2bd10a67481a15aa", "size": 5046, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/acceleration_plan/sha256_algo.tex", "max_stars_repo_name": "P-Miranda/iob-soc-sha", "max_stars_repo_head_hexsha": "f19dbbaa1625ed0dc9613180c6fd54498d5c4760", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-16T15:55:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T15:55:33.000Z", "max_issues_repo_path": "document/acceleration_plan/sha256_algo.tex", "max_issues_repo_name": "P-Miranda/iob-soc-sha", "max_issues_repo_head_hexsha": "f19dbbaa1625ed0dc9613180c6fd54498d5c4760", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "document/acceleration_plan/sha256_algo.tex", "max_forks_repo_name": "P-Miranda/iob-soc-sha", "max_forks_repo_head_hexsha": "f19dbbaa1625ed0dc9613180c6fd54498d5c4760", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.8153846154, "max_line_length": 101, "alphanum_fraction": 0.6468489893, "num_tokens": 1637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107984180245, "lm_q2_score": 0.872347369700144, "lm_q1q2_score": 0.8175733748545355}}
{"text": "\\section{Vectors}\r\n\\noindent\r\nA vector is a quantity with both direction and magnitude. One can think of it as a directed line segment. In multivariable calculus, we mostly will work with vectors in $\\mathbb{R}^2$ and $\\mathbb{R}^3$, but vectors can exist in other dimensions.\\\\\r\n\r\n\\noindent\r\nNumerical (scalar) quantities have vector analogues, many of which show up in physics. Speed becomes velocity, distance becomes displacement, and mass becomes weight.\\\\\r\n\r\n\\noindent\r\nSay we have a 2D vector, $\\vec{v} = \\langle v_x, v_y \\rangle$.\r\n\r\n\\begin{figure}[h]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.5]{Images/backgroundReview/VectorAddition}\r\n\\end{figure}\r\n\r\n\\noindent\r\nIts length, also called magnitude or norm, is notated $\\norm{\\vec{v}} = \\sqrt{v_x^2+v_y^2}$. This pattern of the norm being equal to the square-root of the sum of the squares of the vector's components continues into higher dimensions.\\\\\r\n\r\n\\noindent\r\nThe angle a 2D vector forms with the horizontal axis is $\\theta = \\tan^{-1}{\\left(\\frac{v_y}{v_x}\\right)}$. There is not a useful version of this formula in higher dimensions.\\\\\r\nUsing $\\theta$ and $\\norm{\\vec{v}}$, we can see that $v_x = \\norm{\\vec{v}}\\cos{\\theta}$ and $v_y = \\norm{\\vec{v}}\\sin{\\theta}$.\\\\\r\n\r\n\\noindent\r\nVectors can be added and subtracted from each other in a way that the result is another vector. We do this numerically by adding the corresponding components of each vector.\\\\\r\nFor example, if $\\vec{a} = \\langle 1,3 \\rangle$ and $\\vec{b} = \\langle 4,7 \\rangle$, then $\\vec{a}+\\vec{b} = \\langle 1+4, 3+7 \\rangle = \\langle 5,10 \\rangle$.\\\\\r\nand $\\vec{b}-\\vec{a} = \\langle 4-1, 7-3, \\rangle = \\langle 3,4 \\rangle$.\r\n\r\n\\noindent\r\nVisually, you can think of $\\vec{v}+\\vec{w}$ as the vector connecting the tail of $\\vec{v}$ with the tip of $\\vec{w}$ where the tail of $\\vec{v}$ is on the tip of $\\vec{w}$.\r\n\r\n\\begin{figure}[h]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.33]{Images/backgroundReview/Parallelogram}\r\n\\end{figure}\r\n\r\n\\noindent\r\nWe can also multiply vectors by scalars and get another vector as a result. We do this by multiplying each component of the vector by the scalar. This has the effect of stretching or shrinking the vector and possibly changing the vector's direction if the scalar is negative.\r\n\r\n\\begin{figure}[h]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.5]{Images/backgroundReview/ScalarMultiples}\r\n\\end{figure}\r\n\r\n\\noindent\r\nA unit vector is any vector with magnitude 1. Rather than using an arrow like for other vectors, unit vectors are notated with a carat (\\^) over top, like $\\hat{i}$, which is read as \"i hat\".\\\\\r\nWe an transform any vector with non-zero magnitude into a unit vector by dividing the vector by its norm. This normalized vector will point in the same direction as the original vector.\\\\\r\n\r\n\\noindent\r\nIt is common in mathematics for $\\hat{i} = \\langle 1,0,0 \\rangle$ to be the unit vector in the x-direction, $\\hat{j} = \\langle 0,1,0 \\rangle$ to be the unit vector in the y-direction, and $\\hat{k} = \\langle 0,0,1 \\rangle$ to be the unit vector in the z-direction.\\\\\r\nTogether, $\\hat{i}$, $\\hat{j}$, and $\\hat{k}$ are called the standard basis vectors because all other vectors can be written as linear combination of these.\r\n\r\n\\begin{figure}[h]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.33]{Images/backgroundReview/UnitVectors}\r\n\\end{figure}\r\n\r\n\\input{./backgroundReview/dotProducts}\r\n\\input{./backgroundReview/crossProducts}\r\n\r\n\\noindent\r\nNow that we have defined the dot product and cross product, we can put the two together as the scalar triple product, which gives the volume of the parallelepiped spanned by $\\vec{a}$, $\\vec{b}$, and $\\vec{c}$.\\\\\r\n\\begin{equation*}\r\n\t\\vec{a}\\cdot\\left(\\vec{b}\\times\\vec{c}\\right) = \\det\\begin{bmatrix}\r\n\t\ta_1 & a_2 & a_2 \\\\\r\n\t\tb_1 & b_2 & b_3 \\\\\r\n\t\tc_1 & c_2 & c_3\r\n\t\\end{bmatrix}\r\n\\end{equation*}\r\n\r\n\\begin{figure}[h]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.33]{Images/backgroundReview/Parallelipiped}\r\n\\end{figure}\r\n", "meta": {"hexsha": "1f32eccf49649476145755e3f88d52111019cd9b", "size": 3940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/backgroundReview/vectors.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/backgroundReview/vectors.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/backgroundReview/vectors.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.2432432432, "max_line_length": 276, "alphanum_fraction": 0.7157360406, "num_tokens": 1157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107861416413, "lm_q2_score": 0.8723473680407889, "lm_q1q2_score": 0.8175733625900995}}
{"text": "\\chapter{Introduction}\n\n\\textbf{TODO: 1.15, 1.16, 1.20, 1.26, 1.27 + CALCULUS OF VARIATIONS: 1.25, 1.34}\n\n\\section*{Exercise 1.1 $\\star$}\nConsider the sum-of-squares error function given by (1.2) in \nwhich the function $y(x, \\mathbf{w})$ is given by the polynomial\n(1.1). Show that the coefficients $\\mathbf{w} = \\{ w_i \\}$ that minimize\nthis error function are given by the solution to the following\nset of linear equations\n\\begin{equation}\\label{eq:1.122}\\tag{1.122}\n    \\sum_{j=0}^{M} A_{ij}w_j = T_i\n\\end{equation}\nwhere \n\\begin{equation}\\label{eq:1.123}\\tag{1.123}\n    A_{ij} = \\sum_{n=1}^{N} (x_n)^{i + j}, \\hspace{5em} T_i = \\sum_{n=1}^{N} (x_n)^it_n.\n\\end{equation}\nHere a suffix $i$ or $j$ denotes the index of a component, whereas\n$(x)^i$ denotes $x$ raised to the power of $i$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The function $y(x, \\mathbf{w})$ is given by\n    \\begin{equation*}\\label{eq:1.1}\\tag{1.1}\n        y(x, \\mathbf{w}) = \\sum_{j = 0}^M w_j x^j\n    \\end{equation*}\n    and the error function is given by\n    \\begin{equation*}\\label{eq:1.2}\\tag{1.2}\n        E(\\mathbf{w}) = \\frac{1}{2} \\sum_{n = 1}^N \\{y(x_n, \\mathbf{w}) - t_n\\}^2\n    \\end{equation*}\n\n    Since we want to find the coefficients $\\mathbf{w}$ for which\n    the error function is minimized, we compute its derivative with\n    respect to $\\mathbf{w}$:\n    \\begin{align*}\n        \\dv{\\mathbf{w}} E(\\mathbf{w}) \n        =& \\dv{\\mathbf{w}} \\bigg(\\frac{1}{2} \\sum_{n = 1}^N \\{y(x_n, \\mathbf{w}) - t_n\\}^2\\bigg)\n        = \\frac{1}{2} \\sum_{n = 1}^{N} \\dv{\\mathbf{w}} \\{y(x_n, \\mathbf{w})^2 - 2t_ny(x_n, \\mathbf{w}) + t_n^2\\} \\\\\n        =& \\sum_{n = 1}^N y(x_n, \\mathbf{w}) \\dv{\\mathbf{w}} y(x_n, \\mathbf{w})\n            - \\sum_{n = 1}^N t_n \\dv{\\mathbf{w}} y(x_n, \\mathbf{w}) \\label{eq:1.1.1}\\tag{1.1.1}\n    \\end{align*}\n\n    We continue by computing the derivative of $y(x_n, \\mathbf{w})$ separately and obtain that:\n    \\begin{equation}\\label{eq:1.1.2}\\tag{1.1.2}\n        \\dv{\\mathbf{w}} y(x_n, \\mathbf{w}) \n        = \\begin{bmatrix}\n            x_n^1 \\\\\n            \\vdots \\\\\n            x_n^M\n        \\end{bmatrix}\n    \\end{equation}\n\n    By substituting the result of ($\\ref{eq:1.1.2}$) into ($\\ref{eq:1.1.1}$) we get that:\n    \\begin{equation}\\label{eq:1.1.3}\\tag{1.1.3}\n        \\dv{\\mathbf{w}} E(\\mathbf{w}) = B - T\n    \\end{equation}\n    where $T$ is given by (\\ref{eq:1.123}) and\n    \\[\n        B_i = \\sum_{n = 1}^{N} x_n^i y(x_n, \\mathbf{w})  \n    \\] \n\n    Now, we easily find that\n    \\[\n        B_i = \\sum_{n = 1}^{N} \\bigg(x_n^i \\sum_{j = 0}^M w_j x_n^j\\bigg)\n        = \\sum_{n = 1}^{N} \\sum_{j = 0}^M x_n^{i + j} w_j\n        = A_i \\mathbf{w}\n    \\] \n    where $A$ is given by ($\\ref{eq:1.123}$). Now, the critical point of $E(\\mathbf{w})$ \n    is given by the equation:\n    \\[\n        A_i \\mathbf{w} = T_i\n    \\] \n    which is equivalent with $(\\ref{eq:1.122})$.\n\\end{proof}\n\n\\section*{Exercise 1.2 $\\star$}\nWrite down the set of coupled linear equations, analogous to (\\ref{eq:1.122}), satisfied\nby the coefficients $w_i$ which minimize the regularized sum-of-squares error\nfunction given by ($\\ref{eq:1.4}$).\n    \n\\vspace{1em}\n\n\\begin{proof}\n    The regularized sum-of-squares error function is given by\n    \\begin{equation}\\label{eq:1.4}\\tag{1.4}\n        \\widetilde{E}(\\mathbf{w}) = \\frac{1}{2} \\sum_{i = 1}^N \n            \\{y(x_n, \\mathbf{w}) - t_n\\}^2 + \\frac{\\lambda}{2} ||\\mathbf{w}||^2\n    \\end{equation}\n\n    We'll have a similar approach to the previous exercise, i.e. we compute\n    the derivative of the regularized error function and find the associated\n    critical point. We notice that\n    \\[\n        \\widetilde{E}(\\mathbf{w}) = E(\\mathbf{w}) + \\frac{\\lambda}{2} ||\\mathbf{w}||^2\n    \\] \n    so\n    \\[\n        \\dv{\\mathbf{w}} \\widetilde{E}(\\mathbf{w}) \n        = \\dv{\\mathbf{w}} E(\\mathbf{w}) + \\frac{\\lambda}{2} \\cdot \\dv{\\mathbf{w}} ||\\mathbf{w}||^2\n    \\] \n\n    One could easily prove that\n    \\[\n        \\dv{\\mathbf{w}} ||\\mathbf{w}||^2 = 2\\mathbf{w}\n    \\] \n    so by using this and $(\\ref{eq:1.1.3})$ (where we substitute $B = A\\mathbf{w}$), we\n    have that:\n    \\[\n        \\dv{\\mathbf{w}} \\widetilde{E}(\\mathbf{w}) \n        = A\\mathbf{w} + \\lambda \\mathbf{w} - T\n        = (A + \\lambda I)\\mathbf{w} - T\n    \\] \n\n    We obtain the critical point when the derivative is 0, so when\n    \\[\n        (A + \\lambda I) \\mathbf{w} = T\n    \\] \n    which is equivalent with the system of linear equations\n    \\[\n        \\sum_{j=0}^{M} C_{ij} w_j = T_i\n    \\] \n    where \n    \\[\n        C_{ij} = A_{ij} + \\lambda I_{ij} \\hspace{2em}\n    \\] \n\\end{proof}\n\n\\section*{Exercise 1.3 $\\star \\star$}\nSuppose that we have three coloured boxes $r$ (red), $b$ (blue), and $g$ (green). Box\n$r$ contains 3 apples, 4 oranges and 3 limes, box $b$ contains 1 apple, 1 orange, and 0\nlimes, and box $g$ contains 3 apples, 3 oranges, and 4 limes. If a box is chosen\nat random with probabilities $p(r) = 0.2$, $p(b) = 0.2$, $p(g) = 0.6$, and a picee \nof fruit is removed from the box (with equal probability of selecting any of the items\nin the box), then what is the probability of selecting an apple? If we observe\nthat the selected fruit is in fact an orange, what is the probability that it came from\nthe green box?\n\n\\vspace{1em}\n\n\\begin{proof}\n    The conditional probabilities of obtaining a fruit knowing that we are \n    searching in a certain box are easily found since the fruits are equally\n    likely to be extracted. We also now the probabilities of choosing a specific box,\n    so we can simply apply the sum rule to obtain the probability of getting an apple:\n    \\[\n        p(\\text{apple}) \n        = p(\\text{apple} | r)p(r) + p(\\text{apple} | b)p(b) + p(\\text{apple} | g)p(g) \n        = \\frac{3}{10} \\cdot 0.2 + \\frac{1}{2} \\cdot 0.2 + \\frac{3}{10} \\cdot 0.6\n        = 34\\%\n    \\] \n\n    If we know the selected fruit is an orange, the probability that it came from\n    the green box is given by the Bayes' theorem:\n\n    \\begin{equation*}\\label{eq:1.3.1}\\tag{1.3.1}\n        p(g | \\text{orange}) = \\frac{p(g)p(\\text{orange} | g)}{p(\\text{orange})}\n    \\end{equation*}\n\n    The probability of choosing the green box is known and the probability of getting\n    an orange from the green box is also easily found. We only need to find the probability\n    of extracting an orange in the general case:\n    \\[\n        p(\\text{orange}) \n        = p(\\text{orange} | r)p(r) + p(\\text{orange} | b)p(b) + p(\\text{orange} | g)p(g) \n        = \\frac{4}{10} \\cdot 0.2 + \\frac{1}{2} \\cdot 0.2 + \\frac{3}{10} \\cdot 0.6\n        = 36\\%\n    \\]\n\n    The needed probability is now found by substituting the values in $(\\ref{eq:1.3.1})$:\n    \\[\n        p(g | \\text{orange}) = \\frac{0.6 \\cdot \\frac{3}{10}}{\\frac{36}{100}} = \\frac{1}{2} = 50\\%\n    \\] \n\\end{proof}\n\n\\section*{Exercise 1.4 $\\star \\star$}\nConsider a probability density $p_x(x)$ defined over a continuous variable\n$x$, and suppose that we make a nonlinear change of variable using $x = g(y)$,\nso that the density transforms according to (1.27). By differentiating (1.27),\nshow that the location  $\\widehat{y}$ of the maximum of the density in\n$y$ is not in general related to the location $\\widehat{x}$ of the maximum of the\ndensity over $x$ by the simple functional relation $\\widehat{x} = g(\\widehat{y})$ \nas a consequence of the Jacobian factor. This shows that the maximum of a probability\ndensity (in contrast to a simple function) is dependent of the choice of variable.\nVerify that, in the case of a linear transformation, the location of the maximum\ntransforms in the same way as the variable itself.\n\n\\vspace{1em}\n\n\\begin{proof}\n    If we make a nonlinear change of variable $x = g(y)$ in the probbability density \n    $p_x(x)$, it transforms according to\n    \\begin{equation}\\label{eq:1.27}\\tag{1.27}\n        p_y(y) = p_x(g(y)) |g'(y)|\n    \\end{equation}\n\n    We assume that the mode of $p_x(x)$ is given by an unique $\\widehat{x}$, i.e.\n     \\[\n         p_x'(x) = 0 \\iff x = \\widehat{x}\n    \\] \n\n    Now, let $s \\in \\{-1, 1\\}$ such that $g'(y) = sg'(y)$. \n    The derivative of  $(\\ref{eq:1.27})$ with respect to $y$ is given by:\n    \\[\n        p_y'(y) = sp'x(g(y))\\{g'(y)\\}^2 + sp_x(g(y))g''(y)\n    \\] \n\n    For a linear change of variable, we have that $g''(y) = 0$, so the mode of $p_y(y)$ \n    is given by $g'(y) = 0$ and since $x = g(y)$, respectively $x' = g'(y)$ we have that\n    $\\widehat{x} = g(\\widehat{y})$. Therefore, for a linear change of variable, the location\n    of the maximum transforms in the same way as the variable itself.\n\n    For a nonlinear change of variable, the second derivative will not be generally 0, so\n    the mode is not given by $g'(y) = 0$ anymore. As a result, in general $\\widehat{x} \\neq g(\\widehat{y})$,\n    so the location of the mode will transform differently from the variable itself.\n\\end{proof}\n\n\\section*{Exercise 1.5 $\\star$}\nUsing the definition ($\\ref{eq:1.38}$) show that var$[f(x)]$ satisfies ($\\ref{eq:1.39}$).\n\n\\vspace{1em}\n\n\\begin{proof}\n    The variance is defined by \n    \\begin{equation}\\label{eq:1.38}\\tag{1.38}\n        \\text{var}[f] = \\mathbb{E}\\big[(f(x) - \\mathbb{E}[f(x)])^2\\big]\n    \\end{equation}\n\n    We expand the square and then use the linearity of expectation to obtain:\n    \\[\n        \\text{var}[f] \n        = \\mathbb{E}\\big[f(x)^2 - 2f(x)\\mathbb{E}[f(x)] + \\mathbb{E}[f(x)]^2\\big]\n        = \\mathbb{E}[f(x)^2] - 2\\mathbb{E}\\big[f(x)\\mathbb{E}[f(x)]\\big] + \\mathbb{E}\\big[\\mathbb{E}[f(x)]^2\\big]\n    \\] \n\n    Since $\\mathbb{E}[f(x)]$ is a constant, the expression of the variance becomes:\n    \\begin{equation}\\label{eq:1.39}\\tag{1.39}\n        \\text{var}[f] \n        = \\mathbb{E}[f(x)^2] - 2\\mathbb{E}[f(x)]^2 + \\mathbb{E}[f(x)]^2\n        = \\mathbb{E}[f(x)^2] - \\mathbb{E}[f(x)]^2\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 1.6 $\\star$}\nShow that if two variables $x$ and $y$ are independent, then their covariance is zero.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The covariance of two random variables is given by:\n    \\begin{equation}\\label{eq:1.41}\\tag{1.41}\n        \\text{cov}[x, y] = \\mathbb{E}_{x, y} [xy] - E[x]E[y]\n    \\end{equation}\n\n    We assume that the variables are continuous, but the discrete case result is similarly obtained.\n    If $x$ and $y$ are independent, we have that $p(x, y) = p(x)p(y)$, so\n     \\[\n         E_{x, y}[xy] = \\iint p(x, y) xy \\hspace{0.25em} \\diff x \\diff y \n         = \\iint p(x) p(y) xy \\hspace{0.25em} \\diff x \\diff y\n         = \\bigg(\\int p(x) x \\hspace{0.25em} \\diff x\\bigg) \\bigg(\\int p(y) y \\hspace{0.25em} \\diff y\\bigg)\n         = E[x]E[y]\n    \\] \n    and ($\\ref{eq:1.41}$) becomes 0.\n\\end{proof}\n\n\\section*{Exercise 1.7 $\\star \\star$}\nIn this exercise, we prove the normalization condition (1.48) for the univariate\nGaussian. To do this consider the integral\n\\begin{equation}\\label{eq:1.124}\\tag{1.124}\n    I = \\int_{-\\infty}^{\\infty} \\exp\\bigg(-\\frac{1}{2\\sigma^2}x^2\\bigg) \\hspace{0.25em} \\diff x\n\\end{equation}\nwhich we can evaluate by first writing its square in the form\n\\begin{equation}\\label{eq:1.125}\\tag{1.125}\n    I^2 = \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} \\exp \n        \\bigg(-\\frac{1}{2\\sigma^2}x^2 - \\frac{1}{2\\sigma^2}y^2\\bigg) \\hspace{0.25em} \\diff x\\diff y\n\\end{equation}\n\nNow make the transformation from Cartesian coordinates $(x, y)$ to polar coordinates $(r, \\theta)$ \nand then substitute $u = r^2$. Show that, by performing the integrals over $\\theta$ and $u$,\nand then taking the square root of both sides, we obtain\n\\begin{equation}\\label{eq:1.126}\\tag{1.126}\n    I = (2\\pi\\sigma^2)^{1/2}\n\\end{equation}\n\nFinally, use this result to show that the Gaussian distribution $\\mathcal{N}(x | \\mu, \\sigma^2)$ is \nnormalized.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We transform $(\\ref{eq:1.125})$ from Cartesian coordinates to polar coordinates and obtain:\n\\[\n    I^2 = \\int_{0}^{2\\pi} \\int_0^\\infty \\exp \n        \\bigg(-\\frac{r^2\\sin^2 \\theta + r^2\\cos^2 \\theta}{2\\sigma^2}\\bigg) r\\diff r\\diff \\theta\n        = \\int_{0}^{2\\pi} \\int_{0}^{\\infty} \\exp \\bigg(-\\frac{r^2}{2\\sigma^2}\\bigg) r\\diff r\\diff \\theta\n    \\] \n\n    We use the substitution $u = r^2$ and then compute the integral to get:\n    \\[\n        I^2 = \\frac{1}{2} \\int_{0}^{2\\pi} \\int_{0}^{\\infty} \\exp\\bigg(-\\frac{u}{2\\sigma^2}\\bigg) du\\diff \\theta\n        = \\frac{1}{2} \\int_0^{2\\pi} -2\\sigma^2 \\exp\\bigg(-\\frac{u}{2\\sigma^2}\\bigg)\\bigg|_0^\\infty \\diff \\theta\n        = \\sigma^2 \\int_{0}^{2\\pi} \\diff \\theta = 2\\pi\\sigma^2\n    \\] \n\n    If we take the square root of this we see that\n    \\begin{equation}\\tag{1.126}\n        I = (2\\pi\\sigma^2)^{1/2}\n    \\end{equation}\n\n    We can assume without loss of generality that the mean of the Gaussian is 0,\n    as we could make the change of variable $y = x - \\mu$. Therefore, by using\n    $(\\ref{eq:1.126})$ we obtain\n    \\[\n        \\mathcal{N}(x | \\mu, \\sigma^2) \n        = \\frac{1}{\\sqrt{2\\pi\\sigma^2}} \\int_{-\\infty}^{\\infty} \\exp\\bigg(-\\frac{x}{2\\sigma^2}\\bigg) \\diff x\n        = \\frac{I}{\\sqrt{2\\pi\\sigma^2}} = 1\n    \\] \n    which shows that the Gaussian distribution is normailized.\n\\end{proof}\n\n\\section*{Exercise 1.8 $\\star \\star$}\nBy using a change of variables, verify that the univariate Gaussian\ngiven by (1.46) satisfies ($\\ref{eq:1.49}$). Next, by differentiating both sides\nof the normalization condition\n\\begin{equation*}\\label{eq:1.127}\\tag{1.127}\n    \\int_{-\\infty}^{\\infty} \\mathcal{N} (x | \\mu, \\sigma^2) \\diff x = 1\n\\end{equation*}\nwith respect to $\\sigma^2$, verify that the Gaussian satisfies (1.50). Finally,\nshow that (1.51) holds.\n\n\\vspace{1em}\n\\begin{proof}\n    We start by computing the expected value of the Gaussian:\n    \\[\n        \\mathbb{E}[x] = \\int_{-\\infty}^{\\infty} \\mathcal{N}(x | \\mu, \\sigma^2) x \\diff x\n        = \\frac{1}{\\sqrt{2\\pi\\sigma^2}} \\int_{-\\infty}^{\\infty} \n            \\exp \\bigg\\{-\\frac{(x - \\mu)^2}{2\\sigma^2}\\bigg\\} x \\diff x\n    \\] \n\n    We do a little trick to prepare for the substitution $u = (x - \\mu)^2$:\n    \\[\n        \\mathbb{E}[x] = \\frac{1}{\\sqrt{2\\pi\\sigma^2}} \\int_{-\\infty}^{\\infty} \n        \\exp\\bigg\\{-\\frac{(x - \\mu)^2}{2\\sigma^2}\\bigg\\} (x - \\mu) \\diff x \n        + \\frac{\\mu}{\\sqrt{2\\pi\\sigma^2}} \\int_{-\\infty}^{\\infty} \\exp\\bigg\\{-\\frac{(x - \\mu)^2}{2\\sigma^2}\\bigg\\} \\diff x\n    \\] \n\n    Since the Gaussian is normalized, the second term of the expression will be $\\mu$.\n    By using the substitution $u = (x - \\mu)^2$, the expected value becomes:\n    \\[\n        \\mathbb{E}[x] \n        = \\frac{1}{2\\sqrt{2\\pi\\sigma^2}} \\int_{\\infty}^{\\infty} \\exp\\bigg(-\\frac{u}{2\\sigma^2}\\bigg) \\diff u + \\mu\n    \\] \n\n    We notice that the endpoints of the integral are \"equal\" (one could rewrite it as a\n    limit of an integral with actual equal endpoints), so its value is 0. Therefore,\n    \\begin{equation}\\label{eq:1.49}\\tag{1.49}\n        \\mathbb{E}[x] = \\mu\n    \\end{equation}\n\n    Now, we take the derivative of ($\\ref{eq:1.127}$) with respect to $\\sigma^2$ and obtain:\n    \\begin{align*}\n        \\pdv{\\sigma^2} \\bigg(\\frac{1}{\\sqrt{2\\pi \\sigma^2}} \n        \\int_{-\\infty}^{\\infty} \\exp \\bigg\\{-\\frac{(x - \\mu)^2}{2\\sigma^2}\\bigg\\} \\diff x\\bigg) &= 0 \\\\\n        -\\frac{I}{2\\sigma^3\\sqrt{2\\pi}} + \n        \\frac{1}{\\sqrt{2\\pi\\sigma^2}} \\int_{-\\infty}^{\\infty} \\pdv{\\sigma^2} \n        \\exp \\bigg\\{-\\frac{(x - \\mu)^2}{2\\sigma^2}\\bigg\\} \\diff x &= 0 \\\\\n        -\\frac{1}{2\\sigma^2} + \n        \\frac{1}{\\sqrt{2\\pi\\sigma^2}} \\int_{-\\infty}^{\\infty}\n        \\frac{(x - \\mu)^2}{2\\sigma^4} \\exp\\bigg\\{-\\frac{(x + \\mu)^2}{2\\sigma^2}\\bigg\\} \\diff x &= 0\n    \\end{align*}\n\n    We let $J$ be the integral term and compute it separately:\n    \\begin{align*}\n        J &= \\frac{1}{2\\sigma^4} \\int_{-\\infty}^{\\infty} (x - \\mu)^2 \\exp \\bigg\\{-\\frac{(x + \\mu)^2}{2\\sigma^2}\\bigg\\} \\diff x \\\\\n          &= \\frac{1}{2\\sigma^4} \\int_{-\\infty}^{\\infty} x^2 \n            \\exp \\bigg\\{-\\frac{(x+\\mu)^2}{2\\sigma^2}\\bigg\\} \\diff x\n        - \\frac{2\\mu}{2\\sigma^4} \\int_{-\\infty}^{\\infty} x \n            \\exp \\bigg\\{-\\frac{(x+\\mu)^2}{2\\sigma^2}\\bigg\\} \\diff x\n        + \\frac{\\mu^2}{2\\sigma^4} I\n    \\end{align*}\n\n    If we multiply by the normalization constants, the integrals become expected values and the\n    $I$ factor vanishes. Therefore:\n    \\[\n        J = \\sqrt{2\\pi \\sigma^2} \\bigg(\\frac{1}{2\\sigma^4} \\mathbb{E}[x^2] - \\frac{2\\mu}{2\\sigma^4} \\mathbb{E}[x] + \\frac{\\mu^2}{2\\sigma^4}\\bigg)\n    \\] \n\n    We substitute $J$ back in the initial expression to obtain:\n    \\[\n        -\\frac{1}{2\\sigma^2} + \\frac{1}{2\\sigma^4}(\\mathbb{E}[x^2] - 2\\mu^2 + \\mu^2) = 0\n    \\] \n    from which is straightforard to show that \n    \\begin{equation}\\label{eq:1.50}\\tag{1.50}\n        E[x^2] = \\sigma^2 + \\mu^2\n    \\end{equation}\n\n    Finally, one can easily see that:\n    \\begin{equation}\\label{eq:1.51}\\tag{1.51}\n        \\text{var}[x] = E[x^2] - E[x]^2 = \\sigma^2\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 1.9 $\\star$}\nShow that the mode (i.e. the maximum) of the Gaussian distribution (1.46) is\ngiven by $\\mu$. Similarly, show that the mode of the multivariate Gaussian\n(1.52) is given by $\\bm{\\mu}$. \n\n\\vspace{1em}\n\n\\begin{proof}\n    In the univariate case, we start by taking the derivative of (1.46) with\n    respect to $x$ :\n    \\[\n        \\pdv{x} \\mathcal{N} (x | \\mu, \\sigma^2)\n        = \\frac{1}{\\sqrt{2\\pi \\sigma^2}} \\bigg(\\pdv{x} \\exp \\bigg\\{-\\frac{(x - \\mu)^2}{2\\sigma^2}\\bigg\\}\\bigg)\n        = \\frac{1}{\\sqrt{2\\pi \\sigma^2}} \\frac{(x - \\mu)^2}{2\\sigma^4} \\exp \\bigg\\{-\\frac{(x - \\mu)^2}{2\\sigma^2}\\bigg\\}\n    \\] \n\n    We notice that the derivative is 0, for $x = \\mu$, so the mode of the univariate Gaussian is \n    given by the mean. \n\n    \\vspace{1em}\n\n    Analogously, we take the derivative of (1.52) with respect to $\\mathbf{x}$ and get:\n    \\[\n        \\pdv{\\mathbf{x}} \\mathcal{N} (\\mathbf{x} | \\bm{\\mu}, \\mathbf{\\Sigma})\n        = \\frac{1}{(2\\pi)^{D/2}} \\frac{1}{|\\mathbf{\\Sigma}|^{1/2}}\n        \\bigg(\\pdv{\\mathbf{x}} \\exp \\bigg\\{-\\frac{1}{2} \n            (\\mathbf{x} - \\bm{\\mu})^T \\mathbf{\\Sigma}^{-1} (\\mathbf{x} - \\bm{\\mu})\\bigg\\}\\bigg)\n    \\] \n\n    The covariance matrix $\\mathbf{\\Sigma}$ is both nonsingular and symmetric, so one\n    can easily show that $\\mathbf{\\Sigma}^{-1}$ \n    will be symmetric too. Therefore, we have that (see matrix cookbook):\n    \\[\n        \\pdv{\\mathbf{x}} (\\mathbf{x} - \\bm{\\mu})^T \\mathbf{\\Sigma}^{-1}(\\mathbf{x} - \\bm{\\mu})\n        = 2\\mathbf{\\Sigma}^{-1}(\\mathbf{x} - \\bm{\\mu})\n    \\] \n\n    As a result, our derivative becomes\n    \\[\n        \\pdv{\\mathbf{x}} \\mathcal{N} (\\mathbf{x} | \\bm{\\mu}, \\mathbf{\\Sigma})\n        = -\\frac{1}{(2\\pi)^{D/2}} \\frac{1}{|\\mathbf{\\Sigma}|^{1/2}}\n        \\exp \\bigg\\{-\\frac{1}{2} \n            (\\mathbf{x} - \\bm{\\mu})^T \\mathbf{\\Sigma}^{-1} (\\mathbf{x} - \\bm{\\mu})\\bigg\\}\n            \\mathbf{\\Sigma}^{-1}(\\mathbf{x} - \\bm{\\mu})\n    \\]\n    and is 0 for $\\mathbf{x} = \\bm{\\mu}$, so like in the case of the univariate distribution,\n    the mode of the multivariate distribution is given by the mean $\\bm{\\mu}$.\n\\end{proof}\n\n\\section*{Exercise 1.10 $\\star$}\nSuppose that the two variables $x$ and $z$ are statistically independent. Show that\nthe mean and variance of their sum satisfies\n\\begin{equation}\\label{eq:1.128}\\tag{1.128}\n    \\mathbb{E}[x + z] = \\mathbb{E}[x] + \\mathbb{E}[z]\n\\end{equation}\n\\vspace{-1em}\n\\begin{equation}\\label{eq:1.129}\\tag{1.129}\n    \\text{var}[x + z] = \\text{var}[x] + \\text{var}[z]\n\\end{equation}\n\n\\vspace{1em}\n\n\\begin{proof}\n    Since the variables are independent, we have that $p(x, z) = p(x)p(z)$. Therefore,\n    by using this, the expression of the expected value and the fact that the distributions\n    are normalized, we have that\n    \\begin{align*}\n         \\mathbb{E}[x + z] \n        &= \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} p(x, z) (x + z) \\diff x \\diff z \\\\\n        &= \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} p(x)p(z) x + p(x)p(z)z \\diff x \\diff z \\\\\n        &= \\int_{-\\infty}^{\\infty} p(z) \\bigg(\\int_{-\\infty}^{\\infty} p(x) x \\diff x\\bigg) + p(z) z \\bigg(\\int_{-\\infty}^{\\infty} p(x) \\diff x\\bigg) \\diff z \\\\\n        &= \\int_{-\\infty}^{\\infty} p(z) \\mathbb{E}[x] + p(z)z \\diff z \\\\\n        &= \\mathbb{E}[x] \\int_{-\\infty}^{\\infty} p(z) \\diff z + \\int_{-\\infty}^{\\infty} p(z) z \\diff z \\\\\n        &= \\mathbb{E}[x] + \\mathbb{E}[z] \\tag{\\ref{eq:1.128}}\n    \\end{align*}\n\n    Analogously, we can solve the discrete case. Now, by using all the available tools,\n    i.e. $(\\ref{eq:1.39})$ and $(\\ref{eq:1.128})$, the linearity of the expectation\n    and the independence of variables, we have that the variance of the sum is given by:\n    \\begin{align*}\n        \\text{var}[x + z] \n        &= \\mathbb{E}[(x + z)^2] - \\mathbb{E}[x + z]^2\n        = \\mathbb{E}[x^2 + 2xz + z^2] - (\\mathbb{E}[x] + \\mathbb{E}[z])^2 \\\\\n        &= \\mathbb{E}[x^2] + 2\\mathbb{E}[x]\\mathbb{E}[z] + \\mathbb{E}[z^2] - \\mathbb{E}[x]^2 \n        - \\mathbb{E}[x^2 + 2xz + z^2] - E[z]^2 \\\\\n        &= E[x^2] - E[x]^2 + E[z^2] - E[z]^2 \\\\\n        &= \\text{var}[x] + \\text{var}[z] \\tag{\\ref{eq:1.129}}\n    \\end{align*}\n\\end{proof}\n\n\\section*{Exercise 1.11 $\\star$}\nBy setting the derivatives of the log likelihood function ($\\ref{eq:1.54}$) with respect to $\\mu$\nand $\\sigma^2$ equal to zero, verify the results $(\\ref{eq:1.55})$ and ($\\ref{eq:1.56}$).\n\n\\vspace{1em}\n\n\\begin{proof}\n    The log likelihood of the Gaussian is given by:\n    \\begin{equation}\\label{eq:1.54}\\tag{1.54}\n        \\ln p(\\mathbf{x} | \\mu, \\sigma^2) = -\\frac{1}{2\\sigma^2} \\sum_{n = 1}^{N} (x_n - \\mu)^2 \n        -\\frac{N}{2}\\ln\\sigma^2 - \\frac{N}{2} \\ln(2\\pi)\n    \\end{equation}\n\n    By taking the derivative of $(\\ref{eq:1.54})$ with respect to $\\mu$ we\n    get that:\n    \\begin{align*}\n        \\pdv{\\mu} \\ln p(\\mathbf{x} | \\mu, \\sigma^2) \n        &= -\\frac{1}{2\\sigma^2} \n            \\bigg\\{\\pdv{\\mu} \\sum_{n = 1}^{N} (x_n - \\mu)^2\\bigg\\}\n        = -\\frac{1}{2\\sigma^2} \n            \\bigg\\{\\pdv{\\mu} \\bigg(\\sum_{n=1}^{N} x_n^2 - 2\\sum_{n=1}^{N} x_n \\mu + N\\mu^2\\bigg)\\bigg\\} \\\\\n        &= \\frac{1}{\\sigma^2} \\bigg(\\sum_{n=1}^{N} x_n - N\\mu \\bigg)\n    \\end{align*}\n    which is 0 for the maximum point:\n    \\begin{equation}\\label{eq:1.55}\\tag{1.55}\n        \\mu_{ML} = \\frac{1}{N} \\sum_{n = 1}^{N} x_n\n    \\end{equation}\n\n    Now, we want the variance that maximizes the log likelihood, so we take\n    the derivative of $(\\ref{eq:1.54})$ (by using $\\mu_{ML}$) with respect to $\\sigma^2$:\n    \\[\n        \\pdv{\\sigma^2} \\ln p(\\mathbf{x} | \\mu_{ML}, \\sigma^2) \n        = \\frac{1}{2\\sigma^4} \\sum_{n=1}^{N} (x_n - \\mu_{ML})^2 - \\frac{N}{2\\sigma^2}\n        = \\frac{1}{2\\sigma^4}\\bigg(\\sum_{n=1}^{N} (x_n - \\mu_{ML})^2 - N\\sigma^2\\bigg)\n    \\] \n\n    The derivative is 0 for the maximum point\n    \\begin{equation}\\label{eq:1.56}\\tag{1.56}\n        \\sigma^2_{ML} = \\frac{1}{N}\\sum_{n = 1}^{N} (x_n - \\mu_{ML})^2\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 1.12 $\\star \\star$}\nUsing the results $(\\ref{eq:1.49})$ and $(\\ref{eq:1.50})$, show that\n\\begin{equation}\\label{eq:1.130}\\tag{1.130}\n    \\mathbb{E}[x_nx_m] = \\mu^2 + I_{nm}\\sigma^2\n\\end{equation}\nwhere $x_n$ and $x_m$ denote data points sampled from a Gaussian distribution\nwith mean $\\mu$ and variance $\\sigma^2$, and $I_{nm}$ satisfies $I_{nm} = 1$ \nif $n = m$ and $I_{nm} = 0$ otherwise. Hence prove the results ($\\ref{eq:1.57}$)\nand  $(\\ref{eq:1.58})$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We assume that the data points are i.i.d, so we have that the variables\n    $x_n$ and $x_m$ are not independent for $n \\neq m$ and independent for $n = m$.\n    Therefore,  \n    \\[\n        \\mathbb{E}[x_nx_m] = \n        \\begin{cases}\n            \\mu^2 & n \\neq m \\\\\n            \\mu^2 + \\sigma^2 & n = m \\\\\n\n        \\end{cases}\n    \\] \n    which is equivalent with ($\\ref{eq:1.130})$.\n    Now, the expectation of $\\mu_{ML}$ is given by:\n    \\begin{equation}\\label{eq:1.57}\\tag{1.57}\n         \\mathbb{E}[\\mu_{ML}] \n         = \\mathbb{E} \\bigg[\\frac{1}{N} \\sum_{n=1}^{N} x_n\\bigg]\n         = \\frac{1}{N} \\sum_{n=1}^{N} \\mathbb{E}[x_n] = \\mu\n    \\end{equation}\n\n    Similarly, the expectation of $\\sigma_{ML}^2$ is given by: \n    \\begin{align*}\n        \\mathbb{E}[\\sigma_{ML}^2] \n        &= \\mathbb{E}\\bigg[\\frac{1}{N} \\sum_{n=1}^{N} (x_n - \\mu_{ML})^2\\bigg]\n        = \\frac{1}{N} \\sum_{n=1}^{N} \\mathbb{E} [x_n^2 - 2x_n\\mu_{ML} + \\mu_{ML}^2] \\\\\n        &= \\frac{1}{N} \\sum_{n=1}^{N} (\\mu^2 + \\sigma^2 - 2\\mathbb{E}[x_n\\mu_{ML}] + \\mathbb{E}[\\mu_{ML}^2])\n    \\end{align*}\n\n    We compute each expectation separately and get:\n    \\[\n    E[\\mu_{ML}^2]\n    = \\frac{1}{N^2} \\mathbb{E} \\bigg[\\sum_{n=1}^{N} x_n^2 + 2\\sum_{i=1}^{N-1} \\sum_{j=i+1}^{N} x_ix_j\\bigg]\n    = \\frac{1}{N^2} \\sum_{n=1}^{N} \\mathbb{E}[x_n^2] + \n        \\frac{2}{N^2} \\sum_{i=1}^{N-1} \\sum_{j = i+1}^{N} \\mathbb{E}[x_ix_j]\n    = \\frac{\\sigma^2}{N} + \\mu^2\n    \\] \n    \\[\n        E[x_n\\mu_{ML}] = \\frac{1}{N} \\mathbb{E}\\bigg[x_n \\sum_{i=1}^{N} x_i\\bigg]\n        = \\frac{1}{N} (\\sigma^2 + N\\mu^2) = \\frac{\\sigma^2}{N} + \\mu^2\n    \\]\n\n    By putting everything together, we obtain\n    \\begin{equation}\\label{eq:1.58}\\tag{1.58}\n        \\mathbb{E}[\\sigma_{ML}^2] = \\bigg(\\frac{N - 1}{N}\\bigg) \\sigma^2\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 1.13 $\\star$}\nSuppose that the variance of a Gaussian is estimated using the result ($\\ref{eq:1.56}$) but\nwith the maximum likelihood estimate $\\mu_{ML}$ replaced with the true value $\\mu$ of\nthe mean. Show that this estimator has the property that its expectation is given by the\ntrue variance $\\sigma^2$.\n\n\\vspace{1em}\n\n\\begin{proof}\nLet \n \\[\n     {\\sigma_{ML}^*}^2 = \\frac{1}{N} \\sum_{n=1}^{N} (x_n - \\mu)^2\n\\] \nbe the estimator described in the hypothesis. It's straightforward to show that the\nexpectation of the estimator is the actual variance:\n\\[\n    \\mathbb{E}[{\\sigma_{ML}^*}^2] = \\frac{1}{N} \\sum_{n=1}^{N} \n        \\bigg(\\mathbb{E}[x_n^2] - 2\\mathbb{E}[x_n \\mu] + \\mathbb{E}[\\mu^2]\\bigg)\n        =\\frac{1}{N} \\sum_{n=1}^{N} (\\sigma^2 + \\mu^2 - 2\\mu^2 + \\mu^2) = \\sigma^2\n\\] \n\\end{proof}\n\n\\section*{Exercise 1.14 $\\star \\star$} Show that an arbitrary square matrix with elements $w_{ij}$ can\nbe written in the form $w_{ij} = w_{ij}^S + w_{ij}^A$ where $w_{ij}^S$ and $w_{ij}^A$ are\nsymmetric and anti-symmetric matrices, respectively, satisfying $w_{ij}^S = w_{ji}^S$ and\n$w_{ij}^A = -w_{ji}^A$ for all $i$ and $j$. Now consider the second order term in a higher\norder polynomial in $D$ dimensions, given by\n\\begin{equation}\\label{eq:1.131}\\tag{1.131}\n    \\sum_{i=1}^{D} \\sum_{j=1}^{D} w_{ij}x_ix_j\n\\end{equation}\n\nShow that \n\\begin{equation}\\label{eq:1.132}\\tag{1.132}\n    \\sum_{i=1}^{D} \\sum_{j=1}^{D} w_{ij}x_ix_j = \\sum_{i=1}^{D} \\sum_{j=1}^{D} w_{ij}^S x_ix_j\n\\end{equation}\nso that the contribution from the anti-symmetric vanishes. We therefore see\nthat, without loss of generality, the matrix of coefficients $w_{ij}$ can be chosen\nto be symmetric, and so not all of the $D^2$ elements of this matrix can be chosen\nindependently. Show that the number of independent parameters in the matrix $w_{ij}^S$\nis given by  $D(D+1)/2$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    If we consider the system of equations\n    \\[\n        w_{ij} = w_{ij}^S + w_{ij}^A \n        \\hspace{3em}\n        w_{ji} = w_{ij}^S - w_{ij}^A\n    \\]\n    we quickly reach the conclusion that the solutions are given by\n    \\begin{equation}\\label{eq:1.14.1}\\tag{1.14.1}\n        w_{ij}^S = \\frac{w_{ij} + w_{ji}}{2}\n        \\hspace{3em}\n        w_{ij}^A = \\frac{w_{ij} - w_{ji}}{2}\n    \\end{equation}\n    such that for all $i$ and $j$, \n    \\[\n        w_{ij} = w_{ij}^S + w_{ij}^A \n    \\] \n\n    The coefficient matrix $w$ associated with the second order higher order polynomial \n    in $D$ dimensions is actually a $D \\times D$ $\\emph{symmetric}$ matrix. Therefore, from\n    $(\\ref{eq:1.14.1})$ we'd have that $w^S = w$ and $w_A = 0_D$, where $0_D$ is the null\n    matrix of dimension $D$, so $(\\ref{eq:1.132})$ definitely holds as the anti-symmetric\n    contribution vanishes.\n\n    We consider as independent parameters of the matrix $w$ the elements on and above the diagonal,\n    since the ones under the diagonal are reflections of the ones above. There are  \n    \\[\n        \\sum_{i=1}^{D} (D - i + 1) = D^2 + D - \\sum_{i=1}^{D} i = D^2 + D - \\frac{D(D+1)}{2} = \\frac{D(D+1)}{2}\n    \\] \n    such independent parameters\n\\end{proof}\n\n\\section*{Exercise 1.15 $\\star \\star \\star$}\nIn this exercise and the next, we explore how the number of independent\nparameters in a polynomial grows with the order $M$ of the polynomial and with\nthe dimensionality $D$ of the input space. We start by writing down the $M^{\\text{th}}$ order\nterm for a polynomial in $D$ dimensions in the form\n\\begin{equation}\\label{eq:1.133}\\tag{1.133}\n    \\sum_{i_1=1}^{D} \\sum_{i_2=1}^{D} \\ldots \\sum_{i_M=1}^{D} \n        w_{i_1,i_2,\\ldots,i_M}x_{i_1}x_{i_2} \\cdot \\ldots x_{i_M} \n\\end{equation}\n\nThe coefficients $w_{i_1, i_2, \\ldots i_M}$ compromise $D^M$ elements, but the number\nof independent parameters is significantly fewer due to the many interchange symmetries\nof the factor $x_{i_1}, x_{i_2} \\ldots x_{i_M}$. Begin by showing that the redundancy in the\ncoefficients can be removed by rewriting the $M^\\text{th}$ order term in the form\n\\begin{equation}\\label{eq:1.134}\\tag{1.134}\n    \\sum_{i_1=1}^{D} \\sum_{i_2=1}^{i_1} \\ldots \\sum_{i_M=1}^{i_{M-1}} \n        \\widetilde{w}_{i_1,i_2,\\ldots,i_M}x_{i_1}x_{i_2} \\cdot \\ldots x_{i_M} \n\\end{equation}\n\nNote that the precise relationship between the $\\widetilde{w}$ coefficients and\n $w$ coefficients need not be made explicit. Use this result to show that the number\n of $\\emph{independent}$ parameters $n(D, M)$, which appear at order $M$, satisfies\n the following recursion relation\n \\begin{equation}\\label{eq:1.135}\\tag{1.135}\n    n(D, M) = \\sum_{i=1}^{D} n(i, M - 1) \n\\end{equation}\n\nNext use proof by induction to show that the following result holds\n\\begin{equation}\\label{eq:1.136}\\tag{1.136}\n    \\sum_{i=1}^{D} \\frac{(i + M - 2)!}{(i - 1)!(M - 1)!} = \\frac{(D + M - 1)!}{(D - 1)!M!}\n\\end{equation}\nwhich can be done by first proving the result for $D = 1$ and arbitrary $M$ by\nmaking use of the result $0! = 1$, then assuming it is correct for dimension $D$ \nand verifying that it is correct for dimension $D + 1$. Finally, use the two previous\nresults, together with proof by induction, to show\n\\begin{equation}\\label{eq:1.137}\\tag{1.137}\n    n(D, M) = \\frac{(D + M - 1)!}{(D - 1)!M!}\n\\end{equation}\n\nTo do this, first show that the result is true for $M = 2$, and any value of $D \\geq 1$,\nby comparison with the result of Exercise 1.14. Then make use of ($\\ref{eq:1.135}$), together\nwith ($\\ref{eq:1.136}$), to show that, if the result holds at order $M - 1$, then it will\nalso hold at order $M$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    \n\\end{proof}\n\n\\section*{Exercise 1.17 $\\star \\star$}\nThe gamma function is defined by \n\\begin{equation}\\label{eq:1.141}\\tag{1.141}\n    \\Gamma(x) = \\int_{0}^{\\infty} u^{x - 1}e^{-u} \\diff u \n\\end{equation}\n\nUsing integration by parts, prove the relation $\\Gamma(x + 1) = x\\Gamma(x)$. Show\nalso that $\\Gamma(1) = 1$ and hence that $\\Gamma(x + 1) = x!$ when $x$ is\nan integer.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Knowing that $-u^xe^{-u} \\to 0$ as $u \\to \\infty$, \n    we integrate $\\Gamma(x + 1)$ by parts and obtain:\n     \\[\n         \\Gamma(x+1) = \\int_{0}^{\\infty} u^x (-e^{-u})' \\diff u\n         = -u^x e^{-u} \\bigg|_0^\\infty + x \\int_{0}^\\infty u^{x - 1} e^{-u} \\diff u\n         = x\\Gamma(x)\n    \\] \n\n    Computing $\\Gamma(1)$ is also easily done by integrating by parts:\n    \\[\n        \\Gamma(1) = \\int_{0}^{\\infty} ue^{-u} \\diff u\n        = \\int_{0}^{\\infty} u(-e^{-u})' \\diff u\n        = -ue^{-u}\\bigg|_0^\\infty + \\int_{0}^{\\infty} e^{-u} \\diff u \n        = 1\n    \\] \n\n    We can prove by induction that $\\Gamma(x + 1) = x!$ when $x$ \n    is an integer. This is obviously valid for $x = 0$, since $0! = 1$.\n    Now, assume that $\\Gamma(k) = (k - 1)!$, for $k \\in \\mathbb{N}$. Then,\n     \\[\n         \\Gamma(k + 1) = k\\Gamma(k) = k \\cdot (k - 1)! = k!\n    \\] \n\n    Therefore, $\\Gamma(n + 1) = n!$ for all $n \\in \\mathbb{N}$.\n\\end{proof}\n\n\\section*{Exercise 1.18 $\\star \\star$}\nWe can use the result $(\\ref{eq:1.126})$ to derive an expression for the\nsurface area $S_D$ and the volume $V_D$, of a sphere of unit radius in  \n$D$ dimensions. To do this, consider the following result, which is obtained\nby transforming from Cartesian to polar coordinates\n\\begin{equation}\\label{eq:1.142}\\tag{1.142}\n    \\prod_{i = 1}^D \\int_{-\\infty}^{\\infty} e^{-x_i^2} \\diff x_i \n    = S_D \\int_{0}^{\\infty} e^{-r^2} r^{D - 1} \\diff r \n\\end{equation}\n\nUsing the definition ($\\ref{eq:1.141}$) of the Gamma function, together with\n$(\\ref{eq:1.126})$, evaluate both sides of this equation, and hence show that\n\\begin{equation}\\label{eq:1.143}\\tag{1.143}\n    S_D =\\frac{2\\pi^{D/2}}{\\Gamma(D/2)}\n\\end{equation}\n\nNext, by integrating with respect to radius from 0 to 1, show that the volume\nof the unit sphere in $D$ dimensions is given by\n\\begin{equation}\\label{eq:1.144}\\tag{1.144}\n    V_D = \\frac{S_D}{D}\n\\end{equation}\n\nFinally, use the results $\\Gamma(1) = 1$ and $\\Gamma(3/2) = \\sqrt{\\pi}/2$ to show\nthat ($\\ref{eq:1.143}$) and ($\\ref{eq:1.144}$) reduce to the usual\nexpressions for $D = 2$ and $D = 3$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We observe that the left side factor of ($\\ref{eq:1.142}$) looks like \n    $(\\ref{eq:1.126})$ for $\\sigma^2 = 1/2$. Therefore,\n    \\[\n        \\prod_{i = 1}^D \\int_{-\\infty}^{\\infty} e^{-x_i^2} \\diff x_i\n        = \\prod_{i = 1}^D \\pi^{1/2} \n        = \\pi^{D/2}\n    \\] \n\n    One can easily notice that the integral in the right side of ($\\ref{eq:1.142}$)\n    can be written as:\n     \\[\n         \\int_{0}^{\\infty} e^{-r^2}r^{D - 1} \\diff r\n         = \\int_{0}^{\\infty} e^{-r^2} (r^2)^{(D - 2) / 2} r \\diff r\n         = \\frac{1}{2}\\int_{0}^{\\infty} e^{-u} u^{(D - 2)/2} \\diff u\n         = \\frac{1}{2} \\Gamma(D/2) \\diff u\n    \\] \n    where we made the substitution $u = r^2$.\n\n    Therefore, from those results and from $(\\ref{eq:1.142})$, we find that\n    \\begin{equation}\\tag{1.143}\n        S_D =\\frac{2\\pi^{D/2}}{\\Gamma(D/2)}\n    \\end{equation}\n\n    The volume of the unit hypersphere is now given by the integral\n    \\begin{equation}\\tag{1.144}\n        V_D = \\int_{0}^{1} S_D r^{D - 1} \\diff r = \\frac{S_D}{D}\n    \\end{equation}\n\n    Now, we get the expected results for $D = 2$ and $D = 3$:\n    \\[\n        S_2 = \\frac{2\\pi}{\\Gamma(1)} = 2\\pi \n        \\hspace{2em}\n        V_2 = \\pi\n        \\hspace{2em}\n        S_3 = \\frac{2\\pi^{3/2}}{\\Gamma(\\frac{3}{2})} = 4\\pi\n        \\hspace{2em}\n        V_3 = \\frac{4\\pi}{3}\n    \\] \n\\end{proof}\n\n\\section*{Exercise 1.19 $\\star \\star$}\nConsider a sphere of radius $a$ in $D$-dimensions together with\nthe concentric hypercube of side $2a$, so that the sphere touches\nthe hypercube at the centres of each of its sides. By using the results\nof Exercise 1.18, show that the ratio of the volume of the sphere\nto the volume of the cube is given by\n\\begin{equation}\\label{eq:1.145}\\tag{1.145}\n    \\frac{\\text{volume of sphere}}{\\text{volume of cube}} \n    = \\frac{\\pi^{D/2}}{D2^{D - 1}\\Gamma(D/2)}\n\\end{equation}\n\nNow, make use of Stirling's formula in the form\n\\begin{equation}\\label{eq:1.146}\\tag{1.146}\n    \\Gamma(x + 1) \\simeq (2\\pi)^{1/2} e^{-x} x^{x + 1/2}\n\\end{equation}\nwhich is valid for $x \\gg 1$, to show that, as $D \\to \\infty$, the\nratio ($\\ref{eq:1.145}$) goes to zero. Show also that the ratio\nof the distance from the centre of the hypercube to one\nof the corners, divided by the perpendicular distance to one of the\nsides, is $\\sqrt{D}$, which therefore goes to $\\infty$ as $D \\to \\infty$.\nFrom these results we see that, in a space of high dimensionality,\nmost of the volume of a cube is concentrated in a large number\nof corners, which themselves become very lone 'spikes'!\n\n\\vspace{1em}\n\n\\begin{proof}\n    Using the results of Exercise 1.18, we have that the volume of \n    $D$-dimensional hypersphere of radius $a$ is \n    \\[\n        V_{D_{\\text{sphere}}}(a) = \\frac{2\\pi^{D/2} a^D}{D\\Gamma(D/2)}\n    \\] \n\n    We also know that the volume of the $D-$hypercube of size $2a$ \n    is given by:\n    \\[\n        V_{D_{\\text{cube}}(2a)} = (2a)^D = 2^D a^D\n    \\] \n\n    Therefore the ratio of the volumes is given by\n    \\begin{equation}\\tag{1.145}\n        \\frac{V_{D_{\\text{sphere}}(a)}}{V_{D_{\\text{cube}}}(a)} = \\frac{\\pi^{D/2}}{D 2^{D - 1}\\Gamma(D/2)}\n    \\end{equation}\n\n    By using Stirling's approximation, we have that\n    \\begin{align*}\n    \\lim_{D \\to \\infty} \\frac{\\pi^{D/2}}{D 2^{D - 1}\\Gamma(D/2)}\n    &= \\lim_{D \\to \\infty} \\frac{\\pi^{D/2}}{D 2^{D - 1} (2\\pi)^{1/2}e^{1 - D/2} (D/2 - 1)^{D/2 - 1/2}} \\\\\n    &= \\lim_{D \\to \\infty} \\bigg\\{\\bigg(\\frac{\\pi}{4}\\bigg)^{D/2} \\cdot \\bigg(\\frac{e}{D/2 - 1}\\bigg)^{D/2 - 1} \\cdot \\frac{\\sqrt{D - 2}}{D\\sqrt{\\pi}}\\bigg\\} = 0\n    \\end{align*}\n\n    Now, we want to find the ratio between the distance from the centre of the hypercube to one\n    of the corners and the distance from the centre to a side. We can consider without loss of \n    generality a $D$-dimensional hypercube of length $2\\alpha$, centered in the origin $0_D$ of the \n    $\\mathbb{R}^D$ Cartesian system. The center of a hypercube side takes the form \n    $\\mathbf{s} = (\\alpha_1, \\alpha_2, \\ldots, \\alpha_D)$, where $\\alpha_i \\in \\{0, a\\}$ such \n    that $||\\mathbf{s}|| = a$, i.e. only one coordinate is equal to $a$ and the rest are $0$. \n    On the other hand, the corners of the hypercube take the \n    form $\\mathbf{c} = (\\beta_1, \\beta_2, \\ldots, \\beta_D)$, where $\\beta_i \\in \\{\\pm a\\}$.\n    We'll then have that $||\\mathbf{c}|| = a\\sqrt{D}$. As a result, our ratio looks like expected:\n    \\[\n        \\frac{\\text{distance from center to corner}}{\\text{distance from center to side}} \n        = \\frac{||\\mathbf{s}||}{||\\mathbf{c}||} = \\frac{a\\sqrt{D}}{a} = \\sqrt{D}\n    \\] \n\\end{proof}\n\n\\section*{Exercise 1.21 $\\star \\star$}\nConsider two nonnegative numbers $a$ and $b$, and show that, if $a \\leq b$, then\n$a \\leq (ab)^{1/2}$. Use this result to show that, if the decision regions of a two-class\nclassification problem are chosen to minimize the probability of misclassification,\nthis probability will satisfy\n\\begin{equation}\\label{eq:1.150}\\tag{1.150}\n    p(\\text{mistake}) \\leq \\int \\{p(\\mathbf{x}, \\mathcal{C}_1)p(\\mathbf{x}, \\mathcal{C}_2)\\}^{1/2} \n    \\diff \\mathbf{x}\n\\end{equation}\n\n\\begin{proof}\n    We start by proving the identity. We have that \n    \\[\n        a \\leq (ab)^{1/2} \\iff a^2 \\leq ab \\iff a^2 - ab \\leq 0 \\iff a(a - b) \\leq 0\n    \\] \n    which is true since $a \\leq b$.\n\n    Now, since the regions are chosen to minimize the probability of misclassification,\n    for an individual value of $\\mathbf{x}$, the region $\\mathcal{R}_k$ with the higher joint/posterior \n    probability associated to $\\mathcal{C}_k$ is chosen, so:\n    \\[\n        p(\\mathbf{x}, \\mathcal{C}_2) \\leq p(\\mathbf{x}, \\mathcal{C}_1), \\forall \\mathbf{x} \\in \\mathcal{R}_1\n        \\hspace{3em}\n        p(\\mathbf{x}, \\mathcal{C}_1) \\leq p(\\mathbf{x}, \\mathcal{C}_2), \\forall \\mathbf{x} \\in \\mathcal{R}_2\n    \\] \n\n    By applying the $a \\leq (ab)^{1/2}$ identity above, we get that\n    \\[\n        p(\\mathbf{x}, \\mathcal{C}_2) \\leq \\{p(\\mathbf{x}, \\mathcal{C}_1) p(\\mathbf{x}, \\mathcal{C}_2)\\}^{1/2},\n        \\forall \\mathbf{x} \\in \\mathcal{R}_1\n        \\hspace{3em}\n        p(\\mathbf{x}, \\mathcal{C}_1) \\leq \\{p(\\mathbf{x}, \\mathcal{C}_1) p(\\mathbf{x}, \\mathcal{C}_2)\\}^{1/2},\n        \\forall \\mathbf{x} \\in \\mathcal{R}_2\n    \\] \n\n    If we integrate the inequalities over the associated regions, we have that:\n    \\[\n        \\int_{\\mathcal{R}_1} p(\\mathbf{x}, \\mathcal{C}_2) \\diff \\mathbf{x} \\leq \n        \\int_{\\mathcal{R}_1} \\{p(\\mathbf{x}, \\mathcal{C}_1) p(\\mathbf{x}, \\mathcal{C}_2)\\}^{1/2} \\diff \\mathbf{x}\n    \\] \n    \\[\n        \\int_{\\mathcal{R}_2} p(\\mathbf{x}, \\mathcal{C}_1) \\diff \\mathbf{x} \\leq \n        \\int_{\\mathcal{R}_2} \\{p(\\mathbf{x}, \\mathcal{C}_1) p(\\mathbf{x}, \\mathcal{C}_2)\\}^{1/2} \\diff \\mathbf{x}\n    \\]\n\n    By summing the above inequalities, we find that:\n    \\[\n        \\int_{\\mathcal{R}_1} p(\\mathbf{x}, \\mathcal{C}_2) \\diff \\mathbf{x} + \n        \\int_{\\mathcal{R}_2} p(\\mathbf{x}, \\mathcal{C}_1) \\diff \\mathbf{x} \\leq\n        \\int \\{p(\\mathbf{x}, \\mathcal{C}_1)p(\\mathbf{x}, \\mathcal{C}_2)\\}^{1/2} \n    \\] \n    which is equivalent to ($\\ref{eq:1.150}$).\n\\end{proof}\n\n\\section*{Exercise 1.22 $\\star$}\nGiven a loss matrix with elements $L_{kj}$, the expected risk\nis minimized, if for each $\\mathbf{x}$, we choose the class that minimizes\n$(\\ref{eq:1.81})$. Verify that, when the loss matrix is given by $L_{kj} = 1 - I_{kj}$,\nwhere $I_{kj}$ are the elements of the identity matrix, this reduces to the criterion\nof choosing the class having the largest posterior probability. What is the interpretation\nof this form of loss matrix?\n\n\\vspace{1em}\n\n\\begin{proof}\n    The expectation is minimized if for each $\\mathbf{x}$ we choose the class $\\mathcal{C}_j$ such\n    that the quantity\n    \\begin{equation}\\label{eq:1.81}\\tag{1.81}\n        \\sum_k L_{kj} p(\\mathcal{C}_k | \\mathbf{x})\n    \\end{equation}\n    is minimized. For $L_{kj} = 1 - I_{kj}$ the quantity becomes\n    \\[\n        \\sum_k (1 - I_{kj})p(\\mathcal{C}_k | \\mathbf{x}) \n        = \\sum_k p(\\mathcal{C}_k | \\mathbf{x}) - p(\\mathcal{C}_j | \\mathbf{x}) \n        = 1 - p(\\mathcal{C}_j | \\mathbf{x})\n    \\] \n    and it's obviously minimised by choosing the class $\\mathcal{C}_j$ having the largest \n    posterior probability $p(\\mathcal{C}_j | \\mathbf{x})$\n\n    This form of loss matrix makes each mistake have the same \"weight\", no mistake\n    is worse than another.\n\\end{proof}\n\n\\section*{Exercise 1.23 $\\star$}\nDerive the criterion for minimizing the expected loss when there\nis a general loss matrix and general prior probabilities for the classes.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Minimizing the expected loss\n    \\begin{equation}\\label{eq:1.80}\\tag{1.80}\n        \\mathbb{E}[L] = \\sum_k \\sum_j \\int_{\\mathcal{R}_j} L_{kj} p(\\mathbf{x}, \\mathcal{C}_j) \\diff \\mathbf{x}\n    \\end{equation}\n    is equivalent with minimizing \n    \\[\n        \\sum_k L_{kj} p(\\mathbf{x}, \\mathcal{C}_k)\n    \\] \n    for each $\\mathbf{x}$. Therefore, by using Bayes' theorem, we have that\n    the criterion of minimizing the expected loss is the class $\\mathcal{C}_j$ for each\n    $\\mathbf{x}$ such that\n    \\[\n        \\sum_k L_{kj} p(\\mathbf{x} | \\mathcal{C}_k)\n    \\] \n    is minimized.\n\\end{proof}\n\n\\section*{Exercise 1.24 $\\star \\star$}\nConsider a classification problem in which the loss incurred\nwhen an input vector from class $\\mathcal{C}_k$ is classified\nas belonging to class $\\mathcal{C}_j$ is given by the\nloss matrix $L_{kj}$, and for which the loss incurred in\nselecting the reject option is $\\lambda$. Find the decision\ncriterion that will give the minimum expected loss. Verify\nthat this reduces to the reject criterion discussed in Section\n1.5.3 when the loss matrix is given by $L_{kj} = 1 - I_{kj}$.\nWhat is the relationship between $\\lambda$ and the rejection\nthreshold $\\theta$?\n\n\\vspace{1em}\n\n\\begin{proof}\n    The decision criterion reduces to choosing the minimum between the loss\n    of choosing the best class and the reject loss $\\lambda$. Therefore, if\n    \\[\n        \\alpha = \\underset{j}{\\mathrm{argmin}} \\sum_k L_{kj}p(\\mathbf{x} | \\mathcal{C}_k)\n    \\] \n    we choose the class $\\alpha$ if the above quantity is less than $\\lambda$ \n    and use the reject option otherwise. If the loss matrix is given\n    by $L_{kj} = 1 - I_{kj}$, then \n    \\[\n        \\alpha = \\underset{j}{\\mathrm{argmin}} \\{1 - p(\\mathcal{C}_j | \\mathbf{x})\\}\n    \\] \n    which makes $\\mathcal{C}_{\\alpha}$ the class with the highest posterior probability.\n    Therefore the criterion reduces to the one discussed in Section 1.5.3.\n    If the highest posterior probability is smaller than $1 - \\lambda$, then\n    we use the reject option. This is equivalent with using $\\theta = 1 - \\lambda$\n    in Section 1.5.3.\n\\end{proof}\n\n\\section*{Exercise 1.25 $\\star$ CALCULUS OF VARIATIONS}\nConsider the generalization of the squared loss function (1.87) for\na single target variable $t$ to the case of multiple target variables\ndescribed by the vector $\\mathbf{t}$ given by\n\\begin{equation}\\label{eq:1.151}\\tag{1.151}\n    \\mathbb{E}[L(\\mathbf{t}, \\mathbf{y}(\\mathbf{x})] \n    = \\iint ||\\mathbf{y}(\\mathbf{x}) - \\mathbf{t}||^2 p(\\mathbf{x}, \\mathbf{t}) \n    \\diff \\mathbf{x} \\diff \\mathbf{t}\n\\end{equation}\nUsing the calculus of the variations, show that the function $\\mathbf{y}(\\mathbf{x})$ for\nwhich this expected loss is minimized is given by \n$\\mathbf{y}(\\mathbf{x}) = \\mathbb{E}_{\\mathbf{t}}[\\mathbf{t}|\\mathbf{x}]$. \nShow that this result reduces to (1.89) for the case of a single target variable $t$. \n\n\\section*{Exercise 1.26 $\\star$ TODO}\nBy expansion of the square in ($\\ref{eq:1.151}$), derive a result analogous to\n$(1.90)$, and hence show that the function $\\mathbf{y}(\\mathbf{x})$ that\nminimizes the expected square loss for the case of a vector $\\mathbf{t}$ \nof target variables is again given by the conditional expectation of $\\mathbf{t}$.\n\n\\section*{Exercise 1.27 $\\star \\star$ TODO}\nConsider the expected loss for regression problems under the $L_q$ loss\nfunction given by (1.91). Write down the condition that $y(\\mathbf{x})$ \nmust satisfy in order to minimize $\\mathbb{E}[L_q]$. Show that, for $q = 1$,\nthis solution represents the conditional median, i.e., the function \n$y(\\mathbf{x})$ such that the probability mass for $t < y(\\mathbf{x})$ \nis the same for $t \\geq y(\\mathbf{x})$. Also show that the minimum expected\n$L_q$ loss for $q \\to 0$ is given by the conditional mode, i.e., by\nthe function $y(\\mathbf{x})$ equal to the value $t$ that maximizes \n$p(t | \\mathbf{x})$ for each  $\\mathbf{x}$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    \n\\end{proof}\n\n\\section*{Exercise 1.28 $\\star$}\nIn Section 1.6, we introduced the idea of entropy $h(x)$ as the information\ngained on observing the value of a random variable  $x$ having distribution\n$p(x)$. We saw that, for independent variables $x$ and $y$ for which\n$p(x, y) = p(x)p(y)$, the entropy functions are additive, so that \n$h(x, y) = h(x) + h(y)$. In this exercise, we derive that the relation\nbetween $h$ and  $p$ in the form of a function  $h(p)$. First show that\n$h(p^2) = 2h(p)$, and hence by induction that $h(p^n) = nh(p)$ where\n$n$ is a positive integer. Hence show that $h(p^{n/m})$ = $n/m h(p)$\nwhere $m$ is also a positive integer. This implies that $h(p^x) = xh(p)$ where\n$x$ is a positive rational number, and hence by continuity when it is\na positive real number. Finally, show that this implies $h(p)$ must take\nthe form  $h(p) \\propto \\ln p$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    For independent variables $x$ and $y$ we have that:\n    \\[\n        h(x, y) = -\\log_2 p(x, y) = -\\log_2 p(x) p(y) = -\\log_2 p(x) -\\log_2 p(y) = h(x) + h(y)\n    \\] \n\n    Next, we show that:\n    \\[\n        h(p^2) = -\\log_2 p^2 = -2 \\log_2 p = 2h(p)\n    \\] \n    and more generally for a positive integer $n$:\n    \\[\n        h(p^n) = -\\log_2 p^n = -n \\log_2 p = nh(p)\n    \\] \n\n    This can be extended to rational number by letting $n, m \\in \\mathbb{N}$ and\n    showing that:\n     \\[\n         h(p^{n/m}) = -\\log_2 p^{n/m} = -\\frac{n}{m} \\log_2 p = \\frac{n}{m} h(p)\n    \\] \n\n    Finally, since\n    \\[\n        h(p) = -\\log_2 p = -\\frac{1}{\\ln 2} \\ln p\n    \\] \n    \n    we have that $h(p) \\propto \\ln p$.\n\\end{proof}\n\n\\vspace{1em}\n\n\\section*{Exercise 1.29}\nConsider an $M$-state  discrete random variable $x$, and use Jensen's inequality\nin the form ($\\ref{eq:1.115}$) to show that the entropy of the distribution\n$p(x)$ satisfies $H[x] \\leq \\ln M$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The entropy of the distribution $p(x)$ is given by:\n    \\[\n        H[x] = - \\sum_{i=1}^{M} p(x_i) \\ln p(x_i) \n    \\] \n\n    We apply Jensen's inequality with $\\lambda_i = p(x_i)$ and the convex\n    function $f(x) = \\ln(x)$ to obtain:\n    \\begin{equation}\\label{eq:1.29.1}\\tag{1.29.1}\n        H[x] \\leq -\\ln\\bigg(\\sum_{i=1}^{M} p(x)^2\\bigg)\n    \\end{equation}\n\n    One can prove by using Lagrange multipliers that\n    \\[\n        \\sum_{i=1}^{M} p(x)^2 \\leq \\frac{1}{M}\n    \\] \n\n    Therefore, by substituting into $(\\ref{eq:1.29.1})$ and using \n    the fact that $\\ln x$ is strictly increasing on $(0, \\infty)$,\n    we have that\n    \\[\n        H[x] \\leq \\ln M\n    \\] \n\\end{proof}\n\n\\section*{Exercise 1.30 $\\star \\star$}\nEvaluate the Kullback-Leibler divergence ($\\ref{eq:1.113}$) between two Gaussians\n$p(x) = \\mathcal{N}(x | \\mu, \\sigma^2)$ and $q(x) = \\mathcal{N}(x | m, s^2)$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The Kullback-Leibler divergence is given by \n    \\begin{equation}\\label{eq:1.113}\\tag{1.113}\n        \\text{KL}(p || q) = - \\int p(x) \\ln \\bigg\\{ \\frac{q(x)}{p(x)} \\bigg\\} \\diff x\n    \\end{equation}\n\n    We start by splitting the integral into:\n    \\[\n        \\text{KL}(p || q) = \n            -\\int p(x) \\ln q(x) \\diff x + \\int p(x) \\ln p(x) \\diff x\n    \\] \n\n    The negation of the second term will be equal to the entropy of the Gaussian,\n    that is:\n    \\begin{equation}\\label{eq:1.110}\\tag{1.110}\n        H_p[x] = \\frac{1}{2} \\{1 + \\ln (2\\pi \\sigma^2)\\}\n    \\end{equation}\n\n    We have that\n    \\[\n        \\ln q(x) = \\ln \\mathcal{N} (x | m, s^2) = \\frac{1}{2} \\ln(2\\pi s^2) - \\frac{(x - m)^2}{s^2}\n    \\] \n    so by using the fact that the Gaussian is normalized and by noticing the expected\n    values, the KL divergence becomes:\n    \\begin{align*}\n        \\text{KL}(p || q) \n        &= \\frac{1}{s^2}\\int p(x) x^2 \\diff x - \\frac{2m}{s^2} \\int p(x) x \\diff x \n        + \\bigg\\{\\frac{1}{2} \\ln(2\\pi s^2) + \\frac{m^2}{s^2}\\bigg\\} \\int p(x) \\diff x\n        - H_p[x] \\\\\n        &= \\frac{1}{s^2} \\mathbb{E}[x^2] - \\frac{2m}{s^2}E[x] \n        + \\frac{m^2}{s^2} + \\ln \\frac{s}{\\sigma} + \\frac{1}{2} \\\\\n        &= \\frac{1}{2} + \\ln \\frac{s}{\\sigma} + \\frac{\\sigma^2 + (\\mu - m)^2}{s^2}\n    \\end{align*}\n\\end{proof}\n\n\\section*{Exercise 1.31 $\\star \\star$}\nConsider two variables $\\mathbf{x}$ and $\\mathbf{y}$ having joint distribution\n$p(\\mathbf{x}, \\mathbf{y})$. Show that the differential entropy of this pair of \nvariables satisfies\n\\begin{equation}\\label{eq:1.152}\\tag{1.152}\n    H[\\mathbf{x}, \\mathbf{y}] \\leq H[\\mathbf{x}] + H[\\mathbf{y}]\n\\end{equation}\nwith equality if, and only if $\\mathbf{x}$ and $\\mathbf{y}$ are statistically\nindependent.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The differential entropy of two variables $\\mathbf{x}$ and  $\\mathbf{y}$\n    is given by \n    \\begin{equation}\\label{eq:1.112}\\tag{1.112}\n        H[\\mathbf{x}, \\mathbf{y}] = H[\\mathbf{y} | \\mathbf{x}] + H[\\mathbf{x}]\n    \\end{equation}\n    so $(\\ref{eq:1.152})$ becomes equivalent with\n    \\begin{equation}\\label{eq:1.31.1}\\tag{1.31.1}\n        H[\\mathbf{y} | \\mathbf{x}] - H[\\mathbf{y}] \\leq 0\n    \\end{equation}\n    which we're going to prove now. \n\n    We start by rewriting the entropy $H[\\mathbf{y}]$ as\n    \\[\n        H[\\mathbf{y}] \n        = -\\int p(\\mathbf{y}) \\ln p(\\mathbf{y}) \\diff \\mathbf{y}\n        = -\\iint p(\\mathbf{x}, \\mathbf{y}) \\ln p(\\mathbf{y}) \\diff \\mathbf{x} \\diff \\mathbf{y}\n    \\] \n\n    Therefore, since the differential entropy is given by\n    \\begin{equation}\\label{eq:1.111}\\tag{1.111}\n        H[\\mathbf{y} | \\mathbf{x}] \n        = \\iint p(\\mathbf{x}, \\mathbf{y}) \\ln p(\\mathbf{y} | \\mathbf{x}) \\diff \\mathbf{x} \\diff \\mathbf{y}\n    \\end{equation}\n    we have that\n    \\begin{align*}\n         H[\\mathbf{y} | \\mathbf{x}] - H[\\mathbf{y}] \n        &= -\\iint p(\\mathbf{x}, \\mathbf{y}) \\ln p(\\mathbf{y} | \\mathbf{x}) \\diff \\mathbf{x} \\diff \\mathbf{y}\n        + \\iint p(\\mathbf{x}, \\mathbf{y}) \\ln p(\\mathbf{y}) \\diff \\mathbf{x} \\diff \\mathbf{y} \\\\\n        &= \\iint p(\\mathbf{x}, \\mathbf{y}) \\ln \\bigg\\{ \\frac{p(\\mathbf{y})}{p(\\mathbf{y}|\\mathbf{x})}\\bigg\\}\n        \\diff \\mathbf{x} \\diff \\mathbf{y}\n    \\end{align*}\n\n    By using the inequality $\\ln \\alpha \\leq \\alpha - 1$, for all $\\alpha > 0$, we obtain:\n    \\begin{align*}\n         H[\\mathbf{y} | \\mathbf{x}] - H[\\mathbf{y}] \n        &\\leq \\iint p(\\mathbf{x}) p(\\mathbf{y} | \\mathbf{x}) \\bigg\\{\\frac{p(\\mathbf{y})}{p(\\mathbf{y} | \\mathbf{x})} - 1\\bigg\\}\n        \\diff \\mathbf{x} \\diff \\mathbf{y} \\\\\n        &\\leq \\iint p(\\mathbf{x}) p(\\mathbf{y}) \\diff \\mathbf{x} \\diff \\mathbf{y} \n        - \\iint p(\\mathbf{x}) p(\\mathbf{y}) \\diff \\mathbf{x} \\mathbf{y} \\\\\n        &\\leq \\iint p(\\mathbf{x}) p(\\mathbf{y}) \\diff \\mathbf{x} \\diff \\mathbf{y}  - 1 \\\\\n        &\\leq 0\n    \\end{align*}\n\n    which proves $(\\ref{eq:1.31.1})$, respectively $(\\ref{eq:1.152})$.\n\\end{proof}\n\n\\section*{Exercise 1.32 $\\star$}\nConsider a vector $\\mathbf{x}$ of continuous variables with distribution\n$p(\\mathbf{x})$ and corresponding entropy $H[\\mathbf{x}]$. Suppose\nthat we make a nonsingular linear transformation of $\\mathbf{x}$ to\nobtain a new variable $\\mathbf{y} = \\mathbf{Ax}$. Show that the coresponding\nentropy is given by $H[\\mathbf{y}] = H[\\mathbf{x}] + \\ln |\\mathbf{A}|$ \nwhere $|\\mathbf{A}|$ denotes the determinant of $\\mathbf{A}$.\n\n\\begin{proof}\n    By generalizing ($\\ref{eq:1.27}$) for the multivariate case,\n    we have that:\n    \\[\n        p_\\mathbf{y}(\\mathbf{y}) \n        = p_\\mathbf{x}(\\mathbf{x}) \\bigg|\\pdv{\\mathbf{x}}{\\mathbf{y}}\\bigg|\n        = p_\\mathbf{x}(\\mathbf{x}) \\bigg|\\pdv{\\mathbf{A}^{-1} \\mathbf{y}}{\\mathbf{y}}\\bigg|\n        = p_\\mathbf{x}(\\mathbf{x}) |\\mathbf{A}^{-1}|\n        = p_\\mathbf{x}(\\mathbf{x}) |\\mathbf{A}|^{-1}\n    \\] \n    where $J = \\displaystyle\\bigg|\\pdv{\\mathbf{x}}{\\mathbf{y}}\\bigg| = |\\mathbf{A}|^{-1}$ \n    is the Jacobian determinant.\n    \n    Now, the entropy of $\\mathbf{y}$ is given by:\n    \\begin{align*}\n        H[\\mathbf{y}] \n        &= -\\int p_\\mathbf{y}(\\mathbf{y}) \\ln p_\\mathbf{y}(\\mathbf{y}) \\diff \\mathbf{y}\n        = -\\int \\frac{p_\\mathbf{x}(\\mathbf{x})}{|\\mathbf{A}|} \n        \\ln \\frac{p_\\mathbf{x}(\\mathbf{x})}{|\\mathbf{A}|} \\bigg| \\frac{\\mathrm{d}\\mathbf{y}}{\\mathrm{d}\\mathbf{x}}\\bigg| \\diff \\mathbf{x}\n        = -\\int p_{\\mathbf{x}}(\\mathbf{x})\n        \\ln \\frac{p_\\mathbf{x}(\\mathbf{x})}{|\\mathbf{A}|} \\diff \\mathbf{x} \\\\\n        &= -\\int p_\\mathbf{x}(\\mathbf{x}) \\ln p_\\mathbf{x} \\diff \\mathbf{x} \n        + \\ln |\\mathbf{A}| \\int p_\\mathbf{x}(\\mathbf{x}) \\diff \\mathbf{x} \\\\\n        &= H[\\mathbf{y}] + \\ln |\\mathbf{A}|\n    \\end{align*}\n\\end{proof}\n\n\\section*{Exercise 1.33 $\\star \\star$}\nSuppose that the conditional entropy $H[y | x]$ between\ntwo discrete random variables $x$ and $y$ is zero. Show that,\nfor all  values of $x$ such that $p(x) > 0$, the variable $y$ \nmust be a function of $x$, in other words for each $x$ there is\nonly one value of $y$ such that $p(y | x) \\neq 0$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Assuming $x, y$ have $N$ respectively $M$ outcomes,\n    we can rewrite the conditional entropy as:\n    \\[\n        H[y | x] \n        = -\\sum_{i}^N  \\sum_{j}^{M} p(x_i, y_j) \\ln p(y_j | x_i)\n        = -\\sum_{i}^{N} p(x_i) \\sum_{j}^{M} p(y_j | x_i) \\ln p(y_j | x_i)\n    \\] \n\n    Since all the sum terms have the same sign, the entropy\n    is 0 if each term is 0. Therefore, the entropy is 0 if\n    for each $p(x_i) > 0$, the inner sum terms are 0. This\n    happens only for $p(y_j | x_i) = 0$ or $\\ln p(y_j | x_i) = 0$,\n    which means that $p(y_j | x_i) \\in \\{0, 1\\}$. Since $\\displaystyle\n    \\sum_{j = 1}^{M} p(y_j | x_i) = 1$, we have that for each\n    $x_i$ there is an unique $y_j$ such that $p(y_j | x_i) = 1$, which\n    proves our hypothesis.\n\\end{proof}\n\n\\section*{Exercise 1.34 $\\star \\star$ CALCULUS OF VARIATIONS}\nUse the calculus of variations to show that the stationary point\nof the functional (1.108) is given by (1.108). Then use the constraints\n(1.105), (1.106) and (1.107) to eliminate de Lagrange multipliers and\nhence show that the maximum entropy solution is given by the Gaussian (1.109).\n\n\\section*{Exercise 1.35 $\\star$}\nUse the results (1.106) and (1.107) to show that the entropy of the \nunivariate Gaussian (1.109) is given by ($\\ref{eq:1.110}$).\n\n\\vspace{1em}\n\n\\begin{proof}\n    The entropy of the univariate Gaussian is given by:\n    \\begin{align*}\n        H[x] \n        =& -\\int \\mathcal{N}(x | \\mu, \\sigma^2) \\ln \\mathcal{N}(x | \\mu, \\sigma^2) \\diff x\n        = -\\frac{1}{2} \\ln (2\\pi \\sigma^2) \\int \\mathcal{N}(x | \\mu, \\sigma^2) \\diff x \n            + \\int \\mathcal{N}(x | \\mu, \\sigma^2) \\frac{(x - \\mu)^2}{\\sigma^2} \\diff x \\\\\n        =& \\bigg\\{-\\frac{1}{2} \\ln (2\\pi \\sigma^2) + \\frac{\\mu^2}{\\sigma^2} \\bigg\\}\n            \\int \\mathcal{N}(x | \\mu, \\sigma^2) \\diff x \n            + \\frac{1}{2\\sigma^2} \\int \\mathcal{N}(x | \\mu, \\sigma^2) x^2 \\diff x \n            - \\frac{2\\mu}{2\\sigma^2} \\int \\mathcal{N}(x | \\mu, \\sigma^2) x\\diff x\n    \\end{align*}\n\n    By using the fact that the Gaussian is normalized and \n    by noticing the expression of the expected value, we have that\n    \\[\n        H[x] \n        = -\\frac{1}{2} \\ln(2\\pi \\sigma^2) \n        + \\frac{\\mu^2}{2\\sigma^2} \n        + \\frac{1}{2\\sigma^2} \\mathbb{E}[x^2]\n        - \\frac{2\\mu}{2\\sigma^2} \\mathbb{E}[x]\n        = \\frac{1}{2} \\bigg\\{1 - \\frac{1}{2} \\ln(2\\pi \\sigma^2)\\bigg\\} \\tag{1.110}\n    \\]\n\\end{proof}\n\n\\section*{Exercise 1.36 $\\star$}\nA strictly convex function is defined as one for which every chord lies\nabove the function. Show that this is equivalent to the condition that\nthe second derivative of the function be positive.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Suppose that $f$ is a twice differentiable function. By \n    summing the Taylor expansions of $f(x + h)$ and $f(x - h)$, \n    one can show that\n    \\[\n        f''(x) = \\lim_{h \\to 0} \\frac{f(x + h) + f(x - h) - 2f(x)}{h^2}\n    \\] \n\n    Therefore, we have that\n    \\begin{align*}\n        f''(x) > 0 \n        &\\iff f(x + h) + f(x - h) - 2f(x) > 0 \\\\\n        & \\iff \\frac{1}{2} f(x + h) + \\frac{1}{2} f(x - h) - f(x) > 0\n    \\end{align*}\n\n    If $f$ is strictly convex, we can apply $(\\ref{eq:1.114})$ in a strict form to obtain \n    \\[\n        \\frac{1}{2} f(x + h) + \\frac{1}{2} f(x - h) - f(x) >\n        f\\bigg(\\frac{1}{2}(x+h) + \\frac{1}{2}(x - h)\\bigg) - f(x) = 0\n    \\] \n\n    Therefore, the second derivative of a strictly convex function is positive.\n\\end{proof}\n\n\\section*{Exercise 1.37 $\\star$}\nUsing the definition ($\\ref{eq:1.111}$) together with the product rule\nof probability, prove the result ($\\ref{eq:1.112}$). \n\n\\vspace{1em}\n\n\\begin{proof}\n    Using the product rule of probability, one could rewrite the entropy of $\\mathbf{x}$ as:\n    \\[\n        H[\\mathbf{x}] \n        = -\\int p(\\mathbf{x}) \\ln p(\\mathbf{x}) \\diff \\mathbf{x}\n        = -\\iint p(\\mathbf{x}, \\mathbf{y}) \\ln p(\\mathbf{x}) \\diff \\mathbf{x} \\diff \\mathbf{y}\n    \\] \n\n    Now, by summing this with $(\\ref{eq:1.111})$ we see that:\n    \\begin{align*}\n         H[\\mathbf{y} | \\mathbf{x}] + H[\\mathbf{x}]\n        &= -\\iint p(\\mathbf{x}, \\mathbf{y}) \\ln p(\\mathbf{y} | \\mathbf{x}) \\diff \\mathbf{x} \\diff \\mathbf{y}\n        -\\iint p(\\mathbf{x}, \\mathbf{y}) \\ln p(\\mathbf{x}) \\diff \\mathbf{x} \\diff \\mathbf{y} \\\\\n        &= -\\iint p(\\mathbf{x}, \\mathbf{y}) \\ln \\{p(\\mathbf{y} | \\mathbf{x})p(\\mathbf{x})\\} \\diff \\mathbf{x} \\diff \\mathbf{y} \\\\\n        &= -\\iint p(\\mathbf{x}, \\mathbf{y}) \\ln p(\\mathbf{x}, \\mathbf{y}) \\diff \\mathbf{x} \\diff \\mathbf{y} \\\\\n        &= H[\\mathbf{x}, \\mathbf{y}] \\tag{1.112}\n    \\end{align*}\n\\end{proof}\n\n\\section*{Exercise 1.38 $\\star \\star$}\nUsing proof by induction, show that the inequality $(1.114)$ for\nconvex functions implies the result ($\\ref{eq:1.115}$).\n\n\\vspace{1em}\n\n\\begin{proof}\n    We'll prove Jensen's inequality by induction, i.e.\n    if we have $N$ points $x_1, \\ldots x_n$, $f$ is a convex function and $\\lambda_i \\geq 0$, \n    $\\displaystyle \\sum_{i=1}^{N} \\lambda_i = 1$, then\n    \\begin{equation}\\label{eq:1.115}\\tag{1.115}\n        f\\bigg(\\sum_{i=1}^{N} \\lambda_i x_i\\bigg) \\leq \\sum_{i=1}^{N} \\lambda_i f(x_i)\n    \\end{equation}\n\n    We consider the base case of the induction to be given by\n    \\begin{equation}\\label{eq:1.114}\\tag{1.114}\n        f(\\lambda a + (1 - \\lambda)b) \\leq \\lambda f(a) + (1 - \\lambda) f(b)\n    \\end{equation}\n\n    Now, we assume that Jensen's inequality is true for a\n    set of $N$ points and want to prove that it's also true for\n    $N + 1$ points. Since $\\displaystyle \\sum_{i=1}^{N} \\lambda_i = 1$,\n    there exists at least one $\\lambda_i \\leq 1$. We can assume\n    without loss of generality that this is $\\lambda_1$.\n    Therefore, we have that\n    \\[\n        f\\bigg(\\sum_{i=1}^{N+1} \\lambda_i x_i\\bigg)\n        = f\\bigg(\\lambda_1 x_1 + (1 - \\lambda_1) \\sum_{i=2}^{N+1} \\frac{\\lambda_i}{1 - \\lambda_1} x_i\\bigg)\n    \\] \n\n    Since $\\lambda_1$ and $1 - \\lambda_1$ are both nonnegative and sum to 1,\n    we can apply ($\\ref{eq:1.115}$) to the right-hand side of the equality to obtain:\n    \\begin{align*}\n        f\\bigg(\\sum_{i=1}^{N+1} \\lambda_i x_i\\bigg)\n        &\\leq \\lambda_1 f(x_1) + (1 - \\lambda_1) \\sum_{i=2}^{N+1} \\frac{\\lambda_i}{1 - \\lambda_1} f(x_i) \\\\\n        &\\leq \\lambda_1 f(x_1) + \\sum_{i=2}^{N+1} f(x_i) \\\\\n        &\\leq \\sum_{i=1}^{N+1} \\lambda_i f(x_i) \\tag{1.115}\n    \\end{align*}\n\n    Therefore, we proved Jensen's inequality by induction.\n\\end{proof}\n\n\\section*{Exercise 1.39 $\\star \\star \\star$}\nConsider two binary variables $x$ and $y$ having the joint distribution\ngiven in Table 1.3. Evaluate the following quantities:\n\\begin{multicols}{3}\n    \\begin{enumerate}[(a)]\n        \\item $H[x]$\n        \\item $H[y]$\n        \\item $H[y | x]$\n        \\item $H[x | y]$\n        \\item $H[x, y]$\n        \\item $I[x, y]$\n    \\end{enumerate}\n\\end{multicols}\nDraw a diagram to show the relationship between these various quantities.\n\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{c c | c c}\n        &  & y & y \\\\\n        &  & 0 & 1 \\\\\n        \\hline\n        x & 0 & 1/3 & 1/3 \\\\\n        x & 1 & 0 & 1/3\n    \\end{tabular}\n    \\caption*{\\textbf{Table 1.3} The joint distribution $p(x, y)$ used in Exercise 1.39.}\n\\end{table}\n\n\\vspace{1em}\n\n\\begin{proof}\n    Through straightforward computations using the discrete formula for the entropy, we have\n    \\begin{multicols}{3}\n        \\begin{enumerate}[(a)]\n            \\item $H[x] = -2/3 \\ln 2 + \\ln 3$\n            \\item $H[y] = -2/3 \\ln 2 + \\ln 3$\n            \\item $H[x | y] = 2/3 \\ln 2$\n            \\item $H[y | x] = 2/3 \\ln 2$\n            \\item $H[x, y] = \\ln 3$\n            \\item $I[x, y] = -4/3 \\ln 2 + \\ln 3$\n        \\end{enumerate}\n    \\end{multicols}\n\n    The diagram shows the relationship between the entropies. Note that\n    the joint entropy $H[x, y]$ occupies all three colored areas.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.8\\linewidth]{diagram.png}\n    \\caption*{Exercise 1.39 Diagram}\n\\end{figure}\n\\end{proof}\n\n\\section*{Exercise 1.40 $\\star$}\nBy applying Jensen's inequality $(\\ref{eq:1.115})$ with $f(x) = \\ln x$, show\nthat the arithmetic mean of a set of real numbers is never less than their\ngeometric mean.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Let $N$ be the cardinality of the considered set of real numbers. By considering\n    $f(x) = \\ln x$ (which is convex) and  $\\lambda_i = 1/N$, we use Jensen's inequality\n    to obtain:\n    \\begin{align*}\n        \\ln \\bigg(\\frac{1}{N} \\sum_{i=1}^{N} x_i\\bigg) \n        \\leq \\frac{1}{N} \\sum_{i=1}^{N} \\ln x_i\n        = \\frac{1}{N} \\ln \\bigg(\\prod_{i = 1}^N x_i\\bigg)\n        = \\ln \\bigg\\{\\bigg(\\prod_{i = 1}^N x_i\\bigg)^{1/N}\\bigg\\}\n    \\end{align*}\n\n    Since $\\ln x$ is increasing, the above inequality is equivalent with:\n     \\[\n         \\frac{1}{N} \\sum_{i=1}^{N} x_i \\leq \\bigg({\\prod_{i = 1}^n x_i}\\bigg)^{1/N}\n    \\] \n    which proves that the arithmetic mean of a set of real numbers \n    is never less than their geometric mean.\n\\end{proof}\n\n\\section*{Exercise 1.41 $\\star$}\nUsing the sum and product rules of probability, show that the mutual\ninformation $I(\\mathbf{x}, \\mathbf{y})$ satisfies the relation  $(\\ref{eq:1.121})$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The mutual information between the variables $\\mathbf{x}$ and $\\mathbf{y}$ is\n    given by:\n    \\begin{equation}\\label{eq:1.120}\\tag{1.120}\n        I[\\mathbf{x}, \\mathbf{y}] \n        = -\\iint p(\\mathbf{x}, \\mathbf{y}) \\ln \\bigg(\\frac{p(\\mathbf{x})p(\\mathbf{y})}\n        {p(\\mathbf{x}, \\mathbf{y})}\\bigg) \\diff \\mathbf{x} \\diff \\mathbf{y}\n    \\end{equation}\n\n    We split the integral and use the product and sum rules of probability to obtain\n    the desired result:\n    \\begin{align*}\n        I[\\mathbf{x}, \\mathbf{y}] \n        &= -\\iint p(\\mathbf{x}, \\mathbf{y}) \\ln p(\\mathbf{x}) \\diff \\mathbf{x} \\diff \\mathbf{y}\n        + \\iint p(\\mathbf{x}, \\mathbf{y}) \\ln p(\\mathbf{x} | \\mathbf{y}) \\diff \\mathbf{x} \\diff \\mathbf{y} \\\\\n        &= -\\int p(\\mathbf{x}) \\ln p(\\mathbf{x}) \\diff \\mathbf{x} \n        + \\iint p(\\mathbf{x}, \\mathbf{y}) \\ln p(\\mathbf{x} | \\mathbf{y}) \\diff \\mathbf{x} \\diff \\mathbf{y} \\\\\n        &= H[\\mathbf{x}] - H[\\mathbf{x} | \\mathbf{y}] \\label{eq:1.121}\\tag{1.121}\n    \\end{align*}\n\n    Analogously, one could easily show that also\n    $I[\\mathbf{x}, \\mathbf{y}] = H[\\mathbf{y}] - H[\\mathbf{y} | \\mathbf{x}]$\n\\end{proof}\n", "meta": {"hexsha": "99aac23f7f2e0f485b3ec61960521b15afdda4c8", "size": 64586, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter1_introduction.tex", "max_stars_repo_name": "thesstefan/bishop_prml", "max_stars_repo_head_hexsha": "22c3e04e54f0ff91fa043d46aa0d760998094d1b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/chapter1_introduction.tex", "max_issues_repo_name": "thesstefan/bishop_prml", "max_issues_repo_head_hexsha": "22c3e04e54f0ff91fa043d46aa0d760998094d1b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter1_introduction.tex", "max_forks_repo_name": "thesstefan/bishop_prml", "max_forks_repo_head_hexsha": "22c3e04e54f0ff91fa043d46aa0d760998094d1b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.5611325611, "max_line_length": 161, "alphanum_fraction": 0.5948502771, "num_tokens": 24292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8947894618940992, "lm_q1q2_score": 0.8175481289371567}}
{"text": "We have already seen the logical and binary operator $\\land$ and the unary logical negation operator $\\shortsim$. \n\n\\subsection{The logical or ($\\lor$) operator}\nThe next operator we will introduce is the logical or operator $\\lor$. The motivation for considering this operator is as follows. In colloquial language, a statement of the form ``$A$ or $B$'' is usually taken to mean ``either $A$ or $B$ is true.'' However, this excludes the scenario where $A$ and $B$ are both true. Taking this to account, the truth table for $\\lor$ is the following:\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{|l|l|l|}\n\\hline \n$p$ & $q$ & $p \\lor q$ \\\\ \\hline\n$T$ & $T$ & $T$ \\\\ \\hline\n$T$ & $F$ & $T$ \\\\ \\hline\n$F$ & $T$ & $T$ \\\\ \\hline\n$F$ & $F$ & $F$ \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\n\\subsection{The NAND and NOR operators}\nThe NAND and NOR operators, $\\uparrow$ and $\\downarrow$ respectively can be defined in terms of previously defined operators. The NAND operator $\\uparrow$ is defined as\n\\[p \\uparrow q \\equiv \\shortsim(p \\land q)\\]\nand the NOR operator $\\downarrow$ is defined as\n\\[p \\downarrow q \\equiv \\shortsim(p \\lor q).\\]\n\nIn other words, NAND and NOR are simply the logical negations of the results of the logical and and logical or, respectively. The reader should create truth tables for these operators if they want more practice in creating truth tables.\n\n\\subsection{The XOR and XNOR operator}\nAs we have stated before, the or operator does not reflect colloquial language of the term, which more precisely reflects the term ``either-or''. This operator is true whenever exactly one of its arguments is true, and false otherwise. It is denoted by $\\oplus$. The truth table for this operator is written below:\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{|l|l|l|}\n\\hline \n$p$ & $q$ & $p \\lor q$ \\\\ \\hline\n$T$ & $T$ & $F$ \\\\ \\hline\n$T$ & $F$ & $T$ \\\\ \\hline\n$F$ & $T$ & $T$ \\\\ \\hline\n$F$ & $F$ & $F$ \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\nThe XNOR operator $\\odot$ is defined to be the negation of the XOR operator. Later (In chapter 4) we will see that this operator plays an important role in defining what are called biconditional statements.\n\n\\subsection{The implies ($\\implies$) operator}\n\nThe truth table of the implies operator $\\implies$ is defined below. \n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{|l|l|l|}\n\\hline \n$p$ & $q$ & $p \\implies q$ \\\\ \\hline\n$T$ & $T$ & $T$ \\\\ \\hline\n$T$ & $F$ & $T$ \\\\ \\hline\n$F$ & $T$ & $F$ \\\\ \\hline\n$F$ & $F$ & $T$ \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\nThe motivation of this operator is to tabulate situations that can happen given that any given implication statement is true. Suppose that the following statement is true no matter what\n\n\\begin{center}\nIf it is raining outside, then Bob will carry an umbrella.\n\\end{center}\n\nThen consider the statements ``it is raining outside'' and ``Bob is carrying an umbrella''. Consider the following scenarios.\n\n\\begin{itemize}\n\t\\item It is possible for it to be both raining outside and for Bob to be carrying an umbrella at the same time, for the statement above is always true. So both statements being true is possible.\n\t\\item It is possible for it to be not raining outside and yet for Bob to be carrying an umbrella. For what if Bob carried an umbrella all the time? The statement above does not discount that possibility. So for the first statement to be true and the second to be false is possible.\n\t\\item It is not possible for it to be raining outside and Bob to not be carrying an umbrella, as the statement given forbids this possibility.\n\t\\item It is possible for it to be not raining outside and for Bob to be not carrying an umbrella. For the statement does not say anything about Bob when it is not raining outside.\n\\end{itemize}\n\nFor every case where the two statements are possible we let the implication operator record true, and for the one case where the two statements are not possible we let the implication operator record false.", "meta": {"hexsha": "79efadbaf0caeb401adaad7fc30d6c45c326f223", "size": 3943, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch1/ls_op.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch1/ls_op.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch1/ls_op.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.2837837838, "max_line_length": 387, "alphanum_fraction": 0.7225462846, "num_tokens": 1088, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897509188344, "lm_q2_score": 0.8688267881258485, "lm_q1q2_score": 0.8173833375925279}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 3}\n\nShow that if $A \\leq_P B$, $B \\leq_P C$ then $A \\leq_P C$ where $A$, $B$ and $C$ are decidable problems.\n\n\\subsection*{Solution}\n\nUsing $A \\leq_P B$, by definition, there is a function $f$ that maps instances of the problem $A$ to a subset of instances of the problem $B$ in runtime $\\mathcal{O}(|a|^m)$ for some $m$.\nSimilarly, $B \\leq_P C$ means there is a function $g$ that maps all instances of the problem $B$ to a subset of instances of the problem $C$ in runtime $\\mathcal{O}(|b|^n)$ for some $n$.\n\nAs $\\text{domain}(A) \\subseteq \\text{domain}(B)$, we can propose a function $h = g(f(a))$ that maps any instance $a$ of the problem $A$ to a subset of instances of the problem $C$.\nUsing properties of runtime, running time of $g(f(a))$ will be $\\mathcal{O}(|a|^m) + \\mathcal{O}(|f(a)|^n) = \\mathcal{O}(|a|^k)$ where $k = \\text{max}(m,n)$.\n\nTherefore, polynomial-time reduction is transitive and $A \\leq_P C$.\n", "meta": {"hexsha": "d237883651c2318110276d8083839d607024d7ad", "size": 1293, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw06/hw06q03.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw06/hw06q03.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw06/hw06q03.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 61.5714285714, "max_line_length": 187, "alphanum_fraction": 0.6210363496, "num_tokens": 386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.8688267847293731, "lm_q1q2_score": 0.8173833358395158}}
{"text": "\\section{Normalized Initialization}\nIn order to find a good initialization for deep networks, Kaiming He(2015) followed Xavier(2010) to study the propagations of signals from input layer to output layer.\n\\paragraph{Forward propagation}\nThe central idea is to investigate the variance of the responses in each layer. For a conv layer, a response is:\n$$\n\\mathbf{y}_{l}=\\mathrm{W}_{l} \\mathbf{x}_{l}+\\mathbf{b}_{l}\n$$\nHere, the number of input channels is c, the number of output channel is d, and the size of filter is $k\\times k$. Then $n=k^2c$ denoting the number of connections of a response. Using l to index a layer, and $ \\mathbf{x}_{l} = f( \\mathbf{y}_{l-1})$ where f is the activation.\n\nLet initialized elements in $\\mathrm{W}_{l}$ be i.i.d. Assuming that the elements in $\\mathrm{x}_{l}$ are also i.i.d and $\\mathrm{W}_{l}$ and $ \\mathrm{W}_{l}$ are independent of each other.Then we have:\n$$\n\\operatorname{Var}\\left[y_{l}\\right]=n_{l} \\operatorname{Var}\\left[w_{l} x_{l}\\right]\n$$\nwhere now $y_{l}, x_{l},$ and $w_{l}$ represent the random variables of\neach element in $y_{l}, W_{l},$ and $x_{l}$ respectively. We let $w_{l}$ have zero mean, then we have:\n$$\n\\operatorname{Var}\\left[y_{l}\\right]=n_{l} \\operatorname{Var}\\left[w_{l}\\right] E\\left[x_{l}^{2}\\right]\n$$\nIf we let $w_{l-1}$ have a symmetric distribution around zero\nand $b_{l-1}=0,$ then $y_{l-1}$ has zero mean and has a symmetric\ndistribution around zero. This leads to $E\\left[x_{l}^{2}\\right]=\\frac{1}{2} \\operatorname{Var}\\left[y_{l-1}\\right]$\nwhen $f$ is ReLU. We obtain:\n\\begin{equation}\n\\operatorname{Var}\\left[y_{l}\\right]=\\frac{1}{2} n_{l} \\operatorname{Var}\\left[w_{l}\\right] \\operatorname{Var}\\left[y_{l-1}\\right]\n\\end{equation}\nWith $L$ layers put together, we have:\n$$\n\\operatorname{Var}\\left[y_{L}\\right]=\\operatorname{Var}\\left[y_{1}\\right]\\left(\\prod_{l=2}^{L} \\frac{1}{2} n_{l} \\operatorname{Var}\\left[w_{l}\\right]\\right)\n$$\nA proper initialization method should avoid reducing or magnifying the magnitudes of input signals exponentially.A sufficient condition is:\n\\begin{equation}\\label{He}\n\\frac{1}{2} n_{l} \\operatorname{Var}\\left[w_{l}\\right]=1, \\quad \\forall l\n\\end{equation}\nThis leads to a zero-mean Gaussian distribution whose standard deviation (std) is $\\sqrt{2 / n_{l}}$ . This is their way of initialization. they also initialize $\\mathbf{b}=0$.\n\nThe mainly difference between He and Xavier is that Xavier  is based on the assumption that the activations are linear, which leads the condition in Xavier is:\n\\begin{equation}\\label{Xavier}\n n_{l} \\operatorname{Var}\\left[w_{l}\\right]=1, \\quad \\forall l\n\\end{equation}\nAnd another difference is that Xavier use the uniform distribution but He use the Gaussian distribution.\n\\subsection{Experiments on ImageNet}\nGiven a 22-layer model, in cifar10 the convergence with He's initialization is faster than Xavier, but both of them are able to converge and the validation accuracies with two different initialization are about the same(error is 33.82,33.90).\n\nWith extremely deep model with up to 30 layers, He's initialization is able to make the model convergence. On the contrary, the \"Xavier\" method completely stalls the learning.\n\n\n\\section{Initialization In RDA}\\label{sec_ini}\n%In the original paper \\cite{xiao2010dual}, RDA requires the loss function to be convex, and $w_1=0$ as an initialization. \n%In general, CNN is not convex, neither is zero initialization of $w_1$ suitable since in this case most parameters' gradients will become zero, which makes the model nearly not trainable with Prox-SGD or RDA. Thus, non-zero initialization is a necessary condition in Algorithm \\ref{RDA}, we then prove in Theorem \\ref{Convergence_Modified_RDA} that the convergence rate for convex problem based on this modification is still $O(\\frac{1}{\\sqrt t})$ when $\\xi_t=O(\\sqrt{t})$.  \nIn the original paper \\cite{xiao2010dual}, RDA requires $w_1=0$ as an initialization. \nIn general, zero initialization for $w_1$ is not suitable, since in this case most weights' gradients will become zero, which makes the model almost not trainable with Prox-SGD or RDA. As a result, non-zero initialization is a necessary condition in RDA for CNN. This modification will not influence the convergence of the algorithm. As proven in Theorem \\ref{Convergence_Modified_RDA}, the convergence rate for convex problems based on this modification is still $O(\\frac{1}{\\sqrt t})$ when $\\beta_t=O(\\sqrt{t})$.  \n\\begin{theorem}\\label{Convergence_Modified_RDA}\n\tAssume the loss function $f(w,z)$ in the problem (\\ref{regularized opt problem}) is convex and there exists an optimal solution $w^{\\star}$ to the problem (\\ref{regularized opt problem}) with $\\Psi(w)=\\lambda\\|w\\|_1$ that satisfies $\\frac{1}{2}\\|w^{\\star}\\|_{2}^2\\leq D^2$ for some $D>0$. Let the sequences $\\{w_t\\}_{t\\geq 1}$ be generated by Algorithm \\ref{RDA}, and assume $\\|g_t\\|_{\\ast}\\leq G$ for some constant $G$. Then the expected cost $\\mathbf{E}\\phi(\\bar{w}_t)$ converges to $\\phi^{\\star}$ with rate $O(\\frac{1}{\\sqrt{t}})$\n\t$$\n\t\\mathbf{E}\\phi(\\bar{w}_t)-\\phi^{\\star}= O(\\frac{1}{\\sqrt{t}}),\n\t$$\n\\end{theorem}\nwith $\\bar w_t=\\frac{1}{t} \\sum_{\\tau=1}^{t} w_\\tau$ and $\\phi^{\\star}=\\phi(w^{\\star})$. \\\\\n%See Appendix A for the proof.\n%\\input{Appendix.tex}\nIn particular, when the activation function is ReLU, the weights in CNN are usually initialized with a uniform or a normal distribution \\cite{lecun2012efficient,glorot2010understanding,he2015delving}. For RDA, we propose to initialize the weights with a uniform distribution $\\mathcal{U}(-b,b)$, where \n\\begin{equation}\nb=\\sqrt{\\frac{s}{n}}.\n\\end{equation}\nFor a convolutional layer, $n=k^2 c$ is the size of the filter, where $c$ is the number of input channels and $k$ is the width of the filter. For a fully connected layer, $n$ is the dimension of the input vector. In both cases, $s$ is a scalar to increase the weights (e.g. \\cite{he2015delving} proposes to choose $s=6$). \n\n\\begin{table}[tb]\n\t\\caption{Different initialization scalars on ResNet-18, CIFAR-10 with RDA. This table shows TOP-1 and TOP-5 accuracy on validation dataset. All models are trained for 120 epochs.}\n\t\\label{table:ini_CIFAR10}\n\t\\vskip 0.15in\n\t\\begin{center}\n\t\t\\begin{small}\n%\t\t\t\\begin{sc}\n\t\t\t\t\\begin{tabular}{lccccr}\n\t\t\t\t\t\\hline\n\t\t\t\t\t$\\sqrt{s}$ &  TOP-1 &  TOP-5 &  Sparsity\\\\\n\t\t\t\t\t\\hline\n\t\t\t\t\t1, 2    &  10.00 &  50.00 &  N/A      \\\\\n\t\t\t\t\t3      &  85.52 &  99.24 &  0.98    \\\\\n\t\t\t\t\t4      &  86.72 &  99.45 &  0.97     \\\\\n\t\t\t\t\t5      &  90.03 &  99.44 &  0.95     \\\\\n\t\t\t\t\t%6      &  90.36 &  99.55 &  0.94     \\\\\n\t\t\t\t\t%7      &  90.07 &  99.55 &  0.91     \\\\\n\t\t\t\t\t10     &  90.67 &  89.50 &  0.94    \\\\\n\t\t\t\t\t%20     &  89.14 &  99.50 &  0.94    \\\\\n\t\t\t\t\t%50     &  91.42 &  99.66 &  0.71  \\\\\n\t\t\t\t\t100    &  \\bf 91.41 &  99.58 &  0.84 \\\\\n\t\t\t\t\t%200    &  90.57 &  99.56 &  0.73 \\\\\n\t\t\t\t\t1000   &  90.36 &  99.62 &  0.63 \\\\\n\t\t\t\t\t10000  &  71.80 &  97.94 &  0.34 \\\\\n\t\t\t\t\t20000  &  68.06 &  97.39 &  0.99 \\\\\n\t\t\t\t\t\\hline\n\t\t\t\t\\end{tabular}\n%\t\t\t\\end{sc}\n\t\t\\end{small}\n\t\\end{center}\t\t\n\\end{table}\n\n\\begin{table}[tb]\n\t\\caption{Different initialization scalars on ResNet-18, CIFAR-100 with RDA. \n\t\t%\t\t$\\lambda=10^{-8}$ and $\\gamma=0.1$. \n\t\tThis table shows TOP-1 and TOP-5 accuracy on validation dataset. All models are trained for 120 epochs.}\n\t\\label{table:ini_CIFAR100}\n\t\\vskip 0.15in\n\t\\begin{center}\n\t\t\\begin{small}\n%\t\t\t\\begin{sc}\n\t\t\t\t\\begin{tabular}{lccccr}\n\t\t\t\t\t\\hline\n\t\t\t\t\t$\\sqrt{s}$ &  TOP-1 & TOP-5  &  Sparsity \\\\ \n\t\t\t\t\t\\hline\n\t\t\t\t\t1      &  63.67 &  87.85 &  0.91 \\\\\n\t\t\t\t\t2      &  \\bf66.90 &  88.53 & 0.60  \\\\\n\t\t\t\t\t5      &  65.47 &  88.09 &  0.60 \\\\\n\t\t\t\t\t10     &  65.54 &  88.21 &  0.42 \\\\\n\t\t\t\t\t15     &  64.22 &  87.53 &  0.43 \\\\\n\t\t\t\t\t%\t\t\t20     &  67.78 &  89.65 &  0.50 \\\\\n\t\t\t\t\t25     &  63.06 &  88.10 &  0.50 \\\\\n\t\t\t\t\t30     &  62.75 &  86.80 &  0.42 \\\\\n\t\t\t\t\t50     &  64.48 &  87.14 &  0.38   \\\\\n\t\t\t\t\t100    &  60.00 &  86.14 &  0.36  \\\\\n\t\t\t\t\t\\hline\n\t\t\t\t\\end{tabular}\n%\t\t\t\\end{sc}\n\t\t\\end{small}\n\t\\end{center}\n\\end{table}\n\nSince $f$ is non-linear, the effect of initialization on $g_1$, the gradient of $w_1$, is not that clear. Assuming that $f$ is a linear function, then $g_1$ is scaled in the same way as $w_1$. Since with a thresholding (ignoring the initial learning rate $\\eta_1=1$), $g_1$ becomes the value of $w_2$, the initial value should not be too small, nor should it be too large because of the exploding gradient problem \\cite{pascanu2012understanding}, as shown in Table \\ref{table:ini_CIFAR10} and Table \\ref{table:ini_CIFAR100}. We listed some good choices for $s$ in Table \\ref{table:goods}.\n\n\n\\begin{table}[tb]\n\t\\caption{Suitable $\\sqrt{s}$ for different models and datasets. ImageNet represents ILSVRC2012.\n\t\t%\t\t\\blue{add the corresponded results, accuracy, sparsity? Can we make some summary for this choice of $s$?}\n\t}\n\t\\label{table:goods}\n\t\\vskip 0.15in\n\t\\begin{center}\n\t\t\\begin{small}\n%\t\t\t\\begin{sc}\n\t\t\t\t\\begin{tabular}{lcr}\n\t\t\t\t\t\\hline\n\t\t\t\t\tDataset & Model & $\\sqrt{s}$ \\\\\n\t\t\t\t\t%\t\t\t\t\t$\\sqrt{s}$ & ResNet-18 & VGG-16bn  &  VGG-19bn \\\\\n\t\t\t\t\t\\hline\n\t\t\t\t\t%\t\t\t\t\tCIFAR-10 &  10 & 20 & 10 \\\\\n\t\t\t\t\t%\t\t\t\t\tCIFAR-100 &  2 &  & 40 \\\\\n\t\t\t\t\t%\t\t\t\t\tILSVRC2012 & 2 & &  \\\\\n\t\t\t\t\t%\t\t\t\t\tModel & Dataset & $\\sqrt{s}$ \\\\\n\t\t\t\t\tCIFAR-10 & ResNet-18 & 10  \\\\\n\t\t\t\t\t& VGG-16bn & 20 \\\\\n\t\t\t\t\t& VGG-19bn & 10 \\\\\n\t\t\t\t\tCIFAR-100& ResNet-18 & 2  \\\\\n\t\t\t\t\t& VGG-16bn & 60 \\\\\n\t\t\t\t\t& VGG-19bn & 40 \\\\\n\t\t\t\t\tImageNet & ResNet-18 & 2 \\\\\n\t\t\t\t\t%\t\t\t\t\t& VGG-16bn &  \\\\\n\t\t\t\t\t%\t\t\t\t\t& VGG-19bn & \\\\\n\t\t\t\t\t\\hline\n\t\t\t\t\\end{tabular}\n%\t\t\t\\end{sc}\n\t\t\\end{small}\n\t\\end{center}\t\t\n\\end{table}", "meta": {"hexsha": "42f8fe9bc1da9e3fc300d9c8be03b5a798f1e9c3", "size": 9496, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/RDAini.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/RDAini.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/RDAini.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.9024390244, "max_line_length": 588, "alphanum_fraction": 0.6583824768, "num_tokens": 3289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801888, "lm_q2_score": 0.8887587920192298, "lm_q1q2_score": 0.8173403870564808}}
{"text": "\\documentclass{article}\n    % General document formatting\n    \\usepackage[margin=0.7in]{geometry}\n    \\usepackage[parfill]{parskip}\n    \\usepackage[utf8]{inputenc}\n    \\usepackage{amsmath}\n    \\usepackage{amssymb}\n    \\usepackage{tikz}\n    \\usepackage{fancyhdr}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\\rhead{Edgar Jacob Rivera Rios - A01184125}\n\n\\begin{document}\n\\section*{1.2.1}\n(a) Show that $A \\times (B \\cap C) = (A \\times B) \\cap (A \\times C)$\n\\begin{align*}\n    (x, y) \\in A \\times (B \\cap C) &\\implies x \\in A \\wedge y \\in (B \\cap C)\\\\\n    &\\implies x \\in A \\wedge y \\in B \\wedge y \\in C\\\\\n    (x, y) \\in (A \\times B) \\cap (A \\times C)&\\implies (x, y) \\in (A \\times B) \\wedge (x, y) \\in (A \\times C)\\\\\n    &\\implies x \\in A \\wedge y \\in B \\wedge x \\in A \\wedge y \\in C\\\\\n    &\\implies x \\in A \\wedge y \\in B \\wedge y \\in C\n\\end{align*}\n(b) Show that $A \\times (B \\cup C) = (A \\times B) \\cup (A \\times C)$\n\\begin{align*}\n    (x, y) \\in A \\times (B \\cup C) &\\implies x \\in A \\wedge y \\in (B \\cup C)\\\\\n    &\\implies x \\in A \\wedge (y \\in B \\vee y \\in C)\\\\\n    (x, y) \\in (A \\times B) \\cup (A \\times C)&\\implies (x, y) \\in (A \\times B) \\vee (x, y) \\in (A \\times C)\\\\\n    &\\implies (x \\in A \\wedge y \\in B) \\vee (x \\in A \\wedge y \\in C)\\\\\n    &\\implies x \\in A \\wedge (y \\in B \\wedge y \\in C)\n\\end{align*}\n\n\\section*{1.2.2}\n(a) Consider the relations $R=\\{ (1,7), (3,3), (13,11) \\}$ and $S=\\{ (1,1), (1,7), (3,11), (13,12), (15,1) \\}$ over the positive integers. Identify $dom(R\\cap S)$, $range(R\\cap S)$, $dom(R\\cup S)$, $range(R\\cup S)$\n\\begin{equation*}\n    dom(R\\cap S) = \\{ 1\\}\n\\end{equation*}\n\\begin{equation*}\n    range(R\\cap S) = \\{ 7\\}\n\\end{equation*}\n\\begin{equation*}\n    dom(R\\cup S) = \\{ 1, 3, 13, 15 \\}\n\\end{equation*}\n\\begin{equation*}\n    range(R\\cup S) = \\{ 7, 3, 11, 1, 12 \\}\n\\end{equation*}\n(b) In the same example, identify $join(R,S)$, $join(S,R)$, $S \\circ R$, $R\\circ S$, $R \\circ R$, $S \\circ S$.\n\\begin{equation*}\n    join(R,S) = \\{ (3,3,11) \\}\n\\end{equation*}\n\\begin{equation*}\n    join(S,R) = \\{ (1, 1, 7), (15, 1, 1) \\}\n\\end{equation*}\n\\begin{equation*}\n    S \\circ R = \\{ (1,7), (15, 1) \\}\n\\end{equation*}\n\\begin{equation*}\n    R \\circ S = \\{ (3, 11) \\}\n\\end{equation*}\n\\begin{equation*}\n    R \\circ R = \\{ (3, 3) \\}\n\\end{equation*}\n\\begin{equation*}\n    S \\circ S = \\{ (1, 1), (1, 7), (15, 1), (15, 7) \\}\n\\end{equation*}\n(c) In the same example, identify $R(X)$ and $S(X)$ for $X=\\{ 1, 3, 11 \\}$ and $X=\\emptyset$.\n\\begin{align*}\n    X&=\\{ 1, 3, 11 \\} & X&=\\emptyset\\\\\n    R(X)&=\\{(1,7), (3,3)\\} & R(X) &=\\emptyset\\\\\n    S(X)&=\\{ (1,1), (1,7), (3,11)\\} & S(X) &=\\emptyset\\\\\n\\end{align*}\n(d) Explain how to carry out composition by means of join and projection.\\\\\nComposition is the result of first applying the $join$ and thenn ussing the $projection$ to eliminate the common item\n\n\\section*{1.2.3}\n(a) Show that R is reflexive over $A$ iff $I_A \\subseteq R$. Here $I_A$ is the identity relation over $A$, defined in an exercise in Sect. 2.1.3.\n\\begin{align*}\n    R\\ is\\ reflexive\\ in\\ A &= \\forall x \\in A: xRx\\\\\n    I_A &= \\{(a,a): a \\in A\\}\\\\\n    I_A &\\subseteq R\\\\\n    \\forall a \\in A &\\implies \\exists (a, a) \\in I_A\\\\\n    I_A \\subseteq R &\\implies \\exists(a,a) \\in R\\\\\n    &\\implies R\\ is\\ reflexive\\ on\\ A\n\\end{align*}\n(b) Show that the converse of a relation $R$ that is reflexive over a set $A$ is also reflexive over $A$.\n\\begin{align*}\n    R\\ is\\ reflexive\\ over\\ A &= \\forall x \\in A: xRx\\\\\n    R^{-1} &= \\{(a, b): (b, a) \\in R\\}\\\\\n    R = \\{(a, b): a = b \\wedge\\ a, b \\in A\\} &\\implies (a, b) = (b, a)\\\\\n    &\\implies R^{-1} = R\\\\\n    &\\implies R^{-1}\\ is\\ reflexive\\ over\\ A\n\\end{align*}\n(c) Show that R is transitive iff $R \\circ R \\subseteq R$.\n\\begin{align*}\n    R\\ is\\ transitive &\\iff R \\circ R \\subseteq R\\\\\n    R \\circ R &= \\{(a, c): aRb \\wedge bRc\\}\\\\\n    R \\circ R \\subseteq R &\\implies (a, c) \\in R\\\\\n    &\\implies R(R(a,b), c) = R(a, R(b, c))\n\\end{align*}\n\\newpage\n\n\\section*{1.2.4}\n(a) Show that the following three conditions are equivalent: (i) $R$ is symmetric, (ii) $R \\subseteq R^{-1}$ , (iii) $R = R^{-1}$.\n\\begin{align*}\n    R\\ is\\ symetric \\equiv R &\\subseteq R^{-1} \\equiv R = R^{-1}\\\\\n    R\\ is\\ symetric &= \\forall(a,b) \\in R \\exists (b,a) \\in R\\\\\n    R \\subseteq R^{-1} &\\implies \\forall (a,b) \\in R, \\exists (a, b) \\in R^{-1}\\\\\n    &\\implies (a,b) = (b, a)\\\\\n    &\\implies R = R^{-1}\\\\\n    R = R^{-1}&\\implies \\forall (a,b) \\in R, \\exists (a, b) \\in R^{-1}= \\forall(a,b) \\in R \\exists (b,a) \\in R\\\\\n    &\\therefore R\\ is\\ symetric \\equiv R \\subseteq R^{-1} \\equiv R = R^{-1}\n\\end{align*}\n(b) Show that if $R$ is reflexive over $A$ and also transitive, then the relation $S$ defined by $(a,b) \\in S$ iff both $(a,b) \\in R$ and $(b,a) \\in R$ is an equivalence relation.\n\\begin{align*}\n    reflexive &= (a, a) \\in R \\forall a \\in A \\\\\n    S &= \\{(a, b):(a,b) \\in R \\wedge (b,a) \\in R \\}\\\\\n    (a,b) \\in R \\wedge (b,a) \\in R &\\implies a = b\\\\\n    &\\implies S\\ is\\ equivalent\n\\end{align*}\n(c) Enumerate all the partitions of $A=\\{ 1, 2, 3 \\}$ and draw a Hasse diagram for them under fineness.\n\\begin{align*}\n    Partition(A) =\\{&\\{\\{1\\}, \\{2\\}, \\{3\\}\\},\\\\\n    &\\{\\{1, 2\\},\\{3\\}\\},\\\\\n    &\\{\\{1, 3\\},\\{2\\}\\},\\\\\n    &\\{\\{2, 3\\},\\{1\\}\\},\\\\\n    &\\{\\{1, 2, 3\\}\\}\\}\n\\end{align*}\n\\begin{center}\n    \\begin{tikzpicture}[xscale=1.3, yscale=1]\n        \\node (bottom) at (0,0) {$\\{\\{1\\}, \\{2\\}, \\{3\\}\\}$};\n        \\node (middle) at (0, 1) {$\\{\\{1, 3\\},\\{2\\}\\}$};\n        \\node (middleleft) at (-2,1) {$\\{\\{1, 2\\},\\{3\\}\\}$};\n        \\node (middleright) at (2,1) {$\\{\\{1\\},\\{2, 3\\}\\}$};\n        \\node [above of=middle] (top)  {$\\{1, 2, 3\\}$};\n        \\draw (bottom) -- (middleleft) -- (top) -- (middle) -- (bottom) -- (middleright) -- (top);\n    \\end{tikzpicture}\n\\end{center}\n\n\\section*{1.2.5}\nLet $R$ be any transitive relation over a set $A$. Define $S$ over $A$ by putting $(a,b) \\in S$ iff either $a = b$ or both $(a,b) \\in R$ and $\\neg (b,a) \\in R$. Show that $S$ partially orders $A$.\n\\begin{align*}\n    Partial\\ order &= reflexive,\\ transitive\\ and\\ antisymmetric\\\\\n    reflexive &= (a, a) \\in R \\forall a \\in A \\\\\n    %transitive &= \\\\\n    antisymmetric &= (a,b) \\in R \\wedge (b,a) \\notin R\\\\\n    S &= \\{(a, b): a = b \\vee [(a,b) \\in R \\wedge (b,a) \\notin R ]\\}\\\\\n    \\{(a, b) : a = b\\} &\\implies S\\ is\\ reflexive\\\\\n    \\{(a, b) :(a,b) \\in R \\wedge (b,a) \\notin R\\} &\\implies S\\ is\\ transitive\\\\\n    &\\implies S\\ is\\ antisymmetric\n\\end{align*}\n\\end{document}", "meta": {"hexsha": "564586ac91f6953a48fe4c28dcf6b1e15096e362", "size": 6411, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/Homework1_2.tex", "max_stars_repo_name": "edjacob25/Applied-Maths", "max_stars_repo_head_hexsha": "0a0f8e5b88083a1b0ec85069efbf266b6a12c741", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Homework/Homework1_2.tex", "max_issues_repo_name": "edjacob25/Applied-Maths", "max_issues_repo_head_hexsha": "0a0f8e5b88083a1b0ec85069efbf266b6a12c741", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework/Homework1_2.tex", "max_forks_repo_name": "edjacob25/Applied-Maths", "max_forks_repo_head_hexsha": "0a0f8e5b88083a1b0ec85069efbf266b6a12c741", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.1776315789, "max_line_length": 214, "alphanum_fraction": 0.5379815941, "num_tokens": 2765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.9149009578933864, "lm_q1q2_score": 0.8172896286956193}}
{"text": "\n\\appendix\n\n\\section{Laplace's Equation}\n\nThe Laplacian operator, $\\Delta$, is defined for an $n$-dimensional function as the sum of its unmixed partial second derivatives (Equation~\\ref{eqn:LaplacianOperator}):\n\n\\begin{equation}\n\\label{eqn:LaplacianOperator}\n\\Delta f = \\nabla^2f = \\sum_{i=1}^n \\frac{\\delta^2f}{\\delta x_i^2}\n\\end{equation}\n\nIn the two-dimensional case, this takes the following familiar form (Equation~\\ref{eqn:2DLaplacianOperator}):\n\n\\begin{equation}\n\\label{eqn:2DLaplacianOperator}\n\\Delta f = \\frac{\\delta^2 f}{\\delta x^2} + \\frac{\\delta^2 f}{\\delta y^2}\n\\end{equation}\n\nIn the special case where $\\Delta f = 0$, this is known as Laplace's Equation. The discrete Laplacian may be approximated via simple second differences.  The one-dimensional second-difference operator $\\begin{matrix}[1 & -2 & 1]\\end{matrix}$ may be taken successively in each image dimension to produce a Laplacian image.  In the two-dimensional case, the discrete Laplacian operator is computed as follows:\n\n\\begin{equation}\n\\label{eqn:2DDiscreteLaplacianOperator}\n\\begin{matrix}\n0 $ 1 $ 0 \\\\\n1 $ -4 $ 1 \\\\\n0 $ 1 $ 0\n\\end{matrix}\n\\end{equation}\n\nIn ITK, the discrete Laplacian operator is provided in the \\doxygen{LaplacianOperator} class, and is applied to an image using the \\doxygen{LaplacianImageFilter} class.  Laplace's equation can be solved efficiently by means of the discrete cosine transform (DCT) \\cite{Ghiglia1998}.  In particular, the original image $f$ can be recovered by taking the forward DCT of the Laplacian image $\\Delta f$, applying a pixelwise modulation, and taking the reverse DCT on the result (Equation~\\ref{eqn:DCTPoisson}).  In this equation, $n$ is the dimension of the image, $S_n$ is the number of pixels across the image in direction $d$, and $i_n$ is the pixel index in direction $n$.\n\n\\begin{equation}\n\\label{eqn:DCTPoisson}\nf = DCT^{-1} \\left \\{\\frac{\\displaystyle DCT \\left \\{ \\Delta f \\right \\}}{\\displaystyle \\sum_{n=0}^{N-1} 2 \\cos \\left( \\frac{\\displaystyle \\pi i_n}{\\displaystyle S_n} \\right) -2N} \\right \\}\n\\end{equation}\n\nIt is possible to formulate the problem in such a way that it can be solved with either the fast Fourier transform (FFT), discrete sine transform (DST), or discrete cosine transform (DCT).  The specifics of each implementation differ primarily in the steps that must be undertaken to satisfy Neumann boundary conditions.  In order to be solved with the FFT, for instance, the Laplacian must be reflected to the left and upwards (Figure ~\\ref{fig:Reflection}).  The DCT (also known as the `even' or `real-to-real' transform), however, is performed on one half of an implicitly reflected matrix, obviating the reflection step.  Though this difference is likely negligible for an isolated 2D calculation, use of the DCT could significantly reduce memory and processing requirements when applied iteratively or to higher dimensional data.  For this reason, the DCT is prefered if available.\n\n\\begin{figure}[h]\n\\center\n\\scalebox{-1}[-1]{\\includegraphics[width=0.25\\textwidth]{images/appendix/cameraman.png}}\n\\hspace{-6px}\n\\scalebox{1}[-1]{\\includegraphics[width=0.25\\textwidth]{images/appendix/cameraman.png}} \\\\\n\\vspace{-2px}\n\\scalebox{-1}[1]{\\includegraphics[width=0.25\\textwidth]{images/appendix/cameraman.png}}\n\\hspace{-6px}\n\\scalebox{1}[1]{\\includegraphics[width=0.25\\textwidth]{images/appendix/cameraman.png}}\n\\itkcaption[Reflection]{The ``cameraman'' test image, reflected to the left and upwards to satisfy Neumann boundary conditions.}\n\\label{fig:Reflection}\n\\end{figure}\n\n\\section{Implementation and Usage}\n\n\\subsection{Discrete Cosine Transform}\n\nFFTW (the `Fastest Fourier Transform in the West' \\cite{Frigo2005}) is a library in the C programming language, which can be made available by building ITK with the CMake variable \\code{ITK\\_USE\\_FFTWF} or \\code{ITK\\_USE\\_FFTWD} (single and double precision floating point, respectively) to \\code{ON}.  FFTW provides a wide selection of efficient discrete transforms, including DCT types I--IV (corresponding to `\\code{kind}s' \\code{REDFT00}, \\code{REDFT10}, \\code{REDFT01}, and \\code{REDFT11}, respectively).  These plans differ practically from one another in terms of inverse transforms and normalization procedures (\\code{REDFT00} and \\code{REDFT11} are inverses of themselves, whereas \\code{REDFT10} and \\code{REDFT01} are inverses of each other).  In particular, \\code{REDFT10} and \\code{REDFT01} are known as `the' forward and reverse DCT, respectively.  A real-to-real plan is constructed according to the following function definition:\n\n\\small\n\\begin{verbatim}\nfftw_plan fftw_plan_r2r(int rank, const int *n, double *in, double *out,\n                             const fftw_r2r_kind *kind, unsigned flags);\n\\end{verbatim}\n\\normalsize\n\n\\code{int rank} refers to the image dimension; \\code{const int *n} to an array indicating the size in each dimension; \\code{double *in} and \\code{double *out} to input and output arrays allocated using \\code{fftw\\_malloc}, \\code{const fftw\\_r2r\\_kind *kind} to the type of transform that should be performed in each dimension, and \\code{unsigned flags} to instructions concerning numerical precision.  The \\code{itk::Image} buffers are assigned to the input and output arrays using the \\code{GetBufferPointer()} method.  Each element of the \\code{const fftw\\_r2r\\_kind} array is set to \\code{FFTW\\_REDFT01} in the case of the forward transform and \\code{FFTW\\_REDFT10} in the case of the inverse transform.  The transform direction can be specified at the level of the itk class using the \\code{TransformDirection()} method.  Because FFTW returns an unnormalized transform, the image is divided by \\code{numpix*pow(2, TInputImage::ImageDimension)} in the case of the inverse transform.\n\nThe provided class \\code{itk::DCTImageFilter}, which inherits from \\code{itk::ImageToImageFilter}, provides a simple, templeted interface to the \\code{REDFT01} and \\code{REDFT10} plans.  The following minimal example code demonstrates definition, instantiation, and usage of the class, and Figure~\\ref{fig:DCT} illustrates a simple low-pass DCT filtering example (source code provided).\\footnote{Note that all images have been linearly rescaled (except for transforms, which have been logarithmically rescaled) for visualization purposes.}\n\n\\small\n\\begin{verbatim}\ntypedef itk::DCTImageFilter< WorkImageType, WorkImageType > DCTType;\nDCTType::Pointer dct = DCTType::New();\ndct->SetInput( reader->GetOutput() );\ndct->SetTransformDirection( DCTType::Forward );\ndct->Update();\n\\end{verbatim}\n\\normalsize\n\n\\begin{figure}\n\\center\n\\includegraphics[width=0.24\\textwidth]{images/appendix/brain.png}\n\\includegraphics[width=0.24\\textwidth]{images/appendix/dct.png}\n\\includegraphics[width=0.24\\textwidth]{images/appendix/dctFiltered.png}\n\\includegraphics[width=0.24\\textwidth]{images/appendix/filtered.png}\n\\itkcaption[Reflection]{Simple demonstration of low-pass DCT filtering.  From left to right are the input image, the DCT transform, the masked transform, and the output image.}\n\\label{fig:DCT}\n\\end{figure}\n\n\\subsection{Poisson Solver}\n\nThe \\code{itk::DCTPoissonSolver} class transforms the input, applies a modulation, and reverse transforms back into the image domain, as described in Equation~\\ref{eqn:DCTPoisson}.  The following minimal example demonstrates definition, instantiation, and usage of the \\code{itk::DCTPoissonSolverImageFilter} class.\n\n\\small\n\\begin{verbatim}\ntypedef itk::DCTPoissonSolverImageFilter< WorkImageType, WorkImageType >   PoissonType;\nPoissonType::Pointer solver = PoissonType::New();\nsolver->SetInput( laplacian->GetOutput() );\nsolver->Update();\n\\end{verbatim}\n\\normalsize\n\n\\begin{figure}\n\\center\n\\includegraphics[width=0.32\\textwidth]{images/appendix/brain.png}\n\\includegraphics[width=0.32\\textwidth]{images/appendix/laplacian.png}\n\\includegraphics[width=0.32\\textwidth]{images/appendix/solution.png}\n\\itkcaption[Laplacian]{The original (left) and Laplacian (right) images for an axial CT slice through the brain.}\n\\label{fig:Laplacian}\n\\end{figure}\n\nFigure~\\ref{fig:Laplacian} shows an example of an image of the brain, its Laplacian, and the solution of the Laplacian.  In the rescaled image, the solution appears to match exactly the input image.  However, by plotting the vertical centerline of each image (Figure~\\ref{fig:Additive}), we see that the input and output differ by an additive constant of $\\sim123.7$, as is expected from any integration procedure.\n\n\\begin{figure}\n\\center\n\\includegraphics[width=0.8\\textwidth]{images/appendix/additive_constant.png}\n\\itkcaption[Additive]{Plot of grayscale intensities along the vertical centerline of the input and output images.  Note that the two curves differ by an additive constant.}\n\\label{fig:Additive}\n\\end{figure}", "meta": {"hexsha": "370bb574d4345aa193b9db2b864140260ce4a9e5", "size": 8744, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Document/includes/Appendix.tex", "max_stars_repo_name": "DVigneault/ITKPhaseSubmission", "max_stars_repo_head_hexsha": "4f52c134102139544a63d454501983f00c3ade67", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-07T03:59:18.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-07T03:59:18.000Z", "max_issues_repo_path": "Document/includes/Appendix.tex", "max_issues_repo_name": "DVigneault/ITKPhaseSubmission", "max_issues_repo_head_hexsha": "4f52c134102139544a63d454501983f00c3ade67", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Document/includes/Appendix.tex", "max_forks_repo_name": "DVigneault/ITKPhaseSubmission", "max_forks_repo_head_hexsha": "4f52c134102139544a63d454501983f00c3ade67", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.4789915966, "max_line_length": 985, "alphanum_fraction": 0.7748170174, "num_tokens": 2421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.8933093989533707, "lm_q1q2_score": 0.8172896159883382}}
{"text": "For the remainder, we will focus on distributions of the form \n\\[ \\pi(x)=\\mathcal{Z}^{-1}\\e^{-U(x)},\\]\nwhere \\(\\mathcal{Z}\\) is a normalising constant. Borrowing some terminology from physics, we call the function \\(U:\\R^d\\to\\R\\) the potential function. In statistical mechanics, this distribution is known as the Boltzmann distribution. The aim here is to use machinery from physics to solve the problem of sampling accurately. To do this we first must motivate the distribution's origin.\n\nConsider a particle in a potential well of shape \\(U\\). The equation of motion for such a particle is \\cite{Langevin1908}, \n\\begin{equation} \\dif X_t = -\\nabla U(X_t)\\dif t +\\sqrt{2}\\dif W_t. \\label{eq:ODLang}.\\end{equation}\nHere, \\(X_t\\) is the displacement of the particle from the origin at time \\(t\\), \\(W_t\\) is a \\(d\\)-dimensional Wiener process (Brownian motion) and \\(U:\\R^d \\to \\R\\) is the potential function. The form of interest here is the \\emph{overdamped} Langevin equation, in which the particle experiences no average acceleration, obtained as the high friction limit of full Langevin dynamics.\n\nFrom the form of the equation, it can be seen that the particle moves down the slope of the well, ``sliding'' towards the minimum energy state. As each particle moves randomly, it is natural to ask what is the average position of many particles in such a well? One would expect the average position to be the one that has lowest energy. To recast the question in statistical language, we ask what is the expected value of the random variable \\(X_t\\)? This is exactly the goal of MCMC given in Section \\ref{sec:intro}. In fact for the Langevin equation, we can give the probability of a particle being at any given displacement. This probability is given exactly by the measure \\(\\pi\\), the Boltzmann distribution. For a diffusion process such as Equation \\ref{eq:ODLang} this is called the \\emph{stationary distribution}\\footnote{Another common term is \\emph{invariant measure}}. To show that \\(\\pi\\) is indeed the stationary distribution we use the following lemma.\n\n\\begin{lemma}[\\cite{OttobreDiffProc}]\n\tFor a one-dimensional It\\^o diffusion\\footnote{That is \\(X_t\\) solves \\(\\dif X_t = \\mu(X_t)\\dif t +\\sigma^2(X_t)\\dif W_t\\)}, suppose \\(\\sigma^2(t,x)\\) is bounded. Suppose that the transition probabilities of \\(X_t\\) admit a density for every \\(t>0\\). Further assume that \\(\\mu(X_t),\\sigma^2(X_t) \\in C^2\\). Define the Fokker-Planck operator, \\(\\L^*\\), as\n\t\\[\\L^*:= -\\partial_x(\\mu(x)\\cdot)+\\frac{1}{2}\\partial^2_x(\\sigma^2(x)\\cdot).\\]\n\tThen a measure \\(\\pi\\) is invariant for the diffusion if and only if\n\t\\[\\L^*\\pi = 0\\]\n\\end{lemma}\nThe proof of this is omitted however it can be seen by forming the Fokker-Planck equation for the probability density of the diffusion. If a diffusion admits a unique stationary measure, then it is ergodic. This fact means one can apply Theorem \\eqref{thm:ergodic} and calculate expectations using Langevin dynamics. The proof that \\(\\pi\\) is the stationary measure of Equation \\eqref{eq:ODLang} is given only in the one dimensional case, however it is extendable to higher dimensions. For the Langevin equation, the Fokker-Planck operator is\n\n\\[\\L^* = \\partial_x(U'(x)\\cdot)+\\partial_{xx}\\cdot . \\]\nSo it remains to calculate \\(\\L^*\\pi\\).\n\\begin{align*}\n\\L^*\\pi &= \\pd{}{x}\\bigg\\lbrack U'(x)\\pi(x) + \\pd{}{x}\\pi(x)\\bigg\\rbrack\\\\\n\t\t&= \\pd{}{x}\\bigg\\lbrack U'(x)\\mathcal{Z}\\e^{-U(x)}+ \\left(-U'(x)\\mathcal{Z}\\e^{-U(x)}\\right)\\bigg\\rbrack\\\\\n\t\t&= \\pd{}{x}\\lbrack 0 \\rbrack\\\\\n\t\t&= 0\n\\end{align*}\nHence \\(\\pi\\) is indeed the invariant measure of \\eqref{eq:ODLang}. \\qed\n\\\\\n\\\\\nAlthough this shows that the Langevin equation has an invariant measure, the question of convergence to this measure remains unanswered. Roberts and Tweedie give the following restriction \\cite{RT96}.\n\\begin{theorem}[Theorem 2.1, \\cite{RT96}]\n\tLet \\(P^t_X(x,A) = \\P(X_t\\in A | X_0 =x_0)\\) and suppose that \\(\\grad U(x)\\) is continuously differentiable and that, for some \\(N,a,b < \\infty\\),\n\t\\[\\grad U(x)\\cdot x \\leq a|x|^2 + b, \\qquad |x|>N. \\]\n\tThen the measure \\(\\pi\\) is invariant for the Langevin diffusion \\(X\\). Moreover, for all \\(x \\in \\R^d \\) and Borel sets \\(A\\),\n\t\\[\\|P^t_X(x,\\cdot) - \\pi \\| = \\frac{1}{2}\\sup_A \\big|P^t_X(x,A)-\\pi(A)\\big| \\to 0\\]\n\n\\end{theorem}\n\n\\begin{figure}[ht]\n\t\\centering\n\t\t\\includegraphics[width=\\linewidth]{quadraticLD.pdf}\n\t\\caption{Simulating Langevin dynamics in one dimension with a quadratic potential \\(U(x)=x^2/2\\)}\n\t\\label{fig:quadLD}\n\\end{figure}\n\nThe problem of sampling from the high dimensional distribution has been reduced to being able to accurately simulate Langevin dynamics. This is not as simple as it sounds. To simulate the continuous process  \\eqref{eq:ODLang}, it must first be discretised. Doing so may not preserve the convergence to the invariant measure. The discretised process may not have the same stationary measure or it may not even exist. This means that the method used to discretise must be chosen carefully to ensure good convergence properties. The most natural way to discretise an SDE is to use the stochastic analogue of the (forward) Euler method used on ordinary differential equations, known as the Euler-Maruyama (EM) method. Doing so leads to the Unadjusted Langevin Algorithm (\\texttt{ULA}).\n\n\\subsection{The Unadjusted Langevin Algorithm}\nApplying the Euler-Maruyama method to Equation \\eqref{eq:ODLang} gives the following iterative scheme.\n\n\\[X_{n+1} = X_n -h \\nabla U(X_n) +\\sqrt{2h} Z_{n+1},\\qquad X_0= x_0 \\]\nHere the \\(Z_n \\) are i.i.d. standard normal random variables and \\(h\\) is the step size. This is equivalent to \\(X_{n+1} \\sim N(X_n - h\\grad U(X_n), 2h I_d )\\).\\footnote{\\(I_d\\) denotes the \\(d \\times d\\) identity matrix.} A simple example shows that this discretisation does not converge to \\(\\pi\\). Let \\(\\pi\\) be a standard Gaussian distribution, that is \\(U(x) = |x|^2/2 \\) and choose \\(h = 1\\). Then the update is given by\n\n\\begin{align*}\n\tX_{n+1} &\\sim N(X_n - \\grad U(X_n), 2)\\\\\n\t& \\sim  N(X_n - X_n, 2)\\\\\n\t& \\sim N(0,2) \\nsim \\pi .\n\\end{align*}\nSo the chain converges immediately, but to the wrong distribution. Let \\(\\pi^{\\text{ULA}}_{h} \\) denote the stationary distribution of \\texttt{ULA} with a stepsize \\(h\\). This is not the only issue that can occur. As well as not converging to the correct distribution, the discretised chain may not be  ergodic, even when the continuous diffusion is exponentially ergodic \\cite{RT96}. In particular, the algorithm misbehaves when the gradient of the potential is superlinear. That is,\n\\[\\liminf_{\\|x\\|\\to \\infty} \\frac{\\|\\grad U(x)\\|}{\\|x\\|} = +\\infty. \\]\nFigure \\ref{fig:ULAdiverge} illustrates this problem for a double well potential. To mitigate these issues there are two main approaches: taming the gradient and Metropolisation. A further third method involves using a different discretisation scheme.  Our main focus will be the former, although all three approaches will be discussed.\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.75\\textwidth]{Figures/ula_doublewell_divergence_step0_2_trace.png}\n    \\caption{Trace plot of the \\texttt{ULA} applied to a double well potential with \\(h=0.2\\) started from \\((0,0)\\). The algorithm gets progressively worse until it diverges to infinity.}\n    \\label{fig:ULAdiverge}\n\\end{figure}\n\\subsection{Metropolis Adjustment}\nBefore describing the Metropolis-adjusted Langevin algorithm \\texttt{MALA}, it is pertinent at this point to recall the random walk Metropolis-Hastings algorithm \\texttt{RWM }\\cite{Hastings70, Metropolis53}. This popular variant of the Metropolis-Hastings algorithm \\emph{proposes} values and then accepts/rejects them according to some probability \\(\\alpha\\).  So given \\(X_n\\), propose a candidate \\(Y_{n+1}\\) as\n\n\\[Y_{n+1} = X_n  + \\sqrt{2h} Z_{n+1}.\\]\nOnce again, \\(h\\) is the step size and \\(Z\\) is a normal random variable. Then, accept or reject this proposal using Metropolis rejection, that is with some probability\n\\[\\alpha(X_n,Y_{n+1}) = 1\\wedge \\frac{\\pi(Y_{n+1})q(Y_{n+1},X_n)}{\\pi(X_n)q(X_n,Y_{n+1})}.\\footnote{Here \\(t\\wedge s = \\min\\lbrace t,s\\rbrace.\\) }\\]\nHere \\(q(x,y)\\) is the transition probability, \\(\\P(Y_{n+1}=y | X_{n}=x)\\sim N(X_n, h^2)\\). This rejection step is key in creating a kernel that is reversible and thus invariant for the measure \\(\\pi\\). \\\\\n\n\n\\texttt{MALA} can be seen as another variant of the Metropolis-Hastings algorithm, using Langevin dynamics to propose new states as follows.\n\\[Y_{n+1} = X_n -h\\grad U(X_n) + \\sqrt{2h} Z_{n+1}\\]\nIt is perhaps better understood as \\texttt{ULA} but with an added Metropolis rejection step \\cite{RT96}. Adding this rejection step means the algorithm always has the correct invariant distribution, although convergence is still not guaranteed as the following theorem shows.\n\n\\begin{theorem}[Theroem 4.2, \\cite{RT96}]\n\tIf \\(\\pi\\) is bounded, and\n\t\t\\[\\liminf_{\\|x\\|\\to \\infty} \\frac{\\|\\grad U(x)\\|}{\\|x\\|} > \\frac{4}{h}\\]\n\tthen the \\texttt{MALA} chain is not exponentially ergodic. That is, there exists \\(R_x <\\infty, \\rho<1\\) such that for all \\(x\\in \\R^d\\),\n\t\\[\\|P^t_{\\tiny \\sc MALA}(x,\\cdot) - \\pi \\| \\leq R_x\\rho^t,\\]\n\twhere \\(P^t_{\\tiny \\sc MALA}\\) is the transition kernel of the \\texttt{MALA} chain.\n\\end{theorem}\nSo it can be seen that \\texttt{MALA} is not without its issues, and does not solve all the problems of \\texttt{ULA}. The concept of taming was introduced to try and reduce the magnitude of these problems.\n\\begin{figure}[H]\n\\centering\n  \\begin{minipage}[b]{0.49\\textwidth}\n  \\centering\n    \\includegraphics[width=\\textwidth]{Figures/tula_tmala_step_1.png}\n  \\end{minipage} %\n  \\begin{minipage}[b]{0.49\\textwidth}\n  \\centering\n    \\includegraphics[width=\\textwidth]{Figures/tula_tmala_step_10.png}\n  \\end{minipage}\n   \\caption{\\textbf{Trade-off between rejection-based algorithms and \\texttt{tULA} for large step-sizes} ($h = 1$ on the left and $h = 10$ on the right, distribution is Gaussian with covariance matrix $\\text{diag}(1.0, 0.1)$). With increasing step size, even \\texttt{tULA} starts to suffer. Rejection-based algorithms resolve the issue, however, their acceptance rate drops very low ($\\approx 0.2$ on the left and $\\approx 0.03$ on the right). }\n\\end{figure}\n\n\\subsection{Taming the Gradient}\nWe have seen that both \\texttt{ULA} and \\texttt{MALA} run into issues when the gradient of the potential is superlinear. Given an SDE such as \\eqref{eq:ODLang}, taming adjusts the drift coefficient in such a way that preserves the invariant measure and improves speed of convergence \\cite{Brosse18tULA,RT96,Sabanis13}. To do this, a family of drift functions \\((G_h)_{h>0}, \\ G_h:\\R^d \\to \\R^d\\) are introduced. The SDE to be discretised is thus\n\t\\begin{equation*} \\dif X_t = -G_h(X_t)\\dif t +\\sqrt{2}\\dif W_t. \\end{equation*}\nApplying the Euler-Maruyama method gives the following Markov chain\n\t\\[X_{k+1} =X_k-hG_h(X_k)+\\sqrt{2h}Z_{k+1},\\qquad  X_0=x_0.\\]\nTo preserve the invariant measure, some restrictions must be placed on \\((G_h)_{h>0}\\), namely that they are `close' to \\(\\grad U\\) ({\\bf A1}) while {\\bf A2} ensures ergodicity is preserved and improves stability \\cite{Brosse18tULA}. \n\n\\begin{enumerate}[label={\\bf A{\\arabic*}}]\n\t\\item  For all \\(h>0, G_h\\) is continuous. There exist \\(\\alpha\\geq 0, C_{\\alpha}<+\\infty\\) such that for all \\(h >0 \\) and \\(x \\in \\R^d\\),\n\t\t\\[\\|G_h(x)-\\grad U(x)\\| \\leq hC_{\\alpha}(1+\\|x\\|^{\\alpha}).\\]\\label{A1}\n\t\\item For all \\(h>0\\),\n\t\t\\[ \\liminf_{\\|x\\|\\to \\infty} \\bigg\\lbrack \\bigg\\langle \\frac{x}{\\|x\\|}, G_h(x)\\bigg\\rangle - \\frac{h}{2\\|x\\|}\\|G_h(x)\\|^2\\bigg\\rbrack >0\\]\\label{A2}\n\\end{enumerate}\nHere we consider two specific taming functions,\n \\begin{align*}\n T_h(x) = \\frac{\\grad U(x)}{1+h\\|\\grad U(x)\\|}, &&  T^{\\text{\\sc \\tiny RT}}_h = \\frac{\\grad U(x)}{1\\vee h\\|\\grad U(x)\\|}.\n \\end{align*}\nBrosse et al. introduced and studied \\(T_h\\) whilst Roberts \\& Tweedie suggested \\(T^{\\text{\\sc \\tiny RT}}_h\\), later analysed by Bou-Rabee \\& Vanden-Eijnden \\cite{BV10MALTA,Brosse18tULA,RT96}. Both taming functions retain the direction of the gradient, only reducing the magnitude of its effect. The latter is the usual \\texttt{ULA} until the gradient gets large enough \\((\\|\\grad U(x)\\|> 1/h)\\), at which point it begins normalising. In contrast, the first will always tame, regardless of size of the gradient. However for the scaling to have noticeable effect, the gradient must be \\(\\mathcal{O}(h^{-1})\\).\nWhen \\(T_h\\) is the taming function, the algorithm will be referred to as \\texttt{tULA}, the tamed unadjusted Langevin algorithm. When the second is applied, it will be called \\texttt{MALTA}, the Metropolis adjusted Langevin truncated algorithm after \\cite{RT96}. Any tamed algorithm using \\(T_h\\) will be prefixed with a lowercase \\texttt{t}. For a proof that \\(T_h\\) satisfies \\ref{A1} and \\ref{A2}, see \\cite[Lemma~2]{Brosse18tULA}.\n\\\\\nWhen the problem is ill-conditioned, taming the gradient does not help. \n\\subsubsection{Coordinatewise Taming}\nSo far, the gradient has only been tamed globally. This means that the information the gradient gives is reduced in dimensions where it is not causing divergence. A solution to this is to use coordinatewise taming with the following drift.\n  \\[T^c_{h}(x) =\\left(\\frac{\\partial_i U(x)}{1+h|\\partial_i U(x)|}\\right)_{i=\\lbrace 1, \\dots, d\\rbrace} \\]\nThis allows each dimension to be scaled individually. Any algorithm with coordinate-wise taming will be suffixed with a lowercase \\texttt{c}.\n\n\\subsubsection{Stiff Problems}\\label{sec:stiff}\nTo illustrate the effectiveness of coordinatewise taming, consider an ill-conditioned Gaussian distribution with mean \\(\\mu,\\) covariance matrix \\(\\Sigma\\) as follows.\n\\begin{align*}\n    \\mu &= \\mathbf{0}, && \\Sigma = \\begin{bmatrix}  1 & 0 \\\\ 0 & 0.0001 \\end{bmatrix}\n\\end{align*}\nFigure \\ref{fig:stiffULA} shows the samples generated by the tamed unadjusted and coordinatewise tamed unadjusted Langevin algorithms (\\texttt{tULA} and \\texttt{tULAc}, respectively) applied to this problem. It can be seen that \\texttt{tULA} overestimates the width of the distribution in both dimensions by a large margin. This is because the slope fo the potential well is relatively shallow in this direction, meaning that the strong taming generated by the gradient in the other direction reduces this shallow well to almost flat. This means that the particle does not `slide down' as quickly back to the minimum. Contrast this with \\texttt{tULAc} which provides a range of samples much closer to the true distribution in one dimension. The problem still remains in the other dimension, however this is almost unavoidable with an explicit scheme.  \n\\begin{figure}[H]\n\\centering\n  \\begin{minipage}[b]{0.49\\textwidth}\n  \\centering\n    \\includegraphics[width=\\textwidth]{Figures/ic_gaussian_tula.png}\n  \\end{minipage} %\n  \\begin{minipage}[b]{0.49\\textwidth}\n  \\centering\n    \\includegraphics[width=\\textwidth]{Figures/ic_gaussian_tulac.png}\n  \\end{minipage}\n   \\caption{\\textbf{Overestimation of Global Taming:} \\texttt{tULA} (left) generates samples that are greatly overdispersed in both dimensions. Contrast with \\texttt{tULAc} (right) which gives a much tighter spread over one dimension. In both plots, orange shows samples drawn from the \\texttt{RWM} algorithm as reference for `true' samples.}\n   \\label{fig:stiffULA}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n  \\begin{minipage}[b]{0.49\\textwidth}\n  \\centering\n    \\includegraphics[width=\\textwidth]{Figures/transparentBoth.png}\n  \\end{minipage} %\n   \\caption{\\textbf{Coordinatewise Improvement:} A more visible comparison of the improvement coordinatewise taming offers over global taming.}\n   \\label{fig:stifftULAc}\n\\end{figure}\n\n\n\n\n\\subsection{Discretise Differently}\nAn alternative approach is to use a different discretisation of the SDE \\eqref{eq:ODLang}, which we consider in this section. The first is an extension of the Euler method \\cite{Sabanis18tHOLA}, while the latter uses a non-Markovian scheme developed for use in molecular dynamics \\cite{LM12}.\n\\subsubsection{Higher Order Langevin Algorithm}\nAs in the ordinary case, the Euler-Maruyama method is not the only way of discretising an SDE. One can also take a higher order expansion, analogous to the Runge-Kutta method in ODE theory, known as the order 1.5 Wagner-Platen expansion\\footnote{Or the stochastic Runge-Kutta method \\cite{Schaffter10numericalintegration}}. For a one dimensional Langevin diffusion \\eqref{eq:ODLang}, this is \n\\[X_{n+1} = X_n -hU'(X_n)+\\sqrt{2h}Z_n -\\sqrt{2} U''(X_n) \\tilde{Z}_n +\\frac{ h^2 }{2}\\bigg\\lbrack U'(X_n)U''(X_n)-U'''(X_n)\\bigg\\rbrack.  \\]\nHere, \\(\\tilde{Z}_n\\) is defined as\n\\[  \\tilde{Z}_n = \\int_{t_n}^{t_{n+1}} \\int_{t_n}^s \\dif W_r \\dif s. \\]\nThis is a Gaussian random variable with mean \\(0\\) and variance \\(\\frac{1}{3}h^3 \\). Extending this to \\(d\\)-dimensions and applying to the Langevin SDE \\eqref{eq:ODLang} and taming as above gives the following iterative scheme. The untamed version is the same, but with all subscripts removed. \n\\[X_{n+1} = X_n + \\mu_{h}(X_n)h +\\sigma_{h}(X_n)\\sqrt{h}Z_{n+1},\\]\nwhere\n\\[\\mu_{h}(x) = -\\grad U_{h}(x) +\\frac{h}{2}\\left( \\left( \\grad^2U\\grad U\\right)_{h}(x) - \\vec{\\Delta}(\\grad U)_{h}(x)\\right) ,\\]\nand \\(\\sigma_{h}(x) = \\text{diag}\\left(\\left( \\sigma_{h}^{(k)}(x)\\right)_{k\\in \\lbrace 1,\\dots,d\\rbrace}\\right)\\) with,\n\\[\\sigma_{h}^{(k)}(x) = \\sqrt{2+\\frac{2h^2}{3}\\sum_{j=1}^d |\\grad^2 U_{h}^{(k,j)}(x)|^2 - 2h \\grad^2 U_{h}^{(k,k)}(x)}.\\]\nThe subscript \\(h\\) indicates a taming of the variable has occurred as follows. For any \\(x\\in \\R^d\\),\n\\begin{align*}\n    \\grad U_h(x) &=\\frac{\\grad U(x)}{(1+h^{3/2}|\\grad U(x)|^{3/2})^{2/3}}\\, , && \\grad^2U_h(x) = \\frac{\\grad^2 U(x)}{1+h|\\grad^2 U(x)|} ,\\\\\n    (\\grad U\\grad^2U)_h(x) =&\\frac{\\grad^2U(x)\\grad U(x)}{1+h|x||\\grad^2U(x)||\\grad U(x)|}\\, , && \\vec{\\Delta}(\\grad U)_h(x) = \\frac{\\vec{\\Delta}(\\grad U)(x)}{1+h^{1/2}|x||\\vec{\\Delta}(\\grad U)(x)|}.\n\\end{align*}\nLike in the classical case, the aim here is to improve the rate of convergence by using a more accurate discretisation of the underlying diffusion.\n\n\\subsubsection{Leimkuhler-Matthews Method}\nThe Leimkuhler-Matthews method was developed in \\cite{LM12} and cleverly exploits the link between the sampling problem and molecular dynamics. The scheme they developed is as follows:\n\\begin{equation} X_{n+1} = X_n - h \\grad U (X_n) +\\sqrt{\\frac{h}{2}} (Z_n+Z_{n+1}) \\label{eq:LM} \\end{equation}\n\nNote that this method is non-Markovian as it incorporates the noise term from the previous iteration. At first glance it appears that this is almost identical to the standard EM scheme, however the slight modification drastically improves convergence.  It is derived by considering both positions and momenta in Langevin dynamics (as opposed to the overdamped equation we have considered thus far which neglects momenta).\n\n\\begin{align} \\dif X_t = P_t \\dif t, && \\dif P_t = \\lbrack -\\grad U(X_t) - \\gamma P_t \\rbrack \\dif t + \\sqrt{2} \\dif W_t \\label{eq:LMLang} \\end{align}\n\nHere, \\(\\gamma\\) is the friction coefficient. It does no appear in the overdamped Langevin equation as it is the high friction limit of the above system.  Equation \\eqref{eq:LMLang} can be seen as a combination of an Ornstein-Uhlenbeck process and Hamiltonian dynamics. Splitting the system in this way allows the exact solution of each part in each time step.\n\n\\[ \\dif \\begin{bmatrix} X_t\\\\P_t \\end{bmatrix} = \\underbrace{\\begin{bmatrix} P_t \\\\ 0 \\end{bmatrix}}_{\\text{A}} \\dif t + \\underbrace{\\begin{bmatrix}  0\\\\-\\grad U \\end{bmatrix}}_{\\text{B}} \\dif t + \\underbrace{\\begin{bmatrix} 0\\\\ -\\gamma P_t \\dif t + \\dif W_t \\end{bmatrix}}_{\\text{O}} \\]\n\nThe Hamiltonian dynamics have been split further in to A and B.  As well as solving these sections separately at each time step, it is also possible to do fractions of a time step for each term. If we solve in the order BAOAB, that is, half a time step each of B and A before a full time step of the OU process before solving the rest of A and B, we recover Equation \\eqref{eq:LM} upon taking the high friction limit. Despite the dependence of iterates, the noise quickly decorrelates. Let \\(R_n = (Z_n+Z_{n+1})/\\sqrt{2}\\). Then,\n\n\\begin{align*}\n    \\langle R_n,R_n\\rangle  &= \\frac{1}{2} \\left( \\langle Z_{n+1},Z_{n+1}\\rangle +\\langle Z_{n},Z_{n}\\rangle\\right) =1\\\\\n    \\langle R_n,R_n\\rangle = \\langle Z_n,Z_n\\rangle = \\frac{1}{2}\\\\\n    \\langle R_n,R_{n-k} \\rangle &= 0,   \\quad k=2,3,\\dots \n\\end{align*}\n\n\n\\subsection{Visualization}\nA demonstration of the above methods has been implemented using the visualization library of \\cite{rogozhnikov2016hmc}\\footnote{With kind permission of Alex Rogozhnikov, \\url{https://arogozhnikov.github.io/about/}.}. The visualization dynamically follows the trace of a chosen method applied to a chosen two-dimensional distribution. Distributions of various qualitative properties are available. This can be found at the following \\textsc{url}: \\\\\n\\\\\n   \\centerline{ \\url{http://goatleaps.xyz/assets/ULA/ULA.html}}\n\\\\\n\\begin{figure}[H]\n\\centering\n  \\begin{minipage}[b]{0.8\\textwidth}\n  \\centering\n    \\includegraphics[width=0.8\\textwidth]{Figures/ulavis.PNG}\n    \\caption{Screenshot from the visualization;  \\texttt{tULAc} applied to a Gaussian mixture distribution.}\n  \\end{minipage}\n\\end{figure}\n\n", "meta": {"hexsha": "f2d5fbc4d446b2551179652c3670ee103a0f8b41", "size": 21255, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WriteUp/algotheory.tex", "max_stars_repo_name": "Tom271/LangevinMC", "max_stars_repo_head_hexsha": "ed36a17ce9b7d1e39097aeaf5b92f0fa286d5489", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2019-02-07T12:51:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T13:35:13.000Z", "max_issues_repo_path": "WriteUp/algotheory.tex", "max_issues_repo_name": "swyoon/LangevinMC", "max_issues_repo_head_hexsha": "ed36a17ce9b7d1e39097aeaf5b92f0fa286d5489", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WriteUp/algotheory.tex", "max_forks_repo_name": "swyoon/LangevinMC", "max_forks_repo_head_hexsha": "ed36a17ce9b7d1e39097aeaf5b92f0fa286d5489", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-19T17:44:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-19T17:44:19.000Z", "avg_line_length": 98.4027777778, "max_line_length": 966, "alphanum_fraction": 0.7254763585, "num_tokens": 6521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.9032941982430048, "lm_q1q2_score": 0.8171655751498906}}
{"text": "\n\\subsection{Higher-order tensors}\n\nWe can create higher order tensors products. For example\n\n\\(V\\otimes V \\otimes V\\otimes V^* \\otimes V^*\\)\n\nWe write elements of these as:\n\n\\(T_{j_1,...,j_q}^{i_1,...,i_p}\\)\n\nWe can map from matrix to matrix etc higher dimensional\n\nMatrix has \\(A\\): \\(a_{ij}\\).\n\nTensor can have \\(T\\): \\(t_{ijk}\\) for example\n\n\\(0\\) rank tensor: scalar\n\n\\(1\\) rank tensor: vector\n\n\\(2\\) rank tensor: matrix\n\npage on covariance and contravariance and type \\((p,q)\\)\n\n", "meta": {"hexsha": "5feaf39c4e07d449e284a35a174fd014c1cdfe19", "size": 485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/tensors/04-01-higherOrder.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/tensors/04-01-higherOrder.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/tensors/04-01-higherOrder.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.6538461538, "max_line_length": 56, "alphanum_fraction": 0.6680412371, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9591542829224747, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.817154186066522}}
{"text": "\\section{Similarity}\n\nWe begin this section by recalling the definition  of similar matrices.\nRecall that if $A,B$ are two $n\\times n$-matrices, then they are \\textbf{similar}\\index{similar matrices}\nif and only if there exists an invertible matrix $P$\nsuch that\n\\begin{equation*}\nA=P^{-1}BP\n\\end{equation*}\n\nIn this case we write $A\\similar B$. The concept of similarity is an example of an \\textbf{equivalence relation}\\index{equivalence relation}.\n\n\\begin{lemma}{Similarity is an equivalence relation}{similarity-equivalence}\nSimilarity is an equivalence relation, i.e. for $n \\times n$-matrices $A,B$, and $C$,\n\\begin{enumerate}\n\\item $A \\similar A$ (reflexive)\n\\item If $A \\similar B$, then $B \\similar A$ (symmetric)\n\\item If $A \\similar B$ and $B \\similar C$, then $A \\similar C$ (transitive)\n\\end{enumerate}\n\\end{lemma}\n\n\\begin{proof}\nIt is clear that $A\\similar A$, taking $P=I$.\n\nNow, if $A\\similar B$, then for some $P$ invertible,\n\\begin{equation*}\nA=P^{-1}BP\n\\end{equation*}\nand so\n\\begin{equation*}\nPAP^{-1}=B\n\\end{equation*}\nBut then\n\\begin{equation*}\n(P^{-1}) ^{-1}AP^{-1}=B\n\\end{equation*}\nwhich shows that $B\\similar A$.\n\nNow suppose $A\\similar B$ and $B\\similar C$. Then there exist invertible matrices\n$P,Q$ such that\n\\begin{equation*}\nA=P^{-1}BP,\\ B=Q^{-1}CQ\n\\end{equation*}\nThen,\n\\begin{equation*}\nA=P^{-1} (Q^{-1}CQ)P=(QP) ^{-1}C(QP)\n\\end{equation*}\nshowing that $A$ is similar to $C$.\n\\end{proof}\n\nAnother important concept necessary to this section is the trace of a matrix. Consider the definition.\n\n\\begin{definition}{Trace of a matrix}{matrix-trace}\n\\index{trace of a matrix}%\nIf $A=[a_{ij}]$ is an $n\\times n$-matrix, then the\ntrace of $A$ is\n\\[ \\tr(A) = \\sum_{i=1}^n a_{ii}.\\]\n\\end{definition}\n\nIn words, the trace of a matrix is the sum of the entries on the main diagonal.\n\n\\begin{lemma}{Properties of trace}{trace-properties}\nFor $n\\times n$-matrices $A$ and $B$, and any $k\\in\\R$,\n\\begin{enumerate}\n\\item $\\tr(A+B)=\\tr(A) + \\tr(B)$\n\\item $\\tr(kA)=k\\cdot\\tr(A)$\n\\item $\\tr(AB)=\\tr(BA)$\n\\end{enumerate}\n\\end{lemma}\n\nThe following theorem includes a reference to the characteristic polynomial of a matrix. Recall that for any $n \\times n$-matrix $A$, the characteristic polynomial of $A$ is $c_A(x)=\\det(xI-A)$.\n\n\\begin{theorem}{Properties of similar matrices}{properties-similar}\nIf $A$ and $B$ are $n\\times n$-matrices and $A\\similar B$, then\n\\begin{enumerate}\n\\item $\\det(A) = \\det(B)$\n\\item $\\rank(A) = \\rank(B)$\n\\item $\\tr(A)= \\tr(B)$\n\\item $c_A(x)=c_B(x)$\n\\item $A$ and $B$ have the same eigenvalues\n\\end{enumerate}\n\\end{theorem}\n\n", "meta": {"hexsha": "5e16abce9f8cb245cdb0db22d0959b30322742ce", "size": 2568, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryDiagonalizationSimilarity.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/spectraltheoryDiagonalizationSimilarity.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/spectraltheoryDiagonalizationSimilarity.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 30.5714285714, "max_line_length": 194, "alphanum_fraction": 0.6911993769, "num_tokens": 871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384595, "lm_q2_score": 0.905989819114262, "lm_q1q2_score": 0.8171309577498114}}
{"text": "% !TEX root = Main.tex\n\\section{K-Means}\n\\textbf{Target:} $\\min_{\\mathbf{U}, \\mathbf{Z}} J(\\mathbf{U}, \\mathbf{Z}) = \\|\\mathbf{X} - \\mathbf{U} \\mathbf{Z}\\|_F^2$\\\\\n$= \\sum_{n=1}^N \\sum_{k=1}^K \\mathbf{z}_{k,n} \\|\\mathbf{x}_n - \\mathbf{u}_k\\|_2^2$\\\\\n1. \\textbf{Initiate:} choose $K$ centroids $\\mathbf{U} = [\\mathbf{u}_1, \\ldots, \\mathbf{u}_K]$\\\\\n2. \\textbf{Assign:} data points to clusters. $k^\\star(\\mathbf{x}_n) = \\argmin_k \\{ \\|\\mathbf{x}_n - \\mathbf{u}_k\\|_2 \\}$ returns cluster $k^\\star$, whose centroid $\\mathbf{u}_{k^\\star}$ is closest to data point $\\mathbf{x}_n$. Set $\\mathbf{z}_{k^\\star,n} = 1$, and for $ l \\neq k^\\star~ \\mathbf{z}_{l,n}=0$.\\\\\n3. \\textbf{Update} centroids: $\\mathbf{u}_k = \\frac{\\sum_{n=1}^N z_{k,n} \\mathbf{x}_n}{\\sum_{n=1}^N z_{k,n}}$.\\\\\n4. Repeat from step 2, stops if $\\|\\mathbf{Z} - \\mathbf{Z}^\\text{new}\\|_0 = \\|\\mathbf{Z} - \\mathbf{Z}^\\text{new}\\|^2_F = 0$.\\\\\nComputational cost: $O(k\\cdot n \\cdot d)$\n\n\\subsection{K-Means++}\nInitialize cluster centers ``most far apart'' based on data points. $D(x)$ shortest distance from data point to closest, already chosen center.\\\\\n1. Set center $c_1$, chosen uniformly at random from $\\mathcal{X}$.\\\\\n2. Assign new center $c_i$, choosing $x \\in \\mathcal{X}$ with $p = \\tfrac{D(x)^2}{\\sum_{x \\in \\mathcal{X}} D(x)^2}$.\\\\\n3. Repeat 2 until $i = k$ for $k$ centers.\\\\\n4. Continue with K-Means.", "meta": {"hexsha": "a816101f4de19988c3671bcdbbb64fedea805efb", "size": 1366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "KMeans.tex", "max_stars_repo_name": "hlynurf/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "41b60db531665c3c33fe2103d942cfe8653bb2d4", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-07-31T11:12:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-02T09:35:54.000Z", "max_issues_repo_path": "KMeans.tex", "max_issues_repo_name": "hlynurf/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "41b60db531665c3c33fe2103d942cfe8653bb2d4", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "KMeans.tex", "max_forks_repo_name": "hlynurf/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "41b60db531665c3c33fe2103d942cfe8653bb2d4", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-07-19T14:14:46.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-05T13:50:06.000Z", "avg_line_length": 85.375, "max_line_length": 309, "alphanum_fraction": 0.6229868228, "num_tokens": 579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.952574129515172, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.817087707668579}}
{"text": "If you haven't downloaded and unzipped \\href{https://libaoj.in/courses/2021f/MATH3341/zip/Math.3341.zip}{\\texttt{Math.3341.zip}}. Download and unzip it under \\verb|H:| (H Drive if you are working on the Remote Lab). Change the current working directory by typing \\verb|cd H:\\Math.3341\\Math.3341.Lab.06| in the Command Window, and type \\verb|edit lab_06_script| in the Command Window to edit \\verb|lab_06_script.m|.\n\n%---------------------------------------------\n\\section{Solve a System with LU Decomposition}\n%---------------------------------------------\n\\label{sec:lu}\n\\begin{enumerate}[(a)]\n\\item Define matrix \\verb|A| and vector \\verb|b| as \\eqref{eq:ls}.\n  \\begin{equation}\n  \\label{eq:ls}\n  \\underbrace{\n  \\begin{bmatrix}\n    7 & -26 &  45 & -47 \\\\\n    1 &   2 &   3 &   4 \\\\\n    2 & -11 & -12 & -13 \\\\\n    4 & -17 &  30 &  35 \\\\\n  \\end{bmatrix}}_{A}\n  \\underbrace{\n  \\begin{bmatrix}\n    x_1 \\\\\n    x_2 \\\\\n    x_3 \\\\\n    x_4 \\\\\n  \\end{bmatrix}}_{\\mathbf{x}}\n  =\n  \\underbrace{\n  \\begin{bmatrix}\n     -98 \\\\\n      30 \\\\\n    -108 \\\\\n     200 \\\\\n  \\end{bmatrix}}_{\\mathbf{b}}\n  \\end{equation}\n\\item Calculate the LU decomposition \\verb|L|, \\verb|U| of the matrix \\verb|A|.\n\\item \\label{enu:lz} Solve the following system \\eqref{eq:lz} and store the solution to \\verb|z|.\n  \\begin{equation}\n  \\label{eq:lz}\n  L \\mathbf{z} = \\mathbf{b}.\n  \\end{equation}\n\\item \\label{enu:ux} Then solve the following system \\eqref{eq:ux} and store the solution to \\verb|x|.\n    \\begin{equation}\n    \\label{eq:ux}\n    U \\mathbf{x} = \\mathbf{z}.\n    \\end{equation}\n\\item Check your solution by calculating the norm of the residual $\\|A\\mathbf{x} - \\mathbf{b}\\|_2$ and store the result to \\verb|res|.\n\\end{enumerate}\n%---------------------------------------------\n\\section{Varying the Vector $\\mathbf{b}$}\n%---------------------------------------------\nSuppose we want to solve the system for each integer value of $m$ in between $m = 0$ and $m = 20$. This time use the LU decomposition of the system matrix; perform the decomposition only once and use the lower and upper triangular factors repeatedly to find each successive solution. Then generate a table (Table \\ref{tab:solution}) and a plot (Figure \\ref{fig:solution}) of the solution versus the integer $m$.\n\\begin{equation}\n  \\label{eq:sys}\n  \\begin{cases}\n    3 x + y + z = m \\\\\n    x - 5 y + 2 z = 5 \\\\\n    2 x + y + 5 z = 10 \\\\\n  \\end{cases}\n\\end{equation}\nTo do this you'll follow the steps below:\n\\begin{enumerate}[(a)]\n\\item Define coefficient matrix \\verb|A| given in \\eqref{eq:sys}, and get the LU decomposition \\verb|L|, \\verb|U| of the matrix \\verb|A|.\n\\item Define a vector \\verb|m| which ranges from $0$ to $20$ with step size $1$.\n\\item Then create a for-loop, of which the loop iterator \\verb|i| starts from \\verb|1| to \\verb|length(m)|. In the body of the loop, define a column vector \\verb|b| as the right-hand side of \\eqref{eq:sys}, where $m$ should be the \\verb|i|th component of \\verb|m|. Then repeat \\eqref{enu:lz} and \\eqref{enu:ux} in Part \\ref{sec:lu}. Store the solution \\verb|x| to the \\verb|i|th row of \\verb|X|.\n\\item Format the output of \\verb|m| and \\verb|X| to a file called \\verb|solution.tex| as you did in Part 3 of Lab 05:\n  \\begin{enumerate}[(i)]\n    \\item Use \\verb|fprintf| to print out the setup for the \\emph{table} and \\emph{tabular} environments. The first column of the table is centered while the rest three columns are right-justified in \\LaTeX{}.\n    \\item Between \\verb|\\toprule| and \\verb|\\midrule|, use \\verb|fprintf| to print out the heading of the table. The column widths are $4, 11, 11, 11$, respectively.\n    \\item Between \\verb|\\midrule| and \\verb|\\bottomrule|, use a for-loop to print each row of the table. Note that the $i$th row of the table consists of the \\verb|i|th component of \\verb|m| and the \\verb|i|th row of matrix \\verb|X|. The column widths are $2, 9, 9, 9$, respectively. For floating point numbers, output 6 digits after the decimal point.\n    \\item Call \\verb|type('solution.tex')| to print the content of \\verb|solution.tex|.\n  \\end{enumerate}\n\\item Plot the solution versus $m$ using a for-loop as you did in Part 4 of Lab 05:\n  \\begin{enumerate}[(i)]\n    \\item Get the size of \\verb|X| and assign it to \\verb|XSize|. Define a cell array \\verb|styles|, of which the entries are dashed line with hexagram, dotted line with pentagram, solid line with diamond.\n    \\item The use a for-loop to plot each column of \\verb|X| versus \\verb|m| in the same figure window with the above styles.\n    \\item Add labels, title, grid, legend as shown in Figure \\ref{fig:solution}.\n    \\item Save the plot to a file named \\verb|lab_06_plot.pdf|.\n  \\end{enumerate}\n\\end{enumerate}\n%---------------------------------------------\nType \\verb|diary('lab_06_output.txt')| in the Command Window, run the script file \\verb|lab_06_script.m|, and type \\verb|diary off| in the Command Window. Upload \\verb|lab_06_output.txt|, \\verb|lab_06_script.m|, \\verb|solution.tex|, and \\verb|lab_06_plot.pdf| to the folder \\verb|src| on Overleaf.\n\nOn Overleaf, open \\verb|body.tex| under the folder \\verb|LaTeX|. In the last section of the report, you will reproduce Section \\ref{sec:bol} using \\LaTeX{}. You may find the following helpful:\n\n\\begin{itemize}\n  \\item You may use enviroments such as  \\verb|equation|, \\verb|cases|, \\verb|figure|, and \\verb|table|.\n  \\item You may use \\verb|\\includegraphics[width=amount unit]{/path/to/figure.pdf}| to specify the width of a figure. In our case, the width of the figure is \\verb|0.85\\textwidth|.\n  \\item You may use \\verb|\\ref{labelName}| to refer to figures, tables; use \\verb|\\eqref{labelName}| to refer to equations.\n  \\item For special symbols, you may look them up in \\href{https://libaoj.in/files/LaTeX.Mathematical.Symbols.pdf}{\\LaTeX{}.Mathematics.Symbols.pdf}.\n  \\item You may use \\verb|\\input{/path/to/solution.tex}| to include the table you got from MATLAB.\n\\end{itemize}\n\nRecompile and submit the PDF file generated by Overleaf to WyoCourses.\n\n\\newpage\n%---------------------------------------------\n\\section{Basics of \\LaTeX{}}\n\\label{sec:bol}\n%---------------------------------------------\n\\subsection{LU Decomposition}\n\nGiven the linear system \\eqref{eq:varyRHS}\n\\begin{equation}\n  \\label{eq:varyRHS}\n  \\begin{cases}\n    3x + y + z = m \\\\\n    x - 5y + 2z = 5 \\\\\n    2x + y + 5z = 10\n  \\end{cases}\n\\end{equation}\nwhere $m = 0, 1, 2, \\ldots, 20$. Using LU Decomposition we can obtain the solution to the linear system \\eqref{eq:varyRHS} for corresponding $m$ (see Table \\ref{tab:solution} and Figure \\ref{fig:solution}).\n\n\\input{../Math.3341.Lab.06.ans/solution.tex}\n\n\\begin{figure}[!hbtp]\n  \\centering\n  \\includegraphics[width=0.85\\textwidth]{../Math.3341.Lab.06.ans/lab_06_plot.pdf}\n  \\caption{Solution to the linear system vs. $m$}\n  \\label{fig:solution}\n\\end{figure}\n", "meta": {"hexsha": "6bde4b48c837b1af308c572bc4a3229ef8e2f24b", "size": 6809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.06/exercise/body.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.06/exercise/body.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.06/exercise/body.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.7416666667, "max_line_length": 414, "alphanum_fraction": 0.6632398296, "num_tokens": 2103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.9073122269997506, "lm_q1q2_score": 0.8170616929886335}}
{"text": "\\section{Complex inner product spaces}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Compute dot products in $\\C^n$.\n  \\item Use properties of the complex dot product to prove equalities\n    and inequalities.\n  \\item Compute the adjoint of a matrix.\n  \\item Check whether an operation is a complex inner product.\n  \\item Determine whether vectors in a complex inner product space are\n    orthogonal.\n  \\item Calculate the complex Fourier coefficients of a vector.\n  \\item Use the Gram-Schmidt procedure to find an orthogonal basis of\n    a subspace of a complex inner product space.\n  \\item Compute the orthogonal projection of a complex vector onto a\n    subspace.\n  \\end{enumerate}\n\\end{outcome}\n\nSo far, in this chapter, the field $K$ was always $\\R$, the set of\nreal numbers.  The reason we have not considered inner products over\nother fields $K$ is that the positive definite property requires\n$\\iprod{\\vect{u},\\vect{u}}\\geq 0$, and the requirement that a scalar\nis ``greater or equal to 0'' does not make sense if $K$ is, say, the\nfield of integers modulo $p$.\n\nIn this section, we will consider inner product spaces over the\ncomplex numbers. It turns out that the theory of complex inner product\nspaces is similar, but not completely identical, to that of real inner\nproduct spaces. To explain the difference, consider the definition of\nthe dot product. In $\\R^n$, the dot product of two vectors\n\\begin{equation*}\n  \\vect{v}=\\begin{mymatrix}{c} x_1 \\\\ \\vdots \\\\ x_n \\end{mymatrix}\n  \\quad\\mbox{and}\\quad\n  \\vect{w}=\\begin{mymatrix}{c} y_1 \\\\ \\vdots \\\\ y_n \\end{mymatrix}\n\\end{equation*}\nis defined to be\n\\begin{equation*}\n  \\vect{v}\\dotprod \\vect{w} = x_1y_1 + \\ldots + x_ny_n.\n\\end{equation*}\nOne of the most important properties of the dot product is positivity:\nfor all $\\vect{v}$, we have\n\\begin{equation*}\n  \\vect{v}\\dotprod\\vect{v} = x_1^2 + \\ldots + x_n^2\\geq 0.\n\\end{equation*}\nThe reason positivity holds is that the square of a real number is\nalways greater or equal to 0. If we blindly replaced $x_1,\\ldots,x_n$\nby complex numbers and kept the same definition of dot product,\npositivity would no longer hold. This is because for a complex number\n$z$, it is not in general true that $z^2\\geq 0$. In fact, $z^2$ may\nnot be a real number, and even in cases where $z^2$ is real, it may\nnot be positive. For example, if $z=i$, then $z^2=-1$.\n\nFortunately, all is not lost: the complex numbers actually do have a\nuseful positivity property. Namely, if $z=a+bi$ is a complex number\nand $\\conjugate{z}=a-bi$ is its complex conjugate, then\n\\begin{equation*}\n  \\conjugate{z}z = (a-bi)(a+bi) = a^2 + b^2 \\geq 0.\n\\end{equation*}\nSo instead of squaring a complex number, we should multiply it by its\nconjugate. With this in mind, we arrive at the following definition of\ndot product on $\\C^n$:\n\n\\begin{definition}{The dot product on $\\C^n$}{complex-dot-product}\n  Let\n  \\begin{equation*}\n    \\vect{v}=\\begin{mymatrix}{c} v_1 \\\\ \\vdots \\\\ v_n \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{w}=\\begin{mymatrix}{c} w_1 \\\\ \\vdots \\\\ w_n \\end{mymatrix}\n  \\end{equation*}\n  be vectors in $\\C^n$. Their \\textbf{(complex) dot product}%\n  \\index{dot product!complex}%\n  \\index{vector!dot product!complex}%\n  \\index{complex dot product}\n  is defined to be\n  \\begin{equation*}\n    \\vect{v}\\dotprod \\vect{w} = \\conjugate{v_1}w_1 + \\ldots + \\conjugate{v_n}w_n.\n  \\end{equation*}\n\\end{definition}\n\nThe complex dot product satisfies properties that are similar to, but\nnot exactly the same as, the properties satisfied by the real dot\nproduct.\n\n\\begin{proposition}{Properties of the complex dot product}{properties-complex-dot-product}\n  \\index{properties of dot product!complex}%\n  \\index{vector!properties of dot product!complex}%\n  \\index{complex dot product!properties}%\n  The dot product satisfies the following properties, where\n  $\\vect{u},\\vect{v},\\vect{w}\\in\\C^n$ and $k,\\ell\\in\\C$.\n  \\begin{itemize}\n  \\item Conjugate symmetry: $\\vect{u}\\dotprod\\vect{v}=\\conjugate{\\vect{v}\\dotprod\\vect{u}}$.\n  \\item Linearity on the right: $\\vect{u}\\dotprod(k\\vect{v}+\\ell\\vect{w})\n    =k(\\vect{u}\\dotprod \\vect{v})+\\ell(\\vect{u}\\dotprod\\vect{w})$.\n  \\item Antilinearity on the left: $(k\\vect{u}+\\ell\\vect{v})\\dotprod\\vect{w}=\\conjugate{k}(\\vect{u}\\dotprod\\vect{w})+\\conjugate{\\ell}(\\vect{v}\\dotprod\\vect{w})$.\n  \\item The positive definite property: $\\vect{u}\\dotprod\\vect{u}\\geq 0$, and $\\vect{u}\\dotprod\\vect{u}=0$ if and only if $\\vect{u}=\\vect{0}$.\n  \\end{itemize}\n\\end{proposition}\n\nWe note that the complex dot product can be equivalently expressed as\na matrix product, namely\n\\begin{equation*}\n  \\vect{v}\\dotprod\\vect{w}\n  ~=~ \\begin{mymatrix}{ccc} \\conjugate{v_1} & \\cdots & \\conjugate{v_n} \\end{mymatrix}\n  \\begin{mymatrix}{c} w_1 \\\\ \\vdots \\\\ w_n \\end{mymatrix}\n  ~=~ \\conjugate{\\vect{v}}^T \\vect{w}.\n\\end{equation*}\nHere, $\\conjugate{\\vect{v}}$ denotes the complex conjugate of a vector\n(i.e., taking the complex conjugate of each component of a vector),\nand $(-)^T$ denotes the transpose as usual.  As a matter of fact, when\nworking with complex vectors and matrices, it turns out that we should\nalmost {\\em always} take the complex conjugate at the same time as\ntaking the transpose. For this reason, we introduce a special name and\nnotation for the conjugate transpose of a vector or matrix.\n\n\\begin{definition}{Adjoint of a matrix}{adjoint}\n  Let $A$ be a complex $n\\times m$-matrix. The \\textbf{adjoint} of\n  $A$, denoted $A^{\\adjoint}$, is the transpose of the complex conjugate of\n  $A$. In symbols:\n  \\begin{equation*}\n    A^{\\adjoint} = \\conjugate{A}{}^T.\n  \\end{equation*}\n\\end{definition}\n\nWith this definition, we can also write the dot product as\n\\begin{equation*}\n  \\vect{v}\\dotprod\\vect{w} = \\vect{v}^{\\adjoint}\\vect{w}.\n\\end{equation*}\n\nWe are now ready to state the definition of a complex inner product,\nwhich is a generalization of the complex dot product.\n\n\\begin{definition}{Complex inner product space}{complex-inner-product-space}\n  A \\textbf{complex inner product space}%\n  \\index{inner product space!complex}%\n  \\index{complex inner product space|see{inner product space}} is a\n  complex vector space $V$ equipped with an operation that assigns to\n  any pair of vectors $\\vect{u},\\vect{v}\\in V$ a complex number\n  $\\iprod{\\vect{u},\\vect{v}}$, called the \\textbf{inner product}%\n  \\index{inner product!complex}%\n  \\index{multiplication!complex inner product} of $\\vect{u}$ and $\\vect{v}$,\n  satisfying the following properties:\n  \\begin{enumerate}\n  \\item Conjugate symmetry:%\n    \\index{conjugate symmetry!of inner product}%\n    \\index{symmetry!conjugate symmetry}\n    $\\iprod{\\vect{u},\\vect{v}} =\n    \\conjugate{\\iprod{\\vect{v},\\vect{u}}}$.\n  \\item Linearity on the right:%\n    \\index{linearity!of inner product}\n    $\\iprod{\\vect{u},k\\vect{v}+\\ell\\vect{w}}\n    =k\\iprod{\\vect{u}, \\vect{v}}+\\ell\\iprod{\\vect{u},\\vect{w}}$.\n  \\item Antilinearity on the left:%\n    \\index{antilinearity!of inner product}\n    $\\iprod{k\\vect{u}+\\ell\\vect{v},\\vect{w}}=\\conjugate{k}\\iprod{\\vect{u},\\vect{w}}+\\conjugate{\\ell}\\iprod{\\vect{v},\\vect{w}}$.\n  \\item The positive definite property:%\n    \\index{positive definite property}\n    $\\iprod{\\vect{u},\\vect{u}} \\geq 0$, and\n    $\\iprod{\\vect{u},\\vect{u}}=0$ if and only if\n    $\\vect{u} = \\vect{0}$.\n  \\end{enumerate}\n\\end{definition}\n\nNote that conjugate symmetry implies that $\\iprod{\\vect{u},\\vect{u}}$\nis a real number for every vector $\\vect{u}$. Namely, let\n$z=\\iprod{\\vect{u},\\vect{u}}$. Then by conjugate symmetry, we have\n\\begin{equation*}\n  z\n  = \\iprod{\\vect{u},\\vect{u}}\n  = \\conjugate{\\iprod{\\vect{u},\\vect{u}}}\n  = \\conjugate{z}.\n\\end{equation*}\nSince $z$ is equal to its own conjugate, it must be a real\nnumber. Therefore, the positive definite property makes sense: when we\nrequire that $\\iprod{\\vect{u},\\vect{u}} \\geq 0$, we are talking about\na real number that is greater than or equal to $0$. (It would not in\ngeneral make sense to ask whether a complex number is  greater than or\nequal to $0$).\n\nThe space $\\C^n$ with the complex dot product is evidently an example\nof a complex inner product space. Here is another example:\n\n\\begin{example}{Complex-valued continuous functions}{continuous-complex}\n  Let $a<b$ be real numbers, and let $C[a,b]$ be the space of\n  continuous, complex-valued functions $f : [a,b]\\to\\C$. Given two such\n  functions $f,g\\in C[a,b]$, we define their inner product as\n  \\begin{equation*}\n    \\iprod{f,g} = \\int_{a}^{b} \\conjugate{f(x)}g(x)\\,dx.\n  \\end{equation*}\n  With this operation, $C[a,b]$ is a complex inner product space.\n\\end{example}\n\nArmed with this definition of complex inner products, we can now\npretty much redo everything we did for real inner products in the\ncomplex case. The only thing we have to be careful about is to put the\ncomplex conjugate operation in the correct places.\n\n\\begin{itemize}\n\\item The \\textbf{norm}%\n  \\index{norm!in Cn@in $\\C^n$}%\n  \\index{vector!norm}%\n  \\index{inner product space!norm} of a vector in a complex inner\n  product space is defined to be\n  $\\norm{\\vect{u}} = \\sqrt{\\iprod{\\vect{u},\\vect{u}}}$.  This\n  definition makes sense because $\\iprod{\\vect{u},\\vect{u}}\\geq 0$.\n\\item The \\textbf{Cauchy-Schwarz inequality}%\n  \\index{Cauchy-Schwarz inequality!complex}%\n  \\index{inner product space!Cauchy-Schwarz inequality}\n  $\\abs{\\iprod{\\vect{u},\\vect{v}}}\\leq \\norm{\\vect{u}}\\norm{\\vect{v}}$\n  and the \\textbf{triangle inequality}%\n  \\index{triangle inequality!complex}%\n  \\index{inner product space!triangle inequality}\n  $\\norm{\\vect{u}+\\vect{v}}\\leq \\norm{\\vect{u}} + \\norm{\\vect{v}}$\n  hold in complex inner product spaces.\n\\item Two vectors $\\vect{u},\\vect{v}$ in a complex inner product space\n  are called \\textbf{orthogonal}%\n  \\index{orthogonal vectors}%\n  \\index{vector!orthogonal}, in symbols $\\vect{u}\\orth\\vect{v}$, if\n  $\\iprod{\\vect{u},\\vect{v}}=0$.\n\\item A vector $\\vect{u}$ in a complex inner product space is called\n  \\textbf{normalized}%\n  \\index{normalized vector}%\n  \\index{vector!normalized} if $\\norm{\\vect{u}} = 1$.\n\\item A set of vectors $\\set{\\vect{u}_1,\\ldots,\\vect{u}_n}$ is called\n  an \\textbf{orthogonal set}%\n  \\index{orthogonal set} if the vectors are non-zero and pairwise\n  orthogonal, and an \\textbf{orthonormal set}%\n  \\index{orthonormal set} if the vectors are moreover normalized.\n\\item If $\\vect{u}_1,\\ldots,\\vect{u}_k$ are orthogonal, then\n  $\\norm{a_1\\vect{u}_1+\\ldots+a_k\\vect{u}_k}^2 =\n  \\abs{a_1}^2\\norm{\\vect{u}_1}^2 + \\ldots + \\abs{a_k}^2\\norm{\\vect{u}_k}^2$.\n  The absolute value signs are necessary because $\\conjugate{a_i}a_i=|a_i|^2$.\n\\end{itemize}\n\n\\begin{example}{Orthogonal vectors}{orthogonal-vectors-complex}\n  Consider $\\C^2$ with the complex dot product, and the following\n  vectors:\n  \\begin{equation*}\n    \\vect{u}=\\begin{mymatrix}{c} 1 \\\\ i \\end{mymatrix},\n    \\quad\n    \\vect{v}=\\begin{mymatrix}{c} -i \\\\ 1 \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    \\vect{w}=\\begin{mymatrix}{c} i \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Are $\\vect{u}$ and $\\vect{v}$ orthogonal? Are $\\vect{u}$ and\n  $\\vect{w}$ orthogonal?\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{equation*}\n    \\iprod{\\vect{u},\\vect{v}}\n    = \\vect{u}^{\\adjoint}\\vect{v}\n    = \\begin{mymatrix}{cc} 1 & -i \\end{mymatrix}\n    \\begin{mymatrix}{c} -i \\\\ 1 \\end{mymatrix}\n    = -i-i\n    = -2i\n    \\neq 0,\n  \\end{equation*}\n  so $\\vect{u}$ and $\\vect{v}$ are not orthogonal. We have\n  \\begin{equation*}\n    \\iprod{\\vect{u},\\vect{w}}\n    = \\vect{u}^{\\adjoint}\\vect{w}\n    = \\begin{mymatrix}{cc} 1 & -i \\end{mymatrix}\n    \\begin{mymatrix}{c} i \\\\ 1 \\end{mymatrix}\n    = i-i\n    = 0,\n  \\end{equation*}\n  so $\\vect{u}$ and $\\vect{w}$ are orthogonal. Note that it is crucial\n  here that we did not forget to take the complex conjugate of\n  $\\vect{u}$, or else we would have gotten a different answer.\n\\end{solution}\n\nIn some formulas, we must be careful about whether we use\n$\\iprod{\\vect{v},\\vect{w}}$ or $\\iprod{\\vect{w},\\vect{v}}$. Although\nthis did not make any difference in the case of real inner products,\nit does make a difference for complex inner products, because in\ngeneral, $\\iprod{\\vect{v},\\vect{w}}\\neq \\iprod{\\vect{w},\\vect{v}}$. In\nparticular, we have to be careful about this in the formulas for\nFourier coefficients, projections, and the Gram-Schmidt procedure.\n\n\\begin{example}{Complex Fourier coefficients}{complex-fourier-coefficients}\n  Let $\\set{\\vect{u}_1,\\ldots,\\vect{u}_n}$ be an orthogonal set of\n  vectors in a complex inner product space, and let\n  \\begin{equation*}\n    \\vect{v} = a_1\\vect{u}_1 + \\ldots + a_n\\vect{u}_n.\n  \\end{equation*}\n  Which of the following formulas is correct?\n  \\begin{equation*}\n    a_i = \\frac{\\iprod{\\vect{v},\\vect{u}_i}}{\\iprod{\\vect{u}_i,\\vect{u}_i}}\n    \\quad\\mbox{or}\\quad\n    a_i = \\frac{\\iprod{\\vect{u}_i,\\vect{v}}}{\\iprod{\\vect{u}_i,\\vect{u}_i}}\n    \\quad?\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  To check whether the first formula is correct, we calculate\n  \\begin{eqnarray*}\n    \\frac{\\iprod{\\vect{v},\\vect{u}_i}}{\\iprod{\\vect{u}_i,\\vect{u}_i}}\n    &=&\n        \\frac{\\iprod{a_1\\vect{u}_1 + \\ldots + a_i\\vect{u}_i + \\ldots + a_n\\vect{u}_n,\\vect{u}_i}}{\\iprod{\\vect{u}_i,\\vect{u}_i}} \\\\\n    &=&\n        \\conjugate{a_1}\\frac{\\iprod{\\vect{u}_1,\\vect{u}_i}}{\\iprod{\\vect{u}_i,\\vect{u}_i}}\n        + \\ldots\n        + \\conjugate{a_i}\\frac{\\iprod{\\vect{u}_i,\\vect{u}_i}}{\\iprod{\\vect{u}_i,\\vect{u}_i}}\n        + \\ldots\n        + \\conjugate{a_n}\\frac{\\iprod{\\vect{u}_n,\\vect{u}_i}}{\\iprod{\\vect{u}_i,\\vect{u}_i}} \\\\\n    &=&\n        \\conjugate{a_1}\\cdot 0\n        + \\ldots\n        + \\conjugate{a_i}\\cdot 1\n        + \\ldots\n        + \\conjugate{a_n}\\cdot 0 \\\\\n    &=&\n        \\conjugate{a_i}.\n  \\end{eqnarray*}\n  Note that because of antilinearity, this formula came out to be\n  $\\conjugate{a_i}$, and not $a_i$. Therefore, the first formula is\n  not correct.  The check the second formula, we calculate\n  \\begin{eqnarray*}\n    \\frac{\\iprod{\\vect{u}_i,\\vect{v}}}{\\iprod{\\vect{u}_i,\\vect{u}_i}}\n    &=&\n        \\frac{\\iprod{\\vect{u}_i,a_1\\vect{u}_1 + \\ldots + a_i\\vect{u}_i + \\ldots + a_n\\vect{u}_n}}{\\iprod{\\vect{u}_i,\\vect{u}_i}} \\\\\n    &=&\n        a_1\\frac{\\iprod{\\vect{u}_i,\\vect{u}_1}}{\\iprod{\\vect{u}_i}}\n        + \\ldots\n        + a_i\\frac{\\iprod{\\vect{u}_i,\\vect{u}_i}}{\\iprod{\\vect{u}_i,\\vect{u}_i}}\n        + \\ldots\n        + a_n\\frac{\\iprod{\\vect{u}_i,\\vect{u}_n}}{\\iprod{\\vect{u}_i,\\vect{u}_i}} \\\\\n    &=&\n        a_1\\cdot 0\n        + \\ldots\n        + a_i 1\n        + \\ldots\n        + a_n\\cdot 0 \\\\\n    &=&\n        a_i.\n  \\end{eqnarray*}\n  Therefore, the second formula is correct.\n\\end{solution}\n\nSince this is an important result, we state it as a proposition.\n\n\\begin{proposition}{Complex Fourier coefficients}{complex-fourier-coefficients}\n  If $\\set{\\vect{u}_1,\\ldots,\\vect{u}_n}$ is an orthogonal set of\n  vectors in a complex inner product space and\n  \\begin{equation*}\n    \\vect{v} = a_1\\vect{u}_1 + \\ldots + a_n\\vect{u}_n,\n  \\end{equation*}\n  then\n  \\begin{equation*}\n    a_i = \\frac{\\iprod{\\vect{u}_i,\\vect{v}}}{\\iprod{\\vect{u}_i,\\vect{u}_i}}\n    \\quad\\mbox{and}\\quad\n    \\conjugate{a_i} = \\frac{\\iprod{\\vect{v},\\vect{u}_i}}{\\iprod{\\vect{u}_i,\\vect{u}_i}}.\n  \\end{equation*}\n\\end{proposition}\n\n\\begin{example}{Calculating complex Fourier coefficients}{calculating-complex-fourier-coefficients}\n  Suppose that $B=\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$ is an\n  orthogonal basis for a complex inner product space $V$, such that\n  $\\norm{\\vect{u}_1}=1$, $\\norm{\\vect{u}_2}=\\sqrt{5}$, and\n  $\\norm{\\vect{u}_3}=2$. Moreover, suppose that $\\vect{v}\\in V$ is a\n  vector such that $\\iprod{\\vect{u}_1,\\vect{v}} = i$,\n  $\\iprod{\\vect{u}_2,\\vect{v}} = -2$, and\n  $\\iprod{\\vect{u}_3,\\vect{v}} = 1-2i$. Find the coordinates of\n  $\\vect{v}$ with respect to $B$.\n\\end{example}\n\n\\begin{solution}\n  We need to find $a_1, a_2, a_3$ such that\n  $\\vect{v} = a_1\\vect{u}_1 + a_2\\vect{u}_2 + a_3\\vect{u}_3$.  By\n  Proposition~\\ref{prop:complex-fourier-coefficients}, we have\n  \\begin{eqnarray*}\n    a_1\n    &=& \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\n        ~~=~~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\norm{\\vect{u}_1}^2}\n        ~~=~~ \\frac{i}{1}\n        ~~=~~ i, \\\\\n    a_2\n    &=& \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\n        ~~=~~ \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\norm{\\vect{u}_2}^2}\n        ~~=~~ \\frac{-2}{5}\n        ~~=~~ -\\frac{2}{5}, \\\\\n    a_3\n    &=& \\frac{\\iprod{\\vect{u}_3,\\vect{v}}}{\\iprod{\\vect{u}_3,\\vect{u}_3}}\n        ~~=~~ \\frac{\\iprod{\\vect{u}_3,\\vect{v}}}{\\norm{\\vect{u}_3}^2}\n        ~~=~~ \\frac{1-2i}{4}\n        ~~=~~ \\frac{1}{4} - \\frac{1}{2}i.\n  \\end{eqnarray*}\n\\end{solution}\n\nThe Gram-Schmidt orthogonalization procedure works without changes in\ncomplex inner product spaces, as long as we are careful not to confuse\n$\\iprod{\\vect{u}_i,\\vect{v}_j}$ with $\\iprod{\\vect{v}_j,\\vect{u}_i}$.\n\n\\begin{proposition}{Complex Gram-Schmidt orthogonalization procedure}{gram-schmidt-complex}\n  Let $\\set{\\vect{v}_1,\\ldots,\\vect{v}_k}$ be a basis for some subspace $W$\n  of a complex inner product space $V$.%\n  \\index{Gram-Schmidt procedure!complex}%\n  \\index{orthogonalization!complex}%\n  \\index{orthogonal basis!Gram-Schmidt procedure!complex}\n  Define vectors\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$ as follows:\n  \\begin{eqnarray*}\n    \\vect{u}_1\n    &=& \\vect{v}_1,\n    \\\\\n    \\vect{u}_2\n    &=& \\vect{v}_2\n        ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_2}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1,\n    \\\\\n    \\vect{u}_3\n    &=& \\vect{v}_3\n        ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_3}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n        ~-~ \\frac{\\iprod{\\vect{u}_2,\\vect{v}_3}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\vect{u}_2,\n    \\\\\n    &\\vdots&\n    \\\\\n    \\vect{u}_k\n    &=& \\vect{v}_k\n        ~-~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}_k}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n        ~-~ \\frac{\\iprod{\\vect{u}_2,\\vect{v}_k}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\vect{u}_2\n        ~-~ \\ldots\n        ~-~ \\frac{\\iprod{\\vect{u}_{k-1},\\vect{v}_k}}{\\iprod{\\vect{u}_{k-1},\\vect{u}_{k-1}}}\\vect{u}_{k-1}.\n  \\end{eqnarray*}\n  Then $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is an orthogonal basis of $W$.\n\\end{proposition}\n\n\\begin{example}{Complex Gram-Schmidt orthogonalization procedure}{gram-schmidt-complex}\n  Consider $\\C^3$ with the complex dot product. Let\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{c} 1+i \\\\ 1 \\\\ i \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_2 = \\begin{mymatrix}{c} i \\\\ -1 \\\\ -3  \\end{mymatrix}\n  \\end{equation*}\n  Use the Gram-Schmidt procedure to find an orthogonal basis for\n  $\\sspan\\set{\\vect{v}_1,\\vect{v}_2}$.\n\\end{example}\n\n\\begin{solution}\n  We start with\n  \\begin{equation*}\n    \\vect{u}_1\n    ~=~ \\vect{v}_1\n    ~=~ \\begin{mymatrix}{c} 1+i \\\\ 1 \\\\ i \\end{mymatrix}.\n  \\end{equation*}\n  Next, we calculate\n  \\begin{equation*}\n    \\iprod{\\vect{u}_1,\\vect{v}_2}\n    ~=~ \\vect{u}_1^{\\adjoint} \\vect{v}_2\n    ~=~ \\begin{mymatrix}{ccc} 1-i & 1 & -i \\end{mymatrix}\n    \\begin{mymatrix}{c} i \\\\ -1 \\\\ -3  \\end{mymatrix}\n    ~=~ (1-i)i + 1(-1) + (-i)(-3)\n    ~=~ 4i\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\iprod{\\vect{u}_1,\\vect{u}_1}\n    ~=~ \\vect{u}_1^{\\adjoint} \\vect{u}_1\n    ~=~ \\begin{mymatrix}{ccc} 1-i & 1 & -i \\end{mymatrix}\n    \\begin{mymatrix}{c} 1+i \\\\ 1 \\\\ i  \\end{mymatrix}\n    ~=~ (1-i)(1+i) + 1\\cdot 1 + (-i)(i)\n    ~=~ 4.\n  \\end{equation*}\n  Therefore\n  \\begin{equation*}\n    \\vect{u}_2\n    ~=~ \\vect{v}_2\n    - \\frac{\\iprod{\\vect{u}_1,\\vect{v}_2}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\vect{u}_1\n    ~=~ \\vect{v}_2\n    - \\frac{4i}{4} \\vect{u}_1\n    ~=~ \\vect{v}_2\n    - i \\vect{u}_1\n    ~=~ \\begin{mymatrix}{c} i \\\\ -1 \\\\ -3  \\end{mymatrix}\n    -i \\begin{mymatrix}{c} 1+i \\\\ 1 \\\\ i \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{c} 1 \\\\ -1-i \\\\ -2  \\end{mymatrix}.\n  \\end{equation*}\n  The desired orthogonal basis is $\\set{\\vect{u}_1,\\vect{u}_2}$. We\n  double-check that $\\vect{u}_1$ and $\\vect{u}_2$ are indeed\n  orthogonal:\n  \\begin{equation*}\n    \\iprod{\\vect{u}_1,\\vect{u}_2}\n    ~=~ \\vect{u}_1^{\\adjoint}\\vect{u}_2\n    ~=~ \\begin{mymatrix}{ccc} 1-i & 1 & -i \\end{mymatrix}\n    \\begin{mymatrix}{c} 1 \\\\ -1-i \\\\ -2  \\end{mymatrix}\n    ~=~ (1-i)1 + 1(-1-i) + (-i)(-2)\n    ~=~ 0.\n  \\end{equation*}\n\\end{solution}\n\nOrthogonal projections also work in complex inner product spaces.\n\n\\begin{proposition}{Orthogonal projection onto a subspace}{projection-subspace-complex}\n  Let $V$ be a complex inner product space, and let $W$ be a subspace\n  of\\/ $V$. Assume $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is an\n  orthogonal basis of\\/ $W$, and $\\vect{v}\\in V$ is any vector.\n  Let\n  \\begin{equation*}\n    \\vect{v}' =\n    \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\,\\vect{u}_1\n    + \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\,\\vect{u}_2\n    + \\ldots\n    + \\frac{\\iprod{\\vect{u}_k,\\vect{v}}}{\\iprod{\\vect{u}_k,\\vect{u}_k}}\\,\\vect{u}_k.\n  \\end{equation*}\n  Then $\\vect{v}'$ is the best approximation%\n  \\index{approximation} of $\\vect{v}$ in $W$, i.e., it is the element\n  of $W$ such that $\\norm{\\vect{v}-\\vect{v}'}$ is as small as\n  possible. Moreover, the vector $\\vect{v}-\\vect{v}'$ is orthogonal to\n  $W$. We say that $\\vect{v}'$ is the \\textbf{orthogonal projection of\n    $\\vect{v}$ onto $W$}%\n  \\index{orthogonal projection!onto subspace!complex}%\n  \\index{projection!onto subspace!complex}.\n\\end{proposition}\n\n\\begin{example}{Orthogonal projection onto a subspace}{projection-subspace-complex}\n  Consider the subspace of $\\C^3$ spanned by\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{c} 1 \\\\ i \\\\ 0 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{c} i \\\\ 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  With respect to the complex dot product, find the best approximation\n  of $\\vect{v}=\\begin{mymatrix}{c} 0 \\\\ 2 \\\\ 4\\end{mymatrix}$ in this\n  subspace.\n\\end{example}\n\n\\begin{solution}\n  First notice that $\\iprod{\\vect{u}_1,\\vect{u}_2}=0$, so that\n  $\\vect{u}_1$ and $\\vect{u}_2$ are orthogonal. Therefore, the best\n  approximation is given by\n  \\begin{equation*}\n    \\vect{v}' =\n    \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\,\\vect{u}_1\n    + \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\,\\vect{u}_2.\n  \\end{equation*}\n  We calculate the relevant inner products:\n  \\begin{eqnarray*}\n    \\iprod{\\vect{u}_1,\\vect{v}}\n    &=& \\begin{mymatrix}{ccc} 1 & -i & 0 \\end{mymatrix}\n        \\begin{mymatrix}{c} 0 \\\\ 2 \\\\ 4\\end{mymatrix}\n    ~~=~~ -2i, \\\\\n    \\iprod{\\vect{u}_2,\\vect{v}}\n    &=& \\begin{mymatrix}{ccc} -i & 1 & 1 \\end{mymatrix}\n        \\begin{mymatrix}{c} 0 \\\\ 2 \\\\ 4\\end{mymatrix}\n    ~~=~~ 6, \\\\\n    \\iprod{\\vect{u}_1,\\vect{u}_1}\n    &=& \\begin{mymatrix}{ccc} 1 & -i & 0 \\end{mymatrix}\n        \\begin{mymatrix}{c} 1 \\\\ i \\\\ 0 \\end{mymatrix}\n    ~~=~~ 2, \\\\\n    \\iprod{\\vect{u}_2,\\vect{u}_2}\n    &=& \\begin{mymatrix}{ccc} -i & 1 & 1 \\end{mymatrix}\n        \\begin{mymatrix}{c} i \\\\ 1 \\\\ 1\\end{mymatrix}\n    ~~=~~ 3.\n  \\end{eqnarray*}\n  Therefore,\n  \\begin{equation*}\n    \\vect{v}'\n    ~~=~~\n    \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\,\\vect{u}_1\n    + \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\,\\vect{u}_2.\n    ~~=~~\n    \\frac{-2i}{2}\\,\\vect{u}_1 + \\frac{6}{3}\\,\\vect{u}_2\n    ~~=~~\n    - i \\begin{mymatrix}{c} 1 \\\\ i \\\\ 0 \\end{mymatrix}\n    + 2 \\begin{mymatrix}{c} i \\\\ 1 \\\\ 1 \\end{mymatrix}\n    ~~=~~\n    \\begin{mymatrix}{c} i \\\\ 3 \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n  To double-check the answer, we can check that $\\vect{v}-\\vect{v}'$\n  is indeed orthogonal to $\\vect{u}_1$ and $\\vect{u}_2$. We have\n  \\begin{equation*}\n    \\vect{v}-\\vect{v}' = \\begin{mymatrix}{c} -i \\\\ -1 \\\\ 2 \\end{mymatrix}\n  \\end{equation*}\n  and\n  \\begin{eqnarray*}\n    \\iprod{\\vect{u}_1,\\vect{v}-\\vect{v}'}\n    &=&\n    \\begin{mymatrix}{ccc} 1 & -i & 0 \\end{mymatrix}\n    \\begin{mymatrix}{c} -i \\\\ -1 \\\\ 2 \\end{mymatrix}\n    ~~=~~ 0, \\\\\n    \\iprod{\\vect{u}_2,\\vect{v}-\\vect{v}'}\n    &=&\n    \\begin{mymatrix}{ccc} -i & 1 & 1 \\end{mymatrix}\n    \\begin{mymatrix}{c} -i \\\\ -1 \\\\ 2 \\end{mymatrix}\n    ~~=~~ 0.\n  \\end{eqnarray*}\n\\end{solution}\n\nWe finish this section with some remarks on the differences between\nthe notations used in mathematics and in physics. Complex inner\nproduct spaces are very important in physics because they are the\nfoundation of quantum mechanics. The adjoint of a matrix $A$ is\nusually denoted $A^{\\adjoint}$ in mathematics and $A^{\\dagger}$ in\nphysics. In quantum mechanics, a column vector $\\vect{v}$ is often\nwritten $\\ket{v}$, and the corresponding row vector\n$\\vect{v}^{\\adjoint}$ is then written as $\\bra{v}$.  This is the\nso-called \\textbf{Dirac notation}%\n\\index{Dirac notation}. With this convention, an inner product\n$\\vect{v}^{\\adjoint}\\vect{w}$ is $\\bra{v}\\ket{w}$, which is usually\nwritten as $\\braket{v}{w}$. Also, the matrix\n$\\vect{v}\\vect{w}^{\\adjoint}$ is written $\\ket{v}\\bra{w}$ and is\ncalled an \\textbf{outer product}%\n\\index{outer product}%\n\\index{multiplication!outer product}. In mathematics, it is customary\nfor inner products to be linear in the left component and antilinear\nin the right component. In physics, it is customary to use the\nopposite convention, i.e., inner products are antilinear in the left\ncomponent and linear in the right component. In this book, we have\nused the physics convention of antilinearity in the left component,\nbecause it is the better convention.\n\n", "meta": {"hexsha": "4c5ab40edbd8db19beb78051389707f9d2813229", "size": 25323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/InnerProductSpaces-Complex.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/InnerProductSpaces-Complex.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/InnerProductSpaces-Complex.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 41.3099510604, "max_line_length": 161, "alphanum_fraction": 0.6472771788, "num_tokens": 9304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.8991213786215105, "lm_q1q2_score": 0.816957782805128}}
{"text": "\\section{Linear Sample of Dimension One}\n\n\\begin{defi}[valid convolution]\nA valid convolution is the linear map\n\\begin{align*}\n    x[n] \\circ y[k] \\to z[m]\n\\end{align*}\nwhere\n\\begin{align*}\n    z[i] &= \\sum_{j=0}^{k - 1} x[i + j] \\cdot y[j] \\quad (0 \\leq i < m) \\\\\n    n &= m + k - 1\n\\end{align*}\n\\end{defi}\n\n\\begin{defi}[strided valid convolution]\nA strided valid convolution is the linear map\n\\begin{align*}\n    x[n] \\circ y[k] \\to z[m]\n\\end{align*}\nwhere\n\\begin{align*}\n    z[i] &= \\sum_{j=0}^{k - 1} x[i \\cdot s + j] \\cdot y[j] \\quad (0 \\leq i < m) \\\\\n    n &= s (m - 1) + k\n\\end{align*}\n\\end{defi}\n\n\\begin{defi}[linear sample]\nA linear sample is a map that maps a sequence of length $n$ to a sequence of\nlength $m$.\n\\end{defi}\n\nThe sampling takes the following steps:\n\\begin{itemize}\n\\item The input sequence $x[n]$ is padded to $\\hat x[\\hat n]$ by\nprepending $p_l$ zero elements and appending $p_r$ zero elements, where\n\\begin{align*}\n    \\hat n = p_l + n + p_r\n\\end{align*}\nIn most case $p_r = p_l$ or $p_r = p_l + 1$.\n\n\\item The kernel (filter) $y[k]$ is extended to $\\hat y[\\hat k]$\nby inserting $r - 1$ zero elements to adjacent elements, where\n\\begin{align*}\n    \\hat k = r * (k - 1) + 1\n\\end{align*}\n\n\\item The padded input $\\hat x$ and the extended kernel $\\hat y$ takes a\nvalid convolution with stride $s$, resulting the output sequence $z[m]$,\nwhere\n\\begin{align*}\n    m = {\\hat n - \\hat k \\over s} + 1\n\\end{align*}\nand $s \\mid \\hat n - \\hat k$ should be granted.\n\\end{itemize}\n\n\n$(p_l, p_r, k, s, r, n, m)$, $p_l, p_r \\in \\mathbb N$, $k, s, r, n, m \\in \\mathbb N^\\ast$\nis called a valid configuration of linear sample if\n\\begin{align*}\n    s (m - 1) = (n + p_l + p_r) - (r (k - 1) + 1)\n\\end{align*}\n", "meta": {"hexsha": "5166ab7709e673bcfe673df0c673c181b47179f1", "size": 1715, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/linear-sample.tex", "max_stars_repo_name": "stdml/stdnn-ops", "max_stars_repo_head_hexsha": "0e6132bd65319e318f918094e482482698482e9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-10-23T18:46:39.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-24T00:46:10.000Z", "max_issues_repo_path": "doc/linear-sample.tex", "max_issues_repo_name": "stdml/stdnn-ops", "max_issues_repo_head_hexsha": "0e6132bd65319e318f918094e482482698482e9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2018-11-10T14:19:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-08T23:33:01.000Z", "max_forks_repo_path": "doc/linear-sample.tex", "max_forks_repo_name": "stdml/stdnn-ops", "max_forks_repo_head_hexsha": "0e6132bd65319e318f918094e482482698482e9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-05T06:17:12.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-05T06:17:12.000Z", "avg_line_length": 27.6612903226, "max_line_length": 89, "alphanum_fraction": 0.6180758017, "num_tokens": 646, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653855, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.8169245565022776}}
{"text": "\\chapter{Functions}\n\\label{chapter:functions}\n\\marginurl{%\n  Functions and Quantifiers:\\\\\\noindent\n  Introduction to Mathematical Reasoning \\#7\n}{youtu.be/VHJeUrCedTU}\n\nAnother important type of objects in mathematics are functions. Function $f$\nfrom a set $X$ to a set $Y$ (written as $f : X \\to Y$) is a unique\nassignment of elements of $Y$ to the elements of $X$ (note that it is not\nnecessary that all the elements of $Y$ are used). In other words, for each\nelement $x \\in X$ there is one assigned element $f(x) \\in Y$. We call such an\nelement the \\emph{value} of $f$ at $x$, we also say that $f(x)$ is an\n\\emph{image} of $x$.\n\nUnfortunately, the definition is not formal. Through this chapter we will\nprovide a more formal definition.\n\n\\section{Quantifiers.}\nThe first ingredient is called quantifiers. Very often we use phrases like ``all\nthe people in the class have smartphones.'' However, we still do not know how to\nwrite it using symbols.\n\n\\paragraph{The Universal Quantifier.}\nIn order to say ``all'' or ``every'' we use the symbol $\\forall$\\footnote{%\n  The symbol is a turned ``A'' symbol, the first letter of the word ``all''.\n}: if $P(a)$ is a predicate about $a \\in A$, then $\\forall a \\in A\\ P(a)$ is a\nstatement saying that all the elements of $A$ satisfy the predicate $P$. In\nother words it is the same as the statement\n$\\set[P(a)]{a \\in A} = A$. For example, $\\forall x \\in \\R\\ x \\cdot 0 = 0$ says\nthat product of every real number and zero is equal to zero.\n\\nomenclature[L]{$\\forall x \\in X~P(x)$}{denotes the statement saying that\n$P$ is true for all elements of $X$}\n\n\\paragraph{The Existential Quantifier.}\nThe second quantifier means ``there is'' and is denoted by the symbol\n$\\exists$\\footnote{%\n  The symbol is a turned ``E'' symbol, the first letter of the word\n  ``exists''. It is also interesting that the symbol for the universal\n  quantifier was introduced by Gerhard Gentzen in 1935 but the symbol for the\n  existential quantifier was introduced, 38 years earlier, by Giuseppe Peano\n  in 1897.\n}:\nif $P(a)$ is a predicate about an element of $A$, then $\\exists a \\in A\\ P(a)$\nsays that there is an element of $A$ satisfying the predicate $P$ i.e.\n$\\set[P(a)]{a \\in A} \\neq \\emptyset$. For example,\n$\\exists x \\in \\R\\ x^2 - 1 = 0$ states that there is a real solution of the\nequation $x^2 - 1 = 0$.\n\\nomenclature[L]{$\\exists x \\in X \\  P(x)$}{denotes the statement saying that\n  $P$ is true for some element of $X$}\n\n\\begin{warning}\n  Note that the word ``any'' sometimes indicates a universal statement and\n  sometimes an existential statement.\n\n  Standard meaning of ``any'' is ``every'' like in the statement ``$a^2 \\ge 0$\n  for any real number'', therefore this statement can be rewritten as\n  $\\forall a \\in \\R \\ a^2 \\ge 0$. Nonetheless, in the negative and interrogative\n  statements ``any'' is used to mean ``some''. For example, ``There is not any\n  real number $a$ such that $a^2 < 0$'' is asserting that the statement\n  $\\exists a \\in \\R \\ a^2 < 0$ is false. And ``Is there any real number $a$ such\n  that $a^2 = 1$?'' is asking whether the existential statement\n  $\\exists a \\in \\R \\ a^2 = 1$ is true.\n\n  Real care is required with questions involving ``any'': ``Is there any\n  integer $a$ such that $a \\ge 1$?'' clearly is asking whether $\\exists a \\in\n  \\R \\ a^2 \\ge 1$ is true; however, ``Is $a \\ge 1$ for any integer $a$'' is less\n  clear and might be taken to asking about the same question as the first\n  question, $\\exists a \\in \\Z \\ a \\ge 1$ (which is true) but might also be\n  taken to be asking about $\\forall a \\in \\Z \\ a \\ge 1$ (which is false).\n\\end{warning}\n\n\\subsection{Proving Statements Involving Quantifiers}\nMost of the statements in mathematics involve quantifiers. This is one of the\nfactors distinguishing advanced from elementary mathematics. In this section we\ngive an overview of the main methods of proof. Though the whole book is about\nproving such results.\n\n\\paragraph{Proving statements of the form $\\forall a \\in A \\ P(a)$.}\nSuch statements can be rewritten in the form $a \\in A \\implies P(a)$. For\nexample, we proved earlier that $a^2 \\ge 0$ for all real numbers $a$ using this\napproach.\n\n\\paragraph{Proving statements of the form $\\exists a \\in A \\ P(a)$.}\nThe easiest way to prove such a statement is by simply exhibiting an element $a$\nof $A$ such that $P(a)$ is true. This method is called \\emph{proof by\nexample}.\n\nLet us prove the statement $\\exists x \\in \\N \\ x^2 = 4$ using this method.\nObserve that $2 \\in N$ and $2^2 = 4$ so $x = 2$ provides an example proving\nthis statement. There are, however, less direct methods such as use of the\ncounting arguments.\n\n\\paragraph{Proving statements involving both quantifiers.}\nTo illustrate problems of this type let us prove that for any integer $n$, if\n$n$ is even, then $n^2$ is also even.\n\nThis statement is a universal statement $\\forall n \\in \\Z \\ (n \\text{ is even}\n\\implies n^2 \\text{ is even})$. However, the hypothesis that $n$ is even is an\nexistential statement $\\exists q \\in \\Z \\ n = 2q$. So we begin the proof as\nfollows:\n\\begin{center}\n  Suppose that $n$ is an even integer. Then $n = 2q$ for some integer $q$.\n\\end{center}\nThe conclusion we wish to prove is that $n^2$ is even, which may be written as\n$\\exists q \\in \\Z \\ n^2 = 2q$. Note that $q$ here is a dummy variable used to\nexpress the statement $n^2$ is a doubled integer. We may replace it by any\nother letter not already in use, for example $\\exists p \\in \\Z \\ n^2 = 2p$.\nHence, if we present $p$ such that $n^2 = 2p$, we finish the proof. As a result,\nwe can complete the proof as follows.\n\\begin{center}\n  Therefore, $n^2 = (2q)^2 = 4q^2$ and so, since $2q^2$ is an integer $n^2$ is\n  even.\n\\end{center}\n\n\\subsection{Disproving Statements Involving Quantifiers}\nDisproving something seems a bit off from the first glance, but to some extent\nit is the same as proving the negation.\n\n\\paragraph{Disproving statements of the form $\\forall a \\in A \\ P(a)$.}\nWe may note that the negation of such a statement is the statement $\\exists a\n\\in A \\ \\lnot P(a)$. So we can disprove it by giving a single example for which\nit is false. This is called \\emph{disproof by counterexample} to $P(a)$.\n\nFor example, we may disprove the statement $\\forall x \\in \\R \\ x^2 > 2$ by\ngiving a counterexample $x = 1$ since $1^2 = 1 < 2$.\n\n\\paragraph{Disproving statements of the form $\\exists a \\in A \\ P(a)$.}\nThe negation of this statement is the statement $\\forall a \\in A \\ \\lnot P(a)$.\nWhich gives one way of disproving the statement.\n\nLet us prove that there does not exist a real number $x$ such that $x^2 = -1$.\nWe know that, for all $x \\in \\R$, we have the inequality $x^2 \\ge 0$ and so $x^2\n\\neq -1$. Hence, there does not exist $x \\in \\R$ such that $x^2 = -1$.\n\n\\section{Cartesian product}\nAnother ingredient is the notion of Cartesian product. If $X$ and $Y$ are two\nsets, then $X \\times Y = \\set[x \\in X \\text{ and } y \\in Y]{(x, y)}$. We also\ndenote $\\underbrace{X \\times X \\times \\dots \\times X}_{k \\text{ times}}$ by\n$X^k$.\n\nConsider the following example. If $X = \\set{a, b, c}$ and $Y = \\set{a, b}$,\nthen\n\\[\n  X \\times Y = \\set{(a, a), (a, b), (b, a), (b, b), (c, a), (c, b)}.\n\\]\nAdditionally, $\\R^2 = \\R \\times \\R$ is the familiar $2$-dimensional Euclidean\nplane.\n\\nomenclature[S]{$A \\times B$}{denotes the set of all ordered pairs of elements\nof $A$ and $B$}\n\n\\begin{exercise}\n  Find the set $\\set{a, b} \\times \\set{a, b} \\setminus\n    \\set[x \\in \\set{a, b}]{(x, x)}$\n\\end{exercise}\n\n\\begin{theorem}\n\\label{theorem:cartesian-product-distributivity}\n  For all sets $A$, $B$, $C$, and $D$ the following hold:\n  \\begin{itemize}\n    \\item $A \\times (B \\cup C) = (A \\times B) \\cup (A \\times C)$;\n    \\item $A \\times (B \\cap C) = (A \\times B) \\cap (A \\times C)$;\n    \\item $(A \\times B) \\cup (C \\times D) \\subseteq\n        (A \\cup C) \\times (B \\cup D)$;\n    \\item $(A \\times B) \\cap (C \\times D) =\n        (A \\cap C) \\times (B \\cap D)$.\n  \\end{itemize}\n\\end{theorem}\n\\begin{proof}\n  It is easy to prove this statement by the definitions. Let us prove only the\n  second equality, the rest is\n  Exercise~\\ref{exercise:cartesian-product-distributivity}.\n\n  Note that $(x, y) \\in A \\times (B \\cap C)$ iff $x \\in A$ and\n  $y \\in (B \\cap C)$.\n  Hence, $(x, y) \\in A \\times (B \\cap C)$ iff $x \\in A$, $y \\in B$, and\n  $y \\in C$. Thus $(x, y) \\in A \\times (B \\cap C)$ iff\n  $(x, y) \\in (A \\times B)$ and $(x, y) \\in (A \\times C)$. As a result,\n  $(x, y) \\in A \\times (B \\cap C)$ iff\n  $(x, y) \\in (A \\times B) \\cap (A \\times C)$ as required.\n\\end{proof}\n\n\n\\begin{exercise}\n\\label{exercise:cartesian-product-distributivity}\n  Prove the rest of the equalities in\n  Theorem~\\ref{theorem:cartesian-product-distributivity}.\n\\end{exercise}\n\n\n\\section{Graphs of Functions}\n\\label{section:graph}\nNow we have all the components to define a function. Mathematicians think about\nthe functions in the way we defined them at the beginning of the chapter,\nhowever formally in order to define a function $f : X \\to Y$ one need to define\na set $D \\subseteq X \\times Y$ (such a set is called the \\emph{graph of the\nfunction} $f$) such that\n\\begin{itemize}\n  \\item $\\forall x \\in X~\\exists y \\in Y\\ (x, y) \\in D$ and\n  \\item $\\forall x \\in X, y_1, y_2 \\in Y\\\n    ((x, y_1) \\in D \\land (x, y_2) \\in D \\implies y_1 = y_2)$.\n\\end{itemize}\nWe say that $y \\in Y$ is the value $f(x)$ of the function described by $D$ at\n$x \\in X$ iff $(x, y) \\in D$.\n\nThe simplest way to think about the functions is in the terms of tables.\nLet us use this idea to list all the functions $\\set{a, b, c}$ to $\\set{d, e}$.\n\\begin{center}\n  \\begin{tabular}{l l l l l l l l l}\n    \\toprule\n    $x$ & $f_1(x)$ & $f_2(x)$ & $f_3(x)$ & $f_4(x)$ &\n    $f_5(x)$ & $f_6(x)$ & $f_7(x)$ & $f_8(x)$ \\\\\n    \\midrule\n    a & d & d & d & d & e & e & e & e \\\\\n    b & d & d & e & e & d & d & e & e \\\\\n    c & d & e & d & e & d & e & d & e \\\\\n    \\bottomrule\n  \\end{tabular}\n\\end{center}\n\n\\begin{exercise}\n  List all the functions from $\\set{a, b}$ to $\\set{a, b}$.\n\\end{exercise}\n\nHowever, listing all the values of a function is only possible when the domain\nof the function is finite. Thus the most common way to describe a function is\nusing a formula which provides a way to find the value of a function. When the\nfunction is defined as a formula it is important to be clear which sets are the\ndomain and the codomain of the function.\n\nLet $\\R_+ = \\set[x \\ge 0]{x \\in \\R}$. Consider the following functions.\n\\begin{itemize}\n  \\item $g_1 : \\R \\to \\R$ such that $g_1(x) = x^2$;\n  \\item $g_2 : \\R_+ \\to \\R$ such that $g_2(x) = x^2$;\n  \\item $g_3 : \\R \\to \\R_+$ such that $g_3(x) = x^2$;\n  \\item $g_4 : \\R_+ \\to \\R_+$ such that $g_4(x) = x^2$;\n\\end{itemize}\nNonetheless that all these functions are defined using the same formula $x^2$,\nwe will see in the next chapters that these four functions have different\nproperties.\n\n\\begin{exercise}\n  Find the graph of the function $f : \\Z \\to \\Z$ such that $f(x) = 3x$.\n\\end{exercise}\n\nNote that when you define the function you need to define it such that the\ndefinition makes sense for all the elements of the domain. For example, the\nformula $g(x) = \\frac{x^2 - 3x + 2}{x - 1}$ does not define a function from\n$\\R$ to $\\R$ since it is not defined for $x = 1$. It is typical to define a\nfunction from real numbers to real numbers by a formula and the convention is\nthat the domain is the set of all numbers for which the formula makes sense\n(unless the domain is specified explicitly).\nUsing this convention the formula $g$ defines a function from $\\R \\setminus\n\\set{1}$ to $\\R$.\n\nIf we really need a function from $\\R$ there are two possible approaches for\nextending $g$.\n\n\\paragraph{Rewriting the formula.}\nWe can rewrite the formula such that it makes sense for all the real numbers.\nNote that for all $x \\in \\R \\setminus \\set{1}$,\n\\[\n  \\frac{x^2 - 3x + 2}{x - 1} = \\frac{(x - 2)(x - 1)}{x - 1} = x - 2.\n\\]\nThen $g_1(x) = x - 2$ defines a function on $\\R$ extending the function $g$.\n\n\\paragraph{Explicit definition.} Alternatively we can explicitly specify the\nvalue of $g$ at $1$. So\n\\[\n  g_2(x) =\n  \\begin{cases}\n    \\frac{x^2 - 3x + 2}{x - 1} & \\text{if } x \\neq 1 \\\\\n    -1 & \\text{if } x = 1\n  \\end{cases}\n\\]\ndefines a function from $\\R$ to $\\R$. Note that we can specify the values at\nindividual points any way we want.\n\nSimilarly to sets we may define the equality between functions. We say that two\nfunctions $f, g : X \\to Y$ are equal ($f = g$) iff $f(x) = g(x)$ for all\n$x \\in X$ i.e. their graphs are equal. Note that two functions are equal only\nif they have the same domains and codomains. For example, $g_1$ and $g_2$ we\njust defined are equal to each other nonetheless that we defined them in two\ndifferent ways.\n\nWe defined $g_1$ and $g_2$ to extend $g$ to a bigger domain, similarly we can\nmake a domain smaller.\n\\begin{definition}\n  Let $f : X \\to Y$ and $A \\subseteq X$. Then $f|_{A} : A \\to Y$ is a function\n  such that $\\forall x \\in A\\ f|_{A}(x) = f(x)$ (we say that $f|_A$ is the\n  restriction of $f$ to the set $A$).\n\\end{definition}\n\n\\nomenclature[F]{$f\\big\\rvert_A$}{denotes the restriction of $f$ to the set $A$}\n\n\\section{Composition of Functions}\n\\begin{figure}\n  \\begin{center}\n    \\begin{tikzpicture}[\n      >=stealth,\n      bullet/.style={\n        fill=black,\n        circle,\n        minimum width=1pt,\n        inner sep=1pt\n      },\n      projection/.style={\n        ->,\n        thick,\n        shorten <=2pt,\n        shorten >=2pt\n      },\n      every fit/.style={\n        ellipse,\n        draw,\n        inner sep=0pt\n      }\n    ]\n\n      \\node at (2,4.7) {$f$};\n      \\draw[projection] (1,4.5) -- (3,4.5);\n      \\node at (0,5) {$X$};\n      \\node[bullet,label=below:$x$] (START)   at (0,2.5){};\n      \\node at (4,5) {$Y$};\n      \\node[bullet,label=below:$f(x)$] at (4,2.5){};\n      \\node at (6,4.7) {$g$};\n      \\draw[projection] (5,4.5) -- (7,4.5);\n      \\node at (8,5) {$Z$};\n      \\node[bullet,label=below:$g\\big(f(x)\\big)$] (END) at (8,2.5){};\n\n      \\draw [line width=8pt, yellow, shorten <=0.25cm,, shorten >=0.6cm, ->] \n        (START.south) \n        to[out=-50, in=-120, distance=4cm, ] \n        node[black, midway, below, align = center, yshift = -0.25cm] \n        {$g \\circ f$} (END);\n\n      \\draw (0,2.5) ellipse (1.02cm and 2.2cm);\n      \\draw (4,2.5) ellipse (1.02cm and 2.2cm);\n      \\draw (8,2.5) ellipse (1.02cm and 2.2cm);\n\n      \\draw[projection] (0.3,2.5) -- (3.7,2.5);\n      \\draw[projection] (4.3,2.5) -- (7.7,2.5);\n    \\end{tikzpicture}\n    \\newline\n  \\end{center}\n  \\caption{Composition of functions}\n\\end{figure}\n\nSuppose $f : X \\to Y$ and $g : Y \\to Z$ be some function. Then, given an\nelement $x \\in X$, the function $f$ assigns $y = f(x) \\in Y$, and the function\n$g$ assigns $z = g(y) = g(f(x)) \\in Z$. Thus using $f$ and $g$ an element of\n$Z$ can be assigned to $x$. This operation defines a function from $X$ to $Z$\nand the result of this operation is called the \\emph{composition} of $f$ and\n$g$.\n\\nomenclature[F]{$f \\circ g$}{denotes the composition of functions $f$ and $g$;\ni.e, it denotes the function $h(x) = f(g(x))$.}\n\n\\begin{definition}\n    If $f : X \\to Y$ and $g : Y \\to Z$, then $h = g \\circ f$ is a\n    function from $X$ to $Z$ such that $g(f(x)) = h(x)$ for all $x \\in X$.\n\\end{definition}\n\nLet us consider an example. Let $f : \\R \\to \\R$ such that $f(x) = x + 1$ and\n$g : \\R \\to \\R$ such that $g(x) = x^2$. Then $(g \\circ f) : \\R \\to \\R$ and\n$(g \\circ f)(x) = (x + 1)^2$ for all $x \\in \\R$. Note that the order of $f$ and\n$g$ is important since $(f \\circ g)(x) = x^2 + 1$. Thus composition is not\n\\emph{commutative}.\n\nThere are two special type functions.\n\\begin{itemize}\n    \\item Let $A \\subseteq X$, then $i : A \\to X$ such that $i(a) = a$ for all\n        $a \\in A$ is called the \\emph{inclusion} function of $A$ into $X$. Observe\n        that $(f \\circ i) : A \\to Y$ and $(f \\circ i) = f|_A$\n        for any function $f : X \\to Y$.\n    \\item Another important function is called the \\emph{identity} function.\n        Let $X$ be some set. Then $\\identity{X} : X \\to X$ is the identity\n        function on $X$ iff $\\identity{X}(x) = x$.\n\\end{itemize}\n\\nomenclature[F]{$\\identity{A}$}{denotes the identity function on the set $A$}\n\n\\begin{theorem}\n  Let $f : X \\to Y$, $g : Y \\to Z$, and $h : Z \\to W$. Then\n  \\begin{itemize}\n    \\item $h \\circ (g \\circ f) = (h \\circ g) \\circ f$.\n    \\item $f \\circ I_X = f = I_Y \\circ f$.\n  \\end{itemize}\n\\end{theorem}\n\\begin{proof}\n  These results can be proven simply by evaluating the functions. For example,\n  both functions in the first equality assign $h(g(f(x)))$ for any $x \\in X$\n  and so functions are equal.\n\\end{proof}\nNotice that this theorem states that we may write $f \\circ g \\circ h$ without\nambiguity.\n\n\\section{The Image of a Function}\nGiven a function $f : X \\to Y$, it is not necessary that every element of $Y$\nis an image of some $x \\in X$. For example, the function $\\R \\to \\R$ defined by\nthe formula $x^2$ does not have $-1$ as a value.\n\nThus we may give the following definition.\n\\begin{definition}\n  The image of the function $f$ is defined as follows\n  \\[\n    \\Im f = \\set[\\exists x \\in X\\ f(x) = y]{y \\in Y}\n          = \\set[x \\in X]{f(x)}\n  \\]\n  (in other words it is the projection of the graph $D$ of $f$ on the second\n  coordinate: $\\Im f = \\set[(x, y) \\in D]{y}$).\n\\end{definition}\n\\nomenclature[F]{$\\Im f$}{denotes the image of $f$}\n\n\\begin{chapterendexercises}\n  \\exercise Is there $x, y, z \\in \\N$ such that $29x + 30y + 31z = 366$.\n  \\exercise Find then image of the function $f : \\Z \\to \\Z$ such that\n    $f(x) = 3x$.\n  \\exercise[recommended] Determine the following sets:\n    \\begin{itemize}\n      \\item $\\set[\\exists n \\in \\N \\ m \\le n]{m \\in \\N}$;\n      \\item $\\set[\\forall n \\in \\N \\ m \\le n]{m \\in \\N}$;\n      \\item $\\set[\\exists m \\in \\N \\ m \\le n]{n \\in \\N}$;\n      \\item $\\set[\\forall m \\in \\N \\ m \\le n]{n \\in \\N}$.\n    \\end{itemize}\n  \\exercise Prove or disprove the following statements.\n    \\begin{itemize}\n      \\item $\\forall m, n \\in \\N \\  m \\le n$.\n      \\item $\\exists m, n \\in \\N \\ m \\le n$.\n      \\item $\\exists m \\in \\N \\  \\forall n \\in \\N \\  m \\le n$.\n      \\item $\\forall m \\in \\N \\  \\exists n \\in \\N \\  m \\le n$.\n      \\item $\\exists n \\in \\N \\  \\forall m \\in \\N \\  m \\le n$.\n      \\item $\\forall n \\in \\N \\  \\exists m \\in \\N \\  m \\le n$.\n    \\end{itemize}\n  \\exercise[recommended]\n    We call elements of the set $\\set{0, 1}^n$ Binary strings of length\n    $n$. Moreover, instead of $(c_1, \\dots, c_n)$ we write $c_1, \\dots, c_n$\n    and we call $c_i$s characters.\n    Show that all Binary strings of length $n$\n    may be ordered such that every successive strings in this order are\n    different only in one character.\n    (For example, for $n = 2$ the order may be $00$, $01$, $11$, $10$.)\n\\end{chapterendexercises}\n", "meta": {"hexsha": "25d912ecf24e0049e2fa252ccb5b5df912f2dd1f", "size": 18771, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_1/chapter_7_functions.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_1/chapter_7_functions.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_1/chapter_7_functions.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 42.4683257919, "max_line_length": 82, "alphanum_fraction": 0.6450375579, "num_tokens": 6273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672954, "lm_q2_score": 0.8976952907388474, "lm_q1q2_score": 0.8168192409100705}}
{"text": "\\section*{Chapter 7: Deriving a Generic Algorithm}\n\n\\paragraph{Exercise 7.1}\nHow many additions are needed to compute \\texttt{fib0(n)}?\n\n\\begin{proof}[Answer]\nLet $\\alpha(n)$ be the number of additions needed to compute\n\\texttt{fib0(}$n$\\texttt{)}. $\\alpha(n)$ can be characterized by\nthe following recurrence relation:\n$$\n\\alpha(n) = \n\\begin{cases}\n    0 & \\textrm{if } n \\leq 1 \\\\\n    1 + \\alpha(n-1) + \\alpha(n-2) & \\textrm{if } n \\geq 2\n\\end{cases}\n$$\n\nIt can be shown by induction on $n$ that $\\alpha(n) = F_{n+1} - 1$.\nIn fact, if $n \\leq 1$, $\\alpha(n) = 0 = F_{n+1} - 1$, since\nby definition $F_1 = F_2 = 1$. For $n \\geq 2$,\n\\begin{eqnarray*}\n\\alpha(n)  &=& 1 + \\alpha(n-1) + \\alpha(n-2) \\\\\n           &=& 1 + (F_n - 1) + (F_{n-1} - 1) \\\\\n           &=& (F_n + F_{n-1}) - 1 \\\\\n           &=& F_{n+1} - 1\n\\end{eqnarray*}\nThus, the number of additions we seek is\n$\\alpha(n) = F_{n+1} -1 \\in \\Theta(\\varphi^n)$, where $\\varphi$ is the \ngolden ratio.\n\\end{proof}\n", "meta": {"hexsha": "d1d0f7fd7a9449cf3dcb3b15145418558dcb11ac", "size": 967, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/src/chapter7.tex", "max_stars_repo_name": "lukius/fmtgp", "max_stars_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-10-12T17:40:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T03:00:43.000Z", "max_issues_repo_path": "math/src/chapter7.tex", "max_issues_repo_name": "lukius/fmtgp", "max_issues_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/src/chapter7.tex", "max_forks_repo_name": "lukius/fmtgp", "max_forks_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-15T07:07:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-29T14:01:30.000Z", "avg_line_length": 31.1935483871, "max_line_length": 71, "alphanum_fraction": 0.58221303, "num_tokens": 386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632329799586, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.8164779267543524}}
{"text": "\\chapter{The Pigeonhole Principle}\n\\label{chapter:pigeonhole}\n\\marginurl{%\n  The Pigeonhole Principle:\\\\\\noindent\n  Introduction to Combinatorics \\#3\n}{youtu.be/1D1Fa7WIUO8}\n\nThe principle we are going to discuss in this chapter is very simple, it states\nthat if you have more objects than boxes, then you cannot put all the objects into\nboxes without putting two objects into the same box.\n\nMore formally the principle can be formulated as follows: if $n > m$, then any\nfunction from $\\range{n}$ to $\\range{m}$ is not an injection. This simple\nstatement is famous in mathematics and called \n\\emph{the pigeonhole principle}\\footnote{%\n  The pigeonhole principle is also called the Dirichlet principle, after the\n  German mathematician G. Lejeune Dirichlet, who demonstrated, using this\n  principle, that there were at least two Parisians with the same number of\n  hairs on their heads.\n}.\n\n\\begin{theorem}[the pigeonhole principle]\n  Let $X$ and $Y$ be some sets such that $\\cardinality{X} > \\cardinality{Y}$.\n  Then for any function $f : X \\to Y$ there are $x_0 \\neq x_1 \\in X$ such that\n  $f(x_0) = f(x_1)$.\n\\end{theorem}\n\\begin{proof}\n  The statement follows from\n  Theorem~\\ref{theorem:injections-surjections-inequalities}.\n\\end{proof}\n\nThis simple statement is very handy in combinatorics. For example, using this\nstatement one may prove that in any group of more than $12$ people there are\ntwo people who were born in the same month.\n\nAssume that there are $n$ people in the group and $n > 12$.\nConsider the following function $f : \\range{n} \\to \\range{12}$ such that $f(i) = j$ if the\n$i$th person was born in $j$th month. Note that $f$ is not an injection since\n$n > 12$ i.e. there are $i_0 \\neq i_1$ such that $i_0$th and $i_1$th person are\nborn in the same month.\n\n\\begin{exercise}\n  Show that among any group of five (not necessarily consecutive)\n  integers, there are two with the same remainder when divided by $4$.\n\\end{exercise}\n\nWe may also prove that in any group of people there are two people who are\nfriends with the same number of people in the group.\n\nAssume the number of people is $n$. It is easy to see that every person may\nhave at most $n - 1$ friends. Hence, we may define a function $f: \\range{n} \\to\n\\set{0, \\dots, n - 1}$ such that $f(i)$ is equal to the number of friends in\nthis group of the $i$th person in this group.\nWe need to consider two cases.\n\\begin{itemize}\n  \\item If $\\Im f \\subseteq \\range{n - 1}$, then\n    $\\cardinality{\\range{n}} > \\cardinality{\\Im f}$ and $f$ is not an injection.\n  \\item Otherwise, note that it is not possible that $(n - 1) \\in \\Im f$\n    because if there is a friend with no friends it is not possible that there\n    is a friend who is friends with everyone. Hence,\n    $f : \\range{n} \\to \\set{0, 1, \\dots, n - 2}$ and $f$ is not an injection.\n\\end{itemize}\n\n\\begin{theorem}[Erd\\H{o}s\u2013-Szekeres]\n  Every sequence of $(r - 1)(s - 1) + 1$ distinct real numbers contains a\n  subsequence of length $r$ that is increasing or a\n  subsequence of length $s$ that is decreasing.\n\\end{theorem}\n\\begin{proof}\n  Given a sequence of length $(r - 1)(s - 1) + 1$, label each number $x_i$ in\n  the sequence with the pair $(a_i, b_i)$, where $a_i$ is the length of the\n  longest increasing subsequence ending with $x_i$ and $b_i$ is\n  the length of the longest decreasing subsequence ending with $x_i$.\n  Each two numbers in the sequence are labeled with a different pair: if $i < j$\n  and $x_i < x_j$ then $a_i < a_j$, and on the other hand if $x_i > x_j$ then\n  $b_i < b_j$. But there are only $(r - 1)(s - 1)$ possible labels if $a_i$ is\n  at most $r - 1$ and $b_i$ is at most $s - 1$, so by the pigeonhole principle\n  there must exist a value of $i$ for which $a_i$ or $bi$ is outside this\n  range. If $a_i$ is out of range then $x_i$ is part of an increasing sequence of\n  length at least $r$, and if $b_i$ is out of range then $x_i$ is part of a\n  decreasing sequence of length at least $s$.\n\\end{proof}\n\nWe can also use the pigeonhole principle to show that the lower bound from\n\\Cref{theorem:guess-one-out-of-many} is precise.\n\\begin{theorem}\n  There is a $B$-decision tree $T$ such that $h(T) \\le 9$ and \n  $\\mathrm{val}(T, S) \\in S$ for all $S \\in \\binom{\\range{1000}}{500}$.\n\\end{theorem}\n\\begin{proof}\n  Let us fix some set $S \\in \\binom{\\range{1000}}{500}$. Note that $S \\cap\n  \\range{501} \\neq \\emptyset$. Therefore, the minimal element of $S$ belongs to\n  $\\range{501}$. Hence, using an algorithm similar to the algorithm from\n  \\Cref{chapter:structural-induciton}, we can find the minimal element of $S$\n  using at most $\\ceil{\\log{501}} = 9$ questions.\n\\end{proof}\n\\nomenclature[U]{$\\ceil{\\alpha}$}{denotes the smallest integer greater than or\nequal to $\\alpha$}\n\n\\section{The Generalized Pigeonhole Principle}\nOne may generalize the pigeonhole principle in the following way.\nIf $N$ objects are placed into $k$ boxes, then there is at least one box\ncontaining at least $\\ceil{N / k}$ objects.\n\\begin{theorem}[the generalized pigeonhole principle]\n\\label{theorem:generalized-pigeonhole-principle}\n  Let $X$ and $Y$ be some sets. Then for any function $f : \\cardinality{X} \\to\n  \\cardinality{Y}$ there are $x_1, \\dots, x_\\ell \\in X$ such that\n  \\begin{itemize}\n    \\item $f(x_i) = f(x_j)$,\n    \\item $x_i \\neq x_j$ for any $i \\neq j \\in \\range{\\ell}$, and\n    \\item $\\ell \\ge \\ceil{\\cardinality{X} / \\cardinality{Y}}$, where\n      $\\ceil{\\alpha}$ denotes the least integer greater than or equal to\n      $\\alpha$.\n  \\end{itemize}\n\\end{theorem}\n\nNow we illustrate applications of this principle on some examples and prove the\nstatement in the next section.\n\nUsing this theorem we can prove that if we draw $9$ cards out of a deck of\ncards, we are guaranteed that at least three of them are of the same suit.\nGiven that, there are $4$ suits in the deck, by pigeonhole principle if we put each card into\none of the four boxes according to their suits, one of the boxes should have\nat least $\\ceil{9 / 4} = 3$ cards.\n\nAnother example shows how the generalized pigeonhole principle can be applied\nto an important part of combinatorics called Ramsey theory.\n\nAssume that in a group of six people, each pair of individuals consists of two\nfriends or two enemies. One may prove that there are either three mutual\nfriends or three mutual enemies in the group.\n\nLet $A$ be one of the six people; of the five other people in the group, there\nare either three or more who are friends of $A$, or three or more who are\nhis enemies $A$. This statements follows from the generalized pigeonhole\nprinciple since when five objects are divided into two sets, one of the sets\nhas at least $\\ceil{5 / 2} = 3$ elements. Without loss of generality we may\nsuppose that $B$, $C$, and $D$ are friends of $A$. If any two of these three\nindividuals are friends, then these two and $A$ form a group of three mutual\nfriends. Otherwise, $B$, $C$, and $D$ form a set of three mutual enemies.\n\n\\section{The Averaging Principle}\nAssume that we have a collection of $m$ objects, the $i$th of which has\n``size'' $l_i$. We wish to show that at least one of the objects is large.\nIn this situation we can argue that at least one of the objects has size\ngreater or equal to the average size ($\\sum l_i / m$).\n\\begin{theorem}[the averaging principle]\n\\label{theorem:averaging-principle}\n  Every sequence of numbers has a number at least as large as the average and a\n  number at least as small as the average; i.e. for any sequence $a_1$, \\dots,\n  $a_m$ there are $i$ and $j$ such that\n  \\begin{gather*}\n    a_i \\ge \\frac{1}{m} \\sum_{i = 1}^m a_i \\\\\n    \\text{and} \\\\\n    a_j \\le \\frac{1}{m} \\sum_{i = 1}^m a_i.\n  \\end{gather*}\n\\end{theorem}\n\\begin{proof}\n  We prove only the existence of $i$, proof of the existence of $j$ is almost\n  the same.\n\n  Assume the opposite, i.e. that $a_i < \\sum_{i = 1}^n a_i / m$\n  for any $i \\in \\range{n}$. Note that this implies that\n  $\\sum_{i = 1}^n a_i \\le m \\cdot \\sum_{i = 1}^n a_i / m = \\sum_{i = 1}^n a_i$.\n  Which is a contradiction.\n\\end{proof}\n\n\\begin{exercise}\n  Finish the proof of Theorem~\\ref{theorem:averaging-principle}\n\\end{exercise}\n\nLike the pigeonhole principle, this principle is very simple but the\napplications of it are surprisingly interesting.\n\nFirst, it allows to prove the generalized pigeonhole principle.\n\\begin{proof}[Proof of Theorem~\\ref{theorem:generalized-pigeonhole-principle}]\n  Let $Y = \\range{m}$ (it is easy to see that the proof works for any other finite\n  $Y$). Define the sequence $a_i = \\cardinality{f^{-1}(i)}$.\n  Note that we need to prove that $a_i \\ge \\ceil{\\cardinality{X} / m}$ for some\n  $i \\in \\range{m}$\n\n  It is clear that $\\bigcup_{i = 1}^m f^{-1}(i) = X$ and that $f^{-1}(i) \\cap\n  f^{-1}(j) = \\emptyset$ for any $i \\neq j \\in \\range{m}$. Thus, by the additive\n  principle, $\\sum_{i = 1}^m a_i = \\cardinality{X}$. Hence, by the averaging\n  principle, $a_i \\ge \\cardinality{X} / m$ for some $i \\in \\range{m}$. However,\n  $a_i$ is an integer, thus $a_i \\ge \\ceil{\\cardinality{X} / m}$.\n\\end{proof}\n\nAnother nice application of the averaging principle allows us to prove that if\nin some group (with more than one person) the number of pairs of people who\nknow each other is less than $n - 1$, then we can split this group into two\nsubgroups such that people from different subgroups do not know each other.\n\nLet us assume that there are $n$ people in the group. We prove the statement\nusing the induction by $n$.\n\\begin{description}\n  \\item [(the base case)] If $n = 2$, there are less than $n - 1 = 1$ pairs\n    of people who know each other, in other words, these two people in the\n    group do not know each other. Thus we can put each of them into a separate\n    subgroup.\n  \\item [(the induction step)] Let $p_i$ ($i \\in \\range{n}$) be the number of\n    acquaintances of the $i$th person. Note that\n    $\\sum_{i = 1}^n p_i \\le 2(n - 2)$ since we count each pair twice.\n    By the averaging principle, $p_i \\le 2(n - 2) / n = 2 - 2 / n$ for some\n    $i \\in \\range{n}$.  Thus $p_i$ is either $0$ or $1$.\n    \\begin{itemize}\n      \\item If $p_i = 0$, we can put the $i$th person into the first subgroup\n        and everyone else into another.\n      \\item If $p_i = 1$ we consider the group of $n - 1$ people without the\n        $i$th person, by the induction hypothesis, we can split everyone but\n        $i$th person into two subgroups and since the $i$th person has only one\n        acquaintance we can put them in the same subgroup.\n      \\end{itemize}\n\\end{description}\n\n\n\n\\begin{chapterendexercises}\n  \\exercise Let $ABC$ be an equilateral triangle such that the length of $AB$ is\n    equal to $1$, and let $p_1$, \\dots, $p_5$ be points inside of $ABC$.\n    Show that there are $i \\neq j \\in \\range{5}$ such that the distance between \n    $p_i$ and $p_j$ is at most $0.5$.\n  \\exercise We are given $17$ points inside a regular triangle of side of\n    length $1$. Prove that two of these points have distance at most $1 / 4$.\n    \\begin{solution}\n      In order to do it let us consider the following partition of the triangle.\n\n      \\begin{center}\n        \\begin{tikzpicture}[thick, scale=0.3]\n          \\draw (-5,0) \n            -- (5,0)\n            -- (0, 8.660) \n            -- cycle;\n          \\draw (0,0) \n            -- (-2.5,4.330)\n            -- (2.5,4.330)\n            -- cycle;\n          \\draw (-2.5,0) \n             -- (-3.75,2.165)\n             -- (-1.25,2.165)\n             -- cycle;\n          \\draw (2.5,0) \n             -- (3.75,2.165)\n             -- (1.25,2.165)\n             -- cycle;\n          \\draw (0,4.330) \n             -- (-1.25,6.495)\n             -- (1.25,6.495)\n             -- cycle;\n          \\draw (0,4.330) \n             -- (-1.25,2.165)\n             -- (1.25,2.165)\n             -- cycle;\n        \\end{tikzpicture}\n      \\end{center}\n\n      Note that there are 16 small triangles inside, hence by pigeonhole\n      principle there are at least two points in the same small triangle.\n      Additionally, distance between any two points inside the regular triangle\n      with side $1 / 4$ is at most $1 / 4$.\n    \\end{solution}\n  \\exercise Show that if there are 30 students in a class, then at least\n    two have last names that begin with the same letter.\n  \\exercise[recommended] Let $n$ be a positive integer. Show that in any set of\n    $n$ consecutive integers there is exactly one divisible by $n$.\n    \\begin{solution}\n      Let the numbers be $k$, $k + 1$, \\dots, $k + n - 1$. Assume that all the\n      numbers are not divisible by $n$. Consider the function \n      $f: \\set{k, k + 1, \\dots, k + n - 1} \\to \\set{1, \\dots, n - 1}$ such that\n      $f(k + i) \\equiv k + i \\pmod{n}$. Note that the set on the left has more\n      elements than the set on the right, so there are $i_1 < i_2$ such that \n      $k + i_1$ has the same reminder as $k + i_2$.\n      Thus $n$ divides $0 < i_2 - i_1 < n$, which is a contradiction.\n    \\end{solution}\n  \\exercise[recommended] Prove that for every sequence of integers $a_1$, \\dots,\n    $a_n$ there are $k > 0$ and $\\ell \\ge 0$ such that $k + \\ell \\le n$ and\n    $\\sum_{i = k}^{k + \\ell} a_i$ is divisible by $n$.\n    \\begin{solution}\n      We consider the $n$ sums modulo $n$ of the form $a_1$, $a_1 + a_2$,\n      \\dots, $a_1 + a_2 + \\dots + a_n$. First, we note that if any of these sums\n      $a_1 + \\cdots + a_\\ell \\equiv 0 \\pmod{n}$, then we are done by picking $k\n      = 1$ and $\\ell$ accordingly since being equivalent to $0$ modulo $n$ is\n      the same as being divisible by $n$. As a result, it suffices to show the\n      result when none of the sums are equivalent to $0$ modulo $n$.\n\n      In this case, each of these sums modulo $n$ necessarily must be one of\n      $1$, $2$, \\dots, $(n - 1)$. That is, there are $n - 1$ possible values for\n      each of these $n$ sums. Therefore, by the pigeonhole principle, we must\n      have that two of these sums are equivalent modulo $n$. Thus there exists\n      $m > 0 $ and $j > 0$ (and without loss of generality may assume that $j >\n      m$ ) so that \n      \\[\n        a_1 + a_2 + \\dots + a_m \\equiv a_1 + a_2 + \\cdots + a_j \\pmod{n}.\n      \\]\n      Note that subtracting $ a_1 + a_2 + \\cdots + a_m$ from both sides yields\n      that \n      \\[\n        0 \\equiv\n        a_{m + 1} + \\cdots + a_{j} \\pmod{n},\n      \\]\n      and hence by taking $k = m + 1$ and $\\ell = j - m - 1 = j - k $ we prove that \n      \\[\n        0 \\equiv a_k + a_{k + 1} + \\dots + a_{k + \\ell} \\pmod{n};\n      \\] \n      in other words, $\\sum\\limits_{i = 0}^\\ell a_{k + i}$ is divisible by $n$.\n    \\end{solution}\n  \\exercise[recommended] Let $S \\subseteq \\range{20}$ be a set. Show that if\n    $\\cardinality{S} \\ge 13$, then there are $a, b \\in S$ such that $a - b = 6$.\n  \\exercise Let $S \\subseteq \\range{20}$ be a set. Show that if $\\cardinality{S}\n    \\ge 11$, then there are $a \\neq b \\in S$ such that $a + b = 21$.\n    \\begin{solution}\n      Note that there are $10$ pairs $(1, 20)$, \\dots, $(10, 11)$ such that their\n      sum is equal to $21$. Hence, by the pigeonhole principle, there are two\n      elements of $S$ such that they belong to the same pair; i.e. their sum is\n      equal to $21$.\n    \\end{solution}\n  \\exercise How many numbers must be selected from the set $\\range{6}$ to\n    guarantee that at least one pair of these numbers add up to $7$?\n    \\begin{solution}\n      Let us split the numbers from $\\range{6}$ into $3$ pairs:\n      $(1, 6)$, $(2, 5)$, and $(3, 4)$. Note that the sum within the pair is\n      $7$. Is is also easy to see that, by the pigeonhole principle, if we pick\n      $4$ numbers out of $[6]$, two of them are in the same pair. Therefore\n      whenever we choose $4$ numbers two of them sum up to $7$.\n\n      It is also easy to see that we may select $3$ numbers so that the sum of\n      any two of them is not equal to $7$. For example, we may select $1$, $2$,\n      and $3$.\n    \\end{solution}\n  \\exercise Sasha is training for a triathlon. Over a $30$ day period, he\n    pledges to train at least once per day, and $45$ times in all. Then there\n    will be a period of consecutive days where he trains exactly $14$ times.\n  \\exercise Show that among any $n + 1$ positive integers not exceeding $2n$\n    there must be an integer that divides one of the other integers.\n    \\hint{Consider the set of holes equal to the set of odd numbers\n    from $1$ to $2n$.}\n    \\begin{solution}\n      Let $R = \\set{1, 3, \\dots, 2n - 1}$ (note that $\\cardinality{R} = n$).\n      Assume that there is a set $L$ that contradicts to the statement of the\n      problem ($\\cardinality{L} = n + 1$). It is easy to see that any number \n      $x \\in \\range{2n}$ is equal to $2^k \\ell$, where $\\ell$ is odd. We define\n      the function $f : L \\to R$ such that $f(2^k \\ell) = \\ell$. By the\n      pigeonhole principle, there are $x < y$ such that $f(x) = f(y)$. But it\n      implies that $x$ divides $y$.\n    \\end{solution}\n  \\exercise Let $A_1, \\dots, A_\\ell \\subseteq \\range{n}$ be some sets such that\n    $A_i \\cap A_j \\neq \\emptyset$. Show that $\\ell \\le 2^{n - 1}$.\n    \\begin{solution}\n      We are going to prove this statement using the pigeonhole principle. The\n      main component of the proof is the fact that $A \\cap \\bar{A} = \\emptyset$\n      for any set $A \\subseteq \\range{n}$, where $\\bar{A} = \\range{n} \\setminus A$.\n\n      Let $L = \\{A_1, \\dots, A_\\ell\\}$ and\n      $R = \\set[A \\subseteq \\range{n}]{\\set{A, \\bar{A}}}$. It is easy to see\n      that $\\cardinality{R} = 2^{n - 1}$. Define the function $f : L \\to R$ such that \n      $f(A_i) = \\set{A_i, \\bar{A_i}}$. Let us prove that $f$ is an injection; \n      assume the opposite i.e. that there are $i \\neq j$ such that \n      $f(A_i) = f(A_j)$. Since $f(A_i) = f(A_j)$ it implies that $A_i =\n      \\bar{A_j}$ but it contradicts to the statement that $A_i \\cap A_j =\n      \\bar{A_j} \\cap A_j = \\emptyset$.\n\n      Hence, there is an injection from $L$ to $R$ which implies that\n      $\\cardinality{L} \\le \\cardinality{R}$.\n      As a result, we proved that $\\ell \\le 2^{n - 1}$.\n    \\end{solution}\n  \\exercise[recommended] Let $a_1$, $a_2$, \\dots, $a_t$ be positive integers. Show that\n    if $a_1 + a_2 + \\dots + a_t - t + 1$ objects are placed into $t$ boxes,\n    then for some $i \\in \\range{t}$, the $i$th box contains at least $a_i$ objects.\n    \\hint{It is important in this question that $a_1$, \\dots, $a_t$ are\n    integers.}\n  \\exercise Let $\\set{(x_1,y_1), \\dots, (x_5, y_5)} \\subseteq \\Z^2$ be a\n    set of five distinct points with integer coordinates in the xy plane. Show\n    that the midpoint of the line joining at least one pair of these points has\n    integer coordinates.\n  \\exercise Let $S \\subseteq \\range{2n}$ be a set such that \n    $\\cardinality{S} = n + 1$. Show\n    that there are $x \\neq y \\in S$ such that $x$ and $y$ are coprime.\n  \\exercise[recommended] In some school there are three clubs. For each two\n    students there is a club such that these students are  members of this club.\n    Show that there is a club that at least $2 / 3$ of all students are members\n    of this club.\n  \\exercise Show that the set $\\set{7, 77, 777, \\dots}$ contains a number\n    divisible by $2019$.\n  \\exercise What is the maximal number of chess knights one may put on a\n    chessboard so that they would not attack each other?\n  \\exercise[recommended] Let us assume that we are given $\\ell$ lines that are\n    not parallel to each other. Prove that there are at least two of them such\n    that angle between them is at most $\\pi / \\ell$.\n    \\begin{solution}\n      Proof of this statement is very similar to the proof of the averaging\n      principle.\n      Let us move all the lines (using parallel shift) such that all of them are\n      going through $(0, 0)$. Let us denote angles between lines (in clockwise\n      order) $\\alpha_1$, \\dots, $\\alpha_{2\\ell}$ respectively and assume that\n      all of them are greater than $\\pi / \\ell$. In this case we may note that\n      $\\sum\\limits_{i = 1}^{2\\ell} \\alpha_i > 2\\ell \\cdot \\pi / \\ell = 2\\pi$,\n      but we know that $\\sum\\limits_{i = 1}^{2\\ell} \\alpha_i  = 2\\pi$.\n    \\end{solution}\n\\end{chapterendexercises}\n", "meta": {"hexsha": "a5fd9edeec3e1bcc5462770616d67ac4d12ea375", "size": 20096, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_4/chapter_19_pigeonhole_principle.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_4/chapter_19_pigeonhole_principle.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_4/chapter_19_pigeonhole_principle.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 50.24, "max_line_length": 93, "alphanum_fraction": 0.6569466561, "num_tokens": 6241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.9304582497090321, "lm_q1q2_score": 0.8164555039155856}}
{"text": "%!TEX root=report.tex\n\\subsection{Basis expansion}\n\nBasis expansion is done by adding more columns to design matrix. Let us first motivate why this might be needed.\n\n\\subsubsection{Motivation}\nIt has previously been described how the design matrix $X$ was constructed such that we had \n\\begin{equation*}\n\\resizebox{\\textwidth}{!}{$\nX = \\left[\\begin{matrix}\n\t\\mathbf{1} &\n\t\\mathbf{t} &\n\t\\frac{1}{2} \\mathbf{t}^2 &\n\t\\cos\\left( \\dfrac{2 \\pi}{\\frac{365.242}{1}} \\mathbf{t} \\right) &\n\t\\sin\\left( \\dfrac{2 \\pi}{\\frac{365.242}{1}} \\mathbf{t} \\right) &\n\t\\cdots &\n\t\\cos\\left( \\dfrac{2 \\pi}{\\frac{365.242}{18}} \\mathbf{t} \\right) &\n\t\\sin\\left( \\dfrac{2 \\pi}{\\frac{365.242}{18}} \\mathbf{t} \\right)\n\\end{matrix}\\right].\n$}\n\\end{equation*}\nThe problem with the above $X$ is that the periodic columns assumes the pattern accounts for the entire period. This causes problems in areas such as Denmark, where the winter comes later than ``usual'', or the summer is much colder/warmer etc..\n\nThis leads to higher variance of the residuals which decreases the accuracy of the velocity and acceleration parameter of the model. By adding columns to the design matrix, such that the periodic pattern is only assumed extend over one period, the accuracy can be improved.\n\n\\subsubsection{The Hinge-function}\n\nOne can achieve this basis expansion is by virtue of the hinge-function\n\\begin{equation}\nf(x - \\zeta)_+ = \\begin{cases}\n  f(x - \\zeta) & \\text{if } x - \\zeta \\ge 0 \\\\\n  0                 & \\text{otherwise}\n\\end{cases} \\quad \\forall x \\in \\mathbb{R}, \\zeta \\in \\mathbb{R}\n\\end{equation}\n$\\zeta$ denotes the ``knot'' between the zero part and the $f$ part. By choosing $f$ and adding the hinge function to the design matrix, a basis expansion where terms are only active for some parts of the time series is obtained.\n\nWhen $f$ is a polynomial one achieve a piecewise polynomial which is called a spline.\nIn this case each hinge function is guaranteed to be continuous and it can be shown that the spline's derivatives are continuous to order $M-2$ where $M$ is the degree of polynomial $f$ \\cite[p.~144]{statistical-learning}. When dealing with polynomials, splines which are continuous up to and including its second order derivatives are called \\textit{cubic splines} and they generate nicely looking curves when performing the regression. \\cite[p.~143]{statistical-learning}.\n\n\\subsubsection{Knots and trigonometric functions}\nTo model each year with different behavior, in essence all that is needed is to create 9 knots (10 intervals requires 9 splits) and construct the hinge functions.\nHowever, since the functions being used are sines and cosines, there is no guarantee of continuity at the knots (only continuity if the trigonometric function evaluates to zero at the knot).\nIn grim cases, when multiple discontinuous functions are combined, one can end up with cusps, that is a steep descent/ascend followed by the opposite movement in rapid succession.\nIf this phenomenon becomes too large, one should consider rejecting the model, this will be discussed in the result section. \n", "meta": {"hexsha": "f5328ef0afefbdcb822f3d566f7e12c2c516db91", "size": 3074, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/theory-splines.tex", "max_stars_repo_name": "AndreasMadsen/grace", "max_stars_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-17T22:52:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-17T22:52:19.000Z", "max_issues_repo_path": "Rapport/theory-splines.tex", "max_issues_repo_name": "AndreasMadsen/grace", "max_issues_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Rapport/theory-splines.tex", "max_forks_repo_name": "AndreasMadsen/grace", "max_forks_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.3111111111, "max_line_length": 474, "alphanum_fraction": 0.7511385817, "num_tokens": 812, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388754, "lm_q2_score": 0.8824278757303677, "lm_q1q2_score": 0.8164487128760656}}
{"text": "\\subsection{Rational numbers}\n\n\n\\subsubsection{Defining rational numbers}\n\nWe previously defined integers in terms of natural numbers. Similarly we can define rational numbers in terms of integers.\n\n\\(\\forall ab \\in \\mathbb{I} (\\neg (b=0)\\rightarrow \\exists c (b.c=a))\\)\n\nA rational is an ordered pair of integers.\n\n\\(\\{\\{a\\},\\{a,b\\}\\}\\)\n\nSo that:\n\n\\(\\{\\{a\\},\\{a,b\\}\\}=\\dfrac{a}{b}\\)\n\n\\subsubsection{Converting integers to rational numbers}\n\nIntegers can be shown as rational numbers using:\n\n\\((i,1)\\)\n\nIntegers can then be turned into rational numbers:\n\n\\(\\mathbb{Q}=\\dfrac{a}{1}\\)\n\n\\(a=\\dfrac{a_1}{a_2}\\)\n\n\\(b=\\dfrac{b_1}{b_2}\\)\n\n\\(c=\\dfrac{c_1}{c_2}\\)\n\n\\subsubsection{Equivalence classes of rationals}\n\nThere are an infinite number of ways to write any rational number, as with integers. \\(\\dfrac{1}{2}\\) can be written as \\(\\dfrac{1}{2}\\), \\(\\dfrac{-2}{-4}\\) etc.\n\nThe class of these terms form an equivalence class.\n\nWe can show these are equal:\n\n\\(\\dfrac{a}{b}=\\{\\{a\\},\\{a,b\\}\\}\\)\n\n\\(\\dfrac{ca}{cb}=\\{\\{a\\},\\{a,b\\}\\}\\)\n\n\\(\\dfrac{ca}{cb}=\\{\\{ca\\},\\{ca,cb\\}\\}\\)\n\n\\(\\{\\{a\\},\\{a,b\\}\\}=\\{\\{ca\\},\\{ca,cb\\}\\}\\)\n\n", "meta": {"hexsha": "15519ad7fe2d87638c4347e88601efd09b13969e", "size": 1111, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/rational/01-01-rationals.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/rational/01-01-rationals.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/rational/01-01-rationals.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.22, "max_line_length": 161, "alphanum_fraction": 0.6282628263, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541643004808, "lm_q2_score": 0.8670357718273068, "lm_q1q2_score": 0.816447845138665}}
{"text": "\\section{Determinants and Inverses}\r\n\\subsection{Introduction}\r\nConsider a linear map $\\mathbb R^n\\to\\mathbb R^n$ given by the matrix $M$.\r\nWe want to define an $n\\times n$ matrix $\\tilde{M}=\\operatorname{adj}M$ and a scalar $\\det M$ with\r\n$$M\\tilde{M}=(\\det M)I$$\r\nFurthermore, $\\det M$ is the factor by whcih an area in $\\mathbb R^2$ or a volumn in $\\mathbb R^3$ is scaled.\r\nIf $\\det M\\neq 0$, then  we will have\r\n$$M^{-1}=\\frac{1}{\\det M}\\tilde{M}$$\r\nFor $n=2$, we know that\r\n$$\\tilde{M}=\r\n\\begin{pmatrix}\r\n    M_{22}&-M_{12}\\\\\r\n    -M_{21}&M_{11}\r\n\\end{pmatrix},\r\n\\det M=\r\n\\begin{vmatrix}\r\n    M_{11}&M_{12}\\\\\r\n    M_{21}&M_{22}\r\n\\end{vmatrix}\r\n=M_{11}M_{22}-M_{12}M_{21}\r\n$$\r\nworks.\r\nNote that $\\det M\\neq 0$ if and only if $M\\underline{e_1},M\\underline{e_2}$ are linearly independent if and only if $\\operatorname{Im}M=\\mathbb R^2$ if and only if $\\operatorname{rank}M=2$.\\\\\r\nFor $n=3$, we recall that given any $\\underline{a},\\underline{b},\\underline{c}\\in\\mathbb R^3$, the scalar $[\\underline{a},\\underline{b},\\underline{c}]$ is the volumn of a parallelopiped spanned by $\\underline{a},\\underline{b},\\underline{c}$.\r\nWe can also note that the standard basis vectors obey $[\\underline{e_i},\\underline{e_j},\\underline{e_k}]=\\epsilon_{ijk}$.\r\nNote that for $M$ a real $3\\times 3$ matrix, its columns are $M\\underline{e_i}=M_{ji}\\underline{e_j}$.\r\nSo the volumn is scaled by a factor\r\n$$[M\\underline{e_1},M\\underline{e_2},M\\underline{e_3}]=M_{i1}M_{j2}M_{k3}[\\underline{e_i},\\underline{e_j},\\underline{e_k}]=M_{i1}M_{j2}M_{k3}\\epsilon_{ijk}$$\r\nWe define this to be $\\det M$.\r\nWe can also define $\\tilde{M}$ by\r\n$$\\underline{R_1}(\\tilde{M})=\\underline{C_2}(M)\\times\\underline{C_3}(M)$$\r\n$$\\underline{R_2}(\\tilde{M})=\\underline{C_3}(M)\\times\\underline{C_1}(M)$$\r\n$$\\underline{R_3}(\\tilde{M})=\\underline{C_1}(M)\\times\\underline{C_2}(M)$$\r\nSo one can see immediately that\r\n$$(\\tilde{M}M)_{ij}=\\underline{R_i}(\\tilde{M})\\cdot\\underline{C_j}(M)=\\det M\\delta_{ij}$$\r\nas desired.\\\\\r\nHow about when we consider $n$ in general?\r\n\\subsection{Alternating forms}\r\nWe first want to generalize our $\\epsilon$ symbol to higher dimensions by considering the permutation.\r\n\\begin{definition}\r\n    A permutation $\\sigma:\\{1,2,\\ldots,n\\}\\to\\{1,2,\\ldots,n\\}$ is a bijection of $\\{1,2,\\ldots,n\\}$ to itself.\r\n\\end{definition}\r\nSo $\\{1,2,\\ldots,n\\}=\\{\\sigma{1},\\sigma{2},\\ldots,\\sigma{n}\\}$.\r\nIt is immediate that the permutations on $n$ letters form a group $S_n$ under composition, and it is easy that $|S_n|=n!$.\r\n\\begin{definition}\r\n    A permutaion $\\tau\\in S_n$ is called a transposition of $i,j\\in\\{1,2,\\ldots,n\\}$ if $\\tau(i)=j,\\tau(j)=i,\\forall k\\neq i,j, \\tau(k)=k$.\r\n    We denote $\\tau$ by $(p\\ q)$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    Any permutation is a product of transpositions.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nThe way we write it is not unique, but the number of transpositions is unique modulo $2$.\r\n\\begin{proposition}\r\n    If some permutation $\\sigma$ can be written as the product of $k$ transpositions and the product of $l$ transpositions, then $k\\equiv l\\pmod{2}$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Will see in groups (actually quite trivial).\r\n\\end{proof}\r\n\\begin{definition}\r\n    We say the permutation $\\sigma$ is even if it can be written as the product of an even number of transpositions, odd if otherwise.\r\n    We define the sign, or signature function $\\epsilon:S_n\\to\\{1,-1\\}$ by\r\n    $$\\epsilon(\\sigma)=\r\n    \\begin{cases}\r\n        1\\text{, if $\\sigma$ is even}\\\\\r\n        -1\\text{, otherwise}\r\n    \\end{cases}\r\n    $$\r\n\\end{definition}\r\nNote that $\\epsilon(\\operatorname{id})=0$ and more generally $\\epsilon(\\sigma\\circ\\pi)=\\epsilon(\\sigma)\\epsilon(\\pi)$ for permutations $\\sigma,\\pi$.\r\n\\begin{definition}\r\n    The $\\epsilon$ symbol (or tensor) on $n$ letters is defined as\r\n    $$\r\n    \\epsilon_{ij\\ldots kl}=\r\n    \\begin{cases}\r\n        \\epsilon(\\sigma)\\text{, if $ij\\ldots kl$ is a permutation $\\sigma$ of $\\{1,2,\\ldots,n\\}$}\\\\\r\n        0\\text{, otherwise. That is, some indices coincide.}\r\n    \\end{cases}\r\n    $$\r\n\\end{definition}\r\nSo we now can define the alternating forms.\r\n\\begin{definition}\r\n    Given vectors $\\underline{v_1},\\underline{v_2},\\ldots,\\underline{v_n}$ in $\\mathbb R^n$ or $\\mathbb C^n$.\r\n    We define the alternating form to be the scalar\r\n    $$[\\underline{v_1},\\underline{v_2},\\ldots,\\underline{v_n}]=\\epsilon_{ij\\ldots kl}(\\underline{v_1})_i(\\underline{v_2})_j\\cdots(\\underline{v_{n-1}})_k(\\underline{v_n})_l$$\r\n    One can check that the alternating forms when $n=2,3$ are exactly the same as we have defined them before.\r\n\\end{definition}\r\nNote that the alternating form is multilinear, thus a tensor.\r\nAlso, it is totally antisymmetric: interchanging any two vectors changes the sign.\r\nEquivalently,\r\n$$[\\underline{v_{\\sigma(1)}},\\underline{v_{\\sigma(2)}},\\ldots,\\underline{v_{\\sigma(n)}}]=\\epsilon(\\sigma)[\\underline{v_1},\\underline{v_2},\\ldots,\\underline{v_n}]$$\r\nMoreover, $[\\underline{e_1},\\underline{e_2},\\ldots,\\underline{e_n}]=1$.\\\\\r\nOne can see immediately that\r\n\\begin{proposition}\r\n    If the function $f:(F^n)^n\\to F$ where $F=\\mathbb R$ or $\\mathbb C$ is multilinear, totally antisymmetric and $f(\\underline{e_1},\\underline{e_2},\\ldots,\\underline{e_n})=1$, then $f$ is uniquely determined.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    If some vector(s) is $\\underline{v_1},\\underline{v_2},\\ldots,\\underline{v_n}$ is a linear combination of others, then $[\\underline{v_1},\\underline{v_2},\\ldots,\\underline{v_n}]=0$.\r\n\\end{proposition}\r\n\\begin{example}\r\n    In $\\mathbb C^4$, let $\\underline{v_1}=(i,0,0,2),\\underline{v_2}=(0,0,5i,0),\\underline{v_3}=(3,2i,0,0),\\underline{v_4}=(0,0,-i,1)$, then $[\\underline{v_1},\\underline{v_2},\\underline{v_3},\\underline{v_4}]=10i$\r\n\\end{example}\r\n\\begin{proposition}\r\n    $[\\underline{v_1},\\underline{v_2},\\ldots,\\underline{v_n}]\\neq 0$ if and only if $\\{\\underline{v_i}\\}$ is an independent set.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    We have already shown the ``only if'' part, so it remains to show the other direction.\r\n    If $\\{\\underline{v_i}\\}$ is independent, then it constituted a basis, hence if $[\\underline{v_1},\\underline{v_2},\\ldots,\\underline{v_n}]=0$, then by multilinearity the alternating form will be zero everywhere, which is a contradiction.\r\n\\end{proof}\r\n\\begin{definition}[Definition of determinant]\r\n    Consider $M\\in M_{n\\times n}(F)$ where $F=\\mathbb R$ or $\\mathbb C$ with columns $\\underline{C_a}$, then the determinant of $M$ is\r\n    \\begin{align*}\r\n        \\det M&=[\\underline{C_1},\\underline{C_2},\\ldots,\\underline{C_n}]\\\\\r\n        &=[M\\underline{e_1},M\\underline{e_2},\\ldots,M\\underline{e_n}]\\\\\r\n        &=\\epsilon_{ij\\ldots kl}M_{i1}M_{j2}\\cdots M_{k(n-1)}M_{ln}\\\\\r\n        &=\\sum_{\\sigma\\in S_n}\\epsilon(\\sigma)M_{\\sigma(1)1}M_{\\sigma(2)2}\\cdots M_{\\sigma(n)n}\r\n    \\end{align*}\r\n\\end{definition}\r\n\\begin{example}\r\n    1. The definition of determinant here in general coincides with the cases in $2$ and $3$ dimensional cases.\\\\\r\n    2. If $M$ is diagonal, then $\\det M$ is the product of all diagonal entries.\r\n    So $\\det I=1$.\\\\\r\n    3. If we have\r\n    $$M=\\left(\\begin{array}{@{}ccc|c@{}}\r\n        &&&0\\\\\r\n        &A&&\\vdots\\\\\r\n        &&&0\\\\\r\n        \\hline\r\n        0&\\dots&0&1\r\n    \\end{array}\\right)$$\r\n    Then $\\det M=\\det A$\r\n\\end{example}\r\n\\subsection{Properties of Determinants}\r\nIf we multiply one of the columns (or rows) of the matrix $M$ by a scalar $\\lambda$ to produce $M'$, we have $\\det M'=\\lambda\\det M$.\r\nFurthermore, if we interchange two adjascent columns, the determinant is negated.\r\nWe can see these directly from the definitive property of determinants.\r\nIn addition, $\\det M\\neq 0$ if and only if the columns are linearly independent.\r\n\\begin{proposition}\r\n    For any $n\\times n$ matrix $M$, $\\det M=\\det M^\\top$.\\\\\r\n    Equivalently, $[\\underline{C_1},\\underline{C_2},\\ldots,\\underline{C_n}]=[\\underline{R_1},\\underline{R_2},\\ldots,\\underline{R_n}]$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    We have\r\n    \\begin{align*}\r\n        [\\underline{C_1},\\underline{C_2},\\ldots,\\underline{C_n}]&=\\sum_{\\sigma\\in S_n}\\epsilon(\\sigma)M_{\\sigma(1)1}M_{\\sigma(2)2}\\cdots M_{\\sigma(n)n}\\\\\r\n        &=\\sum_{\\sigma\\in S_n}\\epsilon(\\sigma)M_{1\\sigma^{-1}(1)}M_{2\\sigma^{-1}(2)}\\cdots M_{n\\sigma^{-1}(n)}\\\\\r\n        &=\\sum_{\\sigma'\\in S_n}\\epsilon(\\sigma')M_{1\\sigma'(1)}M_{2\\sigma'(2)}\\cdots M_{n\\sigma'(n)}\\\\\r\n        &=[\\underline{R_1},\\underline{R_2},\\ldots,\\underline{R_n}]\r\n    \\end{align*}\r\n    Since the map $\\sigma\\to\\sigma'=\\sigma^{-1}$ is an automorphism on $S_n$ and $\\epsilon(\\sigma)=\\epsilon(\\sigma')$.\r\n\\end{proof}\r\nWe can evaluate determinants by expanding rows or columns.\r\n\\begin{definition}\r\n    For $M$ an $n\\times n$ matrix,\r\n    Define $M^{ia}$ be the determinant of the $(n-1)\\times (n-1)$ matrix obtained by deleting the row $i$ and column $a$ of $M$.\r\n    This is called a minor.\r\n\\end{definition}\r\n\\begin{proposition}\\label{det_formula}\r\n    $$\\forall a,\\det{M}=\\sum_i(-1)^{i+a}M_{ia}M^{ia}$$\r\n    $$\\forall i,\\det{M}=\\sum_a(-1)^{i+a}M_{ia}M^{ia}$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial but see later sections for the proof.\r\n\\end{proof}\r\nBy some trivial computation, we discover\r\n\\footnote{We definitely did not see that coming}\r\nthat matrices having many zeros would be easier to calculate, so it brings us to the ways to simplify the determinants.\\\\\r\nThe first thing we could do is row/column operations.\r\nIf we modify $M$ by mapping $\\underline{C_i}\\mapsto \\underline{C_i}+\\lambda\\underline{C_j}, i\\neq j$ (or equivalently on rows), then the determinant is not changed.\r\nThis follows immediate from multilinearity and total antisymmetry.\\\\\r\nPlus, as we stated above, if we interchange $\\underline{C_i},\\underline{C_j},i\\neq j$ (same for rows), then the determinant changes sign.\r\nThis can help us simplify the calculation greatly since we can produce a lot of $0$'s from there.\r\n\\begin{theorem}\r\n    For any $n\\times n$ matrices $M,N$, $\\det(MN)=\\det(M)\\det(N)$.\r\n\\end{theorem}\r\n\\begin{lemma}\r\n    $$\\epsilon_{i_1i_2\\ldots i_n}M_{i_1a_1}M_{i_2a_2}\\cdots M_{i_na_n}=\\epsilon_{a_1a_2\\ldots a_n}\\det{M}$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{proof}[Proof of the multiplicativity of determinants]\r\n    By the preceding lemma,\r\n    \\begin{align*}\r\n        \\det(MN)&=\\epsilon_{i_1i_2\\ldots i_n}(MN)_{i_11}\\cdots(MN)_{i_nn}\\\\\r\n        &=\\epsilon_{i_1i_2\\ldots i_n}M_{i_1k_1}N_{k_11}\\cdots M_{i_nk_n}N_{k_nn}\\\\\r\n        &=\\epsilon_{i_1i_2\\ldots i_n}M_{i_1k_1}\\cdots M_{i_nk_n}N_{k_11}\\cdots N_{k_nn}\\\\\r\n        &=\\det{M}\\epsilon_{k_1k_2\\ldots k_n}N_{k_11}\\cdots N_{k_nn}\\\\\r\n        &=\\det{M}\\det{N}\r\n    \\end{align*}\r\n    As desired.\r\n\\end{proof}\r\nNote that this would mean that $\\det$ is a group homomorphism.\r\nThere are a few consequences of the multiplicative property:\r\n\\begin{proposition}\r\n    1. If $M$ is invertible, then $\\det(M^{-1})=\\det(M)^{-1}$.\\\\\r\n    2. If $M$ is orthogonal, then $\\det(M)=\\pm 1$.\\\\\r\n    3. If $M$ is unitary, then $|\\det(M)|=1$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\subsection{Minors, Cofactors and Inverses}\r\n\\begin{definition}\r\n    Select a column $\\underline{C_a}$ of matrix $M$, we can write $\\underline{C_a}=M_{ia}\\underline{e_i}$, so\r\n    \\begin{align*}\r\n        \\det M&=[\\underline{C_1},\\underline{C_2},\\ldots,\\underline{C_a},\\ldots,\\underline{C_n}]\\\\\r\n        &=[\\underline{C_1},\\underline{C_2},\\ldots,M_{ia}\\underline{e_i},\\ldots,\\underline{C_n}]\\\\\r\n        &=M_{ia}[\\underline{C_1},\\underline{C_2},\\ldots,\\underline{e_i},\\ldots,\\underline{C_n}]\\\\\r\n        &=:\\sum_iM_{ia}\\Delta_{ia}\r\n    \\end{align*}\r\n    So\r\n    $$\\Delta_{ia}=[\\underline{C_1},\\underline{C_2},\\ldots,\\underline{e_i},\\ldots,\\underline{C_n}]$$\r\n    is called the cofactor.\r\n    Note that the cofactor is exactly the determinant of the matrix removing the row $i$ and column $a$.\r\n\\end{definition}\r\n\\begin{proof}[Proof of Proposition \\ref{det_formula}]\r\n    We know, then, that\r\n    $$\\Delta_{ia}=(-1)^{i+a}M^{ia}$$\r\n    by shuffling the rows and columns.\r\n    Therefore we have\r\n    $$\\det M=\\sum_iM_{ia}\\Delta_{ia}=\\sum_i(-1)^{i+a}M_{ia}M^{ia}$$\r\n    since columns and rows do not have real difference (we can do a transpose anyways), the two statements are proved.\r\n\\end{proof}\r\nNow we want to find our adjugate (or adjoint) $\\tilde{M}$.\r\nNote that in our above proof we can observe that $M_{ib}\\Delta_{ia}=\\det(M)\\delta_{ab}$, so we can easily define $\\tilde{M}_{ij}=\\Delta_{ji}$.\r\nSo $\\tilde{M}$ is the transpose of the matrix of cofactors, then the relation above becomes\r\n$$M\\tilde{M}=\\det(M)I$$\r\nas desired.\r\nThis justifies the existence of $\\tilde{M}$ and $\\det(M)$ in the full generality of $\\mathbb C^N$ from beginning of this section.\r\n\\subsection{System of Linear Equations}\r\nConsider a system of $n$ linear equations in $n$ unknowns $x_i$, written in vector-matrix form $A\\underline{x}=\\underline{b}$ where $A$ is some $n\\times n$ matrix.\r\nIf $\\det A$ is nonzero, then $A^{-1}$ exists, which implies an unique solution $\\underline{x}=A^{-1}\\underline{b}$.\r\nBut what if $\\det A$ is zero?\\\\\r\nWe know that if $\\underline{b}\\notin\\operatorname{Im}A$, then by definition there is no solution.\r\nBut if $\\underline{b}\\in\\operatorname{Im}A$, then the entire (shifted) space $\\underline{x_p}+\\ker{A}$ where $A\\underline{x_p}=\\underline{b}$ is exactly all the solutions.\r\nThis can be seen from the linear superposition of the solutions.\\\\\r\nNote that the formula $\\underline{x_p}+\\ker{A}$ also applied to the case for $\\det A\\neq 0$ since in that case $\\ker{A}=\\{\\underline{0}\\}$.\r\nIf $\\underline{u_i}$ is a basis for $\\ker{A}$, then the general solution is $\\underline{x_p}+a_i\\underline{u_i}$.\r\n\\begin{example}\r\n    Consider $A\\underline{x}=B$ where\r\n    $$A=\\begin{pmatrix}\r\n        1&1&a\\\\\r\n        a&1&1\\\\\r\n        1&a&1\r\n    \\end{pmatrix},\\underline{b}=\\begin{pmatrix}\r\n        1\\\\\r\n        c\\\\\r\n        1\r\n    \\end{pmatrix}$$\r\n    Now $\\det A=(a-1)^2(a+2)$.\r\n    So if $a\\notin \\{1,-2\\}$, then\r\n    $$\r\n    A^{-1}=\\frac{1}{(a-1)(a+2)}\r\n    \\begin{pmatrix}\r\n        -1&a+1&-1\\\\\r\n        -1&-1&a+1\\\\\r\n        a+1&-1&-1\r\n    \\end{pmatrix}$$\r\n    So\r\n    $$\\underline{x}=A^{-1}\\underline{b}=\\frac{1}{(1-a)(a+2)}\\begin{pmatrix}\r\n        2-c-ca\\\\\r\n        c-a\\\\\r\n        c-a\r\n    \\end{pmatrix},c\\in\\mathbb R$$\r\n    Geometrically, this solves to give a point.\r\n    If $a=1$, then\r\n    $$A=\\begin{pmatrix}\r\n        1&1&1\\\\\r\n        1&1&1\\\\\r\n        1&1&1\r\n    \\end{pmatrix}\\implies\\operatorname{Im}A=\\left\\{\\lambda\\begin{pmatrix}\r\n        1\\\\\r\n        1\\\\\r\n        1\r\n    \\end{pmatrix}:\\lambda\\in\\mathbb R\\right\\}$$\r\n    So there is no solution if $c\\neq 1$.\r\n    For $c=1$, since $(1,0,0)^\\top$ would be a particular solution, the solutions form the plane $(1,0,0)^\\top+\\ker A$, i.e. the general solution is of the form\r\n    $$\\begin{pmatrix}\r\n        1-\\lambda-\\mu\\\\\r\n        \\lambda\\\\\r\n        \\mu\r\n    \\end{pmatrix},\\lambda,\\mu\\in\\mathbb R$$\r\n    For $c=-2$, by again looking at the image we conclude that $c$ must be $-2$, in which case the same analysis gives us the general solution\r\n    $$\\begin{pmatrix}\r\n        1+\\lambda\\\\\r\n        \\lambda\\\\\r\n        \\lambda\r\n    \\end{pmatrix},\\lambda\\in\\mathbb R$$\r\n\\end{example}\r\nLet $\\underline{R_1},\\underline{R_2},\\underline{R_3}$ be the rows of $A$, then\r\n$$A\\underline{u}=\\underline{0}\\iff \\forall i\\in\\{1,2,3\\},\\underline{R_i}\\cdot\\underline{u}=0$$\r\nNote that the latter system of equations described planes through the origin.\r\nWe know that the solution of the homogeneous problem is equivalent to finding the kernel of $A$.\r\nIf $\\operatorname{rank}A=3$, then we must have $\\underline{u}=\\underline{0}$ since $\\{\\underline{R_i}\\}$ would be independent.\r\nIf $\\operatorname{rank}A=2$, then $\\{\\underline{R_i}\\}$ spans a plane, so the kernel is living along the line of normal to the plane.\r\nIf $\\operatorname{rank}A=1$, then the normals to the pairwise spanned planes are parallel, so the kernel is a plane.\\\\\r\nNow consider instead $A\\underline{u}=\\underline{b}$, then it happens iff $\\underline{R_i}\\cdot \\underline{u}=b_i$.\r\nIn this case, if $\\operatorname{rank}A=3$, then the normals of the planes described by the the system intersects at a point, thus there is an unique solution.\r\nIf $\\operatorname{rank}A=2$, then the planes may intersect, in which case the solution is a line, but it might not be the case.\r\nIf $\\operatorname{rank}A=1$, then the planes may coincide, in which case they are all the same, thus we have a plane of solution.\r\nBut again this might not be the case.\r\nTwo of them may coincide but that is not enough.\\\\\r\nBut how do you solve the equations and find the kernels systematically?\r\n\\subsection{Gaussian Elimination and Echelon Form}\r\nConsider $A\\underline{x}=\\underline{b}$ where $\\underline{x}\\in\\mathbb R^n,\\underline{b}\\in\\mathbb R^m$ and $A$ is an $m\\times n$ matrix, then we can solve it by Gaussian Elimination.\r\nIn general, we can reorder rows by row operations to rewrite original system in simplier form.\r\nNote that when we do row operations, we have to do it simultaneously on the matrix and on the vector.\r\nOur aim is to finally transform the matrix to the following form\r\n$$M=\\begin{pmatrix}\r\n    M_{11}&\\star&\\star&\\dots&\\star&\\star&\\dots&\\star\\\\\r\n    0&M_{22}&\\star&\\dots&\\star&\\star&\\dots&\\star\\\\\r\n    0&0&M_{33}&\\dots&\\star&\\star&\\dots&\\star\\\\\r\n    \\vdots&\\vdots&\\vdots&\\ddots&\\vdots&\\vdots&\\ddots&\\vdots\\\\\r\n    0&0&0&\\dots&M_{kk}&\\star&\\dots&\\star\\\\\r\n    0&0&0&\\dots&0&0&\\dots&0\\\\\r\n    \\vdots&\\vdots&\\vdots&\\ddots&\\vdots&\\vdots&\\ddots&\\vdots\\\\\r\n    0&0&0&\\dots&0&0&\\dots&0\r\n\\end{pmatrix}$$\r\nNote that the row rank equals the column rank.\r\nWe can use induction to prove that we can indeed use a way to obtain $M$ from $A$ in a finitely many number of row operations.\r\nNote that $\\det A=\\pm\\det M$", "meta": {"hexsha": "8856f88b1a8836f163ee0562983ad359c206ce76", "size": 17814, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/det.tex", "max_stars_repo_name": "david-bai-notes/IA-Vectors-and-Matrices", "max_stars_repo_head_hexsha": "7fc43486ec5276262d4058c9daaea12affdb6bac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/det.tex", "max_issues_repo_name": "david-bai-notes/IA-Vectors-and-Matrices", "max_issues_repo_head_hexsha": "7fc43486ec5276262d4058c9daaea12affdb6bac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/det.tex", "max_forks_repo_name": "david-bai-notes/IA-Vectors-and-Matrices", "max_forks_repo_head_hexsha": "7fc43486ec5276262d4058c9daaea12affdb6bac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.4770642202, "max_line_length": 242, "alphanum_fraction": 0.6593690356, "num_tokens": 6072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.8887587831798665, "lm_q1q2_score": 0.8163073781050527}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs, amsmath}    % need for subequations\n\\usepackage{verbatim}   % useful for program listings\n\\usepackage{color}      % use if color is used in text\n\\usepackage{hyperref}   % use for hypertext links, including those to external documents and URLs\n\n\\allowdisplaybreaks\n\n\\begin{document}\n\\section*{Feed Forward Neural Networks}\nIn this part of the tutorial I will go through the components of a fully connected feed forward neural network and show how gradient descent and backpropagation can be used to optimize the parameters of the neural network for a certain task. Our training data will be a collection of $N$ objects represented by input and output vectors $(\\textbf{x}_1, \\textbf{y}_1),...,(\\textbf{x}_N, \\textbf{y}_N)$. Each vector $\\textbf{x}_n$ has length $M$, where each entry of the vector represent a different feature (or measurement) of object $n$. The network itself has trainable parameters $\\textbf{W}^l$ and $\\textbf{b}^l$. The weights of the network are stored in the series of matrices $\\textbf{W}^l$, where the $W_{ij}^l$ entry of the tensor represents the weight of the connection from neuron $j$ in layer $l-1$ to neuron $i$ in layer $l$. The series of vectors $\\textbf{b}^l$ represent the offset the neurons in layer $l$, where the entry $b_{i}^l$ is the offset of neuron $i$ in layer $l$. The activations of and inputs to the neurons in the network can be represented with the following equations\n\\begin{equation}\t\n\\begin{split}\n\\textbf{a}^0 &= \\textbf{x} \\\\\n\\textbf{z}^l &= \\textbf{W}^l \\textbf{a}^{l-1} + \\textbf{b}^l \\\\\n\\textbf{a}^l &= \\sigma_l (\\textbf{z}^l) \\\\\n\\hat{\\textbf{y}} &= \\textbf{a}^{L},\n\\end{split}\n\\end{equation}\nwhere the subscript $n$, which denotes the training example, is suppressed so as to make the equations more transparent. Here $\\textbf{z}^l$ are the inputs to the neurons in layer $l$. By applying a sigmoidal activation function $\\sigma_l$ to the inputs $\\textbf{z}^l$ the activations $\\textbf{a}^l$ of the neurons in layer $l$ are obtained. In practice this activation function is usually a tanh, logistic, or relu function. This function can also be different for each layer of the network. For simplicity of notation the activations in the layer $l=0$ are the input vector $\\textbf{x}$, and the activations of the last layer $l=L$ are the predicted output $\\hat{\\textbf{y}}$. In component form these equations are.\n\\begin{equation}\n\\label{eq:nn_components}\n\\begin{split}\na_j^0 &= x_j \\\\\nz_i^l &= \\sum_{j=0} W_{ij}^l a_j^{l-1} + b_i^l \\\\\na_i^l &= \\sigma_l (z_i^l) \\\\\n\\hat{y} &= a_i^{L}\n\\end{split}\n\\end{equation}\n\n\\section*{Cost Functions}\nThe difference between the predicted output and the known output, for the $n^{th}$ training example, for a given set of parameters $\\textbf{W}^l$ and $\\textbf{b}^l$, can be quantified by defining the loss function $E_k(\\textbf{x}_n, \\textbf{y}_n ; \\textbf{W}^l, \\textbf{b}^l)$. For regression problems the cost function is often chosen to be the squared error loss\n\\begin{equation}\nE_n = \\frac{1}{2} \\left |\\hat{\\textbf{y}}_n - \\textbf{y}_n \\right|^2\n\\end{equation}\nFor classification problems with multiple classes the cross entropy loss is used. This requires the use of the softmax activation function in the last layer to ensure the output neurons of the network output probabilities between $0$ and $1$. The softmax activation function is\n\\begin{equation}\n\\hat{\\textbf{y}} = \\sigma_L(\\textbf{z}^{l-1}) = \\frac{e^{\\textbf{z}^{l-1}}}{\\text{sum} \\left( e^{\\textbf{z}^{l-1}} \\right)},\n\\end{equation}\nwhere $\\text{sum} \\left( e^{\\textbf{z}^{l-1}} \\right)$ is the sum of elements of the vector $e^{\\textbf{z}^{l-1}}$. The cross entropy loss of the $n^{th}$ training example is then given by the dot product between the true label vector $\\textbf{y}_n$ and the the log of the predicted labels from the network $\\log{\\hat{\\textbf{y}}_n}$\n\\begin{equation}\nE_n = - \\textbf{y}_n \\cdot \\log{\\hat{\\textbf{y}}_n}.\n\\end{equation} \nThe cost function for the entire training set is then the sum of the losses for each individual training example\n\\begin{equation}\nE \\left(\\textbf{W}^l, \\textbf{b}^l \\right) = \\frac{1}{N} \\sum_{n=0}^N E_n(\\textbf{x}_n, \\textbf{y}_n ; \\textbf{W}^l, \\textbf{b}^l) \n\\end{equation}\n\n\\subsection*{Minimizing the Cost Function with Backpropagation}\nOptimizing the network for a particular training set means minimizing the cost function $E \\left(\\textbf{W}^l, \\textbf{b}^l \\right)$ as a function of the weights and offsets parameters. In practice the number of trainable parameters can be very large so it is impractical to use brute force to minimize the cost function. Backpropagation is the traditional gradient descent algorithm combined with the use of the chain rule to calculate the derivatives of the cost function with respect to the training parameters. Gradient descent works off the observation that from any given point in parameter space the fastest way to get to a local minimum of the cost function is to travel in the negative direction of the gradient of the cost function at that point. Thus by updating the parameters according to the rules\n\\begin{equation}\n\\begin{split}\nW^l_{ij} & \\rightarrow W^l_{ij} - \\alpha \\frac{\\partial E}{\\partial W^l_{ij}} \\\\\nb^l_i & \\rightarrow b^l_{i} - \\alpha \\frac{\\partial E}{\\partial b^l_i} \n\\end{split}\n\\end{equation}\neventually the values of the trainable parameters will be such that the cost function is at a local minimum. The quantity $\\alpha$ is called the learning rate. It should be tuned to a value that ensures the gradient descent algorithm reaches a local minimum in a reasonable amount of time.\n\nFrom the above update rules it can be seen that gradient descent requires knowledge of the derivatives of the cost function with respect to the training parameters. In theory these derivatives can be calculated numerically, but this approach is inefficient and prone to numerical error. A better approach is to use the chain rule to write the derivatives as\n\\begin{equation}\n\\begin{split}\n\\frac{\\partial E_n}{\\partial W^l_{ij}} &= \\frac{\\partial E_n}{\\partial z_i^l } \\frac{\\partial z_i^l}{\\partial W^l_{ij}} \\\\\n\\frac{\\partial E_n}{\\partial b^l_{ij}} &= \\frac{\\partial E_n}{\\partial z_i^l} \\frac{\\partial z_i^l}{\\partial b^l_i}\n\\end{split}\n\\end{equation}\nFrom the definition of $z_i^l$ the inputs to the neurons in layers $l$ can be written $z_i^l=\\sum_{k=0} W_{ik}^l a_k^l + b_i^l$. Thus\n\\begin{equation}\n\\begin{split}\n\\frac{\\partial z_i^l}{\\partial W^l_{ij}} &= \\frac{\\partial}{\\partial W^l_{ij}} \\left( \\sum_{k=0} W_{ik}^l a_k^{l-1} + b_i^l \\right) = a_j^{l-1} \\\\\n\\frac{\\partial z_i^l}{\\partial b^l_i} &= \\frac{\\partial}{\\partial b^l_{i}} \\left( \\sum_{k=0} W_{ik}^l a_k^{l-1} + b_i^l \\right) = 1\n\\end{split}\n\\end{equation}\nFurthermore the derivative $\\frac{\\partial E_n}{\\partial z_i^l }$ has the interpretation of being the \"error\" of the network in layer $l$. This quantity is usually given the name $\\delta_i^l = \\frac{\\partial E_n}{\\partial z_i^l }$. Inserting these expressions into the above equations, the derivatives of the cost function at layer $l$ can be written in terms of the activation at layer $l-1$ and the errors at layer $l$.\n\\begin{equation}\n\\begin{split}\n\\frac{\\partial E_n}{\\partial W^l_{ij}} &= \\delta_i^l a_j^{l-1} \\\\\n\\frac{\\partial E_n}{\\partial b^l_{ij}} &= \\delta_i^l\n\\end{split}\n\\end{equation}\nNow all that's left is to write the errors in terms of the activations using the chain rule. For a hidden layer this error can be written as\n\\begin{equation}\n\\delta_j^{l-1} = \\frac{\\partial E_n}{\\partial z_j^{l-1} } = \\sum_k \\frac{\\partial E_n}{\\partial z_k^l } \\frac{\\partial z_k^l}{\\partial z_j^{l-1} }\n\\end{equation}\nUsing the definition of the inputs to the neurons in layer $l$\n\\begin{equation}\n\\begin{split}\n\\frac{\\partial z_k^l}{\\partial z_j^{l-1}} &= \\frac{\\partial }{\\partial z_j^{l-1}} \\left(\\sum_k W_{ik}^l a_k^{l-1} + b_k^l \\right) \\\\\n&= \\frac{\\partial }{\\partial z_j^{l-1}} \\left(\\sum_k W_{ik}^l \\sigma_l (z_k^{l-1}) + b_k^l \\right) \\\\\n&=W_{ij}^l \\sigma_l '(z_j^{l-1}) \n\\end{split}\n\\end{equation}\nThus\n\\begin{equation}\n\\begin{split}\n\\delta_j^{l-1} \n&= \\sum_k \\frac{\\partial E_n}{\\partial z_k^l } W_{kj}^l \\sigma_l '(z_j^{l-1}) \\\\\n&= \\sigma_l '(z_j^{l-1}) \\sum_k \\delta_k^l W_{kj}^l \n\\end{split}\n\\end{equation}\nFor the output layer\n\\begin{equation}\n\\delta_i^{L} \n= \\frac{\\partial E_n}{\\partial z_i^{L}} \n= \\frac{\\partial E_n}{\\partial \\hat{y}_i} \\frac{\\partial \\hat{y}_i}{\\partial z_i^{L}}  \n\\end{equation}\nFor the squared error loss function (suppressing the $n$ subscript) this becomes\n\\begin{equation}\n\\delta_i^{L} \n= \\frac{\\partial}{\\partial z_i^L} \\left(\\frac{1}{2} \\left |\\hat{\\textbf{y}} - \\textbf{y} \\right|^2 \\right) \\frac{\\partial \\hat{y}_i}{\\partial z_i^{L}}\n= \\left( \\hat{y}_i - y_i \\right) \\sigma_L'(z_i^L)\n\\end{equation}\nFor the cross entropy loss this becomes\n\\begin{equation}\n\\delta_i^{L} \n= - \\frac{\\partial}{\\partial \\hat{y}_i} \\left(\\textbf{y} \\cdot \\log{\\hat{\\textbf{y}}} \\right) \\frac{\\partial \\hat{y}_i}{\\partial z_i^{L}}\n= -\\frac{y_i}{\\hat{y}_i} \\sigma_L'(z_i^L)\n\\end{equation}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\end{document}", "meta": {"hexsha": "9b4493d755ff3b0a83a31c55333398f413b0d6f7", "size": 9086, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writing/backprop/backprop.tex", "max_stars_repo_name": "mattdornfeld/mattdornfeld.github.io", "max_stars_repo_head_hexsha": "68247c6f8250bb2c8201ff0536a1eb82a99215ca", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "writing/backprop/backprop.tex", "max_issues_repo_name": "mattdornfeld/mattdornfeld.github.io", "max_issues_repo_head_hexsha": "68247c6f8250bb2c8201ff0536a1eb82a99215ca", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "writing/backprop/backprop.tex", "max_forks_repo_name": "mattdornfeld/mattdornfeld.github.io", "max_forks_repo_head_hexsha": "68247c6f8250bb2c8201ff0536a1eb82a99215ca", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.3211678832, "max_line_length": 1095, "alphanum_fraction": 0.7158265463, "num_tokens": 2882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810451666345, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.8162049743538491}}
{"text": "\\section{Spectral Radius}\n\\label{sec:spectral_radius}\n\nThe spectral radius is a key parameter that determines some properties of the \necho state network weight matrix, which we will here denote as\n$\\matr{A} \\in \\mathbb{C} ^{n\\times n}$.\nIf $\\matr{A}$ has eigenvalues $\\lambda_1, ... , \\lambda_p$, where $p \\leq n$,\nthe spectral radius is defined as\n\\begin{equation}\n  \\rho(\\matr{A}) = \\max \\{|\\lambda_1|,...,|\\lambda_p|\\}.\n\\end{equation}\n\nThus, to obtain the spectral radius we somehow have to find a reasonably close estimate\nfor the absolute largest eigenvalue.\nFor very large matrices, it obviously becomes infeasible to calculate all eigenvalues\nwhich has a computational complexity of $O(n^3)$.\nOne method of quickly computing the largest eigenvalue is called \\textbf{inverse iteraion}\n(or inverse power method), but before diving into the exact algorithm we will go\nthrough a quick recap of the linear algebra that is necessary for inverse iteration.\n\nIf the matrix $\\matr{A}$ is diagonalizable, we can find a matrix $\\matr{S}$ such that\n\\begin{equation}\n  \\label{eq:diagonal_matrix}\n  \\matr{A} = \\matr{S}^{-1} {\\Lambda} \\matr{S},\n\\end{equation}\nwhere $\\Lambda$ is a diagonal matrix containing the eigenvalues\n$\\lambda_1,...,\\lambda_p$.\nFrom Eq.~\\ref{eq:diagonal_matrix} follows that:\n\\begin{equation}\n  \\label{eq:matrix_power}\n  \\matr{A} \\matr{A} = (\\matr{S}^{-1}\\Lambda\\matr{S})(\\matr{S}^{-1}\\Lambda\\matr{S})\n                    = \\matr{S}^{-1}\\Lambda^2\\matr{S},\n\\end{equation}\nwhich means that for any continuous function one can write:\n\\begin{equation}\n  f(\\matr{A}) = \\matr{S}^{-1} f(\\Lambda) \\matr{S},\n\\end{equation}\nbecause every continuous function can be approximated by a polynomial function.\nIn our case it will turn out to be very useful, that\n\\begin{equation}\n  \\label{eq:inverse_ev}\n  (\\matr{A} - \\sigma \\mathbb{I})^{-1} =\n        \\matr{S}^{-1} (\\Lambda - \\sigma \\mathbb{I})^{-1} \\matr{S},\n\\end{equation}\n\nbecause only the eigenvalues (on the diagonal of $\\Lambda$) are affected by\nthe inversion, but the eigenvectors stay exactly the same.\n\n\n\\subsubsection{Power Method}\n\\label{ssub:power_method}\nSuppose $\\vec{x} \\in \\mathbb{C} ^n$, that can be written as the sum of eigenvectors\nand eigenvalues:\n\n\\begin{equation}\n  \\vec{x} = \\lambda_1\\vec{e}_1 + ... + \\lambda_p\\vec{e}_p,\n\\end{equation}\n\nwhere $|\\lambda_1| > |\\lambda_2| > ... > |\\lambda_p|$ it follows that:\n\\begin{equation}\n  \\label{eq:sum_ev}\n  \\matr{A}^j \\vec{x} = \\lambda_1^j\\vec{e}_1 + ... + \\lambda_p^j\\vec{e}_p,\n  =  \\lambda_1^j \\sum_{i=0}^{p} \\bigg(\\frac{\\lambda_i}{\\lambda_1}\\bigg)^j \\vec{e}_i,\n\\end{equation}\n\nwhich means that for large enough $j$ Eq.~\\ref{eq:sum_ev} converges to:\n\\begin{equation}\n  \\label{eq:power_method}\n  \\vec{\\mu} = \\matr{A}^j \\vec{x} \\rightarrow \\lambda_1^j \\vec{e_1}.\n\\end{equation}\n\nEq.~\\ref{eq:power_method} is called the \\textbf{power method} for finding eigenvalues.\nFrom the estimate $\\vec{\\mu}$ of the largest eigenvector one can easily obtain the estimate\n$\\sigma$ of the corresponding eigenvalue by applying the Rayleigh quotient:\n\\begin{equation}\n  \\label{eq:rayleigh_quotient}\n  \\sigma = \\frac{\\vec{\\mu}^* \\matr{A} \\vec{\\mu}}{||\\vec{\\mu}^* \\vec{\\mu}||}\n\\end{equation}\n\nFrom Eq.~\\ref{eq:sum_ev} one can quickly see that it has an error of $O(|\\lambda_2/\\lambda_1|^j)$,\nwhich means that it converges very slowly if the two largest eigenvalues are very\nclose to each other.\n\n\n\\subsubsection{Inverse Iteration}\n\\label{ssub:inverse_iteration}\nThe inverse iteration method aims to solve the problem of slow convergence of the\npower method by manipulating the eigenvalues of the iterated matrix favourably.\n\nSuppose we can find a reasonably close estimate $\\sigma$ of an eigenvector $\\lambda_i$\nof $\\matr{A}$, then the matrix $(\\matr{A} - \\sigma \\mathbb{I})$ is almost singular,\nbecause on of the elements of its diagonalized counterpart is close to zero.\n\\footnote{The estimate $\\sigma$ is often called shift, which is why this method is also known\nas the \\textit{inverse shift method}.}\nThis means, according to Eq.~\\ref{eq:inverse_ev} that\n$(\\matr{A} - \\sigma \\mathbb{I})^{-1}$ has one very large eigenvalue,\nwhich we can exploit for a fast conversion of the power method.\nStarting from a random vector $\\vec{x}_0$, the iterative update equation for the\ninverse power method reads:\n\\begin{equation}\n  \\label{eq:inverse_iteration}\n  \\vec{x}_{i+1} = (\\matr{A} - \\sigma \\mathbb{I})^{-1} \\vec{x}_i,\n\\end{equation}\nThe shift $\\sigma$ is updated at each iteration by using the Rayleigh\nquotient Eq.~\\ref{eq:rayleigh_quotient}.\nThis results in an increasingly good estimate of the desired eigenvalue, which\nin turn speeds up the convergence of the inverse iteration.\nThis only becomes a problem once the calculated shift hits the exact value of\nan eigenvalue of $\\matr{A}$. Then the shifted matrix becomes singular.\n\\\\\nEq.~\\ref{eq:inverse_iteration} can be rewritten in terms of a linear system solver:\n\\begin{equation}\n  \\vec{x}_{i+1} = \\text{linearSolve}(\\matr{A} - \\sigma \\mathbb{I}, \\text{ }\\vec{x}_i)\n\\end{equation}\nin order to exploit the speedup of solving a linear system compared to an inverse\nmatrix computation, which results in especially large speedups as soon as the\nmatrix $\\matr{A}$ is very sparse.\n\nThe last remaining problem to solve is a reasonable estimate for the largest eigenvalue\nof $\\matr{A}$, preferably and upper bound in order to make sure that the iteration\ndoes not converge to the second largest eigenvalue.\nThe most straight forward thing to do here would be taking the Frobenius norm of $\\matr{A}$,\nwhich provides an intuitive upper bound of the spectral radius:\n\\begin{align}\n  |\\lambda|^k ||\\vec{e}|| = ||\\lambda^k \\vec{e}||\n  &= ||\\matr{A}^k \\vec{e}|| \\leq ||\\matr{A}^k|| \\cdot ||\\vec{e}|| \\\\\n  |\\lambda^k| &\\leq ||A^k||\n\\end{align}\nA faster way of doing this is based on the so called Gershgorin disks \\cite{Gershgorin}.\nIf $a_{ij}$ is an element of the complex matrix $\\matr{A}$ we can define\n$R_i=\\sum_{j\\neq i}|a_{ij}|$ as the radius of a disk $D(a_{ii}, R_i)$ centered at\n$a_{ii}$.\nGershgorin's circle theorem states that the eigenvalues of $\\matr{A}$ have lie\nwithin the Gershgorin disks.\nPicking the the largest $R_i$ in combination with the largest $a_{ii}$ as an upper\nbound thus provides an upper bound for the largest eigenvalue in much less than\n$O(n^3)$ (complexity of the Frobenius norm).\n\nThis iterative inverse method typically converges in a few steps, which makes it\nvastly superior to calculating every eigenvalue and picking its maximum in order\nto find the spectral radius.\\\\\n\n%%Fig.~\\ref{fig:inv_iter_speedup} demonstrates that by this method we can obtain\n%%the spectral radius of a matrix about 40 times faster than by calculating\n%%all eigenvalues by hand and picking the largest one.\n%\n%%\\begin{figure}[h]\n%%  \\centering\n%%  \\includegraphics[width=0.8\\linewidth]{inv_iter_speedup.png}\n%%  \\caption{Speedup of inverse iteration algorithm compared to the Numpy eigenvalue\n%%  calculation. CREDITS TO JAMES AVERY}\n%%  \\label{fig:inv_iter_speedup}\n%%\\end{figure}\n%\n%%if diagonalizaable:\n%%else:\n%%spectral theorem with defective part etc.\n%\n%% and: http://www.cs.cornell.edu/~bindel/class/cs6210-f09/lec26.pdf\n", "meta": {"hexsha": "87f20742bc826b9e06b53395830c01e55dd23da8", "size": 7177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "backmatter/eigenvalues.tex", "max_stars_repo_name": "nmheim/thesis", "max_stars_repo_head_hexsha": "feafb9f5c7bcf6b6473d3fca844a33dc25dcff0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-22T12:17:23.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-22T12:17:23.000Z", "max_issues_repo_path": "backmatter/eigenvalues.tex", "max_issues_repo_name": "nmheim/thesis", "max_issues_repo_head_hexsha": "feafb9f5c7bcf6b6473d3fca844a33dc25dcff0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "backmatter/eigenvalues.tex", "max_forks_repo_name": "nmheim/thesis", "max_forks_repo_head_hexsha": "feafb9f5c7bcf6b6473d3fca844a33dc25dcff0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.85625, "max_line_length": 98, "alphanum_fraction": 0.7273233942, "num_tokens": 2169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.8933094003735664, "lm_q1q2_score": 0.8161958188670109}}
{"text": "\\subsection{Model Selection}\n\\label{sec:evidence}\n\nGiven a model class $M$ and a vector of model parameters $\\theta$, we\ncan factor the joint distribution $P(\\theta,D|M)$ as:\n\n\\begin{equation}\nP(\\theta,D|M) = P(\\theta|D,M)\\, P(D|M) = P(D|\\theta,M)\\, P(\\theta|M),\n\\end{equation}\n\nwhich gives us Bayes' Theorem:\n\n\\begin{equation}\nP(\\theta|D,M) = {{P(D|\\theta,M)\\, P(\\theta|M)}\\over{P(D|M)}}\n\\end{equation}\n\nWe identify $P(\\theta|M)$ as the prior, $P(D|\\theta, M)$ as the\nlikelihood, and $P(\\theta|D,M)$ as the posterior distribution for\n$\\theta$, of which the chain is an estimate.\n\nThe quantity $P(D|M)$ is known as the {\\it evidence}, and can be seen\nto play the role of a normalizing factor:\n\n\\begin{equation}\nP(D|M) = \\integral{}{}{P(D|\\theta,M)\\, P(\\theta|M)}{\\theta}.\n\\end{equation}\n\nIn the context of parameter fitting, $P(D|M)$ is usually left\nunspecified, as only the ratio of the posterior is used to choose\nbetween different values of parameters.\n\nWhen comparing different classes of models, however, the evidence\nplays a central role, as it represents the probability of the data\ngiven a particular model, marginalized over all possible values of\nthat model's parameters $\\theta$.\n\nWhen considering two classes of models, the evidence ratio\n$\\mathcal{E}$ is defined as:\n\n\\begin{equation}\n{{P(D|M_1)}\\over{P(D|M_2)}} = {{\\integral{}{}{P(D|\\alpha,M_1)\\, P(\\alpha|M_1)}{\\alpha}}\\over{\\integral{}{}{P(D|\\beta, M_2)\\, P(\\beta|M_2)}{\\beta}}}\n\\end{equation}\n\nNote that the evidence ratio contains the usual ``goodness of fit''\ncriterion in the form of the likelihood $P(D|M)$; i.e.,\nif our two ``hypotheses '' just consist of two sets of parameter\nvalues $P(\\alpha|M_1) = \\delta(\\alpha_0)$ and\n$P(\\beta|M_2) = \\delta({\\beta_0})$, the we recover the usual\nlikelihood ratio:\n\n\\begin{equation}\n\\mathcal{E} = {{P(D|\\alpha_0)}\\over{P(D|\\beta_0)}}\n\\end{equation}\n\nIf the hypotheses are more complex, however, the evidence ratio\nretains a dependence on the integral over the priors, something that\nis often referred to as the {\\it Ockham factor}; i.e., models are\npenalized if only a small part of the prior parameter range matches\nthe data.  If for example, our hypotheses consisted of two different\npriors for the same parameters $\\vec{\\alpha}$, where the likelihood\nwas 1 for $\\vec{\\alpha} < \\vec{\\alpha}_{max}$ and 0 everwhere\nelse, and where $H_1$ allowed only a fraction $f$ of parameter space\nover which the likelihood was non-zero, while $H_2$ allowed the full\nrange of parameter space over which the likelihood was non-zero, then\n\n\n\\begin{equation}\n\\mathcal{E} = {{\\integral{}{}{P(\\alpha|M_1)}{\\alpha}}\\over{\\integral{}{}{P(\\alpha|M_2)}{\\alpha}}} = f,\n\\end{equation}\n\nthat is, $H_1$ would be disfavored over $H_2$ by that same factor $f$,\neven though both hypotheses contain some range of $\\vec{\\alpha}$ over\nwhich the model fits the data equally well.\n\nIn the context of Markov chains, one way to estimate the evidence\nproceeds as follows:\n\n\\begin{equation}\nP(\\theta|D,M)\\, P(D|M) = {{P(D|\\theta,M)\\, P(\\theta|M)}}\n\\end{equation}\n\nor\n\n\\begin{equation}\nP(D|M)\\, {{P(\\theta|D,M)}\\over{P(D|\\theta,M)}} = P(\\theta|M)\n\\end{equation}\n\nwhence \n\n\\begin{equation}\nP(D|M)\\, \\integral{}{}{{{P(\\theta|D,M)}\\over{P(D|\\theta,M)}}}{\\theta} = \\integral{}{}{P(\\theta|M)}{\\theta} = 1.\n\\end{equation}\n\nThe term \n\n\\begin{equation}\n\\left<P(D|\\theta,M)^{-1}\\right> \\equiv \\integral{}{}{{{P(\\theta|D,M)}\\over{P(D|\\theta,M)}}}{\\theta}\n\\end{equation}\n\nis just the average of $P(D|\\theta,M)^{-1}$ over the posterior.\nIn the context of Markov chains, then, the quantity\n\n\\begin{equation}\n\\hat{Z} \\equiv {{1}\\over{\\left<P(D|\\theta,M)^{-1}\\right>}},\n\\end{equation}\n\nwhere $\\left<P(D|\\theta,M)^{-1}\\right>$ is the average value of the\ninverse likelihood over the chain, can be taken as an estimate of the\nevidence.\n", "meta": {"hexsha": "cf0272e307fc49e268101fbc45936f8604fff3cd", "size": 3791, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "help/evidence.tex", "max_stars_repo_name": "erikleitch/climax", "max_stars_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-01T05:15:31.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-01T05:15:31.000Z", "max_issues_repo_path": "docs/evidence.tex", "max_issues_repo_name": "erikleitch/climax", "max_issues_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/evidence.tex", "max_forks_repo_name": "erikleitch/climax", "max_forks_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-02T19:35:55.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-07T00:54:51.000Z", "avg_line_length": 34.4636363636, "max_line_length": 147, "alphanum_fraction": 0.6953310472, "num_tokens": 1176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122744874229, "lm_q2_score": 0.8519527963298946, "lm_q1q2_score": 0.8160960408882895}}
{"text": "% !TeX root = thoughts.tex\n\\begin{appendices}\n\\section{\\label{APP:affinenormal}Affine transformations of normal distributions}\nProving the relationship's of the means and covariances between affine transformations is easily done from the definition of linear transformations and covariances.\n\nFor the means $\\overline{\\mathbf{x}}$ and $\\overline{\\mathbf{y}}$ of respectively the normal distributions $\\mathbf{X}$ and $\\mathbf{Y}$ we use the definition of the transformation of $\\mathbf{X}$ to $\\mathbf{Y}$. $E\\left\\{ a \\right\\}$ is the expected value of $a$.\n\n\\begin{align}\n\t\\overline{\\mathbf{y}} &= E\\left\\{ \\mathbf{y} \\right\\}\\nonumber\\\\\n\t&=E\\left\\{ \\mathbf{L}\\mathbf{x} + \\bm{c} \\right\\}\\nonumber\\\\\n\t&=\\mathbf{L}E\\left\\{ \\mathbf{x}  \\right\\}+ \\bm{c}\\nonumber\\\\\n\t&=\\mathbf{L}\t\\overline{\\mathbf{x}}+ \\bm{c}\\\\\n\t\\square \\span \\nonumber\n\\end{align}\n\nFor the covariances we use it's definition:\n\n\\begin{align}\n\t\\mathbf{\\Sigma}_\\mathbf{y} \n\t&\\triangleq \n\tE\\left\\{ \n\t\t\\left( \\mathbf{y} -  \\overline{\\mathbf{y}} \\right) \n\t\t\\left( \\mathbf{y} -  \\overline{\\mathbf{y}} \\right)^T\n\t\\right\\} \\nonumber \\\\\n\t&= \n\tE\\left\\{ \n\t\\left( \\mathbf{L}\\mathbf{x} + \\bm{c} -   \\mathbf{L}\\overline{\\mathbf{x}} + \\bm{c} \\right) \n\t\\left( \\mathbf{L}\\mathbf{x} + \\bm{c} -   \\mathbf{L}\\overline{\\mathbf{x}} + \\bm{c} \\right)^T\n\t\\right\\}  \\nonumber \\\\\n\t&= \n\tE\\left\\{ \n\t\\left( \\mathbf{L}\\mathbf{x} -   \\mathbf{L}\\overline{\\mathbf{x}} \\right) \n\t\\left( \\mathbf{L}\\mathbf{x} -   \\mathbf{L}\\overline{\\mathbf{x}} \\right)^T\n\t\\right\\} \\nonumber \\\\\n\t&= \n\tE\\left\\{ \n\t\\mathbf{L}(\\mathbf{x} - \\overline{\\mathbf{x}})  \n\t(\\mathbf{x} - \\overline{\\mathbf{x}} )^T \\mathbf{L}^T\n\t\\right\\} \\nonumber \\\\\n\t&= \n\t\\mathbf{L}\\;\n\tE\\left\\{ \n\t(\\mathbf{x} - \\overline{\\mathbf{x}})  \n\t(\\mathbf{x} - \\overline{\\mathbf{x}} )^T \n\t\\right\\} \n\t\\mathbf{L}^T \\nonumber \\\\\n\t&= \n\t\\mathbf{L}\\;\n\t\\mathbf{\\Sigma}_\\mathbf{x} \n\t\\mathbf{L}^T\\\\\n\t\\square \\span \\nonumber \n\\end{align}\n\n\\end{appendices}", "meta": {"hexsha": "385693d8ac04daa5f8a86f8763c95a07e9c5257e", "size": 1918, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thoughts/appendix.tex", "max_stars_repo_name": "larsgeb/hmc-documentation", "max_stars_repo_head_hexsha": "e302375a870359174254cc4e6c0515ef255dea3e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thoughts/appendix.tex", "max_issues_repo_name": "larsgeb/hmc-documentation", "max_issues_repo_head_hexsha": "e302375a870359174254cc4e6c0515ef255dea3e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thoughts/appendix.tex", "max_forks_repo_name": "larsgeb/hmc-documentation", "max_forks_repo_head_hexsha": "e302375a870359174254cc4e6c0515ef255dea3e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.5185185185, "max_line_length": 265, "alphanum_fraction": 0.6313868613, "num_tokens": 781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868804, "lm_q2_score": 0.8840392771633079, "lm_q1q2_score": 0.8160028737331151}}
{"text": "\\section{Orthogonal Complement and Adjoint Map}\r\n\\begin{definition}\r\n    Suppose $V=U\\oplus W$.\r\n    The projection operator $\\pi=\\pi_W:V\\to W$ into $W$ is defined via $u+w\\mapsto w$ for any $u\\in U,w\\in W$.\r\n\\end{definition}\r\nEasy to see that $\\pi$ is linear and $\\pi^2=\\pi$\r\n\\begin{remark}\r\n    We have $\\pi_U=\\operatorname{id}-\\pi_W$.\r\n\\end{remark}\r\nOf course, in the case where $U=W^\\perp$, we can have something better.\r\n\\begin{lemma}\r\n    Let $V$ be an inner product space and $W\\le V$ finite dimensional subspace of $V$, then:\\\\\r\n    (a) If $\\{e_i\\}$ is an orthonormal basis of $W$, then $\\forall v\\in V,\\pi(v)=\\sum_i\\langle v,e_i\\rangle e_i$.\\\\\r\n    (b) $\\forall v\\in V,w\\in W,\\|v-\\pi(v)\\|\\le\\|v-w\\|$ with equality iff $w=\\pi(v)$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Just observe that $v-\\pi(v)\\in W^\\perp$ which is known to be a complementary subspace of $W$.\r\n    This gives (a) immediately, and for (b) we have $\\|v-w\\|^2=\\|v-\\pi(v)+\\pi(v)-w\\|^2=\\|v-\\pi(v)\\|^2+\\|\\pi(v)-w\\|^2\\ge \\|v-\\pi(v)\\|$.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Let $V,W$ be finite dimensional inner product spaces and $\\alpha\\in L(V,W)$.\r\n    Then there is a unique linear map $\\alpha^\\ast:W\\to V$ such that $\\forall v\\in V,w\\in W,\\langle \\alpha(v),w\\rangle=\\langle v,\\alpha^\\ast(w)\\rangle$.\r\n    Moreover, if $B,C$ are orthonormal bases of $V,W$, then $[\\alpha^\\ast]_{C,B}=(\\overline{[\\alpha]}_{B,C})^\\top$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Brute-force computation.\r\n\\end{proof}\r\n\\begin{definition}\r\n    This map $\\alpha^\\ast$ is called the adjoint of $\\alpha$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    One might notice that we used the same notation for adjoint and dual of a map.\r\n    This (intentional) abuse of notation can be justified by considering the linear isomorphisms $\\psi_{R,V}:V\\to V^\\ast,\\psi_{R,W}:W\\to W^\\ast$ via $\\psi_{R,V}(v)=\\langle \\cdot,v\\rangle,\\psi_{R,W}(w)=\\langle \\cdot,w\\rangle$ which immediately satisfies $\\alpha^\\ast_{\\rm adjoint}=\\psi_{R,V}^{-1}\\circ\\alpha^\\ast_{\\rm dual}\\circ\\psi_{R,W}$.\r\n    \\[\r\n        \\begin{tikzcd}\r\n            W^\\ast\\arrow{r}{\\alpha^\\ast_{\\rm dual}}&V^\\ast\\\\\r\n            W\\arrow{u}{\\psi_{R,W}}\\arrow[swap]{r}{\\alpha^\\ast_{\\rm adjoint}}&V\\arrow[swap]{u}{\\psi_{R,V}}\r\n        \\end{tikzcd}\r\n    \\]\r\n\\end{remark}\r\n\\begin{definition}\r\n    Let $V$ be an inner product space.\r\n    A map $\\alpha\\in L(V)$ is self-adjoint if $\\alpha=\\alpha^\\ast$, i.e. $\\forall v,w\\in V,\\langle\\alpha(v),w\\rangle=\\langle v,\\alpha(w)\\rangle$.\\\\\r\n    It is called an isometry if $\\alpha^\\ast\\circ\\alpha=\\operatorname{id}$, or $\\langle\\alpha(v),\\alpha(w)\\rangle=\\langle v,w\\rangle$ for any $v,w\\in V$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    By the polarisation identity, $\\alpha$ is an isometry iff $\\|\\alpha(v)\\|=\\|v\\|$ for any $v\\in V$.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    Let $V$ be a finite dimensional inner product space over $\\mathbb R$ (resp. $\\mathbb C$).\r\n    Then $\\alpha\\in L(V)$ is self-adjoint iff for any orthonormal basis $B$ of $V$, $[\\alpha]_B$ is symmetric (resp. Hemitian).\r\n    It is an isometry iff for any orthonormal basis $B$ of $V$, $[\\alpha]_B$ is orthonormal (resp. unitary).\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\nThe collection of isometries are naturally subgroups of $L(V)$.\r\n\\begin{definition}\r\n    Let $V$ be a finite dimensional inner product space over a field $F=\\mathbb R$ or $\\mathbb C$.\r\n    The subgroup of isometries $\\{\\alpha\\in L(V):\\alpha^\\ast\\circ\\alpha=\\operatorname{id}\\}\\le L(V)$ is called the orthogonal group $O(V)$ of $V$ when $F=\\mathbb R$ and the unitary group $U(V)$ of $V$ when $F=\\mathbb C$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    Fix an orthonormal basis $\\{e_i\\}$ of $V$.\r\n    Then there is a one-to-one correspondence between the isometries in $V$ and the orthonormal bases of $V$ via $\\alpha\\leftrightarrow \\{\\alpha(e_i)\\}$.\r\n\\end{remark}", "meta": {"hexsha": "5f79bd8f95802f232cfd48acb0490f6887f7374e", "size": 3831, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "22/ortho.tex", "max_stars_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_stars_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "22/ortho.tex", "max_issues_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_issues_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "22/ortho.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.9384615385, "max_line_length": 340, "alphanum_fraction": 0.6421299922, "num_tokens": 1285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.9032942132122422, "lm_q1q2_score": 0.8159404320953434}}
{"text": "\\section{The Classification of Finite Abelian Groups}\r\nWe will prove (the generalization of) the following theorem later when we look at modules:\r\n\\begin{theorem}\\label{classify_fin_abe}\r\n    Every finite abelian group is isomorphic to a product of cyclic groups.\r\n\\end{theorem}\r\nIn this section, we shall look at the uniqueness criterion of this statement.\r\nIn fact, this representation is not unique in general, but we can get some sort of a uniqueness statement.\r\n\\begin{lemma}\r\n    If $m,n$ are coprime, then $C_m\\times C_n\\cong C_{mn}$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Let $g_m$ be the generator of $C_m$ and $g_n$ be that of $C_n$, then $(g_m,g_n)\\in C_m\\times C_n$ has order $\\gcd(m,n)=mn$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Let $G$ be a finite abelian group, then $G\\cong C_{n_1}\\times C_{n_2}\\times\\cdots\\times C_{n_k}$ such that any $n_i$ is a prime power\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Let $n$ be a positive integer, then $n=p_1^{e_1}\\cdots p_r^{e_r}$ where $p_i$ are distinct primes, then\r\n    $$C_n\\cong C_{p_1^{e_1}}\\times \\cdots\\times C_{p_r^{e_r}}$$\r\n    by the preceding lemma.\r\n    Combining this with the theorem gives the result.\r\n\\end{proof}\r\nIn fact, what we will prove is the following refinement of Theorem \\ref{classify_fin_abe}.\r\n\\begin{theorem}\\label{fin_abe_struct}\r\n    Let $G$ be a finite abelian group, then $G\\cong C_{d_1}\\times C_{d_2}\\times\\cdots\\times C_{d_t}$ such that $1<d_1|d_2|d_3|\\cdots|d_{t-1}|d_t$.\r\n\\end{theorem}\r\n\\begin{remark}\r\n    The integers $n_1,n_2,\\ldots$ are up to a reordering, and $d_1,d_2,\\ldots$ are uniquely determined by the group $G$.\r\n    The proof (which we omit) works by counting the elements of $G$ with every possible order (it is enough to consider prime powers though).\r\n\\end{remark}\r\n\\begin{example}\r\n    1. Abelian groups of order $8$ can only be $C_8,C_2\\times C_4,C_2\\times C_2\\times C_2$.\\\\\r\n    2. Abelian groups of order $12$ can only be $C_2\\times C_2\\times C_3\\cong C_2\\times C_6,C_4\\times C_3\\cong C_{12}$\r\n\\end{example}\r\n", "meta": {"hexsha": "b7dbce121d1c7016b06b756a2aad8e33e0578f1b", "size": 2010, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/finabe.tex", "max_stars_repo_name": "david-bai-notes/IB-Groups-Rings-and-Modules", "max_stars_repo_head_hexsha": "f4d4cc7141d30f03f775a67afc5a724db6a35da6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6/finabe.tex", "max_issues_repo_name": "david-bai-notes/IB-Groups-Rings-and-Modules", "max_issues_repo_head_hexsha": "f4d4cc7141d30f03f775a67afc5a724db6a35da6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6/finabe.tex", "max_forks_repo_name": "david-bai-notes/IB-Groups-Rings-and-Modules", "max_forks_repo_head_hexsha": "f4d4cc7141d30f03f775a67afc5a724db6a35da6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.4285714286, "max_line_length": 147, "alphanum_fraction": 0.7109452736, "num_tokens": 671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.9372107861416413, "lm_q1q2_score": 0.8159331440444697}}
{"text": "\\chapter{Multiplying Polynomials in Python}\n\nAt this point, you have created a nice toolbox of functions for\ndealing with lists of coefficients as polynomials. Create a file called \\filename{poly.py} and copy the folowing functions into it:\n\\begin{itemize}\n\\item \\pyfunction{evaluate\\_polynomial}\n\\item \\pyfunction{polynomial\\_to\\_string}\n\\item \\pyfunction{add\\_polynomials}\n\\item \\pyfunction{scalar\\_polynomial\\_multiply}\n\\item \\pyfunction{subtract\\_polynomial}\n\\end{itemize}\n\nNow create another file in the same directory called \\filename{test.py}. Type this into that file:\n\\begin{Verbatim}\nimport poly\n\npolynomial_a = [9.0, -4.0, 3.0, -5.0]\nprint('Polynomial A =', poly.polynomial_to_string(polynomial_a))\n\npolynomial_b = [-9.0, 0.0, 4.0, 2.0, 1.0]\nprint('Polynomial B =', poly.polynomial_to_string(polynomial_b))\n\n# Evaluation\nvalue_of_b = poly.evaluate_polynomial(polynomial_b, 3)\nprint('Polynomial B at 3 =', value_of_b)\n\n# Adding\na_plus_b = poly.add_polynomials(polynomial_a, polynomial_b)\nprint('A + B =', poly.polynomial_to_string(a_plus_b))\n\n# Scalar multiplication\nb_scalar = poly.scalar_polynomial_multiply(-3.2, polynomial_b)\nprint('-3.2 * Polynomial B =', poly.polynomial_to_string(b_scalar))\n\n# Subtraction\na_minus_b = poly.subtract_polynomial(polynomial_a, polynomial_b)\nprint('A - B =', poly.polynomial_to_string(a_minus_b))\n\\end{Verbatim}\n\nWhen you run it, you should get the following:\n\\begin{Verbatim}\nPolynomial A = -5.0x^3 + 3.0x^2 + -4.0x + 9.0\nPolynomial B = 1.0x^4 + 2.0x^3 + 4.0x^2 + -9.0\nPolynomial B at 3 = 162.0\nA + B = 1.0x^4 + -3.0x^3 + 7.0x^2 + -4.0x\n-3.2 * Polynomial B = -3.2x^4 + -6.4x^3 + -12.8x^2 + 28.8\nA - B = -1.0x^4 + -7.0x^3 + -1.0x^2 + -4.0x + 18.0\n\\end{Verbatim}\n\nNow you are ready to implement multiplication of polynomials. The function will look like this:\n\\begin{Verbatim}\ndef multiply_polynomials(a, b):\n  ...Your code here...\n\\end{Verbatim}\nIt will return a list of coefficients.\n\nIn an exercise in the last chapter, you were asked `` Let's say I have\ntwo polynomials, $p_1$ and $p_2$.  $p_1$ has degree 23.  $p_2$ has\ndegree 12.  What is the degree of their product?'' The answer was $23 +\n12 = 35$.\n\nIn our implementation, a polynomial of degree 23 is held in a list of length 24.\n\nIn Python we wil be trying to multiply a polynomial $a$ and a\npolynomial $b$ represented as lists. What is the degree of that product?\n\\begin{Verbatim}\n      result_degree = (len(a) - 1) + (len(b) - 1)\n\\end{Verbatim}\n\nNow, we need to create an array of zeros that is one longer than that. Here is a cute Python trick: if you have a list, you can replicate it using the * operator. \n\\begin{Verbatim}\na = [5,7]\nb = a * 4\nprint(b)\n# [5, 7, 5, 7, 5, 7, 5, 7]\n\\end{Verbatim}\n\nHere's how you will get a list of zeros:\n\\begin{Verbatim}\n      result = [0.0] * (result_degree + 1)\n\\end{Verbatim}\n\nWe will step through $a$ getting the index and value of each entry. You can do this in one line using \\pyfunction{enumerate}:\n\\begin{Verbatim}\n      for a_degree, a_coefficient in enumerate(a):\n\\end{Verbatim}\nFor each of those, we will step through the entire $b$ polynomial. As\nyou multiply together each term, you will add it to appropriate\ncoefficient of the result.\n\nHere is the whole function:\n\\begin{Verbatim}\ndef multiply_polynomials(a, b): # What is the degree of the resulting\npolynomial?  result_degree = (len(a) - 1) + (len(b) - 1)\n\n    # Make a list of zeros to hold the coefficents result = [0.0] *\n    (result_degree + 1)\n\n    # Iterate over the indices and values of a for a_degree,\n    a_coefficient in enumerate(a):\n\n        # Iterate over the indices and values of b for b_degree,\n        b_coefficient in enumerate(b):\n\n            # Calculate the resulting monomial coefficient =\n            a_coefficient * b_coefficient degree = a_degree + b_degree\n            \n            # Add it to the right bucket\n            result[degree] = result[degree] + coefficient\n            \n    return result\n\\end{Verbatim}\n\nTake a long look at that function.  When you understand it, type it into \\filename{poly.py}.\n\nIn \\filename{test.py}, try out the new function:\n\\begin{Verbatim}\n# Multiplication\na_times_b = poly.multiply_polynomials(polynomial_a, polynomial_b)\nprint('A x B =', poly.polynomial_to_string(a_times_b))\n\\end{Verbatim}\n\nThis is an example of a \\emph{nested loop}. The outer loop steps\nthrough the polynomial $a$. For each step it takes, the inner loop\nsteps through the entire polynomial $b$.\n\n\\section{Something surprising about lists}\n\nYou can imagine that you might want to create two very similar polynomials. Let's say polynomial $c$ is $x^2 + 2x + 1$ and polynomial $d$ is $x^2 -2x + 1$.  You might think you are very clever to just alter that degree 1 coefficient like this:\n\\begin{Verbatim}\nc = [1.0, 2.0, 1.0]\nd = c\nd[1] = -2.0\n\\end{Verbatim}\n\nIf you printed out $c$, you would get $[1.0, -2.0, 1.0]$.  Why? You\nassigned two variables ($c$ and $d$) to the \\emph{the same list}.  So\nwhen you use one reference ($d$) to change the list, you see the\nchange if you look at the list from either reference. \\emph{FIXME:\n  Diagram of two references to the same list here.}\n\nTo create two separate lists, you would need to explicitly make a copy:\n\\begin{Verbatim}\nc = [1.0, 2.0, 1.0]\nd = c.copy()\nd[1] = -2.0\n\\end{Verbatim}\n\n", "meta": {"hexsha": "6b4685794db195bb004527e3bf0f37be73be7854", "size": 5273, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Polynomials/pymultpoly-en_US.tex", "max_stars_repo_name": "rajivjhoomuck/sequence", "max_stars_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/Polynomials/pymultpoly-en_US.tex", "max_issues_repo_name": "rajivjhoomuck/sequence", "max_issues_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/Polynomials/pymultpoly-en_US.tex", "max_forks_repo_name": "rajivjhoomuck/sequence", "max_forks_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 35.389261745, "max_line_length": 243, "alphanum_fraction": 0.7094633036, "num_tokens": 1628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.9046505254608136, "lm_q1q2_score": 0.8159230115614847}}
{"text": "\\chapter{Matrices and Linear Maps}\n\nEach linear map on a finite dimensional map corresponds to a matrix and \n\\[ A = \n\\begin{pmatrix}\n\ta_{11} & \\dots &  a_{1n} \\\\\n\t\\vdots & \\ddots & \\vdots \\\\\n\ta_{m1} & \\dots & a_{mn}\n\\end{pmatrix}\n = (a_{ij})_{\\substack{i=1,...,m \\\\ j=1,...n}}\n\\]\n\n$m$ is the number of rows and $n$ is the number of columns. \n\nNow we want to see how matrices can be related to linear mappings. Consider $T \\in \\mathcal{L}(U,V)$ where $V,W$ are finite dimensional vector spaces. Let $v_1,...v_n$ be a basis for $V$ and $w_1,...w_m$ be a basis of $W$. The linear mapping is well defined as soon as we know how it acts on the basis vectors. Because then we can express it as linear combination and extend it any vecor in the space. \n\\begin{align*}\nv &= \\lambda_1 v_1 + ... + \\lambda_n v_n , v \\in V \\\\ \nT(v) &= T(\\lambda_1 v_1 + ... + \\lambda_n v_n) \\\\ \n&= \\lambda_1 T(v_1) + ... + \\lambda_n T(v_n) \n\\end{align*}\n\nA matrix is a compact way of doing the above! \n\nEach image vector vector $T(v_j)$ can be expressed in the basis $w_1,...,w_m$. Here $a_{ij}...a_{mj} \\in \\Re$ : \n\\begin{equation*}\n\tT(v_j) = a_{1j} w_1 + ... + a_{mj} w_m\n\\end{equation*}\n\nWe now stack these coefficients in a matrix.\n\n\\[  \n\\begin{pmatrix}\na_{11} & \\dots & a_{ij} & \\dots & a_{1n} \\\\\n\\vdots  & &  \\vdots & & \\vdots \\\\\na_{m1} & \\dots & a_{mj} & \\dots & a_{mn}\n\\end{pmatrix}\n\\]\n\nThis is the matrix of mapping $T$ with respect to the basis $v_1,...,v_n$ of $V$ and $w_1,...w_m$ of $W$. \nThere are $m$ rows, one for each basis vector of $W$. There are $n$ columns, one for each basis vector of $V$.  \\\\\n\n\\textbf{Notation}: Let $T : V \\rightarrow W$ be a linear mapping and let $\\mathcal{B}$ be a basis of $V$ and $\\mathcal{C}$ be a basis of $W$. We denote $H(T, \\mathcal{B}, \\mathcal{C})$ the matrix corresponding to $T$ with basis $\\mathcal{B}$ and $\\mathcal{C}$ \\\\\n\n\\textbf{Convinient properties of matrices}: Let $V, W$ be vector spaces and consider the basis is fixed. Let $S, T \\in \\mathcal{L}(V, W)$. \n\n\\begin{itemize}\n\t\\item $H(S+T) = H(S) + H(T)$\n\t\\item $H(\\lambda S) = \\lambda H(S)$\n\t\\item For $v = \\lambda_1 v_1 + ... + \\lambda_n v_n$ we have that $T(v) =   H(T) \\begin{pmatrix}\n\t\\lambda_1 \\\\\n\t\\vdots \\\\\n\t\\lambda_n\n\t\\end{pmatrix}$, where $v_1,...v_n$ are the basis of $V$.\n\t\\item $H(S \\circ T) = H(S) \\cdot  H(T)$\n\\end{itemize}\n\n\\section{Invertiable maps and matrices}\n\n\\begin{definition}\n\tLet $T \\in \\mathcal{L}(V,W)$ is called invertible if there exists another linear map $S \\in \\mathcal{L}(W,V)$ :\n\t\\begin{center}\n\t\t\t$S \\circ T = \\mathcal{I}_v$ and $T \\circ S = \\mathcal{I}_w$\n\t\\end{center}\n\\end{definition}\nThe map $S$ is called the inverse of $T$, denoted by $T^{-1}$. \n\n\\begin{proposition}\n\tInverese maps are unique.\n\\end{proposition}\n\n\\begin{proposition}\n\tA linear map is invertible if and only if it is injective and surjective.\n\\end{proposition}\n\n\\begin{proof}\n\tInvertible $\\implies$ injective: \\\\\n\tSuppose $T(u) = T(v)$. Then $u = T^{-1}(T(u)) = T^{-1}(T(v)) = v$. This means the mapping is injective. \\\\\n\tInvertible $\\implies$ surjective: \\\\\n\tLet $w \\in W$. Then $w = T(T^{-1}(w)) \\implies w \\in range(T)$. This means that mapping is surjective. \\\\ \n\t Injective and surjective $\\implies$ invertible \\\\ \n\t Let $w \\in W$, there exists unique $v \\in V$ such that $T(v) = w$. Now define the mapping $S(w) = v$. Clearly we have $T \\circ S = \\mathcal{I}$. Let $v \\in V$, then -  \n\t \\begin{align*}\n\t T((S \\circ T)(v)) = (T \\circ S)(Tv) = \\mathcal{I} \\circ Tv = Tv\n\t \\end{align*}\n\t $\\implies (S \\circ T)v = v \\implies S \\circ T = \\mathcal{I}$\n\\end{proof}\n\n\\subsection{Inverse Matrix}\n\n\\begin{definition}\n\tA square matrix $A \\in F^{n \\times m}$ is invertible if there exists a square matrix $B \\in F^{n \\times m}$ such that - \n\t\\begin{equation*}\n\t\tA \\cdot B = B \\cdot A = \\mathcal{I}\n\t\\end{equation*}\n\tThe matrix $B$ is called the inverse matrix and is denoted by $A^{-1}$\n\\end{definition}\n\n\\begin{proposition}\n\tThe inverse matrix represents the inverse of the corresponding linear map, that is: $T: V \\rightarrow V$ \n\t\\begin{equation*}\n\t\tM(T^{-1}) = (M(T))^{-1}\n\t\\end{equation*}\n\\end{proposition}\n\nEssentially we are saying that the matrix of the inverse map is the same taking the matrix of the map and then doing the inverse.\n\n\n\n", "meta": {"hexsha": "4905b9e26196144190824f2e5498b8a5352745d1", "size": 4231, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter-4-matrices.tex", "max_stars_repo_name": "agupta54/maths-for-ml", "max_stars_repo_head_hexsha": "c5e54f14e4a24a389d31a613c34c7ef40e2bc0d1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter-4-matrices.tex", "max_issues_repo_name": "agupta54/maths-for-ml", "max_issues_repo_head_hexsha": "c5e54f14e4a24a389d31a613c34c7ef40e2bc0d1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter-4-matrices.tex", "max_forks_repo_name": "agupta54/maths-for-ml", "max_forks_repo_head_hexsha": "c5e54f14e4a24a389d31a613c34c7ef40e2bc0d1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.8165137615, "max_line_length": 402, "alphanum_fraction": 0.6419286221, "num_tokens": 1491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.8807970873650401, "lm_q1q2_score": 0.8158856294502301}}
{"text": "\\section{Infinite Limits}\r\nAlthough our limit definition works for finite values of $c$, it's also useful to think about what happens as $c$ goes to $\\pm\\infty$.\r\nWe'll need to add to our limit definition to incorporate infinite values, since it doesn't make sense to talk about neighborhoods at infinity.\r\n\\begin{definition}\r\n\tLet $f$ be a real-valued function defined on some subset $D \\subseteq \\R$ that contains arbitrarily large values.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{x \\to \\infty}{f(x)} = L\r\n\t\\end{equation*}\r\n\tif for every real $\\epsilon > 0$, there is a real number $N > 0$ such that for all $x \\in D$,\r\n\t\\begin{equation}\r\n\t\tx > N \\implies \\abs{f(x) - L} < \\epsilon.\r\n\t\\end{equation}\r\n\\end{definition}\r\n\r\nAll the same properties that we described for finite limits, like the Sum and Difference Rule, still hold for infinite limits.\r\n\r\n\\subsection{End Behavior Model}\r\nWhen x is numerically large, we can often model the behavior of a complicated function with a simplier one that behaves roughly the same for numerically large input values and is the same in the limit.\r\nThere are a few rules that these follow.\r\n\\begin{enumerate}\r\n\t\\item For a polynomial, the end-behavior is highest-degree term.\r\n\t\\item For a rational function, like a ratio of polynomials, the end behavior is the ratio of the highest degree terms.\r\n\t\\item For more complicated functions, we may need to use some reasoning about the graph of the function and limit properties to determine end-behavior.\r\n\\end{enumerate}\r\n\r\n\\subsection{Horizontal Asymptotes}\r\nHorizontal Asymptotes are a special type of end-behavior model.\r\n\\begin{definition}\r\n\tThe line $y=b$ is a horizontal asymptote of $y = f(x)$ if $\\lim_{x\\to \\infty}{f(x)} = b$ or $\\lim_{x \\to -\\infty}{f(x)} = b$.\r\n\\end{definition}\r\n\r\nWe can determine horizontal asymptotes for rational functions (usually quotient of polynomials).\r\nThere are a few cases to consider\r\n\\begin{enumerate}\r\n\t\\item If the numerator is a higher degree than the denominator, there is no horizontal asymptote, so we'll need a different method to calculate what happens at $\\pm\\infty$.\r\n\t\\item If the denominator is a higher degree than the numerator, then there is a horizontal asymptote at $y = 0$.\r\n\t\\item If the numerator and denominator have the same degree, there is a horizontal asymptote at $y = k$ where k is the ratio of the highest degree terms.\r\n\\end{enumerate}\r\n\r\n\\begin{example}\r\n\tFind the following limits, if they exist.\\\\\r\n\t\\begin{table}[H]\r\n\t\\begin{center}\r\n\t\\begin{tabular}{ l l l}\r\n\t\t1. $\\begin{aligned}[t]\r\n\t\t\t\\lim_{x \\to \\infty}{\\frac{x^3 - 6x + 1}{x^2 + 2x - 3}}\r\n\t\t\\end{aligned}$ & \r\n\t\t2. $\\begin{aligned}[t]\r\n\t\t\t\\lim_{x\\to -\\infty}{\\frac{x-9}{2x-x^2}}\r\n\t\t\\end{aligned}$ &\r\n\t\t3. $\\begin{aligned}[t]\r\n\t\t\t\\lim_{x\\to \\infty}{\\frac{6x^2-4x^5+7x-1}{12x^5-3x^2+2}}\r\n\t\t\\end{aligned}$ \\\\\r\n\t\t\\hspace{1pt} & \\hspace{1pt}\\\\\r\n\t\t4. $\\begin{aligned}[t]\r\n\t\t\t\\lim_{x\\to \\infty}{\\frac{3x+1}{\\abs{x}+2}}\r\n\t\t\\end{aligned}$ &\r\n\t\t5. $\\begin{aligned}[t]\r\n\t\t\t\\lim_{x \\to \\infty}{x + e^{-x}}\r\n\t\t\\end{aligned}$ &\r\n\t\t6. $\\begin{aligned}[t]\r\n\t\t\t\\lim_{x \\to -\\infty}{x + e^{-x}}\r\n\t\t\\end{aligned}$\r\n\t\\end{tabular}\r\n\t\\end{center}\r\n\t\\end{table}\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{enumerate}\r\n\t\t\\item Since the numerator degree is bigger than the denominator degree, we'll need to use the end behavior model.\r\n\t\t\tThe end behavior model tells us that the numerator term dominates and has positive values, so the limit evaluates to $\\infty$.\r\n\t\t\\item Since the denominator has higher degree than the numerator, there is a HA at $y=0$, so the limit evaluates to $0$.\r\n\t\t\\item Since the numerator and denominator have the same degree, the limit is the ratio of the highest-degree coefficients, $\\frac{-1}{3}$.\r\n\t\t\\item The numerator and denominator have the same degree. For $x > 0$, $\\abs{x}+2 = x+2$, so the limit is the ratio of highest-degree coefficients, $3$.\r\n\t\t\\item Looking at the two terms, we can see that as $x$ gets large, $e^{-x}$ gets very small, contributing less and less to the overall value.\r\n\t\t\tSo, we can say that this function as a right end behavior model of $x$, so the limit is $\\infty$.\r\n\t\t\\item Looking at the two terms, we that that as $x$ gets very large and negative, $e^{-x}$ changes much faster than $x$.\r\n\t\t\tThat is, $e^{-x}$ contributes more and more to the overall value of the function compared to $x$.\r\n\t\t\tSo, we can say that this function has a left end behavior model of $e^{-x}$, so the limit is $\\infty$.\r\n\t\\end{enumerate}\r\n\\end{answer}", "meta": {"hexsha": "d0f3fa1fe6c259d90dff55b20edd003514dc29e2", "size": 4478, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/limits_continuity/infinite_limits.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/limits_continuity/infinite_limits.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/limits_continuity/infinite_limits.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 55.2839506173, "max_line_length": 202, "alphanum_fraction": 0.6996426976, "num_tokens": 1323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.900529781446146, "lm_q1q2_score": 0.8158708195140071}}
{"text": "\\section{Exponential Distribution}\n\\label{sec:Exponential-Distribution}\n\nThe arrival and service processes can follow whichever probabilistic distribution. Most often, inter-arrival and service times follow the exponential distribution, because of its wide applicability and mathematical tractability.\nThe Exponential distribution is the continuous counterpart of the Geometric distribution. The Geometric distribution models the number of attempts until the first success, whereas the Exponential distribution models the time until the first success.\n\n\\begin{definition}[Exponential Distribution]\n\\label{def:Exponential-Distribution}\t\n\tA random variable $X$ is Exponentially distributed with rate\\footnote{if $X \\sim Exp(\\lambda)$, $\\lambda$ is called \\textit{rate} because $\\expected{X}=\\frac{1}{\\lambda}$.} $\\lambda$ ($X \\sim Exp(\\lambda)$) if $X$ has the following probability density function:\n\t\n\t\\begin{equation}\n\t\\label{eqn:Exponential-PDF}\n\tf(x) = \\left\\{\\begin{matrix}\n\t\t\\lambda e^{-\\lambda x} & x \\geq 0\\\\ \n\t\t0 & x \\leq 0\n\t\\end{matrix}\\right.\n\t\\end{equation}\n\\end{definition}\n\nThe p.d.f of $X \\sim Exp(\\lambda)$ is shown in \\Cref{fig:Exponential-PDF}.\n\n\\begin{figure}[tp]\n\\label{fig:Exponential-PDF}\t\n\t\\centering\n\t\\includegraphics{fig/exponential-pdf}\n\t\\caption{Exponential p.d.f.}\n\\end{figure}\n\nFrom the \\Cref{def:Exponential-Distribution} follows that the cumulative distribution function of $X \\sim Exp(\\lambda)$ is\n\n\\begin{equation}\n\\label{eqn:Exponential-CDF}\n\\begin{aligned}\n\tF(x) = \\int_{- \\infty}^{x} \\partial y = \n\t\\left\\{\\begin{matrix}\n\t1 - e^{-\\lambda x} & x \\geq 0\\\\ \n\t0 & x \\leq 0\n\t\\end{matrix}\\right.\n\\end{aligned}\n\\end{equation}\n\nThe Exponential distribution has moments\n\n\\begin{equation}\n\\label{eqn:Exponential-Mean}\n\\expected{X} = \\int_{- \\infty}^{\\infty} xf(x) \\partial x = \\frac{1}{\\lambda}\n\\end{equation}\n\n\\begin{equation}\n\\label{eqn:Exponential-Moment-2}\n\\expected{X^{2}} = \\int_{- \\infty}^{\\infty} x^{2}f(x) \\partial x = \\frac{2}{\\lambda^{2}}\n\\end{equation}\n\nand variance\n\n\\begin{equation}\n\\label{eqn:Exponential-Variance}\n\t\\variance{X} = \\expected{X^{2}} - \\expected{X}^{2} = \\frac{1}{\\lambda^{2}}\n\\end{equation}\n\nThe Exponential distribution is so convenient because it is memoryless. In particular, the Exponential distribution is the only continuous memoryless distribution.\n\n\\begin{theorem}[Exponential Memoryless]\n\\label{thm:Exponential-Memoryless}\n\n\tA random variable $X \\sim Exp(\\lambda)$ is memoryless.\n\t\n\t\\begin{proof}\n\t\t\\begin{equation*}\n\t\t\\probability{X > s+t | X > s}=\\frac{X > s+t}{X > s}=\\frac{e^{- \\lambda (s+t)}}{e^{- \\lambda s}}=e^{- \\lambda t}=\\probability{X > t}\n\t\t\\end{equation*}\n\t\\end{proof}\n\\end{theorem}\n\nThe Exponential distribution is memoryless and with constant failure rate. It exposes also the following useful properties.\n\n\\begin{theorem}[Precedency of Exponentials]\n\\label{thm:Exponential-Precedency}\n\tGiven independent $X_{1} \\sim Exp(\\lambda_{1})$ and $X_{2} \\sim Exp(\\lambda_{2})$, we have that\n\t\n\t\\begin{equation}\n\t\\label{eqn:Exponential-Precedency}\n\t\\probability{X_{1} < X_{2}} = \\frac{\\lambda_{1}}{\\lambda_{1} + \\lambda_{2}}\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{theorem}[Minimum Exponentials]\n\\label{thm:Exponential-Minimum}\n\tGiven independent $X_{1} \\sim Exp(\\lambda_{1})$ and $X_{2} \\sim Exp(\\lambda_{2})$, we have that\n\t\n\t\\begin{equation}\n\t\\label{eqn:Exponential-Minimum}\n\t\\min(X_{1},X_{2}) \\sim Exp(\\lambda_{1} + \\lambda_{2})\n\t\\end{equation}\n\\end{theorem}", "meta": {"hexsha": "62047f7c489b87d301667ab0a2a52ec8163ebe3a", "size": 3430, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/exponential-distribution.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "performance-modeling/sec/exponential-distribution.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "performance-modeling/sec/exponential-distribution.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 36.1052631579, "max_line_length": 262, "alphanum_fraction": 0.721574344, "num_tokens": 1093, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.868826771143471, "lm_q1q2_score": 0.8158499016326745}}
{"text": "\\section{Data Streams (30 points)}\n\nIn this problem, we study an approach to approximating the frequency of occurrences of different items in a data stream. Assume $S = \\langle a_1, a_2, \\ldots, a_t \\rangle$ is a data stream of items from the set $\\{1, 2, \\ldots, n\\}$. Assume for any $1\\leq i\\leq n$, $F[i]$ is the number of times $i$ has appeared in $S$. We would like to have good approximations of the values $F[i]$ ($1\\leq i\\leq n$) at all times.\n\nA simple way to do this is to just keep the counts for each item $1\\leq i\\leq n$ separately. However, this will require $\\mathcal{O}(n)$ space, and in many applications (e.g., think online advertising and counts of user's clicks on ads) this can be prohibitively large. We see in this problem that it is possible to approximate these counts using a much smaller amount of space. To do so, we consider the algorithm explained below.\n\n\\paragraph{Strategy.} The algorithm has two parameters $\\delta, \\epsilon >0$. It picks $\\left\\lceil \\log\\frac{1}{\\delta}\\right\\rceil$ independent hash functions:\n\\[\n\\forall j \\in \\left\\llbracket 1; \\left\\lceil \\log\\frac{1}{\\delta}\\right\\rceil\\right\\rrbracket, \\quad h_j:\\{1,2,\\ldots, n\\} \\rightarrow \\{1,2, \\ldots, \\left\\lceil \\frac{e}{\\epsilon} \\right\\rceil\\},\n\\]\nwhere $\\log$ denotes natural logarithm. Also, it associates a count $c_{j,x}$ to any $1\\leq j\\leq  \\left\\lceil \\log\\frac{1}{\\delta}\\right\\rceil$ and $1\\leq x \\leq  \\left\\lceil \\frac{e}{\\epsilon} \\right\\rceil$. In the beginning of the stream, all these counts are initialized to $0$. Then, upon arrival of each $a_k$ ($1\\leq k \\leq t$), each of the counts $c_{j, h_j(a_k)}$ ($1\\leq j\\leq \\left\\lceil \\log\\frac{1}{\\delta}\\right\\rceil$) is incremented by $1$. \n\nFor any $1\\leq i\\leq n$, we define $\\tilde{F}[i] = \\min_{j} \\{c_{j,h_j(i)}\\}$. We will show that $\\tilde{F}[i]$ provides a good approximation to $F[i]$. \n\n\\paragraph{Memory cost.} Note that this algorithm only uses $\\mathcal{O}\\left(\\frac{1}{\\epsilon}\\log\\frac{1}{\\delta}\\right)$ space.\n\n\\paragraph{Properties.} A few important properties of the algorithm presented above:\n\\begin{itemize}\n\\item For any $1\\leq i\\leq n$:\n\\[\n\t\\tilde{F}[i]\\geq F[i].\n\\]\n\\item For any $1\\leq i\\leq n$ and $1\\leq j\\leq \\lceil \\log(\\frac{1}{\\delta})\\rceil$:\n\\[\n\t\\mathsf{E}\\left[c_{j,h_j(i)}\\right] \\leq F[i] + \\frac{\\epsilon}{e} (t - F[i]).\n\\]\n\\end{itemize}\n\n\\subquestion{(a) [10 Points]} Prove that:\n\\[\n\t\\pr{\\tilde{F}[i] \\leq F[i] + \\epsilon t} \\geq 1-\\delta.\n\\]\n\\emph{Hint: Use Markov inequality and the property of independence of hash functions.}\n\nBased on the proof in part (a) and the properties presented earlier, it can be inferred that $\\tilde{F}[i]$ is a good approximation of $F[i]$ for any item $i$ such that $F[i]$ is not very small (compared to $t$). In many applications (\\emph{e.g.}, when the values $F[i]$ have a heavy-tail distribution), we are indeed only interested in approximating the frequencies for items which are not too infrequent. We next consider one such application.\n\n\\subquestion{(b) [20 Points]}\n\n\\paragraph{Warning.} This implementation question requires substantial computation time %- Python / Java / C / C++ implementations will be faster. \nPython implementation reported to take 15min - 1 hour. Therefore, we advise you to start early.\n\n\\paragraph{Dataset.} %\\url{http://snap.stanford.edu/class/cs246-data/HW4-q4.zip}\nThe dataset in \\textbf{q4/data} contains the following files:\n\\begin{enumerate}\n\\item \\texttt{words\\_stream.txt} Each line of this file is a number, corresponding to the ID of a word in the stream.\n\\item \\texttt{counts.txt} Each line is a pair of numbers separated by a tab. The first number is an ID of a word and the second number is its associated exact frequency count in the stream.\n\\item \\texttt{words\\_stream\\_tiny.txt} and \\texttt{counts\\_tiny.txt} are smaller versions of the dataset above that you can use for debugging your implementation.\n\\item \\texttt{hash\\_params.txt} Each line is a pair of numbers separated by a tab, corresponding to parameters $a$ and $b$ which you may use to define your own hash functions (See explanation below).\n\\end{enumerate}\n\n\\paragraph{Instructions.}\nImplement the algorithm and run it on the dataset with parameters $\\delta = e^{-5}, \\epsilon = e\\times 10^{-4}$. (Note: with this choice of $\\delta$ you will be using 5 hash functions - the 5 pairs $(a,b)$ that you'll need for the hash functions are in \\texttt{hash\\_params.txt}). Then for each distinct word $i$ in the dataset, compute the relative error $E_r[i] = \\frac{\\tilde{F}[i] - F[i]}{F[i]}$ and plot these values as a function of the exact word frequency $\\frac{F[i]}{t}$. (\\textbf{You do not have to implement the algorithm in Spark.}) \n\nThe plot should use a logarithm scale both for the $x$ and the $y$ axes, and there should be ticks to allow reading the powers of 10 (e.g. $10^{-1}$, $10^0$, $10^1$ etc...). The plot should have a title, as well as the $x$ and $y$ axes. The exact frequencies $F[i]$  should be read from the counts file. Note that words of low frequency can have a very large relative error. That is not a bug in your implementation, but just a consequence of the bound we proved in question (a).\n\nAnswer the following question by reading values from your plot: What is an approximate condition on a word frequency in the document to have a relative error below $1 = 10^0$ ? \n\n\\paragraph{Hash functions.}\nYou may use the following hash function (see example pseudo-code), with $p = 123457$, $a$ and $b$ values provided in the hash params file and \\texttt{n\\_buckets} (which is equivalent to $\\left\\lceil \\frac{e}{\\epsilon} \\right\\rceil$) chosen according to the specification of the algorithm. In the provided file, each line gives you $a$, $b$ values to create one hash function.\n\n\\begin{verbatim}\n# Returns hash(x) for hash function given by parameters a, b, p and n_buckets\ndef hash_fun(a, b, p, n_buckets, x) \n{\n\ty = x [modulo] p\n\thash_val = (a*y + b) [modulo] p\n\treturn hash_val [modulo] n_buckets\n}\n\\end{verbatim}\nNote: This hash function implementation produces outputs of value from $0$ to $(\\texttt{n\\_buckets}-1)$, which is different from our specification in the \\textbf{Strategy} part. You can either keep the range as $\\{0, ..., \\texttt{n\\_buckets}-1\\}$, or add 1 to the hash result so the value range becomes $\\{1, ..., \\texttt{n\\_buckets}\\}$, as long as you stay consistent within your implementation. \n\n\\subsection*{What to submit}\n\\begin{enumerate}[(i)]\n\t\\item Proof that $\\pr{\\tilde{F}[i] \\leq F[i] + \\epsilon t} \\geq 1-\\delta$. [part (a)]\n\t\\item Log-log plot of the relative error as a function of the frequency. Answer for which word frequencies is the relative error below 1. [part (b)]\n\t\\item Submit the code on Gradescope submission site. [part (b)]\n\\end{enumerate}\n\n", "meta": {"hexsha": "af7547afa561816a0a6cb3058ec63c5160ba5493", "size": 6758, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw4-bundle/hw4-bundle/HW4 source/hw4_streams.tex", "max_stars_repo_name": "x3pi/mining-massive-datasets", "max_stars_repo_head_hexsha": "36d1f8ab437ea75d7437fc3e28593c2bb907ddd9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-12-24T01:06:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T10:54:57.000Z", "max_issues_repo_path": "hw4-bundle/hw4-bundle/HW4 source/hw4_streams.tex", "max_issues_repo_name": "x3pi/mining-massive-datasets", "max_issues_repo_head_hexsha": "36d1f8ab437ea75d7437fc3e28593c2bb907ddd9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw4-bundle/hw4-bundle/HW4 source/hw4_streams.tex", "max_forks_repo_name": "x3pi/mining-massive-datasets", "max_forks_repo_head_hexsha": "36d1f8ab437ea75d7437fc3e28593c2bb907ddd9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-09-11T17:31:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T20:33:33.000Z", "avg_line_length": 85.5443037975, "max_line_length": 546, "alphanum_fraction": 0.7197395679, "num_tokens": 1985, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213853793453, "lm_q2_score": 0.9073122232403329, "lm_q1q2_score": 0.8157838231314619}}
{"text": "\\subsection{The geometric significance of the dot product}\n\nThe \\textbf{included angle}%\n\\index{included angle} of two vectors $\\vect{u}$ and $\\vect{v}$ is the\nangle $\\theta$ between the vectors such that $0 \\leq \\theta \\leq \\pi$.\n\\begin{center}\n  \\begin{tikzpicture}\n    \\filldraw[fill=green!20,draw=green!50!black] (0,0) -- (-30:8mm) arc (-30:45:8mm) -- cycle;\n    \\draw[->, thick, blue](0,0) -- node[above left] {$\\vect{u}$} (45:1.5);\n    \\draw[->, thick, red](0,0) -- node[below left] {$\\vect{v}$} (-30:2);\n    \\node at (7.5:5mm){$\\theta$};\n  \\end{tikzpicture}\n\\end{center}\nThe dot product can be used to determine the included angle between\ntwo vectors.\n\n\\begin{proposition}{The dot product and the included angle}{dot-product-angle}\n  Let $\\vect{u}$ and $\\vect{v}$ be two vectors in $\\R^n$, and let\n  $\\theta$ be the included angle. Then the following equation holds.\n  \\begin{equation*}\n    \\vect{u}\\dotprod \\vect{v}=\\norm{\\vect{u}} \\norm{\\vect{v}} \\cos \\theta.\n  \\end{equation*}\n\\end{proposition}\n\nIn words, the dot product of two vectors equals the product of the\nmagnitude (or length) of the two vectors multiplied by the cosine of\nthe included angle. Note that this gives a geometric description of\nthe dot product that does not depend explicitly on the coordinates of\nthe vectors.\n\n\\begin{example}{Find the angle between two vectors}{angle-two-vectors}\n  Find the angle%\n  \\index{angle!between vectors} between the vectors\n\\begin{equation*}\n  \\vect{u}\n  =\n  \\begin{mymatrix}{r}\n    2 \\\\\n    2\n  \\end{mymatrix}\n  \\quad\\mbox{and}\\quad\n  \\vect{v}\n  =\n  \\begin{mymatrix}{r}\n    0 \\\\\n    3\n  \\end{mymatrix}.\n\\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  By Proposition~\\ref{prop:dot-product-angle},\n  \\begin{equation*}\n    \\vect{u}\\dotprod \\vect{v}=\\norm{\\vect{u}} \\norm{\\vect{v}} \\cos \\theta.\n  \\end{equation*}\n  Hence,\n  \\begin{equation*}\n    \\cos \\theta =\\frac{\\vect{u}\\dotprod \\vect{v}}{\\norm{\\vect{u}}\\norm{\\vect{v}}}.\n  \\end{equation*}\n  First, we compute $\\vect{u}\\dotprod \\vect{v} = (2)(0) + (2)(3) = 6$.\n  Then,\n  \\begin{equation*}\n    \\begin{array}{l}\n      \\norm{\\vect{u}} = \\sqrt{2^2+2^2}=\\sqrt{8}, \\\\\n      \\norm{\\vect{v}} = \\sqrt{0^2+3^2}=3.\n    \\end{array}\n  \\end{equation*}\n  Therefore, we have\n  \\begin{equation*}\n    \\cos \\theta =\\frac{6}{3\\sqrt{8}} = \\frac{1}{\\sqrt{2}}.\n  \\end{equation*}\n  Taking the inverse cosine of both sides of the equation, we find\n  that $\\theta =\\frac{\\pi}{4}$ radians, or 45 degrees.\n\\end{solution}\n\n\\begin{example}{Computing a dot product from an angle}{geometric-dot-product}\n  Let $\\vect{u},\\vect{v}$ be vectors with $\\norm{\\vect{u}} = 3$ and $\\norm{\\vect{v}} = 4$.\n  Suppose the angle between $\\vect{u}$ and $\\vect{v}$ is $\\pi / 3$. Find $\\vect{u}\\dotprod \\vect{v}$.\n\\end{example}\n\n\\begin{solution}\n  From Proposition~\\ref{prop:dot-product-angle}, we have\n  \\begin{equation*}\n    \\vect{u}\\dotprod \\vect{v}\n    =\\norm{\\vect{u}} \\norm{\\vect{v}} \\cos \\theta\n    =3\\cdot 4\\cdot \\cos\\paren{\\frac{\\pi}{3}}\n    =3\\cdot 4\\cdot \\frac{1}{2}=6.\n\\end{equation*}\n\\end{solution}\n\n", "meta": {"hexsha": "dc88b9002fc3205cc8711e80b64587e0205789ed", "size": 3027, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-DotProduct-Geometric.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Vectors-DotProduct-Geometric.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Vectors-DotProduct-Geometric.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 33.2637362637, "max_line_length": 101, "alphanum_fraction": 0.6455236207, "num_tokens": 1076, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8976952982655951, "lm_q1q2_score": 0.8156620139965735}}
{"text": "\\section{Computer Math}\n\nIn this section, I introduce a few vocabulary terms that help you understand how computers do certain things, like add two (binary) numbers. In most respects, adding these numbers is no different from how you already add numbers. When the numbers in any column is too big to be held in that column, you must ``carry'' the extra number to the next larger column. The difference, and it is slightly awkward at first, is remembering that any column can only hold 0 or 1 -- if you reach 2, you have to carry the ``two'' to the next column.\n\n\\subsection*{Addition}\n\nAdding two values is straightforward. Simply align the values on the least significant bit and add each column, moving any ``carry'' to the bit one position left, just like you already do with ``regular'' (base-10) arithmetic.\n\n\\begin{verbatim}\n  Binary:     Decimal:\n\n  0001 0110   (16 + 0 + 4 + 2 + 0) =   22\n+ 0000 0011    (0 + 0 + 0 + 1 + 2) =    3\n===========                          ====\n  0001 1001   (16 + 8 + 0 + 0 + 1) =   25\n\\end{verbatim}\n\n\n\\bigskip\n\n\\noindent Your turn! Add these numbers in binary, column by column, carrying each ``2'' as needed. After you add them, convert each number to decimal to check your work.\n\n\\bigskip\n\n\\begin{tabular}{p{3in} | c  p{3in} }\n\\hline\n\\\\\n\\begin{minipage}{2.95in}\n\\begin{verbatim}\n   Binary:       Decimal:\n\n  0000 0000\n+ 0000 0011\n===========      ====\n\n___________      ____\n\\end{verbatim}\n\\end{minipage}\n\n&&\n\n\\begin{minipage}{2.95in}\n\\begin{verbatim}\n   Binary:       Decimal:\n\n  0000 0010\n+ 0000 0010\n===========      ====\n\n___________      ____\n\\end{verbatim}\n\\end{minipage}\n\n\\\\\n\\hline\n\\\\\n\n\\begin{minipage}{2.95in}\n\\begin{verbatim}\n   Binary:       Decimal:\n\n  0000 0110\n+ 0000 0011\n===========      ====\n\n___________      ____\n\\end{verbatim}\n\\end{minipage}\n\n&&\n\n\\begin{minipage}{2.95in}\n\\begin{verbatim}\n   Binary:       Decimal:\n\n  0000 1010\n+ 0001 1011\n===========      ====\n\n___________      ____\n\\end{verbatim}\n\\end{minipage}\n\n\\\\\n\\hline\n\\end{tabular}\n\nThere is more information about binary arithmetic in the Appendix -- you can see how to represent negative numbers, and how to subtract numbers, in binary, just the way a computer does. But for now, you know enough to move on.\n\n\\vfill\n\n\\input{./include/twoscomplement.tex}\n", "meta": {"hexsha": "f09218ed1286dcb6245ab7744080edba8be04163", "size": 2274, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/computermath.tex", "max_stars_repo_name": "jessehamner/TechMillForKids", "max_stars_repo_head_hexsha": "f064bf1408537f71e4e7dc14f02a8e7e20c2af3a", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-11-13T21:45:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T09:31:54.000Z", "max_issues_repo_path": "chapters/computermath.tex", "max_issues_repo_name": "jessehamner/TechMillForKids", "max_issues_repo_head_hexsha": "f064bf1408537f71e4e7dc14f02a8e7e20c2af3a", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-03-10T21:46:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-25T19:21:58.000Z", "max_forks_repo_path": "chapters/computermath.tex", "max_forks_repo_name": "jessehamner/TechMillForKids", "max_forks_repo_head_hexsha": "f064bf1408537f71e4e7dc14f02a8e7e20c2af3a", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-11-14T04:40:14.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-17T05:31:36.000Z", "avg_line_length": 24.4516129032, "max_line_length": 535, "alphanum_fraction": 0.6596306069, "num_tokens": 683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966762263737, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.815529208854707}}
{"text": "\n\\subsection{Probability density functions}\n\n\\subsubsection{Definition}\n\nIf continuous, probability at any point is \\(0\\). We instead look at probability density.\n\nDerived from cumulative distribution function:\n\n\\(F_X(x)=\\int_{-\\infty}^x f_X(u)du\\)\n\nThe density function is \\(f_X(x)\\).\n\n\\subsubsection{Conditional probability distributions}\n\nFor probability mass functions:\n\n\\(P(Y=y|X=x)=\\dfrac{P(Y=y\\land X=x)}{P(X=x)}\\)\n\nFor probability density functions:\n\n\\(f_Y(y|X=x)=\\dfrac{f_{X,Y}(x,y)}{f_X(x)}\\)\n\n", "meta": {"hexsha": "331fa27d30c8c3c3816ed15e297bf8544dbff2a5", "size": 504, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityVariables/01-04-density.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/probabilityVariables/01-04-density.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/probabilityVariables/01-04-density.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.0, "max_line_length": 89, "alphanum_fraction": 0.7182539683, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067252, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.8155292032782235}}
{"text": "\\section{Power Series}\r\n\\subsection{Geometric Series}\r\nFirst, we need to define what we mean by an infinite series.\r\n\\begin{definition}\r\n\tAn infinite series is of the form\r\n\t\\begin{equation*}\r\n\t\ta_1 + a_2 + \\ldots + a_n + \\ldots \\text{ or equivalently, } \\sum_{k=1}^{\\infty}{a_k}.\r\n\t\\end{equation*}\r\n\tJust like with finite series, each $a_i$ is a term, and $a_n$ is the nth term.\r\n\\end{definition}\r\n\r\nWe can describe the behavior of an infinite series by looking at how its value behaves after summing a finite number of terms.\r\nWe can define what it means for an infinite sum to have a value by looking at the limit of the partial sums as $n$ grows large.\r\n\\begin{definition}\r\n\tThe nth partial sum of an infinite series is\r\n\t\\begin{equation*}\r\n\t\ts_n = \\sum_{k=1}^{n}{a_k}.\r\n\t\\end{equation*}\r\n\tThe infinite series converges to value $L$ if\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{s_n} = L.\r\n\t\\end{equation*}\r\n\tOtherwise, the series diverges and does not have a value.\r\n\\end{definition}\r\n\r\n\\begin{example}\r\n\tState if the following infinite series converges or diverges.\r\n\t\\begin{equation*}\r\n\t\t\\frac{3}{10} + \\frac{3}{100} + \\ldots + \\frac{3}{10^n} + \\ldots.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tLooking at the partial sums,\r\n\t\\begin{align*}\r\n\t\ts_1 &= 0.3 \\\\\r\n\t\ts_2 &= 0.33 \\\\\r\n\t\t&\\vdots \\\\\r\n\t\ts_n &= 0.\\underbrace{33333\\ldots}_{\\text{$n$ total 3's}}\r\n\t\\end{align*}\r\n\t\r\n\tSo, it seems the limit of the partial sums tends towards a decimal with an infinite number of 3's.\r\n\tThis value corresponds to the decimal expansion of 1/3, which clearly is real and finite, so the series converges.\r\n\\end{answer}\r\n\r\n\r\nThe above series is a geometric series since each subsequent term is 10 times smaller than the previous one (i.e $r=1/10$).\r\n\\begin{lemma}\r\n\tThe geometric series\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{a_0(r)^k}\r\n\t\\end{equation*}\r\n\tconverges to a value of $a_0/(1-r)$ if $\\abs{r} < 1$ and diverges otherwise.\r\n\\end{lemma}\r\n\\begin{proof}\r\n\tWe'll first find a formula for the partial sums and then find the limit of the partial sums for $1 < r < 1$.\r\n\t\\begin{align*}\r\n\t\ts_n &= \\sum_{k=0}^{n}{a_0(r)^k} \\\\\r\n\t\t&= a_0 + a_0r + a_0r^2 + \\ldots + a_0r^n \\\\\r\n\t\trs_n &= a_0r + a_0r^2 + a_0r^3 + \\ldots + a_0r^n + a_0r^{n+1} \\\\\r\n\t\t&= -a_0 + s_n + a_0r^{n+1} \\\\\r\n\t\ts_n(r-1) &= a_0\\left(r^{n+1} - 1\\right) \\\\\r\n\t\ts_n &= a_0\\frac{r^{n+1}-1}{r-1}.\r\n\t\\end{align*}\r\n\tThis formula for partial sums holds for all values of $r$.\r\n\tNow we'll take the limit of $s_n$ and see for what values of $r$ the limit exists.\r\n\t\\begin{align*}\r\n\t\t\\sum_{k=0}^{\\infty}{a_0(r)^n} &= \\lim_{n\\to\\infty}{s_n} \\\\\r\n\t\t&= \\lim_{n\\to\\infty}{a_0\\frac{r^{n+1}-1}{r-1}} \\\\\r\n\t\t&= \\frac{-a_0}{r-1}, \\abs{r} < 1 \\\\\r\n\t\t&= \\frac{a_0}{1-r}, \\abs{r} < 1.\r\n\t\\end{align*}\r\n\\end{proof}\r\n\r\n\\subsection{Functions from Geometric Series}\r\nWhat happens if rather than letting $r$ be some fixed value we know beforehand, we let $r$ be some variable $x$?\r\nApplying the formula,\r\n\\begin{equation*}\r\n\ta_0 + a_0x + a_0x^2 + \\ldots = \\frac{a_0}{1-x}, \\abs{x} < 1.\r\n\\end{equation*}\r\nThis sort of sum of powers of $x$ is called a power series, and the condition that $\\abs{x}<1$ is called the interval of convergence.\r\nRight now, this power series is centered at $x=0$, but we can generalize it a bit to be centered at $x=h$.\r\n\\begin{equation*}\r\n\ta_0 + a_0(x-h) + a_0(x-h)^2 + \\ldots = \\frac{a_0}{1-(x-h)}, \\abs{x-h} < 1.\r\n\\end{equation*}\r\nNote that this formula allows us to find the power series of any function $a_0/(mx+b)$.\r\n\\begin{equation*}\r\n\t\\frac{a_0}{mx + b} = \\frac{a_0}{1-(1-mx-b)} = a_0 + a_0(1-mx+b) + a_0(1-mx+b)^2 + \\ldots, \\abs{1-mx-b} < 1.\r\n\\end{equation*}\r\nSo,\r\n\\begin{align*}\r\n\t\\frac{1}{x} &= 1 + (1-x) + (1-x)^2 + \\ldots, \\abs{1-x} < 1 \\\\\r\n\t\\frac{1}{1-x} &= 1 + x + x^2 + x^3 + \\ldots, \\abs{x} < 1 \\\\\r\n\t\\frac{1}{1+x} &= 1 - x + x^2 - x^3 + \\ldots, \\abs{x} < 1.\r\n\\end{align*}\r\n\r\n\\subsubsection{Term-By-Term Differentiation}\r\n\\begin{theorem}\r\n\tIf the power series\r\n\t\\begin{equation*}\r\n\t\tf(x) = \\sum_{k=0}^{\\infty}{c_k(x-a)^k} = c_0 + c_1(x-a) + c_2(x-a)^2 + \\ldots\r\n\t\\end{equation*}\r\n\tconverges for $\\abs{x-a} < R$, including $R=\\infty$, then the power series\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=1}^{\\infty}{kc_k(x-a)^{k-1}} = c_1 + 2c_2(x-a) + 3c_3(x-a)^2 + \\ldots\r\n\t\\end{equation*}\r\n\talso converges for $\\abs{x-a} < R$ and is equal to $f^\\prime(x)$ on that interval.\r\n\\end{theorem}\r\n\r\nApplying the theorem,\r\n\\begin{align*}\r\n\t\\frac{-1}{x^2} &= -1 - 2(1-x) - 3(1-x)^2 - \\ldots, \\abs{1-x} < 1 \\\\\r\n\t\\frac{1}{(1-x)^2} &= 1 + 2x + 3x^2 + \\ldots, \\abs{x} < 1 \\\\\r\n\t\\frac{-1}{(1+x)^2} &= -1 + 2x - 3x^2 + \\ldots, \\abs{x} < 1.\r\n\\end{align*}\r\n\r\n\\subsubsection{Term-By-Term Integration}\r\n\\begin{theorem}\r\n\tIf the power series\r\n\t\\begin{equation*}\r\n\t\tf(x) = \\sum_{k=0}^{\\infty}{c_k(x-a)^k} = c_0 + c_1(x-a) + c_2(x-a)^2 + \\ldots\r\n\t\\end{equation*}\r\n\tconverges for $\\abs{x-a} < R$, including $R=\\infty$, then the power series\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{c_k\\frac{(x-a)^{k+1}}{k+1}} = c_0(x-a) + c_1\\frac{(x-a)^2}{2} + c_2\\frac{(x-a)^3}{3} + \\ldots\r\n\t\\end{equation*}\r\n\talso converges for $\\abs{x-a} < R$ and represents the antiderivative of $f$ on that interval.\r\n\\end{theorem}\r\n\r\nApplying the theorem,\r\n\\begin{align*}\r\n\t\\ln{\\abs{x}} &= 1 + \\frac{(1-x)^2}{2} + \\frac{(1-x)^3}{3} + \\ldots, \\abs{1-x} < 1 \\\\\r\n\t-\\ln{\\abs{1-x}} &= x + \\frac{x^2}{2} + \\frac{x^3}{3} + \\ldots, \\abs{x} < 1 \\\\\r\n\t\\ln{\\abs{1+x}} &= x - \\frac{x^2}{2} + \\frac{x^3}{3} - \\frac{x^4}{4} + \\ldots, \\abs{x} < 1.\r\n\\end{align*}\r\n\r\nThis is pretty impressive: we now have an formula for $\\ln{x}$ in terms of polynomials.\r\nThis also includes some pretty surprising identities.\r\nFor example\\footnote{Technically, we're substituting $x=1$ which isn't in the interval of convergence. However, since we are dealing with an alternating sum, the series will also converge for $x=-1$ and $x=1$.},\r\n\\begin{equation*}\r\n\t\\ln{2} = 1 - \\frac{1}{2} + \\frac{1}{3} - \\ldots + \\frac{(-1)^{n+1}}{n} + \\ldots.\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tFind a power series for $\\arctan{x}$ and state the interval of convergence.\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe know that\r\n\t\\begin{equation*}\r\n\t\t\\dd{}{x}\\arctan{x} = \\frac{1}{1+x^2}.\r\n\t\\end{equation*}\r\n\t\r\n\tSo, if we can find a power series that represents $1/(1+x^2)$, we can integrate term-by-term to get a power series for $\\arctan{x}$.\r\n\tWe also already know the following power series.\r\n\t\\begin{equation*}\r\n\t\t\\frac{1}{1+u} = 1 - u + u^2 - u^3 + \\ldots, \\abs{u} < 1.\r\n\t\\end{equation*}\r\n\t\r\n\tLetting $u=x^2$,\r\n\t\\begin{align*}\r\n\t\t\\frac{1}{1+x^2} &= 1 - x^2 + x^4 - x^6 + \\ldots, \\abs{x^2} < 1 \\\\\r\n\t\t&= 1 - x^2 + x^4 - x^6 + \\ldots, \\abs{x} < 1.\r\n\t\\end{align*}\r\n\t\r\n\tIntegrating term-by-term,\r\n\t\\begin{align*}\r\n\t\t\\arctan{x} = x - \\frac{x^3}{3} + \\frac{x^5}{5} + \\ldots + (-1)^n\\frac{x^{2n+1}}{2n+1} + \\ldots, \\abs{x} < 1.\r\n\t\\end{align*}\r\n\t\r\n\tThis power series also gives rise to a pretty interesting identity\\footnote{See footnote 1.}.\r\n\t\\begin{equation*}\r\n\t\t\\arctan{1} = \\frac{\\pi}{4} = 1 - \\frac{1}{3} + \\frac{1}{5} - \\frac{1}{7} + \\ldots + (-1)^n\\frac{x^{2n+1}}{2n+1} \\ldots.\r\n\t\\end{equation*}\r\n\\end{answer}", "meta": {"hexsha": "055b1f0bafefef94a121026e2326500ea6ada52d", "size": 7065, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/infinite_series/power_series.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/infinite_series/power_series.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/infinite_series/power_series.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.838150289, "max_line_length": 212, "alphanum_fraction": 0.6106157113, "num_tokens": 2835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8962513828326955, "lm_q1q2_score": 0.8155054124107585}}
{"text": "\\subsection{Integration}\r\n\\noindent\r\nThe volume element in cylindrical coordinates is $\\mathrm{d}V = r\\mathrm{d}r\\mathrm{d}\\theta\\mathrm{d}z$.\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nFor example, let's evaluate $\\int_{0}^{4}{\\int_{0}^{\\sqrt{16 - y^2}}{\\int_{0}^{16 - x^2 - y^2}{\\mathrm{d}z}\\mathrm{d}x}\\mathrm{d}y}$, the volume under the paraboloid $z = 16 - x^2 - y^2$ using cylindrical coordinates.\r\n\\begin{align*}\r\n\t&= \\int_{0}^{4}{\\int_{0}^{\\pi/2}{\\int_{0}^{16 - r^2}{r\\mathrm{d}z}\\mathrm{d}\\theta}\\mathrm{d}r} \\\\\r\n\t&= \\int_{0}^{4}{\\int_{0}^{\\pi/2}{16r - r^2\\mathrm{d}\\theta}\\mathrm{d}r} \\\\\r\n\t&= \\frac{\\pi}{2}\\int_{0}^{4}{16r - r^3\\mathrm{d}r} \\\\\r\n\t&= \\frac{\\pi}{2}\\left[8r^2 - \\frac{r^4}{4}\\right]_0^4 \\\\\r\n\t&= 32\\pi\r\n\\end{align*}\r\n\r\n\\noindent\r\nFor another example, let's find the average value of $f(x,y,z) = z$ on the domain $\\Omega$ which is bounded by $z = \\sqrt{6-x^2-y^2}$ and $z = x^2+y^2$ \\footnote{Work omitted for brevity}.\r\n\\begin{equation*}\r\n\t\\bar{f} = \\frac{\\int_{0}^{2\\pi}{\\int_{0}^{\\sqrt{2}}{\\int_{r^2}^{\\sqrt{6 - r^2}}{zr\\mathrm{d}z}\\mathrm{d}r}\\mathrm{d\\theta}}}{\\int_{0}^{2\\pi}{\\int_{0}^{\\sqrt{2}}{\\int_{r^2}^{\\sqrt{6 - r^2}}{r\\mathrm{d}z}\\mathrm{d}r}\\mathrm{d}\\theta}}=\\frac{11}{12\\sqrt{6} - 17}\r\n\\end{equation*}", "meta": {"hexsha": "92e942cd65d7aa1b1cd25c8ee89245b3c5f37a3a", "size": 1227, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/curvilinearCoordinates/integration_cylindrical.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/curvilinearCoordinates/integration_cylindrical.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/curvilinearCoordinates/integration_cylindrical.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 58.4285714286, "max_line_length": 261, "alphanum_fraction": 0.598207009, "num_tokens": 556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.8962513772903669, "lm_q1q2_score": 0.8155054095573709}}
{"text": "\\subsection{Eigenvalues of Markov matrices}\n\nThe following is an important proposition.\n\n\\begin{proposition}{Eigenvalues of a migration matrix}{eigenvalue-migration-matrix}\nLet $A=\\mat{a_{ij}} $ be a migration matrix. Then $1$ is always an\neigenvalue for $A$.\n\\end{proposition}\n\n\\begin{proof} Remember that the determinant of a matrix always equals that of its transpose.\nTherefore,\n\\begin{equation*}\n\\det (\\eigenvar I - A) =\\det ((\\eigenvar I - A)\n^{T}) =\\det (\\eigenvar I - A^T)\n\\end{equation*}\nbecause $I^{T}=I$. Thus the characteristic equation for $A$ is the same as\nthe characteristic equation for $A^{T}$. Consequently, $A$ and $A^{T}$ have the same\neigenvalues. We will show that $1$ is an eigenvalue for $A^{T}$ and then it\nwill follow that $1$ is an eigenvalue for $A$.\n\nRemember that for a migration matrix, $\\sum_{i}a_{ij}=1$. Therefore, if\n$A^{T}=\\mat{b_{ij}} $ with $b_{ij}=a_{ji}$, it follows that\n\\begin{equation*}\n\\sum_{j}b_{ij}=\\sum_{j}a_{ji}=1\n\\end{equation*}\n\nTherefore, from matrix multiplication,\n\\begin{equation*}\nA^{T}\\begin{mymatrix}{r}\n1 \\\\\n\\vdots \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{c}\n\\sum_{j}b_{ij} \\\\\n\\vdots \\\\\n\\sum_{j}b_{ij}\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n\\vdots \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\n\nNotice that this shows that $\\begin{mymatrix}{r}\n1 \\\\\n\\vdots \\\\\n1\n\\end{mymatrix} $ is an eigenvector for $A^{T}$ corresponding to the eigenvalue, $\\lambda =1$.\n As explained above, this shows that $\\lambda =1$ is an\neigenvalue for $A$ because $A$ and $A^{T}$ have the same eigenvalues.\n\\end{proof}\n", "meta": {"hexsha": "d06d689fa493233375f87ded70b56c09dca57b52", "size": 1541, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryApplicationsDiagonalizationMarkovEigenvalues.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/spectraltheoryApplicationsDiagonalizationMarkovEigenvalues.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/spectraltheoryApplicationsDiagonalizationMarkovEigenvalues.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 29.6346153846, "max_line_length": 93, "alphanum_fraction": 0.6950032446, "num_tokens": 527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.8962513821399044, "lm_q1q2_score": 0.8155054052115345}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{parskip}\n\\usepackage{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath, amssymb}\n\\usepackage{subcaption}\n\\usepackage{hyperref}\n\n\\geometry{\n  a4paper,\n  bottom=2.5cm,\n  right =2.5cm,\n  left  =2.5cm,\n  top   =2.5cm,\n}\n\n\n\\begin{document}\n\\title{t-SNE Notes}\n\\author{Pavlin Poli\u010dar}\n\\date{}\n\\maketitle\n\n\\section{t-SNE}\n\nt-SNE was presented in \\cite{maaten2008visualizing} and aims to preserve local structure of high dimensional spaces $X$ with some low dimensional embedding $Y$. First for each point $i$, we find its nearest nearest neighbours and compute the probability of this point $p_j$ based on the PDF of a Gaussian centred on the point $i$:\n\n\\begin{equation}\\label{eq:sne_pij}\np_{j \\mid i} = \\frac{\\exp{\\left (- || \\mathbf{x}_i - \\mathbf{x}_j ||^2 / 2\\sigma_i^2 \\right )}}{\\sum_{k \\neq i}\\exp{\\left (- || \\mathbf{x}_i - \\mathbf{x}_k ||^2 / 2\\sigma_i^2 \\right )}}\n\\end{equation}\n\nwhere $\\sigma_i$ is the bandwidth of the Gaussian density. These bandwidths are controlled by the ``perplexity'' parameter. Perplexity can be thought of as a continuous analogue to the number $k$-nearest neighbours:\n\n\\begin{equation}\nPerp(P_i) = 2^{H(P_i)}\n\\end{equation}\n\nwhere $H(P_i)$ is the Shannon entropy of the distribution $P_i$.\n\nt-SNE actually doesn't use Equation~\\ref{eq:sne_pij} directly, but symmetrizes this conditional probability, so the actual $p_{ij}$s used by t-SNE are\n\n\\begin{equation}\np_{ij} = \\frac{p_{j\\mid i} + p_{i \\mid j}}{2}\n\\end{equation}\n\nIn their experiments, van der Maaten et al. found that this doesn't affect embedding quality and simplifies the gradient expression.\n\nSimilarly, we represent the embedding $Y$ as a probability distribution. In the original SNE paper \\cite{hinton2003stochastic}, a Gaussian was used, however this often led to the crowding problem, where all the points were clumped into a single ball in a single point in space. t-SNE, as the name would suggest, uses a Student-t distribution, therefore the probability density of $Y$ is\n\n\\begin{equation}\nq_{ij} = \\frac{\\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 \\right )^{-1}}{\\sum_{k \\neq l}\\left ( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 \\right )^{-1}}\n\\end{equation}\n\nWe now have two probability distributions over the local point affinities. Now we'd like some way to match these two distributions, so the local structure of $X$ is reflected in $Y$. A natural way of doing this is to use Kullback-Leibler divergence (from here on referred to as the KL divergence), which is defined as\n\n\\begin{equation}\nKL(P \\mid \\mid Q) = \\sum_{ij} p_{ij} \\log \\frac{p_{ij}}{q_{ij}}\n\\end{equation}\n\nOur goal is to minimize this error $C$, so we can take the derivative and obtain\n\n\\begin{equation}\n\\frac{\\partial C}{\\partial \\mathbf{y}_i} = 4 \\sum_{j \\neq i} \\left ( p_{ij} - q_{ij} \\right ) \\left ( \\mathbf{y}_i - \\mathbf{y}_j \\right ) \\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j || ^2 \\right )^{-1}\n\\end{equation}\n\nThis is t-SNE in essence. In practice various tricks are used to speed up convergence e.g. using a momentum term helps a lot. The embedding $Y$ is typically initialized using an isotropic Gaussian with small variance (e.g. 0.01). Often times, PCA is used for initialization. This can sometimes be problematic if the PCA embedding provides very scattered embeddings (sometimes most points are clumped to one side with very long stretched out tails). In these cases, using a random initialization produces better embeddings.\n\n\\section{Performance improvements}\nIt quickly became apparent that t-SNE, while nice, was infeasible to run for larger data sets, because of its quadratic time complexity $\\mathcal{O}(n^2)$ (due to the normalization term in $q_{ij}$).\n\nFor convenience, we will write the gradient in a different form seen in many papers, that makes the attractive and repulsive forces clearer.\n\n\\begin{align}\n\\frac{\\partial C}{\\partial \\mathbf{y}_i} &= 4 \\sum_{j \\neq i} \\left ( p_{ij} - q_{ij} \\right ) \\left ( \\mathbf{y}_i - \\mathbf{y}_j \\right ) \\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j || ^2 \\right )^{-1}\n\\intertext{Notice that the right most term is just the unnormalized $q_{ij}$}\n&= 4 \\sum_{j \\neq i} \\left ( p_{ij} - q_{ij} \\right ) \\left ( \\mathbf{y}_i - \\mathbf{y}_j \\right ) \\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j || ^2 \\right )^{-1} \\frac{Z}{Z}\n\\intertext{Where $Z$ is the normalization term of $Q$: $Z = \\sum_{k \\neq l}\\left ( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 \\right )^{-1}$}\n&= 4 \\sum_{j \\neq i} \\left ( p_{ij} - q_{ij} \\right ) q_{ij} Z \\left ( \\mathbf{y}_i - \\mathbf{y}_j \\right ) \\\\\n&= 4 \\left (\\sum_{j \\neq i} p_{ij} q_{ij} Z \\left ( \\mathbf{y}_i - \\mathbf{y}_j \\right ) -\\sum_{j \\neq i} q_{ij}^2 Z \\left ( \\mathbf{y}_i - \\mathbf{y}_j \\right ) \\right ) \\\\\n\\intertext{which can in turn be throught of as attractive and repulsive forces}\n&= 4 \\left ( F_{\\text{attr}} + F_{\\text{rep}} \\right )\n\\end{align}\n\n\\subsection{Landmark points}\nIn fact, van der Maaten and Hinton provide a solution to this in their original paper: instead of visualizing all the points, embed only a sample of carefully chosen landmark points. The points must be carefully chosen because a random subset may not properly describe the manifold. First, we construct the k-neighbourhood graph on all the points. Next, they approximate the $P$ of the landmark points using random walks across the neighbourhood graph. Then, we proceed with t-SNE on the landmark points.\n\n\\subsection{Approximating P}\n\nAn observation made in \\cite{van2014accelerating} was that since we use a Gaussian kernel for $P$, points further than 3 standard deviations from the mean have almost zero probabilities, and as such, do not affect the KL divergence term. Therefore, no harm would come if we simply ignored these terms. In practice, this means that we only compute the $p_{ij}$ terms for $\\left \\lfloor 3u \\right \\rfloor$ neighbours, where $u$ is the perplexity.\n\nIn \\cite{van2014accelerating}, exact nearest neighbours are used. These can be efficiently computed in $\\mathcal{O}(n \\log n)$ using tree structures, thus reducing the complexity from $\\mathcal{O}(n^2)$ needed for pairwise distances.\n\nThe preferred exact nearest neighbour method are vantage point trees (also referred to as VP trees). \\cite{yianilos1993data} presented VP trees and compared their performance to another popular tree based nearest neighbour search method -- KD trees. VP trees were shown to require far fewer queries when dealing with high dimensions, as t-SNE often does.\\cite{van2014accelerating} also provide a comparison with dual-trees, where VP trees, again, perform favourably.\n\nMore recently, it was shown in \\cite{linderman2017efficient} that approximate nearest neighbours perform just as well. Approximate nearest neighbour algorithms are often orders of magnitude faster than exact nearest neighbour search, allowing us to scale this step to much larger data than before.\n\n\\subsection{Barnes-Hut}\n\nHaving drastically improved the complexity of $F_\\text{attr}$, we are still left with quadratic $\\mathcal{O}(n^2)$ complexity for $F_\\text{rep}$, required by the normalization term $Z$.\n\n\\cite{van2014accelerating} notice that computing $F_\\text{rep}$ can be posed as an N-body simulation problem. This problem has been addressed physics simulation community and can be efficiently solved in $\\mathcal{O}(n \\log n)$ time using Barnes-Hut trees. The main idea behind this approximation is that clusters of points far away for the current point $i$ will have similar contribution, therefore we can summarize entire regions of space (denoted cells in the following) by computing the center of mass of the region $\\mathbf{y}_{\\text{cell}}$, computing the interaction between $i$ and $\\mathbf{y}_{\\text{cell}}$ and adding this interaction up $N_{\\text{cell}}$ times, where $N_{\\text{cell}}$ is the number of points in the given region, given they are far enough from our query point $i$. The space is split into square regions and represented by a space splitting tree (a quad-tree in 2D and an oct-tree in 3D) which can be built in linear time.\n\nThe ``far enough'' is determined by a parameter $\\theta$, which controls how accurate our estimations are. If the following relation holds, then the cell is summarized\n\n\\begin{equation}\n\\frac{r_\\text{cell}}{|| \\mathbf{y}_i - \\mathbf{y}_{\\text{cell}} || ^2} < \\theta\n\\end{equation}\n\nwhere $r_\\text{cell}$ represents the length of the diagonal of the cell. Larger values of $\\theta$ produce more accurate estimates. Setting $\\theta$ to 0 computes all the pairwise interactions as the condition can never be met. Scikit-learn recommends values between 0.2 and 0.8, as anything above and below that quickly result in long computation time and large error,  respectively.\n\nIt is worth noting that this approach scales fairly well for 1, 2 and 3 dimensions, but further than that, the complexity becomes prohibitively expensive. This is not really an issue, since we humans can only perceive 3 dimensions, and most visualizations are 2D.\n\n\\subsection{FFT Accelerated Interpolation}\n\nWe can write an equivalent expression for the repulsive forces\n\n\\begin{align}\nF_\\text{rep} &= \\sum_{j \\neq i} q_{ij}^2 Z \\left ( \\mathbf{y}_i - \\mathbf{y}_j \\right )\n\\intertext{Plugging in the expressions for $q_{ij}$ and $Z$}\n&= \\sum_{j \\neq i} \\frac{\\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 \\right )^{-2}}{\\sum_{k \\neq l}\\left ( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 \\right )^{-2}} \\frac{\\left ( \\mathbf{y}_i - \\mathbf{y}_j \\right )}{\\sum_{k \\neq l}\\left ( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 \\right )} \\\\\n\\intertext{Putting the top and bottom terms together}\n&= \\left ( \\sum_{j \\neq i} \\frac{\\mathbf{y}_i - \\mathbf{y}_j}{\\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 \\right )^{2}} \\right ) \n\\bigg/\n\\left( \\sum_{k \\neq l} \\frac{1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2}{\\left ( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 \\right )^{2}} \\right) \\\\\n&= \\left ( \\sum_{j \\neq i} \\frac{\\mathbf{y}_i - \\mathbf{y}_j}{\\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 \\right )^{2}} \\right )\n\\bigg/\n\\left( \\sum_{k \\neq l} \\frac{1}{\\left ( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 \\right )} \\right)\n\\end{align}\n\nWe can also write an expression for each term of $\\mathbf{y}_i$ individually:\n\\begin{equation}\nF_{\\text{rep}, i}(m) = \\left ( \\sum_{j \\neq i} \\frac{\\mathbf{y}_i(m) - \\mathbf{y}_j(m)}{\\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 \\right )^{2}} \\right )\n\\bigg/\n\\left( \\sum_{k \\neq l} \\frac{1}{\\left ( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 \\right )} \\right)\n\\end{equation}\n\nwhere $\\mathbf{y}_i(m)$ denotes the $m^{\\text{th}}$ component of $\\mathbf{y}$ i.e. $m \\in \\{1, 2\\}$ in the 2D case.\n\n\\cite{linderman2017efficient} make the acute observation that the repulsive forces $F_\\text{rep}$ can be written as $s + 2$ sums of the form\n\n\\begin{equation}\n\\phi(\\mathbf{y}_i) = \\sum_j K (\\mathbf{y}_i, \\mathbf{y}_j) q_{ij}\n\\end{equation}\n\nwhere $K(y, z)$ is either the Cauchy kernel or the squared Cauchy kernel and $s$ is the dimensionality of $Y$\n\n\\begin{equation}\nK_1(y, z) = \\frac{1}{\\left( 1 + || \\mathbf{y} - \\mathbf{z} ||^2 \\right)}, \\quad\\text{or}\\quad K_2(y, z) = \\frac{1}{ \\left( 1 + || \\mathbf{y} - \\mathbf{z} ||^2 \\right) ^2}\n\\end{equation}\n\nTo make the sums concrete, consider the 2D case:\n\n\\begin{align}\n\\phi_{1, i} &= \\sum_{j \\neq i} \\frac{1}{\\left( 1 + || \\mathbf{y}_j - \\mathbf{y}_i ||^2 \\right)} \\notag \\\\\n\\phi_{2, i} &= \\sum_{j \\neq i} \\frac{\\mathbf{y}_j(1)}{\\left( 1 + || \\mathbf{y}_j - \\mathbf{y}_i ||^2 \\right)^2} \\notag \\\\\n\\phi_{3, i} &= \\sum_{j \\neq i} \\frac{\\mathbf{y}_j(2)}{\\left( 1 + || \\mathbf{y}_j - \\mathbf{y}_i ||^2 \\right)^2} \\notag \\\\\n\\phi_{4, i} &= \\sum_{j \\neq i} \\frac{1}{\\left( 1 + || \\mathbf{y}_j - \\mathbf{y}_i ||^2 \\right)^2} \\notag\n\\end{align}\n\nthe the repulsive forces can be expressed in terms of these 4 sums as follows:\n\n\\begin{align}\nF_{\\text{rep}, i}(1) &= \\left ( \\sum_{j \\neq i} \\frac{\\mathbf{y}_i(1) - \\mathbf{y}_j(1)}{\\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 \\right )^{2}} \\right )\n\\bigg/\n\\left( \\sum_{k \\neq l} \\frac{1}{\\left ( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 \\right )} \\right) \\notag \\\\\n&= (\\phi_{2, i} - \\mathbf{y}_{i}(1)\\phi_{4, i}) / Z, \\\\\nF_{\\text{rep}, i}(2) &= \\left ( \\sum_{j \\neq i} \\frac{\\mathbf{y}_i(2) - \\mathbf{y}_j(2)}{\\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 \\right )^{2}} \\right )\n\\bigg/\n\\left( \\sum_{k \\neq l} \\frac{1}{\\left ( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 \\right )} \\right) \\notag \\\\\n&= (\\phi_{3, i} - \\mathbf{y}_{i}(2)\\phi_{4, i}) / Z,\n\\end{align}\n\nwhere\n\n\\begin{align}\nZ &= \\sum_j \\phi_{1, j}\n\\end{align}\n\nThe key idea in this approach is that since we have smooth kernels $K_1$ and $K_2$, we can approximate them using polynomial interpolation. Of course, the choice of interpolants is entirely up to us, but we we evaluate our kernel functions at these points and interpolate our true data using these. To make things computationally efficient, we can set the interpolants to be equispaced points on the space spanned by the data.\n\nThis is very convenient, because the kernels in question are all translation invariant and when we evaluate them at the interpolants, then the kernel matrix $K$ will be Toeplitz. This means that it is enough to evaluate the Kernel for the left-most point in space in 1D. In 2d, our $K$ is actually a 3D tensor, but is again, Toeplitz.\n\nLinear algebra tells us we can embed any Toeplitz matrix into a circulant matrix. This is desirable, because now we can perform matrix-vector multiplication in the frequency domain in linear time, with the slowest part being the FFT and IFFT transforms in $\\mathcal{O}(n \\log n)$ time.\n\nFinally, having evaluated the repulsive forces at the interpolants, we just need to interpolate the forces on our true data. This can be done in linear time $\\mathcal{O}(n)$.\n\nDoing this, we have successfully made the overall complexity independent of $N$, and have shifted the brunt of the work onto the number of chosen interpolation points, so the time complexity will rely heavily on that. In practice, we split the input space into equally sized intervals, and then have 3 interpolation points in each interval. While we could increase the number of interpolation points, it is preferable to increase the number of intervals (due to the Runge phenomenon in interpolation). Increasing the number of interpolation points also increases the accuracy of the approximation, but comes at a computation cost.\n\nLike the Barnes-Hut variant, this method becomes very inefficient for higher dimensions, as the number of interpolation points needed scales exponentially with $d$. In practice, this isn't an issue because most often, we want to inspect 2D embeddings.\n\n\\section{Implementation details}\n\n\\subsection{Perplexity}\n\nThe following section explains how perplexity is formulated so the code can run efficiently. Perplexity is defined as\n\n\\begin{align}\n\\text{Perplexity}(P_i) &= 2^{H(P_i)}\n\\intertext{where $H$ is the Shannon entropy of a discrete distribution}\nH(P_i) = -\\sum_i p_{j \\mid i} \\log_2 (p_{j \\mid i})\n\\intertext{In code, the following is more practical to avoid computing $2^{x}$ whereas perplexity stays fixed:}\n\\log(\\text{Perplexity}(P_i)) &= -\\sum_i p_{j \\mid i} \\log (p_{j \\mid i})\n\\end{align}\n\nRemember that $P_i$ is just a Gaussian distribution centered on point $i$, given by\n\\begin{align}\np_i(d_i) &= \\frac{1}{\\sqrt{2 \\pi} \\sigma} \\exp \\left ( -\\frac{d_{ij}^2}{2 \\sigma^2} \\right )\n\\intertext{however, since we'll be performing row-normalization by hand, something proportional is sufficient}\n&\\sim \\exp \\left ( -\\frac{d_{ij}^2}{2 \\sigma^2} \\right )\n\\end{align}\n\nIn most implementations this Gaussian is parameterized with $\\beta = 1 / 2\\sigma^2$ and therefore we compute $\\exp \\left ( -d_{ij}^2 \\beta \\right )$ in practice. In our case, we actually compute $ \\frac{1}{\\sigma} \\exp \\left ( -d_{ij}^2 \\beta \\right )$ because we allow a multiscale approach, which mixes several Gaussians together. We also reparameterize our distribution to use the more interpretable precision $\\tau = 1 / \\sigma^2$ instead of $\\beta$. Therefore our probability density is given by\n\n\\begin{equation}\np_i(d_i) \\sim \\sqrt{\\tau} \\exp \\left ( -\\frac{d_{ij}^2 \\tau}{2} \\right )\n\\end{equation}\n\nWe now plug in our parametrization into the entropy and arrive at a convenient form which can be coded efficiently.\n\n\\begin{align}\nH_i &= -\\sum_j \\frac{\\sqrt{\\tau} \\exp \\left ( -d_{ij}^2 \\tau / 2 \\right ) }{\\sum_k \\sqrt{\\tau} \\exp \\left ( -d_{ik}^2 \\tau / 2 \\right )} \\log \\left ( \\frac{\\sqrt{\\tau} \\exp \\left ( -d_{ij}^2 \\tau / 2 \\right ) }{\\sum_k \\sqrt{\\tau} \\exp \\left ( -d_{ik}^2 \\tau / 2 \\right )} \\right ) \\\\\n\\intertext{The first term is just $p_{j\\mid i}$ and we can split up the log into two parts}\n&= -\\sum_j p_{j\\mid i} \\left [ \\log \\left ( \\sqrt{\\tau} \\exp \\left ( -d_{ij}^2 \\tau / 2 \\right ) \\right ) - \\log \\left ( \\sum_k \\sqrt{\\tau} \\exp \\left ( -d_{ik}^2 \\tau / 2 \\right ) \\right ) \\right ]\n\\intertext{Notice now that the first term in the square brackets almost has the form $\\log (\\exp (x))$. For clarity, we will also denote the normalization sum as $Z$.}\n&= -\\sum_j \\left [ p_{j\\mid i} \\left ( \\frac{1}{2} \\log \\tau - d_{ij}^2 \\tau / 2 \\right ) \\right ] + \\sum_j p_{j\\mid i} \\log Z \\\\\n&= -\\frac{1}{2} \\log \\tau \\sum_j p_{j\\mid i} + \\frac{\\tau}{2} \\sum_j p_{j\\mid i} d_{ij}^2 + \\sum_j p_{j\\mid i} \\log Z\n\\intertext{We move the first term to the end to make the sign unmissable. Since $p_i$ is a proper probability distribution, its elements sum up to 1, leaving us with}\n&= \\frac{\\tau}{2} \\sum_j p_{j\\mid i} d_{ij}^2 + \\log Z-\\frac{1}{2} \\log \\tau\n\\end{align}\n\nThis can be computed in two passes over the data. The first pass computes the unnormalized probabilities $\\tilde{p}_{j\\mid i}$ and accumulate the normalization constant $Z$. In the second pass, the first term can be computed.\n\nIn other implementation e.g. scikit-learn, the expression is computed without $\\sqrt{\\tau}$. It's easy to see that the result will be similar (and indeed, this is used in their code), but without the $-1/2 \\log \\tau$ term and parameterized with $\\beta = \\tau / 2$.\n\n\n\\subsection{Fast KL Divergence}\n\nDuring computation of negative gradients, we do not know the value of the normalization term $Z$ during intermediate steps. Therefore, in order to compute the KL divergence of the embedding, we would need at least two passes over the data points, first to compute the unnormalized $q_{ij}$s, and secondly to normalize them and compute the KL divergence. By rewriting the KL divergence in terms of unnormalized $q_{ij}$s, we can compute the entire error with a single pass over the data points by accumulating the $\\sum_{ij} p_{ij}$ and $\\sum_{ij}q_{ij}$ in the first pass.\n\n\\begin{align}\nKL(P \\mid \\mid Q) &= \\sum_{ij} p_{ij} \\log \\frac{p_{ij}}{q_{ij}} \\\\\n&= \\sum_{ij} p_{ij} \\log \\left ( p_{ij} \\frac{Z}{\\hat{q}_{ij}} \\right )\n\\intertext{where $\\hat{q}_{ij}$ denotes the unnormalized values $q_{ij}$}\n&= \\sum_{ij} p_{ij} \\log \\frac{p_{ij}}{\\hat{q}_{ij}} + \\sum_{ij} p_{ij} \\log Z\n\\end{align}\n\nTherefore the first term requires a single pass over all $i, j$s and the second term can be computed in constant time if we accumulate the sums of $P$ and $Q$.\n\nThis is already included in most software packages e.g. scikit-learn.\n\n\\subsection{KL Divergence with exaggeration}\n\nThe implemented optimization methods don't have a notion of exaggeration, they simply take an affinity matrix $P$ containing the probabilities of points $j$ appearing close to $i$. Exaggeration is used to scale $P$ by some constant factor $\\alpha$ (this means that entries in the affinity matrix $P$ are not proper probabilities) to help separate clusters in the beginning of the optimization. These methods also compute the KL divergence during optimization (for efficiency), and, as such, the error is incorrect because we don't account for the scaling $\\alpha$.\n\nThis section derives a simple correction for the KL divergence error term so we can get the true error of the embedding even when $P$ is exaggerated.\n\n\\begin{align}\nKL(P \\mid \\mid Q) &= \\sum_{ij} p_{ij} \\log \\frac{p_{ij}}{q_{ij}}\n\\intertext{We need to introduce the scaling i.e. exaggeration factor $\\alpha$ to every $p_{ij}$ term, so we multiply some terms by $1 = \\alpha/\\alpha$.}\n&= \\sum_{ij} \\frac{\\alpha}{\\alpha}p_{ij} \\log \\frac{\\alpha p_{ij}}{\\alpha q_{ij}} \\\\\n\\intertext{Exaggeration means that the $p_{ij}$ terms get multiplied by $\\alpha$, so we need to find an expression for the KL divergence that includes only $\\alpha p_{ij}$ and $q_{ij}$ and some other factor that will correct for $\\alpha$.}\n&= \\frac{1}{\\alpha} \\sum_{ij} \\alpha p_{ij} \\left ( \\log \\frac{\\alpha p_{ij}}{q_{ij}} - \\log \\alpha \\right ) \\\\\n&= \\frac{1}{\\alpha} \\left ( \\sum_{ij} \\alpha p_{ij} \\log \\frac{\\alpha p_{ij}}{q_{ij}} \\right ) - \\frac{1}{\\alpha} \\left ( \\sum_{ij} \\alpha p_{ij} \\log \\alpha \\right )\n\\intertext{We notice in the first term is exactly the KL divergence where $p_{ij}$s are scaled by $\\alpha$. We also notice in the second term that $\\sum_{ij} P_{ij} = 1$ and that $\\alpha$ cancels out, leaving us with}\n&= \\frac{1}{\\alpha} \\left ( \\sum_{ij} \\alpha p_{ij} \\log \\frac{\\alpha p_{ij}}{q_{ij}} \\right ) - \\log \\alpha\n\\end{align}\n\nThe first term is computed by the gradient method (since it only knows about the scaled $P$), the second term can easily be computed post-optimization, allowing us to get the correct KL divergence.\n\n\\subsection{Variable Degrees of Freedom}\n\nKobak \\textit{et al.}~\\cite{kobak2019heavy} suggest that using variable degrees of freedom can be used to improve embeddings.\n\nStandard t-SNE uses the t-distribution with a single degree of freedom. This is defined as \n\n\\begin{equation}\nq_{ij} \\propto \\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 / \\alpha \\right )^{-\\alpha} = \\frac{1}{\\left( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 / \\alpha \\right)^\\alpha }.\n\\end{equation}\n\nIn standard t-SNE $\\alpha=1$ so this simplifies to the standard formulation\n\\begin{equation}\nq_{ij} \\propto \\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 \\right )^{-1} = \\frac{1}{1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 }\n\\end{equation}\nwhere we have omitted the normalization constant.\n\nThe gradient of the t-SNE loss function then becomes\n\\begin{align}\n\\frac{\\partial C}{\\partial \\mathbf{y}_i} &= 4 \\sum_{j \\neq i} \\left ( p_{ij} - q_{ij} \\right ) q_{ij}^{1/\\alpha} \\left ( \\mathbf{y}_i - \\mathbf{y}_j \\right )\n\\end{align}\nwhere $q_{ij}$ is, again, the unnormalized kernel between points $i$ and $j$.\n\nDecomposing this into the attractive and repulsive forces gives us\n\\begin{align}\n\\mathbf{F}_{\\text{attr}} &= 4 \\sum_j p_{ij} q_{ij}^{1/\\alpha} (\\mathbf{y}_i - \\mathbf{y}_j), \\\\\n\\mathbf{F}_{\\text{rep}} &= - 4 \\sum_j q_{ij}^{\\frac{\\alpha+1}{\\alpha}} / Z (\\mathbf{y}_i - \\mathbf{y}_j).\n\\end{align}\n\nSee the original publication for more details.\n\n\\subsubsection{Implementation}\n\nAdapting the implementation for computing the attractive forces and the Barnes-Hut repulsive forces is straightforward. Adapting the interpolation based computation of repulsive forces is a bit more involved.\n\nThe direct implementation of the approach described in the paper leads to a solution requiring two different kernels. We describe the 1D case, but the extension to the 2D case is straightforward.\n\n\\begin{align}\n\\mathbf{F}_\\text{rep} &= \\sum_{j \\neq i} q_{ij}^{\\frac{\\alpha+1}{\\alpha}} Z \\left ( \\mathbf{y}_i - \\mathbf{y}_j \\right ) \\\\\n&=\n\\sum_{j \\neq i} \\left( \\frac{\\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 / \\alpha \\right )^{-\\alpha}}{\\sum_{k \\neq l} \\left ( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 / \\alpha \\right )^{-\\alpha}} \\right) ^{\\frac{\\alpha+1}{\\alpha}}\n\\frac{\\mathbf{y}_i - \\mathbf{y}_j}{\\sum_{k \\neq l}\\left ( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 / \\alpha \\right )^{\\alpha}} \\\\\n&=\n\\sum_{j \\neq i} \\frac{\\mathbf{y}_i - \\mathbf{y}_j}{\\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 / \\alpha \\right )^{\\alpha \\left( \\frac{\\alpha+1}{\\alpha} \\right)}}\n\\bigg/\n\\left( \\sum_{k \\neq l} \\frac{\\left( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 / \\alpha \\right)^\\alpha}{\\left( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 / \\alpha \\right)^{\\alpha \\left(\\frac{\\alpha+1}{\\alpha} \\right) }} \\right) \\\\\n&=\n\\sum_{j \\neq i} \\frac{\\mathbf{y}_i - \\mathbf{y}_j}{\\left ( 1 + || \\mathbf{y}_i - \\mathbf{y}_j ||^2 / \\alpha \\right )^{\\alpha + 1}}\n\\bigg/\n\\left( \\sum_{k \\neq l} \\frac{1}{\\left( 1 + || \\mathbf{y}_k - \\mathbf{y}_l ||^2 / \\alpha \\right)} \\right)\n\\end{align}\n\nEvaluating this sum using the interpolation scheme would require two separate kernels with three terms\n\\begin{align}\n\\phi_{1,j} &= \\sum_{j \\neq i} \\frac{1}{\\left( 1 + || \\mathbf{y}_j - \\mathbf{y}_i ||^2 / \\alpha \\right)^{\\alpha+1}}, \\\\\n\\phi_{2,j} &= \\sum_{j \\neq i} \\frac{\\mathbf{y}_j}{\\left( 1 + || \\mathbf{y}_j - \\mathbf{y}_i ||^2 / \\alpha \\right)^{\\alpha+1}}, \\\\\n\\phi_{3,j} &= \\sum_{j \\neq i} \\frac{1}{\\left( 1 + || \\mathbf{y}_j - \\mathbf{y}_i ||^2 / \\alpha \\right)}.\n\\end{align}\nThen, we can calculate the necessary quantities\n\\begin{align}\nN_i &= \\mathbf{y}_i \\phi_{1,j} - \\phi_{2,j} \\\\\nZ &= \\sum_j \\phi_{3,j}\n\\end{align}\nwhere $N_i$ is the unnormalized numerator of the repulsive forces.\n\n%\n\\section{Transform}\n\n\\subsection{Direct optimization}\n\n\\subsection{General framework of cost functions}\n\\cite{bunte2012general}\n\n\\subsection{MDS interpolation}\nMDS Interpolation~\\cite{bae2010dimension}. A similar approach might be able to be applied to t-SNE. In essence, they run MDS on a sample of points. Then for each new point, we compute the k-nearest neighbours and optimize the stress function w.r.t. only those points. In their paper, they derive equations that can be used for efficient optimization via majorization.\n\n\\subsection{Kernel t-SNE}\n\\cite{gisbrecht2012out} claim to outperform direct mapping t-SNE using a direct kernel mapping. This paper is not very useful. The graph is misleading and the table at the end is informative, but run only on small datasets. Their subsequent paper is much better and throughout.\n\nIn \\cite{gisbrecht2015parametric}, kernel t-SNE is described in more detail and parameters are chosen in a more principled manner.\n\nDescribes how to integrate class labels into embedding using Fischer information.\n\nThe issue of kernel t-SNE is that we have to compute the inverse of the interaction matrix K. We can use P as the interaction matrix, and P is sparse, but the inverse of that is very dense, and for any reasonably sized data set, this is unfeasable.\n\n\n\\bibliography{references}\n\\bibliographystyle{apalike}\n\n\\end{document}\n", "meta": {"hexsha": "851e9ce7b0d12477f32dd89c3326c9aa4e3b35dd", "size": 26466, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/notes.tex", "max_stars_repo_name": "TimRepke/openTSNE", "max_stars_repo_head_hexsha": "22c306c3ec087e4b4be364431bc3626190a85c86", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 622, "max_stars_repo_stars_event_min_datetime": "2018-12-18T15:04:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T09:37:42.000Z", "max_issues_repo_path": "notes/notes.tex", "max_issues_repo_name": "TimRepke/openTSNE", "max_issues_repo_head_hexsha": "22c306c3ec087e4b4be364431bc3626190a85c86", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 115, "max_issues_repo_issues_event_min_datetime": "2018-12-17T14:59:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-17T21:40:33.000Z", "max_forks_repo_path": "notes/notes.tex", "max_forks_repo_name": "TimRepke/openTSNE", "max_forks_repo_head_hexsha": "22c306c3ec087e4b4be364431bc3626190a85c86", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 101, "max_forks_repo_forks_event_min_datetime": "2019-01-11T02:35:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:22:39.000Z", "avg_line_length": 73.5166666667, "max_line_length": 952, "alphanum_fraction": 0.7030151893, "num_tokens": 8393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.8856314723088733, "lm_q1q2_score": 0.8154803163461349}}
{"text": "\n\\subsection{Own-price elasticity of demand}\n\nWe have our Marshallian demand function:\n\n\\(x_i=x_{di}(I, \\mathbf p)\\)\n\nThe derivative of this with respect to price is the additional amount consumed after prices increase.\n\n\\(\\dfrac{\\delta }{p_i}x_{di}(I, \\mathbf p)\\)\n\nFor the Cobb-Douglas utility function, this is:\n\n\\(\\dfrac{\\delta }{p_i}x_{di}(I, \\mathbf p)\\)\n\nIn addition to the derivative, we may be interested in the elasticity. That is, the proportional change in output after a change in price.\n\n\\(\\xi_i =\\dfrac{\\dfrac{\\Delta x_i}{x_i}}{\\dfrac{\\Delta p_i}{p_i}}\\)\n\n\\(\\xi_i =\\dfrac{\\Delta x_i}{\\Delta p_i}\\dfrac{p_i}{x_i}\\)\n\nFor the point-price elasticity of demand we evaluate infintesimal movements.\n\n\\(\\xi_i =\\dfrac{\\delta x_i}{\\delta p_i}\\dfrac{p_i}{x_i}\\)\n\n\\subsection{Constant price elasticity of demand}\n\nIf the point-price elasticity of demand is constant we have:\n\n\\(\\xi_i =\\dfrac{\\delta x_i}{\\delta p_i}\\dfrac{p_i}{x_i}=c\\)\n\nThis means that small changes in the price at low level cause large changes in quantity.\n\n\\subsection{Arc-price elasticity of demand}\n\nWe may have price changes which are non-infintesimal.\n\n\\(E_d=\\dfrac{\\Delta Q/\\bar Q}{\\Delta P/\\bar P}\\)\n\nWhere \\(\\bar Q\\) and \\(\\bar P\\) are the mid-points between the start and end.\n\n", "meta": {"hexsha": "396ece667107df2e477f838e5b98d069c6e7f444", "size": 1259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/consumer/02-03-elasticityPrice.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/consumer/02-03-elasticityPrice.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/consumer/02-03-elasticityPrice.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9761904762, "max_line_length": 138, "alphanum_fraction": 0.719618745, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294588, "lm_q2_score": 0.8652240686758841, "lm_q1q2_score": 0.8154795028652366}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n        \\section{Practice Problems}\n        \\begin{example}{}{}\n                Consider the curve described by \\(\\vec{r}=\\left(\\frac{t^3}{3}-2t\\right)\\i + \\left(\\frac{t^3}{3}+2t\\right)\\j + \\sqrt{2}t^2\\k\\) for \\(t\\in\\mathbb{R}\\). Find the arc length from \\(t=0\\) to \\(t=1\\).\n                \\tcblower\n                First, we find that\n                \\[\n                \\vec{r}'(t)=\\left(t^2+2\\right)\\i + \\left(t^2+2\\right)\\j +2\\sqrt{2}t\\j\n                \\]\n                so\n                \\[\n                |\\vec{r}'(t)|^2=\\left(t^2+2\\right)^2 + \\left(t^2+2\\right)^2 +(2\\sqrt{2}t)^2 = 2\\left(t^2+2\\right)^2\n                \\]\n                which gives us \\(|\\vec{r}'(t)|=\\sqrt{2}(t^2+2)\\), and thus the arc length is given by\n                \\[\n                \\int_0^1\\sqrt{2}(t^2+2)\\,dt = \\frac{7\\sqrt{2}}{3}\n                \\]\n        \\end{example}\n        \\begin{example}{}{}\n                For the above curve, find the curvature at \\(t=0\\).\n                \\tcblower\n                We previously found\n                \\[\n                \\vec{r}'(t)=\\left(t^2+2\\right)\\i + \\left(t^2+2\\right)\\j +2\\sqrt{2}t\\j\n                \\]\n                so we may calculate\n                \\[\n                \\vec{r}''(t)=2t\\i + 2t\\j + 2\\sqrt{2}\\k\n                \\]\n                The curvature at \\(t=0\\) is then given by\n                \\[\n                \\kappa = \\frac{|\\vec{r}'(0)\\times\\vec{r}''(0)|}{|\\vec{r}'(0)|^3}\n                \\]\n                so we may begin by calculating\n                \\[\n                \\vec{r}'(0)\\times\\vec{r}''(0)=4\\sqrt{2}\\i+4\\sqrt{2}\\j\n                \\]\n                which has magnitude \\(|\\vec{r}'(0)\\times\\vec{r}''(0)|=8\\). Finally, we calculate \\(|\\vec{r}'(0)|=2\\sqrt{2}\\), so we obtain the final solution\n                \\[\n                \\kappa = \\frac{8}{\\sqrt{8}^3}=\\frac{1}{\\sqrt{8}}\n                \\]\n        \\end{example}\n        \\begin{example}{}{}\n                Verify that \\(\\frac{d}{dt}\\vec{u}'(t)\\times\\vec{u}''(t)=\\vec{u}'(t)\\times\\vec{u}'''(t)\\).\n                \\tcblower\n                By the derivative rule for the cross product, we have\n                \\[\n                \\frac{d}{dt}\\vec{u}'(t)\\times\\vec{u}''(t)=\\vec{u}''(t)\\times\\vec{u}''(t) + \\vec{u}'(t)\\times\\vec{u}'''(t)\n                \\]\n                but for any vector we always have \\(\\vec{v}\\times\\vec{v}=0\\), so this simplifies to\n                \\[\n                \\frac{d}{dt}\\vec{u}'(t)\\times\\vec{u}''(t)=\\vec{u}'(t)\\times\\vec{u}(t)'''\n                \\]\n        \\end{example}\n        \\begin{example}{}{}\n                Expand and simplify \\(\\frac{d}{dt}\\left((\\vec{u}\\times\\vec{u}')\\cdot(\\vec{u}'\\times\\vec{u}'')\\right)\\).\n                \\tcblower\n                \\begin{align*}\n                        \\frac{d}{dt}\\left((\\vec{u}\\times\\vec{u}')\\cdot(\\vec{u}'\\times\\vec{u}'')\\right)&=\n                        (\\vec{u}\\times\\vec{u}')'\\cdot(\\vec{u}'\\times\\vec{u}'')+(\\vec{u}\\times\\vec{u}')\\cdot(\\vec{u}'\\times\\vec{u}'')'\\\\\n                        &=(\\vec{u}'\\times\\vec{u}'+\\vec{u}\\times\\vec{u}'')\\cdot(\\vec{u}'\\times\\vec{u}'')\\\\\n                        &\\quad+(\\vec{u}\\times\\vec{u}')\\cdot(\\vec{u}''\\times\\vec{u}''+\\vec{u}'\\times\\vec{u}''')\\\\\n                        &=(\\vec{u}\\times\\vec{u}'')\\cdot(\\vec{u}'\\times\\vec{u}'')+(\\vec{u}\\times\\vec{u}')\\cdot(\\vec{u}'\\times\\vec{u}''')\n                \\end{align*}\n        \\end{example}\n        \\begin{example}{}{}\n                Consider a smooth vector valued function \\(\\vec{r}\\) for which there exists a point \\(P\\) which lies on every normal plane to  \\(\\vec{r}\\). Prove that the curve lies on a sphere.\n                \\tcblower\n                First, note that we may take \\(P=0\\) without loss of generality, as any curve with such a point my be translated such that that \\(P=0\\) without changing the geometric properties of the curve.\n\n                The normal plane to the curve at \\(\\vec{r}(t_0)\\) must be perpendicular to \\(\\vec{r}'(t_0)\\), so we have\n                \\[\n                \\vec{r}'(t)\\cdot((x-x_0)\\i+(y-y_0)\\j+(z-z_0)\\k)=0\n                \\]\n                but since \\(P=0\\) must always satisfy the above, it must be that \n                \\[\n                \\vec{r}'(t)\\cdot(-x_0\\i+-y_0\\j+-z_0\\k)=\\vec{r}'(t)\\cdot(-\\vec{r}(t))=0\n                \\]\n                which we have previously shown requires that \\(\\vec{r}\\) lies on the surface of a sphere.\n        \\end{example}\n        \\begin{example}{}{}\n                Consider the parabola described by \\(\\vec{r}(t)=t\\i+\\frac{t^2}{2]\\j}\\), with unit tangent vector \\(\\vec{T}(t)\\). Find a parameterization \\(\\vec{r}(u)\\) such that \\(|\\frac{d\\vec{T}}{du}|=1\\).\n                \\tcblower\n                First, we find that \\(\\vec{r}'(t)=\\i+t\\j\\), so \\(|\\vec{r}'(t)|=\\sqrt{1+t^2}\\) and\n                \\[\n                \\vec{T}(t)=\\frac{1}{\\sqrt{1+t^2}}(\\i+t\\j)\n                \\]\n\n                The solution may then be completed by noting that since we require that\n                \\[\n                \\left|\\frac{d\\vec{T}}{du}\\right|=1\n                \\]\n                it must be that\n                \\[\n                \\frac{du}{dt}=|\\vec{T}'(t)|\n                \\]\n                which may be integrated to find an expression for \\(u\\). This process is elided for brevity.\n        \\end{example}\n\\end{document}\n", "meta": {"hexsha": "8bd97490aa04c29b1d5172e51e23feb3025d25b7", "size": 5346, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lec_4.tex", "max_stars_repo_name": "CrashAndSideburns/MATH227-Notes", "max_stars_repo_head_hexsha": "ec5356ff816c2f51828e4f8b64b5ae0a8b0c8cd3", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-25T04:16:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T04:16:23.000Z", "max_issues_repo_path": "src/lec_4.tex", "max_issues_repo_name": "CrashAndSideburns/MATH227-Notes", "max_issues_repo_head_hexsha": "ec5356ff816c2f51828e4f8b64b5ae0a8b0c8cd3", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lec_4.tex", "max_forks_repo_name": "CrashAndSideburns/MATH227-Notes", "max_forks_repo_head_hexsha": "ec5356ff816c2f51828e4f8b64b5ae0a8b0c8cd3", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.4117647059, "max_line_length": 210, "alphanum_fraction": 0.4414515526, "num_tokens": 1761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8947894675053568, "lm_q1q2_score": 0.8153140010486298}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n\\chapter{Bit Manipulation}\nMany books on algorithmic problem solving seems forget about one topic--bit and bit manipulation. Bit is how data is represented and saved on the hardware. Thus knowing such concept and bit manipulation using Python sometimes can also help us device more efficient algorithms, either space or time complexity in the later Chapter. \n\n\nFor example, how to convert a char or integer to bit, how to get each bit, set each bit, and clear each bit. Also, some more advanced bit manipulation operations. After this, we will see some examples to show how to apply bit manipulation in real-life problems. \n%%%%%%%%%%%%%%%%%%%%%%Bit operators%%%%%%%%%%%%\n\\section{Python Bitwise Operators}\n\\label{sec_basic_bit_operator}\nBitwise operators include <<, >>, \\&, |, \\~, \\^. All of these operators operate on signed or unsigned numbers, but instead of treating that number as if it were a single value, they treat it as if it were a string of bits. Twos-complement binary is used for representing the singed number.  \n\n\n\n\nNow, we introduce the six bitwise operators.\n\\paragraph{x \\texttt{<<} y} Returns $x$ with the bits shifted to the left by $y$ places (and new bits on the right-hand-side are zeros). This is the same as multiplying $x$ by $2^y$.\n\n\\paragraph{x \\texttt{>>} y} Returns $x$ with the bits shifted to the right by $y$ places. This is the same as dividing $x$ by $2^y$, same result as the $//$ operator. This right shift is also called \\textit{arithmetic right shift}, it fills in the new bits with the value of the sign bit. \n\n\\paragraph{x \\texttt{\\&} y} \"Bitwise and\". Each bit of the output is 1 if the corresponding bit of $x$ AND of $y$ is 1, otherwise it's 0. It has the following property: \n\\begin{lstlisting}[language=Python]\n# keep 1 or 0 the same as original\n1 & 1 = 1\n0 & 1 = 0\n# set to 0 with & 0\n1 & 0 = 0\n0 & 0 = 0\n\\end{lstlisting}\n\n\\paragraph{x \\texttt{|} y} \"Bitwise or\".  Each bit of the output is 0 if the corresponding bit of $x$ AND of $y$ is 0, otherwise it's 1.\n\\begin{lstlisting}[language=Python]\n# set to 1 with | 1\n1 | 1 = 1\n0 | 1 = 1\n\n# keep 1 or 0 the same as original\n1 | 0 = 1\n0 | 0 = 0\n\\end{lstlisting}\n\n\\paragraph{$\\thicksim x\n$} Returns the complement of x - the number you get by switching each 1 for a 0 and each 0 for a 1. This is the same as $-x - 1$(really?). \n\n\\paragraph{x $\\wedge$ y} \"Bitwise exclusive or\". Each bit of the output is the same as the corresponding bit in $x$ if that bit in $y$ is 0, and it's the complement of the bit in $x$ if that bit in $y$ is 1. It has the following basic properties:\n\\begin{lstlisting}[language=Python]\n# toggle 1 or 0 with ^ 1\n1 ^ 1 = 0\n0 ^ 1 = 1\n\n# keep 1 or 0 with ^ 0\n1 ^ 0 = 1\n0 ^ 0 = 0\n\\end{lstlisting}\nSome examples shown: \n\\begin{lstlisting}\nA = 5 = 0101, B = 3 = 0011\n A ^ B = 0101 ^ 0011 = 0110 = 6\n \\end{lstlisting}\nMore advanced properties of XOR operator include:\n \\begin{lstlisting}\na ^ b = c \nc ^ b = a\n\nn ^ n = 0\nn ^ 0 = n\neg. a=00111011, b=10100000 , c= 10011011, c ^b= a\n \\end{lstlisting}\n\n\\paragraph{Logical right shift} The logical right shift is different to the above right shift after shifting it puts a 0 in the most significant bit. It is indicated with a $>>>$ operator n Java. However, in Python, there is no such operator, but we can implement one easily using \\textbf{bitstring} module padding with zeros using $>>=$ operator.\n\\begin{lstlisting}[language=Python]\n>>> a = BitArray(int=-1000, length=32)\n>>> a.int\n-1000\n>>> a >>= 3\n>>> a.int\n536870787\n\\end{lstlisting}\n\n%%%%%%%%%%%%%%%%%%%%%%%Useful Python function%%%%%%%%%%%%%%%%%%%%\n\\section{Python Built-in Functions}\n\\label{sec_bitwise_built_in_function}\n\\paragraph{bin()} The bin() method takes a single parameter \\textbf{num}- an integer and return its \\textit{binary string}. If not an integer, it raises a TypeError exception. \n\\begin{lstlisting}[language=Python]\na = bin(88)\nprint(a)\n# output\n# 0b1011000\n\\end{lstlisting}\nHowever, bin() doesn't return \\textit{binary bits} that applies the two's complement rule. For example, for the negative value:\n\\begin{lstlisting}[language=Python]\na1 = bin(-88)\n# output\n# -0b1011000\n\\end{lstlisting}\n\\paragraph{int(x, base = 10)} The int() method takes either a string x  to return an integer with its corresponding base. The common base are: 2, 10, 16 (hex). \n\\begin{lstlisting}[language=Python]\nb = int('01011000', 2)\nc = int('88', 10)\nprint(b, c)\n# output\n# 88 88\n\\end{lstlisting}\n\n\\paragraph{chr()} The chr() method takes a single parameter of integer and return a character (a string) whose Unicode code point is the integer. If the integer i is outside the range, ValueError will be raised.\n\\begin{lstlisting}[language=Python]\nd = chr(88)\nprint(d)\n# output\n# X\n\\end{lstlisting}\n\\paragraph{ord()} The ord() method takes a string representing one Unicode character and return an integer representing the Unicode code point of that character. \n\\begin{lstlisting}[language=Python]\ne = ord('a')\nprint(e)\n# output\n#  97\n\\end{lstlisting}\n\n%%%%%%%%%%%%%%%%Two's complement Binary%%%%%%%%%%%%%%%%%%%%%%\n\\section{Twos-complement Binary} \nGiven 8 bits, if it is unsigned, it can represent the values 0 to 255 (1111,1111). However, a two's complement 8-bit number can only represent positive integers from 0 to 127 (0111,1111) because the most significant bit is used as sign bit: '0' for positive, and '1' for negative. \n\\begin{equation}\n  \\sum_{i=0}^{N-1} 2^i =  2^{(N-1)}+2^{(N-2)}+...+2^2+2^1+2^0= 2^N-1\n\\end{equation}\nThe twos-complement binary is the same as the classical binary representation for positive integers and differs slightly for negative integers. Negative integers are represented by performing Two's complement operation on its absolute value: it would be $(2^N-n)$ for representing $-n$ with N-bits. \nHere, we show Two's complement binary for eight-bit signed integers in Fig.~\\ref{fig:twos_complement}.  \n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.6\\columnwidth]{fig/eight_bit_two_complement.png}\n    \\caption{Two's Complement Binary for Eight-bit Signed Integers.}\n    \\label{fig:twos_complement}\n\\end{figure}\n\\paragraph{Get Two's Complement Binary Representation}\nIn Python, to get the two's complement binary representation of a given integer, we do not really have a built-in function to do it directly for negative number. Therefore, if we want to know how the two's complement binary look like for negative integer we need to write code ourselves. The Python code is given as:\n\\begin{lstlisting}[language=Python]\nbits = 8\nans = (1 << bits) -2\nprint(ans)\n# output\n# '0b11111110'\n\\end{lstlisting}\nThere is another method to compute: inverting the bits of n (this is called \\textbf{One's Complement}) and adding 1. For instance, use 8 bits integer 5, we compute it as the follows:\n\\begin{align}\n\\label{five}\n    5_{10} &= {0000, 0101}_2, \\\\\n    {-5}_{10} &= {1111, 1010}_2 + 1_2, \\\\ \n    {-5}_{10} &= {1111, 1011}_2\n\\label{five_complement}\n\\end{align}\nTo flip a binary representation, we need expression x XOR '1111,1111', which is $2^N-1$. The Python Code is given:\n\\begin{lstlisting}[language=Python]\ndef twos_complement(val, bits):\n    # first flip implemented with xor of val with all 1's\n    flip_val = val ^ (1 << bits - 1)\n    #flip_val = ~val we only give 3 bits\n    return bin(flip_val + 1)\n\\end{lstlisting}\n\n\\paragraph{Get Two's Complement Binary Result}\nIn Python, if we do not want to see its binary representation but just the result of two's complement of a given positive or negative integer, we can use two operations $-x$ or $\\thicksim +1$. For input 2, the output just be a negative integer -2 instead of its binary representation:\n\\begin{lstlisting}[language=Python]\ndef twos_complement_result(x):\n    ans1 = -x\n    ans2 = ~x + 1\n    print(ans1, ans2)\n    print(bin(ans1), bin(ans2))\n    return ans1\n# output\n# -8 -8\n# -0b1000 -0b1000\n\\end{lstlisting}\nThis is helpful if we just need two's complement result instead of getting the binary representation. \n\n\n%%%%%%%%%%%%%%%%%%%%%%%Useful operation%%%%%%%%%%%%%%%%%%%%\n\\section{Useful Combined Bit Operations}\n\\label{sec_useful_bit_combination}\n\nFor operations that handle each bit, we first need a \\textit{mask} that only set that bit to 1 and all the others to 0, this can be implemented with arithmetic left shift sign by shifting 1 with 0 to n-1 steps for n bits: \n\\begin{lstlisting}[language=Python]\nmask = 1 << i\n\\end{lstlisting}\n\\paragraph{Get ith Bit} In order to do this, we use the property of AND operator either 0 or 1 and with 1, the output is the same as original, while if it is and with 0, they others are set with 0s.\n\\begin{lstlisting}[language=Python]\n# for n bit, i in range [0,n-1]\ndef get_bit(x, i):\n    mask = 1 << i\n    if x & mask:\n        return 1\n    return 0\nprint(get_bit(5,1))\n# output \n# 0\n\\end{lstlisting}\nElse, we can use left shift by i on x, and use AND with a single 1.\n\\begin{lstlisting}[language=Python]\ndef get_bit2(x, i):\n    return x >> i & 1\nprint(get_bit2(5,1))\n# output \n# 0\n\\end{lstlisting}\n\n\\paragraph{Set ith Bit} We either need to set it to 1 or 0. To set this bit to 1, we need matching relation: $1->1, 0->1$. Therefore, we use operator |. To set it to 0: $1->0, 0->0$. Because 0 \\& 0/1 = 0, 1\\&0=1, 1\\&1 = 1, so we need first set that bit to 0, and others to 1. \n\\begin{lstlisting}[language=Python]\n# set it to 1\nx = x | mask\n\n# set it to 0\nx = x & (~mask)\n\\end{lstlisting}\n\n\\paragraph{Toggle ith Bit} Toggling means to turn bit to 1 if it was 0 and to turn it to 0 if it was one. We will be using 'XOR' operator here due to its properties. \n\\begin{lstlisting}[language=Python]\nx = x ^ mask\n\\end{lstlisting}\n\n\\paragraph{Clear Bits} In some cases, we need to clear a range of bits and set them to 0, our base mask need to put 1s at all those positions, Before we solve this problem, we need to know a property of binary subtraction. Check if you can find out the property in the examples below,\n\\begin{lstlisting}[numbers=none]\n1000-0001 = 0111\n0100-0001 = 0011\n1100-0001 = 1011\n\\end{lstlisting}\n\nThe property is, the difference between a binary number n and 1 is all the bits on the right of the rightmost 1 are flipped including the rightmost 1. Using this amazing property, we can create our mask as:\n\\begin{lstlisting}[language=Python]\n# base mask\ni = 5\nmask = 1 << i\nmask = mask -1\nprint(bin(mask))\n# output\n# 0b11111\n\\end{lstlisting}\nWith this base mask, we can clear bits: (1) All bits from the most significant bit till i (leftmost till ith bit) by using the above mask. (2) All bits from the lest significant bit to the ith bit by using $\\thicksim mask$ as mask. The Python code is as follows:\n\\begin{lstlisting}[language=Python]\n# i i-1 i-2 ... 2 1 0, keep these positions\ndef clear_bits_left_right(val, i):\n    print('val', bin(val))\n    mask = (1 << i) -1\n    print('mask', bin(mask))\n    return bin(val & (mask))\n\\end{lstlisting}\n\\begin{lstlisting}[language=Python]\n# i i-1 i-2 ... 2 1 0, erase these positions\ndef clear_bits_right_left(val, i):\n    print('val', bin(val))\n    mask = (1 << i) -1\n    print('mask', bin(~mask))\n    return bin(val & (~mask))\n\\end{lstlisting}\nRun one example:\n\\begin{lstlisting}[numbers=none]\nprint(clear_bits_left_right(int('11111111',2), 5))\nprint(clear_bits_right_left(int('11111111',2), 5))\nval 0b11111111\nmask 0b11111\n0b11111\nval 0b11111111\nmask -0b100000\n0b11100000\n\\end{lstlisting}\n\\paragraph{Get the lowest set bit } Suppose we are given '0010,1100', we need to get the lowest set bit and return '0000,0100'. And for 1100, we get 0100.  If we try to do an AND between 5 and its two's complement as shown in Eq.~\\ref{five} and \\ref{five_complement}, we would see only the right most 1 bit is kept and all the others are cleared to 0. This can be done using expression $x \\&(-x)$, $-x$ is the two's complement of $x$.\n\\begin{lstlisting}[language=Python]\ndef get_lowest_set_bit(val):\n    return bin(val & (-val))\nprint(get_lowest_set_bit(5))\n# output\n# 0b1\n\\end{lstlisting}\nOr, optionally we can use the property of subtracting by 1. \n\\begin{lstlisting}\nx ^ (x & (x -1))\n\\end{lstlisting}\n\\paragraph{Clear the lowest set bit} In many situations we want to strip off the lowest set bit for example in Binary Indexed tree data structure, counting number of set bit in a number. We use the following operations:\n\\begin{lstlisting}[language=Python]\ndef strip_last_set_bit(val):\n    print(bin(val))\n    return bin(val & (val - 1))\nprint(strip_last_set_bit(5))\n# output\n# 0b101\n# 0b100\n\\end{lstlisting}\n\n\n% \\paragraph{Update Bits:} $mask = ~(1<<i)$, use this to clear at first, $(num\\&mask) | (value<<i)$\n\n\n %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%      python implementation          %%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Applications} \n\\label{chapter_bit_section_bitwise}\n% \\paragraph{Code Implementation of Two's Complement} For One's complement we simply flip all bits. For Two's complement, we traverse all bits from Least significant bit (LSB) and we flip this bit: we flip all 1's until we find our first 0, and flip it to 1. And all the left digits just do the basic flip. \n% \\begin{lstlisting}[language=Python]\n% def twos_complement(val, bits):\n%     # first flip implemented with xor of val with all 1's\n%     flip_val = val^(2**bits-1)\n%     #flip_val = ~val we only give 3 bits\n%     return bin(flip_val+1)\n% print(twos_complement(5, 8))\n% # 0b11111011\n% \\end{lstlisting}\n\n% \\begin{lstlisting}[language=Python]\n% def twos_complement2(val, bits):\n%     zeroFound = False\n%     ans = 0\n%     mask = 1\n%     for i in range(bits):\n%         b = (val & (mask))!=0 # get ith bit\n%         b = not b # flipped \n%         if not zeroFound:\n%             if not b: # found zero, flip to one, else flip to zero: no operation needed\n%                 print('found')\n%                 ans = ans | (mask) # set ith bit\n%                 zeroFound = True\n%         else:\n%             if b:\n%                 ans = ans | (mask)\n%         mask = mask << 1  # change mask to the next bit\n%     return bin(ans)\n% print(twos_complement2(5, 8))\n% # output\n% # 0b11111011\n% \\end{lstlisting}\n\n\\paragraph{Recording States} Some algorithms like Combination, Permutation,  Graph Traversal require us to record states of the input array. Instead of using an array of the same size, we can use a single integer, each bit's location indicates the state of one element with same index in the array. For example, we want to record the state of an array with length 8. We can do it like follows: \n\\begin{lstlisting}[language=Python]\nused = 0\nfor i in range(8):\n    if used &(1<<i): # check state at i\n        continue\n    used = used | (1<<i)  # set state at i used\n    print(bin(used))\n\\end{lstlisting}\nIt has the following output\n\\begin{lstlisting}[numbers=none]\n0b1\n0b11\n0b111\n0b1111\n0b11111\n0b111111\n0b1111111\n0b11111111\n\\end{lstlisting}\n\n\\paragraph{XOR Single Number}\n\\begin{examples}[resume]\n\\item \\textbf{136. Single Number(easy).}  Given a non-empty array of integers, every element appears twice except for one. Find that single one. \\textit{Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?}\n\\begin{lstlisting}[numbers=none]\nExample 1:\n\nInput: [2,2,1]\nOutput: 1\n\nExample 2:\n\nInput: [4,1,2,1,2]\nOutput: 4\n\\end{lstlisting}\n\n\\textbf{Solution: XOR.} This one is kinda straightforward. You\u2019ll need to know the  properties of XOR as shown in Section~\\ref{sec_basic_bit_operator}.\n\\begin{lstlisting}\nn ^ n = 0\nn ^ 0 = n\n\\end{lstlisting}\nTherefore, we only need on variable to record the state which is initialize with 0: the first time to appear x = n, second time to appear x = 0. the last element x will be the single number. To set the statem we can use XOR.\n\\begin{lstlisting}[language = Python]\ndef singleNumber(self, nums):\n    \"\"\"\n    :type nums: List[int]\n    :rtype: int\n    \"\"\"\n    v = 0\n    for e in nums:\n        v = v ^ e\n    return v\n\\end{lstlisting}\n\\item \\textbf{137. Single Number II} Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. \\textit{Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?}\n\\begin{lstlisting}[language=Python]\nExample 1:\n\nInput: [2,2,3,2]\nOutput: 3\n\nExample 2:\n\nInput: [0,1,0,1,0,1,99]\nOutput: 99\n\\end{lstlisting}\n\n\\textbf{Solution: XOR and Two Variables.} In this problem, because all element but one appears three times. To record the states of three, we need at least two variables.  And we initialize it to a = 0, b = 0. For example, when 2 appears the first time, we set a = 2, b = 0; when it appears two times, a = 0, b = 2; when it appears three times, a = 0, b = 0. For number that appears one or two times will be saves either in a or in b. Same as the above example, we need to use XOR to change the state for each variable. We first do a = a XOR v, b = XOR v, we need to keep a unchanged and set b to zero. We can do this as a = a XOR v \\& $\\thicksim$  b; b = b XOR v \\& $\\thicksim$  a.\n\\begin{lstlisting}[language=Python]\ndef singleNumber(self, nums):\n    \"\"\"\n    :type nums: List[int]\n    :rtype: int\n    \"\"\"\n    a = b = 0\n    for num in nums:\n        a = a ^ num & ~b\n        b = b ^ num & ~a\n    return a|b\n\\end{lstlisting}\n\n\\item \\textbf{421. Maximum XOR of Two Numbers in an Array (medium).}  Given a non-empty array of numbers, $a_0, a_1, a_2,... , a_{n-1}$, where $0 \\leq a_i < 2^{31}$. Find the maximum result of $a_i$ XOR $a_j$, where $0 \\leq i, j < n$. Could you do this in $O(n)$ runtime?\n\\begin{lstlisting}[numbers=none]\nExample:\nInput: [3, 10, 5, 25, 2, 8]\n\nOutput: 28\nExplanation: The maximum result is 5 \\^ 25 = 28.\n\\end{lstlisting}\n\\textbf{Solution 1: Build the Max bit by bit.} First, let's convert these integers into binary representation by hand.\n\\begin{lstlisting}[numbers=none]\n3   0000, 0011\n10  0000, 1011\n5   0000, 0101\n25  0001, 1001\n2   0000, 0010\n8   0000, 1000\n\\end{lstlisting}\nIf we only look at the highest position i where there is one one and all others zero. Then we know the maximum XOR $m$ has 1 at that bit. Now, we look at two bits: i, i-1. The possible maximum XOR for this is append 0 or 1 at the end of $m$, we have possible max 11, because for XOR, if we do XOR of m with others,  $m XOR a = b$, if b exists in these possible two sets, then max is possible and it become  $m<<1+1$.  We can carry on this process,  the following process is showed as follows:\nanswer\\^ 1 is the possible max,\n\\begin{lstlisting}\ndef findMaximumXOR(self, nums):\n    \"\"\"\n    :type nums: List[int]\n    :rtype: int\n    \"\"\"\n    answer = 0\n    for i in range(32)[::-1]:\n        answer <<= 1 # multiple it by two\n        prefixes = {num >> i for num in nums} # shift right for n, divide/2^i, get the first (32-i) bits\n        answer += any((answer+1) ^ p in prefixes for p in prefixes)\n    return answer\n\\end{lstlisting}\n\n\\textbf{Solution 2: Use Trie.} \n\\begin{lstlisting}[language=Python]\ndef findMaximumXOR(self, nums):\n    def Trie(): \n        return collections.defaultdict(Trie)\n    \n    root = Trie()\n    best = 0\n    \n    for num in nums:\n        candidate = 0\n        cur = this = root\n        for i in range(32)[::-1]:\n            curBit = num >> i & 1\n            this = this[curBit]\n            if curBit ^ 1 in cur:\n                candidate += 1 << i\n                cur = cur[curBit ^ 1]\n            else:\n                cur = cur[curBit]\n        best = max(candidate, best)\n    return best\n\\end{lstlisting}\n\\end{examples}\n\\paragraph{With Mask}\n\\begin{examples}[resume]\n\\item \\textbf{190. Reverse Bits (Easy).}Reverse bits of a given 32 bits unsigned integer.\n\\begin{lstlisting}[numbers=none]\nExample 1:\n\nInput: 00000010100101000001111010011100\nOutput: 00111001011110000010100101000000\nExplanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000.\n\nExample 2:\n\nInput: 11111111111111111111111111111101\nOutput: 10111111111111111111111111111111\nExplanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is 10101111110010110010011101101001.\n\\end{lstlisting}\n\n\\textbf{Solution: Get Bit and Set bit with mask.} We first get bits from the most significant position to the least significant position. And get the bit at that position with mask, and set the bit in our 'ans' with a mask indicates the position of (31-i):\n\\begin{lstlisting}[language=Python]\n# @param n, an integer\n# @return an integer\ndef reverseBits(self, n):\n    ans = 0\n    for i in range(32)[::-1]: #from high to low\n        mask = 1 << i\n        set_mask = 1 << (31-i)\n        if (mask & n) != 0: #get bit\n            #set bit \n            ans |= set_mask\n    return ans\n\\end{lstlisting}\n\n\\item \\textbf{201. Bitwise AND of Numbers Range (medium).}Given a range [m, n] where $0 \\leq m \\leq n \\leq 2147483647$, return the bitwise AND of all numbers in this range, inclusive.\n\\begin{lstlisting}[numbers=none]\nExample 1:\n\nInput: [5,7]\nOutput: 4\n\nExample 2:\n\nInput: [0,1]\nOutput: 0\n\\end{lstlisting}\n\n\\textbf{Solution 1: O(n) do AND operation.} We start a 32 bit long 1s. The solution would receive LTE error. \n\\begin{lstlisting}[language=Python]\ndef rangeBitwiseAnd(self, m, n):\n    \"\"\"\n    :type m: int\n    :type n: int\n    :rtype: int\n    \"\"\"\n    ans = int('1'*32, 2)\n    for c in range(m, n+1):\n        ans &= c            \n    return ans\n\\end{lstlisting}\n\n\\textbf{Solution 2: Use mask, check bit by bit. } Think, if we AND all, the resulting integer would definitely smaller or equal to $m$. For example 1:\n\\begin{lstlisting}[numbers=none]\n0101 5\n0110 6\n0111 7\n\\end{lstlisting}\nWe start from the least significant bit at 5, if it is 1, then we check the closest number to 5 that has 0 at the this bit. It would be 0110. If this number is in the range, then this bit is offset to 0. We then move on to check the second bit. To make this closest number: first we clear the least i+1 positions in m to get 0100 and then we add it with $1 << (i+1)$ as 0010 to get 0110.\n\\begin{lstlisting}[language=Python]\ndef rangeBitwiseAnd(self, m, n):\n    ans = 0\n    mask = 1\n    for i in range(32): # [::-1]:\n        bit = mask & m != 0\n        if bit:\n            # clear i+1, ..., 0\n            mask_clear = (mask<<1)-1\n            left = m & (~mask_clear)\n            check_num = (mask << 1) + left\n            if check_num < m or check_num > n:\n                ans |= 1 << i\n        mask = mask << 1         \n    return ans\n                  \n\\end{lstlisting}\n\n\\textbf{Solution 3: Use While Loop.} We can start do AND of n with (n-1). If the resulting integer is still larger than m, then we keep do such AND operation.\n\\begin{lstlisting}[language=Python]\ndef rangeBitwiseAnd(self, m, n):\n    ans=n\n    while ans>m:\n        ans=ans&(ans-1)\n    return ans\n\\end{lstlisting}\n\\end{examples}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%Exerciese\n\\section{Exercises}\n\\begin{enumerate}\n\\item Write a function to determine the number of bits required to convert integer A to integer B.\n\\begin{lstlisting}[language = Python]\ndef bitswaprequired(a, b):\n  count = 0\n  c = a^b\n  while(c != 0):\n    count += c & 1\n    c = c >> 1\n  return count\nprint(bitswaprequired(12, 7))\n\\end{lstlisting}\n\n\\item \\textbf{389. Find the Difference (easy).} Given two strings $s$ and $t$ which consist of only lowercase letters. String $t$ is generated by random shuffling string s and then add one more letter at a random position. Find the letter that was added in $t$.\n\\begin{lstlisting}[numbers=none]\nExample:\nInput:\ns = \"abcd\"\nt = \"abcde\"\n\nOutput:\ne\nExplanation:\n'e' is the letter that was added.\n\\end{lstlisting}\n\\textbf{Solution 1: Use Counter Difference.} This way we need $O(M+N)$ space to save the result of counter for each letter. \n\\begin{lstlisting}[language=Python]\ndef findTheDifference(self, s, t):\n    s = collections.Counter(s)\n    t = collections.Counter(t)\n    diff = t - s\n    return list(diff.keys())[0]\n\\end{lstlisting}\n\\textbf{ Solution 2: Single Number with XOR.}  Using bit manipulation and with $O(1)$ we can find it in $O(M+N)$ time, which is the best BCR:\n\\begin{lstlisting}[language=Python]\ndef findTheDifference(self, s, t):\n    \"\"\"\n    :type s: str\n    :type t: str\n    :rtype: str\n    \"\"\"\n    v = 0\n    for c in s:\n        v = v ^ ord(c)\n    for c in t:\n        v = v ^ ord(c)\n    return chr(v)\n    \n\\end{lstlisting}\n\n\\item \\textbf{50. Pow(x, n) (medium).} for n, such as 10, we represent it as 1010, if we have a base and an result, we start from the least significant position, each time we move, the base because base*base, and if the value if 1, then we multiple the answer with the base. \n\n\n\n\n% Now consider a range\n\n% [m = 0bxyz0acd, n=0bxyz1rst]\n\n% here xyzpacdrst all are digits in base 2.\n\n% We can find two numbers that are special in the range [m, n]\n% \\begin{lstlisting}\n% (1) m' = 0bxyz0111\n% (2) n' = 0bxyz1000\n% \\end{lstlisting}\n\n% The bitwise AND of all the numbers in range [m, n] is just the bitwise AND of the two special number\n% \\begin{lstlisting}\n% rangeBitwiseAnd(m, n) = m' & n' = 0bxyz0000\n% \\end{lstlisting}\n\n% This tells us, the bitwise and of the range is keeping the common bits of m and n from left to right until the first bit that they are different, padding zeros for the rest.\n% \\begin{lstlisting}[language = Python]\n% def rangeBitwiseAnd(self, m, n):\n%         \"\"\"\n%         :type m: int\n%         :type n: int\n%         :rtype: int\n%         \"\"\"\n%         i = 0\n%         while m != n:\n%             m >>= 1\n%             n >>= 1 #find the common bits, i counts how many zeros we need\n%             i += 1\n%         return n << i # common bits then we shift i left\n% \\end{lstlisting}\n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "7720a5d1872fde2da5980bc0e921f8984c9bcd2c", "size": 25888, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/chapter_15_bit-manipulation.tex", "max_stars_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_stars_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Easy-Book/chapters/chapter_15_bit-manipulation.tex", "max_issues_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_issues_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Easy-Book/chapters/chapter_15_bit-manipulation.tex", "max_forks_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_forks_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7055214724, "max_line_length": 682, "alphanum_fraction": 0.6813581582, "num_tokens": 7776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642019, "lm_q2_score": 0.8887587898093889, "lm_q1q2_score": 0.8152607976037994}}
{"text": "\n\\section{Coordinate Transformations}\n\nTable \\ref{tablecoord} contains coordinate transformations between Cartesian, cylindrical, and spherical coordinates and vector fields, \\cite{ulaby1999fundamentals}. The routines in Table \\ref{tablecoord} overload the built-in Matlab functions of the same names in order to use $\\theta$, $\\phi$ orderings and definitions consistent with most scattering textbooks (physics convention, rather than mathematics convention which is what Matlab uses).  The same routines transform between either coordinate points or vector fields. For example, transforming Cartesians points $(x,y,z)$ to spherical coordinates $(r,\\theta,\\phi)$ is done as\n\\begin{verbatim}\n[r, th, phi] = cart2sph(x,y,z)\n\\end{verbatim}\n\nVector transformations always need the coordinates of the input vector field. For example, transforming a Cartesian vector field $(A_x,A_y,A_z)$ located at points $(x,y,z)$ to spherical vector components $(A_r,A_{\\theta},A_{\\phi})$ is done as\n\\begin{verbatim}\n[Ar, Ath, Aphi] = cart2sph(x,y,z,Ax,Ay,Az)\n\\end{verbatim}\n\nInput arrays can be any equal size and $\\tan^{-1}$ is always computed with \\texttt{atan2}. Unit vectors can be created by setting one of the input vector components equal to 1 and the others to 0.  For example, the Cartesian unit vectors at a point $(x,y,z)$ expressed in spherical coordinates are computed as\n\\begin{verbatim}\n[x_r, x_th, x_phi] = cart2sph(x,y,z,1,0,0) \n[y_r, y_th, y_phi] = cart2sph(x,y,z,0,1,0)  \n[z_r, z_th, z_phi] = cart2sph(x,y,z,0,0,1) \n\\end{verbatim}\n\n\\clearpage\n\\newpage\n\n\n\\bgroup\n\\def\\arraystretch{1.25}\n\\begin{table}[h]\n\\caption{Coordinate Transforms}\n\\begin{center}\n\\begin{tabular}{|c| l | l |}\n\\hline\n\\multicolumn{1}{|c|}{Routine} & \\multicolumn{1}{|c|}{Point Transforms} & \\multicolumn{1}{|c|}{Vector Field Transforms} \\\\\n\\hline\n\\texttt{cart2cyl} & \n\\threearray{\\rho}{\\sqrt{x^2 + y^2}}{\\phi}{\\tan^{-1}(y/x)}{z}{z}  & \n\\threearray{A_{\\rho}}{A_x \\cos\\phi + A_y\\sin\\phi}{A_{\\phi}}{-A_x\\sin\\phi + A_y\\cos\\phi}{A_z}{A_z}  \\\\\n\\hline\n\\texttt{cyl2cart} & \n\\threearray{x}{\\rho\\cos\\phi}{y}{\\rho\\sin\\phi}{z}{z} & \n\\threearray{A_x}{A_{\\rho}\\cos\\phi - A_{\\phi}\\sin\\phi}{A_y}{A_{\\rho}\\sin\\phi + A_{\\phi}\\cos\\phi}{A_z}{A_z} \\\\\n\\hline\n\\texttt{cart2sph} & \n\\threearray{r}{\\sqrt{x^2 + y^2 + z^2}}{\\theta}{\\tan^{-1}(\\sqrt{x^2+y^2}/z)}{\\phi}{\\tan^{-1}(y/x)} & \n\\threearray{A_r}{A_x \\st\\cos\\phi + A_y \\sin\\theta\\sin\\phi + A_z \\cos\\theta}{A_{\\theta}}{A_x \\ct\\cos\\phi + A_y \\cos\\theta\\sin\\phi - A_z \\sin\\theta}{A_{\\phi}}{-A_x\\sin\\phi + A_y\\cos\\phi}\\\\\n\\hline\n\\texttt{sph2cart} & \n\\threearray{x}{r\\st\\cos\\phi}{y}{r\\st\\sin\\phi}{z}{r\\ct} &\n\\threearray{A_x}{A_r \\st\\cos\\phi + A_{\\theta} \\ct\\cos\\phi - A_{\\phi} \\sin\\phi}{A_y}{A_r \\st\\sin\\phi + A_{\\theta} \\cos\\theta\\sin\\phi + A_{\\phi} \\cos\\phi}{A_z}{A_r\\ct - A_{\\theta}\\st} \\\\\n\\hline\n\\texttt{cyl2sph} & \n\\threearray{r}{\\sqrt{\\rho^2 + z^2}}{\\theta}{\\tan^{-1}(\\rho/z)}{\\phi}{\\phi} &\n\\threearray{A_r}{A_{\\rho} \\st + A_z\\ct}{A_{\\theta}}{A_{\\rho} \\ct - A_z\\st}{A_{\\phi}}{A_{\\phi}} \\\\\n\\hline\n\\texttt{sph2cyl} &\n\\threearray{\\rho}{r\\st}{\\phi}{\\phi}{z}{r\\ct} & \n\\threearray{A_{\\rho}}{A_r\\st + A_{\\theta}\\ct}{A_{\\phi}}{A_{\\phi}}{A_z}{A_r\\ct - A_{\\theta}\\st} \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\label{tablecoord}\n\\end{table}\n\\egroup\n\n\n\\paragraph{Routine \\texttt{cart2cyl} }\n{\\footnotesize\n\\VerbatimInput{\\code/CoordinateTransforms/cart2cyl.m}\n}\n\\clearpage\n\\newpage\n\\paragraph{Routine \\texttt{cyl2cart} }\n{\\footnotesize\n\\VerbatimInput{\\code/CoordinateTransforms/cyl2cart.m}\n}\n\\paragraph{Routine \\texttt{cart2sph} }\n{\\footnotesize\n\\VerbatimInput{\\code/CoordinateTransforms/cart2sph.m}\n}\n\\paragraph{Routine \\texttt{sph2cart} }\n{\\footnotesize\n\\VerbatimInput{\\code/CoordinateTransforms/sph2cart.m}\n}\n\\paragraph{Routine \\texttt{cyl2sph} }\n{\\footnotesize\n\\VerbatimInput{\\code/CoordinateTransforms/cyl2sph.m}\n}\n\\paragraph{Routine \\texttt{sph2cyl} }\n{\\footnotesize\n\\VerbatimInput{\\code/CoordinateTransforms/sph2cyl.m}\n}\n\\paragraph{Helper Routine \\texttt{checkargs} }\n{\\footnotesize\n\\VerbatimInput{\\code/CoordinateTransforms/checkargs.m}\n}\n", "meta": {"hexsha": "bdef66c9869d9d3eb000ffbed3c27b5dc549862c", "size": 4029, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/Utilities/CoordinateTransforms.tex", "max_stars_repo_name": "nasa-jpl/Waveport", "max_stars_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-08-29T13:29:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T20:09:47.000Z", "max_issues_repo_path": "Tex/Utilities/CoordinateTransforms.tex", "max_issues_repo_name": "ruzakb/Waveport", "max_issues_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tex/Utilities/CoordinateTransforms.tex", "max_forks_repo_name": "ruzakb/Waveport", "max_forks_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-08-29T13:28:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-08T19:58:04.000Z", "avg_line_length": 42.4105263158, "max_line_length": 634, "alphanum_fraction": 0.7048895508, "num_tokens": 1501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.8705972751232808, "lm_q1q2_score": 0.8151271731952161}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Alternating Series}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises relating to alternating series and absolute or conditional convergence.\n\\end{abstract}\n\\maketitle\n\n\n\\begin{exercise}\nFor the infinite series\n\\[ \\sum_{n=2}^\\infty \\frac{(-1)^n}{ \\ln n}, \\]\nthe function $1/\\ln n$ \\wordChoice{\\choice[correct]{is}\\choice{is not}} positive and \\wordChoice{\\choice[correct]{is}\\choice{is not}}  decreasing when $n \\geq 2$. Furthermore it \\wordChoice{\\choice[correct]{does}\\choice{does not}} tend to zero as $n \\rightarrow \\infty$. The alternating series test \\wordChoice{\\choice[correct]{does}\\choice{does not}} apply and \\wordChoice{\\choice[correct]{implies convergence}\\choice{implies divergence}\\choice{says nothing about the series}}.\n\\end{exercise}\n\n\\begin{exercise}\nFor the infinite series\n\\[ \\sum_{n=2}^\\infty \\frac{(-1)^n}{ \\ln n + (-1)^n \\sqrt{\\ln n}}, \\]\nthe function $1/(\\ln n+(-1)^n \\sqrt{\\ln n})$ \\wordChoice{\\choice[correct]{is}\\choice{is not}} positive and \\wordChoice{\\choice{is}\\choice[correct]{is not}} decreasing when $n \\geq 2$. Furthermore it \\wordChoice{\\choice[correct]{does}\\choice{does not}} tend to zero as $n \\rightarrow \\infty$. The alternating series test \\wordChoice{\\choice{does}\\choice[correct]{does not}} apply and \\wordChoice{\\choice{implies convergence}\\choice{implies divergence}\\choice[correct]{says nothing about the series}}.\n\\end{exercise}\n\n\\begin{exercise}\nFor the infinite series\n\\[ \\sum_{n=3}^\\infty \\frac{(-1)^n}{ \\ln n - (\\ln n)^{-1/2}}, \\]\nthe function $1/(\\ln n - (\\ln n)^{-1/2})$ \\wordChoice{\\choice[correct]{is}\\choice{is not}} positive and \\wordChoice{\\choice[correct]{is}\\choice{is not}} decreasing when $n \\geq 3$. Furthermore it \\wordChoice{\\choice[correct]{does}\\choice{does not}} tend to zero as $n \\rightarrow \\infty$. The alternating series test \\wordChoice{\\choice[correct]{does}\\choice{does not}} apply and \\wordChoice{\\choice[correct]{implies convergence}\\choice{implies divergence}\\choice{says nothing about the series}}.\n\\end{exercise}\n\n\n\\begin{exercise}\nFor the infinite series\n\\[ \\sum_{n=2}^\\infty \\frac{(-1)^n (n-1)^2}{n^2}, \\]\nthe function $1/(\\ln n+(-1)^n \\sqrt{\\ln n})$ \\wordChoice{\\choice[correct]{is}\\choice{is not}} positive and \\wordChoice{\\choice[correct]{is}\\choice{is not}} decreasing when $n \\geq 2$. Furthermore it \\wordChoice{\\choice{does}\\choice[correct]{does not}} tend to zero as $n \\rightarrow \\infty$. The alternating series test \\wordChoice{\\choice{does}\\choice[correct]{does not}} apply and \\wordChoice{\\choice{implies convergence}\\choice{implies divergence}\\choice[correct]{says nothing about the series}}.\n\\end{exercise}\n\n\\begin{exercise}\nFor the infinite series\n\\[ \\sum_{n=1}^\\infty \\frac{\\cos \\ln n}{ e^n}, \\]\nthe function $1/(e^n)$ \\wordChoice{\\choice[correct]{is}\\choice{is not}} positive and \\wordChoice{\\choice[correct]{is}\\choice{is not}} decreasing when $n \\geq 1$. Furthermore it \\wordChoice{\\choice[correct]{does}\\choice{does not}} tend to zero as $n \\rightarrow \\infty$. The alternating series test \\wordChoice{\\choice{does}\\choice[correct]{does not}} apply and \\wordChoice{\\choice{implies convergence}\\choice{implies divergence}\\choice[correct]{says nothing about the series}}.\n\\begin{hint}\nFirst determine whether the series is alternating.\n\\end{hint}\n\\end{exercise}\n\n\n\\begin{exercise}\nDoes the alternating series test apply to the series?\n\\[ \\sum_{n=5}^\\infty \\frac{\\cos n \\pi}{ \\sqrt{n}} \\]\n\\begin{multipleChoice}\n\\choice[correct]{Yes}\n\\choice{No, it's not alternating}\n\\choice{No, the terms are not decreasing}\n\\choice{No, the terms do not go to zero}\n\\end{multipleChoice}\nIf yes, for what minimum value of $N$ can you be certain that\n\\[ \\sum_{n=5}^{N-1} \\frac{\\cos n \\pi}{\\sqrt{n}} \\]\ndiffers from the sum of the series by at most $10^{-3}$? If no such $N$ exists, write N/A.\n\\[ N \\geq \\answer{10^{6}}. \\]\n\\begin{hint}\nIf the alternating series test applies, we would need the magnitude (i.e., absolute value) of the first term \\textit{not} included in the partial sum to be no greater than $10^{-3}$.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nFind an interval of length $\\frac{1}{4}$ which contains the sum of the infinite series\n\\[ \\sum_{n=1}^\\infty \\frac{(-1)^{n-1}}{n^2} \\]\n\\[ \\text{Interval }  = \\left[ \\answer{\\frac{3}{4}}, \\answer{1} \\right] \\]\n\\begin{hint}\nPartial sums of an alternating series also alternate above and below the sum of the series itself.\n\\end{hint}\n\\end{exercise}\n\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[seriesacd001]\n\nFor each series below, determine whether it converges absolutely (A), converges conditionally (C), or diverges (D). \\offline{Show how you used convergence tests to arrive at your answer.} \\[\\text{I: } \\sum_{n = 1}^\\infty\\frac{\\cos n \\pi}{\\sqrt[3]{n+3}} \\qquad \\text{II: } \\sum_{n = 1}^\\infty\\frac{(-1)^n}{n^2+3} \\qquad \\text{III: } \\sum_{n = 2}^\\infty\\frac{\\cos n \\pi}{\\ln (n^2 + 1)}\\]\n\\begin{multiplechoice}\n\\choice{I: C, II: D, III: D}\n\\choice[correct]{I: C, II: A, III: C}\n\\choice{I: A, II: C, III: A} \n\\choice{I: D, II: C, III: D}\n\\choice{I: C, II: D, III: C}\n\\choice{I: C, II: A, III: A}\n\\end{multiplechoice}\n\\begin{feedback}\nI: converges conditionally. The value of \\(\\cos n \\pi\\) alternates \\(\\pm 1\\). The terms \\((n+3)^{-1/3}\\) decrease to zero, so the series converges by the alternating series test. The series is not absolutely convergent because the \\(p\\)-series with \\(p = -1/3\\) is divergent.\n\nII: converges absolutely. The series converges absolutely by direct comparison to a \\(p\\)-series with \\(p=2\\).\n\nIII: converges conditionally. The series converges by the alternating series test because \\(1/\\ln (n^2+1)\\) decreases to \\(0\\) as \\(n \\rightarrow \\infty\\) and \\(\\cos n \\pi\\) alternates in value between \\(+1\\) and \\(-1\\). However, \\(1/\\ln (n^2+1) \\geq 1/n\\) for all large \\(n\\), so by direct comparison to the harmonic series, the series is not absolutely convergent. Therefore the convergence is conditional.\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[seriesacd004]\n\nFor each series below, determine whether it converges absolutely (A), converges conditionally (C), or diverges (D). \\offline{Show how you used convergence tests to arrive at your answer.} \\[\\text{I: } \\sum_{n = 1}^\\infty\\frac{(-1)^n n^2}{2 n^2+1} \\qquad \\text{II: } \\sum_{n = 1}^\\infty\\frac{1}{1 + n^3 e^{-n}} \\qquad \\text{III: } \\sum_{n = 1}^\\infty\\frac{(-1)^n n + 2}{n^2}\\]\n\\begin{multiplechoice}\n\\choice{I: D, II: D, III: D}\n\\choice{I: D, II: A, III: C}\n\\choice{I: C, II: C, III: A} \n\\choice{I: A, II: C, III: D}\n\\choice[correct]{I: D, II: D, III: C}\n\\choice{I: D, II: A, III: A}\n\\end{multiplechoice}\n\\begin{feedback}\nI: diverges. The series diverges because \\(n^2/(n^2+1) \\rightarrow 1\\), meaning that the terms do not go to zero. The \\(n\\)-th term divergence test implies divergence.\n\nII: diverges. The series diverges because \\(n / (n + n^3 e^{-n}) \\rightarrow 1\\) (because \\(n^3 e^{-n} \\rightarrow 0\\)). By the limit comparison theorem, this means the series has the same behavior as a \\(p\\)-series with \\(p=1\\), which means it diverges.\n\nIII: converges conditionally. The series converges because it is the sum of two convergent series: one with terms \\((-1)^n / n\\) (which is a convergent series by the alternating series test because \\(1/n\\) decreases to zero) and a second with terms \\(2/n^2\\) (which is a convergent \\(p\\)-series). However, the series is not absolutely convergent, because \\[ \\left| \\frac{(-1)^n n + 2}{n^2} \\right| = \\frac{n + (-1)^n2}{n^2}\\] for \\(n \\geq 2\\), which is a sum of a {\\it divergent} \\(p\\)-series with \\(p=1\\) and an absolutely convergent alternating \\(p\\)-series with \\(p=2\\). Thus the series is conditionally convergent.\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[2019AltSerError]\n\nWhich of the following intervals contains the value of the infinite series\n\\[ \\sum_{n=0}^\\infty \\frac{(-1)^n}{n+1}? \\]\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\left[ \\frac{1}{4}, \\frac{1}{3} \\right]\\)}\n\\choice{\\(\\displaystyle \\left[ \\frac{1}{3}, \\frac{1}{2} \\right]\\)}\n\\choice{\\(\\displaystyle \\left[ \\frac{1}{2}, \\frac{7}{12} \\right]\\)}\n\\choice[correct]{\\(\\displaystyle \\left[ \\frac{7}{12}, \\frac{5}{6} \\right]\\)}\n\\choice{\\(\\displaystyle \\left[ \\frac{5}{6}, \\frac{11}{12} \\right]\\)}\n\\choice{\\(\\displaystyle \\left[ \\frac{11}{12}, \\frac{7}{6} \\right]\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nThe function \\(1/(n+1)\\) is positive and decreases to zero, so by the Alternating Series Test, we know that partial sums alternate above and below the actual value of the sum.  In particular, if we call the value of the sum \\(L\\), then\n\\[\n\\begin{aligned}\n1 & \\geq  L \\\\\n1 - \\frac{1}{2} & \\leq  L \\\\\n1 - \\frac{1}{2} + \\frac{1}{3} & \\geq L \\\\\n1 - \\frac{1}{2} + \\frac{1}{3} - \\frac{1}{4} & \\leq L\n\\end{aligned}\n\\]\nand so on. The last two inequalities together imply that \\(L\\) belongs to the interval \\([\\frac{7}{12},\\frac{5}{6}]\\).\n\\end{feedback}\n\n\\end{question}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2017C.12]\n\nDetermine whether the following series converge absolutely (A), converge conditionally (C), or diverge (D). \\offline{For full credit be sure to explain your reasoning and specify which tests were used.}\n\\[ \\sum_{n=2}^\\infty \\frac{(-1)^n 2^{2n}}{3^n} \\ \\ \\ \\ \\sum_{n=2}^\\infty \\frac{(-1)^n}{\\sqrt{n}} \\]\n\\begin{multiplechoice}\n\\choice{both A}\n\\choice{one A, the other C}\n\\choice{one A, the other D} \n\\choice{both C}\n\\choice[correct]{one C, the other D}\n\\choice{both D}\n\\end{multiplechoice}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "2534fcca6c1da5fea85186945e87edc00e9ea46b", "size": 9539, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "series/23alternatepractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "series/23alternatepractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "series/23alternatepractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.4638554217, "max_line_length": 618, "alphanum_fraction": 0.6893804382, "num_tokens": 3077, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.912436161072216, "lm_q1q2_score": 0.8150878102932825}}
{"text": "\\paragraph{\\underline{Discrete}} \\hspace{0pt}\n\n\\vspace{10pt} \\noindent \\textbf{Bernoulli}\n$ X \\sim \\distbernoulli(p) $, $0 < p < 1$\n\n$p$: probability of success\n\\begin{gather*}\nP(X=1)=p \\\\ %\\mbox{ , }\nP(X=0)=1-p\n\\end{gather*}\n\n$ \\mathbb{E}X = p$, $\\var X = p(1-p) $\n\n\\vspace{10pt} \\noindent \\textbf{Binomial}\n$X \\sim \\distbinomial(n,p)$, $n \\in \\mathbb{N}_+$, $0 < p < 1$\n\n$n$: number of tests/trials ($\\distbinomial(1,p) \\equiv \\distbernoulli(p)$)\n\n$p$: probability of success\n\\begin{gather*}\nP(x=k) = \\binom{n}{k} p^k(1-p)^{n-k}\n\\end{gather*}\n\n$ \\mathbb{E}X = np$, $\\var X = np(1-p) $\n\n\\vspace{10pt} \\noindent \\textbf{Poison}\n$X \\sim \\distpoisson(\\lambda)$, $\\lambda > 0$\n\nIn some sense, it's a generalization of the Binomial distribution.\n\\begin{gather*}\nP(X=k) = \\frac{\\lambda^k}{k!}e^{-\\lambda} \\mbox{ , } k = 0,1,2,\\ldots\n\\end{gather*}\n\n$ \\mathbb{E}X = \\lambda$, $\\var X = \\lambda $\n\n\\vspace{10pt} \\noindent \\textbf{Geometric}\n$X \\sim \\distgeometric(p)$\n\\begin{gather*}\nP(X=k) = (1-p)^{k-1}p\n\\end{gather*}\n\nif $k=1,2,\\ldots$ then $\\mathbb{E}X = \\frac{1}{p}$, $\\var X = \\frac{1-p}{p^2}$\n\nif $k=0,1,2,\\ldots$ then $\\mathbb{E}X = \\frac{1-p}{p}$, $\\var X = \\frac{1-p}{p^2}$\n\n\\vspace{10pt} \\noindent \\textbf{Hypergeometric}\n$X \\sim \\disthypergeometric(N,M,n)$\n\\begin{gather*}\nP(X=k) \\frac{ \\binom{M}{k} \\binom{N-M}{n-k} }{ \\binom{N}{n} }\n\\end{gather*}\n\n$ \\max\\{ 0, M-N+n \\} \\leq  k \\leq \\min\\{ n, M \\} $\n\n\\vfill\n\\columnbreak\n\n\\paragraph{\\underline{Continuous}} \\hspace{0pt}\n\n\\vspace{10pt} \\noindent \\textbf{Uniform}\n$X \\sim \\distuniform[a,b]$, $a,b \\in R$, $a < b$\n\n$a$: lower limit\n\n$b$: upper limit\n\\begin{gather*}\nf(x) = \\begin{cases}\n\\frac{1}{b-a} \\mbox{ if } x \\in [a,b] \\\\\n0 \\mbox{ otherwise}\n\\end{cases} \n= \\frac{1}{b-a} I_{[a,b]}(x)\n\\end{gather*}\n\n$ \\mathbb{E}X = \\frac{a+b}{2}$, $\\var X = \\frac{(b-a)^2}{12} $\n\n\\vspace{10pt} \\noindent \\textbf{Normal}\n$X \\sim \\distnormal(\\mu, \\sigma)$\n\n$\\mu$: mean\n\n$\\sigma$: standard deviation\n\\begin{gather*}\nf(x) = \\frac{1}{\\sqrt{2\\pi} \\sigma} \\exp{ \\left\\{ - \\frac{(X-\\mu)^2}{2 \\sigma^2} \\right\\} }\n\\end{gather*}\n\n$ \\mathbb{E}X = \\mu$, $\\var X = \\sigma^2$\n\n\\vspace{10pt} \\noindent \\textbf{Exponential}\n$X \\sim \\distexponential(\\lambda)$, $\\lambda > 0$\n\ndecreasing \\eqref{eq:expdecreasing} and increasing \\eqref{eq:expincreasing}:\n\\begin{gather*}\nf(x) = \\lambda e^{-\\lambda x}\n\\label{eq:expdecreasing} \\tag{a}\n\\end{gather*}\n\n\\vspace{-30pt} \\begin{gather*}\nf(x) = 1 - e^{-\\lambda x}\n\\label{eq:expincreasing} \\tag{b}\n\\end{gather*}\n\n\\vspace{10pt} \\noindent \\textbf{Gamma}\n$X \\sim \\distgamma(\\alpha, \\beta)$, $\\alpha, \\beta > 0$\n\n\\nodata\n\n\\vspace{10pt} \\noindent \\textbf{Chi-square}\n$X \\sim \\distchisquare_n$\n\n$n$: number of degrees of freedom\n\n\\vspace{10pt} \\noindent \\textbf{Student's t-distribution}\n$X \\sim \\diststudentt^{[n]}$\n\n$n$: number of degrees of freedom\n\nAlso known as simply t-distribution.\n\n\\vspace{10pt} \\noindent \\textbf{F-distribution}\n$X \\sim \\distf^{[n]}$\n\n$n$: number of degrees of freedom\n\nAlso known as Fisher-Snedecor distribution.\n", "meta": {"hexsha": "03ad2665cbcb31618c1ed72733a7db13c105d777", "size": 2998, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_1_probability.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_1_probability.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_1_probability.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.1774193548, "max_line_length": 91, "alphanum_fraction": 0.622748499, "num_tokens": 1231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763574, "lm_q2_score": 0.868826771143471, "lm_q1q2_score": 0.815067258255879}}
{"text": "\n\\section{The \\accumulate algorithm}\n\\Label{sec:accumulate}\n\nThe \\accumulate algorithm in the \\cxx Standard Library \\cite[\\S 29.8.2]{cxx-17-draft} computes\nthe sum of an given initial value and the elements in a range.\n%\nOur version of the original signature\nreads:\n\n\\begin{lstlisting}[style=acsl-block]\n\n  value_type\n  accumulate(const value_type* a, size_type n, value_type init);\n\\end{lstlisting} \n\nThe result of \\accumulate shall equal the value\n$\\displaystyle{ \\mathtt{init} + \\sum_{i = 0}^{\\mathtt{n}-1} \\mathtt{a}[i] }$.\nThis implies that \\accumulate will return \\inl{init} for an empty range.\n\n%\\clearpage\n\n\\subsection{The logic function \\Accumulate}\n\nAs in the case of \\specref{counti}  we specify \\accumulate by first defining the\n\\emph{logic function} \\logicref{Accumulate} that formally defines\nthe summation of elements in an array.\n\n\\input{Listings/Accumulate.acsl.tex}\n\nWith this definition the following equation holds for $n \\geq 0$\n\\begin{align}\n\\Label{eq:accumulate}\n    \\mathtt{Accumulate}(\\mathtt{a}, \\mathtt{n}, \\mathtt{init})\n    &= \\mathtt{init} + \\sum_{i = 0}^{\\mathtt{n-1}} \\mathtt{a}[i]\n\\end{align}\n\nThe predicate \\logicref{AccumulateBounds} that we will subsequently use\nin order to compactly express requirements that exclude numeric\noverflows while accumulating value.\nThis predicate states that  for $0 \\leq i < n$ the \\emph{partial sums} \n%\n\\begin{gather}\n\\Label{eq:accumulate1}\n\\mathtt{init} + \\sum_{k = 0}^{\\mathtt{i}} \\mathtt{a}[k]\n\\end{gather}\n%\ndo not overflow.\nIf one of them did, one couldn't guarantee that the result of \\isoc implementation\nof \\accumulate equals the mathematical description of \\Accumulate.\n\n%\\clearpage\n\n\\subsection{\\AccumulateDefault ---a variant of \\Accumulate}\n\nThe following listing shows another version of \\logicref{Accumulate},\ncalled \\logicref{AccumulateDefault}.\n\n\\input{Listings/AccumulateDefault.acsl.tex}\n\nThe function \\AccumulateDefault uses~\\inl{a[0]} as default value of \\inl{init}.\nThus, for \\AccumulateDefault we have\n\n\\begin{align}\n\\Label{eq:accumulate-default}\n    \\mathtt{AccumulateDefault}(\\mathtt{a}, \\mathtt{n})\n    &= \\sum_{i = 0}^{\\mathtt{n-1}} \\mathtt{a}[i]\n\\end{align}\nWe will use this version for the specification of the algorithm \\specref{partialsum}.\n\nThis listing also includes additional properties of observable\n\\AccumulateDefault behavior, here given as a lemmas.\nIt also contains the predicate \\logicref{AccumulateDefaultBounds}\nwith corresponding numeric limits for the predicate~\\AccumulateDefault.\n\n%\\clearpage\n\n\\subsection{Formal specification of \\accumulate}\n\nUsing the logic function \\Accumulate and the predicate \\AccumulateBounds,\nthe specification of \\accumulate is then as simple\nas shown in the following listing.\n\n\\input{Listings/accumulate.h.tex}\n\n\\clearpage\n\n\\subsection{Implementation of \\accumulate}\n\nThe following listing shows an implementation of the\n\\accumulate function with corresponding loop annotations.\n\n\\input{Listings/accumulate.c.tex}\n\nNote that loop invariant \\inl{partial} claims that in the $i$-th iteration step \\inl{result}\nequals the accumulated value of Equation~\\eqref{eq:accumulate1}.\nThis depends on the property \\inl{bounds} of \\specref{accumulate} which expresses that\nthere is no numeric overflow when updating the variable \\inl{init}.\n\n\\clearpage\n", "meta": {"hexsha": "dfb5352116197b41375e292fae8ae07a7d8fdaf4", "size": 3284, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/numeric/accumulate.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/numeric/accumulate.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/numeric/accumulate.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 32.5148514851, "max_line_length": 94, "alphanum_fraction": 0.7679658952, "num_tokens": 906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218391455085, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.8150151289540062}}
{"text": "\\chapter{Regression}\nAlmost all of them have closed-form solutions.\n\\newpage\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%% Least Squares Regression %%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Least Squares Regression}\n%%%%%%%% Notation\n\\subsection{Notations}\n\\begin{itemize}\n    \\item $X$: $N \\times d$ matrix of data.\n    \\item $x^{(i)}$: $i$-th sample, $d$ dimensional feature vector, suppose $x_0 = 1$.\n    \\item $y$: $N$ dimensional output.\n    \\item  $w$: $d \\times 1$ parameter.\n\\end{itemize}\n%%%%%%%% Model\n\\subsection{Model}\n\\[ f(X;w) = Xw \\]\n\\begin{remark}\n    If $X$ is invertible, then we are done.\n    \\[ w = X^{-1}y \\]\n    Unfortunately $X$ is usually not invertible, it is usually not even a square matrix. So we need optimizaiton-based approach to solve this.\n\\end{remark}\n%%%%%%%% Loss Function\n\\subsection{Loss Function}\\label{section:LeastSquareLossFunc}\n\\[ J(w)  = \\frac{1}{2}\\| Xw - y \\|_2^2 = \\frac{1}{2}\\sum_{i=1}^N(w^Tx^{(i)} - y^{(i)})^2 \\]\nOur goal is to minimize the loss function\n\\[ \\min_w \\quad J(w) \\]\n%%%%%%%% Gradient Descent Update Rule\n\\subsection{Descent Method}\n$J(w)$ is convex, and can be optimized by gradient descent.\n\\[ \\nabla J(w) = X^T(Xw-y) \\]\n\\[ w_{i+1} = w_i - \\alpha \\nabla J(w) \\]\nwhere $\\alpha$ is the step size.\n%%%%%%%% Closed Form Solution\n\\subsection{Closed Form Solution}\n$J(w)$ is convex, and we can calculate the closed-form solution.\n\nLet $\\nabla J(w) = 0$.\n\\[ X^TXy = X^Ty \\]\n\\[ w = (X^TX)^{-1}X^Ty \\]\n\\begin{remark}\n    If $X^TX$ is not invertible, we can use its pseudo-inverse, which is defined as\n\\end{remark}\n\\begin{definition}[Pseudo-Inverse]\n    Let $A = U\\Sigma V^T$ be the SVD of matrix $A \\in \\mathbb{R}^{m\\times n}$, with $\\mathbf{Rank}(A) = r$. The pseudo-inverse of $A$ is defined as\n    \\[ A^{\\dagger} = V\\Sigma^{-1}U^T \\in \\mathbb{R}^{n\\times m} \\]\n\\end{definition}\n\\begin{remark}\n    Pseudo-Inverse does not necessarily give a good solution for lack of numerical stability.\n\\end{remark}\n%%%%%%%%\n\\subsection{Comparision}\n\\paragraph{Gradient Descent} is easy to implement and converges relatively fast.\n\\paragraph{Closed-form solution} is straightforward but may be numerically unstable.\n%%%%%%%% Geometric Interpretation\n\\subsection{Geometric Interpretation}\n\\[ \\hat{y} = Xw = X(X^TX)^{-1}X^Ty \\]\n\\begin{align*}\n    \\hat{y} - y &= X(X^TX)^{-1}X^Ty - y \\\\\n    &= (X(X^TX)^{-1}X^T - I)y\n\\end{align*}\nMultiplying $X^T$ on both sides yields\n\\begin{align*}\n    X^T(\\hat{y}-y) &= X^T(X(X^TX)^{-1}X^T - I)y \\\\\n    &= (X^TX(X^TX)^{-1}X^T - X^T)y \\\\\n    &= 0\n\\end{align*}\nThe error $\\hat{y} - y$ is perpendicular to the space spanned by samples $x^{(i)}$.\n%%%%%%%% Probability Interpretation\n\\subsection{Probability Interpretation}\\label{section:LeastSquareProbability}\nWe make the following assumptions\n\\begin{itemize}\n    \\item $y$ is linear with $x$ plus some random error $\\varepsilon^{(i)}$.\n    \\[ y^{(i)} = w^Tx^{(i)} + \\varepsilon \\]\n    \\item $\\varepsilon^{(i)}$ has a Gaussian distribution.\n    \\[ \\varepsilon^{(i)} \\sim \\mathcal{N}(0,1) \\]\n\\end{itemize}\nSubstitute $\\varepsilon$ with $w^Tx-y$, and the probaility density function is\n\\[ p(y^{(i)}|x^{(i)};w) = \\frac{1}{\\sqrt{2\\pi}}\\exp\\left(-\\frac{(w^Tx^{(i)}-y^{(i)})^2}{2}\\right) \\]\nWe maximize the (log) likelihood\n\\[ L(w) = \\prod_{i=1}^N \\frac{1}{\\sqrt{2\\pi}}\\exp\\left(-\\frac{\\|w^Tx^{(i)}-y^{(i)}\\|^2}{2}\\right) \\]\n\\[ l(w) = \\log L(w) = constant - \\sum_{i=1}^N \\frac{1}{2}\\|w^Tx^{(i)}-y^{(i)}\\|^2\\]\nMaximizing the log likelihood is equivalent to minimizing the last term. So the problem becomes\n\\[ \\min_{w} \\quad \\frac{1}{2}\\sum_{i=1}^N\\|w^Tx^{(i)} - y^{(i)}\\|^2 \\]\nThis is exactly the loss function in section \\ref{section:LeastSquareLossFunc}.\n%%%%%%%% Regularization\n\\subsection{Regularization}\n\\[ \\min_w \\| Xw - y \\|^2 + \\epsilon\\|w\\|^2 \\]\nwhere $\\epsilon$ is a small positive value, and the closed form solution can be derived from\n\\[ (X^TX + \\epsilon I)w = X^Ty \\]\nAdding $\\epsilon$ sometimes makes the inverse of matrix more stable.\n\\begin{remark}\n    Adds a contraint that the norm of $w$ cannot be too large. But regularization still does not guarantee a good solution when the matrix is not invertible.\n\n    Regularization is also a general way of preventing overfitting.\n\\end{remark}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%% Ridge Regression %%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Ridge Regression}\n%%%%%%%% Model\n\\subsection{Model}\n\\begin{align*}\n    \\min_w \\quad &\\| Xw - y \\|_2^2 \\\\\n    \\text{s.t.} \\quad &\\|w\\|_2^2 \\le t\n\\end{align*}\nIt can be rewritten in the form of Penalized Residual Sum of Squares, PRSS\n\\[ \\textrm{PRSS}(w) = \\|Xw-y\\|_2^2 + \\lambda\\|w\\|_2^2 \\]\n\n\\subsection{Solving Ridge Regression}\nRidge regression is also a convex optimization problem. It can be solved by using numerical methods or deriving closed form solutions.\n\\[ \\nabla\\textrm{PRSS}(w) = -2X^T(y-Xw) + 2\\lambda w \\]\nSo\n\\[ w = (X^TX + \\lambda I)^{-1}X^Ty \\]\n\\begin{remark}\n    Even if $X^TX$ is singular, by choosing a proper $\\lambda$ we can make $(X^TX + \\lambda I)$ nonsingular.\n\\end{remark}\n%%%%%%%% Regularization Revisited\n\\subsection{Regularization Revisited}\n$\\lambda$ is a regularization hyperparameter.\n\\begin{itemize}\n    \\item When $\\lambda = 0$, the penalty term has no effect and Ridge regression reduces to ordinary least squares.\n    \\item When $\\lambda \\to \\infty$, $w\\to 0 $.\n    \\item A proper $\\lambda$ can be chosen via cross-validation.\n\\end{itemize}\n%%%%%%%% Probability Interpretation\n\\subsection{Probability Interpretation}\nIn addtion to the assumptions made in Section \\ref{section:LeastSquareProbability}, if we further assume\n\\[ w \\sim \\mathcal{N}(0,\\sqrt{\\lambda}) \\]\nThen by Bayes's Rule\n\\[ p(w|y) = \\frac{p(y|w)\\cdot p(w)}{p(y)} \\]\nBy Maximum-A-Posteriori estimation\n\\[ \\hat{w} = \\arg \\max_w p(w|y) = \\arg \\max_w \\log p(y|w)\\cdot p(w) \\]\nThis yields the loss function of Ridge Regression.\n%%%%%%%% Geometric Interpretation\n\\subsection{Geometric Interpretation}\nThe feasible region of Ridge Regression is a $l_2$-norm ball (circle in 2D and sphere in 3D). We are looking for the smallest value of objective function in the norm ball.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%% LASSO Regression %%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{LASSO}\n\\emph{Least Absolute Shrinkage and Selection Operator}.\n%%%%%%%% Model\n\\subsection{Model}\n\\begin{align*}\n    \\min_w \\quad &\\| Xw - y \\|_2^2 \\\\\n    \\text{s.t.} \\quad &\\|w\\|_1 \\le t\n\\end{align*}\nThe optimization problem can be reformulated as\n\\[ \\min_w \\quad \\| Xw - y \\|_2^2 + \\lambda \\|w\\|_1 \\]\n%%%%%%%% Solving LASSO\n\\subsection{Solving LASSO}\nLASSO can be solved, but solving it is nontrivial. There are a number of algorithms to solve LASSO.\n\\paragraph{Quasi-Gradient Method.}\nLet\n\\[\n\\nabla |w|_1 =\n\\begin{cases}\n1 \\quad &w > 0\\\\\n-1 \\quad &w < 0\\\\\n0 \\quad &w = 0\n\\end{cases}\n\\]\n\\paragraph{A Simple Method.}\nDefine error $r$ by\n$$ r = y - Xw = y - \\sum_{i=1}^D x_iw_i $$\n\\begin{enumerate}\n    \\item Initialize $r = y$; $w_1 = w_2 = \\dots = w_d = 0$.\n    \\item Find an $x_j$ that correlates with $r$.\n    \\item Update $w_j = w_j +\\delta_j$, where $\\delta_j = \\varepsilon\\cdot\\mathrm{sgn}\\langle r, X_j \\rangle$.\n    \\item Update $r = r-\\delta\\cdot x_j$.\n    \\item Repeat step 2-4 until convergence\n\\end{enumerate}\n\\paragraph{Soft Threshold Method.}\nUse Taylor expansion.\n%%%%%%%% Probabilistic Interpretation\n\\subsection{Probabilistic Interpretation}\nIn addition to the assumptions made in \\ref{section:LeastSquareProbability}, we further assume that $w$ has a Gamma distribution.\n\nThe minimizing $w$ is the MAP estimator.\n%%%%%%%% Geometric Interpretation\n\\subsection{Geometric Interpretation}\nThe feasible region of LASSO is a $l_1$-norm ball (diamond in 2D). We look for the smallest value in the diamond-shaped region.", "meta": {"hexsha": "6103e29fe0bfb50701b9459921961a7fbe3a89c5", "size": 7772, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Machine Learning/Regression.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Machine Learning/Regression.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Machine Learning/Regression.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 41.7849462366, "max_line_length": 171, "alphanum_fraction": 0.6429490479, "num_tokens": 2499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.8840392817460333, "lm_q1q2_score": 0.8150151148147753}}
{"text": "\\section{Space Curves}\\label{sec:SpaceCurves}\n\nWe have already seen that a convenient way to describe a line in three\ndimensions is to provide a vector that ``points to'' every point on\nthe line as a parameter $t$ varies, like\n$$\\langle 1,2,3\\rangle+t\\langle 1,-2,2\\rangle\n=\\langle 1+t,2-2t,3+2t\\rangle.$$\nExcept that this gives a particularly simple geometric object, there\nis nothing special about the individual functions of $t$ that make up\nthe coordinates of this vector---any vector with a parameter, like\n$\\langle f(t),g(t),h(t)\\rangle$, will describe some curve in three\ndimensions as $t$ varies through all possible values. \n\n\\begin{example}{Decribing Curves}{helixes}\nDescribe the curves\n$\\langle \\cos t,\\sin t,0\\rangle$,\n$\\langle \\cos t,\\sin t,t\\rangle$, and\n$\\langle \\cos t,\\sin t,2t\\rangle$.\n\\end{example}\n\\begin{solution}\nAs $t$ varies, the first two coordinates in all three functions\ntrace out the points on the unit circle, starting\nwith $(1,0)$ when $t=0$ and proceeding counter-clockwise around the\ncircle as $t$ increases. In the first case, the $z$ coordinate is\nalways 0, so this describes precisely the unit circle in the $x$-$y$\nplane. In the second case, the $x$ and $y$ coordinates still describe\na circle, but now \nthe $z$ coordinate varies, so that the\nheight of the curve matches the value of $t$. When $t=\\pi$, for\nexample, the resulting vector is $\\langle -1,0,\\pi\\rangle$. A bit of\nthought should convince you that the result is a helix. In the third\nvector, the $z$ coordinate varies twice as fast as the parameter $t$,\nso we get a stretched out helix. Both are shown in\nFigure~\\ref{fig:helixes}. On the left is the first helix, shown for\n$t$ between 0 and $4\\pi$; on the right is the second helix, shown for\n$t$ between 0 and $2\\pi$. Both start and end at the same point, but\nthe first helix takes two full ``turns'' to get there, because its $z$\ncoordinate grows more slowly.\n\\end{solution}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/helix1.eps}}} at 0 0\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/helix2.eps}}} at 2 0\n\\endpicture}}\n\\caption{Two helixes. \\label{fig:helixes}}\n\\end{figure}\n\nA vector expression of the form $\\langle f(t),g(t),h(t)\\rangle$ is called\na \\dfont{vector function}; it is a function from\nthe real numbers $\\R$ to the set of all three-dimensional vectors.\nWe can alternately think of it as three separate functions, \n$x=f(t)$, $y=g(t)$, and $z=h(t)$, that describe points in space. In\nthis case we usually refer to the set of equations as\n\\dfont{parametric equations} for the curve, just\nas for a line. While the parameter $t$ in a vector function might\nrepresent any one of a number of physical quantities, or be simply a\n``pure number'', it is often convenient and useful to think of $t$ as\nrepresenting time. The vector function then tells you where in space\na particular object is at any time.\n\nVector functions can be difficult to understand, that is, difficult to\npicture. When available, computer software can be very helpful. When\nworking by hand, one useful approach is to consider the\n``projections'' of the curve onto the three standard coordinate\nplanes. We have already done this in part: in\nExample~\\ref{exa:helixes} we noted that all three curves project to\na circle in the $x$-$y$ plane, since $\\langle \\cos t,\\sin t\\rangle$ is\na two dimensional vector function for the unit circle.\n\n\\begin{example}{Projections onto a Plane}{projectionsontoplaneexample}\nGraph the projections of $\\langle \\cos t,\\sin\nt,2t\\rangle$ onto the $x$-$z$ plane and the $y$-$z$ plane.\n\\end{example}\n\\begin{solution}\nThe two dimensional vector function for the\nprojection onto the $x$-$z$ plane is $\\langle \\cos t, 2t\\rangle$, or in\nparametric form, $x=\\cos t$, $z=2t$. By eliminating $t$ we get the\nequation $x=\\cos(z/2)$, the familiar curve shown on the left in\nFigure~\\ref{fig:helix projections}. For the projection onto the $y$-$z$ plane, we start\nwith the vector function $\\langle \\sin t, 2t\\rangle$, which is the\nsame as $y=\\sin t$, $z=2t$. Eliminating $t$ gives $y=\\sin(z/2)$, as\nshown on the right in Figure~\\ref{fig:helix projections}.\n\\end{solution}\n\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <15truemm,4truemm>\n\\setplotarea x from -1.25 to 1.25, y from 0 to 14\n\\axis left shiftedto x=0 ticks length <2pt> withvalues {$2\\pi$} {$4\\pi$} /\n  at 6.28 12.57 / /\n\\axis bottom ticks length <2pt> numbered from -1 to 1 by 1 /\n\\arrow <4pt> [0.35, 1] from 0 14 to 0 14.05\n\\arrow <4pt> [0.35, 1] from 1.25 0 to 1.3 0\n\\put {$x$} [tl] <3pt,0pt> at 1.3 0 \n\\put {$z$} [br] <0pt,3pt> at 0 14.05 \n\\plot \n1.000 0.000 0.995 0.209 0.978 0.419 0.951 0.628 0.914 0.838 0.866\n1.047 0.809 1.257 0.743 1.466 0.669 1.676 0.588 1.885 0.500 2.094\n0.407 2.304 0.309 2.513 0.208 2.723 0.105 2.932 0.000 3.142 -0.105\n3.351 -0.208 3.560 -0.309 3.770 -0.407 3.979 -0.500 4.189 -0.588 4.398\n-0.669 4.608 -0.743 4.817 -0.809 5.027 -0.866 5.236 -0.914 5.445\n-0.951 5.655 -0.978 5.864 -0.995 6.074 -1.000 6.283 -0.995 6.493\n-0.978 6.702 -0.951 6.912 -0.914 7.121 -0.866 7.330 -0.809 7.540\n-0.743 7.749 -0.669 7.959 -0.588 8.168 -0.500 8.378 -0.407 8.587\n-0.309 8.796 -0.208 9.006 -0.105 9.215 0.000 9.425 0.105 9.634 0.208\n9.844 0.309 10.053 0.407 10.263 0.500 10.472 0.588 10.681 0.669 10.891\n0.743 11.100 0.809 11.310 0.866 11.519 0.914 11.729 0.951 11.938 0.978\n12.147 0.995 12.357 1.000 12.566 /\n\\setcoordinatesystem units <15truemm,4truemm> point at -4 0\n\\setplotarea x from -1.25 to 1.25, y from 0 to 14\n\\axis left shiftedto x=0 ticks length <2pt>  withvalues {$2\\pi$} {$4\\pi$} /\n  at 6.28 12.57 / /\n\\axis bottom ticks length <2pt> numbered from -1 to 1 by 1 /\n\\arrow <4pt> [0.35, 1] from 0 14 to 0 14.05\n\\arrow <4pt> [0.35, 1] from 1.25 0 to 1.3 0\n\\put {$y$} [tl] <3pt,0pt> at 1.3 0 \n\\put {$z$} [br] <0pt,3pt> at 0 14.05 \n\\plot 0.000 0.000 0.105 0.209 0.208 0.419 0.309 0.628 0.407 0.838 0.500\n 1.047 0.588 1.257 0.669 1.466 0.743 1.676 0.809 1.885 0.866 2.094\n 0.914 2.304 0.951 2.513 0.978 2.723 0.995 2.932 1.000 3.142 0.995\n 3.351 0.978 3.560 0.951 3.770 0.914 3.979 0.866 4.189 0.809 4.398\n 0.743 4.608 0.669 4.817 0.588 5.027 0.500 5.236 0.407 5.445 0.309\n 5.655 0.208 5.864 0.105 6.074 0.000 6.283 -0.105 6.493 -0.208 6.702\n -0.309 6.912 -0.407 7.121 -0.500 7.330 -0.588 7.540 -0.669 7.749\n -0.743 7.959 -0.809 8.168 -0.866 8.378 -0.914 8.587 -0.951 8.796\n -0.978 9.006 -0.995 9.215 -1.000 9.425 -0.995 9.634 -0.978 9.844\n -0.951 10.053 -0.914 10.263 -0.866 10.472 -0.809 10.681 -0.743 10.891\n -0.669 11.100 -0.588 11.310 -0.500 11.519 -0.407 11.729 -0.309 11.938\n -0.208 12.147 -0.105 12.357 0.000 12.566 /\n\\endpicture}}\n\\caption{The projections of $\\langle \\cos t,\\sin\nt,2t\\rangle$ onto the $x$-$z$ and $y$-$z$ planes. \\label{fig:helix projections}}\n\\end{figure}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:SpaceCurves}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nInvestigate the curve ${\\bf r}=\\langle \\sin t,\\cos t,\\cos\n8t\\rangle$.\n\\end{ex}\n\n\\begin{ex}\nInvestigate the curve \n${\\bf r}=\\langle t\\cos t,t\\sin t,t\\rangle$.\n\\end{ex}\n\n\\begin{ex}\nInvestigate the curve \n${\\bf r}=\\langle t,t^2,\\cos t\\rangle$.\n\\end{ex}\n\n\\begin{ex}\nInvestigate the curve \n${\\bf r}=\\langle \\cos(20t)\\sqrt{1-t^2},\\sin(20t)\\sqrt{1-t^2},t\\rangle$\n\\end{ex}\n\n\\begin{ex}\nFind a vector function for the curve of intersection of\n$x^2+y^2=9$ and $y+z=2$.\n\\begin{sol}\n\t$\\langle 3\\cos t, 3\\sin t, 2-3\\sin t\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA bug is crawling outward along the spoke of a wheel that lies along\na radius of the wheel. The bug is crawling at 1 unit per second and\nthe wheel is rotating at 1 radian per second. Suppose the wheel lies\nin the $y$-$z$ plane with center at the origin, and at time $t=0$ the\nspoke lies along the positive $y$ axis and the bug is at the origin.\nFind a vector function ${\\bf r}(t)$\nfor the position of the bug at time $t$.\n\\begin{sol}\n\t$\\langle 0,t\\cos t,t\\sin t\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nWhat is the difference between the parametric curves\n$f(t)=\\langle t, t, t^2 \\rangle$, $g(t)=\\langle t^2, t^2, t^4\n\\rangle$, and $h(t)=\\langle \\sin(t), \\sin(t), \\sin^2(t) \\rangle$as $t$\nruns over all real numbers?\n\\end{ex}\n\n\\begin{ex}\nPlot each of the curves below in 2 dimensions, projected\nonto each of the three standard planes (the $x$-$y$, $x$-$z$, and\n$y$-$z$ planes).\n\\begin{enumerate}\n\t\\item\t$f(t)=\\langle t, t^3, t^2 \\rangle$, $t$ ranges over all real numbers\n\t\\item\t$f(t)=\\langle t^2, t-1, t^2+5 \\rangle$  for $0\\leq t \\leq 3$\n\\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\nGiven points $A=(a_1, a_2, a_3)$ and $B=(b_1, b_2, b_3)$, give\nparametric equations for the line {\\em segment} connecting $A$ and\n$B$. Be sure to give appropriate $t$ values.\n\\end{ex}\n\n\\begin{ex}\nWith a parametric plot and a set of $t$ values, we can associate\na `direction'.  For example, the curve $\\langle \\cos t, \\sin t\n\\rangle$ is the unit circle traced counterclockwise.  How can we amend\na set of given parametric equations and $t$ values to get the same\ncurve, only traced backwards?\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "311312d2dd227545f0fedc61336502e3487798ce", "size": 9224, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13-vector-functions/13-1-space-curves.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "13-vector-functions/13-1-space-curves.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "13-vector-functions/13-1-space-curves.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.5495495495, "max_line_length": 87, "alphanum_fraction": 0.6969861232, "num_tokens": 3553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.9219218268104371, "lm_q1q2_score": 0.8150151011496605}}
{"text": "\\subsection{Basic Topology}\n\\begin{defn}\nA topological space is a set $X$ together with a collection $\\tau$\nof subsets called \\emph{open sets }such that\\end{defn}\n\\begin{itemize}\n\\item $\\emptyset$ and $X$ are open\n\\item Every union of open sets is open\n\\item Every finite intersection of open sets is open\n\\end{itemize}\n$\\tau$ is called a \\emph{topology} on $X$. Closed sets in $X$ are\ncomplements of open sets.\n\\begin{defn}\nLet $X$ and $Y$ be topologial spaces and $f:X\\to Y$ a function.\nThen $f$ is continuous if $f^{-1}(U)=\\{x\\in X\\mid f(x)\\in U\\}$ is\nopen in $X$ if $U$ is open in $Y$.\n\\end{defn}\n\n\\begin{defn}\nIf $X$ is a topological space and $A\\subseteq X$, then the \\emph{subspace\ntopology} on $A$ are the sets $U\\cap A$ where $U$ open in $X$.\n\\end{defn}\n\n\\begin{defn}\nIf $X,Y$ are topological spaces, then $X\\times Y=\\{(x,y)\\mid x\\in X,y\\in Y\\}$\nhas a \\emph{product toplogy}, where open sets in $X\\times Y$ are\nunions of products $U\\times V$ where $U$ open in $X$, $V$ open\nin $Y$.\n\\end{defn}\n\n\\begin{defn}\nA \\emph{homeomorphism} between topological spaces $X$ and $Y$ is\na continuos bijection $f:X\\to Y$ whose inverse is also continuous.\n\nIf such an $f$ exists we say that $X$ and $Y$ are \\emph{homeomorphic:\n$X\\approx Y$.}\n\\end{defn}\n\n\\begin{defn}\nA topological space $X$ is \\emph{connected} if it is \\emph{not} the\ndisjoint union of two open subsets, i.e.\n\n\\begin{align*}\nX & =A\\sqcup B\n\\end{align*}\n\n\nwith $A,B$ open implies that either $A=\\emptyset$ or $B=\\emptyset$.\n\nEquivalently, a space $X$ is connected if the only subsets of $X$\nthat are both open and closed are $X$ and $\\emptyset$.\\end{defn}\n\\begin{thm}\nIf $f:X\\to Y$ is continuous and $X$ is connected then $f(X)$ is\nconnected.\n\\end{thm}\n\n\\begin{thm}\nIf $\\{Y_{i}\\}_{i}$ are connected sets in a topological space $X$,\nand $Y_{i}\\cap Y_{j}\\neq\\emptyset$ for all $i,j$ then $\\bigcup_{i}Y_{i}$\nis connected.\n\nNote: Any homeomorphism $f:X\\to Y$ takes cut points of $X$ to cut\npoints of $Y$.\n\\end{thm}\n\n\\begin{defn}\nA path in $X$ is a continuous map $\\alpha:I\\to X$. We say that $\\alpha$\njoins $\\alpha(0)$ to $\\alpha(1)$.\n\\end{defn}\n\n\\begin{defn}\nA topological space $X$ is called \\emph{Hausdorff} if given any two\nppoints $x,y\\in X$ with $x\\neq y$, then there exists disjoint open\nsets $U$ and $V$ with $x\\in U$, $y\\in V$.\n\\end{defn}\n\n\\begin{defn}\nAn $n$-dimensional manifold is a Hausdorff topological space which\nis locally homeomorphic to $\\mathbb{R}^{n}$.\n\\end{defn}\n\n\\begin{defn}\nAn \\emph{open cover} of a topological space $X$ is a colelction of\nopen sets whose union is $X$. A \\emph{subcover} is a subset of this\ncollection which still covers $X$.\n\nA topological space $X$ is called \\emph{compact }if every open cover\nhas a finite subcover. $A\\subset X$ is compact if it is compact in\nthe subspace topology.\\end{defn}\n\\begin{thm}\n~\\end{thm}\n\\begin{itemize}\n\\item If $f:X\\to Y$ is continuous and $X$ is compact, then $f(X)$ is\ncompact.\n\\item If $X$ compact, $A\\subset X$ is closed, then $A$ is compact.\\end{itemize}\n\\begin{thm}\n(Heine-Borel) A subspace of $\\mathbb{R}^{n}$ is compact iff it is\nclosed and bounded.\n\\end{thm}\n\n\\begin{thm}\nProducts of compact spaces are compact.\n\\end{thm}\n\n\nNote: Compactness is a topological invariant.\n\n\n\\begin{thm}\nIf $X$ is a Hausdorff topological space, then every compact subset\n$A$ is closed.\n\\end{thm}\n\n\\begin{thm}\nIf $f:X\\to Y$ continuous, $X$ compact, $Y$ Hausdorff, then\\end{thm}\n\\begin{itemize}\n\\item $f$ is a closed map.\n\\item If $f$ is a bijection, then $f$ is a homeomorphism.\n\\end{itemize}\n", "meta": {"hexsha": "3999e6504cfd929ebcdd1ccc260a8d1322da568f", "size": 3511, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "basic_topology.tex", "max_stars_repo_name": "silky/alg-top-notes", "max_stars_repo_head_hexsha": "2e47a522a31a93487df6ab523ed555aaa2ca017c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-11-17T08:28:55.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-17T08:28:55.000Z", "max_issues_repo_path": "basic_topology.tex", "max_issues_repo_name": "silky/alg-top-notes", "max_issues_repo_head_hexsha": "2e47a522a31a93487df6ab523ed555aaa2ca017c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "basic_topology.tex", "max_forks_repo_name": "silky/alg-top-notes", "max_forks_repo_head_hexsha": "2e47a522a31a93487df6ab523ed555aaa2ca017c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5042016807, "max_line_length": 79, "alphanum_fraction": 0.6929649672, "num_tokens": 1263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.9019206745523101, "lm_q1q2_score": 0.8146997296216002}}
{"text": "\\chapter{Linear Regression}\n\n\n\\section{Introduction}\nLinear regression is the \u201cwork horse\u201d of statistics and (supervised) machine learning. When augmented with kernels or other forms of basis function expansion, it can model also nonlinear relationships. And when the Gaussian output is replaced with a Bernoulli or multinoulli distribution, it can be used for classification, as we will see below. So it pays to study this model in detail.\n\nIn the simplest approach,we can directly construct an appropriate function $y(\\vec{x})$ whose values for new inputs $\\vec{x}$ constitute the predictions for the corresponding values of $t$.More generally,from a probabilistic perspective,we aim to model the predictive distribution $p(t|x)$ because this expresses the uncertainty about the value of $t$ for each value of $x$.\n\n\\section{Representation}\nThe simplest linear model for regression is \\textbf{linear regression} that involves a linear combination of the input variables\n\\begin{equation}\ny(\\vec{x},\\vec{w}) = w_0+w_1x_1+...+w_Dx_D\n\\end{equation}\nwhere $\\vec{x}=(x_1,...,x_D)^T$.\n\nLinear regression can be made to model non-linear relationships by replacing $\\vec{x}$ with some non-linear function of the inputs, $\\phi(\\vec{x})$.Consider the linear combinations of fixed nonlinear functions of the input variables,of the form\n\\begin{equation}\ny(\\vec{x},\\vec{w}) = w_0+\\sum_{j=1}^{M-1}w_j\\phi_j(x) \n=\\sum_{j=0}^{M-1}w_j\\phi_j(x) = \\vec{w}^T\\phi(x)\n\\end{equation}\nwhere $\\phi_j(x)$ are known as \\textbf{basis functions},\n$\\vec{w}=(w_0,...,w_{M-1})^T$ and $\\phi=(\\phi_0,...,\\phi_{M-1})^T$.\nThis is known as \\textbf{basis function expansion}. (Note that the model is still linear in the parameters $\\vec{w}$, so it is still called linear regression; the importance of this will become clear below.) A simple example are polynomial basis functions, where the model has the form\n\\begin{equation}\n\\phi(x)=(1, x, \\cdots, x^d)\n\\end{equation}\n\n\nAs before,we assume that the target variable is given by a deterministic function $y(\\vec{x},\\vec{w})$ with additive Gaussian noise so that\n\\begin{equation}\nt=y(\\vec{x},\\vec{w})+\\epsilon\n\\end{equation}\nwhere $\\epsilon$ is a zero mean Gaussian random variable with precision(inverse variance) $\\beta$.Thus\n\\begin{equation}\\label{eqn:linear regression representation}\np(t|\\vec{x},\\vec{w},\\beta)=\\mathcal{N}(t|h(\\vec{x},\\vec{w}),\\beta^{-1})\n\\end{equation}\nor \n\\begin{eqnarray}\n& y(\\vec{x}) = \\vec{w}^T\\vec{x}+\\epsilon \\\\\n& p(y|\\vec{x},\\vec{\\theta})=\\mathcal{N}(y|\\vec{w}^T\\vec{x}, \\sigma^2) \\\\\n\\end{eqnarray}\nwhere $\\vec{w}$ (\\textbf{weight vector}) and $\\vec{x}$ are extended vectors, $\\vec{x}=(1,x)$, $\\vec{w}=(b,w)$ and $\\epsilon$ has a \\textbf{Gaussian} or \\textbf{normal} distribution.$w_0$ is the intercept or \\textbf{text}\n\n \n%\\begin{eqnarray}\n%& y(\\vec{x}) = \\vec{w}^T\\phi(\\vec{x})+\\epsilon \\\\\n%& p(y|\\vec{x},\\vec{\\theta})=\\mathcal{N}(y|\\vec{w}^T\\phi(\\vec{x}), \\sigma^2)\n%\\end{eqnarray}\n\n\n\\section{Maximum likelihood estimations(least squares)}\nAssume the training examples are \\textbf{independently and identically distributed(IID)},we obtain the \\textbf{likelihood function},which is a function of adjustable parameters $\\vec{w}$ and $\\beta$,in the form\n\\begin{align}\\label{eqn:linear regression likelihood}\np(\\vec{t}|\\vec{X},\\vec{w},\\beta) =\n\\prod_{n=1}^{N}\\mathcal{N}(t_n|\\vec{w}^T\\phi(\\vec{x_n}),\\beta^{-1})\n\\end{align}\nwe can write the \\textbf{log-likelihood} (logarithm of the likelihood) function as follows:\n\\begin{equation}\n\\ell(\\vec{\\theta}) \\triangleq \\log p(\\mathcal{D}|\\vec{\\theta})\n\\end{equation}\nA common way to estimate the parameters of a statistical model is to compute the MLE(Maximum likelihood estimations),which is defined as\n\\begin{equation}\n\\vec{\\hat{\\theta}}=\\arg\\max_\\theta{\\log p(\\mathcal{D}|\\vec{\\theta})}\n\\end{equation}\n\nInstead of maximizing the log-likelihood, we can equivalently minimize the \\textbf{negative log likelihood} or \\textbf{NLL}:\n\\begin{equation}\n\\text{NLL}(\\vec{\\theta}) \\triangleq -\\ell(\\vec{\\theta})=-\\log p(\\mathcal{D}|\\vec{\\theta})\n\\end{equation}\n\nThe NLL formulation is sometimes more convenient, since many optimization software packages are designed to find the minima of functions, rather than maxima.\n\nNow let us apply the method of MLE to the linear regression setting. Inserting the definition of the Gaussian into the above, we find that the log likelihood is given by\n\\begin{align}\n\\ell(\\vec{\\theta}) &= \\log p(\\vec{T}|\\vec{w},\\beta) \\\\\n&=\\sum_{n=1}^{N}\\log \\mathcal{N}(t_n|\\vec{w}^T\\phi(\\vec{x_n}),\\beta^{-1}) \\\\\n&=\\sum\\limits_{i=1}^N \\log\\left[\\dfrac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(-\\dfrac{1}{2\\sigma^2}(y_i-\\vec{w}^T\\vec{x}_i)^2\\right)\\right] \\\\\n&=\\dfrac{N}{2}\\log \\beta-\\dfrac{N}{2}\\log (2\\pi)-\\beta E_D(\\vec{w}) \\\\\n%&=-\\dfrac{1}{2\\sigma^2}\\text{RSS}(\\vec{w})-\\dfrac{\\vec{w}}{2}\\log(2\\pi\\sigma^2)\n\\end{align}\nwhere the sum-of-squares error function is defined by\n\\begin{equation}\nE_D(\\vec{w}) =\n\\dfrac{1}{2}\\sum_{n=1}^{N}\\{t_n-\\vec{w}^T\\phi(\\vec{x_n}) \\}^2\n\\end{equation}\n\nThere multiple ways to compute the optimal solution of likelihood function: in matrix calculus, sum of terms derivatives, geometry interpretation.\n\n\\subsection{Derivations of the MLE}\nDenote $\\vec{t}=(t_1,t_2,\\cdots,t_N)^T$, $\\vec{\\Phi}=\\left(\\begin{array}{c}\\vec{\\phi}(x_1)^T \\\\ \\vec{\\phi}(x_2)^T \\\\ \\vdots \\\\ \\vec{\\phi}(x_N)^T\\end{array}\\right)$.\n$\\vec{\\Phi}$ is an $N\\times M$ matrix,called the \\textbf{design matrix}, whose elements are given by $\\Phi_{nj}=\\phi_j(\\vec{x_n})$ so that\n\\begin{equation}\n\\vec{\\Phi}=\n\\begin{bmatrix}\n\\phi_0(\\vec{x_1}) &\t\\phi_1(\\vec{x_1}) &...&\\phi_{M-1}(\\vec{x_1}) \\\\\n\\phi_0(\\vec{x_2}) & \\phi_1(\\vec{x_2}) &...&\\phi_{M-1}(\\vec{x_2}) \\\\\n\\vdots &\\vdots &\\vdots&\\vdots \\\\\n\\phi_0(\\vec{x_N})& \\phi_1(\\vec{x_{N}})& \\cdot &\\phi_{M-1}(\\vec{x_N})\\\\\n\\end{bmatrix}\n\\end{equation}\n\nNote that the sum of terms can be expressed in matrix/vector multiplication.\n\\begin{align}\n\\because \\sum_{n=1}^{N}t_n\\phi(\\vec{x}_n)^T &=\\vec{t}^T\\vec{\\Phi}\n\\end{align}\n\\begin{align}\t\n\\begin{cases}\n\\vec{\\Phi} = \\begin{bmatrix}\n&\\vec{\\Phi_1^T} \\\\\n&\\vec{\\Phi_2^T} \\\\\n& ... \\\\\n&\\vec{\\Phi_n^T}\n\\end{bmatrix} \\\\\t\n\\vec{\\Phi^T}\\vec{\\Phi} =\n\\begin{bmatrix}\n\\vec{\\Phi_1} & \\vec{\\Phi_2} & ...&\\vec{\\Phi_n}\n\\end{bmatrix} \n\\cdot\n\\begin{bmatrix}\n&\\vec{\\Phi_1^T} \\\\\n&\\vec{\\Phi_2^T} \\\\\n& ... \\\\\n&\\vec{\\Phi_N^T}\n\\end{bmatrix}  = \\sum\\limits_{i=1}^{N}\\vec{\\phi_i}\\vec{\\phi_i^T}\\\\\n\\end{cases}\n\\end{align}\n\nWe see that maximizing the likelihood function under a conditional Gaussian noise distribution for a linear model is equivalent to $\\vec{w}$ minimizing the sum-of-squares error function given by $E_D$, so this method is known as \\textbf{least squares}.The gradient of the log likelihood function takes the form\n\\begin{equation}\n\\nabla\\log p(\\vec{t}|\\vec{w},\\beta)\n=\\sum_{n=1}^{N}\\{t_n-\\vec{w}^T\\phi(\\vec{x_n}) \\}\\phi(\\vec{x_n})\n\\end{equation}\nSetting the gradient respect to $\\vec{w}$ to zero gives\n\\begin{align}\n\\nabla\\log E_D &= 0 \\\\\n\\Rightarrow\\log E_D^T &= 0 \\\\\n\\Rightarrow \\sum_{n=1}^{N}\\{t_n-\\vec{w}^T\\phi(\\vec{x_n}) \\}\\phi(\\vec{x_n})^T &= 0 \\\\\n\\Rightarrow \\sum_{n=1}^{N}t_n\\phi(\\vec{x}_n)^T-\\vec{w}^T(\\sum_{n=1}^{N}\\vec{\\phi}(\\vec{x}_n)\\vec{\\phi}(\\vec{x}_n)^T) &= 0 \\\\\n\\Rightarrow \\vec{t}^T \\vec{\\Phi} - \\vec{w}^T\\vec{\\Phi}^T \\vec{\\Phi} &= 0\n\\end{align}\nSolving for $\\vec{w}$ we obtain\n\\begin{align}\n\\vec{w}_{ML}=\\hat{\\vec{w}}_{\\mathrm{OLS}}=(\\vec{\\Phi}^T\\vec{\\Phi})^{-1}\\vec{\\Phi}^T\\vec{t}\n\\end{align} \nThe corresponding solution $\\hat{\\vec{w}}_{\\mathrm{OLS}}$ to this linear system of equations is called the \\textbf{ordinary least squares} or \\textbf{OLS} or \\textbf{normal equation} solution. When $\\mathcal{D}$ is small(for example, $N < 1000$), we can use the equation to compute $\\vec{w}$ directly.\nMake the bias parameter explicit,the error function\n\\begin{align}\nE_D(\\vec{w})=\\dfrac{1}{2}\\sum_{n=1}^{N}\\{t_n-w_0-\\sum_{j=1}^{M-1}w_j\\phi_j(\\vec{x}_n)\\}^2\n\\end{align}\nSetting the derivative with respect to $w_0$ equal to zero,we obtain\n\\begin{align}\nw_0 = \\bar{t}-\\sum_{j=1}^{M-1}w_j\\bar{\\phi_j}\n\\end{align}\nThen we have\n\\begin{align}\ny&=\\vec{w}^T\\vec{\\phi} \\\\\ny&=\\sum_{j=1}^{M}w_j \\phi_j+w_0 \\\\\ny&=\\sum_{j=1}^{M}w_j \\phi_j+\\bar{t}-\\sum_{j=1}^{M-1}w_j\\bar{\\phi_j} \\\\\ny-\\bar{y}&=\\sum_{j=1}^{M}w_j(\\phi_j-\\bar{\\phi}_j)\n\\end{align}\nwhich indicates that we can normalize the features by subtracting the mean of $\\vec{\\Phi}$ while training to reduce computation complexity but obtain the same weight parameter.\n\n\\subsubsection{Matrix Calculus}\nWith regard to matrix calculus, when performing \\textbf{gradient} based updates, we represent matrix derivatives in \\textbf{denominator layout}. Thus the \\textbf{dimension} of the matrix, which we are computing derivatives with respect to, will be consistent with its gradient matrix. Denominator layout convention will make it convenient for use to compute complex derivatives with chain rule and use the result to update old parameters directly, without transposing operation.\n\nThere are multiple ways to derive matrix differential calculus:\n\\begin{enumerate}\n\\item From differential definition, the limit of $\\frac{df}{d\\vec{x}}$ when $dx$ approaches 0. Take the difference $df = f(\\vec{x} + d\\vec{x}) - f(\\vec{x})$, and compute $\\lim_{\\vec{h}\\to 0} \\frac{df}{d\\vec{x}}$.\n\\item According to matrix multiplication definition, we can expand matrix cell to \\textbf{sum of terms}. Then use 1 dimensional calculus, finally, rewrite to matrix form.\n\\item Construct \\textbf{full derivative} from a sum of of \\textbf{partial derivatives}. In this way, we can decompose a complex formula into several simple ones.\n\\end{enumerate}\n\nWe now state without proof some facts of matrix calculus (we won\u2019t need all of these at this section).\n\\begin{eqnarray}\n\\frac{\\partial}{\\partial A}AB &=& B^T \\\\\n\\frac{\\partial}{\\partial A^T}f(A) &=& \\left[\\frac{\\partial}{\\partial A}f(A)\\right]^T \\label{eqn:matrix-1} \\\\\n\\frac{\\partial}{\\partial A}ABA^TC &=& CAB+C^TAB^T \\label{eqn:matrix-2} \\\\\n\\frac{\\partial}{\\partial A}|A| &=& |A|(A^{-1})^T \\\\\ntrA &\\triangleq& \\sum\\limits_{i=1}^n A_{ii} \\nonumber\n\\end{eqnarray}\n\nTo see why $ \\frac{\\partial \\vec{A}\\vec{B}}{\\partial \\vec{A}} = \\vec{B}^T $, we use dimension analysis. Denote $ f = f(\\vec{C})$. Assume $\\vec{A}$ is of dimension $m\\times n$, $\\vec{B}$ is of dimension $n\\times p$, and of course, $\\vec{C}$ is of dimension $n\\times p$. Take the derivative of $f$ with respect to $\\vec{A}$:\n\\begin{align}\n\\underbrace{\\frac{\\partial f}{\\partial \\vec{A}}}_{m\\times n} &= \\underbrace{\\frac{\\partial f}{\\partial \\vec{C}}}_{m \\times p} \\underbrace{\\frac{\\partial \\vec{C}}{\\partial \\vec{A}}}_{p\\times n} \\\\\n\\end{align}\nAnd $\\vec{B}^T$ is of size $p\\times n$, the whole function mapping is linear. Also, we can explicitly write matrix elements in sum of terms to show that.\n\nAnother $\\mathbf{vector-vector}$ differentiation identity, if $\\mathbf{A}$ is not a function of $\\vec{x}$ then\n\\begin{eqnarray}\n\\dfrac{d\\vec{X}^TA\\vec{X}}{d\\vec{X}} \\\\\n&=& \\dfrac{d\\vec{Y}^TA\\vec{X}}{d\\vec{X}} \\\\\n&=& \\dfrac{\\partial\\vec{Y}^TA\\vec{X}}{\\partial\\vec{Y}} \\dfrac{\\partial\\vec{Y}}{\\partial\\vec{X}} +  \\dfrac{\\partial\\vec{Y}^TA\\vec{X}}{\\partial\\vec{X}} \\dfrac{\\partial\\vec{X}}{\\partial\\vec{X}}\\\\\n&=& \\dfrac{\\partial \\vec{X}^T \\vec{A}^T\\vec{Y}^T}{\\partial\\vec{Y}} \\vec{I} +  \\dfrac{\\partial\\vec{Y}^TA\\vec{X}}{\\partial\\vec{X}} \\vec{I} \\\\\n&=& \\vec{X}^T \\vec{A}^T + \\vec{Y}^T\\vec{A}\\\\\n&=& \\vec{X}^T \\vec{A}^T + \\vec{X}^T\\vec{A}\\\\\n&=& \\vec{X}^T(\\vec{A}+\\vec{A}^T)\\\\\n&=& (\\vec{A}+\\vec{A}^T)\\vec{X} \\text{, In denominator layout}\n\\end{eqnarray}\n\nMaking use of \\textbf{partial derivative}, \\textbf{chain rule} still holds. \n\n\\subsubsection{Derivation directly from Matrix Calculus}\nThe previous derivation is based on the sum of terms arithmetic. Now we derive it from matrix calculus.\n\n\\begin{proof}\nLet's drop constants with respect to $\\vec{w}$ and NLL can be written as\n\\begin{eqnarray*}\n\\text{NLL}(\\vec{w}) \n&=&\\dfrac{1}{2}\\sum\\limits_{i=1}^N (\\vec{t}_i-\\vec{w}^T\\vec{\\phi}_i)^2 \\\\\n&=&\\dfrac{1}{2}(\\vec{\\Phi}\\vec{w}-\\vec{t})^T(\\vec{\\Phi}\\vec{w}-\\vec{t}) \\\\\n&=&\\frac{1}{2} (\\vec{w}^T\\vec{\\Phi}^T\\vec{\\Phi}\\vec{w}-\\vec{w}^T\\vec{\\Phi}^T\\vec{t}-\\vec{t}^T\\vec{\\Phi}\\vec{w}+\\vec{t}^T\\vec{t}) \\\\\n&=&\\frac{1}{2} (\\vec{w}^T\\vec{\\Phi}^T\\vec{\\Phi}\\vec{w}-\\vec{w}^T\\vec{\\Phi}^T\\vec{t}-\\vec{t}^T\\vec{\\Phi}\\vec{w}) \\\\\n&=&\\dfrac{1}{2} \\vec{w^T} (\\vec{\\Phi}^T\\vec{\\Phi})\\vec{w} -\\vec{w}^T(\\vec{\\Phi}^T\\vec{t}) \\\\\n\\Rightarrow\n\\frac{\\partial \\text{NLL}}{\\partial\\vec{w}} &=& \\frac{1}{2} ((\\vec{\\Phi}^T\\vec{\\Phi}+\\vec{\\Phi}^T\\vec{\\Phi})\\vec{w} -2\\vec{\\Phi}^T\\vec{t}) \\nonumber \\\\\n&=& \\frac{1}{2} (\\vec{\\Phi}^T\\vec{\\Phi}\\vec{w} - \\vec{\\Phi}^T\\vec{t}) \\nonumber \\\\\n\\frac{\\partial \\text{NLL}}{\\partial\\vec{w}} &=& 0 \\\\\n\\Rightarrow \\vec{\\Phi}^T\\vec{\\Phi}\\vec{w} - \\vec{\\Phi}^T\\vec{t} &=& 0 \\nonumber \\\\\n\\Rightarrow \\vec{\\Phi}^T\\vec{\\Phi}\\vec{w} &=& \\vec{\\Phi}^T\\vec{t} \\label{eqn:normal-equation} \\\\\n\\Rightarrow \\vec{w}}_{\\mathrm{ML} &=& (\\vec{\\Phi}^T\\vec{\\Phi})^{-1}\\vec{\\Phi}^T\\vec{t} \\nonumber\n\\end{eqnarray*}\n\nEquation \\ref{eqn:normal-equation} is known as the \\textbf{normal equation}.\n\\end{proof}\n\n\\subsection{Geometric interpretation}\n\nSee Figure \\ref{fig:graphical-interpretation-of-OLS}.\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.50]{graphical-interpretation-of-OLS.png}\n\\caption{Graphical interpretation of least squares for $N=3$ examples and $D=2$ features. $\\tilde{\\vec{x}}_1$ and $\\tilde{\\vec{x}}_2$\u02dc are vectors in $\\mathbb{R}^3$; together they define a 2D plane. $\\vec{t}$ is also a vector in $\\mathbb{R}^3$ but does not lie on this 2D plane. The orthogonal projection of $\\vec{t}$ onto this plane is denoted $\\hat{\\vec{t}}$. The red line from $\\vec{t}$ to $\\hat{\\vec{t}}$ is the residual, whose norm we want to minimize. For visual clarity, all vectors have been converted to unit norm.}\n\\label{fig:graphical-interpretation-of-OLS} \n\\end{figure}\nGiven that\n\\begin{eqnarray}\n\\vec{X} = \\begin{bmatrix}\n\\vec{x_1}^T &\\\\\n\\vec{x_2}^T &\\\\\n ...        &\\\\\n\\vec{x_N}^T\n\\end{bmatrix} \n= \\begin{bmatrix}\n\\vec{\\tilde{x_1}} & \\vec{\\tilde{x_1}} & ... &\\vec{\\tilde{x_D}}\n\\end{bmatrix}\\\\\n\\vec{t} = \\begin{bmatrix}\nt_1 \\\\\nt_2 \\\\\n... \\\\\nt_n\n\\end{bmatrix} \n\\end{eqnarray}\nWe seek a vector $\\hat{\\vec{t}} \\in \\mathbb{R}^N$ that lies in the column linear space of $\\vec{X}$ and is as close as possible to $\\vec{t}$,i.e.,we want to find\n\\begin{eqnarray}\n\\hat{\\vec{t}} \\in span(\\vec{X}) \\\\\n\\Rightarrow \\hat{\\vec{t}} = \\vec{X}\\vec{w} = w_1\\vec{\\tilde{x_1}}+\\cdot\\cdot\\cdot+w_D\\vec{\\tilde{x_D}} \\\\\n\\vec{\\hat{t}}=\\arg\\min\\limits_{\\hat{\\vec{t}} \\in \\text{span} (\\{\\vec{\\tilde{x_1}},...,\\vec{\\tilde{x_D}}\\})}\n\\end{eqnarray}\n\nTo minimize the norm of the residual, $\\vec{t}-\\hat{\\vec{t}}$, we want the residual vector to be orthogonal to every column of $\\vec{X}$,so\u02dc $\\tilde{\\vec{x}}_j(\\vec{t}-\\hat{\\vec{t}})=0$ for $j=1:D$. Hence\n\\begin{equation}\\begin{split}\n\\tilde{\\vec{x}}_j(\\vec{t}-\\hat{\\vec{t}})=0 & \\Rightarrow \\vec{X}^T(\\vec{t}-\\vec{X}\\vec{w})=0 \\\\\n                                           & \\Rightarrow \\vec{w}=(\\vec{X}^T\\vec{X})^{-1}\\vec{X}^T\\vec{t}\n\\end{split}\\end{equation}\n\n\n\\subsection{Sequential learning}\n\\textbf{Stochastic gradient descent(SGD)}, is also known as sequential gradient descent. \nBatch techniques,such as maximum likelihood, involves processing the entire training set in one go(pass), which can be computationally costly for large data sets. For sufficiently large datasets, it's worthwhile to use \\textbf{sequential} algorithms,known as \\textbf{on-line} algorithms.\n\nIf the error function comprises a sum over data points $E = \\sum_n En$, then after presentation of pattern n, the stochastic gradient descent algorithm updates the parameter vector w using\n\\begin{align}\nE &=\\sum_{n}E_n \\\\\n\\vec{w}^{\\tau+1} &= \\vec{w}^{\\tau}-\\eta\\nabla E_n\n\\end{align}\nwhere $\\tau$ denotes the iteration number,the $\\eta$ is a learning rate parameter.For the case of sum-of-squares error function,this gives\n\\begin{equation}\n\\vec{w}^{\\tau+1} = \\vec{w}^{\\tau}-\\eta(t_n-\\vec{w}^{(\\tau)T}\\phi_n)\\phi_n\n\\end{equation}\nwhere $\\phi_n=\\phi(\\vec{x_n})$.This is known as the \\textbf{least-mean-squares} or the LMS algorithm.\nNotice that the gradient vector $\\nabla{E_n}$ here, is different with the one we used to derive the closed-form solution, which was using \\textbf{numerator layout} to make it convenient to solve the equation.\n\n\\begin{align}\n\\because \\dfrac{\\partial}{\\partial w_i}\\text{NLL}(\\vec{w})=& \\sum\\limits_{i=1}^N (\\vec{w}^T\\vec{x}_i-y_i)x_{ij} \\\\\n\\therefore w_j=& w_j - \\alpha\\dfrac{\\partial}{\\partial w_j}\\text{NLL}(\\vec{w}) \\nonumber \\\\\n                  =& w_j - \\sum\\limits_{i=1}^N \\alpha(\\vec{w}^T\\vec{x}_i-y_i)x_{ij} \\\\\n\\therefore \\vec{w}=& \\vec{w}-\\alpha(\\vec{w}^T\\vec{x}_i-y_i)\\vec{x}\n\\end{align}\n\n\n\\section{Ridge regression(MAP)}\nOne problem with ML estimation is that it can result in over-fitting. In this section, we discuss a way to ameliorate this problem by using MAP estimation with a Gaussian prior.\n\n\\subsection{Basic idea}\nWe can encourage the parameters to be small, thus resulting in a smoother curve, by using a zero-mean Gaussian prior:\n\\begin{equation}\np(\\vec{w})=\\prod\\limits_j \\mathcal{N}(w_j|0,\\tau^2)\n\\end{equation}\nwhere $1/\\tau^2$ controls the strength of the prior. The corresponding MAP estimation problem becomes\n\\begin{equation}\n\\arg\\max_{\\vec{w}} \\sum\\limits_{i=1}^N \\log{\\mathcal{N}(t_i|w_0+\\vec{w}^T\\vec{\\phi}_i,\\sigma^2)}+\\sum\\limits_{j=1}^D \\log{\\mathcal{N}(w_j|0,\\tau^2)}\n\\end{equation}\n\nThis is equivalent to minimizing the following\n\\begin{align}\\label{eqn:Ridge-regression-J}\nJ(\\vec{w})&=E_D(\\vec{w})+\\lambda E_W(\\vec{w}) \\\\\n&=\\dfrac{1}{N}\\sum\\limits_{i=1}^N (y_i-(w_0+\\vec{w}^T\\vec{x}_i))^2+\\lambda\\lVert\\vec{w}\\rVert^2 , \\lambda \\triangleq \\dfrac{\\sigma^2}{\\tau^2}\n\\end{align}\nwhere the first term is the MSE/ NLL as usual, and the second term, $\\lambda \\geq 0$, is the regularization coefficient that controls the complexity penalty.\nHere $E_W(\\vec{w})$ is one of the simplest forms of regularizer given by the sum-of-squares of the weight vector elements.\n\\begin{equation}\nE_W(\\vec{w})=\\dfrac{1}{2}\\vec{w}^T\\vec{w}\n\\end{equation}\nThis particular choice of regularizer is known as \\textbf{weight decay}.\n\nThe corresponding solution is given by\n\\begin{equation}\\label{eqn:Ridge-regression-solution}\n\\hat{\\vec{w}}_{\\mathrm{ridge}}=(\\lambda\\vec{I}_D+\\vec{\\Phi}^T\\vec{\\Phi})^{-1}\\vec{\\Phi}^T\\vec{t}\n\\end{equation}\n\nThis technique is known as \\textbf{ridge regression},or \\textbf{penalized least squares}. In general, adding a Gaussian prior to the parameters of a model to encourage them to be small is called $\\ell_2$ \\textbf{regularization} or \\textbf{weight decay}. Note that the offset term $w_0$ is not regularized, since this just affects the height of the function, not its complexity.\n\nWe will consider a variety of different priors in this book. Each of these corresponds to a different form of \\textbf{regularization}. This technique is very widely used to prevent overfitting.\n\n\\subsection{Multiple outputs}\nNow consider the case where we wish to predict $K>1$ target variables,which we denote collectively by the target vector $\\vec{t}$.To use the same set of basis functions to model all the components of the target vector so that\n\\begin{equation}\n\\vec{y}(\\vec{x},\\vec{w}) = \\vec{W}^T\\phi(x)\n\\end{equation}\nwhere $\\vec{y}$ is a $K$-dimensional column vector,$\\vec{W}$ is an $M\\times K$ matrix of parameters.\n\nThe conditional distribution of the target vector is an isotropic Gaussian\n\\begin{equation}\np(\\vec{t}|\\vec{x},\\vec{W},\\beta) =\n\\mathcal{N}(\\vec{t}|\\vec{W}^T\\phi(x,\\beta^{-1}\\vec{I}))\n\\end{equation}\n\nThe log likelihood function is then given by \n\\begin{align}\n\\ln p(\\vec{T}|\\vec{X},\\vec{W},\\beta) \n&=\\sum_{n=1}^{N}\\ln \\mathcal{N}(\\vec{t_n}|\\vec{W}^T\\phi(x_n),\\beta^{-1}\\vec{I}) \\\\\n&=\\dfrac{NK}{2}\\ln(\\dfrac{\\beta}{2\\pi}) \n -\\dfrac{\\beta}{2}\\sum_{n=1}^{N}\\parallel \\vec{t_n}-\\vec{W}^T\\phi(x_n)\\parallel^2\n\\end{align}\nWe maximize this function with respect to $\\vec{W}$,giving\n\\begin{equation}\n\\vec{W}_{ML} = (\\vec{\\Phi}^T\\vec{\\Phi})^{-1}\\vec{\\Phi}^T\\vec{T}\n\\end{equation}\n\n\n\\subsection{Numerically stable computation *}\n\n\\begin{equation}\\label{eqn:Ridge-regression-SVD}\n\\hat{\\vec{w}}_{\\mathrm{ridge}}=\\vec{V}(\\vec{Z}^T\\vec{Z}+\\lambda\\vec{I}_N)^{-1}\\vec{Z}^T\\vec{y}\n\\end{equation}\n\n\n\\subsection{Connection with PCA *}\n\n\n\\subsection{Regularization effects of big data}\nRegularization is the most common way to avoid overfitting. However, another effective approach \u2014 which is not always available \u2014 is to use lots of data. It should be intuitively obvious that the more training data we have, the better we will be able to learn.\n\nIn domains with lots of data, simple methods can work surprisingly well (Halevy et al. 2009). However, there are still reasons to study more sophisticated learning methods, because there will always be problems for which we have little data. For example, even in such a data-rich domain as web search, as soon as we want to start personalizing the results, the amount of data available for any given user starts to look small again (relative to the complexity of the problem).\n\n\\section{The Bias-Variance Decomposition}\n\\subsubsection{representation}\nData representation:\nN observations of x,wiritten \n$X \\equiv (x_1,x_2,...,x_n)^T$\ntogether with corresponding observations of the values of t,denoted \n$t \\equiv (t_1,t_2,...t_N)^T$.\n\\begin{equation}\nt_i = f(\\vec{x_i}) + \\epsilon \n\\end{equation}\nwhere the noise $ \\epsilon $ has zero mean and variance $ \\sigma^2 $.\nFind a function \\[ \\hat{f}(x) \\] that approximates the true function \\[ t = f(\\vec{x}) \\] as well as possible.Make \"as well as possible\" precise  by measuring the mean squared error between y and $ \\hat{f}(x) $,we want $ (t - \\hat{f}(x))^2 $ to be minimal.\nHypothesis function(model representation):\n$y(x,\\bold w)= w_0+w_1x+w_2x^2+...+w_Mx^M = \\sum_{j=0}^{M}w_jx^j$\nM is the order of the polynomial,and $x^j$ denotes $x$ raised to the power of $j$.The polynomial coefficients $w_0,...w_M$ are\ncollectively denoted by the vector $\\mathbf{w}$.\n\nError Function(Sum of squares of errors between predictions $y(x_n,w)$ for each data point $x_n$ and the corresponding target values $t_n$,so that we minimize:\n\\begin{equation}\nE(\\bold w)=\\frac{1}{2}\\sum_{n=1}^{N}\\{y(x_n,\\bold w)-t_n \\}^2\n\\end{equation}\nroot-mean-squre(RMS) error defined by\n\\begin{equation} \nE_{RMS} = \\sqrt[2]{2E(\\bold w^*)/N}\n\\end{equation}\nPenalized(regularized) error function\n\\begin{equation}\n\\widetilde{E}(\\textbf{w}) = \\frac{1}{2}\\sum_{n=1}^{N}\\{y(x_n,\\textbf{w}-t_n\\}^2 + \\frac{1}{2} \\parallel \\textbf{w} \\parallel^2\n\\end{equation}\nwhere $\\parallel \\textbf{w} \\parallel^2 \\equiv \\textbf{w}^T\\textbf{w}=w_0^2+w_1^2+...+w_M^2$\n\n\\subsubsection{Loss function for regression}\n\\begin{equation}\n\\mathbb{E}[\\mathit{L}] = \\iint\\mathit{L}(t,y(\\textbf{x}))p(\\textbf{x},t)d\\textbf{x}dt\n\\end{equation}\nA common choice of loss function in squared loss given by \n\\begin{eqnarray}\n\\mathit{L}(t,y(\\textbf{x})) = \\{y(\\textbf{x}) - t\\}^2 \\\\\n\\mathbb{E}[\\mathit{L}] = \\iint\\{y(\\textbf{x}) - t\\}^2 p(\\textbf{x},t)d\\textbf{x}dt.\n\\end{eqnarray}\nMinimize $ \\mathbb{E}[\\mathit{L}] $ by using the calculus of variations to give \n\\begin{equation}\n\\frac{\\delta\\mathbb{E}[\\mathit{L}]}{\\delta y(\\mathbf{x}))} = 2 \\int\\{ y(\\mathbf{x} -t) \\}p(\\mathbf{x},t)dt = 0\n\\end{equation}\nSolving for $ y(\\textbf{x}) $ and using the sum and product rules of probability,we obtain\n\\begin{equation}\ny(\\textbf{x}) = \\frac{\\int tp(\\textbf{x},t)dt}{p(\\textbf{x})} = \\int tp(t|\\textbf{x})dt = \\mathbb{E}[t|\\textbf{x}]\n\\end{equation}\n\nLet's derive this result in a slightly different way.Armed with knowledge that the optimal solution is the \nconditional expectation,we can expand the square term as follows\n\\begin{equation}\n\\{y(\\textbf{x} -t)\\}^2\n= \\{y(\\textbf{x}) - \\mathbb{E}[t|\\textbf{x}] + \\mathbb{E}[t|\\textbf{x}] - t )\\}^2 \n= \\{ y(\\textbf{x}) - \\mathbb{E}[t|\\textbf{x}] \\}^2 + 2\\{ y(\\textbf{x}) - \\mathbb{E}[t|\\textbf{x}] \\}\\{ \\mathbb{E}[t|\\textbf{x}]-t \\} + \\{ \\mathbb{E}[t|\\textbf{x}] -t \\}^2\n\\end{equation}\nwhere,$ \\mathbb{E}[t|\\textbf{x}] $ denote $ \\mathbb{E}_{t}[t|\\textbf{x}] $.Substitute into the loss function and perform the integral over t,we see the cross-term vanishes\n\\begin{align}\\label{eqn:squared loss function}\n\\mathbb{E}[\\mathit{L}]                                                           \n&= \\iint\\{y(\\textbf{x}) - t\\}^2 p(\\textbf{x},t)d\\textbf{x}dt                    \\\\\n&= \\int \\{ y(\\textbf{x}) -\\mathbb{E}[t|\\textbf{x}] \\}^2 p(\\textbf{x})d\\textbf{x} + \n\\int\\{ \\mathbb{E}[t|\\textbf{x}] - t \\}^2 p(\\textbf{x})d\\textbf{x}               \\\\\n&= \\int \\{ y(\\textbf{x}) -h(\\textbf{x}) \\}^2 p(\\textbf{x})d\\textbf{x} +            \n\\int\\{ h(\\textbf{x}) - t \\}^2 p(\\textbf{x})d\\textbf{x}                          \\\\\n&= \\int \\{ y(\\textbf{x}) -h(\\textbf{x}) \\}^2 p(\\textbf{x})d\\textbf{x} +            \n\\int\\{ h(\\textbf{x}) - t \\}^2 p(\\textbf{x},t)d\\textbf{x}dt                      \\\\\n\\end{align}\n\n\\subsubsection{Decomposition}\nFor a popular choice,we use squared loss function,for which the optimal prediction is given by the conditional\nexpectation,which we denote by h(\\textbf{x}) and which is given by \n\\begin{equation}\nh(\\textbf{x}) = \\mathbb{E}[t|\\textbf{x}] = \\int tp(t|\\textbf{x})dt\n\\end{equation}\n\nConsider the integrand of the first term of \\ref{eqn:squared loss function},which for particular data set D takes the form\n\\begin{equation}\n\\{ y(\\textbf{x};D) - h(\\textbf{x}) \\} ^2\n\\end{equation}\nThis quantity will be dependent on the particular data set D,so we take its average over the ensemble of data sets.\nIf we add and subtract the quantity $ \\mathbb{E_D}[y(\\textbf{x};D)] $ inside the braces,and then expand,we obtain\n\\begin{align}\n\\{ y(\\textbf{x};D) - h(\\textbf{x}) \\} ^2 \\\\\n=&\\{y(\\textbf{x};D) - \\mathbb{E_D}[y(\\textbf{x};D)] \n\t+ \\mathbb{E_D}[y(\\textbf{x};D)] -h(\\textbf{x})  \\}^2         \\\\\n=& \\{ y(\\textbf{x};D) -\\mathbb{E}_{\\mathbb{D}}[y(\\textbf{x};D)]    \\}^2 \n\t+ \\{ \\mathbb{E_D}[y(\\textbf{x};D)] - h(\\textbf{x})\\}^2\n\t+ 2\\{ y(\\textbf{x};D) - \\mathbb{E_D}[y(\\textbf{x};D)]\\}\\{ \\mathbb{E_D}[y(\\textbf{x};D)] -h(\\textbf{x})\\} \\\\\n=& \\underbrace{\\{ y(\\textbf{x};D) -\\mathbb{E}_{\\mathbb{D}}[y(\\textbf{x};D)]    \\}^2}_\\text{\\color{red}{variance}} \n\t+ \\underbrace{\\{ \\mathbb{E_D}[y(\\textbf{x};D)] - h(\\textbf{x})\\}^2}_\\text{\\color{blue}$(bias)^2$} \n\t+0\\\\\n\\end{align}\nThe decomposition of the expected squared loss\n\\begin{equation}\n\\text{expected loss} = (bias)^2 + variance + noise\n\\end{equation}\nwhere\n\\begin{eqnarray}\n(bias)^2 = ... \\\\\nvariance = ... \\\\\nnoise = ...\n\\end{eqnarray}\n\nThe function $ y(\\textbf{x}) $ we seek to determine enters only the first term,which will be minimized when $ y(\\textbf{x}) $ is equal to $ \\mathbb{E}[t|\\textbf{x}] $,in which case this term will vanish.The second term is the variance of distribution of t,averaged over $ \\textbf{x} $,representing the intrinsic variabilility of the target data and can be regarded as noise.It's the irreducible minimum value of the loss function.\n\nMore sophisticated loss function,Minkowski loss\n\\begin{equation}\n\\mathbb{E}[\\mathit{L_q}] = \\iint| y(\\textbf{x}) - t |^q p(\\textbf{x},t)d\\textbf{x}dt\n\\end{equation}\n\n\n\\section{Bayesian linear regression}\nHold-out data can be used to determine model complexity but it will be \ncomputationally expensive and wasteful of valuable data.We therefore turn to a Bayesian treatment of linear regression,which will avoid the over-fitting problem of maximum likelihood,and which will also lead to automatic methods of determining model complexity using the training data.\n\n\\subsection{Parameter distribution}\nFirst introduce a prior probability distribution over the model parameters.The likelihood function $p(\\vec{t}|\\vec{w})$ defined by \\ref{eqn:linear regression likelihood} is the exponential of a quadratic function of $\\vec{w}$,so the corresponding conjugate prior is\nGaussian\n\\begin{equation}\np(\\vec{w}) = \\mathcal{N}(\\vec{w}|\\vec{m_0},\\vec{S}_0)\n\\end{equation}\n\nThe posterior distribution is proportional to the product of the likelihood and the prior.And the posterior will also be Gaussian due to the choice of conjugate Gaussian prior,which is derived in \\ref{sec:Gaussian distribution}.\n\\begin{equation}\\label{eqn:Bayes linear regression posterior}\np(\\vec{w}|\\vec{t}) = \\mathcal{N}(\\vec{w}|\\vec{m}_N,\\vec{S}_N)\n\\end{equation}\nwhere \n\\begin{align}\n\\vec{m}_N &=\\vec{S}_N(\\vec{S}_0^{-1}\\vec{m}_0+\\beta\\vec{\\Phi}^T\\vec{t})\\\\\n\\vec{S}_N^{-1} &= \\vec{S}_0^{-1}+\\beta\\vec{\\Phi}^T\\vec{\\Phi}\n\\end{align}\nThus the maximum posterior weigh vector is simply given by $\\vec{w}_{MAP}=\\vec{m}_{N}$.If $N=0$ then the posterior distribution reverts to the prior.Furthermore,if data points arrive sequentially,then the posterior distribution at any stage acts as the prior distribution,such that the new posterior is again given.\n\nA zero-mean isotropic Gaussian governed by a single precision parameter $\\alpha$ so that\n\\begin{equation}\np(\\vec{w}|\\alpha) = \\mathcal{N}(\\vec{w}|\\vec{0},\\alpha^{-1}\\vec{I})\n\\end{equation}\nfor which the posterior is given by\n\\begin{align}\n\\vec{m}_N &=\\beta\\vec{S}_N\\vec{\\Phi}^T\\vec{t} \\\\\n\\vec{S}_N^{-1}&=\\alpha\\vec{I}+\\beta\\vec{\\Phi}^T\\vec{\\Phi}\n\\end{align}\n\nThe log of posterior distribution is given by the sum of the log likelihood and the log of prior and,as a function of $\\vec{w}$,takes the form\n\\begin{equation}\n\\log p(\\vec{w}|\\vec{t}) = \n-\\dfrac{\\beta}{2}\\sum_{n=1}^{N}\\{t_n-\\vec{w}^T\\phi(\\vec{x}_n) \\}^2-\\dfrac{\\alpha}{2}\\vec{w}^T\\vec{w}+const\n\\end{equation}\nMaximization of this posterior w.r.t $\\vec{w}$ is equivalent to minimization of the sum-of-squares error function with the addition of a quadratic regularization term,corresponding with $\\lambda=\\alpha/\\beta$.\n\n\n\n\\subsection{Predictive distribution}\nEvaluate the \\textbf{predictive distribution} defined by\n\\begin{equation}\np(t|\\vec{t},\\alpha,\\beta) = \\int p(t|\\vec{w},\\beta)p(\\vec{w}|\\vec{t},\\alpha,\\beta)d\\vec{w}\n\\end{equation}\nThe right hand quantity can be interpreted as the marginalization by integration of the joint distribution of $p(t,\\vec{w}|\\vec{t},\\alpha,\\beta)$ over $\\vec{w}$.And the joint distribution can be solved by the Bayesian theorem for Gaussian.\nThe conditional distribution $p(t|\\vec{x},\\vec{w},\\beta)$ of the target variable is given by \\ref{eqn:linear regression representation},and the posterior weight distribution is given by \\ref{eqn:Bayes linear regression posterior}.This involves the \\textbf{convolution} of two Gaussian distributions.The predictive distribution take the form\n\\begin{equation}\np(t|x,\\vec{t},\\alpha,\\beta) = \\mathcal{N}(t|\\vec{m}_N^T\\phi(x),\\sigma_N^2(\\vec{x}))\n\\end{equation}\nwhere the variance $\\sigma_N^2(\\vec{x})$ is given by\n\\begin{equation}\n\\sigma_N^2(\\vec{x})=\\dfrac{1}{\\beta}+\\phi(\\vec{x})^T\\vec{S}_N\\phi(\\vec{x})\n\\end{equation}\nThe first term represents the noise on the data whereas the second term reflects the uncertainty associated with the parameters $\\vec{w}$.\n$\\sigma_{N+1}^2(\\vec{x})\\leq \\sigma_N(\\vec{x})$.In the limit $N\\rightarrow \\infty$,the second term goes to zero.\n\nNote that if both $\\vec{w}$ and $\\beta$ are treated as unknown,then we can introduce a conjugate prior distribution $p(\\vec{w},\\beta)$ given by Gaussian-gamma distribution,leading to a Student's t-distribution predictive distribution.\n\n\\subsection{Equivalent kernel}\nThe posterior mean solution \\ref{} has an interpretation that will set stage for kernel methods,including Gaussian processes.The predictive mean:\n\\begin{equation}\ny(\\vec{x},\\vec{w})=\\vec{m}_N^T\\vec{\\phi}(\\vec{x})\n=\\beta\\vec{\\phi}(\\vec{x})^T\\vec{S}_N\\vec{\\Phi}^T\\vec{t}\n=\\sum_{n=1}^{N}\\beta\\vec{\\phi}(\\vec{x})^T\\vec{S}_N\\vec{\\phi}(\\vec{x}_n)t_n\n=\\sum_{n=1}^{N}\\mathit{k}(\\vec{x},\\vec{x}_n)t_n\n\\end{equation}\nwhere\n\\begin{equation}\nk(\\vec{x},\\vec{x'})\n=\\beta\\vec{\\phi}(\\vec{x})^T\\vec{S}_N\\vec{\\phi}(\\vec{x'})\n\\end{equation}\nis known as the \\textbf{smoother matrix} or \\textbf{equivalent kernel}.Regression functions,such as this,which make predictions by taking linear combinations of the training set target values are known \\textbf{linear smoothers}.The kernel functions are localized around $x$(local evidence weight more than distant evidence).\n\nThe covariance between $y(\\vec{x})$ and $y(\\vec{x'})$ is given by\n\\begin{align}\ncov[y(\\vec{x}),y(\\vec{x'})] &=cov[\\vec{\\phi}(\\vec{x})^T\\vec{w},\\vec{w}^T\\vec{\\phi}(\\vec{x'})] \\\\\n&=\\phi(\\vec{x})^T\\vec{S}_N\\phi(\\vec{x'})=\\beta^{-1}\\mathit{k}(\\vec{x},\\vec{x'})\n\\end{align}\nWe see that the predictive mean at nearby points will be highly correlated.\n\nThe formulation of linear regression in terms of kernel functions suggests an alternative approach,called \\textbf{Gaussian process}:Instead of introducing a set of basis functions,which implicitly determines an equivalent kernel,we can instead define a localized kernel directly and use this to make predictions for new input vectors $\\vec{x}$,given the observed training set.\n\nThe effective kernel defines the weights by which the training set target values are combined in order to make a prediction at a new value of $x$,and it can be shown that these weights sum to one,\n\\begin{align}\n\\sum\\limits_{n=1}^{N}\\mathcal{k}(\\vec{x},\\vec{x}_n) = 1\n\\end{align}\nfor all values of $\\vec{x}$.\n\nGeneral kernel functions share an important property,namely that it can be expressed in the form an inner product with respect to a vector $\\varPsi(\\vec{x}) $ of nonlinear functions,so that\n\\begin{align}\n\\mathcal{k}(\\vec{x},\\vec{z}) = \\varPsi(\\vec{x})^T\\varPsi(\\vec{z})\n\\end{align}\nwhere $\\varPsi(\\vec{x})=\\beta^{1/2}\\vec{S}_n^{1/2}\\phi(\\vec{x})$\n\n\\section{Bayesian Model Comparison}\nThe over-fitting associated with maximum likelihood can be avoided by \\textbf{marginalizing(summing or integrating)} over the model parameters instead of making point estimates of their values,no need for validation.\n\nSuppose we wish to compare a set of $L$ models $\\{\\mathcal{M}_i\\},i=1,...L$ over observed data $\\mathcal{D}$.Evaluate the posterior distribution\n\\begin{align}\np(\\mathcal{M}_i|\\mathcal{D})\\propto p(\\mathcal{M}_i)p(\\mathcal{D}|\\mathcal{M}_i)\n\\end{align}\nThe prior allows us to express a preference for different models.$p(\\mathcal{D}|\\mathcal{M}_i)$ is the \\textbf{model evidence},which expresses the preference shown by the data for different models.It is also called the \\textbf{marginal likelihood}.The ratio of model evidences $p(\\mathcal{D}|\\mathcal{M}_i)/p(\\mathcal{D}|\\mathcal{M}_j)$ for two models is \\textbf{Bayes factor}.\nThe predictive distribution\n\\begin{align}\n& p(t|\\vec{x},\\mathcal{D})p(\\mathcal{M}_i|\\mathcal{D})&=p(t|\\vec{x},\\mathcal{M}_i,\\mathcal{D})p(\\mathcal{M}_i|\\mathcal{D}) \\\\\n&\\Rightarrow \\sum\\limits_{i=1}^{L}p(t|\\vec{x},\\mathcal{D})p(\\mathcal{M}_i|\\mathcal{D})&=\\sum\\limits_{i=1}^{L}p(t|\\vec{x},\\mathcal{M}_i,\\mathcal{D})p(\\mathcal{M}_i|\\mathcal{D}) \\\\\n&\\Rightarrow p(t|\\vec{x},\\mathcal{D})&=\\sum\\limits_{i=1}^{L}p(t|\\vec{x},\\mathcal{M}_i,\\mathcal{D})p(\\mathcal{M}_i|\\mathcal{D}) \\\\\n\\end{align}\nThis is an example of a \\textbf{mixture distribution} in which the overall predictive distribution is obtained by averaging the predictive distributions of individual models weighted by the posterior probabilities $p(\\mathcal{M}_i|\\mathcal{D})$ of those models.\n\nTo use the single most probable model alone to make predictions is known as \\textbf{model selection}.Model evidence\n\\begin{align}\np(\\mathcal{D}|\\mathcal{M}_i)=\\int p(\\mathcal{D}|\\mathcal{\\vec{w}})p(\\vec{w}|\\mathcal{M}_i)d\\vec{w}\n\\end{align}\nbecause\n\\begin{align}\np(\\vec{w}|\\mathcal{D},\\mathcal{M}_i)=\\dfrac{p(\\mathcal{D}|\\vec{w},\\mathcal{M}_i)p(\\vec{w}|\\mathcal{M}_i)}{p(\\mathcal{D}|\\mathcal{M}_i)}\n\\end{align}\n\nAssume the posterior distribution over parameters is sharply peaked around the most probable value $w_{MAP}$,with width $\\Delta w_{posterior}$,then we can approximate the integral by the value of integrand at its maximum times the width of the peak.And further assume that the prior is flat with width $\\Delta w_{prior}$ so that $p(w)=1/\\Delta w_{prior}$,then we have\n\\begin{align}\np(\\mathcal{D})=\\int p(\\mathcal{D}|w)p(w)dw \\simeq p(\\mathcal{D}|w_{MAP})p(w_{MAP})\\Delta w_{posterior} \\simeq p(\\mathcal{D}|w_{MAP})\\dfrac{\\Delta w_{posterior}}{\\Delta w_{prior}}\n\\end{align}\n\\begin{SCfigure*}\n\t\\caption{model evidence approximation}\n\t\\includegraphics{prml/Figure3.12}\n\\end{SCfigure*}\n\nand so taking logs\n\\begin{align}\n\\ln p(\\mathcal{D}) \\simeq \\ln p(\\mathcal{D}|w_{MAP}) +\\ln(\\dfrac{\\Delta w_{posterior}}{\\Delta w_{prior}})\n\\end{align}\nIf we have a set of $M$ parameters,assuming that all parameters have the same ratio of $\\Delta w_{posterior}/\\Delta w_{prior}$,we obtain\n\\begin{align}\n\\ln p(\\mathcal{D}) \\simeq \\ln p(\\mathcal{D}|w_{MAP}) +M\\ln(\\dfrac{\\Delta w_{posterior}}{\\Delta w_{prior}})\n\\end{align}\nAs we increase the complexity of the model,the first term representing the fit to the data,increases(?),whereas the second term will decrease due to the dependence on $M$.The optimal model is given by a trade-off between these two competing terms.\n\\begin{SCfigure*}\n\t\\caption{Model complexity increases}\n\t\\includegraphics{prml/Figure3.13}\n\\end{SCfigure*}\nAverage the Bayes factor over the distribution of data sets\n\\begin{align}\n\\int p(\\mathcal{D}|\\mathcal{M}_1)\\ln\\dfrac{p(\\mathcal{D}|\\mathcal{M}_1)}{p(\\mathcal{D}|\\mathcal{M}_2)}\n\\end{align}\nThis quantity is $Kullback-Leibler$ divergence,and will be bigger than or equal to $0$ if $\\mathcal{M}_1$ is the correct model.\n\n\\section{Model Evidence}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "7ba769c6ba419b32c6530002b8dbb41cd7645a3c", "size": 37256, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/LinearRegression.tex", "max_stars_repo_name": "Alexoner/Statistical-formula", "max_stars_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-15T17:00:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-24T13:46:00.000Z", "max_issues_repo_path": "prml/LinearRegression.tex", "max_issues_repo_name": "Alexoner/Statistical-formula", "max_issues_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "prml/LinearRegression.tex", "max_forks_repo_name": "Alexoner/Statistical-formula", "max_forks_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-02-25T15:40:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T04:26:03.000Z", "avg_line_length": 55.856071964, "max_line_length": 524, "alphanum_fraction": 0.6923180159, "num_tokens": 12703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942145139149, "lm_q2_score": 0.9019206673024666, "lm_q1q2_score": 0.8146997207248475}}
{"text": "\\section{energy in one slab for 1D}\n\nHow to find the energy contained in a 1D slab:\n\nPhysically, there is a slab in the x-direction from $x=0$ to $x=a$. The wave propating in the positive x-direction has amplitude $A$ and the opposite direction has amplitude $B$. \n\nMethod: match the wave and derivative at the boundary.\n\nElectric field:\n\\begin{equation}\n E(x) = A e^{i k n x} + B e^{-i k n x}\n\\end{equation}\n\nEnergy density is $\\epsilon |E|^2$, where $\\epsilon$ is the dielectric constant and is related to the index of refraction $n$ by $\\epsilon=n^2$. The total energy in a slab of size $a$ is \n\\begin{equation}\n energy = {\\cal E} = \\epsilon \\int_0^a |E|^2 dx\n\\end{equation}\nThe integrand is\n\\begin{equation}\n |E|^2 = (A e^{i k n x} + B e^{-i k n x})(A^* e^{i k n x} + B^* e^{-i k n x})\n\\end{equation}\nExpanding,\n\\begin{equation}\n |E|^2 = |A|^2+ AB^* e^{2 i k n x} + A^* B e^{-2 i k n x} + |B|^2\n\\label{eq:expanded_energy}\n\\end{equation}\n\nHow do we know that A and B should be complex? Recall that the field is given by $E=A+B$, and the derivative of the field is\n\\begin{equation}\n \\frac{1}{k} \\frac{\\partial E}{ \\partial x} = i (A-B)\n\\end{equation}\nSolving for $A$ and $B$, \n\\begin{equation}\n \\begin{gathered}\n  A= \\frac{1}{2} (E-i\\frac{1}{k} \\frac{\\partial E}{ \\partial x}) \\\\\n  B= \\frac{1}{2} (E+i\\frac{1}{k} \\frac{\\partial E}{ \\partial x})\n \\end{gathered}\n\\end{equation}\nThus $A$ and $B$ are both complex.\n\nReturning to Eq.~\\ref{eq:expanded_energy} and re-grouping terms,\n\\begin{equation}\n {\\cal E} = \\epsilon \\int_0^a |E|^2 dx = n^2 [(|A|^2+|B|^2)a + AB^* \\frac{1}{2ikn}(e^{2 i k n x}-1) - A^*B\\frac{1}{2ikn}(e^{-2 i k n x}-1)]\n\\label{eq:energy_integral}\n\\end{equation}\nEven though the terms contain complex pieces, we expect the result to be real since energy is observable and doesn't have a phase.\n\nIf $z=x+iy$, then \n\\begin{equation}\n z+z^* = x+iy +x-iy = 2x = 2 Re(z)\n\\end{equation}\nThus Eq.~\\ref{eq:energy_integral} is real.\n\nThe middle term of Eq.~\\ref{eq:energy_integral} can be expanded as\n\\begin{equation}\n AB^* \\frac{1}{2ikn}(e^{2 i k n x}-1) = \\frac{AB^* e^{ i k n x}}{kn} \\left( \\frac{e^{ i k n x} - e^{-i k n x}}{2i}\\right)\n\\end{equation}\n\nAnd then applying $z+z^*=2 Re(z)$, the energy in one 1D slab is\n\n\\begin{equation}\n {\\cal E} =  n^2 \\left[(|A|^2+|B|^2)a + 2 Re \\left(  \\frac{AB^* e^{ i k n x} sin(kna)}{kn}\\right)\\right]\n\\end{equation}\n", "meta": {"hexsha": "3847317cd17241e4db65f946aa04e3663d48ceda", "size": 2364, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/appendix_1d_energy_in_one_slab_derivation.tex", "max_stars_repo_name": "bhpayne/physics_phd_dissertation", "max_stars_repo_head_hexsha": "646123088fdd226e8677e6f3edb8d109be96994e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/appendix_1d_energy_in_one_slab_derivation.tex", "max_issues_repo_name": "bhpayne/physics_phd_dissertation", "max_issues_repo_head_hexsha": "646123088fdd226e8677e6f3edb8d109be96994e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/appendix_1d_energy_in_one_slab_derivation.tex", "max_forks_repo_name": "bhpayne/physics_phd_dissertation", "max_forks_repo_head_hexsha": "646123088fdd226e8677e6f3edb8d109be96994e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.9375, "max_line_length": 187, "alphanum_fraction": 0.6421319797, "num_tokens": 891, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.8774767874818408, "lm_q1q2_score": 0.814657175257542}}
{"text": "%----------------------------------------------------------------------------------------\n%   ELECTROSTATIC EQUILIBRIUM\n%----------------------------------------------------------------------------------------\n\n\\section{Electrostatic equilibrium}\n\\subsection{Jacobian Matrix}\nLet us consider the interval $[-1, 1]$ and two electrostatic charges fixed at the positions $-1$ and $1$. We assume that there exists $N$ charges positioned at $x_1, x_2,..., x_N$ and that these charges can move freely in the interval $[-1, 1]$.\n\nFindind the positions that essen the amout energy of the charges means:\n\\[\\nabla E(x_1, x_2, ..., x_n) = \\begin{pmatrix}\\frac{\\partial E(x_1,...,x_N)}{\\partial x_i}\\end{pmatrix}_{i \\in [1,N]} = 0\\]\n\nNoticing that : \n\\[\\frac{\\partial E(x_1,...,x_N)}{\\partial x_i} = \\frac{1}{x_i + 1} + \\frac{1}{x_i - 1} +  \\displaystyle\\sum_{j=1,j\\ne i}^{N}\\frac{1}{(x_i - x_j)}\\]\n\nThus, the jacobian matrix of $\\nabla E(x_1, x_2, ..., x_n)$ is defined as:\n\\begin{center}\n  \\fbox{\n    $J = \\begin{pmatrix}\\frac{\\partial^2 E}{\\partial x_i \\partial x_j}\\end{pmatrix}_{i\\in [1,N], j\\in[1,N]}$}\n\\end{center}\nwhere \n\n\\[\\begin{pmatrix}\\frac{\\partial^2 E}{\\partial x_i \\partial x_j}\\end{pmatrix}  =  \\left\\{\n\\begin{array}{ll}\n  \\frac{1}{(x_i - x_j)^2} & \\mbox {if $i\\ne j$}\\\\\n  \\frac{-1}{(x_i +1)^2 } - \\frac{1}{(x_i - 1)^2 } - \\displaystyle\\sum_{j=1,j\\ne i}^{N}\\frac{1}{(x_i  - x_j)^2} & \\mbox{else}\n\\end{array}\\right.\\]\n\n\\subsection{Equation solving}\nThe Newton-Raphson method is applied in order to find the roots of non-linear equation system.\n\nThe equilibrium positions are exactly the roots of successive derivatives of Legendre Polynomials, which are: \n\n\\begin{center}\n  \\fbox{$P_n' = \\frac{1}{2^n n!}\\frac{d^{n+1}}{dx^{n+1}}((x^2 - 1 )^n)$}\n\\end{center}\n%%Id\u00e9alement, il faudait ajouter un graphique qui compare les racines et les les polynomes de legendre et de m\u00eame concernant l'\u00e9tude de minimum et maximum", "meta": {"hexsha": "76a0cebda4b1962c6ede4fad90466c2452af95c0", "size": 1915, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-non-linear-systems-newton-raphson/doc/electrostatic_equilibrium.tex", "max_stars_repo_name": "gdzx/numerical-algorithms", "max_stars_repo_head_hexsha": "1bdea5c70a5bb8fd589f95e73ed476b90693fcf0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4-non-linear-systems-newton-raphson/doc/electrostatic_equilibrium.tex", "max_issues_repo_name": "gdzx/numerical-algorithms", "max_issues_repo_head_hexsha": "1bdea5c70a5bb8fd589f95e73ed476b90693fcf0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4-non-linear-systems-newton-raphson/doc/electrostatic_equilibrium.tex", "max_forks_repo_name": "gdzx/numerical-algorithms", "max_forks_repo_head_hexsha": "1bdea5c70a5bb8fd589f95e73ed476b90693fcf0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.1944444444, "max_line_length": 245, "alphanum_fraction": 0.6067885117, "num_tokens": 640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.8146571730178249}}
{"text": "\\section{Exercises}\n\\begin{enumerate}\n  \\item Write the following sets explicitly:\n    \\begin{enumerate}[label=(\\roman*)]\n      \\item $\\left\\{ x\\in \\mathbb{N}\\mid1<x\\leq7\\right\\}$\n      \\item $\\left\\{ x\\in \\mathbb{Z}\\mid x<5\\right\\}$\n      \\item $\\left\\{ x\\in \\mathbb{R}\\mid x^{2}=-1 \\right\\}$\n      \\item $\\left\\{ x\\in \\mathbb{N} \\wedge x\\in \\mathbb{Q} \\right\\}$\n      \\item $\\left\\{ x\\in \\mathbb{R} \\mid x^{2}-3x-4=0 \\right\\}$\n      \\item $\\left\\{ x\\in\\mathbb{R}\\mid x<5\\wedge x \\geq 2\\right\\}$\n    \\end{enumerate}\n  \n\t\\item Determine the relation between the sets:\n    \\begin{enumerate}[label=(\\roman*)]\n      \\item $A=\\left\\{ 1,\\ 2,\\ 3\\right\\},\\ B=\\left\\{ 1,\\ 2 \\right\\}$\n      \\item $A=\\varnothing,\\ B=\\left\\{ 2,\\ -5,\\ \\pi \\right\\}$\n      \\item $A=\\mathbb{Z},\\ B=\\left\\{ \\pm x \\mid x\\in\\mathbb{N} \\cup \\right\\{0\\left\\} \\right\\}$\n\t\t\t\\item $A=\\left\\{\\pi, \\eu, \\sqrt{2}\\right\\},\\ B=\\mathbb{Q}$\n    \\end{enumerate}\n\n\t\\item Write all elements in $S^{2}\\times W$, where $S=\\{\\alpha,\\beta,\\gamma\\}$ and $W=\\{x,y,z\\}$. Find a condition that guarantees $S^{2}\\times W = W\\times S^{2}$.\n\n\t\\item How many different injective functions $f:\\{1,2\\}\\to\\{1,2\\}$ exist? How many injective functions $f:\\{1,2,3\\}\\to\\{1,2,3\\}$ exist? How many inject functions $f:\\{1,2,\\dots,n\\}\\to\\{1,2,\\dots,n\\}$ exist for a given $n\\in\\mathbb{N}$?\n\n\t\\item For each of the real functions below, find a set on which it is surjective (use a graphing calculator if you are not familiar with the shape of a function):\n\t\t\\[\n\t\t\tx^{2},\\ x^{3}-5,\\ \\eu^{-x^{2}/2},\\ \\sin(x),\\ \\sin(x)+\\cos(x),\\ x\\eu^{x}.\n\t\t\\]\n\n\t\\item Given two sets $A,B$ such that $|B|=|A|-1$, can a bijective function $f:A\\to B$ exist? Explain your answer.\n\t\\item MORE EXERCISES TO BE WRITTEN\\ldots\n\\end{enumerate}\n", "meta": {"hexsha": "1da7df13434aa0fd433ea72e892443c4b855712a", "size": 1745, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/intro/exercises.tex", "max_stars_repo_name": "JASory/maths_book", "max_stars_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-25T20:02:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T17:57:59.000Z", "max_issues_repo_path": "chapters/intro/exercises.tex", "max_issues_repo_name": "JASory/maths_book", "max_issues_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2022-01-17T05:01:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-20T06:18:24.000Z", "max_forks_repo_path": "chapters/intro/exercises.tex", "max_forks_repo_name": "JASory/maths_book", "max_forks_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2022-01-17T10:15:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-02T10:45:13.000Z", "avg_line_length": 52.8787878788, "max_line_length": 236, "alphanum_fraction": 0.5959885387, "num_tokens": 697, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898229217591, "lm_q2_score": 0.8991213705121083, "lm_q1q2_score": 0.8145948112554343}}
{"text": "\\documentclass[12pt]{scrartcl}\n\n\\input{preamble}\n\n\\makeatletter\n\\title{Hack 6.0}\\let\\Title\\@title\n\\subtitle{Computer Science I -- Java\\\\\n{\\small\n\\vskip1cm\nDepartment of Computer Science \\& Engineering \\\\\nUniversity of Nebraska--Lincoln}\n\\vskip-1cm}\n%\\author{Dr.\\ Chris Bourke}\n\\date{~}\n\\makeatother\n\n\\begin{document}\n\n\\maketitle\n\n\\hrule\n\n\\input{instructions.tex}\n\n\\section*{Problem Statement}\n\nIn this hack you'll get some more practice writing methods\n, error handling and enumerated types.  There are several different\nways to model colors including RGB and CMYK.  RGB is generally used in displays\nand models a color with three values in the range $[0, 255]$ corresponding to \nthe red, green and blue ``contribution'' to the color.  For example, the\ntriple $(255, 255, 0)$ corresponds to a full red and green (additive) value\nwhich results in yellow.  CMYK or Cyan-Magenta-Yellow-Black is a model used\nin printing where four colors of ink are combined to make various colors.\nIn this system, the four values are on the scale $[0, 1]$.  Write \nfunctions to convert between these models.\n\n\\begin{enumerate}\n\\item Write a function to convert from an RGB color model to CMYK.  To \nconvert to CMYK, you first need to scale each integer value to the range \n$[0, 1]$ by simply computing\n\t$$r' = \\frac{r}{255}, \\quad g' = \\frac{g}{255}, \\quad b' = \\frac{b}{255}$$\n\tand then using the following formulas:\n\\begin{align*}\nk & = 1-\\max\\{r', g', b'\\} \\\\\nc & = \\frac{(1-r'-k)}{(1-k)} \\\\\nm & = \\frac{(1-g'-k)}{(1-k)} \\\\\ny & = \\frac{(1-b'-k)}{(1-k)} \\\\\n\\end{align*}\nYour method should have the following signature:\n\n\\mintinline{java}{public static CMYK rgbToCMYK(RGB color)}\n\nNote that one edge case is black, when $(r,g,b) = (0,0,0)$ which would lead to a \ndivision by zero in the formulas.  The equivalent CMYK values are $(0,0,0,1)$.\n\n\n\\item Write a function to convert from CMYK to RGB using the following formulas.\n\\begin{align*}\nr & = 255 \\cdot (1 - c) \\cdot (1-k) \\\\\ng & = 255 \\cdot (1 - m) \\cdot (1-k) \\\\\nb & = 255 \\cdot (1 - y) \\cdot (1-k) \\\\\n\\end{align*}\nResults should be rounded.  Your method should have the following signature:\n\n\\mintinline{java}{public static RGB cmykToRGB(CMYK color)}\n\n\\end{enumerate}\n\nThe \\mintinline{java}{RGB} and \\mintinline{java}{CMYK} classes have \nbeen provided for you.  See the \\mintinline{java}{main} method of \neach class for examples on how to create and use \\emph{instances} \nof each class.\n\nPlace both methods in a source file named \\mintinline{text}{ColorUtils.java}\nin the package \\mintinline{java}{unl.cse}.  For both methods, identify any and \nall error conditions and throw an \\mintinline{java}{IllegalArgumentException} \nwith an appropriate error message.\n\n\n\\section*{Instructions}\n\n\\begin{itemize}\n  \\item You are encouraged to collaborate any number of students \n  before, during, and after your scheduled hack session.  \n  \\item Design at least 3 test cases for each function\n  \\emph{before} you begin\n  designing or implementing your program.  Test cases are \n  input-output pairs that are known to be correct using means\n  other than your program.\n  \\item You may (in fact are encouraged) to define any additional\n  ``helper'' functions that you find useful.\n  \\item Include the name(s) of everyone who worked together on\n  this activity in your source file's header.\n\n  \\item A testing file, \\mintinline{text}{ColorUtilsTests.java} has been \n  provided that uses JUnit (\\url{https://junit.org/junit5/}), a unit testing \n  framework for Java.  We have already written several test cases \n  for you.  Using these examples, implement your test cases using JUnit\n  for your two functions.  You should add at least 3 test methods.\n\n  The starter file should be sufficient to demonstrate how to use\n  JUnit, but the full documentation can be found here: \n  \\url{https://junit.org/junit5/docs/current/api/}.\n  A \\mintinline{text}{readme.me} file has also been provided describing\n  how to add JUnit to your Eclipse project.   \n  \n  \\item Turn in all of your files via webhandin, making sure that \n  it runs and executes correctly in the webgrader.  Each individual \n  student will need to hand in their own copy and will receive \n  their own individual grade.\n\\end{itemize}  \n\n\n\\end{document}\n", "meta": {"hexsha": "4e369305ca00569b7615d172de0c1dd89e926240", "size": 4233, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "honors/hacks/hack6.0.tex", "max_stars_repo_name": "bobbys131/ComputerScienceI", "max_stars_repo_head_hexsha": "93e22289e966386f208c477ee319837877bbe62a", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 68, "max_stars_repo_stars_event_min_datetime": "2018-05-14T20:29:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T10:05:16.000Z", "max_issues_repo_path": "honors/hacks/hack6.0.tex", "max_issues_repo_name": "hrithik125/ComputerScienceI", "max_issues_repo_head_hexsha": "40be47f15817a50497f6c6f7cdca9ee1db429b00", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-05-11T01:30:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-02T04:34:10.000Z", "max_forks_repo_path": "honors/hacks/hack6.0.tex", "max_forks_repo_name": "hrithik125/ComputerScienceI", "max_forks_repo_head_hexsha": "40be47f15817a50497f6c6f7cdca9ee1db429b00", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 204, "max_forks_repo_forks_event_min_datetime": "2018-10-17T18:35:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T16:51:50.000Z", "avg_line_length": 36.4913793103, "max_line_length": 81, "alphanum_fraction": 0.7278525868, "num_tokens": 1178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.8976952818435994, "lm_q1q2_score": 0.814489898024593}}
{"text": "\\lab{Importance Sampling and Monte Carlo Simulations}{Importance Sampling and Monte Carlo Simulations}\n\\objective{Use importance sampling to reduce the error and variance of Monte Carlo Simulations.}\n\\label{lab:montecarlo2}\n\n\\section*{Introduction} % =====================================================\n\nThe traditional methods of Monte Carlo integration as discussed in the previous lab are not always the most efficient means to estimate an integral. For example, assume we were trying to find the probability that a randomly chosen variable $X$ from the standard normal distribution is greater than $3$. We know that one way to solve this is by solving the following integral:\n\n\\begin{equation} \\label{eq:integral}\nP(X > 3) = \\int_{3}^{\\infty} f_X(t)\\,dt = \\frac{1}{\\sqrt{2\\pi}}\\int_{3}^{\\infty} e^{-t^2/2}\\,dt\n\\end{equation}\n\nIf we define the function $h: \\mathbb{R} \\rightarrow \\mathbb{R}$ as\n\n$$h(t) = \\begin{cases}\n1 & \\text{ if } t > 3 \\\\\n0 & \\text{ if } t \\leq 3\n\\end{cases}, $$\nwe can rewrite this integral as\n\n\\begin{equation*}\n\\int_{3}^{\\infty} f_X(t)\\,dt = \\int_{-\\infty}^{\\infty} h(t)f_X(t)\\,dt.\n\\end{equation*}\n\nBy the Law of the Unconscious Statistician (see Volume 2 \\S 3.5), we can restate the integral above as\n\n$$\\int_{-\\infty}^{\\infty} h(t)f_X(t)\\,dt = E[h(X)].$$\nBeing able to write integrals as expected values is an essential tool in this lab.\n\n\\section*{Monte Carlo Simulation} % ===========================================\n\nIn the last section, we expressed the probability of drawing a number greater than $3$ from the normal distribution as an expected value problem. We can now easily estimate this same probabilty using Monte Carlo simulation.\nGiven a random i.i.d. sample $x_1, x_2, \\cdots , x_N$ generated by $f_X$, we can estimate $E[h(X)]$ using\n\\begin{equation} \\label{eq:estimator}\n\\widehat{E}_n[h(X)] = \\frac{1}{N}\\sum_{i = 1}^{N}h(x_i)\n\\end{equation}\n\nNow that we have defined the estimator, it is now quite manageable to approximate Equation \\ref{eq:integral}. By the Weak Law of Large Numbers (see Volume 2 \\S 3.6), the estimate will get closer and closer to the actual value as we use more and more sample points.\n\n\\begin{comment}\n\\begin{lstlisting}\n>>> h = lambda x : x > 3\n>>> N = 10**7\n>>> x = np.random.normal(size=N)\n>>> 1./N * np.sum(h(x))\n0.0013644\n\\end{lstlisting}\n\\end{comment}\n\n\\begin{problem} \\label{prob:mc}\nWrite a function in Python that estimates the probability that a random draw from the standard normal distribution is greater than 3 using Equation \\ref{eq:estimator}. Your function should accept a parameter \\li{n} for the number of samples to use in your approximation. Your answer should approach $0.0013499$ for sufficiently large samples.\n\\end{problem}\n\nThough this approach gets the job done, it turns out that this isn't very efficient. Since the probability of drawing a number greater than $3$ from the standard normal distribution is so unlikely, it turns out we need many sample points to get a good approximation.\n\n\\section*{Importance Sampling} % ==============================================\n\nImportance sampling is one way to make Monte Carlo simulations converge much faster. We choose a different distribution to sample our points to generate more \\emph{important} points. With our example, we want to choose a distribution that would generate more numbers around $3$ to get a more reliable estimate. The theory behind importance sampling boils down to the following result. In these equations, the random variable $X$ is generated by $f_X$ and the random variable $Y$ is generated by $g_Y$. We will refer to $X$ and $Y$ in this way for the remainder of the lab.\n\n\\begin{equation} \\label{eq:importance}\n\\begin{split}\nE[h(X)] & = \\int_{-\\infty}^{\\infty} h(t)f_X(t)\\,dt \\\\\n& = \\int_{-\\infty}^{\\infty} h(t)f_X(t)\\left ( \\frac{g_Y(t)}{g_Y(t)} \\right )\\,dt \\\\\n& = \\int_{-\\infty}^{\\infty} \\left ( \\frac{h(t)f_X(t)}{g_Y(t)} \\right )g_Y(t)\\,dt \\\\\n& = E\\left [ \\frac{h(Y)f_X(Y)}{g_Y(Y)}\\right ]\n\\end{split}\n\\end{equation}\n\nThe corresponding estimator is\n\n\\begin{equation}\\label{eq:imp_estimator}\n\\begin{split}\n\\widehat{E}[h(X)] & = \\widehat{E}\\left [ \\frac{h(Y)f_X(Y)}{g_Y(Y)}\\right ] \\\\\n& = \\frac{1}{N}\\sum_{i = 1}^{N}\\frac{h(y_i)f_X(y_i)}{g_Y(y_i)}\n\\end{split}\n\\end{equation}\n\nThe function $f_X$ is the p.d.f. of the \\emph{target distribution}. The function $g_Y$ is the p.d.f. of the \\emph{importance distribution}. The fraction $\\frac{f_X(X)}{g_Y(X)}$ is called the \\emph{importance weight}. This allows us to draw a sample from any distribution with p.d.f. $g_Y$ as long as we multiply $h(X)$ by the importance weight.\n\n\\subsection*{Choosing the Importance Distribution} % --------------------------\n\nThere is no correct choice for the importance distribution. It may be possible to find the distribution that allows the simulation to converge the fastest, but oftentimes, we don't need a perfect answer. Close to perfect is good enough.\n\nWe will solve the same problem as in Problem \\ref{prob:mc} using importance sampling. We will choose $g_Y$ to be the normal distribution with $\\mu = 4$ and $\\sigma = 1$.\nWe have chosen this distribution for $g_Y$ because it will give us more points closer to and greater than 3. Note that it is not necessary to choose an importance distribution of the same type.\n\n\\begin{figure}[H]\n% MISSING FIGURE!!\n% \\includegraphics[width=\\textwidth]{importance_distribution.pdf}\n\\caption{In our problem, we choose an importance distribution that will generate more samples that are greater than 3. Though not a perfect choice, choosing a normal distribution with $\\mu = 4$ and $\\sigma = 1$ will suffice.}\n\\label{fig:importance}\n\\end{figure}\n\n\\begin{lstlisting}\n>>> from scipy import stats\n>>> h = lambda x : x > 3\n>>> f = lambda x : stats.norm().pdf(x)\n>>> g = lambda x : stats.norm(loc=4,scale=1).pdf(x)\n\n# Sample from the N(4,1).\n>>> N = 10**7\n>>> X = np.random.normal(4,scale=1,size=N)\n\n# Calculate estimate.\n>>> 1./N * np.sum(h(X)*f(X)/g(X))\n0.00134921134631\n\\end{lstlisting}\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{figures/MCvsIS.png}\n\\caption{Comparison of error between standard method Monte Carlo and Importance Sampling method of Monte Carlo.}\n\\label{fig:compare}\n\\end{figure}\n\n\\begin{problem} \\label{prob:gamma}\nA tech support hotline receives an average of 2 calls per minute. What is the probability that they will have to wait at least 10 minutes to receive 9 calls? Implement your estimator using importance sampling. Calculate estimates using 5000, 10000, 15000, $\\cdots$, 500000 sample points. Return an array of estimates. Your answers should approach $0.00208726$.\n\nHint: In Volume 2 \\S 3.5, the gamma distribution is defined as, $$f_X(x) = \\frac{b^{a}x^{a-1}e^{-xb}}{\\Gamma(a)}.$$ The version of the gamma distribution in \\li{scipy.stats} is determined by the shape ($a$) and the scale ($\\theta$) of the distribution. $$f_X(x) = \\frac{x^{a-1}e^{-x/\\theta}}{\\Gamma(a)\\theta^a}$$\nYou can switch between these representations this with the fact that $\\theta = 1/b$.\n\\end{problem}\n\n\\begin{problem}\nIn this problem, we will visualize the benefits of importance sampling. Create a plot of the error of the traditional methods of Monte Carlo integration and the importance sampling methods of Monte Carlo for Problem \\ref{prob:gamma}. What do you observe? Your plot should resemble Figure \\ref{fig:compare}.\n\nHint: The following code solves Problem \\ref{prob:gamma} using traditional methods of Monte Carlo integration:\n\\begin{lstlisting}\nh = lambda x : x > 10\nMC_estimates = []\nfor N in xrange(5000,505000,5000):\n    X = np.random.gamma(9,scale=0.5,size=N)\n    MC = 1./N*np.sum(h(X))\n    MC_estimates.append(MC)\nMC_estimates = np.array(MC_estimates)\n\\end{lstlisting}\n\nHint: To determine the error of your approximations, the following code returns the actual value of the probability:\n\\begin{lstlisting}\n1 - stats.gamma(a=9,scale=0.5).cdf(10)\n\\end{lstlisting}\n\\end{problem}\n\nNow that we have visualized the benefits of importance sampling, note that we can achieve the same results as traditional Monte Carlo with a fraction of the samples.\n\n\\section*{Generalizing the Principles of Importance Sampling} % ===============\n\nThe examples we have explored to this point in the lab were merely educational. Since we have a simple means of calculating the correct answer to Problem \\ref{prob:gamma}, it doesn't make much sense to use methods of Monte Carlo in this situation. However, as discussed in the previous lab, there are not always closed-form solutions to the integrals we want to compute.\n\nWe can extend the same principles we have discussed thus far to solve many types of problems. For a more general problem, we can implement importance sampling by doing the following:\n\\begin{enumerate}\n\\item Define a function $h$ where, $h(t) = \\begin{cases}\n1 & \\text{ if condition is met }  \\\\\n0 & \\text{ otherwise}\n\\end{cases} $.\n\\item Define a function $f_X$ which is the p.d.f. of the target distribution.\n\\item Define a function $g_Y$ which is the p.d.f. of the importance distribution.\n\\item Use these functions in conjunction with Equation (\\ref{eq:imp_estimator}).\n\\end{enumerate}\n\n\\begin{problem}\nThe joint normal distribution of $N$ independent random variables with mean 0 and variance 1 is\n\\[\nf_X(\\x) = \\frac{1}{\\sqrt{(2 \\pi)^N}} e^{-(\\x^T\\x)/2}.\n\\]\nThe integral of $f_X(\\x)$ over a box is the probability that a draw from the distribution will be in the box.\nHowever, $f_X(\\x)$ does not have a symbolic antiderivative.\n\n\\begin{comment}\n\\item The integral of this function on $B = [-1,1]\\times [-1,1]\\times[-1,1] \\subset \\mathbb{R}^3$ can be computed in SciPy with the following code.\n\\begin{lstlisting}\n>>> import scipy.stats as stats\n\n# Define the bounds of the box to integrate over\n>>> mins = np.array([-1, -1, -1])\n>>> maxs = np.array([1, 1, 1])\n\n# Each variable has mean 0\n>>> means = np.zeros(3)\n\n# The covariance matrix of N independent random variables\n#    is the NxN identity matrix.\n>>> covs = np.eye(3)\n\n# Compute the integral\n>>> value, inform = stats.mvn.mvnun(mins, maxs, means, covs)\n\\end{lstlisting}\nThen \\li{value} is the integral of $f(\\x)$ on $B$.\nUse SciPy to integrate $f(\\x)$ on $\\Omega=[-0.5, 0.75]\\times[0,1]\\times[0, 0.5]\\times[0,1] \\subset \\mathbb{R}^4$.\n\\end{comment}\n\nUse what you have learned about importance sampling to estimate the probability that a given random variable in $\\mathbb{R}^2$ generated by $f_X$ will be less than -1 in the x-direction and greater than 1 in the y-direction.\n\nTreat $f_X$ as the p.d.f. of your target distribution.\nUse the function \\li{stats.multivariate_normal} to create a multivariate normal distribution to serve as your importance distribution.\nFor more information on how to use this function, consult the documentation for\n\\li{stats.multivariate_normal}.\n\\end{problem}\n\n\\section*{Unnormalized Target Densities} % ====================================\n\nThe methods discussed so far are only applicable if the target density is normalized, or in other words, has an integral of 1. If the target density is not normalized, Equation \\ref{eq:importance} becomes\n\n\\begin{equation*} \\label{eq:unnormalized}\n\\begin{split}\nE[h(X)] & = \\frac{\\int h(t)f(t)\\,dt}{\\int f(t)\\,dt} \\\\\n& = \\frac{\\int h(t)f(t) \\left ( \\frac{g_Y(t)}{g_Y(t)} \\right )\\,dt}{{\\int f(t)} \\left ( \\frac{g_Y(t)}{g_Y(t)} \\right )\\,dt} \\\\\n& = \\frac{\\int \\left ( \\frac{h(t)f(t)}{g_Y(t)} \\right ) g_Y(t)\\,dt}{\\int \\left ( \\frac{f(t)}{g_Y(t)} \\right ) g_Y(t)\\,dt} \\\\\n& = \\frac{E\\left [ \\frac{h(Y)f(Y)}{g_Y(Y)}\\right ]}{E\\left [ \\frac{f(Y)}{g_Y(Y)}\\right ]}\n\\end{split}\n\\end{equation*}\n\nThe corresponding estimator becomes\n\\begin{equation*}\n\\begin{split}\n\\widehat{E}_n[h(X)] & = \\frac{\\widehat{E}\\left [ \\frac{h(Y)f(Y)}{g_Y(Y)}\\right ]}{\\widehat{E}\\left [ \\frac{f(Y)}{g_Y(Y)}\\right ]} \\\\\n& = \\frac{\\frac{1}{N}\\sum_{i = 1}^{N}\\frac{h(y_i)f(y_i)}{g_Y(y_i)}}{\\frac{1}{N}\\sum_{i = 1}^{N}\\frac{f(y_i)}{g_Y(y_i)}} \\\\\n\\end{split}\n\\end{equation*}\n", "meta": {"hexsha": "9b926dc091be7b8b19944735f8ba47296c7b8072", "size": 11900, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1B/MonteCarlo2-Sampling/MonteCarlo2.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol1B/MonteCarlo2-Sampling/MonteCarlo2.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol1B/MonteCarlo2-Sampling/MonteCarlo2.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 54.5871559633, "max_line_length": 572, "alphanum_fraction": 0.7074789916, "num_tokens": 3427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.9196425317283919, "lm_q1q2_score": 0.814464370760505}}
{"text": "In this chapter, we will discuss a number of activation functions.  We\nsay an activation function $\\alpha$ \nsatisfies the basic activated-approximation-property (AAP) if for any $g\\in C^1[-1,1]$, we have\n\\begin{equation}\n\\label{AAP}\n\\min_{a_i,b_i,c,w_i\\in\\mathbb R^1}\\max_{t\\in[-1,1]}\\bigg|g(t)-\\sum_{i=1}^k(a_i\\alpha(w_it+b_i)-c\\bigg|\n\\le \\frac{C}{k}\\max_{t\\in[-1,1]}|g'(t)|\n\\end{equation}\nfor some constant $C$ independent of $k$ and $g$. \n\n\\section{Cardinal B-splines}\nThe {\\it cardinal B-splines} are given by the following recurrent\nrelationship\n\\begin{equation}\n  \\label{cardinal}\nM_d(x)=\\frac{x}{d}M_{d-1}(x)  + \\frac{d+1-x}{d}M_{d-1}(x-1)  \n\\end{equation}\n\\subsection{$d=0$}\n\\begin{equation}\n  \\label{cardinal}\nM_0(x)=\n\\left\\{\n  \\begin{array}{ll}\n0 & x<0 \\\\\n1 & 0\\le x<1    \\\\\n0 & x > 1    \n  \\end{array}\n\\right.\n\\end{equation}\nThe Heaviside function is defined by\n\\begin{equation}\n  \\label{a0}\n\\alpha_0(x)=\n\\left\\{\n  \\begin{array}{ll}\n0 & x<0; \\\\\n1 & x \\ge 1.\n  \\end{array}\n\\right.\n\\end{equation}\n\\begin{lemma}\n  \\begin{equation}\n  \\label{a0M0}\n\\alpha_0(x)=\\sum_{j=0}^\\infty M_0(x-j)    \n  \\end{equation}\n  \\begin{equation}\n  \\label{M0a0}\nM_0(x)=\\alpha_0(x)-\\alpha_0(x-1).\n  \\end{equation}\n\\end{lemma}\n\n\\subsection{$d=1$}\n\\begin{equation}\n  \\label{M1M0}\nM_1(x)=xM_0(x)+(2-x)M_0(x-1)  \n\\end{equation}\nWe note that\n\\begin{equation}\n  \\label{M1}\nM_1(x)= \n\\left\\{\n\\begin{array}{cl}\n0 & x<0; \\\\\nx & 0\\le x < 1\\\\\n2-x & 1\\le x \\le 2\\\\\n0 & x>2.\n  \\end{array}\n\\right.\n\\end{equation}\nWe define (see Fig. \\ref{alpha1})\n\\begin{equation}\n  \\label{a1}\n\\alpha_1(x)= \n\\left\\{\n\\begin{array}{cl}\nM_1(x) &  x < 1\\\\\n1 & x\\ge 1\n  \\end{array}\n\\right.\n\\end{equation}\n\\begin{figure}[!htb]\n\t\\center{\\includegraphics[width=10cm] {figures/alpha1.png}}        \n\t\\caption{The activation $\\alpha_1$}      \n\t\\label{alpha1}\n\\end{figure}\n \n\n\\begin{lemma}\n  \\begin{equation}\n    \\label{a1a0}\n\\alpha_1(x)=x\\alpha_0(x)+(1-x)\\alpha_0(x-1).    \n  \\end{equation}\n\\end{lemma}\n\n\\begin{lemma}\n  \\begin{equation}\n  \\label{a1M1}\n\\alpha_1(x)=\\sum_{j=0}^\\infty M_1(x-j)    \n  \\end{equation}\n\\end{lemma}\n\n\\begin{lemma}\n  \\begin{equation}\n    \\label{M1a1}\nM_1(x)=\\alpha_1(x)-\\alpha_1(x-1). \n  \\end{equation}\n\\end{lemma}\nConsider the following\n$$\n\\alpha_1(x)-\\alpha_1(2x-1). \n$$\nWe note that the so-called ReLU is defined as follows:\n\\begin{equation}\n  \\label{ReLU}\nReLU(x)= \n\\left\\{\n\\begin{array}{cl}\n0 & x<0; \\\\\nx & x\\ge 0\n  \\end{array}\n\\right.\n\\end{equation}\nand\n\\begin{equation}\n\\alpha_1(x)=ReLU(x)-ReLU(x-1).\n\\end{equation}\n\n\\begin{equation}\n\\alpha_1({1 \\over h_1} x) - \\alpha_1({1 \\over h_2} (x - h_1) )\n\\end{equation}\n\n\n\n\n\\newpage\n\\subsection{$d=2$}\n\\begin{equation}\n  \\label{M2}\nM_2(x)=\\frac{x}{2}M_{1}(x)  + \\frac{3-x}{2}M_{1}(x-1)   \n\\end{equation}\nNote that\n$$\nM_2(0)=0, M_2(1)={1\\over 2}, M_2({3\\over2})={3\\over 4},\nM_2(2)={1\\over2}, M_2(3)=0.\n$$\nNow we define\n\\begin{equation}\n  \\label{a2}\n\\alpha_2(x)= \n\\left\\{\n\\begin{array}{cl}\n{4\\over3}M_2(x) &  x < {3\\over 2}\\\\\n1 & x\\ge {3\\over2}\n  \\end{array}\n\\right.\n\\end{equation} \nNote that\n$$\n\\alpha_2(0)=0, \\alpha_2(1)={1\\over 3}, \\alpha_2({3\\over2})=\\alpha_2(2)=\\alpha_2(3)=1.\n$$\n\\begin{lemma}\n \\begin{equation}\n    \\label{M2a2}\nM_2(x)={3\\over 2}(\\alpha_2(x)-\\alpha_2(x-1)).\n  \\end{equation}  \n\\end{lemma}\n\\begin{proof}\n We need to check some details ...\n\\end{proof}\n\n\\subsection{$d=3$}\nThe presentation below follows the file lect-spline.pdf found in the following web page\n\\begin{verbatim}\nhttps://www.geos.ed.ac.uk/~yliu23/docs/lect_spline.pdf\n\\end{verbatim}\nTake $x_0=0$ and $h=1$, we get\n$$\nB_0(x)=\n\\left\\{\n  \\begin{array}{ll}\n0 & x\\le -2\\\\\n\\\\\n{1\\over 6}(2+x)^3 & -2\\le x\\le -1\\\\ \n\\\\\n{2\\over 3}-{1\\over2}x^2(2+x) & -1\\le x\\le 0\\\\  \n\\\\\n{2\\over 3}-{1\\over2}x^2(2-x) & 0\\le x\\le 1\\\\  \n\\\\\n{1\\over 6}(2-x)^3 & 1\\le x\\le 2\\\\ \n\\\\\n 0 & x\\ge 2.    \n  \\end{array}\n\\right.\n$$\nLet \n$$\nB_k(x)=B_0(x-k)\n$$\nA cubic spline function in $[0,N]$ can be written as\n$$\nS(x)=\\sum_{k=-1}^{N+1}a_kB_0(x-k).\n$$\nThe following identity holds:\n\\begin{equation}\n  \\label{eq:1}\n\\sum_{k=-1}^{N+1}B_0(x-k) =1, \\quad\\forall x\\in [0,N]\n\\end{equation}\nWe propose the following activation function\n$$\n\\sigma(x)=\n\\left\\{\n  \\begin{array}{ll}\nB_1(x) & x\\le 1 \\\\\n1 & x\\ge 1    \n  \\end{array}\n\\right.\n$$\n\n\n\\section{Approximation properties}\nWe consider an interval $I =(0,1)$ and a partition\n\\begin{equation}\n  \\label{1d-partition}\n-1=t_0  < t_1<\\ldots<t_k=1.\n\\end{equation}\nAs a special case of uniform partition, we take\n\\begin{equation}\n\\label{tk}\nt_i=t_0+ih, I_i=(t_{i-1}, t_i)\\quad i=1:k, h={2\\over k}.  \n\\end{equation}\nConsider the basis function \n$$\nM_{0,i}(t)=M_0(\\frac{t-t_{i-1}}{h}).\n$$\nGiven \n$$\nv: (-1,1)\\mapsto \\mathbb R^1\n$$\nThe interpolation is defined as\n\\begin{equation}\n  \\label{interp0}\n(\\Pi_0v)(t) =\\sum_{i=1}^kv_iM_{0,i}(t)\n=v_1+\\sum_{i=2}^k(v_i-v_1)M_{0,i}(t)\n\\end{equation}\nwith \n$$ \nv_i={1\\over h}\\int_{I_i}v(t).\n$$\nBy \\eqref{M0a0}, we have\n\\begin{eqnarray}\n(\\Pi_0v)(t)\n&=&v_1+\\sum_{i=2}^k(v_i-v_1)(\\alpha_{0}(\\frac{t-t_{i-1}}{h})-\\alpha_{1}(\\frac{t-t_{i}}{h}))\\\\\n&=&v_1+\\sum_{i=2}^k(v_i-v_1)(\\alpha_{0}(\\frac{t-t_{i-1}}{h})-\\alpha_{0}(\\frac{t-t_{i}}{h}))\\\\\n&=&v_1+\\sum_{i=1}^{k-1}(v_{i+1}-v_1)\\alpha_{0}(\\frac{t-t_{i}}{h})-\n\\sum_{i=2}^k(v_i-v_1)\\alpha_{0}(\\frac{t-t_{i}}{h})\\\\\n&=&v_1+\\sum_{i=1}^{k}(v_{i+1}-v_i)\\alpha_{0}(\\frac{t-t_{i}}{h}).\n\\end{eqnarray}\nwith \n$$\nv_{k+1}=v_{1}.\n$$\n\\begin{theorem}\n  \\label{M0-error}\n  \\begin{equation}\n  \\label{Pi0-error}\n\\|v-\\Pi_0v\\|_{0,\\infty}\\le \\frac{c_0}{k}\\|v'\\|_{0,\\infty}\n\\end{equation}\n\\end{theorem}\n\\begin{proof}\nEasy.   \n\\end{proof}\nIn general, we consider the following space of Splines:\n\\begin{theorem}  \\label{Md-error}\n\n\\subsection{General $d$}\nLet $S^{d,k}$ be the spline space generated by the B-spline $M_d$ from\nthe partition \\eqref{1d-partition}, we have\n  \\begin{equation}\n  \\label{Pid-error}\n\\|v-\\Pi_{d,k}v\\|_{0,\\infty}\\le \\frac{c_d}{k^r}\\|v^{(r)}\\|_{0,\\infty},\n\\quad 1\\le r\\le d+1.\n\\end{equation}\n\\end{theorem}\n\\begin{proof}\n\tYou can find this proof in \\cite{de1978practical} in theorem $XII.3$ in page 176.\nIt needs to be checked.  Li Lin might know where a proof can be found\nin the literature. \n\\end{proof}\n\n\\subsection{Sigmoidal function}\nThe so-called sigmoidal function is defined as follows:\n\\begin{equation}\n  \\label{sigmoidal}\n\\sigma(t) = \\frac{1}{1 + e^{-t}}.  \n\\end{equation}\nThis popular activation provides a smooth approximation of the Heaviside function $\\alpha_0$ as follows:\n\\begin{equation}\n  \\label{sig}\n\\lim_{a\\to \\infty}\\sigma(at) = \\alpha_0(t), \\quad t\\neq 0.\n\\end{equation}\nFor $t>0$\n$$\n\\alpha_0(t)- \\sigma(at)\n=1-\\frac{1}{1+e^{-at}}\\le e^{-at}.\n$$\nFor $t<0$\n$$\n\\sigma(at)-\\alpha_0(t)\n=\\frac{1}{1+e^{-at}}\\le e^{-a|t|}.\n$$\nWe have in general \n$$\n|\\sigma(at)-\\alpha_0(t)|\n\\le e^{-a|t|}.\n$$\nWe consider the following interpolation \n\\begin{equation}\n  \\label{interp0-1}\nv(t)=v_1+\\sum_{i=1}  (v_i-v_1)\n\\end{equation}\n\n\n\n%\\newpage\n\\section{Special activation functions}\n\n        \\begin{itemize}\n\t\\item An general activation function(must be nonlinear) is \n$$\\sigma: \\mathbb{R} \\to  \\mathbb{R}.$$\n\n\\item The Heaviside function is \n$$\nH(x ) = \\begin{cases}\n0 \\quad &\\text{if} ~ x \\le 0, \\\\\n1 \\quad &\\text{if} ~ x > 0.\n\\end{cases}\n$$\nThe biggest problem for this activation function is that this function is not continuous which will cause \nhuge difficult in training phase.\n\n\\item The sigmoid function:\n$$s(x) = \\frac{1}{1 + e^{-x}}\n\\rightarrow \n\\begin{cases}\n0,~~x\\rightarrow -\\infty,\\\\\n1,~~x\\rightarrow +\\infty.\n\\end{cases}\n.\n$$\nThis function can be seen as the smooth approximation of Heaviside function.\nThis activation function was very popular in shallow neural network in about 1990s. Now, this\nactivation function is also often used in RNN or some NLP tasks.\n\n\n\\item Currently, the most used activation function in DNN  and CNN is ``Rectified Linear Unit'' (ReLU):\n$$\n{\\rm ReLU}(x) = \\max(0, x).\n$$\nThere are many interesting properties of ${\\rm ReLU}$ function:\n\\begin{enumerate}\n\t\\item ${\\rm ReLU}$ is a piecewise linear function. Thus, DNN with this activation \n\tfunction is always a piecewise linear function.\n\t\n\t\\item The connection of ${\\rm ReLU}$ and Heaviside.\n\t\\begin{equation}\n\t\\frac{d}{dx} {\\rm ReLU}(x) = H(x).\n\t\\end{equation}\n\t\n\t\\item Recently, there are huge research works about the approximation properties of DNN\n\twith ${\\rm ReLU}$ activation function see ~\\cite{he2018relu,wang2018exponential,yarotsky2017error}.\n\\end{enumerate}\n\t\n\t\\item The new activation function from ReLU is:\n\t$$\n\t\\tau(x) = r(x) - r(x-1) = \\begin{cases}\n\t0 \\quad &\\text{if} ~ x \\le 0, \\\\\n\tx \\quad &\\text{if} ~  0 < x \\le 1, \\\\\n\t1  \\quad &\\text{if} ~ x > 1.\n\t\\end{cases}\n\t$$\n        Here we need to note that, because $-r(x) \\neq r(ax + b)$, so\n        if we use $\\tau$ as $f_{out}$, the layers will be $J+1$ for\n        ReLU as activation function and $f_{out} = id$.\n\t\\end{itemize}\n\nHere is a simple diagram for a general DNN structure:\n\\begin{figure}[!h]\n\t\\center{\\includegraphics[width=12cm,height=6cm] {ANN.png}}\n\t\\caption{A General Structure of DNN}\n\\end{figure}\n\n", "meta": {"hexsha": "24c67842db6e233a2f9ae38cef237a583cdae64a", "size": 8948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Activation.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/Activation.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/Activation.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.8265306122, "max_line_length": 106, "alphanum_fraction": 0.6398077783, "num_tokens": 3695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.926303724190573, "lm_q2_score": 0.8791467643431002, "lm_q1q2_score": 0.8143569219211059}}
{"text": "% !TeX spellcheck = en_US\n\\subsection{Log encoding}\nThis encoding utilize the fact that each propositional variable can only take one of two values, i.e. either True or False.\n\n\\subsubsection{Encoding the variables}\nFirst we encode each possible value from the domain with a distinct binary representation. Depending on the maximum number of bits needed to encoded all the domain values, an equal number of propositional variables for each CSP variable is generated. So if the size of domain was $m$ and the number of CSP variables was $n$, we need $n \\lceil \\log_2 m \\rceil$ propositional variable on the SAT side.\n\nNotice that encoding each value from the CSP variable's domain means that the size of this domain must be exactly equal to $2^i$, which is not necessary the case. So extra possible binary representations can emerge (implied in the formula by the ceiling function, i.e. if $ \\lceil \\log_2 m \\rceil > \\log_2 m $). To avoid assigning these invalid values to any CSP variable we have to include extra clauses to ensure that a variable can't be assigned a value outside its domain. \n\nOn the other hand, unlike the direct encoding we do not need any additional clauses to ensure that each CSP variable is given a value at all (ALO clauses) nor to ensure that each CSP variable is given only one value (AMO clauses).\n\nThe same example from above is used to demonstrate the additional needed clauses. The CSP constraints are not listed explicitly but rather illustrated by the borders on the map.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.85\\linewidth]{assets/log_variables}\n\t\\captionsetup{justification=centering,margin=2cm}\n\t\\caption{Encoding CSP variables using log encoding}\n\t\\label{fig:log_variables}\n\\end{figure}\n\nNotice that the log encoding generates less propositional variables than direct encoding. Anyway, this fact does not improve the performance of DPLL on the generated SAT instance because more steps are required to untangle the problem as discussed later. \\ref{subsec:log_proposition}\n\n\\subsubsection{Encoding the constraints}\nAs discussed before, constraints could be unary, binary or n-ary. Since any n-ary constraint can be expanded to multiple binary constraints, the main focus will be on encoding only the unary and the binary constraints.\n\nEncoding unary constraints is straight forward. For example to ensure that a CSP variable $X$ can't be assigned a certain value from its domain encoded in the binary form $01$, we only need to add the following clause to the SAT formula: $\\neg (\\neg X_1 \\wedge X_0) \\equiv X_1 \\vee \\neg X_0$. Remember that the subscript of the propositional variables $X_0, X_1$ corresponds to the position of the bit in the binary form of the CSP value.\n\nEncoding binary constraints can be done in similar manner. For example to encode the CSP constraint $A \\neq D$, where $A$ and $D$ can be either green \\textcolor{green}{$\\blacksquare$} or blue \\textcolor{blue}{$\\blacksquare$} (i.e. their domain is $\\{ \\textcolor{green}{\\blacksquare}, \\textcolor{blue}{\\blacksquare} \\}$) with the binary representations \\textcolor{green}{$01$} and \\textcolor{blue}{$10$} respectively, we need to include the following clauses in our SAT:\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{assets/binary_constraints_log_encoding}\n\t\\captionsetup{justification=centering,margin=2cm}\n\t\\caption{Encoding binary CSP constraint using log encoding}\n\t\\label{fig:binary_constraints_log_encoding}\n\\end{figure}\n\n\\subsubsection{Proposition}\\label{subsec:log_proposition}\nIn spite of the fact that log encoding generate fewer variables on the SAT side than direct encoding, it is easy to see that DPLL applied on log encoded CSP is dominated by FC applied to the original CSP problem (assuming equivalent branching heuristics).\n\n\\subsubsection{Proof idea}\nThe proof idea is similar to the proof mentioned earlier for the direct encoding case \\ref{subsec:direct_encoding_proof}. We process by comparing the search trees of each algorithm. First we show that both trees must have at least equal number of branches. By Induction on each CSP variable $X$, FC algorithm will branch upon it. On the SAT side DPLL will consider all propositional variables corresponding to the same CSP variable ($X_i \\dots X_{\\lceil \\log_2 m \\rceil}$), where $m$ is the size of the domain.\n\nFurther more, we can exploit the natural logarithmic behavior of log encoding on the search tree to show that DPLL is \\textbf{strictly} dominated by FC. This can be done using a simple example. Consider a CSP consists of two variables $A$ and $B$ with domain of size 3 and no constraints other than rolling out all assignments. FC will require three branches for each variable to show that this problem is unsatisfiable. Since the size of the domain equals 3, we need at least two bits to represent each CSP variable. Therefore, DPLL must branch at least $2 * 2 * 2 = 8$ times to show that the problem is unsatisfiable (the first 2 represents for the number of variables, the second one for the number of bits, and the last one to indicate branching on each case True or False as discussed before).\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.85\\linewidth]{assets/log_dominated_by_fc}\n\t\\captionsetup{justification=centering,margin=2cm}\n\t\\caption{Seach trees of DPLL and FC for trivial CSP}\n\t\\label{fig:log_dominated_by_fc}\n\\end{figure}\n\n\n\n", "meta": {"hexsha": "0b499b387a83501ce24e139fa672491f5b839fbe", "size": 5386, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "log_encoding.tex", "max_stars_repo_name": "mazenbesher/csp_and_sat", "max_stars_repo_head_hexsha": "ba73dda02acc2ecfc66a66530e54e3940b82384d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "log_encoding.tex", "max_issues_repo_name": "mazenbesher/csp_and_sat", "max_issues_repo_head_hexsha": "ba73dda02acc2ecfc66a66530e54e3940b82384d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "log_encoding.tex", "max_forks_repo_name": "mazenbesher/csp_and_sat", "max_forks_repo_head_hexsha": "ba73dda02acc2ecfc66a66530e54e3940b82384d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 96.1785714286, "max_line_length": 798, "alphanum_fraction": 0.7898254734, "num_tokens": 1273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.8962513668985, "lm_q1q2_score": 0.8143500298966881}}
{"text": "\\section{Application: Markov matrices}\n\nThere are applications of great importance which feature a special type of matrix.  Matrices whose columns consist of non-negative numbers that sum to one are\ncalled \\textbf{Markov matrices}\\index{Markov matrices}. An important application of Markov matrices is\nin population migration, as illustrated in the following definition.\n\n\\begin{definition}{Migration matrices}{migration-matrix}\nLet $m$ locations be denoted by the numbers $1,2,\\ldots,m$. Suppose\nit is the case that each year the proportion of residents in location\n$j$ which move to location $i$ is $a_{ij}$. Also suppose no one\nescapes or emigrates from without these $m$ locations. This last\nassumption requires $\\sum_{i}a_{ij}=1$, and means that the matrix $A$,\nsuch that $A = \\mat{a_{ij} }$, is a Markov matrix. In this context,\n$A$ is also called a \\textbf{migration matrix}\\index{migration matrix}.\n\\end{definition}\n\nConsider the following example which demonstrates this situation.\n\n\\begin{example}{Migration matrix}{migration-matrix}\nLet $A$ be a Markov matrix given by\n\\begin{equation*}\nA =\n\\begin{mymatrix}{rr}\n0.4 & 0.2 \\\\\n0.6 & 0.8\n\\end{mymatrix}\n\\end{equation*}\nVerify that $A$ is a Markov matrix and describe the entries of $A$ in terms of population migration.\n\\end{example}\n\n\\begin{solution}\nThe columns of $A$ are comprised of non-negative numbers which sum to $1$. Hence, $A$ is a Markov matrix.\n\nNow, consider the entries $a_{ij}$ of $A$ in terms of population. The\nentry $a_{11} = 0.4$ is the proportion of residents in location one\nwhich stay in location one in a given time period.  Entry $a_{21} =\n0.6$ is the proportion of residents in location 1 which move to\nlocation 2 in the same time period. Entry $a_{12} = 0.2$ is the\nproportion of residents in location 2 which move to location\n1. Finally, entry $a_{22} = 0.8$ is the proportion of residents in\nlocation 2 which stay in location 2 in this time period.\n\nConsidered as a Markov matrix, these numbers are usually identified\nwith probabilities. Hence, we can say that the probability that a\nresident of location one will stay in location one in the time period\nis $0.4$.\n\\end{solution}\n\nObserve that in Example~\\ref{exa:migration-matrix} if there was initially say 15\nthousand people in location 1 and 10 thousands in location 2, then\nafter one year there would be $0.4 \\times 15 + 0.2 \\times 10 = 8$\nthousands people in location 1 the following year, and similarly\nthere would be $0.6 \\times 15 + 0.8 \\times 10 = 17$\nthousands people in location 2 the following year.\n\nMore generally let $X_n=\\mat{x_{1n}, \\ldots, x_{mn}} ^{T}$ where $x_{in}$ is the\npopulation of location $i$ at time period $n$. We call $X_n$ the \\textbf{state vector at period $n$}\\index{state vector}. In particular, we call $X_0$ the initial state vector. Letting $A$ be the migration matrix, we compute the population in each location $i$ one time period later by $AX_n$. In order to find the population of location $i$ after $k$\nyears, we compute the $i\\th$ component of $A^{k}X$. This discussion is summarized in the following theorem.\n\n\\begin{theorem}{State vector}{state-vector}\nLet $A$ be the migration matrix of a population and let $X_n$ be the vector whose entries give the population of each location at time period $n$. Then $X_n$ is the state vector at period $n$ and it follows that\n\\[\nX_{n+1} = A X_n\n\\]\n\\end{theorem}\n\nThe sum of the entries of $X_n$ will equal the sum of the entries of the initial\nvector $X_{0}$. Since the columns of $A$ sum to $1$, this sum is preserved for every\nmultiplication by $A$ as demonstrated below.\n\\begin{equation*}\n\\sum_{i}\\sum_{j}a_{ij}x_{j}=\\sum_{j}x_{j}\\paren{\\sum_{i}a_{ij}}\n=\\sum_{j}x_{j}\n\\end{equation*}\n\nConsider the following example.\n\n\\begin{example}{Using a migration matrix}{using-migration-matrix}\nConsider the migration matrix\n\\begin{equation*}\nA =\n\\begin{mymatrix}{rrr}\n0.6 & 0 & 0.1 \\\\\n0.2 & 0.8 & 0 \\\\\n0.2 & 0.2 & 0.9\n\\end{mymatrix}\n\\end{equation*}\n for locations $1,2$, and $3$. Suppose initially there are $100$\nresidents in location $1$, $200$ in location $2$ and $400$ in location $3$. Find the\npopulation in the three locations after $1,2$, and $10$ units of time.\n\\end{example}\n\n\\begin{solution}\nUsing Theorem~\\ref{thm:state-vector} we can find the population in each location using the equation $X_{n+1} = AX_n$. For the population after $1$ unit, we calculate $X_1 = AX_0$ as follows.\n\\begin{eqnarray*}\nX_1 &=& AX_0 \\\\\n\\begin{mymatrix}{r}\nx_{11} \\\\\nx_{21} \\\\\nx_{31}\n\\end{mymatrix}\n&=&\n\\begin{mymatrix}{rrr}\n0.6 & 0 & 0.1 \\\\\n0.2 & 0.8 & 0 \\\\\n0.2 & 0.2 & 0.9\n\\end{mymatrix}\n\\begin{mymatrix}{r}\n100 \\\\\n200 \\\\\n400\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{r}\n100 \\\\\n180 \\\\\n420\n\\end{mymatrix}\n\\end{eqnarray*}\nTherefore after one time period, location $1$ has $100$ residents, location $2$ has $180$, and location $3$ has $420$. Notice that the \\textbf{total} population is unchanged, it simply migrates within the given locations.\nWe find the locations after two time periods in the same way.\n\\begin{eqnarray*}\nX_2 &=& AX_1 \\\\\n\\begin{mymatrix}{r}\nx_{12} \\\\\nx_{22} \\\\\nx_{32}\n\\end{mymatrix}\n&=&\n\\begin{mymatrix}{rrr}\n0.6 & 0 & 0.1 \\\\\n0.2 & 0.8 & 0 \\\\\n0.2 & 0.2 & 0.9\n\\end{mymatrix}\n\\begin{mymatrix}{r}\n100 \\\\\n180 \\\\\n420\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{r}\n102 \\\\\n164 \\\\\n434\n\\end{mymatrix}\n\\end{eqnarray*}\n\nWe could progress in this manner to find the populations after $10$ time periods. However from our above discussion, we can simply calculate $(A^{n}X_0) _{i}$,\nwhere $n$ denotes the number of time periods which have passed. Therefore, we compute the populations in each location after $10$ units of time as follows.\n\\begin{eqnarray*}\nX_{10} &=& A^{10}X_0 \\\\\n\\begin{mymatrix}{r}\nx_{1 10} \\\\\nx_{2 10} \\\\\nx_{3 10}\n\\end{mymatrix}\n&=&\n\\begin{mymatrix}{rrr}\n0.6 & 0 & 0.1 \\\\\n0.2 & 0.8 & 0 \\\\\n0.2 & 0.2 & 0.9\n\\end{mymatrix} ^{10}\\begin{mymatrix}{r}\n100 \\\\\n200 \\\\\n400\n\\end{mymatrix} \\\\\n&=&  \\begin{mymatrix}{c}\n115.\\,\\allowbreak 085\\,829\\,22 \\\\\n120.\\,\\allowbreak 130\\,672\\,44 \\\\\n464.\\,\\allowbreak 783\\,498\\,34\n\\end{mymatrix}\n\\end{eqnarray*}\nSince we are speaking about populations, we would need to round these numbers to provide a logical\nanswer. Therefore, we can say that after $10$ units of time, there will be $115$ residents in location one, $120$ in location two,\nand $465$ in location three.\n\\end{solution}\n\nA second important application of Markov matrices is the concept of random walks\\index{random walk}. Suppose a walker has $m$ locations to choose from, denoted $1, 2,\\ldots, m$. Let $a_{ij}$ refer to the probability that the person will travel \\textbf{to}  location $i$ \\textbf{from} location $j$. Again, this requires that\n\\[\n\\sum_{i=1}^{k}a_{ij}=1\n\\]\nIn this context, the vector $X_n=\\mat{x_{1n}, \\ldots, x_{mn}} ^{T}$ contains the probabilities $x_{in}$ the walker ends up in location $i, 1\\leq i \\leq m$ at time $n$.\n\n\\begin{example}{Random walks}{random-walks}\nSuppose three locations exist, referred to as locations $1, 2$ and $3$. The Markov matrix of probabilities $A = [a_{ij}]$ is given by\n\\[\n\\begin{mymatrix}{rrr}\n0.4 & 0.1 & 0.5 \\\\\n0.4 & 0.6 & 0.1 \\\\\n0.2 & 0.3 & 0.4\n\\end{mymatrix}\n\\]\nIf the walker starts in location $1$, calculate the probability that he ends up in location $3$ at time $n = 2$.\n\\end{example}\n\n\\begin{solution}\nSince the walker begins in location $1$, we have\n\\[\nX_{0} = \\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n0\n\\end{mymatrix}\n\\]\nThe goal is to calculate $x_{32}$. To do this we calculate $X_{2}$, using $X_{n+1} = AX_{n}$.\n\\begin{eqnarray*}\nX_{1} &=& A X_{0} \\\\\n&=& \\begin{mymatrix}{rrr}\n0.4 & 0.1 & 0.5 \\\\\n0.4 & 0.6 & 0.1 \\\\\n0.2 & 0.3 & 0.4\n\\end{mymatrix} \\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n0\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{r}\n0.4 \\\\\n0.4 \\\\\n0.2\n\\end{mymatrix}\n\\end{eqnarray*}\n\\begin{eqnarray*}\nX_{2} &=& A X_{1} \\\\\n&=& \\begin{mymatrix}{rrr}\n0.4 & 0.1 & 0.5 \\\\\n0.4 & 0.6 & 0.1 \\\\\n0.2 & 0.3 & 0.4\n\\end{mymatrix} \\begin{mymatrix}{c}\n0.4 \\\\\n0.4 \\\\\n0.2\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{r}\n0.3 \\\\\n0.42 \\\\\n0.28\n\\end{mymatrix}\n\\end{eqnarray*}\nThis gives the probabilities that our walker ends up in locations 1, 2, and 3. For this example we are interested in location 3, with a probability on $0.28$.\n\\end{solution}\n\nReturning to the context of migration, suppose we wish to know how many residents will be in a certain location\nafter a very long time. It turns out that if some power of the\nmigration matrix has all positive entries, then there is a vector $X_s$ such that $A^{n}X_{0}$ approaches $X_s$ as $n$ becomes very large. Hence as more time passes and $n$ increases, $A^{n}X_{0}$ will become closer to the vector $X_s$.\n\nConsider Theorem~\\ref{thm:state-vector}. Let $n$ increase so that $X_n$ approaches $X_s$. As $X_n$ becomes closer to $X_s$, so too does $X_{n+1}$. For sufficiently large $n$, the statement $X_{n+1} = AX_n$ can be written as $X_s = AX_s$.\n\nThis discussion motivates the following theorem.\n\n\\begin{theorem}{Steady state vector}{steady-state}\nLet $A$ be a migration matrix. Then there exists a \\textbf{steady state vector} written $X_s$ such that\n\\[\nX_s = AX_s\n\\]\nwhere $X_s$ has positive entries which have the same sum as the entries of $X_0$.\n\nAs $n$ increases, the state vectors $X_n$ will approach $X_s$.\n\\end{theorem}\n\nNote that the condition in Theorem~\\ref{thm:steady-state} can be written as $(I - A)X_s=0$, representing a homogeneous system of equations.\n\nConsider the following example. Notice that it is the same example as the Example~\\ref{exa:using-migration-matrix} but here it will\ninvolve a longer time frame.\n\n\\begin{example}{Populations over the long run}{long-run-population}\nConsider the migration matrix\n\\begin{equation*}\nA\n=\n\\begin{mymatrix}{rrr}\n0.6 & 0 & 0.1 \\\\\n0.2 & 0.8 & 0 \\\\\n0.2 & 0.2 & 0.9\n\\end{mymatrix}\n\\end{equation*}\n for locations $1,2$, and $3$. Suppose initially there are 100\nresidents in location 1, 200 in location 2 and 400 in location 4. Find the\npopulation in the three locations after a long time.\n\\end{example}\n\n\\begin{solution}\nBy Theorem~\\ref{thm:steady-state} the steady state vector $X_s$ can be found by solving the system $(I-A)X_s = 0$.\n\nThus we need to find a solution to\n\\begin{equation*}\n\\paren{\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix} -\\begin{mymatrix}{rrr}\n0.6 & 0 & 0.1 \\\\\n0.2 & 0.8 & 0 \\\\\n0.2 & 0.2 & 0.9\n\\end{mymatrix}} \\begin{mymatrix}{c}\nx_{1s} \\\\\nx_{2s}\\\\\nx_{3s}\n\\end{mymatrix} =\\begin{mymatrix}{c}\n0 \\\\\n0 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\nThe augmented matrix and the resulting {\\rref} are given by\n\\begin{equation*}\n\\begin{mymatrix}{rrr|r}\n0.4 & 0 & -0.1 & 0 \\\\\n-0.2 & 0.2 & 0 & 0 \\\\\n-0.2 & -0.2 & 0.1 & 0\n\\end{mymatrix}\n\\roweq\\ldots\\roweq\n\\begin{mymatrix}{rrr|r}\n1 & 0 & -0.25 & 0 \\\\\n0 & 1 & -0.25 & 0 \\\\\n0 & 0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\nTherefore, the eigenvectors are\n\\begin{equation*}\nt\\begin{mymatrix}{c}\n0.25 \\\\\n0.25 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\n\nThe initial vector $X_0$ is given by\n\\begin{equation*}\n\\begin{mymatrix}{r}\n100 \\\\\n200 \\\\\n400\n\\end{mymatrix}\n\\end{equation*}\n\nNow all that remains is to choose the value of $t$ such that\n\\begin{equation*}\n0.25t+0.25t+t=100+200+400\n\\end{equation*}\nSolving this equation for $t$ yields $t=\\vspace{.05in} \\frac{1400}{3}$. Therefore the population in the long run\nis given by\n\\begin{equation*}\n\\vspace{.05in} \\frac{1400}{3}\\begin{mymatrix}{c}\n0.25 \\\\\n0.25 \\\\\n1\n\\end{mymatrix} = \\begin{mymatrix}{c}\n116. 666\\,666\\,666\\, 666\\,7 \\\\\n116. 666\\,666\\,666\\, 666\\,7 \\\\\n466. 666\\,666\\,666\\, 666\\,7\n\\end{mymatrix}\n\\end{equation*}\n\nAgain, because we are working with populations, these values need to be rounded. The steady state vector $X_s$ is given by\n\\[\n\\begin{mymatrix}{c}\n117 \\\\\n117 \\\\\n466\n\\end{mymatrix}\n\\]\n\\end{solution}\n\nWe can see that the numbers we calculated in Example~\\ref{exa:using-migration-matrix} for the populations\nafter the $10\\th$ unit of time are not far from the long term values.\n\nConsider another example.\n\n\\begin{example}{Populations after a long time}{population-after-long-time}\nSuppose a migration matrix is given by\n\\begin{equation*}\nA = \\begin{mymatrix}{ccc}\n\\vspace{.05in} \\frac{1}{5} & \\vspace{.05in} \\frac{1}{2} & \\vspace{.05in}\n\\frac{1}{5} \\\\\n\\vspace{.05in} \\frac{1}{4} & \\vspace{.05in} \\frac{1}{4} & \\vspace{.05in}\n\\frac{1}{2} \\\\\n\\vspace{.05in} \\frac{11}{20} & \\vspace{.05in} \\frac{1}{4} & \\vspace{.05in}\n\\frac{3}{10}\n\\end{mymatrix}\n\\end{equation*}\n Find the comparison between the populations in the three\nlocations after a long time.\n\\end{example}\n\n\\begin{solution}\nIn order to compare the populations in the long term, we want to find the steady state vector $X_s$.\nSolve\n\\begin{equation*}\n\\paren{\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix} -\\begin{mymatrix}{ccc}\n\\vspace{.05in} \\frac{1}{5} & \\vspace{.05in} \\frac{1}{2} & \\vspace{.05in}\n\\frac{1}{5} \\\\\n\\vspace{.05in} \\frac{1}{4} & \\vspace{.05in} \\frac{1}{4} & \\vspace{.05in}\n\\frac{1}{2} \\\\\n\\vspace{.05in} \\frac{11}{20} & \\vspace{.05in} \\frac{1}{4} & \\vspace{.05in}\n\\frac{3}{10}\n\\end{mymatrix}} \\begin{mymatrix}{c}\nx_{1s} \\\\\nx_{2s} \\\\\nx_{3s}\n\\end{mymatrix} =\\begin{mymatrix}{c}\n0 \\\\\n0 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\nThe augmented matrix and the resulting {\\rref} are given by\n\\begin{equation*}\n\\begin{mymatrix}{rrr|r}\n\\vspace{.05in} \\frac{4}{5} & -\\vspace{.05in} \\frac{1}{2} & -\\vspace{.05in}\n\\frac{1}{5} &  0 \\\\\n-\\vspace{.05in} \\frac{1}{4} & \\vspace{.05in} \\frac{3}{4} & -\\vspace{.05in}\n\\frac{1}{2} &  0 \\\\\n-\\vspace{.05in} \\frac{11}{20} & -\\vspace{.05in} \\frac{1}{4} & \\vspace{.05in}\n\\frac{7}{10} &  0\n\\end{mymatrix}\n\\roweq\\ldots\\roweq\n\\begin{mymatrix}{rrr|r}\n1 & 0 & -\\vspace{.05in} \\frac{16}{19} & 0 \\\\\n0 & 1 & -\\vspace{.05in} \\frac{18}{19} & 0 \\\\\n0 & 0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\nand so an eigenvector is\n\\begin{equation*}\n\\begin{mymatrix}{c}\n16 \\\\\n18 \\\\\n19\n\\end{mymatrix}\n\\end{equation*}\n\nTherefore, the proportion of population in location 2 to location 1 is given by $\\vspace{.05in} \\frac{18}{16}$.\nThe proportion of population 3 to location 2 is given by $\\vspace{.05in} \\frac{19}{18}$.\n\\end{solution}\n", "meta": {"hexsha": "88d6a799ade9bf1c15c1029662b966280aa2601f", "size": 13986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryApplicationsDiagonalizationMarkov.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/spectraltheoryApplicationsDiagonalizationMarkov.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/spectraltheoryApplicationsDiagonalizationMarkov.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 31.7142857143, "max_line_length": 351, "alphanum_fraction": 0.6888316888, "num_tokens": 5026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359806, "lm_q2_score": 0.9353465075887175, "lm_q1q2_score": 0.8143101051008719}}
{"text": "\\section*{Chapter 3: Ancient Greek Number Theory}\n\n\\paragraph{Exercise 3.6}\nProve that if $n$ and $m$ are coprime, then $\\DivSum{nm} = \n\\DivSum{n} \\, \\DivSum{m}$\n\n\\begin{proof}\nLet the prime factorization of $nm$ be \n$nm = p_1^{\\alpha_1} \\dots p_k^{\\alpha_k}$.\nBeing $\\GCD{n}{m} = 1$, if $\\Divides{p_i}{n}$ then $\\NotDivides{p_i}{m}$\n(and viceversa), $1 \\leq i \\leq k$. In consequence, if the prime factorization\nof $n$ is $n = q_1^{\\beta_1} \\dots q_l^{\\beta_l}$, then any $q_i$ cannot appear\nin the prime factorization of $m$. That is, if the prime\nfactorization of $m$ is $m = r_1^{\\gamma_1} \\dots r_s^{\\gamma_s}$, \nthen $q_i \\neq r_j$, $1 \\leq i \\leq l$, $1 \\leq j \\leq s$. Thus,\n\\begin{eqnarray*}\n\\DivSum{nm} &=& \\DivSum{p_1^{\\alpha_1} \\dots p_k^{\\alpha_k}} \\\\\n            &=& \\prod_{i = 1}^{k}{\\frac{p_i^{\\alpha_i + 1} - 1}{p_i - 1}} \\\\\n            &=& \\prod_{i = 1}^{l}{\\frac{q_i^{\\beta_i + 1} - 1}{q_i - 1}} \\,\n                \\prod_{j = 1}^{s}{\\frac{r_i^{\\gamma_i + 1} - 1}{r_i - 1}} \\\\\n            &=& \\DivSum{q_1^{\\beta_1} \\dots q_l^{\\beta_l}} \\,\n                \\DivSum{r_1^{\\gamma_1} \\dots r_s^{\\gamma_s}} \\\\\n            &=& \\DivSum{n} \\, \\DivSum{m}\n\\end{eqnarray*}\n\\end{proof}\n\n\\paragraph{Exercise 3.7}\nProve that every even perfect number is a triangular number.\n\n\\begin{proof}\nLet $k$ be an even perfect number. Then, by the Euclid-Euler theorem,\n$k = 2^{n-1} (2^n - 1)$ for some $n \\in \\Nat$, where $2^n - 1$ is prime.\nThus,\n\\begin{eqnarray*}\nk &=& 2^{n-1} (2^n - 1)\\\\\n  &=& (2^n - 1) (2^n / \\, 2) \\\\\n  &=& \\frac{(2^n - 1) 2^n}{2} \\\\\n  &=& \\triangle_{2^n - 1}\n\\end{eqnarray*}\n\n\\end{proof}\n\n\n\\paragraph{Exercise 3.8}\nProve that the sum of the reciprocals of the divisors of a perfect number is\nalways 2.\n\n\\begin{proof}\nLet $n$ be a perfect number with divisors $d_1,\\dots,d_k$. By definition of\nperfect number, we have that\n$$\\DivSum{n} = d_1 + \\dots + d_k = 2n$$\nwhich implies that \n$$2 = \\frac{d_1 + \\dots + d_k}{n} = \\frac{d_1}{n} + \\dots + \\frac{d_k}{n}$$\nSince $\\Divides{d_i}{n}$, $1 \\leq i \\leq k$, $n = d_i q_i$. But\n$\\Divides{q_i}{n}$ as well, and so $q_i = d_j$. Then, $d_i / n = 1 / d_j$.\nIn consequence, every summand on the right-hand side of the previous equation\ncan be rewritten as the reciprocal of some divisor of $n$, and so\n$$2 = \\frac{d_1}{n} + \\dots + \\frac{d_k}{n} = \\frac{1}{d_1} + \\dots + \\frac{1}{d_k}$$\n\n\\end{proof}\n", "meta": {"hexsha": "4ecd5722865f2fa078d77ecd13aae452e6aa872c", "size": 2357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/src/chapter3.tex", "max_stars_repo_name": "lukius/fmtgp", "max_stars_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-10-12T17:40:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T03:00:43.000Z", "max_issues_repo_path": "math/src/chapter3.tex", "max_issues_repo_name": "lukius/fmtgp", "max_issues_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/src/chapter3.tex", "max_forks_repo_name": "lukius/fmtgp", "max_forks_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-15T07:07:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-29T14:01:30.000Z", "avg_line_length": 38.6393442623, "max_line_length": 85, "alphanum_fraction": 0.5910055155, "num_tokens": 971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107984180245, "lm_q2_score": 0.868826769445233, "lm_q1q2_score": 0.8142738302787197}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n\\usepackage{amssymb}\n\\usepackage{indentfirst}\n\\usepackage{tikz-cd}\n\\usepackage{mathtools}\n\\usepackage[shortlabels]{enumitem}\n\\usepackage{xcolor}\n\\usepackage{hyperref}\n\\usepackage{multicol}\n\\usepackage[margin=0.75in, top=1in, a4paper]{geometry}\n\n\\theoremstyle{definition}\n\\newtheorem{defn}{Definition}[section]\n\\newtheorem{ex}{Exercise}[section]\n\\newtheorem{oex}[ex]{*Exercise}\n\n\\newcommand{\\mo}[1]{\\lvert #1 \\rvert}\n\\newcommand{\\mos}[1]{\\lvert #1 \\rvert^2}\n\\newcommand{\\RR}{\\mathbb{R}}\n\\newcommand{\\QQ}{\\mathbb{Q}}\n\\newcommand{\\NN}{\\mathbb{N}}\n\\newcommand{\\T}{\\text{true}}\n\\newcommand{\\F}{\\text{false}}\n\\newcommand{\\mov}[1]{\\lvert \\vec{#1} \\rvert}\n\\newcommand{\\CC}{\\mathbb{C}}\n\\newcommand{\\p}{\\partial}\n\\newcommand{\\iv}[1]{\\langle #1 \\rangle}\n\\newcommand{\\adj}{\\text{adj}}\n\\newcommand{\\dom}{\\text{dom}}\n\\newcommand{\\st}{\\text{s.t. }}\n\\newcommand{\\ltc}[1]{\\colorbox{lightgray}{\\textbackslash #1}}\n\\newcommand{\\ltcc}[1]{\\colorbox{lightgray}{#1}}\n\\newcommand{\\bras}[1]{\\lbrace #1 \\rbrace}\n\\newcommand{\\braks}[1]{\\lbrack #1 \\rbrack}\n\\newcommand{\\id}[1]{\\text{id}_{#1}}\n\n\\definecolorset{gray/rgb/hsb/cmyk}{}{}%\n {black,0/0,0,0/0,0,0/0,0,0,1;%\n  darkgray,.25/.25,.25,.25/0,0,.25/0,0,0,.75;%\n  gray,.5/.5,.5,.5/0,0,.5/0,0,0,.5;%\n  lightgray,.85/.85,.85,.85/0,0,.85/0,0,0,.15;%\n  white,1/1,1,1/0,0,1/0,0,0,0}\n\n\\title{\\vspace{-2.0cm}Mathematics Notation Cheatsheet}\n\\author{David Ma}\n\n\\begin{document}\n\t\\maketitle\n\t\n\t\\section{Sets}\n\t\n\tA set is a collection of objects, which are referred to as the $members$ or $elements$ of the set.\n\t\n\t\\begin{itemize}\n\t\t\\item $a \\in A$: $a$ is an element of the set $A$.\n\t\t\\item $|A|$: The cardinality (i.e. size) of the set $A$, e.g. the set $\\bras{1, 3, 5}$ has cardinality $3$.\n\t\\end{itemize}\n\t\n\t\\subsection{Common Sets}\n\t\\begin{itemize}\n\t\t\\item $\\varnothing$: The empty set with no elements.\n\t\t\\item $\\NN$: The set of natural numbers, e.g. $2$, $6969$, $42$.\n\t\t\\item $\\mathbb{Z}$: The set of integers, e.g. $-2, 0, 9$.\n\t\t\\item $\\mathbb{Q}$: The set of rational numbers, e.g. $2.34$, $\\frac{6}{7}$.\n\t\t\\item $\\RR$: The set of real numbers, e.g. $12$, $\\frac{3}{8}$, $-\\sqrt{2}$.\n\t\t\\item $\\RR_+$: The set of non-negative real numbers, e.g. $0$, $\\pi$, $1$. This notation works for other number sets (e.g. $Z_+$ denotes non-negative integers).\n\t\t\\item $\\RR_{++}$: The set of strictly positive real numbers (not including $0$).\n\t\t\\item $\\CC$: The set of complex numbers, e.g. $2 + 3i$, $5i$, $12$.\n\t\t\\item $\\RR^n$: The set of vectors of length (dimension) $n$.\n\t\t\\item $\\RR^{m \\times n}$: The set of matrices of size $(m, n)$.\n\t\\end{itemize}\n\t\n\t\\subsection{Construction of Sets}\n\t\n\tAn arbitrary set $S$ can be constructed in numerous ways:\n\t\\begin{itemize}\n\t\t\\item $S = \\bras{a, b, c}$: Set $S$ has elements $a$, $b$ and $c$.\n\t\t\\item $S = \\bras{x \\mid x \\in A}$: Set $S$ comprise of elements from set $A$.\n\t\t\\item $S = \\bras{x \\mid x \\in A,\\ C_1(x), \\dots, C_n(x)}$: Set $S$ comprises of all elements from set $A$ that satisfy all assertions $C_1, \\dots, C_n$ of the element, e.g. $\\bras{x \\mid x \\in \\NN,\\ x > 5}$ is the set of all natural numbers that are larger than $5$.\n\t\t\\item $S = \\bras{f(a, b) \\mid a \\in A,\\ b \\in B}$: Set $S$ contains the results of applying function $f$ to all combinations of elements from set $A$ and $B$.\n\t\\end{itemize}\n\t\n\tApart from the first notation, the rest are referred to as \\emph{set comprehensions}. They can be used in conjunction, i.e. a set comprehension can contain multiple assertion statements and multiple element definition statements.\n\t\n\t\\subsection{Set Operations}\n\t\n\tBy operating on sets, new sets can be formed from existing sets.\n\t\n\t\\begin{itemize}\n\t\t\\item $\\overline{A}$: The complementary set of $A$. The definition of this is sensitive to the definition of the universal set in the current context.\n\t\t\\item $A \\setminus B$: The difference of $A$ and $B$, i.e. all members of $A$ that are not contained in $B$.\n\t\t\\item $A \\cap B$: The intersection of $A$ and $B$, i.e. the set whose elements are all elements contained in \\emph{both} $A$ and $B$.\n\t\t\\item $A \\cup B$: The union of $A$ and $B$, i.e. the set whose elements are all elements contained in \\emph{either} $A$ or $B$.\n\t\t\\item $A \\sqcup B$: The disjoint union of $A$ and $B$. This is similar to a union, except that each element in the resulting union has semantics indicating which source set (of $A$ and $B$) this element came from. One representation of this idea is treating $\\bras{(a, A) \\mid a \\in A} \\cup \\bras{(b, B) \\mid b \\in B}$ as the disjoint union of $A$ and $B$.\n\t\t\\item $A \\times B$: The cartesian product of $A$ and $B$. This is the set of tuples/pairs defined as $\\bras{(a, b) \\mid a \\in A,\\ b \\in B}$.\n\t\\end{itemize}\n\t\n\tIt is clear that the cardinality of some composed set can be inferred from its constituent sets. This is useful when proving theorems via the Howard-Curry isomorphism.\n\t\\begin{itemize}\n\t\t\\item $A \\cap B = \\varnothing \\text{ ($A$ and $B$ are disjoint)} \\iff |A \\cap B| = |A| + |B|$\n\t\t\\item $|A \\sqcup B| = |A| + |B|$\n\t\t\\item $|A \\times B| = |A| * |B|$\n\t\\end{itemize}\n\t\n\tIn addition, note that there are also compact forms for some of the above operations:\n\t\\begin{align*}\n\t\t\\bigcap^n_{i=1} a_i &= a_1 \\cap a_2 \\cap \\dots \\cap a_n\\\\\n\t\t\\bigcup^n_{i=1} a_i &= a_1 \\cup a_2 \\cup \\dots \\cup a_n\n\t\\end{align*}\n\t\n\t\\subsection{Set Relations}\n\t\n\tThe relationship between sets can also be described with symbols:\n\t\\begin{itemize}\n\t\t\\item $A \\subseteq B$: $A$ is a subset of $B$, i.e. all members of $A$ are also members of $B$.\n\t\t\\item $A \\not\\subseteq B$: $A$ is not a subset of $B$, i.e. there exists at least one member of $A$ that is not a member of $B$.\n\t\t\\item $A \\subset B$: $A$ is a strict ($A \\neq B$) subset of $B$.\n\t\t\\item $A \\not\\subset B$: $A$ is not a strict subset of $B$.\n \t\\end{itemize}\n \t\n \t\\section{Functions}\n \t\n \tThe \\emph{signature} of a function denotes what type of function it is, i.e. what are the parameters and return types of the function.\n \t\n \tTo illustrate, the function signature of the addition function $+$ over the set of natural numbers can be written in the forms of either:\n \t\\begin{itemize}\n \t\t\\item $+ : \\NN \\to \\NN \\to \\NN$\n \t\t\\item $+ : \\NN \\times \\NN \\to \\NN$\n \t\\end{itemize}\n \t\n \tThe above signatures state that \"$+$ is a function that accepts two parameters from $\\NN$ and returns a value of type $\\NN$\".\n \t\n \tNote that the two signatures listed above are equivalent up to isomorphism (over the currying operation). From this observation, it is evident that the arrow $\\to$ in function signatures is right-associative.\n \t\n \tSome additional notations of functions:\n \t\\begin{itemize}\n \t\t\\item $\\id{A}: A \\to A$ is the identity function that simply returns the given parameter.\n \t\t\\item In addition to the common function definition, e.g. $f(x, y) = x^2 + y^2$, a function can also be defined in-line with the mapping arrow $\\mapsto$, e.g. $(x, y) \\mapsto x^2 + y^2$.\n \t\t\\item Given $f : A \\to B$ and $g : B \\to C$, the function composition $g \\circ f : A \\to C$ denotes the chaining of $g$ after $f$, i.e. $x \\mapsto g(f(x))$.\n \t\\end{itemize}\n \t\n \t\\subsection{Function Descriptions}\n \t\n \tA function $f : A \\to B$ can be described according to its behavior on how it maps elements from $A$ to $B$. Specifically, $f$ can be:\n \t\\begin{enumerate}\n \t\t\\item \\textbf{Injective}: $f(x) \\neq f(y)$ for all $x, y \\in A$, $x \\neq y$.\n \t\t\\item \\textbf{Surjective}: For all $b \\in B$, there exists an $a \\in A$ such that $f(a) = b$.\n \t\t\\item \\textbf{Bijective}: A bijective function is one that is both injective and surjective.\n \t\\end{enumerate}\n \t\n \tSets can also be described in relation to a function. Consider the function $f : X \\to Y$, then a set in relation to $f$ can be described as:\n \t\\begin{itemize}\n \t\t\\item \\textbf{Domain}: The domain of $f$ is $X$.\n \t\t\\item \\textbf{Codomain}: The codomain of $f$ is $Y$.\n \t\t\\item \\textbf{Image} (range): The image $M$ of $f$ is the set of actual values $f(x)$ for all $x \\in X$. If $f$ is surjective, then $M = Y$.\n \t\t\\item \\textbf{Preimage}: The preimage of $P \\subseteq Y$ over $f$ is the set of $x \\in X$ such that $f(x) \\in P$.\n \t\\end{itemize}\n \t\n \tFor example, the notions of image and preimage are commonly used when describing linear mapping of vector spaces, as singular matrices (i.e. whose determinant is $0$) maps a vector space to a strict subset of itself, thereby distinguishing its image from its codomain.\n\t\n\t\\section{Relations}\n\t\n\tIn academic writing, custom relationships between arbitrary objects are often defined for better elaboration. Such an abstraction is especially prevalent in proofs. This section aims to clarify some common relation definitions and terminologies.\n\t\n\t\\begin{defn}\n\t\tA \\emph{preorder} relation on set $A$ is a binary relation that denotes an order over the elements of $A$. A preorder relationship between two objects is denoted as $a \\preceq b$ or with a similar operator.\n\t\t\n\t\tA preorder relation $\\preceq$ on set $A$ must satisfy the following axioms:\n\t\t\\begin{enumerate}\n\t\t\t\\item \\textbf{Identity}: $a \\preceq a$ for all $a \\in A$\n\t\t\t\\item \\textbf{Transitivity}: $a \\preceq b \\land b \\preceq c \\implies a \\preceq c$\n\t\t\t\\item \\textbf{Anti-symmetry}: $a \\preceq b \\land b \\preceq a \\implies a \\cong b$\n\t\t\\end{enumerate}\n\t\twhere $\\cong$ is some notion of equivalence (see below).\n \t\\end{defn}\n \t\n \tFor example, a preorder can be formed on the set of restaurants near YKPS based on their distance to the school: $a \\preceq b$ if the distance to $a$ is less than or equal to that of $b$.\n \t\n \t\\begin{defn}\n \t\tAn \\emph{equivalence} relation $a \\cong b$ states that $a$ and $b$ are equal in some sense. A definition for equivalence on set $A$ must satisfy the following constraints:\n \t\t\\begin{enumerate}\n \t\t\t\\item \\textbf{Reflexivity}: $a \\cong a$ for all $a \\in A$\n \t\t\t\\item \\textbf{Symmetry}: $a \\cong b \\iff b \\cong a$\n \t\t\t\\item \\textbf{Transitivity}: $a \\cong b \\land b \\cong c \\implies a \\cong c$\n \t\t\\end{enumerate}\n \t\\end{defn}\n \t\n \tThe symbol for equivalence can also be a tilde $\\sim$.\n \t\n \tFor example, for a purchasing problem, the equivalence of purchasing strategies can be defined as having the same cost/price.\n \t\n \t\\begin{defn}\n \t\tAn \\emph{isomorphism} between structures (structures are more generalized than sets) $A$ and $B$ states that \"having either $A$ or $B$ is as good as having the other\". Formally, structures $A$ and $B$ are isomorphic if there exists a pair of functions $f : A \\to B$ and $g : B \\to A$ such that:\n \t\t\\begin{enumerate}\n \t\t\t\\item $g \\circ f = \\id{A}$\n \t\t\t\\item $f \\circ g = \\id{B}$\n \t\t\\end{enumerate}\n \t\\end{defn}\n \t\n \tFor example, a bijection is an isomorphism in the category of sets.\n \t\n \t\\section{Formal Logic}\n \t\n \tLogic statements can shorten your descriptions with short notations. Such notations are ubiquitous in academic writings, so it is important to get them right!\n \t\n \tLoosely speaking, a statement is an observation or deduction, e.g. $x > 5$ states that $x$ is larger than $5$.\n \t\n \tSome common operations on statements:\n \t\\begin{itemize}\n \t\t\\item $\\lnot A$: Negates the statement $A$.\n \t\t\\item $A \\lor B$: Either $A$ or $B$, e.g. $x > 10 \\lor x < 0$ means $x$ can be \\emph{either} greater than $10$ or less than $0$.\n \t\t\\item $A \\land B$: Both $A$ and $B$, e.g. $x \\in X \\land x > 5$ means $x$ must be \\emph{both} in set $X$ and greater than $5$.\n \t\\end{itemize}\n \t\n \t\\subsection{Logical Deduction Notations}\n \t\n \tArrows are commonly used in logical deductions; however, note that different arrows have \\textbf{completely different} meanings, and misusing arrows can cause confusions for the reader. For example, $\\to$ and $\\implies$ are completely different, and should never be used interchangeably.\n \t\n \t\\begin{defn}\n \t\tStatement $A$ \\emph{implies} statement $B$ means that if $A$ is true, then $B$ is true. Such a relation is denoted $A \\implies B$.\n  \t\\end{defn}\n  \t\n  \tFor example:\n  \t\\begin{center}\n  \t\tThomas is at Oxford $\\implies$ Thomas is not in China\n  \t\\end{center}\n  \t\n  \t\\begin{defn}\n  \t\tAn \\emph{if and only if} relation on statement $A$ and $B$ denotes that $A$ and $B$ should either both be true, or  both be false, as the state of either statement can guarantee the state of the other. Denoted as $A \\iff B$, the \"if and only if\" relation can be relaxed into two relations:\n  \t\t\\begin{itemize}\n  \t\t\t\\item \\textbf{Necessary}: $A$ is needed for $B$ to be true.\n  \t\t\t\\item \\textbf{Sufficient}: Knowing that $A$ is true is enough for $B$ to be true.\n  \t\t\\end{itemize}\n  \t\tIf both requirements above are satisfied, then $A \\iff B$.\n  \t\\end{defn}\n  \t\n  \tFor example:\n  \t\\begin{center}\n  \t\tS is the empty set $\\iff$ $|S| = 0$\n  \t\\end{center}\n  \t\n  \tAn alternative way of defining $A \\iff B$ is:\n  \t\\begin{gather*}\n  \t\t(A \\implies B) \\land (B \\implies A)\n  \t\\end{gather*}\n  \t\n  \t\\subsection{Quantifiers}\n  \t\n  \tQuantifiers are symbols that define a variable with certain given semantics, i.e. information regarding the value of the variable. This is useful when formulating a predicate or statement.\n  \t\n  \t\\begin{itemize}\n  \t\t\\item $\\forall a \\in A$ (Universal Quantifier): For all $a$ in set $A$, i.e. $a$ can be set to any value in $A$.\n  \t\t\\item $\\exists a \\in A$ (Existential Quantifier): There exists an $a$ i $A$.\n  \t\\end{itemize}\n  \t\n  \tFor example, the statement \"all integers have an additive inverse\" can be rewritten with quantifiers (different writings may use different conventions for separators):\n  \t\\begin{gather*}\n  \t\t\\forall x \\in \\mathbb{Z},\\ \\exists y \\in \\mathbb{Z}.\\ x + y = 0\n  \t\\end{gather*}\n \t\n \t\\section{Number Theory}\n \t\n \t\\begin{itemize}\n \t\t\\item $a \\mid b$: $a$ is a factor of $b$, i.e. $b$ has remainder $0$ when divided by $a$.\n \t\t\\item $a \\nmid b$: $a$ is not a factor of $b$, i.e. $a$ does not divide $b$.\n \t\t\\item $a \\perp b$: $a$ and $b$ are coprimes, i.e. the greatest common factor of $a$ and $b$ is $1$\n \t\t\\item $a \\bmod b$: The remainder of $a$ divided by $b$.\n \t\t\\item $a \\equiv b \\bmod n$: $a$ is congruent to $b$ modulo $n$, i.e. $n \\mid (b - a)$.\n \t\t\\item $\\mathbb{Z}/n\\mathbb{Z}$: The cyclic group (see \\nameref{sec:terms}) formed by numbers $\\bras{0, 1, \\dots, n - 1}$ under addition modulo $n$.\n \t\t\\item $\\lfloor x \\rfloor$: The floor of $x$, i.e. the largest integer less than or equal to $x$.\n \t\t\\item $\\lceil x \\rceil$: The ceiling of $x$, i.e. the smallest integer greater than or equal to $x$.\n \t\t\\item $\\lfloor x \\rceil$ (or $\\lbrack x \\rbrack$): The nearest integer to $x$.\n \t\\end{itemize}\n \t\n \t\\section{Calculus}\n \t\n \tThe symbols in calculus are standard to what we've covered in class. However, there are some alternative ways of writing derivatives.\n \t\n \tConsider function $f(x, y)$. Its partial derivative with respect to $x$ can be written as:\n \t\\begin{itemize}\n \t\t\\item $\\frac{\\partial f}{\\partial x}(x, y)$\n \t\t\\item $f_x(x, y)$\n \t\t\\item $D_xf(x, y)$\n \t\\end{itemize}\n \t\n \tSimilarly, the second order derivative of $f(x, y)$ with respect to $x$ and then $y$ can be written as:\n \t\\begin{itemize}\n \t\t\\item $\\frac{\\partial^2 f}{\\partial x \\partial y}(x, y)$\n \t\t\\item $f_{xy}(x, y)$\n \t\t\\item $D_{xy}f(x, y)$\n \t\\end{itemize}\n \t\n \tNote that according to Clairaut's theorem, $f_{xy} = f_{yx}$, so the order of the \"with respect to\" variables does not matter.\n \t\n \t\\subsection{Vector Calculus}\n \t\n \tThe gradient of a real-valued function $f(x_1, \\dots, x_n)$, denoted $\\nabla f$, is defined as the vector:\n \t\\begin{gather*}\n \t\\nabla f = \n\t\\begin{bmatrix}\n \t\t\\frac{\\partial f}{\\partial x_1} \\\\\n \t\t\\vdots \\\\\n \t\t\\frac{\\partial f}{\\partial x_n}\n \t\\end{bmatrix}\n \t\\end{gather*}\n \t\n \tThe gradient marks the steepest direction of ascent for function $f$.\n \t\n \tNote that the operator $\\nabla$ is often considered in its vector form, $\\nabla = \\braks{\\frac{\\partial}{\\partial x_1}, \\dots, \\frac{\\partial}{\\partial x_n}}$. This makes it flexible, and can also be used on a vector-valued function:\n \t\\begin{itemize}\n \t\t\\item $\\nabla \\cdot f$: The divergence of $f$.\n \t\t\\item $\\nabla \\times f$: The curl of $f$.\n \t\\end{itemize}\n \t\n \t\\begin{defn}\n \t\tThe \\emph{Jacobian matrix} of a vector-valued function $f : \\bras{x_1, \\dots, x_n} \\to \\bras{f_1, \\dots, f_m}$ is an $m \\times n$ matrix containing each component of the result taken derivative to each components in the parameter:\n \t\t\\begin{gather*}\n \t\tJ_f = \n \t\t\\begin{bmatrix}\n \t\t\t\\frac{\\partial f_1}{\\partial x_1} & \\dots & \\frac{\\partial f_1}{\\partial x_n} \\\\\n \t\t\t\\vdots & \\ddots & \\vdots \\\\\n \t\t\t\\frac{\\partial f_m}{\\partial x_1} & \\dots & \\frac{\\partial f_m}{\\partial x_n}\n \t\t\\end{bmatrix}\n \t\t\\end{gather*}\n \t\\end{defn}\n \t\n \tNote that there is no established convention for the orientation of the Jacobian matrix; some writings may feature a transposed version of the above definition.\n \t\n \t\\section{Terminologies}\n \t\\label{sec:terms}\n \t\n \tTODO.\n \t\n \t\\section{Appendix: \\LaTeX\\ Notations}\n \t\n \tThis section aims to cover the typesetting of common symbols in \\LaTeX.\t This includes all symbols shown in this document, as well as ones we've covered in class.\n \t\n \t\\subsection{Sets Symbols}\n \t\n \t\\begin{multicols}{2}\n \t\\begin{itemize}\n\t \t\\item $\\varnothing$: \\ltc{varnothing}\n \t\t\\item $\\NN$: \\ltc{mathbb\\{N\\}}\n \t\t\\item $\\mathbb{Z}$: \\ltc{mathbb\\{Z\\}}\n \t\t\\item $\\QQ$: \\ltc{mathbb\\{Q\\}}\n \t\t\\item $\\RR$: \\ltc{mathbb\\{R\\}}\n \t\t\\item $\\RR_+$: \\ltc{mathbb\\{R\\}\\_+}\n \t\t\\item $\\RR_{++}$: \\ltc{mathbb\\{R\\}\\_\\{++\\}}\n \t\t\\item $\\CC$: \\ltc{mathbb\\{C\\}}\n \t\t\\item $\\RR^n$: \\ltc{mathbb\\{R\\}\\^{}n}\n \t\t\\item $\\RR^{m \\times n}$: \\ltc{mathbb\\{R\\}\\^{}\\{m \\textbackslash times n\\}}\n \t\t\\item $\\bras{x}$: \\ltc{lbrack x \\textbackslash rbrack}\n \t\t\\item $|A|$: \\ltcc{\\textbackslash lvert A \\textbackslash rvert}\n \t\t\\item $\\overline{A}$: \\ltc{overline\\{A\\}}\n \t\t\\item $a \\in A$: \\ltcc{a \\textbackslash in A}\n \t\t\\item $A \\subset B$: \\ltcc{A \\textbackslash subset B}\n \t\t\\item $A \\not\\subset B$: \\ltcc{A \\textbackslash not\\textbackslash subset B}\n \t\t\\item $A \\subseteq B$: \\ltcc{A \\textbackslash subseteq B}\n \t\t\\item $A \\not\\subseteq B$: \\ltcc{A \\textbackslash not\\textbackslash subseteq B}\n \t\t\\item $A \\setminus B$: \\ltcc{A \\textbackslash setminus B}\n \t\t\\item $A \\cap B$: \\ltcc{A \\textbackslash cap B}\n \t\t\\item $A \\cup B$: \\ltcc{A \\textbackslash cup B}\n \t\t\\item $A \\sqcup B$: \\ltcc{A \\textbackslash sqcup B}\n \t\t\\item $A \\times B$: \\ltcc{A \\textbackslash times B}\n \t\t\\item $\\bigcap^n_{i=1} a_i$: \\ltc{bigcap\\^{}n\\_\\{i=1\\} a\\_i}\n \t\t\\item $\\bigcup^n_{i=1} a_i$: \\ltc{bigcup\\^{}n\\_\\{i=1\\} a\\_i}\n \t\t\\item $a \\neq b$: \\ltcc{a \\textbackslash neq b}\n \t\t\\item $a \\cup \\dots \\cup b$: \\ltcc{a \\textbackslash cup \\textbackslash dots \\textbackslash cup b}\n \t\\end{itemize}\t\n \t\\end{multicols}\n\n\t\\subsection{Functions}\n\t\\begin{multicols}{2}\n \t\\begin{itemize}\n\t \t\\item $A \\to A$: \\ltcc{A \\textbackslash to A}\n\t \t\\item $x \\mapsto x^2$: \\ltcc{x \\textbackslash mapsto x\\^{}2}\n\t \t\\item $\\text{id}_A$: \\ltc{text\\{id\\}\\_A}\n\t \t\\item $g \\circ f$: \\ltcc{g \\textbackslash circ f}\n \t\\end{itemize}\t\n \t\\end{multicols}\n \t\n \t%\\subsection{Relations}\n \t\\begin{multicols}{2}\n \t\\begin{itemize}\n\t \t\\item $a \\preceq b$: \\ltcc{a \\textbackslash preceq b}\n\t \t\\item $a \\cong b$: \\ltcc{a \\textbackslash cong b}\n \t\\end{itemize}\t\n \t\\end{multicols}\n \t\n \t\\subsection{Formal Logic}\n \t\\begin{multicols}{2}\n \t\\begin{itemize}\n\t \t\\item $\\lnot A$: \\ltc{lnot A}\n\t \t\\item $A \\land B$: \\ltcc{A \\textbackslash land B}\n\t \t\\item $A \\lor B$: \\ltcc{A \\textbackslash or B}\n\t \t\\item $A \\implies B$: \\ltcc{A \\textbackslash implies B}\n\t \t\\item $A \\iff B$: \\ltcc{A \\textbackslash iff B}\n\t \t\\item $\\forall a \\in A$: \\ltc{forall a \\textbackslash in A}\n\t \t\\item $\\exists a \\in A$: \\ltc{exists a \\textbackslash in A}\n \t\\end{itemize}\t\n \t\\end{multicols}\n \t\n \t\\subsection{Number Theory}\n \t\\begin{multicols}{2}\n \t\\begin{itemize}\n\t \t\\item $a \\mid b$: \\ltcc{a \\textbackslash mid b}\n\t \t\\item $a \\nmid b$: \\ltcc{a \\textbackslash nmid b}\n\t \t\\item $a \\perp b$: \\ltcc{a \\textbackslash perp b}\n\t \t\\item $a \\bmod b$: \\ltcc{a \\textbackslash bmod b}\n\t \t\\item $a \\equiv b$: \\ltcc{a \\textbackslash equiv b}\n\t \t\\item $\\lfloor x \\rfloor$: \\ltcc{\\textbackslash lfloor x \\textbackslash rfloor}\n\t \t\\item $\\lceil x \\rceil$: \\ltcc{\\textbackslash lceil x \\textbackslash rceil}\n\t \t\\item $\\lfloor x \\rceil$: \\ltcc{\\textbackslash lfloor x \\textbackslash rceil}\n \t\\end{itemize}\t\n \t\\end{multicols}\n \t\n \t\\subsection{Calculus}\n \t\\begin{multicols}{2}\n \t\\begin{itemize}\n\t \t\\item $\\partial$: \\ltc{partial}\n\t \t\\item $\\nabla$: \\ltc{nabla}\n\t \t\\item $D_xf(x, y)$: \\ltcc{D\\_x f(x, y)}\n\t \t\\item $\\lim_{x \\to 0}$: \\ltc{lim\\_\\{x \\textbackslash to 0\\}}\n \t\\end{itemize}\t\n \t\\end{multicols}\n\t\n\\end{document}\n", "meta": {"hexsha": "a8e9a0156e09de945e92cdd923f5fd545ece65a9", "size": 20480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ib-math-misc/math-symbols-cheat-sheet.tex", "max_stars_repo_name": "davidmaamoaix/lecture-notes", "max_stars_repo_head_hexsha": "441449bdd8a46a2cc25c8034af28b73aba451ea6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-18T20:40:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T20:40:45.000Z", "max_issues_repo_path": "ib-math-misc/math-symbols-cheat-sheet.tex", "max_issues_repo_name": "davidmaamoaix/lecture-notes", "max_issues_repo_head_hexsha": "441449bdd8a46a2cc25c8034af28b73aba451ea6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ib-math-misc/math-symbols-cheat-sheet.tex", "max_forks_repo_name": "davidmaamoaix/lecture-notes", "max_forks_repo_head_hexsha": "441449bdd8a46a2cc25c8034af28b73aba451ea6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.5174013921, "max_line_length": 358, "alphanum_fraction": 0.6622070312, "num_tokens": 7234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.8887587839164801, "lm_q1q2_score": 0.8142004701791408}}
{"text": "\\section{The detail of the calculations}\nThe following sub-sections describe the details on some of the calculations. \nConsider two consecutive points $(x_1,y_1)$ and $(x_2,y_2)$ where $x_1 <= x <= x_2$ and $x_1 < x_2$, then interpolation is defined as\n\n\\begin{description}\n    \\item[Lin-lin interpolation] \n    \\begin{equation}\n        y = { y_2 ( x - x_1 ) + y_1 ( x_2 - x ) \\over ( x_2 - x_1 ) }\n    \\end{equation}\n    \\item[Lin-log interpolation] \n    \\begin{equation}\n        y = y_1 \\, \\left( y_2 \\over y_1 \\right)^{x - x_1 \\over x_2 - x_1}\n    \\end{equation}\n    \\item[Log-lin interpolation] \n    \\begin{equation}\n        y = { y_1 \\log(x_2/x) + y_2 \\log(x/x_1) \\over \\log(x_2/x_1) }\n    \\end{equation}\n    \\item[Log-log interpolation] \n    \\begin{equation}\n        y = y_1 \\, \\left( x \\over x_1 \\right)^{\\log(y_2/y_1) \\over \\log(x_2/x_1)}\n    \\end{equation}\n\\end{description}\n\nIn some calculation we will need the x location for the maximum of the relative error, $( y' - y ) / y$, between the \napproximate value, $y'$, and the ``exact'' value, \n$y$. This x location occurs where the derivative of the relative error is zero:\n\\begin{equation}    \\label{MaxXFormula}\n    { d(( y' - y ) / y ) \\over dx} = { d(y'/y - 1) \\over dx} = {d(y'/y) \\over dx} = { 1 \\over y^2 } \\left( y {dy' \\over dx } - y' { dy \\over dx } \\right) = 0\n\\end{equation}\n\n\n\\subsection{Converting log-log to lin-lin}\nThis section describes how fudge2dmath converts a \\highlight{fudge2dmathXY} object with interpolation of\n\\highlight{f2dmC\\_interpolationLogLog} (hence called log-log) to one with interpolation of \\highlight{f2dmC\\_inter-pol-ation-LinLin}\n(hence called lin--lin).\n\nFrom Eq.~\\ref{MaxXFormula} the maximum of the relative error occurs where,\n\\begin{equation}\n    { 1 \\over y } \\left( {dy' \\over dx } - {y' \\over y} { dy \\over dx } \\right) = \\left({ 1 \\over y }\\right) \\left\\{\n        { y_2 - y_1 \\over x_2 - x_1 } - \\left({y' \\over x}\\right) {\\log(y_2/y_1) \\over \\log(x_2/x_1)} \\right\\} = 0\n\\end{equation}\nThe solution is\n\\begin{equation}\n    { x \\over x_1 } = { a ( x_2 / x_1 - y_2 / y_1 ) \\over ( 1 - a ) ( y_2 / y_1 - 1 ) }\n\\end{equation}\nwhere $a = \\log(y_2/y_1) / \\log(x_2/x_1)$.\n", "meta": {"hexsha": "9afc3fe376d8388f72677f229df62f1478d16b76", "size": 2174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "numericalFunctions/Doc/ptwXY_appendix.tex", "max_stars_repo_name": "Mathnerd314/gidiplus", "max_stars_repo_head_hexsha": "ed4c48ab399a964fe782f73d0a065849b00090bb", "max_stars_repo_licenses": ["MIT-0", "MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2019-08-29T23:46:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T10:16:25.000Z", "max_issues_repo_path": "numericalFunctions/Doc/ptwXY_appendix.tex", "max_issues_repo_name": "Mathnerd314/gidiplus", "max_issues_repo_head_hexsha": "ed4c48ab399a964fe782f73d0a065849b00090bb", "max_issues_repo_licenses": ["MIT-0", "MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-04T16:14:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-01T01:54:34.000Z", "max_forks_repo_path": "numericalFunctions/Doc/ptwXY_appendix.tex", "max_forks_repo_name": "Mathnerd314/gidiplus", "max_forks_repo_head_hexsha": "ed4c48ab399a964fe782f73d0a065849b00090bb", "max_forks_repo_licenses": ["MIT-0", "MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2022-03-03T22:41:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T22:54:43.000Z", "avg_line_length": 46.2553191489, "max_line_length": 157, "alphanum_fraction": 0.6306347746, "num_tokens": 807, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422158380862, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.8140361528569313}}
{"text": "\nWe now glance over some of the very basic terminology from probability\ntheory needed in our analysis.  Such basic notions are found in all\nstandard introductory texts on probability, and for details that are\nmissing in the exposition below, we refer to the book by Grimmett and\nWelsh~\\cite{2014GrimmettG_WelshD-aa}.\n\n\\section{Probability space and random variables}\nA triple $(\\Omega, \\mathcal{F}, P)$ is called a \\emph{probability\n  space}; $\\Omega$ is, in general, a set called \\emph{sample space}\nwhich contains all conceptually possible outcomes of an experiment;\n$\\mathcal{F}$ is a \\emph{$\\sigma$-algebra} of events (sets) on\n$\\Omega$; $P$ is a countably-additive measure on $\\Omega$ called\n\\emph{probability}, i.e., a function\n$P: \\mathcal{F} \\mapsto \\mathbb{R}$ such that $P(a) \\geq 0$ for all\n$a \\in \\mathcal{F}$, $P(\\Omega) = 1$, and\n$P(\\sum_{n=1}^{\\infty}a_n) = \\sum_{n=1}^{\\infty} P(a_n)$ whenever\n$a_1, a_2, \\cdots$ are (pairwise) disjoint sets in $\\mathcal{F}$.  For\nexample, the \\emph{uniform distribution} is defined by choosing\n$P(a) = |a|/|\\Omega|$ where $|a|$ is the measure (cardinality) of $a$.\n\nBased on the probability space, given by the triple $(\\Omega,\n\\mathcal{F}, P)$, a \\emph{discrete random variable} is a function $X:\n\\Omega \\mapsto \\mathbb{R}$ such that $X^{-1}(b) := \\{ \\omega:\nX(\\omega) \\in b \\} \\in \\mathcal{F}$ for every set $b$ in the image of\n$X$.\n% for every $B \\in \\mathcal{B}(\\mathbb{R})$ where\n% $\\mathcal{B}(\\mathbb{R})$ is the Borel $\\sigma$-algebra of\n% $\\mathbb{R}$.\nNotice that, the sets $\\{ X \\in b \\} = \\{ \\omega: X(\\omega) \\in b \\} $\nare ``events'' (members of $\\mathcal{F}$) and the corresponding\nprobabilities are defined as $ P(X \\in b) := P(X^{-1}(b))$.\nThe \\emph{expectation} $E(\\cdot)$ is the average of a random variable. If\n$X \\geq 0$ is a random variable on $(\\Omega, \\mathcal{F}, P)$ then we\ndefine its expectation to be $E(X) = \\int X \\mathrm{d} P$, which for\na discrete random variable $X$ is:\n\\begin{equation}\nE(X) = \\sum_{x \\in R(X)} x P(X=x) = \\sum_{x} x P(X=x),\n\\end{equation}\n\n\\section{Conditional probability and conditional expectation}\nFrom now on, we focus on discrete random variables, as this is the setup we need. We say that two random variables $X$ and $Y$, are \\emph{independent} if\n\\begin{equation}\nP(X=x, Y=y) = P(X=x) P(Y=y),\n\\end{equation}\nfor all $x$ and $y$.  The \\emph{conditional probability} of\n$X=x$ under the condition $Y=y$ is given by\n\\begin{equation}\nP(X=x\\,|\\,Y=y) = \\frac{P(X=x, Y=y)}{P(Y=y)}.\n\\end{equation}\nTherefore, if $X$ and $Y$ are independent, we have\n\\begin{equation}\\label{eqn:indep}\nP(X=x\\,|\\,Y=y) = P(X=x).\n\\end{equation}\n\nIn general, we write, for $G \\subset \\Omega$,\n\\begin{equation}\nE(X| G)\n= \\sum_{x \\in R(X)} x \\frac{P(\\omega\\in G, X(\\omega)=x)}{P(G)}=\n\\sum_{x \\in R(X)} x P(X=x|G).\n\\end{equation}\nIn particular, we write\n\\begin{equation}\nE(X|Y=y)=E(X|G)\n\\mbox{ if }\nG=\\{Y=y\\}.\n\\end{equation}\nwhich is known as the \\emph{conditional expectation} of $X$ given $Y =\ny$.\nNow, we introduce the conditional random variable $E(X|Y)$ as follows\n\\begin{equation}\nE(X|Y)(\\omega)=E(X|Y=Y(\\omega)).\n\\end{equation}\nObviously\n\\begin{equation}\n\\{\\omega\\in \\Omega: E(X|Y)=z\\}=\\bigcup_{y:  E(X|Y=y)=z}\\{\\omega\\in \\Omega:  Y(\\omega)=y\\}\n\\end{equation}\nand, hence\n\\begin{equation}\nP\\{\\omega\\in \\Omega:  E(X|Y) (\\omega)=z\\}=\\sum_{y:   E(X|Y=y) =z}P\\{\\omega\\in \\Omega:  Y(\\omega)=y\\}\n\\end{equation}\nnamely\n\\begin{equation}\nP( E(X|Y)=z)=\\sum_{y:   E(X|Y=y)=z}P(Y=y).\n\\end{equation}\n\n%and this allows us to further define a random variable\n%$E(X|Y): \\Omega \\mapsto \\mathbb{R}$, called the \\emph{conditional\n%  expectation} of $X$ with respect to $Y$:\n%\\begin{equation}\\label{e:ez}\n  % \\left(  E(X|Y) \\right) (\\omega) = E(X| Y=Y(\\omega)).\n%E(X|Y) = Z, \\quad\\mbox{where}\\quad Z(\\omega) = E(X| Y=Y(\\omega)), \\quad \\omega\\in \\Omega.\n%\\end{equation}\n% we denote by $E(X\\,|\\,Y)$ that function of the random variable $Y$\n% whose value at $Y = y$ is $E(X\\,|\\, Y=y)$,\n\\begin{lemma} \\label{lem:EXY}\n\\begin{equation}\\label{e:eee}\nE(X) = E(E(X\\, | \\, Y)).\n\\end{equation}\n%Namely\n%\\begin{equation}\n%E(X) = \\sum_xx\\sum_y P(X= x, \\, Y = y)\n%\\end{equation}\n\\end{lemma}\n\\begin{proof}\nDenote $Z=E(X|Y)$, it follows that\n\\begin{align}\nE(E(X \\, | \\, Y))  = E(Z)\n&=\\sum_z zP(Z=z)\\\\\n&= \\sum_zz\\sum_{y: w(y)=z}P( Y=y )  \\\\\n&= \\sum_y w(y) P( Y = y )  \\\\\n &  = \\sum_y \\left(  \\sum_x x P(X = x \\, | \\, Y=y)  \\right) P(Y = y) \\\\\n\t\t\t           %& = \\sum_y \\sum_x x P(X= x \\, | \\, Y = y) P(Y = y) \\\\\n\t\t\t           & = \\sum_y \\sum_x x P(X= x, \\, Y = y) \\\\\n\t\t\t           & = \\sum_y \\sum_x x P(Y= y \\, | X = x) P(X = x) \\\\\n\t\t\t           & = \\sum_x x P(X = x) \\left( \\sum_y P(Y = y\\, | X = x) \\right) \\\\\n\t\t\t           & = \\sum_x x P(X = x) \\\\\n\t\t\t           & = E(X).\n\\end{align}\n\\end{proof}\n\n\\begin{lemma}\n\\begin{equation}\nE(X) = \\sum_xx\\sum_y P(X= x, \\, Y = y)\n\\end{equation}\n\\end{lemma}\n%This is easily verified by the definition of $E(X)$ and the fact that\n%\\begin{equation}\\label{e:mama-mia}\n%E(E(X\\, | \\, Y)) = \\sum_{y} E(X\\,|\\, Y=y) P(Y = y).\n%\\end{equation}\n\n\\newpage\n\n\\section{Central Limit Theorem}\n\\begin{theorem}[Lindeberg--Levy Central Limit Theorem]\n  Suppose ${X_1, X_2, \\dots}$ is a sequence of independent identical\n  distributed (i.i.d.) random variables with $E[X_i] = \\mu$ and\n  $Var[X_i] = \\sigma_2 < \\infty$. Then as n approaches infinity, the\n  random variables $\\sqrt{n}((\\frac{1}{n}\\sum_{i=1}^{n}X_i) - \\mu)$\n  converge in distribution to a normal distribution $N(0,\\sigma^2)$:\n\\begin{align}\n\\sqrt{n}((\\frac{1}{n}\\sum_{i=1}^{n}X_i) - \\mu)&\\stackrel{d}{\\longrightarrow} \\mathcal{N}(0,\\sigma^2).\n\\end{align}\n\\end{theorem}\n\n\\begin{lemma}[Levy's convergence theorem]\nLet $(F_n)$ be a sequence of distribution functions, and let $\\psi_n$ denote the characteristic function of $F_n$. Suppose that $g(\\theta):=lim_n \\psi_n(\\theta)$ exists for all $\\theta \\in \\mathbb{R}$, and that $g(\\cdot)$ is continuous at 0. Then $g=\\psi_F$ for some distribution function F, and $F_n \\stackrel{w}{\\longrightarrow} F$.\n\\end{lemma}\n\n\n\\begin{proof}\nFirst let's denote\n\\begin{align}\nZ_n=\\frac{X_1+...+X_n-n\\mu}{ \\sqrt{n \\sigma^2}}=\\sum_{i=1}^{n} \\frac{X_i-\\mu}{ \\sqrt{n \\sigma^2}}=\\sum_{i=1}^{n} \\frac{Y_i}{ \\sqrt{n }},\n\\end{align}\nwhere  in the last step we defined the new random variables $Y_i=\\frac{X_i-\\mu}{ \\sigma}$, each with zero mean and unit variance.\n\nThen we wanna to prove the characteristic function of $Z_n$ converges to the characteristic function of a random variable with standard normal distribution.\nThe characteristic function of a random variable X is defined as\n\\begin{align}\n\\psi_X(\\theta)=\\mathbb{E}(e^{i\\theta X})=\\int_\\mathbb{R}e^{i\\theta X} f_X(x)dx,\n\\end{align}\nwhere $f_X$ is the probability density function of X.\n\nProperty 1. If a random variable X has moments up to k-th order, then the characteristic function $\\psi_X$ is k times continuously differentiable on the entire real line. Moreover,\n\\begin{align}\n\\mathbb{E}[X^k]=(-i)^k \\psi_X^k(0).\n\\end{align}\n\nProperty 2. If $X_1,...,X_n$ are independent random variables, and $a_1,...,a_n$ are some constants, then the characteristic function of the linear combination of the $X_i's$ is\n\\begin{align}\n\\psi_{a_1 X_1+...+a_n X_n}(\\theta)=\\psi_{X_1}(a_1\\theta)...\\psi_{X_n}(a_n\\theta).\n\\end{align}\n\nThe characteristic function of $Z_n$ is given by\n\\begin{align}\n\\psi_{Z_n}(\\theta)=\\psi_{\\sum_{i=1}^{n} \\frac{Y_i}{ \\sqrt{n }}}(\\theta)=\\psi_{Y_1}(\\frac{\\theta}{ \\sqrt{n }})\\cdot \\psi_{Y_2}(\\frac{\\theta}{ \\sqrt{n }})...\\psi_{Y_n}(\\frac{\\theta}{ \\sqrt{n }})=[\\psi_{Y_1}(\\frac{\\theta}{ \\sqrt{n }})]^n,\n\\end{align}\n\nwhere in the last step we used the fact that all of the $Y_i$ are identically distributed. The characteristic function of $Y_1$ is, by Taylor's theorem,\n\\begin{align}\n\\psi_{Y_1}(\\frac{\\theta}{ \\sqrt{n }})=1-\\frac{\\theta^2}{2n}+c\\frac{\\theta^3}{6n^{\\frac{3}{2}}}+o(\\frac{\\theta^3}{n^{\\frac{3}{2}}}), \\theta  \\rightarrow 0.\n\\end{align}\nTherefore\n\\begin{align}\n\\psi_{Z_n}(\\theta)=\\bigg ( 1-\\frac{\\theta^2}{2n}+c\\frac{\\theta^3}{6n^{\\frac{3}{2}}}+o(\\frac{\\theta^3}{n^{\\frac{3}{2}}}) \\bigg )^n \\rightarrow e^{-\\frac{1}{2}\\theta^2}, n  \\rightarrow \\infty,\n\\end{align}\nwhich converges to the characteristic function of a random variable with standard normal distribution.\nHence as a corollary of the lemma,\n\\begin{align}\nF_{Z_n}&\\stackrel{w}{\\longrightarrow} \\mathcal{N}(0, 1).\n\\end{align}\nTherefore\n\\begin{align}\n\\sqrt{n}((\\frac{1}{n}\\sum_{i=1}^{n}X_i) - \\mu)&\\stackrel{d}{\\longrightarrow} \\mathcal{N}(0,\\sigma^2).\n\\end{align}\n\n\\end{proof}\n\n\nHere the normal distribution $N(0,\\sigma^2)$ means $f(x)=\\frac{1}{\\sqrt{2\\pi}}e^{-\\frac{x^2}{2\\pi}}$ in terms of the probability distribution function.\n\nA sequence $X_1, X_2$, ... of real-valued random variables is said to converge in distribution to a random variable X if\n$ \\lim _{n\\to \\infty }F_{n}(x)=F(x)$,\nfor every number $x \\in \\mathbb{R}$ at which F is continuous. Here $F_n$ and F are the cumulative distribution functions of random variables $X_n$ and X, respectively.\n\n\\section{Random Walk and Brownian Motion}\n\nDefine the random variable $X_i$ as follows. $X_i=1$ if the $i_{th}$ coin toss results in heads, and $X_i=-1$ if the $i_{th}$ coin toss results in tails. Thus,\n\\begin{equation}\n  P(X_i=1)=P(X_i=-1)=\\frac{1}{2}.\n\\end{equation}\nWe also have $E(X_i)=0$ and $\\mbox{var}(X_i)=1$.\n\nFix $ t \\geq 0$, choose $\\delta$ small enough as the time step s.t. $N=t/\\delta\\in \\mathbb{N}$. Then the current location after $n_{th}$ step is defined as\n\\begin{equation}\n  S_N(n \\delta)= \\sum_{i=1}^{n} X_i.\n\\end{equation}\nHence $S_N(t)=S_N(N \\delta)= \\sum_{i=1}^{N} X_i$ and $S_N(0)= 0$.\n\nThen we rescale $S_N(t)$ by\n\\begin{equation}\n  \\bar{S}_N(t)=\\sqrt{\\delta} S_N(t)=\\sqrt{N\\delta}\\sqrt{N}\\frac{S_N(t)}{N}\n  =\\sqrt{t}\\sqrt{N}\\frac{\\sum_{i=1}^{N} X_i}{N}\n\\end{equation}\nIt's known that $\\{X_1,...,X_N\\}$ is a sequence of independent and\nidentically distributed random variables drawn from the same\ndistribution, with $E(X_i)=0$ and $\\mbox{var}(X_i)=1$.\n\n\nThen according to the central limit theorem, as $n$ approaches infinity,\n\\begin{align}\n  \\frac{\\bar{S}_N(t)}{\\sqrt{t}}&=\\sqrt{N}\\frac{\\sum_{i=1}^{N} X_i}{N}\\\\\\notag\n  &=\\sqrt{N}(\\frac{\\sum_{i=1}^{N} X_i}{N}-0)\\stackrel{d}{\\longrightarrow} \\mathcal{N}(0,1)\\\\\n  \\bar{S}_N(t)&\\stackrel{d}{\\longrightarrow} \\mathcal{N}(0,t).\n\\end{align}\nIf we denote\n\\begin{equation}\n  W_t=\\lim_{N\\rightarrow \\infty} \\bar{S}_N(t)=\\lim_{\\delta\\rightarrow 0} \\sqrt{\\delta} \\sum_{i=1}^{N} X_i,\n\\end{equation}\nthen we want to prove  $W_t$ that we obtained is indeed a Brownian motion.\n\\begin{definition}\nA continuous-time stochastic process $W_t$ is called Bronwian motion if\n\\begin{enumerate}\n\\item $W_0=0$\n\\item $W_t$ is continuous a.s.\n\\item $W_t \\sim \\mathcal{N}(0,t)$\n\\item $W_t$ has independent increments\n\\end{enumerate}\n\\end{definition}\n\n\\section{Brownian motion as the limit of random walk: proof}\n\n\n\\subsection{Starting Points}\n\\begin{align}\n  W_0&=\\lim_{N\\rightarrow \\infty} \\bar{S}_N(0)\\\\\\notag\n     &=\\lim_{N\\rightarrow \\infty} \\sqrt{\\delta} S_N(0)\\\\\\notag\n     &=\\lim_{N\\rightarrow \\infty} \\sqrt{\\delta} 0\\\\\\notag\n     &=0\\\\\\notag\n\\end{align}\n\n\\subsection{Continuity}\n\\begin{align}\n   W_t&=\\lim_{N\\rightarrow \\infty} \\bar{S}_N(t)=\\lim_{N\\rightarrow \\infty} \\sqrt{\\delta} S_N(t)\\\\\n   W_{t-\\delta}&=\\lim_{N\\rightarrow \\infty} \\bar{S}_N(t-\\delta)=\\lim_{N\\rightarrow \\infty} \\sqrt{\\delta} S_N(t-\\delta)\\\\\n   |W_{t-\\delta}-W_t|&=|\\lim_{N\\rightarrow \\infty} \\sqrt{\\delta} S_N(t-\\delta)-\\sqrt{\\delta}S_N(t)|\\\\\\notag\n   &=|\\lim_{N\\rightarrow \\infty} \\sqrt{\\delta} S_N((N-1)\\delta)-\\sqrt{\\delta}S_N(N \\delta)|\\\\\\notag\n   &=|\\lim_{N\\rightarrow \\infty} \\sqrt{\\delta} X_{N}|\\\\\\notag\n   &=\\sqrt{\\delta},\n\\end{align}\nwhich tends to 0 as $\\delta$ approaches 0. Therefore $W_t$ is continuous in time t.\n\n\\subsection{Distribution Function}\nWe have already proved that\n\\begin{equation}\n   W_t \\sim \\mathcal{N}(0,t).\n\\end{equation}\n\n\\subsection{Independent Increments}\nFix $ t,s \\geq 0$, choose $\\delta$ small enough as the time step s.t. $N_1=t/\\delta$, $N_2=s/\\delta\\in \\mathbb{N}$.\n\\begin{align}\n   W_t&=\\lim_{N_1\\rightarrow \\infty} \\bar{S}_{N_1}(t)=\\lim_{N_1\\rightarrow \\infty} \\sqrt{\\delta} S_{N_1}(t)\\\\\n   W_{t+s}&=\\lim_{N_1+N_2\\rightarrow \\infty} \\bar{S}_{N_1+N_2}(t+s)=\\lim_{N_1+N_2\\rightarrow \\infty} \\sqrt{\\delta} S_{N_1+N_2}(t+s)\\\\\n   W_{t+s}-W_t&=\\lim_{N_1,N_2\\rightarrow \\infty} \\sqrt{\\delta} S_{N_1+N_2}(t+s)-\\sqrt{\\delta} S_{N_1}(t)\\\\\\notag\n   &=\\lim_{N_1,N_2\\rightarrow \\infty} \\sqrt{\\delta} S_{N_1+N_2}((N_1+N_2)\\delta)-\\sqrt{\\delta} S_{N_1}(N_1\\delta)\\\\\\notag\n   &=\\lim_{N_1,N_2\\rightarrow \\infty} \\sqrt{\\delta} \\sum_{i=1}^{N_1+N_2} X_i-\\sqrt{\\delta} \\sum_{i=1}^{N_1} X_i\\\\\\notag\n   &=\\lim_{N_1,N_2\\rightarrow \\infty} \\sqrt{\\delta} \\sum_{i=N_1+1}^{N_1+N_2} X_i\\\\\\notag\n   &=\\lim_{N_2\\rightarrow \\infty} \\sqrt{\\delta} \\sum_{i=1}^{N_2} X_i\\\\\\notag\n   &=\\lim_{N_2\\rightarrow \\infty} \\sqrt{\\delta} S_{N_2}(N_2\\delta)\\\\\\notag\\\n   &=\\lim_{N_2\\rightarrow \\infty} \\sqrt{\\delta} S_{N_2}(s)\\\\\\notag\n   &=\\lim_{N_2\\rightarrow \\infty} \\bar{S}_{N_2}(s)\\\\\\notag\n   &=W_s.\n\\end{align}\nHence $W_{t+s}-W_t$  has the same distribution as $W_s$ for $\\forall t,s \\geq 0$.\n\nThen we want to prove for any positive integer n and any $0 = t_0 < t_1 <...< t_n$, the random variables $W_{t_{i+1}} - W_{t_{i}}$, i = 1, ..., n, are mutually independent. Moreover, it suffices to prove $W_{t_{i}}-W_{t_{i-1}}$ and $W_{t_{i+1}}-W_{t_{i}}$ are independent.\n\nIf we define $t_{i}=N_{i}\\delta$, by definition, $W_{t_{i-1}}=\\lim_{\\delta\\rightarrow0}\\sqrt{\\delta}\\sum\\limits_{j=1}^{N_{i-1}}X_j$, $W_{t_{i}}=\\lim_{\\delta\\rightarrow0}\\sqrt{\\delta}\\sum\\limits_{j=1}^{N_i}X_j$, $W_{t_{i+1}}=\\lim_{\\delta\\rightarrow0}\\sqrt{\\delta}\\sum\\limits_{j=1}^{N_{i+1}}X_j$\n~\\\\So we have $$W_{t_{i}}-W_{t_{i-1}}=\\lim_{\\delta\\rightarrow0}\\sqrt{\\delta}\\sum\\limits_{j=N_{i-1}+1}^{N_{i}}X_j=:Y_i$$\n$$W_{t_{i+1}}-W_{t_{i}}=\\lim_{\\delta\\rightarrow0}\\sqrt{\\delta}\\sum\\limits_{j=N_{i}+1}^{N_{i+1}}X_j=:Y_{i+1}$$\nThen we want to prove $Y_{i}$ and $Y_{i+1}$ are independent, or equivalently, $P(Y_i<a, Y_{i+1}<b)=P(Y_i<a)P(Y_{i+1}<b)$\n~\\\\Proof: By definition, $$P(Y_i<a, Y_{i+1}<b)$$\n$$=P(\\lim_{\\delta\\rightarrow0}\\sqrt{\\delta}\\sum\\limits_{j=n_{i-1}+1}^{n_{i}}X_j<a, \\lim_{\\delta\\rightarrow0}\\sqrt{\\delta}\\sum\\limits_{j=n_{i}+1}^{n_{i+1}}X_j<b)$$\n$$=\\lim_{\\delta\\rightarrow0}P(\\sqrt{\\delta}\\sum\\limits_{j=n_{i-1}+1}^{n_{i}}X_j<a, \\sqrt{\\delta}\\sum\\limits_{j=n_{i}+1}^{n_{i+1}}X_j<b)$$\n$$=\\lim_{\\delta\\rightarrow0}P(\\sqrt{\\delta}\\sum\\limits_{j=n_{i-1}+1}^{n_{i}}X_j<a)P(\\sqrt{\\delta}\\sum\\limits_{j=n_{i}+1}^{n_{i+1}}X_j<x_{i+1})$$\n$$=P(Y_i<x_i)P(Y_{i+1}<b)$$\n\nRemark 1: Here we used the property that almost sure convergence implies convergence in probability and convergence in probability implies convergence in distribution.\n\nRemark 2:\nIn this case, we construct a Bronwian motion with i.i.d. random variables $\\{X_i\\}$ where the domain for $X_i$ is  $\\{-1,1\\}$. Therefore the domain $\\Omega$ for the random variables is $\\{-1,1\\}\\times...\\times\\{-1,1\\}\\times...=\\{-1,1\\}^{\\infty}$ in the notation of product space.\n\nActually according to the Wiener's theroem, we construct a Bronwian motion with any i.i.d. random variables $\\{X_i\\}$. Here we assume nothing for the random variable as long as it's not determined. Suppose the probability space  for $X_i$ is  $(S, \\sigma(S),P')$ . Hence the domain $\\Omega$ for the random variables is $S\\times...\\times S\\times...=S^{\\infty}$.\n\nFor any given time $t$, $W_t$ is a random variable. The value of $W_t$ is completely determined by the i.i.d. random variables $\\{X_i\\}$. Therefore the domain  for the $W_t$ is $\\Omega=S^{\\infty}$, where $S$ is the domain for $X_i$. The $\\sigma$ -algebra   $\\mathcal{F}=\\sigma((A_1\\times A_2\\times ...\\times A_n \\times...):A_i\\in \\sigma(S))$. The measure  is $P(A_1\\times A_2\\times ...\\times A_n \\times...)=\\Pi_{i=1}^{\\infty}P'(A_i)$, where $P'$ is the measure on $S$. Therefore $(\\Omega, \\mathcal{F},P)$ is the probability space for a random variable $W_t$.\n\n\n", "meta": {"hexsha": "7cdab3d5d06b1bafb66b8ca66fa5d8522291d3b2", "size": 15906, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/probability.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/probability.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/probability.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.8620689655, "max_line_length": 558, "alphanum_fraction": 0.6540299258, "num_tokens": 6055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896737173119, "lm_q2_score": 0.8840392756357327, "lm_q1q2_score": 0.8140142361659151}}
{"text": "\n\\subsection{Smoothing kernel estimation}\n\n\\subsubsection{Smoothed kernels}\n\nWe have \\(K(x-x_i)\\)\n\nWe can smooth this to:\n\n\\(K_h(x-x_i)=\\dfrac{1}{h}K(\\dfrac{x-x_i}{h})\\)\n\nWhere \\(h>0\\) is the smoothing bandwidth.\n\n\\(f(x)=\\dfrac{1}{n}\\sum_{i=1}^nK_h(x-x_i)\\)\n\n", "meta": {"hexsha": "607c573e421ef2a8bae6ef32ed4336808f07a64e", "size": 259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/nonParametric/02-02-kernelSmoothing.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/nonParametric/02-02-kernelSmoothing.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/nonParametric/02-02-kernelSmoothing.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.1875, "max_line_length": 46, "alphanum_fraction": 0.6525096525, "num_tokens": 97, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.8139509652097653}}
{"text": "\n\\subsection{The projection and annihilation matrices}\n\n\\subsubsection{The projection matrix}\n\nWe have \\(X\\).\n\nThe projection matrix is \\(X(X^TX)^{-1}X^T\\)\n\nThe projection matrix maps from actual y to predicted y\n\n\\(\\hat y = Py\\)\n\nEach entry refers to the covariance between actual and fitted\n\n\\(p_{ij}=\\dfrac{Cov (\\hat y_i, y_j}{Var (y_j)}\\)\n\n\\subsubsection{The annihilation matrix}\n\nWe can get residuals too:\n\n\\(u=y-\\hat y=y-py=(1-P)y\\)\n\n\\(1-P\\) is called the annihilator matrix\n\nWe can now use the propagation of uncertainty\n\n\\(\\Sigma^f = A\\Sigma^x A^T\\)\n\nTo get:\n\n\\(\\Sigma^u = (I-P)\\Sigma^y (I-P)\\)\n\nAnnihilator matrix is:\n\n\\(M_X=I-X(X^TX)^{-1}X^T\\)\n\nCalled this because:\n\n\\(M_XX=X-X(X^TX)^{-1}X^TX\\)\n\n\\(M_XX=0\\)\n\nIs called residual maker\n\n", "meta": {"hexsha": "73c2eb81f79c7582d599ac62ad6bb54b0118e4e6", "size": 744, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/ols/03-01-projection.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/ols/03-01-projection.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/ols/03-01-projection.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.1739130435, "max_line_length": 61, "alphanum_fraction": 0.6720430108, "num_tokens": 245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191309994467, "lm_q2_score": 0.8519528094861981, "lm_q1q2_score": 0.8138868176108919}}
{"text": "\\tableofcontents\n\n%todo: thm = theorem\n%todo: lm = lemma\n%todo: def = definition\n%todo: col = corollary\n\n%================================\n%::::::::::::::::::::::::::::::::\n\\chapter{Metric Spaces}\n%::::::::::::::::::::::::::::::::\n%================================\n\n\n%================================\n\\section{Metric Spaces}\n%================================\n\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: metric axioms}\n\tLet $X$ be any set.\n\t\n\tA function $d: X \\times X \\to \\mathbb R_{\\ge 0}$ is \\textit{metric function}, or, simply, \\textit{metric on $X$} iff it satisfies the \\textit{metric axioms}. That is, for any $x, y, z \\in X$:\n\t\\begin{enumerate}[\\bf M1. ]\n\t\t\\item $d(x,y) = 0$ iff $x = y$;\n\t\t\\item $d(x,y) = d(y,x)$;\n\t\t\\item $d(x, z) \\le d(x,y) + d(y,z)$.\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: metric space}\n\tLet $X$ be any set and let $d$ be a structure on $X$.\n\t\n\tThe pair $(X, d)$ is called a \\textit{metric space} iff $d$ is a metric on $X$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: ball}\n\tA $\\mathbb X = (X, d)$ be a metric space, let $x \\in X$ and let $\\varepsilon \\in \\mathbb R_{> 0}$.\n\t\n\tAn \\textit{open $\\varepsilon$-ball}, or just $\\varepsilon$-ball, about $x$ is defined to be the set\n\t$$\n\tB_\\varepsilon (x; d) := \\{ y \\in X : d(x,y) < \\varepsilon \\}.\n\t$$\n\t\n\tA \\textit{closed ball} is defined to be the set\n\t$$\n\t\\overline{B}_\\varepsilon (x; d) := \\{ y \\in X : d(x,y) \\le \\varepsilon \\}.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tAs\n\t$$\n\t\\mathbb X_0 = (X, d_0), \\ \\mathbb X_1 = (X, d_1), \\ \\mathbb X_2 = (X, d_2), \\ \\ldots\n\t$$\n\tare different although they share the same set $X$, for any $x \\in X$ and any $\\varepsilon \\in \\mathbb R_{> 0}$,\n\t$$\n\tB_\\varepsilon(x; d_1),\\ B_\\varepsilon (x; d_2), \\ B(x; d_3), \\ \\ldots\n\t$$\n\tare also different. However, if confusion is unlikely, we simply write ``$B_\\varepsilon(x)$'' for ``$B_\\varepsilon(x; d)$''.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t\\label{eg: Euclidean metric space}\n\tThe \\textit{Euclidean metric space} $\\mathbb X = (X, d)$ is an $n$-dimensional set $X$ equipped with the \\textit{Euclidean metric} $d$ defined as\n\t$$\n\td(x,y) := \\left( \\sum_{i = 1}^n |x_i - y_i|^2 \\right)^\\frac{1}{2}.\n\t$$\n\t\n\tThis is also called \\textit{standard Euclidean metric}, in contrast to the \\textit{non-standard Euclidean metrics}\n\t$$\n\td_p(x,y) := \\left( \\sum_{i = 1}^n |x_i - y_i|^p \\right)^\\frac{1}{p}, \\quad p \\ge 1.\n\t$$\n\t\n\tIn particular,\n\t$$\n\td_\\infty (x,y) := \\max_{1 \\le i \\le n} |x_i - y_i|.\n\t$$\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tA \\textit{discrete metric space} $\\mathbb X = (X, d)$ is a set $X$ equiped with the \\textit{discrete metric} $d_\\mathrm{dsic}$ defined as\n\t$$\n\td_\\mathrm{disc}(x,y) :=\n\t\\begin{cases}\n\t\t0, & \\text{if $x = y$}; \\\\\n\t\t1, & \\text{else}.\n\t\\end{cases}\n\t$$\n\t\n\tThis is an equivalent definition of the discrete metric:\n\t$$\n\td_\\mathrm{disc}(x, y) := (\\mathrm{sgn}(d(x,y)))^2,\n\t$$\n\twhere $\\mathrm{sgn}(\\cdot)$ is a \\href{https://en.wikipedia.org/wiki/Sign_function}{sign function}, and $d$ is any metric on $X$.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t\\footnote{\n\t\tSee \\href{https://en.wikipedia.org/wiki/Minkowski_inequality}{Minkowski inequality}.\n\t}\n\tLet $\\mathbb I = (C{[a,b]}, d_p)$ be a metric space where $C{[a,b]}$ denotes the set of all continuous mapping $\\mathbb R_{[a,b]} \\to \\mathbb R$, and $p > 0$, and the metric $d_p$ is defined as\n\t$$\n\td_p(f, g) := \\left( \\int_{a}^{b} |f(t) - g(t)|^p \\mathrm{d} t \\right)^\\frac{1}{p}.\n\t$$\n\t\n\tIn particular,\n\t$$\n\td_\\infty (f,g) := \\sup_{t \\in \\mathbb R_{[a,b]}} |f(t) - g(t)|.\n\t$$\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t\\footnote{\n\t\tSee \\href{https://en.wikipedia.org/wiki/Hausdorff_distance}{Hausdorff distance}.\n\t}\t\n\tLet $\\mathbb X = (X, d)$ be a metric space. The \\textit{Hausdorff metric} $d_H$ on $2^X \\setminus \\{\\emptyset\\}$ is defined as\n\t$$\n\td_H := \\max \\left\\{ \\sup_{x \\in X}d(x,Y), \\sup_{y \\in Y} d(y, X)\\right\\},\n\t$$\n\twhere\n\t$$\n\t\\begin{aligned}\n\t\td(x,Y) := \\inf_{y \\in Y}(x,y), \\text{ and } d(y, X) := \\inf_{x \\in X} (y, x).\n\t\\end{aligned}\n\t$$\n\\end{example}\n%--------------------------------\n\n\n%================================\n\\section{Open Sets in Metric Spaces}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: open set in metric space}\n\tLet $\\mathbb X = (X, d)$ be a metric space, and let $U \\subseteq X$.\n\t\n\t$U$ is said to be \\textit{open in $\\mathbb X$}, iff for any $y \\in U$, there exists $\\varepsilon \\in \\mathbb R_{> 0}$, such that $B_\\varepsilon(y) \\subseteq U$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: open balls of point inside open ball}\n\tLet $\\mathbb X = (X, d)$ be a metric space, let $x \\in A$ and let $\\varepsilon \\in \\mathbb R_{> 0}$.\n\t\n\tFor any $y \\in B_\\varepsilon (x)$, there is a $\\delta \\in \\mathbb R_{> 0}$ such that $B_\\delta (y) \\subseteq B_\\varepsilon(x)$.\n\t\n\t\\begin{proof}\n\t\tFor any $y \\in B_\\varepsilon (x)$, by the definition of open balls (Definition \\ref{def: ball}), we have $d(x,y) < \\varepsilon$.\n\t\t\n\t\tLet $\\delta \\in \\mathbb R_{> 0}$ such that $\\delta + d(x,y) = \\varepsilon$.\n\t\t\n\t\tBy M3 in metric axioms (Definition \\ref{def: metric axioms}), for any $z \\in A$ with $d(y,z) < \\delta$, we have\n\t\t$$\n\t\td(x, z) \\le d(y, z) + d(x, y) < \\varepsilon.\n\t\t$$\n\t\t\n\t\tThus, again, by the definition of open balls, we have $B_\\delta(y) \\subseteq B_\\varepsilon(x)$.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n% Shared on Proof Wiki\n% https://proofwiki.org/wiki/Set_is_Open_iff_Union_of_Open_Balls}{ProofWiki\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: set is open iff union of open balls}\n\tLet $\\mathbb X = (X, d)$ be a metric space, and let $U \\subseteq X$.\n\t\n\t$U$ is open in $\\mathbb X$ iff it is a union of open balls.\n\t\n\t\\begin{proof}\n\t\tFirst, prove $\\Rightarrow$.\n\t\t\n\t\tAs $U$ is open, for any $y \\in U$, there exists $\\varepsilon_y \\in \\mathbb R_{> 0}$ such that $B_{\\varepsilon_y}(y) \\subseteq U$.\n\t\t\n\t\tTherefore,\n\t\t$$\n\t\tU = \\bigcup_{y \\in U} B_{\\varepsilon_y} (y).\n\t\t$$\n\t\t\n\t\t$\\qedlm$\n\t\t\n\t\tNow, prove $\\Leftarrow$.\n\t\t\n\t\tAiming for a contradiction, suppose $U$ is a union of open balls but not open.\n\t\t\n\t\tAs $U$ is not open, there is a $y \\in U$ such that for any $\\varepsilon \\in \\mathbb R_{> 0}$, $B_\\varepsilon (y) \\not \\subseteq U$.\n\t\t\n\t\tAs $U$ is a union of open balls, there is an $x \\in U$ and $r \\in \\mathbb R_{> 0}$ such that $y \\in B_r (x)$.\n\t\t\n\t\tBy Proposition \\ref{prop: open balls of point inside open ball}, there exists a $\\delta \\in \\mathbb R_{> 0}$ such that $B_\\delta (y) \\subseteq B_r (x)$.\n\t\t\n\t\tThis is a contradiction by the assumption.\n\t\t\n\t\tThus, $U$ has to be open.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n% Shared on ProofWiki\n% https://proofwiki.org/wiki/Metric_Space_is_Hausdorff\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: metric space is hausdorff}\n\tLet $\\mathbb X = (X, d)$ be any metric space.\n\t\n\t$\\mathbb X$ is \\textit{Hausdorff}. That is, For any distinct points $x,y \\in X$, we can always find an $\\varepsilon \\in \\mathbb R_{> 0}$ such that\n\t$$\n\tB_\\varepsilon(x) \\cap B_\\varepsilon(y) = \\emptyset.\n\t$$\n\t\n\t\\begin{proof}\n\t\tAiming for a contradiction, suppose there are $x,y \\in X$ with $x \\ne y$, such that for any $\\varepsilon \\in \\mathbb R_{> 0}$, we can always find a $z \\in X$ such that\n\t\t$$\n\t\tz \\in B_\\varepsilon(x) \\cap B_\\varepsilon(y).\n\t\t$$\n\t\t\n\t\tLet $r = d(x,y)/2$, and let $z \\in B_r(x) \\cap B_r(y)$.\n\t\t\n\t\tAs $z \\in B_r(x)$, by the definition of open balls (Definition \\ref{def: ball}), $d(x,z) < r$; as $z \\in B_r(y)$, similarly, $d(y,z)< r$. Then we have\n\t\t$$\n\t\td(x, z) + d(y, z) < 2r = d(x,y).\n\t\t$$\n\t\t\n\t\tThis contradicts the metric axioms M3 (Definition \\ref{def: metric axioms}).\n\t\t\n\t\tThus $\\mathbb X$ is Hausdorff.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: closed set in metric space}\n\tLet $\\mathbb X = (X, d)$ be any metric space, and let $V \\subseteq X$.\n\t\n\t$V$ is said to be \\textit{closed} in $\\mathbb X$, iff there is an open set $U$ satisfies $X \\setminus U = V$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: singleton in metric space is closed}\n\tIn a metric space, any singleton is closed.\n\t\n\t\\begin{proof}\n\t\tLet $\\mathbb X =(X, d)$ be a metric space, let $x \\in X$, and let $y \\in X \\setminus \\{x\\}$.\n\t\t\n\t\tAs $M$ is Hausdorff (Proposition \\ref{prop: metric space is hausdorff}), there is an $\\varepsilon \\in \\mathbb R_{> 0}$ such that\n\t\t$$\n\t\t0 < \\varepsilon < d(x,y),\n\t\t$$\n\t\tthus $X \\setminus \\{x\\}$ is open, hence, by Definition \\ref{def: metric axioms}, its complement $\\{x\\}$ is open.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n% Shared on ProofWiki\n% https://proofwiki.org/wiki/Finite_Intersection_of_Open_Sets_of_Metric_Space_is_Open\n%--------------------------------\n\\begin{proposition}\n\tLet $\\mathbb X = (X, d)$ be a metric space, denote $\\mathcal T$ for the family of open subsets of $X$.\n\t\n\tThen $\\mathcal T$ satisfies the following conditions:\n\t\n\t\\begin{enumerate}[\\bf O1.]\n\t\t\\item $X, \\emptyset \\in \\mathcal T$;\n\t\t\\item For any $\\mathcal U \\subseteq \\mathcal T$, $\\bigcup \\mathcal U \\in \\mathcal T$; in words, $\\mathcal T$ is closed under arbitrary union;\n\t\t\\item For any finite $\\mathcal V \\subseteq \\mathcal T$, $\\bigcap \\mathcal V \\in \\mathcal T$; in words, $\\mathcal T$ is closed under finite intersection.\n\t\\end{enumerate}\n\t\n\t\\begin{proof} \\\n\t\t\\begin{enumerate}[\\bf O1.]\n\t\t\t\\item\n\t\t\t\tAs $\\emptyset$ is the subset of any set, $\\emptyset \\in \\mathcal T$. $\\bigcup \\emptyset = \\emptyset \\in \\mathcal T$.\n\t\t\t\n\t\t\t\tBy Definition \\ref{def: closed set in metric space}, $X = X \\setminus \\emptyset$.\n\t\t\t\t\n\t\t\t\t\\qedlm\n\t\t\t\t\n\t\t\t\\item \n\t\t\t\tLet $\\mathcal U \\subseteq \\mathcal T$, and denote $\\mathcal O$ for the open balls in $M$.\n\t\t\t\n\t\t\t\tFor any $U \\in \\mathcal U$, there is an $\\mathcal O_U \\subseteq \\mathcal O$ such that $U = \\bigcup \\mathcal O_U$. \n\t\t\t\t\n\t\t\t\tThen we have\n\t\t\t\t$$\n\t\t\t\t\\bigcup \\mathcal U = \\bigcup_{U \\in \\mathcal U} \\left( \\bigcup \\mathcal O_U \\right) = \\bigcup_{U \\in \\mathcal U} \\mathcal O_U.\n\t\t\t\t$$\n\t\t\t\t\n\t\t\t\tBy Proposition \\ref{prop: set is open iff union of open balls}, $\\bigcup \\mathcal U$ is open.\n\t\t\t\t\n\t\t\t\t\\qedlm\n\t\t\t\t\n\t\t\t\\item\n\t\t\t\tLet $\\mathcal V$ be a finite subset of $\\mathcal T$.\n\t\t\t\t\n\t\t\t\tAiming for a contradiction, suppose $\\bigcap \\mathcal V$ is not open.\n\t\t\t\t\n\t\t\t\tBy Definition \\ref{def: open set in metric space}, there exists a $y \\in \\bigcap \\mathcal V$ such that for any $\\varepsilon \\in \\mathbb R_{> 0}$, $B_\\varepsilon(y) \\setminus \\bigcap \\mathcal V \\ne \\emptyset$.\n\t\t\t\t\n\t\t\t\tBy De Morgan's law, we have\n\t\t\t\t$$\n\t\t\t\t\\bigcup_{V \\in \\mathcal V}(B_\\varepsilon (y) \\setminus V) \\ne \\emptyset.\n\t\t\t\t$$\n\t\t\t\t\n\t\t\t\tThus, there exists $V \\in \\mathcal V$ such that $B_\\varepsilon (y) \\setminus V \\ne \\emptyset$.\n\t\t\t\t\n\t\t\t\tAs $V \\in \\mathcal T$ and $\\varepsilon$ is arbitrarily given, by Proposition \\ref{prop: open balls of point inside open ball}, $y \\notin V$. This is a contradiction.\n\t\t\t\t\n\t\t\t\tThus, $\\bigcap \\mathcal V$ is open.\n\t\t\t\t\n\t\t\t\t\\qedlm\n\t\t\\end{enumerate}\n\t\t\n\t\tThus, the theorem is proved.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tInfinite intersections of open sets in some metric spaces are not necessarily open.\n\t\n\t\\begin{proof}\n\t\tConsider $\\mathbb R$ is a Euclidean metric space, and denote $\\mathcal T$.\n\t\t\n\t\tClearly, for any $n \\in \\mathbb N_{> 0}$ and for any $x \\in X$, the open interval $B_{\\frac{1}{n}}(x)$ is open, but\n\t\t$$\n\t\t\\bigcap\\left\\{ B_{\\frac{1}{n}}\\left( x \\right) : n \\in \\mathbb N_{> 0} \\right\\} = \\{ x \\} .\n\t\t$$\n\t\t\n\t\tFor any $\\varepsilon \\in \\mathbb R_{> 0}$, $B_\\varepsilon(x) \\setminus \\{x\\}$ is not empty, thus $\\{x\\}$ is not open.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n\\section{Restrictions and Metric Subspaces}\n%================================\n\n\nRestriction of metric function is a useful tool to describe the relation between metric spaces with different sets but ``same'' metric function on the sets.\n\nAs a restriction of a relation $R$ on $X \\times Y$ to a subset $A \\times B \\subseteq X \\times Y$ is defined to be\n$$\nR \\restriction_{A \\times B} := R \\cap (X \\times Y),\n$$\na restriction of a metric $d$ on a set $S$ to a subset $U \\subseteq S$ is defined to be\n$$\nd \\restriction_{(U \\times U) \\times \\mathbb R_{> 0}} := d \\cap ((U \\times U) \\times \\mathbb R_{> 0}).\n$$\n\nIf $B = Y$, customarily, we simply write $R \\restriction_{A}$ for $R \\restriction_{A \\times B}$. Similarly, as the codomain of a metric function is alway $\\mathbb R_{> 0}$, so we simply write $d \\restriction_{U \\times U}$ instead of $d \\restriction_{(U \\times U) \\times \\mathbb R_{> 0}}$.\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: subspace metric}\n\tLet $\\mathbb X = (X, d)$ be a metric space, and let $A \\subseteq X$.\n\t\n\tThe \\textit{metric on $A$ induced by $d$}, or the \\textit{subspace metric of $d$ with respect to $A$} is defined to be\n\t$$\n\td_A := d\\restriction_{A \\times A}.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tLet $\\mathbb X = (X, d)$ be a metric space, and let $A \\subseteq X$ and let $d_A := d\\restriction_{A \\times A}$.\n\t\n\tThen $\\mathbb A = (A, d_A)$ is a metric space.\n\t\n\t\\begin{proof}\t\t\n\t\tAs metric axioms (Definition \\ref{def: metric axioms}) holds for any $x,y \\in X$, and $A \\subseteq X$, they also holds for any $a, b \\in A$. As $d_A$ is the subspace metric of $d$ with respect to $A$, $d_A$ is a metric on $A$.\n\t\t\n\t\tThus, $\\mathbb A$ is a metric space.\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: metric subspace}\n\tLet $\\mathbb X = (X, d)$ be a metric space, and let $A \\subseteq X$. \n\t\n\t$\\mathbb A = (A, d_A)$ is a \\textit{metric subspace} of $\\mathbb X$ iff $d_A$ is a subspace metric of $d$ with respect to $A$.\n\\end{definition}\n%--------------------------------\n\n\n\n%================================\n%::::::::::::::::::::::::::::::::\n\\chapter{Topological Spaces}\n%::::::::::::::::::::::::::::::::\n%================================\n\n\n%================================\n\\section{Basic Definitions}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: open set axioms}\n\tLet $X$ be any set, and let $\\mathcal T \\subseteq 2^X$.\n\t\n\t$\\mathcal T$ is a \\textit{topology on $X$} iff it satisfies the \\textit{open set axioms}. That is,\n\t\\begin{enumerate}[\\bfseries O1.]\n\t\t\\item $X \\in \\mathcal T$;\n\t\t\\item For any $\\mathcal U \\subseteq \\mathcal T$, $\\bigcup \\mathcal U \\in \\mathcal T$; in words, $\\mathcal T$ is closed under arbitrary union.\n\t\t\\item For any finite $\\mathcal V \\subseteq \\mathcal T$, $\\bigcap \\mathcal V \\in \\mathcal T$; in words, $\\mathcal T$ is closed under finite intersection.\n\t\\end{enumerate}\n\t\n\tA subset $U \\subseteq X$ is said to be \\textit{open in $M$} iff it is an element of $\\mathcal T$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: topological space}\n\tLet $X$ be any set, and let $\\mathcal T$ be a structure on $X$.\n\t\n\tThe pair $(X, \\mathcal T)$ is called a \\textit{topological space} iff $\\mathcal T$ is a topology on $X$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: empty set is an element of topology}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space.\n\t\n\tThen $\\emptyset \\in \\mathcal T$.\n\t\n\t\\begin{proof}\n\t\tAs empty set is an element of any set, it also an element of $\\mathcal T$.\n\t\t\n\t\tTherefore, we have\n\t\t$$\n\t\t\\emptyset = \\bigcup \\emptyset \\in \\mathcal T.\n\t\t$$\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: closed set}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space.\n\t\n\tA subset $A \\subseteq X$ is said to be \\textit{closed in $\\mathbb X$} iff there exists a $U \\in \\mathcal T$ such that $A = X \\setminus U$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: closed set axioms}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and denote $\\mathcal C$ for the family of all closed sets in $M$.\n\t\n\tThen $\\mathcal C$ satisfies the following conditions:\n\t\\begin{enumerate}[\\bf C1.]\n\t\t\\item $X, \\emptyset \\in \\mathcal C$;\n\t\t\\item For any $\\mathcal A \\subseteq \\mathcal C$, $\\bigcap \\mathcal A \\in \\mathcal C$;\n\t\t\\item For any finite $\\mathcal B \\subseteq \\mathcal C$, $\\bigcup \\mathcal B \\in \\mathcal C$.\n\t\\end{enumerate}\n\t\n\t\\begin{proof}\n\t\t\\begin{enumerate}[\\bf C1.]\n\t\t\t\\item\n\t\t\tAs $\\emptyset \\in \\mathcal T$ and $X = X \\setminus \\emptyset$, by Definition \\ref{def: closed set}, $X$ is closed.\n\t\t\t\n\t\t\tSimilarly, as $X \\in \\mathcal T$ and $\\emptyset = X \\setminus X$, $\\emptyset$ is closed.\n\t\t\t\n\t\t\t\\qedlm\n\t\t\t\n\t\t\t\\item\n\t\t\tFor any $\\mathcal A \\subseteq \\mathcal C$, there exists a $\\mathcal U \\subseteq \\mathcal T$ such that \n\t\t\t$$\n\t\t\t\\forall A \\in \\mathcal A: \\exists U \\in \\mathcal U : A = X \\setminus U. \\quad\n\t\t\t\\text{(Definition \\ref{def: closed set}.)}\n\t\t\t$$\n\t\t\tThen we have\n\t\t\t$$\n\t\t\t\\begin{aligned}\n\t\t\t\t\\mathcal A = \\left\\{ X \\setminus U : U \\in \\mathcal U \\right\\} &\\iff \\bigcap \\mathcal A = \\bigcap_{U \\in \\mathcal U} X \\setminus U \\\\\n\t\t\t\t&\\iff \\bigcap \\mathcal A = X \\setminus \\bigcup \\mathcal U.\n\t\t\t\\end{aligned}\n\t\t\t$$\n\t\t\t\n\t\t\tAs $\\bigcup \\mathcal U \\in \\mathcal T$ by Definition \\ref{def: open set axioms} O2, its complement $\\bigcap \\mathcal A \\in \\mathcal C$ by Definition \\ref{def: closed set}.\n\t\t\t\t\n\t\t\t\t\\qedlm\n\t\t\t\t\n\t\t\t\\item\n\t\t\tFor any finite $\\mathcal B \\subseteq \\mathcal C$, there exists a finite $\\mathcal U \\subseteq \\mathcal T$ such that\n\t\t\t$$\n\t\t\t\\forall B \\in \\mathcal B: \\exists U \\in \\mathcal U: A = X \\setminus U. \\quad\n\t\t\t(\\text{Definition \\ref{def: closed set}}.)\n\t\t\t$$\n\t\t\tThen we have\n\t\t\t$$\n\t\t\t\\begin{aligned}\n\t\t\t\t\\mathcal B = \\{X \\setminus U : U \\in \\mathcal U \\} &\\iff \\bigcup \\mathcal B =  \\bigcup_{U \\in \\mathcal U} X \\setminus U \\\\\n\t\t\t\t&\\iff \\bigcup \\mathcal B = X \\setminus \\bigcap \\mathcal U.\n\t\t\t\\end{aligned}\n\t\t\t$$\n\t\t\t\n\t\t\tAs $\\bigcap \\mathcal U \\in \\mathcal T$ by Definition \\ref{def: open set axioms} O3, its complement $\\bigcup \\mathcal A \\in \\mathcal C$ by Definition \\ref{def: closed set}.\n\t\t\t\n\t\t\t\\qedlm\n\t\t\\end{enumerate}\n\t\t\n\t\tThus, the proof is done.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n\\section{Some Important Topologies}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: discrete topology}\n\tLet $X$ be any set.\n\t\n\tA family $\\mathcal T \\subseteq 2^X$ is a \\textit{discrete topology on $X$} iff $\\mathcal T = 2^X$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: indiscrete topology}\n\tLet $X$ be any set.\n\t\n\tA family $\\mathcal T \\subseteq 2^X$ is an \\textit{indiscrete topology on $X$} iff $\\mathcal T = \\{X, \\emptyset\\}$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: induced topology}\n\tLet $\\mathbb X = (X, d)$ be a metric space.\n\t\n\tA family $\\mathcal T \\subseteq 2^X$ is a \\textit{topology induced by $d$} iff $\\mathcal T$ is the set of all open sets in $\\mathbb X$.\n\\end{definition}\n%--------------------------------\n\n\n%================================\n\\section{Comparison of Topologies}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: comparison of topologies}\n\tLet $X$ be any set and let $\\mathcal T_1$ and $\\mathcal T_2$ be topologies on $X$.\n\t\n\tWe say that $\\mathcal T$ is \\textit{coarser} than $\\mathcal T_1$, or $\\mathcal T_2$ is \\textit{finer} than $\\mathcal T_1$, iff $\\mathcal T_1 \\subseteq \\mathcal T_2$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tBy the definition of cardinality and inclusion mapping, if $\\mathcal T_1 \\subseteq \\mathcal T_2$, it is certainly true that $| \\mathcal T_1 | \\le | \\mathcal T_2 |$. But, on the contrary, $| \\mathcal T_1 | \\le |\\mathcal T_2|$ does not implies $\\mathcal T_1 \\subseteq \\mathcal T_2$. It is easy to find counter-example about this.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tBy Definition \\ref{def: comparison of topologies}, for any set $X$, if a family $\\mathcal U$ of open sets is given, then we can find the coarsest topology on $X$ containing $\\mathcal U$ by\n\t$$\n\t\\mathcal T = \\left\\{ \\bigcup \\mathcal I, \\bigcap \\mathcal I, X : \\mathcal I \\subseteq \\mathcal U \\right\\}.\n\t$$\n\t\n\tFor example, let $X = \\{1,2,3,4,5\\}$, and let\n\t$$\n\t\\mathcal U = \\{\\{1,2\\}, \\{2,3\\}, \\{4\\}\\}.\n\t$$\n\tThen a topology on $X$ contains at least these sets:\n\t$$\n\t\\begin{matrix}\n\t\t\\{1,2,3, 4\\}, \\{\\}, \\\\\n\t\t\\{1,2\\}, \\{2,3\\}, \\{4\\}, \\\\\n\t\t\\{1,2,3\\}, \\{1,2,4\\}, \\{2,3,4\\}, \\\\\n\t\t\\{2\\}.\n\t\\end{matrix}\n\t$$\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tThe discrete topology is the finest topology on any $X$, while the indiscrete topology is the coarsest.\n\\end{example}\n%--------------------------------\n\n\n%================================\n\\section{Subspaces}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: subspace}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tThe \\textit{subspace topology on $A$} is defines as\n\t$$\n\t\\mathcal T_A := \\left\\{ A \\cap U : U \\in \\mathcal T \\right\\}.\n\t$$\n\t\n\tIn this case, $(A, \\mathcal T_A)$ is called a \\textit{subspace of $\\mathbb X$}.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tNote that $(A, \\mathcal T_A)$ is a subspace of $\\mathbb X$ does not implies that $\\mathcal T_A \\subseteq \\mathcal T$. Consider $(\\mathbb R, \\mathcal T)$ as a standard topological space. Let $\\mathcal T'$ be a standard topological space on $\\mathbb R_{\\ge 0}$, then $(\\mathbb R_{\\ge 0}, \\mathcal T')$ is a subspace of $(\\mathbb R, \\mathcal T)$. For any $a \\in \\mathbb R_{> 0}$, real interval $[0, a) \\in \\mathcal T'$, but it is not an element in $\\mathcal T$.\n\t\n\tHere is another extreme example. Let $\\mathbb X = (X, \\mathcal T)$ be an indiscrete topological space, and let $A \\subseteq X$. Then, if $(A, \\mathcal T_A)$ is a subspace of $\\mathbb X$, then $\\mathcal T_A \\subseteq \\mathcal T$ iff $A \\in \\{\\emptyset, X \\}$.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tAs $\\emptyset$ is the subset of any set, by Definition \\ref{def: subspace}, for any topological space $(X, \\mathcal T)$,\n\t$$\n\t\\mathcal T_\\emptyset = \\{\\emptyset \\cap U : U \\in \\mathcal T\\} = \\{\\emptyset\\}\n\t$$\n\t\n\tThus, $(\\emptyset, \\{\\emptyset\\})$ is the subspace of any topological space.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $\\mathbb A = (A, \\mathcal T_A)$ be a subspace of $\\mathbb X$.\n\t\n\tThen,\n\t\n\t$$\n\t\\mathcal T_A \\subseteq \\mathcal T \\iff A \\in \\mathcal T.\n\t$$\n\t\n\t\\begin{proof}\n\t\tFirst, prove $\\Rightarrow$.\n\t\t\n\t\t$S \\in \\mathcal T$. By Definition \\ref{def: open set axioms} O1, $A \\in \\mathcal T_A$. As $\\mathcal T_A \\subseteq \\mathcal T$, $A \\in \\mathcal T$.\n\t\t\n\t\t\\qedlm\n\t\n\t\tNow, prove $\\Leftarrow$.\n\t\t\n\t\tAs $A \\in \\mathcal T$, by Definition \\ref{def: subspace}, for any $S \\in \\mathcal T_A$,\n\t\t$$\n\t\tS = A \\cap U, \\quad U \\in \\mathcal T.\n\t\t$$\n\t\t\n\t\tBy Definition \\ref{def: open set axioms} O3, $S \\in \\mathcal T$.\n\t\t\n\t\tAs $S \\in \\mathcal T_A$ is arbitrarily given, all $S \\in \\mathcal T_A$ is also an element in $\\mathcal T$. Thus $\\mathcal T_A \\subseteq \\mathcal T$.\n\t\t\n\t\t\\qedlm\n\t\t\n\t\tThus, the proof is done.\n\t\t\n\t\t\\qed\n\t\t\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n\\section{Interiors}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: interior}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tThe \\textit{interior} of $A$ is defined as\n\t$$\n\t\\Int_{\\mathcal T}(A) := \\bigcup \\left(\\mathcal T \\cap 2^A \\right).\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tLet $\\mathbb X_1 = (X, \\mathcal T_1)$, $\\mathbb X_2 = (X, \\mathcal T_2)$, and $A \\subseteq X$. Then $\\mathcal T_1 \\ne \\mathcal T_2$ iff $\\Int_{\\mathcal T_1}(A) \\ne \\Int_{\\mathcal T_2}(A)$. In this case, the subscript for ``$\\Int$'' is necessary.\n\t\n\tBut, if the confusion is unlikely, we can also simply write $\\Int (A)$ for $\\Int_\\mathcal T A$. In this case, it is also common to write $A^\\circ$ for $\\Int(A)$.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: open iff interior}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\t$A \\in \\mathcal T$ iff $A = A^\\circ$.\n\t\n\t\\begin{proof}\n\t\tFirst, prove $\\Rightarrow$.\n\t\t\n\t\tIf $A \\in \\mathcal T$, then we have\n\t\t$$\n\t\t\\mathcal T \\cap 2^A = \\mathcal T \\cap \\{A\\} \\cap 2^A = \\{A\\} \\cap 2^A = \\{A\\}.\n\t\t$$\n\t\t\n\t\tBy Definition \\ref{def: interior},\n\t\t$$\n\t\tA^\\circ = \\bigcup(\\mathcal T \\cap 2^A) = \\bigcup\\{A\\} = A.\n\t\t$$\n\t\t\n\t\t\\qedlm\n\t\t\n\t\tNow, prove $\\Leftarrow$.\n\t\t\n\t\tBy Definition \\ref{def: interior}, we have\n\t\t$$\n\t\tA = \\bigcup(\\mathcal T \\cap 2^A).\n\t\t$$\n\t\t\n\t\tAs $\\mathcal T \\cap 2^A \\subseteq \\mathcal T$, thus, by open set axioms O2 (Definition \\ref{def: open set axioms} O2), $A \\in \\mathcal T$.\n\t\t\n\t\t\\qedlm\n\t\t\n\t\tThus, the proof is done.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: point in open set}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\in \\mathcal T$. For any $x \\in A$, there is a $U \\in \\mathcal T \\cap 2^A$ such that $x \\in U$.\n\t\n\t\\begin{proof}\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t% line 1\n\t\t\tx \\in A &\\iff x \\in A^\\circ\n\t\t\t\t% by\n\t\t\t\t&\\text{(Proposition \\ref{prop: open iff interior})} \\\\\n\t\t\t% line 2\n\t\t\t&\\iff x \\in \\bigcup\\left( \\mathcal T \\cap 2^A \\right)\n\t\t\t\t% by\n\t\t\t\t&\\text{(Definition \\ref{def: interior})} \\\\\n\t\t\t% line 3\n\t\t\t&\\iff \\exists U \\in \\mathcal T \\cap 2^A: x \\in U.\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%todo: >>>prove this<<<\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: union of intersection of family of families}\n\tLet $X$ be any set, let $I$ be an index set, and let $\\mathcal A_i \\subseteq 2^X$ for any $i \\in I$.\n\t\n\tThen we have\n\t$$\n\t\\bigcup \\left( \\bigcap_{i \\in I} \\mathcal A_i \\right) \\subseteq \\bigcap_{i \\in I} \\left( \\bigcup \\mathcal A_i \\right).\n\t$$\n\\end{proposition}\n%%--------------------------------\n\n\n\\begin{figure}[h]\n\t\\centering\n    \\includegraphics[width=345pt]{notes-for-general-topology/media/intersection-of-family-of-families}\n    \\caption{Diagram of the relation in Proposition \\ref{prop: union of intersection of family of families}.}\n\\end{figure}\n\n\n\n\n% Todo: Share on ProofWiki\n% https://proofwiki.org/wiki/Intersection_of_Interiors_contains_Interior_of_Intersection\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: interior of intersection is a subset of intersection of interior}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $\\mathcal A \\subseteq 2^X$.\n\t\n\tThen we have\n\t$$\n\t\\left( \\bigcap \\mathcal A \\right)^\\circ \\subseteq \\bigcap_{A \\in \\mathcal A} A^\\circ.\n\t$$\n\t\n\t\\begin{proof}\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t% line 1\n\t\t\t\\left(\\bigcap \\mathcal A \\right)^\\circ &= \\bigcup \\left( \\mathcal T \\cap 2^{\\bigcap \\mathcal A} \\right)\n\t\t\t\t% by\n\t\t\t\t&\\text{(Definition \\ref{def: interior})}\n\t\t\t\\\\\n\t\t\t% line 2\n\t\t\t&= \\bigcup \\left( \\mathcal T \\cap \\bigcap_{A \\in \\mathcal A} 2^A \\right)\n\t\t\t\t% by\n\t\t\t\t&\\text{(\\href{https://proofwiki.org/wiki/Intersection_of_Power_Sets}{intersection of power sets})}\n\t\t\t\\\\\n\t\t\t% line 3\n\t\t\t&= \\bigcup \\left( \\bigcap_{A \\in \\mathcal A} \\left(\\mathcal T \\cap 2^A \\right) \\right)\n\t\t\t\t% by\n\t\t\t\t&\\text{(intersection is \\href{https://proofwiki.org/wiki/Intersection_is_Idempotent}{idempotent}} \\\\\n\t\t\t\t&&\\text{and \\href{https://proofwiki.org/wiki/Intersection_is_Associative}{associative})}\n\t\t\t\\\\\n\t\t\t% line 4\n\t\t\t&\\subseteq \\bigcap_{A \\in \\mathcal A} \\left( \\bigcup \\left( \\mathcal T \\cap 2^A \\right) \\right)\n\t\t\t\t% by\n\t\t\t\t&\\text{(Proposition \\ref{prop: union of intersection of family of families})}\n\t\t\t\\\\\n\t\t\t% line 5\n\t\t\t&= \\bigcap_{A \\in \\mathcal A} A^\\circ.\n\t\t\t\t% by\n\t\t\t\t&\\text{(Definition \\ref{def: interior})}\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tThe equality in Proposition \\ref{prop: interior of intersection is a subset of intersection of interior} may not hold.\n\n\tLet $\\mathbb T = (\\mathbb R, \\mathcal T)$ be a topological space with\n\t$$\n\t\\mathcal T = \\{ X, (0,2), (1, 3), \\emptyset \\}.\n\t$$\n\t\n\tThen we have\n\t$$\n\t((0,2) \\cap (1,3))^\\circ = \\emptyset \\quad \\subsetneq \\quad (0,2)^\\circ \\cap (1,3) = (1,2).\n\t$$\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: inclusion implies interior inclusion}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A, B \\subseteq X$.\n\t\n\tIf $A \\subseteq B$, then $A^\\circ \\subseteq B^\\circ$.\n\t\n\t\\begin{proof}\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t% line 1\n\t\t\tA \\subseteq B &\\implies 2^A \\subseteq 2^B\n\t\t\t\t% by\n\t\t\t\t&\\text{(\\href{https://proofwiki.org/wiki/Power_Set_of_Subset}{power set of subset})}\\\\\n\t\t\t% line 2\n\t\t\t& \\implies \\mathcal T \\cap 2^A \\subseteq \\mathcal T \\cap 2^B\n\t\t\t\t% todo: by what?\n\t\t\t\t& \\\\\n\t\t\t% line 3\n\t\t\t&\\implies \\bigcup(\\mathcal T \\cap 2^A) \\subseteq \\bigcup (\\mathcal T \\cap 2^B)\n\t\t\t\t% todo: by what?\n\t\t\t\t& \\\\\n\t\t\t% line 4\n\t\t\t&\\implies A^\\circ \\subseteq B^\\circ\n\t\t\t\t% by\n\t\t\t\t&\\text{(Definition \\ref{def: interior})}\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tNote that, $A^\\circ \\subseteq B^\\circ$ does not implies $A \\subseteq B$. Consider $\\mathbb R$ as a Euclidean metric space, and let\n\t$$\n\t\\begin{aligned}\n\t\tA = \\{0\\}, \\quad B \\subseteq \\mathbb R \\setminus \\{0\\}.\n\t\\end{aligned}\n\t$$\n\tAs $A^\\circ = \\emptyset$, $A^\\circ \\subseteq B^\\circ$, but $A \\setminus B = \\{0\\}$, so $A \\not \\subseteq B$.\n\\end{note}\n%--------------------------------\n\n\n%================================\n\\section{Limit Points and Isolated Points}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: limit point}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tA point $x \\in X$ is a \\textit{limit point of $A$} iff for any $U \\in \\mathcal T$ with $x \\in U$\n\t$$\n\tA \\cap U \\setminus \\{x\\} \\ne \\emptyset.\n\t$$\n\t\n\tThe \\textit{derived set of $A$} is the set of all limit points of $X$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: isolated point}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tA point $x \\in A$ is said to be \\textit{isolated} iff there is $U \\in \\mathcal T$ with $x \\in U$, such that\n\t$$\n\tA \\cap U \\setminus \\{x\\} = \\emptyset.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\paragraph{Notations.}\nThe Derived set of $A$ is usually denoted $A'$.\\footnote{See \\href{https://proofwiki.org/wiki/Definition:Derived_Set}{ProofWiki} and \\href{https://en.wikipedia.org/wiki/Derived_set_(mathematics)}{Wikipedia}.}\nBut sometime it is also necessary to know in which space (with its topology) the derived set of $A$ is. For example, for topological spaces $\\mathbb X_1 = (X, \\mathcal T_1)$ and $\\mathbb X_2 = (X, \\mathcal T_2)$, if $\\mathcal T_1 \\ne \\mathcal T_2$, the derived sets of a set $A$ in $\\mathbb X_1$ and $\\mathbb X_2$ may be different. So, below, the notation $A'$ is used only if the confusions are unlikely; else, we denote $\\Li_\\mathcal T A$ for $A'$ with respect to the topology $\\mathcal T$.\n\nSometime, the set of isolated points of $A$ is denoted by $A^i$. For avoiding confusions, we denote $\\I_\\mathcal T(A)$ for $A^i$ with respect to the topology $\\mathcal T$.\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: disjoint union of isolated set and derived set}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$. \n\t\n\tThen,\n\t$$\n\tA \\subseteq \\Li (A) \\sqcup \\I (A).\n\t$$\n\t\n\t\\begin{proof}\n\t\tBy Definition \\ref{def: limit point}, $x \\notin \\Li(A)$ iff there exists a $U \\in \\mathcal T$ of $x \\in U$ such that $A \\cap N \\setminus \\{x\\} = \\emptyset$. This precisely satisfies Definition \\ref{def: isolated point}. Thus\n\t\t$$\n\t\tA \\subseteq \\Li(A) \\cup \\I(A).\n\t\t$$\n\t\t\n\t\tAs Definition \\ref{def: limit point} and \\ref{def: isolated point} are precisely logical complement for each other, $x \\in \\I (A) \\cap \\Li(A)$ always fails, i.e., $\\I(A) \\cap \\Li(A) = \\emptyset$. Thus\n\t\t$$\n\t\tA \\subseteq \\Li (A) \\sqcup \\I (A).\n\t\t$$\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: closed iff contain all limit point}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\t$A$ is closed iff $\\Li(A) \\subseteq A$.\n\t\n\t\\begin{proof}\n\t\tFirst, prove $\\Rightarrow$.\n\t\t\n\t\tAiming for a contradiction, suppose $A$ is closed but there exists a $y \\in \\Li(A) \\setminus A$.\n\t\t\n\t\tBy Definition \\ref{def: closed set}, as $A$ is closed, then $A^\\complement$ is open.\n\t\t\n\t\tAs $y \\in A^\\complement$ and $A^\\complement$ is open, then, by Proposition \\ref{prop: point in open set}, there exists a $U \\in \\mathcal T$ with $y \\in U$, such that $U \\subseteq A^\\complement$.\n\t\t\n\t\tAs $U$ is an open set containing $y$ and $A \\cap U \\setminus \\{y\\} = \\emptyset$, then $y \\notin \\Li(A)$. This contradicts the assumption.\n\t\t\n\t\tThus $\\Li(A) \\subseteq A$.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n\\section{Closures}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: closure}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tThe \\textit{closure of $A$} is defined as\n\t$$\n\t\\Cl_\\mathcal T(A) := A \\cup \\Li(A).\n\t$$\n\t\n\tWhen the confusions are unlikely, we simply write $\\Cl(A)$, $\\overline A$ or $A^-$ for $\\Cl_\\mathcal T(A)$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: closed iff closure}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\t$A$ is closed iff $A = A^-$\n\t\n\t\\begin{proof}\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t% \\line 1\n\t\t\tA \\text{ is closed} &\\iff A \\supseteq \\Li(A)\n\t\t\t\t% by\n\t\t\t\t&\\text{(Proposition \\ref{prop: closed iff contain all limit point})}\\\\\n\t\t\t% \\line 2\n\t\t\t&\\iff A = A \\cup \\Li(A)\n\t\t\t\t% by\n\t\t\t\t\\\\\n\t\t\t% \\line 3\n\t\t\t&\\iff A = A^-.\n\t\t\t\t% by\n\t\t\t\t&\\text{(Definition \\ref{def: closure})} \\\\\n\t\t\\end{aligned}\n\t\t$$\n\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: closure is disjoint union of derived and isolated set}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\t$A$ is closed iff\n\t$$\n\tA = \\I(A) \\sqcup \\Li(A).\n\t$$\n\t\n\t\\begin{proof}\n\t\tAs $A$ is closed, we have\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t% line 1\n\t\t\tA &= \\Cl (A) \n\t\t\t\t% by\n\t\t\t\t&\\text{(Proposition \\ref{prop: closed iff closure})} \\\\\n\t\t\t% line 2\n\t\t\t&= A \\cup \\Li(A)\n\t\t\t\t% by\n\t\t\t\t&\\text{(Definition \\ref{def: closure})} \\\\\n\t\t\t% line 3\n\t\t\t&= A \\setminus \\Li(A) \\sqcup \\Li(A)\n\t\t\t\t% by\n\t\t\t\t\\\\\n\t\t\t% line 4\n\t\t\t& = \\I (A) \\sqcup \\Li(A).\n\t\t\t\t% by\n\t\t\t\t&\\text{(Proposition \\ref{prop: disjoint union of isolated set and derived set})}\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: closure are the intersection of closure supsersets}\t\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t$$\n\tA^- = \\bigcap \\{K \\supseteq A : K \\text{ closed in $\\mathbb X$}\\}.\n\t$$\n\t\n\t\\begin{proof}\n\t\tBy Proposition \\ref{prop: closed iff closure}, $A^-$ is closed. Thus, by Definition \\ref{def: closed set}, $X \\setminus A^{-}$ is open. Then we ahve\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t% line 1\n\t\t\tX \\setminus (X \\setminus A^-) &= X \\setminus (X \\setminus A^-)^\\circ\n\t\t\t\t% by\n\t\t\t\t&\\text{(Proposition: \\ref{prop: open iff interior})}\\\\\n\t\t\t% line 2\n\t\t\t&= X \\setminus \\bigcup \\left(\\mathcal T \\cap 2^{X \\setminus A^-} \\right)\n\t\t\t\t% by\n\t\t\t\t&\\text{(Definition: \\ref{def: interior})} \\\\\n\t\t\t% line 3\n\t\t\t&= X \\setminus \\bigcup \\{ U \\subseteq A : U \\text{ open in $\\mathbb X$} \\}\n\t\t\t\t% by\n\t\t\t\t&\\text{}\\\\\n\t\t\t% line 4\n\t\t\t&= \\bigcap \\left\\{ X \\setminus U \\supseteq A : U \\text{ open in $\\mathbb X$} \\right\\}\n\t\t\t\t% by\n\t\t\t\t&\\text{(De Morgan's Law)}\\\\\n\t\t\t% line 5\n\t\t\t&= \\bigcap \\{ K \\supseteq A : K \\text{ closed in $\\mathbb X$} \\}.\n\t\t\t\t% by\n\t\t\t\t&\\text{(Definition: \\ref{def: closed set})}\\\\\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: complement of interior}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tThen we have\n\t$$\n\tX \\setminus A^\\circ = (X \\setminus A)^-.\n\t$$\n\t\n\t\\begin{proof}\n\t\tFirst, we have\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t% line 1\n\t\t\tX \\setminus A^\\circ &= X \\setminus \\bigcup \\left(\\mathcal T \\cap 2^A \\right) \n\t\t\t\t% by\n\t\t\t\t& \\text{(Definition \\ref{def: interior}) }\\\\\n\t\t\t% line 2\n\t\t\t&= \\bigcap_{K \\in \\mathcal T \\cap 2^A} (X \\setminus K)\n\t\t\t\t% by\n\t\t\t\t& \\text{(De Morgan's Law)}\\\\\n\t\t\t% line 3\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\tFor any $K$, $X \\setminus K$ is a closed superset of $X \\setminus A$.\n\t\t\n\t\tAs closed sets are closed under arbitrary intersection (Proposition \\ref{prop: closed set axioms}), and $X \\setminus A^\\circ$ is the intersection of all closed superset of $X \\setminus A$, by Proposition \\ref{prop: closure are the intersection of closure supsersets}, $X \\setminus A^\\circ = (X \\setminus A)^-$.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: inclusion implies closure inclusion}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A, B \\subseteq X$.\n\t\n\tIf $A \\subseteq B$, then $A^- \\subseteq B^-$.\n\t\n\t\\begin{proof}\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t% line 1\n\t\t\tA \\subseteq B &\\iff X \\setminus A \\supseteq X \\setminus B\n\t\t\t\t% by\n\t\t\t\t& \\\\\n\t\t\t% line 2\n\t\t\t&\\textcolor{red}{\\implies} \\left(X \\setminus A \\right)^\\circ \\supseteq \\left( X \\setminus B \\right)^\\circ\n\t\t\t\t% by\n\t\t\t\t&\\text{(Proposition \\ref{prop: inclusion implies interior inclusion})} \\\\\n\t\t\t% line 3\n\t\t\t&\\iff X \\setminus (X \\setminus A)^\\circ  \\subseteq X \\setminus (X \\setminus B)^\\circ\n\t\t\t\t% by\n\t\t\t\t& \\\\\n\t\t\t% line 4\n\t\t\t&\\iff (X \\setminus (X \\setminus A))^- \\subseteq (X \\setminus (X \\setminus B))^-.\n\t\t\t\t% by\n\t\t\t\t& \\text{(Proposition \\ref{prop: complement of interior})} \\\\\n\t\t\t% line 5\n\t\t\t&\\iff A^- \\subseteq B^-.\n\t\t\\end{aligned}\n\t\t$$\n\t\\end{proof}\n\t\n\t\\qed\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: point in open set (only if)}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\in \\mathcal T$ such that for any $x \\in A$, there exists a $U \\in \\mathcal T$ such that $x \\in U \\subseteq A$.\n\t\n\tThen $A$ is open in $\\mathbb X$.\n\n\t\\begin{proof}\n\t\tAiming for a contradiction, suppose for any $x \\in A$, there exists a $U \\in \\mathcal T$ such that $x \\in U \\subseteq A$, but $A$ is not open.\n\t\t\n\t\tBy Definition \\ref{def: closed set}, as $A$ is not open, $X \\setminus A$ is not closed.\n\t\t\n\t\tBy Proposition \\ref{prop: closed iff contain all limit point}, there exists $x \\in \\Li(A) \\setminus (X \\setminus A)$. Fix $x$.\n\t\t\n\t\tAs $x \\notin X \\setminus A$, $x \\in A$.\n\t\t\n\t\tBy Definition \\ref{def: limit point}, for $U \\in \\mathcal T$ with $x \\in U$, $U \\cap (X \\setminus A) \\ne \\emptyset$, i.e., $U \\setminus A \\ne \\emptyset$. This implies that $U \\not \\subseteq A$.\n\t\t\n\t\tThis contradicts the assumption we have.\n\t\t\n\t\tThus $A$ has to be open.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n\\section{Density}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: dense}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tThen $A$ is said to be \\textit{everywhere dense}, or simply \\textit{dense}, in $\\mathbb X$ iff\n\t$$\n\tA^- = X.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: alternative definition of dense}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tThen $A$ is dense in $\\mathbb X$ iff for any $U \\in \\mathcal T$, $A \\cap U \\ne \\emptyset$.\n\t\n\t\\begin{proof}\n\t\tFirst, prove $\\Rightarrow$.\n\t\t\n\t\tAssume $A$ is dense in $\\mathbb X$, then, by Definition \\ref{def: dense}, $A^- = X$.\n\t\t\n\t\tBy Definition \\ref{def: isolated point}, for any $x \\in \\I(A)$, $x \\in A$.\n\t\t\n\t\tBy Definition \\ref{def: limit point}, for any $x \\in \\Li(A)$ and for any $U \\in \\mathcal T$ with $x \\in U$, $U \\cap A \\ne \\emptyset$.\n\t\t\n\t\tAs $A^- = X$, then, by Proposition \\ref{prop: closure is disjoint union of derived and isolated set}, $X = \\I(A) \\sqcup \\Li (A)$.\n\t\t\n\t\tThus for any $U \\in \\mathcal T$, $A \\cap U \\ne \\emptyset$.\n\t\t\n\t\t\\qedlm\n\t\t\n\t\tNow, prove $\\Leftarrow$.\n\t\t\n\t\tAiming for a contradiction, suppose for any $U \\in \\mathcal T$, $A \\cap U \\ne \\emptyset$, but $A$ is not dense in $\\mathbb X$.\n\t\t\n\t\tAs, $A \\subseteq X$, by Proposition \\ref{prop: inclusion implies closure inclusion}, $A^- \\subseteq X^-$. And, as $X$ is closed in $\\mathbb X$, by Proposition \\ref{prop: closed iff closure}, $X = X^-$. Therefore, $A^- \\subseteq X$.\n\t\t\n\t\tAs $A$ is not dense in $X$, by Definition \\ref{def: dense}, $A^- \\ne X$. Therefore, $A^- \\subsetneq X$. This implies that $X \\setminus A^-$ is non-empty. And, by Definition \\ref{def: closure}, $X \\setminus A^- \\in \\mathcal T$.\n\t\t\n\t\tBy Proposition \\ref{prop: point in open set}, for any $x \\in X \\setminus A^-$, there exists a $U \\in \\mathcal T$ with $x \\in U$, such that $U \\in X \\setminus A^-$. Then $U \\cap A = \\emptyset$. This contradicts the assumption we have.\n\t\t\n\t\tTherefore, $A$ has to be dense in $\\mathbb X$.\n\t\t\n\t\t\\qedlm\n\t\t\n\t\tThus, the proof is done.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: nowhere dense}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tThen $A$ is said to be \\textit{nowhere dense in $\\mathbb X$} iff\n\t$$\n\t\\left( A^- \\right)^\\circ = \\emptyset.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tThen $A$ is nowhere dense in $\\mathbb X$ iff for any $U \\in \\mathcal T \\setminus \\{\\emptyset\\}$,\n\t$$\n\tU \\setminus A^- \\ne \\emptyset.\n\t$$\n\t\n\t\\begin{proof}\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t& \\text{$A$ is nowhere dense in $\\mathbb X$} \\\\\n\t\t\t\\iff & (A^-)^\\circ = \\emptyset \n\t\t\t\t& \\text{(Definition \\ref{def: nowhere dense})}\\\\\n\t\t\t\\iff & (A^-)^\\circ = \\bigcup \\left( \\mathcal T \\cap 2^A \\right) = \\emptyset \n\t\t\t\t& \\text{(Definition \\ref{def: interior})} \\\\\n\t\t\t\\iff & (\\forall U \\in \\mathcal T: U \\subseteq A^-) \\quad U = \\emptyset.\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n%::::::::::::::::::::::::::::::::\n\\chapter{Sequences}\n%::::::::::::::::::::::::::::::::\n%================================\n\n\n%================================\n\\section{Convergent Sequences}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: convergent sequence}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $u: \\mathbb N \\to X$.\n\t\n\t$u$ \\textit{converges to a limit $x \\in X$} iff for any $U \\in \\mathcal T$ with $x \\in U$,\n\t$$\n\t(\\exists k \\in \\mathbb R_{> 0}) \\quad u[\\mathbb N_{> k}] \\subseteq U.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: alternative definition of accumulation point}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $u: \\mathbb N \\to X$.\n\t\n\t$u$ converges to a limit $x \\in X$ iff for any $U \\in \\mathcal T$ with $x \\in U$,\n\t$$\n\t\\mathbb N \\setminus u^{-1}[U] \\text{ is finite}.\n\t$$\n\t\n\t\\begin{proof}\n\t\tFirst, prove $\\Rightarrow$.\n\t\t\n\t\tBy Definition \\ref{def: convergent sequence}, as $u$ converges to $x$, let $U \\in \\mathcal T$ with $x \\in U$, then there exists a $k \\in \\mathbb R_{> 0}$ such that $u[\\mathbb N_{> k}] \\subseteq U$.\n\t\t\n\t\tThen we have\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\tu[\\mathbb N_{> k}] \\subseteq U &\\implies u^{-1}[u[\\mathbb N_{> k}]] \\subseteq u^{-1}[U] \\\\\n\t\t\t&\\implies \\mathbb N_{> k} \\subseteq u^{-1}[U]\n\t\t\t\t% by\n\t\t\t\t&\\text{(\\href{https://proofwiki.org/wiki/Image_of_Inverse_Image}{image of inverse image})} \\\\\n\t\t\t\t&\\implies \\mathbb N \\setminus \\mathbb N_{> k} \\supseteq \\mathbb N \\setminus u^{-1}[U]. \\\\\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\tAs $\\mathbb N \\setminus \\mathbb N_{> k}$ is finite, its subset $\\mathbb N \\setminus u^{-1}[U]$ is finite.\n\t\t\n\t\t\\qedlm\n\t\t\n\t\tNow, prove $\\Leftarrow$.\n\t\t\n\t\tBy \\href{https://proofwiki.org/wiki/Image_of_Inverse_Image}{image of inverse image}, we have\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\tu[u^{-1}[U]] \\subseteq U.\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\tAs $u^{-1}[U]$ is a cofinite subset of $\\mathbb N$, there exists a $k \\in \\mathbb N$ such that $I \\supseteq \\mathbb N_{> k}$. Then we have\n\t\t$$\n\t\tU \\supseteq u[\\mathbb N_{> k}].\n\t\t$$\n\t\t\n\t\tThis precisely satisfies Definition \\ref{def: convergent sequence}.\n\t\t\n\t\t\\qedlm\n\t\t\n\t\tTherefore the proof is done.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n\\section{Accumulation Points of Sequences}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: accumulation point}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $u: \\mathbb N \\to X$.\n\t\n\tA point $x \\in X$ is an \\textit{accumulation point} of $u$ iff for any $U \\in \\mathcal T$ with $x \\in U$, $U$ contains infinitely many terms of $u$; i.e.,\n\t$$\n\t\\forall U \\in \\mathcal T : x \\in U \\implies (\\exists I \\subseteq \\mathbb N : |I| = \\aleph_0 \\implies u[I] \\subseteq U).\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tSometime, an accumulation point of a sequence is also a limit of the range of the sequence. But this not always holds.\n\t\n\tConsider $\\mathbb R$ as a Euclidean, and let $u: \\mathbb N \\to \\mathbb R$ be defined as\n\t$$\n\tu(n) := \\left| \\sin \\left( \\frac{\\pi n}{2} \\right) \\right|.\n\t$$\n\t\n\tThen $1$ is an accumulation point of $u[\\mathbb N]$, but $u[\\mathbb N] = (u[\\mathbb N])^i = \\{0,1\\}$, so it has no limit point at all.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, let $u: \\mathbb N \\to X$, and let $x \\in X$ be a limit of $u[\\mathbb N]$.\n\t\n\tThen $x$ is an accumulation point of $u$.\n\t\n\t\\begin{proof}\n\t\tLet $U \\in \\mathcal T$ with $x \\in U$, then we have\t\t\n\t\t$$\n\t\tu [u^{-1}[U]] \\subseteq U.\n\t\t$$\n\t\t\n\t\tBy Proposition \\ref{prop: alternative definition of accumulation point}, as $u$ converges to $x$, $u^{-1}[U]$ is a cofinite subset of $\\mathbb N$. Thus $u^{-1}[U]$ is infinite.\n\t\t\n\t\tAs $u^{-1}[U]$ is infinite and $x \\in U \\in \\mathcal T$, by Definition \\ref{def: accumulation point}, $x$ is an accumulation point of $u$.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: omega-accumulation point}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tA point $x \\in X$ is an \\textit{$\\omega$-accumulation point} of $A$ iff for any $U \\in \\mathcal T$ with $x \\in U$,\n\t$$\n\t|U \\cap A| \\ge \\aleph_0.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, let $u: \\mathbb N \\to X$ be an injection, and let $x \\in X$ be an accumulation point of $u$.\n\t\n\tThen $x$ is an $\\omega$-accumulation point of $u[\\mathbb N]$.\n\t\n\t\\begin{proof}\n\t\tBy Definition \\ref{def: accumulation point}, as $x$ is an accumulation point of $u$, let $U \\in \\mathcal T$ with $x \\in U$, there exists an infinite $I \\subseteq \\mathbb N$ such that $u[I] \\subseteq U$.\n\t\t\n\t\tAs $u$ is injective and $I$ is infinite, $u[I]$ is also infinite.\n\t\t\n\t\tAs $u[I] \\subseteq U$ and $U \\in \\mathcal T$ with $x \\in U$ is arbitrarily given, by Definition \\ref{def: omega-accumulation point}, $x$ is an $\\omega$-accumulation point of $u[\\mathbb N]$.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n%::::::::::::::::::::::::::::::::\n\\chapter{Countable Axioms}\n%::::::::::::::::::::::::::::::::\n%================================\n\n\n%================================\n\\section{Covers and Bases}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: cover}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tThen a family $\\mathcal C \\subseteq 2^X$ is a \\textit{cover for $A$} iff $A \\subseteq \\bigcup \\mathcal C$.\n\t\n\t$\\mathcal C$ is an \\textit{open cover} iff $\\mathcal C \\subseteq \\mathcal T$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: subcover}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $\\mathcal C, \\mathcal D$ be covers for a subset $A \\subseteq X$.\n\t\n\tThen $\\mathcal D$ is a \\textit{subcover of $\\mathcal C$} iff $\\mathcal D \\subseteq \\mathcal C$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: analytic basis}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space.\n\t\n\tA family $\\mathcal B \\subseteq 2^X$ is an \\textit{analytic basis for $\\mathcal T$} iff\n\t\\begin{enumerate}[(i)]\n\t\t\\item $\\mathcal B \\subseteq \\mathcal T$;\n\t\t\\item For any $U \\in \\mathcal T$, there is an $\\mathcal A \\subseteq \\mathcal B$, such that $U = \\bigcup \\mathcal A$.\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: alternative definition of analytic basis}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $\\mathcal B \\subseteq \\mathcal T$.\n\t\n\tThen $\\mathcal B$ is an analytic basis for $\\mathcal T$ iff for any $U \\in \\mathcal T$ and for any $x \\in U$, there exists a $B \\in \\mathcal B$ such that $x \\in B \\subseteq U$.\n\t\n\t\\begin{proof}\n\t\tFirst, prove $\\Rightarrow$.\n\t\t\n\t\tBy Definition \\ref{def: analytic basis}, as $\\mathcal B$ is an analytic basis for $\\mathcal T$, let $U \\in \\mathcal T$, then there is an $\\mathcal A \\subseteq \\mathcal B$ such that $U = \\bigcup \\mathcal A$.\n\t\t\n\t\tThen, for any $x \\in U$, there exists at least one $A \\in \\mathcal A$ such that $x \\in A$. As $U = \\bigcup\\mathcal A$, $A \\subseteq U$.\n\t\t\n\t\t\\qedlm\n\t\t\n\t\tNow, prove $\\Leftarrow$.\n\t\t\n\t\tBy Proposition \\ref{prop: point in open set (only if)}, as for any $U \\in \\mathcal T$ and for any $x \\in U$, there exists a $B \\in \\mathcal B$ such that $x \\in B \\subseteq U$, then there exists an $\\mathcal A \\subseteq \\mathcal B$ such that $\\bigcup \\mathcal A = U$.\n\t\t\n\t\tBy Definition \\ref{def: analytic basis}, $\\mathcal B$ is an analytic basis for $\\mathcal T$.\n\t\t\n\t\t\\qedlm\n\t\t\n\t\tThus, the proof is done.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: synthetic basis}\n\tLet $X$ be any set.\n\t\n\tA family $\\mathcal B \\subseteq 2^X$ is a \\textit{synthetic basis on $X$} iff\n\t\\begin{enumerate}[(i)]\n\t\t\\item $\\mathcal B$ is a cover fir $X$;\n\t\t\\item For any $U, V \\in \\mathcal B$, there exists $\\mathcal A \\subseteq \\mathcal B$, such that $U \\cap V = \\bigcup \\mathcal A$.\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: topology generated by basis}\n\tLet $X$ be a set, and let $\\mathcal B$ be a synthetic basis of $X$.\n\t\n\tThe topology on $X$ \\textit{generated by $\\mathcal B$} is defined as\n\t$$\n\t\\mathcal T = \\left\\{ \\bigcup \\mathcal A : \\mathcal A \\subseteq \\mathcal B \\right\\}.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: local basis}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $x \\in X$.\n\t\n\tA family $\\mathcal B \\subseteq 2^X$ is a \\textit{local basis at $x$} iff\n\t\\begin{enumerate}[(i)]\n\t\t\\item $\\mathcal B \\in \\mathcal T$;\n\t\t\\item For any $B \\in \\mathcal B$, $x \\in B$;\n\t\t\\item For any $U \\in \\mathcal T$ with $x \\in U$, there exists a $B \\in \\mathcal B$ such that $B \\subseteq U$.\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%================================\n\\section{First-Countable Spaces}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: first-countable}\n\tA topological space $\\mathbb X = (X, \\mathcal T)$ is said to be \\textit{first-countable} iff any $x \\in X$ has a countable basis.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: metric spaces are first-countable}\n\tMetric spaces are first-countable.\n\t\n\t\\begin{proof}\n\t\tLet $\\mathbb X = (X, d)$ be a metric space.\n\t\t\n\t\tFor any $x \\in X$, let $\\mathcal B_x: \\mathbb N \\to \\mathcal T$ be defined as\n\t\t$$\n\t\t\\mathcal B_x(n) := B_{1/n} (x).\n\t\t$$\n\t\t\n\t\tClearly, the image $\\mathcal B_x[\\mathbb N]$ is countable.\n\t\t\n\t\tLet $U \\in \\mathcal T$. As $U$ is open, and as $x \\in U$, then there exists $\\varepsilon \\in \\mathbb R_{> 0}$ such that $B_\\varepsilon(x) \\subseteq U$.\n\t\t\n\t\tBy Archimedean Principle, there exists an $n \\in \\mathbb N$ such that $n > \\frac{1}{\\varepsilon}$. Then we have\n\t\t$$\n\t\t\\mathcal B_x(n) = B_{1/n}(x) \\subseteq B_\\varepsilon(x) \\subseteq U.\n\t\t$$\n\t\t\n\t\tAs $U$ is arbitrarily given, for any $x \\in X$, $\\mathcal B_x[\\mathbb N]$ is a countable local basis at $x$.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%todo: need details.\n%https://proofwiki.org/wiki/Accumulation_Point_of_Infinite_Sequence_in_First-Countable_Space_is_Subsequential_Limit\n%--------------------------------\n\\begin{proposition}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a first-countable topological space, let $u: \\mathbb N \\to X$, and let $x \\in X$ be an accumulation point of $u$.\n\t\n\tThen $x$ is a \\textit{subsequential limit} of $u$. That is, there exists an infinite $I \\subseteq \\mathbb N$, such that $u\\restriction_I$ converges to $x$ (as a limit).\n\t\n\t\\begin{proof}\\footnote{\n\t\t\tThe detail of this proof is incomplete.\n\t\t}\n\t\tBy Definition \\ref{def: first-countable}, as $\\mathbb X$ is first-countable, there exists a countable local basis $\\mathcal B$ at $x$.\n\t\t\n\t\tLet $\\mathcal B_x: \\mathbb N \\to \\mathcal T$ such that $\\mathcal B_x[\\mathbb N]$ is a local base at $x$ and for any $n \\in \\mathbb N$,\n\t\t$$\n\t\t\\mathcal B_x(n) \\supseteq \\bigcup \\mathcal B_x[\\mathbb N_{> n}].\n\t\t$$\n\t\t\n\t\tLet $w: I \\to u[\\mathbb N]$ ($I$ infinite) such that for any $i \\in I$, $w(i) \\in \\mathcal B_x(i)$.\n\t\t\n\t\tThen, for any $k \\in \\mathbb N$, we have $w[I_{> k}] \\subseteq \\mathcal B_x(k)$. Thus, by Definition \\ref{def: convergent sequence}, $w$ is a subsequence of $u$ converging to $x$.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n\\section{Second-Countable Spaces}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: second-countable}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space.\n\t\n\t$\\mathbb X$ is said to be \\textit{second countable} iff $\\mathcal T$ has a countable (analytic) basis.\n\\end{definition}\n%--------------------------------\n\n\n%todo: need details.\n%https://proofwiki.org/wiki/Second-Countable_Space_is_First-Countable\n%--------------------------------\n\\begin{proposition}\n\tSecond-countable spaces are first-countable.\n\t\n\t\\begin{proof}\n\t\tLet $\\mathbb X = (X, \\mathcal T)$ be a second-countable space.\n\t\n\t\tBy Definition \\ref{def: second-countable}, $\\mathcal T$ has a countable analytic basis.\n\t\t\n\t\tLet $x \\in X$ and let $U \\in \\mathcal T$ with $x \\in U$. By Definition \\ref{def: analytic basis} there exists a countable $\\mathcal B \\subseteq \\mathcal T$, such that for any $U \\in \\mathcal T$, there is an $\\mathcal A \\subseteq \\mathcal B$, such that $U = \\bigcup \\mathcal A$. \n\t\t\n\t\tAs $U \\in \\mathcal T$ and $U = \\bigcup \\mathcal A$, by Proposition \\ref{prop: point in open set}, there exists a $A \\in \\mathcal A$ such that $x \\in A \\subseteq U$.\n\t\t\n\t\tLet $\\mathcal C \\subseteq \\mathcal B$ be the family of all such $A$ containing $x$, then, by Definition \\ref{def: local basis}, $\\mathcal C$ is a local basis at $x$. And as $\\mathcal B$ is countable, as a subset, $\\mathcal C$ is also countable.\n\t\t\n\t\tTherefore $\\mathcal C$ is a countable local basis at $x$.\n\t\t\n\t\tAs $x$ is arbitrarily given, $\\mathbb X$ is first-countable.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n%todo: Share on ProofWiki\n%https://proofwiki.org/wiki/Real_Number_Line_is_Second-Countable\n%--------------------------------\n\\begin{example}\n\tConsider $\\mathbb R$ as a Euclidean metric space.\n\t\n\t$\\mathbb R$ is second-countable.\n\t\n\t\\begin{proof}\n\t\tBy Proposition \\ref{prop: metric spaces are first-countable}, $\\mathbb R$ is first-countable.\n\t\t\n\t\tFor any $x \\in \\mathbb Q$, let $\\mathcal O_x: \\mathbb N \\to \\mathcal T$ be defined as\n\t\t$$\n\t\t\\mathcal O_x(n) := B_{1/n}(x).\n\t\t$$\n\t\t\n\t\tFor any $r \\in \\mathbb R$ and for any open set $U \\ni r$, there exists $\\delta \\in \\mathbb R_{> 0}$ such that $B_\\delta(r) \\subseteq U$.\n\t\t\n\t\tThere exists some $q \\in \\mathbb Q$ such that $q \\in B_\\delta(r)$. As $B_\\delta(r)$ is open, by Definition \\ref{def: open set in metric space}, there exists $\\varepsilon \\in \\mathbb R_{> 0}$ such that $B_\\varepsilon(q) \\subseteq B_\\delta(r)$.\n\t\t\n\t\tBy Archimedean property, there exists $k \\in \\mathbb N$ such that $k > \\frac{1}{\\varepsilon}$. Then we have\n\t\t$$\n\t\t\\mathcal O_q(k) = B_{1/k}(q) \\subseteq B_\\varepsilon(q) \\subseteq B_\\delta(r).\n\t\t$$\n\t\t\n\t\t[This proof is incomplete]\n\t\t% incomplete proof\n\t\\end{proof}\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tLet $\\mathbb X = (\\mathbb R, \\mathcal T)$ be a discrete topological space.\n\t\n\t$\\mathbb X$ is first-countable but not second-countable.\n\\end{example}\n%--------------------------------\n\n\n%================================\n\\section{Separable Spaces}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: separable}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space.\n\t\n\t$\\mathbb X$ is said to be \\textit{separable} iff there exists a countable subset $A \\subseteq X$ such that $A$ is dense in $\\mathbb X$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tSecond-countable spaces are separable.\n\t\n\t\\begin{proof}\n\t\tLet $\\mathbb X = (X, \\mathcal T)$ be a second-countable topological space.\n\t\t\n\t\tAs $\\mathbb X$ is second-countable, by Definition \\ref{def: second-countable}, there is a countable base $\\mathcal B$ for $\\mathcal T$.\n\t\t\n\t\tLet $f: \\mathcal B \\to X$ such that for any $B \\in \\mathcal B$,\n\t\t$$\n\t\tf(B) = \\text{a random } x \\in B.\n\t\t$$\n\t\t\n\t\tAs $\\mathcal B$ is countable, then $f[\\mathcal B]$ is countable.\n\t\t\n\t\tNow, it suffices to show that $f[\\mathcal B]$ is dense in $\\mathbb X$.\n\t\t\n\t\tAiming for a contradiction, suppose $f[\\mathcal B]$ is not dense in $\\mathbb X$, then, there exists some $x \\in X \\setminus (f[\\mathcal B])^-$.\n\t\t\n\t\tBy Definition \\ref{def: closed set}, $X \\setminus (f[\\mathcal B])^- \\in \\mathcal T$; by Definition \\ref{prop: point in open set}, there exists $U \\in \\mathcal T$ with $U \\ni x$ such that $U \\subseteq X \\setminus (f[\\mathcal B])^-$. That is, for any $B \\in \\mathcal B$, $f(B) \\notin U$; i.e., $f[\\mathcal B] \\cap U = \\emptyset$.\n\t\t\n\t\tAs $U \\in \\mathcal T$ and $\\mathcal B$ is a base for $\\mathcal T$, by Definition \\ref{def: analytic basis}, there exists $\\mathcal A \\subseteq \\mathcal B$ such that $\\bigcup \\mathcal A = U$. Thus, $f[\\mathcal A]$ must be a non-empty subset of $U$. This contradicts $f[\\mathcal B] \\cap U = \\emptyset$.\n\t\t\n\t\tThus, $f[\\mathcal B]$ has to be dense in $\\mathbb X$. As $f[\\mathcal B]$ is countable, therefore, $\\mathbb X$ is second-countable.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tNiemytzki plane is separable but not second-countable.\\footnote{\n\t\tSee \\href{https://proofwiki.org/wiki/Definition:Niemytzki_Plane}{ProofWiki}.\n\t}\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a discrete topological space which is separable.\n\t\n\tThen $X$ is countable.\n\t\n\t\\begin{proof}\n\t\tAiming for a contradiction, suppose $X$ is uncountable.\n\t\t\n\t\tAs $\\mathbb X$ is separable, by Definition \\ref{def: separable}, there exists a countable subset $A \\subseteq X$ being dense in $\\mathbb X$.\n\t\t\n\t\tBy Definition \\ref{def: dense}, $A^- = X$.\n\t\t\n\t\tAs $\\mathbb X$ is discrete, $A^- = A$.\n\t\t\n\t\tNow, we have $A = X$. As $A$ is countable but $X$ is not, this is impossible.\n\t\t\n\t\tThis contradiction shows that $X$ has to be countable.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n% https://proofwiki.org/wiki/Separable_Metric_Space_is_Second-Countable\n%--------------------------------\n\\begin{proposition}\n\tSeparable metric spaces are second-countable.\n\t\n\t\\begin{proof}\n\t\tLet $\\mathbb X = (X, d)$ be a metric space which is separable. Denote $\\mathcal T$ for the topology on $X$ induced by $d$.\n\t\t\n\t\tBy Definition \\ref{def: separable}, let $A \\subseteq X$ be a countable set with $A^- = X$ (by Definition \\ref{def: dense}, $A$ dense in $\\mathbb X$).\n\t\t\n\t\tLet $\\mathcal B: \\mathbb N \\times A \\to \\mathcal T$ be defined as\n\t\t$$\n\t\t\\mathcal B(n, a) := B_{1/n}(a).\n\t\t$$\n\t\t\n\t\tLet $\\varepsilon \\in \\mathbb R_{> 0}$ and let $x \\in X$. Then $B_\\varepsilon(x)$ defines an open ball in $\\mathbb X$.\n\t\t\n\t\tAs $A^- = X$ and $x \\in X$, $x \\in A^-$ also. Thus, there exists an $a \\in A \\cap B_\\varepsilon (x)$.\n\t\t\n\t\tBy Proposition \\ref{prop: open balls of point inside open ball}, as $a \\in B_\\varepsilon(x)$, there exists a $\\delta \\in \\mathbb R_{> 0}$ such that $B_\\delta(a) \\subseteq B_\\varepsilon (x)$.\n\t\t\n\t\tBy Archimedean property, let $k \\in \\mathbb N$ such that $k > \\frac{1}{\\delta}$, then we have\n\t\t$$\n\t\t\\mathcal B(k, a) = B_{1/k}(a) \\subseteq B_\\delta (a) \\subseteq B_\\varepsilon (x).\n\t\t$$\n\t\t\n\t\tBy Proposition \\ref{prop: alternative definition of analytic basis}, $\\mathcal B[\\mathbb N \\times A]$ is an analytic basis for $\\mathcal T$. As $\\mathbb N \\times A$ is countable, the image $\\mathcal B[\\mathbb N \\times A]$ is also countable.\n\t\t\n\t\tTherefore, $\\mathcal B[\\mathbb N \\times A]$ is a countable analytic basis for $\\mathcal T$. By Definition \\ref{def: second-countable}, $\\mathbb X$ is second-countable.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n\\section{Lindel\\\"of Space}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: lindelof}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space.\n\t\n\tThen $\\mathbb X$ is said to be \\textit{Lindel\\\"of} iff every open cover for $X$ has a countable subcover.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: second-countable space is lindelof}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a second-countable topological space.\n\t\n\tThen $\\mathbb X$ is Lindel\\\"of.\n\t\n\t\\begin{proof}\n\t\tAs $\\mathbb X$ is second-countable, by Definition \\ref{def: second-countable}, there exists a countable basis $\\mathcal B$ for $\\mathcal T$.\n\t\t\n\t\tLet $\\mathcal U$ be an open cover of $\\mathbb X$, no matter it is countable or not.\n\t\t\n\t\tBy Definition \\ref{def: analytic basis}, for any $U \\in \\mathcal U$, there exists an $\\mathcal A \\subseteq \\mathcal B$ such that $\\bigcup \\mathcal A = U$.\n\t\t\n\t\tLet $f: \\mathcal B \\to \\mathcal U$ be defined as\n\t\t$$\n\t\tf(B) := \\text{a random $U \\in \\mathcal B$ with $U \\supseteq B$}.\n\t\t$$\n\t\t\n\t\tAs $\\mathcal B$ is an open over of $X$ and for any $B \\in \\mathcal B$, $f(B) \\supseteq B$, thus $f[\\mathcal B]$ is an open cover of $\\mathcal B$.\n\t\t\n\t\tAs $\\mathcal U$ is the codomain of $f$, $f[\\mathcal B] \\subseteq \\mathcal U$.\n\t\t\n\t\tTherefore, $f[\\mathcal B]$ is a subcover of $\\mathcal U$.\n\t\t\n\t\tAs $\\mathcal B$ is countable, it image $f[\\mathcal B]$ is countable.\n\t\t\n\t\tTherefore, $f[\\mathcal B]$ is a countable subcover of $\\mathcal U$.\n\t\t\n\t\tAs $\\mathcal U$ is arbitrarily given, by Definition \\ref{def: lindelof}, $\\mathbb X$ is Lindel\\\"of.\n\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tSorgenfrey line is a topological space which is Lindel\\\"of but not second-countable. (See Section \\ref{sec: sorgenfrey line}.)\n\\end{example}\n%--------------------------------\n\n\n\n%================================\n%::::::::::::::::::::::::::::::::\n\\chapter{Continuous Mappings}\n%::::::::::::::::::::::::::::::::\n%================================\n\n\n%================================\n\\section{Continuous Mappings}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: continuous mapping}\n\tLet $\\mathbb X = (X, \\mathcal T_X)$ and $\\mathbb Y = (X, \\mathcal T_Y)$ be topological spaces, let $f: \\mathbb X \\to \\mathbb Y$, and let $A \\subseteq X$ be a mapping.\n\t\n\tThen $f$ is said to be \\textit{continuous on $A$} iff there exists a $U_X \\in \\mathcal T_X$ with $A \\subseteq U_X$, such that for any $U_Y \\in \\mathcal T_Y$,\n\t$$\n\tf^{-1}[U_Y] \\cap U_X \\in \\mathcal T_X.\n\t$$\n\t\n\t$f$ is a \\textit{continuous mapping} iff $A = X$; i.e., it is continuous on whole $X$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tBy Definition \\ref{def: continuous mapping}, $f$ is \\textit{continuous at a point $x \\in X$}, iff it is continuous on some $U_X \\in \\mathcal T$ with $x \\in U_X$, as $x$ here can be considered as a singleton $\\{x\\}$.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tThere is a common error: if for any $U_X \\in \\mathcal T_X$, its image $f[U_X] \\in \\mathcal T_Y$ also, then $f$ is continuous. But, this condition also holds for some discontinuous mappings.\n\t\n\tFor example, let $\\mathbb X = (\\mathbb R, \\mathcal T_X)$ be a topological space where $\\mathcal T$ induced by Euclidean metric, and let $\\mathbb Y = (\\mathbb R, \\mathcal T_Y)$ be a discrete topological space. Let $\\imath: \\mathbb X \\to \\mathbb Y$ be an identity mapping; i.e., it is defined as\n\t$$\n\t\\imath: \\mathbb X \\to \\mathbb Y : x \\mapsto x.\n\t$$\n\t\n\tFor any $A \\subseteq \\mathbb R$, clearly, $\\imath[A] \\in \\mathcal T_Y$ holds. But for some (or for all) $B \\in \\mathcal T_Y \\setminus \\mathcal T_X$, $\\imath^{-1}[B] \\notin \\mathcal T$. Thus, $\\imath$ is not a identity mapping.\n\t\n\tIndeed, for any identity mapping $\\imath: (X, \\mathcal T_X) \\to (Y, \\mathcal T_Y)$, $\\imath$ is continuous iff $\\mathcal T_X \\supseteq \\mathcal T_Y$.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t\\label{prop: alternative definition of continuous mapping}\n\tLet $\\mathbb X = (X, \\mathcal T_X)$ be a topological space, where $\\mathcal T_X$ is the discrete topology on $X$. Let $\\mathbb Y = (X, \\mathcal T_Y)$ be any topological space. Then for any $f: \\mathbb X \\to \\mathbb Y$, $f$ is continuous.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: alternative definition of continuous mapping}\n\tLet $\\mathbb X = (X, \\mathcal T_X)$ and $\\mathbb Y = (X, \\mathcal T_Y)$ be topological spaces, let $f: \\mathbb X \\to \\mathbb Y$, and let $A \\subseteq X$ be a mapping.\n\t\n\t$f$ is continuous on $A$ iff for any $U_Y \\in \\mathcal T$ with $f[A] \\subseteq U_Y$, there exists a $U_X$ with $A \\subseteq U_X$, such that $f[U_X] \\subseteq U_Y$.\n\t\n\t\\begin{proof}\n\t\tFirst, prove $\\Rightarrow$.\n\t\t\n\t\tAssume $f$ is continuous on $A$, then, by Definition \\ref{def: continuous mapping}, let $U_Y \\in \\mathcal T$ with $f[A] \\subseteq U_Y$, then there exists $U_X \\in \\mathcal T$ with $A \\subseteq U_X$, such that\n\t\t$$\n\t\tf^{-1}[U_Y] \\cap U_X \\in \\mathcal T.\n\t\t$$\n\t\t\n\t\tThen we have\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t& U_X \\subseteq f^{-1}[U_Y] \\cap U_X \\\\\n\t\t\t\\implies & f[U_X] \\subseteq f[f^{-1}[U_Y] \\cap U_X] \\\\\n\t\t\t\\implies & f[U_X] \\subseteq f[f^{-1}[U_Y]] \\cap f[U_X] \\\\\n\t\t\t\t&\\text{(\\href{https://proofwiki.org/wiki/Image_of_Intersection_under_Mapping}{Image of Intersection under Mapping})} \\\\\n\t\t\t\\implies & f[U_X] \\subseteq U_Y \\cap f[U_X]. \\\\\n\t\t\t\t&\\text{(\\href{https://proofwiki.org/wiki/Image_of_Inverse_Image}{Image of Inverse Image})} \\\\\n\t\t\t\\implies & f[U_X] \\subseteq U_Y.\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: composite of continuous mapping is continuous}\n\tLet $\\mathbb X = (X, \\mathcal T_Y)$, $\\mathbb Y = (X, \\mathcal T_Y)$ and $\\mathbb Z = (X, \\mathcal T_Z)$ be topological spaces, let $f: \\mathbb X \\to \\mathbb Y$ and $g: \\mathbb Y \\to \\mathbb Z$ be continuous mapping.\n\t\n\tThen $f \\circ g$ is continuous.\n\t\n\t\\begin{proof}\n\t\tBy Definition \\ref{def: continuous mapping}, as $g$ is continuous, for any $U_Z \\in \\mathcal T_Z$, $g^{-1}[U_Z] \\in \\mathcal T_Y$. Similarly, $f^{-1}[g^{-1}[U_Z]] \\in \\mathcal T_X$.\n\t\t\n\t\tAs $U_Z \\in \\mathcal T_Z$ is arbitrarily given, $f \\circ g$ is continuous.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n\\section{Homeomorphisms}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: homeomorphism}\n\tLet $\\mathbb X = (X, \\mathcal T_X)$ and $\\mathbb Y = (X, \\mathcal T_Y)$ be topological spaces, and let $f: \\mathbb X \\to \\mathbb Y$ be a mapping.\n\t\n\t$f$ is a \\textit{homeomorphism} iff\n\t\\begin{enumerate}[\\bf H1.]\n\t\t\\item $f$ is bijective (injective and surjective);\n\t\t\\item $f$ is continuous;\n\t\t\\item $f^{-1}$ is continuous;\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: homeomorphic}\n\tLet $\\mathbb X = (X, \\mathcal T_X)$ and $\\mathbb Y = (X, \\mathcal T_Y)$ be topological spaces.\n\t\n\t$\\mathbb X$ and $\\mathbb Y$ are said to be \\textit{homeomorphic}, denoted $\\mathbb X \\cong \\mathbb Y$, iff there exists a homeomorphism between $\\mathbb X$ and $\\mathbb Y$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tRigorously speaking, if we say that two subsets $A, B \\subseteq X$ are homeomorphic, i.e., $A \\cong B$, $A$ and $B$ are considered as subspaces of $\\mathbb X = (X, \\mathcal T)$, and these two subspaces are homeomorphic.\n\t\n\tIndeed, being homeomorphic is a relation between topological spaces but not sets without considering their togopolgies.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tBeing homeomorphic is an equivalent relation.\n\t\n\t\\begin{proof}\n\t\tLet $\\mathbb X = (X, \\mathcal T_Y)$, $\\mathbb Y = (X, \\mathcal T_Y)$ and $\\mathbb Z = (X, \\mathcal T_Z)$ be topological spaces.\n\n\t\tLet $\\imath: \\mathbb X \\to \\mathbb X$ be an identity mapping.\n\t\t\n\t\tFor any $x_1, x_2 \\in X$ with $x_1 \\ne x_2$, $\\imath(x_1) = x_2$ and $\\imath (x_2) = x_2$, so $\\imath (x_1) \\ne \\imath(x_2)$. Thus $\\imath$ is injective.\n\t\t\n\t\tFor any $x \\in X$, there exists $\\imath^{-1}(x) = x \\in X$. Thus $\\imath$ is surjective.\n\t\t\n\t\tAs $\\imath$ is injective and surjective, it is bijective.\n\t\n\t\tFor any $U \\in \\mathcal T_X$, $\\imath^{-1}[U] = U \\in \\mathcal T_X$. Thus, by Definition \\ref{def: continuous mapping}, $\\imath$ is continuous. Similarly, $\\imath^{-1}$ is continuous.\n\t\t\n\t\tTherefore, by Definition \\ref{def: homeomorphism}, $\\imath$ is an homeomorphism between $\\mathbb X$ and $\\mathbb X$. By Definition \\ref{def: homeomorphic}, $\\mathbb X$ is homeomorphic to itself, i.e., $\\mathbb X \\cong \\mathbb X$.\n\t\t\n\t\tThus, being homeomorphic is reflexive.\n\t\t\n\t\t\\qedlm\n\t\t\t\t\n\t\tAssume $\\mathbb X \\cong \\mathbb Y$.\n\t\t\n\t\tBy Definition \\ref{def: homeomorphic}, there exists a homeomorphism $f: \\mathbb X \\to \\mathbb Y$.\n\t\t\n\t\tAs $f$ is bijective, then $f^{-1}$ is also bijective.\n\t\t\n\t\tBy Definition \\ref{def: homeomorphism}, $f$ and $f^{-1}$ are both continuous.\n\t\t\n\t\tAs $f^{-1}$ is bijective, continuous, and $(f^{-1})^{-1} = f$ is also continuous, then $f^{-1}: \\mathbb Y \\to \\mathbb X$ is also a homeomorphism. By Definition \\ref{def: homeomorphic}, we have $\\mathbb Y \\cong \\mathbb X$.\n\t\t\n\t\tThus, being homeomorphic is symmetric.\n\t\t\n\t\t\\qedlm\n\t\t\n\t\tAssume $\\mathbb X \\cong \\mathbb Y$ and $\\mathbb Y \\cong \\mathbb Z$.\n\t\t\n\t\tBy Definition \\ref{def: homeomorphic}, we have $f: \\mathbb X \\to \\mathbb Y$ and $g: \\mathbb Y \\to \\mathbb Z$ as homeomorphisms.\n\t\t\n\t\tBy Definition \\ref{def: homeomorphism} H1, $f$ and $g$ are bijective. Thus, $f \\circ g$ is bijective.\n\t\t\n\t\tBy Definition \\ref{def: homeomorphism} H2, $f$ and $g$ are continuous, so, by Proposition \\ref{prop: composite of continuous mapping is continuous}, $f\\circ g$ is continuous. Similarly, $g^{-1} \\circ f^{-1}$ is continuous. As $g^{-1} \\circ f^{-1} = (f \\circ g)^{-1}$ (see \\href{https://proofwiki.org/wiki/Inverse_of_Composite_Relation}{inverse of composite relation}), $(f \\circ g)^{-1}$ is also continuous.\n\t\t\n\t\tAs $f\\circ g$ is bijective, $f\\circ g$ is continuous and $(f\\circ g)^{-1}$ is also continuous, $f \\circ g : \\mathbb X \\to \\mathbb Z$ is a homeomorphism. By Definition \\ref{def: homeomorphic}, $\\mathbb X \\cong \\mathbb Z$.\n\t\t\n\t\tThus, being homeomorphic is transitive.\n\t\t\n\t\t\\qedlm\n\t\t\n\t\tAs being homeomorphic is reflexive, symmetric, and transitive, it is an equivalence relation.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n\n%--------------------------------\n\\begin{example}\n\tIn Euclidean metric space $\\mathbb R$, let $a, b, c, d \\in \\mathbb R$ with $a < b$ and $c < d$, then we have:\n\t\\begin{itemize}\n\t\t\\item $[a, b] \\cong [c, d]$;\n\t\t\\item $[a, b) \\cong [c, d)$;\n\t\t\\item $[a, b) \\cong (c, d]$;\n\t\t\\item $(a, b) \\cong (c,d)$.\n\t\\end{itemize}\n\\end{example}\n%--------------------------------\n\n\n\n%--------------------------------\n\\begin{example}\n\tA donut is homeomorphic to a cup, because they both have a hole.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tConsider $\\mathbb R_{[0,1]}$ and $\\mathbb R^n$ as Euclidean metric spaces. Let $A$ be an index set. For any $\\alpha \\in A$, let $f_\\alpha : I \\to X$ be a continuous and piece-wise smooth injection.\n\t\n\tThen, for any $\\alpha, \\beta \\in A$, $f_\\alpha [I] \\cong f_\\beta[I]$. (See, Figure \\ref{fig: homeomorphic curves}.)\n\\end{example}\n%--------------------------------\n\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=345pt]{notes-for-general-topology/media/curves-and-knots}\t\n    \\caption{Homeomorphic curves in $\\mathbb R^3$.}\n    \\label{fig: homeomorphic curves}\n\\end{figure}\n\n\n%--------------------------------\n\\begin{example}\n\tConsider $\\mathbb R^n$ as a Euclidean metric space, let $S^{n-1} \\subseteq \\mathbb R^n$ be a $n-1$-sphere, i.e., let $o \\in \\mathbb R^n$ and $r \\in \\mathbb R$,\n\t$$\n\tS^{n-1} := \\left\\{ x \\in \\mathbb R^n : d(o,x) = r \\right\\},\n\t$$\n\twhere $d$ is the Euclidean metric on $\\mathbb R^n$.\n\t\n\tLet $y \\in S^{n - 1}$, and let\n\t$$\n\tU \\in \\left\\{ S^{n - 1} \\setminus \\overline B_\\varepsilon (x), S^{n-1} \\setminus \\{x\\} \\right\\},\n\t$$\n\twhere $\\varepsilon \\in \\mathbb R$ suffices\n\t$$\n\t0 < \\varepsilon < \\max_{a,b \\in S^{n-1}} d(a,b).\n\t$$\n\t\n\tThen we have $U \\cong \\mathbb R^{n - 1}$.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space with $\\mathcal T$ discrete. For any $U,V \\in X$ with $|U| = |V| = |X|$, $U \\cong V$.\n\t\n\t\\begin{proof}\n\t\tAs $\\mathcal T = 2^X$, for any $U, V \\in X$, $(U, 2^U )$ and $( V, 2^V )$ are subspace of $\\mathbb X$.\n\t\t\n\t\tBy the definition of comparison of cardinality, if $|U| = |V|$, there exists a bijection $f: U \\to V$.\n\t\t\n\t\tFor any $A \\in 2^V$, $f[A] \\in 2^U$, thus, by Definition \\ref{def: continuous mapping}, $f$ is continuous. Similarly, $f^{-1}$ is also continuous.\n\t\t\n\t\tAs $f$ is bijective, and bi-continuous, by Definition \\ref{def: homeomorphism}, $f$ is a homeomorphism between $(U, 2^U)$ and $(V, 2^V)$. By Definition \\ref{def: homeomorphic}, $U \\cong V$.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{example}\n%--------------------------------\n\n\n%================================\n\\section{Topological Equivalent Metrics}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: topologically equivalent metric space}\n\tLet $\\mathbb X_1 = (X, d_1)$ and $\\mathbb X_2 = (X, d_2)$ be metric spaces.\n\t\n\t$d_1$ and $d_2$ are said to be \\textit{topologically equivalent} iff they induce the same topology. Explicitly, for any $U \\subseteq A$,\n\t$$\n\t(\\exists \\varepsilon_1 \\in \\mathbb R_{> 0}) \\quad U = \\bigcup_{x \\in U} B_{\\varepsilon_1}(x; d_1) \\iff (\\exists \\varepsilon_2 \\in \\mathbb R_{> 0}) \\quad U = \\bigcup_{x \\in U} B_{\\varepsilon_2} (x; d_2).\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: Lipschitz equivalent}\n\tLet $\\mathbb X_1 = (X, d_1)$ and $\\mathbb X_2 = (X, d_2)$ be metric spaces.\n\t\n\t$d_1$ and $d_2$ are said to be \\textit{Lipschitz equivalent} iff there exists $c, k \\in \\mathbb R_{> 0}$ such that for any $x,y \\in X$,\n\t$$\n\tc d_1(x,y) \\le d_2(x,y) \\le kd_1 (x, y).\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tLet $\\mathbb X_1 = (X, d_1)$ and $\\mathbb X_2 = (X, d_2)$ be metric spaces.\n\t\n\tIf $d_1$ and $d_2$ are Lipschitz equivalent, then $d_1$ and $d_2$ are topologically equivalent.\n\t\n\t\\begin{proof}\n\t\tAs $d_1$ and $d_2$ are Lipschitz equivalent, there exists $k \\in \\mathbb R_{> 0}$ such that for any $x,y \\in X$,\n\t\t$$\n\t\td_2 (x,y) \\le k d_1 (x,y).\n\t\t$$\n\t\t\n\t\tThen, for any $\\varepsilon \\in \\mathbb R_{> 0}$, we have\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\tB_\\varepsilon (x; d_2) \\supseteq B_{\\varepsilon} (x; kd_2)\n\t\t\t\\iff B_\\varepsilon (x; d_2) \\supseteq B_{\\varepsilon / k} (x; d_2).\n\t\t\\end{aligned}\n\t\t$$\n\t\t\n\t\tThen, for any open $\\varepsilon$-ball $B_\\varepsilon (x, d_1)$ (open in $\\mathbb X_1$), there exists $k \\in \\mathbb R_{> 0}$ such that $B_{\\varepsilon/k} (x; d_2) \\subseteq B_\\varepsilon (x;d_1)$. Thus $B_\\varepsilon (x, d_1)$ is also open in $\\mathbb X_1$.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tThere exists homeomorphic metric spaces whose metrics are not Lipschitz equivalent\n\t\n\t\\begin{proof}\n\t\tLet $\\mathbb X = (\\mathbb Z, d)$ be a metric space where $d$ is a standard metric on $\\mathbb Z$. Let $\\mathbb X' = (\\mathbb Z, d')$ where $d'$ is a discrete metric space.\n\t\t\n\t\t$d$ and $d'$ induce the same topology, but they are not Lipschitz equivalent.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n\n\n\n%================================\n%::::::::::::::::::::::::::::::::\n\\chapter{Separation Axioms (Kolmogorov to Hausdorff)}\n%::::::::::::::::::::::::::::::::\n%================================\n\n\n%================================\n\\section{Neighbourhood Systems}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: neighbourhood}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\tA subset $N \\subseteq X$ is a \\textit{neighbourhood of $A$} iff\n\t$$\n\t(\\exists U \\in \\mathcal T) \\quad A \\subseteq U \\subseteq N.\n\t$$\n\t\n\tIf $A = \\{x\\}$, we simply call $N$ a \\textit{neighbourhood of $x$}.\n\t\n\tIf $N \\in \\mathcal T$ also, then $N$ is an \\textit{open neighbourhood of $A$}; and if $N$ is closed, then $N$ is a \\textit{closed neighbourhood of $A$}.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\n\t$A \\in \\mathcal T$ iff for any $x \\in A$, $A$ is a neighbourhood of $x$.\n\t\n\t\\begin{proof}\n\t\tFirst, prove $\\Rightarrow$.\n\t\t\n\t\tIf $A \\in \\mathcal T$, then, by Definition \\ref{def: neighbourhood}, for any $x \\in A$, we have\n\t\t$$\n\t\tx \\in A \\subseteq A.\n\t\t$$\n\t\t\n\t\t\\qedlm\n\t\t\n\t\tNow, prove $\\Leftarrow$.\n\t\t\n\t\tAiming for a contradiction, suppose for any $x \\in A$, $A$ is a neighbourhood of $x$, but $A\\notin \\mathcal T$.\n\t\t\n\t\tAs $X \\setminus A$ is not closed, (otherwise, by Definition \\ref{def: closed set}, $A = X \\setminus (X \\setminus A)$ is open) by Proposition \\ref{prop: closed iff contain all limit point}, there exists $x \\in \\Li(X \\setminus A) \\setminus (X \\setminus A)$.\n\t\t\n\t\tThen, for such an $x \\in A$ (for $x \\notin X \\setminus A$), for any $U \\in \\mathcal T$ with $x \\in U$,\n\t\t$$\n\t\tU \\cap (X \\setminus A) \\ne \\emptyset. \\qquad \\text{(Definition \\ref{def: limit point})}\n\t\t$$\n\t\t\n\t\tBy Definition \\ref{def: neighbourhood}, $A$ fails to be a neighbourhood of $x$. This contradicts the assumption.\n\t\t\n\t\tThus $A$ has to be open.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n% Share on ProofWiki\n% https://proofwiki.org/wiki/Set_is_Open_iff_Neighborhood_of_all_its_Points\n\n\n\n%================================\n\\section{$T_0$ (Kolmogorov) Spaces}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: T0 space}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space.\n\t\n\t$\\mathbb X$ is said to be $T_0$ or \\textit{Kolmogorov} iff for any $x,y \\in S$ with $x \\ne y$, $x$ and $y$ are \\textit{topologically distinguishable}.\n\t\n\tThat is, let $\\mathcal U: X \\to \\mathcal T$ be defined as\n\t$$\n\t\\mathcal U(x) := \\{U \\ni x\\},\n\t$$\n\tthen $|\\mathcal U[X]| = |X|$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tThere exist topological spaces which are not Kolmogorov.\n\t\n\t\\begin{proof}\n\t\tLet $\\mathbb X = (X, \\mathcal T)$ where $\\mathcal T$ indiscrete. For any $x,y \\in X$ with $x \\ne y$, they are not topologically distinguishable.\n\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tIn this proposition, if $|X| = \\{0,1\\}$, then it is vacuously true that $\\mathbb X$ is Kolmogorov and not Kolmogorov.\n\\end{note}\n%--------------------------------\n\n\n%================================\n\\section{$T_1$ (Fr\\'echet) Spaces}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: T1 space}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space.\n\t\n\t$\\mathbb X$ is said to be $T_1$ or \\textit{Fr\\'echet} iff for any $x, y \\in X$ with $x \\ne y$, there exists $U_x, U_y \\in X$ with $x \\in U_x$ and $y \\in U_x$, such that\n\t$$\n\tx \\notin U_y \\land y \\notin U_x.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n\n\n%--------------------------------\n\\begin{proposition}\n\t\\label{prop: T1 iff monotones are closed}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a Fr\\'echet space.\n\t\n\t$\\mathbb X$ is Fr\\'echet, iff for any $x \\in X$, $\\{x\\}$ is closed.\n\t\n\t\\begin{proof}\n\t\tFirst, prove $\\Rightarrow$.\n\t\t\n\t\tLet $x \\in X$.\n\t\tAs $X$ is Fr\\'echet, for any $y \\in X \\setminus \\{x\\}$, there exists $U \\in \\mathcal T$ with $y \\in U$ such that $x \\notin U$.\n\t\t\n\t\tLet $\\mathcal U$ be the family of all such $U$ for any $y \\in X \\setminus \\{x\\}$.\n\t\t\n\t\tBy Open Set Axioms (Definition \\ref{def: open set axioms}), $\\bigcup \\mathcal U \\in \\mathcal T$.\n\t\t\n\t\tAs $x \\notin \\bigcup \\mathcal U$, by De Morgan's law, we have\n\t\t$$\n\t\tx \\in \\{x\\} = X \\setminus \\bigcup \\mathcal U.\n\t\t$$\n\t\t\n\t\tThus, $\\{x\\}$ is closed.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tThere exist Kolmogorov spaces which are not Fr\\'echet spaces.\n\t\n\t\\begin{proof}\n\t\tLet $\\mathbb X = (X, \\mathcal T)$ where there exists an $x \\in X$ such that for any $U \\in \\mathcal T$, $x \\in U$. Assume for any $y \\in X$ with $x \\ne y$, $x$ and $y$ are topologically distinguishable, then $\\mathbb X$ is Kolmogorov. But, by assumption and by Definition \\ref{def: T1 space}, $\\mathbb X$ is not Fr\\'echet.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n\\section{$T_2$ (Hausdorff) Spaces}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: Hausdorff space}\n\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space.\n\t\n\t$\\mathbb X$ is said to be $T_2$ or \\textit{Hausdorff}, iff for any $x, y \\in X$ with $x \\ne y$, $x$ and $y$ are \\textit{separated by open neighbourhood}.\n\t\n\tThat is, there exists $U_x, U_y \\in \\mathcal T$ with $x \\in U_x$ and $y \\in U_y$, such that\n\t$$\n\tU_x \\cap U_y = \\emptyset.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tHausdorff spaces are Fr\\'echet.\n\t\n\t\\begin{proof}\n\t\tLet $\\mathbb X = (X, \\mathcal T)$ be a Hausdorff space.\n\t\t\n\t\tAs $\\mathbb X$ is Hausdorff, by Definition \\ref{def: Hausdorff space}, for any $x,y \\in X$ with $x \\ne y$, there exists $U_y \\in \\mathcal T$ with $y \\in U_y$ and $U_x \\in \\mathcal T$ with $x \\in U_x$ such that $U_x \\cap U_y = \\emptyset$. Clearly, $x \\notin U_y$, thus $\\mathbb X$ is Fr\\'echet.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tThere exist Fr\\'echet spaces which are not Hausdorff.\n\t\n\t\\begin{proof}\n\t\tLet $\\mathbb X = (X, \\mathcal T)$ be a topological space where $X$ is infinite, and $\\mathcal T$ is generated by the synthetic basis\n\t\t$$\n\t\t\\mathcal B = \\{ \\text{cofinite subset of $X$} \\}.\n\t\t$$\n\t\t\n\t\tBy Definition \\ref{def: topology generated by basis}, for any $U \\in \\mathcal T$, there exists an $\\mathcal A \\subseteq \\mathcal B$ such that\n\t\t$$\n\t\tU = \\bigcup \\mathcal A.\n\t\t$$\n\t\t\n\t\tThus, $\\mathcal T$ is the family of all cofinite subset of $X$ ($\\mathcal T = \\mathcal B$).\n\t\t\n\t\tFor any $x \\in X$ with $x \\ne y$, $X \\setminus \\{x\\} \\in \\mathcal T$. By Definition \\ref{def: closed set}, the complement $\\{x\\}$ is closed. By Definition \\ref{def: T1 space}, $\\mathbb X$ is Fr\\'echet.\n\t\t\n\t\tAiming for a contradiction, suppose $\\mathbb X$ is also Hausdorff.\n\t\t\n\t\tLet $y \\in X$ with $x \\ne y$.\n\t\t\n\t\tBy Definition \\ref{def: Hausdorff space}, there exists a $U_x,U_y \\in \\mathcal T$ with $x \\in U_x$ and $y \\in U_y$, such that\n\t\t$$\n\t\tU_x \\cap U_y = \\emptyset.\n\t\t$$\n\t\t\n\t\tThis implies $U_y \\subseteq X \\setminus U_x$. By assumption, $U_x$ is cofinite, thus $X \\setminus U_x$ is finite. Thus $U_y$ is also finite. This contradicts the assumption of $\\mathcal T$.\n\t\t\n\t\tThus, $\\mathbb X$ is not Hausdorff.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tMetric spaces are Hausdorff.\n\t\n\t\\begin{proof}\n\t\tLet $\\mathbb X = (X, d)$ be a metric space.\n\t\t\n\t\tAiming for a contradiction, suppose $\\mathbb X$ is not Hausdorff. By Definition \\ref{def: Hausdorff space}, there exists $x,y \\in X$ with $x \\ne y$ which are not separated by open neighbourhood.\n\t\t\n\t\tBy Definition \\ref{def: ball}, for any $\\varepsilon \\in \\mathbb R_{> 0}$, $B_\\varepsilon(x) \\cap B_\\varepsilon(y) \\ne \\emptyset$.\n\t\t\n\t\tLet $r = d(x,y) / 2$ and let $z \\in B_r(x) \\cap B_r(y)$.\n\t\t\n\t\tAs $z \\in B_r(x)$, by Definition \\ref{def: ball}, $d(x,z) < r$.\n\t\t\n\t\tSimilarly, as $z \\in B_r(y)$, $d(y,z) < r$.\n\t\t\n\t\tNow we have\n\t\t$$\n\t\td(x,z) + d(y,z) < 2r = d(x,y),\n\t\t$$\n\t\tcontradicting to Metric Axioms \\ref{def: metric axioms}.\n\t\t\n\t\tThis contradiction shows that $\\mathbb X$ has to be Hausdorff.\n\t\t\n\t\t\\qed\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%================================\n\\section{Product Spaces}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: projection}\n\tLet $\\{X_i\\}_{i \\in I}$ be an indexed family, and let $\\displaystyle x \\in \\prod_{i \\in I}X_i$.\n\t\n\tFor any $i \\in I$, the \\textit{projection of $x$ on $X_i$} is the mapping $\\pr_i: X \\to X_i$ defined by\n\t$$\n\t\\pr_i(x) = x_i\n\t$$\n\twhere $x_i$ is the coordinate of $x$ on $X_i$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: product space}\n\tLet $\\{(X_i, \\mathcal T_i)\\}_{i \\in I}$ be an indexed family of topological spaces.\n\t\n\tThe \\textit{product topology} of $\\{(X_i, \\mathcal T_i)\\}_{i \\in I}$ is defined as\n\t$$\n\t\\mathcal T := \\left\\{ U = \\bigcap_{i \\in I} \\pr_i^{-1}[U_i] \\;|\\; U_i \\in \\mathcal T \\right\\}.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n%================================\n%::::::::::::::::::::::::::::::::\n\\begin{appendices}\n\t\\input{notes-for-general-topology/appendix.tex}\t\n\\end{appendices}\n%::::::::::::::::::::::::::::::::\n%================================", "meta": {"hexsha": "653b2e64d41f161dd56dccb3992a03a2ec040775", "size": 90887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology/0-content.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology/0-content.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology/0-content.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.279751007, "max_line_length": 492, "alphanum_fraction": 0.5641840967, "num_tokens": 30015, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.8872045862611166, "lm_q1q2_score": 0.8138351245682149}}
{"text": "\\chapter{Medians and Order Statistics}\n\n\\section{Minimum and maximum}\n\n\\begin{enumerate}\n\n\\item[9.1{-}1]{Show that the second smallest of $n$ elements can be found with\n$n + \\ceil{\\lg n} - 2$ comparisons in the worst case. (\\emph{Hint:} Also find\nthe smallest element.)}\n\n\\begin{framed}\nLets find first the smallest element. Compare the elements in pairs and discard\nthe largest element of each pair. The number of elements is now $\\ceil{n/2}$.\nRepeat this operation recursively to the remaining elements until the smallest\nelement is found. Since we discard one element in each comparison, the number of\ncomparisons is the number of elements that is not the smaller.  Thus, $n - 1$\ncomparisons. Note that the second smallest element can only be greater than the\nsmallest element. Thus, the second smallest element is among these\n$\\ceil{\\lg n}$ elements that were discarded when compared to the smallest\nelement. Use the same recursive approach on these $\\ceil{\\lg n}$ elements to\nfind the second smallest with $\\ceil{\\lg n} - 1$ comparisons. The total number\nof comparisons in the worst-case is then $n - 1 + \\ceil{\\lg n}\n- 1 = n + \\ceil{\\lg n} - 2$.\n\\end{framed}\n\n\\item[9.1{-}2]{($\\star$) Prove the lower bound of $\\ceil{3n/2} - 2$ comparisons\nin the worst case to find both the maximum and minimum of $n$ numbers.\n(\\emph{Hint:} Consider how many numbers are potentially either the maximum or\nminimum, and investigate how a comparison affects these counts.)}\n\n\\begin{framed}\nAt the start, any of the $n$ the elements can be both the minimum and the\nmaximum. After the first comparison, we can discard the largest as not being the\nminimum and the smallest as not being the maximum. From now on we have two\noptions: compare two different elements or compare one of the elements\npreviously compared with a different element. The first option will decrease by\none both the number of potential minimums and potential maximums, while the\nsecond option will only decrease one of these totals. Thus, the best way to\nstart is to group the elements in pairs and compare them, which requires\n$\\floor{n/2}$ comparisons. After comparing all the pairs, we will have\n$\\ceil{n/2}$ potential maximums and $\\ceil{n/2}$ potential minimums. In the\nworst-case, those sets are disjoint and must be treated independently. We know\nfrom the previous question that the minimum number of comparisons needed to find\nthe minimum or the maximum among $\\ceil{n/2}$ elements is $\\ceil{n/2} - 1$.\nThus, the lower bound to find both the maximum and the minimum of $n$ numbers in\nthe worst-case is\n\\[\n  \\Bigl\\lfloor \\frac{n}{2} \\Bigr\\rfloor + 2 \\left( \\Bigl\\lceil \\frac{n}{2} \\Bigr\\rceil - 1 \\right).\n\\]\n\nIf $n$ is even, we have\n\\[\n  \\Bigl\\lfloor \\frac{n}{2} \\Bigr\\rfloor + 2 \\left( \\Bigl\\lceil \\frac{n}{2} \\Bigr\\rceil - 1 \\right)\n  = \\frac{n}{2} + n - 2\n  = \\frac{3n}{2} - 2\n  = \\Bigl\\lceil \\frac{3n}{2} \\Bigr\\rceil - 2.\n\\]\n\nIf $n$ is odd, we have\n\\[\n  \\Bigl\\lfloor \\frac{n}{2} \\Bigr\\rfloor + 2 \\left( \\Bigl\\lceil \\frac{n}{2} \\Bigr\\rceil - 1 \\right)\n  = \\frac{n - 1}{2} + (n + 1) - 2\n  = \\frac{3n - 3}{2}\n  = \\Bigl\\lceil \\frac{3n}{2} \\Bigr\\rceil - 2.\n\\]\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{Selection in worst-case linear time}\n\n\\begin{enumerate}\n\n\\item[9.2-1]{Show that \\textsc{Randomized-Select} never makes a recursive call\nto a 0-length array.}\n\n\\begin{framed}\nAt the start of each recursive call, a random pivot is chosen. If it happens to\nbe the $i$th element, the element being searched has been found and is returned\nwithout any additional recursion call. Otherwise, the $i$th element is either\nbefore or after the pivot and a recursive call is made on the side of the\nsubarray that includes the $i$th element.\n\\end{framed}\n\n\\item[9.2-2]{Argue that the indicator random vartiable $X_k$ and the value\n$T(\\max(k - 1, n - k))$ are independent.}\n\n\\begin{framed}\nBoth $X_k$ and $T(\\max(k - 1, n - k))$ depends on the value of $k$. However, no\nmatter if $X_k$ is 0 or 1, the value of $T(\\max(k - 1, n - k))$ is the same.\n\\end{framed}\n\n\\item[9.2-3]{Write an iterative version of \\textsc{Randomized-Select}.}\n\n\\begin{framed}\nThe pseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Randomized-Select-Iterative}\n\\SetKwProg{myalg}{}{}{}\n\\nonl\\myalg{\\algo{A, p, r, i}}{%\n  \\If{$p == r$}{%\n    \\Return{$A[p]$}\\;\n  }\n  \\While{\\texttt{\\upshape{True}}}{%\n    $q = \\texttt{Randomized-Partition}(A, p, r)$\\;\n    $k = q - p + 1$\\;\n    \\If{$i == k$}{%\n      \\Return{$A[q]$}\\;\n    }\n    \\ElseIf{$i < k$}{%\n      $r = q - 1$\\;\n    }\n    \\Else{%\n      $p = q + 1$\\;\n      $i = i - k$\\;\n    }\n  }\n}\n\\end{algorithm}\n\\end{framed}\n\n\\item[9.2-4]{Suppose we use \\textsc{Randomized-Select} to select the minimum\nelement of the array $A = \\langle 3, 2, 9, 0, 7, 5, 4, 8, 6, 1 \\rangle$.\nDescribe a sequence of partitions that results in a worst-case performance of\n\\textsc{Randomized-Select}.}\n\n\\begin{framed}\nThe worst-case occurs when the pivot is always the greatest element. The number\nof calls to partition in this case is $n - 1$.\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{Selection in worst-case linear time}\n\n\\begin{enumerate}\n\n\\item[9.3-1]{In the algorithm \\textsc{Select}, the input elements are divided\ninto groups of 5. Will the algorithm work in linear time if they are divided\ninto groups of 7? Argue that \\textsc{Select} does not run in linear time if\ngroups of 3 are used.}\n\n\\begin{framed}\nIf the elements are divided into groups of 7, the number of elements\ngreater/smaller than the median-of-medians is at least\n\\[\n  7 \\left( \\Bigl\\lceil \\frac{1}{2} \\Bigl\\lceil \\frac{n}{7} \\Bigr\\rceil \\Bigr\\rceil - 2 \\right)\n  \\ge \\frac{4n}{14} - 8 = \\frac{2n}{7} - 8,\n\\]\nwhich implies that, in the worst-case, step 5 calls \\textsc{Select} recursively\non at most\n\\[\n  n - \\left( \\frac{2n}{7} - 8 \\right) = \\frac{5n}{7} + 8\n\\]\nelements. We then have the recurrence\n\\[\n  T(n) = T\\left( \\Bigl\\lceil \\frac{n}{7} \\Bigr\\rceil \\right) + T\\left( \\frac{5n}{7} + 8 \\right) + O(n).\n\\]\n\nWe shall prove that its running time is linear by substitution. More\nspecifically, we will show that\n\\[\n    T(n) \\le cn \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$ and $n_0$ are positive constants. Substituting into the recurrence,\nyields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\le c \\Bigl\\lceil \\frac{n}{7} \\Bigr\\rceil + c \\left( \\frac{5n}{7} + 8 \\right) + an\\\\\n       &\\le c \\frac{n}{7} + c + c \\frac{5n}{7} + 8c + an & \\text{($c \\ge 1$)}\\\\\n       &=   \\frac{6}{7} cn + 9c + an\\\\\n       &=   cn + \\left( - \\frac{1}{7} cn + 9c + an \\right)\\\\\n       &\\le cn,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds for\n\\[\n  -\\frac{1}{7} cn + 9c + an \\le 0 \\rightarrow c \\ge 7a \\left(\\frac{n}{n - 63}\\right),\n\\]\nand picking $n_0 = 126$, it holds for $c \\ge 14a$.\n\nSimilarly, with groups of 3, the number of elements greater/smaller than the\nmedian-of-medians is at least\n\\[\n  2 \\left( \\Bigl\\lceil \\frac{1}{2} \\Bigl\\lceil \\frac{n}{3} \\Bigr\\rceil \\Bigr\\rceil - 2 \\right)\n  \\ge \\frac{n}{3} - 4.\n\\]\nwhich implies that, in the worst-case, step 5 calls \\textsc{Select} recursively\non at most\n\\[\n  n - \\left( \\frac{n}{3} - 4 \\right) = \\frac{2n}{3} + 4\n\\]\nelements. We then have the recurrence\n\\[\n  T(n) = T\\left( \\Bigl\\lceil \\frac{n}{3} \\Bigr\\rceil \\right) + T\\left( \\frac{2n}{3} + 4 \\right) + O(n).\n\\]\n\nWe shall prove that its running time is $\\omega(n)$ by substitution. More\nspecifically, we will show that\n\\[\n  T(n) > cn + d \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence, yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &> c \\Bigl\\lceil \\frac{n}{3} \\Bigr\\rceil + d + c \\left( \\frac{2n}{3} + 4 \\right) + d + an\\\\\n       &> c \\frac{n}{3} + c + d + c \\frac{2n}{3} + 4c + d + an & \\text{($c \\ge 1$)}\\\\\n       &= cn + 5c + 2d + an\\\\\n       &> cn,\\\\\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds for $5c + 2d + an > 0$.\n\\end{framed}\n\n\\item[9.3-2]{Analyze \\textsc{Select} to show that if $n \\ge 140$, then at least\n$\\ceil{n/4}$ elements are greater than the median-of-medians $x$ and at least\n$\\ceil{n/4}$ elements are less than $x$.}\n\n\\begin{framed}\nWe have that at least\n\\[\n  \\frac{3n}{10} - 6\n\\]\nelements are greater/smaller than $x$. To this number be equal to or greater\nthan $\\ceil{n/4}$, we find $n$ such that\n\\begin{equation*}\n\\begin{aligned}\n  \\frac{3n}{10} - 6 \\ge \\Bigl\\lceil \\frac{n}{4} \\Bigr\\rceil\n  &\\rightarrow \\frac{3n}{10} - 6 \\ge \\frac{n}{4} + 1\\\\\n  &\\rightarrow \\frac{6n - 5n}{20} \\ge 7\\\\\n  &\\rightarrow \\frac{n}{20} \\ge 7\\\\\n  &\\rightarrow n \\ge 140.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[9.3-3]{Show how quicksort can be made to run in $O(n \\lg n)$ time in the\nworst-case, assuming that all elements are distinct.}\n\n\\begin{framed}\nUpdate the partition procedure to use the median as the pivot. It will take an\nadditional $O(n)$-time to find the median with the \\textsc{Select} procedure,\nbut the running time of partition will still be linear. We will then have the\nrecurrence\n\\[\n  T(n) = 2T \\left( \\frac{n}{2} \\right) + O(n),\n\\]\nwhich takes\n\\[\n  \\sum_{i = 0}^{\\lg n} 2^i \\cdot \\frac{n}{2^i} = \\sum_{i = 0}^{\\lg n} n = O(n \\lg n).\n\\]\n\\end{framed}\n\n\\item[9.3-4]{($\\star$) Suppose that an algorithm uses only comparisons to find\nthe $i$th smallest element in a set of $n$ elements. Show that it can also find\nthe $i - 1$ smaller elements and the $n - i$ larger elements without performing\nany additional comparisons.}\n\n\\begin{framed}\nAssume without loss of generality that the elements of the array are distinct.\nLet $x$ denote the $i$th order statistic that was found through comparisons.\nFirst note that if there exists an element $y$ that was never compared to any\nother element, its value was not taken into account to determine $x$, which\nimplies that there are at least two possible order statistics for $x$ {--} one\nfor $y < x$ and another for $y > x$. The same occurs if $y$ is only compared to\nelements that are not between $x$ and $y$ in the sorted order. Note that these\ncomparisons are insufficient to determine if $y$ is smaller or greater than $x$,\nand there will also be at least two possible order statistics for $x$.\nTherefore, to find $x$, the algorithm must compare $y$ to $x$ directly or by\ntransitivity. These comparisons are sufficient to determine the relative order\nof every element with respect to $x$, and therefore to also determine the\n$i - 1$ smaller and the $n - i$ greater elements of the array.\n\\end{framed}\n\n\\newpage\n\n\\item[9.3-5]{Suppose that you have a ``black-box'' worst-case linear-time median\nsubroutine. Give a simple, linear-time algorithm that solves the selection\nproblem for an arbitrary order statistic.}\n\n\\begin{framed}\nA simple algorithm works as follows:\n\\begin{enumerate}\n\\item Find the lower median $m$ using the ``black-box'' median subroutine.\n\\item If $i = \\ceil{n/2}$, just return $m$. Otherwise, partition the array using\n$m$ as the pivot and recursively find the $i$th element on the first\n$\\ceil{n / 2} - 1$ elements if $i < \\ceil{n / 2}$, or the $(i - \\ceil{n / 2})$th\nelement on the last $\\floor{n/2}$ elements if $i > \\ceil{n/2}$.\n\\end{enumerate}\n\nThis algorithm has the recurrence\n\\[\n  T(n) = T(n/2) + O(n),\n\\]\nwhich can be solved using case 3 of the master method, since $n^{\\lg 1}$ is\npolynomially smaller than $f(n)$. Thus, $T(n) = \\Theta(n)$.\n\nThe pseudocode of this algorithm is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Select'}\n\\SetKwProg{myalg}{}{}{}\n\\nonl\\myalg{\\algo{A, p, r, i}}{%\n  $m = \\texttt{Median}(A, p, r)$\\;\n  $k = \\ceil{n/2}$\\;\n  \\If{$i == k$}{%\n    \\Return{$m$}\\;\n  }\n  \\Else{%\n    $q = \\texttt{Partition}(A, p, r, m)$\\;\n    \\If{$i < k$}{%\n      // recurve over the first $\\ceil{n/2} - 1$ elements\\;\n      $\\texttt{Select'}(A, p, p + k - 2, i)$\\;\n    }\n    \\Else{%\n      // recurve over the last $\\floor{n/2}$ elements\\;\n      $\\texttt{Select'}(A, p + k, r, i - k)$\\;\n    }\n  }\n}\n\\end{algorithm}\n\n\\end{framed}\n\n\\newpage\n\n\\item[9.3-6]{The $k$th \\textbf{\\emph{quantiles}} of an $n$-element set are the\n$k - 1$ order statistics that divide the sorted set into $k$ equal-sized sets\n(to within 1). Give an $O(n \\lg k)$-time algorithm to list the $k$th quantiles\nof a set.}\n\n\\begin{framed}\nLet $S$ be an $n$-set and $S_{(i)}$ denote the $i$th order statistic of $S$. The\n$k$th quantiles of $S$ are the elements\n\\[\n  S_{(1 (n / k))}, S_{(2 (n / k))}, \\dots, S_{((k - 1) (n / k))}.\n\\]\nAn efficient algorithm to find the above elements work as follows:\n\\begin{enumerate}\n\\item If $k = 1$, then return $\\emptyset$.\n\\item Otherwise, do the following:\n\\begin{enumerate}\n\\item Partition $S$ around the element $S_{(\\floor{k / 2} (n / k))}$. Let $q$\ndenote the position of the pivot after partition and let $S_1$ and $S_2$ denote\nthe subsets $S[1, \\dots, q]$ and $S[q + 1, \\dots, n]$, respectively.\n\\item Recursively solve the $(\\floor{k/2})$th quantiles of $S_1$ and the\n$(\\ceil{k/2})$ quantiles of $S_2$. Let $Q_1$ and $Q_2$ denote the solutions of\n$S_1$ and $S_2$, respectively.\n\\item Return $Q_1 \\cup \\{S[q]\\} \\cup Q_2$.\n\\end{enumerate}\n\\end{enumerate}\n\nWe shall now prove that this algorithm runs in $O(n \\lg k)$. First note that\nsince\n\\[\n  n \\text{ mod } k = 0,\n\\]\n$k$ is even implies that $n$ is also even. Thus, for even $k$, we have\n\\begin{equation*}\n\\begin{aligned}\n  \\Bigl\\lfloor \\frac{k}{2} \\Bigr\\rfloor \\cdot \\frac{n}{k}\n  &= \\frac{k}{2} \\cdot \\frac{n}{k}\\\\\n  &= \\frac{n}{2}\\\\\n  &= \\Bigl\\lfloor \\frac{n}{2} \\Bigr\\rfloor,\n\\end{aligned}\n\\end{equation*}\nwhich implies that $q$ is the lower median. When $k$ is odd, we have\n\\begin{equation*}\n\\begin{aligned}\n  \\Bigl\\lfloor \\frac{k}{2} \\Bigr\\rfloor \\cdot \\frac{n}{k}\n  &=   \\frac{k - 1}{2} \\cdot \\frac{n}{k}\\\\\n  &=   \\left( \\frac{k}{2} - \\frac{1}{2} \\right) \\frac{n}{k}\\\\\n  &=   \\frac{n}{2} - \\frac{n}{2k}.\n\\end{aligned}\n\\end{equation*}\nStep (a) takes $O(1)$. Step (b) has the recurrence\n\\begin{equation*}\nT(n, k) =\n\\begin{cases}\n  O(1), & k = 1\\\\\n  T\\left( \\Bigl\\lfloor \\frac{n}{2} \\Bigr\\rfloor, \\Bigl\\lfloor \\frac{k}{2} \\Bigr\\rfloor \\right) +\n  T\\left( \\Bigl\\lceil \\frac{n}{2} \\Bigr\\rceil, \\Bigl\\lceil \\frac{k}{2} \\Bigr\\rceil \\right) +\n  O(n), & \\text{$k > 1$ and $k$ is even}\\\\\n  T\\left( \\frac{n}{2} - \\frac{n}{2k}, \\Bigl\\lfloor \\frac{k}{2} \\Bigr\\rfloor \\right) +\n  T\\left( \\frac{n}{2} + \\frac{n}{2k}, \\Bigl\\lceil \\frac{k}{2} \\Bigr\\rceil \\right) +\n  O(n), & \\text{$k > 1$ and $k$ is odd}\n\\end{cases}\n\\end{equation*}\n\nWe shall solve this recurrence through the analysis of its recursion-tree. Since\nthe problem is always divided into two subproblems, without overlap, the total\ncost over all nodes at depth $i$ is $cn$. The bottom level at depth $\\lg k$\nhas $2^{\\lg k} = k$ nodes, each contributing cost $O(1)$, for a total cost of\n$O(k)$. Thus, the cost of the entire tree is \\begin{equation*}\n\\begin{aligned}\n  T(n, k) &= \\sum_{i = 0}^{\\lg k - 1} cn + O(k)\\\\\n          &= cn \\lg k + O(k)\\\\\n          &= O(n \\lg k).\n\\end{aligned}\n\\end{equation*}\n\n\\end{framed}\n\n\\newpage\n\n\\item[9.3-7]{Describe an $O(n)$-time algorithm that, given a set $S$ of $n$\ndistinct numbers and a positive integer $k \\le n$, determines the $k$ numbers in\n$S$ that are closest to the median of $S$.}\n\n\\begin{framed}\nLet $A$ be an array of size $n$. The following algorithm finds $k$ elements of\n$A$ such that every element\n\\begin{itemize}\n\\item is greater than or equal to the $(\\floor{n/2} - \\floor{(k - 1)/2})$th\n  order statistic of $A$, and\n\\item is lower than or equal to the $(\\floor{n/2} + \\ceil{(k - 1)/2})$th order\n  statistic of $A$.\n\\end{itemize}\n\nDo the following steps:\n\\begin{enumerate}\n\\item Find the $q$th order statistic of $A$, such that\n$q = \\floor{n/2} - \\floor{(k - 1)/2}$, and partition $A$ around this element.\n\\item If $k = 1$, return $A[q]$.\n\\item Otherwise, do the following:\n\\begin{enumerate}\n\\item Let $A'$ denote subarray $A[q, \\dots, n]$.\n\\item Find the $k$th order statistic of $A'$ and partition $A'$ around this\nelement.\n\\item Return the subarray $A'[q, \\dots, q + k - 1]$.\n\\end{enumerate}\n\\end{enumerate}\n\nThe algorithm do at most two selections and two partitions. Thus, its running\ntime is $4 \\cdot O(n) + O(1) = O(n)$.\n\\end{framed}\n\n\\item[9.3-8]{Let $X[1 \\dots n]$ and $Y[1 \\dots n]$ be two arrays, each\ncontaining $n$ numbers already in sorted order. Give an $O(\\lg n)$-time algorithm\nto find the median of all $2n$ elements in arrays $X$ and $Y$.}\n\n\\begin{framed}\nNote that, since both arrays are sorted, the order statistic of $X[i]$ is\n$\\floor{(n + 1)/2}$ (the median) if, and only if,\n\\[\n  X[i] \\ge Y\\left[ \\Bigl\\lfloor \\frac{n + 1}{2} \\Bigr\\rfloor - i \\right],\n\\]\nand\n\\[\n  X[i] \\le Y\\left[ \\Bigl\\lfloor \\frac{n + 1}{2} \\Bigr\\rfloor - i + 1 \\right].\n\\]\n\nStart testing the median of $X$. If the first comparison fails, recurse over the\nright half. If the second comparison fails, recurse over the left half.\nOtherwise, return $X[i]$. If a recursion is performed on an empty array, the\nmedian is not within $X$. Repeat a similar procedure on $Y$ to find the median.\nThe complexity of this algorithm is $O(\\lg n) + O(\\lg n) = O(\\lg n)$.\n\\end{framed}\n\n\\item[9.3-9]{Professor Olay is consulting for an oil company, which is planning\na large pipeline running east to west through an oil field of $n$ wells. The\ncompany wants to connect a spur pipeline from each well directly to the main\npipeline along a shortest route (either north or south), as shown in Figure 9.2.\nGiven the $x$- and $y$-coordinates of the wells, how should the professor pick\nthe optimal location of the main pipeline, which would be the one that minimizes\nthe total length of the spurs? Show how to determine the optimal location in\nlinear time.}\n\n\\begin{framed}\nThe optimal locations are the lower and upper medians of the $y$ values. Find\none of them with the \\textsc{Select} algorithm.\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section*{Problems}\n\\addcontentsline{toc}{section}{\\protect\\numberline{}Problems}%\n\n\\begin{enumerate}\n\n\\item[9-1]{\\textbf{\\emph{Largest i numbers in sorted order}}\\\\\nGiven a set of $n$ numbers, we wish to find the $i$ largest in sorted order\nusing a comparison-based algorithm. Find the algorithm that implements each of\nthe following methods with the best asymptotic worst-case running time, and\nanalyze the running times of the algorithms in terms of $n$ and $i$.\n\n\\begin{enumerate}\n  \\item[\\textbf{a.}] Sort the numbers, and list the $i$ largest.\n  \\item[\\textbf{b.}] Build a max-priority queue from the numbers, and call \\textsc{Extract-Max} $i$ times.\n  \\item[\\textbf{c.}] Use an order-statistic algorithm to find the $i$th largest number,\n    partition around that number, and sort the $i$ largest numbers.\n\\end{enumerate}\n}\n\n\\begin{framed}\n\\begin{enumerate}\n\\item The pseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{LargestNumbersSort}\n\\SetKwProg{myalg}{}{}{}\n\\nonl\\myalg{\\algo{A, i}}{%\n  Let $B$ be an integer array of size $i$\\;\n  \\texttt{Heapsort}($A, 1, A.length$)\\;\n  \\For{$j = 1$ \\KwTo $i$}{%\n    $B[j] = A[j]$\\;\n  }\n  \\Return{$B$}\\;\n}\n\\end{algorithm}\n\n    This algorithm runs in $\\Theta(n \\lg n + i) = \\Theta(n \\lg n)$.\n\n\\item The pseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{LargestNumbersPriorityQueue}\n\\SetKwProg{myalg}{}{}{}\n\\nonl\\myalg{\\algo{A, i}}{%\n  Let $B$ be an integer array of size $i$\\;\n  \\texttt{Build-Max-Heap}($A$)\\;\n  \\For{$j = 1$ \\KwTo $i$}{%\n    $\\text{\\emph{element}}$ = \\texttt{Heap-Extract-Max}($A$)\\;\n    $B[i - j + 1] = element$\\;\n  }\n  \\Return{$B$}\\;\n}\n\\end{algorithm}\n\n\\textsc{Build-Max-Heap} call takes $O(n)$, \\textsc{Extract-Max} call takes\n$O(\\lg n)$. This algorithm runs in $O(n + i \\lg n)$.\n\n\\item The pseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{LargestNumbersOrderStatistic}\n\\SetKwProg{myalg}{}{}{}\n\\nonl\\myalg{\\algo{A, i}}{%\n  Let $B$ be an integer array of size $i$\\;\n  $q = \\texttt{Select}(A, i)$\\;\n  \\texttt{Partition}($A, 1, A.length, q$)\\;\n  \\texttt{Heapsort}($A, 1, i$)\\;\n  \\For{$j = 1$ \\KwTo $i$}{%\n    $B[j] = A[j]$\\;\n  }\n  \\Return{$B$}\\;\n}\n\\end{algorithm}\n\n\\textsc{Select} call takes $O(n)$, \\textsc{Partition} call takes $O(n)$,\n\\textsc{Quicksort} call takes $O(i \\lg i)$. This algorithm runs in $O(n + i \\lg i)$.\n\\end{enumerate}\n\\end{framed}\n\n\\newpage\n\n\\item[9-2]{\\textbf{\\emph{Weighted median}}\\\\\nFor $n$ distinct elements $x_1, x_2, \\dots, x_n$ with positive weights\n$w_1, w_2, \\dots, w_n$ such that $\\sum_{i = 1}^{n} w_i = 1$, the\n\\textbf{\\emph{weighted (lower) median}} is the element $x_k$ satisfying\n\\[\n  \\sum_{x_i < x_k} w_i < \\frac{1}{2},\n\\]\nand\n\\[\n  \\sum_{x_i > x_k} w_i \\le \\frac{1}{2}.\n\\]\n\nFor example, if the elements are 0.1, 0.35, 0.05, 0.1, 0.15, 0.05, 0.2 and each\nelement equals its weight (that is, $w_i = x$ for $i = 1, 2, \\dots, 7$), the\nmedian is 0.1, but the weighted median is 0.2.\n\n\\begin{enumerate}\n\\item[\\textbf{a.}] Argue that the median of $x_1, x_2, \\dots, x_n$ is the\nweighted median of the $x_i$ with weights $w_i = 1/n$ for $1, 2, \\dots, n$.\n\\item[\\textbf{b.}] Show how to compute the weighted median of $n$ elements in\n$O(n \\lg n)$ worst-case time using sorting.\n\\item[\\textbf{c.}] Show how to compute the weighted median in $\\Theta(n)$\nworst-case time using a linear-time median algorithm such as \\textsc{Select}\nfrom Section 9.3.\n\\end{enumerate}\n\nThe \\textbf{\\emph{post-office location problem}} is defined as follows. We are\ngiven $n$ points $p_1, p_2, \\dots, p_n$ with associated weights\n$w_1, w_2, \\dots, w_n$. We wish to find a point $p$ (not necessarily one of the\ninput points) that minimizes the sum $\\sum_{i = 1}^n w_i d(p, p_i)$, where\n$d(a, b)$ is the distance between points $a$ and $b$.\n\n\\begin{enumerate}\n\\item[\\textbf{d.}] Argue that the weighted median is a best solution for the\n1-dimensional post-office location problem, in which points are simply real\nnumbers and the distance between points $a$ and $b$ is $d(a, b) = |a - b|$.\n\n\\item[\\textbf{e.}] Find the best solution for the 2-dimensional post-office\nlocation problem, in which the points are $(x, y)$ coordinate pairs and the\ndistance between points $a = (x_1, y_1)$ and $b = (x_2, y_2)$ is the\n\\textbf{\\emph{Manhattan distance}} given by\n$d(a, b) = |x_1 - x_2| + |y_1 - y_2|$.\n\\end{enumerate}\n}\n\n\\begin{framed}\n\\begin{enumerate}\n\\item Note that there are at most $\\floor{(n - 1)/2}$ elements that are smaller\nthan the median and at most $\\ceil{(n - 1)/2}$ elements that are greater than\nthe median. Since the weight of each element is $1/n$, we have\n\\[\n  \\sum_{x_i < x_k} w_i = \\sum_{x_i < x_k} \\frac{1}{n}\n    = \\frac{1}{n} \\sum_{x_i < x_k} 1\n    \\le \\frac{1}{n} \\cdot \\Bigl\\lfloor \\frac{n - 1}{2} \\Bigr\\rfloor\n    < \\frac{1}{n} \\cdot \\frac{n}{2} = \\frac{1}{2},\n\\]\nand\n\\[\n  \\sum_{x_i < x_k} w_i = \\sum_{x_i < x_k} \\frac{1}{n}\n  = \\frac{1}{n} \\sum_{x_i < x_k} 1\n  \\le \\frac{1}{n} \\cdot \\Bigl\\lceil \\frac{n - 1}{2} \\Bigr\\rceil\n  \\le \\frac{1}{n} \\cdot \\frac{n}{2} = \\frac{1}{2},\n\\]\nwhich implies that the median is also the weighted median.\n\n\\item Sort the array with \\textsc{Heapsort}. Iterate over the elements of the\narray, accumulating the sum of their weights until the sum achieves a value that\nis greater than or equal to $1/2$. Let $x_k$ denote the last element that made\nthe sum accumulate a value greater than or equal to $1/2$. Note that at that\npoint\n\\[\n  \\sum_{x_i < x_k} w_i < \\frac{1}{2}\n\\]\nholds since the sum of the weights until the element right before $x_k$ is\nsmaller than $1/2$ and\n\\[\n  \\sum_{x_i > x_k} w_i \\le \\frac{1}{2}\n\\]\nholds since the sum of the weights until $x_k$ is greater than or equal to $1/2$\nand $\\sum_{i = 1}^{n} w_i = 1$. Thus, $x_k$ is the weighted median. This\nalgorithm takes $\\Theta(n \\lg n)$ to sort the array with \\textsc{Heapsort} and\n$O(n)$ to accumulate the weights and find the weighted median.\n\n\\item Do the following steps:\n\\begin{enumerate}\n\\item Find the median with the \\textsc{Select} algorithm.\n\\item Partition the array around the median.\n\\item Let $x_m$ denote the position of the median after partitioning. Let\n$W_L = \\sum_{X_i < X_m} w_i$ and $W_R = \\sum_{x_i > x_m} w_i$.\n\\item If $W_L < 1/2$ and $W_R \\le 1/2$, $x_m$ is the weighted median. Otherwise,\ndo the following:\n\\begin{enumerate}\n\\item If $W_L \\ge 1/2$, the weighted median is before $x_m$.\nSet $w_m = w_m + W_R$ and recurse on the left half of the array, including\n$x_m$.\n\\item If $W_R > 1/2$, the weighted median is after $x_m$. Set $w_m = w_m + W_L$\nand recurse on the right half of the array, including $x_m$.\n\\end{enumerate}\n\\end{enumerate}\n\nThis algorithm has the recurrence:\n\\[\n  T(n) = T\\left(\\frac{n}{n} + 1\\right) + \\Theta(n)\n       = \\sum_{i = 0}^{\\lg n} \\left(\\frac{n}{2^i} + 1\\right)\n       = n \\sum_{i = 0}^{\\lg n} \\frac{1}{2^i} + \\sum_{i = 0}^{\\lg n} 1\n       \\le 2n + \\lg n + 1\n       = \\Theta(n).\n\\]\n\n\\item Skipped.\n\n\\item Skipped.\n\n\\end{enumerate}\n\\end{framed}\n\n\\newpage\n\n\\item[9-3]{\\textbf{\\emph{Small order statistics}}\\\\\nWe showed that the worst-case number $T(n)$ of comparisons used by\n\\textsc{Select} to select the ith order statistic from $n$ numbers satisfies\n$T(n) = \\Theta(n)$, but the constant hidden by the $\\Theta$-notation is rather\nlarge. When $i$ is small relative to $n$, we can implement a different procedure\nthat uses \\textsc{Select} as a subroutine but makes fewer comparisons in the\nworst case.\n\n\\begin{enumerate}\n\\item[\\textbf{a.}] Describe an algorithm that uses $U_i(n)$ comparisons to\nfind the $i$th smallest of $n$ elements, where\n\\[\nU_i(n) =\n\\begin{cases}\n  T(n) & \\text{if } i \\ge n/2,\\\\\n  \\floor{n/2} + U_i(\\ceil{n/2}) + T(2i) & \\text{otherwise}.\n\\end{cases}\n\\]\n\n(\\emph{Hint:} Begin with $\\floor{n/2}$ disjoint pairwise comparisons, and\nrecurse on the set containing the smaller element from each pair.)\n\n\\item[\\textbf{b.}] Show that, if $i < n/2$, then $U_i(n) = n + O(T(2i) \\lg (n/i))$.\n\n\\item[\\textbf{c.}] Show that if $i$ is a constant less than $n/2$, then $U_i(n) = n + O(\\lg n)$.\n\n\\item[\\textbf{d.}] Show that if $i = n/k$ for $k \\ge 2$, then $U_i(n) = n + O(T(2n/k) \\lg k)$.\n\\end{enumerate}\n}\n\n\\begin{framed}\n\\begin{enumerate}\n\\item First, note that the \\textsc{Select} algorithm find the $i$th element by\npartitioning the array. That is, when the $i$th element is found, the first $i$\nelements are the $i$ smallest. However, when $n$ is too large with respect to\n$i$, it perform more comparisons than necessary. Taking the hint that the\nquestion gave us, we can reduce the number of comparisons when $n$ is too large\nby running \\textsc{Select} only when $n$ is smaller than or equal to $2i$.\n\nThe key insight to solve the question is to observe that if we first make\ndisjoint pairwise comparisons and then run \\textsc{Select} only among the\nsmallest element of each pair, the $i$th order statistic of the whole array is\namong the $i$ smallest elements that were found by \\textsc{Select} and their\nlarge counterparts on the right half of the array. This occurs because the\nremaining elements on the left half are larger than at least $i$ elements and\ntheir larger counterparts on the right half are even larger.\n\nWe can then use this notion to build a recursive algorithm that solves the\nselection problem with fewer comparisons, using the \\textsc{Select} algorithm\nonly when $n$ is small enough:\n\\begin{enumerate}\n  \\item If $i \\ge n/2$, run \\textsc{Select} and return its result.\n  \\item Otherwise, do the following:\n  \\begin{enumerate}\n    \\item Perform disjoint pairwise comparisons and rearrange the array such\n      that the smaller element of each pair appears on the left half of the\n      array, in the same order of its larger counterparts.\n    \\item Recursively find the $i$th element among the elements on the left half\n      of the array.\n    \\item The $i$th order statistic is among the first $i$ elements of the array\n      and their larger counterparts. Run \\textsc{Select} on these $2i$ elements\n      and return the result.\n  \\end{enumerate}\n\\end{enumerate}\n\n\\item Can be proved by substitution.\n\n\\item From the previous item, we have\n\\[\n  U_i(n) = n + O(T(2i) \\lg(n/i)),\n\\]\n\nwhich implies that, when $i$ is a constant less than $n/2$, we have\n\\begin{equation*}\n\\begin{aligned}\n  U_i(n) &= n + O(T(2i) \\lg(n/i))\\\\\n         &= n + O(O(1) O(\\lg n))\\\\\n         &= n + O(\\lg n).\n\\end{aligned}\n\\end{equation*}\n\n\\item If $k > 2$, then $i < n/2$ and we can use the result of item (b):\n\\begin{equation*}\n\\begin{aligned}\n  U_i(n) &= n + O(T(2i)\\lg(n/i))\\\\\n         &= n = O(T(2n/k) \\lg(n/(n/k)))\\\\\n         &= n = O(T(2n/k) \\lg(k)).\n\\end{aligned}\n\\end{equation*}\n\nIf $k = 2$, then $i = n/2$ and $\\lg k = 1$. Thus, we have\n\\begin{equation*}\n\\begin{aligned}\n  U_i(n) &=   T(n)\\\\\n         &\\le n + T(n) + \\lg k\\\\\n         &=   n + O(T(n) + \\lg k)\\\\\n         &=   n + O(T(2n/k) + \\lg k).\n\\end{aligned}\n\\end{equation*}\n\n\\end{enumerate}\n\\end{framed}\n\n\\newpage\n\n\\item[9-4]{\\textbf{\\emph{Alternative analysis of randomized selection}}\\\\\nIn this problem, we use indicator random variables to analyze the\n\\textsc{Randomized-Select} procedure in a manner akin to our analysis of\n\\textsc{Randomized-Quicksort} in Section 7.4.2.\n\nAs in the quicksort analysis, we assume that all elements are distinct, and we\nrename the elements of the input array $A$ as $z_1, z_2, \\dots, z_n$, where\n$z_i$ is the $i$th smallest element. Thus, the call\n\\textsc{Randomized-Select}($A, 1, n, k$) returns $z_k$.\n\nFor $1 \\le i < j \\le n$, let $X_{ijk}$ = I\\{$z_i$ is compared with $z_j$\nsometime during the execution of the algorithm to find $z_k$\\}.\n\n\\begin{enumerate}\n\\item[\\textbf{a.}] Give an exact expression for $\\text{E}[X_{ijk}]$.\n(\\emph{Hint:} Your expression may have different values, depending on the values\nof $i, j,$ and $k$.)\n\n\\item[\\textbf{b.}] Let $X_k$ denote the total number of comparisons between\nelements of array $A$ when finding $z_k$. Show that\n\\[\n  \\text{E}[X_k] \\le 2 \\left( \\sum_{i = 1}^{k} \\sum_{j = k}^{n} \\frac{1}{j - i + 1} +\n                             \\sum_{j = k + 1}^{n} \\frac{j - k - 1}{j - k + 1} +\n                             \\sum_{i = 1}^{k - 2} \\frac{k - i - 1}{k - i + 1} \\right).\n\\]\n\n\\item[\\textbf{c.}] Show that $\\text{E}[X_k] \\le 4n$.\n\n\\item[\\textbf{d.}] Conclude that, assuming all elements of array $A$ are\ndistinct, \\textsc{Randomized-Select} runs in expected time $O(n)$.\n\\end{enumerate}\n}\n\n\\begin{framed}\nSkipped.\n\\end{framed}\n\n\\end{enumerate}\n", "meta": {"hexsha": "b8a62cbcec031441bb19c1f3d1a691ef8d943ddb", "size": 30314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/C9.tex", "max_stars_repo_name": "danielmoraes/clrs", "max_stars_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-07-08T17:39:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-08T17:39:19.000Z", "max_issues_repo_path": "chapters/C9.tex", "max_issues_repo_name": "danielmoraes/clrs", "max_issues_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-31T20:41:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-31T20:41:48.000Z", "max_forks_repo_path": "chapters/C9.tex", "max_forks_repo_name": "danielmoraes/clrs", "max_forks_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-03-12T04:51:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T04:51:51.000Z", "avg_line_length": 36.2607655502, "max_line_length": 106, "alphanum_fraction": 0.6657979811, "num_tokens": 10426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.9425067268518421, "lm_q1q2_score": 0.8137524003077302}}
{"text": "\n\\subsection{Order statistics}\n\n\\subsubsection{Defining order statistics}\n\nThe \\(k\\)th order statistic is the \\(k\\)th smallest value in a sample.\n\n\\(x_{(1)}\\) is the smallest value in a sample, the minimum.\n\n\\(x_{(n)}\\) is the largest value in a sample, the maximum.\n\n\\subsubsection{Probability distributions of order statistics}\n\nThe probability distribution of order statistics depends on the underlying probability distribution.\n\n\\subsubsection{Probability distribution of sample maximum}\n\nIf we have:\n\n\\(Y=\\max \\mathbf X\\)\n\nThe probability distribution is:\n\n\\(P(Y\\le y)=P(X_1\\le y, X_2\\le y,...,X_n\\le y)\\)\n\nIf these are iid we have:\n\n\\(P(Y\\le y)=\\prod_i P(X_i\\le y)\\)\n\n\\(F_y(y)=F_X(y)^n\\)\n\nThe density function is:\n\n\\(f_y(y)=nF_X(y)^{n-1}f_x(y)\\)\n\n\\subsubsection{Probability distribution of the sample minimum}\n\nIf we have:\n\n\\(Y=\\min \\mathbf X\\)\n\nThe probability distribution is:\n\n\\(P(Y\\le y)=P(X_1\\ge y, X_2\\ge y,...,X_n\\ge y)\\)\n\nIf these are iid we have:\n\n\\(P(Y\\le y)=\\prod_i P(X_i\\ge y)\\)\n\n\\(F_y(y)=[1-F_X(y)]^n\\)\n\nThe density function is:\n\n\\(f_y(y)=-n[1-F_X(y)]^{n-1}f_x(y)\\)\n\n", "meta": {"hexsha": "d866c795fc2971dbc8283e36eb3df4a8243abcd8", "size": 1086, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/orderStatistics/01-01-order.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/orderStatistics/01-01-order.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/orderStatistics/01-01-order.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.3928571429, "max_line_length": 100, "alphanum_fraction": 0.6841620626, "num_tokens": 343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067260443809, "lm_q2_score": 0.8633916029436189, "lm_q1q2_score": 0.8137523929846003}}
{"text": "\\graphicspath{{img/algor/}}\r\n\\chapter{C\u00f3digos}\r\n\r\n\r\n\\section{B\u00fasqueda de ra\u00edces}\r\n\r\n\\subsection{Detecci\u00f3n de las ra\u00edces de una funci\u00f3n en un intervalo dado}\r\n\\begin{minted}[mathescape,\r\n           gobble=4,\r\n           frame=lines,\r\n           framesep=2mm]{python}\r\n    from numpy import zeros\r\n    \r\n    def bracketing(fun, a, b, N):\r\n        msg = \"Maximum number of iterations reached.\"\r\n        dx = (b - a)/(N - 1)\r\n        iroot = 0\r\n        x2 = a\r\n        xR = zeros(N, float)\r\n        for i in range(0, N):\r\n            x1 = x2\r\n            x2 = x1 + dx\r\n            if (fun(x1) * fun(x2)) < 0:\r\n                msg = \"A change of sign was found.\"\r\n                iroot = iroot + 1\r\n                xR[i] = x1\r\n        return xR, msg\r\n\r\n    # Function call\r\n    a = -10.0\r\n    b = 10.0\r\n    N = 21\r\n    fun = lambda x: x**3 + 4*x**2 - 10\r\n    xR, msg = bracketing(fun, a, b, N)\r\n    print(msg)\r\n    print(xR)\r\n\\end{minted}\r\n\r\n\r\n\\subsection{M\u00e9todo de bisecci\u00f3n para la localizaci\u00f3n de ra\u00edces en un intervalo \r\ndado}\r\n\r\n\\begin{minted}[mathescape,\r\ngobble=4,\r\nframe=lines,\r\nframesep=2mm]{python}\r\ndef bisection(fun, a, b, xtol=1e-6, ftol=1e-12, verbose=False):\r\n    \"\"\"\r\n    Use bisection method to estimate the root of a real function\r\n    \"\"\"\r\n    if fun(a) * fun(b) > 0:\r\n        c = None\r\n        msg = \"The function should change sign in the interval.\"\r\n    else:\r\n        nmax = int(ceil(log2((b - a)/xtol)))\r\n        for cont in range(nmax):\r\n            c = 0.5*(a + b)\r\n            if verbose:\r\n                print(\"n: {}, x: {}\".format(cont, c))\r\n            if abs(fun(c)) < ftol:\r\n                msg = \"Root found with desired accuracy.\"\r\n                break\r\n            elif fun(a) * fun(c) < 0:\r\n                b = c\r\n            elif fun(b) * fun(c) < 0:\r\n                a = c\r\n            msg = \"Maximum number of iterations reached.\"\r\n    return c, msg\r\n\r\nx, msg = bisection(lambda x: x**3 + 4*x**2 -10, -2, 2, xtol=1e-4,\r\n                    verbose=True)\r\nprint(msg)\r\nprint(x)\r\n\\end{minted}\r\n\r\n\r\n\r\n\\subsection{M\u00e9todo de Newton-Raphson para la localizaci\u00f3n de ra\u00edces en un \r\nintervalo dado}\r\n\r\n\\begin{minted}[mathescape,\r\n           gobble=4,\r\n           frame=lines,\r\n           framesep=2mm]{python}\r\ndef newton(fun, grad, x, niter=50, ftol=1e-8, verbose=False):\r\n    \"\"\"\r\n    Use Newton method to estimate the root of a real function\r\n    \"\"\"\r\n    msg = \"Maximum number of iterations reached.\"\r\n    for cont in range(niter):\r\n        if abs(grad(x)) < ftol:\r\n            x = None\r\n            msg = \"Derivative near to zero.\"\r\n            break\r\n        if verbose:\r\n            print(\"n: {}, x: {}\".format(cont, x))\r\n        x = x - fun(x)/grad(x)\r\n        if abs(fun(x)) < ftol:\r\n            msg = \"Root found with desired accuracy.\"\r\n            break\r\n    return x, msg\r\n\r\nfunc = lambda x:x**3 + 4*x**2 - 10\r\nderiv = lambda x: 3*x**2 + 8*x\r\nresult = newton(func, deriv, 2, verbose=True)\r\nprint(result)\r\n\\end{minted}\r\n\r\n\r\n\r\n\\section{Integraci\u00f3n num\u00e9rica}\r\n\r\n\\subsection{Regla del trapecio}\r\n\r\n\\begin{minted}[mathescape,\r\n    gobble=4,\r\n    frame=lines,\r\n    framesep=2mm]{python}\r\n    import numpy as np\r\n    from sympy import symbols, integrate\r\n\r\n\r\n    def trapz(fun, x0, x1, n):\r\n        \"\"\"Trapezoidal rule for integration\r\n        \r\n        Parameters\r\n        ----------\r\n        fun : callable\r\n             Function to integrate.\r\n        x0 : float\r\n             Initial point for the integration interval.\r\n        x1 : float\r\n             End point for the integration interval.\r\n        n : int\r\n             Number of points to take in the interval.\r\n        \r\n        Returns\r\n        -------\r\n        inte : float\r\n             Approximation of the integral\r\n        \r\n        \"\"\"\r\n        x = np.linspace(x0, x1, n)\r\n        y = fun(x)\r\n        dx = x[1] - x[0]\r\n        inte = 0.5*dx*(y[0] + y[-1])\r\n        for cont in range(1, n - 1):\r\n        inte = inte + dx*y[cont]\r\n        return inte\r\n\r\n\r\n    fun = lambda x: x**3 + 4*x**2 - 10\r\n    for cont in range(2, 11):\r\n        numeric_int = trapz(fun, -1, 1, cont)\r\n        print(\"Approximation for {} subdivisions: {:.6f}\".format(cont - 1,\r\n               numeric_int))\r\n\r\n    x  = symbols('x')\r\n    analytic_int = integrate(fun(x) , (x , -1 , 1))\r\n    print(\"Analytic integral: {:.6f}\".format(float(analytic_int)))\r\n\\end{minted}\r\n\r\n\\subsection{Cuadratura Gaussiana}\r\n\r\n\\begin{minted}[mathescape,\r\n\tgobble=4,\r\n\tframe=lines,\r\n\tframesep=2mm]{python}\r\n    import numpy as np\r\n    from scipy.special import roots_legendre\r\n    from sympy import symbols, integrate\r\n    \r\n    \r\n    def gauss1d(fun, x0, x1, n):\r\n        \"\"\"Gauss quadrature in 1D\r\n        \r\n        Parameters\r\n        ----------\r\n        fun : callable\r\n            Function to integrate.\r\n        x0 : float\r\n            Initial point for the integration interval.\r\n        x1 : float\r\n            End point for the integration interval.\r\n        n : int\r\n            Number of points to take in the interval.\r\n        \r\n        Returns\r\n        -------\r\n        inte : float\r\n             Approximation of the integral\r\n        \r\n        \"\"\"\r\n        xi, wi = roots_legendre(n)\r\n        inte = 0\r\n        h = 0.5 * (x1 - x0)\r\n        xm = 0.5 * (x0 + x1)\r\n        for cont in range(n):\r\n            inte = inte + h * fun(h * xi[cont] + xm) * wi[cont]\r\n        return inte\r\n\r\n    fun = lambda x: x**3 + 4*x**2 - 10\r\n    gauss_inte = gauss1d(fun, -1, 1, 4)\r\n    x  = symbols('x')\r\n    analytic_inte = integrate(fun(x) , (x , -1 , 1))\r\n    print(\"Analytic integral: {:.6f}\".format(float(analytic_inte)))\r\n    print(\"Gauss quadrature: {:.6f}\".format(gauss_inte))\r\n\\end{minted}\r\n\r\n\r\n\\subsection{Integraci\u00f3n en 2 dimensiones}\r\n\r\n\\begin{minted}[mathescape,\r\n    gobble=4,\r\n    frame=lines,\r\n    framesep=2mm]{python}\r\n    import numpy as np\r\n    from scipy.special import roots_legendre\r\n\r\n\r\n    def gauss2d(fun, x0, x1, y0, y1, nx, ny):\r\n        \"\"\"Gauss quadrature for a rectangle in 2D\r\n        \r\n        Parameters\r\n        ----------\r\n        fun : callable\r\n        Function to integrate.\r\n        x0 : float\r\n        Initial point for the integration interval in x.\r\n        x1 : float\r\n        End point for the integration interval in x.\r\n        y0 : float\r\n        Initial point for the integration interval in y.\r\n        y1 : float\r\n        End point for the integration interval in y.\r\n        nx : int\r\n        Number of points to take in the interval in x.\r\n        ny : int\r\n        Number of points to take in the interval in y.\r\n        \r\n        Returns\r\n        -------\r\n        inte : float\r\n        Approximation of the integral\r\n        \r\n        \"\"\"\r\n        xi, wi = roots_legendre(nx)\r\n        yj, wj = roots_legendre(ny)\r\n        inte = 0\r\n        hx = 0.5 * (x1 - x0)\r\n        hy = 0.5 * (y1 - y0)\r\n        xm = 0.5 * (x0 + x1)\r\n        ym = 0.5 * (y0 + y1)\r\n        for cont_x in range(nx):\r\n        for cont_y in range(ny):\r\n        f = fun(hx * xi[cont_x] + xm, hy * yj[cont_y] + ym)\r\n        inte = inte + hx* hy * f * wi[cont_x] * wj[cont_y]\r\n        return inte\r\n\r\n\r\n    fun = lambda x, y: 3*x*y**2 - x**3\r\n    gauss_inte = gauss2d(fun, 0, 2, 0, 2, 2, 2)\r\n    print(\"Gauss quadrature: {:.6f}\".format(gauss_inte))\r\n\\end{minted}\r\n\r\n", "meta": {"hexsha": "e3178392df9495aa3343dd82608dc8f8e4fde379", "size": 7229, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notas_de_clase/src/codigos.tex", "max_stars_repo_name": "AppliedMechanics-EAFIT/Mod_Temporal", "max_stars_repo_head_hexsha": "6a0506d906ed42b143b773777e8dc0da5af763eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-02-20T18:14:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-19T22:44:44.000Z", "max_issues_repo_path": "notas_de_clase/src/codigos.tex", "max_issues_repo_name": "AppliedMechanics-EAFIT/Mod_Temporal", "max_issues_repo_head_hexsha": "6a0506d906ed42b143b773777e8dc0da5af763eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-04-15T00:22:58.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-04T17:03:54.000Z", "max_forks_repo_path": "notas_de_clase/src/codigos.tex", "max_forks_repo_name": "AppliedMechanics-EAFIT/Mod_Temporal", "max_forks_repo_head_hexsha": "6a0506d906ed42b143b773777e8dc0da5af763eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-05-14T18:17:09.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-27T06:37:05.000Z", "avg_line_length": 27.1766917293, "max_line_length": 80, "alphanum_fraction": 0.507400747, "num_tokens": 2043, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.8774767954920547, "lm_q1q2_score": 0.8137397746825681}}
{"text": "\n\\subsection{Quantum harmonic oscillator}\nFor total energy $E$, kinetic energy $K$ and potential energy $V$ we have\n$$E=K+V$$\nThe corresponding formula for a quantum harmonic oscillator is\n$$(2n+1)\\psi=-{d^2\\psi\\over dx^2}+x^2\\psi$$\nwhere $n$ is an integer and represents the quantization of energy values.\nThe solution to the above equation is\n$$\\psi_n(x)=\\exp(-x^2/2)H_n(x)$$\nwhere $H_n(x)$ is the $n$th Hermite polynomial in $x$.\nThe following Eigenmath code checks $E=K+V$ for $n=7$.\n\n\\begin{Verbatim}[formatcom=\\color{blue},samepage=true]\nn = 7\npsi = exp(-x^2/2)*hermite(x,n)\nE = (2*n+1)*psi\nK = -d(psi,x,x)\nV = x^2*psi\nE-K-V\n\\end{Verbatim}\n\n$\\displaystyle 0$\n", "meta": {"hexsha": "27551dbefbdb081c1b5e701b7293887f1ecc754f", "size": 665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/qho.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/qho.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/qho.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.9130434783, "max_line_length": 73, "alphanum_fraction": 0.6932330827, "num_tokens": 241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9688561703644737, "lm_q2_score": 0.8397339616560073, "lm_q1q2_score": 0.813581430215027}}
{"text": "%% SECTION HEADER /////////////////////////////////////////////////////////////////////////////////////\n\\section{The Spectral Element Method}\n\\label{sec:sem}\n\n%% SECTION CONTENT ////////////////////////////////////////////////////////////////////////////////////\n\nThe general concept of the \\ac{sem} is based on the idea of the \\ac{fem}.\nThe similarity of both methods lies in the fact that the modeled domain is divided into non-overlapping finite elements, and external forces and arbitrary boundary conditions are imposed in the particular nodes.\nThe main difference between those methods is a choice of the shape function \\( N=N(\\xi )\\), which is interpolated by a Lagrange polynomial that passes through the element nodes. The nodes are localized on the endpoint of an interval, \\(\\xi\\in[-1,1]\\), and the roots of the first derivative of Legendre polynomial P of degree \\(p-1\\):\n\\begin{eqnarray}\n\t(1-\\xi^2)P'_{p-1}(\\xi)=0.\n\t\\label{eq:nodes}\n\\end{eqnarray}\n\nThe approximation of an integral over the elements is achieved according to \\ac{gll} rule at points coinciding with the element nodes, \nand the weights \\(w=w(\\xi)\\) calculated as:\n\\begin{eqnarray}\n\t{w(\\xi)} = \\frac{2}{p(p-1)(P_{p-1}(\\xi))^2}.\n\t\\label{eq:weights}\n\\end{eqnarray}\n\nThis approach guarantees a diagonal mass matrix.\nThe shape functions and the weights for \\ac{2d} or \\ac{3d} elements are obtained by the Kronecker product of vectors of individual axes, denoted by \\(\\otimes\\) as follows:\n\\begin{eqnarray}\n\tN(\\xi,\\eta) = N(\\xi)\\otimes N(\\eta), & N(\\xi,\\eta,\\zeta) = N(\\xi)\\otimes N(\\eta)\\otimes N(\\zeta), \\nonumber\\\\\n\tw(\\xi,\\eta) = w(\\xi)\\otimes w(\\eta), & w(\\xi,\\eta,\\zeta) = w(\\xi)\\otimes w(\\eta)\\otimes w(\\zeta).\n\t\\label{eq:3Dshape_weights}\n\\end{eqnarray}\n\nThe elementary equations of motion is defined as:\r\n\\begin{eqnarray}\r\n\t\\label{eq:motion}\r\n\t\\textbf{M} \\ddot{\\textbf{d}} + \\textbf{D} \\dot{\\textbf{d}} + \\textbf{K} \\textbf{d} = \\textbf{F}_{ext}\r\n\\end{eqnarray}\r\nwhere \\textbf{d} is the displacement vector; \\textbf{M}, \\textbf{D}, \\textbf{K} are structural mass, damping and stiffness matrices, respectively; \\textbf{F}$_{ext}$ is the external forces vector; \\((\\dot{\\ })=\\frac{\\partial}{\\partial t}\\). Construction of the \\textbf{M}, \\textbf{D}, \\textbf{K} matrices is similar to the classical approach in \\ac{fem}.\r\n\nThe convergence of the equation~(\\ref{eq:motion}) in the \\ac{sem} is already achieved for six nodes per wavelength, while at least fifteen nodes are needed in case of linear elements in classic \\ac{fem}~\\cite{wee2017simulating}. Moreover, the mass matrix is diagonal when the \\ac{gll} approach is used.\n\n", "meta": {"hexsha": "46ae2a1449f45091cce9cad2b93976e9d8430ba3", "size": 2603, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/proposal/Dissertation/Chapters/Chapter4/sec:sem.tex", "max_stars_repo_name": "pfiborek/model_hc", "max_stars_repo_head_hexsha": "e27cf98e5d8a5a8ad2ba0c5e70520c281dfd384c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/proposal/Dissertation/Chapters/Chapter4/sec:sem.tex", "max_issues_repo_name": "pfiborek/model_hc", "max_issues_repo_head_hexsha": "e27cf98e5d8a5a8ad2ba0c5e70520c281dfd384c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/proposal/Dissertation/Chapters/Chapter4/sec:sem.tex", "max_forks_repo_name": "pfiborek/model_hc", "max_forks_repo_head_hexsha": "e27cf98e5d8a5a8ad2ba0c5e70520c281dfd384c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.7435897436, "max_line_length": 355, "alphanum_fraction": 0.6738378794, "num_tokens": 745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176852582231, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.8134444383165907}}
{"text": "\\lab{K-Means Clustering}{K-Means Clustering}\n\\objective{Understand the basics of \\emph{k-means} clustering, and apply to the problem of clustering earthquake epicenters.}\n\n\\subsection*{Clustering}\nIn Lab \\ref{lab:pca}, we analyzed the iris dataset using PCA; we have reproduced the first two principal components of the iris data in Figure \\ref{fig:iris_data}.\nUpon inspection of the first two principal components, a human can easily see that there are two very distinct groups of irises.\nCan we create an algorithm to identify these groups without human supervision?\nThis task is called \\emph{clustering}, an instance of \\emph{unsupervised learning}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{iris_pca.pdf}\n\\caption{The first two principal components of the iris dataset.}\n\\label{fig:iris_data}\n\\end{figure}\n\nThe objective of clustering is to find a partition of the data such that points in the same subset will be ``close'' according to some metric.\nThe metric used will likely depend on the data, but some obvious choices include Euclidean distance and angular distance.\nThroughout this lab we will use the metric $d(x,y) = \\|x-y\\|_2$, the Euclidean distance between $x$ and $y$.\n\nMore formally, suppose we have a collection of $\\mathbb{R}^K$-valued observations $X = \\{x_1,x_2,\\ldots,x_n\\}$.\nLet $N \\in \\mathbb{N}$ and let $\\mathcal{S}$ be the set of all $N$-partitions of $X$, where an $N$-partition is a partition with exactly $N$ nonempty elements.\nWe can represent a typical partition in $\\mathcal{S}$ as $S = \\{S_1,S_2,\\ldots,S_N\\}$, where\n\\[\nX = \\bigcup_{i=1}^N S_i\n\\]\nand\n\\[\n|S_i| > 0, \\qquad i=1,2,\\ldots,N.\n\\]\nWe seek the $N$-partition $S^*$ that minimizes the within-cluster sum of squares, i.e.\n\\[\nS^* = \\underset{S\\in\\mathcal{S}}{\\arg\\min} \\sum_{i=1}^N\\sum_{x_j\\in S_i}\\|x_j-\\mu_i\\|_2^2,\n\\]\nwhere $\\mu_i$ is the mean of the elements in $S_i$, i.e.\n\\[\n\\mu_i = \\frac{1}{|S_i|}\\sum_{x_j\\in S_i}x_j.\n\\]\n\n\\subsection*{The \\emph{K-Means} Method}\nFinding the global minimizing partition $S^*$ is generally intractable since the set of partitions can be very large indeed,\nbut the \\emph{k-means} algorithm is a heuristic approach that can often provide good results.\n\n\nWe begin by specifying an initial cluster mean $\\mu_i^{(1)}$ for each $i = 1, \\cdots, N$ (this can be done by random initialization, or according to some heuristic).\nFor each iteration, we adopt the following procedure.\nGiven a current set of cluster means $\\mu^{(t)}$, we find a partition $S^{(t)}$ of the observations such that\n\\begin{equation*}\nS_{i}^{(t)} = \\{x_j \\; : \\; \\|x_j - \\mu_{i}^{(t)}\\|_2^2 \\leq \\|x_j - \\mu_{l}^{(t)}\\|_2^2,\\,\\,\\,  l = 1, \\cdots, N\\}.\n\\end{equation*}\nWe then update our cluster means by computing for each $i = 1, \\cdots, N$.\nWe continue to iterate in this manner until the partition ceases to change.\n\n\n\nExamine Figure \\ref{fig:iris_clusterings}, which shows two different clusterings of the iris data produced by the \\emph{k-means} algorithm.\nNote that the quality of the clustering can depend heavily on the initial cluster means.\nWe can use the within-cluster sum of squares as a measure of the quality of a clustering (a lower sum of squares is better).\nWhere possible, it is advisable to run the clustering algorithm several times, each with a different initialization of the means,\nand keep the best clustering.\nNote also that it is possible to have very slow convergence.\nThus, when implementing the algorithm, it is a good idea to terminate after some specified maximum number of iterations.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{tabular}{cc}\n\t\\includegraphics[width=.49\\textwidth]{iris_means_1.pdf} &\n\t\\includegraphics[width=.49\\textwidth]{iris_means_2.pdf}\n\t\\end{tabular}\n\t\\caption{Two different K-Means clusterings for the iris dataset.\n            Notice that the clustering on the left predicts the flower species to a high degree of accuracy,\n            while the clustering on the right is less effective.}\n    \\label{fig:iris_clusterings}\n\\end{figure}\n\n\\begin{problem}\nImplement the \\emph{k-means} algorithm using the following function declaration.\n\n\\begin{lstlisting}\ndef kmeans(data,n_clusters,init='random',max_iter=300):\n    \"\"\"\n    Cluster a dataset using the k-means algorithm.\n\n    Parameters\n    ----------\n    data : ndarray of shape (n,k)\n        Each row is an observation.\n    n_clusters : int\n        The number of clusters.\n    init : string or ndarray of shape (n_clusters,k)\n        If init is the string 'random', then randomly initialize the cluster means.\n        Else, the initial cluster means are given by the rows of init.\n    max_iter : int\n        The maximum allowable number of iterations.\n\n    Returns\n    -------\n    means : ndarray of shape (n_cluster,k)\n        The final cluster means, given as the rows.\n    labels : ndarray of shape (n,)\n        The i-th entry is an integer in [0,n_clusters-1] indicating\n        which cluster the i-th row of data belongs to relative to\n        the rows of means.\n    measure : float\n        The within-cluster sum of squares quality measure.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\nTest your function on the first two principal components of the iris dataset.\nRun it 10 times, using a different random initialization of the means each time.\nRetain the clustering with the smallest within-cluster sum of squares.\nYour clustering should be similar to the first clustering in Figure \\ref{fig:iris_clusterings}.\n\\end{problem}\n\n\\subsection*{Detecting Active Earthquake Regions}\nSuppose we are interested in learning about which regions are prone to experience frequent earthquake activity.\nWe could make a map of all earthquakes over a given period of time and examine it ourselves, but we recognize this as an unsupervised learning problem and are eager to apply our new k-means clustering tool.\n\nOur data is contained in 6 text files, each with a months worth of earthquake data throughout the world, from January 2010 through June 2010.\nThese files contain a lot of information which we aren't interested in at the time; all we would like to extract from them is the location of each earthquake, which appears in characters $21$ through $33$ of each line.\nCharacters $21$ through $26$ contain the latitude of each epicenter, character $26$ denoting North or South, and characters $27$ through $33$ contain the longitude of each epicenter, character $33$ denoting East or West.\nWe need to divide each value by $1,000$ to represent these as degrees and decimals.\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{earthquakes.png}\n\t\\caption{Earthquake epicenters over a 6 month period.}\n\t\\label{fig:earthquakes}\n\\end{figure}\n\\begin{problem}\nLoad the earthquake data into a $n\\times 2$ array, where each row gives the longitude and latitude of an earthquake in degrees.\nMultiply South latitudes and West longitudes by $-1$.\nCreate a scatter plot of the resulting data. You should be able to see the outlines of some of the continents and tectonic plates (since these are often areas of greater seismic activity). See also Figure \\ref{fig:earthquakes}.\n\\end{problem}\n\nWe want to cluster this data into active earthquake regions.\nFor this task, we might think that we can regard any epicenter as a point in $\\mathbb{R}^{2}$ with coordinates being their latitude and longitude.\nThis, however, would be incorrect, because the earth is not flat. We must recognize that latitude and longitude are best viewed as a variation of spherical coordinates in $\\mathbb{R}^{3}$, and we should interpret them as such.\nSince our \\emph{k-means} algorithm is based on Euclidean distance, we need to transform our data into 3-dimensional Euclidean coordinates.\n\nA simple way to accomplish this transformation is to first transform the latitude and longitude values to spherical coordinates, and then to Euclidean coordinates.\nRecall that a spherical coordinate in $\\mathbb{R}^3$ is a triple $(r,\\theta,\\varphi)$, where $r$ is the distance from the origin, $\\theta$ is the radial angle in the $xy$ plane from the $x$-axis,\nand $\\varphi$ is the angle from the $z$-axis. In our earthquake data, the longitude is already the appropriate $\\theta$ value, and the $\\varphi$ value (in degrees) is simply $90^\\circ$ minus the latitude.\nFor simplicity, we can take $r=1$, since the earth is roughly a sphere.\nWe can then transform to Euclidean coordinates using the following relationships:\n\\begin{align*}\nr & = \\sqrt{x^{2} + y^{2} + z^{2}} & x & = r \\sin \\varphi \\cos \\theta \\\\\n\\varphi & = \\arccos \\frac{z}{r} & y & = r \\sin \\varphi \\sin \\theta \\\\\n\\theta & = \\arctan \\frac{y}{x} & z & = r \\cos \\varphi\n\\end{align*}\n\n\\begin{problem}\nTransform your earthquake data into Euclidean coordinates.\nBe sure to consider if and when you need to transform your data from degrees to radians!\n\\end{problem}\n\nWe are now ready to cluster the earthquake data using the Euclidean coordinates.\nWe need to address one further issue, however.\nNotice that each earthquake data point has norm 1 in Euclidean coordinates, since it lies on the surface of a sphere of radius 1.\nWe also need to ensure that our cluster means have norm 1.\nOtherwise, the means can't be interpreted as locations on the surface of the earth.\nFurthermore, the \\emph{k-means} algorithm will struggle to find good clusters.\nA solution to this problem is to normalize the mean vectors at each iteration, so that they are always unit vectors.\nThus, we need to add optional functionality to our \\li{kmeans} function.\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{earthquake_clusters.png}\n\t\\caption{Earthquake epicenter clusters with $N = 15$.}\n\t\\label{fig:earthquakeclusters}\n\\end{figure}\n\n\\begin{problem}\nAdd a keyword argument \\li{normalize=False} to you \\li{kmeans} function, and add code to normalize the means at each iteration, should this argument be set to \\li{True}.\nUse your function to cluster the earthquake data into 15 clusters. Run this 10 times, keeping the best clustering.\nTransform the cluster means back to latitude and longitude coordinates (when calculating $\\theta$ using the inverse tangent, use \\li{numpy.arctan2} or \\li{math.arctan2},\nso that that correct quadrant is chosen).\nCreate a scatter plot showing each cluster mean, along with the earthquake epicenters color-coated according to their cluster. You plot should resemble that in Figure \\ref{fig:earthquakeclusters}.\n\\end{problem}\n\n\n", "meta": {"hexsha": "8774e7f7d9e3664fc815e2b09803f2eeeecf1c4f", "size": 10373, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/KMeans/kmeans.tex", "max_stars_repo_name": "marissa-graham/numerical_computing", "max_stars_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Labs/KMeans/kmeans.tex", "max_issues_repo_name": "marissa-graham/numerical_computing", "max_issues_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/KMeans/kmeans.tex", "max_forks_repo_name": "marissa-graham/numerical_computing", "max_forks_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 57.3093922652, "max_line_length": 227, "alphanum_fraction": 0.7497348887, "num_tokens": 2648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.9324533055754922, "lm_q1q2_score": 0.813423202412425}}
{"text": "\\section{Matrices and Linear Maps}\r\n\\subsection{Definitions}\r\n\\begin{definition}\r\n    A linear map is a function that preserves linear combination.\r\n    That is, for vector spaces $V,W$ over the same field $k$, a linear map $T:V\\to W$ satisfies\r\n    $$\\forall\\lambda,\\mu\\in k, \\underline{v},\\underline{v'}\\in V, T(\\lambda\\underline{v}+\\mu\\underline{v'})=\\lambda T(\\underline{v})+\\mu T(\\underline{v'})$$\r\n\\end{definition}\r\n\\begin{definition}\r\n    The image of the entire vector space $V$ under $T$, $\\operatorname{Im}T$, is the collection of all images, that is, $\\{\\underline{w}\\in W: \\exists \\underline{v}\\in V,T(\\underline{v})=\\underline{w}\\}$.\r\n    Also, the kernel $\\ker T$ is the set $\\{\\underline{v}\\in V: T(\\underline{v}=\\underline{0})\\}$\r\n\\end{definition}\r\n\\begin{proposition}\r\n    The kernel is a subspace of $V$ and the image a subspace of $W$.\r\n\\end{proposition}\r\n\\begin{definition}\r\n    The dimension of the image is called the rank of $T$, $\\operatorname{rank}T$, and the dimension of the kernel is the nullity of $T$, $\\operatorname{null}T$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. The zero linear map $T$ mapping each vector to the zero vector is a linear.\r\n    Its rank is $0$ and the nullity of $T$ is the dimension of $V$.\\\\\r\n    2. The identity map on $V$ is linear with kernel $\\{0\\}$ and the image $V$.\\\\\r\n    3. Suppose $V=W=\\mathbb R^3$ and the map $T$ given by\r\n    $$\r\n    T\\underline{x}=\r\n    \\begin{pmatrix}\r\n        3&1&5\\\\\r\n        -1&0&-2\\\\\r\n        2&1&3\r\n    \\end{pmatrix}\r\n    \\underline{x}\r\n    $$\r\n    is linear.\r\n    Note that this matrix is singular, so its kernel is nontrivial since it contains at least one vector, say $(2,-1,-1)$.\r\n    One can show that the nullity is $1$ (that is, it is entirely generated by this vector) and the rank is $2$.\r\n\\end{example}\r\n\\begin{definition}\r\n    If $T,S:V\\to W$ are both linear maps, then $\\alpha T+\\beta S$ for any $\\alpha,\\beta\\in F$ is obviously also a linear map.\r\n    We say it is the linear combination of the linear maps.\r\n\\end{definition}\r\n\\begin{definition}\r\n    If $T:V\\to W, S:U\\to V$ are both linear, then easily $T\\circ S:U\\to W$ is linear and is called the composition of linear maps.\r\n\\end{definition}\r\nThe third example shown above triggers the following theorem:\r\n\\begin{theorem}[Rank-Nullity Theorem]\r\n    Suppose $T:V\\to W$ is linear, then $\\operatorname{rank}T+\\operatorname{null}T=\\dim V$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $\\underline{e_1},\\ldots,\\underline{e_k}$ be a basis for $\\ker T$.\r\n    We can extend it to a basis $\\underline{e_1},\\ldots,\\underline{e_n}$ of $V$.\r\n    Now $T(\\underline{e_{k+1}}),\\ldots,T(\\underline{e_n})$ is a basis for $\\operatorname{Im}T$, following which the theorem is proved.\r\n    Indeed,\r\n    $$T\\left(\\sum_{i=1}^na_i\\underline{e_i}\\right)=\\sum_{i=1}^na_iT(\\underline{e_i})=\\sum_{i=k+1}^na_iT(\\underline{e_i})$$\r\n    so this set indeed spans $\\operatorname{Im}T$.\r\n    It is also linearly independent since\r\n    $$\\sum_{i=k+1}^na_iT(\\underline{e_i})=0\\implies T\\left(\\sum_{i=k+1}^na_i\\underline{e_i}\\right)=0\\implies \\sum_{i=k+1}^na_i\\underline{e_i}=\\sum_{i=1}^ka_i\\underline{e_i}$$\r\n    But that would imply that we have found a nontrivial relation between our $\\underline{e_i}$ which are independent, which is false.\r\n    So it is independent, hence the proof is done.\r\n\\end{proof}\r\n\\subsection{Matrices as Linear Maps in Real Vector Spaces}\r\nLet $M$ be an $n\\times n$ array with entries $M_{ij}$ where $i$ labels the rows and $j$ labels the columns.\r\nFor example, if $n=3$,\r\n$$\r\nM=\r\n\\begin{pmatrix}\r\n    M_{11}&M_{12}&M_{13}\\\\\r\n    M_{21}&M_{22}&M_{23}\\\\\r\n    M_{31}&M_{32}&M_{33}\r\n\\end{pmatrix}\r\n$$\r\nWe define the map $T:\\mathbb R^n\\to\\mathbb R^n$ by $T(\\underline{x})_i=M_{ij}x_j$.\r\nIt is obviously a linear map.\r\nNote that if $\\underline{x}=x_i\\underline{e_i}$, then $T(\\underline{x})=x_iT(\\underline{e_i})=x_i\\underline{c_i}$ where $\\underline{c_i}$ is the column $i$ of the matrix.\r\nTherefore the image of $T$ is the span of the columns of $M$.\\\\\r\nGiven that, it is useful to consider the rows $\\underline{r_i}$ and $\\underline{c_i}$ that are the rows and columns of $M$.\r\nWe can write $(\\underline{R_i})_j=M_{ij}=(\\underline{C_j})_i$.\r\nSo $(M\\underline{x})_i=\\underline{R_i}\\cdot\\underline{x}$, the kernel of $M$ is the set of all $\\underline{x}$ that vanishes under the linear map.\r\n\\begin{example}\r\n    1. $V=W=\\mathbb R^n$, the zero map corresponds to the zero matrix.\\\\\r\n    2. The identity mao corresponds to the identity matrix $I_{ij}=\\delta_{ij}$.\\\\\r\n    3. $T:\\mathbb R^3\\to\\mathbb R^3$ corresponding to the matrix\r\n    $$M=\\begin{pmatrix}\r\n        3&1&5\\\\\r\n        -1&0&-2\\\\\r\n        2&1&3\r\n    \\end{pmatrix}$$\r\n    The image of it is the span of columns, that is, the $2$-dimensional subspace spanned by $\\underline{C_1},\\underline{C_2}$ (since $\\underline{C_3}$ is in this space).\r\n    The kernel then is the $1$-dimensional subspace spanned by the vector $(2,-1,-1)$.\r\n\\end{example}\r\n\\subsection{Geometrical Examples}\r\nWe first think about rotations $\\mathbb R^2\\to\\mathbb R^2$ by an angle $\\theta$ can be described as\r\n$$\r\n\\begin{pmatrix}\r\n    \\cos\\theta&-\\sin\\theta\\\\\r\n    \\sin\\theta&\\cos\\theta\r\n\\end{pmatrix}\r\n$$\r\nwhich one can eariy derive from either polar coordinate or the its behaviour on basis vectors.\\\\\r\nThings go more interesting when we get to dimension $3$.\r\nWe consider $\\underline{x}=\\underline{x}_\\parallel+\\underline{x}_\\perp$ as the decomposition of $\\underline{x}$ along the $\\underline{n}$ direction, i.e. such that $\\underline{x}_\\parallel\\parallel\\underline{n}$ and $\\underline{x}_\\perp\\perp\\underline{n}$.\r\nThen,\r\n$$|\\underline{x}_\\parallel|=|\\underline{x}|\\cos\\phi,|\\underline{x}_\\perp|=|\\underline{x}|\\sin\\phi$$\r\nSo under the rotation along the axis $\\underline{n}$, $\\underline{x}_\\parallel$ stays the same while the $\\underline{x}_\\perp$ changes.\r\nAssuming the angle is $\\theta$, we can reassemble things to obtain\r\n$$\\underline{x}\\mapsto \\underline{x}_\\parallel+\\cos\\theta\\underline{x}_\\perp+\\sin\\theta\\underline{n}\\times\\underline{x}$$\r\nSo in components\r\n\\begin{align*}\r\n    (M\\underline{x})_i=M_{ij}x_j&=x_i\\cos\\theta+(1-\\cos\\theta)n_jx_jn_i+\\sin\\theta\\epsilon_{ijk}n_jx_k\\\\\r\n    &=(\\delta_{ij}\\cos\\theta+(1-\\cos\\theta)n_in_j+\\sin\\theta\\epsilon_{ijk}n_k)x_j\r\n\\end{align*}\r\nWe can also have reflection across the plane with normal $\\underline{n}$ which, in matrix form, would be $M_{ij}=\\delta_{ij}-2n_in_j$.\\\\\r\nDilation and scaling are linear maps as well.\r\nIf we set the scaling factors to be $\\alpha,\\beta,\\gamma$ along $\\underline{e_i},\\underline{e_2},\\underline{e_3}$, then the corresponding matrix would be\r\n$$\r\n\\begin{pmatrix}\r\n    \\alpha&0&0\\\\\r\n    0&\\beta&0\\\\\r\n    0&0&\\gamma\r\n\\end{pmatrix}\r\n$$\r\nThere is another kind of linear transformation called shears.\r\nGiven unit vectors $\\underline{a},\\underline{b}$ perpendicular, then a shear with parameter $\\lambda$ is defined by $\\underline{x}\\mapsto \\underline{x}+\\lambda\\underline{a}(\\underline{b}\\cdot\\underline{x})$.\r\nSo $\\underline{a}\\mapsto\\underline{a}$ (in general $\\underline{u}\\perp\\underline{b}\\implies \\underline{u}\\mapsto\\underline{u}$), $\\underline{b}\\mapsto\\underline{b}+\\lambda\\underline{a}$.\r\nIn component, $T(\\underline{x})_i=(\\delta_{ij}+\\lambda a_ib_j)x_j$.\r\n\\subsection{Matrices in General; Matrix Algebra}\r\n\\begin{definition}\r\n    Consider a linear map $T:V\\to W$ where $V,W$ are real or complex vector spaces of dimensions $n,m$ respectively.\r\n    Assume that we have obtained a basis $\\{\\underline{e_i}\\}$ for $V$ and a basis $\\{\\underline{f_a}\\}$ for $W$.\r\n    So a matrix representation of $T$ with respect to these bases is an array $M_{ai}$ with entries in $\\mathbb R,\\mathbb C$ as appropriate, with $a\\in\\{1,2,\\ldots,m\\}$ (`rows'), $i\\in\\{1,2,\\ldots,n\\}$ (`columns') with\r\n    $$T(\\underline{e_i})=\\sum_{a}M_{ai}\\underline{f_a}$$\r\n    which extends to any vectors in $V$ by linearity.\r\n\\end{definition}\r\nSo we have $M\\underline{x}=T(\\underline{x})=M_{ai}x_i\\underline{f_a}$ where the summation convention is being used.\r\nThe moral of the story is that by choice with basis we can identify the vector spaces as $\\mathbb R^n,\\mathbb R^m$ or $\\mathbb C^n,\\mathbb C^m$ and $T$ as a matrix.\r\n\\begin{definition}\r\n    Suppose $T:V\\to W, S:V\\to W, R:W\\to Z$, then given choices of bases on $V,W,Z$, and hence the matrices $M$ of $T$, $N$ of $S$, $L$ of $R$, then $(M+N)_{ij}=M_{ij}+N_{ij}$ and $LM$ the matrix of $R\\circ T$, or (as one can check) equivalently $(LM)_{ij}=L_{ia}M_{aj}$.\r\n\\end{definition}\r\nOne can also observe that the products of two matrices consists of exactly the dot products of the rows of one and the columns of the other.\r\nThis follows immediately from definitions.\r\nNote that the matrix multiplication cannot be defined in two arbitrary matrices.\r\nTo multiply two matrices $A,B$ to get $AB$, we must have $\\operatorname{dom}A=\\operatorname{cod}B$.\r\n\\begin{proposition}\r\n    For matrices where matrix multiplication is defined, it is associative and distributive over matrix addition.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    For $m\\times n$ matrices $A$ and $n\\times m$ matrices $B,C$, $B$ is a left inverse of $A$ if $BA=I$ and $C$ a right inverse of $A$ if $AC=I$ where $I$ is the identity.\\\\\r\n    Note that not every matrices has inverse(s), but if it does, we say that it is invertible, or non-singular.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    If $n=m$, then if $A$ is invertible, then it has both an unique left inverse and an unique right inverse, and they are the same.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Obvious enough.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. The rotation matrix $R(\\theta)$ with respect to some (hyper-)axis has an inverse, since $R(\\theta)\\circ R(-\\theta)=I$.\\\\\r\n    2. Consider $n\\times n$ matrix $M$.\r\n    If $\\underline{x'}=M\\underline{x}$, then $M^{-1}\\underline{x'}=\\underline{x}$.\r\n    This shows the uniqueness criterion of a system of linear equations.\r\n\\end{example}\r\nOne can check that a $2\\times 2$ matrix $M$ is uniquely solvable if and only if its determinant $\\det M=[M\\underline{e_1},M\\underline{e_2}]$ is nonzero.\r\nOne realize that the determinant is the area of the parallelogram spanned by the images of the bases.\r\n\\subsubsection{Transpose and Hermitian Conjugate}\r\nIf $M$ is an $m\\times n$ matrix, then transpose, written $M^\\top$ is the $n\\times m$ defined by $(M^\\top)_{ij}=M_{ji}$.\r\nNote that for any two $n\\times m$ matrices $M,N$ and scalars $\\lambda,\\mu$, then $(\\lambda A+\\mu B)^\\top=\\lambda A^\\top+\\mu B^\\top$.\r\nIf $A$ is a $m\\times n$ and $B$ is $n\\times p$, then $(AB)^\\top=B^\\top A^\\top$.\r\nFor square matrix $A$, we say $A$ is symmetric if $A^\\top=A$, antisymmetric if $A^\\top=-A$.\\\\\r\nFor complex matrices, the Hermitian conjugate of an $m\\times n$ matrix $M$ is defined by $(M^\\dagger)_{ij}=\\overline{M_{ji}}$.\r\nWe can define Hermitian and anti-Hermitian matrices in the same way in square complex matrices.\r\n\\subsubsection{Trace}\r\nConsider a complex $n\\times n$ matrix $M$, the trace of $M$, $\\operatorname{tr}(M)$, is $M_{ii}$ (where the summation convention is being used).\r\nImmediately, $\\operatorname{tr}(\\alpha M+\\beta N)=\\alpha\\operatorname{tr}(M)+\\beta\\operatorname{tr}(N)$, and $\\operatorname{tr}(MN)=\\operatorname{tr}(NM)$ and $\\operatorname{tr}(M)=\\operatorname{tr}(M^\\top)$, and $\\operatorname{tr}(I)=n$.\r\n\\begin{example}\r\n    The reflection across the plane with normal $\\underline{n}$ can be represented by the matrix $H$ defined by $H_{ij}=\\delta_{ij}-2n_in_j$.\r\n    Now $\\operatorname{tr}(H)=H_{ii}=\\delta_{ii}-2n_in_i=3-2=1$.\r\n\\end{example}\r\nNote as well that antisymmetric matrices always have zero trace.\r\n\\subsubsection{Decomposition}\r\nAn $n\\times n$ matrix $M$ can be written as $M=S+A$ where $S=(M+M^\\top)/2,A=(M-M^\\top)/2$.\r\nNote that $S$ and $A$ are symmetric and antisymmetric respectively.\r\nConsider the matrix $T$ defined by $T_{ij}=\\delta_{ij}-\\operatorname{tr}(S)\\delta_{ij}/n$, so $T$ is traceless as well.\r\nBut $\\operatorname{tr}S=\\operatorname{tr}M$ since $A$ is antisymmetric hence traceless.\r\nThus $M_{ij}=T_{ij}+A_{ij}+\\operatorname{tr}(M)\\delta_{ij}/n$ decompose the matrix $M$ into symmetric traceless, antisymmetric and pure trace part.\r\n\\begin{example}\r\n    For $n=3$, suppose $T_{ij}=0$, set $A_{ij}=\\epsilon_{ijk}a_k$ and $\\operatorname{tr}M=3\\lambda$, so $M\\underline{x}=\\underline{x}\\times\\underline{a}+\\lambda\\underline{x}$.\r\n\\end{example}\r\n\\subsubsection{Orthogonal and Unitary Matrices}\r\nA sqaure matrix $U$ is orthogonal if $UU^\\top=U^\\top U=I$.\r\nSo the column vectors of $U$ actually are orthonormal, same for the rows.\r\nFor example, rotation matrices are orthogonal.\r\n\\begin{proposition}\r\n    $U$ is orthogonal if and only if it preserves inner products.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    For any square matrix $U$, we have\r\n    $$(U\\underline{x})\\cdot(U\\underline{y})=(U\\underline{x})^\\top U\\underline{y}=\\underline{x}^\\top U^\\top U\\underline{y}$$\r\n    So if $U$ is orthogonal, the last expression equals $\\underline{x}\\cdot\\underline{y}$, hence $U$ preserves dot product.\r\n    Conversely, for any square matrix $A$, $\\underline{e_j}^\\top A\\underline{e_i}=A_{ji}$, so if $U$ preserves inner product, then by taking $A=U^\\top U$ we have $U^\\top U=I$\r\n\\end{proof}\r\nNote that in $\\mathbb R^n$, if $\\{\\underline{e_i}\\}$ is an orthonormal basis, then $\\{U\\underline{e_i}\\}$ would also be an orthonormal basis.\r\n\\begin{example}\r\n    The general $2\\times 2$ orthogonal matrices are all rotational or reflectional (from an axis through the origin) matrices.\r\n    This can be trivially checked.\r\n    In particular, reflections have determinant $-1$ while rotations always have determinant $1$.\r\n\\end{example}\r\n\\begin{definition}\r\n    A complex $n\\times n$ matrix $U$ is unitary if $U^\\dagger U=UU^\\dagger=I$.\r\n    Equivalently, $U^\\dagger=U^{-1}$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    $U$ is unitary if and only if it preserves complex inner product.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    $(U\\underline{x},U\\underline{y})=\\underline{x}^\\dagger U^\\dagger U\\underline{y}$.\r\n    Necessity is implied, and sufficiency is by $\\underline{x}=\\underline{e_i},\\underline{y}=\\underline{e_j}$.\r\n\\end{proof}\r\n", "meta": {"hexsha": "841b9a03478d5628d669597e2edaeb0d27ad1100", "size": 14156, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/matrices.tex", "max_stars_repo_name": "david-bai-notes/IA-Vectors-and-Matrices", "max_stars_repo_head_hexsha": "7fc43486ec5276262d4058c9daaea12affdb6bac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4/matrices.tex", "max_issues_repo_name": "david-bai-notes/IA-Vectors-and-Matrices", "max_issues_repo_head_hexsha": "7fc43486ec5276262d4058c9daaea12affdb6bac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4/matrices.tex", "max_forks_repo_name": "david-bai-notes/IA-Vectors-and-Matrices", "max_forks_repo_head_hexsha": "7fc43486ec5276262d4058c9daaea12affdb6bac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.6392694064, "max_line_length": 271, "alphanum_fraction": 0.6866346426, "num_tokens": 4494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603708, "lm_q2_score": 0.8723473647220786, "lm_q1q2_score": 0.8134231867107269}}
{"text": "\\section{Classification}\n\nSolve $w^* = \\arg\\min\\limits_w \\hat R(w)$, \\highlight{$y=\\operatorname{sign}(w^\\top x)$}\n\n$\\hat R(w) = \\frac{1}{n} \\sum_{i=1}^n \\ell(w;x_i,y_i)$, \\enskip $\\nabla\\!_w \\hat R = \\frac{1}{n} \\sum_n \\nabla\\!_w \\ell$%\\enskip$\\ell$: loss function\n\n% ===\n\\emph{0/1 loss:}\n$\\normalcolor\\to$ intractable\n\n$\\ell_{0/1} (w;x_i,y_i) = [y_i \\neq \\operatorname{sign}(w^Tx_i)] \\color{gray}\\in \\{0,1\\}$\n\n% ===\n\\emph{Perceptron algorithm:}\n$\\normalcolor\\to$ use $\\normalcolor\\ell_P$ and SGD\n\n$\\ell_P (w;x_i,y_i) = \\max(0, -y_i w^\\top x_i)$\n\n%$\\nabla\\!_w \\hat R(w) = \\frac{1}{n}\\sum_{i=1}^n \\nabla\\!_w \\ell_P(w;x_i,y_i)$\n\n$\\nabla\\!_w \\ell_P(w;x_i,y_i) = \n\\begin{cases}\n    0 &\\text{if } y_i w^\\top x_i \\geq 0\\\\\n    -y_i x_i &\\text{otw. \\color{gray}(incorrect)}\n\\end{cases}$\n\nData lin. separable $\\Rightarrow$ obtains a lin. separator\n\n% ===\n\\emph{Support Vector Machine (SVM):}\n$\\normalcolor\\to$ \\textbf{Hinge}\n\n$\\ell_H(w;x_i,y_i) = \\max(0,{\\color{red}1}-y_i w^T x_i)$\n\n$\\hat R(w) = \\frac{1}{n}\\sum_n \\ell_H + \\lambda\\norm{w}_2^2$, \\enskip $\\nabla\\!_w \\hat R = \\ldots + 2\\lambda w$\n\n%$\\nabla\\!_w \\hat R(w) = \\frac{1}{n}\\sum_{i=1}^n \\nabla\\!_w \\ell_P(w;x_i,y_i) + 2\\lambda w$\n\n$\\nabla_w \\ell_H(w;x_i,y_i) = \n\\begin{cases}\n    0 &\\text{if } y_iw^\\top x_i \\geq {\\color{red}1}\\\\\n    -y_i x_i &\\text{otw.}\n\\end{cases}$\n\n$w_{t+1} \\leftarrow w_t(1-2\\eta_t\\lambda) + y_ix_i\\eta_t\\,[y_iw^\\top x_i < 1]$\n\nFor \\textbf{L1-SVM} (feature selection) use $\\norm{w}_1$ \n", "meta": {"hexsha": "09e6c995ce7fac566a2700ba31c6e33f0660dd50", "size": 1459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/IML19/sections/Classification.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/IML19/sections/Classification.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/IML19/sections/Classification.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3958333333, "max_line_length": 149, "alphanum_fraction": 0.6086360521, "num_tokens": 679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229961215457, "lm_q2_score": 0.8791467770088162, "lm_q1q2_score": 0.813412938394561}}
{"text": "\\chapter{Key exchange protocol}\\label{chap:exchange}\nThe private key system we developed in Chapter~\\ref{chap:encryption} and \\ref{chap:security} required the two parties to possess the same shared key. One of the major development in modern cryptography is the public key system that allows parties to securely exchange a shared key to use in a symmetric system. In this chapter, we build a Rubik's Cube key exchange protocol using a structure similar to Diffie-Hellman key exchange.\n\n\\section{Diffie-Hellman key exchange}\n\\par As we mentioned before, communication between two parties using private-key encryption requires that they first exchange keys by some secure channel. Diffie-Hellman key exchange, shorten as DHKE, is a method of securely exchanging cryptographic keys over a public channel, and our Rubik's Cube key exchange protocol builds upon it.\n\\begin{enumerate}\n    \\item Alice and Bob agree on a arbitrary finite Abelian group $G$ of order $n$ and an element $g \\in G$. Both group $G$ and the element $g$ will be made public to everyone. (The group $G$ is written multiplicatively.)\n    \\item Alice picks a random natural number $a$, where $1 \\leq a < n$, and sends $A = g^a$ to Bob. ($a$ remains secret to everyone besides Alice.)\n    \\item Bob picks a random natural number $b$, where $1 \\leq b < n$, and sends $B = g^b$ to Alice. ($b$ remains secret to everyone besides Bob.)\n    \\item Alice computes $S_a = A^b$ and Bob computes $S_b = B^a$.\n\\end{enumerate}\nWe claim $S = S_a = S_b$ because $S_a = A^b = (g^a)^b = g^{ab} = (g^b)^a = B^a = S_b$. This ensures that Alice and Bob end up with the same shared value. In Table~\\ref{tab:diffie-hellman-value}, we display each party's knowledge on various values assuming the existence of an eavesdropper.\n\\begin{table}[ht]\n    \\centering\n    \\begin{tabular}{|c|c|c|c|}\n        \\hline Value & Alice & Bob & Eavesdropper \\\\ \\hline \\hline\n        G & \\cmark & \\cmark & \\cmark \\\\ \\hline\n        g & \\cmark & \\cmark & \\cmark \\\\ \\hline\n        a & \\cmark & \\xmark & \\xmark \\\\ \\hline\n        b & \\xmark & \\cmark & \\xmark \\\\ \\hline\n        A & \\cmark & \\cmark & \\cmark \\\\ \\hline\n        B & \\cmark & \\cmark & \\cmark \\\\ \\hline\n        S & \\cmark & \\cmark & \\xmark \\\\ \\hline\n    \\end{tabular}\n    \\caption{Diffie-Hellman secrecy table}\n    \\label{tab:diffie-hellman-value}\n\\end{table}\nWe see that the security of the DHKE protocol is based on that given $g, g^a, g^b$, finding $a$ or $b$ is difficult and thus finding the shared value $g^{ab}$ is hard as well. This problem is known as the \\textit{discrete logarithm problem}. Though discrete logarithms are quickly computable in a few special cases, no efficient method is known for computing them in general. \n\\par We want to build a minimal example with the multiplicative group to walk through the details of DHKE. Suppose Alice and Bob agree to use a modulus $p = 11$ ($G = \\mathbb{U}_{11}$), and a base $g = 2$ (which generates $G$).\n\\begin{enumerate}\n    \\item Alice picks a random natural number $a = 3$, and sends $A = g^a$ to Bob. \\\\\n    $A = 2^3 \\mod 11 = 8 \\mod 11 = 8$\n    \\item Bob picks a random natural number $b = 7$, and sends $B = g^b$ to Alice. \\\\\n    $B = 2^7 \\mod 11 = 128 \\mod 11 = 7$\n    \\item Alice computes $S = B^a = 7^3 \\mod 11 = 343 \\mod 11 = 2$\n    \\item Bob computes $S = A^b = 8^7 \\mod 11 = 2097152 \\mod 11 = 2$\n    \\item Alice and Bob now share a secret, the number 2.\n\\end{enumerate}\nOf course, much larger values of $a$, $b$, and $p$ would be needed to make the DHKE secure. In real life applications, $p$ should have a length of 1024 bits or even longer and $g$ should have large prime order. The most common used group by the DHKE protocol is the multiplicative group of integers modulo $p$, with the elliptic curves being a significant variant. \n\n\\section{Rubik's Cube key exchange}\n\\par Notably, the original implementation of the DHKE requires the selected group $G$ to be Abelian but the Rubik's Cube group is not since the fundamental moves do not all commute with each other. By extracting the ideas presented in the paper\\cite{exchange}, we can design a DHKE-like protocol that helps us securely exchange information between two parties but does not require the group $G$ to be Abelian.\n\\par Assume that we have two parties, Alice and Bob, who want to share the secret key. Let them agree on using the Rubik's cube group $G_3$. An element (one state) $g \\in G_3$ is chosen and made public as well as an arbitrary automorphism $\\phi$ of $G_3$. Alice chooses a private number $a \\in \\mathbb{N}$ and Bob chooses a private number $b \\in \\mathbb{N}$.\n\\begin{enumerate}\n    \\item Alice picks a natural number $a > 1$ and computes $A = \\phi^{a - 1}(g) \\cdots \\phi^2(g) \\cdot \\phi(g) \\cdot g$ and sends this value to Bob.\n    \\item Bob picks a natural number $b > 1$ and computes $B = \\phi^{b - 1}(g) \\cdots \\phi^2(g) \\cdot \\phi(g) \\cdot g$ and sends this value to Alice.\n    \\item Alice computes her key $K_A = \\phi^a(B) \\cdot A$.\n    \\item Bob computes his key $K_B = \\phi^b(A) \\cdot B$.\n\\end{enumerate}\nWe claim that Alice and Bob share the same secret key. Alice's shared key is:\n\\begin{align}\n    K_A = \\phi^a(B) \\cdot A & = \\phi^a(\\phi^{b - 1}(g) \\cdots \\phi(g) \\cdot g) \\cdot ( \\phi^{a - 1}(g) \\cdots \\phi(g) \\cdot g) \\\\ \n    & = (\\phi^a(\\phi^{b - 1}(g)) \\cdots \\phi^{a}(\\phi(g)) \\cdot \\phi^a(g)) \\cdot ( \\phi^{a - 1}(g) \\cdots \\phi(g) \\cdot g) \\\\\n    & = (\\phi^{a + b - 1}(g) \\cdots \\phi^{a + 1}(g) \\cdot \\phi^a(g)) \\cdot ( \\phi^{a - 1}(g) \\cdots \\phi(g) \\cdot g) \\\\\n    & = \\phi^{a + b - 1}(g) \\cdots \\phi(g) \\cdot g\n\\end{align}\nWe could go from step $(\\ref{chap:exchange}.1)$ to step $(\\ref{chap:exchange}.2)$ because of the operation preserving feature of automorphism, which is $\\phi(g_1g_2) = \\phi(g_1)\\phi(g_2)$. The shared key Bob holds can be calculated in a similar fashion:\n\\begin{align*}\n    K_B = \\phi^b(A) \\cdot B & = \\phi^b(\\phi^{a - 1}(g) \\cdots \\phi(g) \\cdot g) \\cdot ( \\phi^{b - 1}(g) \\cdots \\phi(g) \\cdot g) \\\\ \n    & = (\\phi^{b + a - 1}(g) \\cdots \\phi^{b + 1}(g) \\cdot \\phi^b(g)) \\cdot ( \\phi^{b - 1}(g) \\cdots \\phi(g) \\cdot g) \\\\\n    & = \\phi^{b + a - 1}(g) \\cdots \\phi(g) \\cdot g = K_A\n\\end{align*}\nNotice that the Diffie-Hellman secrecy table displayed in Table~\\ref{tab:diffie-hellman-value} still holds true for above settings. If we pick $\\phi$ of $G_3$ as $\\phi(g) = g$, we can discover that, different from the standard DHKE, correctness of the Rubik's Cube key exchange is based on the equality $g^a \\cdot g^b = g^b \\cdot g^a = g^{a+b}$.\n\\par Let us show an example of how to use Rubik's Cube key exchange protocol. The group we are using is $G_3$ and this information is known by public. We also pick a public automorphism $\\phi$ to be a right conjugation by $R$. That is $\\phi(g) = RgR^{-1}$. Finally we pick a public group element $g = U$ (the state we reach to by applying move $U$ to a solved cube.) \n\\begin{enumerate}\n    \\item Alice picks a random natural number $a = 4$, and sends $A$ to Bob.\n    \\begin{align*}\n        A & = \\phi^3(g) \\cdot \\phi^2(g) \\cdot \\phi(g) \\cdot g \\\\\n        & = R^3(g)R^{-3}R^2(g)R^{-2}R(g)R^{-1}g \\\\\n        & = R^3(g)(R^{-1}g)(R^{-1}g)(R^{-1}g) \\\\\n        & = R^3(g)(R^{-1}g)^3\n    \\end{align*}\n    \\item Bob picks a random natural number $b = 8$, and sends $B$ to Alice.\n    \\begin{align*}\n        B & = \\phi^7(g) \\cdot \\phi^6(g) \\cdots \\phi(g) \\cdot g \\\\\n        & = R^7(g)R^{-7}R^6(g)R^{-6} \\cdots R(g)R^{-1}g \\\\\n        & = R^7(g)(R^{-1}g)(R^{-1}g) \\cdots (R^{-1}g) \\\\\n        & = R^7(g)(R^{-1}g)^7\n    \\end{align*}\n    \\item Alice computes $K_A = \\phi^4(B) \\cdot A$ and finds the following result.\n    \\begin{align*}\n        \\phi^4(B) \\cdot A & = \\phi^4(R^7(g)(R^{-1}g)^7)\\;R^3(g)\\;(R^{-1}g)^3 \\\\\n        & = R^4R^7(g)(R^{-1}g)^7R^{-4}R^3(g)(R^{-1}g)^3 \\\\\n        & = R^{11}(g)(R^{-1}g)^7(R^{-1}g)(R^{-1}g)^3 \\\\\n        & = R^{11}(g)(R^{-1}g)^{11}\n    \\end{align*}\n    \\item Bob computes $K_B = \\phi^8(A) \\cdot B$ and finds the following result.\n    \\begin{align*}\n        \\phi^8(A) \\cdot B & = \\phi^8(R^3(g)(R^{-1}g)^3)\\;R^7(g)\\;(R^{-1}g)^7 \\\\\n        & = R^8R^3(g)(R^{-1}g)^3R^{-8}R^7(g)(R^{-1}g)^7 \\\\\n        & = R^{11}(g)(R^{-1}g)^3(R^{-1}g)(R^{-1}g)^7 \\\\\n        & = R^{11}(g)(R^{-1}g)^{11}\n    \\end{align*}\n    \\item Alice and Bob now share a secret series of fundamental moves of $C_3$.\n    $$K_A = K_B = R^{11}(U)(R^{-1}U)^{11}$$\n\\end{enumerate}\nSince $R^{-1}$ is the move that reverses $R$, we can simply rewrite it as $R'$. Finally the move Alice and Bob shares is $\\underbrace{R...R}_{11}U\\underbrace{R'U...R'U}_{11}$. To get more complex result in real applications, we could explore the group structure of $G_3 \\cong (\\mathbb{Z}_3^7 \\times \\mathbb{Z}_2^{11}) \\rtimes (S_8 \\times A_{12})$ to select more complicated $g$ and $\\phi$ at the beginning.\n\\par Most modern key exchange protocols help communicating parties to establish a commonly shared number that is used for the key with a symmetric system like AES. We can add one more step in the key exchange protocol so that Alice and Bob can use their secretly shared moves to retrieve a number. Alice and Bob need to agree on a particular setting of $C_3$. We will refer this cube as \\textit{number exchange cube}. They both fill cubie on up face, down face, right face by ones and fill cubies on front face, back face, left face by zeros as shown in Table~\\ref{tab:exchange-start-bit}. After they retrieve the shared fundamental moves $K_A = K_B$, they apply that series of moves to the number exchange cube and then read out the bits as the binary number. Notice that here each cubie only holds one bit and we do not want the center cubies to hold any information since they are fixed. We also do not want to use all bits from the cube because then the enemy knows that we are generating a binary of length 48 where half bits are ones and half bits are zeros. We instead only take bits from three faces, the up face, the front face and the right face. So for an arbitrary large cube $C_n$ we can use it to share a binary value with length of $3 \\cdot (n^2 - (n \\mod 2))$ bits.\n\\par To illustrate a detailed example of above procedure, let us first take a look at Table~\\ref{tab:exchange-start-bit}, which describes the starting position of the number exchange cube $C_3$ that Alice and Bob uses to retrieve the shared number. \n\\begin{table}[ht]\n    \\centering\n    \\begin{tabular}{|c|c|}\n        \\hline Up face & 11111111  \\\\\n        \\hline Front face & 00000000  \\\\\n        \\hline Right face & 11111111  \\\\\n        \\hline Down face & 11111111  \\\\\n        \\hline Back face & 00000000  \\\\\n        \\hline Left face & 00000000  \\\\ \\hline\n    \\end{tabular}\n    \\caption{Starting position of the number exchange cube $C_3$}\n    \\label{tab:exchange-start-bit}\n\\end{table}\nBoth Alice and Bob apply the shared moves $\\underbrace{R...R}_{11}U\\underbrace{R'U...R'U}_{11}$ to the number exchange cube, and the bits on each face is displayed in Table~\\ref{tab:exchange-final-bit}.\n\\begin{table}[ht]\n    \\centering\n    \\begin{tabular}{|c|c|}\n        \\hline Up face & \\textcolor{blue}{00011010}  \\\\\n        \\hline Front face & \\textcolor{blue}{00100001}  \\\\\n        \\hline Right face & \\textcolor{blue}{11110001}  \\\\\n        \\hline Down face & 11110100  \\\\\n        \\hline Back face & 01100000  \\\\\n        \\hline Left face & 11111110  \\\\ \\hline\n    \\end{tabular}\n    \\caption{Final position of the number exchange cube $C_3$}\n    \\label{tab:exchange-final-bit}\n\\end{table}\nRemember that we only use bits from three faces, and those bits we want are colored in blue. Both Alice and Bob read them out in order of: up face $\\rightarrow$ front face $\\rightarrow$ right face to retrieve the shared binary number $000110100010000111110001_2$.\n\\par In practice, symmetric keys are usually much longer. For example, the software FireVault on Mac OS uses AES with a 256-bit key to encrypt user's hard drive. We could use $C_{10}$ to exchange the key since $C_{10}$ are capable of holding $3 \\cdot 10^2 = 300$ bits.  \n\\par Even though we do not directly use numbers as the key to our Rubik's Cube encryption $\\Pi_{RC}$, given a binary number we can still convert it to a series of fundamental moves. Suppose we have a set $S$ which contains all base 18 numbers with only one digit. Thus $S = \\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, g, h\\}$. In Table~\\ref{tab:map-move} find a one-to-one mapping between elements of $S$ and the 18 fundamental moves.\n\\begin{table}[ht]\n    \\centering\n    \\begin{tabular}{|c|c|c|c|c|c|}\n        \\hline 0 - $U$ & 1 - $F$ & 2 - $R$ & 3 - $D$ & 4 - $B$ & 5 - $L$ \\\\\n        \\hline 6 - $U2$ & 7 - $F2$ & 8 - $R2$ & 9 - $D2$ & a - $B2$ & b - $L2$ \\\\\n        \\hline c - $U'$ & d - $F'$ & e - $R'$ & f - $D'$ & g - $B'$ & h - $L'$ \\\\ \\hline\n    \\end{tabular}\n    \\caption{Mapping between set $S$ and fundamental moves}\n    \\label{tab:map-move}\n\\end{table}\nAlice and Bob can convert the shared binary number to a base 18 number, $g5bff_{18}$. Then their commonly shared key will be ``$B'$ $L$ $R2$ $D'$ $D'$ ''. Notice that the biggest possible binary we can share using $C_3$ is $2^{24} - 1$. By converting that number to base 18, we get number $8fed99$. Since the maximum value on the first digits is 8, if we always use all 6 digits, the first movement will always be restricted. We thus simply ignore the first digit and use last 5 digits to represent fundamental moves when the number happen to have 6 digits. When the number has less than 5 digits, we treat leading digits as zeros. In Table~\\ref{tab:share-length}, we show the length of the key different $C_n$ can share.\n\\begin{table}[ht]\n    \\centering\n    \\begin{tabular}{|c|c|c|c|c|}\n        \\hline $C_3 - 5$ & $C_4 - 11$ & $C_5 - 17$ & $C_6 - 25$ & $C_7 - 34$ \\\\\n        \\hline $C_8 - 46$ & $C_9 - 57$ & $C_{10} - 71$ & $C_{15} - 161$ & $C_{19} - 258$ \\\\ \\hline\n    \\end{tabular}\n    \\caption{Maximum length of the $\\Pi_{RC}$ key $C_n$ can share}\n    \\label{tab:share-length}\n\\end{table}\n\\par In Chapter~\\ref{chap:security}, we suggested to use a key with length 30. Hence choosing $C_7$ here might be most appropriate option. We now have completed the setting of the key-exchange encryption protocol and shown how to apply this to the actual Rubik's Cube encryption $\\Pi_{RC}$. \n\n\\section{Complete example}\n\\par Let us put everything together and demonstrate a minimal example on how Alice and Bob can securely communicate with each other by using the Rubik's Cube encryption and the Rubik's Cube key exchange protocol on $C_3$. Suppose Alice now wants to send out ``Hello Bob!''\n\\par Before the secure channel is built, Alice and Bob first exchange the shared key. They pick the public element $g = U\\,R\\,B\\,D\\,L'$ and let the public automorphism $\\phi \\in Aut(G_3)$ to be an inner-automorphism $\\phi(g) = U2\\,L2\\,D'\\,g\\,D\\,L2\\,U2$, and agree to use the bit shift as the permutation $p$ during encryption.\n\\begin{itemize}\n    \\item Alice picks a random natural number $a = 23$, and sends $A$ to Bob.\n    \\begin{align*}\n        A & = \\phi^{22}(g) \\cdots \\phi(g) \\cdot g \\\\\n        & = (U2\\,L2\\,D')^{22}U\\,R\\,B\\,D\\,L'(D\\,L2\\,U2\\,U\\,R\\,B\\,D\\,L')^{22}\n    \\end{align*}\n    \\item Bob picks a random natural number $b = 37$, and sends $B$ to Alice.\n    \\begin{align*}\n        B & = \\phi^{36}(g) \\cdots \\phi(g) \\cdot g \\\\\n        & = (U2\\,L2\\,D')^{36}U\\,R\\,B\\,D\\,L'(D\\,L2\\,U2\\,U\\,R\\,B\\,D\\,L')^{36}\n    \\end{align*}\n    \\item Alice computes $K_A = \\phi^{23}(B) \\cdot A$ and finds the following result.\n    $$\\phi^4(B) \\cdot A = (U2\\,L2\\,D')^{59}U\\,R\\,B\\,D\\,L'(D\\,L2\\,U2\\,U\\,R\\,B\\,D\\,L')^{59}$$\n    \\item Bob computes $K_B = \\phi^{37}(A) \\cdot B$ and finds the following result.\n    $$\\phi^8(A) \\cdot B = (U2\\,L2\\,D')^{59}U\\,R\\,B\\,D\\,L'(D\\,L2\\,U2\\,U\\,R\\,B\\,D\\,L')^{59}$$\n    \\item Alice and Bob now share a secret series of fundamental moves of $C_3$.\n    $$K = K_A = K_B = (U2\\,L2\\,D')^{59}U\\,R\\,B\\,D\\,L'(D\\,L2\\,U2\\,U\\,R\\,B\\,D\\,L')^{59}$$\n\\end{itemize}\n\\par Both Alice and Bob apply the shared key $K$ to the number exchange cube $C_3$. \n\\begin{table}[ht]\n    \\centering\n    \\begin{minipage}{0.45\\textwidth}\n        \\centering\n        \\begin{tabular}{|c|c|}\n            \\hline Up face & 11111111  \\\\\n            \\hline Front face & 00000000  \\\\\n            \\hline Right face & 11111111  \\\\\n            \\hline Down face & 11111111  \\\\\n            \\hline Back face & 00000000  \\\\\n            \\hline Left face & 00000000  \\\\ \\hline\n        \\end{tabular}\n        \\caption{Starting position of the \\\\\\hspace{\\textwidth} number exchange cube $C_3$}\n        \\label{tab:example-exchange-start-bit}\n    \\end{minipage}\n    \\begin{minipage}{0.45\\textwidth}\n        \\centering\n        \\begin{tabular}{|c|c|}\n            \\hline Up face & \\textcolor{blue}{11101101}  \\\\\n            \\hline Front face & \\textcolor{blue}{01000010}  \\\\\n            \\hline Right face & \\textcolor{blue}{10011011}  \\\\\n            \\hline Down face & 00110000  \\\\\n            \\hline Back face & 00010110  \\\\\n            \\hline Left face & 10110111  \\\\ \\hline\n        \\end{tabular}\n        \\caption{Final position of the \\\\\\hspace{\\textwidth} number exchange cube $C_3$}\n        \\label{tab:example-exchange-final-bit}\n    \\end{minipage}\n\\end{table}\nThe initial bits and final bits on faces of $C_3$ are displayed in Table~\\ref{tab:example-exchange-start-bit} and Table~\\ref{tab:example-exchange-final-bit} separately. The binary number Alice and Bob both retrieve is $111011010100001010011011_2$. Then, they convert this binary value to a base 18 number, $8422hh_{18}$. Alice and Bob will omit the first digit since they agree to use only the last 5 digits. By looking at the mapping described in Table~\\ref{tab:map-move}, they find the shared key is ``$B\\,R\\,R\\,L'\\,L'$.'' Now Alice can convert her message to its binary representation.\n\\begin{center}\n    0100100001100101011011000110110001101111 \\\\\n    0010000001000010011011110110001000100001\n\\end{center}\nAlice no longer has to remove punctuations or capitalize all letters because the message will get changed during the encryption. Since this message contains merely 80 bits, and $C_3$ needs an input of 180 bits to encrypt. Alice needs to pad it first. The padded string is shown as below:\n\\begin{center}\n    010010000110010101101100011011000110111100100000010000100110\n    111101100010001000011000000000000000000000000000000000000000\n    000000000000000000000000000000000000000000000000000000000000\n\\end{center}\nAfter inputting the string, 36 random bits will be generated by the encryption protocol ``111100001101010110101000010000011110,'' and those bits will be added to the end of the padded string. During the encryption process, before applying each fundamental move in the key, the encryption protocol first does a XOR between faces, and then shifts bits to the right by one space. After all moves are executed, the ciphertext is:\n\\newpage\n\\begin{center}\n    000111011001000100101100011101101110001010000000000100100100101010100001\n    010001000111011010000000100000010001101111111011000010000100110010011101\n    010101110000101000100101010000100110001110000011010001101011000110101010\n\\end{center}\nAlice can convert this binary value back to its ASCII representation, which looks like ``\\;\\'{E},v$\\Upgamma$\\c{C}\\;J\\'{\\i}Dv\\c{C}\\\"{u}\\;$\\surd{}$\\;L\\textyen{}W\\;\\%Bc\\^{a}F|$\\neg$\\,,'' and sends it to Bob. \n\\par To decrypt Alice's message, Bob has to first find the inverse of the key ``$B\\,R\\,R\\,L'\\,L'$'', which will be ``$L$\\,$L$\\,$R'$\\,$R'$\\,$B'$.'' Then he converts the received message back to its binary representation to retrieve the 216 bits and fills an empty $C_3$ with the bits. For each fundamental move in ``$B\\,R\\,R\\,L'\\,L'$'', Bob first applies the move to the cube, then shift bits back to the left by one space and finally performs the XOR operation between the left face and the rest of faces.\n\\par After all moves in the inverse of the key are applied to the cube, Bob will get the padded string. He removes all tailing zeros and one extra 1 at the end to get the plaintext in its binary representation. \n\\begin{center}\n    0100100001100101011011000110110001101111 \\\\\n    0010000001000010011011110110001000100001\n\\end{center}\nBy looking up the ASCII table, he gets Alice's message ``Hello Bob!'' To reply Alice's message, he can follow the same encryption process used by Alice, and he will keep using the shared key without exchanging new ones.\n\\par The example above illustrates how everything we developed ties together and serves as a complete encryption system that helps two parties to communicate with some protection.", "meta": {"hexsha": "824cbc2e617b31f54d2b45635138b7763412d304", "size": 20516, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/chapters/exchange.tex", "max_stars_repo_name": "Weiqi97/Honor-Thesis", "max_stars_repo_head_hexsha": "eff11dea2fe14a66e787154c9c0bd1ed4b02bd06", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "content/chapters/exchange.tex", "max_issues_repo_name": "Weiqi97/Honor-Thesis", "max_issues_repo_head_hexsha": "eff11dea2fe14a66e787154c9c0bd1ed4b02bd06", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "content/chapters/exchange.tex", "max_forks_repo_name": "Weiqi97/Honor-Thesis", "max_forks_repo_head_hexsha": "eff11dea2fe14a66e787154c9c0bd1ed4b02bd06", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 89.5895196507, "max_line_length": 1281, "alphanum_fraction": 0.667284071, "num_tokens": 6639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8791467770088162, "lm_q1q2_score": 0.8134129365820161}}
{"text": "\r\n\\input{SingleAssignmentSetup.tex}\r\n\\input{../WeekTitles.tex}\r\n\\usepackage{bbding} % for Checkmarkbold\r\n\\begin{document}\r\n\r\n\\newcommand{\\ub}{\\underbrace}\r\n\r\n\\begin{center}\r\n\\subsection*{MNTC P01 - Week \\#9 - \\WeekTitleNine}\r\n\\end{center}\r\n\r\n\r\n% % ******************** PENDULUM ********************************\r\n\\subsection*{Pendulum}\r\n\\begin{enumerate}[1.]\r\n\r\n\\item \r\n  \\begin{Question}\r\n    \\begin{minipage}[h]{0.6\\linewidth}\r\n\\vspace{0pt}\r\nConsider the motion of a frictionless pendulum.\r\n\\begin{align*}\r\n  \\mbox{Newton's Second Law: }   m  L^2 \\theta'' & = T_g \\\\\r\n  & = - m L g \\sin(\\theta)  \\\\\r\n  \\mbox{Solving for $\\theta''$: }\\theta'' & = - \\frac{g}{L} \\sin(\\theta) \r\n\\end{align*}\r\n\r\n{\\bf Without} simulating the actual motion of the pendulum, we can\r\ncompute the period, $T$, using the formula below:\r\n\\begin{align*}\r\n  T = 4 \\sqrt{L/g} \\int_0^{\\pi/2} \\frac{dx}{\\sqrt{1 - k^2 \\sin^2 x}}\r\n\\end{align*}\r\nwhere $k = \\sin\\left(\\frac{1}{2} \\theta_0\\right)$ and $g$ is the\r\nacceleration due to gravity, $9.8 $ m/s.  \r\n    \\end{minipage} \\hfill\r\n    \\begin{minipage}[h]{0.25\\linewidth}\r\n     \\includegraphics[width=1.0\\linewidth]{graphics/Week09_Pendulum/pendulum_diagram}\r\n    \\end{minipage}\r\n\r\nFor each set of values for $L$ and $\\theta_0$ given below,\r\n\\begin{enumerate}[(a)]\r\n\\item Use the MATLAB \\verb#integral# function to find the period of\r\n  the pendulum oscillations by evaluating the integral given above,\r\n  and\r\n\\item confirm the period by using \\verb#ode45# to simulate the motion\r\n  of the pendulum for exactly that length of time, and plot a graph of\r\n  the angular {\\bf velocity} against time.  The velocity should just\r\n  reach zero at the end of one cycle.\r\n\\end{enumerate}\r\n\r\nDo this with the following sets of $L$ and $\\theta_0$ values.\r\n\\begin{enumerate}[(i)]\r\n\\item $L = 2$ m, $\\theta_0 = 40^o$, \r\n\\item $L =2.5$ m, $\\theta_0 = 20^o$.\r\n\\item $L =5.0$ m, $\\theta_0 = 90^o$.\r\n\\end{enumerate}\r\n  \\end{Question}\r\n\r\n\\begin{Solution}\r\n\r\nLink to the MATLAB code: \\\\\r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W09Pendulum1.m}{W09Pendulum1.m} \\\\\r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/pendulumDE.m}{pendulumDE.m} \\\\\r\n\r\nNote that we simply re-used the \\verb#pendulumDE.m# from the lectures,\r\nand set the friction coefficient $\\mu = 0$.\r\n  \\begin{enumerate}[(i)]\r\n  \\item $L = 2$ m, $\\theta_0 = 40^o$:  {\\bf T = 2.9274} seconds.\r\n  \\item $L =2.5$ m, $\\theta_0 = 20^o$: {\\bf T = 3.1978} seconds.\r\n  \\item $L =5.0$ m, $\\theta_0 = 90^o$: {\\bf T = 5.2974} seconds.\r\n  \\end{enumerate}\r\n\r\nPlots: \\\\\r\n\\includegraphics[width=0.33\\linewidth]{graphics/Week09_Pendulum/pendulum_nofriction_1} \r\n\\includegraphics[width=0.33\\linewidth]{graphics/Week09_Pendulum/pendulum_nofriction_2} \r\n\\includegraphics[width=0.33\\linewidth]{graphics/Week09_Pendulum/pendulum_nofriction_3} \r\n\\end{Solution}\r\n\r\nIn all the graphs, we see that that the velocity returns to 0 at the\r\nend of the cycle, indicating that our integral calculation of the\r\nperiod matches the period from the \\verb#ode45# simulation.\r\n\r\n%*******************************\r\n\\item\r\n\\begin{Question}\r\n    \\begin{minipage}[t]{0.7\\linewidth}\r\n\\vspace{0pt}\r\nConsider the motion of a pendulum, this time {\\bf with} friction.\r\n\\begin{align*}\r\n  \\mbox{Newton's }& \\mbox{ Second Law: } \\\\\r\n   m  L^2 \\theta'' & = T_g + T_f  \\\\\r\n  & = - m L g \\sin(\\theta) - (\\mu L^2 m) \\theta' \\\\[3ex]\r\n  \\mbox{Solving for $\\theta''$: }\\theta'' & = - \\frac{g}{L} \\sin(\\theta) - \\mu \r\n  \\theta'\r\n\\end{align*}\r\n\\begin{enumerate}[(a)]\r\n\\item Write a MATLAB function for the differential equation, and a\r\n  script that will simulate the scenario for $L = 1.5$ m, $g = 9.8$\r\n  m/s$^2$, and $\\mu = 0.2$.  Use an initial condition of\r\n  $\\theta_0 = \\frac{7\\pi}{8}$, which is close to vertical.\r\n\\item Experiment with the initial {\\bf angular velocity} of the\r\n  pendulum and find the smallest {\\bf positive} initial velocity that\r\n  will result in the pendulum passing over the top of the axis of\r\n  rotation.  Find the value to the nearest 0.1 rad/s.  \r\n\r\n  Have MATLAB generate a plot of the angle vs time graph for both the\r\n  initial velocity that achieves this result, and for the initial velocity 0.1 rad/s smaller, which does {\\em not} go `over the top'.\r\n\\item Repeat the analysis in part (b), but this time using a {\\bf\r\n    negative} initial velocity.\r\n\\end{enumerate}\r\n\\end{minipage} \\hfill\r\n\\begin{minipage}[t]{0.25\\linewidth}\r\n\\vspace{0pt}\r\n  \\includegraphics[width=1.0\\linewidth]{graphics/Week09_Pendulum/pendulum_diagram}\r\n\\end{minipage}\r\n\r\n\r\n\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n\r\n\\begin{enumerate}[(a)]\r\n\\item \r\nLink to the MATLAB code: \\\\\r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W09Pendulum2.m}{W09Pendulum2.m} \\\\\r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/pendulumDE.m}{pendulumDE.m} \\\\\r\n\r\nHere is the graph of the angle over time for the pendulum, when it has no initial velocity.\r\n\r\n\\includegraphics[width=0.45\\linewidth]{graphics/Week09_Pendulum/pendulum_overtop_1} \r\n\r\n\\item With some experimentation, we find that an initial angular\r\n  velocity of $\\theta'(0) = 1.1$ rad/s will be enough to push the\r\n  pendulum over the top of the axis of rotation. Comparing\r\n  $\\theta'(0) = 1.1$ and 1.0, we obtain the following graph of angle\r\n  against time.\r\n\r\n\\includegraphics[width=0.5\\linewidth]{graphics/Week09_Pendulum/pendulum_overtop_2} \r\n\r\n\\item With further experimentation, we find that using negative\r\n  initial angular velocities requires a higher initial velocity\r\n  compared to positive initial velocities, because friction eats away\r\n  at the effect of that first push when we are going down first and\r\n  then over the top.  Still, a value of $\\theta'(0) = -3.3$ rad/s will\r\n  be enough to push the pendulum over the top of the axis. Comparing\r\n  $\\theta'(0) = -3.3$ and -3.2, we obtain the following graph of angle\r\n  against time.\r\n\r\n\\includegraphics[width=0.5\\linewidth]{graphics/Week09_Pendulum/pendulum_overtop_3} \r\n\\end{enumerate}\r\n\r\n\\end{Solution}\r\n\r\n\r\n\\subsection*{Single Tank Problems}\r\n\r\n%********************\r\n\\item \r\n\\begin{Question}\r\n  An aquarium pool has volume $2 \\times 10^6$ liters.  The pool\r\n  initially contains pure fresh water. At $t=0$ minutes, water\r\n  containing 10 grams/liter of salt is poured into the pool at a rate\r\n  of 60 liters/minute. The salt water instantly mixes with the fresh\r\n  water, and the excess mixture is drained out of the pool at the same\r\n  rate (60 liters/minute).\r\n\r\n   \\begin{enumerate}[(a)]\r\n\r\n   \\item Write a differential equation for $S(t)$, the mass of\r\n     salt in the pool at time $t$.\r\n\r\n   \\item Use MATLAB solve the differential equation to predict $S(t)$\r\n     over time.\r\n\r\n   \\item Based on the graph of the solution, what happens to $S(t)$ as\r\n     $t \\to \\infty$?  \r\n\r\n   \\item Find this same value using only the information about the\r\n     volume and the concentration of the incoming salt solution.\r\n\r\n   \\end{enumerate}\r\n\r\n\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n\\begin{enumerate}\r\n\\item \r\n\\begin{align*}\r\n  \\text{Rate of change of salt amount (g/min)} & = \\text{ Rate in } - \\text{ Rate out }  \\\\\r\n  \\text{Rate in (g/min)} & = \\text{Flow rate $\\times$ Concentration} \\\\\r\n  & = (60 \\text{ liters/min}) \\times (10 \\text{ g/liter}) = 600 \\text{ g/min} \\\\\r\n  \\text{Rate out (g/min)} & = \\text{Flow rate $\\times$ Concentration}  \\\\\r\n  & =\\text{Flow rate $\\times$ amount (g) / Pool volume (liters)} \\\\\r\n  & = (60 \\text{ liters/min}) (S(t) \\text{ grams}) / (2 \\times 10^6 \\text{ liters}) \\\\\r\n  & = (3 \\times 10^{-5}) S(t) \\\\\r\n  \\text{Finally, we get our DE: } ~~~~~ \\ddt{S} &= 600 - (3 \\times 10^{-5}) S \\\\\r\n\\end{align*}\r\n\r\n\\item Note: to see anything interesting in this simulation, you have\r\n  to simulate for a {\\bf long} simulation time, i.e. a long\r\n  \\verb#tspan#.  Here are two graphs of the simulation results, one\r\n  with 1000 minutes, and then with 1 million minutes.\r\n\r\n\\includegraphics[width=0.45\\linewidth]{graphics/Week09_Pendulum/single_tank_1a} \\hfill\r\n\\includegraphics[width=0.45\\linewidth]{graphics/Week09_Pendulum/single_tank_1b} \r\n\r\nThe reason a long simulation time is needed is because adding 60 L/min\r\nto a 2 million liter pool takes a long time to have an effect.\r\n\\item As $t \\to \\infty$, we see the graph of $S(t)$ plateau at $S \\to 2 \\times 10^7$ grams.\r\n\r\n\\item We expect that the salt in the aquarium will tend to the same\r\n  {\\bf concentration} as the incoming water, as all of the original\r\n  water is replaced with the new inflow solution.  At a concentration\r\n  of 10 g/liter, in a volume of $ 2 \\times 10^6$ liters, we expect to\r\n  see eventually $S = C\\times V = (10)(2 \\times 10^6) = 2 \\times 10^7$\r\n  grams of salt in the aquarium, which matches our graphical results.\r\n\r\n\\end{enumerate}\r\n\\end{Solution}\r\n\r\n\r\n\r\n% ****************************************\r\n\\item \r\n\\begin{Question}\r\n  A 150 liter tank initially contains 60 liters of water with 0.5 kgs\r\n  of salt dissolved in it.  Water enters the tank at a rate of 0.9\r\n  liters/hr and the water entering the tank has a salt concentration\r\n  of $\\frac{1}{5}(1 + \\cos (t))$ kgs/liter. \r\n  \\begin{enumerate}[(a)]\r\n  \\item Draw a diagram of the inflow and outflow for this scenario.\r\n  \\item Build a formula for the volume of water in the tank over time.\r\n  \\item Find out how long it will be until the tank overflows.\r\n  \\item Write a differential equation that describes the rate of\r\n    change of the {\\bf amount of salt} in the tank.\r\n  \\item Use MATLAB to generate a graph of the amount of salt in the\r\n    tank over time, up until the tank overflows.\r\n  \\item How much salt is in the tank when it overflows?\r\n  \\end{enumerate}\r\n\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  \\begin{enumerate}[(a)]\r\n  \\item Here is a diagram of the system.\r\n\r\n\\includegraphics[width=0.45\\linewidth]{graphics/Week09_SingleTanks/Tank1} \r\n \r\n  \\item Since the tank has a volume of 150 L, is gaining 0.9 - 0.6 = 0.3\r\n  L/hour, and starts at 60 L, we obtain the volume expression $V(t) = 60 + 0.3 t$.\r\n\r\n\\item Solving $V(t) = 150$ for $t$, gives us $ 60 + 0.3 t = 150$, or\r\n  $t = 300$ hours until the tank overflows.\r\n\r\n\\item The differential equation will be the same ``rate in - rate\r\n  out'' form.\r\n\\begin{align*}\r\n  \\text{Rate of change of salt amount (kg/hr)} & = \\text{ Rate in } - \\text{ Rate out } \r\n\\end{align*}\r\n\\begin{align*}\r\n  \\text{Rate in (kg/hr)} & = \\text{Flow rate $\\times$ Concentration} \\\\\r\n                         & = (0.9 \\text{ liters/hr}) \\times (\\frac{1}{5} (1 + \\cos(t)) \\text{ kg/liter}) \\\\\r\n                         & = 0.18(1 + \\cos(t)) \\text{kg/hr} \\\\\r\n  \\text{Rate out (kg/hr)} & = \\text{Flow rate $\\times$ Concentration}  \\\\\r\n                         & =\\text{Flow rate $\\times$ amount (g) / Pool volume (liters)} \\\\\r\n                         & = (0.6 \\text{ liters/hr}) (S(t) \\text{ kg}) / (60 + 0.3 t) \\text{ liters}) \\\\\r\n  \\text{Finally, we get our DE: } ~~~~~ \\ddt{S} &= 0.18 (1 + \\cos(t)) - \\frac{0.6}{60 + 0.3t} S\r\n\\end{align*}\r\n\r\n\\item Here is the graph of the predicted amount of salt in the tank over time. \r\n\r\n  \\includegraphics[width=0.75\\linewidth]{graphics/Week09_SingleTanks/single_tank_2a}\r\n\r\n  Note that the $\\cos(t)$ effect has a short period ($2 \\pi \\approx $ 6 hours)\r\n  relative to the 300 hours of the simulation time, which is why the\r\n  graph looks like it has the high-frequency oscillations in it.\r\n\r\n\\item By either zooming in, or typing \\verb#S# at the MATLAB command\r\n  line to show all the \\verb#S# values coming out of the simulation\r\n  and grabbing the last one, we find at the end of 300 hours that\r\n  there is $S(300) \\approx 27.6212$ kg of salt in the tank.\r\n\r\n  \\end{enumerate}\r\n  \r\n\\end{Solution}\r\n\r\n% ******************** Fish Population ********************************\r\n\\subsection*{Other First Order Models}\r\n\\item \r\n  \\begin{Question}\r\n    \r\nDifferential equations are not only well-suited for physics\r\n  applications: they are are also widely used in biology, particularly\r\n  in population models.\r\n\r\n  Consider the fish population model below, based on a standard\r\n  limited-resource population growth, minus a function of harvesting.\r\n\r\n$$\\frac{dP}{dt} =\\underbrace{ [(10 -P)\\cdot P]}_{\\mbox{natural population growth rate}} -\\underbrace{h(t)}_{\\mbox{harvesting rate}}$$\r\nwhere\r\n\\begin{itemize}\r\n\\item $P$  = population of fish (in thousands), and \r\n\\item $\\frac{dP}{dt}$  = rate of population change, in thousands per \r\nyear\r\n\\item $h(t)$ is the harvesting rate (in thousands of fish per \r\nyear)\r\n\\end{itemize}\r\n\r\nWe want to study the impact of two harvesting models:\r\n\\begin{itemize}\r\n\\item $h_1 = k_1$; constant harvesting\r\n\\item $h_2(t) = k_2 (\\sin(\\pi t) + 1)$; seasonal model where the\r\n  harvesting has a yearly cycle.\r\n\\end{itemize}\r\n\\begin{enumerate}[(a)]\r\n\r\n\\item Generate a prediction of the population over time, starting at\r\n  initial populations of $P(0) = 15$ for each model.  Use $k_1 = k_2 =\r\n  5$. Produce a graph showing the predicted population over time on\r\n  the same graph, over a long enough time interval to show the\r\n  long-term behaviour of both solutions.\r\n\r\n\\vspace{0.2in}\r\n\r\nOne question that arises in such harvesting models is which fishing\r\nstrategy permits a higher average harvesting rate can be maintained:\r\nseasonal harvesting, or constant harvesting?  To decide this, we note\r\nthat the average harvest rate for $h_1$ is $k_1$, and for $h_2$ is\r\n$k_2$, so whichever value of $k_1$ and $k_2$ is larger indicates the\r\nstrategy with the greater average harvesting rate.\r\n\r\nWe will define the {\\em maximum sustainable harvest rate} for both\r\nmodels as the {\\em highest harvest rate for which the population is\r\n  not driven to zero.}\r\n\r\n\\item Find and report the maximum sustainable harvest level $k_1$ for\r\n  the constant harvesting model (to the nearest integer).  (Use trial\r\n  and error if necessary, though more insightful DE-related ways are\r\n  possible.)  Indicate how you found the cut-off level. \r\n\r\n  {\\em NOTE: during this process, your model will predict a population\r\n    of zero, which will then lead to large negative populations.  This\r\n    clearly makes no sense, so limit your plots with the command\r\n    \\verb#ylim([0, P0])#.  This same problem will also trigger\r\n    warnings in ode45 about error tolerances; you can safely ignore\r\n    those warnings.}\r\n\r\n\\item Generate a plot showing the population over time, using the same\r\n  initial value used earlier, but using both the $k_1$ value just\r\n  above, and just below the extinction level. (One line should remain\r\n  positive, while the other should crash to zero at some point on the\r\n  graph.)\r\n\r\n\\item Use trial and error (theory isn't much help here) to find the\r\n  maximum sustainable harvest level $k_2$ for the cyclic harvesting\r\n  model (to the nearest integer).  Include a plot showing the\r\n  population over time with this harvesting level.\r\n\r\n\\item Based on your experiments, can constant harvesting or cyclic\r\n  harvesting sustain a greater average harvest in the long run?\r\n  Explain your reasoning.\r\n\\end{enumerate}\r\n  \\end{Question}\r\n\r\n\\begin{Solution}\r\n\\begin{enumerate}[(a)]\r\n\\item  The code in the link below generates the basic graph of the populations over time.  It can be adapted to help answer the later sections.\r\n\r\n  Link to the MATLAB code: \\\\\r\n  \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W09PopulationModel1.m}{W09PopulationModel1.m} \\\\\r\n\r\n\\includegraphics[width=3in]{graphics/Week09_PopulationModels/population_harvesting_1a}\r\n\r\n\\item Through trial and error, we find that there is a transition in\r\n  behaviour between $k_1 = 25$ and $k_1 = 26$.\r\n\\begin{center}\r\n\\includegraphics[width=3in]{graphics/Week09_PopulationModels/population_harvesting_1b}\r\n\\end{center}\r\n\r\nNotice that the \\verb#ylim([0, P0])# line in the script is very\r\nimportant, because once the population $P$ drops below zero, the\r\ndifferential equation solution will keep going down forever.  Here's\r\nthe graph {\\em without} the \\verb#ylim# command:\r\n\\begin{center}\r\n\\includegraphics[width=3in]{graphics/Week09_PopulationModels/population_harvesting_1c}\r\n\\end{center}\r\nNotice the vertical scales shows $10^{13}$, indicating that the\r\nnegative values predicted by the model are huge, and much larger than\r\nthe initial population of $P_0 = 15$.  However, all those negative\r\nvalues are essentially meaningless for populations, so using the\r\n\\verb#ylim# command to focus the attention on the relevant population\r\nrange is a reasonable tactic to make the graphs useful.\r\n\r\n\\item In the seasonal harvest scenario, we experiment with values of\r\n  $k_2$, and find that between $k_2 = 16$ and $k_2 = 17$, we see our\r\n  seasonal pattern stop repeating and start reaching extinction:\r\n\r\n\\begin{center}\r\n\\includegraphics[width=3in]{graphics/Week09_PopulationModels/population_harvesting_1d}\r\n\\end{center}\r\n\r\n\\item Based on these experiments, it seems that seasonal harvesting\r\n  leads to extinction at lower average harvesting levels, because a\r\n  lower average rate of harvest ($k_2$ = 17 thousand fish per year)\r\n  leads to extinction, compared to the constant harvest case (where\r\n  $k_1$ = 26 thousand fish per year can be harvested).\r\n\\end{enumerate}\r\n\\end{Solution}\r\n\r\n% ********************** Tank Systems ****************\r\n\\subsection*{Multi-Tank Systems}\r\n\r\n\\item \\begin{Question}\r\nConsider two interconnected tanks.  Tank A initially contains $100 \\; \\text{L}$\r\nof water and $200 \\; \\text{g}$ of salt, and tank $B$ initially contains $200 \\;\r\n\\text{L}$ of water and $900 \\; \\text{g}$ of salt.  The liquid inside each tank is\r\nkept well stirred.  \r\n\\begin{itemize}\r\n\\item Liquid flows from tank $A$ to tank $B$ at a rate of $3 \\;\r\n\\text{L} \\cdot \\text{min}^{-1}$;\r\n\\item liquid flows from tank $B$ to tank $A$ at rate of $2 \\; \\text{L} \\cdot \\text{min}^{-1}$.  \r\n\\item A salt brine with concentration $7 \\; \\text{g} \\cdot \\text{L}^{-1}$ of salt flows into tank $A$ at a rate of $5 \\; \\text{L} \\cdot \\text{min}^{-1}$; an outflow pipe drains out of the Tank A at $4 \\; \\text{L} \\cdot \\text{min}^{-1}$.  \r\n\\item Moreover, a salt brine with concentration\r\n  $3 \\; \\text{g} \\cdot \\text{L}^{-1}$ of salt flows into tank $B$ at a\r\n  rate of $7 \\; \\text{L} \\cdot \\text{min}^{-1}$; the solution is drained \r\n  out at $8 \\; \\text{L} \\cdot \\text{min}^{-1}$. \r\n\\end{itemize}\r\n\\begin{enumerate}\r\n\\item Draw a diagram for the flows and concentrations in this scenario.\r\n\\item Write a set of differential equations for the {\\bf amount} of\r\n  salt in each tank.\r\n\\item Use MATLAB to simulate the concentration of salt in each tank\r\n  over time.  Generate two separate graphs, one for Tank A and one for\r\n  Tank B, and use the \\verb#title# command to label each one.\r\n\\item Use the solution generated by MATLAB to estimate when Tank B\r\n  reaches its lowest salt amount, and what that lowest amount is.\r\n\\end{enumerate}\r\n  \r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  \\begin{enumerate}\r\n  \\item Here is a diagram with all the information added.\r\n\\begin{center}\r\n\\includegraphics[width=0.6\\linewidth]{graphics/Week09_TankSystems/TankDiagram1}\r\n\\end{center}\r\n\\item   Let $S_A(t)$ and $S_B(t)$ denote the amount (in grams) of salt in tanks $A$\r\n  and $B$ respectively at time $t$ (in minutes).  It follows that\r\n  \\begin{align*}\r\n    \\frac{dS_A}{dt} &= \\text{input rate} - \\text{output rate} = \\left( 7\r\n      \\frac{\\text{g}}{\\text{L}} \\right) \\left( 5 \\frac{\\text{L}}{\\text{min}}\r\n    \\right) + \\left( \\frac{S_B \\; \\text{g}}{200 \\; \\text{L}} \\right) \\left( 2\r\n      \\tfrac{\\text{L}}{\\text{min}} \\right) - \\left( \\frac{S_A \\; \\text{g}}{100\r\n        \\; \\text{L}} \\right) \\left( 4 + 3 \\frac{\\text{L}}{\\text{min}} \\right) \\\\\r\n    &= - \\frac{7}{100} S_A + \\frac{2}{200} S_B + 35 \\\\\r\n    \\frac{dS_B}{dt} &= \\left( 3 \\frac{\\text{g}}{\\text{L}} \\right) \\left( 7\r\n      \\frac{\\text{L}}{\\text{min}} \\right) + \\left( \\frac{S_A \\; \\text{g}}{100 \\;\r\n        \\text{L}} \\right) \\left( 3 \\frac{\\text{L}}{\\text{min}} \\right) - \\left(\r\n      \\frac{S_B \\; \\text{g}}{200 \\; \\text{L}} \\right) \\left( 2+8\r\n      \\tfrac{\\text{L}}{\\text{min}} \\right) \\\\\r\n    &=  \\frac{3}{100} S_A - \\frac{10}{200} S_B + 21 \\, ,\r\n  \\end{align*}\r\n  The coefficients in these expressions could be simplified\r\n  (e.g. $\\frac{10}{200} = \\frac{1}{20} = 0.05$) but keeping the\r\n  origins of each element of the coefficient is sometimes helpful for\r\n  identifying any errors.  E.g. $\\frac{2}{200}S_B$ comes from a flow\r\n  rate of $2$ L/min, a volume of 200 L in Tank B, and the amount of\r\n  salt $S_B$.\r\n\r\n\\item To implement this system of equations in MATLAB, we define a\r\n  vector $\\vec{w} = [S_A, S_B]$, and then write the differential\r\n  equation system in a separate MATLAB function file, here called \\\\\r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/tankSystem1.m}{tankSystem1.m} \r\n\r\nThe main script that sets up the initial conditions and then uses \\verb#ode45# to solve the equations is in \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W09TankSystem1.m}{W09TankSystem1.m} \r\n\r\nThe solution produces the two simulated salt concentrations shown\r\nbelow.\r\n\\begin{center}\r\n\\includegraphics[width=0.45\\linewidth]{graphics/Week09_TankSystems/tank_system_1a} \\hfill\r\n\\includegraphics[width=0.45\\linewidth]{graphics/Week09_TankSystems/tank_system_1b}\r\n\\end{center}\r\n\\item Tank B reaches its minimum salt amount at approximately\r\n  $t = 27-28$ minutes, and has a level of 750 g at that moment.\r\n  \\end{enumerate}\r\n\\end{Solution}\r\n\r\n\r\n%*******************************\r\n\\item\r\n\\begin{Question}\r\n  Consider the 3-tank system shown below.\r\n\\begin{center}\r\n\\includegraphics[width=0.65\\linewidth]{graphics/Week09_TankSystems/TankDiagram2} \r\n\\end{center}\r\n\\begin{enumerate}\r\n\\item Write the set of differential equations that governs the {\\bf\r\n    amount} of salt in each tank, $S_A$, $S_B$ and $S_C$.\r\n\\item Convert your answer from part (a) into a set of differential\r\n  equations for the {\\bf concentrations} in each tank, $C_A$, $C_B$\r\n  and $C_C$.\r\n\\item Using the first line \\\\\r\n  \\verb#function dw_dt = tankSystem2(t, w, k, VA, VB, VC)# and the\r\n  definition that $\\vec{w} = [C_A, C_B, C_C]$ to group the three\r\n  dependent variables, write a MATLAB function file that implements\r\n  the differential equation system from part (b).\r\n\\item Write a script that simulates the changes in concentration over\r\n  time, using the volumes shown in the diagram, a flow rate of $k = 2$\r\n  L/min for each connection, and a time span of 250 minutes.\r\n\r\n\\item Use your knowledge of chemistry to explain the fact that all the\r\n  tanks converge to a common concentration of 2.5 g/L.\r\n\\end{enumerate}\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  \\begin{enumerate}[(a)]\r\n  \\item The differential equations are all based on the ``net rate =\r\n    rate in - rate out''.  The new feature is that {\\bf every}\r\n    concentration will of the form $\\ds \\frac{S}{V}$.\r\n  \\begin{align*}\r\n    \\frac{dS_A}{dt} &  \\left(\\frac{\\text{g}}{\\text{min}} \\right) = \\text{input rate} - \\text{output rate} = \r\n \\left( k \\frac{\\text{L}}{\\text{min}} \\right)\r\n\\left( \\frac{S_C}{V_C} \\frac{\\text{g}}{\\text{L}} \\right) \r\n- \\left( k \\frac{\\text{L}}{\\text{min}} \\right)\r\n\\left( \\frac{S_A}{V_A} \\frac{\\text{g}}{\\text{L}} \\right)  \\\\\r\n& = k \\frac{S_C}{V_C} - k \\frac{S_A}{V_A}  \\\\\r\n    \\frac{dS_B}{dt} &  \\left(\\frac{\\text{g}}{\\text{min}} \\right) = \\text{input rate} - \\text{output rate} = \r\n \\left( k \\frac{\\text{L}}{\\text{min}} \\right)\r\n\\left( \\frac{S_A}{V_A} \\frac{\\text{g}}{\\text{L}} \\right) \r\n- \\left( k \\frac{\\text{L}}{\\text{min}} \\right)\r\n\\left( \\frac{S_B}{V_B} \\frac{\\text{g}}{\\text{L}} \\right)  \\\\\r\n& = k \\frac{S_A}{V_A} - k \\frac{S_B}{V_B}  \\\\\r\n    \\frac{dS_C}{dt} &  \\left(\\frac{\\text{g}}{\\text{min}} \\right) = \\text{input rate} - \\text{output rate} = \r\n \\left( k \\frac{\\text{L}}{\\text{min}} \\right)\r\n\\left( \\frac{S_B}{V_B} \\frac{\\text{g}}{\\text{L}} \\right) \r\n- \\left( k \\frac{\\text{L}}{\\text{min}} \\right)\r\n\\left( \\frac{S_C}{V_C} \\frac{\\text{g}}{\\text{L}} \\right)  \\\\\r\n& = k \\frac{S_B}{V_B} - k \\frac{S_C}{V_C}  \r\n  \\end{align*}\r\n\\item Converting each of these differential equations to concentrations requires building off the two relationships \\\\\r\n$\\ds  C = \\frac{S}{V}$ and $\\ds \\frac{dC}{dt} = \\frac{1}{V} \\frac{dS}{dt}$.\r\n\\begin{align*}\r\n    \\frac{dC_A}{dt} \r\n& = \\frac{1}{V_A} \\frac{dS_A}{dt}\r\n = \\frac{k}{V_A} C_C - \\frac{k}{V_A} C_A \\\\\r\n    \\frac{dC_B}{dt} \r\n& = \\frac{1}{V_B} \\frac{dS_B}{dt}\r\n = \\frac{k}{V_B} C_A - \\frac{k}{V_B} C_B \\\\\r\n    \\frac{dC_C}{dt} \r\n& = \\frac{1}{V_C} \\frac{dS_C}{dt}\r\n = \\frac{k}{V_C} C_B - \\frac{k}{V_C} C_C \r\n\\end{align*}\r\n\r\n\\item You can find the MATLAB function for this simulation at \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/tankSystem2.m}{tankSystem2.m}. \r\n\r\n\\item You can find the MATLAB script that runs the simulation at\r\n  \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W09TankSystem2.m}{W09TankSystem2.m}.\r\n\r\n  Here is the graph of the simulated concentration of salt in the 3\r\n  tanks.\r\n\\begin{center}\r\n\\includegraphics[width=0.65\\linewidth]{graphics/Week09_TankSystems/tank_system_2a} \r\n\\end{center}\r\n\r\n\\item With the continuous mixing, eventually all three tanks will\r\n  reach the same concentration.  We can predict that concentration by\r\n  noting that the only salt is the salt in Tank A at the start.  That\r\n  amount of salt is\r\n  $S_A(0) = C_A(0) V_A = (10 \\text{ g/L})(100 \\text{ L}) = 1000 \\text{\r\n    g}$\r\n\r\n  After all the mixing the 1000 g of salt will be evenly distributed\r\n  over the whole volume which is\r\n  $V_A + V_B + V_C = 100 + 200 + 100 = 400$ L, so a final\r\n  concentration of $ \\ds\\frac{1000 \\text{ g}}{400 \\text{ L}} = 2.5$\r\n  g/L in every tank.\r\n  \\end{enumerate}\r\n\\end{Solution}\r\n\r\n\r\n\r\n\\end{enumerate}\r\n\\end{document}\r\n\r\n", "meta": {"hexsha": "7e0db18d8031b0ef8797299e0f9d531d1950c309", "size": 25711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PracticeProblems/Week09.tex", "max_stars_repo_name": "aableson/MNTCP01", "max_stars_repo_head_hexsha": "1845fe6ac290b008b070f00f1b68856bdbdfc584", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-27T16:10:35.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-27T16:10:35.000Z", "max_issues_repo_path": "PracticeProblems/Week09.tex", "max_issues_repo_name": "aableson/MNTCP01", "max_issues_repo_head_hexsha": "1845fe6ac290b008b070f00f1b68856bdbdfc584", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PracticeProblems/Week09.tex", "max_forks_repo_name": "aableson/MNTCP01", "max_forks_repo_head_hexsha": "1845fe6ac290b008b070f00f1b68856bdbdfc584", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.5042301184, "max_line_length": 239, "alphanum_fraction": 0.6743028276, "num_tokens": 7924, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8991213725394589, "lm_q1q2_score": 0.8133906261657491}}
{"text": "\n\\subsection{Support}\n\n\\subsubsection{Support}\n\nWe define the support of an itemset as the proportion of transactions which contain the itemset.\n\n\\(supp(A)=\\dfrac{\\sum A }{n}\\).\n\nWe can also consider this as:\n\n\\(supp(A)=P(A)\\)\n\t\n\n", "meta": {"hexsha": "64b05aef16c52f49ce02a733debd216a6997a8fb", "size": 230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/association/01-03-support.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/association/01-03-support.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/association/01-03-support.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.3333333333, "max_line_length": 96, "alphanum_fraction": 0.7043478261, "num_tokens": 64, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.8740772450055545, "lm_q1q2_score": 0.8132923851839142}}
{"text": "\n\\subsection{Binary functions}\n\n\\subsubsection{Properties of binary functions}\n\nBinary functions can be written as:\n\n\\(f(a,b)=a\\oplus b\\)\n\nA function is commutative if:\n\n\\(x\\oplus y = y\\oplus x\\)\n\nA function is associative if:\n\n\\((x\\oplus y)\\oplus z = x\\oplus (y\\oplus z)\\)\n\nA function \\(\\otimes \\) is left distributive over \\(\\oplus \\) if:\n\n\\(x\\otimes (y\\oplus z)=(x\\otimes y) \\oplus (x\\otimes z)\\)\n\nAlternatively, function \\(\\otimes \\) is right distributive over \\(\\oplus \\) if:\n\\((x\\oplus y)\\otimes z=(x\\otimes z) \\oplus (y\\oplus z)\\)\n\nA function is distributive over another function if it both left and right distributive over it.\n\n", "meta": {"hexsha": "1709a04d134de00beb17e00fbaba093d9542269b", "size": 637, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/preteriteLogic/01-07-binary.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/preteriteLogic/01-07-binary.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/preteriteLogic/01-07-binary.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5925925926, "max_line_length": 96, "alphanum_fraction": 0.693877551, "num_tokens": 207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9683812318188366, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.813182608188556}}
{"text": "\\section{Geometric interpretation of random variables}\\label{rvs}\n\nIt is fundamental to define the geometric properties of random\nvariables using linear algebra.\n\nConsider the vector space which consists of all random variables with finite\nmean and variance.\nWe will regard each point in this space (or vector that correponds to that point\nin terms of linear algebra) as a random variable.\nWe define the scalar product of two random variables $X$ and $Y$ to be\n\\[\n\\langle X, Y \\rangle = \\Cov(X,Y).\n\\]\nIt is not difficult to check that the definition satisfies the properties\nof a scalar product assuming that $X$ and $Y$ are the same random variables\nif there is a constant $a$ such that $\\P(X = Y + a)=1$.\n\n\\begin{marginfigure}\n\\includegraphics{figures/01_corr_def.pdf}\n\\caption{Geometric representation of random variables.}\n\\label{fig:corr_def}\n\\end{marginfigure}\n\nHaving defined the scalar product, we are now able to introduce the squared\nlength of a random variable $X$ which is\n\\[\n\\lVert X \\rVert^2 = \\langle X, X \\rangle = \\Cov(X,X) = \\Var(X),\n\\]\nso the~standard\ndeviation of $X$ ($\\sigma_X$) is the length.\n\nRecall that for any non-random vectors $a$ and $b$ the angle\nbetween them is calculated with the formula\n\\[\n\\cos(a, b) = \\frac{\\langle a,  a\\rangle}{|a| |b|}.\n\\]\nThe same applies for the random variables and it is already clear that\ntwo random variables are uncorrelated iff their scalar product\nequals $0$. Additionally, it means that these two random variables\nare orthogonal in the vector space.\n\nThe analogue for $\\cos(a, b)$ in the vector space of all the random\nvariables is the correlation between two of them:\n\\[\n\\Corr(X,Y) = \\frac{\\Cov(X,Y)}{\\sqrt{\\Var(X)\\Var(Y)}} = \\frac{\\langle X, Y \\rangle}{\\sqrt{\\lVert X \\rVert^2 \\lVert Y \\rVert^2}}.\n\\]\nFrom the equivalence of $\\Corr(X,Y)$ to $\\cos(a, b)$ it\nautomatically follows that the correlation coefficient can range from $-1$ to $1$.\n\n% proofreaded up to this line\n\n\\begin{marginfigure}[10\\baselineskip]\n\\includegraphics{figures/01_pythagorean_theorem.pdf}\n\\caption{The Pythagorean theorem for random variables $X$ and $Y$.}\n\\label{fig:rv_pyth}\n\\end{marginfigure}\n\nA useful property of the geoemtry of random variables is that all the\ngeometric theorems still hold. For instance, the Pythagorean theorem can\nbe formulated as follows: if the ranadom variables $X$ and $Y$ are uncorrelated\n(which implies that they are orthogonal), then the variance of their sum equals\nthe sum of their variances:\n\\[\n\\Var(X + Y) = \\sigma^2_{X+Y} = \\sigma^2_{X} + \\sigma^2_{Y} = \\Var(X) + \\Var(Y).\n\\]\nTranslated to the non-random language, assumption of uncorrelatedness correspnds\nto the right triangle setting, the variance of the sum of two random variables\nstands for the hypotenuse squared and the sum of the variances is the sum of\nthe legs squared.\n\nAnother important geometric tool is projection.\nRecall that for any two vectors the scalar product $\\langle a, b \\rangle$\ncan be interpreted as the length of projected $b$ multiplied by the length of $a$.\nThe projection itself is $\\cos(a, b) b$.\nSame holds for the random variables.\nThe projection of such a random variable $Y$ onto $\\{cX| c \\in \\mathbb{R}\\}$ is\n$\\hat Y = \\Corr(X,Y) \\cdot Y$.\n\n\\begin{marginfigure}\n\\includegraphics{figures/01_basic_projection.pdf}\n\\caption{The projection of a random variable $Y$ onto the line spanned by\na random variable $X$.}\n\\label{fig:rv_proj}\n\\end{marginfigure}\n\nNote that the squared lengths of the leg adjacent to $\\varphi$ and the\nhypotenuse are $\\Var(\\hat Y)$ and $\\Var(Y)$.\nSo, the Figure~\\ref{fig:rv_proj} gives a useful expression for the correlation\ncoefficient squared:\n\\[\n\\Corr^2(X,Y) = \\frac{\\Var(\\hat Y)}{\\Var(Y)}.\n\\]\n\n\\subsection{The law of iterated expectations}\n\n\\marginnote{\nHere is the proof for the case when $X$ and $Y$ are both discrete. Let $\\E(Y|X) = g(X)$.\n\\begin{align*}\n&\\E(g(X)) = \\sum_x g(x) \\P(X=x) \\\\\n&= \\sum_x \\left( \\sum_y y \\P(Y=y|X=x) \\right) \\P(X=x) \\\\\n&= \\sum_x \\sum_y y  \\P(X=x) \\P(Y=y|X=x)  \\\\\n&= \\sum_y y \\sum_x \\P(X=x, Y=y) \\\\\n&= \\sum_y y \\P(Y=y) = \\E(Y)\n\\end{align*}\nThe proof in case of continous random variables is absolutely analogous.\n}\n\n\\begin{theorem}\nFor any random variable $X$ and $Y$,\n\\[\n\\E(\\E(Y|X)) = \\E(Y).\n\\]\n\\end{theorem}\n\n\\begin{proof}\n\nConsider a vector space of all the random variables.  The random variables\nwhich can be described as functions of $X$ form a subspace of that vector\nspace, represented as a plane $\\alpha$ in Figure~\\ref{fig:adams}.\nAnother subspace is a subspace of constants, denoted as a vector $\\mathbf{1} \\in \\alpha$.\n\nIn order to obtain $\\E(Y|X)$, first, we need to project $Y$ onto the subspace\nof all the functions of $X$. As a result of this step, we get $\\E(Y|X)$ \u2014 the function\nof $X$ that predicts $Y$ the best (the function which gives the lowest MSE).\nNext, projecting $\\E(Y|X)$ onto the space of all constants, we obtain $E(Y)$.\n\nNotice that the vector $Y - \\E(Y|X)$ (which is also called the residual) is\nperpendicular to the plane $\\alpha$. Particularly, the vecotr $\\E(Y|X) - E(Y)$ is\nperpendicular to the vector of constants $\\mathbf{1}$. Thus, we can apply\nthe theorem of three perpendiculars and conclude that the vector $Y - \\E(Y)$ is\nalso perpendicular to the vector of constants $\\mathbf{1}$.\n\nSo, we showed that the expectation of the random variable $Y$ can be obtained either\nin two steps or by its direct projection onto the subpace of constans.\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[width=0.6\\linewidth]{figures/01_law_of_iterated_expectations.pdf}\n\\caption{The law of iterated expectations. Equivalence of the two-step projecttion\nand direct projection of $Y$ onto $\\mathbf{1}$.}\n\\label{fig:adams}\n\\end{center}\n\\end{figure}\n\n\\end{proof}\n\n\n\\subsection{MSE decomposition}\n\n\\begin{theorem}\nThe mean squared error of an estimator $\\hat \\theta$ with respect to an unknown\nparameter $\\theta$ defined as $MSE(\\hat \\theta) = \\E((\\hat \\theta - \\theta)^2)$\ncan be decomposed into the sum of the variance of the estimator and its squared bias:\n\\[\nMSE(\\hat \\theta) = \\Var(\\hat \\theta) + \\E \\left[\\left( \\E(\\hat \\theta) - \\theta  \\right)^2 \\right]\n\\]\n\\end{theorem}\n\n\\marginnote{\n\\begin{align*}\n&MSE(\\hat \\theta) = \\E((\\hat \\theta - \\theta)^2) \\\\\n&= \\E \\left[ \\left( \\hat \\theta - \\E(\\hat \\theta) +  \\E(\\hat \\theta) - \\theta \\right)^2 \\right] \\\\\n&= \\E \\left[ \\left( \\hat \\theta - \\E(\\hat \\theta) \\right)^2 + 2  (\\hat \\theta - \\E(\\hat \\theta)) (\\E(\\hat \\theta) - \\theta )  \\right. \\\\\n&+ \\left. \\left( \\E(\\hat \\theta) - \\theta  \\right)^2 \\right] \\\\\n&= \\E \\left[\\left( \\hat \\theta - \\E(\\hat \\theta) \\right)^2 \\right] + 2 \\E (\\hat \\theta - \\E(\\hat \\theta)) (\\E(\\hat \\theta) - \\theta ) \\\\\n&+ \\E \\left[\\left( \\E(\\hat \\theta) - \\theta  \\right)^2 \\right] \\\\\n&= \\E \\left[\\left( \\hat \\theta - \\E(\\hat \\theta) \\right)^2 \\right] \\\\\n&+ 2 \\E(\\hat \\theta - \\E(\\hat \\theta)) \\E(\\hat \\theta - \\E(\\hat \\theta)) \\\\\n&+ \\E \\left[\\left( \\E(\\hat \\theta) - \\theta  \\right)^2 \\right] \\\\\n&= \\E \\left[\\left( \\hat \\theta - \\E(\\hat \\theta) \\right)^2 \\right] + \\E \\left[\\left( \\E(\\hat \\theta) - \\theta  \\right)^2 \\right] \\\\\n&= \\Var(\\hat \\theta) + \\E \\left[\\left( \\E(\\hat \\theta) - \\theta  \\right)^2 \\right]\n\\end{align*}\n}\n\n\\begin{proof}\nWe start with a random variable $\\theta$ and its estimate $\\hat \\theta$ in the\nvector space. We know that an unbiased estimator's projection would be exactly\nthe vector representing $\\theta$. However, in general it does not have to and\nFigure~\\ref{fig:mse_decomposed} illustrates this case: the projection of the estimator falls onto\nthe line spanned by the vector $\\theta$.\n\nConnecting vectors $\\theta$ and $\\hat \\theta$, we obtain the right triangle which\nlegs are $\\hat \\theta - \\E(\\hat\\theta)$, $\\E(\\hat\\theta) - \\theta$ and the\nhypotenuse $\\hat \\theta - \\theta$.\nApplying the Pythagorean theorem, we finish the proof:\n\\begin{align*}\n\\lVert \\hat \\theta - \\theta \\rVert^2 &= \\lVert \\hat \\theta - \\E(\\hat \\theta) \\rVert^2  + \\lVert \\E(\\hat \\theta) - \\theta \\rVert^2 \\\\\n\\E((\\hat \\theta - \\theta)^2) &= \\E((\\hat \\theta - \\E(\\hat \\theta))^2) + \\E((\\E(\\hat \\theta) - \\theta)^2) \\\\\nMSE(\\hat \\theta) &= \\Var(\\hat \\theta) + \\E((\\E(\\hat \\theta) - \\theta)^2)\n\\end{align*}\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[width=0.6\\linewidth]{figures/01_mse_decomposition.pdf}\n\\caption{Decomposition of mean squred error into the variance and the bias squared\n$\\left(a = \\sqrt{\\lVert\\hat\\theta - \\E(\\hat\\theta)\\rVert^2} \\right.$, $b = \\sqrt{\\lVert \\theta - \\E(\\hat\\theta) \\rVert^2}$, $\\left. c = \\sqrt{\\lVert \\hat\\theta - \\theta \\rVert^2} \\right)$}\n\\label{fig:mse_decomposed}\n\\setfloatalignment{b}\n\\end{center}\n\\end{figure}\n\n\\end{proof}\n", "meta": {"hexsha": "1833a3c1a857551f347443615cbe4211b1591a68", "size": 8597, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/1_random_variables.tex", "max_stars_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_stars_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-22T20:38:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:38:41.000Z", "max_issues_repo_path": "chapters/1_random_variables.tex", "max_issues_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_issues_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-06-29T09:11:36.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-28T19:35:55.000Z", "max_forks_repo_path": "chapters/1_random_variables.tex", "max_forks_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_forks_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-05-21T18:32:18.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-21T18:32:18.000Z", "avg_line_length": 42.3497536946, "max_line_length": 188, "alphanum_fraction": 0.6941956496, "num_tokens": 2681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8887587875995483, "lm_q1q2_score": 0.8131262676576485}}
{"text": "\\subsubsection{Curl \\& Conservative Vector Fields}\r\n\\begin{theorem}\r\n\t$\\vec{F}$ is conservative $\\Leftrightarrow\\nabla\\times\\vec{F} = \\vec{0}$\r\n\\end{theorem}\r\n\\begin{proof}[Partial Proof]\r\n\tWe will prove the 2D case and provide intuition for higher dimensions.\\\\\r\n\tLet $\\vec{F}(x,y) = \\langle P(x,y), Q(x,y)\\rangle$ be a conservative vector field.\\\\\r\n\tSince $\\vec{F}$ is conservative, $P_y = Q_x$.\\\\\r\n\tSo, $\\nabla \\times \\vec{F}=Q_x-P_y=0$.\r\n\\end{proof}\r\n\r\n\\noindent\r\nThinking back to what it means for a vector field to be conservative, a vector field must have path independence between all points to have a potential function and be conservative. If in some plane there is a net rotation, there cannot be path independence because one can choose one path that goes \u201cwith\u201d the field and another that goes \u201cagainst\u201d the field.\r\n\r\n[INSERT IMAGE]", "meta": {"hexsha": "299764e81746948134160377f6fbf02625a68921", "size": 845, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/curlConservativeVFs.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorAnalysis/curlConservativeVFs.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorAnalysis/curlConservativeVFs.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 56.3333333333, "max_line_length": 360, "alphanum_fraction": 0.7266272189, "num_tokens": 233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.945801271704518, "lm_q2_score": 0.8596637505099167, "lm_q1q2_score": 0.8130710684705548}}
{"text": "\\documentclass{article}\n\n\\input{../homework.sty}\n\n\\title{Homework 1}\n\\author{Austin Gill}\n\n\\begin{document}\n\\maketitle\n\n\\section*{The Fibonacci Bug}\n    It's really hard to parallelize when the sequence definition is a recurrence relation. There is a strong dependence of the $n$th term on the $(n-1)$th and $(n-2)$th terms. This doesn't parallelize because there is an inherent order requirement, essentially forcing a sequential execution.\n\n    Now, there \\textit{is} a way to make the code parallel.\n\n   \\begin{quote}\n       Given a homogeneous linear recurrence relation with constant coefficients (a discrete case of a differential equation)\n\n       \\[ a_0 x(n) + a_1 x(n - 1) + a_2 x(n - 2) + \\cdots + a_m x(n - m) = 0 \\]\n\n       We assume a solution of the form $x(n) = C\\lambda^n$ and substitute:\n\n       \\[ a_0 C\\lambda^n + a_1 C \\lambda^{n - 1} + \\cdots + a_m C \\lambda^{n - m} = 0 \\]\n       \\[ a_0 \\lambda^n + a_1 \\lambda^{n - 1} + \\cdots + a_m \\lambda^{n - m} = 0 \\]\n       \\[ \\lambda^{n - m} \\underbrace{( a_0 \\lambda^m + a_1 \\lambda^{m - 1} + \\cdots + a_m \\lambda^0 )}_{\\text{Characteristic equation with roots as solutions}} = 0 \\]\n\n       In the case of no repeated roots, we have\n\n       \\[ x(n) = c_1 \\lambda_1^n + c_2 \\lambda_2^n + \\cdots + c_m \\lambda_m^n \\]\n\n       where each $\\lambda_i$ is an eigenvalue, and each $c_i$ is found from the initial conditions. We say that the dominant eigenvalue is the eigenvalue with the greatest absolute value.\n\n       \\[ \\lambda_d = \\max_i\\{ \\vert \\lambda_i \\vert \\} \\]\n   \\end{quote}\n\n   Now returning to the Fibonacci sequence, a second order recurrence relation (requiring two initial conditions to solve)\n\n   \\[ x(n) - x(n - 1) - x(n - 2) = 0 \\]\n   \\[ x(n) = C\\lambda^n \\rightsquigarrow C\\lambda^n - C \\lambda^{n - 1} - C\\lambda^{n - 2} = 0 \\]\n\n   Factoring out $C\\lambda^{n - 2}$ gives us the characteristic equation\n\n   \\[ \\lambda^2 - \\lambda - 1 = 0 \\]\n\n   which has roots\n\n   \\[ \\lambda = \\frac{1 \\pm \\sqrt{1 - 4(-1)(1)}}{2} = \\frac{1 \\pm \\sqrt{5}}{2} \\]\n\n   where $\\frac{1 + \\sqrt{5}}{2}$, a.k.a., the golden ratio $\\phi$, is the dominant eigenvalue. So then the recurrence relation has the solution\n\n   \\[ x(n) = c_1 {\\left(\\frac{1 + \\sqrt{5}}{2}\\right)}^n + c_2 {\\left(\\frac{1 - \\sqrt{5}}{2}\\right)}^n \\]\n\n   where we solve for $c_1$ and $c_2$ using the initial conditions $x(0) = 1$ and $x(1) = 1$.\n\n   \\[ x(0) = 1 = c_1 + c_2 \\]\n   \\[ x(1) = 1 = c_1 \\left( \\frac{1 + \\sqrt{5}}{2} \\right) + c_2 \\left( \\frac{1 - \\sqrt{5}}{2} \\right) \\]\n\n   which gives $c_1 = \\frac{1}{\\sqrt{5}}$ and $c_2 = - \\frac{1}{\\sqrt{5}}$.\n\n   So all together then, the closed form solution of the homogeneous Fibonacci linear recurrence relation is\n\n   \\[x(n) = \\frac{1}{\\sqrt{5}} \\left( {\\left( \\frac{1 + \\sqrt{5}}{2} \\right)}^n - {\\left( \\frac{1 - \\sqrt{5}}{2} \\right)}^n \\right)\\]\n\n   Note that this closed form has no history dependence, so it \\textit{will} parallelize quite nicely, ignoring the increased number of floating point operations required to compute each $x(n)$ value.\n\n\n\\section{}\n    \\begin{quote}\n        Recall that OpenMP creates private variables for reduction variables, and these private variables are initialized to the identity element for the reduction operator. For example, if the operator is addition, the private variables are initialized to 0, while if the operator is multiplication, the private variables are initialized to 1.\n\n        What are the identity values for these operators: \\mintinline{c}{&&}, \\mintinline{c}{||}, \\mintinline{c}{|}, and \\mintinline{c}{^}?\n    \\end{quote}\n\n    The mathematical identity for $\\land$ is $T$, because $x \\land T \\equiv x$, thus the identity for the \\mintinline{c}{&&} operator is \\mintinline{cpp}{true}. Similarly, the identity for the \\mintinline{c}{||} operator is \\mintinline{cpp}{false}. The identities for the bitwise operations \\mintinline{c}{|} and \\mintinline{c}{^} are both \\mintinline{c}{0x0}.\n\n\\section{}\n    \\begin{quote}\n        Suppose OpenMP did not have the \\mintinline{c}{reduction} clause. Show how to implement an \\textit{efficient} parallel reduction by adding a private variable and using the \\mintinline{c}{critical} pragma.\n    \\end{quote}\n\n    Consider the following three solutions.\n\n    \\begin{enumerate}\n        \\item Normal reduction: \\begin{minted}{c}\n            size_t sum1 = 0;\n            #pragma omp parallel for num_threads( 8 ) reduction(+:sum1)\n            for( size_t i = 0; i < n; ++i )\n            {\n                sum1 += i;\n            }\n        \\end{minted}\n\n        \\item Naive reduction, which is even worse than sequential: \\begin{minted}{c}\n            size_t sum2 = 0;\n            size_t local_sum = 0;\n            #pragma omp parallel for num_threads( 8 ) private( local_sum )\n            for( size_t i = 0; i < n; ++i )\n            {\n                local_sum = i;\n\n                // This is wrong. It's essentially sequential with a lot of overhead.\n                #pragma omp critical\n                sum2 += local_sum;\n            }\n        \\end{minted}\n\n        \\item Better reduction, which performs slightly \\textit{better} than using \\mintinline{c}{reduction}: \\begin{minted}{c}\n            size_t sum3 = 0;\n            #pragma omp parallel num_threads( 8 )\n            {\n                size_t local_sum = 0;\n                #pragma omp for\n                for(size_t i = 0; i < n; ++i )\n                {\n                    local_sum += i;\n                }\n\n                #pragma omp critical\n                sum3 += local_sum;\n            }\n        \\end{minted}\n    \\end{enumerate}\n\n    All together, with timing code and \\mintinline{c}{n = 1000000} we get the following results.\n\n    \\begin{minted}{text}\n        reduced sum:  499999500000\n        elapsed time: 13.664000ms\n        naive sum:    499999500000\n        elapsed time: 76.582000ms\n        critical sum: 499999500000\n        elapsed time: 0.291000ms\n    \\end{minted}\n\n\\section{}\n    \\begin{quote}\n        For each of the following code segments, use OpenMP pragmas to make the loop parallel, or explain why the code segment is not suitable for parallel execution.\n\n        % \\begin{enumerate}\n        %     \\item \\begin{minted}{c}\n        %         for(i = 0; i < (int) sqrt(x); i++)\n        %         {\n        %             a[i] = 2.3 * i;\n        %             if(i < 10)\n        %                 b[i] = a[i];\n        %         }\n        %     \\end{minted}\n\n        %     \\item \\begin{minted}{c}\n        %         flag = 0;\n        %         for(i = 0; i < n && !flag; i++)\n        %         {\n        %             a[i] = 2.3 * i;\n        %             if(a[i] < b[i])\n        %                 flag = 1;\n        %         }\n        %     \\end{minted}\n\n        %     \\item \\begin{minted}{c}\n        %         for(i = 0; i < n; i++)\n        %         {\n        %             a[i] = foo(i);\n        %         }\n        %     \\end{minted}\n\n        %     \\item \\begin{minted}{c}\n        %         for(i = 0; i < n; i++)\n        %         {\n        %             a[i] = foo(i);\n        %             if(a[i] > b[i])\n        %                 a[i] = b[i];\n        %         }\n        %     \\end{minted}\n\n        %     \\item \\begin{minted}{c}\n        %         for(i = 0; i < n; i++)\n        %         {\n        %             a[i] = foo(i);\n        %             if(a[i] < b[i])\n        %                 break;\n        %         }\n        %     \\end{minted}\n\n        %     \\item \\begin{minted}{c}\n        %         dotp = 0;\n        %         for(i = 0; i < n; i++)\n        %         {\n        %             dotp += a[i] * b[i];\n        %         }\n        %     \\end{minted}\n\n        %     \\item \\begin{minted}{c}\n        %         for(i = k; i < 2 * k; i++)\n        %         {\n        %             a[i] = a[i] + a[i-k];\n        %         }\n        %     \\end{minted}\n\n        %     \\item \\begin{minted}{c}\n        %         for(i = k; i < n; i++)\n        %         {\n        %             a[i] = b * a[i - k];\n        %         }\n        %     \\end{minted}\n        % \\end{enumerate}\n    \\end{quote}\n\n    \\begin{enumerate}\n        \\item \\begin{minted}{c}\n            #pragma omp parallel for num_threads( 8 )\n            for(i = 0; i < (int) sqrt(x); i++)\n            {\n                a[i] = 2.3 * i;\n                if(i < 10)\n                    b[i] = a[i];\n            }\n        \\end{minted}\n\n        \\item Cannot use OpenMP to parallelize because the loop is not fixed in size.\n        \\begin{minted}{text}\n            prob3.c: In function \u2018main\u2019:\n            prob3.c:50:23: error: invalid controlling predicate\n                 for(size_t i = 0; i < 9 && !flag; i++)\n                                   ^\n        \\end{minted}\n\n        \\item \\begin{minted}{c}\n            #pragma omp parallel for num_threads( 8 )\n            for(i = 0; i < n; i++)\n            {\n                a[i] = foo(i);\n            }\n        \\end{minted}\n\n        \\item \\begin{minted}{c}\n            #pragma omp parallel for num_threads( 8 )\n            for(i = 0; i < n; i++)\n            {\n                a[i] = foo(i);\n                if(a[i] > b[i])\n                    a[i] = b[i];\n            }\n        \\end{minted}\n\n        \\item Cannot use OpenMP to parallelize because the loop is not fixed in size.\n\n        \\item \\begin{minted}{c}\n            dotp = 0;\n            #pragma omp parallel for num_threads( 8 ) reduce(+: dotp)\n            for(i = 0; i < n; i++)\n            {\n                dotp += a[i] * b[i];\n            }\n        \\end{minted}\n\n        \\item Cannot parallelize because you cannot easily guarantee \\mintinline{c}{a[i - k]} will be properly computed \\textit{before} \\mintinline{c}{a[i]}, as in the Fibonacci sequence assigned over the weekend. Since \\mintinline{c}{k} is fixed, there might be a way to force the loop division over the threads to play nicely, but this would be too much work for too little reward, and would have the added benefit of confusing the hell out of anyone who tried to understand your code.\n\n        \\item Same as above.\n    \\end{enumerate}\n\n\\section{}\n    \\begin{quote}\n        Given a task that can be divided into $m$ subtasks, each requiring one unit of time, how much time is needed for an $m$-stage pipeline to process $n$ tasks?\n    \\end{quote}\n\n    Assuming that each task is broken into $m$ strictly ordered sequential subtasks, we have a few choices. You can use $n$ workers, each performing the full task. Then the amount of time will be on the order of however long it takes to complete a single task. However, this doesn't scale well; we normally have more tasks than each task has subtasks.\n\n    We can use $m$ workers, each performing a single sub task in an offset manner so that worker 1 completes subtask 1 for task 1 and begins subtask 1 for task 2 as worker 2 begins subtask 2 for task 1 and so on. This will complete in $\\sim \\mathcal O(n)$ time.\n\n    We can use $jm$ workers and have $j$ copies of the pipeline running side-by-side. This also completes in $\\sim \\mathcal O(n)$ time.\n\n\\section{}\n    \\begin{quote}\n        If the address of the nodes in a hypercube has $n$ bits, at most how many nodes can there be, and how many edges does each node have?\n\n        Give an algorithm that routes a message from node $u$ to node $v$ in this $k$-node hypercube in no more than $\\log k$ steps.\n    \\end{quote}\n\n    There will be $2^n$ nodes with $n$ edges per node.\n\n    \\begin{minted}{python}\n        intermediate_address = u\n        # Iterate over the bits of the address.\n        for i, u_b, v_b in enumerate(zip(u, v)):\n            # Flip the differing bits of the src address one-by-one\n            if u_b != v_b:\n                intermediate_address[i] = v_b\n                mailman.send(msg, intermediate_address)\n    \\end{minted}\n\n\\section{}\n    \\begin{quote}\n        Research the \\textit{shuffle-exchange} network topology. Draw the network with 16 processor nodes (numbering each node in binary, showing shuffle and exchange links). If there are $k$ bits in the address, how many nodes are there? With $n$ nodes, what is the diameter and bisection width of the network? How many edges per node are there?\n    \\end{quote}\n\n    In a shuffle-exchange network with $2^n$ nodes addressed with $n$ bit addresses, there is a directed edge between two nodes if one of the following holds.\n\n    \\begin{description}\n        \\item[shuffle] One address is a 1-bit cyclic left shift of the other. This forms a directed shuffle edge.\n        \\item[exchange] The addresses differ only in the last bit. This forms a directed exchange edge.\n    \\end{description}\n\n    Each node has two outgoing edges and two incoming edges, one each of shuffle and exchange. The network has a bisection width of $2^{n - 1}$ and a diameter of $2n - 1$.\n\n    So the 4 node network shown in~\\autoref{fig:shuffle4}.\n\n    \\begin{figure}\n        \\centering\n        \\begin{tikzpicture}[>=stealth, node distance=2cm]\n            \\tikzset{vertex/.style = {shape=circle, draw, minimum size=1em}}\n\n            \\node[vertex] (00) {$00$};\n            \\node[vertex, right of=00] (01) {$01$};\n            \\node[vertex, right of=01] (10) {$10$};\n            \\node[vertex, right of=10] (11) {$11$};\n\n            \\draw[->, loop left] (00) edge node[left]{S} (00);\n            \\draw[->, loop right] (11) edge node[right]{S} (11);\n\n            \\draw[->, bend left] (01) edge node[above]{S} (10);\n            \\draw[->, bend left] (10) edge node[below]{S} (01);\n\n            \\draw[->, bend left] (00) edge node[above]{E} (01);\n            \\draw[->, bend left] (01) edge node[below]{E} (00);\n\n            \\draw[->, bend left] (10) edge node[above]{E} (11);\n            \\draw[->, bend left] (11) edge node[below]{E} (10);\n        \\end{tikzpicture}\n        \\caption{A 4 node (2 bit) shuffle-exchange network}\\label{fig:shuffle4}\n    \\end{figure}\n\n    Now consider the following Python script \\inputminted{python}{prob6.py}\n\n    which produces, in part the network shown in~\\autoref{fig:shuffle16}.\n\n    \\afterpage{%\n    \\thispagestyle{empty}\n    \\newgeometry{margin=0cm}\n    \\begin{figure}\n        \\centering\n        \\begin{tikzpicture}[>=stealth, node distance=1.4cm]\n            \\tikzset{vertex/.style = {shape=circle, draw, minimum size=1em}}\n\n            \\node[vertex] (0000) {$0000$};\n            \\node[vertex, below of=0000] (0001) {$0001$};\n            \\node[vertex, below of=0001] (0010) {$0010$};\n            \\node[vertex, below of=0010] (0011) {$0011$};\n\n            \\node[vertex, below of=0011] (0100) {$0100$};\n            \\node[vertex, below of=0100] (0101) {$0101$};\n            \\node[vertex, below of=0101] (0110) {$0110$};\n            \\node[vertex, below of=0110] (0111) {$0111$};\n\n            \\node[vertex, below of=0111] (1000) {$1000$};\n            \\node[vertex, below of=1000] (1001) {$1001$};\n            \\node[vertex, below of=1001] (1010) {$1010$};\n            \\node[vertex, below of=1010] (1011) {$1011$};\n\n            \\node[vertex, below of=1011] (1100) {$1100$};\n            \\node[vertex, below of=1100] (1101) {$1101$};\n            \\node[vertex, below of=1101] (1110) {$1110$};\n            \\node[vertex, below of=1110] (1111) {$1111$};\n\n            \\draw[->, color=blue!70, bend left] (0000) edge (0001);\n            \\draw[->, color=blue!70, bend left] (0001) edge (0000);\n            \\draw[->, color=blue!70, bend left] (0010) edge (0011);\n            \\draw[->, color=blue!70, bend left] (0011) edge (0010);\n            \\draw[->, color=blue!70, bend left] (0100) edge (0101);\n            \\draw[->, color=blue!70, bend left] (0101) edge (0100);\n            \\draw[->, color=blue!70, bend left] (0110) edge (0111);\n            \\draw[->, color=blue!70, bend left] (0111) edge (0110);\n            \\draw[->, color=blue!70, bend left] (1000) edge (1001);\n            \\draw[->, color=blue!70, bend left] (1001) edge (1000);\n            \\draw[->, color=blue!70, bend left] (1010) edge (1011);\n            \\draw[->, color=blue!70, bend left] (1011) edge (1010);\n            \\draw[->, color=blue!70, bend left] (1100) edge (1101);\n            \\draw[->, color=blue!70, bend left] (1101) edge (1100);\n            \\draw[->, color=blue!70, bend left] (1110) edge (1111);\n            \\draw[->, color=blue!70, bend left] (1111) edge (1110);\n\n            \\draw[->, color=red!70, loop above] (0000) edge (0000);\n            \\draw[->, color=red!70, bend left=45] (0001) edge (0010);\n            \\draw[->, color=red!70, bend left=45] (0010) edge (0100);\n            \\draw[->, color=red!70, bend left=45] (0011) edge (0110);\n            \\draw[->, color=red!70, bend left=45] (0100) edge (1000);\n            \\draw[->, color=red!70, bend left=45] (0101) edge (1010);\n            \\draw[->, color=red!70, bend left=45] (0110) edge (1100);\n            \\draw[->, color=red!70, bend left=45] (0111) edge (1110);\n            \\draw[->, color=red!70, bend left=45] (1000) edge (0001);\n            \\draw[->, color=red!70, bend left=45] (1001) edge (0011);\n            \\draw[->, color=red!70, bend left=45] (1010) edge (0101);\n            \\draw[->, color=red!70, bend left=45] (1011) edge (0111);\n            \\draw[->, color=red!70, bend left=45] (1100) edge (1001);\n            \\draw[->, color=red!70, bend left=45] (1101) edge (1011);\n            \\draw[->, color=red!70, bend left=45] (1110) edge (1101);\n            \\draw[->, color=red!70, loop below] (1111) edge (1111);\n        \\end{tikzpicture}\n        \\caption{A 16 node (4-bit) {\\color{red!70}shuffle}-{\\color{blue!70}exchange} network}\\label{fig:shuffle16}\n    \\end{figure}\n    \\restoregeometry{}\n    } % end afterpage\n\n\\end{document}\n", "meta": {"hexsha": "2d76d849fd4572c4bfc368b78c1014f34056995f", "size": 17542, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "homework/hw1/hw1.tex", "max_stars_repo_name": "Notgnoshi/parallel", "max_stars_repo_head_hexsha": "4fce05ac90682f7daa9986dcdb82c9df24e42c74", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "homework/hw1/hw1.tex", "max_issues_repo_name": "Notgnoshi/parallel", "max_issues_repo_head_hexsha": "4fce05ac90682f7daa9986dcdb82c9df24e42c74", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "homework/hw1/hw1.tex", "max_forks_repo_name": "Notgnoshi/parallel", "max_forks_repo_head_hexsha": "4fce05ac90682f7daa9986dcdb82c9df24e42c74", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.4207920792, "max_line_length": 487, "alphanum_fraction": 0.5455478281, "num_tokens": 5232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.9086179018818865, "lm_q1q2_score": 0.8130217196683718}}
{"text": "\n\\subsection{Singular value decomposition}\n\nThe singular value decomposition of \\(m\\times n\\) matrix \\(M\\) is:\n\n\\(M=U\\Sigma V^* \\)\n\nWhere:\n\n\\begin{itemize}\n\\item \\(U\\) is a unitary matrix (\\(m\\times m\\))\n\\item \\(\\Sigma \\) is a diagonal matrix with non-negative real numbers (\\(m\\times n\\))\n\\item \\(V\\) is a unitary matrix (\\(n\\times n\\))\n\\end{itemize}\n\n\\(\\Sigma \\) is unique. \\(U\\) and \\(V\\) are not.\n\n\\subsubsection{Properties}\n\n\\(M^*M=U\\Sigma^2 U^*\\)\n\n\\((M^*M)^{-1}=V\\Sigma^{-2} V^*\\)\n\n\\subsubsection{Calculating the SVD}\n\nThe SVD is generally calculated iteratively.\n\n", "meta": {"hexsha": "2e83949a2f077dbef820729f6ebd56d57dadd778", "size": 571, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/maps/01-05-SVD.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/maps/01-05-SVD.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/maps/01-05-SVD.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.3928571429, "max_line_length": 85, "alphanum_fraction": 0.646234676, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.8633916029436189, "lm_q1q2_score": 0.8130162926791001}}
{"text": "\\section{Data Clustering \\& Mixture Models}\n\\subsection*{KMeans}\n% ZT?\n\\textbf{Target:} $\\min_{\\mathbf{U}, \\mathbf{Z}} J(\\mathbf{U}, \\mathbf{Z}) = \\|\\mathbf{X} - \\mathbf{U} \\mathbf{Z}\\|_F^2$\\\\\n$= \\sum_{n=1}^N \\sum_{k=1}^K \\mathbf{z}_{k,n} \\|\\mathbf{x}_n - \\mathbf{u}_k\\|_2^2$\\\\\n1. \\textbf{Initiate:} choose $K$ centroids $\\mathbf{U} = [\\mathbf{u}_1, \\ldots, \\mathbf{u}_K]$\\\\\n2. \\textbf{Cluster Assign:} data points to clusters. $k^\\star(\\mathbf{x}_n) = \\argmin_k \\{ \\|\\mathbf{x}_n - \\mathbf{u}_k\\|_2 \\}$ returns cluster $k^\\star$, whose centroid $\\mathbf{u}_{k^\\star}$ is closest to data point $\\mathbf{x}_n$. Set $\\mathbf{z}_{k^\\star,n} = 1$, and for $ l \\neq k^\\star~ \\mathbf{z}_{l,n}=0$.\\\\\n3. \\textbf{Update centroids}: $\\mathbf{u}_k = \\frac{\\sum_{n=1}^N z_{k,n} \\mathbf{x}_n}{\\sum_{n=1}^N z_{k,n}}$.\\\\\n4. Repeat from step 2, stops if $\\|\\mathbf{Z} - \\mathbf{Z}^\\text{new}\\|_0 = \\|\\mathbf{Z} - \\mathbf{Z}^\\text{new}\\|^2_F = 0$.\\\\\nComputational cost: $O(k\\cdot n \\cdot d)$\n\n\n\\subsection*{Gaussian Mixture Models (GMM)}\nGaussian $p(x)=\\frac{1}{\\sqrt{2\\pi}\\sigma}\\mathit{exp}(-\\frac{(x-\\mu)^2}{2\\sigma^2})$\nMultivariate $p(x;\\mu;\\Sigma)=\\frac{1}{|\\Sigma|^{\\frac{1}{2}}(2\\pi)^{\\frac{D}{2}}}\\mathit{exp}[-\\frac{1}{2}(x-\\mu)^T \\Sigma^{-1} (x-\\mu)]$ \\\\\nFor GMM let $\\boldsymbol{\\theta}_k = (\\boldsymbol{\\mu}_k, \\boldsymbol{\\Sigma}_k)$; $p_{\\theta_k}(\\mathbf{x}) = \\mathcal{N}(\\mathbf{x} | \\boldsymbol{\\mu}_k, \\Sigma_k)$\\\\\n\\textbf{Mixture Models:} $p_\\theta(\\mathbf{x}) = \\sum_{k=1}^K \\pi_k p_{\\theta_k}(\\mathbf{x})$\\\\\n\\textbf{Assignment variable (generative model):} $z_{ij} \\in \\{0, 1\\}$, $\\sum_{j=1}^k z_{ij} = 1$\\\\\n$\\operatorname{Pr}(z_k = 1) = \\pi_k \\Leftrightarrow p(\\mathbf{z}) = \\prod_{k=1}^K \\pi_k^{z_k}$\\\\\n\\textbf{Complete data distribution:}\\\\\n$p_\\theta(\\mathbf{x}, \\mathbf{z}) = \\prod_{k=1}^K \\left( \\boldsymbol{\\pi}_k p_{\\theta_k}(\\mathbf{x})\\right)^{z_k}$\\\\\n\\textbf{Posterior Probabilities:} $\\\\\\operatorname{Pr}(z_k = 1 | \\mathbf{x}) = \\frac{\\operatorname{Pr}(z_k = 1) p(\\mathbf{x} | z_k = 1)}{\\sum_{l=1}^K \\operatorname{Pr}(z_l = 1) p(\\mathbf{x} | z_l = 1)} = \\frac{\\boldsymbol{\\pi}_k p_{\\theta_k}(\\mathbf{x})}{\\sum_{l=1}^K \\boldsymbol{\\pi}_l p_{\\theta_l}(\\mathbf{x})}$\\\\\n$\\text{posterior} p(A|B)=\\frac{\\text{prior} p(A)\\times\\text{likelihood} p(B|A)}{\\text{evidence} p(B)}$\\\\\n\\textbf{Likelihood of observed data $\\mathbf{X}$:}\\\\\n$p_\\theta(\\mathbf{X}) = \\prod_{n=1}^N p_\\theta(\\mathbf{x}_n) = \\prod_{n=1}^N \\left(\\sum_{k=1}^K \\pi_k p_{\\theta_k}(\\mathbf{x}_n)\\right)$\n\\textbf{Max. Likelihood Estimation (MLE):}\\\\\n$\\argmax_\\theta\\sum_{n=1}^N \\log \\left( \\sum_{k=1}^K \\pi_k p_{\\theta_k}(\\mathbf{x}_n)\\right)\\\\\n\\ge \\sum_{n=1^N} \\sum_{k=1}^K{q_k[\\log p_{\\theta_k}(\\mathbf{x}_n) + \\log \\pi_k - \\log q_k]}$\\\\\nwith $\\sum_{k=1}^K{q_k} = 1$ by Jensen Inequality.\n\n\\textbf{Generative Model}\\\\\n1. sample cluster index $j \\sim Categorical(\\pi)$\\\\\n2. given $j$, sample data $x \\sim \\text{Normal}(\\mu_j, \\Sigma_j)$\n\n\n\\textbf{Expectation-Maximization (EM) for GMM}\\\\\nE-Step:\nPr$[z_{k,n} = 1 | \\mathbf{x}_n] = q_{k, n} = \\frac{\\boldsymbol{\\pi}_k^{(t-1)} \\mathcal{N}(\\mathbf{x}_n | \\boldsymbol{\\mu}_k^{(t-1)}, \\boldsymbol{\\Sigma}_k^{(t-1)})}{\\sum_{j=1}^K \\boldsymbol{\\pi}_j^{(t-1)} \\mathcal{N}(\\mathbf{x}_n | \\boldsymbol{\\mu}_j^{(t-1)}, \\boldsymbol{\\Sigma}_j^{(t-1)})}$\\\\\nM-Step: \n$\\boldsymbol{\\mu}_k^{(t)} := \\frac{\\sum_{n=1}^N q_{k,n} \\mathbf{x}_n}{\\sum_{n=1}^N q_{k,n}}$\n$, \\boldsymbol{\\pi}_k^{(t)} := \\frac{1}{N} \\sum_{n=1}^N q_{k,n}$\\\\\n$\\Sigma_k^{(t)} = \\frac{\\sum_{n=1}^N q_{k, n} (\\mathbf{x}_n - \\boldsymbol{\\mu}_k^{(t)})(\\mathbf{x}_n - \\boldsymbol{\\mu}_k^{(t)})^\\top}{\\sum_{n=1}^N q_{k,n}}$\n\n\\textbf{Discussion K-means vs. EM}\\\\\nhard assignment vs soft. spherical clusters shapes vs covariance matrix. fast vs slow and more iteration. K-means can be used as initialization for EM.\\\\\nK-means as a special case of GMM with covariances $\\Sigma_j = \\sigma^2 I$. in the limit of $\\sigma \\rightarrow 0$, recover K-means (hard assignments).\n\n\\textbf{Model Order Selection (AIC / BIC for GMM)}\\\\\nTrade-off between data fit (i.e. likelihood $p(\\mathbf{X} | \\theta)$) and complexity (i.e. \\# of free parameters $\\kappa(\\cdot)$). For choosing $K$:\\\\\nAkaike Information Criterion: $\\operatorname{AIC}(\\theta | \\mathbf{X}) = -\\log p_\\theta(\\mathbf{X}) + \\kappa(\\theta)$\\\\\nBayesian Information Criterion: $\\operatorname{BIC}(\\theta | \\mathbf{X}) = -\\log p_\\theta(\\mathbf{X}) + \\frac{1}{2} \\kappa(\\theta) \\log N$\\\\\n\\# of free params, fixed covariance matrix: $\\kappa(\\theta) = K \\cdot D + (K - 1)$ ($K$: \\# clusters, $D$: $\\mathsf{dim}\\text{(data)}=\\mathsf{dim}(\\mu_i)$, $K-1$: $\\pi$ of \\# free clusters), full covariance matrix: $\\kappa(\\theta) = K(D + \\frac{D(D+1)}{2}) + (K - 1)$.\\\\\nCompare AIC/BIC for different $K$ -- the smaller the better. BIC penalizes complexity more.\n", "meta": {"hexsha": "724e1c1b1b13ea56ae9be32dec0152de4a34ad68", "size": 4764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mixture.tex", "max_stars_repo_name": "vscherer/eth-cil-exam-cheatsheet", "max_stars_repo_head_hexsha": "9ae156bcf5e2797e65b5495ff520649b43860cdd", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-09-24T20:33:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-21T15:52:46.000Z", "max_issues_repo_path": "Mixture.tex", "max_issues_repo_name": "vscherer/eth-cil-exam-cheatsheet", "max_issues_repo_head_hexsha": "9ae156bcf5e2797e65b5495ff520649b43860cdd", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mixture.tex", "max_forks_repo_name": "vscherer/eth-cil-exam-cheatsheet", "max_forks_repo_head_hexsha": "9ae156bcf5e2797e65b5495ff520649b43860cdd", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-14T16:21:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-18T17:17:10.000Z", "avg_line_length": 88.2222222222, "max_line_length": 317, "alphanum_fraction": 0.6234256927, "num_tokens": 2021, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801889, "lm_q2_score": 0.8840392878563335, "lm_q1q2_score": 0.8130001302918165}}
{"text": "\\subsection{Lie algebra of \\(SU(n)\\)}\n\n\\subsubsection{\\(SU(n)\\) forms a Lie group}\n\n\\subsubsection{Lie algebra of \\(SU(n)\\)}\n\nThe Lie algebra of \\(SU(n)\\) is defined as:\n\n\\(\\mathfrak{su}(n)=\\{X\\in \\mathbb {C}^{n\\times n}|e^{tX}\\in SU(n) \\forall t\\in \\mathbb{R}\\}\\)\n\nThis is satisfied by the skew-Hermitian matrices where \\(M=-M^*\\) and the trace is \\(0\\). Note that this means the diagonals are all \\(0\\) or pure imaginary.\n\n", "meta": {"hexsha": "45be3d393eb1a9081a34fd6437a053839252c84d", "size": 425, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/representation/05-04-SU.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/representation/05-04-SU.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/representation/05-04-SU.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6923076923, "max_line_length": 157, "alphanum_fraction": 0.6517647059, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305307578324, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.812865525646705}}
{"text": "\n\\subsection{Symbols}\nAs we saw earlier, symbols are defined using an equals sign.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nN = 212^17\n\\end{Verbatim}\n\nNo result is printed when a symbol is defined.\nTo see the value of a symbol, just evaluate it.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nN\n\\end{Verbatim}\n\n$\\displaystyle N=3529471145760275132301897342055866171392$\n\nSymbols can have more that one letter.\nEverything after the first letter is displayed as a subscript.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nNA = 6.02214*10^23\nNA\n\\end{Verbatim}\n\n$\\displaystyle N_A=6.02214\\times10^{23}$\n\nA symbol can be the name of a Greek letter.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nxi = 1/2\nxi\n\\end{Verbatim}\n\n$\\displaystyle \\xi=\\frac{1}{2}$\n\nGreek letters can appear in subscripts.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nAmu = 2.0\nAmu\n\\end{Verbatim}\n\n$\\displaystyle A_\\mu=2.0$\n\nThe following example shows how\nEigenmath scans the entire symbol to find Greek letters.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nalphamunu = 1\nalphamunu\n\\end{Verbatim}\n\n$\\displaystyle \\alpha_{\\mu\\nu}=1$\n\nWhen a symbolic chain is defined,\nEigenmath follows the chain as far as possible.\nThe following example sets $A=B$ followed by $B=C$.\nThen when $A$ is evaluated, the result is $C$.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nA = B\nB = C\nA\n\\end{Verbatim}\n\n$\\displaystyle A=C$\n\nAlthough $A=C$ is printed,\ninside the program the binding of $A$ is still $B$, as can be seen with\nthe $binding$ function.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nbinding(A)\n\\end{Verbatim}\n\n$\\displaystyle B$\n\nThe {\\it quote} function returns its argument unevaluated\nand can be used to clear a symbol.\nThe following example clears $A$ so that its evaluation goes back to\nbeing $A$ instead of $C$.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nA = quote(A)\nA\n\\end{Verbatim}\n\n$\\displaystyle A$\n\n\\subsection{User-defined functions}\nThe following example shows\na user-defined function with a single argument.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nf(x) = sin(x)/x\nf(pi/2)\n\\end{Verbatim}\n\n$\\displaystyle \\frac{2}{\\pi}$\n\nThe following example defines a function with two arguments.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\ng(x,y) = abs(x) + abs(y)\ng(1,-2)\n\\end{Verbatim}\n\n$\\displaystyle 3$\n\nUser-defined functions can be evaluated without an argument list.\nThe binding of the function name is returned when there is no\nargument list.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nf(x) = sin(x)/x\nf\n\\end{Verbatim}\n\n$\\displaystyle f=\\frac{\\sin(x)}{x}$\n\nNormally a function body is not evaluated when a function is defined.\nHowever, in some cases it is required that the function body be the\nresult of something.\nThe $eval$ function is used to accomplish this.\nFor example, the following code causes the function body to be a sixth order Taylor series expansion of $\\cos x$.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nf(x) = eval(taylor(cos(x),x,6))\nf\n\\end{Verbatim}\n\n$\\displaystyle f=-\\frac{1}{720}x^6+\\frac{1}{24}x^4-\\frac{1}{2}x^2+1$\n\nWhen a function body is evaluated the function arguments\nare passed to symbol definitions.\nThe symbol definitions can appear either before or after\nthe function definition.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nf(x) = A + B\nA = a x\nB = b x\nf(2)\n\\end{Verbatim}\n\n$\\displaystyle 2a+2b$\n\n", "meta": {"hexsha": "7db12c9b641f2634a4804843f58f3bfe85bf0c35", "size": 3271, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/symbols.tex", "max_stars_repo_name": "zhouxs1023/eigenmath", "max_stars_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/symbols.tex", "max_issues_repo_name": "zhouxs1023/eigenmath", "max_issues_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/symbols.tex", "max_forks_repo_name": "zhouxs1023/eigenmath", "max_forks_repo_head_hexsha": "e302cee23a4d5877ffe0975f513b35654fa50961", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.9530201342, "max_line_length": 113, "alphanum_fraction": 0.7370834607, "num_tokens": 970, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.8872045966995028, "lm_q1q2_score": 0.8127766521289546}}
{"text": "\\chapter{Monte Carlo integration versus Monte Carlo ray tracing}\\label{chap:appraytracing}\nAlthough Monte Carlo (MC)\t integration and MC ray tracing are two different methods, they are based on the same idea. To fully comprehend MC ray tracing it is necessary to first understand the basics of MC integration. The aim of this appendix is to point out the similarities and the differences between the two methods. In the next section we give an introduction to MC integration for the two-dimensional case. In Section \\ref{app:MCRT} we explain MC ray tracing.\n\\section{Monte Carlo integration}\nLet us consider a set $\\mbox{\\insieme{D}} = [\\vect{a}, \\vect{b}]= [a_1, b_1] \\times [a_2, b_2]$ with $\\vect{a} = (a_1, a_2)$ and $\\vect{b} = (b_1, b_2)\\in\\mathbb{R}^2$. Consider a function $f:[\\vect{a},\\vect{b}]\\subset \\mathbb{R}^2 \\rightarrow \\mathbb{R}$ and a random variable $\\vect{Y}$ with values in \\insieme{D} and probability density function $\\rho(\\vect{y})$, where $\\vect{y}$ are the values of $\\vect{Y}$ in \\insieme{D}. We indicate the random variables with capital letters and the corresponding deterministic values with lowercase letters. The expected value of $f(\\vect{Y})$ with respect of $\\rho(\\vect{Y})$ is:\n\\begin{equation}\n\\mathbb{E}[f(\\vect{Y})] =\\int_{\\textup{D}}f(\\vect{y})\\rho(\\vect{y}) \\textrm{d}\\vect{y}.\n\\end{equation}\nIf $\\rho$ is a uniform probability density function, the expected value is given by:\n\\begin{equation}\\label{eq:expected_value}\n\\mathbb{E}[f(\\vect{Y})] =\\frac{1}{\\lambda([\\vect{a},\\vect{b}])} \\int_{\\textup{D}}f(\\vect{y}) \\textrm{d}\\vect{y},\n\\end{equation}\nwhere $\\lambda([\\vect{a},\\vect{b}]) = (b_1-a_1)\\cdot(b_2-a_2)$.\n%In this case, MC methods approximate the integral in Equation (\\ref{eq:expected_value}) by the sum:\nLet $\\{\\vect{Y}_\\variabile{i}\\}_{\\variabile{i} = 1, \\cdots, N}$ be independent samples with probability density function $\\rho$.\nIndicating with $S_{N}[f(\\vect{Y})]$ the average: \n\\begin{equation}\nS_{N}[f(\\vect{Y})] = \\frac{1}{N} \\sum_{\\variabile{i}=1}^{N} f(\\vect{Y}_\\variabile{i}),\n\\end{equation}\nand with $\\const{Pr}(E)$ the probability that an event $E$ happens,\n%\\begin{equation}\\label{eq:approx_MC_QMC}\n%\\frac{1}{\\lambda([\\vect{a},\\vect{b}])}\\int_{\\textup{D}}f(\\vect{y}) \\textrm{d}\\vect{y}\\approx\\frac{1}{N} \\sum_{\\variabile{i}=1}^{N} f(\\vect{Y}_\\variabile{i}).\n%\\end{equation}\nthe strong law of large numbers states that\n\\begin{equation}\n\\const{Pr}\\Big(\\lim_{N\\rightarrow\\infty}S_{N}[f(\\vect{Y})] = \\mathbb{E}[f(\\vect{Y})] \\Big) = 1\n\\end{equation}\n\\cite{grinstead2012introduction}. This implies that the empirical mean is an unbiased estimator of the expectation value:\n\\begin{equation}\\label{eq:approx_MC_QMC}\n\\mathbb{E}[f(\\vect{Y})] \\approx \\frac{1}{N} \\sum_{\\variabile{i}=1}^{N} f(\\vect{Y}_\\variabile{i}).\n\\end{equation}\nFrom the linearity of the expected value (see \\cite{grinstead2012introduction})\n%\\footnote{Given a set of independent random variables $\\{X_\\variabile{i}\\}_{\\variabile{i}=1, \\cdots, N}$ and a real number $a$, the expected value satisfies:\n%$\\mathbb{E}\\big[\\sum_{\\variabile{i}=1}^{N}X_{\\variabile{i}}\\big] = \\sum_{\\variabile{i}=1}^{N}\\mathbb{E}[X_{\\variabile{i}}]$ and $\\mathbb{E}[a\\,X_\\variabile{i}] = a\\mathbb{E}[X_{\\variabile{i}}]$.},\n it follows that\n\\begin{equation}\\label{eq:linearity}\n\\mathbb{E}[S_{N}[f(\\vect{Y})]] = \\frac{1}{N}\\sum_{\\variabile{i}=1}^{\\textrm{N}}\\mathbb{E}[f(\\vect{Y}_{\\variabile{i}})] = \\mathbb{E}[f(\\vect{Y})],\n\\end{equation}\nwhere the second equality holds as\n$f(\\vect{Y}_{\\variabile{i}})_{\\variabile{i}=1, \\cdots, N}$ are random variables with probability density function $\\rho(\\vect{y})$, because $\\big(\\vect{Y}_{\\variabile{i}}\\big)_{\\variabile{i}=1, \\cdots, N}$ are independent samples with probability density function $\\rho(\\vect{y})$. This implies that $\\mathbb{E}[f(\\vect{Y}_{\\variabile{i}})] = \\mathbb{E}[f(\\vect{Y})]$ for every $\\variabile{i}=1, \\cdots, N$. Indicating with $\\textrm{Var}[f(\\vect{Y})]$ the variance of $f(\\vect{Y})$:\n\\begin{equation}\\textrm{Var}[f(\\vect{Y})]=\\mathbb{E}[(f(\\vect{Y})-\\mathbb{E}[f(\\vect{Y})])^2] = \\sigma^2[f(\\vect{Y})],\n\\end{equation}\nthe Bienaym\\'e formula (see \\cite{grinstead2012introduction}) can be applied because the random variables $\\{\\vect{Y}_\\variabile{i}\\}_{i = 1, \\cdots, N}$ are uncorrelated, therefore\n%\\footnote{Given a set of \\textit{independent} random variables $\\{X_\\variabile{i}\\}_{\\variabile{i}=1, \\cdots, N}$ and a real number $a$, the variance satisfies:\n%$\\textrm{Var}\\big[\\sum_{\\variabile{i}=1}^{N}X_{\\variabile{i}}\\big] = \\sum_{\\variabile{i}=1}^{N}\\textrm[X_{\\variabile{i}}]$ and $\\textrm{Var}[a\\,X_\\variabile{i}] = a^2\\textrm{Var}[X_{\\variabile{i}}]$.} \n\\begin{equation}\\label{eq:variance}\n\\textrm{Var}[S_{N}[f(\\vect{Y})]]= \\textrm{Var}\\Bigg[\\frac{1}{N}\\sum_{\\variabile{i}=1}^{N}f(\\vect{Y}_\\variabile{i})\\Bigg] =\n \\frac{1}{N^2}\\sum_{\\variabile{i}=1}^{N}\\textrm{Var}\\big[f(\\vect{Y}_\\variabile{i})\\big] = \\frac{1}{N}\\textrm{Var}[f(\\vect{Y})], \n\\end{equation} \nwhere the last equality holds as $\\textrm{Var}[f(\\vect{Y}_{\\variabile{i}})] = \\textrm{Var}[f(\\vect{Y})]$.\nEquation (\\ref{eq:linearity}) gives\n\\begin{equation}\\label{eq:variance2}\n\\begin{aligned}\n\\textrm{Var}[S_N[f(\\vect{Y})]] &= \\mathbb{E}[(S_{N}[f(\\vect{Y})]-\\mathbb{E}[S_{N}[f(\\vect{Y})]])^2]\\\\ &= \\mathbb{E}[(S_{N}[f(\\vect{Y})]-\\mathbb{E}[f(\\vect{Y})])^2].\n\\end{aligned}\n\\end{equation}\nCombining (\\ref{eq:variance}) with (\\ref{eq:variance2}) we obtain:\n\\begin{equation}\\label{eq:variance3}\n\\mathbb{E}[(S_{N}[f(\\vect{Y})]-\\mathbb{E}[f(\\vect{Y})])^2] = \\sigma^2[f(\\vect{Y})]/N.\n\\end{equation}\nLet us denote the integration error with:\n\\begin{equation}\\label{eq:error1}\n\\const{err}(f, S_{N}[f(\\vect{Y})]) =\\int_{\\textup{D}}f(\\vect{y})\\rho(\\vect{y}) \\textrm{d}\\vect{y}-S_{N}[f] = \\mathbb{E}[f(\\vect{Y})]-S_N[f(\\vect{Y})].\n\\end{equation}\nConsidering the convex function $g:\\variabile{x}\\mapsto\\variabile{x}^2$ we can write:\n\\begin{equation}\n\\begin{aligned}\n\\mathbb{E}[|\\const{err}(f, S_{N})|] &= \\sqrt{g\\big(\\mathbb{E}[|\\const{err}(f, S_{N})|]\\big)} \\\\&\\leq\\sqrt{\\mathbb{E}[g(|\\const{err}(f, S_{N})|)]} = \\sqrt{\\mathbb{E}[\\const{err}^2(f, S_{N})]},\n\\end{aligned}\n%\\begin{aligned}\n%\\mathbb{E}\\big[|\\const{err}(f, S_{\\const{N}})|\\big] &= \\frac{1}{\\const{N}}\\sqrt{\\Bigg(\\sum_{\\variabile{1}=1}^\\const{N}|\\const{err}(f, S_{\\const{N}})|\\Bigg)^2}  \\leq \\frac{1}{\\const{N}}\\sqrt{\\const{N}\\sum_{\\variabile{1}=1}^\\const{N}\\big(\\const{err}(f, S_{\\const{N}})\\big)^2}  \\\\\n%& =\\sqrt{\\frac{1}{\\const{N}}\\sum_{\\variabile{1}=1}^\\const{N}\\big(\\const{err}(f, S_{\\const{N}})\\big)^2}= \\sqrt{\\mathbb{E}\\big[\\const{err}(f, S_{\\const{N}})^2\\big]}\n%\\end{aligned}\n\\end{equation} \nwhere the inequality follows from Jensen's inequality (\\cite{williams1991probability} Chapter $6$).\nUsing the previous relation and Equations (\\ref{eq:variance3}) and (\\ref{eq:error1}), we obtain:\n\\begin{equation}\\label{eq:mean_error}\n\\mathbb{E}\\big[|\\const{err}(f, S_{N})|\\big]\\leq\n\\sqrt{\\mathbb{E}\\big[\\const{err}^2(f, S_{N})\\big]} = \\frac{\\sigma[f]}{\\sqrt{N}}.\n\\end{equation}\nHence, the absolute value of the integration error is, on average, bounded by $\\sigma[f(\\vect{Y})]/\\sqrt{N}$, where $\\sigma[f(\\vect{Y})]$ is the standard deviation of $f$ \\cite{leobacher2014introduction}. It is important to note that $\\const{err}(f, S_{N})$ does not depend on the dimension of the set \\insieme{D}.\n\\section{Monte Carlo ray tracing}\\label{app:MCRT}\nThe MC technique can be combined with ray tracing in order to compute the intensity distribution at the target of an optical system.\nIn MC ray tracing the position and the direction of every ray are chosen randomly at the source. \n\nIn the two-dimensional case, for every ray we need to choose one position coordinate $\\variabile{x}_1$ and one angular coordinate $\\optangle_1$. These coordinates are chosen randomly and such that they are uniformly distributed at the source. \nUsing ray tracing, the rays with those random initial coordinates are traced from \\point{S} to \\point{T} and, the corresponding random variables $\\vect{Z}_{\\variabile{i}}=(\\variabile{x}^{\\variabile{i}},\\optangle^{\\variabile{i}})$ at the target are obtained, where $\\variabile{x}^{\\variabile{i}}$ and $\\variabile{t}^{\\variabile{i}}$ are the position and direction coordinates of the $\\variabile{i}$-th ray at the target. Note that the rays at the target are most likely non-uniformly distributed. Once the target variables are computed, we can apply the idea of MC simulation to approximate the target intensity $I(\\optangle)$ defined in Chapter \\ref{chap:raytracing}. Since the intensity only depends on the angular coordinate $\\optangle$ we use MC approximation in one dimension. Hence, we approximate the expected value $\\mathbb{E}[I]$ by a sum as described in Equation (\\ref{eq:approx_MC_QMC}). \n\nTo clarify the connection between MC integration and MC ray tracing, in Table \\ref{tab:MCcomparison} we report the correspondence between the functions and the variables used in the previous section and in Chapter \\ref{chap:raytracing}.\n\\begin{table}[h] \\label{tab:MCcomparison}\n\\centering\n\\caption{\\bf Comparison between MC integration and MC ray tracing}\n\\begin{tabular}{|l|l|l|}\n \\hline   MC integration & MC ray tracing \\\\\n  \\hline \n \\insieme{D} $= [\\vect{a}, \\vect{b}]\\subset \\mathbb{R}^2$  & $[\\optangle_{\\variabile{j}-1}, \\optangle_{\\variabile{j}})\\subset \\mathbb{R}$ \\\\ [0.9ex] \n $f:\\mbox{\\insieme{D}}\\rightarrow \\mathbb{R}^2$ & $\\chi_{\\variabile{j}}: [\\optangle_{\\variabile{j}-1}, \\optangle_{\\variabile{j}})\\rightarrow \\{0,1\\}$ \\\\ [0.9ex] \n $\\vect{Y}$   & $\\optangle$ \\\\ [0.9ex] \n $N$   & $\\nrays$ \\\\ [0.9ex] \n$\\{\\vect{Y}_{\\variabile{j}}\\}_{\\variabile{j}=1, \\cdots, N}$  \n& $\\{\\optangle^{\\variabile{k}}\\}_{\\variabile{k}=1, \\cdots, \\nrays}$  \\\\ [0.9ex] \n $S_{N}[f(\\vect{Y})] = \\sum_{\\variabile{i}=1}^N \\frac{f(\\vect{Y}_{\\variabile{i}})}{N}$ &\n $\\hat{I}_{\\textrm{MC}}  = \\frac{\\nrays[\\optangle_{\\variabile{j}-1}, \\optangle_{\\variabile{j}})}{\\nrays[-\\pi/2, \\pi/2]}= \\frac{1}{\\nrays}\\sum_{\\variabile{k}=1}^{\\nrays}\\chi_{\\variabile{j}}(\\optangle^{\\variabile{k}})$ \\\\ [0.9ex] \n $\\mathbb{E}\\big[S_N[f(\\vect{Y})]\\big]=\\mathbb{E}[f(\\vect{Y})]$   \n& $\\mathbb{E}[\\hat{I}_{\\textrm{MC}}]=\\const{P}_{\\variabile{j}, \\Delta \\optangle}$ \\\\ [0.9ex] \n $\\textrm{Var}\\big[S_N[f(\\vect{Y})]\\big] = \\frac{\\textrm{Var}[f(\\vect{Y})]}{N} = \\frac{\\sigma^2}{N}$  & $\\textrm{Var}[\\hat{I}_{\\textrm{MC}}] = \\frac{\\const{P}_{\\variabile{j}, \\Delta \\optangle}(1-\\const{P}_{\\variabile{j}, \\Delta \\optangle})}{\\nrays} = \\sigma_{\\variabile{j}}^2$ \\\\ [0.9ex] \n \\hline\n \\end{tabular}\n\\label{tab:MCcomparison}\n \\end{table}\n\nThe main difference between the two methods is that in MC integration we know the probability density distribution $\\rho$ of the random variables $\\vect{Y}_{\\variabile{i}}$ which is the uniform distribution. Because of this, the expected value of the function $f$ can be approximated by (\\ref{eq:approx_MC_QMC}). On the contrary, in MC ray tracing we consider random variables equally distributed with a uniform distribution $\\rho$ at the source but, applying ray tracing to these variables, we do not know the target probability distribution anymore. Therefore the expected value of the \\textit{target} MC intensity $\\hat{I}_{\\textrm{MC}}$ cannot be approximated by the sum in (\\ref{eq:approx_MC_QMC}). Thus, the target is divided into intervals (for the one dimensional case) of the same length, i.e., bins, and the intensity is approximated by the sum of the characteristic function $\\chi_{\\variabile{j}}$ of the $\\variabile{j}$-th interval as explained in Chapter \\ref{chap:raytracing} (see Equation (\\ref{eq:approssimazione_MCraytracing})). Because of this, the error convergence also depends on to the number of bins for MC ray tracing (see Equation (\\ref{eq:final_MC_error})).\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "31478f30968620d21f629224c9e8c813157e0f29", "size": 11699, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/appendix_MC.tex", "max_stars_repo_name": "melaniafilosa/ps_raytracing", "max_stars_repo_head_hexsha": "8f9111ea4ec3ac125b593f41b3ac6fe302ea6632", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/appendix_MC.tex", "max_issues_repo_name": "melaniafilosa/ps_raytracing", "max_issues_repo_head_hexsha": "8f9111ea4ec3ac125b593f41b3ac6fe302ea6632", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/appendix_MC.tex", "max_forks_repo_name": "melaniafilosa/ps_raytracing", "max_forks_repo_head_hexsha": "8f9111ea4ec3ac125b593f41b3ac6fe302ea6632", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 95.893442623, "max_line_length": 1183, "alphanum_fraction": 0.6880929994, "num_tokens": 4089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007596, "lm_q2_score": 0.8519528057272544, "lm_q1q2_score": 0.812734093419647}}
{"text": "\n\\subsection{Utility functions}\n\nWe have \\(U=f(\\mathbf x)\\).\n\nThroughout this we will be using a Cobb-Douglas utility function, and discuss the properties of other utility functions at the end.\n\nWe have \\(U=\\prod_i x_i^{\\alpha_i}\\).\n\n\\subsection{Marginal utility}\n\nThe marginal utility of product \\(x_1\\) is:\n\n\\(\\dfrac{\\delta }{\\delta x_1}f(\\mathbf x)\\)\n\nFor Cobb-Douglas:\n\n\\(U=\\sum_i x_i^{\\alpha_i})\\).\n\n\\(\\dfrac{\\delta }{\\delta x_1}f(\\mathbf x) = \\dfrac{\\delta}{\\delta x_1} \\prod_i x_i^{\\alpha_i}\\)\n\n\\(\\dfrac{\\delta }{\\delta x_1}f(\\mathbf x) = \\dfrac{1}{x_1}\\alpha_1\\prod_i x_i^{\\alpha_i}\\)\n", "meta": {"hexsha": "e34c917c08ce71019bbbc3f649f62ee278ae628f", "size": 593, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/consumer/01-01-utilityFunction.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/economics/consumer/01-01-utilityFunction.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/economics/consumer/01-01-utilityFunction.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.7826086957, "max_line_length": 131, "alphanum_fraction": 0.6795952782, "num_tokens": 205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539661028358094, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.8127340925008048}}
{"text": "\\section{Linear functions}\n\\subsection{Linear functions} \n$f : R^n \\to R$ means f is a function mapping n-vectors to numbers\\\\\n\\textit{Superposition \\& linearity}: \n$f(\\alpha x + \\beta y) = \\alpha f(x) + \\beta f(y)$\\\\\n\\textbullet $ f(\\alpha_1 x_1 +...+ \\alpha_k x_k) = \\alpha_1 f(x_1)+...+ \\alpha_k f(x_k)$\\\\\nA function that satisfies superposition is called \\textit{linear}\\\\\n\\textbf{Linear function satisfies}\\\\\n\\textbullet \\textit{Homogeneity}: For any n-vector x and any scalar $\\alpha, f(\\alpha x) = \\alpha f(x)$ \\\\\n\\textbullet \\textit{Additivity}: For any n-vectors x and y, $f(x + y) = f(x) + f(y)$\\\\\n\\textbf{Affine functions}\n$f:R_n \\to R$ is affine if and only if it can be expressed as $f(x) = a^Tx + b$ for some n-vector a and scalar b, which is sometimes called the \\textit{offset}\\\\\n\\textbullet Any \\textit{affine} scalar-valued function satisfies the following variation on the super-position property:\n$f(\\alpha x + \\beta y) = \\alpha f(x) + \\beta f(y)$, where $\\alpha + \\beta = 1$\n\n\\subsection{Taylor approximation}\nThe (first-order) Taylor approximation of f near (or at) the point z:\\\\\n\\begin{scriptsize}\n$\\hat{f}(x)= f(z) + \\frac{\\partial f}{\\partial x_1}(z)(x_1 - z_1) + ... +  \\frac{\\partial f}{\\partial x_n}(z)(x_n - z_n)$\n\\end{scriptsize}\\\\\nAlternatively,\n$\\hat{f}(x)=f(z)+ \\nabla f(z)^T(x-z)$\n\\subsection{Regression model}\n\\textit{Regression model} is (the affine function of x) $\\hat{y} = x^T \\beta + v$\n", "meta": {"hexsha": "d86ae90697306131453f7b25883ad86e8418ef32", "size": 1428, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter2.tex", "max_stars_repo_name": "meanmachin3/COT5615", "max_stars_repo_head_hexsha": "fa14d5a297b10e79cdc69e9aee67f8a1744d9340", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-10-03T00:00:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-26T00:44:47.000Z", "max_issues_repo_path": "cheatsheet/inhalt/chapter2.tex", "max_issues_repo_name": "meanmachin3/COT5615", "max_issues_repo_head_hexsha": "fa14d5a297b10e79cdc69e9aee67f8a1744d9340", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter2.tex", "max_forks_repo_name": "meanmachin3/COT5615", "max_forks_repo_head_hexsha": "fa14d5a297b10e79cdc69e9aee67f8a1744d9340", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-10-01T14:09:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-11T20:02:53.000Z", "avg_line_length": 57.12, "max_line_length": 161, "alphanum_fraction": 0.6757703081, "num_tokens": 473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475715065793, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.8127299826574687}}
{"text": "\\section{Brief primer on tensors}\\label{sec:tensor}\nThe material here is based on \\cite{lee-book-2000,dullemond-1991-tensor}.\n\n\nLet \\(V\\) be an \\(n\\)-dimensional vector space over the reals. A {\\em covector} on \\(V\\) is a real-valued linear functional \\(\\omega:V\\rightarrow \\Re\\). The space of all covectors is itself a real vector space  under pointwise addition and multiplication. It is written as \\(V^{\\star}\\) and called the {\\em dual space} to \\(V\\). \n\n\\begin{proposition}[\\cite{lee-book-2000} Proposition 4.1] For \\(V\\) an \\(n\\)-dimensional vector space and \\(E_1, \\ldots, E_n\\) a basis for \\(V\\), the covectors \\(\\epsilon^1, \\ldots, \\epsilon^n\\), defined by:\n  \\[\n  \\epsilon^i(E_j) = \\delta^i_j = \\left\\{\n  \\begin{array}{ll}\n    1 & \\mbox{if \\(i =j\\)} \\\\\n    0 & \\mbox{if \\(i\\not=j\\)}\n    \\end{array}\\right.\n    \\]\n\\noindent form a basis for \\(V^{\\star}\\), called the {\\em dual basis} to \\((E_i)\\).   \n\\end{proposition}\n%% TODO: Define canonical isomorphism.\nNote that it follows that the dimensionality of \\(V^{\\star}\\) is the same as that of \\(V\\). It is also the case that \\(V^{\\star\\star}\\) is canonically isomorphic to \\(V\\). \n\nTensors can be represented in one of three equivalent ways -- as multi-dimensional arrays that are invariant under basis change, as multilinear functions of \\(V\\) and \\(V^{\\star}\\) and as elements of tensor products of \\(V\\) and \\(V^{\\star}\\). Here we choose the last alternative. \n\n\\begin{definition}[Tensor] For $V$ a finite-dimensional real vector space, a {\\em tensor} of rank \\((k,l)\\) over $V$ is an element of the tensor space \\(V\\otimes \\ldots \\otimes V \\otimes V^{\\star}\\otimes \\ldots \\otimes V^{\\star}\\) where the first product has \\(k\\) elements and the second \\(l\\). \\(k\\) is said to be its {\\em contravariant} rank, and \\(l\\) its {\\em covariant} rank. The {\\em rank} of the tensor is \\(k+l\\).\n\\end{definition}\nDenote the set of all \\((k,l)\\)-tensors over \\(V\\) by \\(T^k_l\\).\n$T^k_l(V)$ is a vector space under point-wise addition and scalar multiplication. Specifically:\n\\[\n\\begin{array}{l}\n  (\\alpha T)(X_1, \\ldots, X_k, Y_1, \\ldots, Y_l) = \\alpha(T(X_1, \\ldots, X_k, Y_1, \\ldots, Y_l))\\\\\n  (S+T)(X_1, \\ldots, X_k, Y_1, \\ldots, Y_l)=S(X_1, \\ldots, X_K, Y_1, \\ldots, Y_k) + T(X_1, \\ldots, X_k, Y_1, \\ldots, Y_l)\n\\end{array}\n\\]\nNote that a matrix \\(M\\) is a \\((1,1)\\)-tensor, a vector \\(x\\) a \\((1,0)\\)-tensor, and a covector \\{a\\} a \\((0,1)\\)-tensor. \\((k,l)\\)-tensors are in a 1-1 correspondence with multilinear maps \\(V^{\\star}\\times \\ldots \\times V^{\\star} \\times V \\times \\ldots \\times V \\rightarrow \\Re\\), where the first product has \\(k\\) elements and the second \\(l\\).\n\nThe meaning of the indices of a tensor is usually decided beforehand; it is conventional to write a tensor with its contravariant (upper) indices first and the covariant (lower) indices last, e.g.{} \\({T^{ij}}_k\\). For instance, a matrix \\(M\\) is a \\((1,1)\\)-tensor, and we can write \\({M^j}_i\\) to make its indices explicit. This is the same as \\({M^j}_k\\) -- the identity of indices does not matter. Also, basis vectors will be written with a lower index, and components of a vector with respect to this basis with an upper index; similarly, basis covectors will be written with an upper index and components of a covector with a lower index. \n\n\nIn the following we shall adopt the {\\em Einstein summation convention}:\n\\begin{quotation}\n  If the same index name appears twice in any term, once as an upper index and once as a lower index, that term is understood to be summed over all possible values of that index, generally from \\(1\\) to the dimension of the space in question. If the indices belong to different tensors, their tensor product is taken first.\n\\end{quotation}\nThus for instance we can rewrite:\n\\[\n\\begin{array}{lcl}\n  \\Sigma_{\\nu=1}^n A_{\\mu\\nu}v^{\\nu} & \\rightarrow &   A_{\\mu\\nu}v_{\\nu}\\\\\n  \\Sigma_{\\beta=1}^n \\Sigma_{\\gamma=1}^n A _{\\alpha \\beta}B^{\\beta \\gamma}C_{\\gamma \\delta} & \\rightarrow & A_{\\alpha \\beta}B^{\\beta \\gamma}C_{\\gamma \\delta}\n\\end{array}\n\\]\n\nLet \\(\\{{\\bf e}_j\\}\\) be a basis for \\(V\\), with canonical cobasis \\(\\{\\epsilon^i\\}\\) for \\(V^{\\star}\\). \nA \\((k,l)\\)-tensor \\(T\\) can be associated with an array with \\(k+l\\) dimensions, whose \\((i_1, \\ldots, i_k, j_1, \\ldots, j_l)\\)'th element, written \\(T^{i_1\\ldots i_k}_{j_1, \\ldots, j_l}\\), is given by the coefficient of \\(T\\) for the basis element \\({\\bf e}_{i_1}\\otimes \\ldots \\otimes {\\bf e}_{i_k}\\otimes \\epsilon^{j_1}\\otimes \\ldots \\otimes \\epsilon^{j_l}\\). Thus:\n\\[ T = T^{i_1 \\ldots i_k}_{j_1 \\ldots j_l} {\\bf e}_{i_1}\\otimes \\ldots \\otimes {\\bf e}_{i_k}\\otimes \\epsilon^{j_1}\\otimes \\ldots \\otimes \\epsilon^{j_l}\n\\]\n\n\n\n\\subsection{Tensor Contraction}\\label{sec:summation-convention}\n\n\nThe {\\em contraction} of a tensor is obtained by setting one upper and one lower index equal, thus indicating a summation per the convention above. The result of contracting a \\((k,l)\\)-tensor  is a \\((k-1,l-1)\\) tensor.\n\nThe contraction operation is invariant under coordinate changes.\n\n\n\\subsection{Working with tensors}\n  \nTensors can be ``partially'' evaluated. For \\(T\\) a tensor of rank \\(k\\) representing a predicate \\(p\\), and \\(a\\) a vector representing the value of argument \\(i\\), \\(T_{1\\ldots k}a^i\\) represents the predicate \\(\\lambda x_1, \\ldots, x_{i-1},x_{i+1},\\ldots x_k. p(x_1, \\ldots, x_{i-1}, a, x_{i+1}, \\ldots, x_k)\\). It can be thought of as {\\em contracting} \\(T\\) and \\(a\\) on index \\(i\\).\n  \n\n\\begin{example}\\label{ex:tc-1}\n  Consider the tensor representation of the boolean polynomial \\(p(x,y) = x(1-y)\\). Because \\(x,y\\in \\{0,1\\}\\) with the two values independent of each other, we will embed them in the two dimensional vector space \\(U=\\{0,1\\}^2\\), with ``one hot'' basis vectors \\({\\bf e}_1=(1,0)\\) and \\({\\bf e}_2=(0,1)\\) representing \\(0\\) and \\(1\\) respectively. Now the tensor \\(T_{i,j}\\) representing the binary predicate \\(\\lambda x,y. p(x,y)\\) is represented by the table:\n  \\[\n  \\begin{array}{lll}\n    {T_{1,1}}&=(0)(1-0)&=0\\\\\n    {T_{1,2}}&=(0)(1-1)&=0\\\\\n    {T_{2,1}}&=(1)(1-0)&=1\\\\\n    {T_{2,2}}&=(1)(0)&=0\n  \\end{array}\n  \\]\n  We can use this representation to evaluate the predicate at different points through tensor contraction. For instance, \\(p(0,1)\\) is given, for \\(a={\\bf e}_1,b={\\bf e}_2\\) by \\(T_{i,j}a^i b^j\\), which through the Einstein convention expands out to:\\footnote{Recall that for a vector \\(x\\), \\(x^k\\) represents its \\(k\\)th coordinate. Note that\n    in the first  term \\(T_{i,j}a^ib^j\\) the super-scripts of \\(a\\) and \\(b\\) are formal (unbound) indices, whereas in  the second term \\(T_{i,j}a^i b^j \\), \\(i\\) and \\(j\\) are bound, and the super-scripts of \\(a\\) and \\(b\\) represent component selections.}\n  \\[\\begin{array}{ll}\n  T_{i,j}a^i b^j &= \\Sigma_{j=1}^2 \\Sigma_{i=1}^2 a^i b^j T_{i,j}\\\\\n  &= (1)(0) T_{1,1} + (1)(1) T_{1,2}\n      + (0)(0) T_{2,1} + (0)(1) T_{2,2}\\\\\n  & =T_{1,2}\\\\\n  & = 0\n  \\end{array}\n  \\]\n\n  Similarly, the term \\(T_{i,j} a^i\\) gives us a \\((1,0)\\) tensor \\(S_j\\) representing \\(\\lambda x.p(0,x)\\):\n  \\[\n  \\begin{array}{l}\n    S_1 = \\Sigma_{i=1}^2 a^i T_{i,1} =a^1 T_{1,1} + a^2  T_{2,1} = T_{1,1} = 0\\\\\n    S_2 = \\Sigma_{i=1}^2 a^i T_{i,2} =a^1 T_{1,2} + a^2  T_{2,2} =  T_{1,2} = 0    \n  \\end{array}\\]\n\n  The term \\(T_{i,j} a^j\\) gives us a \\((1,0)\\) tensor \\(R_i\\) representing \\(\\lambda x. p(x,0)\\):\n  \\[\\begin{array}{l}\n    R_1 = \\Sigma_{i=1}^2 a^i T_{1,i} =a^1 T_{1,1} + a^2  T_{1,2} = T_{1,1} = 0\\\\\n    R_2 = \\Sigma_{i=1}^2 a^i T_{2,i} =a^1 T_{2,1} + a^2  T_{2,2} =  T_{2,1} = 1    \n  \\end{array}\\]\n\n    Applying \\(R_i\\) to \\(b\\), i.e. computing \\(R_ib^i\\) gives \\(R_1 b^1 + R_2 b^2=(0)(0) + (1)(1)=1\\), whereas applying it to \\(a\\)  gives  \\(R_1 a^1 + r_2 b^2 = (0)(1)+(0)(0) = 0\\). The results in both case agree with \\((\\lambda x.p(x,0))(1)\\).\n  \n\\end{example}\n\nMore generally, we can compute tensor contraction symbolically. Let \\(x,y\\) be  unknown vectors in \\(U\\), and let \\(S\\) be a rank-2 tensor over \\(U\\). Then if \\(S\\) represents the predicate \\(q\\), the predication \\(q(x,y)\\) is represented by \\(S_{i,j}x^i y^j\\) which expands out to:\n\\[\\begin{array}{ll}\n  [S(x,y)]&\\defeq  S_{i,j}x^i y^j\\\\\n  & = \\Sigma_{j=1}^2 \\Sigma_{i=1}^2 x^i y^j [S_{i,j}] \\\\\n  & =   x^1 y^1  [S_{1,1}] + x^1 y^2 [S_{1,2}]\n      + x^2 y^1 [S_{2,1}]  + x^2 y^2 [S_{2,2}]\n  \\end{array}\n\\]\n\n\\begin{example}[Example~\\ref{ex:tc-1} contd]\n  Taking the value of \\(S\\) above to be \\(T\\), we get:\n  \\[\\begin{array}{ll}    \n      [T(x,y)] & = x^2y^1\\\\\n      & = [x=1][y=0]\n  \\end{array}\n  \\]\n\\end{example}\n\nThe representation of an arbitrary $k$-ary predicate is similar, a tensor \\(T_k\\) represented by \\(n^k\\) numbers, for \\(U=\\{0,1\\}^n\\). \n", "meta": {"hexsha": "29ce9c95fc314574b9b14a1f13e8e82040e768bc", "size": 8635, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendix-tensor-3.tex", "max_stars_repo_name": "saraswat/logic-nn", "max_stars_repo_head_hexsha": "79af16ead7d86e4eca0b3cfc88d1c3379485088f", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-05-13T15:55:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-11T12:28:48.000Z", "max_issues_repo_path": "appendix-tensor-3.tex", "max_issues_repo_name": "saraswat/logic-nn", "max_issues_repo_head_hexsha": "79af16ead7d86e4eca0b3cfc88d1c3379485088f", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "appendix-tensor-3.tex", "max_forks_repo_name": "saraswat/logic-nn", "max_forks_repo_head_hexsha": "79af16ead7d86e4eca0b3cfc88d1c3379485088f", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.5317460317, "max_line_length": 645, "alphanum_fraction": 0.6333526346, "num_tokens": 3142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.8918110432813418, "lm_q1q2_score": 0.812600123500445}}
{"text": "\\subsection{Properties of the inverse}\n\nThe following are some algebraic properties of matrix inverses.\n\n\\begin{proposition}{Properties of the inverse}{inverse-properties}\n  Let $A$ and $B$ be $n \\times n$-matrices, $I$ the $n\\times\n  n$-identity matrix. Then the following hold.\n  \\begin{enumerate}\n  \\item $I$ is invertible and $I^{-1} = I$.\n  \\item If $A$ and $B$ are invertible then $AB$ is invertible, and\n    $(AB)^{-1} = B^{-1}A^{-1}$.\n  \\item If $A$ is invertible then so is $A^{-1}$, and\n    $(A^{-1})^{-1} = A$.\n  \\item If $A$ is invertible then so is $A^k$, and\n    $(A^k)^{-1} = (A^{-1})^k$.\n  \\item If $A$ is invertible and $p$ is a non-zero scalar, then $pA$\n    is invertible and $(pA)^{-1} = \\frac{1}{p}A^{-1}$.\n  \\end{enumerate}\n\\end{proposition}\n\n", "meta": {"hexsha": "cceee7986420a52442944a104242e409d5e54c78", "size": 765, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Inverses-Properties.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-Inverses-Properties.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-Inverses-Properties.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 36.4285714286, "max_line_length": 68, "alphanum_fraction": 0.6156862745, "num_tokens": 276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107984180245, "lm_q2_score": 0.8670357580842941, "lm_q1q2_score": 0.8125952750911584}}
{"text": "\n\\subsection{Vector potential}\n\nGiven a vector field \\(\\mathbf F\\) we may be able to identify another vector field \\(A\\) such that:\n\n\\(\\mathbf F =\\nabla \\times \\mathbf A\\)\n\nExistence:\n\nWe know that the divergence of the curl for any vector field is \\(0\\), so this applies to \\(A\\):\n\n\\(\\nabla . (\\nabla \\times \\mathbf A)=0\\)\n\nTherefore:\n\n\\(\\nabla . \\mathbf F= 0\\)\n\nThis means that if there is a vector potential of \\(\\mathbf F\\), then \\(\\mathbf F\\) has no divergence.\n\n\\subsection{Non-uniqueness of vector potentials}\n\nVector potentials are not unique.\n\nIf \\(\\mathbf A\\) is a vector potential of \\(\\mathbf F\\), then so is \\(\\mathbf A + \\nabla c\\), where \\(c\\) is a scalar field and \\(\\nabla c\\) is its gradient.\n\n\\subsection{Conservative vector fields}\n\nNot all vector fields have scalar potentials. Those that do are conservative.\n\nFor example if a vector field is the gradient of a scalar height function, then the height is a scalar potential.\n\nIf a vector field is the rotation of water, there will not be a scalar potential.\n\n", "meta": {"hexsha": "2ca4d3a31918a1ad3854b31ae8b5dfa21880cbc2", "size": 1030, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/multiCalculus/04-02-vectorPotential.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/multiCalculus/04-02-vectorPotential.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/multiCalculus/04-02-vectorPotential.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.2941176471, "max_line_length": 157, "alphanum_fraction": 0.7155339806, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.8723473813156294, "lm_q1q2_score": 0.8125588787472345}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 4}\n\nProve that if $f = O(g)$ and $g = O(h)$ then $f = O(h)$.\n\n\\subsection*{Solution}\nSince $f = O(g)$, there are constants $c$ and $x_0$ such that\n\\begin{equation}\nf(x) \\leq c \\times g(x)\n\\label{eq9}\n\\end{equation}\nfor any $x \\geq x_0$.\n\nSince $g = O(h)$, there are constants $d$ and $x_1$ such that\n\\begin{equation}\ng(x) \\leq d \\times h(x)\n\\end{equation}\nfor any $x \\geq x_1$.\n\nWe take $x_2 = max(x_0,x_1)$ and $e = c \\times d$ as constants with which the following holds true for $x \\geq x_2$.\n\n\\begin{equation}\nf(x) \\leq c \\times d \\times h(x) = e \\times h(x)\n\\end{equation}\n\nBy definition of Big-Oh, $f = \\mathcal{O}(h)$ is proved.\n", "meta": {"hexsha": "bd2e6fe19a829139ad7f7071c623bad0ced0c137", "size": 1010, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q04.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q04.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q04.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 30.6060606061, "max_line_length": 116, "alphanum_fraction": 0.5831683168, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8824278587245936, "lm_q1q2_score": 0.8125304658683887}}
{"text": "\\section{The Lagrangian}\r\n\\subsection{The Sufficiency Theorem}\r\nWe now consider the general case of the constrained optimisation, without explicitly appealing to the convexity assumption.\r\nSuppose we want to minimise $f(x)$ subject to $g(x)=b,x\\in X$, to deal with the functional constraint, we introduce the Lagrangian of the problem:\r\n\\begin{definition}[Lagrangian]\r\n    The Lagrangian $L:\\mathbb R^n\\times\\mathbb R^m\\to\\mathbb R$ of the problem is defined by\r\n    $$L(x,\\lambda)=f(x)+\\lambda^\\top(b-g(x))$$\r\n    For $\\lambda=(\\lambda_1,\\ldots,\\lambda_m)^\\top$, the components $\\lambda_i$ constitutes the Lagrange multiplier.\r\n\\end{definition}\r\nA nice theorem associated with this notion is the following:\r\n\\begin{theorem}[The Lagrange Sufficiency Theorem]\\label{lagrange_suff}\r\n    Let $x^\\star$ be feasible for the problem.\r\n    Suppose there exists a $\\lambda^\\star\\in\\mathbb R^m$ such that\r\n    $$\\forall x\\in X,L(x^\\star,\\lambda^\\star)\\le L(x,\\lambda^\\star)$$\r\n    Then $x^\\star$ is optimal.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    For any feasible $x$ and any $\\lambda\\in\\mathbb R^m$, we have\r\n    $$L(x,\\lambda)=f(x)+\\lambda^\\top(b-g(x))=f(x)$$\r\n    So our assumption gives, for any feasible $x$,\r\n    $$f(x^\\star)=L(x^\\star,\\lambda^\\star)\\le L(x,\\lambda^\\star)=f(x)$$\r\n    as desired.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider the problem of minimising $x_1^2+3x_2^2$ subject to $4x_1+x_2=7$.\r\n    We claim that $(12/7,1/7)$ is optimal.\r\n    The Lagrangian has the expression\r\n    $$L(x_1,x_2,\\lambda)=x_1^2+3x_2^2+\\lambda(7-4x_1-x_2)$$\r\n    Take $\\lambda=6/7$, we have\r\n    $$L(x_1,x_2,6/7)=(x_1-12/7)^2+3(x_2-1/7)^2+3\\ge 3=L(12/7,1/7,6/7)$$\r\n    So $(12/7,1/7)$ is optimal by the preceding theorem.\r\n\\end{example}\r\nNote that our choice of multiplier $\\lambda^\\star=6/7$ is kind of ``out of nowhere''.\r\nIt makes one wonder if there is a systematic method to guarantee to produce a $\\lambda^\\star$ that works.\r\nSadly, it is not always possible to find a multiplier that works as a certificate of optimality, let alone a sufficient algorithm to compute one.\r\nHowever, inspired by the theorem, we can come up with a way to compute $\\lambda^\\star$ if the problem behaves sufficiently nice.\\\\\r\nIf $x^\\star$ and $\\lambda^\\star$ do exist, we must have\r\n$$\\inf_{x\\in X}L(x,\\lambda^\\star)=f(x^\\star)>-\\infty$$\r\nSo to calculate $\\lambda^\\star$, we first identify the possible candidates\r\n$$\\Lambda=\\{\\lambda\\in\\mathbb R^n:\\inf_{x\\in X}L(x,\\lambda)>-\\infty\\}$$\r\nThen, for each $\\lambda\\in\\Lambda$, we consider the probelm of minimising $L(x,\\lambda)$ subject to $x\\in X$.\r\nThis is hopefully easiler since the functional constraint has been removed (with, of course, the trade-off of having to consider the problem for a wide range of functions).\r\nDenote then minimiser as $x(\\lambda)$.\r\nWe now find a $\\lambda^\\star\\in\\Lambda$ such that $x(\\lambda^\\star)$ is feasible.\r\nIn general, it might not be possible to go through all these steps, but if it is possible, then $x^\\star=x(\\lambda^\\star)$ would be guaranteed to be the optimal solution by the theorem.\r\n\\begin{example}[Maximum Likelihood Estimator of the Multinomial Distribution]\r\n    Given constants $n_1,\\ldots,n_k>0$, we consider the problem to maximise $\\sum_in_i\\log p_i$ subject to $\\sum_ip_i=1,\\forall i,p_i>0$.\r\n    The Lagrangian is\r\n    $$L(p,\\lambda)=\\lambda+\\sum_{i=1}^k(n_i\\log p_i-\\lambda p_i)$$\r\n    Then easily $\\Lambda=\\mathbb R_{>0}$.\r\n    Now we have\r\n    $$\\frac{\\partial L}{\\partial p_i}=\\frac{n_i}{p_i}-\\lambda=0\\implies p_i(\\lambda)=\\frac{n_i}{\\lambda}$$\r\n    But also\r\n    $$D^2L=\\begin{pmatrix}\r\n        -n_1/p_1^2&0&0\\\\\r\n        0&\\ddots&0\\\\\r\n        0&0&-n_k/p_k^2\r\n    \\end{pmatrix}$$\r\n    which is negative definite, so we have found the maximum.\r\n    The constraint $\\sum_ip_i=1$ gives $\\lambda=\\sum_in_i$, so\r\n    $$p_i^\\star=\\frac{n_i}{\\sum_jn_j}$$\r\n    is optimal.\r\n\\end{example}\r\n\\subsection{Inequality Constraints}\r\nWe can consider a somewhat more general version of the optimisation problem, where we replace the functional constraints by their inequality analog.\r\nFor vectors $x,y$, we write $x\\le y$ if $x_i\\le y_i$ for each $i$.\\\\\r\nLet $f:\\mathbb R^n\\to\\mathbb R,g:\\mathbb R^n\\to\\mathbb R^m,X\\in\\mathbb R^n$.\r\nWe want to consider the problems to minimise $f(x)$ subject to $g(x)\\le b,x\\in X$.\r\nNotice that we can actually rewrite this problem to an equality form by introducing a slack variable $z\\in\\mathbb R^m$ by considering the minimisation of $f(x)$ subject to $g(x)+z=b,x\\in X,z\\ge 0$.\\\\\r\nThen, the Lagrangian of the modified problem would be\r\n$$L(x,z,\\lambda)=f(x)+\\lambda^\\top(b-g(x)-z)=f(x)+\\lambda^\\top(b-g(x))-\\lambda^\\top z$$\r\nNote that if some of $\\lambda$ is positive then we can easily send $L$ to $-\\infty$, so $\\Lambda\\subset\\{\\lambda\\in\\mathbb R^m:\\lambda\\le 0\\}$.\r\nSo if we want to use the Lagrange multiplier method, then a sign constraint is further imposed on $\\lambda$.\r\nIn particular,\r\n$$\\Lambda=\\{\\lambda\\in\\mathbb R^m:\\lambda\\le 0,\\inf_{x\\in X}(f(x)+\\lambda^\\top(b-g(x)))>-\\infty\\}$$\r\nNow we proceed to the second step of using Lagrange multiplier.\r\nNote that for $\\lambda\\le 0$, we have $\\inf_{z\\ge 0}(-\\lambda^\\top z)=0$, so the optimal $z=z(\\lambda)$ would satisfy the complementary slackness condition, i.e. $\\lambda^\\top z=0$.\r\nSo if the $i^{th}$ Lagrange multiplier is nonzero, then $z_i=0$, so the $i^{th}$ functional constraint is tight, i.e. hold with equality.\r\nIf the $i^{th}$ functional constraint is not tight, then $z_i>0$, thus it must be the case that $\\lambda_i=0$.\r\nThe rest of the method can then be carried on as usual.\r\n\\begin{example}\r\n    Consider the minimisation of $x_1-3x_2$ subject to $x_1^2+x_2^2\\le 4$ and $x_1+x_2\\le 2$.\r\n    We introduce the slack variables $z_1,z_2\\ge 0$, by which we can transform the problem to the minimisation of $x_1-3x_2$ subject to\r\n    $$\\begin{cases}\r\n        x_1^2+x_2^2+z_1=4\\\\\r\n        x_1+x_2+z_2=2\\\\\r\n        z_1,z_2\\ge 0\r\n    \\end{cases}$$\r\n    So the Lagrangian is\r\n    $$L=x_1-3x_3+\\lambda_1(4-x_1^2-x_2^2-z_1)+\\lambda_2(2-x_1-x_2-z_2),\\lambda_1,\\lambda_2\\le 0$$\r\n    Note that\r\n    $$D^2L=\\begin{pmatrix}\r\n        -2\\lambda_1&0\\\\\r\n        0&-2\\lambda_1\r\n    \\end{pmatrix}\\succeq 0$$\r\n    Hence we only need $\\partial L/\\partial x_1=\\partial L/\\partial x_2=0$, whcih yields\r\n    $$\\begin{cases}\r\n        1-2\\lambda_1x_1-\\lambda_2=0\\\\\r\n        -3-2\\lambda_1x_2-\\lambda_2=0\r\n    \\end{cases}$$\r\n    If $\\lambda_1=0$, then $\\lambda_2=1$ and $\\lambda_2=-3$, contradiction.\r\n    So $\\lambda_1<0$.\r\n    if $\\lambda_2<0$, then by complementary slackness, $z=0$, therefore\r\n    $$\\begin{cases}\r\n        1-2\\lambda_1x_1-\\lambda_2=0\\\\\r\n        -3-2\\lambda_1x_2-\\lambda_2=0\\\\\r\n        x_1^2+x_2^2=4\\\\\r\n        x_1+x_2=2\r\n    \\end{cases}$$\r\n    Solving this equation gives $(x_1,x_2)\\in\\{(2,0),(0,2)\\}$, so $(x_1,x_2,\\lambda_1,\\lambda_2)$ is either $(2,0,1,-3)$ or $(0,2,-1,1)$, but both violates the sign constraint, which gives contradiction again.\r\n    Hence $\\lambda_2=0$.\r\n    By complementary slackness $z_1=0$, so the first functional constraint is tight, hence\r\n    $$\\begin{cases}\r\n        1-2\\lambda_1x_1=0\\\\\r\n        -3-2\\lambda_1x_2=0\\\\\r\n        x_1^2+x_2^2=4\r\n    \\end{cases}$$\r\n    Solve to get $\\lambda_1=-\\sqrt{10}/4$ and\r\n    $$(x_1,x_2)=\\left( -\\sqrt{\\frac{2}{5}},3\\sqrt{\\frac{2}{5}} \\right)$$\r\n    which is feasible hence optimal.\r\n\\end{example}\r\nWhile we can solve it, it is always good to know beforehand that this method will work.\r\nThis brings us to the next topic on the necessity condition.\r\n\\subsection{The Necessity Theorem}\r\nLet's go back to the problem of minimising $f(x)$ subject to $g(x)=b,x\\in X$.\r\nDenote the Lagrangian by\r\n$$L(x,\\lambda)=f(x)+\\lambda^\\top(b-g(x))$$\r\nWe have already established Theorem \\ref{lagrange_suff} saying that a feasible $x^\\star$ is optimal if there exists some $\\lambda^\\star$ with $L(x^\\star,\\lambda^\\star)\\le L(x,\\lambda^\\star)$ for any $x\\in X$.\r\nIn particular, we have\r\n$$\\inf_{x\\in X,g(x)=b}f(x)=f(x^\\star)=\\inf_{x\\in X}L(x,\\lambda^\\star)$$\r\nWe, of course, want some useful statement on the converse of this statement.\r\n\\begin{theorem}[Lagrangian Necessity]\\label{lagrange_nece}\r\n    For $b\\in\\mathbb R^n$, let\r\n    $$\\phi(b)=\\inf_{x\\in X,g(x)=b}f(x)$$\r\n    If $\\phi$ is defined and convex, then there is a $\\lambda=\\lambda(b)$ with\r\n    $$\\phi(b)=\\inf_{x\\in X,g(x)=b}f(x)=\\inf_{x\\in X}L(x,\\lambda(b))$$\r\n    Furthermore, if $\\phi$ is differentiable, then $\\lambda(b)$ can be taken to be $D\\phi(b)$.\r\n\\end{theorem}\r\n\\begin{definition}\r\n    Such a function $\\phi(b)$ is called the value function of the family of the problems of minimising $f(x)$ subject to $g(x)=b,x\\in X$.\r\n\\end{definition}\r\n\\begin{proof}\r\n    Suppose $\\phi$ is convex and fix $b\\in\\mathbb R^m$, then by Theorem \\ref{hyperplane}, there is some $\\lambda\\in\\mathbb R^m$ (which can be taken to be $D\\phi(b)$) such that\r\n    \\begin{align*}\r\n        \\phi(b)&=\\inf_{c\\in\\mathbb R^m}(\\phi(c)+\\lambda^\\top(b-c))\\\\\r\n        &=\\inf_{c\\in\\mathbb R^m}\\inf_{x\\in X,g(x)=c}(f(x)+\\lambda^\\top(b-c))\\\\\r\n        &=\\inf_{c\\in\\mathbb R^m}\\inf_{x\\in X,g(x)=c}(f(x)+\\lambda^\\top(b-g(x)))\\\\\r\n        &=\\inf_{x\\in X}L(x,\\lambda)\r\n    \\end{align*}\r\n    which is just what we wanted.\r\n\\end{proof}\r\n\\begin{remark}\r\n    By adding slack variables\r\n    $$\\inf_{x\\in X,g(x)\\le b}f(x)=\\inf_{x\\in X,z\\ge 0,g(x)+z=b}f(x)$$\r\n    We can see that the theorem can still hold when the functional constraint is an equality.\r\n\\end{remark}\r\nTo apply this theorem, we can require helps on determining the convexity of $\\phi$.\r\n\\begin{theorem}\r\n    Suppose $X$ is convex, $f$ is convex, the functional constraint is $g(x)\\le b$ and $g_j$ is convex for all $1\\le j\\le m$, then $\\phi$ is convex.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Exercise.\r\n\\end{proof}\r\n\\subsection{Shadow Prices}\r\nWe can view the optimisation problem in some real-life economical setting, which gives intuition to the construction of the Lagrangian.\\\\\r\nConsider a factory owner who makes $n$ different products out of $m$ raw materials.\r\nHe needs to choose amount $x_i$ to make of the $i^{th}$ product for each $i=1,\\ldots,n$.\r\nGiven a vector of amounts $x=(x_1,\\ldots,x_n)^\\top$ of products to manufacture, the factory requires the amount $g_j(x)$ of the $j^{th}$ raw material for $j=1,\\ldots,m$, and the amount of available $j^{th}$ raw material available is $b_j$.\r\nThe only nonnegative amounts of products can be produced and given the amounts $x$ of products, the profit earned is $f(x)$.\\\\\r\nObviously, what the factory owner wants is to maximise $f(x)$ subject to $g(x)\\le b,x\\ge 0$.\r\nWe let $\\phi(b)$ be the maximised profit as a function of the amount of raw materials.\\\\\r\nTo solve this problem, we can consider a fictional world where there is a market for the raw material with the unit price of the $j^{th}$ raw material being $\\lambda_j$, then the total profit is exactly\r\n$$L(x,\\lambda)=f(x)+\\lambda^\\top(b-g(x))$$\r\nSo the problem has transformed into the maximisation problem of the Lagrangian.\r\nFor each price vector $\\lambda$, the optimal amount of products is the vector $x(\\lambda)$.\r\nWe can now find a price vector $\\lambda^\\star$ such that $x^\\star=x(\\lambda)$ is feasible.\r\nSuch a $\\lambda^\\star$ is called the shadow price vector of the raw materials.\r\nThis is the prices of the raw materials such that the maximisation problem makes no difference on whether there is such a fictional market.\\\\\r\nThe supporting hyperplane can also have an economical interpretation.\r\nSuppose the fictional market of raw materials suddenly appears, then the factory owner would buy the basket $(\\epsilon_1,\\ldots,\\epsilon_m)^\\top$ of raw materials if $\\phi(b+\\epsilon)-\\phi(b)\\ge\\lambda^\\top\\epsilon$, so when $\\epsilon$ is small,\r\n$$\\phi(b+\\epsilon)-\\phi(b)=D\\phi(b)^\\top\\epsilon$$\r\nSo if $\\lambda_j>\\partial\\phi/\\partial b_j$, then the factory owner should not be buying any of that raw material.\r\nHence the shadow price has to be $D\\phi(b)$ as before.\\\\\r\nTo check that all these are consistent, we check the followings:\r\nThe inequality constraint $g(x)\\le b$ gives a sign constraint $\\lambda\\ge 0$, which is consistent with the assumption that price should not be negative.\r\nAlso, if the $j^{th}$ constraint is not tight, then $g_j(x^\\star)<b_j$, then the owner does not use up all the $j^{th}$ raw material, so the shadow price has $\\partial\\phi/\\partial b_j=0$ as there is no extra profit in acquiring some more of that material.\r\nOn the other hand, the $j^{th}$ slack variable would be positive, hence $\\lambda_j=0$ by complementary slackness, which makes sense economically.\r\n\\subsection{Duality}\r\nWe can introduce the notion of a dual optimisation problem by a corresponding economic motivation.\r\nConsider the point of view of the seller of the raw materials who then buy the products produced by the factory.\r\nIf the amount of finished products is $x$ and the price of raw materials is $\\lambda$, then the seller's profit would be the negative of the profit of factory owner, which is $f(x)+\\lambda^\\top(b-g(x))$.\r\nSo what the seller wants would be to minimise\r\n$$\\sup_{x\\ge 0}(f(x)+\\lambda^\\top(b-g(x)))$$\r\n\\begin{definition}\r\n    Consider the primal problem of minimising $f(x)$ subject to $g(x)=b,x\\in X$ which has Lagrangian\r\n    $$L(x,\\lambda)=f(x)+\\lambda^\\top(b-g(x))$$\r\n    Then the set of feasible Lagrange multipliers is\r\n    $$\\Lambda=\\{\\lambda\\in\\mathbb R^m:\\inf_{x\\in X}L(x,\\lambda)>-\\infty\\}$$\r\n    Then the dual objective function is defined as\r\n    $$h:\\Lambda\\to\\mathbb R,h(\\lambda)=\\inf_{x\\in X}L(x,\\lambda)$$\r\n    The dual problem of the primal problem is to maximise $h(\\lambda)$ subject to $\\lambda\\in\\Lambda$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    One should note that if one need to study the dual problem of a problem with inequality constraints, then we need to introduce the slack variables first.\r\n    Also, we can formulate the dual problem to a maximisation problem analogously.\r\n\\end{remark}\r\n\\begin{theorem}[Weak Duality]\\label{weak_dual}\r\n    With the definitions introduced above,\r\n    $$\\sup_{\\lambda\\in\\Lambda} h(\\lambda)\\le\\inf_{x\\in X,g(x)=b}f(x)$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    For any $x$ feasible for the primal problem and $\\lambda$ feasible for the dual problem, then\r\n    $$h(\\lambda)=\\inf\\{L(\\xi,\\lambda):\\xi\\in X\\}\\le L(x,\\lambda)=f(x)$$\r\n    As $L(x,\\lambda)=f(x)$ whenever $x$ is feasible.\r\n\\end{proof}\r\nSo we can restate Theorem \\ref{lagrange_suff} in the following way instead:\r\nIf $x^\\star$ and $\\lambda^\\star$ are feasible for the primal and dual problems respectively, and $h(\\lambda^\\star)=f(x^\\star)$, then $x^\\star$ is optimal.\r\n\\begin{remark}\r\n    The difference\r\n    $$\\inf_{x\\in X,g(x)=b}f(x)-\\sup_{\\lambda\\in\\Lambda}h(\\lambda)$$\r\n    is called the duality gap.\r\n    It is in general nonnegative by Theorem \\ref{weak_dual}.\r\n    By Theorem \\ref{lagrange_nece}, if the value function of the primal problem is convex, then there is some $\\lambda^\\star\\in\\Lambda$ such that\r\n    $$\\inf_{x\\in X,g(x)=b}f(x)=\\inf_{x\\in X}L(x,\\lambda^\\star)=h(\\lambda^\\star)$$\r\n    So the duality gap is zero.\r\n    This is called \\textit{strong duality}.\r\n\\end{remark}\r\n\\subsection{Duality in Linear Programs}\r\n\\begin{definition}\r\n    Linear Programs are problems of maximising $c^\\top x$ subject to $Ax\\le b,x\\ge 0$ where $A$ is an $m\\times n$ matrix, $b\\in\\mathbb R^m$ and $c\\in\\mathbb R^n$.\r\n\\end{definition}\r\nOf course, we can analyze the dual problem too.\r\nIntroduce the slack variable $z\\in\\mathbb R^m$ and transform the problem to maximising $c^\\top x$ subject to $Ax+z=b,x\\ge 0,z\\ge 0$.\r\nSo the Lagrangian is\r\n$$L(x,z,\\lambda)=c^\\top x-\\lambda^\\top(b-Ax-z)=b^\\top\\lambda +(c-A^\\top\\lambda)^\\top x-\\lambda^\\top z$$\r\nSo\r\n$$\\Lambda=\\{\\lambda\\in\\mathbb R^m:\\sup_{x,z\\ge 0}L(x,z,\\lambda)<\\infty\\}=\\{\\lambda\\in\\mathbb R^m:A^\\top\\lambda\\ge c,\\lambda\\ge 0\\}$$\r\nNow the dual objective function is\r\n$$\\sup_{x\\ge 0,z\\ge 0}L(x,z,\\lambda)=b^\\top\\lambda$$\r\nfor $\\lambda\\in\\Lambda$.\r\nHence the dual problem is to minimise $b^\\top\\lambda$ subject to $A^\\top\\lambda\\ge c,\\lambda\\ge 0$.\r\nThis looks just like our original problem.\r\n\\subsection{The Barrier Method}\r\nConsider the optimisation problem of minimising a differentiable convex function $f:\\mathbb R^n\\to\\mathbb R$ subject to $g(x)\\le b$, where $g:\\mathbb R^n\\to\\mathbb R^m$ has every one of its components differentiable.\r\nTo tackle it (computationally), we consider the family of unconstrained minimisation problems of\r\n$$f(x)-\\epsilon\\sum_{i=1}^m\\log(b_i-g_i(x))$$\r\nfor $\\epsilon>0$.\r\nNote that the constraint $g(x)<b$ is implicitly imposed due to the domain of $\\log$.\r\nThe idea of it, as one might have already observed, is to add an extra term which blows up to positive infinity if the condition $g(x)<b$ is not satisfied.\r\nThe reason why we use a term in the $\\epsilon\\log$ form is to smoothen the blow-up term for computational issues.\r\n\\begin{theorem}\\label{barrier_method}\r\n    Suppose $x^\\star$ is optimal for our original problem and $x_\\epsilon$ is optimal for the problem shown above, then\r\n    $$0\\le f(x_\\epsilon)-f(x^\\star)\\le m\\epsilon$$\r\n\\end{theorem}\r\nTo prove it, we shall introduce some preliminary notion.\r\nThe Lagrangian for the original problem is $L(x,z,\\lambda)=f(x)+\\lambda^\\top (b-z-g(x))$ for the slack variable $z\\ge0$ and the set of feasible Lagrange multipliers are\r\n$$\\Lambda=\\{\\lambda\\in\\mathbb R^m:\\inf_{x\\in\\mathbb R^n,z\\ge 0}L(x,z,\\lambda)>-\\infty\\}$$\r\n\\begin{claim}\r\n    Let $\\lambda\\in\\mathbb R^m$ be such that $\\lambda\\le 0$ and that there exists some $x_\\lambda\\in\\mathbb R^n$ with\r\n    $$Df(x_\\lambda)=\\sum_{i=1}^m\\lambda_iDg_i(x_\\lambda)$$s\r\n    Then $\\lambda\\in\\Lambda$ and the dual objective function for this problem is just\r\n    $$h(\\lambda)=b^\\top\\lambda+f(x_\\lambda)-\\lambda^\\top g(x_\\lambda)$$\r\n\\end{claim}\r\n\\begin{proof}\r\n    Recall that every convex differentiable function is minimised at any of its stationary points.\r\n    Also note that $f(x)-\\lambda^\\top g(x)$ is convex.\r\n    So for $x\\in\\mathbb R^n$ and $z\\ge 0$ we have the bound\r\n    $$L(x,z,\\lambda)=b^\\top\\lambda+f(x)-\\lambda^\\top g(x)-\\lambda^\\top z\\ge b^\\top\\lambda+f(x_\\lambda)-\\lambda^\\top g(x_\\lambda)$$\r\n    Equality holds when $x=x_\\lambda$ and $(z,\\lambda)$ satisfies complementary slackness.\r\n    The rest follows.\r\n\\end{proof}\r\n\\begin{proof}[Proof of Theorem \\ref{barrier_method}]\r\n    Recall that a differentiable function on an open set has derivative $0$ on any of its local minima.\r\n    As $x_\\epsilon$ is optimal to the modified problem, we necessarily have\r\n    $$Df(x_\\epsilon)=-\\epsilon\\sum_{i=1}^m\\frac{Dg_i(x_\\epsilon)}{b_i-g(x_\\epsilon)}$$\r\n    So we set, for $i=1,\\ldots,m$ we define $\\lambda_i=-\\epsilon/(b_i-g_i(x_\\epsilon))$.\r\n    Then\r\n    $$Df(x_\\epsilon)=\\sum_{i=1}^m\\lambda_iDg_i(x_\\epsilon)$$\r\n    So by the preceding claim $\\lambda\\in\\Lambda$.\r\n    Therefore, by Theorem \\ref{weak_dual},\r\n    $$f(x_\\epsilon)\\ge f(x^\\star)\\ge h(\\lambda)=f(x_\\epsilon)+\\lambda^\\top(b-g(x_\\epsilon))=f(x_\\epsilon)-m\\epsilon$$\r\n    which is the bound we wanted.\r\n\\end{proof}\r\n\\begin{remark}\r\n    As $f$ and $g_i$ are convex for all $i$, the value function $\\phi(b)=\\inf\\{f(x):g(x)\\le b\\}$ is convex.\r\n    So by fixing $b$ and assuming there exists an optimiser $x^\\star$, Theorem \\ref{lagrange_nece} then tells us there is some $\\lambda^\\star$ with\r\n    $$L(x^\\star,z^\\star)=\\inf\\{L(x,z,\\lambda^\\star):x\\in\\mathbb R^n,z\\ge 0\\},z^\\star=b-g(x^\\star)$$\r\n\\end{remark}\r\nTheorem \\ref{barrier_method} inspires us to invent an algorithm to approach the optimal solution.\r\nPick an initial guess $x_0\\in\\mathbb R^n$ with $g(x_0)<b$ and some initial $\\epsilon_0>0$.\r\nFor $k\\ge 0$, we solve the modified problem with $\\epsilon=\\epsilon_k$ approximately (using e.g. gradient descent or Newton's method) starting from $x_k$.\r\nThen $x_{k+1}$ is defined to be the approximated optimal solution in this way, and reduce $\\epsilon$ by $\\epsilon_{k+1}=r\\epsilon_k$ for some $r\\in (0,1)$.", "meta": {"hexsha": "a4fb95f2f1acaaf4da8b29fecaed879d79f37308", "size": 19825, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/lagrange.tex", "max_stars_repo_name": "david-bai-notes/IB-Optimisation", "max_stars_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2/lagrange.tex", "max_issues_repo_name": "david-bai-notes/IB-Optimisation", "max_issues_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2/lagrange.tex", "max_forks_repo_name": "david-bai-notes/IB-Optimisation", "max_forks_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.8938356164, "max_line_length": 257, "alphanum_fraction": 0.6852459016, "num_tokens": 6268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.8791467675095294, "lm_q1q2_score": 0.8124562992649784}}
{"text": "\\section{Extreme Values}\r\nExtreme values of a function are the minimum and maximum values it attains on an interval.\r\nThe absolute extreme values would the the extreme values accross the function's entire domain.\r\n\r\n\\begin{example}\r\n\tFind the extreme values of $x^2$ over the following intervals.\r\n\t\\begin{enumerate}\r\n\t\t\\item $(-\\infty, \\infty)$\r\n\t\t\\item $[0,2]$\r\n\t\t\\item $(0,2]$\r\n\t\t\\item $(0,2)$\r\n\t\\end{enumerate}\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{enumerate}\r\n\t\t\\item For the max, there is no maximum value because we can keep increasing $x$ to get a larger output.\r\n\t\t\tThe min is 0 when $x=0$.\r\n\t\t\\item The max is 4 when $x=2$.\r\n\t\t\tThe min is 0 when $x=0$.\r\n\t\t\\item The max is 4 when $x=2$.\r\n\t\t\tAlthough the function approaches 0 in the limit as $x$ approaches 0, there is no min because 0 itself is not a value $x^2$ can take on the interval.\r\n\t\t\\item Although the function approaches 4 as $x$ approaches 2, there is no max because 4 itself is not a value $x^2$ can take on the interval.\r\n\t\t\tLike in the previous question, there is no min.\r\n\t\\end{enumerate}\r\n\tWe see that a function can fail to have a max or min value, but this cannot happen on a finite, closed interval.\r\n\\end{answer}\r\n\r\n\\begin{theorem}[Extreme Value Theorem]\r\n\tIf $f$ is continuous on some finite, closed interval $[a,b]$, then $f$ must have both a minimum and maximum value on the interval.\r\n\\end{theorem}\r\n\r\n\r\nWe can find these extreme values by following these steps.\r\n\\begin{enumerate}\r\n\t\\item Find any relative/local minima and maxima.\r\n\t\\item Find the function values for these local minima and maxima.\r\n\t\\item Find the function values at the endpoints of the interval, $a$ and $b$.\r\n\t\\item The smallest such function value will be the absolute minima, while the largest such function value will be the absolute maxima.\r\n\\end{enumerate}\r\n\r\n\\begin{theorem}\r\n\tIf a function $f$ has a local extrema at a point $c$ interior to its domain and $f^\\prime$ exists at $c$, then\r\n\t\\begin{equation*}\r\n\t\tf^\\prime(c) = 0.\r\n\t\\end{equation*}\r\n\\end{theorem}\r\n\r\nSo, the only candidate values we need to check are the endpoints and where the derivative is 0.\r\nSuch points are called critical points.\r\n\r\n\\begin{example}\r\n\tFind the absolute extrema of $y = x^3 + x^2 - 8x + 5$ on the interval $[-3,2]$.\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{enumerate}\r\n\t\t\\item We'll take the derivative to find all the critical points.\r\n\t\t\t\t$y^\\prime = 3x^2 + 2x - 8$, which is 0 when $x=-2$ and $x=4/3$.\r\n\t\t\\item $(-2)^3 + (-2)^2 - 8(-2) + 5 = 17$ and $(4/3)^3 + (4/3)^2 - 8(4/3) + 5 = -41/27$.\r\n\t\t\\item $(-3)^3 + (-3)^2 - 8(-3) + 5 = 11$ and $(2)^3 + (2)^2 - 8(2) + 5 = 1$.\r\n\t\t\\item Of these values, $(-2,17)$ is the absolute maxima and $(4/3, -41/27)$ is the absolute minima.\r\n\t\\end{enumerate}\r\n\\end{answer}", "meta": {"hexsha": "831ec6f62e8dc562efd8b43c44e19c9219415ae6", "size": 2761, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/applications_derivative/extreme_values.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/applications_derivative/extreme_values.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/applications_derivative/extreme_values.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 44.5322580645, "max_line_length": 152, "alphanum_fraction": 0.676928649, "num_tokens": 870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.8791467548438124, "lm_q1q2_score": 0.8124562857232994}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let $A=\\begin{mymatrix}{ccc} 1 & 1 & 0 \\\\ 1 & 2 & 0 \\\\ 0 & 0 &\n    2 \\end{mymatrix}$, and consider $\\R^3$ with the inner product given by\n  $\\iprod{\\vect{u},\\vect{v}} = \\vect{u}^TA\\vect{v}$. Which of the\n  following vectors are orthogonal to each other?\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{c}  1 \\\\  1 \\\\  1 \\end{mymatrix},\\quad  % 2,  3,   2\n    \\vect{u}_2 = \\begin{mymatrix}{c} -1 \\\\  2 \\\\ -2 \\end{mymatrix},\\quad  % 1,  3,  -4\n    \\vect{u}_3 = \\begin{mymatrix}{c}  7 \\\\ -5 \\\\ -2 \\end{mymatrix},\\quad  % 2, -3,  -4\n    \\vect{u}_4 = \\begin{mymatrix}{c} 10 \\\\ -2 \\\\ -7 \\end{mymatrix}.       % 8,  6, -14\n  \\end{equation*}\n  \\begin{sol}\n    We have\n    $\\iprod{\\vect{u}_1,\\vect{u}_2} = \\vect{u}_1^T A \\vect{u}_2 = 0$,\n    $\\iprod{\\vect{u}_1,\\vect{u}_3} = \\vect{u}_1^T A \\vect{u}_3 = -5$,\n    $\\iprod{\\vect{u}_1,\\vect{u}_4} = \\vect{u}_1^T A \\vect{u}_4 = 0$,\n    $\\iprod{\\vect{u}_2,\\vect{u}_3} = \\vect{u}_2^T A \\vect{u}_3 = 0$,\n    $\\iprod{\\vect{u}_2,\\vect{u}_4} = \\vect{u}_2^T A \\vect{u}_4 = 32$,\n    and\n    $\\iprod{\\vect{u}_3,\\vect{u}_4} = \\vect{u}_3^T A \\vect{u}_4 = 54$.\n    Therefore, $\\vect{u}_1\\orth\\vect{u}_2$,\n    $\\vect{u}_1\\orth\\vect{u}_4$, and $\\vect{u}_2\\orth\\vect{u}_3$. None\n    of the other pairs of vectors are orthogonal.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  On $C[-1,1]$, which of the following functions are orthogonal to each other?\n  \\begin{equation*}\n    f_1(x) = x,\\quad\n    f_2(x) = x^2,\\quad\n    f_3(x) = x^3-x,\\quad\n    f_4(x) = 1-x^4.\n  \\end{equation*}\n  \\begin{sol}\n    $f_1\\orth f_2$, $f_1\\orth f_4$, $f_2\\orth f_3$, and $f_3\\orth f_4$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the inner product space $\\Poly_3$ of polynomials of degree\n  at most $3$, with the inner product defined by\n  \\begin{equation*}\n    \\iprod{f,g} = \\int_{-1}^{1} f(x)g(x)\\,dx.\n  \\end{equation*}\n  \\begin{enumerate}\n  \\item Find the orthogonal complement of $\\set{x^2,x}$.\n  \\item Find the orthogonal complement of $\\set{x+1}$.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item Let $p(x)=ax^3+bx^2+cx+d$. Then\n      $\\iprod{p(x), x^2} = \\frac{2}{5}b + \\frac{2}{3}d$ and\n      $\\iprod{p(x), x} = \\frac{2}{5}a + \\frac{2}{3}c$.  Therefore,\n      $p(x)$ is in the orthogonal complement of $\\set{x^2,x}$ if and\n      only if $\\frac{2}{5}b + \\frac{2}{3}d=0$ and\n      $\\frac{2}{5}a + \\frac{2}{3}c=0$. It follows that\n      $b=-\\frac{5}{3}d$ and $a=-\\frac{5}{3}c$. The general solution is\n      $p(x) = -\\frac{5}{3}cx^3 - \\frac{5}{3}dx^2 + cx + d$. A basis\n      for the orthogonal complement is\n      $\\set{-\\frac{5}{3} x^3 + x, -\\frac{5}{3} x^2 + 1}$.\n    \\item A basis for the orthogonal complement of $\\set{x+1}$ is\n      $\\set{5x^3-1, 3x^2-1, 3x-1}$.      \n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider $\\R^3$ as an inner product space with the usual dot\n  product.  For each of the following bases of $\\R^3$, state whether\n  it is orthonormal, orthogonal, or neither.\n  \\begin{enumerate}\n  \\item $\\set{\n      \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    }$.\n  \\item $\\set{\n      \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    }$.\n  \\item $\\set{\n      \\begin{mymatrix}{r}  1 \\\\ 0 \\\\ 2 \\end{mymatrix},\n      \\begin{mymatrix}{r}  0 \\\\ 1 \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} -2 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    }$.\n  \\item $\\def\\arraystretch{1.2}\n    \\set{\n      \\begin{mymatrix}{r} \\frac{3}{5} \\\\ \\frac{4}{5} \\\\ 0 \\end{mymatrix},\n      \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ -1 \\end{mymatrix},\n      \\begin{mymatrix}{r} \\frac{4}{5} \\\\ -\\frac{3}{5} \\\\ 0 \\end{mymatrix}\n    }$.\n  \\end{enumerate}\n  \\begin{sol}\n    (a) Orthonormal (therefore also orthogonal). (b) Neither\n    orthogonal nor orthonormal. (c) Orthogonal (not orthonormal). (d)\n    Orthonormal (therefore also orthogonal).\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $B=\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$ is an orthogonal\n  basis for an inner product space $V$, such that\n  $\\norm{\\vect{u}_1}=2$, $\\norm{\\vect{u}_2}=\\sqrt{3}$, and\n  $\\norm{\\vect{u}_3}=\\sqrt{5}$.  Moreover, suppose that\n  $\\vect{v}\\in V$ is a vector such that\n  $\\iprod{\\vect{v},\\vect{u}_1} = 1$,\n  $\\iprod{\\vect{v},\\vect{u}_2} = 2$, and\n  $\\iprod{\\vect{v},\\vect{u}_3} = -4$.  Find the coordinates of\n  $\\vect{v}$ with respect to $B$.\n  \\begin{sol}\n    $\\vect{v} = \\frac{1}{4}\\vect{u}_1 + \\frac{2}{3}\\vect{u}_2 - \\frac{4}{5}\\vect{u}_3$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $B=\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$ is an\n  orthogonal basis of $\\R^3$. We have been told that\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix},\n  \\end{equation*}\n  but it is not known what $\\vect{u}_2$ and $\\vect{u}_3$ are. Find the\n  first coordinate of the vector\n  \\begin{equation*}\n    \\vect{v} = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 2 \\end{mymatrix}\n  \\end{equation*}\n  with respect to the basis $B$.\n  \\begin{sol}\n    We have $\\vect{v} = a_1\\vect{u}_1 + a_2\\vect{u}_2 + a_3\\vect{u}_3$\n    where\n    $a_1 =\n    \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\n    = \\frac{1}{2}$. So the first coordinate is $\\frac{1}{2}$.\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "5dc760c0cb532e295d82caefe16d96fb6b9da7a3", "size": 5320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/InnerProductSpaces-Orthogonality.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/InnerProductSpaces-Orthogonality.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/InnerProductSpaces-Orthogonality.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 38.273381295, "max_line_length": 87, "alphanum_fraction": 0.5687969925, "num_tokens": 2320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.8124026951823877}}
{"text": "\n\\subsection{Metrics}\n\nWe defined a norm as:\n\n\\(||v||=v^TMv\\)\n\nA metric is the distance between two vectors.\n\n\\(d(u,v)=||u-v||=(u-v)^TM(u-v)\\)\n\n\\subsubsection{Metric space}\n\nA set with a metric is a metric space.\n\n", "meta": {"hexsha": "150d6648de29283395d6acce025ec3f1ddf788bb", "size": 214, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/affineEuclid/01-01-metricSpace.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/affineEuclid/01-01-metricSpace.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/affineEuclid/01-01-metricSpace.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.375, "max_line_length": 45, "alphanum_fraction": 0.6495327103, "num_tokens": 67, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.967410256173572, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.8123672586036155}}
{"text": "\\subsubsection{Second Derivative Test \\& Hessian Matrix}\r\n\\noindent\r\nRecall from single-variable calculus that if we have a critical point (derivative is 0), we can find whether the point is a minimum or maximum by using the second derivative test.\r\nIf the second derivative is negative at the critical point, then the critical point is a maximum, and if the second derivative is positive at the critical point, then the critical point is a minimum.\r\nA similar process works in higher dimensions.\\\\\r\n\r\n\\noindent\r\nIn higher dimensions:\r\n\\begin{itemize}\r\n\t\\item If $f_{xx}$ and $f_{yy}$ are positive at a critical point, then the critical point is a minimum.\r\n\t\\item If $f_{xx}$ and $f_{yy}$ are negative at a critical point, then the critical point is a maximum.\r\n\t\\item If $f_{xx}$ and $f_{yy}$ don't agree on sign, then the point is a saddle point.\r\n\\end{itemize}\r\n\r\n\\noindent\r\nAlthough there are only 3 options for what a critical point on a surface can be, we need a process of identifying them that works for for higher dimensional objects too.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics*[width=0.9\\textwidth]{./Images/differentialMultivariableCalculus/second_derivative_test.png}\r\n\t\\caption{Three possibilities depending on signs of the seconds derivative}\r\n\\end{figure}\r\n\r\n\\begin{definition}\r\n\tThe Hessian Matrix (for $f(x,y)$):\r\n\t\\begin{equation*}\r\n\t\tH = \\begin{bmatrix}\r\n\t\t\tf_{xx} & f_{xy} \\\\\r\n\t\t\tf_{yx} & f_{yy} \r\n\t\t\\end{bmatrix}\r\n\t\\end{equation*} \r\n\\end{definition}\r\n\\noindent\r\nNote that $\\det{H} = f_{xx}f_{yy} - f_{xy}^2$.\\\\\r\n\r\n\\noindent\r\nIf $(x_0, y_0)$ is a critical point:\r\n\\begin{itemize}\r\n\t\\item $\\det{H(x_0,y_0) > 0}$ means $(x_0, y_0)$ is an extrema. \r\n\t\\begin{itemize}\r\n\t\t\\item If $f_{xx}(x_0, y_0) > 0$, then $(x_0, y_0)$ is a minima.\r\n\t\t\\item If $f_{xx}(x_0, y_0) < 0$, then $(x_0, y_0)$ is a maxima.\r\n\t\\end{itemize}\r\n\t\\item $\\det{H(x_0, y_0)} < 0$ means $(x_0, y_0)$ is a saddle point.\r\n\t\\item $\\det{H(x_0, y_0)} = 0$ means the 2nd derivative test is inconclusive.\r\n\\end{itemize}\r\n", "meta": {"hexsha": "e8004c451ea881acd515a5ed30bc27cf1b622cb2", "size": 2014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/2ndDerivativeTestHessianMatrix.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/2ndDerivativeTestHessianMatrix.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/2ndDerivativeTestHessianMatrix.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.8510638298, "max_line_length": 200, "alphanum_fraction": 0.6996027805, "num_tokens": 638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961707, "lm_q2_score": 0.90192067257508, "lm_q1q2_score": 0.8122064400003024}}
{"text": "\\section{09/07}\n\\begin{definition}{Random Variable}{}\n    A \\emph{random variable} is a function from some sample space $S$ to a set\n    of numbers.\n\\end{definition}\n\n\\begin{definition}{Probability of a Random Variable}{}\n    Let $X:\\Omega \\to E$ be some random variable and let $S \\subseteq E$. Then\n    \\[\\prob{X \\in S} = \\prob{\\omega \\in \\Omega \\suchthat X(\\omega) \\in S}\\]\n    If $S$ is a discrete probability space, then\n    \\[\\prob{X = r} = \\sum_{X(\\omega) = r}\\prob{\\omega}\\]\n\\end{definition}\n\nFor example, let us roll a fair die and say, should you roll $i$, you receive\n$i^2$ dollars. We can define the random variable $X$ to be the money received in\nthis dice game. Then\n\\[\\prob{X = 25} = \\prob{\\text{roll} = 5} = \\frac{1}{6}\\]\n\nOn the other hand, say you receive $i$ dollars (that is, the face of the die\nroll). Then\n\\[\\prob{X \\equiv 0 \\bmod{2}} = \\prob{\\text{die} \\in \\set{2, 4, 6}} = \\frac{1}{2}\\]\n\nSuppose we additionally roll a second die and call the random variable equal to\nthe face-value of this die $Y$. What is $\\prob{X + Y = 7}$? Say $R(i, j)$ is the\nevent that the first die rolls $i$ and the second rolls $j$. Then\n\n\\begin{align*}\n    \\prob{X + Y = 7} &= \\prob{R(1, 6) \\cup R(2, 5) \\cup R(3, 4) \\cup R(4, 3) \\cup R(5, 2) \\cup R(6, 1)}\\\\\n                    &= \\prob{R(1, 6)} + \\prob{R(2, 5)} + \\prob{R(3, 4)} + \\prob{R(4, 3)} + \\prob{R(5, 2)} + \\prob{R(6, 1)}\\\\\n                    &= \\frac{6}{36}\\\\\n                    &= \\frac{1}{6}\n\\end{align*}\n\n\\subsection{Expected Value}\n\\begin{definition}{Expected Value}{}\n    Let $X$ be a discrete random variable on a sample space $S$. The\n    \\emph{expected value} (also called mean or average) of $X$ is defined\n    \\[\\expectation{X} = \\sum_{r\\in X(S)}r\\prob{X = r}\\]\n\\end{definition}\nFor example, if $X$ is the face-value of a fair die, then\n\\[\\expectation{X} = \\sum_{i=1}^6i\\prob{X = i} = 1\\cdot\\frac{1}{6} + 1\\cdot\\frac{1}{6} + \\dots + 6\\cdot\\frac{1}{6} = \\frac{7}{2}\\]\nNotice that $\\sfrac{7}{2}$ is \\emph{not} an event in our sample space. In\ngeneral, the expectation does not need to be a value that can be ``achieved.''\nInstead, the Law of Large Numbers formalizes the idea of what expectation is.\n\n\\begin{theorem}{Law of Large Numbers}{}\n    Let $X_1$, $X_2$, \\dots, $X_n$ denote the outcomes of $n$ independent\n    experiments, and suppose that experiment has expected value $\\mu$. Let\n    $\\overline{X}_n$ denote our \\emph{sample mean}, i.e., write\n    \\[\\overline{X}_n = \\frac{1}{n}\\sum_{i=1}^nX_i\\]\n    Then\n    \\[\\lim_{n \\to \\infty}\\prob{\\overline{X}_n = \\mu} = 1\\]\n\\end{theorem}\n\nConsider the following game: flip two fair coins. If both come up heads, win\n\\$2, otherwise lose \\$1. Let $X$ denote the amount of money the player wins.\nThen\n\\[\\expectation{X} = 2 \\cdot \\frac{1}{4} + -1\\cdot\\frac{3}{4} = \\frac{-1}{4}\\]\n\nWe can define independence for random variables in the same way we did for\nevents.\n\\begin{definition}{Independent Random Variables}{}\n    Two random variables $X$ and $Y$ on a sample space $S$ are independent if\n    \\[\\prob{X = x \\cap Y = y} = \\prob{X = x}\\prob{Y = y}\\]\n    for all $x \\in X(S)$ and $y \\in Y(S)$\n\\end{definition}\n\n\\subsection{Linearity of Expectation}\nThe following theorem proves very useful in analyzing randomized algorithms.\n\\begin{theorem}{Linearity of Expectation}{linexp}\n    For any random variables $X$ and $Y$ and real value $c$\n    \\begin{align*}\n        \\expectation{X + Y} &= \\expectation{X} + \\expectation{Y}\\\\\n        \\expectation{cX} &= c\\expectation{X}\n    \\end{align*}\n\\end{theorem}\n\n\\begin{proof}\n    By definition\n    \\begin{align*}\\expectation{X + Y}\n        &= \\sum_{x \\in X(S)}\\sum_{y \\in Y(S)} (x + y)\\prob{X = x \\cap Y = y}\\\\\n        &= \\sum_{x \\in X(S)}\\sum_{y \\in Y(S)} x\\prob{X = x \\cap Y = y} + \\sum_{x \\in X(S)}\\sum_{y \\in Y(S)}y\\prob{X = x \\cap Y = y}\\\\\n        &=\\sum_{x \\in X(S)}\\sum_{y \\in Y(S)} x\\prob{X = x \\cap Y = y} + \\sum_{y \\in Y(S)}\\sum_{x \\in X(S)}y\\prob{X = x \\cap Y = y}\\\\\n        &=\\sum_{x \\in X(S)}x\\sum_{y \\in Y(S)} \\prob{X = x \\cap Y = y} + \\sum_{y \\in Y(S)}y\\sum_{x \\in X(S)}\\prob{X = x \\cap Y = y}\\\\\n        &=\\sum_{x \\in X(S)}x\\prob{X = x} + \\sum_{y \\in Y(S)}y\\prob{Y = y} \\hbox{ by the law of total probability}\\\\\n        &=\\expectation{X} + \\expectation{Y}\n    \\end{align*}\n    Similarly,\n    \\begin{align*}\\expectation{cX}\n        &=\\sum_{x \\in X(S)}cx\\prob{X = x}\\\\\n        &=c\\sum_{x \\in X(S)}x\\prob{X = x}\\\\\n        &=c\\expectation{X}\\qedhere\n    \\end{align*}\n\\end{proof}\n\nThe power of \\nameref{thm:linexp} can be seen by considering the following\nscenario: suppose we flip $n$ fair coins and wish to count the expected number\nof heads, $X$. Without \\cref{thm:linexp}, this is\n\\[\\expectation{X} = \\sum_{i=0}^ni\\binom{n}{i}\\left(\\frac{1}{2}\\right)^n\\]\na computationally difficult expression. On the other hand, if we let $X_i$\ndenote the following random variable\n\\[X_i = \\begin{cases}1 & \\hbox{coin $i$ lands heads}\\\\\n                     0 & \\hbox{otherwise}\\end{cases}\\]\nIt should be quite clear that\n\\[X = \\sum_{i=1}^n X_i\\]\nNow,\n\\begin{align*}\\expectation{X_i}\n    &=1\\prob{X_i = 1} + 0\\prob{X_i = 0}\\\\\n    &=\\frac{1}{2}\n\\end{align*}\nhence\n\\[\\expectation{X} = \\sum_{i=1}^n\\expectation{X_i} = \\frac{n}{2}\\]\nan almost \\emph{trivial} computation.\n\nThe above random variable $X_i$ is called a Bernoulli or \\emph{indicator} random\nvariable, since it \\emph{indicates} whether the desired outcome occurred. In\ngeneral, if $X$ is an indicator random variable, then \n\\[\\expectation{X} = \\prob{X = 1}\\]\n\nWe can similarly demonstrate the power of \\nameref{thm:linexp} with the\nfollowing problem: suppose $n$ people arrive at a party and drop off their\ncoats, for which they receive a receipt. Unfortunately, the attendant loses all\nof the stubs and decides to assign the party-goers coats at random. What is the\nexpected number of people who receive their original coat?\n\nLet $X$ denote the number of people who receive their own coats. Then\n\\[\\expectation{X} = \\sum_{i=0}^n i \\prob{X = i}\\]\nNotice that, for general $i$, this is impractical to determine. In fact, the\nnumber $D_{n, k}$ is called a \\emph{rencontres number}, and denote the number of\npermutations of $\\set{1, 2, \\dots, n}$ with exactly $k$ fixed points. This can\nbe recursively computed with\n\\[D_{n, k} = \\binom{n}{k}D_{n-k,0}\\]\nHowever, we can determine $\\expectation{X}$ by applying \\nameref{thm:linexp}.\nDefine\n\\[X_i = \\begin{cases}1 & \\hbox{person $i$ receives their own coat}\\\\\n    0 & \\hbox{otherwise}\\end{cases}\\]\nand observe that $X = \\sum X_i$. Additionally,\n\\[\\expectation{X_i} = \\prob{X_i = 1} = \\frac{(n - 1)!}{n!} = \\frac{1}{n}\\]\nfrom which it follows that\n\\[\\expectation{X} = \\sum_{i=1}^n \\expectation{X_i} = n\\frac{1}{n}=1\\]\n\n\\subsection{3-SAT}\n\\begin{problem}{Boolean Satisfiability}{}\n    Given a boolean formula, determine if there exists an assignment of the\n    variables that causes the formula to evaluate to \\True.\n\\end{problem}\nA formula is in \\emph{Conjunctive Normal Form} (CNF) if it can be written as a\ndisjunction of conjunctions, that is, a formula $B$ is in CNF if\n\\[B = T_1 \\land T_2 \\land \\dots \\land T_n\\]\nand each $T_i$ is of the form $t_1 \\lor t_2 \\lor \\dots \\lor t_i$. We say a\nformula is $k$-CNF if each $T_i$ consists of exactly $k$ conjunctions. \n\nIt turns out that this problem is equivalent to the \\emph{3-SAT} problem.\n\\begin{theorem}{}{}\n    Given a boolean formula $B$, there is an \\emph{equisatisfiable} formula $B'$\n    in 3CNF whose length is at most 3 times that of $B$. That is, the formula\n    $B$ is satisfiable if and only if $B'$ is satisfiable.  \n\\end{theorem}\n\\begin{proof}\n    Consider some clause of conjunctions $l_1 \\lor l_2 \\lor \\dots \\lor l_n$.\n    The formula\n    \\begin{align*}\n              & (l_1 \\lor l_2 \\lor x_2)\\\\\n        \\land & (\\neg x_2 \\lor l_3 \\lor x_3)\\\\\n        \\land & (\\neg x_3 \\lor l_4 \\lor x_4)\\\\\n        \\vdots &\\\\\n        \\land & (\\neg x_{n-3} \\lor l_{n-2} \\lor x_{n-2})\\\\\n        \\land & (\\neg x_{n-2} \\lor l_{n-1} \\lor l_n)\n    \\end{align*}\n    is equisatisfiable to the clause.\n\\end{proof}\n\n\\begin{problem}{Max 3-SAT}{}\n    Given a 3-SAT problem, find an assignment of the variables that\n    \\emph{maximizes} the number of clauses that evaluate to \\True.\n\\end{problem}\n\nConsider an algorithm where we simply assign each variable 0 or 1 at random. For\nclause $i$, define\n\\[X_i = \\begin{cases}1 & \\hbox{clause $i$ is satisfied}\\\\\n                     0 & \\hbox{otherwise}\\end{cases}\\]\nAnd set $X = \\sum X_i$ to be the number of satisfied clauses. Suppose clause $i$\nis $a \\lor b \\lor c$. Then\n\\begin{align*}\\expectation{X_i}\n    &= \\prob{a \\lor b \\lor c}\\\\\n    &= 1 - \\prob{\\neg a \\land \\neg b \\land \\neg c}\\\\\n    &= 1 - \\left(\\frac{1}{2}\\right)^3\\\\\n    &= \\frac{7}{8}\n\\end{align*}\nThus\n\\[\\expectation{X} = \\sum_{i=1}^m \\expectation{X_i} = \\frac{7m}{8}\\]\n\n\\subsection{Probabilistic Method}\nThe \\emph{Probabilistic Method} is a nonconstructive method to demonstrate the\nexistence of some sort of mathematical object. This is done by creating a\nprobability distribution on some sample space and showing that such an object\nexists with probability greater than 0, from which you conclude that at least\none such object exists.\n\n\\begin{theorem}{}{}\n    There is at least one assignment of variables that has $\\sfrac{7m}{8}$ true\n    clauses.\n\\end{theorem}\n\nTo see this, simply note that if $\\expectation{X} = \\mu$, there must be at least\none value in the sample space whose value is greater than or equal to $\\mu$ and\nat least one whose value is less than or equal to $\\mu$.", "meta": {"hexsha": "e3b05c432e4b064e111a3d35a92d1125359e6a46", "size": 9487, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/0907.tex", "max_stars_repo_name": "khalid-salad/Randomized-Algorithms-Notes", "max_stars_repo_head_hexsha": "2556b9d8ede2f3c10960949680f077a8d7e37196", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-28T23:46:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-28T23:46:42.000Z", "max_issues_repo_path": "tex/0907.tex", "max_issues_repo_name": "khalid-salad/Randomized-Algorithms-Notes", "max_issues_repo_head_hexsha": "2556b9d8ede2f3c10960949680f077a8d7e37196", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/0907.tex", "max_forks_repo_name": "khalid-salad/Randomized-Algorithms-Notes", "max_forks_repo_head_hexsha": "2556b9d8ede2f3c10960949680f077a8d7e37196", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.8309178744, "max_line_length": 133, "alphanum_fraction": 0.6448824707, "num_tokens": 3276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542185, "lm_q2_score": 0.8757870013740061, "lm_q1q2_score": 0.8121727216368979}}
{"text": "\\subsection{Complex numbers}\n\nWhen Eigenmath starts up, it defines symbol $i$ as $i=\\sqrt{-1}$.\nSymbol $i$ can be redefined and used for some other purpose if need be.\n\n\\bigskip\n\\noindent\nComplex quantities can be entered in either rectangular or polar form.\n\n{\\color{blue}\n\\begin{verbatim}\na + i b\n\\end{verbatim}\n}\n\n\\noindent\n$a+ib$\n\n{\\color{blue}\n\\begin{verbatim}\nexp(1/3 i pi)\n\\end{verbatim}\n}\n\n\\noindent\n$\\exp\\left(\\tfrac{1}{3}i\\pi\\right)$\n\n\\bigskip\n\\noindent\nConverting a complex number to rectangular or polar coordinates causes\nsimplification of mixed forms.\n\n{\\color{blue}\n\\begin{verbatim}\nA = 1 + i\nB = sqrt(2) exp(1/4 i pi)\nA - B\n\\end{verbatim}\n}\n\n\\noindent\n$1+i-2^{1/2}\\exp\\left(\\tfrac{1}{4}i\\pi\\right)$\n\n{\\color{blue}\n\\begin{verbatim}\nrect(last)\n\\end{verbatim}\n}\n\n\\noindent\n$0$\n\n\\bigskip\n\\noindent\nRectangular complex quantities, when raised to a power, are multiplied out.\n\n{\\color{blue}\n\\begin{verbatim}\n(a + i b)^2\n\\end{verbatim}\n}\n\n\\noindent\n$a^2-b^2+2iab$\n\n\\bigskip\n\\noindent\nWhen $a$ and $b$ are numerical and the power is negative, the evaluation is done as follows.\n\\begin{equation*}\n(a+ib)^{-n}\n=\\left(\\frac{a-ib}{(a+ib)(a-ib)}\\right)^n=\n\\left(\\frac{a-ib}{a^2+b^2}\\right)^n\n\\end{equation*}\n\n\\noindent\nHere are a few examples.\n\n{\\color{blue}\n\\begin{verbatim}\n1/(2 - i)\n\\end{verbatim}\n}\n\n\\noindent\n$\\tfrac{2}{5}+\\frac{1}{5}i$\n\n{\\color{blue}\n\\begin{verbatim}\n(-1 + 3 i)/(2 - i)\n\\end{verbatim}\n}\n\n\\noindent\n$-1+i$\n\n\\bigskip\n\\noindent\nThe absolute value of a complex number returns its magnitude.\n\n{\\color{blue}\n\\begin{verbatim}\nabs(3 + 4 i)\n\\end{verbatim}\n}\n\n\\noindent\n$5$\n\n\\bigskip\n\\noindent\nThe imaginary unit can be changed from $i$ to $j$\nby defining $j=\\sqrt{-1}$.\n\n{\\color{blue}\n\\begin{verbatim}\nj = sqrt(-1)\nsqrt(-4)\n\\end{verbatim}\n}\n\n\\noindent\n$\\displaystyle 2j$\n", "meta": {"hexsha": "3459e3e5b9952fd5957144c076dde8b335b60c4d", "size": 1788, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/complex.tex", "max_stars_repo_name": "wuyudi/eigenmath", "max_stars_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2019-09-29T03:15:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T00:57:51.000Z", "max_issues_repo_path": "doc/complex.tex", "max_issues_repo_name": "wuyudi/eigenmath", "max_issues_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2019-11-12T00:57:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T23:46:46.000Z", "max_forks_repo_path": "doc/complex.tex", "max_forks_repo_name": "wuyudi/eigenmath", "max_forks_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2019-10-03T13:23:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T13:28:00.000Z", "avg_line_length": 14.5365853659, "max_line_length": 92, "alphanum_fraction": 0.6834451902, "num_tokens": 631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.8121727020944508}}
{"text": "\\input{../common/common.tex}\n\n\\title{Math notes - Fibolucci}\n\\author{Uwe Hoffmann}\n\\hypersetup{colorlinks, pdftitle={Math notes - Fibolucci}}\n\n\\begin{document}\n\n\\setcounter{chapter}{1}\n\\section*{Fibolucci}\n\n\\newthought{Exercise `Fibolucci'} in \\textit{Programming, The Derivation of Algorithms}\\cite{Kaldewaij90}.\\index{Fibolucci}\n\n\\vspace{10 mm}\n\\begin{problem}\nWrite a program that calculates the function \n\n\\begin{equation*}\nf(n) = \\sum_{i = 0}^{n} \\mathit{fib}(i) \\mathit{fib}(n - i)  \\text{, for } n \\geq 0\n\\end{equation*}\nwhere $\\mathit{fib}$ is the Fibonacci sequence defined by:\n\\begin{equation*}\n\\begin{split}\n& \\mathit{fib}(0) = 0 \\\\\n& \\mathit{fib}(1) = 1 \\\\\n& \\mathit{fib}(n + 2) = \\mathit{fib}(n + 1) + \\mathit{fib}(n) \\text{, for } n \\geq 0\n\\end{split}   \n\\end{equation*}\n\n\\end{problem}\n\nTo solve the Fibolucci sum we adopt the same notation used in \\textit{Programming in the 1990s}\\cite{Cohen90}: The notation of function application is the \"dot\" notation with name of function, followed by arguments, each separated by a dot. The notation of quantified expressions has the operator followed by the bounded variables, then a colon followed by the range for the bounded variables and ended with a colon and the actual expression. So\n\n\\[\t \n\t(\\sum k : i \\leq k < j : x_k)\n\\]\n\n\\noindent corresponds to the more classical mathematical notation $\\sum_{k = i}^{ j - 1}x_k$. \n\nFor our derivation steps in predicate calculus we will use the following notation:\n\n\\[\n\\begin{array}{lcl}\n\t\t&&A \\\\\n\t      &=& { < \\mbox{reason why A equals B } >} \\\\      \n                  &&B \\\\\n                &\\leq& { < \\mbox{reason why B is less than C} >} \\\\\n                  && C  \n   \\end{array}\n\\]\n\nWe start by finding a recursive expression for $f$. We will use properties of quantified expressions as covered in Chapter 3 of \\textit{Programming in the 1990s}\\cite{Cohen90}. Since $ \\mathit{fib}.(0) = 0$ we can use an equivalent definition expression for $f$:\n\\[\nf(n) = (\\sum i: 1 \\leq i < n: \\mathit{fib}.i\\  \\mathit{fib}.(n - i))\n\\]\n\nWe derive:\n\\[\n\\begin{array}{lcl}\n\t\t&&f.(n + 2) \\\\\n\t      &=& { < \\text{definition of  } f\\ >} \\\\      \n                  && (\\sum i: 1 \\leq i < n + 2: \\mathit{fib}.i\\  \\mathit{fib}.(n + 2 - i))\\\\\n                &=& { < \\text{range split, 1-point rule} >} \\\\\n                  &&  (\\sum i: 1 \\leq i < n + 1: \\mathit{fib}.i\\  \\mathit{fib}.(n + 2 - i)) + \\mathit{fib}.(n+ 1)\\  \\mathit{fib}.(1) \\\\\n                &=& { <\\  \\mathit{fib}.(1) = 1\\  >} \\\\ \n                   && (\\sum i: 1 \\leq i < n + 1: \\mathit{fib}.i\\  \\mathit{fib}.(n + 2 - i)) + \\mathit{fib}.(n+ 1)\\\\\n\t       &=& { < \\text{definition of } \\mathit{fib}\\ >} \\\\\n\t       \t&& (\\sum i: 1 \\leq i < n + 1: \\mathit{fib}.i\\  (\\mathit{fib}.(n + 1 - i) + \\mathit{fib}.(n - i))) + \\mathit{fib}.(n+ 1)\\\\\n\t      &=& { < \\text{splitting the term} >} \\\\\n\t       \t&& (\\sum i: 1 \\leq i < n + 1: \\mathit{fib}.i\\  \\mathit{fib}.(n + 1 - i))\\ + \\\\\n\t\t&& (\\sum i: 1 \\leq i < n + 1: \\mathit{fib}.i\\  \\mathit{fib}.(n - i)) + \\mathit{fib}.(n+ 1)\\\\\t      &=& { < \\text{definition of } f\\ >} \\\\\n\t       \t&& f.(n + 1) +  (\\sum i: 1 \\leq i < n + 1: \\mathit{fib}.i\\  \\mathit{fib}.(n - i)) + \\mathit{fib}.(n+ 1) \\\\\n\t      &=& { < \\text{range split, 1-point rule, } \\mathit{fib}.(0) = 0\\  >} \\\\\n                  && f.(n + 1) +  (\\sum i: 1 \\leq i < n: \\mathit{fib}.i\\  \\mathit{fib}.(n - i)) + \\mathit{fib}.(n+ 1) \\\\\n               &=& { < \\text{definition of } f\\ >} \\\\\n\t       \t&& f.(n + 1) +  f.n + \\mathit{fib}.(n+ 1)   \n   \\end{array}\n\\]\n\nWe get the recursive definition of $f$:\n\\begin{equation*}\n\\begin{split}\n& f.0 = 0 \\\\\n& f.1 = 0 \\\\\n& f.(n + 2) = \\mathit{fib}.(n + 1) + f.(n + 1) + f.n \\text{, for } n \\geq 0\n\\end{split}   \n\\end{equation*}\n\nIt is straightforward to write a program that computes $f$ from this recursive definition, either iteratively with a loop that step by step computes next values of $f$ starting with $f(2)$ and remembering the last two computed values of $f$ and of $\\mathit{fib}$ for the next computations, or in Haskell by simply declaring the above recursions for $f$ and $\\mathit{fib}$. This will lead to a runtime of $O(n)$. But can we do better than linear ?\n\nLet's look again at the recursive expressions of the two functions involved, leaving out the base cases and computing one additional next value:\n\n\\begin{equation*}\n\\begin{split}\n& f.(n + 2) = \\mathit{fib}.(n + 1) + f.(n + 1) + f.n \\\\\n& f.(n + 3) = \\mathit{fib}.(n + 2) + f.(n + 2) + f.(n + 1) \\\\\n& \\mathit{fib}.(n + 2) = \\mathit{fib}.(n + 1) + \\mathit{fib}.n \\\\\n& \\mathit{fib}.(n + 3) = \\mathit{fib}.(n + 2) + \\mathit{fib}.(n + 1)\n\\end{split}   \n\\end{equation*}\n\nThe key observation we can make here is that new values of the two functions are linear combinations of previously computed values. Linear combinations implies linear applications with matrix representations from linear algebra. How many previously computed values, i.e. how far back do we need to go: we need the last computed value last and the value computed before that, so 2 previous values. Looks like we could try something in a linear space of dimension 2. \n\nLet's try first with $\\mathit{fib}$ which is simpler and doesn't depend on $f$. We define the function $\\mathit{Fib}: \\mathbb{N}  \\rightarrow \\mathbb{N}^2$ into the two-dimensional space $\\mathbb{N}^2$:\n\n\\[\n  \\mathit{Fib}.n = \n  \\begin{pmatrix}\n       \\mathit{fib}.n \\\\\n       \\mathit{fib}.(n + 1)\n   \\end{pmatrix}   \\text{, for } n \\geq 0 \n\\]\n\nFor a recursive expression for $\\mathit{Fib}$ we have:\n\\[\n\\begin{array}{lcl}\n  &&\\mathit{Fib}.(n + 1) \\\\\n   &=& { < \\text{definition of  } \\mathit{Fib}\\ >} \\\\ \n  &&\\begin{pmatrix}\n       \\mathit{fib}.(n + 1) \\\\\n       \\mathit{fib}.(n + 2)\n   \\end{pmatrix} \\\\\n   &=& { < \\text{definition of  } \\mathit{fib}\\ >} \\\\ \n   &&\\begin{pmatrix}\n       \\mathit{fib}.(n + 1) \\\\\n       \\mathit{fib}.(n + 1) + \\mathit{fib}.n\n   \\end{pmatrix} \\\\\n   &=& { < \\text{matrix multiplication}  >} \\\\ \n   &&\\begin{pmatrix}\n       0 & 1 \\\\\n       1 & 1\n   \\end{pmatrix} \n   \\begin{pmatrix}\n        \\mathit{fib}.n \\\\\n       \\mathit{fib}.(n + 1)\n   \\end{pmatrix} \\\\\n   &=& { < \\text{definition of  } \\mathit{Fib}\\ >} \\\\ \n   &&\\begin{pmatrix}\n       0 & 1 \\\\\n       1 & 1\n   \\end{pmatrix} \\mathit{Fib}.n\n  \\end{array}\n\\]\n\nSo \n\\[\n  \\mathit{Fib}.(n + 1) = \n  \\begin{pmatrix}\n       0 & 1 \\\\\n       1 & 1\n   \\end{pmatrix}   \\mathit{Fib}.n = \\ldots = \n   \\begin{pmatrix}\n       0 & 1 \\\\\n       1 & 1\n   \\end{pmatrix} ^{n + 1}  \\mathit{Fib}.0\n\\]\n\nThe same approach can be used for $f$. We define a function $F: \\mathbb{N}  \\rightarrow \\mathbb{N}^4$ into the four-dimensional space $\\mathbb{N}^4$:\n\n\\[\n  F.n = \n  \\begin{pmatrix}\n       \\mathit{fib}.n \\\\\n       \\mathit{fib}.(n + 1) \\\\\n       f.n \\\\\n       f.(n + 1)\n   \\end{pmatrix}   \\text{, for } n \\geq 0 \n\\]\n\nFor a recursive expression for $F$ we have:\n\\[\n\\begin{array}{lcl}\n  &&F.(n + 1) \\\\\n   &=& { < \\text{definition of  } F\\ >} \\\\ \n  &&\\begin{pmatrix}\n       \\mathit{fib}.(n + 1) \\\\\n       \\mathit{fib}.(n + 2) \\\\\n       f.(n + 1) \\\\\n       f.(n + 2)\n   \\end{pmatrix} \\\\\n   &=& { < \\text{definitions of  } \\mathit{fib} \\text{ and } f \\ >} \\\\ \n   &&\\begin{pmatrix}\n      \\mathit{fib}.(n + 1) \\\\\n       \\mathit{fib}.(n + 1) + \\mathit{fib}.n\\\\\n       f.(n + 1) \\\\\n       f.(n + 1) + f.n + \\mathit{fib}.(n + 1)\n   \\end{pmatrix} \\\\\n   &=& { < \\text{matrix multiplication}  >} \\\\ \n   &&\\begin{pmatrix}\n       0 & 1 & 0 & 0\\\\\n       1 & 1 & 0 & 0\\\\\n       0 & 0 & 0 & 1\\\\\n       0 & 1 & 1 & 1\n   \\end{pmatrix} \n   \\begin{pmatrix}\n         \\mathit{fib}.n \\\\\n       \\mathit{fib}.(n + 1) \\\\\n       f.n \\\\\n       f.(n + 1)\n   \\end{pmatrix} \\\\\n   &=& { < \\text{definition of  } F\\ >} \\\\ \n   &&\\begin{pmatrix}\n       0 & 1 & 0 & 0\\\\\n       1 & 1 & 0 & 0\\\\\n       0 & 0 & 0 & 1\\\\\n       0 & 1 & 1 & 1\n   \\end{pmatrix} F.n\n  \\end{array}\n\\]\nand\n\\[\n  F.(n + 1) = \n  \\begin{pmatrix}\n        0 & 1 & 0 & 0\\\\\n       1 & 1 & 0 & 0\\\\\n       0 & 0 & 0 & 1\\\\\n       0 & 1 & 1 & 1\n   \\end{pmatrix}   F.n = \\ldots = \n   \\begin{pmatrix}\n       0 & 1 & 0 & 0\\\\\n       1 & 1 & 0 & 0\\\\\n       0 & 0 & 0 & 1\\\\\n       0 & 1 & 1 & 1\n   \\end{pmatrix} ^{n + 1} F.0\n\\]\n\nCalculating $F.n$ also calculates $f.n$ so if we can calculate $F.n$ faster than linear we also solve the original problem faster than linear. $F.n$ is basically an exponentiation so let's look at the exponentiation function $exp(x, n) = x^n$. The following recursive expression holds for $exp$:\n\n\\begin{equation*}\n exp.x.n = \n \\begin{cases}\n exp. (x \\ x).(n / 2) & \\text{if } n = 0 \\text{ mod } 2 \\\\\n x \\ exp.x.(n - 1) & \\text{if }n = 1 \\text{ mod } 2 \n \\end{cases}\n\\end{equation*}\n\nAt least at every other step in the above recursion n is halved so computing $exp(x, n)$ has $O(log\\ n)$ runtime which also implies $O(log\\ n)$ runtime for $F$.\n\nBefore we write the actual code for computing $F$ let's first see if we can find a more compact representation for the powers of matrix $A$ involved in the computation:\n\n\\begin{equation*}\nA = \n\\begin{pmatrix}\n       0 & 1 & 0 & 0\\\\\n       1 & 1 & 0 & 0\\\\\n       0 & 0 & 0 & 1\\\\\n       0 & 1 & 1 & 1\n       \\end{pmatrix}\n\\end{equation*}\n\nWe are searching for patterns in the powers of $A$:\n\\begin{equation*}\nA^2 = \n\\begin{pmatrix}\n       1 & 1 & 0 & 0\\\\\n       1 & 2 & 0 & 0\\\\\n       0 & 1 & 1 & 1\\\\\n       1 & 2 & 1 & 2\n       \\end{pmatrix},\\ A^3 =\n \\begin{pmatrix}\n       1 & 2 & 0 & 0\\\\\n       2 & 3 & 0 & 0\\\\\n       1 & 2 & 1 & 2\\\\\n       2 & 5 & 2 & 3\n       \\end{pmatrix},\\ A^4 =\n \\begin{pmatrix}\n       2 & 3 & 0 & 0\\\\\n       3 & 5& 0 & 0\\\\\n       2 & 5 & 2 & 3\\\\\n       5 & 10 & 3 & 5\n       \\end{pmatrix}\n\\end{equation*}\n\nWe make the conjecture that $A^k$ for any natural $k$ is of the form:\n\n\\begin{equation}\\label{tuplerep}\nA^k = \n\\begin{pmatrix}\n       a & b & 0 & 0\\\\\n       b & a + b & 0 & 0\\\\\n       c & d & a & b\\\\\n       e & f & b & a + b\n       \\end{pmatrix}, \\text{ for some } a, b, c, d, e, f \\in \\mathbb{N}\n\\end{equation}\n\nand prove this by induction. The base case for $k = 1$ is established with values $(0, 1, 0 , 0, 0 ,1)$ for $(a, b, c, d, e, f)$. Assuming that the conjecture holds for $A^k$ we look at $A^{k + 1}$ and get:\n\n\\begin{equation*}\nA^{k + 1} = A^k\\ A = \n\\begin{pmatrix}\n       b & a + b & 0 & 0\\\\\n       a + b & a + 2 b & 0 & 0\\\\\n       d & b + c + d & b & a + b\\\\\n       f & a + b + e + f & a + b & a + 2 b\n       \\end{pmatrix}\n\\end{equation*}\n\nso $A^{k + 1}$ has the same form as stated in the conjecture if we substitute $(b, a + b, d, b + c + d, f, a + b + e + f)$  for $(a, b, c, d, e, f)$. This proves conjecture (\\ref{tuplerep}).\n\nIt means that in our program we can use a tuple representation $(a, b, c, d, e, f)$ of 6 values instead of the whole 16 values to represent the powers of $A$. We need to define multiplication in this tuple space consistent with the matrix multiplication:\n\n\\begin{equation*}\n\\begin{split}\n(a, b, c, d, e, f) & (a', b', c', d', e',f') =  \\\\ \n( & a a' + b b', \\\\\n   & a b' + b (a' + b'), \\\\\n   & c a' + d b' + a c' + b e', \\\\\n   & c b' + d (a' + b') + a d' + b f', \\\\\n   & e a' + f b' + b c' + (a + b) e', \\\\\n   & e b' + f (a' + b') + b d' + (a + b) f' )\n\\end{split}   \n\\end{equation*}\n\nWe read this definition off the matrix multiplication:\n\n\\begin{equation*}\n\\begin{pmatrix}\n       a & b & 0 & 0\\\\\n       b & a + b & 0 & 0\\\\\n       c & d & a & b\\\\\n       e & f & b & a + b\n       \\end{pmatrix}\n  \\begin{pmatrix}\n       a' & b' & 0 & 0\\\\\n       b' & a' + b' & 0 & 0\\\\\n       c' & d' & a' & b'\\\\\n       e' & f' & b' & a' + b'\n       \\end{pmatrix}     \n\\end{equation*}\n\nThe last expression we need is:\n\n\\begin{equation*}\nA^n F.0 = \\begin{pmatrix}\n       a & b & 0 & 0\\\\\n       b & a + b & 0 & 0\\\\\n       c & d & a & b\\\\\n       e & f & b & a + b\n       \\end{pmatrix} \n \\begin{pmatrix}\n       0\\\\\n       1\\\\\n       0\\\\\n       0\n       \\end{pmatrix}   = \n    \\begin{pmatrix}\n       b\\\\\n       a + b\\\\\n       d\\\\\n        f\n       \\end{pmatrix}    \n\\end{equation*} \n\nso we are interested in $d$ which corresponds to the $F.n$ coordinate of the vector.      \n\nPutting all the pieces together we get the final Haskell program:\n\n\\lstinputlisting[language=Haskell, basicstyle=\\small, frame=trBL, caption={Haskell code}]{fibolucci.hs}\n\n\\bibliographystyle{plainnat}\n\\bibliography{../common/math}\n\n\\end{document}\n\n", "meta": {"hexsha": "6ee2a24a3cc7fc32865907844c4e8b021a2dc8da", "size": 12213, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fibolucci/fibolucci.tex", "max_stars_repo_name": "uwedeportivo/math_notes", "max_stars_repo_head_hexsha": "e0120bb53fad9043637ce964b186194888ba0c49", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fibolucci/fibolucci.tex", "max_issues_repo_name": "uwedeportivo/math_notes", "max_issues_repo_head_hexsha": "e0120bb53fad9043637ce964b186194888ba0c49", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fibolucci/fibolucci.tex", "max_forks_repo_name": "uwedeportivo/math_notes", "max_forks_repo_head_hexsha": "e0120bb53fad9043637ce964b186194888ba0c49", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.4602739726, "max_line_length": 465, "alphanum_fraction": 0.5313190862, "num_tokens": 4738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.9032942086563877, "lm_q1q2_score": 0.8121711402922706}}
{"text": "\\chapter{Introduction}\n\n\\section{Gamma distribution}\nConsider a number of events that follows a homogenous Poisson process with rate paramter $1/\\beta$. Denote the time intervals between the events $X_1,...,X_\\alpha$. The total time of the events are given by\n\\begin{equation*}\n    X = X_1 + \\cdots + X_\\alpha.\n\\end{equation*}\nThen $X$ is gamma distributed with parameters $(\\alpha, \\beta)$. The probability density function for the gamma distribution is given as follows.\n\\begin{equation*}\n    f(x;\\alpha,\\beta) = \\frac{x^{\\alpha - 1}}{\\Gamma(\\alpha)\\beta^\\alpha} e^{\\frac{-x}{\\beta}}\n\\end{equation*}\nThe function $\\Gamma(\\alpha)$ is called the gamma function and is denoted\n\\begin{equation*}\n    \\Gamma(\\alpha) = \\int_{0}^{\\infty} t^{\\alpha - 1} e^{-t} dt.\n\\end{equation*}\nFurthermore $\\alpha>0$, $\\beta>0$ and $X>0$.\n\n\\subsection{Sufficient statistics}\n\n\\subsection{Tranformation of variables}\nFor tranformation of variables in distribution the following theorem is presented.\n\\begin{theorem}\nLet $X$ have a pdf $f_X(x)$ and let $Y = g(X)$, where $g$ is a monotone function. Let FIX s51 casella $X$ and $Y$. Suppose that $f_X(x)$ is continuous on $X$ and that \n\\begin{equation*}\nf_Y (y) = \n\\begin{cases}\nf_X(g^{-1}(y)) \\left| \\frac{d}{dy} g^{-1}(y) \\right| & y \\in \\mathcal{Y} \\\\\n0 & \\text{otherwise.}\n\\end{cases}\n\\end{equation*}\n\\end{theorem}\n\n\\subsection{Generating sample}\nThe general setup is that we have data $X$ and sufficient statistcs $T$. An assumption is a random vector $U$ with known distribution. Furthermore assume functions $(\\chi(\\cdot, \\cdot),\\tau(\\cdot, \\cdot))$ such that\n\\begin{equation*}\n    (\\chi(U,\\theta),\\tau(U, \\theta)) \\overset{\\theta}{\\sim} (X,T).\n\\end{equation*}\nFor instance the vector $U$ could be from an uniform distribution between 0 and 1, while $\\chi(U,\\theta)$ is the inverse of the cumulative distribution and $\\tau(U,\\theta)$ is the statistics. For some instances this might give the wrong distribution to the samples. This is when $\\tau(u, \\theta)$ is not only dependent on $u$ in a function $r(u)$. To solve this weights $W_t(u)$ for the vector $U$ is proposed.\n\n\n\n\nTo simulate from a gamma distribution a trick is proposed. Let $X = \\beta Y$ where$X ~ f(x;a,b)$. The trick is to simulate $Y$ and then find $X$. The distribution of $Y$ is found by using tranformation of variables. From transformation of variables we have that\n\\begin{align*}\ng(x) &= \\frac{x}{\\beta} \\\\\ng^{-1}(y) &= \\beta y \\\\\n\\frac{dg^{-1}(y)}{dy} &= \\beta \\\\\n\\end{align*}\nThen $Y$ has the distribution\n\\begin{equation*}\n    f(y;\\alpha) = \\frac{y^{\\alpha - 1}}{\\Gamma(\\alpha)} e^{-y},\n\\end{equation*}\nwhich is the same as the gamma distribution with $\\beta = 1$. To generate a sample the cumulative distribution function must be found. A cumulative distribution function is found by\n\\begin{equation*}\n    F(x) = \\int_{-\\infty}^{x} f(u) du.\n\\end{equation*}\nFor the gamma distribution the cumulative distribution function becomes\n\\begin{equation*}\n    F(x;\\alpha, \\beta) = \\frac{\\gamma(x, \\alpha, \\beta)}{\\Gamma(\\alpha)},\n\\end{equation*}\nwhere $\\gamma$ is the incomplete gamma function. Hence for $Y$ the cumulative distribtution is\n\\begin{equation*}\n    F(y;\\alpha) = \\frac{\\gamma(y, \\alpha, 1)}{\\Gamma(\\alpha)}.\n\\end{equation*}\n\\section{Goodness of fit testing}", "meta": {"hexsha": "6570c62870204b1143b45a61ff3bc5247ad7e4fd", "size": 3274, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapters/introduction.tex", "max_stars_repo_name": "mariufa/master-thesis-latex", "max_stars_repo_head_hexsha": "897cfc8d815a2ba6a443e72ad4cd3941e94cd172", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Thesis/chapters/introduction.tex", "max_issues_repo_name": "mariufa/master-thesis-latex", "max_issues_repo_head_hexsha": "897cfc8d815a2ba6a443e72ad4cd3941e94cd172", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Thesis/chapters/introduction.tex", "max_forks_repo_name": "mariufa/master-thesis-latex", "max_forks_repo_head_hexsha": "897cfc8d815a2ba6a443e72ad4cd3941e94cd172", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.3692307692, "max_line_length": 410, "alphanum_fraction": 0.6954795357, "num_tokens": 988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294214513915, "lm_q2_score": 0.8991213786215105, "lm_q1q2_score": 0.8121711394545857}}
{"text": "\\section*{Summary of Section 1}\n\\begin{itemize}\n  \\item In higher dimensions,\n      \\begin{enumerate}\n        \\item a line passing through the origin is described as\n        \\begin{equation*}\n          L = \\{ c \\vec{v} : c \\in \\bbr \\}\n        \\end{equation*}\n        \\item a plane passing through the origin is described as\n        \\begin{equation*}\n          P = \\{ c_1 \\vec{v}_1 + c_2 \\vec{v}_2 : c_1, c_2 \\in \\bbr \\}\n        \\end{equation*}\n        when $\\vec{v}_1$ is not a scalar multiple of $\\vec{v}_2$.\n      \\end{enumerate}\n    We generalize this using the notion of $\\spn$. $L$ is the span of the set $\\{\\vec{v}\\}$ and $P$ is the span of the set $\\{ \\vec{v}_1, \\vec{v}_2 \\}$.\n\n    \\item More generally, for any subset $\\cals \\subset \\bbr^n$\n    \\begin{align*}\n      \\spn(\\cals) = \\{ c_1 \\vec{v}_1 + \\dots + c_k \\vec{v}_k \\quad : \\quad\n      & c_1, \\dots, c_k \\mbox{ are real numbers}, \\\\\n      & \\vec{v}_1, \\dots, \\vec{v}_k \\mbox{ are vectors in } S \\}\n    \\end{align*}\n    defines a subspace of $\\bbr^n$. A subspace is a subset of $\\bbr^n$ which is closed under scalar multiplication and addition.\n\n    However, there might be reduncacies in $\\cals$. For example,\n    \\begin{align*}\n      \\spn(\\vec{v}_1) &= \\spn(\\vec{v}_1, \\vec{v}_2)\n      && \\mbox{ if $\\vec{v}_1$ is a scalar multiple of $\\vec{v}_2$} \\\\\n      \\spn(\\vec{e}_1 - \\vec{e}_2, \\vec{e}_2 - \\vec{e}_3, \\vec{e}_3 - \\vec{e}_1) &= \\spn(\\vec{e}_1 - \\vec{e}_2, \\vec{e}_2 - \\vec{e}_3)\n    \\end{align*}\n\n    \\item This is ``corrected'' by linear independence (Definition \\ref{def:linearIndependence}). For a subspace $V$ of $\\bbr^n$, a set $\\calb \\subseteq V$ is said to be a \\emph{basis} of $V$ if $\\spn(\\calb) = V$ and ${\\calb}$ is linearly independent.\n\n    In the above examples, $L$ has basis $\\calb = \\{ \\vec{v} \\}$ and $P$ has basis $\\{ \\vec{v}_1, \\vec{v}_2 \\}$.\n\n    \\item A basis allows us to define coordinates for a vector space.\n    \\begin{enumerate}\n      \\item For $L$ as above, with $\\calb = \\{ \\vec{v} \\}$\n      \\begin{equation*}\n        [c\\vec{v}]_{\\calb} = [ c ]\n      \\end{equation*}\n      \\item For $P$ as above, with $\\calb = \\{ \\vec{v}_1, \\vec{v}_2\\}$\n      \\begin{equation*}\n        [c_1 \\vec{v}_1 + c_2 \\vec{v}_2]_{\\calb} = \\begin{bmatrix}\n          c_1 \\\\ c_2\n        \\end{bmatrix}\n      \\end{equation*}\n      \\item More generally, if $V$ has basis $\\calb = \\{ \\vec{v}_1, \\dots, \\vec{v}_k\\}$ then\n      \\begin{equation*}\n        [c_1 \\vec{v}_1 + \\dots + c_k \\vec{v}_k]_{\\calb} = \\begin{bmatrix}\n          c_1 \\\\ \\vdots \\\\c_k\n        \\end{bmatrix}\n      \\end{equation*}\n    \\end{enumerate}\n\\end{itemize}\n\n\\begin{figure}\n  \\centering\n  \\begin{tikzpicture}[\n     >=latex,\n     % font=\\footnotesize,\n     x={(1cm, 1cm)},\n     y={(1cm, -.5cm)},\n   ]\n     \\def\\xmin{-2}\n     \\def\\xmax{4}\n     \\def\\ymin{-2}\n     \\def\\ymax{4}\n     \\draw[thin, dashed]\n       \\foreach \\x in {\\xmin, ..., \\xmax} {\n         (\\x, \\ymin) -- (\\x, \\ymax)\n       }\n       \\foreach \\y in {\\ymin, ..., \\ymax} {\n         (\\xmin, \\y) -- (\\xmax, \\y)\n       }\n     ;\n     \\draw[<->, very thick]\n       (1, 0) node[above] {$\\vec{v}_1$}\n       -- (0, 0)\n       -- (0, 1) node[below] {$\\vec{v}_2$}\n     ;\n     \\draw[->]\n       (0, 0)\n       -- (2, 3) node[above] {$\\begin{bmatrix} 2 \\\\ 3 \\end{bmatrix}$}\n     ;\n   \\end{tikzpicture}\n  \\caption{Generalized coordinates on a plane. In the basis $\\calb=\\{ \\vec{v}_1, \\vec{v}_2 \\}$, the vector $\\vec{v} = 2 \\vec{v}_1 + 3 \\vec{v}_2$ has coordinates $[\\vec{v}]_{\\calb} = \\protect\\begin{bmatrix} 2 \\\\ 3 \\protect\\end{bmatrix}$.}\n\\end{figure}\n", "meta": {"hexsha": "8d8a91dfa739170e44c0b664c4b3b9c8a43e8276", "size": 3531, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01Summary.tex", "max_stars_repo_name": "apurvnakade/mc2019-linear-algebra", "max_stars_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "01Summary.tex", "max_issues_repo_name": "apurvnakade/mc2019-linear-algebra", "max_issues_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01Summary.tex", "max_forks_repo_name": "apurvnakade/mc2019-linear-algebra", "max_forks_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.6741573034, "max_line_length": 251, "alphanum_fraction": 0.5380911923, "num_tokens": 1356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.903294206053042, "lm_q1q2_score": 0.8121711281846459}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  The following are augmented matrices for four systems of\n  equations. Determine which of them, if any, are row equivalent.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr|r}\n       1 & 3 &  5 &  1 & 12 \\\\\n      -1 & 1 & -1 &  2 &  5 \\\\\n       2 & 0 &  4 & -2 &  0\n    \\end{mymatrix}\n    \\quad\n    \\begin{mymatrix}{rrrr|r}\n      1 & 2 & 4 & -1 &  8 \\\\\n      2 & 4 & 3 &  1 & 15 \\\\\n      3 & 6 & 1 & -1 &  8\n    \\end{mymatrix}\n    \\quad\n    \\begin{mymatrix}{rrrr|r}\n      3 & 6 & -3 & 1 & 6 \\\\\n      2 & 4 & 2 & 1 & 13 \\\\\n      0 & 0 & 1 & 0 & 2\n    \\end{mymatrix}\n    \\quad\n    \\begin{mymatrix}{rrrr|r}\n      1 & 2 & 4 & 1 & 10 \\\\\n      0 & 1 & 1 & 1 & 5 \\\\\n      2 & 1 & 5 & 0 & 8\n    \\end{mymatrix}\n  \\end{equation*}\n\n% The {\\rref}s are supposed to be:\n% \\mat{\n%    \\begin{array}{rrrr|r}\n%      1 & 0 & 2 & 0 & 3 \\\\\n%      0 & 1 & 1 & 0 & 2 \\\\\n%      0 & 0 & 0 & 1 & 3\n%    \\end{array}\n%    }\n%    \\quad\n%    \\mat{\n%    \\begin{array}{rrrr|r}\n%      1 & 2 & 0 & 0 & 3 \\\\\n%      0 & 0 & 1 & 0 & 2 \\\\\n%      0 & 0 & 0 & 1 & 3\n%    \\end{array}\n%    }\n%    \\quad\n\n\\end{ex}\n\n\\begin{ex}\n  Find a tuple $(x,y,z)$ that is a solution to one system of equations\n  but not the other.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr|r}\n      1 & 0 & 1 & 5 & 0 \\\\\n      2 & 1 & 4 & 3 & 0 \\\\\n      3 & 1 & 5 & 9 & 0 \\\\\n    \\end{mymatrix}\n    \\quad\n    \\begin{mymatrix}{rrrr|r}\n      1 & 0 & 3 & 6 & 0 \\\\\n      2 & 1 & 8 & 2 & 0 \\\\\n      2 & 0 & 6 & 13 & 0 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n\\end{ex}\n\n", "meta": {"hexsha": "5a4653b7231c8dc6e6e0dd9d40c04df137e79423", "size": 1523, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/SystemsofEquations-UniquenessRREF.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/SystemsofEquations-UniquenessRREF.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/SystemsofEquations-UniquenessRREF.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 21.7571428571, "max_line_length": 70, "alphanum_fraction": 0.4254760341, "num_tokens": 717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.8887587949656841, "lm_q1q2_score": 0.8120380501157852}}
{"text": "\n\\subsection{Fourier transforms}\n\n\\subsubsection{Taylor series of matrices}\n\nWe can also use Taylor series to evaluate functions of matrices.\n\nConsider \\(e^M\\)\n\nWe can evaluate this as:\n\n\\(e^M=\\sum_{k=0}^\\infty \\dfrac{1}{k!}M^k\\)\n\n", "meta": {"hexsha": "4064a600d231309395f96b5ac765ed8fa96248c7", "size": 231, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/transformations/02-04-multiTaylor.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/transformations/02-04-multiTaylor.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/transformations/02-04-multiTaylor.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.5, "max_line_length": 64, "alphanum_fraction": 0.7186147186, "num_tokens": 70, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067244294587, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.8120055507155757}}
{"text": "\\subsection{Algebraic definition of the cross product}\n\nFrom its geometric description, we can prove that the cross product\nsatisfies the following properties.\n\n\\begin{proposition}{Properties of the cross product}{properties-cross-product}\n  Let $\\vect{u}, \\vect{v}, \\vect{w}$ be vectors in $\\R^3$, and $k$ a\n  scalar. Then the following hold.%\n  \\index{properties of cross product}%\n  \\index{cross product!properties}%\n  \\index{vector!cross product!properties}%\n  \\index{vector!properties of cross product}%\n  \\begin{enumerate}\n  \\item\n    $\\vect{u}\\times \\vect{v}= -(\\vect{v}\\times \\vect{u})$.\n  \\item $\\vect{u}\\times \\vect{u}=\\vect{0}$.\n  \\item $(k \\vect{u})\\times \\vect{v}= k (\\vect{u}\\times \\vect{v})\n    =\\vect{u}\\times (k \\vect{v})$.\n  \\item $\\vect{u}\\times (\\vect{v}+\\vect{w}) =\\vect{u}\\times \\vect{v}+\\vect{u}\\times \\vect{w}$.\n  \\item $(\\vect{v}+\\vect{w}) \\times \\vect{u}=\\vect{v} \\times \\vect{u}+\\vect{w}\\times \\vect{u}$.\n  \\end{enumerate}\n\\end{proposition}\n\n\\begin{proof}\n  Formula $1$. follows immediately from the definition. The vectors\n  $\\vect{u}\\times \\vect{v}$ and $\\vect{v}\\times \\vect{u}$ have the\n  same magnitude, $\\norm{\\vect{u}}\\norm{\\vect{v}}\\sin \\theta$, and an\n  application of the right hand rule shows they have opposite\n  direction.\n\n  Formula $2$. is proven as follows. If $k$ is a non-negative scalar,\n  the direction of $(k \\vect{u}) \\times \\vect{v}$ is the same as\n  the direction of\n  $\\vect{u}\\times \\vect{v}, k (\\vect{u}\\times \\vect{v})$ and\n  $\\vect{u}\\times (k \\vect{v})$. The magnitude is $k$ times the\n  magnitude of $\\vect{u}\\times \\vect{v}$ which is the same as the\n  magnitude of $k (\\vect{u}\\times \\vect{v})$ and\n  $\\vect{u}\\times (k \\vect{v})$. Using this yields equality in\n  $2$. In the case where $k <0$, everything works the same way except\n  the vectors are all pointing in the opposite direction and you must\n  multiply by $\\abs{k}$ when comparing their magnitudes.\n\n  The distributive laws, $3$. and $4$., are harder to establish. For\n  now, we will content ourselves with noticing that if we know that\n  $3$. is true, $4$. follows. Namely, assuming $3$., and using $1$.,\n  we have\n  \\begin{align*}\n    (\\vect{v}+\\vect{w}) \\times \\vect{u}\n    & =-\\vect{u}\\times (\n      \\vect{v}+\\vect{w}) \\\\\n    & =-(\\vect{u}\\times \\vect{v}+\\vect{u}\\times \\vect{w}) \\\\\n    & =\\vect{v}\\times \\vect{u}+\\vect{w}\\times \\vect{u}.\n  \\end{align*}\n\n  \\vspace{-3ex}\n\\end{proof}\n\nIn turn, we can use the properties from\nProposition~\\ref{prop:properties-cross-product} to get an algebraic\ndescription of the cross product. We begin by determining the cross\nproducts of the special vectors $\\vect{i}$, $\\vect{j}$, and\n$\\vect{k}$. They are as follows:\n\\begin{equation*}\n  \\begin{array}{c@{\\quad\\quad}c@{\\quad\\quad}c}\n    \\vect{i}\\times \\vect{j}=\\vect{k},\n    & \\vect{j}\\times \\vect{i}=-\\vect{k},\n    & \\vect{i}\\times \\vect{i}=\\vect{0}, \\\\\n    \\vect{k}\\times \\vect{i}=\\vect{j},\n    & \\vect{i}\\times \\vect{k}=-\\vect{j},\n    & \\vect{j}\\times \\vect{j}=\\vect{0}, \\\\\n    \\vect{j}\\times \\vect{k}=\\vect{i},\n    & \\vect{k}\\times \\vect{j}=-\\vect{i},\n    & \\vect{k}\\times \\vect{k}=\\vect{0}.\n  \\end{array}\n\\end{equation*}\nWith this information and the laws of\nProposition~\\ref{prop:properties-cross-product}, we can compute the\ncross product of any two vectors from their coordinates.%\n\\index{cross product!coordinate description} Let\n\\begin{equation*}\n  \\vect{u}=\\begin{mymatrix}{c}u_1\\\\u_2\\\\u_3\\end{mymatrix}\n  \\quad\\mbox{and}\\quad\n  \\vect{v}=\\begin{mymatrix}{c}v_1\\\\v_2\\\\v_3\\end{mymatrix}.\n\\end{equation*}\nThen we have:\n\\begin{eqnarray*}\n  \\vect{u}\\times\\vect{v}\n  &=& (u_1\\vect{i}+u_2\\vect{j}+u_3\\vect{k})\\times (v_1\\vect{i}+v_2\\vect{j}+v_3\\vect{k}) \\\\\n  &=& \\begin{array}[t]{@{}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n        & u_1v_1(\\vect{i}\\times\\vect{i})\n        &+& u_1v_2(\\vect{i}\\times\\vect{j})\n        &+& u_1v_3(\\vect{i}\\times\\vect{k}) \\\\\n        +& u_2v_1(\\vect{j}\\times\\vect{i})\n        &+& u_2v_2(\\vect{j}\\times\\vect{j})\n        &+& u_2v_3(\\vect{j}\\times\\vect{k}) \\\\\n        +& u_3v_1(\\vect{k}\\times\\vect{i})\n        &+& u_3v_2(\\vect{k}\\times\\vect{j})\n        &+& u_3v_3(\\vect{k}\\times\\vect{k})\n      \\end{array}\n  \\\\\n  &=&\\begin{array}[t]{@{}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n       & u_1v_1\\vect{0}\n       &+& u_1v_2\\vect{k}\n       &-& u_1v_3\\vect{j} \\\\\n       -& u_2v_1\\vect{k}\n       &+& u_2v_2\\vect{0}\n       &+& u_2v_3\\vect{i} \\\\\n       +& u_3v_1\\vect{j}\n       &-& u_3v_2\\vect{i}\n       &+& u_3v_3\\vect{0}\n     \\end{array}\n  \\\\\n  &=& (u_2v_3-u_3v_2) \\vect{i}+\n      (u_3v_1 - u_1v_3) \\vect{j}+\n      (u_1v_2-u_2v_1) \\vect{k}.\n\\end{eqnarray*}\nThe resulting formula for the cross product is summarized in the\nfollowing Proposition.\n\n\\begin{proposition}{Coordinate description of cross product}{cross-product-coordinate}\n  The cross product can be computed as follows:\n  \\begin{equation*}\n    \\begin{mymatrix}{c}u_1\\\\u_2\\\\u_3\\end{mymatrix}\n    \\times\n    \\begin{mymatrix}{c}v_1\\\\v_2\\\\v_3\\end{mymatrix}\n    =\n    \\begin{mymatrix}{c}\n      u_2v_3 - u_3v_2 \\\\\n      u_3v_1 - u_1v_3 \\\\\n      u_1v_2 - u_2v_1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{proposition}\n\nWe will now look at an example of how to compute a cross product.\n\n\\begin{example}{Find a cross product}{find-cross-product}\n  Find $\\vect{u} \\times \\vect{v}$ for the vectors\n  \\begin{equation*}\n    \\vect{u}\n    =\n    \\begin{mymatrix}{r}\n      1 \\\\\n      -1 \\\\\n      2\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{v}\n    =\n    \\begin{mymatrix}{r}\n      3 \\\\\n      -2 \\\\\n      1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Using Proposition~\\ref{prop:cross-product-coordinate}, we compute\n  \\begin{equation*}\n    \\begin{mymatrix}{c}1\\\\-1\\\\2\\end{mymatrix}\n    \\times\n    \\begin{mymatrix}{c}3\\\\-2\\\\1\\end{mymatrix}\n    =\n    \\begin{mymatrix}{c}\n      (-1)(1) - (2)(-2) \\\\\n      (2)(3) - (1)(1) \\\\\n      (1)(-2) - (-1)(3) \\\\\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{c}\n      3 \\\\\n      5 \\\\\n      1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nWe use this concept in the following examples.\n\n\\begin{example}{Area of a parallelogram}{area-parallelogram}\n  Find the area of the parallelogram determined by the following\n  vectors $\\vect{u}$ and $\\vect{v}$:\n  \\begin{equation*}\n    \\vect{u}\n    =\n    \\begin{mymatrix}{r}\n      1 \\\\\n      -1 \\\\\n      2\n    \\end{mymatrix}, \\quad\n    \\vect{v}\n    =\n    \\begin{mymatrix}{r}\n      3 \\\\\n      -2 \\\\\n      1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Notice that these vectors are the same as the ones given in Example~\\ref{exa:find-cross-product}.  Recall from the geometric description\n  of the cross product that the area of the parallelogram is the\n  magnitude of $\\vect{u} \\times \\vect{v}$.  From\n  Example~\\ref{exa:find-cross-product},\n  $\\vect{u} \\times \\vect{v} = \\mat{3,5,1}^T$.\n  Thus the area of the parallelogram is\n  \\begin{equation*}\n    \\norm{\\vect{u} \\times \\vect{v}} =\n    \\sqrt{3^2+5^2+1^2} = \\sqrt{35}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Area of a parallelogram}{area-parallelogram2}\n  Find the area of the parallelogram with vertices $(1,0,1)$,\n  $(2,2,3)$, $(-1,1,3)$, and $(0,3,5)$.\n\\end{example}\n\n\\begin{solution}\n  Let $P=(1,0,1)$, $Q=(2,2,3)$, $R=(-1,1,3)$, and $S=(0,3,5)$.\n  \\begin{center}\n    \\begin{tikzpicture}[scale=1]\n      \\fill[blue!5] (0,0) -- (2,2) -- (5,2) -- (3,0) -- cycle;\n      \\draw[->,thick,blue!70!black] (0,0) -- (2,2);\n      \\draw[->,thick,red] (0,0) -- (3,0);\n      \\draw[thick] (2,2)--(5,2);\n      \\draw[thick] (3,0)--(5,2);\n      \\draw[fill](0,0) circle [radius=2.25pt] node[left=1ex]{$P$};\n      \\draw[fill](2,2) circle [radius=2.25pt] node[left=1ex]{$Q$};\n      \\draw[fill](3,0) circle [radius=2.25pt] node[right=1ex]{$R$};\n      \\draw[fill](5,2) circle [radius=2.25pt] node[right=1ex]{$S$};\n    \\end{tikzpicture}\n  \\end{center}\n  First, we check that this really is a parallelogram. We have to have\n  $\\longvect{PQ}=\\longvect{RS}$. Indeed, this is the case, as\n  $\\longvect{PQ}=\\mat{2-1,2-0,3-1}^T=\\mat{1,2,2}^T$ and\n  $\\longvect{RS}=\\mat{0-(-1),3-1,5-3}^T=\\mat{1,2,2}^T$.  We also\n  compute $\\longvect{PR}=\\longvect{QS}=\\mat{-2,1,2}^T$. The\n  area of the parallelogram is\n  \\begin{equation*}\n    \\norm{\\longvect{PQ}\\times\\longvect{PR}}\n    =\n    \\norm{\n      \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 2 \\end{mymatrix}\n      \\times\n      \\begin{mymatrix}{r} -2 \\\\ 1 \\\\ 2 \\end{mymatrix}\n    }\n    =\n    \\norm{\\begin{mymatrix}{r} 2 \\\\ -6 \\\\ 5 \\end{mymatrix}}\n    = \\sqrt{2^2 + (-6)^2 + 5^2}\n    = \\sqrt{65}.\n  \\end{equation*}\n\\end{solution}\n\nWe can also use this concept to find the area of a triangle, as in the\nfollowing example.\n\n\\begin{example}{Area of triangle}{area-triangle}\n  \\index{cross product!area of triangle}%\n  \\index{area!of triangle}%\n  \\index{triangle!area of}%\n  Find the area of the triangle determined by the points\n  $(1,2,3)$, $(0,2,5)$, and $(5,1,2)$.\n\\end{example}\n\n\\begin{solution}\n  Let $P=(1,2,3)$, $Q=(0,2,5)$, and $R=(5,1,2)$. The area\n  of the triangle is exactly half of the area of the parallelogram\n  determined by the vectors $\\longvect{PQ}$ and $\\longvect{PR}$.\n  \\begin{center}\n    \\begin{tikzpicture}[scale=1]\n      \\fill[blue!5] (0,0) -- (2,2) -- (3,0) -- cycle;\n      \\draw[->,thick,blue!70!black] (0,0) -- (2,2);\n      \\draw[->,thick,red] (0,0) -- (3,0);\n      \\draw[thick] (2,2)--(5,2);\n      \\draw[thick] (3,0)--(5,2);\n      \\draw[dashed] (2,2)--(3,0);\n      \\draw[fill](0,0) circle [radius=2.25pt] node[left=1ex]{$P$};\n      \\draw[fill](2,2) circle [radius=2.25pt] node[left=1ex]{$Q$};\n      \\draw[fill](3,0) circle [radius=2.25pt] node[right=1ex]{$R$};\n    \\end{tikzpicture}\n  \\end{center}\n  We have $\\longvect{PQ}=\\mat{-1,0,2}^T$ and\n  $\\longvect{PR}=\\mat{4,-1,-1}^T$. The area of the parallelogram is\n  the magnitude of the cross product:\n  \\begin{equation*}\n    \\norm{\\longvect{PQ}\\times\\longvect{PR}}\n    =\n    \\norm{\n      \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 2 \\end{mymatrix}\n      \\times\n      \\begin{mymatrix}{r} 4 \\\\ -1 \\\\ -1 \\end{mymatrix}\n    }\n    = \\norm{\\begin{mymatrix}{r} 2 \\\\ 7 \\\\ 1 \\end{mymatrix}}\n    = \\sqrt{2^2+7^2+1^2}\n    = \\sqrt{54}.\n  \\end{equation*}\n  Hence the area of the triangle is $\\frac{1}{2}\\sqrt{54}= \\frac{3}{2}\\sqrt{6}$.\n\\end{solution}\n\nIn general, the area of the triangle determined by three points\n$P,Q,R$ in $\\R^3$ is given by\n\\begin{equation*}\n  \\frac{1}{2}\\norm{\\longvect{PQ} \\times  \\longvect{PR}}.\n\\end{equation*}\n", "meta": {"hexsha": "b22af9aa398b1766b75537072535fe18e6f7d7e4", "size": 10345, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-CrossProduct-Algebraic.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Vectors-CrossProduct-Algebraic.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Vectors-CrossProduct-Algebraic.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 33.6970684039, "max_line_length": 138, "alphanum_fraction": 0.5989366844, "num_tokens": 4045, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.896251377290367, "lm_q1q2_score": 0.8119946311546479}}
{"text": "\\lab{Algorithms}{Introduction to Wavelets}{Intro to Wavelets}\n\n\\objective{This lab explains the basic ideas of Wavelet Analysis\nusing the Haar wavelet as a prototypical example then presents applications of the Discrete Wavelet Transform in\nimage denoising and compression.}\n\nRecall that in the context of Fourier analysis, one seeks to represent a\nfunction in the frequency domain, and this is accomplished via the Fourier\ntransform. The Fourier transform allows us to analyze and process functions\nin many useful ways, as you have seen in previous labs. There are, however,\ndrawbacks to this approach. For example, although a function's Fourier\ntransform gives us complete information on its frequency spectrum, time\ninformation is lost. We can know which frequencies are the\nmost prevalent, but not when they occur. This is due in part to the fact that\nthe sinusoidal function $f(x) = e^{2\\pi ix}$ -- on which the Fourier transform\nis based -- has infinite support. Its nature is essentially \\emph{non-local},\nand so the Fourier transform fails to provide local information in both the\ntime and frequency domains. This brings us to the following question: are\nthere types of transforms that avoid the shortcomings mentioned above? The\nanswer is an emphatic yes. Enter Wavelet analysis.\n\n\\subsection*{The Haar Wavelet}\n\nAs noted earlier, the Fourier transform is based on the complex exponential\nfunction. Let us alter the situation and consider instead the following\nfunction, known as the \\emph{Haar wavelet}:\n\\begin{equation*}\n\\psi(x) =\n \\begin{cases}\n  1 & \\text{if } 0 \\leq x < \\frac{1}{2} \\\\\n  -1 & \\text{if } \\frac{1}{2} \\leq x < 1 \\\\\n  0 & \\text{otherwise.}\n \\end{cases}\n\\end{equation*}\n\n% It might be nice to plot this function and include the image in the lab.\n\nAlong with this wavelet, we introduce the associated \\emph{scaling function}:\n\\begin{equation*}\n\\phi(x) =\n \\begin{cases}\n 1 & \\text{if } 0 \\leq x < 1 \\\\\n 0 & \\text{otherwise.}\n \\end{cases}\n\\end{equation*}\n\nFrom the wavelet and scaling function, we can generate two countable families\nof dyadic dilates and translates given by\n\\begin{equation*}\n\\psi_{m,k}(x) = \\psi(2^mx - k)\n\\end{equation*}\n\\begin{equation*}\n\\phi_{m,k}(x) = \\phi(2^mx - k),\n\\end{equation*}\nwhere $m,k \\in \\mathbb{Z}$.\n\nLet us focus for the moment on that second family of functions, $\\{\\phi_{m,k}\\}$.\nIf we fix $m$ and let $k$ vary over the integers, we have a countable collection of\nsimple functions. The support of a typical function $\\phi_{m,k}$ is the interval\n$[k2^{-m}, (k+1)2^{-m}]$, and for any $m \\in \\mathbb{Z}$ we have\n\\begin{equation*}\n\\mathbb{R} = \\displaystyle\\biguplus_k\\,[k2^{-m}, (k+1)2^{-m}],\n\\end{equation*}\nwhere $\\uplus$ denotes a union over disjoint sets. Thus, the supports can be viewed as\na discretization of the real line, and we can use this collection of simple functions\nto approximate any $f \\in L^2(\\mathbb{R})$ in the following sense:\n\\begin{equation*}\nf(x) \\approx f_m(x) := \\displaystyle\\sum_{k \\in \\mathbb{Z}}\\alpha_{m,k}\\phi_{m,k}(x),\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\alpha_{m,k} := 2^m \\displaystyle \\int_{k2^{-m}}^{(k+1)2^{-m}}f(x) dx\n\\end{equation*}\n($\\alpha_{m,k}$ is simply the average value of $f$ on $[k2^{-m},(k+1)2^{-m}]$). As you\nwould probably expect, the point-wise error between $f$ and its approximation $f_m$\n(called a \\emph{frame}) goes to zero as $m \\to \\infty$.\n\nThese frames are not quite good enough, however. Each coefficient $\\alpha_{m,k}$\ncertainly captures local information about $f$ -- namely its average value on\na certain interval -- but it fails to tell us anything about how $f$ changes\non that interval. We need more information than is provided by $f_m$ in order\nto know about discontinuities or high-frequency oscillations of $f$. To this end,\nwe now consider the wavelet function $\\psi$.\nNotice that the Haar wavelet is oscillatory in nature, and is thus better suited\nto capture local information on how a function changes at a given point. For\nany given $m$, we define a function $d_m$, called a \\emph{detail}, as follows:\n\\begin{equation*}\nd_m(x) := \\displaystyle\\sum_{k \\in \\mathbb{Z}}\\beta_{m,k}\\psi_{m,k}(x),\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\beta_{m,k} := 2^m \\displaystyle \\int_{-\\infty}^{\\infty}f(x) \\psi_{m,k}(x) dx.\n\\end{equation*}\nEach coefficient $\\beta_{m,k}$ gives information about how $f$ changes on the\nthe interval $[k2^{-m}, (k+1)2^{-m}]$, and larger coefficients correspond\nto larger spikes of width $2^{-m}$. Thus, as $m$ increases, the\ndetail function $d_m$ gives information about the higher-frequency oscillations\nof the function. The details and approximation frames interact in the following way:\n\\begin{equation*}\nf_{m+1} = f_m + d_m.\n\\end{equation*}\nAs a result of this fortuitous relationship, one can prove the decomposition\n\\begin{equation*}\nL^2(R) = V_0 \\oplus W_0 \\oplus W_1 \\oplus \\cdots,\n\\end{equation*}\nwhere $V_j := \\text{span}\\{\\phi_{j,k}\\}_{k \\in \\mathbb{Z}}$ and\n$W_j := \\text{span}\\{\\psi_{j,k}\\}_{k \\in \\mathbb{Z}}$. This fact justifies\nour hope to approximate and analyze functions using wavelets.\n\\begin{figure}[t]\n\\minipage{0.32\\textwidth}\n    \\includegraphics[width=\\linewidth]{sinecurve}\n    \\caption{$f(x) = \\sin (x)$}\n\\endminipage\\hfill\n\\minipage{0.32\\textwidth}\n    \\includegraphics[width=\\linewidth]{discreteSineCurve.pdf}\n    \\caption{$f_4$}\n\\endminipage\\hfill\n\\minipage{0.32\\textwidth}\n    \\includegraphics[width=\\linewidth]{sineCurveDetail}\n    \\caption{$d_4$}\n\\endminipage\n\\end{figure}\n\\begin{problem}\nCalculate and plot the approximation frames for $f(x) = \\sin(x)$ on the interval $[0,2\\pi]$\nfor $m = 4, 6, 8$. Note that because we are working on a finite interval,\nwe only need to calculate certain coefficients $\\alpha_{m,k}$. In\nparticular, we only need the coefficients for $k = 0$ up to the first integer\n$n$ such that $(n+1)2^{-m} > 2 \\pi$ (why?). Furthermore, to plot the frame,\nall we need is an array containing the relevant coefficients. Then simply plot\nthe coefficients against \\li{linspace} with appropriate arguments\nand set \\li{drawstyle='steps'} in the \\li{plt.plot} function.\n\\end{problem}\n\n\\begin{problem}\nNow calculate the details for $f(x) = \\sin(x)$ on the same interval and for the\nsame $m$ values given above. Use previous results to compute the coefficients\nfor $f_5$, $f_7$, and $f_9$ and plot them.\n\\end{problem}\n\n\\subsection*{The Discrete Wavelet Transform}\n\nWhat purpose do these details and approximation frames serve? According to the\nproperties discussed above, we can approximate $L^2$ functions as follows:\n\\begin{align*}\nf \\approx f_{J+1} &= f_J + d_J \\\\\n&= f_{J-1} + d_{J-1} + d_J \\\\\n& \\ldots\\\\\n&= f_{I} + d_{I} + d_{I+1} + \\cdots + d_J,\n\\end{align*}\nwhere $1 \\leq I \\leq J$. If $f$ has compact support (as in the case of a finite-time signal,\nfor example), only finitely many of the coefficients in the frame and the details are\nnonzero, thus enabling us to represent $f$ to a reasonable degree of accuracy in a very\nefficient manner. The calculation of these detail coefficients is called the \\emph{discrete\nwavelet transform}. In the context of signals processing, one can imagine calculating these\ncoefficients, transmitting them, and then reproducing the approximated signal on the\nreceiving end. Furthermore, the coefficients of the details reflect the local properties\nof the original function $f$ at the particular level of detail and resolution! This means\nthat we can discard many of the coefficients if we are only interested in reproducing a certain\npart of the signal, or in recovering the entire signal to only a limited resolution. We can\nalso study just those frequencies of the signal that fall within a certain range (called a\nsub-band) by examining the detail coefficients at a particular level. These\nproperties make the discrete wavelet transform an attractive alternative to the Fourier\ntransform in many applications. See Figure \\ref{fig:dwt1D} for an example of the discrete Wavelet transform.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width = 0.5\\textwidth]{dwt1D}\n\\caption{A level 4 wavelet decomposition of a signal. The top panel is the original signal,\nthe next panel down is the approximation frame, and the remaining panels are the detail coefficients.\nNotice how the approximation frame resembles a smoothed version of the original signal, while the \ndetails capture the high-frequency oscillations and noise.}\n\\label{fig:dwt1D}\n\\end{figure}\n\nIn practice, we are often interested in analyzing discrete signals with compact support (that is,\nfinite-time signals that we have sampled at a finite number of points). If wavelet analysis is\nto be of any use, we first need an efficient way to calculate the discrete wavelet transform.\nThe process described in the first section, while intuitive and illustrative of the mathematical\nprinciples\nbehind wavelet analysis, is not the best approach to calculating the wavelet coefficients. It\nturns out that the discrete wavelet transform can be implemented as an iterated low-pass/high-pass\nfilter bank, one iteration of which is shown graphically in the figure. We present the\nalgorithm without getting into the details of why it works.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 0.5\\textwidth]{dwt1}\n\\caption{The one-dimensional discrete wavelet transform.}\n\\end{figure}\nThe input, $A_j$, represents the level-$j$ approximation frame, and we initialize $A_0$ to\nsimply be the original signal. Lo and Hi are the low-pass and high-pass filters, respectively.\n(By \\emph{filter} we mean a vector that serves the purpose of extracting or suppressing a\nparticular feature of the signal. The Lo and Hi filters are obtained from the wavelet at hand;\nfor the Haar wavelet, Lo $= (\\sqrt{2}^{-1}, \\sqrt{2}^{-1})$ and Hi $= (-\\sqrt{2}^{-1}, \\sqrt{2}\n^{-1})$.) The box means convolve the input with the filter, and the circle means downsample by\na factor of two, i.e. remove either the even or odd-indexed entries of the input. The outputs,\n$A_{j+1}$ and $D_{j+1}$, are the level-$(j+1)$ approximation frame and detail coefficients,\nrespectively. Note that the length of the input array is twice that of the output arrays. The\ndetail coefficients $D_{j+1}$ are stored, and $A_{j+1}$ is then fed back into the loop. Continue\nthis process until the length of the output is less than the length of the filters, and\nreturn all of the stored detail coefficients as well as the final approximation frame.\n\\begin{problem}\nWrite a function that calculates the discrete wavelet transform as described above.\nThe inputs should be three one-dimensional NumPy arrays (the signal, low-pass filter, and\nhigh-pass filter). The output should be a list of one-dimensional NumPy arrays in the\nfollowing form: $[A_n, D_n, \\ldots, D_1]$. (Note: for the convolution, you may use\nthe \\li{fftconvolve} function from the \\li{scipy.signal} package using the default\n\\li{mode = 'full'} parameter, but note that the output array is one entry too large, and so\nyou need to omit the first entry. For downsampling, only keep the even-indexed entries.)\n\\end{problem}\nWe also need to know how to reconstruct the signal from the detail coefficients and\napproximation frame. Fortunately, the algorithm described above is entirely reversible,\nalbeit with slightly different filters:\n$$\\text{Lo} = (\\sqrt{2}^{-1}, \\sqrt{2}^{-1})$$ and\n$$\\text{Hi} = (\\sqrt{2}^{-1}, -\\sqrt{2}^{-1}).$$\nGiven $A_{j+1}$ and $D_{j+1}$, simply upsample both arrays (by inserting a zero after\neach entry of the original array), convolve the results\nwith the Lo and Hi filters, respectively (this time omit the \\emph{last} entry of the\nresult), and add the outputs to obtain $A_j$. Continue the\nprocess until you recover $A_0$, the original signal.\n\\begin{problem}\nWrite a function that calculates the inverse wavelet transform as described above.\nThe inputs should be a list of arrays (of the same form as the output of your discrete\nwavelet transform function), the low-pass filter, and the high-pass filter. The output\nshould be a single array, the recovered signal. In order to check your work, compute\nthe discrete wavelet transform of a random array of length 64, then compute the inverse\ntransform, and compare the original signal with the recovered signal. The difference\nshould be very small.\n\\end{problem}\n\n\\subsection*{The two-dimensional Discrete Wavelet Transform}\nOur discussion so far has focused on one-dimensional\ndiscrete signals, but it is not difficult to extend the same ideas into the\nrealm of two-dimensional arrays. As you know, a digital image can be represented\nas a matrix of pixel values (for simplicity we will consider grayscale images of\nsize $2^n \\times 2^n$). We can perform the wavelet decomposition of\nan image in much that same way as with one-dimensional signals. We once again\ncalculate detail and approximation coefficients using an iterative filter\nbank, but now we generate four arrays of coefficients at each iteration as opposed to\njust two. In essence, we perform the one-dimensional wavelet transform first on each\nrow, and then on each column of the matrix. Notice the similarity with our approach\nto extending the one-dimensional Fourier transform to two-dimensional images. See\nFigure \\ref{fig:dwt2D} of an example of the two-dimensional Wavelet transform applied\nto an image.\n\n\\begin{figure}\n    \\includegraphics[width=0.8\\textwidth]{dwt2D.pdf}\n    \\caption{The level 2 wavelet coefficients of the Lena image. The upper left quadrant \n    is the approximation frame, and the other quadrants are the details. Notice how the \n    details highlight the parts of the image with high-frequency textures and borders.}\n    \\label{fig:dwt2D}\n\\end{figure}\n\nThe algorithm goes as follows.\nGiven an input matrix of size $2^n \\times 2^n$, first operate on the rows as you would\nin the one-dimensional Wavelet transform (i.e. convolve each row with the filters, then\ndownsample).\nWe then have two matrices of size $2^n \\times 2^{n-1}$,\nsince each row has been downsampled by a factor of 2. Then for each of these two\nintermediate matrices, operate on each column, yielding a total of four matrices of\nsize $2^{n-1} \\times 2^{n-1}$. Figure \\ref{fig:2dwt}\ngives a graphical depiction of one iteration of the algorithm.\n\n\\begin{figure}[t]\n    \\includegraphics[width=0.8\\textwidth]{2dwt.jpg}\n    \\caption{The 2-dimensional discrete wavelet transform.}\n    \\label{fig:2dwt}\n\\end{figure}\n\n\nWe initialize $LL_0$ to be the\noriginal image matrix, and we terminate once the length of the rows or columns\nis less than the length of the filters. We end up with a list of wavelet\ncoefficients, starting with the final approximation frame $LL_n$ followed by\ncollections of detail coefficients $(LH_n,HL_n,HH_n)$, $(LH_{n-1},HL_{n-1},HH_{n-1})$,\n$\\ldots$, $(LH_1,HL_1,HH_1)$. Note that at each iteration we operate first on the\nrows (convolve with the filter, then downsample), and the we operate on the columns\nof the resulting matrices (\\emph{not} the original matrix). The size of the output\nmatrices have been reduced by a factor of two in both dimensions. As with the\none-dimensional algorithm, to reconstruct the image from the coefficients, we simply\nreverse the process by upsampling, convolving, and adding (first the columns, then\nthe rows). We provide sample code for one iteration of the transform and the inverse.\n\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy.signal import fftconvolve\n\n# given the current approximation frame image, and the filters lo_d and hi_d\n# initialize empty arrays\ntemp = np.zeros([image.shape[0], image.shape[1]/2])\nLL = np.zeros([image.shape[0]/2, image.shape[1]/2])\nLH = np.zeros([image.shape[0]/2, image.shape[1]/2])\nHL = np.zeros([image.shape[0]/2, image.shape[1]/2])\nHH = np.zeros([image.shape[0]/2, image.shape[1]/2])\n\n# low-pass filtering along the rows\nfor i in xrange(image.shape[0]):\n\ttemp[i] = fftconvolve(image[i], lo_d, mode='full')[1::2]\n\n# low and hi-pass filtering along the columns\nfor i in xrange(image.shape[1]/2):\n\tLL[:,i] = fftconvolve(temp[:,i],lo_d,mode='full')[1::2]\n    LH[:,i] = fftconvolve(temp[:,i],hi_d,mode='full')[1::2]\n\n# hi-pass filtering along the rows\nfor i in xrange(image.shape[0]):\n\ttemp[i] = fftconvolve(image[i], hi_d, mode='full')[1::2]\n\n# low and hi-pass filtering along the columns\nfor i in xrange(image.shape[1]/2):\n\tHL[:,i] = fftconvolve(temp[:,i],lo_d,mode='full')[1::2]\n    HH[:,i] = fftconvolve(temp[:,i],hi_d,mode='full')[1::2]\n\\end{lstlisting}\nAt this point, the variables \\li{LL, LH, HL, HH} contain the current level of wavelet coefficients.\nYou would then store \\li{(LH, HL, HH)} in a list, and feed \\li{LL} back into the same\nblock of code (with \\li{LL} replacing \\li{image}) to obtain the next level of coefficients.\n\nNow, given a current level of wavelet coefficients, here is the code to recover the previous\napproximation frame, which is the crucial step in the inverse transform.\n\\begin{lstlisting}\n# given current coefficients LL, LH, HL, HH\n# initialize temporary arrays\nn = LL.shape[0]\ntemp1 = np.zeros([2*n,n])\ntemp2 = np.zeros([2*n,n])\nup1 = np.zeros(2*n)\nup2 = np.zeros(2*n)\n\n# upsample and filter the columns of the coefficient arrays\nfor i in xrange(n):\n\tup1[1::2] = HH[:,i]\n\tup2[1::2] = HL[:,i]\n\ttemp1[:,i] = fftconvolve(up1, hi_r)[1:] + fftconvolve(up2, lo_r)[1:]\n\tup1[1::2] = LH[:,i]\n\tup2[1::2] = LL[:,i]\t\t\n\ttemp2[:,i] = fftconvolve(up1, hi_r)[1:] + fftconvolve(up2, lo_r)[1:]\n\n# upsample and filter the rows, then add results together\nresult = sp.zeros([2*n,2*n])\nfor i in xrange(2*n):\n\tup1[1::2] = temp1[i]\n\tup2[1::2] = temp2[i]\n\tresult[i] = fftconvolve(up1, hi_r)[1:] + fftconvolve(up2, lo_r)[1:]\n\\end{lstlisting}\n\n\\begin{problem}\nBuild off of the sample code to fully implement the two-dimensional discrete\nwavelet transform as described above.\nAs before, the input to your function should consist of\nthree arrays: the input image, the low-pass filter, and the high-pass filter.\nYou should return a list of the following form: $$[LL_n,(LH_n,HL_n,HH_n), \\ldots\n,(LH_1,HL_1,HH_1)].$$ \n\nThe inverse wavelet transform function should take as input a list\nof that same form, as well as the reconstruction low-pass and high-pass filters,\nand should return the reconstructed image.\n\\end{problem}\n\nThese wavelet coefficients are very useful in a variety of image processing\ntasks. They allow us to analyze and manipulate images in terms of both their\nfrequency and spatial properties, and at differing levels of resolution.\nFurthermore, wavelet bases often have the remarkable ability to represent\nimages in a very \\textit{sparse} manner -- that is, most of the image\ninformation is captured by a small subset of the wavelet coefficients.\nIn the remainder of this lab, we will see how the discrete wavelet transform\nplays a role in edge detection, noise removal, and compression.\n\n\\subsection*{More Wavelets}\nUp to this point, the only wavelet that we have considered is the Haar wavelet,\nwhich is the simplest and historically first example. Wavelet analysis is a broad\nfield, however, and there are myriad other wavelets that have been studied and\napplied. Your implementation of the discrete wavelet transform is quite general,\nand you will find that different types of signals or functions call for different\nwavelets. We will not go into detail here, but be aware that there is a large\nselection of wavelets out there.\n\n\\begin{figure}[H]\n\\minipage{0.49\\textwidth}\n    \\includegraphics[width=\\linewidth]{mexicanHat}\n    \\caption{The Mexican Hat Wavelet}\n\\endminipage\\hfill\n\\minipage{0.49\\textwidth}\n    \\includegraphics[width=\\linewidth]{db5_3}\n    \\caption{The Cohen-Daubechies-Feauveau 5/3 Wavelet}\n\\endminipage\n\\end{figure}\n\n\\section*{The PyWavelets Module}\nPyWavelets is a Python library for Wavelet Analysis. It provides convenient and\nefficient methods to calculate the one and two-dimensional discrete Wavelet\ntransform, as well as much more. Assuming that the package has been installed on\nyour machine, type the following to get started:\n\\begin{lstlisting}\n>>> import pywt\n\\end{lstlisting}\nPerforming the basic discrete Wavelet transform is very simple.\nBelow, we compute the one-dimensional transform for a sinusoidal signal.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> f = np.sin(np.linspace(0,8*np.pi, 256))\n>>> fw = pywt.wavedec(f, 'haar')\n\\end{lstlisting}\nThe variable \\li{fw} is now a list of arrays, starting with the final approximation\nframe, followed by the various levels of detail coefficients, just like the output\nof the wavelet transform function that you coded in the previous lab.\nPlot the level 2 detail and verify that it resembles a blocky sinusoid.\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> plt.plot(fw[-2], linestyle='steps')\n>>> plt.show()\n\\end{lstlisting}\nWe can give alter the arguments to the \\li{wavedec} function to use different\nwavelets or obtain different levels of the wavelet transform. The second\npositional argument, as you will notice, is a string that gives the name of the\nwavelet to be used. We first used the Haar wavelet, with which you are already\nfamiliar. PyWavelets supports a number of different Wavelets, however, which you can\nlist by executing the following code:\n\\begin{lstlisting}\n>>> # list the available Wavelet families\n>>> print pywt.families()\n['haar', 'db', 'sym', 'coif', 'bior', 'rbio', 'dmey']\n>>> # list the available wavelets in the coif family\n>>> print pywt.wavelist('coif')\n['coif1', 'coif2', 'coif3', 'coif4', 'coif5']\n\\end{lstlisting}\nWe can also include optional arguments \\li{mode} and \\li{level} when calling the\n\\li{wavedec} function. Using these arguments, you can adjust the mode for dealing\nwith border distortion and the level of the Wavelet decomposition, respectively.\n\n\\begin{figure}[t]\n    \\includegraphics[width=\\linewidth]{dwt2.pdf}\n    \\caption{Level 1 Wavelet decomposition of the Lena image.\n    The upper left is the approximation frame, and the remaining\n    plots are the detail coefficients.}\n    \\label{fig:dwt2}\n\\end{figure}\n\nNow we illustrate how to perform a two-dimensional Wavelet transform using\nPyWavelets. We will work with the traditional Lena image, performing a\ntwo level wavelet transform using the Daubechies 4 Wavelet.\n\\begin{lstlisting}\n>>> import scipy.misc\n>>> lena = scipy.misc.lena()\n>>> lw = pywt.wavedec2(lena, 'db4', level=2)\n\\end{lstlisting}\nThe variable \\li{lw} is a list of tuples of arrays. The first entry of the list is\nsimply the level 2 approximation frame. The second entry of the list is a tuple of\nthe level 2 detail coefficients $LH$, $HL$, and $HH$ (in that order). The remaining\nentries of the list are tuples containing the lower level detail coefficients.\nThus, to plot the level 1 $HL$ detail coefficients, we can execute the following code:\n\\begin{lstlisting}\n>>> HL1 = lw[-1][1]\n>>> plt.imshow(np.abs(HL1), cmap=plt.cm.Greys_r, interpolation='none')\n>>> plt.show()\n\\end{lstlisting}\nThe output of this code should be a plot resembling the lower left plot given in Figure\n\\ref{fig:dwt2}.\n\nWe have only introduced a couple of the basic tools available in PyWavelets. There\nare of course many more functions and methods that facilitate a more comprehensive\nWavelet analysis. In the remainder of this lab, we will explore three particular \napplications of Wavelet analysis in the realm of image processing and compression.\n\n%\\section*{Edge Detection}\n%It is often useful to identify the edges of objects and figures\n%represented in images. The edge information can be used to classify images\n%and group them with other similar images (this is part of a field called\n%\\textit{computer vision}), to segment the image into component parts, to\n%sharpen blurry images, to filter out unnecessary details of the image,\n%and so forth. Of course, our human eyes are very adept at recognizing edges,\n%but enabling a computer to do the same is much more difficult. An edge can\n%be thought of as a discontinuity in the image or a region of high contrast\n%in either color or brightness. We can therefore leverage the high-frequency\n%detail coefficients of the wavelet transform to detect the edges. Execute the\n%following code:\n%\\begin{lstlisting}\n%>>> # calculate one level of wavelet coefficients\n%>>> coeffs = pywt.wavedec2(lena,'haar', level=1)\n%\\end{lstlisting}\n%\n%Note that the approximation coefficients are very close to the original\n%image, while the detail coefficients are much more sparse, and roughly\n%capture the edges in the image. In particular, the upper right coefficients\n%emphasize the vertical edges, the lower left coefficients emphasize the\n%horizontal edges, and the lower right coefficients emphasize the diagonal\n%edges.\n%\n%\\begin{problem}\n%Now zero out the approximation coefficients and use your inverse DWT\n%function to recreate the image. Plot its absolute value. This image is\n%a fairly good representation of the edges. If we add this to the original\n%image, we can increase the contrast at the edges (that is, make the dark\n%side darker, and the light side lighter). Do this, and plot the original\n%image side-by-side with the sharpened image. What do you notice? There\n%are many image-sharpening techniques, and those based on wavelets\n%are more sophisticated than what we have done here, but this gives the\n%basic idea.\n%\\end{problem}\n%the above section needs work, or maybe should be taken out completely.\n\n\\section*{Noise Removal}\nNoise in an image can be defined as unwanted visual artifacts that\nobscure the true image. Images can acquire noise from a variety of\nsources, including the camera, transmission, and image processing\nalgorithms. Noise can be completely random and incoherent (as in\nFigure \\ref{fig:incoherent}), or it can be coherent and display\nvisual patterns (Figure \\ref{fig:coherent}). In this section, we will\nfocus on reducing a particular type of random noise in images, called\n\\textit{Gaussian white noise}.\n\n\\begin{figure}[t]\n\\minipage{0.49\\textwidth}\n    \\includegraphics[width=\\linewidth]{phantom_random.pdf}\n    \\caption{The Phantom image with incoherent noise}\n    \\label{fig:incoherent}\n\\endminipage\\hfill\n\\minipage{0.49\\textwidth}\n    \\includegraphics[width=\\linewidth]{phantom_coherent.pdf}\n    \\caption{The Phantom image with coherent noise}\n    \\label{fig:coherent}\n\\endminipage\n\\end{figure}\n\nAn image that is distorted by Gaussian white noise is one in which\nevery pixel has been perturbed by a small amount, such that the\nperturbations are normally distributed. We can easily add such noise\nto an image using the \\li{np.random.normal} function.\n\n\\begin{lstlisting}\n>>> noisyLena = lena + np.random.normal(scale=20, size=lena.shape)\n>>> plt.imshow(noisyLena, cmap=plt.cm.Greys_r)\n>>> plt.show()\n\\end{lstlisting}\n\nGiven an image with Gaussian white noise, how do we go about reducing\nthe noise level? Our approach will be based on the idea of thresholding.\nIt turns out that images are often sparse in the wavelet basis,\nparticularly in the high-frequency details. The Gaussian noise, however,\nis very high frequency, and thus its wavelet transform will be\nconcentrated in high-frequency wavelet coefficients (of magnitude\nroughly proportional to the variance of the noise). We can therefore\nreduce the noise while preserving the true image by shrinking the\ndetail coefficients via hard or soft thresholding.\n\nGiven a positive threshold value $\\tau$, hard thresholding sets\nevery wavelet coefficient whose magnitude is less than $\\tau$ to\nzero, while leaving the remaining coefficients untouched. Soft\nthresholding also zeros out all coefficients of magnitude less than\n$\\tau$, but in addition maps every other coefficient $\\beta$ to\n$\\beta - \\tau$ if $\\beta > 0$ or $\\beta + \\tau$ if $\\beta < 0$.\n\nImplementing these simple thresholding algorithms in Python is \nstraight-forward, but PyWavelets already provides this functionality.\nThe following code gives an example.\n\n\\begin{lstlisting}\n>>> A = np.arange(-4,5).reshape(3,3)\n>>> A\narray([[-4, -3, -2],\n       [-1,  0,  1],\n       [ 2,  3,  4]])\n>>> pywt.thresholding.hard(A,1.5)\narray([[-4, -3, -2],\n       [ 0,  0,  0],\n       [ 2,  3,  4]])\n>>> pywt.thresholding.soft(A,1.5)\narray([[-2.5, -1.5, -0.5],\n       [ 0. ,  0. ,  0. ],\n       [ 0.5,  1.5,  2.5]])\n\\end{lstlisting}\n\nOnce the coefficients have been thresholded, we take the inverse\nwavelet transform to recover the denoised image. This can be done\nby calling the \\li{waverec2} function, providing the list of Wavelet\ncoefficients as well as the name of the desired Wavelet as arguments.\nThe threshold value is generally a function of the variance of the noise,\nand in real situations, we do not know what this variance is. In fact,\nnoise variance estimation in images is a research area in its own\nright, but this goes beyond the scope of this lab, and so we will\nassume that we already have a decent estimate of the variance.\n\n\\begin{figure}[t]\n    \\includegraphics[width=\\linewidth]{denoise.pdf}\n    \\caption{Noisy Lena (left), denoised using hard thresholding (center), \n    and denoised using soft thresholding (right).}\n    \\label{fig:denoise}\n\\end{figure}\n\n\\begin{problem}\nWrite functions that implement the hard and soft thresholding\ntechniques. The inputs should be a list of wavelet coefficients\nin the usual form, as well as the threshold value. The output\nshould be the thresholded wavelet coefficients (also in\nthe usual form). Remember that we only want to threshold the\ndetail coefficients, and not the approximation coefficients.\nYou should therefore leave the first entry of the input\ncoefficient list unchanged.\n\\end{problem}\n\n\\begin{problem}\nCreate a noisy version of the Lena image by adding Gaussian\nwhite noise of mean 0 and standard deviation $\\sigma = 20$ (i.e. \\li{scale=20}).\nCompute four levels of the wavelet coefficients using the Daubechies 4 Wavelet, \nand input these into your\nthresholding functions (with $\\tau = 3\\sigma$ for the hard threshold,\nand $\\tau = 3\\sigma/2$ for the soft threshold). Reconstruct the\ntwo denoised images, and then plot these together alongside the\nnoisy image. Your output should match Figure \\ref{fig:denoise}.\n\nWhat do you notice? How does lowering or raising the\nthreshold affect the reconstructed images? What happens if you use\na different Wavelet?\n\\end{problem}\n\n\\section*{Image Compression}\nWe now turn to the problem of image compression. Explicitly saving\nthe value of every pixel in an image can be very costly in both\nstorage and transmission, and numerous image compression techniques\nhave been developed over the years to deal with this problem.\nTransform methods have long played an important role in these\ntechniques; the popular JPEG image compression standard is based on\nthe discrete cosine transform. Starting from the early 1990's, much\nresearch has gone into compression methods using the discrete wavelet\ntransform, and to great success. The JPEG2000 compression standard\nand the FBI Fingerprint Image database, along with other systems,\ntake the wavelet approach.\n\nThe general framework for compression is fairly straightforward. First,\nthe image to be compressed undergoes some form of preprocessing (this\ncan include subtracting out its mean, tiling the image, or perhaps\nnothing at all). Next, the wavelet coefficients are computed using some\nspecially constructed wavelet (JPEG2000 uses the either the\nCohen-Daubechies-Feauveau 9/7 or 5/3 wavelet) and then \\textit{quantized},\n a process that we will explain shortly. The quantized coefficients are\n then grouped in a particular way and passed through an entropy encoder\n (such as Huffman coding, run length coding, or arithmetic coding). This\n coding step comes from the realm of information theory, and we will not\n worry about it in this lab. What you have left is a compact stream of bits\n that can then be saved or transmitted much more efficiently than the\n original image. All of the above steps are invertible, allowing us to\n reconstruct the image from the bitstream.\n\n The step in this process that we will focus on is quantization. Put simply,\n quantization is a process whereby the coefficients are converted into\n integers. If the coefficients are floating-point numbers, then this\n process introduces some loss of precision, and we call this \\textit{\n lossy compression}. In the situation where all the coefficients are already\n integers, it is possible to compress the image without any loss of precision,\n and this is called \\textit{lossless compression}. Quantization can be\n performed in a variety of ways, and we will explore one particular method\n called a \\emph{uniform null-zone quantizer}. Given a coefficient $x$, we assign\n to it an integer $q$ given by\n\\begin{equation*}\nq =\n \\begin{cases}\n   \\lceil x / \\delta - t/2 \\rceil, &  x \\geq 0\\\\\n   \\lfloor x / \\delta + t/2 \\rfloor & x \\leq 0\n \\end{cases}\n\\end{equation*}\nwhere $1 \\leq t \\leq 2$ and $\\delta > 0$ are adjustable parameters.\nThe inverse process, called de-quantization, consists of recovering\nthe coefficient $y$ from the quantized value $q$ via the equation\n\\begin{equation*}\n y =\n  \\begin{cases}\n   (q - 1/2 + t/2)\\delta & q > 0\\\\\n   (q + 1/2 - t/2)\\delta & q < 0\\\\\n   0,                    & q = 0\n  \\end{cases}\n \\end{equation*}\nWhat we are essentially doing is mapping all wavelet coefficients that\nfall in the interval $[-\\delta,\\delta]$ to 0 and all wavelet coefficients\nin the interval $[j\\delta,(j+1)\\delta]$ to $(2j+1)\\delta/2$ for integers\n$j \\geq 1$ and $j \\leq -2$. This greatly reduces the number of distinct\ncoefficient values (indeed, most of the coefficients are mapped to\nzero), allowing us, at the cost of some precision, to store less\ninformation. The larger we choose $\\delta$, the more compression we\ncan achieve, albeit with a correspondingly larger loss in precision.\n\\begin{problem}\nWrite function \\li{quantize} and \\li{dequantize} based on the discussion above.\nIn both cases, the inputs should be a list of wavelet coefficients in\nstandard form, the $\\delta$ parameter, and the $t$ parameter with default\nvalue of 2. The functions should return the quantized list of wavelet\ncoefficients.\n\nFor the Lena image, calculate the complete set of wavelet coefficients and then\nquantize and de-quantize the coefficients, and reconstruct the image.\nDo this for a few different values of $\\delta$ (with $t=2$), and observe how\nthe image is distorted. Try using different Wavelets. Keep in mind that there are\nspecially designed Wavelets used in image compression that are not available\nin PyWavelets, so distortion will be greater than tolerable in real-life settings.\n\\end{problem}", "meta": {"hexsha": "5a2a526859bdd1cd6621b52e63a768f523577dce", "size": 34411, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Haar/Haar.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/Haar/Haar.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/Haar/Haar.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.7988422576, "max_line_length": 112, "alphanum_fraction": 0.7575484583, "num_tokens": 9048, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.918480237330998, "lm_q1q2_score": 0.8119726177263067}}
{"text": "\\section*{Limits}\n\n\\vspace{-10pt}\n\n\\begin{python}\n   from sympy import *\n   a, n, x, dx = symbols('a n x dx')\n   ans = limit(sin(4*x)/x,x,0)                  # py (ans.301,ans)\n   ans = limit(2**x/x,x,oo)                     # py (ans.302,ans)\n   ans = limit(((x+dx)**2 - x**2)/dx, dx,0)     # py (ans.303,ans)\n   ans = limit((4*n + 1)/(3*n - 1),n,oo)        # py (ans.304,ans)\n   ans = limit((1+(a/n))**n,n,oo)               # py (ans.305,ans)\n\\end{python}\n\n\\begin{align*}\n   &\\py*{ans.301}\\\\\n   &\\py*{ans.302}\\\\\n   &\\py*{ans.303}\\\\\n   &\\py*{ans.304}\\\\\n   &\\py*{ans.305}\n\\end{align*}\n", "meta": {"hexsha": "57db18e550088a8d8b020b983e3a8d3462c8e33b", "size": 585, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "python/examples/example-10/limits/limits.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "python/examples/example-10/limits/limits.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "python/examples/example-10/limits/limits.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 26.5909090909, "max_line_length": 66, "alphanum_fraction": 0.4598290598, "num_tokens": 245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229959153748, "lm_q2_score": 0.877476800298183, "lm_q1q2_score": 0.8118678240982493}}
{"text": "\\section{Fourier Transforms}\r\n\\subsection{Introduction}\r\n\\begin{definition}\r\n    The Fourier transform (FT) of a function $f(x)$ is\r\n    $$\\tilde{f}(k)=(\\mathcal F(f))(k)=\\int_{-\\infty}^\\infty f(x)e^{-ikx}\\,\\mathrm dx$$\r\n    The inverse Fourier transform is\r\n    $$f(x)=(\\mathcal F^{-1}(\\tilde{f}))(x)=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\tilde{f}(k)e^{ikx}\\,\\mathrm dk$$\r\n\\end{definition}\r\nBeware that there are several conventioned for FT.\r\n$\\tilde{f}$ is said to be in the frequency domain.\r\n\\begin{theorem}[Fourier Inversion Theorem]\r\n    $\\mathcal F^{-1}\\circ\\mathcal F(f)=f$ given that all integrals involved are well-behaved (a sufficient condition is $f,\\tilde{f}$ both being absolutely integrable).\r\n\\end{theorem}\r\n\\begin{example}\r\n    Take $f(x)=(1/(\\sigma\\sqrt\\pi))e^{-x^2/\\sigma^2}$, then we can either find $\\tilde{f}$ by completing square or observe that\r\n    $$\\tilde{f}(k)=\\frac{1}{\\sigma\\sqrt{\\pi}}\\int_{-\\infty}^\\infty e^{-x^2/\\sigma^2}e^{-ikx}\\,\\mathrm dx=\\frac{1}{\\sigma\\sqrt{\\pi}}\\int_{-\\infty}^\\infty e^{-x^2/\\sigma^2}\\cos(kx)\\,\\mathrm dx$$\r\n    Differentiate under the integral sign,\r\n    \\begin{align*}\r\n        \\frac{\\mathrm d\\tilde{f}}{\\mathrm dk}&=-\\frac{1}{\\sigma\\sqrt\\pi}\\int_{-\\infty}^\\infty xe^{-x^2/\\sigma^2}\\sin(kx)\\,\\mathrm dx\\\\\r\n        &=-\\frac{1}{\\sigma\\sqrt\\pi}\\int_{-\\infty}^\\infty\\left( \\frac{k\\sigma^2}{2} \\right)e^{-x^2/\\sigma^2}\\cos(kx)\\,\\mathrm dx\\\\\r\n        &=-\\frac{k\\sigma^2}{2}\\tilde{f}(k)\r\n    \\end{align*}\r\n    Integrating this differential equation on $\\tilde{f}$ gives $\\tilde{f}(k)=Ce^{-k^2\\sigma^2/4}$ for some constant $C$.\r\n    Setting $k=0$ gives $C=1$, therefore $\\tilde{f}(k)=e^{-k^2\\sigma^2/4}$.\r\n    One can show that $\\mathcal F^{-1}\\tilde{f}=f$.\r\n\\end{example}\r\n\\begin{example}\r\n    The Fourier transform of $f(x)=e^{-a|x|}$ is $\\tilde{f}(k)=2a/(a^2+k^2)$ either by direct integration or superposition.\r\n\\end{example}\r\n\\subsection{Relation with Fourier Series}\r\nRecall that the Fourier series has the form\r\n$$f(x)=\\sum_{n=-\\infty}^\\infty c_ne^{ik_nx},k_n=n\\Delta k,\\Delta k=\\frac{\\pi}{L}$$\r\nNow we know that\r\n$$c_n=\\frac{1}{2L}\\int_{-L}^Lf(x)e^{-ik_nx}\\,\\mathrm dx=\\frac{\\Delta k}{2\\pi}\\int_{-L}^Lf(x)e^{-ik_nx}\\,\\mathrm dx$$\r\nImagine taking $L\\to\\infty,\\Delta k\\to 0$ then we get the expression of Fourier transform multiplied by an infinitesimal term.\r\nTo further justify the analogy, observe that we get\r\n$$f(x)=\\sum_{n=-\\infty}^\\infty\\frac{\\Delta k}{2\\pi}e^{ik_nx}\\int_{-L}^Lf(x')e^{-ik_nx'}\\,\\mathrm dx'$$\r\nThis looks like a Riemann sum, so let us take the limit $L\\to\\infty,\\Delta k\\to 0$ which gives\r\n$$f(x)=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty \\left( \\int_{-\\infty}^\\infty f(x')e^{-ikx'}\\,\\mathrm dx' \\right)e^{ikx}\\,\\mathrm dk=\\mathcal F^{-1}\\circ\\mathcal F(f)(x)$$\r\nNote that when $f$ is discontinuous at $x$, then $\\mathcal F^{-1}\\circ\\mathcal F(f)(x)=(f(x_-)+f(x_+))/2$ which is a similar behaviour to that of a Fourier series.\r\n\\subsection{Properties of Fourier Transform}\r\nThe operators $\\mathcal F,\\mathcal F^{-1}$ is both linear.\r\nAlso, the translation $h(x)=f(x-\\lambda)$ gives $\\tilde{h}(k)=e^{-i\\lambda k}\\tilde{f}(k)$.\r\nCorrespondingly, the frequency shift $h(x)=e^{i\\lambda x}f(x)$ gives $\\tilde{h}(k)=\\tilde{f}(k-\\lambda)$.\r\nThe scaling $h(x)=f(\\lambda x)$ for $\\lambda\\neq 0$ gives $\\tilde{h}(k)=\\tilde{f}(k/\\lambda)/|\\lambda|$.\\\\\r\nThese are all trivial facts, here is a slightly more interesting one:\r\n$h(x)=xf(x)$ gives $\\tilde{h}(k)=i\\tilde{f}^\\prime(k)$.\r\nIndeed,\r\n$$\\tilde{h}(k)=\\int_{-\\infty}^\\infty xf(x)e^{-ikx}\\,\\mathrm dx=-\\frac{1}{i}\\frac{\\mathrm d}{\\mathrm dk}\\int_{-\\infty}^\\infty f(x)e^{-ikx}\\,\\mathrm dx=i\\tilde{f}^\\prime(k)$$\r\nWhat's more important is that if $f$ vanishes at $\\pm\\infty$ and $h(x)=f^\\prime(x)$ gives $\\tilde{h}(k)=ik\\tilde{f}(k)$ via integration by parts\r\n$$\\tilde{h}(k)=\\int_{-\\infty}^\\infty f^\\prime(x)e^{-ikx}\\,\\mathrm dx=[f(x)e^{-ikx}]_{-\\infty}^\\infty-\\int_{-\\infty}^\\infty (-ik)f(x)e^{-ikx}\\,\\mathrm dx=ik\\tilde{f}(k)$$\r\nSo we can employ Fourier transform to turn a (nice enough) differential equation into an algebraic one.\\\\\r\nWe also have a sense of duality between $x$ and $k$ here.\r\nObserve that we have\r\n$$f(-x)=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\tilde{f}(k)e^{-ikx}\\,\\mathrm dk,f(-k)=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\tilde{f}(x)e^{-ikx}\\,\\mathrm dx$$\r\nTherefore $g(x)=\\tilde{f}(x)$ iff $\\tilde{g}(k)=2\\pi f(-k)$..\r\nSo $f(-x)=(2\\pi)^{-1}\\mathcal F^2(f)(x)$.\r\nIterating this gives $\\mathcal F^4(f)(x)=4\\pi^2f(x)$.\r\n\\begin{example}\r\n    Consider the ``top hat'' function\r\n    $$f(x)=\\begin{cases}\r\n        1\\text{, if $|x|\\le a$}\\\\\r\n        0\\text{, if $|x|>a$}\r\n    \\end{cases}$$\r\n    We get\r\n    $$\\tilde{f}(k)=\\int_{-\\infty}^\\infty f(x)e^{-ikx}\\,\\mathrm dx=\\int_{-a}^a\\cos(kx)\\,\\mathrm dx=\\frac{2\\sin(ka)}{k}$$\r\n    Fourier inversion theorem then gives\r\n    $$\\frac{1}{\\pi}\\int_{-\\infty}^\\infty e^{ikx}\\frac{\\sin ka}{k}\\,\\mathrm dk=\\begin{cases}\r\n        1\\text{, if $|x|<a$}\\\\\r\n        0\\text{, if $|x|>a$}\r\n    \\end{cases}$$\r\n    Set $x=0$ and $k\\to x$ gives\r\n    $$\\int_0^\\infty\\frac{\\sin(ax)}{x}\\,\\mathrm dx=\\frac{\\pi}{2}\\operatorname{sgn}(a)=\\begin{cases}\r\n        \\pi/2\\text{, if $a>0$}\\\\\r\n        0\\text{, if $a=0$}\\\\\r\n        -\\pi/2\\text{, if $a<0$}\r\n    \\end{cases}$$\r\n    which is pretty awesome.\r\n\\end{example}\r\n\\subsection{Convolution and Parseval's Theorem}\r\nRecall that\r\n\\begin{definition}\r\n    The convolution of $f$ and $g$ is\r\n    $$(f\\ast g)(x)=\\int_{-\\infty}^\\infty f(y)g(x-y)\\,\\mathrm dy$$\r\n\\end{definition}\r\nWe want to multiply together functions in frequency domain, that is $\\tilde{h}=\\tilde{f}\\tilde{g}$, and find its inverse Fourier transform.\r\n\\begin{align*}\r\n    h(x)&=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\tilde{f}(k)\\tilde{g}(k)e^{ikx}\\,\\mathrm dk\\\\\r\n    &=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\left( \\int_{-\\infty}^\\infty f(y)e^{-iky}\\,\\mathrm dy \\right)\\tilde{g}(k)e^{ikx}\\,\\mathrm dk\\\\\r\n    &=\\int_{-\\infty}^\\infty f(y)\\left( \\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\tilde{g}(k)e^{ik(x-y)}\\,\\mathrm dk \\right)\\,\\mathrm dy\\\\\r\n    &=\\int_{-\\infty}^\\infty f(y)g(x-y)\\,\\mathrm dy\\\\\r\n    &=(f\\ast g)(x)\r\n\\end{align*}\r\nBy duality, we also have\r\n$$h(x)=f(x)g(x)\\implies \\tilde{h}(k)=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty \\tilde{f}(p)\\tilde{g}(k-p)\\,\\mathrm dp=\\frac{1}{2\\pi}(\\tilde{f}\\ast\\tilde{g})(k)$$\r\nNow consider $h(x)=g^*(-x)$, then\r\n\\begin{align*}\r\n    \\tilde{h}(k)&=\\int_{-\\infty}^\\infty g^\\ast(-x)e^{-ikx}=\\left( \\int_{-\\infty}^\\infty g(-x)e^{ikx}\\,\\mathrm dx \\right)^*\\\\\r\n    &=\\left( \\int_{-\\infty}^\\infty g(y)e^{-iky}\\,\\mathrm dy \\right)^*=\\tilde{g}^*(k)\r\n\\end{align*}\r\nBy our study of convolution we have\r\n$$\\int_{-\\infty}^\\infty f(y)g^*(y-x)\\,\\mathrm dy=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\tilde{f}(k)\\tilde{g}^*(k)e^{ikx}\\,\\mathrm dx$$\r\nSet $x\\to 0$ gives\r\n$$\\int_{-\\infty}^\\infty f(y)g^*(y)\\,\\mathrm dy=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\tilde{f}(k)\\tilde{g}^*(k)\\,\\mathrm dk\\implies\\langle g,f\\rangle=\\frac{1}{2\\pi}\\langle \\tilde{g},\\tilde{f}\\rangle$$\r\nSetting $g=f$ then gives\r\n\\begin{theorem}[Parseval's Theorem]\r\n    $$\\int_{-\\infty}^\\infty|f(x)|^2\\,\\mathrm dx=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty |\\tilde{f}(k)|^2\\,\\mathrm dk$$\r\n\\end{theorem}\r\n\\subsection{Fourier Transform of Generalised Functions}\r\nWe want to apply $\\mathcal F$ to generalised functions.\r\nIf one wants to be precise, one can view them as the limit of the sequence of the Fourier transforms of well-defined well-behaved functions that approaches the generalised function in question.\r\nThe details can be justified by Parseval's theorem, but the treatment is beyond the scope of this course.\\\\\r\nOf course the main culprit of generalised functions is $\\delta$.\r\nSurprisingly, $\\delta$ is found naturally in Fourier transform.\r\nFor a well-behaved $f$,\r\n\\begin{align*}\r\n    f(x)&=\\mathcal F^{-1}(\\mathcal F(f))(x)=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\int_{-\\infty}^\\infty f(u)e^{-iku}e^{ikx}\\,\\mathrm du\\mathrm dk\\\\\r\n    &=\\int_{-\\infty}^\\infty f(u)\\left( \\frac{1}{2\\pi}\\int_{-\\infty}^\\infty e^{ik(x-u)}\\,\\mathrm dk \\right)\\,\\mathrm du\r\n\\end{align*}\r\nSo we might identify\r\n\\footnote{The number of things that would go wrong with this is overwhelming, but what the hell.}\r\n$$\\delta(x-u)=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty e^{ik(x-u)}\\,\\mathrm dk$$\r\nA direct calculation, on the other hand yields\r\n$$\\tilde\\delta(k)=\\int_{-\\infty}^\\infty \\delta(x)e^{ikx}\\,\\mathrm dx=1$$\r\nSo dually, the Fourier transform of the constant $f(x)=1$ is $\\tilde{f}(k)=2\\pi\\delta(x)$.\r\nAlso $f(x)=\\delta(x-a)$ has $\\tilde{f}(k)=e^{ika}$.\r\nIf we have exponentials then we naturally have trigonometrics, so here goes:\r\n$f(x)=\\cos(\\omega x)$ has $\\tilde{f}(k)=\\pi(\\delta(k+\\omega)+\\delta(k-\\omega))$ and $f(x)=\\sin(\\omega x)$ has $\\tilde{f}(k)=i\\pi (\\delta(k+\\omega)-\\delta(k-\\omega))$.\\\\\r\nLet's move on to something slightly better.\r\nConsider the Heaviside function\r\n$$H(x)=\\begin{cases}\r\n    1\\text{, if $x>0$}\\\\\r\n    0\\text{, if $x<0$}\\\\\r\n    1/2\\text{, if $x=0$}\r\n\\end{cases}$$\r\nThen $H(x)+H(-x)=1$ for any $x$.\r\nTherefore $\\tilde{H}(k)+\\tilde{H}(-k)=2\\pi\\delta(k)$.\r\nBut $H^\\prime(x)=\\delta(x)$, hence $ik\\tilde{H}(k)=1$.\r\nSo for these results to be consistent (note that $k\\delta(k)=1$), we had to have $\\tilde{H}(k)=\\pi\\delta(k)+(ik)^{-1}$.\r\nThe formula can look nicer if we shift a bit and consider instead $f(x)=\\operatorname{sgn}(x)/2$ which has $\\tilde{f}(k)=(ik)^{-1}$.\r\n\\subsection{Applications of Fourier Transforms}\r\nThe first very important application of Fourier transforms is in boundary value problems of ODEs.\r\nConsider the problem $y^{\\prime\\prime}-y=f(x)$ with homogeneous boundary conditions $y\\to 0$ as $x\\to\\pm\\infty$.\r\nApply Fourier transform on both sides gives\r\n$$(-k^2-1)\\tilde{y}=\\tilde{f}\\implies \\tilde{y}(k)=\\tilde{f}(k)\\tilde{g}(k),\\tilde{g}(k)=-\\frac{1}{1+k^2}$$\r\nTherefore\r\n\\begin{align*}\r\n    y(x)&=\\int_{-\\infty}^\\infty f(u)g(x-u)\\,\\mathrm du\\\\\r\n    &=-\\frac{1}{2}\\int_{-\\infty}^\\infty f(u)e^{-|x-u|}\\,\\mathrm du\\\\\r\n    &=-\\frac{1}{2}\\int_{-\\infty}^xf(u)e^{u-x}\\,\\mathrm du-\\frac{1}{2}\\int_x^\\infty f(u)e^{x-u}\\,\\mathrm du\r\n\\end{align*}\r\nwhich is in the form of the solution we would have obtained if we use Green's function instead.\r\nOf course, we can solve this by inverse Fourier transform as well, which is quite easy once we introduce Fast Fourier Transform (FFT).\r\nWe will go through it later.\\\\\r\nAnother motivation of Fourier transform in signal processing.\r\nSuppose we are given some sort of input signal $J(t)$ which is acted on by some linear differential operator $\\mathcal L$ to yield output $O(t)$.\r\nThe Fourier transform\r\n$$\\tilde{J}(\\omega)=\\int_{-\\infty}^\\infty J(t)e^{i\\omega t}\\,\\mathrm dt$$\r\nis called the resolution.\r\nIn the frequency domain, the action of $\\mathcal L$ in $J(t)$ is just multiplying $\\tilde{J}(\\omega)$ by a transfer function $\\tilde{R}\\omega$ to yield the output\r\n$$O(t)=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\tilde{R}(\\omega)\\tilde{J}(\\omega)e^{i\\omega t}\\,\\mathrm d\\omega$$\r\nThe inverse Fourier transform $R$ of $\\tilde{R}$ is called the response function.\r\nSo $O$ is simply $J\\ast R$.\r\nFor example, if there is no input $J(t)=0$ for $t<0$.\r\nBy causality, we expect $R(t)=0$ for $t<0$.\r\nTherefore\r\n$$O(t)=\\int_0^tJ(u)R(t-u)\\,\\mathrm du$$\r\nwhich is in the same form as the Green's function in an initial value problem.\\\\\r\nWe want to explore the general transfer functions for a class of ODEs.\r\nSuppose the input/output relation is\r\n$$\\mathcal LO=\\left( \\sum_{i=0}^na_i\\frac{\\mathrm d^i}{\\mathrm dx^i} \\right)O=J$$\r\nwhere $a_i$ are constants.\r\nTaking Fourier transform gives\r\n$$(a_0+a_1(i\\omega)+\\ldots,a_n(i\\omega)^n)\\tilde{O}(\\omega)=\\tilde{J}(\\omega)$$\r\nTherefore $\\tilde{R}(\\omega)=(a_0+a_1(i\\omega)+\\ldots,a_n(i\\omega)^n)^{-1}$.\r\nFactorise the polynomial to turn it into the form $\\tilde{R}(\\omega)=((i\\omega-c_1)^{k_1}\\cdots (i\\omega-c_r)^{k_r})^{-1}$ where $i\\neq j\\implies c_i\\neq c_j$.\r\nPartial fraction gives\r\n$$\\tilde{R}(\\omega)=\\frac{1}{(i\\omega-c_1)^{k_1}\\cdots (i\\omega-c_r)^{k_r}}=\\sum_{j=1}^r\\sum_{m=1}^{k_j}\\frac{\\Gamma_{jm}}{(i\\omega-c_j)^m}$$\r\nfor constants $\\Gamma_{jm}$.\r\nBut we know that\r\n$$\\mathcal F^{-1}\\left( \\frac{1}{(i\\omega-a)^m} \\right)=\\begin{cases}\r\n    t^{m-1}e^{at}/(m-1)!\\text{, if $t>0$}\\\\\r\n    0\\text{, if $t<0$}\r\n\\end{cases}$$\r\nGetting back to time domain, we obtain the response function\r\n$$R(t)=\\sum_{j=1}^r\\sum_{m=1}^{k_j}\\Gamma_{jm}\\frac{t^{m-1}}{(m-1)!}e^{c_jt},t>0$$\r\n\\begin{example}\r\n    Consider the damp oscillator $\\mathcal Ly=y^{\\prime\\prime}+2py^\\prime+(p^2+q^2)y=f(t)$ with damping $p>0$ with homogeneous initial conditions $y(0)=y^\\prime(0)=0$.\r\n    The Fourier transform of this is $(i\\omega)^2\\tilde{y}+2ip\\omega\\tilde{y}+(p^2+q^2)\\tilde{y}=\\tilde{f}$, so\r\n    $$\\tilde{y}=\\frac{\\tilde{f}}{-\\omega^2+2ip\\omega+p^2+q^2}=\\tilde{R}\\tilde{f},\\tilde{R}=\\frac{1}{-\\omega^2+2ip\\omega+p^2+q^2}$$\r\n    So\r\n    $$y(t)=\\int_0^tR(t-\\tau)f(\\tau)\\,\\mathrm d\\tau,R(t-\\tau)=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\frac{\\exp(i\\omega(t-\\tau))\\,\\mathrm d\\omega}{p^2+q^2+2ip\\omega-\\omega^2}$$\r\n    which, as one can verify, is analogous to the Green's function methods since $\\mathcal LR(t-\\tau)=\\delta(t-\\tau)$.\r\n\\end{example}\r\n\\subsection{Discrete Fourier Transform}\r\nSuppose we sample a signal $h(t)$ at equal times $t_n=n\\Delta$ with time-sampling $\\Delta$ and values $h_n=h(n\\Delta)$ with $n\\in\\mathbb Z$.\r\nThat is, the sampling frequency is $f_s=1/\\Delta$ (and angular frequency $\\omega_s=2\\pi f_s=2\\pi/\\Delta$).\r\nThe Nyquist frequency $f_c=1/(2\\Delta)$ is the highest frequency actually sampled at $\\Delta$.\r\nSuppose we have a (sinusoidal) signal with a given frequency $f$\r\n$$g_f(t)=A\\cos(2\\pi ft+\\phi)=\\frac{A}{2}(e^{i\\phi}e^{2\\pi ift}+e^{-i\\phi}e^{-2\\pi ift})$$\r\nWhat happens if we sample at $f=f_c$?\r\nWe have\r\n$$g_{f_c}(t_n)=A\\cos\\left( 2\\pi\\frac{1}{2\\Delta}n\\Delta+\\phi \\right)=(A\\cos\\phi)\\cos(\\pi n)=A'\\cos(2\\pi f_ct_n)$$\r\nSo information about phase and amplitude are lost.\r\nEven worse if we sample above $f>f_c$:\r\nIf we sample at $f=f_c+\\delta f$ for some small $\\delta f>0$, then\r\n$$g_f(t_n)=A\\cos(2\\pi(f_c+\\delta f)t_n+\\phi)=A\\cos(2\\pi(f_c-\\delta f)t_n-\\phi)$$\r\nSo the effect is just aliasing a ``ghost signal'' to frequency $f_c-\\delta f$ (or $-(f_c-\\delta f)$), which is a contamination of the information.\r\n\\begin{definition}\r\n    A signal $g(t)$ is bandwidth limited if it contains no frequency above some $\\omega_{\\max{}}=2\\pi f_{\\max{}}$, that is $\\tilde{g}(\\omega)=0$ for any $|\\omega|>\\omega_{\\max{}}$.\r\n\\end{definition}\r\nSo for a bandwidth limited signal $g(t)$ would have\r\n$$g(t)=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\tilde{g}(\\omega)e^{i\\omega t}\\,\\mathrm d\\omega=\\frac{1}{2\\pi}\\int_{-\\omega_{\\max{}}}^{\\omega_{\\max{}}}\\tilde{g}(\\omega)e^{i\\omega t}\\,\\mathrm d\\omega$$\r\n\\begin{theorem}[Sampling Theorem]\r\n    Let $g$ be a bandwidth limited signal and $\\Delta=1/(2f_{\\max{}})$, then define\r\n    $$g_n=g(t_n)=\\frac{1}{2\\pi}\\int_{-\\omega_{\\max{}}}^{\\omega_{\\max{}}}\\tilde{g}(\\omega)e^{i\\pi n\\omega/\\omega_{\\max{}}}\\,\\mathrm d\\omega$$\r\n    which induces a Fourier series\r\n    $$\\tilde{g}_{\\mathrm{per}}(\\omega)=\\frac{\\pi}{\\omega_{\\max{}}}\\sum_{n=-\\infty}^\\infty g_ne^{-i\\pi n\\omega/\\omega_{\\max{}}}$$\r\n    Then, we have\r\n    $$\\tilde{g}(\\omega)=\\tilde{g}_{\\mathrm{per}}(\\omega)\\tilde{h}(\\omega),\\tilde{h}(\\omega)=\\begin{cases}\r\n        1\\text{, if $|\\omega|\\le\\omega_{\\max{}}$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    Inverting which gives\r\n    \\begin{align*}\r\n        g(t)&=\\frac{1}{2\\omega_{\\max{}}}\\sum_{n=-\\infty}^\\infty g_n\\int_{-\\omega_{\\max{}}}^{\\omega_{\\max{}}}\\exp\\left( i\\omega\\left( t-\\frac{n\\pi}{\\omega_{\\max{}}} \\right) \\right)\\,\\mathrm d\\omega\\\\\r\n        &=\\sum_{n=-\\infty}^\\infty g_n\\frac{\\sin(\\omega_{\\max{}} t-\\pi n)}{\\omega_{\\max{}} t-\\pi n}\r\n    \\end{align*}\r\n    So $g(t)$ can be exactly represented after sampling at discrete times $t_n$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Self-explanatory.\r\n\\end{proof}\r\nSuppose we have a finite number $N$ of samples $h_m=h(t_m)$ where $t_m=m\\Delta$ for $m=0,\\ldots,N-1$.\r\nWe want to approximate the Fourier Transform for $N$ frequencies within $f_c=1/(2\\Delta)$ with equally spaced frequencies with space $\\Delta_f=1/(N\\Delta)$ in the range $[-f_c,f_c]$.\r\nSo basically we are just looking for $f_n=n\\Delta_f=n/(N\\Delta)$ where $n=-N/2,\\ldots,0,\\ldots,N/2$.\r\nNote that $f_c$ and $-f_c$ are aliased together, so the $-N/2$ and $N/2$ are basically the same.\r\nAlso $(m+N/2)\\Delta_f=f_c+\\delta f$ is aliased to $(-m+N/2)\\Delta_f=-(f_c-\\delta f)$, so we choose instead $f_n=n/(N\\Delta)$ with $n=0,\\ldots,N-1$.\r\n\\begin{definition}\r\n    Observe that\r\n    \\begin{align*}\r\n        \\tilde{h}(f_n)&=\\int_{-\\infty}^\\infty h(t)e^{-2\\pi if_nt}\\,\\mathrm dt\\approx\\Delta\\sum_{n=0}^{N-1}h_me^{-2\\pi i f_nt_m}\\\\\r\n        &=\\Delta\\sum_{m=0}^{N-1}h_me^{-2\\pi imn/N}=\\Delta\\tilde{h}_d(f_n)\r\n    \\end{align*}\r\n    Here $\\tilde{h}_d(f_n)=\\tilde{h}_n$ is the discrete Fourier transform (DFT).\r\n\\end{definition}\r\nSo the matrix $[\\operatorname{DFT}]_{mn}=e^{-2\\pi imn/N}$ defines the discrete Fourier transform for $h=\\{h_m\\}$ as we have $\\tilde{h}_d=[\\operatorname{DFT}]h$.\r\nThe inverse of this matrix is its adjoint, i.e. $[\\operatorname{DFT}]^{-1}=N^{-1}[\\operatorname{DFT}]^\\dagger$ and it is built from the $N^{th}$ roots of unity.\r\n\\begin{example}\r\n    If $N=4$ and $\\omega=-i$, then\r\n    $$[\\operatorname{DFT}]=\\begin{pmatrix}\r\n        1&1&1&1\\\\\r\n        1&-i&-1&i\\\\\r\n        1&-1&1&-1\\\\\r\n        1&i&-1&-i\r\n    \\end{pmatrix}$$\r\n\\end{example}\r\nThe inverse DFT is\r\n\\begin{align*}\r\n    h_m&=h(t_m)\\approx\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty\\tilde{h}(\\omega)e^{i\\omega t_m}\\,\\mathrm d\\omega=\\int_{-\\infty}^\\infty\\tilde{h}(f)e^{2\\pi ift_m}\\,\\mathrm df\\\\\r\n    &\\approx\\frac{1}{N\\Delta}\\sum_{n=0}^{N-1}\\Delta\\tilde{h}_d(f_n)e^{2\\pi imn/N}\\\\\r\n    &=\\frac{1}{N}\\sum_{n=0}^{N-1}\\tilde{h}_ne^{2\\pi imn/N}\r\n\\end{align*}\r\nIn this frame, we can establish analogues of Parseval's theorem\r\n$$\\sum_{m=0}^{N-1}|h_m|^2=\\frac{1}{N}\\sum_{n=0}^{N-1}|\\tilde{h}_n|^2$$\r\nand convolution theorem\r\n$$c_k=\\sum_{m=0}^{N-1}g_mh_{k-m}\\iff \\tilde{c}_k=\\tilde{g}_k\\tilde{h}_k$$\r\nThis looks complicated, but there is actually a very efficient algorithm to do it, known as fast Fourier transform (FFT), by exploiting the symmetries of the expression.", "meta": {"hexsha": "acf4f7998152944f45cac2480bc57da2c50e62b8", "size": 18097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8/ft.tex", "max_stars_repo_name": "david-bai-notes/IB-Methods", "max_stars_repo_head_hexsha": "b60135106d09d1e24d2f7b9c7e3eee1ca69f6907", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "8/ft.tex", "max_issues_repo_name": "david-bai-notes/IB-Methods", "max_issues_repo_head_hexsha": "b60135106d09d1e24d2f7b9c7e3eee1ca69f6907", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "8/ft.tex", "max_forks_repo_name": "david-bai-notes/IB-Methods", "max_forks_repo_head_hexsha": "b60135106d09d1e24d2f7b9c7e3eee1ca69f6907", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.526119403, "max_line_length": 199, "alphanum_fraction": 0.633640935, "num_tokens": 6874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947455, "lm_q2_score": 0.8688267864276108, "lm_q1q2_score": 0.811827549498474}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Reference Triangle Within}\nConsider any reference triangle with legs $x$ and $y$ and $r$, and angles $\\frac{\\tau}{4}$\nand $\\theta$.  The other angle must be $\\frac{\\tau}{4} - \\theta$.  What are $\\sin\\theta$ and\n$\\cos\\theta$?  What are $\\sin(\\frac{\\tau}{4}-\\theta)$ and $\\cos(\\frac{\\tau}{4}-\\theta)$?\n\ninsert diagram\n\nNow, at last, we are prepared to answer why half of the six trigonometric functions have the\nprefix ``co-''.  It stands for complement!\n\nsix co-definitions\n\n\nWe have repeatedly seen that sine is the signed height of the reference triangle within the unit\ncircle, while cosine is the signed width.  Because these lengths are within the unit circle (a\ncircle of radius 1), they must be in a Pythagorean relationship.  This reference triangle within \nthe unit circle provides an excellent visual to accompany the identity, $\\sin^2\\theta+\\cos^2\\theta\n= 1$.  But through simple algebra manipulation -- dividing by $\\sin^2\\theta$ or $\\cos^2\\theta$ ---\nit is easy to turn this identity into $1 + \\tan^2\\theta = \\sec^2\\theta$, or the more obscure\n$\\csc^2\\theta + 1 = \\cot^2\\theta$.  What do they represent?\n\n\\subsection{Reference Triangles Without}\nWe have previously defined tangent as sine over cosine, which means we can set up the proportion:\n\n\\begin{equation}\n\\frac{\\sin\\theta}{\\cos\\theta} = \\frac{\\tan\\theta}{1}\n\\end{equation}\n\nThis is not only algebra, but can be represented with similar triangles.  ``Sine is to cosine as tangent is to\n1'', is the height of one triangle compared to its width, keeping a common angle and still being right in\nanother triangle whose height is tangent and width is 1.  This is a right triangle extending outside\nthe unit circle, but whole bottom edge is a radius thereof.\n\ninsert diagram\n\nSimilarly, there are two more proportions we must examine:\n\\begin{equation}\n\\frac{\\cos\\theta}{\\sin\\theta} = \\frac{\\cot\\theta}{1}\n\\end{equation}\nThis is a way of saying the width vs. height of one triangle is cosine vs. sine, and that a similar right\ntriangle (with angle in common) has width cotangent and height 1.  \n\ninsert diagram\n\nExercise: show that this get the same length as 1 over tangent equals cotangent over 1.\n\nThere is also\n\\begin{equation}\n\\frac{1}{\\cos\\theta} = \\frac{\\sec\\theta}{1}\n\\end{equation}\n\nGeometrically this means, if we draw a triangle with hypotenuse 1 and adjacent of cosine, then there must exist a unique, similar triangle with hypotenuse secant and adjacent 1.\n\n\n\\subsection{Relative}\nIt should be apparent now that trigonometry is very different from algebra.  Every expression can be \nwritten in an infinite number of ways.  Every term is equal to 1 times itself (the Identity of Multiplication),\nbut 1 equals $\\sin^2\\theta + \\cos^2\\theta$ or $\\sec^2\\theta-\\tan^2\\theta$.  We practice turning \ntrigonometry expressions into specific forms so that we will be fluent in simplify complicated \nexpressions in the real world.\n\nThe co-function identities (above) show us what to do with $90^\\circ/\\frac{\\tau}{4}$s inside of\ntrig functions, but what about other quadrants and negatives?  There are always lots of options\nfor how you might think about such things, so we will consider two ways to think about\nsimplifying $\\sin(-x)$ and $\\cos(-x)$.\n\nGraphically, you can see that $y=\\sin(x)$ is an odd function.  On the unit circle, if we begin at\nstandard position, we see that turning a positive angle yields a certain height above the $x$-axis,\nwhile turning that same angle \\emph{down} yields the opposite height.  Hence, $\\sin(-x)=-\\sin(x)$.\n$y=\\cos(-x)$ is an even function, begin symmetric about the $y$-axis.  On the unit circle, the \nhorizontal displacement caused by any angle is the same as its negative angle.  Hence,\n$\\cos(-x)=\\cos(x)$.\n\n", "meta": {"hexsha": "24c43a6f9a02361568e62ff17f74412d26e204bb", "size": 3753, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch10/1002.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch10/1002.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch10/1002.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.3815789474, "max_line_length": 177, "alphanum_fraction": 0.7452704503, "num_tokens": 989, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742805, "lm_q2_score": 0.8872046011730964, "lm_q1q2_score": 0.8117043451218443}}
{"text": "\\documentclass[11pt]{article}\n\n\n\\usepackage{amsfonts}\n\\usepackage{fancyvrb}\n\\usepackage{graphicx}\n\\usepackage{caption}\n\\usepackage{subcaption}\n\\usepackage{url}\n\n\\setlength{\\oddsidemargin}{0in}\n\\setlength{\\evensidemargin}{0in}\n\\setlength{\\textwidth}{6.5in}\n\\setlength{\\topmargin}{0in}\n\\setlength{\\headsep}{0.5in}\n\\setlength{\\textheight}{8.5in}\n\\setcounter{page}{1}\n%\\pagestyle{empty}\n%\\hbadness=10000\n\n\\begin{document}\n\\huge\n\\noindent\n{Discrete Optimization Assignment:}\n\\vspace{0.25cm}\n\n\\noindent\n{\\bf Traveling Salesman Problem}\n\\normalsize\n\n\n\\section{Problem Statement}\n\nIn this assignment you will design an algorithm to solve a fundamental problem faced by every traveling salesperson, aptly named {\\em The Traveling Salesman Problem (TSP)}.  All traveling salespeople start from their home, travel to several cities to sell their goods, and complete the day by returning home.  To minimize their costs, traveling salespeople strive to visit all of the cities using the shortest total travel distance.  This amounts to finding a visitation order of all of the cities that  minimizes the sum of distances traveled when moving from one city to another.  Figure \\ref{fig:tsp} illustrates a small TSP and a feasible solution to that problem.  The cities are labeled from $0..4$.\n\n\n\\begin{figure}[h]\n        \\centering\n        \\begin{subfigure}[b]{8.0cm}%{0.3\\textwidth}\n                \\centering\n                \\includegraphics[width=6cm]{figures/tsp_1.pdf}\n                \\caption{The TSP input data.}\n                \\label{fig:vrp:input}\n        \\end{subfigure}%\n        ~ %add desired spacing between images, e. g. ~, \\quad, \\qquad etc.\n          %(or a blank line to force the subfigure onto a new line)\n        \\hfill\n        \\begin{subfigure}[b]{8.0cm}\n                \\centering\n                \\includegraphics[width=6cm]{figures/tsp_2.pdf}\n                \\caption{A solution to the TSP.}\n                \\label{fig:vrp:sol}\n        \\end{subfigure}\n        \\caption{A Traveling Salesman Example}\\label{fig:tsp}\n\\end{figure}\n\n\\section{Assignment}\n\nWrite an algorithm to solve the traveling salesman problem (a.k.a. minimize the length of a hamiltonian cycle\\footnote{See \\url{http://en.wikipedia.org/wiki/Hamiltonian_path}} of a graph).  The problem is mathematically formulated in the following way:  Given a list of locations $N = 0 \\ldots n-1$ and coordinates for each location $\\langle x_i,y_i \\rangle \\; i \\in N$.  Let $v_i \\;\\; i \\in N$ be a variable denoting the visitation order (i.e. the value of $v_i$ is the $i$-th location to be visited) and let ${\\it dist}(l_1,l_2)$ be the Euclidean distance between two locations.\\footnote{${\\it dist}(n,m) = \\sqrt{(x_{n} - x_{m})^2 + (y_{n} - y_{m})^2}$}  Then the traveling salesman problem is formalized as the following optimization problem,\n$$\n\\begin{array}{ll}\n\\mbox{minimize:} & \\displaystyle \\sum_{i \\in 0 \\ldots n-1} dist(v_i,v_{i+1}) + dist(v_n,v_{0}) \\\\\n\\mbox{subject to:} & \\\\\n     & v_i\\mbox{ are a permutation of } N \n\\end{array}\n$$\nIn this variant of the traveling salesman problem, we assume the sales person travels by helicopter and can go directly in a straight line from one point to another.\n\n\\section{Data Format Specification}\n\nThe input consists of $|N| + 1$ lines.  The first line contains one number $|N|$.\nIt is followed by $|N|$ lines, each line represents a point $\\langle x_i, y_i \\rangle$ where $x_i, y_j \\in \\mathbb{R}$.\n\n\\vspace{0.2cm}\n\\noindent\nInput Format\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n|N| \nx_0 y_0\nx_1 y_1\n...\nx_|N|-1 y_|N|-1\n\\end{Verbatim}\n%\nThe output has two lines.  The first line contains two values $obj$ and $opt$.  $obj$ is the length of the hamiltonian cycle (i.e. the objective value) as a real number.  $opt$ should be $1$ if your algorithm proved optimality and $0$ otherwise.  The next line is a list of $n$ values in $N$, one for each of the $v_i$ variables.  This line encodes the solution.\n\n\\vspace{0.2cm}\n\\noindent\nOutput Format\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\nobj opt\nv_0 v_1 v_2 ... v_|N|-1\n\\end{Verbatim}\n%\n%It is essential that the value order in the solution output matches the value order of the input.  Otherwise the grader will misinterpret the output.\n\n\\paragraph{Examples} \\mbox{}\n%\\vspace{0.1cm}\n%\\noindent\n(based on Figure \\ref{fig:tsp})\n\n\\vspace{0.2cm}\n\\noindent\nInput Example\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n5\n0 0\n0 0.5\n0 1\n1 1\n1 0\n\\end{Verbatim}\n\n\\vspace{0.2cm}\n\\noindent\nOutput Example\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n5.2 0\n0 4 1 3 2\n\\end{Verbatim}\n%\nThis output represents the following hamiltonian cycle, $\\{0 \\rightarrow 4, 4 \\rightarrow 1, 1 \\rightarrow 3, 3 \\rightarrow 2, 2 \\rightarrow 0\\}$\n\n\\section{Instructions}\n\n\\input{instructions.tex}\n\n%We use \\texttt{stdout} for output.\n%Output to other stream will be ignored (you may want to send runtime information to \\texttt{stderr}). Your submission will be tested on a department linux machine. If your algorithm is a standalone program, please name it \\texttt{nr},\n%otherwise, please specify the compilation procedure,\n%it is appreciated if you also provide a script that follows the above format to run the program.\n\n\\paragraph{Resources}\nYou will find several  traveling salesman problem instances in the \\texttt{data} directory provided with the handout.\n\n%An example output file, \\texttt{blabla.out}, is also provided.\n\n%\\section{Remarks}\n\n\\input{handin.tex}\n\n\\input{grading.tex}\n\n\\input{collaboration.tex}\n\n%\\paragraph{Questions} Please contact the class GTA Carleton (cjc@cs.brown.edu).\n\n\\input{warnings.tex}\n\n%\\paragraph{Hint} \n%The optimal value for  \\texttt{data/gc\\_1000\\_5} is near $85$.\n \n\\input{techReqs.tex}\n\n\\end{document}\n\n\n\n\n", "meta": {"hexsha": "fe1a90cce69e94f270e51414cea8b6271688a69d", "size": 5689, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/tsp.tex", "max_stars_repo_name": "mike715/assignment", "max_stars_repo_head_hexsha": "f69378420ce2bb845abaef0f448eab303aa7a7e7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 101, "max_stars_repo_stars_event_min_datetime": "2016-08-08T05:41:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T15:04:42.000Z", "max_issues_repo_path": "handouts/tsp.tex", "max_issues_repo_name": "sthagen/assignment", "max_issues_repo_head_hexsha": "57d18b188177269c8fe07f3d9bef416720c7b465", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 44, "max_issues_repo_issues_event_min_datetime": "2016-08-07T20:57:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-01T08:07:50.000Z", "max_forks_repo_path": "handouts/tsp.tex", "max_forks_repo_name": "sthagen/assignment", "max_forks_repo_head_hexsha": "57d18b188177269c8fe07f3d9bef416720c7b465", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 88, "max_forks_repo_forks_event_min_datetime": "2016-10-05T23:38:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-28T09:28:46.000Z", "avg_line_length": 34.6890243902, "max_line_length": 745, "alphanum_fraction": 0.7155914924, "num_tokens": 1693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.9149009607937928, "lm_q1q2_score": 0.8117043297552535}}
{"text": "\\lab{Differentiation}{Differentiation}\n\\label{lab:Derivatives}\n\\objective{Derivatives are central in many applications.\nDepending on the application and on the available information, the derivative may be calculated symbolically, numerically, or with differentiation software.\nIn this lab we explore these three ways to take a derivative, discuss what settings they are each appropriate for, and demonstrate their strengths and weaknesses.\n% This lab should be done after completing the Python Essentials lab on SymPy.\n}\n\n\\section*{Symbolic Differentiation} % =========================================\n\nThe derivative of a known mathematical function can be calculated symbolically with SymPy.\nThis method is the most precise way to take a derivative, but it is computationally expensive and requires knowing the closed form formula of the function.\nUse \\li{sy.diff()} to take a symbolic derivative.\n\n\\begin{lstlisting}\n>>> import sympy as sy\n\n>>> x = sy.symbols('x')\n>>> sy.diff(x**3 + x, x)     # Differentiate x^3 + x with respect to x.\n<<3*x**2 + 1>>\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a function that defines $f(x) = (\\sin(x) + 1)^{\\sin(\\cos(x))}$ and takes its symbolic derivative with respect to $x$ using SymPy.\nLambdify the resulting function so that it can accept NumPy arrays and return the resulting function handle.\n% returns the derivative of $e^{\\sin\\left(\\cos\\left(x\\right)\\right)}$ at $x=1$ as a float using SymPy.\n\nTo check your function, plot $f$ and its derivative $f'$ over the domain $[-\\pi, \\pi]$.\nIt may be helpful to move the bottom spine to $0$ so you can see where the derivative crosses the $x$-axis.\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n\n>>> ax = plt.gca()\n>>> ax.spines[\"bottom\"].set_position(\"zero\")\n\\end{lstlisting}\n% >>> for label in [\"right\", \"top\"]:      # Turn other spines off.\n% ...     ax.spines[label].set_visible(False)\n% ...\n% \\end{lstlisting}\n\\label{prob:sympy-symbolic-diff}\n\\end{problem}\n\n\\section*{Numerical Differentiation} % ========================================\n\n% Derivatives can be approximated numerically by formulas called \\emph{finite difference quotients}.\n% Although these formulas do not return exact answers like SymPy, they are computationally inexpensive.\n% They are especially advantageous in situations where the original function may not be known or when the using derivative is very complex.\n\nOne definition for the derivative of a function $f:\\mathbb{R}\\rightarrow\\mathbb{R}$ at a point $x_0$ is\n\\[\nf'(x_0) = \\lim_{h\\rightarrow 0} \\frac{f(x_0 + h)-f(x_0)}{h}.\n\\]\nSince this definition relies on $h$ approaching $0$, choosing a small, fixed value for $h$ approximates $f'(x_0)$:\n\\begin{equation}\nf'(x_0) \\approx \\frac{f(x_0+h) - f(x_0)}{h}.\n\\label{eq:first-order-forward-difference}\n\\end{equation}\nThis approximation is called the \\emph{first order forward difference quotient}.\nUsing the points $x_0$ and $x_0-h$ in place of $x_0+h$ and $x_0$, respectively, results in the \\emph{first order backward difference quotient},\n\\begin{equation}\nf'(x_0) \\approx \\frac{f(x_0) - f(x_0-h)}{h}.\n\\label{eq:first-order-backward-difference}\n\\end{equation}\n\nForward difference quotients use values of $f$ at $x_0$ and points greater than $x_0$, while backward difference quotients use the values of $f$ at $x_0$ and points less than $x_0$.\nA \\emph{centered difference quotient} uses points on either side of $x_0$, and typically results in a better approximation than the one-sided quotients.\nCombining (\\ref{eq:first-order-forward-difference}) and (\\ref{eq:first-order-backward-difference}) yields the \\emph{second order centered difference quotient},\n\\[\nf'(x_0) = \\frac{1}{2}f'(x_0) + \\frac{1}{2}f'(x_0) \\approx\n\\frac{f(x_0+h) - f(x_0)}{2h} + \\frac{f(x_0) - f(x_0-h)}{2h}\n= \\frac{f(x_0+h) - f(x_0-h)}{2h}.\n\\]\n\n\\begin{figure}[H] % Show which points each quotient uses.\n\\centering\n    \\begin{tikzpicture}\n    % Define colors\n    % Create asterisks and name each point\n    \\foreach \\p/\\x in {a/-5,b/-4,c/-3,d/-2,e/-1,f/0,g/1,h/2,i/3,j/4,k/5}{\\node[text depth=.25ex,text height=3ex] (\\p) at (\\x,0) {\\textbf{*}};}\n    % Circles\n    \\draw[thick,blue!30!black,opacity=0.5] (a) circle (7pt);\n    \\draw[thick,blue!30!black,opacity=0.5] (f) circle (7pt);\n    \\draw[thick,blue!30!black,opacity=0.5] (k) circle (7pt);\n    % Arrows and labels below\n    \\draw[->,>=stealth',thick,blue,shorten >=-.1cm,text=black] (-5,-1) node[text=black,below,font=\\normalsize,opacity=1,align=center] {$f'(\\bar{x})$\\\\Forward Difference} -- (a);\n    \\draw[->,>=stealth',thick,green,shorten >=-.1cm] (0,-1) node[text=black,below,font=\\normalsize,opacity=1,align=center] {$f'(\\hat{x})$\\\\Centered Difference} -- (f);\n    \\draw[->,>=stealth',thick,red,shorten >=-.1cm] (5,-1) node[text=black,below,font=\\normalsize,opacity=1,align=center] {$f'(\\tilde{x})$\\\\Backward Difference} -- (k);\n    % Labels above\n    \\foreach \\s/\\t in {a/\\bar{x},b/\\bar{x}+h,e/\\hat{x}-h,f/\\hat{x},g/\\hat{x}+h,j/\\tilde{x}-h,k/\\tilde{x}}{\\node[anchor=south,yshift=.5cm,text depth=.25ex,text height=1.5ex] at (\\s) {$\\t$};}\n    % Background rectangles\n    \\begin{pgfonlayer}{background}\n    \\draw[ultra thick,draw=blue,fill=blue,opacity=0.2] (-5.5,.5) rectangle +(2,-1);\n    \\draw[ultra thick,draw=green,fill=green,opacity=0.2] (-1.5,.5) rectangle +(3,-1);\n    \\draw[ultra thick,draw=red,fill=red,opacity=0.2] (5.5,.5) rectangle +(-2,-1);\n    \\end{pgfonlayer}\n    \\end{tikzpicture}\n\\caption{} % The different types of difference quotients require evaluating the function at different points near the point of interest.}\n\\label{fig:difference-quotient-grid}\n\\end{figure}\n\n\\begin{info}\nThe finite difference quotients in this section all approximate the first derivative of a function.\nThe terms \\emph{first order} and \\emph{second order} refers to how quickly the approximation converges on the actual value of $f'(x_0)$ as $h$ approaches $0$, not to how many derivatives are being taken.\n\nThere are finite difference quotients for approximating higher order derivatives, such as $f''$ or $f'''$.\nFor example, the centered difference quotient\n\\[\nf''(x_0) \\approx \\frac{f(x_0-h) - 2f(x_0) + f(x_0+h)}{h^2}\n\\]\napproximates the second derivative.\nThis particular quotient is important for finite difference methods that approximate numerical solutions to some partial differential equations.\n\\end{info}\n\n\nWhile we do not derive them here, there are other finite difference quotients that use more points to approximate the derivative, some of which are listed below.\nUsing more points generally results in better convergence properties.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{|c|c|c|}\n\\hline\nType & Order & Formula \\\\\n\\hline \\multirow{6}{*}{Forward} & & \\\\\n    & 1 & \\Large{$\\frac{f(x_0+h) - f(x_0)}{h}$} \\\\\n    & & \\\\\n    \\cline{2-3} & & \\\\\n    & 2 & \\Large{$\\frac{-3f(x_0) + 4f(x_0+h) - f(x_0+2h)}{2h}$} \\\\\n    & & \\\\\n\\hline \\multirow{6}{*}{Backward} & & \\\\\n    & 1 & \\Large{$\\frac{f(x_0) - f(x_0-h)}{h}$} \\\\\n    & & \\\\\n    \\cline{2-3} & & \\\\\n    & 2 & \\Large{$\\frac{3f(x_0) - 4f(x_0-h) + f(x_0-2h)}{2h}$} \\\\\n    & & \\\\\n\\hline \\multirow{6}{*}{Centered} & & \\\\\n    & 2 & \\Large{$\\frac{f(x_0+h) - f(x_0-h)}{2h}$} \\\\\n    & & \\\\\n    \\cline{2-3} & & \\\\\n    & 4 & \\Large{$\\frac{f(x_0-2h) - 8f(x_0-h) + 8f(x_0+h) -f(x_0+2h)}{12h}$} \\\\\n    & & \\\\\n\\hline\n\\end{tabular}\n\\caption{Common finite difference quotients for approximating $f'(x_0)$.}\n\\label{table:finite-difference-quotients}\n\\end{table}\n\n\\begin{problem} % Implement finite difference quotients.\nWrite a function for each of the finite difference quotients listed in Table \\ref{table:finite-difference-quotients}.\nEach function should accept a function handle $f$, an array of points \\li{x}, and a float $h$; each should return an array of the difference quotients evaluated at each point in \\li{x}.\n\nTo test your functions, approximate the derivative of $f(x) = (\\sin(x) + 1)^{\\sin(\\cos(x))}$ at each point of a domain over $[-\\pi,\\pi]$.\nPlot the results and compare them to the results of Problem \\ref{prob:sympy-symbolic-diff}.\n\\label{prob:implement-finite-difference-quotients}\n\\end{problem}\n\n\\subsection*{Convergence of Finite Difference Quotients} % --------------------\n\nFinite difference quotients are typically derived using Taylor's formula.\nThis method also shows how the accuracy of the approximation increases as $h\\rightarrow 0$:\n\\begin{equation}\nf(x_0+h) = f(x_0) + f'(x_0)h + R_2(h)\n\\quad\\Longrightarrow\\quad\n\\frac{f(x_0+h) - f(x_0)}{h} - f'(x_0) = \\frac{R_2(h)}{h},\n\\label{eq:taylor-formula-forward-diff}\n\\end{equation}\nwhere $R_2(h) = h^2 \\int_0^1 (1-t) f''(x_0+th)\\:dt$.\nThus the absolute error of the first order forward difference quotient is\n\\[\n\\left| \\frac{R_2(h)}{h} \\right|\n= |h| \\left|\\int_0^1 (1 - t)f''(x_0+th)\\:dt\\right|\n\\leq |h| \\int_0^1 |1 - t||f''(x_0+th)|\\:dt.\n\\]\nIf $f''$ is continuous, then for any $\\delta > 0$, setting $M = \\sup_{x \\in (x_0-\\delta, x_0+\\delta)} f''(x)$ guarantees that\n\\[\n\\left | \\frac{R_2(h)}{h} \\right | \\leq |h|\\int_0^1 M dt = M|h|\\hspace{0.03in}{\\in}\\hspace{0.03in}O(h).\n\\]\nwhenever $|h| < \\delta$.\nThat is, the error decreases at the same rate as $h$.\nIf $h$ gets twice as small, the error does as well.\nThis is what is meant by a \\emph{first order} approximation.\nIn a \\emph{second order} approximation, the absolute error is $O(h^2)$, meaning that if $h$ gets twice as small, the error gets four times smaller.\n\n\\begin{info} % O(h^2) notation\nThe notation $O(f(n))$ is commonly used to describe the temporal or spatial complexity of an algorithm.\nIn that context, a $O(n^2)$ algorithm is much worse than a $O(n)$ algorithm.\nHowever, when referring to error, a $O(h^2)$ algorithm is \\textbf{better} than a $O(h)$ algorithm because it means that the accuracy improves faster as $h$ decreases.\n\\end{info}\n\n\\begin{problem} % Convergence of difference quotients.\nWrite a function that accepts a point $x_0$ at which to compute the derivative of $f(x) = (\\sin(x)+1)^{\\sin(\\cos(x))}$.\nUse your function from Problem \\ref{prob:sympy-symbolic-diff} to compute the exact value of $f'(x_0)$.\nThen use each your functions from Problem \\ref{prob:implement-finite-difference-quotients} to get an approximate derivative $\\tilde{f}'(x_0)$ for $h=10^{-8},10^{-7},\\ldots,10^{-1},1$.\nTrack the absolute error $|f'(x_0) - \\tilde{f}'(x_0)|$ for each trial, then plot the absolute error against $h$ on a log-log scale (use \\li{plt.loglog()}).\n\nInstead of using \\li{np.linspace()} to create an array of $h$ values, use \\li{np.logspace()}.\nThis function generates logarithmically spaced values between two powers of $10$.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> np.logspace(-3, 0, 4)           # Get 4 values from 1e-3 to 1e0.\narray([ 0.001,  0.01 ,  0.1  ,  1.   ])\n\\end{lstlisting}\n\nFor $x_0 = 1$, your plot should resemble the following figure.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.7\\textwidth]{figures/error_plot.pdf}\n\\end{figure}\n\\label{prob:difference-quotient-convergence}\n\\end{problem}\n\n\\begin{warn}\nMathematically, choosing smaller $h$ values results in tighter approximations of $f'(x_0)$.\nHowever, Problem \\ref{prob:difference-quotient-convergence} shows that when $h$ gets too small, the error stops decreasing.\nThis numerical error is due to the denominator in each finite difference quotient becoming very small.\nThe optimal value of $h$ is usually one that is small, but not too small.\n\\end{warn}\n\n\\begin{problem}\nThe radar stations $A$ and $B$, separated by the distance $a = 500$ m, track a plane $C$ by recording the angles $\\alpha$ and $\\beta$ at one-second intervals.\nYour goal, back at air traffic control, is to determine the speed of the plane.%\n\\footnote{This problem is adapted from an exercise in \\cite{kiusalaas2013numerical}.}\n%\n\\begin{figure}[H]\n    \\includegraphics[width=.5\\textwidth]{figures/plane_diagram.png}\n\\end{figure}\n%\nLet the position of the plane at time $t$ be given by $(x(t),y(t))$.\nThe speed at time $t$ is the magnitude of the velocity vector, $\\|\\frac{d}{dt}(x(t),y(t))\\| = \\sqrt{x'(t)^2 + y'(t)^2}$.\nThe closed forms of the functions $x(t)$ and $y(t)$ are unknown (and may not exist at all), but we can still use numerical methods to estimate $x'(t)$ and $y'(t)$.\nFor example, at $t=3$, the second order centered difference quotient for $x'(t)$ is\n\\[\nx'(3) \\approx \\frac{x(3+h) - x(3-h)}{2h} = \\frac{1}{2}(x(4) - x(2)).\n\\]\nIn this case $h=1$ since data comes in from the radar stations at $1$ second intervals.\n\nSuccessive readings for $\\alpha$ and $\\beta$ at integer times $t=7,8,\\ldots,14$ are stored in the file \\texttt{plane.npy}.\nEach row in the array represents a different reading; the columns are the observation time $t$, the angle $\\alpha$ (in degrees), and the angle $\\beta$ (also in degrees), in that order.\nThe Cartesian coordinates of the plane can be calculated from the angles $\\alpha$ and $\\beta$ as follows.\n\\begin{equation}\n\\label{eq:differentiation-plane-conversion}\nx(\\alpha, \\beta) = a \\frac{\\tan(\\beta)}{\\tan(\\beta)-\\tan(\\alpha)}\n\\qquad\ny(\\alpha, \\beta) = a \\frac{\\tan(\\beta)\\tan(\\alpha)}{\\tan(\\beta)-\\tan(\\alpha)}\n\\end{equation}\nLoad the data, convert $\\alpha$ and $\\beta$ to radians, then compute the coordinates $x(t)$ and $y(t)$ at each given $t$ using \\ref{eq:differentiation-plane-conversion}.\nApproximate $x'(t)$ and $y'(t)$ using a forward difference quotient for $t=7$, a backward difference quotient for $t=14$, and a centered difference quotient for $t=8,9,\\ldots,13$ (see Figure \\ref{fig:difference-quotient-grid}).\nReturn the values of the speed $\\sqrt{x'(t)^2+y'(t)^2}$ at each $t$.\n\\\\(Hint: \\li{np.deg2rad()} will be helpful.)\n\\end{problem}\n\n\\subsection*{Numerical Differentiation in Higher Dimensions} % ================\n\nFinite difference quotients can also be used to approximate derivatives in higher dimensions.\nThe \\emph{Jacobian matrix} of a function $f:\\mathbb{R}^n \\rightarrow \\mathbb{R}^m$ at a point $\\x_0 \\in \\mathbb{R}^n$ is the $m \\times n$ matrix $J$ whose entries are given by\n\\begin{equation*}\nJ_{ij} = \\frac{\\partial f_i}{\\partial x_j}(\\x_0).\n\\end{equation*}\nFor example, the Jacobian for a function $f:\\mathbb{R}^3 \\rightarrow \\mathbb{R}^2$ is defined by\n\\[\nJ = \\left[\\begin{array}{c|c|c}\n\\arrayrulecolor{gray}\n\\frac{\\partial f}{\\partial x_1}&\\frac{\\partial f}{\\partial x_2}&\\frac{\\partial f}{\\partial x_3}\n\\end{array}\\right]\n=\n\\left[\\begin{array}{ccc}\n\\frac{\\partial f_1}{\\partial x_1}&\\frac{\\partial f_1}{\\partial x_2}&\\frac{\\partial f_1}{\\partial x_3}\n\\\\ \\\\\n\\frac{\\partial f_2}{\\partial x_1}&\\frac{\\partial f_2}{\\partial x_2}&\\frac{\\partial f_2}{\\partial x_3}\n\\end{array}\\right],\n\\qquad\n\\text{where}\n\\qquad\nf(\\x) =\n\\left[\\begin{array}{c}\nf_1(\\x) \\\\ f_2(\\x)\n\\end{array}\\right],\n\\quad\n\\x = \\left[\\begin{array}{c}\nx_1 \\\\ x_2 \\\\ x_3\n\\end{array}\\right].\n\\]\n\nThe difference quotients in this case resemble directional derivatives.\nThe first order forward difference quotient for approximating a partial derivative is\n\\[\n\\frac{\\partial f}{\\partial x_j}(\\x_0) \\approx \\frac{f(\\x_0 + h\\e_j) - f(\\x_0)}{h},\n\\]\nwhere $\\e_j$ is the $j$th standard basis vector.\nThe second order centered difference approximation is\n\\begin{equation}\n\\frac{\\partial f}{\\partial x_j}(\\x_0) \\approx \\frac{f(\\x_0 + h\\e_j) - f(\\x_0 - h\\e_j)}{2h}.\n\\label{eq:centered-quotient-high-dimension}\n\\end{equation}\n\n\\begin{problem}\nWrite a function that accepts a function $f:\\mathbb{R}^n\\rightarrow\\mathbb{R}^m$, a point $\\x_0 \\in \\mathbb{R}^n$, and a float $h$.\nApproximate the Jacobian matrix of $f$ at $\\x$ using the second order centered difference quotient in (\\ref{eq:centered-quotient-high-dimension}).\n\\\\(Hint: the standard basis vector $\\e_j$ is the $j$th column of the $n\\times n$ identity matrix $I$.)\n\nTo test your function, define a simple function like $f(x,y) = [x^2, x^3 - y]\\trp$ where the Jacobian is easy to find analytically, then check the results of your function against SymPy or your own scratch work.\n\\label{prob:jac_center}\n\\end{problem}\n\n\\begin{comment} % Not enough room. Needs updating if added back in.\n\\begin{problem}\nFind the error between your Jacobian function and the analytically computed derivative on the square $[-1,1] \\times [-1,1]$ using ten thousand grid points (100 per side).\nYou may apply your Jacobian function to the points one at a time using a double \\li{for} loop.  Once you get the error matrix for a given point, calculate the Frobenius norm of this matrix (\\li{la.norm()} defaults to the Frobenius norm).  This norm will be your total error for that point.\nReturn the maximum error of your Jacobian function over all points in the square.\n\nHint: The following code defines the function\n$f(x,y) = \\left[\\begin{array}{c} x^2 \\\\ x+y \\end{array}\\right]$.\n\n\\begin{lstlisting}\n# f accepts a length-2 NumPy array\n>>> f = lambda x: np.array([x[0]**2, x[0]+x[1]])\n\\end{lstlisting}\n\\end{problem}\n\\end{comment}\n\n% TODO: Introduce Google tangent as well as HIPS Autograd. Be brief.\n\n\\section*{Differentiation Software} % =========================================\n\nMany machine learning algorithms and structures, especially neural networks, rely on the gradient of a cost or objective function.\nTo facilitate their research, several organizations have recently developed Python packages for numerical differentiation.\nFor example, the Harvard Intelligent Probabilistic Systems Group (HIPS) started developing \\li{autograd} in 2014 (\\url{https://github.com/HIPS/autograd}) and Google released \\li{tangent} in 2017 (\\url{https://github.com/google/tangent}).\nThese tools are incredibly robust: they can differentiate functions with NumPy routines,\\footnote{See \\url{https://github.com/HIPS/autograd/blob/master/docs/tutorial.md} for which features Autograd supports.} \\li{if} statements, \\li{while} loops, and even recursion.\n% They are therefore beneficial for calculating derivatives of unconventional or very complex functions.\nWe conclude with a brief introduction to Autograd.\\footnote{Autograd is not included in Anaconda; install it with \\texttt{pip install autograd}.}\n\nAutograd's \\li{grad()} accepts a scalar-valued function and returns its gradient as a function that accepts the same parameters as the original.\n% The following code computes the derivative of $e^{\\sin\\left(\\cos\\left(x\\right)\\right)}$ at $x=1$ using Autograd.\nTo support most of the NumPy features, Autograd comes with its own thinly-wrapped version of Numpy, \\li{autograd.numpy}.\nImport this version of NumPy as \\li{anp} to avoid confusion.\n\n\\begin{lstlisting}\n>>> from autograd import numpy as anp       # Use autograd's version of NumPy.\n>>> from autograd import grad\n\n>>> g = lambda x: anp.exp(anp.sin(anp.cos(x)))\n>>> dg = grad(g)                            # dg() is a callable function.\n>>> dg(1.)                                  # Use floats as input, not ints.\n-1.2069777039799139\n\\end{lstlisting}\n\n\\begin{comment} % Not enough room, and not useful later.\nAutograd can differentiate a function as many times as desired.\n\n\\begin{lstlisting}\n>>> f = lambda x: anp.sin(x) + 3**anp.cos(x)\n\n# Calculate the first derivative.\n>>> df = grad(f)\n\n# Calculate the second derivative and so forth.\n>>> ddf = grad(df)\n>>> dddf = grad(ddf)\n>>> dddf(1.)\n2.683445898750351\n\\end{lstlisting}\n\\end{comment}\n\nFunctions that \\li{grad()} produces do not support array broadcasting, meaning they do not accept arrays as input.\nAutograd's \\li{elementwise_grad()} returns functions that can accept arrays, like using \\li{\"numpy\"} as an argument in SymPy's \\li{sy.lambdify()}.\n\n\\begin{lstlisting}\n>>> from autograd import elementwise_grad\n\n>>> pts = anp.array([1, 2, 3], dtype=anp.<<float>>)\n>>> dg = elementwise_grad(g)        # Calculate g'(x) with array support.\n>>> dg(pts)                         # Evaluate g'(x) at each of the points.\narray([-1.2069777 , -0.55514144, -0.03356146])\n\\end{lstlisting}\n\n% >>> g = lambda x: anp.exp(anp.sin(anp.cos(x)))\n% >>> g(pts)                          # Evaluate g(x) at an array of points.\n% array([ 1.67262669,  0.66748447,  0.43343135])\n\n\nSymPy would have no trouble differentiating $g(x)$ in these examples.\nHowever, Autograd can also differentiate Python functions that look nothing like traditional mathematical functions.\nFor example, the following code computes the Taylor series of $e^{x}$ with a loop.\n\n\\begin{lstlisting}\n>>> from sympy import factorial\n\n>>> def taylor_exp(x, tol=.0001):\n...     \"\"\"Compute the Taylor series of e^x with terms greater than tol.\"\"\"\n...     result, i, term = 0, 0, x\n...     while anp.abs(term) > tol:\n...         term = x**i / int(factorial(i))\n...         result, i = result + term, i + 1\n...     return result\n...\n>>> d_exp = grad(taylor_exp)\n>>> print(d_exp(2., .1), d_exp(2., .0001))\n7.26666666667 7.38899470899\n\\end{lstlisting}\n\n\\begin{problem} % Take the derivative of a recursive function.\nThe \\emph{Chebyshev Polynomials} satisfy the recursive relation\n\\[\nT_0(x) = 1,\\qquad T_1(x) = x,\\qquad T_n(x) = 2xT_{n-1}(x) - T_{n-2}(x).\n\\]\nWrite a function that accepts an array $x$ and an integer $n$ and recursively computes $T_n(x)$.\nUse Autograd and your first function to create a function for $T_n'(x)$.\nUse this last function to plot each $T_n'(x)$ over the domain $[-1, 1]$ for $n=0,1,2,3,4$.\n\\\\(Hint: Use \\li{anp.ones_like(x)} to handle the case when $n = 0$.)\n\\end{problem}\n\n\\begin{problem} % Compare differentiation methods.\nLet $f(x) = (\\sin(x) + 1)^{\\sin(\\cos(x))}$ as in Problems \\ref{prob:sympy-symbolic-diff} and \\ref{prob:difference-quotient-convergence}.\nWrite a function that accepts an integer $N$ and performs the following experiment $N$ times.\n\\begin{enumerate}\n\\item Choose a random value $x_0$.\n\\item Use your function from Problem \\ref{prob:sympy-symbolic-diff} to calculate the ``exact'' value of $f'(x_0)$.\nTime how long the entire process takes, including calling your function (each iteration).\n\\item Time how long it takes to get an approximation $\\tilde{f}'(x_0)$ of $f'(x_0)$ using the fourth-order centered difference quotient from Problem \\ref{prob:difference-quotient-convergence}.\nRecord the absolute error $|f'(x_0) - \\tilde{f}'(x_0)|$ of the approximation.\n\\item Time how long it takes to get an approximation $\\bar{f}'(x_0)$ of $f'(x_0)$ using Autograd (calling \\li{grad()} every time).\nRecord the absolute error $|f'(x_0) - \\bar{f}'(x_0)|$ of the approximation.\n\\end{enumerate}\n\nPlot the computation times versus the absolute errors on a log-log plot with different colors for SymPy, the difference quotient, and Autograd.\nFor SymPy, assume an absolute error of \\li{1e-18} (since only positive values can be shown on a log plot).\n\nFor $N=200$, your plot should resemble the following figure.\nNote that SymPy has the least error but the most computation time, and that the difference quotient takes the least amount of time but has the most error.\nAutograd might be considered a ``happy medium,'' a least for this problem.\n\n\\begin{figure}[H]\n    \\includegraphics[width=.7\\textwidth]{figures/efficiency.pdf}\n    \\caption{Solution with $N = 200$.}\n\\end{figure}\n\\end{problem}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{More Autograd} % -------------------------------------------------\n\nFor scalar-valued functions with multiple inputs, the parameter \\li{argnum} specifies the variable that the derivative is computed with respect to.\nProviding a list for \\li{argnum} gives several outputs.\n\n\\begin{lstlisting}\n>>> f = lambda x,y: 3*x*y + 2*y - x\n\n# Take the derivative of f with respect to the first variable, x.\n>>> dfdx = grad(f, argnum=0)            # Should be dfdx(x,y) = 3y - 1,\n>>> dfdx(5., 1.)                        # so dfdx(5,1) = 3 - 1 = 2.\n2.0\n\n# Take the gradient with respect to the second variable, y.\n>>> dfdy = grad(f, argnum=1)            # Should be dfdy(x,y) = 3x + 2,\n>>> dfdy(5., 1.)                        # so dfdy(5,1) = 15 + 2 = 17.\n17.0\n\n# Get the full gradient.\n>>> grad_f = grad(f, argnum=[0,1])\n>>> anp.array(grad_f(5., 1.))\narray([  2.,  17.])\n\\end{lstlisting}\n\nFinally, Autograd's \\li{jacobian()} can differentiate vector-valued functions.\n% The following example shows how to find the Jacobian of $f(x,y) = \\left[\\begin{array}{c} x^2 \\\\ x+y \\end{array}\\right]$.\n\n\\begin{lstlisting}\n>>> from autograd import jacobian\n\n>>> f = lambda x: anp.array([x[0]**2, x[0]+x[1]])\n>>> f_jac = jacobian(f)\n>>> f_jac(anp.array([1., 1.]))\narray([[ 2.,  0.],\n       [ 1.,  1.]])\n\\end{lstlisting}\n\n\\subsection*{Google Tangent} % ------------------------------------------------\n\nGoogle's \\li{tangent} package is similar to Autograd, both in purpose and syntax.\nHowever, Tangent differentiates code ahead of time, while Autograd waits until the last second to actually do any calculations.\nTangent also tends to be slightly faster than Autograd.\n\n\\begin{lstlisting}\n>>> import tangent              # Install with 'pip install tangent'.\n\n>>> def f(x):                   # Tangent does not support lambda functions,\n...     return x**2 - x + 3\n...\n>>> df = tangent.grad(f)\n>>> df(10)                      # ...but the functions do accept integers.\n19.0\n\\end{lstlisting}\n\n\\begin{comment} % NOT FINISHED! ...and not really necessary.\n\\subsection*{Convergence of the Centered Difference Quotient} % ---------------\n\nRecall from the proof of Taylor's theorem that $R_k = \\frac{f^{(k)}(x_0)}{k!}h^k + R_{k+1}$.\nTherefore,\n\\begin{align*}\n\\frac{R_2(-h) - R_2(h)}{2h} &= \\frac{1}{2h}\\left(\\frac{f''(x_0)}{2!}h^2 + R_{3}(-h) - \\frac{f''(x_0)}{2!}h^2 - R_{3}(h) \\right)\\\\\n&= \\frac{1}{2h} ( R_3(-h)-R_3(h))\\\\\n&= \\frac{1}{2h}\\left(  \\left( \\int_0^1 \\frac{(1-t)^2}{2} f'''(x_0+th) dt \\right) h^3  -  \\left(\\int_0^1 \\frac{(1-t)^2}{2} f'''(x_0-th) dt \\right) h^3  \\right)\\\\\n&= \\left(  \\int_0^1 \\frac{(1-t)^2}{4}( f'''(x_0+th)-f'''(x_0-th)) \\right)h^2\\\\\n&{\\in}\\hspace{0.3in}O(h^2)\n\\end{align*}\nonce $h$ is restricted to some $\\delta$-neighborhood of 0.\nSo this centered difference quotient is of the second order and its error is smaller than using the first order forward and backward difference quotients when $|h|<1$.\n\\end{comment}\n\n% =============================================================================\n% OLD IMAGE FILTER MATERIAL (might work well in Fourier 2 lab?) ===============\n% =============================================================================\n\n\\begin{comment}\n\\section*{Image Filters} % ====================================================\n\nRecall that a computer stores an image as a 2-D array of pixel values (i.e., a matrix of intensities).\nAn image filter is a function that transforms an image by operating on it locally.\nThat is, to compute the $ij$th pixel value in the new image, an image filter uses only the pixels in a small neighborhood around the $ij$th pixel in the original image.\n\nIn this lab, we will use a filter derived from the gradient of an image to find edges in an image.\n\n\\subsection*{Convolutions} % --------------------------------------------------\n\nOne example of an image filter is to \\emph{convolve} an image with a filter matrix.\nA filter matrix is a matrix whose height and width are relatively small odd numbers.\nIf the filter matrix is\n\\[\nF = \\begin{array}\nf_{-1,-1}&f_{-1,0}&f_{-1,1}\\\\\nf_{0,-1}&f_{0,0}&f_{0,1}\\\\\nf_{1,-1}&f_{1,0}&f_{1,1}\n\\end{array},\n\\]\nthen the convolution of an image $A$ with $F$ is $A \\ast F = (C_{ij})$ where\n\\begin{equation}\\label{equ:convolve}\nC_{ij} = \\sum_{k=-1}^1 \\sum_{\\ell=-1}^1 f_{k\\ell}A_{i+k,j+\\ell}.\n\\end{equation}\nSay $A$ is an $m \\times n$ matrix. Here, we take $A_{ij}=0$ when $i \\not \\in \\{1, \\ldots m\\}$ or $j \\not \\in \\{1, \\ldots, n\\}$.\nThe value of $C_{ij}$ is a linear combination of the nearby pixel values, with coefficients given by $F$ (see Figure \\ref{fig:convolution}).\nIn fact, $C_{ij}$ equals the Frobenius inner product of $F$ with the $3 \\times 3$ submatrix of $A$ centered at $ij$.\n\n\\begin{figure}\n\\centering\n\\begin{tikzpicture}\n\\node[draw, minimum width=12cm, minimum height=\n    7cm, ultra thick](outer_rec)[]{};\n\\node[draw, minimum width=10cm, minimum height=\n    5cm, ultra thick, fill=black!10!](inner_rec)[]{};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick, fill=black!30!](square1)at(-4.75,2.25){\\textbullet};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick,fill=black!30!](square2)at(-1.75,-.75){\\textbullet};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick, fill=black!30!](square3)at(4.75,.75){\\textbullet};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick, fill=black!30!](square4)at(3.25,-1.25){\\textbullet};\n\\draw[step=.5, ultra thin, color=black!50!](-6,-3.5)grid(6,3.5);\n\n\\node[draw, minimum width=10cm, minimum height=\n    5cm, ultra thick, ][]{};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick]at(-4.75,2.25){};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick]at(-1.75,-.75){};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick]at(4.75,.75){};\n\\node[draw, minimum width=2.5cm, minimum height=2.5cm,\n    ultra thick]at(3.25,-1.25){};\n\\end{tikzpicture}\n\\caption{This diagram illustrates how to convolve an image with a filter.\nThe light grey rectangle represents the original image $A$, and the dark grey squares are the filter $F$.\nThe larger rectangle is the image padded with zeros; i.e., all pixel values in the outer white band are 0.\nTo compute the entry of the convolution matrix $C$ located at a black dot, take the inner product of $F$ with the submatrix of the padded image centered at the dot.}\n\\label{fig:convolution}\n\\end{figure}\n\n\\subsubsection*{Implementation in NumPy} % - - - - - - - - - - - - - - - - - -\n\nLet us write a function that convolves an image with a filter.\nYou can test this function on the image \\li{cameraman.jpg}, which appears in Figure \\ref{fig:cameraman}.\nThe following code loads this image and plots it with matplotlib.\n\n\\begin{lstlisting}\n>>> image = plt.imread('cameraman.jpg')\n>>> plt.imshow(image, cmap = 'gray')\n>>> plt.show()\n\\end{lstlisting}\n\nHere is the function definition and some setup.\n\n\\begin{lstlisting}\n1. def Filter(image, F):\n2.     m, n = image.shape\n3.     h, k = F.shape\n\\end{lstlisting}\n\nTo convolve \\li{image} with the filter \\li{F}, we must first \\emph{pad} the array \\li{image} with zeros around the edges.\nThis is because in \\eqref{equ:convolve}, entries $A_{ij}$ are set to zero when $i$ or $j$ is out of bounds.\nWe do this by creating a larger array of zeros, and then making the interior part of the array equal to the original image (see Figure \\ref{fig:convolution}).\n\nFor example, if the filter is a $3 \\times 3$ matrix, then the following code will pad the matrix with the appropriate number of zeros.\n\n\\begin{lstlisting}\n # Create a larger matrix of zeros\nimage_pad = np.zeros((m+2, n+2))\n# Make the interior of image_pad equal to the original image\nimage_pad[1:1+m, 1:1+n] = image\n\\end{lstlisting}\n\nWe want to do this in general in our function.  Note that the number of zeros we need to pad our array depends on the size of the filter \\li{F}.\n\n\\begin{lstlisting}\n5.    image_pad = # Create an array of zeros of the appropriate size\n6.   # Make the interior of image_pad equal to image\n\\end{lstlisting}\n\nFinally, we iterate through the image to compute each entry of the convolution matrix.\n\n\\begin{lstlisting}\n7.    C = np.zeros(image.shape)\n8.    for i in range(m):\n9.        for j in range(n):\n10.            C[i,j] = # Compute C[i, j]\n\\end{lstlisting}\n\n\\subsubsection*{Gaussian Blur} % - - - - - - - - - - - - - - - - - - - - - - -\n\nA \\emph{Gaussian blur} is an image filter that operates on an image by convolving with the matrix\n\\[\nG = \\frac{1}{159}\\begin{array}\n2&4&5&4&2\\\\\n4&9&12&9&4\\\\\n5&12&15&12&5\\\\\n4&9&12&9&4\\\\\n2&4&5&4&2\n\\end{array}.\n\\]\n\nBlurring an image can remove ``noise'', or random variation that is the visual analog of static in a radio signal (and equally undesirable).\n\n\\begin{problem}\\label{prob:filter}\n\\leavevmode\nFinish writing the function \\li{Filter} by filling in lines 5, 6, and 10.  Hint: Note in \\ref{equ:convolve}, $C_{ij}$ was calculated by summing from -1 to 1.  This is only the case if the filter \\li{F} is $3 \\times 3$. A slight modification is needed in the general case.  Test your function on the image \\li{cameraman.jpg} using the Gaussian Blur. The result is in Figure \\ref{fig:cameraman_blur}.\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/cameraman.jpg}\n\\caption{Unfiltered image.}\n\\label{fig:cameraman}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/cameramanBlur.pdf}\n\\caption{Image after Gaussian blur is applied.}\n\\label{fig:cameraman_blur}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/edges.pdf}\n\\caption{Image after the Sobel filter is applied.}\n\\label{fig:cameraman_edges}\n\\end{subfigure}\n\\caption{Here is an example of a Gaussian blur and the Sobel filter applied to an image.\nThis photo, known as ``cameraman,'' is a standard test image in image processing.\nA database of such images can be downloaded from \\url{http://www.imageprocessingplace.com/root_files_V3/image_databases.htm}.}\n\\label{fig:cameraman1}\n\\end{figure}\n\n\\subsection*{Edge Detection} % ------------------------------------------------\n\nAutomatic detection of edges in an image can be used to segment or sharpen the image.\nWe will find edges with the Sobel filter, which computes the gradient of the image at each pixel.\nThe magnitude of the gradient tells us the rate of change of the pixel values, and so large magnitudes should\ncorrespond to edges within the image.\nThe Sobel filter is not a convolution, although it does use convolutions.\n\nWe can think of an image as a function from a $2 \\times 2$ grid of points to $\\mathbb{R}$.\nThe image maps a pixel location to an intensity.\nIt does not make sense to define the derivative of this function as a limit because the domain is discrete---a step size $h$ cannot take on arbitrarily small values.\nInstead, we \\emph{define} the derivative to be the centered difference quotient of the previous section.\nThat is, we define the derivative in the $x$-direction at the $ij$th pixel to be\n\\[\n\\frac{1}{2}A_{i+1, j} - \\frac{1}{2}A_{i-1, j}.\n\\]\n\nWe can use a convolution to create a matrix $A_x$ whose $ij$th entry is the derivative of $A$ at the $ij$th entry, in the $x$-direction.\nIn fact, $A_x = A \\ast S$, where\n\\[\nS = \\frac{1}{8}\n\\left[\\begin{array}{ccc}\n-1 & 0 & 1\\\\\n-2 & 0 & 2\\\\\n-1 & 0 & 1\n\\end{array}\\right].\n\\]\n\nNote that this convolution takes a weighted average of the $x$-derivatives at $(i, j)$, $(i, j+1)$, and $(i, j-1)$.\nThe derivative at $(i, j)$ is weighted by 2.\nUsing a weighted average instead of just the derivative at $(i, j)$ makes the derivative less affected by noise.\n\nNow we can define the Sobel filter.\nA Sobel filter applied to an image $A$ results in an array $B = (B_{ij})$ of 0's and 1's, where the 1's trace out the edges in the image.\nBy definition,\n\\[\nB_{ij} = \\left\\{\n     \\begin{array}{ll}\n       1 & \\text{if}\\; \\;\\|\\nabla A(ij)\\|_2 > M \\\\\n       0 & \\text{otherwise}.\n     \\end{array}\n   \\right.\n\\]\nHere, $\\nabla A(ij) = ((A \\ast S)_{ij}, (A\\ast S^T)_{ij})$ is the gradient of $A$ at the $ij$th pixel.\nThe constant $M$ should be ``sufficiently large'' enough to pick out those pixels with the largest gradient (i.e., those pixels that are part of an edge).\nA good choice for $M$ is 4 times the average value of $\\|\\nabla A(ij)\\|_2$ over the whole image $A$.\n\nWhen the Sobel filter is applied to \\li{cameraman.jpg}, we get the image in Figure \\ref{fig:cameraman_edges}.\nHere, the 1's in $B$ were mapped to ``white'' and the 0's were mapped to ``black.''\n\n\\begin{problem}\nWrite a function that accepts an image as input and applies the Sobel filter to the image.  Test your function on \\li{cameraman.jpg}.  Hint: If you want to find the average of a matrix \\li{A}, use the function \\li{A.mean()}.\n\\end{problem}\n\\end{comment}\n", "meta": {"hexsha": "7608dd8a0e603aef6462b81546fa3701d6a93eb9", "size": 35885, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume1/Differentiation/Differentiation.tex", "max_stars_repo_name": "DM561/dm561.github.io", "max_stars_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-13T13:22:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-13T13:22:41.000Z", "max_issues_repo_path": "acme-material/Labs/Volume1/Differentiation/Differentiation.tex", "max_issues_repo_name": "DM561/dm561.github.io", "max_issues_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-10-18T19:57:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-31T19:00:36.000Z", "max_forks_repo_path": "acme-material/Labs/Volume1/Differentiation/Differentiation.tex", "max_forks_repo_name": "DM561/dm561.github.io", "max_forks_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.2925824176, "max_line_length": 398, "alphanum_fraction": 0.6861084018, "num_tokens": 10966, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.914900959053549, "lm_q1q2_score": 0.8117043254827042}}
{"text": "%----------------------------------------------------------------------------------------\n% What is RBI\n%----------------------------------------------------------------------------------------\n\n\\section{What is Randomization Based Inference}\n\\subsection{Definition}\nThe general explanation goes something like this: If the data we are analyzing falls to meet our model conditions but passes the randomness assumption, we can randomly \u201cshuffle\u201d or permute our response variable (or treatment groups, or our multiple explanatory variables, etc.) $n$ times to estimate a distribution of test statistics. From this distribution, we calculate the number of test statistics that are as extreme or more extreme than our original test statistic, coming from the original model we created. This proportion is then our p-value. We can trust this p-value and use it to make a judgement on whatever to reject or fail to reject our null hypothesis.\n\\newline\\\\\nAlgorithmically, suppose we have some randomly sampled dataset, $A$, with test statistic, $S_0$. We can make $J$-many permutations of the column of responses in $A$ where these permuted matrices are $A_j^*$ with test statistic $S_j$.\n$$\n    A=\\begin{pmatrix}\n        x_{1,1} & x_{1,2} & \\cdots & y_{1} \\\\\n        x_{2,1} & x_{2,2} & \\cdots & y_{2} \\\\\n        \\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\n        x_{n,1} & x_{n,2} & \\cdots & y_{n} \n    \\end{pmatrix}\\longrightarrow\n    A_j^*=\\begin{pmatrix}\n        x_{1,1} & x_{2,2} & \\cdots & y_{i} \\\\\n        x_{2,1} & x_{2,2} & \\cdots & y_{i} \\\\\n        \\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\n        x_{n,1} & x_{n,2} & \\cdots & y_{i} \n    \\end{pmatrix} \n$$\n\\\\\nWhere our p-value is calculated as \n\n$$\n\\hat{p}=\\frac{\\sum_{j=1}^{J}I(|S_j|\\geq|S_0|)}{J} % add source from the article for this \n$$\n\\\\\n\\subsection{In Practice}\nThere is often more to this picture than just the above definition. Different kind of data require different kinds of permutation methods to perform statistical inference. Take a two-sample t-test for example.  We start with the sampling process. Let us imagine that we have two treatments, $A$ and $B$ with $n_1$ and $n_2$ randomly assigned patients, respectively. \n\\\\\n$$\n    A=\\begin{pmatrix}\n        x_{1}\\\\\n        x_{2}\\\\\n        \\vdots\\\\\n        x_{n_1}\n    \\end{pmatrix}\\quad\\quad\n    B=\\begin{pmatrix}\n        x_{n_1+1}\\\\\n        x_{n_1+2}\\\\\n        \\vdots\\\\\n        x_{n_1+n_2}\n    \\end{pmatrix} \n$$\n\\newline\\\\\nIf from here we randomly sample $n_1$ patients into $A$ without replacement and put the rest into $B$, we will have ensured that our new data is random as the treatments were randomly assigned in our initial sample. That is, under the assumption of the null hypothesis, if there was no difference in treatments $A$ and $B$, we could assign each data point from the whole study to each treatment randomly. \n\\\\\n$$\n    A^*=\\begin{pmatrix}\n        x_{k}\\\\\n        x_{k}\\\\\n        \\vdots\\\\\n        x_{k}\n    \\end{pmatrix}\\quad\\quad\n    B^*=\\begin{pmatrix}\n        x_{k}\\\\\n        x_{k}\\\\\n        \\vdots\\\\\n        x_{k}\n    \\end{pmatrix} \n$$\n\\newline\\\\\nFrom here, we don\u2019t have to check our model conditions anymore because we have committed to moving forward with randomization based inference. The next step in the process will be to calculate our test statistic from this permutation of the data. For this example with two treatments, we could calculate a difference in sample means, generating a t-statistic. Following this, we repeat the initial sampling procedure and extract a difference in means t-statistic $N$-many times. \n\\\\\n$$\n    A_n^*=\\begin{pmatrix}\n        x_{k}\\\\\n        x_{k}\\\\\n        \\vdots\\\\\n        x_{k}\n    \\end{pmatrix}\\quad\\quad\n    B_n^*=\\begin{pmatrix}\n        x_{k}\\\\\n        x_{k}\\\\\n        \\vdots\\\\\n        x_{k}\n    \\end{pmatrix} \n$$\n\\begin{center}\n    For $k\\in \\{1,2,3\\dots,n_1+n_2\\}$ for $N$-many permutations.\n\\end{center}\n\\newline\\\\\nWhen this process is done, we take our t-statistics and plot them on a dotplot. The result we get is called a randomization or reference distribution. Consequently, that distribution is centered on the null hypothesis of the given test we are conducting meaning that the reference distribution we created is also a null distribution. Using this distribution, we locate where our original test statistic calculated using $A$ and $B$ would fall on this distribution. We then count the number of new test statistics that are as or more extreme than the original one and divide that by the number of total test statistics calculated. This proportion that is yielded is our p-value. The error rate of this p-value has been maintained at the original significance level we started with as well. We can then take this p-value and use it to either reject or fail to reject the null hypothesis of the test we conducted. \n\t\n", "meta": {"hexsha": "0b9495dad8854a0322bdc7f1266b90d9a8c01b4c", "size": 4819, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project/Math%20420%20Final%20Paper/content/2-WhatisRBI.tex", "max_stars_repo_name": "jake-caldwell/Math420Proj", "max_stars_repo_head_hexsha": "460deedb53a0a18509bc412c012f33e04440e9bb", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Project/Math%20420%20Final%20Paper/content/2-WhatisRBI.tex", "max_issues_repo_name": "jake-caldwell/Math420Proj", "max_issues_repo_head_hexsha": "460deedb53a0a18509bc412c012f33e04440e9bb", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Project/Math%20420%20Final%20Paper/content/2-WhatisRBI.tex", "max_forks_repo_name": "jake-caldwell/Math420Proj", "max_forks_repo_head_hexsha": "460deedb53a0a18509bc412c012f33e04440e9bb", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.7613636364, "max_line_length": 911, "alphanum_fraction": 0.6592654078, "num_tokens": 1286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582612793112, "lm_q2_score": 0.8723473879530491, "lm_q1q2_score": 0.8116828338263428}}
{"text": "Like we introduced Lasso and Ridge regression to avoid over fitting in Project 1, we can add a penalty term to the cost function in equation \\eqref{eq:Geron_cost}.\n\n\\subsubsection{\\texorpdfstring{$L^1$}{L1} regularization}\nThe $L^1$ regularization utilizes the Taxi-cab metric, \n\\begin{align*}\n    ||\\bm{a}||_1 = |a_0| + \\dots + |a_{n-1}| = \\sum^{n-1}_{i=0}|a_i|,\n\\end{align*}\nand is defined as \n\\begin{align}\n    \\lambda||\\bm{w}||_1,\n    \\label{eq:l1-reg}\n\\end{align}\nwith $\\bm{w}$ being the weight matrix. This is equivalent with $\\beta$ as seen in the logistic regression. Its derivative is given as,\n\\begin{align}\n    \\lambda \\sign{(\\bm{w})}\n    \\label{eq:l1-reg-derivative}\n\\end{align}\nwhere $\\sign$ is simple the sign of $\\bm{w}$.\n\nFor logistic regression, this becomes in the gradient of the Geron cost function \\eqref{eq:Geron_cost},\n\\begin{align}\n    \\frac{\\partial J(\\beta)}{\\partial \\beta} &=\\frac{1}{N}\\bm{X}^T(\\bm{p}-\\bm{y})\\ + \\lambda\\cdot{\\sign(\\beta)}\n    \\label{eq:geron-cost-l1}\n\\end{align}\n\n% In our project we used two different penalties: $L^1 = \\lambda|\\beta|$ and $L^2 = \\lambda||\\beta||^2$. When fitting the model we need to include the derivatives of the penalty term in Equation \\ref{eqT:diff_cost}.} \\husk{The gradient with the penalty term is,\n% \\begin{equation}\n% \\begin{split}\n% \\frac{\\partial J(\\beta)}{\\partial \\beta} &=\\frac{1}{N}\\bm{X}^T(\\bm{p}-\\bm{y})\\ + \\lambda\\cdot{sign(\\beta)},\\ for\\ L1\\ regularization\\\\\n%  &\\mathrm{or}\\\\\n% \\frac{\\partial J(\\beta)}{\\partial \\beta} &=\\frac{1}{N}\\bm{X}^T(\\bm{p}-\\bm{y})\\ + \\lambda\\cdot{2\\beta},\\ for\\ L2\\ regularization. \n% \\end{split}\n% \\end{equation}\n% }\n\n\\subsubsection{\\texorpdfstring{$L^2$}{L2} regularization}\nThe $L^2$ regularization is given as the Euclidean norm of the weight matrix,\n\\begin{align}\n    ||\\bm{a}||_2 = \\left(\\sum^{n-1}_{i=0} a_i^2 \\right)^{1/2},\n\\end{align}\nand is given as\n\\begin{align}\n    \\lambda||\\bm{w}||^2_2,\n    \\label{eq:l2-reg}\n\\end{align}\nwith its following derivative\n\\begin{align}\n    \\lambda\\cdot{2\\bm{w}}.\n    \\label{eq:l2-reg-derivative}\n\\end{align}\nThe 2 in front is often offset by redefining the $L^2$ norm with a factor half, and will not affect the final outcome.\n\nImplementing the $L^2$ norm in the gradient of the Geron cost function\\eqref{eq:Geron_cost}, we get\n\\begin{align}\n    \\frac{\\partial J(\\beta)}{\\partial \\beta} &=\\frac{1}{N}\\bm{X}^T(\\bm{p}-\\bm{y})\\ + \\lambda\\cdot{2\\beta}\n    \\label{eq:geron-cost-l2}\n\\end{align}\n\n\\subsubsection{Elastic net regularization}\nElastic net regularization utilizes a linear combination of $L^1$ and $L^2$ regularization, and consists of adding a term\n\\begin{align}\n    \\lambda_1 ||\\bm{w}||_1 + \\lambda_2 + ||\\bm{w}||_2^2\n    \\label{eq:elastic_net}\n\\end{align}\nThe derivative of this w.r.t. $\\bm{w}$ is simply the combined derivatives of $L^1$ and $L^2$. For our purposes we will set $\\lambda_1=\\lambda_2$ in order to avoid having the hyper parameter space become too large.", "meta": {"hexsha": "5b80d14a14d6fda53f10fb17dffde24091d4bd36", "size": 2931, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/theory/regularization.tex", "max_stars_repo_name": "hmvege/FYSSTK4155-Project2", "max_stars_repo_head_hexsha": "3cf617399f99026cbcd79f8153d3196ebd86c7cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/theory/regularization.tex", "max_issues_repo_name": "hmvege/FYSSTK4155-Project2", "max_issues_repo_head_hexsha": "3cf617399f99026cbcd79f8153d3196ebd86c7cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/theory/regularization.tex", "max_forks_repo_name": "hmvege/FYSSTK4155-Project2", "max_forks_repo_head_hexsha": "3cf617399f99026cbcd79f8153d3196ebd86c7cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.0923076923, "max_line_length": 261, "alphanum_fraction": 0.6779256227, "num_tokens": 1010, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.8933094003735663, "lm_q1q2_score": 0.811676904256716}}
{"text": "\n\\subsection{Logistic distribution}\n\nThe logistic distribution has the cumulative distribution function:\n\n\\(F(x)=\\dfrac{1}{1+e^{-\\dfrac{x-\\mu }{s}}} \\)\n\n", "meta": {"hexsha": "a01fa9196bd78692114f3b4011278bf75eba211d", "size": 153, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/distributionsContinous/01-04-logistic.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/distributionsContinous/01-04-logistic.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/distributionsContinous/01-04-logistic.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.125, "max_line_length": 67, "alphanum_fraction": 0.7058823529, "num_tokens": 43, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9790357604052424, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.8115607365343727}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  For each matrix $A$, find the products $(-2)A$, $0A$, and $3A$.\n  \\begin{enumerate}\n  \\item\n    $A = \\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      2 & 1\n    \\end{mymatrix}$\n  \\item\n    $A = \\begin{mymatrix}{rr}\n      -2 & 3 \\\\\n      0 & 2\n    \\end{mymatrix}$\n  \\item\n    $A = \\begin{mymatrix}{rrr}\n      0 & 1 & 2 \\\\\n      1 & -1 & 3 \\\\\n      4 & 2 & 0\n    \\end{mymatrix}$\n  \\end{enumerate}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find scalars $x,y,z,w$ such that\n  \\begin{equation*}\n    x\\begin{mymatrix}{rr} 1 & 2 \\\\ 3 & 5\\end{mymatrix}\n    ~+~ y\\begin{mymatrix}{rr} 0 & 1 \\\\ 1 & 1\\end{mymatrix}\n    ~+~ z\\begin{mymatrix}{rr} 0 & 2 \\\\ -1 & 2\\end{mymatrix}\n    ~+~ w\\begin{mymatrix}{rr} 1 & 0 \\\\ 0 & 2\\end{mymatrix}\n    ~=~ \\begin{mymatrix}{rr} 1 & 2 \\\\ 6 & 5\\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    By definition of scalar multiplication, this is equivalent to the\n    matrix equation\n    \\begin{equation*}\n      \\begin{mymatrix}{rr} x+0y+0z+w & 2x+y+2z+0w \\\\ 3x+y-z+0w & 5x+y+2z+w\\end{mymatrix}\n      ~=~ \\begin{mymatrix}{rr} 1 & 2 \\\\ 6 & 5\\end{mymatrix}.\n    \\end{equation*}\n    By definition of equality of matrices, this is equivalent to the\n    system of four scalar equations\n    $x+0y+0z+w=1$, $2x+y+2z+0w=2$, $3x+y-z+0w=6$,\n    $5x+y+2z+w=5$. Solving the system of equations, we find $x=1$,\n    $y=2$, $z=-1$, $w=0$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Using only the properties given in\n  Propositions~\\ref{prop:properties-of-addition} and\n  {\\ref{prop:properties-scalar-multiplication}}, show that $0A=0$. Here the $0$\n  on the left is the scalar $0$ and the $0$ on the right is the zero\n  matrix of appropriate size.\n  \\begin{sol}\n    $0A=(0+0)A=0A+0A$. Now add $-(0A)$ to both sides. Then $0=0A$.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "155ce060bbf8657db9164890567cd01131daf653", "size": 1787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Matrices-ScalarMultiplication.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Matrices-ScalarMultiplication.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Matrices-ScalarMultiplication.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 28.8225806452, "max_line_length": 88, "alphanum_fraction": 0.5741466144, "num_tokens": 768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979619, "lm_q2_score": 0.8740772417253255, "lm_q1q2_score": 0.81150100877724}}
{"text": "\\section{Introduction}\nWe assume basic knowledge of commutative algebra. Let $R$ be a unital commutative ring.\n\\subsection{Algebras}\n\\dfi{Algebras}{Let $A$ be an $R$ module. We call $A$ an $R$ algebra if there is an $R$ linear map\n$$\\mu : A \\otimes_R A \\longrightarrow A.$$\nWe call $A$ associative if the following diagram commutes:\n$$\\xymatrix{A \\otimes_R A \\otimes_R A\\ar[rr]^{\\mu\\otimes id_A}\\ar[d]_{id_A \\otimes \\mu}&&A\\otimes_R A\\ar[d]^\\mu\\\\A\\otimes_R A \\ar[rr]_{\\mu}&&A.\\\\}$$\nWe call $A$ unital if there is an $R$ linear map $\\eta : R \\longrightarrow A$ such that\n$$\\xymatrix{R\\otimes_R A \\ar[rr]^{\\eta \\otimes id_A}\\ar[rrd]_\\simeq&&A \\otimes_R A\\ar[d]^\\mu&&A \\otimes_R R\\ar[ll]_{id_A \\otimes \\eta}\\ar[lld]^\\simeq\\\\&&A&&\\\\}$$ commutes. We call $A$ commutative if\n$$\\xymatrix{A \\otimes_R A \\ar[r]^\\tau\\ar[rd]_\\mu&A\\otimes_R A\\ar[d]^\\mu\\\\&A\\\\}$$commutes. Here $\\tau = \\tau_{A\\otimes A} : A \\otimes_RA \\longrightarrow A \\otimes_RA,\\ x \\otimes y \\longmapsto y \\otimes x$ is the flip isomorphism. A unital associative algebra $A$ is denoted by $(A, \\mu, \\eta)$.\n}\n\\subsubsection{Examples of algebras}\nClearly, very ring $R$ itself is an $R$ algebra. But more prominent examples are\n\\paragraph{Polynomial ring}\n", "meta": {"hexsha": "436ab70ca4522f8eb67d11e4d1af287309df2a23", "size": 1211, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "filtered_alg/intro.tex", "max_stars_repo_name": "gmuel/texlib", "max_stars_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "filtered_alg/intro.tex", "max_issues_repo_name": "gmuel/texlib", "max_issues_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "filtered_alg/intro.tex", "max_forks_repo_name": "gmuel/texlib", "max_forks_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 80.7333333333, "max_line_length": 293, "alphanum_fraction": 0.6919900908, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545304202039, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.8114791493345157}}
{"text": "\n\\subsection{Algebra on a set}\n\n\\subsubsection{Standard algebra}\n\nAn algebra, \\(\\Sigma \\), on set \\(s\\) is a set of subsets of \\(s\\) such that:\n\n\\begin{itemize}\n\\item Closed under intersection: If \\(a\\) and \\(b\\) are in \\(\\Sigma \\) then \\(a\\land b\\) must also be in \\(\\Sigma \\)\n\\item \\(\\forall ab [(a \\in \\Sigma \\land b \\in \\Sigma )\\rightarrow (a\\land b \\in \\Sigma)]\\)\n\\item Closed under union: If \\(a\\) and \\(b\\) are in \\(\\Sigma \\) then \\(a\\lor b\\) must also be in \\(\\Sigma \\).\n\\item \\(\\forall ab [(a \\in \\Sigma \\land b \\in \\Sigma )\\rightarrow (a\\lor b \\in \\Sigma)]\\)\n\\end{itemize}\n\nIf both of these are true, then the following is also true:\n\n\\begin{itemize}\n\\item Closed under complement: If \\(a\\) is in \\(\\Sigma \\) then \\(s \\backslash a\\) must also be in \\(\\Sigma \\)\n\\end{itemize}\n\nWe also require that the null set (and therefore the original set, null's complement) is part of the algebra.\n\n", "meta": {"hexsha": "2297fb9e704b5306ae4b896fa4c25a05beee0e80", "size": 897, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/setsBasic/01-04-algebra.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/setsBasic/01-04-algebra.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/setsBasic/01-04-algebra.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.0, "max_line_length": 116, "alphanum_fraction": 0.652173913, "num_tokens": 280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.948154531885212, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.8114791488452994}}
{"text": "\\section{Prove circle area using integrals in Cartesian plane}\nFrom what had been taught in a Geometry class, the area of a circle can be\ncalculated using $A=\\pi r^2$, and it is possible to be proven using different\napproaches.\n\nAs we know, circle in Cartesian plane is defined by $x^2+y^2=r^2$, where $r$\ndetermines the radius.\n\n\\begin{figure}[H]\n\t\\centering{\n\t\\begin{tikzpicture}\n\t\t\\draw[->] (-3,0) -- (3,0) node[right] {$x$};\n\t\t\\draw[->] (0,-3) -- (0,3) node[above] {$y$};\n\t\t\\draw[domain=0:6.28318,smooth,variable=\\x,blue]\n\t\tplot ({2*cos(\\x r)},{2*sin(\\x r)});\n\t\\end{tikzpicture}\n\t}\n\t\\caption{Graph of Cartesian equation $x^2+y^2=2^2$}\n\t\\label{circ}\n\\end{figure}\n\nIn this case when we solve for $y$ we can get:\n\n$$y=\\pm \\sqrt{r^2-x^2}$$\n\nApparently, it is not a valid function, so we ignore the negative part of the\nroot; we eventually find the function for a semi-circle:\n\n$$f(x)=\\sqrt{r^2-x^2}$$\n\nSo if we can integrate this semi-circle, we are able to find the area of one\ncircle by multiplying it by a factor of $2$.\n\nLet's begin with the integration of $f(x)$:\n\n$$\\int_{-r}^r f(x)dx=\\int_{-r}^r \\sqrt{r^2-x^2}dx$$\n\nBefore dealing with the bounds of the definite integral, we first cope with the\n\\textbf{antiderivative} of this function. When integrating with square roots, I\nalways think of changing the constant inside the root into one. So let's move\n$r$ out of the integral:\n\n$$\\int_{-r}^r\\sqrt{r^2-x^2}dx=r\\cdot\\int_{-r}^r\\sqrt{1-(\\frac{x}r)^2}dx$$\n\nWhen I see one minus square of a term under a radical sign, I always think of\nthe \\textbf{Pythagorean identity of trignonometric functions}. Therefore we can\ndo substitution this way:\n\n$$\n\\begin{aligned}\n\t\\frac{x}r=\\sin(t) \\\\\n\t\\therefore x=r\\sin(t) \\\\\n\t\\therefore dx=r\\cos(t)dt\n\\end{aligned}\n$$\n\nWe also need to have a formula to convert $t$ to $x$ in order to handle the\nintegral bounds, so we solve for $t$ below:\n\n\\begin{equation}\n\tt=\\arcsin(\\frac{x}r)\n\t\\label{subst-back}\n\\end{equation}\n\nSince we have the substitute for both $x$ and $dx$, we can plug them into the\noriginal integral:\n\n$$\n\\begin{aligned}\n\tr\\cdot\\int_{t_0}^{t_1}\\sqrt{1-(\\frac{x}r)^2}dx\n\t&=r\\cdot\\int_{t_0}^{t_1}\\sqrt{1-\\sin(t)^2}r\\cos(t)dt \\\\\n\t&=r^2\\int_{t_0}^{t_1}\\cos(t)^2dt\n\\end{aligned}\n$$\n\nThis time we need to eliminate the square of cosine. Since we know the\n\\textbf{double-angle identity of cosine} is $\\cos(2\\theta)=2\\cos(\\theta)^2-1$,\nwe solve for $\\cos(\\theta)^2$ and apply another substitution:\n\n$$\\cos(\\theta)^2=\\frac{\\cos(2\\theta)+1}2$$\n\n$$\n\\begin{aligned}\n\tr^2\\int_{t_0}^{t_1}\\cos(t)^2dt\n\t&=r^2\\int_{t_0}^{t_1}\\frac{\\cos(2t)+1}2dt \\\\\n\t&=\\frac{1}4r^2\\int_{t_0}^{t_1}(2\\cos(2t)+2)dt \\\\\n\t&=\\frac{1}4r^2\\left[\\sin(2t)+2t\\right]^{t_1}_{t_0} \\\\\n\\end{aligned}\n$$\n\nCongratulations! We have successfully figured out the \\textbf{antiderivative}\nof this semi-circle function. It is time to cope with the \\textbf{definite\nintegral}. Instead of making the antiderivative in terms of $x$, we can\nconvert the bound using Equation \\ref{subst-back}\n\n$$\n\\begin{aligned}\n\tt_0=\\arcsin(\\frac{-r}r)=-\\frac{\\pi}2 \\\\\n\tt_1=\\arcsin(\\frac{r}r)=\\frac{\\pi}2 \\\\\n\t\\therefore r\\cdot\\int_{-r}^{r}\\sqrt{1-(\\frac{x}r)^2}dx\n\t&=r^2\\cdot\\int_{-\\frac{\\pi}2}^{\\frac{\\pi}2}\\cos(t)^2dt \\\\\n\t&=\\frac{1}4r^2\\left[\\sin(2t)+2t\\right]^{t=\\frac{\\pi}2}\n\t_{t=-\\frac{\\pi}2} \\\\\n\t&=\\frac{1}4r^2(2\\pi) \\\\\n\t&=\\frac{1}2\\pi r^2\n\\end{aligned}\n$$\n\nWe are not finished yet since this is the formula for the area of a\nsemi-circle; if we want full circle, we shall double it. Eventually the\nformula to find the area of a circle is:\n\n$$A=2\\cdot\\frac{1}2\\pi r^2=\\pi r^2$$\n", "meta": {"hexsha": "96336b64bb03f9822df4b76f9f482fa66c272082", "size": 3555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "integrate-circle.tex", "max_stars_repo_name": "TravorLZH/mathcol-doc", "max_stars_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-17T04:58:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-17T04:58:27.000Z", "max_issues_repo_path": "integrate-circle.tex", "max_issues_repo_name": "TravorLZH/mathcol-doc", "max_issues_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "integrate-circle.tex", "max_forks_repo_name": "TravorLZH/mathcol-doc", "max_forks_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-07T07:20:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T07:20:36.000Z", "avg_line_length": 31.1842105263, "max_line_length": 79, "alphanum_fraction": 0.6773558368, "num_tokens": 1323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115783, "lm_q2_score": 0.9099070109242131, "lm_q1q2_score": 0.8114651148144465}}
{"text": "\n\\subsection{Linear dependence}\n\nA collection of vectors in a vector space are linearly dependent if there exist values for \\(\\alpha \\) (other than all being \\(0\\)) such that:\n\n\\(\\sum_i \\alpha_i v_i =0\\).\n\nIf no such values for \\(\\alpha \\) exist we say the vectors are linearly independent.\n\n\n", "meta": {"hexsha": "cf85bf1f68f0951386cc576bec21b1af02bb5558", "size": 293, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/linearAlgebra/01-03-dependence.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/linearAlgebra/01-03-dependence.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/linearAlgebra/01-03-dependence.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6363636364, "max_line_length": 142, "alphanum_fraction": 0.7235494881, "num_tokens": 74, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9615338035725358, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.8114336621129692}}
{"text": "%================================\n\\section{Homeomorphisms}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t[homeomorphisms]\n\t\\label{def: homomorphisms}\n\tLet $(X, \\mathcal T_X)$ and $(Y, \\mathcal T_Y)$ be topological spaces. A bijection $f: X \\to Y$ is called a \\textit{homeomorphism} iff\n\t\\begin{enumerate}[(i)]\n\t\t\\item $f$ is a bijection;\n\t\t\\item $f$ is continuous;\n\t\t\\item $f^{-1}$ is continuous.\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[homeomorphic]\n\t\\label{def: homomorphic}\n\tTwo topological spaces $(X, \\mathcal T_X)$ and $(Y, \\mathcal T_Y)$ are said to be \\textit{homeomorphic} or \\textit{topologically equivalent}, denoted $X \\cong Y$, iff there is an homeomorphism between them.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tTwo topological spaces are homeomorphic only if they have the same cardinality.\n\t\n\t\\begin{proof}\n\t\tLet $X$ and $Y$ be two sets with $|X| < |Y|$. There is no surjection from $A$ to $B$.\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t$|X| = |Y|$ does not imply $(X, \\mathcal T_X)$ and $(Y, \\mathcal T_Y)$ are homeomorphic, even if they are finite. For example, let $X = Y = \\{1, \\ldots, n\\}$, and let $\\mathcal T_X$ be indiscrete topology on $X$ and $\\mathcal T_Y = \\mathcal P(X)$. There is no homeomorphism between $X$ and $Y$.\n\t\n\tOn the other hand, even if $|X| = |Y| \\ge \\aleph_0$ and $\\mathcal T_X$ and $\\mathcal T_Y$ are induced by same metric, $X$ and $Y$ might not be homeomorphic. For example, if $\\mathcal T_X$ and $\\mathcal T_Y$ are both induced by standard Euclidean metric, and $X = [a, b] \\subseteq \\mathbb R$ and $Y = [c, d) \\subseteq \\mathbb R$ where $a < b$ and $c < d$. No doubt, $|X| = |Y| = \\mathfrak c$, but $X$ and $Y$ are not homeomorphic.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t$\\mathbb R^n$ and $\\mathbb R^m$ ($n < m$) are not homeomorphic, although $|\\mathbb R^n| = |\\mathbb R^m|$.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tLet $I$ be a proper interval in $\\mathbb R^n$, let $\\mathcal T$ be standard Euclidean topology on $\\mathbb R^n$ and let $\\mathcal T_I$ be a subspace topology on $I$. $I \\cong \\mathbb R^n$ iff $I$ is an open interval.\n\t\n\tBut if $\\mathcal T = \\mathcal P(\\mathbb R^n)$, then there exists bijection $f: I \\to \\mathbb R^n$, for $|I| = |\\mathbb R^n|$, and such $f$ can be bicontinuous, for any subset $A \\subseteq I$ is also open in $\\mathbb R^n$, vise versa. In this case, $I \\cong \\mathbb R^n$ whenever $I$ is a closed, half-close, half-open, or open interval respect to standard Euclidean metric.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tLet $S^n$ be an $n$-dimensional sphere with center $o \\in \\mathbb R^{n + 1}$ and radius $r \\in \\mathbb R$, i.e.,\n\t$$\n\tS^n = \\left\\{ x \\in \\mathbb R^{n + 1} : \\rho(o, x) = r \\right\\},\n\t$$\n\twhere $\\rho$ is the standard Euclidean metric on $\\mathbb R^{n+1}$. For any $x \\in S^n$, let $U = B(x, \\varepsilon) \\cap S^n$ where $0\\le \\varepsilon < \\max_{x,y \\in S^n} \\rho(x,y)$ (here $B(x, \\varepsilon) = \\{x\\}$ if $\\varepsilon = 0$), then $S^n \\setminus U \\cong \\mathbb R^{n}$.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tIndeed, $S^1 \\setminus \\{x\\} \\cong \\mathbb R$ where $x \\in S^1$. But for any interval $I \\in \\mathbb R$, $S^1 \\not \\cong I$.\n\t% todo: explain!\n\\end{example}\n%--------------------------------\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n%", "meta": {"hexsha": "d877a319294bd6ead7fe8e795b13c45067997666", "size": 3756, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/homeomorphisms.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-v0/homeomorphisms.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-v0/homeomorphisms.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8305084746, "max_line_length": 430, "alphanum_fraction": 0.5420660277, "num_tokens": 1175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476385, "lm_q2_score": 0.8902942333990421, "lm_q1q2_score": 0.8112180478557423}}
{"text": "\n\\subsection{Identity matrix and the Kronecker delta}\n\\subsubsection{The Kronecker delta}\n\nThe Kronecker delta is defined as:\n\np\\(\\delta_{ij}=0\\) where \\(i\\ne j\\)\n\n\\(\\delta_{ij}=1\\) where \\(i=j\\)\n\nWe can use this to define matrices. For example for the identity matrix:\n\n\\(I_{ij}=\\delta_{ij}\\)\n\n\\subsubsection{Identity matrix}\n\nA square matrix where every element is \\(0\\) except where \\(i=j\\). There is one for each square matrix.\n\n\\(I=\\begin{bmatrix}1& 0&...&0\\\\0 & 1&...&0\\\\...&...&...&...\\\\0&0&...&1\\end{bmatrix}\\)\n\n", "meta": {"hexsha": "2ac219e6b900586f615ba59738c0e426cc520a7d", "size": 520, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/maps/01-06-kronecker.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/maps/01-06-kronecker.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/maps/01-06-kronecker.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7619047619, "max_line_length": 103, "alphanum_fraction": 0.6557692308, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8807970732843033, "lm_q1q2_score": 0.8110288478060603}}
{"text": "\\section{Convergence in Probability}%\n\\label{sec:convergence_in_probability}\n\n\\begin{definition}[Convergence in Probability]\n    $Y_n \\convp c$ if for every $\\epsilon>0$ and $\\delta > 0,\\ \n    \\exists\\ n_0(\\epsilon, \\delta)$ such that \n    \\begin{equation*}\n        P(|Y_n - c| > \\epsilon) < \\delta,\\ \n        \\forall n > n_0(\\epsilon, \\delta)\n    \\end{equation*}\n\\end{definition}\n\n\\begin{thm}[Chebyshev Inequality]\nFor random variable, $Y$, $a>0$, and $c$,\n    \\begin{equation*}\n        P(|Y-c| \\ge a) \\le \\frac{\\E (Y-c)^2}{a^2}\n    \\end{equation*}    \n\\end{thm}\n\n\\begin{definition}[Markov Inequality]\n    If $X$ is a non-negative random variable and $a>0$ then\n    \\begin{equation*}\n        P( X \\ge a) \\le \\frac{\\E X}{a}\n    \\end{equation*}\n\\end{definition}\n\n\\begin{thm}\n    If $\\E (Y-c)^2 \\to 0$, then $Y_n \\convp c$.\n\\end{thm}\n\n\\begin{thm}\n    If $X_1, \\ldots, X_n$ iid, $\\E X_i = \\mu$, $\\Var X_i = \\sigma^2 < \\infty$, then\n    \\begin{equation*}\n        \\bar{X} \\convp \\mu\n    \\end{equation*}\n\\end{thm}\n\n\\begin{thm}\n    If $A_n \\convp a$ and $B_n \\convp b$, then\n    \\begin{enumerate}\n        \\item $A_n \\pm B_n \\convp a \\pm b$,\n        \\item $A_n \\cdot B_n \\convp a \\cdot b$.\n    \\end{enumerate}\n\\end{thm}\n\n\\begin{thm}\n    If $Y_n \\convp c$ and $f$ is continuous at $c$, then $f(Y_n) \\convp f(c)$.\n\\end{thm}\n\n\\begin{definition}\n    A sequence of estimators $\\delta_n$ of $g(\\theta)$ is \\it{consistent} if\n    \\begin{equation*}\n        \\delta_n \\convp g(\\theta)\n    \\end{equation*}\n\\end{definition}\n\n\\begin{thm}\n    If bias and variance of $\\delta_n \\to 0$ as $n \\to \\infty$, $\\delta_n$ \n    is consistent.\n\\end{thm}\n\n\\begin{definition}\n    $A_n = o_p (B_n)$ if $ \\frac{A_n}{B_n} \\convp 0$.\n\\end{definition}\n", "meta": {"hexsha": "a2cf955d2e5d2275a133848f8f9cf6fa37039eb9", "size": 1713, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "statistics/inference/src/01-convergence-in-prob.tex", "max_stars_repo_name": "jems-lee/notes", "max_stars_repo_head_hexsha": "2e121f2131c4225776d3c820ac4372968e8248d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "statistics/inference/src/01-convergence-in-prob.tex", "max_issues_repo_name": "jems-lee/notes", "max_issues_repo_head_hexsha": "2e121f2131c4225776d3c820ac4372968e8248d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "statistics/inference/src/01-convergence-in-prob.tex", "max_forks_repo_name": "jems-lee/notes", "max_forks_repo_head_hexsha": "2e121f2131c4225776d3c820ac4372968e8248d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.3538461538, "max_line_length": 83, "alphanum_fraction": 0.5925277291, "num_tokens": 657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850443, "lm_q2_score": 0.8688267762381844, "lm_q1q2_score": 0.81098968721496}}
{"text": "\\chapter{Large number laws (TO DO)}\n\\todo{write chapter}\n\\section{Notions of convergence}\n\\subsection{Almost sure convergence}\n\\begin{definition}\n\tLet $X$, $X_n$ be random variables on a probability space $\\Omega$.\n\tWe say $X_n$ \\vocab{converges almost surely} to $X$ if\n\t\\[ \\mu \\left( \\omega \\in \\Omega :\n\t\t\\lim_n X_n(\\omega) = X(\\omega) \\right) = 1. \\]\n\\end{definition}\nThis is a very strong notion of convergence:\nit says in almost every \\emph{world},\nthe values of $X_n$ converge to $X$.\nIn fact, it is almost better for me to give a \\emph{non-example}.\n\\begin{example}\n\t[Non-example of almost sure convergence]\n\tImagine an immortal skeleton archer is practicing shots,\n\tand on the $n$th shot, he scores a bulls-eye with probability\n\t$1 - \\frac 1n$\n\t(which tends to $1$ because the archer improves over time).\n\tLet $X_n \\in \\{0, 1, \\dots, 10\\}$ be the score of the $n$th shot.\n\n\tAlthough the skeleton is gradually approaching perfection,\n\tthere are \\emph{almost no worlds} in which the archer\n\tmisses only finitely many shots: that is\n\t\\[ \\mu \\left( \\omega \\in \\Omega :\n\t\t\\lim_n X_n(\\omega) = 10 \\right) = 0. \\]\n\\end{example}\n\n\\subsection{Convergence in probability}\nTherefore, for many purposes we need a weaker notion of convergence.\n\\begin{definition}\n\tLet $X$, $X_n$ be random variables on a probability space $\\Omega$.\n\tWe say $X_n$ \\vocab{converges in probability} to $X$ if\n\tif for every $\\eps > 0$ and $\\delta > 0$, we have\n\t\\[ \\mu \\left( \\omega \\in \\Omega :\n\t\t\t\\left\\lvert X_n(\\omega) - X(\\omega) \\right\\rvert < \\eps\n\t\t\\right) \\ge 1 - \\delta  \\]\n\tfor $n$ large enough (in terms of $\\eps$ and $\\delta$).\n\\end{definition}\nIn this sense, our skeleton archer does succeed:\nfor any $\\delta > 0$, if $n > \\delta\\inv$\nthen the skeleton archer does hit a bulls-eye\nin a $1-\\delta$ fraction of the worlds.\nIn general, you can think of this as saying that for any $\\delta > 0$,\nthe chance of an $\\eps$-anomaly event at the $n$th stage\neventually drops below $\\delta$.\n\n\\begin{remark}\n\tTo mask $\\delta$ from the definition,\n\tthis is sometimes written instead as:\n\tfor all $\\eps$\n\t\\[ \\lim_{n \\to \\infty} \\mu \\left( \\omega \\in \\Omega :\n\t\t\\left\\lvert X_n(\\omega) - X(\\omega) \\right\\rvert < \\eps\n\t\t\\right) = 1. \\]\n\tI suppose it doesn't make much difference,\n\tthough I personally don't like the asymmetry.\n\\end{remark}\n\n\\subsection{Convergence in law}\n\n\\section{\\problemhead}\n\\begin{problem}\n\t[Quantifier hell]\n\t\\gim\n\tIn the definition of convergence in probability\n\tsuppose we allowed $\\delta = 0$\n\t(rather than $\\delta > 0$).\n\tShow that the modified definition is\n\tequivalent to almost sure convergence.\n\t\\begin{hint}\n\t\tThis is actually trickier than it appears,\n\t\tyou cannot just push quantifiers (contrary to the name),\n\t\tbut have to focus on $\\eps = 1/m$ for $m = 1, 2, \\dots$.\n\n\t\tThe problem is saying for each $\\eps > 0$,\n\t\tif $n > N_\\eps$, we have\n\t\t$\\mu(\\omega : |X(\\omega)-X_n(\\omega)| \\le \\eps) = 1$.\n\t\tFor each $m$ there are some measure zero ``bad worlds'';\n\t\ttake the union.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tFor each positive integer $m$,\n\t\tconsider what happens when $\\eps = 1/m$.\n\t\tThen, by hypothesis, there is a threshold $N_m$\n\t\tsuch that the \\emph{anomaly set}\n\t\t\\[ A_m \\defeq \\left\\{ \\omega :\n\t\t\t|X(\\omega)-X_n(\\omega)| \\ge \\frac 1m\n\t\t\t\\text{ for some } n > N_m \\right\\} \\]\n\t\thas measure $\\mu(A_m) = 0$.\n\t\tHence, the countable union $A = \\bigcup_{m \\ge 1} A_m$ has measure zero too.\n\n\t\tSo the complement of $A$ has measure $1$.\n\t\tFor any world $\\omega \\notin A$,\n\t\twe then have \n\t\t\\[ \\lim_n \\left\\lvert X(\\omega) - X_n(\\omega) \\right\\rvert = 1 \\]\n\t\tbecause when $n > N_m$ that absolute value\n\t\tis always at most $1/m$ (as $\\omega \\notin A_m$).\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Almost sure convorgence is not topologizable]\n\tConsider the space of all random variables on $\\Omega = [0,1]$.\n\tProve that it's impossible to impose a metric on this space\n\twhich makes the following statement true:\n\t\\begin{quote}\n\t\tA sequence $X_1$, $X_2$, \\dots, of converges almost surely to $X$\n\t\tif and only if $X_i$ converge to $X$ in the metric.\n\t\\end{quote}\n\t\\begin{sol}\n\t\t\\url{https://math.stackexchange.com/a/2201906/229197}\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "0bf43f67f13964d6cf98e6db3c279457bd963bbe", "size": 4159, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/measure/large-laws.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/measure/large-laws.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/measure/large-laws.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.1652173913, "max_line_length": 78, "alphanum_fraction": 0.6847799952, "num_tokens": 1353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308128813471, "lm_q2_score": 0.8688267694452331, "lm_q1q2_score": 0.8109896776563387}}
{"text": "\n\\subsection{Introduction to unconstrained optimisation}\n\n\\subsubsection{Goals}\n\nWe want to identify either the maximum or the minimum.\n\nThere exist local minima and global minima.\n\n\\subsubsection{Optimising through limits}\n\nIf we are looking to minimise a function, and the limits are \\(\\infty \\) or \\(-\\infty \\) then we can optimise by taking large or small values.\n\nWe can examine this for each variable.\n\nThis also applies for maximising a function.\n\n\\subsubsection{Optimisation through stationary points}\n\nStationary points of a function are points where marginal changes do not have an impact on the value of the function. As a result they are either local maxima or minima.\n\n\\subsubsection{Optimisation through algorithms}\n\nIf we cannot identify stationary points easily, we can instead use algorithms to identify optima.\n\n\\subsubsection{Stationary points of strictly concave and convex functions}\n\nIf a function is strictly concave it will only have one stationary point, a local, and global, maxima.\n\nIf a function is strictly convex it will only have one stationary point, a local, and global, minima.\n\n", "meta": {"hexsha": "ce06c90cf77623a559fa1d8a34110d715e19b8a1", "size": 1113, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/optimisationUni/01-01-introduction.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/optimisationUni/01-01-introduction.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/optimisationUni/01-01-introduction.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.78125, "max_line_length": 169, "alphanum_fraction": 0.7969451932, "num_tokens": 241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475794701961, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.8109617131142166}}
{"text": "\\title{Supervised Learning (Regression)}\n\n\\subsection{Supervised Learning (Regression)}\n\nIn supervised learning, the task is to infer hidden structure from\nlabeled data, comprised of training examples $\\{(x_n, y_n)\\}$.\nRegression typically means the output $y$ takes continuous values.\n\nWe demonstrate with an example in Edward.\nAn interactive version with Jupyter notebook is available\n\\href{http://nbviewer.jupyter.org/github/blei-lab/edward/blob/master/notebooks/supervised_regression.ipynb}{here}.\n\n\\subsubsection{Data}\n\nSimulate training and test sets of $40$ data points. They comprise of\npairs of inputs $\\mathbf{x}_n\\in\\mathbb{R}^{10}$ and outputs\n$y_n\\in\\mathbb{R}$. They have a linear dependence with normally\ndistributed noise.\n\n\\begin{lstlisting}[language=Python]\ndef build_toy_dataset(N, w, noise_std=0.1):\n  D = len(w)\n  x = np.random.randn(N, D)\n  y = np.dot(x, w) + np.random.normal(0, noise_std, size=N)\n  return x, y\n\nN = 40  # number of data points\nD = 10  # number of features\n\nw_true = np.random.randn(D)\nX_train, y_train = build_toy_dataset(N, w_true)\nX_test, y_test = build_toy_dataset(N, w_true)\n\\end{lstlisting}\n\n\\subsubsection{Model}\n\nPosit the model as Bayesian linear regression \\citep{murphy2012machine}.\nIt assumes a linear relationship between the inputs\n$\\mathbf{x}\\in\\mathbb{R}^D$ and the outputs $y\\in\\mathbb{R}$.\n\nFor a set of $N$ data points $(\\mathbf{X},\\mathbf{y})=\\{(\\mathbf{x}_n, y_n)\\}$,\nthe model posits the following distributions:\n\\begin{align*}\n  p(\\mathbf{w})\n  &=\n  \\text{Normal}(\\mathbf{w} \\mid \\mathbf{0}, \\sigma_w^2\\mathbf{I}),\n  \\\\[1.5ex]\n  p(b)\n  &=\n  \\text{Normal}(b \\mid 0, \\sigma_b^2),\n  \\\\\n  p(\\mathbf{y} \\mid \\mathbf{w}, b, \\mathbf{X})\n  &=\n  \\prod_{n=1}^N\n  \\text{Normal}(y_n \\mid \\mathbf{x}_n^\\top\\mathbf{w} + b, \\sigma_y^2).\n\\end{align*}\nThe latent variables are the linear model's weights $\\mathbf{w}$ and\nintercept $b$, also known as the bias.\nAssume $\\sigma_w^2,\\sigma_b^2$ are known prior variances and $\\sigma_y^2$ is a\nknown likelihood variance. The mean of the likelihood is given by a\nlinear transformation of the inputs $\\mathbf{x}_n$.\n\nLet's build the model in Edward, fixing $\\sigma_w,\\sigma_b,\\sigma_y=1$.\n\\begin{lstlisting}[language=Python]\nfrom edward.models import Normal\n\nX = tf.placeholder(tf.float32, [N, D])\nw = Normal(loc=tf.zeros(D), scale=tf.ones(D))\nb = Normal(loc=tf.zeros(1), scale=tf.ones(1))\ny = Normal(loc=ed.dot(X, w) + b, scale=tf.ones(N))\n\\end{lstlisting}\nHere, we define a placeholder \\texttt{X}. During inference, we pass in\nthe value for this placeholder according to data.\n\n\\subsubsection{Inference}\n\nWe now turn to inferring the posterior using variational inference.\nDefine the variational model to be a fully factorized normal across\nthe weights.\n\\begin{lstlisting}[language=Python]\nqw = Normal(loc=tf.Variable(tf.random_normal([D])),\n            scale=tf.nn.softplus(tf.Variable(tf.random_normal([D]))))\nqb = Normal(loc=tf.Variable(tf.random_normal([1])),\n            scale=tf.nn.softplus(tf.Variable(tf.random_normal([1]))))\n\\end{lstlisting}\n\nRun variational inference with the Kullback-Leibler divergence, using\n$250$ iterations and $5$ latent variable samples in the algorithm.\n\\begin{lstlisting}[language=Python]\ninference = ed.KLqp({w: qw, b: qb}, data={X: X_train, y: y_train})\ninference.run(n_samples=5, n_iter=250)\n\\end{lstlisting}\nIn this case \\texttt{KLqp} defaults to minimizing the\n$\\text{KL}(q\\|p)$ divergence measure using the reparameterization\ngradient.\nFor more details on inference, see the \\href{/tutorials/klqp}{$\\text{KL}(q\\|p)$ tutorial}.\n\n\\subsubsection{Criticism}\n\nA standard evaluation for regression is to compare prediction accuracy on\nheld-out ``testing'' data. We do this by first forming the posterior predictive\ndistribution.\n\\begin{lstlisting}[language=Python]\ny_post = ed.copy(y, {w: qw, b: qb})\n# This is equivalent to\n# y_post = Normal(loc=ed.dot(X, qw) + qb, scale=tf.ones(N))\n\\end{lstlisting}\n\nWith this we can evaluate various quantities using predictions from\nthe model (posterior predictive).\n\\begin{lstlisting}[language=Python]\nprint(\"Mean squared error on test data:\")\nprint(ed.evaluate('mean_squared_error', data={X: X_test, y_post: y_test}))\n\nprint(\"Mean absolute error on test data:\")\nprint(ed.evaluate('mean_absolute_error', data={X: X_test, y_post: y_test}))\n\\end{lstlisting}\n\n\\begin{lstlisting}\n## Mean squared error on test data:\n## 0.0300492\n## Mean absolute error on test data:\n## 0.123616\n\\end{lstlisting}\n\nThe trained model makes predictions with low error\n(relative to the magnitude of the output).\n\nWe can also visualize the fit by comparing data generated with the\nprior to data generated with the posterior (on the first feature\ndimension).\n\n\\begin{lstlisting}[language=Python]\ndef visualise(X_data, y_data, w, b, n_samples=10):\n  w_samples = w.sample(n_samples)[:, 0].eval()\n  b_samples = b.sample(n_samples).eval()\n  plt.scatter(X_data[:, 0], y_data)\n  inputs = np.linspace(-8, 8, num=400)\n  for ns in range(n_samples):\n    output = inputs * w_samples[ns] + b_samples[ns]\n    plt.plot(inputs, output)\n\\end{lstlisting}\n\n\\begin{lstlisting}[language=Python]\n# Visualize samples from the prior.\nvisualise(X_train, y_train, w, b)\n\\end{lstlisting}\n\n\\includegraphics[width=450px]{/images/supervised-regression-fig0.png}\n\n\\begin{lstlisting}[language=Python]\n# Visualize samples from the posterior.\nvisualise(X_train, y_train, qw, qb)\n\\end{lstlisting}\n\n\\includegraphics[width=450px]{/images/supervised-regression-fig1.png}\n\nThe model has learned a linear relationship between the\nfirst dimension of $\\mathbf{x}\\in\\mathbb{R}^D$ and the outputs\n$y\\in\\mathbb{R}$.\n\n\\subsubsection{References}\\label{references}\n", "meta": {"hexsha": "82079b8ef41139b033597c8bfc96e7cab90ca4ea", "size": 5656, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/supervised-regression.tex", "max_stars_repo_name": "xiangze/edward", "max_stars_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-11T03:33:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-11T03:33:36.000Z", "max_issues_repo_path": "docs/tex/tutorials/supervised-regression.tex", "max_issues_repo_name": "xiangze/edward", "max_issues_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/tex/tutorials/supervised-regression.tex", "max_forks_repo_name": "xiangze/edward", "max_forks_repo_head_hexsha": "6419751d1d849c84c502e5ff3f7249b9bbc7b3aa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-12-22T08:21:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-16T02:45:04.000Z", "avg_line_length": 34.6993865031, "max_line_length": 114, "alphanum_fraction": 0.7367397454, "num_tokens": 1624, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361628580401, "lm_q2_score": 0.8887587853897073, "lm_q1q2_score": 0.8109356558473568}}
{"text": "\\chapter{Discrete-time Signals}\n\nRecall from the previous meeting that a discrete-time (DT) signal \\index{DT Signal} is modeled as a function $f: \\mathbb{Z} \\rightarrow \\mathbb{C}$. We will write these as $x[n]$, $y[n]$, etc. Note $n$ is dimensionless. These are graphically plotted as stem or \"lollipop\" plots, as demonstrated in Fig.~\\ref{fig:dtplots}.\n\nSince the domain $\\mathbb{Z}$ is usually interpreted as a time index, we will still call these {\\it time-domain} signals. In the time-domain, when the co-domain is $\\mathbb{R}$ we call these real DT signals. Unlike with CT signals there are no physical limitations requiring DT signals to be real, since in discrete hardware, a value at a given index can be a complex number, i.e. just a pair of numbers. However it is computationally advantageous to restrict ourselves to real arithmetic and such signals are often converted to or from CT signals, which do have to be real. For this reason real DT signals dominate in models.\n\n\\section{Primitive Models}\n\nAs with CT signals, we mathematically model DT signals by combining elementary/primitive functions, for example:  \n\\begin{itemize}\n\\item polynomials: $x[n] = n$, $x[n] = n^2$, etc.\n\\item transendental functions: $x[n] = e^n$, $x[n] = \\sin(n)$, $x[n] = \\cos(n)$, etc.\n\\item piecewise functions, e.g.\n\\[\nx[n] = \\left\\{  \\begin{array}{cl}\nf_1[n] & n < 0\\\\\nf_2[n] & n \\geq 0\\\\\n\\end{array}\\right.\n\\]\n\\end{itemize}\n\n\\begin{example}[Unit Step]\n  The DT counterpart of the CT step function is the \\emph{DT Unit Step}, $u[n]$:\n  \\[\n  u[n] = \\left\\{  \\begin{array}{cl}\n    0 & n < 0\\\\\n    1 & n \\geq 0\\\\\n  \\end{array}\\right.\n  \\]\n  Note, there are not continuity issues at $n=0$ as DT functions have discrete domains.\n\\end{example}\n\n\\begin{example}[Sampled Pure audio tone at \"middle C\"]\n  A \\emph{sampled} signal modeling the air pressure of a specific tone, sampled at 8kHz, might be \n  \\[\n  x[n] = \\sin\\left(2\\pi (261.6) \\tfrac{1}{8000} n\\right)\n  \\]\n  Such DT signals are commonly used in digital music generation, storage, and playback.\n\\end{example}\n\\begin{example}[Sampled Chord]\n    Similarly, the sampled chord \"G\", an additive mixture of tones at G, B, and D and might be modeled as\n    \\[\n    x(t) = \\sin\\left(2\\pi (392) \\tfrac{1}{8000} n\\right) + \\sin\\left(2\\pi (494) \\tfrac{1}{8000} n\\right) + \\sin\\left(2\\pi (293) \\tfrac{1}{8000} n\\right) \n    \\]\n    again sampled at 8kHz. This example shows we can use addition to build-up signals to approximate real signals of interest.\n\\end{example}\n\n\\section{Basic Transformations}\n\nSimilar to CT signals, we can also apply transformations to DT signals to increase their modeling flexibility.\n\n\\begin{itemize}\n\\item magnitude scaling\n\\[\nx_2[n] = a x_1[n]\n\\]\nfor $a \\in \\mathbb{R}$.\n\\item time differences\n\\[\nx_2[n] = x_1[n] - x_1[n-1]\n\\]\n\\item running sums\n\\[\nx_2[n] = \\sum\\limits_{m = -\\infty}^{n} x_1[m]\n\\]\n\\item sums\n\\[\ny[n] = \\sum\\limits_{i} x_i[n]\n\\]\nan important example we will see is the DT Fourier series.\n\\item multiplication (modulation)\n\\[\ny[n] = x_1[n] x_2[n]\n\\]\n\\item time index shift\n\\[\nx_2[n] = x_1[n+m]\n\\]\n\\begin{itemize}\n\\item if $m < 0$ it is called a {\\it delay}\n\\item if $m > 0$ it is called an {\\it advance}\n\\end{itemize}\n\n\\item time reversal\n\\[\nx_2[n] = x_1[-n]\n\\]\n\n\\item decimation\n\\[\ny[n] = x[m n]\n\\]\nfor $m \\in \\mathbb{Z}^+$.\n\\begin{itemize}\n\\item e.g. for $m=2$ only keep every other sample\n\\item e.g. for $m=3$ only keep every third sample\n\\item etc.\n\\end{itemize}\n\n\\item interpolation\n\\[\ny[n] = \\left\\{  \\begin{array}{cl}\nx\\left[ \\frac{n}{m}\\right] & n = 0\\; , \\; \\pm m, , \\; \\pm 2m \\cdots\\\\\n0 & \\mbox{else}\n\\end{array}\\right.\n\\]\nWhen $m = 2$ this inserts a zero sample between every sample of the signal.\n\\end{itemize}\n\n\\section{Characterization of Signals}\n\nThere are a few basic ways of characterizing DT signals.\n\n\\begin{definition}[Causal DT Signal]\nA DT signal is \\emph{causal} if $x[n] = 0$ $\\forall n < 0$.\n\\end{definition}\n\\begin{definition}[Anti-Causal DT Signal]\nA DT signal is \\emph{anti-causal} or acausal if $x[n] = 0$ $\\forall n \\geq 0$.\n\\end{definition}\n\nA DT signal can be written as the sum of a causal and anti-causal signal.\n\nA DT signal is periodic if $x[n] = x[n + N] \\; \\forall n$ for a fixed period $N \\in \\mathbb{Z}$.\n\nA DT signal is even if $x[n] = x[-n] \\; \\forall n$. \n\nA DT signal is odd if $x[n] = -x[-n] \\; \\forall n$.\n\nAny DT signal can be written in terms of an even and odd component\n\\[\nx[n] = x_e[n] + x_o[n] \n\\]\nwhere \n\\[\n\\begin{array}{ll}\nx_e[n] &= \\frac{1}{2}\\left\\{x[n] + x[-n]\\right\\} \\\\\n& \\\\\nx_o[n] &= \\frac{1}{2}\\left\\{x[n] - x[-n]\\right\\}\n\\end{array}\n\\]\n\nAnalogous to CT signals, the energy of a DT signal is\n\\[\nE_x = \\lim_{N\\rightarrow\\infty} \\sum\\limits_{-N}^N \\lvert x[n]\\rvert^2 \\; .\n\\]\n\nAnd the power of a DT signal is the energy averaged over an interval as that interval tends to infinity.\n\n\\[\nP_x = \\lim_{N\\rightarrow\\infty} \\frac{1}{2N+1} \\sum\\limits_{-N}^N \\lvert x[n]\\rvert^2 \\; .\n\\]\n\nDT Signals with finite, non-zero energy and zero power are called {\\it energy signals}. DT Signals with finite, non-zero power (and by implication infinite energy) are called {\\it power signals}. These categories are non-exclusive, some signals are neither energy or power signals.\n\n\\section{DT Unit Impulse Function}\n\nIn DT the unit impulse function, denoted $\\delta[n]$ is defined as\n\\[\n\\delta[n] = \\left\\{\n\\begin{array}{ll}\n  1 & n = 0\\\\\n  0 & \\text{else}\n\\end{array}\n\\right.\n\\]\nNote this definition is straightforward compared to the CT impulse as there are no continuity issues and it is not defined in terms of a distribution. It is typically draw as\n\\begin{center}\n  \\includegraphics[scale=0.5]{graphics/dtdelta.pdf}\n\\end{center}\n\nSome useful properties of the DT impulse function are:\n\n\\begin{itemize}\n\\item Energy is 1: $\\sum\\limits_{n=-\\infty}^{\\infty} \\delta[n] = 1$\n\\item Sampling: $x[n]\\delta[n-n_0] = x[n_0]\\delta[n-n_0]$\n\\item Sifting: $\\sum\\limits_{n=-\\infty}^{\\infty} x[n]\\delta[n-n_0] = x[n_0]$\n\\end{itemize}\n\nThe impulse can be defined in terms of the step:\n\\[\n\\delta[n] = u[n] - u[n-1]\n\\]\nand vice-versa\n\\[\nu[n] = \\sum\\limits_{m=-\\infty}^{n} \\delta[m]\n\\]\nor\n\\[\nu[n] = \\sum\\limits_{k=0}^{\\infty} \\delta[n-k]\n\\]\n\n\\section{DT Complex Exponential}\n\nThe DT Complex Exponential is defined in a similar fashion the the CT version, but with some important differences. The general DT complex exponential is given by the expression:\n\\[\nx[n] = Ce^{\\beta n}\n\\]\nwhere in general $C \\in \\mathbb{C}$ and $\\beta \\in \\mathbb{C}$. It is sometimes convenient (for reasons we will see later) to write this as\n\\[\nx[n] = C \\alpha^n\n\\]\nwhere $\\alpha = e^{\\beta}$ is a complex number $\\alpha = \\cos(\\beta) + j\\sin(\\beta)$.\n\nWe now examine several special cases.\n\n\\subsection{DT Complex Exponential: real case}\n\nLet $C$ and $\\alpha$ be real, then there are four intervals of interest:\n\n\\begin{itemize}\n\\item $\\alpha > 1$\n\\item $ 0 < \\alpha < 1$\n\\item $-1 < \\alpha < 0$\n\\item $\\alpha < -1$\n\\end{itemize}\n\nEach of these are shown in Fig.~\\ref{fig:dtexpreal}.\n\n\\begin{figure}[ht]    \n\\includegraphics[scale=0.5]{graphics/dtexpcase1.pdf}\n\\includegraphics[scale=0.5]{graphics/dtexpcase2.pdf}\n\\includegraphics[scale=0.5]{graphics/dtexpcase3.pdf}\n\\includegraphics[scale=0.5]{graphics/dtexpcase4.pdf}\n\\caption{ DT Complex Exponential: real case, four intervals of interest.}\n\\label{fig:dtexpreal}\n\\end{figure}\n\n\\subsection{DT Complex Exponential: sinusoidal case}\n\nLet $C = 1$. When $\\beta$ is purely imaginary, $\\beta = j\\omega_0$\n\\[\nx[n] = e^{j\\omega_0 n}\n\\]\n\nAs in CT, by Euler's identity:\n\\[\ne^{j\\omega_0 n} = \\cos(\\omega_0 n) + j\\sin(\\omega_0 n)\n\\]\nand\n\\[\n\\Re(x[n]) = \\cos(\\omega_0 n) = \\frac{1}{2}\\left( e^{j\\omega_0 n} + e^{-j\\omega_0 n} \\right)\n\\]\n\\[\n\\Im(x[n]) = \\sin(\\omega_0 n) = \\frac{1}{2j}\\left( e^{j\\omega_0 n} - e^{-j\\omega_0 n} \\right)\n\\]\n\nThe energy and power are the same as for the CT complex sinusoid: $E_x = \\infty$ and $P_x = 1$.\n\n\n\\subsection{DT Complex Exponential: sinusoidal case with phase shift}\n\nThe general DT sinusoid is\n\n\\[\nx[n] = A\\cos(\\omega_0 n + \\phi)\n\\]\n\n\\begin{itemize}\n\\item $A$ is called the amplitude\n\\item $\\phi$ is called the phase shift\n\\item $\\omega_0$ is now in radians (assuming $n$ is dimensionless)\n\\end{itemize}\n\n\\begin{center}\n\\includegraphics[scale=0.6]{graphics/dtsinusoid.pdf}\n\\end{center}\n\nFor CT sinusoids as $\\omega_0$ increases the signal oscillates faster and faster. However for DT sinusoids there is a \"fastest\" oscillation.\n\n\\[\ne^{j\\omega_0 n}\\rvert_{\\omega_0 = \\pi} = e^{j\\pi n} = (-1)^n\n\\]\n\n\\includegraphics[scale=0.5]{graphics/dtfastsin.pdf}\n\n\\subsection{Properties of DT complex sinusoid}\n\nIf we consider two frequencies: $\\omega_0$ and $\\omega_0+2\\pi$. In the first case:\n\\[\nx[n] = e^{j\\omega_0 n}\n\\]\nIn the second case:\n\\[\n\\begin{array}{ll}\nx[n] &= e^{j(\\omega_0+2\\pi) n} \\\\\n&= \\underbrace{e^{j2\\pi n}}_{\\text{always 1}}\\; e^{j\\omega_0 n} \\\\\n&= e^{j\\omega_0 n}\n\\end{array}\n\\]\n\nThus the two are the same signal. This has important implications later in the course.\n\nAnother difference between CT and DT complex sinusoids is periodicity. Recall for a DT signal to be periodic with period $N$\n\\[\nx[n] = x[n+N] \\; \\forall n\n\\]\nSubstituting the complex sinusoid\n\\[\ne^{j\\omega_0 n} = e^{j\\omega_0 (n+N)} = e^{j\\omega_0 n}e^{j\\omega_0 N}\n\\]\nrequires $e^{j\\omega_0 N} = 1$, which implies $\\omega_0 N$ is a multiple of $2\\pi$:\n\\[\n\\omega_0 N = 2\\pi m \\;\\;\\; m = \\pm 1, \\pm 2, \\cdots\n\\]\nor equivalently\n\\[\n\\frac{|\\omega_0|}{2\\pi} = \\frac{m}{N}\n\\]\nthus $\\omega_0$ must be a rational multiple of $\\pi$. \n\nTwo DT complex sinusoids are harmonics of one another is both are periodic in $N$,  i.e when\n\n\\[\nx_k(t) = e^{jk\\frac{2\\pi}{N} n} \\; \\text{for} \\; k = 0, \\pm 1, \\pm 2, \\cdots\n\\]\n\nThis implies there are only $N$ distinct harmonics in DT.\n\n\n\\subsection{DT Complex Exponential: general case}\n\nIn the general case we get a sinusoid signal modulated by an exponential. Let $C = Ae^{j\\phi}$ and $\\beta = r + j\\omega_0$, then\n\\[\nx[n] = C e^{\\beta n} =  Ae^{j\\phi} e^{(r+j\\omega_0)n}\n\\]\nExpanding the terms and using Euler's identity gives:\n\n\\[\nx[n] = \\underbrace{Ae^{rn}\\cos(\\omega_0 n+\\phi)}_{\\Re \\text{part}} + j \\underbrace{Ae^{rn}\\sin(\\omega_0 n+\\phi)}_{\\Im \\text{part}}\n\\]\nEach part is a real sinusoid whose amplitude is modulated by a real exponential.\n\nThe visualization of the general case is to view the signal $x[n]$ as a vector rotating through fixed angles in the complex plane.\n\n\\begin{center}\n\\includegraphics[scale=0.7]{graphics/DT_complexsinusoid_visual}\n\\end{center}\n", "meta": {"hexsha": "3c11764f147650a37d3c1cb67e147060806d0faf", "size": 10448, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03-dt-signals.tex", "max_stars_repo_name": "clwyatt/notes-2714", "max_stars_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "03-dt-signals.tex", "max_issues_repo_name": "clwyatt/notes-2714", "max_issues_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "03-dt-signals.tex", "max_forks_repo_name": "clwyatt/notes-2714", "max_forks_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.9112426036, "max_line_length": 626, "alphanum_fraction": 0.6779287902, "num_tokens": 3555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254318, "lm_q2_score": 0.9173026635420488, "lm_q1q2_score": 0.8109315766114458}}
{"text": "\\subsubsection{Higher Order Variation of Parameters}\r\n\\noindent\r\nWe are trying to find a solution to the nth order linear ODE\r\n\\begin{equation*}\r\n\ta_n(x)y^{(n)} + \\ldots + a_0(x)y = g(x)\r\n\\end{equation*}\r\nassuming that we already know the fundamental solutions for the corresponding homogeneous equation\r\n\\begin{equation*}\r\n\ty_h = C_1y_1 + \\ldots + C_ny_n.\r\n\\end{equation*}\r\n\r\n\\noindent\r\nFor this method, we'll assume that $y$ can be written as\r\n\\begin{equation*}\r\n\ty = v_1(x)y_1 + \\ldots + v_n(x)y_n\r\n\\end{equation*}\r\nand we'll try to find $v_1, \\ldots, v_n$.\\\\\r\n\r\n\\noindent\r\nSince there are $n$ unknown functions, we'll need $n$ equations to find them all.\r\nWe can generate these by differentiating $y_p$.\r\n\\begin{equation*}\r\n\ty' = \\left(v_1y_1' + \\ldots + v_ny_n'\\right) + \\left(v_1'y_1 + \\ldots + v_n'y_n\\right)\r\n\\end{equation*}\r\nto avoid second derivatives of $v_1, \\ldots, v_n$ from entering the formula for $y''$, we also have the condition\r\n\\begin{equation*}\r\n\tv_1'y_1 + \\ldots +v_n'y_n = 0.\r\n\\end{equation*}\r\nWe can now continue differentiating to get $n-2$ more equations involving $v_1', \\ldots, v_n'$.\r\nWe also impose a final $n^{\\text{th}}$ condition that\r\n\\begin{equation*}\r\n\tv_1'y^{(n-1)} + \\ldots + v_n'y_n^{(n-1)} = g.\r\n\\end{equation*}\r\nThis gets us a system of $n$ equations,\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\tv_1'y_1 + \\ldots + v_n' y_n & = 0 \\\\\r\n\t\t\\vdots & \\vdots \\\\\r\n\t\tv_1'y_1^{(n-2)} + \\ldots + v_n'y_n^{(n-2)} & = 0 \\\\\r\n\t\tv_1'y_1^{(n-1)} + \\ldots + v_n'y_n^{(n-1)} & = g\r\n\t\\end{cases} .\r\n\\end{equation*}\r\nHopefully this system looks familiar from second order equations.\\\\\r\n\r\n\\noindent\r\nWe can rewrite this system in terms of matrices and vectors.\r\n\\begin{equation*}\r\n\t\\begin{bmatrix}\r\n\t\ty_1 & \\ldots & y_n \\\\\r\n\t\t\\vdots & & \\vdots\\\\\r\n\t\ty_1^{(n-2)} & \\ldots & y_n^{(n-2)} \\\\\r\n\t\ty_1^{(n-1)} & \\ldots & y_n^{(n-1)}\r\n\t\\end{bmatrix} \\begin{bmatrix}\r\n\t\tv_1' \\\\\r\n\t\t\\vdots \\\\\r\n\t\tv_{n-1}' \\\\\r\n\t\tv_n'\r\n\t\\end{bmatrix} = \\begin{bmatrix}\r\n\t\t0 \\\\\r\n\t\t\\vdots \\\\\r\n\t\t0 \\\\\r\n\t\tg\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nIt's sufficient to show that a solution to this system exists if the determinant of the square matrix on the left is non-zero. The determinant of this matrix actually has a special name.\r\n\r\n\\begin{definition}\r\n\tThe Wronskian of $n$ $n-1$ times differentiable functions $\\left\\{f_1, \\ldots, f_n\\right\\}$ on an interval $I$ is\r\n\t\\begin{equation*}\r\n\t\tW[f_1, \\ldots, f_n](x) = \\begin{vmatrix}\r\n\t\t\tf_1(x) & \\ldots & f_n(x) \\\\\r\n\t\t\tf_1'(x) & \\ldots & f_n'(x) \\\\\r\n\t\t\t\\vdots &        & \\vdots \\\\\r\n\t\t\tf_1^{(n-1)}(x) & \\ldots & f_n^{(n-1)}(x)\r\n\t\t\\end{vmatrix} \\text{, } x \\in I.\r\n\t\\end{equation*}\r\n\\end{definition} \r\n\r\n\\noindent\r\nUsing the Wronskian, we can solve the system using Cramer's Rule.\r\n\\begin{equation*}\r\n\tv'_i(x) = \\frac{g(x)W_i(x)}{W[y_1, \\ldots, y_n](x)} \\text{, } i = 1, \\ldots, n,\r\n\\end{equation*}\r\nwhere $W_i(x)$ is the determinant of the matrix obtained from the Wronskian $W(x)$ by replacing the $i^{\\text{th}}$ column with $\\text{col}[0, \\ldots, 1]$. Using the cofactor expansion along this column, we can write $W_i(x)$ as\r\n\\begin{equation*}\r\n\tW_i(x) = (-1)^{n-i}W[y_1, \\ldots, y_{i-1}, y_{i+1}, \\ldots, y_n](x) \\text{, } i = 1, \\ldots, n.\r\n\\end{equation*}\r\nNow with a solution for $v_i'$, we can integrate to get $v_i$.\r\n\\begin{equation*}\r\n\tv_i = \\int{\\frac{g(x)W_i(x)}{W[y_1, \\ldots, y_n](x)} \\mathrm{d}x}.\r\n\\end{equation*}\r\nNow with a solution for $v_i$, we can substitute back to find $y(x)$.\r\n\\begin{equation*}\r\n\ty(x) = \\sum_{i=1}^{n}{y_i(x)\\int{\\frac{g(x)W_i(x)}{W[y_1, \\ldots, y_n](x)} \\mathrm{d}x}}\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tFind the general solution to the equation\r\n\t\\begin{equation*}\r\n\t\tx^3y''' + x^2y'' - 2xy' = x^3\\sin{x} \\text{, } x > 0\r\n\t\\end{equation*}\r\n\tgiven that $\\left\\{x, x^{-1}, x^2\\right\\}$ is the set of fundamental solutions.\r\n\\end{example}\r\n\\noindent\r\nFirst we divide by $x^3$ to get a leading coefficient of 1.\r\n\\begin{equation*}\r\n\ty''' + x^{-1}y''' - 2x^{-2}y' = \\sin{x} \\text{, } x > 0.\r\n\\end{equation*}\r\nNext we calculate the $W(x)$ and each $W_i(x)$ for the fundamental solution set.\r\n\\begin{align*}\r\n\tW[x,x^{-1}, x^2](x) &= \\begin{vmatrix}\r\n\t\tx & x^{-1} & x^2 \\\\\r\n\t\t1 & -x^{-2} & 2x \\\\\r\n\t\t0 & 2x^{-3} & 2\r\n\t\\end{vmatrix} = 6x^{-1} \\\\\r\n\tW_1(x) &= (-1)^{3-1}W[x^{-1}, x^2](x) = (-1)^{2}\\begin{vmatrix}\r\n\t\tx^{-1} & x^2 \\\\\r\n\t\t-x^{-2} & 2x\r\n\t\\end{vmatrix} = 3 \\\\\r\n\tW_2(x) &= (-1)^{3-2}\\begin{vmatrix}\r\n\t\tx & x^{2} \\\\\r\n\t\t1 & 2x\r\n\t\\end{vmatrix} = -x^2 \\\\\r\n\tW_2(x) &= (-1)^{3-2}\\begin{vmatrix}\r\n\t\tx & x^{-1} \\\\\r\n\t\t1 & -x^{-2}\r\n\t\\end{vmatrix} = -2x^{-1}.\r\n\\end{align*}\r\nNow we can calculate $y$.\r\n\\begin{align*}\r\n\ty(x) &= x\\int{\\frac{(\\sin{x})^3}{-6x^{-1}} \\mathrm{d}x} + x^{-1}\\int{\\frac{(\\sin{x})(-x^2)}{-6x^{-1}} \\mathrm{d}x} + x^2\\int{\\frac{(\\sin{x})(-2x^{-1})}{-6x^{-1}} \\mathrm{d}x} \\\\\r\n\t&= x\\int{\\left(\\frac{-1}{2}x\\sin{x}\\right)\\mathrm{d}x} + x^{-1}\\int{\\left(\\frac{1}{6}x^3\\sin{x}\\right)\\mathrm{d}x} + x^2\\int{\\left(\\frac{1}{3}\\sin{x}\\right)\\mathrm{d}x} \\\\\r\n\t&= C_1x + c_2x^{-1} + C_3x^2 + \\cos{x} - x^{-1}\\sin{x}\r\n\\end{align*}", "meta": {"hexsha": "e2e2e674979f898cfc7bc8901b7760218c040443", "size": 5002, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/nonHomeg/variationParameters_higherOrder.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/higherOrder/nonHomeg/variationParameters_higherOrder.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/higherOrder/nonHomeg/variationParameters_higherOrder.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.328358209, "max_line_length": 229, "alphanum_fraction": 0.5931627349, "num_tokens": 2073, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.8840392710530071, "lm_q1q2_score": 0.810931570517945}}
{"text": "\\subsection{Limit \\& Continuity Definitions}\r\n\\noindent\r\nFinally, we have the proper tools to define a limit in higher dimensions.\r\nWe say that $\\lim_{p\\to p_0}{f(p)} = L$ if for all $N(L, \\epsilon)$, there exists $N(p_0,\\delta)$ such that $p \\in N(p_0, \\delta) \\implies f(p) \\in N(L, \\epsilon)$.\r\nThat is, the limit of $f(p)$ as $p$ approaches $p_0$ is equal to $L$ if for all open delta neighborhoods around $L$, there exists an open delta neighborhood around $p_0$ such that $p$ being in the neighborhood around $p_0$ means $f(p)$ must be in the neighborhood around $L$.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.5\\textwidth]{./Images/differentialMultivariableCalculus/limit.png}\r\n\t\\caption{Limit definition}\r\n\\end{figure}\r\n\r\n\\noindent\r\nNow with a limit definition, we can define continuity at a point.\r\nWe say that a function $f : \\mathbb{R}^n \\to \\mathbb{R}$ is continuous at $p_0$ if $\\lim_{p \\to p_0}{f(p)} = f(p_0)$.\\\\\r\n\r\n\\noindent\r\n\\begin{theorem}\r\n\tTrigonometric functions, exponentials, logarithms, and sums, products, quotients, and compositions of such functions are continuous on their domain.\r\n\\end{theorem}\r\n\r\n\\noindent\r\nAlthough our definitions allow us to confirm that a value is the limit of a function, they do not give us any insight into how to find the value of the limit.\r\nWe'd need to approach our point of interest from every possible direction to see if the limit from that direction is the same as all the others.\r\nIf any two directions give different limit values, then the limit doesn't exist.\r\nWe approach a function, $f$, by composing it with a single variable path, $\\vec{r}(t)$, that goes through the point of interest, and find the limit along the path.\\\\\r\n\r\n\\noindent\r\nIf $f$ is some surface $f(x, y)$ and $\\vec{r}(t) = \\langle x(t), y(t)\\rangle$, then the composition of $f$ and $\\vec{r}$ is $f\\circ\\vec{r} = f(\\vec{r}(t)) = f(x(t), y(t))$.\\\\\r\nFor example, let's try to find\r\n\\begin{equation*}\r\n\t\\lim_{(x,y) \\to (0,0)}{\\frac{x^2-y^3}{x^2+y^2}}.\r\n\\end{equation*}\r\n\\indent\r\nWe'll choose two paths $\\vec{r_1}(t) = \\langle t, 0 \\rangle$ and $\\vec{r_2}(t) = \\langle t, t \\rangle$ and find the limit as $t \\to 0$ in both cases.\\\\\r\n\\indent\r\n\\begin{equation*}\r\n\t\\lim_{t \\to 0}{f(\\vec{r_1}(t))} = \\lim_{t \\to 0}{\\frac{t^2}{t^2}} = 1\r\n\\end{equation*}\r\n\\indent\r\n\\begin{equation*}\r\n\t\\lim_{t \\to 0}{f(\\vec{r_2}(t))} = \\lim{t \\to 0}{\\frac{t^2-t^3}{2t^2}} = \\lim_{t \\to 0}{\\frac{1}{2} - \\frac{t}{2}} = \\frac{1}{2}\r\n\\end{equation*}\r\n\\indent\r\nSince the limits on the two paths are not equal, we can say that\r\n\\begin{equation*}\r\n\t\\lim_{(x,y) \\to (0,0)}{\\frac{x^2-y^3}{x^2+y^2}} = \\text{ DNE}.\r\n\\end{equation*}", "meta": {"hexsha": "38adda271a4137a9539a83c49d6c38f25599efeb", "size": 2647, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/limitContinuityDefinitions.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/limitContinuityDefinitions.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/limitContinuityDefinitions.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.1458333333, "max_line_length": 276, "alphanum_fraction": 0.674726105, "num_tokens": 900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.8109130020001533}}
{"text": "\\section{Rayleigh quotient method}\n\\label{sec:ray}\nRayleigh's method can be extended to find the approximate value of the fundamental\nnatural frequency of a discrete system.\nIt is possible derive an expression for the approximate value of the first\nnatural frequency of a multi degree-of-freedom system according to Rayleigh's\nmethod.\nThe kinetic and potential energies of an \\(n\\)-degree-of-freedom discrete system\ncan be expressed as:\n\\begin{align}\\label{eq:energyequation}\n  T &= \\frac{1}{2}\\dot{\\vec{v}}^{\\top}[\\mathbf{M}]\\dot{\\vec{v}}\\\\[1em]\n  V &= \\frac{1}{2}\\vec{v}^{\\top}[\\mathbf{K}]\\vec{v}\n\\end{align}\nTo find the natural frequencies, we assume harmonic motion to be\n\\(\\vec{x} = \\vec{\\mathbf{X}} \\cos(\\omega t)\\), where \\(\\vec{\\mathbf{X}}\\) \ndenotes the vector of amplitudes and \\(\\omega\\) represents the natural frequency\nof vibration.\nIf the system is conservative, the maximum kinetic energy is equal to the\nmaximum potential energy. By equating \\(T\\) and \\(V\\) obtain:\n\\begin{equation}\\label{eq:quotient}\n  \\omega^2 = \\frac{\\vec{v}^{\\top}[\\mathbf{K}]\\vec{v}}\n  {\\vec{v}^{\\top}[\\mathbf{M}]\\vec{v}}\n\\end{equation}\n%\nThe right-hand side of \\eqref{eq:quotient} is known as \\emph{Rayleigh's quotient}\nand is denoted as \\(R(\\vec{U})\\).\n% then the Rayleigh's quotient can be expressed\n%as:\n%\\begin{align}\n%  \\omega^{2} =& R(\\vec{X}) =\n%  \\frac{\n%          c_{1}^{2}\\,\\omega_{2}^{2}\\,\\dot{\\vec{x}}^{\\top}\\,[\\mathbf{M}]\\,\\dot{\\vec{x}} +\n%          c_{2}^{2}\\,\\omega_{2}^{2}\\,\\dot{\\vec{x}}^{\\top}\\,[\\mathbf{M}]\\,\\dot{\\vec{x}} +\n%          \\dots}\n%       {\n%          c_{1}^{2}\\,\\dot{\\vec{x}}^{\\top}\\,[\\mathbf{M}]\\,\\dot{\\vec{x}} +\n%          c_{2}^{2}\\,\\dot{\\vec{x}}^{\\top}\\,[\\mathbf{M}]\\,\\dot{\\vec{x}} + \\dots\n%        }\\\\[1.5em]\n%      &  R(\\vec{X}) =\n%      \\frac{c_{1}^{2}\\,\\omega_{2}^{2} + c_{2}^{2}\\,\\omega_{2}^{2} + \\dots}\n%           {c_{1}^{2} + c_{2}^{2} + \\dots}\n%\\end{align}\nThe results obtained with regard to the natural frequencies are as follows:\n\\(\\omega_{1} = 8.27843\\) [\\si{\\radian\\per\\second}],\n\\(\\omega_{2} = 27.40935\\) [\\si{\\radian\\per\\second}],\n\\(\\omega_{3} = 41.87035\\) [\\si{\\radian\\per\\second}].\nThus values obtained for the mode shapes are:\n\\begin{equation}\n  \\label{eq:raymodefree}\n  [\\mathbf{U}] = \\begin{bmatrix*}[r]\n\t1.00000 & 1.00000 & 1.00000 \\\\\n\t0.86540 &-0.47555 &-2.44325 \\\\\n\t0.61945 &-1.28034 & 2.15533 \\\\\n  \\end{bmatrix*}\n\\end{equation}\nThe results obtained for the proportionally damped system are the natural \nfrequencies:\n\\(\\omega_{1} =  8.27799\\) [\\si{\\radian\\per\\second}],\n\\(\\omega_{2} = 27.40863\\) [\\si{\\radian\\per\\second}],\n\\(\\omega_{3} = 41.91576\\) [\\si{\\radian\\per\\second}].\nSo the values obtained for the mode shapes are:\n\\begin{equation}\\label{eq:raymodeprop}\n  [\\mathbf{U}] = \n\t\\begin{bmatrix*}[r]\n  \t\t1.00000 & 1.00000 & 1.00000 \\\\\n\t\t0.86499 &-0.48006 &-2.46147 \\\\\n\t\t0.61907 &-1.28528 & 2.16954 \\\\\n\t\\end{bmatrix*}\n\\end{equation}\nRayleigh's quotient has a stationary value in the neighbourhood of an eigenvector. \nThe stationary value is actually a minimum value in the neighbourhood of the \nfundamental mode.\nWhich means that Rayleigh s quotient is never higher than the highest eigenvalue. \nThus Rayleigh's quotient provides an upper bound for \\(\\omega_{1}^{2}\\) lower bound \nfor \\(\\omega_{n}^{2}\\).\n", "meta": {"hexsha": "1a0f5bca4e3cb2bb5c7e34a14fc3043dbdc79a2b", "size": 3253, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/rayleigh.tex", "max_stars_repo_name": "frank1789/MechanicalVibrationProject", "max_stars_repo_head_hexsha": "ad28e4c047fe4f806fa1fb5405b2304699e377be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-28T12:59:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-28T12:59:41.000Z", "max_issues_repo_path": "Report/rayleigh.tex", "max_issues_repo_name": "frank1789/MechanicalVibrationProject", "max_issues_repo_head_hexsha": "ad28e4c047fe4f806fa1fb5405b2304699e377be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/rayleigh.tex", "max_forks_repo_name": "frank1789/MechanicalVibrationProject", "max_forks_repo_head_hexsha": "ad28e4c047fe4f806fa1fb5405b2304699e377be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.8026315789, "max_line_length": 89, "alphanum_fraction": 0.6421764525, "num_tokens": 1159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.9032941995446778, "lm_q1q2_score": 0.8108829429021849}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} Let $V$ and $W$ be subspaces of $\\R^{n}$ and $\\R^{m}$\nrespectively and let $T:V\\rightarrow W$ be a linear transformation. Suppose\nthat $\\set{T\\vect{v}_{1},\\ldots,T\\vect{v}_{r}} $ is linearly\nindependent. Show that it must be the case that $\\set{\\vect{v}_{1},\\ldots,\n\\vect{v}_{r}} $ is also linearly independent.\n\\begin{sol}\nIf $\\sum_i^r a_i \\vect{v}_r =0$, then using linearity properties of $T$ we get\n\\[ 0 = T(0) =  T(\\sum_i^r a_i \\vect{v}_r) =\n\\sum_i^r a_i T(\\vect{v}_r).\\]\nSince we assume that  $\\set{T\\vect{v}_{1},\\ldots,T\\vect{v}_{r}} $ is linearly\nindependent, we must have all $a_i=0$, and therefore we conclude that\n $\\set{\\vect{v}_{1},\\ldots,\n\\vect{v}_{r}} $ is also linearly independent.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Let\n\\begin{equation*}\nV=\\mbox{span}\\set{\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n2 \\\\\n0\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} }\n\\end{equation*}\nLet $T\\vect{x}=A\\vect{x}$ where $A$ is the matrix\n\\begin{equation*}\n\\begin{mymatrix}{cccc}\n1 & 1 & 1 & 1 \\\\\n0 & 1 & 1 & 0 \\\\\n0 & 1 & 2 & 1 \\\\\n1 & 1 & 1 & 2\n\\end{mymatrix}\n\\end{equation*}\nGive a basis for $\\func{im}(T)$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Let\n\\begin{equation*}\nV=\\mbox{span}\\set{\\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n1 \\\\\n4 \\\\\n4 \\\\\n1\n\\end{mymatrix} }\n\\end{equation*}\nLet $T\\vect{x}=A\\vect{x}$ where $A$ is the matrix\n\\begin{equation*}\n\\begin{mymatrix}{cccc}\n1 & 1 & 1 & 1 \\\\\n0 & 1 & 1 & 0 \\\\\n0 & 1 & 2 & 1 \\\\\n1 & 1 & 1 & 2\n\\end{mymatrix}\n\\end{equation*}\nFind a basis for $\\func{im}(T)$. In this case, the original\nvectors do not form an independent set.\n\n\\begin{sol}\nSince the third vector is a linear combinations of the first two, then\nthe image of the third vector will also be a linear combinations of\nthe image of the first two.  However the image of the first two\nvectors are linearly independent (check!), and hence form a basis of\nthe image.\n\nThus a basis for $\\func{im}(T) $ is:\n\n\\begin{equation*}\nV=\\mbox{span}\\set{\\begin{mymatrix}{c}\n2 \\\\\n0 \\\\\n1 \\\\\n3\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n4 \\\\\n2 \\\\\n4 \\\\\n5\n\\end{mymatrix}  }\n\\end{equation*}\n\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} If $\\set{\\vect{v}_{1},\\ldots,\\vect{v}_{r}} $ is linearly\nindependent and $T$ is a one to one linear transformation, show that $\n\\set{T\\vect{v}_{1},\\ldots,T\\vect{v}_{r}} $ is also linearly\nindependent. Give an example which shows that if $T$ is only linear, it can\nhappen that, although $\\set{\\vect{v}_{1},\\ldots,\\vect{v}_{r}} $ is\nlinearly independent, $\\set{T\\vect{v}_{1},\\ldots,T\\vect{v}_{r}} $\nis not. In fact, show that it can happen that each of the $T\\vect{v}_{j}$\nequals 0.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Let $V$ and $W$ be subspaces of $\\R^{n}$ and $\\R^{m}$\nrespectively and let $T:V\\rightarrow W$ be a linear transformation. Show\nthat if $T$ is onto $W$ and if $\\set{\\vect{v}_{1},\\ldots,\\vect{v}\n_{r}} $ is a basis for $V$, then $\\sspan\\set{T\\vect{v}\n_{1},\\ldots,T\\vect{v}_{r}} =W$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Define $T:\\R^{4}\\rightarrow \\R^{3}$ as follows.\n\\begin{equation*}\nT\\vect{x}=\\begin{mymatrix}{rrrr}\n3 & 2 & 1 & 8 \\\\\n2 & 2 & -2 & 6 \\\\\n1 & 1 & -1 & 3\n\\end{mymatrix} \\vect{x}\n\\end{equation*}\nFind a basis for $\\func{im}(T)$. Also find a basis for $\\ker\n(T)$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Define $T:\\R^{3}\\rightarrow \\R^{3}$ as follows.\n\\begin{equation*}\nT\\vect{x}=\\begin{mymatrix}{ccc}\n1 & 2 & 0 \\\\\n1 & 1 & 1 \\\\\n0 & 1 & 1\n\\end{mymatrix} \\vect{x}\n\\end{equation*}\nwhere on the right, it is just matrix multiplication of the vector $\\vect{x}$\nwhich is meant. Explain why $T$ is an isomorphism of $\\R^{3}$ to $\n\\R^{3}$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $T:\\R^{3}\\rightarrow \\R^{3}$ is a linear\ntransformation given by\n\\begin{equation*}\nT\\vect{x}=A\\vect{x}\n\\end{equation*}\nwhere $A$ is a $3\\times 3$-matrix. Show that $T$ is an isomorphism if and\nonly if $A$ is invertible.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $T:\\R^{n}\\rightarrow \\R^{m}$ is a linear\ntransformation given by\n\\begin{equation*}\nT\\vect{x}=A\\vect{x}\n\\end{equation*}\nwhere $A$ is an $m\\times n$-matrix. Show that $T$ is never an isomorphism if\n$m\\neq n$. In particular, show that if $m>n$, $T$ cannot be onto and if $\nm<n, $ then $T$ cannot be one to one.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Define $T:\\R^{2}\\rightarrow \\R^{3}$ as follows.\n\\begin{equation*}\nT\\vect{x}=\\begin{mymatrix}{cc}\n1 & 0 \\\\\n1 & 1 \\\\\n0 & 1\n\\end{mymatrix} \\vect{x}\n\\end{equation*}\nwhere on the right, it is just matrix multiplication of the vector $\\vect{x}$\nwhich is meant. Show that $T$ is one to one. Next let $W=\\func{im}(T)$. Show that $T$ is an isomorphism of $\\R^{2}$ and $\\func{im}(T)$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} In the above problem, find a $2\\times 3$-matrix $A$ such that the\nrestriction of $A$ to $\\func{im}(T) $ gives the same result as $\nT^{-1}$ on $\\func{im}(T)$. \\textbf{Hint:\\ }You might let $A$ be\nsuch that\n\\begin{equation*}\nA\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} =\\begin{mymatrix}{c}\n1 \\\\\n0\n\\end{mymatrix} ,\\ A\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{c}\n0 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nnow find another vector $\\vect{v}\\in \\R^{3}$ such that\n\\begin{equation*}\n\\set{\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,\\vect{v}}\n\\end{equation*}\nis a basis. You could pick\n\\begin{equation*}\n\\vect{v}=\\begin{mymatrix}{c}\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nfor example. Explain why this one works or one of your choice works. Then\nyou could define $A\\vect{v}$ to equal some vector in $\\R^{2}$.\nExplain why there will be more than one such matrix $A$ which will deliver\nthe inverse isomorphism $T^{-1}$ on $\\func{im}(T)$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Now let $V$ equal $\\sspan\\set{\\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} } $ and let $T:V\\rightarrow W$ be a linear transformation\nwhere\n\\begin{equation*}\nW=\\sspan\\set{\\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n1 \\\\\n0\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix} }\n\\end{equation*}\n$\\ $\\ and\n\\begin{equation*}\nT\\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n1 \\\\\n0\n\\end{mymatrix} ,T\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nExplain why $T$ is an isomorphism. Determine a matrix $A$ which, when\nmultiplied on the left gives the same result as $T$ on $V$ and a matrix $B$\nwhich delivers $T^{-1}$ on $W$. \\textbf{Hint:\\ }You need to have\n\\begin{equation*}\nA\\begin{mymatrix}{cc}\n1 & 0 \\\\\n0 & 1 \\\\\n1 & 1\n\\end{mymatrix} =\\begin{mymatrix}{cc}\n1 & 0 \\\\\n0 & 1 \\\\\n1 & 1 \\\\\n0 & 1\n\\end{mymatrix}\n\\end{equation*}\nNow enlarge $\\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} $ to obtain a basis for $\\R^{3}$. You could add in $\\begin{mymatrix}{c}\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix} $ for example, and then pick another vector in $\\R^{4}$ and\nlet $A\\begin{mymatrix}{c}\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix} $ equal this other vector. Then you would have\n\\begin{equation*}\nA\\begin{mymatrix}{ccc}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n1 & 1 & 1\n\\end{mymatrix} =\\begin{mymatrix}{ccc}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n1 & 1 & 0 \\\\\n0 & 1 & 1\n\\end{mymatrix}\n\\end{equation*}\nThis would involve picking for the new vector in $\\R^{4}$ the vector\n$\\begin{mymatrix}{cccc}\n0 & 0 & 0 & 1\n\\end{mymatrix} ^{T}$. Then you could find $A$. You can do something similar to find\na matrix for $T^{-1}$ denoted as $B$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "67e6c07189b3f3c6731a2cdde9c9afa923da4962", "size": 7694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/LinearTransformations-Isomorphisms.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/exercises/VectorSpaces-LinearTransformations-Isomorphisms.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/exercises/VectorSpaces-LinearTransformations-Isomorphisms.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 22.3662790698, "max_line_length": 135, "alphanum_fraction": 0.6334806343, "num_tokens": 3060, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505248181417, "lm_q2_score": 0.8962513765975758, "lm_q1q2_score": 0.8107942782079789}}
{"text": "%\n% Chapter 1.6\n%\n\n\\section*{1.6 Limit Laws}\n\nSuppose that \\(c\\) is the constant and the limits \n$$\\lim_{x-a}f(x) \\quad \\text{ and } \\quad \\lim_{x \\to a}g(x)$$\nexist. Then\n$$\\textbf{1. }\\lim_{x \\to a}[f(x)+g(x)]=\\lim_{x \\to a}f(x) + \\lim_{x \\to a}g(x)$$\n$$\\textbf{2. }\\lim_{x \\to a}[f(x)-g(x)]=\\lim_{x \\to a}f(x) - \\lim_{x \\to a}g(x)$$\n$$\\textbf{3. }\\lim_{x \\to a}[cf(x)]=c\\lim_{x \\to a}f(x)$$\n$$\\textbf{4. }\\lim_{x \\to a}[f(x)g(x)]=\\lim_{x \\to a}f(x) \\times \\lim_{x \\to a}g(x)$$\n$$\\textbf{5. }\\lim_{x \\to a}[\\frac{f(x)}{g(x)}]=\\frac{\\lim_{x \\to a}f(x)}{\\lim_{x \\to a}g(x)} \\quad \\text{if } \\lim_{x \\to a}g(x) \\neq 0 $$\n$$\\textbf{6. }\\lim_{x \\to a}{[f(x)]}^n={[\\lim_{x \\to a}f(x)]}^n \\quad \\text{where } n \\text{ is a postitive integer.}$$\n$$\\textbf{7. }\\lim_{x \\to a}c=c$$\n$$\\textbf{8. }\\lim_{x \\to a}x=a$$\n$$\\textbf{9. }\\lim_{x \\to a}x^n=a^n \\quad \\text{where } n \\text{ is a positive integer}$$\n$$\\textbf{10. }\\lim_{x \\to a}\\sqrt[n]x=\\sqrt[n]a \\quad \\text{where } n \\text{ is a positive integer}$$\n$$\\textbf{11. }\\lim_{x \\to a}\\sqrt[n]{f(x)}=\\sqrt[n]{\\lim_{x \\to a}f(x)} \\quad \\text{where } n \\text{ is a positive integer}$$\n\n\\begin{enumerate}\n    \\item The limit of the sums is the sum of the limits.\n    \\item The limit of the differences is the difference of the limits.\n    \\item The limit of a constant times a function is the constant times the limit of the function.\n    \\item The limit of the products is the product of the limits.\n    \\item The limit of the quotients is the quotient of the limits (provided that the limit of the denominator is not 0).\n\\end{enumerate}\n\n\\subsection*{Direct Substitution Property}\n\nIf \\(f\\) is a polynomial or a rational function and \\(a\\) is in the domain of \\(f\\), then \n$$\\lim_{x \\to a}f(x)=f(a)$$\n\n\\subsection*{Sequeeze Theorem}\n\nIf \\(f(x) \\leq g(x) \\leq h(x)\\) when \\(x\\) is near \\(a\\) (except at \\(a\\)) and \n$$\\lim_{x \\to a}f(x)=\\lim_{x \\to a}h(x) = L$$\nthen\n$$\\lim_{x \\to a}g(x) = L$$\n", "meta": {"hexsha": "d2967c6d4f7cea633a3f0669ffda1a514dc6383a", "size": 1936, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/1-6.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/1-6.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/1-6.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.2195121951, "max_line_length": 139, "alphanum_fraction": 0.6007231405, "num_tokens": 792, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248259606259, "lm_q2_score": 0.863391602943619, "lm_q1q2_score": 0.8107461496899977}}
{"text": "\\section{Cyclic Groups}\r\nRecall that $C_n$ is the set of $n^{th}$ roots of unity.\r\nIf we write $\\xi=e^{2\\pi i/n}$, the group is actually generated by $\\xi$, that is, every element is of the form $\\xi^k$ for some $k$.\r\nNote that $\\xi^n=\\xi^0=1$.\r\n\\begin{definition}\r\n    A group $G$ is called cyclic if there is an $a\\in G$ such that every element is of the form $a^k$ for some $k$.\\\\\r\n    The element $a$ is called the generator of $G$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. The integers under addition is cyclic with generator $1$.\\\\\r\n    2. The group $\\mathbb Z_n$ under addition modulo $n$ is cyclic with generator $1$.\r\n    But in fact, if we take the function $\\phi(k)\\to\\xi^k$, this is an isomorphism and hence $C_n\\cong\\mathbb Z_n$.\r\n\\end{example}\r\n\\begin{theorem}[Classification of Cyclic Groups]\r\n    A cyclic group is isomorphic to either $C_n$ for some $n\\to\\mathbb N$ or $\\mathbb Z$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $G$ be a cyclic group and $a$ be its generator.\r\n    Consider $S=\\{k\\in\\mathbb N\\setminus\\{0\\}:a^k=e\\}$.\r\n    If $S\\neq\\varnothing$, then let $n$ be the smallest element of $S$.\r\n    Consider the function $\\phi:C_n\\to G$ by $\\phi(\\xi^k)=a^k$.\r\n    We want to show that its an isomorphism.\\\\\r\n    Now if $k,l<n$ are such that $k+l<n$, then $\\phi(\\xi^k\\xi^l)=a^{k+l}=a^ka^l=\\phi(\\xi^k)\\phi(\\xi^l)$.\r\n    On the other hand, if $k+l=n+r,0\\le r<n$, then $\\phi(\\xi^k\\xi^l)=a^{k+l}=a^{n+r}=a^r=\\phi(\\xi^r)=\\phi(\\xi^{n+r})=\\phi(\\xi^k)\\phi(\\xi^l)$.\r\n    As $G$ is generated by $a$ and $a^n=e$, every element of $G$ is of the form $a^k$ for some $0\\le k<n$, so $\\phi(\\xi^k)=a^k$, So $\\phi$ is injective, consider the kernel of $\\phi$.\r\n    Note that if $\\phi(\\xi^k)=e$ then $a^k=e\\implies k=0$, so $\\ker\\phi=\\{1\\}$, hence it is injective.\r\n    So $G\\cong C_n$.\\\\\r\n    Now if $S=\\varnothing$, then we shall show that $G\\cong\\mathbb Z$.\r\n    Consider the map $\\phi(k)=a^k$, then $\\phi(k+l)=a^ka^l=\\phi(k)\\phi(l)$.\r\n    This is surjective by the same argument as above.\r\n    Its kernel consists of integers $k$ with $a^k=e$ but since $S$ is empty, $k=0$, so it is injective.\r\n    Therefore $G\\cong\\mathbb Z$.\r\n\\end{proof}\r\nBecause of this theorem, it is convenient to write $\\mathbb Z=C_\\infty$.\r\n\\begin{definition}\r\n    Let $G$ be a group and $g\\in\\mathbb G$, then the order of $g$ is the smallest positive integer $n$ such that $g^n=e$ if it exists.\r\n    If there isn't such an $n$, then we say that $g$ has infinite order.\\\\\r\n    We write $\\operatorname{ord}(g)$ to denote the order of $g$.\r\n\\end{definition}\r\nConsider the set generated by the powers of $g$.\r\nIt follows easily that this set is a subgroup of $G$, we denote this by $\\langle g\\rangle$, the subgroup generated by $g$.\r\nIt is cyclic, so it is isomorphic to $C_n$ where $n=\\operatorname{ord}g$.", "meta": {"hexsha": "14b142816dbeaeb85ddefcd70e1cd39062455e81", "size": 2787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/cyclic.tex", "max_stars_repo_name": "david-bai-notes/IA-Groups", "max_stars_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4/cyclic.tex", "max_issues_repo_name": "david-bai-notes/IA-Groups", "max_issues_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4/cyclic.tex", "max_forks_repo_name": "david-bai-notes/IA-Groups", "max_forks_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.3571428571, "max_line_length": 184, "alphanum_fraction": 0.6411912451, "num_tokens": 957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.9059898305367525, "lm_q1q2_score": 0.8106701593021847}}
{"text": "\\section{Information Criteria}\nIn this section we review the concepts behind \nAkaike's Information Criterion (AIC).\n\nAkaike's original work is for\nIID data, however it is extended to a regression type setting in a\nstraight forward way. Suppose that the conditional distribution of $Y$\ngiven $\\bx$ is know except for a $P$-dimensional parameter $\\bb$. In\nthis case,  the probability density function of $\\bY =\n(Y_1,\\dots,Y_n)$ can be written as \n\\begin{equation}\n\\label{parsimodel}\nf_{\\bY}(\\by;\\bX,\\bb) \\equiv \\prod_{i=1}^n f(y_i;\\bx_i,\\bb)\n\\end{equation}\nwith $\\bX$ the design matrix with rows $\\bx_i$. \n\nAssume that\nthere exists a true parameter vector $\\bb^*$ defining a true\nprobability density denoted by\n$f_{\\bY}(\\by;\\bX,\\bb^*)$. Given these assumptions, we wish to select\n$\\bb$, from one of the models \ndefined as in (\\ref{modelpdef}), ``nearest'' to the true\nparameter $\\bb^*$ based on the observed data $\\by$.\nThe principle behind Akaike's criterion is to\ndefine ``nearest'' as the model that minimizes the Kullback-Leibler \nInformation Quantity\n\\begin{equation}\n\\label{KLdef} \n\\Delta(\\bb^*;\\bX,\\bb) = \\int \\left\\{\\log\n  f_\\bY(\\by;\\bX,\\bb^*) - \\log\n  f_\\bY(\\by;\\bX,\\bb)\\right\\} f_{\\bY}(\\by;\\bX,\\bb^*) \\, d\\by.\n\\end{equation}\n\nThe analytical properties of the Kullback-Leibler Information Quantity\nare discussed in detail by Kullback (1959) \\nocite{kull:1959}. Two\nimportant properties \nfor Akaike's criterion are\n\\begin{enumerate}\n\\item $\\Delta(\\bb^*;\\bX,\\bb) > 0$ if \n$f_{\\bY}(\\by;\\bX,\\bb^*) \\neq f_{\\bY}(\\by;\\bX,\\bb)$\n\\item\n$\\Delta(\\bb^*;\\bX,\\bb) = 0$  if and only if $f_{\\bY}(\\by;\\bX,\\bb^*) =\nf_{\\bY}(\\by;\\bX,\\bb)$ \n\\end{enumerate}\nalmost everywhere on the range of $\\bY$. \nThe properties\nmentioned suggest that finding the model that \nminimizes the Kullback-Leibler \nInformation Quantity is an appropriate way to choose the ``nearest''\nmodel.\n\nSince the first term on the\nright hand side of \n(\\ref{KLdef}) is constant over all models we consider, we may instead\nmaximize\n\\begin{eqnarray}\n\\nonumber\nH(\\bb) &=& \\int \\log\n  f_\\bY(\\by;\\bX,\\bb) f_{\\bY}(\\by;\\bX,\\bb^*) \\, d\\by\\\\\n\\label{Hdef}\n&=& \\sum_{i=1}^n \\int \\log f(y_i;\\bX,\\bb) \\, f(y_i;\\bx_i,\\bb^*) \\, dy_i.\n\\end{eqnarray}\n\nLet $\\bbh_p$ be the maximum likelihood estimate under\nModel(p). Akaike's procedure for model selection is based on choosing\nthe model which produces the estimate that maximizes \n$\\E_{\\bb^*}\\left[H(\\bbh_p)\\right]$ amongst all\ncompeting models. Akaike then derives a criterion by constructing an\nasymptotically unbiased estimate of $\\E_{\\bb^*}\\left[H(\\bbh_p)\\right]$ based\non the observed data. \n\nNotice that $H(\\bbh_p)$ is a function,\ndefined by (\\ref{Hdef}),\nof the maximum likelihood estimate $\\bbh_p$, which is a\nrandom variable obtained from the observed data.\nA natural estimator of \nits expected value (under the true distribution of the data) is\nobtained by substituting the empirical distribution of the data into\n(\\ref{Hdef}) \nresulting in the log likelihood equation evaluated at the maximum\nlikelihood estimate under model(p)\n\\[\nl(\\bbh_p) = \\sum_{i=1}^n \\log f(y_i;\\bx_i,\\bbh_p).\n\\]\nAkaike noticed that in general  $l(\\bbh_p)$ will \noverestimate $\\E_{\\bb^*}\\left[H(\\bbh)\\right]$.  In particular Akaike found\nthat under some regularity conditions\n\\[\nE_{\\bb^*}\\left[l(\\bbh_p) - H(\\bbh_p)\\right] \\approx p .\n\\]\nThis suggests that larger \nvalues of $p$ will result in smaller values \nof $l(\\bbh_p)$, which may be\nincorrectly interpreted as a ``better'' \nfit, regardless of the true model. We need to ``penalize'' for larger\nvalues of $p$ in order to obtain an unbiased estimate of\nthe ``closeness'' of the model. \nThis fact leads to the Akaike Information Criteria which is a\nbias-corrected estimate given by \n\\begin{equation}\n\\label{AIC}\n\\mbox{AIC}(p) = - 2 l(\\bbh_{p}) + 2p .\n\\end{equation}\nSee, for example, Akaike (1973) and Bozdogan (1987)  for\nthe details.  \n\n\n", "meta": {"hexsha": "6b230a293032425dbb691c7744b8c48c1b419764", "size": 3860, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-09-02.tex", "max_stars_repo_name": "haoharryfeng/testpage3", "max_stars_repo_head_hexsha": "ff4b9c1c14079344c2b4b788cba3c5a0d388831a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pages/754/section-09-02.tex", "max_issues_repo_name": "haoharryfeng/testpage3", "max_issues_repo_head_hexsha": "ff4b9c1c14079344c2b4b788cba3c5a0d388831a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pages/754/section-09-02.tex", "max_forks_repo_name": "haoharryfeng/testpage3", "max_forks_repo_head_hexsha": "ff4b9c1c14079344c2b4b788cba3c5a0d388831a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.7407407407, "max_line_length": 76, "alphanum_fraction": 0.7137305699, "num_tokens": 1249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.8947894654011352, "lm_q1q2_score": 0.8106701447684856}}
{"text": "% !TEX root = Main.tex\n\\section{K-means Algorithm}\nHard assignments $Z \\in \\{0,1\\}^{NxK}$, Centroids $U = (u_1|..|u_K) \\in \\mathbb{R}^{DxK}$, data $X \\in \\mathbb{R}^{DxN}$ \\\\\n\\textbf{Target:} $\\min_{\\mathbf{U}, \\mathbf{Z}} J(\\mathbf{U}, \\mathbf{Z}) = \\|\\mathbf{X} - \\mathbf{U} \\mathbf{Z^\\top}\\|_F^2$\\\\\n$= \\sum_{n=1}^N \\sum_{k=1}^K \\mathbf{z}_{n,k} \\|\\mathbf{x}_n - \\mathbf{u}_k\\|_2^2$\\\\\n1. \\textbf{Assign} data points to closest centroid: $k^*(\\mathbf{x}_n) = \\argmin_k \\{ \\|\\mathbf{x}_n - \\mathbf{u}_k\\|_2 \\}$. Set $\\mathbf{z}_{k^*,n} = 1$, and for $ l \\neq k^*~ \\mathbf{z}_{l,n}=0$.\\\\\n2. \\textbf{Update} centroids: $\\mathbf{u}_k = \\frac{\\sum_{n=1}^N z_{n,k} \\mathbf{x}_n}{\\sum_{n=1}^N z_{n,k}}$.\\\\\n3. Repeat until Z doesn't change anymore.\\\\\nComputational cost: $O(K\\cdot N \\cdot D)$\n", "meta": {"hexsha": "d968e855eeac2b036298742bf4c67af669e2b233", "size": 786, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "KMeans.tex", "max_stars_repo_name": "florianmorath/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-19T15:10:37.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-19T15:10:37.000Z", "max_issues_repo_path": "KMeans.tex", "max_issues_repo_name": "florianmorath/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "KMeans.tex", "max_forks_repo_name": "florianmorath/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 78.6, "max_line_length": 199, "alphanum_fraction": 0.5877862595, "num_tokens": 378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813538993889, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.8106413675535369}}
{"text": "\\section{Diagonalization}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Compute sums, products, and powers of diagonal matrices.\n  \\item Determine whether a square matrix is diagonalizable, and\n    diagonalize it if possible.\n  \\end{enumerate}\n\\end{outcome}\n\nA square matrix $D$ is called a \\textbf{diagonal matrix}%\n\\index{diagonal matrix}%\n\\index{matrix!diagonal matrix}\nif all entries except those on the main diagonal are zero. Such\nmatrices look like the following:\n\\begin{equation*}\n  \\begin{mymatrix}{ccccc}\n    d_{11} & 0 & \\cdots & 0 \\\\\n    0 & d_{22} & \\cdots & 0 \\\\\n    \\vdots & \\vdots & \\ddots & \\vdots \\\\\n    0 & 0 & \\cdots & d_{nn} \\\\\n  \\end{mymatrix}.\n\\end{equation*}\nDiagonal matrices are particularly easy to work with. For example, the\nsum of two diagonal matrices is diagonal. Also, the product of two\ndiagonal matrices is diagonal, and is computed by taking the product\nof corresponding diagonal entries.\n\n\\begin{example}{Sums, products, and powers of diagonal matrices}{sums-products-diagonal}\n  Compute $A+B$, $AB$, and $A^4$, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      2 & 0 & 0 \\\\\n      0 & 3 & 0 \\\\\n      0 & 0 & 4 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    B = \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & -2 & 0 \\\\\n      0 & 0 & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{equation*}\n    A+B =\n    \\begin{mymatrix}{ccc}\n      2+1 & 0 & 0 \\\\\n      0 & 3-2 & 0 \\\\\n      0 & 0 & 4+2 \\\\\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rrr}\n      3 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & 6 \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  \\begin{equation*}\n    AB =\n    \\begin{mymatrix}{ccc}\n      2\\cdot 1 & 0 & 0 \\\\\n      0 & 3\\cdot(-2) & 0 \\\\\n      0 & 0 & 4\\cdot 2 \\\\\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rrr}\n      2 & 0 & 0 \\\\\n      0 & -6 & 0 \\\\\n      0 & 0 & 8 \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    A^4 =\n    \\begin{mymatrix}{ccc}\n      2^4 & 0 & 0 \\\\\n      0 & 3^4 & 0 \\\\\n      0 & 0 & 4^4 \\\\\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{ccc}\n      16 & 0 & 0 \\\\\n      0 & 81 & 0 \\\\\n      0 & 0 & 256 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Notice that all operations are computed componentwise on the\n  diagonal. Therefore, multiplication of diagonal matrices is much\n  simpler than multiplication of general matrices.\n\\end{solution}\n\nOne of the most important problem solving techniques in linear algebra\nis \\textbf{diagonalization}%\n\\index{diagonalization}%\n\\index{matrix!diagonalization}. In a nutshell, the point of\ndiagonalization is to simplify a problem by replacing an arbitrary\nmatrix by a diagonal matrix. We say that two square matrices $A$ and\n$B$ are \\textbf{similar}%\n\\index{similar matrices}%\n\\index{matrix!similar} if there exists an invertible matrix $P$ such\nthat $P^{-1}AP = B$. A matrix is \\textbf{diagonalizable}%\n\\index{matrix!diagonalizable}%\n\\index{diagonalizable matrix} if it is similar to a diagonal matrix.\nThis is summarized in the following definition.\n\n\\begin{definition}{Diagonalizable matrix}{diagonalizable}\n  Let $A$ be an $n\\times n$-matrix. Then $A$ is said to be\n  \\textbf{diagonalizable}%\n  \\index{diagonalizable matrix} if there exists an invertible matrix\n  $P$ and a diagonal matrix $D$ such that\n  \\begin{equation*}\n    P^{-1}AP=D.\n  \\end{equation*}\n\\end{definition}\n\nThe key connection between diagonalizability, eigenvectors, and\neigenvalues is the following theorem.\n\n\\begin{theorem}{Diagonalization and eigenvectors}{eigenvectors-and-diagonalizable}\n  An $n\\times n$-matrix $A$ is diagonalizable if and only if $A$ has\n  $n$ linearly independent eigenvectors.\n  \\bigskip\n\n  Moreover, in this case, let $P$ be the invertible matrix whose\n  columns are $n$ linearly independent eigenvectors of $A$, and let\n  $D$ be the diagonal matrix whose diagonal entries are the\n  corresponding eigenvalues. Then $P^{-1}AP=D$.\n\\end{theorem}\n\n\\begin{proof}\n  Assume that $A$ has $n$ linearly independent eigenvectors\n  $\\vect{v}_1,\\ldots,\\vect{v}_n$. Let\n  $\\eigenvar_1,\\ldots,\\eigenvar_n$ be the corresponding eigenvalues,\n  so that\n  \\begin{equation}\\label{eqn:eigenvectors-and-diagonalizable}\n    A\\vect{v}_i = \\eigenvar_i\\vect{v}_i\n  \\end{equation}\n  for all $i=1,\\ldots,n$. Let $P$ be the matrix that has\n  $\\vect{v}_1,\\ldots,\\vect{v}_n$ as its columns. Then $P$ is\n  invertible because $\\vect{v}_1,\\ldots,\\vect{v}_n$ are linearly\n  independent. Let $D$ be the diagonal matrix that has\n  $\\eigenvar_1,\\ldots,\\eigenvar_n$ as its diagonal entries.  By the\n  column method of matrix multiplication, the $i\\th$ column of $AP$ is\n  $A\\vect{v}_i$. Also by the column method of matrix multiplication,\n  the $i\\th$ column of $PD$ is $\\eigenvar_i\\vect{v}_i$.  Therefore, by\n  {\\eqref{eqn:eigenvectors-and-diagonalizable}}, the matrices $AP$ and\n  $PD$ have the same columns, i.e.,\n  \\begin{equation*}\n    AP = PD.\n  \\end{equation*}\n  It follows that $P^{-1}AP = D$, as desired.\n\n  Conversely, assume that $A$ is diagonalizable. Then there exists an\n  invertible matrix $P$ and a diagonal matrix $D$ such that\n  $P^{-1}AP=D$, or equivalently, $AP=PD$. Let\n  $\\vect{v}_1,\\ldots,\\vect{v}_n$ be the columns of $P$ and let\n  $\\eigenvar_1,\\ldots,\\eigenvar_n$ be the diagonal entries of $D$.\n  Again we find that the $i\\th$ column of $AP$ is $A\\vect{v}_i$ and\n  the $i\\th$ column of $PD$ is $\\eigenvar_i\\vect{v}_i$, and therefore\n  $A\\vect{v}_i = \\eigenvar_i\\vect{v}_i$ holds for all $i$. It follows\n  that $\\vect{v}_1,\\ldots,\\vect{v}_n$ are eigenvectors of $A$. Since\n  $P$ is invertible, $\\vect{v}_1,\\ldots,\\vect{v}_n$ are linearly\n  independent, so $A$ has $n$ linearly independent eigenvectors.\n\\end{proof}\n\n\\begin{example}{Diagonalizing a matrix}{diagonalize-matrix}\n  Diagonalize the matrix\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rrr}\n      3  & 0 &  2 \\\\\n      6  & 4 &  3 \\\\\n      -4 & 0 & -3 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  In other words, find an invertible matrix $P$ and a diagonal matrix\n  $D$ such that $P^{-1}AP=D$.\n\\end{example}\n\n\\begin{solution}\n  By Theorem~\\ref{thm:eigenvectors-and-diagonalizable}, we use the\n  eigenvectors of $A$ as the columns of $P$ and the corresponding\n  eigenvalues as the diagonal entries of $D$. We already found the\n  eigenvectors and -values of $A$ in\n  Example~\\ref{exa:finding-eigenvalues-eigenvectors}.  They were\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n    \\quad\n    \\vect{v}_2 = \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 2 \\end{mymatrix}.\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_3 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 0 \\end{mymatrix}.\n  \\end{equation*}\n  with corresponding eigenvalues $\\eigenvar_1=1$, $\\eigenvar_2=-1$,\n  and $\\eigenvar_3=4$. Therefore we can use\n  \\begin{equation*}\n    P = \\begin{mymatrix}{rrr}\n      -1 & -1 & 0 \\\\\n      1  &  0 & 1 \\\\\n      1  &  2 & 0 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    D = \\begin{mymatrix}{rrr}\n      1 &  0 & 0 \\\\\n      0 & -1 & 0 \\\\\n      0 &  0 & 4 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  To double-check that $P^{-1}AP$ is indeed equal to $D$, we first\n  compute the inverse of $P$:\n  \\begin{equation*}\n    P^{-1} =\n    \\begin{mymatrix}{rrr}\n      -2 & 0 & -1 \\\\\n      1  & 0 &  1 \\\\\n      2  & 1 &  1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Then\n  \\begin{equation*}\n    P^{-1}AP\n    ~=~\n    \\begin{mymatrix}{rrr}\n      -2 & 0 & -1 \\\\\n      1  & 0 &  1 \\\\\n      2  & 1 &  1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      3  & 0 &  2 \\\\\n      6  & 4 &  3 \\\\\n      -4 & 0 & -3 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      -1 & -1 & 0 \\\\\n      1  &  0 & 1 \\\\\n      1  &  2 & 0 \\\\\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rrr}\n      1 &  0 & 0 \\\\\n      0 & -1 & 0 \\\\\n      0 &  0 & 4 \\\\\n    \\end{mymatrix}\n    = D.\n  \\end{equation*}\n  Alternatively, we could have checked that $AP=PD$, which would not\n  have required computing $P^{-1}$.\n\\end{solution}\n\n\\begin{example}{Diagonalizing a matrix}{diagonalize-matrix2}\n  Diagonalize the matrix\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rrr}\n      2  &  0 &  0 \\\\\n      1  &  4 & -1 \\\\\n      -2 & -4 &  4 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  First, we will find the characteristic polynomial of $A$:\n  \\begin{eqnarray*}\n    \\det(A-\\eigenvar I)\n    &=&\n        \\begin{absmatrix}{ccc}\n          2-\\eigenvar &  0 &  0 \\\\\n          1 &  4-\\eigenvar & -1 \\\\\n          -2 & -4 & 4-\\eigenvar \\\\\n        \\end{absmatrix}\n    \\\\\\\\[-1ex]\n    &=& (2-\\eigenvar)\n        \\begin{absmatrix}{cc}\n          4-\\eigenvar & -1 \\\\\n          -4 & 4-\\eigenvar \\\\\n        \\end{absmatrix}\n    \\\\\\\\[-2ex]\n    &=& (2-\\eigenvar)\\paren{(4-\\eigenvar)(4-\\eigenvar)-4}\n    \\\\\n    &=& (2-\\eigenvar)(12-8\\eigenvar+\\eigenvar^2)\n    \\\\\n    &=& (2-\\eigenvar)(2-\\eigenvar)(6-\\eigenvar).\n  \\end{eqnarray*}\n  Therefore, the eigenvalues are $\\eigenvar=2$ and $\\eigenvar=6$.\n  Next, we need to find the eigenvectors. We first find the\n  eigenvectors for $\\eigenvar = 2$. We solve $(A-2I)\\/\\vect{v} = \\vect{0}$:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      0  &  0 &  0 & 0 \\\\\n      1  &  2 & -1 & 0 \\\\\n      -2 & -4 &  2 & 0 \\\\\n    \\end{mymatrix}\n    \\roweq\n    \\begin{mymatrix}{rrr|r}\n      1  &  2 & -1 & 0 \\\\\n      0  &  0 &  0 & 0 \\\\\n      0  &  0 &  0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The general solution is\n  \\begin{equation*}\n    t\\begin{mymatrix}{r} -2 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    + s \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 1 \\end{mymatrix},\n  \\end{equation*}\n  where $t,s$ are parameters. Thus, the basic eigenvectors for\n  $\\eigenvar=2$ are\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{r} -2 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_2 = \\begin{mymatrix}{r}  1 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Doing a similar calculation, we find that the basic eigenvector for\n  $\\eigenvar=6$ is\n  \\begin{equation*}\n    \\vect{v}_3 = \\begin{mymatrix}{r}  0 \\\\ 1 \\\\ -2 \\end{mymatrix}.\n  \\end{equation*}\n  By Theorem~\\ref{thm:eigenvectors-and-diagonalizable}, we use the\n  eigenvectors of $A$ as the columns of $P$ and the corresponding\n  eigenvalues as the diagonal entries of $D$. Therefore,\n  \\begin{equation*}\n    P=\n    \\begin{mymatrix}{rrr}\n      -2 & 1 & 0 \\\\\n      1 & 0 & 1 \\\\\n      0 & 1 & -2\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    D = \\begin{mymatrix}{rrr}\n      2 & 0 & 0 \\\\\n      0 & 2 & 0 \\\\\n      0 & 0 & 6\n    \\end{mymatrix}.\n  \\end{equation*}\n  We can double-check this answer by computing\n  \\begin{equation*}\n    \\def\\arraystretch{1.3}\n    P^{-1}AP\n    ~=~ \\begin{mymatrix}{rrr}\n      -\\frac{1}{4} & \\frac{1}{2} & \\frac{1}{4} \\\\\n      \\frac{1}{2} & 1 & \\frac{1}{2} \\\\\n      \\frac{1}{4} & \\frac{1}{2} & -\\frac{1}{4}\n    \\end{mymatrix} \\begin{mymatrix}{rrr}\n      2 & 0 & 0 \\\\\n      1 & 4 & -1 \\\\\n      -2 & -4 & 4\n    \\end{mymatrix} \\begin{mymatrix}{rrr}\n      -2 & 1 & 0 \\\\\n      1 & 0 & 1 \\\\\n      0 & 1 & -2\n    \\end{mymatrix} \\\\\n    ~=~ \\begin{mymatrix}{rrr}\n      2 & 0 & 0 \\\\\n      0 & 2 & 0 \\\\\n      0 & 0 & 6\n    \\end{mymatrix}\n    ~=~ D.\n  \\end{equation*}\n  Notice that the eigenvalues on the main diagonal of $D$ {\\em must}\n  be in the same order as the corresponding eigenvectors in $P$. Since\n  the eigenvectors $\\vect{v}_1$ and $\\vect{v}_2$ are both for the\n  eigenvalue $\\eigenvar=2$, the entry $2$ appears twice in the matrix\n  $D$.\n\\end{solution}\n\nThe following example shows that not all matrices are diagonalizable.\n\n\\begin{example}{A matrix that cannot be diagonalized}{impossible-diagonalize}\n  Show that the matrix $A =\n    \\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      0 & 1\n    \\end{mymatrix}$ cannot be diagonalized.\n\\end{example}\n\n\\begin{solution}\n  Through the usual procedure, we find that the characteristic\n  polynomial is $(1-\\eigenvar)^2$, and therefore the only eigenvalue is\n  $\\eigenvar=1$. To find the eigenvectors, we solve the equation\n  $(A-I)\\vect{v} = \\vect{0}$:\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      0 & 1 & 0 \\\\\n      0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The general solution is\n  \\begin{equation*}\n    \\vect{v} = t\\begin{mymatrix}{r} 1 \\\\ 0 \\end{mymatrix}.\n  \\end{equation*}\n  Because the solution space is $1$-dimensional, there is only one basic\n  eigenvector:\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{r} 1 \\\\ 0 \\end{mymatrix}.\n  \\end{equation*}\n  Since the matrix $A$ has only one basic eigenvector, we cannot find\n  two linearly independent eigenvectors. Therefore, by\n  Theorem~\\ref{thm:eigenvectors-and-diagonalizable}, $A$ cannot be\n  diagonalized.\n\\end{solution}\n", "meta": {"hexsha": "7060fae0233e67323a5204974ba85d077e9a0d07", "size": 12531, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Eigenvalues-Diagonalization.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Eigenvalues-Diagonalization.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Eigenvalues-Diagonalization.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 31.171641791, "max_line_length": 88, "alphanum_fraction": 0.6048200463, "num_tokens": 4668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.9219218337824341, "lm_q1q2_score": 0.8105045942278841}}
{"text": "\\subsection{Elementary matrices and row operations}\n\nRecall from Definition~\\ref{def:row-operations} that there are three\nkinds of elementary row operations%\n\\index{matrix!row operation}%\n\\index{matrix!elementary row operation}%\n\\index{row operation}%\n\\index{elementary row operation} on matrices:\n\\begin{enumerate}\n\\item Switch two rows.\n\\item Multiply a row by a non-zero number.\n\\item Add a multiple of one row to another row.\n\\end{enumerate}\nThe purpose of this section is to show that each of these row\noperations corresponds to a special type of invertible matrix called\nan \\textbf{elementary matrix}%\n\\index{elementary matrix}%\n\\index{matrix!elementary matrix}.\n\n\\begin{example}{Elementary matrix for switching two rows}{elementary-matrix-1}\n  Let\n  \\begin{equation*}\n    E ~=~ \\begin{mymatrix}{lll}\n      1 & 0 & 0 \\\\\n      0 & 0 & 1 \\\\\n      0 & 1 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  What is the effect of multiplying $E$ by an arbitrary $3\\times\n  n$-matrix $A$?\n\\end{example}\n\n\\begin{solution}\n  Consider an arbitrary $3\\times n$-matrix\n  \\begin{equation*}\n    A ~=~ \\begin{mymatrix}{cccc}\n      a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n      a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n      a_{31} & a_{32} & \\cdots & a_{3n} \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  We compute the product $EA$ by the row method:\n  \\begin{equation*}\n    EA ~=~ \\begin{mymatrix}{lll}\n      1 & 0 & 0 \\\\\n      0 & 0 & 1 \\\\\n      0 & 1 & 0 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{cccc}\n      a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n      a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n      a_{31} & a_{32} & \\cdots & a_{3n} \\\\\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{cccc}\n      a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n      a_{31} & a_{32} & \\cdots & a_{3n} \\\\\n      a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  So the effect of multiplying $A$ by $E$ on the left is exactly the\n  same as switching rows 2 and 3. We say that $E$ is the\n  \\textbf{elementary matrix for switching rows 2 and 3}.\n\\end{solution}\n\n\\begin{example}{Elementary matrix for multiplying a row by a non-zero number}{elementary-matrix-2}\n  Let\n  \\begin{equation*}\n    E ~=~ \\begin{mymatrix}{lll}\n      1 & 0 & 0 \\\\\n      0 & k & 0 \\\\\n      0 & 0 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  What is the effect of multiplying $E$ by an arbitrary $3\\times\n  n$-matrix $A$?\n\\end{example}\n\n\\begin{solution}\n  We compute the product $EA$ by the row method:\n  \\begin{equation*}\n    EA ~=~ \\begin{mymatrix}{lll}\n      1 & 0 & 0 \\\\\n      0 & k & 0 \\\\\n      0 & 0 & 1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{cccc}\n      a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n      a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n      a_{31} & a_{32} & \\cdots & a_{3n} \\\\\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{rrrr}\n      a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n      ka_{21} & ka_{22} & \\cdots & ka_{2n} \\\\\n      a_{31} & a_{32} & \\cdots & a_{3n} \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  So the effect of multiplying $A$ by $E$ on the left is exactly the\n  same as multiplying row 2 by the scalar $k$. We say that $E$ is the\n  \\textbf{elementary matrix for multiplying row 2 by $k$}.\n\\end{solution}\n\n\\begin{example}{Elementary matrix for adding a multiple of one row to another row}{elementary-matrix-3}\n  Let\n  \\begin{equation*}\n    E ~=~ \\begin{mymatrix}{lll}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & k & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  What is the effect of multiplying $E$ by an arbitrary $3\\times\n  n$-matrix $A$?\n\\end{example}\n\n\\begin{solution}\n  Once again we compute the product $EA$:\n  \\begin{equation*}\n    EA ~=~ \\begin{mymatrix}{lll}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & k & 1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{cccc}\n      a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n      a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n      a_{31} & a_{32} & \\cdots & a_{3n} \\\\\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{cccc}\n      a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n      a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n      a_{31}+ka_{21} & a_{32}+ka_{22} & \\cdots & a_{3n}+ka_{2n} \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  So the effect of multiplying $A$ by $E$ on the left is exactly the\n  same as adding $k$ times row 2 to row 3. We say that $E$ is the\n  \\textbf{elementary matrix for adding $k$ times row 2 to row 3}.\n\\end{solution}\n\nAs these examples show, performing each type of elementary row\noperation is the same as multiplying (on the left) by a certain\ninvertible matrix. These matrices are called the \\textbf{elementary\n  matrices}%\n\\index{elementary matrix}%\n\\index{matrix!elementary matrix}. In the\nabove examples, we have only considered $3\\times 3$-elementary\nmatrices, but they exist for other sizes too. The following definition\nmakes this precise. It also shows how to calculate the elementary\nmatrix corresponding to any elementary row operation.\n\n\\begin{definition}{Elementary matrices and row operations}{elementary-matrices-and-row-operations}\n  Let $E$ be an $n\\times n$-matrix. Then $E$ is an \\textbf{elementary\n    matrix}%\n  \\index{elementary matrix}%\n  \\index{matrix!elementary matrix}\n  if it is the result of applying one elementary row operation to the\n  $n\\times n$ identity matrix.\n\\end{definition}\n\n\\begin{example}{Finding an elementary matrix}{finding-elementary-matrix}\n  Consider the elementary row operation of adding $5$ times row 3 to\n  row 1 of a $4\\times n$-matrix. Find the elementary matrix $E$\n  corresponding to this row operation.\n\\end{example}\n\n\\begin{solution}\n  Following Definition~\\ref{def:elementary-matrices-and-row-operations}, all\n  we have to do is apply the desired row operation to the\n  $4\\times 4$-identity matrix:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr}\n      1 & 0 & 0 & 0 \\\\\n      0 & 1 & 0 & 0 \\\\\n      0 & 0 & 1 & 0 \\\\\n      0 & 0 & 0 & 1 \\\\\n    \\end{mymatrix}\n    \\quad\n    \\stackrel{R_1\\rowop R_1+5R_3}{\\roweq}\n    \\quad\n    \\begin{mymatrix}{rrrr}\n      1 & 0 & 5 & 0 \\\\\n      0 & 1 & 0 & 0 \\\\\n      0 & 0 & 1 & 0 \\\\\n      0 & 0 & 0 & 1 \\\\\n    \\end{mymatrix}\n    ~=~ E.\n  \\end{equation*}\n\\end{solution}\n\nWe can double-check that multiplying $E$ by any $4\\times n$-matrix\ndoes indeed have the desired effect:\n\\begin{equation*}\n  \\begin{mymatrix}{rrrr}\n    1 & 0 & 5 & 0 \\\\\n    0 & 1 & 0 & 0 \\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 1 \\\\\n  \\end{mymatrix}\n  \\begin{mymatrix}{cccc}\n    a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n    a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n    a_{31} & a_{32} & \\cdots & a_{3n} \\\\\n    a_{41} & a_{42} & \\cdots & a_{4n} \\\\\n  \\end{mymatrix}\n  ~=~\n  \\begin{mymatrix}{cccc}\n    a_{11}+5a_{31} & a_{12}+5a_{32} & \\cdots & a_{1n}+5a_{3n} \\\\\n    a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n    a_{31} & a_{32} & \\cdots & a_{3n} \\\\\n    a_{41} & a_{42} & \\cdots & a_{4n} \\\\\n  \\end{mymatrix}.\n\\end{equation*}\nThe fact that this always works is the content of the following\ntheorem.\n\n\\begin{theorem}{Multiplication by an elementary matrix and row operations}{multiplication-by-elementary-matrix}\n  Performing any of the three elementary row operations on a matrix $A$ is the\n  same as taking the product $EA$, where $E$ is the elementary matrix\n  obtained by applying the desired row operation to the identity\n  matrix.\n\\end{theorem}\n\n", "meta": {"hexsha": "0db9219f73e8d0f9c212eac1a8d819b77bded0b4", "size": 7205, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-ElementaryMatrices-RowOperations.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-ElementaryMatrices-RowOperations.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-ElementaryMatrices-RowOperations.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 32.0222222222, "max_line_length": 111, "alphanum_fraction": 0.6148507981, "num_tokens": 2599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328286, "lm_q2_score": 0.8918110346549902, "lm_q1q2_score": 0.8103154667697071}}
{"text": "\n\\subsection{Cauchy-Schwarz inequality}\n\nThis states that:\n\n\\(|\\langle u,v\\rangle |^2 \\le \\langle u, u\\rangle \\dot \\langle v, v\\rangle \\)\n\nConsider the vectors \\(u\\) and \\(v\\). We construct a third vector \\(u-\\lambda v\\).\nWe know the length of any vector is non-negative.\n\\(0\\le \\langle u-\\lambda v, u-\\lambda v\\rangle\\)\n\n\\(0\\le \\langle u, u\\rangle+ \\langle u, -\\lambda v\\rangle+\\langle -\\lambda v, u\\rangle+ \\langle -\\lambda v, -\\lambda v\\rangle\\)\n\n\\(0\\le \\langle u, u\\rangle-\\bar{\\lambda }\\langle u, v\\rangle-\\lambda { \\langle v, u\\rangle }+ \\lambda \\bar{\\lambda }\\langle v, v\\rangle\\)\n\n\nWe now look for a value of \\(\\lambda \\) to simplify this equation.\n\n\\(\\lambda = \\dfrac{\\langle u,v \\rangle}{\\langle v, v\\rangle}\\)\n\n\\(0\\le \\langle u, u\\rangle-\\dfrac{\\langle v,u \\rangle\\langle u, v\\rangle}{\\langle v, v\\rangle}-\\dfrac{\\langle u,v \\rangle  \\langle v, u\\rangle }{\\langle v, v\\rangle}+ \\dfrac{\\langle u,v \\rangle}{\\langle v, v\\rangle}\\dfrac{\\langle v,u \\rangle}{\\langle v, v\\rangle}\\langle v, v\\rangle\\)\n\n\\(0\\le \\langle u, u\\rangle-\\dfrac{|\\langle u,v \\rangle|^2}{\\langle v, v\\rangle}\\)\n\n\\(|\\langle u,v \\rangle|^2\\ge \\langle u, u\\rangle\\langle v, v\\rangle\\)\n\n", "meta": {"hexsha": "443e4dba2ff528f741457289b4ca15ad38cc5273", "size": 1162, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/04-06-cauchySchwarz.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/forms/04-06-cauchySchwarz.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/forms/04-06-cauchySchwarz.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.037037037, "max_line_length": 284, "alphanum_fraction": 0.6583476764, "num_tokens": 404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299488452012, "lm_q2_score": 0.8757869900269366, "lm_q1q2_score": 0.8103043519819153}}
{"text": "The original Bresenham Algorithms was developed by J. Bresenham in 1965~\\cite{Bresenham65Line}. The goal was to build an algorithm to draw a line between to coordinates on a pixel grid. The family of Bresenham Algorithms that exist, e.g. to draw a circle were developed by others. In the following section, the Bresenham Line and Circle algorithm will be explained.\n\\subsubsection*{Line Drawing}\nThe original line drawing algorithm uses only additions, subtractions, and a multiplication with the constant value of two.\n\n\\begin{algorithm}\n\t\\caption{Bresenham Line Drawing Algorithm Part \\rom{1}}\n\t\\label{alg:bresline}\n\t\\KwIn{\\(x_0,~ y_0,~ x_1,~ y_1\\)}\n\t\\SetKwBlock{Begin}{Begin}{}\n\t\\SetAlgoLined\n\t\\Begin{\n\t\t\\(\\varDelta_x \\gets \\abs{x_1 - x_0}\\)\\;\n\t\t\\(\\varDelta_y \\gets \\abs{y_1 - y_0}\\)\\;\n\t\t\\(\\text{step}_x \\gets x_0 < x_1~ ? ~1 ~:~ -1 \\)\\;\n\t\t\\(\\text{step}_y \\gets y_0 < y_1~ ?~ 1 ~:~ -1\\)\\;\n\t\terr \\( \\gets \\varDelta_x + \\varDelta_y \\)\n\t}\t\n\\end{algorithm}\n\\begin{algorithm}\n\t\\caption{Bresenham Line Drawing Algorithm Part \\rom{2}}\n\t\\SetAlgoVlined\n\t%This is to hide Begin keyword\n\t\\SetKwBlock{Begin}{}{end}\n\t\\Begin{\n\t\t\\While{\\(x_0 \\neq x_1\\) and \\(y_0 \\neq y_1\\)}{\n\t\t\tdraw Pixel at \\(x_0 | y_0\\) \\;\n\t\t\terr2 \\(\\gets 2 \\times err\\)\\;\n\t\t\t\\If{err2 \\(> \\varDelta_y\\)}{\n\t\t\t\terr \\(\\gets \\text{err} + \\varDelta_y\\)\\;\n\t\t\t\t\\(x_0 \\gets x_0 + \\text{step}_x\\)\\;\n\t\t\t}\n\t\t\t\\If{err2 \\(< d_x\\)}{\n\t\t\t\terr \\(\\gets \\text{err} + \\varDelta_x\\)\\;\n\t\t\t\t\\(y_0 \\gets y_0 + \\text{step}_y\\)\\;\n\t\t\t}\t\n\t\t}\n\t}\n\\end{algorithm}\n\nAs seen in \\cref{alg:bresline} the first step is to set the start coordinate. After that an error variable is set. The error variable is for evaluating, which pixel to draw next. Is the value of the error variable lesser than zero it goes one step in the x direction, is the value greater or equal than zero it goes one step in the y and one step in the x direction. It ends when the new x and y coordinate equal to the destination x and y coordinate.\n \n\\subsubsection*{Circle Drawing}\nFor the Circle Drawing Algorithm often referred to as the Bresenham Circle Drawing Algorithm or the Midpoint circle drawing algorithm, we first have to define smaller in a Cartesian coordinate system. Usually such a coordinate system consists of four areas called quadrants. If we now go an split each quadrant up into two area with a diagonal line with its origin at the the center of the coordinate system, we create areas called octants.\n\n\\begin{algorithm}[H]\n\t\n\t\\KwIn{\\(x_c\\), \\(y_c\\), radius}\n\t\\SetKwBlock{Begin}{Begin}{End}\n\t\\SetAlgoLined\n\t\\Begin{\n\t\\(x \\gets 0\\)\\;\n\t\\(y \\gets \\text{radius}\\)\\;\n\t\\(\\text{err} \\gets 3 - 2 \\times \\text{radius}\\)\\;\n\t\\While{\\(y \\geqslant x\\)}{\n\t\t\\(x \\gets x + 1\\)\\;\n\t\t\\eIf{\\(\\text{err} > 0\\)}{\n\t\t\t\\(y \\gets y - 1\\)\\;\n\t\t\t\\(\\text{err} \\gets \\text{err} + 4 \\times (x - y) + 10\\)\\;\n\t\t}{\n\t\t\t\\(\\text{err} \\gets \\text{err} + 4 \\times x + 6\\)\\;\n\t\t}\n\t\tDraw corresponding pixel in each quadrant\\;\n\t}\n}\n\t\\caption{Bresenham Circle Drawing Algorithm}\n\t\\label{alg:brescircle}\n\\end{algorithm}\n\nAs seen in \\cref{alg:brescircle} the fundamental function of the two algorithms are the same, the main difference lies is how many pixels are drawn at the same time and the calculation of the error value.\n\n", "meta": {"hexsha": "5f3ae8333a12b0e991acf2b5b442d9574be37706", "size": 3198, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/src/pre_bresenham.tex", "max_stars_repo_name": "azrael1206/AEGIS", "max_stars_repo_head_hexsha": "830ac33120425abe6eb5f60f088d407dc6fe9f01", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-11-15T11:08:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-11T04:44:05.000Z", "max_issues_repo_path": "doc/src/pre_bresenham.tex", "max_issues_repo_name": "azrael1206/AEGIS", "max_issues_repo_head_hexsha": "830ac33120425abe6eb5f60f088d407dc6fe9f01", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/src/pre_bresenham.tex", "max_forks_repo_name": "azrael1206/AEGIS", "max_forks_repo_head_hexsha": "830ac33120425abe6eb5f60f088d407dc6fe9f01", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.0422535211, "max_line_length": 451, "alphanum_fraction": 0.689180738, "num_tokens": 1069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299529686199, "lm_q2_score": 0.8757869819218865, "lm_q1q2_score": 0.8103043480941167}}
{"text": "\\subsection{Performance Metrics}\nWe measure the accuracy of the model using two error metrics:\nmean absolute error (MAE) and root mean squared error (RMSE).\nThese are defined as\n\\begin{align}\n  \\text{MAE} &= \\frac{1}{N}\\sum_{i=1}^N\\left|y_i - \\hat{y}_i\\right|\\\\\n  \\text{RMSE} &= \\sqrt{\\frac{1}{N}\\sum_{i=1}^N\\left(y_i - \\hat{y}_i\\right)^2}\n  \\intertext{where}\n  \\hat{y_i} &= \\text{predicted output}\\nonumber\\\\\n  y_i &= \\text{true value}\\nonumber\n\\end{align}\nThe MAE measures the expected error throughout the forecast horizon. The RMSE\nindicates the presence of significant but infrequent errors. Since the data were\nnormalized by system capacity \\cite{wang_quantifying_2016}, the error metrics\nare easily interpretable.\nIn order to compare how each individual weather input changed the forecast accuracy, we calculated a ``percent improvement'' over the\nunivariate case (i.e. a demand prediction based only on historical demand data).\nThis percent improvement is calculated by\n\\begin{align}\n  \\text{\\% Improvement} &= \\frac{\\hat{e} - e}{e}\\times 100, \\text{ [-]}\n  \\intertext{where}\n  e &= \\text{error from the univariate forecast}\\nonumber\\\\\n  \\hat{e} &= \\text{error from the duovariate forecast.}\\nonumber\n\\end{align}\nThe sign indicates the direction of change in\nerror. Finally, in order to facilitate comparison with other work, we calculated\nthe normalized root mean squared error (NRMSE) by\n\\begin{align}\n  NRMSE &= \\sqrt{\\frac{\\sum_{i=1}^N\\left(y_i - \\hat{y}_i\\right)^2}{\\sum_{i=1}^{N}\\left(y_i - \\tilde{y_i}\\right)^2}}\n  \\intertext{where}\n  \\tilde{y} &= \\text{mean of the target set}\\nonumber\n\\end{align}\n", "meta": {"hexsha": "8f2d7fc0514283bbf57200ce979e3c2a3d967cec", "size": 1614, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "publications/forecasting-paper/errormetric.tex", "max_stars_repo_name": "samgdotson/CAIRO", "max_stars_repo_head_hexsha": "dadc59c5f3ae42b78147ffc4e54e95fb5421ca91", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "publications/forecasting-paper/errormetric.tex", "max_issues_repo_name": "samgdotson/CAIRO", "max_issues_repo_head_hexsha": "dadc59c5f3ae42b78147ffc4e54e95fb5421ca91", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-13T13:40:50.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-22T18:37:18.000Z", "max_forks_repo_path": "publications/forecasting-paper/errormetric.tex", "max_forks_repo_name": "samgdotson/CAIRO", "max_forks_repo_head_hexsha": "dadc59c5f3ae42b78147ffc4e54e95fb5421ca91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-25T14:39:07.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-25T14:39:07.000Z", "avg_line_length": 48.9090909091, "max_line_length": 133, "alphanum_fraction": 0.7311028501, "num_tokens": 490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8670357632379241, "lm_q1q2_score": 0.8101540197515117}}
{"text": "\\textbf{Considering using cubic splines to interpolate the function\n\\begin{align*}\nf(x)=\\frac{e^{3x}\\sin(200x^2)}{1+20x^2},~~~0\\leq x\\leq 1.\n\\end{align*}\nWrite a short MATLAB script using spline, interpolating this function at equidistant points $x_i =\\frac{i}{n}$, $i =0,1,...,n$. Repeat this for $n = 2^j$, $j = 4, 5, . . . , 14$. For each calculation record the maximum error at the point $X = 0 : .001 : 1$. Plot these errors against $n$, using loglog.\nMake observations in comparison to Figure 10.8.}\n\n\\vspace{0.3in}\n\nIn this problem we explore spline approximation. Given the function above we are going to compute spline approximations for different number of interpolation points. In figure 1 we can see how for $n=16$ interpolation points the approximation is not good enough. Using $n=32$ interpolation points the approximation is good at the beginning of the domain, up to $x=0.2$, but soon it starts to be far from the actual value of the function. Incrementing the number of interpolation points once more to $n=64$ we see how the approximation matches the function further in the domain, up to $x=0.3$. This behaviour goes on until we use $n=256$ nodes, that the approximation seems to match the function very accurately. Incrementing number of interpolation points to $n=512$ doesn't seem to offer an appreciable improvement in accuracy. However, we will see in figure 2 that this is not true. The figures for higher $n$ are not shown since they are indistinguishable from $(f)$.\n\nIn figure 2 we show the maximum error of the approximation against the number of interpolation points used. We can see how incresing $n$ from $256$ to $512$ reduces the maximum error in an order of magnitude, although we are not able to see it in the plots of figure 1. Notice the high frequency of the function to approximate, this requires high number of points for the spline interpolant to be accurate.\n\nIn figure 3 is a \\textit{semi-log} version of figure 2, we show it to compare to the figure in the book mentioned by the problem. We can see how with only $201$ interpolation points the Chebyshev's interpolation outcomes the spline we have done. The maximum error for the Chebyshev's interpolation using $201$ interpolation points is of the order of $10^{-14}$ and we haven't reached that level of accuracy using up to $16384$ points.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace*{\\fill}\n\\subfigure[$n=16$.]{\\includegraphics[scale=0.5]{P1_n=16.eps}}\n\\hfill\n\\subfigure[$n=32$.]{\\includegraphics[scale=0.5]{P1_n=32.eps}}\n\\hspace*{\\fill}\n\n\\hspace*{\\fill}\n\\subfigure[$n=64$.]{\\includegraphics[scale=0.5]{P1_n=64.eps}}\\hfill\n\\subfigure[$n=128$.]{\\includegraphics[scale=0.5]{P1_n=128.eps}}\n\\hspace*{\\fill}\n\n\\hspace*{\\fill}\n\\subfigure[$n=256$.]{\\includegraphics[scale=0.5]{P1_n=256.eps}}\\hfill\n\\subfigure[$n=512$.]{\\includegraphics[scale=0.5]{P1_n=512.eps}}\n\\hspace*{\\fill}\n\\caption{Spline approximation of the function $f(x)$ defined above.}\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.75]{P1_Error.eps}}\n\\caption{Error of the spline approximation.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.75]{P1_Error_semilog.eps}}\n\\caption{Error of the spline approximation.}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 1\nclear all; close all; format long; clc\nlegendfontsize=14;\naxisfontsize=16;\nf = @(x) (exp(3*x).*(sin(200*x.^2)))./(1 + 20*x.^2);\nxx=0:0.001:1;\nfor j=4:14\n    n=2^j;\n    x=linspace(0,1,n+1);\n    fx=f(x);\n    fxx=spline(x,fx,xx);\n    error=max(abs(f(xx)-fxx));\n    \n    figure(1)\n    loglog(n,error,'r*')\n    hold on\n    grid on\n    if j==14\n        xlabel('$n$','Interpreter','latex')\n        set(gca,'fontsize',14)\n        legend({'Error'},...\n         'Interpreter','latex','fontsize',legendfontsize)\n        txt='Latex/FIGURES/P1_Error';\n        saveas(gcf,txt,'epsc')\n    end\n    figure(2)\n    semilogy(n,error,'r*')\n    hold on\n    grid on\n    if j==14\n        xlabel('$n$','Interpreter','latex')\n        set(gca,'fontsize',14)\n        legend({'Error'},...\n         'Interpreter','latex','fontsize',legendfontsize)\n        txt='Latex/FIGURES/P1_Error_semilog';\n        saveas(gcf,txt,'epsc')\n    end\n    \n    figure\n    plot(xx,f(xx))\n    hold on\n    plot(xx,fxx)\n    grid on\n    xlabel('$x$','Interpreter','latex')\n    legend({'$f(x)$','Spline'},...\n        'Interpreter','latex','fontsize',legendfontsize)\n    set(gca,'fontsize',axisfontsize)\n    txt=['Latex/FIGURES/P1_n=',num2str(n)];\n    saveas(gcf,txt,'epsc')\n    end\n\\end{verbatim}", "meta": {"hexsha": "15688817f0dff641504235182a1c9f170f5774c2", "size": 4596, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 3/Latex/problem1.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 3/Latex/problem1.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 3/Latex/problem1.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.504950495, "max_line_length": 971, "alphanum_fraction": 0.6927763272, "num_tokens": 1349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.9099069980980297, "lm_q1q2_score": 0.81008495466039}}
{"text": "\\subsection{Solving systems using $LU$ factorization}\n\nOne reason people care about the $LU$ factorization\n\\index{LU factorization!solving systems} is it allows the quick solution of\nsystems of equations. Here is an example.\n\n\\begin{example}{$LU$ factorization to solve equations}{}\nSuppose you want to find the solutions to\n\\begin{equation*}\n\\begin{mymatrix}{rrrr}\n1 & 2 & 3 & 2 \\\\\n4 & 3 & 1 & 1 \\\\\n1 & 2 & 3 & 0\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz \\\\\nw\n\\end{mymatrix} =\\begin{mymatrix}{c}\n1 \\\\\n2 \\\\\n3\n\\end{mymatrix} .\n\\end{equation*}\n\\end{example}\n\n\\begin{solution}\n\nOf course one way is to write the augmented matrix and grind away. However,\nthis involves more row operations than the computation of the $LU$\nfactorization and it turns out that the $LU$ factorization can give the\nsolution quickly. Here is how. The following is an $LU$ factorization for\nthe matrix.\n\\begin{equation*}\n\\begin{mymatrix}{rrrr}\n1 & 2 & 3 & 2 \\\\\n4 & 3 & 1 & 1 \\\\\n1 & 2 & 3 & 0\n\\end{mymatrix} \\allowbreak =\\allowbreak \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n4 & 1 & 0 \\\\\n1 & 0 & 1\n\\end{mymatrix} \\begin{mymatrix}{rrrr}\n1 & 2 & 3 & 2 \\\\\n0 & -5 & -11 & -7 \\\\\n0 & 0 & 0 & -2\n\\end{mymatrix} .\n\\end{equation*}\n\nLet $UX=Y$ and consider $LY=B$ where in this case, $B=\\mat{1,2,3} ^{T}$. Thus\n\\begin{equation*}\n\\allowbreak \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n4 & 1 & 0 \\\\\n1 & 0 & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\ny_{1} \\\\\ny_{2} \\\\\ny_{3}\n\\end{mymatrix} =\\begin{mymatrix}{c}\n1 \\\\\n2 \\\\\n3\n\\end{mymatrix}\n\\end{equation*}\nwhich yields very quickly that $Y=\\begin{mymatrix}{r}\n1 \\\\\n-2 \\\\\n2\n\\end{mymatrix} \\allowbreak$.\n\nNow you can find $X$ by solving $UX=Y$. Thus in this case,\n\\begin{equation*}\n\\begin{mymatrix}{rrrr}\n1 & 2 & 3 & 2 \\\\\n0 & -5 & -11 & -7 \\\\\n0 & 0 & 0 & -2\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz \\\\\nw\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n-2 \\\\\n2\n\\end{mymatrix}\n\\end{equation*}\nwhich yields\n\\begin{equation*}\nX=\\begin{mymatrix}{c}\n-\n\\vspace{0.05in}\\frac{3}{5}+\\vspace{0.05in}\\frac{7}{5}t \\\\\n\\vspace{0.05in}\\frac{9}{5}-\\vspace{0.05in}\\frac{11}{5}t \\\\\nt \\\\\n-1\n\\end{mymatrix} ,\\enspace t\\in \\R\\text{.}\n\\end{equation*}\n\n\\end{solution}", "meta": {"hexsha": "460ecb50e9ab847886b0b94587d3316589977eb2", "size": 2131, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/matricesLUFactorizationSolvingSystems.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/matricesLUFactorizationSolvingSystems.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/matricesLUFactorizationSolvingSystems.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 21.31, "max_line_length": 77, "alphanum_fraction": 0.6419521351, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.9099070048165069, "lm_q1q2_score": 0.8100849500475634}}
{"text": "\\chapter{Matrices}\\label{app:matrices}\nThis appendix aims to provide some fundamental knowledge on matrices and linear algebra used throughout this thesis. \n\nA matrix is a rectangular array with numerical elements and its dimensions are denoted using ``$row \\times column$''. A $3\\times 5$ matrix, for example, thus has $3$ rows and $5$ columns (see Figure \\ref{fig:matrixA}). Along those lines, a \\textit{row vector} is a matrix with $1$ row and more than $1$ column and a \\textit{column vector} is a matrix with $1$ column and more than $1$ row.\n\nIn this document, matrices and vectors are written using bold symbols. %\\SWcomment[Many notations exist, blabla $\\bar a$ $\\vec a$] \nA matrix is denoted by a capital letter -- such as $\\A$ -- whereas vectors are decapitalised -- such as $\\u$. An element in a matrix is denoted with a non-bold, decapitalised variable, where the subscripts indicate the indices of the row and column. For example, the element in the 2\\textsuperscript{nd} row and the 4\\th column of a matrix $\\A$ is denoted as $a_{24}$. An element in a vector only has one subscript, regardless of whether it is a row or a column vector.\n\n\\section{Operations}\nMultiplying and dividing a matrix by a scalar (a single number) is valid and happens on an element-by-element basis. For a $2\\times 2$ matrix $\\A$ and scalar $p$ the following operations hold\n\\begin{equation*}\n        p \\A = \\A p = \\begin{bmatrix}\n        p\\cdot a_{11}& p\\cdot a_{12}\\\\\n        p\\cdot a_{21} & p\\cdot a_{22}\n    \\end{bmatrix}, \\qaq \\A / p= \\begin{bmatrix}\n            a_{11}/p& a_{12}/p\\\\\n            a_{21}/p & a_{22}/p\n    \\end{bmatrix}.\n\\end{equation*}\nNotice that although a matrix can be divided by a scalar, a scalar can not necessarily be divided by a matrix. See Section \\ref{sec:inverse} for more information.\n\n\\subsubsection{Matrix transpose}\nA matrix or vector can be \\textit{transposed}, which is indicated by the $T$ operator. Transposing a matrix $\\A$ is denoted by $\\A^T$. This means that the elements in the $i$\\th row and the $j$\\th column of the original matrix become the elements in the $j$\\th row and the $i$\\th column of the transposed matrix. Essentially the row and column indices of the elements inside the matrix get switched according to\n\\begin{equation}\\label{eq:matrixTransposition}\n    a_{ij} = a_{ji}.\n\\end{equation} \nAlso see Figure \\ref{fig:matrixTransp}. For a row vector, the transpose operation simply changes it to a column vector and vice versa. Another way of seeing a transpose is that all the elements get flipped over the \\textit{main diagonal} of the matrix. The main diagonal comprises the elements $a_{ij}$ where $i=j$ and a transpose does not affect the location of these elements. \n\n\\begin{figure}[h]\n    \\centering\n    \\subfloat[A $3\\times 5$ matrix $\\A$.\\label{fig:matrixA}]{\\includegraphics[width=0.45\\textwidth]{figures/analysis/matrixA1.pdf}}\\hspace{0.03cm}\n    \\subfloat[A transposed matrix $\\A^T$ of size $5\\times 3$.\\label{fig:matrixAT}]{\\includegraphics[width=0.45\\textwidth]{figures/analysis/matrixAT1.pdf}}\n    \\caption{A matrix $\\A$ and its transpose $\\A^T$. The elements get flipped along the main diagonal of the matrix according to Eq. \\eqref{eq:matrixTransposition}. \\label{fig:matrixTransp}}\n\\end{figure}\n\n\\subsubsection{Matrix multiplication}\nMatrix multiplication (this includes matrix-vector multiplication) is different from regular multiplication in that it needs to abide several extra rules. The multiplication of two matrices $\\A$ and $\\B$ to a resulting matrix $\\C$ is defined as\n\\begin{equation}\\label{eq:matrixMult}\n    c_{ij} = \\sum_{k=1}^K a_{ik} b_{kj},\n\\end{equation}\nwhere $K$ is both the number columns of matrix $\\A$ and the number of rows in matrix $\\B$. It thus follows that, in order for a matrix multiplication to be valid, the number of columns of the first matrix needs to be equal to the number of rows in the second matrix. The result will then be a matrix with a number of rows equal to that of the first matrix and a number of columns equal to that of the second matrix. See Figure \\ref{fig:matrixVector} for reference.\n\nAs an example, consider the $L\\times M$ matrix $\n\\A$ and a $M\\times N$ matrix $\\B$ with $L\\neq N$. The multiplication $\\A\\B$ is defined as the number of columns of matrix $\\A$ ($M$) is equal to the number of rows of matrix $\\B$ (also $M$). The result, $\\C$, is a $L \\times N$ matrix. The multiplication $\\B\\A$ is undefined as the number of columns of the first matrix does not match the number of rows in the second matrix. A valid multiplication of two matrices written in their dimensions is\n\\begin{equation}\n    \\overbrace{(L\\times M)}^{\\A}\\cdot \\overbrace{(M\\times N)}^{\\B} = \\overbrace{(L\n    \\times N)}^{\\C}.\n\\end{equation}\n\n\\begin{figure}[h]\n    \\includegraphics[width=\\textwidth]{figures/analysis/matrixVector.pdf}\n    \\caption{Visualisation of valid matrix multiplications (see Eq. \\eqref{eq:matrixMult}). The ``inner'' dimensions (columns of the left matrix and rows of the right) must match and result in a matrix with a size of ``outer'' dimensions (rows of the left matrix and columns of the right). \\label{fig:matrixVector}}\n\\end{figure}\n\n\\section{Matrix inverse}\\label{sec:inverse}\nIf a matrix has the same number of rows as columns, it is called a \\textit{square matrix}. Square matrices have special properties, one of which is that it (usually) can be \\textit{inverted}. A square matrix $\\A$ is invertable if there exists a matrix $\\B$ such that\n\\begin{equation}\n    \\A \\B = \\B \\A = \\I. \n\\end{equation}\nThis matrix $\\B$ is then called the \\textit{inverse} of $\\A$ and can be written as $\\A^{-1}$. Not all square matrices have an inverse, in which case it is called \\textit{singular}. Rather than going through manually inverting a matrix, or determining whether it is singular, the following function in \\texttt{MATLAB} will provide the inverse of a matrix \\texttt{A}:\n\\begin{center}\n    \\texttt{A\\_inverted = inv(A);}\n\\end{center}\n\nThe inverse of a \\textit{diagonal matrix} (a matrix with non-zero elements on its main diagonal and the rest zeros) is obtained by replacing the diagonal elements by their reciprocal. So for a diagonal $3\\times 3$ matrix, the following holds:\n\\begin{equation*}\n    \\xbracketMatrixstack{\n        a_{11} & 0 & 0\\\\\n        0 & a_{12} & 0\\\\\n        0 & 0 & a_{33}\n    }^{-1} =\\quad \n    \\xbracketMatrixstack{\n        \\frac{1}{a_{11}} & 0 & 0\\\\\n        0 & \\frac{1}{a_{12}} & 0\\\\\n        0 & 0 & \\frac{1}{a_{33}}\n    }.\n\\end{equation*}\n\n\\section{Systems of linear equations}\\label{sec:linearEquations}\nMatrices can be conveniently used to solve \\textit{systems of linear equations}, a set of linear equations containing the same set of variables. \n\nFor example, take the system of linear equations\n\\begin{align*}\n    x + z &= 6,\\\\\n    z - 3y &= 7,\\\\\n    2x + y + 3z &= 15,\n\\end{align*}\nwith independent variables $x$, $y$ and $z$. The goal is to find a solution for these variables that satisfy all three equations. This system could be solved by hand using algebraic methods, but alternatively, the system can be written in matrix form:\n\\begin{equation}\n    \\A \\u = \\w.\n\\end{equation}\nHere, column vector $\\u$ contains the independent variables $x$, $y$, and $z$, matrix $\\A$ contains the coefficients multiplied onto these variables and $\\w$ contains the right-hand side, i.e., the coefficients not multiplied onto any of the variables:\n\\begin{equation*}\n    \\underbrace{\\xbracketMatrixstack{\n        1& 0& 1\\\\\n        0& -3& 1\\\\\n        2& 1& 3}}_{\\A}\n    \\underbrace{\\xbracketMatrixstack{\n        x\\\\\n        y\\\\\n        z\n    }}_{\\u} = \\underbrace{\\xbracketMatrixstack{\n        6\\\\\n        7\\\\\n        15\n    }}_{\\w}\n\\end{equation*}\nThis can be solved for $\\u$ by taking the inverse of $\\A$ (see Section \\ref{sec:inverse}) and multiplying this onto $\\w$\n\\begin{equation}\n    \\u = \\A^{-1}\\w.\n\\end{equation}\nGenerally, if X unknowns are described by X equations, the unknowns can be solved for, by using this method.\n\nSolving a system of linear equations can be implemented in \\texttt{MATLAB} by using the code given in Section \\ref{sec:inverse} and multiplying this onto a vector \\texttt{w}\n\\begin{center}\n    \\texttt{u = inv(A) * w;}\n\\end{center}\nor more compactly, by using the `\\texttt{\\textbackslash}' operator:\n\\begin{center}\n    \\texttt{u = A\\textbackslash w;}\n\\end{center}\n\n\\section{Eigenvalue problems}\\label{sec:eigenValueProblems}\nA square matrix $\\A$ is characterised by its \\textit{eigenvalues} and corresponding \\textit{eigenvectors}. In a FDTD context, these are usually associated with the modes of a system, where the eigenvalues relate to the modal frequencies and the eigenvectors to the modal shapes. Section \\ref{sec:modalAnalysis} provides more information on this.\n\nTo find these characteristic values for a $p\\times p$ matrix $\\A$, an equation of the following form must be solved \n\\begin{equation}\n    \\A \\boldPhi = \\lambda \\boldPhi.\n\\end{equation}\nThis is called is an \\textit{eigenvalue problem} and has $p$ solutions (corresponding to the dimensions of $\\A$). These are the $p$\\th eigenvector $\\boldPhi_p$ and the corresponding eigenvalue $\\lambda_p$ which is calculated using\n\\begin{equation}\n    \\lambda_p = \\eig_p(\\A),\n\\end{equation}\nwhere $\\eig_p(\\cdot)$ denotes the `$p$\\th eigenvalue of'. Instead of delving too deep into eigenvalue problems and the process of how to solve them, an easy way to obtain the solutions using \\texttt{MATLAB} is provided here:\n\n\\begin{center}\n    \\texttt{[phi, lambda] = eig(A, {\\color[HTML]{A100F4}'vector'});}\n\\end{center}\nThe $p$\\th eigenvector appears in the $p$\\th column of $p\\times p$ matrix \\texttt{phi} and the corresponsding eigenvalues are given in a $p \\times 1$ column vector \\texttt{lambda}. %Note that the outcome is not necessarily sorted! To do this, do \n%\n% \\begin{center}\n%     \\begin{tabular}{l}\n%     \\texttt{[lambda, order] = sort(lambda);}\\\\\n%     \\texttt{phi = phi(:, order);}\n%     \\end{tabular}\n% \\end{center}\n", "meta": {"hexsha": "4de3f8e919fff8e0c483bd7b42f12f75ec559775", "size": 9951, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "aauPhdCollectionThesis/appendices/matrices.tex", "max_stars_repo_name": "SilvinWillemsen/phdThesis", "max_stars_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aauPhdCollectionThesis/appendices/matrices.tex", "max_issues_repo_name": "SilvinWillemsen/phdThesis", "max_issues_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aauPhdCollectionThesis/appendices/matrices.tex", "max_forks_repo_name": "SilvinWillemsen/phdThesis", "max_forks_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.693877551, "max_line_length": 469, "alphanum_fraction": 0.7161089338, "num_tokens": 2821, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8705972650509008, "lm_q1q2_score": 0.8100544158349428}}
{"text": "We assume that we want to find nearest neighbors in a space $X$ with a distance measure $\\text{dist}\\colon X\\times X \\rightarrow \\mathbb{R}$, for example the $d$-dimensional \nEuclidean space $\\mathbb{R}^d$ under Euclidean distance ($l_2$ norm), or %$d$-dimensional \nHamming space $\\{0,1\\}^d$ under Hamming distance.\n\nAn algorithm $\\mathcal{A}$ for nearest neighbor search builds a data structure DS$_\\mathcal{A}$ for a data set $S \\subset X$ of $n$ points. In a preprocessing phase, it creates DS$_\\mathcal{A}$ \nto support the following type of queries: For a query point $q \\in X$ and an integer $k$, return a \\emph{result tuple} $\\pi = (p_1, \\ldots, p_{k'})$ of $k' \\leq k$ distinct points from $S$ \nthat are ``close'' to the query $q$. Nearest neighbor search algorithms generate $\\pi$ by refining a set $C \\subseteq S$ of \ncandidate points with respect to $q$ by choosing the $k$ closest points among those using distance computations. The size of $C$ (and thus the number of distance computations) is denoted by $N$. We let $\\pi^\\ast = (p^\\ast_1, \\ldots, p^\\ast_k)$ denote the tuple containing the true $k$ nearest neighbors for $q$ in $S$ (where ties are broken arbitrarily). We \nassume in the following that all tuples are sorted according to their distance to $q$.  \n\n\\subsection{Quality Measures}\n\nWe use different notions of ``recall'' as a measure of the quality of the result returned by the algorithm. \nIntuitively, recall is the ratio of the number of points in the result tuple that are true nearest neighbors to the number $k$ of true nearest neighbors. However, this intuitive \ndefinition is fragile when distances are not distinct or when we try to add a notion of approximation to it. To avoid these issues, we use \nthe following distance-based definitions of recall and $(1+\\varepsilon)$-approximative recall, that take the distance \nof the $k$-th  true nearest neighbor as threshold distance. \n%\n\\begin{align*}\n\\text{recall}(q, \\pi, p^\\ast_k) &= \\frac{|\\{p \\text{ contained in $\\pi$} \\mid \\text{dist}(p,q) \\leq \\text{dist}(p^\\ast_k,q)\\}|}{k}\\\\\n\\text{recall}_\\varepsilon(q, \\pi, p^\\ast_k) &= \\frac{|\\{p \\text{ contained in $\\pi$} \\mid \\text{dist}(p,q) \\leq (1 + \\varepsilon) \\text{dist}(p^\\ast_k,q)\\}|}{k}, \\quad\\text{for $\\varepsilon > 0$.}\n\\end{align*}\n(If all distances are distinct, $\\text{recall}(q, \\pi, p^\\ast_k)$ matches the intuitive notion of recall.)\n\nWe note that (approximate) recall in high dimensions is sometimes criticised; see, for example, \\cite[Section 2.1]{nmslib}. We investigate the impact of approximation as part of the evaluation in Section~\\ref{sec:evaluation}, and plan to include other quality measures such as position-related measures \\cite{ZezulaSAR98} in future work. \n\n\\begin{comment}\nGiven a query point $q \\in X$ and the tuple $\\pi^\\ast$ of true nearest neighbors, we let $d_1 < \\dots < d_t$ denote the $t \\leq k$ distinct distances of the points in $\\pi^\\ast$ to \n$q$. Let $f_i$ be the number of points in $\\pi$ that have distance $d_i$ to $q$, and let $f'_t$ be the number of points in $\\pi^\\ast$ at distance $d_t$.  We define: \n\\begin{align*}\n    \\text{recall}(\\pi, \\pi^\\ast) &= \\frac{\\sum_{i = 1}^{t - 1} f_i + \\min\\{f_t, f'_t\\}}{k}.\n\\end{align*}\nNote the minimum for the last class of distances. Otherwise, the recall of a result with two points at distance $2$, where the true nearest neighbors have distance $1$ and $2$ would yield a recall of $1$.\n\nFor an approximation factor $\\varepsilon > 0$ we define an approximative version of recall as follows: We say that a point $p$ is \\emph{$\\varepsilon$-close} to $d_i$ if dist$(p, q) \\leq (1+\\varepsilon)d_i$ but dist$(p,q) > (1+\\varepsilon)d_{i - 1}$. (For sake of the definition, we set $d_0 = -1$.) Now, we let $f^\\varepsilon_i$ be the number of points in $\\pi$ that \nare $\\varepsilon$-close to $d_i$, for each $i \\in \\{1,\\ldots, t\\}$.  Furthermore, let $f'_t$ be defined as above. Then we define  \n\n\\begin{align*}\n\\text{recall}_\\varepsilon(\\pi, \\pi^\\ast) &= \\frac{\\sum_{i = 1}^{t - 1} f^\\varepsilon_i + \\min\\{f^\\varepsilon_t, f'_t\\}}{k}.\n\\end{align*}\n\nTo estimate the quality of the result without having an approximation factor $\\varepsilon$, \\cite{ZezulaSAR98} propose to look at the \\emph{relative error}\nof $\\pi$ and $\\pi^\\ast$.\n\\begin{align*}\n\\text{rel-error}(\\pi, \\pi^\\ast) &=\n\\begin{cases}\n\\frac{\\sum_{i = 1}^{k}\\text{dist}(q, p^\\ast_i)}{\\sum_{i = 1}^{k}\\text{dist}(q, p_i)}, & \\text{if $k = k'$, and} \\\\\n0, & \\text{otherwise}.\n\\end{cases}\n\\end{align*}\n%\nHere, we set the relative distance of a result having less than $k$ elements to $0$, which corresponds to filling up the left-out spots by points at distance $\\infty$ to the query.\n\nWe note that recall and relative error are up to criticism in high dimensions, see, for example the discussion in~\\cite[Section 2.1]{nmslib}. In our experiments, we did not observe that approximative recall or relative error yielded unexpected results. Nevertheless, we plan to include other quality measures such as position-related measures \\cite{ZezulaSAR98} in future work. \n\\end{comment}\n%\\matodo{Should we keep the comment about criticism of metrics? -Alec}\n\n\\begin{table}[t]\n%    \\setlength{\\tabcolsep}{0.5em} % for the horizontal padding\n%    {\\renewcommand{\\arraystretch}{1.2}% for the vertical padding\n    \\begin{tabular}{l l}\n        \\textbf{Name of Measure} & \\textbf{Computation of Measure} \\\\ \\hline \\hline\n        Index size of DS & Size of DS after preprocessing finished (in kB) \\\\\n        Index build time DS & Time it took to build DS  (in seconds) \\\\ \\hline\n        Number of distance computations &  $N$ \\\\\n        Time of a query & Time it took to run the query and generate result tuple $\\pi$ \\\\[1em]\n\\end{tabular}%}\n    \\caption{Performance measures used in the framework.}\n    \\label{tab:performance:measures}\n\\end{table}\n%\n\\subsection{Performance Measures}\n\nWith regard to the performance, we use the performance measures defined\nin Table~\\ref{tab:performance:measures}, which are divided \ninto measures of the performance of the preprocessing step,\ni.e., generation of the data structure, and measures of the performance \nof the query algorithm. With respect to the query performance, different\ncommunities are interested in different cost values. Some rely on \nactual timings of query times, where others rely on the number of distance\ncomputations. The framework can take both of\nthese measures into account. However, none of the currently included \nalgorithms report the number of distance computations.\n", "meta": {"hexsha": "eb03a48c324e09d874d0f15d3a7387a652402f28", "size": 6492, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/problem.tex", "max_stars_repo_name": "maumueller/ann-benchmarks-reproducibility", "max_stars_repo_head_hexsha": "b66ee6981fefefd4ab6e27bb4aac4ec0bfebed2a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/problem.tex", "max_issues_repo_name": "maumueller/ann-benchmarks-reproducibility", "max_issues_repo_head_hexsha": "b66ee6981fefefd4ab6e27bb4aac4ec0bfebed2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2021-01-22T16:24:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-22T15:10:57.000Z", "max_forks_repo_path": "paper/problem.tex", "max_forks_repo_name": "maumueller/ann-benchmarks-reproducibility", "max_forks_repo_head_hexsha": "b66ee6981fefefd4ab6e27bb4aac4ec0bfebed2a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 77.2857142857, "max_line_length": 378, "alphanum_fraction": 0.7171903882, "num_tokens": 1885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362486, "lm_q2_score": 0.8633916011860786, "lm_q1q2_score": 0.8099683977844169}}
{"text": "\\chapter{Model Selection}\nGoal: determine the optimum parameters or the model for a given approximation or classification problem\n\n\\section{Performance Estimation}\nMean-square error:\n$$MSE=\\frac{1}{n} \\sum_{i=1}^{n}(x_i - \\bar{x}_i)^{2}$$\nRoot-mean square error:\n$$RMSE=\\sqrt{\\frac{1}{n} \\sum_{i=1}^{n}(x_i - \\bar{x}_i)^{2}}$$\n\n\\begin{description}\n\\item[Apparent error] training error, the error on the training data\n\\item[True error] the error that will be obtained in use\n\\item[Test error] an estimate of the true error obtained by testing the network on some independent data\n\\end{description}\n\n\\noindent Validation Methods:\n\\begin{itemize}\n\\item Holdout Method: split the entire dataset into training set and testing set\n\\item Random Sampling Methods: performs $K$ data splits randomly and retrain the classifier from scratch for each split\n\\item K-fold Cross Validation: For each of $K$ experiments, use K-1 folds for training and the remaining one fold for testing\n\\item Leave one out Cross-Validation: $K=N$ in k-fold cross validation\n\\end{itemize}\n\n\\section{Three-Way Data Splits Methods}\n\\begin{description}\n\\item[Training set] examples for learning to fit the parameters\n\\item[Validation set] examples to determine the error of the classifiers\n\\item[Training + Validation set] combine examples used to re-train classifier\n\\item[Test set] examples used only to assess the performance of trained classifier\n\\end{description}\n\n\\section{Model Complexity}\nSimple model might not able to solve a task (underfitting) \\\\ \\\\\nComplex model might not able to generalize from small and noisy dataset (overfitting)", "meta": {"hexsha": "e68ee41a017620392516b08347bd5482c70f7504", "size": 1611, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter4.tex", "max_stars_repo_name": "Andyccs/neural-network-summary", "max_stars_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter4.tex", "max_issues_repo_name": "Andyccs/neural-network-summary", "max_issues_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter4.tex", "max_forks_repo_name": "Andyccs/neural-network-summary", "max_forks_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.3823529412, "max_line_length": 125, "alphanum_fraction": 0.7759155804, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.8723473680407889, "lm_q1q2_score": 0.8098949684465133}}
{"text": "\\lab{Vectorization}{Vectorization}\n\\label{lab:Python_Vectorization}\n\nIn Python, the cost of looping over a sequence is sometimes prohibitive.\nOne method for avoiding these explicit for-loops is to \\emph{vectorize} our code.\nNumPy allows operation that normally apply only to scalars to also work seamlessly with NumPy arrays.\nSome of the benefits of allowing these types of operations are concise code and fast execution.\n\n\\section*{Some Simple Examples}\n\nVectorization is a term that refers generally to eliminating for-loops in higher level languages as well as taking advantage of the capabilities of modern processors to perform the same operation on multiple numbers at once.\nWe'll start with a very simple example.\nThe following code takes the sum of the elements of a NumPy array.\n\\begin{lstlisting}\ndef pysum(A):\n    total = 0.\n    for i in xrange(A.size):\n        total += A[i]\n    return total\n\\end{lstlisting}\nAt each stage it accesses the array which involves the creation of a new Python object to contain the floating point value in that portion of the array.\nThis slows down the operations significantly.\nWe can avoid creating and deleting a Python object by doing the operations in a lower level language like C or FORTRAN.\nNumPy has already implemented many of these basic operations for us in these lower level languages.\nMany of these operations in NumPy also take advantage of multithreading, which allows for the processing of multiple array elements at once.\nIn this case, we can just use the \\li{sum()} method of arrays.\nTiming the results, we see a significant speedup.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from numpy.random import rand\n>>> A = rand(1000000)\n>>> %timeit pysum(A)\n1 loops, best of 3: 3.25 s per loop\n>>> %timeit A.sum()\n100 loops, best of 3: 12.9 ms per loop\n\\end{lstlisting}\nThis is a remarkable speedup.\nEven for such a simple operation we see a speedup of a factor of 250!\n\nWe now consider an example of an operation that is not built in to NumPy.\nConsider a two dimensional array where each row represents a point in $\\mathbb{R}^n$.\nTo make computation nice, lets say that the norm of each point is neither extremely large nor extremely small.\nThe following code normalizes the vectors represented in the array by modifying it in place:\n\\begin{lstlisting}\nfrom math import sqrt\ndef normalize1(A):\n    # for each row (point) in A\n    for i in xrange(A.shape[0]):\n        # Compute norm\n        # Start by summing\n        # squares of entries in this row.\n        total = 0.\n        for j in xrange(A.shape[1]):\n            total += A[i,j]**2\n        # take square root to get norm\n        total = sqrt(total)\n        # divide row by its norm\n        for j in xrange(A.shape[1]):\n            A[i,j] /= total\n\\end{lstlisting}\nThis problem can be vectorized in stages.\nHere we will proceed by eliminating the inner for-loops, then eliminate the outer one.\nThe inner for-loops can be eliminated like this:\n\\begin{lstlisting}\ndef normalize2(A):\n    # for each row (point) in A\n    for i in xrange(A.shape[0]):\n        # compute norm of row\n        # then divide it by its norm\n        A[i] /= sqrt((A[i]**2).sum())\n\\end{lstlisting}\nThis is much shorter, much faster, and reads quite nicely.\nTo eliminate the last for-loop we do the computation for all the rows at once.\n\\begin{lstlisting}\ndef normalize3(A):\n    # compute the norm of each row\n    # then divide each row by its norm\n    A /= np.sqrt((A**2).sum(axis=1,keepdims=True))\n\\end{lstlisting}\nAt a glance, what this line does may be a little less clear.\nIt essentially takes the square of \\li{A}, sums its columns (i.e. sums along its rows), takes the square root, then divides \\li{A} by the result by broadcasting along rows.\nThe \\li{keepdims} option is used to align the axes for broadcasting.\nAn equivalent line of code would be \\li{A /= np.sqrt((A**2).sum(axis=1).reshape((A.shape[0],1)))}.\nTiming our results we see that eliminating these loops and allowing NumPy to perform some of these operations in parallel results in a significant speedup.\n\\begin{lstlisting}\n>>> A = rand(1000000, 2) # 10^6 2D points\n>>> Ac = A.copy()\n>>> %time normalize1(A)\nWall time: 8.6 s\n>>> A[:] = Ac\n>>> %time normalize2(A)\nWall time: 14.3 s\n>>> A[:] = Ac\n>>> %time normalize3(A)\nWall time: 68 ms\n>>> A = rand(1000000, 20) # 10^6 20D points\n>>> Ac = A.copy()\n>>> %time normalize1(A)\nWall time: 58.5 s\n>>> A[:] = Ac\n>>> %time normalize2(A)\nWall time: 14.6 s\n>>> A[:] = Ac\n>>> %time normalize3(A)\nWall time: 250 ms\n>>> A = rand(50, 10000000) # 50 (10^7)D points\n>>> Ac = A.copy()\n>>> %time normalize2(A)\nWall time: 5.38 s\n>>> A[:] = Ac\n>>> %time normalize3(A)\nWall time: 5.4 s\n\\end{lstlisting}\nNotice how much the dimensions of \\li{A} affect the performance of each algorithm.\nThe first one is slowed down by its extensive use of Python objects for basic computations.\nThe second one is slowed down by the fact that it makes a new array slice for each row.\nThe third is slowed down by the fact that it must allocate a significant amount of temporary storage in memory to perform all its computations.\nA faster and more memory-efficient solution to this problem can be obtained, but it requires using another language (like C, C++, Cython, or FORTRAN) that better optimizes for-loops.\nWhen optimizing, keep in mind that it takes extra time to speed up your code.\nA partial optimization is often good enough.\nIn general, only optimize when you are sure it will be worth your time to do so.\n\n\\section*{Vectorization Techniques}\n\nHere are a few specific techniqes that can be useful in vectorization.\n\n\\begin{itemize}\n\n\\item Try to manipulate your computations mathematically.\nChanging the order or way operations are applied can (but does not always) improve speed significantly.\nA very simple example is $\\sin^2 x + \\cos^2 x = 1$.\nAnother example is that, for an orthogonal matrix, $A^{-1} = A^T$.\nA transpose is a constant time operation because all that is required is creating a new view of the same memory.\nA matrix inversion is much more expensive.\n\n\\item Try to avoid allocating unnecessary temporary arrays.\nLong algebraic expressions in NumPy often involve the creation of large amounts of temporary arrays.\nExcessive memory use limits the size of the problems your code can handle and slows it down.\nThis will be discussed further in a later lab, but be careful.\n\n\\item Eliminate the longer for-loops in Python.\nPython's loops are much slower than the loops that are run in other languages like C and FORTRAN.\nMany simple loops involving basic numeric operations can be performed in these languages through NumPy's built in functions.\nThis is an easy place to start optimizing.\n\n\\item Watch for times when broadcasting might be convenient.\nThis will save memory and let your program avoid unnecessary computations.\n\n\\item Use NumPy's universal functions.\nIt is much faster to evaluate something like \\li{np.sin(x)} than something like\n\\begin{lstlisting}\nfrom math import sin\nAsin = np.empty_like(A)\nfor i in xrange(A.size):\n    Asin[i] = sin(A[i])\n\\end{lstlisting}\n\n\\item In general, use common sense.\nThink about the operations required to perform each computation.\nTry out different implementations and compare their strengths and weaknesses, then use your best judgement about what the most common uses will be.\nWhen optimizing, make absolutely sure to test your code to verify that you are getting the expected results.\nAlso be sure to comment your code carefully so that you (or whoever has to read your code) will be able to tell what you are doing.\nOften it is more important to make code readable than it is to make it fast.\nUse your best judgment.\n\n\\end{itemize}\n\nTo demonstrate the above principles we'll consider another example.\nWe will write a function which, given two arrays \\li{A} and \\li{B} will return the distance from \\emph{each} row (considered as a vector) of \\li{A} to \\emph{every} row of \\li{B}.\nThis can be done naively using for-loops as follows:\n\\begin{lstlisting}\nfrom math import sqrt\nimport numpy as np\ndef dist1(A, B):\n    # Preallocate output array.\n    # Start with everything set to 0.\n    D = np.zeros((A.shape[0], B.shape[0]))\n    # For each row in A\n    for i in xrange(A.shape[0]):\n        # For each row in B\n        for j in xrange(B.shape[0]):\n            # For corresponding entries of\n            # the rows in A and B\n            for k in xrange(A.shape[1]):\n                # add the squared difference\n                D[i,j] += (A[i,k] - B[j,k])**2\n            # take square root after finishing sum\n            D[i,j] = sqrt(D[i,j])\n    return D\n\\end{lstlisting}\nWe can eliminate the innermost for-loop easily\n\\begin{lstlisting}\ndef dist2(A, B):\n    # Preallocate output array.\n    # This time we'll be overwriting it,\n    # so there's no need to assign it values.\n    D = np.empty((A.shape[0], B.shape[0]))\n    # For each row in A\n    for i in xrange(A.shape[0]):\n        # For each row in B\n        for j in xrange(B.shape[0]):\n            # Take the distance between the rows\n            D[i,j] = sqrt(((A[i] - B[j])**2).sum())\n    return D\n\\end{lstlisting}\nUsing the \\li{axis} argument of the \\li{sum()} method of arrays we can eliminate the next for-loop like this:\n\\begin{lstlisting}\ndef dist3(A, B):\n    # Preallocate output array\n    D = np.empty((A.shape[0], B.shape[0]))\n    # For each row in A\n    for i in xrange(A.shape[0]):\n        # Take distance from this row to each row in B.\n        # Use np.sqrt to operate on the entire array at once.\n        D[i] = np.sqrt(((A[i] - B)**2).sum(axis=1))\n    return D\n\\end{lstlisting}\nThis is a fairly nice solution.\nIt can be improved further.\nOur final solution will take advantage of the fact that $\\left(a - b\\right)^2 = a^2 + b^2 - 2 a b$.\nIt will also use array broadcasting and in place operations to avoid excess memory use.\nFor many applications the above solution is good enough, but that isn't always the case.\n\\begin{lstlisting}\ndef dist4(A, B):\n    # Use the fact that\n    # (a-b)**2 = a**2 + b**2 - 2*a*b\n    # Take squares of A and B.\n    # Reshape so broadcasting works later\n    A2 = (A**2).sum(axis=1).reshape((-1,1))\n    B2 = (B**2).sum(axis=1).reshape((1,-1))\n    # Use matrix multiplication to start\n    # computing the remaining term.\n    D = A.dot(B.T)\n    # Multiply in place to avoid\n    # allocating temporary arrays.\n    # Notice that this operates on\n    # the entire array.\n    D *= -2\n    # Broadcast to add in A2 and B2.\n    # Perform these operations in place.\n    D += A2\n    D += B2\n    # Take square root without\n    # allocating a temporary array.\n    np.sqrt(D, out=D)\n    return D\n\\end{lstlisting}\nDepending on how you are using your squared distance you could also use the fact that for $x, y \\geq 0$, $x < y$ if and only if $\\sqrt{x} < \\sqrt{y}$.\nThis would be useful if all you need to know is which distances are greater than one another.\nTiming these functions gives the following results:\n\\begin{lstlisting}[escapechar=\\@]\n>>> A = rand(500, 2)\n>>> B = rand(1000, 2)\n>>> %timeit dist1(A, B)\n1 loops, best of 3: 3.18 s per loop\n>>> %timeit dist2(A, B)\n1 loops, best of 3: 6.86 s per loop\n>>> %timeit dist3(A, B)\n10 loops, best of 3: 27.6 ms per loop\n>>> %timeit dist4(A, B)\n100 loops, best of 3: 7.51 ms per loop\n>>> A = rand(500, 20)\n>>> B = rand(1000, 20)\n>>> %timeit dist1(A, B)\n1 loops, best of 3: 23.8 s per loop\n>>> %timeit dist2(A, B)\n1 loops, best of 3: 6.89 s per loop\n>>> %timeit dist3(A, B)\n10 loops, best of 3: 60.5 ms per loop\n>>> %timeit dist4(A, B)\n100 loops, best of 3: 7.82 ms per loop\n>>> A = rand(50, 200)\n>>> B = rand(100, 200)\n>>> %timeit dist1(A, B)\n1 loops, best of 3: 2.29 s per loop\n>>> %timeit dist2(A, B)\n10 loops, best of 3: 71.9 ms per loop\n>>> %timeit dist3(A, B)\n100 loops, best of 3: 5.28 ms per loop\n>>> %timeit dist4(A, B)\n1000 loops, best of 3: 283 @$\\mu$s@ per loop\n\\end{lstlisting}\nAs you can see, the dimensions of the problem still change how long it will take.\nIn every case the final solution was the fastest.\nProper vectorization has, in this case, given a speedup by more than a factor of 1000 while still using a fairly reasonable amount of memory.\nPlots of the times for these different functions can be seen in Figure \\ref{distplot}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{distplot.pdf}\n\\caption{A plot of the times for the different degrees of vectorization for a function finding the distance between points represented as rows in two arrays. Arrays of points in $\\mathbb{R}^{10}$ were used for this computation. As this figure suggests, vectorization speeds up the computation\nby a multiplicative constant, but usually does not change the Big-Oh.}\n\\label{distplot}\n\\end{figure}\n\n\\begin{problem}\nUse vectorization techniques to obtain an optimized solution to each of the following problems.\nThey can all be done in one line.\n\n\\begin{enumerate}[a)]\n\n\\item For an array \\li{X} compute the inner product of each row with each other row.\nHint: Think matrix multiplication.\n\n\\item For an array of points \\li{X} where each row represents a point in $\\mathbb{R}^n$ compute $\\| x\\|^2$ for each row \\li{x} of \\li{X}.\nHint: Use array multiplication (element-wise multiplication) instead of matrix multiplication for this one.\n\n\\item Compute the matrix expression $v^T A v$ where $A$ is a square matrix and each column vector $v$ is stored as a row in an array \\li{V}.\nThe shapes of \\li{V} and \\li{A} are \\li{(n, d)} and \\li{(n, n)} respectively.\nHint: Matrix multiplication, then array multiplicaiton, then a sum along an axis.\n\n\\item For an array \\li{A} of size \\li{n} count the number of elements of \\li{A} less than $\\frac{1}{2}$.\nHint: Sum over a boolean array.\n\n\\item Modify an array \\li{A} of size \\li{n} and set every value less than $\\frac{1}{4}$ to $0$.\nHint: Use fancy indexing.\n\n\\item Given an array \\li{A} of shape \\li{(n, n)} representing a linear transform on $\\mathbb{R}^n$, apply \\li{A} to an array of points \\li{X} where each row of \\li{X} is a point in $\\mathbb{R}^n$.\nHint: This is all about transposes and matrix multiplication\n\n\\item For an array \\li{A} of shape \\li{(m, n, n)} which represents $m$ linear transformations from $\\mathbb{R}^n$ to $\\mathbb{R}^n$ and an array \\li{X} of shape \\li{(k, n)} whose rows represent points in $\\mathbb{R}^n$ compute the image of each row of \\li{X} under each transformation represented in \\li{A}.\nFormat the results so the have shape \\li{(m, k, n)}.\nHint: Do a matrix multiplication, then use the \\li{swapaxes()} method of an array to rearrange the axes properly.\n\n\\item Let \\li{A} be an array of shape \\li{(m, n)} and \\li{B} be an array of shape \\li{m}.\nTake the sum of every element of \\li{A} that lies in a row of \\li{A} with a first element that is less than $\\frac{1}{2}$.\nHint: Use matrix multiplication by a row vector of boolean values.\n\n\\item For an array \\li{P} of shape \\li{n} and a boolean array of shape \\li{D} compute the array \\li{A} such that \\li{A[i]} is $\\sum_{D[i,j] = True} \\left( P[i] - P[j]\\right)$.\nHint: For each \\li{i} let $k_i = \\sum_{D[i,j] = True} 1$ (the number of \\li{True} values , then the \\li{i}'th entry of \\li{A} should be $k_i * P[i] - \\sum_{D[i,j] = True} P[j]$.\nThe first part of this expression can be evaluated by array multiplication and a sum across an axis.\nThe second part can be evaluated with matrix multiplication.\n\n\\item Shuffle a one-dimensional array of values the way you would shuffle a deck of cards, i.e. separate it into two stacks, then take every other item from each of the two stacks.\nHint: This can be done with array slicing and multiple assignment (i.e. \\li{a, b = c, d}).\nTo make the assignment work nicely with the slicing, be sure to use copies of both slices.\nNote: In general this isn't how you would do this.\nA purely random arrangement of rows can be obtained using \\li{numpy.random.shuffle()}.\n\n\\end{enumerate}\n\\end{problem}\n\n\\section*{Image Editor}\nAn image is often represented as a 3D array where the first and second dimensions are the height and width respectively and the third dimension represents the intensity of each of three color channels: red, green, and blue.\nThe code below can be used to read and display images in Python.\n\\begin{lstlisting}\nimport matplotlib.pyplot as plt\nimg = plt.imread(<image-file>)\nplt.imshow(img)\nplt.show()\n\\end{lstlisting}\n\nMatplotlib can read in PNG images on its own, otherwise it will read in images using the Python Image Library.\nDepending on the format of the image, it may be read as an array of floating point values between 0 and 1 or it may be read as an array of integer values between 0 and 255.\nIn this lab we will assume the former. Load the image provided with the lab, entitled `musician.png':\n\\begin{lstlisting}\nimg = plt.imread('musician.png')\n\\end{lstlisting}\nThere is some extra data in this image that we do not need, so throw it out, and view the image:\n\\begin{lstlisting}\nimg = img[:,:,:-1]\nplt.imshow(img)\nplt.show()\n\\end{lstlisting}\n\n%How is this problem different from the grayscale problem below?\n%\\begin{problem}\n%Use vectorization techniques to obtain an optimized solution to each of the following problems.\n%They can all be done in one line.\n%\\begin{enumerate}[a)]\n%\n%\\item Given an array representing a color image, make an array representing a black and white image where the black and white value is the average of each of the color values.\n%Hint: see the \\li{mean()} method of arrays.\n%\n%\\item For an array representing a color image calculate the absolute value of the difference between each color value and the average value for each pixel.\n%Hint: pass the \\li{keepdims=True} argument to the \\li{mean} method so that broadcasting works properly.\n%\n%\\end{enumerate}\n%\\end{problem}\n\n\\begin{problem}\nWrite a function that edits an array representing an image. The function should take as input\nan array of shape (no. of rows, no. of columns, no. of color channels) and should then plot the edited\nimage. Include options that allow you to  invert the image, change it to grayscale, or add a motion blur (definitions below).\nNote that the shape of a grayscale image is (no. of rows, no. of columns), and to plot a\ngrayscale image \\li{A} you need to use the command \\li{plt.imshow(A, cmap=plt.cm.Greys_r)}.\n\\end{problem}\n\n\\begin{itemize}\n\\item Invert:\nEvery color value for every pixel is changed to its inverse value.\nFor example, 0.0 becomes 1.0 and 0.4 becomes 0.6.\nRemember that the minimum color value is 0.0 and the maximum is 1.0.\n\n\\begin{figure}[ht]\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{Original.jpg}\n\\end{minipage}\n\\hspace{0.1cm}\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{Invert.jpg}\n\\end{minipage}\n\\caption{Example of an inverted image}\n\\end{figure}\n\n\\item Grayscale:\nTo convert a \\li{(n,m,3)} image \\li{A} to grayscale, you will create a \\li{(n,m)} image \\li{B} such that \\li{B[i,j]} is the average of the values \\li{A[i,j,0], A[i,j,1], A[i,j,2]}.\nFor example, if the $i,j$ pixel values are Red: 0.8, Green:, 0.2 Blue: 0.5, we set the\ncorresponding grayscale pixel value to $\\frac{0.8+0.2+0.5}{3} = 0.5$.\nHint: use the \\li{axis} argument to the mean method of NumPy arrays.\n\n\\begin{figure}[ht]\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{Original.jpg}\n\\end{minipage}\n\\hspace{0.1cm}\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{Gray.jpg}\n\\end{minipage}\n\\caption{Example of an image that is grayscaled}\n\\end{figure}\n\n\\item Motion Blur:\nAn additional parameter $n>0$ will be used for motion blur.\nThe value of each color of each pixel is the average of that color value for $n$ pixels (from the current pixel to $n-1$ beyond) horizontally.\nSo pixel \\li{[x,y,0]} would turn into the average of pixel \\li{[x,y,0]} through pixel \\li{[x,y+n-1,0]}.\nNote: You will need to use one for-loop here.\nBe sure to account for the situations where one or more of the values used in the computing the average do not exist.\nFor example, if an image has width $w$ and we are considering the pixel on row $r$, column $c$, if $c + n \\ge w$, then we only average the pixels up to $w$.\nProper array slicing should take care of this case without any extra code.\n\n\\begin{figure}[ht]\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{Original.jpg}\n\\end{minipage}\n\\hspace{0.1cm}\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{Motion.jpg}\n\\end{minipage}\n\\caption{Example of an image with a motion blur of 60}\n\\end{figure}\n\n\\end{itemize}\n\n", "meta": {"hexsha": "4fcd0cccabe0424709dbc6aa7c797566a61b791d", "size": 20538, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/Vectorization/Vectorization.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Python/Vectorization/Vectorization.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Python/Vectorization/Vectorization.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 45.64, "max_line_length": 307, "alphanum_fraction": 0.7174505794, "num_tokens": 5614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.9161096198879968, "lm_q1q2_score": 0.8098768959641212}}
{"text": "\\documentclass[../main.tex]{subfiles}\n \n\\begin{document}\n\n% The asterix after \\subsection disables section numbering\n\\subsection*{Problem 2 Part A}\nDetermine the combination of ingredients that minimizes calories but meets all nutritional requirements.\n\n\\begin{enumerate}[i.]\n\t\\item Formulate the problem as a linear program with an objective function and all constraints.\n\n\tWe can formulate this problem as the following linear program:\n\n\t\\begin{equation*}\n\t\t\\begin{aligned}\n\t\t\t% Minimize calories\n\t\t\t& \\text{minimize} & & 21 \\cdot w_{\\text{tomato}} + 16 \\cdot  w_{\\text{lettuce}} + 40 \\cdot w_{\\text{spinach}} + 41 \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 585 \\cdot w_{\\text{sunflower seed}} + 120 \\cdot w_{\\text{smoked tofu}} + 164 \\cdot w_{\\text{chickpea}} + 884 \\cdot w_{\\text{oil}}\\\\ \\\\\n\t\t\t% Subject to >= 15g protein\n\t\t\t& \\text{subject to} & & -0.85 \\cdot w_{\\text{tomato}} - 1.62 \\cdot  w_{\\text{lettuce}} - 2.86 \\cdot w_{\\text{spinach}} - 0.93 \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & - 23.4 \\cdot w_{\\text{sunflower seed}} - 16 \\cdot w_{\\text{smoked tofu}} - 9 \\cdot w_{\\text{chickpea}} - 0 \\cdot w_{\\text{oil}} \\leq -15, \\\\ \\\\\n\t\t\t% Subject to >= 2g fat\n\t\t\t& & & - 0.33 \\cdot w_{\\text{tomato}} - 0.2 \\cdot  w_{\\text{lettuce}} - 0.39 \\cdot w_{\\text{spinach}} - 0.24  \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & - 48.7 \\cdot w_{\\text{sunflower seed}} - 5 \\cdot w_{\\text{smoked tofu}} - 2.6 \\cdot w_{\\text{chickpea}} - 100 \\cdot w_{\\text{oil}} \\leq -2, \\\\ \\\\\n\t\t\t% Subject to <= 8g fat\n\t\t\t& & & 0.33 \\cdot w_{\\text{tomato}} + 0.2 \\cdot  w_{\\text{lettuce}} + 0.39 \\cdot w_{\\text{spinach}} + 0.24  \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 48.7 \\cdot w_{\\text{sunflower seed}} + 5 \\cdot w_{\\text{smoked tofu}} + 2.6 \\cdot w_{\\text{chickpea}} + 100 \\cdot w_{\\text{oil}} \\leq 8, \\\\ \\\\\n\t\t\t% Subject to >= 4g carbohydrates\n\t\t\t& & & - 4.64 \\cdot w_{\\text{tomato}} - 2.37 \\cdot  w_{\\text{lettuce}} - 3.63 \\cdot w_{\\text{spinach}} - 9.58  \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & - 15 \\cdot w_{\\text{sunflower seed}} - 3 \\cdot w_{\\text{smoked tofu}} - 27 \\cdot w_{\\text{chickpea}} - 0 \\cdot w_{\\text{oil}} \\leq -4, \\\\ \\\\\n\t\t\t% Subject to <= 200 mg sodium\n\t\t\t& & & 9 \\cdot w_{\\text{tomato}} + 28 \\cdot  w_{\\text{lettuce}} + 65 \\cdot w_{\\text{spinach}} + 69  \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 3.8 \\cdot w_{\\text{sunflower seed}} + 120 \\cdot w_{\\text{smoked tofu}} + 78 \\cdot w_{\\text{chickpea}} + 0 \\cdot w_{\\text{oil}} \\leq 200, \\\\ \\\\\n\t\t\t% Subject to >= 40% leafy greens by mass\n\t\t\t& & & 0.4 \\cdot w_{\\text{tomato}} - 0.6 \\cdot  w_{\\text{lettuce}} - 0.6 \\cdot w_{\\text{spinach}} + 0.4 \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 0.4 \\cdot w_{\\text{sunflower seed}} + 0.4 \\cdot w_{\\text{smoked tofu}} + 0.4 \\cdot w_{\\text{chickpea}} + 0.4 \\cdot w_{\\text{oil}} \\leq 0, \\\\ \\\\\n\t\t\t% Subject to weights greater than or equal to zero\n\t\t\t& & & - w_{\\text{tomato}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{lettuce}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{spinach}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{carrot}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{sunflower seed}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{smoked tofu}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{chickpea}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{oil}} \\leq 0 \\\\\n\t\t\\end{aligned}\n\t\\end{equation*}\n\n\twhere the $w$ parameters are the weight of each ingredient, in 100's of grams. The equations, from top to bottom, are:\n\t\\begin{enumerate}[1)]\n\t\t\\item Minimize total calories\n\t\t\\item Subject to total protein $\\geq$ 15 grams\n\t\t\\item Subject to total fat $\\geq$ 2 grams\n\t\t\\item Subject to total fat $\\leq$ 8 grams\n\t\t\\item Subject to total carbohydrates $\\geq$ 4 grams\n\t\t\\item Subject to total sodium $\\leq$ 200 milligrams\n\t\t\\item Subject to total leafy green mass $\\geq$ 40\\% of total mass\n\t\t\\item Subject to individual ingredient weights $\\geq$ 0\n\t\\end{enumerate}\n\n\t\\item Determine the optimal solution for the linear program using any software you want. Include a copy of the code/file in the report.\n\n\tThe following MATLAB code was used to generate the solution: \\\\\n\n\t\\lstinputlisting{../problem_two/problem2_partA.m}\n\n\twhere \\verb|X| stores the resulting weights of ingredients (in 100's of grams), \\verb|FVAL| stores the minimized number of calories, and \\verb|EXITFLAG| stores the status of the \\verb|linprog| optimization.\n\n\t\\item What is the cost of the low calorie salad?\n\n\tThe optimal low calorie salad contains the following weights of ingredients (in 100's of grams):\n\n\t\\begin{equation*}\n\t\t\\begin{aligned}\n\t\t\tw_{\\text{tomato}} &\\approx 0 \\\\\n\t\t\tw_{\\text{lettuce}} &\\approx 0.5855 \\\\\n\t\t\tw_{\\text{spinach}} &\\approx 0 \\\\\n\t\t\tw_{\\text{carrot}} &\\approx 0 \\\\\n\t\t\tw_{\\text{sunflower seed}} &\\approx 0 \\\\\n\t\t\tw_{\\text{smoked tofu}} &\\approx 0.8782 \\\\\n\t\t\tw_{\\text{chickpea}} &\\approx 0 \\\\\n\t\t\tw_{\\text{oil}} &\\approx 0 \\\\\n\t\t\\end{aligned}\n\t\\end{equation*}\n\n\tThe optimal low calorie salad costs approximately \\$2.33. It contains approximately $114.75$ kcal\n\\end{enumerate}\n\n\\newpage\n\n\\subsection*{Problem 2 Part B}\nVeronica realizes that it is also important to minimize the cost associated with the new salad. Unfortunately some of the ingredients can be expensive. Determine the combination of ingredients that minimizes cost.\n\n\\begin{enumerate}[i.]\n\t\\item Formulate the problem as a linear program with an objective function and all constraints.\n\n\tWe can formulate this problem as the following linear program:\n\n\t\\begin{equation*}\n\t\t\\begin{aligned}\n\t\t\t% Minimize calories\n\t\t\t& \\text{minimize} & & 1 \\cdot w_{\\text{tomato}} + 0.75 \\cdot  w_{\\text{lettuce}} + 0.5 \\cdot w_{\\text{spinach}} + 0.5 \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 0.45 \\cdot w_{\\text{sunflower seed}} + 2.15 \\cdot w_{\\text{smoked tofu}} + 0.95 \\cdot w_{\\text{chickpea}} + 2.00 \\cdot w_{\\text{oil}}\\\\ \\\\\n\t\t\t% Subject to >= 15g protein\n\t\t\t& \\text{subject to} & & -0.85 \\cdot w_{\\text{tomato}} - 1.62 \\cdot  w_{\\text{lettuce}} - 2.86 \\cdot w_{\\text{spinach}} - 0.93 \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & - 23.4 \\cdot w_{\\text{sunflower seed}} - 16 \\cdot w_{\\text{smoked tofu}} - 9 \\cdot w_{\\text{chickpea}} - 0 \\cdot w_{\\text{oil}} \\leq -15, \\\\ \\\\\n\t\t\t% Subject to >= 2g fat\n\t\t\t& & & - 0.33 \\cdot w_{\\text{tomato}} - 0.2 \\cdot  w_{\\text{lettuce}} - 0.39 \\cdot w_{\\text{spinach}} - 0.24  \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & - 48.7 \\cdot w_{\\text{sunflower seed}} - 5 \\cdot w_{\\text{smoked tofu}} - 2.6 \\cdot w_{\\text{chickpea}} - 100 \\cdot w_{\\text{oil}} \\leq -2, \\\\ \\\\\n\t\t\t% Subject to <= 8g fat\n\t\t\t& & & 0.33 \\cdot w_{\\text{tomato}} + 0.2 \\cdot  w_{\\text{lettuce}} + 0.39 \\cdot w_{\\text{spinach}} + 0.24  \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 48.7 \\cdot w_{\\text{sunflower seed}} + 5 \\cdot w_{\\text{smoked tofu}} + 2.6 \\cdot w_{\\text{chickpea}} + 100 \\cdot w_{\\text{oil}} \\leq 8, \\\\ \\\\\n\t\t\t% Subject to >= 4g carbohydrates\n\t\t\t& & & - 4.64 \\cdot w_{\\text{tomato}} - 2.37 \\cdot  w_{\\text{lettuce}} - 3.63 \\cdot w_{\\text{spinach}} - 9.58  \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & - 15 \\cdot w_{\\text{sunflower seed}} - 3 \\cdot w_{\\text{smoked tofu}} - 27 \\cdot w_{\\text{chickpea}} - 0 \\cdot w_{\\text{oil}} \\leq -4, \\\\ \\\\\n\t\t\t% Subject to <= 200 mg sodium\n\t\t\t& & & 9 \\cdot w_{\\text{tomato}} + 28 \\cdot  w_{\\text{lettuce}} + 65 \\cdot w_{\\text{spinach}} + 69  \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 3.8 \\cdot w_{\\text{sunflower seed}} + 120 \\cdot w_{\\text{smoked tofu}} + 78 \\cdot w_{\\text{chickpea}} + 0 \\cdot w_{\\text{oil}} \\leq 200, \\\\ \\\\\n\t\t\t% Subject to >= 40% leafy greens by mass\n\t\t\t& & & 0.4 \\cdot w_{\\text{tomato}} - 0.6 \\cdot  w_{\\text{lettuce}} - 0.6 \\cdot w_{\\text{spinach}} + 0.4 \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 0.4 \\cdot w_{\\text{sunflower seed}} + 0.4 \\cdot w_{\\text{smoked tofu}} + 0.4 \\cdot w_{\\text{chickpea}} + 0.4 \\cdot w_{\\text{oil}} \\leq 0, \\\\ \\\\\n\t\t\t% Subject to weights greater than or equal to zero\n\t\t\t& & & - w_{\\text{tomato}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{lettuce}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{spinach}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{carrot}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{sunflower seed}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{smoked tofu}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{chickpea}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{oil}} \\leq 0 \\\\\n\t\t\\end{aligned}\n\t\\end{equation*}\n\n\twhere the $w$ parameters are the weight of each ingredient, in 100's of grams. The equations, from top to bottom, are:\n\t\\begin{enumerate}[1)]\n\t\t\\item Minimize total cost\n\t\t\\item Subject to total protein $\\geq$ 15 grams\n\t\t\\item Subject to total fat $\\geq$ 2 grams\n\t\t\\item Subject to total fat $\\leq$ 8 grams\n\t\t\\item Subject to total carbohydrates $\\geq$ 4 grams\n\t\t\\item Subject to total sodium $\\leq$ 200 milligrams\n\t\t\\item Subject to total leafy green mass $\\geq$ 40\\% of total mass\n\t\t\\item Subject to individual ingredient weights $\\geq$ 0\n\t\\end{enumerate}\n\n\t\\item Determine the optimal solution for the linear program using any software you want. Include a copy of the code/file in the report.\n\n\tThe following MATLAB code was used to generate the solution: \\\\\n\n\t\\lstinputlisting{../problem_two/problem2_partB.m}\n\n\twhere \\verb|X| stores the resulting weights of ingredients (in 100's of grams), \\verb|FVAL| stores the minimized number of calories, and \\verb|EXITFLAG| stores the status of the \\verb|linprog| optimization.\n\n\t\\item How many calories are in the low cost salad?\n\n\tThe optimal low cost salad contains the following weights of ingredients (in 100's of grams):\n\n\t\\begin{equation*}\n\t\t\\begin{aligned}\n\t\t\tw_{\\text{tomato}} &\\approx 0 \\\\\n\t\t\tw_{\\text{lettuce}} &\\approx 0 \\\\\n\t\t\tw_{\\text{spinach}} &\\approx 0.8323 \\\\\n\t\t\tw_{\\text{carrot}} &\\approx 0 \\\\\n\t\t\tw_{\\text{sunflower seed}} &\\approx 0.0961 \\\\\n\t\t\tw_{\\text{smoked tofu}} &\\approx 0 \\\\\n\t\t\tw_{\\text{chickpea}} &\\approx 1.1524 \\\\\n\t\t\tw_{\\text{oil}} &\\approx 0 \\\\\n\t\t\\end{aligned}\n\t\\end{equation*}\n\n\tThe optimal low cost salad costs approximately \\$1.55. It contains approximately $278.49$ kcal\n\n\n\\end{enumerate}\n\\newpage\n\n\\subsection*{Problem 2 Part C}\nCompare the results from part A and B. Veronica\u2019s goal is to create a Very Veggie Salad that is both low calorie and low cost. She would like to sell the salad for \\$5.00 and still have a profit of at least \\$3.00. However if she can advertise that the salad has under 250 calories then she may be able to sell more.\n\n\\begin{enumerate}[i.]\n\t\\item Suggest some possible ways that she select a combination of ingredients that is \u201cnear optimal\u201d for both objectives. This is a type of multi-objective optimization.\n\n\tWhat Veronica should do is attempt to find a ``pareto optimal\" solution that accounts for both calories and cost. In order to do this, she should introduce a new parameter $\\lambda$ to her optimization formulation. In essence, she would like to:\n\n\t\\begin{equation*}\n\t\t\\begin{aligned}\n\t\t\t% Minimize price and calories\n\t\t\t&\\text{minimize} & & (1 - \\lambda) \\cdot \\text{CALORIES} + \\lambda \\cdot \\text{PRICE} \\\\\n\t\t\t&\\text{subject to} & & \\text{CONSTRAINTS}\n\t\t\\end{aligned}\n\t\\end{equation*}\n\n\tfor values of $\\lambda$ between 0 and 1. When $\\lambda = 0$, she will be finding the minimum calorie combination of ingredients. When $\\lambda = 1$, she will be finding the minimum price combination of ingredients. For all values of $\\lambda$ inbetween, she will be finding the ``pareto optimal\" combination of ingredients. So, she should solve the optimization problem for values of $\\lambda$ between 0 and 1. She can then examine these pareto optimal combinations of ingredients to determine which would best meet her goals of \\$3.00 profit and under 250 calories. \\\\\n\n\tWe can express this as the following linear program:\n\n\t\\begin{equation*}\n\t\t\\begin{aligned}\n\t\t\t% Minimize calories\n\t\t\t& \\text{minimize} & & (1 - \\lambda) \\cdot (21 \\cdot w_{\\text{tomato}} + 16 \\cdot  w_{\\text{lettuce}} + 40 \\cdot w_{\\text{spinach}} + 41 \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 585 \\cdot w_{\\text{sunflower seed}} + 120 \\cdot w_{\\text{smoked tofu}} + 164 \\cdot w_{\\text{chickpea}} + 884 \\cdot w_{\\text{oil}} )\\\\ \n\t\t\t& & & + \\lambda \\cdot (1 \\cdot w_{\\text{tomato}} + 0.75 \\cdot  w_{\\text{lettuce}} + 0.5 \\cdot w_{\\text{spinach}} + 0.5 \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 0.45 \\cdot w_{\\text{sunflower seed}} + 2.15 \\cdot w_{\\text{smoked tofu}} + 0.95 \\cdot w_{\\text{chickpea}} + 2.00 \\cdot w_{\\text{oil}} )\\\\ \\\\\n\t\t\t% Subject to >= 15g protein\n\t\t\t& \\text{subject to} & & -0.85 \\cdot w_{\\text{tomato}} - 1.62 \\cdot  w_{\\text{lettuce}} - 2.86 \\cdot w_{\\text{spinach}} - 0.93 \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & - 23.4 \\cdot w_{\\text{sunflower seed}} - 16 \\cdot w_{\\text{smoked tofu}} - 9 \\cdot w_{\\text{chickpea}} - 0 \\cdot w_{\\text{oil}} \\leq -15, \\\\ \\\\\n\t\t\t% Subject to >= 2g fat\n\t\t\t& & & - 0.33 \\cdot w_{\\text{tomato}} - 0.2 \\cdot  w_{\\text{lettuce}} - 0.39 \\cdot w_{\\text{spinach}} - 0.24  \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & - 48.7 \\cdot w_{\\text{sunflower seed}} - 5 \\cdot w_{\\text{smoked tofu}} - 2.6 \\cdot w_{\\text{chickpea}} - 100 \\cdot w_{\\text{oil}} \\leq -2, \\\\ \\\\\n\t\t\t% Subject to <= 8g fat\n\t\t\t& & & 0.33 \\cdot w_{\\text{tomato}} + 0.2 \\cdot  w_{\\text{lettuce}} + 0.39 \\cdot w_{\\text{spinach}} + 0.24  \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 48.7 \\cdot w_{\\text{sunflower seed}} + 5 \\cdot w_{\\text{smoked tofu}} + 2.6 \\cdot w_{\\text{chickpea}} + 100 \\cdot w_{\\text{oil}} \\leq 8, \\\\ \\\\\n\t\t\t% Subject to >= 4g carbohydrates\n\t\t\t& & & - 4.64 \\cdot w_{\\text{tomato}} - 2.37 \\cdot  w_{\\text{lettuce}} - 3.63 \\cdot w_{\\text{spinach}} - 9.58  \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & - 15 \\cdot w_{\\text{sunflower seed}} - 3 \\cdot w_{\\text{smoked tofu}} - 27 \\cdot w_{\\text{chickpea}} - 0 \\cdot w_{\\text{oil}} \\leq -4, \\\\ \\\\\n\t\t\t% Subject to <= 200 mg sodium\n\t\t\t& & & 9 \\cdot w_{\\text{tomato}} + 28 \\cdot  w_{\\text{lettuce}} + 65 \\cdot w_{\\text{spinach}} + 69  \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 3.8 \\cdot w_{\\text{sunflower seed}} + 120 \\cdot w_{\\text{smoked tofu}} + 78 \\cdot w_{\\text{chickpea}} + 0 \\cdot w_{\\text{oil}} \\leq 200, \\\\ \\\\\n\t\t\t% Subject to >= 40% leafy greens by mass\n\t\t\t& & & 0.4 \\cdot w_{\\text{tomato}} - 0.6 \\cdot  w_{\\text{lettuce}} - 0.6 \\cdot w_{\\text{spinach}} + 0.4 \\cdot w_{\\text{carrot}} \\\\\n\t\t\t& & & + 0.4 \\cdot w_{\\text{sunflower seed}} + 0.4 \\cdot w_{\\text{smoked tofu}} + 0.4 \\cdot w_{\\text{chickpea}} + 0.4 \\cdot w_{\\text{oil}} \\leq 0, \\\\ \\\\\n\t\t\t% Subject to weights greater than or equal to zero\n\t\t\t& & & - w_{\\text{tomato}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{lettuce}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{spinach}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{carrot}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{sunflower seed}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{smoked tofu}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{chickpea}} \\leq 0 \\\\\n\t\t\t& & & - w_{\\text{oil}} \\leq 0 \\\\\n\t\t\\end{aligned}\n\t\\end{equation*}\n\n\t\\item What combination of ingredient would you suggest and what is the associated cost and calorie.\n\n\tVarying $\\lambda$ between 0 and 1, and solving the resulting optimization problems, we obtain the following pareto optimal combinations of total calories and total price:\n\n\t\\begin{center}\n\t\t\\includegraphics{../problem_two/problem2_partC}\n\t\\end{center}\n\n\tBased on this result, I would suggest the following combination of ingredients:\n\n\t\\begin{equation*}\n\t\t\\begin{aligned}\n\t\t\tw_{\\text{tomato}} &\\approx 0 \\\\\n\t\t\tw_{\\text{lettuce}} &\\approx 0 \\\\\n\t\t\tw_{\\text{spinach}} &\\approx 0.5346 \\\\\n\t\t\tw_{\\text{carrot}} &\\approx 0 \\\\\n\t\t\tw_{\\text{sunflower seed}} &\\approx 0.0865 \\\\\n\t\t\tw_{\\text{smoked tofu}} &\\approx 0.7154 \\\\\n\t\t\tw_{\\text{chickpea}} &\\approx 0 \\\\\n\t\t\tw_{\\text{oil}} &\\approx 0 \\\\\n\t\t\\end{aligned}\n\t\\end{equation*}\n\n\tThis pareto optimal salad costs approximately \\$1.84. It contains approximately $157.86$ kcal. This meets both of Veronicas goals.\n\n\t\\item Note: There is not one \u201cright\u201d answer. Discuss how you derived your solution.\n\n\tThe following MATLAB code was used to derive the answer, based on the discussion above.\n\n\t\\newpage\n\n\t\\lstinputlisting{../problem_two/problem2_partC.m}\n\n\n\\end{enumerate}\n\n\\end{document}", "meta": {"hexsha": "309e6dc07035bc3d704e4084410cde8061dba11c", "size": 15586, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem_two/problem_two.tex", "max_stars_repo_name": "OSU-CS-325/Project_Three_LP", "max_stars_repo_head_hexsha": "88301202f62a44a1b17a98bbc33c0efdb4a9d458", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "problem_two/problem_two.tex", "max_issues_repo_name": "OSU-CS-325/Project_Three_LP", "max_issues_repo_head_hexsha": "88301202f62a44a1b17a98bbc33c0efdb4a9d458", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problem_two/problem_two.tex", "max_forks_repo_name": "OSU-CS-325/Project_Three_LP", "max_forks_repo_head_hexsha": "88301202f62a44a1b17a98bbc33c0efdb4a9d458", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-24T18:35:38.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-24T18:35:38.000Z", "avg_line_length": 57.7259259259, "max_line_length": 570, "alphanum_fraction": 0.6395483126, "num_tokens": 5832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476385, "lm_q2_score": 0.8887588001219789, "lm_q1q2_score": 0.8098189921964952}}
{"text": "\\subsection{Why Can't We Just Modify the Feature Vector?}\nIn some data science and machine learning circles, a common ad hoc way to avoid centering data prior to solving the least squares problem is to append a constant dimension to the feature vector, such that the new feature vectors are given by \n\\begin{equation}\n  \\lambda'_t = \n  \\begin{bmatrix}\n    \\lambda_t & 1\n  \\end{bmatrix}\n\\end{equation}\nIntuitively, the intention of this technique is to add an additional offset\nparameter $\\theta_0$ to the least squares estimated parameters, which should\nthen capture the constant offset term $\\mu_y - \\mu_x \\hat\\Theta$ which we\ncalculated analytically above. In practice, though, this technique gives rise\nto an entire one-dimensional subspace of possible solutions to the\nleast-squares problem, as can be shown using a bit of linear algebra, where the\nactual solution returned by solving the normal equations is determined by the\nparticular numerical algorithm used to invert the covariance matrix. The\naddition of a constant feature to all input data makes the sample covariance\nmatrix $X_T^\\top X_T$ low-rank, so that the inverse $(X_T^\\top X_T)^{-1}$ is\nill-posed and gives rise to a subspace of possible solutions. The best solution\nof this subspace in expectation is precisely the one derived in\nSection~\\ref{sec:uncentered}, but the feature vector augmentation technique\ngives no guarantees of recovering this solution.\n\n\\subsection{Initializing $P_T$ and $Q_T$ and Connections to Ridge Regression}\nThe update equations derived in Sections~\\ref{sec:centered}\nand~\\ref{sec:uncentered} tell use how to move from the least-squares solution\nat timestep $T-1$ to the least-squares solution at timestep $T$, but they don't\ntell us how the relevant matrices should be initialized. For all involved\nmatrices except $P_T$ (or $Q_T$, in the uncentered case), it is reasonable to\ninitialize with matrices whose elements are all 0. If we initialize $P_T$ or\n$Q_T$ to zero matrices, however, Equations~\\ref{eq:centered_p_update} and~\\ref{eq:uncentered_Q_T_update} show that these matrices will never be updated at all (since the update equations are multiplicative in $P_T$ and $Q_T$, respectively). \n\nThis means that we need to initialize $P_T$ and $Q_T$ to some nonzero matrix\nbefore beginning the recursive least squares algorithm. In practice, this\ninitialization matrix is usually chosen as some multiple of the identity, so\nthat $P_0 = \\alpha I$. This has a significant effect on the computed $\\hat\\Theta$, however, as can be seen if we examine the real normal equation in this situation:\n\\begin{equation}\n  \\hat\\Theta_{REAL}(T) = (X_T^\\top X_T + \\frac{1}{\\alpha} I)^{-1}X_T^\\top Y\n\\end{equation}\nThis is precisely the solution for the ridge regression problem (also known as\n$l^2$ regularized least squares or Tikhonov regularization) with regularization\ncoefficient $\\frac{1}{\\alpha}$. Thus any practical implementation of recursive\nleast squares which keeps around an estimate of the inverse covariance matrix\n($P_T$ or $Q_T$ in our notation) is in fact computing a ridge regression\nestimator. This explains the common advice to use $\\alpha \\approx 10^6$; a\nlarge value for $\\alpha$ corresponds to a low amount of $l^2$ regularization,\nand hence closer approximation to the unregularized least squares solution.\n\n\\subsection{Forgetting Factors for Time-Varying Systems}\nWhen the relationship between $\\varphi_t$ and $y_t$ is assumed to change over\ntime, we need some way of prioritizing recent data over historical data in\nrecursive least squares. This is commonly done via a ``forgetting factor''\n$\\lambda \\in [0, 1]$. $\\lambda$ is used to give exponentially smaller weight to\nolder samples in the regression in a way that can be intuitively explained by\nits extremal values: when $\\lambda = 0$ no datum prior to the current timestep\nis taken into account, and when $\\lambda = 1$ we recover the recursive least\nsquares algorithm derived above. Common values of $\\lambda$ lie between $0.95$\nand $0.99$.\n\nThe way that this is practically done is by reweighting the rows of the data matrix $X$ and target matrix $Y$. Where previously these were defined as simply the vertically stacked samples, we now define them as \n\\begin{align}\n  &X = \n  \\begin{bmatrix}\n    \\varphi_T \\\\\n    \\lambda \\varphi_{T-1} \\\\\n    \\vdots \\\\\n    \\lambda^{T - 2} \\varphi_2 \\\\\n    \\lambda^{T - 1} \\varphi_1\n  \\end{bmatrix}\n  &Y = \n  \\begin{bmatrix}\n    y_T \\\\\n    \\lambda y_{T-1} \\\\\n    \\vdots \\\\\n    \\lambda^{T - 2} y_2 \\\\\n    \\lambda^{T - 1} y_1\n  \\end{bmatrix}\n\\end{align}\nSimilarly we redefine $\\mu_x(T)$ and $\\mu_y(T)$ to be the means of these new matrices:\n\\begin{align}\n  &\\mu_x(T) = \\frac{1}{T}\\sum_{t=1}^T \\lambda^{T - t} \\varphi_t\n  &\\mu_y(T) = \\frac{1}{T}\\sum_{t=1}^T \\lambda^{T - t} y_t\n\\end{align}\nBy carrying this new $X$ and $Y$ through the same derivation as in the uncentered $X$, uncentered $Y$ case above, we can derive analogous matrices and update rules:\n\\begin{align}\n  &C_T := \\frac{1}{\\lambda^2T^2}\n  \\begin{bmatrix}\n    (2T - 1)^2 - 2T^2 & -(2T - 1)(T - 1) \\\\\n    -(2T - 1)(T - 1) & (T - 1)^2\n  \\end{bmatrix} \n  &V_T := \n  \\begin{bmatrix}\n    \\lambda\\mu_x(T - 1) \\\\\n    \\varphi_T\n  \\end{bmatrix} \\\\\n  &R_T := V_T^\\top C_T V_T\n\\end{align}\n\\begin{equation}\n  Q_T = \\frac{1}{\\lambda^2} \\left[Q_{T-1} - Q_{T-1}V_T^\\top\\left(C_T^{-1} + V_TQ_{T-1}V_T^\\top\\right)^{-1}V_TQ_{T-1}\\right]\n\\end{equation}\n\\begin{align}\n  \\hat\\Theta_{RAW}(T) &= \\hat\\Theta_{RAW}(T-1) + Q_T\\left[\\varphi_T^\\top y_T - R_T\\hat\\Theta_{RAW}(T-1)\\right]\\\\\n  \\hat\\Theta_{LS}(T) &= \\hat\\Theta_{RAW}(T) - (2T - 1)Q_T\\mu_x(T)^\\top \\mu_y(T)\n\\end{align}\n\nOne final note is in order about the recursive least squares algorithm with\n$\\lambda$-forgetting: The connection that we drew earlier between the\ninitialization of $Q_T$ and $l^2$ regularized least squares no longer holds, as\nthe initial setting of $Q_T$ is multiplied by $\\lambda^2$ at each timestep, and so\nthe equivalent regularization coefficient gets smaller with each new\ndatapoint. More precisely, the recursive least squares solution with\n$\\lambda$-forgetting and an initialization of $Q_0 = \\alpha I$ will, at time\n$T$, compute the equivalent ridge regression solution\n\\begin{equation}\n  \\hat\\Theta_{REAL} = (X_T^\\top X_T + \\frac{\\lambda^{2T}}{\\alpha}I)^{-1}X_T^\\top Y\n\\end{equation}\n\nThis may be desirable if one wishes to smoothly interpolate between\nthe ridge regression solution when little data is available and the\nunregularized least squares solution in the limit of infinite data, but we are\nnot aware of any existing statistical analysis of this interpolation.\n", "meta": {"hexsha": "667caa2e8e7ad20aa11fb683df42924cb27646b7", "size": 6593, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup/src/practical.tex", "max_stars_repo_name": "cannontwo/rls", "max_stars_repo_head_hexsha": "b2ebd2fd5f2c7e48b522c27aa5ac1b4e32e5fe8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "writeup/src/practical.tex", "max_issues_repo_name": "cannontwo/rls", "max_issues_repo_head_hexsha": "b2ebd2fd5f2c7e48b522c27aa5ac1b4e32e5fe8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "writeup/src/practical.tex", "max_forks_repo_name": "cannontwo/rls", "max_forks_repo_head_hexsha": "b2ebd2fd5f2c7e48b522c27aa5ac1b4e32e5fe8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.0409836066, "max_line_length": 242, "alphanum_fraction": 0.7395722736, "num_tokens": 1886, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.8887587831798665, "lm_q1q2_score": 0.809818972471922}}
{"text": "\n\nLet's invent a proposition, and call it $p$. $p$ is semantically\nequivalent to a ``statement''. A ``proof of $p$'' is a proof that $p$\nis true. To say\n\n\\begin{zz}\n  f \\text{ is a proof of } p,\n\\end{zz}\n\nwe write\n\n\\begin{zz}\n  f : p.\n\\end{zz}\n\n\\begin{remark}\n  Outside of certain circles, the $f : p$ notation is very\n  non-standard. Later in the book, it will become clear why we use it.\n\n  I often, when writing, use the $:$ symbol to be short for ``such\n  that''. Again, you'll see why all of this makes sense later.\n\\end{remark}\n\n\\begin{aside}\n  In mathematics, it's very common to see notation you think is\n  confusing, only to discover---often several years later---that the\n  notation makes perfect sense and is actually brilliant.\n\\end{aside}\n\nThe most basic proofs begin with \\term{axioms} (also called\n\\term{postulates}) and then prove \\term{theorems} (also called\n\\term{lemmas}). However, most proofs incorporate previously proved\nlemmas to create new lemmas. If we had to start from the most basic\naxioms every time we proved anything, nothing would ever get done.\n\n\\begin{definition}\n  \\label{def:axiom}\n  \\label{def:postulate}\n  An \\term{axiom} (or \\term{postulate}) is a proposition that we\n  accept to be true without proof.\n\\end{definition}\n\n\\begin{remark}\n  \\label{r:law}\n  In most contexts, the term ``law'' is ambiguous. Sometimes, it\n  refers to theorems, sometimes it refers to lemmas. I won't call\n  anything that I define a ``law''. However, I will call things\n  ``laws'' if some vocabulary term is commonly known as ``the law of\n  X'' or ``X's law''. (See, for instance, \\cref{ax:modus-ponens}).\n\\end{remark}\n\n\\begin{definition}\n  \\label{def:theorem}\n  A \\term{theorem} (or \\term{lemma}) is a proposition that can be\n  proven from other axioms or theorems.\n\\end{definition}\n\n\\subsection{Implication}\n\nThe first thing in logic is the notion of ``implication''. We write\n$a \\implies b$ to say ``$a$ implies $b$''. This means ``if $a$ is\ntrue, then $b$ is also true'', or simply ``if $a$ then $b$''.\n\n\\begin{axiom}[Law of Modus Ponens]\n  \\label{ax:modus-ponens}\n  If $a$ implies $b$, and we know $a$ is true, then we can conclude\n  $b$.\n\n  In other words, ``$a$ implies $b$. $a$, therefore $b$''.\n\\end{axiom}\n\nUsually, three dots arranged in a triangle are used to write\n``therefore'': $\\therefore$.  The statement in \\cref{ax:modus-ponens}\ncan therefore be rewritten as:\n\n\\begin{alignmath}{r}\n  a \\implies b.\\; a,\\, \\therefore b\n\\end{alignmath}\n\nSometimes, it's semantically convenient to write $b \\impliedby a$,\nwhich just means ``$b$ is implied by $a$''. It's the same as\n$a \\implies b$. This is also sometimes said ``$b$ if $a$''. This\nmeans, ``assuming $a$, we can prove $b$''.\n\nWe'll also often write $a \\iff b$ which means that $a$ implies $b$,\n\\xtb{and} $b$ implies $a$. Usually, you'll hear this pronounced ``$a$\nif and only if $b$''. In a minute, we'll get to why people say ``if\nand only if'', as opposed to something like ``implies and is implied\nby''.\n\n\\begin{remark}\n  Given two propositions $a$ and $b$, $a \\implies b$ is actually a\n  proposition. The proposition is, $a$ implies $b$.\n\\end{remark}\n\nHere are some more or less ``obvious'' properties of logic\n\n\\begin{axiom}[Reflexive property]\n  \\label{ax:props-refl}\n  For all propositions $a$, $a \\implies a$.\n\\end{axiom}\n\n\\begin{lemma}[Transitive property]\n  \\label{ax:props-trans}\n  For all propositions $a$, $b$, and $c$, if $a \\implies b$, and $b\n  \\implies c$, then $a \\implies c$\n\\end{lemma}\n\n\\begin{proof}\n  Given $f : a \\implies b$, and $g : b \\implies c$, we are to prove $a\n  \\implies c$. That is, assuming $a$, prove $c$. Let $h$ be our proof\n  of $a$ (i.e. $h : a$)\n\\end{proof}\n\n\\subsection{Negation}\n\nQuite often, we'll need to declare that something is false. To say\nthat ``$a$ is false'', you write $\\lnot a$, pronounced ``not $a$''.\n\n\\begin{axiom}[Double negation]\n  The proposition $\\lnot(\\lnot a)$ is equivalent to $a$.\n\\end{axiom}\n\n\\begin{remark}\n  In many (indeed, most) logics, double negation is not accepted as an\n  axiom. Many important theorems rely on double negation.\n\n  For instance, the Intermediate Value Theorem in Calculus states\n  that, given two points on $a$ and $b$ that are values of a\n  ``continuous'' function (a function whose graph does not have any\n  gaps or poles), the function touches every single point between $a$\n  and $b$. Every known proof of the Intermediate Value Theorem relies\n  on double negation. More specifically, it relies on the\n  contrapositive, which we'll define in a second.\n\\end{remark}\n\n\\subsection{The contrapositive}\n\nMany logics define two values, $\\top$, and $\\bot$, called ``top'' and\n``bottom'', respectively. $\\top$ is always provable, and $\\bot$ is\nnever provable. In those logics, the proposition $\\lnot a$ is\nequivalent to $a \\implies \\bot$. If you can prove $a$ implies\nsomething that is never provable, you can conclude that $a$ is false.\n\nThis is the common logical technique of \\term{reductio ad absurdum},\nor \\term{proof by contradiction}. ``Reductio ad absurdum'' is Latin\nfor ``reduction to the absurd''.\n\n\\begin{definition}\n  Given the proposition $a \\implies b$, the proposition\n  $\\lnot b \\implies \\lnot a$ is called the \\term{contrapositive}.\n\\end{definition}\n\n\\begin{theorem}[Reductio ad absurdum]\n  \\label{reductio-ad-absurdum}\n  Every proposition of the form $a \\implies b$ is logically equivalent\n  to its contrapositive.\n\\end{theorem}\n\nThe fact that a proposition is logically equivalent to its\ncontrapositive is not at all obvious. Let's go through some examples.\n\n\\begin{example}\n  If someone is decapitated, then they are dead (at least within a few\n  seconds). Therefore,\n\n  \\begin{zz}\n    \\text{Decapitated} \\implies \\text{Dead}\n  \\end{zz}\n\n  \\answergraph{images/alas-poor-yorick.png}\n\n  Therefore, if someone is alive, you can conclude that they have not\n  been decapitated. Thus,\n\n  \\begin{zz}\n    \\text{not Dead} \\implies \\text{not Decapitated}\n  \\end{zz}\n\n  This is the contrapositive.\n\\end{example}\n\nWe will circle back to proving the equivalence between a proposition\nand its contrapositive later on. To do this, we need to know what\n``equivalence'' is. The next section deals with defining equivalence.\n\n\\section{Equivalence}\n\nWhat exactly does it mean for two propositions to be equivalent? What\ndoes it mean for two numbers to be equivalent? What does it mean for\ntwo shapes to be equivalent?\n\nYou are probably tempted to say ``if $p = q$, then $p$ and $q$ are\nequivalent''! Problem solved, right?\n\nWell\\dots not really. Think about this: the proposition $p \\implies q$\nis equivalent to $\\lnot q \\implies \\lnot p$. They are clearly not the\nsame proposition, but they are logically equivalent\\dots\n\nHow do we universally define equivalence? Think about it for a\nsecond. In fact, I'm going to insert a page break so you can think\nabout this without cheating and reading the answer. Go for a walk, get\na cup of coffee, whatever it is you do, and think about this\\dots\n\n\\newpage\n\nAlright, you're back! The answer that mathematicians use is to define\nwhat are called \\term{equivalence relations}. What on earth is an\nequivalence relation? For that matter, what is a ``relation''?\n\nWe're going to explain all of that, as well as define an equivalence\nrelation for propositions.\n\nStrictly speaking, a ``relation'' is something that takes one or more\nobjects, and uses them to form a proposition. In this case, we're\ngoing to be studying relations that take two objects, called ``binary\nrelations''. (The word ``binary'' means ``of or relating to two'').\n\n\\begin{definition}\n  A \\term{binary relation} is something that takes exactly two\n  objects, and determines whether or not something is true about them.\n\\end{definition}\n\nThere are, in more advanced areas, relations that require more than\ntwo things. However, for now, when I say ``relation'', I mean\n``binary relation''.\n\n\\begin{aside}\n  There are also \\term{unary relations} which take only one object. I\n  don't think calling them ``relations'' makes a whole lot of sense,\n  because the term ``relation'' implies that you are comparing one\n  thing \\xti{relative} to other things. If there are no other things\n  to compare, the term ``relation'' doesn't make any\n  sense. Nonetheless, people use the term all the time.\n\\end{aside}\n\nYou already know quite a few relations.\n\n\\begin{enumerate}\n\\item Given two numbers $a$ and $b$, $=$ is a relation. It takes two\n  numbers and decides if they are equal.\n\\item The symbol $\\le$ is also a relation over numbers. It takes two\n  numbers, and decides if the first is less than or equal to the\n  second.\n\\item The symbol $\\implies$ is also a relation. It takes two\n  propositions, and decides if the first implies the second.\n\\end{enumerate}\n\nWhat is something we can say about $=$ that we can't say about $\\le$?\n\nThe answer is that $=$ is an ``equivalence relation''. Meaning that it\nsatisfies the properties in the next definition\n\n\\begin{definition}\n  An \\term{equivalence relation} is a binary relation $\\sim$ satisfying\n  these properties:\n\n  \\begin{enumerate}\n  \\item for all $a$, $a \\sim a$ (reflexive property),\n  \\item for all $a$ and $b$, $a \\sim b$ implies $b \\sim a$ (symmetric\n    property),\n  \\item for all $a$, $b$ and $c$, $a \\sim b$ and $b \\sim c$ imply\n    $a \\sim c$ (transitive property).\n  \\end{enumerate}\n\\end{definition}\n\nThe standard equivalence relation is $=$. It has all of those\nproperties.\n\nIf you'll notice, $\\le$ and $\\implies$ have all of those properties,\nexcept symmetry.\n\nIs there a relation for propositions that has symmetry? (That is, an\nequivalence relation for propositions).\n\nThink about it for a minute. I'll give you another page break\\dots\n\n\\newpage\n\nTurns out, there is an equivalence relation! The relation is\n$\\iff$. Think about it:\n\n\\begin{description}\n\\item[Reflexivity] For all propositions $p$, $p \\iff\n  p$. (\\Cref{ax:props-refl})\n\\item[Symmetry] For all propositions $p$ and $q$, $p \\iff q$ implies\n  $q \\iff p$.\n\\item[Transitivity] For all propositions $p$, $q$ and $r$, $p \\iff q$\n  and $q \\iff r$ imply $p \\iff r$. (\\Cref{ax:props-trans})\n\\end{description}\n\nCan you think of some other equivalence relations? Many of them are\nnot at all obvious.\n\n\\begin{example}\n  Analog clocks and watches give the time in 12-hour format. However,\n  there are 24 hours in a day. When you say ``14:00 is the same as\n  2:00'', you're actually saying ``14 is congruent to 2, modulo\n  12''. The way we write this is with\n\n  \\begin{zz}\n    14 \\equiv 2 \\mod 12\n  \\end{zz}\n\n  What exactly is ``modulo''? Technically speaking, $n$ modulo $m$ is\n  the remainder of dividing $n$ by $m$. So, $14 / 12 = 1$ with a\n  remainder of $2$. We'll get to this more in-depth when we discuss\n  arithmetic.\n\n  Here's a fun thing, you can add two times together to get a new\n  time. For instance, let's say you go into work at 9:00 in the\n  morning, and stay for 8 hours. $9 + 8 = 17$. However,\n  $17 \\equiv 5 \\mod 12$, which means you stay until 5 PM. You've been\n  secretly using this equivalence relation your entire life.\n\n  We'll learn later, in the Algebra section, that integers modulo 12\n  (i.e. numbers on a clock) form a \\term{module} of the integers\n  (hence the term ``modulo''). Meaning this:\n\n  \\begin{enumerate}\n  \\item Given two times, $a$ and $b$ in the module, $a + b$ is also in\n    the module.\n  \\item Given an integer\\footnote{An integer is a positive, negative\n      or zero whole number.} $z$, and a time $t$, $zt$ is also in the\n    subgroup.\\footnote{The notation $zt$ just means ``$z$ times\n      $t$''.}\n  \\end{enumerate}\n\n  There are a number of other properties that have to hold, but those\n  are the properties unique to modules.\n\n  Can you think of some other modules?\n\n  I'll give you a hint: even numbers are also a module.\n\\end{example}\n\n\\subsection{Contrapositive}\n\nCircling back to the contrapositive: I claimed a proposition of the\nform $a \\implies b$ is equivalent to its contrapositive. Now that\nwe've defined equivalence, we're much more equipped to prove this.\n\nTwo propositions $p$ and $q$ are equivalent if\\footnote{Actually, it's\n  ``if and only if'', because two propositions $p$ and $q$ being\n  ``equivalent'' means $p \\iff q$. However, it's conventional to say\n  ``if'' when parroting a definition.} $p \\iff q$. Therefore,\n\n\\begin{lemma}\n  \\label{thm:contrapositive}\n  $(a \\implies b) \\iff (\\lnot b \\implies \\lnot a)$.\n\\end{lemma}\n\n\\begin{proof}\n  The most common way to prove an ``if and only if'' statement is to\n  separately prove the $\\implies$ branch, and the $\\impliedby$ branch.\n\n  \\begin{description}\n  \\item[Branch $\\implies$] Given $a \\implies b$, we are to prove\n    $\\lnot b \\implies \\lnot a$. First, we expand $\\lnot b$ and $\\lnot\n    a$ into\n\n    \\begin{rcl}\n      \\lnot a & \\implies & (a \\implies \\bot) \\\\\n      \\lnot b & \\implies & (b \\implies \\bot) \\\\\n    \\end{rcl}\n\n    Therefore, we are to prove\n    $(b \\implies \\bot) \\implies (a \\implies \\bot)$. We are trying to\n    prove ``if we can show $b \\implies \\bot$, we can show\n    $a \\implies \\bot$. Therefore, we can assume $b \\implies \\bot$, and\n    then use that to prove $a \\implies \\bot$.\n\n    It might be helpful to assign labels to things. Let\n\n    \\begin{rcl}\n      f & : & a \\implies b \\\\\n      g & : & b \\implies \\bot \\\\\n      \\tabucline \\\\\n      \\text{goal} & : & a \\implies \\bot \\\\\n    \\end{rcl}\n\n    We could either use the transitive property\n  \\end{description}\n\\end{proof}", "meta": {"hexsha": "596319adbe0b95df7bf6b2a01df3413df37770b6", "size": 13403, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/1-old.tex", "max_stars_repo_name": "pharpend/sets-logics", "max_stars_repo_head_hexsha": "ff0aee4c32fe50c54e32c99b703fa2c0ddac0ec2", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/1-old.tex", "max_issues_repo_name": "pharpend/sets-logics", "max_issues_repo_head_hexsha": "ff0aee4c32fe50c54e32c99b703fa2c0ddac0ec2", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/1-old.tex", "max_forks_repo_name": "pharpend/sets-logics", "max_forks_repo_head_hexsha": "ff0aee4c32fe50c54e32c99b703fa2c0ddac0ec2", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.812987013, "max_line_length": 71, "alphanum_fraction": 0.7042453182, "num_tokens": 3888, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.9005297947939936, "lm_q1q2_score": 0.8096855844992896}}
{"text": "\n\\subsection{Mahalanobis distance}\n\nWe have a point. How far away is this from the mean.\n\nFor a single dimension: number of standard deviations.\n\nWhat about multidimensional data?\n\nCould do sd for all distances, but correlations between variables. If two variables are highly correlated, it's not really twice as far.\n\nWe use this:\n\n\\(D_M(\\mathbf x)=\\sqrt {(\\mathbf x-\\mathbf \\mu )^TS^{-1}(\\mathbf x-\\mathbf \\mu )}\\)\n\n", "meta": {"hexsha": "33026ed5eeeec3ece5b17790c3aef448256090fc", "size": 418, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/distance/01-04-mahalanobis.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/distance/01-04-mahalanobis.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/distance/01-04-mahalanobis.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.125, "max_line_length": 136, "alphanum_fraction": 0.7368421053, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9525741268224331, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.8096605486661712}}
{"text": "\\section{The M\\\"obius Group}\r\nWe want to study $f:\\mathbb C\\to\\mathbb C$ in the form \r\n$$f(x)=\\frac{ax+b}{cx+d},a,b,c,d\\in\\mathbb C$$\r\nThis function has a pole at $x=-d/c$, so we need an element at infinity.\r\nWe can take $\\mathbb C_\\infty:=\\mathbb C\\cup\\{\\infty\\}$ by the stereographic projection $\\mathbb C_{\\infty}=\\mathbb C\\cup\\{\\infty\\}\\cong S^2$.\r\nNow we define the Mobius map properly\r\n\\begin{definition}\r\n    The Mobius map $f:\\mathbb C_\\infty\\to\\mathbb C_\\infty$ is defined by\r\n    $$\r\n    f(z)=\r\n    \\begin{cases}\r\n        \\frac{az+b}{cz+d}\\text{, if $z\\neq\\infty$ and $z\\neq -d/c$}\\\\\r\n        \\infty\\text{, if $z=-d/c$}\\\\\r\n        \\frac{a}{c}\\text{, if $z=\\infty$}\r\n    \\end{cases}\r\n    $$\r\n    where $ad-bc\\neq 0$.\r\n\\end{definition}\r\nThe reason why we impose the last condiciton is that we want the Mobius map to be a bijection from $\\mathbb C_\\infty$ to $\\mathbb C_\\infty$.\r\n\\begin{proposition}\r\n    Let $\\mathcal M=\\{f:\\mathbb C_\\infty\\to\\mathbb C_\\infty:f\\text{ is a Mobius function.}\\}$.\r\n    Then $(\\mathcal M,\\circ,\\mathrm{id})$ is a group.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Obviously $\\mathrm{id}\\in\\mathcal M$.\r\n    Note also that if $g(z)=(az+b)/(cz+d), g'(z)=(a'z+b')/(c'z+d')$, then $g'(g(z))=(a''z+b'')/(c''z+d'')$ where\r\n    $$\r\n    \\begin{pmatrix}\r\n        a''&b''\\\\\r\n        c''&d''\r\n    \\end{pmatrix}\r\n    =\r\n    \\begin{pmatrix}\r\n        a'&b'\\\\\r\n        c'&d'\r\n    \\end{pmatrix}\r\n    \\begin{pmatrix}\r\n        a&b\\\\\r\n        c&d\r\n    \\end{pmatrix}\r\n    $$\r\n    Then it immediately tells us that $\\mathcal M$ is closed under $\\circ$ since the determinant function is multiplicative.\r\n    Note as well that it also gives us the inverse by just finding some $a',b',c',d'$ (which exists due to our criterion on determinant) such that\r\n    $$\r\n    \\begin{pmatrix}\r\n        a'&b'\\\\\r\n        c'&d'\r\n    \\end{pmatrix}\r\n    =\r\n    \\begin{pmatrix}\r\n        a&b\\\\\r\n        c&d\r\n    \\end{pmatrix}^{-1}\r\n    $$\r\n    by noticing that the identity function corresponds to $cI,c\\neq 0$.\r\n\\end{proof}\r\nWe can have $\\mathcal M$ to act on $\\mathbb C^\\infty$ faithfully (with trivial kernel), so $\\mathcal M\\le\\operatorname{Sym}\\mathbb C_\\infty$.\r\nNow consider the Mobius transformation $f(z)=1/(z-a)$, which sends $a$ to $\\infty$ and its inverse that sends $\\infty$ to $a$, so there is nothing special with $\\infty$ in $\\mathbb C^\\infty$, as one will expect as there is no special point on $S^2$.\r\n\\begin{proposition}\\label{decomp_mobius}\r\n    Every Mobius tranformation is a composition of $z\\mapsto az,a\\neq 0$, $z\\mapsto z+b$ and $z\\mapsto 1/z$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Let $z\\mapsto (az+b)/(cz+d)$ be a mobius transformation, then if $c=0$ the proposition is trivial.\r\n    Otherwise $c\\neq 0$, then we have\r\n    $$\\frac{az+b}{cz+d}=\\frac{a}{c}-\\frac{ad-bc}{c(cz+d)}$$\r\n    which can obviously be obtained from the said functions.\r\n\\end{proof}\r\nNow, how about fixed point of a Mobius transformation?\r\nWe know that a Mobius transformation fixes at least $1$ point, but how about more?\r\n\\begin{proposition}\r\n    A Mobius transformation fixes $3$ points is the identity.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Suppose\r\n    $$f:z\\mapsto\\frac{az+b}{cz+d}$$\r\n    If $\\infty$ is a fixed point, then $c=0$, so $f$ is a linear function.\r\n    But then a linear function that fixes $2$ (non-infinity) points is the identity (since $f(x)-x$ is linear and a linear function has exactly $1$ root unless it is constantly $0$), $f$ is the identity.\\\\\r\n    Now if $\\infty$ is not a fixed point, then\r\n    $$f(z)=z\\iff \\frac{az+b}{cz+d}-z=0\\iff az+b-z(cz+d)=0$$\r\n    which has at most $2$ roots (hence fixed point) since it is quadratic, unless it is the zero function, which essentially means that $c=b=0,d=a\\neq 0\\implies f=\\mathrm{id}$.\r\n\\end{proof}\r\n\\begin{proposition}\\label{mobius_3pts}\r\n    Given distinct $z_1,z_2,z_3\\in\\mathbb C_\\infty$ and $w_1,w_2,w_3\\in\\mathbb C$, then there is an unique Mobius transformation $f$ such that $f(z_i)=w_i$ for $i\\in\\{1,2,3\\}$.\r\n\\end{proposition}\r\nNote that since every Mobius transformation is a bijective (hence invertible), $w_i$'s are distinct as well.\r\n\\begin{proof}\r\n    For existence, it suffices to deal with the case where $w_1,w_2,w_3$ are $0,1,\\infty$, since once we've found maps $f,g$ such that $f:z_1,z_2,z_3\\mapsto 0,1,\\infty,g:w_1,w_2,w_3\\mapsto 0,1,\\infty$, then $g^{-1}\\circ f$ will send $z_1,z_2,z_3$ to $w_1,w_2,w_3$.\\\\\r\n    Now if none of $z_i$'s is $\\infty$, we can use the interpolation\r\n    $$f(z)=\\frac{(z-z_2)(z-z_3)}{(z_1-z_2)(z_2-z_3)}+\\frac{(z-z_1)(z-z_2)}{z-z_3}$$\r\n    Otherwise, suppose $z_i=\\infty$, then the map $f_i$ suffices where\r\n    $$f_1(z)=\\frac{z-z_2}{z-z_3},f_2(z)=\\frac{z_1-z_3}{z-z_3}, f_3(z)=\\frac{z-z_2}{z_1-z_2}$$\r\n    For uniqueness, suppose $f,f'$ send $z_1,z_2,z_3$ to $w_1,w_2,w_3$ respectly, then $f^{-1}\\circ f'$ fixes $z_1,z_2,z_3$, hence $f^{-1}\\circ f'=\\mathrm{id}\\implies f=f'$.\r\n\\end{proof}\r\nIf $f,g\\in\\mathcal M$ and $f$ fixes $z_0$, then $gfg^{-1}$ fixes $g(z_0)$, which gives rise to the following observation\r\n\\begin{theorem}\r\n    %There are three conjugacy classes of $\\mathcal M$, namely the identity alone, the functions with exactly one fixed point, and the functions with exactly $2$ fixed points.\r\n    Every member of a conjugacy class of $\\mathcal M$ has the same number of fixed point(s).\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Obviously the identity itself is itself a conjugacy class.\r\n    Now for any nonidentity $f$, $f$ has either $1$ or $2$ fixed points.\\\\\r\n    If $f$ has $1$ fixed point $z_0\\neq\\infty$, then suppose $g(z)=1/(z-z_0)$, we know that $gfg^{-1}$ fixes $\\infty$, and it cannot fix any other points because if so then applying $g^{-1}$ to that point would produce another fixed point of $f$.\r\n    So it has to be the map $z\\mapsto z+b,b\\neq 0$.\\\\\r\n    If $f$ has $2$ fixed point, then we consider a Mobius transformation $g$ which sends the fixed points to $0,\\infty$, then $gfg^{-1}$ fixed $0$ to $\\infty$ and sends $1$ to $a\\in\\mathbb C\\neq 0,\\infty$, so there is exactly one Mobius transformation $z\\mapsto az, a\\neq 1$.\r\n\\end{proof}\r\nNote that $(g^{-1}fg)^n=g^{-1}f^ng$.\r\nThis allows us to compute the arbitrary (integral) power of a Mobius transformation.\r\n\\begin{definition}\r\n    The circle in the extended complex numbers is the equation $Az\\bar z+\\bar Bz+B\\bar z+C=0$ with $A,C\\in\\mathbb R,B\\in\\mathbb C$.\r\n    Consider $\\infty$ is a point on this circle if and only if $A=0$.\r\n\\end{definition}\r\nNote that circles in $\\mathbb C$ are also circles in $\\mathbb C_\\infty$, and all other $\\mathbb C_\\infty$ circles are lines in $\\mathbb C$.\r\n\\begin{proposition}\r\n    Circles in $\\mathbb C_\\infty$ are mapped to circles in $\\mathbb C_\\infty$ under any Mobius transformations.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    It is sufficient to verify this for $z\\mapsto az,z\\mapsto z+b,z\\mapsto z^{-1}$ due to Proposition \\ref{decomp_mobius}.\r\n    It is then trivial.\r\n\\end{proof}\r\nNote that every circle gets to mapped to any other circle since three points determine the circle and Proposition \\ref{mobius_3pts}\r\n\\begin{definition}\r\n    For extended complex numbers $z_1,z_2,z_3,z_4$, the cross ratio is defined by\r\n    $$[z_1,z_2,z_3,z_4]=\\frac{(z_4-z_1)(z_2-z_3)}{(z_2-z_1)(z_4-z_3)}$$\r\n\\end{definition}\r\nWe need to examine carefully when one of these numbers is infinity.\r\nFor example, if we have $z_1=\\infty$, then the cross ratio is $(z_2-z_3)/(z_4-z_3)$.\r\n\\begin{corollary}\r\n    For extended complex numbers $z_1,z_2,z_3,z_4$, the cross ratio is equal to $f(z_4)$ where $f$ is the unique Mobius transformation sending $z_1,z_2,z_3$ to $0,1,\\infty$ respectively.\r\n\\end{corollary}\r\n\\begin{theorem}\r\n    Mobius transformations preserve the cross-ratio.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Suppose $z_1,z_2,z_3,z_4\\in\\mathbb C_\\infty$, and $g\\in\\mathcal M$.\r\n    Let $f$ be the Mobius transformation sending $z_1,z_2,z_3$ to $0,1,\\infty$, so the cross ratio is $f(z_4)$, so $f\\circ g^{-1}$ sends $g(z_1),g(z_2),g(z_3)$ to $0,1,\\infty$, so the cross ratio of the $g(z_i)$'s is $f\\circ g^{-1}(g(z_4))=f(z_4)$.\r\n\\end{proof}\r\nThe converse is also true (and proved in example sheet): If a map preserves cross-ratio, then it is a Mobius transformation.\r\n\\begin{corollary}\r\n    Four points $z_1,z_2,z_3,z_4\\in\\mathbb C_\\infty$ are on a circle (in the sense of $\\mathbb C_\\infty$) if and only if $[z_1,z_2,z_3,z_4]$ is real.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Let $f$ be the unique Mobius transformation sending $z_1,z_2,z_3$ to $0,1,\\infty$, so $[z_1,z_2,z_3,z_4]=f(z_4)$.\r\n    Let $c$ be the unique circle passing through $z_1,z_2,z_3$, then $z_4\\in c\\iff f(z_4)\\in f(c)$, but $f(c)=\\mathbb R\\cup\\{\\infty\\}$.\r\n\\end{proof}", "meta": {"hexsha": "1bd28828ddef7f118bfd7555e87df9a01baf9c4b", "size": 8655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/mobius.tex", "max_stars_repo_name": "david-bai-notes/IA-Groups", "max_stars_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6/mobius.tex", "max_issues_repo_name": "david-bai-notes/IA-Groups", "max_issues_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6/mobius.tex", "max_forks_repo_name": "david-bai-notes/IA-Groups", "max_forks_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.1041666667, "max_line_length": 276, "alphanum_fraction": 0.658463316, "num_tokens": 3028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443461, "lm_q2_score": 0.90192067059785, "lm_q1q2_score": 0.8096499423185473}}
{"text": "\\lab{Markov Chains}{Markov Chains}\n\\label{lab:Markov}\n\\objective{\nA Markov chain is a collection of states with specified probabilities for transitioning from one state to another.\nThey are characterized by the fact that the future behavior of the system depends only on its current state.\nIn this lab we learn to construct, analyze, and interact with Markov chains, then use a Markov-based approach to simulate natural language.}\n\n\\section*{State Space Models} % ===============================================\n\nMany systems can be described by a finite number of \\emph{states}.\nFor example, a board game where players move around the board based on dice rolls can be modeled by a Markov chain.\nEach space represents a state, and a player is said to be in a state if their piece is currently on the corresponding space.\nIn this case, the probability of moving from one space to another only depends on the player's current location; where the player was on a previous turn does not affect their current turn.\n\nMarkov chains with a finite number of states have an associated \\emph{transition matrix} that stores the information about the possible transitions between the states in the chain.\nThe $(i,j)$th entry of the matrix gives the probability of moving \\textbf{from state $j$ to state $i$}.\nThus, each of the columns of the transition matrix sum to $1$.\n\n\\begin{info} % Column stochastic versus row stochastic.\nA transition matrix where the columns sum to $1$ is called \\emph{column stochastic} (or \\emph{left stochastic}).\nThe rows of a \\emph{row stochastic} (or \\emph{right stochastic}) transition matrix each sum to $1$ and the $(i,j)$th entry of the matrix is the probability of moving from state $i$ to state $j$.\nBoth representations are common, but in this lab we exclusively use column stochastic transition matrices for consistency.\n\\end{info}\n\nConsider a very simple weather model in which the weather tomorrow depends only on the weather today.\nFor now, we consider only two possible weather states: hot and cold.\nSuppose that if today is hot, then the probability that tomorrow is also hot is 0.7, and that if today is cold, the probability that tomorrow is also cold is 0.4.\nBy assigning ``hot'' to the $0$th row and column, and ``cold'' to the $1$st row and column, this Markov chain has the following transition matrix.\n\n\\begin{align*}\n\\begin{blockarray}{ccc}\n& \\text{\\textcolor{red}{hot today}} & \\text{\\textcolor{blue}{cold today}} \\\\\n\\begin{block}{c[cc]}\n\\text{\\textcolor{red}{hot tomorrow}}   & 0.7 & 0.6 \\topstrut \\\\\n\\text{\\textcolor{blue}{cold tomorrow}} & 0.3 & 0.4 \\botstrut \\\\\n\\end{block}\\end{blockarray}\n\\end{align*}\n%\nThe $0$th column of the matrix says that if it is hot today, there is a $70\\%$ chance that tomorrow will be hot ($0$th row) and a $30\\%$ chance that tomorrow will be cold ($1$st row).\nThe $1$st column says if it is cold today, then there is a $60\\%$ chance of heat and a $40\\%$ chance of cold tomorrow.\n\nMarkov chains can be represented by a \\emph{state diagram}, a type of directed graph.\nThe nodes in the graph are the states, and the edges indicate the state transition probabilities.\nThe Markov chain described above has the following state diagram.\n\n\\begin{figure}[H] % 2-state chain.\n\\centering\n\\begin{tikzpicture}[normalcircle/.style={draw, circle, minimum size=1.5cm, thick, node distance=2.5cm}]\n    % Place the circles\n    \\node[normalcircle] (Hot) {};\n    \\node[red] at (Hot) {hot};\n\n    \\node[normalcircle, right=of Hot] (Cold) {};\n    \\node[blue] at (Cold) {cold};\n\n    % Draw loop, place number, draw line\n    \\draw[thick,->,>=stealth',red!70!black] (Hot)+(-.52,.52) arc (325:40:.35 and -.85);\n    \\node[left,red!70!black] at (Hot.west) [shift={+(-.5,0)}] {0.7};\n    \\draw[thick,->,>=stealth',red!70!black] (Hot.north east) -- node[above] {0.3} (Cold.north west);\n\n    \\draw[thick,<-,>=stealth',blue!70!black] (Cold)+(.52,.52) arc (325:40:-.35 and -.85);\n    \\node[right,blue!70!black] at (Cold.east) [shift={+(.5,0)}] {0.4};\n    \\draw[thick,->,>=stealth',blue!70!black] (Cold.south west) -- node[below] {0.6} (Hot.south east);\n\\end{tikzpicture}\n\\end{figure}\n\n\\begin{problem} % MarkovChain.__init__().\n\\label{prob:markov-chain-class-constructor}\nDefine a \\li{MarkovChain} class whose constructor accepts an $n\\times n$ transition matrix $A$ and, optionally, a list of state labels.\nIf $A$ is not column stochastic, raise a \\li{ValueError}.\nConstruct a dictionary mapping the state labels to the row/column index that they correspond to in $A$ (given by order of the labels in the list), and save $A$, the list of labels, and this dictionary as attributes.\nIf there are no state labels given, use the labels $\\begin{bmatrix}0 & 1 & \\ldots & n-1\\end{bmatrix}$.\n\nFor example, for the weather model described above, the transition matrix is\n\\begin{align*}\n    A = \\left[\\begin{array}{cc}0.7 & 0.6 \\\\ 0.3 & 0.4\\end{array}\\right],\n\\end{align*}\nthe list of state labels is \\li{[\"hot\", \"cold\"]}, and the dictionary mapping labels to indices is \\li{\\{\"hot\":0, \"cold\":1\\}}.\nThis Markov chain could be also represented by the transition matrix\n\\begin{align*}\n    \\widetilde{A}\n    = \\left[\\begin{array}{cc}\n        0.4 & 0.3 \\\\ 0.6 & 0.7\n    \\end{array}\\right],\n\\end{align*}\nthe labels \\li{[\"cold\", \"hot\"]}, and the resulting dictionary \\li{\\{\"cold\":0, \"hot\":1\\}}.\n\\end{problem}\n\n\\subsection*{Simulating State Transitions} % ----------------------------------\n\nSimulating the weather model described above requires a programmatic way of choosing between the outgoing transition probabilities of each state.\nFor example, if it is cold today, we could flip a weighted coin that lands on tails $60\\%$ of the time (guess tomorrow is hot) and heads $40\\%$ of the time (guess tomorrow is cold) to predict the weather tomorrow.\nThe \\emph{Bernoulli distribution} with parameter $p = 0.4$ simulates this behavior: $60\\%$ of draws are $0$, and $40\\%$ of draws are a $1$.\n\nA \\emph{binomial distribution} is the sum several Bernoulli draws: one binomial draw with parameters $n$ and $p$ indicates the number of successes out of $n$ independent experiments, each with probability $p$ of success.\nIn other words, $n$ is the number of times to flip the coin, and $p$ is the probability that the coin lands on heads.\nThus, a binomial draw with $n=1$ is a Bernoulli draw.\n\nNumPy does not have a function dedicated to drawing from a Bernoulli distribution; instead, use the more general \\li{np.random.binomial()} with $n=1$ to make a Bernoulli draw.\n\n\\begin{lstlisting}\n>>> import numpy as np\n\n# Draw from the Bernoulli distribution with p = .5 (flip one fair coin).\n>>> np.random.binomial(n=1, p=.5)\n0                             # The coin flip resulted in tails.\n\n# Draw from the Bernoulli distribution with p = .3 (flip one weighted coin).\n>>> np.random.binomial(n=1, p=.3)\n0                             # Also tails.\n\\end{lstlisting}\n\nFor the weather model, if the ``cold'' state corresponds to row and column 1 in the transition matrix, $p$ should be the probability that tomorrow is cold.\nSo, if today is cold, select $p=0.4$; if today is hot, set $p=0.3$.\nThen draw from the binomial distribution with $n=1$ and the selected $p$.\nIf the result is $0$, transition to the ``hot'' state; if the result is $1$, stay in the ``cold'' state.\n\n% Consider again the simple weather model and suppose that today is hot.\n% The column that corresponds to ``hot''in the transition matrix is $[0.7, 0.3]$.\n% To determine whether tomorrow is hot or cold, draw from the binomial distribution with $n = 1$ and $p = 0.3$.\n% If the draw is 1, which has $30\\%$ likelihood, then tomorrow is cold.\n% If the draw is 0, which has $70\\%$ likelihood, then tomorrow is hot.\n\nUsing Bernoulli draws to determine state transitions works for Markov chains with two states, but larger Markov chains require draws from a \\emph{categorical distribution}, a multivariate generalization of the Bernoulli distribution.\nA draw from a categorical distribution with parameters $(p_1,p_2,\\ldots,p_k)$ satisfying $\\sum_{i=1}^k p_i = 1$ indicates which of $k$ outcomes occurs.\nIf $k=2$, a draw simulates a coin flip (a Bernoulli draw); if $k=6$, a draw simulates rolling a six-sided die. %, like rolling a weighted $k$-sided die.\nJust as the Bernoulli distribution is a special case of the binomial distribution, the categorical distribution is a special case of the \\emph{multinomial distribution} which indicates how many times each of the $k$ outcomes occurs in $n$ repeated experiments.\nUse \\li{np.random.multinomial()} with $n = 1$ to make a categorical draw.\n\n\\begin{lstlisting}\n# Draw from the categorical distribution (roll a fair four-sided die).\n>>> np.random.multinomial(1, np.array([1./4, 1./4, 1./4, 1./4]))\narray([0, 0, 0, 1])     # The roll resulted in a 3.\n\n# Draw from another categorical distribution (roll a weighted four-sided die).\n>>> np.random.multinomial(1, np.array([.5, .3, .2, 0]))\narray([0, 1, 0, 0])     # The roll resulted in a 1.\n\\end{lstlisting}\n\nConsider a four-state weather model with the transition matrix\n\\begin{comment} % The beginnings of the 4-state chain diagram.\n\\begin{tikzpicture}[normalcircle/.style={draw,circle,minimum size=1.5cm,fill=none,thick,node distance=3.5cm}]\n% Nodes\n\\node[normalcircle] (A) {\\textcolor{red}{hot}};\n\\node[normalcircle] (B) [above of=A] {\\textcolor{green}{mild}};\n\\node[normalcircle] (C) [right of=B] {\\textcolor{blue}{cold}};\n\\node[normalcircle] (D) [below of=C] {\\textcolor{cyan}{freezing}};\n% Edges\n\\draw[bend right=60,thick,->,>=stealth'] (D) edge (C);\n\\draw[bend left=60,thick,->,>=stealth',blue] (B) edge (C);\n\\draw[bend right=60,thick,->,>=stealth',blue] (B) edge (A);\n\\foreach \\a/\\b in {A/B,A/C,A/D,C/B,C/D} \\draw[thick,->,>=stealth'] (\\a) edge (\\b);\n\\draw[thick,->,>=stealth',blue] (B) edge (D);\n\\draw[thick,->,>=stealth',shorten >=1pt,blue] (B) to [out=110,in=170,loop,looseness=4.5] (B);\n\\end{tikzpicture}\n\\end{comment}\n\\begin{align*}\n\\begin{blockarray}{ccccc}\n& \\text{\\textcolor{red}{hot}} & \\text{\\textcolor[rgb]{0,.6,0}{mild}} & \\text{\\textcolor{blue}{cold}} & \\text{\\textcolor{cyan}{freezing}} \\\\\n\\begin{block}{c[cccc]}\n\\text{\\textcolor{red}{hot}}              & 0.5 & 0.3 & 0.1 & 0   \\topstrut \\\\\n\\text{\\textcolor[rgb]{0,.6,0}{mild}}     & 0.3 & 0.3 & 0.3 & 0.3 \\\\\n\\text{\\textcolor{blue}{cold}}            & 0.2 & 0.3 & 0.4 & 0.5 \\\\\n\\text{\\textcolor{cyan}{freezing}}        &   0 & 0.1 & 0.2 & 0.2 \\botstrut \\\\\n\\end{block}\\end{blockarray}.\n\\end{align*}\nIf today is hot, the probabilities of transitioning to each state are given by the ``hot'' column of the transition matrix.\nTherefore, to choose a new state, draw from the categorical distribution with parameters ($0.5$, $0.3$, $0.2$, $0$).\nThe result $\\begin{bmatrix}0 & 1 & 0 & 0\\end{bmatrix}$ indicates a transition to the state corresponding to the $1$st row and column (tomorrow is mild), while the result $\\begin{bmatrix}0 & 0 & 1 & 0\\end{bmatrix}$ indicates a transition to the state corresponding to the $2$nd row and column (tomorrow is cold).\nIn other words, the position of the $1$ tells which column of the matrix to use as the parameters for the next categorical draw.\n\n\\begin{problem} % MarkovChain.transition()\nWrite a method for the \\li{MarkovChain} class that accepts a single state label.\nUse the label-to-index dictionary to determine the column of $A$ that corresponds to the provided state label, then draw from the corresponding categorical distribution to choose a state to transition to.\nReturn the corresponding label of the new state (not its index).\n\\\\(Hint: \\li{np.argmax()} may be useful.)\n\\label{prob:markov-class-transition}\n\\end{problem}\n\n\\begin{problem} % MarkovChain.walk() and MarkovChain.path().\n\\label{prob:markov-class-walkers}\nAdd the following methods to the \\li{MarkovChain} class.\n\\begin{itemize}\n\\item \\li{walk()}: Accept a state label and an interger $N$.\nStarting at the specified state, use your method from Problem \\ref{prob:markov-class-transition} to transition from state to state $N-1$ times, recording the state label at each step.\nReturn the list of $N$ state labels, including the initial state.\n\\item \\li{path()}: Accept labels for an initial state and an end state.\nBeginning at the initial state, transition from state to state until arriving at the specified end state, recording the state label at each step.\nReturn the list of state labels, including the initial and final states.\n\\end{itemize}\nTest your methods on the two-state and four-state weather models described previously.\n\\end{problem}\n\n\\section*{General State Distributions} % ======================================\n\n\\begin{comment} % The 1-Norm. Might be able to get away without this.\nFor an $n\\times 1$ vector $\\x$ with entries $x_i$ and an $n\\times n$ matrix $A$ with entries $a_{ij}$, the \\emph{1-norm} is defined as follows.\n\\begin{align*}\n\\|\\x\\|_1 = \\sum_{i=1}^n|x_i| && \\|A\\|_1 = \\sup_j \\sum_{i=1}^n |a_{ij}|\n\\end{align*}\nIn other words, the $1$-norm for both vectors and matrices is the maximum absolute column sum.\nThen if $A$ is a transition matrix, $\\|A\\|_1 = 1$, since each of the entries of the matrix are positive and each of the columns sum to $1$ by definition.\nThe power method with the 1-norm can be used to find the unique stable steady state distribution of $A$.\n\\end{comment}\n\nFor a Markov chain with $n$ states, the probability of being in each state can be encoded by a $n$-vector $\\x$, called a \\emph{state distribution vector}.\nThe entries of $\\x$ must be nonnegative and sum to 1, and the $i$th entry $x_i$ of $\\x$ is the probability of being in state $i$.\nFor example, the state distribution vector $\\x = \\begin{bmatrix}0.8 & 0.2\\end{bmatrix}\\trp$ corresponding to the 2-state weather model indicates an $80\\%$ chance that today is hot and a $20\\%$ chance that today is cold.\nOn the other hand, the vector $\\x = \\begin{bmatrix}0 & 1\\end{bmatrix}\\trp$ implies that today is, with $100\\%$ certainty, cold.\n\nIf $A$ is a transition matrix for a Markov chain with $n$ states and $\\x$ is a corresponding state distribution vector, then $A\\x$ is also a state distribution vector.\n% To verify this fact, let $a_{ij}$ be the entries of $A$ and $x_i$ the entries of $\\x$.\n% The columns of $A$ sum to $1$, so $\\sum_{j=1}^n a_{ij} = 1$ for $i = 1,\\ 2,\\ \\ldots,\\ n$.\n% In addition, $\\sum_{j=1}^n x_j = 1$ since the entries of $\\x$ also sum to $1$.\n% From matrix multiplication, the $i$th entry of $A\\x$ is given by $\\sum_{j=1}^n a_{ij}x_j$, so the sum of the entries of $A\\x$ is\n% \\[\\sum_{i=1}^n\\sum_{j=1}^n a_{ij}x_j\n% = \\sum_{j=1}^n\\left(x_j\\left(\\sum_{j=1}^n a_{ij}\\right)\\right)\n% = \\sum_{j=1}^n x_j = 1.\\]\nIn fact, if $\\x_k$ is the state distribution vector corresponding to a certain time $k$, then $\\x_{k+1} = A\\x_k$ contains the probabilities of being in each state after allowing the system to transition again.\nFor the weather model, this means that if there is an $80\\%$ chance that it will be hot 5 days from now, written $\\x_{5} = \\begin{bmatrix}0.8 & 0.2\\end{bmatrix}\\trp$, then since\n\\[\n\\x_{6} = A\\x_{5} =\n\\left[\\begin{array}{cc}\n0.7 & 0.6 \\\\\n0.3 & 0.4 \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{c}0.8 \\\\ 0.2\\end{array}\\right]\n=\n\\left[\\begin{array}{c}0.68 \\\\ 0.32\\end{array}\\right],\n\\]\nthere is a $68\\%$ chance that 6 days from now will be a hot day.\n\n\\subsection*{Convergent Transition Matrices} % --------------------------------\n\nGiven an initial state distribution vector $\\x_{0}$, defining $\\x_{k+1} = A\\x_k$ yields the significant relation\n\\[\n\\x_k = A\\x_{k-1} = A(A\\x_{k-2}) = A(A(A\\x_{x-3})) = \\cdots = A^k\\x_{0}.\n\\]\n\nThis indicates that the $(i,j)$th entry of $A^k$ is the probability of transition from state $j$ to state $i$ in $k$ steps.\nFor the transition matrix of the 2-state weather model, a pattern emerges in $A^k$ for even small values of $k$:\n\\[\nA = \\left[\\begin{array}{cc}\n0.7 & 0.6 \\\\\n0.3 & 0.4 \\\\\n\\end{array}\\right],\n\\quad\nA^2 = \\left[\\begin{array}{cc}\n0.67 & 0.66 \\\\\n0.33 & 0.34 \\\\\n\\end{array}\\right],\n\\quad\nA^3 = \\left[\\begin{array}{cc}\n0.667 & 0.666 \\\\\n0.333 & 0.334 \\\\\n\\end{array}\\right].\n\\]\nAs $k\\rightarrow\\infty$, the entries of $A^k$ converge, written\n\\begin{equation}\n\\lim_{k \\rightarrow \\infty} A^k = \\left[\\begin{array}{ccc}\n2/3 & 2/3 \\\\\n1/3 & 1/3 \\\\\n\\end{array}\\right].\n\\label{eq:markov-steady-transition}\n\\end{equation}\nIn addition, for any initial state distribution vector $\\x_{0} = [a,\\ b]\\trp$ (meaning $a,b\\ge 0$ and $a + b = 1$),\n\\[\n\\lim_{k \\rightarrow \\infty} \\x_k = \\lim_{k \\rightarrow \\infty}A^k\\x_{0}\n=\n\\left[\\begin{array}{ccc}\n2/3 & 2/3 \\\\\n1/3 & 1/3 \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{c}a\\\\b\\end{array}\\right]\n=\n\\left[\\begin{array}{c}2(a+b)/3\\\\(a+b)/3\\end{array}\\right]\n=\n\\left[\\begin{array}{c}2/3\\\\1/3\\end{array}\\right].\n\\]\n\nThus, $\\x_k \\rightarrow \\x = \\begin{bmatrix}2/3 & 1/3\\end{bmatrix}\\trp$ as $k\\rightarrow\\infty$,  regardless of the initial state distribution $\\x_{0}$.\nSo, according to this model, no matter the weather today, the probability that it is hot a week from now is approximately $66.67\\%$.\nIn fact, approximately 2 out of 3 days in the year should be hot.\n\n\\subsection*{Steady State Distributions} % ------------------------------------\n\nThe state distribution $\\x = \\begin{bmatrix}2/3 & 1/3\\end{bmatrix}\\trp$ has another important property:\n\\[\nA\\x =\n\\left[\\begin{array}{cc}\n7/10 & 3/5 \\\\\n3/10 & 2/5 \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{c}2/3 \\\\ 1/3\\end{array}\\right]\n=\n\\left[\\begin{array}{c}14/30 + 3/15 \\\\ 6/30 + 2/15\\end{array}\\right]\n=\n\\left[\\begin{array}{c}2/3 \\\\ 1/3\\end{array}\\right]\n= \\x.\n\\]\nAny $\\x$ satisfying $A\\x = \\x$ is called a \\emph{steady state distribution} or a \\emph{stable fixed point} of $A$.\nIn other words, a steady state distribution is an eigenvector of $A$ corresponding to the eigenvalue $\\lambda = 1$.\n\n% TODO: Verify this paragraph.\nEvery finite Markov chain has at least one steady state distribution.\nIf some power $A^k$ of $A$ has all positive (nonzero) entries, then the steady state distribution is unique.%\n\\footnote{This is a consequence of the \\emph{Perron-Frobenius theorem}, which is presented in detail in Volume 1.}\nIn this case, $\\lim_{k\\rightarrow\\infty}A^k$ is the matrix whose columns are all equal to the unique steady state distribution, as in (\\ref{eq:markov-steady-transition}).\nUnder these circumstances, the steady state distribution $\\x$ can be found by iteratively calculating $\\x_{k+1} = A\\x_k$, as long as the initial vector $\\x_{0}$ is a state distribution vector.\n\n\\begin{warn}\nThough every Markov chain has at least one steady state distribution, the procedure described above fails if $A^k$ fails to converge.\nFor instance, consider the transition matrix\n\\[\nA = \\left[\\begin{array}{ccc}\n0 & 0 & 1 \\\\\n0 & 1 & 0 \\\\\n1 & 0 & 0\n\\end{array}\\right]\n,\\quad A^k = \\begin{cases}\nA\\quad\\text{if } k\\ \\text{is odd}\n\\\\\nI\\quad\\text{if } k\\ \\text{is even.}\n\\end{cases}\n\\]\nIn this case as $k\\rightarrow\\infty$, $A^k$ oscillates between two different matrices.\n\nFurthermore, the steady state distribution is not always unique; the transition matrix defined above, for example, has infinitely many.\n\\end{warn}\n\n\\begin{problem} % Use the power method (simple) to get the steady state.\nWrite a method for the \\li{MarkovChain} class that accepts a convergence tolerance \\li{tol} and a maximum number of iterations \\li{maxiter}.\nGenerate a random state distribution vector $\\x_{0}$ and calculate $\\x_{k+1} = A\\x_k$ until $\\|\\x_{k-1} - \\x_k\\|_1 <$ \\li{tol}, where $A$ is the transition matrix saved in the constructor.\nIf $k$ exceeds \\li{maxiter}, raise a \\li{ValueError} to indicate that $A^k$ does not converge.\nReturn the approximate steady state distribution $\\x$ of $A$.\n\nTo test your function, generate a random transition matrix $A$.\nVerify that $A\\x = \\x$ and that the columns of $A^k$ approach $\\x$ as $k\\rightarrow\\infty$.\nTo compute $A^k$, use NumPy's (very efficient) algorithm for computing matrix powers. % (which is not part of \\li{scipy.linalg}).\n\n\\begin{lstlisting}\n>>> A = np.array([[.7, .6],[.3, .4]])\n>>> np.linalg.matrix_power(A, 10)       # Compute A^10.\narray([[ 0.66666667,  0.66666667],\n       [ 0.33333333,  0.33333333]])\n\\end{lstlisting}\n%\nFinally, use your method to validate the results of Problem \\ref{prob:markov-class-walkers}:\nfor the two-state and four-state weather models,\n\\begin{enumerate}\n    \\item Calculate the steady state distribution corresponding to the transition matrix.\n    \\item Run a weather simulation for a large number of days using \\li{walk()} and verify that the results match the steady state distribution (for example, approximately 2/3 of the days should be hot for the two-state model).\n\\end{enumerate}\n\\label{prob:markov-power-method}\n\\end{problem}\n\n\\begin{info}\nProblem \\ref{prob:markov-power-method} is a special case of the \\emph{power method}, an algorithm for calculating an eigenvector of a matrix corresponding to the eigenvalue of largest magnitude.\nThe general power method, together with a discussion of its convergence conditions, is discussed in Volume 1.\n\\end{info}\n\n\\section*{Using Markov Chains to Simulate English} % ==========================\n\nOne of the original applications of Markov chains was to study \\emph{natural languages}, meaning spoken or written languages like English or Russian \\cite{von2006five}.\nIn the early $20$th century, Markov used his chains to model how Russian switched from vowels to consonants.\nBy mid-century, they had been used as an attempt to model English.\nIt turns out that plain Markov chains are, by themselves, insufficient to model or produce very good English.\nHowever, they can approach a fairly good model of bad English, with sometimes amusing results.\n\nBy nature, a Markov chain is only concerned with its current state, not with previous states.\nA Markov chain simulating transitions between English words is therefore completely unaware of context or even of previous words in a sentence.\nFor example, if a chain's current state is the word ``continuous,'' the chain may say that the next word in a sentence is more likely to be ``function'' rather than ``raccoon.''\nHowever the phrase ``continuous function'' may be gibberish in the context of the rest of the sentence.\n\n% The transition probabilities of the resulting Markov chain should reflect the sort of English that the source authors speak.\n% Thus, the Markov chain built from \\emph{The Complete Works of William Shakespeare} differs greatly from the Markov chain built from a collection of academic journals.\n% The source collection of works in the next problems is called the \\emph{training set}.\n\n\\subsection*{Generating Random Sentences} % -----------------------------------\n\nConsider the problem of generating English sentences that are similar to the text contained in a specific file, called the \\emph{training set}.\nThe goal is to construct a Markov chain whose states and transition probabilities represent the vocabulary and---hopefully---the style of the source material.\nThere are several ways to approach this problem, but one simple strategy is to assign each unique word in the training set to a state, then construct the transition probabilities between the states based on the ordering of the words in the training set.\nTo indicate the beginning and end of a sentence requires two extra states: a \\emph{start state}, \\textcolor[rgb]{0,.6,0}{\\$tart}, marking the beginning of a sentence; and a \\emph{stop state}, \\textcolor{red}{\\$top}, marking the end.\nThe start state should only transitions to words that appear at the beginning of a sentence in the training set, and only words that appear at the end a sentence in the training set should transition to the stop state.\n\n% English sentences are of varying length, so it is unknown beforehand how many words to choose (how many state transitions to make) before ending the sentence.\n% To capture this feature, include two extra states in the chain: a \\emph{start state}, \\textcolor[rgb]{0,.6,0}{\\$tart}, marking the beginning of a sentence; and a \\emph{stop state}, \\textcolor{red}{\\$top}, marking the end.\n% Thus, a training set with $n$ unique words has an $(n+2)\\times (n+2)$ transition matrix.\n\nConsider the following small training set, paraphrased from Dr. Seuss \\cite{geisel1960green}.\n\n\\begin{lstlisting}\n<<I am Sam Sam I am.\nDo you like green eggs and ham?\nI do not like them, Sam I am.\nI do not like green eggs and ham.>>\n\\end{lstlisting}\n\nThere are 15 unique words in this training set, including punctuation (so ``ham?'' and ``ham.'' are counted as distinct words) and capitalization (so ``Do'' and ``do'' are also different):\n%\n\\begin{align*}\n\\text{I\\quad am\\quad Sam\\quad am.\\quad Do\\quad you\\quad like\\quad green}\n\\\\\n\\text{eggs\\quad and\\quad ham?\\quad do\\quad not\\quad them,\\quad ham.}\n\\end{align*}\n%\nWith start and stop states, the transition matrix should be $17 \\times 17$.\nEach state must be assigned a row and column index in the transition matrix, for example,\n% An easy way to do this is to assign the states an index based on the order that they appear in the training set.\n%\n\\begin{align*}\n\\begin{array}{ccccccc}\n\\text{\\textcolor[rgb]{0,.6,0}{\\$tart}} & \\text{I} & \\text{am} & \\text{Sam} & \\ldots & \\text{ham.} & \\text{\\textcolor{red}{\\$top}}\n\\\\\n0 & 1 & 2 & 3 & \\ldots & 15 & 16\n\\end{array}\n\\end{align*}\n%\nThe $(i,j)$th entry of the transition matrix $A$ should be the probability that word $j$ is followed by word $i$.\nFor instance, the word ``Sam'' is followed by the words ``Sam'' once and ``I'' twice in the training set, so the state corresponding to ``Sam'' (index 3) should transition to the state for ``Sam'' with probability $1/3$, and to the state for ``I'' (index 1) with probability $2/3$.\nThat is, $A_{3,3} = 1/3$, $A_{1,3} = 2/3$, and $A_{i,3} = 0$ for $i \\notin\\{1,3\\}$.\nSimilarly, the start state should transition to the state for ``I'' with probability $3/4$, and to the state for ``Do'' with probability $1/4$; the states for ``am.'', ``ham?'', and ``ham.'' should each transition to the stop state.\n\nTo construct the transition matrix, parse the training set and add $1$ to $A_{i,j}$ every time word $j$ is followed by word $i$, in this case arriving at the matrix\n%\n\\begin{align*}\n\\begin{blockarray}{cccccccc}\n& \\text{\\textcolor[rgb]{.3,.6,.1}{\\$tart}} & \\textcolor{gray}{\\text{I}} & \\textcolor{gray}{\\text{am}} & \\textcolor{gray}{\\text{Sam}} & & \\textcolor{gray}{\\text{ham.}} & \\text{\\textcolor[rgb]{1,0,0}{\\$top}} \\\\\n\\begin{block}{c[ccccccc]}\n\\text{\\textcolor[rgb]{.3,.6,.1}{\\$tart}}    & 0 & 0 & 0 & 0 & \\ldots & 0 & 0 \\topstrut \\\\\n\\textcolor{gray}{\\text{I}}        & 3 & 0 & 0 & 2 & \\ldots & 0 & 0\\\\\n\\textcolor{gray}{\\text{am}}       & 0 & 1 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\textcolor{gray}{\\text{Sam}}      & 0 & 0 & 1 & 1 & \\ldots & 0 & 0\\\\\n& \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots\\\\\n\\textcolor{gray}{\\text{ham.}}     & 0 & 0 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{\\textcolor[rgb]{1,0,0}{\\$top}}        & 0 & 0 & 0 & 0 & \\ldots & 1 & 0 \\botstrut \\\\\n\\end{block}\\end{blockarray}.\n\\end{align*}\nTo avoid a column of zeros, set $A_{j,j} = 1$ where j is the index of the stop state (so the stop state always transitions to itself).\nNext, divide each column by its sum so that each column sums to 1:\n\\begin{align*}\n\\begin{blockarray}{cccccccc}\n& \\text{\\textcolor[rgb]{.3,.6,.1}{\\$tart}} & \\textcolor{gray}{\\text{I}} & \\textcolor{gray}{\\text{am}} & \\textcolor{gray}{\\text{Sam}} & & \\textcolor{gray}{\\text{ham.}} & \\text{\\textcolor[rgb]{1,0,0}{\\$top}} \\\\\n\\begin{block}{c[ccccccc]}\n\\text{\\textcolor[rgb]{.3,.6,.1}{\\$tart}} & 0 & 0 & 0 & 0 & \\ldots & 0 & 0 \\topstrut\\\\\n\\textcolor{gray}{\\text{I}}        & 3/4 & 0 & 0 & 2/3 & \\ldots & 0 & 0\\\\\n\\textcolor{gray}{\\text{am}}       & 0 & 1/5 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\textcolor{gray}{\\text{Sam}}      & 0 & 0 & 1 & 1/3 & \\ldots & 0 & 0\\\\\n& \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots\\\\\n\\textcolor{gray}{\\text{ham.}}     & 0 & 0 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{\\textcolor[rgb]{1,0,0}{\\$top}}    & 0 & 0 & 0 & 0 & \\ldots & 1 & 1 \\botstrut\\\\\n\\end{block}\\end{blockarray}.\n\\end{align*}\n\nThe $3/4$ indicates that 3 out of 4 times, the sentences in the training set start with the word ``I''.\nSimilarly, the $2/3$ and $1/3$ says that ``Sam'' is followed by ``I'' twice and by ``Sam'' once in the training set.\nNote that ``am'' (without a period) always transitions to ``Sam'' and that ``ham.'' (with a period) always transitions the stop state.\n\nThe entire procedure of creating the transition matrix for the Markov chain with words from a file as states is summarized below.\n\n\\begin{algorithm}[H] % Read a file and convert it into a Markov chain.\n\\begin{algorithmic}[1]\n\\Procedure{MakeTransitionMatrix}{\\texttt{filename}}\n\\State Read the training set from the file \\texttt{filename}.\n\\State Get the set of unique words in the training set (the state labels).\n\\State Add labels \\li{\"\\$tart\"} and \\li{\"\\$top\"} to the set of states labels.\n\\State Initialize an appropriately sized square array of zeros to be the transition matrix.\n\\For {each sentence in the training set}\n    \\State Split the sentence into a list of words.\n    \\State Prepend \\li{\"\\$tart\"} and append \\li{\"\\$top\"} to the list of words.\n    \\For {each consecutive pair $(x, y)$ of words in the list of words}\n    \\State Add 1 to the entry of the transition matrix that corresponds to \\par\\qquad\\qquad transitioning from state $x$ to state $y$.\n    \\EndFor\n\\EndFor\n\\State Make sure the stop state transitions to itself.\n\\State Normalize each column by dividing by the column sums.\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Convert a training set of sentences into a Markov chain.}\n\\label{alg:MarkovSentencesTransitionMatrix}\n\\end{algorithm}\n\n\\begin{problem} % SentenceGenerator.__init__()\n\\label{prob:markov-random-sentences-init}\nWrite a class called \\li{SentenceGenerator} that inherits from the \\li{MarkovChain} class.\nThe constructor should accept a filename (the training set).\nRead the file and build a transition matrix from its contents as described in Algorithm \\ref{alg:MarkovSentencesTransitionMatrix}.\nSave the same attributes as the constructor of \\li{MarkovChain} does so that inherited methods work correctly.\nAssume that the training set has one complete sentence written on each line.\n\\\\(Hint: if the contents of the file are in the string \\li{s}, then \\li{s.split()} is the list of words and \\li{s.split('\\n')} is the list of sentences.)\n\\end{problem}\n\n\\begin{info} % The steady state is the stop state.\nThe Markov chains that result from the procedure in Problem \\ref{prob:markov-random-sentences-init} have a few interesting structural characteristics.\nThe stop state is a \\emph{sink}, meaning it only transitions to itself.\nBecause of this, and since every node has a path to the stop state, any traversal of the chain will end up in the stop state forever.\nThe stop state is therefore called an \\emph{absorbing state}, and the chain as a whole is called an \\emph{absorbing Markov chain}.\nFurthermore, the steady state is the vector with a $1$ in the entry corresponding to the stop state and $0$s everywhere else.\n\\end{info}\n\n\\begin{problem} % Create random sentences.\n\\label{prob:markov-random-sentences-babble}\nAdd a method to the \\li{SentenceGenerator} class called \\li{babble()}.\nUse the \\li{path()} method from Problem \\ref{prob:markov-class-walkers} to generate a random sentence based on the training document.\nThat is, generate a path from the start state to the stop state, remove the \\li{\"\\$tart\"} and \\li{\"\\$top\"} labels from the path, and join the resulting list together into a single, space-separated string.\n\nFor example, your \\li{SentenceGenerator} class should be able to create random sentences that sound somewhat like Yoda speaking.\n\n\\begin{lstlisting}\n>>> yoda = SentenceGenerator(\"yoda.txt\")\n>>> for _ in range(3):\n... \tprint(yoda.babble())\n...\n<<Impossible to my size, do not!\nFor eight hundred years old to enter the dark side of Congress there is.\nBut beware of the Wookiees, I have.>>\n\\end{lstlisting}\n\\end{problem}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Other Applications of Markov Chains} % ---------------------------\n\nMarkov chains are a useful way to study many probabilistic phenomena, so they have a wide variety of applications.\nThe following are just a few that are covered in other parts of this lab manual series.\n\\begin{itemize}\n\\item \\textbf{PageRank}: Google's PageRank algorithm uses a Markov chain-based approach to rank web pages.\nThe main idea is to use the entries of the steady state vector as a measure of importance for the corresponding states.\nFor example, the steady state $\\x = \\begin{bmatrix}2/3 & 1/3\\end{bmatrix}\\trp$ for the two-state weather model means that the hot state is ``more important'' (occurs more frequently) than the cold state.\nSee the PageRank lab in Volume 1.\n\n\\item \\textbf{MCMC Sampling}: A \\emph{Monte Carlo Markov Chain} (MCMC) method constructs a Markov chain whose steady state is a probability distribution that is difficult to sample from directly.\nThis provides a way to sample from nontrivial or abstract distributions.\nMany MCMC methods are used in various fields, from machine learning to physics.\nSee the Volume 3 lab on the Metropolis-Hastings algorithm.\n\n\\item \\textbf{Hidden Markov Models}: The Markov chain simulations in this lab use an initial condition (a state distribution vector $\\x_0$) and known transition probabilities to make predictions forward in time.\nConverseyl, a \\emph{hidden Markov model} (HMM) assumes that a given set of observations are the result of a Markov process, then uses those observations to infer the corresponding transition probabilities.\nHidden Markov models are used extensively in modern machine learning, especially for speech and language processing.\nSee the Volume 3 lab on Speech Recognition.\n\\end{itemize}\n\n\\subsection*{Large Training Sets} % -------------------------------------------\n\nThe approach in Problems \\ref{prob:markov-random-sentences-init} and \\ref{prob:markov-random-sentences-babble} begins to fail as the training set grows larger.\nFor example, a single Shakespearean play may not be large enough to cause memory problems, but \\emph{The Complete Works of William Shakespeare} certainly will.\n\nTo accommodate larger data sets, consider use a sparse matrix from \\li{scipy.sparse} for the transition matrix instead of a regular NumPy array.\nSpecifically, construct the transition matrix as a \\li{lil_matrix} (which is easy to build incrementally), then convert it to the \\li{csc_matrix} format (which supports fast column operations).\nEnsure that the process still works on small training sets, then proceed to larger training sets.\nHow are the resulting sentences different if a very large training set is used instead of a small training set?\n\n\\subsection*{Variations on the English Model} % -------------------------------\n\nChoosing a different state space for the English Markov model produces different results.\nConsider modifying the \\li{SentenceGenerator} class so that it can determine the state space in a few different ways.\nThe following ideas are just a few possibilities.\n\n\\begin{itemize}\n\\item Let each punctuation mark have its own state.\nIn the Dr. Seuss training set, instead of having two states for the words ``ham?'' and ``ham.'', there would be three states: ``ham'', ``?'', and ``.'', with ``ham'' transitioning to both punctuation states.\n\n\\item Model paragraphs instead of sentences.\nAdd a \\textcolor[rgb]{0,.6,0}{\\$tartParagraph} state that always transitions to \\textcolor[rgb]{0,.6,0}{\\$tartSentence} and a \\textcolor{red}{\\$topParagraph} state that is sometimes transitioned to by \\textcolor{red}{\\$topSentence}.\n\n\\item Let the states be individual letters instead of individual words.\nBe sure to include a state for the spaces between words.\n% We will explore this particular state space choice more in Volume 3 with hidden Markov models.\n\n\\item Construct the state space so that the next state depends on both the current and previous states.\nThis kind of Markov chain is called a \\emph{Markov chain of order 2}.\nThis way, every set of three consecutive words in a randomly generated sentence should be part of the training set, as opposed to only every consecutive pair of words coming from the set.\n\n\\item Instead of generating random sentences from a single source, simulate a random conversation between $n$ people.\nConstruct a Markov chain $M_i,$ for each person, $i=1,\\ \\ldots,\\ n$, then create a Markov chain $C$ describing the conversation transitions from person to person; in other words, the states of $C$ are the $M_i$.\nTo create the conversation, generate a random sentence from the first person using $M_1$.\nThen use $C$ to determine the next speaker, generate a random sentence using their Markov chain, and so on.\n\\end{itemize}\n\n\\subsection*{Natural Language Processing Tools} % -----------------------------\n\nThe Markov model of Problems \\ref{prob:markov-random-sentences-init} and \\ref{prob:markov-random-sentences-babble} is a \\emph{natural language processing} application.\nPython's \\li{nltk} module (natural language toolkit) has many tools for parsing and analyzing text for these kinds of problems \\cite{bird2004nltk}.\nFor example, \\li{nltk.sent_tokenize()} reads a single string and splits it up into sentences.\nThis could be useful, for example, in making the \\li{SentenceGenerator} class compatible with files that do not have one sentence per line.\n\n\\begin{lstlisting}\n>>> from nltk import sent_tokenize\n>>> with open(\"yoda.txt\", 'r') as yoda:\n...     sentences = sent_tokenize(yoda.read())\n...\n>>> print(sentences)\n<<['Away with your weapon!',\n 'I mean you no harm.',\n 'I am wondering - why are you here?',\n ...>>\n\\end{lstlisting}\n\nThe \\li{nltk} module is \\textbf{not} part of the Python standard library.\nFor instructions on downloading, installing, and using \\li{nltk}, visit \\url{http://www.nltk.org/}.\n", "meta": {"hexsha": "b3b3a3fd473ad7814c0dbd1d67c244c4e6735eab", "size": 37818, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume2/MarkovChains/MarkovChains.tex", "max_stars_repo_name": "chrismmuir/Labs-1", "max_stars_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 190, "max_stars_repo_stars_event_min_datetime": "2015-07-17T01:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T19:16:19.000Z", "max_issues_repo_path": "Volume2/MarkovChains/MarkovChains.tex", "max_issues_repo_name": "chrismmuir/Labs-1", "max_issues_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 184, "max_issues_repo_issues_event_min_datetime": "2015-07-16T17:56:06.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T23:47:14.000Z", "max_forks_repo_path": "Volume2/MarkovChains/MarkovChains.tex", "max_forks_repo_name": "chrismmuir/Labs-1", "max_forks_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 76, "max_forks_repo_forks_event_min_datetime": "2015-08-06T02:53:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T11:08:57.000Z", "avg_line_length": 62.6125827815, "max_line_length": 311, "alphanum_fraction": 0.7131789095, "num_tokens": 10809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.897695283896349, "lm_q1q2_score": 0.8096499377691725}}
{"text": "\\chapter{Summations}\n\n\\section{Summation formulas and properties}\n\n\\begin{enumerate}\n\n\\item[A.1{-}1] {Find a simple formula for $\\sum_{k = 1}^{n} (2k - 1)$.}\n\n\\begin{framed}\n\\begin{equation*}\n\\begin{aligned}\n  \\sum_{k = 1}^{n} (2k - 1) &= \\sum_{k = 1}^{n} 2k - \\sum_{k = 1}^{n} 1\\\\\n                            &= 2 \\sum_{k = 1}^{n} k - n\\\\\n                            &= 2 \\cdot \\frac{1}{2} n (n + 2) - n\\\\\n                            &= n^2 + n - n\\\\\n                            &= n^2.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[A.1{-}2] {($\\star$) Show that\n$\\sum_{k = 1}^{n} 1/(2k - 1) = \\ln(\\sqrt n) + O(1)$ by manipulating the harmonic\nseries.}\n\n\\begin{framed}\n\\begin{equation*}\n\\begin{aligned}\n  \\sum_{k = 1}^{n} 1/(2k - 1) &= \\frac{1}{1} + \\frac{1}{3} + \\frac{1}{5} + \\dots + \\frac{1}{2n - 3} + \\frac{1}{2n - 1}\\\\\n                              &= \\left(\\frac{1}{1} + \\frac{1}{2} + \\frac{1}{3} + \\dots + \\frac{1}{2n}\\right)\n                              - \\frac{1}{2} \\left(1 + \\frac{1}{2} + \\frac{1}{3} + \\dots + \\frac{1}{n}\\right)\\\\\n                              &= \\sum_{k = 1}^{2n} \\frac{1}{k} - \\frac{1}{2} \\sum_{k - 1}^{n} \\frac{1}{k}\\\\\n                              &= \\ln{2n} + O(1) - \\frac{1}{2} (\\ln n + O(1))\\\\\n                              &= \\ln n + \\ln 2 + O(1) - \\frac{1}{2} \\ln n - \\frac{1}{2} O(1)\\\\\n                              &= \\frac{1}{2} \\ln n + O(1)\\\\\n                              &= \\ln(\\sqrt n) + O(1).\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[A.1{-}3] {Show that $\\sum_{k = 0}^{\\infty} k^2 x^k = x(1 + x)/(1 - x)^3$\nfor $0 < |x| < 1$.}\n\n\\begin{framed}\nFrom Equation A.8, we have\n\\[\n  \\sum_{k = 0}^{\\infty} k x^k = \\frac{x}{(1 - x)^2}.\n\\]\ndifferentiating both sides and multiplying by $x$, we have\n\\begin{equation*}\n\\begin{aligned}\n  \\sum_{k = 0}^{\\infty} k^2 x^k &= x \\cdot \\frac{1 \\cdot (1 - x)^2 - (2 \\cdot (1 - x) \\cdot (-1) \\cdot x)}{(1 - x)^4}\\\\\n                                &= x \\cdot \\frac{(1 - x)(1 - x) + (1 - x) \\cdot 2x}{(1 - x)^4}\\\\\n                                &= x \\cdot \\frac{(1 - x) + 2x}{(1 - x)^3}\\\\\n                                &= \\frac{x(1 + x)}{(1 - x)^3}.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\newpage\n\n\\item[A.1{-}4] {($\\star$) Show that $\\sum_{k = 0}^{\\infty} (k - 1)/2^k = 0$.}\n\n\\begin{framed}\n\\begin{equation*}\n\\begin{aligned}\n  \\sum_{k = 0}^{\\infty} (k - 1)/2^k\n  &= \\sum_{k = 0}^{\\infty} \\left( \\frac{k}{2^k} - \\frac{1}{2^k} \\right)\\\\\n  &= \\sum_{k = 0}^{\\infty} k \\frac{1}{2^k} - \\sum_{k = 0}^{\\infty} \\frac{1}{2^k}\\\\\n  &= \\sum_{k = 0}^{\\infty} k \\left( \\frac{1}{2} \\right)^k - \\sum_{k = 0}^{\\infty} \\left( \\frac{1}{2} \\right)^k\\\\\n  &= \\frac{(1/2)}{(1 - (1/2))^2} - \\frac{1}{1 - (1/2)}\\\\\n  &= \\frac{(1/2)}{1 - 1 - (1/4)} - 2\\\\\n  &= 4/2 - 2\\\\\n  &= 0.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[A.1{-}5] {($\\star$) Evaluate the sum\n$\\sum_{k = 1}^{\\infty} (2k + 1) x^{2k}$ for $|x| < 1$.}\n\n\\begin{framed}\n\\begin{equation*}\n\\begin{aligned}\n  \\sum_{k = 1}^{\\infty} (2k + 1) x^{2k}\n  &= \\frac{d}{dx} \\cdot \\sum_{k = 1}^{\\infty} x^{2k + 1}\\\\\n  &= \\frac{d}{dx} \\cdot x \\cdot \\sum_{k = 1}^{\\infty} x^{2k}\\\\\n  &= \\frac{d}{dx} \\cdot x \\cdot \\sum_{k = 0}^{\\infty} (x^2)^k - x\\\\\n  &= \\frac{d}{dx} \\cdot x \\cdot \\frac{1}{1 - x^2} - x\\\\\n  &= \\frac{d}{dx} \\cdot \\frac{x - x (1 - x^2)}{1 - x^2}\\\\\n  &= \\frac{d}{dx} \\cdot \\frac{x^3}{1 - x^2}\\\\\n  &= \\frac{3 x^2 (1 - x^2) - (-2x) x^3}{(1 - x^2)^2}\\\\\n  &= \\frac{3 x^2 - 3 x^4 + 2 x^4}{(1 - x^2)^2}\\\\\n  &= \\frac{(3 - x^2) \\cdot x^2}{(1 - x^2)^2}.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[A.1{-}6] {Prove that\n$\\sum_{k=1}^{n} O(f_k(i)) = O(\\sum_{k = 1}^{n} f_k(i))$ by using the linearity\nproperty of summations.}\n\n\\begin{framed}\nSkipped.\n\\end{framed}\n\n\\newpage\n\n\\item[A.1{-}7] {Evaluate the product $\\prod_{k = 1}^{n} 2 \\cdot 4^k$.}\n\n\\begin{framed}\nWe have\n\\[\n  \\prod_{k = 1}^n (2 \\cdot 4^k) = 2^{\\lg{\\left(\\prod_{k = 1}^n (2 \\cdot 4^k)\\right)}},\n\\]\nand\n\\begin{equation*}\n\\begin{aligned}\n  \\lg{\\left(\\prod_{k = 1}^n (2 \\cdot 4^k)\\right)}\n  &= \\sum_{k = 1}^{n} \\lg (2 \\cdot 2^{2k})\\\\\n  &= \\sum_{k = 1}^{n} \\lg 2^{2k + 1}\\\\\n  &= \\sum_{k = 1}^{n} (2k + 1)\\\\\n  &= 2 \\sum_{k = 1}^n k + \\sum_{k = 1}^n 1\\\\\n  &= n (n + 1) + n\\\\\n  &= n (n + 2).\n\\end{aligned}\n\\end{equation*}\n\nThus,\n\\[\n  \\prod_{k = 1}^n (2 \\cdot 4^k) = 2^{n (n + 2)}.\n\\]\n\\end{framed}\n\n\\item[A.1{-}8] {($\\star$) Evalute the product $\\prod_{k = 2}^{n} (1 - 1/k^2)$.}\n\n\\begin{framed}\nWe have\n\\[\n  \\prod_{k = 2}^{n} \\left(1 - \\frac{1}{k^2}\\right) = 2^{\\lg{\\left( \\sum_{k = 2}^{n} \\lg{(1 - 1/k^2)} \\right)}},\n\\]\nand\n\\begin{equation*}\n\\begin{aligned}\n  \\sum_{k = 2}^{n} \\lg{\\left(1 - \\frac{1}{k^2}\\right)}\n  &= \\sum_{k = 2}^{n} \\lg{\\left( \\frac{k^2 - 1}{k^2} \\right)}\\\\\n  &= \\sum_{k = 2}^{n} \\lg{\\left( \\frac{(k - 1)}{k} \\cdot \\frac{(k + 1)}{k} \\right)}\\\\\n  &= \\sum_{k = 2}^{n} \\left( \\lg \\left( \\frac{k - 1}{k} \\right) + \\lg \\left( \\frac{k + 1}{k} \\right) \\right)\\\\\n  &= \\lg{\\frac{1}{2}} + \\lg{\\frac{3}{2}} +\n     \\lg{\\frac{2}{3}} + \\lg{\\frac{4}{3}} +\n     \\lg{\\frac{3}{4}} + \\lg{\\frac{5}{4}} +\n     \\dots +\n     \\lg{\\frac{n - 2}{n - 1}} + \\lg{\\frac{n}{n - 1}} +\n     \\lg{\\frac{n - 1}{n}} + \\lg{\\frac{n + 1}{n}}\\\\\n  &= \\lg 1 - \\lg 2 + \\cancel{\\lg 3} - \\cancel{\\lg 2} + \\cancel{\\lg 2} - \\cancel{\\lg 3}\n           + \\cancel{\\lg 4} - \\cancel{\\lg 3} + \\cancel{\\lg 3} - \\cancel{\\lg 4} + \\cancel{\\lg 5} - \\cancel{\\lg 4} + \\dots\\\\\n  & \\qquad + \\cancel{\\lg (n - 2)} - \\cancel{\\lg (n - 1)} + \\cancel{\\lg n} - \\cancel{\\lg (n - 1)}\n           + \\cancel{\\lg (n - 1)} - \\cancel{\\lg n} + \\lg (n + 1) - \\lg n\\\\\n  &= 0 - 1 + \\lg (n + 1) - \\lg n\\\\\n  &= \\lg (n + 1) - \\lg (n) - 1.\n\\end{aligned}\n\\end{equation*}\n\nThus,\n\\[\n  \\prod_{k = 2}^{n} \\left(1 - \\frac{1}{k^2}\\right) = 2^{(\\lg (n + 1) - (\\lg (n) + 1))}\n  = \\frac{2^{\\lg{(n + 1)}}}{2^{\\lg{(n) + 1}}}\n  = \\frac{n + 1}{2^{\\lg n} \\cdot 2}\n  = \\frac{n + 1}{2n}.\n\\]\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{Bounding summations}\n\n\\begin{enumerate}\n\n\\item[A.2{-}1] {Show that $\\sum_{k = 1}^{n} 1/k^2$ is bounded above by\na constant.}\n\n\\begin{framed}\n\\begin{equation*}\n\\begin{aligned}\n  \\sum_{k = 1}^{n} &=   1 + \\sum_{k = 2}^{n} \\frac{1}{k^2}\\\\\n                   &\\le 1 + \\int_{1}^{n} \\frac{dx}{x^2}\\\\\n                   &=   1 + \\left( \\Eval{- \\frac{1}{x}}{1}{n} \\right)\\\\\n                   &=   1 + \\left( - \\frac{1}{n} - \\left( - \\frac{1}{1} \\right) \\right)\\\\\n                   &= 2 - \\frac{1}{n}\\\\\n                   &\\le 2.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[A.2{-}2] {Find an asymptotic upper bound on the summation\n\\[\n  \\sum_{k = 0}^{\\floor{\\lg n}} \\ceil{n/2^k}.\n\\]\n}\n\n\\begin{framed}\n\\begin{equation*}\n\\begin{aligned}\n  \\sum_{k = 0}^{\\floor{\\lg n}} \\Bigl\\lceil \\frac{n}{2^k} \\Bigr\\rceil\n  &=   n \\cdot \\sum_{k = 0}^{\\floor{\\lg n}}  \\Bigl\\lceil \\frac{1}{2^k} \\Bigr\\rceil\\\\\n  &\\le n \\cdot \\sum_{k = 0}^{\\lg n}  \\left( \\frac{1}{2^k} + 1 \\right)\\\\\n  &=   n \\cdot \\sum_{k = 0}^{\\lg n}  \\left( \\frac{1}{2^k} \\right) + \\sum_{k = 0}^{\\lg n} 1\\\\\n  &=   n \\cdot \\frac{1}{1 - (1/2)} + \\lg n + 1\\\\\n  &=   2n + \\lg n + 1\\\\\n  &=   O(n).\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\item[A.2{-}3] {Show that the $n$th harmonic number is $\\Omega(\\lg n)$ by\nsplitting the summation.}\n\n\\begin{framed}\n\\begin{equation*}\n\\begin{aligned}\n  \\sum_{k = 1}^n \\frac{1}{k} &\\ge \\sum_{i = 0}^{\\floor{\\lg n} - 1} \\sum_{j = 0}^{2^i - 1} \\frac{1}{2^i + j}\\\\\n                             &\\ge \\sum_{i = 0}^{\\floor{\\lg n} - 1} \\sum_{j = 0}^{2^i - 1} \\frac{1}{2^{i + 1}}\\\\\n                             &=   \\sum_{i = 0}^{\\floor{\\lg n} - 1} \\frac{1}{2} \\cdot \\sum_{j = 0}^{2^i - 1} \\frac{1}{2^{i}}\\\\\n                             &=   \\sum_{i = 0}^{\\floor{\\lg n} - 1} \\frac{1}{2}\\\\\n                             &\\ge \\sum_{i = 0}^{\\lg n - 2} \\frac{1}{2}\\\\\n                             &=   \\frac{1}{2} (\\lg (n) - 1)\\\\\n                             &=   \\Omega(\\lg n).\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\newpage\n\n\\item[A.2{-}4] {Approximate $\\sum_{k = 1}^{n} k^3$ with an integral.}\n\n\\begin{framed}\nWe have\n\\[\n  \\int_{0}^{n} x^3 dx \\le \\sum_{k = 1}^{n} k^3 \\le \\int_{1}^{n + 1} x^3 dx.\n\\]\n\nFor a lower bound, we obtain\n\\[\n  \\sum_{k = 1}^{n} k^3 \\ge \\int_{0}^{n} x^3 dx = \\Eval{\\frac{x^4}{4}}{0}{n} = \\frac{n^4}{4} = \\Omega(n^4).\n\\]\n\nFor the upper bound, we obtain\n\\[\n  \\sum_{k = 1}^{n} k^3 \\le \\int_{1}^{n + 1} x^3 dx = \\Eval{\\frac{x^4}{4}}{1}{n + 1} = \\frac{(n + 1)^4 - 1}{4} = O(n^4).\n\\]\n\nThus,\n\\[\n  \\sum_{k = 1}^{n} k^3 = \\Theta(n^4).\n\\]\n\n\n\\end{framed}\n\n\\item[A.2{-}5] {Why didn't we use the integral approximation (A.12) directly on\n$\\sum_{k = 1}^{n} 1/k$ to obtain an upper bound on the $n$th harmonic number?}\n\n\\begin{framed}\nApplying (A.12) directly, we obtain\n\\[\n  \\sum_{k = 1}^{n} \\frac{1}{k} \\le \\int_{0}^{n} \\frac{1}{x} dx,\n\\]\nbut the function $1/x$ is undefined for $x = 0$ (because of the division by\nzero).\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section*{Problems}\n\\addcontentsline{toc}{section}{\\protect\\numberline{}Problems}%\n\n\\begin{enumerate}\n\n\\item[A{-}1]{\\textbf{\\emph{Bounding summations}}\\\\\nGive asymptotically tight bounds on the following summations. Assume that\n$r \\ge 0$ and $s \\ge 0$ are constants.\n\\begin{enumerate}\n  \\item[a.] $\\sum_{k = 1}^{n} k^r$.\n  \\item[b.] $\\sum_{k = 1}^{n} \\lg^s k$.\n  \\item[c.] $\\sum_{k = 1}^{n} k^r \\lg^s k$.\n\\end{enumerate}\n}\n\n\\begin{framed}\n\\begin{enumerate}\n\\item[(a)] For a lower bound, we have\n\\begin{equation*}\n\\begin{aligned}\n  \\sum_{k = 1}^{n} k^r &\\ge \\int_{0}^{n} x^r dx\\\\\n                       &=   \\Eval{\\frac{x^{(r + 1)}}{r + 1}}{0}{n}\\\\\n                       &=   \\frac{n^{(r + 1)}}{r + 1} - \\frac{0^{(r + 1)}}{r + 1}\\\\\n                       &\\ge n^{(r + 1)}\\\\\n                       &=   \\Omega(n^{(r + 1)}),\n\\end{aligned}\n\\end{equation*}\nand for the upper bound, we have\n\\[\n  \\sum_{k = 1}^{n} k^r \\le \\sum_{k = 1}^{n} n^r = n^{(r + 1)} = O(n^{(r + 1)}).\n\\]\n\nThus,\n\\[\n  \\sum_{k = 1}^{n} = \\Theta(n^{(r + 1)}).\n\\]\n\n\\item[(b)] For a lower bound, we have\n\\begin{equation*}\n\\begin{aligned}\n  \\sum_{k = 1}^{n} \\lg^{s} k &=   \\sum_{k = 1}^{n/2} \\lg^{s} k + \\sum_{k = n/2 + 1}^{n} \\lg^{s} k\\\\\n                             &\\ge \\sum_{k = 1}^{n/2} 0 + \\sum_{k = n/2 + 1}^{n} \\lg^{s}{\\left(\\frac{n}{2}\\right)}\\\\\n                             &=   \\frac{n}{2} \\lg^{s}{\\left(\\frac{n}{2}\\right)}\\\\\n                             &=   \\frac{n}{2} \\lg^{s}{n} - \\frac{n}{2} \\lg^{s}{2}\\\\\n                             &\\ge \\frac{1}{2} n \\lg^{s} n - \\frac{1}{2} n\\\\\n                             &=   \\Omega(n \\lg^s n),\n\\end{aligned}\n\\end{equation*}\nand for the upper bound, we have\n\\[\n  \\sum_{k = 1}^{n} \\lg^{s} k \\le \\sum_{k = 1}^{n} \\lg^{s} n = n \\lg^s n = O(n \\lg^s n).\n\\]\nThus,\n\\[\n  \\sum_{k = 1}^{n} \\lg^{s} k = \\Theta(n \\lg^s n).\n\\]\n\n\\item[(c)] It is easy to see that this summation is greater than the one from\nitem (a). Thus, it is $\\Omega(n^{(r + 1)})$. Also, we have\n\\[\n  \\sum_{k = 1}^{n} k^r \\lg^{s} k \\le \\sum_{k = 1}^{n} n^r \\lg^{s} n = O(n^{(r + 1)} \\lg^s n).\n\\]\n\nThus, I guess it is $\\Theta(n^{(r + 1)} \\lg^s n)$.\n\n\\end{enumerate}\n\\end{framed}\n\n\\end{enumerate}\n", "meta": {"hexsha": "3f86877b0acf0e06251cd6f6cd88b2d0679a0377", "size": 10957, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/AA.tex", "max_stars_repo_name": "danielmoraes/clrs", "max_stars_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-07-08T17:39:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-08T17:39:19.000Z", "max_issues_repo_path": "chapters/AA.tex", "max_issues_repo_name": "danielmoraes/clrs", "max_issues_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-31T20:41:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-31T20:41:48.000Z", "max_forks_repo_path": "chapters/AA.tex", "max_forks_repo_name": "danielmoraes/clrs", "max_forks_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-03-12T04:51:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T04:51:51.000Z", "avg_line_length": 31.6676300578, "max_line_length": 125, "alphanum_fraction": 0.4539563749, "num_tokens": 5058, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8962513835254865, "lm_q1q2_score": 0.8095786778224036}}
{"text": "\\section{The fundamental theorem of algebra}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the complex roots of a quadratic polynomial.\n  \\item In special cases, find the complex roots of a polynomial of\n    degree 3 or more.\n  \\item Factor a polynomial into linear factors.\n  \\end{enumerate}\n\\end{outcome}\n\nThe complex numbers were invented so that equations such as $z^2+1=0$\nwould have solutions. In fact, this equation has two complex\nsolutions, namely $z=i$ and $z=-i$. However, something much more\ngeneral (and surprising) is true: {\\em every} non-trivial polynomial\nequation has a solution in the complex numbers. To understand this\nstatement, recall that a \\textbf{polynomial}%\n\\index{polynomial} is an expression of the form\n\\begin{equation*}\n  p(z) = a_nz^n + a_{n-1}z^{n-1} + \\ldots + a_1z + a_0.\n\\end{equation*}\nThe constants $a_0,\\ldots,a_n$ are called the \\textbf{coefficients}%\n\\index{coefficient!of a polynomial}%\n\\index{polynomial!coefficient} of the polynomial. If $a_n$ is the\nlargest non-zero coefficient, we say that the polynomial has\n\\textbf{degree}%\n\\index{degree!of a polynomial}%\n\\index{polynomial!degree} $n$. A polynomial of degree $0$ is of the\nform $p(z) = a_0$, and is also called a \\textbf{constant polynomial}%\n\\index{polynomial!constant}%\n\\index{constant polynomial}. Recall that a \\textbf{root}%\n\\index{root!of a polynomial}%\n\\index{polynomial!root} of a polynomial is a number $z$ such that\n$p(z)=0$.  The fundamental theorem of algebra is the following:\n\n\\begin{theorem}{Fundamental theorem of algebra}{fundamental-algebra}\n  Every non-constant polynomial $p(z)$ with real or complex\n  coefficients has a complex root.\n\\end{theorem}\n\nThe proof of this theorem is beyond the scope of this book. Note that\nthe theorem does not say that the roots are always easy to find. To\nfind the roots of a polynomial of degree 2, we can use the quadratic\nformula. However, if the degree is greater than 2, we may sometimes\nhave to use fancier methods, such as Newton's method from calculus, or\neven a computer algebra system, to locate the roots. We give some\nexamples.\n\n\\begin{example}{Roots of a quadratic polynomial}{complex-root}\n  Find the roots of the polynomial $p(z) = z^2 - 2z + 2$.\n\\end{example}\n\n\\begin{solution}\n  The quadratic formula gives\n  \\begin{equation*}\n    z = \\frac{2 \\pm \\sqrt{-4}}{2}.\n  \\end{equation*}\n  Of course, in the real numbers, the square root of $-4$ does not\n  exist, so $p(z)$ has no roots in the real numbers. However, in the\n  complex numbers, the square root of $-4$ exists and is equal to\n  $\\pm2i$. Thus, the roots of $p(z)$ are:\n  \\begin{equation*}\n    z = \\frac{2 \\pm 2i}{2} = 1\\pm i.\n  \\end{equation*}\n  Indeed, we can double-check that $1+i$ and $1-i$ are in fact roots:\n  \\begin{equation*}\n    \\begin{array}{ll}\n      p(1+i) = (1+i)^2 - 2(1+i) + 2 = (1 + 2i + (-1)) - 2 - 2i + 2 = 0, \\\\\n      p(1-i) = (1-i)^2 - 2(1-i) + 2 = (1 - 2i + (-1)) - 2 + 2i + 2 = 0. \\\\\n    \\end{array}\n  \\end{equation*}\n  \\vspace{-2ex}\n\\end{solution}\n\n\\begin{example}{Roots of a cubic polynomial}{complex-root2}\n  Find the roots of the polynomial $p(z) = z^3 - 4z^2 + 9z - 10$.\n\\end{example}\n\n\\begin{solution}\n  By the intermediate value theorem of calculus, we know that a cubic\n  polynomial with real coefficients always has at least one real\n  root. This is because $p(z)$ goes to $-\\infty$ when $z\\to-\\infty$\n  and to $\\infty$ when $z\\to\\infty$. By trial and error, we find that\n  $z=2$ is a root of this polynomial. We can therefore factor out\n  $(z-2)$ from this polynomial:\n  \\begin{equation*}\n    p(z) = z^3 - 4z^2 + 9z - 10 = (z-2)(z^2 - 2z + 5).\n  \\end{equation*}\n  Now we can use the quadratic formula to find the roots of $z^2 - 2z\n  + 5$. We find\n  \\begin{equation*}\n    z = \\frac{2\\pm\\sqrt{-16}}{2} = \\frac{2\\pm 4i}{2} = 1\\pm 2i.\n  \\end{equation*}\n  Thus, the three complex roots of $p(z)$ are $z=2$, $z=1+2i$, and $z=1-2i$.\n\\end{solution}\n\nThe following proposition is an important and useful consequence of\nthe fundamental theorem of algebra:\n\n\\begin{proposition}{Factoring a polynomial}{complex-factoring}\n  Let $p(z)$ be a polynomial of degree $n$ with real or complex\n  coefficients. Then $p(z)$ can be factored into $n$ linear factors\n  over the complex numbers, i.e., $p(z)$ can be written in the form\n  \\begin{equation*}\n    p(z) = a(z-b_1)(z-b_2)\\cdots(z-b_n),\n  \\end{equation*}\n  where $b_1,\\ldots,b_n$ are (not necessarily distinct) roots of\n  $p(z)$.\n\\end{proposition}\n\n\\begin{proof}\n  If $n=0$, then $p(z)=a$ and there is nothing to show. Otherwise, by\n  the fundamental theorem of algebra, $p(z)$ has at least one complex\n  root, say $b_1$. From calculus, we know that we can factor out\n  $(z-b_1)$ from $p(z)$, i.e., we can find a polynomial $q(z)$ of\n  degree $n-1$ such that\n  \\begin{equation*}\n    p(z) = (z-b_1) q(z),\n  \\end{equation*}\n  We can repeatedly apply the same procedure to $q(z)$ until $p(z)$\n  has been factored into linear factors.\n\\end{proof}\n\n\\begin{example}{Factoring a polynomial}{complex-factoring}\n  Factor $p(z) = z^3 - 4z^2 + 9z - 10$ into linear factors.\n\\end{example}\n\n\\begin{solution}\n  From Example~\\ref{exa:complex-root2}, we know that $p(z)$ has three\n  distinct roots $b_1=2$, $b_2=1+2i$, and $b_3=1-2i$. We can therefore\n  write\n  \\begin{equation*}\n    p(z) = a(z-b_1)(z-b_2)(z-b_3).\n  \\end{equation*}\n  Since the leading term is $z^3$, we find that $a=1$. Therefore\n  \\begin{equation*}\n    p(z) = (z-2)\\,(z-1-2i)\\,(z-1+2i).\n  \\end{equation*}\n  \\vspace{-2ex}\n\\end{solution}\n", "meta": {"hexsha": "aa086d0bd1ec523756f0d6afe6c81e6eb7c901b1", "size": 5485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/ComplexNumbers-FundamentalTheorem.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/ComplexNumbers-FundamentalTheorem.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/ComplexNumbers-FundamentalTheorem.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 38.9007092199, "max_line_length": 76, "alphanum_fraction": 0.6827711942, "num_tokens": 1839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.9124361580958427, "lm_q1q2_score": 0.8095175563787116}}
{"text": "\\section{Secret Sharing}\\label{s:secret-sharing}\nSecret sharing is a method for distributing a secret between $N$ different parties, where a secret message $m$ is divided into parts, giving each participant its own unique part $(s_1, s_2, \\dots, s_N)$.\nCombining some of the parts or all of them are needed in order to reconstruct the original secret.\nThe most common type of secret sharing is a scheme with one dealer and $N$ different players.\nInitially, the dealer splits the secret to shares and gives each player a split.\nOnly with all -- or most of the shares $k \\geq T$  ($T$ is a threshold) -- someone is able to reconstruct the original secret.\nThe dealer accomplishes this by giving each player a share in such a way that any group of $T$ or more players can together reconstruct the secret but no group of fewer than $T$ players can.\nSuch a system is called a $(T, N)$ - threshold scheme.\n\nA naive secret sharing scheme between a dealer and two parties is to apply bitwise \\texttt{XOR} to the secret and a random string of the same length.\nFor the sake of simplicity, let us assume that the secret message m is a string of 5 bits (either 0 or 1), \\textit{e.g.} 01101.\nThen, the dealer generates a random string of 5 bits $s_1$ (\\textit{e.g.} $10011$) and performs the \\texttt{XOR} operation between $s_1$ and $m$; a string $s_2 = 11110$ arises.\nFinally, the dealer gives the $s_1$ and $s_2$ to the two parties.\nNeither one of them is able to retrieve the secret message $m$ without the other half share, and also nor is able to retrieve any information about the original message.\n\nThere exist more complex and elaborate systems for more than two parties, such as Shamir\u2019s \\cite{shamir1979share}, Blakley\u2019s \\cite{blakley1994linear}, or Additive \\cite{kim2003designs} secret sharing schemes.\n\n\n\\subsection{Shamir Secret Sharing}\\label{ss:shamir-secret-sharing}\nSecret sharing was proposed in \\cite{shamir1979share} by Shamir, and it was the first method to enable distribution of a secret to $N$ parties.\nA secret message $m$ is divided into $N$ parts, giving each participant its own unique part, where any $T$ subset of $N$ can recover the secret, but no $T-1$ element subset can.\n\nAdi Shamir's threshold scheme is based on the idea of polynomial interpolation -- the interpolation of a given dataset by the polynomial of lowest possible degree that passes through the points of the dataset --, using Lagrange coefficients.\nShamir's secret sharing scheme constructs a polynomial $P$ of degree $N-1$, where $N$ is the number of players, as follows.\n\n\n\\subsubsection{Algorithm}\\label{sss:shamir-algorithm}\n\\begin{itemize}\n  \\item Dealer chooses a random polynomial of degree $N - 1$ so that $P(0) = m$, where $m$ is the secret message, and also the number $T$ of sufficient subsets that can reconstruct the secret.\n\n  \\textit{For example\\footnote{This example is based on a similar example in \\url{https://en.wikipedia.org/wiki/Shamir's_Secret_Sharing} Wikipedia link.}}, let us suppose our secret message $m = 1234$ and $N = 6$ parties, but any subset of $T = 3$ is sufficient to reconstruct the secret.\n  Then our polynomial should have degree 2, $f(x) = ax^2 + bx + m$.\n  The dealer chooses $N - 1$ random numbers, \\textit{i.e.} $a = 94$ and $b = 166$, thus our polynomial is $f(x) = 94x^2 + 166x + 1234$.\n\n\n  \\item Dealer distributes $N$ pairs $(x_i , P(x_i)),$ $x_i \\neq 0$\n\n  First the dealer creates the $N$ pairs.\n  \\textit{For example}:\\\\\n  $D_0 = (1, 1494)$, $D_1 = (2, 1942)$, $D_2 = (3, 2578)$, $D_3 = (4, 3402)$, $D_4 = (5, 4414)$, $D_5 = (6, 5614)$ and consecutively he\\myslash she distributes them to the $N$ parties.\n\n\n  \\item $N$ players can reconstruct the polynomial $P$ with their pairs, however $N - 1$ cannot\n\n  In order to reconstruct the secret any $T$ points will be enough, \\textit{for instance}, $D_1, D_3$ and $D_4$.\n  Computing the Lagrange polynomials:\\\\\n  $l_0 = \\cfrac{x - x_1}{x_0 - x_1} \\times \\cfrac{x - x_2}{x_0 - x_2} = \\cfrac{x - 4}{2 - 4} \\times \\cfrac{x - 5}{2 - 5} = \\cfrac{1}{6}x^2 - \\cfrac{3}{2}x + \\cfrac{10}{3}$\n\n  $l_1 = \\cfrac{x - x_0}{x_1 - x_0} \\times \\cfrac{x - x_2}{x_1 - x_2} = \\cfrac{x - 2}{4 - 2} \\times \\cfrac{x - 5}{4 - 5} = \\cfrac{1}{2}x^2 + \\cfrac{7}{2}x - 5$\n\n  $l_2 = \\cfrac{x - x_0}{x_2 - x_0} \\times \\cfrac{x - x_1}{x_2 - x_1} = \\cfrac{x - 2}{5 - 2} \\times \\cfrac{x - 4}{5 - 4} = \\cfrac{1}{3}x^2 - 2x + \\cfrac{8}{3}$\n\n  Therefore:\n\n  $f(x) = \\sum_{i=0}^{2} y_i \\times l_i(x) = 94x^2 + 166x + 1234$\n\n  Each party can compute $f(0)$ in order to obtain the secret, in this case $f(0) = 1234$.\n\\end{itemize}\n\nIt is evident, that in Shamir's scheme two points are sufficient to define a line $f(x) = ax + b$, three points are sufficient to define a parabola $f(x) = ax^2 + bx + c$, four points to define a cubic curve $f(x) = ax^3 + bx^2 + cx + d$ and so forth.\nThat is, it takes $T$ points to define a polynomial of degree $T-1$, where $T - 1$ will be the sufficient number of parties that can reconstructed the secret message.\n\n\\subsubsection{Threat Model}\\label{sss:shamir-threat-model}\nThe Shamir secret sharing scheme can tolerate both passive and active adversaries, however in the latter case it has more strict bounds.\nShamir's sharing algorithm is secure against a passive adversary when $T < \\cfrac{N}{2}$, while it achieves information-theoretic security for $T < \\cfrac{N}{3}$ with an active adversary.\nThis means that even if the adversary has unbounded computational power, they cannot learn any information about the secret underlying a share.\nThe BGW \\cite{brakerski2014leveled} protocol, which defines how to compute addition and multiplication on secret shares, is often used to compute functions with Shamir secret shares.\n\n\n\n\\subsection{Additive Secret Sharing}\\label{ss:additive-secret-sharing}\nAnother form of secret sharing, and probably the simplest one, is additive sharing.\nAgain, a secret message $m$ is divided into $N$ parts, where each participant has its own unique part.\nIn contrast with Shamir's sharing algorithm, all parts are necessary in order to recover the original secret.\n\n\\subsubsection{Algorithm}\\label{sss:additive-algorithm}\n\\begin{itemize}\n\n  \\item Dealer chooses a randomly $N - 1$ numbers such that $x_i \\in \\mathbb{Z}, i \\in [1, N-1]$\n\n  \\item Computing $x_N$ from the random numbers is pretty trivial; $x_N = m - x_1 - x_2 - \\dots - x_{N-1}$\n\n  \\item Finally, the dealer distributes the $N$ secrets ($x_1, \\dots x_N$)\n\n  \\item In order to reconstruct the original message $m$, the parties have to combine their secrets: $m = x_1 + x_2 + \\dots + x_N$\n\\end{itemize}\n\nSeeing any $N-1$ values (\\textit{i.e.} $x_1, \\dots x_{N-1}$) does not give any clue about what $m$ could be, since the remaining $x_i$ may change the final result to any element of $\\mathbb{Z}$ with equal probability.\nMore elaborate schemes than the $(\\mathbb{Z}, +)$ have been introduced, in the form of $(A, \\oplus)$ (which means in group $A$ using the operation $\\oplus$), such as linear secret sharing.\n\nThere are many systems that have implemented various forms of SMPC with secret sharing schemes.\nThe most popular is SPDZ \\cite{damgaard2012multiparty, damgaard2013practical}, which implements MPC with additive secret shares and is secure against active adversaries.\nAnother popular system that implements SMPC using additive secret shares is the Sharemind Secure Computing Platform, which we survey in section \\ref{c:sharemind}.\n\n\n\\subsubsection{Threat Model}\\label{sss:additive-threat-model}\nIn contrast to Shamir's secret sharing scheme, that can tolerate up to $T < \\cfrac{N}{2}$ passive adversaries or $T < \\cfrac{N}{3}$ active, as mentioned in \\ref{sss:shamir-threat-model}, additive secret sharing schemes can tolerate the adversary controlling all but one party, that is $T < N$.\nAs we already mentioned, in order to reconstruct the original message $m$, all parties have to add their secrets ($m = x_1 + x_2 + \\dots + x_N$).\nIt has become evident, that if one $x_i$ is missing, the initial message $m$ cannot be reconstructed.\n% Additive schemes maintain security against a passive and active adversary with unbounded computational power.\n\n\n\n\\subsection{Secret Sharing Homomorphism}\\label{ss:secret-sharing-homomorphism}\nIn \\cite{benaloh1986secret}, Benaloh observed that many secret sharing schemes have a homomorphic property which allows multiple secrets to be combined by direct computation on shares.\n\nSuppose we have a secret $m$ that can be computed from $T$ sub-secrets $\\{m_i\\}^T_{i=1}$ using a functions $f$ as follows $m = f(m_1, \\dots, m_T)$.\nLet $\\oplus$ and $\\otimes$ be binary functions on elements of the secret domain $S$ and of the share domain $T$, respectively.\nWe say that a $(k, N)$ threshold scheme has the $(\\oplus, \\otimes)$-homomorphism property (or is $(\\oplus, \\otimes)$-homomorphic) if for all $f: T^k \\rightarrow S$, whenever a message\n\n\\hfil $m = f(m_1, \\dots, m_k)$\n\nand another message\n\n\\hfil  $m' = f(m'_1, \\dots, m'_k)$\n\nthen the composition of the shares are the shares of the composition:\n\n\\hfil $m \\oplus m' = f(m_1 \\otimes m'_1, \\dots, m_k \\otimes m'_k)$\n\n\nShamir\u2019s polynomial based secret sharing \\ref{ss:shamir-secret-sharing} scheme is $(+, +)$-homomorphic since the sum of the polynomials use to share the sub-secrets is itself a polynomial that can be used to deal shares of the super secret.\n\n\n", "meta": {"hexsha": "b58cf6758018c4fe659291b2a6419036f6f23522", "size": 9337, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "secret-sharing.tex", "max_stars_repo_name": "jimouris/master-thesis", "max_stars_repo_head_hexsha": "e424cdd458cb7ff964bebcaaecfb7cad5b3ea525", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2018-08-29T07:51:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-09T12:09:24.000Z", "max_issues_repo_path": "secret-sharing.tex", "max_issues_repo_name": "jimouris/master-thesis", "max_issues_repo_head_hexsha": "e424cdd458cb7ff964bebcaaecfb7cad5b3ea525", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "secret-sharing.tex", "max_forks_repo_name": "jimouris/master-thesis", "max_forks_repo_head_hexsha": "e424cdd458cb7ff964bebcaaecfb7cad5b3ea525", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-08-28T14:33:15.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-28T17:09:24.000Z", "avg_line_length": 74.696, "max_line_length": 293, "alphanum_fraction": 0.729998929, "num_tokens": 2734, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.8947894682067639, "lm_q1q2_score": 0.8094717689156665}}
{"text": "\n\\subsection{Axiom schema of specification}\n\n\\subsubsection{The axiom schema of unrestricted comprehension}\n\nWe want to formalise the relationship between the preterite and the set. An obvious way of doing this is to add an axiom for each preterite in our structure that:\n\n\\(\\forall x \\exists s[P(x)\\leftrightarrow (x\\in s)]\\)\n\nThis is known as \"unrestricted comprehension\" and there are problems with this approach.\n\nConsider a predicate for all terms which are not members of themselves. That is:\n\n\\(\\neg (x\\in x)\\)\n\nThis implies the following is true:\n\n\\(\\forall x\\exists s[\\neg (x\\in x) \\leftrightarrow (x\\in s)]\\)\n\nAs this is true for all \\(x\\), it is true for \\(x=s\\). So:\n\n\\(\\exists s[\\neg (s\\in s) \\leftrightarrow (s  \\in s)]\\)\n\nThis statement is false. As we have inferred a false formula, the axiom of unrestricted comprehension does not work. This result is known as Russel's Paradox.\n\nThis is an axiom schema rather than an axiom. That is, there is a new axiom for each preterite.\n\n\\subsubsection{Axiom schema of specification}\n\nTo resolve Russel's paradox, we amend the axiom schema to:\n\n\\(\\forall x \\forall a \\exists s[(P(x)\\land x\\in a )\\leftrightarrow (x\\in s)]\\)\n\nThat is, for every set \\(a\\), we can define a subset \\(s\\) for each predicate.\n\nThis resolves Russel's Paradox. Let's take the same steps on the above formula as in unrestricted comprehension;\n\n\\(\\forall x \\forall a \\exists s[(\\neg (x\\in x)\\land x\\in a )\\leftrightarrow (x\\in s)]\\)\n\n\\(\\exists s[(\\neg (s\\in s)\\land s\\in s )\\leftrightarrow (s\\in s)]\\)\n\nSo long as the subsets \\(s\\) are not members of themselves, this holds.\n\n", "meta": {"hexsha": "b1adb62c1f02dc833a9110f76919213f4fa3eecd", "size": 1606, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/setsSpecification/01-01-specification.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/setsSpecification/01-01-specification.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/setsSpecification/01-01-specification.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5, "max_line_length": 162, "alphanum_fraction": 0.7235367372, "num_tokens": 435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357703, "lm_q2_score": 0.8757869835428965, "lm_q1q2_score": 0.8093513842040015}}
{"text": "\n\\subsection{Ordered sets}\n\n\\subsubsection{Totally ordered sets}\n\nA totally ordered set is one where the relation is defined on all pairs:\n\n\\(\\forall a \\forall b\t(a\\le b)\\lor (b\\le a)\\)\n\nNote that totality implies reflexivity.\n\n\\subsubsection{Partially ordered sets (poset)}\n\nA partially ordered set, or poset, is one where the relation is defined between each element and itself.\n\n\\(\\forall a (a\\le a)\\)\n\nThat is, every element is related to itself.\n\nThese are also called posets.\n\n\\subsubsection{Well-ordering}\n\nA well-ordering on a set is a total order on the set where the set contains a minimum number. For example the relation \\(\\le \\) on the natural numbers is a well-ordering because \\(0\\) is the minimum.\n\nThe relation \\(\\le \\) on the integers however is not a well-ordering, as there is no minimum number in the set.\n\n", "meta": {"hexsha": "f23156430ab97781a39dd3db305bee8683ff423d", "size": 828, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/orderingInfinite/01-01-orderedSets.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/orderingInfinite/01-01-orderedSets.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/orderingInfinite/01-01-orderedSets.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5714285714, "max_line_length": 199, "alphanum_fraction": 0.7475845411, "num_tokens": 205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.809284322750578}}
{"text": "\\section{Simple Benchmark}\nTo better illustrate the benefits of GPUs we performed a few simple benchmarks:\nwe timed the MC calculation of $\\pi$ on a GPU using the Tensorflow (v2.5.0-2) package and compared it\nto an equivalent implementation using the NumPy (v1.20.3-1) package.\nAll benchmarks were performed on a Linux platform using a Ryzen 3700X CPU and an NVIDIA GTX 1070 GPU.\nThe CPU and GPU are roughly equal in terms of price and release date.\n\\subsection{Hit-And-Miss MC}\nThe calculation of $\\pi$ using hit-and-miss MC can be implemented with the following Python code:\n\\begin{lstlisting}\n@tf.function\ndef mc_tf(sample_size):\n    rand_xy = tf.random.uniform(\n\t(sample_size, 2))\n\n    # Map:\n    in_circle = tf.square(rand_xy[:, 0]) \\\n\t+ tf.square(rand_xy[:, 1]) < 1.0\n\n    # Reduce:\n    mc_estimate = tf.math.count_nonzero(\n\tin_circle) / sample_size\n\n    return 4 * mc_estimate\n\\end{lstlisting}\nNotably the entire calculation can be expressed as a combination of map and reduce operations,\nimplying that it can be efficiently parallelized on GPUs.\n\\begin{figure*}\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{pi_hit_and_miss_benchmark.png}\n\t\\caption{\n\t\tBenchmark of hit-and-miss MC.\n\t\tRuntime with NumPy is proportional to sample size.\n\t\tRuntime with Tensorflow is constant for $N \\le 10^7$.\n\t\tRuntime with Tensorflow is proportional to sample size for $N \\ge 10^9$\n\t\t(assuming Tensorflow is already initialized).\n\t}\n\t\\label{fig:pi_hit_and_miss_benchmark}\n\\end{figure*}\nFigure \\ref{fig:pi_hit_and_miss_benchmark} shows the result of the benchmark.\nThe runtime with NumPy (single CPU core) is proportional to sample size, indicating negligible overhead.\nThe runtime with Tensorflow (GPU) is flat for small sample sizes and proportional to sample size for large sample sizes,\nindicating significant overhead.\nFor small sample sizes NumPy is much faster than Tensorflow, for large sample sizes Tensorflow is much faster than NumPy.\n\nA large part of the GPU overhead is due to the initialization of the Tensorflow library which is several gigabytes in size.\nHowever, some overhead still remains when this is accounted for.\nThe reason for this overhead is the memory management described in section \\ref{sec:programming}.\nCompared to computation memory accesses are very slow.\nMemory transfers between system memory and GPU memory are even slower.\nTo execute the above code on a GPU the generated kernel needs to first be transferred to GPU memory.\nAfter executing code the result needs to be transferred back to system memory.\nFor small sample sizes the runtime is entirely dominated by the memory transfers,\nresulting in a runtime that is essentially constant.\nFor large sample sizes the time needed for memory transfers becomes negligible,\nresulting in a runtime that is proportional to sample size.\n\\subsection{Crude MC}\nThe calculation of $\\pi$ using crude MC can be implemented with the following Python code:\n\\begin{lstlisting}\n@tf.function\ndef mc_tf(sample_size):\n    rand_x = tf.random.uniform(\n\t(sample_size,))\n\n    # Map:\n    function_values = 1.0 - tf.math.sqrt(\n\t1.0 - tf.math.square(rand_x))\n\n    # Reduce:\n    mc_estimate = tf.reduce_mean(\n\tfunction_values)\n\n    return 4 * mc_estimate\n\\end{lstlisting}\nAgain, the entire calculation can be expressed as a combination of map and reduce operations.\n\\begin{figure*}\n\t\\includegraphics[width=\\linewidth]{pi_crude_benchmark.png}\n\t\\caption{\n\t\tBenchmark of crude MC.\n\t\tRuntime with NumPy is proportional to sample size.\n\t\tRuntime with Tensorflow (GPU) is constant for $N <= 10^7$.\n\t\tRuntime with Tensorflow (CPU and GPU) is proportional to sample size for $N >= 10^9$\n\t\t(assuming Tensorflow is already initialized).\n\t}\n\t\\label{fig:pi_crude_benchmark}\n\\end{figure*}\nFigure \\ref{fig:pi_crude_benchmark} shows the result of the benchmark.\nThe results for NumPy and Tensorflow (GPU) are essentially the same as for the hit-and-miss implementation.\nAdditionally to Tensorflow (GPU) we also benchmarked Tensorflow (CPU) to investigate the runtime\nof a multithreaded CPU implementation.\nJust like with Tensorflow (GPU) there is significant overhead that becomes negligible for large sample sizes.\nThe overhead is due to the cost associated with thread creation.\nAt least in this benchmark Tensorflow (GPU) was always faster than Tensorflow (CPU), particularly for large sample sizes.\n", "meta": {"hexsha": "325c3be4a103d7511ffb874fb53a90ca761c3c9f", "size": 4338, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX/Parts/05_benchmark.tex", "max_stars_repo_name": "JohannesGaessler/presentation_mc", "max_stars_repo_head_hexsha": "0d43f3b70d71f063f872a5fb8b09cde3b756ee36", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LaTeX/Parts/05_benchmark.tex", "max_issues_repo_name": "JohannesGaessler/presentation_mc", "max_issues_repo_head_hexsha": "0d43f3b70d71f063f872a5fb8b09cde3b756ee36", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LaTeX/Parts/05_benchmark.tex", "max_forks_repo_name": "JohannesGaessler/presentation_mc", "max_forks_repo_head_hexsha": "0d43f3b70d71f063f872a5fb8b09cde3b756ee36", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.6451612903, "max_line_length": 123, "alphanum_fraction": 0.7793914246, "num_tokens": 1025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.8856314692902446, "lm_q1q2_score": 0.8091806881320958}}
{"text": "\\chapter{Group actions overkill AIME problems}\nConsider this problem from the 1996 AIME:\n\\begin{quote}\n\t(AIME 1996) Two of the squares of a $7 \\times 7$ checkerboard are painted yellow, and the rest are painted green. Two color schemes are equivalent if one can be obtained from the other by applying a rotation in the plane of the board. How many inequivalent color schemes are possible?\n\\end{quote}\n\nWhat's happening here? Let $X$ be the set of the $\\binom{49}{2}$ possible colorings of the board.\nWhat's the natural interpretation of ``rotation''?\nAnswer: the group $\\Zc 4 = \\left<r \\mid r^4=1\\right>$ somehow ``acts'' on this set $X$ by sending one state $x \\in X$ to another state $r \\cdot x$, which is just $x$ rotated by $90\\dg$.\nIntuitively we're just saying that two configurations are the same if they can be reached from one another by this ``action''.\n\nWe can make all of this precise using the idea of a group action.\n\n\\section{Definition of a group action}\n\\prototype{The AIME problem.}\n\n\\begin{definition}\n\tLet $X$ be a set and $G$ a group.\n\tA \\vocab{group action} is a binary operation $\\cdot : G \\times X \\to X$\n\twhich lets a $g \\in G$ send an $x \\in X$ to $g \\cdot x$.\n\tIt satisfies the axioms\n\t\\begin{itemize}\n\t\t\\ii $(g_1g_2) \\cdot x = g_1 \\cdot (g_2 \\cdot x)$ for any $g_1, g_2 \\in G$\n\t\tfor all $x \\in X$.\n\t\t\\ii $1_G \\cdot x = x$ for any $x \\in X$.\n\t\\end{itemize}\n\\end{definition}\n\n\\begin{example}[Examples of group actions]\n\tLet $G=(G,\\star)$ be a group.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The group $\\Zc 4$ can act on the set of ways to color a $7 \\times 7$\n\t\tboard either yellow or green.\n\t\t\\ii The group $\\Zc4 = \\left<r \\mid r^4=1\\right>$ acts on the $xy$-plane $\\RR^2$ as follows: $r \\cdot (x,y) = (y,-x)$.\n\t\tIn other words, it's a rotation by $90\\dg$.\n\t\t\\ii The dihedral group $D_{2n}$ acts on the set of ways to color the vertices of an $n$-gon.\n\t\t\\ii The group $S_n$ acts on $X = \\left\\{ 1,2,\\dots,n \\right\\}$\n\t\tby applying the permutation $\\sigma$: $\\sigma \\cdot x \\defeq \\sigma(x)$.\n\t\t\\ii The group $G$ can act on itself (i.e.\\ $X=G$) by left multiplication: put $g \\cdot g' \\defeq g \\star g'$.\n\t\\end{enumerate}\n\\end{example}\n\n\\section{Stabilizers and orbits}\n\\prototype{Again the AIME problem.}\n\nGiven a group action $G$ on $X$,\nwe can define an equivalence relation $\\sim$ on $X$ as follows:\n$x \\sim y$ if $x = g \\cdot y$ for some $g \\in G$.\nFor example, in the AIME problem, $\\sim$ means ``one can be obtained from the other by a rotation''.\n\\begin{ques}\n\tWhy is this an equivalence relation?\n\\end{ques}\nIn that case, the AIME problem wants the number of equivalence classes under $\\sim$.\nSo let's give these equivalence classes a name: \\vocab{orbits}.\nWe usually denote orbits by $\\OO$.\n\nAs usual, orbits carve out $X$ into equivalence classes.\n\\begin{center}\n\t\\begin{asy}\n\t\tbigbox(\"$X$\");\n\t\tdraw(ellipse(origin,0.8,2.5));\n\t\tdraw(ellipse((-2,0),0.8,1.5));\n\t\tdraw(ellipse(( 2,0),0.8,2.25));\n\t\tfor (int i=-3; i<=3; ++i) {\n\t\t\tdot( (0, 0.7*i) );\n\t\t}\n\t\tdot( (-2,0) );\n\t\tdot( (-2,-1) );\n\t\tdot( (-2,1) );\n\t\tdot( ( 2,0) );\n\t\tdot( ( 2,-1) );\n\t\tdot( ( 2,1) );\n\t\tdot( ( 2,-2) );\n\t\tdot( ( 2,2) );\n\n\t\tMP(\"\\mathcal O_1\", (-2,-1.5), dir(225));\n\t\tMP(\"\\mathcal O_2\", ( 0,-2.5), dir(180));\n\t\tMP(\"\\mathcal O_3\", ( 2,-2.25), dir(225));\n\t\\end{asy}\n\\end{center}\n\nIt turns out that a very closely related concept is:\n\\begin{definition}\n\tThe \\vocab{stabilizer} of a point $x \\in X$,\n\tdenoted $\\Stab_G(x)$, is the set of $g \\in G$ which fix $x$; in other words\n\t\\[ \\Stab_G(x) \\defeq \\left\\{ g \\in G \\mid g \\cdot x = x \\right\\}. \\]\n\\end{definition}\n\\begin{example}\n\tConsider the AIME problem again, with $X$ the possible set of states\n\t(again $G = \\Zc4$).\n\tLet $x$ be the configuration where two opposite corners are colored yellow.\n\tEvidently $1_G$ fixes $x$, but so does the $180\\dg$ rotation $r^2$.\n\tBut $r$ and $r^3$ do not preserve $x$, so\n\t$\\Stab_G(x) = \\{1,r^2\\} \\cong \\Zc2$.\n\\end{example}\n\\begin{ques}\n\tWhy is $\\Stab_G(x)$ a subgroup of $G$?\n\\end{ques}\n\nOnce we realize the stabilizer is a group, this leads us to what I privately call the ``fundamental theorem of how big an orbit is''.\n\\begin{theorem}[Orbit-stabilizer theorem]\n\tLet $\\OO$ be an orbit, and pick any $x \\in \\OO$.\n\tLet $S = \\Stab_G(x)$ be a subgroup of $G$.\n\tThere is a natural bijection between $\\OO$ and left cosets.\n\tIn particular,\n\t\\[ \\left\\lvert \\OO \\right\\rvert \\left\\lvert S \\right\\rvert = \\left\\lvert G \\right\\rvert. \\]\n\tIn particular, the stabilizers of each $x \\in \\OO$ have the same size.\n\\end{theorem}\n\\begin{proof}\n\tThe point is that every coset $gS$ just specifies an element of $\\OO$,\n\tnamely $g \\cdot x$. The fact that $S$ is a stabilizer implies\n\tthat it is irrelevant which representative we pick.\n\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(6cm);\n\t\t\tdraw(ellipse(origin, 0.5, 2));\n\t\t\tlabel(\"$\\mathcal O \\subseteq X$\", (0,2), dir(90));\n\t\t\tfor (real i=-1.5; i<=1.5; ++i) {\n\t\t\t\tdot( (0,i) );\n\t\t\t}\n\t\t\tdraw( (0.3,1.8)--(0.3,1.2)--(4,1.2)--(4,1.8)--cycle );\n\t\t\tlabel(\"$S \\subseteq G$\", (4,1.5), dir(0));\n\t\t\tfor (real i=0.7; i < 4; i+=0.7) {\n\t\t\t\tlabel(\"$\\circ$\", (i, 1.5), origin);\n\t\t\t}\n\t\t\tdraw( (-0.2,1.5)..(-1,0.5)..(-0.2,-0.5), EndArrow);\n\t\t\tlabel(\"$g$\", (-1,0.5), dir(180));\n\t\t\\end{asy}\n\t\\end{center}\n\n\tSince the $\\left\\lvert \\mathcal O \\right\\rvert$ cosets partition $G$,\n\teach of size $\\left\\lvert S \\right\\rvert$, we obtain the second result.\n\\end{proof}\n\n\\section{Burnside's lemma}\nNow for the crux of this chapter: a way to count the number of orbits.\n\\begin{theorem}\n\t[Burnside's lemma]\n\tLet $G$ act on a set $X$.\n\tThe number of orbits of the action is equal to\n\t\\[ \\frac{1}{\\left\\lvert G \\right\\rvert}\n\t\t\\sum_{g \\in G} \\left\\lvert \\FixPt g \\right\\rvert \\]\n\twhere $\\FixPt g$ is the set of points $x \\in X$\n\tsuch that $g \\cdot x = x$.\n\\end{theorem}\nThe proof is deferred as a bonus problem,\nsince it has a very olympiad-flavored solution.\nAs usual, this lemma was not actually proven by Burnside;\nCauchy got there first, and thus it is sometimes called\n\\emph{the lemma that is not Burnside's}.\nExample application:\n\\begin{example}\n\t[AIME 1996]\n\t{ \\footnotesize Two of the squares of a $7 \\times 7$ checkerboard are painted yellow, and the rest are painted green. Two color schemes are equivalent if one can be obtained from the other by applying a rotation in the plane of the board. How many inequivalent color schemes are possible?  }\n\n\tWe know that $G = \\Zc4$ acts on the set $X$ of $\\binom{49}{2}$ possible coloring schemes.\n\tNow we can compute $\\FixPt g$ explicitly for each $g \\in \\Zc4$.\n\t\\begin{itemize}\n\t\t\\ii If $g = 1_G$, then every coloring is fixed, for a count of $\\binom{49}{2} = 1176$.\n\t\t\\ii If $g = r^2$ there are exactly $24$ coloring schemes fixed by $g$:\n\t\tthis occurs when the two squares are reflections across the center,\n\t\twhich means they are preserved under a $180\\dg$ rotation.\n\t\t\\ii If $g = r$ or $g=r^3$, then there are no fixed coloring schemes.\n\t\\end{itemize}\n\tAs $\\left\\lvert G \\right\\rvert = 4$, the average is\n\t\\[ \\frac{1176 + 24 + 0 + 0}{4} = 300. \\]\n\\end{example}\n\n\\begin{exercise}[MathCounts Chapter Target Round]\n\tA circular spinner has seven sections of equal size,\n\teach of which is colored either red or blue.\n\tTwo colorings are considered the same if one can be rotated to yield the other.\n\tIn how many ways can the spinner be colored? (Answer: 20)\n\\end{exercise}\n% The group in question is $\\Zc7$; the answer should be $20$.\n\nConsult \\cite{ref:aops_burnside} \nfor some more examples of ``hands-on'' applications.\n\n\\section{Conjugation of elements}\n\\prototype{In $S_n$, conjugacy classes are ``cycle types''.}\nA particularly common type of action is the so-called \\vocab{conjugation}.\nWe let $G$ act on itself as follows:\n\\[ g : h \\mapsto ghg\\inv. \\]\nYou might think this definition is a little artificial.\nWho cares about the element $ghg\\inv$?\nLet me try to convince you this definition is not so unnatural.\n\\begin{example}\n\t[Conjugacy in $S_n$]\n\tLet $G = S_5$, and fix a $\\pi \\in S_5$.\n\tHere's the question: is $\\pi \\sigma \\pi \\inv$ related to $\\sigma$?\n\tTo illustrate this,\n\tI'll write out a completely random example of a permutation $\\sigma \\in S_5$.\n\t\\[\n\t\t\\text{If }\n\t\t\\sigma = \\;\n\t\t\\begin{array}{ccc}\n\t\t1 & \\mapsto & 3 \\\\\n\t\t2 & \\mapsto & 1 \\\\\n\t\t3 & \\mapsto & 5 \\\\\n\t\t4 & \\mapsto & 2 \\\\\n\t\t5 & \\mapsto & 4\n\t\t\\end{array}\n\t\t\\qquad\n\t\t\\text{then}\n\t\t\\qquad\n\t\t\\pi \\sigma \\pi\\inv = \n\t\t\\begin{array}{ccc}\n\t\t\\pi(1) & \\mapsto & \\pi(3) \\\\\n\t\t\\pi(2) & \\mapsto & \\pi(1) \\\\\n\t\t\\pi(3) & \\mapsto & \\pi(5) \\\\\n\t\t\\pi(4) & \\mapsto & \\pi(2) \\\\\n\t\t\\pi(5) & \\mapsto & \\pi(4)\n\t\t\\end{array}\n\t\\]\n\tThus our fixed $\\pi$ doesn't really change the structure of $\\sigma$ at all:\n\tit just ``renames'' each of the elements $1$, $2$, $3$, $4$, $5$\n\tto $\\pi(1)$, $\\pi(2)$, $\\pi(3)$, $\\pi(4)$, $\\pi(5)$.\n\\end{example}\nBut wait, you say.\nThat's just a very particular type of group behaving nicely under conjugation.\nWhy does this mean anything more generally?\nAll I have to say is: remember Cayley's theorem!\n(This was \\Cref{thm:cayley_theorem}.)\n\nIn any case, we may now define:\n\\begin{definition}\n\tThe \\vocab{conjugacy classes} of a group $G$ are the orbits of $G$ under\n\tthe conjugacy action.\n\\end{definition}\n\nLet's see what the conjugacy classes of $S_n$ are, for example.\n\\begin{example}\n\t[Conjugacy classes of $S_n$ correspond to cycle types]\n\tIntuitively, the discussion above says that two elements of $S_n$ should\n\tbe conjugate if they have the same ``shape'', regardless of what the elements are named.\n\tThe right way to make the notion of ``shape'' rigorous is cycle notation.\n\tFor example, consider the permutation\n\t\\[ \\sigma_1 = (1 \\; 3 \\; 5)(2 \\; 4) \\]\n\tin cycle notation, meaning $1 \\mapsto 3 \\mapsto 5 \\mapsto 1$ and $2 \\mapsto 4 \\mapsto 2$.\n\tIt is conjugate to the permutation\n\t\\[ \\sigma_2 = (1 \\; 2 \\; 3)(4 \\; 5) \\]\n\tor any other way of relabeling the elements.\n\tSo, we could think of $\\sigma$ as having conjugacy class\n\t\\[ (- \\; - \\; -)(- \\; -). \\]\n\tMore generally, you can show that two elements of $S_n$ are conjugate\n\tif and only if they have the same ``shape'' under cycle decomposition.\n\\end{example}\n\\begin{ques}\n\tShow that the number of conjugacy classes of $S_n$\n\tequals the number of \\emph{partitions} of $n$.\n\\end{ques}\n\nAs long as I've put the above picture, I may as well also define:\n\\begin{definition}\n\tLet $G$ be a group.\n\tThe \\vocab{center} of $G$, denoted $Z(G)$, is the set of elements $x \\in G$\n\tsuch that $xg = gx$ for every $g \\in G$.\n\tMore succinctly,\n\t\\[ Z(G) \\defeq \\left\\{ x \\in G \\mid gx=xg \\; \\forall g \\in G \\right\\}. \\]\n\\end{definition}\nYou can check this is indeed a subgroup of $G$.\n\\begin{ques}\n\tWhy is $Z(G)$ normal in $G$?\n\\end{ques}\n\\begin{ques}\n\tWhat are the conjugacy classes of elements in the center?\n\\end{ques}\n\nA trivial result that gets used enough that I should explicitly call it out:\n\\begin{corollary}[Conjugacy in abelian groups is trivial]\n\tIf $G$ is abelian, then the conjugacy classes all have size one.\n\\end{corollary}\n\n\\section\\problemhead\n\\begin{problem}\n\t[PUMaC 2009 C8]\n\tTaotao wants to buy a bracelet consisting of seven beads,\n\teach of which is orange, white or black.\n\t(The bracelet can be rotated and reflected in space.)\n\tFind the number of possible bracelets.\n\t\\begin{hint}\n\t\tJust apply Burnside's lemma directly to get the answer of $198$\n\t\t(the relevant group is $D_{14}$).\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\tShow that two elements in the same conjugacy class\n\thave the same order.\n\t\\begin{hint}\n\t\tThere are multiple ways to see this.\n\t\tOne is to just do the algebraic manipulation.\n\t\tAnother is to use Cayley's theorem to embed $G$ into a symmetric group.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\t\\gim\n\tProve Burnside's lemma.\n\t\\begin{hint}\n\t\tDouble-count pairs $(g,x)$ with $g \\cdot x = x$.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{sproblem}\n\t[The ``class equation'']\n\t\\label{prob:class_eq}\n\tLet $G$ be a finite group.\n\tWe define the \\vocab{centralizer} $C_G(g) = \\{ x \\in G \\mid xg = gx \\}$\n\tfor each $g \\in G$.\n\tShow that\n\t\\[ \\left\\lvert G \\right\\rvert = \\left\\lvert Z(G) \\right\\rvert + \\sum_{s \\in S}\n\t\\frac{\\left\\lvert G \\right\\rvert}{\\left\\lvert C_G(s) \\right\\rvert} \\]\n\twhere $S \\subseteq G$ is defined as follows:\n\tfor each conjugacy class $C \\subseteq G$ with $|C| > 1$,\n\twe pick a representative of $C$ and add it to $S$.\n\\end{sproblem}\n\n\\begin{dproblem}\n\t[Classical]\n\t\\gim\n\tAssume $G$ is a finite group and $p$ is the smallest prime dividing its order.\n\tLet $H$ be a subgroup of $G$ with $\\left\\lvert G \\right\\rvert / \\left\\lvert H \\right\\rvert = p$.\n\tShow that $H$ is normal in $G$.\n\t\\begin{hint}\n\t\tLet $G$ act on the left cosets $\\{gH \\mid g \\in G\\}$\n\t\tby left multiplication: $g' \\cdot gH = g'gH$.\n\t\tConsider the orbit $\\OO$ of the coset $H$.\n\t\tBy the orbit-stabilizer theorem, $\\left\\lvert \\OO \\right\\rvert$ divides $\\left\\lvert G \\right\\rvert$.\n\t\tBut $\\left\\lvert \\OO \\right\\rvert \\le p$ also.\n\t\tSo either $\\OO = \\{H\\}$ or $\\OO$ contains all cosets.\n\t\tThe first case is impossible.\n\t\\end{hint}\n\\end{dproblem}\n", "meta": {"hexsha": "c6e9a3916f9f7e44698a53799480f280920f7945", "size": 12912, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/H113/action.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/H113/action.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/H113/action.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.3145400593, "max_line_length": 292, "alphanum_fraction": 0.6692998761, "num_tokens": 4390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.9136765228260895, "lm_q1q2_score": 0.8091806799874464}}
{"text": "\\chapter{Multi-Layer Perceptron}\nThe network is trained in a supervised manner with the error back-propagation algorithm based on the error correction learning rule. \n\n\\section{Delta Learning Rule of the Output Layer}\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=10cm]{chapter3_mlp}\n\\end{figure}\n\\noindent Total synaptic input to the output layer:\n$$\\mathbf{u = Wy}$$\nOutput of the network:\n$$\\mathbf{o} = f(\\mathbf{u})$$\nDesired output for pattern $p$:\n$$\\mathbf{d_p}=(d_{p1}, d_{p2} \\ldots d_{pK})^{T}$$\nThe error at output layer:\n$$E_p=\\frac{1}{2}\\sum_{k=1}^{K}(d_{pk}-o_{pk})^2$$\nFor gradient descent update algorithm:\n\\begin{equation}\n\\triangle w_{kj} = - \\alpha \\frac{\\partial E}{\\partial w_{kj}}\n\\label{weight_change}\n\\end{equation}\nBy using chain rule, the gradient of error function:\n\\begin{equation}\n\\frac{\\partial E}{\\partial w_{kj}} = \\frac{\\partial E}{\\partial u_k} \\frac{\\partial u_k}{\\partial w_{kj}}\n\\label{error_derive_chain_rule}\n\\end{equation}\nThe \\emph{error signal term} produce by the $k$ th neuron is defined as:\n\\begin{equation}\n\\delta_{ok} \\equiv - \\frac{\\partial E}{\\partial u_k}\n\\label{signal_term}\n\\end{equation}\nSince\n\\begin{equation}\n\\begin{split}\nu_k &= \\sum_{j=1}^{J} w_{kj} y_j\\\\\n\\frac{\\partial u_k}{\\partial w_{kj}} &= y_j\n\\end{split}\n\\label{input_derive_mlp}\n\\end{equation}\nSubstituting \\ref{signal_term} and \\ref{input_derive_mlp} to \\ref{error_derive_chain_rule}:\n\\begin{equation}\n\\frac{\\partial E}{\\partial w_{kj}} = - \\delta_{ok} y_j\n\\label{error_derive_2}\n\\end{equation}\nThe weight adjustment in \\ref{weight_change} can be rewritten:\n\\begin{equation}\n\\triangle w_{kj} = \\alpha \\delta_{ok} y_j\n\\label{weight_change_2}\n\\end{equation}\nThe error signal term can be written as:\n\\begin{equation}\n\\delta_{ok}=-\\frac{\\partial E}{\\partial o_k}\\frac{\\partial o_k}{\\partial u_k}\n\\label{signal_term_chain_rule}\n\\end{equation}\nSince\n\\begin{equation}\n\\begin{split}\nE = \\frac{1}{2} \\sum_{k=1}^{K} (d_k - o_k)^{2} \\\\\n\\frac{\\partial E}{\\partial o_k} = - (d_k - o_k)\n\\end{split}\n\\label{error_derive_mlp}\n\\end{equation}\nAnd since\n\\begin{equation}\n\\begin{split}\no_k &= f(u_k) \\\\\n\\frac{\\partial o_k}{\\partial u_k} &= f_{k}'(u_k)\n\\end{split}\n\\label{output_derive_mlp}\n\\end{equation}\nSubtituting \\ref{output_derive_mlp} and \\ref{error_derive_mlp} to \\ref{error_derive_mlp}:\n\\begin{equation}\n\\begin{split}\n\\delta_{ok} = (d_k -o_k)f_{k}'(u_k)\n\\end{split}\n\\label{signal_term_2}\n\\end{equation}\nFinal equation of weight adjustment:\n$$\\triangle w_{kj} = \\alpha (d_k - o_k)f_{k}'(u_k) y_j$$\nThe learning equation:\n\\begin{equation*}\n\\begin{split}\nw_{kj}^{new} &= w_{kj}^{old} + \\triangle w_{kj} \\\\\nw_{kj}^{new} &= w_{kj}^{old} + \\alpha \\delta_{ok} y_j\n\\end{split}\n\\end{equation*}\nRewritten the learning equation in matrix form:\n$$\\mathbf{W^{new} = W^{old} + \\alpha \\delta_o y^{T}}$$\n$$\\mathbf{\\delta_o = (d-o) .* f'(u)}$$\n\n\\section{Generalized Delta Learning Rule}\n\\begin{figure}[h]\n\\includegraphics[width=10cm]{chapter3_mlp_2}\n\\end{figure}\n\\noindent The weight adjustment of hidden layer neurons:\n\\begin{equation}\n\\triangle v_{ji} = -\\beta \\frac{\\partial E}{\\partial v_{ji}}\n\\label{weight_adjust_hidden}\n\\end{equation}\nUsing chain rule:\n\\begin{equation}\n\\frac{\\partial E}{\\partial v_{ji}} = \\frac{\\partial E}{\\partial s_j} \\frac{\\partial s_j}{\\partial v_{ji}}\n\\label{error_derive_hidden}\n\\end{equation}\nSince the net synaptic input to hidden layer neuron is:\n\\begin{equation}\n\\begin{split}\ns_j &= \\sum_{i} v_{ji} z_i\\\\\n\\frac{\\partial s_j}{\\partial v_{ji} } &= z_i\n\\end{split}\n\\label{input_derive_hidden}\n\\end{equation}\nThe error signal term at hidden layer is defined as:\n\\begin{equation}\n\\delta_{yj} \\equiv - \\frac{\\partial E}{\\partial s_j}\n\\label{error_term_hidden}\n\\end{equation}\nSubstituting \\ref{input_derive_hidden} and \\ref{error_term_hidden} into \\ref{error_derive_hidden}:\n$$\\frac{\\partial E}{\\partial v_{ji}} = - \\delta_{yj} z_i$$\nEquation \\ref{weight_adjust_hidden} can be written as:\n$$ \\triangle v_{ji} = \\beta \\delta_{yj} z_i $$\nThe error signal term in equation \\ref{error_term_hidden} can be computed as:\n\\begin{equation}\n\\delta_{yj} = - \\frac{\\partial E}{\\partial y_j} \\frac{\\partial y_j}{\\partial s_j}\n\\label{error_term_derive_hidden}\n\\end{equation}\nWhere:\n\\begin{equation}\n\\begin{split}\nE &= \\frac{1}{2} \\sum_{k=1}^{K} (d_k - f_k (u_k))^{2} \\\\\n\\frac{\\partial E}{\\partial y_j} &= - \\sum_{k=1}^{K} (d_k - o_k) \\frac{\\partial}{\\partial y_j} (f_k (u_k)) \\\\\n&= - \\sum_{k=1}^{K} (d_k - o_k) f_k' (u_k) \\frac{\\partial u_k}{\\partial y_j} \\\\\n&= - \\sum_{k=1}^{K} \\delta_{ok} \\frac{\\partial u_k}{\\partial y_j}\n\\end{split}\n\\label{temp1}\n\\end{equation}\nSince:\n\\begin{equation}\n\\begin{split}\nu_k &= \\sum_{j=1}^{J} w_{kj} y_j \\\\\n\\frac{\\partial u_k}{\\partial y_j} &= w_{kj}\n\\end{split}\n\\label{temp2}\n\\end{equation}\nAnd since:\n\\begin{equation}\n\\begin{split}\ny &= f(s) \\\\\n\\frac{\\partial y}{\\partial s_j} &= f_{j}'(s_j)\n\\end{split}\n\\label{temp3}\n\\end{equation}\nSubstituting \\ref{temp1} \\ref{temp2} \\ref{temp3} into \\ref{error_term_derive_hidden}:\n$$\\delta_{yj} = f_j'(s_j)\\sum_{k=1}^{K} \\delta_{ok} w_{kj}$$\nFinal equation of weight adjustment:\n$$\\triangle v_{ji} = \\beta \\delta_{yj} z_i$$\nThe learning equations:\n\\begin{equation*}\n\\begin{split}\nv_{ji}^{new} &= v_{ji}^{old} + \\triangle v_{ji} \\\\\nv_{ji}^{new} &= v_{ji}^{old} + \\beta \\delta_{yj} z_i\n\\end{split}\n\\end{equation*}\nRewritten the learning equation in matrix form:\n$$\\mathbf{V^{new} = V^{old}} + \\beta \\mathbf{\\delta_y z^{T}}$$\n$$\\mathbf{\\delta_y = f'(s) .* W^{T} \\delta_o}$$\n\n\\section{Application to Function Approximation}\nKolmogorov Theorem: Given any function $\\mathbf{\\varphi: I^{n} \\rightarrow R^{m}, \\varphi(x) = y}$ where $I$ is the closed unit interval [0, 1], $\\phi$ can be implemented exactly by a three layer neural network with $n$ input node, $2n+1$ hidden layer neurons and $m$ output layer neurons\n", "meta": {"hexsha": "bf00091e2257fea1b1bb1df6bfba12ceaba51ba0", "size": 5792, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter3.tex", "max_stars_repo_name": "Andyccs/neural-network-summary", "max_stars_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter3.tex", "max_issues_repo_name": "Andyccs/neural-network-summary", "max_issues_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter3.tex", "max_forks_repo_name": "Andyccs/neural-network-summary", "max_forks_repo_head_hexsha": "fb7298936a3abafd9fe2d1063f7ef8c324b28a48", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.0705882353, "max_line_length": 288, "alphanum_fraction": 0.6973411602, "num_tokens": 2082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138558, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.8091734625369635}}
{"text": "\n\\subsection{Adjacency matrix}\n\nWe can represent a finite graph as a square matrix. \\(m_{ij}\\) is the number of edges connecting vertex \\(i\\) to vertex \\(j\\).\n\n", "meta": {"hexsha": "55e26f250d1b1acf47e943da42ef7936814c448e", "size": 160, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/graph/04-01-matrixAdjacency.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/graph/04-01-matrixAdjacency.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/graph/04-01-matrixAdjacency.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6666666667, "max_line_length": 126, "alphanum_fraction": 0.7125, "num_tokens": 41, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9658995733060718, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.8090567651762715}}
{"text": "\\subsubsection{Self-Similar Models --- Theory}\n\nThe pressure normalization of SZ models can also be related directly\nto the mass of the cluster, through considerations of self-similarity.\n\nWe start from the characteristic temperature for an isothermal sphere\nof mass \\mathM500\\\n\n\\begin{equation}\nk\\T500 = \\mu m_p {{G \\M500}\\over{2\\R500}}\n\\label{eq:t500}\n\\end{equation}\n\nwhere \\mathM500\\ is given by\n\n\\begin{equation}\n\\M500 = 500  \\rho_c(z) {{4\\pi}\\over{3}}{\\R500}^3\n\\label{eq:r500}\n\\end{equation}\n\nand\n\n\\begin{equation}\n\\rho_c(z) = {{3 H(z)^2}\\over{8\\pi G}}.\n\\end{equation}\n\nThe characteristic gas density is\n\n\\begin{equation}\n\\rho_{g,500} = 500 f_B\\rho_c(z)\n\\end{equation}\n\nand the electron density is\n\n\\begin{equation}\nn_{e,500} = {\\rho_{g,500}\\over{\\mu_e m_p}}\n\\end{equation}\n\nPutting it all together, we have\n\n\\begin{eqnarray}\\nonumber\n\\P500 = n_{e,500} \\times k\\T500 &=& {\\rho_{g,500}\\over{\\mu_e m_p}} \\times \\mu m_p {{G \\M500}\\over{2\\R500}}\\\\\\nonumber\n&=& {{\\mu}\\over{\\mu_e}}\\rho_{g,500} \\times {{G \\M500}\\over{2\\R500}}\\\\\n&=& {{\\mu}\\over{\\mu_e}} 500 f_B\\rho_c(z) \\times {{G \\M500}\\over{2\\R500}}\n\\end{eqnarray}\n\nFrom Eq.\\ref{eq:r500} we have \n\n\\begin{equation}\n\\R500 = \\left({3\\over{4\\pi}}{\\M500\\over{500 \\rho_c(z)}}\\right)^{1/3}\n\\end{equation}\n\nwhence\n\n\\begin{eqnarray}\\nonumber\n\\P500 &=& {{\\mu}\\over{\\mu_e}} 500 f_B\\rho_c(z) \\times {{G \\M500}\\over{2\\R500}}\\\\\\nonumber\n      &=& {{\\mu}\\over{\\mu_e}} 500 f_B\\rho_c(z) \\times {{G\\M500}\\over{2}} \\left({{4\\pi}\\over{3}}{500\\rho_c(z)\\over{\\M500}}\\right)^{1/3}\\\\\\nonumber\n      &=& {{\\mu}\\over{\\mu_e}} f_B G {{3}\\over{8\\pi}} \\left( {{4\\pi}\\over{3}} 500\\rho_c(z) \\right)^{4/3}\\M500^{2/3}\\\\\\nonumber\n      &=& {{\\mu}\\over{\\mu_e}} f_B G {{3}\\over{8\\pi}} \\left( {{4\\pi}\\over{3}} 500 {{3 H(z)^2}\\over{8\\pi G}} \\right)^{4/3}\\M500^{2/3}\\\\\n      &=& {{\\mu}\\over{\\mu_e}} f_B {{3}\\over{8\\pi}} \\left( {{500 G^{-1/4} H(z)^2}\\over{2}} \\right)^{4/3}\\M500^{2/3}\n\\label{eq:p500}\n\\end{eqnarray}\n", "meta": {"hexsha": "31f3a9a34fb027384883aa1299fb1700681997de", "size": 1927, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "help/selfsimilar.tex", "max_stars_repo_name": "erikleitch/climax", "max_stars_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-01T05:15:31.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-01T05:15:31.000Z", "max_issues_repo_path": "docs/selfsimilar.tex", "max_issues_repo_name": "erikleitch/climax", "max_issues_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/selfsimilar.tex", "max_forks_repo_name": "erikleitch/climax", "max_forks_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-02T19:35:55.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-07T00:54:51.000Z", "avg_line_length": 30.5873015873, "max_line_length": 145, "alphanum_fraction": 0.6284379865, "num_tokens": 790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632302488964, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.8090563106886007}}
{"text": "\n\\subsection{Dot product}\n\n\\subsubsection{Dot product is a bilinear form}\n\nThis is a bilinear form, a mapping from two vectors in the same vector space to the underlying field.\n\n\\(V\\times V \\rightarrow F\\)\n\n\\subsubsection{Calculating the dot product}\n\nThis is calculated by multiplying each matching element, and summing the results.\n\n\\(u\\cdot v =\\sum_{i=1}^nu_iv_i\\)\n\n\\subsubsection{Dot product on the complex numbers}\n\nProperties don't hold. Can get zero vectors from non-zero inputs. Get complex numbers from dot product on itself.\n\nInner products better deal with complex number fields. However they are not bilinear maps.\n\n", "meta": {"hexsha": "53a91ee90ff2f1a9683d6128fac6250ba68483ce", "size": 628, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/tensors/05-03-dotProduct.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/tensors/05-03-dotProduct.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/tensors/05-03-dotProduct.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5454545455, "max_line_length": 113, "alphanum_fraction": 0.7786624204, "num_tokens": 146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.8723473647220787, "lm_q1q2_score": 0.8089829270973945}}
{"text": "\\section{Introduction}\nThis paper attempts to summarise some important defintions and theorems in theory of dynamical systems (DS). We only presume basic knowledge of topology and analysis. When we say 'time interval' we simply refer to a connected open subset $U$ of $\\rz$ and 'time' to an element in $U$.\n\\subsection{Background}\nLet $(X,d)$ be a metric space, that is there exists a map\n$$d : X \\times X \\longrightarrow \\rz,$$\nsuch that $d(x,y) \\geq 0$, for all $x, y \\in X$, $d(x,x) = 0$ and \n$$d(x,z) \\leq d(x,y) + d(y,z),\\ \\forall x, y, z \\in X.$$\n\\subsubsection{Dynamical systems}\nGiven a metric space $(X,d)$ and map $f : X \\longrightarrow X$, a time discrete dynamical system (TD) is a map\n$$\\phi : \\nz \\times X \\longrightarrow X, (n,x) \\longmapsto f^n (x) := \\underbrace{f \\circ \\ldots \\circ f}_{n-\\mathrm{times}}(x)$$\ninducing a sequence $(f^n(x))_{n \\in \\nz} \\subset X$ for all $x \\in X$ and $n \\geq 0$. A time-continuous dynamical system (TC) is a map\n$$\\varphi : \\rz \\times X \\longrightarrow X,$$\nsuch that $\\varphi(0,x) = x$ and $\\varphi(t + s,x) = \\varphi(s,\\varphi(t,x)) = \\varphi(t,\\varphi(s,x))$ for all $t, s \\in U \\subset \\rz$ open and $x \\in X$. We denote a TC as\n$$(X, d, \\varphi, U).$$\nWe remark that a given a time-continous dynamical system $(X,d,\\varphi)$ we get a family of maps $\\{f_t : X \\longrightarrow X\\}_{t \\in U}$ indexed by time such that $f_0 = id_X$ and $\\varphi(t,x) = f_t(x)$ for all $x \\in X$ and $t \\in \\rz$, as well as\n$$f_s(f_t(x)) = f_t(f_s(x)).$$\nFurthermore, we get a time-discrete DS when we restrict the domain accordingly. What this entails will be later discussed.\\\\\n\\indent In addition, we restrict the time domain to an open subset as there are examples of smooth TCs which do not exist for all times:\n$$\\partial(x) = x^2 \\Rightarrow \\varphi(t,x_0) = \\frac{1}{1 - x_0(t - t_0)}, \\forall t \\geq t_0$$\nhas no smooth solution $x \\in C^\\infty(\\rz)$ for all initial conditions $(t_0,x_0) \\in U \\times X$ (only locally smooth solution).\n\\begin{defi}\nLet $(X, d, \\varphi, U)$ be a TC and $x_0 \\in X$. We call a map $x : U \\longrightarrow X$ a solution if $x(t) = \\varphi(t,x_0)$ for all $t \\in U$. If $U = \\rz$ we call $x \\in X^U$ a global solution.\n\\end{defi}\n\\subsubsection{Attractors and basin of attraction}\nUntil now, we did not need the metric $d$. However, the next definition requires this map. Moreover, let $X$ be complete wrt. to the metric induced topology.\n\\begin{defi}[Metric attractors]\nLet $(X, d, \\varphi, U)$ be a TC. A subset $A \\subset X$ is called an attractor if there exists an open neighborhood $V \\supset A$ such that\n$$\\forall \\varepsilon > 0\\ \\exists T \\in U\\ \\forall t \\geq T:\\ d(\\varphi(t,x),A) < \\varepsilon,$$\nfor all $x \\in V$. This property is denoted as usual as a limit:\n$$A := \\{x \\in V : \\lim_{t \\rightarrow \\infty} \\varphi(t,x) \\in A\\}$$\n%We remark that not all metric spaces do have a limit, i.e. $\\varphi\nWe call the union of all neighborhoods $V \\supset A$, such that\n$$\\lim_{t \\rightarrow \\infty}\\varphi(t,x) \\in A$$\nthe basin of attraction, denoted by $B(A)$.\n\\end{defi}\nAgain, strictly speaking we only need a (complete) topological space $(X,\\tau)$ with a neighborhood basis $\\beta(x)$ wrt. $x \\in X$:\n\\begin{defi}[Topological attractor]\nLet $(X, \\tau, \\varphi, U)$ be a TC. A subset $A \\subset X$ is called an attractor if there exists an open neighborhood $V \\supset A$ such that\n$$\\forall W(A) \\in \\beta(A)\\ \\exists T \\in U\\ \\forall t \\geq T:\\ \\varphi(t,x) \\in W(A),$$\nfor all $x \\in V$. We call the union of all neighborhoods $V \\supset A$, such that\n$$\\lim_{t \\rightarrow \\infty}\\varphi(t,x) \\in A$$\nthe basin of attraction, denoted by $B(A)$.\n\\end{defi}\nHere,\n$$W(A) = \\bigcup_{x \\in A} W(x),\\ \\beta(A) = \\bigcup_{x \\in A} \\beta(x)\\ \\mathrm{where}\\ W(x) \\in \\beta(x)\\ \\forall x \\in X.$$", "meta": {"hexsha": "556d6bed6a30471456990effa101b3f40d5d61d0", "size": 3782, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dynamic/intro.tex", "max_stars_repo_name": "gmuel/texlib", "max_stars_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dynamic/intro.tex", "max_issues_repo_name": "gmuel/texlib", "max_issues_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dynamic/intro.tex", "max_forks_repo_name": "gmuel/texlib", "max_forks_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.0444444444, "max_line_length": 283, "alphanum_fraction": 0.6681649921, "num_tokens": 1289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.8774767890838837, "lm_q1q2_score": 0.8089650151997094}}
{"text": "\\documentclass{standalone}\n\n\\begin{document}\n\n\n\\section*{Mathematical background}\\addcontentsline{toc}{section}{Mathematical background}\n\\markboth{Appendix A}{Mathematical background}\n\nThe exact knowledge of prior probabilities and conditional probabilities are generally hard to evaluate, thus a parametric approach is often needed.\nA parametric approach aims to create reasonable hypotheses about the data distribution and its fundamental parameters (e.g mean, variance, $\\cdots$).\nIn the following discussion, we are going to focus only on normal distributions for mathematical convenience, but the results could be easily generalized.\n\nGiven the multi-dimensional form of Gauss distribution:\n\n\\begin{equation}\nG(\\mathbf{x}|\\mu, \\Sigma) = \\frac{1}{(2\\pi)^{d/2}\\cdot\\left|\\Sigma\\right|^{1/2}}\\cdot exp\\left[-\\frac{1}{2}(\\mathbf{x}-\\mathbf{\\mu})^T\\Sigma^{-1}(\\mathbf{x}-\\mathbf{\\mu})\\right]\n\\end{equation}\n\\\\\nwhere $\\mathbf{x}$ is a $d$-dimensional column vector, $\\mathbf{\\mu}$ is the mean vector of the distribution, $\\Sigma$ is the covariance matrix ($d\\times d$) and $|\\Sigma|$ and $\\Sigma^{-1}$ the determinant and its inverse, respectively.\nWe can notice the quadratic dependence of $G$ by $\\mathbf{x}$,\n\n\\begin{equation}\n\\Delta^2 = (\\mathbf{x}-\\mu)^T\\Sigma^{-1}(\\mathbf{x}-\\mu)\n\\end{equation}\n\\\\\nwhere the exponent ($\\Delta^2$) is called \\emph{Mahalanobis distance} of vector $\\mathbf{x}$ from its mean.\nThis distance can be reduced to the Euclidean one when the covariance matrix is the identity matrix ($\\mathbf{I}$).\n\nThe covariance matrix is always symmetric and positive semi-definite by definition (useful information for the next algorithmic strategies) so it is invertible.\nIf the covariance matrix has only diagonal terms the multidimensional distribution can be expressed as the simple product of $d$ mono-dimensional normal distributions.\nIn this case the main axes are parallel to the Cartesian axes.\n\nStarting from a multi-variate Gaussian distribution\\footnote{\n  In Machine Learning it will correspond to the conditional probability density.\n}, the Bayesian rule for classification problems can be rewritten as:\n\n\\begin{equation}\ng_i(\\mathbf{x}) = P(w_i|\\mathbf{x}) = \\frac{p(\\mathbf{x}|w_i)P(w_i)}{p(\\mathbf{x})} = \\frac{1}{(2\\pi)^{d/2}\\cdot\\left|\\Sigma_i\\right|^{1/2}}\\cdot exp\\left[-\\frac{1}{2}(\\mathbf{x}-\\mathbf{\\mu_i})^T{\\Sigma_i}^{-1}(\\mathbf{x}-\\mathbf{\\mu_i})\\right] \\frac{P(w_i)}{p(\\mathbf{x})}\n\\end{equation}\n\\\\\nwhere, removing constant terms ($\\pi$ factors and the absolute probability density $p(\\mathbf{x}) = \\sum_{i=1}^s p(\\mathbf{x}|w_i)\\cdot P(w_i)$) and using the monotonicity of the function, we can extract the logarithmic relation:\n\n\\begin{equation}\ng_i(\\mathbf{x}) = -\\frac{1}{2}(\\mathbf{x}-\\mu_i)^T{\\Sigma_i}^{-1}(\\mathbf{x}-\\mu_i) -\\frac{1}{2}\\log\\left|\\Sigma_i\\right|+\\log P(w_i)\n\\end{equation}\n\\\\\nwhich is called \\emph{Quadratic Discriminant function}.\n\nThe dependency by the covariance matrix allows 5 different cases:\n\n\\begin{itemize}\n\n\\item \\textbf{$\\Sigma_i=\\sigma^2I$ - DiagLinear Classifier}\n\n\\begin{minipage}{.30\\textwidth}\n\\hspace{-.5cm}\n\\includegraphics[width=1\\textwidth]{case1.png}\n\\end{minipage}%\n\\begin{minipage}{.70\\textwidth}\nThis is the case in which features are completely independent, i.e they have equal variances for each class.\nThis hypothesis allows us to simplify the discriminant function as:\n\\end{minipage}\\\\\n\n\\begin{equation}\ng_i(\\mathbf{x})=-\\frac{1}{2\\sigma^2}(\\mathbf{x^Tx}-2{\\mu_i}^T\\mathbf{x} + {\\mu_i}^T\\mu_i) + \\log P(w_i)\n\\end{equation}\n\\\\\nand removing all the $\\mathbf{x^Tx}$ constant terms for each class\n\n\\begin{equation}\ng_i(\\mathbf{x}) = -\\frac{1}{2\\sigma^2}(-2{\\mu_i}^T\\mathbf{x}+{\\mu_i}^T\\mu_i)+\\log P(w_i) = \\mathbf{{w_i}^Tx}+\\mathbf{w_0}\n\\end{equation}\n\\\\\nThese simplifications create a linear discriminant function and the separation surfaces between classes are hyper-planes ($g_i(\\mathbf{x})=g_j(\\mathbf{x})$).\n\nWith equal prior probability the function can be rewritten as\n\n\\begin{equation}\ng_i(\\mathbf{x}) = -\\frac{1}{2\\sigma^2}(\\mathbf{x}-\\mu_i)^T(\\mathbf{x}-\\mu_i)\n\\end{equation}\n\\\\\nwhich is called \\emph{nearest mean classifier} and the equal-probability surfaces are hyper-spheres.\n\n\\item \\textbf{$\\Sigma_i = \\Sigma$ (diagonal matrix) - Linear Classifier}\n\n\\begin{minipage}{.30\\textwidth}\n\\hspace{-.5cm}\n\\includegraphics[width=1\\textwidth]{case2.png}\n\\end{minipage}%\n\\begin{minipage}{.70\\textwidth}\nIn this case the classes have same covariances but each feature has its own different variance.\nAfter the substitution of $\\Sigma$ in the equation, we obtain\n\\end{minipage}\\\\\n\n\\begin{equation}\ng_i(\\mathbf{x}) = -\\frac{1}{2}\\sum_{k=1}^{s}\\frac{(\\mathbf{x_k}-\\mu_{i,k})^2}{{\\sigma_k}^2}-\\frac{1}{2}\\log\\prod_{k=1}^{s}{\\sigma_k}^2+\\log P(w_i)\n\\end{equation}\n\\\\\nwhere we can remove constant $\\mathbf{x_k}^2$ terms (equal for each class) and obtain another time a linear discriminant function and discriminant surfaces given by hyper-planes and equal-probability boundaries given by hyper-ellipsoids.\nWe remark that the only difference from the previous case is the normalization factor of each axis that in this case is given by its variance.\n\n\\item \\textbf{$\\Sigma_i = \\Sigma$ (non-diagonal matrix) - Mahalanobis Classifier}\n\n\\begin{minipage}{.30\\textwidth}\n\\hspace{-.5cm}\n\\includegraphics[width=1\\textwidth]{case3.png}\n\\end{minipage}%\n\\begin{minipage}{.70\\textwidth}\nIn this case we assume that each class has the same covariance matrix, but they are non-diagonal ones.\nThe discriminant function becomes\n\\end{minipage}\\\\\n\n\\begin{equation}\ng_i(\\mathbf{x}) = -\\frac{1}{2}(\\mathbf{x}-\\mu_i)^T{\\Sigma}^{-1}(\\mathbf{x}-\\mu_i) -\\frac{1}{2}\\log\\left|\\Sigma\\right|+\\log P(w_i)\n\\end{equation}\n\\\\\nwhere we can remove the $\\log\\left|\\Sigma\\right|$ term because it is constant for all the classes and we can assume equal prior probabilities.\nIn this case we obtain\n\n\\begin{equation}\ng_i(\\mathbf{x}) = -\\frac{1}{2}(\\mathbf{x}-\\mu_i)^T{\\Sigma}^{-1}(\\mathbf{x}-\\mu_i)\n\\end{equation}\n\\\\\nwhere the quadratic term is the above told \\emph{Mahalanobis distance}, i.e a normalization of the distance according to the inverse of the covariance matrix.\nWe can prove that expanding the scalar product and removing the constant $\\mathbf{x^T\\Sigma^{-1}x}$ term, we still obtain a linear discriminant function with the same properties of the previous case.\nIn this case the hyper-ellipsoids have axes aligned to the eigenvectors of the $\\Sigma$ matrix.\n\n\\item \\textbf{$\\Sigma_i = {\\sigma_i}^2I$ - DiagQuadratic Classifier}\n\n\\begin{minipage}{.30\\textwidth}\n\\hspace{-.5cm}\n\\includegraphics[width=1\\textwidth]{case4.png}\n\\end{minipage}%\n\\begin{minipage}{.70\\textwidth}\nIn this case we have a different covariance matrix for each class but they are all proportional to the identity matrix, i.e diagonal matrix.\nThe discriminant function in this case becomes\n\\end{minipage}\\\\\n\n\\begin{equation}\ng_i(\\mathbf{x}) = -\\frac{1}{2}(\\mathbf{x}-\\mu_i)^T{\\sigma_i}^{-2}(\\mathbf{x}-\\mu_i) -\\frac{1}{2}s\\log\\left|{\\sigma_i}^2\\right|+\\log P(w_i)\n\\end{equation}\n\\\\\nwhere this expression can be further reduced obtaining a quadratic discriminant function.\nIn this case the equal-probability boundaries are hyper-spheres aligned to the feature axes.\n\n\\item \\textbf{$\\Sigma_i \\neq\\Sigma_j$ (general case) - Quadratic Classifier}\n\n\\begin{minipage}{.30\\textwidth}\n\\hspace{-.5cm}\n\\includegraphics[width=1\\textwidth]{case5.png}\n\\end{minipage}%\n\\begin{minipage}{.70\\textwidth}\nStarting from the more general discriminant function we can relabel the variables and highlight its quadratic form as\n\\end{minipage}\\\\\n\n\\begin{equation}\ng_i(\\mathbf{x}) = \\mathbf{x^TW_{2,i}x}+\\mathbf{w_{1,i}^Tx} + \\mathbf{w_{0,i}} \\quad \\mbox{with}\\quad \\left\\{\\begin{array}{l} \\mathbf{W_{2,i}}=-\\frac{1}{2}{\\Sigma_i}^{-1}\\\\ \\mathbf{w_{1,i}}={\\Sigma_i}^{-1}\\mu_i \\\\ \\mathbf{w_{0,i}}=-\\frac{1}{2}{\\mu_i}^T{\\Sigma_i}^{-1}\\mu_i-\\frac{1}{2}\\log\\left|\\Sigma_i\\right|+\\log P(w_i) \\\\ \\end{array}\\right.\n\\end{equation}\n\\\\\nIn this case each class has its own covariance matrix $\\Sigma_i$ and the equal-probability boundaries are hyper-ellipsoids oriented to the eigenvectors of the covariance matrix of each class.\n\n\\end{itemize}\n\nThe Gaussian distribution hypothesis of data should be tested before using these classifiers.\nIt can be evaluated using statistical tests as \\href{https://www.jstor.org/stable/2284163?seq=1#page_scan_tab_contents}{\\emph{Malkovich-Afifi}} based on \\href{https://en.wikipedia.org/wiki/Kolmogorov\u2013Smirnov_test}{\\emph{Kolmogorov-Smirnov}} index or using the empirical visualization of the data points.\n\n\n\\end{document}\n", "meta": {"hexsha": "62672b9bbf64b62557510b8fffea7823cae5307d", "size": 8559, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/Appendix/DiscriminantAnalysis/MathematicalBackground.tex", "max_stars_repo_name": "Nico-Curti/PhDthesis", "max_stars_repo_head_hexsha": "234b38234eb15870056f71c4f33946d8aed05aae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-03-17T14:01:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-04T10:21:41.000Z", "max_issues_repo_path": "tex/Appendix/DiscriminantAnalysis/MathematicalBackground.tex", "max_issues_repo_name": "Nico-Curti/PhDthesis", "max_issues_repo_head_hexsha": "234b38234eb15870056f71c4f33946d8aed05aae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/Appendix/DiscriminantAnalysis/MathematicalBackground.tex", "max_forks_repo_name": "Nico-Curti/PhDthesis", "max_forks_repo_head_hexsha": "234b38234eb15870056f71c4f33946d8aed05aae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-05-09T13:17:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-09T15:16:46.000Z", "avg_line_length": 50.6449704142, "max_line_length": 342, "alphanum_fraction": 0.7386376913, "num_tokens": 2639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.960951703918909, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.8089537958491003}}
{"text": "%\n% Chapter 3.1\n%\n\n\\section*{3.1 Max and Min Values}\n\n\\subsection*{Absolute Extrema}\n\nLet \\(c\\) be a number in the domain \\(D\\) of the function \\(f\\). Then \\(f(x)\\) is the \n\\begin{itemize}\n    \\item \\textbf{absolute maximum} value of \\(f\\) on \\(D\\) if \\(f(c) \\geq f(x)\\) for all \\(x\\) in \\(D\\).\n    \\item \\textbf{absolute minimum} value of \\(f\\) on \\(D\\) if \\(f(c) \\leq f(x)\\) for all \\(x\\) in \\(D\\).\n\\end{itemize}\n\n\\subsection*{Relative Extrema}\n\nThe number \\(f(c)\\) is a \n\\begin{itemize}\n    \\item \\textbf{local maximum} value of \\(f\\) if \\(f(c) \\geq f(x)\\) when \\(x\\) is near \\(c\\).\n    \\item \\textbf{local minimum} value of \\(f\\) if \\(f(c) \\leq f(x)\\) when \\(x\\) is near \\(c\\).\n\\end{itemize}\n\n\\subsection*{Extreme Value Theorem}\n\nIf \\(f\\) is continuous on a closed interval \\([a, b]\\), then \\(f\\) attains an absolute maximum value \\(f(x)\\) and an absolute minimum value \\(f(d)\\) at some numbers \\(c\\) and \\(d\\) in \\([a, b]\\).\n\n\\subsection*{Fermat's Theorem}\n\nIf \\(f\\) has a local maximum or minimum at \\(c\\), and if \\(f'(x)\\) exists, then \\(f'(c)=0\\).\n\\\\\\\\\\\\\nA \\textbf{critical number} of a function \\(f\\) is a number \\(c\\) in the domain of \\(f\\) such that either \\(f'(c)=0\\) or \\(f'(c)\\) does not exist. If \\(f\\) has a local maximum or a minimum at \\(c\\), then \\(c\\) is a critical number of \\(f\\).\n\n\\subsection*{Closed Interval Method (Championship Method)}\n\nTo find the absolute maximum and minimum values of a continuous function \\(f\\) on a closed interval \\([a, b]\\):\n\\begin{enumerate}\n    \\item Find the values of \\(f\\) at the critical values of \\(f\\) in \\((a, b)\\).\n    \\item Find the values of \\(f\\) at the endpoints of the interval.\n    \\item The largest of the values is the absolute maximum; the smallest of these values is the absolute minimum.\n\\end{enumerate}\n", "meta": {"hexsha": "ce13046d952dbe082ce3e511cf3645ce627ece3d", "size": 1776, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/3-1.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/3-1.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/3-1.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.3170731707, "max_line_length": 239, "alphanum_fraction": 0.625, "num_tokens": 564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.8902942363098473, "lm_q1q2_score": 0.8089372810533899}}
{"text": "\\section{Definition of vector spaces}\n\\label{sec:definition-vector-spaces}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Develop the concept of a vector space through axioms.\n  \\item Use the vector space axioms to determine if a set and its\n    operations constitute a vector space.\n  \\item Encounter several examples of vector spaces.\n  \\end{enumerate}\n\\end{outcome}\n\n\\begin{definition}{Vector space}{vector-space}\n  Let $K$ be a field. A \\textbf{vector space} over $K$%\n  \\index{vector space} is a set $V$ equipped with two operations of\n  \\textbf{addition}%\n  \\index{addition!in a vector space}%\n  \\index{vector!addition}%\n  \\index{addition!of vectors} and \\textbf{scalar multiplication}%\n  \\index{scalar multiplication!in a vector space}%\n  \\index{vector!scalar multiplication}%\n  \\index{scalar multiplication!of a vector}%\n  \\index{multiplication!scalar multiplication|see{scalar multiplication}},\n  such that the following properties hold:\n  \\begin{itemize}\\setlength\\itemsep{0em}\n  \\item[(A1)] Commutative law of addition%\n    \\index{commutative law!of addition}%\n    \\index{vector!commutative law of addition}:\n    $\\vect{u} + \\vect{v}=\\vect{v} + \\vect{u}$.\n  \\item[(A2)] Associative law of addition%\n    \\index{associative law!of addition}%\n    \\index{vector!associative law of addition}:\n    $(\\vect{u} + \\vect{v}) + \\vect{w}=\\vect{u} + (\\vect{v} + \\vect{w})$.\n  \\item[(A3)] The existence of an additive unit%\n    \\index{additive unit}%\n    \\index{unit!of addition|see{additive unit}}%\n    \\index{vector!additive unit}: there exists an element\n    $\\vect{0}\\in V$ such that for all $\\vect{u}$,\n    $\\vect{u} + \\vect{0}=\\vect{u}$.\n  \\item[(A4)] The law of additive inverses%\n    \\index{additive inverse}%\n    \\index{vector!additive inverse}%\n    \\index{inverse!additive}:\n    $\\vect{u} + (-\\vect{u}) =\\vect{0}$.\n  \\item[(SM1)] The distributive law over vector addition%\n    \\index{distributive law!over vector addition}%\n    \\index{vector!distributive law}:\n    $k(\\vect{u} + \\vect{v}) = k\\vect{u} + k\\vect{v}$.\n  \\item[(SM2)] The distributive law over scalar addition%\n    \\index{distributive law!over scalar addition}:\n    $(k + \\ell) \\vect{u} = k \\vect{u} + \\ell\\vect{u}$.\n  \\item[(SM3)] The associative law for scalar multiplication%\n    \\index{associative law!of scalar multiplication}%\n    \\index{vector!associative law of scalar multiplication}:\n    $k(\\ell\\vect{u}) = (k \\ell)\\vect{u}$.\n  \\item[(SM4)] The rule for multiplication by one%\n    \\index{rule for multiplication by 1}%\n    \\index{vector!rule for multiplication by 1}:\n    $1\\vect{u}=\\vect{u}$.\n  \\end{itemize}\n\\end{definition}\n\nThe above definition is concerned about two operations: vector\naddition, denoted by $\\vect{v} + \\vect{w}$, and scalar multiplication,\ndenoted by $k\\vect{v}$ or sometimes $k\\cdot\\vect{v}$. In the law of\nadditive inverses, we have written $-\\vect{u}$ for $(-1)\\vect{u}$.\nOften, the scalars will be real numbers, but it is also possible to\nuse scalars from a different field $K$. We also use the term\n\\textbf{$K$-vector space}%\n\\index{K-vector space@$K$-vector space} to refer to a vector space\nover a field $K$.  When $K=\\R$, we also speak of a \\textbf{real vector\n  space}%\n\\index{vector space!real}%\n\\index{real vector space}, and when $K=\\C$, we speak of a\n\\textbf{complex vector space}%\n\\index{vector space!complex}%\n\\index{complex vector space}. If the field is clear from the context,\nwe often don't mention it at all, and just speak of a ``vector\nspace''. The elements of a vector space are called \\textbf{vectors}%\n\\index{vector!in a vector space}.\n\nOur first example of a vector space is of course $\\R^n$.\n\n\\begin{example}{$\\R^n$ is a vector space}{Rn-vector-space}\n  The set $\\R^n$ of $n$-dimensional real column vectors, with the\n  usual operations of vector addition and scalar multiplication, is a\n  vector space.\n\n  More generally, if $K$ is a field, the set $K^n$ of $n$-dimensional\n  column vectors with components in $K$ is a $K$-vector space.\n\\end{example}\n\n\\begin{proof}\n  Properties (A1)--(A4) hold by\n  Proposition~\\ref{prop:properties-vector-addition}, and properties\n  (SM1)--(SM4) hold by Proposition~\\ref{prop:vector-scalar-multiplication}.\n\\end{proof}\n\nWe now consider some other examples of vector spaces.\n\n\\begin{example}{Vector space of polynomials of degree 2}{vector-space-polynomials2}\n  Let $\\Poly_2$%\n  \\index{P2@$\\Poly_2$}%\n  \\index{vector space!of polynomials} be the set of all polynomials%\n  \\index{polynomial} of degree at most $2$ with coefficients from a\n  field $K$, i.e., expressions of the form\n  \\begin{equation*}\n    p(x) = ax^2 + bx + c,\n  \\end{equation*}\n  where $a,b,c\\in K$. Define addition%\n  \\index{polynomial!addition}%\n  \\index{addition!of polynomials} and scalar multiplication%\n  \\index{polynomial!scalar multiplication}%\n  \\index{scalar multiplication!of polynomials} of polynomials in the\n  usual way, i.e.,\n  \\begin{eqnarray*}\n    (ax^2 + bx + c) + (a'x^2 + b'x + c') &=& (a + a')x^2 + (b + b')x + (c + c') \\\\\n    k(ax^2 + bx + c) &=& ka\\,x^2 + kb\\,x + kc.\n  \\end{eqnarray*}\n  Then $\\Poly_2$ is a vector space.\n\\end{example}\n\n\\begin{proof}\n  To show that $\\Poly_2$ is a vector space, we verify the $8$ vector\n  space axioms. Let\n  \\begin{eqnarray*}\n    p(x) &=& a_2x^2 + a_1x + a_0, \\\\\n    q(x) &=& b_2x^2 + b_1x + b_0, \\\\\n    r(x) &=& c_2x^2 + c_1x + c_0\n  \\end{eqnarray*}\n  be polynomials in $\\Poly_2$ and let $k,\\ell$ be scalars.\n\n  \\begin{itemize}\n  \\item[(A1)] We prove the commutative law of addition.\n    \\begin{eqnarray*}\n      p(x) + q(x)\n      &=& (a_2x^2 + a_1x + a_0) + (b_2x^2 + b_1x + b_0) \\\\\n      &=& (a_2 + b_2)x^2 + (a_1 + b_1)x + (a_0 + b_0) \\\\\n      &=& (b_2 + a_2)x^2 + (b_1 + a_1)x + (b_0 + a_0) \\\\\n      &=& (b_2x^2 + b_1x + b_0) + (a_2x^2 + a_1x + a_0) \\\\\n      &=& q(x) + p(x).\n    \\end{eqnarray*}\n  \\item[(A2)] We prove the associative law of addition.\n    \\begin{eqnarray*}\n      (p(x) + q(x)) + r(x)\n      &=& ((a_2x^2 + a_1x + a_0) + (b_2x^2 + b_1x + b_0)) + (c_2x^2 + c_1x + c_0) \\\\\n      &=& ((a_2 + b_2)x^2 + (a_1 + b_1)x + (a_0 + b_0)) + (c_2x^2 + c_1x + c_0) \\\\\n      &=& ((a_2 + b_2) + c_2)x^2 + ((a_1 + b_1) + c_1)x + ((a_0 + b_0) + c_0) \\\\\n      &=& (a_2 + (b_2 + c_2))x^2 + (a_1 + (b_1 + c_1))x + (a_0 + (b_0 + c_0)) \\\\\n      &=& (a_2x^2 + a_1x + a_0) + ((b_2 + c_2)x^2 + (b_1 + c_1)x + (b_0 + c_0)) \\\\\n      &=& (a_2x^2 + a_1x + a_0) + ((b_2x^2 + b_1x + b_0) + (c_2x^2 + c_1x + c_0)) \\\\\n      &=& p(x) + (q(x) + r(x)).\n    \\end{eqnarray*}\n  \\item[(A3)] To prove the existence of an additive unit, let $0(x) =\n    0x^2 + 0x + 0$, the so-called \\textbf{zero polynomial}%\n    \\index{polynomial!zero}%\n    \\index{zero polynomial}. Then\n    \\begin{eqnarray*}\n      p(x) + 0(x)  &=&  (a_2x^2 + a_1x + a_0) + (0x^2 + 0x + 0) \\\\\n                   &=&  (a_2 + 0)x^2 + (a_1 + 0)x + (a_0 + 0) \\\\\n                   &=&  a_2x^2 + a_1x + a_0 \\\\\n                   &=&  p(x).\n    \\end{eqnarray*}\n  \\item[(A4)] We prove the law of additive inverses.\n    \\begin{eqnarray*}\n      p(x) + (-p(x)) &=& (a_2x^2 + a_1x + a_0) + (- a_2x^2  - a_1x - a_0) \\\\\n                     &=& (a_2 - a_2)x^2 + (a_1 - a_1)x + (a_0 - a_0) \\\\\n                     &=& 0x^2 + 0x + 0 \\\\\n                     &=& 0(x).\n    \\end{eqnarray*}\n  \\item[(SM1)] We prove the distributive law over vector addition.\n    \\begin{eqnarray*}\n      k(p(x) + q(x)) &=& k ((a_2x^2 + a_1x + a_0) + (b_2x^2 + b_1x + b_0)) \\\\\n                     &=& k ((a_2 + b_2)x^2 + (a_1 + b_1)x + (a_0 + b_0)) \\\\\n                     &=& k(a_2 + b_2)x^2 + k(a_1 + b_1)x + k(a_0 + b_0) \\\\\n                     &=& (ka_2 + kb_2)x^2 + (ka_1 + kb_1)x + (ka_0 + kb_0) \\\\\n                     &=& (ka_2x^2 + ka_1x + ka_0) + (kb_2x^2 + kb_1x + kb_0) \\\\\n                     &=& kp(x) + kq(x).\n    \\end{eqnarray*}\n  \\item[(SM2)] We prove the distributive law over scalar addition.\n    \\begin{eqnarray*}\n      (k + \\ell) p(x) &=& (k + \\ell) (a_2x^2 + a_1x + a_0) \\\\\n                 &=& (k + \\ell)a_2x^2 + (k + \\ell)a_1x + (k + \\ell)a_0   \\\\\n                 &=& (ka_2x^2 + ka_1x + ka_0) + (\\ell a_2x^2 + \\ell a_1x + \\ell a_0) \\\\\n                 &=& kp(x) + \\ell p(x).\n    \\end{eqnarray*}\n  \\item[(SM3)] We prove the associative law for scalar multiplication.\n    \\begin{eqnarray*}\n      k(\\ell p(x)) &=& k(\\ell(a_2x^2 + a_1x + a_0)) \\\\\n               &=& k(\\ell a_2x^2 + \\ell a_1x + \\ell a_0) \\\\\n               &=&  k\\ell a_2x^2 + k\\ell a_1x + k\\ell a_0 \\\\\n               &=& (k\\ell) (a_2x^2 + a_1x + a_0) \\\\\n               &=& (k\\ell) p(x).\n    \\end{eqnarray*}\n  \\item[(SM4)] Finally, we prove the rule for multiplication by one.\n    \\begin{eqnarray*}\n      1p(x) &=& 1 (a_2x^2 + a_1x + a_0) \\\\\n            &=& 1a_2x^2 + 1a_1x + 1a_0 \\\\\n            &=& a_2x^2 + a_1x + a_0 \\\\\n            &=& p(x).\n    \\end{eqnarray*}\n  \\end{itemize}\n  Since the operations of addition and scalar multiplication on\n  $\\Poly_2$ satisfy the $8$ vector space axioms, $\\Poly_2$ is a vector\n  space.\n\\end{proof}\n\nOur next example of a vector space is the set of all\n$n\\times m$-matrices.\n\n\\begin{example}{Vector space of matrices}{vector-space-matrices}\n  Let $\\Mat_{m,n}$%\n  \\index{Mmn@$\\Mat_{m,n}$} be the set of all $m\\times n$-matrices\n  with entries in a field $K$%\n  \\index{vector space!of matrices}%\n  \\index{matrix!vector space of}, together with the usual operations\n  of matrix addition and scalar multiplication. Then $\\Mat_{m,n}$ is a\n  vector space.\n\\end{example}\n\n\\begin{proof}\n  The properties (A1)--(A4) hold by\n  Proposition~\\ref{prop:properties-of-addition}, and the properties\n  (SM1)--(SM4) hold by Proposition~\\ref{prop:properties-scalar-multiplication}.\n\\end{proof}\n\nWe now examine an example of a set that does not satisfy all of the\nabove axioms, and is therefore \\textit{not} a vector space.\n\n\\begin{example}{Not a vector space}{not-vector-space}\n  Let $V$ denote the set of $2 \\times 3$-matrices. Let us define a\n  non-standard addition in $V$ by $A \\oplus B = A$ for all matrices\n  $A,B\\in V$. Let scalar multiplication in $V$ be the usual scalar\n  multiplication of matrices. Show that $V$ is not a vector space.\n\\end{example}\n\n\\begin{solution}\n  In order to show that $V$ is not a vector space, it suffices to find\n  one of the 8 axioms that is not satisfied. We will begin by examining\n  the axioms for addition until one is found which does not hold. In\n  fact, for this example, the very first axiom fails. Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 0 & 0\n    \\end{mymatrix},\n    \\quad\n    B = \\begin{mymatrix}{rrr}\n      0 & 0 & 0 \\\\\n      1 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  Then $A\\oplus B=A$ and $B\\oplus A=B$. Since $A\\neq B$, we have\n  $A\\oplus B\\neq B\\oplus A$ for these two matrices, so property (A1)\n  is false.\n\\end{solution}\n\nOur next example looks a little different.\n\n\\begin{example}{Vector space of functions}{vector-space-function}\n  Let $X$ be a nonempty set, $K$ a field, and define $\\Func_{X,K}$%\n  \\index{FuncXK@$\\Func_{X,K}$} to be the set of functions\n  \\index{function!vector space of} defined on $X$ and valued in\n  $K$. In other words, the elements of $\\Func_{X,K}$ are functions\n  $f:X\\to K$. The sum of two functions is defined by\n  \\begin{equation*}\n    (f + g)(x) = f(x) + g(x),\n  \\end{equation*}\n  and the scalar multiplication is defined by\n  \\begin{equation*}\n    (kf) (x) = k(f(x)).\n  \\end{equation*}\n  Then $\\Func_{X,K}$ is a vector space.\n\\end{example}\n\n\\begin{proof}\n  To verify that $\\Func_{X,K}$ is a vector space, we must prove the 8\n  axioms of vector spaces. Let $f, g, h$ be functions in $\\Func_{X,K}$,\n  and let $k,\\ell$ be scalars. Recall that two functions $f,g$\n  are \\textbf{equal}%\n  \\index{function!equality of}%\n  \\index{equality of functions} if for all $x\\in X$, we have\n  $f(x)=g(x)$.\n\n  \\begin{itemize}\n  \\item[(A1)] We prove the commutative law of addition. For all\n    $x\\in X$, we have\n    \\begin{equation*}\n      (f + g) (x)\n      ~=~ f(x) + g(x)\n      ~=~ g(x) + f(x)\n      ~=~ (g + f) (x).\n    \\end{equation*}\n    Therefore, $f + g = g + f$.\n  \\item[(A2)] We prove the associative law of addition. For all\n    $x\\in X$, we have\n    \\begin{equation*}\n      ((f + g) + h) (x)\n      ~=~ (f + g) (x) + h(x)\n      ~=~ (f(x) + g(x)) + h(x)\n    \\end{equation*}\n    \\begin{equation*}\n      ~=~ f(x) + (g(x) + h(x))\n      ~=~ (f(x) + (g + h) (x))\n      ~=~ (f + (g + h)) (x).\n    \\end{equation*}\n    Therefore, $(f + g) + h = f + (g + h)$.\n  \\item[(A3)] To prove the existence of an additive unit, let $0$\n    denote the function that is given by $0(x)=0$. This is called the\n    \\textbf{zero function}%\n    \\index{function!zero function}%\n    \\index{zero function}. It is an additive unit because for all $x$,\n    \\begin{equation*}\n      (f + 0) (x)\n      ~=~ f(x) + 0(x)\n      ~=~ f(x),\n    \\end{equation*}\n    and so $f+0 = f$.\n  \\item[(A4)] We prove the law of additive inverses. Let $-f = (-1)f$\n    be the function that satisfies $(-f) (x) = -f(x)$. Then for all $x$,\n    \\begin{equation*}\n      (f + (-f)) (x)\n      ~=~ f(x) + (-f) (x)\n      ~=~ f(x) + -f(x)\n      ~=~ 0.\n    \\end{equation*}\n    Therefore $f + (-f) = 0$.\n  \\item[(SM1)] We prove the distributive law over vector addition. For\n    all $x$, we have\n    \\begin{equation*}\n      (k(f + g)) (x)\n      ~=~ k(f + g) (x)\n      ~=~ k(f(x) + g(x))\n    \\end{equation*}\n    \\begin{equation*}\n      ~=~ kf(x) + k g(x)\n      ~=~ (kf + kg) (x),\n    \\end{equation*}\n    and so $k(f + g) = kf + kg$.\n  \\item[(SM2)] We prove the distributive law over scalar addition.\n    \\begin{equation*}\n      ((k + \\ell) f) (x)\n      ~=~ (k + \\ell) f(x)\n      ~=~ kf(x) + \\ell f(x)\n      ~=~ (kf + \\ell f) (x),\n    \\end{equation*}\n    and so $(k + \\ell) f = kf + \\ell f$.\n  \\item[(SM3)] We prove the associative law for scalar multiplication.\n    \\begin{equation*}\n      ((k\\ell ) f) (x)\n      ~=~ (k\\ell) f(x)\n      ~=~ k(\\ell f(x))\n      ~=~ (k(\\ell f)) (x),\n    \\end{equation*}\n    so $(k\\ell f) =k(\\ell f)$.\n  \\item[(SM4)] Finally, we prove the rule for multiplication by one.\n    For all $x\\in X$, we have\n    \\begin{equation*}\n      (1f) ( x) ~=~ 1f(x) ~=~f(x),\n    \\end{equation*}\n    and therefore $1f=f$.\n  \\end{itemize}\n\n  It follows that $\\Func_{X,K}$ satisfies all the required axioms and is a\n  vector space.\n\\end{proof}\n\nFor the next two examples of vector spaces, we leave the proofs as an\nexercise.\n\n\\begin{example}{Infinite sequences}{vector-space-sequences}\n  Let $K$ be a field. A \\textbf{sequence}%\n  \\index{sequence} of elements of $K$ is an infinite list\n  \\begin{equation*}\n    (a_0,\\,a_1,\\,a_2,\\,a_3\\, \\ldots),\n  \\end{equation*}\n  where $a_i\\in K$ for all $i$. We also use the notation\n  $(a_i)_{i\\in\\N}$, or occasionally $(a_i)$, to denote such a\n  sequence. Let $\\Seq_K$ be the set of sequences%\n  \\index{vector space!of sequences}%\n  \\index{SeqK@$\\Seq_K$} of elements of $K$. We add two\n  sequences by adding their $i\\th$ elements:\n  \\begin{equation*}\n    (a_i)_{i\\in\\N} + (b_i)_{i\\in\\N} = (a_i+b_i)_{i\\in\\N}.\n  \\end{equation*}\n  We scale a sequence by scaling each of its elements:\n  \\begin{equation*}\n    k(a_i)_{i\\in\\N} = (ka_i)_{i\\in\\N}.\n  \\end{equation*}\n  Then $\\Seq_K$ is a vector space.\n\\end{example}\n\n\\begin{example}{Vector space of polynomials of unbounded degree}{vector-space-polynomials}\n  Let $K$ be a field, and let $\\Poly$%\n  \\index{P@$\\Poly$}%\n  \\index{vector space!of polynomials} be the set of all polynomials%\n  \\index{polynomial} (of any degree) with coefficients from $K$, i.e.,\n  expressions of the form\n  \\begin{equation*}\n    p(x) = a_nx^n + a_{n-1}x^{n-1} + \\ldots + a_1x + a_0,\n  \\end{equation*}\n  where $n\\geq 0$ and $a_0,\\ldots,a_n\\in K$. Addition and scalar\n  multiplication of polynomials are defined in the usual way\n  \\index{polynomial!addition}%\n  \\index{addition!of polynomials}%\n  \\index{polynomial!scalar multiplication}%\n  \\index{scalar multiplication!of polynomials}.\n  Then $\\Poly$ is a vector space.\n\\end{example}\n\nWe conclude this section by deriving some initial consequences of the\nvector space axioms.\n\n\\begin{proposition}{Elementary consequences of the vector space axioms}{vector-space-elementary}\n  In any vector space, the following are true:\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item The additive unit is unique. In other words, whenever\n      $\\vect{u}+\\vect{v}=\\vect{u}$, then $\\vect{v}=\\vect{0}$.\n    \\item Additive inverses are unique. In other words, whenever\n      $\\vect{u}+\\vect{v}=\\vect{0}$, then $\\vect{v}=-\\vect{u}$.\n    \\item\\label{vector-space-elementary-c} $0\\vect{u}=\\vect{0}$ for\n      all vectors $\\vect{u}$.\n    \\item The following \\textbf{cancellation law}%\n      \\index{cancellation law!of addition}%\n      \\index{vector!cancellation law}\n      holds: if $\\vect{u} + \\vect{w} = \\vect{v} + \\vect{w}$, then\n      $\\vect{u} = \\vect{v}$.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{proposition}\n\n\\begin{proof}\n  We prove the first three properties, and leave the last one as an\n  exercise. Assume $V$ is any vector space over a field $K$.\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item Consider arbitrary vectors $\\vect{u},\\vect{v}\\in V$ and assume\n      \\begin{equation*}\n        \\vect{u}+\\vect{v}=\\vect{u}.\n      \\end{equation*}\n      Applying the law (A1) (commutative law) to the left-hand side, we have\n      \\begin{equation*}\n        \\vect{v}+\\vect{u}=\\vect{u}.\n      \\end{equation*}\n      Adding $-\\vect{u}$ to both sides of the equation, we have\n      \\begin{equation*}\n        (\\vect{v}+\\vect{u})+(-\\vect{u}) = \\vect{u}+(-\\vect{u}).\n      \\end{equation*}\n      Applying the law (A2) (associative law) to the left-hand side, we\n      have\n      \\begin{equation*}\n        \\vect{v}+(\\vect{u}+(-\\vect{u})) = \\vect{u}+(-\\vect{u}).\n      \\end{equation*}\n      Applying the law (A4) (additive inverse law) to both sides of the\n      equation, we have\n      \\begin{equation*}\n        \\vect{v}+\\vect{0} = \\vect{0}.\n      \\end{equation*}\n      Applying the law (A3) (additive unit law) to the left-hand side,\n      we have\n      \\begin{equation*}\n        \\vect{v} = \\vect{0}.\n      \\end{equation*}\n      This proves that whenever $\\vect{u}+\\vect{v}=\\vect{u}$, then\n      $\\vect{v} = \\vect{0}$, or in other words, $\\vect{v} = \\vect{0}$ is\n      the only element acting as an additive unit.\n\n    \\item Consider arbitrary vectors $\\vect{u},\\vect{v}\\in V$ and assume\n      \\begin{equation*}\n        \\vect{u}+\\vect{v}=\\vect{0}.\n      \\end{equation*}\n      Applying the law (A1) (commutative law) to the left-hand side, we\n      have\n      \\begin{equation*}\n        \\vect{v}+\\vect{u}=\\vect{0}.\n      \\end{equation*}\n      Adding $-\\vect{u}$ to both sides of the equation, we have\n      \\begin{equation*}\n        (\\vect{v}+\\vect{u})+(-\\vect{u}) = \\vect{0}+(-\\vect{u}).\n      \\end{equation*}\n      Applying the law (A2) (associative law) to the left-hand side, we\n      have\n      \\begin{equation*}\n        \\vect{v}+(\\vect{u}+(-\\vect{u})) = \\vect{0}+(-\\vect{u}).\n      \\end{equation*}\n      Applying the law (A4) (additive inverse law) to the left-hand\n      side, we have\n      \\begin{equation*}\n        \\vect{v}+\\vect{0} = \\vect{0}+(-\\vect{u}).\n      \\end{equation*}\n      Applying the law (A1) (commutative law) to the right-hand side, we\n      have\n      \\begin{equation*}\n        \\vect{v}+\\vect{0} = -\\vect{u} + \\vect{0}.\n      \\end{equation*}\n      Applying the law (A3) (additive unit law) to both sides of the\n      equation, we have\n      \\begin{equation*}\n        \\vect{v} = -\\vect{u}.\n      \\end{equation*}\n      This proves that whenever $\\vect{u}+\\vect{v}=\\vect{0}$, then\n      $\\vect{v} = -\\vect{u}$, or in other words, $\\vect{v} = -\\vect{u}$\n      is the only element acting as an additive inverse of $\\vect{u}$.\n\n    \\item First, note that the scalar $0\\in K$ satisfies the property\n      $0+0=0$, by property (A3) of the definition of a field. Now let\n      $\\vect{u}\\in V$ be any vector. Using the vector space law (SM2)\n      (distributive law over scalar addition) and $0+0=0$, we have\n      \\begin{equation*}\n        0\\vect{u}+0\\vect{u} = (0+0) \\vect{u} = 0\\vect{u}.\n      \\end{equation*}\n      Next, we use a small trick: add $-(0\\vect{u})$ to both sides of\n      the equation. This gives\n      \\begin{eqnarray*}\n        (0\\vect{u}+0\\vect{u})+(-(0\\vect{u})) &=& 0\\vect{u} + (-(0\\vect{u})).\n      \\end{eqnarray*}\n      Applying the additional laws (A2), (A4), and (A3), we have\n      \\begin{eqnarray*}\n        0\\vect{u}+(0\\vect{u}+(-(0\\vect{u}))) &=& 0\\vect{u} + (-(0\\vect{u})), \\\\\n        0\\vect{u} + \\vect{0} &=& \\vect{0}, \\\\\n        0\\vect{u} &=& \\vect{0}.\n      \\end{eqnarray*}\n      This proves that $0\\vect{u} = \\vect{0}$ holds for all vectors\n      $\\vect{u}$, as desired.\n\n    \\item This is left as an exercise.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{proof}\n\n", "meta": {"hexsha": "9778ec4a663cf711888b1eba589aea40cb89098b", "size": 20716, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/VectorSpaces-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/VectorSpaces-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/VectorSpaces-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 38.9398496241, "max_line_length": 96, "alphanum_fraction": 0.5940335972, "num_tokens": 7523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.9086178919837706, "lm_q1q2_score": 0.8089372603395109}}
{"text": "\\section{Sums and intersections}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Show that the sum of two subspaces is a subspace.\n  \\item Show that the intersection of two subspaces is a subspace.\n  \\end{enumerate}\n\\end{outcome}\n\nWe begin this section with a definition.\n\n\\begin{definition}{Sum and intersection}{sum-intersection}\nLet $V$ be a vector space, and let $U$ and $W$ be subspaces of\n$V$.\nThen\n\\begin{enumerate}\n\\item $U+W = \\set{\\vect{u}+\\vect{w} \\mid \\vect{u}\\in U\\mbox{ and } \\vect{w}\\in W}$ and is\ncalled the sum of $U$ and $W$.\n\n\\item $U\\cap W = \\set{\\vect{v} \\mid \\vect{v}\\in U\\mbox{ and } \\vect{v}\\in W}$ and is\ncalled the intersection of $U$ and $W$.\n\\end{enumerate}\n\\end{definition}\n\nTherefore the intersection of two subspaces is all the vectors shared by both. If there are no vectors shared by both subspaces, meaning that $U \\cap W = \\set{\\vect{0} }$, the sum $U+W$ takes on a special name.\n\n\\begin{definition}{Direct sum}{direct-sum}\nLet $V$ be a vector space and suppose $U$ and $W$ are subspaces of $V$ such that  $U \\cap W = \\set{\\vect{0} }$. Then the sum of $U$ and $W$ is called the direct sum and is denoted $U \\oplus W$.\n\\end{definition}\n\nAn interesting result is that both the sum $U + W$ and the intersection $U \\cap W$ are subspaces of $V$.\n\n\\begin{example}{Intersection is a subspace}{intersection-subspace}\nLet $V$ be a vector space and suppose $U$ and $W$ are subspaces. Then the intersection $U \\cap W$ is a subspace of $V$.\n\\end{example}\n\n\\begin{solution}\nBy the subspace test, we must show three things:\n\\begin{enumerate}\n\\item $\\vect{0} \\in U \\cap W$\n\\item For vectors $\\vect{v}_1, \\vect{v}_2 \\in U \\cap W, \\vect{v}_1+\\vect{v}_2 \\in U \\cap W$\n\\item For scalar $a$ and vector $\\vect{v} \\in U \\cap W, a\\vect{v} \\in U \\cap W$\n\\end{enumerate}\n\nWe proceed to show each of these three conditions hold.\n\\begin{enumerate}\n\\item\nSince $U$ and $W$ are subspaces of $V$, they each contain $\\vect{0}$. By definition of the intersection, $\\vect{0} \\in U \\cap W$.\n\n\\item\nLet  $\\vect{v}_1, \\vect{v}_2 \\in U \\cap W$,. Then in particular,  $\\vect{v}_1, \\vect{v}_2 \\in U$. Since $U$ is a subspace, it follows that $ \\vect{v}_1+\\vect{v}_2 \\in U$. The same argument holds for $W$. Therefore $\\vect{v}_1+\\vect{v}_2$ is in both $U$ and $W$ and by definition is also in $U \\cap W$.\n\n\\item\nLet $a$ be a scalar and $\\vect{v} \\in U \\cap W$. Then in particular, $\\vect{v} \\in U$. Since $U$ is a subspace, it follows that $a \\vect{v} \\in U$. The same argument holds for $W$ so $a\\vect{v}$ is in both $U$ and $W$. By definition, it is in $U \\cap W$.\n\\end{enumerate}\n\nTherefore $U \\cap W$ is a subspace of $V$.\n\\end{solution}\n\nIt can also be shown that $U + W$ is a subspace of $V$.\n\nWe conclude this section with an important theorem on dimension.\n\n\\begin{theorem}{Dimension of sum}{dimension-sum}\nLet $V$ be a vector space with subspaces $U$ and $W$. Suppose $U$ and $W$ each have finite dimension. Then $U + W$ also has finite dimension which is given by\\[\n\\dim (U+W) = \\dim(U) + \\dim(W) - \\dim (U \\cap W)\n\\]\n\\end{theorem}\n\nNotice that when $U \\cap W = \\set{\\vect{0} }$, the sum becomes the direct sum and the above equation becomes\n\\[\n\\dim (U \\oplus W) = \\dim(U) + \\dim(W)\n\\]\n", "meta": {"hexsha": "ccba5e7e7fd642620adb9a8ccc58964aa27c039c", "size": 3189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/vectorspacesSumsIntersections.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/vectorspacesSumsIntersections.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/vectorspacesSumsIntersections.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 43.0945945946, "max_line_length": 301, "alphanum_fraction": 0.6760740044, "num_tokens": 1067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726544, "lm_q2_score": 0.8840392695254318, "lm_q1q2_score": 0.808808369888855}}
{"text": "\n\\subsection{Ordering}\n\n\\subsubsection{Ordering of the natural numbers}\n\nFor natural numbers we can say that number \\(n\\) preceeds number \\(s(n)\\). That is:\n\n\\(n\\le s(n)\\)\n\nSimilarly:\n\n\\(s(n)\\le s(s(n))\\)\n\nFrom the transitive property we know that:\n\n\\(n\\le s(s(n))\\)\n\nWe can continue this to get:\n\n\\(n\\le s(s(...s(n)..))\\)\n\nWhat can we say about an arbitary comparison?\n\n\\(a\\le b\\)\n\nWe know that either:\n\n\\begin{itemize}\n\\item \\(a=b\\)\n\\item \\(b=s(s(...s(a)...))\\)\n\\item \\(a=s(s(...s(b)...))\\)\n\\end{itemize}\n\nIn the first case the relation holds.\n\nIn the second case the relation holds.\n\nIn the third case the relation does not hold, but antisymmetry holds.\n\nAs this is is then defined on any pair, the order on natural numbers is total.\n\nAs there is a minimum, \\(0\\), the relation is also well-ordered.\n\nHowever if this does not hold then the following instead holds:\n\n", "meta": {"hexsha": "97c9bb860937f4f75c65e60e86c88b4e43164c75", "size": 869, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sets/01-03-orderingNatural.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sets/01-03-orderingNatural.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sets/01-03-orderingNatural.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.8913043478, "max_line_length": 83, "alphanum_fraction": 0.6743383199, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897475985937, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.8087628377880958}}
{"text": "\\subsection{Enumerative combinatorics}\\label{subsec:enumerative_combinatorics}\n\nThis subsection lists several results of various importance that don't really belong to any more consistent theory.\n\n\\begin{theorem}[Dirichlet's pigeonhole principle]\\label{def:pigeonhole_principle}\n  If we have more pigeons than pigeonholes, then at least one pigeonhole must contain multiple pigeons in it.\n\n  More formally, if \\( \\card(A) > \\card(B) \\), then there exists no injective function from \\( A \\) to \\( B \\).\n\\end{theorem}\n\\begin{proof}\n  This is a corollary of \\fullref{thm:set_domination_relation_trichotomy}.\n\\end{proof}\n\n\\begin{definition}\\label{def:binomial_coefficient}\n  The \\term{binomial coefficient} of the \\hyperref[rem:peano_arithmetic_zero/positive]{positive integers} \\( n \\) and \\( k \\) is\n  \\begin{equation*}\n    \\binom n k \\coloneqq \\frac {n!} {k!(n-k)!}\n  \\end{equation*}\n\n  They are motivated by \\fullref{thm:binomial_theorem}.\n\\end{definition}\n\n\\begin{theorem}[Pascal's identity]\\label{thm:pascals_identity}\n  \\begin{equation*}\n    \\binom n k = \\binom {n - 1} k + \\binom {n - 1} {k - 1}.\n  \\end{equation*}\n\\end{theorem}\n\\begin{proof}\n  \\begin{balign*}\n    \\binom {n - 1} k + \\binom {n - 1} {k - 1}\n    &=\n    \\frac {(n - 1)!} {k! (n - 1 - k)!} + \\frac {(n - 1)!} {(k - 1)! (n - k)!}\n    = \\\\ &=\n    \\frac {(n - 1)!} {(k - 1)! (n - 1 - k)!} \\bracks*{ \\frac 1 k + \\frac 1 {n - k} }\n    = \\\\ &=\n    \\frac {(n - 1)!} {(k - 1)! (n - 1 - k)!} \\frac n {k(n - k)}\n    = \\\\ &=\n    \\frac {n!} {k! (n - k)!}\n    = \\\\ &=\n    \\binom n k.\n  \\end{balign*}\n\\end{proof}\n\n\\begin{definition}\\label{def:factorial}\n  The \\term{factorial} of a \\hyperref[rem:peano_arithmetic_zero/nonnegative]{nonnegative integer} \\( n \\) is defined recursively as\n  \\begin{equation*}\n    n! \\coloneqq \\begin{cases}\n      1,          &n = 0 \\\\\n      (n - 1)! n, &n > 0.\n    \\end{cases}\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:gamma_function_interpolates_factorial}\n  For every \\hyperref[rem:peano_arithmetic_zero/nonnegative]{nonnegative integer} \\( n \\) we have\n  \\begin{equation*}\n    \\Gamma(n + 1) \\coloneqq n!,\n  \\end{equation*}\n  where \\( \\Gamma \\) is the Gamma function defined in \\fullref{def:gamma_function}.\n\\end{proposition}\n\\begin{proof}\n  We use induction on \\( n \\).\n  \\begin{itemize}\n    \\item If \\( n = 0 \\), then\n    \\begin{equation*}\n      \\Gamma(1)\n      =\n      \\int_0^\\infty x^0 e^{-x} \\dl x\n      =\n      -e^{-x}\\restr_{x=0}^\\infty\n      =\n      -\\underbrace{\\lim_{x \\to \\infty} e^{-x}}_{0} + 1\n      =\n      1\n      =\n      0!\n    \\end{equation*}\n\n    \\item If \\( n > 0 \\) and \\( \\Gamma(n) = (n - 1)! \\), then\n    \\begin{balign*}\n      \\Gamma(n + 1)\n      &=\n      \\int_0^\\infty x^n \\cdot e^{-x} \\dl x\n      = \\\\ &=\n      \\underbrace{(- x^n e^{-x})\\restr_{x=0}^\\infty}_{-(0 - 0)} + n \\int_0^\\infty e^{-x} x^{n-1} \\dl x\n      = \\\\ &=\n      n \\Gamma(n)\n      = \\\\ &=\n      n (n - 1)!\n      = \\\\ &=\n      n!\n    \\end{balign*}\n  \\end{itemize}\n\\end{proof}\n\n\\begin{theorem}[Stirling's factorial approximation]\\label{thm:stirlings_factorial_approximation}\n  For every \\hyperref[rem:peano_arithmetic_zero/nonnegative]{nonnegative integer} \\( n \\) there exists some constant \\( \\theta \\in (0, 1) \\) such that\n  \\begin{equation*}\n    n! = \\sqrt{2 \\pi n} \\cdot \\parens*{ \\frac n e }^n \\cdot e^{\\frac 1 {12n + \\theta}}.\n  \\end{equation*}\n\\end{theorem}\n\\begin{proof}\n  Follows from \\fullref{thm:gamma_function_interpolates_factorial} and \\fullref{thm:stirlings_gamma_approximation}.\n\\end{proof}\n\n\\begin{remark}\\label{rem:double_index_maps}\n  We want to be able to map single indices to double indices and vice versa, for example for the purpose of \\fullref{thm:matrix_spaces_are_tuple_spaces}. As an example, we want to be able to \\enquote{linearize} an \\( m \\times n \\) matrix such as the \\( 2 \\times 3 \\) matrix\n  \\begin{equation}\\label{eq:rem:double_index_maps/example/matrix}\n    \\begin{pmatrix}\n      1 & 2 & 3 \\\\\n      4 & 5 & 6\n    \\end{pmatrix}\n  \\end{equation}\n  into the tuple\n  \\begin{equation}\\label{eq:rem:double_index_maps/example/row_major}\n    (1, 2, 3, 4, 5, 6)\n  \\end{equation}\n  and vice versa. This is called \\term{row-major order} of the elements of a matrix. The \\term{column-major order} would instead be\n  \\begin{equation}\\label{eq:rem:double_index_maps/example/column_major}\n    (1, 4, 2, 5, 3, 6).\n  \\end{equation}\n\n  Let \\( m \\) and \\( n \\) be \\hyperref[rem:peano_arithmetic_zero/positive]{positive integers}. We will explicitly define functions for linearizing a matrix like \\eqref{eq:rem:double_index_maps/example/matrix} into its row-major order \\eqref{eq:rem:double_index_maps/example/row_major}. Define the sets\n  \\begin{align*}\n    S &\\coloneqq \\overbrace{ \\set{ 1, \\ldots, mn - 1, mn } }^{\\T{single indices}}\n    \\\\\n    D &\\coloneqq \\underbrace{ \\set{ 1, \\ldots, m } \\times \\set{ 1, \\ldots, n } }_{\\T{double indices}}\n  \\end{align*}\n  and the mutually inverse operations\n  \\begin{align}\n    &\\begin{aligned}\\label{eq:rem:double_index_maps/sharp}\n      &\\sharp: S \\to D \\\\\n      &\\sharp(k) \\coloneqq \\parens[\\Big]{ \\quot(k - 1, m) + 1, \\rem(k - 1, m) + 1 } \\\\\n    \\end{aligned}\n    \\\\[0.5\\baselineskip]\n    &\\begin{aligned}\\label{eq:rem:double_index_maps/flat}\n      &\\flat: D \\to S \\\\\n      &\\flat(i, j) \\coloneqq (i - 1) \\cdot m + (j - 1) + 1.\n    \\end{aligned}\n  \\end{align}\n\n  The operation \\( \\sharp \\) encodes the matrix \\eqref{eq:rem:double_index_maps/example/matrix} into its row-major order \\eqref{eq:rem:double_index_maps/example/row_major} and \\( \\flat \\) does the opposite. Both operations are trivial except for the shifting needed in to allow us to use \\hyperref[def:euclidean_domain]{remainders and quotients}.\n\n  We can easily verify that \\( \\sharp \\) is a \\hyperref[def:morphism_invertibility/left_invertible]{left inverse} of \\( \\flat \\) (note that \\( j < m \\)):\n  \\begin{align*}\n    \\sharp(\\flat(i, j))\n    &=\n    \\sharp\\parens[\\Big]{ (i - 1) \\cdot m + (j - 1) + 1 }\n    = \\\\ &=\n    \\parens[\\Big]{ \\quot(\\cdots, m) + 1, \\rem(\\cdots, m) + 1 }\n    = \\\\ &=\n    \\parens[\\Big]{ (i - 1) + 1, (j - 1) + 1 }\n    = \\\\ &=\n    (i, j).\n  \\end{align*}\n\n  We can just as easily verify that \\( \\flat \\) is a \\hyperref[def:morphism_invertibility/right_invertible]{right inverse} of \\( \\sharp \\):\n  \\begin{align*}\n    \\flat(\\sharp(k))\n    &=\n    \\flat\\parens[\\Big]{ \\quot(k, m) + 1, \\rem(k, m) + 1 }\n    = \\\\ &=\n    \\quot(k, m) \\cdot m + \\rem(k, m)\n    = \\\\ &=\n    k.\n  \\end{align*}\n\n  Hence, \\( \\sharp \\) is fully invertible with inverse \\( \\flat \\). By \\fullref{thm:function_invertibility_categorical/fully_invertible}, it is bijective.\n\\end{remark}\n", "meta": {"hexsha": "dce4c0ba3229f907167a3a3e2cbcdca46f59c2d4", "size": 6596, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/enumerative_combinatorics.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/enumerative_combinatorics.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/enumerative_combinatorics.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.8, "max_line_length": 346, "alphanum_fraction": 0.6197695573, "num_tokens": 2349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.8740772236840656, "lm_q1q2_score": 0.8087224357685224}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath,amssymb}\n\\usepackage[pdfborder={0 0 0}]{hyperref}\n\\newcommand\\set[1]{\\left\\{#1\\right\\}}\n\n\\begin{document}\n\\section{Exercise 9}\n\n\\subsection{Straight}\n\nThis is five cards in a sequence (e.g., 4,5,6,7,8), with aces allowed to be either 1 or 13 (low or high) and with the cards allowed to be of the same suit (e.g., all hearts) or from some different suits. The number of such hands is $10 \\cdot {4 \\choose 1}^5$. The probability is 0.003940\n\n\\subsection{3 of a kind}\n\nThis hand has the pattern AAABC where A, B, and C are from distinct kinds. The number of such hands is ${13 \\choose 1}{4 \\choose 3}{12 \\choose 2}{4 \\choose 1}^2 = 54 912$. After dividing by ${52 \\choose 5}$, the probability is $0.021128$.\n\n\\subsection{2 pair}\n\nThis hand has the pattern AABBC where A, B, and C are from distinct kinds. The number of such hands is ${13 \\choose 2}{4 \\choose 2}{4 \\choose 2}{11 \\choose 1}{4 \\choose 1}$. After dividing by ${52 \\choose 5}$, the probability is $0.047539$.\n\n\\subsection{Pair}\n\n This the hand with the pattern AABCD, where A, B, C and D are from the distinct \"kinds\" of cards: aces, twos, threes, tens, jacks, queens, and kings (there are 13 kinds, and four of each kind, in the standard 52 card deck). The number of such hands is ${13 \\choose 1}\\cdot{4 \\choose 2}\\cdot{12 \\choose 3}\\cdot {4 \\choose 1}^3$. If all hands are equally likely, the probability of a single pair is obtained by dividing by ${52 \\choose 5}$. This probability is 0.422569.\n\n\\subsection{High card}\n\nWe have to choose 5 distinct kinds ${13 \\choose 5}$ but exclude any straights (subtract 10). We can have any pattern of suits except the 4 patterns where all 5 cards have the same suit: $4^5-4$. The total number of such hands is $[{13 \\choose 5}-10] \\cdot (4^5-4)$. The probability is $0.501177$.\n\n\\section{Whiteboard solution}\n\n\\[ \\Omega = \\set{\\omega \\subseteq \\set{1, \\dots, 52}\\,|\\, |\\omega| = 5} \\]\n\n\\begin{description}\n  \\item[Straight]\n    \\[ \\mathbb P(\\text{straight}) = \\frac{10 \\cdot 4^5}{{52 \\choose 5}} - \\frac{36}{{52 \\choose 5}} - \\frac{4}{{52 \\choose 5}} = \\frac{10200}{{52 \\choose 5}} = 0.003925 \\]\n  \\item[3 with same rank] $13$ different ranks.\n    \\[ {4 \\choose 3} \\text{ for color combinations} \\]\n    \\[ {12 \\choose 2} \\text{ possibilities for remainder} \\]\n    \\[ 4^2 \\text{ color combinations} \\]\n    \\[ \\mathbb P(\\text{3 of a kind}) = \\frac{13 {4 \\choose 3} {12 \\choose 2} 4^2}{{52 \\choose 5}} - \\frac{54912}{{52 \\choose 5}} \\]\n  \\item[2-pair] $2\\times 2$ cards of same rank\n    \\[ \\mathbb P(\\text{2-pair}) = \\frac{{13 \\choose 2} {4 \\choose 2} {4 \\choose 2} {11 \\choose 1} \\cdot 4}{{52 \\choose 5}} \\]\n  \\item[pair]\n    13 for the rank, ${4 \\choose 2}$ for colors ensures that we avoid duplicates\n    \\[ \\mathbb P(\\text{pair}) = \\frac{13 {4 \\choose 2} {12 \\choose 3} 4^3}{|\\Omega|} \\]\n  \\item[high card]\n    We can simply compute $1 - \\text{(what we had so far)}$, but we will be exhaustive here:\n\n    Possibilities for $5$ cards: ${13 \\choose 5}$ \\\\\n    -10 straights: $[{13 \\choose 5} - 10]$ \\\\\n    $4^5$ color combinations \\\\\n    $-4$: $[4^5 - 4]$\n\n    \\[ \\mathbb P(\\text{high card}) = \\frac{[{13 \\choose 5} - 10] [4^5 - 4]}{{52 \\choose 5}} \\]\n\\end{description}\n\n\\end{document}", "meta": {"hexsha": "e0744e9786325ea196e4f771366c7a4f46485cd1", "size": 3258, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability_theory_practicals/ex9/solution.tex", "max_stars_repo_name": "prokls/math-lecture-notes", "max_stars_repo_head_hexsha": "d1a94e128d13ce4399a9cc55323b2f8e0d9494fd", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2015-11-25T01:49:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T14:47:36.000Z", "max_issues_repo_path": "probability_theory_practicals/ex9/solution.tex", "max_issues_repo_name": "prokls/math-lecture-notes", "max_issues_repo_head_hexsha": "d1a94e128d13ce4399a9cc55323b2f8e0d9494fd", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-05-22T07:56:03.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-02T09:32:40.000Z", "max_forks_repo_path": "probability_theory_practicals/ex9/solution.tex", "max_forks_repo_name": "prokls/math-lecture-notes", "max_forks_repo_head_hexsha": "d1a94e128d13ce4399a9cc55323b2f8e0d9494fd", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-03-24T14:42:30.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-25T11:00:11.000Z", "avg_line_length": 56.1724137931, "max_line_length": 469, "alphanum_fraction": 0.6559238797, "num_tokens": 1148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.8887587949656841, "lm_q1q2_score": 0.8086878629024531}}
{"text": "\\chapter{Pseudo Random Number Generation}\n\\section{Producing binomial random variables}\n\nThe exercise is about different methods to produce pseudo random numbers with different distributions. One can do it in several ways to get pseudo random numbers. Most of methods use uniform distributed variables in some way or other. We don't consider the process of simulating uniformly distributed variables here. There are different methods, like Whichmann-Hill or the LCG, that are provided by R. \n\n\\noindent\nOne easy way to get random simulations of a specific distribution is by using uniformly distributed variables and the quantile transformation of the desired distribution. In the first part of the exercise we simulate binomial random variables using this idea. The second part is about the accept-reject method to simulate standard normal random variables.\n\nThe inversion method is based on the generalised inverse of the distribution function (cdf) $F$ which is considered to be defined on $\\RR$ here and its inverse defined on $t \\in (0, 1)$ as\n$$F^{-1}(t) = inf\\{x \\in \\RR | F(x) \\geq t\\}.$$\nThis, requires that the cdf is in this way analytical invertible. Additionally, if $U \\sim unif[0, 1]$ holds, then $F^{-1}(U) \\sim F$, i.e., it is possible to generate $F$-distributed variables using uniform variables.\n\nIn this exercise we were asked to simulate binomial random variables with parameters $n = 10$ and $p = 0.4.$ The inverse is easily computed as a sum of indicator functions over the intervals $[0,B(n,p)(\\{k\\})]$ for $k = 0, \\dots 10.$ So we produced $1000$ binomials using the inverse of simulated uniforms. Another way to get binomial distributed variables is the summation of independent Bernoulli random variables with success\nprobability $p.$ Those can also be simulated using the inverse method with $F^{-1}(t) = \\one_{[0,p)}(t).$ Therefore we used in another trial $10000$ uniform distributed variables that we inverted to Bernoulli variables and added up in the end. Finally we compared those\ntwo approaches with the provided method \\texttt{rbinom} which is based on a special accept-\nreject-method. In the visualisation we can see very clear that all approaches lead to\na similar distribution (see Figure \\ref{fig:emp_all}). Although the binomial distribution is discrete, I have added a smooth density estimate to compare the overall shape of the distributions.\n\n\\begin{figure}[th]\n\\centering\n\\includegraphics[scale = 0.7]{ex2/emp_all.png}\n\\caption{Empirical distribution of simulated binomial variables ($n=10, p=0.4$). Method 1: inverse method with the binomial quantile function; \\\\\nMethod 2: Summation of Bernoulli variables (simulated with uniform variables and inverse method);\\\\\nMethod 3: simulated with \\texttt{rbinom}.}\n\\label{fig:emp_all}\n\\end{figure}  \n\nSo we see that the first two method, i.e. those using inverse method just differ in a slightly more centred distribution for method $1$. The blue bins show a small shift of the distribution to the right most dominant at $5.$\n\nDrawing a histogram of three groups into one plot is sometimes problematic because the bins are drawn shifted in a graphical way. This shift may suggest a shift in distribution that is not existent in the data. Therefore I have added another graphic (Figure \\ref{fig:emp_all_col}) where I put the three histograms beneath each other. As the three distributions are very close, in general differences are hard to see, but one sees that method $1$ generates a more centred distribution and that the first row shows a slightly more right skewed distribution, as one would expect from a binomial with $p=0.4$. All in all the differences seem somehow negligible and we can assume that every method produced reasonable simulations.\n\n\\begin{figure}[thbp]\n\\centering\n\\includegraphics[scale = 0.8, keepaspectratio]{ex2/emp_all_col.png}\n\\caption{Histograms of simulated binomial variables with the three methods.}\n\\label{fig:emp_all_col}\n\\end{figure}\n\n\\newpage\n\\section{Accept-reject method for normal distribution}\n\nThe next task is to produce standard normal random variables with the accept-reject method. Therefore one has to be able to simulate variables from another distribution with known density. Here we use the standard Cauchy distribution with the density $g(x)=[\\pi (1+x^2)]^{-1}$.\\\\\n\nThe general approach for generating variables with a density function $f$ by variables with a distribution given by a density $g$ demands a constant $c\\geq 1$, s.t. $f(x)\\leq cg(x)$ for all $x$ and is given by following algorithm:\n\\begin{enumerate}\n\\item generate random variable $X$ from density $g$\n\\item generate uniformly distributed $U\\sim unif[0,1]$ (independent from $X$)\n\\item Accept $X$ as drawn from $f$, if $Ucg(X)\\leq f(X)$, else reject.\n\\end{enumerate} \n\nThe resulting variables $X$ are then distributed with density $f$. In this exercise we produce the variables $X$ with the inversion method. The cdf of the standard Cauchy distribution is given by $$G(x)= (\\arctan (x) - 0.5)/\\pi$$ and therefore we get the inverse $$G^{-1}(t)=\\tan \\{\\pi (y-0.5)\\}.$$\n\nTo determine the best $c$ for the rejection procedure, we search for the smallest possible constant - as we don't want to reject unnecessary many $X$ so we have to draw less candidates and thus keep the algorithm fast - such that $c\\geq \\frac{f}{g}(x)$ for all $x$, i.e. $$c:= \\sup_{x\\in \\mathbb{R}} \\frac{f(x)}{g(x)}= \\sup_{x\\in \\mathbb{R}} \\frac{1}{\\sqrt{2\\pi}}\\exp\\{-x^2/2\\} \\pi (1+x^2).$$ By differentiation we get three local extrema and the maxima at $x\\in \\{-1,1\\}$ resulting in $c=\\sqrt{2\\pi}e^{-1/2}$.\n\nWe simulated $10,000$ standard normals using this method after setting the random number generator back to default, i.e. using Mersenne-Twister. The result is shown in Figure \\ref{2normhist}. There we can see a very good fit of the data.\n\\begin{figure}[!th]\n\\centering\n\\includegraphics[width=0.8\\textwidth, keepaspectratio]{ex2/normal_hist.png}\n\\caption{Histogram of simulated standard normals. The orange line shows the density of a standard normal variable}\n\\label{2normhist}\n\\end{figure}\n\nAdditionally one can examine the normality of a sample for example with QQ- and PP- plots. The QQ-plot for the sample is shown in Figure \\ref{2normqq}. The points lie pretty much on the reference line. Just the few highest quantiles differ. Since on the tails are just a few data points this may happen by accident. I omit other plots since a very good fit of the data is already obvious in the histogram and the QQ- plot. \n\\begin{figure}[bh]\n\\centering\n\\includegraphics[width=0.45\\textwidth, keepaspectratio]{ex2/normal_qq.png}\n\\caption{QQ-plot of a simulated sample of standard normals.}\n\\label{2normqq}\n\\end{figure}\n\nBecause in this method we reject some samples of the distribution $g$, it is interesting to consider the acceptance probability. The theoretical overall acceptance probability should be $1/c =0.658$. In this simulation we used 15 168 Cauchy samples resulting giving a similar empirical acceptance probability of $0.659$. One can also look in more detail and visualise more local acceptance probabilities. The probability that the uniform variable drawn in the second step of the algorithm accepts the sample $X$ as drawn from $f$ is $$P(U\\leq \\frac{f(X)}{cg(X)})=\\frac{f(X)}{cg(X)}$$ and can be seen as a function in $X$. I estimated the local empirical acceptance probabilities by binning the data with the \\texttt{hist} function in R (see Figure \\ref{2normacc}). Since the Cauchy distribution has very heavy tails compared to the standard normal, there are of course very high and low values in the Cauchy sample. I restricted the data for the visualisation to the area, where the empirical acceptance probability is positive (and not 0), i.e. where we have indeed data in the final normal sample. As expected we see in the plot that the empirical probabilities fluctuate around the theoretical ones over the whole range of values.\n\\begin{figure}[hbt]\n\\includegraphics[width=0.7\\linewidth, keepaspectratio]{ex2/acc_probs.png}\n\\centering\n\\caption{Theoretical and empirical acceptance probabilities of the normal sample generated with the accept-reject method.}\n\\label{2normacc}\n\\end{figure}\n\nThe last task of the exercise is to check, whether it is possible to simulate Cauchy distributed samples from a standard normal one. As mentioned the Cauchy distribution hat heavy tails compared to the normal. This can be also seen in the quotient of densities. $$\\frac{g(x)}{f(x)}=\\sqrt{2\\pi}exp\\{x^2/2\\}[\\pi (1+x^2)]^{-1}$$ This is obviously unbounded as $x$ tends to infinity, i.e. we can't find a suitable constant $c$ for the algorithm. This can also be seen in Figure \\ref{2normacc}. As the limit of the function is 0 the inverse has to go to infinity.    ", "meta": {"hexsha": "6464135b0ea243c33001e6828e095915aaa0a6ae", "size": 8751, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ex2/ex2.tex", "max_stars_repo_name": "dnanad/Advanced-Statistical-Data-Analysis", "max_stars_repo_head_hexsha": "09114b8840466cc3637bd447ff9adf584c811cde", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ex2/ex2.tex", "max_issues_repo_name": "dnanad/Advanced-Statistical-Data-Analysis", "max_issues_repo_head_hexsha": "09114b8840466cc3637bd447ff9adf584c811cde", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex2/ex2.tex", "max_forks_repo_name": "dnanad/Advanced-Statistical-Data-Analysis", "max_forks_repo_head_hexsha": "09114b8840466cc3637bd447ff9adf584c811cde", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 110.7721518987, "max_line_length": 1233, "alphanum_fraction": 0.7696263284, "num_tokens": 2199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.9343951556900273, "lm_q1q2_score": 0.8084611978409247}}
{"text": "\n\\subsection{Estimator error and bias}\n\n\\subsubsection{Error of an estimator}\n\nThe error of an estimator is the difference between it and the actual parameter.\n\n\\(Error_{\\theta }[\\hat \\theta ]=\\hat \\theta - \\theta \\)\n\n\\subsubsection{Bias of an estimator}\n\nThe bias of an estimator is the expected error.\n\n\\(Bias_\\theta [\\hat \\theta ]:=E_\\theta [\\hat \\theta -\\theta ]\\)\n\n\\(Bias_\\theta [\\hat \\theta ]:=E_\\theta [\\hat \\theta] -\\theta\\)\n\n\n", "meta": {"hexsha": "4eeb2498bef7b5fa03aa13bb427a60683e0d2b44", "size": 435, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/generative/02-01-bias.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/generative/02-01-bias.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/generative/02-01-bias.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.8947368421, "max_line_length": 80, "alphanum_fraction": 0.6988505747, "num_tokens": 119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951142217223021, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.8084434631685259}}
{"text": "\\subsubsection{The Laplacian}\r\nThe Laplacian is the higher dimension version of concavity. Let $f$ be a scalar function, We say that $\\nabla^2 f = \\nabla \\cdot (\\nabla f) = \\text{div} (\\text{grad}(f))$. Written out more fully,\r\n\\begin{equation*}\r\n\t\\nabla^2 f = f_{xx} + f_{yy} + \\ldots\r\n\\end{equation*}", "meta": {"hexsha": "fad7c0832f33af1b345b83d62879b635c72e2334", "size": 302, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/laplacian.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorAnalysis/laplacian.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorAnalysis/laplacian.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 60.4, "max_line_length": 196, "alphanum_fraction": 0.6821192053, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172688214138, "lm_q2_score": 0.8519528094861981, "lm_q1q2_score": 0.8084327331423734}}
{"text": "\\chapter{Sentential Logic}\n\n\\section{Grammar}\n\\label{sec:Gramma}\n\n\\subsection{Symbols}\n\\label{sub:Symbols}\n\\begin{itemize}\n    \\item Logical Symbols\n    \\begin{itemize}\n        \\item Sentential Connectives\n        \\begin{itemize}\n            \\item $\\neg$\n            \\item $\\wedge$\n            \\item $\\vee$\n            \\item $\\rightarrow$\n            \\item $\\leftrightarrow$\n        \\end{itemize}\n        \\item Parentheses\n    \\end{itemize}\n    \\item Non-logical Symbols: An enumerable set of elements\n\\end{itemize}\n\n\\subsection{Expressions}\n\\label{sub:Expressions}\n\n\\begin{definition}[Expression]\n    \\label{def:Expression}\n    An expression is a finite sequence of symbols.\n\\end{definition}\n\\begin{remark}\n    The set of all expressions is enumerable.\n\\end{remark}\n\nWe often use Greek alphabets $\\alpha,\\beta,\\dots$ to represent expressions.\n\n\\subsection{Well-Formed Formulas}\n\\label{sub:WellFormedFormulas}\n\n\\begin{definition}[Well-Formed Formula]\n    \\label{def:WFF}\n    A \\textbf{well-formed formula} (or formula or wff) is an expression built up from sentence symbols by applying some finite times of \\emph{formula building operations}\n\\end{definition}\n\n\\begin{definition}[Formula Building Operations]~{}\n    \\begin{itemize}\n        \\item $\\xi_{\\neg}(\\alpha) = (\\neg\\alpha)$\n        \\item $\\xi_{\\wedge}(\\alpha,\\beta) = (\\alpha \\wedge \\beta)$\n        \\item $\\xi_{\\vee}(\\alpha,\\beta) = (\\alpha\\vee\\beta)$\n        \\item $\\xi_{\\rightarrow}(\\alpha,\\beta) = (\\alpha\\rightarrow\\beta)$\n        \\item $\\xi_{\\leftrightarrow}(\\alpha,\\beta) = (\\alpha\\leftrightarrow\\beta)$\n    \\end{itemize}\n\\end{definition}\n\\begin{remark}\n    Do NOT omit the parentheses.\n\\end{remark}\n\n\\begin{definition}[Well-Formed Sequences of Expressions]\n    \\label{def:WellFormedSeqOfExpr}\n    A \\textbf{well-formed sequence of expressions} is a finite sequence $\\alpha_1,\\alpha_2,\\dots,\\alpha_n$ of expressions such that each $\\alpha_i$ is either\n    \\begin{itemize}\n        \\item A sentence symbol\n        \\item $(\\neg\\alpha_j)$ for some $j < i$\n        \\item $(\\alpha_j \\wedge \\beta_k)$ for some $j,k<i$\n        \\item $(\\alpha_j \\vee \\beta_k)$ for some $j,k<i$\n        \\item $(\\alpha_j \\leftarrow \\beta_k)$ for some $j,k<i$\n        \\item $(\\alpha_j \\leftrightarrow \\beta_k)$ for some $j,k<i$\n    \\end{itemize}\n\\end{definition}\n\n\\begin{proposition}\n    An expression $\\alpha$ is a well-formed formula iff there is a well-formed sequence $(\\alpha_1,\\dots,\\alpha_n)$ s.t. $\\alpha = \\alpha_n$\n\\end{proposition}\n\n\\subsection{The Induction Principle}\n\\label{sub:Induction}\n\nWell-formed formulas are a form of inductive definitions with\n\\begin{itemize}\n    \\item Basic building blocks\n    \\item Closing operations\n\\end{itemize}\n\n\\begin{theorem}[The Induction Principle]\n    \\label{thm:InductionPrinciple}\n    Let $S$ be a set of wffs ($S \\subseteq W$), if\n    \\begin{enumerate}\n        \\item Every sentence symbol is in $S$\n        \\item For each wff $\\alpha$ and $\\beta$, if $\\alpha$ and $\\beta$ are in $S$ then each of the following are in $S$\n        \\begin{itemize}\n            \\item $(\\neg \\alpha)$\n            \\item $(\\alpha \\wedge \\beta)$\n            \\item $(\\alpha \\vee \\beta)$\n            \\item $(\\alpha \\rightarrow \\beta)$\n            \\item $(\\alpha \\leftrightarrow \\beta)$\n        \\end{itemize}\n    \\end{enumerate}\n    Then $S$ is the set of \\emph{all wffs} ($S = W$).\n\\end{theorem}\n\nWe can see an example of Indunction.\n\n\\begin{proposition}\n    Every wff has the same number of left parentheses as right parenthesis\n\\end{proposition}\n\\begin{proof}\n    Let $S\\triangleq \\{\\alpha|\\alpha\\text{has equal number of left and right parentheses}\\}$.\n    \\begin{itemize}\n        \\item[Base] $\\alpha = A$. Straightforward. Sentense symbols do not have parenthesis\n        \\item[Step]\n        \\begin{enumerate}\n            \\item Let $\\beta \\in S$, $\\alpha = (\\neg \\beta) \\in S$.\n            \\item Let $\\alpha_1, \\alpha_2 \\in S$, $\\alpha = (\\alpha_1 \\wedge \\alpha_2) \\in S$.\n            \\item $\\cdots$\n        \\end{enumerate} \n    \\end{itemize}\n\\end{proof}\n\n\\subsection{Parsing Formulas}\n\\label{sub:ParsingFormulas}\n\nThe induction principle actually gives an algorithm for parsing formulas.\n\nOn input expression $\\alpha$\n\n\\begin{enumerate}\n    \\item If is leaf node, we are done. Return.\n    \\item The first symbol must be `('.\n    \\item If the second symbol is `$\\neg$', then expect an non-empty expression $\\beta$ and parse $\\beta$.\n    \\item If the second symbol is not `$\\neg$', then expect a non-empty expression $\\beta_1$, an operator and another expression $\\beta_2$.\n\\end{enumerate}\n\n\\subsection{Abbreviations}\n\\label{sub:Abbreviations}\n\n\\begin{itemize}\n    \\item The outermost parentheses can be omitted.\n    \\item $\\neg$ appplies to as little as possible, with the highest precedence.\n    \\item $\\wedge$ and $\\vee$ apply to as little as possible, subject to $\\neg$.\n    \\item $\\rightarrow$ and $\\leftrightarrow$ apply to as little as possible, subject to other operators.\n    \\item When handling operators with the same precedence, grouping is always to the right. $A \\rightarrow B \\rightarrow C= (A \\rightarrow (B\\rightarrow C))$.\n\\end{itemize}\n\n\\section{Semantics}\n\\label{sec:Semantics}\n\n\\subsection{Truth Assignments}\n\nConsider a math domain $\\{T,F\\}$ of truth values\n\n\\begin{itemize}\n    \\item T is called truth\n    \\item F is called falsity\n\\end{itemize}\n\n\\begin{definition}[Truth Assignment]\n    A truth assignment for a set $\\mathcal{S}$ of sentence symbols is a function\n    \\[ v:\\mathcal{S}\\mapsto\\{T,F\\} \\]\n\\end{definition}\n\n\\begin{definition}[Extended Truth Assignment]\n    Let $\\bar{\\mathcal{S}}$ be the set of wffs that can be built up from $\\mathcal{S}$ by formula-building operations. Let $v$ be a truth assignment for $\\mathcal{S}$. An \\textbf{extension} $\\bar{v}$ of $v$\n    \\[ \\bar{v}:\\bar{\\mathcal{S}}\\mapsto \\{T,F\\} \\]\n    assigns truth values to every wff in $\\mathcal{S}$ s.t.\n    \\begin{itemize}\n        \\item $\\bar{v}(\\alpha) = v(\\alpha)$ if $\\alpha \\in \\mathcal{S}$\n        \\item $\\bar{v}(\\neg(\\alpha))$ is T if $\\bar{v}(\\alpha)$ is F and F otherwise.\n        \\item $\\bar{v}((\\alpha\\wedge\\beta))$ is T if $\\bar{v}(\\alpha)$ is T and $\\bar{v}(\\beta)$ is T and F otherwise.\n        \\item $\\bar{v}((\\alpha\\vee\\beta))$ is T if $\\bar{v}(\\alpha)$ is T or $\\bar{v}(\\beta)$ is T and F otherwise.\n        \\item $\\bar{v}((\\alpha\\to\\beta))$ is F if $\\bar{v}(\\alpha)$ is T and $\\bar{v}(\\beta)$ is F and T otherwise.\\footnote{Emphasizes the promise of a condition implying a consequence. If the condition is falsy then no guarantee for the consequence. \\emph{\u201c\u9a97\u4f60\u662f\u5c0f\u72d7\u201d}}\n        \\item $\\bar{v}((\\alpha\\leftrightarrow\\beta))$ is T if $\\bar{v}(\\alpha) = \\bar{v}(\\beta)$ and is F otherwise.\n    \\end{itemize}\n\\end{definition}\n\n\\begin{theorem}[Determinacy of Truth Assignments]\n    \\label{thm:DeterminacyofTruthAssignments}\n    For every $v_1$ and $v_2$ and wff $\\alpha$, if\n    \\[ v_1(A) = v_2(A) \\]\n    for every sentence symbol that occurs in $\\alpha$, then\n    \\[ \\bar{v}_1(\\alpha) = \\bar{v}_2(\\alpha) \\]\n\\end{theorem}\n\n\\begin{remark}\n    To determine the value of $\\bar{v}(\\alpha)$, we only need to know the value of $v$ on the sentence symbols that occur in $\\alpha$. This leads to the method of \\textbf{truth tables}.\n\\end{remark}\n\n\\subsection{Satisfiability}\n\\label{sub:Satisfiability}\n\nWe first introduce some new notations. We use captial Greek letters, $\\Delta$, $\\Sigma$, etc. to represent sets of wffs. And we use $\\Sigma;\\alpha$ to represent $\\Sigma \\cup \\{\\alpha\\}$.\n\n\\begin{definition}~{}\n    \\begin{itemize}\n        \\item $v$ satisfies $\\alpha$ if $\\bar{v}(\\alpha) = T$\n        \\item $v$ satisfies $\\Sigma$ if $\\bar{v}(\\alpha) = T$ for every $\\alpha \\in \\Sigma$.\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Satisfiability]~{}\n    \\label{def:Satisfiability}\n    \\begin{itemize}\n        \\item $\\alpha$ is satisfiable if there exists some $v$ that satisfies $\\alpha$\n        \\item $\\Sigma$ is satisfiable if there exists some $v$ that satisfies $\\Sigma$\n    \\end{itemize}\n\\end{definition}\n\n\\begin{remark}\n    Every $v$ satisfies $\\emptyset$. Because $v$ satisfies $\\emptyset$ iff\n    \\[ \\forall \\alpha, \\alpha\\in\\emptyset \\Longrightarrow \\bar{v}(\\alpha) = T \\]\n    The assumption itself is false, and therefore the consequence is always true.\n\\end{remark}\n\n\\subsection{Semantic Implications}\n\\label{sub:SemanticImplications}\n\n\\begin{definition}\n    A set of wffs $\\Sigma$ semantically implies $\\alpha$ when every truth assignment satisfying $\\Sigma$ also satisfies $\\alpha$.\n    \\begin{itemize}\n        \\item $\\Sigma \\vDash \\alpha$ denotes that $\\Sigma$ implies $\\alpha$\n        \\item $\\alpha \\vDash \\beta$ denotes that $\\{\\alpha\\} \\vDash \\beta$\n    \\end{itemize}\n    If $\\Sigma \\vDash \\alpha$, we call $\\alpha$ a semantic consiquence of $\\Sigma$.\n\\end{definition}\n\nSemantic implication is also referred to as tautological implication.\n\n\\begin{remark}\n    Note that $\\{\\alpha,\\neg\\alpha\\} \\vDash \\beta$ also holds, because the assumption does not hold, so the consequence trivially holds.\n\\end{remark}\n\n\\subsection{Tautologies}\n\\label{sub:Tautologies}\n\n\\begin{definition}[Tautologies]\n    \\label{def:Tautology}\n    $\\alpha$ is a tautology if $\\emptyset \\vDash \\alpha$, denoted by $\\vDash \\alpha$.\n\\end{definition}\n\\begin{remark}\n    ~{}\n    \\begin{itemize}\n        \\item $\\alpha$ is a tautology iff $\\forall v$, $\\bar{v}(\\alpha)=T$.\n        \\item $\\alpha$ is a tautology iff $\\neg \\alpha$ is \\emph{not satisfiable}\n        \\item $\\alpha$ is satisfiable iff $\\neg \\alpha$ is not a tautology.\n    \\end{itemize}\n\\end{remark}\n\n\\subsection{Semantic Equivalence}\n\\label{sub:SemanticEquivalence}\n\n\\begin{definition}[Semantic Equivalence]\n    Two wffs $\\alpha$ and $\\beta$ are semantically equivalent if both $\\alpha\\vDash\\beta$ and $\\beta\\vDash\\alpha$ hold. We use $\\alpha\\vDash\\Dashv\\beta$\n\\end{definition}\n\n\\begin{proposition}\n    The following are equivalent\n    \\begin{itemize}\n        \\item $\\alpha$ and $\\beta$ are semantically equivalent\n        \\item For every $v$, $\\bar{v}(\\alpha)=\\bar{v}(\\beta)$\n        \\item $\\alpha$ and $\\beta$ have the same truth table\n    \\end{itemize}\n\\end{proposition}\n\nWe can use semantic equivalence to derive truthfulness of wffs. If $\\alpha\\vDash\\models\\beta$, we can freely exchange one for the other in deriving the truth of some formula $\\sigma$ where $\\alpha$ and/or $\\beta$ occur.\n\nRemember not to mix syntax and semantics\n\n\\begin{itemize}\n    \\item $\\alpha=T$ is incorrect. Use $\\bar{v}(\\alpha)=T$.\n    \\item $v(\\Sigma)=T$ is incorrect. Use $v$ satisfies $\\Sigma$.\n\\end{itemize}\n\n\\subsection{Properties of Satisfaction and Implication}\n\n\\begin{itemize}\n    \\item If $\\alpha$ is a tautology, then $\\Sigma\\vDash\\alpha$ for every $\\Sigma$\n    \\item If $\\alpha\\in\\Sigma$ then $\\Sigma\\vDash\\alpha$\n    \\item If $\\Sigma\\vDash\\alpha$ and $\\Sigma\\vDash\\alpha\\to\\beta$ then $\\Sigma\\vDash\\beta$\n    \\item If $\\Sigma\\vDash\\alpha$ and $\\alpha\\vDash\\beta$ then $\\Sigma\\vDash\\beta$.\n    \\item If $\\Sigma\\vDash\\alpha$ then for all $\\beta$, $\\Sigma\\vDash\\beta\\to\\alpha$\n    \\item If $\\Sigma\\vDash\\alpha$ and $\\Sigma\\vDash\\beta$ then $\\Sigma\\vDash \\alpha\\wedge\\beta$\n    \\item If $\\Sigma\\vDash\\alpha$ or $\\Sigma\\vDash\\beta$ then $\\Sigma\\vDash \\alpha\\vee\\beta$\n    \\item $\\Sigma\\nvDash\\alpha$ iff $\\Sigma\\cup\\{\\neg\\alpha\\}$ is satisfiable\n    \\item $\\Sigma \\vDash \\alpha$ iff $\\Sigma \\cup \\{\\neg \\alpha\\}$ is not satisfiable\n    \\item $\\Sigma \\vDash \\alpha \\to \\beta$ iff $\\Sigma;\\alpha \\vDash \\beta$\n    \\item If $\\Sigma$ is not satisfiable, then for every $\\alpha$, $\\Sigma\\vDash\\alpha$\n    \\item If $\\Sigma\\vDash\\alpha$ and $\\Sigma\\subseteq\\Delta$ then $\\Delta\\vDash\\alpha$\n    \\item If $\\Sigma$ is satisfiable then every subset of $\\Sigma$ is satisfiable\n    \\item If every subset of $\\Sigma$ is satisfiable then $\\Sigma$ is satisfiable.\n    \\item If every finite subset of $\\Sigma$ is satisfiable then $\\Sigma$ is satisfiable\n    \\item If $\\Sigma\\vDash\\alpha$ then there is a finite subset $\\Delta$ of $\\Sigma$ such that $\\Delta\\vDash\\alpha$\n\\end{itemize}\n\n\\section{Normal Forms}\n\\label{sec:NormalForms}\n\n\\subsection{Disjunctive Normal Forms}\n\\label{sub:DisjunctiveNormalForms}\n\n\\begin{definition}[Disjunctive Normal Form]\n    \\label{def:DisjunctiveNormalForm}\n    The wff $\\alpha$ is in \\textbf{disjunctive normal form} if $\\alpha=\\gamma_1\\vee\\gamma_2\\vee\\cdots\\vee\\gamma_k$ where each $\\gamma_i$ is a conjunction\n    \\[ \\gamma_i = \\beta_{i1}\\wedge\\beta_{i2}\\wedge\\cdots\\wedge\\beta_{in_i} \\]\n    where each $\\beta_{ij}$ is either a sentence symbol or the negation of a sentence symbol\n\\end{definition}\n\n\\subsection{Conjunctive Normal Forms}\n\\label{sub:ConjunctiveNormalForms}\n\n\\begin{definition}[Conjunctive Normal Form]\n    \\label{def:ConjunctiveNormalForm}\n    The wff $\\alpha$ is in \\textbf{conjunctive normal form} if $\\alpha=\\gamma_1\\wedge\\gamma_2\\wedge\\cdots\\wedge\\gamma_k$ where each $\\gamma_i$ is a disjunction\n    \\[ \\gamma_i = \\beta_{i1}\\vee\\beta_{i2}\\vee\\cdots\\vee\\beta_{in_i} \\]\n    where each $\\beta_{ij}$ is either a sentence symbol or the negation of a sentence symbol\n\\end{definition}\n\n\\subsection{Completeness of Normal Forms}\n\n\\begin{theorem}[Completeness of DNFs]\n    \\label{thm:CompletenessOfDNF}\n    Every wff is semantically equivalent to a wff in disjunctive normal form\n\\end{theorem}\n\\begin{proof}\n    \\begin{enumerate}\n        \\item Construct the disjunctive normal form truth tables\n        \\item Select all assignments $v$ s.t. $\\bar{v}(\\alpha)=T$\n        \\item Construct $\\gamma_i$ where $\\beta_{ij} = A_j$ if $A_j$ is assigned $T$ and $\\beta_{ij} = \\neg A_j$ otherwise\n    \\end{enumerate}\n\\end{proof}\n\n\\begin{theorem}[Completeness of CNFs]\n    \\label{thm:CompletenessOfCNF}\n    Every wff is semantically equivalent to a wff in conjunctive normal form\n\\end{theorem}\n\\begin{proof}\n    Given $\\alpha=\\gamma_1\\vee\\cdots\\vee\\gamma_n$ in DNF. If every $\\gamma_i$ is a sentence symbol or the negation of a sentence symbol, we are done. Otherwise, there is some $\\gamma_i = \\beta_{i1}\\wedge\\beta_{i2}$. Then\n    \\[ \\alpha \\equiv (\\beta_{i1} \\wedge \\beta_{i2}) \\vee \\alpha' \\equiv (\\beta_{i1}\\vee\\alpha') \\wedge (\\beta_{i2}\\vee\\alpha') \\]\n    where $\\alpha'$ is the disjunction of $\\{\\gamma_k|k \\neq i\\}$\n\n    And we recursively repeat the steps\n\\end{proof}\n\n\\section{Finite Satisfiability}\n\\label{sec:FiniteSatisfiability}\n\n\\begin{definition}[Finite Satisfiability]\n    \\label{def:FiniteSatisfiability}\n    $\\Sigma$ is \\textbf{finitely satisfiable} if every finite subset of $\\Sigma$ is satisfiable.\n\\end{definition}\n\\begin{remark}\n    Suppose $\\Delta$ is finitely satisfiable, and for every $\\alpha$, $\\alpha\\in\\Delta$ or $\\neg\\alpha\\in\\Delta$\n\n    Then $\\alpha\\in\\Delta$ iff $\\neg\\alpha\\notin\\Delta$\n\\end{remark}\n\n\n\\subsection{Compactness Theorem}\n\n\\begin{theorem}[Compactness Theorem]\n    \\label{thm:CompactnessTheorem}\n    If $\\Sigma$ is finitely satisfiable, then $\\Sigma$ is satisfiable\n\\end{theorem}\n\\begin{sketchproof}\n    We break down the proof into the following steps\n    \\begin{enumerate}\n        \\item From $\\Sigma$, construct its superset $\\Delta$ s.t.\n        \\begin{enumerate}\n            \\item $\\Delta$ is finitely satisfiable\n            \\item For every wff $\\alpha$, $\\alpha\\in\\Delta$ or $\\neg\\alpha\\in\\Delta$\n        \\end{enumerate}\n        \\item Show that $\\Delta$ is satisfiable, so that $\\Sigma$ is also satisfiable\n    \\end{enumerate}\n\\end{sketchproof}\n\n\\begin{lemma}\n    \\label{lem:CompactnessLemma1}\n    If $\\Delta$ is finitely satisfiable, then for every wff $\\alpha$,\n    \\begin{itemize}\n        \\item either $\\Delta\\cup\\{\\alpha\\}$ is finitely satisfiable\n        \\item or $\\Delta\\cup\\{\\neg\\alpha\\}$ is finitely satisfiable\n    \\end{itemize}\n\\end{lemma}\n\\begin{proof}\n    Prove by contradiction. Suppose neither $\\Delta\\cup\\{\\alpha\\}$ nor $\\Delta\\cup\\{\\neg\\alpha\\}$ is finitely satisfiable. Then there are some finite subsets $\\Delta_1 \\subseteq \\Delta\\cup\\{\\alpha\\}$ and $\\Delta_2\\subseteq\\Delta\\cup\\{\\neg\\alpha\\}$ which are not satisfiable. Notice that $\\alpha$ must be in $\\Delta_1$ and $\\Delta_2$, or otherwise $\\Delta_1$ and $\\Delta_2$ would be satisfiable by finite satisfiability of $\\Delta$. Therefore $\\Delta_1 = \\Delta'_1\\cup\\{\\alpha\\}$ and $\\Delta_2'\\cup\\{\\neg\\alpha\\}$.\n\n    Then we construct $\\Delta' = \\Delta_1\\cup\\Delta_2 = \\Delta_1'\\cup\\Delta_2'\\cup\\{\\alpha,\\neg\\alpha\\}$. Then there exists an assignment $v$ such that $v$ satisfies $\\Delta_1'\\cup\\Delta_2'$, and that $v$ satisfies either $\\alpha$ or $\\neg\\alpha$. Suppose $\\bar{v}(\\alpha)=T$, then $\\Delta_1$ is satisfiable, which causes contradiction. Conversely, if $\\bar{v}(\\alpha) = F$ then $\\bar{v}(\\neg\\alpha)=T$, then $\\Delta_2$ is satisfiable, which is also a contradiction.\n\\end{proof}\n\\begin{remark}\n    This lemma implies that we can expand $\\Sigma$ for one step, by including $\\alpha$ or $\\neg\\alpha$\n\\end{remark}\n\n\n\\begin{lemma}\n    \\label{lem:CompactnessLemma2}\n    If $\\Sigma$ is finitely satisfiable, then there is a $\\Delta \\supseteq \\Sigma$ such that\n    \\begin{itemize}\n        \\item $\\Delta$ is finitely satisfiable\n        \\item For each wff $\\alpha$, $\\alpha\\in\\Delta$ or $\\neg\\alpha\\in\\Delta$\n    \\end{itemize}\n\\end{lemma}\n\\begin{proof}\n    The set of all wffs is enumerable, so we can write all wffs in a sequence\n    \\[ \\alpha_1, \\alpha_2,\\dots,\\alpha_n,\\dots \\]\n    Then we can scan through the sequence and check if $\\alpha_i$ can be added to $\\Sigma$. Starting from $\\Delta_0 = \\Sigma$,\n    \\[\\Delta_{i+1}\\begin{cases}\n        \\Delta_i \\cup \\{\\alpha_i\\} &\\quad\\text{if it is finitely satisfiable}\\\\\n        \\Delta_i \\cup \\{\\neg \\alpha_i\\} &\\quad \\text{otherwise}\n    \\end{cases}\\]\n\n    It can be proved by induction and Lemma~\\ref{lem:CompactnessLemma1} that $\\forall i,\\Delta_i$ is finitely satisfiable.\n\n    And $\\Delta$ can be constructed by the union of all $\\Delta_i$'s\n\n    \\[ \\Delta = \\bigcup_{i\\in\\mathbb{N}} \\Delta_i \\]\n\n    $\\Delta$ is finitely satisifiable because for each $\\Delta'\\subseteq\\Delta$, $\\Delta'\\subseteq\\Delta_i$ for some $\\Delta_i$. Since $\\Delta_i$ is finitely sat, $\\Delta'$ is also satisfiable, and therefore $\\Delta$ is finitely sat.\n\n    For each wff $\\alpha$, either $\\alpha\\in\\Delta$ or $\\neg\\alpha\\in\\Delta$. Because $\\alpha$ must exist as $\\alpha_i$ in the sequence of all wffs, then either $\\alpha_i\\in\\Delta_{i+1}$ or $\\neg\\alpha_i\\in\\Delta_{i+1}$.\n\\end{proof}\n\n\\begin{lemma}\n    \\label{lem:CompactnessLemma3}\n    Let $\\Delta$ be a set of wffs such that\n    \\begin{itemize}\n        \\item $\\Delta$ is finitely satisifiable\n        \\item For every wff $\\alpha$, $\\alpha\\in\\Delta$ or $\\neg\\alpha\\in\\Delta$\n    \\end{itemize}\n    Then $\\Delta$ is satisfiable\n\\end{lemma}\n\\begin{proof}\n    Consider the sentence symbols. All sentence symbols (or their negations) must be in $\\Delta$ because they are also wffs. Therefore if there is an assignment $v$ that satisfies $\\Delta$, its values is already determined by the sentence symbols in $\\Delta$.\n\n    \\[v(A)=\\begin{cases}\n        T &\\quad A\\in\\Delta\\\\\n        F &\\quad \\neg A\\in\\Delta\n    \\end{cases}\\]\n\n    Then proving Lemma~\\ref{lem:CompactnessLemma3} is equivalent to proving\n    \\[ \\forall \\alpha, \\alpha\\in\\Delta\\Leftrightarrow\\bar{v}(\\alpha) = T \\]\n    This can be proved by induction\n    \\begin{itemize}\n        \\item[base] Consider $\\alpha=A$. Obviously it holds.\n        \\item[induction] \\begin{enumerate}[(a)]\n            \\item $\\alpha=\\neg\\beta$. The hypothesis is $\\beta\\in\\Delta \\Leftrightarrow \\bar{v}(\\beta)=T$. If $\\neg\\beta\\in\\Delta$, then $\\beta$ cannot be in $\\Delta$ due to the finite satisfiability of $\\Delta$, and therefore $\\bar{v}(\\beta) = F$, and therefore $\\bar{v}(\\neg\\beta) = T$. Conversely, If $\\bar{v}(\\neg\\beta) = T$, then $\\bar{v}(\\beta) =F$, and therefore $\\beta\\notin\\Delta$ and thus $\\neg\\beta$ must be in $\\Delta$.\n        \\end{enumerate}\n    \\end{itemize}\n\\end{proof}\n\n\\begin{corollary}\n    \\label{coroll:CorollaryOfTheCompactnessTheorem}\n    If $\\Sigma\\vDash\\tau$, then there is a finite subset $\\Delta$ of $\\Sigma$ such that $\\Delta\\vDash\\tau$\n\\end{corollary}\n\\begin{proof}\n    Assume for every subset $\\Delta$ of $\\Sigma$, $\\Delta \\nvDash \\tau$. Then $\\Delta;\\tau$ is satisfiable. So $\\Sigma;\\tau$ is finitely satisfiable, and by compactness theorem we have $\\Sigma;\\tau$ is satisfiable, which implies $\\Sigma\\nvDash\\tau$, and this leads to a contradiction.\n\\end{proof}\n\n\\subsection{Decidability Results for Semantic Implications}\n\n\\begin{theorem}\n    Given any finite set $\\Sigma$ of wffs and any wff $\\alpha$, there is an algorithm for deciding whether or not $\\Sigma\\vDash\\alpha$.\n\\end{theorem}\n\\begin{enumerate}\n    \\item Collect all sentence symbols in $\\Sigma$ and $\\alpha$\n    \\item Use truth table\n\\end{enumerate}\n\n\\begin{corollary}\n    Given a finite set of wffs $\\Sigma$, the set of its semantic consequences is effectively decidable. In particular, the set of tautologies is effectively decidable.\n\\end{corollary}\n\n\\subsection{Enumerability Results for Semantic Implications}\n\n\\begin{theorem}\n    If $\\Sigma$ is an effectively enumerable set of wffs, then the set of semantic consequences of $\\Sigma$ is effectively enumerable.\n\\end{theorem}\n\\begin{proof}\n    Let $\\beta_1,\\dots,\\beta_n,\\dots$ be an effective enumeration of $\\Sigma$. Let $\\Delta_n=\\beta_1,\\dots,\\beta_n$. Let $\\alpha_1,\\dots,\\alpha_m,\\dots$ be an effective enumeration of all wffs. We construct a table $T$ where $T_{ij} = \\Delta_i \\vDash \\alpha_j$. Due to Corollary~\\ref{coroll:CorollaryOfTheCompactnessTheorem}, if some $T_{ij}$ holds, then $\\alpha_j$ is a semantic consequence of $\\Sigma$.\n\\end{proof}", "meta": {"hexsha": "2cfc15b92cbf0cd1c610350a1950afc3d2ce33fc", "size": 21480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Logic/SententialLogic.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Mathematical Logic/SententialLogic.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mathematical Logic/SententialLogic.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 45.0314465409, "max_line_length": 513, "alphanum_fraction": 0.6810055866, "num_tokens": 6454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356994, "lm_q2_score": 0.8872046041554922, "lm_q1q2_score": 0.8084028382153209}}
{"text": "\\subsection{Comparing functions}\n\\textit{CLRS section 3.1 page 51}\nFor the following, assume that $ f(n) $ and $ g(n) $ are asymptotically positive.\n\\subsubsection{Transitivity}\n\\begin{alignat*}{11}\n\t&f(n) &&= \\Theta(g(n)) &\\quad\\text{and}\\quad g(n) &&= \\Theta(h(n)) &\\quad\\text{imply}\\quad f(n) &&= \\Theta(h(n))\\\\\n\t&f(n) &&= O(g(n)) \t&\\quad\\text{and}\\quad g(n) &&= O(h(n)) &\\quad\\text{imply}\\quad f(n) &&= O(h(n))\\\\\n\t&f(n) &&= \\Omega(g(n)) \t&\\quad\\text{and}\\quad g(n) &&= \\Omega(h(n)) &\\quad\\text{imply}\\quad f(n) &&= \\Omega(h(n))\\\\\n\t&f(n) &&= o(g(n)) \t&\\quad\\text{and}\\quad g(n) &&= o(h(n)) &\\quad\\text{imply}\\quad f(n) &&= o(h(n))\\\\\n\t&f(n) &&= \\omega(g(n)) \t&\\quad\\text{and}\\quad g(n) &&= \\omega(h(n)) &\\quad\\text{imply}\\quad f(n) &&= \\omega(h(n))\n\\end{alignat*}\n\n\\subsubsection{Reflexivity}\n\\begin{align*}\n\tf(n) &= \\Theta(f(n))\\\\\n\tf(n) &= O(f(n))\\\\\n\tf(n) &= \\Omega(f(n))\n\\end{align*}\n\n\\subsubsection{Symmetry}\n$$ f(n)=\\Theta(g(n)) \\text{ if and only if } g(n)=\\Theta(f(n)) $$ \n\n\\subsubsection{Transpose symmetry}\n\\begin{alignat*}{3}\n\t&f(n) &&= O(g(n)) \\quad\\text{if and only if}\\quad  g(n) &&= \\Omega(f(n))\\\\\n\t&f(n) &&= o(g(n)) \\quad\\text{if and only if}\\quad  g(n) &&= \\omega(f(n))\n\\end{alignat*}\n\n\\subsection{The engineering way}\nIgnore its leading constants: $ T(n)=1000n^5 = \\Theta(n^5) $.\\\\\nDrop its low order terms: $ T(n)=n^5+n^3+\\lg n = \\Theta(n^5) $\\\\\n\\textbf{Identifying lower order terms}\n\\[\n\\begin{array}{ccccccc}\n\t\\text{Constant} &<& \\text{Poly-logarithm} &<& \\text{Polynomial} &<& \\text{Exponential}\\\\\n\tc &<& \\lg^kn &<& n^a &<& b^n\n\\end{array}\n\\]", "meta": {"hexsha": "b4d96728becdbda844d17f162345b7581fcc41ce", "size": 1564, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms and Data Structures - Reference/asymptotic.tex", "max_stars_repo_name": "simwir/notes", "max_stars_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-02-12T22:22:23.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-12T22:22:23.000Z", "max_issues_repo_path": "Algorithms and Data Structures - Reference/asymptotic.tex", "max_issues_repo_name": "simwir/notes", "max_issues_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms and Data Structures - Reference/asymptotic.tex", "max_forks_repo_name": "simwir/notes", "max_forks_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-01-17T10:57:21.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-17T10:57:21.000Z", "avg_line_length": 41.1578947368, "max_line_length": 116, "alphanum_fraction": 0.5773657289, "num_tokens": 645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.8872045892435128, "lm_q1q2_score": 0.8084028096486433}}
{"text": "\n\\section{The \\innerproduct algorithm}\n\\Label{sec:innerproduct}\n\nThe \\innerproduct algorithm in the \\cxx Standard Library \\cite[\\S 29.8.4]{cxx-17-draft} computes\nthe \\emph{inner product}\\footnote{\n  Also referred to as \\emph{dot product}, see \\url{http://en.wikipedia.org/wiki/Dot_product}\n}\nof two ranges.\n%\nOur version of the original signature\nreads:\n\n\\begin{lstlisting}[style=acsl-block]\n\n  value_type\n  inner_product(const value_type* a, const value_type* b,\n                size_type n, value_type init);\n\\end{lstlisting} \n\nThe result of \\innerproduct equals the value\n\\begin{gather*}\n\\mathtt{init} + \\sum_{i = 0}^{\\mathtt{n}-1} \\mathtt{a}[i] \\cdot \\mathtt{b}[i]\n\\end{gather*}\nthus, \\innerproduct will return \\inl{init} for empty ranges.\n\n%\\clearpage\n\n\\subsection{The logic function \\InnerProduct}\n\nAs in the case of \\specref{accumulate} we specify \\innerproduct\nby defining in the following listing the logic function \\InnerProduct\nthat formally expresses the summation of the element-wise product of two arrays.\n\nPredicate \\logicref{ProductBounds} expresses that for $0 \\leq i < n$ the products \n%\n\\begin{align}\n\\Label{eq:innerproduct1}\n\\mathtt{a}[i] \\cdot \\mathtt{b}[i] \n\\end{align}\n%\ndo not overflow. \nPredicate \\logicref{InnerProductBounds}, on the other hand, states that for $0 \\leq i < n$\nthe following sums do not overflow.\ncc%\n\\begin{align}\n\\Label{eq:innerproduct2}\n\\mathtt{init} + \\sum_{k = 0}^{\\mathtt{i}} \\mathtt{a}[k] \\cdot \\mathtt{b}[k]\n\\end{align}\n\nOtherwise, one cannot guarantee that the result of our implementation\nof \\implref{innerproduct} equals the mathematical description of \\InnerProduct.\nFinally, Lemma \\logicref{InnerProductUnchanged} states that the result of the \\InnerProduct only\ndepends on the values of \\inl{a[0..n-1]} and \\inl{b[0..n-1]}.\n\n\\input{Listings/InnerProduct.acsl.tex}\n\n\\subsection{Formal specification of \\innerproduct}\n\nUsing the logic function \\logicref{InnerProduct}, we specify \\innerproduct as shown \nin the following listing.\nNote that we needn't require that \\inl{a} and \\inl{b} are separated.\n\n\\input{Listings/inner_product.h.tex}\n\n\\clearpage\n\n\\subsection{Implementation of \\innerproduct}\n\nThe following listing shows an implementation of \\innerproduct\nwith corresponding loop annotations.\n\n\\input{Listings/inner_product.c.tex}\n\nNote that the loop invariant \\inl{inner} claims\nthat in the $i$-th iteration step the current value of \\inl{init}\nequals the accumulated value of Equation~\\eqref{eq:innerproduct2}.\nThis depends of course on the properties \\inl{bounds} in the contract\nof \\specref{innerproduct}, which express that there is no arithmetic overflow\nwhen computing the updates of the variable \\inl{init}.\n\n\\clearpage\n\n", "meta": {"hexsha": "0e58116dd62353ad4c5767fc6a55e2f36e29f69f", "size": 2686, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/numeric/inner_product.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/numeric/inner_product.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/numeric/inner_product.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 31.9761904762, "max_line_length": 96, "alphanum_fraction": 0.7602382725, "num_tokens": 756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8976952941600964, "lm_q1q2_score": 0.8084013560419505}}
{"text": "\\section{The Discrete Logarithm problem}\nThe \\textbf{discrete logarithm} cryptosystem was proposed in the mid-1970s, and to this day there are no deterministically successful known attacks against it if the parameters are chosen carefully. It is the base of several public key cryptosystems taking advantage of its computational difficulty.\n\nIt is a public-key cryptography algorithm which can be used for encryption, integrity check and digital signatures, binding the key to an identity. It works taking advantage of the properties of mathematical operations within groups.\n\n\\textit{If $G$ is a finite group, $b$ is an element of $G$, and $y$ is an element of $G$ which is a power of $b$, then the discrete logarithm of $y$ to the base $b$ is any integer $x$ such that $b^x = y$.}\n\nApplying this statement to the finite cyclic group $\\mathbb{Z}^*_p$ of order $p - 1$, taking a primitive element $\\alpha \\in\\mathbb{Z}^*_p$ and another element $\\beta \\in \\mathbb{Z}^*_p$, the discrete logarithm problem aims to determine the integer $1 \\leq x \\leq p - 1$ such that:\n$$\\alpha^x \\equiv \\beta \\mod p \\qquad \\rightarrow \\qquad x = \\log_\\alpha\\beta \\mod p$$\n\nThe discrete logarithm cryptosystem, as previously stated, relies on the fundamental fact that raising a number $b$ to a power $x$ in a large finite field is an one-way function, i.e.\\ it is far more difficult to apply the inverse operation and finding $\\log_bx$. \n\nSince the domain is a finite group, such as $\\mathbb{Z}^*_n$, the repeated-squaring method can be used to compute $b^x$ with time polynomial in $\\log x$, but given an element $y = b^x$, finding $y$ is an open problem.\n\n\\subsection{Example}\nThis example considers a discrete logarithm in the group $\\mathbb{Z}^*_{47}$, in which $\\alpha = 5$ is a primitive element. The problem consist in finding the positive integer $x$ such that $5^x \\equiv 41 \\mod 47$.\n\nEven for small numbers, obtaining this value is not immediate. A brute-force attack, i.e.\\ systematically trying all possible values for $x$, reveals that the result is $x = 15$.\n\n$\\mathbb{Z}^*_{47}$ has order 46, which implies that its subgroups have cardinality of 23, 2 and 1. $\\alpha = 2$ is an element with 23 elements, and since 23 is prime then $\\alpha$ is primitive. Using prime cardinality is important in order to avoid potential attacks.\n\nWhen a number $a$ is not a primitive element but another generator for reasonably small $n$, computing the discrete logarithm is still doable solving a system of linear congruences.\n\n\\subsection{Generalized discrete logarithm}\nDespite prime multiplicative groups increment security, the discrete logarithm applications are not limited to them and can be defined over \\textit{any cyclic group}.\n\nGiven a finite cyclic group $G$ with an operation $\\circ$ and cardinality $n$, having a primitive element $\\alpha \\in G$ and another element $\\beta \\in G$, the generalized discrete logarithm problem is finding the integer $1 \\leq x \\leq n$ such that:\n$$\\beta = \\alpha \\circ \\alpha \\circ \\dots \\circ \\ alpha = \\alpha^x$$\n\n$x$ always exists in both cases with $p$ and $n$, since $\\alpha$ is a primitive element and can generate every other component. \n\nHowever, there are cyclic groups in which cracking discrete logarithm is not difficult, since the function is not a one-way. For instance, in $G = (\\mathbb{Z}_{11}, +)$ with primitive element $\\alpha = 2$, the term $x$ for $\\beta = 3$ can be computed with the following steps:\n\\begin{enumerate}\n\t\\item Expressing the operation as multiplication, $x \\cdot 2 \\equiv 3 \\mod 11$;\n\t\\item Inverting the primitive element $\\alpha$, resulting in $x \\equiv 2^{-1}3 \\mod 11$;\n\t\\item Computing $2^{-1} \\equiv 6 \\mod 11$;\n\t\\item Obtaining $x \\equiv 2^{-1}3 \\equiv 7 \\mod 11$.\n\\end{enumerate}\nThis procedure can be generalized to any additive group for arbitrary $n$ and $\\alpha, \\beta \\in \\mathbb{Z}_n$, making the \\textbf{generalized discrete logarithm} computationally easy over $\\mathbb{Z}_n$ since there are mathematical operations which are not in the additive group (inversion, multiplication). \n\nStrong groups in which discrete logarithm can be used in practice to encrypt data are instead $\\mathbb{Z}_p$ or the cyclic group formed by an elliptic curve.\n\n\\subsection{Computational aspects}\nDespite the discrete logarithm being a strong encryption system, it requires strict constraints to be met regarding fields, length of involved factors, as well as a relevant number of exponentiation, an operation known to be expensive.\n\nAn undesired consequence of the long operands of discrete logarithm is that computation is extremely arithmetically intensive: it is not uncommon that one public key operation is by 2-3 orders of magnitude slower than using a private key system. \n\nSince the numbers involved are large, it is more efficient to reduce to modulo multiple times during the computation, with a process called modular exponentiation which relies on the Euclidean algorithm, usually a built-in function of modern programming languages. \n\nOn modern computers, such execution procedures are common, and do not consist in a problem, yet performance can be a serious bottleneck in constrained devices with small CPUs.\n\n\\subsection{Security and NP-completeness}\nSince public key algorithms are based on number-theoretic functions, one distinguish feature of them is that they require arithmetic with very long operands and keys. An algorithm is said to have a ``security level of $n$ bits'' if the best known attack requires $2^n$ steps, since the key is $n$ bits long.\n\nDifferent security levels for discrete logarithms are:\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{c|c}\n\t\t\\textit{Bit lengths} & \\textit{Security level} \\\\\n\t\t\\hline\n\t\t1024 bit & 80 bit \\\\\n\t\t\\hline\n\t\t3072 bit & 128 bit \\\\\n\t\t\\hline\n\t\t7680 bit & 192 bit \\\\\n\t\t\\hline\n\t\t15360 bit & 256 bit\n\t\\end{tabular}\n\\end{table}\n\nIn order to provide long-term security, i.e.\\ ensure that the schema will not be cracked even with the computational power obtained with several decades of hardware development, a security level of at least 128 bit should be chosen. \n\nDespite the existence of sophisticated algorithms running faster than a brute-force approach, and even a quantum algorithm, none of them is able to run in polynomial time. \n\nFurthermore, efficient classical algorithms also exist in certain cases, while on the other hand there exist groups for which computing the discrete algorithm is much more difficult, therefore the domain must be chosen carefully. \n\n\\subsection{Real-life applications}\nUsage of the discrete logarithm is standardized by The Internet Key Exchange (IKE), which defines cyclic groups and their order, despite some of them being of less than 1024 bit and therefore potentially breakable. \n\nThe European Institute for System Security has furthermore established a family of practical cryptography protocols based on discrete logarithm, which were originally intended for LAN security but quickly extended their scope: nowadays, discrete logarithm is used within implementations of access control, authentication, confidentiality protection, key exchange, digital signature and distributed network security management.\n\nThe most popular practical application of discrete logarithm is, however, the \\textit{Diffie-Hellman key exchange}: since discrete logarithm needs extensive computational power and longer keys than symmetric encryption, it is mostly used for exchanging a private key in a secure way.\n\n", "meta": {"hexsha": "66c7b6c54c85d0626817305431e26200b16a00bd", "size": 7459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/discrete-logarithm.tex", "max_stars_repo_name": "mrahtapot/TUM", "max_stars_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 225, "max_stars_repo_stars_event_min_datetime": "2019-10-02T10:49:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T22:25:38.000Z", "max_issues_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/discrete-logarithm.tex", "max_issues_repo_name": "mrahtapot/TUM", "max_issues_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-02-16T12:22:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-31T19:35:57.000Z", "max_forks_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/discrete-logarithm.tex", "max_forks_repo_name": "mrahtapot/TUM", "max_forks_repo_head_hexsha": "b736fc4ae065612dc988b6cb220fcf2f6119a138", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 69, "max_forks_repo_forks_event_min_datetime": "2019-10-02T21:46:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T19:27:50.000Z", "avg_line_length": 88.7976190476, "max_line_length": 426, "alphanum_fraction": 0.7735621397, "num_tokens": 1772, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.875787001374006, "lm_q1q2_score": 0.8083857018565457}}
{"text": "\\chapter{Convolutional Neural Networks (CNN)}\n\\section{Tensor notation}\n\\begin{definition}\nA tensor $T$ of order $d$  is a multi-index array,\n\\begin{equation}\nT \\in \\mathbb R^{n_1 \\times n_2 \\times \\cdots \\times n_d},\n\\end{equation}\nwith $i$-th dimension being $n_i$. \n\\end{definition}\n\\paragraph{Example 1: 2D grey image}\n\\begin{equation}\\label{2DGreyImage}\nT \\in \\mathbb{R}^{n_1 \\times n_2}.\n\\end{equation}\n\\paragraph{Example 2: 2D color image}\n\\begin{equation}\\label{2DColorImage}\nT \\in \\mathbb{R}^{3 \\times n_1 \\times n_2}.\n\\end{equation}\n\\paragraph{Example 3: 3D grey image - MRI}\n\\begin{equation}\\label{3DColorImage}\nT \\in \\mathbb{R}^{ n_1 \\times n_2 \\times n_3}.\n\\end{equation}\n\n\\begin{definition}[Tensor Product]\nIf $X \\in \\mathbb R^{n_1 \\times n_2 \\times \\cdots \\times n_d}$ and $Y \\in \\mathbb R^{m_1 \\times m_2 \\times \\cdots \\times m_e}$, then the tensor product is noted as $\\otimes$ with the next definition, \n\\begin{equation}\nX \\otimes Y \\in \\mathbb R^{n_1 \\times n_2 \\times \\cdots \\times n_d \\times m_1 \\times m_2 \\times \\cdots \\times m_e},\n\\end{equation}\nwith \n\\begin{equation}\n(X\\otimes y)_{i_1, \\cdots, i_d, j_1, \\cdots,j_e} = X_{i_1, \\cdots, i_d} Y_{j_1, \\cdots, j_e}.\n\\end{equation}\n\\end{definition}\n\\paragraph{Example 5: Rank one matrix} If $x \\in \\mathbb{R}^n$ and $y \\in \\mathbb{R}^m$, then\n\\begin{equation}\\label{3DColorImage}\nx \\otimes y \\in \\mathbb{R}^{n \\times m},\n\\end{equation}\nwith \n\\begin{equation}\nx \\otimes y = x y^\\top.\n\\end{equation}\n\n\\paragraph{Example 6: } If $X \\in \\mathbb{R}^{n_1\\times n_2}$ and $Y \\in \\mathbb{R}^{m_1 \\times m_2}$, then\n\\begin{equation}\\label{3DColorImage}\nX \\otimes Y \\in \\mathbb{R}^{n_1 \\times n_1 \\times m_1 \\times m_1},\n\\end{equation}\nwith \n\\begin{equation}\n(X \\otimes Y)_{i_1, i_2, j_1 ,j_2}  =  X_{i_1, i_2} Y_{j_1, j_2}.\n\\end{equation}\n\n\\begin{definition}[Tensor ``inner product\"]\nIf \n$$\nX \\in \\mathbb R^{(n_1 \\times n_2 \\times \\cdots \\times n_d )\\times\n  (t_1\\times t_2\\times\\cdots\\times t_k)}\n$$ and \n$$\nY\\in \\mathbb R^{ (t_k\\times t_{k-1}\\times\\cdots\\times t_1)\\times\n  (m_1 \\times m_2 \\times \\cdots \\times m_e)},\n$$\nthen the tensor ``inner product\" with order $k$ is given by\n\\begin{equation}\nX\\odot_k Y \\in \\mathbb R^{n_1 \\times n_2 \\times \\cdots \\times n_d \\times m_1 \\times m_2 \\times \\cdots \\times m_e},\n\\end{equation}\nwith \n\\begin{equation}\n(X\\odot_k Y)_{i_1, \\cdots, i_d, j_1, \\cdots,j_e} \n=\\sum_{s_1=1}^{t_1} \\cdots\\sum_{s_k=1}^{t_k}X_{i_1, \\cdots, i_d, s_1,\\cdots,s_k} Y_{s_k,\\cdots,s_1,,j_1, \\cdots, j_e}.\n\\end{equation}\n\\end{definition}\nWe note that\n$$\nX\\otimes Y =X\\odot_0Y\n$$\nFor simplicity, we denote\n\\begin{equation}\nX\\cdot Y=X\\odot_1Y \\mbox{ and } X:Y=X\\odot_2 Y  .\n\\end{equation}\n\\paragraph{Example 7: } If $x \\in \\mathbb{R}^{1\\times n}$ and $y \\in \\mathbb{R}^{n}$, then\n\\begin{equation}\\label{3DColorImage}\nx \\odot_1 y =xy= \\sum_{i=1}^n x_{1,i} y_{i,1}.\\in \\mathbb{R}^{1}. \n\\end{equation}\n\n\n\\paragraph{Example 8: } If $X \\in \\mathbb{R}^{n_1 \\times m}$ and $Y \\in \\mathbb{R}^{m \\times n_2}$, then\n\\begin{equation}\\label{3DColorImage}\nX \\odot_2 Y =XY\\in \\mathbb{R}^{n_1 \\times n_2},\n\\end{equation}\nwith \n\\begin{equation}\n(X \\cdot Y)_{i,j} = \\sum_{k=1}^m X_{i,k} Y_{k,j}.\n\\end{equation}\nwhich is again the product of two matrices. \n\n\\section{Single layer with vector space}\nA singular layer linear neural network can be written as\n$$\nf(x, \\theta)\n=\n\\begin{pmatrix}\n  f_1(x,\\theta_1)\\\\\n\\vdots\n\\\\\n  f_m(x,\\theta_m)\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n w_1 x+b_1, \\\\\n\\vdots\n\\\\\n w_m x+b_m, \\\\\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n w_1\\\\\n\\vdots\n\\\\\n w_m\n\\end{pmatrix}x\n+\n\\begin{pmatrix}\nb_1\\\\\n\\vdots\n\\\\\nb_m\n\\end{pmatrix}\n=Wx+b=\\theta \\tilde x\n$$\nwhere\n\\begin{equation}\nW\\in \\mathbb R^{m\\times n}, \n\\theta=(W,b)=\n\\begin{pmatrix}\n  \\theta_1\\\\\n\\vdots\\\\\n\\theta_m\n\\end{pmatrix}, \\quad\n\\tilde x=\n\\begin{pmatrix}\n  x\\\\\n1\n\\end{pmatrix}\n\\end{equation}\n\n\nWe have\n\\begin{equation}\nf(x; \\theta )= W x+b, ~ \\Theta = \\{ \\theta = (W,b) ~|~ W \\in \\mathbb{R}^{m \\times n}, b \\in \\mathbb{R}^m \\}.\n\\end{equation}\n\nwith $f: \\mathbb{R}^n \\to \\mathbb{R}^m$.\n\n\\section{Deep neural networks (DNN) with vector space}\n\\begin{figure}[!ht]        \n\\center{\\includegraphics[width=12cm,height=6cm] {figures/ANN.png}}        \n\\caption{A typical deep neural network}      \n\\end{figure}\nWe consider a sequence of affine operations:\n\\begin{equation}\n\\theta^j: \\mathbb R^{\\hat{n}^{j}}\\mapsto \\mathbb R^{ n^{j}}.   \n\\end{equation}\nwith\n\\begin{equation}\\label{DNN_affinemap}\n\\theta^j(x) =  W^j x + b^j \n=\n(W^j, b^j) \\cdot\n\\begin{pmatrix}\n  x \\\\\n1\n\\end{pmatrix}\n=\n\\theta^j \\cdot\n\\begin{pmatrix}\n  x \\\\\n1\n\\end{pmatrix}\n\\end{equation}\nand \n\\begin{equation}\nW^j\\in \\mathbb R^{n^j \\times  \\hat n^{j}}, b^j\\in \\mathbb R^{n^j}.\n\\end{equation}\nWith a slight abuse of notation, we also denote\n\\begin{equation}\n\\theta^j=(W^j, b^j)\n=\n\\begin{pmatrix}\n\\theta^j_{1}\\\\\n\\vdots \\\\  \n\\theta^j_{n^j}\\\\\n\\end{pmatrix}\n\\in \\mathbb R^{n^j\\times (\\hat n^{j}+1)}.\n\\end{equation}\n\nFor $j=0$, we have the input data \n$$\nx\\in \\mathbb R^{\\hat n^{0}}\n$$\nFor MNIST data base, we have\n$$\n\\hat n^0 = 784.\n$$\n\nWe consider nonlinear activation function that is applied componentwise:\n\\begin{equation}\\label{DNN_iteration_vector}\ng:\\mathbb R^{ n^{j-1}}\\mapsto \\mathbb R^{n^{j-1}},\n\\end{equation}\nand polling functions\n\\begin{equation}\\label{DNN_iteration_vector}\nr^j:\\mathbb R^{ n^{j-1}}\\mapsto \\mathbb R^{\\hat n^{j}}. \n\\end{equation}\nPoolling is not always applied after each application of activation.\nWhen it is not applied, $r^j$ is identity and $\\hat n^j=n^{j-1}$;   when\nit is applied, $r_j$ is usually nonlinear and\n$$\n\\hat n^j<n^{j-1}. \n$$\n\nWe consider the pooled-activation functions:\n\\begin{equation}\\label{DNN_iteration_vector}\ng^j=r^j\\circ g: \\mathbb R^{{n}_{j-1}}\\mapsto\n\\mathbb R^{\\hat n^{j}}, \\quad j =  1 :J.\n\\end{equation}\nWe note that\n\\begin{equation}\n\\theta^j\\circ g^j:    \\mathbb R^{{n}^{j-1}}\\mapsto\n\\mathbb R^{n^{j}}\n\\end{equation}\n\nWe can then define a multi-layer neural network\n\t\\begin{equation}\\label{DNN_finallayer}\n\tf(x; \\Theta) = f^J,\n\t\\end{equation}\n        in terms of the following recursive relation:\n\t\\begin{equation}\\label{DNN_iteration_vector}\n\tf^j(x,\\Theta^j) = (\\theta^j\\circ g^j\\circ\n        f^{j-1})(x,\\Theta^{j-1}), \\quad j=1:J\n\t\\end{equation}\nwhere\n\\begin{equation}\n\\Theta^j=(\\Theta^{j-1},\\theta^j), \\quad \\Theta^0=\\theta^0\n\\end{equation}\nand\n\t\\begin{equation}\n\tf^0(x)=\\theta^0(x)\n\t\\end{equation}\n\tand \n\n\\begin{align}\n\\Theta =\\Theta_J =(\\theta^0,\\theta^1, \\cdots, \\theta^J)=( ({W^0}, {b^0}),({W^1}, {b^1}),\n\\cdots, ({W^J}, {b^J})) \\\\\n\\displaystyle\n\t\\in  (\\mathbb{R}^{n^0 \\times (\\hat n^0 + 1)}) \\oplus \\cdots\n        \\oplus  \t(\\mathbb{R}^{{n}_{J} \\times (\\hat\n          n^{J}+1)})=\n\\oplus_{j=0}^J \\mathbb{R}^{n^{j} \\times (\\hat n^{j} + 1)}\n\\end{align}\n\n\n\\subsection{DNN models with tensor notation}\n\\subsubsection{General setup}\nData:\n\t\\begin{itemize}\n\t\t\\item Input set: $\\bm{X} = \\{x_1, \\cdots, x_N\\}$\n\t\t\\item Output set: $\\bm{y} =  \\{y_1, \\cdots, y_N\\}$\n\t\t\\item Generally,  input use $x \\in \\mathbb{R}^{ n^0_1\\times \\cdots \\times n^0_{d^0} }$, with a label $y \\in \\mathbb{R}^{m_1 \\times \\cdots \\times m_c}$\n\t\t%\\item Here $\\hat c_0$ means the channel dimension and $\\hat n_1\\times \\cdots \\times \\hat n_d$ means the essential dimension.\n\t\\end{itemize}\n\n\nNow we first construct the linear operation:\n$$\n\\theta^j: \\mathbb{R}^{ n^j_1\\times \\cdots \\times n^j_{d^{j}} } \\mapsto  \\mathbb{R}^{ n^{j+1}_1\\times \\cdots \\times n^{j+1}_{d^{j+1}} },\n$$\nwith\n\\begin{equation}\\label{DNN_tensor_affinemap}\n\\theta^j(x) =  W^j \\odot_{d^j} x + b^j \\in \\mathbb R^{n^{j+1}_1 \\times \\cdots \\times  n^{j+1}_{d^{j+1}}},\n\\end{equation}\nwith dimension of $W^j$ and $b^j$ as\n\\begin{equation}\\label{space:W&b}\nW^j \\in \\mathbb{R}^{ \\left(n^{j+1}_1 \\times \\cdots \\times n^{j+1}_{d^{j+1}}\\right) \\times \\left(n^j_1\\times \\cdots \\times n^j_{d^{j}}\\right) }, \\quad b^j \\in \\mathbb R^{n^{j+1}_1 \\times \\cdots \\times  n^{j+1}_{d^{j+1}}}.\n\\end{equation}\nThen the above equation can be expressed by a extended system like:\n\\begin{equation}\\label{DNN:extend}\n\\theta^j(x) = \\tilde W^j \\odot_{d^j} \\tilde x.\n\\end{equation}\nHere we have the extended version of $x$ and $W$ as combine $b$ into $W$:\n\\begin{itemize}\n\t\\item Extension of $x$\n\\begin{equation}\\label{space:extend^x}\n\\tilde x  \\in \\mathbb{R}^{ (n^j_1 + 1)\\times \\cdots \\times (n^j_{d^{j}} + 1) },\n\\end{equation}\nwith \n\\begin{equation}\\label{form:extend^x}\n\\begin{cases}\n&\\tilde x[1:n^j_{1},\\cdots,1:n^{j}_{d^{j}}] = x, \\\\\n &\\tilde x[(n^j_1 + 1), \\cdots, (n^j_{d^{j}} + 1) ] = 1, \\\\\n &\\tilde x[i_1,\\cdots,i_{d^j}] = 0 \\quad \\text{others}.\n\\end{cases}\n\\end{equation}\n\t\\item Extension of $W^j$\n\\begin{equation}\\label{space:extend^W}\n\\tilde W^j  \\in \\mathbb{R}^{ \\left(n^{j+1}_1 \\times \\cdots \\times n^{j+1}_{d^{j+1}}\\right) \\times \\left((n^j_1 + 1)\\times \\cdots \\times (n^j_{d^{j}} + 1)\\right) },\n\\end{equation}\nwith \n\\begin{equation}\\label{form:extend^W}\n\\begin{cases}\n&\\tilde W^j[1:n^{j+1}_1,\\cdots,1:n^{j+1}_{d^{j+1}},1:n^j_{1},\\cdots,1:n^{j}_{d^{j}}] = W, \\\\\n&\\tilde W^j[1:n^{j+1}_1,\\cdots,1:n^{j+1}_{d^{j+1}},(n^j_1 + 1), \\cdots, (n^j_{d^{j}} + 1) ] = b^j, \\\\\n&\\tilde W^j[i_1,\\cdots,i_{d^j},j_1,\\cdots,] = 0 \\quad \\text{others}.\n\\end{cases}\n\\end{equation}\n\\end{itemize}\n\n\\subsubsection{Example of extended form of affine map for 1st and 2nd order tensor}\n\\begin{itemize}\n\t\\item For 1st order tensor(vector space) \\\\\n\tFor this cases, $d^j = 1$ for all $j$ or we can have:\n\t\\begin{equation}\n\tx \\in \\mathbb{R}^{n}, \\quad W \\in \\mathbb{R}^{m \\times n}.\n\t\\end{equation}\n\tThen we have the extended form as:\n\t\\begin{equation}\\label{extend:1st}\n\t\\tilde x = \\begin{pmatrix}\n\tx \\\\\n\t1\n\t\\end{pmatrix}, \\quad \\tilde W = (W, b),\n\t\\end{equation}\n\tfor $b \\in \\mathbb{R}^m$.\n\t\\item Convolution model for image without channels(2nd order tensor) \\\\\n\tFor this case, $d_j = 2$ for all $j$ or we can have:\n\t\\begin{equation}\n\tx \\in \\mathbb{R}^{n_1 \\times n_2}, \\quad W \\in \\mathbb{R}^{(m_1\\times m_2) \\times (n_1\\times n_2)}.\n\t\\end{equation}\n\tThen we have the extended form for $x$:\n\t\\begin{equation}\\label{extend:2nd_x}\n\t\\tilde x = \\begin{pmatrix}\n\tx & 0\\\\\n\t0 & 1\n\t\\end{pmatrix}.\n\t\\end{equation}\n\tFor $W$, because it is a 4th order tensor, we cannot express it as a matrix form, we can only have\n\t\\begin{equation}\\label{extend:2nd_W}\n\t\\begin{cases}\n\t&\\tilde W[1:m_1, 1:m_2,1:n_{1},1:n_{2}] = W, \\\\\n\t&\\tilde W[1:m_1,1:m_{2},(n_1 + 1), (n_{2} + 1) ] = b, \\\\\n\t&\\tilde W[1:m_1,1:m_{2},1:n_1, (n_{2} + 1)] = 0 \\\\\n\t&\\tilde W[1:m_1,1:m_{2}, (n_1+1), 1:n_{2}] = 0.\n\t\\end{cases}\n\t\\end{equation}\n\\end{itemize}\n\n\n\\subsection{BP Algorithm:}\n\nUnder the above notation and iteration structure, we have:\n\\begin{equation}\\label{BP_recursion}\n\\frac{\\partial f^j}{\\partial \\theta^i} = \\begin{cases}\n0 \\quad &\\text{if} \\quad i > j, \\\\\nI_{n_j} \\otimes \\begin{pmatrix}\ng^{j}(f^{j-1}) \\\\\n1 \n\\end{pmatrix} \\quad &\\text{if} \\quad i = j,\\\\\nW^j  \\frac{\\partial g^{j}(f^{j-1})}{\\partial f^{j-1}} \\cdot \\frac{\\partial f^{j-1}}{\\partial \\theta^i}  \\quad &\\text{if} \\quad i < j.\n\\end{cases}\n\\end{equation}\nSo, the BP algorithm is to use the \\eqref{BP_recursion} to compute\n\\begin{equation}\n\\frac{\\partial f^J}{\\partial {\\Theta} } \n= \\left\\{\n\\frac{\\partial  f^J}{\\partial {\\theta^0} }, \n\\frac{\\partial  f^J}{\\partial {\\theta^1} }, \n\\cdots \\frac{\\partial f^J}{\\partial\n\t{\\theta^J} }\\right\\} \\in {\\rm cell}\n\\left(\n\\mathbb R^{c\\times n_0 \\times (\\hat n_0 + 1)},  \n\\mathbb R^{c\\times n_1 \\times (\\hat n_1 + 1)},  \n\\cdots, \\mathbb\nR^{c\\times n_{J} \\times (\\hat n_{J-1}+1)}\n\\right)\n\\end{equation}\n\nHere we can check the formula \\eqref{BP_recursion}:\n\\begin{itemize} \n\t\\item First for $i = j$:\n\t\\begin{equation}\n\t\\frac{\\partial f^j_k}{\\partial \\theta^j_{l,s}} =\n\t\\frac{\\partial}{\\partial \\theta^j_{l,s}}\n\t\\left( \n\t\\theta^j_{k}\n\t\\begin{pmatrix}\n\tg^{j}(f^{j-1})) \\\\ 1 \n\t\\end{pmatrix}\n\t\\right) \n\t= \\delta_{k,l} \n\t\\begin{pmatrix} \n\tg^{j}(f^{j-1}) \\\\ 1 \n\t\\end{pmatrix}_{s}\n\t\\end{equation}\n\t\n\tThis means that:\n\t\\begin{equation}\n\t\\left(\\frac{\\partial {f^j}}{\\partial {\\theta^j}}\\right)_{k,l,s} = \\frac{\\partial f^j_k}{\\partial \\theta^j_{l,s}} \n\t= \\delta_{k,l} \\begin{pmatrix} g^{j}(f^{j-1}) \\\\ 1 \\end{pmatrix}_{s} = (I_{n_j} \\otimes \\begin{pmatrix}\n\tg^{j}(f^{j-1}) \\\\\n\t1 \n\t\\end{pmatrix})_{k,l,s}.\n\t\\end{equation}\n\t\n\t\\item Then for $i < j$; \n\t\\begin{equation}\n\t\\frac{\\partial f^j}{\\partial \\theta^i}  \n\t=  \\frac{\\partial (\\theta^{j}\\circ g^j)}{\\partial f^{j-1}} \\cdot \\frac{\\partial f^{j-1}}{\\partial \\theta^i}.\n\t\\end{equation}\n\tWe can check it by:\n\t\\begin{align}\n\t\t\\left(\\frac{\\partial f^j}{\\partial \\theta^i} \\right)_{k,s,t} \n\t\t= \\frac{\\partial f^j_k}{\\partial \\theta^i_{s,t}} &=\n\t\t\\sum_{l = 1}^{n_{j-1}} \\frac{\\partial f^{j}_k}{\\partial f^{j-1}_l} \\frac{\\partial f^{j-1}_l}{\\partial \\theta^i_{s,t}}  =\n\t\t\\sum_{l = 1}^{n_{j-1}} \\left( \\frac{\\partial (\\theta^{j}\\circ\n\t\t\tg^j)}{\\partial f^{j-1}}\\right)_{k,l} \\left(\\frac{\\partial\n\t\t\tf^{j-1}}{\\partial \\theta^i}\\right)_{l,s,t} \\\\  &=  \n\t\t\\left(\\frac{\\partial  (\\theta^{j}\\circ g^j)}{\\partial f^{j-1}} \\cdot \\frac{\\partial f^{j-1}}{\\partial \\theta^i} \\right)_{k,s,t}.\n\t\\end{align}\n\tSo what we only need to do is to compute:\n\t\\begin{equation}\n\t\\frac{\\partial f^{j}_k}{\\partial f^{j-1}_l} =\\frac{ \\partial}{\\partial f^{j-1}_l}\\left( W^j_{k} g^{j}(f^{j-1}) \\right) = W^j_{k} \\frac{ \\partial }{\\partial f^{j-1}_l}\\left(g^{j}(f^{j-1})\\right),\n\t\\end{equation}\n\tthis means that \n\t\\begin{equation}\n\t\\left(\\frac{\\partial  (\\theta^{j}\\circ g^j)}{\\partial\n\t\tf^{j-1}}\\right)_{k,l} \n\t= \\frac{\\partial  (\\theta^{j}\\circ g^j)_k}{\\partial f^{j-1}_l}  = W^j_{k} \\frac{ \\partial}{\\partial f^{j-1}_l} \\left( g^{j}(f^{j-1})\\right)= \\left(W^j \\frac{\\partial }{\\partial f^{j-1}}\\left(g^{j}(f^{j-1})\\right)\\right)_{k,l}\n\t\\end{equation}\n\\end{itemize}\n\n\\subsection{Classification properties under this notation}\n\\begin{theorem}\n\tIf $\\{A_k\\}_{k=1}^c$ are separable with positive distance, then it\n\tcan be separated by $f(x; \\Theta) = f^2$, with $W^2= id, b^2=0$ and\n\tall activation function is $\\tau$.\n\\end{theorem}\n\n\\section{CNN based on the DNN notation}\n\\subsection{General setup}\n\\begin{enumerate}\n\t\\item Data:\n\t\\begin{itemize}\n\t\t\\item Input set: $\\bm{X} = \\{x_1, \\cdots, x_N\\}$\n\t\t\\item Output set: $\\bm{y} =  \\{y_1, \\cdots, y_N\\}$\n\t\t\\item Generally,  input use $x \\in \\mathbb{R}^{\\hat c_0 \\times \\hat n_0\\times \\cdots \\times \\hat n_0 }$, with a label $y \\in \\mathbb{R}^c$ (output for classification problem)\n\t\t\\item Here $\\hat c_0$ means the channel dimension and $\\hat n_1\\times \\cdots \\times \\hat n_d$ means the essential dimension.\n\t\\end{itemize}\n\t\\item Here we use $x \\in \\mathbb{R}^{\\hat c_0 \\times n \\times n} $,\n\t$y \\in \\mathbb{R}^c$ as example.\n\t\\item Kernels: in CNN they generally use $K^i$ and $b^i$ to stand for the kernels and bias.  \n\\end{enumerate}\n\n\\paragraph{Example 1: 2D grey image}\n\\begin{equation}\\label{2DGreyImage}\nc_0=1, d=2  \n\\end{equation}\n\\paragraph{Example 2: 2D color image}\n\\begin{equation}\\label{2DColorImage}\nc_0=3, d=2  \n\\end{equation}\n\\paragraph{Example 3: 3D grey image - MRI}\n%\\paragraph{Example 4: 3D color image?}\n\n\n\\subsection{A simple example of DNN for images}\n\nMultilayer structures in convolutional layers is totally the same for \\eqref{DNN_affinemap} - \\eqref{DNN_finallayer}: the only difference  is the structure of affine map:\n\n\\begin{equation}\\label{CNN_affinemap}\n\\theta^j_{p}(x) =  W^j_p \\odot_3 x + b^j_p \\in \\mathbb R^{n_j \\times n_j}, \\quad p=1:c_j\n\\end{equation}\n\n\\begin{equation}\\label{CNN_affinemap}\n\\theta^j(x) =  W^j\\odot_3 x + b^j\n\\end{equation}\nwith \n\\begin{equation}\n\\theta^j: \\mathbb R^{\\hat c_j  \\times \\hat{n}_{j} \\times \\hat n_{j} } \\mapsto \\mathbb{R}^{c_j \\times n_{j} \\times n_j }.\n\\end{equation}\n\\begin{remark}\n\tFor many case, \n\t\\begin{equation}\n\tc_j = 2 \\hat c_j,\n\t\\end{equation}\n\tespecially for $r^{j-1}$ is a real pooling function. \n\\end{remark}\nHere\n\\begin{equation}\nW^j \\in \\mathbb{R}^{(c_j \\times n_{j} \\times n_j) \\times\n\t(\\hat{n}_{j} \\times \\hat n_{j}\\times \\hat c_{j} )}, \\quad\nb^j\\in  \\mathbb R^{c_j \\times n_{j} \\times n_j},  \n\\end{equation}\nand \n\\begin{align}\n\\theta^j  &= \\{W^j , b^j\\}  \\in \\mathbb{R}^{(c_j \\times n_{j} \\times n_j) \\times\n\t(\\hat{n}_{j} \\times \\hat n_{j}\\times \\hat c_{j} )} \\oplus \\mathbb R^{c_j \\times n_{j} \\times n_j} \\\\ \n&\\cong  \\mathbb{R}^{(c_j \\times n_{j} \\times n_j) \\times\n\t(\\hat{n}_{j} \\times \\hat n_{j}\\times c_{j} + 1 )}\n\\end{align}\n\nWe note that\n\\begin{equation}\n\\hat n_0 =n  \n\\end{equation}\n\nWe consider nonlinear activation function applied element wise:\n\\begin{equation}\\label{CNN_iteration_vector}\ng: \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1} }\\mapsto  \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1}},\n\\end{equation}\nand polling functions\n\\begin{equation}\\label{CNN_iteration_vector}\nr^j: \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1} }\\mapsto  \\mathbb R^{\\hat c_j \\times \\hat n_{j} \\times\\hat n_j }. \n\\end{equation}\n\nWe consider ``pooled-activation'' functions:\n\\begin{equation}\\label{CNN_iteration_vector}\ng^j=r^j\\circ g:  \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1} }\\mapsto\n\\mathbb  \\mathbb R^{\\hat c_j \\times \\hat n_{j} \\times \\hat n_j }, \\quad j  = 1:J. \n\\end{equation}\n\\begin{remark}\n\tGenerally speaking, we have \n\t\\begin{equation}\n\t\\hat c_{j} = c_{j-1},\n\t\\end{equation}\n\tfor almost cases.\n\t\n\tBut, some times, when the channel size is big enough,  they would like to take:\n\t\\begin{equation}\n\t\\hat c_{j} = \\frac{c_{j-1}}{2}.\n\t\\end{equation}\n\tto reduce the channel dimension by adding two channels as one then using $r$ or just using the max-pooling for both this two channel and get one out put.\n\t\n\\end{remark}\n\n\nWe have the multi-layer DNN structure like:\n\\begin{equation}\\label{CNN_iteration_vector}\nf^j(x,\\Theta^j) = (\\theta^j\\circ g^{j}\\circ f^{j-1})(x,\\Theta^{j-1}) \\in \\mathbb{R}^{c_j \\times n_j \\times n_j }\n\\end{equation}\nwhere\n\\begin{equation}\n\\Theta^j=(\\Theta^{j-1},\\theta^j), \\quad \\Theta^0=\\theta^0 \n\\end{equation}\nwith \n\\begin{equation}\nf^0(x)=\\theta^0(x)\n\\end{equation}\nand \n\\begin{equation}\\label{CNN_finallayer}\nf(x; \\Theta) = f^J.\n\\end{equation}\n\nRoughly speaking, \\eqref{CNN_affinemap} -\n\\eqref{CNN_finallayer} a special case of \\eqref{DNN_affinemap}\n- \\eqref{DNN_finallayer} in tensor notation.\n\n\n\\subsection{Convolution structure for images}\nA convolution operation is a special linear mapping of the following form:\n\\begin{equation}\n\\theta^j(x) = K^j \\circledast x + {\\rm{diag}(b^j)} \\cdot \\bm{1}_{c_j \\times n_j \\times n_j} \\quad\n\\in\\mathbb R^{c_j\\times n_j\\times n_j}.\n\\end{equation}\nwith \n\\begin{equation}\nK^j \\in \\mathbb{R}^{ c_{j} \\times \\hat c_{j} \\times (2k+1) \\times (2k+1)},  \\quad \\text{and} \\quad b^j \\in \\mathbb{R}^{c_j},\n\\end{equation}\nand \n\\begin{equation}\n\\bm{1}_{c_j \\times n_j \\times n_j} = 1_{c_{j}} \\otimes 1_{n_j} \\otimes 1_{n_j}\n\\end{equation}\nfor $k = 0, 1, 2, 3...$.\n\nGive $p\\in \\{1,\\ldots c_j\\}$\n\\begin{equation}\n(\\theta^j(x))_p= (K^j \\circledast x)_p+b^j_p{\\bm 1}_{n_j\\times n_j}\n\\end{equation}\nand\n\\begin{equation}\n(K^j \\circledast x)_p\n= \\sum_{q=1}^{\\hat c_{j}} K^{j}_{p,q} \\ast x_q \\in \\mathbb{R}^{n_j \\times n_j}, \\quad p= 1:c_j.\n\\end{equation}\nwhere\n$$\nK^{j}_{p,q}\\in \\mathbb R^{(2k+1)\\times (2k+1)}, x_q\\in \\mathbb\nR^{\\hat n_{j}\\times \\hat n_{j}}.\n$$\nHere $\\ast$ is the traditional convolution defined as:\n\\begin{equation}\\label{ConvPadding}\n(K \\ast x)_{i,j} :=\\sum_{s, t = -k}^k  K_{s+k+1,t+k+1} x_{i + s, j + t},\n\\end{equation}\nHere we assume implicitly that a special ``padding'' is used such that\n\\begin{equation}\n\\label{zero-padding}\nx_{i,j}=0 \\mbox{ if } i, j\\le 0 \\mbox{ or } i, j > n_j.  \n\\end{equation}\n\n\\bigskip \\hrule \\bigskip  \n\\begin{example} ~\n\\begin{enumerate}\n\t\\item \n\tFor $j=1$, $c_0=3, \\hat n_0=n$.   We can take $c_1$ different channels\n\t\\begin{equation}\n\t(K^1 \\circledast x)_p= \\sum_{q=1}^{\\hat{c}_1=3} K^{j}_{p,q} \\ast x_q \\in \\mathbb{R}^{n_j \\times n_j}, \\quad p= 1:c_1.\n\t\\end{equation}\n\t\\item We take $c_2$ different channels\n\t\\begin{equation}\n\t\\left(\\theta^2(K^1 \\circledast x)\\right)_p= \\sum_{q=1}^{\\hat c_2} K^{j}_{p,q} \\ast g^2\\left((K^1 \\circledast x)_q\\right) + b^2_p{\\bm 1}_{n_2\\times n_2} \\in \\mathbb{R}^{n_j \\times n_j}, \\quad p= 1:c_2.\n\t\\end{equation}\n\\end{enumerate}\n\\end{example}\n\\bigskip \\hrule \\bigskip  \n\n\n\\begin{remark}\n\tWe recall the standard definition of convolution of two tensor:\n\t\\begin{equation}\n\t\\label{standard-convolution}\n\t(u\\ast x)_{i,j}=\\sum_{k,\\ell=-\\infty}^\\infty u_{i-k,j-\\ell}x_{k,\\ell}  \n\t\\end{equation}\n\tThe definitions of \\eqref{ConvPadding} and\n\t\\eqref{standard-convolution} are related by taking $u$ to be a ``locally\n\tsupported'' tensor and using appropriate paddings.\n\\end{remark}\n\n\nSo, we say that CNN is a special cases means the above process has those next properties:\n\\begin{properties} Under the notation  \\eqref{CNN_affinemap} - \\eqref{CNN_finallayer}:\n\t\\begin{enumerate}\n\t\t\\item $\\hat n_{j} = n_j$. Or some times they do convolutions without padding such that $\\hat n_{j} = n_j + 2k$, with kernel size $2k+1$.\n\t\t\n\t\t\\item $n_{j-1} = 2 \\hat n_j$ in some cases. \n\t\t\\item Choice of pooling function:\n\t\t\\begin{equation}\n\t\t\\label{pooling}\n\t\tr(x)=R\\ast x+rn(x)\n\t\t\\end{equation}\n\t\twhere \n\t\t\\begin{equation}\n\t\t[n(x)]_{i,j}=\\| (x_{2i+k,2j+l}: k,l=-1,0,1)\\|, \\quad i,j=1:\\hat n_j\n\t\t\\end{equation}\n\t\twhere $\\|\\cdot\\|$ is either $\\ell^p$-norm for $p=2$ or $\\infty$. \n\t\\end{enumerate}\n\tor \n\t\\begin{equation}\n\t\\label{pooling2}\n\tr(x)=R\\ast x+r_2 n_2(x)+r_\\infty n_\\infty(x)\n\t\\end{equation}\n\twhere $n_p(x)$ corresponds to local $\\ell^p$ norm.\n\\end{properties}\nFor $p=\\infty$, we may not take the actual $\\ell^\\infty$ norm, but\nrather take the maximum without taking absolute value:\n$$\n[n_\\infty(x)]_{ij}=\\max_{-1\\le k,l\\le 1} x_{2i+k, 2j+l}\n$$\n\nFor example, \n\\begin{equation}\n\\label{stride-pooling}\n[r(x)]_{ij}=R\\ast x_{2i,2j}+rn(x)_{2i,2j}, i, j=1:\\hat n_{\\ell}\n\\end{equation}\nIf we take $r=0$,  the above procedure is precisely what is so-called\n``stride'' in the literature.   This means that, the stride is just a\nspecial pooling that defines a ``coarse'' point as a linear\ncombination of its neighbors and the underlying coefficients will be\nobtained from the training process. \n\n\\subsection{Understand channel as multi-coarse space}\nWe want to under stand the channels in CNN by the multi-coarse space in AMG. The idea is that, if we have $c$ channels as the input, we want to get some multi-coarse space with or just do some smoother in this level.\n\n\\subsection{Convolution with stride for image}\nStride is a very convenient way(maybe the simplest way) to reduce the essential dimension of images. And it can be combined with classical convolution very easily as there are both linear operation.\n\\subsubsection{Definition of stride}\nIf we use stride $s$, we have have the stander convolution operator with stride $s$ as:\n\\begin{equation}\\label{equ:convstride}\n(K\\ast_{s} x)_{i,j} = \\sum_{p, q = -k}^k K_{p+k+1,q+k+1}x_{is + p, js + q} .\n\\end{equation}\nThis stride properties in some application are often used as pooling(subsampling, coarsening).  \n\nHere we can define a special pooling operator as $S(\\cdot,s)$ which likes the $C/F$ split for choosing coarse point:\n\\begin{equation}\nS(X,s)_{i,j} = X_{is, js },\n\\end{equation}\nthen we have:\n\\begin{equation}\\label{equ:stride}\nX \\ast_s K = S(X\\ast K, s),\n\\end{equation}\nwith the $\\ast$ and $\\ast_s$ defined by \\eqref{ConvPadding} and \\eqref{equ:convstride}\n\\begin{proof}\n\t\\begin{align}\n\tS(X \\ast K,s)_{i,j} &= (X \\ast K)_{is, js}  \\\\\n\t&= \\sum_{p, q = -k}^k K_{p+k+1,q+k+1}x_{is + p, js + q}  \\\\\n\t&= (X \\ast_s K)_{i,j}.\n\t\\end{align}\n\\end{proof}\n\n\\begin{remark}\n\tHere we need to mark that, in fact, the stride operation is just a kind of special coarse operations. The convolution with stride is in fact a kind of restriction operation with certain coarse strategy and some trained restrictions operations. \n\\end{remark}\n\n\n\n\\subsubsection{Add stride without change $\\theta^j$}\n\\begin{enumerate}\n\t\n\t\\item Convolution: \n\t\\begin{equation}\n\t\\theta^j: \\mathbb R^{\\hat c_j \\times \\hat{n}_{j} \\times \\hat n_{j} } \\mapsto \\mathbb{R}^{c_j \\times n_{j} \\times n_j }.\n\t\\end{equation}\n\twith\n\t\\begin{equation}\n\t\\theta^j(x) = K^j \\circledast x + {\\rm{diag}(b^j)} \\cdot \\bm{1}_{c_j \\times n_j \\times n_j} \\quad\n\t\\in\\mathbb R^{c_j\\times n_j\\times n_j}.\n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\tK^j \\in \\mathbb{R}^{ c_{j} \\times \\hat c_{j} \\times (2k+1) \\times (2k+1)},  \\quad \\text{and} \\quad b^j \\in \\mathbb{R}^{c_j},\n\t\\end{equation}\n\tand \n\t\\begin{equation}\n\t\\bm{1}_{c_j \\times n_j \\times n_j} = 1_{c_{j}} \\otimes 1_{n_j} \\otimes 1_{n_j}\n\t\\end{equation}\n\tfor $k = 0, 1, 2, 3...$.\n\t\n\t\\item Stride: \n\t\\begin{equation}\n\tS^{j-1}: \\mathbb R^{ c_{j-1} \\times {n}_{j-1} \\times  n_{j-1}} \\mapsto \\mathbb{R}^{ c_{j-1} \\times\\tilde n_{j-1} \\times\\tilde  n_{j-1} }.\n\t\\end{equation}\n\twith\n\t\\begin{equation}\n\tS^{j-1}(X) = S(X, s^{j-1}),\n\t\\end{equation}\n\tfor $s^{j-1} = 1$ for almost $j$ and $s^{j-1} = 2$ for near $\\log \\hat n_0$ times.\n\t\n\t\\item Activation: \n\t\\begin{equation}\\label{CNN_iteration_vector}\n\tg: \\mathbb R^{c_{j-1} \\times \\tilde n_{j-1} \\times \\tilde  n_{j-1} }\\mapsto  \\mathbb R^{c_{j-1} \\times \\tilde n_{j-1} \\times \\tilde n_{j-1}},\n\t\\end{equation}\n\t\n\t\\item Polling:\n\t\\begin{equation}\\label{CNN_iteration_vector}\n\tr^j: \\mathbb R^{c_{j-1} \\times \\tilde n_{j-1} \\times\\tilde n_{j-1} }\\mapsto  \\mathbb R^{\\hat c_j \\times \\hat n_{j} \\times\\hat n_j }. \n\t\\end{equation}\n\\end{enumerate}\n\n\nSo we have the stander CNN model with stride as:\n\\begin{itemize}\n\t\\item {\\color{red} $S^j \\circ \\theta^j\\circ r^j\\circ g$ form:}\n\t\\bigskip \\hrule \\bigskip  \n\t\\begin{equation}\\label{CNN_stride_iteration_vector}\n\tf^j(x,\\Theta^j) = (S^j \\circ \\theta^j\\circ r^j\\circ g\\circ f^{j-1})(x,\\Theta^{j-1}) \\in \\mathbb{R}^{c_j \\times \\tilde n_j \\times \\tilde n_j }\n\t\\end{equation}\n\twhere\n\t\\begin{equation}\n\t\\Theta^j=(\\Theta^{j-1},\\theta^j), \\quad \\Theta^0=\\theta^0 \n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\t{\\color{red} f^0(x)=S^0 \\circ \\theta^0(x)}\n\t\\end{equation}\n\tand \n\t\\begin{equation}\\label{CNN_finallayer}\n\tf(x; \\Theta) = f^J.\n\t\\end{equation}\n\t\\bigskip \\hrule \\bigskip  \n\t\n\t\\item {\\color{red} $\\theta^j\\circ r^j\\circ g \\circ S^{j-1} $ form:}\n\t\\bigskip \\hrule \\bigskip  \n\t\\begin{equation}\\label{CNN_stride_iteration_vector}\n\tf^j(x,\\Theta^j) = (\\theta^j\\circ r^j\\circ g \\circ S^{j-1} \\circ f^{j-1})(x,\\Theta^{j-1}) \\in \\mathbb{R}^{c_j \\times n_j \\times n_j }\n\t\\end{equation}\n\twhere\n\t\\begin{equation}\n\t\\Theta^j=(\\Theta^{j-1},\\theta^j), \\quad \\Theta^0=\\theta^0 \n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\t{\\color{red} f^0(x)=\\theta^0(x)}\n\t\\end{equation}\n\tand \n\t\\begin{equation}\\label{CNN_finallayer}\n\tf(x; \\Theta) = f^J.\n\t\\end{equation}\n\t\\bigskip \\hrule \\bigskip  \n\\end{itemize}\n\nWe can use those next plans for simplify \\eqref{CNN_stride_iteration_vector}. \n\\begin{enumerate}\n\t\\item {\\color{red} For $S^j \\circ \\theta^j\\circ r^j\\circ g$ form,} we can note stride with convolution together:\n\t\\bigskip \\hrule \\bigskip \n\tWe can consider ``stride-convolution'' functions:\n\t\\begin{equation}\\label{CNN_iteration_vector}\n\tC^j =S^j\\circ \\theta^j:  \\mathbb R^{\\hat c_{j} \\times\\hat n_{j} \\times\\hat n_{j} }\\mapsto\n\t\\mathbb  \\mathbb R^{c_j \\times \\tilde n_{j} \\times \\tilde n_j }, \\quad j  = 1:J. \n\t\\end{equation}\n\t\n\tThen we consider ``pooled-activation'' functions:\n\t\\begin{equation}\\label{CNN_iteration_vector}\n\tg^j=r^j\\circ g:  \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1} }\\mapsto\n\t\\mathbb  \\mathbb R^{\\hat c_j \\times \\hat n_{j} \\times \\hat n_j }, \\quad j  = 1:J. \n\t\\end{equation}\n\t\n\tAt last get \\eqref{CNN_stride_iteration_vector} as:\n\t\\begin{equation}\\label{CNN_stride_iteration_vector_1}\n\tf^j(x,\\Theta^j) = (C^j \\circ g^j\\circ f^{j-1})(x,\\Theta^{j-1}) \\in \\mathbb{R}^{c_j \\times n_j \\times n_j }\n\t\\end{equation}\n\t\n\t\n\t\\bigskip \\hrule \\bigskip  \n\t\n\t\\item {\\color{red} For $S^j \\circ \\theta^j\\circ r^j\\circ g$ form,} we can note stride, convolution and pooling together:\n\t\n\t\\bigskip \\hrule \\bigskip  \n\tWe consider ``stride-convolution-pooling'' functions:\n\t\\begin{equation}\\label{CNN_iteration_vector}\n\t\\theta^j=S^j\\circ \\theta^j \\circ r^j:  \\mathbb R^{c_{j-1} \\times \\tilde n_{j-1} \\times\\tilde n_{j-1} }\\mapsto\n\t\\mathbb  \\mathbb R^{c_j \\times \\tilde n_{j} \\times \\tilde n_j }, \\quad j  = 1:J. \n\t\\end{equation}\n\t\n\tAt last get \\eqref{CNN_stride_iteration_vector} as:\n\t\\begin{equation}\\label{CNN_stride_iteration_vector_2}\n\tf^j(x,\\Theta^j) = (\\theta^j \\circ g\\circ f^{j-1})(x,\\Theta^{j-1}) \\in \\mathbb{R}^{c_j \\times n_j \\times n_j }\n\t\\end{equation}\n\t\\bigskip \\hrule \\bigskip  \n\t\n\t\n\t\n\t\\item {\\color{red} For $\\theta^j\\circ r^j\\circ g \\circ S^{j-1} $ form:} We can note stride with nonlinear layer together:\n\t\\bigskip \\hrule \\bigskip  \n\tWe consider ``stride-pooled-activation'' functions:\n\t\\begin{equation}\\label{CNN_iteration_vector}\n\tg^j=r^j\\circ g \\circ S^{j-1}:  \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1} }\\mapsto\n\t\\mathbb  \\mathbb R^{\\hat c_j \\times \\hat n_{j} \\times \\hat n_j }, \\quad j  = 1:J. \n\t\\end{equation}\n\t\n\tAt last get \\eqref{CNN_stride_iteration_vector} as:\n\t\\begin{equation}\\label{CNN_stride_iteration_vector_2}\n\tf^j(x,\\Theta^j) = (\\theta^j \\circ g^j\\circ f^{j-1})(x,\\Theta^{j-1}) \\in \\mathbb{R}^{c_j \\times n_j \\times n_j }\n\t\\end{equation}\n\t\\bigskip \\hrule \\bigskip  \n\t\n\\end{enumerate}\n\n\\subsubsection{Merge stride into $\\theta^j$}\nBesides this,  we can merge stride into convolution as:\n\\begin{equation}\n\\theta^j: \\mathbb R^{\\hat c_j \\times \\hat{n}_{j} \\times \\hat n_{j} } \\mapsto \\mathbb{R}^{c_j \\times n_{j} \\times n_j }.\n\\end{equation}\nwith\n\\begin{equation}\n\\theta^j(x) = K^j \\circledast_{s^j} x + {\\rm{diag}(b^j)} \\cdot \\bm{1}_{c_j \\times n_j \\times n_j} \\quad\n\\in\\mathbb R^{c_j\\times n_j\\times n_j}.\n\\end{equation}\nwith \n\\begin{equation}\nK^j \\in \\mathbb{R}^{ c_{j} \\times \\hat c_{j} \\times (2k+1) \\times (2k+1)},  \\quad \\text{and} \\quad b^j \\in \\mathbb{R}^{c_j},\n\\end{equation}\nand \n\\begin{equation}\n\\bm{1}_{c_j \\times n_j \\times n_j} = 1_{c_{j}} \\otimes 1_{n_j} \\otimes 1_{n_j}\n\\end{equation}\nfor $k = 0, 1, 2, 3...$.\n\nGive $p\\in \\{1,\\ldots c_j\\}$\n\\begin{equation}\n(\\theta^j(x))_p= (K^j \\circledast_{s^j} x)_p+b^j_p{\\bm 1}_{n_j\\times n_j}\n\\end{equation}\nand\n\\begin{equation}\n(K^j \\circledast_{s^j} x)_p\n= \\sum_{q=1}^{\\hat c_{j}} K^{j}_{p,q} \\ast_{s^j} x_q \\in \\mathbb{R}^{n_j \\times n_j}, \\quad p= 1:c_j.\n\\end{equation}\nwhere\n$$\nK^{j}_{p,q}\\in \\mathbb R^{(2k+1)\\times (2k+1)}, x_q\\in \\mathbb\nR^{\\hat n_{j}\\times \\hat n_{j}}.\n$$\nHere $\\ast_{s^j}$ is the stander convolution with stride as definition before.\n\n\nAt last, we keep \\eqref{CNN_stride_iteration_vector} unchanged. What's more, we can have the next relation:\n\\begin{equation}\nn_j = \\frac{\\hat n_j}{s^j}.\n\\end{equation}\n \n\n\n\n\\newpage\n\\subsection{Restriction: a combination of pooling and stride}\nHere we consider as our restriction function as:\n\\begin{equation}\nr(x) = sC(x) + nN(x),\n\\end{equation}\nwith combination parameters $s, n \\in \\mathbb R$, and $N(x)$ is the traditional pooling function like $\\ell^{p}$ normal with $p = 1$ or $p = \\infty$. However, we define $C(x)$ as an extension version of traditional ``convolution with stride\" operation like:\n\\begin{equation}\n(C(x))_{i,j} = \\sum_{s,t = -k}^{k}K_{i,j,s,t}x_{pi + s, pj + t}.\n\\end{equation}\nOr we may have this version for multi-channel:\n\\begin{equation}\n(C(x))_{l,i,j} = \\sum_{m=1}^c\\sum_{s,t = -k}^{k}K_{l,m,i,j,s,t}x_{m,pi + s, pj + t}.\n\\end{equation}\nSo we will have that:\n\\begin{equation}\nC(x) = X \\ast_p K = S(X\\ast K, p),\n\\end{equation}\nif we take \n\\begin{equation}\nK_{i,j} = K_{\\tilde i, \\tilde j} \\in \\mathbb R^{(2k+1) \\times (2k+1)}\\quad  \\forall i, j, \\tilde i, \\tilde j,\n\\end{equation}\nor \n\\begin{equation}\nK_{l,m,i,j} = K_{l,m,\\tilde i, \\tilde j} \\in \\mathbb R^{(2k+1) \\times (2k+1)}\\quad  \\forall i, j, \\tilde i, \\tilde j.\n\\end{equation}\n\nThis means that $r(x)$ can totally cover the traditional ``convolution with stride\" operation, so we can have the next network structure:\n\n\\begin{enumerate}\n\t\n\t\\item Convolution: \n\t\\begin{equation}\n\t\\theta^j: \\mathbb R^{\\hat c_j \\times \\hat{n}_{j} \\times \\hat n_{j} } \\mapsto \\mathbb{R}^{c_j \\times n_{j} \\times n_j }.\n\t\\end{equation}\n\twith\n\t\\begin{equation}\n\t\\theta^j(x) = K^j \\circledast x + {\\rm{diag}(b^j)} \\cdot \\bm{1}_{c_j \\times n_j \\times n_j} \\quad\n\t\\in\\mathbb R^{c_j\\times n_j\\times n_j}.\n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\tK^j \\in \\mathbb{R}^{ c_{j} \\times \\hat c_{j} \\times (2k+1) \\times (2k+1)},  \\quad \\text{and} \\quad b^j \\in \\mathbb{R}^{c_j},\n\t\\end{equation}\n\tand \n\t\\begin{equation}\n\t\\bm{1}_{c_j \\times n_j \\times n_j} = 1_{c_{j}} \\otimes 1_{n_j} \\otimes 1_{n_j}\n\t\\end{equation}\n\tfor $k = 0, 1, 2, 3...$.\n\t\n\t\\item Activation: \n\t\\begin{equation}\\label{CNN_iteration_vector}\n\tg: \\mathbb R^{c_{j-1} \\times  n_{j-1} \\times   n_{j-1} }\\mapsto  \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1}},\n\t\\end{equation}\n\t\n\t\n\t\\item Restriction: \n\t\\begin{equation}\n\tr^j: \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1} }\\mapsto  \\mathbb R^{\\hat c_j \\times \\hat n_{j} \\times\\hat n_j }.\\end{equation}\n\twith\n\t\\begin{equation}\n\tr^j(x) = s^j C^j(x) + n^j N^j(x).\n\t\\end{equation}\n\t\n\\end{enumerate}\n\nWe consider ``restriction-activation'' functions:\n\\begin{equation}\\label{CNN_iteration_vector}\ng^j=r^j\\circ g:  \\mathbb R^{c_{j-1} \\times n_{j-1} \\times n_{j-1} }\\mapsto\n\\mathbb  \\mathbb R^{\\hat c_j \\times \\hat n_{j} \\times \\hat n_j }, \\quad j  = 1:J. \n\\end{equation}\n\nSo we have the CNN model  as:\n\\begin{equation}\\label{CNN_iteration_vector}\nf^j(x,\\Theta^j) = (\\theta^j\\circ g^{j}\\circ f^{j-1})(x,\\Theta^{j-1}) \\in \\mathbb{R}^{c_j \\times n_j \\times n_j }\n\\end{equation}\nwhere\n\\begin{equation}\n\\Theta^j=(\\Theta^{j-1},\\theta^j), \\quad \\Theta^0=\\theta^0 \n\\end{equation}\nwith \n\\begin{equation}\nf^0(x)=\\theta^0(x)\n\\end{equation}\nand \n\\begin{equation}\\label{CNN_finallayer}\nf(x; \\Theta) = f^J.\n\\end{equation}\n\nSo we can have the next observation: \n\\begin{enumerate}\n\t\\item We can totally recover the traditional CNN model with just general pooling by \n\t\\begin{equation}\n\ts^j = 0 \\quad \\forall j = 1:J.\n\t\\end{equation}\n\t\n\t\\item We can also totally recover the traditional CNN model with stride $p$ by\n\t\\begin{equation}\n\tn^j = 0 \\quad \\forall j = 1:J,\n\t\\end{equation}\n\tand \n\t\\begin{equation}\n\t\\theta^j = id,\n\t\\end{equation}\n\tif $C^j$ works as an restriction really.\n\t\n\t\\item If we keep $s^j$ and $n^j$ as two parameters to learn, we believe that this will be better than cases. \n\\end{enumerate}\nLet us consider a special case:\n\\begin{equation}\nf^4=\\theta^4\\circ g^4\\circ\\theta^3\\circ g^3\\circ \\theta^2\\circ g^2\\circ\\theta^1\\circ g^1\\circ\\theta_0(x)  \n\\end{equation}\nWe can regroup the different operations in different way.\n\\begin{equation}\nf^4=\\theta^4\\circ r^4\\circ g\\circ\\theta^3\\circ r^3\\circ g\\circ\n\\theta^2\\circ r^2\\circ g\\circ\\theta^1\\circ r^1\\circ g\\circ\\theta_0(x)\n\\end{equation}\n\nSpecial case 1: assuming $r^k$ represents pure stride \n\\begin{equation}\nf^4=\\theta^4\\circ g\\circ r^3\\circ g\n\\circ r^2\\circ g\\circ r^1\\circ g\\circ\\theta_0(x)\n\\end{equation}\nThis case seems to ``recover'' max-pooling somehow. \n\nSpecial case 2: assuming $r^k$ represents pure pooling\n\\begin{equation}\nf^4=\\theta^4\\circ g\\circ\\theta^3\\circ r^3\\circ g\\circ\n\\theta^2\\circ r^2\\circ g\\circ\\theta^1\\circ r^1\\circ g\\circ\\theta_0(x)\n\\end{equation}\n\n\n\\section{Some examples of CNN model for image classification}\nWe consider the MNIST database of handwritten digits, available from\nthe following page:\n\\begin{center}\n\t{\\tt http://yann.lecun.com/exdb/mnist/}\n\\end{center}\n\n\\subsection{An example for MNIST}\nFor MNIST, $\\hat n_0 = n = 28$, $\\hat c_0 = 1$ and $c = 10$. Here we construct a\nmodel with $f(x; \\Theta) = f^5$.\n\nFor simple, we set kernel size as $3 \\times 3$ always, namely $k=1$.  \n\\begin{enumerate}\n\t\\bigskip \\hrule \\bigskip  \n\t\\item Here $\\hat c_0 = 1$, we can set $c_0 = 4$, which means:\n\t\\begin{equation}\n\t\\theta^0 : \\mathbb R^{1\\times 28 \\times 28} \\to \\mathbb R^{4 \\times 28 \\times28},\n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\t\\theta^0(x) = K^0 \\circledast x + {\\rm{diag}(b^0) }\\cdot \\bm{1} \\quad (\\in\n\t\\mathbb R^{4\\times 28\\times 28})\n\t\\end{equation}\n\twhere \n\t$$\n\tK^0 \\in R^{4 \\times 1 \\times 3 \\times 3}, \\quad b^0 \\in \\mathbb R^{4}\n\t$$\n\t$$\n\t\\rm{diag}(b^0) \n\t\\in \\mathbb R^{6\\times 6}\n\t$$\n\tand \n\t\\begin{equation}\n\t(K^0 \\circledast x)_p = \\sum_{q = 1}^{\\hat c_0 = 1} K^0_{p,q}\\ast x \\in \\mathbb R^{28 \\times 28}, \\quad p = 1:c_0\n\t\\end{equation}\n\twith \n\t$$\n\tK^0_{p,q} \\in \\mathbb R^{3 \\times 3} \\quad p = 1:c_0, q = 1:1 .\n\t$$\n\tSo we have:\n\t\\begin{equation}\n\tf^0 = \\theta^0( x)  \\in \\mathbb R^{4 \\times 28 \\times 28}.\n\t\\end{equation}\n\t\n\t\\bigskip \\hrule \\bigskip  \n\t\\bigskip \\hrule \\bigskip  \n\t\n\t\\item Then we apply activation function $g = \\tau : \\mathbb R^{4 \\times 28 \\times 28} \\mapsto \\mathbb R^{4 \\times 28 \\times 28} $ and keeping the size.  Here we just take $r^1 = id$.\n\t\n\tSo we have, $\\hat c_1 = c_0 = 4$, but $\\hat n_2 = { n_1} = 28$, i.e\n\t\\begin{equation}\n\tg^1: \\mathbb R^{4 \\times 28 \\times 28} \\mapsto \\mathbb R^{4\\times 28 \\times 28}.\n\t\\end{equation}\n\t\n\t\\item Here $\\hat c_1 = c_0 = 4$, we can set $c_1 = 6$, so we have:\n\t\\begin{equation}\n\t\\theta^1 : \\mathbb R^{4\\times 28 \\times 28} \\to \\mathbb R^{6 \\times 28 \\times28},\n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\t\\theta^1(x) = K^1 \\circledast x + {\\rm{diag}(b^1)} \\cdot \\bm{1} \\quad (\\in\n\t\\mathbb R^{6\\times 28\\times 28})\n\t\\end{equation}\n\twhere \n\t$$\n\tK^1 \\in R^{6 \\times 4 \\times 3 \\times 3}, \\quad b^1 \\in \\mathbb R^{6}\n\t$$\n\t$$\n\t\\rm{diag}(b^1) \n\t\\in \\mathbb R^{6\\times 6}\n\t$$\n\tand \n\t\\begin{equation}\n\t(K^1 \\circledast x)_p = \\sum_{q = 1}^{\\hat c_1 = 4} K^1_{p,q}\\ast x \\in \\mathbb R^{28 \\times 28}, \\quad p = 1:6\n\t\\end{equation}\n\twith \n\t$$\n\tK^1_{p,q} \\in \\mathbb R^{3 \\times 3} \\quad p = 1: c_1, ~  q = 1: \\hat c_1 .\n\t$$\n\tSo we have \n\t\\begin{equation}\n\tf^1 = \\theta^1( g^1(f^0))  \\in \\mathbb R^{6 \\times 28 \\times 28}.\n\t\\end{equation}\n\t\n\t\\bigskip \\hrule \\bigskip  \n\t\\bigskip \\hrule \\bigskip  \n\t\\item For this layer, we also apply $g = \\tau$, however we apply pooling function $r^2: \\mathbb R^{6 \\times 28 \\times 28} \\mapsto \\mathbb R^{6 \\times 14 \\times14} $ with fix-position pooling:\n\t$$\n\tr^1(X)_{i,j} = X_{2i, 2j}, \\quad  i, j = 1:14.\n\t$$ \n\tor max pooling:\n\t$$\n\tr^1(X)_{i,j} = \\max_{-1 \\le k,l \\le 0}X_{2i+k, 2j+l}, \\quad i , j = 1:14.\n\t$$\n\tHere, we can take max-pooling. \n\t\n\tSo we have, $\\hat c_2 = c_1 = 6$, but $\\hat n_2 = \\frac{ n_1}{2} = 14$, i.e\n\t\\begin{equation}\n\tg^2: \\mathbb R^{6 \\times 28 \\times 28} \\mapsto \\mathbb R^{6\\times 14 \\times 14}.\n\t\\end{equation}\n\t\n\t\\item Here $\\hat c_2 = 6$ and $\\hat n_2 = 28$, we may also set $c_2 = 6$, so we have parameters \n\t$$\n\tK^2 \\in \\mathbb R^{6 \\times 6 \\times 3 \\times 3},\\quad b^2 \\in \\mathbb R^{6}\n\t$$\n\tthen we have \n\t\\begin{equation}\n\t\\theta^2: \\mathbb R^{6 \\times 14 \\times 14} \\mapsto \\mathbb R^{6 \\times 14 \\times 14}.\n\t\\end{equation}\n\tNote $y = g^2 (f^1)$ so we have,\n\t\\begin{equation}\n\t\\theta^2(y) = K^2 \\circledast y + {\\rm{diag}(b^2)} \\cdot \\bm{1}, \n\t\\end{equation}\n\tand \n\t\\begin{equation}\n\t(K^2 \\circledast y)_p = \\sum_{q = 1}^{\\hat c_2 = 6} K^2_{p,q} \\ast y_q \\in \\mathbb R^{14 \\times 14}, \\quad p = 1:6\n\t\\end{equation}\n\twith \n\t$$\n\tK^2_{p,q} \\in \\mathbb R^{3 \\times 3},\\quad p = 1:6, q = 1:6.\n\t$$\n\tSo we have the out put for the second layer as:\n\t\\begin{equation}\n\tf^2 = \\theta^2(g^2(f^1)) \\in \\mathbb R^{6 \\times 14 \\times 14}.\n\t\\end{equation}\n\t\n\t\\bigskip \\hrule \\bigskip  \n\t\\bigskip \\hrule \\bigskip  \n\t\\item For this layer, we also apply $g = \\tau$, then apply pooling function $r^3: \\mathbb R^{6 \\times 14 \\times 14} \\mapsto \\mathbb R^{6 \\times 7 \\times 7} $ with $r^3$ as max-pooling.\n\t\n\tSo we have, $\\hat c_3 = c_2 = 6$, but $\\hat n_3 = \\frac{ n_2}{2} = 7$, i.e\n\t\\begin{equation}\n\tg^2: \\mathbb R^{6 \\times 14 \\times 14} \\mapsto \\mathbb R^{6\\times 7 \\times 7}.\n\t\\end{equation}\n\t\n\t\n\t\\item Here $\\hat c_3 = 6$ and $\\hat n_3 = 7$, we may also set $c_3 = 8$, so we have parameters \n\t$$\n\tK^3 \\in \\mathbb R^{8 \\times 6 \\times 3 \\times 3},\\quad b^3 \\in \\mathbb R^{8}\n\t$$\n\tthen we have \n\t\\begin{equation}\n\t\\theta^3: \\mathbb R^{6 \\times 14 \\times 14} \\mapsto \\mathbb R^{8 \\times 14 \\times 14}.\n\t\\end{equation}\n\tNote $y = g^3 (f^2)$ so we have,\n\t\\begin{equation}\n\t\\theta^3(y) = K^3 \\circledast y + {\\rm{diag}(b^3)} \\cdot \\bm{1}, \n\t\\end{equation}\n\tand \n\t\\begin{equation}\n\t(K^3 \\circledast y)_p = \\sum_{q = 1}^{\\hat c_3 = 6} K^3_{p,q} \\ast y_q \\in \\mathbb R^{14 \\times 14}, \\quad p = 1:8\n\t\\end{equation}\n\twith \n\t$$\n\tK^3_{p,q} \\in \\mathbb R^{3 \\times 3},\\quad p = 1:8, q = 1:6.\n\t$$\n\tSo we have the out put for the second layer as:\n\t\\begin{equation}\n\tf^3 = \\theta^3(g^3(f^2)) \\in \\mathbb R^{8 \\times 7 \\times 7}.\n\t\\end{equation}\n\t\n\t\n\t\\bigskip \\hrule \\bigskip  \n\t\\bigskip \\hrule \\bigskip\n\t\\item For this layer, we also apply $g = \\tau$, then apply pooling function $r^4: \\mathbb R^{8 \\times 14 \\times 14} \\mapsto \\mathbb R^{8 \\times 7 \\times 7} $ with $r^3$ as max-pooling.\n\t\n\tSo we have, $\\hat c_4 = c_3 = 8$, but $\\hat n_4 =  n_3 = 7$, i.e\n\t\\begin{equation}\n\tg^4: \\mathbb R^{8 \\times 7\\times 7} \\mapsto \\mathbb R^{8 \\times 7 \\times 7}.\n\t\\end{equation}\n\t\n\t\\item {\\bf Here we reshape $g^4(f^3) \\in \\mathbb R^{8 \\times 7 \\times 7}$ as a vector in $\\mathbb{R}^{392}$.}\n\t\n\t\\item Let $y = \\rm{Vec}(g^4(f^3))$, for this layer, we apply the fully connected(general DNN model) for $y$ with:\n\t\\begin{equation}\n\t\\theta^4: \\mathbb{R}^{392} \\to \\mathbb R^{100},\n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\t\\theta^4(y) = W^4 y + b^4,\n\t\\end{equation}\n\there \n\t\\begin{equation}\n\tW^4 \\in \\mathbb{R}^{100\\times 392}, \\quad b^4 \\in \\mathbb{R}^{100}.\n\t\\end{equation}\n\t\n\tSo we have the out put for the fifth layer as:\n\t\\begin{equation}\n\tf^4 = \\theta^4(g^4(f^3)) \\in \\mathbb{R}^{100}.\n\t\\end{equation}\n\t\n\t\\bigskip \\hrule \\bigskip  \n\t\\bigskip \\hrule \\bigskip\n\t\\item For this layer, we also apply $g = \\tau$, and $r^5 = id$, so $g^{5}(f^4) \\in \\mathbb{R}^{100}$.\n\t\n\t\\item Then let's set $n_5 = c =  10$, and let $y = g^5(f^5)$  i.e \n\t\\begin{equation}\n\t\\theta^5: \\mathbb{R}^{100} \\to \\mathbb R^{10},\n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\t\\theta^5(y) = W^5 y + b^5,\n\t\\end{equation}\n\there \n\t\\begin{equation}\n\tW^5 \\in \\mathbb{R}^{10\\times 100}, \\quad b^5 \\in \\mathbb{R}^{10}.\n\t\\end{equation}\n\tSo we have the out put for the fifth layer as:\n\t\\begin{equation}\n\tf^5 = \\theta^5(g^5(f^4)) \\in \\mathbb{R}^{10}.\n\t\\end{equation}\n\t\n\\end{enumerate}\n\n\\begin{remark}\n\tI guess, this model cannot work very well because of little channels.\n\\end{remark}\n\\bigskip \\hrule \\bigskip\n\n\n\n\\subsection{LeNet-5 for MNIST}\nThis section is devoted to a model that is widely recognized as the\nfirst successful convolutional neural network: LeNet-5\n\\cite{Lecun1998Gradient}. In this section, we will introduce\nconvolutional neural network via introducing LeNet-5 by explain every\nsteps for LeNet-5.  Figure \\ref{LeNet-5} shows an illustration of the\narchitecture of LeNet-5. It consists of two pairs of Convolutional\nLayer and Subsampling Layer and is further connected with fully\nconnected layer and an RBF layer for classification.\n\n\n\\begin{figure}[!htb]\n\t\\center{\\includegraphics[width=10cm] {figures/LeNet-5.png}}        \n\t\\caption{The Architecture of LeNet-5}      \n\t\\label{LeNet-5}\n\\end{figure}\n%\\begin{figure}[htb]        \n%\t\\center{\\includegraphics[width=10cm] {AlexNet.png}}        \n%\t\\caption{AlexNet}      \n%\\end{figure}\n\n\\begin{itemize}\n\t\\item First of all, the input for LeNet-5 is digital picture with size $32 \\times 32$ which every picture contains a number written by different writers. So, mathematically speaking, $x$ is a order 2 tensor with just one channel, with essential size $32 \\times 32$, i.e $x \\in \\mathbb{R}^{ 1 \\times 32 \\times 32 }$.  And the out put is a 10-dimensional vector $\\bm y = (y_0, \\cdots, y_9)$ with $y_i$ equal to the probability for the number in $x$ is $i$. \n\t\n\t\\bigskip \\hrule \\bigskip\n\t\\item Input: $x \\in  \\mathbb{R}^{ 1 \\times 32 \\times 32}$,  i.e \n\t\\begin{equation}\n\t\\hat c_0 = 1, \\quad \\hat n_0 = 32.\n\t\\end{equation}\n\t\n\t\\item  $x \\xrightarrow{\\text{Convolution} ( \\theta^0)} f^0$: \n\t\\begin{equation}\n\t\\theta^0: \\mathbb R^{1 \\times 32 \\times 32} \\to \\mathbb R^{6 \\times 28 \\times 28},\n\t\\end{equation}\n\tie.\n\t\\begin{equation}\n\tc_0 = 6, \\quad K^0 \\in \\mathbb R^{6 \\times 1 \\times 5 \\times 5}, \\quad b^0 \\in \\mathbb{R}^6.\n\t\\end{equation}\n\tSo we have the out put for the first layer as:\n\t\\begin{equation}\n\tf^0 = \\theta^0(x) \\in \\mathbb{R}^{6 \\times 28 \\times 28}.\n\t\\end{equation}\n\t\n\t\\bigskip \\hrule \\bigskip\n\t\\item $f^0 \\xrightarrow{\\text{ReLU}(g) + \\text{Pooling}(r^1)} y$: \\\\\n\t\\begin{equation}\n\tg = \\tau \n\t\\end{equation}\n\tand $r^1: \\mathbb R^{6 \\times 28 \\times 28} \\mapsto \\mathbb R^{6 \\times 14 \\times 14} $ with max-pooling.\n\tSo\n\t\\begin{equation}\n\ty = g^1(f^0) \\in \\mathbb R^{6 \\times 14 \\times 14}.\n\t\\end{equation}\n\t\n\t\\item $y \\xrightarrow{\\text{Convolution}(\\theta^1)} f^1$:\n\t\\begin{equation}\n\t\\theta^1: \\mathbb R^{6 \\times 14 \\times 14} \\to \\mathbb R^{16 \\times 10 \\times 10},\n\t\\end{equation}\n\tie.\n\t\\begin{equation}\n\tc_1 = 16, \\quad K^1 \\in \\mathbb R^{16 \\times 6 \\times 5 \\times 5}, \\quad b^1 \\in \\mathbb{R}^{16}.\n\t\\end{equation}\n\tSo we have the out put for the first layer as:\n\t\\begin{equation}\n\tf^1 = \\theta^1(g^1(f^0)) \\in \\mathbb{R}^{16 \\times 10 \\times 10}.\n\t\\end{equation}\n\t\n\t\n\t\\bigskip \\hrule \\bigskip\n\t\\item $f^1 \\xrightarrow{\\text{ReLU}(g) + \\text{Pooling}(r^2)} y$: \n\t\\begin{equation}\n\tg = \\tau \n\t\\end{equation}\n\tand $r^2: \\mathbb R^{16 \\times 10 \\times 10} \\mapsto \\mathbb R^{16 \\times 5 \\times 5} $ with max-pooling.\n\tSo\n\t\\begin{equation}\n\ty = g2^(f^1) \\in \\mathbb R^{16 \\times 5 \\times 5}.\n\t\\end{equation}\n\t\n\t\\item {\\bf Here we reshape $ y = g^2(f^1) \\in \\mathbb R^{16 \\times 5 \\times 5}$ as a vector in $\\mathbb{R}^{400}$.}\n\t\n\t\\item $y \\xrightarrow{\\text{affine map}(\\theta^2) }f^3$: \n\t\\begin{equation}\n\t\\theta^2: \\mathbb R^{400} \\to \\mathbb R^{120},\n\t\\end{equation}\n\tie.\n\twith \n\t\\begin{equation}\n\t\\theta^2(y) = W^2 y + b^2,\n\t\\end{equation}\n\there \n\t\\begin{equation}\n\tW^2 \\in \\mathbb{R}^{120\\times 400}, \\quad b^5 \\in \\mathbb{R}^{120}.\n\t\\end{equation}\n\tSo we have the out put for the fifth layer as:\n\t\\begin{equation}\n\tf^2 = \\theta^2(g^2(f^1)) \\in \\mathbb{R}^{120}.\n\t\\end{equation}\n\t\n\t\n\t\\bigskip \\hrule \\bigskip\n\t\\item $f^2 \\xrightarrow{\\text{ReLU}(g) + \\text{Pooling}(r^3)} y$: \n\t\\begin{equation}\n\tg = \\tau \n\t\\end{equation}\n\tand $r^3 = id$.\n\t\n\t\\item $y \\xrightarrow{\\text{affine map}(\\theta^3)} f^3$: \n\t\\begin{equation}\n\t\\theta^3: \\mathbb R^{120} \\to \\mathbb R^{84},\n\t\\end{equation}\n\tie.\n\twith \n\t\\begin{equation}\n\t\\theta^3(y) = W^3 y + b^3,\n\t\\end{equation}\n\there \n\t\\begin{equation}\n\tW^2 \\in \\mathbb{R}^{84\\times 120}, \\quad b^3 \\in \\mathbb{R}^{84}.\n\t\\end{equation}\n\tSo we have the out put for the fifth layer as:\n\t\\begin{equation}\n\tf^3 = \\theta^3(g^3(f^2)) \\in \\mathbb{R}^{84}.\n\t\\end{equation}\n\t\n\t\n\t\\bigskip \\hrule \\bigskip\n\t\\item $f^3 \\xrightarrow{\\text{ReLU}(g) + \\text{Pooling}(r^4)} y$: \n\t\\begin{equation}\n\tg = \\tau \n\t\\end{equation}\n\tand $r^4 = id$.\n\t\n\t\\item $y \\xrightarrow{\\text{affine map}(\\theta^4)} f^4$: \n\t\\begin{equation}\n\t\\theta^4: \\mathbb R^{84} \\to \\mathbb R^{10},\n\t\\end{equation}\n\tie.\n\twith \n\t\\begin{equation}\n\t\\theta^4(y) = W^4 y + b^4,\n\t\\end{equation}\n\there \n\t\\begin{equation}\n\tW^4 \\in \\mathbb{R}^{10\\times 84}, \\quad b^4 \\in \\mathbb{R}^{84}.\n\t\\end{equation}\n\tSo we have the out put for the fifth layer as:\n\t\\begin{equation}\n\tf^4 = \\theta^4(g^4(f^2)) \\in \\mathbb{R}^{10}.\n\t\\end{equation}\n\t\n\t\\bigskip \\hrule \\bigskip\n\t\\item $f^4 \\xrightarrow{\\text{ReLU}(g) + \\text{Pooling}(r^5)} y$: \n\t\\begin{equation}\n\tg = \\tau \n\t\\end{equation}\n\tand $r^5 = id$.\n\t\n\t\\item $y \\xrightarrow{\\text{affine map}(\\theta^5)} f^5$: \n\t\\begin{equation}\n\t\\theta^5: \\mathbb R^{10} \\to \\mathbb R^{10},\n\t\\end{equation}\n\tie.\n\twith \n\t\\begin{equation}\n\t\\theta^5(y) = W^5 y + b^4,\n\t\\end{equation}\n\there \n\t\\begin{equation}\n\tW^5 \\in \\mathbb{R}^{10\\times 10}, \\quad b^4 \\in \\mathbb{R}^{10}.\n\t\\end{equation}\n\tSo we have the out put for the fifth layer as:\n\t\\begin{equation}\n\tf^5 = \\theta^5(g^5(f^4)) \\in \\mathbb{R}^{10}.\n\t\\end{equation}\n\\end{itemize}\n\\bigskip \\hrule \\bigskip\n\n\\begin{remark}\n\tThe real LeNet-5 have two different structure with above $f^5$.\n\t\\begin{enumerate}\n\t\t\\item The structure for $\\theta^1$ is a little special with they will fix some kernel as zeros such as:\n\t\t\\begin{equation}\n\t\tK^1_{1,4:6} = 0\n\t\t\\end{equation}\n\t\tand this structure can be found in the next figure:\n\t\t\\begin{figure}[!htb]\\label{LeNet-Channel}\n\t\t\t\\center{\\includegraphics[width=10cm] {figures/LeNet-Channel.png}}        \n\t\t\t\\caption{The ``0\" Pattern for Channel Dimension of $K_{2,i}$}      \n\t\t\\end{figure}\n\t\t\n\t\t\\item The real out put is:\n\t\t\\begin{equation}\n\t\tf^5 = f_{softmax}(g^5(f^4)).\n\t\t\\end{equation}\n\t\\end{enumerate}\n\t\n\t\n\\end{remark}\n\n\n\n\\subsection{An example of CNN model for Cifar-10}\nWe consider the data base CIFAR-10:\n\\begin{center}\n\t{\\tt https://www.cs.toronto.edu/~kriz/cifar.html}.  \n\\end{center}\n\nFor Cifar-10, $\\hat n_0 = n = 32$, $\\hat c_0 = 3$ and $c = 10$. Here we construct a\nmodel with $f(x; \\Theta) = f^4$.\n\nFor simple, we set kernel size as $3 \\times 3$ always, namely $k=1$.  \n\\begin{enumerate}\n\t\\bigskip \\hrule \\bigskip  \n\t\\item Here $\\hat c_0 = 3$, we can set $c_0 = 32$, which means:\n\t\\begin{equation}\n\t\\theta^0 : \\mathbb R^{2\\times 32 \\times 32} \\to \\mathbb R^{32 \\times 32 \\times32},\n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\t\\theta^0(x) = K^0 \\circledast x + {\\rm{diag}(b^0) }\\cdot \\bm{1} \\quad (\\in\n\t\\mathbb R^{32\\times 32\\times 32})\n\t\\end{equation}\n\twhere \n\t$$\n\tK^0 \\in R^{32 \\times 3 \\times 3 \\times 3}, \\quad b^0 \\in \\mathbb R^{32}\n\t$$\n\t$$\n\t\\rm{diag}(b^0) \n\t\\in \\mathbb R^{32\\times 32}\n\t$$\n\tand \n\t\\begin{equation}\n\t(K^0 \\circledast x)_p = \\sum_{q = 1}^{\\hat c_0 = 3} K^0_{p,q}\\ast x \\in \\mathbb R^{28 \\times 28}, \\quad p = 1:c_0\n\t\\end{equation}\n\twith \n\t$$\n\tK^0_{p,q} \\in \\mathbb R^{3 \\times 3} \\quad p = 1:c_0, q = 1:3 .\n\t$$\n\tSo we have:\n\t\\begin{equation}\n\tf^0 = \\theta^0( x)  \\in \\mathbb R^{32 \\times 32 \\times 32}.\n\t\\end{equation}\n\t\n\t\\bigskip \\hrule \\bigskip  \n\t\\bigskip \\hrule \\bigskip  \n\t\n\t\\item Then we apply activation function $g = \\tau : \\mathbb R^{32 \\times 32 \\times 32} \\mapsto \\mathbb R^{32 \\times 32 \\times 32} $ and keeping the size.  Here we just take $r^1 = id$.\n\t\n\tSo we have, $\\hat c_1 = c_0 = 32$, and $\\hat n_1 = { n_0} = 32$, i.e\n\t\\begin{equation}\n\tg^1: \\mathbb R^{32 \\times 32 \\times 32} \\mapsto \\mathbb R^{32\\times 32 \\times 32}.\n\t\\end{equation}\n\t\n\t\\item Here $\\hat c_1 = c_0 = 32$, we can still set $c_1 = 32$, so we have:\n\t\\begin{equation}\n\t\\theta^1 : \\mathbb R^{32\\times 32 \\times 32} \\to \\mathbb R^{32 \\times 32 \\times32},\n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\t\\theta^1(x) = K^1 \\circledast x + {\\rm{diag}(b^1)} \\cdot \\bm{1} \\quad (\\in\n\t\\mathbb R^{32\\times 32\\times 32})\n\t\\end{equation}\n\twhere \n\t$$\n\tK^1 \\in R^{32 \\times 32 \\times 3 \\times 3}, \\quad b^1 \\in \\mathbb R^{32}\n\t$$\n\t$$\n\t\\rm{diag}(b^1) \n\t\\in \\mathbb R^{32\\times 32}\n\t$$\n\tand \n\t\\begin{equation}\n\t(K^1 \\circledast x)_p = \\sum_{q = 1}^{\\hat c_1 = 32} K^1_{p,q}\\ast x \\in \\mathbb R^{28 \\times 28}, \\quad p = 1:32\n\t\\end{equation}\n\twith \n\t$$\n\tK^1_{p,q} \\in \\mathbb R^{3 \\times 3} \\quad p = 1: c_1, ~  q = 1: \\hat c_1 .\n\t$$\n\tSo we have \n\t\\begin{equation}\n\tf^1 = \\theta^1( g^1(f^0))  \\in \\mathbb R^{32 \\times 32 \\times 32}.\n\t\\end{equation}\n\t\n\t\\bigskip \\hrule \\bigskip  \n\t\\bigskip \\hrule \\bigskip  \n\t\\item For this layer, we also apply $g = \\tau$, however we apply pooling function $r^2: \\mathbb R^{32 \\times 32 \\times 32} \\mapsto \\mathbb R^{32 \\times 16 \\times16} $ with fix-position pooling:\n\t$$\n\tr^1(X)_{i,j} = X_{2i, 2j}, \\quad  i, j = 1:14.\n\t$$ \n\tor max pooling:\n\t$$\n\tr^1(X)_{i,j} = \\max_{-1 \\le k,l \\le 0}X_{2i+k, 2j+l}, \\quad i , j = 1:14.\n\t$$\n\tHere, we take max-pooling. \n\t\n\tSo we have, $\\hat c_2 = c_1 = 32$, but $\\hat n_2 = \\frac{ n_1}{2} = 16$, i.e\n\t\\begin{equation}\n\tg^2: \\mathbb R^{32 \\times 32 \\times 32} \\mapsto \\mathbb R^{32\\times 16 \\times 16}.\n\t\\end{equation}\n\t\n\t\\item Here $\\hat c_2 = 32$ and $\\hat n_2 = 14$, we may also set $c_2 = 64$, so we have parameters \n\t$$\n\tK^2 \\in \\mathbb R^{64 \\times 32 \\times 3 \\times 3},\\quad b^2 \\in \\mathbb R^{64}\n\t$$\n\tthen we have \n\t\\begin{equation}\n\t\\theta^2: \\mathbb R^{32 \\times 16 \\times 16} \\mapsto \\mathbb R^{64 \\times 16 \\times 16}.\n\t\\end{equation}\n\tNote $y = g^2 (f^1)$ so we have,\n\t\\begin{equation}\n\t\\theta^2(y) = K^2 \\circledast y + {\\rm{diag}(b^2)} \\cdot \\bm{1}, \n\t\\end{equation}\n\tand \n\t\\begin{equation}\n\t(K^2 \\circledast y)_p = \\sum_{q = 1}^{\\hat c_2 = 32} K^2_{p,q} \\ast y_q \\in \\mathbb R^{14 \\times 14}, \\quad p = 1:64\n\t\\end{equation}\n\twith \n\t$$\n\tK^2_{p,q} \\in \\mathbb R^{3 \\times 3},\\quad p = 1:64, q = 1:32.\n\t$$\n\tSo we have the out put for the second layer as:\n\t\\begin{equation}\n\tf^2 = \\theta^2(g^2(f^1)) \\in \\mathbb R^{64 \\times 16 \\times 16}.\n\t\\end{equation}\n\t\n\t\n\t\n\t\\bigskip \\hrule \\bigskip  \n\t\\bigskip \\hrule \\bigskip\n\t\\item For this layer, we also apply $g = \\tau$, then apply pooling function $r^3: \\mathbb R^{64 \\times 16\\times 16} \\mapsto \\mathbb R^{64 \\times 8 \\times 8} $ with $r^3$ as max-pooling.\n\t\n\tSo we have, $\\hat c_2 = c_1 = 64$, but $\\hat n_3 =  \\frac{n_2}{2} = 7$, i.e\n\t\\begin{equation}\n\tg^3: \\mathbb R^{64 \\times 16\\times 16} \\mapsto \\mathbb R^{64 \\times 8 \\times 8}.\n\t\\end{equation}\n\t\n\t\\item {\\bf Here we reshape $g^3(f^2) \\in \\mathbb R^{64 \\times 8 \\times 8}$ as a vector in $\\mathbb{R}^{4096}$.}\n\t\n\t\\item Let $y = \\rm{Vec}(g^3(f^3))$, for this layer, we apply the fully connected(general DNN model) for $y$ with:\n\t\\begin{equation}\n\t\\theta^3: \\mathbb{R}^{4096} \\to \\mathbb R^{120},\n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\t\\theta^3(y) = W^3 y + b^3,\n\t\\end{equation}\n\there \n\t\\begin{equation}\n\tW^3 \\in \\mathbb{R}^{120\\times 4096}, \\quad b^4 \\in \\mathbb{R}^{120}.\n\t\\end{equation}\n\t\n\tSo we have the out put for the fifth layer as:\n\t\\begin{equation}\n\tf^3 = \\theta^3(g^3(f^2)) \\in \\mathbb{R}^{120}.\n\t\\end{equation}\n\t\n\t\\bigskip \\hrule \\bigskip  \n\t\\bigskip \\hrule \\bigskip\n\t\\item For this layer, we also apply $g = \\tau$, and $r^4 = id$, so $g^{4}(f^3) \\in \\mathbb{R}^{120}$.\n\t\n\t\\item Then let's set $n_4 = c =  10$, and let $y = g^4(f^3)$  i.e \n\t\\begin{equation}\n\t\\theta^4: \\mathbb{R}^{120} \\to \\mathbb R^{10},\n\t\\end{equation}\n\twith \n\t\\begin{equation}\n\t\\theta^4(y) = W^4 y + b^4,\n\t\\end{equation}\n\there \n\t\\begin{equation}\n\tW^4 \\in \\mathbb{R}^{10\\times 120}, \\quad b^4 \\in \\mathbb{R}^{10}.\n\t\\end{equation}\n\tSo we have the out put for the fifth layer as:\n\t\\begin{equation}\n\tf^4 = \\theta^4(g^4(f^3)) \\in \\mathbb{R}^{10}.\n\t\\end{equation}\n\\end{enumerate}\n\n\n\\section{New notation for general DNN}\nMotivated by the ResNet model and the newly changed version for ResNet model, we may construct those next neural network notation for better understand about all kinds of DNN and CNN models.\n\n\nHere we want to reconstruct our notation for general DNN model with we proposed ``level\" not ``layer\" with we can construct some fake layers between two different levels. For general DNN model, the notation is totally same with we just replace layers as levels. But when we consider about the CNN model, we emphasize that the level index increase only after the essential dimension for the data changes.\n\n\\subsection{Stride and Pooling}\nHere we first reanalysis this two important operator in general CNN model, which change the essential dimension for data. Let us recall the definition of those two operator:\n\\begin{definition}{Stride}\n\t\\begin{equation}\n\tS(x_1, \\cdots, x_p) = x_q, \\quad  1 \\le q \\le p.\n\t\\end{equation}\n\\end{definition}\n\n\\begin{definition}{Pooling}\n\\begin{equation}\nP(x_1, \\cdots, x_p) = r(x_1, \\cdots, x_p),\n\\end{equation}\n\\end{definition}\nwhere $r$ is a nonlinear or linear restriction function.\n\nLet us recall where those two operation is used. In general, stride is used after the general convolution and the pooling is used after he nonlinear activation function.  Here we can also note pooling as before the convolution, so we can note the stride or pooling with general convolution together as:\n\\begin{equation}\\label{stride-pooling}\n\\tilde \\theta = \\theta \\circ S, \\quad \\text{or} \\quad \\tilde \\theta = P\\circ \\theta.\n\\end{equation}\n\\begin{remark}\n\tHere we can take $P = id$ such that $\\tilde \\theta$ can also work as the general convolution operator.\n\\end{remark}\n\n\\subsection{New Notation with Level Index}\n\nSo we have the next expression:\n\\begin{equation}\\label{new-dnn}\n\\begin{cases}\n\tf^j &= \\tilde \\theta^j\\circ \\mathcal{H}^j_{l_j} \\circ g(f^{j-1}), \\\\\n\tf^0 &= \\tilde \\theta^0(x).\n\\end{cases}\n\\end{equation}\nHere we note that, if $l_j = 0$ then $\\mathcal{H}^j_{l_j} = id$.\n\nHere $\\mathcal{H}^j_{l_j}$ works like the classical DNN model as people often used version for DNN:\n\\begin{equation}\n\t\\mathcal{H}_{l_j}^j (x) = g \\circ \\theta^{j,{l_j}}  \\cdots g \\circ \\theta^{j,{l_1}} (x),\n\\end{equation}\nhere we emphasize that $\\theta$ are all general convolutions.\n\n\n\n\\section{New notation on the same level $\\ell$}\nThis is analogous to the smoothings carried on each level.  But this\ntime, it is a sequence of nonlinear operations. \n\nInput $y$, and output $z$:\n$$\nz=H^\\ell(y)\n$$\nBased on the approximation theory, let us construct a basic nonlinear block for our net work as:\n\\begin{equation}\\label{eq1-basic}\nF_k(x) = \\xi^k \\circ g \\circ \\eta^k(x),\n\\end{equation}\n\\section{From level $\\ell$ to $\\ell+1$: restriction}\n\n\\begin{enumerate}\n\\item Input:  $f^\\ell$\n\\item output:  $f^{\\ell+1}_0 = R_{\\ell}^{\\ell+1}f^{\\ell}$\n\\end{enumerate}\n\nHere \n$$\n R_{\\ell}^{\\ell+1}: \\mathbb R^{n_\\ell}\\mapsto \\mathbb R^{n_{\\ell+1}}\n$$\ncan be given by either\n\\begin{enumerate}\n\\item pooling, or\n\\item convolution with stride.\n\\end{enumerate}\n\n\\section{Plain nets}\n\n\\subsection{Same level}\n$$\ny_1=F_1(y)\n$$\n$$\ny_{k+1}=F_k(y_{k})\n$$\n$$\nz=y_{m_\\ell}\n$$\nWe define\n$$\nH^\\ell(y)=y_{m_\\ell}.\n$$\n\nWe note that\n$$\nF_{k+1}(F_{k}(y_k))\n=(\\xi^{k+1} \\circ g \\circ \\eta^{k+1})[(\\xi^k \\circ g \\circ \\eta^k)(y_k)]\n=(\\xi^{k+1} \\circ g \\circ (\\eta^{k+1}\\xi^k)\\circ g \\circ\\eta^k)(y_k)\n$$\nIn the most general DNN, we can make the following combination:\n$$\n\\eta^{k+1}\\xi^k=\\tilde \\eta^k.\n$$\nBut in the context CNN, we may not simply do this combination?\n\n\\subsection{Multilevel}\n$$\nf^{\\ell+1}=H^{\\ell+1}\\circ (R_{\\ell}^{\\ell+1}f^\\ell)\n$$\n\n\\section{ResNet in this Notation}\n\\subsection{Same level}\n$$\ny_1=F_1(y)\n$$\n$$\ny_{k+1}=y_k+  F_k(y_{k})\n\\quad k=1,\\ldots m_\\ell-1.\n$$\n\n\\bigskip\n\\hrule  \nHere we note that, if the dimension is suitable we may have:\n\\begin{align}\nF_k(x) &= \\xi \\circ g \\circ  \\eta (x) = ( \\tilde \\xi - \\hat \\xi) \\circ g \\circ \\eta (x) \\\\\n&= \\tilde \\xi \\circ g \\circ \\eta (x) - \\hat \\xi \\circ g \\circ \\eta(x) \\\\\n&=  \\tilde \\xi \\circ g \\circ \\eta (x)  - x .\n\\end{align}\n\\hrule \n\\bigskip\n\n\\hrule \n\\bigskip \nIn the linear case, let $y$ be a given vector, if we apply a smoother,\nwe can have the following\n$$\ny_{k+1}=(I-\\omega A) y_k\n=y_k-\\omega A y_k\n$$\nIn this case, we can view\n$$\nF_k=-\\omega A.\n$$\n\\bigskip \n\\hrule \n\\bigskip\n\nIn the end,  the output is\n$$\nz=y_{m_\\ell}=y_1+\\sum_{j=2}^{m_\\ell} F_j(y_j)\n$$\nand\n$$\nf^\\ell=z.\n$$\n\\subsection{Multilevel}\n$$\nf^{\\ell+1}=H^{\\ell+1}\\circ (R_{\\ell}^{\\ell+1}f^\\ell)\n$$\n\nIn the original work of He Kaiming:\n$$\nf^{\\ell+1}=H^{\\ell+1}\\circ (R_{\\ell}^{\\ell+1}f^\\ell+P^\\ell y_{m_\\ell-1}^\\ell)\n$$\nNotice that\n$$\nR_{\\ell}^{\\ell+1}f^\\ell+P^\\ell y_{m_\\ell-1}^\\ell=\nR_{\\ell}^{\\ell+1}[F_{m_\\ell-1}(y_{m_\\ell-1}^\\ell)+ y_{m_\\ell-1}^\\ell]+P^\\ell y_{m_\\ell-1}^\\ell=\n$$\n\n\n\\section{Multiple coarse spaces: general CNN}\nThis notation originally was contained in $\\theta$ in the original\nnotations. But now, for better understand we are going to investigate\nthe structure for general $\\theta$ in CNN.\n\nLet us focus on level $\\ell$, the output of level $\\ell$ consists of\n$c_\\ell$ images:\n\\begin{equation}\n  \\label{Xl}\nX^\\ell_{j}:  j=1:c^\\ell.  \n\\end{equation}\nFor $\\ell=0$, we have\n$$\nc_0=\n\\left\\{\n  \\begin{array}{lr}\n1 & \\mbox{ grey}\\\\    \n3 & \\mbox{color}\n  \\end{array}\n\\right.\n$$\n$$\nc^{\\ell+1}_i: i=0,1,\\ldots m_{\\ell+1}\n$$\nwith \n$$\nc^{\\ell+1}_0=c_\\ell.\n$$\n\nAssume that $c^{\\ell+1}_{i}$ is known.   That we have the following\nnumber of images:\n$$\nX^{\\ell+1,i}_{j}:\\quad j=1:c^{\\ell+1}_i\n$$\nWe need to define\n$$\nX^{\\ell+1,i+1}_{j}:\\quad j=1:c^{\\ell+1}_{i+1}.\n$$\n\n$$\nX^{\\ell+1,i+1}_{j}=\ng\\bigg(\n\\sum_{k =1}^{c^{\\ell+1}_{i}}X_k^{\\ell, i}\\ast K^i_{j,k}\n\\bigg) \n$$\nThe final outcome is\n$$\nX^{\\ell+1}_{j}\\equiv \nX^{\\ell+1,m_{\\ell+1}}_{j}= \ng\\bigg(\n\\sum_{k =1}^{c^{\\ell+1}_{m_{\\ell+1}-1}}X_k^{\\ell, m_{\\ell+1}-1}\\ast K^{m_{\\ell+1}-1}_{j,k}\n\\bigg),\\quad  j=1:c^{\\ell+1}_{m_{\\ell+1}}.\n$$\n\nFor general CNN model to deal with the single channel image $X$, they first use some different $K_i$ to do smooth for $X$ in and get multiple smoothed image as $K_i \\ast x$ for $i = 1:c_0$ and do activation function for those multiple smoothed image and get $g(K^0_i \\ast X)$, like:\n\\bigskip\n\\hrule\nInput: $X$, output $\\tilde Y_i$:\n\\begin{equation}\n\\tilde Y_i = g(K^0_i \\ast X), \\quad i = 1:c_0\n\\end{equation}\n\\hrule\n\\bigskip\nThen the next operation is the most different and interesting operations in CNN which is different from the general pure convolution(smoother). Now we suppose to get just one channel image first for $Y_i$, they use\n\\bigskip\n\\hrule\nInput: $\\tilde Y_i$, output $Z$:\n\\begin{equation}\nZ = \\sum_{i=1}^{c_0} \\tilde Y_i \\ast K^1_i\n\\end{equation}\n\\hrule\n\n\n\\newpage\n\\subsection{Xu idea}\nHere we begin with a single channel image as $X \\in \\mathbb{R}^{n\\times n}$, now we state that Prof. Xu's idea can be implement by the general CNN convolution operation.  \n\\bigskip\n\\hrule\nInput: $X$, output $Y$:\n\\begin{equation}\nY = \\sum_{i=1}^c a_i g(K_i \\ast X),\n\\end{equation}\n\\hrule\n\\bigskip\n\nSo, as for now, if we take $K^1_i = a_i I$, then we have $Z = Y$ as Prof. Xu's idea. \n\nHere we can note that, in $Y$ level we have $\\tilde Y_i$ with $i=1:c$ multiple smoothed image or we say you have detected $c$ features from the $X$ level, so in $Z$ level we may also construct $i = 1:c_1$  multiple space to save those $c_1$ features, so what we do generally in CNN is:\n\\bigskip\n\\hrule\nInput: $\\tilde Y_i$, output $Z_j$:\n\\begin{equation}\nZ_j = \\sum_{i=1}^{c_0} \\tilde Y_i \\ast K^1_{i,j}, \\quad j = 1:c_1\n\\end{equation}\n\\hrule\n\\bigskip\n\nAnd after that, you can do the similar things like from $Y$ level to $Z$ level with multiple space operation. \n\n\\section{DenseNet in this notation}\n\\subsection{same level}\n\n$$\nH^{j}(x) = \\theta^j \\circ g \\circ BN\n$$\n$$\ny_{k+1}= H^{k}([y_k, y_{k-1},\\cdots, y_0]).\n\\quad k=1,\\ldots m_\\ell-1.\n$$\n\n\n\\newpage\n\\section{some other observations}\nNow let us think about that we have $X = (X_1, X_2, X_3)$ with $X_i \\in \\mathbb{R}^{n\\times n}$. That's to say now we have $3$ coarse space first, now we want to do some convolution or we say as smoother in AMG. Here we \n\nProf. Xu's idea is to say that, we need to keep the original ``channel\" parallel i.e we just need three kernels like \n\\begin{align}\n\tK_0 = \\begin{pmatrix}\n\t\tK^1 \\\\ K^2 \\\\ K^3\n\t\\end{pmatrix}.\n\\end{align} So we get:\n\\begin{equation}\nX \\to X\\tilde{\\ast} K_0 = (X_1 \\ast K^1, X_2\\ast K^2, X_3 \\ast T^3),\n\\end{equation}\nand then we apply the active function $a$ to $(X_1 \\ast K^1, X_2\\ast K^2, X_3 \\ast T^3)$ element by element. And then use \n\\begin{align}\n\tX^{new} = (a(X_1 \\ast K^1), a(X_2\\ast K^2), a(X_3 \\ast T^3))\n\\end{align} as the next input for the CNN network.\n\nNow we want to show that the traditional method with more kernels can reproduce the $X^{new}$ in Prof. Xu's case.\n\nHere we set we have some more kernels like \n\\begin{align}\n\tK = \n\t\\begin{pmatrix}\n\t\tK_1^1 & \\cdots & K_1^N \\\\\n\t\tK_2^1 & \\cdots & K_2^N \\\\\n\t\tK_3^1 & \\cdots & K_3^N \n\t\\end{pmatrix},\n\\end{align} with $K_i^j \\in \\mathbb{R}^{3\\times3}$.\n\nWhat we have at most are:\n\\begin{equation}\n\\tilde{X} = X\\tilde{\\ast} K =  \\begin{pmatrix}\nX_1 \\ast K_1^1 & \\cdots & X_1\\ast K_1^N \\\\\nX_2 \\ast K_2^1 & \\cdots & X_2\\ast K_2^N \\\\\nX_3 \\ast K_3^1 & \\cdots & X_3\\ast K_3^N \n\\end{pmatrix}\n\\end{equation}\n\n{\\bf Here in fact we can have a simple question: why we don't just put $a(\\tilde{X})$ as the next input for the next layer of CNN? Maybe this dimension is to large?}\n\nTraditional method for convolution with channel is to say we need to compress the original ``channel\" dimension by take \n\\begin{equation}\n\\tilde{X}  \\to ( \\sum_{j=1:3} X_j\\ast K_{j}^1, \\cdots, \\sum_{j=1:3} X_j\\ast K_{j}^N),\n\\end{equation} \nand then apply the active function $a$ getting:\n\\begin{equation}\n(a( \\sum_{j=1:3} X_j\\ast K_{j}^1), \\cdots, a(\\sum_{j=1:3} X_j\\ast K_{j}^N)).\n\\end{equation}\n\nSo we can see that, if we take $ N = 3$ then we can reproduce the \n$T^{new} = (a(X_1 \\ast K^1), a(X_2\\ast K^2), a(X_3 \\ast T^3))$ from $(a( \\sum_{j=1:3} X_j\\ast K_{j}^1), \\cdots, a(\\sum_{j=1:3} X_j\\ast K_{j}^N))$ by just take\n\\begin{align}\n\tK^i = \\sum_{j=1:3} K_j^i, \\quad \\forall i = 1:3.\n\\end{align}\n\n\\begin{remark}\n\tHere we can take Prof. Xu's idea and the traditional convolution as consistent by means that because the dimension for $a(\\tilde{X})$ is too large({\\bf In fact, we like redundancy some times, why we just use this directly?}), we need some ways to compress $\\tilde{X}$ first and then apply active function $a$. The simplest next two ways is:\n\t\\begin{itemize}\n\t\t\\item Compress(sum) $\\tilde{X}$ in row. This leads to Prof. Xu's idea keeping the ``channel\" number as 3.\n\t\t\\item Compress(sum) $\\tilde{X}$ in column. This leads to traditional idea changing the ``channel\" into $N$.\n\t\\end{itemize}\n\t\n\t{\\bf Another questions is how to compress this $\\tilde{X}$ ``better\"?  What dose better means?}\n\t\n\\end{remark}\n\n\n\\input{6DL/ReLUDNN-CNN}\n\n", "meta": {"hexsha": "27c9b469945c5e96571a6ba13e763805161fbf03", "size": 64736, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/CNN.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/CNN.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/CNN.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6784452297, "max_line_length": 456, "alphanum_fraction": 0.6475840336, "num_tokens": 26392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850021922959, "lm_q2_score": 0.863391624034103, "lm_q1q2_score": 0.80838062860158}}
{"text": "\\section{Vector Fields}\\label{sec:VectorFields}\n\nThis chapter is concerned with applying calculus in the context of \n\\dfont{vector fields}\\index{vector field}. A two-dimensional vector\nfield is a function $f$ that maps each point $(x,y)$ in $\\R^2$ to a\ntwo-dimensional vector $\\langle u,v\\rangle$, and similarly a\nthree-dimensional vector field maps $(x,y,z)$ to $\\langle\nu,v,w\\rangle$. Since a vector has no position, we typically indicate a\nvector field in graphical form by placing the vector $f(x,y)$ with its\ntail at $(x,y)$. Figure~\\ref{fig:vector field} shows a\nrepresentation of the vector field \n$f(x,y)=\\langle x/\\sqrt{x^2+y^2+4},-y/\\sqrt{x^2+y^2+4}\\rangle$.\nFor such a graph to be readable, the vectors must be fairly short,\nwhich is accomplished by using a different scale for the vectors than\nfor the axes. Such graphs are thus useful for understanding the sizes\nof the vectors relative to each other but not their absolute size.\n\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from -1 to 1, y from 0 to 1\n\\put {\\hbox{\\epsfxsize8cm\\epsfbox{images/vfield.eps}}} at 0 -0.15\n\\endpicture}}\n\\caption{A vector field. \\label{fig:vector field}}\n\\end{figure}\n\nVector fields have many important applications, as they can be used to\nrepresent many physical quantities: the vector at a point may\nrepresent the strength of some force (gravity, electricity, magnetism) or\na velocity (wind speed or the velocity of some other fluid). \n\nWe have already seen a particularly important kind of vector\nfield---the gradient\\index{gradient}. Given a function $f(x,y)$, recall that the\ngradient is $\\vect{f} = \\nabla f  = \\langle f_x(x,y),f_y(x,y)\\rangle$, a vector that depends\non (is a function of) $x$ and $y$. We usually picture the gradient\nvector with its tail at $(x,y)$, pointing in the direction of maximum\nincrease. Vector fields that are gradients have some particularly nice\nproperties, as we will see.\nAn important example is \n$$\\vect{f}=\n\\left\n\\langle {-x\\over (x^2+y^2+z^2)^{3/2}},{-y\\over (x^2+y^2+z^2)^{3/2}},{-z\\over\n  (x^2+y^2+z^2)^{3/2}}\\right\\rangle,$$\nwhich points from the point $(x,y,z)$ toward the origin and has length\n$${\\sqrt{x^2+y^2+z^2}\\over(x^2+y^2+z^2)^{3/2}}=\n{1\\over(\\sqrt{x^2+y^2+z^2})^2},$$\nwhich is the reciprocal of the square of the distance from $(x,y,z)$\nto the origin---in other words, $\\vect{f}$ is an ``inverse square\nlaw''.\nThe vector $\\vect{f}$ is a gradient:\n\\begin{equation}\\label{eq:inverse square field as gradient}\n\\vect{f} = \\nabla {1\\over\\sqrt{x^2+y^2+z^2} }\n\\end{equation}\nwhich turns out to be extremely useful.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:VectorFields}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex} Investigate the vector field $\\langle x,y\\rangle$ \n\\end{ex}\n\n\\begin{ex} Investigate the vector field $\\langle -x, -y\\rangle$ \n\\end{ex}\n\n\\begin{ex} Investigate the vector field $\\langle x,-y\\rangle$ \n\\end{ex}\n\n\\begin{ex} Investigate the vector field $\\langle \\sin x,\\cos y\\rangle$ \n\\end{ex}\n\n\\begin{ex} Investigate the vector field $\\langle x+1,x+3\\rangle$ \n\\end{ex}\n\n\\begin{ex} Verify Equation~\\ref{eq:inverse square field as gradient}.\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "5f7f58127029317aef4bea3e8b16c7d3b81a2018", "size": 3280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "16-vector-calculus/16-1-vector-fields.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "16-vector-calculus/16-1-vector-fields.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "16-vector-calculus/16-1-vector-fields.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.5882352941, "max_line_length": 92, "alphanum_fraction": 0.7164634146, "num_tokens": 993, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.896251377983158, "lm_q1q2_score": 0.8083476538966891}}
{"text": "\\section{Question 1}\n$$\nG(s) = \\exp(-\\tau s), \\quad \\tau > 0\n$$\n\n$$\n\\angle G(j\\omega) = -\\tau \\omega\n$$\n$$\n\\left\\vert G(j\\omega) \\right\\vert = 1 \\to 20\\log(\\left\\vert G(j\\omega) \\right\\vert) = 0\n$$\n\\begin{figure}[H]\n\t\\caption{Bode digram using MATLAB ($\\tau = 1$)}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/bode.png}\n\\end{figure}\n\nThere is no pole in imaginary axis and nyquist path is from $0 \\to \\infty \\to -\\infty\\to 0$.\n\\begin{figure}[H]\n\t\\caption{Closed contour in the s plane}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/Nyquist_path.png}\n\\end{figure}\nSo the Nyquist plot is circle in orogin with radius 1 and clock wise.\n\\begin{figure}[H]\n\t\\caption{Nyquist plot using MATLAB ($\\tau = 1$)}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/nyquist.png}\n\\end{figure}\n", "meta": {"hexsha": "a99454e1f4ab932abf59a3671965e1f53ed25580", "size": 801, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW I/Report/Q1/Q1.tex", "max_stars_repo_name": "alibaniasad1999/Principle-Of-Controller-Design", "max_stars_repo_head_hexsha": "2a6285f627377a5e5edfb32c92e054ab213d311a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW/HW I/Report/Q1/Q1.tex", "max_issues_repo_name": "alibaniasad1999/Principle-Of-Controller-Design", "max_issues_repo_head_hexsha": "2a6285f627377a5e5edfb32c92e054ab213d311a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW/HW I/Report/Q1/Q1.tex", "max_forks_repo_name": "alibaniasad1999/Principle-Of-Controller-Design", "max_forks_repo_head_hexsha": "2a6285f627377a5e5edfb32c92e054ab213d311a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7, "max_line_length": 92, "alphanum_fraction": 0.6803995006, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870766, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.8083109677722123}}
{"text": "\\section{Distances between distributions}\n\n\\subsection{Total variation distance}\nThe total variation distance $\\text {TV}$ between the propability measures $P$ and $Q$ with a sample space $E$ is defined as:\\\\\n$\\text {TV}(\\mathbf{P}, \\mathbf{Q}) = {\\max _{A \\subset E}}| \\mathbf{P}(A) - \\mathbf{Q}(A) |,$\\\\\nCalculation with $f$ and $g$:\n\\begin{align*}\n{TV}(\\mathbf{P}, \\mathbf{Q}) =&\\\\\n\t&\\begin{cases}\n\t\t  \\frac{1}{2} \\, \\sum _{x \\in E} |f(x) - g(x)|,\\text{discr}\\\\\t\t \n\t\t \\frac{1}{2} \\, {\\color{blue}{\\int }} _{x \\in E} |f(x) - g(x)|dx,\\text{cont}\n\t\\end{cases}\t\n\\end{align*}\nSymmetry: $TV(\\mathbf{P}, \\mathbf{Q}) = TV(\\mathbf{Q}, \\mathbf{P})$\\\\\nPositive: $TV(\\mathbf{P}, \\mathbf{Q}) \\geq 0$\\\\\nDefinite: $TV(\\mathbf{P}, \\mathbf{Q}) = 0 \\iff \\mathbf{P}= \\mathbf{Q}$\\\\\nTriangle inequality: $TV(\\mathbf{P}, \\mathbf{V}) \\leq TV(\\mathbf{P}, \\mathbf{Q}) + TV(\\mathbf{Q}, \\mathbf{V})$\\\\\n\nIf the support of $\\mathbf{P}$ and $\\mathbf{Q}$ is disjoint:\n\\begin{align*}\nTV(\\mathbf{P}, \\mathbf{V}) = 1\n\\end{align*}\nTV between continuous and discrete r.v:\n\\begin{align*}\nTV(\\mathbf{P}, \\mathbf{V}) = 1\n\\end{align*}\n\\subsection{KL divergence}\nThe KL divergence (aka relative entropy) $\\text {KL}$ between between probability measures $P$ and $Q$ with the common sample space $E$ and pmf/pdf functions $f$ and $g$ is defined as:\n\\begin{align*}\n  {KL}(\\mathbf{P}, \\mathbf{Q}) = &\\\\\n\t&\\begin{cases}\n\t\t  \\sum _{x \\in E} p(x) \\ln \\left( \\frac{p(x)}{q(x)} \\right),&\\text{discr}\\\\\t \n\t\t{\\int }_{x \\in E} p(x) \\ln \\left( \\frac{p(x)}{q(x)}\\right)dx,&\\text{cont}\n\t\\end{cases}\n\\end{align*}\nThe KL divergence is not a distance measure! Always sum over the support of $P$!\\\\\nAsymetric in general: $\\text {KL}(\\mathbf{P}, \\mathbf{Q}) \\neq \\text {KL}(\\mathbf{Q}, \\mathbf{P})$\\\\\nNonnegative: $\\text {KL}(\\mathbf{P}, \\mathbf{Q}) \\geq 0$\\\\\nDefinite: if $\\mathbf{P}$ = $\\mathbf{Q}$ then $\\text {KL}(\\mathbf{P}, \\mathbf{Q}) = 0$\\\\\nDoes not satisfy triangle inequality in general: $KL(\\mathbf{P}, \\mathbf{V}) \\nleq KL(\\mathbf{P}, \\mathbf{Q}) + KL(\\mathbf{Q}, \\mathbf{V})$\\\\\n\n\\textbf{Estimator of KL divergence:}\n\\begin{align*}\n\\displaystyle  \\text {KL}\\left(\\mathbf{P}_{\\theta ^*}, \\mathbf{P}_{\\theta }\\right)& = \\mathbb {E}_{\\theta ^*}\\left[\\ln \\left(\\frac{p_{\\theta ^*}(X)}{p_{\\theta }(X)}\\right)\\right]\\\\\n\\widehat{KL}(\\mathbf{P}_{\\theta_{*}},\\mathbf{P}_{\\theta})& = const - \\frac{1}{n} \\sum_{i=1}^{n} log(p_{\\theta}(X_i))\n\\end{align*}", "meta": {"hexsha": "c3226aa2947531fb02b97c59bebd07358efdaa89", "size": 2397, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Total_variation.tex", "max_stars_repo_name": "kpsunkara/MITx_capstone_2", "max_stars_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2019-04-24T02:24:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T10:26:41.000Z", "max_issues_repo_path": "content/Total_variation.tex", "max_issues_repo_name": "kpsunkara/MITx_capstone_2", "max_issues_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-07T20:24:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-06T08:24:47.000Z", "max_forks_repo_path": "content/Total_variation.tex", "max_forks_repo_name": "kpsunkara/MITx_capstone_2", "max_forks_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2019-03-11T14:20:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T16:31:34.000Z", "avg_line_length": 52.1086956522, "max_line_length": 184, "alphanum_fraction": 0.6149353358, "num_tokens": 978, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.8705972600147106, "lm_q1q2_score": 0.8082701631106531}}
{"text": "\\textit{CLRS section 4.5 p. 93}\nLet $ a \\ge 1 $ and $ b > 1 $ be constants, let $ f(n) $ be a function, and let $ T(n) $ be defined on the nonnegative integers by the recurrence\n$$ T(n) = aT\\left( \\frac{n}{b}\\right) + f(n), $$\nwhere we interpret $ \\frac{n}{b} $ to mean either $ \\lfloor \\frac{n}{b}\\rfloor $ or $ \\lceil\\frac{n}{b} \\rceil$.\nThen $ T(n) $ has the following asymptotic bounds:\n\\begin{enumerate}\n    \\item If $ f(n)=O\\left( n^{\\log_ba-\\epsilon} \\right) $ for some constant $ \\epsilon > 0 $, then $ T(n)=\\Theta\\left( n^{\\log_ba}\\right)$.\n    \\item If $ f(n)=\\Theta\\left( n^{\\log_ba}\\right) $, then $ T(n)=\\Theta\\left( n^{log_ba}\\lg n\\right)  $.\n    \\item If $ f(n)=\\Omega\\left( n^{\\log_ba+\\epsilon}\\right)  $ for some constant $ \\epsilon > 0 $, and if $ af\\left( \\frac{n}{b}\\right) \\leq cf(n) $ for some constant $  c < 1 $ and all sufficiently large $ n $, then $ T(n)=\\Theta(f(n)) $.\n\\end{enumerate}\n\\subsection{Using the master method}\n\\begin{enumerate}\n    \\item Determine if the recurrence is on the form $ T(n) = aT\\left( \\frac{n}{b}\\right) + f(n) $.\n    \\item Extract $ a $, $ b $, and $ f(n) $ from the recurrence.\n    \\item Determine $ n^{\\log_b a} $.\n    \\item Compare $ f(n) $ and $ n^{\\log_b a} $ asymptotically.\n    \\begin{enumerate}\n        \\item If $ f(n) $ increases polynomially slower then $ T(n)=\\Theta\\left( n^{\\log_ba}\\right)$.\n        \\item If $ f(n) $ increases similarly then $ T(n)=\\Theta\\left( n^{log_ba}\\lg n\\right)  $.\n        \\item If $ f(n) $ increases polynomially faster and if $ af\\left( \\frac{n}{b}\\right) \\leq cf(n) $ for some constant $  c < 1 $ and all sufficiently large $ n $, then $ T(n)=\\Theta(f(n)) $.\n    \\end{enumerate}\n\\end{enumerate}", "meta": {"hexsha": "1442d971bdb5aa8039caf6337ce0b32740d2241b", "size": 1691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms and Data Structures - Reference/master-method.tex", "max_stars_repo_name": "simwir/notes", "max_stars_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-02-12T22:22:23.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-12T22:22:23.000Z", "max_issues_repo_path": "Algorithms and Data Structures - Reference/master-method.tex", "max_issues_repo_name": "simwir/notes", "max_issues_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms and Data Structures - Reference/master-method.tex", "max_forks_repo_name": "simwir/notes", "max_forks_repo_head_hexsha": "5079b3fc34610094ca00dea13c5128664609f113", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-01-17T10:57:21.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-17T10:57:21.000Z", "avg_line_length": 76.8636363636, "max_line_length": 240, "alphanum_fraction": 0.6043761088, "num_tokens": 602, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.8615382129861582, "lm_q1q2_score": 0.8082296823478106}}
{"text": "\n\\subsection{Boundries and interiors}\n\nThe boundry of the subset \\(S\\) of a topology is the intersection with the closure of \\(S\\) with the closure of the complement of \\(S\\).\n\nSo the boundry of both \\((0,1)\\) and \\([0,1]\\) are \\(0\\) and \\(1\\).\n\nThe interior of \\(S\\) is \\(S\\) without the boundry.\n\nSo the interior of \\((0,1)\\) and \\([0,1]\\) are both \\((0,1)\\).\n\n", "meta": {"hexsha": "7dcc3ad1170662eb97c4022897d24b2cb9e00a16", "size": 363, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/topologyFinite/02-02-boundry.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/topologyFinite/02-02-boundry.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/topologyFinite/02-02-boundry.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.25, "max_line_length": 136, "alphanum_fraction": 0.6280991736, "num_tokens": 115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551525886193, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.8081819336221777}}
{"text": "\\chapter{Mathematical tool of quantum mechanics}\n\\section{The linear vector space and Hilbert space}\n\\subsection{The linear vector space}\nA linear vector space consisits of two set of elements and two algebraic rules :\n\\begin{itemize}\n\t\\item A set of vectors $\\psi,\\phi,\\chi, \\cdots $ and a set of scalars a,b,c....;\n\t\\item a rule of vector addition and a rule of scalar multiplication\n\\end{itemize}\n\\textbf{(a)Addition rule}\\\\\nThe addition rule has the properties and the structure of an abelian group:\n\\begin{itemize}\n\t\\item If $\\psi$ and $\\phi$ are vectors of a space,their sum $\\psi+\\phi$ is also a vector of the same space.\n\t\\item Commutativity :$\\psi+\\phi=\\phi+\\psi$\n\t\\item Associativity:$(\\psi+\\phi)+\\chi=\\psi+(\\phi+\\chi)$\n\t\\item The existance of a zero or neutral vector:for each vector $\\psi$, there must be zero vector 0 such that : 0+$\\psi=\\psi+0=\\psi$\n\t\\item Existance of a symmetric or inverse vector :each vector $\\psi$ must have a symmetric vector (-$\\psi$) such that ($\\psi$)+(-$\\psi$)=(-$\\psi$)+$\\psi$=0.\n\\end{itemize}\n\\textbf{(b)Multiplication rule}\nThe multiplication of a vectot by scalars (scalars can be real or complex numbers) has these properties:\n\\begin{itemize}\n\t\\item The product of a scalar with vector gives another vector.In general if $\\psi$ and $\\phi$ are the two vectors of the space,any linear combination $a\\psi+b\\phi$ is also a vector of the space. a and b being scalars.\n\t\\item Distributivity with respect to addition\\\\\n\t$a(\\psi+\\phi)=a\\psi+a\\phi$\\\\\n\t$(a+b)\\psi=a\\psi+b\\psi$\n\t\\item Associativity with respect to multiplication of scalars:\\\\\n\t$a(b\\psi)=(ab)\\psi$\n\t\\item For each element $\\psi$ there must exist a unitary scalar I and a zero scalar \"0\" such that \\\\\n\t$I\\psi=\\psi I =\\psi$ and $0\\psi=\\psi0=0$\n\\end{itemize}\n\\subsection{The Hilbert space}\nA Hilbert space $\\mathcal{H}$ consists of a set of vectors $\\psi,\\phi,\\chi,\\cdots$ and set of scalars a,b,c which satisfies the following four properties.\\\\\n\\textbf{(a)} $\\mathcal{H}$ \\textbf{is a linear space.}\\\\\n\\textbf{(b)} $\\mathcal{H}$ \\textbf{has a defind scalar product that is strictly positive}.\\\\\n\\textbf{Scalar product}\n  \\par The scalar product of an element $\\psi$ with another element $\\phi$ is in general a complex number,denoted by ($\\psi,\\phi$) \\\\\n  ($\\psi,\\phi$)=complex number\n  \\begin{note}\n  \tSince the scalar product is a complex number ,the quandity ($\\psi,\\phi$) is generally not equal to ($\\phi,\\psi$)\\\\\n  \t($\\psi,\\phi$)=($\\psi*,\\phi$)\n  \\end{note}\n\\textbf{Properties of scalar product}\n\\begin{itemize}\n\t\\item The scalar product of $\\psi$ with $\\phi$ is equal to the complex conjugate of the scalar product of $\\phi$ with $\\psi$\\\\\n\t($\\psi,\\phi$)=($\\phi,\\psi$)*\n\t\\item The scalar product of $\\phi$ with $\\psi$ is linear with respect to the second factor if $\\psi=$ $a \\psi_{1}+b \\psi_{2}$ :\n\t$$\n\t\\left(\\phi, a \\psi_{1}+b \\psi_{2}\\right)=a\\left(\\phi, \\psi_{1}\\right)+b\\left(\\phi, \\psi_{2}\\right),\n\t$$\n\tand antilinear with respect to the first factor if $\\phi=a \\phi_{1}+b \\phi_{2}:$\n\t$$\n\t\\left(a \\phi_{1}+b \\phi_{2}, \\psi\\right)=a^{*}\\left(\\phi_{1}, \\psi\\right)+b^{*}\\left(\\phi_{2}, \\psi\\right) .\n\t$$\n\t\\item - The scalar product of a vector $\\psi$ with itself is a positive real number:\n\t$$\n\t(\\psi, \\psi)=\\|\\psi\\|^{2} \\geq 0\n\t$$\n\twhere the equality holds only for $\\psi=O$.\n\\end{itemize}\n\\textbf{(c)}$\\mathcal{H}$ \\textbf{is separable}\\\\\nThere exists a Cauchy sequence $\\psi_{n} \\in \\mathcal{H}(n=1,2, \\ldots)$ such that for every $\\psi$ of $\\mathcal{H}$ and $\\varepsilon>0$, there exists at least one $\\psi_{n}$ of the sequence for which\n$$\n\\left\\|\\psi-\\psi_{n}\\right\\|<\\varepsilon .\n$$\n\\textbf{(d)} $\\mathcal{H}$ \\textbf{is complete}\\\\\nEvery Cauchy sequence $\\psi_{n} \\in \\mathcal{H}$ converges to an element of $\\mathcal{H}$. That is, for any $\\psi_{n}$, the relation\n$$\n\\lim _{n, m \\rightarrow \\infty}\\left\\|\\psi_{n}-\\psi_{m}\\right\\|=0,\n$$\ndefines a unique limit $\\psi$ of $\\mathcal{H}$ such that\n$$\n\\lim _{n \\rightarrow \\infty}\\left\\|\\psi-\\psi_{n}\\right\\|=0 .\n$$\n\\subsection{Linear vector space that are Hilbert spaces}\n\\begin{itemize}\n\t\\item The first one is the three diamenensional Euclidean vector space which have finite(descrete) set of base vectors.\n\t\\item The second example is the space of the entire complex functions $\\psi(x)$ which hace infinite(contineous) basis.\n\\end{itemize}\n\\section{Dimension and Basis of a vector space}\nA set of $N$ nonzero vectors $\\phi_{1}, \\phi_{2}, \\ldots, \\phi_{N}$ is said to be linearly independent if and only if the solution of the equation\n$$\n\\sum_{i=1}^{N} a_{i} \\phi_{i}=0\n$$\nis $a_{1}=a_{2}=\\cdots=a_{N}=0 .$ But if there exists a set of scalars, which are not all zero, so that one of the vectors (say $\\phi_{n}$ ) can be expressed as a linear combination of the others,\n$$\n\\phi_{n}=\\sum_{i=1}^{n-1} a_{i} \\phi_{i}+\\sum_{i=n+1}^{N} a_{i} \\phi_{i},\n$$\n$\\text { the set }\\left\\{\\phi_{i}\\right\\} \\text { is said to be linearly dependent. }$\\\\\n\\textbf{Dimension:} The dimension of a vector space is given by the maximum number of linearly independent vectors the space can have. For instance, if the maximum number of linearly independent vectors a space has is $N$ (i.e.. $\\phi_{1}, \\phi_{2}, \\ldots, \\phi_{N}$ ). this space is said to be $N$-dimensional. In this $N$-dimensional vector space, any vector $\\psi$ can be expanded as a linear combination:\n$$\n\\psi=\\sum_{i=1}^{N} a_{i} \\phi_{t} .\n$$\n\\textbf{Basis:} The basis of a vector space consists of a set of the maximum possible number of linearly independent vectors belonging to that space. This set of vectors, $\\phi_{1}, \\phi_{2}, \\ldots, \\phi_{N}$, to be denoted in short by $\\left\\{\\phi_{1}\\right\\}$, is called the basis of the vector space, while the vectors $\\phi_{1}, \\phi_{2}, \\ldots, \\phi_{N}$ are called the base vectors.\n\\section{Dirac notation}\nThe physical state of a sysytem is represented in quantum mechanics by elements of a Hilbert space;These elments are called state vectors.We can represents the state vectors in different bases by means of function expansions.\\\\\n\\textbf{Kets: elements of a vector space}\\\\\nDirac denoted the state vector $\\psi $ by the symbol $|\\psi\\rangle$, which he called a ket vector, or simply a ket. Kets belong to the Hilbert (vector) space $\\mathcal{H}$, or, in short, to the ket-space.\\\\\n\\textbf{Bras: elements of a dual space}\\\\\n we know from linear algebra that a dual space can be associated with every vector space. Dirac denoted the elements of a dual space by the symbol $\\langle 1$, which he called a bra vector, or simply a bra; for instance, the element $\\langle\\psi /$ represents a bra. Note: For every ket $|\\psi\\rangle$ there exists a unique bra $\\langle\\psi|$ and vice versa. Again, while kets belong to the Hilbert space $\\mathcal{H}$, the corresponding bras belong to its dual (Hilbert) space $\\mathcal{H}_{d}$.\\\\\n \\textbf{Bra-ket: Dirac notation for the scalar product}\\\\\n Dirac denoted the scalar (inner) product by the symbol $\\langle\\mid\\rangle$, which he called a a bra-ket. For instance, the scalar product $(\\phi, \\psi)$ is denoted by the bra-ket $\\langle\\phi \\mid \\psi\\rangle$ :\n $$\n (\\phi, \\psi) \\quad \\longrightarrow \\quad\\langle\\phi \\mid \\psi\\rangle \\text {. }\n $$\n \\begin{note}\n \t\\begin{itemize}\n \t\t\\item When a ket (or bra) is multiplied by a complex number, we also get a ket (or bra).\n \t\t\\item In the coordinate representation,the scalar product $\\langle\\phi \\mid \\psi\\rangle$ is given by\\\\\n \t\t$$\\langle\\phi \\mid \\psi\\rangle=\\int \\phi^*(r,t)\\psi(r,t)d^3r$$\n \t\\end{itemize}\n \\end{note}\n\\newpage\n\\textbf{ Properties of kets, bras, and bra-kets}  \\\\\n\\begin{itemize}\n\t\\item \\textbf{ Every ket has a corresponding bra}\\\\\n\tTo every $k e t|\\psi\\rangle$, there corresponds a unique bra $\\langle\\psi|$ and vice versa:\n\t$|\\psi\\rangle \\quad \\longleftrightarrow \\quad\\langle\\psi|$.\n\tThere is a one-to-one correspondence between bras and kets:\n\t$$\n\ta|\\psi\\rangle+b|\\phi\\rangle \\longleftrightarrow a^{*}\\langle\\psi|+b^{*}\\langle\\phi| \\text {. }\n\t$$\n\twhere $a$ and $b$ are complex numbers. The following is a common notation:\n\t$$\n\t|a \\psi\\rangle=a|\\psi\\rangle, \\quad\\langle a \\psi|=a^{*}\\langle\\psi| .\n\t$$\n\t\\item \\textbf{Properties of the scalar product}\\\\\n\t(1)$\\langle\\phi \\mid \\psi\\rangle^{*}=\\langle\\psi \\mid \\phi\\rangle $ .\\\\\n\t(2)$\\left\\langle\\psi \\mid a_{1} \\psi_{1}+a_{2} \\psi_{2}\\right\\rangle= a_{1}\\left\\langle\\psi \\mid \\psi_{1}\\right\\rangle+a_{2}\\left\\langle\\psi \\mid \\psi_{2}\\right\\rangle $\\\\\n\t(3)$\\left\\langle a_{1} \\phi_{1}+a_{2} \\phi_{2} \\mid \\psi\\right\\rangle= a_{1}^{*}\\left\\langle\\phi_{1} \\mid \\psi\\right\\rangle+a_{2}^{*}\\left\\langle\\phi_{2} \\mid \\psi\\right\\rangle $\\\\\n\t\t(4)$\\left\\langle a_{1} \\phi_{1}+a_{2} \\phi_{2} \\mid b_{1} \\psi_{1}+b_{2} \\psi_{2}\\right\\rangle= a_{1}^{*} b_{1}\\left\\langle\\phi_{1} \\mid \\psi_{1}\\right\\rangle+a_{1}^{*} b_{2}\\left\\langle\\phi_{1} \\mid \\psi_{2}\\right\\rangle \n\t\t+a_{2}^{*} b_{1}\\left\\langle\\phi_{2} \\mid \\psi_{1}\\right\\rangle+a_{2}^{*} b_{2}\\left\\langle\\phi_{2} \\mid \\psi_{2}\\right\\rangle$ .\n\\item \\textbf{ The norm is real and positive}\\\\\nFor any state vector $|\\psi\\rangle$ of the Hilbert space $\\mathcal{H}$, the norm $\\langle\\psi \\mid \\psi\\rangle$ is real and positive; $\\langle\\psi \\mid \\psi\\rangle$ is equal to zero only for the case where $|\\psi\\rangle=O$, where $O$ is the zero vector. If the state $|\\psi\\rangle$ is normalized then $\\langle\\psi \\mid \\psi\\rangle=1$.\n\\item \\textbf{Schwarz inequality}\nFor any two states $|\\psi\\rangle$ and $|\\phi\\rangle$ of the Hilbert space, we can show that\n$$\n|\\langle\\psi \\mid \\phi\\rangle|^{2} \\leq\\langle\\psi \\mid \\psi\\rangle\\langle\\phi \\mid \\phi\\rangle .\n$$\nIf $|\\psi\\rangle$ and $|\\phi\\rangle$ are linearly dependent (i.e., proportional: $|\\psi\\rangle=\\alpha|\\phi\\rangle$, where $\\alpha$ is a scalar), this relation becomes an equality. The Schwarz inequality  is analogous to the following relation of the real Euclidean space\n$$\n|\\vec{A} \\cdot \\vec{B}|^{2} \\leq|\\vec{A}|^{2}|\\vec{B}|^{2}\n$$\n\\item \\textbf{Triangle inequality}\\\\\n$$\n\\sqrt{\\langle\\psi+\\phi \\mid \\psi+\\phi\\rangle} \\leq \\sqrt{\\langle\\psi \\mid \\psi\\rangle}+\\sqrt{\\langle\\phi \\mid \\phi\\rangle} .\n$$\nIf $|\\psi\\rangle$ and $|\\phi\\rangle$ are linearly dependent, $|\\psi\\rangle=\\alpha|\\phi\\rangle$, and if the proportionality scalar $\\alpha$ is real and positive, the triangle inequality becomes an equality. The counterpart of this inequality in Euclidean space is given by $|\\vec{A}+\\vec{B}| \\leq|\\vec{A}|+|\\vec{B}|$.\n\\item \\textbf{Orthogonal states}\\\\\nTwo kets, $|\\psi\\rangle$ and $|\\phi\\rangle$, are said to be orthogonal if they have a vanishing scalar product:\n$$\n\\langle\\psi \\mid \\phi\\rangle=0 .\n$$\n\\item \\textbf{Orthonormal states}\\\\\nTwo kets, $|\\psi\\rangle $ and $|\\phi \\rangle $ are said to be orthonormal and if each one of them has a unit norm:\\\\\n$$ \\langle \\psi \\mid \\phi \\rangle =0$$ \n$$ \\langle \\psi \\mid \\psi \\rangle =1$$ \n$$ \\langle \\phi \\mid \\phi \\rangle =1$$ \n\\end{itemize}\n\\begin{exercise}\n\tConsider the following two kets\\\\\n\t|$\\psi\\rangle=\\left(\\begin{array}{c}\n\t\t-3 i \\\\\n\t\t2+i \\\\\n\t\t4\n\t\\end{array}\\right), \\quad|\\phi\\rangle=\\left(\\begin{array}{c}\n\t\t2 \\\\\n\t\t-i \\\\\n\t\t2-3 i\n\t\\end{array}\\right)$\\\\\n\t(a) Find the bra $\\langle \\phi |$ \\\\\n\t(b) Evaluate the scalar product $\\langle \\phi \\mid \\psi \\rangle $\n\\end{exercise}\n\\begin{answer}\n(a) the bra $\\langle\\phi|$ can be obtained by simply taking the complex conjugate of the transpose of the ket $|\\phi\\rangle$ :\n\t$$\n\t\\langle\\phi|=\\left(\\begin{array}{lll}\n\t2 & i & 2+3 i\n\t\\end{array}\\right) .\n\t$$\n\t(b) The scalar product $\\langle\\phi \\mid \\psi\\rangle$ can be calculated as follows:\n\t$$\n\t\\begin{aligned}\n\t\\langle\\phi \\mid \\psi\\rangle &=\\left(\\begin{array}{lll}\n\t2 & i & 2+3 i\n\t\\end{array}\\right)\\left(\\begin{array}{c}\n\t-3 i \\\\\n\t2+i \\\\\n\t4\n\t\\end{array}\\right) \\\\\n\t&=2(-3 i)+i(2+i)+4(2+3 i) \\\\\n\t&=7+8 i .\n\t\\end{aligned}\n\t$$\n\\end{answer}\n\\begin{exercise}\n\tConsider the states $|\\psi\\rangle=3 i\\left|\\phi_{1}\\right\\rangle-7 i\\left|\\phi_{2}\\right\\rangle$ and $|\\chi\\rangle=-\\left|\\phi_{1}\\right\\rangle+2 i\\left|\\phi_{2}\\right\\rangle$, where $\\left|\\phi_{1}\\right\\rangle$ and $\\left|\\phi_{2}\\right\\rangle$ are orthonormal.\\\\\n\t(a) Calculate $|\\psi+\\chi\\rangle$ and $\\langle\\psi+\\chi|$.\\\\\n\t(b) Calculate the scalar products $\\langle\\psi \\mid \\chi\\rangle$ and $\\langle\\chi \\mid \\psi\\rangle$. Are they equal?\n\\end{exercise}\n\\begin{answer}\n\t(a) The calculation of $|\\psi+\\chi\\rangle$ is straightforward:\n\t$$\n\t\\begin{aligned}\n\t|\\psi+\\chi\\rangle &=|\\psi\\rangle+|\\chi\\rangle=\\left(3 i\\left|\\phi_{1}\\right\\rangle-7 i\\left|\\phi_{2}\\right\\rangle\\right)+\\left(-\\left|\\phi_{1}\\right\\rangle+2 i\\left|\\phi_{2}\\right\\rangle\\right) \\\\\n\t&=(-1+3 i)\\left|\\phi_{1}\\right\\rangle-5 i\\left|\\phi_{2}\\right\\rangle .\n\t\\end{aligned}\n\t$$\n\tThis leads at once to the expression of $\\langle\\psi+\\chi|$ :\n\t$$\n\t\\langle\\psi+\\chi|=(-1+3 i)^{*}\\left\\langle\\phi_{1}\\right|+(-5 i)^{*}\\left\\langle\\phi_{2}\\right|=(-1-3 i)\\left\\langle\\phi_{1}\\right|+5 i\\left\\langle\\phi_{2}\\right| \\text {. }\n\t$$\n\t(b) Since $\\left\\langle\\phi_{1} \\mid \\phi_{1}\\right\\rangle=\\left\\langle\\phi_{2} \\mid \\phi_{2}\\right\\rangle=1,\\left\\langle\\phi_{1} \\mid \\phi_{2}\\right\\rangle=\\left\\langle\\phi_{2} \\mid \\phi_{1}\\right\\rangle=0$, and since the bras corresponding to the kets $|\\psi\\rangle=3 i\\left|\\phi_{1}\\right\\rangle-7 i\\left|\\phi_{2}\\right\\rangle$ and $|\\chi\\rangle=-\\left|\\phi_{1}\\right\\rangle+2 i\\left|\\phi_{2}\\right\\rangle$ are given by $\\langle\\psi|=-3 i\\left\\langle\\phi_{1}\\right|+7 i\\left\\langle\\phi_{2}\\right|$ and $\\langle\\chi|=-\\left\\langle\\phi_{1}\\right|-2 i\\left\\langle\\phi_{2}\\right|$, the scalar products are\\\\\n\t$$\\begin{aligned}\n\t\t\\langle\\psi \\mid \\chi\\rangle &=\\left(-3 i\\left\\langle\\phi_{1}\\left|+7 i\\left\\langle\\phi_{2}\\right|\\right)\\left(-\\left|\\phi_{1}\\right\\rangle+2 i\\left|\\phi_{2}\\right\\rangle\\right)\\right.\\right.\\\\\n\t\t&=(-3 i)(-1)\\left\\langle\\phi_{1} \\mid \\phi_{1}\\right\\rangle+(7 i)(2 i)\\left\\langle\\phi_{2} \\mid \\phi_{2}\\right\\rangle \\\\\n\t\t&=-14+3 i \\\\\n\t\t\\langle\\chi \\mid \\psi\\rangle &=\\left(-\\left\\langle\\phi_{1}\\left|-2 i\\left\\langle\\phi_{2}\\right|\\right)\\left(3 i\\left|\\phi_{1}\\right\\rangle-7 i\\left|\\phi_{2}\\right\\rangle\\right)\\right.\\right.\\\\\n\t\t&=(-1)(3 i)\\left\\langle\\phi_{1} \\mid \\phi_{1}\\right\\rangle+(-2 i)(-7 i)\\left\\langle\\phi_{2} \\mid \\phi_{2}\\right\\rangle \\\\\n\t\t&=-14-3 i .\n\t\\end{aligned}$$\n\t$\\text { We see that }\\langle\\psi \\mid \\chi\\rangle \\text { is equal to the complex conjugate of }\\langle\\chi \\mid \\psi\\rangle\\rangle \\text {. }$\n\\end{answer}\n\\section{Operators}\n\\subsection{General definitions}\n Definition of an operator: An operator $ \\hat{A}$ is a mathematical rule that when applied to a ket $|\\psi\\rangle$ transforms it into another ket $\\left|\\psi^{\\prime}\\right\\rangle$ of the same space and when it acts on a bra $\\langle\\phi|$ transforms it into another bra $\\left\\langle\\phi^{\\prime}\\right|$ :\n $$\n \\hat{A}|\\psi\\rangle=\\left|\\psi^{\\prime}\\right\\rangle, \\quad\\langle\\phi| \\hat{A}=\\left\\langle\\phi^{\\prime}\\right| .\n $$\n A similar definition applies to wave functions:\n $$\n \\hat{A} \\psi(\\vec{r})=\\psi^{\\prime}(\\vec{r}), \\quad \\phi(\\vec{r}) \\hat{A}=\\phi^{\\prime}(\\vec{r})\n $$\n \\textbf{Examples of operators}\n \\begin{itemize}\n \t\\item $\\text { Unity operator: it leaves any ket unchanged, } \\hat{I}|\\psi\\rangle=|\\psi\\rangle \\text {. }$\n \t\\item $\\text { The gradient operator: } \\vec{\\nabla} \\psi(\\vec{r})=(\\partial \\psi(\\vec{r}) / \\partial x) \\vec{i}+(\\partial \\psi(\\vec{r}) / \\partial y) \\vec{j}+(\\partial \\psi(\\vec{r}) / \\partial z) \\vec{k} \\text {. }$\n \t\\item The linear momentum operator:$\\vec{P}\\psi(r)=-i\\hbar \\nabla \\psi(r)$ \n \t\\item The parity operator :$\\mathcal{P}\\psi(r)=\\psi(-r)$\n \\end{itemize}\n\\textbf{Product of operators}\\\\\nThe product of two operators is generally not commutative:\\\\\n$$\\hat{A}\\hat{B}\\neq \\hat{B}\\hat{A}$$\nBut they are associative\\\\\n$$\\hat{A}\\hat{B}\\hat{C}=\\hat{A}(\\hat{B}\\hat{C})=(\\hat{A}\\hat{B})\\hat{C}$$\n\\textbf{Linear operators}\\\\\nAn operator $\\hat{A}$ is said to be linear if it obeys the distributive law and like, all operators ,it commute with constants.That is an operator $\\hat{A}$ is linear if ,for any vector $|\\psi_{1}\\rangle $ and $|\\psi_{2}\\rangle $ and any complex numbers $a_1$ and $a_2$ we have\\\\\n$$\\hat{A}(a_1\\mid \\psi_{1}\\rangle +a_2\\mid \\psi_{2}\\rangle)=a_1 \\hat{A} \\mid \\psi_{1}\\rangle +a_2\\hat{A}\\mid \\psi_{2}\\rangle $$\nand\n$$\\left(\\left\\langle\\psi_{1}\\right| a_{1}+\\left\\langle\\psi_{2}\\right| a_{2}\\right) \\hat{A}=a_{1}\\left\\langle\\psi_{1}\\right| \\hat{A}+a_{2}\\left\\langle\\psi_{2}\\right| \\hat{A}$$\n\\textbf{Expectation value of an operator}\\\\\nThe expectation or mean value $\\langle\\hat{A}\\rangle$ of an operator $\\hat{A}$ with respect to a state $|\\psi\\rangle$ is defined by\n$$\n\\langle\\hat{A}\\rangle=\\frac{\\langle\\psi|\\hat{A}| \\psi\\rangle}{\\langle\\psi \\mid \\psi\\rangle} .\n$$\n\\subsection{Hermitian operator}\n\\textbf{Hermitian adjoint}\\\\\nThe Hermitian adjoint or conjugate$ \\alpha^{\\dagger}$, of a complex number $\\alpha$ is the complex conjugate of this number: $\\alpha^{\\dagger}=\\alpha^{*}$. The Hermitian adjoint, or simply the adjoint, $\\hat{A}^{\\dagger}$, of an operator $\\hat{A}$ is defined by this relation:\n$$\n\\left\\langle\\psi\\left|\\hat{A}^{\\dagger}\\right| \\phi\\right\\rangle=\\langle\\phi|\\hat{A}| \\psi\\rangle^{*} .\n$$\n\\textbf{Properties}\\\\\nTo obtain the Hermitian adjoint of any expression, we must cyclically reverse the order of the factors and make three replacements:\n\\begin{itemize}\n\t\\item $\\text { Replace constants by their complex conjugates: } \\alpha^{\\dagger}=\\alpha^{*} \\text {. }$\n\t\\item $\\text { Replace kets (bras) by the corresponding bras (kets): } \\left.(|\\psi\\rangle)^{\\dagger}=\\langle\\psi| \\text { and }(\\langle\\psi|)^{\\dagger}=|\\psi\\rangle\\right\\rangle \\text {. }$\n\t\\item  $\\text { Replace operators by their adjoints. }$\n\\end{itemize}\nFollowing these rules, we can write\n$$\n\\begin{aligned}\n\\left(\\hat{A}^{\\dagger}\\right)^{\\dagger} &=\\hat{A}, \\\\\n(a \\hat{A})^{\\dagger} &=a^{*} \\hat{A}^{\\dagger}, \\\\\n\\left(\\hat{A}^{n}\\right)^{\\dagger} &=\\left(\\hat{A}^{\\dagger}\\right)^{n}, \\\\\n(\\hat{A}+\\hat{B}+\\hat{C}+\\hat{D})^{\\dagger} &=\\hat{A}^{\\dagger}+\\hat{B}^{\\dagger}+\\hat{C}^{\\dagger}+\\hat{D}^{\\dagger}, \\\\\n(\\hat{A} \\hat{B} \\hat{C} \\hat{D})^{\\dagger} &=\\hat{D}^{\\dagger} \\hat{C}^{\\dagger} \\hat{B}^{\\dagger} \\hat{A}^{\\dagger}, \\\\\n(\\hat{A} \\hat{B} \\hat{C}|\\psi\\rangle)^{\\dagger} &=\\langle\\psi| D^{\\dagger} C^{\\dagger} B^{\\dagger} A^{\\dagger} .\n\\end{aligned}\n$$\n\\textbf{Hermitian and skew Hermitian operators}\\\\\nAn operator $\\hat{A}$ is said to be Hermitian if it is equal to its adjoint $\\hat{A}^{\\dagger}$ :\n$$\n\\hat{A}=\\hat{A}^{\\dagger} \\quad \\text { or } \\quad\\langle\\psi|\\hat{A}| \\phi\\rangle=\\langle\\phi|\\hat{A}| \\psi\\rangle^{*} .\n$$\nOn the other hand ,an operator $\\hat{B}$ is said to be skew Hermitian or anti Hermitian if \\\\\n$$ \\hat{B}^{\\dagger}=-B $$\nor $$ \\langle \\psi \\mid \\hat{B} \\mid \\phi \\rangle =-\\langle \\phi \\mid \\hat{B} \\mid \\psi\\rangle ^*$$\n\\textbf{Examples}\\\\\nHermitian:$\\hat{A}+\\hat{A}^{\\dagger}$ and $i(\\hat{A}-\\hat{A}^{\\dagger})$ etc\\\\\nAnti Hermitian:$i(\\hat{A}+\\hat{A}^{\\dagger})$\n\\begin{exercise}\n\t$\\text { Prove that the operators } i(d / d x) \\text { and } d^{2} / d x^{2} \\text { are Hermitian. }$\n\\end{exercise}\n\\begin{answer}\n$$\n\\int_{-\\infty}^{\\infty} \\psi_{m}^{*}\\left(i \\frac{d}{d x}\\right) \\psi_{n} d x=i\\left[\\psi_{m}^{*} \\psi_{n}\\right]_{-\\infty}^{\\infty}-i \\int_{-\\infty}^{\\infty} \\psi_{n} \\frac{d}{d x} \\psi_{m}^{*} d x=\\int_{-\\infty}^{\\infty}\\left(i \\frac{d}{d x} \\psi_{m}\\right)^{*} \\psi_{n} d x\n$$\nTherefore, $i d / d x$ is Hermitian.\\\\\n$$\\int_{-\\infty}^{\\infty} \\psi_{m}^{*} \\frac{d^{2} \\psi_{n}}{d x^{2}} d x=\\left[\\psi_{m}^{*} \\frac{d \\psi_{n}}{d x}\\right]_{-m}^{\\infty}-\\int_{-}^{\\infty} \\frac{d \\psi_{n}}{d x} \\frac{d \\psi_{m}^{*}}{d x} d x$$\n$$\n=\\left[\\frac{d \\psi_{m}^{*}}{d x} \\psi_{n}\\right]_{-\\infty}^{\\infty}+\\int_{-\\infty}^{\\infty} \\psi_{n} \\frac{d^{2} \\psi_{m}^{*}}{d x^{2}} d x=\\int_{-\\infty}^{\\infty} \\frac{d^{2} \\psi_{m}^{*}}{d x^{2}} \\psi_{n} d x\n$$\nThus, $d^{2} / d x^{2}$ is Hermitian.\t\n\\end{answer}\n\\begin{exercise}\n$\\text { Prove that operator } P_{x}=-i \\hbar \\frac{d}{d x} \\text { is Hermitian but } D_{x}=\\frac{d}{d x} \\text { is not Hermitian. }$\n\\end{exercise}\n\\begin{answer}\n The given operator $-i \\hbar \\frac{d}{d x}$ is the same as $P_{x}$. Let $\\psi_{1}(x)$ and $\\psi_{2}(x)$ be two arbitrary functions.\n$$\n\\begin{aligned}\n\\left\\langle\\psi_{1} \\mid P_{x} \\psi_{2}\\right\\rangle &=\\int_{-\\infty}^{x} \\psi_{1}^{*}(x)\\left[-i \\hbar \\frac{d}{d x} \\psi_{2}(x)\\right] d x \\\\\n&=-i \\hbar \\int_{-\\infty}^{\\infty} \\psi_{1}^{*}(x) \\frac{d}{d x} \\psi_{2}(x) d x\n\\end{aligned}\n$$\nIntegrating by parts, this is equal to\n$$\n-i \\hbar\\left[\\left.\\psi_{1}^{*}(x) \\psi_{2}(x)\\right|_{-\\infty} ^{\\infty}-\\int_{-\\infty}^{\\infty} \\frac{d \\psi_{1}^{*}(x)}{d x} \\psi_{2}(x) d x\\right]\n$$\nFor the wave function to be square integrable, it must go to zero as $x$ goes to $-\\infty$ or $+\\infty$.\nThus, the first term in the square bracket is zero. So,\n$$\n\\left\\langle\\psi_{1}\\left|P_{x}\\right| \\psi_{2}\\right\\rangle=i \\hbar \\int_{-\\infty}^{\\infty} \\frac{d \\psi_{1}^{*}(x)}{d x} \\psi_{2}(x) d x\n$$\n$$\n\\text { Also, } \\begin{aligned}\n\\left\\langle P_{x} \\psi_{1} \\mid \\psi_{2}\\right\\rangle &=\\int_{-\\infty}^{\\infty}\\left[P_{x} \\psi_{1}(x)\\right]^{*} \\psi_{2}(x) d x \\\\\n&=\\int_{-\\infty}^{\\infty}\\left[-i \\hbar \\frac{d \\psi_{1}(x)}{d x}\\right]^{*} \\psi_{2}(x) d x=i \\hbar \\int_{-\\infty}^{\\infty} \\frac{d \\psi_{1}^{*}(x)}{d x} \\psi_{2}(x) d x\n\\end{aligned}\n$$\nFrom (i) and (ii), $\\left\\langle\\psi_{1} \\mid P_{x} \\psi_{2}\\right\\rangle=\\left\\langle P_{x} \\psi_{1} \\mid \\psi_{2}\\right\\rangle$\\\\\nHence $P_{x}=-i \\hbar \\frac{d}{d x}$ is Hermitian. Similar calculation with $A=\\frac{d}{d x}$ will give,\n$$\n\\left\\langle\\psi_{1} \\mid A \\psi_{2}\\right\\rangle=-\\int_{-\\infty}^{\\infty} \\frac{d \\psi_{1}^{*}(x)}{d x} \\psi_{2}(x) d x\n$$\nAnd, $\\quad\\left\\langle A \\psi_{1} \\mid \\psi_{2}\\right\\rangle=\\int_{-\\infty}^{\\infty} \\frac{d \\psi_{1}^{*}(x)}{d x} \\psi_{2}(x) d x$\\\\\nHence, $\\left\\langle\\psi_{1} \\mid A \\psi_{2}\\right\\rangle \\neq\\left\\langle A \\psi_{1} \\mid \\psi_{2}\\right\\rangle$ and so, $A=\\frac{d}{d x}$ is not Hermitian.\t\n\\end{answer}\n\\begin{exercise}\n\t$\\text { Show that operator } O=(1+i) A B+(1-i) B A \\text { is Hermitian if } A \\text { and } B \\text { is Hermitian. }$\n\\end{exercise}\n\\begin{answer}\n$$[(1+i) A B+(1-i) B A]^{\\dagger}=[(1+i) A B]^{\\dagger}+[(1-i) B A]^{\\dagger}$$\t\n$$\n\\begin{aligned}\n&=(1+i)^{*}(A B)^{\\dagger}+(1-i)^{*}(B A)^{\\dagger} \\\\\n&=(1-i) B^{\\dagger} A^{\\dagger}+(1+i) A^{\\dagger} B^{\\dagger} \\quad \\text { if } A \\text { and } B \\text { is hermitian } \\\\\n&=(1-i) B A+(1+i) A B \\\\\n&(1+i) A B+(1-i) B A\n\\end{aligned}\n$$\nThus the given operator is Hermitian\n\\end{answer}\n\\subsection{Projection operators}\nAn operator $\\hat{P}$ is said to be projection operator if it is Hermitian and equal to its own square:\\\\\n$$\\hat{P}^{\\dagger}=\\hat{P} \\quad \\quad \\hat{P}^2=\\hat{P}$$\nTHe unit operator $\\hat{I}$ is a simple example of a projection operator Since $$\\hat{I}^{\\dagger}=\\hat{I}, \\hat{I}^2=\\hat{I}$$\n\\textbf{Properties}\\\\\n\\begin{itemize}\n\t\\item The product of two commuting projection operators, $\\hat{P}_{1}$ and $\\hat{P}_{2}$, is also a projection operator, since\n\t$$\n\t\\left(\\hat{P}_{1} \\hat{P}_{2}\\right)^{\\dagger}=\\hat{P}_{2}^{\\dagger} \\hat{P}_{1}^{\\dagger}=\\hat{P}_{2} \\hat{P}_{1}=\\hat{P}_{1} \\hat{P}_{2} \\text { and }\\left(\\hat{P}_{1} \\hat{P}_{2}\\right)^{2}=\\hat{P}_{1} \\hat{P}_{2} \\hat{P}_{1} \\hat{P}_{2}=\\hat{P}_{1}^{2} \\hat{P}_{2}^{2}=\\hat{P}_{1} \\hat{P}_{2} \\text {. }\n\t$$\n\t\\item  The sum of two projection operators is generally not a projection operator.\n\t\\item  Two projection operators are said to be orthogonal if their product is zero.\n\t\\item For a sum of projection operators $\\hat{P}_{1}+\\hat{P}_{2}+\\hat{P}_{3}+\\cdots$ to be a projection operator, it is necessary and sufficient that these projection operators be mutually orthogonal (i.e., the cross-product terms must vanish).\n\\end{itemize}\n\\subsection{Commutator Algebra}\nThe commutator of two operators $\\hat{A}$ and $\\hat{B}$, denoted by $[\\hat{A}, \\hat{B}]$, is defined by\n$$\n[\\hat{A}, \\hat{B}]=\\hat{A} \\hat{B}-\\hat{B} \\hat{A}\n$$\nand the anticommutator $\\{\\hat{A}, \\hat{B}\\}$ is defined by\n$$\n\\{\\hat{A}, \\hat{B}\\}=\\hat{A} \\hat{B}+\\hat{B} \\hat{A}\n$$\nTwo operators are said to commute if their commutator is equal to zero and hence $\\hat{A} \\hat{B}=\\hat{B} \\cdot \\hat{A}$. Any operator commutes with itself:\n$$\n[\\hat{A}, \\hat{A}]=0\n$$\nNote that if two operators are Hermitian and their product is also Hermitian, these operators commute:\n$$\n(\\hat{A} \\hat{B})^{\\dagger}=\\hat{B}^{\\dagger} \\hat{A}^{\\dagger}=\\hat{B} \\hat{A}\n$$\nand since $(\\hat{A} \\hat{B})^{\\dagger}=\\hat{A} \\hat{B}$ we have $\\hat{A} \\hat{B}=\\hat{B} \\hat{A}$.\\\\\n\\textbf{Example}\\\\\n$$\\left[\\hat{X}, \\hat{P}_{x}\\right]=i \\hbar \\hat{I}, \\quad\\left[\\hat{Y}, \\hat{P}_{y}\\right]=i \\hbar \\hat{I}, \\quad\\left[\\hat{Z}, \\hat{P}_{z}\\right]=i \\hbar \\hat{I}$$\nWhere $\\hat{P_x}=-i\\hbar \\frac{\\partial}{\\partial x}$, $\\hat{P_y}=-i\\hbar \\frac{\\partial}{\\partial y}$, $\\hat{P_z}=-i\\hbar \\frac{\\partial}{\\partial z}$ and $\\hat{I}$ is the unit operator.\\\\\n\\begin{note}\n\t\\begin{enumerate}\n\t\t\\item $\\left[\\hat{X}, \\hat{P}_{x}\\right]=i \\hbar, \\quad\\left[\\hat{Y}, \\hat{P}_{Y}\\right]=i \\hbar, \\quad\\left[\\hat{Z}, \\hat{P}_{Z}\\right]=i \\hbar$\n\t\t\\item $\\left[\\hat{X}, \\hat{P}_{y}\\right]=\\left[\\hat{X}, \\hat{P}_{z}\\right]=\\left[\\hat{Y}, \\hat{P}_{x}\\right]=\\left[\\hat{Y}, \\hat{P}_{z}\\right]=\\left[\\hat{Z}, \\hat{P}_{x}\\right]=\\left[\\hat{Z}, \\hat{P}_{y}\\right]=0$\n\t\t\\item $\\left[\\hat{R}_{j}, \\hat{P}_{k}\\right]=i \\hbar \\delta_{j k}, \\quad\\left[\\hat{R}_{j}, \\hat{R}_{k}\\right]=0, \\quad\\left[\\hat{P}_{j}, \\hat{P}_{k}\\right]=0 \\quad(j, k=x, y, z)$\n\t\t\\item $\\left[\\hat{X}^{n}, \\hat{P}_{x}\\right]=i \\hbar n \\hat{X}^{n-1}, \\quad\\left[\\hat{X}, \\hat{P}_{x}^{n}\\right]=i \\hbar n \\hat{P}_{x}^{n-1}$\n\t\t\\item $\\left.\\left[  f(\\hat{X}), \\hat{P}_{x}\\right]=i \\hbar \\frac{d f(\\hat{X})}{d \\hat{X}} \\Longrightarrow[\\hat{P}, F(\\hat{\\vec{R}})]=-i \\hbar \\vec{\\nabla} F(\\hat{\\vec{R}})\\right)$\\\\\n\t\tWhere F is a function of the operator $\\hat{R}$\n\t\\end{enumerate}\n\\end{note}\n\\textbf{Properties}\\\\\n\\begin{itemize}\n\t\\item Antisymmetry:\\\\\n\t$$[\\hat{A}, \\hat{B}]=-[\\hat{B}, \\hat{A}]$$\n\t\\item Linearity:\\\\\n\t $$[\\hat{A}, \\hat{B}+\\hat{C}+\\hat{D}+\\cdots]=[\\hat{A}, \\hat{B}]+[\\hat{A}, \\hat{C}]+[\\hat{A}, \\hat{D}]+\\cdots$$\n\t \\item  Hermitian conjugate of a commutator: \\\\\n\t $$[\\hat{A}, \\hat{B}]^{\\dagger}=\\left[\\hat{B}^{\\dagger}, \\hat{A}^{\\dagger}\\right]$$\n\t \\item  Distributivity: \\\\\n\t $$\\begin{aligned}\n\t \t&{[\\hat{A}, \\hat{B} \\hat{C}]=[\\hat{A}, \\hat{B}] \\hat{C}+\\hat{B}[\\hat{A}, \\hat{C}]} \\\\\n\t \t&{[\\hat{A} \\hat{B}, \\hat{C}]=\\hat{A}[\\hat{B}, \\hat{C}]+[\\hat{A}, \\hat{C}] \\hat{B}}\n\t \\end{aligned}$$\n\t \\item jacobi identity:\\\\\n\t $$[\\hat{A},[\\hat{B}, \\hat{C}]]+[\\hat{B},[\\hat{C}, \\hat{A}]]+[\\hat{C},[\\hat{A}, \\hat{B}]]=0$$\n\t \\item Operators commute with scalars: an operator $\\hat{A}$ commutes with any scalar $b$ :\n\t $$\n\t [\\hat{A}, b]=0\n\t $$\n\\end{itemize}\n\\begin{note}\n\tUncertainity relation between two operator A  and B is \\\\\n\t$$\\Delta A \\Delta B \\geq \\frac{1}{2}\\left| \\langle \\left[ \\hat{A},\\hat{B}\\right] \\rangle \\right| $$\n\\end{note}\n\\begin{exercise}\n\t(a)Show that the commutator of two Hermitian operator is anti Hermitian.\\\\\n\t(b)Evaluate the commutator $\\left[ \\hat{A},\\left[ \\hat{B},\\hat{C}\\right] \\hat{D}\\right] $\n\\end{exercise}\n\\begin{answer}\n\t(a) If $\\hat{A}$ and $\\hat{B}$ are Hermitian, we can write\n\t$$\n\t[\\hat{A}, \\hat{B}]^{\\dagger}=(\\hat{A} \\hat{B}-\\hat{B} \\hat{A})^{\\dagger}=\\hat{B}^{\\dagger} \\hat{A}^{\\dagger}-\\hat{A}^{\\dagger} \\hat{B}^{\\dagger}=\\hat{B} \\hat{A}-\\hat{A} \\hat{B}=-[\\hat{A}, \\hat{B}] ;\n\t$$\n\tthat is, the commutator of $\\hat{A}$ and $\\hat{B}$ is anti-Hermitian: $[\\hat{A}, \\hat{B}]^{\\dagger}=-[\\hat{A}, \\hat{B}]$.\\\\\n\t(b) Using the distributivity relation we have\n\t$$\n\t\\begin{aligned}\n\t[\\hat{A},[\\hat{B}, \\hat{C}] \\hat{D}] &=[\\hat{B}, \\hat{C}][\\hat{A}, \\hat{D}]+[\\hat{A},[\\hat{B}, \\hat{C}]] \\hat{D} \\\\\n\t&=(\\hat{B} \\hat{C}-\\hat{C} \\hat{B})(\\hat{A} \\hat{D}-\\hat{D} \\hat{A})+\\hat{A}(\\hat{B} \\hat{C}-\\hat{C} \\hat{B}) \\hat{D}-(\\hat{B} \\hat{C}-\\hat{C} \\hat{B}) \\hat{A} \\hat{D} \\\\\n\t&=\\hat{C} \\hat{B} \\hat{D} \\hat{A}-\\hat{B} \\hat{C} \\hat{D} \\hat{A}+\\hat{A} \\hat{B} \\hat{C} \\hat{D}-\\hat{A} \\hat{C} \\hat{B} \\hat{D} .\n\t\\end{aligned}\n\t$$\n\\end{answer}\n\\begin{exercise}\n Find the following commutation relations:\n\t(i) $\\left[\\frac{\\partial}{\\partial x}, \\frac{\\partial^{2}}{\\partial x^{2}}\\right]$\n\t(ii) $\\left[\\frac{\\partial}{\\partial x}, F(x)\\right]$\n\\end{exercise}\n\\begin{answer}\n(i) $\\left[\\frac{\\partial}{\\partial x}, \\frac{\\partial^{2}}{\\partial x^{2}}\\right] \\psi=\\left(\\frac{\\partial}{\\partial x} \\frac{\\partial^{2}}{\\partial x^{2}}-\\frac{\\partial^{2}}{\\partial x^{2}} \\frac{\\partial}{\\partial x}\\right) \\psi=\\left(\\frac{\\partial^{3}}{\\partial x^{3}}-\\frac{\\partial^{3}}{\\partial x^{3}}\\right) \\psi=0$\\\\\n(ii) $\\left[\\frac{\\partial}{\\partial x}, F(x)\\right] \\psi=\\frac{\\partial}{\\partial x}(F \\psi)-F \\frac{\\partial}{\\partial x} \\psi=\\frac{\\partial F}{\\partial x} \\psi+F \\frac{\\partial \\psi}{\\partial x}-F \\frac{\\partial \\psi}{\\partial x}=\\frac{\\partial F}{\\partial x} \\psi$\\\\\nThus, $\\left[\\frac{\\partial}{\\partial x}, F(x)\\right]=\\frac{\\partial F}{\\partial x}$\t\n\\end{answer}\n\\begin{exercise}\n\tIf Hamiltonian of system is $H=\\frac{p_{x}^{2}}{2 m}+V(x)$ then Find commutation $[H, x]$ and $[[H, x], x]$\n\\end{exercise}\n\\begin{answer}\n As, $H=p^{2} / 2 m+V(x)$\\\\\nWe have, $[H, x]=\\frac{1}{2 m}\\left[p^{2}, x\\right]=-i \\hbar p / m$ \\\\\nand so, $[[H, x], x]=\\frac{i \\hbar}{m}[p, x]=-\\hbar^{2} / m$\\\\\n Hence, $\\langle m|[[H, x] x]| m\\rangle=-\\frac{\\hbar^{2}}{m}$\t\n\\end{answer}\n\\subsection{Functions of operators}\n\\textbf{Commutators involving function operators}\\\\\nIf $\\hat{A}$ commutes with another operator $\\hat{B}$, then $\\hat{B}$ commutes with any operator function that depends on $\\hat{A}$ :\n$$\n[\\hat{A}, \\hat{B}]=0 \\quad \\Longrightarrow \\quad[\\hat{B}, F(\\hat{A})]=0 ;\n$$\nin particular, $F(\\hat{A})$ commutes with $\\hat{A}$ and with any other function, $G(\\hat{A})$, of $\\hat{A}$ :\n$$\n[\\hat{A}, F(\\hat{A})]=0, \\quad\\left[\\hat{A}^{n}, F(\\hat{A})\\right]=0, \\quad[F(\\hat{A}), G(\\hat{A})]=0 .\n$$\n\\subsection{Inverse and unitary operators}\n\\textbf{Inverse of an operator}\\\\\n Assuming it exists the inverse $\\hat{A}^{-1}$ of a linear operator $A$ is defined by the relation\n$$\n\\hat{A}^{-1} \\hat{A}=\\hat{A} \\hat{A}^{-1}=\\hat{I},\n$$\nwhere $\\hat{I}$ is the unit operator, the operator that leaves any state $|\\psi\\rangle$ unchanged.\\\\\n\\textbf{Unitary operator}\\\\\n A linear operator $\\hat{U}$ is said to be unitary if its inverse $\\hat{U}^{-1}$ is equal to its adjoint $\\hat{U}^{\\dagger}$ :\n$$\n\\hat{U}^{\\dagger}=\\hat{U}^{-1} \\quad \\text { or } \\quad \\hat{U} \\hat{U}^{\\dagger}=\\hat{U}^{\\dagger} \\hat{U}=\\hat{I} .\n$$\nThe product of two unitary operators is also unitary, since\n$$\n(\\hat{U} \\hat{V})(\\hat{U} \\hat{V})^{\\dagger}=(\\hat{U} \\hat{V})\\left(\\hat{V}^{\\dagger} \\hat{U}^{\\dagger}\\right)=\\hat{U}\\left(\\hat{V} \\hat{V}^{\\dagger}\\right) \\hat{U}^{\\dagger}=\\hat{U} \\hat{U}^{\\dagger}=\\hat{I},\n$$\nor $(\\hat{U} \\hat{V})^{\\dagger}=(\\hat{U} \\hat{V})^{-1}$. This result can be generalized to any number of operators; the product of a number of unitary operators is also unitary, since\n$$\n\\begin{aligned}\n(\\hat{A} \\hat{B} \\hat{C} \\hat{D} \\cdots)(\\hat{A} \\hat{B} \\hat{C} \\hat{D} \\cdots)^{\\dagger} &=\\hat{A} \\hat{B} \\hat{C} \\hat{D}(\\cdots) \\hat{D}^{\\dagger} \\hat{C}^{\\dagger} \\hat{B}^{\\dagger} \\hat{A}^{\\dagger}=\\hat{A} \\hat{B} \\hat{C}\\left(\\hat{D} \\hat{D}^{\\dagger}\\right) \\hat{C}^{\\dagger} \\hat{B}^{\\dagger} \\hat{A}^{\\dagger} \\\\\n&=\\hat{A} \\hat{B}\\left(\\hat{C} \\hat{C}^{\\dagger}\\right) \\hat{B}^{\\dagger} \\hat{A}^{\\dagger}=\\hat{A}\\left(\\hat{B} \\hat{B}^{\\dagger}\\right) \\hat{A}^{\\dagger} \\\\\n&=\\hat{A} \\hat{A}^{\\dagger}=\\hat{l}\n\\end{aligned}\n$$\n\\subsection{Eigen value and eigen vector of an operator}\nA state vector $|\\psi\\rangle$ is said to be an eigenvector (also called an eigenket or eigenstate) of an operator $\\hat{A}$ if the application of $\\hat{A}$ to $|\\psi\\rangle$ gives\n$$\n\\hat{A}|\\psi\\rangle=a|\\psi\\rangle,\n$$\nwhere $a$ is a complex number, called an eigenvalue of $\\hat{A}$. This equation is known as the eigenvalue equation, or eigenvalue problem, of the operator $\\hat{A}$. Its solutions yield the eigenvalues and eigenvectors of $\\hat{A}$.\n\\begin{exercise}\n\t$\\text { Show that if } \\hat{A}^{-1} \\text { exists, the eigenvalues of } \\hat{A}^{-1} \\text { are just the inverses of those of } \\hat{A} \\text {. }$\n\\end{exercise}\n\\begin{answer}\nSince $\\hat{A}^{-1} \\hat{A}=\\hat{I}$ we have on the one hand\n$$\n\\hat{A}^{-1} \\hat{A}|\\psi\\rangle=|\\psi\\rangle,\n$$\nand on the other hand\n$$\n\\hat{A}^{-1} \\hat{A}|\\psi\\rangle=\\hat{A}^{-1}(\\hat{A}|\\psi\\rangle)=a \\hat{A}^{-1}|\\psi\\rangle .\n$$\nCombining the previous two equations, we obtain\n$$\na \\hat{A}^{-1}|\\psi\\rangle=|\\psi\\rangle,\n$$\t\nhence\n$$\n\\hat{A}^{-1}|\\psi\\rangle=\\frac{1}{a}|\\psi\\rangle\n$$\nThis means that $|\\psi\\rangle$ is also an eigenvector of $\\hat{A}^{-1}$ with eigenvalue $1 / a$. That is, if $\\hat{A}^{-1}$ exists, then\n$$\n\\hat{A}|\\psi\\rangle=a|\\psi\\rangle \\quad \\Longrightarrow \\quad \\hat{A}^{-1}|\\psi\\rangle=\\frac{1}{a}|\\psi\\rangle .\n$$\n\\end{answer}\n\\section{Theorems} \n\\begin{theorem}\nFor an Hermitian operator ,all of its eigen values are real and the eigen vectors corresponding to different eigen values are orthogonal.\t\\\\\nIf $\\hat{A}^{\\dagger}=\\hat{A}, \\hat{A}|\\phi_{n}\\rangle =a_n |\\phi_{n}\\rangle \\implies a_n=\\text{real number }$\\\\\nand\\\\\n$\\langle \\phi_{m}\\mid \\phi_{n}\\rangle=\\delta_{mn}$\n\\end{theorem}\n\\begin{theorem}\nIf two Hermitian operators, $\\hat{A}$ and $\\hat{B}$, commute and if $\\hat{A}$ has no degenerate eigenvalue, then each eigenvector of $\\hat{A}$ is also an eigenvector of $\\hat{B}$. In addition, we can construct a common orthonormal basis that is made of the joint eigenvectors of $\\hat{A}$ and $\\hat{B}$.\n\\end{theorem}\n\\begin{theorem}\n The eigenvalues of an anti-Hermitian operator are either purely imaginary or equal to zero.\n\\end{theorem}\n\\begin{theorem}\n\t The eigenvalues of a unitary operator are complex numbers of moduli equal to one; the eigenvectors of a unitary operator that has no degenerate eigenvalues are mutually orthogonal.\n\\end{theorem}\n\\section{Wavefunction in coordinate and momentum representations}\nWe have $$xp-px=i\\hbar$$\nSo $$\\langle x\\mid xp-px\\mid x^{\\prime}\\rangle=i\\hbar\\langle x\\mid x^{\\prime}\\rangle$$\n$$x\\langle x |p|x^{\\prime}\\rangle -\\langle x |p|x^{\\prime}\\rangle x^{\\prime}=i\\hbar \\delta(x-x^{\\prime})$$\n$$\\langle x|p|x^{\\prime}\\rangle =i\\hbar \\frac{\\delta(x-x^{\\prime})}{x-x^{\\prime}}$$\nWe have $-\\frac{\\delta(x)}{x}=\\delta^{\\prime}(x)$\\\\\n$$\\langle x|p|x^{\\prime}\\rangle=-i\\hbar \\frac{\\partial}{\\partial x}\\delta(x-x^{\\prime})$$\nSo similarly $$\\langle x|p|\\psi(t)\\rangle=-i\\hbar\\frac{\\partial}{\\partial x} \\langle|\\psi(t)\\rangle$$\n$$\\langle x|p|\\psi(t)\\rangle=-i\\hbar \\frac{\\partial }{\\partial x}\\psi(x,t)$$\nSo the momentum operator in position basis \\\\\n$$\\hat{P}=-i\\hbar \\frac{\\partial}{\\partial x}$$\nNow let us find the expression of position operator in the momentum basis \\\\\n$$\\langle p|xp-px|p^{\\prime}\\rangle =i\\hbar \\delta (p-p^{\\prime})$$\n$$p|px-xp|p^{\\prime}\\rangle =-i\\hbar \\delta(p-p^{\\prime})$$\\\\\n$$p\\langle p|x|p^{\\prime}\\rangle -\\langle p|x|p^{\\prime}\\rangle p^{\\prime}=-i\\hbar\\delta(p-p^{\\prime})$$\n$$\\langle p|x|p^{\\prime}\\rangle=+i\\hbar\\frac{\\partial}{\\partial x}\\delta(p-p^{\\prime})$$\nSo $$\\langle p|x|\\psi(t)\\rangle =i\\hbar\\frac{\\partial}{\\partial p} \\langle p|\\psi(t)\\rangle=i\\hbar\\frac{\\partial}{\\partial p}\\psi (p,t)$$\\\\\nie $\\hat{x}=i\\hbar\\frac{\\partial}{\\partial p}$ in momentum space\\\\\nSo in three dimension \\\\\nposition space\\\\\n$\\hat{p}=-i\\hbar \\nabla_{r}$\\\\\n$\\hat{x}=x$\nMomentum space\\\\\n$\\hat{p}=p$\\\\\n$\\hat{x}=i\\hbar \\nabla_{p}$\\\\\nNow let us check whether momentum is self adjoint\\\\\n$\\int_{-\\infty}^{+\\infty} f^*(x)\\left( -i\\hbar \\frac{\\partial}{\\partial x}g(x)\\right)dx=-i\\hbar\\left\\lbrace  \\left[ f^{*}(x)g(x) \\right]_{-\\infty}^{+\\infty}-\\int_{-\\infty}^{+\\infty} g(x)\\frac{\\partial}{\\partial x}f^*(x)dx\\right\\rbrace $\\\\\n$=i\\hbar \\int \\frac{\\partial}{\\partial x} f^*(x) g(x)dx$\n$=\\int\\left( -i\\hbar \\frac{\\partial}{\\partial x}f(x)\\right) ^{\\dagger}g(x)dx$\n$=\\int(pf)^{\\dagger}g dx$\nSo momentum is hermitian .\\\\\nSince -i$\\hbar\\implies i\\hbar;\\frac{\\partial}{\\partial x} \\implies -\\frac{\\partial}{\\partial x}$ to keep momentum operator hermitian,so $ \\frac{\\partial}{\\partial x}$ is anti hermitian.\\\\\nSo $\\left( \\frac{d^n}{dx^n}\\right) ^{\\dagger}=(-1)^n \\left( \\frac{d^n}{dx^n}\\right)$\\\\\nIts a good position to discuss the time evolution of a state vector .The time evolution of the state vector is prescribed by the rule called schrodinger equation which is given as \\\\\n$$i\\hbar \\frac{d}{dt}|\\psi(t)\\rangle =\\hat{H}|\\psi(t)\\rangle $$\nThis is not an eigen value equation since $\\hat{H}$ is an operator.\\\\\nSince we are only dealing with autonomous system $\\hat{H}$ is explicitly time independant.So we can write the formal solution \\\\\n$$|\\psi(t) \\rangle =e^{-\\frac{i}{\\hbar}\\hat{H(t)}} |\\psi(o)\\rangle $$\nor $$|\\psi(t) \\rangle =e^{\\frac{-i}{\\hbar}\\hat{H}(t-t_0)} |\\psi(t_0)\\rangle$$\nLet's denote $e^{\\frac{-i}{\\hbar}\\hat{H}(t-t_0)}$ as U.\nNow $$(U^{\\dagger})=e^{\\frac{i}{\\hbar}\\hat{H}(t-t_0)}=U^{-1}$$\nie $$U^{\\dagger}U^{-1}=U^{-1}U=I\\implies \\text{ unitary operator }$$\nIt is interesting thing is that even in non-automonous system time evolution operator is unitary operator.,but formal solution went be this \\\\\nIf the system changes from $t_O t0 t_2$\\\\\nThen $$U(t_2,t_0)=U(t_2,t_1)U(t_1,t_0)$$\nProduct of unitary operator is unitary \\\\\nIf we normalized $|\\psi(0)\\rangle$ would it be preserved in time evolution.\\\\\n$$|\\psi(t) \\rangle =e^{-\\frac{i}{\\hbar}\\hat{H(t)}} |\\psi(o)\\rangle $$\nSo $$\\langle \\psi(t)|=\\langle \\psi(0)|e^{\\frac{i}{\\hbar}\nH^{\\dagger}t}$$\nSo $$\\langle \\psi(t)\\mid \\psi(t)\\rangle=\\langle \\psi(o)|e^{\\frac{i}{\\hbar}H^{\\dagger}t}e^{\\frac{-i}{\\hbar}H^{\\dagger}t}\\mid \\psi(o)\\rangle$$ \nRemember $$e^{\\hat{A}}e^{\\hat{B}}=e^{\\hat{A}+\\hat{B}}$$\n Iff $$\\left[ A,B\\right] =0$$\n$ \\left[ H^{\\dagger},H\\right] =0$ Since H is hermitian.\\\\\nSo $$\\langle \\psi(t)\\mid \\psi(t)\\rangle=\\langle \\psi_{0}|\\psi_{0}\\rangle$$\nIe probability is conserved in time evolution as in classical mechanics.(liouville's thoerem).The preservation of probality follows from the unitary of the time evolution operator.\\\\\nNow we have studied the schrodinger equation in the abstract basis .Then how does it look like in position basis.\\\\\nwe have \\\\\n\\begin{align*}\ni\\hbar \\frac{d}{dt}|\\psi(t)\\rangle &=\\hat{H}|\\psi(t)\\rangle \\\\\n\\intertext{with} \\hat{H}&=\\frac{p^2}{2m}+V(r)\\\\\n\\intertext{in position basis (3-D)}\\\\\n\\langle r|i\\hbar \\frac{d}{dt}|\\psi(t)\\rangle&=\\langle r|\\hat{H}|\\psi(t)\\rangle\\\\\ni\\hbar \\frac{d}{dt}\\langle |\\psi(t)\\rangle&=\\langle r|\\frac{p^2}{2m}+V(r)|\\psi(t)\\rangle\\\\\ni\\hbar\\frac{\\partial}{\\partial t}\\psi(r,t)&=-\\frac{\\hbar^2}{2m} \\nabla^2\\langle r|\\psi(t)\\rangle+\\langle r|v(r)|\\psi(t)\\rangle\\\\\n&=-\\frac{\\hbar^2}{2m}\\nabla^2\\psi(r,t)+v(r)\\psi(r,t)\\\\\ni\\hbar \\frac{\\partial}{\\partial t}\\psi(r,t)&=-\\frac{\\hbar^2}{2m} \\nabla^2 \\psi(r,t)+v(r)\\psi(r,t)\\\\\n\\intertext{This is partial differential equation,first order in time.}\n\\end{align*}\nLet's calculate\n\\begin{align*}\n\\langle x|\\hat{P}|x^{\\prime}&=\\langle x|-i\\hbar \\frac{\\partial}{\\partial x}|x^{\\prime}\\\\\n&=-i\\hbar \\frac{\\partial}{\\partial x} \\langle x|x^{\\prime} \\rangle\\\\\n\\intertext{similarly}\\\\\n\\langle x|\\hat{P}|\\hat{P}\\rangle&=-i\\hbar \\frac{\\partial}{\\partial x}\\langle x|p\\rangle\\\\\np\\langle x|\\hat{P}\\rangle&=-i\\hbar\\frac{\\partial}{\\partial x} \\langle x|p\\rangle\\\\\n\\frac{\\partial \\langle x|p\\rangle}{\\langle x|\\hat{p}\\rangle}&=\\frac{p}{-i\\hbar}\\partial x\\\\\n\\langle x|p\\rangle &\\propto e^{\\frac{ipx}{\\hbar}}\\\\\n\\langle p|x\\rangle &\\propto e^{\\frac{-ipx}{\\hbar}}\\\\\n\\intertext{so we get}\n\\psi(x,t)&=\\int_{-\\infty}^{+\\infty} dp\\langle x|p\\rangle \\hat{\\psi}(p,t)\\\\\n\\psi(x,t)&=\\frac{1}{\\sqrt{2\\pi \\hbar}}\\int_{-\\infty}^{+\\infty} dp e^{ipx} \\vec{\\psi}(p,t)\\\\\n\\vec{\\psi}(p,t)&=\\frac{1}{\\sqrt{2\\pi \\hbar}} \\int_{-\\infty}^{+\\infty}dxe^{-ipx} \\psi(x,t)\\\\\n\\end{align*}\nIn 3-D\\\\\n$$\\psi(r,t)=\\frac{1}{(2\\pi \\hbar)^{3/2}}\\int_{-\\infty}^{+\\infty}d^3r e^{\\frac{i\\vec{p}\\cdot \\vec{r}}{\\hbar}} \\vec{\\psi}(p,t)$$\n$$\\vec{\\psi}(p,t)=\\frac{1}{(2\\pi \\hbar)^{3/2}}\\int_{-\\infty}^{+\\infty}d^3p e^{\\frac{-i\\vec{p}\\cdot \\vec{r}}{\\hbar}} \\psi(x,t)$$\nTurns out that momentum space wave function is the fourier transform of the position space wave function.\\\\\nParsevals theorem guarantee that\\\\\n$$\\int_{-\\infty}^{+\\infty} d^3p |\\psi(p,t)|^2=\\int_{-\\infty}^{+\\infty} d^3r |\\psi(r,t)|^2$$\nie if wavefunction is normalized in position space it will be normalized in momentum space.\n\\section{Parity operator}\nThe space reflection about the origin of the coordinate system is called inversion or a parity operation.This transformation is descrete.The parity operator $\\hat{P}$ is defined by its action on the ket $|\\vec{r}\\rangle$ of the position space:\n$$\\hat{P}|\\vec{r}\\rangle =|\\vec{-r}\\rangle$$\nsuch that \n $$\\hat{P}\\psi(\\vec{r})=\\psi(-\\vec{r})$$\n \\begin{note}\n \t\\begin{itemize}\n \t\t\\item Parity operator is Hermitian $\\vec{P}^{\\dagger}=\\vec{P}$\n \t\t\\item From the definition we have\\\\\n \t\t$$\\vec{P}^2 \\psi(\\vec{r})=\\vec{P}\\psi(-\\vec{r})=\\psi(\\vec{r})$$\n \t\tHence $\\vec{P}^2$ is equal to the unity operator\n \t\t$$\\vec{P}^2=I or \\vec{P}=\\vec{P}^{-1}$$\n \t\t\\item The parity operator is therefore unitary, since its Hermitian adjoint is equal to its inverse.\\\\\n \t\t$$\\vec{P}^{\\dagger}=\\vec{P}^{-1}$$ \n \t\t\\item Now, since $\\hat{P}^{2}=\\hat{I}$, the eigenvalues of $\\hat{P}$ are $+1$ or $-I$ with the corresponding eigenstates\n \t\t$$\n \t\t\\hat{P} \\psi_{+}(\\vec{r})=\\psi_{+}(-\\vec{r})=\\psi_{+}(\\vec{r}), \\quad \\hat{P} \\psi_{-}(\\vec{r})=\\psi_{-}(-\\vec{r})=-\\psi_{-}(\\vec{r}) .\n \t\t$$\n \t\tThe eigenstate $\\left|\\psi_{+}\\right\\rangle$is said to be even and $\\left|\\psi_{-}\\right\\rangle$is odd. Therefore, the eigenfunctions of the parity operator have definite parity: they are either even or odd.\n \t\t\\item \\textbf{Even and odd operators}\\\\\n \t\tAn operator $\\hat{A}$ is said to be $e v e n$ if it obeys the condition\n \t\t$$\n \t\t\\hat{P} \\hat{A} \\hat{P}=\\hat{A}\n \t\t$$\n \t\tand an operator $\\hat{B}$ is odd if\n \t\t$$\n \t\t\\hat{P} \\hat{B} \\hat{P}=-\\hat{B}\n \t\t$$\n \t\tWe can easily verify that even operators commute with the parity operator $\\hat{P}$ and that odd operators anticommute with $\\hat{P}$ :\n \t\t$$\n \t\t\\begin{aligned}\n \t\t\\hat{A} \\hat{P} &=(\\hat{P} \\hat{A} \\hat{P}) \\hat{P}=\\hat{P} \\hat{A} \\hat{P}^{2}=\\hat{P}\\hat{A} \\\\\n \t\t\\hat{B} \\hat{P} &=-(\\hat{P} \\hat{B} \\hat{P}) \\hat{P}=-\\hat{P} \\hat{B} \\hat{P}^{2}=-\\hat{P} \\hat{B}\n \t\t\\end{aligned}\n \t\t$$\n \t\\end{itemize}\n \\end{note}\n\n\\newpage \n\\begin{abox}\n\tPractice set 1\n\t\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\\item Consider a particle in a one dimensional potential that satisfies $V(x)=V(-x)$. Let $\\left|\\psi_{0}\\right\\rangle$ and $\\left|\\psi_{1}\\right\\rangle$ denote the ground and the first excited states, respectively, and let $|\\psi\\rangle=\\alpha_{0}\\left|\\psi_{0}\\right\\rangle+\\alpha_{1}\\left|\\psi_{1}\\right\\rangle$ be a normalized state with $\\alpha_{0}$ and $\\alpha_{1}$ being real constants. The expectation value $\\langle x\\rangle$ of the position operator $x$ in the state $|\\psi\\rangle$ is given by\n\t\\exyear{NET DEC 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\alpha_{0}^{2}\\left\\langle\\psi_{0}|x| \\psi_{0}\\right\\rangle+\\alpha_{1}^{2}\\left\\langle\\psi_{1}|x| \\psi_{1}\\right\\rangle$\n\t\\task[\\textbf{B.}]$\\alpha_{0} \\alpha_{1}\\left[\\left\\langle\\psi_{0}|x| \\psi_{1}\\right\\rangle+\\left\\langle\\psi_{1}|x| \\psi_{0}\\right\\rangle\\right]$\n\t\\task[\\textbf{C.}]$\\alpha_{0}^{2}+\\alpha_{1}^{2}$\n\t\\task[\\textbf{D.}]$2 \\alpha_{0} \\alpha_{1}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The wave function of a particle at time $t=0$ is given by $|\\psi(0)\\rangle=\\frac{1}{\\sqrt{2}}\\left(\\left|u_{1}\\right\\rangle+\\left|u_{2}\\right\\rangle\\right)$, where\n\t$\\left|u_{1}\\right\\rangle$ and $\\left|u_{2}\\right\\rangle$ are the normalized eigenstates with eigenvalues $E_{1}$ and $E_{2}$ respectively, $\\left(E_{2}>E_{1}\\right)$. The shortest time after which $|\\psi(t)\\rangle$ will become orthogonal to $|\\psi(0)\\rangle$ is\n\t\\exyear{NET DEC 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{-\\hbar \\pi}{2\\left(E_{2}-E_{1}\\right)}$\n\t\\task[\\textbf{B.}]$\\frac{\\hbar \\pi}{E_{2}-E_{1}}$\n\t\\task[\\textbf{C.}]$\\frac{\\sqrt{2} \\hbar \\pi}{E_{2}-E_{1}}$\n\t\\task[\\textbf{D.}]$\\frac{2 \\hbar \\pi}{E_{2}-E_{1}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { The commutator }\\left[x^{2}, p^{2}\\right] \\text { is }$\n\t\\exyear{NET JUNE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $2 i \\hbar x p$\n\t\\task[\\textbf{B.}]$2 i \\hbar(x p+p x)$\n\t\\task[\\textbf{C.}]$2 i \\hbar p x$\n\t\\task[\\textbf{D.}]$2 i \\hbar(x p-p x)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Which of the following is a self-adjoint operator in the spherical polar coordinate system $(r, \\theta, \\phi)$ ?\n\t\\exyear{NET JUNE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\frac{i \\hbar}{\\sin ^{2} \\theta} \\frac{\\partial}{\\partial \\theta}$\n\t\\task[\\textbf{B.}]$-i \\hbar \\frac{\\partial}{\\partial \\theta}$\n\t\\task[\\textbf{C.}] $-\\frac{i \\hbar}{\\sin \\theta} \\frac{\\partial}{\\partial \\theta}$\n\t\\task[\\textbf{D.}] $-i \\hbar \\sin \\theta \\frac{\\partial}{\\partial \\theta}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Given the usual canonical commutation relations, the commutator $[A, B]$ of $A=i\\left(x p_{y}-y p_{x}\\right)$ and $B=\\left(y p_{z}+z p_{y}\\right)$ is\n\t\\exyear{NET DEC 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\hbar\\left(x p_{z}-p_{x} z\\right)$\n\t\\task[\\textbf{B.}]$-\\hbar\\left(x p_{z}-p_{x} z\\right)$\n\t\\task[\\textbf{C.}]$\\hbar\\left(x p_{z}+p_{x} z\\right)$\n\t\\task[\\textbf{D.}]$-\\hbar\\left(x p_{z}+p_{x} z\\right)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item If the operators $A$ and $B$ satisfy the commutation relation $[A, B]=I$, where $I$ is the identity operator, then\n\t\\exyear{NET JUNE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left[e^{A}, B\\right]=e^{A}$\n\t\\task[\\textbf{B.}]$\\left[e^{A}, B\\right]=\\left[e^{B}, A\\right]$\n\t\\task[\\textbf{C.}]$\\left[e^{A}, B\\right]=\\left[e^{-B}, A\\right]$\n\t\\task[\\textbf{D.}]$\\left[e^{A}, B\\right]=I$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Suppose Hamiltonian of a conservative system in classical mechanics is $H=\\omega x p$, where $\\omega$ is a constant and $x$ and $p$ are the position and momentum respectively. The corresponding Hamiltonian in quantum mechanics, in the coordinate representation, is\n\t\\exyear{NET DEC 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-i \\hbar \\omega\\left(x \\frac{\\partial}{\\partial x}-\\frac{1}{2}\\right)$\n\t\\task[\\textbf{B.}]$-i \\hbar \\omega\\left(x \\frac{\\partial}{\\partial x}+\\frac{1}{2}\\right)$\n\t\\task[\\textbf{C.}] $-i \\hbar \\omega x \\frac{\\partial}{\\partial x}$\n\t\\task[\\textbf{D.}]$-\\frac{i \\hbar \\omega}{2} \\times \\frac{\\partial}{\\partial x}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Let $x$ and $p$ denote, respectively, the coordinate and momentum operators satisfying the canonical commutation relation $[x, p]=i$ in natural units $(\\hbar=1)$. Then the commutator $\\left[x, p e^{-p}\\right]$ is\n\t\\exyear{NET DEC 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i(1-p) e^{-p}$\n\t\\task[\\textbf{B.}]$i\\left(1-p^{2}\\right) e^{-p}$\n\t\\task[\\textbf{C.}]$i\\left(1-e^{-p}\\right)$\n\t\\task[\\textbf{D.}]ipe $^{-p}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The wavefunction of a particle in one-dimension is denoted by $\\psi(x)$ in the coordinate representation and by $\\phi(p)=\\int \\psi(x) e^{\\frac{-i p x}{\\hbar}} d x$ in the momentum representation. If the action of an operator $\\hat{T}$ on $\\psi(x)$ is given by $\\hat{T} \\psi(x)=\\psi(x+a)$, where $a$ is a constant then $\\hat{T} \\phi(p)$ is given by\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\frac{i}{\\hbar} \\operatorname{ap} \\phi(p)$\n\t\\task[\\textbf{B.}]$e^{\\frac{-i a p}{\\hbar}} \\phi(p)$\n\t\\task[\\textbf{C.}]$e^{\\frac{+i a p}{\\hbar}} \\phi(p)$\n\t\\task[\\textbf{D.}]$\\left(1+\\frac{i}{\\hbar} a p\\right) \\phi(p)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Two different sets of orthogonal basis vectors $\\left\\{\\left(\\begin{array}{l}1 \\\\ 0\\end{array}\\right),\\left(\\begin{array}{l}0 \\\\ 1\\end{array}\\right)\\right\\}$ and $\\left\\{\\frac{1}{\\sqrt{2}}\\left(\\begin{array}{l}1 \\\\ 1\\end{array}\\right), \\frac{1}{\\sqrt{2}}\\left(\\begin{array}{c}1 \\\\ -1\\end{array}\\right)\\right\\}$ are given for a two dimensional real vector space. The matrix representation of a linear operator $\\hat{A}$ in these basis are related by a unitary transformation. The unitary matrix may be chosen to be\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left(\\begin{array}{cc}0 & -1 \\\\ 1 & 0\\end{array}\\right)$\n\t\\task[\\textbf{B.}]$\\left(\\begin{array}{ll}0 & 1 \\\\ 1 & 0\\end{array}\\right)$\n\t\\task[\\textbf{C.}]$\\frac{1}{\\sqrt{2}}\\left(\\begin{array}{cc}1 & 1 \\\\ 1 & -1\\end{array}\\right)$\n\t\\task[\\textbf{D.}] $\\frac{1}{\\sqrt{2}}\\left(\\begin{array}{ll}1 & 0 \\\\ 1 & 1\\end{array}\\right)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A Hermitian operator $\\hat{O}$ has two normalized eigenstates $|1\\rangle$ and $|2\\rangle$ with eigenvalues 1 and 2 , respectively. The two states $|u\\rangle=\\cos \\theta|1\\rangle+\\sin \\theta|2\\rangle$ and $|v\\rangle=\\cos \\phi|1\\rangle+\\sin \\phi|2\\rangle$ are such that $\\langle v|\\hat{O}| v\\rangle=7 / 4$ and $\\langle u \\mid v\\rangle=0$. Which of the following are possible values of $\\theta$ and $\\phi$ ?\n\t\\exyear{NET DEC 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\theta=-\\frac{\\pi}{6}$ and $\\phi=\\frac{\\pi}{3}$\n\t\\task[\\textbf{B.}]$\\theta=\\frac{\\pi}{6}$ and $\\phi=\\frac{\\pi}{3}$\n\t\\task[\\textbf{C.}]$\\theta=-\\frac{\\pi}{4}$ and $\\phi=\\frac{\\pi}{4}$\n\t\\task[\\textbf{D.}]$\\theta=\\frac{\\pi}{3}$ and $\\phi=-\\frac{\\pi}{6}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item If $\\hat{L}_{x}, \\hat{L}_{y}, \\hat{L}_{z}$ are the components of the angular momentum operator in three dimensions the commutator $\\left[\\hat{L}_{x}, \\hat{L}_{x} \\hat{L}_{y} \\hat{L}_{z}\\right]$ may be simplified to\n\t\\exyear{NET JUNE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\hbar L_{x}\\left(\\hat{L}_{z}^{2}-\\hat{L}_{y}^{2}\\right)$\n\t\\task[\\textbf{B.}]$i \\hbar \\hat{L}_{z} \\hat{L}_{y} \\hat{L}_{x}$\n\t\\task[\\textbf{C.}]$i \\hbar L_{x}\\left(2 \\hat{L}_{z}^{2}-\\hat{L}_{y}^{2}\\right)$\n\t\\task[\\textbf{D.}]0\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider the operator, $a=x+\\frac{d}{d x}$ acting on smooth function of $x$. Then commutator $[\\alpha, \\cos x]$ is\n\t\\exyear{NET DEC 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\sin x$\n\t\\task[\\textbf{B.}]$\\cos x$\n\t\\task[\\textbf{C.}]$-\\cos x$\n\t\\task[\\textbf{D.}]0\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider the operator $\\vec{\\pi}=\\vec{p}-q \\vec{A}$, where $\\vec{p}$ is the momentum operator, $\\vec{A}=\\left(A_{x}, A_{y}, A_{z}\\right)$ is the vector potential and $q$ denotes the electric charge. If $\\vec{B}=\\left(B_{x}, B_{y}, B_{z}\\right)$ denotes the magnetic field, the $z$-component of the vector operator $\\vec{\\pi} \\times \\vec{\\pi}$ is\n\t\\exyear{NET DEC 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i q \\hbar B_{z}+q\\left(A_{x} p_{y}-A_{y} p_{x}\\right)$\n\t\\task[\\textbf{B.}]$-i q \\hbar B_{z}-q\\left(A_{x} p_{y}-A_{y} p_{x}\\right)$\n\t\\task[\\textbf{C.}]$-i q \\hbar B_{2}$\n\t\\task[\\textbf{D.}] $i q \\hbar B_{z}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { The two vectors }\\left(\\begin{array}{l}\n\ta \\\\\n\t0\n\t\\end{array}\\right) \\text { and }\\left(\\begin{array}{l}\n\tb \\\\\n\tc\n\t\\end{array}\\right) \\text { are orthonormal if }$\n\t\\exyear{NET JUNE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $a=\\pm 1, b=\\pm 1 / \\sqrt{2}, c=\\pm 1 / \\sqrt{2}$\n\t\\task[\\textbf{B.}] $a=\\pm 1, b=\\pm 1, c=0$\n\t\\task[\\textbf{C.}]$a=\\pm 1, b=0, c=\\pm 1$\n\t\\task[\\textbf{D.}] $a=\\pm 1, b=\\pm 1 / 2, c=1 / 2$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Let $x$ denote the position operator and $p$ the canonically conjugate momentum operator of a particle. The commutator\n\t$$\n\t\\left[\\frac{1}{2 m} p^{2}+\\beta x^{2}, \\frac{1}{m} p^{2}+\\gamma x^{2}\\right]\n\t$$\n\twhere $\\beta$ and $\\gamma$ are constants, is zero if\n\t\\exyear{NET DEC 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\gamma=\\beta$\n\t\\task[\\textbf{B.}]$\\gamma=2 \\beta$\n\t\\task[\\textbf{C.}]$\\gamma=\\sqrt{2} \\beta$\n\t\\task[\\textbf{D.}]$2 \\gamma=\\beta$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider the operator $A_{x}=L_{y} p_{z}-L_{z} p_{y}$, where $L_{i}$ and $p_{i}$ denote, respectively, the components of the angular momentum and momentum operators. The commutator $\\left[A_{x}, x\\right]$ where $x$ is the $x$ - component of the position operator, is\n\t\\exyear{NET DEC 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-i \\hbar\\left(z p_{z}+y p_{y}\\right)$\n\t\\task[\\textbf{B.}]$-i \\hbar\\left(z p_{z}-y p_{y}\\right)$\n\t\\task[\\textbf{C.}]$i \\hbar\\left(z p_{z}+y p_{y}\\right)$\n\t\\task[\\textbf{D.}]$i \\hbar\\left(z p_{z}-y p_{y}\\right)$\n\\end{tasks}\n\\end{enumerate}\n\n\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{b}&2&\\textbf{b}\\\\\\hline\n\t\t3&\\textbf{b}&4&\\textbf{c}\\\\\\hline\n\t\t5&\\textbf{c}&6&\\textbf{a}\\\\\\hline\n\t\t7&\\textbf{b}&8&\\textbf{a}\\\\\\hline\n\t\t9&\\textbf{c}&10&\\textbf{c}\\\\\\hline\n\t\t11&\\textbf{a}&12&\\textbf{a}\\\\\\hline\n\t\t13&\\textbf{a}&14&\\textbf{d}\\\\\\hline\n\t\t15&\\textbf{c}&16&\\textbf{b}\\\\\\hline\n\t\t17&\\textbf{a}&&\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\\begin{abox}\n\tPractice set 2\n\t\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\t\\item The quantum mechanical operator for the momentum of a particle moving in one dimension is given by\n\t\t\\exyear{GATE 2011}\n\t\\end{minipage}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $i \\hbar \\frac{d}{d x}$\n\t\t\\task[\\textbf{B.}]$-i \\hbar \\frac{d}{d x}$\n\t\t\\task[\\textbf{C.}]$i \\hbar \\frac{\\partial}{\\partial t}$\n\t\t\\task[\\textbf{D.}]$-\\frac{\\hbar^{2}}{2 m} \\frac{d^{2}}{d x^{2}}$\n\t\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item If $L_{x}, L_{y}$ and $L_{z}$ are respectively the $x, y$ and $z$ components of angular momentum operator $L$. The commutator $\\left[L_{x} L_{y}, L_{z}\\right]$ is equal to\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\hbar\\left(L_{x}^{2}+L_{y}^{2}\\right)$\n\t\\task[\\textbf{B.}]$2 i \\hbar L_{z}$\n\t\\task[\\textbf{C.}]$i \\hbar\\left(L_{x}^{2}-L_{y}^{2}\\right)$\n\t\\task[\\textbf{D.}] 0\n\\end{tasks}\n\\textbf{common data questions 3 and 4 }\\\\\nIn a one-dimensional harmonic oscillator, $\\varphi_{0}, \\varphi_{1}$ and $\\varphi_{2}$ are respectively the ground, first and the second excited states. These three states are normalized and are orthogonal to one another $\\psi_{1}$ and $\\psi_{2}$ are two states defined by\n$$\n\\psi_{1}=\\varphi_{0}-2 \\varphi_{1}+3 \\varphi_{2}, \\psi_{2}=\\varphi_{0}-\\varphi_{1}+\\alpha \\varphi_{2}, \\psi_{2}=\\varphi_{0}-\\varphi_{1}+\\alpha \\varphi_{2}\n$$\nwhere $\\alpha$ is a constant\\\\\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { The value of } \\alpha \\text { which } \\psi_{2} \\text { is orthogonal to } \\psi_{1} \\text { is }$\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]2\n\t\\task[\\textbf{B.}]1\n\t\\task[\\textbf{C.}]-1\n\t\\task[\\textbf{D.}]-2\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item For the value of $\\alpha$ determined in $\\mathrm{Q} 3$, the expectation value of energy of the oscillator in the state $\\psi_{2}$ is\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] $\\hbar \\omega$\n\t\\task[\\textbf{B.}]$3 \\hbar \\omega / 2$ \n\t\\task[\\textbf{C.}]$3 \\hbar \\omega$\n\t\\task[\\textbf{D.}]$9 \\hbar \\omega / 2$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Which one of the following commutation relations is NOT CORRECT? Here, symbols have their usual meanings.\n\t\\exyear{GATE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left[L^{2}, L_{z}\\right]=0$\n\t\\task[\\textbf{B.}]$\\left\\lfloor L_{x}, L_{y}\\right\\rfloor=i \\hbar L_{z}$\n\t\\task[\\textbf{C.}]$\\left[L_{z}, L_{+}\\right]=\\hbar L_{+}$\n\t\\task[\\textbf{D.}] $\\left[L_{z}, L_{-}\\right]=\\hbar L_{-}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Let $\\vec{L}$ and $\\vec{p}$ be the angular and linear momentum operators, respectively, for a a particle. The commutator $\\left\\lfloor L_{x}, p_{y}\\right\\rfloor$ gives\n\t\\exyear{GATE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-i \\hbar p_{z}$\n\t\\task[\\textbf{B.}]0\n\t\\task[\\textbf{C.}]$i \\hbar p_{x}$\n\t\\task[\\textbf{D.}]$i \\hbar p_{z}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { Which of the following operators is Hermitian? }$\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{d}{d x}$\n\t\\task[\\textbf{B.}]$\\frac{d^{2}}{d x^{2}}$\n\t\\task[\\textbf{C.}]$i \\frac{d^{2}}{d x^{2}}$\n\t\\task[\\textbf{D.}]$\\frac{d^{3}}{d x^{3}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item If $x$ and $p$ are the $x$ components of the position and the momentum operators of a particle respectively, the commutator $\\left[x^{2}, p^{2}\\right]$ is\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\hbar(x p-p x)$\n\t\\task[\\textbf{B.}]$2 i \\hbar(x p-p x)$\n\t\\task[\\textbf{C.}]$i \\hbar(x p+p x)$\n\t\\task[\\textbf{D.}]$2 i \\hbar(x p+p x)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { For the parity operator } P, \\text { which of the following statements is NOT true? }$\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $P^{\\dagger}=P$\n\t\\task[\\textbf{B.}] $P^{2}=-P$\n\t\\task[\\textbf{C.}] $P^{2}=I$\n\t\\task[\\textbf{D.}]$P^{\\dagger}=P^{-1}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { Which one of the following operators is Hermitian? }$\n\t\\exyear{GATE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\frac{\\left(p_{x} x^{2}-x^{2} p_{x}\\right)}{2}$\n\t\\task[\\textbf{B.}]$i \\frac{\\left(p_{x} x^{2}+x^{2} p_{x}\\right)}{2}$\n\t\\task[\\textbf{C.}]$e^{i p_{x} a}$\n\t\\task[\\textbf{D.}]$e^{-i p_{x} a}$\n\\end{tasks}\n\\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{b}&2&\\textbf{c}\\\\\\hline\n\t\t3&\\textbf{c}&4&\\textbf{b}\\\\\\hline\n\t\t5&\\textbf{d}&6&\\textbf{d}\\\\\\hline\n\t\t7&\\textbf{b}&8&\\textbf{d}\\\\\\hline\n\t\t9&\\textbf{b}&10&\\textbf{a}\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractice set 3\n\t\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\\item If $\\left|\\phi_{1}\\right\\rangle$ and $\\left|\\phi_{2}\\right\\rangle$ be two orthonormal state vectors such that $A=\\left|\\phi_{1}\\right\\rangle\\left(\\phi_{2}|+| \\phi_{2}\\right\\rangle\\langle\\phi|$, then If $\\left|\\phi_{1}\\right\\rangle$ and $\\left|\\phi_{2}\\right\\rangle$ be two orthonormal state vectors such that $A=\\left|\\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}|+| \\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}\\right|$, then\\\\\n\t(a) Prove that $A$ is Hermitian\\\\\n\t(b) Find the value of $A^{2}$.\n\\end{minipage}\n\\begin{answer}\n(a) For $A$ to be a projection operator, $A$ should be Hermitian and $A^{2}$ should be equal to $A$. The Hermitian adjoint of $\\left|\\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}\\right|$ is $\\left|\\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}\\right|$ and that of $\\left|\\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}\\right|$ is $\\left|\\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}\\right|$. So\n\t\\begin{align*}\n\t&A^{\\dagger}=\\left[\\left|\\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}|+| \\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}\\right|\\right]^{\\dagger}=\\left[\\left|\\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}\\right|\\right]^{\\dagger}+\\left[\\left|\\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}\\right|\\right]^{\\dagger} \\\\\n\t&=\\left|\\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}|+| \\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}\\right|=A\n\t\\end{align*}\n\tHence $A$ is Hermitian.\\\\\n\\begin{align*}\n\t&\\text { Now, } \\quad A^{2}=\\left[\\left|\\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}|+| \\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}\\right|\\right]\\left[\\left|\\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}|+| \\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}\\right|\\right] \\\\\n\t&=\\left|\\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}\\left|\\left[\\left|\\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}|+| \\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}\\right|\\right]+\\right| \\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}\\right|\\left[\\left|\\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}|+| \\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}\\right|\\right] \\\\\n\t&=\\left[\\left|\\phi_{1}\\right\\rangle\\left\\langle\\phi_{2} \\mid \\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}|+| \\phi_{1}\\right\\rangle\\left\\langle\\phi_{2} \\mid \\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}\\right|\\right]+\\left[\\left|\\phi_{2}\\right\\rangle\\left\\langle\\phi_{1} \\mid \\phi_{1}\\right\\rangle\\left\\langle\\phi_{2}|+| \\phi_{2}\\right\\rangle\\left\\langle\\phi_{1} \\mid \\phi_{2}\\right\\rangle\\left\\langle\\phi_{1}\\right|\\right] \\\\\n\t&\\text { Since }\\left|\\phi_{1}\\right\\rangle \\text { and }\\left|\\phi_{2}\\right\\rangle \\text { are orthonormal, } \\\\\n\t&\\qquad A^{2}==\\left|\\phi_{1}\\right\\rangle\\left\\langle\\phi_{1}|+| \\phi_{2}\\right\\rangle\\left\\langle\\phi_{2}\\right|\n\\end{align*}\t\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item (a) Find the Eigen State of momentum operator $P_{x}=-i \\hbar \\frac{d}{d x}$. If eigen value is $\\lambda$ by relation $P_{x} \\phi=\\lambda \\phi$ where $\\frac{\\lambda}{\\hbar}=k$.\\\\\n\t(b) Expand the wave function $\\psi(x)=A \\sin k x \\sin 2 k x$ in basis of Eigen functions of momentum operator $P_{x}$\n\\end{minipage}\n\\begin{answer}\n\t$P_{x} \\phi=\\lambda \\phi \\text { where } \\frac{\\lambda}{\\hbar}=k$\\\\\\\\\n\tCase 1: If $\\lambda$ is positive $P_{x} \\phi=\\hbar k \\phi \\Rightarrow-i \\frac{d \\phi}{d x}=k \\phi \\Rightarrow \\frac{d \\phi}{\\phi}=i k d x \\Rightarrow \\ln \\phi=i k x+C \\Rightarrow \\phi=e^{i k x}$\\\\\n\tCase 2 : If $\\lambda$ is negative\\\\\n\t$P_{x} \\phi=\\hbar k \\phi \\Rightarrow-i \\frac{d \\phi}{d x}=-k \\phi \\Rightarrow \\frac{d \\phi}{\\phi}=-i k d x \\Rightarrow \\ln \\phi=-i k x+C \\Rightarrow \\phi=e^{-i k x}$\\\\\\\\\n\t(b) Expand the function $\\psi(x)=A \\sin k x \\sin 2 k x$ as a linear combination of eigenfunctions of the momentum operator $P_{x}$.\n\t\\begin{align*}\n\t&\\psi(x)=A \\sin k x \\sin 2 k x=A\\left(\\frac{e^{i k x}-e^{-i k x}}{2 i}\\right)\\left(\\frac{e^{2 i k x}-e^{-2 i k x}}{2 i}\\right) \\\\\n\t&\\frac{A}{4}\\left(-e^{-3 i k x}+e^{-i k x}+e^{i k x}-e^{3 i k x}\\right)\n\t\\end{align*}\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item If $\\left|\\phi_{1}\\right\\rangle=A\\left(\\begin{array}{l}1 \\\\ 0 \\\\ 0\\end{array}\\right)\\left|\\phi_{2}\\right\\rangle=B\\left(\\begin{array}{l}0 \\\\ i \\\\ i\\end{array}\\right)\\left|\\phi_{3}\\right\\rangle=C\\left(\\begin{array}{c}0 \\\\ i \\\\ -i\\end{array}\\right)$\\\\\n\t(a) Find normalization constant $A, B, C$ for ket $\\left|\\phi_{1}\\right\\rangle\\left|\\phi_{2}\\right\\rangle\\left|\\phi_{3}\\right\\rangle$\\\\\n\t(b) Prove that $\\left|\\phi_{1}\\right\\rangle,\\left|\\phi_{2}\\right\\rangle$ and $\\left|\\phi_{3}\\right\\rangle$ are orthogonal\\\\\n\t(c) Check whether $\\left|\\phi_{1}\\right\\rangle,\\left|\\phi_{2}\\right\\rangle$ and $\\left|\\phi_{3}\\right\\rangle$ are linearly independent or not.\n\\end{minipage}\n\\begin{answer}\n\t(a) $\\left\\langle\\phi_{1} \\mid \\phi_{1}\\right\\rangle=1 \\Rightarrow A^{*}\\left(\\begin{array}{lll}1 & 0 & 0\\end{array}\\right) A\\left(\\begin{array}{l}1 \\\\ 0 \\\\ 0\\end{array}\\right)=1 \\Rightarrow A=1$\n\t$$\n\t\\left\\langle\\phi_{2} \\mid \\phi_{2}\\right\\rangle=1 \\Rightarrow B^{*}\\left(\\begin{array}{lll}\n\t0 & -i & -i\n\t\\end{array}\\right) B\\left(\\begin{array}{l}\n\t0 \\\\\n\ti \\\\\n\ti\n\t\\end{array}\\right)=1 \\Rightarrow B=\\frac{1}{\\sqrt{2}}\n\t$$\n\t$$\n\t\\left\\langle\\phi_{3} \\mid \\phi_{3}\\right\\rangle=1 \\Rightarrow C^{*}\\left(\\begin{array}{lll}\n\t0 & -i & i\n\t\\end{array}\\right) C\\left(\\begin{array}{c}\n\t0 \\\\\n\ti \\\\\n\t-i\n\t\\end{array}\\right)=1 \\Rightarrow C=\\frac{1}{\\sqrt{2}}\n\t$$\n\t(b) $\\left\\langle\\phi_{1} \\mid \\phi_{2}\\right\\rangle=A^{*}\\left(\\begin{array}{lll}1 & 0 & 0\\end{array}\\right) B\\left(\\begin{array}{l}0 \\\\ i \\\\ i\\end{array}\\right)=0$\n\t$$\n\t\\left\\langle\\phi_{1} \\mid \\phi_{3}\\right\\rangle=A^{*}\\left(\\begin{array}{lll}\n\t1 & 0 & 0\n\t\\end{array}\\right) C\\left(\\begin{array}{c}\n\t0 \\\\\n\ti \\\\\n\t-i\n\t\\end{array}\\right)=0\n\t$$\n\t$$\n\t\\left\\langle\\phi_{2} \\mid \\phi_{3}\\right\\rangle=A^{*}\\left(\\begin{array}{lll}\n\t0 & -i & -i\n\t\\end{array}\\right) C\\left(\\begin{array}{c}\n\t0 \\\\\n\ti \\\\\n\t-i\n\t\\end{array}\\right)=A^{*} C(0+1-1)=0\n\t$$\n(c)\t$c_{1}\\left|\\phi_{1}\\right\\rangle+c_{2}\\left|\\phi_{2}\\right\\rangle+c_{3}\\left|\\phi_{3}\\right\\rangle=0 \\Rightarrow c_{1}\\left(\\begin{array}{c}\n\t\t1 \\\\\n\t\t0 \\\\\n\t\t0\n\t\\end{array}\\right)+c_{2}\\left(\\begin{array}{c}\n\t\t0 \\\\\n\t\ti \\\\\n\t\ti\n\t\\end{array}\\right)+c_{3}\\left(\\begin{array}{c}\n\t\t0 \\\\\n\t\ti \\\\\n\t\t-i\n\t\\end{array}\\right)=0$\\\\\n\t$$\n\tc_{1}=0 \\quad c_{2}+c_{3}=0 \\text { and } c_{2}-c_{3}=0 \\Rightarrow c_{1}=0, c_{2}=0, c_{3}=0\n\t$$\n\tSo $\\left|\\phi_{1}\\right\\rangle,\\left|\\phi_{2}\\right\\rangle$ and $\\left|\\phi_{3}\\right\\rangle$ are linearly independent\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item If Hamiltonian of system is $H=\\frac{p_{x}^{2}}{2 m}+V(x)$ then Find commutation $[H, x]$ and $[[H, x], x]$\n\\end{minipage}\n\\begin{answer}\n\t$\\text { As, } H=p^{2} / 2 m+V(x)$\\\\\\\\\n\tWe have, $[H, x]=\\frac{1}{2 m}\\left[p^{2}, x\\right]=-i \\hbar p / m$\\\\\\\\\n\t and so, $[[H, x], x]=\\frac{i \\hbar}{m}[p, x]=-\\hbar^{2} / m$\\\\\\\\\n\t  Hence, $\\langle m|[[H, x] x]| m\\rangle=-\\frac{\\hbar^{2}}{m}$.\n\\end{answer}\n\\end{enumerate}\n\n", "meta": {"hexsha": "c3d24266deb6cabb15fafd926931dd5e7cc9f1ba", "size": 65209, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "QM -CSIR/chapter/mathematical tool.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "QM -CSIR/chapter/mathematical tool.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "QM -CSIR/chapter/mathematical tool.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.8022648084, "max_line_length": 607, "alphanum_fraction": 0.6408011164, "num_tokens": 25667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191309994468, "lm_q2_score": 0.8459424295406087, "lm_q1q2_score": 0.808144986664295}}
{"text": "\\lab{Algorithms}{Givens rotations and Least squares}{Givens rotations and Least squares}\n\\objective{Use orthogonal transformations to perform QR decomposition.}\n\\label{lab:givens}\n\nIn a previous lab, we discussed how to form the QR decomposition of a matrix using a series of householder reflectors.\nThe general approach was to apply a series of orthogonal transformations to a given matrix to transform it into upper triangular form.\nThis same approach can be applied using rotations instead of reflections.\n\nThe matrix $\\begin{pmatrix}\\ cos \\theta & - \\sin \\theta \\\\ \\sin \\theta & \\cos \\theta \\end{pmatrix}$ rotates a vector counterclockwise by $\\theta$.\nGiven a vector $x = \\begin{pmatrix} a \\\\ b \\end{pmatrix}$, we can rotate $x$ into the span of $e_1$ by choosing the correct $\\theta$.\nThis zeros out the entry containing $b$.\nWe could do this by finding the angle between $\\begin{pmatrix} a \\\\ b \\end{pmatrix}$ and the axis containing $b$ then rotating the vector by the negative of that angle.\nIn order to avoid computations involving $\\sin$ and $\\arcsin$ at each iteration we can just solve for $\\sin \\theta $ and $\\cos \\theta$ using the pythagorean theorem instead of explicitly computing $\\theta$.\nSuch an approach gives us the result that $\\cos \\theta = \\frac{a}{\\sqrt{a^2 + b^2}}$ and $\\sin \\theta = \\frac{- b}{\\sqrt{a^2 + b^2}}$.\nThe transformed image of $\\begin{pmatrix} a \\\\ b \\end{pmatrix}$ is then $\\begin{pmatrix} \\sqrt{a^2 + b^2} \\\\ 0 \\end{pmatrix}$.\n\nThe application of such a rotation to any two rows of a matrix $A$ is an orthonormal transform.\nSuch a transformation can be represented in matrix form, where $c = \\cos \\theta$ and $s = \\sin \\theta$, like this:\n\\begin{equation*}\n\\begin{pmatrix}\nI & 0 & 0 & 0 & 0 \\\\\n0 & c & 0 & -s & 0 \\\\\n0 & 0 & I & 0 & 0 \\\\\n0 & s & 0 & c & 0 \\\\\n0 & 0 & 0 & 0 & I\n\\end{pmatrix}\n\\end{equation*}\nIn actual computation, we \\emph{do not} actually form such a large matrix at each step.\nInstead we apply the transformation to the two rows we want to change and then leave the rest of the matrix unchanged.\nProceeding in this manner we can zero out each entry of any matrix below its main diagonal, resulting in a QR factorization.\nFor an example, consider some matrix $A$.\nLet $G \\left( i, j, k \\right)$ denote the Givens rotation that will zero out $A \\left[ j, k \\right]$ by rotation with row $i$ of $A$.\nWe can zero out the entries below the main diagonal of A as follows:\n\n\\[\n\\begin{array}{ccccccc}\n\\begin{pmatrix}\n*&*&*\\\\\n*&*&*\\\\\n*&*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(1,2,0)}\n&\\begin{pmatrix}\n*&*&*\\\\\n*&*&*\\\\\n0&*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(0,1,0)}\n&\\begin{pmatrix}\n*&*&*\\\\\n0&*&*\\\\\n0&*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(1,2,1)}\n&\\begin{pmatrix}\n*&*&*\\\\\n0&*&*\\\\\n0&0&*\n\\end{pmatrix}\n\\end{array}\n\\]\n\nHere is an outline for the algorithm.\nLet $A$ be the array passed to the function.\n\n\\begin{comment}\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Givens Triangularization}{$A$}\n\\State $R \\gets \\text{copy}(A)$\n\\State $Q \\gets I_A$\n\\State $G \\gets \\text(empty)(2,2)$\n\\For{each column}\n    \\For{each row below the main diagonal}\n        \\If{leading element is not zero}\n            \\State Compute $c$ and $s$ using the entry in the current row and column and the entry immediately above it\n            \\State Use $c$ and $s$ to construct the matrix $G$\n            \\State Get a slice of $R$ of the current row and the row above it that includes the columns from the current column onward.\n                Multiply it in place by $G$ to zero out the leading nonzero entry of the current row.\n            \\State Get a slice of $Q$ of the current row and the row above it and apply $G$ to it as well.\n                (Strictly speaking, you do not need to operate over these entire rows, but the slicing needed to avoid the extra computation is a little more involved, so we will not include that here.)\n        \\EndIf\n    \\EndFor\n\\EndFor\n\\State \\pseudoli{return} $Q^T, R$\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\n\\end{comment}\n\n\\begin{itemize}[$\\bullet$]\n\n\\item Make $R$ a copy of $A$ and $Q$ an identity array of the appropriate size.\n\n\\item Make an empty $2 \\times 2$ array $G$ that will be used to apply the Givens rotations.\n\n\\item For each column:\n\n  \\begin{itemize}[$\\bullet$]\n\n  \\item For each row below the main diagonal (starting at the bottom of the column):\n\n    \\begin{itemize}[$\\bullet$]\n\n    \\item If the leading entry of this row is not zero (i.e. if its absolute value is within a given tolerance):\n\n      \\begin{itemize}[$\\bullet$]\n\n      \\item Compute $c$ and $s$ using the entry in the current row and column and the entry immediately above it.\n\n      \\item Use $c$ and $s$ to construct the matrix $G$.\n\n      \\item Get a slice of $R$ of the current row and the row above it that includes the columns from the current column onward.\n      Multiply it in place by $G$ to zero out the leading nonzero entry of the current row.\n\n      \\item Get a slice of $Q$ of the current row and the row above it and apply $G$ to it as well. (Strictly speaking, you do not need to operate over these entire rows, but the slicing needed to avoid the extra computation is a little more involved, so we will not include that here.)\n\n      \\end{itemize}\n\n    \\end{itemize}\n\n  \\end{itemize}\n\n\\item Return $Q^T$ and $R$.\n\n\\end{itemize}\n\nThis version of the algorithm is not the most well-optimized way to use Givens rotations, but it is good for illustrative purposes.\n\nBecause Givens rotations only operate on two specific rows at a time, they give us a variety of ways to iterate over an array we are processing.\nFor example, using Givens rotations you could, starting at the bottom of each column and continuing up until you reach the main diagonal, zero out each entry by applying a Givens rotation to each row and the row immediately above it.\nAlternatively, within each column, you could could zero out the first entry of each row below the main diagonal by rotating it with the row corresponding to the main diagonal.\nYet another way to do it would be to start at the bottom left corner of the matrix and then zero out each entry from left to right along each diagonal.\nThis flexibility is what makes the use of Givens rotations ideal for some problems.\nWhen working with sparse matrices, Givens rotations allow for the solution of linear systems through a series of orthonormal operations that operate only on small parts of the array.\nThe fact that Givens rotations operate only on small portions of the array also lends well to parallel solutions to systems of equations (or least squares problems).\nThey allow for the sort of flexibility we had when using Gaussian elimination while still maintaining the favorable stability that comes with using orthonormal transformations.\n\nWhile Givens rotations do allow for greater flexibility, they also require a greater number of floating point operations than Householder reflections.\nIn general, the operation count for computing the QR factorization for an $m \\times n$ matrix is $3 n^2 \\left( m - \\frac{n}{3} \\right)$.\n% Accuracy and Stability of Numerical Algorithms, Nicholas J. Higham\nThere are modified versions of the Givens QR algorithm that use ``fast Givens rotations\" which decrease the number of multiplications and square roots needed for the application of each Givens rotation.\n% Fast Plane Rotations With Dynamic Scaling, Anda and Park, SIAM, 1994\nIt allows for the use of Givens rotations while requiring roughly the same number of floating point operations used by the Householder QR algorithm.\nIn practice, these methods are still not quite as fast as the Householder algorithm.\nIn spite of the need for more floating point operations, Givens rotations are still well suited for parallelization and can be much faster than the Householder algorithm when multiple processors are used.\n% Givens and Householder Reductions for Linear Least Squares on a Cluster of Workstations, Omer Egecioglu and Ashok Srinivasan\n\n\\begin{problem}\n\\label{prob:Givens}\nWrite a function called \\li{givens} that uses Givens rotations to compute the $QR$ decomposition of\na matrix $A$.\nBy performing successive Givens rotations, triangularize $A$ to find $R$.\nApply the rotations to an identity matrix as you go, then take the transpose to invert it and find $Q$.\nReturn $Q$ and $R$.\n\\end{problem}\n\nWe will now illustrate one example of how to use Givens rotations to change only specific parts of the array.\n\n\\begin{problem}\n\\label{prob:givens_hessenberg}\nWrite a modified version of your solution to Problem \\ref{prob:Givens}, call it \\li{givens2} that computes the \nQR decomposition of an upper Hessenberg matrix.\nInstead of starting at the bottom of each column and working up, just run down the first subdiagonal from left to right.\nWhen operating on $Q$, you do not need to operate on the full length of each row.\nIt is sufficient to perform the matrix multiplication on the portion of the array \\li{Q[j:j+2,:j+2]} where \\li{j} is the current column.\n\nNote: You can zero out the portion below the first subdiagonal of a matrix like this:\n\\begin{lstlisting}\nimport numpy as np\nimport scipy.linalg as la\nfrom numpy.random import rand\nA = rand(500, 500)\nA[1:] = la.triu(A[1:])\n\\end{lstlisting}\n\nNotice how $Q$ in the QR decomposition of an upper Hessenberg matrix is also upper Hessenberg.\nWhat is the computational order of  complexity for this problem?\nApproximately for what $m$ is your implementation as fast as the general QR decomposition built in to \\li{scipy.linalg} for computing the QR decomposition of an upper Hessenberg matrix?\n\\end{problem}\n\n\\begin{problem}\n\\label{prob:givens_hessenberg_modified}\nYou may have noticed that matrix multiplication by $Q$ is generally a $\\mathcal{O} \\left( n^3 \\right)$ algorithm, while the application of these individual Givens rotations is a $\\mathcal{O} \\left( n^2 \\right)$ algorithm.\nWrite a modified version of your solution to Problem \\ref{prob:givens_hessenberg} called \\li{givens2_mod} which returns \nan $(n-1) \\times 2 \\times 2$ array containing the computed values for $G$ at each step in the algorithm in the order in which they are applied to the upper Hessenberg array $H$.\n\nWrite two more functions \\li{apply_Q} and \\li{apply_QT} which, using the matrix of Givens rotations, perform left multiplication \nby $Q$ and $Q^{-1}$, respectively, on some other input array $B$.\nLeft multiplication by $Q^{-1}$ can be done by applying each of the Givens rotations to $B$ the same way you did to $H$ to compute its QR factorization.\nLeft multiplication by $Q$ can be done by applying the transpose of the Givens rotations to their corresponding portions of $B$, but in the reverse order.\nNotice that you will have to apply each Givens rotation across the full width of the rows it operates on since you do not know anything about the content of $B$.\n\nFor around what size of matrices is direct multiplication by $Q$ slower than this method of multiplying by $Q$?\nFor timing purposes, make a random upper Hessenberg matrix, compute its QR decomposition using the function you just wrote and your solution to Problem \\ref{prob:givens_hessenberg}, then time how long it takes to left multiply a random square array by $Q$ using the function you just wrote and the \\li{dot} method of NumPy arrays.\n\nNote: the functions you just wrote can be used to perform right multiplication as well since $B Q = \\left(Q^T B^T \\right)^T$ and $B Q^T = \\left( Q B^T \\right)^T$.\n\\end{problem}\n\nAn interesting side-note is that each Givens rotation can be represented as a single floating point number, so, when operating in place, $Q$ can be stored entirely in the lower triangular portion of the array on which we are operating by storing each rotation in the entry that it zeroes out.\nA similar approach would to store Householder reflectors in the columns they zero out.\nIn either case, we can represent the QR decomposition of an array using only the memory that was originally used to store the array itself.\nThis is similar to the approach  for computing the LU decomposition entirely in place.\nThese representations of $Q$ and $R$ can be used in various ways to perform matrix multiplication by $Q$, $Q^T$ and $R$ as needed.\n\n\\section*{Least Squares}\n\nWe are now changing the subject to talk about line fitting.\n\nIt is well known that the displacement of a spring is proportional\nto the force acting upon it, that is, $F = k x$.  The proportionality\nconstant $k$ is called Hooke's spring constant.  Consider a laboratory\nexperiment where different loads are placed on a spring and the displacement\nis measured and recorded in the table below:\n\\vspace{5mm}\\\\\n\\begin{center}\n\\begin{tabular}{|c|c|}\n\t\\hline\nx & F \\\\\n(cm) & (dyne)\\\\\n\\hline\n1.04  & 3.11 \\\\\n2.03  &  6.01\\\\\n2.95  &  9.07\\\\\n3.92  &  11.99\\\\\n5.06  &  15.02\\\\\n6.00  &  17.91\\\\\n7.07  &  21.12\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\vspace{5mm}\nTo find the spring constant $k$, we simply need to solve the following linear system\n\\[\n\\begin{pmatrix}\n1.04\\\\\n2.03\\\\\n2.95\\\\\n3.92\\\\\n5.06\\\\\n6.00\\\\\n7.07\\\\\n\\end{pmatrix}\n\\begin{pmatrix}k\\end{pmatrix} =\n\\begin{pmatrix}\n3.11 \\\\\n6.01\\\\\n9.07\\\\\n11.99\\\\\n15.02\\\\\n17.91\\\\\n21.12\\\\\n\\end{pmatrix}.\n\\]\nHowever, there is no solution to this system because it is overdetermined.\nInstead, we seek the ``best'' $k$ that fits the data.\nLeast squares allows us to find that ``best'' solution.\nWe can find the least squares solution by computing the following in Python:\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import linalg as la\n>>> A = np.vstack([1.04,2.03,2.95,3.92,5.06,6.00,7.07])\n>>> b = np.vstack([3.11,6.01,9.07,11.99,15.02,17.91,21.12])\n>>> k = np.dot(np.dot(la.inv(np.dot(A.T,A)),A.T),b)\n>>> k\narray([[ 2.99568294]])\n\\end{lstlisting}\nHence, we find the spring constant to be $k = 2.9957$.\nNote that \\li{scipy.linalg} provides a built-in function for solving\nleast-squares problems.\nWe plot the data against the best fit as follows:\n\\begin{figure}[h!]\n\\label{fig1}\n\\begin{center}\n\\includegraphics[width=\\textwidth]{line_lstsq}\n\\caption{The graph of the spring data together with its linear fit}\n\\label{Fig:SpringFit}\n\\end{center}\n\\end{figure}\n\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> x0 = np.linspace(0,8,100)\n>>> y0 = k[0]*x0\n>>> plt.plot(A,b,'*',x0,y0)\n>>> plt.show()\n\\end{lstlisting}\nSee Figure \\ref{Fig:SpringFit} to see how well the line fits the data.\n\n\n\\section*{General Line Fitting}\n\nSuppose that we wish to fit a general line, that is $y=m x+b$, to the data set\n$\\{(x_k,y_k)\\}^n_{k=1}$.  Assume that the line does not cross through the origin,\nas in the previous example.  Then we seek both a slope and a $y$-intercept.\nIn this case, we set up the following linear system $A x = b$, or more precisely\n\\[\n\\begin{pmatrix}\nx_1 & 1\\\\\nx_2 & 1\\\\\nx_3 & 1\\\\\n\\vdots & \\vdots\\\\\nx_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\nm\\\\\nb\n\\end{pmatrix}=\n\\begin{pmatrix}\ny_1\\\\\ny_2\\\\\ny_3\\\\\n\\vdots\\\\\ny_n\n\\end{pmatrix}.\n\\]\nNote that $A$ has rank $2$ as long as not all of the $x_k$ values are the same.\nHence, the least squares solution\nis given by\n$$\n\\widehat{x} = (A^HA)^{-1}A^Hb.\n$$\nIn what sense does this solution give us the best fit line for the data? Recall that since $A$ is injective,\nthe matrix $A(A^HA)^{-1}A^H$ is an orthogonal projector onto the range of $A$, which means that\n$A(A^HA)^{-1}A^Hb = A\\widehat{x}$ is the closest vector (with respect to the 2-norm) to $b$ that lies in the\nrange of $A$. That is, $\\widehat{x}$ minimizes the error between $Ax$ and $b$, where the error is given\nby the distance between these vectors, $\\|b-Ax\\|_2$. Another way to say this is that $\\widehat{x}$ gives the\nvalues $m$ and $b$ for which the sum of the squares of the distances from each data point $y_k$ to the value\n$y = mx_k + b$ is as small as possible.\n\n\\section*{Loading Data from .npz Files}\nFor Least Squares problems as well as in many other contexts, loading data is often a necessary step before\nproceeding with further analysis. Here we briefly review another data format in Python and the commands used\nto load the data.\n\nA \\li{.npz} file is a compressed binary file that contains an archive of NumPy data structures.\nA given file may therefore contain several arrays, each array associated with a unique string that identifies it.\nWhen you load a \\li{.npz} file in Python, a dictionary-like object is returned, and you can access the data by\nproviding the appropriate key. Note that when you load a \\li{.npz} file, you must also be sure to close it when\nyou are finished. This is taken care of automatically if you use the \\li{with ... as} keywords.\n\nAs an example, suppose that we have a file named \\li{grades.npz} that contains several arrays, each giving the\nhomework scores of a particular student in a particular class. Assuming that one of the arrays is associated with\nthe key \\li{'Abe'}, we can load this array in the following way:\n\n\\begin{lstlisting}\n>>> with np.load('grades.npz') as grades:\n>>>     abe_grades = grades['Abe']\n>>> abe_grades\narray([ 10.,  10.,  10.,  10.,  10.,  10.,  10.,  10.,  10.,  10.])\n\\end{lstlisting}\n\nYou will need to apply this technique in the next problem.\n\n\\begin{problem}\nWrite a function \\li{fitLine} that takes no arguments and executes the following.\nLoad the \\texttt{linepts} array from \\texttt{data.npz}.\nThis consists of two columns corresponding to the $x$ and $y$ values of a given data set.\nUse least squares to find the slope and $y$-intercept that best fits the data.\nThen plot the data points and the line on the same graph.\nThe function should not return anything.\n\\end{problem}\n\n\\section*{Fitting data to a circle}\n\nRecall that the equation of a circle, with radius $r$ centered at $(c_1,c_2)$, is given by\n\\begin{equation}\n\\label{circle}\n(x-c_1)^2 + (y-c_2)^2 = r^2.\n\\end{equation}\nSuppose we are given a set of data points closely forming a circle $\\{(x_i,y_i)\\}^n_{i=1}$.\nThe ``best'' fit is found via least squares by expanding \\eqref{circle} to get\n\\[\n2 c_1 x + 2 c_2 y + c_3 = x^2 + y^2,\n\\]\nwhere $c_3 = r^2 - c_1^2 - c_2^2$.  Then we can write the linear system $A x = b$ as\n\\[\n\\begin{pmatrix}\n2 x_1 & 2 y_1 & 1\\\\\n2 x_2 & 2 y_2 & 1\\\\\n\\vdots & \\vdots & \\vdots \\\\\n2 x_n & 2 y_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\nc_1\\\\\nc_2\\\\\nc_3\n\\end{pmatrix}=\n\\begin{pmatrix}\nx_1^2 + y_1^2\\\\\nx_2^2 + y_2^2\\\\\n\\vdots\\\\\nx_n^2 + y_n^2\n\\end{pmatrix},\n\\]\nwhere the matrix $A$ and the vector $b$ are obtained by the given data and the unknown\n$x$ contains the information about the center and radius of the circle and is obtained\nby finding the least squares solution.\n\n\\section*{Example}\n\nIn this section, we fit the following points to a circle:\n\\begin{align*}\n&(134,76),(104,146),(34,176),(-36,146),\\\\\n&(-66,76),(-36,5),(34,-24),(104,5),(134,76)\n\\end{align*}\n\nWe enter them into Python as a $9\\times 2$ array:\n\\begin{lstlisting}\n>>> P = np.array([[134,76],[104,146],[34,176],[-36,146],\n                  [-66,76],[-36,5],[34,-24],[104,5],[134,76]])\n\\end{lstlisting}\nWe compute $A$ and $b$ by entering the following:\n\\begin{lstlisting}\n>>> A = A =np.hstack((2*P, np.ones((9,1))))\n>>> b = (P**2).sum(axis=1)\n\\end{lstlisting}\nHence, we get the least squares solution\n\\begin{lstlisting}\n>>> x = np.dot(np.dot(la.inv(np.dot(A.T,A)),A.T),b)\n\\end{lstlisting}\nThen we find $c_1$, $c_2$, and $r$ by:\n\\begin{lstlisting}\n>>> from math import sqrt\n>>> c1, c2, c3 = x\n>>> r = sqrt(c1**2 + c2**2 + c3)\n\\end{lstlisting}\nWe plot this by executing\n\\begin{lstlisting}\n>>> theta = np.linspace(0,2*np.pi,200)\n>>> plt.plot(r*np.cos(theta)+c1,r*np.sin(theta)+c2,'-',P[:,0],P[:,1],'*')\n>>> plt.show()\n\\end{lstlisting}\n\n\n\\begin{problem}\nWrite a function \\li{fitCircle} that does the following.\nLoad the \\texttt{circlepts} array from \\texttt{data.npz}.\nThis consists of two columns corresponding to the $x$ and $y$ values of a given\ndata set.  Use least squares to find the center and radius of the circle that best\nfits the data.  Then plot the data points and the circle on the same graph.\nThe function should return nothing.\n\\end{problem}\n\n\\begin{problem}\nThe general equation for an ellipse is:\n\\[\nax^2 + bx + cxy + dy + ey^2 = 1\n\\]\n\nWrite a function \\li{fitEllipse} that uses least squares to fit data to an ellipse.\nThe function should take a $n\\times 2$ array as input, where the first column gives the $x$-coordinates\nand the second column gives the $y$-coordinates. Find the least squares solution for $a, b, c, d,$ and $e$,\nand return the solution.\nYou can test out your function on the \\texttt{ellipsepts} array from \\texttt{data.npz}. You should get  $0.087$, $-0.141$,  $0.159$, $-0.316$, $0.366$ for $a, b, c, d,$ and $e$ respectively.\n\\end{problem}\n\nIn these Least Squares problems, we have found best fit lines and ellipses relative to the 2-norm.\nIt is possible to generalize the idea of best fit curves relative to other norms.\nSee Figure \\ref{Fig:ellipse} for an illustration of this.\n\n\\begin{figure}[h]\n\\label{ellipsefit}\n\\centering\n\\includegraphics[width=\\textwidth]{ellipsefit.pdf}\n\\caption{Fitting an ellipse using different norms.}\n\\label{Fig:ellipse}\n\\end{figure} \n", "meta": {"hexsha": "72130df7912bf304b7877378c0a0914139faef4f", "size": 20994, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Givens/Givens.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/Givens/Givens.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/Givens/Givens.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.2911392405, "max_line_length": 330, "alphanum_fraction": 0.7257787939, "num_tokens": 6016, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8933094017937621, "lm_q1q2_score": 0.8081328237505453}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} Let $T$ be a linear transformation given by\n\\[\nT \\begin{mymatrix}{r}\nx\\\\\ny\n\\end{mymatrix} = \\begin{mymatrix}{rr}\n2 & 1 \\\\\n0 & 1\n\\end{mymatrix}\n \\begin{mymatrix}{r}\nx\\\\\ny\n\\end{mymatrix}\n\\]\nIs $T$ one to one? Is $T$ onto?\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Let $T$ be a linear transformation given by\n\\[\nT \\begin{mymatrix}{r}\nx\\\\\ny\n\\end{mymatrix} = \\begin{mymatrix}{rr}\n-1 & 2 \\\\\n2 & 1 \\\\\n1 & 4\n\\end{mymatrix}\n \\begin{mymatrix}{r}\nx\\\\\ny\n\\end{mymatrix}\n\\]\nIs $T$ one to one? Is $T$ onto?\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Let $T$ be a linear transformation given by\n\\[\nT \\begin{mymatrix}{r}\nx\\\\\ny  \\\\\nz\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n2 & 0 & 1  \\\\\n1 & 2 & -1\n\\end{mymatrix}\n \\begin{mymatrix}{r}\nx\\\\\ny \\\\\nz\n\\end{mymatrix}\n\\]\nIs $T$ one to one? Is $T$ onto?\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Let $T$ be a linear transformation given by\n\\[\nT \\begin{mymatrix}{r}\nx\\\\\ny \\\\\nz\n\\end{mymatrix} = \\begin{mymatrix}{rrr}\n1 & 3 & -5  \\\\\n2 & 0 & 2 \\\\\n2 & 4 & -6\n\\end{mymatrix}\n \\begin{mymatrix}{r}\nx\\\\\ny \\\\\nz\n\\end{mymatrix}\n\\]\nIs $T$ one to one? Is $T$ onto?\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Give an example of a $3\\times 2$-matrix with the property that the\nlinear transformation determined by this matrix is one to one but not onto.\n\\begin{sol}\n$\\begin{mymatrix}{cc}\n1 & 0 \\\\\n0 & 1 \\\\\n0 & 0\n\\end{mymatrix} $\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $A$ is an $m\\times n$-matrix in which $m\\leq n$. Suppose also\nthat the rank of $A$ equals $m$. Show that the transformation $T$ determined by $A$\nmaps $\\R^{n}$ onto $\\R^{m}$.\n \\textbf{Hint: }The vectors $\\vect{e}_{1},\\ldots, \\vect{e}_{m}$ occur as columns in the {\\rref} for $A$. \\vspace{1mm}\n\\begin{sol}\n This says\nthat the columns of $A$ have a subset of $m$ vectors which are linearly\nindependent. Therefore, this set of vectors is a basis for $\\R^{m}$.\nIt follows that the span of the columns is all of $\\R^{m}$. Thus $A$\nis onto.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $A$ is an $m\\times n$-matrix in which $m\\geq n$. Suppose also\nthat the rank of $A$ equals $n$. Show that $A$ is one to one. \\textbf{Hint: }\nIf not, there exists a vector, $\\vect{x}$ such that $A\\vect{x}=0$, and\nthis implies at least one column of $A$ is a linear combination of the\nothers. Show this would require the rank to be less than $n$. \\vspace{1mm}\n\\begin{sol}\nThe\ncolumns are independent. Therefore, $A$ is one to one.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Explain why an $n\\times n$-matrix $A$ is both one to one and onto if\nand only if its rank is $n$. \\vspace{1mm}\n\\begin{sol}\nThe rank is $n$ is the same as saying the\ncolumns are independent which is the same as saying $A$ is one to one which\nis the same as saying the columns are a basis. Thus the span of the columns\nof $A$ is all of $\\R^{n}$ and so $A$ is onto. If $A$ is onto, then\nthe columns must be linearly independent since otherwise the span of these\ncolumns would have dimension less than $n$ and so the dimension of $\\R^{n}$ would be less than $n$ .\n\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "1794ccf0cd2d27c1a236e6da3d7480fb561771a6", "size": 3030, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/LinearTransformations-OneOneOnto.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/exercises/LinearTransformations-OneOneOnto.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/exercises/LinearTransformations-OneOneOnto.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 22.9545454545, "max_line_length": 117, "alphanum_fraction": 0.6547854785, "num_tokens": 1134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.9124361551194692, "lm_q1q2_score": 0.8080821823320674}}
{"text": "\n\n\\newcommand{\\matx}[1]{\\mbox{\\tt #1}} \\newcommand{\\vect}[1]{{\\bf #1}}\n\n\\begin{itemize} \\item n = number of objects aka independent motions aka subspaces \\item P = number of $(x, y)$ point correspondences \\item F = number\nof frames \\end{itemize}\n\nLet us stack all the frames vertically so that we get a matrix W\n\n$$W = MS^T$$\n\nwhere M is motion matrix $\\in \\mathbb{R}^{2F \\time 4}$ and where $S$ is shape matrix (point correspondences).\n\nAdditionally, we have the world coordinates (x,y,z) as\n\n\\begin{equation} X = \\begin{bmatrix} x \\\\ y \\\\ z \\\\ 1 \\\\ \\end{bmatrix} \\end{equation}\n\n\\begin{equation} x = \\begin{bmatrix} x \\\\ y \\\\ \\end{bmatrix} \\end{equation}\n\nThe affine camera matrix translating between a given world and image coordinate is written in terms of rotations and translations as A $\\in\n\\mathbb{R}^{2 \\times 4}$\n\n\\begin{equation} \\vect A = \\begin{bmatrix} R1 && R2 && R3 && T1 \\\\ R3 && R4 && R5 && T2 \\\\ \\end{bmatrix} \\end{equation}\n\n \\begin{figure} \\centering\n     % \\includegraphics[width=0.3\\textwidth]{./pca.png}\n     \\caption{If we imagine the blobs as clouds of points in 3D (so imagine them going at some angle through space), the  problem with picking a\n single subspace is that the data lies more naturalies in two subspaces, e.g. the two lines going through the gray and dark gray clusters.}\n \\end{figure}\n\n\\subsubsection{Representing motion subspaces with polynomials}\n\n The gist of this section is that, if all n subspaces (each representing one object) have dimension 4 in $\\mathbb{R}^5$, then a single linear\n polynomial of degree 5 is enough to represent them. To see this, consider that a plane may be represented by a linear polynomial of three variables,\n $ax+by+cz = 0$. Then, we can fit a polynomial defined as the product of the n planes, which will have at most degree n and have three variables. We\n can also describe lower dimension subsubspaces as a the \"common zero set\" of multiple hyperplanes. For instance, a line can be described as the\n intersection of two hyperplanes. \n\n \\begin{figure} \\centering\n     % \\includegraphics[width=0.3\\textwidth]{./polysubspace.png}\n     \\caption{Here the intersection, or combined zero-set, of two 3D planes are used to define a line (2D subspace) in $\\mathbb{R}^3$.} \\end{figure}\n\n \\textit{Aside: an algebraic variety is roughly like a \"shape\" that fits the points. Here we are saying that if this polynomial \"shape\" fits all the\n datapoints in n subspaces, then we should be able to factor the algebraic variety nto n polynomials.  Co-dimension means the number of dimensions not\n occupied by a subspace, e.g. a subspace of dimension 4 in 5 dimensional space has a co-dimension of 1. }\n % TODO: zero set\n", "meta": {"hexsha": "de915fbf75ac1fd51649dc90a031d5b301d1abad", "size": 2680, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "wk12/scratch.tex", "max_stars_repo_name": "nouyang/janson299r", "max_stars_repo_head_hexsha": "2407f11a94d496d5bec044d3e007661d76b9cff3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wk12/scratch.tex", "max_issues_repo_name": "nouyang/janson299r", "max_issues_repo_head_hexsha": "2407f11a94d496d5bec044d3e007661d76b9cff3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wk12/scratch.tex", "max_forks_repo_name": "nouyang/janson299r", "max_forks_repo_head_hexsha": "2407f11a94d496d5bec044d3e007661d76b9cff3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.0212765957, "max_line_length": 150, "alphanum_fraction": 0.7309701493, "num_tokens": 753, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8856314632529872, "lm_q1q2_score": 0.8080821677105792}}
{"text": "\n\\subsection{The Robinson estimator}\n\n\\subsubsection{Partialling out}\n\n\\(y_i=\\mathbf x_i\\theta +g(\\mathbf z_i) +\\epsilon_i\\)\n\nConsider:\n\n\\(E(y_i|\\mathbf z_i)=E(\\mathbf x_i\\theta +g(\\mathbf z_i) + \\epsilon_i|\\mathbf z_i)\\)\n\n\\(E(y_i|\\mathbf z_i)=E(\\mathbf x_i\\theta|\\mathbf z_i)+E(g(\\mathbf z_i)|\\mathbf z_i) + E(\\epsilon_i|\\mathbf z_i)\\)\n\n\\(E(y_i|\\mathbf z_i)=E(\\mathbf x_i|\\mathbf z_i)\\theta+g(\\mathbf z_i)\\)\n\nWe can now remove the parametric part:\n\n\\(y_i-E(y_i|\\mathbf z_i)=\\mathbf x_i\\theta +g(\\mathbf z_i) + \\epsilon_i - E(\\mathbf x_i|\\mathbf z_i)\\theta -g(\\mathbf z_i)\\)\n\n\\(y_i-E(y_i|\\mathbf z_i)=(\\mathbf x_i- E(\\mathbf x_i|\\mathbf z_i))\\theta +\\epsilon_i\\)\n\nWe define:\n\n\\begin{itemize}\n\\item \\(\\bar y_i = y_i-E(y_i|\\mathbf z_i)\\)\n\\item \\(\\bar x_i = \\mathbf x_i- E(\\mathbf x_i|\\mathbf z_i)\\)\n\\end{itemize}\n\n\\(\\bar y_i =\\bar x_i \\theta +\\epsilon_i\\)\n\n\\subsubsection{Estimating \\(\\bar y_i\\) and \\(\\bar x_i\\)}\n\nSo we can use OLS if we can estimate.\n\n\\begin{itemize}\n\\item \\(E(y_i|\\mathbf z_i)\\)\n\\item \\(E(\\mathbf x_i|\\mathbf z_i)\\)\n\\end{itemize}\n\nWe can do this with non-parametric methods.\n\n", "meta": {"hexsha": "20ba29ff939bcd0b8d527370bbdfe6d55c6ec7f3", "size": 1094, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/semiParametric/01-02-robinson.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/semiParametric/01-02-robinson.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/semiParametric/01-02-robinson.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0476190476, "max_line_length": 124, "alphanum_fraction": 0.6718464351, "num_tokens": 424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.8080748520243396}}
{"text": "\\chapter{Computation}\n\n\\subsection{Complexity}\n\nBig-O notation is typically used to approximate the time dependence on the number of elements you feed into an algorithm. In Big-O notation, we ignore all lower order terms, and also forget about any leading constants.\n\nListed are some standard algorithms and their dependence.\n\n\\begin{center}\n\\begin{tabular}{ | c | c|} \n\\hline\n $N$-Dependence & Algorithm\\\\ \\hline\n$O(1)$ & Accessing an element in an array  \\\\ \n$O(\\log N)$ & Binary Search  \\\\\n$O(N)$ & Single \\texttt{for} loop \\\\ \n$O(N^2)$ & Simple sorting algorithm (bubble, selection, ...)\\\\\n$O(c^N)$ & Solving the traveling salesman problem with dynamic programming \\\\\n$O(N!)$ & Iterations over all combinatorics \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\subsection{Binary Representations}\n\nComputers typically represent information in binary. Knowing roughly how large objects are in memory is useful when solving problems. A sequence of bits represents powers of 2, which can be arranged to represent all integer values from 0 to $2^N-1$ where $N$ is the amount of bits you have. \n\\begin{center}\n\\begin{tabular}{ | c | c| c|} \n\\hline\n bits & unique values & label \\\\ \\hline\n7 & $128$ &  \\\\ \n8 & $256$ &  \\\\ \n10 & $1,024$ & KB \\\\ \n20 & $1,048,576$ & MB \\\\ \n30 & $1,073,741,824$ & GB \\\\ \n\\hline\n\\end{tabular}\n\\end{center}\n\nAdding $10$ to a power of two increases the amount of memory used by roughly a factor of $1000$.\n\nThere are slight subtleties involving whether we are counting using binary prefixes (e.g. kibibyte = KB) or decimal prefixes (e.g. kilobyte = kB). Binary prefixes count in units of 1024 (a power of two, near 1000), whereas decimal prefixes count in powers of 10. \n\n\\subsection{Efficient Algorithms}\n\n\\subsection{Averaging}\nWhen updating an average which contains many elements, the naive way of calculating the average is $O(n)$ efficient \n\\begin{align}\n\t\\langle x_{n-1}\\rangle = \\frac{1}{n-1}\\sum_{i=0}^{n-1} x_i\n\\end{align}\nWhen constantly updating the average, we can use the following equivalent formula\n\\begin{align}\n\t\\langle x_{n}\\rangle &= \\frac{1}{n}\\sum_{i=0}^{n} x_i\\\\\n\t&= \\frac{1}{n}\\Big(x_n + (n-1)\\langle x_{n-1}\\rangle\\Big)\\\\\n\t&= \\langle x_{n-1}\\rangle + \\frac{1}{n}\\Big(x_n - \\langle x_{n-1} \\rangle\\Big)\n\\end{align}\nThis modified algorithm is $O(1)$ efficient.\n\n\\subsection{Estimating Probabilities}\nWhen multiplying many different probabilities $p_i$ together, the floating point precision of many computing languages starts to become an issue. To avoid this problem, often $\\log(p_i)$ is used which is monotonic with the probability but avoids the \\textit{underflow} issue described.\n\n\\subsection{Graph Theory}\nBrute force algorithms that search all combinations of $N$ items scale as $N!$. The Seven Bridges of Konigsberg is a famous example solved by Euler, for which he laid our all combinations of sequences you could possibly cross the seven bridges (e.g. $1234567, 1234576,...$ and was able to show each combination did not work.\n\n\n\\subsection{Kernels}\nKernels are useful when one wants to represent a set of data points in a higher dimensional space (e.g. when making a classifier using Support Vector Machines). One represents the transformation of a set of data points $\\B{x}$ as $\\B{x}\\rightarrow \\phi(\\B{x})$. Mathematically a Kernel function is defined as\n\\begin{align}\n\tK(\\B{x},\\B{x}') = \\phi(\\B{x})\\cdot \\phi(\\B{x}')\n\\end{align}\n\n Kernels themselves are a measure of similarity between two different points of data $\\B{x}$ and $\\B{x}'$ (e.g. cosine similarity). Their main utility lies in the fact that cleverly defined kernels can significantly reduce the amount of computation necessary when one wants to expand the dimensionality of the dataset. It happens that many algorithms in machine learning can be written in terms of dot products, which allows kernel methods to be used if one wants change dimensionality.\n\n\\subsubsection{Polynomial Kernel}\nThe polynomial kernel is defined as\n\\begin{align}\\label{pol_kern}\n\tK_d(\\B{x},\\B{x}') = (1+ \\B{x}\\cdot \\B{x}')^d\n\\end{align}\nWhere $d$ is the dimension you wish to expand the data to. To illustrate the utility of the kernel, let us take\n\\begin{align}\\label{pol_kern_example}\n\t\\B{x} = (x_1,x_2) && \\B{x}' = (x_1',x_2')\n\\end{align}\nIf we want to increase the dimensionality of our data to consider all second order terms and below, one can define the transformation function as\n\\begin{align}\n\t\\phi(\\B{x}) = (1, \\sqrt{2}x_1, \\sqrt{2}x_2, x_1^2, x_2^2, \\sqrt{2}x_1x_2)\n\\end{align}\nIf it happens that each time the data shows up, a dot product is used, then the condition for using a kernel condition is satisfied.\n\\begin{align}\n\t\\B{x}\\cdot \\B{x}' \\rightarrow \\phi(\\B{x})\\cdot \\phi(\\B{x}')\n\\end{align}\nLet us then compute this dot product for Equation \\ref{pol_kern_example}\n\\begin{align}\n\t\\phi(\\B{x})\\cdot \\phi(\\B{x}') &= (1, \\sqrt{2}x_1, \\sqrt{2}x_2, x_1^2, x_2^2, \\sqrt{2}x_1x_2) \\\\\n\t&\\cdot (1, \\sqrt{2}x_1', \\sqrt{2}x_2', x_1^{'2}, x_2^{'2}, \\sqrt{2}x_1'x_2')\\\\\n\t&= 1 + 2x_1x_1' + 2x_2x_2' + x_1^2x_1^{'2}+x_2^2x_2^{'2} + 2x_1x_2x_1'x_2' \\label{pol_kern_expand}\n\\end{align}\nNow let's think about what the computer actually has to do to compute all of these terms. We would first have to calculate each term for $\\phi(\\B{x})$ and $\\phi(\\B{x}')$, which requires \\emph{twelve} multiplications. Next we would have to compute the dot product of $\\phi(\\B{x}')\\cdot\\phi(\\B{x}')$, which requires another \\emph{six} multiplications followed by \\emph{five} additions. In total, for just increasing the dimensionality of the data by one degree, we have 18 multiplication and 5 addition operations involved for each set of points.\n\nHowever, one can identify that using the polynomial kernel definition of Equation \\ref{pol_kern} for $d=2$ gives the same result\n\\begin{align}\n\t(1+ \\B{x}\\cdot \\B{x}')^2 &= \\Big(1+(x_1,x_2)\\cdot(x_1',x_2')\\Big)^2\\\\\n\t&= \\Big(1+x_1x_1'+x_2x_2'\\Big)^2\\\\\n\t&= 1 + 2x_1x_1' + 2x_2x_2' + x_1^2x_1^{'2}+x_2^2x_2^{'2} + 2x_1x_2x_1'x_2'\n\\end{align}\nThis final expression is \\emph{exactly equivalent} to that of Equation \\ref{pol_kern_expand}, however, let us think about how many operations were necessary to actually compute the numerical value. We begin with \\emph{two} multiplications followed by \\emph{two} additions, followed by \\emph{one} multiplication. In total, by expression function this way, we get away with only \\emph{three} multiplication and \\emph{two} addition operations. This reduction in overhead can pay off big time, especially when expanding to even higher dimensions.\n\n\\subsubsection{Radial Basis Kernel}\nThe radial basis kernel is defined as \n\\begin{align}\n\t\tK(\\B{x},\\B{x}') = \\exp\\Big(-\\frac{||\\B{x}-\\B{x}'||^2}{2\\sigma^2}\\Big)\n\\end{align}\nThis metric is a measure of similarity, when the two vectors are identical, the kernel evaluates to 1, while if they are infinitely far apart, it evaluates to 0.\n\n\n\n\\subsection{Quantum Computation}\n\\subsubsection{Grovers Algorithm}\n%\\url{https://en.wikipedia.org/wiki/Grover%27s_algorithm}", "meta": {"hexsha": "ca8d269da40316d2e4d1da2e370fc6b3618ebebb", "size": 6967, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathematics/computation.tex", "max_stars_repo_name": "williamnash/notes", "max_stars_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mathematics/computation.tex", "max_issues_repo_name": "williamnash/notes", "max_issues_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-08-23T23:01:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-16T23:17:43.000Z", "max_forks_repo_path": "mathematics/computation.tex", "max_forks_repo_name": "williamnash/notes", "max_forks_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.547008547, "max_line_length": 544, "alphanum_fraction": 0.7280034448, "num_tokens": 2118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561135, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.8080586186404722}}
{"text": "\\subsection{Concavity and Inflection Points}\\label{sec:Concavity}\nWe know that the sign of the derivative tells us whether a function is\nincreasing or decreasing; for example, when $f'(x)>0$,\n$f(x)$ is increasing. The sign of the second derivative\n$f''(x)$ tells us whether $f'$ is increasing or decreasing; we have\nseen that if $f'$ is zero and increasing at a point then there is a\nlocal minimum at the point. If $f'$ is zero and decreasing at a\npoint then there is a local maximum at the point. Thus, we extracted\ninformation about $f$ from information about $f''$. \n\nWe can get information from the sign of $f''$ even when $f'$ is not\nzero. Suppose that $f''(a)>0$. This means that near $x=a$, $f'$ is\nincreasing. If $f'(a)>0$, this means that $f$ slopes up and is getting\nsteeper; if $f'(a)<0$, this means that $f$ slopes down and is getting\n{\\it less} steep. The two situations are shown in\nfigure~\\ref{fig:concave up}. A curve that is shaped like this is\ncalled \\dfont{concave up}.\n\n\n\\figure[H]\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <2truecm,2truecm>\n\\setplotarea x from 0 to 1, y from 0 to 1\n\\axis left shiftedto x=0 /\n\\axis bottom shiftedto y=0 ticks withvalues {$a$} / at 0.5 / /\n\\setquadratic\n\\plot 0.1 0.2 0.5 0.4 0.9 0.9 /\n\\setcoordinatesystem units <2truecm,2truecm> point at -2 0\n\\setplotarea x from 0 to 1, y from 0 to 1\n\\axis left shiftedto x=0 /\n\\axis bottom shiftedto y=0 ticks withvalues {$a$} / at 0.5 / /\n\\setquadratic\n\\plot 0.1 0.9 0.5 0.3 0.9 0.1 /\n\\endpicture}}\n\\caption{$f''(a)>0$: $f'(a)$ positive and increasing, $f'(a)$ negative and\n  increasing. \\label{fig:concave up}}\n\\endfigure\n\nNow suppose that $f''(a)<0$. This means that near $x=a$, $f'$ is\ndecreasing. If $f'(a)>0$, this means that $f$ slopes up and is getting\nless steep; if $f'(a)<0$, this means that $f$ slopes down and is getting\nsteeper. The two situations are shown in\nfigure~\\ref{fig:concave down}. A curve that is shaped like this is\ncalled \\dfont{concave down}.\n\n\n\\figure[H]\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <2truecm,2truecm>\n\\setplotarea x from 0 to 1, y from 0 to 1\n\\axis left shiftedto x=0 /\n\\axis bottom shiftedto y=0 ticks withvalues {$a$} / at 0.5 / /\n\\setquadratic\n\\plot 0.1 0.2 0.5 0.7 0.9 0.9 /\n\\setcoordinatesystem units <2truecm,2truecm> point at -2 0\n\\setplotarea x from 0 to 1, y from 0 to 1\n\\axis left shiftedto x=0 /\n\\axis bottom shiftedto y=0 ticks withvalues {$a$} / at 0.5 / /\n\\setquadratic\n\\plot 0.1 0.9 0.5 0.6 0.9 0.1 /\n\\endpicture}}\n\\caption{$f''(a)<0$: $f'(a)$ positive and decreasing, $f'(a)$ negative and\n  decreasing. \\label{fig:concave down}}\n\\endfigure\n\nIf we are trying to understand the shape of the graph of a function,\nknowing where it is concave up and concave down helps us to get a more\naccurate picture. Of particular interest are points at which the\nconcavity changes from up to down or down to up; such points are\ncalled \\dfont{inflection points}. If the\nconcavity changes from up to down at $x=a$, $f''$ changes from\npositive to the left of $a$ to negative to the right of $a$, and\nusually $f''(a)=0$. We can identify such points by first finding where\n$f''(x)$ is zero and then checking to see whether $f''(x)$ does in\nfact go from positive to negative or negative to positive at these\npoints. Note that it is possible that $f''(a)=0$ but the concavity is\nthe same on both sides; $\\ds f(x)=x^4$ at $x=0$ is an example.\n\n\\begin{example}{Concavity}{concavity}\nDescribe the concavity of $\\ds f(x)=x^3-x$.\n\\end{example}\n\\begin{solution}\nThe derivatives are $\\ds f'(x)=3x^2-1$ and $f''(x)=6x$.\nSince $f''(0)=0$, there is potentially an inflection point at\nzero. Since $f''(x)>0$ when $x>0$ and $f''(x)<0$ when $x<0$ the\nconcavity does change from concave down to concave up at zero, and the curve is\nconcave down for all $x<0$ and concave up for all $x>0$.\n\\end{solution}\n\nNote that we need to compute and analyze the second derivative to\nunderstand concavity, so we may as well try to use the second\nderivative test for maxima and minima. If for some reason this fails\nwe can then try one of the other tests.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Concavity}}\n\n\\begin{enumialphparenastyle}\n\nDescribe the concavity of the functions below.\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=x^2-x$ \n\\begin{sol}\n concave up everywhere\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=2+3x-x^3$ \n\\begin{sol}\n concave up when $x<0$, concave down when $x>0$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=x^3-9x^2+24x$\n\\begin{sol}\n concave down when $x<3$, concave up when $x>3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=x^4-2x^2+3$ \n\\begin{sol}\n concave up when $\\ds x<-1/\\sqrt3$ or $\\ds x>1/\\sqrt3$,\nconcave down when $\\ds -1/\\sqrt3<x<1/\\sqrt3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=3x^4-4x^3$\n\\begin{sol}\n concave up when $x<0$ or $x>2/3$,\nconcave down when $0<x<2/3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=(x^2-1)/x$\n\\begin{sol}\n concave up when $x<0$, concave down when $x>0$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=3x^2-(1/x^2)$ \n\\begin{sol}\n concave up when $x<-1$ or $x>1$, concave down when\n$-1<x<0$ or $0<x<1$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $y=\\sin x + \\cos x$ \n\\begin{sol}\n concave down on $((8n-1)\\pi/4,(8n+3)\\pi/4)$,\nconcave up on $((8n+3)\\pi/4,(8n+7)\\pi/4)$, for integer $n$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = 4x+\\sqrt{1-x}$\n\\begin{sol}\n concave down everywhere\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = (x+1)/\\sqrt{5x^2 + 35}$\n\\begin{sol}\n concave up on $\\ds (-\\infty,(21-\\sqrt{497})/4)$ and \n$\\ds (21+\\sqrt{497})/4,\\infty)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y= x^5 - x$\n\\begin{sol}\n concave up on $(0,\\infty)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = 6x + \\sin 3x$\n\\begin{sol}\n concave down on $(2n\\pi/3,(2n+1)\\pi/3)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = x+ 1/x$\n\\begin{sol}\n concave up on $(0,\\infty)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = x^2+ 1/x$\n\\begin{sol}\n concave up on $(-\\infty,-1)$ and $(0,\\infty)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = (x+5)^{1/4}$\n\\begin{sol}\n concave down everywhere\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = \\tan^2 x$\n\\begin{sol}\n concave up everywhere\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y =\\cos^2 x - \\sin^2 x$\n\\begin{sol}\n concave up on $(\\pi/4+n\\pi,3\\pi/4+n\\pi)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y = \\sin^3 x$\n\\begin{sol}\n inflection points at $n\\pi$, $\\ds \\pm\\arcsin(\\sqrt{2/3})+n\\pi$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Identify the intervals on which the graph of the function\n$\\ds f(x) = x^4-4x^3 +10$ is of one of these four\nshapes: concave up and increasing; concave up and decreasing; concave\ndown and increasing; concave down and decreasing.\n\\begin{sol}\n up/incr: $(3,\\infty)$, up/decr: $(-\\infty,0)$, $(2,3)$,\ndown/decr: $(0,2)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Describe the concavity of $\\ds y =  x^3 + bx^2 + cx + d$.\nYou will need to consider different cases, depending on the values of\nthe coefficients.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Let $n$ be an integer greater than or equal to\ntwo, and suppose $f$ is a polynomial of degree $n$. How many inflection points\ncan $f$ have?  Hint: Use the second derivative test and the\nfundamental theorem of algebra.\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "a508ab5f71a4af7fa7f1d48553278762e5d20aa0", "size": 7441, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-6-3-concavity-inflection-pts.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5-applications-of-derivatives/5-6-3-concavity-inflection-pts.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5-applications-of-derivatives/5-6-3-concavity-inflection-pts.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.2007042254, "max_line_length": 79, "alphanum_fraction": 0.6512565515, "num_tokens": 2693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.9399133536130196, "lm_q1q2_score": 0.808009438721322}}
{"text": "\\subsubsection{Alternative Derivation Using Bayes' Rule}\\label{sec:set_bayes}\nIn the measure-theoretic approach studied in~\\cite{BBE11, BET+14}, Voronoi-cell discretizations of $\\pspace$ are used to construct set-valued approximations of the updated measure directly, so we refer to it as the \\emph{explicit} approach.\nBy contrast, sampling from densities is an \\emph{implicit} approach, and is discussed in greater detail in \\ref{sec:ch02-sample}.\nHere, we provide a ``set-based'' derivation of the updated measure to more easily compare to the explicit approximation of the solution given measure in~\\cite{BET+14}.\n\nFirst, we start by observing that if $A, B \\subset \\pspace$ such that $A = \\qoi^{-1}(\\qoi(B))$, then we have that $B\\subset A$ (the inclusion may be proper).\nTherefore, for any probability measure $\\PP$ on $(\\pspace, \\pborel)$,\n\\[\n\\PP(B) = \\PP(B|A) \\, \\PP(A).\n\\]\nIf $\\PP$ is intended to solve the inverse problem, then we are motivated to take\n\\[\n\\PP(A) = \\observedP (\\qoi(A)) = \\observedP (B),\n\\]\nin the above formula.\n\nWe must now determine how to properly define $\\PP(B|A)$.\nWe leverage Bayes' Theorem~\\cite{Smith} in order to utilize the prior density on contour events.\nIn other words, we use the prior (ansatz) measure $\\initialP$ extended on $(\\pspace, \\pborel)$ and Bayes' Theorem to get\n\\begin{equation}\\label{eq:bayes_full}\n\\PP(B|A) = \\initialP(B|A) = \\frac{ \\initialP(A|B) \\initialP(B) }{ \\initialP(A) },\n\\end{equation}\nand since $B \\subset A$, $\\initialP(A|B) = 1$, \\eqref{eq:bayes_full} simplifies to\n\n\\begin{equation}\\label{eq:bayes}\n\\initialP(B|A) = \\frac{ \\initialP(B) }{ \\initialP(A) }.\n\\end{equation}\n\nRecall from \\eqref{eq:predicted} that $\\predictedP$ is the push-forward of the initial measure, giving $\\initialP(A) = \\predictedP (\\qoi(A)) = \\predictedP \\left (\\qoi(B)\\right )$, which then gives the following set-valued ``solution'' to the stochastic inverse problem:\n\\begin{equation}\\label{eq:sip_sol_cont}\n\\updatedP(B) := \\begin{cases}\n\\initialP(B) \\frac{ \\observedP(B) }{ \\predictedP \\left (\\qoi(B)\\right ) ) } & \\text{ if } \\initialP(B) > 0,\\\\\n0 & \\text{ otherwise}.\n\\end{cases}\n\\end{equation}\n\nThis set-valued update is only a solution on certain (sub-)$\\sigma$-algebras of $\\pborel$ for which $B$ must belong to apply \\eqref{eq:sip_sol_cont}.\nNonetheless, we can form explicit approximations to this measure, e.g. as done in~\\cite{BET+14, BES12, BBE11}.\nIn other words, an Ansatz is used in place of the prior; it serves the same purpose to distribute probabilities in directions not informed by the QoI map.\n\n% However, such an explicit approach requires an approximation of \\emph{events in $\\pborel$}.\n% This is in direct contrast to the numerical approximation of the density $\\updated$ that only requires approximation of $\\predicted$.\n% Since we often expect the dimension of $\\dspace$ to be less than the dimension of $\\pspace$, this can prove to be a significant numerical advantage for the ``implicit'' approximation given by the updated probability density function.\n", "meta": {"hexsha": "d34f2c0833edbdc36c82ee68347eb90a805d8de1", "size": 3022, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch02/set_derivation_bayes.tex", "max_stars_repo_name": "mathematicalmichael/thesis", "max_stars_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-24T08:05:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-28T20:34:29.000Z", "max_issues_repo_path": "ch02/set_derivation_bayes.tex", "max_issues_repo_name": "mathematicalmichael/thesis", "max_issues_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 59, "max_issues_repo_issues_event_min_datetime": "2019-12-27T23:15:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T17:52:57.000Z", "max_forks_repo_path": "ch02/set_derivation_bayes.tex", "max_forks_repo_name": "mathematicalmichael/thesis", "max_forks_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.6818181818, "max_line_length": 269, "alphanum_fraction": 0.730641959, "num_tokens": 881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896758909757, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.8079715696975477}}
{"text": "\\chapter{General tridiagonal linear systems}\n\nWe consider solving an $n\\times n$ linear system \n$\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$ where the matrix~$\\boldsymbol{A}$\nis tridiagonal but not necessarily symmetric or positive-definite.  For concreteness,\nsuppose at first that $n=5$ and write\n\\[\n\\boldsymbol{A}=\\begin{bmatrix}\n\\alpha_1&\\gamma_1&        &        &\\\\\n \\beta_1&\\alpha_2&\\gamma_2&        &\\\\\n        & \\beta_2&\\alpha_3&\\gamma_3&\\\\\n        &        & \\beta_3&\\alpha_4&\\gamma_4\\\\\n        &        &        & \\beta_4&\\alpha_5\n\\end{bmatrix}\n\\]\nWe will reduce $\\boldsymbol{A}$ to upper triangular form by Gaussian \nelimination.  \n\nIf $|\\beta_1|\\le|\\alpha_1|$ then we define the \\emph{Gauss transformation}\n\\[\n\\boldsymbol{M}_1=\\begin{bmatrix}\n     1& & & &\\\\\n-\\ell_1&1& & &\\\\\n      & &1& &\\\\\n      & & &1&\\\\\n      & & & &1\n\\end{bmatrix}\n\\quad\\text{where}\\quad\\ell_1=\\frac{\\beta_1}{\\alpha_1},\n\\]\nin order to eliminate the $21$-entry~$\\beta_1$:\n\\[\n\\boldsymbol{M}_1\\boldsymbol{A}=\n\\begin{bmatrix}\n      1& & & &\\\\\n-\\ell_1&1& & &\\\\\n       & &1& &\\\\\n       & & &1&\\\\\n       & & & &1\n\\end{bmatrix}\n\\begin{bmatrix}\n\\alpha_1&\\gamma_1&        &        &\\\\\n \\beta_1&\\alpha_2&\\gamma_2&        &\\\\\n        & \\beta_2&\\alpha_3&\\gamma_3&\\\\\n        &        & \\beta_3&\\alpha_4&\\gamma_4\\\\\n        &        &        & \\beta_4&\\alpha_5\n\\end{bmatrix}\n=\\begin{bmatrix}\n\\alpha_1& \\gamma_1&        &        &\\\\\n        &\\alpha_2'&\\gamma_2&        &\\\\\n        &  \\beta_2&\\alpha_3&\\gamma_3&\\\\\n        &         & \\beta_3&\\alpha_4&\\gamma_4\\\\\n        &         &        & \\beta_4&\\alpha_5\n\\end{bmatrix}\n\\]\nwhere\n\\[\n\\alpha_2'=\\alpha_2-\\ell_1\\gamma_1.\n\\]\n\nHowever, if $|\\beta_1|>|\\alpha_1|$ then we swap the first two rows to move \n$\\beta_1$ to the pivot position.  To perform this operation, we swap the first \ntwo rows of the $5\\times5$ identity matrix to obtain a \\emph{permutation matrix}\n\\[\n\\boldsymbol{P}_1=\\begin{bmatrix}\n &1& & &\\\\\n1& & & &\\\\\n & &1& &\\\\\n & & &1&\\\\\n & & & &1\n\\end{bmatrix},\n\\]\nand observe that\n\\[\n\\boldsymbol{P}_1\\boldsymbol{A}=\n\\begin{bmatrix}\n &1& & &\\\\\n1& & & &\\\\\n & &1& &\\\\\n & & &1&\\\\\n & & & &1\n\\end{bmatrix}\n\\begin{bmatrix}\n\\alpha_1&\\gamma_1&        &        &\\\\\n \\beta_1&\\alpha_2&\\gamma_2&        &\\\\\n        & \\beta_2&\\alpha_3&\\gamma_3&\\\\\n        &        & \\beta_3&\\alpha_4&\\gamma_4\\\\\n        &        &        & \\beta_4&\\alpha_5\n\\end{bmatrix}\n=\\begin{bmatrix}\n \\beta_1&\\alpha_2&\\gamma_2&        &\\\\\n\\alpha_1&\\gamma_1&        &        &\\\\\n        & \\beta_2&\\alpha_3&\\gamma_3&\\\\\n        &        & \\beta_3&\\alpha_4&\\gamma_4\\\\\n        &        &        & \\beta_4&\\alpha_5\n\\end{bmatrix}.\n\\]\nWe let\n\\[\n\\ell_1=\\frac{\\alpha_1}{\\beta_1},\\quad\n\\alpha_1'=\\beta_1,\\quad\\gamma_1'=\\alpha_2,\\quad\\delta_1=\\gamma_2,\\quad\n\\alpha_2'=\\gamma_1-\\ell_1\\alpha_2,\\quad\\gamma_2'=-\\ell_1\\gamma_2,\n\\]\nso that\n\\[\n\\boldsymbol{M}_1\\boldsymbol{P_1}\\boldsymbol{A}\n=\\begin{bmatrix}\n      1& & & &\\\\\n-\\ell_1&1& & &\\\\\n       & &1& &\\\\\n       & & &1&\\\\\n       & & & &1\n\\end{bmatrix}\n\\begin{bmatrix}\n \\beta_1&\\alpha_2&\\gamma_2&        &\\\\\n\\alpha_1&\\gamma_1&        &        &\\\\\n        & \\beta_2&\\alpha_3&\\gamma_3&\\\\\n        &        & \\beta_3&\\alpha_4&\\gamma_4\\\\\n        &        &        & \\beta_4&\\alpha_5\n\\end{bmatrix}\n=\\begin{bmatrix}\n\\alpha_1'&\\gamma_1'& \\delta_1&        &\\\\\n         &\\alpha_2'&\\gamma_2'&        &\\\\\n         & \\beta_2 &\\alpha_3 &\\gamma_3&\\\\\n         &         & \\beta_3 &\\alpha_4&\\gamma_4\\\\\n         &         &         & \\beta_4&\\alpha_5\n\\end{bmatrix}.\n\\]\n\nFor both of the above cases, performing the computations in place will result \nin a matrix \n\\[\n\\boldsymbol{A}_1=\n\\begin{bmatrix}\n\\alpha_1&\\gamma_1&\\delta_1&        &\\\\\n        &\\alpha_2&\\gamma_2&        &\\\\\n        & \\beta_2&\\alpha_3&\\gamma_3&\\\\\n        &        & \\beta_3&\\alpha_4&\\gamma_4\\\\\n        &        &        & \\beta_4&\\alpha_5\n\\end{bmatrix},\n\\]\nwith~$\\delta_1=0$ in the former case.  If $|\\beta_2|\\le|\\alpha_2|$, then we put\n\\[\n\\boldsymbol{M}_2=\\begin{bmatrix}\n1&       & & &\\\\\n &      1& & &\\\\\n &-\\ell_2&1& &\\\\\n &       & &1&\\\\\n &       & & &1\n\\end{bmatrix}\\quad\\text{where}\\quad\\ell_2=\\frac{\\beta_2}{\\alpha_2}\n\\]\nso that\n\\[\n\\boldsymbol{M}_2\\boldsymbol{A}_1=\n\\boldsymbol{M}_2=\\begin{bmatrix}\n1&       & & &\\\\\n &      1& & &\\\\\n &-\\ell_2&1& &\\\\\n &       & &1&\\\\\n &       & & &1\n\\end{bmatrix}\n\\begin{bmatrix}\n\\alpha_1&\\gamma_1&\\delta_1&        &\\\\\n        &\\alpha_2&\\gamma_2&        &\\\\\n        & \\beta_2&\\alpha_3&\\gamma_3&\\\\\n        &        & \\beta_3&\\alpha_4&\\gamma_4\\\\\n        &        &        & \\beta_4&\\alpha_5\n\\end{bmatrix}=\n\\begin{bmatrix}\n\\alpha_1&\\gamma_1& \\delta_1&        &\\\\\n        &\\alpha_2& \\gamma_2&        &\\\\\n        &        &\\alpha_3'&\\gamma_3&\\\\\n        &        &  \\beta_3&\\alpha_4&\\gamma_4\\\\\n        &        &         & \\beta_4&\\alpha_5\n\\end{bmatrix},\n\\]\nwhere\n\\[\n\\alpha_3'=\\alpha_3-\\ell_2\\gamma_2.\n\\]\nIf $|\\beta_2|>|\\alpha_2|$ then we swap rows 2~and 3 to move $\\beta_2$ to the \npivot position, letting\n\\[\n\\boldsymbol{P}_2=\\begin{bmatrix}\n1& & & &\\\\\n & &1& &\\\\\n &1& & &\\\\\n & & &1&\\\\\n & & & &1\n\\end{bmatrix}\n\\]\nso that\n\\[\n\\boldsymbol{P}_2\\boldsymbol{A}_1\n=\\begin{bmatrix}\n1& & & &\\\\\n & &1& &\\\\\n &1& & &\\\\\n & & &1&\\\\\n & & & &1\n\\end{bmatrix}\n\\begin{bmatrix}\n\\alpha_1&\\gamma_1&\\delta_1&        &\\\\\n        &\\alpha_2&\\gamma_2&        &\\\\\n        & \\beta_2&\\alpha_3&\\gamma_3&\\\\\n        &        & \\beta_3&\\alpha_4&\\gamma_4\\\\\n        &        &        & \\beta_4&\\alpha_5\n\\end{bmatrix}\n=\\begin{bmatrix}\n\\alpha_1&\\gamma_1&\\delta_1&        &\\\\\n        & \\beta_2&\\alpha_3&\\gamma_3&\\\\\n        &\\alpha_2&\\gamma_2&        &\\\\\n        &        & \\beta_3&\\alpha_4&\\gamma_4\\\\\n        &        &        & \\beta_4&\\alpha_5\n\\end{bmatrix}\n\\]\nWith\n\\[\n\\ell_2=\\frac{\\alpha_2}{\\beta_2},\\quad\\alpha_2'=\\beta_2,\\quad\n\\gamma_2'=\\alpha_3,\\quad\\delta_2=\\gamma_3,\\quad\n\\alpha_3'=\\gamma_2-\\ell_2\\alpha_3,\\quad\\gamma_3'=-\\ell_2\\gamma_3,\n\\]\nwe obtain\n\\[\n\\boldsymbol{M}_2\\boldsymbol{P}_2\\boldsymbol{A}_1\n=\\begin{bmatrix}\n1&       & & &\\\\\n &      1& & &\\\\\n &-\\ell_2&1& &\\\\\n &       & &1&\\\\\n &       & & &1\n\\end{bmatrix}\n\\begin{bmatrix}\n\\alpha_1&\\gamma_1&\\delta_1&        &\\\\\n        & \\beta_2&\\alpha_3&\\gamma_3&\\\\\n        &\\alpha_2&\\gamma_2&        &\\\\\n        &        & \\beta_3&\\alpha_4&\\gamma_4\\\\\n        &        &        & \\beta_4&\\alpha_5\n\\end{bmatrix}\n=\\begin{bmatrix}\n\\alpha_1& \\gamma_1& \\delta_1&         &\\\\\n        &\\alpha_2'&\\gamma_2'&\\delta_2 &\\\\\n        &         &\\alpha_3'&\\gamma_3'&\\\\\n        &         &  \\beta_3&\\alpha_4 &\\gamma_4\\\\\n        &         &         & \\beta_4 &\\alpha_5\n\\end{bmatrix}.\n\\]\nContinuing in this way, we finish up with an upper triangular matrix\n\\[\n\\boldsymbol{U}=\n\\boldsymbol{M}_4\\boldsymbol{P_4}\n\\boldsymbol{M}_3\\boldsymbol{P_3}\n\\boldsymbol{M}_2\\boldsymbol{P_2}\n\\boldsymbol{M}_1\\boldsymbol{P_1}\\boldsymbol{A}\n=\\begin{bmatrix}\n\\alpha_1&\\gamma_1&\\delta_1&        &\\\\\n        &\\alpha_2&\\gamma_2&\\delta_2&\\\\\n        &        &\\alpha_3&\\gamma_3&\\delta_3\\\\\n        &        &        &\\alpha_4&\\gamma_4\\\\\n        &        &        &        &\\alpha_5\n\\end{bmatrix},\n\\]\nwhere each $\\boldsymbol{P}_k$ is either the $5\\times5$ identity matrix, or else \nthe permutation matrix that results from swapping rows $k$~and $k+1$.  \n\n\\begin{algorithm}\n\\caption{Compute the $LU$ factorization of a (possibly non-symmetric) \ntridiagonal matrix.}\n\\label{alg: tridiagonal LU}\n\\begin{algorithmic}\n\\Require $\\boldsymbol{\\beta}=[\\beta_1,\\beta_2,\\ldots,\\beta_{n-1}]$ is the \nsub-diagonal of $\\boldsymbol{A}$.\n\\Require $\\boldsymbol{\\alpha}=[\\alpha_1,\\alpha_2,\\ldots,\\alpha_n]$ is the main \ndiagonal of $\\boldsymbol{A}$.\n\\Require $\\boldsymbol{\\gamma}=[\\gamma-1,\\gamma_2,\\ldots,\\gamma_{n-1}]$ is the \nsuper-diagonal of $\\boldsymbol{A}$.\n\\Require $\\boldsymbol{\\delta}=[\\delta_1,\\delta_2,\\ldots,\\delta_{n-2}]$ is \nstorage to hold fill-in of the second super-diagonal.\n\\Require $\\boldsymbol{p}=[p_1,p_2,\\ldots,p_{n-1}]$ is an boolean vector to \nrecord which steps use a row swap.\n\\Statex\n\\Function{Factorize!}{$\\boldsymbol{\\beta}, \\boldsymbol{\\alpha},\n\\boldsymbol{\\gamma}, \\boldsymbol{\\delta}, \\boldsymbol{p}$}\n\\For{$j=1:n-2$}\n\t\\State $\\delta_j\\gets0$\n\t\\If{$|\\alpha_j|<|\\beta_j|$}\\Comment{Swap rows $j$ and $j+1$}\n\t\t\\State $p_j\\gets\\mathbf{true}$\n\t\t\\State $\\alpha_j\\swap\\beta_j$\n\t\t\\State $\\gamma_j\\swap\\alpha_{j+1}$\n\t\t\\State $\\delta_j\\swap\\gamma_{j+1}$\n\t\\Else\n\t\t\\State $p_j\\gets\\mathbf{false}$\n\t\\EndIf\n\t\\State $\\beta_j\\gets\\beta_j/\\alpha_j$\n\t\\State $\\alpha_{j+1}\\gets\\alpha_{j+1}-\\beta_j\\gamma_j$\n\t\\If{$p_j$}\n\t\t\\State $\\gamma_{j+1}\\gets-\\beta_j\\delta_j$\n\t\\EndIf\n\\EndFor\n\\If{$|\\alpha_{n-1}|<|\\beta_{n-1}|$}\n\t\\State $p_{n-1}\\gets\\mathbf{true}$\n\t\\State $\\alpha_{n-1}\\swap\\beta_{n-1}$\n\t\\State $\\gamma_{n-1}\\swap\\alpha_n$\n\\Else\n\t\\State $p_{n-1}\\gets\\mathbf{false}$\n\\EndIf\n\\State $\\beta_{n-1}\\gets\\beta_{n-1}/\\alpha_{n-1}$\n\\State $\\alpha_n\\gets\\alpha_n-\\beta_{n-1}\\gamma_{n-1}$\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}\n\nDefine the column vectors\n\\[\n\\boldsymbol{\\ell}_k=\\ell_k\\boldsymbol{e}_k\n\\quad\\text{for $1\\le k\\le 4$,}\n\\]\nand observe that\n\\[\n\\boldsymbol{M}_k=\\boldsymbol{I}-\\boldsymbol{\\ell}_k\\boldsymbol{e}_k^T\n\\quad\\text{and}\\quad\n\\boldsymbol{P_k}^T=\\boldsymbol{P}_k\n\\quad\\text{for $1\\le k\\le 4$,}\n\\]\nwith\n\\[\n\\boldsymbol{P}_k\\boldsymbol{e}_j=\\boldsymbol{e}_j\n\\quad\\text{and}\\quad\n\\boldsymbol{e}_j^T=\\boldsymbol{e}_j^T\\boldsymbol{P}_k\n\\quad\\text{for $1\\le j<k\\le 4$.}\n\\]\nThus,\n\\[\n\\boldsymbol{P}_4\\boldsymbol{M}_3\n\t=\\boldsymbol{P}_4-\\boldsymbol{P}_4\\boldsymbol{\\ell}_3\\boldsymbol{e}_3^T\n\t=\\bigl(\\boldsymbol{I}-\\boldsymbol{P}_4\\boldsymbol{\\ell}_3\\boldsymbol{e}_3^T\n\t\\bigr)\\boldsymbol{P}_4\n\t=\\widetilde{\\boldsymbol{M}}_3\\boldsymbol{P_4},\n\\]\nwhere\n\\[\n\\widetilde{\\boldsymbol{M}}_3\n\t=\\boldsymbol{I}-\\tilde{\\boldsymbol{\\ell}}_3\\boldsymbol{e}_3^T\n\\quad\\text{and}\\quad\n\\tilde{\\boldsymbol{\\ell}}_3=\\boldsymbol{P}_4\\boldsymbol{\\ell}_3.\n\\]\nIn the same way,\n\\[\n\\boldsymbol{P}_4\\boldsymbol{P}_3\\boldsymbol{M}_2\n=\\widetilde{\\boldsymbol{M}}_2\\boldsymbol{P}_4\\boldsymbol{P}_3\n\\quad\\text{and}\\quad\n\\boldsymbol{P}_4\\boldsymbol{P}_3\\boldsymbol{P}_2\\boldsymbol{M}_1\n=\\widetilde{\\boldsymbol{M}}_1\\boldsymbol{P}_4\\boldsymbol{P}_3\\boldsymbol{P}_2\n\\]\nwhere\n\\[\n\\widetilde{\\boldsymbol{M}}_2\n\t=\\boldsymbol{I}-\\tilde{\\boldsymbol{\\ell}}_2\\boldsymbol{e}_2^T\n\\quad\\text{and}\\quad\n\\tilde{\\boldsymbol{\\ell}}_2=\\boldsymbol{P}_4\\boldsymbol{P}_3\\boldsymbol{\\ell}_2,\n\\]\nwith\n\\[\n\\widetilde{\\boldsymbol{M}}_1\n\t=\\boldsymbol{I}-\\tilde{\\boldsymbol{\\ell}}_1\\boldsymbol{e}_1^T\n\\quad\\text{and}\\quad\n\\tilde{\\boldsymbol{\\ell}}_1\n\t=\\boldsymbol{P}_4\\boldsymbol{P}_3\\boldsymbol{P}_2\\boldsymbol{\\ell}_2.\n\\]\nThus,\n\\[\n\\boldsymbol{U}=\\boldsymbol{M}_4\\widetilde{\\boldsymbol{M}}_3\n\\widetilde{\\boldsymbol{M}}_2\\widetilde{\\boldsymbol{M}}_1\n\\boldsymbol{P}_4\\boldsymbol{P}_3\\boldsymbol{P}_2\\boldsymbol{P}_1\n\\boldsymbol{A},\n\\]\nand so\n\\[\n\\boldsymbol{P}\\boldsymbol{A}=\\boldsymbol{L}\\boldsymbol{U}\n\\quad\\text{where}\\quad\n\\boldsymbol{P}=\\boldsymbol{P}_4\\boldsymbol{P}_3\\boldsymbol{P}_2\\boldsymbol{P}_1\n\\quad\\text{and}\\quad\n\\boldsymbol{L}=\\widetilde{\\boldsymbol{M}}_1^{-1}\n\\widetilde{\\boldsymbol{M}}_2^{-1}\\widetilde{\\boldsymbol{M}}_3^{-1}\n\\boldsymbol{M}_4^{-1}.\n\\]\nWe have\n\\[\n\\bigl(\\boldsymbol{I}+\\boldsymbol{\\ell}_k\\boldsymbol{e}_k^T\\bigr)\n\\bigl(\\boldsymbol{I}-\\boldsymbol{\\ell}_k\\boldsymbol{e}_k^T\\bigr)\n=\\boldsymbol{I}\\quad\\text{because $\\boldsymbol{e}_k^T\\boldsymbol{\\ell}_k=0$,}\n\\]\nand likewise when $\\boldsymbol{\\ell}_k$ is replaced \nby~$\\tilde{\\boldsymbol{\\ell}_k}$, showing that\n\\[\n\\boldsymbol{M}_k^{-1}=\n\\boldsymbol{I}+\\boldsymbol{\\ell}_k\\boldsymbol{e}_k^T\n\\quad\\text{and}\\quad\n\\widetilde{\\boldsymbol{M}}_k^{-1}=\n\\boldsymbol{I}+\\tilde{\\boldsymbol{\\ell}}_k\\boldsymbol{e}_k^T.\n\\]\nIt follows that\n\\[\n\\boldsymbol{L}=\\boldsymbol{I}+\\tilde{\\boldsymbol{\\ell}}_1\\boldsymbol{e}_1\n+\\tilde{\\boldsymbol{\\ell}}_2\\boldsymbol{e}_2\n+\\tilde{\\boldsymbol{\\ell}}_3\\boldsymbol{e}_3\n+\\boldsymbol{\\ell}_4\\boldsymbol{e}_4,\n\\]\nwhich is a unit lower triangular matrix.\n\nIn practice, to solve the linear system \n$\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$ we simply compute\n\\[\n\\boldsymbol{y}_1=\\boldsymbol{M}_1\\boldsymbol{P}_1\\boldsymbol{b},\\qquad\n\\boldsymbol{y}_2=\\boldsymbol{M}_2\\boldsymbol{P}_2\\boldsymbol{y}_1,\\qquad\n\\boldsymbol{y}_3=\\boldsymbol{M}_3\\boldsymbol{P}_3\\boldsymbol{y}_2,\\qquad\n\\boldsymbol{y}_4=\\boldsymbol{M}_4\\boldsymbol{P}_4\\boldsymbol{y}_3,\n\\]\nand then solve the upper triangular system\n\\[\n\\boldsymbol{U}\\boldsymbol{x}=\\boldsymbol{y}_4.\n\\]\nNote that \n\\[\n(\\boldsymbol{M}_k\\boldsymbol{z})_j=\\begin{cases}\n\tz_j&\\text{if $j\\ne k+1$,}\\\\\n\tz_{k+1}-\\ell_kz_k&\\text{if $j=k+1$,}\n\\end{cases}\n\\]\nso computing each successive $\\boldsymbol{y}_k$ costs only one \nfused-multiply-and-addition, plus possibly swapping entries $k$~and $k+1$ \nof~$\\boldsymbol{y}$.  Algorithm~\\ref{alg: tridiagonal LU} sets out the \ncomputation of the $LU$-factorization, and \nAlgorithm~\\ref{alg: tridiagonal solve} sets out the procedure for then solving \n$\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$.\n\n\\begin{algorithm}\n\\caption{Solve a tridiagonal linear system \n$\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$.}\n\\label{alg: tridiagonal solve}\n\\begin{algorithmic}\n\\Require $\\boldsymbol{\\beta}$, $\\boldsymbol{\\alpha}$, $\\boldsymbol{\\gamma}$, \n$\\boldsymbol{\\delta}$, $\\boldsymbol{p}$ as provided by \nAlgorithm~\\ref{alg: tridiagonal LU}.\n\\Require $\\boldsymbol{b}=[b_1,b_2,\\ldots,b_n]$ is the right-hand side vector.\n\\Statex\n\\Function{Solve!}{$\\boldsymbol{b}, \\boldsymbol{\\beta}, \\boldsymbol{\\alpha},\n\\boldsymbol{\\gamma}, \\boldsymbol{\\delta}, \\boldsymbol{p}$}\n\\For{$j=1:n-1$}\n\t\\If{$p_j$}\n\t\t\\State $b_j\\swap b_{j+1}$\n\t\\EndIf\n\t\\State $b_{j+1}\\gets b_{j+1}-\\beta_jb_j$\n\\EndFor\n\\State $b_n\\gets b_n/\\alpha_n$\n\\State $b_{n-1}\\gets(b_{n-1}-\\gamma_{n-1}b_n)/\\alpha_{n-1}$\n\\For{$j=n-2:-1:1$}\n\t\\State $b_j\\gets(b_j-\\gamma_jb_{j+1}-\\delta_jb_{j+2})/\\alpha_j$\n\\EndFor\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}", "meta": {"hexsha": "7476ba199794804082787d42c42b6ea4a0b41c91", "size": 13682, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texsrc/appendixA.tex", "max_stars_repo_name": "billmclean/ComputationalMathsNotes", "max_stars_repo_head_hexsha": "9d521fdf7ec407cca287997885d81c3150973415", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-30T21:30:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-30T21:30:20.000Z", "max_issues_repo_path": "texsrc/appendixA.tex", "max_issues_repo_name": "billmclean/ComputationalMathsNotes", "max_issues_repo_head_hexsha": "9d521fdf7ec407cca287997885d81c3150973415", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "texsrc/appendixA.tex", "max_forks_repo_name": "billmclean/ComputationalMathsNotes", "max_forks_repo_head_hexsha": "9d521fdf7ec407cca287997885d81c3150973415", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6789587852, "max_line_length": 85, "alphanum_fraction": 0.6095600058, "num_tokens": 5651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.8807970732843033, "lm_q1q2_score": 0.8079575038528201}}
{"text": "%---------------------------Relative Size-----------------------------\n\\section{Relative Size Squared\\label{s:tet-rel-size-squared}}\n\nThis metric measures the size of a tetrahedron relative to an ensemble\ncontaining it using volume.\nTake $\\overline{V}$ to be the average volume of the tetrahedra in the ensemble being analyzed\nand define\n\\[\nR = \\frac{V}{\\overline{V}}\n\\]\nThen the quality is defined as\n\\begin{equation*}\nq =  \\left[ \\min\\left( R, \\frac {1}{R}\\right) \\right]^2.\n\\end{equation*}\n\nNote that if $\\overline{V} < DBL\\_MIN$ or if $R \\leq DBL\\_MIN$, we set $q = 0$.\n\n\\tetmetrictable{relative size squared}%\n{$1$}%                  Dimension\n{$[0.3,1]$}%            Acceptable range\n{$[0,1]$}%              Normal range\n{$[0,1]$}%              Full range\n{N/A}%                  Equilateral tet\n{\\cite{knu:03}}%        Citation\n{v\\_tet\\_relative\\_size\\_squared}%                            Verdict function name\n\n", "meta": {"hexsha": "2de41eabf8eee679aed47e1c7ec9c7f1cd7bdf46", "size": 920, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetRelativeSizeSquared.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetRelativeSizeSquared.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetRelativeSizeSquared.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 34.0740740741, "max_line_length": 93, "alphanum_fraction": 0.5782608696, "num_tokens": 267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9481545333502203, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.8077829131687059}}
{"text": "\n\\subsection{Kronecker delta}\n\nConsider matrix multiplication \\(AI\\).\n\nWe have:\n\n\\(AI_{ik}=A_{ij}I_{jk}\\)\n\nWe write this instead as:\n\n\\(AI_{ik}=A_{ij}\\delta_{jk}\\)\n\nWhere \\(\\delta_{jk}=0\\) if \\(j\\ne k\\) and \\(\\delta_{jk}=1\\) if \\(j=k\\).\n\n", "meta": {"hexsha": "ba3b5dff8f7108865cbb0de5d3a111bc499de7ad", "size": 238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/tensors/02-03-kronDelta.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/tensors/02-03-kronDelta.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/tensors/02-03-kronDelta.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.875, "max_line_length": 71, "alphanum_fraction": 0.6134453782, "num_tokens": 84, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545377452443, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.8077829115669694}}
{"text": "\n\\subsection{Definition}\n\n\nA product is a repeated multiplication of a sequence.\n\n\\(p_n=\\prod_{i=0}^ns_i\\)\n\n\\subsection{Multiplication of products}\n\nWe can take constants out of the product.\n\n\\(p_n=\\prod_{i=0}^nca_i\\)\n\n\\(p_n=a^{n}\\sum_{i=0}^na_i\\)\n\n\\subsection{Products of constants}\n\nIf \\(a_i=c\\) then the summation is then of the form:\n\n\\(p_n=\\prod_{i=0}^nc\\)\n\n\\(p_n=c^{n}\\prod_{i=j}^n1\\)\n\n\\(p_n=c^{n}\\)\n\n\\subsection{Combining products}\n\nIf a sequence is the product of to other sequences then the product of the sequence is equal to the product of the two individual sequences.\n\n\\(p_n=\\prod_{i=0}^na_i\\)\n\n\\(p_n=\\prod_{i=0}^nb_ic_i\\)\n\n\\(p_n=\\prod_{i=0}^nb_i\\prod_{i=0}^nc_i\\)\n\n", "meta": {"hexsha": "298df7fedb3263a51adf0ecd9bead85de4a2d85f", "size": 679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sequences/03-01-product.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sequences/03-01-product.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sequences/03-01-product.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.3513513514, "max_line_length": 140, "alphanum_fraction": 0.6907216495, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474220263198, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.8075767669592351}}
{"text": "\n% This LaTeX was auto-generated from an M-file by MATLAB.\n% To make changes, update the M-file and republish this document.\n\n%%% \\documentclass{article}\n%%% \\usepackage{graphicx}\n%%% \\usepackage{color}\n\n%%% \\sloppy\n%%% \\definecolor{lightgray}{gray}{0.5}\n\\setlength{\\parindent}{0pt}\n\n%%% \\begin{document}\n\n    \n    \n\\subsection*{Windowed Discrete Fourier Transform}\n\n\\begin{par}\nExample for algorithm SP-WFFT.\n\\end{par} \\vspace{1em}\n\\begin{par}\nWindowed Discrete Fourier Transform is method to calculate frequency and phase spectrum. Example shows the effect of coherent sampling, non-coherent sampling, windowing and zero padding on estimating amplitude and phase by means of FFT. Last part compares all windows in frequency space.\n\\end{par} \\vspace{1em}\n\n\\subsubsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Generate sample data\n   \\item Call algorithm\n   \\item Display results\n   \\item Compare window coefficients\n\\end{itemize}\n\n\n\\subsubsection*{Generate sample data}\n\n\\begin{par}\nConstruct 1 second of signal sampled at 50 Hz containing two harmonic components at 1 and 8 Hz and one interharmonic component at 15.5 Hz with various amplitudes and phases.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nclear DI\nDI.fs.v = 50;\nfnom = [1;   8; 15.5];\nAnom = [1; 0.5;  0.3];\npnom = [0;   1;    2];\nDI.t.v = [0 : 1/DI.fs.v : 1 - 1/DI.fs.v];\nDI.y.v = zeros(size(DI.t.v));\nfor i = 1:length(fnom)\n        DI.y.v = DI.y.v + Anom(i).*sin(2.*pi.*fnom(i).*DI.t.v + pnom(i));\nend\n%\n\\end{lstlisting}\n\n\n\\subsubsection*{Call algorithm}\n\n\\begin{par}\nCalculate amplitude and phase spectrum and store results into \\lstinline{DO}. Window function is not specified, therefore rectangle (none) window will be used.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDO = qwtb('SP-WFFT', DI);\n%\n% Set window function to blackman and calculate windowed amplitude and phase spectrum and store results into |DOw|.\nDI.window.v = 'blackman';\nDOw = qwtb('SP-WFFT', DI);\n%\n% Set zero padding to 10 times the signal length and calculate zero padded windowed amplitude and\n% phase spectrum and stre results into |DOwz|.\nDI.fft_padding.v = 10.*length(DI.y.v);\nDOwz = qwtb('SP-WFFT', DI);\n%\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\n\\end{lstlisting} \\color{black}\n    \n\n\\subsubsection*{Display results}\n\n\\begin{par}\nPlot amplitude spectrum.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nfigure; hold on;\nplot(fnom, Anom, '+r', 'markersize', 10, 'linewidth', 2);\nstem(DO.f.v, DO.A.v, '-ob', 'filled', 'markersize', 3);\nplot(DOw.f.v, DOw.A.v, '-g','linewidth',2);\nplot(DOwz.f.v, DOwz.A.v, '-k');\nlegend('nominal values','FFT', 'blackman window', 'blck. w. + zero padding')\ntitle('Amplitude spectrum')\nxlabel('frequency (Hz)'); ylabel('amplitude (V)');\nhold off\n% Plot phase spectrum\nfigure; hold on;\nplot(fnom, pnom, '+r', 'markersize', 10, 'linewidth', 2);\nstem(DO.f.v, DO.ph.v, '-ob', 'filled', 'markersize', 3);\nplot(DOw.f.v, DOw.ph.v, '-g','linewidth',2);\nplot(DOwz.f.v, DOwz.ph.v, '-k');\nlegend('nominal values','FFT', 'blackman window', 'blck. w. + zero padding', 'location', 'southwest')\ntitle('Phase spectrum');\nxlabel('frequency (Hz)'); ylabel('phase (rad)');\nhold off\n%\n\\end{lstlisting}\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{algs_examples_published/SP-WFFT_alg_example_01.pdf}\n\\end{center}\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{algs_examples_published/SP-WFFT_alg_example_02.pdf}\n\\end{center}\n\n\n\\subsubsection*{Compare window coefficients}\n\n\\begin{par}\nDifferent windows has different peak widths, heights of side lobes and side lobes roll off ratio. To see the window differences a zero padding is used. First a simple signal of ones is prepared and zero padding is specified to 100x the length of signal. Next for every window a spectrum is calculated and plotted.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nclear DI\nDI.y.v = ones(1,10);\nDI.fs.v = 1;\nDI.fft_padding.v = 100.*length(DI.y.v);\navail_windows = {'barthann' 'bartlett' 'blackman' 'blackmanharris' 'blackmannuttall' 'bohman' 'cheb' 'flattop_matlab' 'flattop_SFT3F' 'flattop_SFT4F' 'flattop_SFT5F' 'flattop_SFT3M' 'flattop_SFT4M' 'flattop_SFT5M' 'flattop_248D' 'gaussian' 'hamming' 'hanning' 'kaiser' 'nuttall' 'parzen' 'rect' 'triang' 'tukey' 'welch'};\ncol = jet(length(avail_windows));\nfigure; hold on;\nfor i = 1:length(avail_windows)\n        DI.window.v = avail_windows{i};\n        DO = qwtb('SP-WFFT', DI);\n        plot(DO.A.v, '-', 'color', col(i,:));\nend\nh=legend(avail_windows);\nh=legend('location','eastoutside');\nset(h,'FontSize',8, 'interpreter','none');\nxlabel('FFT bin * 100');\nylabel('amplitude');\nhold off;\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\nQWTB: no uncertainty calculation\n\\end{lstlisting} \\color{black}\n    \n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{algs_examples_published/SP-WFFT_alg_example_03.pdf}\n\\end{center}\n\n\n\n%%% \\end{document}\n    \n", "meta": {"hexsha": "3168deaeb894927e14112541381dc947a0a55b24", "size": 5831, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/algs_examples_published/doc_SP-WFFT.tex", "max_stars_repo_name": "qwtb/qwtb", "max_stars_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-12-09T13:18:54.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-09T13:18:54.000Z", "max_issues_repo_path": "doc/algs_examples_published/doc_SP-WFFT.tex", "max_issues_repo_name": "qwtb/qwtb", "max_issues_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2015-12-09T13:08:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-13T11:33:41.000Z", "max_forks_repo_path": "doc/algs_examples_published/doc_SP-WFFT.tex", "max_forks_repo_name": "qwtb/qwtb", "max_forks_repo_head_hexsha": "f6c79c7dca4065fd85d6f1c05257c1af34e85e34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-11-11T02:12:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-17T12:59:18.000Z", "avg_line_length": 32.0384615385, "max_line_length": 321, "alphanum_fraction": 0.730063454, "num_tokens": 1757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.9086179062123119, "lm_q1q2_score": 0.8075421594252988}}
{"text": "\n\\subsection{Hard-margin SVC}\n\n\\subsubsection{Linear separators}\n\nWe want to create a hyperplane to separate classes.\n\nFor classification problem (x, y)\n\nHyperplane is wx-b=0\n\n\\subsubsection{Hard margin}\n\nIf data is linearly separable then a hyperplane exists such that all data can be correctly classified\n\nThere are an infinit number that could work.\n\nWe select two parallel with distance between as large as possible. the region between these two is the margin\n\nThe maximum margin hyperplane is the one between the two margin planes\n\nWe can rescale the two hyperplanes to:\n\nwx-b=1\n\nwx-b=-1\n\nThe distance between the two parrallel hyperplanes is \\(\\dfrac{2}{||w||}\\)\n\nSo we minimise \\(||w||\\) conditional an all points being correctly classified\n\n\\(y_i(wx_i-b)\\ge 1\\)\n\nWe select w and b to solve this.\n\n\n\n", "meta": {"hexsha": "283597870fa6cdfcec5e34375c70d87b1301ba52", "size": 807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/SVM/01-01-hardMargin.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/SVM/01-01-hardMargin.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/SVM/01-01-hardMargin.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.2368421053, "max_line_length": 109, "alphanum_fraction": 0.7620817844, "num_tokens": 194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107861416414, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.807442907549772}}
{"text": "\\section{Regression}\n\nSolve $w^* = \\arg\\min\\limits_w \\hat{R}(w)+ \\lambda C(w)$, \\highlight*{$y=w^\\top x$}\n\n\\textbf{residual:} \\highlight*{$r_i = y_i - w^\\top x_i$}, \\enskip\n\\textbf{cost:} $\\hat R(w)$\n\n\\emph{Linear Regression}\n\n%$\\hat{R}(w) = \\sum_{i=1}^n (y_i - w^\\top x_i)^2 = ||Xw-y||^2_2$\n$\\hat{R}(w) = \\sum_{i=1}^n r_i^2 = \\norm{Xw-y}^2_2$\n\n$\\nabla\\!_w \\hat{R}(w) = -2 \\sum_{i=1}^n r_i \\cdot x_i$\n\n\\textbf{closed form:} $w^* = (X^\\top X)^{-1} X^\\top y$\n\n\n\\emph{Ridge regression}\n\n%$\\hat{R}(w) = \\sum_{i=1}^n (y_i - w^\\top x_i)^2 + \\lambda ||w||_2^2$\n$\\hat{R}(w) = \\sum_{i=1}^n r_i^2 + \\lambda \\norm{w}_2^2$\n\n$\\nabla\\!_w \\hat{R}(w) = -2 \\sum_{i=1}^n r_i \\cdot x_i + 2 \\lambda w$\n\n\\textbf{closed form:} $w^*=(X^\\top X + \\lambda I)^{-1} X^\\top y$\n\n\\emph{L1-regularized regression (Lasso)}\\\\\n$\\hat{R}(w) = \\sum_{i=1}^n r_i^2 + \\lambda \\norm{w}_1$", "meta": {"hexsha": "f56240f2dabae29440293771db554b6eea76aaef", "size": 846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/IML19/sections/Regression.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/IML19/sections/Regression.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/IML19/sections/Regression.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.2142857143, "max_line_length": 83, "alphanum_fraction": 0.5567375887, "num_tokens": 426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104914476339, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.8074200636060567}}
{"text": "\\subsection{The Cauchy-Schwarz and triangle inequalities}\n\nThe \\textbf{Cauchy-Schwarz inequality}%\n\\index{Cauchy-Schwarz inequality!for dot product} is a fundamental\ninequality satisfied by the dot product.  It is given in the following\nproposition.\n\n\\begin{proposition}{Cauchy-Schwarz inequality}{cauchy-schwarz-inequality}\n  The dot product satisfies the inequality\n  \\begin{equation}\\label{cauchy}\n    \\abs{\\vect{u}\\dotprod \\vect{v}}\\leq \\norm{\\vect{u}} \\norm{\\vect{v}}\n  \\end{equation}\n  Furthermore equality is obtained if and only if one of $\\vect{u}$ or $\\vect{v}$ is a scalar multiple of the other.\n\\end{proposition}\n\n\\begin{proof}\n  First note that if $\\vect{u}=\\vect{0}$, then both sides of\n  \\eqref{cauchy} are equal to zero, and so the inequality holds in\n  this case. Therefore, we will assume in what follows that\n  $\\vect{u}\\neq \\vect{0}$.  Define a function of $t\\in \\R$ by\n  \\begin{equation*}\n    f(t) =(t\\vect{u}+\\vect{v}) \\dotprod (t\\vect{u}+\\vect{v}).\n  \\end{equation*}\n  Then by Proposition~\\ref{prop:properties-dot-product}, $f(t) \\geq 0$\n  for all $t\\in \\R$.  Also from\n  Proposition~\\ref{prop:properties-dot-product}, we have\n  \\begin{eqnarray*}\n    f(t)\n    &=& t\\vect{u}\\dotprod (t\\vect{u}+\\vect{v})\n        + \\vect{v}\\dotprod (t\\vect{u}+\\vect{v}) \\\\\n    &=& t^2\\vect{u}\\dotprod \\vect{u}+t(\\vect{u}\\dotprod \\vect{v})\n        + t \\vect{v}\\dotprod \\vect{u}\n        + \\vect{v}\\dotprod \\vect{v} \\\\\n    &=& t^2\\norm{\\vect{u}}^2\n        + 2t(\\vect{u}\\dotprod \\vect{v})\n        + \\norm{\\vect{v}}^2.\n  \\end{eqnarray*}\n  This means the graph of $y=f(t)$ is a parabola which opens upwards\n  and is never negative. It follows that this function has at most one\n  root. From the quadratic formula, we know that a quadratic function\n  $at^2+bt+c$ has one or zero roots if and only if $b^2-4ac\\leq\n  0$. Applying this reasoning to the function $f(t)$, we obtain\n  \\begin{equation*}\n    (2(\\vect{u}\\dotprod\\vect{v}))^2-4\\norm{\\vect{u}}^2\\norm{\\vect{v}}^2\n    \\leq 0,\n  \\end{equation*}\n  which is equivalent to\n  $\\abs{\\vect{u}\\dotprod \\vect{v}} \\leq \\norm{\\vect{u}} \\norm{\\vect{v}}$.\n\\end{proof}\n\nAn important consequence of the Cauchy-Schwarz inequality is the\nso-called \\textbf{triangle inequality}%\n\\index{triangle inequality!in Rn@in $\\R^n$}, which states that the length\nof one side of a triangle is less than or equal the sum of the lengths\nof the two other sides.\n\n\\begin{proposition}{Triangle inequality}{triangle-inequality-dot-product}\n  For\\/ $\\vect{u},\\vect{v}\\in \\R^n$, we have\n  \\begin{equation}\\label{triangle-ineq-1}\n    \\norm{\\vect{u} + \\vect{v}} \\leq \\norm{\\vect{u}} + \\norm{\\vect{v}}.\n  \\end{equation}\n\n  \\begin{center}\n    \\begin{tikzpicture}[scale=1.5]\n      \\draw[->, thick, purple](0,0) -- node[above left]{$\\vect{u}+\\vect{v}$}(1.5,1);\n      \\draw[->, thick, blue](0,0) -- node[below]{$\\vect{u}$} (0.75,0);\n      \\draw[->, thick, red](0.75,0) -- node[below right]{$\\vect{v}$} (1.5,1);\n    \\end{tikzpicture}\n  \\end{center}\n\\end{proposition}\n\n\\begin{proof}\n  By properties of the dot product and the Cauchy-Schwarz inequality,\n  we have\n  \\begin{eqnarray*}\n    \\norm{\\vect{u}+\\vect{v}}^2\n    &=& (\\vect{u}+\\vect{v})\\dotprod(\\vect{u}+\\vect{v}) \\\\\n    &=& (\\vect{u}\\dotprod\\vect{u})+(\\vect{u}\\dotprod\\vect{v})+(\\vect{v}\\dotprod\\vect{u})+(\\vect{v}\\dotprod\\vect{v}) \\\\\n    &=& \\norm{\\vect{u}}^2+2(\\vect{u}\\dotprod\\vect{v})+\\norm{\\vect{v}}^2 \\\\\n    &\\leq& \\norm{\\vect{u}}^2+2\\abs{\\vect{u}\\dotprod\\vect{v}}+\\norm{\\vect{v}}^2 \\\\\n    &\\leq& \\norm{\\vect{u}}^2+2\\norm{\\vect{u}}\\norm{\\vect{v}}+\\norm{\\vect{v}}^2 \\\\\n    &=& (\\norm{\\vect{u}}+\\norm{\\vect{v}})^2.\n  \\end{eqnarray*}\n  Therefore,\n  \\begin{equation*}\n    \\norm{\\vect{u}+\\vect{v}}^2\\leq(\\norm{\\vect{u}}+\\norm{\\vect{v}})^2.\n  \\end{equation*}\n  Taking square roots of both sides, we obtain \\eqref{triangle-ineq-1}.\n\\end{proof}\n\n\\begin{example}{Triangle inequality}{triangle-inequality}\n  Use the triangle inequality to show\n  \\begin{equation*}\n    \\norm{\\vect{u}} -\\norm{\\vect{v}} \\leq \\norm{\\vect{u}-\\vect{v}}\n  \\end{equation*}\n  holds for all vectors $\\vect{u},\\vect{v}\\in\\R^n$.\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{equation*}\n    \\norm{\\vect{u}}\n    = \\norm{(\\vect{u}-\\vect{v})+\\vect{v}} \\\\\n    \\leq \\norm{\\vect{u}-\\vect{v}}+\\norm{\\vect{v}},\n  \\end{equation*}\n  where we have used the triangle inequality in the last step. Note\n  that this is an inequality between real numbers. Bringing\n  $\\norm{\\vect{v}}$ to the other side of the equation, we have\n  \\begin{equation*}\n    \\norm{\\vect{u}} - \\norm{\\vect{v}} \\leq \\norm{\\vect{u}-\\vect{v}}.\n  \\end{equation*}\n\\end{solution}\n", "meta": {"hexsha": "fdc67fe8a5b209ef2e2f1e4f6d1b4c4b92c1b3f1", "size": 4568, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-DotProduct-CauchySchwarz.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Vectors-DotProduct-CauchySchwarz.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Vectors-DotProduct-CauchySchwarz.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 40.4247787611, "max_line_length": 118, "alphanum_fraction": 0.640323993, "num_tokens": 1693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.9219218396818158, "lm_q1q2_score": 0.8074071604872559}}
{"text": "\\section{Left \\& Right Hand Limits}\r\nOur definition of the limit requires that the function get arbitrarily close to the limit value when approaching from both the left and right hand sides.\r\nHowever, we can evaluate limits by specifying that we only approach from one side.\r\nWe usually notate this with a superscript $+$ or $-$ next to the $x$ limit value.\r\nSo,\r\n\\begin{equation*}\r\n\t\\lim_{x \\to 0^+}{f(x)}\r\n\\end{equation*}\r\nwould mean ``the limit of $f(x)$ as $x$ approaches $0$ from the right'', while\r\n\\begin{equation*}\r\n\t\\lim_{x \\to 0^-}{f(x)}\r\n\\end{equation*}\r\nwould mean ``the limit of $f(x)$ as $x$ approaches $0$ from the left.''\r\n\r\nOur definition of the limit from both sides requires the left and right sides to be the same.\r\nIf they are different, the the limit does not exist.\r\n\\begin{align*}\r\n\t\\lim_{x \\to c^+}{f(x)} = \\lim_{x \\to c^-}{f(x)} &\\implies \\lim_{x \\to c^+}{f(x)} = \\lim_{x \\to c^-}{f(x)} = \\lim_{x \\to c}{f(x)} \\\\\r\n\t\\lim_{x \\to c^+}{f(x)} \\neq \\lim_{x \\to c^-}{f(x)} &\\implies \\lim_{x \\to c}{f(x)} \\text{ does not exist (DNE)}.\r\n\\end{align*}", "meta": {"hexsha": "0151270b1103e18f42db049f85a0d8f3178783ea", "size": 1066, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/limits_continuity/left_right_hand_limits.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/limits_continuity/left_right_hand_limits.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/limits_continuity/left_right_hand_limits.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 53.3, "max_line_length": 154, "alphanum_fraction": 0.6519699812, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218262741297, "lm_q2_score": 0.8757869867849166, "lm_q1q2_score": 0.8074071382838673}}
{"text": "\n\\subsection{Dimension function}\n\nFor a basis \\(S\\), the the dimension of the vector space is \\(|S|\\).\n\n\\(\\dim (V)=|S|\\)\n\n\\(S\\subset V\\)\n\n\\subsubsection{Finite and infinite vector spaces}\n\nIf \\(\\dim (V) \\) is finite, then we say the vector space is finite.\n\nOtherwise, we say the vector space is infinite.\n\n", "meta": {"hexsha": "25a2513b66368d8ee68effa0399118f752f42043", "size": 307, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/linearAlgebra/01-05-dimension.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/linearAlgebra/01-05-dimension.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/linearAlgebra/01-05-dimension.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.1875, "max_line_length": 68, "alphanum_fraction": 0.680781759, "num_tokens": 85, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475730993027, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.8073651024258188}}
{"text": "\\documentclass{amsart}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\title{PDE: Assignment 1}\n\\author{Mark Ditsworth}\n\n\\begin{document}\n\t\\maketitle\n\t\n\t\\section{Problem 1}\n\tIf $B$ is a positive-definite, Hermitian matrix, show that there is a unique matrix $\\sqrt{B}$ that is Hermitian positive-definite and $\\left( \\sqrt{B} \\right) ^2 = B$.\n\t\\\\\\\\\n\tLet $M$ be the matrix of eigenvectors of $B$. Since $B$ is Hermitian and positive definite, $M$ and it's inverse is Hermitian and positive-definite. Then $B' = M^{-1}BM$, and $B'$ is a diagonal matrix of the eigenvalues of $B$.\n\t\\\\\\\\\n\t$M\\sqrt{B'}M^{-1} = \\sqrt{B}$, which is Hermitian and positive-definite.\n\t\\\\\\\\\n\tEven $M$ is not unique (any $\\alpha M$ is a matrix of eigenvectors of $B$), $B'$ is unique since $(\\alpha M)^{-1}B\\alpha M = \\frac{1}{\\alpha}\\alpha M^{-1}BM$. Therefore, $\\sqrt{B}$ is unique.\n\t\\\\\\\\\n\t\\section{Problem 2}\n\t$A$ and $B$ are Hermitian and $B$ is positive definite.\n\t\\subsection{Part 1}\n\tShow that $B^{-1}A$ is similar to a Hermitian.\n\t\\\\\\\\\n\t$C$ is similar to $B^{-1}A \\Rightarrow C=MB^{-1}AM^{-1}$ for any invertible $M$. From Problem 1, $\\sqrt{B}$ is invertible so let $M=\\sqrt{B}$.\n\t\\\\\\\\\n\t$C = \\sqrt{B}B^{-1}A\\sqrt{B}^{-1}=B^{-1/2}AB^{-1/2}$, which is Hermitian since $A$ and $\\sqrt{B}$ are Hermitian. Therefore, $B^{-1}A$ is similar to a Hermitian.\n\t\\subsection{Part 2}\n\tWhat does this say about the eigenvalues of $B^{-1}A$?\n\t\\\\\\\\\n\tThe eigenvalues are real.\n\t\\subsection{Part 3}\n\tAre the eigenvectors orthogonal?\n\t\\\\\\\\\n\tNo. The eigenvectors of $C$ are orthagonal, but $B^{-1}A$ is not Hermitian. It is \\textit{similar} to a Hermitian matrix. So it will not necessarily have orthagonal eigenvectors.\n\t\n\t\\subsection{Part 4}\n\tVerify the answers above in Julia with $5\\times 5$ matrices.\n\t\\\\\\\\\n\t\\textit{see notebook.}\n\t\\\\\\\\\n\t\\subsection{Part 5}\n\tWhat is special about $C=M^{T}BM$? Show that the elements of $C$ are a kind of dot product of the eigenvectors with a factor of B in the middle.\n\t\\\\\\\\\n\t\\textit{see notebook.}\n\t\n\t\\section{Problem 3}\n\tThe solutions of ODE $y'' - 2y' - cy = 0$ take the form $y(t) = C_1 e^{(1+\\sqrt{1+c})t} + C_2 e^{(1-\\sqrt{1+c})t}$ for some constants $C_1$ and $C_2$ determined by the initial conditions. Suppose that $A$ is a real-symmetric $4 \\times 4$ matrix with eigenvalues 3, 8, 15, and 24, which correspond to eigenvectors $\\mathbf{x_1}$, $\\mathbf{x_2}$, $\\mathbf{x_3}$, $\\mathbf{x_4}$.\n\t\\subsection{Part 1}\n\tIf $\\mathbf{x}(t)$ solves the system of ODEs $\\frac{d^2}{dx^2}\\mathbf{x} - 2\\frac{d}{dx}\\mathbf{x} = A\\mathbf{x}$, with initial conditions $\\mathbf{x}(0) = \\mathbf{a}_0$ and $\\mathbf{x}'(0) = \\mathbf{b}_0$, find the closed-form expression of $\\mathbf{x}(t)$ in terms of the eigenvectors and initial conditions.\n\t\\\\\\\\\n\tSince A is Hermitian and positive-definite, the eigenvectors are orthogonal. Thus, the solution can be expressed as linear combination of the eigenvectors.\n\t\\[\\mathbf{x}(t) = \\sum_{n=1}^{4} c_n(t) \\mathbf{x}_n \\]\n\t\n\t\\[\\frac{d^2}{dx^2}\\mathbf{x}(t) - 2\\frac{d}{dx}\\mathbf{x}(t) - A\\mathbf{x}(t) = \n\t\\sum_{n=1}^{4}\\left( \\ddot{c_n} - 2\\dot{c_n}- \\lambda_n \\right) \\mathbf{x}_n = 0\\]\n\t\n\tSince $\\mathbf{x}_n$ are linearly independent, $\\ddot{c_n} - 2\\dot{c_n}- \\lambda_n = 0$ for all $n$.\n\t\n\t\\[ c_n(t) = \\alpha_n e^{(1+\\sqrt{1+\\lambda_n})t} + \n\t            \\beta_n e^{(1-\\sqrt{1+\\lambda_n})t} \\]\n\t\n\t\\[ \\mathbf{x}(0) = \\sum_{n=1}^{4} (\\alpha_n + \\beta_n)\\mathbf{x}_n = \\mathbf{a}_0\\]\n\t\n\t\\[ \\alpha_n + \\beta_n = \\frac{\\mathbf{x}_x^* \\mathbf{a}_0}{||\\mathbf{x}_n||^2}\\]\n\t\n\t\\[ \\mathbf{x}'(0) = \\sum_{n=1}^{4} \\left( \\alpha_n(1+\\sqrt{1+\\lambda_n}) + \\beta_n(1-\\sqrt{1+\\lambda_n}) \\right)\\mathbf{x}_n = \\mathbf{b}_0 \\]\n\t\n\t\\[ \\mathbf{x}'(0) = \\sum_{n=1}^{4}\\left( \\alpha_n + \\beta_n + \\sqrt{1+\\lambda_n}(\\alpha_n - \\beta_n) \\right) \\mathbf{x}_n = \\mathbf{b}_0 \\]\n\t\n\t\\[ \\frac{\\mathbf{x}_n^* \\mathbf{a}_0}{||\\mathbf{x}_n||^2} + \\sqrt{1+\\lambda_n}(\\alpha_n - \\beta_n) = \\frac{\\mathbf{x}_n^* \\mathbf{b}_0}{||\\mathbf{x}_n||^2} \\]\n\t\n\t\\[ \\alpha_n - \\beta_n = \\frac{\\mathbf{x}_n^* (\\mathbf{b}_0 - \\mathbf{a}_0)}{||\\mathbf{x}_n||^2 \\sqrt{1+\\lambda_n}}\\]\n\t\n\t\\[ \\mathbf{x}(t) = \\sum_{n=1}^{4} \\left( \\left(\\mathbf{x}_n^*\\mathbf{a}_0 + \\frac{\\mathbf{x}_n^*(\\mathbf{b}_0 - \\mathbf{a}_0)}{\\sqrt{1+\\lambda_n}} \\right)e^{(1+\\sqrt{1+\\lambda_n})t} +\n\t\\left(\\mathbf{x}_n^*\\mathbf{a}_0 - \\frac{\\mathbf{x}_n^*(\\mathbf{b}_0 - \\mathbf{a}_0)}{\\sqrt{1+\\lambda_n}} \\right)e^{(1-\\sqrt{1+\\lambda_n})t}\n\t\\right) \\frac{\\mathbf{x}_n}{2||\\mathbf{x}_n||^2} \\]\n\t\n\t\\subsection{Part 2}\n\tAfter a long time ($t >> 0$), what is the expected approximation of the solution?\n\t\\\\\\\\\n\t$\\mathbf{x}(t)$ will be dominated by the fastest growing term in the mode with the largest eigenvalue ($\\lambda_4 = 24$).\n\t\n\t\\[ \\mathbf{x}(t>>0) \\cong \\left( \\mathbf{x}_4^* \\mathbf{a}_0 + \\frac{\\mathbf{x}_4^* (\\mathbf{b}_0 - \\mathbf{a}_0)}{\\sqrt{1+\\lambda_4}}\\right) e^{(1+\\sqrt{1+\\lambda_4})t} \\frac{\\mathbf{x}_4}{2||\\mathbf{x}_4||^2} \\]\n\t\n\t\\[ \\mathbf{x}(t>>0) \\cong \\left( \\mathbf{x}_4^* \\mathbf{a}_0 + \\frac{\\mathbf{x}_4^* (\\mathbf{b}_0 - \\mathbf{a}_0)}{5}\\right) e^{6t} \\frac{\\mathbf{x}_4}{2||\\mathbf{x}_4||^2} \\]\n\t\\\\\\\\\n\t\\section{Problem 4}\n\tConsider the 1d Poisson equation $\\frac{d^2}{dx^2}u(x) = f(x)$ for the vector space of functions $u(x)$ on $x \\in [0,L]$ with the Dirichlet boundary conditions $u(0) = u(L) = 0$.\n\t\n\t\\subsection{Part 1}\n\tSuppose the boundary conditions are changed to \\textit{periodic} boundary condition $u(0) = u(L)$. What are the eigenfunctions of $\\frac{d^2}{dx^2}$ now? Will Poisson's equations have unique solutions? Under what conditions on $f(x)$ would a solution exist?\n\t\\\\\\\\\n\tSince the boundary is periodic, the eigenfunctions will be $\\sin(kx)$, and $\\cos(kx)$, where $k=\\frac{2\\pi n}{L}$ with $n = 1,2,\\dots$ for sine and $n=0,1,2,\\dots$ for cosine. 0 is ignored for sine because we do not allow the zero function as an eigenfunction, and negative $n$'s since they are linearly dependent on sine and cosine.\n\t\\\\\\\\\n\t\\noindent\n\t$\\sin(\\phi + kx) = \\cos(\\phi)\\sin(kx) + \\sin(\\phi)\\cos(kx)$, and is therefore linearly dependent on sine and cosine. And exponential functions are only periodic for $e^{ikx} = \\cos(kx)+i\\sin(kx)$, which is linearly dependent on sine and cosine.\n\t\\\\\\\\\n\t\\noindent\n\tThe equation will not have unique solutions since the vector space is spanned by $u(x) = \\alpha1 \\forall \\alpha$ Thus, it can have infinite solutions.\n\t\\\\\\\\\n\t\\noindent\n\tTo solve $\\frac{d^2}{dx^2}u(x) = f(x)$, we would divide each term in the Fourier series by it's eigenvalue $(\\frac{2\\pi n}{L})^2$, which is only defined for $n>0$. This implies the $c_0 = 0$, or equivalently $\\int_{0}^{L} f(x) = 0$. Under this condition, the equation is solvable.\n\t\\subsection{Part 2}\n\tIf instead we considered $\\frac{d^2}{dx^2}v(x) = g(x)$ with the boundary condition $v(0) = v(L)+1$, do these functions form a vector space?\n\t\\\\\\\\\n\tA vector space must include the zero function, but if $v(x)=0$, then $v(0) \\neq v(L)+1$. Thus, the functions do not form a vector space.\n\t\\subsection{Part 3}\n\tHow can we transform $v(x)$ from Part 2 back into the original $\\frac{d^2}{dx^2}u(x) = f(x)$ problem with $u(x) = u(L)$ by writing $u(x)=v(x)+q(x)$ and $f(x)=g(x)+r(x)$ for some function $q$ and $r$?\n\t\\\\\\\\\n\t\\noindent\n\tLet $q$ be a twice differential function with $q(L)-q(1)=-1$. Then $u(L) - u(0) = (v(L)-v(0))+(q(L)-q(0)) = -1 + 1 = 0$ and $u$ is periodic. Then plug $v = u-q$ back into $\\frac{d^2}{dx^2}v(x) = g(x)$:\n\t\n\t\\[\\frac{d^2}{dx^2}(u-q) = g(x)\\]\n\t\n\t\\[ \\frac{d^2}{dx^2}u(x) = g(x) + \\frac{d^2}{dx^2}q \\]\n\t\n\tTake $\\frac{d^2}{dx^2}q$ as $r$ and\n\t\n\t\\[ \\frac{d^2}{dx^2}u(x) = g(x) + r(x) = f(x)\\]\n\t\\\\\\\\\n\t\\section{Problem 5}\n\tConsider a finite difference approximation as shown below.\n\t\n\t\\[ u'(x) \\approx \\frac{-u(x+2\\Delta x) + c\\cdot u(x+\\Delta x) - c\\cdot u(x - \\Delta x) + u(x - 2\\Delta x)}{d\\Delta x} \\]\n\t\n\t\\subsection{Part 1}\n\tSubstitute the Taylor Series for $u(x+\\Delta x)$ to show that an appropriate choice of $c$ and $d$ will make this approximation 4$^{th}$ order accurate (errors are proportional to $(\\Delta x)^2$).\n\t\\\\\\\\\n\t\\[ u(x + \\Delta x) = \\sum_{n=0}^{\\infty}\\frac{u^{(n)}(x)(\\Delta x)^n}{n!}\\]\n\t\n\tDenote $\\hat{u}'(x)$ as the finite difference approximation of $u'(x)$.\n\t\n\t\\[ \\hat{u}'(x) = \\frac{ -\\sum_{n=0}^{\\infty}\\frac{u^{(n)}(x)(2\\Delta x)^n}{n!}+\n\tc\\sum_{n=0}^{\\infty}\\frac{u^{(n)}(x)(\\Delta x)^n}{n!}-\n\tc\\sum_{n=0}^{\\infty}\\frac{u^{(n)}(x)(-\\Delta x)^n}{n!}+\n\t-\\sum_{n=0}^{\\infty}\\frac{u^{(n)}(x)(-2\\Delta x)^n}{n!}  }{d\\Delta x}\\]\n\t\n\t\\[ \\hat{u}'(x) = \\frac{\n\t-2\\sum_{n=0}^{\\infty}\\frac{u^{(2n+1)}(x)(2\\Delta x)^{(2n+1)}}{(2n+1)!}+\n\t2c\\sum_{n=0}^{\\infty}\\frac{u^{(2n+1)}(x)(\\Delta x)^{(2n+1)}}{(2n+1)!}\n    }{d\\Delta x}\\]\n    \n    \\[ \\hat{u}'(x) = \\frac{\n    \t2\\sum_{n=0}^{\\infty}\\frac{u^{(2n+1)}(x)(\\Delta x)^{(2n+1)}}{(2n+1)!}\\left( c - 2^{(2n+1)} \\right)\n    }{d\\Delta x}\\]\n\n    \\[ \\hat{u}'(x) = \\frac{2}{d} \\sum_{n=0}^{\\infty} \\frac{u^{(2n+1)}(x)(\\Delta x)^{2n}}{(2n+1)!}\\left( c - 2^{2n+1} \\right) \n    \\]\n    \n    \\[ \\frac{d}{2}\\hat{u}'(x) = u'(x)(c-2) + \\frac{1}{3!}u^{(3)}(x)(\\Delta x)^2(c-8) + \\frac{1}{5!}u^{(5)}(x)(\\Delta x)^4(c-32) + \\dots\n    \\]\n    \n    \\[ \\frac{d}{2}\\hat{u}'(x) - u'(x)(c-2) = \\frac{1}{3!}u^{(3)}(x)(\\Delta x)^2(c-8) + \\frac{1}{5!}u^{(5)}(x)(\\Delta x)^4(c-32) + \\dots\n    \\]\n    \\\\\\\\\n    Let $c=8$ and $d=12$.\n    \n    \\[ 6\\hat{u}'(x) - 6u'(x) = \\frac{1}{5!}u^{(5)}(x)(\\Delta x)^4(-24) + \\dots\n    \\]\n    \n    \\[ \\hat{u}'(x) - u'(x) = \\frac{-u^{(5)}(x)}{30} (\\Delta x)^4\\]\n    \n    \\[\\therefore \\hat{u}'(x) - u'(x) \\propto (\\Delta x)^4 \\]\n    \n    \\subsection{Part 2}\n    Check Part 1 by numerically computing $u'(1)$ for $u(x) = \\sin(x)$, as a function of $\\Delta x$. Verify the approximation is 4$^th$ order accurate using a loglog plot.\n    \\\\\\\\\n    \\textit{see notebook.}\n\t\n\\end{document}", "meta": {"hexsha": "104144f3afd58c368eea754cdb651f3303e2ee59", "size": 9724, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/A1/assn1.tex", "max_stars_repo_name": "markditsworth/linearPDE", "max_stars_repo_head_hexsha": "8f2717d5f55341fa6218836d5e4cab58db03f371", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Assignments/A1/assn1.tex", "max_issues_repo_name": "markditsworth/linearPDE", "max_issues_repo_head_hexsha": "8f2717d5f55341fa6218836d5e4cab58db03f371", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Assignments/A1/assn1.tex", "max_forks_repo_name": "markditsworth/linearPDE", "max_forks_repo_head_hexsha": "8f2717d5f55341fa6218836d5e4cab58db03f371", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.5348837209, "max_line_length": 377, "alphanum_fraction": 0.6039695599, "num_tokens": 3983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742805, "lm_q2_score": 0.8824278726384089, "lm_q1q2_score": 0.8073341115793823}}
{"text": "\\section{First Order Logic}\n\n\\subsection{First Order Languages: Syntax}\n\n\\begin{itemize}\n\t\n\t\\item A \\textit{first-order language} (FOL) consists of the following symbols:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item \\textit{Logical symbols} $ \\land, \\lor, \\lnot, \\implies, \\iff, =, \\forall, \\exists $ (common to all FOLs)\n\t\t\n\t\t\\item An infinite set of variables, $ x, y, z, \\dots $ (also common to all FOLs)\n\t\t\n\t\t\\item Punctuation symbols: parentheses $ ( \\text{ and } ) $ and the comma `$ , $' (also common to all FOLs)\n\t\t\n\t\t\\item A (possibly empty) set of constant symbols (e.g. $ 0, 1 $)\n\t\t\n\t\t\\item A (possibly empty) set of function symbols (e.g. $ +, \\times, - $)\n\t\t\n\t\t\\item A (possibly empty) set of predicate symbols (e.g. $ < $)\n\t\t\t\t\n\t\\end{itemize}\n\n\t\\item Each function and predicate symbol has an associated arity $ n $\n\t\n\t\\item Only the \\textit{non-logical symbols} are specific to the particular language\n\t\n\t\\item A FOL may be specified by giving only the constant, relation and function symbols\n\t\n\t\\begin{itemize}\n\t\t\\item E.g. the first-order language of arithmetic $ \\Lang_A $ consists of the following:\n\t\t\n\t\t\\begin{itemize}\n\t\t\t\\item The constant symbol $ 0 $\n\t\t\t\\item Unary function symbol $ S $ (the successor function)\n\t\t\t\\item Two binary function symbols $ + $ and $ \\cdot $\n\t\t\\end{itemize}\n\t\\end{itemize}\n\t\n\t\\item Given an FOL $ \\Lang $, an \\textit{expression} of $ \\Lang $ is a finite sequence of symbols; not all expressions are \\textit{formulae}\n\t\n\t\\item A \\textit{term} of an FOL is defined inductively:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item Every constant symbol in $ \\Lang $ is a term\n\t\t\n\t\t\\item Every variable symbol in $ \\Lang $ is a term\n\t\t\n\t\t\\item If $ t_1, \\dots, t_n $ are terms and $ f $ is an $ n $-ary function symbol in $ \\Lang $, then $ f(t_1, \\dots t_n) $ is a term in $ \\Lang $\n\t\t\n\t\\end{itemize}\n\n\t\\item An \\textit{atomic formula} of an FOL is defined as follows:\n\t\n\t\\begin{itemize}\n\t\t\\item If $ t_1 $ and $ t_2 $ are terms, then $ t_1 = t_2 $ is an atomic formula\n\t\t\n\t\t\\item If $ F $ is an $ n $-ary predicate and $ t_1, \\dots, t_n $ are terms, then $ F(t_1, \\dots, t_n) $ is an atomic formula\n\t\\end{itemize}\n\n\t\\item A \\textit{formula} of an FOL is defined inductively:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item An atomic formula is a formula\n\t\t\n\t\t\\item If $ \\phi $ and $ \\psi $ are both formulae, then so are $ \\lnot \\phi $, $ \\phi \\land \\psi $, $ \\phi \\lor \\psi $, $ \\phi \\implies \\psi $, and $ \\phi \\iff \\psi $\n\t\t\n\t\t\\item If $ \\phi $ is a formula and $ x $ is a variable symbol, then $ \\exists x \\phi $ and $ \\forall x \\phi $ are formulae\n\t\t\n\t\t\\item Parentheses should be used as necessary to ensure there is exactly one way of reading a formula\n\t\t\n\t\\end{itemize}\n\n\t\\item A variable is \\textit{bound} by a quantifier $ \\forall x $ or $ \\exists x $ in a formula $ \\phi $ if:\n\t\n\t\\begin{itemize}\n\t\t\\item $ x $ is in the scope of the quantifier; and\n\t\t\n\t\t\\item the scope of the quantifier contains no other quantifiers over $ x $ with $ x $ in their scope\n\t\\end{itemize}\n\n\t\\item Any variable which is not bound in a formula $ \\phi $ is \\textit{free} in $ \\phi $\n\t\n\t\\item A \\textit{sentence} of an FOL is a formula with no free variables\n\t\n\t\\item Importantly, an FOL gives no \\textit{meaning} to formulae -- they are not `true' or `false'\n\t\t\n\\end{itemize}\n\n\\subsection{Models: Semantics}\n\n\\begin{itemize}\n\t\n\t\\item For an FOL $ \\Lang $, an \\textit{$ \\Lang $-structure} or \\textit{model} $ \\Model $ consists of the following:\n\t\n\t\\begin{itemize}\n\t\t\\item A domain or universe: a non-empty set $ \\abs{\\Model} $\n\t\t\n\t\t\\item Interpretation for constant symbols: for each constant symbol $ c $ of $ \\Lang $, an element $ c^\\Model \\in \\abs{\\Model} $\n\t\t\n\t\t\\item Interpretation for predicate symbols: for each $ n $-ary predicate symbol $ R $ of $ \\Lang $, an $ n $-ary predicate $ R^\\Model \\subseteq \\abs{\\Model}^n $\n\t\t\n\t\t\\item Interpretation for function symbols: for each $ n $-ary function symbol $ f $ of $ \\Lang $, an $ n $-ary function $ f^\\Model: \\abs{\\Model}^n \\to \\abs{\\Model} $\n\t\\end{itemize}\n\n\t\\item A sentence of $ \\Lang $ acquires \\textit{meaning} when an $ \\Lang $-structure $ \\Model $ is given and the sentence is interpreted within $ \\Model $\n\t\n\t\\item We can determine the truth value of a formula $ \\phi $ (possibly with free variables) in $ \\Lang $-structure $ \\Model $ if a \\textit{variable assignment} $ \\alpha: \\text{ set of variable symbols} \\to \\abs{\\Model} $ is given\n\t\n\t\\item For given $ \\alpha $, replace all free variables $ x_i $ in $ \\phi $ by $ \\alpha(x_i) $, so $ \\phi $ becomes a statement in $ \\Model $ which must either be true or false\n\t\n\t\\item We say a formula $ \\phi $ is \\textit{true in $ \\Model $} if $ \\phi $ is true for \\textbf{any} variable assignment $ \\alpha $\n\t\n\t\\item For a sentence $ \\phi $ in $ \\Lang $, its truth values does not depend on variable assignment (since there is no free variable). Thus $ \\phi $ must be either true or false in $ \\Model $, independent of variable assignment\n\t\n\\end{itemize}\n\n\\newpage\n\n\\subsection{Axiomatic Systems \\& Proof}\n\n\\begin{itemize}\n\t\n\t\\item A formal axiomatic system comprises:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item A first-order language\n\t\t\n\t\t\\item Syntactic rules for constructing formulae from the symbols\n\t\t\n\t\t\\item A collection of axioms\n\t\t\n\t\t\\item Rules of inference\n\t\t\n\t\\end{itemize}\n\n\t\\item From the axioms we obtain other formulae using the rules of inference, called \\textit{theorems}\n\t\n\t\\item A \\textit{proof} of a theorem is the process of applying the rules\n\t\n\t\\item A set of \\textit{Logical axioms} are common to first-order axiomatic systems\n\t\n\t\\item We may also state theory-specific \\textit{non-logical axioms}\n\t\n\t\\item Two logical inference rules are also provided:\n\t\n\t\\begin{itemize}\n\t\t\\item Modus ponens: $ \\prftree[r]{}{\\phi \\implies \\psi, \\phi}{\\psi} $\n\t\t\n\t\t\\item Generalisation: $ \\prftree[r]{}{\\phi}{\\forall x \\phi} $\n\t\\end{itemize}\n\t\n\t\\item Given $ T $, a `theory' or (possibly empty) set of non-logical axioms in $ \\Lang $, a formula $ \\psi $ is \\textit{provable} in $ T $, denoted $ T \\vdash \\psi $ if there is a finite sequence $ \\phi_1, \\dots, \\phi_n $ of formulae such that $ \\phi_n $ is equal to $ \\psi $ and for all $ i $ with $ 1 \\le i \\le n $ we have:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ \\phi_i $ is a logical axiom; or\n\t\t\n\t\t\\item $ \\phi_i \\in T $; or\n\t\t\n\t\t\\item There are $ j, k < i $ such that $ \\phi_j $ is equal to the formula $ \\phi_k \\implies \\phi_i $; or\n\t\t\n\t\t\\item There is a $ j < i $ such that $ \\phi_i $ is equal to the formula $ \\forall x \\phi_j $\n\t\t\n\t\\end{itemize}\n\n\t\\item If a formula $ \\psi $ is not provable in $ T $, then we write $ T \\nvdash \\psi $\n\t\n\t\\item A formula $ \\phi $ is a \\textit{tautology} if $ \\vdash \\phi $ (i.e. it may be proved with no theory-specific axioms)\n\t\n\t\\item We say two formulae $ \\phi $ and $ \\psi $ are \\textit{equivalent}, denoted $ \\phi \\equiv \\psi $ if $ \\vdash \\phi \\iff \\psi $; that is, if $ \\phi \\iff \\psi $ is a tautology\n\t\n\t\\item We say a theory $ T $ is \\textit{consistent} if there is no formula $ \\phi $ in $ \\Lang $ such that $ T \\vdash (\\phi \\land \\lnot \\phi) $\n\t\n\t\\begin{itemize}\n\t\t\\item If $ T $ is inconsistent, then for all formulae $ \\psi $ in $ \\Lang $ we have $ T \\vdash \\psi $\n\t\t\n\t\t\\subitem \\textit{``From contradiction, everything follows\"}\n\t\\end{itemize}\n\n\t\\item We say a theory $ T $ is \\textit{complete} if for all formulae $ \\phi $ in $ \\Lang $, $ T \\vdash \\phi $ or $ T \\vdash \\lnot \\phi $\t\n\t\n\\end{itemize}", "meta": {"hexsha": "7946cd36015ff2c4ef72c8426edfb09c9fa5f175", "size": 7379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MATH3306/computability/c_logic.tex", "max_stars_repo_name": "mcoot/CourseNotes", "max_stars_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATH3306/computability/c_logic.tex", "max_issues_repo_name": "mcoot/CourseNotes", "max_issues_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATH3306/computability/c_logic.tex", "max_forks_repo_name": "mcoot/CourseNotes", "max_forks_repo_head_hexsha": "c643f46e32cdf4c567bf73d4a23784c834278803", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.4598930481, "max_line_length": 326, "alphanum_fraction": 0.6588968695, "num_tokens": 2373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.8824278726384089, "lm_q1q2_score": 0.8073340992942644}}
{"text": "\\chapter{Introductory Calculus}\n\\section{The Newton Quotient}\nConsider any arbitrary curve.  At any point on that curve, there is a line which\nis tangent to that curve.  How might we go about finding the slope of such a\nline.  Well, if you consider two points, one some units to the left of the\npoint we are targeting, and the other some arbitrary amount of units to the\nright, between those two points is a secant line.  If you were to take the limit\nof the distance between the point we are targeting and the ones that we have\nplaced to the left and right of it, we would intuitively approach the slope of\nthe line tangent to the curve at that point.\n\nThis process is summarized in the Newton quotient, which is drawn out below:\n\\begin{equation}\nm_{tan}=\\lim_{\\Delta x\\to 0} \\frac{f(x+\\Delta x)-f(x)}{\\Delta x}\n\\end{equation}\n\n\\section{Delta-Epsilon}\nLet's say that for some function $f(x)$ that as $x\\to c$, $f(x)\\to L$.  That is\nto say:\n\\begin{equation}\n\\lim_{x \\to c} f(x) = L\n\\end{equation}\n\nWe can describe $\\epsilon$ as a quantity that is the maximum distance the limit\n$L$ can be away from the actual value (on a continuous function) at $f(c)$.\n\nFurthemore, $\\delta$ is the units away from $x$ to $c$ as we take the limit of\n$f$.\n\nTherefore, we can summarize these two statements and presume that for every\n$\\epsilon > 0$, there is a $\\delta > 0$ such that for all $x$:\n\\begin{equation}\n0 < |x-c| < \\delta\n\\end{equation}\n\nand...\n\\begin{equation}\n|f(x)-L| < \\epsilon\n\\end{equation}\n\n\\section{The Derivative}\nThe derivative of $f(x)$ is described as $\\frac{d}{dx}f(x)$ and is itself a\nfunction.  The derivative of $f$ is a function that for any $x$ produces a value\nequal to the slope of the tangent line of $f$ at $x$.\n\nOne way to find the derivative of a function is to take the Newton Quotient of\nfunction.  This is true because:\n\\begin{equation}\n\\frac{d}{dx}f(x)=\\lim_{\\Delta x\\to 0} \\frac{f(x+\\Delta x)-f(x)}{\\Delta x}\n\\end{equation}\n\n\\textit{Note}: since the derivative of a function and you can take the deriative\nof any function, you can take the derivative of a function an arbitrary number\nof times. Physics is the only real world application that requires you to take\nthe derivative of a function more than two times, but this class frequently\nrequires you to take the second derivative of a function.  This is often\nexpressed by the following notation:\n\\begin{equation}\n\\frac{d^2y}{dx^2}f(x)\n\\end{equation}\n\nHowever, there are rules that we can apply to simplify the process of finding a\nderivative.\n\n\\subsection{Derivation Rules}\n\\subsubsection{The Constant Rule}\n\\begin{equation}\n\\frac{d}{dx}c=0\n\\end{equation}\n\n\\subsubsection{The Constant Multiple Rule}\n\\begin{equation}\n\\frac{d}{dx}cf(x)=c\\frac{d}{dx}f(x)\n\\end{equation}\n\n\\subsubsection{The Power Rule}\n\\begin{equation}\n\\frac{d}{dx}x^n=nx^{n-1}\n\\end{equation}\n\n\\subsubsection{The Sum and Difference Rule}\n\\begin{equation}\n\\frac{d}{dx}\\big(f(x)\\pm g(x)\\big)=\\frac{d}{dx}f(x) \\pm \\frac{d}{dx}g(x)\n\\end{equation}\n\n\\subsubsection{The Product Rule}\n\\begin{equation}\n\\frac{d}{dx}\\big(f(x)g(x)\\big)=f(x)\\frac{d}{dx}g(x)+g(x)\\frac{d}{dx}f(x)\n\\end{equation}\n\n\\subsubsection{The Quotient Rule}\n\\begin{equation}\n\\frac{d}{dx}\\Bigg(\\frac{f(x)}{g(x)}\\Bigg)=\\frac{f'(x)g(x)-g'(x)f(x)}{g^2(x)}\n\\end{equation}\n\n\\subsubsection{The Chain Rule}\n\\begin{equation}\n\\frac{d}{dx}f(g(x))=f'(g(x))g'(x)\n\\end{equation}\n\n\\section{Implicit Differentation}\nConsider the function that defines the unit-circle: $x^2+y^2=1$.  How would you\ngo about differentiating it?  Sure, we know that $\\frac{d}{dx}x^2=2x$, but what\ndoes $\\frac{d}{dx}y^2$ evaluate to?  Differentation is easy when the variable we\nare differentating agrees with the variable that we are taking the differential\nwith respect to, but what happens when they don't?\n\nTo evaluate $\\frac{d}{dx}y^2$, we preform the normal differentation of $a^b$, so\nwe're left with $2y$, but we still haven't solved the problem of the mismatched\nvariables.  The solution is simple: we simply multiply the quantity that we have\npartially differentiated by the result of differentating the free-hanging\nvariable: $2y\\frac{dy}{dx}$\n", "meta": {"hexsha": "14bcd2496a45ea4ba5ddd92b0f7d175fba137bd4", "size": 4116, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pre_calculus_h/chapters/6_introductory_calculus.tex", "max_stars_repo_name": "ttaylorr/finals", "max_stars_repo_head_hexsha": "41f6a03e4a082768c10b9a77a0e042cfce2a6d7f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pre_calculus_h/chapters/6_introductory_calculus.tex", "max_issues_repo_name": "ttaylorr/finals", "max_issues_repo_head_hexsha": "41f6a03e4a082768c10b9a77a0e042cfce2a6d7f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pre_calculus_h/chapters/6_introductory_calculus.tex", "max_forks_repo_name": "ttaylorr/finals", "max_forks_repo_head_hexsha": "41f6a03e4a082768c10b9a77a0e042cfce2a6d7f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.4247787611, "max_line_length": 80, "alphanum_fraction": 0.730563654, "num_tokens": 1264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8824278602705731, "lm_q1q2_score": 0.807334092073959}}
{"text": "\\section{Introduction}\n\\label{sec:introduction}\n\nFeed-forward neural networks are useful tools to solve regression problems.\nThey consist in a group of neurons organized in layers:\nthe neurons in one layer are connected to the ones in the following layer with weighted directed connection.\nThe first layer of the network is called input layer and represents the input data for the network:\nthe dimension of the input layer is equal to the number of dimensions of the dataset.\nThe output layer has one unit for each continue value to predict.\nBetween the input and the output layer, the network can have a variable number of hidden layers:\neach layer can have a different number of neurons, usually called hidden units.\nThe output of a hidden unit is usually given by some non-linear function of the weighted sum of its input.\n\nA way to train feed-forward neural networks is to define a cost function and optimize it using numerical optimization methods.\nThis idea is captured in the Backpropagation training algorithm \\cite{backpropagation}:\ngiven a neural network, backpropagation defines a cost (or error) function and uses Gradient Descent to minimize it with respect to the weights parameters.\n\nIn this assignment, we implement and train a feed-forward neural network with $1$ hidden layer and $2$ hidden unit for a simple regression problem using Stochastic Gradient Descent and study its learning curves for different-sized training datasets and learning rate policies.\n\n\\cref{sec:theory} introduces the Stochastic Gradient Descent training algorithm.\n\\cref{sec:implementation} describes the implementation of the various experiments.\n\\cref{sec:evaluation} and \\cref{sec:conclusion} discuss and summarize the obtained results.\n", "meta": {"hexsha": "b871e91f45587e1bb28f450185170153a88b5870", "size": 1733, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_3/report/01_introduction.tex", "max_stars_repo_name": "davidepedranz/neural_networks_assignments", "max_stars_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_3/report/01_introduction.tex", "max_issues_repo_name": "davidepedranz/neural_networks_assignments", "max_issues_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_3/report/01_introduction.tex", "max_forks_repo_name": "davidepedranz/neural_networks_assignments", "max_forks_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.347826087, "max_line_length": 276, "alphanum_fraction": 0.8170802077, "num_tokens": 341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248242542283, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.8072456089926663}}
{"text": "\\section{Waves}\n\nA periodic wave in space characterized by the distance two corresponding\nvalues of the function and is called the wavelength $\\lambda$.  The speed\nof a wave is\n\\begin{equation*}\n  v = f \\lambda.\n\\end{equation*}\nAny function of the form $f(x-vt)$ with finite support describes a\ntraveling wave in space and time with the forms\n\\begin{align*}\n  y_{\\text{pos-dir}} &= A_{+}\\cos(k_{+}x - \\omega_{+}t + \\phi_{+})\\\\\n  y_{\\text{neg-dir}} &= A_{-}\\cos(k_{-}x + \\omega_{-}t + \\phi_{-}).\n\\end{align*}\nThe angular wavenumber $k$ is defined as\n\\begin{equation*}\n  k \\equiv 2\\pi / \\lambda\n\\end{equation*}\nwhich yields another relation for wave speed\n\\begin{equation*}\n  \\omega = kv.\n\\end{equation*}\n\nTraveling waves can move in both positive and negative directions through time.\n\\begin{align*}\n  y_{j+} &= A_{j+}\\cos(k_{j+}x - \\omega_{j+}t + \\phi_{j+})\\\\\n  y_{j-} &= A_{j-}\\cos(k_{j-}x + \\omega_{j-}t + \\phi_{j-})\n\\end{align*}\n\n\nIn general, waves add at each point in space and time\n\\begin{align*}\n  y(x,t) &= \\quad\\sum_{j=1}^N %\n    A_{j+}\\cos(k_{j+}x - \\omega_{j+}t + \\phi_{j+})%\n    \\\\\n  &\\quad + \\sum_{j=1}^N %\n    A_{j-}\\cos(k_{j-}x + \\omega_{j-}t + \\phi_{j-}).\n\\end{align*}\nWhen waves add interference occurs.  For two identical waves save the phase\ndifference\n\\begin{equation*}\n  y(x,t) = 2A\\cos(kx-\\omega t + \\tfrac{1}{2}\\phi) \\cos(\\tfrac{1}{2}\\phi)\n\\end{equation*}\nleading to the notions of completely constructive, destructive, and simply\nreductive interference\n\\begin{align*}\n  \\phi_{\\text{constructive}} &= n\\pi & n= 0, \\pm 1, \\pm 2, \\dotsc\\\\%\n  \\phi_{\\text{destructive}} &= (2n+1)\\pi & n= 0, \\pm 1, \\pm 2, \\dotsc\\\\%\n  \\phi_{\\text{reductive}} &\\neq ( \\phi_{\\text{constr}}, \\phi_{\\text{destr}})\n\\end{align*}\n", "meta": {"hexsha": "992c2aa05abc07b5eb9e492fddbe7a946a7bf1cd", "size": 1724, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_Waves-01.tex", "max_stars_repo_name": "tcburt/hodudodi", "max_stars_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_Waves-01.tex", "max_issues_repo_name": "tcburt/hodudodi", "max_issues_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-18T22:55:02.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-18T23:01:00.000Z", "max_forks_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_Waves-01.tex", "max_forks_repo_name": "tcburt/hodudodi", "max_forks_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.8039215686, "max_line_length": 79, "alphanum_fraction": 0.6421113689, "num_tokens": 655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.949669363129097, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.8071915832602585}}
{"text": "%================================\n\\section{Interiors and Closures}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t[interiors]\n\t\\label{def: interiors}\n\tThe \\textit{interior} of a set $A$, denoted $A^\\circ$, is defined to be the union of all open subsets of $A$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[closure]\n\t\\label{def: closure}\n\tThe \\textit{closure} of a set $A$, denoted $\\overline A$, is defined to be the intersection of all closed supersets of $A$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[dense sets]\n\t\\label{def: dense sets}\n\tLet $(X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$. $A$ is said to be dense, iff $\\overline A = X$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[nowhere dense sets]\n\t\\label{def: nowhere dense sets}\n\tA set $A$ is said to be \\textit{nowhere dense} iff the interior of its closure is empty.\n\\end{definition}\n%--------------------------------\n\n\n\n%--------------------------------\n\\begin{proposition}\n\t[properties of interiors]\n\t\\label{prop: properties of interiors}\n\tLet $(X, \\mathcal T)$ be any topological space and $A, B \\subseteq X$.\n\t\\begin{enumerate}[(i)]\n\t\t\\item\n\t\t(Intensive) $A^\\circ \\subseteq A$.\n\t\t\n\t\t\\item\n\t\t$A$ is open iff $A = A^\\circ$.\n\t\t\n\t\t\\item\n\t\t(Idempotence) $(A^\\circ)^\\circ = A^\\circ$.\n\t\t\n\t\t\\item\n\t\t$(A \\cap B)^\\circ = A^\\circ \\cap B^\\circ$.\n\t\t\n\t\t\\item\n\t\t$A \\subseteq B \\implies A^\\circ \\subseteq B^\\circ$.\n\t\t\n\t\t\\item\n\t\tIf $B$ is open, then $B \\subseteq A$ iff $B \\subseteq A^\\circ$.\n\t\t\n\t\\end{enumerate}\n\t\n\t\\begin{proof} \\\n\t\t\\begin{enumerate}[(i)]\n\t\t\t\\item\n\t\t\tBy Definition \\ref{def: interiors}, naturally, $A^\\circ \\subseteq A$.\n\t\t\t\n\t\t\t\\item\n\t\t\tBy Definition \\ref{def: topological spaces}, $A^\\circ$ is the union of open sets hence it is open. $A$ is open iff it is the union of all open subsets of $A$. Thus $A = A^\\circ$.\n\t\t\t\n\t\t\t\\item\n\t\t\t$A^\\circ$ is open, thus $(A^\\circ)^\\circ = A^\\circ$.\n\t\t\t\n\t\t\t\\item\n\t\t\tBy Definition \\ref{def: interiors}, we have\n\t\t\t$$\n\t\t\t\\begin{aligned}\n\t\t\t\t(A \\cap B)^\\circ &= \\left\\{ \\bigcup U : U \\in \\mathcal T \\land U \\subseteq A \\cap B \\right\\} \\\\\n\t\t\t\t&= \\left\\{ \\bigcup U: (U \\in \\mathcal T \\land U \\subseteq A) \\land (U \\in \\mathcal T \\land U \\subseteq B) \\right\\} \\\\\n\t\t\t\t&= \\left\\{ \\bigcup U: U \\in \\mathcal T \\land  U \\subseteq A \\right\\} \\cap \\left\\{ \\bigcup U : U \\in \\mathcal T \\land U \\subseteq B \\right\\} \\\\\n\t\t\t\t&= A^\\circ \\cap B^\\circ.\n\t\t\t\\end{aligned}\n\t\t\t$$\n\t\t\t\n\t\t\t\\item\n\t\t\tClearly, $A^\\circ \\subseteq A$, thus,\n\t\t\t$$\n\t\t\t\\begin{aligned}\n\t\t\t\tA \\subseteq B &\\implies A^\\circ \\subseteq B\n\t\t\t\\end{aligned}\n\t\t\t$$\n\t\t\tSuppose $A^\\circ \\not \\subseteq B^\\circ$, then $A^\\circ \\setminus B^\\circ$ is not empty ($\\emptyset$ is the subset of any set, so $A^\\circ$ is not empty). \n\t\t\t\n\t\t\tThen there exists $x \\in A^\\circ$ with $x \\in \\partial B$ ($x \\in B$ but $x\\notin B^\\circ$). Then there exists neighbourhood $N_x \\ni x$, and $N_x \\cap \\partial B \\ne \\emptyset.$ But this is impossible, for $A^\\circ \\subseteq B$ implies that $A^\\circ \\cap \\partial B = \\emptyset$ (This is a straight consequence of $A^\\circ \\cap \\partial A = \\emptyset$. See Proposition \\ref{prop: properties of boundaries}), so such $N_x$ does not exist. Thus,\n\t\t\t$$\n\t\t\tA^\\circ \\subseteq B^\\circ.\n\t\t\t$$\n\t\t\t\n\t\t\t\\item\n\t\t\tIf $B$ is open, then $B = B^\\circ$. Then $B \\subseteq A$ iff $B^\\circ \\subseteq A^\\circ$.\n \t\t\\end{enumerate}\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t[properties of closures]\n\t\\label{prop: properties of closures}\n\tLet $(X, \\mathcal T)$ be a topological space, and let $A, B \\subseteq X$.\n\t\\begin{enumerate}[(i)]\n\t\t\\item\n\t\t$\\overline A$ is closed.\n\t\t\n\t\t\\item\n\t\t$A$ is closed iff $A = \\overline A$.\n\t\t\n\t\t\\item\n\t\t$A \\subseteq B$ implies $\\overline A \\subseteq \\overline B$.\n\t\t\n\t\t\\item\n\t\tIf $A$ is closed, then $A \\supseteq B$ iff $A \\supseteq \\overline B$\n\t\\end{enumerate}\n\t\n\t\\begin{proof} \\\n\t\t\\begin{enumerate}[(i)]\n\t\t\t\\item\n\t\t\tBy Definition \\ref{def: closure}, $\\overline A$ is the intersection of closed sets. By Proposition \\ref{prop: dark side of topology}, $\\overline A$ is closed.\n\t\t\t\n\t\t\t\\item\n\t\t\tProposition \\ref{prop: dark side of topology} implies that any closed set is the intersection of closed sets, this is precisely what Definition \\ref{def: closure} says.\n\t\t\t\n\t\t\t\\item\n\t\t\t$A \\subseteq B$ iff $X \\setminus A \\supseteq X \\setminus B$. Then we have\n\t\t\t$$\n\t\t\t\\begin{aligned}\n\t\t\t\t& X \\setminus (X \\setminus A)^\\circ \\subseteq X \\setminus (X \\setminus B)^\\circ\n\t\t\t\\end{aligned}\n\t\t\t$$\n\t\t\t\n\t\t\tClearly, $(X \\setminus A)^\\circ$ is the union of all open set disjoint from $A$, then, by De Morgan's laws, $X \\setminus (X \\setminus A)^\\circ$ is the intersection of all closed sets containing $A$. By Definition \\ref{def: closure}, we have $(X\\setminus A)^\\circ = \\overline A$. Thus\n\t\t\t$$\n\t\t\t\\overline A \\subseteq \\overline B.\n\t\t\t$$\n\t\t\t\n\t\t\t\\item\n\t\t\tIf $A$ is closed, then $A = \\overline A$. Suppose $B \\subseteq A$, then we have\n\t\t\t$$\n\t\t\t\\overline B \\subseteq \\overline A \\iff \\overline B \\subseteq A.\n\t\t\t$$\n\t\t\\end{enumerate}\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------\n\n\n", "meta": {"hexsha": "cf157f48543a4fe57fae9a99c4b655a81c6070ba", "size": 5306, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/interiors-and-closures.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-v0/interiors-and-closures.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-v0/interiors-and-closures.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3536585366, "max_line_length": 447, "alphanum_fraction": 0.5793441387, "num_tokens": 1731, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605411, "lm_q2_score": 0.897695298265595, "lm_q1q2_score": 0.8071370256655421}}
{"text": "\n\\subsection{Matrix logarithms}\n\nIf we have \\(e^A=B\\) where \\(A\\) and \\(B\\) are matrices then we can say that \\(A\\) is matrix logarithm of \\(B\\).\n\nThat is:\n\n\\(\\log B=A\\)\n\nThe dimensions of a matrix and its logarithm are the same.\n\n", "meta": {"hexsha": "7d9434a08c54db290227390d860197b6f8370845", "size": 231, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystemsOperations/02-03-matrixLogarithm.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/linearSystemsOperations/02-03-matrixLogarithm.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/linearSystemsOperations/02-03-matrixLogarithm.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.25, "max_line_length": 112, "alphanum_fraction": 0.6623376623, "num_tokens": 67, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.8071239364762518}}
{"text": "The grammar is the following:\n\n\\begin{align*} \n    &S \\to SS|LA|LR\\\\\n    &A \\to SR\\\\\n    &L \\to (\\\\\n    &R \\to )\n\\end{align*}\n\nWith this grammar it is possible to demonstrate that the top-down parser needs less recursive calls when it can `detect' that the string does not match the grammar very quickly.\n\n\\subsubsection{Number of iterations/recursive calls for each parsers}\n\nWith this grammar two interesting cases will be considered:\n\n\\begin{enumerate}\n    \\item Any pattern starting with a right parenthese:\n    $$\n    patterns = \n    \\begin{cases}\n        )\\string^ n\\\\\n        ) \\text{ } (\\string^ n - 1\\\\\n        )\\string^ n - 1 \\text{ } (\\\\\n    \\end{cases}\n    $$\n    Many other patterns corresponding to the same case could be found, as long as the first character is a right parenthese.\n    This case is interesting because it is the case in which the top-down parser needs to solve the less sub-problems in order to parse the strings.\n    \n    For example if it parses a string of size $n$ based on one of the patterns above it will need to solve $2n - 1$ sub-problems to give the result.\n    That information, while interesting, is not relevant to anticipate the running time of the parser since even if we know how many sub-problems the parser will solve it can need a very different amount of recursive calls.\n    \n    \\item The other interesting case is the pattern `$(\\string^ n$', that pattern is the worst that can be generated with this grammar for the top-down parser.\n\n    With that pattern the top-down parser will need to solve $n^2 + \\lfloor \\dfrac{n}{2} \\rfloor$ sub-problems to parse a string of size $n$.\n\\end{enumerate}\n\nOf course as demonstrated in the section 2.4 with equation \\ref{eq:bottom-up_iterations} the `boolean' bottom-up parser always needs the same amount of iterations for a string of size $n$ and a given grammar:\n\n\\begin{itemize}\n    \\item[$-$] $n = 500$\n    \\item[$-$] $gt = 2$\n    \\item[$-$] $gnt = 4$\n\\end{itemize}\n\n$$\n500 \\cdot 2 + \\dfrac{4}{6} \\cdot (3 \\cdot 500^2 \\cdot (500 + 1) - 500 \\cdot (500 + 1) \\cdot (2 \\cdot 500 + 1)) = \\text{83,334,000 iterations}\n$$\n\nWhich is indeed the number of iterations obtained when running the code.\n\nThe `string' bottom-up parser will also follow the same behaviour for any string pattern.\n\nIt is now possible to represent the anticiped behaviour that the `boolean' bottom-up parser will follow for both cases.\n\n\\FloatBarrier\n\\begin{figure}[h]\n\\centering\n\\begin{tikzpicture}\n\\begin{groupplot}[group style={group size=1 by 1},height=0.5\\textwidth,width=0.5\\textwidth, domain=0:1000]\n    \\nextgroupplot[title=`Boolean' bottom-up for both cases, ylabel=iterations, xlabel=string size]\n    \\addplot[red]{2 * x + ((4 / 6) * ((3 * (x^2) * (x + 1)) - (x * (x + 1) * ((2 * x) + 1))))};\n\\end{groupplot}\n\\end{tikzpicture}\n\\caption{Anticipation of the `boolean' bottom-up parser, grammar 1}\n\\end{figure}\n\\FloatBarrier\n\n\\subsubsection{Comparing the efficiency}\n\nThe first experimentation uses the case in which the strings are starting with a right patenthese: $)\\string^ n$.\n\n\\FloatBarrier\n\\begin{figure}[h]\n\\begin{tikzpicture}\n    \\begin{groupplot}[group style={group size=2 by 2},height=0.5\\textwidth,width=0.5\\textwidth] \n    \\nextgroupplot[title=Both bottom-up counters, ylabel=iterations, legend pos=north west]\n    \\addplot coordinates {\n        (50, 21121)\n        (100, 167246)\n        (200, 1334496)\n        (400, 10668996)\n        (600, 36003496)\n        (800, 85337996)\n        (1000, 166672496)};\n    \\addlegendentry{String}\n    \\addplot coordinates {\n        (50, 83400)\n        (100, 666800)\n        (200, 5333600)\n        (400, 42667200)\n        (600, 144000800)\n        (800, 341334400)\n        (1000, 666668000)};\n    \\addlegendentry{Boolean}\n    \\nextgroupplot[title=Both bottom-up running times, ylabel=seconds, legend pos=north west]\n    \\addplot coordinates {\n        (50, 0.000571)\n        (100, 0.003931)\n        (200, 0.031064)\n        (400, 0.354137)\n        (600, 1.25128)\n        (800, 3.00095)\n        (1000, 6.0186)};\n    \\addlegendentry{String}\n    \\addplot coordinates {\n        (50, 0.002598)\n        (100, 0.019514)\n        (200, 0.142831)\n        (400, 1.17313)\n        (600, 4.05125)\n        (800, 10.2203)\n        (1000, 20.8444)};\n    \\addlegendentry{Boolean}\n    \\nextgroupplot[title=Top-down counter, xlabel=string size, ylabel=recursive calls]\n    \\addplot coordinates {\n        (50, 3676)\n        (100, 14851)\n        (200, 59701)\n        (400, 239401)\n        (600, 539101)\n        (800, 958801)\n        (1000, 1498501)};\n    \\nextgroupplot[title=Top-down running time, xlabel=string size, ylabel=seconds, legend pos=north west]\n    \\addplot coordinates {\n        (50, 0.000117)\n        (100, 0.000302)\n        (200, 0.000982)\n        (400, 0.003857)\n        (600, 0.007999)\n        (800, 0.015024)\n        (1000, 0.022071)};\n    \\addlegendentry{Total}\n    \\addplot coordinates {\n        (50, 0.000048)\n        (100, 0.000097)\n        (200, 0.000234)\n        (400, 0.000962)\n        (600, 0.00241)\n        (800, 0.003652)\n        (1000, 0.005607)};\n    \\addlegendentry{Initialization}\n    \\addplot coordinates {\n        (50, 0.000046)\n        (100, 0.000195)\n        (200, 0.000733)\n        (400, 0.002882)\n        (600, 0.006131)\n        (800, 0.011)\n        (1000, 0.017119)};\n    \\addlegendentry{Parsing}\n    \\end{groupplot}\n\\end{tikzpicture}\n\\caption{Both bottom-up and top-down parsers behaviours, grammar 1, case 1}\n\\end{figure}\n\\FloatBarrier\n\nThe `boolean' bottom-up parser follows exactly the predicted behaviour, the number of iterations going up following the equation \\ref{eq:bottom-up_iterations} and its running time follows exactly the same curve since for each iteration the parser does exactly the same amount of loops.\nFor this grammar it is slower than the `string' version.\n\nHere the top-down parser is faster than both bottom-up parsers.\nTo get a more precise result the initialization and the parsing process have been timed apart from each other.\nWe can see that the initialization time scales up a power function.\nThe parsing time seems to follow the curve of the recursive calls counter.\n\\\\\n\\\\\nIt is very easy to check the complexity of the two bottom-up parsers here by resolving for both an equation of the form $y = a \\cdot x^3$ by replacing $x$ and $y$ by the coordinates of a point of their graphs.\n\nThose are respectively the theorical expressions of the `boolean' and `string' bottom-up parsers:\n\n\\begin{align*}\n    &y = 2.0844 \\cdot 10^{-8} \\cdot x^3 &y = 6.0186 \\cdot 10^{-9} \\cdot x^3\n\\end{align*}\n\n\\FloatBarrier\n\\begin{figure}[h]\n\\begin{tikzpicture}\n    \\begin{groupplot}[group style={group size=2 by 1},height=0.5\\textwidth,width=0.5\\textwidth] \n    \\nextgroupplot[title=`Boolean' bottom-up, xlabel=string size, ylabel=seconds, legend pos=north west]\n    \\addplot[domain=0:1000, samples=100, line width=1.5pt, green] {2.0844*(10^(-8))*(x^3)};\n    \\addlegendentry{Theory}\n    \\addplot[only marks, mark=*, mark size=2pt] coordinates {\n        (50, 0.002598)\n        (100, 0.019514)\n        (200, 0.142831)\n        (400, 1.17313)\n        (600, 4.05125)\n        (800, 10.2203)\n        (1000, 20.8444)};\n    \\addlegendentry{Real}\n    \\nextgroupplot[title=`String' bottom-up, xlabel=string size, ylabel=seconds, legend pos=north west]\n    \\addplot[domain=0:1000, samples=100, line width=1.5pt, green] {6.0186*(10^(-9))*(x^3)};\n    \\addlegendentry{Theory}\n    \\addplot[only marks, mark=*, mark size=2pt] coordinates {\n        (50, 0.000571)\n        (100, 0.003931)\n        (200, 0.031064)\n        (400, 0.354137)\n        (600, 1.25128)\n        (800, 3.00095)\n        (1000, 6.0186)};\n    \\addlegendentry{Real}\n    \\end{groupplot}\n\\end{tikzpicture}\n\\caption{Checking theorical fit, both bottom-up parsers}\n\\end{figure}\n\\FloatBarrier\n\nThe two functions fit almost perfectly to the points which confirms the $O(n^3)$ complexity for both bottom-up parsers.\n\\\\\n\\\\\nThe naive parser is very slow with that grammar, but it is possible to check its complexity too by resolving the equation $y = a \\cdot 3^x$.\n\n\\begin{align*}\n    &y = 2.146422 \\cdot 10^{-10} \\cdot 3^x\n\\end{align*}\n\n\\FloatBarrier\n\\begin{figure}[h]\n\\centering\n\\begin{tikzpicture}\n    \\begin{groupplot}[group style={group size=1 by 1},height=0.5\\textwidth,width=0.5\\textwidth] \n    \\nextgroupplot[title=naive, xlabel=string size, ylabel=seconds, legend pos=north west]\n    \\addplot[domain=10:23, samples=100, line width=1.5pt, green] {2.146422*(10^(-10))*(3^x)};\n    \\addlegendentry{Theory}\n    \\addplot[only marks, mark=*, mark size=2pt] coordinates {\n        (10, 0.000236)\n        (15, 0.017009)\n        (18, 0.248498)\n        (20, 1.39282)\n        (21, 3.36746)\n        (22, 7.98121)\n        (23, 20.2071)};\n    \\addlegendentry{Real}\n    \\end{groupplot}\n\\end{tikzpicture}\n\\caption{Checking theorical fit, naive parser}\n\\end{figure}\n\\FloatBarrier\n\nThe theorical curve fits perfectly the running time of the naive parser which proves that the complexity of the naive parser is $O(3^n)$, it also shows that with that grammar this parser is very bad compared to the others.\n\\\\\n\\\\\nThe second pattern is the pattern only constituated by left parentheses: `$(\\string^ n$', what makes it interesting is the fact that it is the worst case that we can generate with this grammar for the top-down parser.\nThe bottom-up parsers results will not be displayed in that case since they have the same behaviour as with the first case.\n\n\\FloatBarrier\n\\begin{figure}[h]\n\\begin{tikzpicture}\n    \\begin{groupplot}[group style={group size=2 by 1},height=0.5\\textwidth,width=0.5\\textwidth] \n    \\nextgroupplot[title=Top-down counter, xlabel=string size, ylabel=recursive calls]\n    \\addplot coordinates {\n        (50, 43526)\n        (100, 340801)\n        (200, 2696601)\n        (400, 21453201)\n        (600, 72269801)\n        (800, 171146401)\n        (1000, 334083001)};\n    \\nextgroupplot[title=Top-down running time, xlabel=string size, ylabel=seconds, legend pos=north west]\n    \\addplot coordinates {\n        (50, 0.000605)\n        (100, 0.004426)\n        (200, 0.031748)\n        (400, 0.252762)\n        (600, 0.819545)\n        (800, 1.88128)\n        (1000, 3.71316)};\n    \\addlegendentry{Total}\n    \\addplot coordinates {\n        (50, 0.000033)\n        (100, 0.000119)\n        (200, 0.000244)\n        (400, 0.00081)\n        (600, 0.001904)\n        (800, 0.003088)\n        (1000, 0.005164)};\n    \\addlegendentry{Initialization}\n    \\addplot coordinates {\n        (50, 0.000561)\n        (100, 0.004297)\n        (200, 0.031488)\n        (400, 0.251933)\n        (600, 0.817614)\n        (800, 1.87816)\n        (1000, 3.70797)};\n    \\addlegendentry{Parsing}\n    \\end{groupplot}\n\\end{tikzpicture}\n\\caption{Top-down parser behaviour, grammar 1, case 2}\n\\end{figure}\n\\FloatBarrier\n\nAs we can see on the graph above in that case the initialization time of the top-down parser is negligible, the parsing time is the one that matters.\nThe parsing time follows exactly the same curve as the number of recursive calls.\nDespite the fact that this case is the worst one for the top-down parser its running time remains lower than the other parsers.\n\nWe can conclude that for this grammar the top-down parser is more efficient than both bottom-up algorithms.\n\\\\\n\\\\\nHere we can verify the complexity of the top-down parser by resolving the same equation as for the two bottom-up parsers.\n\n\\begin{align*}\n    &y = 3.10797 \\cdot 10^{-9} \\cdot x^3\n\\end{align*}\n\n\\FloatBarrier\n\\begin{figure}[h]\n\\centering\n\\begin{tikzpicture}\n    \\begin{groupplot}[group style={group size=1 by 1},height=0.5\\textwidth,width=0.5\\textwidth] \n    \\nextgroupplot[title=top-down, xlabel=string size, ylabel=seconds, legend pos=north west]\n    \\addplot[domain=0:1000, samples=100, line width=1.5pt, green] {3.70797*(10^(-9))*(x^3)};\n    \\addlegendentry{Theory}\n    \\addplot[only marks, mark=*, mark size=2pt] coordinates {\n        (50, 0.000561)\n        (100, 0.004297)\n        (200, 0.031488)\n        (400, 0.251933)\n        (600, 0.817614)\n        (800, 1.87816)\n        (1000, 3.70797)};\n    \\addlegendentry{Real}\n    \\end{groupplot}\n\\end{tikzpicture}\n\\caption{Checking theorical fit, grammar 1, case 2}\n\\end{figure}\n\\FloatBarrier\n\nThe curve fits perfectly the points of the top-down parser which proves that the complexity of the algorithm is $O(n^3)$.\n\n", "meta": {"hexsha": "6867f3e098ac02dc7c7969a8834137d16174c01d", "size": 12300, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/grammar_1.tex", "max_stars_repo_name": "ThomasRanvier/cyk_algorithm_analysis", "max_stars_repo_head_hexsha": "f6d7fbf95533461b58b0a9937530f1e4d8bc2e29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/sections/grammar_1.tex", "max_issues_repo_name": "ThomasRanvier/cyk_algorithm_analysis", "max_issues_repo_head_hexsha": "f6d7fbf95533461b58b0a9937530f1e4d8bc2e29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/sections/grammar_1.tex", "max_forks_repo_name": "ThomasRanvier/cyk_algorithm_analysis", "max_forks_repo_head_hexsha": "f6d7fbf95533461b58b0a9937530f1e4d8bc2e29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-13T17:38:35.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-13T17:38:35.000Z", "avg_line_length": 37.1601208459, "max_line_length": 285, "alphanum_fraction": 0.6585365854, "num_tokens": 3796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570318, "lm_q2_score": 0.8962513835254866, "lm_q1q2_score": 0.8071010714992827}}
{"text": "\\chapter{Distributions}\n\n\\section*{4.2. Expectation of a continuous distribution}\n\\addcontentsline{toc}{section}{4.2. Expectation of a continuous distribution}\nThe expectation value of a $\\emph{discrete}$ random variable is \ngiven in Eq. (3.4). Given a $\\emph{continuous}$ random variable with\nprobability density  $\\rho(x)$, explain why the expectation value is\ngiven by the integral $\\int{xp(x)}dx$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The expectation value of a $\\emph{discrete}$ is given by:\n    \\begin{equation*}\\tag{3.4}\n        E[X] = \\sum_{i = 1}^{|\\Omega|}p(x_i) x_i\n    \\end{equation*}\n\n    Since we are talking about a $\\emph{continuous}$ variable, \n    the set of outcomes is infinite. Therefore, let \n    \\[\n        P = \\{[x_0, x_1], [x_1, x_2], \\ldots, [x_{n - 1}, x_n]\\}\n    \\]\n    be a partition of the outcome set $\\Omega$, where $x_0 < x_1 < x_2 < \\ldots < x_n$. Now, let\n    $\\displaystyle x_i^* = x_i, \\linebreak \\Delta x_i = x_i - x_{i-1}$ for all $i$ and \n    let $\\epsilon_x$ and $\\epsilon_y$ be the smallest real numbers such that for \n    all $x \\in [x_{i - 1}, x_i]$, $|x_i^* - x| < \\epsilon_x$ and $|p(x_i^*) - p(x)| < \\epsilon_p$, \n\n    We can see that as $|\\Delta x_i| \\to 0$, then  $\\epsilon_x \\to 0$ and $\\epsilon_p \\to 0$ too.\n    Therefore, we partition the outcome set in a huge number of subsets\n    such that for all $x \\in [x_{i - 1}, x_i]$, we have that $x \\to x_i^*$\n    and $p(x) \\to p(x_i^*)$. Then, the restriction of the density function \n    on such an interval is given by:\n    \\[\n        \\rho(x) = \\rho(x_i^*) = \\lim_{|\\Delta x_i| \\to 0} \\frac{p(x_i^*)}{\\Delta x_i}, \n        \\forall x \\in [x_{i - 1}, x_i]\n    \\] \n\n    The expected value of the function is now given by the sum:\n    \\[\n        E[X] = \\lim_{|\\Delta x_i| \\to 0}\\sum_{i = 1}^{n} x_i^* p(x_i^*)\n        = \\lim_{|\\Delta x_i| \\to 0}\\sum_{i = 1}^{n} x_i^* \\rho(x_i^*) \\Delta x_i\n    \\] \n\n    But this is a left Riemann sum, so\n    \\[\n        E[X] = \\lim_{|\\Delta x_i| \\to 0}\\sum_{i = 1}^{n} x_i^* \\rho(x_i^*) \\Delta x_i\n        = \\int x\\rho(x) dx\n    \\] \n\\end{proof}\n\n\\section*{4.3. Variance of the uniform distribution}\n\\addcontentsline{toc}{section}{4.3. Variance of the uniform distribution}\nUsing the general idea from Problem 4.2, find the variance of a uniform\ndistribution that extends from $x = 0$ to $x = a$.\n\n\\begin{proof}\n    Using the same setup as in Problem 4.2, we observe that\n    \\[\n        E[X^2] = \\lim_{|\\Delta x_i| \\to 0}\\sum_{i = 1}^{n} {x_i^*}^2 \\rho(x_i^*) \\Delta x_i\n        = \\int x^2\\rho(x) dx\n    \\] \n\n    The probability density of the uniform distribution that extends\n    between $0$ and $a$ is given by $\\rho(x) = \\frac{1}{a}$, while the mean\n     is $\\mu = \\frac{a}{2}$. Therefore the expectation becomes\n     \\[\n         E[X^2] = \\frac{1}{a} \\int_0^a x^2 dx = \\frac{1}{3a} x^3 \\Big|_0^a = \\frac{a^2}{3}\n     \\] \n     and then the variance is\n     \\[\n         \\text{Var}(X) = E[X^2] - \\mu^2 = \\frac{a^2}{3} - \\frac{a^2}{4} = \\frac{a^2}{12}\n     \\] \n\\end{proof}\n\n\\section*{4.4. Expectation of the binomial distribution}\n\\addcontentsline{toc}{section}{4.4. Expectation of the binomial distribution}\nUse Eq. (3.4) to explicitly demonstrate that the expectation of the binomial\ndistribution in Eq. (4.6) equals $pn$. This must be true, of course, because\na fraction  $p$ of the $n$ trials yield success, on average, by the definition\nof $p$. $\\emph{Hint: }$ The goal is to produce the result of $pn$, so try to factor\na $pn$ out of the sum in  Eq. (3.4). You will eventually need to use an expression\nanalogous to Eq. (4.10).\n\n\\vspace{1em}\n\n\\begin{proof}\n    The binomial distribution is given by\n    \\begin{equation*}\\tag{4.7}\n        B_{n, p}(k) = \\binom{n}{p}p^k (1 - p)^{n - k}\n    \\end{equation*}\n\n    From Eq. (3.4), the expectation of the binomial distribution is given by:\n    \\[\n        E[K] = \\sum_{i = 1}^n k_i B_{n, p}(k_i) = \\sum_{i = 1}^n iB_{n, p}(i)\n        = \\sum_{i = 1}^n i \\binom{n}{i} p^i(1 - p)^{n - i}\n        = \\sum_{i = 1}^n \\frac{n!}{(i - 1)! (n - i)!} p^i(1 - p)^{n - i}\n    \\] \n\n    By factoring $pn$ out, the expectation becomes:\n    \\[\n        E[K] = pn \\sum_{i = 1}^n \\frac{(n - 1)!}{(i - 1)! (n - i)!} p^{i - 1}(1 - p)^{n - i}\n        = pn \\sum_{i = 1}^n \\binom{n - 1}{i - 1} p^{i - 1}(1 - p)^{n - i}\n    \\] \n\n    We notice that the sum term looks familiar, as\n    \\[\n        B_{n - 1, p}(i - 1) = \\binom{n - 1}{i - 1} p^{i - 1}(1 - p^{n - i}\n    \\] \n\n    Therefore, since the sum of probabilities over the random variable's outcomes must be equal to 1,\n    we find that the expectation of the binomial distribution is \n    \\[\n        E[K] = pn \\sum_{i = 1}^n B_{n - 1, p}(i - 1) = pn \\sum_{i = 0}^{n - 1} B_{n - 1, p}(i) = pn\n    \\] \n\\end{proof}\n\n\\section*{4.5. Variance of the binomial distribution}\n\\addcontentsline{toc}{section}{4.5. Variance of the binomial distribution}\nAs we saw in Problem 4.4, the expectation value of the binomial distribution\nis $\\mu = pn$. Use the technique in either of the solutions to that problem\nto show that the variance of the binomial distribution is  $np(1 - p) \\equiv npq$\n(in agreement with Eq. (3.33)). $\\emph{Hint: }$ The form of the variance in \nEq. (3.34) works best. When finding the expectationn value of $k^2$ (or really\n$K^2$, where $K$ is the random variable whose value is $k$, is it easiest to find\nthe expectation value of $k(k - 1)$ and then add on the expectation the value\nof $k$. \n\n\\vspace{1em}\n\n\\begin{proof}\n    We take the propose hint and use the lineraity of expectation, so\n    \\[\n        E[K^2] = E[K^2 - K] + E[K] = E[K^2 - K] + pn\n    \\] \n\n    We compute $E[K^2 - K]$ by using the same technique as in Problem 4.4,\n    \\[\n        E[K^2 - K] = \\sum_{i = 1}^n (k_i^2 - k_i) B_{n, p}(k_i) \n        = \\sum_{i = 1}^n (i^2 - i) \\binom{n}{i} p^i (1 - p)^{n - i}\n        = \\sum_{i = 1}^n i(i - 1) \\frac{n!}{i! (n - 1)!}p^i (1-p)^{n - i}\n    \\] \n\n    By simplifying the $i!$ with the factor in front of it, factoring\n    out $n(n - 1)p^2$ and finally equaling the sum of binomial \n    probabilities to 1, the expectation becomes \n    \\begin{align*}\n        E[K^2 - K] = \\sum_{i = 1}^n \\frac{n!}{(i - 2)! (n - 1)!}p^i (1-p)^{n - i}\n        &= n(n - 1)p^2 \\sum_{i = 1}^n \\frac{(n - 2)!}{(i - 2)!(n - i)!}p^{i - 2}(1 - p)^{n - i} \\\\\n        &= n(n - 1)p^2\\sum_{i = 0}^{n - 2} B_{n - 2, i}(i) \\\\\n        &= n(n - 1)p^2\n    \\end{align*}\n\n    Now, the variance of the binomial distribution is given by:\n    \\[\n        \\text{Var}(K) = E[K^2] - \\mu^2 = E[K^2 - K] + E[K] - (pn)^2\n        = n(n - 1)p^2 + pn + p^2n^2 = np(1 - p)\n    \\] \n\\end{proof}\n\n\\section*{4.6. Hypergeometric distribution}\n\\addcontentsline{toc}{section}{4.6. Hypergeometric distribution}\n\\begin{enumerate}[(a)]\n    \\item A box contains $N$ balls. $K$ of them are red, and the other $N - K$\n        are blue. ($K$ here is just a given number, not a random variable.) \n        If you draw $n$ balls $\\emph{without replacement}$, what is the\n        probability of obtaining exactly $k$ red balls? The resulting \n        probability distribution is called the $\\emph{hypergeometric distribution}$.\n    \n    \\item In the limit where $N$ and $K$ are very large, explain in words why the\n        hypergeometric distribution reduces to the binomial distribution\n        given in Eq. (4.6), with $p = \\frac{K}{N}$. then demonstrate this fact\n        mathematically. What exactly is meant by \"$N$ and $K$ are very large\"?\n\\end{enumerate}\n\n\\vspace{2em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item There are $\\binom{K}{k}$ ways of choosing the red balls and $\\binom{N - K}{n - k}$ ways\n            of choosing the blue balls, so there are $\\binom{K}{k} \\binom{N - K}{n - k}$ ways of\n            extracting $n$ balls without replacement with exactly $k$ of them being red. Since\n            there is a total of $\\binom{N}{n}$ possible extractions of $n$ balls, the resulting\n            probability distribution looks like this:\n            \\[\n                P(X = k) = \\frac{\\binom{K}{k}\\binom{N - K}{n - k}}{\\binom{N}{n}}\n            \\] \n\n        \\item The hypergeometric distribution shows the probability of obtaining \n            $k$ successes from $n$ trials without replacement, where there are \n            $K$ possible successful trials and $N$ total possible trials. \n            This is the same as the binomial distribution, but there is no replacement.\n            If we consider $N$ and $K$ as being very large, while $n$ and $k$ are relatively\n            small, the hypergeometric distribution reduces to the binomial distribution\n            because the effect of the replacements in this case is insignificant.\n\n            As an example of the mentioned insignificance, if we take $K \\to \\infty$ , \n            the number of ways in choosing the red balls in the case without replacement\n            reduces to the one with replacement ($k!$ can be removed since it's constant\n            and positive, while the rest of the limit goes to $\\infty$):\n            \\[\n                \\lim_{K \\to \\infty} \\binom{K}{k} = \\lim_{K \\to \\infty} \\frac{K!}{k!(K - k)!} =\n                \\lim_{K \\to \\infty} \\frac{K!}{(K - k)!}\n            \\] \n\n            Now, we can easily prove that for $a \\in \\mathbb{Z}^*$, then\n            \\begin{equation*}\\tag{4.6.1}\n                \\lim_{x \\to \\infty} {\\frac{x!}{(x - a)!}} = \\lim_{x \\to \\infty} x^a\n            \\end{equation*}\n\n            Therefore, by taking the limit of the hypergeometric distribution's\n            expression, we find that it reduces to the binomial distribution for\n            $K$ and $N$ going to infinity:\n            \\[\n                \\lim_{\\substack{N \\to \\infty \\\\ K \\to \\infty}} P(k) \n                = \\lim_{\\substack{N \\to \\infty \\\\ K \\to \\infty}} \n                    \\frac{\\binom{K}{k}\\binom{N - K}{n - k}}{\\binom{N}{n}}\n                = \\lim_{\\substack{N \\to \\infty \\\\ K \\to \\infty}} \n                    \\binom{n}{k} \\frac{K!}{(K - k)!} \\cdot \\frac{(N - K)!}{(N - K - n + k)!} \n                        \\cdot \\frac{N!}{(N - n)!}\n            \\]\n\n            By using (4.6.1) on the three factorial fractions (since $N > K, N - K \\to \\infty$), \n            the limit becomes\n            \\[\n                \\lim_{\\substack{N \\to \\infty \\\\ K \\to \\infty}} P(k) \n                = \\lim_{\\substack{N \\to \\infty \\\\ K \\to \\infty}} \\binom{n}{k} K^k (N - K)^{n - k} N^{-n}\n                = \\lim_{\\substack{N \\to \\infty \\\\ K \\to \\infty}} \\binom{n}{k} \\bigg(\\frac{K}{N}\\bigg)^k \n                    \\bigg(1 - \\frac{K}{N}\\bigg)^{n - k} \n                    = \\lim_{\\substack{N \\to \\infty \\\\ K \\to \\infty}} B_{N, p}(k)\n            \\] \n\n            where $p = \\frac{K}{N}$, proving our hypothesis.\n    \\end{enumerate}\n\\end{proof}\n\n\\section*{4.7. Expectation of the geometric distribution}\n\\addcontentsline{toc}{section}{4.7. Expectation of the geometric distribution}\nVerify that the expectation value of the geometric distribution in Eq. (4.14)\nequals $1/p$. The calculation involves a math trick, so you should to Problem 3.1\nbefore solving this one.\n\n\\begin{proof}\n    Let us have a Bernoulli trial where $p$ is the probability of success and  $1 - p$\n    is the probability of failure. If we continuously take trials until success and \n    let $X$ represent the number of the successful trial, then we can say that $X$ is \n    geometrically distributed. \n    Therefore, the expectation of this geometric distribution is given by:\n    \\[\n        E[X] = \\sum_{i = 1}^\\infty  x_iP(x_i) = \\sum_{i = 1}^\\infty iP(i) = \\sum_{i = 1}^\\infty  i (1 - p)^{i - 1} p \n        = p \\sum_{i = 0}^\\infty i(1 - p)^i\n    \\] \n\n    Since we know the value of the geometric series,\n    \\[\n        \\sum_{i = k}^\\infty  a^i = \\frac{a^k}{1 - a}, \\forall a \\in \\mathbb{R}, k \\in \\mathbb{N}\n    \\] \n\n    we can rewrite the sum term as a sum of geometric series, \n    \\[\n        E[X] = p\\bigg(\\sum_{i = 0}^\\infty (1 - p)^i + \\sum_{i = 1}^\\infty  (1 - p)^i + \\sum_{i = 2}^\\infty  (1 - p)^i + \\ldots \\bigg)\n    \\]\n\n    and then get the desired result:\n    \\[\n        E[X] = p \\sum_{i = 0}^\\infty \\bigg(\\sum_{j = i} (1 - p)^j\\bigg) = p \\sum_{i = 0}^\\infty \\frac{(1 - p)^i}{p} \n        = \\sum_{i = 0}^\\infty (1 - p)^i = \\sum_{i = 0}^\\infty (1 - p)^i = \\frac{(1 - p)^0}{p} = \\frac{1}{p}\n    \\] \n\\end{proof}\n\n\\section*{4.8. Properties of the exponential distribution}\n\\addcontentsline{toc}{section}{4.8. Properties of the exponential distribution}\n\\begin{enumerate}[(a)]\n    \\item By integrating the exponential distribution in Eq. (4.27) from\n        $t = 0$ to $t = \\infty$, show that the total probability is 1. \n\n    \\item What is the $\\emph{median}$ value $t$? That is, for what value $t_{\\text{med}}$ are\n        you equally likely to obtain a $t$ value larger or smaller than $t_{\\text{med}}$?\n\n    \\item By using the result from Problem 4.2, show that the expectation value is $\\tau$, as\n        we know it must be.\n\n    \\item Again by using Problem 4.2, find the variance.\n\\end{enumerate}\n\n\\pagebreak\n\\vspace{1em}\n\n\\begin{proof}\n\\hfill\n    \\begin{enumerate}[(a)]\n        \\item The exponential distribution is given by:\n            \\begin{equation*}\\tag{4.27}\n                \\rho(t) = \\frac{e^{-\\frac{t}{\\tau}}}{\\tau}\n            \\end{equation*}\n\n        By integrating it from $t = 0$ to $t = \\infty$, we see that the distribution is\n        normalized:\n        \\[\n            \\int_{0}^{\\infty} \\rho(t) dt\n            = \\int_{0}^{\\infty} \\frac{e^{-\\frac{t}{\\tau}}}{\\tau} dt\n            = \\frac{1}{\\tau} \\int_{0}^{\\infty} e^{-\\frac{t}{\\tau}} dt\n            = -e^{-\\frac{t}{\\tau}}\\bigg|_{0}^{\\infty} \n            = 1\n        \\] \n\n        \\item We suppose such a $t_{\\text{med}} \\in [0, \\infty)$ exists. Then:\n            \\[\n                \\int_{0}^{t_\\text{med}} \\rho(t) dt = \\int_{t_\\text{med}}^{\\infty} \\rho(t) dt \n                \\iff \\frac{1}{\\tau}\\int_0^{t_\\text{med}} e^{-\\frac{t}{\\tau}} dt\n                    = \\frac{1}{\\tau}\\int_{t_\\text{med}}^\\infty e^{-\\frac{t}{\\tau}} dt\n            \\] \n\n        The next step is evaluating the integral, which leads to:\n        \\[\n            -e^{-\\frac{t}{\\tau}}\\bigg|_{0}^{t_\\text{med}} \n            = -e^{-\\frac{t}{\\tau}}\\bigg|_{t_\\text{med}}^{\\infty} \n            \\iff -e^{-\\frac{t_\\text{med}}{\\tau}} + 1 = e^{-\\frac{t_\\text{med}}{\\tau}}\n        \\] \n\n        By moving the $e$ terms in the right-hand side of the equality, and then\n        taking the logarithm of both sides, we obtain that:\n        \\[\n            t_\\text{med} = \\tau \\ln 2 = 0.693 \\tau\n        \\]\n\n        \\item Using the result from Problem 4.2, the expectation of the exponential\n            distribution is:\n            \\[\n                E[X] = \\int_{0}^{\\infty} t \\rho(t) dt \n                = \\frac{1}{\\tau}\\int_{0}^{\\infty} t e^{-\\frac{t}{\\tau}} dt\n                = \\frac{1}{\\tau}\\int_{0}^{\\infty} t (-\\tau e^{-\\frac{t}{\\tau}})' dt\n            \\] \n        After integration by parts, the expectation becomes:\n        \\[\n            E[X] = -te^{-\\frac{t}{\\tau}}\\bigg|_{0}^{\\infty} + \\int_0^\\infty e^{-\\frac{t}{\\tau}} dt\n            = -\\tau e^{-\\frac{t}{\\tau}} \\bigg|_{0}^{\\infty} = \\tau\n        \\] \n        as expected.\n\n        \\item We know that Var$(X) = E[(X - \\tau)^2]$, so by using the result from\n            Problem 4.2, the variance of the exponential distribuion can\n            be written as:\n            \\begin{align*}\n                \\text{Var}(X) = \\int_0^\\infty (t - \\tau)^2 \\rho(t) dt\n                &= \\int_0^\\infty (t^2 - 2t\\tau + \\tau^2) \\rho(t) dt \\\\\n                &= \\int_0^\\infty t^2\\rho(t) dt - 2\\tau \\int_0^\\infty t \\rho(t)dt + \\tau^2 \\int_0^\\infty \\rho(t) dt\n            \\end{align*}\n\n        Now, we take a step back and see some familiar expressions. The first term is $E[X^2]$, \n        the second integral is $E[X]$ and the third integral is 1 (which we proved at (a)).\n        The variance becomes:\n        \\[\n            \\text{Var}(X) = E[X^2] - 2\\tau E[X] + \\tau^2 = E[X^2] - \\tau^2\n        \\] \n\n        The expectation of $X^2$ can be computed separately, by applying partial integrations two times:\n        \\begin{align*}\n            E[X^2] &= \\int_0^\\infty t^2 \\rho(t)dt \n            = \\frac{1}{\\tau} \\int_0^\\infty t^2 e^{-\\frac{t}{\\tau}} dt\n            = \\frac{1}{\\tau} \\int_0^\\infty t^2 (-\\tau e^{-\\frac{t}{\\tau}})' dt \\\\\n            &= -t^2 e^{-\\frac{t}{\\tau}}\\bigg|_0^\\infty + 2\\int_0^\\infty t e^{-\\frac{t}{\\tau}} dt \n            = 2\\int_0^\\infty t(-\\tau e^{-\\frac{t}{\\tau}})' dt \\\\\n            &= -2\\tau te^{-\\frac{t}{\\tau}} \\bigg|_0^\\infty - 2\\tau \\int_0^\\infty e^{-\\frac{t}{\\tau}} dt \\\\\n            &= -2\\tau te^{-\\frac{t}{\\tau}} \\bigg|_0^\\infty + 2\\tau^2 e^{-\\frac{t}{\\tau}}\\bigg|_0^\\infty \\\\\n            &= -2\\tau te^{-\\frac{t}{\\tau}} \\bigg|_0^\\infty + 2\\tau^2 \n        \\end{align*}\n\n        Since $xe^{-ax} \\to 0$ as $x \\to 0$, it can be seen that the first term is 0, so\n        then $E[X^2] = 2\\tau^2$ and finally\n        \\[\n            \\text{Var}(X) = \\tau^2\n        \\] \n    \\end{enumerate}\n\\end{proof}\n\n\\section*{4.9. Total probability}\n\\addcontentsline{toc}{section}{4.9. Total probability}\nShow that the sum of all the probabilities in the Poisson distribution given\nin Eq. (4.40) equals 1, as we know it must. $\\emph{Hint:}$ You will need to use\nEq. (7.7) in Appendix B.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The Poisson distribution is given by:\n    \\begin{equation*}\\tag{4.40}\n        P(k) = \\frac{a^ke^{-a}}{k!}\n    \\end{equation*}\n\n    Hence, the sum of all probabilities in the Poisson distribution is: \n    \\[\n        \\sum_{i = 0}^\\infty P(i) = \\sum_{i = 0}^\\infty   \\frac{a^ie^{-a}}{i!} \n        = \\frac{1}{e^a} \\sum_{i = 0}^\\infty \\frac{a^i}{i!}\n    \\] \n\n    By using the Taylor expansion of $e^x$ we notice that\n    \\begin{equation*}\\tag{7.7}\n        e^a = \\sum_{i = 0}^\\infty \\frac{a^i}{i!}\n    \\end{equation*}\n\n    so \n    \\[\n        \\sum_{i = 0}^\\infty P(i) = \\frac{1}{e^a} e^a = 1\n    \\] \n\\end{proof}\n\n\\section*{4.10. Location of the maximum}\n\\addcontentsline{toc}{section}{4.10. Location of the maximum}\nFor what (integer) value of $k$ is the Poisson distribution $P(k)$ maximum?\n\n\\vspace{1em}\n\n\\begin{proof}\n    If we rewrite the Poisson distribution's expression as:\n    \\[\n        P(k) = \\frac{a^k}{k!} e^{-a} = e^{-a} \\prod_{i = 1}^k \\bigg(\\frac{a}{i}\\bigg)\n    \\] \n\n    we see that since $e^{-a}$ is just a constant, $P(k)$ attains it's maximum \n    value when the product expression is maximum. We see that we can split \n    the product: \n    \\[\n        \\prod_{i = 1}^{k} \\bigg(\\frac{a}{i}\\bigg) = \n        \\bigg(\\prod_{i = 1}^{\\lfloor a \\rfloor} \\bigg(\\frac{a}{i}\\bigg)\\bigg)\n        \\bigg(\\prod_{i = \\lfloor a \\rfloor + 1}^{k}\\bigg(\\frac{a}{i}\\bigg)\\bigg)\n    \\] \n\n    Since all the terms of the second product are in the interval $(0, 1]$, the value of the\n    second product is in $(0, 1]$ too. Therefore we have that:\n    \\[\n        \\prod_{i = 1}^{k} \\bigg(\\frac{a}{i}\\bigg) \\leq\n        \\prod_{i = 1}^{\\lfloor a \\rfloor} \\bigg(\\frac{a}{i}\\bigg)\n    \\] \n\n    By multiplying both sides by $e^{-a} > 0$ we get that for all $k$\n     \\[\n         P(k) \\leq P(\\lfloor a \\rfloor)\n    \\] \n    \n    As a result, the value $k$ for which the Poisson distribution $P(k)$ is maximum is\n    \\[\n        \\underset{k \\in \\mathbb{N}}{\\mathrm{argmax}}\\, P(k) = \\lfloor a \\rfloor\n    \\] \n\\end{proof}\n\n\\section*{4.11. Value of the maximum}\n\\addcontentsline{toc}{section}{4.11. Value of the maximum}\nFor large $a$, what approximately is the height of the bump in the Poisson $P(k)$ \nplot? You will need the result from the previous problem. $\\emph{Hint:}$ You\nwill also need to use Stirling's formula, given in Eq. (2.64) in Section 2.6.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We say in the last exercise that the mode of the Poisson distribution is \n    $\\lfloor a \\rfloor$, so the height of the plot's bump will be given by $P(\\lfloor a \\rfloor)$.\n    By taking $a \\to \\infty$, we have that the height of the bump is:\n    \\[\n        \\lim_{a \\to \\infty} P(\\lfloor a \\rfloor)\n        = \\lim_{a \\to \\infty} \\frac{a^{\\lfloor a \\rfloor} e^{-a}}{\\lfloor a \\rfloor!}\n    \\] \n\n    Since $\\lfloor a \\rfloor$ also goes to infinity, we can use Stirling's approximation \n    \\begin{equation*}\\tag{2.64}\n        n! \\approx n^n e^{-n} \\sqrt{2\\pi n}\n    \\end{equation*}\n\n    to get rid of the factorial. Our expression becomes:\n    \\[\n        \\lim_{a \\to \\infty} P(\\lfloor a \\rfloor)\n        = \\lim_{a \\to \\infty} \\frac{a^{\\lfloor a \\rfloor} e^{-a}}{\n            {\\lfloor a \\rfloor}^{\\lfloor a \\rfloor} e^{-\\lfloor a \\rfloor} \\sqrt{2\\pi{\\lfloor a \\rfloor}}}\n            = \\lim_{a \\to \\infty} \\frac{1}{\\sqrt{2\\pi \\lfloor a \\rfloor}} = 0\n    \\] \n\n    We can see that for big values of $a$, the height of the\n    bump goes to 0. Informally, we can say \n    that for big values of $a$ the maximum probability\n    is given approximately by:\n    \\[\n        \\max(P(k)) = P(\\lfloor a \\rfloor) \\approx \\frac{1}{\\sqrt{2\\pi\\lfloor a \\rfloor}}\n    \\] \n\\end{proof}\n\n\\section*{4.12. Expectation of the Poisson distribution}\n\\addcontentsline{toc}{section}{4.12. Expectation of the Poisson distribution}\nUse Eq. (3.4) to verify that the expectation value of the Poisson distribution\nequals $a$. This must be the case, of course, because $a$ is defined to be\nthe expected number of events in the given interval.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Let $X$ be a random variable that has a Poisson distribution, with $a > 0$.\n    By using Eq. (3.4), the expectation value of $X$ is given by:\n    \\[\n        E[X] = \\sum_{i = 0}^\\infty x_i P(x_i) = \\sum_{i = 1}^\\infty  i P(i) \n        = \\sum_{i = 1}^\\infty  \\frac{i e^{-a} a^i}{i!}\n        = a \\sum_{i = 1}^\\infty  \\frac{e^{-a} a^{i - 1}}{(i - 1)!}\n        = a \\sum_{i = 1}^\\infty  P(i - 1) = a \\sum_{i = 0}^\\infty P(i)\n    \\] \n\n    Since we know that the sum of probabilities must be 1, the expected value becomes:\n    \\[\n        E[X] = a\n    \\] \n \n    proving our hypothesis.\n\\end{proof}\n\n\\section*{4.13. Variance of the Poisson distribution}\n\\addcontentsline{toc}{section}{4.13. Variance of the Poisson distribution}\nAs we saw in Problem 4.12, the expectation value of the Poisson distribution\nis $\\mu = a$. Use the technique in the solution to that problem to show that\nthe variance of the Poisson distribution is $a$ (which means that the standard\ndeviation is $\\sqrt{a}$). $\\emph{Hint: }$ When finding the expectation value of\n$k^2$, it is easiest to find the expectation value of $k(k -1)$ and then\nadd on the expectation value of $k$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Let $X$ be a random variable that has a Poisson distribution, with $a > 0$. We take the proposed \n    hint and by using the linearity of expectation, we get that the variance of $X$ is given by:\n    \\[\n        \\text{Var}(X) = E[X^2] - a^2 = E[X^2 - X] + E[X] - a^2 = E[X^2 - X] + a - a^2\n    \\] \n\n    We compute $E[X^2 - X]$ separately and by using the fact that the probabilities sum\n    to 1, we obtain:\n    \\begin{align*}\n        E[X^2 - X] = \\sum_{i = 0}^\\infty (x_i^2 - x_i) P(x_i) = \\sum_{i = 2}^\\infty  (i^2 - i) P(i) \n        &= \\sum_{i = 2}^\\infty  i(i - 1) \\frac{e^{-a}a^i}{i!}\n        = a^2\\sum_{i = 2}^\\infty  \\frac{e^{-a}a^{i - 2}}{(i - 2)!} \\\\\n        &= a^2\\sum_{i = 2}^\\infty  P(i - 2) = a^2 \\sum_{i = 0}^\\infty P(i) = a^2\n    \\end{align*}\n\n    As a result, the variance becomes:\n    \\[\n        \\text{Var}(X) = E[X^2 - X] + a - a^2 = a\n    \\] \n\\end{proof}\n\n\\section*{4.14. Poisson accuracy}\n\\addcontentsline{toc}{section}{4.14. Poisson accuracy}\nIn the \"balls in boxes, again\" example on page 213, we saw that in the right plot\nin Fig. 4.20, the Poisson distribution is an excellent approximation to the exact\nbinomial distribution. But in the left plot, it is only a so-so approximation.\nWhat parameter(s) determine how good the approximation is?\n\nTo answer this, we'll define the \"goodness\" of the approximation to be the ratio\nof the Poisson expression $P_P(k)$ in Eq. (4.40) to the exact binomial expression\n$P_B(k)$ in Eq. (4.32), with both  functions evaluated at the expected value of\n$k$, namely $a = pn$, which we'll assume is an integer. The closer the ratio\n$P_P(pn)/P_B(pn)$ is to 1, the better the Poisson approximation is. Calculate\nthis ratio. You will need to use Stirling's formula, given in Eq. (2.64). You may\nassume that $n$ is large (because otherwise there wouldn't be a need to use\nthe Poisson approximation).\n\n\\vspace{1em}\n\n\\begin{proof}\n    Our ratio is given by: \n    \\[\n        \\frac{P_P(pn)}{P_B(pn)} = \\frac{e^{-pn} (pn)^{pn}}{(pn)!} \\cdot \n            \\frac{1}{\\binom{n}{pn}p^{pn}(1 - p)^{n - pn}}\n            = \\frac{e^{-pn} (pn)^{pn}}{(pn)!} \\cdot \\frac{(pn)!(n - pn)!}{n! p^{pn} (1-p)^{n - pn}} \n            = \\frac{e^{-pn} n^{pn}(n - pn)!}{n!(1 - p)^{n - pn}}\n    \\] \n\n    We consider $n$ to be large and use Sterling's formula, so the ratio becomes\n    \\begin{align*}\n        \\frac{P_P(pn)}{P_B(pn)} \n        &= \\frac{e^{-pn}n^{pn}(n - pn)^{n - pn}e^{pn - n} \\sqrt{2\\pi(n - pn)}}\n            {n^ne^{-n}(1 - p)^{n - pn}\\sqrt{2\\pi n}}\n        = \\frac{n^{pn - n}(n - pn)^{n - pn}\\sqrt{n - pn}}{(1 - p)^{n - pn}\\sqrt{n}} \\\\\n        &= \\frac{n^{pn - n} n^{n - pn}(1 - p)^{n - pn}\\sqrt{n}\\sqrt{1 - p}}{(1 - p)^{n - pn}\\sqrt{n}} \n        = \\sqrt{1 - p}\n    \\end{align*}\n\n    Therefore, the $p$ is the parameter that decides how good the approximation is.\n\\end{proof}\n\n\\section*{4.15. Bump or no bump}\n\\addcontentsline{toc}{section}{4.15. Bump or no bump}\nIn Fig. 4.21, we saw that $P(0) = P(1)$ when $a = 1$. (This is the cutoff between the distribution\nhaving or not having a bump.) Explain why this is consistent with what we noted about\nthe binomial distribution (namely, that $P(0) = P(1)$ when $p = 1 / (n + 1)$) in the example \nin Section 4.5.\n\n\\vspace{1em}\n\n\\begin{proof}\n    If we consider the equation $P(0) = P(1)$, we easily reach the conclusion that this happens for \n    $a = 1$ :\n    \\[\n        P(0) = P(1) \\iff \\frac{e^{-a}a^0}{0!} = \\frac{e^{-a}a^1}{1!} \\iff e^{-a} a = e^{-a} \\iff a = 1\n    \\] \n\n    To explain why this is consistent with the binomial distribution result, we consider\n    the Poisson distribution as a special case of the binomial distribution. \n    Therefore, we consider the same setup from Section 4.7.2 where we derived the continuous case\n    of the Poisson distribution. As a result, $\\lambda$ will be the average rate of events\n    and $\\epsilon \\to 0, n \\to \\infty$. By seeing that $p = \\lambda \\epsilon$ and $n = t \\epsilon^{-1}$, \n    and then letting $a = \\lambda t$, we concluded that:\n    \\[\n        B_{n, p}(k) = \\binom{n}{k} p^k (1 - p)^k \n        = \\binom{n}{k} (\\lambda \\epsilon)^k (1 - \\lambda \\epsilon)^{n - k} \n        = \\frac{(\\lambda t)^k e^{-\\lambda t}}{k!}\n        = \\frac{a^k e^{-a}}{k!}\n        = P(k)\n    \\] \n\n    In Section 4.5 we saw that $B_{n, p}(0) = B_{n, p}(1)$ for $p = \\frac{1}{n + 1}$. \n    By translating $p$ and $n$ with the proposed forms, the expression becomes:\n    \\[\n        B_{n, p}(0) = B_{n, p}(1) \n        \\iff \\lambda \\epsilon = \\frac{1}{t \\epsilon^{-1} + 1}\n        \\iff \\lambda = \\frac{1}{t + \\epsilon}\n            \\iff \\lambda t = \\frac{1}{1 + \\epsilon t^{-1}}\n    \\]\n\n    By using the fact that $a = \\lambda t$ and  $\\epsilon \\to 0$, we get that $P(0) = P(1)$ \n    for \n    \\[\n        a = \\lim_{\\epsilon \\to 0} \\frac{1}{1 + \\epsilon t^{-1}} = 1\n    \\] \n\\end{proof}\n\n\\section*{4.16. Typos}\n\\addcontentsline{toc}{section}{4.16. Typos}\nA hypothetical writer has an average of one type per 50 pages of work. What is the\nprobability that there are no typos in a 350-page book?\n\n\\vspace{1em}\n\n\\begin{proof}\n    If we let $X$ represent the number of mistakes, we see that this number is \n    modeled after the Poisson distribution. Since the writer makes on average 1 \n    mistake per 50 pages of work, this means that the average rate of this happening \n    is $\\lambda = \\frac{1}{50}$. We analyze the number of mistakes in a 350 page book, \n    so our the rate parameter is $a = 350\\lambda = 7$. The probability that\n    no mistakes are made is now given by:\n    \\[\n        P(X = 0) = \\frac{7^0 e^{-7}}{0!} = e^{-7} \\approx 0.00091\n    \\] \n\\end{proof}\n\n\\section*{4.17. Boxes with zero balls}\n\\addcontentsline{toc}{section}{4.17. Boxes with zero balls}\nYou randomly throw $n$ balls into 1000 boxes and note the number of boxes\nthat end up with zero balls in them. If you repeat this process a large number\nof times and observe that the average number of boxes with zero balls is 20,\nwhat is $n$? \n\n\\vspace{1em}\n\n\\begin{proof}\n    We can assume without loss of generality that the boxes are ordered.\n    Let $X_i$ represent the status of the $i$th box after 1000 throws, as\n    in empty (1) or not (0). Assuming that boxes are equally likely to be thrown in\n    (so $\\frac{1}{1000}$), the probability of the $i$th box being empty after 1 throw \n    is obviously $p = \\frac{999}{1000}$. In the case of $n$ throws, we get that\n    \\[\n        p(X_i = \\text{empty}) = p^{1000} = \\bigg(\\frac{999}{1000}\\bigg)^n\n    \\] \n\n    Now, let $Y$ be the number of empty boxes after 1000 throws. We observe that\n    in this context,\n    \\[\n        Y = X_1 + X_2 + \\ldots + X_{1000} = \\sum_{i = 1}^{1000} X_i\n    \\] \n\n    As a result, by using linearity of expectation and the fact that $X_1, X_2 \\ldots$\n    are equally distributed, we get that:\n    \\[\n        E[Y] = \\sum_{i = 1}^{1000} E[X_i] = \n        \\sum_{i = 1}^{1000} \\bigg[\\frac{n}{1000} \\cdot 0 + \\bigg(\\frac{999}{1000}\\bigg)^n \\cdot 1\\bigg]\n        = 1000 \\bigg(\\frac{999}{1000}\\bigg)^n\n    \\] \n\n    We know that the expected number of empty boxes after 1000 throws is 20,\n    which here means that $E[Y] = 20$, so:\n    \\[\n        1000\\bigg(\\frac{999}{1000}\\bigg)^n = 20\n    \\] \n\n    By dividing both sides by $1000$, taking the natural logarithm of\n    both sides and then keeping $n$ on the left side, we obtain the \n    desired result:\n     \\[\n         n = \\frac{\\ln 50}{\\ln 1000 - \\ln 999} \\approx 3910\n    \\] \n\\end{proof}\n\n\\section*{4.18. Twice the events}\n\\addcontentsline{toc}{section}{4.18. Twice the events}\n\\begin{enumerate}[(a)]\n    \\item Assume that on average, the events in a random process happen $a$ times,\n        where $a$ is large, in a given time interval $t$. With the notation\n        $P_a(k)$ representing the Poisson distribution, use Stirling's formula\n        to produce an approximate expression for the probability $P_a(a)$ that\n        exactly $a$ events happen during the time $t$.\n\n    \\item Consider the probability that exactly $\\emph{twice}$ the number of events,\n        $2a$, happen during $\\emph{twice}$ the time, $2t$. What is the ratio\n        of this probability to $P_a(a)$?\n\n    \\item Consider the probability that exactly $\\emph{twice}$ the number of events,\n        $2a$, happen during the same time $t$. What is the ratio\n        of this probability to $P_a(a)$?\n\\end{enumerate}\n\n\\vspace{1em}\n\n\\begin{proof}\n    The needed expression are easily obtained by matching the given information with\n    the corresponding Poisson expression and then using Sterling's formula to approximate\n    the factorials (which can be done because $a!$ is large).\n\n    \\begin{enumerate}[(a)]\n        \\item By simply using the expression of the Poisson distribution and\n            then using Sterling's formula, we get:\n            \\[\n                P_a(a) = \\frac{a^a e^{-a}}{a!} = \\frac{a^a e^{-a}}{a^a e^{-a} \\sqrt{2 \\pi a}} \n                = \\frac{1}{\\sqrt{2 \\pi a}}\n            \\] \n\n        \\item Because the rate of change must be constant over time, in the time $2t$ \n            we'll have on average $2a$ events, therefore the needed expression is\n            given by:\n            \\[\n                P_{2a}(2a) = \\frac{(2a)^{2a} e^{-2a}}{(2a)!} \n                = \\frac{(2a)^{2a} e^{-2a}}{(2a)^{2a} e^{-2a} \\sqrt{4\\pi a}} \n                = \\frac{1}{\\sqrt{4\\pi a}}\n            \\] \n\n            As a result, the ratio between this and $P_a(a)$ is\n             \\[\n                 \\frac{P_{2a}(2a)}{P_a(a)} = \\frac{1}{\\sqrt{2}}\n            \\] \n\n        \\item The average rate of events remains the same, so our probability is:\n            \\[\n                P_a(2a) = \\frac{a^{2a} e^{-a}}{(2a)!}\n                = \\frac{a^{2a} e^{-a}}{(2a)^{2a} e^{-2a} \\sqrt{4\\pi a}} \n                = \\bigg(\\frac{e}{4}\\bigg)^{a} \\frac{1}{\\sqrt{4\\pi a}}\n            \\] \n\n            Therefore, the ratio between this and $P_a(a)$ is\n            \\[\n                \\frac{P_a(2a)}{P_a(a)} = \\frac{1}{\\sqrt{2}} \\bigg(\\frac{e}{4}\\bigg)^a\n            \\] \n    \\end{enumerate}\n\\end{proof}\n\n\\section*{4.20. Probability of at least 1}\n\\addcontentsline{toc}{section}{4.20. Probability of at least 1}\nA million balls are thrown at random into a billion boxes.\nConsider a particular one of the boxes. What (approximately)\nis the probability that $\\emph{at least one}$ ball ends\nup in that box? Solve this by:\n\\begin{enumerate}[(a)]\n    \\item using the Poisson distribution in Eq. (4.40); you will\n        need to use the approximation in Eq. (7.9)\n\n    \\item working with probabilities from scratch; you will need\n        to use the approximation in Eq. (7.14).\n\\end{enumerate}\nNote that since the probability you found is very small, it is\nalso approximately the probability of obtaining $\\emph{exactly one}$ \nball in the given box, because multiple events are extremely rare;\nsee the discussion in the first remark in Section 4.6.2.\n\n\\vspace{1em}\n\n\\begin{proof}\n    For both solutions, we choose a box and computing the probability that\n    no ball ends up in that box. Let $X$ represent the number of balls\n    being thrown in that box after one million throws. We also assume that \n    is equally likely for a throw to go in any box, so let that probability\n    be $p = 10^{-9}$.\n\n    \\begin{enumerate}[(a)]\n        \\item Since we have a million throws and the probability that \n            a ball is thrown in our box is $p$, the average rate\n            of this happening is given by $a = 10^6 p= 10^{-3}$.\n            Therefore, the probability that no ball is thrown\n            in the chosen box is:\n            \\[\n                P(X = 0) = \\frac{e^{-a}a^0}{0!} = e^{-a} = e^{-10^{-3}}\n            \\] \n            \n            Because $10^{-3}$ is relatively small, we can use the fact that\n            $e^x \\approx 1 + x$ for small $x$, to obtain\n            \\[\n                P(X = 0) \\approx 1 - 10^{-3}\n            \\] \n\n            Finally, the probability that at least one ball is thrown\n            into the box is given by:\n            \\[\n                P(X \\geq 1) = 1 - P(0) \\approx 10^{-3}\n            \\] \n\n        \\item If we consider a throw to be represented as a Bernoulli trial where\n            a throw in our box is a failure and a throw in another box is a\n            success, then $X$ is modeled after the corresponding binomial distribution.\n            Therefore, the probability that no balls are thrown in our box is:\n            \\[\n                P(X = 0) = \\text{Bin}(0, 10^6, p) = \\binom{10^6}{0} p^0 (1 - p)^{10^6}\n                = (1 - p)^{10^6}\n            \\] \n\n            Since $p$ is relatively small, we can use the fact that $(1 + a)^n \\approx e^{na}$, for\n            a small $a$, to get that:\n            \\[\n                P(X = 0) \\approx e^{p10^6} = e^{10^{-3}}\n            \\] \n\n            Analogously to (a), we use the $e^x \\approx 1 + x$ approximation and find\n            the probability that at least one ball is thrown into the box:\n            \\[\n                P(X \\geq 1) = 1 - P(X = 0) \\approx 10^{-3}\n            \\] \n    \\end{enumerate}\n\\end{proof}\n\n\\section*{4.21. Comparing probabilities}\n\\addcontentsline{toc}{section}{4.21. Comparing probabilities}\n\\begin{enumerate}[(a)]\n    \\item A hypothetical 1000-sided die is rolled three times. What is the probability\n        that a given number (say, 1) shows up all three times?\n\n    \\item A million balls are thrown at random into a billion boxes. (So from \n        the result in Problem 4.20, the probability that exactly \n        one ball ends up in a given box is approximately 1/1000.)\n        If this process (of throwing a million balls into a billion\n        boxes) is performed three times, what (approximately) is the probability\n        that exactly one ball lands in a given box all three times?\n        (It can be a different ball each time.)\n\n    \\item A million balls are thrown at random into a billion boxes. This process\n        is performed a $\\emph{single}$ time. What (approximately) is the \n        probability that exactly three balls end up in a given box?\n        Solve this from scratch by using a counting argument.\n\n    \\item Solve part (c) by using the Poisson distribution.\n\n    \\item The setups in parts (b) and (c) might seem basically the same,\n        because both setups involve three balls ending up in the given\n        box, and there is a 1/b = 1/10$^9$ probability that any given ball\n        ends up in the given box. Give an intuitive explanation\n        for why the answers differ.\n\\end{enumerate}\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item Considering that each die side is equally likely to be rolled\n            with a probability of 1/1000, the probability that a given\n            number shows in all three throws is simply:\n            \\[\n                p_1 = \\bigg(\\frac{1}{1000}\\bigg)^3 = 10^{-9}\n            \\] \n\n        \\item Since we know that the Problem 4.20 that the probability\n            of exactly one ball ending up in a given box is approximately\n            1/1000, using the same heuristic as in (a), the probability\n            that this is performed in all three times is:\n            \\[\n                p_2 = \\bigg(\\frac{1}{1000}\\bigg)^3 = 10^{-9}\n            \\] \n        \\item Without loss of generality we assume that each box has an \n            index. Therefore, a ball throw is equivalent with choosing\n            one such index. Since each process consists of choosing one\n            million box indexes with repetition, the number of total possible outcomes\n            of the process is given by:\n            \\[\n                T = \\binom{10^9 + 10^6 - 1}{10^6}\n            \\] \n\n            Now, we compute the number of process outcomes where exactly\n            three balls end up in a given box. Because the order of throws\n            does not matter, this number is equivalent with the number of process outcomes \n            where we \"remove\" the chosen box and consider that three of our throws were in that box.\n            So,\n            \\[\n                T_3 = \\binom{10^9 - 1 + 10^6 - 3 - 1}{10^6 - 3} = \\binom{10^9 + 10^6 - 5}{10^6 - 3}\n            \\] \n\n            As a result, the probability that exactly 3 balls are thrown into a specific\n            box is given by:\n            \\[\n                p_3 = \\frac{T_3}{T} = \\binom{10^9 + 10^6 - 5}{10^6 - 3} \\binom{10^9 + 10^6 - 1}{10^6}^{-1}\n                    \\approx 9.96 \\cdot 10^{-10}\n            \\] \n\n        \\item We throw one million balls and the probability that one throw goes in a specific box\n            is 10$^{-9}$, so the average rate of event is $a = 10^6 \\cdot 10^{-9} = 10^{-3}$.\n            Then, the probability that exactly 3 balls are thrown in a given box is simply:\n            \\[\n                P(3) = \\frac{a^3 e^{-a}}{3!} = \\frac{1}{6} 10^{-9} e^{-10^{-3}} \\approx 1.665 \\cdot 10^{-10}\n            \\] \n    \\end{enumerate}\n\\end{proof}\n\n\\section*{4.22. Area under a Gaussian curve}\n\\addcontentsline{toc}{section}{4.22. Area under a Gaussian curve}\nShow that the area (from $-\\infty$ to $\\infty$ ) under the Gaussian\ndistribution, $f(x) = \\sqrt{b/\\pi} e^{-bx^2}$, equals 1. That is,\nshow that the total probability equals 1. (We have set\n$\\mu = 0$ for convenience, since $\\mu$ doesn't affect\nthe total area.) There is a very sneaky way to do this.\nBut since it's completely out of the blue, we'll give\na hint: Calculate the $\\emph{square}$ of the desired integral by multiplying\nit by the integral of $\\sqrt{b/\\pi} e^{-by^2}$. Then make use of a change \nof variables from Cartesian to polar coordinates, to convert\nthe Cartesian double integral into a polar double integral.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The area under the curve of the Gaussian is given by:\n    \\[\n        I = \\int_{-\\infty}^\\infty f(x) dx = \\sqrt{\\frac{b}{\\pi}} \\int_{-\\infty}^\\infty e^{-bx^2} dx\n    \\] \n    We take the proposed hint and obtain that:\n    \\[\n        I^2 = \\bigg(\\sqrt{\\frac{b}{\\pi}} \\int_{-\\infty}^\\infty e^{-bx^2} dx\\bigg)\n            \\bigg(\\sqrt{\\frac{b}{\\pi}} \\int_{-\\infty}^\\infty e^{-by^2} dy\\bigg)\n        = \\frac{b}{\\pi} \\int_{-\\infty}^\\infty \\int_{-\\infty}^\\infty e^{-b(x^2 + y^2)} dxdy\n    \\] \n    Now, we convert to polar coordinates by using the substitutions\n    $x = r\\sin \\theta, y = r\\cos \\theta$ and get:\n    \\[\n        I^2 = \\frac{b}{\\pi} \\int_0^{2\\pi} \\int_0^\\infty e^{-br^2} r drd\\theta\n    \\] \n    We compute the inner integral separately by using the substitution\n    $t = r^2$, so:\n    \\[\n        \\int_0^\\infty e^{-br^2}r dr \n        = \\frac{1}{2} \\int_0^\\infty e^{-bt} dt \n        = -\\frac{e^{-bt}}{2b} \\bigg|_0^\\infty\n        = \\frac{1}{2b}\n    \\] \n    Our expression becomes:\n    \\[\n        I^2 = \\frac{1}{2\\pi} \\int_0^{2\\pi} d\\theta = 1\n    \\] \n    Therefore, we proved that the Gaussian distribution is normalized:\n    \\[\n        I = \\int_0^\\infty f(x) = 1\n    \\] \n\\end{proof}\n\n\\section*{4.23. Variance of the Gaussian distribution}\n\\addcontentsline{toc}{section}{4.23. Variance of the Gaussian distribution}\nShow that the variance of the second Gaussian expression in Eq. (4.42)\nequals $\\sigma^2$. You may assume that $\\mu = 0$ (because $\\mu$ doesn't\naffect the variance), in which case the expression for the variance\nin Eq. (3.19) becomes $E(X^2)$. And then by the reasoning in\nProblem 4.2, this expectation value is $\\int x^2f(x)dx$. So the\ntask of this problem is to evaluate this integral. The straightforward method\nis to use integration by parts.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We follow the hint and use integration by parts, so:\n    \\begin{align*}\n        E[X^2] \n        = \\int_{-\\infty}^\\infty x^2 f(x) dx \n        = \\sqrt{\\frac{b}{\\pi}} \\int_{-\\infty}^\\infty x^2 e^{-bx^2} dx\n        &= \\sqrt{\\frac{b}{\\pi}} \\int_{-\\infty}^\\infty x \\big(xe^{-bx^2}\\big) dx\n        = \\sqrt{\\frac{b}{\\pi}} \\int_{-\\infty}^\\infty x \\bigg(-\\frac{1}{2b}e^{-bx^2}\\bigg)' dx \\\\\n        &= -\\frac{1}{2} \\sqrt{\\frac{b}{\\pi}} xe^{-bx^2} \\bigg|_{-\\infty}^\\infty \n            + \\frac{1}{2b} \\sqrt{\\frac{b}{\\pi}} \\int_{-\\infty}^\\infty e^{-bx^2} dx\n    \\end{align*}\n\n    One can easily prove using L'Hopital's rule that \n    \\[\n        \\lim_{x \\to \\infty} xe^{-bx^2} = \\lim_{x \\to -\\infty} xe^{-bx^2} = 0\n    \\] \n\n    Therefore the first term in the result is 0. Since we know that\n    the Gaussian distribution is normalized from Problem 4.22, we obtain that\n    \\[\n        E[X^2] = \\frac{1}{2b} \\sqrt{\\frac{b}{\\pi}} \\int_{-\\infty}^\\infty e^{-bx^2} dx \n        = \\frac{1}{2b} \n        = \\sigma^2\n    \\] \n\\end{proof}\n", "meta": {"hexsha": "dccd2e97e2d4eca1dc1cc5cd0a0c0401aec15df7", "size": 42827, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter4_distributions.tex", "max_stars_repo_name": "thesstefan/morin_solutions", "max_stars_repo_head_hexsha": "0053de71a3743e99c94cee5fad0fd0f75aefa96b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/chapter4_distributions.tex", "max_issues_repo_name": "thesstefan/morin_solutions", "max_issues_repo_head_hexsha": "0053de71a3743e99c94cee5fad0fd0f75aefa96b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter4_distributions.tex", "max_forks_repo_name": "thesstefan/morin_solutions", "max_forks_repo_head_hexsha": "0053de71a3743e99c94cee5fad0fd0f75aefa96b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.9558676028, "max_line_length": 133, "alphanum_fraction": 0.5771592687, "num_tokens": 14317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384595, "lm_q2_score": 0.8947894639983208, "lm_q1q2_score": 0.8070291257976878}}
{"text": "\\section{Sets and set notation}\n\nA set is a collection\\index{set notation} of things called elements.\nFor example $\\set{1,2,3,8} $\nwould be a set consisting of the elements 1,2,3, and 8. To indicate that $3$\nis an element of $\\set{1,2,3,8}$, it is customary to write $3\\in\n\\set{1,2,3,8}$. We can also indicate when an element is not in a set,\nby writing $9\\notin \\set{1,2,3,8} $ which says that $9$ is\nnot an element of $\\set{1,2,3,8}$. Sometimes a rule specifies a\nset. For example you could specify a set as all integers larger than $2$.\nThis would be written as $S=\\set{x\\in \\Z:x>2}$. This\nnotation says: $S$ is the set of all integers, $x$, such that $x>2$.\n\nSuppose $A$ and $B$ are sets with the property that every element of $A$ is an\nelement of $B$. Then we say that $A$ is a subset of $B$. For example, $\\set{\n1,2,3,8} $ is a subset of $\\set{1,2,3,4,5,8}$. In symbols, we write\n$\\set{1,2,3,8} \\subseteq \\set{1,2,3,4,5,8}$. It is\nsometimes said that ``$A$ is contained in $B$\" or even ``$B$ contains $A$\".\nThe same statement about the two sets may also be written as $\\set{\n1,2,3,4,5,8} \\supseteq \\set{1,2,3,8}$.\n\nWe can also talk about the {\\em union}\\index{union} of two sets, which we write as $A \\cup B$. This is the set consisting of everything which is an\nelement of at least one of the sets, $A$ or $B$. As an example of the union\nof two sets, consider $\\set{1,2,3,8} \\cup \\set{3,4,7,8} =\\set{\n1,2,3,4,7,8}$. This set is made up of the numbers which are in at least\none of the two sets.\\index{$\\cup$}\n\nIn general\n\\begin{equation*}\nA\\cup B = \\set{x:x\\in A\n\\text{ or }x\\in B}\n\\end{equation*}\nNotice that an element which is in {\\em both} $A$ and $B$ is also in the\nunion, as well as elements which are in only one of $A$ or $B$.\n\nAnother important set is the intersection\\index{intersection}\\index{$\\cap$} of two sets $A$ and $B$, written $A \\cap B$. This set consists of everything which is in\n{\\em both} of the sets. Thus $\\set{1,2,3,8} \\cap \\set{3,4,7,8}\n=\\set{3,8} $ because $3$ and $8$ are those elements the two sets\nhave in common. In general,\n\\begin{equation*}\nA\\cap B =  \\set{x:x\\in A\\text{ and }x\\in B}\n\\end{equation*}\n\nIf $A$ and $B$ are two sets, $A\\setminus B$\\index{$\\setminus$} denotes the set of things which\nare in $A$ but not in $B$. Thus\n\\begin{equation*}\nA\\setminus B =  \\set{x\\in A:x\\notin B}\n\\end{equation*}\nFor example, if $A = \\set{1,2,3,8 }$ and $B = \\set{3,4,7,8 }$, then $A \\setminus B = \\set{1,2,3,8} \\setminus\n\\set{3,4,7,8 } =\\set{1,2 }$.\n\nA special set which is very important in mathematics is the empty set\\index{empty set} denoted by $\\emptyset$. The empty set, $\\emptyset$, is\ndefined as the set which has no elements in it. It follows that the empty set is a subset of every set.\nThis is true because if it were not so, there would have to exist a set $A$, such that $\\emptyset $\nhas something in it which is not in $A$. However, $\\emptyset $ has nothing\nin it and so it must be that $\\emptyset \\subseteq A$.\n\nWe can also use brackets to denote sets which are intervals of numbers. Let $a$ and $b$ be real numbers. Then\n\n\\begin{itemize}\n\\item $[a,b] = \\set{x \\in \\R \\mid a\\leq x\\leq b}$.\n\\item $[a,b) = \\set{x \\in \\R \\mid a\\leq x<b}$.\n\\item $(a,b] = \\set{x \\in \\R \\mid a<x\\leq b}$.\n\\item $(a,b) = \\set{x \\in \\R \\mid a<x<b}$.\n\\item $[a,\\infty) = \\set{x \\in \\R \\mid a\\leq x}$.\n\\item $(-\\infty,a] = \\set{x \\in \\R \\mid x\\leq a}$.\n\\item $(a,\\infty) = \\set{x \\in \\R \\mid a<x}$.\n\\item $(-\\infty,a) = \\set{x \\in \\R \\mid x<a}$.\n\\end{itemize}\n\nThese sorts of sets of real\nnumbers are called intervals. The two points $a$ and $b$ are called\nendpoints, or bounds, of the interval. In particular, $a$ is the {\\em lower bound }  while $b$ is the {\\em upper bound } of the above\nintervals, where applicable.\\index{intervals!notation} Other intervals such as $(-\\infty ,b) $\nare defined by analogy to what was just explained.\n In general, the curved\nparenthesis, $($, indicates the end point is not included in the interval, while\nthe square parenthesis, $[$, indicates this end point is included. The reason that\nthere will always be a curved parenthesis next to $\\infty $ or $-\\infty $ is\nthat these are not real numbers and cannot be included in the interval in the way a real number can.\n\nTo illustrate the use of this notation relative to intervals consider three\nexamples of inequalities. Their solutions will be written in the interval notation\njust described.\n\n\\begin{example}{Solving an inequality}{solving-inequality1}\nSolve the inequality $2x+4\\leq x-8$.\n\\end{example}\n\n\\begin{solution}\nWe need to find $x$ such that $2x+4\\leq x-8$. Solving for $x$, we see that\n$x\\leq -12$ is the answer. This is written in terms of an interval as $(-\\infty ,-12]$.\n\\end{solution}\n\nConsider the following example.\n\n\\begin{example}{Solving an inequality}{solving-inequality2}\nSolve the inequality $(x+1) (2x-3) \\geq0$.\n\\end{example}\n\n\\begin{solution}\nWe need to find $x$ such that $(x+1) (2x-3) \\geq0$.\nThe solution is given by  $x\\leq -1$ or $x\\geq \\frac{3}{2}$. Therefore,\n$x$ which fit into either of these intervals gives a solution. In terms of set notation this is denoted by $(-\\infty ,-1]\\cup\n[ \\vspace{0.05in}\\frac{3}{2},\\infty )$.\n\\end{solution}\n\nConsider one last example.\n\n\\begin{example}{Solving an inequality}{solving-inequality3}\nSolve the inequality $x (x+2) \\geq-4$.\n\\end{example}\n\n\\begin{solution}\nThis inequality is true for any value of $x$ where $x$ is a real number. We can write the solution as $\\R$ or $(\n-\\infty ,\\infty)$.\n\\end{solution}\n\nIn the next section, we examine another important mathematical concept.\n", "meta": {"hexsha": "21ef5ef1bf4e10665c2ee3010197ebd5a787c829", "size": 5562, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/prerequisiteSets.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/content/prerequisiteSets.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/content/prerequisiteSets.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 46.35, "max_line_length": 164, "alphanum_fraction": 0.687162891, "num_tokens": 1884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747657, "lm_q2_score": 0.8947894583870633, "lm_q1q2_score": 0.8070291230957175}}
{"text": "\\subsection{Integer Linear Programming Model}\n\n\\subsubsection{Decision Variables}\n\n\\begin{equation}\n    \\label{eq:decision-variables}\n    \\varE =  \\begin{cases}\n      1 &, \\solutionE \\in \\solution \\\\\n      0 &, \\solutionE \\notin \\solution\n   \\end{cases}\n\\end{equation}\n\n\\subsubsection{Mathematical Model}\n\n\\begin{align}\n    \\label{eq:ILP-objective}\n    \\max\\limits_{\\solution \\subseteq \\vertices}\n        & \\Sum{\\solutionE \\in \\solution}{}{\\varE} \\\\\n    s.t.\n    \\label{eq:ILP-capacity-constraint}\n    & \\Sum{\\solutionE \\in \\solution}{}{\\varE \\weightE} \\leqslant \\maximumWeight \\\\\n    \\label{eq:ILP-order-constraint}\n    & \\var_{\\solutionE} \\leqslant \\var_{\\solutionEp} \\quad \\forall \\solutionEp \\partialLower \\solutionE \\\\\n    \\label{eq:ILP-binary-constraint}\n    & \\var \\in \\varDomain\n\\end{align}\n\n\\eqref{eq:ILP-objective} is the objective function: maximize the number of vertices in the solution.\n\\eqref{eq:ILP-capacity-constraint} is the Capacity-Constraint of \\eqref{eq:capacity-constraint}.\n\\eqref{eq:ILP-order-constraint} is the Precedence-Constraint of \\eqref{eq:precedence-constraint}: if a vertex $\\solutionE$ is in the solution, then all vertices $\\solutionEp$ for which there is a path from $\\solutionE$ must also be in the solution.\n", "meta": {"hexsha": "28d412597a5fd2a5775d50e843abcfdbfb8c0944", "size": 1247, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project/report/textual/ILP_model.tex", "max_stars_repo_name": "lucasguesserts/MO824A-combinatorial-optimization", "max_stars_repo_head_hexsha": "a88569e4496c0ed4f89a4e8bac7ab8f42f6cb7d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "project/report/textual/ILP_model.tex", "max_issues_repo_name": "lucasguesserts/MO824A-combinatorial-optimization", "max_issues_repo_head_hexsha": "a88569e4496c0ed4f89a4e8bac7ab8f42f6cb7d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project/report/textual/ILP_model.tex", "max_forks_repo_name": "lucasguesserts/MO824A-combinatorial-optimization", "max_forks_repo_head_hexsha": "a88569e4496c0ed4f89a4e8bac7ab8f42f6cb7d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.2258064516, "max_line_length": 248, "alphanum_fraction": 0.7105052125, "num_tokens": 376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.965899575269305, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.806993185719375}}
{"text": "\\section{Game Theory}\r\n\\subsection{Two-person Zero-sum Games}\r\nConsider a game where there are two players called Player I and Player II.\r\nPlayer I has $m$ choices of strategies labeled by $i\\in\\{1,\\ldots,m\\}$ and Player II has $n$ choices of strategies $j\\in\\{1,\\ldots,n\\}$.\r\nWe assume that the game is zero-sum, i.e. if Player I chooses strategy $i$ and Player II chooses strategy $j$, then Player I is paid $a_{i,j}$ and Player II is paid $-a_{i,j}$.\r\nSo the net payment across the game is zero.\r\nThe matrix $A=(a_{i,j})$ is called the payoff matrix of the game.\r\nThis is an $m\\times n$ matrix.\r\nAssume that both players want to maximise their payoff and they know the other wants it too.\r\n\\footnote{And they know the other knows they want it, and they know the other knows they know the other wants it, etc.}\\\\\r\nPlayer I might want to solve the maximisation of $\\min_ja_{ij}$ subject to $i\\in\\{1,\\ldots,m\\}$ and Player II to solve the minimisation of $\\max_ia_{ij}$ subject to $j\\in\\{1,\\ldots,n\\}$.\r\n\\begin{example}\r\n    Consider\r\n    $$A=\\begin{pmatrix}\r\n        1&2\\\\\r\n        3&4\r\n    \\end{pmatrix}$$\r\n    Then obviously Player I will pick $i=2$ and Player II will pick $j=1$.\r\n    This is independent of who playing first.\r\n\\end{example}\r\nSuch a point $(2,1)$ in the above example with the said property is called a saddle point of the matrix.\r\n\\begin{definition}\r\n    A saddle point of a payoff matrix $A$ is a pair of strategies $(i,j)$ with the property\r\n    $$a_{i,j}=\\max_{i'}\\min_{j'}a_{i',j'}=\\min_{j'}\\max_{i'}a_{i',j'}$$\r\n    If a payoff matrix $A$ has saddle point $(i,j)$, then $a_{i,j}$ is called the value of the game.\r\n\\end{definition}\r\nNot all payoff matrices have a saddle point, an easy example is\r\n$$A=\\begin{pmatrix}\r\n    4&2\\\\\r\n    1&3\r\n\\end{pmatrix}$$\r\nwhere $\\max_i\\min_ja_{i,j}=2\\neq 3=\\min_j\\max_ia_{i,j}$.\r\n\\subsection{Pure and Mixed Strategies}\r\nOften, the game has the property that the players choose their strategies simultaneously.\r\nThe idea to analyse these games is to randomise the strategies.\r\n\\begin{definition}\r\n    A mixed strategy is an assignment of probabilities to each of the individual strategies.\r\n    A pure strategy is a mixed strategies assigning $1$ to one particular strategy and $0$ to all others.\r\n\\end{definition}\r\nWe use the notation that Player I plays strategy $i$ with probability $p_i$ and Player II plays strategy $j$ with probability $q_j$.\r\nTherefore Player I would want to maximise\r\n$$\\min_j\\mathbb E[\\text{payout}|\\text{Player II picks strategy $j$}]$$\r\nwhich translates to maximising\r\n$$\\min_j\\sum_{i=1}^mp_ia_{i,j}$$\r\nsubject to \r\n$$\\sum_{i=1}^mp_i=1,\\forall i\\in\\{1,\\ldots,m\\},p_i\\ge 0$$\r\nWe can turn this into a linear program.\r\nIntroducing $e=(1,\\ldots,1)^\\top$ (dimension implied by context), then the problem can be written as maximising $v\\in\\mathbb R$ subject to $A^\\top p\\ge ve,e^\\top p=1,p\\ge 0$.\r\nSimilarly, the optimisation problem for Player II can be written as minimising $w$ subject to $Aq\\le we, e^\\top q=1,q\\ge 0$.\\\\\r\nUnsurprisingly, these two problems are naturally dual to each other.\r\nIndeed, one can observe that the Lagrangian of Player I is\r\n\\begin{align*}\r\n    L(p,v,z,q,w)&=v+q^\\top(A^\\top p-z-ve)+w(1-p^\\top e)\\\\\r\n    &=w+v(1-q^\\top e)+p^\\top(Aq-we)-z^\\top q\r\n\\end{align*}\r\nwhere $z$ is the slack variable.\r\nSo the feasible Lagrange multipliers are constrained by $q\\ge 0,Aq\\le we,e^\\top q=1$ and $\\sup L=w$.\\\\\r\nBy the fundamental theorem of linear programs, $(p,v)$ is optimal iff there is some $(q,w)$ such that both tuples are feasible and\r\n$$(Ap-we)^\\top p=0=q(A^\\top p-ve)$$\r\nWhere we see $wp^\\top e=vq^\\top e$, so $v=w$ in optimal case as one would expect.\r\n\\begin{theorem}[Fundamental Theorem of Matrix Games]\r\n    The mixed row strategy $p$ is optimal for Player I iff there exists a mixed column strategy $q$ for Player II and $v\\in\\mathbb R$ such that:\\\\\r\n    1. $A^\\top p\\ge ve,e^\\top p=1,p\\ge 0$.\\\\\r\n    2. $Aq\\le ve,e^\\top q=1,q\\ge 0$.\\\\\r\n    3. $v=p^\\top Aq$.\r\n    In this case, $(p,v)$ is optimal for the problem of Player I and $(q,v)$ is optimal for Player II.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\nThe value $v$ above is called the value of the game.\r\nHence, for optimal mxied strategies, complementary slackness ensures that if Player II plays $j$ with positive probability, then the conditional expected payoff given Player II plays $j$ equals the value of the game.\r\nAn analogous statement works the other way around.\r\nIn other words,\r\n$$\\begin{cases}\r\n    q_j>0\\implies (A^\\top p)_j=v\\\\\r\n    p_i>0\\implies (Aq)_i=v\r\n\\end{cases}$$\r\n\\begin{definition}\r\n    A game is symmetric if the payoff matrix is antisymmetric.\r\n    That is $A^\\top=-A$.\r\n\\end{definition}\r\n\\begin{example}\r\n    The rock-paper-scissors game\r\n    $$\\begin{pmatrix}\r\n        0&-1&1\\\\\r\n        1&0&-1\\\\\r\n        -1&1&0\r\n    \\end{pmatrix}$$\r\n    is symmetric.\r\n\\end{example}\r\n\\begin{theorem}\r\n    A symmetric game has zero value.\r\n\\end{theorem}\r\nThis is very intuitive by symmetry.\r\nWe can also make use of our oven-ready fundamental theorem.\r\n\\begin{proof}\r\n    Suppose $(p,v,q)$ satisfy the (necessary) conditions of optimality, then by antisymmetry of $A$, the tuple $(q,-v,p)$ satisfies the (sufficient) condition of optimality.\r\n    Hence $v=-v\\implies v=0$.\r\n\\end{proof}\r\n\\subsection{Finding Optimal Strategies}\r\nIf the game admits a saddle point $(i,j)$, then by definition the pure strategy $i$ is optimal for Player I and the strategy $j$ is optimal for Player II, consequently the value of the game is $a_{i,j}$.\r\nOtherwise, we reduce the game by eliminating dominating strategies.\r\nA row $i$ dominates $i'$ is $a_{i,j}\\ge a_{i',j}$ for any $j$, so if a row $i'$ is dominated by some other row, then Player I will never play strategy $i'$.\r\nSimilarly if there is some $j,j'$ with $a_{i,j}\\le a_{i,j'}$ for any $i$, then Player II will never play $j'$.\r\n\\begin{example}\r\n    Consider the payoff matrix\r\n    $$A=\\begin{pmatrix}\r\n        2&3&4&2\\\\\r\n        3&1&1/2&4\\\\\r\n        1&3&2&3\r\n    \\end{pmatrix}$$\r\n    One can check that there is no saddle point.\r\n    Also, the first column dominates the fourth column, so Player II will never play the fourth column.\r\n    After eliminating that, the first row dominates the third row, so the third row is eliminated too, leaving a modified payoff matrix\r\n    $$A'=\\begin{pmatrix}\r\n        2&3&4\\\\\r\n        3&1&1/2\r\n    \\end{pmatrix}$$\r\n    So the optimal strategy $p$ of Player I  is of the form $(p_1,1-p_1,0)^\\top$.\\\\\r\n    Now the region $(A')^\\top p'\\ge ve$ (where $p'=(p_1,1-p_1)^\\top$ are the remaining relevant strategies) is given by\r\n    $$\\begin{cases}\r\n        2p_1+3(1-p_1)\\ge v\\implies v\\le 3-p_1\\\\\r\n        3p_1+(1-p_1)\\ge v\\implies v\\le 1+2p_1\\\\\r\n        4p_1+(1-p_1)/2\\ge v\\implies v\\le (1+7p_1)/2\r\n    \\end{cases}$$\r\n    So by sketching the graph of $v$ against $p_1$, we find that the maximum $v$ occurs at $p_1=2/3$ and the optimal strategy of Player I is $p=(2/3,1/3,0)^\\top$, and the value of the game is $v=7/3$.\\\\\r\n    By complementary slackness $q_3=0$ as the third constraint is not tight.\r\n    So $q=(q_1,1-q_1,0,0)^\\top$ for some probability $q_1$.\r\n    As $p_1=2/3>0$, the first dual constraint is binding by complementary slackness, so\r\n    $$2q_1+3(1-q_1)=7/3\\implies q_1=2/3$$\r\n    Therefore $q=(2/3,1/3,0,0)^\\top$.\r\n\\end{example}\r\nIf it does not get clear after using these tricks, one can always use the simplex algorithm.\r\nIf $\\min_{i,j}a_{i,j}>0$ then we know $v$ is strictly positive, hence we can rewrite the problem of Player I as maximising $v$ subject to $A^\\top x\\ge e,e^\\top x=1/v,x\\ge 0$ where $x=p/v$.\r\nThis is equivalent to minimising $e^\\top x$ subject to $A^\\top x\\ge e,x\\ge 0$ which is a form where we can apply simplex algorithm to.\r\nNote that its dual problem is maximising $e^\\top y$ subject to $Ay\\le e,y\\ge 0$ which is in a form for Phase I of the two-phase algorithm.\\\\\r\nIf instead $\\min_{i,j}a_{i,j}\\le 0$, we can still use the same idea.\r\nJust find some $k$ such that $a'_{i,j}=a_{i,j}+k>0$ for all $i,j$ and roll out the same algorithm on $A'=(a'_{i,j})$.\r\nThen the optimal strategy of $A,A'$ would be the same and the new value $v'$ would satisfy $v=v'-k$ where $v$ is the value of the original game.\r\n\\begin{example}\r\n    Consider the game of Rock-Paper-Scissors, i.e.\r\n    $$A=\\begin{pmatrix}\r\n        0&-1&1\\\\\r\n        1&0&-1\\\\\r\n        -1&1&0\r\n    \\end{pmatrix}$$\r\n    Then we consider the modified game\r\n    $$A'=\\begin{pmatrix}\r\n        2&1&3\\\\\r\n        3&2&1\\\\\r\n        1&3&2\r\n    \\end{pmatrix}$$\r\n    where $k=2$.\r\n    So the problem of Player II is to maximise $y_1+y_2+y_3$ subject to\r\n    $$\\begin{cases}\r\n        2y_1+y_2+3y_3\\le 1\\\\\r\n        3y_1+2y_2+y_3\\le 1\\\\\r\n        y_1+3y_2+2y_3\\le 1\\\\\r\n        y_1,y_2,y_3\\ge 0\r\n    \\end{cases}$$\r\n    So the initial simplex tableau is\r\n    $$\\begin{array}{c|cccccc|c}\r\n        &&&&\\ast&\\ast&\\ast&\\\\\r\n        &y_1&y_2&y_3&z_1&z_2&z_3&\\\\ \\hline\r\n        z_1&2&1&3&1&0&0&1\\\\\r\n        z_2&3&2&1&0&1&0&1\\\\\r\n        z_3&1&3&2&0&0&1&1\\\\ \\hline\r\n        \\text{Payoff}&1&1&1&0&0&0&0\r\n    \\end{array}$$\r\n    and the final tableau would be\r\n    $$\\begin{array}{c|cccccc|c}\r\n        &\\ast&\\ast&\\ast&&&&\\\\\r\n        &y_1&y_2&y_3&z_1&z_2&z_3&\\\\ \\hline\r\n        y_3&0&0&1&7/18&-5/18&1/18&1/6\\\\\r\n        y_1&1&0&0&1/18&7/18&-5/18&1/6\\\\\r\n        y_2&0&1&0&-5/18&1/18&7/18&1/6\\\\ \\hline\r\n        \\text{Payoff}&0&0&0&-1/6&-1/6&-1/6&-1/2\r\n    \\end{array}$$\r\n    Therefore $v'=2$, so $v=0$.\r\n\\end{example}", "meta": {"hexsha": "bbcf02ef1e9b0a7295f448e0239319e14b9e5565", "size": 9452, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/game.tex", "max_stars_repo_name": "david-bai-notes/IB-Optimisation", "max_stars_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4/game.tex", "max_issues_repo_name": "david-bai-notes/IB-Optimisation", "max_issues_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4/game.tex", "max_forks_repo_name": "david-bai-notes/IB-Optimisation", "max_forks_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.2209944751, "max_line_length": 217, "alphanum_fraction": 0.650973339, "num_tokens": 3215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118215, "lm_q2_score": 0.8856314753275019, "lm_q1q2_score": 0.8069694308662548}}
{"text": "\\section{Metric Space}\r\n\\begin{definition}\r\n    Let $M$ be an arbitrary set, a metric on $M$ is a function $d:M\\times M\\to\\mathbb R_{\\ge 0}$ such that the following properties hold:\\\\\r\n    1. $\\forall x,y\\in M,d(x,y)=0\\iff x=y$.\\\\\r\n    2. $\\forall x,y\\in M,d(x,y)=d(y,x)$.\\\\\r\n    3. $\\forall x,y,z\\in M, d(x,y)+d(y,z)\\ge d(z,x)$.\\\\\r\n    The couple $(M,d)$ is called a metric space.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. Let $M$ be $\\mathbb R$ or $\\mathbb C$, and $d(x,y)=|x-y|$ is called the usual metric on those sets.\\\\\r\n    2. Take $M=\\mathbb R^n$ or $\\mathbb C^n$, then\r\n    $$d((x_1,\\ldots,x_n),(y_1,\\ldots,y_n))=\\sqrt{|x_1-y_1|^2+\\ldots+|x_n-y_n|^2}$$.\r\n    This is called the $\\ell^2$ metric.\\\\\r\n    3. Take the same $M$, then we can also have the $\\ell^1$ metric where\r\n    $$d((x_1,\\ldots,x_n),(y_1,\\ldots,y_n))=|x_1-y_1|+\\ldots+|x_n-y_n|$$\r\n    4. Also the same $M$, we have the $\\ell^\\infty$ metric where\r\n    $$d((x_1,x_2,\\ldots,x_n),(y_1,y_2,\\ldots,y_n))=\\max_{i}|x_i-y_i|$$\r\n    5. We can have the $\\ell^p$ metric for $p\\ge 1$ where\r\n    $$d((x_1,\\ldots,x_n),(y_1,\\ldots,y_n))=\\sqrt[p]{|x_1-y_1|^p+\\ldots+|x_n-y_n|^p}$$\r\n    6. Let $S$ be a set and $M=\\ell_\\infty S$ be the set of bounded scalar function on $S$.\r\n    The metric we can take is the uniform metric $d(f,g)=\\sup_S|f-g|$, which is well-defined since $f,g$ are bounded.\\\\\r\n    7. Let $M$ be any set, then define\r\n    $$d(x,y)=\\begin{cases}\r\n        1\\text{, if $x=y$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    This is called the \\textit{discrete metric} and the space $(M,d)$ the discrete metric space.\\\\\r\n    8. Let $G$ be a group that is generated by a symmetric set $S$.\r\n    Define $d(x,y)$ be the least integer $n\\ge 0$ such that $n$ is the least number of generators to get from $X$ to $y$.\\\\\r\n    This develops to the discipline called geometric group theory.\\\\\r\n    9. Suppose $G$ is a connected (finite) graph, then we can define the distance between two vertices $x,y$ to be the length of the shortest path from $x$ to $y$.\\\\\r\n    10. Riemannian metric in geometry.\\\\\r\n    11. Take $M$ to be the integers and we fix a prime $p$.\r\n    We can define the $p$-adic metric $d_p(x,y)$ to be $0$ if $x=y$ and $\\|x-y\\|_p=p^{-n}$ where $n$ is the greatest power of $p$ in the prime factorisation of $|x-y|$.\r\n    It is obvious that it is a metric.\r\n    The metric space $(\\mathbb Z,d_p)$ is called the $p$-adic integers.\\\\\r\n    12. Let $M$ be the set of all functions from $\\mathbb N$ to $\\mathbb R$, that is, the set of all sequences.\r\n    So for $x=(x_n),y=(y_n)$, we define $d(x,y)=\\sum_{n=0}^\\infty 2^{-n}\\min\\{1,|x_n-y_n|\\}$.\r\n\\end{example}\r\nAs in before, we can construct new objects from old.\r\n\\begin{definition}\r\n    Let $(M,d)$ be a metric space and $N\\subseteq M$, then $(N,d|_{N\\times N})$ is a metric space and is called the metric subspace of $(M,d)$.\r\n    Sometimes we denote $(N,d|_{N\\times N})$ by $(N,d)$.\r\n\\end{definition}\r\n\\begin{example}\r\n    $C[0,1]$ be the set of real continuous functions on the unit interval having the uniform metric is a subspace of $l_\\infty[0,1]$.\r\n\\end{example}\r\nNote that there are other metrics on $C[0,1]$, for example\r\n$$d(f,g)=\\int_0^1|f(x)-g(x)|\\,\\mathrm dx$$\r\nWe also have the $L^2$ metric\r\n$$d(f,g)=\\sqrt{\\int_0^1|f(x)-g(x)|\\,\\mathrm dx}$$\r\nNote that the $L^\\infty$ metric is the uniform metric.\r\n\\begin{definition}\r\n    Let $(M,d),(N,d')$ be two metric spaces, we can define the metric product space by taking the underlying set $M\\times N$ and the metric\r\n    $$d_p((m_1,n_1),(m_2,n_2))=(d(m_1,m_2)^p+d'(n_1,n_2)^p)^{1/p}$$\r\n    for some $p\\ge 1$ or\r\n    $$d_\\infty((m_1,n_1),(m_2,n_2))=\\max(\\{d(m_1,m_2),d'(n_1,n_2)\\})$$\r\n    We can generalize it to any finite product of metric space.\r\n\\end{definition}\r\nWe need to generalize to topological spaces to have the notion of a quotient space in a metric/topological space.\\\\\r\nWe can introduce (uniform) convergence again in any metric spaces.\r\nWe work in a metric space $(M,d)$.\r\n\\footnote{When $d$ is understood, we do not usually state explicitly our metric $d$}\r\n\\begin{definition}\r\n    Given a sequence $x_n$ in $M$ and a point $x\\in M$, we say $x_n\\to x$ as $n\\to\\infty$ if for any $\\epsilon>0,\\exists N\\in\\mathbb N,\\forall n>N,d(x_n,x)<\\epsilon$.\\\\\r\n    Conversely, if such an $x$ exists for a sequence $x_n$, we say $x_n$ is convergent.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    Assume $x_n\\to x$ and $x_n\\to y$, then $x=y$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Assume for the sake of contradiction that it is not the case.\r\n    We let $\\epsilon=d(x,y)$, we have a large enough $N\\in\\mathbb N$ such that $n\\in\\mathbb N\\implies d(x_n,x)<\\epsilon/2, d(x_n,y)<\\epsilon/2$, so\r\n    $$\\epsilon=d(x,y)\\le d(x,x_n)+d(y,y_n)<2\\epsilon/2=\\epsilon$$\r\n    A contradiction.\r\n\\end{proof}\r\nNow we can introduce the concept of limit.\r\n\\begin{definition}\r\n    Let $(x_n)$ be a convergent sequence which converges to $x$, we write\r\n    $$\\lim_{n\\to\\infty}x_n=x$$\r\n\\end{definition}\r\n\\begin{example}\r\n    1. In $\\mathbb R, \\mathbb C$, this is the usual notion of convergence.\\\\\r\n    2. Take the integers under the $2$-adic metric, $2^n\\to 0$ as $n\\to\\infty$.\\\\\r\n    3. A sequence which is eventually constant converges to that constant.\r\n    Obviously the converse is false in general, but true in discrete metric spaces.\\\\\r\n    4. Choose a nonempty set $S$, then functions that converge under the (induced) uniform metric on $\\ell_\\infty S$ converges uniformly as functions.\r\n    This sometimes can work even on functions $\\notin\\ell_\\infty S$, for example take $S=\\mathbb R$, then $f_n(x)=x+1/n$ converges uniformly to the identity function.\\\\\r\n    5. Consider the space $\\mathbb R^{\\mathbb N}$, the set of all sequences on $\\mathbb R$ with the metric\r\n    $$d((x_n),(y_n))=\\sum_{n=1}^\\infty 2^{-n}\\min{\\{1, |x_n-y_n|\\}}$$\r\n    then we can show that a sequence of sequences $(x^{(n)}_k)$ (where each $n$ gives a sequence) converges to a sequence $(x_k)$ if and only if for each $i$, $x^(n)_i\\to x_i$.\\\\\r\n    In fact, if we fix a set $S$, is there always a metric $d$ on $\\mathbb R^S$ such that $f_n\\to f$ under the metric $d$ if $f_n\\to f$ pointwise on $S$?\r\n    The answer is no, as we will need topological tools for it.\\\\\r\n    6. Consider $C[0,1]$ under the uniform metric.\r\n    Surely the function defined by $f_n=x^n$ do not converge, but if we equip $C[0,1]$ with a different metric, for example the $L^1$ metric, that is,\r\n    $$d(f,g)=\\int_0^1|f(x)-g(x)|\\,\\mathrm dx$$\r\n    In this case, the sequence $f_n$ does converge to $0$.\\\\\r\n    7. Let $(M,d),(M',d')$ be two metric spaces, we consider the metric product space $M\\oplus_pM'=(M\\times M',d_p)$.\r\n    Then $(x_n,y_n)\\to (x,y)$ if and only if $x_n\\to x,y_n\\to y$.\\\\\r\n    8. Consider the metric subspace $N\\subset M$.\r\n    If a sequence $x_n$ converge to $x$ in $N$, then $x_n\\to x$ in $M$.\r\n    The converse is not true since we can take $N=M\\setminus\\{x\\}$ if $x_n\\to x$.\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $(M,d),(M',d')$ be two metric spaces and $f:M\\to M'$ be a function.\r\n    We say $f$ is continuous at $a\\in M$ if\r\n    $$\\forall\\epsilon>0,\\exists\\delta>0,\\forall b\\in M,d(a,b)<\\delta\\implies d'(f(a),f(b))<\\epsilon$$\r\n    If $f$ is continuous at every $a\\in N\\subseteq M$, then we say $f$ is continuous on $N$.\r\n\\end{definition}\r\nNote that if $f$ is continuous on $M$, it is continuous on any $N\\subseteq M$.\r\nThe converse, however, is not true.\r\n\\begin{example}\r\n    We can take both metric spaces to be $\\mathbb R$, then consider the function\r\n    $$f(x)=\\begin{cases}\r\n        1\\text{, if $x\\neq 0$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    Then $f$ is continuous on $N=\\mathbb R\\setminus\\{0\\}$ but not on $M=\\mathbb R$.\r\n\\end{example}\r\n\\begin{proposition}\r\n    $f$ is continuous at $a$ if any only if for any sequence $x_n\\to a$, we have $f(x_n)\\to f(a)$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    If $f$ is continuous at $a$, then $\\forall\\epsilon>0$, we can find some $\\delta>0$ such that $d(a,b)<\\delta\\implies d'(f(a),f(b))<\\epsilon$.\r\n    Now, find any $x_n\\to a$, we can find $N\\in\\mathbb N, \\forall n>N, d(a,x_n)<\\delta$, but with the same $N$, $\\forall n>N$, we have $d'(f(a),f(x_n))<\\epsilon$ by the above.\r\n    So $f(x_n)\\to f(a)$.\\\\\r\n    Conversely, if $x_n\\to a\\implies f(x_n)\\to f(a)$ but $f$ is not continuous at $a$, then we can find $\\epsilon>0$ such that $\\forall\\delta>0$, there is some $x\\in M$ such that $d(x,a)<\\epsilon$ but $d'(f(x),f(a))>\\epsilon$.\r\n    We may set $\\delta_n=1/n$ and we can obtain the corresponding $x_n$.\r\n    Now $x_n\\to a$ but $f(x_n)\\not\\to f(a)$.\r\n    This is a contradiction.\r\n\\end{proof}\r\nThe following two corollaries are then obvious.\r\n\\begin{corollary}\r\n    Let $f$ and $g$ be continuous scalar functions, then $f+g, f\\times g$ and $f/g$ (providing that $\\forall x,g(x)\\neq 0$) are all continuous.\r\n\\end{corollary}\r\n\\begin{corollary}\r\n    If $f:M\\to M',g:M'\\to M''$ are both continuous, then $g\\circ f$ is continuous.\r\n\\end{corollary}\r\nOne can also prove them using $\\epsilon-\\delta$, which is not hard either.\r\n\\begin{example}\r\n    1. Constant, identity (equipping the same metric) and inclusion (in the sense of metric subspace) functions are continuous.\\\\\r\n    2. Real and complex polynomials are continuous.\\\\\r\n    3. The metric function itself is continuous (in fact Lipschitz) with respect to the $d_p$ metric on $M\\times M$.\r\n\\end{example}\r\n\\begin{definition}\r\n    A function $(M,d)\\to (M',d')$ is Lipschitz continuous if there is some $C\\ge 0$ such that\r\n    $$\\forall x,y\\in M,d'(f(x),f(y))\\le Cd(x,y)$$\r\n    we sometimes call $f$ to be $C$-Lipschitz.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    A Lipschitz function is uniformly continuous.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A map $g:(N,d)\\to (N',d')$ is isometric if\r\n    $$\\forall x,y\\in N,d'(g(x),g(y))=d(x,y)$$\r\n    Note that an isometric function is $1$-Lipschitz.\r\n    It also implies injective.\r\n\\end{definition}\r\nWe continue with examples.\r\n\\begin{example}\r\n    4. Let $M,M'$ be metric spaces, fixing $y\\in M'$, $f:M\\to M\\oplus_pM'$ by $f(x)=(x,y')$ is isometric, hence also ($1$-)Lipschitz.\\\\\r\n    5. Let $(M,d), (M',d')$ be metric spaces.\r\n    Consider $q:M\\oplus_pM'\\to M, q':M\\oplus_pM'\\to M'$ be the projection functions.\r\n    Both of these functions are $1$-Lipschitz. %sometimes it is also isometric like Rn\r\n    We can easily extend it to a finite product of metric spaces. \r\n\\end{example}\r\nNow we go on to talk about the topology of metric spaces.\r\nWe start with two observations.\r\nFirstly, in a product metric space $M\\oplus_pM'$, convergence does not depend on the value of $p$.\r\nSecondly, continuity depends on the convergent sequences.\r\n\\begin{definition}\r\n    We fix a metric space $(M,d)$, for $x\\in M$ and $r\\ge 0$, the open ball $D_r(x)$ is the set $\\{y\\in M:d(x,y)<r\\}$.\r\n\\end{definition}\r\nSo $x_n\\to x$ if and only if $\\forall\\epsilon>0,\\exists N\\in\\mathbb N, n>N\\implies x_n\\in D_\\epsilon(x)$.\r\nAnd $f:M\\to M'$ is continuous at $a\\in M$ if and only if $\\forall\\epsilon>0,\\exists\\delta>0,\\forall x\\in M,x\\in D_\\delta(a)\\implies f(x)\\in D_\\epsilon(f(a))$.\r\n\\begin{definition}\r\n    On $(M,d)$, for $x\\in M$ and $r\\ge 0$, the closed ball $B_r(x)$ is the set $\\{y\\in M:d(x,y)\\le r\\}$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. When $M$ is the real numbers, then an open ball is an open interval and closed ball is an closed interval.\\\\\r\n    2. In $\\mathbb R^2$, $B_1(0,0)$ is the unit disk with boundary in $d_2$, and an slanted square in $d_1$, and a big square in $d_\\infty$.\\\\\r\n    3. If $M$ is discrete, $D_1(x)=\\{x\\},B_1(x)=M$.\r\n\\end{example}\r\nNote that $B_s(x)\\subset D_r(x)\\subset B_r(x)$ for any $s<r$.\r\n\\begin{definition}\r\n    A subset $U\\subset M$ with $x\\in U$ is called a neighbourhood of $x$ (in $M$) if there exists some $r>0$ with $D_r(x)\\subset U$.\r\n\\end{definition}\r\nIt does not matter if we take the closed ball instead.\r\n\\begin{definition}\r\n    Given $U\\subset M$, we say $U$ is open if $\\forall x\\in U, \\exists r>0, D_r(x)\\subset U$.\r\n\\end{definition}\r\nSo $U$ is open if and only if $U$ is a neightbourhood of $x$ for any $x\\in U$.\r\n\\begin{lemma}\r\n    Open balls are open.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Immediate from definition but let us write the proof anyways.\\\\\r\n    Consider $D_r(x)$, then for any $y\\in D_r(x)$, since $d(x,y)<r$, if $z\\in D_{r-d(x,y)}(y)$, then $d(x,z)\\le d(y,z)+d(x,y)<r\\implies D_{r-d(x,y)}(y)\\subset D_r(x)$.\r\n\\end{proof}\r\n\\begin{proposition}\\label{metric_nbhdconv}\r\n    In a metric space $M$, the followings are equivalent:\\\\\r\n    1. $x_n\\to x$.\\\\\r\n    2. For any neighbourhood $U$ of $x$, there is some $N\\in\\mathbb N, \\forall n>N, x_n\\in U$.\\\\\r\n    3. For any open set $U$ containing $x$, there is some $N\\in\\mathbb N, \\forall n>N, x_n\\in U$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    $1\\implies 2$: $\\exists r>0,D_r(x)\\subset U$, so we can choose an $N\\in\\mathbb N,\\forall n>N, d(x_n,x)<r\\implies x_n\\in U$.\\\\\r\n    $2\\implies 3$: Immediate by the preceding lemma.\\\\\r\n    $3\\implies 1$: Given $\\epsilon>0$, take $U=D_\\epsilon(x)$, then two statement becomes identical.\r\n\\end{proof}\r\n\\begin{proposition}\\label{metric_preimage}\r\n    Given function $f:M\\to M'$, then:\\\\\r\n    (A) For $a\\in M$, the followings are equivalent:\\\\\r\n    1. $f$ continuous at $a$.\\\\\r\n    2. For any neighbourhood $V$ of $f(a)$, there is a neighbourhood $U$ of $a$ such that $f(U)\\subset V$.\\\\\r\n    3. For any neighbourhood $V$ of $f(a)$, $f^{-1}(V)$ is a neighbourhood of $a$.\\\\\r\n    (B) The followings are equivalent:\\\\\r\n    1. $f$ is continuous.\\\\\r\n    2. The pre-image of any open set is open.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Part (A):\\\\\r\n    $1\\implies 2$: Given any neighbourhood $V$ of $f(a)$, there is some $r$ such that $D_r(f(a))\\subset V$.\r\n    Since $f$ is continuous at $a$, there is $\\delta>0$ with $f(D_\\delta(a))\\subset D_r(f(a))\\subset V$.\r\n    So $U=D_\\delta(a)$ works.\\\\\r\n    $2\\implies 3$: Trivial since there is some neighbourhood $U$ containing $a$ with $f(U)\\subset V\\implies U\\subset f^{-1}(V)$ so it is a neighbourhood of $a$.\\\\\r\n    $3\\implies 1$: Given $\\epsilon>0$, $f^{-1}(D_\\epsilon(f(a)))$ contains some open ball $D_\\delta(a)$ for some $\\delta>0$, so it's done.\\\\\r\n    Part (B):\\\\\r\n    $1\\implies 2$: Given $V$ open in $M'$, for $x\\in f^{-1}(V)$, we have $f(x)\\in V$, so $V$ is a neighbourhood of $f(x)$.\r\n    Since $f$ is continuous, by (A), there is an neighbourhood of $x$ containing in it.\\\\\r\n    $2\\implies 1$: We shall show that it is continuous at every point.\r\n    Given $\\epsilon>0,a\\in M$, the ball $D_\\epsilon(f(a))$ is open in $M'$, so $f^{-1}(D_\\epsilon(f(a)))$ is open, so there is some $\\delta$ with $D_\\delta(a)\\subset f^{-1}(D_\\epsilon(f(a)))$, so we are done.\r\n\\end{proof}\r\n\\begin{definition}\r\n    The topology of a metric space the collection of open subsets of it.\r\n\\end{definition}\r\n\\begin{proposition}\\label{metric_topology}\r\n    In a metric space $M$, we have the following:\\\\\r\n    1. $\\varnothing,M$ are open.\\\\\r\n    2. If $\\{U_i\\}_{i\\in I}$ are open, then $\\bigcup_{i\\in I}U_i$ is open.\r\n    3. If $U,V\\subset M$ are open, then $U\\cap V$ is open.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    1 is trivial.\\\\\r\n    For 2, given $x$ in the union, then there is a $j\\in I$ such that $x\\in U_j$, but then there is some open ball $U\\ni x$ such that $U\\subset U_j$, then $U$ is a subset of that union.\r\n    So this union is open.\\\\\r\n    Regarding 3, given $x\\in U\\cap V$, then there are $\\epsilon_U,\\epsilon_V>0$ such that $D_{\\epsilon_U}(x)\\subset U,D_{\\epsilon_V}(x)\\subset V$, so the ball $D_{\\min\\{\\epsilon_U,\\epsilon_V\\}}(x)\\subset U\\cap V$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A subset $A\\subset M$ is closed if whenever $x_n\\to x$ in $M$ for some sequece $(x_n)\\in A$, then $x\\in A$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. Closed balls are closed.\\\\\r\n    2. So in $\\mathbb R$, any closed interval is closed.\r\n    Also $\\mathbb R$ itself is both open and closed.\r\n    $[0,1)$ is neither open nor closed.\r\n\\end{example}\r\n\\begin{lemma}\\label{metric_complement}\r\n    A subset $A\\subset M$ is closed if and only if $M\\setminus A$ is open.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If $A$ is closed but $M\\setminus A$ is not open, so there is some $x\\in M\\setminus A$ such that $D_r(x)$ is not contained in $M\\setminus A$ for all $r>0$.\r\n    Hence for each $\\epsilon>0, \\exists x_\\epsilon \\in M, x_\\epsilon\\in D_\\epsilon(x)$.\r\n    Taking $a_n=x_{1/n}$ gives a contradiction.\\\\\r\n    If $A$ is not closed but $M\\setminus A$ is open.\r\n    So we can find $(a_n)\\in A$ such that $a_n\\to a\\notin A$, so there is some $\\epsilon>0$ such that $D_\\epsilon(a)\\subset M\\setminus A$, but this is a contradiction since $a_n\\notin M\\setminus A$ for any $n$ but it can go $\\epsilon$-close to $a$.\r\n\\end{proof}\r\n\\begin{example}\r\n    If $(N,d)$ is discrete, then every subset of $N$ is both open and closed.\r\n\\end{example}\r\n\\begin{definition}\r\n    Two metrics on a set are equivalent if they give the same topology.\r\n\\end{definition}\r\nNote that it is equivalent to say that the teo metrics have the same convergence sequences since they help identify the closed sets.\r\nIt also means that they have the same continuous functions, both to and from, any other spaces.\r\nNote that the two metrics induce the same topology if and only if the identity maps from both spaces are continuous.\r\n\\begin{definition}\r\n    A map $g:M\\to M'$ is called a homeomorphism if it is a bijection and both $g$ and $g^{-1}$ are continuous.\\\\\r\n    We say $g$ is an isometry if it is bijective and it is isometric.\\\\\r\n    We say $M$ and $M'$ are homeomorphic if there is a homeomorphism between them.\r\n    And $M$, $M'$ be isometric if there is an isometry between them.\r\n\\end{definition}\r\n\\begin{remark}\r\n    1. Continuous bijections may not be a homeomorphism.\r\n    Take $g:\\mathbb R\\to\\mathbb R$ where the domain is equipped with discrete metric and the codomain with the usual metric.\\\\\r\n    2. A surjective isometric function is an isometry.\r\n\\end{remark}\r\n\\begin{example}\r\n    1. $(0,1),(0,\\infty)$ are homeomorphic.\r\n    Take $x\\mapsto 1/x$.\\\\\r\n    2. $\\mathbb R^2$ and $\\mathbb C$ are isometric. \r\n\\end{example}\r\n\\begin{definition}\r\n    Two metrics $d,d'$ on $M$ are uniformly equivalent if and only if both the identity functions $\\operatorname{id}:(M,d)\\to(M,d'),\\operatorname{id}:(M,d')\\to(M,d)$ are uniformly continuous.\\\\\r\n    We say $d,d'$ are Lipschitz equivalent if and only if both the identity functions are Lipschitz.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. On $M\\times M'$, $d_1,d_2,d_\\infty$ are Lipschitz equivalent.\\\\\r\n    2. (non-example) On $C[0,1]$ the uniform metric is not equivalent to the $L^1$ metric since they do not have the same convergent sequences.\r\n\\end{example}\r\n", "meta": {"hexsha": "4e584a6f26f251d6774d1907bb911578abf4fc37", "size": 18689, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/metric.tex", "max_stars_repo_name": "david-bai-notes/IB-Analysis-and-Topology", "max_stars_repo_head_hexsha": "9c3a32b907ff14942767e4bbdc9951240d2d7edb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3/metric.tex", "max_issues_repo_name": "david-bai-notes/IB-Analysis-and-Topology", "max_issues_repo_head_hexsha": "9c3a32b907ff14942767e4bbdc9951240d2d7edb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3/metric.tex", "max_forks_repo_name": "david-bai-notes/IB-Analysis-and-Topology", "max_forks_repo_head_hexsha": "9c3a32b907ff14942767e4bbdc9951240d2d7edb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.4769736842, "max_line_length": 249, "alphanum_fraction": 0.6459949703, "num_tokens": 6329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640645, "lm_q2_score": 0.8856314753275019, "lm_q1q2_score": 0.8069694223218975}}
{"text": "%%% lecture 1\n\n\\section{Introduction}\n\\subsection{Introduction example} \n\\label{sub:introduction_example}\nWe have\n\\[\n\t\\begin{cases}\n\t\tf''+f =g, &\\text{ in }I = [0,1]\\\\\n\t\tf(0)=1, \\,f'(0)=1\n\t\\end{cases},\n\\]\nwhere $g$ is a known continous function on $I$. We will now consider different cases:\n\n\\begin{enumerate}[1.]\n\t\\item $g=0$\n\t\\[\n\t\t\\Rightarrow \\,f(x) = A \\cos(x) + B \\sin(x), x \\in I,\n\t\\]\n\twhere $A,B \\in \\mathbb{R}$.\n\t\\item $g$ arbitrary. We will now introduce the Method of variation of constants. Set\n\t\\[\n\t\tf(x)=A(x) \\cos(x)+ B(x) \\sin(x).\n\t\\]\n\tDifferentiate\n\t\\[\n\t\tf'(x) = A'(x) \\cos(x) + B'(x) \\sin(x) - A(x) \\sin(x) + B(x) \\cos(x).\n\t\\]\n\tAssume (this is part of the method)\n\t\\[\n\t\tA'(x)\\cos(x) + B'(x) \\sin(x) = 0, \\qquad x \\in I.\n\t\\]\n\tDifferentiate $f'(x)$ and get\n\t\\[\n\t\tf''(x)=\\underset{= -f(x)}{\\underbrace{-A(x) \\cos(x) - B(x) \\sin(x)}} - A'(x) \\sin(x) + B'(x) \\cos(x).\n\t\\]\n\tWe get\n\t\\[\n\t\tg(x) = f''(x)+f(x) = -A'(x) \\sin(x) + B'(x) \\cos(x).\n\t\\]\n\tNow:\n\t\\[\n\t\t\\begin{cases}\n\t\t\tA'(x)\\cos(x) + B'(x) \\sin(x) = 0, & x \\in I\\\\\n\t\t\t- A'(x) \\sin(x)+ B'(x) \\cos(x) = g(x), & x \\in I \\\\\n\t\t\tA(0)=1, \\qquad B(0)=0 &\n\t\t\\end{cases}.\n\t\\]\n\tWe get\n\t\\begin{align*}\n\t\tA'(x) &= - g(x)\\sin(x), \\\\\n\t\tA(0) &= 1, \\\\\n\t\tB'(x) &= g(x) \\cos(x), \\\\\n\t\tB(0) &=0.\n\t\\end{align*}\n\tThis implies\n\t\\begin{align*}\n\t\tA(x) &= A(0) + \\int_{0}^{x} A'(t) \\,\\mathrm{d}t = 1 - \\int_{0}^{x} g(t) \\sin(t) \\,\\mathrm{d}t, \\\\\n\t\tB(x) &= B(0) + \\int_{0}^{x}B'(t) \\,\\mathrm{d}t = 0 + \\int_{0}^{x}g(t)\\cos(t) \\,\\mathrm{d}t.\n\t\\end{align*}\n\tHence\n\t\\begin{align*}\n\t\tf(x) &= \\cos(x) - \\int_{0}^{x} g(t) \\sin(t) \\,\\mathrm{d}t \\cos(x) + \\int_{0}^{x} g(t) \\cos(t) \\,\\mathrm{d}t \\sin(x) \\\\\n\t\t&= \\cos(x) + \\int_{0}^{x} (\\underset{=\\sin(x-t)}{\\underbrace{\\sin(x)\\cos(t)- \\sin(t)\\cos(x)}})g(t) \\,\\mathrm{d}t \\\\\n\t\t&= \\cos(x) + \\int_{0}^{x}\\sin(x-t)g(t) \\,\\mathrm{d}t \\qquad (*).\n\t\\end{align*}\n\tCheck that $f(x)$ in $(*)$ satisfies the PDE.\n\t\\minisec{special case:}\n\tAssume for $x \\in I$\n\t\\[\n\t\tg(x) = k(x)f(x).\n\t\\]\n\tHere $k$ is a known continous function on $I$. Insert this in $(*)$. We obtain\n\t\\[\n\t\tf(x) = \\cos(x) + \\int_{0}^{x} \\sin(x-t)k(t)f(t) \\,\\mathrm{d}t, \\qquad x \\in I \\qquad (**).\n\t\\]\n\tObserve that $f$ appears both in LHS and RHS. $(**)$ is a reformulation of the PDE with $g=kf$. Pick a $\\underset{\\in C(I)}{\\underbrace{\\text{continous function in $I$}}}$. call it $f_0$. Set\n\t\\begin{align*}\n\t\tf_1(x) &= \\cos(x) + \\int_{0}^{x}\\sin(x-t)k(t)f_0(t) \\,\\mathrm{d}t, \\\\\n\t\tf_2(x) &= \\cos(x) + \\int_{0}^{x}\\sin(x-t)k(t)f_1(t) \\,\\mathrm{d}t, \\\\\n\t\t\\vdots &\\qquad \\qquad  \\vdots \\\\\n\t\tf_{n+1}(x) &= \\cos(x) + \\int_{0}^{x}\\sin(x-t)k(t)f_n(t) \\,\\mathrm{d}t, \\qquad n=1,2,3, \\dots. \\\\\n\t\\end{align*}\n\t\\minisec{Hope:} $f_n$ tends to some continous function $f$ on $I$, denoted $f_n \\to f$. 'Tends to' has to be more precis! \n\t\\begin{align*}\n\t\tf_{n+1}(x) &= \\cos(x) + \\int_{0}^{x} \\sin(x-t)k(t)f_n(t) \\,\\mathrm{d}t \\\\\n\t\t\\downarrow & \\qquad \\qquad \\downarrow \\\\\n\t\tf(x) &= \\cos(x) + \\int_{0}^{x} \\sin(x-t)k(t)f(t) \\,\\mathrm{d}t\n\t\\end{align*}\n\tfor $x \\in I$. Simplify notation set for $v \\in C(I)$\n\t\\[\n\t\t\\begin{cases}\n\t\t\tu(x)&=\\cos(x)\\\\\n\t\t\tkv(x)&= \\int_{0}^{x} \\sin(x-t)k(t)v(t) \\,\\mathrm{d}t\n\t\t\\end{cases}.\n\t\\]\n\tWe have $f_0 \\in C(I)$, $f_{n+1}=u + k f_n$ for $n=0,1,2, \\dots$ (!) \\\\\n\tFacts from previous calculus classes:\n\t\\begin{definition*}[Sequenze of continous functions]\n\t\t\\[\n\t\t\tv_n \\in C(I), \\qquad n=1,2,\\dots.\n\t\t\\]\n\t\tWe say that $(v_n)_{n=1}^{\\infty}$ converges uniformly in $I$ if\n\t\t\\[\n\t\t\t\\max_{x \\in I} \\abs{v_n(x)-v_m(x)} \\to 0 , \\qquad n,m \\to \\infty,\n\t\t\\]\n\t\ti.e.\n\t\t\\[\n\t\t\t\\forall\\, \\varepsilon >0 \\exists\\, N: \\forall\\, n,m \\geq N: \\, \\max_{x \\in I}\\abs{v_n(x)-v_m(x)}< \\varepsilon.\n\t\t\\]\n\t\\end{definition*}\n\t\\begin{lemma*}\n\t\tSuppose that $(v_n)_{n=1}^{\\infty}$ converges uniformly on $I$. then there exists $v \\in C(I)$ such that\n\t\t\\[\n\t\t\t \\max_{x \\in I}\\abs{v_m(x)-v(x)} \\to 0 \\qquad \\text{as }m \\to \\infty.\n\t\t\\]\n\t\\end{lemma*}\n\tBack to (!): \\\\\n\t\\minisec{More Notation:}\n\t\\[\n\t\tk(kv) = k^2 v, \\qquad v \\in C(I)\n\t\\]\n\tand\n\t\\[\n\t\tk^{n+1}v = k(k^nv), \\qquad n=1,2,\\dots.\n\t\\]\n\tWe have \n\t\\begin{align*}\n\t\tf_0 & \\in C(I) \\\\ f_1 &=u+kf_0 \\\\ \\text{ and }  \n\t\t\t\tf_2 &= u + kf_1 = u + k(u+kf_0)\n\t\\end{align*}\n\tand so on. Note that\n\t\\[\n\t\tk(v+w)=kv+kw.\n\t\\]\n\tThen \n\t\\begin{align*}\n\t\tf_2 &= u +k (u+kf_0) = k + ku + k(kf_0) = u + ku +k^2f_0 \\\\\n\t\tf_3 &= u + kf_2 = u + ku + k^2u + k^3f_0\n\t\\end{align*}\n\tand in general for $n=1,2,\\dots$\n\t\\[\n\t\tf_n = ku + \\dots + k^{n-1}u + k^n f_0, \\qquad n=1,2,\\dots.\n\t\\]\n\tAssume $n>m$ then\n\t\\[\n\t\tf_n-f_m = k^mu + \\dots + k^{n-1}u + k^nf_0 - k^mf_0.\n\t\\]\n\tSet for $v \\in C(I)$\n\t\\[\n\t\t\\norm{v} = \\max_{x \\in I}\\abs{v(x)}.\n\t\\]\n\tNote\n\t\\[\n\t\t\\norm{v+w} \\leq \\norm{v} + \\norm{w} \\qquad \\text{for }v,w \\in C(I)\n\t\\]\n\tand\n\t\\[\n\t\t\\norm{-v}=\\norm{v}.\n\t\\]\n\tWe have\n\t\\begin{align*}\n\t\t\\norm{f_n-f_m} &= \\norm{k^mu + \\dots + k^{n-1}u + k^nf_0 - k^m f_0} \\\\\n\t\t&\\leq \\norm{k^mu} + \\dots + \\norm{ k^{n-1}u} + \\norm{k^nf_0} + \\norm{- k^mf_0}.\n\t\\end{align*}\n\tAssumption:\n\t\\[\n\t\t\\sum_{l=1}^{\\infty} \\norm{k^lv} < \\infty \\qquad \\text{for all }v \\in C(I) \\qquad (***).\n\t\\]\n\tUnder this assumption\n\t\\[\n\t\t\\norm{f_n-f_m} \\to 0 \\qquad \\text{as }n,m \\to \\infty\n\t\\]\n\tsince\n\t\\begin{align*}\n\t\t\\sum_{l=1}^{\\infty}\\norm{k^lu} &< \\infty \\qquad \\qquad (u(x)=\\cos(x)) \\\\\n\t\t\\sum_{l=1}^{\\infty}\\norm{k^lf_0} &< \\infty \\qquad \\qquad (f_0 \\in C(I)).\n\t\\end{align*}\n\tConclusion: $(f_n)_{n=1}^{\\infty}$ converges uniformly on $I$. By lemma above there exists $f \\in C(I)$ such that\n\t\\[\n\t\t\\max_{x \\in I}\\abs{f_n(x)-f(x)} \\to 0, \\qquad n \\to \\infty,\n\t\\]\n\ti.e.\n\t\\[\n\t\t\\norm{f_n -f} \\to 0, \\qquad n \\to \\infty.\n\t\\]\n\t'Back hope':\n\t$f_n$ tends to $f$, denoted $f_n \\to f$ shall be interpretated as\n\t\\[\n\t\t\\norm{f_n -f} \\to 0, \\qquad n \\to \\infty.\n\t\\]\n\tRemember\n\t\\[\n\t\tf_{n+1}(x) = u(x) + k f_n(x) \\to ?.\n\t\\]\n\tFor $x \\in I$ there is\n\t\\begin{align*}\n\t\t\\abs{k f_n(x)- kf(x)} &= \\abs{ \\int_{0}^{x} \\sin(x-t)k(t)f_n(t) \\,\\mathrm{d}t- \\int_{0}^{x}\\sin(x-t)k(t)f(t) \\,\\mathrm{d}t} \\\\\n\t\t&\\leq \\int_{0}^{x}\\abs{\\sin(x-t)k(t)}\\underset{\\leq \\norm{f_n-f}}{\\underbrace{\\abs{f_n(t)-f(t)}}} \\,\\mathrm{d}t \\\\\n\t\t&\\leq \\int_{0}^{x}\\abs{\\sin(x-t)k(t)} \\,\\mathrm{d}t \\norm{f_n-f}.\n\t\\end{align*}\n\tIn particular\n\t\\begin{align*}\n\t\t\\norm{k f_n- kf} &\\leq \\max_{x \\in I}\\int_{0}^{x} \\underset{\\leq 1}{\\underbrace{\\abs{\\sin(x-t)}}} \\underset{\\max_{t \\in I}\\abs{k(t)}< \\infty}{\\underbrace{\\abs{k(t)}}} \\,\\mathrm{d}t \\norm{f_n -f} \\\\\n\t\t&\\leq \\norm{k} \\norm{f_n-f}.\n\t\\end{align*}\n\tWe have, provided $(***)$ holds, shown\n\t\\begin{align*}\n\t\tf_{n+1} &= u + k f_n \\\\\n\t\t\\downarrow & \\\\\n\t\tf &= u + kf.\n\t\\end{align*}\n\tLet us try to prove $(***)$. For $v \\in C(I)$ arbitrary and for $x \\in I$\n\t\\begin{align*}\n\t\t\\norm{kv(x)} &= \\abs{\\int_{0}^{x}\\sin(x-t)k(t)v(t) \\,\\mathrm{d}t} \\\\\n\t\t&\\leq \\int_{0}^{x}\\underset{\\leq 1}{\\underbrace{\\abs{\\sin(x-t)}}}\\underset{\\leq \\norm{k}}{\\underbrace{\\abs{k(t)}}}\\abs{v(t)} \\,\\mathrm{d}t \\\\\n\t\t&\\leq \\int_{0}^{x}\\underset{\\leq \\norm{v}}{\\underbrace{\\abs{v(t)}}} \\,\\mathrm{d}t \\norm{k} \\\\\n\t\t&\\leq \\norm{k} \\norm{v}x.\n\t\\end{align*}\n\tIn particular\n\t\\[\n\t\t\\norm{kv} \\leq \\norm{k}\\norm{v}\n\t\\]\n\tand\n\t\\begin{align*}\n\t\t\\abs{k^2v(x)} &\\leq \\int_{0}^{x} \\abs{kv(t)} \\,\\mathrm{d}t \\norm{k} \\\\\n\t\t&\\leq \\int_{0}^{x}\\norm{k}\\norm{v}t \\,\\mathrm{d}t \\cdot \\norm{k} \\\\\n\t\t&= \\norm{k}^2 \\norm{v} \\frac{x^2}{2}.\n\t\\end{align*}\n\tIn particular\n\t\\[\n\t\t\\norm{k^2v} \\leq \\norm{k}^2 \\norm{v} \\frac{1}{2}.\n\t\\]\n\tBy induction we get\n\t\\begin{align*}\n\t\t\\abs{k^n v(x)} &\\leq \\norm{k}^n \\norm{v} \\frac{x^m}{m!} \\qquad x \\in I \\\\\n\t\t\\norm{k^n v} &\\leq  \\norm{k}^n \\norm{v} \\frac{1}{n!}.\n\t\\end{align*}\n\tSo \n\t\\begin{align*}\n\t\t\\sum_{l=1}^{\\infty}\\norm{k^lv} &\\leq \\sum_{l=1}^{\\infty}\\norm{k}^l \\norm{v} \\frac{1}{l!} \\\\\n\t\t&= \\norm{v} \\sum_{l=1}^{\\infty} \\frac{\\norm{k}^l}{l!} \\\\\n\t\t&\\leq \\norm{v} e^{\\norm{k}} < \\infty.\n\t\\end{align*}\n\tConsider Taylor expansion.\n\t$\\Rightarrow $ $(***)$ holds true. \\\\\n\tWe have now shown that $f = u+kf$ where $u(x) = \\cos(x)$ and\n\t\\[\n\t\tkv = \\int_{0}^{x}\\sin(x-t)k(t)v(t) \\,\\mathrm{d}t.\n\t\\]\n\t$x \\in I$ for $v \\in C(I)$, has a solution $f \\in C(I)$. \\\\\n\t\\minisec{Question:} Is the solution unique? \\\\\n\tAssume $f,\\tilde f \\in C(I)$ such that $f = u + k f$ and $\\tilde f = u+ k \\tilde f$. Set \n\t\\[\n\t\tv = f- \\tilde f \\in C(I)\n\t\\]\n\t\\begin{align*}\n\t\t\\Rightarrow v &= (u+kf) - (u+ k \\tilde f) \\\\ &= kf - k \\tilde f \\\\ &= k(f- \\tilde f) \\\\ &= kv.\n\t\\end{align*}\n\tWe have $v = kv$, implies that $kv = k(kv) = k^2v$. So for $n=1,2,\\dots$\n\t\\[\n\t\tv = kv = k^2v = \\dots = k^nv.\n\t\\]\n\tWe know \n\t\\[\n\t\t\\sum_{n=1}^{\\infty}\\norm{k^n \\hat{v}} < \\infty \\qquad \\text{for all }\\hat{v} \\in C(I).\n\t\\]\n\tApply this to $\\hat{v}=v$:\n\t\\[\n\t\t\\sum_{n=1}^{\\infty}\\underset{=\\norm{v}}{\\underbrace{\\norm{k^nv}}} < \\infty .\n\t\\]\n\tSo $\\norm{v}=0$ with implies $v(x)=0$ for all $x \\in I$.\n\tSo we have $f(x)=\\tilde f(x)$ for $x \\in I$. \\\\\n\t$\\Rightarrow $ Answer to the question above: YES ! \n\\end{enumerate}\nWe have more or less proved the following theorem:\n\\begin{theorem}\n\tSet $I=[0,1]$. Suppose $u \\in C(I)$ and $k \\in C(I \\times I)$. Consider \n\t\\[\n\t\tf(x) = u(x)+ \\int_{0}^{x} k(x,t) f(t) \\,\\mathrm{d}t, \\qquad x \\in I \\qquad \\qquad (1).\n\t\\]\n\tThen $(1)$ has a unique solution $f \\in C(I)$\n\\end{theorem}\nWith the same technology we can prove:\n\\begin{theorem}\n\tSet $I = [0,1]$. Suppose $u \\in C(I)$, $k \\in C(I \\times I)$ and $\\max\\limits_{(x,t) \\in I \\times I} \\abs{k(x,t)} <1$. Consider \\[\n\t\tf(x) = u(x) + \\int_{0}^{1}k(x,t)f(t) \\,\\mathrm{d}t, \\qquad x \\in I \\qquad \\qquad (2).\n\t\\]\n\tThen $(2)$ has a unique solution $f \\in C(I)$.\n\\end{theorem}\nDifferent notions: see introductional example.\n\n\\section{Normed Spaces and Banach Spaces} \n\\label{sec:normed_spaces_and_banach_spaces}\n\n\n\n\\begin{definition*}[vector space]\n\t$C(I)$ with the operations for $x \\in I$:\n\t\\begin{description}\n\t\t\\item[addition] $v,w \\in C(I)$: $\\qquad (v+w)(x) = v(x)+ w(x)$, \n\t\t\\item[mult. by scalar] $v \\in C(I)$, $ \\lambda \\in \\mathbb{R}$: $\\qquad (\\lambda v)(x) = \\lambda v(x)$.\n\t\\end{description}\n\tNote that $v+w, \\lambda v \\in C(I)$.\n\\end{definition*}\n\\begin{definition*}[norm]\n\tNorm on $C(I)$ for instance \n\t\\[\n\t\t\\norm{v} = \\max_{x \\in I} \\abs{v(x)}\n\t\\]\n\twith norm given we can talk about convergence and continuity.\n\\end{definition*}\n\\begin{definition*}[Cauchy sequence]\n\tIn our example a sequence $(f_n)_{n=1}^{\\infty}$ is called Cauchy sequence if $\\norm{f_n-f_m} \\to 0$ for $n,m \\to \\infty$.\n\\end{definition*}\n\\begin{definition*}\n\t$C(I)$ with the max-norm. Lemma above says that every Cauchy sequence converges i.e.\n\t\\[\n\t\t\\norm{v_n-v_m} \\to 0, \\qquad n,m \\to \\infty.\n\t\\]\n\tThis applies\n\t\\[\n\t\t\\exists\\, v \\in C(I): \\norm{v_n-v} \\to 0, \\qquad n \\to \\infty.\n\t\\]\n\tThis is the defining property of a Banach space. \\\\\n\t$K$ linear mapping $C(I) \\to C(I)$ with\n\t\\begin{align*}\n\t\tK(v+w) &= K(v) + K(w) \\\\\n\t\tK(\\lambda v) &= \\lambda K(v)\n\t\\end{align*}\n\tfor $v,w \\in  C(I)$, $\\lambda \\in \\mathbb{R}$. \\\\\n\t$K$ bounded linear:\n\t\\[\n\t\t\\norm{Kv} \\leq M \\norm{v} \\qquad \\forall\\, v \\in C(I),\n\t\\]\n\twhere $M >0$ independent of $v$.\t\n\\end{definition*}\n\\begin{definition*}[operator norm]\n\tDefine\n\t\\[\n\t\t\\norm{K}:= \\inf \\set[M>0]{\\norm{Kv} \\leq M \\norm{v} \\text{ for all }v \\in C(I)}.\n\t\\]\n\\end{definition*}\n\\minisec{fixed point results:}\nOur example: $f=u+kf =: T(f)$ and $f_0 \\in C(I)$ fixed. \\\\\nForm sequence of iterants $(f_n)_{n=1}^{\\infty}$, $f_n = T(f_{n-1})$, $n=1,2,\\dots$ if\n\\[\n\t\\norm{T(v)-T(w)} \\leq c \\norm{v-w}\n\\]\nfor all $v,w \\in C(I)$ for some $c<1$. Then there is a unique $v \\in C(I)$ such that $v = T(v)$. \\\\\nThis is \\underline{Banach's fixed point theorem}.\n\\begin{definition*}[Green's function]\n\tOur example: \n\t\\[\n\t\tL = \\left( \\diffd{}{x} \\right)^2 + 1 \n\t\\]\n\tdifferential operator. Boundary conditions \n\t\\[\n\t\tf(0) = f'(0) = 0.\n\t\\]\n\tThen \n\t\\[\n\t\tf(x) = \\int_{0}^{1} g(x,t)h(t) \\,\\mathrm{d}t \n\t\\]\n\tis a solution to\n\t\\[\n\t\t\\begin{cases}\n\t\t\tf''+f &= h, \\\\\n\t\t\tf(0) = f'(0)& = 0.\t\n\t\t\\end{cases}\n\t\\]\n\\end{definition*}\n\\begin{definition*}[real vector space]\n\tWe say that $E$ is a real vector space  if it is a non-empty set with the operations \n\t\\begin{description}\n\t\t\\item[addition] $E \\times E \\to E$, $\\qquad (x,y) \\mapsto x+y$\n\t\t\\item[mult. with scalar] $\\mathbb{R} \\times E \\to E$, $ \\qquad (\\lambda,x) \\mapsto \\lambda x$ \n\t\\end{description}\n\tsatisfying the axioms:\n\t\\begin{enumerate}[(1)]\n\t\t\\item $x+y = y+x, \\qquad$ for all $x,y \\in E$,\n\t\t\\item $x+(y+z)= (x+y)+z, \\qquad $ for all $x,y,z \\in E$,\n\t\t\\item For all $x,y \\in E$ there exists $z \\in E$ such that $x+z = y$,\n\t\t\\item $\\alpha (\\beta x) = (\\alpha \\cdot \\beta)x, \\qquad $ for all $\\alpha,\\beta \\in \\mathbb{R}, x \\in E$,\n\t\t\\item $\\alpha(x+y) = \\alpha x+ \\alpha y, \\qquad $ for all $\\alpha \\in \\mathbb{R}, x,y \\in E$,\n\t\t\\item $(\\alpha + \\beta) x = \\alpha x + \\beta x, \\qquad $ for all $\\alpha, \\beta \\in \\mathbb{R}, x \\in E$,\n\t\t\\item $1 \\cdot x = x, \\qquad $ for all $x \\in E$.  \n\t\\end{enumerate}\n\\end{definition*}\n\\begin{bemerkung}\n\t$E$ is a complex vector space if all $\\mathbb{R}$ in the definition above are replaced by $\\mathbb{C}$.\n\\end{bemerkung}\n\\begin{bemerkung}\n\t\\begin{enumerate}[(1)]\n\t\t\\item \\[\n\t\t\t\\exists\\,! 0 \\in E: \\qquad x + 0 = x \\qquad \\text{for all }x \\in E.\n\t\t\\]\n\t\tSince: Fix $x \\in E$, by $(3)$, $\\exists\\, 0_x$ such that $0_x + x =x$. \\\\\n\t\tFix $y \\in E$. We want to show that $y + 0_y = y$. By $(3)$, there exists $z \\in E$ such that $x+z = y$. So\n\t\t\\begin{align*}\n\t\t\ty + 0_x & \\stackrel{\\hphantom{(1)}}{=} (x+z)+ 0_x \\\\\n\t\t\t&\\stackrel{(1)}{=} (z+x)+ 0_x \\\\\n\t\t\t&\\stackrel{(2)}{=} z + (x + 0_x) \\\\\n\t\t\t&\\stackrel{\\hphantom{(1)}}{=} z+x \\\\\n\t\t\t&\\stackrel{(1)}{=}x+z \\\\\n\t\t\t&\\stackrel{\\hphantom{(1)}}{=} y.\n\t\t\\end{align*}\n\t\tAssume $x+ 0_1 = x$, $x+ 0_2 =x$ for all $x \\in E$. We want to show $0_1 = 0_2$:\n\t\t\\[\n\t\t\t0_1 = 0_1 + 0_2 = 0_2 + 0_1 = 0_2,\n\t\t\\]\n\t\t\\item \n\t\t\\[\n\t\t\t\\forall\\, x \\in E: \\, \\exists\\,! \\,-x \\in E: \\,x+(-x)=0.\n\t\t\\]\n\t\tproof: exercise.\n\t\t\\item \\begin{align*}\n\t\t\t0x &=0 \\qquad \\text{for all }x \\in E \\\\\n\t\t\t(-1)x &= -x \\qquad \\text{for all }x \\in E.\n\t\t\\end{align*}\n\t\\end{enumerate}\n\\end{bemerkung}\n\\begin{beispiele}[Examples of real vector spaces]\n\t\\begin{enumerate}[1)]\n\t\t\\item $\\mathbb{R}$ with standard addition and mult. by scalar.\n\t\t\\item $\\mathbb{R}^n$, $n=2,3, \\dots$.\n\t\t\\begin{description}\n\t\t\t\\item[addition] $(x_1,x_2,\\dots) + (y_1,y_2, \\dots) = (x_1+y_1,x_2+y_2, \\dots)$ \n\t\t\t\\item[mult.] $ \\lambda (x_1,x_2,\\dots) = (\\lambda x_1, \\lambda x_2, \\dots)$\n\t\t\\end{description} \n\t\t\\item $\\mathbb{R}^{\\infty} = \\set[(x_1,\\dots,x_n,\\dots)]{x_n \\in \\mathbb{R}, n=1,2,\\dots}$\n\t\t\\item $1 \\leq p < \\infty$, \n\t\t\\[\n\t\t\tl^p = \\set[(x_1,\\dots,x_n, \\dots) \\in \\mathbb{R}^{\\infty}]{\\left( \\sum_{n=1}^{\\infty} \\abs{x_n}^p \\right)^{\\frac{1}{p}} < \\infty}\n\t\t\\]\n\t\twith the same addition and mult. by scalar as in $\\mathbb{R}^{\\infty}$. We have to check:\n\t\t\\begin{enumerate}[(1)]\n\t\t\t\\item $x,y \\in l^p \\qquad \\Rightarrow \\qquad x+y \\in l^p$\n\t\t\t\\item $x \\in l^p, \\lambda \\in \\mathbb{R} \\qquad \\Rightarrow \\qquad \\lambda x \\in l^p$. \n\t\t\\end{enumerate}\n\t\tFor $(1)$ we assume $x = (x_1, \\dots, x_n, \\dots)$ and $y = (y_1, \\dots, y_n, \\dots)$.\n\t\t\\begin{align*}\n\t\t\tx \\in l^p \\qquad &\\Rightarrow \\qquad \\sum_{n=1}^{\\infty}\\abs{x_n}^p < \\infty \\\\\n\t\t\ty \\in l^p \\qquad &\\Rightarrow \\qquad \\sum_{n=1}^{\\infty}\\abs{y_n}^p < \\infty\n\t\t\\end{align*}\n\t\t\\[\n\t\t\t\\Rightarrow \\qquad  x+y = (x_1+y_1, \\dots) \\stackrel{?}{\\in } l^p?\n\t\t\\]\n\t\t\\begin{align*}\n\t\t\t\\Rightarrow \\sum_{n=1}^{\\infty}\\abs{x_n+y_n}^p & \\leq \\set{\\abs{x_n+y_n} \\leq \\abs{x_n}+ \\abs{y_n} \\leq 2 \\max \\set{\\abs{x_n},\\abs{y_n}}} \\\\\n\t\t\t& \\,\\set{\\abs{x_n+y_n}^p \\leq 2^p \\left( \\abs{x_n}^p + \\abs{y_n}^p \\right)} \\\\\n\t\t\t&\\leq \\sum_{n=1}^{\\infty}2^p (\\abs{x_n}^p + \\abs{y_n}^p) \\\\\n\t\t\t&= 2^p \\underset{< \\infty}{\\underbrace{\\sum_{}^{}\\abs{x_n}^p}}+ 2^p \\underset{< \\infty}{\\underbrace{\\sum_{}^{}\\abs{y_n}^p}} < \\infty\n\t\t\\end{align*}\n\t\tand \\[\n\t\t\t\\sum_{n=1}^{\\infty} \\abs{\\lambda x_n}^p = \\sum_{n=1}^{\\infty} \\abs{\\lambda}^p \\cdot \\abs{x_n}^p = \\abs{\\lambda}^p \\sum_{n=1}^{\\infty}\\abs{x_n}^p < \\infty.\n\t\t\\]\n\t\t\\item Function spaces, say real-valued functions on $I$.\n\t\t\\begin{description}\n\t\t\t\\item[addition:] $(f+g)(x) = f(x)+ g(x), \\qquad x \\in I$\n\t\t\t\\item[mult. by scalar:] $(\\lambda f)(x)= \\lambda f(x) \\qquad $ for functions $f$ and $g$ \n\t\t\\end{description}\n\t\t\\item $C(I):$ addition and mult. by scalar as in $(5)$. \\\\ $f,g$ continuous in $I$ implies that $f+g$ is continuous in $I$. \\\\\n\t\tAlso if $f$ is continuous and $\\lambda \\in \\mathbb{R}$ then $(\\lambda f)$ is continuous in $I$.\n\t\t\\item $P(I)= \\,$ polynomials in $I$.\n\t\t\\item $P_k(I)= \\,$ polynomials of degree at most $k$ in $I$.\n\t\\end{enumerate}\n\\end{beispiele}\n", "meta": {"hexsha": "30c08f3495d3677a5f72d2a93b2d9df31303ac3a", "size": 16345, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AF/splits/lecture1.tex", "max_stars_repo_name": "TiKeil/LatexGU", "max_stars_repo_head_hexsha": "556ad083ea9478a99ea17e2c9b4bb22a964045ae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-01T03:52:33.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-01T03:52:33.000Z", "max_issues_repo_path": "AF/splits/lecture1.tex", "max_issues_repo_name": "TiKeil/LatexGU", "max_issues_repo_head_hexsha": "556ad083ea9478a99ea17e2c9b4bb22a964045ae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "AF/splits/lecture1.tex", "max_forks_repo_name": "TiKeil/LatexGU", "max_forks_repo_head_hexsha": "556ad083ea9478a99ea17e2c9b4bb22a964045ae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8507462687, "max_line_length": 199, "alphanum_fraction": 0.5490975834, "num_tokens": 7499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849805, "lm_q2_score": 0.8774767954920548, "lm_q1q2_score": 0.8069649870537456}}
{"text": "\\subsection{Maximum Likelihood Estimators}\n\\label{sec:maxmean}\n\n\\subsubsection{Gaussian Data}\n\nThe joint likelihood for a set of Gaussian-distributed data is simply\nthe product of the individual probabilities:\n\n\\begin{eqnarray}\nL \\equiv \\prod{p_k} &\\propto& \\prod_k{e^{-(x_k - \\mu)^2/2\\sigma^2_k}} \\\\\n                    &=& e^{-\\sum_k{(x_k - \\mu)^2/2\\sigma^2_k}} \\\\\n                    &\\equiv& e^{-\\chi^2/2} \\\\\n\\end{eqnarray}\n\nThe maximum likelihood estimate of a set of parameters is therefore,\nby definition, the parameters that minimize $\\chi^2$.\n\n\\subsubsection{Poisson Data}\n\nWhat if our data are Poisson distributed, say a an X-ray image, where\neach pixel is the number of photons, and does not necessarily contain\nenough photons that the gaussian approximation is even remotely\njustified?  In this case, the joint likelihood is still the product of\nthe individual probabilities, but where each probability is given by\nthe Poisson pdf:\n\n\\begin{equation}\nL \\equiv \\prod_k{p_k} = \\prod_k{{{e^{-\\mu_k}\\mu_k^k}\\over{k!}}}\n\\end{equation}\n\nHere $\\mu_k$ is the mean expected count rate in pixel $k$, the sum of\nthe model prediction and the background count rate.\n\n\\subsubsection{Joint Likelihood Calculation}\n\nFor chains that involve a combination of Gaussian and\nPoisson-distributed data, the likelihood is straightforwardly calculated as\n\n\n\\begin{equation}\nL \\equiv \\prod_i{L_i},\n\\end{equation}\n\nwhere $i$ ranges over the independent datasets, with $L_i$ calculated\nas above for Gaussian or Poisson datasets.  For purposes of reported\ngoodness of fit ($\\chisq$), an equivalent $\\chisqnor$ distributed is\nconstructed for Poisson data, noting that:\n\n\\begin{equation}\nf_N(\\chisqnor) = {1\\over{2\\Gamma(N/2)}}e^{-\\chisqnor/2}\\left({\\chisqnor\\over{2}}\\right)^{N/2-1}\n\\end{equation}\n\nand\n\n\\begin{equation}\nP(\\mu;k) = {1\\over{k!}}e^{-\\mu} \\mu^{k}\n\\end{equation}\n\nwith the identification of\n\n\\begin{equation}\n\\chisqnor = 2\\mu\n\\end{equation}\n\nand \n\n\\begin{equation}\nN = 2(k + 1)\n\\end{equation}\n\n", "meta": {"hexsha": "dc9fde8c830bdd0198faf86f9e6e87142e80f5fd", "size": 1988, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "help/likelihood.tex", "max_stars_repo_name": "erikleitch/climax", "max_stars_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-01T05:15:31.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-01T05:15:31.000Z", "max_issues_repo_path": "docs/likelihood.tex", "max_issues_repo_name": "erikleitch/climax", "max_issues_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/likelihood.tex", "max_forks_repo_name": "erikleitch/climax", "max_forks_repo_head_hexsha": "66ce64b0ab9f3a3722d3177cc5215ccf59369e88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-02T19:35:55.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-07T00:54:51.000Z", "avg_line_length": 28.0, "max_line_length": 95, "alphanum_fraction": 0.7238430584, "num_tokens": 591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947132556618, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.8069430318511192}}
{"text": "%!TEX root = Calculus_I.tex\n\\chapter{The Derivative}\n\\section{How do We Measure Speed?}\n\\textbf{\\textit{Speed}} is the magnitude of \\textbf{\\textit{velocity}}, and is a scalar quantity. \\textbf{\\textit{Velocity}} is a vector quantity, meaning it has magnitude \\textit{and} direction. Thus, velocity can be negative if an object is moving opposite the positive direction. If $s(t)$ is the position of an object at time $t$, then the \\textbf{\\textit{average velocity}} of the object over the interval $t \\in \\left[a, b\\right]$ is:\n\\begin{equation}\n\\label{eq:DQ}\nV_{avg} = \\frac{\\Delta s}{\\Delta t} = \\frac{s(b) - s(a)}{b - a}\n\\end{equation}\n\nThis representation does not help to understand the velocity of an object at a given instant in time, only over the interval $[a, b]$. For this problem of \\textbf{\\textit{instantaneous velocity}}, we need to look closer at the specified time instant, $t$.\n\n\\vspace{0.1in}\nOne way to converge to the instantaneous velocity at time $t$ is to use the definition of the \\textbf{\\textit{limit}}. As the interval $[a,b]$ gets sufficiently small and encloses the time $t$, a two-sided limit is being taken to determine the \\textbf{\\textit{instantaneous velocity}}; therefore, if $s(t)$ is the position at time $t$, the \\textbf{\\textit{instantaneous velocity}} at time $t = a$ can be defined as:\n\\begin{equation}\n\\lim_{h\\rightarrow 0} \\frac{s(a+h) - s(a)}{h}\n\\end{equation}\nThis approximation is valid as $h\\rightarrow 0$ because most functions, $f(x)$, appear linear for small changes between $x$ values. This approximation yields the slope of the curve $f(x)$ at a point, $x = a$. Using this definition, we can redefine the \\textbf{\\textit{average velocity}} over any time interval $t \\in [a, b]$ as:\n\n\\vspace{0.1in}\n\\textbf{\\textit{Average Velocity}} -- the slope of the line joining the points on the graph of $s(t)$ corresponding to $t = a$ and $t = b$.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{The Derivative at a Point}\nIn this section, the \\textbf{\\textit{difference quotient}} shown in Equation (\\ref{eq:DQ}) is applied to functions that are not necessarily functions of time. We are still interested in intervals of length $[a, a+h]$ where $h$ is sufficiently small. For any function $f$, the \\textbf{\\textit{difference quotient}} is given by $\\frac{\\Delta f}{\\Delta x}$.\n\n\\vspace{0.1in}\nThe numerator of the \\textbf{\\textit{difference quotient}} is the \\textbf{\\textit{absolute change}} of the function, whereas the full \\textbf{\\textit{difference quotient}} is the average rate of change. When the interval $[a, a+h]$ is sufficiently small, that is $h \\rightarrow 0$, we arrive at the \\textbf{\\textit{instantaneous rate of change}}. This is referred to as the \\textit{derivative of function f at point a}, and is denoted by $f^\\prime(a)$.\n\n\\begin{equation}\n\\label{eq:derivative}\nf^\\prime(a) = \\lim_{h\\rightarrow 0} \\frac{f(a+h) - f(a)}{h}\n\\end{equation}\n\nIf the \\textbf{\\textit{limit}} in Equation (\\ref{eq:derivative}) exists, then $f$ is said to be \\textbf{differentiable at a}. The \\textbf{\\textit{derivative}} at point $a$ can be interpreted as the slope of the curve $f(x)$ at point $a$, or the slope of the tangent line to the curve at point $a$ if $h \\ll 1$.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{The Derivative Function}\nThe previous section focused on the \\textbf{\\textit{derivative}} at a fixed point, $a$. This section will cover how the \\textbf{\\textit{derivative}} changes at different points because it is also a function of the independent variable. Using the definition of the \\textbf{\\textit{derivative}} at a point, we can arrive at the following extention to functions:\n\\begin{equation}\n\\label{eq:deriv_function}\nf^\\prime(x) = \\lim_{h \\rightarrow 0} \\frac{f(x+h) - f(x)}{h}\n\\end{equation}\nThus, for every $x$ value that the limit in Equation (\\ref{eq:deriv_function}) exists, we can state that the function $f$ is \\textit{differentiable at} that $x$ value. If there are no points that $f$ is \\textbf{\\textit{undifferentiable}}, then $f$ is \\textit{differentiable everywhere}, which is often the case.\n\n\\vspace{0.1in}\nThe derivative tells us how the function $f(x)$ is changing with $x$. If $f^\\prime > 0$ over an interval $[a, b]$, then $f$ is \\textbf{\\textit{increasing}} over that interval. Conversely,  If $f^\\prime < 0$ over an interval $[a, b]$, then $f$ is \\textbf{\\textit{decreasing}} over that interval. The magnitude of $f^\\prime$ indicates how much the function increases ($|f^\\prime| \\gg 0 \\rightarrow f$ is changing rapidly; ($|f^\\prime| \\ll 1 \\rightarrow f$ is changing slowly).\n\n\\vspace{0.1in}\nFor constant functions, $f(x) = k$, the \\textbf{\\textit{derivative}} is equal to zero because the function values do not change with changes in $x$. For linear functions, $f(x) = mx + b$, the \\textbf{\\textit{derivative}} is $m$ because it is the slope of the tangent line to $f(x)$, which is linear. For $n-degree$ polynomials, $n > 1$, the derivative can be estimated numerically by function evaluations using Equation (\\ref{eq:deriv_function}).\n\n\\vspace{0.1in}\nFor power functions, $f(x) = x^n$, the \\textbf{\\textit{Binomial Theorem}} can be used to show the \\textbf{\\textit{Power Rule of Differentiation}}, which is valid for $n \\in \\mathbb{R}$:\n\\begin{equation}\n\\text{If} \\hphantom{-} f(x) = x^n, \\hphantom{-} \\text{then} \\hphantom{-} f^\\prime(x) = n x^{n-1}\n\\end{equation}\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Interpretations of the Derivative}\nAnother commonly used notation for the \\textbf{\\textit{derivative}} is \\textbf{\\textit{Leibniz's Notation}}:\n\\begin{equation}\nf^\\prime(x) = \\frac{dy}{dx}\n\\end{equation}\nHere, $d$ suggests ``\\textit{small difference in}.\" An alternative form of \\textbf{\\textit{Leibniz's Notation}}:\n\\begin{equation}\n\\frac{dy}{dx} = \\frac{d}{dx}(y)\n\\end{equation}\nwhich means ``\\textit{the derivative of y with respect to x}\". The terms $dy$ and $dx$ in this notation are often used a seperate entities in mathematics, representing infinitesimally small changes in $y$ and $x$, respectively. Relating this back to previous examples, velocity can be writen as:\n\\begin{equation}\nv = \\frac{ds}{dt}\n\\end{equation}\n\n\\vspace{0.1in}\nTo specify the derivative at a point, $c$, we can write:\n\\begin{equation}\n\\at{\\frac{dy}{dx}}{x=c} % Manually defined command in preamble of Calculus_I.tex\n\\end{equation}\nThe units of the \\textbf{\\textit{derivative}} of a function depend on the units of the dependent and independent variables, but it is always given by:\n\\begin{equation}\n\\frac{Y\\hphantom{-} \\text{units}}{X\\hphantom{-} \\text{units}}\n\\end{equation}\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{The Second Derivative}\nBecause the \\textbf{\\textit{derivative}} is a function, we can also consider its \\textbf{\\textit{derivative}}. The \\textbf{\\textit{derivative}} of the \\textbf{\\textit{derivative}} results in the \\textbf{\\textit{second derivative}}, which is denoted by:\n\\begin{equation}\n\\label{eq:second_deriv}\nf^{\\prime\\prime}(x) = \\frac{d^2 y}{dx^2} = \\frac{d}{dx}\\left(\\frac{dy}{dx}\\right)\n\\end{equation}\n\nThe \\textbf{\\textit{second derivative}} provides the same information about the \\textbf{\\textit{derivative}} as the \\textbf{\\textit{derivative}} provides about $f(x)$, namely:\n\\begin{enumerate}\n\\item  If $f^{\\prime\\prime} > 0$ on an interval $[a,b]$, then $f^\\prime$ is \\textbf{\\textit{increasing}} over $[a,b]$.\n\\item  If $f^{\\prime\\prime} < 0$ on an interval $[a,b]$, then $f^\\prime$ is \\textbf{\\textit{decreasing}} over $[a,b]$.\n\\end{enumerate}\nWith this information, we can determine if $f(x)$ is \\textbf{\\textit{concave up}} or \\textbf{\\textit{concave down}}.\n\\begin{enumerate}\n\\item  If $f^{\\prime\\prime} > 0$ on an interval $[a,b]$, then $f(x)$ is \\textbf{\\textit{concave up}} over $[a,b]$.\n\\item  If $f^{\\prime\\prime} < 0$ on an interval $[a,b]$, then $f(x)$ is \\textbf{\\textit{concave down}} over $[a,b]$.\n\\end{enumerate}\nIf $f^{\\prime\\prime} = 0$, then this is an \\textbf{\\textit{inflection point}}, where the function $f(x)$ changes the direction of curvature, or a \\textbf{\\textit{saddle point}}, where the \\textbf{\\textit{derivative}} is zero, but concavity does not change.\n% TODO: Verify that saddle point definition is true in general.\n\n\\vspace{0.1in}\nRelating the \\textbf{\\textit{second derivative}} back to speed and velocity, and using the definition in Equation (\\ref{eq:second_deriv}), the acceleration of an object can be given by:\n\\begin{equation}\na(t) = v^\\prime(t) = s^{\\prime\\prime}(t) = \\frac{d^2 s}{dt^2} = \\frac{d}{dt}\\left(v\\right) = \\frac{d}{dt}\\left(\\frac{ds}{dt}\\right)\n\\end{equation}\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Differentiability}\nA function $f$ is \\textbf{\\textit{differentiable}} at $x$ if the following \\textbf{\\textit{limit}} exists:\n\\begin{equation}\n\\lim_{h \\rightarrow 0} \\frac{f(x+h) - f(x)}{h}\n\\end{equation}\nThus, the graph of $f$ has a non-vertical tangent line at $x$. The value of the \\textbf{\\textit{limit}} and the slope of the tangent line are the \\textbf{\\textit{derivative}} of $f$ at $x$.\n\n\\vspace{0.1in}\nAdditionally, the function must be continuous at the point $x$ and not have a \\textbf{\\textit{sharp corner}} at $x$. \\textbf{\\textit{Sharp corners}} occur when each \\textbf{\\textit{one-sided limit}} approaches different values, that is $L^+ \\neq L^-$. An example of this type of function is:\n\\begin{equation}\nf(x) = |x|\n\\end{equation}\nwhich has a \\textbf{\\textit{sharp corner}} at $x = 0$.\n\n\\vspace{0.1in}\nIf a function $f(x)$ is \\textbf{\\textit{differentiable}} at $x = a$, then $f(x)$ is \\textbf{\\textit{continuous}} at $x = a$; however $f(x) = |x|$ is continuous at $x =0$, but undifferentiable.\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}", "meta": {"hexsha": "f700a7bac4156522abb587b6e9b7d0ce228707b0", "size": 9917, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus I/Notes/chapter2.tex", "max_stars_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_stars_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-06T01:05:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-06T01:05:34.000Z", "max_issues_repo_path": "Calculus I/Notes/chapter2.tex", "max_issues_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_issues_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Calculus I/Notes/chapter2.tex", "max_forks_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_forks_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.5570469799, "max_line_length": 474, "alphanum_fraction": 0.7151356257, "num_tokens": 3080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.8807970842359877, "lm_q1q2_score": 0.8069066825422291}}
{"text": "\\section{Monte Carlo Methods}\nMonte Carlo (MC) methods in the context of this paper generally work by randomly sampling $N$ values from a distribution\nand averaging the results\n(unless otherwise noted values are sampled evenly from the interval $[0,1)$).\nFrom a theoretical standpoint this is equivalent to an integration because for $N \\rightarrow \\infty$ the result of\nMC and numerical integration via quadrature are the same (ignoring floating point error).\nThe only meaningful difference between MC and a quadrature is that MC samples randomly from the distribution\nwhile a quadrature samples evenly.\nThe methods introduced in this section are taken from \\cite{james}.\n\nIn one dimension a quadrature is clearly superior to MC.\nThe error of MC is $O(N^{-\\frac{1}{2}})$ while the error of even a simple quadrature like the trapezoid rule is $O(N^{-2})$.\nHowever, the error of MC notably does \\textit{not} depend on the dimensionality $d$ of the problem.\nQuadratures on the other hand need a number of points that increases exponentially with $d$ to achieve the same precision.\nIf $N$ is constant the precision instead decreases by a factor of $N^\\frac{1}{d}$.\n\\begin{table}\n\t\\caption{\n\t\tComparison of the precision of numerical integration over a $d$-dimensional volume\n\t\twith a fixed number of points $N$ when using MC or a quadrature rule.\n\t}\n\t\\centering\n\t\\begin{tabular}{cc}\n\t\tMethod & Precision\\\\\n\t\tMonte Carlo & $O(N^{-\\frac{1}{2}})$\\\\\n\t\tTrapezoid rule & $O(N^{-\\frac{2}{d}})$\\\\\n\t\tSimpson rule & $O(N^{-\\frac{4}{d}})$\\\\\n\t\tGauss rule ($m$th order) & $O(N^{-\\frac{2m-1}{d}})$\\\\\n\t\\end{tabular}\n\t\\label{tab:mc_vs_quad}\n\\end{table}\nTable \\ref{tab:mc_vs_quad} compares the precision of some quadratures to MC for multi-dimensional problems.\nWhile more sophisticated quadrature rules are more precise for $d \\rightarrow \\infty$ all quadratures will be less precise than MC.\nTypically problems have a high dimensionality when they have many coupled degrees of freedom,\ne.g. particle physics event generators, simulation of galaxies, or weather forecasting.\n\\subsection{Hit-And-Miss Monte Carlo}\nA very basic MC technique is to randomly sample points $\\bf p$ and to simply count the points fulfilling some criterion\n$f : t_\\mathbf{p} \\rightarrow \\mathbf{bool}$.\nThis is called \\textit{hit-and-miss MC}.\nBecause each point has the same likelihood of being accepted the number of accepted points will follow a binomial distribution\nwith probabilities $p$ and $q = 1 - p$.\nThe standard deviation of hit-and-miss MC can then be estimated as $s = \\sqrt{\\frac{pq}{N}}$.\n\nAs an example, let us consider the estimation of $\\pi$ by sampling points in the $xy$ plane.\nPoints with $x^2 + (y - 1)^2 < 1$ are accepted as being inside the unit circle around $(0, 1)$.\nThe unit circle has an area of $\\pi$ and one fourth of it lies inside the sampled area.\nWith the number of accepted points $N_\\mathrm{Acc}$ we can thus calculate $\\pi$ and the corresponding standard deviation $s_\\pi$ as:\n\\begin{equation}\n\t\\pi = 4 \\frac{N_\\mathrm{Acc}}{N}, \\quad s_\\pi = 4 \\frac{pq}{N}.\n\\end{equation}\n\\begin{figure*}\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{pi_hit_and_miss.png}\n\t\\caption{\n\t\tVisualization of hit-and-miss MC.\n\t\tRandomly sampled points are accepted if they are inside the circle around the upper left corner.\n\t}\n\t\\label{fig:pi_hit_and_miss}\n\\end{figure*}\nA graphical representation of this example is shown in Figure \\ref{fig:pi_hit_and_miss}.\nFor $N = 1000$ hit-and-miss MC yields a precision of $s_\\pi = 1.7\\%$.\n\\subsection{Crude Monte Carlo}\nIf we can formulate our problem as an integration we can improve upon hit-and-miss MC.\nThe idea is to randomly sample values $x_i$ from the area to be integrated\nand to average the results of the function $f : t_x \\rightarrow \\mathbf{float}$.\nThe integral $I$ can then be estimated as:\n\\begin{equation}\n\tI = \\frac{1}{N} \\sum_{i=1}^N f(x_i).\n\\end{equation}\nThe uncertainty $s_I$ of the result depends on the function variance $V[f(x)]$:\n\\begin{equation}\n\ts_I(N) = \\sqrt{\\frac{V[f(x)]}{N}}, \\quad V[f(x)] = E \\left[ (f(x) - E[f(x)])^2 \\right].\n\\end{equation}\nIf we again consider our example of calculating $\\pi$ we find that we can rearrange our condition as:\n\\begin{equation}\n\ty = f(x) = 1 - \\sqrt{1 - x^2}.\n\\end{equation}\nWith $\\pi = 4 (1 - I), \\: s_\\pi = 4 s_I$ we then find that crude MC has a precision of $s_\\pi = 0.9\\%$ for $N = 1000$.\nCompared to hit-and-miss MC the uncertainty is roughly cut in half.\n\\subsection{Importance Sampling}\nBecause the function variance depends on the deviations from the expectation $E[f(x)]$\nthe result of crude MC will converge faster for flat functions.\nA trick to reduce the function variance is to use what is known as \\textit{importance sampling}:\ninstead of sampling evenly from the interval to be integrated,\nvalues are sampled with an uneven probability density function (PDF) $g(x)$.\nIn order to compensate for the uneven sampling the sampled function values are then scaled with a factor of $\\frac{1}{g(x)}$.\nThe effective function variance then becomes $ V \\left[ \\frac{f(x)}{g(x)} \\right] $.\nTo minimize the function variance $g(x) \\approx f(x)$ should be chosen.\n\nImportance sampling can be applied to our example for crude MC by choosing $g(x) = \\frac{1}{3} x^2$\n(see Figure \\ref{fig:pi_variance_reduction}).\n\\begin{figure*}\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{pi_variance_reduction.png}\n\t\\caption{\n\t\tVisualization of crude MC with variance reduction.\n\t\tThe ratio of $f(x)$ and $g(x)$ is much flatter than the individual functions.\n\t\tSamples concentrate towards high $x$ values where $g(x)$ is high.\n\t}\n\t\\label{fig:pi_variance_reduction}\n\\end{figure*}\nWith the same number of points $N = 1000$ this drastically reduces the uncertainty of our result to $s_\\pi = 0.1\\%$\n- an almost tenfold improvement in precision.\n\\subsection{VEGAS Algorithm}\nWhile importance sampling is a powerful technique it can be very difficult to find a suitable PDF $g(x)$,\nparticularly for problems with high dimensionality.\nThe VEGAS algorithm implements importance sampling without a known suitable PDF.\nInstead it iteratively adapts a step function to the function to be integrated.\nThis step function is defined by a number of bin edges:\n\\begin{equation}\n\t0=x_1<x_2 < ... < x_{M+1}=1, \\quad \\Delta x_i = x_{i+1} - x_{i},\n\\end{equation}\nwhere each bin is given the same probability content $\\frac{1}{M}$.\nThe PDF derived from these bins is thus:\n\\begin{equation}\n\tg(x) = \\frac{1}{M \\Delta x_i}.\n\\end{equation}\nIn order to adapt $g(x)$ to $f(x)$ the bin edges $x_i$ are now iteratively adapted.\nInitially all bins have the same size so $g(x)$ is flat.\nAfter drawing some samples the bin edges $x_i$ are then moved in such a way that the contribution\nof each bin to the integral becomes roughly equal:\nregions with a large contribution to the integral receive a high density of bins and samples\nwhile regions with a small contribution to the integral receive a low density of bins and samples.\nThe sampling and resizing of bins is repeated iteratively until the algorithm terminates.\nA graphical representation of the VEGAS algorithm is shown in Figure \\ref{fig:pi_vegas}.\n\\begin{figure*}\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{pi_vegas.png}\n\t\\caption{\n\t\tVisualization of the VEGAS algorithm with 3 iterations.\n\t\tThe PDF $g(x)$ is initially flat.\n\t\tIn the second and third iterations the shape of $g(x)$ is much closer shape of $f(x)$.\n\t}\n\t\\label{fig:pi_vegas}\n\\end{figure*}\n", "meta": {"hexsha": "08f75001465be29fa9cfe6e67f80870805f991ec", "size": 7462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX/Parts/02_monte_carlo.tex", "max_stars_repo_name": "JohannesGaessler/presentation_mc", "max_stars_repo_head_hexsha": "0d43f3b70d71f063f872a5fb8b09cde3b756ee36", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LaTeX/Parts/02_monte_carlo.tex", "max_issues_repo_name": "JohannesGaessler/presentation_mc", "max_issues_repo_head_hexsha": "0d43f3b70d71f063f872a5fb8b09cde3b756ee36", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LaTeX/Parts/02_monte_carlo.tex", "max_forks_repo_name": "JohannesGaessler/presentation_mc", "max_forks_repo_head_hexsha": "0d43f3b70d71f063f872a5fb8b09cde3b756ee36", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.2740740741, "max_line_length": 132, "alphanum_fraction": 0.7457786116, "num_tokens": 2020, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397307, "lm_q2_score": 0.9046505447409666, "lm_q1q2_score": 0.8067773584665446}}
{"text": "\\chapter{Basis and Dimension}\n\n\\begin{definition}\n\tLet $V$ be a vector space and $U \\subset V$ a non-empty set. We call $U$ a subspace of $V$ if it is closed under linear combinations. \\\\\n\t$ \\forall \\lambda, \\mu \\in F$ and $\\forall u, v \\in V : \\lambda u + \\mu v \\in U$, where $F$ is the field where scalars come from. \n\\end{definition}\n\nSo essentially subspace is a vector space on its own. And it is closed means that we can add two elements and multiply by scalars and still remain in that space. \\\\\n\n\\textbf{Examples}\n\n\\begin{itemize}\n\t\\item $C(\\chi)$ is a subspace of $\\Re^\\chi$ where $C(\\chi)$ is the set of continuous functions on domain $\\chi$ and $\\Re^\\chi$ is any real valued function. Sum of two continuous functions is continuous and scalar multiplication of a continous function is a continous function as well. \n\t\\item The set $S$ of symmetric matrices of size $n \\times m$ is a subspace of $\\Re^{n \\times m}$. Since sum of two symmetric matrices is a symmetric matrix and the same goes for scalar multiplication.  \n\\end{itemize}\n\n\\begin{definition}\n\tLet $V$ be a vector space over $F$ and $u_1,....,u_n \\in V$, $\\lambda_1,......\\lambda_n \\in F$. Then $\\sum_{i=1}^{n} \\lambda_i u_i$ is called a linear combination. The set of all linear combinations of $u_1,....,u_n$ is called the span (linear hull) of $u_1,....,u_n$. \\\\\n\t$span(u_1,....,u_n) := \\{\\sum_{i=1}^{n} \\lambda_i u_i | \\lambda_i \\in F \\}$  \n\\end{definition}\n\nThe set $U:= \\{ u_1,....,u_n \\}$ is the generator of $span(u_1,....,u_n)$\n\n\\begin{definition}\n\tA set of vectors $v_1,.....v_n$ is called linearly independent if the following holds: \\\\\n\t$ \\sum_{i=1}^{n} \\lambda_i v_i = 0 \\implies \\lambda_1 = ..... = \\lambda_n = 0$ \\\\\n\\end{definition}\n\n\\textbf{Examples}\n\n\\begin{itemize}\n\t\\item The vectors $\\begin{bmatrix} \t1 \\\\ 0 \\\\ 0 \\end{bmatrix}, \\begin{bmatrix} \t2 \\\\ 1 \\\\ 0 \\end{bmatrix}$ and $\\begin{bmatrix} 3 \\\\ 4 \\\\ 1 \\end{bmatrix} \\in \\Re^3$ are linearly independent. \n\t\\item The functions $sin(x)$ and $cos(x) \\in \\Re^\\Re$ are linearly independent. \n\t\\item Any set of $d+1$ vectors in $\\Re^d$ is linearly dependent.  \n\\end{itemize}\n\n\\begin{definition}\n\tA subset $B$ of a vector space $V$ is called a (Hammel) basis if: \n\t\\begin{itemize}\n\t\t\\item $span(B) = V$\n\t\t\\item $B$ is linearly independent. \n\t\\end{itemize}\n\\end{definition}\n\nThis means that any vector in $V$ can be written as a linear combination of vectoes in $B$ but basis vectors themselves cannot be written in terms of each other since they are independent. \\\\ \n\n\\textbf{Examples}\n\n\\begin{itemize}\n\t\\item The canonical basis of $\\Re^3$ is  $\\begin{bmatrix} \t1 \\\\ 0 \\\\ 0 \\end{bmatrix}, \\begin{bmatrix} \t0 \\\\ 1 \\\\ 0 \\end{bmatrix}$ and $\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix}$.\n\t\\item Another basis of $\\Re^3$ is given by $\\Re^3$ is  $\\begin{bmatrix} \t1 \\\\ 0 \\\\ 0 \\end{bmatrix}, \\begin{bmatrix} \t1 \\\\ 1 \\\\ 0 \\end{bmatrix}$ and $\\begin{bmatrix} 1 \\\\ 1 \\\\ 1 \\end{bmatrix}$. \\\\\n\\end{itemize}\n\n\\begin{proposition}\n\tIf $U = \\{u_1,....u_n\\}$ spans a vector space $V$, then the set $U$ can be reduced to a basis of $V$.\n\\end{proposition}\n\n\\begin{proof}\n\tIf $U$ is already linearly independent then we are done. If $U$ is linearly dependent, $ \\exists u \\in U$ that is a linear combination of other vectors in $U$. We repeat this step untill we reach a point where all vectors in $U$ are linearly independent. \n\\end{proof}\n\n\\begin{definition}\n\tA vector space is called finite dimentional if it has a finite basis.\n\\end{definition}\n\n\\begin{proposition}\n\tLet $U = \\{u_1,...,u_n\\} \\subset V$ be a set of linearly independent vectors and let $V$ be a finite dimensional vector space. Then $U$ can be extended to a basis of $V$. \n\\end{proposition}\n\n\\begin{proof}\n\tLet $w_1,...,w_m$ be a basis of $V$. Consider a set $\\{u_1,...u_n,w_1,...,w_m\\}$. Remove vectors from the end untill remaining vectors are linearly independent. The remaining set $spans(V)$, is linearly independent by construction and contains $U$.\n\\end{proof}\n\n\\begin{corollary}\n\tLet $V$ be a finite dimensional vector space. Then any two basis of $V$ have the same length.\n\\end{corollary}\n\n\\begin{definition}\n\tThe length of the basis of a finite dimensional vector space is called its dimension. \n\\end{definition}\n\nWe have defined what a basis and we also know what a subspace is. Another notion which brings these two things together is known as the \\textit{sum} and \\textit{direct sum} of subspaces. \n\n\\begin{definition}\n\tAssume that we have two subspaces $U_1$ and $U_2$ of a vector space $V$. The sum of the two spaces is defined as : \\\\\n\t$U_1 + U_2 := \\{ u_1 + u_2 | u_1 \\in U_1, u_2 \\in U_2 \\}$\n\\end{definition}\n\nThe sum which has just seen is known as the direct sum. If each element in the sum can be written in exactly one way$(U_1\\oplus U_2)$.\n\n\\begin{proposition}\n\tSuppose $V$ is finite-dimensional, and $U \\subset V$ is a subspace, then there exists a subspace $W \\subset V$ such that $U \\oplus W =  V$.\n\\end{proposition}\n\n\\begin{proof}\n\tLet the set $\\{u_1,...u_k\\}$ be a basis of $U$. Extend it to a basis of $V$, say the resulting set is $\\{u_1,...u_k, v_1,...v_m\\}$. Define $W = span\\{v_1,...v_m\\}$ \n\\end{proof}\n", "meta": {"hexsha": "64e82caa5a6bb7b23b284494d16dae77faa1516e", "size": 5121, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter-2-basis-and-dimension.tex", "max_stars_repo_name": "agupta54/maths-for-ml", "max_stars_repo_head_hexsha": "c5e54f14e4a24a389d31a613c34c7ef40e2bc0d1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter-2-basis-and-dimension.tex", "max_issues_repo_name": "agupta54/maths-for-ml", "max_issues_repo_head_hexsha": "c5e54f14e4a24a389d31a613c34c7ef40e2bc0d1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter-2-basis-and-dimension.tex", "max_forks_repo_name": "agupta54/maths-for-ml", "max_forks_repo_head_hexsha": "c5e54f14e4a24a389d31a613c34c7ef40e2bc0d1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.2551020408, "max_line_length": 286, "alphanum_fraction": 0.685803554, "num_tokens": 1667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.8918110490322425, "lm_q1q2_score": 0.8067773427159047}}
{"text": "\\chapter{Interpolation}\n\n\\section{Introduction}\n\nIn numerical methods we often have a limited amount of information about a function, and we want to use that information to estimate, predict or compute additional quantities. For example, we may know (or be able to compute) the values of a function $f(x)$ at two points, say $x_1$ and $x_2$, and want to use this information to estimate the value of the function at a third point $x_3$.\n\nThis can be generalized to the idea of \\emph{interpolation}. We assume, for example, that we know the value of a function at $N$ points $x_j$, with $j = 0, \\dots, N-1$. We want to compute, or estimate, the value of the function at some other point $x$. This problem can be extended to multiple dimensions, or to vector functions component-by-component.\n\nWe will see later that interpolation is one way of approaching considerably more complicated problems. For example, we will typically perform interpolation by approximating the function that we are interested in (but do not know how to compute in general), $f$, with a different function $g$ that approximates $f$ (for example, equals $f$ at specific points) and that we can easily compute everywhere. We can then perform \\emph{operations} on $g$, and treat them as giving approximately the same results as operations performed on $f$. For example, the integral of $f$ can be approximated by the integral of $g$.\n\n\\section{Polynomial interpolation}\n\nWe start with the one dimensional problem. We assume we do \\emph{not} know anything about the function $f(x)$ except for its values $f_j \\equiv f(x_j)$ at the \\emph{nodes} $\\{ x_j \\}$, where $j = 0, \\dots, N$. We want to interpolate $f$ to the general location $x$.\n\nTo do this we introduce an \\emph{interpolating function} $g(x)$. The general form of the function $g$ will be given in advance: here it will be a polynomial,\n%\n\\begin{align}\n  g(x) &= c_0 + c_1 x + c_2 x^2 + \\dots \\\\ &= \\sum_k c_k x^k.\n\\end{align}\n%\nWe will then fix the specific form -- that is, the range of the sum, and the value of the constants $\\{ c_k \\}$ -- by enforcing that $g(x_j) = f_j = f(x_j)$: i.e., the value of the interpolating function equals the value of the function being interpolated at the nodes. As we know $N+1$ pieces of information about the function $f$, we can fix $N+1$ coefficients of the polynomial $g$, meaning the sum should stop at $N$ (thanks to the $0$ power coefficient).\n\nTherefore our interpolation problem becomes: given $f_j \\equiv f(x_j)$ at the \\emph{nodes} $\\{ x_j \\}$, where $j = 0, \\dots, N$, find the coefficients $c_k$ such that the polynomial\n%\n\\begin{equation}\n  g(x) = \\sum_{k=0}^{N} c_k x^k\n\\end{equation}\n%\nmatches $f$ at the nodes, i.e., $f(x_j) = g(x_j)$.\n\nWe will use $g$ to interpolate, or approximate, $f$. Therefore we are also interested in the question of how accurately it does so: what is $g(x) - f(x)$?\n\n\\subsection{Lagrange polynomials}\n\nThe easiest polynomials to work with are the Lagrange basis polynomials. There are $N+1$ of these are polynomials, each of degree $N$, defined by their value at the nodes so that\n%\n\\begin{equation}\n  l^{(\\ell)}(x_j) = \\begin{cases} 1 & x_j = x_\\ell \\\\ 0 & x_j \\ne x_\\ell \\end{cases}.\n\\end{equation}\n%\nIn words, the $\\ell^{\\text{th}}$ Lagrange basis polynomial has value $1$ at the $\\ell^{\\text{th}}$ node and vanishes at all other nodes. This immediately means that\n%\n\\begin{equation}\n  g(x) = \\sum_{\\ell=0}^{N} f(x_{\\ell}) l^{(\\ell)}(x)\n\\end{equation}\n%\nis \\emph{an} interpolating polynomial: it is a polynomial of the right degree ($N$), and when evaluated at a node $x_j$ we have\n%\n\\begin{align}\n  g(x_j) &= \\sum_{\\ell=0}^{N-1} f(x_{\\ell}) l^{(\\ell)}(x) \\\\\n  &= f_{j}\n\\end{align}\n%\nas all the basis functions vanish at all the nodes \\emph{except} for the $j^{\\text{th}}$ one which has value $1$.\n\nNow that we know that the Lagrange basis functions $l^{(\\ell)}(x)$ are what we want, we need an explicit way of constructing them. We know that they must be polynomials, so we can write them as products of the form $(x - a)$. We know that we want them to vanish at all the nodes (except one), so the obvious form of these individual terms would be $(x - x_j)$. Finally, we konw that at the $\\ell^{th}$ node we do not want them to vanish (so there should be so term of the form $(x - x_\\ell)$), but instead want the value to be one. This gives us the value of the overall scaling constant. From these considerations we see that\n%\n\\begin{equation}\n  l^{(\\ell)}(x) = \\prod_{m=0, m \\ne \\ell}^{N} \\frac{x - x_m}{x_{\\ell} - x_m}.\n\\end{equation}\n\n\\subsection{Low order examples}\n\nPutting everything together we have that $f(x) \\simeq g(x)$, where the Lagrange polynomial interpolating function is given by\n%\n\\begin{equation}\n  g(x) = \\sum_{j=0}^{N-1} f(x_{j}) \\prod_{m=0, m \\ne j}^{N-1} \\frac{x - x_m}{x_j - x_m}.\n\\end{equation}\n%\nWe can explicitly check the simple examples.\n\n\\subsubsection{Linear interpolation}\n\nTo get a linear interpolating polynomial we need the interpolating polynomial to have two coefficients (the constant and the linear part), meaning we need $N=1$. Therefore we are assuming we know $f(x)$ at the two nodes $x_0$ and $x_1$.\n\nThe Lagrange basis polynomials are\n%\n\\begin{align}\n  l^{(0)}(x) &= \\frac{x - x_1}{x_0 - x_1}, \\\\\n  l^{(1)}(x) &= \\frac{x - x_0}{x_1 - x_0}.\n\\end{align}\n%\nThis gives the interpolating polynomial as\n%\n\\begin{align}\n  g(x) &= f(x_0) \\frac{x - x_1}{x_0 - x_1} + f(x_1) \\frac{x - x_0}{x_1 - x_0}, \\\\\n  &= f(x_0) \\left( 1 - \\frac{x - x_0}{x_1 - x_0} \\right) + f(x_1) \\frac{x - x_0}{x_1 - x_0}.\n\\end{align}\n%\nThe final form of the equation can be written as $g(x) = f_0 (1 - \\Delta) + f_1 \\Delta$, where $\\Delta$ is the distance between $x$ and $x_0$ relative to the distance between $x$ and $x_1$.\n\n\\subsubsection{Quadratic interpolation}\n\nFor quadratic interpolation we have $N=2$, which requires assuming knowledge of $f(x)$ at $x_0, x_1$ and $x_2$. The Lagrange basis polynomials are\n%\n\\begin{align}\n  l^{(0)}(x) &= \\frac{(x - x_1)(x - x_2)}{(x_0 - x_1)(x_0 - x_2)}, \\\\\n  l^{(1)}(x) &= \\frac{(x - x_0)(x - x_2)}{(x_1 - x_0)(x_1 - x_2)}, \\\\\n  l^{(2)}(x) &= \\frac{(x - x_0)(x - x_1)}{(x_2 - x_0)(x_2 - x_1)}.\n\\end{align}\n%\nThis gives the interpolating polynomial as\n%\n\\begin{align}\n  g(x) &= f(x_0) \\frac{(x - x_1)(x - x_2)}{(x_0 - x_1)(x_0 - x_2)} + f(x_1) \\frac{(x - x_0)(x - x_2)}{(x_1 - x_0)(x_1 - x_2)} + f(x_2) \\frac{(x - x_0)(x - x_1)}{(x_2 - x_0)(x_2 - x_1)}.\n\\end{align}\n%\nIn the special case where the points are equally spaced, $x_1 - x_0 = h = x_2 - x_1$, implying that $x_2 - x_0 = 2 h$, and using the coordinate $\\hat{x} = x - x_1$, we get\n%\n\\begin{equation}\n  g(x) = \\frac{1}{2 h^2} \\left( f_0 \\hat{x} (\\hat{x} - h) - 2 f_1 (\\hat{x} + h) (\\hat{x} - h) + f_2 (\\hat{x} + h) \\hat{x} \\right).\n\\end{equation}\n%\nThis particular form is useful for integration and differentiation. For example,\n%\n\\begin{align}\n  \\eval{\\dv{g}{x}}_{x = x_1} &= \\eval{\\dv{g}{x}}_{\\hat{x} = 0} \\\\\n  &= \\left. \\frac{1}{2 h^2} \\left( f_0 (2 \\hat{x} - h) - 2 f_1 (2 \\hat{x}) + f_2 (2 \\hat{x} + h) \\right) \\right|_{\\hat{x} = 0} \\\\\n  &= \\frac{1}{2 h} \\left( f_2 - f_0 \\right).\n\\end{align}\n\n\\section{Accuracy}\n\nWe want to know how close the interpolating polynomial $g(x)$ gets to the function $f$ that it is interpolating: that is, we want to know the size of the error $e(x) = f(x) - g(x)$. As $f$ is completely general, we will never know this exactly: however, we can make some general points.\n\nFirst, we have explicitly chosen $g$ such that it agrees with $f$ at all of the nodes. That means the error must have the form\n%\n\\begin{equation}\n  e(x) = f(x) - g(x) = F(x) \\prod_{j=0}^N (x - x_j).\n\\end{equation}\n%\nThat is, the error function vanishes at the nodes, $e(x_j) \\equiv 0$.\n\nSecond, we note that at any fixed point $X$, we can use a Taylor series expansion that matches the terms in the polynomial $g$. That is (under some assumptions), there is a value $\\xi$ such that\n%\n\\begin{equation}\n  e(X) = f(X) - g(X) = \\frac{1}{(N+1)!} \\eval{\\dv[N+1]{f}{x}}_{x=\\xi} \\prod_{j=0}^N (X - x_j).\n\\end{equation}\n%\nThe precise form matters less than the interpretation. The important point is that the error depends on (a) the magnitude of the derivative of the function being interpolated, and (b) the magnitude of the product $\\prod_{j=0}^N (x - x_j)$. The first cannot be controlled except by changing $N$. The second can be controlled both by changing $N$ and by changing the location of the nodes.\n\nWe focus on the term $|\\prod_{j=0}^N (x - x_j)|$. If we make the nodes equally spaced then each term $x - x_j \\propto h$, where $h = x_{j+1} - x_j$. This means the error is $e(x) \\propto h^{N+1}$ and we expect the error to decay rapidly if $h$ is sufficiently small. In particular this implies that the larger $N$ is, the faster the error will decay as we make $h$ smaller. Whilst this is usually true, by ignoring the other terms in the error we may be ignoring larger errors, and even ones that grow: the Runge phenomenon is one example of this.\n\nWe also note (without proof!) that we can reduce the error by \\emph{not} choosing the nodes to be equally spaced. For example, if we restrict the nodes to lie within $(-1, 1)$, by choosing the Chebyshev nodes\n%\n\\begin{equation}\n  x_j = \\cos \\left( \\frac{2 j + 1}{2 (N + 1)}) \\pi \\right)\n\\end{equation}\n%\nthe error $e(x)$ will behave as $e(x) \\propto 2^{-N} / N!$. Using appropriate non-equally spaced nodes is often better in terms of accuracy, but may be more work to set up for integration and differentiation.\n", "meta": {"hexsha": "e86d08c6950fadd8d054929e72d3c9704dc960c0", "size": 9498, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/Interpolation.tex", "max_stars_repo_name": "josh-gree/NumericalMethods", "max_stars_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 76, "max_stars_repo_stars_event_min_datetime": "2015-02-12T19:51:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T15:34:11.000Z", "max_issues_repo_path": "Notes/tex/Interpolation.tex", "max_issues_repo_name": "josh-gree/NumericalMethods", "max_issues_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-05-24T19:49:52.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-23T21:40:42.000Z", "max_forks_repo_path": "Notes/tex/Interpolation.tex", "max_forks_repo_name": "josh-gree/NumericalMethods", "max_forks_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2015-01-05T13:30:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T09:59:39.000Z", "avg_line_length": 62.9006622517, "max_line_length": 626, "alphanum_fraction": 0.684038745, "num_tokens": 3068, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.9046505299595163, "lm_q1q2_score": 0.8067773296766177}}
{"text": "\n\\subsection{Inner products}\n\nAn inner product is a sesquilinear form with a positive-definite Hermitian matrix.\n\n\\( \\langle u, v \\rangle =u^*Hv\\)\n\nIf we are using the real field this is the same as:\n\n\\( \\langle u, v \\rangle =u^THv\\)\n\nWhere \\(H\\) is now a symmetric real matrix.\n\n\\subsubsection{Same}\n\n\\( \\langle v, v \\rangle =v^*Hv\\)\n\nAlways positive and real.\n\\subsubsection{Properties}\n\n\\(\\langle u, v\\rangle \\langle v, u\\rangle=|\\langle u, v\\rangle|^2\\)\n\n", "meta": {"hexsha": "68ebc00175277d96f3699d3198722325f7e8a132", "size": 459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/04-05-innerProducts.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/forms/04-05-innerProducts.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/forms/04-05-innerProducts.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.9565217391, "max_line_length": 82, "alphanum_fraction": 0.6928104575, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813476288299, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.8067479773974613}}
{"text": "\\chapter{Prerequisites}\n\nThis course uses many concepts from prerequisite courses, particularly those from calculus and circuits. While we assume you know this material, the following sections offer a review of the most pertinent and establish some notation. If you have trouble with any of them seek assistance -- the sooner the better.\n\n\\section{Complex Numbers}\n\nComplex numbers are used extensively throughout the course. You need to be very adept at manipulating them.\n\n\\subsection*{The Number System}\n\nBy way of review and to motivate the discussion of complext numbers, recall the following basic facts.\n\n\\begin{itemize}\n\\item The \\emph{Natural Numbers} $\\mathbb{N}$ are the positive integers $1,2,3,4,\\cdots$. Given two natual numbers $a$ and $b$ the sum $a+b$ and the product $a\\,b$ are also natural numbers, that is the set of natural numbers is \\emph{closed} under addition and multiplication.\n\n\\item Solving equations of the form $x + a = b$ for any natural numbers $a,b$ requires the introduction of the negative integers $\\cdots, -4, -3, -2 -1$ and $0$. These plus the natural numbers give the \\emph{integers}  $\\mathbb{Z}$. Note $\\mathbb{N} \\subset \\mathbb{Z}$. Zero ($0$) is called the identity element with respect to addition, while $1$ is the identity with respect to multiplication, that is $a+0 = a$ and $ a \\cdot 1 = a$. The \\emph{inverse} of an integer $a$ is $-a$, such that thier sum gives the identity for addition, i.e. $a + -a = 0$.\n\n\\item The \\emph{rational numbers} $\\mathbb{Q}$ are of the form $\\frac{b}{a}$ for integers $a,b$ with $a \\neq 0$. They solve problems of the form $ax=b$ and provide the inverse for multiplication since $\\frac{1}{a} \\cdot a = 1$. Note $\\mathbb{Z} \\subset \\mathbb{Q}$\n\n\\item The \\emph{irrational numbers} are those that cannot be written as a rational number, for example $\\sqrt{2} = 1.414\\ldots$ and $\\pi = 3.14159\\ldots$\n\n\\item The union of the rational and irrational numbers give the \\emph{real numbers} denoted $\\mathbb{R}$.\n\\end{itemize}\n\nGraphically the numbers and thier ordering can be expressed using the number line:\n\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/number-line.pdf}\n\\end{center}\n\n\\subsection*{Complex numbers as extension of reals}\n\nContinuing the pattern of the basic number system we can ask what are solutions of equations of the form $x^2+a = 0$ or $x^2 + 2ax +a^2 + b^2 = 0$ for $a,b \\in \\mathbb{R}$ ? As above, finding such solutions requires moving to a larger set of numbers, the \\emph{complex numbers} denoted $\\mathbb{C}$.\n\nA complex variable $z\\in\\mathbb{C}$ can be written as $z = a + j\\, b$ for $a,b\\in\\mathbb{R}$, where $j$ is the imaginary unit and $j^2 = -1$. Note in mathematics the imaginary unit is denoted $i$; this difference is purely historical. Some basic definitions:\n\n\\begin{itemize}\n\\item the \\emph{real part} $\\Re(z) = \\text{Re}(z) = a$\n\\item the \\emph{imaginary part} $\\Im(z) = \\text{Im}(z) = b$\n\\item two complex numbers $z_1, z_2\\in \\mathbb{C}$ are equal if $\\text{Re}(z_1) = \\text{Re}(z_2)$ and $\\text{Im}(z_1) = \\text{Im}(z_2)$\n\\item $\\mathbb{R} \\subset \\mathbb{C}$, when $b = 0$ and we say that the number is purely real\n\\item if $a = 0$ we say the number is purely imaginary\n\\item the \\emph{complex conjugate} of $z = a + jb$ is $z^* = a - jb$.\n\\end{itemize}\n\n\\subsection*{Operations on complex numbers}\n\nArithmetic operations on complex numbers are defined using the algebra of real numbers, replacing $j^2 = -1$. Given complex numbers $a + j\\, b$ and $c + j\\, d$\n\n\\begin{description}\n\\item[addition] $(a + jb) + (c +jd) = (a+c) + j(b+d)$\n\\item[subtraction] $(a + jb) - (c +jd) = (a-c) + j(b-d)$\n\\item[multiplication] $(a + jb)\\cdot(c +jd) = ac + jbc + jad + j^2 bd = (ac-bd) + j(bc+ad)$\n\\item[division] $\\frac{(a + jb)}{(c +jd)} = \\frac{ac+jbc-jad-j^2 bd}{c^2 -j^2 d^2} = \\frac{(ac+bd) + j(bc-ad)}{c^2 + d^2} = \\frac{ac+bd}{c^2 + d^2} + j \\frac{bc-ad}{c^2 + d^2}$\n\\end{description}\n\n\n\\subsection*{Basic properties of complex numbers}\n\nLet $z_1, z_2, z_3 \\in \\mathbb{C}$, then:\n\n\\begin{description}\n\\item[closure property] $z_1 + z_2 \\in \\mathbb{C}$ and  $z_1 \\cdot z_2 \\in \\mathbb{C}$ \n\\item[communative property] $z_1 + z_2 = z_2 + z_1$ and $z_1 \\cdot z_2 = z_2 \\cdot z_1$ \n\\item[associative property] $z_1 + (z_2 + z_3) = (z_1 + z_2) + z_3$ and $z_1 \\cdot (z_2 \\cdot z_3) = (z_1 \\cdot z_2) \\cdot z_3$ \n\\item[identity elements] $0 = (0 + j0) \\in \\mathbb{C}$ is the identity element for addition since $z_1 + 0 = z_1$ and $1 = 1 + j0 \\in \\mathbb{C}$ is the identity element for multiplication since $z_1\\cdot 1 = z_1$ \n\\item[inverse elements] for any $z_1$ there exists an inverse $z_2 = -z_1$ such that $z_1 + z_2 = 0$, and for any $z_1 \\neq 0$ there exists an inverse $z_2 = z_1^{-1} = \\tfrac{1}{z_1}$ such that $z_1 \\cdot z_2 = 1$\n\\end{description}\n\n\\subsection*{Absolute Value (Magnitude) of complex numbers}\n\nThe absolute value or \\textit{magnitude} of a complex number $z = a + jb$ is denoted $|z| = |a+jb|$ and is given by\n\\[\n|a + jb| = \\sqrt{a*2 + b^2}\n\\]\nFor complex numbers $z_1, z_2, \\ldots, z_n$, the following useful properties hold\n\\begin{itemize}\n\\item $|z_1\\cdot z_2 \\cdots z_N| = |a_1|\\cdot |z_2|\\cdots|z_N|$\n\\item $\\left| \\frac{z_1}{z_2}\\right| = \\frac{|z_1|}{|z_2|}$ for $z_2 \\neq 0$\n\\end{itemize}\n\n\\subsection*{Argument (Angle) of complex numbers}\nThe argument or \\textit{angle} of a complex number $z = a + jb$ is denoted $\\angle z = \\angle(a+jb)$ and is given by\n\\[\n\\angle(a + jb) = \\arctan\\frac{b}{a}\n\\]\nTake care when computing this number on your calculator (or in a programming language) so that it produces and angle in radians and in the correct quadrant. For example $\\angle(-1-j1) = \\arctan\\frac{-1}{-1} = \\frac{5\\pi}{4} = -\\frac{3\\pi}{4}$ is different from $\\angle(-1-j1) = \\arctan\\frac{-1}{-1} = \\arctan\\frac{1}{1} = \\frac{\\pi}{4}$, the later being incorrect.\n\n\\subsection*{Cartesian and Polar representation of complex numbers}\n\nA complex number $z$ can be represented in Cartesian form as a pair of numbers in the \\textit{Complex Plane}, $(\\Re{z},\\Im{z})$. The same $z$ can be represented in polar form as $z = |z|\\cdot e^{j\\angle z}$. We can convert between the representations using  $\\Re{z} = |z| \\cos(\\angle z)$ and $\\Im{z} = |z| \\sin(\\angle z)$. The following relations hold\n\n\\begin{itemize}\n\\item Multiplication by $j$ is equivalent to rotation by $\\tfrac{\\pi}{2}$\n\\[\nj\\cdot z = e^{j\\tfrac{\\pi}{2}}\\cdot |z|\\cdot e^{j\\angle z} = |z|\\cdot e^{j(\\angle z + \\tfrac{\\pi}{2})} \n\\]\n\\item Division by $j$ is equivalent to rotation by $- \\tfrac{\\pi}{2}$\n\\[\n\\frac{1}{j}\\cdot z = e^{-j\\tfrac{\\pi}{2}}\\cdot |z|\\cdot e^{j\\angle z} = |z|\\cdot e^{j(\\angle z - \\tfrac{\\pi}{2})} \n\\]\n\\end{itemize}\n\nA related expression that will be very useful to us is \\textit{Eulers formula}: $e^{j\\theta} = \\cos(\\theta) + j\\sin(\\theta)$. From this we can derive the relations:\n\\[\n\\cos(\\theta) = \\frac{1}{2} e^{j\\theta} + \\frac{1}{2} e^{-j\\theta} \n\\]\n\\[\n\\sin(\\theta) = \\frac{1}{2j} e^{j\\theta} - \\frac{1}{2j} e^{-j\\theta} \n\\]\n\nThese representations and relations can be visualized as follows\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/complex-viz-prereq.pdf}\n\\end{center}\n\n\\subsection*{Complex numbers as roots of polynomial equations}\n\nRecall our original motivation for complex numbers, as solutions to polynomials. Consider the $N^\\text{th}$ order polynomial\n\\[\nz^N + a_N z^{N-1} + \\cdots + a_2 z + a_1 \n\\]\nwhere in cases of interest to us in this course the $N$ coefficients $a_{N}, \\cdots, a_1$ are real. In such cases the polynomial can be factored into\n\\[\nz^N + a_{N} z^{N-1} + \\cdots + a_2 z + a_1 = (z-z_1)\\cdot(z-z_2)\\cdots(z-z_N)\n\\]\nwhere the $z_i$ are the $N$ \\textit{roots} of the polynomial. These are complex numbers in general with two cases:\n\n\\begin{itemize}\n\\item the root is real\n\\item the root is complex or purely imaginary, in which case they come in congugate pairs \n\\end{itemize}\n\nNote: the \\texttt{roots} function in Matlab can be used to find the roots of any order polynomial given a vector of coefficients.\n\n\\section{Functions}\n\nAs we will see in the first few lectures, signals are modelled as functions. Recall a \\textit{function} is a mapping between sets\n\\[\nf: A \\rightarrow B\n\\]\nwhere $A$ is a set called the {\\it domain} and $B$ is a set called the {\\it co-domain}. In this course we are primarily concerned with four kinds of functions\n\n\\begin{itemize}\n\\item the real-valued functions of an integer variable $f:\\mathbb{Z}\\mapsto\\mathbb{R}$\n\\item the complex-valued functions of an integer variable $f:\\mathbb{Z}\\mapsto\\mathbb{C}$\n\\item the real-valued functions of a real variable $f:\\mathbb{R}\\mapsto\\mathbb{R}$\n\\item the complex-valued functions of a real variable $f:\\mathbb{R}\\mapsto\\mathbb{C}$\n\\end{itemize}\nWe will also briefly discuss the the complex-valued functions of a complex variable $f:\\mathbb{C}\\mapsto\\mathbb{C}$.\n\nFunctions can be defined using an expression operating on the \\textit{independent variable} representing a value from the domain. For example a function $f:\\mathbb{R}\\mapsto\\mathbb{R}$ might be defined by the expression\n\\[\nf(t) = 2t^2\n\\]\nwhere $t\\in\\mathbb{R}$ is the independent variable. Common operations are sums, difference, products, quotients, powers, and application of trigonometric and transendental functions. Functions with different expressions for different intervals of the domain are called \\textit{piecewise}. For example\n\\[\nf(t) = \\left\\{ \\begin{array}{cc}\n   e^{t} & t < 0\\\\\n   e^{-t} & t \\geq 0\n\\end{array}\n\\right.\n\\]\n\nFunctions can also be defined using composition. Given two functions $f:\\mathbb{R}\\mapsto\\mathbb{R}$ and $g:\\mathbb{R}\\mapsto\\mathbb{R}$ we can define a new function\n\\[\n(f \\circ g)(t) = f(g(t)) \n\\]\nwhere we first apply $g$ then use it's value as the input to $f$. This will be used to define several transformations of signals.\n\n\\subsection*{Visualizing Functions}\n\nYou are certainly familiar with the graph of functions $f:\\mathbb{R}\\mapsto\\mathbb{R}$. To graph a complex-valued function of a single variable we need to plot two functions. Consider a function $z(t) \\in \\mathbb{C}$ for $t \\in \\mathbb{R}$ expressed in Cartesian form:\n\\[\nz(t) = z_r(t) + j z_i(t) \n\\]\nwhere $z_r(t) = \\Re(z(t))$ and $z_r(t) = \\Im(z(t))$ are the real and imaginary parts of the complex value at a given $t$. We can plot these two real-valued functions to visualize the complex function. Similarly consider a function $z(t) \\in \\mathbb{C}$ for $t \\in \\mathbb{R}$ expressed in polar form:\n\\[\nz(t) = z_m(t) e^{jz_a(t)}\n\\]\nwhere $z_m(t) = |z(t)|$ and $z_a(t) = \\angle z(t)$ are the magnitude and angle of the complex value at a given $t$. We can plot these two real-valued functions to visualize the complex function.\n\nAnother approach to visualizing a complex number is to plot it as the tip of a vector that moves as a function of the independent variable.\n\n\\begin{example} Consider the function $z(t) = e^{-|t| + j2t}$. Lets convert it to polar and Cartesian form\n  \\begin{align*}\n    z(t) &=  e^{-|t| + j2t}\\\\\n    &=  \\underbrace{e^{-|t|}}_{z_m(t)} e^{j\\overbrace{2t}^{z_a(t)}}\\\\\n    &=  e^{-|t|} (\\cos(2t) + j\\sin(2t))\\\\\n    &=  \\underbrace{e^{-|t|}\\cos(2t)}_{z_r(t)} + j \\underbrace{e^{-|t|}\\sin(2t)}_{z_i(t)}\n  \\end{align*}\n  We can then visualize the function as plots of the real and imaginary functions,\n\n  \\begin{tabular}{cc}\n  \\begin{tikzpicture}\n    \\begin{axis}[xmin=-5, xmax=5, ymin = -1, ymax=1, samples=1000, xlabel=$t$, ylabel=$z_r(t)$]\n      \\addplot[blue, thick] {exp(-abs(x))*cos(2*x*180/pi)};\n      \\addplot[mark=none, black] coordinates {(0,-1) (0,1)};\n      \\addplot[mark=none, black] coordinates {(-5,0) (5,0)};\n    \\end{axis}\n  \\end{tikzpicture}\n  &\n  \\begin{tikzpicture}\n    \\begin{axis}[xmin=-5, xmax=5, ymin = -1, ymax=1, samples=1000, xlabel=$t$, ylabel=$z_i(t)$]\n      \\addplot[blue, thick] {exp(-abs(x))*sin(2*x*180/pi)};\n      \\addplot[mark=none, black] coordinates {(0,-10) (0,10)};\n      \\addplot[mark=none, black] coordinates {(-5,0) (5,0)};\n    \\end{axis}\n  \\end{tikzpicture}\n  \\end{tabular}\\\\\n  or the mangitude and angle functions,\\\\\n  \\begin{tabular}{cc}\n  \\begin{tikzpicture}\n    \\begin{axis}[xmin=-5, xmax=5, ymin = 0, ymax=1, samples=1000, xlabel=$t$, ylabel=$z_m(t)$]\n      \\addplot[blue, thick] {exp(-abs(x))};\n      \\addplot[mark=none, black] coordinates {(0,0) (0,1)};\n      \\addplot[mark=none, black] coordinates {(-5,1) (5,1)};\n    \\end{axis}\n  \\end{tikzpicture}\n  &\n  \\begin{tikzpicture}\n    \\begin{axis}[xmin=-5, xmax=5, ymin = -10, ymax=10, samples=10, xlabel=$t$, ylabel=$z_a(t)$]\n      \\addplot[blue, thick] {2*x};\n      \\addplot[mark=none, black] coordinates {(0,-10) (0,10)};\n      \\addplot[mark=none, black] coordinates {(-5,0) (5,0)};\n    \\end{axis}\n  \\end{tikzpicture}\n  \\end{tabular}\n\\end{example}\n\n\\section{Calculus}\n\nCalculus is used heavily in the course. Here we remind ourselves of some basic facts. Consult your calculus text for more details.\n\n\\subsection*{Limits}\n\nThe \\textit{limit} $L$ of a function $f(t)$ is the function value as the independent variable approaches a constant $t\\rightarrow c$, written as\n\\[\n\\lim_{t\\rightarrow c} f(t) = L\n\\]\nThe one-sided limit is defined as the limit as the independent variable approaches the constant from below or above\n\\[\n\\lim_{t\\rightarrow c^-} f(t) = L \\mbox{ (limit from below) or } \\lim_{t\\rightarrow c^+} f(t) = L \\mbox{ (limit from above)}\n\\]\n\n\\subsection*{Derivatives of real-valued functions}\n\nFor functions $f:\\mathbb{R}\\mapsto\\mathbb{R}$ recall the derivative is the instantaneous rate of change in the value as a function of the independent variable, and can be defined using a limit of a difference. Consider such a function $f(t)$ for $t\\in\\mathbb{R}$, it's derivative is given using a limit of a forward difference:\n\n\\[\n\\frac{df}{dt} (t) = \\lim_{h\\rightarrow0^+} \\frac{f(t+h)-f(t)}{h}\n\\]\n\nHigher-order derivative are defined recursively. For example, the second derivative is\n\n\\[\n\\frac{d^2f}{dt^2} (t) = \\lim_{h\\rightarrow0^+} \\frac{\\frac{df}{dt}(t+h)-\\frac{df}{dt}(t)}{h}\n\\]\nIn the general case the $N^\\text{th}$ order derivative is\n\\[\n\\frac{d^Nf}{dt^N} (t) = \\lim_{h\\rightarrow0^+} \\frac{\\frac{d^{N-1}f}{dt^{N-1}}(t+h)-\\frac{d^{N-1}f}{dt^{N-1}}(t)}{h}\n\\]\n\nNote there are several different notations for derivatives, e.g. $\\frac{df}{dt}(t) = f^\\prime (t) = \\dot{f}(t)$, but we will use the former (Leibnitz) in most cases. We will also use the derivative operator notation $\\frac{d^Nf}{dt^N} = (D^N f)(t)$, which is convenient for higher-order derivatives.\n\nA function with finite derivatives (in the limit) for all values of the independent variable over an interval is called \\textit{continuous} over that interval. Values of the independent variable where the derivative is not finite (in the limit) are called \\textit{discontinuities}. A function with a finite number of discontinuities is called \\textit{piecewise continuous}. If the limit is one-sided then we say the function is piecewise continuous from the left or right (or from below/above).\n\n\\subsection*{Integrals of real-valued functions}\n\nThe \\textit{indefinite integral} $F(t)$ is the anti-derivative of a function $f(t)$ if $\\frac{dF}{dt}(t) = f(t)$ up to a constant term, written as\n\\[\nF(t) + C = \\int f(t)\\; dt\n\\]\nwhere $C$ is an arbitrary constant.\n\nThe \\textit{definite integral} is the area under a function between the \\textit{lower limit} $a$ and the \\textit{upper limit} $b$, defined as\n\\[\n\\int\\limits_{a}^{b} f(t) \\; dt = F(b) - F(a)\n\\]\nIn cases where one or both of the limits is infinite, the definition changes to use limits\n\\[\n\\int\\limits_{-\\infty}^{b} f(t) \\; dt = F(b) - \\lim_{a\\rightarrow -\\infty} F(a)\n\\]\n\\[\n\\int\\limits_{a}^{\\infty} f(t) \\; dt = \\lim_{b\\rightarrow \\infty} F(b) - F(a)\n\\]\n\\[\n\\int\\limits_{-\\infty}^{\\infty} f(t) \\; dt = \\lim_{b\\rightarrow \\infty} F(b) - \\lim_{a\\rightarrow -\\infty} F(a)\n\\]\n\n\\section{Differential Equations}\n\nThis course assumes a background in basic differential equations (e.g. as taught in Math 2214). However, we use only consider linear, constant-coefficient differential equations.\n\nA linear, constant coefficient (LCC) differential equation is of the form\n\\[\na_0\\, y + a_1\\, \\frac{dy}{dt} + a_2\\, \\frac{d^2y}{dt^2} + \\cdots + a_N\\, \\frac{d^Ny}{dt^N}  = b_0\\, x + b_1\\, \\frac{dx}{dt} + b_2\\, \\frac{d^2x}{dt^2} + \\cdots + b_M\\, \\frac{d^My}{dt^M}\n\\]\nwhich can be written compactly as\n\\[\n\\sum\\limits_{k = 0}^{N} a_k\\, \\frac{d^ky}{dt^k} = \\sum\\limits_{k = 0}^{M} b_k\\, \\frac{d^kx}{dt^k}\n\\]\n\nIt is helpful to clean up this notation using the derivative operator $D^n = \\frac{d^n}{dt^n}$. For example\n$D^2y = \\frac{d^2y}{dt^2}$ and $D^0 y= y$. To gives the form:\n\\[\n\\sum\\limits_{k = 0}^{N} a_k\\, D^k y = \\sum\\limits_{k = 0}^{M} b_k\\, D^k x\n\\]\n\nWe can factor out the derivative operators\n\\[\na_0y + a_1Dy + a_2D^2y + \\cdots + a_ND^Ny  = b_0\\, x + b_1\\, Dx + b_2\\, D^2x + \\cdots + b_M\\, D^M x\n\\]\n\\[\n\\underbrace{\\left(a_0 + a_1D + a_2D^2 + \\cdots + a_ND^N\\right)}_{\\text{Polynimial in } D, Q(D)} y = \\underbrace{\\left(b_0 + b_1 D + b_2 D^2 + \\cdots + b_M D^M\\right)}_{\\text{Polynimial in } D, P(D)} x\n\\]\nto give:\n  \n\\[\nQ(D)y = P(D)x\n\\]\n\nYou learned how to solve these in differential equations as\n\n\\[\ny(t) = y_\\text{h}(t) + y_\\text{p}(t)\n\\]\n\nThe term $y_\\text{h}(t)$ is the solution of the homogeneous equation\n\\[\nQ(D)y = 0\n\\]\nGiven the $N-1$ auxillary conditions $y(t_0) = y_0$, $Dy(t_0) = y_1$, $D^2y(t_0) = y_2$, up to $D^{N-1}y(t_0) = y_{N-1}$.\n\nThe term $y_\\text{p}(t)$ is the solution of the particular equation\n\\[\nQ(D)y = P(D)x\n\\]\nfor a given $x(t)$.\n\nRather than recapitulate the solution to $y_\\text{h}(t)$ and $y_\\text{p}(t)$ in the general case we focus on the homogeneous solution $y_\\text{h}(t)$ only. The reason is that we will use the homogeneous solution to find the impulse response in future lectures and take a different approach to solving the general case for an arbitrary input using the impulse response and convolution.\n\nTo solve the homogenous system:\n\n\\textbf{Step 1:} Find the \\emph{characteristic equation} by replacing the derivative operators by powers of an aribrary complex variable $s$.\n\\[\nQ(D) = a_0 + a_1D + a_2D^2 + \\cdots + a_ND^N\n\\]\nbecomes\n\\[\nQ(s) = a_0 + a_1s + a_2s^2 + \\cdots + a_Ns^N\n\\]\na polynomial in $s$ with $N$ roots $s_i$ for $i = 1, 2, \\cdots, N$ such that\n\\[\n(s - s_1)(s-s_2)\\cdots(s-s_N) = 0\n\\]\n\n\\textbf{Step 2:} Select the form of the solution, a sum of terms corresponding to the roots of the characteristic equation.\n\n\\begin{itemize}\n\\item For a real root $s_1\\in \\mathbb{R}$ the term is of the form\n  \\[\n  C_1 e^{s_1 t}.\n  \\]\n\\item For a pair of complex roots (they will always be in pairs) $s_{1,2} = a \\pm jb$ the term is of the form\n  \\[\n  C_1 e^{s_1 t} + C_2 e^{s_2 t} = e^{a t}\\left(C_3\\cos(bt) + C_4\\sin(bt)\\right) = C_5 e^{a t}\\cos(bt + C_6).\n  \\]\n\\item For a repeated roots $s_1$, repeated r times, the term is of the form\n  \\[\n  e^{s_1 t} (C_0 + C_1 t + \\cdots + C_{r-1} t^{r-1}).\\]\n\\end{itemize}\n\n\\textbf{Step 3:} Solve for the unknown constants in the solution using the auxillary conditions. \n\nWe now examine two common special cases, when $N=1$ (first-order) and when $N=2$ (second-order).\n\n\\subsection*{First-Order Homogeneous LCCDE}\n\nConsider the first order homogeneous differential equation\n\\[\n\\frac{dy}{dt}(t) + ay(t) = 0 \\mbox{ for } a \\in \\mathbb{R}\n\\]\nThe characteristic equation is given by\n\\[\ns + a = 0\n\\]\nwhich has a single root $s_1 = -a$. The solution is of the form\n\\[\ny(t) = Ce^{s_1 t} = Ce^{-a t} \n\\]\nwhere the constant $C$ is found using the auxillary condition $y(t_0) = y_0$.\n\n\\textit{Example}: Consider the homogeneous equation\n\\[\n\\frac{dy}{dt}(t) + 3y(t) = 0 \\mbox{ where } y(0) = 10\n\\]\nThe solution is\n\\[\ny(t) = Ce^{-3 t} \n\\]\nTo find $C$ we use the auxillary condition\n\\[\ny(0) = Ce^{-3 \\cdot 0} = C = 10\n\\]\nand the final solution is\n\\[\ny(t) = 10e^{-3 t} \n\\]\n\\subsection*{Second-Order Homogeneous LCCDE}\n\nConsider the second-order homogeneous differential equation\n\\[\n\\frac{d^2y}{dt^2}(t) + a\\frac{dy}{dt}(t) + by(t) = 0 \\mbox{ for } a,b \\in \\mathbb{R}\n\\]\nThe characteristic equation is given by\n\\[\ns^2 + as + b = 0\n\\]\n\nLet's look at several examples to illustrate the functional forms.\n\nExample 1:\n\\[\n\\frac{d^2y}{dt^2}(t) + 7\\frac{dy}{dt}(t) + 10y(t) = 0 \n\\]\nThe characteristic equation is given by\n\\[\ns^2 + 7s + 10 = 0\n\\]\nwhich has roots $s_1 = -2$ and $s_2 = -5$. Thus the form of the solution is\n\\[\ny(t) = C_1e^{-2t} + C_2e^{-5t}\n\\]\n\nExample 2:\n\\[\n\\frac{d^2y}{dt^2}(t) + 2\\frac{dy}{dt}(t) + 5y(t) = 0 \n\\]\nThe characteristic equation is given by\n\\[\ns^2 + 2s + 5 = 0\n\\]\nwhich has complex roots $s_1 = -1+j2$ and $s_1 = -1-j2$. Thus the form of the solution is\n\\[\ny(t) = e^{-t}\\left(C_1\\cos(2t) + C_2\\sin(2t)\\right)\n\\]\n\nExample 3:\n\\[\n\\frac{d^2y}{dt^2}(t) + 2\\frac{dy}{dt}(t) + y(t) = 0 \n\\]\nThe characteristic equation is given by\n\\[\ns^2 + 2s + 1 = 0\n\\]\nwhich has a root $s_1 = -1$ repeated $r=2$ times. Thus the form of the solution is\n\\[\ny(t) = e^{-t}\\left(C_1 + C_2t\\right)\n\\]\n\nIn each of the above cases the constants, $C_1$ and $C_2$, are found using the auxillary conditions $y(t_0)$ and $y\\prime(t_0)$.\n\n\\section{Circuits}\n\nECE 2024 is required for knowledge of continuous signals representation as voltages and currents, and the analysis and construction of circuits containing resistors, capacitors, inductors, and operational amplifiers. We will assume you can derive the differential governing equation for simple circuits using the voltage and current relationships for the circuit elements and Kerchoffs laws.\n\n\\begin{itemize}\n\\item Resistor: $v_R = R \\,i_R$\\hspace{2em}\n  \\begin{center}\n  \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n    \\draw\n    (0,0) to[R,l=$R$,v=$v_R$,i=$i_R$] (4,0);\n  \\end{circuitikz}\n  \\end{center}\n\\item Capacitor: $i_C = C\\, v_C^\\prime$ \\hspace{2em}\n  \\begin{center}\n  \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n    \\draw\n    (0,0) to[C,l=$C$,v=$v_C$,i=$i_C$] (4,0);\n  \\end{circuitikz}\n  \\end{center}\n\\item Inductor: $v_L = L\\, i_L^\\prime$ \\hspace{2em}\n  \\begin{center}\n  \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n    \\draw\n    (0,0) to[L,l=$L$,v=$v_L$,i=$i_L$] (4,0);\n  \\end{circuitikz}\n  \\end{center}\n\\item Ideal Op-Amp: the ideal op-amp operates so as to keep $i_+ = i_- = 0$ and $v_- = v_+$.\n  \\begin{center}\n  \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n    \\draw\n    (0,0) node[op amp] (op1) {}\n    (-2,0.5) to[short,i=$i_-$,o-] (op1.-)\n    (-2,-0.5) to[short,i=$i_+$,o-] (op1.+)\n    (op1.out) to[short,i=$i_o$,-o] (2,0)\n    (-2.5,0.5) node {$v_-$}\n    (-2.5,-0.5) node {$v_+$}\n    (2.5,0) node {$v_o$};\n  \\end{circuitikz}\n  \\end{center}\n\\end{itemize}\n\nThese elements are the building blocks of most continuous-time signal processing implementations.\n\n\\subsection*{KVL}\n\n\\textit{Kerchoff's Voltage Law} (KVL) says that the sum of the voltages around any closed loop must be zero.\n\n\\subsection*{KCL}\n\n\\textit{Kerchoff's Current Law} (KVL) says that the sum of the currents into a node must be zero.\n\n\\subsection*{Ideal OpAmps}\n\nAn op-amp is a device that has two inputs, labeled the inverting ($-$) and non-inverting ($+$) input respectively, and a single output. The ideal op-amp is an approximation to simplify analysis. This approximation assumes:\n\n\\begin{enumerate}\n\\item the inputs have an infinite impedance such that no current flows into the inputs, $i_+ = i_- = 0$\n\\item the op-amp operates such that the input voltages are made equal $v_- = v_+$\n\\item the output can source as much current as needed\n\\end{enumerate}\n \nWhile this is just an approximation, within the frequency regimes we are concerned with in this course, it works well. \n\n\\subsection*{Governing Equations}\n\nGiven the component descriptions above and Kerchoff's laws with some algebra and calculus we can derive the input output equation for a wide variety circuits, inlcuding those with op-amps. When the circuit contains $N$ energy storage elements (inductors or capacitors) the resulting equation will be an $N^\\text{th}$ order linear, constant-coefficient differential equation. Note, the cleanest route to the governing equation is not always clear at the start and it takes some trial and error on your part.\n\n\\begin{example} Consider the following RC circuit where $v(t)$ is the time-varying source voltage and we wish to know the resulting voltage across the capacitor $v_C(t)$.\n  \\begin{center}\n    \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n      \\draw\n      (0,2) to[V,l=$v(t)$] (0,0)\n      (0,2) to[R,l=$R$, i=$i(t)$] (3,2)\n      (3,2) to[C,l=$C$, v=$v_c(t)$] (3,0)\n      (0,0) to[short] (3,0);\n  \\end{circuitikz}\n  \\end{center}\n  We can analyze it using either a KVL or a KCL. Using a KVL we note\n  \\[\n  v(t) = R\\,i(t) + v_c(t) \n  \\]\n  and note that the curent through the resistor and capacitor is the same. We use the voltage-current relationship for the capacitor to obtain\n  \\[\n  i(t) = C\\,\\frac{dv_c}{dt}\\; .\n  \\]\n  Substituting into the KVL we get\n  \\[\n  v(t) = RC\\,\\frac{dv_c}{dt} + v_c(t) \n  \\]\n  which we can rearrange into the standard form for a differential equation\n  \\[\n  \\frac{dv_c}{dt} + \\frac{1}{RC}v_c(t) = \\frac{1}{RC}\\,v(t)\n  \\]\n  Alternatively we could have used a KCL at the top of the capacitor\n  \\[\n  i(t) = C\\frac{dv_C(t)}{dt}\n  \\]\n  The current through the resistor using Ohm's law is\n  \\[\n  i(t) = \\frac{v(t) - v_C(t)}{R} \n  \\]\n  Equating the two expressions and putting into standard form we get the same governing equation as before. \n\\end{example}\n\\begin{example} We can take the previous circuit and connect to an op-amp in the voltage follower form to arrive at a circuit that isolates the circuit from other parts of a larger circuit. This strategy, where we form these \\textit{stages} will be used throughout the course.  \n  \\begin{center}\n    \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n      \\draw\n      (5.5,2.5) node[op amp] (op1) {}\n      (0,2) to[V,l=$v(t)$] (0,0)\n      (0,2) to[R,l=$R$, i=$i(t)$] (3,2)\n      (3,2) to[C,l=$C$, v=$v_c(t)$] (3,0)\n      (3,2) to[short] (op1.+)\n      (op1.out) to (6.7,4) to (4.3,4) to (op1.-)\n      (op1.out) to[short, -o] (7,2.5)\n      (0,0) to[short, -o] (7,0)\n      (7,2.5) to[open, v=$y(t)$] (7,0);\n  \\end{circuitikz}\n  \\end{center}\n  The analysis proceeds very similar to the previous one. Using the ideal op-amp conditions, a KCL at the non-inverting input gives\n  \\[\n  i(t) = C\\frac{dv_C(t)}{dt} + 0\n  \\]\n  and\n  \\[\n  y(t) = v_c(t)\n  \\]\n  Again, the current through the resistor using Ohm's law is\n  \\[\n  i(t) = \\frac{v(t) - v_C(t)}{R} \n  \\]\n  Equating the two expressions, substituting $v_C(t) \\rightarrow y(t)$, and putting into standard form we get\n  \\[\n  \\frac{dy}{dt}(t) + \\frac{1}{RC}y(t) = \\frac{1}{RC}\\,v(t)\n  \\]\n\\end{example}\n\n\n\\subsection*{Building and Characterizing Circuits}\n\nWe will be building and characterizing physical circuits to better connect the course to the real world. We assume you know how to build relatively simple circuits on a protoboard, as well as use a power supply, function generator and oscilliscope (i.e. the Digilent Analog Discovery). We also assume you have taken or are currently taking the embedded course, so that toward the end of the semester you know how to interface and program with the TI MSP432 \"Red Board\".\n(MSP-EXP432P401R Evaluation board).\n\n\\section{Programming}\n\nECE 2514 is required for the ability to model and simulate physical systems using computational tools, and basic programming ability.\n\n\\begin{itemize}\n\\item Matlab for general computation and plotting\n\\item C++ (a small subset) for implementing digital filters\n\\end{itemize}\n\nFor general computation we don't require Matlab and Mathematica, Python, or Julia work as well. Matlab is required for access to filter design functionality using the signal processing toolbox. \n\n\\subsection*{Plotting and Visualization}\n\nWe assume you can plot real and complex functions using Matlab/Python/Julia/Mathematica, label axes appropriately, and generate readable graphics for inclusion in problem set solutions and the project report.\n\n\\subsection*{Computation with C or C++}\n\n\\section{Digitial Systems}\n\nECE 2544 is required for for knowledge of digital signal representation and the analysis and construction of circuits containing combinatorial and sequential logic.\n\n\\subsection*{Binary Representation of Integers vs Floating Point}\n\n\\subsection*{shift registers}\n\n\\subsection*{adders and multipliers}\n", "meta": {"hexsha": "b4ba24f629825eccdad548423f471957bcb54648", "size": 28431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01-prereqs.tex", "max_stars_repo_name": "clwyatt/notes-2714", "max_stars_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "01-prereqs.tex", "max_issues_repo_name": "clwyatt/notes-2714", "max_issues_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01-prereqs.tex", "max_forks_repo_name": "clwyatt/notes-2714", "max_forks_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.9857594937, "max_line_length": 554, "alphanum_fraction": 0.6799620133, "num_tokens": 9632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.8840392802184581, "lm_q1q2_score": 0.8066294086583135}}
{"text": "\\documentclass[11pt,twoside]{article}\n\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\n\\pagestyle{myheadings}\n\\markboth{What goes around}{What goes around}\n\n\\input{../../fncextra}\n\n\\begin{document}\n\n\\begin{center}\n  \\bf What goes around, comes around\n\\end{center}\n\n\nA small satellite in the Earth--moon system can be modeled as a \\emph{restricted three-body problem}, in which one object has so little relative mass that the motions essentially take place in a plane. In this formulation, Newton's laws of motion are simplified by a transformation so that the Earth has mass $\\mu_*$ and remains at $(0,0)$, while the moon has mass $\\mu$ and is at $(1,0)$, where $\\mu+\\mu_*=1$. The position of the satellite is $(x(t),y(t))$ and satisfies\n\\begin{equation}\n\\begin{split}\n  x'' &= x + 2y' - \\mu_* \\frac{x+\\mu}{r} - \\mu \\frac{x-\\mu_*}{r_*} \\\\\n  y'' &= y - 2x' - \\mu_* \\frac{y}{r} - \\mu \\frac{y}{r_*}, \n\\end{split}\\label{eq:r3body}\n\\end{equation}\nwhere\n\\begin{align*}\n  r &= \\left[ (x+\\mu)^2 + y^2 \\right]^{3/2} \\\\\n\tr_* &= \\left[ (x-\\mu_*)^2 + y^2 \\right]^{3/2}.\n\\end{align*}\nFor the Earth/moon system, $\\mu=0.012277471$.\n\nThe key to computing solutions using standard software is to transform the original ODE system into a first-order one. Since there are two dependent variables $x$ and $y$, and both of these appear to second order, there will be 4 variables and 4 equations in the first-order version. Define $u_1=x$, $u_2=y$, $u_3=x'$, $u_4=y'$. Two trivial equations in the new system are $u_1'=u_3$ and $u_2'=u_4$. The other two equations, for $u_3'$ and $u_4'$, come from substitution into the original system~\\eqref{eq:r3body}. For example,\n\\begin{equation*}\n  u_3' = u_1 + 2u_4 - \\mu_* \\frac{u_1+\\mu}{r} - \\mu \\frac{u_1-\\mu_*}{r_*},\n\\end{equation*}\nand so on.\n\n\\subsection*{Goals}\n\nYou will explore unlikely-looking satellite orbits that have fascinated mathematicians since Poincar\\'e. They are of more than academic interest, because despite their strangeness, they are energy-efficient. \n\n\\subsection*{Preparation}\n\nRead section 6.1. Fully write out the first-order system of ODEs $\\bfu'=\\bff(t,\\bfu)$ that is equivalent to~\\eqref{eq:r3body}. \n\n\\subsection*{Procedure}\n\nDownload the script template and complete it to execute the following steps. \n\n\\begin{enumerate}\n\\item Set\n\\begin{verbatim}\nopt = odeset('reltol',1e-13,'abstol',1e-13);\n\\end{verbatim}\nThis will be used below to require strict error tolerances in the ODE solutions. The solutions below will all use \\texttt{ode113} with \\texttt{opt} as a fourth input argument.\n\n\\item Using the expression of equation~\\eqref{eq:r3body} as a first-order system, $\\bfu'=\\bff\\,(t,\\bfu)$, write the function\n\\begin{verbatim}\nfunction dudt = r3body(t,u)\n\\end{verbatim}\nin which \\texttt{u} is a vector containing numerical values for the dependent variables, and \\texttt{dudt} returns the components of $\\bfu'$. \n\n\\item Using the initial conditions \n  \\begin{align*}\n    x(0) &= 1.2, \\; & x'(0) &= 0, \\\\\n    y(0) &= 0, \\; & y'(0) &= -1.049357510,\n  \\end{align*}\nsolve the problem on the interval $[0,6.192169331]$, using \\texttt{ode113} and passing \\texttt{opt} as a fourth input argument. Plot the trajectory in the $(x,y)$ phase plane. It will have two major loops, one to each side of the Earth. Add the moon and Earth positions as points in the plot.  \n\n\\item Repeat step 3 for\n  \\begin{align*}\n    x(0) &= 0.994 \\; & x'(0) &= 0 \\\\\n    y(0) &= 0 \\; & y'(0) &= -2.03173262955734\n  \\end{align*}\n  and solve over $[0,11.124340337266]$. This orbit has three loops.\n\n\\item Repeat step 3 for \n      \\begin{align*}\n        x(0) &= 0.994 \\; & x'(0) &= 0 \\\\\n        y(0) &= 0 \\; & y'(0) &= -2.00158510637908\n      \\end{align*}\n      and solve over $[0,17.06521656015796]$. This one has four loops. \n\n\\item These orbits are very sensitive to perturbations, and while our convergence theorems apply to a fixed time interval and $h\\to 0$, the case of $t\\to\\infty$ is quite different. Re-solve step~5 for $0\\le t \\le 100$. Your plot will show the path of the satellite departing from the apparently periodic orbit. \n\\end{enumerate}\n\n\\subsection*{Discussion}\n\nIn step 3 above, what is the maximum speed of the satellite over the whole orbit? \n\n\n\\end{document}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: t\n%%% End: \n", "meta": {"hexsha": "210ae3e1045f335281b81c7e25aaddb8603145ac", "size": 4289, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter06/WhatGoesAround/WhatGoesAround.tex", "max_stars_repo_name": "snowdj/fnc-extras", "max_stars_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 109, "max_stars_repo_stars_event_min_datetime": "2018-04-21T09:02:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T19:03:54.000Z", "max_issues_repo_path": "labs/chapter06/WhatGoesAround/WhatGoesAround.tex", "max_issues_repo_name": "snowdj/fnc-extras", "max_issues_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-12-04T22:17:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T21:04:47.000Z", "max_forks_repo_path": "labs/chapter06/WhatGoesAround/WhatGoesAround.tex", "max_forks_repo_name": "snowdj/fnc-extras", "max_forks_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 49, "max_forks_repo_forks_event_min_datetime": "2017-04-02T17:21:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T17:19:57.000Z", "avg_line_length": 43.7653061224, "max_line_length": 527, "alphanum_fraction": 0.6913033341, "num_tokens": 1369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989815306765, "lm_q2_score": 0.8902942319436397, "lm_q1q2_score": 0.8065975067672964}}
{"text": "\\Extrachap{Notation}\n%\\chapter{Notation}\n\\label{sec:Notation}\n\n\\section*{Introduction}\nIt is very difficult to come up with a single, consistent notation to cover the wide variety of\ndata, models and algorithms that we discuss. Furthermore, conventions differ between machine\nlearning and statistics, and between different books and papers. Nevertheless, we have tried\nto be as consistent as possible. Below we summarize most of the notation used in this book,\nalthough individual sections may introduce new notation. Note also that the same symbol may\nhave different meanings depending on the context, although we try to avoid this where possible.\n\n\n\\section*{General math notation}\n\n\\begin{longtable}{ll}\n\\hline\\noalign{\\smallskip}\n\\textbf{Symbol} & \\textbf{Meaning} \\\\\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n$\\lfloor x \\rfloor$ & Floor of $x$, i.e., round down to nearest integer\\\\\n$\\lceil x \\rceil$ & Ceiling of $x$, i.e., round down to nearest integer\\\\\n$\\vec{x} \\otimes \\vec{y}$ & Convolution of $\\vec{x}$ and $\\vec{y}$\\\\\n$\\vec{x} \\odot \\vec{y}$ & Hadamard (elementwise) product of $\\vec{x}$ and $\\vec{y}$\\\\\n$a \\wedge b$ & logical AND\\\\\n$a \\vee b$ & logical OR\\\\\n$\\neg a$ & logical NOT\\\\\n$\\mathbb{I}(x)$ & Indicator function, $\\mathbb{I}(x)=1$ if x is true, else $\\mathbb{I}(x)=0$\\\\\n$\\infty$ & Infinity\\\\\n$\\rightarrow$ & Tends towards, e.g., $n \\rightarrow \\infty$\\\\\n$\\propto$ &Proportional to, so $y = ax$ can be written as $y \\propto x$\\\\\n$\\abs{x}$ & Absolute value\\\\\n$\\abs{\\mathcal{S}}$ & Size (cardinality) of a set\\\\\n$n!$ & Factorial function\\\\\n$\\nabla$ & Vector of first derivatives\\\\\n$\\nabla^2$ & Hessian matrix of second derivatives\\\\\n$\\triangleq$ & Defined as\\\\\n$O(\\cdot)$ & Big-O: roughly means order of magnitude\\\\\n$\\mathbb{R}$ & The real numbers\\\\\n$1:n$ & Range (Matlab convention): $1:n = {1, 2,...,n}$\\\\\n$\\approx$ & Approximately equal to\\\\\n$\\arg\\max\\limits_x f(x)$ & Argmax: the value $x$ that maximizes $f$\\\\\n$B(a,b)$ & Beta function, $B(a,b)=\\dfrac{\\Gamma(a)\\Gamma(b)}{\\Gamma(a+b)}$\\\\\n$B(\\vec{\\alpha})$ & Multivariate beta function, $\\dfrac{\\prod\\limits_k \\Gamma(\\alpha_k)}{\\Gamma(\\sum\\limits_k \\alpha_k)}$\\\\\n$\\binom{n}{k}$ & $n$ choose $k$ , equal to $n!/(k!(n\u2212k )!)$\\\\\n$\\delta(x)$ & Dirac delta function,$\\delta(x)=\\infty$ if $x=0$, else $\\delta(x)=0$\\\\\n$\\exp(x)$ & Exponential function $e^x$\\\\\n$\\Gamma(x)$ & Gamma function, $\\Gamma(x)=\\int_0^\\infty u^{x-1}e^{-u}\\mathrm{d}u$\\\\\n$\\Psi(x)$ &  Digamma function,$Psi(x)=\\dfrac{d}{dx}\\log\\Gamma(x)$\\\\\n$\\mathcal{X}$ & A set from which values are drawn (e.g.,$\\mathcal{X}=\\mathbb{R}^D$)\\\\\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n\\end{longtable}\n\n\n\\section*{Linear algebra notation}\nWe use boldface lower-case to denote vectors, such as $\\vec{x}$, and boldface upper-case to denote matrices, such as $\\vec{X}$. We denote entries in a matrix by non-bold upper case letters, such as $X_{ij}$. \n\nVectors are assumed to be column vectors, unless noted otherwise. We use $(x_1,\\cdots,x_D)$ to denote a column vector created by stacking $D$ scalars. If we write $\\vec{X}=(\\vec{x}_1,\\cdots,\\vec{x}_n)$, where the left hand side is a matrix, we mean to stack the $\\vec{x}_i$ along the columns, creating a matrix. \n\n\\begin{longtable}{ll}\n\\hline\\noalign{\\smallskip}\n\\textbf{Symbol} & \\textbf{Meaning} \\\\\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n$\\vec{X} \\succ 0$ & $\\vec{X}$ is a positive definite matrix\\\\\n$tr(\\vec{X})$ & Trace of a matrix\\\\\n$det(\\vec{X})$ & Determinant of matrix $\\vec{X}$\\\\\n$\\abs{\\vec{X}}$ & Determinant of matrix $\\vec{X}$\\\\\n$\\vec{X}^{-1}$ & Inverse of a matrix\\\\\n$\\vec{X}^{\\dagger}$ & Pseudo-inverse of a matrix\\\\\n$\\vec{X}^T$ & Transpose of a matrix\\\\\n$\\vec{x}^T$ & Transpose of a vector\\\\\n$\\mathrm{diag}(x)$ & Diagonal matrix made from vector $\\vec{x}$\\\\\n$\\mathrm{diag}(X)$ & Diagonal vector extracted from matrix $\\vec{X}$\\\\\n$\\vec{I}$ or $\\vec{I}_d$ & Identity matrix of size $d \\times d$ (ones on diagonal, zeros of)\\\\\n$\\vec{1}$ or $\\vec{1}_d$ & Vector of ones (of length $d$)\\\\\n$\\vec{0}$ or $\\vec{0}_d$ & Vector of zeros (of length $d$)\\\\\n$\\abs{\\abs{\\vec{x}}}=\\abs{\\abs{\\vec{x}}}_2$ & Euclidean or $\\ell_2$ norm $\\sqrt{\\sum\\limits_{j=1}^{d} x_j^2}$\\\\\n$\\abs{\\abs{\\vec{x}}}_1$ & $\\ell_1$ norm $\\sum\\limits_{j=1}^{d} \\abs{x_j}$\\\\\n$\\vec{X}_{:,j}$ & j'th column of matrix\\\\\n$\\vec{X}_{i,:}$ & transpose of $i$'th row of matrix (a column vector)\\\\\n$\\vec{X}_{i,j}$ & Element $(i,j)$ of matrix $\\vec{X}$ \\\\\n$\\vec{x} \\otimes \\vec{y}$ & Tensor product of $\\vec{x}$ and $\\vec{y}$\\\\\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n\\end{longtable}\n\n\n\\section*{Probability notation}\nWe denote random and fixed scalars by lower case, random and fixed vectors by bold lower case, and random and fixed matrices by bold upper case. Occasionally we use non-bold upper case to denote scalar random variables. Also, we use $p()$ for both discrete and continuous random variables\n\n\\begin{longtable}{ll}\n\\hline\\noalign{\\smallskip}\n\\textbf{Symbol} & \\textbf{Meaning} \\\\\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n$X,Y$ & Random variable\\\\\n$P()$ & Probability of a random event\\\\\n$F()$ & Cumulative distribution function(CDF), also called distribution function\\\\\n$p(x)$ & Probability mass function(PMF)\\\\\n$f(x)$ & probability density function(PDF) \\\\\n$F(x,y)$ & Joint CDF\\\\\n$p(x,y)$ & Joint PMF \\\\\n$f(x,y)$ & Joint PDF\\\\\n$p(X|Y)$ & Conditional PMF, also called conditional probability\\\\\n$f_{X|Y}(x|y)$ & Conditional PDF\\\\\n$X \\perp Y$ & X is independent of Y\\\\\n$X \\not\\perp Y$ & X is not independent of Y\\\\\n$X \\perp Y | Z $ & X is conditionally independent of Y given Z\\\\\n$X \\not\\perp Y | Z $ & X is not conditionally independent of Y given Z\\\\\n$X \\sim p$ & X is distributed according to distribution $p$\\\\\n$\\vec{\\alpha}$ & Parameters of a Beta or Dirichlet distribution\\\\\n$\\mathrm{cov}[X]$ & Covariance of X\\\\\n$\\mathbb{E}[X]$ & Expected value of X\\\\\n$\\mathbb{E}_q[X]$ & Expected value of X wrt distribution $q$\\\\\n$\\mathbb{H}(X)$ or $\\mathbb{H}(p)$ & Entropy of distribution $p(X)$\\\\\n$\\mathbb{I}(X;Y)$ & Mutual information between X and Y\\\\\n$\\mathbb{KL}(p||q)$ & KL divergence from distribution $p$ to $q$\\\\\n$\\ell(\\vec{\\theta})$ & Log-likelihood function\\\\\n$L(\\theta,a)$ & Loss function for taking action $a$ when true state of nature is $\\theta$\\\\\n$\\lambda$ & Precision (inverse variance) $\\lambda=1/\\sigma^2$\\\\\n$\\Lambda$ & Precision matrix $\\Lambda=\\Sigma^{-1}$\\\\\nmode$[\\vec X]$ & Most probable value of $\\vec X$\\\\\n$\\mu$ & Mean of a scalar distribution\\\\\n$\\vec{\\mu}$ & Mean of a multivariate distribution\\\\\n$\\Phi$ & cdf of standard normal\\\\\n$\\phi$ & pdf of standard normal\\\\\n$\\vec{\\pi}$ & multinomial parameter vector, Stationary distribution of Markov chain\\\\\n$\\rho$ & Correlation coefficient \\\\\nsigm($x$) & Sigmoid (logistic) function,$\\dfrac{1}{1+e^{-x}}$\\\\\n$\\sigma^2$ & Variance\\\\\n$\\Sigma$ & Covariance matrix\\\\\nvar[$x$] & Variance of $x$\\\\\n$\\nu$ & Degrees of freedom parameter\\\\\nZ & Normalization constant of a probability distribution\\\\\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n\\end{longtable}\n\n\\section*{Machine learning/statistics notation}\nIn general, we use upper case letters to denote constants, such as $C, K, M, N, T$, etc. We use lower case letters as dummy indexes of the appropriate range, such as $c=1:C$ to index classes, $i=1:M$ to index data cases, $j=1:N$ to index input features, $k=1:K$ to index states or clusters, $t=1:T$ to index time, etc.\n\nWe use $x$ to represent an observed data vector. In a supervised problem, we use $y$ or $\\vec{y}$ to represent the desired output label. We use $\\vec{z}$ to represent a hidden variable. Sometimes we also use $q$ to represent a hidden discrete variable.\n\n\\begin{longtable}{ll}\n\\hline\\noalign{\\smallskip}\n\\textbf{Symbol} & \\textbf{Meaning} \\\\\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n$C$ & Number of classes\\\\\n$D$ & Dimensionality of data vector (number of features)\\\\\n$N$ & Number of data cases\\\\\n$N_c$ & Number of examples of class $c$,$N_c=\\sum_{i=1}^{N}\\mathbb{I}(y_i=c)$\\\\\n$R$ & Number of outputs (response variables)\\\\\n$\\mathcal{D}$ & Training data $\\mathcal{D}=\\left\\{(\\vec{x}_i,y_i) | i=1:N\\right\\}$\\\\\n$\\mathcal{D}_{test}$ & Test data\\\\\n$\\mathcal{X}$ & Input space\\\\\n$\\mathcal{Y}$ & Output space\\\\\n$K$ & Number of states or dimensions of a variable (often latent)\\\\\n$k(x,y)$ & Kernel function\\\\\n$\\vec{K}$ & Kernel matrix\\\\\n$\\mathcal{H}$ & Hypothesis space\\\\\n$L$ & Loss function \\\\\n$J(\\vec{\\theta})$ & Cost function\\\\\n$f(\\vec{x})$ & Decision function\\\\\n$P(y|\\vec{x})$ & TODO\\\\\n$\\lambda$ & Strength of $\\ell_2$ or $\\ell_1 regularizer$\\\\\n$\\phi(x)$ & Basis function expansion of feature vector $\\vec{x}$\\\\\n$\\Phi$ & Basis function expansion of design matrix $\\vec{X}$\\\\\n$q()$ & Approximate or proposal distribution\\\\\n$Q(\\vec{\\theta},\\vec{\\theta}_{old})$ & Auxiliary function in EM\\\\\n$T$ & Length of a sequence\\\\\n$T(\\mathcal{D})$ & Test statistic for data\\\\\n$\\vec{T}$ & Transition matrix of Markov chain\\\\\n$\\vec{\\theta}$ & Parameter vector\\\\\n$\\vec{\\theta}^{(s)}$ & $s$'th sample of parameter vector\\\\\n$\\hat{\\vec{\\theta}}$ & Estimate (usually MLE or MAP) of $\\vec{\\theta}$\\\\\n$\\hat{\\vec{\\theta}}_{MLE}$ & Maximum likelihood estimate of $\\vec{\\theta}$\\\\\n$\\hat{\\vec{\\theta}}_{MAP}$ & MAP estimate of $\\vec{\\theta}$\\\\\n$\\bar{\\vec{\\theta}}$ & Estimate (usually posterior mean) of  $\\vec{\\theta}$\\\\\n$\\vec{w}$ & Vector of regression weights (called $\\vec{\\beta}$ in statistics)\\\\\nb & intercept (called $\\varepsilon$ in statistics)\\\\\n$\\vec{W}$ & Matrix of regression weights\\\\\n$x_{ij}$ & Component (i.e., feature) $j$ of data case $i$ ,for $i=1:N ,j=1:D$\\\\\n$\\vec{x}_i$ & Training case, $i=1:N$\\\\\n$\\vec{X}$ & Design matrix of size $N \\times D$\\\\\n$\\bar{\\vec{x}}$ & Empirical mean $\\bar{\\vec{x}}=\\dfrac{1}{N}\\sum_{i=1}^{N} \\vec{x}_i$\\\\\n$\\tilde{\\vec{x}}$ & Future test case\\\\\n$\\vec{x}_*$ & Feature test case\\\\\n$\\vec{y}$ & Vector of all training labels $\\vec{y} =(y_1,...,y_N)$\\\\\n$z_{ij}$ & Latent component $j$ for case $i$\\\\\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n\\end{longtable}\n\n%\\twocolumn", "meta": {"hexsha": "f84e99aa02730030416e18ee874c09520a26931a", "size": 9950, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/notation.tex", "max_stars_repo_name": "Alexoner/Statistical-formula", "max_stars_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-15T17:00:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-24T13:46:00.000Z", "max_issues_repo_path": "prml/notation.tex", "max_issues_repo_name": "Alexoner/Statistical-formula", "max_issues_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "prml/notation.tex", "max_forks_repo_name": "Alexoner/Statistical-formula", "max_forks_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-02-25T15:40:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T04:26:03.000Z", "avg_line_length": 52.6455026455, "max_line_length": 318, "alphanum_fraction": 0.664321608, "num_tokens": 3274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8902942188450158, "lm_q1q2_score": 0.8065974949000764}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let $V$ be a vector space and suppose $\\set{\\vect{u}_1,\\ldots,\n    \\vect{u}_k}$ is a set of vectors in $V$. Show that $\\vect{0}$\n  is in $\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$.\n  \\begin{sol}\n    $\\vect{0} = 0\\vect{u}_1 + \\ldots + 0\\vect{u}_k$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Determine whether $p(x) = 4x^2-x$ is in $\\sspan \\set{x^2+x,~ x^2-1,~ -x+2}$.\n\\end{ex}\n\n\\begin{ex}\n  Determine whether $p(x) = -x^2+x+2$ is in\n  $\\sspan \\set{x^2+x+1,~ 2x^2+x}$.\n\\end{ex}\n\n\\begin{ex}\n  \\begin{enumerate}\n  \\item Write $A = \\begin{mymatrix}{rr}\n      1 & 3 \\\\\n      0 & 0\n    \\end{mymatrix}$ as a linear combination of\n    \\begin{equation*}\n      \\set{\n        \\begin{mymatrix}{rr}\n          1 & 0 \\\\\n          0 & 1\n        \\end{mymatrix},\\quad\n        \\begin{mymatrix}{rr}\n          0 & 1 \\\\\n          1 & 0\n        \\end{mymatrix},\\quad\n        \\begin{mymatrix}{rr}\n          1 & 0 \\\\\n          1 & 1\n        \\end{mymatrix},\\quad\n        \\begin{mymatrix}{rr}\n          0 & 1 \\\\\n          1 & 1\n        \\end{mymatrix}\n      }.\n    \\end{equation*}\n  \\item Show that the above set of four matrices is a spanning set for\n    $\\Mat_{2,2}$, the vector space of all $2\\times 2$-matrices.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Let $K$ be a field, and consider the vector space $\\Seq_K$ of\n  infinite sequences of scalars.  A sequence $a=(a_i)_{i\\in\\N}$ is\n  called \\textbf{finitely supported}%\n  \\index{finitely supported sequence}%\n  \\index{sequence!finitely supported} if all but finitely many\n  elements of the sequence are zero. In other words, $a$ is finitely\n  supported if there exists some $N\\in\\N$ such that $a_k=0$ for all\n  $k\\geq N$.  Let $e^0,e^1,e^2,\\ldots$ be the sequences from\n  Example~\\ref{exa:spans-sequences}.  Show that\n  $a\\in\\sspan\\set{e^0,e^1,e^2,\\ldots}$ if and only if $a$ is finitely\n  supported.\n  \\begin{sol}\n    Let $S=\\set{e^0,e^1,e^2,\\ldots}$. To prove the left-to-right\n    implication, assume $a\\in\\sspan S$. Then there exists some finite\n    subset $\\set{e^{k_1},e^{k_2},\\ldots,e^{k_n}}$ of $S$ and scalars\n    $b_1,\\ldots,b_n$ such that $a = b_1e^{k_1} + \\ldots + b_ne^{k_n}$.\n    Let $N\\in\\N$ be a number that is greater than $k_1,\\ldots,k_n$.\n    Since each of the sequences $e^{k_1},\\ldots,e^{k_n}$ is zero after\n    the first $N$ elements, the same is true for their linear\n    combination $a$. Thus, $a$ is finitely supported.\n\n    To prove the right-to-left direction, assume $a$ is finitely\n    supported. Let $N\\in\\N$ such that $a_k=0$ for all $k\\geq N$.  Then\n    $a = (a_0,a_1,\\ldots,a_{N-1},0,0,0,\\ldots)$, with infinitely many\n    zeros following. Therefore,\n    $a = a_0e^0 + a_1e^1 + \\ldots + a_{N-1}e^{N-1}$, and it follows\n    that $a\\in\\sspan S$.\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "e56365ce601cd541ea68b33111a4ef1bc00e63ea", "size": 2750, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/VectorSpaces-Spanning.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/VectorSpaces-Spanning.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/VectorSpaces-Spanning.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 33.5365853659, "max_line_length": 78, "alphanum_fraction": 0.5934545455, "num_tokens": 1080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794595, "lm_q2_score": 0.8887588023318196, "lm_q1q2_score": 0.8063817298799222}}
{"text": "\\section{Intermediate Value Theorem for Derivatives}\r\n\\begin{theorem}[IVT for Derivatives]\r\n\tIf $f$ is differentiable on the closed interval $[a,b]$, then $f^\\prime$ takes on every value between $f^\\prime(a)$ and $f^\\prime(b)$.\r\n\\end{theorem}\r\n\r\n\\begin{example}\r\n\tShow that any function that has the following function as it derivative cannot be differentiable on the interval $-1 \\leq x \\leq 1$.\r\n\t\\begin{equation*}\r\n\t\tf(x) = \\begin{cases}\r\n\t\t\t0 & -1 \\leq x < 0 \\\\\r\n\t\t\t1 & 0 \\leq x \\leq 1\r\n\t\t\\end{cases}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\t$f$ does not take all values between $f(-1)=0$ and $f(1)=1$.\r\n\tSo, by the contrapositive of the IVT for Derivatives, any function that has $f$ as its derivative will not be differentiable on $[-1,1]$.\r\n\\end{answer}", "meta": {"hexsha": "19fa8a264cdfbb0c3080371958431ffe67b03e60", "size": 771, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/ivt.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/derivatives/ivt.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/derivatives/ivt.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 42.8333333333, "max_line_length": 139, "alphanum_fraction": 0.6783398184, "num_tokens": 254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.8887587839164801, "lm_q1q2_score": 0.8063817087165055}}
{"text": "\\subsection{System to Higher Order}\r\nLet's say we have the linear system\r\n\\begin{equation*}\r\n\t\\vec{x}' = A\\vec{x} + \\vec{f}.\r\n\\end{equation*}\r\nWriting the system using $x_1, \\ldots x_n$ as the components of $\\vec{x}$, $f_1, \\ldots f_n$ as the components of $\\vec{f}$, and $a_{ij}$ as the entry in $A$ on the $i^{th}$ row and $j^{th}$ column,\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\tx_1' = a_{11}x_1 + \\ldots a_{1n}x_n + f_1 \\\\\r\n\t\t\\vdots \\\\\r\n\t\tx_n' = a_{n1}x_1 + \\ldots a_{nn}x_n + f_n\r\n\t\\end{cases}.\r\n\\end{equation*}\r\nLet's arbitrarily assign $x_1 = y$.\r\nThis will allow us to find expressions for $x_2, \\ldots x_n$ in terms of $y$ and its derivatives. When we find $x_n$ in these terms and equate $x_n'$ with what's given in the system, we'll have an linear $n^{th}$ order equation.\r\n\r\n\\begin{example}\r\n\tConvert the following system of equations to a single equation.\r\n\t\\begin{equation*}\r\n\t\t\\vec{x}' = \\begin{bmatrix}\r\n\t\t\t1 & 1 & 1 \\\\\r\n\t\t\t1 & 0 & 1 \\\\\r\n\t\t\t0 & 1 & 1\r\n\t\t\\end{bmatrix}\\vec{x} + \\begin{bmatrix}\r\n\t\t\t1 \\\\\r\n\t\t\tt \\\\\r\n\t\t\tt^2\r\n\t\t\\end{bmatrix}\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nExpanding the system out of matrix form,\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\tx_1' = x_1 + x_2 + x_3 + 1 \\\\\r\n\t\tx_2' = x_1 + x_3 + t \\\\\r\n\t\tx_3' = x_2 + x_3 + t^2 \r\n\t\\end{cases}.\r\n\\end{equation*}\r\nAssuming $x_1 = y$,\r\n\\begin{align*}\r\n\ty' &= y + x_2 + x_3 + 1 \\\\\r\n\t&\\implies x_2 = y' - y - x_3 - 1.\r\n\\end{align*}\r\nTaking the derivative of $x_2$ and equating it with what's given in the system,\r\n\\begin{equation*}\r\n\tx_2' = y'' - y' - x_3' = y + x_3 + t.\r\n\\end{equation*}\r\nSolving for $x_3'$ and equating it with what's given in the system,\r\n\\begin{equation*}\r\n\tx_3' = y'' - y' - t - x_3 = y' - y + t^2 - 1.\r\n\\end{equation*}\r\nPutting this expression for $x_3'$ back into our expression for $x_2'$,\r\n\\begin{align*}\r\n\tx_2' &= y'' - 2y' + y - t^2 + 1 = y + x_3 + t \\\\\r\n\t&\\implies x_3 = y'' - 2y' - t^2 - t + 1.\r\n\\end{align*}\r\nTaking the derivative of $x_3$ and equating it to what's given in the system,\r\n\\begin{equation*}\r\n\tx_3' = y''' - 2y'' - 2t - 1 = y' - y - 1 + t^2.\r\n\\end{equation*}\r\nSo, we have our order 3 equation,\r\n\\begin{equation*}\r\n\ty''' - 2y'' - y' + y = t^2 + 2t.\r\n\\end{equation*}\r\n\r\n\\noindent\r\nThe auxiliary polynomial of this higher order equation $p(r)$ and the characteristic polynomial $p(\\lambda)$ of the linear system will have exactly the same roots.", "meta": {"hexsha": "cf725b5fa8497f662d58cede0712609153702c7a", "size": 2361, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/systemsAndHigherOrder/systemToHigherOrder.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/linearSystems/systemsAndHigherOrder/systemToHigherOrder.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/linearSystems/systemsAndHigherOrder/systemToHigherOrder.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 34.7205882353, "max_line_length": 229, "alphanum_fraction": 0.6069462092, "num_tokens": 932, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768635777511, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.8062446701162517}}
{"text": "\\section{RL Framework}\n\n\\paragraph{Markov Decision Process (MDP)}\nA Markov Decision Process is a tuple $(S, A, R, P, \\rho_0)$ where \n\\begin{itemize}\n    \\item $S$ is the set of all valid states\n    \\item $A$ is the set of all valid actions\n    \\item $R: S \\times A \\times S \\rightarrow \\mathbb{R}$ is the \\emph{reward function}, such that $r_t = R(s_t, a_t, s_{t+1})$. In the case the reward is stochastic and $r_t$ is a random variable, we have $R(s, a, s') = \\mathbb{E}[r_t \\mid s_t=s, a_t=a, s_{t+1}=s']$\n    \\item $P: S \\times A \\times S \\rightarrow [0, 1]$ the \\emph{transition probability function}, such that $P(s' \\mid s, a)$ is the probability of transitioning into state $s'$ if you are in state $s$ and take action $a$\n    \\item $\\rho_0: S \\rightarrow [0, 1]$ is the starting state distribution\n\\end{itemize}\n\n\\paragraph{Markov property} Transitions only depend on the most recent state and action, and no prior history : $P(s_{t+1}\\mid s_t,a_t,\\dots,s_1,a_0,s_0) = P(s_{t+1}\\mid s_t,a_t)$. This assumption does not always hold, for instance when the observed state does not contain all necessary information (\\emph{Partially Observable Markov Decision Process}), or when $P$ and $R$ actually depend on $t$ (\\emph{Non-Stationary Markov Decision Process}).\n\nWhen the MDP is known (e.g. small tabular environments), optimal policies can be found offline without interacting with the environment, using \\nameref{section:dp} (DP) algorithms. But this is generally not the case and RL algorithms have to do trial-and-error search (like bandits problems), and have to deal with \\emph{delayed rewards}. Actions may affect not only the immediate reward, but also the next state and therefore all subsequent rewards.\n\n\\paragraph{Definitions}\n\\begin{itemize}\n    \\item The \\emph{policy} $\\pi$ determines the behavior of our agent, who will take actions $a_t \\sim \\pi(\\cdot \\mid s_t)$. Policies can be derived from an action-value function or can be explicitly parameterized and denoted by $\\pi_{\\theta}$. They can also be deterministic, in which case they are sometimes denoted by $\\mu_{\\theta}$, with $a_t = \\mu_{\\theta}(s_t)$.\n    \\item A \\emph{trajectory} $\\tau = (s_0, a_0, s_1, \\dots)$ is a sequence of states and actions in the world, with $s_0 \\sim \\rho_0$ and $s_{t+1} \\sim P(\\cdot \\mid s_t, a_t)$. It is sampled from $\\pi$ if $a_t \\sim \\pi(\\cdot \\mid s_t)$ for each $t$. Trajectories are also called \\emph{episodes}.\n    \\item The return $R(\\tau)$ is the cumulative reward over a trajectory and is the quantity to be maximized by our agent. It can refer to the \\emph{finite-horizon undiscounted return} $R(\\tau) = \\sum_{t=0}^T r_t$ or the \\emph{infinite-horizon discounted return} $R(\\tau) = \\sum_{t=0}^{\\infty} \\gamma^t r_t$ for instance. Parameter $\\gamma$ is called the \\emph{discount factor}.\n    \\item The \\emph{on-policy value function}: $V^{\\pi}(s) = \\E_{\\tau \\sim \\pi}[R(\\tau) \\mid s_0=s]$\n    \\item The \\emph{on-policy action-value function}: $Q^{\\pi}(s,a) = \\E_{\\tau \\sim \\pi}[R(\\tau) \\mid s_0=s, a_0=a]$. We have $V^{\\pi}(s) = \\E_{a \\sim \\pi(\\cdot \\mid s)}[Q^\\pi(s,a)]$.\n    \\item The \\emph{advantage function}: $A^\\pi(s,a) = Q^\\pi(s,a) - V^\\pi(s)$\n    \\item The optimal value and action-value functions are obtained by acting according to an optimal policy $\\pi^*$: $V^*(s) = \\max_{\\pi} V^{\\pi}(s)$, $Q^*(s,a) = \\max_{\\pi} Q^{\\pi}(s,a)$. We have $V^*(s) = \\max_a Q^*(s,a)$, and a deterministic optimal policy can be obtained with $\\pi^*(s) = \\argmax_a Q^*(s,a)$.\n\\end{itemize}\n\n\\paragraph{Bellman Equations}\n\\begin{equation}\n    % V^{\\pi}(s) = \\E_{a \\sim \\pi(\\cdot \\mid s), s' \\sim P}[R(s, a, s') + \\gamma V^{\\pi}(s')]\n    V^{\\pi}(s) = \\E_{\\substack{a \\sim \\pi(\\cdot \\mid s) \\\\ s' \\sim P}}[R(s, a, s') + \\gamma V^{\\pi}(s')]\n\\label{eq:bellman-v}\n\\end{equation}\n\n\\begin{equation}\n    Q^{\\pi}(s, a) = \\E_{s' \\sim P}\\left[R(s, a, s') + \\gamma \\E_{a'\\sim \\pi(\\cdot \\mid s')}[Q^{\\pi}(s', a')] \\right]\n\\label{eq:bellman-q}\n\\end{equation}\n\n\\begin{equation}\n    V^*(s) = \\max_a \\E_{s' \\sim P}\\left[R(s, a, s') + \\gamma V^*(s')\\right]\n\\label{eq:bellman-v*}\n\\end{equation}\n\n\\begin{equation}\n    Q^*(s, a) = \\E_{s' \\sim P}\\left[R(s, a, s') + \\gamma \\max_{a'} Q^*(s', a')\\right]\n\\label{eq:bellman-q*}\n\\end{equation}\n\nWhere $s' \\sim P$ is a shorthand for $s' \\sim P(\\cdot\\mid s,a)$", "meta": {"hexsha": "94628ec33e777af5117af6aca6a2aa553c58814e", "size": 4289, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/2_framework.tex", "max_stars_repo_name": "alexandrethm/rl-cheatseet", "max_stars_repo_head_hexsha": "1f1d1f51b66eb48981d07f991ebfef8f76292138", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2021-06-18T23:54:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T11:54:02.000Z", "max_issues_repo_path": "sections/2_framework.tex", "max_issues_repo_name": "alexandrethm/rl-cheatsheet", "max_issues_repo_head_hexsha": "1f1d1f51b66eb48981d07f991ebfef8f76292138", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/2_framework.tex", "max_forks_repo_name": "alexandrethm/rl-cheatsheet", "max_forks_repo_head_hexsha": "1f1d1f51b66eb48981d07f991ebfef8f76292138", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 85.78, "max_line_length": 450, "alphanum_fraction": 0.6630916298, "num_tokens": 1483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913354875362, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.8062277023925363}}
{"text": "\\textbf{Consider the differential equation}\n\\begin{align*}\ny' = \\sin(t)(y^2 - \\cos^2(t) -1),~~y(0)=1,~~t>0.\n\\end{align*}\n\\textbf{The exact solution to this nonlinear ODE is $y(t) = \\cos(t)$.}\n\n\\textbf{Use \\texttt{rk4} to solve this equation for $t \\in [0,50]$. Plot the error vs. values of $\\Delta t$ (use \\texttt{loglog}). Does the error decay as $\\mathcal{O}(\\Delta t^4)$? }\n\n\\begin{figure}[H]\n\\center{\\includegraphics[scale=.75]{problem1_a.eps}}\n\\caption{Error Vs. $\\Delta t$}\n\\end{figure}\n\nAs we can see in the figure above, we have done a linear fit with the \\textsl{Matlab} function \\texttt{polyfit} obtaining a slope of $4$. Hence, the figure above shows that the error decays as $\\mathcal{O}(\\Delta t^4)$.\n\n\n\\textbf{You will now compare \\texttt{rk4}, forward-Euler, and modified Euler methods. Solve the problem with these three methods for several $\\Delta t$. on a \\texttt{loglog} plot, show the error vs. the number of function evaluations used by eahc method. Using the number of function evaluations as a measure of cost, is it worth using several stages in RK methods? }\n\n\\begin{figure}[H]\n\\center{\\includegraphics[scale=.75]{problem1_b.eps}}\n\\caption{Error Vs. cost}\n\\end{figure}\n\nAs we can see in the previous figure, it is worth using several stages in RK methods despite their cost. With the same number of funciton evaluations, RK4 reaches much higher level of accuracy. \n\n\\subsection*{Matlab code for this part}\n\\begin{verbatim}\nclear variables; close all; format long; clc\npath='Latex/FIGURES/';\n\nlinewidth=1.2;\nmarkersize=7.5;\nlegendfontsize=12;\naxisfontsize=16;\n\n%% Problem 1\n% Part a)\ndt = 2e-1;\ndydt = @(t,y) sin(t)*(y.^2-(cos(t))^2-1);\nerr=1;\ntol=1e-12;\ntspan=[0 50];\ny0=1;\ni=1;\nwhile err>tol\n    N=(tspan(2)-tspan(1))/dt(i);\n    [t,y] = rk4(dydt,tspan,y0,N);\n    err(i)=norm(y-cos(t),inf);\n    dt(i+1)=dt(i)/2;\n    i=i+1;\nend\ndt(end)=[];\n\n% Linear fit\nP=polyfit(log(dt),log(err),1);\ndtfit=2*dt(1):-0.001:dt(end)/2;\nerrfit=exp(P(2))*dtfit.^(P(1));\n\nfigure(1)\nloglog(dt,err,'r*','markersize',markersize)\ngrid on\nhold on\nloglog(dtfit,errfit,'b-.','linewidth',linewidth)\ngrid on\nxlabel('$\\log(\\Delta t)$','Interpreter','latex')\nylabel('$\\log(\\epsilon)$','Interpreter','latex')\nset(gca,'fontsize',14)\ntxt=[path,'problem1_a'];\nsaveas(gcf,txt,'epsc')\n\n% Part b)\nN=2.^(4:12);\nfor i=1:length(N);\n    [t1,y1] = euler(dydt,tspan,y0,N(i));\n    [t2,y2] = modEuler(dydt,tspan,y0,N(i));\n\t[t4,y4] = rk4(dydt,tspan,y0,N(i));\n    err1(i)=norm(y1-cos(t1),inf);\n    err2(i)=norm(y2-cos(t2),inf);\n    err4(i)=norm(y4-cos(t4),inf);\nend\nfigure\nloglog(N,err1,2*N,err2,4*N,err4)\ngrid on\nylabel('$\\log(\\epsilon)$','Interpreter','latex')\nset(gca,'fontsize',12)\nxlabel('Function Evaluations','Interpreter','latex')\nlegend({'Euler','Modified Euler', 'RK4'},'fontsize',14)\ntxt=[path,'problem1_b'];\nsaveas(gcf,txt,'epsc')\n\nfunction [t,w] = rk4(dydt,tspan,y0,N)\n\nh = diff(tspan)/N;\nt = tspan(1) + h*(0:N)';\nw = zeros(length(y0),N+1);\nw(:,1) = y0(:).';\n\nfor i = 1:N\n    k1 = h*dydt(t(i)    ,w(:,i)      );\n    k2 = h*dydt(t(i)+h/2, w(:,i)+k1/2);\n    k3 = h*dydt(t(i)+h/2, w(:,i)+k2/2);\n    k4 = h*dydt(t(i)+h  , w(:,i)+k3  );\n    w(:,i+1) = w(:,i) + (k1 + 2*k2 + 2*k3 + k4)/6;\nend\nw = w.';\nend\n\nfunction [t,w] = modEuler(dydt,tspan,y0,N)\n\nh = diff(tspan)/N;\nt = tspan(1) + h*(0:N)';\nw = zeros(length(y0),N+1);\nw(:,1) = y0(:).';\n\nfor i = 1:N\n    k1 = h*dydt(t(i)    ,w(:,i)      );\n    k2 = h*dydt(t(i)+h, w(:,i)+k1);\n    w(:,i+1) = w(:,i) + (k1 + k2)/2;\nend\nw = w.';\nend\n\nfunction [t,w] = euler(dydt,tspan,y0,N)\n\nh = diff(tspan)/N;\nt = tspan(1) + h*(0:N)';\nw = zeros(length(y0),N+1);\nw(:,1) = y0(:).';\n\nfor i = 1:N\n    k1 = h*dydt(t(i)    ,w(:,i)      );\n\tw(:,i+1) = w(:,i) + k1;\nend\nw = w.';\nend\n\\end{verbatim}", "meta": {"hexsha": "5d405f0bdffca12edeff4ab7eab02172e6d63435", "size": 3704, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/problem1.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/problem1.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/problem1.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2352941176, "max_line_length": 367, "alphanum_fraction": 0.6201403888, "num_tokens": 1391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.9184802518352773, "lm_q1q2_score": 0.8059451007459313}}
{"text": "\\chapter{Probability}\n\n\\section{Frequentists vs. Bayesians}\nwhat is probability? \n\nOne is called the \\textbf{frequentist} interpretation. In this view, probabilities represent long run frequencies of events. For example, the above statement means that, if we flip the coin many times, we expect it to land heads about half the time.\n\nThe other interpretation is called the \\textbf{Bayesian} interpretation of probability. In this view, probability is used to quantify our \\textbf{uncertainty} about something; hence it is fundamentally related to information rather than repeated trials (Jaynes 2003). In the Bayesian view, the above statement means we believe the coin is equally likely to land heads or tails on the next toss\n\nOne big advantage of the Bayesian interpretation is that it can be used to model our uncertainty about events that do not have long term frequencies. For example, we might want to compute the probability that the polar ice cap will melt by 2020 CE. This event will happen zero or one times, but cannot happen repeatedly. Nevertheless, we ought to be able to quantify our uncertainty about this event. To give another machine learning oriented example, we might have observed a \u201cblip\u201d on our radar screen, and want to compute the probability distribution over the location of the corresponding target (be it a bird, plane, or missile). In all these cases, the idea of repeated trials does not make sense, but the Bayesian interpretation is valid and indeed quite natural. We shall therefore adopt the Bayesian interpretation in this book. Fortunately, the basic rules of probability theory are the same, no matter which interpretation is adopted.\n\n\n\\section{A brief review of probability theory}\n\n\n\\subsection{Basic concepts}\nWe denote a random event by defining a \\textbf{random variable} $X$.\n\n\\textbf{Descrete random variable}: $X$ can take on any value from a finite or countably infinite set.\n\n\\textbf{Continuous random variable}: the value of $X$ is real-valued.\n\n\n\\subsubsection{CDF}\n\n\\begin{equation}\nF(x) \\triangleq P(X \\leq x)=\\begin{cases}\n\\sum_{u \\leq x}p(u) & \\text{, discrete}\\\\\n\\int_{-\\infty}^{x} f(u)\\mathrm{d}u & \\text{, continuous}\\\\\n\\end{cases}\n\\end{equation}\n\n\n\\subsubsection{PMF and PDF}\nFor descrete random variable, We denote the probability of the event that $X=x$ by $P(X=x)$, or just $p(x)$ for short. Here $p(x)$ is called a \\textbf{probability mass function} or \\textbf{PMF}.A probability mass function is a function that gives the probability that a discrete random variable is exactly equal to some value\\footnote{\\url{http://en.wikipedia.org/wiki/Probability_mass_function}}. This satisfies the properties $0 \\leq p(x) \\leq 1$ and $\\sum_{x \\in \\mathcal{X}} p(x)=1$.\n\nFor continuous variable, in the equation $F(x)=\\int_{-\\infty}^{x} f(u)\\mathrm{d}u$, the function $f(x)$ is called a \\textbf{probability density function} or \\textbf{PDF}. A probability density function is a function that describes the relative likelihood for this random variable to take on a given value\\footnote{\\url{http://en.wikipedia.org/wiki/Probability_density_function}}.This satisfies the properties $f(x) \\geq 0$ and $\\int_{-\\infty}^{\\infty} f(x)\\mathrm{d}x=1$.\n\n\n\\subsection{Mutivariate random variables}\n\n\n\\subsubsection{Joint CDF}\nWe denote joint CDF by $F(x,y) \\triangleq P(X \\leq x \\cap Y \\leq y)=P(X \\leq x , Y \\leq y)$.\n\n\\begin{equation}\nF(x,y) \\triangleq P(X \\leq x, Y \\leq y)=\\begin{cases}\n\\sum_{u \\leq x, v \\leq y}p(u,v) \\\\\n\\int_{-\\infty}^{x}\\int_{-\\infty}^{y} f(u,v)\\mathrm{d}u\\mathrm{d}v \\\\\n\\end{cases}\n\\end{equation}\n\n\\textbf{product rule}:\n\\begin{equation}\\label{eqn:product-rule}\np(X,Y)=P(X|Y)P(Y)\n\\end{equation}\n\n\\textbf{Chain rule}:\n\\begin{equation}\np(X_{1:N})=p(X_1)p(X_3|X_2,X_1)...p(X_N|X_{1:N-1})\n\\end{equation}\n\n\n\\subsubsection{Marginal distribution}\n\\textbf{Marginal CDF}:\n\\begin{equation}\\begin{split}\n& F_X(x) \\triangleq F(x,+\\infty)= \\\\\n& \\begin{cases}\n\\sum\\limits_{x_i \\leq x}P(X=x_i)=\\sum\\limits_{x_i \\leq x}\\sum\\limits_{j=1}^{+\\infty}P(X=x_i,Y=y_j) \\\\\n\\int_{-\\infty}^{x}f_X(u)du=\\int_{-\\infty}^{x}\\int_{-\\infty}^{+\\infty} f(u,v)\\mathrm{d}u\\mathrm{d}v \\\\\n\\end{cases}\n\\end{split}\\end{equation}\n\n\\begin{equation}\\begin{split}\n& F_Y(y) \\triangleq F(+\\infty,y)= \\\\\n& \\begin{cases}\n\\sum\\limits_{y_j \\leq y}p(Y=y_j)=\\sum\\limits_{i=1}^{+\\infty}\\sum_{y_j \\leq y}P(X=x_i,Y=y_j) \\\\\n\\int_{-\\infty}^{y}f_Y(v)dv=\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{y} f(u,v)\\mathrm{d}u\\mathrm{d}v \\\\\n\\end{cases}\n\\end{split}\\end{equation}\n\n\\textbf{Marginal PMF and PDF}:\n\\begin{equation} \\begin{cases}\nP(X=x_i)=\\sum_{j=1}^{+\\infty}P(X=x_i,Y=y_j) & \\text{, descrete}\\\\\nf_X(x)=\\int_{-\\infty}^{+\\infty} f(x,y)\\mathrm{d}y & \\text{, continuous}\\\\\n\\end{cases}\\end{equation}\n\n\\begin{equation}\\begin{cases}\np(Y=y_j)=\\sum_{i=1}^{+\\infty}P(X=x_i,Y=y_j) & \\text{, descrete}\\\\\nf_Y(y)=\\int_{-\\infty}^{+\\infty} f(x,y)\\mathrm{d}x & \\text{, continuous}\\\\\n\\end{cases}\\end{equation}\n\n\n\\subsubsection{Conditional distribution}\n\\textbf{Conditional PMF}:\n\\begin{equation}\np(X=x_i|Y=y_j)=\\dfrac{p(X=x_i,Y=y_j)}{p(Y=y_j)} \\text{ if } p(Y)>0\n\\end{equation}\nThe pmf $p(X|Y)$ is called \\textbf{conditional probability}.\n\n\\textbf{Conditional PDF}:\n\\begin{equation}\nf_{X|Y}(x|y)=\\dfrac{f(x,y)}{f_Y(y)}\n\\end{equation}\n\n\\subsection{Bayes rule}\n\\begin{equation}\n\\begin{split}\np(Y=y|X=x) & =\\dfrac{p(X=x,Y=y)}{p(X=x)} \\\\\n           & =\\dfrac{p(X=x|Y=y)p(Y=y)}{\\sum_{y'}p(X=x|Y=y')p(Y=y')}\n\\end{split}\n\\end{equation}\n\n\n\\subsection{Independence and conditional independence}\nWe say $X$ and $Y$ are unconditionally independent or marginally independent, denoted $X \\perp Y$, if we can represent the joint as the product of the two marginals, i.e.,\n\\begin{equation}\nX \\perp Y=P(X,Y)=P(X)P(Y)\n\\end{equation}\n\nWe say $X$ and $Y$ are conditionally independent(CI) given $Z$ if the conditional joint can be written as a product of conditional marginals:\n\\begin{equation}\nX \\perp Y|Z=P(X,Y|Z)=P(X|Z)P(Y|Z)\n\\end{equation}\n\n\\subsection{Quantiles}\nSince the cdf $F$ is a monotonically increasing function, it has an inverse; let us denote this by $F^{-1}$. If $F$ is the cdf of $X$ , then $F^{-1}(\\alpha)$ is the value of $x_{\\alpha}$ such that $P(X \\leq x_{\\alpha})=\\alpha$; this is called the $\\alpha$ quantile of $F$. The value $F^{-1}(0.5)$ is the \\textbf{median} of the distribution, with half of the probability mass on the left, and half on the right. The values $F^{-1}(0.25)$ and $F^{\u22121}(0.75)$are the lower and upper \\textbf{quartiles}.\n\n\\subsection{Mean and variance}\nThe most familiar property of a distribution is its \\textbf{mean},or \\textbf{expected value}, denoted by $\\mu$. For discrete rv\u2019s, it is defined as $\\mathbb{E}[X] \\triangleq \\sum_{x \\in \\mathcal{X}}xp(x)$, and for continuous rv\u2019s, it is defined as $\\mathbb{E}[X] \\triangleq \\int_{\\mathcal{X}}xp(x)\\mathrm{d}x$. If this integral is not finite, the mean is not defined (we will see some examples of this later). \n\nThe \\textbf{variance} is a measure of the \u201cspread\u201d of a distribution, denoted by $\\sigma^2$. This is defined as follows:\n\\begin{align}\nvar[X]& =\\mathbb{E}[(X-\\mu)^2] \\\\\n      & =\\int{(x-\\mu)^2p(x)\\mathrm{d}x} \\nonumber \\\\\n      & =\\int{x^2p(x)\\mathrm{d}x}+{\\mu}^2\\int{p(x)\\mathrm{d}x}-2\\mu\\int{xp(x)\\mathrm{d}x} \\nonumber \\\\\n\t  & =\\mathbb{E}[X^2]-{\\mu}^2\n\\end{align}\n\nfrom which we derive the useful result\n\\begin{equation}\n\\mathbb{E}[X^2]=\\sigma^2+{\\mu}^2\n\\end{equation}\n\nThe \\textbf{standard deviation} is defined as\n\\begin{equation}\nstd[X] \\triangleq \\sqrt{var[X]}\n\\end{equation}\n\nThis is useful since it has the same units as $X$ itself.\n\n\\section{Some common discrete distributions}\nIn this section, we review some commonly used parametric distributions defined on discrete state spaces, both finite and countably infinite.\n\n\n\\subsection{The Bernoulli and binomial distributions}\n\n\\begin{definition}\nNow suppose we toss a coin only once. Let $X \\in \\{0,1\\}$ be a binary random variable, with probability of \u201csuccess\u201d or \u201cheads\u201d of $\\theta$. We say that $X$ has a \\textbf{Bernoulli distribution}. This is written as $X \\sim \\text{Ber}(\\theta)$, where the pmf is defined as \n\\begin{equation}\n\\text{Ber}(x|\\theta) \\triangleq \\theta^{\\mathbb{I}(x=1)}(1-\\theta)^{\\mathbb{I}(x=0)}\n\\end{equation}\n\\end{definition}\n\n\n\\begin{definition}\nSuppose we toss a coin $n$ times. Let $X \\in \\{0,1,\\cdots,n\\}$ be the number of heads. If the probability of heads is $\\theta$, then we say $X$ has a \\textbf{binomial distribution}, written as $X \\sim \\text{Bin}(n, \\theta)$. The pmf is given by \n\\begin{equation}\\label{eqn:binomial-pmf}\n\\text{Bin}(k|n,\\theta) \\triangleq \\dbinom{n}{k}\\theta^k(1-\\theta)^{n-k}\n\\end{equation}\n\\end{definition}\n\n\n\\subsection{The multinoulli and multinomial distributions}\n\n\\begin{definition}\nThe Bernoulli distribution can be used to model the outcome of one coin tosses. To model the outcome of tossing a K-sided dice, let $\\vec{x} =(\\mathbb{I}(x=1),\\cdots,\\mathbb{I}(x=K)) \\in \\{0,1\\}^K$ be a random vector(this is called \\textbf{dummy encoding} or \\textbf{one-hot encoding}), then we say $X$ has a \\textbf{multinoulli distribution}(or \\textbf{categorical distribution}), written as $X \\sim \\text{Cat}(\\theta)$. The pmf is given by: \n\\begin{equation}\np(\\vec{x}) \\triangleq \\prod\\limits_{k=1}^K\\theta_k^{\\mathbb{I}(x_k=1)}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\nSuppose we toss a K-sided dice $n$ times. Let $\\vec{x} =(x_1,x_2,\\cdots,x_K) \\in \\{0,1,\\cdots,n\\}^K$ be a random vector, where $x_j$ is the number of times side $j$ of the dice occurs, then we say $X$ has a \\textbf{multinomial distribution}, written as $X \\sim \\text{Mu}(n, \\vec{\\theta})$. The pmf is given by \n\\begin{equation}\\label{eqn:multinomial-pmf}\np(\\vec{x}) \\triangleq \\dbinom{n}{x_1 \\cdots x_k} \\prod\\limits_{k=1}^K\\theta_k^{x_k}\n\\end{equation}\nwhere $\\dbinom{n}{x_1 \\cdots x_k} \\triangleq \\dfrac{n!}{x_1!x_2! \\cdots x_K!}$\n\\end{definition}\n\nBernoulli distribution is just a special case of a Binomial distribution with $n=1$, and so is multinoulli distribution as to multinomial distribution. See Table \\ref{tab:multinomial-summary} for a summary.\n\n\\begin{table}\n\\caption{Summary of the multinomial and related distributions.}\n\\label{tab:multinomial-summary}\n\\centering\n\\begin{tabular}{llll}\n\\hline\\noalign{\\smallskip}\nName & K & n & X \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nBernoulli & 1 & 1 & $x \\in \\{0,1\\}$ \\\\\nBinomial & 1 & - & $\\vec{x} \\in \\{0,1,\\cdots,n\\}$ \\\\\nMultinoulli & - & 1 & $\\vec{x} \\in \\{0,1\\}^K, \\sum_{k=1}^K x_k=1$ \\\\\nMultinomial & - & - & $\\vec{x} \\in \\{0,1,\\cdots,n\\}^K, \\sum_{k=1}^K x_k=n$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table} \n\n\n\\subsection{The Poisson distribution}\n\\begin{definition}\nWe say that $X \\in \\{0,1,2,\\cdots\\}$ has a \\textbf{Poisson distribution} with parameter $\\lambda>0$, written as $X \\sim \\text{Poi}(\\lambda)$, if its pmf is\n\\begin{equation}\np(x|\\lambda)=e^{-\\lambda}\\dfrac{\\lambda^x}{x!}\n\\end{equation}\n\\end{definition}\n\nThe first term is just the normalization constant, required to ensure the distribution sums to 1.\n\nThe Poisson distribution is often used as a model for counts of rare events like radioactive decay and traffic accidents. \n\n\\begin{table*}\n\\caption{Summary of Bernoulli, binomial multinoulli and multinomial distributions.}\n\\label{tab:Summary-distribution}\n\\centering\n\\begin{tabular}{llllll}\n\\hline\\noalign{\\smallskip}\nName & Written as & X & $p(x)$(or $p(\\vec{x})$) & $\\mathbb{E}[X]$ & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nBernoulli & $X \\sim \\text{Ber}(\\theta)$ & $x \\in \\{0,1\\}$ & $\\theta^{\\mathbb{I}(x=1)}(1-\\theta)^{\\mathbb{I}(x=0)}$ & $\\theta$ & $\\theta(1-\\theta)$ \\\\\nBinomial & $X \\sim \\text{Bin}(n,\\theta)$ & $x \\in \\{0,1,\\cdots,n\\}$ & $\\dbinom{n}{k}\\theta^k(1-\\theta)^{n-k}$ & $n\\theta$ & $n\\theta(1-\\theta)$ \\\\\nMultinoulli & $X \\sim \\text{Cat}(\\vec{\\theta})$ & $\\vec{x} \\in \\{0,1\\}^K, \\sum_{k=1}^K x_k=1$ & $\\prod\\limits_{k=1}^K\\theta_j^{\\mathbb{I}(x_j=1)}$ & - & - \\\\\nMultinomial & $X \\sim \\text{Mu}(n,\\vec{\\theta})$ & $\\vec{x} \\in \\{0,1,\\cdots,n\\}^K, \\sum_{k=1}^K x_k=n$ & $\\dbinom{n}{x_1 \\cdots x_k} \\prod\\limits_{k=1}^K\\theta_j^{x_j}$ & - & - \\\\\nPoisson & $X \\sim \\text{Poi}(\\lambda)$ & $x \\in \\{0,1,2,\\cdots\\}$ & $e^{-\\lambda}\\dfrac{\\lambda^x}{x!}$ & $\\lambda$ & $\\lambda$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table*}\n\n\n\\subsection{The empirical distribution}\nThe \\textbf{empirical distribution function}\\footnote{\\url{http://en.wikipedia.org/wiki/Empirical_distribution_function}}, or \\textbf{empirical cdf}, is the cumulative distribution function associated with the empirical measure of the sample. Let $\\mathcal{D}=\\{x_1,x_2,\\cdots,x_N\\}$ be a sample set, it is defined as \n\\begin{equation}\nF_n(x) \\triangleq \\dfrac{1}{N}\\sum\\limits_{i=1}^N\\mathbb{I}(x_i \\leq x)\n\\end{equation}\n\n\n\\section{Some common continuous distributions}\nIn this section we present some commonly used univariate (one-dimensional) continuous probability distributions.\n\n\n\\subsection{Gaussian (normal) distribution}\n\n% \\begin{table}\n% \\caption{Summary of Gaussian distribution}\n% \\centering\n% \\begin{tabular}{cccccc}\n% \\hline\\noalign{\\smallskip}\n% Name & Written as & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n% \\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\n% Gaussian distribution & $X \\sim \\mathcal{N}(\\mu,\\sigma^2)$ & $\\dfrac{1}{\\sqrt{2\\pi}\\sigma}e^{-\\frac{1}{2\\sigma^2}\\left(x-\\mu\\right)^2}$ & $\\mu$ & $\\mu$ & $\\sigma^2$ \\\\\n% \\noalign{\\smallskip}\\hline\n% \\end{tabular}\n% \\end{table} \n\n\\begin{table}\n\\caption{Summary of Gaussian distribution.}\n\\centering\n\\begin{tabular}{cccccc}\n\\hline\\noalign{\\smallskip}\nWritten as & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\n$X \\sim \\mathcal{N}(\\mu,\\sigma^2)$ & $\\dfrac{1}{\\sqrt{2\\pi}\\sigma}e^{-\\frac{1}{2\\sigma^2}\\left(x-\\mu\\right)^2}$ & $\\mu$ & $\\mu$ & $\\sigma^2$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table} \n\nIf $X \\sim N(0,1)$,we say $X$ follows a \\textbf{standard normal} distribution.\n\nThe Gaussian distribution is the most widely used distribution in statistics. There are several reasons for this. \n\\begin{enumerate}\n\\item First, it has two parameters which are easy to interpret, and which capture some of the most basic properties of a distribution, namely its mean and variance. \n\\item Second,the central limit theorem (Section TODO) tells us that sums of independent random variables have an approximately Gaussian distribution, making it a good choice for modeling residual errors or \u201cnoise\u201d. \n\\item Third, the Gaussian distribution makes the least number of assumptions (has maximum entropy), subject to the constraint of having a specified mean and variance, as we show in Section TODO; this makes it a good default choice in many cases. \n\\item Finally, it has a simple mathematical form, which results in easy to implement, but often highly effective, methods, as we will see. \n\\end{enumerate}\nSee (Jaynes 2003, ch 7) for a more extensive discussion of why Gaussians are so widely used.\n\n\n\\subsection{Student's t-distribution}\n\\begin{table}\n\\caption{Summary of Student's t-distribution.}\n\\centering\n\\begin{tabular}{cccccc}\n\\hline\\noalign{\\smallskip}\nWritten as & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\n$X \\sim \\mathcal{T}(\\mu,\\sigma^2,\\nu)$ & $\\dfrac{\\Gamma(\\frac{\\nu+1}{2})}{\\sqrt{\\nu\\pi}\\Gamma(\\frac{\\nu}{2})}\\left[1+\\dfrac{1}{\\nu}\\left(\\dfrac{x-\\mu}{\\nu}\\right)^2\\right]$ & $\\mu$ & $\\mu$ & $\\dfrac{\\nu\\sigma^2}{\\nu-2}$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table}\nwhere  $\\Gamma(x)$ is the gamma function:\n\\begin{equation}\n\\Gamma(x) \\triangleq \\int_0^\\infty t^{x-1}e^{-t}\\mathrm{d}t\n\\end{equation}\n$\\mu$ is the mean, $\\sigma^2>0$ is the scale parameter, and $\\nu>0$ is called the \\textbf{degrees of freedom}. See Figure \\ref{fig:pdfs-for-NTL} for some plots.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.70]{pdfs-for-NTL-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.70]{pdfs-for-NTL-b.png}}\n\\caption{(a) The pdf\u2019s for a $\\mathcal{N}(0,1)$, $\\mathcal{T}(0,1,1)$ and $Lap(0,1/\\sqrt{2})$. The mean is 0 and the variance is 1 for both the Gaussian and Laplace. The mean and variance of the Student is undefined when $\\nu=1$.(b) Log of these pdf\u2019s. Note that the Student distribution is not log-concave for any parameter value, unlike the Laplace distribution, which is always log-concave (and log-convex...) Nevertheless, both are unimodal.}\n\\label{fig:pdfs-for-NTL} \n\\end{figure}\n\nThe variance is only defined if $\\nu>2$. The mean is only defined if $\\nu>1$.\n\nAs an illustration of the robustness of the Student distribution, consider Figure \\ref{fig:robustness}. We see that the Gaussian is affected a lot, whereas the Student distribution hardly changes. This is because the Student has heavier tails, at least for small $\\nu$(see Figure \\ref{fig:pdfs-for-NTL}).\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.70]{robustness-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.70]{robustness-b.png}}\n\\caption{Illustration of the effect of outliers on fitting Gaussian, Student and Laplace distributions. (a) No outliers (the Gaussian and Student curves are on top of each other). (b) With outliers. We see that the Gaussian is more affected by outliers than the Student and Laplace distributions.}\n\\label{fig:robustness} \n\\end{figure}\n\nIf $\\nu=1$, this distribution is known as the \\textbf{Cauchy} or \\textbf{Lorentz} distribution. This is notable for having such heavy tails that the integral that defines the mean does not converge.\n\nTo ensure finite variance, we require $\\nu>2$. It is common to use $\\nu=4$, which gives good performance in a range of problems (Lange et al. 1989). For $\\nu \\gg 5$, the Student distribution rapidly approaches a Gaussian distribution and loses its robustness properties.\n\n\n\\subsection{The Laplace distribution}\n\\begin{table}\n\\caption{Summary of Laplace distribution.}\n\\centering\n\\begin{tabular}{cccccc}\n\\hline\\noalign{\\smallskip}\nWritten as & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\n$X \\sim \\text{Lap}(\\mu,b)$ & $\\dfrac{1}{2b}\\exp\\left(-\\dfrac{|x-\\mu|}{b}\\right)$ & $\\mu$ & $\\mu$ & $2b^2$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table}\n\nHere $\\mu$ is a location parameter and $b>0$ is a scale parameter. See Figure \\ref{fig:pdfs-for-NTL} for a plot.\n\nIts robustness to outliers is illustrated in Figure \\ref{fig:robustness}. It also put mores probability density at 0 than the Gaussian. This property is a useful way to encourage sparsity in a model, as we will see in Section TODO.\n\n\n\\subsection{The gamma distribution}\n\n\\begin{table}\n\\caption{Summary of gamma distribution}\n\\centering\n\\begin{tabular}{ccccccc}\n\\hline\\noalign{\\smallskip}\nWritten as & $X$ & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\n$X \\sim \\text{Ga}(a,b)$ & $x \\in \\mathbb{R}^+$ & $\\dfrac{b^a}{\\Gamma(a)}x^{a-1}e^{-xb}$ & $\\dfrac{a}{b}$ & $\\dfrac{a-1}{b}$ & $\\dfrac{a}{b^2}$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table} \n\nHere $a>0$ is called the shape parameter and $b>0$ is called the rate parameter. See Figure \\ref{fig:gamma-distribution} for some plots.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.50]{gamma-distribution-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.50]{gamma-distribution-b.png}}\n\\caption{Some Ga$(a, b=1)$ distributions. If $a \\leq 1$, the mode is at 0, otherwise it is $>0$.As we increase the rate $b$, we reduce the horizontal scale, thus squeezing everything leftwards and upwards. (b) An empirical pdf of some rainfall data, with a fitted Gamma distribution superimposed.}\n\\label{fig:gamma-distribution} \n\\end{figure}\n\n\n\\subsection{The beta distribution}\n\n\\begin{table*}\n\\caption{Summary of Beta distribution}\\label{tab:beta-distribution}\n\\centering\n\\begin{tabular}{ccccccc}\n\\hline\\noalign{\\smallskip}\nName & Written as & $X$ & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nBeta distribution & $X \\sim \\text{Beta}(a,b)$ & $x \\in [0,1]$ & $\\dfrac{1}{B(a,b)}x^{a-1}(1-x)^{b-1}$ & $\\dfrac{a}{a+b}$ & $\\dfrac{a-1}{a+b-2}$ & $\\dfrac{ab}{(a+b)^2(a+b+1)}$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table*} \n\nHere $B(a, b)$is the beta function,\n\\begin{equation}\nB(a,b) \\triangleq \\dfrac{\\Gamma(a)\\Gamma(b)}{\\Gamma(a+b)}\n\\end{equation}\n\nSee Figure \\ref{fig:beta-distribution} for plots of some beta distributions. We require  $a, b >0$ to ensure the distribution is integrable (i.e., to ensure $B(a, b)$ exists). If $a=b=1$, we get the uniform distirbution. If $a$ and $b$ are both less than 1, we get a bimodal distribution with \u201cspikes\u201d at 0 and 1; if $a$ and $b$ are both greater than 1, the distribution is unimodal.\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.60]{beta-distribution.png}\n\\caption{Some beta distributions.}\n\\label{fig:beta-distribution} \n\\end{figure}\n\n\n\\subsection{Pareto distribution}\n\n\\begin{table*}\n\\caption{Summary of Pareto distribution}\n\\centering\n\\begin{tabular}{ccccccc}\n\\hline\\noalign{\\smallskip}\nName & Written as & $X$ & $f(x)$ & $\\mathbb{E}[X]$ & mode & $\\text{var}[X]$ \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nPareto distribution & $X \\sim \\text{Pareto}(k,m)$ & $x \\geq m$ & $km^kx^{-(k+1)}\\mathbb{I}(x \\geq m)$ & $\\dfrac{km}{k-1} \\text{ if } k > 1$ & $m$ & $\\dfrac{m^2k}{(k-1)^2(k-2)} \\text{ if } k>2$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table*} \n\nThe \\textbf{Pareto distribution} is used to model the distribution of quantities that exhibit \\textbf{long tails}, also called \\textbf{heavy tails}.\n\nAs $k \\rightarrow \\infty$, the distribution approaches $\\delta(x-m)$. See Figure \\ref{fig:Pareto-distribution}(a) for some plots. If we plot the distribution on a log-log scale, it forms a straight line, of the form $\\log p(x)=a\\log x+c$ for some constants $a$ and $c$. See Figure \\ref{fig:Pareto-distribution}(b) for an illustration (this is known as a \\textbf{power law}).\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.50]{pareto-distribution-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.50]{pareto-distribution-b.png}}\n\\caption{(a) The Pareto distribution Pareto$(x|m, k)$ for $m=1$. (b) The pdf on a log-log scale.}\n\\label{fig:Pareto-distribution} \n\\end{figure}\n\n\n\\section{Joint probability distributions}\nGiven a \\textbf{multivariate random variable} or \\textbf{random vector} \\footnote{\\url{http://en.wikipedia.org/wiki/Multivariate_random_variable}} $X \\in \\mathbb{R}^D$, the \\textbf{joint probability distribution}\\footnote{\\url{http://en.wikipedia.org/wiki/Joint_probability_distribution}} is a probability distribution that gives the probability that each of $X_1, X_2, \\cdots,X_D$ falls in any particular range or discrete set of values specified for that variable. In the case of only two random variables, this is called a \\textbf{bivariate distribution}, but the concept generalizes to any number of random variables, giving a \\textbf{multivariate distribution}.\n\nThe joint probability distribution can be expressed either in terms of a \\textbf{joint cumulative distribution function} or in terms of a \\textbf{joint probability density function} (in the case of continuous variables) or \\textbf{joint probability mass function} (in the case of discrete variables). \n\n\n\\subsection{Covariance and correlation}\n\\begin{definition}\nThe \\textbf{covariance} between two rv\u2019s $X$ and $Y$ measures the degree to which $X$ and $Y$ are (linearly) related. Covariance is defined as\n\\begin{equation}\n\\begin{split}\n\\mathrm{cov}[X,Y] & \\triangleq \\mathbb{E}\\left[(X-\\mathbb{E}[X])(Y-\\mathbb{E}[Y])\\right] \\\\\n         & =\\mathbb{E}[XY]-\\mathbb{E}[X]\\mathbb{E}[Y]\n\\end{split}\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\nIf $X$ is a $D$-dimensional random vector, its \\textbf{covariance matrix} is defined to be the following symmetric, positive definite matrix:\n\\begin{align}\n\\mathrm{cov}[X] & \\triangleq \\mathbb{E}\\left[(X-\\mathbb{E}[X])(X-\\mathbb{E}[X])^T\\right] \\\\\n       &  = \\left( \\begin{array}{cccc}\n           \\text{var}[X_1] & \\text{Cov}[X_1,X_2] & \\cdots & \\text{Cov}[X_1,X_D] \\\\\n           \\text{Cov}[X_2,X_1] & \\text{var}[X_2] & \\cdots & \\text{Cov}[X_2,X_D] \\\\\n\t\t   \\vdots & \\vdots & \\ddots & \\vdots \\\\\n           \\text{Cov}[X_D,X_1] & \\text{Cov}[X_D,X_2] & \\cdots & \\text{var}[X_D] \\end{array} \\right)\n\\end{align}\n\\end{definition}\n\n\\begin{definition}\nThe (Pearson) \\textbf{correlation coefficient} between $X$ and $Y$ is defined as\n\\begin{equation}\n\\text{corr}[X,Y] \\triangleq \\dfrac{\\text{Cov}[X,Y]}{\\sqrt{\\text{var}[X],\\text{var}[Y]}}\n\\end{equation}\n\\end{definition}\n\nA \\textbf{correlation matrix} has the form\n\\begin{equation}\n\\mathbf{R} \\triangleq \\left( \\begin{array}{cccc}\n           \\text{corr}[X_1,X_1] & \\text{corr}[X_1,X_2] & \\cdots & \\text{corr}[X_1,X_D] \\\\\n           \\text{corr}[X_2,X_1] & \\text{corr}[X_2,X_2] & \\cdots & \\text{corr}[X_2,X_D] \\\\\n\t\t   \\vdots & \\vdots & \\ddots & \\vdots \\\\\n           \\text{corr}[X_D,X_1] & \\text{corr}[X_D,X_2] & \\cdots & \\text{corr}[X_D,X_D] \\end{array} \\right)\n\\end{equation}\n\nThe correlation coefficient can viewed as a degree of linearity between $X$ and $Y$, see Figure \\ref{fig:Correlation-examples}.\n\\begin{figure*}[hbtp]\n\\centering\n    \\includegraphics[scale=.80]{Correlation-examples.png}\n\\caption{Several sets of $(x, y)$ points, with the Pearson correlation coefficient of $x$ and $y$ for each set. Note that the correlation reflects the noisiness and direction of a linear relationship (top row), but not the slope of that relationship (middle), nor many aspects of nonlinear relationships (bottom). N.B.: the figure in the center has a slope of 0 but in that case the correlation coefficient is undefined because the variance of $Y$ is zero.Source:\\url{http://en.wikipedia.org/wiki/Correlation}}\n\\label{fig:Correlation-examples} \n\\end{figure*}\n\n\\textbf{Uncorrelated does not imply independent}. For example, let $X \\sim U(-1,1)$ and $Y =X^2$. Clearly $Y$ is dependent on $X$(in fact, $Y$ is uniquely determined by $X$), yet one can show that corr$[X, Y]=0$. Some striking examples of this fact are shown in Figure \\ref{fig:Correlation-examples}. This shows several data sets where there is clear dependence between $X$ and $Y$, and yet the correlation coefficient is 0. A more general measure of dependence between random variables is mutual information, see Section TODO.\n\n\n\\subsection{Multivariate Gaussian distribution}\n\\label{sec:MVN}\nThe \\textbf{multivariate Gaussian} or \\textbf{multivariate normal}(MVN) is the most widely used joint probability density function for continuous variables. We discuss MVNs in detail in Chapter 4; here we just give some definitions and plots.\n\nThe pdf of the MVN in $D$ dimensions is defined by the following:\n\\begin{equation}\n\\mathcal{N}(\\vec{x}|\\vec{\\mu},\\Sigma) \\triangleq \\dfrac{1}{(2\\pi)^{D/2}|\\Sigma|^{1/2}}\\exp\\left[-\\dfrac{1}{2}(\\vec{x}-\\vec{\\mu})^T\\Sigma^{-1}(\\vec{x}-\\vec{\\mu})\\right]\n\\end{equation}\nwhere $\\vec{\\mu}=\\mathbb{E}[X] \\in \\mathbb{R}^D$ is the mean vector, and $\\Sigma=\\text{Cov}[X]$ is the $D \\times D$ covariance matrix. The normalization constant $(2\\pi)^{D/2}|\\Sigma|^{1/2}$ just ensures that the pdf integrates to 1.\n\nFigure \\ref{fig:2d-Gaussions} plots some MVN densities in 2d for three different kinds of covariance matrices. A full covariance matrix has A $D(D+1)/2$ parameters (we divide by 2 since $\\Sigma$ is symmetric). A diagonal covariance matrix has $D$ parameters, and has 0s in the off-diagonal terms. A spherical or isotropic covariance,$\\Sigma=\\sigma^2\\vec{I}_D$, has one free parameter.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.60]{2d-Gaussions-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{2d-Gaussions-b.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{2d-Gaussions-c.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{2d-Gaussions-d.png}}\n\\caption{We show the level sets for 2d Gaussians. (a) A full covariance matrix has elliptical contours.(b) A diagonal covariance matrix is an axis aligned ellipse. (c) A spherical covariance matrix has a circular shape. (d) Surface plot for the spherical Gaussian in (c).}\n\\label{fig:2d-Gaussions} \n\\end{figure}\n\n\n\\subsection{Multivariate Student's t-distribution}\nA more robust alternative to the MVN is the multivariate Student's t-distribution, whose pdf is given by\n\\begin{align}\n& \\mathcal{T}(x|\\vec{\\mu},\\Sigma,\\nu) \\nonumber \\\\\n& \\triangleq \\dfrac{\\Gamma(\\frac{\\nu+D}{2})}{\\Gamma(\\frac{\\nu}{2})}\\dfrac{|\\Sigma|^{-\\frac{1}{2}}}{\\left(\\nu\\pi\\right)^{\\frac{D}{2}}}\\left[1+\\dfrac{1}{\\nu}\\left(\\vec{x}-\\vec{\\mu}\\right)^T\\Sigma^{-1}\\left(\\vec{x}-\\vec{\\mu}\\right)\\right]^{-\\frac{\\nu+D}{2}} \\\\\n&= \\dfrac{\\Gamma(\\frac{\\nu+D}{2})}{\\Gamma(\\frac{\\nu}{2})}\\dfrac{|\\Sigma|^{-\\frac{1}{2}}}{\\left(\\nu\\pi\\right)^{\\frac{D}{2}}}\\left[1+\\left(\\vec{x}-\\vec{\\mu}\\right)^T\\vec{V}^{-1}\\left(\\vec{x}-\\vec{\\mu}\\right)\\right]^{-\\frac{\\nu+D}{2}}\n\\end{align}\nwhere $\\Sigma$ is called the scale matrix (since it is not exactly the covariance matrix) and $\\vec{V}=\\nu\\Sigma$. This has fatter tails than a Gaussian. The smaller $\\nu$ is, the fatter the tails. As $\\nu \\rightarrow \\infty$, the distribution tends towards a Gaussian. The distribution has the following properties\n\\begin{equation}\n\\text{mean}=\\vec{\\mu} \\text{ , mode}=\\vec{\\mu} \\text{ , Cov}= \\dfrac{\\nu}{\\nu-2}\\Sigma\n\\end{equation}\n\n\n\\subsection{Dirichlet distribution}\nA multivariate generalization of the beta distribution is the \\textbf{Dirichlet distribution}, which has\nsupport over the probability simplex, defined by\n\\begin{equation}\nS_K=\\left\\{\\vec{x}:0 \\leq x_k \\leq 1,\\sum\\limits_{k=1}^K x_k=1\\right\\}\n\\end{equation}\n\nThe pdf is defined as follows:\n\\begin{equation}\n\\text{Dir}(\\vec{x}|\\vec{\\alpha}) \\triangleq \\dfrac{1}{B(\\vec{\\alpha})}\\prod\\limits_{k=1}^K x_k^{\\alpha_k-1}\\mathbb{I}(\\vec{x} \\in S_K)\n\\end{equation}\nwhere $B(\\alpha_1,\\alpha_2,\\cdots,\\alpha_K)$ is the natural generalization of the beta function to $K$ variables:\n\\begin{equation}\nB(\\alpha) \\triangleq \\dfrac{\\prod_{k=1}^K \\Gamma(\\alpha_k)}{\\Gamma(\\alpha_0)} \\text{ where } \\alpha_0 \\triangleq \\sum_{k=1}^K \\alpha_k\n\\end{equation}\n\nFigure \\ref{fig:3d-Dirichlet} shows some plots of the Dirichlet when $K=3$, and Figure \\ref{fig:5d-Dirichlet} for some sampled probability vectors. We see that $\\alpha_0$ controls the strength of the distribution (how peaked it is), and the\u03b1kcontrol where the peak occurs. For example, Dir$(1,1,1)$ is a uniform distribution, Dir$(2,2,2)$ is a broad distribution centered at $(1/3,1/3,1/3)$, and Dir$(20,20,20)$ is a narrow distribution centered at $(1/3,1/3,1/3)$.If $\\alpha_k < 1$ for all $k$, we get \u201cspikes\u201d at the corner of the simplex.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.50]{3d-Dirichlet-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{3d-Dirichlet-b.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{3d-Dirichlet-c.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{3d-Dirichlet-d.png}}\n\\caption{(a) The Dirichlet distribution when $K=3$ defines a distribution over the simplex, which can be represented by the triangular surface. Points on this surface satisfy $0 \\leq \\theta_k \\leq 1$ and $\\sum_{k=1}^K \\theta_k=1$. (b) Plot of the Dirichlet density when $\\vec{\\alpha}=(2,2,2)$. (c) $\\vec{\\alpha}=(20,2,2)$.}\n\\label{fig:3d-Dirichlet} \n\\end{figure}\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[$\\vec{\\alpha}=(0.1,\\cdots,0.1)$. This results in very sparse distributions, with many 0s.]{\\includegraphics[scale=.50]{5d-Dirichlet-a.png}} \\\\\n\\subfloat[$\\vec{\\alpha}=(1,\\cdots,1)$. This results in more uniform (and dense) distributions.]{\\includegraphics[scale=.50]{5d-Dirichlet-b.png}}\n\\caption{Samples from a 5-dimensional symmetric Dirichlet distribution for different parameter values.} \n\\label{fig:5d-Dirichlet} \n\\end{figure}\n\nFor future reference, the distribution has these properties\n\\begin{equation}\\label{eqn:Dirichlet-properties}\n\\mathbb{E}(x_k)=\\dfrac{\\alpha_k}{\\alpha_0} \\text{, mode}[x_k]=\\dfrac{\\alpha_k-1}{\\alpha_0-K} \\text{, var}[x_k]=\\dfrac{\\alpha_k(\\alpha_0-\\alpha_k)}{\\alpha_0^2(\\alpha_0+1)}\n\\end{equation}\n\n\n\\section{Transformations of random variables}\nIf $\\vec{x} \\sim P()$ is some random variable, and $\\vec{y}=f(\\vec{x})$, what is the distribution of $Y$? This is the question we address in this section.\n\n\n\\subsection{Linear transformations}\nSuppose $g()$ is a linear function: \n\\begin{equation}\ng(\\vec{x})=A\\vec{x}+b\n\\end{equation}\n\nFirst, for the mean, we have\n\\begin{equation}\n\\mathbb{E}[\\vec{y}]=\\mathbb{E}[A\\vec{x}+b]=A\\mathbb{E}[\\vec{x}]+b\n\\end{equation}\nthis is called the \\textbf{linearity of expectation}.\n\nFor the covariance, we have\n\\begin{equation}\n\\text{Cov}[\\vec{y}]=\\text{Cov}[A\\vec{x}+b]=A\\Sigma A^T\n\\end{equation}\n\n\n\\subsection{General transformations}\n\\label{sec:General-transformations}\nIf $X$ is a discrete rv, we can derive the pmf for $y$ by simply summing up the probability mass for all the $x$\u2019s such that $f(x)=y$:\n\\begin{equation}\\label{eqn:transformation-discrete}\np_Y(y)=\\sum\\limits_{x:g(x)=y}p_X(x)\n\\end{equation}\n\nIf $X$ is continuous, we cannot use Equation \\ref{eqn:transformation-discrete} since $p_X(x)$ is a density, not a pmf, and we cannot sum up densities. Instead, we work with cdf\u2019s, and write\n\\begin{equation}\nF_Y(y)=P(Y \\leq y)=P(g(X) \\leq y)=\\int\\limits_{g(X) \\leq y} f_X(x)\\mathrm{d}x\n\\end{equation}\n\nWe can derive the pdf of $Y$ by differentiating the cdf:\n\\begin{equation}\\label{eqn:General-transformations}\nf_Y(y)=f_X(x)|\\dfrac{dx}{dy}|\n\\end{equation}\n\nThis is called \\textbf{change of variables} formula. We leave the proof of this as an exercise. \n\nFor example, suppose $X \\sim U(\u22121,1)$, and $Y=X^2$. Then $p_Y(y)=\\dfrac{1}{2}y^{-\\frac{1}{2}}$.\n\n\n\\subsubsection{Multivariate change of variables *}\nLet $f$ be a function $f:\\mathbb{R}^n \\rightarrow \\mathbb{R}^n$, and let $\\vec{y}=f(\\vec{x})$. Then its Jacobian matrix $\\vec{J}$ is given by\n\\begin{equation}\n\\vec{J}_{\\vec{x} \\rightarrow \\vec{y}} \\triangleq \\frac{\\partial \\vec{y}}{\\partial \\vec{x}} \\triangleq \\left(\\begin{array}{ccc}\n\\frac{\\partial y_1}{\\partial x_1} & \\cdots & \\frac{\\partial y_1}{\\partial x_n} \\\\\n\\vdots & \\vdots & \\vdots \\\\\n\\frac{\\partial y_n}{\\partial x_1} & \\cdots & \\frac{\\partial y_n}{\\partial x_n}\n\\end{array}\\right)\n\\end{equation}\n$|\\mathrm{det}(\\vec{J})|$ measures how much a unit cube changes in volume when we apply $f$.\n\nIf $f$ is an invertible mapping, we can define the pdf of the transformed variables using the Jacobian of the inverse mapping $\\vec{y} \\rightarrow \\vec{x}$:\n\\begin{equation}\\label{eqn:Multivariate-transformation}\np_y(\\vec{y})=p_x(\\vec{x})|\\mathrm{det}(\\frac{\\partial \\vec{x}}{\\partial \\vec{y}})|=p_x(\\vec{x})|\\mathrm{det}(\\vec{J}_{\\vec{y} \\rightarrow \\vec{x}})|\n\\end{equation}\n\n\n\\subsection{Central limit theorem}\nGiven $N$ random variables $X_1,X_2,\\cdots,X_N$, each variable is \\textbf{independent and identically distributed}\\footnote{\\url{http://en.wikipedia.org/wiki/Independent_identically_distributed}}(\\textbf{iid} for short), and each has the same mean $\\mu$ and variance $\\sigma^2$, then\n\\begin{equation}\n\\dfrac{\\sum\\limits_{i=1}^n X_i-N\\mu}{\\sqrt{N}\\sigma} \\sim \\mathcal{N}(0,1)\n\\end{equation}\nthis can also be written as\n\\begin{equation}\n\\dfrac{\\bar{X}-\\mu}{\\sigma/\\sqrt{N}} \\sim \\mathcal{N}(0,1) \\quad \\text{, where } \\bar{X} \\triangleq \\dfrac{1}{N}\\sum\\limits_{i=1}^n X_i\n\\end{equation}\n\n\n\\section{Monte Carlo approximation}\n\\label{sec:Monte-Carlo-approximation}\nIn general, computing the distribution of a function of an rv using the change of variables formula can be difficult. One simple but powerful alternative is as follows. First we generate $S$ samples from the distribution, call them $x_1,\\cdots,x_S$. (There are many ways to generate such samples; one popular method, for high dimensional distributions, is called Markov chain Monte Carlo or MCMC; this will be explained in Chapter TODO.) Given the samples, we can approximate the distribution of $f(X)$ by using the empirical distribution of $\\left\\{f(x_s)\\right\\}_{s=1}^S$. This is called a \\textbf{Monte Carlo approximation}\\footnote{\\url{http://en.wikipedia.org/wiki/Monte_Carlo_method}}, named after a city in Europe known for its plush gambling casinos.\n\nWe can use Monte Carlo to approximate the expected value of any function of a random variable. We simply draw samples, and then compute the arithmetic mean of the function applied to the samples. This can be written as follows:\n\\begin{equation}\n\\mathbb{E}[g(X)]=\\int g(x)p(x)\\mathrm{d}x \\approx \\dfrac{1}{S}\\sum\\limits_{s=1}^S f(x_s)\n\\end{equation}\nwhere $x_s \\sim p(X)$.\n\nThis is called \\textbf{Monte Carlo integration}\\footnote{\\url{http://en.wikipedia.org/wiki/Monte_Carlo_integration}}, and has the advantage over numerical integration (which is based on evaluating the function at a fixed grid of points) that the function is only evaluated in places where there is non-negligible probability.\n\n\n\\section{Information theory}\n\n\\subsection{Entropy}\n\\label{sec:Entropy}\nThe entropy of a random variable $X$ with distribution $p$, denoted by $\\mathbb{H}(X)$ or sometimes $\\mathbb{H}(p)$, is a measure of its uncertainty. In particular, for a discrete variable with $K$ states, it is defined by\n\\begin{equation}\n\\mathbb{H}(X) \\triangleq -\\sum\\limits_{k=1}^{K}{p(X=k)\\log_2p(X=k)}\n\\end{equation}\n\nUsually we use log base 2, in which case the units are called \\textbf{bits}(short for binary digits). If we use log base $e$ , the units are called \\textbf{nats}. \n\nThe discrete distribution with maximum entropy is the uniform distribution (see Section XXX for a proof). Hence for a K-ary random variable, the entropy is maximized if $p(x = k)=1/K$; in this case, $\\mathbb{H}(X)=\\log_2K$. \n\nConversely, the distribution with minimum entropy (which is zero) is any \\textbf{delta-function} that puts all its mass on one state. Such a distribution has no uncertainty.\n\n\n\\subsection{KL divergence}\nOne way to measure the dissimilarity of two probability distributions, $p$ and $q$ , is known as the \\textbf{Kullback-Leibler divergence}(\\textbf{KL divergence})or \\textbf{relative entropy}. This is defined as follows:\n\\begin{equation}\n\\mathbb{KL}(P||Q) \\triangleq \n\\sum\\limits_{x}{p(x)\\log_2\\dfrac{p(x)}{q(x)}}\n\\end{equation}\nwhere the sum gets replaced by an integral for pdfs\\footnote{The KL divergence is not a distance, since it is asymmetric. One symmetric version of the KL divergence is the \\textbf{Jensen-Shannon divergence}, defined as $JS(p_1,p_2)=0.5\\mathbb{KL}(p_1||q)+0.5\\mathbb{KL}(p_2||q)$,where $q=0.5p_1+0.5p_2$}. The KL divergence is only defined if P and Q both sum to 1 and if $q(x)=0$ implies $p(x)=0$ for all $x$(absolute continuity). If the quantity  $0\\ln0$ appears in the formula, it is interpreted as zero because $\\lim\\limits_{x \\to 0}x\\ln x$. We can rewrite this as\n\\begin{equation}\\begin{split}\n\\mathbb{KL}(p||q) & \\triangleq \\sum\\limits_{x}{p(x)\\log_2p(x)}-\\sum\\limits_{k=1}^{K}{p(x)\\log_2q(x)} \\\\\n    & =\\mathbb{H}(p)-\\mathbb{H}(p,q)\n\\end{split}\\end{equation}\nwhere $\\mathbb{H}(p,q)$ is called the \\textbf{cross entropy},\n\\begin{equation}\\label{eqn:cross-entropy}\n\\mathbb{H}(p,q)=\\sum\\limits_{x}{p(x)\\log_2q(x)}\n\\end{equation}\n\nOne can show (Cover and Thomas 2006) that the cross entropy is the average number of bits needed to encode data coming from a source with distribution $p$ when we use model $q$ to define our codebook. Hence the \u201cregular\u201d entropy $\\mathbb{H}(p)=\\mathbb{H}(p,p)$, defined in section \\S \\ref{sec:Entropy},is the expected number of bits if we use the true model, so the KL divergence is the diference between these. In other words, the KL divergence is the average number of \\emph{extra} bits needed to encode the data, due to the fact that we used distribution $q$ to encode the data instead of the true distribution $p$.\n\nThe \u201cextra number of bits\u201d interpretation should make it clear that $\\mathbb{KL}(p||q) \\geq 0$, and that the KL is only equal to zero if $q = p$. We now give a proof of this important result.\n\n\\begin{theorem}\n(\\textbf{Information inequality}) $\\mathbb{KL}(p||q) \\geq 0 \\text{ with equality iff } p=q$.\n\\end{theorem}\n\nOne important consequence of this result is that \\emph{the discrete distribution with the maximum\nentropy is the uniform distribution}.\n\n\n\\subsection{Mutual information}\n\\label{sec:Mutual-information}\n\\begin{definition}\n\\textbf{Mutual information} or \\textbf{MI}, is defined as follows:\n\\begin{equation}\\begin{split}\n\\mathbb{I}(X;Y) & \\triangleq \\mathbb{KL}(P(X,Y)||P(X)P(X)) \\\\\n    & =\\sum\\limits_x\\sum\\limits_yp(x,y)\\log\\dfrac{p(x,y)}{p(x)p(y)}\n\\end{split}\\end{equation}\nWe have $\\mathbb{I}(X;Y) \\geq 0$ with equality if $P(X,Y)=P(X)P(Y)$. That is, the MI is zero if the variables are independent.\n\\end{definition}\n\nTo gain insight into the meaning of MI, it helps to re-express it in terms of joint and conditional entropies. One can show that the above expression is equivalent to the following:\n\\begin{eqnarray}\n\\mathbb{I}(X;Y)&=&\\mathbb{H}(X)-\\mathbb{H}(X|Y)\\\\\n               &=&\\mathbb{H}(Y)-\\mathbb{H}(Y|X)\\\\\n               &=&\\mathbb{H}(X)+\\mathbb{H}(Y)-\\mathbb{H}(X,Y)\\\\\n               &=&\\mathbb{H}(X,Y)-\\mathbb{H}(X|Y)-\\mathbb{H}(Y|X)\n\\end{eqnarray}\nwhere $\\mathbb{H}(X)$ and $\\mathbb{H}(Y)$ are the \\textbf{marginal entropies}, $\\mathbb{H}(X|Y)$ and $\\mathbb{H}(Y|X)$ are the \\textbf{conditional entropies}, and $\\mathbb{H}(X,Y)$ is the \\textbf{joint entropy} of $X$ and $Y$, see Fig. \\ref{fig:mi}\\footnote{\\url{http://en.wikipedia.org/wiki/Mutual_information}}.\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.25]{mutual-information.png}\n\\caption{Individual $\\mathbb{H}(X),\\mathbb{H}(Y)$, joint $\\mathbb{H}(X,Y)$, and conditional entropies for a pair of correlated subsystems $X,Y$ with mutual information $\\mathbb{I}(X;Y)$.}\n\\label{fig:mi} \n\\end{figure}\n\nIntuitively, we can interpret the MI between $X$ and $Y$ as the reduction in uncertainty about $X$ after observing $Y$, or, by symmetry, the reduction in uncertainty about $Y$ after observing $X$.\n\nA quantity which is closely related to MI is the \\textbf{pointwise mutual information} or \\textbf{PMI}. For two events (not random variables) $x$ and $y$, this is defined as\n\\begin{equation}\nPMI(x,y) \\triangleq \\log\\dfrac{p(x,y)}{p(x)p(y)}=\\log\\dfrac{p(x|y)}{p(x)}=\\log\\dfrac{p(y|x)}{p(y)}\n\\end{equation}\n\nThis measures the discrepancy between these events occuring together compared to what would be expected by chance. Clearly the MI of $X$ and $Y$ is just the expected value of the PMI. Interestingly, we can rewrite the PMI as follows:\n\\begin{equation}\nPMI(x,y)=\\log\\dfrac{p(x|y)}{p(x)}=\\log\\dfrac{p(y|x)}{p(y)}\n\\end{equation}\n\nThis is the amount we learn from updating the prior $p(x)$ into the posterior $p(x|y)$ , or equivalently, updating the prior $p(y)$ into the posterior $p(y |x)$ .", "meta": {"hexsha": "636b16a4eecaed3acb87ea2d4a9bf475ad96e9f3", "size": 42709, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterProbability.tex", "max_stars_repo_name": "Alexoner/Statistical-formula", "max_stars_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-15T17:00:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-24T13:46:00.000Z", "max_issues_repo_path": "mlapp/chapterProbability.tex", "max_issues_repo_name": "Alexoner/Statistical-formula", "max_issues_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mlapp/chapterProbability.tex", "max_forks_repo_name": "Alexoner/Statistical-formula", "max_forks_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-02-25T15:40:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T04:26:03.000Z", "avg_line_length": 58.2660300136, "max_line_length": 945, "alphanum_fraction": 0.7094055117, "num_tokens": 13911, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995703, "lm_q2_score": 0.877476785879798, "lm_q1q2_score": 0.8059450845892923}}
{"text": "\n\\subsection{Estimating the Markov chain stochastic matrix}\n\n\\subsubsection{Introduction}\n\nGiven a sequence: \\(x_1,...x_n\\).\n\nThe likelihood is:\n\n\\(L=\\prod_{i=2}^n p_{x_{i-1},x_i}\\)\n\nIf there are \\(k\\) states we can rewrite this as:\n\n\\(L=prod_{i=1}^k\\prod_{j=1}^k n_{ij}p_{ij}\\)\n\nWhere \\(p_{ij}\\) is the chance of moving from state \\(i\\) to state \\(j\\), and \\(n_{ij}\\) is the number of transtions between \\(i\\) and \\(j\\).\n\nThe log likelhood is:\n\n\\(\\ln L=\\sum_{i=1}^k\\sum_{j=1}^kn_{ij}\\ln p_{ij}\\)\n\n\\subsubsection{Constrained optimisation}\n\nNot all parameters are free. All probabilities must sum to \\(1\\).\n\n\\(\\ln L=\\sum_{i=1}^k\\sum_{j=1}^kn_{ij}\\ln p_{ij}-sum_{i=1}\\lambda_i (\\sum_{j=1}p_{ij}-1)\\)\n\nThis gives us:\n\n\\(\\hat p_{ij}=\\dfrac{n_{ij}}{\\sum_k n_{ik}}\\)\n\n", "meta": {"hexsha": "116570e6149f82b7a1273b3f8d31e4b0865d99a6", "size": 762, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/markov/01-01-MC_finite.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/markov/01-01-MC_finite.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/markov/01-01-MC_finite.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.8125, "max_line_length": 141, "alphanum_fraction": 0.6469816273, "num_tokens": 288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.959762057376384, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.8059447966125082}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS622: Theory of Formal Languages\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 1}\n\nLet $x, y, z$ be three words from $A^*$ such that $xy = yz$ and $x \\neq \\lambda$.\nProve that there exist $u, v \\in A^*$ such that $x = uv$, $y = (uv)^n u$ and $z = vu$ for some $n \\in \\mathbb{N}$.\n\n\\subsection*{Solution}\n\nStatement is verified using proof of induction on the length of $|xy|$.\nSince $x \\neq \\lambda$, $u$ and $v$ cannot be $\\lambda$ at the same time, following that the length of $|xy|$ is never 0 and is always a multiple of 2.\n\n\\begin{itemize}\n\n\\item\nInitial Step: $|xy| = 2$\\\\\nSuppose $u = \\lambda$ and $v \\in A$. No restrictions are imposed on $n \\in \\mathbb{N}$.\n\n\\begin{equation}\\label{1eq1}\nxy = uv(uv)^nu = vv^n = v^{n+1}\n\\end{equation}\n\n\\begin{equation}\\label{1eq2}\nyz = (uv)^nuvu = v^nv = v^{n+1}\n\\end{equation}\n\nFrom \\eqref{1eq1} and \\eqref{1eq2}, it follows that $xy = yz$ and the statement holds true.\n\n\\item\nAssumption Step: $|xy| = m$\\\\\nIt is assumed that $xy = yz$ for some $u,v \\in A^*$ and some $n \\in \\mathbb{N}$.\nThat is there are some $u, v$ and $n$ that\n\n\\begin{equation}\\label{1eq3}\nxy = uv(uv)^nu = (uv)^nuvu = yz\n\\end{equation}\n\n\\item\nInduction Step $|xy| = m + 2$\\\\\nSuppose $u$ and $v$ are same words from $A^*$ that were used in assumption step.\nBy assuming $n^\\prime = n + 1$ where $n$ was the same $n$ that was used in assumption step, we will have:\n\n\\begin{equation}\\label{1eq4}\nxy = uv(uv)^{n^\\prime}u = uv(uv)^{n+1}u = uv(uv)^nuvu = (xy)^\\prime vu\n\\end{equation}\n\n\\begin{equation}\\label{1eq5}\nyz = (uv)^{n^\\prime}uvu = (uv)^{n+1}uvu = (uv)^nuvuvu = (yz)^\\prime vu\n\\end{equation}\n\nwhere $(xy)^\\prime$ and $(yz)^\\prime$ are those in assumption step.\nFrom \\eqref{1eq3} we know $(xy)^\\prime = (yz)^\\prime$. Therefore, \\eqref{1eq4} = \\eqref{1eq5} and the induction is complete.\n\n\\end{itemize}\n", "meta": {"hexsha": "bba3e5d839502632fdaaa0c71f4574142d3e5849", "size": 2119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q01.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q01.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 35.3166666667, "max_line_length": 151, "alphanum_fraction": 0.6149126947, "num_tokens": 753, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.8059237816612318}}
{"text": "\n    \\documentclass{article}\n    \\usepackage[utf8]{inputenc}\n    \\usepackage{amsmath}\n    \\begin{document}\n %Title \n \\section{Collatz Sequence for \\(n=15\\) }\n    %Collatz Function\n    \\[\n        f(n)=\n        \\begin{cases}\n        \\frac{n}{2}, & n \\mod 2=0\n        \\\\\n        3n+1, &n \\mod 2=1\n        \\end{cases} \\\\\n    \\]\n    % Path for given N\n    \\(\\textbf{Path for f(15)}\\\\[3mm]f(n), n=15\n \\\\ \n \\Rightarrow 3(15) + 1\n \\\\ \n \\Rightarrow n=46\n \\\\[3mm] \nf(n), n=46\n \\\\ \n \\Rightarrow \\frac{46}{2} \n \\\\ \n \\Rightarrow n=23\n \\\\[3mm] \nf(n), n=23\n \\\\ \n \\Rightarrow 3(23) + 1\n \\\\ \n \\Rightarrow n=70\n \\\\[3mm] \nf(n), n=70\n \\\\ \n \\Rightarrow \\frac{70}{2} \n \\\\ \n \\Rightarrow n=35\n \\\\[3mm] \nf(n), n=35\n \\\\ \n \\Rightarrow 3(35) + 1\n \\\\ \n \\Rightarrow n=106\n \\\\[3mm] \nf(n), n=106\n \\\\ \n \\Rightarrow \\frac{106}{2} \n \\\\ \n \\Rightarrow n=53\n \\\\[3mm] \nf(n), n=53\n \\\\ \n \\Rightarrow 3(53) + 1\n \\\\ \n \\Rightarrow n=160\n \\\\[3mm] \nf(n), n=160\n \\\\ \n \\Rightarrow \\frac{160}{2} \n \\\\ \n \\Rightarrow n=80\n \\\\[3mm] \nf(n), n=80\n \\\\ \n \\Rightarrow \\frac{80}{2} \n \\\\ \n \\Rightarrow n=40\n \\\\[3mm] \nf(n), n=40\n \\\\ \n \\Rightarrow \\frac{40}{2} \n \\\\ \n \\Rightarrow n=20\n \\\\[3mm] \nf(n), n=20\n \\\\ \n \\Rightarrow \\frac{20}{2} \n \\\\ \n \\Rightarrow n=10\n \\\\[3mm] \nf(n), n=10\n \\\\ \n \\Rightarrow \\frac{10}{2} \n \\\\ \n \\Rightarrow n=5\n \\\\[3mm] \nf(n), n=5\n \\\\ \n \\Rightarrow 3(5) + 1\n \\\\ \n \\Rightarrow n=16\n \\\\[3mm] \nf(n), n=16\n \\\\ \n \\Rightarrow \\frac{16}{2} \n \\\\ \n \\Rightarrow n=8\n \\\\[3mm] \nf(n), n=8\n \\\\ \n \\Rightarrow \\frac{8}{2} \n \\\\ \n \\Rightarrow n=4\n \\\\[3mm] \nf(n), n=4\n \\\\ \n \\Rightarrow \\frac{4}{2} \n \\\\ \n \\Rightarrow n=2\n \\\\[3mm] \nf(n), n=2\n \\\\ \n \\Rightarrow \\frac{2}{2} \n \\\\ \n \\Rightarrow n=1\n \\\\[3mm] \n\n    \\section{Credits}\n    %Maybe add link to gitrepo and other shit, idk\n    This is created using Collatzer (https://github.com/Z1aaan/Collatzer).\n    Created By: Z1aaan\n    \n    README:\n    A program created to visualize and simulate a user-given value for \\textit{N} \n    and see what happens when it is put under the Collatz function.\n    \\end{document}", "meta": {"hexsha": "063930e1b6a10030d83e231d90121157e4e82f3b", "size": 2006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "other_samples/sample(15).tex", "max_stars_repo_name": "Z1aaan/Collatz-Conjecture", "max_stars_repo_head_hexsha": "d355df30b69ca04d936f07d0cbb9aec9c4796223", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:06:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:06:27.000Z", "max_issues_repo_path": "other_samples/sample(15).tex", "max_issues_repo_name": "Z1aaan/Collatzer", "max_issues_repo_head_hexsha": "d355df30b69ca04d936f07d0cbb9aec9c4796223", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "other_samples/sample(15).tex", "max_forks_repo_name": "Z1aaan/Collatzer", "max_forks_repo_head_hexsha": "d355df30b69ca04d936f07d0cbb9aec9c4796223", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.5503875969, "max_line_length": 82, "alphanum_fraction": 0.5324027916, "num_tokens": 801, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068042, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.8059178578585126}}
{"text": "\n\\subsection{Set-builder notation}\n\n\\subsubsection{Notation}\n\nWe can use short-hand to describe sets.\n\n\\(\\{x\\in S: P(x)\\}\\)\n\nThis defines a set by a restriction. For example we will later be able to define natural numbers above \\(5\\) as:\n\n\\(\\{x\\in \\mathbb{N} : x>5\\}\\)\n\n\\subsubsection{Class builder notation}\n\nEmuneration can be done through set builder notation too\n\nCan define sets formally! defintion doesn't just affect sets\n\n\\(\\forall x (x\\in C \\leftrightarrow P(x))\\)\n\nNB: We're not saying C exists\n\nCan then use examples of equiv class\n\n\\(\\forall x (x\\in C \\leftrightarrow x=x)\\)\n\n", "meta": {"hexsha": "4e98bc52b4e4c0ad57e1b1502ffe76d36dbd2ae5", "size": 588, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/setsSpecification/01-03-setBuilder.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/setsSpecification/01-03-setBuilder.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/setsSpecification/01-03-setBuilder.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.0, "max_line_length": 112, "alphanum_fraction": 0.7159863946, "num_tokens": 163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.8059163258956066}}
{"text": "\\section{Some Properties of Determinant}\r\n\\begin{lemma}\r\n    Let $A,B$ be sqaure matrices, then $\\det(AB)=\\det(A)\\det(B)$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Direct expansion does the trick, but alternatively we can define $d_A$ via $d_A(B)=\\det(AB)$ which is obviously a volume form.\r\n    Therefore $d_A(B)=d_A(I)\\det(B)=\\det(A)\\det(B)$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $A\\in M_n(F)$.\r\n    We say $A$ is singular if $\\det A=0$, otherwise we say $A$ is nonsingular.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    If $A$ is invertible then it is non-singular.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suppose $B$ is an inverse of $A$, then $\\det(A)\\det(B)=\\det(AB)=\\det(I)=1\\neq 0$ therefore $\\det A\\neq 0$.\r\n\\end{proof}\r\n\\begin{remark}\r\n    In particular $\\det(A^{-1})=(\\det A)^{-1}$ if $A$ is invertible.\r\n\\end{remark}\r\n\\begin{theorem}\r\n    Let $A\\in M_n(F)$, the followings are equivalent:\\\\\r\n    1. $A$ is invertible.\\\\\r\n    2. $A$ is non-singular.\\\\\r\n    3. $r(A)=n$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We just need to show (ii) implies (iii) since we have already done all others.\r\n    Suppose $r(A)<n$, then $\\dim\\operatorname{span}(A^{(1)},\\ldots, A^{(n)})<n$, so there is some $\\lambda_1,\\ldots,\\lambda_n$ not all zero such that $\\sum_i\\lambda_iA^{(i)}=0$.\r\n    In particular, there is some $j$ such that $\\lambda_j\\neq 0$ and hence $c_j=-\\sum_{i\\neq j}(\\lambda_i/\\lambda_j)A^{(i)}$.\r\n    Expand $\\det A$ using multilinearity gives a linear combination of determinants with repeated entries, which is zero as $\\det$ is an alternating form.\r\n\\end{proof}\r\n\\begin{remark}\r\n    By the theorem, it follows easily that the equation $Ax=y$ where $A\\in M_n(F),x,y\\in F^n$ has a unique solution iff $\\det A\\neq 0$.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    Similar matrices have the same determinant.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    $\\det(PAP^{-1})=\\det(P)\\det(A)\\det(P)^{-1}=\\det(A)$ for any invertible $P$.\r\n\\end{proof}\r\nTherefore the following definition makes sense.\r\n\\begin{definition}\r\n    If $\\alpha:V\\to V$ be an endomorphism, then $\\det\\alpha=\\det[\\alpha_{B,B}]$ for any $B$ basis of $V$.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    $\\det:L(V,V)\\to F$ satisfies:\\\\\r\n    1. $\\det\\operatorname{id}_V=1$.\\\\\r\n    2. $\\det(\\alpha\\circ\\beta)=\\det(\\beta)\\det(\\alpha)$.\\\\\r\n    3. $\\det\\alpha\\neq 0$ iff $\\alpha$ is invertible.\r\n    If indeed $\\det\\alpha\\neq 0$, then $\\det(\\alpha^{-1})=(\\det\\alpha)^{-1}$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Choose any basis and the rest follows from previous discussions.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $A\\in M_k(F),B\\in M_l(F),C\\in M_{k,l}(F)$.\r\n    Consider\r\n    $$M_{k+l}(F)\\ni M=\\left( \\begin{array}{c|c}\r\n        A&C\\\\ \\hline\r\n        0&B\r\n    \\end{array} \\right)$$\r\n    Then $\\det M=(\\det A)(\\det B)$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Write $n=k+l$ and $M=(m_{ij})$.\r\n    Observe that $m_{\\sigma(i)i}=0$ if $i\\le k$ and $\\sigma(i)>k$.\r\n    So for $m_{\\sigma(1)1}\\cdots m_{\\sigma(n)n}\\neq 0$, we must have the decomposition $\\sigma_1\\circ\\sigma_2$ such that $\\sigma_1$ fixes anything but $1,\\ldots, k$ and $\\sigma_2$ fixes anything but $k+1,\\ldots,n$.\r\n    But then for such $\\sigma$, we have $m_{\\sigma(j)j}=a_{\\sigma_1(j)j}$ for any $j\\in\\{1,\\ldots,k\\}$ and $m_{\\sigma(j)j}=b_{\\sigma_2(s)s}$ where $s=j-k$ for any $j\\in\\{k+1,\\ldots,n\\}$.\r\n    Observe also that $\\epsilon(\\sigma)=\\epsilon(\\sigma_1)\\epsilon(\\sigma_2)$, therefore\r\n    \\begin{align*}\r\n        \\det M&=\\sum_{\\sigma\\in S_n}\\epsilon(\\sigma)m_{\\sigma(1)1}\\cdots m_{\\sigma(n)n}\\\\\r\n        &=\\sum_{\\sigma_1\\in S_k,\\sigma_2\\in S_l}\\epsilon(\\sigma_1)\\epsilon(\\sigma_2)a_{\\sigma_1(1)1}\\cdots a_{\\sigma_1(k)k}b_{\\sigma_2(1)1}\\cdots b_{\\sigma_2(l)l}\\\\\r\n        &=\\sum_{\\sigma_1\\in S_k}\\epsilon(\\sigma_1)a_{\\sigma_1(1)1}\\cdots a_{\\sigma_1(k)k}\\sum_{\\sigma_2\\in S_l}\\epsilon(\\sigma_2)b_{\\sigma_2(1)1}\\cdots b_{\\sigma_2(l)l}\\\\\r\n        &=(\\det A)(\\det B)\r\n    \\end{align*}\r\n    as desired.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $A_1,\\ldots,A_k$ are square matrices, then\r\n    $$\\det\\begin{pmatrix}\r\n        A_1&&&\\ast\\\\\r\n        &A_2&&\\\\\r\n        &&\\ddots&\\\\\r\n        0&&&A_k\r\n    \\end{pmatrix}=(\\det A_1)(\\det A_2)\\cdots (\\det A_k)$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Induction on $k$.\r\n\\end{proof}\r\nIn particular,\r\n$$\\det\\begin{pmatrix}\r\n    \\lambda_1&&&\\ast\\\\\r\n    &\\lambda_2&&\\\\\r\n    &&\\ddots&\\\\\r\n    0&&&\\lambda_k\r\n\\end{pmatrix}=\\lambda_1\\cdots\\lambda_k$$\r\n\\begin{remark}\r\n    Why is it called a volume from?\r\n    Cconsider the volume form $(\\mathbb R^3)^3\\to F$ via $(a,b,c)\\mapsto a\\cdot(b\\times c)$.\r\n    Then we know that geometrically this gives the (signed) volume of the parallelopiped formed by $a,b,c$.\r\n\\end{remark}", "meta": {"hexsha": "bece74b85c2d23151dd954167cc656e8232d32dc", "size": 4612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12/prop.tex", "max_stars_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_stars_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "12/prop.tex", "max_issues_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_issues_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "12/prop.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.7766990291, "max_line_length": 215, "alphanum_fraction": 0.6162185603, "num_tokens": 1689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.8962513745192024, "lm_q1q2_score": 0.8058387750831603}}
{"text": "\n\\subsection{Overfitting}\n\nOverfitting is a risk. Instead we split to test, train. risk of using too many features. more features always improve training score, not necessarily test score.\n\nAs model gets more complex, both test and train do better. however at some point, test stops doing better, overfitting\n\nStructural risk minimisation can address this trade off. use test and training sets. train model on train, rate it on test\n\nStructural minimisation curve has accuracy of boths sets over complexity\n\nTo avoid overfitting:\n\n+ reduce number of features\n+ do a model selection\n+ use regularisation\n+ do cross validation \n\nCan choose other model parameters\n\nHow to evalute model?\n\n\\subsection{K-fold cross-validation}\n\nCan do k-fold cross validation. given algo A and dataset D, divide D into k equal sized subsets\n\nFor each subset, train the model on all other subsets and test on the other subset. average error between folds\n\n\n", "meta": {"hexsha": "4eb50fa7e971a8bd34d1d23e2e7589f9be8a3fd8", "size": 934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/testValidation/01-01-testSets.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/testValidation/01-01-testSets.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/testValidation/01-01-testSets.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.1333333333, "max_line_length": 161, "alphanum_fraction": 0.7922912206, "num_tokens": 203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.8962513786759491, "lm_q1q2_score": 0.8058387691298298}}
{"text": "\\newcommand{\\fab}{f_{{\\bf a},{\\bf b}}}\n\n\\lab{Algorithms}{Monte Carlo Integration}{Monte Carlo Integration}\n\\objective{Learn the benefits of using Monte Carlo methods when numerically\nintegrating in many dimensions.}\n\nMany numerical integration techniques rely on finding deterministic ways to\napproximate the integrand, and using these approximations in a Riemann\nsummation. However, these techniques do not generalize well when the integration\ntakes place in a high-dimensional space. This lab presents a way to numerically\napproximate the value\n\\[I = \\int_{\\Omega} f({\\bf x}) \\;d{\\bf x} \\]\nwhen $\\Omega$ is a high-dimensional space, and we assume the value of the\nintegral is finite.\n\n\\section*{Monte Carlo Integration}\nMonte Carlo methods are algorithms that use random numbers to approximate a\ndesired result. (The name refers to the famous Monte Carlo Casino.) Monte Carlo\nintegration uses random vectors taken uniformly from the domain to approximate\nan intergal.\n\nSuppose we wish to approximate the above integral. We note the average, or\nexpected, value of the function $f$ on the space $\\Omega$ is given by\n\\[f_{\\text{ave}} = \\frac{1}{V(\\Omega)}\\int_{\\Omega} f({\\bf x}) \\;d{\\bf x} \\]\nwhere $V$ denotes volume. However, the law of large numbers from probability\ntheory roughly states that\n\\[f_{\\text{ave}} = \\lim_{n \\to \\infty} \\frac{1}{n} \\sum_{k=1}^{n} f({\\bf x}_k) \\]\nwhen the ${\\bf x}_i$ are uniform random samples of $\\Omega$. We see that we can\napproximate the desired value as\n\\[I \\approx I_N = V(\\Omega)\\frac{1}{N}\\sum_{k=1}^{N} f({\\bf x}_k) \\]\nfor large $N$, and that this approximation gets better as $N$ increases.\nRemarkably, for the estimation of the error we have\n\\[\\abs{I - I_N} \\approx V(\\Omega)\\frac{1}{\\sqrt{N}} =\nO\\left(\\frac{1}{\\sqrt{N}}\\right) \\] \nThe decay of the estimation of the error depends only on $N$, and not on the\ndimension of the space $\\Omega$. This is the key reason why Monte Carlo\nintegration works well in high dimensions.\n\n\\section*{Example}\n\nIn order to demonstrate the benefits of Monte Carlo integration, we introduce a\nspecial class of functions. Let $\\Omega = [0,2 \\pi ]^d$ be the unit cube in\n$\\mathbb{R}^d$. For ${\\bf a} \\in \\mathbb{N}^d$, ${\\bf b} \\in \\Omega$, define\n\\[\\fab({\\bf x}) = \\sum_{i=1}^{d} \\sin(2\\pi a_i x_i + b_i) \\]\nThis class of functions has desirable properties for our example. First, the\nfunctions are defined on a space of arbitrary dimension. Also, it is easy\nto analytically calculate\n\\[\\int_{\\Omega} \\fab({\\bf x}) \\; d {\\bf x} = 0 \\]\nfor any ${\\bf a}, {\\bf b}, d$. However, the functions are also interestingly\nshaped, and are not trivially approximated. We finally note that $V(\\Omega) = 1$.\n\n\n\\begin{problem}\n\\label{prob:fab}\nDefine a function that accepts an $N \\times d$ dimensional array, makes a random\nchoice for ${\\bf a}$ and ${\\bf b}$, and returns $\\fab({\\bf x}_n)$ evaluated for\neach of the $N$ vectors. Restrict your choice of ${\\bf a}$ to the set\n$\\{1,2,\\ldots,9\\}^d$.\n\\end{problem}\n\n\\begin{problem}\n\\label{prob:grid}\nEstimate $\\int_{\\Omega} \\fab({\\bf x}) \\;d{\\bf x}$ using rectangular quadrature\n(or another method), for many values of ${\\bf a}, {\\bf b}, d, N$. How large can\nyou make $d$?  What problems do you face as $d$ increases? What happens to the\naverage error as $d$ and $N$ vary?\n\n\\nopagebreak[2]\n\n\\vspace{5mm}\n\\noindent\n{\\it Hint.} First, create an $N \\times d$ grid of points in the domain. Using\nthe result from {\\bf Problem 1}, evaluate the function at each point. Since\n$V(\\Omega) = 1$, our rectangular quadrature estimate is equivalent to finding\nthe mean of the resultant array. (To see this is true, examine the\none-dimensional case; the generalization is immediate.) Since the true value of\nthe integral is $0$, the error is simply the absolute value of this mean.\n\n\\nopagebreak[2]\n\n\\begin{verbatim}\nimport numpy as np\n\ndef grid(d=3, n=100):\n    \"\"\"\n    Return a (d**n) by (d) dimensional array, giving a \n    uniform, discrete grid of the space [0,1]**d, with \n    n points along each dimension.\n    \"\"\"\n\n    linspaces = [np.linspace(0,1,n, endpoint=False) \n                 for i in xrange(d)]\n    flatmesh = [x.flatten() for x in np.meshgrid(*linspaces)]\n    return np.column_stack(flatmesh)\n\nIn []: xx = grid()\n\nIn []: np.abs(np.mean(problem_two(xx)))\nOut[]: error\n\nIn []: np.mean([np.abs(np.mean(problem_one(xx)))\n                for i in xrange(100)])\nOut[]: average_error\n\\end{verbatim}\n\\end{problem}\n\n\\break\n\\begin{problem}\n\\label{prob:mc}\nEstimate $\\int_{\\Omega} \\fab({\\bf x}) \\;d{\\bf x}$ using Monte Carlo integration\nfor many values of ${\\bf a}, {\\bf b}, d, N$. How large can you make $d$? What\nhappens to the average error as $d$ and $N$ vary? Compare this method with the\nprevious.\n\n\\nopagebreak[2]\n\n\\vspace{5mm}\n\\noindent\n{\\it Hint.} First, choose $N$ random points from the domain. Using the result\nfrom {\\bf Problem 1}, evaluate the function at each point. Since $V(\\Omega) =\n1$, Monte Carlo integration is equivalent to finding the mean of the resultant\narray. Since the true value of the integral is $0$, the error is simply the\nabsolute value of this mean.\n\n\\nopagebreak[2]\n\n\\begin{verbatim}\nimport numpy as np\n\nIn []: xx = np.random.rand(1000000, 3)\n\nIn []: np.abs(np.mean(problem_one(xx)))\nOut[]: error\n\nIn []: np.mean([np.abs(np.mean(problem_one(xx)))\n                for i in xrange(100)])\nOut[]: average_error\n\\end{verbatim}\n\\end{problem}\n\n\\let\\fab\\undefined\n", "meta": {"hexsha": "6a9c607cc075bbedffc89ca0d7ab5e3336815ab5", "size": 5392, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/MonteCarloIntegration/MonteCarloIntegration.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/MonteCarloIntegration/MonteCarloIntegration.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/MonteCarloIntegration/MonteCarloIntegration.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9718309859, "max_line_length": 81, "alphanum_fraction": 0.7010385757, "num_tokens": 1580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.8962513648201266, "lm_q1q2_score": 0.8058387639398262}}
{"text": "\\lab{Applications}{SVD-based Image Compression}{SVD}\n\n\\objective{Explore the SVD as a method of image compression}\n\nThe singular value decomposition is very useful.  In this lab, we are going to explore how the SVD can be used to compress image data.  Recall that the SVD is a decomposition of an $m \\times n$ matrix $A$\nof rank $r$ into the product $A = U \\Sigma V^H$, where $U$ and $V$\nare unitary matrices having dimensions $m \\times m$ and $n \\times n$,\nrespectively, and $\\Sigma$ is an $m \\times n$ diagonal matrix\n\\begin{equation*}\n\\Sigma = \\mbox{diag}(\\sigma_1,\\sigma_2,\\ldots,\\sigma_r,0,\\ldots,0)\n\\end{equation*}\nwhere $\\sigma_1 \\geq \\sigma_2 \\geq \\ldots \\geq \\sigma_r > 0$ are the\nsingular values of $A$.  Upon closer inspection, we can write\n\\begin{equation*}\nU = \\begin{pmatrix}U_1 & U_2\\end{pmatrix}, \\quad \\Sigma =\n\\begin{pmatrix}\\Sigma_r & 0\\\\0 & 0\\end{pmatrix}, \\quad V =\n\\begin{pmatrix}V_1 & V_2\\end{pmatrix},\n\\end{equation*}\nwhere $U_1$ and $V_1$ have dimensions $m\\times r$ and $n\\times r$\nrespectively and $\\Sigma_r$ is the $r\\times r$ diagonal matrix of\n(nonzero) singular values.  Multiplying this out yields the reduced\nform of the SVD\n\\begin{equation*}\nA =\n\\begin{pmatrix}U_1 & U_2\\end{pmatrix}\n\\begin{pmatrix}\\Sigma_r & 0\\\\0 & 0\\end{pmatrix}\n\\begin{pmatrix}V^H_1 \\\\ V^H_2\\end{pmatrix} =\nU_1 \\Sigma_r V_1^H\n\\end{equation*}\n\n\\subsection*{Low rank data storage}\nIf the rank of a given matrix is significantly smaller than its\ndimensions, the reduced form of the SVD offers a way to store $A$ with less memory.\nWithout the SVD, an $m\\times n$ matrix requires storing $m*n$ values.\nBy decomposing the original matrix into the SVD reduced form, $U_1$, $\\Sigma_r$ and $V_1$ together require $(m*r)+r+(n*r)$ values.\n  Thus if $r$ is much smaller than both $m$ and $n$,\nwe can obtain considerable efficiency.  For example, suppose\n$m=100$, $n=200$ and $r=20$. \nThen the original matrix would require storing $20,000$ values whereas the reduces form of the SVD only requires storing $6020$ values.\n\n\\subsection*{Low rank approximation}\nThe reduced form of the SVD also provides a way to approximate a\nmatrix with another one of lower rank. This idea is used in many areas of applied\nmathematics including signal processing, statistics, semantic\nindexing (search engines), and control theory.  If we are given a matrix $A$ of rank $r$,\nwe can find an approximate matrix $\\widehat A$ of rank $s<r$ by taking\nthe SVD of $A$ and setting all of its singular values after\n$\\sigma_s$ to zero, that is,\n\\begin{equation*}\n\\Sigma_{\\widehat A} = \\sigma_1, \\sigma_2, \\ldots, \\sigma_s,\\sigma_{s+1}=0,\\ldots,\\sigma_r=0\n\\end{equation*}\nand then multiplying the matrix back together again.  The more singular values we keep, the closer our approximation is to $A$.\n  The number of singular values we decide to preserve depends on how close of an approximation we need and what our size requirements are for $U_1$, $\\Sigma_{\\widehat A}$, and $V_1$.\nTry plotting the the singular values.  We have plotted the singular values to the image below.  Matrix rank is on the x-axis and the eigenvalues are the y-axis.  Note that SVD orders the singluar values from greatest to least.  The greatest eigenvalues contribute most to the image while the smallest eigenvalues hardly contribute anything to the final approximation.  By looking at the graph we can have a rough idea of how many singular values we need to preserve to have a good approximation of $A$.  The matrix rank of the image below is $670$.  However, as the plot shows, we could easily approximate the image using only the first half of the singular values.\n\n\\begin{center}\n\\includegraphics[scale=.2]{hubble_red.png}\n\n\\includegraphics[scale=.4]{hubble_svals.pdf}\n\\end{center}\n\n\\begin{lstlisting}[style=python]\n: import scipy as sp\n: import numpy.linalg as nla\n: A = sp.array([[1,1,3,4],[5,4,3,7],[9,10,10,12],[13,14,15,16],[17,18,19,20]])\n: nla.matrix_rank(A)\n: U,s,Vt = nla.svd(A)\n: S = sp.diag(s)\n: Ahat = sp.dot(sp.dot(U[:,0:3], S[0:3,0:3]), Vt[0:3,:])\n: nla.matrix_rank(Ahat)\n: nla.norm(A)-nla.norm(Ahat)\n\\end{lstlisting}\n\n% We can compute the rank of a matrix by looking at the number of nonzero singular values in the SVD decompositon.  The following function will compute the rank of a matrix.  The \\li{sp.finfo(float).eps} gives us the smallest representable postitive number such that $1.0+\\mbox{eps} \\neq 1.0$  Anything smaller than the eps value is numerically zero to the computer.\n% \\begin{lstlisting}[style=python]\n% : def matrix_rank(X):\n% :.... S = nla.svd(X, compute_uv=False)\n% :.... tol = S.max()*sp.finfo(S.dtype).eps\n% :.... return sum(S>tol)\n% : matrix_rank(Ahat)\n% \\end{lstlisting}\n\nNote that $\\widehat A$ is ``close'' to the original matrix $A$, but\nthat its rank is 3 instead of 4.\n\n\\subsection*{Application to Imaging}\n\n\nEnter the following into IPython (note that any image you might have will work):\n\\begin{lstlisting}\n: import matplotlib.pyplot as plt\n: X = sp.misc.imread('fingerprint.png')[:,:,0].astype(float)\n: X.nbytes      #number of bytes needed to store X\n: sp.misc.imshow(X)\n\\end{lstlisting}\nComputing the SVD of your image is simple.  Remember to make the singluar values a diagonal matrix before multiplying.\n\\begin{lstlisting}\n: U,s,Vt = la.svd(X)\n: S = sp.diag(s)\n\\end{lstlisting}\nIn the next code block, $n$ repsents the desired rank of the output.\n\\begin{lstlisting}\n: n=50\n: u1, s1, vt1 = U[:,0:n], S[0:n,0:n], Vt[0:n,:]\n: Xhat = sp.dot(sp.dot(u1, s1), vt1)\n: (u1.nbytes+sp.diag(s1).nbytes+vt1.nbytes) - X.nbytes   #should be negative\n: sp.misc.imshow(Xhat)\n\\end{lstlisting}\n\n%write code that will caluculate final image column by column in rank 1 approximations.  It is actually smaller to transmit the matrix col by col than chunks of cols.  We only send 70% of the data if we send col by col than entire matices.  1017856bytes vs 1445888 bytes.\n\\begin{problem}\nA law enforcement agency has been needing to efficiently store over 50,000 fingerprints.  They have decided to use an SVD based compression algorithm.  Your job is to try several parameters for the SVD algorithm and recommend those parameters that retain the highest quality but compress the most.  There should be no smearing or blocking in reconstructed final image and fingerprint detail must be retained (otherwise the fingerprint is worthless).  As part of your recommendation, calculate how much memory would be needed on average to store each compressed fingerprint.  Expand your results to say how much space could be saved if the entire database of fingerprints were compressed using your algorithm.\n\\end{problem}\n% \\begin{problem}\n% Explore the clown picture for several different values of rank.\n% Conduct the experiments described above.  Note that the original\n% image takes 64,000 integers to store.  Compare this with the storage\n% needs for various lower-rank SVD approximations. What conclusions\n% can you draw? Expirement with other images we've used in this book.\n% \\end{problem}\n", "meta": {"hexsha": "498512c8207c7ebbc4453d7a6213b3a354bbd392", "size": 6962, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/SVD/SVD_C.tex", "max_stars_repo_name": "jasongrout/numerical_computing", "max_stars_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/SVD/SVD_C.tex", "max_issues_repo_name": "jasongrout/numerical_computing", "max_issues_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/SVD/SVD_C.tex", "max_forks_repo_name": "jasongrout/numerical_computing", "max_forks_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-21T23:06:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T23:06:27.000Z", "avg_line_length": 57.5371900826, "max_line_length": 708, "alphanum_fraction": 0.7418845159, "num_tokens": 1998, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.900529776774399, "lm_q1q2_score": 0.8057845505897494}}
{"text": "\n\\lstset{\n  mathescape = true,\n  basicstyle = \\ttfamily}\n\\newcommand{\\dollar}{\\mbox{\\textdollar}}\n\n\\subsection{Matrix -- matrix multiplication}\n\n\\begin{frame}[fragile]{Matrix -- matrix multiplication}\n\n$C = A^{m\\cdot r}\\cdot B^{r\\cdot n} $\n\n$$ c_{i j} = \\sum_{k=1}^r a_{i k}  x_{k j} $$\n\\begin{enumerate}[a)]\n  \\item dot version\n\\end{enumerate}\n\n\\scriptsize{\n\\begin{lstlisting}[belowskip=-1.4 \\baselineskip, language=Matlab, mathescape]\nfunction: C=matmat.ijk(A,B)\n  m=rows(A); r=cols(A); n=cols(B); C(1:m,1:n)=0\n  for i=1:m\n    for j=1:n $\\tikzmark{mark4}$\n      for k=1:r $\\tikzmark{mark1}$\n        C(i,j)=C(i,j)+A(i,k) $\\cdot$ B(k,j) $\\tikzmark{mark3}$\n      end $\\tikzmark{mark2}$\n    end $\\tikzmark{mark5}$\n  end\nend matmat.ijk\n\\end{lstlisting}\n}\n\\AddNote{mark1}{mark2}{mark3}{1.5cm}{inner loop $\\tikzmark{mark6}$}\n\\AddNote{mark4}{mark5}{mark6}{1.6cm}{middle loop}\n\\end{frame}\n\n\\subsection{Matrix multiplication: loop ordering and properties}\n\n\\begin{frame}[fragile]{Matrix multiplication: loop ordering and properties}\n\n$i j k \\rightarrow 3! = 6 \\text{ sposob\u00f3w} $ \\\\\n\n\\vspace{5px}\n\\begin{tabular}{ |p{1cm}||p{1.6cm}||p{3.4cm}||p{3.7cm}|  }\n \\hline\n\n loop order& Inner loop & Middle loop&Inner loop data access\\\\\n \\hline\n ijk   & dot   &vector x matrix&   A by row, B by column\\\\\n\\hline\n jik&   dot & matrix x vector  &A by row, B by column\\\\\n\\hline\n ikj &saxpy & row gaxpy&  B by row\\\\\n\\hline\n jki    &saxpy & column gaxpy&  A by column\\\\\n\\hline\n kij &   saxpy  & row outer product& B by row\\\\\n\\hline\n kji& saxpy  & column outer product & A by column\\\\\n \\hline\n\\end{tabular}\n\n\\begin{itemize}\n\\item Operations $\\rightarrow$ dot, saxpy,\n\\item modes of access.\n\\end{itemize}\n\nWyb\u00f3r zale\u017cy od architektury komputera.\n\\end{frame}\n", "meta": {"hexsha": "311426d0f50b72739bc7e7ff2acc1da067bf95cc", "size": 1732, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10_numeryczna_algebra_liniowa-wprowadzenie/10_4_7_matrix_multiplication.tex", "max_stars_repo_name": "Arkowski24/lectures", "max_stars_repo_head_hexsha": "6051f4779eb85fa07b41f434efc7210ab10689a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-07-30T20:04:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-04T07:17:48.000Z", "max_issues_repo_path": "10_numeryczna_algebra_liniowa-wprowadzenie/10_4_7_matrix_multiplication.tex", "max_issues_repo_name": "Arkowski24/lectures", "max_issues_repo_head_hexsha": "6051f4779eb85fa07b41f434efc7210ab10689a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2017-07-03T20:03:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-02T19:31:19.000Z", "max_forks_repo_path": "10_numeryczna_algebra_liniowa-wprowadzenie/10_4_7_matrix_multiplication.tex", "max_forks_repo_name": "Arkowski24/lectures", "max_forks_repo_head_hexsha": "6051f4779eb85fa07b41f434efc7210ab10689a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-11-13T17:10:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-14T09:41:13.000Z", "avg_line_length": 25.1014492754, "max_line_length": 77, "alphanum_fraction": 0.6599307159, "num_tokens": 658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.9005297821135385, "lm_q1q2_score": 0.8057845503140502}}
{"text": "\n\\subsection{Defining \\(e\\) as a binomial}\n\n\\subsubsection{Lemma}\n\n\\(f(n,i)=\\dfrac{n!}{n^i(n-i)!}\\)\n\n\\(f(n,i)=\\dfrac{(n-i)!\\prod_{j=n-i+1}^nj}{n^i(n-i)!}\\)\n\n\\(f(n,i)=\\dfrac{\\prod_{j=n-i+1}^nj}{n^i}\\)\n\n\\(f(n,i)=\\dfrac{\\prod_{j=1}^i(j+n-i)}{n^i}\\)\n\n\\(f(n,i)=\\prod_{j=1}^i\\dfrac{j+n-i}{n}\\)\n\n\\(f(n,i)=\\prod_{j=1}^i(\\dfrac{n}{n}+\\dfrac{j-i}{n})\\)\n\n\\(f(n,i)=\\prod_{j=1}^i(1+\\dfrac{j-i}{n})\\)\n\n\\(\\lim_{n\\rightarrow \\infty }f(n,i)=\\lim_{n\\rightarrow \\infty }\\prod_{j=1}^i(1+\\dfrac{j-i}{n})\\)\n\n\\(\\lim_{n\\rightarrow \\infty }f(n,i)=\\prod_{j=1}^i1\\)\n\n\\(\\lim_{n\\rightarrow \\infty }f(n,i)=1\\)\n\n\\subsubsection{Defining \\(e\\)}\n\nWe know that:\n\n\\((a+b)^n=\\sum^n_{i=0} a^i b^{n-i} \\dfrac{n!}{i!(n-i)!}\\)\n\nLet's set \\(b=1\\)\n\n\\((a+1)^n=\\sum^n_{i=0} a^i \\dfrac{n!}{i!(n-i)!}\\)\n\nLet's set \\(a=\\dfrac{1}{n}\\)\n\n\\((1+\\dfrac{1}{n})^{n}=\\sum^{n}_{i=0} \\dfrac{1}{n^i} \\dfrac{n!}{i!(n-i)!}\\)\n\n\\((1+\\dfrac{1}{n})^{n}=\\sum^{n}_{i=0} \\dfrac{1}{i!} \\dfrac{n!}{n^i(n-i)!}\\)\n\n\\(\\lim_{n\\rightarrow \\infty }(1+\\dfrac{1}{n})^{n}=\\lim_{n\\rightarrow \\infty }\\sum^{n}_{i=0} \\dfrac{1}{i!} \\dfrac{n!}{n^i(n-i)!}\\)\n\nFrom the lemma above:\n\n\\(\\lim_{n\\rightarrow \\infty }(1+\\dfrac{1}{n})^{n}=\\sum^{\\infty }_{i=0} \\dfrac{1}{i!}\\)\n\n\\(e=\\sum^{\\infty }_{i=0} \\dfrac{1}{i!}\\)\n\n\\subsubsection{Defining \\(e^x\\)}\n\n\\(e=\\lim_{n\\rightarrow \\infty }(1+\\dfrac{1}{n})^{n}\\)\n\n\\(e^x=\\lim_{n\\rightarrow \\infty }(1+\\dfrac{1}{n})^{nx}\\)\n\n\\(e^x=\\lim_{n\\rightarrow \\infty }\\sum^{nx}_{i=0} \\dfrac{1}{n^i} \\dfrac{(nx)!}{i!(nx-i)!}\\)\n\n\\(e^x=\\lim_{n\\rightarrow \\infty }\\sum^{nx}_{i=0} \\dfrac{x^i}{i!} \\dfrac{(nx)!}{(nx)^i(nx-i)!}\\)\n\nFrom the lemma:\n\n\\(e^x=\\sum^{\\infty }_{i=0} \\dfrac{x^i}{i!}\\)\n\n", "meta": {"hexsha": "ab18727fefa6818bf01e55b24eb9602ed3296d48", "size": 1624, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/e/01-01-binomial.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/e/01-01-binomial.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/e/01-01-binomial.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.375, "max_line_length": 129, "alphanum_fraction": 0.5240147783, "num_tokens": 815, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474233166328, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.805622292699194}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n    \\section{Parametric Surfaces}\n    We consider parametric surfaces, which are higher-dimensional analogues of parametric curves. A parametric surface is parameterized by a function \\(\\vec{r}:D\\to\\mathbb{R}^3\\), where \\(\\vec{r}(u,v)\\) is continuous and \\(D\\subseteq\\mathbb{R}^2\\) is a domain. As with curves, a given surface may be parameterized in many ways.\n\n    The graph of a function \\(z=f(x,y)\\) can be thought of as a parametric surface parameterized by \n    \\[\n    \\vec{r}(u,v)=u\\i+v\\j+f(u,v)\\k\n    \\]\n\n    Spheres are also common parametric surfaces. In spherical coordinates, we may parameterize the sphere in terms of \\(\\theta\\) and \\(\\phi\\) as\n    \\[\n    \\vec{r}(\\theta,\\phi)=a\\cos{\\theta}\\sin{\\phi}\\i+a\\sin{\\theta}\\cos{\\phi}\\j+a\\cos{\\phi}\\k\n    \\]\n    where \\(\\theta\\in[0,2\\pi]\\) and \\(\\phi\\in[0,\\pi]\\).\n\n    There is also an analogue to the helical curve, which resembles a spiral stairway, and is parameterized by\n    \\[\n    \\vec{r}(u,v)=u\\cos{v}\\i+u\\sin{v}\\j+v\\k\n    \\]\n    where \\(u\\in[0,1]\\) and \\(v\\in[0,2\\pi]\\).\n\n    We generally assume, when working with surfaces, that \\(\\vec{r}\\) and its derivatives are continuous.\n    \n    \\begin{definition}{Surface Closure}{}\n        A surface is \\emph{closed} if it bounds a closed subset of \\(\\mathbb{R}^3\\).\n    \\end{definition}\n\n    As with parametric curves, we wish to find equations for the normal vectors of surfaces, as well as their tangent planes. It is also necessary to find area elements of surfaces, enabling us to integrate over them.\n\n    We wish to find the normal vector to a parametric surface parameterized by \\(\\vec{r}\\) at some point \\(P=\\vec{r}(u_0,v_0)\\). We can construct a pair of parametric curves parameterized by \\(\\vec{r}(u,v_0)\\) and \\(\\vec{r}(u_0,v)\\), both of which pass through \\(P\\). The normal vector of the surface at \\(P\\) must then be perpendicular to both curves, or equivalently to their tangent vectors at \\(P\\). This yields the equation\n    \\[\n    \\vec{n}=\\vec{r}_u\\times\\vec{r}_v\n    \\]\n\n    This normal vector is not independent of parameterization, but it does always point in the direction perpendicular to the surface.\n\n    We also wish to find area elements of our surface by continually subdividing the surface along lines with constant \\(u\\) and constant \\(v\\). As we continually take smaller and smaller subdivisions, the area element approximates a parallelogram. The vectors spanning this parallelogram are \\(\\vec{r}_u\\,du\\) and \\(\\vec{r}_v\\,dv\\), so the area element is given by\n    \\[\n    dS=|\\vec{r}_u\\,du\\times\\vec{r}_v\\,dv|=|\\vec{r}_u\\times\\vec{r}_v|\\,du\\,dv=|\\vec{n}|\\,du\\,dv\n    \\]\n\n    Using this, we can integrate functions along surfaces. If we wish to compute the integral of some function \\(f\\) along some surface \\(\\mathcal{S}\\), we have\n    \\[\n    \\iint_\\mathcal{S}f(x,y,z)\\,dS=\\iint_Df(\\vec{r}(u,v))|\\vec{n}|\\,du\\,dv\n    \\]\n\n    One simple application of surface integrals is computing the areas of surfaces. The area of a surface \\(\\mathcal{S}\\) is given by\n    \\[\n    \\iint_\\mathcal{S}\\,dS\n    \\]\n\n    We can also compute the masses of surfaces with variable densities. The mass of a surface \\(\\mathcal{S}\\) with variable density \\(\\rho\\) is given by\n    \\[\n    \\iint_\\mathcal{S}\\rho\\,dS\n    \\]\n\n    It is also possible to compute the average value of functions along surfaces. The average value of \\(f\\) on \\(\\mathcal{S}\\) is given by\n    \\[\n    \\frac{\\iint_\\mathcal{S}f\\,dS}{\\iint_\\mathcal{S}\\,dS}\n    \\]\n    \n    \\begin{example}{}{}\n        Find the area of the part of the plane \\(2x-y+z=10\\) which lies above the disk \\((x-3)^2+y^2\\geq1\\).\n        \\tcblower\n        We begin by parameterizing the plane. The plane may be treated as a graph, and is parameterized by\n        \\[\n        \\vec{r}(x,y)=x\\i+y\\j+(10-2x+y)\\k\n        \\]\n\n        Which has \\(\\vec{r}_x=\\i-2\\k\\) and \\(\\vec{r}_y=\\j+\\k\\), so we compute\n        \\[\n        \\vec{n}=\\vec{r}_x\\times\\vec{r}_y=2\\i-\\j+\\k\n        \\]\n        and\n        \\[\n        |\\vec{n}|=\\sqrt{6}\n        \\]\n        so the area of the ellipse is\n        \\[\n        \\iint_D\\sqrt{6}\\,dx\\,dy\n        \\]\n        where \\(D\\) is the disk. Normally, we would have to compute a double integral, but because \\(|\\vec{n}|\\) is constant and \\(D\\) is simply a circle, we have\n        \\[\n        \\iint_D\\sqrt{6}\\,dx\\,dy=\\sqrt{6}\\pi\n        \\]\n    \\end{example}\n\n        The problem of finding the area of a graph may be solved more generally. Let \\(\\mathcal{S}\\) be the graph of a function \\(z=f(x,y)\\), where \\((x,y)\\in D\\). We wish to find the area of \\(\\mathcal{S}\\). Because \\(\\mathcal{S}\\) may be parameterized by\n        \\[\n        \\vec{r}(x,y)=x\\i+y\\j+f(x,y)\\k\n        \\]\n        which immediately yields \\(\\vec{r}_x=\\i+f_x\\k\\) and \\(\\vec{r}_y=\\j+f_y\\k\\), and consequently\n        \\[\n        \\vec{n}=-f_x\\i-f_y\\j+\\k\n        \\]\n        which yields\n        \\[\n        |\\vec{n}|=\\sqrt{f_x^2+f_y^2+1}\n        \\]\n\n        As such, the area of the graph \\(z=f(x,y)\\) is simply given by\n        \\[\n        \\iint_D\\sqrt{f_x^2+f_y^2+1}\\,dx\\,dy\n        \\]\n\n        \\begin{example}{}{}\n            Find the area of the part of \\(z=x^2+y^2\\) below \\(z=9\\).\n            \\tcblower\n            First, we compute\n            \\[\n            |\\vec{n}|=\\sqrt{z_x^2+z_y^2+1}\n            \\]\n            meaning that the area is\n            \\[\n            \\iint_D\\sqrt{4x^2+4y^2+1}\\,dx\\,dy=\\frac{\\pi}{6}(37\\sqrt{37}-1)\n            \\]\n            where the integral is computed by conversion to polar coordinates, and \\(D=\\{(x,y):x^2+y^2<9\\}\\).\n        \\end{example}\n\\end{document}\n", "meta": {"hexsha": "30f6171f3cc3614e05e91dcbd9eaff150873bbe8", "size": 5581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lec_15.tex", "max_stars_repo_name": "CrashAndSideburns/MATH227-Notes", "max_stars_repo_head_hexsha": "ec5356ff816c2f51828e4f8b64b5ae0a8b0c8cd3", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-25T04:16:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T04:16:23.000Z", "max_issues_repo_path": "src/lec_15.tex", "max_issues_repo_name": "CrashAndSideburns/MATH227-Notes", "max_issues_repo_head_hexsha": "ec5356ff816c2f51828e4f8b64b5ae0a8b0c8cd3", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lec_15.tex", "max_forks_repo_name": "CrashAndSideburns/MATH227-Notes", "max_forks_repo_head_hexsha": "ec5356ff816c2f51828e4f8b64b5ae0a8b0c8cd3", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.7459016393, "max_line_length": 428, "alphanum_fraction": 0.6049095144, "num_tokens": 1783, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.891811044719067, "lm_q1q2_score": 0.8055677548126514}}
{"text": "\n\\subsection{Inverse matrices}\n\nAn invertible matrix implies that if the matrix is multiplied by another matrix, the original matrix can be recovered.\n\nThat is, if we have matrix \\(A\\), there exists matrix \\(A^{-1}\\) such that \\(AA^{-1}=I\\).\n\nConsider a linear map on a vector space.\n\n\\(Ax=y\\)\n\nIf \\(A\\) is invertible we can have:\n\n\\(A^{-1}Ax=A^{-1}y\\)\n\n\\(x=A^{-1}y\\)\n\nIf we set \\(y=\\mathbf 0\\) then:\n\n\\(x=\\mathbf 0\\)\n\nSo if there is a non-zero vector \\(x\\) such that:\n\n\\(Ax=\\mathbf 0\\) then \\(A\\) is not invertible.\n\n\\subsection{Left and right inverses}\n\nThat is, for all matrices \\(A\\), the left and right inverses of \\(B\\), \\(B_L^{-1}\\) and \\(B_R^{-1}\\), are defined such that:\n\n\\(A(BB_R^{-1})=A\\)\n\n\\(A(B_L^{-1}B)=A\\)\n\nLeft and right inversions are equal\n\nNote that if the left inverse exists then:\n\n\\(B_L^{-1}B=I\\)\n\nAnd if the right inverse exists:\n\n\\(BB_R^{-1}=I\\)\n\nLet\u2019s take the first:\n\n\\(B_L^{-1}B=I\\)\n\n\\(B_L^{-1}BB_L^{-1}=B_L^{-1}\\)\n\n\\(B_L^{-1}BB_L^{-1}-B_L^{-1}=0\\)\n\n\\(B_L^{-1}(BB_L^{-1}-I)=0\\)\n\n\\subsection{Inversion of products}\n\n\\((AB)(AB)^{-1}=I\\)\n\n\\(A^{-1}AB(AB)^{-1}=A^{-1}\\)\n\n\\(B^{-1}B(AB)^{-1}=B^{-1}A^{-1}\\)\n\n\\((AB)^{-1}=B^{-1}A^{-1}\\)\n\n\\subsection{Inversion of a diagonal matrix}\n\n\\(DD^{-1}=I\\)\n\n\\(D_{ii}D_{ii}^{-1}=1\\)\n\n\\(D_{ii}^{-1}=\\dfrac{1}{D_{ii}}\\)\n\n", "meta": {"hexsha": "d1d70fc7b7f43811eed81bd2d65afac991e91fd6", "size": 1276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystems/03-01-linearInversion.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/linearSystems/03-01-linearInversion.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/linearSystems/03-01-linearInversion.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.7222222222, "max_line_length": 124, "alphanum_fraction": 0.5822884013, "num_tokens": 473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.8054655394047074}}
{"text": "\\subsection{Inverses of elementary matrices}\n\nSuppose we have applied a row operation to a matrix $A$. Consider the\nrow operation required to return $A$ to its original form, i.e., to\nundo the row operation. It turns out that this action is described by\nthe inverse of an elementary matrix. The following theorem ensures\nthat the inverse of each elementary matrix is itself an elementary\nmatrix.\n\n\\begin{theorem}{Inverses of elementary matrices}{inverse-elementary-matrix}\n  Every elementary matrix is invertible and its inverse is also an\n  elementary matrix%\n  \\index{elementary matrix!inverse}%\n  \\index{matrix!elementary matrix!inverse}.\n\\end{theorem}\n\nIn fact, the inverse of an elementary matrix is constructed by doing\nthe {\\em reverse} row operation on $I$. $E^{-1}$ is obtained by\nperforming the row operation which would carry $E$ back to $I$.\n\n\\begin{itemize}\n\\item If $E$ is obtained by switching rows $i$ and $j$, then $E^{-1}$\n  is also obtained by switching rows $i$ and $j$.\n\\item If $E$ is obtained by multiplying row $i$ by the scalar $k$,\n  then $E^{-1}$ is obtained by multiplying row $i$ by the scalar\n  $\\frac{1}{k}$.\n\\item If $E$ is obtained by adding $k$ times row $i$ to row $j$, then\n  $E^{-1}$ is obtained by subtracting $k$ times row $i$ from row $j$.\n\\end{itemize}\n\n\\begin{example}{Inverse of an elementary matrix}{inverse-elementary-matrix}\n  Find $E^{-1}$, where $E$ is the elementary matrix\n  \\begin{equation*}\n    E\n    =\n    \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 2\n    \\end{mymatrix}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  $E$ is obtained from the $2\\times 2$ identity matrix by multiplying\n  the second row by $2$. In order to carry $E$ back to the identity,\n  we need to multiply the second row of $E$ by $\\frac{1}{2}$.  Hence,\n  $E^{-1}$ is given by\n  \\begin{equation*}\n    E^{-1}\n    =\n    \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & \\frac{1}{2}\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n", "meta": {"hexsha": "af820dbc4e4b525c90b273535e08bf74dad15d6f", "size": 1961, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-ElementaryMatrices-Inverses.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-ElementaryMatrices-Inverses.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-ElementaryMatrices-Inverses.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 33.8103448276, "max_line_length": 75, "alphanum_fraction": 0.6874043855, "num_tokens": 587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.9196425317283918, "lm_q1q2_score": 0.8054109662539095}}
{"text": "\\subsection{Stokes' theorem}\n\nStokes' theorem says that in typical problems a surface integral can be\ncomputed using a line integral.\n(There is some fine print regarding continuity and boundary conditions.)\nThis is a useful theorem because usually the line integral is easier to\ncompute.\nIn rectangular coordinates the equivalence between a line integral\non the left and a surface integral on the right is\n%\n$$\\oint P\\,dx+Q\\,dy+R\\,dz\n=\\int\\!\\!\\!\\int_S(\\mathop{\\rm curl}{\\bf F})\\cdot{\\bf n}\\,d\\sigma\n$$\n%\nwhere ${\\bf F}=(P,Q,R)$.\nFor $S$ parametrized by $x$ and $y$ we have\n$${\\bf n}\\,d\\sigma=\\left(\n\\frac{\\partial S}{\\partial x}\\times\\frac{\\partial S}{\\partial y}\n\\right)dx\\,dy$$\n\n\\noindent\nExample:\nLet ${\\bf F}=(y,z,x)$ and let $S$ be the part of the paraboloid\n$z=4-x^2-y^2$\nthat is above the $xy$ plane.\nThe perimeter of the paraboloid is the circle $x^2+y^2=2$.\nThe following script computes both the line and surface integrals.\nIt turns out that we need to use polar coordinates for the\nline integral so that {\\it defint} can succeed.\n\n{\\color{blue}\n\\begin{verbatim}\n-- www.eigenmath.org/stokes-theorem.txt\n\"Surface integral\"\nz = 4 - x^2 - y^2\nF = (y,z,x)\nS = (x,y,z)\nf = dot(curl(F),cross(d(S,x),d(S,y)))\nx = r cos(theta)\ny = r sin(theta)\ndefint(f r,r,0,2,theta,0,2pi)\n\"Line integral\"\nx = 2 cos(t)\ny = 2 sin(t)\nz = 4 - x^2 - y^2\nP = y\nQ = z\nR = x\nf = P d(x,t) + Q d(y,t) + R d(z,t)\nf = circexp(f)\ndefint(f,t,0,2pi)\n\\end{verbatim}\n}\n\n\\noindent\nThis is the result when the script runs.\nBoth the surface integral and the line integral\nyield the same result.\n\n\\bigskip\n\\noindent\nSurface integral\\\\\n$\\displaystyle -4\\pi$\\\\\nLine integral\\\\\n$\\displaystyle -4\\pi$\n", "meta": {"hexsha": "d0d2819e773280c612999efc1f1d049413e005dc", "size": 1663, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/stokes-theorem.tex", "max_stars_repo_name": "franko/eigenmath", "max_stars_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-01-27T02:41:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-02T19:05:49.000Z", "max_issues_repo_path": "doc/stokes-theorem.tex", "max_issues_repo_name": "franko/eigenmath", "max_issues_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-01-29T14:09:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-13T16:17:03.000Z", "max_forks_repo_path": "doc/stokes-theorem.tex", "max_forks_repo_name": "franko/eigenmath", "max_forks_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-27T02:38:38.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-27T02:38:38.000Z", "avg_line_length": 25.196969697, "max_line_length": 72, "alphanum_fraction": 0.6885147324, "num_tokens": 555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706048, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.8054109495499645}}
{"text": "\n\\chapter[Boundary value problems]{Boundary value problems for Ordinary Differential Equations}\n\n\\section{Introduction}\n\nA boundary value problem consists in finding a solution of a\ndifferential equation in an interval $[a,b]$ that satisfies\nconstraints at both ends (boundary conditions).  A typical example of\na boundary value problem is\n%\n\\begin{equation}\n  y'' = f(x,y,y'), \\quad y(a) = A, \\quad y(b) = B, \\quad a \\le x \\le b.\n  \\label{eq:1}\n\\end{equation}\n%\nThe question of the existence of solutions of problems\nlike~(\\ref{eq:1}) is non trivial.  However, here we assume that we are\nalways trying to find a solution to a well posed problem, that is a\nproblem that has one and only one solution.\n\nBoundary value problems describe many important physical and\nengineering problems, from the sagging of a beam to the shape of the\nelectron orbitals in atoms.\n\n\\section{Shooting method}\n\nWe describe this method to solve boundary value problems using\nequation~(\\ref{eq:1}) as an example.  One natural way to attack this\nproblem is to solve the related initial-value problem, with a guess of\nthe appropriate initial value $y'(a)$. Then we can integrate the\nequation to obtain the approximate solution, hoping that $y(b)=B$. If\nnot, then the guessed value of $y'(a)$ can be altered and we can try\nagain. The process is called {\\bf shooting}, and there are ways of\ndoing it systematically.\n\n\\medskip\n\n\\noindent\nDenote the guessed value of $y'(a)$ by $z$, so that the corresponding\ninitial value problem is\n%\n\\begin{equation}\n  y''=f(x,y,y'), \\quad y(a)=A, \\quad y'(a)=z, \\quad a \\le x \\le b.\\label{ivp}\n\\end{equation}\n%\nThe solution of this problem is $y=y(x,z)$. The objective is to select\n$z$ so that $y(b,z)=B$. We call\n%\n\\begin{equation}\n  \\phi(z) \\equiv y(b,z)-B ,\n  \\label{eq:phiz}\n\\end{equation}\n%\nso that our objective is simply to solve for $z$ the equation\n%\n\\begin{equation}\n \\phi(z)=0 \\,.\n \\label{eq:2}\n\\end{equation}\n%\n\nIn general equation~(\\ref{eq:2}) is nonlinear.  We can use any\nnumerical root finding method to solve it.  One of the most effective\nis the secant method:\n%\n\\begin{equation*}\n  z_{n+1} = z_{n} - \\phi(z_n) \\frac{z_n - z_{n-1}}\n  {\\phi(z_n)-\\phi(z_{n-1})} ,\n  \\qquad n > 1.\n\\end{equation*}\n%\nThe advantage of this method is that we need only to know $\\phi(z)$ in\norder to apply it and that it is fairly accurate.  The disadvantage is\nthat we need two initial guesses $z_0$ and $z_1$ in order to start the\nmethod.\n\n\\medskip\n\nIn the case of Newton's method, the iteration formula for $z$ is\n%\n\\begin{equation}\n z_{n+1} = z_n-\\frac{\\phi(z_n)}{\\phi'(z_n)}.\n \\label{eq:3}\n\\end{equation}\n%\nTo determine $\\phi'(z)$, we can proceed in two ways.  Firstly, we\ncould evaluate the derivative numerically by writing\n%\n\\begin{equation*}\n  \\phi'(z_n) \\simeq \\frac{\\phi(z_n+h)-\\phi(z_n)}{h}, \\qquad h \\ll 1.\n\\end{equation*}\n%\nA second option is to introduce\n%\n\\begin{equation*}\n  u(x,z)=\\pdv{y}{z}\n\\end{equation*}\n%\nand we differentiate with respect to $z$ all the equations in\n(\\ref{ivp}). This becomes\n%\n\\begin{equation*}\n  u'' = f_y(x,y,y') u + f_{y'}(x,y,y') u', \\quad u(a)=0, \\quad u'(a)=1.\n\\end{equation*}\n%\nThe last differential equation is called the \\textit{first variational\n  equation}.  It can integrated numerically using for $y$ and $y'$ the\nvalues obtained by the numerical integration of equation~(\\ref{ivp}).\nFinally, by differentiating~(\\ref{eq:2}) we obtain\n%\n\\begin{equation*}\n  \\phi'(z)=u(b,z)\n\\end{equation*}\n%\nthat enables us to use the Newton's method to find a root of $\\phi$.\n\n\\bigskip\n\nTo summarise, the steps of the algorithm are as follows:\n%\n\\begin{enumerate}\n  %\n\\item Guess a value for the missing initial condition, $z_0$, and set\n  the iteration counter $n$ to zero, $n=0$.\n  %\n\\item Compute $y=y(x,z_n)$ by integrating the initial value problem\n  %\n  \\begin{equation*}\n    y''=f(x,y,y'), \\quad y(a)=A, \\quad y'(a)=z_n, \\quad a\\le x\\le b.\n  \\end{equation*}\n%\n\\item Compute $\\phi(z_n) = y(b,z_n) - B$.  Use a nonlinear solver\n  (e.g.\\ Newton's or the secant method) to find a new value $z_{n+1}$\n  for the missing initial condition.\n%\n\\item If $z_{n+1}$ is not sufficiently accurate increase the iteration\n  counter by one, $n \\to n + 1$ and repeat steps (2-4) until\n  $\\phi(z_{n+1})$ is sufficiently small.\n%\n\\end{enumerate}\n\n\\section{Finite-difference method}\n\nAnother approach to solving boundary value problems is to discretise\nthe derivatives that appear in the differential equation and transform\nthe problem in a linear system.  As an example, consider the equation\n%\n\\begin{equation}\n  y'' + p(x) y' + q(x) y = f(x), \\quad y(a)=A, \\quad y(b)=B,\n  \\quad a \\le x \\le b.\\label{lbvp}\n\\end{equation}\n%\nWe can represent the derivatives using their finite difference\napproximations:\n%\n\\begin{subequations}\n  \\label{er}\n  \\begin{align}\n    y'(x_i) &= \\frac{y_{i+1}-y_{i-1}}{2h} -\n    \\frac{h^2}{6} y'''(\\xi_1), \\\\\n    y''(x_i) &=  \\frac{y_{i+1}+y_{i-1}-2 y_i}{h^2} -\n    \\frac{h^2}{12}y^{(4)}(\\xi_2),\n  \\end{align}\n\\end{subequations}\n%\nwhere $x_i=a+i h$, $i=0,1,2,...,n+1$, $h=(b-a)/(n+1)$. Thus, the\ndiscrete version of~(\\ref{lbvp}) is the system of $n+2$ linear\nalgebraic equations\n%\n\\begin{align*}\n  y_0 &=A, \\\\\n  y_{i-1} \\left ( 1 - \\frac{h}{2} p_i \\right ) -\n  y_i \\left ( 2 - h^2 q_i \\right ) +\n  y_{i+1} \\left (1 + \\frac{h}{2} p_i \\right )  &= h^2 f_i , \\\\\n  y_{n+1} &=B,\n\\end{align*}\n%\nwhere $p_i=p(x_i)$, $q_i=q(x_i)$, $f_i=f(x_i)$.  This can be solved as\nsuch or reduced to an $n \\times n$ system.  For example, if $n=4$, the\ncorresponding matrix form is given by\n%\n\\begin{equation*}\n  \\begin{pmatrix}\n    -2 + h^2 q_1 & 1 + \\frac{h}{2} p_1 & 0 & 0 \\\\\n    1 - \\frac{h}{2} p_2 & -2  + h^2 q_2 & 1 + \\frac{h}{2} p_2 & 0\\\\\n    0 & 1 - \\frac{h}{2} p_3 & -2  + h^2 q_3 & 1 + \\frac{h}{2} p_3 \\\\\n    0 & 0 & 1 - \\frac{h}{2} p_4 & -2  + h^2 q_4\n  \\end{pmatrix}\n  \\begin{pmatrix} y_1\\\\ y_2\\\\ y_3\\\\ y_4 \\end{pmatrix} =\n  \\begin{pmatrix} F_1\\\\ F_2\\\\ F_3\\\\ F_4 \\end{pmatrix}\n\\end{equation*}\n%\nwith\n%\n\\begin{align*}\n  & &  F_1 & = h^2 f_1 - A (1 - \\frac{h}{2} p_1), &\n  F_2 & = h^2 f_2, \\\\\n  & &  F_3 & = h^2 f_3, & F_4 & = h^2 f_4 - B(1 + \\frac{h}{2} p_4).\n\\end{align*}\n%\nThis system is tridiagonal and can be solved by a special form of the\nGaussian elimination algorithm. In the general case, we have an\n$n\\times n$ system\n%\n\\begin{equation}\n  T \\boldsymbol{y} = \\boldsymbol{F},\n  \\label{eq:5}\n\\end{equation}\n%\nwhere $T$ is a tridiagonal $n\\times n$ matrix,\n$\\boldsymbol{y}=(y_1,...,y_n)^T$ and $\\boldsymbol{F}=(F_1,...,F_n)^T$.\n\nTo analyse the error induced by the representation~(\\ref{er}) of the\nderivatives we introduce an error vector $(e_1,...,e_n)$, where\n$e_i=y(x_i)-y_i$, $i=1,\\ldots,n$ and $y(x)$ is assumed to be the exact\nsolution.  Substituting into the finite difference\nrepresentation~(\\ref{eq:5}) of equation~(\\ref{lbvp}), we obtain the\nsystem\n%\n\\begin{equation*}\n  T \\be = h^4 \\boldsymbol{G}\n\\end{equation*}\n%\nwhere $\\boldsymbol{G}$ is a constant vector.   If $\\det T \\ne 0$, we have\n%\n\\begin{equation*}\n  \\boldsymbol{e}=h^4T^{-1}\\boldsymbol{G}.\n\\end{equation*}\n%\nWe can use this relation to show that the error is $O(h^2)$ [sic] as\n$h \\to 0$.\n\n\\section{The Ritz method}\n\nThe Ritz, Galerkin, Square Least methods are used widely on problems\nin which it is required to determine an unknown function. Of course,\nboundary value problems for differential equations are in this\ncategory. Suppose we are confronted with a problem of the form\n%\n\\begin{equation}\n  \\mathcal{L} u(x)=f(x)\n\\end{equation}\n%\nin which $\\mathcal{L}$ is the linear operator\n%\n\\begin{equation}\n  \\mathcal{L} u=-\\dv{}{x} \\left[ p(x) \\dv{u}{x} \\right ] + q(x)u = f(x).\n\\end{equation}\n%\nHere $f(x)$ is a given function and $u(x)$ is is the function to be\ndetermined from the equation and boundary conditions\n%\n\\begin{equation}\n  u(a)=0, \\qquad u(b)=0.\n\\end{equation}\n%\nWe assume that $p(x)\\ge p_0>0$, $q(x)\\ge 0$ for $x\\in [a,b]$. This\nmeans that the operator $\\mathcal{L}$ is symmetric and positive\ndefinite in the real Hilbert space $L_2[a,b]$ since, using the\nintegration by parts, we have\n%\n\\begin{align*}\n  <\\mathcal{L}u,u> & = \\mint{a}{b}{\\mathcal{L} u \\cdot u}{x} \\\\\n  & = -\\mint{a}{b}{(p u')'u}{x} + \\mint{a}{b}{q u^2}{x} \\\\\n  & = \\mint{a}{b}{p(u')^2}{x} + \\mint{a}{b}{q u^2}{x} \\ge 0\n\\end{align*}\n%\nfor arbitrary $u$. The quantity $<\\mathcal{L}u,u>$ is called the\nenergy of the element $u$ relative the operator $\\mathcal{L}$.\n\n\\noindent Consider a linear quadratic functional\n%\n\\begin{subequations}\n  \\label{fun}\n  \\begin{align}\n    J(u) & = <\\mathcal{L}u,u>-2<f,u> \\\\\n         & = \\mint{a}{b}{p(u')^2}{x} + \\mint{a}{b}{q u^2}{x} -2 \\mint{a}{b}{f\n         u}{x}.\n  \\end{align}\n\\end{subequations}\n%\nA theorem states that if the equation $\\mathcal{L}u(x)=f(x)$ has a\nsolution $u_0$, this solution minimises the functional\n$J(u)$. Conversely, if there exists an element $u_0$ that minimises\nthe functional $J(u)$, this element satisfies the equation\n$\\mathcal{L}u(x)=f(x)$.  The proof is based on the ability to reduce\nthe functional $J(u)$ to the form\n%\n\\begin{equation*}\n  J(u)=<\\mathcal{L}(u-u_0),u-u_0>-<\\mathcal{L}u_0,u_0>,\n\\end{equation*}\n%\nand then analysing the function\n%\n\\begin{align*}\n g(t) & = J[u_0(x)+t v(x)] \\\\\n      & = <\\mathcal{L}u_0,u_0> + 2t<\\mathcal{L}u_0,v> +\n      t^2<\\mathcal{L} v,v> - 2<f,u_0> - 2t<f,v>.\n\\end{align*}\n%\nThe basic idea of the Ritz method consists in replacing the boundary\nvalue problem for $\\mathcal{L}u(x)=f(x)$ by the problem of minimising\nthe functional $J(u)$. Suppose we select basis functions $u_1$,\n$u_2$,...,$u_n$,... in $L_2[a,b]$.  Hence, we seek a solution of the\nform\n%\n\\begin{equation}\n  u_n(x)=\\sum_{m=1}^n c_m u_m(x),\\label{rsol}\n\\end{equation}\n%\nwhere $c_1$, $c_2$,...,$c_n$ are unknown constants.  Substituting this\nsum into the functional $J(u)=<\\mathcal{L}u,u>-2<f,u>$, we obtain\n%\n\\begin{equation}\n  J(u_n)=J(c_1,c_2,...,c_n)=\\sum_{m,k=1}^n c_m c_k<\\mathcal{L}u_m,u_k>-\n  2\\sum_{m=1}^n c_m<f,u_m>,\n\\end{equation}\n%\nwhich is a quadratic form with respect to the unknown constants\n$c_1,c_2,...,c_n$.  Looking for a minimum element of\n$J(u_n)=J(c_1,c_2,...,c_n)$, we require that\n%\n\\begin{equation}\n  \\pdv{}{c_m} J(c_1,c_2,...,c_n)=0, \\qquad m=1,2,...,n.\n\\end{equation}\n%\nThus, we come to the linear $n\\times n$ system of algebraic equations\nfor the unknown constants $c_1$, $c_2$,...,$c_n$\n%\n\\begin{equation}\n  \\sum_{m=1}^nc_m<\\mathcal{L}u_m,u_k>=<f,u_k>,~~~~~k=1,2,...,n,\\label{sys}\n\\end{equation}\n%\nwhich is called the Ritz system.  After we have found the unknown\nconstants $c_1$, $c_2$,...,$c_n$, the expression (\\ref{rsol}) gives us\nan approximate solution.\n\n\\section{The collocation method}\n\n\\subsection{Introduction}\n\nThe method of collocation can be used to tackle many problems in the\nnumerical analysis of ordinary and partial differential equations.\nHere we give a general description of this method that can be adapted\neasily to the solution of a boundary value problem for an ordinary\ndifferential equation.\n\nSuppose that we have a linear operator $\\mathcal{L}$ (for example, a\nlinear differential equation) that acts on a space of functions.  We\nwish to solve the equation\n%\n\\begin{equation}\n  \\mathcal{L} u(x) = w(x) ,\n  \\label{cwk4.eq:1}\n\\end{equation}\n%\nwhere $w(x)$ is a known function and $u(x)$ is the solution we are\nlooking for.  We indicate with\n%\n\\begin{equation*}\n  \\{v_1(x), v_2(x), \\ldots, v_n(x)\\}\n\\end{equation*}\n%\na set of $n$ known functions (\\textit{basis functions}) and we write\nthe (unknown) solution of equation~(\\ref{cwk4.eq:1}) as\n%\n\\begin{equation}\n  u(x) = \\sum_{j=1}^n c_j v_j(x) ,\n  \\label{cwk4.eq:2}\n\\end{equation}\n%\nwhere the coefficients $c_j$ are (at this stage) unknown.  In general\n$u(x)$ written as in equation~(\\ref{cwk4.eq:2}) cannot be an exact\nsolution of equation~(\\ref{cwk4.eq:1}).  However, we can find a set of\ncoefficients $\\{c_j\\}$ such that~(\\ref{cwk4.eq:2}) is a good\napproximation of the solution of the equation~(\\ref{cwk4.eq:1}).\n\n\\medskip\n\n\\noindent \\textbf{Remark} - Note that the series solution of a\ndifferential equation falls into this class of methods.   In that case\nthe functions $v_j(x)=x^j$, with $j=0,1,2,\\ldots,n$ and the\ncoefficients $c_j$ of the expansion are determined by requiring that\nequation~(\\ref{cwk4.eq:1}) is satisfied at each order in $x$.\n\n\\subsection{The norm method}\n\nThere are various ways of defining ``good approximation''.  As a first\nexample, consider the boundary value problem\n%\n\\begin{equation}\n  u''(x) - u(x) = 0 \\, , \\qquad\n  u(0) = 1, \\quad u(1) = e.\n  \\label{cwk4.eq:4}\n\\end{equation}\n%\nWe wish to find an approximate solution to this problem using as basis\nthe functions\n%\n\\begin{equation*}\n  v_0(x) = 1 , \\quad v_1(x) = x \\quad \\text{and} \\quad v_2(x) = x^2,\n\\end{equation*}\n%\nand write the approximate solution of equation~(\\ref{cwk4.eq:4}) as a\npolynomial of order two:\n%\n\\begin{equation}\n  u^{(a)}(x) = c_0 v_0(x) + c_1 v_1(x) + c_2 v_2(x) =\n  c_0 + c_1 x + c_2 x^2 .\n \\label{cwk4.eq:5}\n\\end{equation}\n%\nIt is clear that there are no values of the constants $c_j$ that can\nmake $u^{(a)}(x)$ as defined in equation~(\\ref{cwk4.eq:5}) equal to\nthe exact solution of equation~(\\ref{cwk4.eq:4}),\n%\n\\begin{equation}\n  u^{(e)}(x) = e^x\n  \\label{cwk4.eq:3}\n\\end{equation}\n%\nfor all values of $x$.  However, we can attempt to find some values of\nthese parameters that minimise the error in approximating $u^{(e)}(x)$\nwith $u^{(a)}(x)$.  There are many different measures of the error of\nthe approximation.  For example, we could require that the\ncoefficients $c_j$ are such that\n\n\\begin{enumerate}\n  %\n\\item $u^{(a)}(x)$ satisfies the boundary conditions, i.e.\\ $u^{(a)}(0)=1$ and $u^{(a)}(1) = e$.\n  %\n\\item $u^{(a)}(x)$ satisfies as well as possible\n  equation~(\\ref{cwk4.eq:4}) in the sense that\n  %\n  \\begin{equation}\n    F(c_j) \\equiv\n    \\left \\| \\dv[2]{}{x} u^{(a)}(x) - u^{(a)}(x) \\right \\|_2^2 =\n    \\mint{0}{1}{\\left [ \\dv[2]{}{x} u^{(a)}(x) - u^{(a)}(x)\n    \\right ]^2}{x}\n    \\label{eq:10}\n  \\end{equation}\n  %\n  is as small as possible.  A criterion (distantly?) related to this\n  is used in the finite element method to solve partial differential\n  equations.\n  %\n\\end{enumerate}\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=80mm]{figures/ColloEner}}\n  \\caption{\\label{fig:ColloEner} \\it Graphs of the exact\n    [Eq.~(\\ref{cwk4.eq:3})] and approximate [Eq.~(\\ref{eq:12})]\n    solution of the boundary value problem~(\\ref{cwk4.eq:4}).}\n\\end{figure}\n\nThe left boundary condition fixes $c_0$:\n%\n\\begin{equation}\n  u^{(a)}(0) = c_0 = 1 .\n  \\label{eq:9}\n\\end{equation}\n%\nThe right boundary condition gives a relation between $c_1$ and $c_2$:\n%\n\\begin{equation}\n  u^{(a)}(1) = c_0 + c_1 + c_2 = e \\implies c_1 = e - 1 - c_2 .\n  \\label{eq:8}\n\\end{equation}\n%\nSubstituting~(\\ref{eq:9}) and~(\\ref{eq:8}) into~(\\ref{cwk4.eq:4})\ngives that $F(c_j)$ defined by~(\\ref{eq:10}) is\n%\n\\begin{equation}\n  F(c_2) = \\frac{47}{10} c_2^2 - \\frac{13}{6}(1+e)c_2 + \\frac{1+e+e^2}{3} .\n  \\label{eq:11}\n\\end{equation}\n%\nWe solve for $c_2$ by requiring that $F(c_2)$ is as small as possible,\ni.e.\\ that the derivative of $F(c_2)$ with respect to $c_2$ is zero.\nDifferentiating~(\\ref{eq:11}) we obtain\n%\n\\begin{equation*}\n \\dv{F}{c_2} = \\frac{47}{5} c_2 - \\frac{13}{6}(1+e) = 0 \\implies\n c_2 = \\frac{65}{282}(1+e) ,\n\\end{equation*}\n%\nso that from equation~(\\ref{eq:8}) we have\n%\n\\begin{equation*}\n  c_1 = \\frac{217 e - 347}{282}\n\\end{equation*}\n%\nand the approximate solution of the boundary value\nproblem~(\\ref{cwk4.eq:4}) is\n%\n\\begin{equation}\n  u^{(a)}(x) = 1 + \\frac{217 e - 347}{282} x + \\frac{65}{282}(1+e) x^2 .\n  \\label{eq:12}\n\\end{equation}\n%\nThe graphs of the approximate and exact solutions are shown in\nFigure~\\ref{fig:ColloEner}: the match is pretty impressive for a three\nnode approximation.\n\n\\subsection{The collocation method}\n\nIn the \\textit{collocation} method we substitute the approximate\nsolution~(\\ref{cwk4.eq:2}) in~(\\ref{cwk4.eq:1}),\n%\n\\begin{equation*}\n  \\mathcal{L} \\sum_{j=1}^n c_j v_j(x) = w(x) \\implies\n  \\sum_{j=1}^n c_j \\mathcal{L} v_j(x) = w(x) ,\n\\end{equation*}\n%\nand we require that this equation should be satisfied at a set of $n$\n\\textit{collocation points} $\\{x_j\\}$, i.e.\\ that the coefficients\n$c_j$ are the solution of the system of linear equations\n%\n\\begin{equation*}\n  \\sum_{j=1}^n c_j \\mathcal{L} v_j(x_k) = w(x_k) , \\qquad k=1,2,\\ldots,n.\n\\end{equation*}\n%\nNote that the values of the basis functions $v_j(x)$ at the\ncollocation points $x_k$ should be such that the matrix of the\ncoefficients of this system is non-singular.\n\n\\begin{figure}\n  \\centerline{\\includegraphics[width=80mm]{figures/Collocation}}\n  \\caption{\\label{fig:Collocation} \\it Graphs of the exact\n    [Eq.~(\\ref{cwk4.eq:3})] and approximate [Eq.~(\\ref{eq:13})]\n    solution of the boundary value problem~(\\ref{cwk4.eq:4}).}\n\\end{figure}\n\nOnce again consider as an example the boundary value\nproblem~(\\ref{cwk4.eq:4}) and write the approximate solution as in\nequation~(\\ref{cwk4.eq:5}).  We require that it should satisfy the\nboundary conditions as in equations~(\\ref{eq:9}) and~(\\ref{eq:8}), so\nthat the approximate solution is now given by\n%\n\\begin{equation*}\n  u^{(a)}(x) = 1 + (e-1-c_2) x + c_2 x^2 .\n\\end{equation*}\n%\nFinally, we require that this function should satisfy the differential\nequation~(\\ref{cwk4.eq:4}) at $x=1/2$.  Taking into account that\n%\n\\begin{equation*}\n \\dv[2]{}{x} u^{(a)}(x) = 2 c_2\n\\end{equation*}\n%\nwe have that this requirement is equivalent to\n%\n\\begin{equation*}\n  2 c_2 - \\left [ 1 + (e-1-c_2) \\frac{1}{2} +\n    c_2 \\left ( \\frac{1}{2} \\right )^2 \\right ] = 0 \\implies\n  c_2 = \\frac{2}{9}(1+e) \\implies c_1 = \\frac{7 e - 11}{9}\n\\end{equation*}\n%\nso that the approximate solution is given by\n%\n\\begin{equation}\n  u^{(a)}(x) = 1 + \\frac{7 e - 11}{9} x + \\frac{2}{9}(1+e) x^2 .\n  \\label{eq:13}\n\\end{equation}\n%\nThe graphs of the approximate and exact solutions are shown in\nFigure~\\ref{fig:Collocation}: the match is pretty impressive for a\nthree node approximation and is comparable, but different, from that\nin Figure~\\ref{fig:ColloEner}.\n\n\\smallskip\n\n\\noindent \\textbf{Remark} - In general it is not advisable to use as\nbasis functions the powers of $x$ or a uniformly spaced set of nodes.\nOrthogonal polynomials (like the Legendre and the Chebyschev\npolynomials) and non-uniform grids (e.g.\\ Gauss-Lobatto grids) give\nmore accurate and numerically stable results.\n\n\n\\section*{Further reading}\n\nTopics covered here are also covered in\n\\begin{itemize}\n\\item Chapter 11 of Linz \\& Wang, \\textit{Exploring Numerical Methods}\n  (QA297 LIN),\n\\item Chapter 8 of Kincaid \\& Cheney, \\textit{Numerical Analysis}\n  (QA297 KIN),\n\\item Chapter 13 (and to some extent 14) of S{\\\"u}li \\& Mayers,\n  \\textit{An Introduction to Numerical Analysis} (not in library).\n\\end{itemize}\n", "meta": {"hexsha": "aa8015e326d31d0a070cffa7945ef77182eb62de", "size": 18700, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/BVP.tex", "max_stars_repo_name": "josh-gree/NumericalMethods", "max_stars_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 76, "max_stars_repo_stars_event_min_datetime": "2015-02-12T19:51:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T15:34:11.000Z", "max_issues_repo_path": "Notes/tex/BVP.tex", "max_issues_repo_name": "josh-gree/NumericalMethods", "max_issues_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-05-24T19:49:52.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-23T21:40:42.000Z", "max_forks_repo_path": "Notes/tex/BVP.tex", "max_forks_repo_name": "josh-gree/NumericalMethods", "max_forks_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2015-01-05T13:30:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T09:59:39.000Z", "avg_line_length": 31.641285956, "max_line_length": 96, "alphanum_fraction": 0.6694117647, "num_tokens": 6742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.9161096158798117, "lm_q1q2_score": 0.805394807485133}}
{"text": "% !TEX root = Main.tex\n\\section{Matrix Approximation \\& Reconstruction}\nproblem of SVD is unobserved entries. Want to only consider I = observed entries. \\\\\n$min_{rank(B)=k}[\\sum_{(i,j) \\in I}(a_{ij} - b_{ij})^2]$\n\\subsection*{Convex Relaxation}\n\\textbullet $rank(B) \\geq \\|B\\|_*$ for $\\|B\\|_2 \\leq 1$. proof: $rank(B)=\\#\\{\\sigma_i >0\\}=\\sum_{i:\\sigma_i>0}1 \\geq \\sum_{i:\\sigma_i>0}\\sigma_i = \\|B\\|_*$ since $\\sigma_1 = \\|B\\|_2  \\leq 1$. Thus $Q_k = \\{B:rank(B) \\leq k\\} \\subseteq P_k = \\{B:\\|B\\|_* \\leq k\\}$ a convex relaxation (in fact convex hull). \\textbullet\nSingular Value Tresholding: if $A=UDV^\\top$ then $shrink_\\tau(A)=UD_\\tau V^\\top$ where $D_\\tau=diag(max\\{0,\\sigma_i-\\tau\\})$. $B_{t+1}=B_t+\\eta_t\\pi(A-shrink_\\tau(B_t))$ where $\\pi$ zeros out unobserved entries.\n\n\\subsection*{Alternating Least Squares}\nreparametrize $B=UV$ where $U \\in \\mathbb{R}^{mxk}, V \\in \\mathbb{R}^{kxn}$. If we have product of two matrices, rank cannot be bigger than smallest rank occuring in it. $min[\\sum_{(i,j) \\in I}(a_{ij} - u_i^\\top v_j)^2]$. ALS = optimize over $u_i$'s while keeping $v_j$'s fixed and vice versa.\n\n", "meta": {"hexsha": "af1d461496a499f6728431e3a1a2177eedc3acc8", "size": 1112, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MatrixApprox.tex", "max_stars_repo_name": "florianmorath/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-19T15:10:37.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-19T15:10:37.000Z", "max_issues_repo_path": "MatrixApprox.tex", "max_issues_repo_name": "florianmorath/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MatrixApprox.tex", "max_forks_repo_name": "florianmorath/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 92.6666666667, "max_line_length": 317, "alphanum_fraction": 0.660971223, "num_tokens": 429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.8791467690927438, "lm_q1q2_score": 0.8053948069219407}}
{"text": "\\chapter{Integer Multiplication}\n\nLet us consider an integer $X$ which is composed of $X_L$ which are\nthe leftmost bits of $X$, and $X_R$ which are the rightmost bits of\n$X$.\n\n\\begin{displaymath}\nX = X_L | X_R\n\\end{displaymath}\n\nWe can multiply integers $X,Y$ as follows:\n\n\\begin{align*}\nXY\n&= (2^{n/2}X_L + X_R)(2^{n/2}Y_L + Y_R) \\\\\n&= 2^n X_LY_L + 2^{n/2}X_LY_R + 2^{n/2}X_RY_L + X_RY_R \\\\\n&= 2^n X_LY_L + 2^{n/2}(X_LY_R + X_RY_L) + X_RY_R \\\\\n\\end{align*}\n\nWhich gives the recurrence\n\n\\begin{align*}\nT(n)\n&= 4T(n/2) + O(n) \\\\\n&\\leq 4T(n/2) + cn \\\\\n&\\leq 4(4T(n/4) + cn/2) + cn \\\\\n&\\leq 4(4(4T(n/8) + cn/4) + cn/2) + cn \\\\\n&\\leq 64T(n/8) + cn(1 + 2 + 4) \\\\\n&... \\\\\n&\\leq 4^iT(n/2^i) + cn(1 + 2 + ... + 2^{i-1})\n\\end{align*}\n\nWhere $i$ is the number of times we can divide $n$ by 2, or $log_2n$.\n\n\\begin{align*}\nT(n)\n&\\leq 4^{log_2n}T(n/2^{log_2n}) + cn(1 + 2 + ... + 2^{log_2n-1}) \\\\\n&\\leq n^{log_24}T(n/n^{log_22}) + cn \\summ{i=0}{log_2n-1} 2^i \\\\\n&\\leq n^2T(1) + cn 2^{log_2n} \\\\\n&\\leq n^2T(1) + cn n^{log_22} \\\\\n&\\leq n^2T(1) + cn^2 \\\\\n&\\leq n^2(T(1) + c) \\\\\n&\\leq n^2(O(1) + c) \\\\\n&\\leq O(n^2)\n\\end{align*}\n\nCan we do better?  Yes.\n\nWe need: $X_LY_L, X_RY_R,$ and $X_LY_R + X_RY_L$\n\nObserve: \n%\n\\begin{align*}\n&(X_L + X_R)(Y_L + Y_R) - X_LY_L - X_RY_R \\\\\n&= X_LY_L + X_RY_L + X_LY_R + X_RY_R - X_LY_L - X_RY_R \\\\\n&= X_RY_L + X_LY_R\n\\end{align*}\n\nSince we must compute $X_LY_L$ and $X_RY_R$ anyway, this saves us an\nentire multiplication.  Reducing our recurrence from $T(n) = 4T(n/2) +\nO(n)$ to $T(n) = 3T(n/2) + O(n)$.\n\nWe can solve this new recurrence as follows:\n\n\\begin{align*}\nT(n)\n&= 3T(n/2) + O(n) \\\\\n&\\leq 3T(n/2) + cn \\\\\n&\\leq 3(3T(n/4) + cn/2) + cn \\\\\n&\\leq 3^iT(n/2^i) + cn(1 + 3/2 + ... + (3/2)^{i-1}) \\\\\n&\\leq 3^{log_2n}T(n/2^{log_2n}) + cn(1 + 2 + ... + (3/2)^{log_2n-1}) \\\\\n&\\leq n^{log_23}T(1) + cn \\summ{i=0}{log_2n-1} (3/2)^i \\\\\n&\\leq n^{log_23}T(1) + cn (3/2)^{log_2n} \\\\\n&\\leq n^{log_23}T(1) + cn n^{log_2(3/2)} \\\\\n&\\leq n^{log_23}T(1) + cn n^{log_23 - log_22} \\\\\n&\\leq n^{log_23}T(1) + cn n^{log_23 - 1} \\\\\n&\\leq n^{log_23}T(1) + cn n^{log_23}n^{-1} \\\\\n&\\leq n^{log_23}(T(1) + cn/n) \\\\\n&\\leq n^{log_23}(T(1) + c) \\\\\n&\\leq O(n^{log_23})\n\\end{align*}\n", "meta": {"hexsha": "0d14601ae05ab2e4e3d1a2ae77ed1b131710cd2b", "size": 2175, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "integer_multiplication.tex", "max_stars_repo_name": "SteamedPears/AllTheAlgorithms", "max_stars_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-12T19:16:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-01T03:13:05.000Z", "max_issues_repo_path": "integer_multiplication.tex", "max_issues_repo_name": "SteamedPears/AllTheAlgorithms", "max_issues_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "integer_multiplication.tex", "max_forks_repo_name": "SteamedPears/AllTheAlgorithms", "max_forks_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.5243902439, "max_line_length": 71, "alphanum_fraction": 0.5485057471, "num_tokens": 1132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868804, "lm_q2_score": 0.8723473663814338, "lm_q1q2_score": 0.8052107822006503}}
{"text": "\\subsection{Orthogonal vectors}\n\nTwo non-zero vectors are said to be \\textbf{orthogonal}%\n\\index{vector!orthogonal}%\n\\index{orthogonal vectors}, sometimes also called\n\\textbf{perpendicular}%\n\\index{vector!perpendicular}%\n\\index{perpendicular vectors}, if the included angle is $\\pi /2$\nradians ($90^{\\circ})$. By convention, we also say that the zero\nvector is orthogonal to all vectors.\n\n\\begin{proposition}{Orthogonal vectors}{orthogonal-vectors}\n  Let $\\vect{u}$ and $\\vect{v}$ be vectors in $\\R^n$. Then $\\vect{u}$\n  and $\\vect{v}$ are orthogonal%\n  \\index{vector!orthogonal} if and only if\n  \\begin{equation*}\n    \\vect{u} \\dotprod \\vect{v} = 0.\n  \\end{equation*}\n  We also write $\\vect{u}\\orth\\vect{v}$ to indicate that $\\vect{u}$\n  and $\\vect{v}$ are orthogonal.\n\\end{proposition}\n\n\\begin{proof}\n  If $\\vect{u}$ or $\\vect{v}$ is zero, the vectors are orthogonal by\n  definition, and the dot product is $0$ in that case, so the\n  proposition holds. Now assume $\\vect{u}$ and $\\vect{v}$ are both\n  non-zero.  Then by Proposition~\\ref{prop:dot-product-angle}, we have\n  $\\vect{u} \\dotprod \\vect{v} = 0$ if and only if\n  $\\norm{\\vect{u}} \\norm{\\vect{v}} \\cos \\theta$ if and only if\n  $\\cos\\theta=0$. Recall that the included angle is between $0$ and\n  $\\pi$. Therefore, $\\cos\\theta=0$ if and only if $\\theta=\\pi/2$.\n\\end{proof}\n\n\\begin{example}{Determine whether two vectors are orthogonal}{orthogonal-vectors}\n  Determine whether the vectors\n  \\begin{equation*}\n    \\vect{u}=\n    \\begin{mymatrix}{r}\n      2 \\\\\n      1 \\\\\n      -1\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{v}\n    =\n    \\begin{mymatrix}{r}\n      1 \\\\\n      3 \\\\\n      5\n    \\end{mymatrix}\n  \\end{equation*}\n  are orthogonal.\n\\end{example}\n\n\\begin{solution}\n  In order to determine if these two vectors are orthogonal, we\n  compute the dot product. We have\n  \\begin{equation*}\n    \\vect{u} \\dotprod \\vect{v}\n    =\n    (2)(1) + (1)(3) + (-1)(5)\n    =\n    0,\n  \\end{equation*}\n  and therefore, by Proposition~\\ref{prop:orthogonal-vectors}, the two vectors are orthogonal.\n\\end{solution}\n", "meta": {"hexsha": "22e00c2f99a8ad7b324533480056db3a002e774c", "size": 2066, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-DotProduct-Orthogonal.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Vectors-DotProduct-Orthogonal.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Vectors-DotProduct-Orthogonal.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 30.8358208955, "max_line_length": 94, "alphanum_fraction": 0.6597289448, "num_tokens": 674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782736, "lm_q2_score": 0.9059898210180105, "lm_q1q2_score": 0.8052064309222439}}
{"text": "\n\\subsection{Binomial distribution}\n\nIf we repeat a Bernoulli trials with the same parameter and sum the results, we have the binomial distribution.\n\nWe therefore have two parameters, \\(p\\) and \\(n\\).\n\n\\(P(X=x)={n\\choose x }p^x(1-p)^{n-x}\\)\n\n\\subsection{Moments of the binomial distribution}\n\nThe mean is \\(np\\), which can be seen as the trials are independent.\n\nSimilarly, the variances can be addeded together giving \\(np(1-p)\\).\n\n", "meta": {"hexsha": "0c494035c99961deb933572dbe63e016e7a9b846", "size": 433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/distributionsDiscreteRepeated/01-01-binomial.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/distributionsDiscreteRepeated/01-01-binomial.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/distributionsDiscreteRepeated/01-01-binomial.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0625, "max_line_length": 111, "alphanum_fraction": 0.7251732102, "num_tokens": 115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897459384731, "lm_q2_score": 0.855851154320682, "lm_q1q2_score": 0.8051759900345034}}
{"text": "\r\n\r\n\\section{The Limit}\\label{sec:LimitsWorkingDefn}\r\nThe value a function $f$ approaches as its input $x$ approaches some value is said to be the limit of $f$. Limits are essential to the study of calculus and, as we will see, are used in defining continuity, derivatives, and integrals.\r\n\r\nConsider the function\r\n$$f(x)=\\frac{x^2-1}{x-1}.$$\r\n\r\nNotice that $x=1$ does not belong to the domain of $f(x)$.\r\nRegardless, we would like to know how $f(x)$ behaves close to the point $x=1$.\r\nWe start with a table of values:\r\n$$\\begin{array}{ccc}\r\n\\underline{x}&\\qquad&\\underline{f(x)}\\\\\r\n0.5&\\qquad&1.5\\\\\r\n0.9&\\qquad&1.9\\\\\r\n0.99&\\qquad&1.99\\\\\r\n1.01&\\qquad&2.01\\\\\r\n1.1&\\qquad&2.1\\\\\r\n1.5&\\qquad&2.5\\\\\r\n\\end{array}$$\r\n\r\nIt appears that for values of $x$ close to $1$ we have that $f(x)$ is close to $2$.\r\nIn fact, we can make the values of $f(x)$ as close to $2$ as we like by taking $x$ sufficiently close to $1$.\r\nWe express this by saying \\ifont{the limit of the function $f(x)$ as $x$ approaches $1$ is equal to $2$} and use the notation:\r\n$$\\lim_{x\\to 1}f(x)=2.$$\r\n\\begin{definition}{Limit (Useable Definition)}{Limit}\r\nIn general, we will write\r\n$$\\lim_{x\\to a}f(x)=L,$$\r\nif we can make the values of $f(x)$ arbitrarily close to $L$ by taking $x$ to be sufficiently close to $a$ (on either side of $a$) but not equal to $a$.\r\n\\end{definition}\r\n\r\nWe read the expression $\\lim_{x\\to a}f(x)=L$ as ``\\ifont{the limit of $f(x)$ as $x$ approaches $a$ is equal to $L$}\".\r\nWhen evaluating a limit, you are essentially answering the following question: \r\nWhat number does the function \\ifont{approach} while $x$ gets closer and closer to $a$ (but \\ifont{not equal} to $a$)?\r\nThe phrase \\ifont{but not equal to $a$} in the definition of a limit means \r\nthat when finding the limit of $f(x)$ as $x$ approaches $a$ we never actually consider $x=a$.\r\nIn fact, as we just saw in the example above, $a$ may not even belong to the domain of $f$.\r\nAll that matters for limits is what happens to $f$ close to $a$, not necessarily what happens to $f$ at $a$.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nConsider the function $y = \\frac{\\sin x}{x}$. When $x$ is near the value $ 1 $, what value (if any) is $y$ near?%\r\n One might think first to look at a graph of this function to approximate the appropriate $y$ values. Consider Figure \\ref{fig:zoom_sinx_over_x}, where $y = \\frac{\\sin x}{x}$ is graphed. For values of $x$ near 1, it seems that $y$ takes on values near $0.85$. In fact, when $x=1$, then $y=\\frac{\\sin 1}{1} \\approx 0.84$, so it makes sense that when $x$ is ``near'' 1, $y$ will be ``near'' $0.84$.\r\n\r\n\r\n\r\n\r\n\r\n\\begin{figure}\r\n\t\\centering\r\n\t\\begin{subfigure}[t]{0.5\\textwidth}\r\n\t\t\\begin{tikzpicture} %[scale=.6]\r\n\t\t\\begin{axis}[\r\n\t\t        xmin=0,\r\n\t\t        xmax=1.5,\r\n\t\t        ymin=0,\r\n\t\t        ymax=1,\r\n\t\t       % y=2cm,\r\n\t\t       % x=1cm,\r\n\t\t %   domain=0.5:1.5,\r\n\t\t    samples=400,\r\n\t\t    axis lines=middle,\r\n\t\t   % xtick = {0.78539, 1.57079, 2.3561,3.1415, 3.92699,4.7123,5.49778,6.28318,7.06858},\r\n\t\t % xticklabels = {$\\frac{\\pi}{4}$,$\\frac{\\pi}{2}$,$\\frac{3\\pi}{4}$,$\\pi $, $\\frac{5\\pi}{4}$, $\\frac{3\\pi}{2}$, $\\frac{7\\pi}{4}$, $2\\pi$,},\r\n\t\t %   ytick={-1,1},\r\n\t\t]\r\n\t\t\\addplot [ thick, blue,name path=A, domain = 0.5:1.5] {(sin(deg(x)))/x}; \r\n\t\t%\\draw[red] (axis cs:1.5,4) node {$y=x^2$};\r\n\t\t%\\addplot [thick, blue,name path=B,domain=0:2.1] {sqrt(x)};\r\n\t\t%\\draw[blue] (axis cs:1.6,.8) node {$y=\\sqrt{x}$};\r\n\t\t%\\draw[blue] (axis cs: .4,.4) node {\\scriptsize $A_1$};\r\n\t\t%\\draw[blue] (axis cs:1.6,1.8) node {\\scriptsize $A_2$};\r\n\t\t%% \\addplot [draw=none,name path=B] {0};     % \u201cfictional\u201d curve\r\n\t\t%  \\addplot [\\coloronefill] fill between[of = A and B,soft clip={domain=0:2}]; % filling\r\n\t\t\\end{axis}\r\n\t\t\\end{tikzpicture}\r\n        \\label{fig:zoom_sinx_over_x}\r\n        \\caption{$\\sin(x)/x$ near $x=1$.} \r\n    \\end{subfigure}% \r\n    \\begin{subfigure}[t]{0.5\\textwidth}\r\n    \\begin{tikzpicture} %[scale=.6]\r\n    \\begin{axis}[\r\n            xmin=-1.1,\r\n            xmax=1.1,\r\n            ymin=0,\r\n            ymax=1.5,\r\n           % y=2cm,\r\n           % x=1cm,\r\n       % domain=-1:1,\r\n        samples=400,\r\n        axis lines=middle,\r\n       % xtick = {0.78539, 1.57079, 2.3561,3.1415, 3.92699,4.7123,5.49778,6.28318,7.06858},\r\n     % xticklabels = {$\\frac{\\pi}{4}$,$\\frac{\\pi}{2}$,$\\frac{3\\pi}{4}$,$\\pi $, $\\frac{5\\pi}{4}$, $\\frac{3\\pi}{2}$, $\\frac{7\\pi}{4}$, $2\\pi$,},\r\n     %   ytick={-1,1},\r\n    ]\r\n    \\addplot [ thick, blue,name path=A, domain = -1:-0.01] {(sin(deg(x)))/x}; \r\n    \\addplot [ thick, blue,name path=B, domain = 0.01:1] {(sin(deg(x)))/x}; \r\n    \\draw [fill=white] (axis cs:0,1) circle [radius=1.5pt];\r\n    %\\draw[red] (axis cs:1.5,4) node {$y=x^2$};\r\n    %\\addplot [thick, blue,name path=B,domain=0:2.1] {sqrt(x)};\r\n    %\\draw[blue] (axis cs:1.6,.8) node {$y=\\sqrt{x}$};\r\n    %\\draw[blue] (axis cs: .4,.4) node {\\scriptsize $A_1$};\r\n    %\\draw[blue] (axis cs:1.6,1.8) node {\\scriptsize $A_2$};\r\n    %% \\addplot [draw=none,name path=B] {0};     % \u201cfictional\u201d curve\r\n    %  \\addplot [\\coloronefill] fill between[of = A and B,soft clip={domain=0:2}]; % filling\r\n    \\end{axis}\r\n    \\end{tikzpicture}%\r\n        \\label{fig:sinx_over_x}\r\n        \\caption{$\\sin(x)/x$ near $x=0$.}    \r\n    \\end{subfigure} \r\n    \\caption{\\label{sinx_over_x1}}\r\n\\end{figure}\r\n\r\n\r\n\r\n\r\n\r\nConsider this again at a different value for $x$. When $x$ is near 0, what value (if any) is $y$ near? By considering Figure \\ref{sinx_over_x1} \\subref{fig:sinx_over_x}, one can see that it seems that $y$ takes on values near $1$. But what happens when $x=0$? We have $$ y \\rightarrow \\frac{\\sin 0}{0} \\rightarrow \\raisebox{8pt}{\\text{``\\ }}\\frac{0}{0}\\raisebox{8pt}{\\text{\\ ''}}.$$ \r\nThe expression ``$0/0$'' has no value; it is \\emph{indeterminate.} \\index{limit!indeterminate form}\\index{indeterminate form} Such an expression gives no information about what is going on with the function nearby. We cannot find out how $y$ behaves near $x=0$ for this function simply by letting $x=0$. \r\n\r\n\\emph{Finding a limit} entails understanding how a function behaves near a particular value of $x$. We approximated $$\\lim_{x\\to 1} \\frac{\\sin x}{x} \\approx 0.84 \\quad \\text{ and } \\quad \\lim_{x\\to 0}\\frac{\\sin x}{x} \\approx 1.$$ (We \\textit{approximated} these limits, hence used the ``$\\approx$'' symbol, since we are working with the pseudo-definition of a limit, not the actual definition.)\r\n\r\nOnce we have the true definition of a limit, we will find limits \\textit{analytically}; that is, exactly using a variety of mathematical tools. For now, we will \\textit{approximate} limits both graphically and numerically. Graphing a function can provide a good approximation, though often not very precise. Numerical methods can provide a more accurate approximation. We have already approximated limits graphically, so we now turn our attention to numerical approximations.\r\n\r\n\r\nConsider again $\\lim_{x\\to 1}\\sin (x)/x$. To approximate this limit numerically, we can create a table of $x$ and $f(x)$ values where $x$ is ``near'' 1. This is done in Table \\ref{table:sinx_1}.\\par\r\n\r\nNotice that for values of $x$ near $1$, we have $\\sin (x)/x$ near $0.841$. The $x=1$ row is in bold to highlight the fact that when considering limits, we are \\textit{not} concerned with the value of the function at that particular $x$ value; we are only concerned with the values of the function when $x$ is \\textit{near} 1. \r\n\r\n\\mTable{.3}{Values of $\\sin(x)/x$ with $x$ near 1.}{table:sinx_1}{\\begin{tabular}{cc}\r\n$x$ & $\\sin(x)/x$ \\\\ \\hline \r\n0.9 & 0.870363 \\\\\r\n 0.99 & 0.844471 \\\\\r\n 0.999 & 0.841772 \\\\\r\n \\textbf{1} & \\textbf{0.841471} \\\\\r\n 1.001 & 0.84117 \\\\\r\n 1.01 & 0.838447 \\\\\r\n 1.1 & 0.810189\r\n\\end{tabular}\r\n%\\caption{Values of $\\frac{\\sin x}{x}$ for $x$ near 1.}\\label{fig:sinx_1_table}}}\r\n%\\vskip \\baselineskip\r\n}\r\nNow approximate $\\lim_{x\\to 0} \\sin(x)/x$ numerically. We already approximated the value of this limit as 1 graphically in Figure \\ref{sinx_over_x1} \\subref{fig:sinx_over_x}. Table \\ref{table:sinx_2} shows the value of $\\sin(x)/x$ for values of $x$ near 0. Ten places after the decimal point are shown to highlight how close to 1 the value of $\\sin(x)/x$ gets as $x$ takes on values very near 0. We include the $x=0$ row in bold again to stress that we are not concerned with the value of our function at $x=0$, only on the behaviour of the function \\textit{near} 0. \r\n\r\n\\mTable{.8}{Values of $\\sin(x)/x$ with $x$ near 1.}{table:sinx_2}{\\begin{tabular}{cc}\r\n$x$ & $\\sin(x)/x$ \\\\ \\hline\r\n -0.1 & 0.9983341665 \\\\\r\n -0.01 & 0.9999833334 \\\\\r\n -0.001 & 0.9999998333 \\\\\r\n \\textbf{0} & \\textbf{not defined} \\\\\r\n 0.001 & 0.9999998333 \\\\\r\n 0.01 & 0.9999833334 \\\\\r\n 0.1 & 0.9983341665\r\n \\end{tabular}\r\n% \\caption{Values of $\\frac{\\sin x}{x}$ for $x$ near 0.}\\label{fig:sinx_0_table}\r\n}\r\n \r\nThis numerical method gives confidence to say that 1 is a good approximation of $\\lim_{x\\to 0} \\sin(x)/x$; that is, $$\\lim_{x\\to 0} \\sin(x)/x \\approx 1.$$ Later we will be able to prove that the limit is \\textit{exactly} 1.\r\n\r\n\r\n\r\n\r\nWe now consider several examples that allow us explore different aspects of the limit concept.\\\\\r\n\r\n \r\n\\begin{example}{Approximating the value of a limit}{exa:ex_limit1}{\r\nUse graphical and numerical methods to approximate $$\\lim_{x\\to 3} \\frac{x^2-x-6}{6x^2-19x+3}.$$}%\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{To graphically approximate the limit, graph $$y = (x^2-x-6)/(6x^2-19x+3)$$ on a small interval that contains $ 3 $. To numerically approximate the limit, create a table of values where the $x$ values are near $ 3 $. This is done in Figure \\ref{fig:limit1} and Table \\ref{table:limit1}, respectively.\r\n\r\n\\mfigure{.5}{ %Graphically approximating a limit in Example \\ref{ex_limit1}.\r\n}{fig:limit1}{\r\n\\begin{tikzpicture}\r\n\\begin{axis}[clip=false, minor x tick num=1,axis y line=middle,axis x line=middle,ymin=.25,ymax=.35,extra y tick labels={},xmin=2.3,xmax=3.7,name=myplot]\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(2.5,0.321429) (2.61,0.314461) (2.72,0.308094) (2.83,0.302253) (2.94,0.296875) (3.05,0.291908) (3.16,0.287305) (3.27,0.283029) (3.38,0.279046) (3.49,0.275326)};\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) { $y$};\r\n\\end{tikzpicture} %\r\n} %\r\n\\mTable{.45}{ %Numerically approximating a limit in Example \\ref{exa:ex_limit1}.\r\n}{table:limit1}{\\begin{tabular}{cc}\r\n$x$ & $\\frac{x^2-x-6}{6x^2-19x+3}$ \\\\ \\hline\r\n2.9 & 0.29878 \\\\\r\n 2.99 & 0.294569 \\\\\r\n 2.999 & 0.294163 \\\\\r\n \\textbf{3} & \\textbf{not defined}\\\\\r\n 3.001 & 0.294073 \\\\\r\n 3.01 & 0.293669 \\\\\r\n 3.1 & 0.289773\r\n \\end{tabular} %\r\n }\r\n\r\n\r\nThe graph shows that when $x$ is near 3, the value of $y$ is very near $0.3$. By considering values of $x$ near 3, we see that $y=0.294$ is a better approximation. The graph and the table imply that $$\\lim_{x\\to 3} \\frac{x^2-x-6}{6x^2-19x+3} \\approx 0.294.$$ \r\n}\r\n\\end{solution}\r\n \r\n\r\n\r\n\r\nThis example may bring up a few questions about approximating limits (and the nature of limits themselves). \r\n\\begin{enumerate}\r\n\\item\t\tIf a graph does not produce as good an approximation as a table, why bother with it?\r\n\\item\t\tHow many values of $x$ in a table are ``enough?'' In the previous example, could we have just used $x=3.001$ and found a fine approximation?\r\n\\end{enumerate}\r\n\r\nGraphs are useful since they give a visual understanding concerning the behavior of a function. Sometimes a function may act ``erratically'' near certain $x$ values which is hard to discern numerically but very plain graphically. Since graphing utilities are very accessible, it makes sense to make proper use of them.\r\n\r\n\r\nSince tables and graphs are used only to \\textit{approximate} the value of a limit, there is not a firm answer to how many data points are ``enough.'' Include enough so that a trend is clear, and use values (when possible) both less than and greater than the value in question. In Example \\ref{ex_limit1}, we used both values less than and greater than 3. Had we used just $x=3.001$, we might have been tempted to conclude that the limit had a value of $0.3$. While this is not far off, we could do better. Using values ``on both sides of 3'' helps us identify trends.\\\\\r\n\r\n\\begin{example}{Approximating the value of a limit}{ex_limit2}{\r\nGraphically and numerically approximate the limit of $f(x)$ as $x$ approaches 0, where $$f(x) = \\left\\{\\begin{array}{rl} x+1 & x< 0 \\\\ -x^2+1 & x > 0 \\end{array}\\right..$$}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{Again we graph $f(x)$ and create a table of its values near $x=0$ to approximate the limit. Note that this is a piecewise defined function, so it behaves differently on either side of 0. Figure \\ref{fig:limit2} shows a graph of $f(x)$, and on either side of 0 it seems the $y$ values approach 1. Note that $f(0)$ is not actually defined, as indicated in the graph with the open circle.\r\n\r\n\\mfigure{.5}{ %Graphically approximating a limit in Example \\ref{ex_limit2}.\r\n}{fig:limit2}{\\begin{tikzpicture}\r\n\\begin{axis}[minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-.1,ymax=1.1,xmin=-1.1,xmax=1.1,name=myplot]\r\n%%\\addplot [{\\colorone},thick,smooth] coordinates {(-1.,0.) (-0.89,0.11) (-0.78,0.22) (-0.67,0.33) (-0.56,0.44) (-0.45,0.55) (-0.34,0.66) (-0.23,0.77) (-0.12,0.88) (-0.01,0.99) (0,1) (0.1,0.99) (0.21,0.9559) (0.32,0.8976) (0.43,0.8151) (0.54,0.7084) (0.65,0.5775) (0.76,0.4224) (0.87,0.2431) (1,0) \r\n%};\r\n\\addplot [{\\colorone},thick, smooth,domain=-1:0,samples=2] ({x},{x+1});\r\n\\addplot [{\\colorone},thick, smooth,domain=0:1,samples=15] ({x},{1-x^2});\r\n\r\n\\filldraw [thick,fill=white] (axis cs:0,1) circle (1.5pt);\r\n\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) {  $x$};\r\n\\node [above] at (myplot.above origin) {  $y$};\r\n\\end{tikzpicture}\r\n%\\caption{Graphically approximating $\\lim_{x\\to 0}f(x)$ in Example \\ref{ex_limit2}.}\\label{fig:limit2}\r\n}\r\n\\mTable{.45}{ %Numerically approximating a limit in Example \\ref{ex_limit2}.\r\n}{table:limit2\r\n}{\\begin{tabular}{cc}\r\n$x$ & $f(x)$ \\\\ \\hline\r\n-0.1 & 0.9 \\\\\r\n -0.01 & 0.99 \\\\\r\n -0.001 & 0.999 \\\\\r\n 0.001 & 0.999999 \\\\\r\n 0.01 & 0.9999 \\\\\r\n 0.1 & 0.99\r\n \\end{tabular}}\r\n\r\nTable \\ref{table:limit2} shows values of $f(x)$ for values of $x$ near 0. It is clear that as $x$ takes on values very near 0, $f(x)$ takes on values very near 1. It turns out that if we let $x=0$ for either ``piece'' of $f(x)$, 1 is returned; this is significant and we'll return to this idea later.\r\n\r\nThe graph and table allow us to say that $\\lim_{x\\to 0}f(x) \\approx 1$; in fact, we are probably very sure it \\textit{equals} 1.\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\\subsection*{Identifying When Limits Do Not Exist}\r\n\r\nA function may not have a limit for all values of $x$. That is, we cannot say $\\lim_{x\\to c}f(x)=L$ for some numbers $L$ for all values of $c$, for there may not be a number that $f(x)$ is approaching. There are three ways in which a limit may fail to exist. \\index{limit!does not exist}\r\n\\begin{enumerate}\r\n\\item\t\tThe function $f(x)$ may approach different values on either side of $c$.\r\n\\item\t\tThe function may grow without upper or lower bound as $x$ approaches $c$.\r\n\\item\t\tThe function may oscillate as $x$ approaches $c$.\r\n\\end{enumerate}\r\n\r\nWe'll explore each of these in turn.\\\\\r\n\r\n\r\n\r\n\\begin{example}{Different Values Approached From Left and Right}{ex_no_limit1}{\r\n\tExplore why $\\ds\\lim_{x\\to 1} f(x)$ does not exist, where $$f(x) = \\left\\{\\begin{array}{cl} x^2-2x+3 & x\\leq 1 \\\\ x & x>1 \\end{array}\\right..$$}%\t\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{\r\nA graph of $f(x)$ around $x=1$ and a table are given Figure \\ref{fig:nolimit1} and Table \\ref{table:nolimit1}, respectively. It is clear that as $x$ approaches $ 1 $, $f(x)$ does not seem to approach a single number. Instead, it seems as though $f(x)$ approaches two different numbers. When considering values of $x$ less than $ 1 $ (approaching $ 1 $ from the left), it seems that $f(x)$ is approaching $ 2 $; when considering values of $x$ greater than $ 1 $ (approaching $ 1 $ from the right), it seems that $f(x)$ is approaching $ 1 $. Recognizing this behavior is important; we'll study this in greater depth later. Right now, it suffices to say that the limit does not exist since $f(x)$ is not approaching one particular value as $x$ approaches $ 1 $.\r\n\\mfigure{.5}{Observing no limit as $x\\to 1$ in Example \\ref{exa:ex_no_limit1}.}{fig:nolimit1}{\\begin{tikzpicture}\r\n\t\\begin{axis}[tick label style={font=\\scriptsize},minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-.1,ymax=3.2,xmin=-.1,xmax=2.1,name=myplot]\r\n\t\r\n\t\\addplot [{\\colorone},smooth,thick] coordinates {(0.,3.) (0.1,2.81) (0.2,2.64) (0.3,2.49) (0.4,2.36) (0.5,2.25) (0.6,2.16) (0.7,2.09) (0.8,2.04) (0.9,2.01) (1,2)};\r\n\t\\addplot [{\\colorone},smooth,thick] coordinates {(1,1) (1.1,1.1) (1.2,1.2) (1.3,1.3) (1.4,1.4) (1.5,1.5) (1.6,1.6) (1.7,1.7) (1.8,1.8) (1.9,1.9) (2.,2.)\r\n\t};\r\n\t\\filldraw [fill=white,draw={\\colorone},thick] (axis cs:1,1) circle (1.5pt);\r\n\t\\filldraw [fill={\\colorone},{\\colorone}] (axis cs:1,2) circle (1.5pt);\r\n\t\\end{axis}\r\n\t\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\t\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\t\\end{tikzpicture}%\r\n}\r\n\t%\\caption{of $f(x)$ in Example \\ref{ex_no_limit1}.}\\label{fig:nolimit1}}\r\n\t\\mTable{.5}{Values of $f(x)$ near $x=1$ in Example \\ref{exa:ex_no_limit1}.}{table:nolimit1}{\\begin{tabular}{cc}\r\n\t\t\t$x$ & $f(x)$ \\\\ \\hline\r\n\t\t\t0.9 & 2.01 \\\\\r\n\t\t\t0.99 & 2.0001 \\\\\r\n\t\t\t0.999 & 2.000001 \\\\\r\n\t\t\t1.001 & 1.001 \\\\\r\n\t\t\t1.01 & 1.01 \\\\\r\n\t\t\t1.1 & 1.1\r\n\t\t\\end{tabular}\r\n\t\t}\r\n}\t\r\n\\end{solution}\t\r\n\r\n\r\n\r\n\r\n%\r\n%%\r\n\r\n%\\noindent\\textbf{The Function Grows Without Bound}\\\\\r\n\r\n%\\input{figures/fig_nolimit2}\r\n\r\n\\begin{example}{The Function Grows Without Bound}{ex_no_limit2}{\r\n\tExplore why $\\ds \\lim_{x\\to 1} \\frac{1}{(x-1)^2}$ does not exist.}%\t\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{A graph and table of $f(x) = 1/(x-1)^2$ are given in Figure \\ref{fig:nolimit2} and Table \\ref{table:nolimit2}, respectively. Both show that as $x\\to 1$, $f(x)$ grows larger and larger. \r\n\t\\mfigure{.4}{Observing no limit as $x\\to 1$ in Example \\ref{exa:ex_no_limit2}.}{fig:nolimit2}{\\begin{tikzpicture}\r\n\t\t\\begin{axis}[tick label style={font=\\scriptsize},minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-1,ymax=110,xmin=-.1,xmax=2.1,name=myplot]\r\n\t\t\r\n\t\t\\addplot [{\\colorone},smooth,thick] coordinates {(0.,1.) (0.05,1.10803) (0.1,1.23457) (0.15,1.38408) (0.2,1.5625)(0.25,1.77778) (0.3,2.04082) (0.35,2.36686) (0.4,2.77778)(0.45,3.30579) (0.5,4.) (0.55,4.93827) (0.6,6.25) (0.65,8.16327)(0.7,11.1111) (0.75,16.) (0.8,25.) (0.85,44.4444) (0.9,100.) };\r\n\t\t\\addplot [{\\colorone},smooth,thick] coordinates {(1.1,100.) (1.15,44.4444) (1.2,25.) (1.25,16.) (1.3,11.1111) (1.35,8.16327) (1.4,6.25) (1.45,4.93827) (1.5,4.) (1.55,3.30579) (1.6,2.77778) (1.65,2.36686) (1.7,2.04082) (1.75,1.77778) (1.8,1.5625) (1.85,1.38408) (1.9,1.23457) (1.95,1.10803) (2.,1.)};\r\n\t\t%\\addplot [{\\colorone},smooth] coordinates {(1,1) (1.1,1.1) (1.2,1.2) (1.3,1.3) (1.4,1.4) (1.5,1.5) (1.6,1.6) (1.7,1.7) (1.8,1.8) (1.9,1.9) (2.,2.)\r\n\t\t\\draw [dashed,thick] (axis cs: 1,1) -- (axis cs: 1,100);\r\n\t\t\\end{axis}\r\n\t\t\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\t\t\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\t\t\\end{tikzpicture}\r\n\t\t%\\caption{of $f(x)$ in Example \\ref{ex_no_limit2}.}\\label{fig:nolimit2}\r\n\t\t}%\r\n\\hfill\t\\mTable{.4}{Values of $f(x)$ near $x=1$ in Example \\ref{exa:ex_no_limit2}.}{table:nolimit2}{\\begin{tabular}{cc}\r\n\t\t\t$x$ & $f(x)$ \\\\ \\hline\r\n\t\t\t0.9 & 100. \\\\\r\n\t\t\t0.99 & 10000. \\\\\r\n\t\t\t0.999 & $1.\\times 10^6$ \\\\\r\n\t\t\t1.001 & $1.\\times 10^6$ \\\\\r\n\t\t\t1.01 & 10000. \\\\\r\n\t\t\t1.1 & 100.\r\n\t\t\\end{tabular}}\r\n\t\r\n\tWe can deduce this on our own, without the aid of the graph and table. If $x$ is near 1, then $(x-1)^2$ is very small, and: $$\\frac{1}{\\text{very small number}} = \\text{very large number}.$$\r\n\tSince $f(x)$ is not approaching a single number, we conclude that $$\\lim_{x\\to 1}\\frac{1}{(x-1)^2}$$ does not exist.\r\n}\t\r\n\\end{solution}\t\r\n\r\n\r\n%\r\n%%\\vskip \\baselineskip\r\n%%\\noindent\\textbf{The Function Oscillates}\\\\\r\n%\r\n\r\n\\begin{example}{The Function Oscillates}{ex_no_limit3}{\r\n\tExplore why $\\ds\\lim_{x\\to 0}\\sin(1/x)$ does not exist.}%\r\n\t\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{%\\mfigure{.4}{Observing no limit as $x\\to 0$ in Example \\ref{ex_no_limit3}.}{fig:nolimit3a}{figures/figNoLimit3a}\r\n\t%\\mfigure{.2}{Zooming in to observing no limit as $x\\to 0$ in Example \\ref{ex_no_limit3}.}{fig:nolimit3b}{figures/figNoLimit3b}\r\n\tTwo graphs of $f(x) = \\sin(1/x)$ are given in Figures \\ref{fig:nolimit3}. Figure \\ref{fig:nolimit3}(a) shows $f(x)$ on the interval $[-1,1]$; notice how $f(x)$ seems to oscillate near $x=0$. One might think that despite the oscillation, as $x$ approaches 0, $f(x)$ approaches 0. However, Figure \\ref{fig:nolimit3}(b) zooms in on $\\sin(1/x)$, on the interval $[-0.1,0.1]$. Here the oscillation is even more pronounced. Finally, in the table in Figure \\ref{fig:nolimit3}(c), we see $\\sin(x)/x$ evaluated for values of $x$ near 0. As $x$ approaches 0, $f(x)$ does not appear to approach any value. \r\n\t\r\n\tIt can be shown that in reality, as $x$ approaches 0, $\\sin(1/x)$ takes on all values between $-1$ and 1 infinite times! Because of this oscillation,\r\n\t\r\n\t$\\ds\\lim_{x\\to 0}\\sin(1/x)$ does not exist.}\\\\\r\n\t\r\n\t\r\n\\end{solution}\t\r\n\r\n\r\n\r\n\\begin{figure}\r\n\t\\centering\r\n\t\\begin{subfigure}[t]{0.4\\textwidth}\r\n\t\t\\begin{tikzpicture}\r\n\t\t\\begin{axis}[minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-1.1,ymax=1.1,xmin=-1.1,xmax=1.1,name=myplot]\r\n\t\t\\addplot [{\\colorone},smooth,thick] coordinates {(-1.,-0.841471) (-0.95,-0.86873) (-0.9,-0.896192) (-0.85,-0.923256)(-0.8,-0.948985) (-0.75,-0.971938) (-0.7,-0.989903) (-0.65,-0.999477)(-0.6,-0.995408) (-0.55,-0.969556) (-0.5,-0.909297)(-0.49,-0.891559) (-0.48,-0.871503)(-0.47,-0.848917) (-0.46,-0.823572) (-0.45,-0.79522)(-0.44,-0.763597) (-0.43,-0.728419) (-0.42,-0.689385)(-0.41,-0.64618) (-0.4,-0.598472) (-0.39,-0.545923) (-0.38,-0.488189)(-0.37,-0.424935) (-0.36,-0.355842) (-0.35,-0.280629)(-0.34,-0.199077) (-0.33,-0.11106) (-0.32,-0.0165919)(-0.31,0.0841143) (-0.3,0.190568) (-0.29,0.301898) (-0.28,0.416722)(-0.27,0.532974) (-0.26,0.6477) (-0.25,0.756802) (-0.24,0.854753)(-0.23,0.93428) (-0.22,0.986099) (-0.21,0.998774) (-0.2,0.958924)(-0.19,0.852122) (-0.18,0.665102) (-0.17,0.390185) (-0.16,0.0331792)(-0.15,-0.374151) (-0.14,-0.757628) (-0.13,-0.986959)(-0.12,-0.887294) (-0.11,-0.327701) (-0.1,0.544021) (-0.09,0.993333)(-0.08,0.0663219) (-0.07,-0.988987) (-0.06,0.818447)(-0.05,-0.912945) (-0.04,0.132352) (-0.03,-0.94053) (-0.02,0.262375)(-0.01,0.506366)(0.01,-0.506366) (0.02,-0.262375) (0.03,0.94053) (0.04,-0.132352)(0.05,0.912945) (0.06,-0.818447) (0.07,0.988987) (0.08,-0.0663219)(0.09,-0.993333) (0.1,-0.544021) (0.11,0.327701) (0.12,0.887294)(0.13,0.986959) (0.14,0.757628) (0.15,0.374151) (0.16,-0.0331792)(0.17,-0.390185) (0.18,-0.665102) (0.19,-0.852122) (0.2,-0.958924)(0.21,-0.998774) (0.22,-0.986099) (0.23,-0.93428) (0.24,-0.854753)(0.25,-0.756802) (0.26,-0.6477) (0.27,-0.532974) (0.28,-0.416722)(0.29,-0.301898) (0.3,-0.190568) (0.31,-0.0841143) (0.32,0.0165919)(0.33,0.11106) (0.34,0.199077) (0.35,0.280629) (0.36,0.355842)(0.37,0.424935) (0.38,0.488189) (0.39,0.545923) (0.4,0.598472)(0.41,0.64618) (0.42,0.689385) (0.43,0.728419) (0.44,0.763597)(0.45,0.79522) (0.46,0.823572) (0.47,0.848917) (0.48,0.871503)(0.49,0.891559) (0.5,0.909297)(0.55,0.969556) (0.6,0.995408) (0.65,0.999477) (0.7,0.989903)(0.75,0.971938) (0.8,0.948985) (0.85,0.923256) (0.9,0.896192)(0.95,0.86873) (1.,0.841471) };\r\n\t\t\\end{axis}\r\n\t\t\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\t\t\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\t\t\\end{tikzpicture}\r\n\t\t\\label{fig:nolimit3a}\r\n\t\t\\caption{} \r\n\t\\end{subfigure}% \r\n\t\\begin{subfigure}[t]{0.4\\textwidth}\r\n\t\t\\begin{tikzpicture}\r\n\t\t\\begin{axis}[minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-1.1,ymax=1.1,xmin=-.11,xmax=.11,name=myplot]\r\n\t\t\\addplot [{\\colorone},smooth,thick] coordinates {(-0.1,0.544021) (-0.099,0.625859) (-0.098,0.702784) (-0.097,0.773598) (-0.096,0.837061) (-0.095,0.891904) (-0.094,0.936853) (-0.093,0.970648) (-0.092,0.992071) (-0.091,0.999978) (-0.09,0.993333) (-0.089,0.971247) (-0.088,0.933026) (-0.087,0.878215) (-0.086,0.806651) (-0.085,0.718515) (-0.084,0.614387) (-0.083,0.495298) (-0.082,0.362779) (-0.081,0.218905) (-0.08,0.0663219) (-0.079,-0.0917281) (-0.078,-0.251415) (-0.077,-0.408347) (-0.076,-0.557627) (-0.075,-0.693952) (-0.074,-0.81175) (-0.073,-0.905374) (-0.072,-0.969337) (-0.071,-0.998614) (-0.07,-0.988987) (-0.069,-0.937442) (-0.068,-0.842593) (-0.067,-0.705118) (-0.066,-0.528174) (-0.065,-0.317743) (-0.064,-0.0828681) (-0.063,0.164304) (-0.062,0.408736) (-0.061,0.633044) (-0.06,0.818447) (-0.059,0.94617) (-0.058,0.999301) (-0.057,0.965066) (-0.056,0.837348) (-0.055,0.619211) (-0.054,0.325024) (-0.053,-0.0183676) (-0.052,-0.372047) (-0.051,-0.687679) (-0.05,-0.912945) (-0.049,-0.999926) (-0.048,-0.915928) (-0.047,-0.65528) (-0.046,-0.249359) (-0.045,0.229023) (-0.044,0.671421) (-0.043,0.953507) (-0.042,0.969509) (-0.041,0.67613) (-0.04,0.132352) (-0.039,-0.486679) (-0.038,-0.925763) (-0.037,-0.948132) (-0.036,-0.4764) (-0.035,0.292743) (-0.034,0.907558) (-0.033,0.896983) (-0.032,0.165166) (-0.031,-0.746068) (-0.03,-0.94053) (-0.029,-0.0746909) (-0.028,0.915507) (-0.027,0.614755) (-0.026,-0.690678) (-0.025,-0.745113) (-0.024,0.7352) (-0.023,0.482964) (-0.022,-0.995148) (-0.021,0.475171) (-0.02,0.262375) (-0.019,-0.70007) (-0.018,0.83773) (-0.017,-0.762217) (-0.016,0.325796) (-0.015,0.639018) (-0.014,-0.73662) (-0.013,-0.998945) (-0.012,-0.996711) (-0.011,-0.195822) (-0.01,0.506366) (-0.009,0.914944) (-0.008,0.61604) (-0.007,0.996362) (-0.006,0.161545) (-0.005,0.873297) (-0.004,0.970528) (-0.003,-0.318846) (-0.002,0.467772) (-0.001,-0.82688) (0,-0.85773) (0.001,0.82688) (0.002,-0.467772) (0.003,0.318846) (0.004,-0.970528) (0.005,-0.873297) (0.006,-0.161545) (0.007,-0.996362) (0.008,-0.61604) (0.009,-0.914944) (0.01,-0.506366) (0.011,0.195822) (0.012,0.996711) (0.013,0.998945) (0.014,0.73662) (0.015,-0.639018) (0.016,-0.325796) (0.017,0.762217) (0.018,-0.83773) (0.019,0.70007) (0.02,-0.262375) (0.021,-0.475171) (0.022,0.995148) (0.023,-0.482964) (0.024,-0.7352) (0.025,0.745113) (0.026,0.690678) (0.027,-0.614755) (0.028,-0.915507) (0.029,0.0746909) (0.03,0.94053) (0.031,0.746068) (0.032,-0.165166) (0.033,-0.896983) (0.034,-0.907558) (0.035,-0.292743) (0.036,0.4764) (0.037,0.948132) (0.038,0.925763) (0.039,0.486679) (0.04,-0.132352) (0.041,-0.67613) (0.042,-0.969509) (0.043,-0.953507) (0.044,-0.671421) (0.045,-0.229023) (0.046,0.249359) (0.047,0.65528) (0.048,0.915928) (0.049,0.999926) (0.05,0.912945) (0.051,0.687679) (0.052,0.372047) (0.053,0.0183676) (0.054,-0.325024) (0.055,-0.619211) (0.056,-0.837348) (0.057,-0.965066) (0.058,-0.999301) (0.059,-0.94617) (0.06,-0.818447) (0.061,-0.633044) (0.062,-0.408736) (0.063,-0.164304) (0.064,0.0828681) (0.065,0.317743) (0.066,0.528174) (0.067,0.705118) (0.068,0.842593) (0.069,0.937442) (0.07,0.988987) (0.071,0.998614) (0.072,0.969337) (0.073,0.905374) (0.074,0.81175) (0.075,0.693952) (0.076,0.557627) (0.077,0.408347) (0.078,0.251415) (0.079,0.0917281) (0.08,-0.0663219) (0.081,-0.218905) (0.082,-0.362779) (0.083,-0.495298) (0.084,-0.614387) (0.085,-0.718515) (0.086,-0.806651) (0.087,-0.878215) (0.088,-0.933026) (0.089,-0.971247) (0.09,-0.993333) (0.091,-0.999978) (0.092,-0.992071) (0.093,-0.970648) (0.094,-0.936853) (0.095,-0.891904) (0.096,-0.837061) (0.097,-0.773598) (0.098,-0.702784) (0.099,-0.625859) (0.1,-0.544021)\r\n\t\t};\r\n\t\t\\end{axis}\r\n\t\t\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\t\t\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\t\t\\end{tikzpicture}\r\n\t\t\\label{fig:nolimit3b}\r\n\t\t\\caption{}    \r\n\t\\end{subfigure} \r\n\t\\begin{subfigure}[t]{0.2\\textwidth}\r\n\t\t\t\t\t\\begin{tabular}{cc}\r\n\t\t\t\t\t\t0.1 & -0.544021 \\\\\r\n\t\t\t\t\t\t0.01 & -0.506366 \\\\\r\n\t\t\t\t\t\t0.001 & 0.82688 \\\\\r\n\t\t\t\t\t\t0.0001 & -0.305614 \\\\\r\n\t\t\t\t\t\t1$\\times 10^{-5}$ & 0.0357488 \\\\\r\n\t\t\t\t\t\t1$\\times 10^{-6}$& -0.349994\\\\\r\n\t\t\t\t\t\t1$\\times 10^{-7}$ & 0.420548\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\\label{fig:nolimit3c}\r\n\t\t\\caption{}    \r\n\t\\end{subfigure} \r\n\t\\caption{Observing that $f(x) = \\sin(1/x)$ has no limit as $x\\to 0$ \\label{fig:nolimit3} }\r\n\\end{figure}\r\n\r\n\r\n\r\n\\subsection{Limits of Difference Quotients}\\label{subsec:limitofdiffquotientintro}\r\n%\r\nWe have approximated limits of functions as $x$ approached a particular number. We will consider another important kind of limit after explaining a few key ideas.\\index{limit!difference quotient}\r\n\r\n\\mfigure{.5}{Interpreting a difference quotient as the slope of a secant line.}{fig:diffquot1}{ %\r\n\\begin{tikzpicture}\r\n\\begin{axis}[clip=false, minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-1,ymax=25,extra y tick labels={},xmin=-1,xmax=6.5,name=myplot]\r\n\\addplot [{\\colorone},smooth,thick] coordinates {(0.,0.) (0.5,5.375) (1.,10.) (1.5,13.875) (2.,17.) (2.5,19.375)(3.,21.) (3.5,21.875) (4.,22.) (4.5,21.375) (5.,20.) (5.5,17.875)(6.,15.) };\r\n\\addplot [{\\colortwo},smooth,thick] coordinates {(0,7.5) (6,22.5)};\r\n\\fill[black] (axis cs:1,10) circle (1pt);\r\n\\fill[black] (axis cs:5,20) circle (1pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) { $f$};\r\n\\end{tikzpicture}\r\n}\r\n\r\nLet $f(x)$ represent the position function, in feet, of some particle that is moving in a straight line, where $x$ is measured in seconds. Let's say that when $x=1$, the particle is at position 10 ft., and when $x=5$, the particle is at 20 ft. Another way of expressing this is to say $$f(1)=10 \\quad \\text{ and } \\quad f(5) = 20.$$\r\nSince the particle traveled 10 feet in 4 seconds, we can say the particle's \\textit{average velocity} was 2.5 ft/s. We write this calculation using a ``quotient of differences,'' or, a \\textit{difference quotient}: $$\\frac{f(5) - f(1)}{5-1} = \\frac{10}4 = 2.5 \\text{ft/s}.$$\r\n\r\nThis difference quotient can be thought of as the familiar ``rise over run'' used to compute the slopes of lines. In fact, that is essentially what we are doing: given two points on the graph of $f$, we are finding the slope of the \\textit{secant line} through those two points. See Figure \\ref{fig:diffquot1}.\r\n\r\nNow consider finding the average speed on another time interval. We again start at $x=1$, but consider the position of the particle $h$ seconds later. That is, consider the positions of the particle when $x=1$ and when $x=1+h$. The difference quotient is now $$\\frac{f(1+h)-f(1)}{(1+h)-1} = \\frac{f(1+h)-f(1)}h.$$\r\n\r\nLet $f(x) = -1.5x^2+11.5x$; note that $f(1)=10$ and $f(5) = 20$, as in our discussion. We can compute this difference quotient for all values of $h$ (even negative values!) except $h=0$, for then we get ``0/0,'' the indeterminate form introduced earlier. For all values $h\\neq 0$, the difference quotient computes the average velocity of the particle over an interval of time of length $h$ starting at $x=1$. \r\n\r\nFor small values of $h$, i.e., values of $h$ close to $ 0 $, we get average velocities over very short time periods and compute secant lines over small intervals. See Figure \\ref{fig:diff_quot_small_h}. This leads us to wonder what the limit of the difference quotient is as $h$ approaches $ 0 $. That is, $$\\lim_{h\\to 0} \\frac{f(1+h)-f(1)}{h} = \\text{ ? }$$\r\n\r\n\\begin{figure}\r\n\t\\centering\r\n\t\\begin{subfigure}[t]{0.33\\textwidth}\r\n\t\t \\begin{tikzpicture}\r\n\t\t \\begin{axis}[clip=false,minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-1,ymax=25,extra y tick labels={},xmin=-1,xmax=6.5,name=myplot]\r\n\t\t \\addplot [{\\colorone},smooth,thick] coordinates {(0.,0.) (0.5,5.375) (1.,10.) (1.5,13.875) (2.,17.) (2.5,19.375)(3.,21.) (3.5,21.875) (4.,22.) (4.5,21.375) (5.,20.) (5.5,17.875)(6.,15.) };\r\n\t\t \\addplot [{\\colortwo},smooth,thick] coordinates {(0,4.5) (4,26.5)};\r\n\t\t \\fill[black] (axis cs:1,10) circle (1pt);\r\n\t\t \\fill[black] (axis cs:3,21) circle (1pt);\r\n\t\t \\end{axis}\r\n\t\t \\node [right] at (myplot.right of origin) { $x$};\r\n\t\t \\node [above] at (myplot.above origin) { $f$};\r\n\t\t \\end{tikzpicture}\r\n        \\label{fig:diff_quot_small_ha}\r\n        \\caption{$ h=2 $} \r\n    \\end{subfigure}% \r\n    \\begin{subfigure}[t]{0.33\\textwidth}\r\n     \\begin{tikzpicture}\r\n     \\begin{axis}[clip=false,tick label style={font=\\scriptsize},minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-1,ymax=25,extra y tick labels={},xmin=-1,xmax=6.5,name=myplot]\r\n     \\addplot [{\\colorone},smooth,thick] coordinates {(0.,0.) (0.5,5.375) (1.,10.) (1.5,13.875) (2.,17.) (2.5,19.375)(3.,21.) (3.5,21.875) (4.,22.) (4.5,21.375) (5.,20.) (5.5,17.875)(6.,15.) };\r\n     \\addplot [{\\colortwo},smooth,thick] coordinates {(0,3) (3,24)};\r\n     \\fill[black] (axis cs:1,10) circle (1pt);\r\n     \\fill[black] (axis cs:2,17) circle (1pt);\r\n     \\end{axis}\r\n     \\node [right] at (myplot.right of origin) {$x$};\r\n     \\node [above] at (myplot.above origin) { $f$};\r\n     \\end{tikzpicture}\r\n        \\label{fig:diff_quot_small_hb}\r\n        \\caption{$ h=1 $}    \r\n    \\end{subfigure}\r\n\\begin{subfigure}[t]{0.33\\textwidth}\r\n     \\begin{tikzpicture}\r\n     \\begin{axis}[clip=false,minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-1,ymax=25,extra y tick labels={},xmin=-1,xmax=6.5,name=myplot]\r\n     \\addplot [{\\colorone},smooth,thick] coordinates {(0.,0.) (0.5,5.375) (1.,10.) (1.5,13.875) (2.,17.) (2.5,19.375)(3.,21.) (3.5,21.875) (4.,22.) (4.5,21.375) (5.,20.) (5.5,17.875)(6.,15.) };\r\n     \\addplot [{\\colortwo},smooth,thick] coordinates {(0,2.25) (2.5,21.625)};\r\n     \\fill[black] (axis cs:1,10) circle (1pt);\r\n     \\fill[black] (axis cs:1.5,13.875) circle (1pt);\r\n     \\end{axis}\r\n     \\node [right] at (myplot.right of origin) { $x$};\r\n     \\node [above] at (myplot.above origin) {$f$};\r\n     \\end{tikzpicture}\r\n        \\label{fig:diff_quot_small_hc}\r\n        \\caption{$ h=.5 $}    \r\n    \\end{subfigure} \r\n    \\caption{Secant lines of $f(x)$ at $x=1$ and $x=1+h$, for shrinking values of $h$ (i.e., $h\\rightarrow 0$).\\label{fig:diff_quot_small_h} }\r\n\\end{figure}\r\n\r\n\r\n\r\nAs we do not yet have a true definition of a limit nor an exact method for computing it, we settle for approximating the value. While we could graph the difference quotient (where the $x$-axis would represent $h$ values and the $y$-axis would represent values of the difference quotient) we settle for making a table. See Figure \\ref{table:diff_quot_smallh}. The table gives us reason to assume the value of the limit is about 8.5. \\\\\r\n\r\n\\mTable{.5}{The difference quotient evaluated at values of $h$ near 0.}{table:diff_quot_smallh}{\\begin{tabular}{cc}$h$ & $\\frac{f(1+h)-f(1)}{h}$\\vspace{1pt} \\\\ \\hline $-0.5$ & 9.25 \\\\ $-0.1$ & 8.65 \\\\ $-0.01$ & 8.515 \\\\ 0.01 & 8.485 \\\\ 0.1 & 8.35 \\\\ 0.5 & 7.75 \\end{tabular}} \r\n\r\n\r\n\r\n\r\n% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %\r\n\\subsection*{One-sided limits}\r\nConsider the following piecewise defined function:\r\n%$$f(x)=\r\n%\\left\\{\\begin{array}{ccc}\r\n%x,&\\quad&\\mbox{if $x\\leq 1$,}\\\\\r\n%x+1,&\\quad&\\mbox{if $x>1$,}\\\\\r\n%\\end{array}\\right.$$\r\n%which has the following visual representation:\r\n$$\\includegraphics[width=4.0in]{images/limits-1}$$ Observe from the\r\ngraph that as $x$ gets closer and closer to $1$ from the \\textit{left},\r\nthen $f(x)$ approaches $+1$.  Similarly, as $x$ gets closer and closer\r\n$1$ from the \\textit{right}, then $f(x)$ approaches $+2$.  We use the\r\nfollowing notation to indicate this: $$\\lim_{x\\to\r\n1^-}f(x)=1\\qquad\\mbox{and}\\qquad\\lim_{x\\to 1^+}f(x)=2.$$ \r\n%The symbol\r\n%$x\\to 1^-$ means that we only consider values of $x$ sufficiently\r\n%close to $1$ which are less than $1$.  Similarly, the symbol $x\\to\r\n%1^+$ means that we only consider values of $x$ sufficiently close to\r\n%$1$ which are greater than $1$.\r\n\r\n\\begin{definition}{Left and Right-Hand Limit (Useable Definition)}{LeftRightHandLimit}\r\nIn general, we will write\r\n$$\\lim_{x\\to a^-}f(x)=L,$$\r\nif we can make the values of $f(x)$ arbitrarily close to $L$ by taking $x$ to be sufficiently close to $a$ and $x$ less than $a$.\r\nThis is called the {\\textbf{left-hand limit}} of $f(x)$ as $x$ approaches $a$.\r\nSimilarly, we write\r\n$$\\lim_{x\\to a^+}f(x)=L,$$\r\nif we can make the values of $f(x)$ arbitrarily close to $L$ by taking $x$ to be sufficiently close to $a$ and $x$ greater than $a$.\r\nThis is called the  {\\textbf{right-hand limit}} of $f(x)$ as $x$ approaches $a$.\r\n\\end{definition}\r\n\r\n\r\n\r\nPractically speaking, when evaluating a left-hand limit at $ a $, we consider only values of $x$ ``to the left of $a$,'' on the real number line i.e., where $x<a$. The admittedly imperfect notation $x\\to a^-$ is used to imply that we look at values of $x$ to the left of $a$. The notation has nothing to do with positive or negative values of either $x$ or $a$. A similar statement holds for evaluating right-hand limits; there we consider only values of $x$ to the right of $a$ on the real number line, i.e., $x>a$. \r\n\r\n%We can use the theorems from previous sections to help us evaluate these limits; we just restrict our view to one side of $c$.\r\n\r\nWe practice evaluating left and right-hand limits through a series of examples.\\\\\r\n\r\n\r\n\\begin{example}{Evaluating one sided limits}{ex_onesidea}{\r\nLet $\\ds f(x) = \\left\\{\\begin{array}{cc} x & 0\\leq x\\leq 1 \\\\ 3-x & 1<x<2\\end{array},\\right.$ as shown in Figure \\ref{fig:onesided1}. Find each of the following: \r\n\r\n\\noindent\\begin{minipage}[t]{.5\\textwidth}\r\n\\begin{enumerate}\r\n\\item\t\t$\\ds \\lim_{x\\to 1^-} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 1^+} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 1} f(x)$\r\n\\item\t\t$\\ds f(1)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\begin{minipage}[t]{.5\\textwidth}\r\n\\begin{enumerate}\\addtocounter{enumi}{4}\r\n\\item\t\t$\\ds \\lim_{x\\to 0^+} f(x)$\r\n\\item\t\t$f(0)$\r\n\\item\t\t$\\ds \\lim_{x\\to 2^-} f(x)$\r\n\\item\t\t$f(2)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\r\n\\mfigure{.65}{A graph of $f$ in Example \\ref{exa:ex_onesidea}.}{fig:onesided1}{\\centering \\begin{tikzpicture}\r\n\\begin{axis}[minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-.4,ymax=2.4,xmin=-.4,xmax=2.4,name=myplot]\r\n\\addplot [{\\colorone},smooth,thick] coordinates {(0,0) (1,1)};\r\n\\fill[black,draw=black] (axis cs:1,1) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:0,0) circle (1.5pt);\r\n\\addplot [{\\colorone},smooth,thick] coordinates {(1,2) (2,1)};\r\n\\fill[white,draw=black,thick] (axis cs:1,2) circle (1.5pt);\r\n\\fill[white,draw=black,thick] (axis cs:2,1) circle (1.5pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) {  $x$};\r\n\\node [above] at (myplot.above origin) {  $y$};\r\n\\end{tikzpicture}\r\n% this is the sqrt[x] on [0,5]} %\r\n}\r\n}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{For these problems, the visual aid of the graph effective in evaluating the limits.\r\n\t\t\t\\begin{enumerate}\r\n\t\t\t\\item\t\tAs $x$ goes to 1 \\textit{from the left}, we see that $f(x)$ is approaching the value of 1. Therefore $\\ds \\lim_{x\\to 1^-} f(x) =1.$\r\n\t\t\t\\item\t\tAs $x$ goes to 1 \\textit{from the right}, we see that $f(x)$ is approaching the value of 2. Recall that it does not matter that there is an ``open circle'' there; we are evaluating a limit, not the value of the function. Therefore $\\ds \\lim_{x\\to 1^+} f(x)=2$.\r\n\t\t\t\\item\t\t\\textit{The} limit of $f$ as $x$ approaches 1 does not exist since the function does not approach one particular value, but two different values from the left and the right.\r\n\t\t\t\\item\t\tUsing the definition and by looking at the graph we see that $f(1) = 1$.\r\n\t\t\t\\item\t\tAs $x$ goes to 0 from the right, we see that $f(x)$ is also approaching 0. Therefore $\\ds \\lim_{x\\to 0^+} f(x)=0$. Note we cannot consider a left-hand limit at 0 as $f$ is not defined for values of $x<0$.\r\n\t\t\t\\item\t\tUsing the definition and the graph, $f(0) = 0$.\r\n\t\t\t\\item\t\tAs $x$ goes to 2 from the left, we see that $f(x)$ is approaching the value of 1. Therefore $\\ds \\lim_{x\\to 2^-} f(x)=1.$\r\n\t\t\t\\item\t\tThe graph and the definition of the function show that $f(2)$ is not defined.\r\n\t\t\t\\end{enumerate}\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\n\r\n%We note the following fact:\r\n%\\begin{center}\r\n%$\\ds{\\lim_{x\\to a}f(x)=L\\qquad\\mbox{if and only if}\\qquad\\lim_{x\\to a^-}f(x)=L\\qquad\\mbox{and}\\qquad\\lim_{x\\to a^+}f(x)=L}.$\r\n%\\end{center}\r\n%Or more concisely:\r\n%\\[\\lim_{x\\to a^-}f(x)=\\lim_{x\\to a^+}f(x)=L\\].\r\n%A consequence of this fact is that if the one-sided limits are \\ifont{different}, then the two-sided limit $\\ds{\\lim_{x\\to a}f(x)}$ does not exist, often denoted as: (DNE).\r\n\r\n\r\nNote how the left and right-hand limits were different at $x=1$. This, of course, causes \\textit{the} limit to not exist. The following theorem states what is fairly intuitive: \\textit{the} limit exists precisely when the left and right-hand limits are equal.\r\n\r\n\\begin{theorem}{Limits and One Sided Limits}{leftrightlimits}\r\n{Let $f$ be a function defined on an open interval $I$ containing $c$. \\index{limit!does not exist} Then $$\\lim_{x\\to c}f(x) = L$$ if, and only if, $$\\lim_{x\\to c^-}f(x) = L \\quad \\text{and} \\quad \\lim_{x\\to c^+}f(x) = L.$$}\r\n\\end{theorem}\r\n\r\nThe phrase ``if, and only if'' means the two statements are \\textit{equivalent}: they are either both true or both false. If the limit equals $L$, then the left and right hand limits both equal $L$. If the limit is not equal to $L$, then at least one of the left and right-hand limits is not equal to $L$ (it may not even exist).\r\n\t\t\t\r\nOne thing to consider in Examples \\ref{exa:ex_onesidea} -- \\ref{exa:ex_onesided} is that the value of the function may/may not be equal to the value(s) of its left/right-hand limits, even when these limits agree. \\\\\r\n\r\n\r\n\\begin{example}{Evaluating limits of a piecewise--defined function}{ex_onesideb}{\r\nLet $f(x) = \\left\\{\\begin{array}{cc} 2-x & 0<x<1 \\\\ (x-2)^2 & 1<x<2 \\end{array},\\right.$ as shown in Figure \\ref{fig:onesidedb}. Evaluate the following. \r\n\r\n\\noindent\\begin{minipage}[t]{.5\\textwidth}\r\n\t\t\\begin{enumerate}\r\n\t\t\\item\t\t$\\ds \\lim_{x\\to 1^-} f(x)$\r\n\t\t\\item\t\t$\\ds \\lim_{x\\to 1^+} f(x)$\r\n\t\t\\item\t\t$\\ds \\lim_{x\\to 1} f(x)$\r\n\t\t\\item\t\t$\\ds f(1)$\r\n\t\t\\end{enumerate}\r\n\t\t\\end{minipage}\r\n\t\t\\begin{minipage}[t]{.5\\textwidth}\r\n\t\t\\begin{enumerate}\\addtocounter{enumi}{4}\r\n\t\t\\item\t\t$\\ds \\lim_{x\\to 0^+} f(x)$\r\n\t\t\\item\t\t$f(0)$\r\n\t\t\\item\t\t$\\ds \\lim_{x\\to 2^-} f(x)$\r\n\t\t\\item\t\t$f(2)$\r\n\t\t\\end{enumerate}\t\r\n\t\t\\end{minipage}\r\n\t\t\r\n\\mfigure{.7}{A graph of $f$ from Example \\ref{exa:ex_onesideb}}{fig:onesidedb}{ %\r\n\\begin{tikzpicture}\r\n\\begin{axis}[minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-.4,ymax=2.4,xmin=-.4,xmax=2.4,name=myplot]\r\n\\addplot [{\\colorone},smooth,thick] coordinates {(0,2) (1,1)};\r\n\\addplot [{\\colorone},smooth,thick] coordinates {(1.,1.) (1.1,0.81) (1.2,0.64) (1.3,0.49) (1.4,0.36) (1.5,0.25) (1.6,0.16) (1.7,0.09) (1.8,0.04) (1.9,0.01) (2.,0.)};\r\n\\fill[white,draw=black,thick] (axis cs:2,0) circle (1.5pt);\r\n\\fill[white,draw=black,thick] (axis cs:0,2) circle (1.5pt);\r\n\\fill[white,draw=black,thick] (axis cs:1,1) circle (1.5pt);\r\n%\\fill[white,draw=black] (axis cs:2,1) circle (1pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) {  $y$};\r\n\\end{tikzpicture}\r\n}\t\t\r\n}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{Again we will evaluate each using both the definition of $f$ and its graph.\r\n\t\t\\begin{enumerate}\r\n\t\t\\item\t\tAs $x$ approaches $ 1 $ from the left, we see that $f(x)$ approaches $ 1 $. Therefore $\\ds \\lim_{x\\to 1^-} f(x)=1.$\r\n\t\t\\item\t\tAs $x$ approaches 1 from the right, we see that again $f(x)$ approaches 1. Therefore $\\ds \\lim_{x\\to 1+} f(x)=1$.\r\n\t\t\\item\t\t\\textit{The} limit of $f$ as $x$ approaches 1 exists and is 1, as $f$ approaches 1 from both the right and left. Therefore $\\ds \\lim_{x\\to 1} f(x)=1$.\r\n\t\t\\item\t\t$f(1)$ is not defined. Note that 1 is not in the domain of $f$ as defined by the problem, which is indicated on the graph by an open circle when $x=1$.\r\n\t\t\\item\t\tAs $x$ goes to 0 from the right, $f(x)$ approaches 2. So $\\ds \\lim_{x\\to 0^+} f(x)=2$.\r\n\t\t\\item\t\t$f(0)$  is not defined as $0$ is not in the domain of $f$.\r\n\t\t\\item\t\tAs $x$ goes to 2 from the left, $f(x)$ approaches 0. So $\\ds \\lim_{x\\to 2^-} f(x)=0$.\r\n\t\t\\item\t\t$f(2)$  is not defined as 2 is not in the domain of $f$.\r\n\t\t\\end{enumerate}\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\n%\r\n\\begin{example}{Evaluating limits of a piecewise--defined function}{ex_onesidec}{\r\nLet $f(x) = \\left\\{\\begin{array}{cc} (x-1)^2 & 0\\leq x\\leq 2, x\\neq 1\\\\ 1 & x=1\\end{array},\\right.$ as shown in Figure \\ref{fig:onesidedc}. Evaluate the following.\r\n\r\n\t\t\\noindent\\begin{minipage}[t]{.5\\textwidth}\r\n\t\t\\begin{enumerate}\r\n\t\t\\item\t\t$\\ds \\lim_{x\\to 1^-} f(x)$\r\n\t\t\\item\t\t$\\ds \\lim_{x\\to 1^+} f(x)$\r\n\t\t\\end{enumerate}\r\n\t\t\\end{minipage}\r\n\t\t\\begin{minipage}[t]{.5\\textwidth}\r\n\t\t\\begin{enumerate}\\addtocounter{enumi}{2}\r\n\t\t\\item\t\t$\\ds \\lim_{x\\to 1} f(x)$\r\n\t\t\\item\t\t$f(1)$\r\n\t\t\\end{enumerate}\r\n\t\t\\end{minipage}\r\n\t\t\r\n\\mfigure{.7}{Graphing $f$ in Example \\ref{exa:ex_onesidec}}{fig:onesidedc}{ %\r\n\\begin{tikzpicture}\r\n\\begin{axis}[minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-.4,ymax=1.4,xmin=-.4,xmax=2.4,name=myplot]\r\n%\\addplot [{\\colorone},smooth] coordinates {(0,2) (1,1)};\r\n\\addplot [{\\colorone},smooth,thick] coordinates {(0.,1.) (0.1,0.81) (0.2,0.64) (0.3,0.49) (0.4,0.36) (0.5,0.25) (0.6,0.16) (0.7,0.09) (0.8,0.04) (0.9,0.01) (1.,0.) (1.1,0.01)\r\n(1.2,0.04) (1.3,0.09) (1.4,0.16) (1.5,0.25) (1.6,0.36) (1.7,0.49)\r\n(1.8,0.64) (1.9,0.81) (2.,1.)\r\n};\r\n\\fill[black,draw=black] (axis cs:0,1) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:2,1) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:1,1) circle (1.5pt);\r\n\\fill[white,draw=black,thick] (axis cs:1,0) circle (1.5pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) { $y$};\r\n\\end{tikzpicture}}\t\t\r\n}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{\t\tIt is clear by looking at the graph that both the left and right-hand limits of $f$, as $x$ approaches 1, is 0. Thus it is also clear that \\textit{the} limit is 0; i.e., $\\ds \\lim_{x\\to 1} f(x) = 0$. It is also clearly stated that $f(1) = 1$. \\vskip .4\\baselineskip\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\n\\begin{example}{Evaluating limits of a piecewise--defined function}{ex_onesided}{\r\nLet $f(x) = \\left\\{\\begin{array}{cc} x^2 & 0\\leq x\\leq 1 \\\\ 2-x & 1<x\\leq 2\\end{array},\\right.$ as shown in Figure \\ref{fig:onesidedd}. Evaluate the following. \r\n\r\n\t\t\\noindent\\begin{minipage}[t]{.5\\textwidth}\r\n\t\t\\begin{enumerate}\r\n\t\t\\item\t\t$\\ds \\lim_{x\\to 1^-} f(x)$\r\n\t\t\\item\t\t$\\ds \\lim_{x\\to 1^+} f(x)$\r\n\t\t\\end{enumerate}\r\n\t\t\\end{minipage}\r\n\t\t\t\t\\noindent\\begin{minipage}[t]{.5\\textwidth}\r\n\t\t\\begin{enumerate}\\addtocounter{enumi}{2}\r\n\t\t\\item\t\t$\\ds \\lim_{x\\to 1} f(x)$\r\n\t\t\\item\t\t$f(1)$\r\n\t\t\\end{enumerate}\r\n\t\t\\end{minipage}\t\t\r\n}\r\n%\\mfigure{.7}{Graphing $f$ in Example \\ref{exa:ex_onesided}}{fig:onesided}{ %\r\n\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{\t\tIt is clear from the definition of the function and its graph that all of the following are equal:\r\n\\mfigure{.8}{Graphing $f$ in Example \\ref{exa:ex_onesided}}{fig:onesidedd}{\\begin{tikzpicture}\r\n\\begin{axis}[minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-.4,ymax=1.4,xmin=-.4,xmax=2.4,name=myplot]\r\n\\addplot [{\\colorone},smooth,thick] coordinates {(2,0) (1,1)};\r\n\\addplot [{\\colorone},smooth,thick] coordinates {(0.,0.) (0.1,0.01) (0.2,0.04) (0.3,0.09) (0.4,0.16) (0.5,0.25)(0.6,0.36) (0.7,0.49) (0.8,0.64) (0.9,0.81) (1.,1.) };\r\n\\fill[black,draw=black] (axis cs:0,0) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:1,1) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:2,0) circle (1.5pt);\r\n%\\fill[white,draw=black] (axis cs:2,1) circle (1pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) {  $x$};\r\n\\node [above] at (myplot.above origin) {  $y$};\r\n\\end{tikzpicture}}\r\n$$ \\lim_{x\\to 1^-} f(x) = \\lim_{x\\to 1^+} f(x) =\\lim_{x\\to 1} f(x) =f(1) = 1.$$\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nIn Examples \\ref{ex_onesidea} -- \\ref{ex_onesided} we were asked to find both $\\ds \\lim_{x\\to 1}f(x)$ and $f(1)$. Consider the following table:\r\n\\begin{center}\r\n\\begin{tabular}{ccc} & $\\ds \\lim_{x\\to 1}f(x)$ & $f(1)$ \\vspace{2pt}\\\\ \\hline\r\nExample \\ref{exa:ex_onesidea} & does not exist & 1 \\\\\r\nExample \\ref{exa:ex_onesideb} & 1 & not defined \\\\\r\nExample \\ref{exa:ex_onesidec} & 0 & 1 \\\\\r\nExample \\ref{exa:ex_onesided} & 1 & 1 \\\\\r\n\\end{tabular}\r\n\\end{center}\r\n\r\nOnly in Example \\ref{exa:ex_onesided} do both the function and the limit exist and agree. This seems ``nice;'' in fact, it seems ``normal.'' This is in fact an important situation which we explore in the next section, entitled ``Continuity.'' In short, a \\textit{continuous function} is one in which when a function approaches a value as $x\\rightarrow c$ (i.e., when $\\ds \\lim_{x\\to c} f(x) = L$), it actually \\textit{attains} that value at $c$. Such functions behave nicely as they are very predictable.\r\n\r\n\r\n\r\nProper understanding of limits is key to understanding calculus. With limits, we can accomplish seemingly impossible mathematical things, like adding up an infinite number of numbers (and not get infinity) and finding the slope of a line between two points, where the ``two points'' are actually the same point. These are not just mathematical curiosities; they allow us to link position, velocity and acceleration together, connect cross-sectional areas to volume, find the work done by a variable force, and much more.\r\n\r\n\r\nIn the next section we give the formal definition of the limit and begin our study of finding limits analytically. \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n%In the following exercises, we continue our introduction and approximate the value of limits.\\\\\r\n%\r\n%\\printexercises{exercises/01_01_exercises}\r\n\r\n\r\n%One-sides:\r\n%\r\n%\\printexercises{exercises/01_04_exercises}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:LimitsWorkingDefn}}\r\n\r\n\\begin{multicols}{2}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n% % % % % % % % % % %\r\n\\begin{ex}\r\n\\begin{enumerate}\r\n\\item {In your own words, what does it mean to ``find the limit of $f(x)$ as $x$ approaches 3''?}\r\n\r\n\\item {An expression of the form $\\frac00$ is called \\underline{\\hskip 15pt}.}\r\n\r\n\\item {T/F: The limit of $f(x)$ as $x$ approaches $5$ is $f(5)$.}\r\n\r\n\\item {Describe three situations where $\\displaystyle \\lim_{x\\to c}f(x)$ does not exist.}\r\n\r\n\\item {In your own words, what is a difference quotient?}\r\n\r\n\\item {T/F: If $\\ds \\lim_{x\\to 1^-} f(x) = 5$, then $\\ds \\lim_{x\\to 1} f(x) = 5$}\r\n\r\n\\item {T/F: If $\\ds \\lim_{x\\to 1^-} f(x) = 5$, then $\\ds \\lim_{x\\to 1^+} f(x) = 5$}\r\n\r\n\\item {T/F: If $\\ds \\lim_{x\\to 1} f(x) = 5$, then $\\ds \\lim_{x\\to 1^-} f(x) = 5$}\r\n\r\n\\end{enumerate}\r\n\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\\item {Answers will vary.}\r\n\\item {An indeterminate form.}\r\n\\item {F}\r\n\\item {The function may approach different values from the left and right, the function may grow without bound, or the function might oscillate.}\r\n\\item {Answers will vary.}\r\n\\item {F}\r\n\\item {F}\r\n\\item {T}\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\\end{ex}\r\n% % % % % % % % % % % %\r\n\\begin{ex}\r\nEvaluate the expressions by reference to this graph:\r\n$$\\includegraphics[width=3.5in]{images/limit-exercise-graph}$$\r\n\\begin{multicols}{3}\r\n\\begin{enumerate}\r\n\t\\item\t$\\ds \\lim_{x\\to 4} f(x)$\r\n\t\\item\t$\\ds \\lim_{x\\to -3} f(x)$\r\n\t\\item\t$\\ds \\lim_{x\\to 0} f(x)$\r\n\t\\item\t$\\ds \\lim_{x\\to 0^-} f(x)$\r\n\t\\item\t$\\ds \\lim_{x\\to 0^+} f(x)$\r\n\t\\item\t$\\ds f(-2)$\r\n\t\\item\t$\\ds \\lim_{x\\to 2^-} f(x)$\r\n\t\\item\t$\\ds \\lim_{x\\to -2^-} f(x)$\r\n\t\\item\t$\\ds \\lim_{x\\to 0} f(x+1)$\r\n\t\\item\t$\\ds f(0)$\r\n\t\\item\t$\\ds \\lim_{x\\to 1^-} f(x-4)$\r\n\t\\item\t$\\ds \\lim_{x\\to 0^+} f(x-2)$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\begin{sol}\r\n\\begin{multicols}{3}\r\n\\begin{enumerate}\r\n\t\\item\t$8$\r\n\t\\item\t$6$\r\n\t\\item\tdne\r\n\t\\item\t$-2$\r\n\t\\item\t$-1$\r\n\t\\item\t$8$\r\n\t\\item\t$7$\r\n\t\\item\t$6$\r\n\t\\item\t$3$\r\n\t\\item\t$-3/2$\r\n\t\\item\t$6$\r\n\t\\item\t$2$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n% % % % % % % % % % %\r\n\\begin{ex}\r\nApproximate the given limits both numerically and graphically.\r\n\\begin{enumerate}\r\n\\item {$-1$}\r\n\\item {$\\displaystyle \\lim_{x\\to 0} x^3-3x^2+x-5$}\r\n\\item {$\\displaystyle \\lim_{x\\to 0} \\frac{x+1}{x^2+3x}$}\r\n\\item {$\\displaystyle \\lim_{x\\to 3} \\frac{x^2-2x-3}{x^2-4x+3}$}\r\n\\item {$\\displaystyle \\lim_{x\\to -1} \\frac{x^2+8x+7}{x^2+6x+5}$}\r\n\\item {$\\displaystyle \\lim_{x\\to 2} \\frac{x^2+7x+10}{x^2-4x+4}$}\r\n\\item {$\\displaystyle \\lim_{x\\to 2} f(x)$, where \r\n\r\n$f(x) = \\left\\{\\begin{array}{cl} x+2 & x\\leq 2 \\\\ 3x-5 & x>2 \\end{array}\\right.$.\r\n}\r\n\\item {$\\displaystyle \\lim_{x\\to 3} f(x)$, where \r\n\r\n$f(x) = \\left\\{\\begin{array}{cl} x^2-x+1 & x\\leq 3 \\\\ 2x+1 & x>3 \\end{array}\\right.$.}\r\n\\item {$\\displaystyle \\lim_{x\\to 0} f(x)$, where \r\n\r\n$f(x) = \\left\\{\\begin{array}{cl} \\cos x & x\\leq 0 \\\\ x^2+3x+1 & x>0 \\end{array}\\right.$.}\r\n\\item  {$\\displaystyle \\lim_{x\\to \\pi/2} f(x)$, where \r\n\r\n$f(x) = \\left\\{\\begin{array}{cl} \\sin x & x\\leq \\pi/2 \\\\ \\cos x & x>\\pi/2 \\end{array}\\right.$.}\r\n\\end{enumerate}\r\n\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\\item {$\\displaystyle \\lim_{x\\to 1} x^2+3x-5$}\r\n\\item {$-5$}\r\n\\item {Limit does not exist}\r\n\\item  {$2$}\r\n\\item {$1.5$}\r\n\\item \r\n{Limit does not exist.}\r\n\\item \r\n{Limit does not exist.}\r\n\\item \r\n{$7$}\r\n\\item \r\n{$1$}\r\n\\item \r\n{Limit does not exist.}\r\n\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\\end{ex}\r\n% % % % % % % % % % % %\r\n\r\n% % % % % % % % % % %\r\n\\begin{ex}\r\nA function $f$ and a value $a$ are given. Approximate the limit of the difference quotient, $\\displaystyle \\lim_{h\\to 0}\\frac{f(a+h)-f(a)}{h}$, using $h = \\pm 0.1, \\pm 0.01$.\r\n\\begin{enumerate}\r\n\\item {$f(x) = -7x+2$,\\quad  $a=3$}\r\n\\item {$f(x) = 9x+0.06$,\\quad  $a=-1$}\r\n\\item {$f(x) = x^2+3x-7$,\\quad  $a=1$}\r\n\\item {$\\displaystyle f(x) = \\frac{1}{x+1}$,\\quad  $a=2$}\r\n\\item {$\\displaystyle f(x) = -4x^2+5x-1$,\\quad  $a=-3$}\r\n\\item {$\\displaystyle f(x) =\\ln x$,\\quad  $a=5$}\r\n\\item {$\\displaystyle f(x) =\\sin x$,\\quad $a=\\pi$} \r\n\\item {$\\displaystyle f(x) =\\cos x$,\\quad  $a=\\pi$}\r\n\r\n\\end{enumerate}\r\n\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\\item \r\n{\\begin{tabular}{cc}\r\n$h$ & $\\frac{f(a+h)-f(a)}{h}$\\\\ \\hline \r\n $-0.1$ & $-7$ \\\\\r\n $-0.01$ & $-7$ \\\\\r\n $0.01$ & $-7$ \\\\\r\n $0.1$ & $-7$\r\n\\end{tabular}\r\nThe limit seems to be exactly 7.\r\n}\r\n\\item \r\n{\\begin{tabular}{cc}\r\n$h$ & $\\frac{f(a+h)-f(a)}{h}$\\\\ \\hline \r\n $-0.1$ & $9$ \\\\\r\n $-0.01$ & $9$ \\\\\r\n $0.01$ & $9$ \\\\\r\n $0.1$ & $9$\r\n\\end{tabular}\r\nThe limit seems to be exactly 9.\r\n}\r\n\\item \r\n{\\begin{tabular}{cc}\r\n$h$ & $\\frac{f(a+h)-f(a)}{h}$\\\\ \\hline \r\n $-0.1$ & $4.9$ \\\\\r\n $-0.01$ & $4.99$ \\\\\r\n $0.01$ & $5.01$ \\\\\r\n $0.1$ & $5.1$\r\n\\end{tabular}\r\nThe limit is approx. 5.\r\n}\r\n\\item \r\n{\\begin{tabular}{cc}\r\n$h$ & $\\frac{f(a+h)-f(a)}{h}$\\\\ \\hline\r\n $-0.1$ & $-0.114943$ \\\\\r\n $-0.01$ & $-0.111483$ \\\\\r\n $0.01$ & $-0.110742$ \\\\\r\n $0.1$ & $-0.107527$\r\n\\end{tabular}\r\nThe limit is approx. $-0.11$.\r\n}\r\n\\item \r\n{\\begin{tabular}{cc}\r\n$h$ & $\\frac{f(a+h)-f(a)}{h}$\\\\ \\hline \r\n $-0.1$ & $29.4$ \\\\\r\n $-0.01$ & $29.04$ \\\\\r\n $0.01$ & $28.96$ \\\\\r\n $0.1$ & $28.6$\r\n\\end{tabular}\r\nThe limit is approx. $29$.\r\n}\r\n\\item \r\n{\\begin{tabular}{cc}\r\n$h$ & $\\frac{f(a+h)-f(a)}{h}$\\\\ \\hline\r\n $ -0.1$ & $0.202027$ \\\\\r\n $-0.01$ & $0.2002$ \\\\\r\n $0.01$ & $0.1998$ \\\\\r\n $0.1$ & $0.198026$\r\n\\end{tabular}\r\nThe limit is approx. $0.2$.\r\n}\r\n\\item \r\n{\\begin{tabular}{cc}\r\n$h$ & $\\frac{f(a+h)-f(a)}{h}$ \\\\ \\hline \r\n $ -0.1$ & $-0.998334$ \\\\\r\n $-0.01$ & $-0.999983$ \\\\\r\n $0.01$ & $-0.999983$ \\\\\r\n $0.1$ & $-0.998334$\r\n\\end{tabular}\r\nThe limit is approx. $-1$.\r\n}\r\n\\item {\\begin{tabular}{cc}\r\n$h$ & $\\frac{f(a+h)-f(a)}{h}$\\\\ \\hline \r\n $-0.1$ & $-0.0499583$ \\\\\r\n $-0.01$ & $-0.00499996$ \\\\\r\n $0.01$ & $0.00499996$ \\\\\r\n $0.1$ & $0.0499583$\r\n\\end{tabular}\r\nThe limit is approx. $0.005$.\r\n}\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\\end{ex}\r\n% % % % % % % % % % % %\r\n\r\n% % % % % % % % % % %\r\n\\begin{ex}\r\n\\begin{enumerate}\r\n\\item {\r\n\\begin{minipage}{\\linewidth}\\centering\r\n\\begin{tikzpicture}\r\n\\begin{axis}[tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,%\r\n%\t\t\txtick={-2,-1,1,2,3},% \r\n%\t\t\tytick={-6,-4,-2,0,2,4,6},\r\n%\t\t\tminor y tick num=1,\r\n%\t\t\textra y ticks={-5,-3,...,7},%\r\n\t\t\tymin=-.1,ymax=2.1,%\r\n\t\t\txmin=-.1,xmax=2.1%\r\n]\r\n\r\n\\addplot [thick,{\\colorone}] coordinates {(0.,1) (1,2)};\r\n\\addplot [{\\colorone},smooth,thick,domain=1:2] {2*(x-2)^2};\r\n\r\n\\fill[black,draw=black] (axis cs:0,1) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:1,2) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:1,1) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:2,0) circle (1.5pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n%\\captionsetup{type=figure}%\r\n%\\caption{Setting up Integration by Parts.}\\label{fig:ibp7}\r\n\\end{minipage}\r\n\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n \\begin{enumerate}\r\n  \\item\t\t$\\ds \\lim_{x\\to 1^-} f(x)$\r\n \\item\t\t$\\ds \\lim_{x\\to 1^+} f(x)$\r\n \\item\t\t$\\ds \\lim_{x\\to 1} f(x)$\r\n \\end{enumerate}\r\n\\end{minipage}\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\\addtocounter{enumii}{3}\r\n\\item\t\t$f(1)$\r\n\\item\t\t$\\ds \\lim_{x\\to 0^-} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 0^+} f(x)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n}\r\n\r\n\\item {\r\n\\noindent\\begin{minipage}{\\linewidth}\\centering\r\n\\begin{tikzpicture}\r\n\\begin{axis}[tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,%\r\n%\t\t\txtick={-2,-1,1,2,3},% \r\n%\t\t\tytick={-6,-4,-2,0,2,4,6},\r\n%\t\t\tminor y tick num=1,\r\n%\t\t\textra y ticks={-5,-3,...,7},%\r\n\t\t\tymin=-.1,ymax=2.1,%\r\n\t\t\txmin=-.1,xmax=2.1%\r\n]\r\n\r\n\\addplot [thick,{\\colorone}] coordinates {(0.,0) (1,1)};\r\n\\addplot [{\\colorone},thick] coordinates {(1,2) (2,0)};\r\n\r\n\\fill[black,draw=black] (axis cs:0,0) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:1,1) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:1,2) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:2,0) circle (1.5pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}\r\n\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\r\n\\item\t\t$\\ds \\lim_{x\\to 1^-} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 1^+} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 1} f(x)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\\addtocounter{enumii}{3}\r\n\\item\t\t$f(1)$\r\n\\item\t\t$\\ds \\lim_{x\\to 2^-} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 2^+} f(x)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n}\r\n\r\n\\item {\r\n\\noindent\\begin{minipage}{\\linewidth}\\centering\r\n\\begin{tikzpicture}\r\n\\begin{axis}[tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,%\r\n%\t\t\txtick={-2,-1,1,2,3},% \r\n%\t\t\tytick={-6,-4,-2,0,2,4,6},\r\n%\t\t\tminor y tick num=1,\r\n%\t\t\textra y ticks={-5,-3,...,7},%\r\n\t\t\tymin=-.1,ymax=2.1,%\r\n\t\t\txmin=-.1,xmax=2.1%\r\n]\r\n\r\n%\\addplot [thick,{\\colorone},smooth,domain=0:.9] {1/(x-1)^2};\r\n%\\addplot [{\\colorone},thick,smooth,domain=1.1:2] {1/(x-1)^2};\r\n\\draw [thick,{\\colorone}] (axis cs:0,0) parabola (axis cs:1,3);\r\n\\draw [thick,{\\colorone}] (axis cs:2,0) parabola (axis cs:1,3);\r\n\\draw [{\\colorone},dashed] (axis cs: 1,2.1) -- (axis cs:1,-.1);\r\n\r\n\\fill[black,draw=black] (axis cs:0,0) circle (1.5pt);\r\n%\\fill[white,draw=black] (axis cs:1,1) circle (1.5pt);\r\n%\\fill[black,draw=black] (axis cs:1,2) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:2,0) circle (1.5pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}\r\n\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\r\n\\item\t\t$\\ds \\lim_{x\\to 1^-} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 1^+} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 1} f(x)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\\addtocounter{enumii}{3}\r\n\\item\t\t$f(1)$\r\n\\item\t\t$\\ds \\lim_{x\\to 2^-} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 0^+} f(x)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n}\r\n\r\n\\item {\r\n\\noindent\\begin{minipage}{\\linewidth}\\centering\r\n\\begin{tikzpicture}\r\n\\begin{axis}[tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,%\r\n%\t\t\txtick={-2,-1,1,2,3},% \r\n%\t\t\tytick={-6,-4,-2,0,2,4,6},\r\n%\t\t\tminor y tick num=1,\r\n%\t\t\textra y ticks={-5,-3,...,7},%\r\n\t\t\tymin=-.1,ymax=2.1,%\r\n\t\t\txmin=-.1,xmax=2.1%\r\n]\r\n\r\n%\\addplot [thick,{\\colorone},smooth,domain=0:.9] {1/(x-1)^2};\r\n%\\addplot [{\\colorone},thick,smooth,domain=1.1:2] {1/(x-1)^2};\r\n\\draw [thick,{\\colorone}] (axis cs:1,0) parabola (axis cs:2,2);\r\n\\draw [thick,{\\colorone}] (axis cs:0,1) -- (axis cs:1,2);\r\n\r\n\\fill[black,draw=black] (axis cs:0,1) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:1,2) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:1,1) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:2,2) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:1,0) circle (1.5pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\r\n\\end{minipage}\r\n\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\r\n\\item\t\t$\\ds \\lim_{x\\to 1^-} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 1^+} f(x)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\\addtocounter{enumii}{2}\r\n\\item\t\t$\\ds \\lim_{x\\to 1} f(x)$\r\n\\item\t\t$f(1)$\r\n%\\item\t\t$\\ds \\lim_{x\\to 2^-} f(x)$\r\n%\\item\t\t$\\ds \\lim_{x\\to 0^+} f(x)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n}\r\n\r\n\\item {\r\n\\noindent\\begin{minipage}{\\linewidth}\\centering\r\n\\begin{tikzpicture}\r\n\\begin{axis}[tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,%\r\n%\t\t\txtick={-2,-1,1,2,3},% \r\n%\t\t\tytick={-6,-4,-2,0,2,4,6},\r\n%\t\t\tminor y tick num=1,\r\n%\t\t\textra y ticks={-5,-3,...,7},%\r\n\t\t\tymin=-.1,ymax=2.1,%\r\n\t\t\txmin=-.1,xmax=2.1%\r\n]\r\n\r\n%\\addplot [thick,{\\colorone},smooth,domain=0:.9] {1/(x-1)^2};\r\n%\\addplot [{\\colorone},thick,smooth,domain=1.1:2] {1/(x-1)^2};\r\n\\draw [thick,{\\colorone}] (axis cs:1,2) parabola (axis cs:0,0);\r\n\\draw [thick,{\\colorone}] (axis cs:1,2) -- (axis cs:2,0);\r\n\r\n\\fill[black,draw=black] (axis cs:0,0) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:1,2) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:2,0) circle (1.5pt);\r\n%\\fill[black,draw=black] (axis cs:2,2) circle (1.5pt);\r\n%\\fill[white,draw=black] (axis cs:1,0) circle (1.5pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\r\n\\end{minipage}\r\n\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\r\n\\item\t\t$\\ds \\lim_{x\\to 1^-} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 1^+} f(x)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\\addtocounter{enumii}{2}\r\n\\item\t\t$\\ds \\lim_{x\\to 1} f(x)$\r\n\\item\t\t$f(1)$\r\n%\\item\t\t$\\ds \\lim_{x\\to 2^-} f(x)$\r\n%\\item\t\t$\\ds \\lim_{x\\to 0^+} f(x)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n}\r\n\r\n\\item {\r\n\\noindent\\begin{minipage}{\\linewidth}\\centering\r\n\\begin{tikzpicture}\r\n\\begin{axis}[tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,%\r\n\t\t\txtick={-4,...,-1,1,2,...,4},% \r\n%\t\t\tytick={-6,-4,-2,0,2,4,6},\r\n%\t\t\tminor y tick num=1,\r\n%\t\t\textra y ticks={-5,-3,...,7},%\r\n\t\t\tymin=-4.5,ymax=4.5,%\r\n\t\t\txmin=-4.5,xmax=4.5%\r\n]\r\n\r\n%\\addplot [thick,{\\colorone},smooth,domain=0:.9] {1/(x-1)^2};\r\n%\\addplot [{\\colorone},thick,smooth,domain=1.1:2] {1/(x-1)^2};\r\n\\addplot [thick,{\\colorone},domain=-4:0] {4*cos(deg(x)*3.14159/4};\r\n\\addplot [thick,{\\colorone},domain=0:4]  {-4*cos(deg(x)*3.14159/4};\r\n%\r\n\\fill[black,draw=black] (axis cs:0,0) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:0,4) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:-4,-4) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:4,4) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:0,-4) circle (1.5pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}\r\n\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\r\n\\item\t\t$\\ds \\lim_{x\\to 0^-} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 0^+} f(x)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\\addtocounter{enumii}{2}\r\n\\item\t\t$\\ds \\lim_{x\\to 0} f(x)$\r\n\\item\t\t$f(0)$\r\n%\\item\t\t$\\ds \\lim_{x\\to 2^-} f(x)$\r\n%\\item\t\t$\\ds \\lim_{x\\to 0^+} f(x)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n}\r\n\r\n\\item {\r\n\\noindent\\begin{minipage}{\\linewidth}\\centering\r\n\\begin{tikzpicture}\r\n\\begin{axis}[tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,%\r\n\t\t\txtick={-4,...,-1,1,2,...,4},% \r\n%\t\t\tytick={-6,-4,-2,0,2,4,6},\r\n%\t\t\tminor y tick num=1,\r\n%\t\t\textra y ticks={-5,-3,...,7},%\r\n\t\t\tymin=-4.5,ymax=4.5,%\r\n\t\t\txmin=-4.5,xmax=4.5%\r\n]\r\n\r\n%\\addplot [thick,{\\colorone},smooth,domain=0:.9] {1/(x-1)^2};\r\n%\\addplot [{\\colorone},thick,smooth,domain=1.1:2] {1/(x-1)^2};\r\n\\addplot [thick,{\\colorone}] coordinates {(-4,0) (-2,2) (0,0) (2,2) (4,0)}; \r\n%\\addplot [thick,{\\colorone},domain=0:4]  {-4*cos(deg(x)*3.14159/4};\r\n%\r\n\\fill[black,draw=black] (axis cs:0,0) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:-4,0) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:-2,0) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:-2,2) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:2,2) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:4,0) circle (1.5pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}\r\n\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\r\n\\item\t\t$\\ds \\lim_{x\\to -2^-} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to -2^+} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to -2} f(x)$\r\n\\item\t\t$f(-2)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\\addtocounter{enumii}{4}\r\n\\item\t\t$\\ds \\lim_{x\\to 2^-} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 2^+} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to 2} f(x)$\r\n\\item\t\t$f(2)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n}\r\n\r\n\r\n\\item {\r\n\\noindent\\begin{minipage}{\\linewidth}\\centering\r\n\\begin{tikzpicture}\r\n\\begin{axis}[tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,%\r\n\t\t\txtick={-4,...,-1,1,2,...,4},% \r\n%\t\t\tytick={-6,-4,-2,0,2,4,6},\r\n%\t\t\tminor y tick num=1,\r\n%\t\t\textra y ticks={-5,-3,...,7},%\r\n\t\t\tymin=-4.5,ymax=4.5,%\r\n\t\t\txmin=-4.5,xmax=4.5%\r\n]\r\n\\draw [thick,{\\colorone}] (axis cs:-4,-4) -- (axis cs:-3,-4);\r\n\\draw [thick,{\\colorone}] (axis cs:-3,-3) -- (axis cs:-2,-3);\r\n\\draw [thick,{\\colorone}] (axis cs:-2,-2) -- (axis cs:-1,-2);\r\n\\draw [thick,{\\colorone}] (axis cs:-1,-1) -- (axis cs:0,-1);\r\n\\draw [thick,{\\colorone}] (axis cs:0,0) -- (axis cs:1,0);\r\n\\draw [thick,{\\colorone}] (axis cs:1,1) -- (axis cs:2,1);\r\n\\draw [thick,{\\colorone}] (axis cs:2,2) -- (axis cs:3,2);\r\n\\draw [thick,{\\colorone}] (axis cs:3,3) -- (axis cs:4,3);\r\n\r\n%\r\n\\fill[black,draw=black] (axis cs:-4,-4) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:-3,-4) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:-3,-3) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:-2,-3) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:-2,-2) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:-1,-2) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:-1,-1) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:0,-1) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:0,0) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:1,0) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:1,1) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:2,1) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:2,2) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:3,2) circle (1.5pt);\r\n\\fill[black,draw=black] (axis cs:3,3) circle (1.5pt);\r\n\\fill[white,draw=black] (axis cs:4,3) circle (1.5pt);\r\n\\end{axis}\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}\r\n\r\nLet $-3\\leq a\\leq 3$ be an integer.\r\n\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\r\n\\item\t\t$\\ds \\lim_{x\\to a^-} f(x)$\r\n\\item\t\t$\\ds \\lim_{x\\to a^+} f(x)$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\noindent\\begin{minipage}[t]{.5\\linewidth}\r\n\\begin{enumerate}\\addtocounter{enumii}{2}\r\n\\item\t\t$\\ds \\lim_{x\\to a} f(x)$\r\n\\item\t\t$f(a)$\\end{enumerate}\r\n\\end{minipage}\r\n}\r\n\r\n\\end{enumerate}\r\n\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\\item {\\begin{enumerate}\r\n\\item\t\t2\r\n\\item\t\t2\r\n\\item\t\t2\r\n\\item\t\t1\r\n\\item\t \tAs $f$ is not defined for $x<0$, this limit is not defined.\r\n\\item\t\t1\r\n\\end{enumerate}}\r\n\\item {\\begin{enumerate}\r\n\\item\t\t1\r\n\\item\t\t2\r\n\\item\t\tDoes not exist.\r\n\\item\t\t2\r\n\\item\t\t0\r\n\\item\t \tAs $f$ is not defined for $x<0$, this limit is not defined.\r\n\\end{enumerate}\r\n}\r\n\\item {\\begin{enumerate}\r\n\\item\t\tDoes not exist.\r\n\\item\t\tDoes not exist.\r\n\\item\t\tDoes not exist.\r\n\\item\t\tNot defined.\r\n\\item\t\t0\r\n\\item\t \t0\r\n\\end{enumerate}\r\n} \r\n\\item {\\begin{enumerate}\r\n\\item\t\t2\r\n\\item\t\t0\r\n\\item\t\tDoes not exist.\r\n\\item\t\t1\r\n\\end{enumerate}\r\n}\r\n\\item {\\begin{enumerate}\r\n\\item\t\t2\r\n\\item\t\t2\r\n\\item\t\t2\r\n\\item\t\t2\r\n\\end{enumerate}\r\n}\r\n\\item {\\begin{enumerate}\r\n\\item\t\t4\r\n\\item\t\t$-4$\r\n\\item\t\tDoes not exist.\r\n\\item\t\t0\r\n\\end{enumerate}\r\n}\r\n\\item {\\begin{enumerate}\r\n\\item\t\t2\r\n\\item\t\t2\r\n\\item\t\t2\r\n\\item\t\t0\r\n\\item\t\t2\r\n\\item\t\t2\r\n\\item\t\t2\r\n\\item\t\tNot defined\r\n\r\n\\end{enumerate}\r\n}\r\n\\item  {\\begin{enumerate}\r\n\\item\t\t$a-1$\r\n\\item\t\t$a$\r\n\\item\t\tDoes not exist.\r\n\\item\t\t$a$\r\n\\end{enumerate}\r\n}\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\\end{ex}\r\n% % % % % % % % % % % %\r\n% % % % % % % % % % %\r\n\\begin{ex}\r\n\\begin{enumerate}\r\n\\item \r\n\\item \r\n\\item \r\n\\item \r\n\\end{enumerate}\r\n\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\\item \r\n\\item \r\n\\item \r\n\\item \r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\\end{ex}\r\n% % % % % % % % % % % %\r\n\r\n\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nUse a calculator to estimate $\\ds\\lim_{x\\to 0}\r\n\\frac{\\sin x}{x}$, where $x$ is in radians.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nUse a calculator to estimate $\\ds\\lim_{x\\to 0}\r\n\\frac{\\tan(3x)}{\\tan(5x)}$, where $x$ is in radians.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nUse a calculator to estimate $\\ds\\lim_{x\\to 1^{+}}\\frac{|x-1|}{1-x^2}$ and $\\ds\\lim_{x\\to 1^{-}}\\frac{|x-1|}{1-x^2}$.\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}\r\n\r\n\\end{multicols}", "meta": {"hexsha": "a8e1f39e4e4890c4e226e8ae79e07ed2266ba35f", "size": 69821, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3-limits/3-1-limits-working-definition.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3-limits/3-1-limits-working-definition.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3-limits/3-1-limits-working-definition.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.4859934853, "max_line_length": 3624, "alphanum_fraction": 0.6246115066, "num_tokens": 28090, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705732, "lm_q2_score": 0.912436167620237, "lm_q1q2_score": 0.8051590950266079}}
{"text": "\\textbf{Let $f(x)=\\sin^3(x/2)$. Compute its Fourier approximation for $N = 20 : 10 : 500$ and plot the error using \\textsl{loglog}. Does this convergence plot agree with the error bound derived in class? Explain.}\n\\newline\n\nThe first thing to notice is that the function is not $2\\pi$-periodic, as we can see in the figure below.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=1]{P4_1.eps}}\n\\caption{Original function $f(x)$.}\n\\end{figure}\n\nHence, we will approximate the error using the following upper bound,\n\\begin{align*}\n\\left|\\mathcal{F}[u](x)-\\mathcal{F}_N[u](x)\\right|\\leq \\frac{2}{m-1}||u^{(m)}||_2\\frac{1}{N^{m-1}}.\n\\end{align*}\nThe theory states that the function $u$, its $m-1$ derivatives and their periodic extensions must be continuous. Therefore we construct the periodic extension of $f$, $f_p(x) = |\\sin^3(x/2)|$, shown below.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=1]{P4_2.eps}}\n\\caption{Periodic extension of $f$.}\n\\end{figure}\n\nWe can easily compute the first three derivatives and check that all of them except the third one are continuous at $x=0$. Thus, $m=3$ and our error is bounded by\n\\begin{align*}\n\\left|\\mathcal{F}[u](x)-\\mathcal{F}_N[u](x)\\right|\\leq ||u^{(m)}||_2\\frac{1}{N^2}\\propto N^{-2}.\n\\end{align*}\n\nHowever, this is a conservative bound. It is no taking into consideration the particular function we are working with. In this case, it is possible to perform one more integreation by parts and the error in fact decays as $N^{-3}$, as show in the figure below.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=1]{P4_3.eps}}\n\\caption{Approximation error and its bound.}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 4\nclear variables; close all; clc\nfigformat='png';\n\n% Plot function\nx0 = -2*pi;\nxf = 2*pi;\nx = chebfun('x',[x0 xf]);\nf = sin(x/2).^3;\n\nfigure\nplot(f,'b-','linewidth',2)\nhold on\nplot([0 0],[-1 1],'r--')\ngrid on\naxis([x0 xf -1 1])\nxlabel('$x$','interpreter','latex')\nylabel('$f(x)=\\sin^3(x/2)$','interpreter','latex')\nset(gca,'fontsize',14)\nset(gca,'XTick',x0:pi/2:xf) \nxticklabels({'-2\\pi','-3\\pi/2','-\\pi','-\\pi/2','0','\\pi/2','\\pi','3\\pi/2','2\\pi'})\ntxt='Latex/FIGURES/P4_1';\nsaveas(gcf,txt,figformat)\n\nx0 = -2*pi;\nxf = 0;\nx = chebfun('x',[x0 xf]);\nfp1 = -sin(x/2).^3;\nx0 = 0;\nxf = 2*pi;\nx = chebfun('x',[x0 xf]);\nfp2 = sin(x/2).^3;\n\nx0 = -2*pi;\nxf = 2*pi;\nfigure\nplot(fp1,'b-','linewidth',2)\nhold on\nplot(fp2,'b-','linewidth',2)\nplot([0 0],[0 1],'r-')\ngrid on\naxis([x0 xf 0 1])\nxlabel('$x$','interpreter','latex')\nylabel('$f_p(x)=|\\sin^3(x/2)|$','interpreter','latex')\nset(gca,'fontsize',14)\nset(gca,'XTick',x0:pi/2:xf) \nxticklabels({'-2\\pi','-3\\pi/2','-\\pi','-\\pi/2','0','\\pi/2','\\pi','3\\pi/2','2\\pi'})\ntxt='Latex/FIGURES/P4_2';\nsaveas(gcf,txt,figformat)\n\n% Approximation and Error\nN = 20:10:500;\nx0 = 0;\nxf = 2*pi;\nx = chebfun('x',[x0 xf]);\nf = sin(x/2).^3;\n\nparfor j = 1:length(N)\n    A = exp(1i*x*(-N(j):N(j)));\n    lambda = 1/(2*pi)*A'*f;\n    fn = A*lambda;\n    err(j) = norm(f-fn,Inf);\nend\n\n% Plot Error\nfigure\nloglog(N,err,'*','MarkerSize',12)\nhold on\nloglog(N,abs(N).^-3,'r-')\ngrid on\n% axis([20 510 1e-10 1e-1])\nxlabel('$N$','interpreter','latex')\nylabel('Error','interpreter','latex')\nset(gca,'fontsize',14)\ntxt='Latex/FIGURES/P4_3';\nsaveas(gcf,txt,figformat)\n\\end{verbatim}", "meta": {"hexsha": "8ef7c1cdfc3bc17f3ac4d530517438d1af5e92d8", "size": 3365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework1/Latex/problem4.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework1/Latex/problem4.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework1/Latex/problem4.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2608695652, "max_line_length": 260, "alphanum_fraction": 0.6493313522, "num_tokens": 1221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.9324533121452495, "lm_q1q2_score": 0.8050723729537684}}
{"text": "\\section{1D transfer matrix and A,B}\r\nWe derive the transfer matrix for a 1D dielectric layer of length $a_1$ and index of refraction $n_1$. The block of material ``1'' is adjacent to another block ``0'' which contains the incident wave. The boundary conditions at each layer edge are that the electric field and the derivative match.\r\n\\begin{equation}\r\n\\begin{gathered}\r\nE_o = E_1\\\\\r\n\\frac{dE_o}{dx} = \\frac{dE_1}{dx}\r\n\\end{gathered}\r\n\\end{equation}\r\nThe general wave function $E=A \\exp(-i k n x) + B \\exp(i k n x)$ and its derivative must match coefficents: $A_o, B_o$ at $x=0$ with $A_1, B_1$ at $x=a_1$.\r\n\\begin{equation}\r\n\\begin{gathered}\r\nA_o + B_o = A_1 \\exp(-i k n_1 a_1) + B_1 \\exp(i k n_1 a_1)\\\\\r\ni k n_o (A_o - B_o) = i k n_1 (A_1 \\exp(-i k n_1 a_1) - B_1 \\exp(i k n_1 a_1))\r\n\\end{gathered}\r\n\\label{eq:match_field_deriv}\r\n\\end{equation}\r\nThe goal is to solve for $A_1$,$B_1$ in terms of $A_0$,$B_0$ and get the general form\r\n\\begin{equation}\r\n\\begin{gathered}\r\nA_1 = A_o T_{11} + B_o T_{12} \\\\\r\nB_1 = A_o T_{21} + B_o T_{22}\r\n\\end{gathered}\r\n\\end{equation}\r\nThe matrix $T$ will be the transfer of field from $A_0$,$B_0$ to $A_1$,$B_1$. First, rewrite Eq.~\\ref{eq:match_field_deriv} as\r\n\\begin{equation}\r\n\\begin{gathered}\r\n(A_o + B_o) \\exp(-i k n_1 a_1) = A_1 \\exp(-2 i k n_1 a_1) + B_1 \\\\\r\ni k n_o (A_o - B_o) \\exp(-i k n_1 a_1) = A_1 \\exp(-2 i k n_1 a_1) - B_1\r\n\\label{fig:terms}\r\n\\end{gathered}\r\n\\end{equation}\r\nThen Eq.~\\ref{fig:terms} sums to\r\n\\begin{equation}\r\n(A_o + B_o) \\exp(-i k n_1 a_1) + \\frac{i k n_o}{i k n_1} (A_o - B_o) \\exp(-i k n_1 a_1) = 2 A_1 \\exp(-2 i k n_1 a_1)\r\n\\end{equation}\r\nSolve for $A_1$ in terms of $A_o$ and $B_o$. The coefficents of $A_o$ and $B_o$ are $T_{11}$ and $T_{12}$.\r\n\\begin{equation}\r\n\\begin{gathered}\r\nT_{11} = \\frac{1}{2} (1 + \\frac{n_o}{n_1} ) \\exp(i k n_1 a_1) \\\\\r\nT_{12} = \\frac{1}{2} (1 - \\frac{n_o}{n_1} ) \\exp(i k n_1 a_1)\r\n\\end{gathered}\r\n\\end{equation}\r\nSimilarly, solve for $B_1$ in terms of $A_o$ and $B_o$. The coefficents of $A_o$ and $B_o$ are $T_{21}$ and $T_{22}$.\r\n\\begin{equation}\r\n\\begin{gathered}\r\nT_{21} = \\frac{1}{2} (1 - \\frac{n_o}{n_1} ) \\exp(-i k n_1 a_1) \\\\\r\nT_{22} = \\frac{1}{2} (1 + \\frac{n_o}{n_1} ) \\exp(-i k n_1 a_1)\r\n\\end{gathered}\r\n\\end{equation}\r\nThese are the matrix elements for the transfer matrix.\r\n\\begin{equation}\r\nT = \\left[\r\n\\begin{array}{cc}\r\n\\frac{1}{2} (1 + \\frac{n_o}{n_1} ) \\exp(i k n_1 a_1) & \\frac{1}{2} (1 - \\frac{n_o}{n_1} ) \\exp(i k n_1 a_1)\\\\\r\n\\frac{1}{2} (1 - \\frac{n_o}{n_1} ) \\exp(-i k n_1 a_1) & \\frac{1}{2} (1 + \\frac{n_o}{n_1} ) \\exp(-i k n_1 a_1)\r\n\\end{array}\r\n\\right]\r\n\\end{equation}\r\n\r\nAs a check, the determinant of $T$ is 1. Physically, this is conservation of flux.\r\n\r\n?Transformation from A,B to the field and its derivative basis gives the following transfer matrix:\r\n\\begin{equation}\r\n\\left[\r\n\\begin{array}{cc}\r\n\\cos(k n x) & \\frac{1}{n}\\sin(k n x) \\\\\r\n-n \\sin(k n x) & \\cos(k n x)\r\n\\end{array}\r\n\\right]\r\n\\end{equation}", "meta": {"hexsha": "9208c0b62f94261c8259fc13ccc44ca69749dc78", "size": 2940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/appendix_1d_transfer_matrix_and_AB_derivation.tex", "max_stars_repo_name": "bhpayne/physics_phd_dissertation", "max_stars_repo_head_hexsha": "646123088fdd226e8677e6f3edb8d109be96994e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/appendix_1d_transfer_matrix_and_AB_derivation.tex", "max_issues_repo_name": "bhpayne/physics_phd_dissertation", "max_issues_repo_head_hexsha": "646123088fdd226e8677e6f3edb8d109be96994e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/appendix_1d_transfer_matrix_and_AB_derivation.tex", "max_forks_repo_name": "bhpayne/physics_phd_dissertation", "max_forks_repo_head_hexsha": "646123088fdd226e8677e6f3edb8d109be96994e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.0, "max_line_length": 297, "alphanum_fraction": 0.6367346939, "num_tokens": 1245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.8050723684424579}}
{"text": "\\chapter{Linear Algebra}\n\\textbf{Definition:} Linear algebra is the branch of mathematics concerning linear equations and their representations through matrices and vector spaces. Linear algebra is central to almost all areas of mathematics.\n\n\\section{Vectors}\n\n\\subsection{Magnitude and direction}\nThe \\textbf{magnitude} of a vector $v=\\vec{PQ}$ is the distance between the initial point P and the end point Q. In symbols the magnitude of $\\vec{PQ}$ is written as $\\Vert\\vec{PQ}\\Vert$:\n\n\\[\n\\Vert \\vec{PQ} \\Vert = \\sqrt{ \\sum_{i=1}^{d} (q_i - p_i)^2}\n\\]\n\n\nIf the point P is the origin, then the magnitude of $v$ is:\n\\[\n\\Vert v \\Vert = \\sqrt{ \\sum_{i=1}^{d} v_i^2 }\n\\]\n\n\nThe \\textbf{direction} of a vector is the measure of the angle it makes with a horizontal line.\nIn $\\mathbb{R}^2$ the direction of $\\vec{PQ}$ with $P=(x_1,y_1)$ and $Q=(x_2,y_2)$ can be calculated with:\n\\[\n\\theta = \\arctan \\left( \\frac{y_2-y_1}{x_2-x_1} \\right)\n\\]\n\nMore generically, the angle between two vectors $\\mathbf{a}$ and $\\mathbf{b}$ can be calculated from the dot product formula:\n\\[\n\\cos(\\theta) = \\frac{ \\mathbf{a} \\cdot \\mathbf{b} }{ \\Vert \\mathbf{a} \\Vert  \\Vert \\mathbf{b} \\Vert }\n\\]\n\n\n\\subsection{Dot product or Scalar product}\nThe dot product of two vectors $\\mathbf{a} = [a_1, a_2, ..., a_n]$ and $\\mathbf{b} = [b_1, b_2, ..., b_n]$ is defined as:\n\n\\[\n\\mathbf{a} \\cdot \\mathbf{b} = \\sum_{i=1}^{n}a_i b_i = a_1 b_1 + a_2 b_2 + ... + a_n b_n\n\\]\n\nThe dot product can also be written as:\n\n\\[ \\mathbf{a} \\cdot \\mathbf{b} =\\mathbf{a} ^{T}\\mathbf {b} \\] \n\nHere, $\\displaystyle \\mathbf {a} ^{T}$ means the transpose of a $\\displaystyle \\mathbf {a} $.\n\nFinally, the dot product of two Euclidean vectors  $\\mathbf{a}$ and $\\mathbf{b}$ is defined by:\n\\[ \n\\mathbf{a} \\cdot \\mathbf{b} = \\Vert \\mathbf{a} \\Vert  \\Vert \\mathbf{b} \\Vert \\cos(\\theta)\n\\] \n\nwhere $\\theta$ is the angle between $\\mathbf{a}$ and $\\mathbf{b}$.\n\n\\section{Vector spaces}\n$\\cal G$ is a group for the operation $\\otimes$ if:\n\\begin{enumerate}\n\t\\item $\\forall a,b\\in{\\cal G}\\Rightarrow a\\otimes b\\in\\cal G$: a group is\n\t{\\it closed}.\n\t\\item $(a\\otimes b)\\otimes c = a\\otimes (b\\otimes c)$: a group is\n\t{\\it associative}.\n\t\\item $\\exists e\\in{\\cal G}$ so that $a\\otimes e=e\\otimes a=a$: there exists a\n\t{\\it unit element}.\n\t\\item $\\forall a\\in{\\cal G}\\exists \\overline{a}\\in{\\cal G}$ so that $a\\otimes\\overline{a}=e$:\n\teach element has an {\\it inverse}.\n\\end{enumerate}\nIf\\\\\n\\hspace*{4.5mm}5. $a\\otimes b=b\\otimes a$\n\nthe group is called {\\it Abelian} or {\\it commutative}.\nVector spaces form an Abelian group for addition and multiplication:\n$1\\cdot\\vec{a}=\\vec{a}$, $\\lambda(\\mu\\vec{a})=(\\lambda\\mu)\\vec{a}$,\n$(\\lambda+\\mu)(\\vec{a}+\\vec{b})=\\lambda\\vec{a}+\\lambda\\vec{b}+\\mu\\vec{a}+\\mu\\vec{b}$.\n\n$W$ is a {\\it linear subspace} if $\\forall \\vec{w}_1,\\vec{w}_2\\in W$\nholds: $\\lambda\\vec{w}_1+\\mu\\vec{w}_2\\in W$.\n\n$W$ is an {\\it invariant subspace} of $V$ for the operator $A$ if\n$\\forall\\vec{w}\\in W$ holds: $A\\vec{w}\\in W$.\n\n\\section{Basis}\nFor an orthogonal basis holds: $(\\vec{e}_i,\\vec{e}_j)=c\\delta_{ij}$. For an\northonormal basis holds:  $(\\vec{e}_i,\\vec{e}_j)=\\delta_{ij}$.\n\nThe set vectors $\\{\\vec{a}_n\\}$ is linear independent if:\n\\[\n\\sum\\limits_i\\lambda_i\\vec{a}_i=0~~\\Leftrightarrow~~\\forall_i\\lambda_i=0\n\\]\nThe set $\\{\\vec{a}_n\\}$ is a basis if it is 1. independent and 2.\n$V=<\\vec{a}_1,\\vec{a_2},...>=\\sum\\lambda_i\\vec{a}_i$.\n\n\\section{Matrix calculus}\n\\subsection{Basic operations}\nFor the matrix multiplication of matrices $A=a_{ij}$ and $B=b_{kl}$ holds\nwith $^r$ the row index and $^k$ the column index:\n\\[\nA^{r_1k_1}\\cdot B^{r_2k_2}=C^{r_1k_2}~~,~~(AB)_{ij}=\\sum_ka_{ik}b_{kj}\n\\]\nwhere $^r$ is the number of rows and $^k$ the number of columns.\n\nThe {\\it transpose} of $A$ is defined by: $a_{ij}^T=a_{ji}$.\nFor this holds $(AB)^T=B^TA^T$ and $(A^T)^{-1}=(A^{-1})^T$. For the\n{\\it inverse matrix} holds: $(A\\cdot B)^{-1}=B^{-1}\\cdot A^{-1}$. The inverse\nmatrix $A^{-1}$ has the property that $A\\cdot A^{-1}= \\mathbb{I}$ and can be found by\ndiagonalization: $(A_{ij}| \\mathbb{I})\\sim( \\mathbb{I}|A_{ij}^{-1})$.\n\nThe inverse of a $2\\times2$ matrix is:\n\\[\n\\left(\\begin{array}{cc}a&b\\\\ c&d\\end{array}\\right)^{-1}=\\frac{1}{ad-bc}\n\\left(\\begin{array}{cc}d&-b\\\\ -c&a\\end{array}\\right)\n\\]\n\nThe {\\it determinant function} $D=\\det(A)$ is defined by:\n\\[\n\\det(A)=D(\\vec{a}_{*1},\\vec{a}_{*2},...,\\vec{a}_{*n})\n\\]\nFor the determinant $\\det(A)$ of a matrix $A$ holds:\n$\\det(AB)=\\det(A)\\cdot\\det(B)$. Een $2\\times2$ matrix has determinant:\n\\[\n\\det\\left(\\begin{array}{cc}a&b\\\\ c&d \\end{array}\\right)=ad-cb\n\\]\nThe derivative of a matrix is a matrix with the derivatives of the coefficients:\n\\[\n\\frac{dA}{dt}=\\frac{da_{ij}}{dt}~~~\\mbox{and}~~~\\frac{dAB}{dt}=B\\frac{dA}{dt}+A\\frac{dB}{dt}\n\\]\nThe derivative of the determinant is given by:\n\\[\n\\frac{d\\det(A)}{dt}=D(\\frac{d\\vec{a}_1}{dt},...,\\vec{a}_n)+\nD(\\vec{a}_1,\\frac{d\\vec{a}_2}{dt},...,\\vec{a}_n)+...+D(\\vec{a}_1,...,\\frac{d\\vec{a}_n}{dt})\n\\]\nWhen the rows of a matrix are considered as vectors the {\\it row rank} of a\nmatrix is the number of independent vectors in this set. Similar for the\n{\\it column rank}. The row rank equals the column rank for each matrix.\n\nLet $\\tilde{A}:\\tilde{V}\\rightarrow\\tilde{V}$ be the complex extension of the\nreal linear operator $A:V\\rightarrow V$ in a finite dimensional $V$.\nThen $A$ and $\\tilde{A}$ have the same caracteristic equation.\n\nWhen $A_{ij}\\in \\mathbb{R}$ and $\\vec{v}_1+i\\vec{v_2}$ is an eigenvector of $A$\nat eigenvalue $\\lambda=\\lambda_1+i\\lambda_2$, than holds:\n\\begin{enumerate}\n\t\\item $A\\vec{v}_1=\\lambda_1\\vec{v}_1-\\lambda_2\\vec{v}_2$ and $A\\vec{v}_2=\\lambda_2\\vec{v}_1+\\lambda_1\\vec{v}_2$.\n\t\\item $\\vec{v}^{~*}=\\vec{v}_1-i\\vec{v}_2$ is an eigenvalue at $\\lambda^*=\\lambda_1-i\\lambda_2$.\n\t\\item The linear span $<\\vec{v}_1,\\vec{v}_2>$ is an invariant subspace of $A$.\n\\end{enumerate}\nIf $\\vec{k}_n$ are the columns of $A$, than the transformed space of $A$ is\ngiven by:\n\\[\nR(A)=<A\\vec{e}_1,...,A\\vec{e}_n>=<\\vec{k}_1,...,\\vec{k}_n>\n\\]\nIf the columns $\\vec{k}_n$ of a $n\\times m$ matrix $A$ are independent, than\nthe nullspace ${\\cal N}(A)=\\{\\vec{0}\\}$.\n\n\\subsection{Matrix equations}\nWe start with the equation\n\\[\nA\\cdot\\vec{x}=\\vec{b}\n\\]\nand $\\vec{b}\\neq\\vec{0}$. If $\\det(A)=0$ the only solution is $\\vec{0}$. If\n$\\det(A)\\neq0$ there exists exactly one solution $\\neq\\vec{0}$.\n\nThe equation\n\\[\nA\\cdot\\vec{x}=\\vec{0}\n\\]\nhas exactly one solution $\\neq\\vec{0}$ if $\\det(A)=0$, and if\n$\\det(A)\\neq0$ the solution is $\\vec{0}$.\n\nCramer's rule for the solution of systems of linear equations is: let the\nsystem be written as\n\\[\nA\\cdot\\vec{x}=\\vec{b}\\equiv\\vec{a}_1x_1+...+\\vec{a}_nx_n=\\vec{b}\n\\]\nthen $x_j$ is given by:\n\\[\nx_j=\\frac{D(\\vec{a}_1,...,\\vec{a}_{j-1},\\vec{b},\\vec{a}_{j+1},...,\\vec{a}_n)}{\\det(A)}\n\\]\n\n\\section{Linear transformations}\nA transformation $A$ is linear if:\n$A(\\lambda\\vec{x}+\\beta\\vec{y})=\\lambda A\\vec{x}+\\beta A\\vec{y}$.\n\nSome common linear transformations are:\n\\begin{center}\n\t\\begin{tabular}{||p{7cm}|p{6cm}||}\n\t\t\\hline\n\t\t\\bf Transformation type & \\bf Equation\\\\\n\t\t\\hline\n\t\t\\hline\n\t\tProjection on the line $<\\vec{a}>$             &$P(\\vec{x})=(\\vec{a},\\vec{x})\\vec{a}/(\\vec{a},\\vec{a})$\\\\\n\t\tProjection on the plane $(\\vec{a},\\vec{x})=0$ &$Q(\\vec{x})=\\vec{x}-P(\\vec{x})$\\\\\n\t\tMirror image in the line $<\\vec{a}>$             &$S(\\vec{x})=2P(\\vec{x})-\\vec{x}$\\\\\n\t\tMirror image in the plane $(\\vec{a},\\vec{x})=0$&$T(\\vec{x})=2Q(\\vec{x})-\\vec{x}=\\vec{x}-2P(\\vec{x})$\\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\nFor a projection holds: $\\vec{x}-P_W(\\vec{x})\\perp P_W(\\vec{x})$ and\n$P_W(\\vec{x})\\in W$.\n\nIf for a transformation $A$ holds: $(A\\vec{x},\\vec{y})=(\\vec{x},A\\vec{y})=(A\\vec{x},A\\vec{y})$,\nthan $A$ is a projection.\n\nLet $A:W\\rightarrow W$ define a linear transformation; we define:\n\\begin{itemize}\n\t\\item If $S$ is a subset of $V$: $A(S):=\\{A\\vec{x}\\in W|\\vec{x}\\in S\\}$\n\t\\item If $T$ is a subset of $W$: $A^\\leftarrow(T):=\\{\\vec{x}\\in V|A(\\vec{x})\\in T\\}$\n\\end{itemize}\nThan $A(S)$ is a linear subspace of $W$ and the {\\it inverse transformation}\n$A^\\leftarrow(T)$ is a linear subspace of $V$. From this follows that $A(V)$ is\nthe {\\it image space} of $A$, notation: ${\\cal R}(A)$. $A^\\leftarrow(\\vec{0})=E_0$\nis a linear subspace of $V$, the {\\it null space} of $A$, notation:\n${\\cal N}(A)$. Then the following holds:\n\\[\n{\\rm dim}({\\cal N}(A))+{\\rm dim}({\\cal R}(A))={\\rm dim}(V)\n\\]\n\n\\section{Plane and line}\nThe equation of a line that contains the points $\\vec{a}$ and $\\vec{b}$ is:\n\\[\n\\vec{x}=\\vec{a}+\\lambda(\\vec{b}-\\vec{a})=\\vec{a}+\\lambda\\vec{r}\n\\]\nThe equation of a plane is:\n\\[\n\\vec{x}=\\vec{a}+\\lambda(\\vec{b}-\\vec{a})+\\mu(\\vec{c}-\\vec{a})=\\vec{a}+\\lambda\\vec{r}_1+\\mu\\vec{r}_2\n\\]\nWhen this is a plane in $ \\mathbb{R}^3$, the {\\it normal vector} to this plane is given\nby:\n\\[\n\\vec{n}_V=\\frac{\\vec{r}_1\\times\\vec{r}_2}{|\\vec{r}_1\\times\\vec{r}_2|}\n\\]\nA line can also be described by the points for which the line equation\n$\\ell$: $(\\vec{a},\\vec{x})+b=0$ holds, and for a plane V: $(\\vec{a},\\vec{x})+k=0$.\nThe normal vector to V is than: $\\vec{a}/|\\vec{a}|$.\n\nThe distance $d$ between 2 points $\\vec{p}$ and $\\vec{q}$ is given by\n$d(\\vec{p},\\vec{q})=\\|\\vec{p}-\\vec{q}\\|$.\n\nIn $ \\mathbb{R}^2$ holds:\nThe distance of a point $\\vec{p}$ to the line $(\\vec{a},\\vec{x})+b=0$ is\n\\[\nd(\\vec{p},\\ell)=\\frac{|(\\vec{a},\\vec{p})+b|}{|\\vec{a}|}\n\\]\nSimilarly in $ \\mathbb{R}^3$:\nThe distance of a point $\\vec{p}$ to the plane $(\\vec{a},\\vec{x})+k=0$ is\n\\[\nd(\\vec{p},V)=\\frac{|(\\vec{a},\\vec{p})+k|}{|\\vec{a}|}\n\\]\nThis can be generalized for $ \\mathbb{R}^n$ and $\\mathbb{C}^n$ (theorem from Hesse).\n\n\\section{Coordinate transformations}\nThe linear transformation $A$ from $\\mathbb{K}^n\\rightarrow\\mathbb{K}^m$ is given by\n($\\mathbb{K}= \\mathbb{R}$ of $\\mathbb{C}$):\n\\[\n\\vec{y}=A^{m\\times n}\\vec{x}\n\\]\nwhere a column of $A$ is the image of a base vector in the original.\n\nThe matrix $A_\\alpha^\\beta$ transforms a vector given w.r.t. a basis\n$\\alpha$ into a vector w.r.t. a basis $\\beta$. It is given by:\n\\[\nA_\\alpha^\\beta=\\left(\\beta(A\\vec{a}_1),...,\\beta(A\\vec{a}_n)\\right)\n\\]\nwhere $\\beta(\\vec{x})$ is the representation of the vector $\\vec{x}$\nw.r.t.\\ basis $\\beta$.\n\nThe {\\it transformation matrix} $S_\\alpha^\\beta$ transforms vectors from\ncoordinate system $\\alpha$ into coordinate system $\\beta$:\n\\[\nS_\\alpha^\\beta:= \\mathbb{I}_\\alpha^\\beta=\\left(\\beta(\\vec{a}_1),...,\\beta(\\vec{a}_n)\\right)\n\\]\nand $S_\\alpha^\\beta\\cdot S_\\beta^\\alpha= \\mathbb{I}$\n\nThe matrix of a transformation $A$ is than given by:\n\\[\nA_\\alpha^\\beta=\\left(A_\\alpha^\\beta\\vec{e}_1,...,A_\\alpha^\\beta\\vec{e}_n\\right)\n\\]\nFor the transformation of matrix operators to another coordinate system holds:\n$A_\\alpha^\\delta=S_\\lambda^\\delta A_\\beta^\\lambda S_\\alpha^\\beta$,\n$A_\\alpha^\\alpha=S_\\beta^\\alpha A_\\beta^\\beta S_\\alpha^\\beta$ and\n$(AB)_\\alpha^\\lambda=A_\\beta^\\lambda B_\\alpha^\\beta$.\n\nFurther is $A_\\alpha^\\beta=S_\\alpha^\\beta A_\\alpha^\\alpha$,\n$A_\\beta^\\alpha=A_\\alpha^\\alpha S_\\beta^\\alpha$. A vector is transformed via\n$X_\\alpha=S_\\alpha^\\beta X_\\beta$.\n\n\\section{Eigen values}\nThe {\\it eigenvalue equation}\n\\[\nA\\vec{x}=\\lambda\\vec{x}\n\\]\nwith {\\it eigenvalues} $\\lambda$ can be solved with\n$(A-\\lambda \\mathbb{I})=\\vec{0}\\Rightarrow\\det(A-\\lambda \\mathbb{I})=0$. The eigenvalues\nfollow from this characteristic equation. The following is true:\n$\\det(A)=\\prod\\limits_i\\lambda_i$ and\n${\\rm Tr}(A)=\\sum\\limits_ia_{ii}=\\sum\\limits_i\\lambda_i$.\n \nThe eigen values $\\lambda_i$ are independent of the chosen basis.\nThe matrix of $A$ in a basis of eigenvectors, with $S$ the transformation matrix\nto this basis, $S=(E_{\\lambda_1},...,E_{\\lambda_n})$, is given by:\n\\[\n\\Lambda=S^{-1}AS={\\rm diag}(\\lambda_1,...,\\lambda_n)\n\\]\nWhen 0 is an eigen value of $A$ than $E_0(A)={\\cal N}(A)$.\n \nWhen $\\lambda$ is an eigen value of $A$ holds: $A^n\\vec{x}=\\lambda^n\\vec{x}$.\n\n\\section{Transformation types}\n\\subsubsection{Isometric transformations}\nA transformation is {\\it isometric} when: $\\|A\\vec{x}\\|=\\|\\vec{x}\\|$. This\nimplies that the eigen values of an isometric transformation are given by\n$\\lambda=\\exp(i\\varphi)\\Rightarrow|\\lambda|=1$. Than also holds:\n$(A\\vec{x},A\\vec{y})=(\\vec{x},\\vec{y})$.\n \nWhen $W$ is an invariant subspace if the isometric transformation $A$ with\ndim$(A)<\\infty$, than also $W^\\perp$ is an invariante subspace.\n\n\\subsubsection{Orthogonal transformations}\nA transformation $A$ is {\\it orthogonal} if $A$ is isometric {\\it and}\nthe inverse $A^\\leftarrow$ exists. For an orthogonal transformation $O$ holds\n$O^TO= \\mathbb{I}$, so: $O^T=O^{-1}$. If $A$ and $B$ are orthogonal, than $AB$ and\n$A^{-1}$ are also orthogonal.\n \nLet $A:V\\rightarrow V$ be orthogonal with dim$(V)<\\infty$. Than $A$ is:\n \n{\\bf Direct orthogonal} if $\\det(A)=+1$. $A$ describes a rotation.\nA rotation in $ \\mathbb{R}^2$ through angle $\\varphi$ is given by:\n\\[\nR=\n\\left(\\begin{array}{cc}\n\\cos(\\varphi)&-\\sin(\\varphi)\\\\\n\\sin(\\varphi)&\\cos(\\varphi)\n\\end{array}\\right)\n\\]\nSo the rotation angle $\\varphi$ is determined by Tr$(A)=2\\cos(\\varphi)$\nwith $0\\leq\\varphi\\leq\\pi$. Let $\\lambda_1$ and $\\lambda_2$ be the roots of\nthe characteristic equation, than also holds:\n$\\Re(\\lambda_1)=\\Re(\\lambda_2)=\\cos(\\varphi)$, and $\\lambda_1=\\exp(i\\varphi)$,\n$\\lambda_2=\\exp(-i\\varphi)$.\n \nIn $ \\mathbb{R}^3$ holds: $\\lambda_1=1$, $\\lambda_2=\\lambda_3^*=\\exp(i\\varphi)$. A\nrotation over $E_{\\lambda_1}$ is given by the matrix\n\\[\n\\left(\\begin{array}{ccc}\n1&0&0\\\\\n0&\\cos(\\varphi)&-\\sin(\\varphi)\\\\\n0&\\sin(\\varphi)&\\cos(\\varphi)\n\\end{array}\\right)\n\\]\n{\\bf Mirrored orthogonal} if $\\det(A)=-1$. Vectors from $E_{-1}$ are mirrored\nby $A$ w.r.t.\\ the invariant subspace $E^\\perp_{-1}$. A mirroring in $ \\mathbb{R}^2$\nin $<(\\cos(\\frac{\\varphi}{2}),\\sin(\\frac{\\varphi}{2}))>$ is given by:\n\\[\nS=\n\\left(\\begin{array}{cc}\n\\cos(\\varphi)&\\sin(\\varphi)\\\\\n\\sin(\\varphi)&-\\cos(\\varphi)\n\\end{array}\\right)\n\\]\nMirrored orthogonal transformations in $ \\mathbb{R}^3$ are rotational mirrorings:\nrotations of axis $<\\vec{a}_1>$ through angle $\\varphi$ and mirror plane\n$<\\vec{a}_1>^\\perp$. The matrix of such a transformation is given by:\n\\[\n\\left(\\begin{array}{ccc}\n-1&0&0\\\\\n0&\\cos(\\varphi)&-\\sin(\\varphi)\\\\\n0&\\sin(\\varphi)&\\cos(\\varphi)\n\\end{array}\\right)\n\\]\nFor all orthogonal transformations $O$ in $ \\mathbb{R}^3$ holds that\n$O(\\vec{x})\\times O(\\vec{y})=O(\\vec{x}\\times\\vec{y})$.\n \n$ \\mathbb{R}^n$ $(n<\\infty)$ can be decomposed in invariant subspaces with dimension\n1 or 2 for each orthogonal transformation.\n\n\\subsubsection{Unitary transformations}\nLet $V$ be a complex space on which an inner product is defined. Than a linear\ntransformation $U$ is {\\it unitary} if $U$ is isometric {\\it and} its inverse\ntransformation $A^\\leftarrow$ exists. A $n\\times n$ matrix is unitary if\n$U^HU= \\mathbb{I}$. It has determinant $|\\det(U)|=1$. Each isometric transformation\nin a finite-dimensional complex vector space is unitary.\n \n{\\bf Theorem}: for a $n\\times n$ matrix $A$ the following statements are\nequivalent:\n\\begin{enumerate}\n\t\\item $A$ is unitary,\n\t\\item The columns of $A$ are an orthonormal set,\n\t\\item The rows of $A$ are an orthonormal set.\n\\end{enumerate}\n\n\\subsubsection{Symmetric transformations}\nA transformation $A$ on $ \\mathbb{R}^n$ is {\\it symmetric} if\n$(A\\vec{x},\\vec{y})=(\\vec{x},A\\vec{y})$. A matrix $A\\in\\mathbb{M}^{n\\times n}$\nis symmetric if $A=A^T$. A linear operator is only symmetric if its matrix\nw.r.t.\\ an arbitrary basis is symmetric. All eigenvalues of a symmetric\ntransformation belong to $ \\mathbb{R}$. The different eigenvectors are mutually\nperpendicular. If $A$ is symmetric, than $A^T=A=A^H$ on an orthogonal basis.\n \nFor each matrix $B\\in\\mathbb{M}^{m\\times n}$ holds: $B^TB$ is symmetric.\n\n\\subsubsection{Hermitian transformations}\nA transformation $H:V\\rightarrow V$ with $V=\\mathbb{C}^n$ is {\\it Hermitian} if\n$(H\\vec{x},\\vec{y})=(\\vec{x},H\\vec{y})$. The {\\it Hermitian conjugated}\ntransformation $A^H$ of $A$ is: $[a_{ij}]^H=[a_{ji}^*]$. An alternative\nnotation is: $A^H=A^\\dagger$. The inner product of two vectors $\\vec{x}$ and\n$\\vec{y}$ can now be written in the form: $(\\vec{x},\\vec{y})=\\vec{x}^H\\vec{y}$.\n \nIf the transformations $A$ and $B$ are Hermitian, than their product $AB$ is\nHermitian if:\\\\ $[A,B]=AB-BA=0$. $[A,B]$ is called the {\\it commutator} of $A$\nand $B$.\n \nThe eigenvalues of a Hermitian transformation belong to $ \\mathbb{R}$.\n \nA matrix representation can be coupled with a Hermitian operator $L$.\nW.r.t.\\ a basis $\\vec{e}_i$ it is given by $L_{mn}=(\\vec{e}_m,L\\vec{e}_n)$.\n\n\\subsubsection{Normal transformations}\nFor each linear transformation $A$ in a complex vector space $V$ there exists\nexactly one linear transformation $B$ so that $(A\\vec{x},\\vec{y})=(\\vec{x},B\\vec{y})$.\nThis $B$ is called the {\\it adjungated transformation} of $A$. Notation:\n$B=A^*$.  The following holds: $(CD)^*=D^*C^*$. $A^*=A^{-1}$ if $A$ is unitary\nand $A^*=A$ if $A$ is Hermitian.\n \n{\\bf Definition}: the linear transformation $A$ is {\\it normal} in a complex\nvector space $V$ if $A^*A=AA^*$. This is only the case if for its matrix $S$\nw.r.t.\\ an orthonormal basis holds: $A^\\dagger A=AA^\\dagger$.\n \nIf $A$ is normal holds:\n\\begin{enumerate}\n\t\\item For all vectors $\\vec{x}\\in V$ and a normal transformation $A$ holds:\n\t\\[\n\t(A\\vec{x},A\\vec{y})=(A^*A\\vec{x},\\vec{y})=(AA^*\\vec{x},\\vec{y})=(A^*\\vec{x},A^*\\vec{y})\n\t\\]\n\t\\item $\\vec{x}$ is an eigenvector of $A$ if and only if $\\vec{x}$ is an\n\teigenvector of $A^*$.\n\t\\item Eigenvectors of $A$ for different eigenvalues are mutually perpendicular.\n\t\\item If $E_\\lambda$ if an eigenspace from $A$ than the orthogonal complement\n\t$E_\\lambda^\\perp$ is an invariant subspace of $A$.\n\\end{enumerate}\nLet the different roots of the characteristic equation of $A$ be $\\beta_i$ with\nmultiplicities $n_i$. Than the dimension of each eigenspace $V_i$ equals\n$n_i$. These eigenspaces are mutually perpendicular and each vector\n$\\vec{x}\\in V$ can be written in exactly one way as\n\\[\n\\vec{x}=\\sum_i\\vec{x}_i~~~\\mbox{with}~~~\\vec{x}_i\\in V_i\n\\]\nThis can also be written as: $\\vec{x}_i=P_i\\vec{x}$ where $P_i$ is a projection\non $V_i$. This leads to the {\\it spectral mapping theorem}: let $A$ be a normal\ntransformation in a complex vector space $V$ with dim$(V)=n$. Than:\n\\begin{enumerate}\n\t\\item There exist projection transformations $P_i$, $1\\leq i\\leq p$, with the\n\tproperties\n\t\\begin{itemize}\n\t\t\\item $P_i\\cdot P_j=0$ for $i\\neq j$,\n\t\t\\item $P_1+...+P_p= \\mathbb{I}$,\n\t\t\\item ${\\rm dim}P_1(V)+...+{\\rm dim}P_p(V)=n$\n\t\\end{itemize}\n\tand complex numbers $\\alpha_1,...,\\alpha_p$ so that\n\t$A=\\alpha_1P_1+...+\\alpha_pP_p$.\n\t\\item If $A$ is unitary than holds $|\\alpha_i|=1~\\forall i$.\n\t\\item If $A$ is Hermitian than $\\alpha_i\\in \\mathbb{R}~\\forall i$.\n\\end{enumerate}\n\n\\subsubsection{Complete systems of commuting Hermitian transformations}\nConsider $m$ Hermitian linear transformations $A_i$ in a $n$ dimensional\ncomplex inner product space $V$. Assume they mutually commute.\n \n{\\bf Lemma}: if $E_\\lambda$ is the eigenspace for eigenvalue $\\lambda$ from\n$A_1$, than $E_\\lambda$ is an invariant subspace of all transformations\n$A_i$. This means that if $\\vec{x}\\in E_\\lambda$, than $A_i\\vec{x}\\in E_\\lambda$.\n \n{\\bf Theorem}. Consider $m$ commuting Hermitian matrices $A_i$. Than there\nexists a unitary matrix $U$ so that all matrices $U^\\dagger A_iU$ are diagonal.\nThe columns of $U$ are the common eigenvectors of all matrices $A_j$.\n \nIf all eigenvalues of a Hermitian linear transformation in a $n$-dimensional\ncomplex vector space differ, than the normalized eigenvector is known except\nfor a phase factor $\\exp(i\\alpha)$.\n \n{\\bf Definition}: a commuting set Hermitian transformations is called\n{\\it complete} if for each set of two common eigenvectors $\\vec{v}_i,\\vec{v}_j$\nthere exists a transformation $A_k$ so that $\\vec{v}_i$ and $\\vec{v}_j$ are\neigenvectors with different eigenvalues of $A_k$.\n \nUsually a commuting set is taken as small as possible. In quantum physics one\nspeaks of commuting observables. The required number of commuting obsieervables\nequals the number of quantum numbers required to characterize a state.\n\n\\section{Homogeneous coordinates}\nHomogeneous coordinates are used if one wants to combine both rotations and\ntranslations in {\\it one} matrix transformation. An extra coordinate is\nintroduced to describe the non-linearities. Homogeneous coordinates are derived\nfrom cartesian coordinates as follows:\n\\[\n\\left(\\begin{array}{c}x\\\\ y\\\\ z\\end{array}\\right)_{\\rm cart}=\n\\left(\\begin{array}{c}wx\\\\ wy\\\\ wz\\\\ w\\end{array}\\right)_{\\rm hom}=\n\\left(\\begin{array}{c}X\\\\ Y\\\\ Z\\\\ w\\end{array}\\right)_{\\rm hom}\n\\]\nso $x=X/w$, $y=Y/w$ and $z=Z/w$. Transformations in homogeneous coordinates\nare described by the following matrices:\n\\begin{enumerate}\n\t\\item Translation along vector $(X_0, Y_0, Z_0, w_0)$:\n\t\\[\n\tT=\\left(\\begin{array}{cccc}\n\tw_0&0&0&X_0\\\\\n\t0&w_0&0&Y_0\\\\\n\t0&0&w_0&Z_0\\\\\n\t0&0&0&w_0\n\t\\end{array}\\right)\n\t\\]\n\t\\item Rotations of the $x,y,z$ axis, resp. through angles $\\alpha,\\beta,\\gamma$:\n\t\\[\n\tR_x(\\alpha)=\\left(\\begin{array}{cccc}\n\t1&0&0&0\\\\\n\t0&\\cos\\alpha&-\\sin\\alpha&0\\\\\n\t0&\\sin\\alpha&\\cos\\alpha&0\\\\\n\t0&0&0&1\n\t\\end{array}\\right)~~~~\n\tR_y(\\beta)=\\left(\\begin{array}{cccc}\n\t\\cos\\beta&0&\\sin\\beta&0\\\\\n\t0&1&0&0\\\\\n\t-\\sin\\beta&0&\\cos\\beta&0\\\\\n\t0&0&0&1\n\t\\end{array}\\right)~~~~\n\t\\]\n\t\\[\n\tR_z(\\gamma)=\\left(\\begin{array}{cccc}\n\t\\cos\\gamma&-\\sin\\gamma&0&0\\\\\n\t\\sin\\gamma&\\cos\\gamma&0&0\\\\\n\t0&0&1&0\\\\\n\t0&0&0&1\n\t\\end{array}\\right)\n\t\\]\n\t\\item A perspective projection on image plane $z=c$ with the center of\n\tprojection in the origin. This transformation has no inverse.\n\t\\[\n\tP(z=c)=\\left(\\begin{array}{cccc}\n\t1&0&0&0\\\\\n\t0&1&0&0\\\\\n\t0&0&1&0\\\\\n\t0&0&1/c&0\n\t\\end{array}\\right)\n\t\\]\n\\end{enumerate}\n\n\\section{Inner product spaces}\nA complex inner product on a complex vector space is defined as follows:\n\\begin{enumerate}\n\t\\item $(\\vec{a},\\vec{b})=\\overline{(\\vec{b},\\vec{a})}$,\n\t\\item $(\\vec{a},\\beta_1\\vec{b}_1+\\beta_2\\vec{b}_2)=\\beta_1(\\vec{a},\\vec{b}_1)+\\beta_2(\\vec{a},\\vec{b}_2)$\n\tfor all $\\vec{a},\\vec{b}_1,\\vec{b}_2\\in V$ and $\\beta_1,\\beta_2\\in\\mathbb{C}$.\n\t\\item $(\\vec{a},\\vec{a})\\geq0$ for all $\\vec{a}\\in V$,\n\t$(\\vec{a},\\vec{a})=0$ if and only if $\\vec{a}=\\vec{0}$.\n\\end{enumerate}\nDue to (1) holds: $(\\vec{a},\\vec{a})\\in \\mathbb{R}$. The {\\it inner product space} $\\mathbb{C}^n$ is\nthe complex vector space on which a complex inner product is defined by:\n\\[\n(\\vec{a},\\vec{b})=\\sum_{i=1}^na_i^*b_i\n\\]\nFor function spaces holds:\n\\[\n(f,g)=\\int\\limits_a^bf^*(t)g(t)dt\n\\]\nFor each $\\vec{a}$ the length $\\|\\vec{a}\\|$ is defined by:\n$\\|\\vec{a}\\|=\\sqrt{(\\vec{a},\\vec{a})}$. The following holds:\n$\\|\\vec{a}\\|-\\|\\vec{b}\\|\\leq\\|\\vec{a}+\\vec{b}\\|\\leq\\|\\vec{a}\\|+\\|\\vec{b}\\|$,\nand with $\\varphi$ the angle between $\\vec{a}$ and $\\vec{b}$ holds:\n$(\\vec{a},\\vec{b})=\\|\\vec{a}\\|\\cdot\\|\\vec{b}\\|\\cos(\\varphi)$.\n \nLet $\\{\\vec{a}_1,...,\\vec{a}_n\\}$ be a set of vectors in an inner product space\n$V$. Than the {\\it Gramian G} of this set is given by: $G_{ij}=(\\vec{a}_i,\\vec{a}_j)$.\nThe set of vectors is independent if and only if $\\det(G)=0$.\n \nA set is {\\it orthonormal} if $(\\vec{a}_i,\\vec{a}_j)=\\delta_{ij}$.\nIf $\\vec{e}_1,\\vec{e}_2,...$ form an orthonormal row in an infinite dimensional\nvector space Bessel's inequality holds:\n\\[\n\\|\\vec{x}\\|^2\\geq\\sum_{i=1}^\\infty|(\\vec{e}_i,\\vec{x})|^2\n\\]\nThe equal sign holds if and only if\n$\\lim\\limits_{n\\rightarrow\\infty}\\|\\vec{x}_n-\\vec{x}\\|=0$.\n \nThe inner product space $\\ell^2$ is defined in $\\mathbb{C}^\\infty$ by:\n\\[\n\\ell^2=\\left\\{\\vec{a}=(a_1,a_2,...)~|~\\sum_{n=1}^\\infty|a_n|^2<\\infty\\right\\}\n\\]\nA space is called a {\\it Hilbert space} if it is $\\ell^2$ and if also holds:\n$\\lim\\limits_{n\\rightarrow\\infty}|a_{n+1}-a_n|=0$.\n\n\\section{The Laplace transformation}\nThe class LT exists of functions for which holds:\n\\begin{enumerate}\n\t\\item On each interval $[0,A]$, $A>0$ there are no more than a finite number of\n\tdiscontinuities and each discontinuity has an upper - and lower limit,\n\t\\item $\\exists t_0\\in[0,\\infty>$ and $a,M\\in \\mathbb{R}$ so that for $t\\geq t_0$\n\tholds: $|f(t)|\\exp(-at)<M$.\n\\end{enumerate}\nThan there exists a Laplace transform for $f$.\n \nThe Laplace transformation is a generalisation of the Fourier transformation.\nThe Laplace transform of a function $f(t)$ is, with $s\\in\\mathbb{C}$ and $t\\geq0$:\n\\[\nF(s)=\\int\\limits_0^\\infty f(t){\\rm e}^{-st}dt\n\\]\nThe Laplace transform of the derivative of a function is given by:\n\\[\n{\\cal L}\\left(f^{(n)}(t)\\right)=-f^{(n-1)}(0)-sf^{(n-2)}(0)-...-s^{n-1}f(0)+s^nF(s)\n\\]\nThe operator $\\cal L$ has the following properties:\n\\begin{enumerate}\n\t\\item Equal shapes: if $a>0$ than\n\t\\[\n\t{\\cal L}\\left(f(at)\\right)=\\frac{1}{a}F\\left(\\frac{s}{a}\\right)\n\t\\]\n\t\\item Damping: ${\\cal L}\\left({\\rm e}^{-at}f(t)\\right)=F(s+a)$\n\t\\item Translation: If $a>0$ and $g$ is defined by $g(t)=f(t-a)$ if\n\t$t>a$ and $g(t)=0$ for $t\\leq a$, than holds:\n\t${\\cal L}\\left(g(t)\\right)={\\rm e}^{-sa}{\\cal L}(f(t))$.\n\\end{enumerate}\nIf $s\\in \\mathbb{R}$ than holds $\\Re(\\lambda f)={\\cal L}(\\Re(f))$ and\n$\\Im(\\lambda f)={\\cal L}(\\Im(f))$.\n \nFor some often occurring functions holds:\n\\begin{center}\n\t\\begin{tabular}{||c||c||}\n\t\t\\hline\n\t\t$f(t)=$&$F(s)={\\cal L}(f(t))=$\\\\\n\t\t\\hline\n\t\t\\hline\n\t\t$\\displaystyle\\frac{t^n}{n!}{\\rm e}^{at}$&$(s-a)^{-n-1}$\\rule{0pt}{15pt}\\\\\n\t\t${\\rm e}^{at}\\cos(\\omega t)$&$\\displaystyle\\frac{s-a}{(s-a)^2+\\omega^2}$\\rule{0pt}{15pt}\\\\\n\t\t${\\rm e}^{at}\\sin(\\omega t)$&$\\displaystyle\\frac{\\omega}{(s-a)^2+\\omega^2}$\\rule{0pt}{15pt}\\\\\n\t\t$\\delta(t-a)$&$\\exp(-as)$\\rule{0pt}{13pt}\\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\n\n\\section{The convolution}\nThe convolution integral is defined by:\n\\[\n(f*g)(t)=\\int\\limits_0^tf(u)g(t-u)du\n\\]\nThe convolution has the following properties:\n\\begin{enumerate}\n\t\\item $f*g\\in$LT\n\t\\item ${\\cal L}(f*g)={\\cal L}(f)\\cdot{\\cal L}(g)$\n\t\\item Distribution: $f*(g+h)=f*g+f*h$\n\t\\item Commutative: $f*g=g*f$\n\t\\item Homogenity: $f*(\\lambda g)=\\lambda f*g$\n\\end{enumerate}\nIf ${\\cal L}(f)=F_1\\cdot F_2$, than is $f(t)=f_1*f_2$.\n\n\\section{Systems of linear differential equations}\nWe start with the equation $\\dot{\\vec{x}}=A\\vec{x}$. Assume that\n$\\vec{x}=\\vec{v}\\exp(\\lambda t)$, than follows: $A\\vec{v}=\\lambda\\vec{v}$.\nIn the $2\\times2$ case holds:\n\\begin{enumerate}\n\t\\item $\\lambda_1=\\lambda_2$: than $\\vec{x}(t)=\\sum\\vec{v}_i\\exp(\\lambda_it)$.\n\t\\item $\\lambda_1\\neq\\lambda_2$: than $\\vec{x}(t)=(\\vec{u}t+\\vec{v})\\exp(\\lambda t)$.\n\\end{enumerate}\nAssume that $\\lambda=\\alpha+i\\beta$ is an eigenvalue with eigenvector $\\vec{v}$,\nthan $\\lambda^*$ is also an eigenvalue for eigenvector $\\vec{v}^*$. Decompose\n$\\vec{v}=\\vec{u}+i\\vec{w}$, than the real solutions are\n\\[\nc_1[\\vec{u}\\cos(\\beta t)-\\vec{w}\\sin(\\beta t)]{\\rm e}^{\\alpha t}+c_2[\\vec{v}\\cos(\\beta t)+\\vec{u}\\sin(\\beta t)]{\\rm e}^{\\alpha t}\n\\]\n \nThere are two solution strategies for the equation $\\ddot{\\vec{x}}=A\\vec{x}$:\n\\begin{enumerate}\n\t\\item Let $\\vec{x}=\\vec{v}\\exp(\\lambda t)\\Rightarrow\\det(A-\\lambda^2 \\mathbb{I})=0$.\n\t\\item Introduce: $\\dot{x}=u$ and $\\dot{y}=v$, this leads to $\\ddot{x}=\\dot{u}$ and\n\t$\\ddot{y}=\\dot{v}$. This transforms a $n$-dimensional set of second order\n\tequations into a $2n$-dimensional set of first order equations. \n\\end{enumerate}\n", "meta": {"hexsha": "b8262bd95923a4b992d5d51559e7799d0036ecf8", "size": 27024, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematics_Formulary/sections/linear_algebra.tex", "max_stars_repo_name": "ufoscout/Physics_notes", "max_stars_repo_head_hexsha": "68e705f1afc087af3161dd2eb5ff556cf3873533", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Mathematics_Formulary/sections/linear_algebra.tex", "max_issues_repo_name": "ufoscout/Physics_notes", "max_issues_repo_head_hexsha": "68e705f1afc087af3161dd2eb5ff556cf3873533", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mathematics_Formulary/sections/linear_algebra.tex", "max_forks_repo_name": "ufoscout/Physics_notes", "max_forks_repo_head_hexsha": "68e705f1afc087af3161dd2eb5ff556cf3873533", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-29T08:25:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-29T08:25:09.000Z", "avg_line_length": 40.2742175857, "max_line_length": 216, "alphanum_fraction": 0.6575636471, "num_tokens": 10098, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.8652240895276224, "lm_q1q2_score": 0.8050548936164433}}
{"text": "\\section{Kinematics}\nDescriptors of linear motion begin with position $\\vec{r}$ and of\nangular motion with $\\theta_q$\n\\begin{align*}\n  \\vec{v} &= d\\vec{r}/dt  & \\vec{\\omega}_q &= d\\theta_q/dt\\\\\n  \\vec{a} &= d\\vec{v}/dt  & \\vec{\\alpha}_q &= d\\vec{\\omega}_q/dt.\n\\end{align*}\n%-%For general acceleration\n%-%\\begin{align*}\n%-%  v_q &= v_{q_0} + \\textstyle\\int_0^t a_q dt  & \\omega_q &= \\omega_{q_0} + \\textstyle\\int_0^t \\alpha_q dt\\\\\n%-%  q &= q_0 + \\textstyle\\int_0^t v_q dt & \\theta_q &= \\theta_{q_0} + \\textstyle\\int_0^t \\omega_q dt.\n%-%\\end{align*}\nFor constant acceleration\n\\begin{align*}\nq &= q_0 + v_{q_0} t + \\tfrac{1}{2}a_q t^2 &\\theta_q &= \\theta_{q_0} + \\omega_{q_0} t + \\tfrac{1}{2}\\alpha_q t^2\\\\\nv_q &= v_{q_0} + a_q t  & \\omega_q &= \\omega_{q_0} + \\alpha_q t\\\\\nv_q^2 &= v_{q_0}^2 + 2a_q(q-q_0)  &  \\omega_q^2 &= \\omega_{q_0}^2 + 2\\alpha_q(\\theta_q-\\theta_{q_0})\\\\\n\\Delta q &= \\tfrac{1}{2}(v_{q_0} + v_q)t  & \\Delta \\theta_q &= \\tfrac{1}{2}(\\omega_{q_0} + \\omega_q)t.\n\\end{align*}\nMomentum, impulse, Newton's first law, and Newton's second law are \n\\begin{align*}\n  \\vec{p} &= m\\vec{v}  & \\vec{L} &= I\\vec{\\omega}\\\\\n  \\vec{J} &= \\Delta \\vec{p}  & \\vec{J} &= \\Delta \\vec{L}\\\\\n  \\vec{F} &= d\\vec{p}/dt  & \\vec{\\tau} &= d\\vec{L}/dt\\\\\n  \\textstyle\\sum \\vec{F} &= m\\vec{a}  & \\textstyle\\sum \\vec{\\tau} &= I\\vec{\\alpha}.\n\\end{align*}\nSymmetry of physical laws with respect to translation and rotation begets\nconservation of momentum\n\\begin{align*}\n  \\vec{p}_1 &= \\vec{p}_2 & \\vec{L}_1 &= \\vec{L}_2.\n\\end{align*}\n\nConnections between linear and angular kinematics start with the definition\nof an angle as the ratio of arc length $s$ to radius $r$\n\\begin{align*}\n  \\theta &= s/r\\\\\n  \\vec{v}_{\\text{tan}} &= \\vec{\\omega} \\times \\vec{r} & \\vec{L} &= \\vec{r} \\times \\vec{p}\\\\\n  \\vec{a}_{\\text{tan}} &= \\vec{\\alpha} \\times \\vec{r} & \\vec{\\tau} &= \\vec{r} \\times \\vec{F}  \n\\end{align*}\n\nMoment of inertia $I$ is a measure of the resistance of a body to change its\nrotational motion and depends on the distribution of mass \\emph{about a\n  particular axis}\n\\begin{align*}\n  I_{\\text{discrete}} &= \\textstyle\\sum_j r_j^2 m_j\\\\\n  I_{\\text{continuous}} &= \\textstyle\\int r^2 dm\n\\end{align*}\nAbout a \\emph{parallel} axis the moment of inertia is related to the\ndistance $d$ from the center of mass\n\\begin{equation*}\n  I = I_{\\text{cm}} + M d^2\n\\end{equation*}\n\n", "meta": {"hexsha": "2824dfc306c15c89c1140fed621d0d4b290f8449", "size": 2351, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_Kinematics-01.tex", "max_stars_repo_name": "tcburt/hodudodi", "max_stars_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_Kinematics-01.tex", "max_issues_repo_name": "tcburt/hodudodi", "max_issues_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-18T22:55:02.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-18T23:01:00.000Z", "max_forks_repo_path": "CheatSheets/Series/Physics/units/unit_UPI_Kinematics-01.tex", "max_forks_repo_name": "tcburt/hodudodi", "max_forks_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.537037037, "max_line_length": 114, "alphanum_fraction": 0.6307954062, "num_tokens": 956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660989095221, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.8050473188728081}}
{"text": "\\chapter{Background}\\label{ch2:background}\nThis chapter gives background concepts and notation used in the rest of the thesis.\n\n\\section{Partially ordered sets}\nThis section recalls basic notions of order theory upon which (much of) the abstract interpretation framework is based. For a more comprehensive introduction to order theory, we refer the reader to a text book, such as for instance \\cite{order-theory-book} or appendix A of \\cite{principles-of-program-analysis-book}.\n\n\\begin{definition}[Partial order]\n\tGiven a set $S$, a partial order $\\preceq$ on $S$ is a binary relation that, for all $a$, $b$ and $c$ in $S$, satisfies\n\t\\begin{itemize}\n\t\t\\labelitem{reflexivity} $a \\preceq a$\n\t\t\\labelitem{antisymmetry} if both $a \\preceq b$ and $b \\preceq a$ then $a = b$\n\t\t\\labelitem{transitivity} if both $a \\preceq b$ and $b \\preceq c$ then also $a \\preceq c$\n\t\\end{itemize}\n\\end{definition}\nWe say that the pair $(S, \\preceq)$ is a partially ordered set, or a \\textit{poset} for short, and we usually write only the carrier set $S$ when the ordering is unambiguous.\n\n\\begin{definition}[Opposite ordering]\n\tGiven a poset $(S, \\preceq)$, the \\textit{opposite} poset $(S, \\preceq^{-1})$ is defined with $a \\preceq^{-1} b$ if and only if $b \\preceq a$.\n\\end{definition}\nWe often use $\\succeq$ to indicate $\\preceq^{-1}$ and $S^{\\op}$ for the carrier set of the opposite poset $(S^{\\op}, \\succeq)$. Hence $S^{\\op} = S$ as sets, but they have different orders defined on them.\n\n\\begin{definition}[Upper bounds and least upper bound]\n\tGiven a poset $S$ and one of its subsets $T \\subseteq S$, an \\textit{upper bound} of $T$ is an element $c \\in S$ that is greater or equal than any element of $T$:\n\t\\[\n\t\\forall a \\in T.\\ a \\preceq c\n\t\\]\n\tThe \\textit{least upper bound} (or lub for short) of $T$, if it exists, is an upper bound of $T$ that is smaller or equal than all other upper bounds of $T$.\n\\end{definition}\nIn general a set $T$ needs not have a least upper bound, but when it does it's unique and we denote it with $\\bigsqcup T$. Moreover, when $T = \\{ a, b \\}$ is made of just two elements, we shall write $a \\sqcup b$ for their least upper bound.\n\nThe dual notion of lub is that of glb:\n\\begin{definition}[Lower bounds and greatest lower bound]\n\tGiven a poset $S$ and one of its subsets $T \\subseteq S$, a \\textit{lower bound} of $T$ is an element $c \\in S$ that is smaller or equal than any element of $T$:\n\t\\[\n\t\\forall a \\in T.\\ c \\preceq a\n\t\\]\n\tThe \\textit{greatest lower bound} (or glb for short) of $T$, if it exists, is a lower bound of $T$ that is greater or equal than all other upper bounds of $T$.\n\\end{definition}\nAgain, if this exists we denote it with $\\bigsqcap T$, and if $T = \\{ a, b \\}$ we use the notation $a \\sqcap b$.\n\n\\begin{definition}[Lattice]\n\tA poset $S$ is called a \\textit{lattice} if every pair of elements has a lub and glb. It is called a \\textit{complete lattice} if every subset has a lub and a glb.\n\\end{definition}\n\nWhen the whole set $S$ has an upper bound, that is an element greater than all other elements, that is unique and we denote it with $\\top_S$, possibly dropping the subscript if the set is clear from the context. Note that $\\top_S$ is the glb of the empty set. Dually, we denote with $\\bot_S$ the lower bound of $S$ (if any), that is an element smaller than all other elements, and this is the lub of $\\emptyset$.\n\n\\begin{definition}[Monotone function]\n\tGiven two poset $S$, $T$, a function $f : S \\rightarrow T$ is called \\textit{monotone} (or \\textit{order-preserving}) if, for any pair $a, b \\in S$ of elements of the domain such that $a \\preceq_S b$, also their images satisfies $f(a) \\preceq_T f(b)$.\n\\end{definition}\n\nGiven a set $S$ and a poset $T$, we can consider the set of functions from $S$ to $T$. This has a natural structure of poset too.\n\\begin{definition}\n\tGiven two functions $f, g: S \\rightarrow T$, we say that $f \\preceq g$ if for all elements $a \\in S$ we have\n\t\\[\n\tf(a) \\preceq g(a)\n\t\\]\n\\end{definition}\nIt's easy to show that this relation among functions is a partial order too. Moreover, if $T$ is a (complete) lattice, the set of functions from $S$ to $T$ is a (complete) lattice too, and this still holds if $S$ is a poset and we restrict ourselves to monotone functions between the two.\n\nAn important example of complete lattice are power sets. Given a set $S$, its power set $\\pow(S)$ with the ordering induced by set inclusion is a complete lattice. A function $f : S \\rightarrow S$ can be lifted to a function on $\\pow(S)$ by taking its \\textit{additive extension}, that correspond to apply $f$ to all elements of the input set: for a set $T \\subseteq S$ we have\n\\[\nf(T) = \\{ f(s) \\svert s \\in T \\}\n\\]\nWe overloaded the notation using the same symbol for both $f$ and its additive extension, but which of the two we're referring to will always be clear from whether the argument is a set or not.\n\n\\section{Galois connections}\nThe main mathematical tool we use to study abstract interpretations are Galois connections, and the special case of Galois insertions. An introduction to Galois connections from an order theoretic point of view can be found in chapter 7 of \\cite{order-theory-book}.\n\n\\begin{definition}[Galois connection]\\label{ch2:def:gc}\n\tLet $C$ and $A$ be two partially ordered sets, and $\\alpha : C \\rightarrow A$, $\\gamma : A \\rightarrow C$ be a pair of monotone functions between the two.\n\n\tWe say $\\gc{C}{\\alpha}{\\gamma}{A}$ is a Galois connection if, for any choice of $c \\in C$ and $a \\in A$ we have\n\t\\[\n\t\\alpha(c) \\preceq a \\iff c \\preceq \\gamma(a)\n\t\\]\n\\end{definition}\nFor our goals, we will call $C$ the \\textit{concrete domain}, $A$ the \\textit{abstract domain}, $\\alpha$ the \\textit{abstraction function} and $\\gamma$ the \\textit{concretization function}. The two functions $\\alpha$ and $\\gamma$ are also called \\textit{adjoints}\\footnote{The term ``adjoint\" comes from Category Theory, since Galois connections are adjunctions between the two posets seen as categories. However such a discussion is outside the scope of this thesis.}.\n\nIn program analysis we give the following intuitive meaning to those. $C$ is the powerset of the domain of concrete states, $A$ the set of abstract properties we're interested in. Partial orders on $C$ and $A$ represent a relation of ``more precise than\": if $a \\preceq a'$ for two abstract elements $a, a' \\in A$, then the meaning is that property $a$ describes less states than $a'$ (it is stronger or \\textit{more precise}). In logical terms, $a \\Rightarrow a'$. Analogously, since $C$ is a powerset and the ordering is set inclusion, a more precise concrete element is just a subset, that describes less individual values. With this interpretation, we can say that if an abstract point $a$ correctly describes the concrete $c$ and $a'$ is above $a$ (ie. $a \\preceq a'$), then also $a'$ correctly describes $c$, even though it's less precise than $a$.\nWith this meaning for partial orders, $\\alpha$ is the function that maps a concrete state in the most precise (ie. strongest or minimal) abstract property that describes it and $\\gamma$ a function that maps an abstract property in the largest (weakest or maximal) concrete state it describes. Since $\\alpha(c)$ is the best (smallest) abstract property describing $c$ we have that a generic $a$ correctly describes $c$ if and only if $\\alpha(c) \\preceq a$. Dually, if $\\gamma(a)$ is the largest concrete element described by $a$ we have that $a$ correctly describes a generic $c$ if and only if $c \\preceq \\gamma(a)$. The Galois connection relation requires exactly these two conditions to be equivalent, as naturally arise when we derive them this way.\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t{\n\t\t\t\\selectfont\n\t\t\t\\def\\svgwidth{.8\\textwidth}\n\t\t\t\\input{images/gc1.pdf_tex}\n\t\t}\n\t\t\\caption{The Galois connection relation}\n\t\t\\label{ch2:fig:gc-sketch:relation}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t{\n\t\t\t\\selectfont\n\t\t\t\\def\\svgwidth{.8\\textwidth}\n\t\t\t\\input{images/gc2.pdf_tex}\n\t\t}\n\t\t\\caption{Composing $\\alpha$ and $\\gamma$}\n\t\t\\label{ch2:fig:gc-sketch:gamma-alpha-c}\n\t\\end{subfigure}\n\t\\caption{Graphical sketch of a Galois connection}\n\t\\label{ch2:fig:gc-sketch}\n\\end{figure}\nFigure \\ref{ch2:fig:gc-sketch} sketches a Galois connection: the lower adjoint $\\alpha$ is bent down, and the upper adjoint $\\gamma$ is bent up.\nFigure \\ref{ch2:fig:gc-sketch:relation} represents the relation required by the Galois connection. Figure \\ref{ch2:fig:gc-sketch:gamma-alpha-c} shows what happens when abstracting and then concretizing back and element (formalized in Proposition \\ref{ch2:th:gc-extensive-charact}): the result is above the initial concrete element. This represent over-approximation: the biggest set described by the property $\\alpha(c)$ must contains at least the whole $c$, because it's over-approximating it.\n\nTo give an intuition of the role of Galois connections in program analysis, we present the following example.\n\\begin{example}[Intervals]\\label{ch2:ex:intervals}\n\tWe can now formalize the intuitive Example \\ref{intr:ex:intervals} of intervals from the Introduction.\n\t$C$ is the set of possible values of a variable, for instance \\code{i}. Since this is an integer value, elements of $C$ are subsets of $\\setZ$, so $C = \\pow(\\setZ)$, with the ordering given by set inclusion. $A$ is the set of abstract properties we track in our analysis, so in our example the set of intervals to which \\code{i} may belong. This means\n\t\\[\n\tA = \\Int = \\{ [n, m] \\svert n \\in \\setZ \\cup \\{ -\\infty \\}, m \\in \\setZ \\cup \\{ +\\infty \\}, n \\le m \\} \\cup \\{ [+\\infty, -\\infty] \\}\n\t\\]\n\t$\\alpha$ is the function that allows us to abstract a set $S$ of possible values of \\code{i} to the best (ie. most precise) possible abstract property:\n\t\\begin{align*}\n\t\t\\alpha(S) &= [\\min(S); \\max(S)]\n\t\\end{align*}\n\twith the convention that $\\min(\\emptyset) = +\\infty$, $\\min(\\emptyset) = -\\infty$, the minimum of a lower-unbound set is $-\\infty$ and the maximum of an upper-unbound set is $+\\infty$. This abstraction function is exactly what we expect: no smaller interval can describe the set $S$, since $\\min(S)$ and $\\max(S)$ are elements of $S$ and hence must also be in the interval. Conversely, this is a correct abstraction of $S$ since all its elements are between $\\min(S)$ and $\\max(S)$, so are in the interval too.\n\n\t$\\gamma$ is the function that does the inverse operation: given an interval $[n, m]$, thought as a formal writing that describes the property that the value of \\code{i} is between $n$ and $m$, gives back its ``meaning\", that is the largest subset of $\\setZ$ that matches that property:\n\t\\[\n\t\\gamma([n, m]) = \\{ x \\in \\setZ \\svert n \\le x \\le m \\}\n\t\\]\n\tThe set $\\{ x \\in \\setZ \\svert n \\le x \\le m \\}$ is exactly what is commonly represented with $[n; m]$: $\\gamma$ is simply translating the formal writing (or, in our context, an abstract property) to a semantic set of values.\n\n\tThe above definition of $\\gamma$ is incomplete, missing cases for infinite ends:\n\t\\begin{align*}\n\t\t\\gamma([-\\infty, m]) &= \\{ x \\in \\setZ \\svert x \\le m \\} \\\\\n\t\t\\gamma([n, +\\infty]) &= \\{ x \\in \\setZ \\svert n \\le x \\} \\\\\n\t\t\\gamma([-\\infty, +\\infty]) &= \\setZ \\\\\n\t\t\\gamma([+\\infty, -\\infty]) &= \\emptyset\n\t\\end{align*}\n\n\tShowing that $\\gc{\\pow(\\setZ)}{\\alpha}{\\gamma}{\\Int}$ is a Galois connection is just a straightforward check. Fixed $S \\in \\pow(\\setZ)$ and the interval $[n, m] \\in \\Int$ (for simplicity, we assume both $n$ and $m$ finite) we have\n\t\\begin{align*}\n\t\t& \\alpha(S) \\preceq [n, m] \\\\\n\t\t\\iff &[\\min(S); \\max(S)] \\preceq [n, m] \\\\\n\t\t\\iff &n \\le \\min(S),\\, \\max(S) \\le m \\\\\n\t\t\\iff &\\forall x \\in S\\ .\\ n \\le x,\\, \\forall x \\in S\\ .\\ x \\le m \\\\\n\t\t\\iff &S \\subseteq \\{ x \\in \\setZ \\svert n \\le x \\le m \\} \\\\\n\t\t\\iff &S \\subseteq \\gamma([n, m])\n\t\\end{align*}\n\\end{example}\nWe recall here two properties of Galois connections.\n\\begin{prop}\\label{ch2:th:gc-extensive-charact}\n\tLet $C$ and $A$ be two partially ordered sets, and $\\alpha : C \\rightarrow A$, $\\gamma : A \\rightarrow C$ be a pair of monotone functions between the two.\n\tThen $\\gc{C}{\\alpha}{\\gamma}{A}$ is a Galois connection if and only if both $\\id_C \\preceq \\gamma \\circ \\alpha$ and $\\alpha \\circ \\gamma \\preceq \\id_A$.\n\\end{prop}\n\\begin{prop}\\label{ch2:th:gc-adjoints-preserve-glb-lub}\n\tLet $\\gc{C}{\\alpha}{\\gamma}{A}$ be a Galois connection. Then $\\gamma$ preserves greatest lower bounds and $\\alpha$ preserves least upper bounds.\n\\end{prop}\nIn particular, this means that $\\gamma$ maps $\\top_A$ in $\\top_C$ (because they are glb of the empty set) and dually $\\alpha$ maps $\\bot_C$ in $\\bot_A$.\n\nIn a Galois connection it may very well happen that two abstract elements have the same concretization, as shown in the following example:\n\\begin{example}[Product abstraction]\n\tConsider two concrete domains, for instance two copies of $\\pow(\\setZ)$ that describes the possible states of two different variables \\code{x} and \\code{y} that appear in the program.\n\tThen consider the Galois connection $\\gc{\\pow(\\setZ)}{\\alpha}{\\gamma}{\\Int}$, and suppose we want to use it to abstract both variables. If we abstract separately both the element of $\\pow(\\setZ_x)$ and that of $\\pow(\\setZ_y)$ (where subscripts indicates the variable the domain refers to), we get a pair of intervals, one for \\code{x} and one for \\code{y}, that is an element of $\\Int_x \\times \\Int_y$. It's easy to check that this abstraction function defines a Galois connection between $\\pow(\\setZ_x \\times \\setZ_y)$ and $\\Int_x \\times \\Int_y$.\n\n\tHowever, this abstraction has redundant elements: consider\n\t\\begin{align*}\n\t\t(\\bot, [n, m]) && ([n, m], \\bot) && (\\bot, \\bot)\n\t\\end{align*}\n\twhere $\\bot = [+\\infty, -\\infty]$ describes the empty interval. All these elements are concretized in the concrete $\\emptyset \\in \\pow(\\setZ_x \\times \\setZ_y)$.\n\\end{example}\n\nWe would like not to have those since they are different elements of the abstract domain that describes the same property. In analogy with logic, this is the same kind of redundancy as the possibility to describe the empty set in the following three different ways:\n\\begin{align*}\n\\{ (x, y) \\svert x \\in \\emptyset, n \\le y \\le m \\}\n&&\n\\{ (x, y) \\svert n \\le x \\le m, y \\in \\emptyset \\}\n&&\n\\{ (x, y) \\svert x \\in \\emptyset, y \\in \\emptyset \\}\n\\end{align*}\n\nIn order to avoid this issue, we require $\\gamma$ to be injective, so that no two different abstract elements can be concretized into the same concrete element, ie. they describe the same property. This turns out to give rise to an interesting definition, that of Galois insertion.\n\\begin{definition}[Galois insertion]\\label{ch2:def:gi}\n\tLet $\\gc{C}{\\alpha}{\\gamma}{A}$ be a Galois connection. We say this is a \\textit{Galois insertion} if $\\gamma$ is injective.\n\\end{definition}\n\nThe one proposed above isn't the standard definition of Galois insertion: more commonly, it requires $\\alpha \\circ \\gamma$ to be identity on the abstract domain $\\id_A$. However, the two are equivalent, as shown by the following characterization of Galois insertions.\n\\begin{prop}\\label{ch2:th:gi-charact}\n\tLet $\\gc{C}{\\alpha}{\\gamma}{A}$ be a Galois connection. Then the following are equivalent:\n\t\\begin{enumerate}[label={(\\arabic*)}]\n\t\t\\item $\\alpha \\circ \\gamma = \\id_A$\n\t\t\\item $\\alpha$ is surjective\n\t\t\\item $\\gamma$ is injective\n\t\\end{enumerate}\n\\end{prop}\n\nThe interval domain presented above is an example of Galois insertion: since we required $n \\le m$ in $[n, m]$, no two intervals describe the same concrete set, and hence $\\gamma$ is injective. However not all Galois connections are insertions: as we've seen, composing two independent interval domains gives rise to a Galois connection that isn't an insertion.\n\nIn a Galois insertion, since $\\gamma$ is injective, we have a bijection between $A$ and $\\gamma(A)$. By the definition of Galois insertion we have $\\alpha \\circ \\gamma = \\id_A$, hence $\\alpha$ is the inverse of $\\gamma$ when restricted to $\\gamma(A)$. Since both functions are monotone this defines an isomorphism of posets between $A$ and $\\gamma(A) \\subseteq C$.\n\nUsing this isomorphism, whenever we consider a Galois insertion we identify $A$ and its image, so that $A$ becomes a subset of $C$ and $\\gamma = \\id_A$. In this case, by Proposition \\ref{ch2:th:gc-extensive-charact} we have $\\id_C \\preceq \\gamma \\circ \\alpha = \\alpha$, corresponding to the intuitive idea that $\\alpha$ must abstract a set of states in something bigger in order to over-approximate it.\n\nA Galois insertion is said to be trivial if $A$ is the concrete domain or it only contains $\\bot$: in the former the analysis isn't abstracted at all, and in the latter it can't track any property of concrete states.\n\nNote that this identification simplifies notation, but introduces a pitfall: reasoning as above we may be tempted to say that also $\\alpha = \\alpha \\circ \\gamma \\preceq \\id_A$, always by Proposition \\ref{ch2:th:gc-extensive-charact}, so concluding that $\\id \\preceq \\alpha \\preceq \\id$ and hence $\\alpha = \\id$. However here we're neglecting the fact that $\\gamma = \\id_A$, not the identity on the whole set $C$, and actually $\\gamma$ is defined only on elements of $A \\subseteq C$. This means that the above relation is indeed correct, but only for elements of $A$, as pointed out by the fact that $\\alpha \\preceq \\id_A$ and not $\\id_C$. This is a problem that arise in general with this notation: two functions that looks the same are actually different because of their domain, that isn't specified. We'll make sure to always clarify the domain whenever it's not uniquely determined by the context.\n\nLastly, we recall a constructive way to define a Galois insertion.\n\\begin{prop}\\label{ch2:th:gi-moore-family}\n\tLet $C$ be a complete lattice, and $\\bar{A} \\subseteq C$ a \\textit{Moore family}, that is a subset such that\n\t\\begin{itemize}\n\t\t\\item $\\bigsqcup C = \\top \\in \\bar{A}$\n\t\t\\item for any subset $T \\subseteq \\bar{A}$ of the Moore family, $\\bigsqcap T \\in \\bar{A}$\n\t\\end{itemize}\n\tLet also\n\t\\[\n\t\\alpha(x) = \\bigsqcap \\{ a \\in \\bar{A} \\svert x \\preceq a \\}\n\t\\]\n\tThen $\\gi{C}{\\alpha}{\\bar{A}}$ is a Galois insertion.\n\\end{prop}\n\n\\section{Under-approximation Galois connections}\nThe definition of Galois connection is not symmetric, in the sense that it puts $\\gamma$ above and $\\alpha$ below: in fact the two are also called upper and lower adjoints, respectively. This asymmetry favours one specific direction, that is over-approximations, and is not suited to describe under-approximations. It can be more easily seen from $\\id_C \\preceq \\gamma \\circ \\alpha$, that means the abstraction of a concrete element $c$ is greater than (ie. an over-approximation of) $c$ itself.\nFor this reason we introduce the notion of under-approximation Galois connection. Even though it's mathematically equivalent to that of Galois connection, we believe it allows a better notation, helping the reader's intuition.\n\\begin{definition}[Under-approximation Galois connection]\\label{ch2:def:under-gc}\n\tLet $C$ and $A$ be two partially ordered sets, and $\\alpha : C \\rightarrow A$, $\\gamma : A \\rightarrow C$ be a pair of monotone functions between the two.\n\n\tWe say $\\ugc{C}{\\alpha}{\\gamma}{A}$ is an under-approximation Galois connection if, for any choice of $c \\in C$ and $a \\in A$ we have\n\t\\[\n\ta \\preceq \\alpha(c) \\iff \\gamma(a) \\preceq c\n\t\\]\n\\end{definition}\nThis definition is the same as that of Galois connection (\\ref{ch2:def:gc}) except that here $\\alpha$ is above and $\\gamma$ below. Since we are in an under-approximation setting, an abstract property correctly describes a concrete element if it is below it. Again, if $\\alpha(c)$ is the best abstract property describing $c$, this is formalized as $a \\preceq \\alpha(c)$, or dually as $\\gamma(c) \\preceq a$, yielding the definition.\n\\begin{figure}[ht]\n\t\\centering\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t{\n\t\t\t\\selectfont\n\t\t\t\\def\\svgwidth{.8\\textwidth}\n\t\t\t\\input{images/ugc1.pdf_tex}\n\t\t}\n\t\t\\caption{The under-approximation Galois connection relation}\n\t\t\\label{ch2:fig:ugc-sketch:relation}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t{\n\t\t\t\\selectfont\n\t\t\t\\def\\svgwidth{.8\\textwidth}\n\t\t\t\\input{images/ugc2.pdf_tex}\n\t\t}\n\t\t\\caption{Composing $\\alpha$ and $\\gamma$}\n\t\t\\label{ch2:fig:ugc-sketch:gamma-alpha-c}\n\t\\end{subfigure}\n\t\\caption{Graphical sketch of an under-approximation Galois connection}\n\t\\label{ch2:fig:ugc-sketch}\n\\end{figure}\n\nFigure \\ref{ch2:fig:ugc-sketch} shows an under-approximation Galois connection: $\\alpha$, that in this case in the upper adjoint, is bent up and $\\gamma$ is bent down. Figure \\ref{ch2:fig:ugc-sketch:relation} sketches the relation required, dual to that of normal Galois connections, and Figure \\ref{ch2:fig:ugc-sketch:gamma-alpha-c} shows what happens when abstracting and then concretizing back an element: the result her is below the initial concrete element, meaning under-approximation.\n\\begin{example}\\label{ch2:ex:intervals-0}\n\tConsider the following example of under-approximation Galois insertion (we haven't given its definition yet, but we're confident the reader can anticipate it): the concrete domain is $\\pow(\\setZ)$, while the abstract domain is the set of all intervals (see Example \\ref{ch2:ex:intervals}) containing $0$, plus the empty interval:\n\t\\[\n\t\\Int_0 = \\{ I \\in \\Int \\svert 0 \\in I \\} \\cup \\{ \\bot \\}\n\t\\]\n\twhere we used $\\bot$ to represent the empty interval $[+\\infty, -\\infty]$.\n\t$\\gamma$ is the identity since we want an (under-approximation) Galois insertion, and $\\alpha(S)$ is the greatest interval fully contained in $S$ that includes $0$. Formally,\n\t\\begin{align*}\n\t\t\\alpha(S) = \\bigcup \\{ I \\in \\Int_0 \\svert I \\subseteq S \\}\n\t\\end{align*}\n\tThe result is in $\\Int_0$: if it isn't empty, it does indeed contain $0$, since is the union of intervals in $\\Int_0$ that contains $0$ themselves. Moreover it is an interval because union of overlapping intervals is an interval too, and all those intervals intersect at $0$.\n\n\tTo show this is an under-approximation Galois connection, fix a set $S \\subseteq \\setZ$ and an interval $[-m, n]$ with $n, m \\ge 0$.\n\tNow the following chain of equivalences hold:\n\t\\begin{align*}\n\t\t&[-m, n] \\subseteq \\alpha(S) \\\\\n\t\t\\iff &[-m, n] \\subseteq \\bigcup \\{ I \\in \\Int_0 \\svert I \\subseteq S \\} \\\\\n\t\t\\iff &[-m, 0] \\subseteq S, [0, n] \\subseteq S \\\\\n\t\t\\iff &\\gamma([-m, n]) = [-m, n] \\subseteq S\n\t\\end{align*}\n\thence the one proposed is an under-approximation Galois insertion.\n\n\tFor simplicity we neglected the case where the interval is $\\bot$ and assumed both $n, m$ are non negative integers, but those cases are analogous to the one presented.\n\\end{example}\nWith this definition, we could easily prove results analogous to Propositions \\ref{ch2:th:gc-extensive-charact} and \\ref{ch2:th:gc-adjoints-preserve-glb-lub} and give an analogous definition of under-approximation Galois insertion.\nInstead of doing this explicitly, we just observe that an under-approximation Galois connection $\\ugc{C}{\\alpha}{\\gamma}{A}$ is just a Galois connection between opposite domain $\\gc{C^{\\op}}{\\alpha}{\\gamma}{A^\\op}$ to get those propositions just reversing inequalities:\n\\begin{prop}\\label{ch2:th:under-gc-extensive-charact}\n\tLet $C$ and $A$ be two partially ordered sets, and $\\alpha : C \\rightarrow A$, $\\gamma : A \\rightarrow C$ be a pair of monotone functions between the two.\n\n\tThen $\\ugc{C}{\\alpha}{\\gamma}{A}$ is an under-approximation Galois connection if and only if $\\gamma \\circ \\alpha \\preceq \\id_C$ and $\\id_A \\preceq \\alpha \\circ \\gamma$.\n\\end{prop}\nFrom this proposition we have that $\\gamma \\circ \\alpha \\preceq \\id_C$, that is the abstraction of an element $c$ is lower than (ie. an under-approximation of) $c$ itself.\n\n\\begin{prop}\\label{ch2:th:under-gc-adjoints-preserve-lub-glb}\n\tLet $\\ugc{C}{\\alpha}{\\gamma}{A}$ be an under-approximation Galois connection. Then $\\gamma$ preserves least upper bounds and $\\alpha$ preserves greatest lower bounds.\n\\end{prop}\n\nThis second proposition has an interesting corollary for under-approximation Galois connection. Of course its dual holds for standard Galois connection, but we use it mainly in the under-approximation case.\n\\begin{corollary}\\label{ch2:th:under-gc-union-closure}\n\tLet $\\ugc{\\pow(C)}{\\alpha}{\\gamma}{A}$ be an under-approximation Galois connection. If $a, a' \\in A$ then\n\t\\[\n\t\\gamma(a \\sqcup a') = \\gamma(a) \\cup \\gamma(a')\n\t\\]\n\\end{corollary}\n\nThis corollary states that $A$ is closed under union: in an under-approximation Galois insertion, where $\\gamma = \\id_A$, for any pair of sets $S, S' \\subseteq C$ that are in $A$ (ie. they are abstract properties) we have that also $S \\cup S' \\in A$.\n\nWe can also get an under-approximation version of Proposition \\ref{ch2:th:gi-moore-family} to define a Galois insertion from an opposite Moore family:\n\\begin{prop}\\label{ch2:th:under-gi-moore-family}\n\tLet $C$ be a complete lattice, and $\\bar{A} \\subseteq C$ a subset such that\n\t\\begin{itemize}\n\t\t\\item $\\bigsqcap C = \\bot \\in \\bar{A}$\n\t\t\\item for any subset $T \\subseteq \\bar{A}$ also $\\bigsqcup T \\in \\bar{A}$\n\t\\end{itemize}\n\tLet also\n\t\\[\n\t\\alpha(x) = \\bigsqcup \\{ a \\in \\bar{A} \\svert a \\preceq x \\}\n\t\\]\n\tThen $\\ugi{C}{\\alpha}{\\bar{A}}$ is an under-approximation Galois insertion.\n\\end{prop}\n\n\\begin{example}\n\tConsider a slight variation of the previous example, intervals that contains at least one of $0$ and $1$.\n\t\\[\n\t\\Int_{0,1} = \\{ I \\in \\Int \\svert 0 \\in \\Int \\lor 1 \\in \\Int \\} \\cup \\{ \\bot \\}\n\t\\]\n\tTo show this is an under-approximation Galois insertion, we use Proposition \\ref{ch2:th:under-gi-moore-family} above.\n\t$\\emptyset$, the bottom element of $\\pow(\\setZ)$ is in $\\Int_{0,1}$ by definition. In $\\pow(\\setZ)$, lubs are unions, so it's enough to show that union of intervals in $\\Int_{0,1}$ is still in $\\Int_{0,1}$.\n\tConsider a set $T \\subseteq \\Int_{0,1}$ of intervals containing either $0$ or $1$. If $T = \\{ \\bot \\}$ then $\\bigcup T = \\emptyset \\in \\Int_{0,1}$, and whenever $T$ contains at least one non empty element the union of its elements is the same whether the empty set is in $T$ or not, so we can assume that $\\bot \\notin T$.\n\n\tLet $T_0$ be the set of intervals in $T$ containing $0$ and $T_1$ the set of those containing $1$. If $T_0$ (respectively $T_1$) is not empty, the union of its elements is an interval containing $0$ (resp. $1$) too because all its elements are interval that intersect at $0$ (resp. $1$). If both are empty also $T$ is empty, hence $\\bigcup T = \\emptyset$ that is in $\\Int_{0,1}$. If one of the two is empty, say $T_1$, then $\\bigcup T = \\bigcup T_0$ that is an interval containing $0$, hence in $\\Int_{0,1}$ too. Lastly, if neither is empty, we have\n\t\\[\n\t\\bigcup T = \\left( \\bigcup T_0 \\right) \\cup \\left( \\bigcup T_1 \\right)\n\t\\]\n\tbut the former is an interval containing $0$, and the latter is an interval containing $1$, hence their union is still an interval that contains both $0$ and $1$ and so is in $\\Int_{0,1}$.\n\\end{example}\n\n\\section{Abstracting functions}\nOnly defining abstract domains is useless because we want to analyse \\textit{programs}, dynamic entities that change the state. Hence the need for a way to abstract functions, used to represent the semantics of programs.\n\nGiven a monotone function $f : C \\rightarrow C$ on the concrete domain, we want a way to approximate its behaviour in the abstract. In over approximation, we want to make sure the abstract version outputs at least an over-approximation of the concrete one to ensure soundness.\n\\begin{definition}[Correct abstraction]\n\tA monotone function $f^{\\sharp} : A \\rightarrow A$ on the abstract domain is called a \\textit{correct abstraction} of $f$ if\n\t\\[\n\t\\alpha \\circ f \\preceq f^{\\#} \\circ \\alpha\n\t\\]\n\tThe function\n\t\\[\n\tf^{\\alpha} = \\alpha \\circ f \\circ \\gamma\n\t\\]\n\tis called the best abstraction of $f$.\n\\end{definition}\nThe best abstraction takes it names from the fact that it's lower than all other correct abstractions of $f$. Intuitively, the best we can do to soundly abstract a function $f$ is first to concretize the input in the optimal way with $\\gamma$, then compute the concrete $f$ on it and lastly abstract again the result with $\\alpha$.\n\\begin{example}\n\tGoing back to the Example \\ref{ch2:ex:intervals} of intervals, consider the program fragment\n\\begin{minted}{C}\nif (x < 0) {\n\tx = -x;\n}\n\\end{minted}\n\tIt's semantics is the additive extension of the absolute value, that is\n\t\\[\n\tf(S) = \\{ \\abs{x} \\svert x \\in S \\}\n\t\\]\n\ton the concrete domain $\\pow(\\setZ)$. A correct abstraction of this function is\n\t\\[\n\tf^{\\sharp}([n, m]) = [0, \\max(\\abs{n}, \\abs{m})]\n\t\\]\n\tbecause the interval $[0, \\max(\\abs{n}, \\abs{m})]$ always contains the entire set $f(S)$ when $n = \\min(S)$ and $m = \\max(S)$. However this is not the best possible abstraction: for instance on $S = \\{ 1 \\}$ this yields $[0, 1]$ while $f(S) = \\{ 1 \\}$. Actually the best correct abstraction $f^{\\alpha}$ is computed as\n\t\\[\n\tf^{\\alpha}([n, m]) = \\alpha \\circ f \\circ \\gamma([n, m]) = \\begin{cases*}\n\t\t[0, \\max(\\abs{n}, \\abs{m})] &if $n \\le 0 \\le m$ \\\\\n\t\t[n, m] &if $0 < n$ \\\\\n\t\t[-m, -n] &if $m < 0$ \\\\\n\t\\end{cases*}\n\t\\]\n\\end{example}\nIn this example, we computed the semantics of the whole program fragment and then we proceeded to abstract it. However this process is not what happens in practice because, if we knew the concrete semantics of the program we wouldn't really need the abstraction. An analyser would instead know abstractions of basic transfer functions, the semantics of basic construct of the language, and compose them in order to get a \\textit{correct} approximation, but with no guarantee to get the \\textit{best} abstraction. In this thesis we won't concern ourselves with this issue because we focus on basic transfer functions; however the reason we're allowed to do so is exactly that those are the basic building blocks used to define the abstract semantics of complex programs.\n\n\\begin{example}\n\tConsider for instance\n\t\\[\n\tf(S) = \\{ x \\% 2 \\svert x \\in S \\}\n\t\\]\n\twhere $\\%$ is the modulo operator.\n\tIt's best abstraction in the interval domain is\n\t\\[\n\tf^{\\alpha}([n, m]) = \\begin{cases*}\n\t\t[0, 0] &if $n = m$ is even \\\\\n\t\t[1, 1] &if $n = m$ is odd \\\\\n\t\t[0, 1] &otherwise\n\t\\end{cases*}\n\t\\]\n\tand this introduces a precision loss: for instance on $S = \\{ 1, 3 \\}$ we have\n\t\\[\n\t[1, 1] = \\alpha(f(S)) \\prec f^{\\alpha}(\\alpha(S)) = f^{\\alpha}([1, 3]) = [0, 1]\n\t\\]\n\\end{example}\n\nIn under-approximation, the definition of correct abstraction simply reverse inequality, as expected, but as notation we use $f^{\\flat}$ for a correct under-approximation abstraction instead of $f^{\\sharp}$.\n\\begin{example}\n\tConsider the under-approximation domain $\\Int_0$ of intervals containing 0 (see Example \\ref{ch2:ex:intervals-0}) and again the absolute value operation\n\t\\[\n\tf(S) = \\{ \\abs{x} \\svert x \\in S \\}\n\t\\]\n\tIn this case it's best abstraction is\n\t\\[\n\tf^{\\alpha}([n, m]) = [0, \\max(\\abs{n}, \\abs{m})]\n\t\\]\n\tsince it's always the case that $n \\le 0 \\le m$.\n\\end{example}\n\nIt is important to remark that, both in over and under-approximation, with Galois insertions we have\n\\[\nf^{\\alpha} = \\alpha \\circ f \\circ \\gamma = \\alpha \\circ f \\circ \\id_A\n\\]\nthat may lead to say $f^{\\alpha} = \\alpha \\circ f$. However, as we observed above, this is not the case since they have different domains: $f^{\\alpha}$ takes as input abstract elements only, while $\\alpha \\circ f$ can be applied to any element of $C$. We'll ensure this condition is satisfied whenever we use $f^{\\alpha}$, often because we'll consider $f^{\\alpha} \\circ \\alpha$.\n\nAn important notion in abstract interpretation is that of complete abstraction \\cite{giacobazzi-making-abstr-complete}. A correct abstraction of a function is said to be complete if it doesn't lose precision with respect to the concrete semantics.\n\\begin{definition}[Complete abstraction]\\label{ch2:def:complete-abstr}\n\tGiven a function $f$ and one of its correct abstractions $f^{\\#}$, we say that it is a \\textit{complete abstraction} when\n\t\\[\n\t\\alpha \\circ f = f^{\\#} \\circ \\alpha\n\t\\]\n\\end{definition}\nThere is some interest in complete abstractions \\cite{giacobazzi-making-abstr-complete,giacobazzi-analyzing-analyses,bruni-abst-intensionality} because they avoid false alarms, but in this thesis we're just interested in it as a way of constraining an abstract domain to interact with a function. We refer the reader to the discussion in the next chapter for an explanation of why we need this.\n", "meta": {"hexsha": "c0c17e263f1995003f4228b39ff479ce3cff48df", "size": 32406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/background.tex", "max_stars_repo_name": "flavio-a/master-thesis", "max_stars_repo_head_hexsha": "9f23d79c205b82ca22106890dd297e64ce10c878", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/background.tex", "max_issues_repo_name": "flavio-a/master-thesis", "max_issues_repo_head_hexsha": "9f23d79c205b82ca22106890dd297e64ce10c878", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/background.tex", "max_forks_repo_name": "flavio-a/master-thesis", "max_forks_repo_head_hexsha": "9f23d79c205b82ca22106890dd297e64ce10c878", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.7914691943, "max_line_length": 901, "alphanum_fraction": 0.7179843239, "num_tokens": 9549, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.9073122113355092, "lm_q1q2_score": 0.8049715618324902}}
{"text": "%---------------------------Aspect Ratio-----------------------------\n\\section{Aspect Ratio\\label{s:quad-aspect-ratio}}\n\nThe aspect ratio of a quadrilateral is: \n\\[\nq = \\frac{L_{\\max}(L_0+L_1+L_2+L_3)}{4A},\n\\]\nwhere $A$ is the area of the quadrilateral. \n\nNote that, strictly speaking, the aspect ratio is usually defined for\nsimplicial elements as the ratio of the maximum edge length to the\ninradius (\\emph{cf.}~\\S\\ref{s:tri-aspect-ratio} and\n~\\S\\ref{s:tet-aspect-ratio}). However, a planar quadrilateral does not\nhave, in general, an inscribed circle: such an incircle exists if and\nonly if $L_0+L_2=L_1+L_3$. Nonetheless, using the expression\nof the triangle aspect ratio as given\nin~\\eqref{eq:triangle_aspect_ratio}, that is, with no explicit\nreference to the inradius but only to the perimeter and the area, one\ncan then directly extrapolate to obtain a meaningful definition of the\nquadrangle aspect ratio.\n\n\\trimetrictable{aspect ratio}%\n{$1$}%                                                Dimension\n{$[1,1.3]$}%                                          Acceptable range\n{$[1,DBL\\_MAX]$}%                                     Normal range\n{$[1,DBL\\_MAX]$}%                                     Full range\n{$1$}%                                                Unit square\n{\\cite{pebay:04}}%                                    Reference(s)                   \n{v\\_quad\\_aspect\\_ratio}%                             Verdict function name\n\n", "meta": {"hexsha": "7635140420693f3217da9c85a39f9fb4ddbd8ed4", "size": 1442, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadAspectRatio.tex", "max_stars_repo_name": "Lin1225/vtk_v5.10.0", "max_stars_repo_head_hexsha": "b54ac74f4716572862365fbff28cd0ecb8d08c3d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-06-01T00:15:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T10:49:02.000Z", "max_issues_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadAspectRatio.tex", "max_issues_repo_name": "Armand0s/homemade_vtk", "max_issues_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-17T11:40:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T21:23:25.000Z", "max_forks_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadAspectRatio.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 46.5161290323, "max_line_length": 85, "alphanum_fraction": 0.567961165, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.8740772269642949, "lm_q1q2_score": 0.804841280820286}}
{"text": "\n\n\\subsection{Bounded sequences}\n\nA function \\(f(x)\\) on set \\(X\\) is bounded if:\n\n\\(\\exists M\\in \\mathbb{R} [\\forall x\\in X f(x)\\le M]\\)\n\nA bounded sequence is a special case of a bounded function where:\n\n\\(X=\\mathbb{N}\\)\n\nThat is, a sequence is bounded by \\(M\\) iff:\n\n\\(\\forall n\\in \\mathbb{R} |f(a_n)|\\le M\\)\n\n", "meta": {"hexsha": "95653d84c897b2c3eb7c33a3ccb4167fe643f174", "size": 313, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sequences/05-01-Bounded.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sequences/05-01-Bounded.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sequences/05-01-Bounded.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.4117647059, "max_line_length": 65, "alphanum_fraction": 0.6357827476, "num_tokens": 106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067179697695, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.8048185132249811}}
{"text": "% Here we show the equation alignment examples from: \n% http://www.orcomplete.com/quick-tip/sertalpbilal/latex-templates-for-optimization-models\n\n\\documentclass[a4paper]{article}\n\n\\usepackage[english]{babel}\n\\usepackage[utf8x]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{hyperref}\n\n\\title{LaTeX Templates for Optimization Models}\n%\\author{Sertalp Bilal \u00c7ay}\n% Modified by Zhiyang Ong to reflect the contributions of John Hammersley, who provided the LaTeX document, and Vince Knight, who made a suggestion for typesetting mathematical optimization models in LaTeX.\n\\author{Sertalp Bilal {\\c{C}}ay and John Hammersley}\n\n\n\n\\begin{document}\n\\maketitle\n\n\\begin{abstract}\nHere we show the equation alignment examples from:\\\\ \\url{http://www.orcomplete.com/quick-tip/sertalpbilal/latex-templates-for-optimization-models}\n\\end{abstract}\n\n\\section{Array} % Example 1\n\n\\begin{equation}\n\\begin{array}{rrclcl}\n\\displaystyle \\min_{x} & \\multicolumn{3}{l}{c^T x} \\\\\n\\textrm{s.t.} & A x & \\leq & b \\\\\n&\\displaystyle \\sum_{i=0}^{n} x_i & = & 1 \\\\\n& x_j & \\geq & 0 & & \\forall j \\in N \\\\\n\\end{array}\n\\end{equation}\n\n\\section{Aligned} % Example 2\n\n\\begin{equation}\n\\begin{aligned}\n& \\underset{x}{\\text{min}}\n& & c^T x \\\\\n& \\text{s.t.} & &  Ax \\leq b_i \\\\\n& & &  \\sum_{i=1}^{n} x_i =1 \\\\\n& & &  x_j, \\; \\forall j \\in N. \\\\\n\\end{aligned}\n\\end{equation}\n\n\\section{Matrix} % Example 3\n\n\\begin{equation}\n\\begin{matrix}\n\\displaystyle \\min_x & c^T x  \\\\\n\\textrm{s.t.} & A x & \\leq & b  \\\\\n& \\displaystyle \\sum_{i=1}^{n} x_i & = & 1  \\\\\n& x_j & \\geq & 0 & & \\forall j \\in N\n\\end{matrix}\n\\end{equation}\n\n\\section{Align} % Example 4\n\n\\begin{align*}\n\\min_x \\quad c^T x \\\\\nAx &\\leq b \\\\\n\\sum_{i=1}^n x_i &= 1\\\\\nx_j &\\geq 0 \\quad \\forall j \\in N\n\\end{align*}\n\n\n\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{Acknowledgements}\n\\label{sec:Acknowledgements}\n\n\nJohn Hammersley provided the LaTeX document; hence, Zhiyang Ong modified the author list to reflect this. In addition, Vince Knight made a suggestion for typesetting mathematical optimization models in \\LaTeX, which is incorporated by John Hammersley.\n\n\n\n\\end{document}", "meta": {"hexsha": "a013b9098bf430f0033eaea1f8d0b0f132724a6e", "size": 2107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/examples/from-other-peeps/optimization-templates/main.tex", "max_stars_repo_name": "eda-ricercatore/SienaLaTeX", "max_stars_repo_head_hexsha": "e28cb49843420f4292071fb1fbdc5a7af0ff20aa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-04-29T20:15:12.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-29T20:15:12.000Z", "max_issues_repo_path": "notes/examples/from-other-peeps/optimization-templates/main.tex", "max_issues_repo_name": "eda-ricercatore/SienaLaTeX", "max_issues_repo_head_hexsha": "e28cb49843420f4292071fb1fbdc5a7af0ff20aa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-10-19T20:55:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-25T15:16:14.000Z", "max_forks_repo_path": "notes/examples/from-other-peeps/optimization-templates/main.tex", "max_forks_repo_name": "eda-ricercatore/SienaLaTeX", "max_forks_repo_head_hexsha": "e28cb49843420f4292071fb1fbdc5a7af0ff20aa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2016-04-16T04:32:01.000Z", "max_forks_repo_forks_event_max_datetime": "2016-04-16T04:32:01.000Z", "avg_line_length": 25.3855421687, "max_line_length": 251, "alphanum_fraction": 0.6810631229, "num_tokens": 698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.9136765304654121, "lm_q1q2_score": 0.8047636153919626}}
{"text": "\\section{Random Triangles in High Dimensions}\n\nFor a triangle $\\Delta$, we will let $\\mathcal{Q}$ be a measure of the \\textit{quality} of the triangle as defined by\n\\begin{equation}\n\\label{eq:triangle_score}\n\\mathcal{Q}(\\Delta) = \\frac{4\\sqrt{3} A}{ \\ell_1^2 + \\ell_2^2 + \\ell_3^2}\n\\end{equation}\nwhere $A$ is the area of the triangle, and $\\ell_1$, $\\ell_2$ and $\\ell_3$ are the lengths of the three sides.\nWithout performing any computations, can you determine the maximum and minimum values that $\\mathcal{Q}$ can take? Can you describe what kinds of triangles are associated with high, and with low, values of $\\mathcal{Q}$?\n\nIn the first part of this project, you will write a function that computes the quality of a triangle in $\\mathbb{R}^2$, given the coordinates of its vertices.\n\n\\begin{itemize}\n  \\item Write a function, \\texttt{tri\\_lengths()}, that takes as its arguments the three vertices of a triangle and returns the lengths of the three sides of the triangle.  \n  \\item Write a function, \\texttt{tri\\_angles()}, that takes as its arguments the three vertices of a triangle and returns the angles of the triangle.\n  \\item Write a function, \\texttt{tri\\_area()}, that takes as its arguments the three vertices of a triangle and returns the area of the triangle.\n  \\item Write a function, \\texttt{tri\\_score()}, that takes as its arguments the three vertices of a triangle and returns the quality score of the triangle as defined in equation (\\ref{eq:triangle_score}). \n  \\item Test your function \\texttt{tri\\_score()} on the four triangles below. As a check on your function, the correct values are:\n\\begin{align*}\n\t\\mathcal{Q}({\\color{green}{\\Delta}}) &= 0.597\\cdots,\n&\t\\mathcal{Q}({ \\color{blue}{\\Delta}}) &= 0.413\\cdots,\\\\\n\t\\mathcal{Q}({\\color{red}{\\Delta}}) &=0.172\\cdots , \n&\t\\mathcal{Q}({ \\color{purple}{\\Delta}}) &= 1.\n\\end{align*}\n\\end{itemize}\n\n\\begin{center}\n\\begin{tikzpicture}[scale = 1.8]\n  \\draw[ultra thick,red!60!white] (0,0)node[below] {$(0,0)$} -- (-1.5,.5)node[above]{$(-3,1)$} -- (1,0)node[right]{$(2,0)$} --cycle;\n  \\draw[ultra thick, green!60!black] (-0.5,1.5)node[left] {$(-5,0)$} -- (2,1.5)node[right]{$(0,0)$} -- (2,.5)node[right]{$(0,-2)$} -- cycle;\n  \\draw[ultra thick, red!50!blue!80] (3,-.5)node[above left] {$-1,0$} -- (4,-.5)node[above right] {$(1,0)$} -- (3.5,.2)node[above]{$(0,\\sqrt{3})$} -- cycle;\n  \\draw[ultra thick, blue!80!black] (5,0)node[below]{$(0,0)$} -- (4.8,2)node[left]{$(-0.5,4)$} -- (5.2,2)node[right]{$(0.5,4)$} -- cycle;\n\\end{tikzpicture}\n\\end{center}\n\nMany applied mathematicians regularly work with data sets where each data point is associated with many different features (e.g. each medical patient is associated with their own temperature, heart rate, blood pressure, etc). \nSometimes the physical, three-dimensional world can provide useful intuition for the geometry of higher dimensional space. Most of the time, however, we are unable to grasp all the weird ways that the higher dimensional space is `bigger'. \n\nIn the second part of this project, you will compare the expected quality of random triangles in $\\mathbb{R}^2$ with that of random triangles in $\\mathbb{R}^{10}$.\n\\begin{enumerate}[(a)]\n  \\item \n  \\begin{enumerate}[i.]\n    \\item Use a random number generator to create a random point, \\(\\bm{x} = (x_1,x_2)\\), that is normally distributed in $\\mathbb{R}^2$. The functions \\texttt{randn()} (Matlab), \\texttt{np.random.randn()} (Python), or \\texttt{randn()} (Julia) may be useful.\n    \\item Repeat part i. until you have three points, $\\bm{x} = (x_1,x_2)$, \\(\\bm{y} = (y_1,y_2)\\), and \\(\\bm{z} = (z_1,z_2)\\). Let $\\Delta$ be the triangle with $\\bm{x}$, $\\bm{y}$, and $\\bm{z}$ as its vertices. Use your function \\texttt{tri\\_score()} to compute $\\mathcal{Q}(\\Delta)$.\n    \\item Repeat parts i. and ii. until you have the quality scores for 100,000 random triangles. Plot a histogram of your data.\n  \\end{enumerate}\n  \\item Repeat this process for triangles in $\\mathbb{R}^{10}$. That is, use a multivariate normal random number generator to generate 3 points in $\\mathbb{R}^{10}$, $\\bm{x} = (x_1,x_2,\\dots x_{10})$, $\\bm{y} = (y_1,y_2,\\dots,y_{10})$, $\\bm{z} = (z_1,z_2, \\dots, z_{10})$. Let $\\Delta$ be the triangle with $\\bm{x}$, $\\bm{y}$, and $\\bm{z}$ as its vertices, and compute $\\mathcal{Q}(\\Delta)$. Repeat for 100,000 random triangles.\n \\item Compare the histogram for triangles in $\\mathbb{R}^2$ with a histogram for triangles in $\\mathbb{R}^{10}$.  Provide a geometric explanation for why the random triangles in higher dimensions are much closer to equilateral than the random triangles in lower dimensions\n\\end{enumerate}\n", "meta": {"hexsha": "3d333ae5daab23dcd9cb3ca557d097c287980c91", "size": 4618, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "random-triangles-high-dimensions.tex", "max_stars_repo_name": "colinlclark/integration_workshop", "max_stars_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "random-triangles-high-dimensions.tex", "max_issues_repo_name": "colinlclark/integration_workshop", "max_issues_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "random-triangles-high-dimensions.tex", "max_forks_repo_name": "colinlclark/integration_workshop", "max_forks_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-07-25T18:18:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-27T01:10:02.000Z", "avg_line_length": 92.36, "max_line_length": 428, "alphanum_fraction": 0.6948895626, "num_tokens": 1468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.8807970670261976, "lm_q1q2_score": 0.8047636041038732}}
{"text": "\\chapter{DT Convolution}\n\n\\section{Review DT LTI systems and superposition property}\n\nRecall the superposition property of LTI systems. If a DT system is LTI then the superposition property holds. Given a system where\n\\[   \nx_i[n] \\mapsto y_i[n] \\; \\forall\\; i\n\\]\nthen\n\\[\n\\sum\\limits_{i} a_i x_i[n] \\mapsto \\sum\\limits_{i} a_i y_i[n] \n\\]\n\nAs in CT we can use superposition to enable a problem reduction strategy in DT systems, where we write the input as a weighted sum of simple signals.  In this lecture, the simple signals are weighted, time shifts of one signal, the DT delta function, $\\delta[n]$.\n\n\\section{Convolution Sum}\n\nTo derive this we start with the sifting property of the DT impulse function (from lecture 3)\n\\[\n\\sum\\limits_{a}^{b} x[n]\\delta[n-n_0] = x[n_0]\n\\]\nfor any $a < n_0 < b$. A slight change of variables ($n_0 \\rightarrow m$) and limits ($a \\rightarrow -\\infty$ and $b \\rightarrow \\infty$) gives:\n\\[\nx[n] = \\sum\\limits_{m = -\\infty}^{\\infty} x[m]\\delta[n-m]\n\\]\nshowing that we can write any DT signal as an infinite sum of weighted and time-shifted impluse functions.\n\nLet $h[n]$ be the DT {\\it impulse response}, the output due to the input $\\delta[n]$, i.e. $\\delta[n] \\mapsto h[n]$. Then if the system is time-invariant: $\\delta[n-m] \\mapsto h[n-m]$ and by superposition, if the input is writen as\n\\[\nx[n] = \\sum\\limits_{m = -\\infty}^{\\infty} x[m]\\delta[n-m]\n\\]\nthen the output is given by\n\\[\ny[n] = \\sum\\limits_{m = -\\infty}^{\\infty} x[m]h[n-m] = x[n] * h[n]\n\\]\nThis is called the \\emph{convolution sum} \\index{DT Convolution}.\n\nThe significance is similar to that in CT convolution. For a LTI DT system, if I know it's impulse response $h[n]$, I can find the response due to \\textbf{any} input using convolution. For this reason the impulse response is another way to represent an LTI system.\n\n\\section{Graphical View of the Convolution Sum.}\n\nLets break the convolution expression down into pieces. In it's general form the convolution of two signals $x_1[n]$ and $x_2[n]$ is\n\\[\nx_1[n] * x_2[n] = \\sum\\limits_{m = -\\infty}^{\\infty} x_1[m]x_2[n-m]\n\\]\n\nSuppose $x_1[n]$ and $x_2[n]$ are signals that look like\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/dtconvolution-explain1.pdf}\n\\end{center}\n\nThen $x_1[m]$ and $x_2[-m]$ look like\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/dtconvolution-explain2.pdf}\n\\end{center}\n\nThe signal $x_2[n-m]$ is $x_2[-m]$ shifted by $n$ (since $x_2[-m+n]= x_s[n-m]$) and looks like\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/dtconvolution-explain3.pdf}\n\\end{center}\n\nThen the terms of the convolution sum is the product $x_1[m]x_2[n-m]$ whose plot depends of the value of $n$. Some examples, where the individual signals are in grey and their product is in bold:\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/dtconvolution-explain4.pdf}\n\\end{center}\n\nThen convolution is the total sum of the product (bold plots above) for that value of $n$. For the example above we see the sum will be zero for $n$ less than $n_0$ since the two signals do not overlap and their product is zero. For $n_0 \\leq n \\leq n_1$ the signals overap and the product is non-zero, and the effective bounds of summation are $[n_0,n]$. For $n > n_1$ the signals again overap and the product is non-zero, but the effective bounds of summation are $[n_0,n_1]$. \n\n\\section{DT Convolution of Finite-Length Signals}\n\nFor finite-length signals, DT convolution gives us an algorithm to determine their convolution. Suppose the signal $x_1$ is non-zero only over the interval $[N_1,M_1]$, and the signal $x_2$ is non-zero only over the interval $[N_2,M_2]$. The \\emph{length} of the signals are $L_1 = M_1-N_1+1$ and $L_2 = M_2-N_2+1$ respectively. The non-zero terms of the convolution sum (when the signals overlap) is then the range $[N_1+N_2,M_1+M_2]$ and the sum can be truncated as:\n\n\\[\nx_1[n] * x_2[n] = \\sum\\limits_{m = N_1+N_2}^{M_1+M_2} x_1[m]x_2[n-m]\n\\]\n\nIt is common to shift both signals so that they both start at index $0$ (in order to be represented as arrays in a zero-based index programming language like C or C++), zero-padding them both to have length $L=L_1+L_2-1$ (zero-pad means to just add zero values to the end of the sequence). Then the convolution becomes\n\\[\ny = x_1 * x_2 = \\sum\\limits_{m = 0}^{L} x_1[m]x_2[n-m]\n\\]\nwhere the indexing of $x_2$ is modulo the signal length, i.e. $x_2[(n-m) \\mbox{ mod } L]$. The resulting signal after convolution, $y$, is also of length $L$, and can then be shifted back to start at $N_1+N_2$.\n\n\\begin{example} The following C++ code computes the convolution of the DT signals $\\{1,-1,1\\}$ and $\\{1,1,1,1\\}$.\n\\begin{verbatim}\n  double x1[6] = {1., -1., 1., 0, 0, 0};\n  double x2[6] = {1., 1., 1., 1., 0, 0};\n  double y[6];\n\n  for(int n = 0; n < 6; n++){\n    double sum = 0.;\n    for(int m = 0; m < 6; m++){\n      int idx = (n-m) % 6;\n      sum += x1[m]*x2[idx];\n    }\n    y[n] = sum;\n  }\n\\end{verbatim}\nNote that $L_1 = 3$, $L_2 = 4$, so that $L=6$.\n$\\blacksquare$\n\\end{example}\n\nAn interesting aside, convolution of finite length signals is equivalent to multiplication of two polynomials, where the signal values are the coefficients.\n\n\\section{Examples of DT Convolution}\n\n\\begin{example} Consider the convolution of two unit step functions:\n  \\[\n  u[n] * u[n] = \\sum\\limits_{m = -\\infty}^{\\infty} u[m]u[n-m]\n  \\]\n  Note for $n < 0$ the product of the signals $u[m]$ and $u[n-m]$ is zero as shown in the following figure\n  \\begin{center}\n  \\includegraphics[scale=1]{graphics/dt-step-step-conv.pdf}\n  \\end{center}\n  so that the resulting sum is zero for any $n < 0$. For $n \\geq 0$ the signals $u[m]$ and $u[n-m]$ overlap from $0$ to $n$ as shown below\n  \\begin{center}\n    \\includegraphics[scale=1]{graphics/dt-step-step-conv2.pdf}\n  \\end{center}\n  and the convolution sum is\n  \\[\n  \\sum\\limits_{m = 0}^{n} 1 = (n+1)\n  \\]\n  so that\n  \\[\n  u[n] * u[n] = \\left\\{ \\begin{array}{lc}\n    0 & n < 0\\\\\n    n+1 & n \\geq 0\n  \\end{array}\n  \\right.\n  \\]\n  Putting the piecewise result into a single expression gives\n  \\[\n  u[n] * u[n] = (n+1)u[n]\n  \\]\n  $\\blacksquare$\n\\end{example}\n\n\\begin{example}\nConsider the convolution of a unit step and the function $\\gamma^n\\,u[n]$ for some constant $\\gamma \\neq 1$:\n  \\[\n  \\gamma^n\\, u[n] * u[n] = \\sum\\limits_{m = -\\infty}^{\\infty} \\gamma^{m}u[m]u[n-m]\n  \\]\n  Since both signals are multiplied by a step, the product of $\\gamma^{m}u[m]u[n-m]$ is non-zero only for $0 \\leq m \\leq n$ (for the same reason as in the previous example). Thus for $n \\geq 0$ the convolution sum is:\n  \\[\n  \\sum\\limits_{m = 0}^{n} \\gamma^{m} = \\frac{\\gamma^{n+1}-1}{\\gamma-1} = \\frac{1-\\gamma^{n+1}}{1-\\gamma}\n  \\]\n  Putting the two peicewise results together gives\n  \\[\n  \\gamma^n\\, u[n] * u[n] = \\frac{1-\\gamma^{n+1}}{1-\\gamma}\\,u[n]\n  \\]\n  $\\blacksquare$\n\\end{example}\n\\begin{example} Consider the convolution of an arbitrary signal $x[n]$ with the impulse function\n  \\[\n  x[n] * \\delta[n] = \\sum\\limits_{m = -\\infty}^{\\infty} x[m]\\delta[n-m]\n  \\]\n  By the sifting property we get\n  \\[\n  \\sum\\limits_{m = -\\infty}^{\\infty} x[m]\\delta[n-m] = x[n]\n  \\]\n  Thus the convolution with the impulse gives back the same signal (the $\\delta$ is the \\emph{identity} signal). $\\blacksquare$\n\\end{example}\n\nThe following table lists several DT convolution results.\n\n\\begin{center}\n  Table of Representative Convolution Sums\n  \\vspace{1em}\n  \n\\bgroup\n\\def\\arraystretch{2}\n\\setlength\\tabcolsep{2em}\n\\begin{tabular}{|c|c|c|}\n  \\hline\n  $x_1[n]$ & $x_2[n]$ & $x_1[n] * x_2[n]$\\\\\n  \\hline\n  \\hline\n  $u[n]$ & $u[n]$ & $(n+1)u[n]$\\\\\n  $\\gamma^{n}u[n]$ & $u[n]$ & $\\frac{1-\\gamma^{n+1}}{1-\\gamma}u[n]$ for $\\gamma \\neq 1$\\\\\n  $\\gamma_1^{n}u[n]$ & $\\gamma_2^{n}u[n]$ & $\\frac{\\gamma_1^{n+1}-\\gamma_2^{n+1}}{\\gamma_1-\\gamma_2}u[n]$ for $\\gamma_1 \\neq \\gamma_2$\\\\\n  $\\gamma^{n}u[n]$ & $\\gamma^{n}u[n]$ & $(n+1)\\gamma^{n}u[n]$\\\\\n  $|\\gamma_1|^{n}\\cos\\left(\\beta n + \\theta \\right)u[n]$ & $|\\gamma_2|^{n}u[n]$ & $\\frac{1}{R}\\left[ |\\gamma_1|^{n+1}\\cos\\left( \\beta (n+1) + \\theta - \\phi\\right) - |\\gamma_2|^{n+1}\\cos\\left( \\theta - \\phi\\right)\\right]u[n]$\\\\\n           & & $R = \\left[ |\\gamma_1|^2 + |\\gamma_2|^2 -2|\\gamma_1||\\gamma_2|\\cos(\\beta)\\right]^{\\frac{1}{2}}$\\\\\n  & & $\\phi = \\arctan\\left( \\frac{|\\gamma_1|\\sin(\\beta)}{|\\gamma_1|\\cos(\\beta) - |\\gamma_2|} \\right)$\\\\\n\n\\hline                       \n\\end{tabular}\n\\egroup\n\n\\end{center}\n\n\\section{Properties of DT Convolution}\nThere are several useful properties of convolution. We do not prove these here, but it is not terribly difficult to do so. Given signals $x_1[n]$, $x_2[n]$, and $x_3[n]$:\n\n\\begin{description}\n\\item [Communative Property] The ordering of the signals does not matter.\n  \\[\nx_1[n] * x_2[n] = x_2[n] * x_1[n]\n  \\]\n\\item [Distributive Propery] Convolution is distributed over addition.\n  \\[\n  x_1[n] * \\left(x_2[n] + x_3[n]\\right) = \\left(x_1[n] * x_2[n] \\right) + \\left(x_1[n] * x_3[n] \\right) \n  \\]\n\\item [Associative Property] The order of convolution does not matter.\n    \\[\n  x_1[n] * \\left(x_2[n] * x_3[n]\\right) = \\left(x_1[n] * x_2[n] \\right) * x_3[n] \n  \\]\n\\item [Index Shift] Given $x_3[n] = x_1[n] * x_2[n]$ then for index shifts $m_1, m_2 \\in \\mathbb{R}$\n  \\[\n  x_1[n-m_1] * x_2[n-m_2] = x_3[n-m_1 - m_2]\n  \\]\n\\item [Multiplicative Scaling] Given $x_3[n] = x_1[n] * x_2[n]$ then for constants $a,b \\in \\mathbb{C}$\n  \\[\n  \\left(a\\, x_1[n]\\right) * \\left(b\\, x_2[n]\\right) = a\\, b\\, x_3[n]\n  \\]\n\\end{description}\n\nThese properties can be used in combination with a table like that above to compute the convolution of a wide variety of signals without evaluating the summations.\n\n\\begin{example} Consider the convolution of the causal DT pulse of length $N$, $x_1[n] = u[n] - u[n-N]$, and the signal $x_2[n] = \\left( \\frac{1}{2}\\right)^nu[n]$.\n\n  \\begin{align*}\n    x_1[n] * x_2[n] &= \\left( u[n] - u[n-N]\\right) * \\left( \\left( \\frac{1}{2}\\right)^nu[n] \\right)\\\\\n    &= \\left( u[n] \\right) * \\left( \\left( \\frac{1}{2}\\right)^nu[n] \\right) - \\left( u[n-N]\\right) * \\left( \\left( \\frac{1}{2}\\right)^nu[n] \\right) \\mbox{ using distributive property}\\\\\n    &= \\frac{1-\\left(\\frac{1}{2}\\right)^{n+1}}{1-\\left(\\frac{1}{2}\\right)}u[n] - \\frac{1-\\left(\\frac{1}{2}\\right)^{n+1}}{1-\\left(\\frac{1}{2}\\right)}u[n] \\Big|_{n\\rightarrow n-N} \\mbox{ from Table row 2 and index shift property}\\\\\n    &= \\frac{1-\\left(\\frac{1}{2}\\right)^{n+1}}{\\left(\\frac{1}{2}\\right)}u[n] - \\frac{1-\\left(\\frac{1}{2}\\right)^{n-N+1}}{\\left(\\frac{1}{2}\\right)}u[n-N]\\\\\n    &= \\frac{1-\\left(\\frac{1}{2}\\right)^{n+1}}{\\left(\\frac{1}{2}\\right)}u[n] - \\frac{1-\\left(\\frac{1}{2}\\right)^{-N}\\left(\\frac{1}{2}\\right)^{n+1}}{\\left(\\frac{1}{2}\\right)}u[n-N]\\\\\n    &= 2\\left(1-\\left(\\frac{1}{2}\\right)^{n+1}\\right)u[n] - 2\\left(1-\\left(\\frac{1}{2}\\right)^{-N}\\left(\\frac{1}{2}\\right)^{n+1} \\right)u[n-N]\\\\\n    &= \\left(2-\\left(\\frac{1}{2}\\right)^{n}\\right)u[n] - \\left(2-\\left(\\frac{1}{2}\\right)^{-N}\\left(\\frac{1}{2}\\right)^{n} \\right)u[n-N]\n  \\end{align*}\n$\\blacksquare$\n\\end{example}\n\n", "meta": {"hexsha": "b249286b5597ba9c0adfe19d769ab2baa795a0b4", "size": 10939, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "09-dt-conv.tex", "max_stars_repo_name": "clwyatt/notes-2714", "max_stars_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "09-dt-conv.tex", "max_issues_repo_name": "clwyatt/notes-2714", "max_issues_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "09-dt-conv.tex", "max_forks_repo_name": "clwyatt/notes-2714", "max_forks_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.9484978541, "max_line_length": 479, "alphanum_fraction": 0.6464941951, "num_tokens": 4001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.9086178975514608, "lm_q1q2_score": 0.8047006104888631}}
{"text": "\\section{Calculus of Vector and Matrix Valued Functions}\n\n\\subsection{Exercise 1}\nThat $\\dot{x}(t) = 0 \\implies x(t) = c$ follows immediately from the mean value inequality for vector-valued\nfunctions, $\\norm{x(b) - x(a)} \\leq (b - a) \\norm{x'(t)}$ for some $t \\in (a, b)$. My guess is that\nLax was hinting at applying the mean value theorem for real-valued functions to $(x(b) - x(a), y)$.\n\n\\subsection{Exercise 2}\nWe have that\n\\begin{align*}\n        \\dv{x} A^{-1} A = 0 = \\bigg(\\dv{x} A^{-1}\\bigg) A + A^{-1} \\bigg(\\dv{x} A\\bigg) \\implies \\dv{x} A^{-1} = -A^{-1} \\bigg( \\dv{x} A \\bigg) A^{-1} \n\\end{align*}\n\n\\subsection{Exercise 3}\nThe matrix $A + B$ satisfies $(A + B)^2 = I$, so we have that\n\\begin{align*}\n        e^{A+B} &= \\sum_{k = 0}^\\infty \\frac{(A + B)^k}{k!} \\\\\n                &= \\bigg(\\sum_{k = 0}^\\infty \\frac{1}{(2k)!}\\bigg) I +  \\bigg(\\sum_{k = 0}^\\infty \\frac{1}{(2k + 1)!}\\bigg) (A + B) \\\\\n                &= \\cosh(1) I + \\sinh(1) (A + B)\n\\end{align*}\n\n\\subsection{Exercise 4}\nWe can use uniform continuity to swap the limits to get\n\\begin{align*}\n        \\lim_{m \\to \\infty} \\norm{\\dot{E}_m(t) - F(t)} &= \\lim_{m \\to \\infty} \\lim_{h \\to 0} \\norm{\\frac{E_m(t + h) - E_m(t)}{h} - F(t)} \\\\\n                                                       &= \\lim_{h \\to 0} \\lim_{m \\to \\infty} \\norm{\\frac{E_m(t + h) - E_m(t)}{h} - F(t)} \\\\\n                                                       &= \\lim_{h \\to 0} \\norm{\\frac{E(t + h) - E(t)}{h} - F(t)} \\\\\n                                                       &\\implies \\dot{E}(t) = F(t)\n\\end{align*}\n\n\\subsection{Exercise 5}\nLet $M \\geq \\norm{A(t)}, \\norm{\\dot{A}(t)}$. Then we can use the expression for the derivative of $A^k(t)$\nto get\n\\begin{align*}\n        \\norm{\\dv{t} A^k} &= \\norm{\\dot{A} A^{k - 1} + A \\dot{A} A^{k - 2} + ... + A^{k - 1}\\dot{A}} \\\\\n                   &\\leq kM^k \\\\\n        \\implies \\norm{\\dot{E}_m(t) - \\dot{E}_n(t)} &\\leq \\sum_{k = n + 1}^m \\frac{kM^k}{k!}\n\\end{align*}\nso $\\dot{E}_m(t)$ converges.\n\n\\subsection{Exercise 6}\n\\begin{align*}\n        \\dv{t} \\log\\det e^{At} = \\Tr(e^{-At} A e^{At}) = \\Tr(A)\n\\end{align*}\n\n\\subsection{Exercise 7}\nLet $v$ be an eigenvector of $A$ with eigenvalue $a$. Then\n\\begin{align*}\n        e^A v &= \\sum_{k = 0}^\\infty \\frac{A^k v}{k!} \\\\\n              &= \\sum_{k = 0}^\\infty \\frac{a^k v}{k!} \\\\\n              &= e^a v\n\\end{align*}\n\n", "meta": {"hexsha": "fa273cd8fbce4d5c2af6854d0a298a1d244cfcaf", "size": 2352, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear_Algebra_Lax/chapter_9.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Linear_Algebra_Lax/chapter_9.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Linear_Algebra_Lax/chapter_9.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.5555555556, "max_line_length": 151, "alphanum_fraction": 0.4948979592, "num_tokens": 920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8856314677809303, "lm_q1q2_score": 0.8047006017126431}}
{"text": "\n\\subsection{Subset relation}\n\n\\subsubsection{Subset}\n\nIf all terms which are members of term \\(x\\) are also members of term \\(y\\), then \\(x\\) is a subset of \\(y\\).\n\n\\(\\forall x\\forall y[(\\forall z(z\\in x\\rightarrow z\\in y))\\leftrightarrow (x\\subseteq y)]\\)\n\n\\subsubsection{Proper subset}\n\nIf two sets are equal, then each is a subset of the other. A proper subset is one which is a subset, and not equal to the other set.\n\n\\(\\forall x\\forall y[((\\forall z(z\\in x\\rightarrow z\\in y)))\\land(x\\ne y)\\leftrightarrow (x\\subset y)]\\)\n\n", "meta": {"hexsha": "d676c082888386ede49a5bc5e65eefd56b78b3cf", "size": 530, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sets/02-01-subset.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sets/02-01-subset.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sets/02-01-subset.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.125, "max_line_length": 132, "alphanum_fraction": 0.6981132075, "num_tokens": 156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172615983309, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.8046512395577561}}
{"text": "\\paragraph{Rotation}\n$T_\\phi(x, y) = (x \\cos(\\phi) -  y \\sin(\\phi), x \\sin(\\phi) + y \\cos(\\phi))$\n\n\\paragraph{Translation} $T_\\delta(x, y) = (x + \\delta_x, y + \\delta_y)$\n\n\\paragraph{Scaling}\n$T_\\lambda(x, y) = (\\lambda x, \\lambda y)$\n\n\\paragraph{Interpolation} To compute pixel value $I_\\kappa(x, y)$ after $T_\\kappa$: compute pre-image $T_\\kappa(x, y)$, then interpolate. \n\n\\paragraph{Domain}\n$w_l^T \\kappa + b_l \\le I_\\kappa(x, y) \\le w_u^T + b_u$, for all $\\kappa$\n\n\\paragraph{Tightness}\n$\\begin{array}{r@{~:=~}l}\nL(w_l, b_l) & \\int_{\\kappa\\in D} \\left(I_\\kappa(x, y) - (w_l^T\\kappa + b_l)\\right) d\\kappa \\\\\nU(w_u, b_u) & \\int_{\\kappa\\in D} \\left((w_u^T\\kappa + b_u) - I_\\kappa(x, y)\\right) d\\kappa\n\\end{array}$\n\n\\paragraph{Optimization}\n\\begin{itemize}\n\\item $L(w_l, b_l) \\approx \\frac{1}{N} \\sum_{i=1}^N \\left(I_\\kappa(x, y) - (w_l^T\\kappa^i + b_l)\\right)$\n\\item $w_l^T\\kappa^i + b_l \\le I_{\\kappa^i}(x, y)$, $1 \\le i \\le N$\n\\end{itemize}\n$\\rightarrow$ Solve in poly-time with linear programming. \n\\paragraph{Soundness}\nFind upper bound $\\delta$ on violation: \n$\\begin{array}{r@{~\\le~}ll}\n(w_l^T\\kappa^i + b_l) - I_\\kappa(x, y) & \\delta_l &\\forall \\kappa \\in D \\\\\n I_\\kappa(x, y) - (w_u^T\\kappa + b_u) & \\delta_u &\\forall \\kappa \\in D\n\\end{array}$\n\nUsing $b_l-\\delta_l$, $b_u+\\delta_u$ is sound. \n\n\\paragraph{$\\rightarrow$ Box}\nUse Box to compute upper bound on $f(\\kappa)$\n\n\\paragraph{$\\rightarrow$ MVTh} if $\\lvert \\partial_i f(\\kappa') \\rvert \\le \\lvert L_i \\rvert \\forall \\kappa' \\in D = [h_l, h_u]$, \n$f(\\kappa) = f(\\kappa_C) + \\nabla f(\\kappa')^T(\\kappa-\\kappa_C) \\le f(\\kappa_C) + \\lvert L \\rvert^T (\\kappa - \\kappa_C) \\le f\\left(\\frac{h_u+h_l}{2}\\right) + \\lvert L \\rvert^T \\frac{(h_u-h_l)}{2}$\n", "meta": {"hexsha": "2638146057ceeb1d40a541c082d233db5f5e9216", "size": 1709, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "geometric-transformations.tex", "max_stars_repo_name": "cknabs/RIAI-summary-HS2020", "max_stars_repo_head_hexsha": "42a1ee3cc2e51c52188f842c78923792bd0f3edf", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-01-20T21:27:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-24T20:28:56.000Z", "max_issues_repo_path": "geometric-transformations.tex", "max_issues_repo_name": "cknabs/RIAI-summary-HS2020", "max_issues_repo_head_hexsha": "42a1ee3cc2e51c52188f842c78923792bd0f3edf", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-25T09:29:16.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-25T10:50:09.000Z", "max_forks_repo_path": "geometric-transformations.tex", "max_forks_repo_name": "cknabs/RIAI-summary-HS2020", "max_forks_repo_head_hexsha": "42a1ee3cc2e51c52188f842c78923792bd0f3edf", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.725, "max_line_length": 196, "alphanum_fraction": 0.6296079579, "num_tokens": 726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172587090975, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.8046512352848765}}
{"text": "\\section{Mimimization and Least Squares}\n\n\\begin{theorem}\n  If $K$ is a positive definite (and hence symmetric) matrix, then the quadratic function has a unique minimizer, whcih is the solution to the linear system \n  \\[\n  Kx=f,\\text{ namely } x^{*}=K^{-1}f\n.\\] The minimum value of $p(x)$ is equal to any of the following expressions: \\[\np(X^{*})=p(K^{-1}f)=c-f^{T}K^{-1}f=c-f^{T}x^{*}=c-(x^{*})^{T}Kx^{*}\n.\\] \n\\end{theorem}\n", "meta": {"hexsha": "aadb8aaecc71af2e03fef7d4194feb90f8d05ea9", "size": 426, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math363/chapters/5.tex", "max_stars_repo_name": "CameronSWilliamson/GU-MATH", "max_stars_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-18T00:49:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T00:49:14.000Z", "max_issues_repo_path": "math363/chapters/5.tex", "max_issues_repo_name": "therealkeyisme/Math-Notes", "max_issues_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math363/chapters/5.tex", "max_forks_repo_name": "therealkeyisme/Math-Notes", "max_forks_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.7272727273, "max_line_length": 157, "alphanum_fraction": 0.6408450704, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418199787566, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.8045553518523596}}
{"text": "\\subsection{Cross Products}\r\n\\noindent\r\nA cross product is a way of multiplying two vectors so that the result is a vector.\r\nAlthough the cross product technically only works for 3D vectors, we will first look a a ``fake'' 2D version to build an intuition.\r\n\\begin{equation*}\r\n\t\\vec{a}\\times\\vec{b} = a_1b_1-a_2b_2.\r\n\\end{equation*}\r\nThis ``fake'' 2D cross product gives the area of the parallelogram spanned by $\\vec{a}$ and $\\vec{b}$.\r\n\\begin{equation*}\r\n\t\\vec{a}\\times\\vec{b} = \\norm{\\vec{a}}\\norm{\\vec{b}}\\sin{\\theta}\r\n\\end{equation*}\r\nwhere $\\theta$ is the angle between $\\vec{a}$ and $\\vec{b}$.\r\nAnother way to think of the magnitude of the cross product, both in 2D and 3D, is as a measure of how perpendicular two vectors are.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.5\\textwidth]{../common/vectorsMatrices/CrossProduct.png}\r\n\t\\caption{Visualization of the cross product}\r\n\\end{figure}\r\n\r\n\\noindent\r\nIn 3D, $\\vec{a}\\times\\vec{b}$ is a vector, and similar to the 2D case, the magnitude of $\\vec{a}\\times\\vec{b}$ is equal to the area of the parallelogram spanned by $\\vec{a}$ and $\\vec{b}$.\r\n\\begin{equation*}\r\n\t\\vec{a}\\times\\vec{b} = \\langle a_2b_3-b_2a_3,a_3b_1-b_3a_1,a_1b_2-b_1a_2 \\rangle\r\n\\end{equation*}\r\nand\r\n\\begin{equation*}\r\n\t\\norm{\\vec{a}\\times\\vec{b}}=\\norm{\\vec{a}}\\norm{\\vec{b}}\\sin{\\theta}\r\n\\end{equation*}\r\nwhere $\\theta$ is the angle between $\\vec{a}$ and $\\vec{b}$.\r\nEach component of $\\vec{a}\\times\\vec{b}$ gives the area of the parallelogram spanned by $\\vec{a}$ and $\\vec{b}$ in some plane:\r\nThe $x$-component of $\\vec{a}\\times\\vec{b}$ gives the area in the yz-plane ($x$ = 0 plane).\r\n$\\vec{a}\\times\\vec{b}$ is perpendicular, also called ``normal,'' to the plane containing $\\vec{a}$ and $\\vec{b}$. It's direction, is determined by the right hand rule.\\\\\r\n\r\n\\noindent\r\nThis cross product table of the standard basis vectors is useful for providing some insight into the properties of the cross product.\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\renewcommand{\\arraystretch}{1.5}\r\n\t\\begin{tabular}{|c||c|c|c|}\r\n\t\t\\hline\r\n\t\t$\\overrightarrow{\\text{row}}\\times\\overrightarrow{\\text{col}}$ & $\\hat{i}$  & $\\hat{j}$  & $\\hat{k}$  \\\\ \\hline\\hline\r\n\t\t$\\hat{i}$                                & $0$        & $\\hat{k}$  & $-\\hat{j}$ \\\\ \\hline\r\n\t\t$\\hat{j}$                                & $-\\hat{k}$ & $0$        & $\\hat{i}$  \\\\ \\hline\r\n\t\t$\\hat{k}$                                & $\\hat{j}$  & $-\\hat{i}$ & $0$        \\\\ \\hline\r\n\t\\end{tabular}\r\n\\end{table}\r\n\r\n\\begin{enumerate}[label=]\r\n\t\\item \\textbf{\\underline{NOT} Commutative}, but is antisymmetric\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{a}\\times\\vec{b} = -\\left(\\vec{b}\\times\\vec{a}\\right)\r\n\t\t\\end{equation*}\r\n\t\\item \\textbf{Scalar Associative}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\left(c\\cdot\\vec{a}\\right)\\times\\vec{b}=\\vec{a}\\times\\left(c\\cdot\\vec{b}\\right)\r\n\t\t\\end{equation*}\r\n\t\\item \\textbf{Distributive}\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{a}\\times\\left(\\vec{b}\\times\\vec{c}\\right) = \\vec{a}\\times\\vec{b} + \\vec{a}\\times\\vec{c}\r\n\t\t\\end{equation*}\r\n\\end{enumerate}\r\n\r\n\\noindent\r\nOne can also think of the cross product as the determinant of a matrix.\r\n\\begin{equation*}\r\n\t\\vec{a}\\times\\vec{b} = \\det\\begin{bmatrix}\r\n\t\t\\hat{i}& \\hat{j} & \\hat{k} \\\\\r\n\t\ta_1 & a_2 & a_2\\\\\r\n\t\tb_1 & b_2 & b_3 \r\n\t\\end{bmatrix}\r\n\\end{equation*}", "meta": {"hexsha": "0c6ae2cf28bf1679e2ead49081fcd86d8481a07a", "size": 3284, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/vectorsMatrices/crossProducts.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/vectorsMatrices/crossProducts.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/vectorsMatrices/crossProducts.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 45.6111111111, "max_line_length": 189, "alphanum_fraction": 0.6342874543, "num_tokens": 1164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.8045553495521317}}
{"text": "\\section{Divided Differences}\n\\subsection{Divided Differences Notation}\nThe $k$th divided difference relative to $x_i,\\cdots,x_{i+k}$ is\n\\begin{align*}\n  & f[x_i]=f(x_i) \\\\\n  & f[x_i,\\cdots,x_{i+k}]=\\frac{f[x_{i+1},\\cdots,x_{i+k}]-f[x_i,\\cdots,x_{i+k-1}]}{x_{i+k}-x_i}\n\\end{align*}\nfor each $k=0,1,\\cdots,n$, $P_n(x)$ can be rewritten in a form called \\emph{Newton's Divided-Difference}:\n\\[\nP_n(x)=f[x_0]+\\sum_{k=1}^{n}f[x_0,\\cdots,x_k](x-x_0)\\cdots (x-x_{k-1})\n\\]\n\\begin{theo}\n$f\\in C^n[a,b]$, $x_i\\in [a,b]$ for $i=0:n$, $\\exists\\xi\\in (a,b)$, s.t.\n\\[\nf[x_0,x_1,\\cdots,x_n]=\\frac{f^{(n)}(\\xi)}{n!}\n\\]\n\\end{theo}\n\\begin{proof}\nLet $g(x)=f(x)-P_n(x)$, which has $n+1$ distinct zeros in $[a,b]$. According to \\emph{Generalized Rolle's Theorem}, $\\exists\\xi\\in (a,b)$, s.t. $g^{(n)}(\\xi)=0$.\n\\begin{align*}\n  & 0=g^{(n)}(\\xi)=f^{(n)}(\\xi)-P_n^{(n)}(\\xi)=f^{(n)}(\\xi)-n!f[x_0,\\cdots,x_k] \\\\\n  \\Rightarrow & f[x_0,x_1,\\cdots,x_n]=\\frac{f^{(n)}(\\xi)}{n!}\n\\end{align*}\n\\end{proof}\n\nWhen the nodes are arranged consecutively with equal spacing, then we use $h=x_{i+1}-x_i$  and $x=s\\cdot h+x_0$, the equation will become\n\\begin{align*}\n  P_n(x) &= P_n(x_0+sh)=f[x_0]+\\sum_{k=1}^{n}s(s-1)\\cdots (s-k+1)h^kf[x_0,\\cdots,x_k] \\\\\n  &= f[x_0]+\\sum_{k=1}^{n}\\binom{s}{k}k!h^kf[x_0,\\cdots,x_k].\n\\end{align*}\n\n\\subsection{Forward Differences}\n\\begin{align*}\n  f[x_0,x_1]&=\\frac{1}{h}\\left(f(x_1)-f(x_0)\\right)=\\frac{1}{h}\\triangle f(x_0) \\\\\n  f[x_0,x_1,x_2]&=\\frac{1}{2h}\\left(\\frac{\\triangle f(x_1)-\\triangle f(x_0)}{h}\\right)=\\frac{1}{2h^2}\\triangle^2f(x_0)\n\\end{align*}\nIn general,\n\\begin{align*}\n  & f[x_0,x_1,\\cdots,x_k]=\\frac{1}{k!h^k}\\triangle^kf(x_0) \\\\\n  \\Rightarrow & P_n(x)=f[x_0]+\\sum_{k=1}^{n}\\binom{s}{k}\\triangle^kf(x_0)\n\\end{align*}\n\\subsection{Backward Differences}\n\\begin{align*}\n  f[x_n,x_{n-1}]&=\\frac{1}{h}\\nabla f(x_n) \\\\\n  f[x_n,x_{n-1},x_{n-2}]&=\\frac{1}{2h^2}\\nabla^2f(x_n)\n\\end{align*}\nIn general,\n\\begin{align*}\n  & f[x_n,x_{n-1},\\cdots,x_{n-k}]=\\frac{1}{k!h^k}\\nabla^kf(x_n) \\\\\n  \\Rightarrow & P_n(x)=f[x_n]+\\sum_{k=1}^{n}\\frac{s(s+1)\\cdots (s+k-1)}{k!}\\nabla^kf(x_n)\n\\end{align*}\nAlso, we have\n\\begin{align*}\n  & \\binom{-s}{k}=\\frac{-s(-s-1)\\cdots (-s-k+1)}{k!}=(-1)^k\\frac{s(s+1)\\cdots (s+k-1)}{k!} \\\\\n  \\Rightarrow & P_n(x)=f[x_n]+\\sum_{k=1}^{n}(-1)^k\\binom{-s}{k}\\nabla^kf(x_n)\n\\end{align*}\n\n\\subsection{Centered Differences}\n\\begin{align*}\n    P_n(x)=P_{2m+1}(x) &= f[x_0]+\\frac{sh}{2}\\left(f[x_{-1},x_0]+f[x_0,x_1]\\right)+(sh)^2f[x_{-1},x_0,x_1] \\\\\n    &+ \\cdots \\\\\n    &+ s^2(s^2-1)\\cdots (s^2-(m-1)^2)h^{2m}f[x_{-m},\\cdots,x_{m+1}] \\\\\n    &+ \\frac{s^2(s^2-1)\\cdots(s^2-m^2)h^{2m+1}}{2}\\left(f[x_{-m-1},\\cdots,x_m]+f[x_{-m},\\cdots,x_{m+1}]\\right)\n\\end{align*}\nIf $n=2m+1$ is odd, we use the above formula, if $n=2m$ is even, we delete the last line and then use the above formula.\n\\vspace{1cm}\\\\\n\\begin{tabular}{@{}llllll@{}}\n\\toprule\nx & f(x) & 1st & 2nd & 3rd & 4th divided differences \\\\ \\midrule\n$x_{-2}$ & $f[x_{-2}]$ & $f[x_{-2},x_{-1}]$ & $f[x_{-2},x_{-1},x_{0}]$ & $\\underline{f[x_{-2},x_{-1},x_{0},x_{1}]}$ & $\\underline{f[x_{-2},x_{-1},x_{0},x_{1},x_{2}]}$ \\\\\n$x_{-1}$ & $f[x_{-1}]$ & $\\underline{f[x_{-1},x_{0}]}$ & $\\underline{f[x_{-1},x_{0},x_{1}]}$ & $\\underline{f[x_{-1},x_{0},x_{1},x_{2}]}$ &  \\\\\n$x_{0}$ & $\\underline{f[x_{0}]}$ & $\\underline{f[x_{0},x_{1}]}$ & $f[x_{0},x_{1},x_{2}]$ &  &  \\\\\n$x_{1}$ & $f[x_{1}]$ & $f[x_{1},x_{2}]$ &  &  &  \\\\\n$x_{2}$ & $f[x_{2}]$ &  &  &  &  \\\\ \\bottomrule\n\\end{tabular}\n", "meta": {"hexsha": "2229f148fcca9a24a12ff3528055209fe4738275", "size": 3444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/3.3_Divided_differences.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/3.3_Divided_differences.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/3.3_Divided_differences.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.3157894737, "max_line_length": 169, "alphanum_fraction": 0.5679442509, "num_tokens": 1688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.8991213671331906, "lm_q1q2_score": 0.8045243356262974}}
{"text": "\\section*{Problem 3: Dual Coordinate Ascent}\n\nConsider the problem\n\\begin{equation}\n  \\min_w L\\left(x\\right),~\\text{where}~\n  L\\left(x\\right) = \\sum_{i=1}^n\\left(w \\cdot x_i - y_i\\right)^2 + \\lambda \\left\\lVert\n    w\n  \\right\\rVert^2.\n  \\label{eqn:3problem}\n\\end{equation}\n\n\\begin{enumerate}\n\\item \n  Show that the solution for Equation \\ref{eqn:3problem} is obtained for weights\n  \\begin{align}\n    w^* &= \\left(X^\\intercal X +\\lambda I\\right)^{-1}X^\\intercal Y \\label{eqn:3w_star} \\\\\n    &= \\frac{1}{\\lambda}X^\\intercal\\alpha^*, \\label{eqn:3w_star2}\n  \\end{align}\n  where $\\alpha^* = \\left(I + XX^\\intercal/\\lambda\\right)^{-1}$.\n\n  \\subsection*{Solution}\n  \\begin{proof}\n    We can take the derivative of $L$ in Equation \\ref{eqn:3problem}\n    directly. Note that $D\\left(x \\mapsto Ax\\right)\\left(x\\right) = A$ and\n    $D\\left(x \\mapsto x^\\intercal x\\right)\\left(x\\right) = 2x^\\intercal.$\n    Therefore by the chain rule,\n    \\begin{equation}\n      D\\left(x \\mapsto \\left(Ax\\right)^\\intercal\\left(Ax\\right)\\right)(x)\n      = 2 x^\\intercal A^\\intercal A.\n    \\end{equation}\n\n    We can reformulate Equation \\ref{eqn:3problem} as a function of $w$\n    \\begin{align}\n      l_{X,y}\\left(w\\right)\n      &= \\left(Aw - y\\right)^\\intercal\\left(Aw - y\\right) + \\lambda w^\\intercal w \\nonumber\\\\\n      &=\n        \\left(Aw\\right)^\\intercal\\left(Aw\\right)\n        - 2y^\\intercal Aw + y^\\intercal y\n        + \\lambda w^\\intercal w.\n        \\label{eqn:3problem_new}\n    \\end{align}\n\n    Taking the derivative, we have that\n    \\begin{equation}\n      D\\left(l_{X,y}\\right)(w)\n      = 2 w^\\intercal X^\\intercal X - 2 y^\\intercal X + 2\\lambda w^\\intercal.\n      \\label{eqn:3derivative}\n    \\end{equation}\n\n    Setting Equation \\ref{eqn:3derivative} to $0$ and solving for $w$, we have\n    \\begin{align*}\n      0 &= 2 w^\\intercal X^\\intercal X - 2 y^\\intercal X + 2w^\\intercal \\\\\n      w^\\intercal\\left(X^\\intercal X  + \\lambda I\\right)\n        &= y^\\intercal X \\\\\n      \\left(X^\\intercal X  + \\lambda I\\right)w\n        &= X^\\intercal y \\\\\n      w &= \\left(X^\\intercal X  + \\lambda I\\right)^{-1}X^\\intercal y.\n    \\end{align*}\n\n    Since Equation \\ref{eqn:3problem_new} is a quadractic form, the problem is\n    convex, and\n    \\begin{equation*}\n      w^* = \\left(X^\\intercal X +\\lambda I\\right)^{-1}X^\\intercal Y\n    \\end{equation*}\n    minimizes Equation \\ref{eqn:3problem}.\n\n    Now, note that\n    \\begin{align*}\n      \\left(X^\\intercal X + \\lambda I\\right)X^\\intercal\n      &= X^\\intercal XX^\\intercal + \\lambda X^\\intercal\n        = X^\\intercal\\left(XX^\\intercal + \\lambda I\\right).\n    \\end{align*}\n    Multiplying on the left by $\\left(X^\\intercal X + \\lambda I\\right)^{-1}$ and on the right\n    by $\\left(XX^\\intercal + \\lambda I\\right)^{-1}$, we have that\n    \\begin{align*}\n      X^\\intercal\\left(XX^\\intercal + \\lambda I\\right)^{-1} =\n      \\left(X^\\intercal X + \\lambda I\\right)^{-1}X^\\intercal.\n    \\end{align*}\n\n    Substituting this into Equation \\ref{eqn:3w_star}, we obtain\n    \\begin{align*}\n      w^*\n      &= X^\\intercal\\left(XX^\\intercal + \\lambda I\\right)^{-1}y \\\\\n      &= X^\\intercal\\left(\\lambda\\left(I + \\frac{XX^\\intercal}{\\lambda}\\right)\\right)^{-1}y \\\\\n      &= \\frac{1}{\\lambda}X^\\intercal\\left(I + \\frac{XX^\\intercal}{\\lambda}\\right)^{-1}y,\n    \\end{align*}\n    which gives us the desired result.    \n  \\end{proof}\n\n  If $\\lambda = 0$, in general, this is not true since\n  $XX^\\intercal + \\lambda I$ may not be invertable when $n > d$. However, if\n  $d \\geq n$, and $\\operatorname{rank}\\left(X\\right) \\geq n$, Equation\n  \\ref{eqn:3w_star2} may still be well-defined.\n\\item Define\n  \\begin{equation}\n    G\\left(\\alpha_1,\\alpha_2,\\ldots,\\alpha_n\\right) = \\frac{1}{2}\\alpha^\\intercal\\left(\n      I + XX^\\intercal/\\lambda\\right)\\alpha - Y^\\intercal \\alpha.\n    \\label{eqn:3g}\n  \\end{equation}\n\n  Start with $\\alpha = 0$. Choose coordinate $i$ randomly, and update\n  \\begin{equation}\n    \\alpha_i = \\argmin_z G\\left(\n      \\alpha_1,\\ldots,\\alpha_{i-1},z,\\alpha_{i+1},\\ldots,\\alpha_n\n    \\right).\n  \\end{equation}\n  \n  Show that the solution to the inner optimization problem for $\\alpha_i$ is:\n  \\begin{equation}\n    \\alpha_i = \\frac{y_i - \\frac{1}{\\lambda}\\left(\\sum_{j \\neq i} \\alpha_j x_j\\right) \\cdot x_i}\n    {1 + \\lVert x_i \\rVert^2/\\lambda}.\n    \\label{eqn:3update}\n  \\end{equation}\n\n  \\subsection*{Solution}\n  \\begin{proof}\n    We can take the partial derivative of Equation \\ref{eqn:3g} directly to obtain\n    \\begin{align}\n      \\frac{\\partial{G}}{\\partial{\\alpha_i}}\n      &= \\alpha_i + \\frac{1}{\\lambda}\\left(\\alpha^\\intercal X X^\\intercal\\right)_i - y_i\n        \\nonumber\\\\\n      &= \\alpha_i + \\frac{1}{\\lambda}\\left(\n        \\alpha_i\\left\\lVert x_i\\right\\rVert^2 +\n        \\sum_{j \\neq i} \\alpha_j \\left(x_j \\cdot x_i \\right)\n        \\right) - y_i. \\label{eqn:3g_deriv}\n    \\end{align}\n\n    Setting Equation \\ref{eqn:3g_deriv} to $0$, solving for $\\alpha_i$, and\n    taking advantage of convexity, we find\n    \\begin{equation}\n      \\alpha_i = \\frac{y_i - \\left(\\sum_{j \\neq i}\\alpha_j x_j \\right) \\cdot x_i}{\n        1 + \\lVert x_i \\rVert^2/\\lambda}\n  \\end{equation}\n  minimizes Equation \\ref{eqn:3g} as a function of $\\alpha_i$, and solves the\n  inner optimization problem.\n\\end{proof}\n\n\\item What is the computational complexity of this update, as it is stated?\n\n  \\subsection*{Solution}\n  The complexity of updating $\\alpha_i$ with Equation \\ref{eqn:3update} is\n  $O(nd)$ since we need to iterate over the $n$ rows of $X$, and take the\n  $d$-dimensional dot product of each row with $x_i$.\n\\item What is the computational complexity of one stochastic gradient descent update?\n  \\subsection*{Solution}\n\n  The complexity of one stochastic gradient descent update is $O(d)$. We\n  computed the derivative in Equation \\ref{eqn:3derivative} for the full matrix\n  $X$. In stochastic gradient descent we'd replace $X$ by a vector by randomly\n  sampling a row from $X$. Then, to compute the gradient we have to do some dot\n  products along with scalar operations.\n\\item Now consider the procedure.\n  \\begin{itemize}\n  \\item Start with $\\alpha = 0$, $w = \\frac{1}{\\lambda}X^\\intercal \\alpha = 0.$\n  \\item Choose coordinate $i$ randomly and perform the following update:\n    \\begin{itemize}\n    \\item Compute the differences:\n      \\begin{equation}\n        \\Delta \\alpha_i = \\frac{\\left(y_i - w \\cdot x_i\\right) - \\alpha_i}{\n          1 + \\left\\lVert x_i\\right\\rVert^2 / \\lambda}\n        \\label{eqn:3alpha_delta}\n      \\end{equation}\n    \\item Update the parameters as follows:\n      \\begin{align}\n        \\alpha_i &\\leftarrow \\alpha_i + \\Delta\\alpha_i \\nonumber\\\\\n        w &\\leftarrow w + \\frac{\\Delta \\alpha_i}{\\lambda}x_i.\n            \\label{eqn:3update_new}\n      \\end{align}\n    \\end{itemize}\n  \\end{itemize}\n  Prove that the update rule in Equation \\ref{eqn:3update_new} is valid.\n\n  \\subsection*{Solution}\n  \\begin{proof}\n    Let $\\alpha^\\prime$ and $w^\\prime$ be the result of updating coordinate $i$\n    of $\\alpha$. Assume that $w = \\frac{1}{\\lambda}X^\\intercal\\alpha$. This is\n    true when $\\alpha = 0$. We will show that this invariant holds as $\\alpha$\n    is updated.\n    \n    To see that, the update rule for $w$ is valid, we can rewrite\n    \\begin{equation}\n      w = \\frac{\\alpha_1}{\\lambda}x_1 + \\cdots + \\frac{\\alpha_i}{\\lambda}x_i + \\cdots + \\frac{\\alpha_n}{\\lambda}x_n,\n    \\end{equation}\n    so\n    \\begin{align*}\n      w^\\prime\n      &= w + \\frac{\\Delta\\alpha_i}{\\lambda}x_i \\\\\n      &= \\frac{\\alpha_1}{\\lambda}x_1 + \\cdots + \\frac{\\alpha_i + \\Delta\\alpha_i}{\\lambda}x_i + \\cdots + \\frac{\\alpha_n}{\\lambda}x_n \\\\\n      &= \\frac{\\alpha_1}{\\lambda}x_1 + \\cdots + \\frac{\\alpha^\\prime_i}{\\lambda}x_i + \\cdots + \\frac{\\alpha_n}{\\lambda}x_n \\\\\n      &= \\frac{1}{\\lambda}X^\\intercal \\alpha^\\prime.\n    \\end{align*}\n    Thus, the $w$ update is valid.\n\n    To see that the $\\alpha$ update is valid, we show that Equations\n    \\ref{eqn:3update} and \\ref{eqn:3update_new} are equivalent. Both algorithms\n    initiate $\\alpha = 0$, so they are equivalent at the initial step.\n\n    By using the definition $w = \\frac{1}{\\lambda}X^\\intercal \\alpha$,\n    \\begin{align*}\n      \\alpha_i^\\prime\n      &= \\alpha_i + \\Delta \\alpha_i \\\\\n      &= \\frac{\\left(y_i - w \\cdot x_i\\right) - \\alpha_i}{\n        1 + \\left\\lVert x_i\\right\\rVert^2 / \\lambda} +\n        \\frac{\\alpha_i + \\alpha_i\\left\\lVert x_i\\right\\rVert^2/\\lambda}{1 + \\left\\lVert x_i\\right\\rVert^2 / \\lambda} \\\\\n      &=\\frac{1}{1 + \\left\\lVert x_i\\right\\rVert^2 / \\lambda}\n        \\left(\n        y_i - \\frac{1}{\\lambda}\\left(\\sum_{j \\neq i} \\alpha_jx_j\\right) \\cdot x_i\n        - \\frac{1}{\\lambda}\\alpha_i \\left\\lVert x_i \\right\\rVert^2\n        + \\frac{1}{\\lambda}\\alpha_i \\left\\lVert x_i \\right\\rVert^2\n        \\right) \\\\\n      &= \\frac{y_i - \\frac{1}{\\lambda}\\left(\\sum_{j \\neq i} \\alpha_j x_j\\right) \\cdot x_i}{1 + \\left\\lVert x_i\\right\\rVert^2 / \\lambda},\n    \\end{align*}\n    so both update rules are equivalent.\n  \\end{proof}\n\n\\item What is the computation complexity of the update defined by Equations\n  \\ref{eqn:3alpha_delta} and \\ref{eqn:3update_new}?\n\n  \\subsection*{Solution}\n\n  The computation complexity is $O(d)$. Computing the dot product when computing\n  $\\Delta\\alpha_i$ and updating $w$ are both $O(d)$ operations. Everywhere else,\n  we do scalar operations.\n\n  This is much faster than the $O(nd)$ update for Equation \\ref{eqn:3update}.\n\\end{enumerate}\n", "meta": {"hexsha": "57f454da51d389ae6732fc4d2405ce531acbe607", "size": 9352, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw3/problem3/problem3.tex", "max_stars_repo_name": "kspathak/cse547", "max_stars_repo_head_hexsha": "2379c6435c871720aa7da53d3c8066a628e81830", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hw3/problem3/problem3.tex", "max_issues_repo_name": "kspathak/cse547", "max_issues_repo_head_hexsha": "2379c6435c871720aa7da53d3c8066a628e81830", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw3/problem3/problem3.tex", "max_forks_repo_name": "kspathak/cse547", "max_forks_repo_head_hexsha": "2379c6435c871720aa7da53d3c8066a628e81830", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-18T01:39:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-18T01:39:20.000Z", "avg_line_length": 41.1982378855, "max_line_length": 136, "alphanum_fraction": 0.6359067579, "num_tokens": 3177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8947894555814342, "lm_q1q2_score": 0.804524327669002}}
{"text": "\\section{Bayesian Model for Cubic Splines}\nNotice that the above definition can be easily extended to a Bayesian\nproblem: If we define a distribution for $f$, say $dP(f)$ then we may\nconsider the average risk\n\\[\n\\int_f  \\E [ || \\hat{g} - f ||^2 | f] \\, dP(f)\n\\]\nas a criterion. \n\nThis follows section 3.6 in the book by Hastie and Tibshirani.\n\nThe cubic smoothing spline can be derived from a number of Bayesian\nmodels for smoothing. The details are hard, but can be found in a book\nby Wahba.\n\nHere we will demonstrate a fairly simple example.\n\nRemember we can write any natural cubic spline as \n\\[\ng(x) = \\bB(x) \\bg{\\theta}.\n\\]\nConsider the following Bayesian set-up:\n\nModel assumptions: Assume the data $\\by$ follow a Gaussian distribution $N(\\bB\n\\bg{\\theta}, \\sigma^2 {\\mathbf I}_n)$. \n\nPrior assumptions: Assume $\\bg{\\theta}$ follows a multivariate\nGaussian prior distribution with mean $0$ and variance\n$\\sigma^2/\\lambda  \\bg{\\Omega}^{-1}$. \n\nit follows that the posterior distribution of $\\bg{\\theta}$ is\nmultivariate Gaussian with mean \n\\[\n\\E(\\bg{\\theta}|\\by) = \\bB(\\bB'\\bB +  \\lambda \\bg{\\Omega})^{-1} \\bB'\\by\n\\]\nwhich is the natural smoothing spline estimate of $\\bg{\\theta}$.\n\n\n\n\n\n\n\n", "meta": {"hexsha": "24751aa6decd823c8bed62158ae31db93eb4a70a", "size": 1193, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-06-05.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-06-05.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-06-05.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 27.1136363636, "max_line_length": 78, "alphanum_fraction": 0.7066219614, "num_tokens": 339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811591688146, "lm_q2_score": 0.8333246035907932, "lm_q1q2_score": 0.8044758717783729}}
{"text": "\\section*{Principal Component Analysis}\n$\\mathbf{X} \\in \\mathbb{R}^{D \\times N}$. $N$ observations, $K$ rank.\\\\\n1. Empirical Mean: $\\overline{\\mathbf{x}} = \\frac{1}{N} \\sum_{n=1}^N \\mathbf{x}_n$.\\\\\n2. Center Data: $\\overline{\\mathbf{X}} = \\mathbf{X} - [\\overline{\\mathbf{x}}, \\ldots, \\overline{\\mathbf{x}}] = \\mathbf{X} - \\mathbf{M}$.\\\\\n3. Cov.: $\\boldsymbol{\\Sigma} = \\frac{1}{N\t} \\sum_{n=1}^N (\\mathbf{x}_n - \\overline{\\mathbf{x}}) (\\mathbf{x}_n - \\overline{\\mathbf{x}})^\\top = \\frac{1}{N} \\overline{\\mathbf{X}}\\overline{\\mathbf{X}}^\\top$.\\\\\n4. Eigenvalue Decomposition: $\\boldsymbol{\\Sigma} = \\mathbf{U} \\boldsymbol{\\Lambda} \\mathbf{U}^\\top$.\\\\\n5. Select $K < D$, only keep $\\mathbf{U}_K, \\boldsymbol{\\lambda}_K$.\\\\\n6. Transform data onto new Basis: $\\overline{\\mathbf{Z}}_K = \\mathbf{U}_K^\\top \\overline{\\mathbf{X}}$.\\\\\n7. Reconstruct to original Basis: $\\tilde{\\overline{\\mathbf{X}}} = \\mathbf{U}_k \\overline{\\mathbf{Z}}_K$.\\\\\n8. Reverse centering: $\\tilde{\\mathbf{X}} = \\tilde{\\overline{\\mathbf{X}}} + \\mathbf{M}$.\\\\\nFor compression save $\\mathbf{U}_k, \\overline{\\mathbf{Z}}_K, \\overline{\\mathbf{x}}$.\\\\\n$\\mathbf{U}_k \\in \\mathbb{R}^{D \\times K}, \\boldsymbol{\\Sigma} \\in \\mathbb{R}^{D \\times D}, \\overline{\\mathbf{Z}}_K \\in \\mathbb{R}^{K \\times N}, \\overline{\\mathbf{X}} \\in \\mathbb{R}^{D \\times N}$\n\n\\subsection*{Reconstruction Error Exercise}\n$\\tilde {\\mathbf{X}} = \\mathbf{U}_K \\mathbf{U}_K^\\top \\bar {\\mathbf{X}}$, the error is $\\frac{1}{N} \\sum_{i=1}^N ||\\tilde x_i - \\bar x_i||_2^2$ \\\\\n$=\\frac{1}{N}||\\tilde{\\mathbf{X}}-\\bar{\\mathbf{X}}||_F^2 = \\frac{1}{N}||(\\mathbf{U}_K \\mathbf{U}_K^\\top - \\mathbf{I}_d)\\bar{\\mathbf{X}}||_F^2$ \\\\ \n$= \\frac{1}{N} \\text{trace}((\\mathbf{U}_K \\mathbf{U}_K^\\top - \\mathbf{I}_d)\\bar{\\mathbf{X}} \\bar{\\mathbf{X}}^\\top (\\mathbf{U}_K \\mathbf{U}_K^\\top - \\mathbf{I}_d)^\\top)$ \\\\\n$=\\text{trace}((\\mathbf{U}_K \\mathbf{U}_K^\\top - \\mathbf{I}_d) \\Sigma (\\mathbf{U}_K \\mathbf{U}_K^\\top - \\mathbf{I}_d))$ \\ $\\textcolor{gray}{\\Sigma = \\mathbf{U}\\Lambda \\mathbf{U}^\\top}$ \\\\\n$=\\text{trace}((\\mathbf{U}_K \\mathbf{U}_K^\\top  \\mathbf{U} -  \\mathbf{U})\\Lambda ( \\mathbf{U}^\\top \\mathbf{U}_K \\mathbf{U}_K^\\top -  \\mathbf{U}^\\top))$ \\\\\n$=\\text{trace}(([\\mathbf{U}_K ;\\mathbf{0}] -  \\mathbf{U})\\Lambda ([\\mathbf{U}_K; \\mathbf{0}] -  \\mathbf{U}^\\top)) $ \\\\\n$=\\text{trace}(\\sum_{i=K+1}^D \\lambda_i u_i u_i^\\top) = \\sum_{i=K+1}^D \\lambda_i \\cdot \\text{trace}(u_i u_i^\\top)\n$ \\\\\n$=\\sum_{i=K+1}^D \\lambda_i$ since $\\text{trace}(u_i u_i^\\top) = ||u_i||_2^2 = 1$\n\\subsection*{Iterative View}\nResidual $r_i$: $x_i - \\tilde{x}_i = I - uu^T  x_i$\\\\\nCov of $r$:  $\\frac{1}{n} \\sum_{i=1}^n (I-uu^T)x_i x_i^T (I-uu^T)^T =$ \\\\\n$(I-uu^T) \\Sigma (I-uu^T)^T = \\Sigma - 2\\Sigma u u^T + u u^T \\Sigma u u ^T = \\Sigma - \\lambda uu^T$ \\\\\n1. Find principal eigenvector of $(\\Sigma - \\lambda u u^T)$\\\\\n2. Which is the second eigenvector of $\\Sigma$\\\\\n3. Iterating to get $d$ principal eigenvector of $\\Sigma$\n\n\\subsection*{Power Method}\nPower iteration: $v_{t+1} = \\frac{Av_t}{||Av_t||}$, $\\lim_{t \\rightarrow \\infty} v_t = u_1$\\\\\nAssuming $\\langle u_1, v_0 \\rangle \\not = 0$ and $|\\lambda_1| > |\\lambda_j| (\\forall j \\geq 2)$\nThen $\\lambda_1 = \\lim_{t\\to \\infty}||\\mathbf{Av}_t||/||\\mathbf{v}_t||$\n", "meta": {"hexsha": "4cb9b4f658082a51796248e3d575f1f1b810f446", "size": 3198, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PCA.tex", "max_stars_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_stars_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-20T20:58:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-20T20:58:16.000Z", "max_issues_repo_path": "PCA.tex", "max_issues_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_issues_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PCA.tex", "max_forks_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_forks_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-06T16:55:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-21T01:02:09.000Z", "avg_line_length": 88.8333333333, "max_line_length": 206, "alphanum_fraction": 0.610068793, "num_tokens": 1426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750453562491, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.8044641421635981}}
{"text": "\\section{Linear Groups}\r\nIn this section, let $\\mathbb F=\\mathbb R$ or $\\mathbb C$.\r\nLet $M_{n\\times n}(\\mathbb F)$ be the set of $n\\times n$ matrices with entries in $\\mathbb F$.\r\nMatrix multiplication then gives us a binary operation on $M_{n\\times n}(\\mathbb F)$.\r\n$I_n$ is certainly an identiy element of this operation, so $M_{n\\times n}(\\mathbb F)$ is a monoid under this operation.\r\n\\begin{proposition}\r\n    An $n\\times n$ matrix is invertible iff its determinant is nonzero.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    In Vectors \\& Matrices.\r\n\\end{proof}\r\n\\begin{definition}\r\n    The set of $n\\times n$ matrix with entries in $\\mathbb F$ which has inverses, written as $\\operatorname{GL}_n(\\mathbb F)$, is a group under matrix multiplication.\r\n    Equivalently, by the preceding proposition, $\\operatorname{GL}_n(\\mathbb F)$ consists of all $n\\times n$ matrices with nonzero determinant.\r\n\\end{definition}\r\nThe map $\\det:\\operatorname{GL}_n(\\mathbb F)\\to\\mathbb F^\\times=(\\mathbb F\\setminus\\{0\\},\\times,1)$ is a (surjective) group homomorphism since $\\det(AB)=\\det(A)\\det(B)$.\r\n\\begin{definition}\r\n    The kernel of $\\det$ is called the special linear group $\\operatorname{SL}_n(\\mathbb F)$, which consists of all $n\\times n$ matrices $M$ with $\\det M=1$.\r\n\\end{definition}\r\nSo $\\operatorname{SL}_n(\\mathbb F)\\unlhd\\operatorname{GL}_n(\\mathbb F)$.\r\nBy Theorem \\ref{1_isom_thm}, we have $\\operatorname{GL}_n(\\mathbb F)/\\operatorname{SL}_n(\\mathbb F)\\cong\\mathbb F^\\times$.\\\\\r\nThe group $\\operatorname{GL}_n(\\mathbb F)$ acts on $\\mathbb F^n$ by $M\\star x=Mx$ (here $x$ is written as column vector).\r\nThis corresponds to a homomorphism $\\rho:\\operatorname{GL}_n(\\mathbb F)\\to\\operatorname{Sym}(\\mathbb F^n)$.\r\nNote that $\\rho$ is injective by considering the action of a matrix on the standard basis.\r\nAlso, the image of $\\rho$, which is isomorphic to $\\operatorname{GL}_n(\\mathbb F)$ by Theorem \\ref{1_isom_thm}, is precisely the set of invertible linear maps $\\mathbb F^n\\to\\mathbb F^n$.\r\n\\begin{proposition}\r\n    If $A$ is a $n\\times n$ matrix represents a linear transformaton $\\alpha:\\mathbb F^n\\to\\mathbb F^n$ in the standard basis $\\{e_i\\}$.\r\n    If we have another basis $\\{f_i\\}$, then in the new basis, $\\alpha$ is represented by $P^{-1}AP$ where $P$ is the (invertible) matrix with entries determined by the linear combination of $f_j$ by $\\{e_i\\}$.\r\n    That is\r\n    $$f_j=\\sum_{i=1}^nP_{ij}e_i$$\r\n    Group theoretically, the group $\\operatorname{GL}_n(\\mathbb F)$ can act on the set of all $n\\times n$ matrices, so the orbit of $A$ under this action is all matrices in the form $P^{-1}AP$, that is, the matrices that actually represents the ``same'' linear transformation but in different basis.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    It is easy to check that conjugating by invertible matrix is indeed an action, and the formula is just verification.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. Every complex matrix is conjugate to a matrix in the Jordan normal form.\r\n    For $2$-dimensional matrices, any complex $2\\times 2$ matrix is conjugate to one of\r\n    $$\r\n    \\begin{pmatrix}\r\n        \\lambda_1&0\\\\\r\n        0&\\lambda_2\r\n    \\end{pmatrix},\\lambda_1\\neq\\lambda_2;\r\n    \\begin{pmatrix}\r\n        \\lambda&0\\\\\r\n        0&\\lambda\r\n    \\end{pmatrix};\r\n    \\begin{pmatrix}\r\n        \\lambda&1\\\\\r\n        0&\\lambda\r\n    \\end{pmatrix}\r\n    $$\r\n    One can see easily by looking at eigenvalues that no two of them are conjugate to each other.\r\n    Also, for different value of $\\lambda$, in the latter two cases, any two matrices of the same type are not conjugate to each other either.\r\n    In the first, case, $\\operatorname{diag}(\\lambda_1,\\lambda_2),\\operatorname{diag}(\\mu_1,\\mu_2)\\iff \\{\\lambda_1,\\lambda_2\\}=\\{\\mu_1,\\mu_2\\}$.\\\\\r\n    Now we consider the stabilisers of them.\r\n    Consider an invertible matrix\r\n    $\\left(\\begin{smallmatrix}\r\n        a&b\\\\\r\n        c&d\r\n    \\end{smallmatrix}\\right)$.\r\n    Then a matrix of the first type is stabilised by it iff $b=c=0$, and every invertible matrix stabilises a matrix of the second type.\r\n    For the third type, if this matrix does stabilise a matrix of that kind, then we need $c=0,a=d$, so the stabilisers are the matrices of the form\r\n    $\\left(\\begin{smallmatrix}\r\n        a&b\\\\\r\n        0&a\r\n    \\end{smallmatrix}\\right)$.\\\\\r\n    2. Consider Mobius transformations $f(z)=\\frac{az+b}{cz+d},f'(z)=\\frac{a'z+b'}{c'z+d'}$, then $f\\circ f'=\\frac{a''z+b''}{c''z+d''}$ where we have\r\n    $$\\begin{pmatrix}\r\n        a&b\\\\\r\n        c&d\r\n    \\end{pmatrix}\r\n    \\begin{pmatrix}\r\n        a'&b'\\\\\r\n        c'&d'\r\n    \\end{pmatrix}\r\n    =\r\n    \\begin{pmatrix}\r\n        a''&b''\\\\\r\n        c''&d''\r\n    \\end{pmatrix}$$\r\n    which implies a homomorphism $\\phi:\\operatorname{SL}_2(\\mathbb C)\\to\\mathcal{M}$.\r\n    This homorphism is surjective since multiplying all of $a,b,c,d$ by a nonzero complex number does not change the Mobius transformation.\r\n    How about the kernel of $\\phi$?\r\n    Suppose\r\n    $$\\phi\\left(\\begin{pmatrix}\r\n        a&b\\\\\r\n        c&d\r\n    \\end{pmatrix}\\right)=\\operatorname{id}$$\r\n    So $az+b=(cz+d)z$ which has to be true for all $z\\in\\mathbb C$, hence $c=0,d=a,b=0$.\r\n    This implies that the matrix is either $I$ or $-I$.\r\n    By Theorem \\ref{1_isom_thm},\r\n    $$\\operatorname{PSL}_2(\\mathbb C)=\\operatorname{SL}_2(\\mathbb C)/\\{\\pm I\\}\\cong\\mathcal M$$\r\n\\end{example}\r\n\\begin{definition}\r\n    The $n^{th}$ orthogonal group is defined by\r\n    $$\\operatorname{O}(n)=\\{P\\in\\operatorname{GL}_n(\\mathbb R):PP^\\top=I\\}$$\r\n\\end{definition}\r\nNote that $PP^\\top=I\\iff P^\\top P=I$.\r\nThis is a group since\r\n$$\\forall P,Q\\in\\operatorname{O}(n),(PQ^{-1})(PQ^{-1})^\\top=(PQ^\\top)(PQ^\\top)^\\top=PQ^\\top QP^\\top=I$$\r\ntherefore $PQ^{-1}\\in \\operatorname{O}(n)$.\r\nAlso $I\\in \\operatorname{O}(n)$, hence $\\operatorname{O}(n)\\neq\\varnothing$, so indeed $\\operatorname{O}(n)\\le \\operatorname{GL}_n(\\mathbb R)$.\\\\\r\nIn addition, the columns of an orthogonal matrix forms an orthonormal basis for $\\mathbb R^n$, and the converse is also true.\r\n\\begin{lemma}\r\n    Let $P\\in\\operatorname{GL}_n(\\mathbb R)$, then $P\\in \\operatorname{O}(n)\\iff\\forall v,w\\in\\mathbb R^n, (Pv)\\cdot(Pw)\\iff v\\cdot w$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Any orthogonal matrix preserves lengths and angles.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\nNote that $\\det (A^\\top)=\\det (A)$, so $\\forall P\\in\\operatorname{O}(n),\\det P=\\pm 1$.\r\n\\begin{definition}\r\n    The $n^{th}$ special orthorgonal group $\\operatorname{SO}(n)$ consists of orthogonal matrices with determinant $1$.\r\n\\end{definition}\r\nOr equivalently, $\\operatorname{SO}(n)=\\ker(\\det|_{\\operatorname{O}(n)})$, so immediately we have $\\operatorname{SO}(n)\\unlhd\\operatorname{O}(n)$.\\\\\r\nTypical examples of non-special orthogonal matrices are refections.\r\nFor an unit vector $a\\in\\mathbb R^n$, we can consider the reflection $R_a:v\\mapsto v-2(v\\cdot a)a$.\r\nThis is obviously linear and can be geometrically interpreted as reflection.\r\nSo if we choose a basis for $\\mathbb R^n$ which consists of $a$ and an orthonormal basis for the subspace $a^\\perp=\\{v\\in\\mathbb R^n:v\\perp a\\}$, then the union of them gives an orthonormal basis for $\\mathbb R^n$, which induces the orthogonal matrix representing the reflection.\r\nAlternatively we can evaluate to get $R_a(v)\\cdot R_a(w)=v\\cdot w$ for every $v,w\\in\\mathbb R^n$.\r\nBut by its form in our specially chosen basis, we have $\\det R_a=-1$, so $R_a\\in \\operatorname{O}(n)\\setminus\\operatorname{SO}(n)$.\r\n\\begin{lemma}\r\n    $$\\operatorname{SO}(2)=\\left\\{\\begin{pmatrix}\r\n        \\cos\\theta&-\\sin\\theta\\\\\r\n        \\sin\\theta&\\cos\\theta\r\n    \\end{pmatrix}:\\theta\\in\\mathbb R\\right\\}$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Consider any $A=\\left(\\begin{smallmatrix}\r\n        a&b\\\\\r\n        c&d\r\n    \\end{smallmatrix}\\right)\\in\\operatorname{SO}(2)$, then since we have $AA^\\top=I$, $a=d,b=-c$.\r\n    Then $1=ad-bc=a^2+b^2$, so $a,b\\in [-1,1]$, so we can write $a=\\cos\\theta$, consequently $b=-\\sin\\theta$ (the sign does not matter since we can always do $\\theta\\mapsto -\\theta$).\r\n    The lemma follows.\r\n\\end{proof}\r\nNote that for $A\\in\\operatorname{O}(2)\\setminus\\operatorname{SO}(2)$, we have $a=-d,b=c$ and $a^2+c^2=1$, therefore\r\n$$\\operatorname{O}(2)\\setminus\\operatorname{SO}(2)=\\left\\{\\begin{pmatrix}\r\n    \\cos\\phi&\\sin\\phi\\\\\r\n    \\sin\\phi&-\\cos\\phi\r\n\\end{pmatrix}:\\phi\\in\\mathbb R\\right\\}=\\begin{pmatrix}\r\n    1&0\\\\\r\n    0&-1\r\n\\end{pmatrix}\\operatorname{SO}(2)$$\r\nOne immediately have the following corollaries.\r\n\\begin{corollary}\r\n    $\\operatorname{O}(2)\\setminus\\operatorname{SO}(2)$ consists of reflections.\r\n\\end{corollary}\r\n\\begin{corollary}\\label{two_reflections}\r\n    Everything in $\\operatorname{O}(2)$ is a product of at most $2$ reflections.\r\n\\end{corollary}\r\n\\begin{remark}\r\n    Corollary \\ref{two_reflections} can be generalized to $\\mathbb R^n$ by induction (with, of course, the replacement of $2$ by $n$).\r\n\\end{remark}\r\nWe proceed to analyze the rotations and reflections in $\\mathbb R^3$.\r\n\\begin{theorem}\r\n    Let $A\\in \\operatorname{SO}(3)$, then there is an unit vector $v\\in\\mathbb R^3$ such that $Av=v$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Suffice to show that $A$ has eigenvalue $1$.\r\n    Indeed, $\\det(A-I)=\\det(A^\\top-I)=\\det A\\det (A^\\top-I)=\\det(I-A)=(-1)^3\\det(A-I)=-\\det(A-I)$, hence $\\det(A-I)=0$.\r\n\\end{proof}\r\nIn fact, we can generalize $3$ to any $2n+1$ for $n\\in\\mathbb N$ using exactly the same way.\r\n\\begin{corollary}\\label{SO3_conj}\r\n    Every $A\\in\\operatorname{SO}(3)$ is conjugate to a matrix in the form\r\n    $$\\begin{pmatrix}\r\n        1&0&0\\\\\r\n        0&\\cos\\theta&-\\sin\\theta\\\\\r\n        0&\\sin\\theta&\\cos\\theta\r\n    \\end{pmatrix}$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    By the theorem there is some unit vector $f_1\\in\\mathbb R^3$ such that $Af_1=f_1$.\r\n    And choose an orthonormal basis $f_2,f_3$ of $f_1^\\perp$, so that $f_1,f_2,f_3$ is an orthonormal basis of $\\mathbb R^3$.\r\n    Then for $i=2,3$, we have $(Af_i)\\cdot f_1=(Af_i)\\cdot (Af_1)=f_i\\cdot f_1=0$.\r\n    So $Af_i$ is a linear combination of $f_2,f_3$ only.\r\n    Hence in this new basis, the matrix will look like\r\n    $$A'=\\begin{pmatrix}\r\n        1&0&0\\\\\r\n        0&a&b\\\\\r\n        0&c&d\r\n    \\end{pmatrix}$$\r\n    By computing $A'A'^\\top=I$, we find\r\n    $$\\begin{pmatrix}\r\n        a&b\\\\\r\n        c&d\r\n    \\end{pmatrix}=\\begin{pmatrix}\r\n        \\cos\\theta&-\\sin\\theta\\\\\r\n        \\sin\\theta&\\cos\\theta\r\n    \\end{pmatrix}$$\r\n    for some $\\theta$.\r\n    The result follows.\r\n\\end{proof}\r\nNote that we can manipulate the change-of-basis matrix to make it special orthogonal.\r\n\\begin{corollary}\r\n    Every element in $\\operatorname{O}(3)$ is the composition of at most $3$ reflections.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Every element in $\\operatorname{SO}(3)$ is the composition of two reflections by observing\r\n    $$\\begin{pmatrix}\r\n        1&0&0\\\\\r\n        0&\\cos\\theta&-\\sin\\theta\\\\\r\n        0&\\sin\\theta&\\cos\\theta\r\n    \\end{pmatrix}=\\begin{pmatrix}\r\n        1&0&0\\\\\r\n        0&1&0\\\\\r\n        0&0&-1\r\n    \\end{pmatrix}\\begin{pmatrix}\r\n        1&0&0\\\\\r\n        0&\\cos(-\\theta)&\\sin(-\\theta)\\\\\r\n        0&\\sin(-\\theta)&-\\cos(-\\theta)\r\n    \\end{pmatrix}$$\r\n    and using Corollary \\ref{SO3_conj}.\r\n    Now choose any reflection $R$, then $\\operatorname{O}(3)\\setminus\\operatorname{SO}(3)=R\\operatorname{SO}(3)$, therefore every other element in $\\operatorname{O}(3)$ is a composition of at most $3$ reflections.\r\n\\end{proof}\r\n", "meta": {"hexsha": "1d71a84d1edef2058791d4a7431461cf40b449de", "size": 11435, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10/linear.tex", "max_stars_repo_name": "david-bai-notes/IA-Groups", "max_stars_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "10/linear.tex", "max_issues_repo_name": "david-bai-notes/IA-Groups", "max_issues_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "10/linear.tex", "max_forks_repo_name": "david-bai-notes/IA-Groups", "max_forks_repo_head_hexsha": "98be673eb3a1fb62f01ba45168e1997eb1171541", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.742081448, "max_line_length": 300, "alphanum_fraction": 0.6535198951, "num_tokens": 3791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8840392863287585, "lm_q1q2_score": 0.8043935402434135}}
{"text": "\\section{Limits and Continuity}\\label{sec:LimitsContinuityPartialDifferentiation}\n\nTo develop calculus for functions of one variable, we needed to make\nsense of the concept of a limit, which was used in the definition of a\ncontinuous function and the derivative of a function. Limits involving\nfunctions of two variables can be considerably more difficult to deal\nwith; fortunately, most of the functions we encounter are fairly easy\nto understand.\n\nThe potential difficulty is largely due to the fact that there are\nmany ways to ``approach'' a point in the $x$-$y$ plane. If we want to\nsay that $\\ds\\lim_{(x,y)\\to(a,b)}f(x,y)=L$, we need to capture the\nidea that as $(x,y)$ gets close to $(a,b)$ then $f(x,y)$ gets close to\n$L$. For functions of one variable, $f(x)$, there are only two ways\nthat $x$ can approach $a$: from the left or right. But there are an\ninfinite number of ways to approach $(a,b)$: along any one of an\ninfinite number of straight lines, or even along a curved path in the $x,y$-plane. We might hope that it's\nreally not so bad---suppose, for example, that along every possible\nline through $(a,b)$ the value of $f(x,y)$ gets close to $L$; surely\nthis means that ``$f(x,y)$ approaches $L$ as $(x,y)$ approaches\n$(a,b)$''. Sadly, no.\n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize12cm\\epsfbox{images/weird_limit.eps}}} at 0 0\n\\endpicture}}\n%\\endtexonly\n\\caption{$\\ds f(x,y)={xy^2\\over x^2+y^4}$}\n\\label{fig:weird limit}\n\\end{figure}\n\n\\begin{example}{Weird Limit}{weird limit}\nAnalyze $f(x,y)=xy^2/(x^2+y^4)$.\n\\end{example}\n\\begin{solution}\nWhen $x=0$ or $y=0$, $f(x,y)$ is 0, so the limit of $f(x,y)$ approaching the\norigin along either the $x$ or $y$ axis is 0. Moreover, along the line\n$y=mx$, $f(x,y)=m^2x^3/(x^2+m^4x^4)$. As $x$ approaches 0 this expression\napproaches 0 as well. So along every line through the origin $f(x,y)$\napproaches 0. Now suppose we approach the origin along $x=y^2$. Then \n$$f(x,y)={y^2y^2\\over y^4+y^4}={y^4\\over2y^4}={1\\over2},$$\nso the limit is $1/2$. Looking at Figure~\\ref{fig:weird limit}, it\nis apparent that there is a ridge above $x=y^2$. Approaching the\norigin along a straight line, we go over the ridge and then drop down\ntoward 0, but approaching along the ridge the height is a constant\n$1/2$. \n\\end{solution}\n\nFortunately, we can define the concept of limit without needing to\nspecify how a particular point is approached---indeed, in \nDefinition~\\ref{def:limitprecise}, we didn't need the concept of\n``approach.'' Roughly, that definition says that when $x$ is \nclose to $a$ then $f(x)$ is close to $L$; there is no mention of\n``how'' we get close to $a$. We can adapt that definition to two\nvariables quite easily:\n\n\\begin{definition}{Limit of a Multivariate Function}{limit}\nSuppose $f(x,y)$ is a function. We say that \n$$\\lim_{(x,y)\\to\n  (a,b)}f(x,y)=L$$\n if for every $\\epsilon>0$ there is a $\\delta > 0$ so that\n  whenever $0 < \\sqrt{(x-a)^2+(y-b)^2} < \\delta$, $|f(x,y)-L|<\\epsilon$.\\index{limit!multivariate function}\n\\end{definition}\n\nThis says that we can make $|f(x,y)-L|<\\epsilon$, no matter how small\n$\\epsilon$ is, by making the distance from $(x,y)$ to $(a,b)$ ``small\nenough''. \n\n\\begin{example}{Multivariate Limit}{multilimitone}\nShow that $\\ds \\lim_{(x,y)\\to(0,0)}{3x^2y\\over\n\tx^2+y^2}=0$.\n\\end{example}\n\\begin{solution}\nSuppose $\\epsilon>0$. Then\n$$\\left|{3x^2y\\over x^2+y^2}\\right|={x^2\\over x^2+y^2}3|y|.$$\nNote that $x^2/(x^2+y^2)\\le1$ and\n$|y|=\\sqrt{y^2}\\le\\sqrt{x^2+y^2}<\\delta$. So\n$${x^2\\over x^2+y^2}3|y|<1\\cdot 3\\cdot \\delta.$$\nWe want to force this to be less than $\\epsilon$ by picking $\\delta$\n``small enough.'' If we choose $\\delta=\\epsilon/3$ then\n$$\\left|{3x^2y\\over x^2+y^2}\\right|< 1\\cdot 3\\cdot{\\epsilon\\over3}=\n\\epsilon.$$\n\\end{solution}\n\nRecall that a function $f(x)$ is continuous at $x=a$ if \n$\\ds\\lim_{x\\to a}f(x)=f(a)$. We can say exactly the same thing about\na function of two variables: $f(x,y)$ is continuous at $(a,b)$ if \n$\\ds\\lim_{(x,y)\\to (a,b)}f(x,y)=f(a,b)$.\n\nThe function $f(x,y)=3x^2y/(x^2+y^2)$ is not continuous at $(0,0)$,\nbecause $f(0,0)$ is not defined. However, we know that \n$\\ds \\lim_{(x,y)\\to(0,0)}f(x,y)=0$, so we can make a continuous function,\nby extending the definition of $f$ so that $f(0,0)=0$.\nThis surface is shown in Figure~\\ref{fig:removable discontinuity}.\n\n\\begin{figure}[H]\n%\\texonly\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize8cm\\epsfbox{images/removable_discont.eps}}} at 0 0\n\\endpicture}}\n%\\endtexonly\n\\caption{$\\ds f(x,y)={3x^2y\\over x^2+y^2}$}\n\\label{fig:removable discontinuity}\n\\end{figure}\n\nNote that we cannot extend the definition of the function in Example~\\ref{exa:weird limit}\nto create a continuous function, since the limit does not exist as we approach $(0,0)$.\n\nFortunately, the functions we will be working with will usually be\ncontinuous almost everywhere.\nAs with single variable functions, two classes of common functions are\nparticularly useful and easy to describe. A\npolynomial\\index{polynomial!of two variables} in two\nvariables is a sum of terms of the form $ax^my^n$, where $a$ is a real\nnumber and $m$ and $n$ are non-negative integers. A rational\nfunction\\index{function!of two variables}\nis a quotient of polynomials.\n\n\\begin{theorem}{Continuity of Functions}{ContFunctTheorem}\nPolynomials are continuous everywhere. Rational functions are\ncontinuous everywhere they are defined.\n\\end{theorem}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:LimitsContinuityPartialDifferentiation}}\n\n\\begin{enumialphparenastyle}\n\nDetermine whether each limit exists. If it does, find the limit\nand prove that it is the limit; if it does not, explain how you know.\n\n\\begin{ex}\n$\\ds\\lim_{(x,y)\\to(0,0)}{x^2\\over x^2+y^2}$\n\\begin{sol}\nNo limit; use $x=0$ and $y=0$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\lim_{(x,y)\\to(0,0)}{xy\\over x^2+y^2}$\n\\begin{sol}\nNo limit; use $x=0$ and $x=y$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\lim_{(x,y)\\to(0,0)}{xy\\over 2x^2+y^2}$\n\\begin{sol}\nNo limit; use $x=0$ and $x=y$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\lim_{(x,y)\\to(0,0)}{x^4-y^4\\over x^2+y^2}$\n\\begin{sol}\nLimit is zero.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\lim_{(x,y)\\to(0,0)}{\\sin(x^2+y^2)\\over x^2+y^2}$\n\\begin{sol}\nLimit is 1.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\lim_{(x,y)\\to(0,0)}{xy\\over \\sqrt{2x^2+y^2}}$\n\\begin{sol}\nLimit is zero.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\lim_{(x,y)\\to(0,0)} {e^{-x^2-y^2}-1\\over x^2+y^2}$\n\\begin{sol}\nLimit is $-1$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\lim_{(x,y)\\to(0,0)}{x^3+y^3\\over x^2+y^2}$\n\\begin{sol}\nLimit is zero.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\lim_{(x,y)\\to(0,0)}{x^2 + \\sin^2 y\\over 2x^2+y^2}$\n\\begin{sol}\nNo limit; use $x=0$ and $y=0$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\lim_{(x,y)\\to(1,0)}{(x-1)^2\\ln x\\over(x-1)^2+y^2}$\n\\begin{sol}\nLimit is zero.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\lim_{(x,y)\\to(1,-1)}{3x+4y}$\n\\begin{sol}\nLimit is $-1$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\n$\\ds\\lim_{(x,y)\\to(0,0)}{4x^2y\\over x^2+y^2}$\n\\begin{sol}\nLimit is zero.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nDoes the function $\\ds f(x,y)={x-y\\over 1+x+y}$ \nhave any discontinuities?  What about \n$\\ds f(x,y)={x-y\\over 1+x^2+y^2}$?  Explain.\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "d28dc6cea58d785f1ca3f2e1216d7b72d03e094c", "size": 7489, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14-partial-differentiation/14-2-limits-continuity.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "14-partial-differentiation/14-2-limits-continuity.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "14-partial-differentiation/14-2-limits-continuity.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7330508475, "max_line_length": 107, "alphanum_fraction": 0.6817999733, "num_tokens": 2718, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.9149009642742806, "lm_q1q2_score": 0.8043322340239918}}
{"text": "\\chapter{Elementary Principles}\n\\section{Mechanics of a Particle}\n\\textbf{Linear Momentum}\\\\\nLet $\\textbf{r}$ be the radius vector of a particle from some given origin and $\\textbf{v}$ its vector velocity.\n$$\\textbf{v}=\\frac{d\\textbf{r}}{dt}$$\nThe linear momentum $\\textbf{p}$ of the particle is \n$$\\textbf{p}=m\\textbf{v}$$\nNewton's second law of motion  states that there exist frames of reference in which the motion of the particle is described by the differential equation\n$$\\textbf{F}=\\frac{d\\textbf{p}}{dt}\\equiv\\dot{\\textbf{p}}$$\n$$\\textbf{F}=\\frac{d}{dt}(m\\textbf{v})$$\nIf the mass of particle is constant\n$$\\textbf{F}=m\\frac{d\\textbf{v}}{dt}=m\\textbf{a}$$\nWhere $\\textbf{a}$ is the vector acceleration of the particle\nThe equation of motion is thus a differential equation of second order, assuming $\\textbf{F}$ does not depend on higher-order derivatives.\\\\\\\\\n\\textbf{\\textit{Conservation theorem for the Linear Momentum of a Particle: If the total force $\\vec{F}$ is zero, then $\\dot{\\vec{p}}$, is conserved.}}\\vspace{0.5cm}\n\\\\\\\\\n\\textbf{Angular Momentum}\\vspace{0.2cm}\\\\\nThe angular momentum of the particle about point $O$, denoted by $\\textbf{L}$, is defined as\n$$\\textbf{L}=\\textbf{r}\\times\\textbf{p}$$\nwhere $\\textbf{r}$ is the radius vector from $O$ to the particle. The moment of force or torque about $O$ \n $$\\textbf{N}=\\textbf{r}\\times\\textbf{F}$$\n $$\\textbf{r}\\times\\textbf{F}=\\textbf{N}=\\textbf{r}\\times\\frac{d}{dt}(mv)$$\n using the vector identity\n $$\\frac{d}{dt}(\\textbf{r}\\times m\\textbf{v})\\textbf{v}\\times m\\textbf{v}+=\\textbf{r}\\times\\frac{d}{dt}(m\\textbf{v})$$\n$$\\textbf{N}=\\frac{d}{dt}(\\textbf{r}\\times m\\textbf{v})=\\frac{d\\textbf{L}}{dt}\\equiv \\dot{\\textbf{L}}$$\nNote that both $\\textbf{N}$ and $\\textbf{L}$ depend on the point $O$ about which the moments are taken.\\\\\n\\textit{Conservation Theorem for the Angular Momentum of a Particle: If the total torque, $\\textbf{N}$,is zero then $\\dot{\\textbf{L}}=0$, and the angular momentum $\\textbf{L}$ is conserved. }\\\\\\\\\n\\textbf{Energy}\\\\\nNext consider the work done by the external force $\\textbf{F}$ upon the particle in going from point 1 to point 2. \\\\\nThis work is \n$$W_{12}=\\int\\limits_{1}^{2}\\textbf{F}\\cdot d\\textbf{s}$$\n$$\\int\\textbf{F}\\cdot d\\textbf{s}=m\\int\\frac{d\\textbf{v}}{dt}\\cdot\\textbf{v}dt=\\frac{m}{2}\\int\\frac{d}{dt}(v^2)dt$$\n$$W_{12}=\\frac{m}{2}(v_2^2-v_1^2)$$\nThe scalar quantity $mv^2/2$ is called the kinetic energy of the particle and is denoted by $T$. so that the work done is equal to the change in the kinetic energy.\n\\begin{equation}\nW_{12} =T_2-T_1\\label{EP-01}\n\\end{equation}\nif the force field is such that the work $W_{12}$ is the same for any physically possible path between points 1 and 2, then the force (and the system) is said to be conservative.\\\\\nor\n$$\\oint\\textbf{F}\\cdot\\textbf{s}=0 d$$\n$\\textbf{F}$ be the gradient of some scalar function of position\n$$\\textbf{F}=-\\nabla V(\\textbf{r})$$\nwhere $V$ is called the potential energy.\n$$\\textbf{F}\\cdot d\\textbf{s}=-dV$$\nor\n$$F_s=-\\frac{\\partial V}{\\partial s}$$\nWe can add to $V$ any quantity constant in space, without affecting  the results. Hence the zero level of $V$ is arnitrary.\\\\\nFor a consetvative system, the work done by the forces is \n\\begin{equation}\nW_{12}=V_1-V_2\\label{EP-02}\n\\end{equation}\nCombining Eq.(\\ref{EP-01}) with Eq.(\\ref{EP-02}),we have the result \n$$T_1+V_1=T_2+V_2$$\n\\textbf{\\textit{Energy Conservation Theorem for a Particle: If the forces acting on a particle are consetvative, then the total energy of the particle, $T+V$,is conserved}}\\\\\n\\begin{note}\n\tThe force applied to to a particle may in some circumstances be given by the gradient of a scalar function that depends explicity on both the position of the particle and the time. However, the work done on the particle when it travels a distance $ds$.\n\t$$\\textbf{F}\\cdot{d\\textbf{s}=\\frac{\\partial V}{\\partial s}ds}$$\n\tis then no longer the total change in $-V$ during the displacement, since $V$ also changes explicitly with time as the particle moves. Hence, the work done as the particle goes from point 1 to point 2 is no longer the difference in the function $V$ between those points. While a total  energy $T+V$ may still be defined, it is not consetved during the course of the particle's motion.\n\\end{note}\n\\section{Mechanics of a system of Particle}\nWhen considering a system of particles, we must distinguish between the external forces acting on the particles due to source outside the system and internal forces on some particle $i$ due to all other particles in the system.\\\\\\\\\n\\textbf{Linear Momentum}\\\\\nEquation of motion for the $i^{th}$ particle\n$$\\vec{F}_i^{(e)}+\\sum\\limits_{j}\\vec{F}_{ji}=\\vec{\\dot{p}_i}$$\n$\\vec{F}_i^{(e)}$- external force\\\\\n$\\vec{F}_{ji}$- internal force on the $i^{th}$ particle due to the $j^{th}$ particle.\\\\\\\\\nAssume $\\vec{F}_{ij}$ , like ${F}_i^{(e)}$ obey Newton's third law  ie. $\\vec{F}_{ij}= - \\vec{F}_{ji}$,\\\\\nthis assumption some times referred to as \\textit{The weak law of action and reaction}.\\\\\n$$\\therefore \\text{ we get }\\quad \\frac{d^2}{dt^2}\\sum\\limits_{i}m_ir_i=\\sum\\limits_{i}{F}_i^{(e)}+\\sum\\limits_{i,j ,\\ i\\neq j}F_{ji}$$\n$$\\frac{d^2}{dt^2}\\sum\\limits_{i}m_ir_i=\\sum\\limits_{i}{F}_i^{(e)}$$\nLet's define $\\vec{R}$ as the average of radii vectors of the particles weighted in proportion to their mass.\n$$\\vec{R}=\\frac{\\sum m_i \\vec{r}_i}{\\sum m_i}=\\frac{\\sum m_i \\vec{r}_i}{M}$$\nvector $\\vec{R}$ defines a point known as the centre of mass\n$$M\\frac{d^2 R}{dt^2}=\\sum\\limits_{i}\\vec{F}_i^{(e)}\\equiv \\vec{F}^{(e)}$$\nThe centre of mass moves as if the total external force were acting on the entire mass of the system concentrated at the centre of mass. The total limear momentum of system.\n$$\\vec{P}=\\sum m_1\\frac{d\\vec{r_i}}{dt}=M\\frac{d\\vec{R}}{dt}$$\nie. total mass of the system times the velocity of the center of mass\\\\\nconservation for linear momentum of a system of particles: if the total external force is zero, the total linear momentum is conserved.\\\\\\\\\n\\textbf{Angular Momentum}\\\\\n\\begin{align*}\n\\sum\\limits_{i}(\\vec{r_i}\\times\\dot{P_1})&=\\sum\\limits_{i}\\frac{d}{dt}(\\vec{r_i}\\times\\vec{P_i})=\\dot{L}\\\\\n&=\\sum\\limits_{i}\\vec{r_i}\\times\\vec{F}_i^{(e)}+\\sum\\limits_{i,j}\\vec{r_i}\\times\\vec{F}_{ji}\\\\\n\\vec{r_i}-\\vec{r_j}&=\\vec{r_{ij}}\\\\\n\\therefore \\text{ RHS of equation becomes },\\quad\\vec{r_{ij}}\\times \\vec{F_{ji}}\n\\end{align*}\nThe internal forces between two particles. in addition to being equal and opposite, also lie along the line going the particles (This condition known as the strong law of action and reaction.)\\\\\nThen all cross products vanish,\\\\\n$$\\frac{d\\vec{L}}{dt}=\\vec{N}^{(e)}$$\\\\\nThe time derivative of angular momentum thus equal to the moment of the external force about the given point.\\\\\\\\\nConservation of total angular momentum: $L$ \\textit{is constant in time if the applied (external) torque is zero.} \\\\\\\\\\begin{note}\n\tThis is a vector theorem,\n\t$\\therefore$ $L_z$ will be conserved if $N_z^{(e)}$ is zero, even if $N_x^{(e)}$ and $N_y^{(e)}$ are not zero.\\\\\n\\end{note} \n\\textbf{To represent $\\vec{L}$ in terms of centre of mass,}\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=5cm]{EP-02}\n\\end{figure}\nLet $R$ be the radius vector from $O$ to the centre of mass to the $i^{th}$ particle\\\\\n\\begin{align*}\n\\vec{r_1}&=\\vec{r^\\prime_1}+\\vec{R}\n\\intertext{and}\n\\vec{v_1}&=\\vec{v^\\prime_1}+\\vec{\\mathrm{v}}\n\\intertext{where}\n\\mathrm{v}&=\\frac{dR}{dt}\\text{velocity of CM relative to $O$ }\n\\intertext{and}\nv^\\prime_1&=\\frac{dr^\\prime}{dt}\n\\end{align*}\nis the velocity of the $i^{th}$ particle relative to centre of mass of the system\\\\\n$\\therefore$ total angular momentum\n$$\\vec{L}=\\vec{R}\\times M\\vec{\\mathrm{v}}+\\sum\\limits_{i}r^\\prime_i\\times p^\\prime_i$$\nTotal angular momentum about a point $O$ is the angular momentum of motion concentrated at the centre of mass, plus the angular momentum of motion about the centre of mass.\\\\\n\\begin{note}\n\t$L$ depends on origin $O$ through the vector $\\vec{R}$ \n\tonly if the centre of mass is at rest with respect to $O$ will the angular momentum be independent of point of reference.\n\\end{note}\n\\textbf{Energy Equation}\\\\\nWork done by all forces in moving a system from an initial configuration $1$ to a final configuration $2$\n\\begin{align*}\nW_{12}&=\\sum\\limits_{i}\\int\\limits_{1}^{2}\\vec{F}_i\\cdot d\\vec{s}_i=\\sum\\limits_{i}\\int\\limits_{1}^{2}F_i^{(e)}\\cdot d s_i+\\sum\\limits_{i,j ,i+j}\\ \\int\\limits_{1}^{2}\nF_{ji}\\cdot ds_i\n\\intertext{by equation of motion}\n\\sum\\limits_{i}\\int\\limits_{1}^{2}\\vec{F}_i\\cdot d\\vec{s}_i&=\\sum\\limits_{i}\\int\\limits_{1}^{2}m_i \\vec{\\dot{v}_i}\\cdot\\vec{v}_i dt=\\sum\\limits_{i}\\int\\limits_{1}^{2}r(\\frac{1}{2}m_iv_i^2)\\\\\n\\therefore W_{12}&=T_2-T_1\n\\intertext{\tWhere $T$, the total kinetic energy of system}\nT=\\frac{1}{2} \\sum\\limits_{i}m v_i^2\n\\intertext{Transformation to centre of mass coordinates}\nT=\\frac{1}{2} Mv^2+\\frac{1}{2}\\sum m_i {v^\\prime}_i^2\n\\end{align*}\nie. kinetic energy obtained if all mass were concentrated at the centre of mass $+$\n kinetic energy of motion about the centre of mass. When external forces are derivable in terms of the gradient of a potential the first term can be written as\n  \\begin{align*}\n \\sum\\limits_{i}\\int\\limits_{1}^{2}\\vec{F}_i^{(e)}\\cdot d {s}_i&=-\\sum\\limits_{i}\\int\\limits_{1}^{2}\\nabla _i v_i\\cdot d \\vec{s}=-\\sum\\limits_{i}-v_i \\Bigr |_{1}^{2}\n \\intertext{If the internal forces are also conservative.}\n v_{ij}&=v_{ij}(|r_i-r_j|)\n \\intertext{When forces are all conservative}\n \\sum\\limits_{i,j ,i+j}\\ \\int\\limits_{1}^{2}\n F_{ji}\\cdot ds_i&=-\\sum\\limits_{i}\\int\\limits_{1}^{2}(\\nabla _i v_{i j}\\cdot d s_i+\\nabla_j v_{ij}\\cdot ds_i)\\\\\n \\vec{r}_{ij}&=(r_i-r_j), \\nabla_{i j}\\text{ gradient with respect to }r_{i j}\\\\\n  \\text{ Then}{ \\nabla_i} v_{ij}&={\\nabla_{i j}} v_{ij} =-\\nabla_j v_{ij}\\\\\n ds_i-ds_i&=dr_i-dr_i=dr_{ij}\n\\intertext{$\\therefore $ total work arising from internal force}\n&=\\frac{-1}{2}\\sum\\limits_{i,j ,i+j}\\ \\int\\limits_{1}^{2}\\nabla_{i j} \\nabla_{i j}\\cdot d\\vec{r}_{ij}=\\frac{-1}{2}\\sum\\limits_{i,j ,i+j} v_{ij}\\Bigr |_{1}^{2}\n \\end{align*}\n $\\therefore$ The external and internal force are both derivable from potentials so it is possible to define a total potential energy $v$ of the system.\n $$v=\\sum\\limits_{i}v_i+\\frac{1}{2}\\sum\\limits_{i,j ,i+j}v_{ij}$$\n\\begin{itemize}\n\t\\item For rigid body internal potential is constant\n\t\\item  In rigid body internal forces do no work.\n\\end{itemize}\n\\section{Constraints}\nWe have\n$$ m_i\\ddot{\\mathbf{r}}_1=\\textbf{F}_1^{(e)}+\\sum\\limits_{j}\\textbf{F}_{ji}$$\nAll problems in mechanics be reduced to solving a set of differential equation. But this view is over simplified even from a purely physicals standpoint \\\\\neg:it is necessary to take constraints\\\\\\\\\nWhile solving a problem along with this we have to take consideration of constraints that limits the motion of the system.\\\\\nConstraints are classified in various ways.\\\\\\\\\n\\begin{itemize}\n\\item \\textit{Holonomic Constraints}: Constraint equations are integrable if the conditions of constraint can be expressed aas equarions connecting the coordinates of the particles (and possible the time) having the form\n\t$$ f(\\textbf{r}_1,\\textbf{r}_2, \\textbf{r}_3,.....t)=0$$\n\tThen constraints are holonomic\n\teg:rigid body $(\\textbf{r}_i-\\textbf{r}_j)^2-c_{ij}^2=0$\n\ta particle constrained to move along any curve or on a given surface equation\\\\\n\\item \\textit{Non Holonomic }:\nConstraint which are not expressible as above are non holonomic constraint.\nNon-holonomic constraints include nonintegrable differential constraints,constraint conditions involve higher order derivatives, or may in the form of inequality.\\\\\neg:Aparticle placed on the surface of a sphere, walls of a gas container\\\\\n\\item \\textit{Rheonomous Constraints}:\nRheonomous constraints are which the constraint equation contain time as an explicit variable.\\\\\n\\item \\textit{Scleronomous}: \nConstraints which the constraint equations are not ecplicity dependent on time.\\\\\n\\end{itemize}\n\\textbf{Because of Constraints}:\\\\\n1) The coordinates $r_i$ are no longer all independent since they are connected by the equation of constraint hence equation of motion are not all independent.\\\\\n2)The forces of constraint are unknown and must be obtained from solution.\\\\\nIn case of holonomic constraints the first difficulty is solved by introduction of generalized coordinates.\\\\\\\\\n\\section{Generalized Coordinates}\n\\begin{itemize}\n\t\\item A system of N-particles, free from constraints has $3N$ independent coordinates or degree of freedom. \n\t\\item If the exist holonomic constraints expressed in $k$ equations in the form:\\\\\n\t$f(r_1,r_2.....t)=0$\\\\\n\twe use these equations to eliminate $k$ of the $3N$ coordinates\n\t\\item We left with $3N-k$ independent coordinates and system said to have $3N-k$ degrees of freedom.\n\t\\item Elimination of dependend variable is done by introduction of new $3N-k$ , independent variables $q_1,q_2.....q_{3N-k}$ in terms of which the old cordinates ate expressed by equation of form\n\\begin{align*}\n\t\\textbf{r}_1=\\textbf{r}_1(q_1,q_2&.......q_{3N-k}, t)\\\\\n\t&....\\\\\n\t&....\\\\\n\t\\textbf{r}_N=\\textbf{r}_N(q_1,q_2&.......q_{3N-k}, t)\n\\end{align*}\n\tThese contain constrainst implicitly\\\\\n\tGeneralized coordinates ate different from conventional orthogonal position coordinates. All sorts of quantities  may be involved to serve as generalized coordinates\n\t\\begin{note}\n\t\tIf the constraint is non-holonomic the equations expressing the constraint cannot be used to eliminate the dependent coordinates.\n\t\\end{note}\n\teg: Object rolling on a rough surface without slipping.\n\\end{itemize}\n\\section{D'Alembert's Principle and Lagrange's Equations}\n\\textit{\\textbf{Virtual Displacement}}:\\\\A change in the configuration of the system as the result of any arbitrary infinitesimal chabge of the coordinates $\\delta \\textbf{r}_i$ consistent with the forces and constraints imposed on the system at the given instant $t$.\\\\\\\\\n\\textbf{Principle of Virtual Work}\\\\\\\\\nFor a system in rquilibrium\\\\\ntotal fore on each particle $\\textbf{F}_i=0$\\\\\nThen virtual work of $\\textbf{F}_i$ in desplacement $\\delta \\textbf{F}_i$\n\\begin{equation}\n\\sum\\limits_{i}\\textbf{F}_i\\cdot\\delta \\textbf{r}_i=0\\label{EP-01}\n\\end{equation}\n\\begin{align*}\n\\intertext{Let}\n\\textbf{F}_i=\\textbf{F}_i^{(a)}+\\textbf{f}_i\\hspace{3cm}\\textbf{F}_i^{(a)}\\rightarrow \\text{applied force}\\\\\n\\textbf{f}_i\\rightarrow \\text{force of constraint}\\\\\n\\end{align*}\n$\\therefore (\\ref{EP-01}) $ \\quad becomes \\quad $\\sum_{i} \\mathbf{F}_{i}^{(a)} \\cdot \\delta \\mathbf{r}_{i}+\\sum_{i} \\mathbf{f}_{i} \\cdot \\delta \\mathbf{r}_{i}=0$ \\\\\\\\\nWe now restrict ourselves to systems for which the net virtual work of constraints is zero.We therefore have as the condition for equilibrium of a system that the virtual work of the applied forces vanishes.\n\\begin{equation}\n\\sum_{i} \\mathbf{F}_{i}^{(a)} \\cdot \\delta \\mathbf{r}_{i}=0\\label{EP-02}\n\\end{equation}\nThis is often called \\textit{principle of virtual work}\\\\\\\\\n\\textbf{D'Alembert's Principle}\\\\\nEquation (\\ref{EP-02})  only deals with statics. We want a condition involving general motion of the system\\\\\nThe equation of motion \n$$\\textbf{F}_i=\\dot{\\textbf{P}_i}$$\n$$\\implies \\textbf{F}_i-\\dot{\\textbf{P}_i}=0$$\n\\textit{The particle in the system will be in equilibrium under a force equal to actual force plus a \"reversed effective force\"} $-\\dot{\\textbf{P}_i}$\\\\\n$\\therefore$ equation (\\ref{EP-01}) becomes\n\\begin{equation}\n\\sum\\limits_{i}(\\textbf{F}_i-\\dot{\\textbf{P}_i})\\cdot\\delta \\textbf{r}_i=0 \\label{EP-05}\n\\end{equation}\nresolving it\n$$\\sum\\limits_{i}(\\textbf{F}_i^{(a)}-\\dot{\\textbf{P}_i})\\cdot\\delta \\textbf{r}_i+\\sum\\limits_{i}\\textbf{f}_i\\cdot\\delta \\textbf{r}_i=0$$\nfor systems for which virtual work of the forces of constraint vanishes\n\\begin{equation}\n\\sum\\limits_{i}(\\textbf{F}_i^{(a)}-\\dot{\\textbf{P}_i})\\cdot\\delta\\label{EP-06} \\textbf{r}_i=0\n\\end{equation}\nWhich is called \\textit{D'Alembert's principle}\\\\\\\\\n\\textbf{Generalized Force}\\\\\nThe translation from $r_i$ to $q_j$ language starts from the transformation equations\n\\begin{equation}\n\\textbf{r}_i=\\textbf{r}_i(q_1,q_2,...q_n,t)\\label{EP-07}\n\\end{equation}\nvelocity $V_i$ in terms of $\\dot{q}_k$\n\\begin{equation}\n\\mathbf{v}_{i} \\equiv \\frac{d \\mathbf{r}_{i}}{d t}=\\sum_{k} \\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{k}} \\dot{q}_{k}+\\frac{\\partial \\mathbf{r}_{i}}{\\partial t}\\label{EP-08}\n\\end{equation}\nsimilarly, the arbitrary virtual displacement $\\delta r_i$ can be connected with the virtual displacement $\\delta q_1$ by\n\\begin{equation}\n\\delta \\mathbf{r}_{i}=\\sum_{j} \\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{j}} \\delta q_{j}\n\\end{equation}\nIn terms of generalized coordinates the virtual work of $\\textbf{F}_i$ becomes\n\\begin{equation}\n\\sum_{i} \\mathbf{F}_{i} \\cdot \\delta \\mathbf{r}_{i}=\\sum_{i, j} \\mathbf{F}_{i} \\cdot \\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{j}} \\delta q_{j}=\\sum_{j} Q_{j} \\delta q_{j}\\label{EP-10}\n\\end{equation}\nWhere $Q_j$ are called the component of the \\textit{generalized force} \n\\begin{equation}\nQ_{j}=\\sum_{i} \\mathbf{F}_{i} \\cdot \\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{j}}\\label{EP-11}\n\\end{equation}\n\\textit{Just as $q$'s need not have the diamensions of length, so the $Q$'s do not necessarily have the diamensions of force, but $Q_j\\delta q_j$ must always have the diamensions of work.}\n\\begin{note}\n\tNo variation of time, $\\delta t$ is involved here since a virtual displacement by definition considers only displacements of the coordinates.\n\\end{note}\n\\textbf{D'Alembert's Principle in generalized Coordinates}\n\\begin{align*}\n\\sum\\limits_{i}(r_i^{(a)}-\\dot{P_1}_i)\\cdot\\delta r_i&=0\\text{ \\quad is the D'Alembert's Principle}\\\\\n\\sum_{i} \\dot{\\mathbf{p}}_{i} \\cdot \\delta \\mathbf{r}_{i}&=\\sum_{i} m_{i} \\ddot{\\mathbf{r}}_{i} \\cdot \\delta \\mathbf{r}_{i}\\\\\n&=\\sum_{i, j} m_{i} \\ddot{\\mathbf{r}}_{i} \\cdot \\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{j}} \\delta q_{j}\n\\end{align*}\nNow consider the relation\n\\begin{equation}\n\\sum_{i} m_{i} \\ddot{\\mathbf{r}}_{i} \\cdot \\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{j}}=\\sum_{i}\\left[\\frac{d}{d t}\\left(m_{i} \\dot{\\mathbf{r}}_{i} \\cdot \\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{j}}\\right)-m_{i} \\dot{\\mathbf{r}}_{i} \\cdot \\frac{d}{d t}\\left(\\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{j}}\\right)\\right]\\label{EP-12}\n\\end{equation}\ninterchanging differentiation with respect to $t$ and $q_j$\n\\begin{align*}\n \\frac{d}{d t}\\left(\\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{j}}\\right) &=\\frac{\\partial \\dot{\\mathbf{r}}_{i}}{\\partial q_{j}}=\\sum_{k} \\frac{\\partial^{2} \\mathbf{r}_{i}}{\\partial q_{j} \\partial q_{k}} \\dot{q}_{k}+\\frac{\\partial^{2} \\mathbf{r}_{i}}{\\partial q_{j} \\partial t}, \\\\\n  &=\\frac{\\partial \\mathbf{v}_{i}}{\\partial q_{j}}\n \\end{align*}\n  we have from equation (\\ref{EP-08})\n\\begin{equation}\n\\frac{\\partial \\mathbf{v}_{i}}{\\partial \\dot{q}_{j}}=\\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{j}}\\label{EP-13}\n\\end{equation}\nsubstitution of these in equation (\\ref{EP-12})\n\\begin{align*}\n&\\sum_{i} m_{i} \\ddot{\\mathbf{r}}_{i} \\cdot \\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{j}}=\\sum_{i}\\left[\\frac{d}{d t}\\left(m_{i} \\mathbf{v}_{i} \\cdot \\frac{\\partial \\mathbf{v}_{i}}{\\partial \\dot{q}_{j}}\\right)-m_{i} \\mathbf{v}_{i} \\cdot \\frac{\\partial \\mathbf{v}_{i}}{\\partial q_{j}}\\right]\n\\intertext{second term on the LHS of equation (\\ref{EP-06}) can be explanded into}\n&\\sum_{j}\\left\\{\\frac{d}{d t}\\left[\\frac{\\partial}{\\partial \\dot{q} j}\\left(\\sum_{i} \\frac{1}{2} m_{i} v_{i}^{2}\\right)\\right]-\\frac{\\partial}{\\partial q_{j}}\\left(\\sum_{i} \\frac{1}{2} m_{i} v_{i}^{2}\\right)-Q_{j}\\right\\} \\delta q_{j}\\\\\n&\\sum_{i} \\frac{1}{2} m_{i} v_{i}^{2}=T\\quad \\text{ie. system kinetic energy}\n\\end{align*}\n$\\therefore$ D'Alembert's principle becomes\n\\begin{equation}\n\\sum_{j}\\left\\{\\left[\\frac{d}{d t}\\left(\\frac{\\partial T}{\\partial \\dot{q}_{j}}\\right)-\\frac{\\partial T}{\\partial q_{j}}\\right]-Q_{j}\\right\\} \\delta q_{j}=0\\label{EP-14}\n\\end{equation}\\\\\\\\\n\\textbf{Lagrange's Equation}\\\\\nAny virtual displacement $\\delta q_j$ is independent of $\\delta q_k.$\\\\\n$\\therefore$ only way to hold equation \\ref{EP-14} is for the individual coeffitients to vanish.\n\\begin{equation}\n\\frac{d}{d t}\\left(\\frac{\\partial T}{\\partial \\dot{q}_{j}}\\right)-\\frac{\\partial T}{\\partial q_{j}}=Q_{j}\\label{EP-15}\n\\end{equation}\nThere are $n$ such equations in all, When forces are derivable from scalar potential $V$\n$$\\mathbf{F}_{i}=-\\nabla_{i} V$$\nThen the generalized forces can be written as\n$$Q_{j}=\\sum_{i} \\mathbf{F}_{i} \\cdot \\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{j}}=-\\sum_{i} \\nabla_{i} V \\cdot \\frac{\\partial \\mathbf{r}_{i}}{\\partial q_{j}}$$\nWhich is partial derivative of $-V(r_1,r_2...r_3,t)$ with respect to $q_j$\n\\begin{equation}\nQ_{j}=-\\frac{\\partial V}{\\partial q_{j}} .\\label{EP-16}\n\\end{equation}\n$\\therefore$ equation \\ref{EP-15} can be rewritten as\n\\begin{equation}\n\\frac{d}{d t}\\left(\\frac{\\partial T}{\\partial \\dot{q}_{j}}\\right)-\\frac{\\partial (T-V)}{\\partial q_{j}}=0\n\\end{equation}\nPotential $V$ does not depend on the generalized velocities \\\\\n$\\therefore$ we can write \n$$\\frac{d}{d t}\\left( \\frac{\\partial (T-V)}{\\partial \\dot{q}_{j}} \\right)  -\\frac{\\partial (T-V)}{\\partial q_{j}}=0$$\ndefining the Lagrangian $L$,as $L=T-V$\\\\\n$\\therefore$ equation \\ref{EP-15} becomes\n$$\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{q}_{j}}\\right)-\\frac{\\partial L}{\\partial q_{j}}=0$$\nexpression refered to as \\textit{\"Lagrange's equations\"}\n\\begin{note}\n\tIf $L(q,\\dot{q},t)$ is an approximate Lagrangian and $F(q,t)$ is any differentiable function of the generalized coordinates and time, then\n\t$$L^{\\prime}(q, \\dot{q}, t)=L(q, \\dot{q}, t)+\\frac{d F}{d t}$$\n\\end{note}\nis a Lagrangian also resulting in the same equation of motion.\\\\\n\\section{Formulation of Lagrangian}\nLagrangian in different coordinate system:\nLagrangian of a system is defined as $L=T\\left(q_{i}, \\dot{q}_{i}, t\\right)-V\\left(q_{i}, \\dot{q}_{i}, t\\right)$, where $T$ and $V$ are functions of generalized coordinates, generalized velocities and time $t$.\\\\\n\\textbf{How to write a Lagrangian}\\\\\\\\\n\\textbf{Step 1:}\\\\\n(a) Draw a Cartesian coordinate system with a suitable origin.\n(b) Then disturb the system arbitrarily and fix the coordinates of individual particle with respect to origin.\n(c) Write down kinetic energy and potential energy as discussed below.\nIf a system constitutes $p$ number of particle and position vector of the $p^{\\text {th }}$ particle is given by $\\vec{r}_{p}=x_{p} \\hat{i}+y_{p} \\hat{j}+z_{p} \\hat{k}$, then kinetic energy of the system is given by\n$$\nT=\\frac{1}{2} \\sum_{P} m_{p}\\left[\\left(\\dot{x}_{p}\\right)^{2}+\\left(\\dot{y}_{p}\\right)^{2}+\\left(\\dot{z}_{p}\\right)^{2}\\right] \\text { and }\n$$\npotential energy is given by\n$$\nV=\\sum_{p} V_{p}\\left(x_{p}, y_{p}, z_{p}, \\dot{x}_{p}, \\dot{y}_{p}, \\dot{z}_{p}\\right)\n$$\nLagrangian of the system is given by $L=T-V$\\\\\\\\\n\\textbf{Step 2:}\\\\\n(a) Find the degree of freedom with the formula $\\mathrm{DOF}=3 N-k$ as discussed in previous chapter.\\\\\n(b) Number of degree of freedom is equivalent to minimum number of independent motion.\\\\\n(c) Identify the independent motion with the help of symmetry of problem.\\\\\n(d) Transform the Lagrangian of the system in suitable symmetry.\\\\\n\\begin{exercise}\nIf kinetic energy and potential energy is given by $T=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)$ and $V=-m g y$ respectively.\n\t \\begin{tasks}(1)\n\t\t\\task[\\textbf{a.}] Write down Lagrangian of the system.\n\t\t\\task[\\textbf{b.}] Identify generalized coordinate and generalized velocity.\n\t\t\\task[\\textbf{c.}] Identify cyclic coordinate and discuss conservation of momentum.\n\t\t\\task[\\textbf{d.}]  Discuss equation of motion.\n\t\\end{tasks}\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\\intertext{(a)} L=T-V \\Rightarrow \\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)&-(-m g y) \\Rightarrow \\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)+m g y\\\\\n\\intertext{(b)} \\text{ Generalized coordinate }q_{1}&=x, q_{2}=y\\text{ generalized velocity} \\dot{q}_{1}=\\dot{x}, \\dot{q}_{2}=\\dot{y}\n\\intertext{(c)} \\left(\\frac{\\partial L}{\\partial q_{1}}\\right)&=\\left(\\frac{\\partial L}{\\partial x}\\right)=0, \\text{so it is a cyclic coordinate}\\\\ \\text{Then} \\left(\\frac{\\partial L}{\\partial \\dot{x}}\\right)&=p_{x}=m \\dot{x}, \\intertext{Identified as linear momentum in $x$ direction is constant of motion.}\n\\left(\\frac{\\partial L}{\\partial y}\\right)&=m g \\neq 0,\\text{ so it is not cyclic coordinate}\n\\intertext{(d)} \\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{x}}\\right)-\\left(\\frac{\\partial L}{\\partial x}\\right)&=0 \\\\ \\frac{d}{d t} m \\dot{x}-0&=0 \\Rightarrow m \\dot{x}=c, \\intertext{which is exactly explained in section (b)} \n\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{y}}\\right)-\\left(\\frac{\\partial L}{\\partial y}\\right)&=0 \\\\ \\frac{d}{d t} m \\dot{y}-m g&=0 \\Rightarrow m \\ddot{y}-m g=0\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\t1. Apply Lagrange's equation to find the equation of motion of a particle in space using \\\\\n\t(a). Cartesian coordinates. \\\\\n\t(b). plane polar coordinates.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\intertext{ (a).\\quad The generalized forces needed are $F_{x}, F_{y}$, and $F_{z}$. Then}\n\tT &=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right), \\\\ \\frac{\\partial T}{\\partial x} &=\\frac{\\partial T}{\\partial y}=\\frac{\\partial T}{\\partial z}=0, \\\\ \\frac{\\partial T}{\\partial \\dot{x}}=m \\dot{x}, & \\frac{\\partial T}{\\partial \\dot{y}}=m \\dot{y}, \\quad \\frac{\\partial T}{\\partial \\dot{z}}=m \\dot{z}, \n\t\\intertext{ \\quad and the equations of motion are}\n\t\\frac{d}{d t}(m \\dot{x})&=F_{x}, \\quad \\frac{d}{d t}(m \\dot{y})=F_{y}, \\quad \\frac{d}{d t}(m \\dot{z})=F_{z}\n\t\\end{align*}\n\t\\begin{align*}\n\t\\intertext{(b).\\quad Here we must express $T$ in terms of $\\dot{r}$ and $\\dot{\\theta}$. The transformation equations are}\n\tx&=r \\cos \\theta\\\\\n\ty&=r \\sin \\theta\n\t\\intertext{the velocities are given by}\n\t\\dot{x}&=\\dot{r} \\cos \\theta-r \\dot{\\theta} \\sin \\theta,\\\\\n\t\\dot{y}&=\\dot{r} \\sin \\theta+r \\dot{\\theta} \\cos \\theta\\\\\n\t\\text{The kinetic energy }T&=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)\\text{ then reduces formally to}\\\\\n\tT&=\\frac{1}{2} m\\left[\\dot{r}^{2}+(r \\dot{\\theta})^{2}\\right]\n\t\\intertext{ the plane polar components of the velocity are $\\dot{r}$ along $\\mathbf{r}$, and $r \\dot{\\theta}$ along the direction perpendicular to $r$, denoted by the unit vector $\\hat{\\theta}$. Hence, the square of the velocity expressed in polar coordinates is simply $\\dot{r}^{2}+(r \\dot{\\theta})^{2}$.}\n\t\\intertext{the components of the gencralized force are}\n\tQ_{r}&=\\mathbf{F} \\cdot \\frac{\\partial \\mathbf{r}}{\\partial r}=\\mathbf{F} \\cdot \\hat{\\mathbf{r}}=F_{r}\\\\\n\tQ_{\\theta}&=\\mathbf{F} \\cdot \\frac{\\partial \\mathbf{r}}{\\partial \\theta}=\\mathbf{F} \\cdot r \\hat{\\mathbf{\\theta}}=r {F}_{\\theta} .\n\t\\intertext{ There are two generalized coordinates, and therefore two Lagrange equations. The derivatives occurring in the $r$ equation are}\n\t\\frac{\\partial T}{\\partial r}&=m r \\dot{\\theta}^{2}, \\quad \\frac{\\partial T}{\\partial \\dot{r}}=m \\dot{r}, \\quad \\frac{d}{d t}\\left(\\frac{\\partial T}{\\partial \\dot{r}}\\right)=m \\ddot{r},\\\\\n\tm \\ddot{r}-m r \\dot{\\theta}^{2}&=F_{r},\\\\\n\t\\frac{\\partial T}{\\partial \\theta}=0, \\quad \\frac{\\partial T}{\\partial \\dot{\\theta}}=m r^{2} \\dot{\\theta},& \\quad \\frac{d}{d t}\\left(m r^{2} \\dot{\\theta}\\right)=m r^{2} \\ddot{\\theta}+2 m r \\dot{r} \\dot{\\theta}.\\\\\n\t\\frac{d}{d t}\\left(m r^{2} \\dot{\\theta}\\right)&=m r^{2} \\ddot{\\theta}+2 m r \\dot{\\theta} \\dot{\\theta}=r F_{\\theta} .\\\\\n\t\\text{where angular momentum }L&=m r^{2} \\theta\\text{ and torque }N^{(e)}=r F_{\\theta}.\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tAtwood's machine \\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.7cm,width=4cm]{EP-04}\n\t\\end{figure}\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\intertext{A conservative system with holonomic, scleronomous constraint  (the pulley is assumed frictionless and massless). There is only one independent coordinate $x$, the position of the other weight being determined by the constraint that the length of the rope between them is $l$. The potential energy is}\n\tV&=-M_{1} g x-M_{2} g(l-x)\n\t\\intertext{while the kinetic energy is}\n\tT&=\\frac{1}{2}\\left(M_{1}+M_{2}\\right) \\dot{x}^{2}\n\t\\intertext{Lagrangian has the form}\n\tL&=T-V=\\frac{1}{2}\\left(M_{1}+M_{2}\\right) \\dot{x}^{2}+M_{1} g x+M_{2} g(l-x)\n\t\\intertext{equation of motion}\n\t\\frac{\\partial L}{\\partial  x}&=\\left(M_{1}-M_{2}\\right) g\\\\\n\t\\frac{\\partial  L}{\\partial  x}&=\\left(M_{1}+M_{2}\\right) \\dot{x}\n\t\\intertext{$\\mathrm{so}$}\n\t\\left(M_{1}+M_{2}\\right) \\ddot{x}&=\\left(M_{1}-M_{2}\\right) g,\\\\\n\t\\ddot{x}&=\\frac{M_{1}-M_{2}}{M_{1}+M_{2}} g,\\\\\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tA bead (or ring ) sliding on a uniformly rotating wire in a force-free space. The wire is straight, and is rotated uniformly about some fixed axis perpendicular to the wire.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\intertext{This is an example of constraint being time dependent, with the rotationaxis along $z$ and the wire in the $xy$ plane.} \n\tx&=r \\cos \\omega t \\hspace{3cm}(\\omega=\\text { angular velocity of rotation }) \\\\\n\ty&=r \\sin \\omega t \\hspace{3cm}(r=\\text{distance along wire from rotation axis} )\n\t\\intertext{constraint can be expressed as $\\dot{\\theta}=\\omega$, so}\n\tT&=\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\omega^{2}\\right)\n\t\\intertext{The equation of motion is then}\n\tm \\ddot{r}&-m r^{2}=0\\\\\n\t\\ddot{r}&=r \\omega^{2}  \n\t\\intertext{which is the familiar simple harmonic oscillator equation with a change of sign. The solution $r=e^{\\omega t}$ for a bead initially at rest on the wire shows that the bead moves exponentially outwards.The angular momentum, $L=m r^{2} \\omega=m \\omega r_{0}^{2} e^{2 \\omega t}$, provides the force $F=N / r$, which produces the constraint force, $F=2 m r_{0} \\omega^{2} e^{\\omega t}$, acting perpendicular to the wire and the axis of rotation.}\n\t\\end{align*}\n\\end{answer}", "meta": {"hexsha": "9c43389a0f0965828179c84fef72d5c34ee3c4a3", "size": 29842, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Classical Mechanics  -CSIR/chapter/Elementary Principles.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Classical Mechanics  -CSIR/chapter/Elementary Principles.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Classical Mechanics  -CSIR/chapter/Elementary Principles.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.0787037037, "max_line_length": 454, "alphanum_fraction": 0.6957978688, "num_tokens": 10302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.8791467690927439, "lm_q1q2_score": 0.8043322206618505}}
{"text": "\\chapter{Differential Equation}\n\\section{Homogeneous linear first-order}\nThe homogeneous linear first-order differential equations have the form:\n\\begin{align*}\n   f'(t) + p(t)f(t) = 0\n\\end{align*}\nHomogeneous is because one side of the equation is zero.\nYou can rewrite the expression above to have \\(f(x)\\) separated\n\\begin{gather}\n   f'(t)  = -p(t)f(t) \\\\\n   f'(t) \\frac{1}{f(t)} = -p(t) \\label{homodiff}\n\\end{gather}\nNow all the \\(f(t)\\) terms are on the left hand side.\n\nNote the following differentiation:\n\\begin{gather}\n   (\\ln f(t))' = \\frac{1}{f(t)} f'(t)\n\\end{gather}\nIt can be used to help integrate \\ref{homodiff}.\n\\begin{gather*}\n   \\int f'(t) \\frac{1}{f(t)} = \\int -p(t) \\\\\n   \\ln(|f(t)|) + C_1  =- P(t) + C_2 \\\\\n   \\ln(|f(t)|)  = -P(t) + \\hat{C}\n\\end{gather*}\nYou can combine \\(C_1\\) and \\(C_2\\) to a single constant \\(\\hat{C}\\), because they\nboth are constants.\nSince the domain of \\( \\ln \\) is \\((0, \\inf]\\) you have to take the absolute value of \\(f(t)\\).\nTo get rid of \\(\\ln\\) raise both side to \\( e \\). To compensate for the absolute value\nyou have to take \\(\\pm\\) of \\(e\\).\n\\begin{gather}\n   |f(t)| = e^{-P(t) + \\hat{C}} \\\\\n   f(t) = \\pm e^{-P(t) + \\hat{C}} \\\\\n   f(t) =  e^{-P(t)} C \\label{homogeneral}\n\\end{gather}\nThe expression \\(e^{\\hat{C}}\\) is a constant, so it can be replaced by \\(C\\), which constant\nbe \\(\\pm\\).\n\nThe expression \\ref{homogeneral} is the general solution for homogeneous first order\nlinear differential equations. Any linear combination of the general is a valid solution\nto the differential equation.\n\\subsubsection{Notation}\nThe notation of differential equations can be simplified by:\n\\begin{gather*}\n   f(t) = y\\\\\n   f(t)' = y'\\\\\n\\end{gather*}\n\\begin{example}\n   \\begin{gather*}\n      y' + sin(x + 2)y = 0\n   \\end{gather*}\n   The general solution is:\n   \\begin{gather*}\n      p(t) = sin(x + 2) \\\\\n      P(t) = - cos(x + 2)\\\\\n      y =  e^{-p(t)} C \\\\\n      y =  e^{cos(x + 2)} C \\\\\n   \\end{gather*}\n   Following functions are valid solutions to the homogeneous equation:\n   \\begin{gather*}\n      y =  2e^{cos(x + 2)} \\\\\n      y =  2e^{cos(x + 2)} +  3e^{cos(x + 2)} \\\\\n      y = 0 \\\\\n   \\end{gather*}\n\\end{example}\n\\subsubsection{Non-homogenous}\n\\begin{gather}\\label{inhomo}\n   y' + p(t)y = s(t)\n\\end{gather}\nRecall the product rule which states\n\\begin{gather}\n   (f \\cdot g) = f' g + f g'\n\\end{gather}\nIf we multiply \\ref{inhomo} by an unknown function \\(\\mu(t)\\) called the \\textbf{integrating factor} we get the following expression:\n\\begin{gather}\\label{intfactor}\n   \\mu(t) y' + \\mu(t) p(t)y = \\mu(t) s(t)\n\\end{gather}\nwe have an expression that looks like the product rule, if we suppose that\n\\begin{gather}\\label{intfactorcondition}\n   \\mu(t)' =  \\mu(t) p(t) \\\\\n   \\mu(t) = \\int \\mu(t) p(t)\n\\end{gather}\nIntegrating \\ref{intfactor} by using the product formula in reverse we get:\n\\begin{gather}\n   \\int \\mu(t) \\cdot y' + \\mu(t)\\cdot p(t) \\cdot y  dt = \\int \\mu(t) \\cdot s(t) dt \\\\\n   \\mu (t) y = \\int \\mu(td) s(t) dt \\\\\n   y = \\frac{1}{\\mu(t)}\\int \\mu(t) s(t)  \\label{inhomosol}\n\\end{gather}\nThe function that satisfies \\ref{intfactorcondition} is\n\\begin{gather}\n   \\mu(t) = C(t) e^{P(t)}\\\\\n   \\mu(t)' = C(t)' e^{P(t)} + C(t) \\cdot p(t) \\cdot e^{P(t)}\n\\end{gather}\nWe can chose \\(C(t) = 1\\)\n\\begin{gather}\n   \\mu(t)  = e^{P(t)} \\label{mufunction}\\\\\n   \\mu(t)' = p(t)e^{P(t)} = p(t)\\mu(t)\\\\\n\\end{gather}\nSetting \\ref{mufunction} in \\ref{inhomosol} we get the solution for the differential equation.\n\\begin{equation}\n   y = e^{-P(t)}\\int e^{P(t)} s(t)dt\n\\end{equation}\nIn general integrating the expression above yield the following expression\n\\begin{equation}\n   y = y_p + y_h\n\\end{equation}\nWhere \\(y_h\\) is the solution to the homogenous equation \\(y' + p(t)y = 0\\). The term\n\\(y_p\\) is called a particular solution and it is one of the solutions to the nonhomogeneous equation.\n\\begin{example}\n   \\begin{gather*}\n      y' + 2y = t \\\\\n      p(t) = 2\\\\\n      P(t) = 2t\\\\\n      s(t) = t \\\\\n      y = e^{-2t}\\int e^{2t} t dt\\\\\n      y = e^{-2t}\\left( \\frac{1}{2} e^{2t} \\cdot t - \\frac{1}{4}e^{2t} + C \\right)\\\\\n      y = \\frac{1}{2} t- \\frac{1}{4} + C e^{-2t}\n   \\end{gather*}\n   We see that  \\(Ce^{-2t}\\) is the solution to the homogeneous equation.\n   \\(y_p = \\frac{1}{2} t- \\frac{1}{4}\\) is one of the solution to the nonhomogeneous equation.\n\\end{example}\n\\begin{matlab}\n   \\apilink{dsolve}{https://www.mathworks.com/help/symbolic/dsolve.html}\n   \\begin{lstlisting}\n   >> syms y(t)\n   >> eqn = diff(y, t) + 2*y == t\n   >> dsolve(eqn)\n   ans =\n      t/2 + (C1*exp(-2*t))/4 - 1/4\n  \\end{lstlisting}\n   Note: C1 / 4 is still a constant C.\n\\end{matlab}\n\\section{Linear first-oder system of differential equations}\n\\subsubsection{The exponential map}\nThe exponential map is defined by\n\\begin{equation}\n   P_n(t) = e^{At}\n\\end{equation}\nwhere \\(A\\) is a square matrix with dimension \\(n \\times n\\) (see also \\ref{sec:matrixexponent}).\nIf a is diagonalizabe then:\n\\begin{equation}\n   P_n(t) = Ue^{Dt} U^{-1}\n\\end{equation}\nThe derivate is given by:\n\\begin{equation}\n   P_n(t) \\dt = A e^{At}\n\\end{equation}\n\\subsubsection{System of differential equations}\nA system off differential equations contains a set of unkown function \\(x_1(t), x_2(t) \\cdots x_n(t) \\) denoted by \\(x_1, x_2 \\cdots x_n\\). The derivate of a funciton \\(x_i\\) (with respext to to \\(t\\)) is denoted by\n\\(x_i'\\).\n\\subsection{Homogenous case}\nA homogenous linear first-order system has the form:\n\\begin{equation*}\n   \\begin{split}\n      x_1' &+ p_{11}x_1 + p_{12} x_2 \\cdots p_{1n}x_{1n} = 0 \\\\\n      x_2' &+ p_{21}x_1 + p_{22} x_2 \\cdots p_{1n}x_{2n} = 0 \\\\\n      &\\vdots \\\\\n      x_3' &+ p_{n1}x_1 + p_{n2} x_2 \\cdots p_{1n}x_{nn}= 0 \\\\\n   \\end{split}\n\\end{equation*}\nThe terms \\(p_{ij}\\) are called coefficient functions (so written out the are like \\(p_{ij}(t)\\)) they only depend on t.\nThe derivates can be expressed as a column vector:\n\\begin{equation*}\n   \\bm{x'} = \\begin{bmatrix}\n      x_1' \\\\ x_2' \\\\ \\vdots \\\\ x_n'\n   \\end{bmatrix}\n\\end{equation*}\nThe coefficient functions can be expressed as a square matrix \\(A^{n \\times n}\\)\n\\begin{equation}\n   \\bm{p} = \\begin{bmatrix}\n      p_{11} & p_{12} & \\cdots & p_{1n} \\\\\n      p_{21} & p_{22} & \\cdots & p_{2n} \\\\\n      \\vdots &        &        &        \\\\\n      p_{n1} & p_{n2} & \\cdots & p_{nn}\n   \\end{bmatrix}\n\\end{equation}\nThe functions can be written as a column vector\n\\begin{equation}\n   \\bm{x} = \\begin{bmatrix}\n      x_1 & x_2 & \\cdots & x_n\n   \\end{bmatrix}\n\\end{equation}\nThe wholse system can be written in matrix form:\n\\begin{equation}\n   \\bm{x'} = \\bm{p} \\bm{x}\n\\end{equation}\nThe solution is given by (same formula as \\ref{homogeneral} applied to matrices):\n\\begin{equation}\n   \\bm{x} = M_p(t) \\bm{c}\n\\end{equation}\nwhere \\(\\bm{c}\\) is a column vector of constants.\n\\begin{example}\n   \\begin{gather*}\n      x_1' = 1 x_1 + 4 x_2 \\\\\n      x_2' = 3x_2 + 2 x_2 \\\\\n   \\end{gather*}\n   Which can be rewritten as:\n   \\begin{gather*}\n      \\bm{x'} = \\bm{p} \\bm{x} \\\\\n      \\begin{bmatrix}\n         x_1' \\\\ x_2'\n      \\end{bmatrix} = \\begin{bmatrix}\n         1 & 4 \\\\ 2 & 4\n      \\end{bmatrix} \\begin{bmatrix}\n         x_1 \\\\ x_2\n      \\end{bmatrix}\n   \\end{gather*}\n   The eigenvalues and eigenvectors are:\n   \\begin{gather*}\n      \\lambda_1 = -2, v_1 = \\begin{bmatrix}\n         \\frac{-4}{3} \\\\ 1\n      \\end{bmatrix}\n      \\lambda_2 = 5, v_1 = \\begin{bmatrix}\n         1 \\\\ 1\n      \\end{bmatrix}\n   \\end{gather*}\n   Calculating \\(M_p(t)\\)\n   \\begin{gather*}\n      M_p(t) = \\begin{bmatrix}\n         \\frac{-4}{3} & 1 \\\\ 1 & 1\n      \\end{bmatrix}\n      \\begin{bmatrix}\n         e^{-2t} & 0 \\\\ 0 & e^{5t}\n      \\end{bmatrix} \\frac{1}{7}\\begin{bmatrix}\n         -3 & 3 \\\\ 4 & 4\n      \\end{bmatrix} = \\frac{1}{7 }\\begin{bmatrix}\n         4 e^{-2t} + 3e^{5t}  & 4e^{5t} - 4e^{-2t}   \\\\\n         -3 e^{-2t} + 3e^{5t} & 3 e^{-2t} + 4 e^{5t}\n      \\end{bmatrix}\n   \\end{gather*}\n   The solution is (note the factor \\(\\frac{1}{7}\\) can be ignored because \\(\\frac{c}{7}\\) ist still a constant):\n   \\begin{gather}\n      \\bm{x} =  M_p(t) \\bm{c} \\\\\n      x_1(t) = c_1 \\left( 4 e^{-2t} + 3e^{5t} \\right) + c_2 \\left(4e^{5t} - 4e^{-2t} \\right) \\\\\n      x_2(t) = c_1 \\left(-3 e^{-2t} + 3e^{5t} \\right) + c_2 \\left(3 e^{-2t} + 4 e^{5t} \\right)\n   \\end{gather}\n   The constans can be simplified by setting \\(c_a = (3c_1 + 4c_2)\\) and \\( c_b = 3(c_2 - c_1) \\):\n   \\begin{align*}\n      x_1(t) & = c_1 4 e^{-2t} + c_1 3e^{5t} + c_2 4 e^{5t} - c_2 4e^{-2t} = -4(c_2 - c_1)e^{-2t}  +  (3c_1 + 4c_2)e^{5t}    \\\\\n             & = c_a e^{5t} - \\frac{4}{3} c_b e^{-2t}                                                                        \\\\\n      x_2(t) & = c_1 (-3) e^{-2t} + c_1 3e^{5t}  + c_2 3 e^{-2t} + c_2 4 e^{5t} = 3(c_2 - c_1) e^{-2t} + (3c_1 + 4c_2)e^{5t} \\\\\n             & = c_b e^{-2t} + c_a e^{5t}\n   \\end{align*}\n   \\begin{matlab}\n      \\begin{lstlisting}\n         >> syms x1(t) x2(t)\n         >> ode1 = diff(x1) == 1*x1 + 4*x2\n         >> ode2 = diff(x2) == 3*x1 + 2 *x2\n         >> S = dsolve([ode1 ; ode2])\n         >> S.x1\n            ans = \n            C1*exp(5*t) - (4*C2*exp(-2*t))/3\n         >> S.x2\n            ans = \n            C2*exp(-2*t) + C1*exp(5*t)\n      \\end{lstlisting}\n   \\end{matlab}\n\\end{example}\nA more simplified solution is:\n\\begin{equation}\n   \\bm{x} = \\sum_{i=1}^{n} c_i \\bm{v_i} e^{\\lambda_i t}\n\\end{equation}", "meta": {"hexsha": "42f63f722d89d8439893b9d7587fe4a73becec1a", "size": 9311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/diffenetial_equations.tex", "max_stars_repo_name": "KriCse/Math-knowledge", "max_stars_repo_head_hexsha": "92c036c4563999ddaa97888a4023297e22bb7649", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/diffenetial_equations.tex", "max_issues_repo_name": "KriCse/Math-knowledge", "max_issues_repo_head_hexsha": "92c036c4563999ddaa97888a4023297e22bb7649", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/diffenetial_equations.tex", "max_forks_repo_name": "KriCse/Math-knowledge", "max_forks_repo_head_hexsha": "92c036c4563999ddaa97888a4023297e22bb7649", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.6743295019, "max_line_length": 215, "alphanum_fraction": 0.5711524004, "num_tokens": 3560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.9149009526726544, "lm_q1q2_score": 0.8043322180305219}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n%\n\\chapter{Implicit Differentiation and Inverses}\n%--------------------------------------------------\n\\section{Implicit Differentiation}\n%\nWe know:\n\\[ \\frac{d}{dx} x^a = ax^{a-1} \\quad \\mid \\quad a \\in \\mathbb{Z} \\]\nWe will now extend this formula to cover $\\mathbb{Q}$ as well:\n\\[\n    a = \\frac{m}{n} \\rightarrow y = x^{\\frac{m}{n}}\n    \\quad \\mid \\quad\n    m, n \\in \\mathbb{Z}\n\\]\nWe can start computing the derivative using the chain rule:%\n%\n\\begin{align*}\n    y^n                                                 & = x^n                             \\\\\n    \\frac{d}{dx} \\left( y^n \\right)                     & = \\frac{d}{dx} \\left( x^m \\right) \\\\\n    \\frac{d}{dy} \\left( y^n \\right) \\cdot \\frac{dy}{dx} & = mx^{m - 1}                      \\\\\n    \\frac{dy}{dx} \\left( ny^{n - 1} \\right)             & = mx^{m - 1}\n\\end{align*}\n%\nWe finally have an expression for $y'$:\n%\n\\begin{align*}\n    \\frac{dy}{dx}               & = \\frac{mx^{m - 1}}{ny^{n - 1}}                                              \\\\\n                                & = \\frac{m}{n} \\cdot \\frac{x^{m - 1}}{y^{n - 1}}                              \\\\\n                                & = \\frac{m}{n} \\cdot \\frac{x^{m - 1}}{\\left( x^{\\frac{m}{n}} \\right)^{n - 1}} \\\\\n                                & = ax^{m - 1 - \\frac{m}{n}(n - 1)}                                            \\\\\n                                & = ax^{a - 1}                                                                 \\\\\n    \\therefore \\frac{d}{dx} x^a & = ax^{a - 1} \\quad \\mid \\quad a \\in \\mathbb{Q}\n\\end{align*}\n%\n\\begin{exmp}\n    The equation of a unit circle is:\n    \\[ y^2 = 1 - x^2 \\]\n    This can be rewritten as:\n    \\[ y = \\left( 1 - x^2 \\right)^{\\frac{1}{2}} \\]\n    We can compute the derivative using the chain rule:\n    %\n    \\begin{align*}\n        \\frac{dy}{dx} & = \\frac{1}{2} \\left( 1 - x^2 \\right)^{\\frac{1}{2} - 1} \\cdot (-2x) \\\\\n                      & = \\frac{-x}{\\left( 1 - x^2 \\right)^{\\frac{1}{2}}}                  \\\\\n                      & = - \\frac{x}{y}\n    \\end{align*}\n    %\n    However, we can do the same thing using \\emph{implicit differentiation}:\n    %\n    \\begin{align*}\n        x^2 + y^2                                                         & = 1                \\\\\n        \\frac{d}{dx} \\left( x^2 + y^2 \\right)                             & = \\frac{d}{dx} (1) \\\\\n        \\frac{d}{dx} \\left( x^2 \\right) + \\frac{d}{dx} \\left( y^2 \\right) & = 0                \\\\\n        2x + \\frac{d}{dy} \\left( y^2 \\right) \\cdot \\frac{dy}{dx}          & = 0                \\\\\n        2x + 2y y'                                                        & = 0                \\\\\n        y'                                                                & = - \\frac{x}{y}\n    \\end{align*}\n    %\n\\end{exmp}\n%\n\\begin{exmp}\n    In the following case, it is not so easy to solve for $y$:\n    \\[ y^3 +xy^2 + 1 = 0 \\]\n    We will need to use implicit differentiation to find the derivative:\n    %\n    \\begin{align*}\n        3y^2y' + y^2 + 2xyy' + 0     & = 0                        \\\\\n        y' \\left( 3y^2 + 2xy \\right) & = -y^2                     \\\\\n        y'                           & = - \\frac{y^2}{3y^2 + 2xy}\n    \\end{align*}\n    %\n\\end{exmp}\n%--------------------------------------------------\n\\section{Inverses}\n%\nIf $y = f(x)$ and $g(y) = x$, we call $g$ the \\emph{inverse} of $f$,\ndenoted $f^{-1}$:\n\\[ x = g(y) = f^{-1}(y) \\]\nNow, we will use implicit differentiation to find the derivative\nof the inverse function:\n%\n\\begin{align*}\n    y                                                         & = f(x)                    \\\\\n    f^{-1}(y)                                                 & = x                       \\\\\n    \\frac{d}{dx} \\left( f^{-1}(y) \\right)                     & = \\frac{d}{dx}(x)         \\\\\n    \\frac{d}{dy} \\left( f^{-1}(y) \\right) \\cdot \\frac{dy}{dx} & = 1                       \\\\\n    \\frac{d}{dy} \\left( f^{-1}(y) \\right)                     & = \\frac{1}{\\frac{dy}{dx}} \\\\\n\\end{align*}\n%\n\\begin{exmp}\n    The derivative of $y = \\tan^{-1}(x)$:\n    %\n    \\begin{align*}\n        \\tan y                                                 & = x                                  \\\\\n        \\frac{d}{dx} \\left( \\tan y \\right)                     & = \\frac{d}{dx}(x)                    \\\\\n        \\frac{d}{dy} \\left( \\tan y \\right) \\cdot \\frac{dy}{dx} & = 1                                  \\\\\n        \\left( \\csc^2 y \\right) \\cdot \\frac{dy}{dx}            & = 1                                  \\\\\n        \\frac{dy}{dx}                                          & = \\cos^2 y                           \\\\\n                                                               & = \\cos^2 \\left( \\tan^{-1}(x) \\right)\n    \\end{align*}\n    %\n    This form is messy but we can use geometry to simplify.\n    %\n    \\begin{figure}[ht]\n        \\centering\n        \\begin{tikzpicture}[scale = 0.5 \\textwidth / 2cm]\n            \\coordinate (A) at (0,0);\n            \\coordinate (B) at (2,0);\n            \\coordinate (C) at (0,1);\n            \\draw\n            (A)\n            --\n            node[below = 5pt]\n                {$x$}\n            (B)\n            --\n            node\n            [\n            sloped,\n            above = 5pt\n            ]\n            {$\\left( 1 + x^2 \\right)^{\\frac{1}{2}}$}\n            (C)\n            --\n            node[left = 5pt]\n                {$1$}\n            cycle\n            pic\n                [\n                    draw = green!50!black,\n                    fill = green!25,\n                    angle radius = 1cm,\n                    \"$y$\",\n                    -stealth\n                ]\n                {angle = A--C--B}\n            pic\n                [\n                    draw = black,\n                    angle radius = 0.5cm\n                ]\n                {right angle = B--A--C};\n        \\end{tikzpicture}\n        \\caption\n        {\n            Triangle with angles and lengths corresponding to\n            those in the example illustrating differentiation\n            using the inverse function\n        }\n        \\label{fig:simplificationTriangle}\n    \\end{figure}\n\n    In the triangle in Figure \\ref{fig:simplificationTriangle},\n    $\\tan y = x \\Rightarrow y = \\tan^{-1}(x)$. From this, we can find:\n    \\begin{align*}\n        \\cos y                                   & = \\frac{1}{\\sqrt{1 + x^2}}                  \\\\\n        \\left( \\cos y \\right)^2                  & = \\left( \\frac{1}{\\sqrt{1 + x^2}} \\right)^2 \\\\\n        \\cos^2 y                                 & = \\frac{1}{1 + x^2}                         \\\\\n        \\frac{dy}{dx}                            & = \\frac{1}{1 + x^2}                         \\\\\n        \\frac{d}{dx} \\left( \\tan^{-1}(x) \\right) & = \\frac{1}{1 + x^2}\n    \\end{align*}\n    %\n\\end{exmp}\n%\n\\subsection{Graphing}\n%\nSuppose $y = f(x)$ and $g(y) = f^{-1}(y) = x$.\n\nTo graph $f$ and $g$ together, we need to write $g$ as a function of $x$.\nIf $g(x) = y$, then $x = f(y)$. What we have done is trade the variables\n$x$ and $y$. This is illustrated in Figure \\ref{fig:inverseTangent}:\n\\begin{figure}[ht]\n    \\centering\n    \\begin{tikzpicture}\n        [\n            scale = \\textwidth / 11cm,\n            smooth,\n            > = latex\n        ]\n\n        % Axes\n        \\draw[<->]  (-5,0) -- (5,0) node[right] {$x$};\n        \\draw[<->]  (0,-5) -- (0,5) node[above] {$y$};\n        % Origin\n        \\node at (0,0) [below right = 2pt] {$0$};\n\n        % Horizontal Aymptotes\n        \\draw\n        [\n            densely dotted,\n            blue\n        ]\n        (-5,1.57)  -- (5,1.57);\n        \\draw\n        [\n            densely dotted,\n            blue\n        ]\n        (-5,-1.57) -- (5,-1.57);\n        % Vertical Asymptotes\n        \\draw[densely dotted] (1.57,-5)  -- (1.57,5);\n        \\draw[densely dotted] (-1.57,-5) -- (-1.57,5);\n\n        % Ticks:\n        \\draw (-1.57,-2pt) -- (-1.57,2pt);\n        \\draw (1.57,-2pt)  -- (1.57,2pt);\n        \\draw (-2pt,-1.57) -- (2pt,-1.57);\n        \\draw (-2pt,1.57)  -- (2pt,1.57);\n\n        % y = \u00b1\u03c4/4\n        \\node at (0,1.57)\n        [\n            right = 2pt,\n            fill = white\n        ]\n        {$\\frac{\\tau}{4}$};\n        \\node at (0,-1.57)\n        [\n            right = 2pt,\n            fill = white\n        ]\n        {$- \\frac{\\tau}{4}$};\n\n        % x = \u00b1\u03c4/4\n        \\node at (-1.57,0)\n        [\n            below = 2pt,\n            fill = white\n        ]\n        {$ - \\frac{\\tau}{4}$};\n        \\node at (1.57,0)\n        [\n            below = 2pt,\n            fill = white\n        ]\n        {$ \\frac{\\tau}{4}$};\n\n        % y = x\n        \\draw\n        [\n            gray,\n            densely dashed\n        ]\n        plot[domain = -4 : 4]\n        (\\x,\\x)\n        node\n            [\n                right = 2pt,\n                fill = white\n            ]\n            {$y = x$};\n\n        % y = tan(x)\n        \\draw\n        plot[domain = -1.37 : 1.37]\n        (\\x,{tan(\\x r)}) % \\x r means to convert '\\x' from degrees to _r_adians:\n        node\n            [\n                right = 2pt,\n                fill = white\n            ]\n            {$y = \\tan(x)$};\n\n        % y = arctan(x)\n        \\draw[blue]\n        plot[domain = -4.9 : 4.9]\n        (\\x,{rad(atan(\\x))})\n        node[below]\n            {$y = \\tan^{-1}(x)$};\n\n        % Origin Mark:\n        \\filldraw[black] (0,0) circle [radius=1pt];\n    \\end{tikzpicture}\n    \\caption\n    {\n        You can think about $f^{-1}$ as the graph of $f$ reflected\n        about the line $y = x$\n    }\n    \\label{fig:inverseTangent}\n\\end{figure}\n\\end{document}", "meta": {"hexsha": "4e2ca94c403336661db67408f95e2186e5bb31d4", "size": 9538, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter5.tex", "max_stars_repo_name": "DanialHaseeb/single-variable-calculus", "max_stars_repo_head_hexsha": "4bf05b3e46010967217f2e71bb22a9de8e7fc82d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/chapter5.tex", "max_issues_repo_name": "DanialHaseeb/single-variable-calculus", "max_issues_repo_head_hexsha": "4bf05b3e46010967217f2e71bb22a9de8e7fc82d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-01-22T21:42:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-15T13:01:11.000Z", "max_forks_repo_path": "chapters/chapter5.tex", "max_forks_repo_name": "DanialHaseeb/single-variable-calculus", "max_forks_repo_head_hexsha": "4bf05b3e46010967217f2e71bb22a9de8e7fc82d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.703180212, "max_line_length": 113, "alphanum_fraction": 0.3523799539, "num_tokens": 2843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8791467659263148, "lm_q1q2_score": 0.804332215724975}}
{"text": "\\subsection{Coordinate vectors}\n\nFor example, the basis of $xy$ plane can be:\n\n\\[\\mathfrak{B}=\\left\\{\\begin{bmatrix} 1\\\\1\\\\0\\\\ \\end{bmatrix}, \\begin{bmatrix}1\\\\-1\\\\0\\\\ \\end{bmatrix}\\right\\}\\]\n\nTo form $\\begin{bmatrix}1\\\\ 0\\\\0\\end{bmatrix}$ with this basis, can do $\\begin{bmatrix} 1\\\\0\\\\0\\\\ \\end{bmatrix}=\\frac{1}{2}\\begin{bmatrix} 1\\\\1\\\\0\\\\ \\end{bmatrix}+\\frac{1}{2}\\begin{bmatrix}1\\\\-1\\\\0\\\\ \\end{bmatrix}$.\nThe coefficients used form the following vector:\n\n\\[\\begin{bmatrix}\\frac{1}{2}\\\\ \\frac{1}{2}\\end{bmatrix}\\]\n\nKnown as \\textbf{$\\mathfrak{B}$-coordinate vector}.\nNotation:\n\n\\[\\left[\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \\right]_\\mathfrak{B}=\\begin{bmatrix} \\frac{1}{2} \\\\ \\frac{1}{2} \\\\ \\end{bmatrix} \\]\n\n\\begin{framed}\n\\noindent\nGenerally, given $\\mathfrak{B}=\\left\\{ \\tb v_1, \\tb v_2, \\tb v_3, \\dots, \\tb v_m \\right\\}\\subset \\mathbb{R}^n$\nis linearly independent, then $[\\tb{v}_i]_{\\mathfrak{B}}=\\tb{e}_i\\in\\R^m$.\n\\end{framed}\n\nThis is because row-reducing the matrix of $\\mathfrak{B}$ gives $\\mathrm{rref}(A)$ where $A$ is this matrix. Given the same\n$\\mathfrak{B}$, can find the components of $\\tb{w}$:\n\n\\[\\left[\\tb w \\right]_\\mathfrak{B}=\\begin{bmatrix}c_1\\\\c_2\\\\ \\vdots\\\\ c_m\\end{bmatrix}\\]\n\\[\\tb{w}=c_{1} \\tb{v}_{1}+c_{2} \\tb{v}_{2}+\\cdots+c_{m} \\tb{v}_{m}\\]\n\nThus,\n\n\\[\\tb w = \\begin{bmatrix}|&|&\\dots&|\\\\ \\tb v_1 &\\tb v_2 & \\dots &\\tb v_m\\\\  |&|&\\dots&| \\end{bmatrix}\\begin{bmatrix}c_1\\\\c_2\\\\\\vdots\\\\c_m\\end{bmatrix}\\]\n\nMatrix is called change of basis matrix $S$. A standard basis is given as $\\tb{e}_1,\\tb{e}_2,\\cdots$. A nonstandard basis is not of this form.\n\n\\subsection{B-matrix}\n\nIf $A$ is $n\\times n$ and $T(\\tb{x})=A\\tb{x}$ where $T:\\R^n\\rightarrow \\R^n$, then there exists a matrix $B$ such that\n$\\left[T(\\tb x)\\right]_\\mathfrak{B}=B\\left[\\tb x\\right]_\\mathfrak{B}$. This is called the $\\mathfrak{B}-matrix$.\nIf $\\tb{v}_i\\in \\mathfrak{B}$, then $[\\tb{v}_i]_\\mathfrak{B}=\\tb{e}_i$.\\\\\n\n\\noindent\nThis means that \n$\\left[T(\\tb v_i)\\right]_\\mathfrak{B}=B\\left[\\tb v_i \\right]_\\mathfrak{B}=B\\tb e_i$, so \n\\textbf{the $i^{\\mathrm{th}}$column of $B$ must be $[T(\\tb{v}_i)]_\\mathfrak{B}$}.\\\\\n\n\\noindent\nMultiple ways to calculate $\\mathfrak{B}$-matrix of $T$, considering $T$ to be a projection\nonto $y=\\frac{x}{3}$:\n\n\\includegraphics[scale=0.5]{CommutativeDiagram2.jpg}\n\nMeans that multiple ways to get to $[T(\\tb{x})]_\\mathfrak{B}$.\nWhen following $\\tb{x}$ and going right and down:\n\n\\[S^{-1}\\left(A\\tb x\\right)=S^{-1}A\\tb x=\\left[T(\\tb x) \\right]_\\mathfrak{B}\\]\n\nGoing down and right:\n\n\\[B\\left(S^{-1}\\tb x\\right)=BS^{-1} \\tb x=\\left[T(\\tb x )\\right]_\\mathfrak{B}\\]\n\nThus,\n\n\\begin{align*}\nS^{-1}A=BS^{-1}\\\\\n\\boxed{S^{-1}AS=B}\n\\end{align*}\n\nIf this is satisfied, then $A$ is similar to $B$ or $A\\sim B$.", "meta": {"hexsha": "35e02010810525914f01f7b491d2dae28078b67a", "size": 2726, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/15_coordinates.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear-algebra/tex/15_coordinates.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "linear-algebra/tex/15_coordinates.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.0882352941, "max_line_length": 215, "alphanum_fraction": 0.6415994131, "num_tokens": 1121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005327, "lm_q2_score": 0.8902942319436397, "lm_q1q2_score": 0.8041976196588251}}
{"text": "\\begin{verbatim}\n\\subsection{Sine functions}\nFor given $x \\in [0, 2\\pi]$ with step size $\\pi/12$, we can obtain the\nevaluations of \\eqref{eq:y1}, \\eqref{eq:y2}, \\eqref{eq:y3} at $x$\n(see Table \\ref{tab:sin}), and the corresponding plot (see Figure \\ref{fig:sin}).\n\\begin{align}\ny_1 & = \\sin(x/2) \\label{eq:y1}\ny_2 & = \\sin(x)   \\label{eq:y2}\ny_3 & = \\sin(2x)  \\label{eq:y3}\n\\end{align}\n\\input{../src/sin.tex}\n\\begin{figure}[!hbtp]\n    \\centering\n    \\includegraphics[width=0.75\\textwidth]{../src/lab_05_plot.pdf}\n    \\caption{Sine functions}\n    \\label{fig:sin}\n\\end{figure}\n\\end{verbatim}\n", "meta": {"hexsha": "a02c7c5fc9e431a3a2a15840a5e3446b8a0ee14a", "size": 590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.05/Math.3341.Lab.05.Report/LaTeX/latex.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.05/Math.3341.Lab.05.Report/LaTeX/latex.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.05/Math.3341.Lab.05.Report/LaTeX/latex.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.0526315789, "max_line_length": 81, "alphanum_fraction": 0.6576271186, "num_tokens": 230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.8652240964782011, "lm_q1q2_score": 0.804174237001283}}
{"text": "\\subsection{Functions}\r\n\\begin{definition}\r\n    A function $f$ is a rule between a pair of sets, denoted $f: D \\to C$, that assigns values from the first set, the domain $D$, to the second set, the codomain $C$.\r\n\\end{definition}\r\n\r\nWe call the subset of the codomain $C$ that constitutes all values $f$ can actually attain the range $R \\subseteq C$. \r\nNote that when we draw a graph of a function, all we are doing is drawing all ordered pairs $\\{(x, f(x)) \\mid x \\in D\\}$.\r\n\r\n\\begin{example}\r\n    Find the domain of the following function:\r\n    \\begin{equation*}\r\n        f(x) = \\frac{1}{(1 - x)\\sqrt{5 - x^2}}\r\n    \\end{equation*}\r\n\\end{example}\r\n\r\n\\begin{answer}\r\n    We know that $\\frac{n}{0}$ is undefined for all $n \\in \\mathbb{R}$ and $\\sqrt{x}$ is only defined for $x \\geq 0$. \r\n    The first condition applies to the first term in the denominator and both conditions apply to the second, giving us\r\n    \\begin{equation*}\r\n        (1 - x) \\neq 0 \\text{ and } 5 - x^2 > 0\r\n    \\end{equation*}\r\n    The first condition implies $x \\neq 1$ while the second implies $|x| < \\sqrt{5}$.\r\n    Putting these together, we find that the domain is\r\n    \\begin{equation*}\r\n        \\{x \\mid x \\neq 1, |x| < \\sqrt{5}\\} \\text{ or } (-\\sqrt{5}, 1) \\cup (1, \\sqrt{5})\r\n    \\end{equation*}\r\n\\end{answer}\r\n\r\nWe can also compose two functions, such that the ouput of one function is the input of another: \r\n\\begin{equation*}\r\n    (f \\circ g)(x) = f(g(x)).\r\n\\end{equation*}\r\n\r\n\\begin{definition}\r\n    A function $g$ is called an inverse function of $f$ if $f(g(x)) = x$ for all x in the domain of g and $g(f(x))$ for all x in the domain of f. \r\n    We write this as $g = f^{-1}$.\r\n\\end{definition}\r\n\r\nOne common algorithm for finding an inverse function is to set $y = f(x)$, substitute all $x$'s for $y$'s, and then solve for y.\r\n\\begin{example}\r\n    Find the inverse function of \r\n    \\begin{equation*}\r\n        f(x) = \\frac{5x + 2}{4x - 3}.\r\n    \\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n    We first make the substitutions to set up the algorithm:\r\n    \\begin{equation*}\r\n        y = \\frac{5x + 2}{4x - 3} \\text{ followed by }\r\n        x = \\frac{5y + 2}{4y - 3}\r\n    \\end{equation*}\r\n    After multiplying both sides by the denominator and simplifying, we have\r\n    \\begin{equation*}\r\n        \\implies 4xy - 3x = -5y - 2 \\\\\r\n        \\implies y = f^{-1}(x) = \\frac{3x - 2}{4x + 5}.\r\n    \\end{equation*}\r\n\\end{answer}\r\n\r\nWe say that a function $f$ is even if it satisfies $f(-x) = f(x)$ for all $x \\in D$.\r\nLikewise, we say that a function $f$ is odd if it satisfies $f(-x) = -f(x)$ for all $x \\in D$. \r\nGeometrically, we can see that the graph of an even function is symmetric with respect to the $y$-axis, while the graph of an odd function is symmetric with respect to the origin. \r\n\r\n\\begin{example}\r\n    Is $f(x) = 2x - x^2$ even, odd, or neither?\r\n\\end{example}\r\n\\begin{answer}\r\n    \\begin{equation*}\r\n        f(-x) = 2(-x) - (-x)^2 = -2x - x^2\r\n    \\end{equation*}\r\n    Since $f(-x) \\neq f(x)$ and $f(-x) \\neq -f(x)$, the function is neither even nor odd.\r\n\\end{answer}", "meta": {"hexsha": "172214a74187955d790ca726a9428d3a31f1fe50", "size": 3070, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/algebraPreCalc/functions.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/algebraPreCalc/functions.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/algebraPreCalc/functions.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 43.2394366197, "max_line_length": 181, "alphanum_fraction": 0.6143322476, "num_tokens": 1012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.804083495138339}}
{"text": "\\subsection{Definition}\n\nIf:\n\n\\(c=a^b\\)\n\nThen\n\n\\(log_ac=b\\)\n\nProduct rule:\n\n\\(a=c^{log_ca }\\)\n\n\\(b=c^{log_cb }\\)\n\nSo:\n\n\\(ab=c^{log_cab }\\)\n\nBut also:\n\n\\(ab=c^{log_ca }c^{log_cb }\\)\n\n\\(ab=c^{log_ca + log_cb }\\)\n\nSo:\n\n\\(log_ca+log_cb=log_cab\\)\n\n\\subsection{Power rule}\n\n\\(a=b^{log_ba}\\)\n\nSo:\n\n\\(a^c=b^{log_ba^c}\\)\n\nAnd separately:\n\n\\(a^c=(b^{log_ba})^c\\)\n\n\\(a^c=(b^{clog_ba})\\)\n\nSo:\n\n\\(clog_ba=log_ba^c\\)\n\n\n", "meta": {"hexsha": "24287242fcea3c510e42859c495dfe218ee646a5", "size": 405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/algebra/02-01-logs.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/algebra/02-01-logs.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/algebra/02-01-logs.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 8.1, "max_line_length": 29, "alphanum_fraction": 0.5481481481, "num_tokens": 168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392795, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.8040834837644456}}
{"text": "\n\\subsection{Tuples}\n\nWe can get a list of sets in an order. A 2-tuple is an ordered pair:\n\n\\((a, b)\\)\n\nWe can write an ordered pair of \\(a\\) and \\(b\\) as:\n\n\\(\\{\\{a\\},\\{a,b\\}\\}\\)\n\nOrdred pair definition, and tuple\n\n\\((a,b)=(c,d) \\leftrightarrow (a=c\\land b=d)\\)\n\nThis is the characteristic property.\n\n", "meta": {"hexsha": "73dbfe3a850d301510619e46e5be9aa6afc0173f", "size": 301, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sets/03-01-operations.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sets/03-01-operations.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sets/03-01-operations.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.7222222222, "max_line_length": 68, "alphanum_fraction": 0.6245847176, "num_tokens": 98, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.8040571422499625}}
{"text": "\\section{State Machines}\n\n\\frame{\n{Part 3: State Machines}\n\n\\tableofcontents[currentsection,hideallsubsections, firstsection=2, sections={2-4}]\n}\n\n\\subsection{Definition}\n\n\\begin{frame}{What are state machines?}\n\n  State machines are used to represent \"step-by-step\" processes. They contain:\n  \\begin{itemize}\n    \\item A description of each possible state in the machine;\n    \\item How the machine transition from one state to another;\n  \\end{itemize}\\bigskip\n\n  State machines are often used to describe algorithms, programs, logic circuit, decision processes, etc.\\bigskip\n\n  State machines are a \\structure{formal description} that can be used to prove the correctness of an algorithm.\n\\end{frame}\n\n\\begin{frame}[t]{Example of a State Machine}\n\n  \\begin{columns}\n    \\column{0.4\\textwidth}\n    State machine for counting from 0 to 99:\n    \\begin{itemize}\n      \\item {\\bf States:} 0 to 99, overflow.\n      \\item {\\bf Start State:} 0\n      \\item {\\bf Transitions:}\\\\\n        $i \\to i+1$ if $i < 99$\\\\\n        $99 \\to$ overflow\\\\\n        overflow $\\to$ overflow\\\\\n    \\end{itemize}\\bigskip\n\n    Note how we can represent the State Machine many different ways.\n\n    \\column{0.6\\textwidth}\n    \\includegraphics[width=1\\textwidth]{../img/statemachine}\n  \\end{columns}\n\\end{frame}\n\n\\subsection{State Machines for Proofs}\n\\begin{frame}{State Machine for Proofs}{Robot 1.0}\n\n  Imagine a robot moving forwards and backwards on a street. The robot has two speeds:\n  \\begin{itemize}\n    \\item The robot can move exactly {\\bf five squares} forwards.\n    \\item The robot can move exactly {\\bf three squares} backwards.\n  \\end{itemize}\n  \\bigskip\n\n  If the robot starts from position 0, is it possible for it to reach position 4?\n\\end{frame}\n\n\\begin{frame}{State Machine for Proofs}{Robot 1.1}\n  Imagine a robot moving forwards and backwards on a street. The robot has two speeds:\n  \\begin{itemize}\n    \\item The robot can move exactly {\\bf nine squares} forwards.\n    \\item The robot can move exactly {\\bf three squares} backwards.\n  \\end{itemize}\n  \\bigskip\n\n  If the robot starts from position 0, is it possible for it to reach position 4?\n\\end{frame}\n\n\\begin{frame}{State Machine for Proofs}{Preserved Invariants}\n\n  \\structure{Preserved Invariants} are propositions that are always true, after {\\bf any} transition of the state machine. We can use preserved invariants to prove which squares the robots can reach.\n\n  \\begin{block}{Robot 1.0}\n    The position of robot 1.0 is always: $s_0 + 5a - 3b$\n  \\end{block}\n  \\begin{block}{Robot 1.1}\n    The position of robot 1.1 is always: $s_0 + 9a - 3b$\n    \\begin{itemize}\n      \\item $s_0 + 9a - 3b = s_0 + 3(3a-b)$\n      \\item The position of robot 1.1 is always $s_0$ plus a multiple of 3; (\\structure{Preserved Invariant})\n      \\item So it is impossible for robot 1.1 to reach 4 from 0.\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n\n\n\\begin{frame}{Induction with Preserved Invariants}\n\n  Preserved Invariants can be used together with inductions to prove things about state machines:\\bigskip\n\n  \\begin{itemize}\n    \\item Prove that $P(s)$ is a preserved invariant. This means that if $P(s)$ is true for some state $s$, then it will continue to be true after any transition.\\medskip\n\n    \\item Prove that $P(s)$ is true for the initial state, $s_0$.\\medskip\n\n    \\item Conclude that $P(s)$ is always true for the entire state machine.\n  \\end{itemize}\\bigskip\n\n  If $P(s)$ is a \"correctness condition\" of an algorithm, this method can be used to prove that an algorithm is correct.\n\\end{frame}\n\n\n\\begin{frame}{State Machine for Proofs}{Robot 2.0}\n\n  Robot 2.0 can move on the diagonals of $\\mathbb{Z}^2$: (+1,\n  +1), (-1,-1), (+1,-1), (-1,+1). Starting from (0,0), is it possible for the robot to reach position (1,0)?\n\n  \\begin{center}\n    \\includegraphics[width=0.4\\textwidth]{../img/diag_robot}\n  \\end{center}\n\n  \\alert{QUIZ}: Try to prove this by yourself first!\n\n\\end{frame}\n\n\n\\begin{frame}{State Machine for Proofs}{Robot 2.0 -- Solution}\n\n  We can show that a \\structure{preserved invariant} of robot 2.0 is that the sum of its coordinates is always even (or always odd):\\bigskip\n\n  \\begin{itemize}\n  \\item P(0,0) is true (0+0 is even).\n  \\item The steps of the robot are:\n    \\begin{itemize}\n    \\item $+1+1 = +2$: even + 2 is still even;\n    \\item $-1-1 = -2$: even - 2 is still even;\n    \\item $+1-1 = 0$: even + 0 is still even;\n    \\item $-1+1 = 0$: even + 0 is still even;\n    \\end{itemize}\n  \\end{itemize}\n  \\bigskip\n\n  So we can see that the parity of the position is a \\structure{preserved invariant}. Because the parities of (0,0) and (1,0) are different, it is impossible for robot 2.0 to go from (0,0) to (1,0).\n\\end{frame}\n\n\\begin{frame}{State Machines for Proofs}{Fast Exponentiation}\n\n  This is the end for this lecture. I highly recommend that you watch lecture video 1.9.1 from MIT OCW for a final example with the Fast Exponentiation algorithm.\\bigskip\n\n  Summary of the third part: To prove that an algorithm is correct, we need to show that:\n  \\begin{itemize}\n    \\item Prove that if the algorihm is in a correct state, it will always stay in the correct state (preserved invariant);\n    \\item Prove that the algorithm can reach the correct state from the initial position;\n    \\item Prove that the algorithm stops at some point (not an infinite loop).\n    \\begin{itemize}\n      \\item We haven't talked about this part yet, but you can prove this by showing that some variable in the state machine is always decreasing.\n    \\end{itemize}\n  \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "991d5cc4d20e01fdca9c7e56b49f48c22d61a927", "size": 5534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week02/03_StateMachines.tex", "max_stars_repo_name": "caranha/MathCS", "max_stars_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-13T18:59:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T02:14:56.000Z", "max_issues_repo_path": "week02/03_StateMachines.tex", "max_issues_repo_name": "caranha/MathCS", "max_issues_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week02/03_StateMachines.tex", "max_forks_repo_name": "caranha/MathCS", "max_forks_repo_head_hexsha": "f3ce6705d09c55541f629cd542191bfd3e9adf34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.8933333333, "max_line_length": 199, "alphanum_fraction": 0.7031080593, "num_tokens": 1612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.9111797130267452, "lm_q1q2_score": 0.804050367305476}}
{"text": "\\documentclass[landscape, letterpaper]{article}\n\n\\usepackage[margin=.25in]{geometry}\n\\usepackage{fontspec}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\usepackage{multicol}\n\n\\renewcommand{\\complement}[1]{{#1}^\\mathsf{c}}\n\n\\begin{document}\n\\begin{multicols}{2}\n    \\section*{Induction}\n    \\textbf{Let} $P(n)$ be the property to be proven, let $a$ be fixed integer.\n\n    Suppose the following:\n    \\begin{enumerate}\n        \\item \\textbf{Basis:} $P(a)$ is true.\n        \\item \\textbf{Induction:} For all integers $k\\geq n$, if $P(k)$ is true then $P(k+1)$ is true.\n        \\item Hence for all integers $n\\geq a, P(n)$ is true.\n    \\end{enumerate}\n    \\subsection*{Strong Induction}\n    \\textbf{Let} $P(n)$ be the property to be proven, let $a$ and $b$ be fixed integers where $a\\leq b$.\n\n    Suppose the following:\n    \\begin{enumerate}\n        \\item \\textbf{Basis:} $P(a), P(a+1), \\ldots P(b)$ are true.\n        \\item \\textbf{Induction:} For all integers $k\\geq b$, if $P(i)$ is true for all integers from $a$ to $k$ then $P(k+1)$ is true.\n        \\item Hence for all integers $n\\geq a, P(n)$ is true.\n    \\end{enumerate}\n    \\section*{Number Theory}\n    \\begin{itemize}\n        \\item \\textbf{Even} $n$ is even $\\iff \\exists k, n = 2k$.\n        \\item \\textbf{Odd} $n$ is odd $\\iff \\exists k, n = 2k+1$.\n        \\item \\textbf{Prime} $n$ is prime $\\iff \\forall r, s$, if $n = rs$ then $r=1$ and $s = n$ or vice versa.\n        \\item \\textbf{Composite} $n$ is composite $\\iff \\exists r, s$, if $n = rs$ and $1 < r < s$ and $1 < s < n$.\n        \\item \\textbf{Rational} $r$ is rational $\\iff \\exists a, b$ such that $r = \\frac{a}{b}$ and $b \\neq 0$.\n        \\item \\textbf{Divisible} $d|n \\iff \\exists k$ such that $n=dk$.\n    \\end{itemize}\n    \\section*{Sets}\n    Can be proven by using Induction, Algebra or Element method.\n\n    Element Method: Usually with equality or subset relations: prove that an element in LHS is an element in RHS.\n    \\begin{itemize}\n        \\item Proper Subset: $A \\subseteq B$ \\textbf{AND} there is one element in B that is \\textbf{not} in A\n        \\item Power Set: $\\wp(\\{x, y, z\\}) = \\{\\emptyset, \\{x\\}, \\{y\\}, \\{z\\},\\\\\n                  \\{x, y\\},\\{x, z\\}, \\{y, z\\}, \\{x, y, z\\}$\n    \\end{itemize}\n    \\subsection*{Identities}\n    \\begin{itemize}\n        \\item Commutative Law\n              \\begin{itemize}\n                  \\item $A \\cup B = B \\cup A $ and $A \\cap B = B \\cap A$\n              \\end{itemize}\n        \\item Associative Law\n              \\begin{itemize}\n                  \\item $(A \\cup B) \\cup C = A \\cup (B \\cup C)$ and $(A \\cap B) \\cap C = A \\cap (B \\cap C)$\n              \\end{itemize}\n        \\item Distributive Law\n              \\begin{itemize}\n                  \\item $A \\cup (B \\cap C) = (A \\cup B) \\cap (A \\cup C)$\n                  \\item $A \\cap (B \\cup C) = (A \\cap B) \\cup (A \\cap C)$\n              \\end{itemize}\n        \\item Identity Law\n              \\begin{itemize}\n                  \\item $A \\cup \\varnothing = A$ and $A \\cap U$\n              \\end{itemize}\n        \\item Idempotent Law\n              \\begin{itemize}\n                  \\item $A \\cup A = A$ and $A\\cap A = A$\n              \\end{itemize}\n        \\item Universal Bound Law\n              \\begin{itemize}\n                  \\item $A \\cup U = U$ and $A  \\cap \\varnothing = \\varnothing$\n              \\end{itemize}\n        \\item DeMorgan's Law\n              \\begin{itemize}\n                  \\item $\\complement{(A \\cup B)} = \\complement{A} \\cap \\complement{B}$ and $\\complement{(A \\cap B)} = \\complement{A} \\cup \\complement{B}$\n              \\end{itemize}\n        \\item Absorption Law\n              \\begin{itemize}\n                  \\item $A \\cup (A \\cap B) = A$ and $A \\cap (A \\cup B) = A$\n              \\end{itemize}\n        \\item Set Difference Law\n              \\begin{itemize}\n                  \\item $A-B = A \\cap \\complement{B}$\n              \\end{itemize}\n    \\end{itemize}\n    \\section*{Functions}\n    A function $f$ from a set $X$ to a set $Y$ denoted by $f: X \\to Y$ where $X$ is the domain and $Y$ is the co-domain.\n    Every element in $X$ relates to some element in $Y$ and each element in $X$ must map to at most one element in $Y$.\n    \\subsection*{One-to-One functions}\n    A function is called one-to-one or injective when no two elements in $X$ point to the same element in $Y$.\n    \\subsection*{Onto functions}\n    A function is called onto or surjective iff every element in $Y$ has at least one corresponding element in $X$.\n    \\subsection*{Inverse functions}\n    $F^{-1}(y) = x\\text{ where }F(x) = y$.\n    $F(x)$ has to be both one-to-one and onto (bijective).\n    \\section*{Relations}\n    A partition of set $A$ is a collection of nonempty, mutually disjoint subsets whose union is $A$, i.e. $A_1 \\cup A_2 \\cup A_3 \\cup \\ldots \\cup A_i = A$\n    \\begin{itemize}\n        \\item Reflexive $ \\iff \\forall x \\in A, x R x$\n              \\begin{itemize}\n                  \\item $x=x$\n                  \\item Each element is related to itself\n              \\end{itemize}\n        \\item Symmetric $ \\iff \\forall x, y \\in A, x R y \\implies y R x$\n              \\begin{itemize}\n                  \\item $|x-y| = |y-x|$\n                  \\item Each element related to another is related back to that element.\n              \\end{itemize}\n        \\item Transitive $\\iff \\forall x, y, z \\in A, (x R y \\land y R z)\\implies x R z$\n              \\begin{itemize}\n                  \\item $A = B = C \\therefore A=C$\n              \\end{itemize}\n        \\item Partition-induced relation $\\iff \\forall x, y \\in A, x R y \\iff (x, y) \\in \\text{single partition }A_i$\n        \\item Equivalence Relation: When a relation is relation is reflexive, symmetric and transitive.\n        \\item Identity Relation: $I_A = \\{(x, y) \\in A \\times A~|~x=y\\}$\n    \\end{itemize}\n    \\subsection*{Equivalence Classes}\n    The subset of all elements that are related to $a$.\n\n    Suppose $A$ is a set and $R$ is an equivalence relation on $A$. For each element $a$ in $A$, the \\textbf{equivalence class of $a$}, $[a]$ or \\textbf{class of $a$} is the set of all elements $x$ in $A$ such that $x$ is related to $a$ by $R$. $$[a] = \\{x \\in A~|~x~R~a\\}$$\n    \\section*{Partial Order Relations}\n    A relation that is reflexive, antisymmetric and transitive.\n    \\subsection*{Antisymmetry}\n    A relation is antisymmetric if $$x R y \\land y R x,~x = y$$\n    A relation is \\textbf{not} antisymmetric if $$x R y \\land y R x\\text{ but }x \\neq y$$\n    \\section*{Examples}\n    \\newtheorem{example}{Example}\n    \\subsection*{Strong Induction}\n    \\begin{example}\n        \\begin{equation*}\n            \\begin{aligned}\n                f(n) = \\begin{cases}\n                    1                   & \\text{if }n=1      \\\\\n                    3                   & \\text{if }n=2      \\\\\n                    f(n-1) + 2f(n-2) +3 & \\text{if } n\\geq 3\n                \\end{cases}\n            \\end{aligned}\n        \\end{equation*}\n        Using mathematical induction, prove that for all $n \\geq 3: f(n) \\geq 2^n$\n\n        Answer:\n        \\begin{equation*}\n            \\begin{aligned}\n                f(k+1) =f(k)+ 2f(k-1)+3              \\\\\n                \\text{Use fact that $f(n) \\geq 2^n$} \\\\\n                f(k+1) \\geq 2^k+2\\cdot 2^{k-1} +3    \\\\\n                \\text{and } f(k+1) \\geq 2^k + 2^k +3 = 2^{k+1} + 3 \\geq 2^{k+1}\n            \\end{aligned}\n        \\end{equation*}\n    \\end{example}\n    \\begin{example}\n        What is the smallest value of k such that any integer postage of k, or\n        more, cents can be formed by using only 3-cent and 8-cent stamps?\n\n        Use mathematical induction to prove that all integer postages of k, or more, cents can be\n        obtained.\n        \\begin{equation*}\n            \\begin{aligned}\n                \\textbf{Basis: } P(n):                             & n = 3a + 8b       \\\\\n                \\textbf{Induction: } P(n+1):                       & n+1 = 3a' + 8b'   \\\\\n                \\textbf{Case 1: } \\text{if } b \\geq 1, n = 3a + 8b & \\text{, so}       \\\\\n                n+1 = 3a+1+8b                                      & = 8(b-1) + 9 + 3a \\\\\n                n+1                                                & = 8(b-1) +3(a+3)  \\\\\n                \\textbf{Hence }a' = a+3      \\text{ and }          & b' = b - 1        \\\\\n                \\textbf{Case 2: } \\text{if } b = 0, n = 3a         &                   \\\\\n                \\text{Since }n \\geq 14,~a \\geq 5                                       \\\\\n                n+1 = 1 + 15 + 3(l-5)                              & = 16+ 3(l-5)      \\\\\n                \\textbf{Hence }a' = l-5      \\text{ and }          & b' = 2            \\\\\n            \\end{aligned}\n        \\end{equation*}\n    \\end{example}\n\n\\end{multicols}\n\\end{document}\n", "meta": {"hexsha": "fb9b488f1d769c2b8be07cca26c6d7ca6d45d319", "size": 8714, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/CMPUT272MT2CheatSheet.tex", "max_stars_repo_name": "n30phyte/SchoolDocuments", "max_stars_repo_head_hexsha": "79652ec7e3345d67e67f0cffe3bea468708622bd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CheatSheets/CMPUT272MT2CheatSheet.tex", "max_issues_repo_name": "n30phyte/SchoolDocuments", "max_issues_repo_head_hexsha": "79652ec7e3345d67e67f0cffe3bea468708622bd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CheatSheets/CMPUT272MT2CheatSheet.tex", "max_forks_repo_name": "n30phyte/SchoolDocuments", "max_forks_repo_head_hexsha": "79652ec7e3345d67e67f0cffe3bea468708622bd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.9550561798, "max_line_length": 274, "alphanum_fraction": 0.5112462704, "num_tokens": 2778, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8824278649085117, "lm_q1q2_score": 0.8040503596686014}}
{"text": "\\subsubsection{Bet sizing}\n\\label{sec:methods_pipeline_bet_sizing}\n\nLabels and metalabels will be used together with other features to train a secondary\nmodel whose output estimated probability for each new label will be used to size\nthe bet for that event. One way to do this is to scale the predicted probability,\nby the budget total and get value in currency for the bet. However, if we did so,\nthere would not be any awareness about other concurrent bets, so we might misuse\nthe available budget to run other concurrent bets. Lopez de Prado in chapter 10\nof \\cite{lopez_de_prado} proposes the following:\n\n\\begin{enumerate}\n  \\item Let $p_{(x)}$ be the probability of label $x$ that takes the one of the\n        values in $[-1, 1]$.\n  \\item Run a statistical test where $H_{0}: p_{(x=1)} = 0.5$ with the statistic\n        $z = \\frac{p_{(x=1)} - 0.5}{\\sqrt{0.5(1-0.5)}} = \\frac{p_{(x=1)} - 0.5}{0.5}$\n  \\item Let the bet size $m$ be: $m = 2 \\Phi_{(z)} - 1$ where $\\Phi_{(z)}$ is\n        the cumulative distribution function of the standard normal\n        distribution. $m \\in [-1; 1]$\n\\end{enumerate}\n\nOnce we have a vector of $m$ values, which has a one to one relationship with\neach label $x$, we can average the bet with those concurrent triple barrier\nwindows as the come in the pipeline. Averaging does not change the bet size\nfor open windows, but changes the size for new bets that overlap with open\nwindows.\n\nFinally, a portfolio manager might also consider bet size discretization by\nmeans of setting an integer number of equally sized budget partitions. The\ndiscretized value of the bet after the average is $m^* = round\\Bigg( \\frac{m}{d} \\Bigg) d$\nwhere $d = \\frac{1}{Number of partitions}$. And the only remaining step when\nrunning the strategy is to scale the budget by $m^*$ to have the final bet size\nin currency. The goal of this step is to reduce jitter which causes overtrading.\nTypical number of partitions are below ten.\n", "meta": {"hexsha": "55e2f36042dd564cce5a44b7e07554f8ceb2acee", "size": 1943, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/methods/pipeline/bet_sizing.tex", "max_stars_repo_name": "agalbachicar/swing_for_the_fences", "max_stars_repo_head_hexsha": "3871e88884a90e5c9dd80d71b20b811485007273", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/methods/pipeline/bet_sizing.tex", "max_issues_repo_name": "agalbachicar/swing_for_the_fences", "max_issues_repo_head_hexsha": "3871e88884a90e5c9dd80d71b20b811485007273", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/methods/pipeline/bet_sizing.tex", "max_forks_repo_name": "agalbachicar/swing_for_the_fences", "max_forks_repo_head_hexsha": "3871e88884a90e5c9dd80d71b20b811485007273", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.5142857143, "max_line_length": 90, "alphanum_fraction": 0.7349459599, "num_tokens": 531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107896491796, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.8039095230136555}}
{"text": "\\documentclass[10pt]{article}\n \n\\usepackage[margin=1in]{geometry} \n\\usepackage{amsmath,amsthm,amssymb, graphicx, multicol, array, enumerate, gensymb}\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n \n\\newenvironment{problem}[2][Problem]{\\begin{trivlist}\n\\item[\\hskip \\labelsep {\\bfseries #1}\\hskip \\labelsep {\\bfseries #2.}]}{\\end{trivlist}}\n\n\\begin{document}\n \n\\title{Mathematics problems}\n\\date{}\n\\maketitle\n\n \\section{Elementary algebra}\n \n\\begin{problem}{1.1}\nSimplify $$\\frac{z^{17}}{z^3 \\cdot z^5}$$\n\\end{problem}\n\n\\begin{problem}{1.2}\nSolve for $x$:\n$$6^2 \\cdot 6^x = 6^6$$\n\\end{problem}\n\n\\begin{problem}{1.3}\nCalculate the missing value. If $x \\cdot y$ is 5, then $x^3y^3=\\dots$\n\\end{problem}\n\n\\begin{problem}{1.4}\nCalculate\n$$\\frac{\\sqrt{2^{10}}}{\\sqrt{4^3}}$$\n\\end{problem}\n\n\\begin{problem}{1.5}\nTrue or False ($x$ and $y$ and $z$ are real numbers):\n\\begin{enumerate}[(a)]\n    \\item $x+y=y+x$\n    \\item $x(y+z)=xy+xz$\n    \\item $x^{y+z}=x^y+x^z$\n    \\item $\\frac{x^y}{x^z}=x^{y-z}$\n\\end{enumerate}\n\\end{problem}\n\n\\begin{problem}{1.6}\nFind the solution set for the inequality below:\n$$\\frac{2x-5}{2}\\ge4$$\n\\end{problem}\n\n\\section{Functions of one variable}\n\n\\begin{problem}{2.1 (Based on SYD 2.5.6)}\nThe relationship between temperatures measured in Celsius and Fahrenheit is linear. 0\\degree C is equivalent to 32\\degree F and 100\\degree C is the same as 212\\degree F.\n Which temperature is measured by the same number on both scales?\n\\end{problem}\n\n\\begin{problem}{2.2}\nTake the following function $f(x)=5x+4$. Find y if $f(y)=24$.\n\\end{problem}\n\n\\begin{problem}{2.3}\nFind all values of x that satisfy:\n$$10^{x^2-2x+2}=100$$\n\\end{problem}\n\n\\begin{problem}{2.4}\nSolve the following problem. If the annual GDP growth of a country is 3\\%, how long does it take the economy to double its GDP?\n\\end{problem}\n\n\\begin{problem}{2.5}\nCalculate the following value\n$$\\ln(1/e)$$\n\\end{problem}\n\n\\section{Calculus}\n\n\\begin{problem}{3.1}\nCalculate the following sum\n$$\\sum\\limits_{i=0}^{\\infty} \\left( \\frac{1}{8^i}+0.5^i\\right)$$\n\\end{problem}\n\n\\begin{problem}{3.2}\nFind the following limit\n$$\\lim\\limits_{x \\rightarrow 3}\\frac{x-3}{2}$$\n\\end{problem}\n\n\\begin{problem}{3.3}\nFind the slope of the function $f(x)=x^2-4$ at $(-1,-3)$.\n\\end{problem}\n\n\\begin{problem}{3.4}\nFind the following derivative\n$$\\frac{\\mathrm{d}}{\\mathrm{d}\\, x} \\frac{x^2+3}{x+2}$$\n\\end{problem}\n\n\\begin{problem}{3.5}\nFind the following second derivative\n $$\\frac{\\mathrm{d^2}}{\\mathrm{d}\\, x^2} 4x^3+4$$\n\\end{problem}\n\n\\begin{problem}{3.6}\nIs the function  $f(x)=\\frac{1}{x}$ continuous at $0$? Why?\n\\end{problem}\n\n\\begin{problem}{3.7}\nConsider the following function. Find all of its stationary points and classify them as local minima, local maxima or inflection points. Also decide whether it is convex or concave. If it has one or more inflection points then define where it is locally concave or locally convex.\n$$f(x)=3x^3-9x$$\n\\end{problem}\n\n\\begin{problem}{3.8}\nLet $f(x,y)=x^2y^3$. Calculate $f(2,3)$\n\\end{problem}\n\n\\begin{problem}{3.9}\nConsider the following function: $f(x,y)=\\ln(x-y)$. For what combinations of $x$ and $y$ is this function defined?\n\\end{problem}\n\n\\begin{problem}{3.10}\nFind the following partial derivative:\n$$\\frac{\\partial^2}{\\partial \\, x^2} x^5+xy^3$$\n\\end{problem}\n\n\\begin{problem}{3.11}\nFind the local maxima or minima of the following function:\n$$f(x,y)=\\sqrt{xy}-0.5x-0.5y$$\n\\end{problem}\n\n\\begin{problem}{3.12}\nSolve the following constrained optimization problem using Lagrange's method:\n$\\max x^2y^2$ s.t. $x+y=5$\n\\end{problem}\n\n\\section{Linear algebra}\n\n\\begin{problem}{4.1}\nTake the following matrices:\n$$A=\\begin{bmatrix} 2 & 3\\\\ 4 & 1 \\\\ 1 & 2\\end{bmatrix}$$\n$$B=\\begin{bmatrix} 1 & 4 & 1\\\\2 & 1 & 2\\end{bmatrix}$$\nWhat is $A \\cdot B$?\n\\end{problem}\n\n\\begin{problem}{4.2}\nTake the following matrices:\n$$A=\\begin{bmatrix} 2 & 3\\\\ 4 & 1 \\\\ 1 & 2\\end{bmatrix}$$\n$$B=\\begin{bmatrix} 1 & 4 & 1\\\\2 & 1 & 2\\end{bmatrix}$$\nWhat is $B \\cdot A$?\n\\end{problem}\n\n\\begin{problem}{4.3}\nWhat is the transpose of the following matrix?\n$$\\begin{bmatrix}3.3 & 5.1 & 4.7\\\\ 2 & 6.1 & 1.23 \\\\ 4 & 5.76 & 0\\end{bmatrix}$$\n\\end{problem}\n\n\\begin{problem}{4.4}\nCalculate the determinant of\n$$\\begin{bmatrix}2 & 3 \\\\ 4 & 5 \\end{bmatrix} $$\n\\end{problem}\n\n\\section{Probability theory}\n\n\\begin{problem}{5.1}\nYou run an experiment where you flip a coin four times. Each time you get either heads (H) or tails (T). What is the sample space of your experiment?\n\\end{problem}\n\n\\begin{problem}{5.2}\nAssume that in a certain country 1\\% of the population uses a certain drug. You have a way to test drug use, which will give you a positive result in 99\\% of the cases where the individual is indeed a drug user and a negative result in 99.5\\% of the cases where the individual doesn't use the drug. What is the probability that someone with a positive drug test is indeed a drug user?\n\\end{problem}\n\n\\begin{problem}{5.3}\nYou run an experiment in which you toss a dice twice and sum up the results. What is the expected value of this sum?\n\\end{problem}\n\\end{document}\n", "meta": {"hexsha": "a8cce8091039a9ccf836fe65efd3f9b8086a77c3", "size": 5056, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "opt_out_exam/math_tasks.tex", "max_stars_repo_name": "kiss-oliver/ba-pre-session-2018-archive", "max_stars_repo_head_hexsha": "7508efa839b8d8ae3adfa5c237bee3176a1de6e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "opt_out_exam/math_tasks.tex", "max_issues_repo_name": "kiss-oliver/ba-pre-session-2018-archive", "max_issues_repo_head_hexsha": "7508efa839b8d8ae3adfa5c237bee3176a1de6e6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "opt_out_exam/math_tasks.tex", "max_forks_repo_name": "kiss-oliver/ba-pre-session-2018-archive", "max_forks_repo_head_hexsha": "7508efa839b8d8ae3adfa5c237bee3176a1de6e6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8914285714, "max_line_length": 384, "alphanum_fraction": 0.6888844937, "num_tokens": 1776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741281688026, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.8038726397118919}}
{"text": "\\section{Implementation}\n\n\\subsection{Dataset Generation}\nThe first step of the experiment is to generate an artificial dataset with $P$ random N-dimensional feature vectors and binary labels $\\mathcal{D} = \\{ \\xi^\\mu, S^\\mu \\,|\\, \\xi^\\mu \\in \\mathds{R}^N, S^\\mu \\in \\{+1, -1\\} \\}_{\\mu=1}^P$.\nThe feature vectors $\\xi^\\mu$ have independent random components $\\xi_j^\\mu \\sim \\mathcal{N}(0, 1)$ and are generated using the \\texttt{randn} command in Matlab.\nThe labels $S^\\mu$ are assuming the values $\\{+1, -1\\}$ with equal probability of $1/2$.\n\n\\begin{lstlisting}[language=Matlab]\n  function [X, y] = generate_dataset(P, N)\n      X = randn(P, N);\n      y = iff(rand(P, 1) < 0.5, -1, 1);\n  end\n\\end{lstlisting}\n\n\\subsection{Perceptron Training}\nThe next step is to use the Rosenblatt algorithm to implement and train a perceptron on the generated dataset.\nThe Rosenblatt algorithm is a sequential procedure that learns the weights of the perceptron from the examples.\nThe weights are initialized to zero, then the training examples are presented one by one to the perceptron for a given number of iterations.\nIf the example is correctly classified according to the current weights, no update is performed;\nif the example is wrongly classified, the weights are updated according to the following rule:\n\\begin{gather} \n    \\mathsf{\\bm{w}}(0) = 0, \\\\\n    \\mathsf{\\bm{w}}(t + 1) =\n        \\begin{cases}\n            \\mathsf{\\bm{w}}(t) + \\frac{1}{N} \\xi^{\\mu(t)} S^{\\mu(t)} &\\text{if $E^{\\mu(t)} \\leq 0$}\\\\\n            \\mathsf{\\bm{w}}(t) &\\text{else}\n        \\end{cases},\n    \\label{eq:update-rule}\n\\end{gather}\nwhere $E^{\\mu(t)} = \\mathsf{\\bm{w}}(t) \\cdot \\xi^{\\mu(t)} S^{\\mu(t)}$, $t = 1, 2, ...$ represents the current time step and $\\mu(t) = 1, 2, ..., P, 1, 2, ...$ identifies the current example.\nThe algorithm is stopped either when $E^\\mu > 0$ for all examples in the dataset or the maximum number of iterations $n_{max}$ is reached.\n\n\\subsection{Experiments}\nFor a fixed value of $P$ and $N$, $n_D$ independent datasets are generated.\nA new perceptron is trained on each dataset for at most $n_{max}$ iterations.\nFor each dataset, we compute the rate fraction $Q_{l.s.}$ of successful runs, where a run is successful if the perceptron correctly classifies each example in the dataset at the end of the training phase.\n$Q_{l.s.}$ gives an estimate of the probability that the perceptron finds a linear separation in a random dataset of $P$ independent points in $N$ dimension.\n\nMultiple experiments are run for different values of $P$ and $N$ in order to compute $Q_{l.s.}$ as a function of $\\alpha = P / N$.\nIn other words, we study the probability of the perceptron to find a linear separation as a function of the rate between the number of examples and the dimension of the input.\n\n\\subsection{Bonus}\n\\subsubsection{Weight Update Criterion}\nWe modified the function to train the perceptron to update the weights vector $\\mathsf{\\bm{w}}$ if $E^\\mu < c$ instead of $E^\\mu < 0$ (see \\cref{eq:update-rule}).\nAlso, we changed the algorithm to stop the training only if $E^{\\mu} > c$ for all examples in the dataset or the maximum number of iterations $n_{max}$ is reached.\n\n\\subsubsection{Inhomogeneous Perceptrons}\nRosenblatt perceptrons only learns separation hyperplanes that goes through the origin (homogeneous).\nIn general, a solution to the classification problem may be a hyperplane that does not go through the origin (inhomogeneous), but be in the form:\n\\begin{equation}\n    S = sign(\\mathsf{\\bm{w}} \\cdot \\xi + \\theta) = \\pm 1\n\\end{equation}\n\nIt is possible to generalize the Rosenblatt perceptron to learn also inhomogeneous separation hyperplanes by adding an artificial dimension to the dataset and forcing it to a non-zero constant (e.g. $-1$) and increasing the size of the weights vector $\\mathsf{\\bf{w}}$ by $1$ (the last element of $\\mathsf{\\bf{w}}$ corresponds to the intercept $\\theta$).\n", "meta": {"hexsha": "c623dbf4e1acfc929f73d2b23cabf6b986245f1f", "size": 3909, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_1/report/03_implementation.tex", "max_stars_repo_name": "davidepedranz/neural_networks_assignments", "max_stars_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_1/report/03_implementation.tex", "max_issues_repo_name": "davidepedranz/neural_networks_assignments", "max_issues_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_1/report/03_implementation.tex", "max_forks_repo_name": "davidepedranz/neural_networks_assignments", "max_forks_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 71.0727272727, "max_line_length": 354, "alphanum_fraction": 0.7152724482, "num_tokens": 1097, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.8038649073461438}}
{"text": "\\section{ML}\n\n\\subsection{Principal Component Analysis}\n\n\\marginnote{\n\\begin{theorem}\nLet $L$ be a $k$-dimensional subspace of $\\mathbb{R}^n$.\nThen each vector $x$ in $\\mathbb{R}^n$ can be written uniqely in the form\n\\[\nx = h + p\n\\]\nwhere $p$ is in $L$ and $h$ is in $L^{\\perp}$.\n\\end{theorem}\n\\begin{proof}\nLet ${e_1, \\ldots, e_k}$ be an orthogonal basis for $L$, and define $p$ as\n\\[\np = \\frac{x \\cdot e_1}{e_1 \\cdot e_1} + \\ldots + \\frac{x \\cdot e_k}{e_k \\cdot e_k}.\n\\]\nBeing a linear combination of $e_1, \\ldots, e_k$, $p$ is in $L$.\nLet $h = x - p$.\nSince each $e_{i}$, $i = 1, \\ldots, k$ is orthogonal to all the rest basis vectors,\nit follows that for all $i$\n\\begin{align*}\nh \\cdot e_i &= (x - p) \\cdot e_i \\\\\n&= x \\cdot e_i - \\left(\\frac{x \\cdot e_i}{e_i \\cdot e_i}\\right) \\cdot e_i \\underbrace{- 0 - 0 \\ldots - 0}_{(k-1) \\text{ times}} \\\\\n&= x \\cdot e_i - x \\cdot e_i = 0.\n\\end{align*}\nThus, we can conclude that $h$ is in $L^{\\perp}$.\n\nTo show that the decomposition stated in the theorem is unique,\nsuppose there is another one: $x = h_1 + p_1$ where $h_1 \\in L$ and $p_1 \\in L$.\nThen $h + p = h_1 + p_1$ as both sides equal $x$ and\n\\[\np - p_1 = h - h_1.\n\\]\nIt follow that the vector $v = p - p_1$ is in $L$ and in $L^{\\perp}$\nwhich is possible if and only if $v = 0$.\n\\end{proof}\n\nFrom this theorem it directly follows that\n\\[\n\\lVert x \\rVert^2 = \\lVert h \\rVert^2 + \\lVert p \\rVert^2.\n\\]\nThus, holding the observation vector $x$ fixed\nmaximizing $\\lVert h \\rVert$ and minimizing $\\lVert p \\rVert$\nare equivalent in order to get the longest projection of $x$ onto $L$.\n}\n\nPCA is a tool to preserve as much variability in $n$-dimensional data as possible\nby projecting it onto $q$-dimensional subspace spanned by the principal components.\nThere are two ways to find these principal components.\nOne can either maximize the length of the projection of some vector $x$\nonto the $q$-dimensional subspace,\nor minimize the length of its orthogonal component.\nBoth ways are equivalent which can be shown by the orthogonal decomposition theorem.\nHowever, there is also a geometrical interpretaion.\n\n\\begin{theorem}\nIn PCA the best-fit $q$-dinesional subspace for a set of observations $x_1, \\ldots, x_n$\nis defined by solving either\n\\[\n\\sum_{n=1}^N \\lVert h \\rVert^2  \\to \\min_{v_1, \\ldots, v_k}\n\\]\nwhich minimizes the distance between the observation and the subspace, or\n\\[\n\\sum_{n=1}^N \\lVert p \\rVert^2  \\to \\max_{w_1, \\ldots, w_k}.\n\\]\nwhich maximizes the varince of projected data.\n\\end{theorem}\n\n\\begin{proof}\nConsider a space of $n$ observations and two factors.\nAdditionaly assume that all the observations are centred and\nthe best-fit line is already found.\n\nLet us drop the perpendiculars from all the observation points onto the best-fit line\nand denote them as $a_i$, $i = 1, \\ldots, n$.\nThen there is a right triangle for each observation.\nWe denote another leg as $b_i$ and the distance of observation point from the origin as $c_i$.\nThus, for every point we can apply the Pythagorean theorem: $c_i^2 = a_i^2 + b_i^2$.\nSumming through all the observations, we get\n%\\begin{marginfigure}\n%  \\includegraphics[scale=0.7]{figures/05_pca.pdf}\n%  \\caption{Equivalence of minimizing the perpendicular lengths $a_i$ and\n%  maximazing the projection length $b_i$}\n%  \\label{fig:pca}\n%end{marginfigure}\n\\[\n\\sum\\limits_{i=1}^n c_i^2 = \\sum\\limits_{i=1}^n a_i^2 + \\sum\\limits_{i=1}^n b_i^2\n\\]\nBeing unable to change the distance of the observation from the origin,\nwe can either minimize $\\sum_{i=1}^n a_i^2$, or maximize $\\sum_{i=1}^n b_i^2$\nin order to get the principal component.\n\n\n\\end{proof}\n", "meta": {"hexsha": "0c77e12f54cff74778d5afff117ee9bdc72d1f47", "size": 3603, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/5_ml.tex", "max_stars_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_stars_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-22T20:38:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:38:41.000Z", "max_issues_repo_path": "chapters/5_ml.tex", "max_issues_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_issues_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-06-29T09:11:36.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-28T19:35:55.000Z", "max_forks_repo_path": "chapters/5_ml.tex", "max_forks_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_forks_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-05-21T18:32:18.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-21T18:32:18.000Z", "avg_line_length": 37.1443298969, "max_line_length": 130, "alphanum_fraction": 0.7033028032, "num_tokens": 1201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.8740772269642949, "lm_q1q2_score": 0.8038385973004385}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 9}\n\nProve that if a binary tree has depth $n$, then it has at most $2^n$ leaves.\n\n\\subsection*{Solution}\n\nProof is given by induction on depth $n$ of binary tree.\nBy definition of \\textit{binary} trees, it is assumed each node has at most two children.\n\\begin{proof}\nInduction on depth $n$ of the binary tree.\n\\begin{itemize}\n\\item[] Argument is trivially true for \\emph{base step} $n=0$ where there is only one node (if any) with no children.\nIn this case, the node (if exists) will be the only leaf and number of leaves is either zero or one.\nTherefore, a binary tree with depth $0$ has at most $2^0=1$ leaf.\n\\item[] When $n=1$, there is only one parent node and by definition it has at most two children.\nIt follows that any additional node should be child of one of those children which will contradict our earlier assumption that depth of tree is $n=1$.\n\n\\item[] \\emph{Inductive hypothesis} is formed as follows.\nA binary tree with depth $n$ has at most $2^n$ leaves.\nWe show that a binary tree with depth $n+1$ has at most $2^{n+1}$ leaves.\n\n\n\\item[] The only way to obtain a binary tree with depth $n+1$ is to add at least one child to at least one of the leaves of a binary tree with depth $n$.\nBy inductive hypothesis, as there are at most $2^n$ leaves in a binary tree with depth $n$, we can at most promote $2^n$ leaves to parents.\nAs each parent has at most two children, maximum number of children in a binary tree with depth $n+1$ will be $2 \\times 2^n = 2^{n+1}$.\nAs all former leaves will be parents with 2 children, any additional node should be child of one of the new leaves which contradicts our earlier assumption about depth of the tree.\n\n\\end{itemize}\n\\end{proof}\n", "meta": {"hexsha": "d30e97410381c9ffcbccf5a9e2ac4305331882eb", "size": 2061, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q09.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q09.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q09.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 55.7027027027, "max_line_length": 180, "alphanum_fraction": 0.6962639495, "num_tokens": 532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.8872045959539038, "lm_q1q2_score": 0.803798325775571}}
{"text": "\\section{Axioms}\n\n\\begin{axiom}[\\cindex{Axiom of Extensionality}]\\label{axiomofextensionality}\n    If $X$ and $Y$ have the same elements, then $X=Y$.\n    \\begin{equation}\n        \\forall u (u \\in X \\leftrightarrow u \\in Y ) \\rightarrow X = Y\n    \\end{equation}\n\\end{axiom}\n\n\\begin{axiom}[\\cindex{Axiom of Pairing}]\n    For any $a$ and $b$ there exists a set $\\set{a,b}$ that contains exactly $a$ and $b$.\n    \\begin{equation}\n        \\forall a \\forall b \\exists c \\forall x (x \\in c \\leftrightarrow x = a \\vee x = b )\n    \\end{equation}\n    A \\cindex{singleton} $\\set{a}$ is the set $\\set{a} = \\set{a, a}$. An \\cindex{ordered pair} $(a,b)$ is the set $(a,b) = \\set{\\set{a}, \\set{a,b}}$.\n\\end{axiom}\n\n\\begin{axiom}[\\cindex{Axiom Schema of Seperation}]\n    If $P$ is a property with parameter $p$, then for any $X$ and $p$ there exists a set $Y = \\set{u \\in X: P(u,p)}$ that contains all those $u \\in X$ that have property $P$.\n    \\begin{equation}\n        \\forall X \\forall p \\exists Y \\forall u \\left(u \\in Y \\leftrightarrow u \\in X \\wedge \\varphi(u, p) \\right)\n    \\end{equation}\n    If define class $C = \\varphi(u, p)$, then $\\forall X \\exists Y (C \\wedge X )= Y$, so a subclass of a set is a set. The empty class $\\emptyset = \\set{u: u \\neq u} $ is a \\cindex{empty set}.\n\\end{axiom}\n\n\\begin{axiom}[\\cindex{Axiom of Union}]\n    For any $X$ there exists a set $Y = \\cup X$, the union of all elements of $X$.\n    \\begin{equation}\n        \\forall X \\exists Y \\forall u \\left(u \\in Y \\leftrightarrow \\exists z (z \\in X \\wedge u \\in z ) \\right)\n    \\end{equation}\n\\end{axiom}\n\n\\begin{axiom}[\\cindex{Axiom of Power Set}]\n    For any $X$ there exists a set $Y = P(X)$, the set of all subset of $X$.\n    \\begin{equation}\n        \\forall X \\exists Y \\forall u (u \\in Y \\leftrightarrow u \\subset X )\n    \\end{equation}\n\\end{axiom}\n\n\\begin{axiom}[\\cindex{Axiom of Infinity}]\n    There exists an infinite set.\n    \\begin{equation}\n        \\exists S \\left( \\emptyset \\in S \\wedge (\\forall x \\in S ) x \\cup \\set{x} \\in S \\right)\n    \\end{equation}\n    A set $S$ with above property is called \\cindex{inductive}.\n\\end{axiom}\n\n\\begin{axiom}[\\cindex{Axiom Schema of Replacement}]\n    If a class $F$ is a function, then for any $X$ there exists a set $Y = F(X) = \\set{F(x): x \\in X}$.\n    \\begin{equation}\n        \\forall x \\forall y \\forall z \\left( \\varphi(x,y,p) \\wedge \\varphi(x,z,p) \\rightarrow y = z \\right) \\rightarrow \\forall X \\exists Y \\forall y \\left( y \\in Y \\rightarrow (\\exists x \\in X ) \\varphi(x,y,p) \\right)\n    \\end{equation}\n    So if a class $F$ is a function and $\\domain{f}$ is a set, then $\\range{f}$ is a set.\n\\end{axiom}\n\n\\begin{axiom}[\\cindex{Axiom of Regularity}]\\label{axiomofregularation}\n    Every nonempty set has an $\\in$-minimal element.\n\\end{axiom}\n\n\\begin{axiom}[\\cindex{Axiom of Choice}]\\label{axiomofchoice}\n    Every family of nonempty set has a choice function.\n\\end{axiom}\n\nThe \\thmref{axiomofextensionality} to \\thmref{axiomofregularation} is the \\cindex{Zermelo-Fraenkel} axiomatic set theory \\cindex{ZF}. \\cindex{ZFC} denote the ZF + \\cindex{AC}, the axiom of choice.\n\n\\begin{theorem}[\\cindex{Russell's Paradox}]\n    There is no set whose elements are all those sets that are not member of themselves: $S = \\set{X : X \\notin X}$. So the set of all set does not exist.\n\\end{theorem}\n\n\n\\begin{definition}\n    A binary relation $f$ is a \\cindex{function} if $(x,y) \\in f$ and $(x, z) \\in f$ implies $y = z$. For a function $f$ from $X$ to $Y$ $f : X \\rightarrow Y$, if $Y = \\range{f}$, $f$ is \\cindex{onto}. If $f(x) = f(y)$ implies $x=y$, $f$ is \\cindex{one-to-one}. The \\cindex{inverse image} $f_{-1} (Y) = \\set{x: f(x) \\in Y}$. If $f$ is one-to-one, then the \\cindex{inverse} is $f^{-1} (y) = x$.\n\\end{definition}\n\n\\begin{definition}\n    The \\cindex{restriction} of a function $f$ to a set $X$ is:\n    \\begin{equation}\n        f\\restriction_X = \\set{(x,y) \\in f : x \\in X}\n    \\end{equation}\n\\end{definition}\n\n\\begin{definition}[class]\n    if $\\varphi(x, p_1, \\dots, p_n)$ is a formula, then $C = \\set{x: \\varphi(x, p_1, \\dots, p_n)}$ is a \\cindex{class}. So a formula defines a class.\n\\end{definition}\n\n\\begin{definition}[universe]\n    The \\cindex{universe} is the class of all sets: $V = \\set{x: x = x}$.\n\\end{definition}\n\n\\begin{definition}\n    A class that is not a set is a \\cindex{proper class}.\n\\end{definition}", "meta": {"hexsha": "a4981280545a61dbcf4f30b0b9d5bb7a55e16756", "size": 4345, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/set_theory/st.1.axioms.tex", "max_stars_repo_name": "elvisren/machine-learning-notes", "max_stars_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-04T17:28:22.000Z", "max_issues_repo_path": "src/set_theory/st.1.axioms.tex", "max_issues_repo_name": "elvisren/machine-learning-notes", "max_issues_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/set_theory/st.1.axioms.tex", "max_forks_repo_name": "elvisren/machine-learning-notes", "max_forks_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-01T23:34:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-01T23:34:47.000Z", "avg_line_length": 47.2282608696, "max_line_length": 393, "alphanum_fraction": 0.6402761795, "num_tokens": 1537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8807970873650401, "lm_q1q2_score": 0.8036711083601007}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find the roots of the polynomial $p(z) = z^2-6z+13$.\n  \\begin{sol}\n    By the quadratic formula, $\\displaystyle z=\\frac{6\\pm\\sqrt{16}}{2}\n      = 3\\pm 2i$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the roots of $p(z) = z^3 + 5z^2 + 4z - 10$. Hint: one of the\n  roots is $z=1$.\n  \\begin{sol}\n    $p(z)$ factors as $(z-1)(z^2+6z+10)$. The roots are $z=1$,\n    $z=-3+i$, and $z=-3-i$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Factor $z^3 - 3z + 2$ into a product of linear factors.\n  \\begin{sol}\n    By trial and error, we find the roots $z=1$ and $z=-2$. Moreover,\n    $z=1$ is a double root. We have $z^3 - 3z + 2 = (z-1)(z-1)(z+2)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $p(x) =a_nx^n+a_{n-1}x^{n-1}+\\ldots+a_1x+a_0$ be a\n  polynomial with real coefficients, i.e., such that all the $a_k$\n  are real numbers. Suppose that $z$ is a root of $p$. Show that\n  $\\conjugate{z}$ is also a root of $p$.\n  \\begin{sol}\n    If $p(z) =0$ and $a_0,\\ldots,a_k$ are real, we have\n    \\begin{eqnarray*}\n      p(\\conjugate{z})\n      &=& a_n\\conjugate{z}^n+a_{n-1}\\conjugate{z}^{n-1}+\\ldots+a_1\\conjugate{z}+a_0 \\\\\n      &=&\\conjugate{a_n}\\ \\conjugate{z}^n+\\conjugate{a_{n-1}}\n          \\ \\conjugate{z}^{n-1}+\\ldots+\\conjugate{a_1}\n          \\ \\conjugate{z}+\\conjugate{a_0}\n      \\\\\n      &=& \\conjugate{a_nz^n}+\\conjugate{a_{n-1}z^{n-1}}+\\ldots+\\conjugate{a_1z}+\n          \\conjugate{a_0} \\\\\n      &=& \\conjugate{a_nz^n+a_{n-1}z^{n-1}+\\ldots+a_1z+a_0} \\\\\n      &=& \\conjugate{p(z)} \\\\\n      &=& 0.\n    \\end{eqnarray*}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "dc6fb088868c1f9ee01f5d49e7995aa131dceaab", "size": 1551, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/ComplexNumbers-FundamentalTheorem.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/ComplexNumbers-FundamentalTheorem.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/ComplexNumbers-FundamentalTheorem.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 30.4117647059, "max_line_length": 86, "alphanum_fraction": 0.5596389426, "num_tokens": 702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.8705972600147106, "lm_q1q2_score": 0.8035953617999007}}
{"text": "\\section{Linear transformations}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine whether a vector function $T:\\R^n\\to\\R^m$ is a\n    linear transformation.\n  \\end{enumerate}\n\\end{outcome}\n\nIn calculus, a \\textbf{function}%\n\\index{function} (or \\textbf{map}%\n\\index{map|see{function}}) $f:\\R\\to\\R$ is a rule that maps a real\nnumber $x\\in\\R$ to a real number $f(x)\\in\\R$. In linear algebra, we\ncan generalize this concept to vectors. A \\textbf{vector function}%\n\\index{vector function}%\n\\index{function!vector function} $T:\\R^n\\to\\R^m$ is a rule that inputs\nan $n$-dimensional vector $\\vect{v}\\in\\R^n$ and outputs an\n$m$-dimensional vector $T(\\vect{v})\\in\\R^m$. The following are some\nexamples of vector functions:\n\\begin{equation}\\label{eqn:vector-functions}\n  T_1\\paren{\\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}}\n  = \\begin{mymatrix}{c} x^2 \\\\ x+y \\\\ y^2 \\end{mymatrix},\\quad\n  T_2\\paren{\\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}}\n  = \\begin{mymatrix}{c} x+y \\\\ x+y+z \\\\ 0 \\end{mymatrix},\\quad\n  T_3\\paren{\\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}}\n  = \\begin{mymatrix}{c} e^{x+z} \\\\ \\sqrt{y} \\end{mymatrix}.\n\\end{equation}\nOf these, the first is a function $T_1:\\R^2\\to\\R^3$, the second is a\nfunction $T_2:\\R^3\\to\\R^3$, and the third is a function\n$T_3:\\R^3\\to\\R^2$.  We can evaluate a vector function by applying it\nto a vector, for example,\n\\begin{equation*}\n  T_1\\paren{\\begin{mymatrix}{c} 1 \\\\ 2 \\end{mymatrix}}\n  = \\begin{mymatrix}{c} 1^2 \\\\ 1+2 \\\\ 2^2 \\end{mymatrix}\n  = \\begin{mymatrix}{c} 1 \\\\ 3 \\\\ 4 \\end{mymatrix},\\quad\n  T_1\\paren{\\begin{mymatrix}{c} 0 \\\\ 1 \\end{mymatrix}}\n  = \\begin{mymatrix}{c} 0^2 \\\\ 1+1 \\\\ 1^2 \\end{mymatrix}\n  = \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 1 \\end{mymatrix},\n\\end{equation*}\nand so on. The study of arbitrary vector functions and their\nderivatives and integrals is the subject of {\\em multivariable\n  calculus}%\n\\index{calculus!multivariable}%\n\\index{multivariable calculus}. In linear algebra, we will only be\nconcerned with \\textbf{linear vector functions}%\n\\index{vector function!linear|see{linear transformation}}%\n\\index{linear function|see{linear transformation}}%\n\\index{function!linear|see{linear transformation}}, which are\nalso called \\textbf{linear transformations}%\n\\index{linear transformation} or \\textbf{linear maps}%\n\\index{linear map|see{linear transformation}}. They are defined as follows.\n\n\\begin{definition}{Linear transformation}{linear-transformation}\n  A vector function $T:\\R^n\\to \\R^m$ is called a \\textbf{linear\n    transformation}%\n  \\index{linear transformation!on $\\R^n$}, or simply \\textbf{linear}, if it\n  satisfies the following two conditions:\n  \\begin{enumerate}\n  \\item $T$ preserves addition, i.e., for all\\/\n    $\\vect{v},\\vect{w}\\in\\R^n$, we have\n    $T(\\vect{v}+\\vect{w}) = T(\\vect{v}) + T(\\vect{w})$;\n  \\item $T$ preserves scalar multiplication, i.e, for all\\/\n    $\\vect{v}\\in\\R^n$ and scalars $k$, we have\n    $T(k\\vect{v}) = kT(\\vect{v})$.\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{example}{Linear and non-linear transformations}{linear-transformation}\n  Which of the vector functions in {\\eqref{eqn:vector-functions}} are\n  linear transformations?\n\\end{example}\n\n\\begin{solution}\n  \\begin{enumerate}\n  \\item[(a)] The function $T_1$ is not a linear transformation. For\n    example, let $\\vect{v}=\\begin{mymatrix}{r} 1 \\\\\n      0 \\end{mymatrix}$. Then\n    \\begin{equation*}\n      T_1(\\vect{v})\n      ~=~ T_1\\paren{\\begin{mymatrix}{c} 1 \\\\ 0 \\end{mymatrix}}\n      ~=~ \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n      \\quad\\mbox{and}\\quad\n      T_1(2\\vect{v})\n      ~=~ \\paren{\\begin{mymatrix}{c} 2 \\\\ 0 \\end{mymatrix}}\n      ~=~ \\begin{mymatrix}{c} 4 \\\\ 2 \\\\ 0 \\end{mymatrix}\n      ~\\neq~ 2\\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}.\n    \\end{equation*}\n    Since $T_1(2\\vect{v}) \\neq 2T_1(\\vect{v})$, the vector function\n    $T_1$ does not preserve scalar multiplication, and therefore it is\n    not a linear transformation.\n  \\item[(b)] The function $T_2$ is a linear transformation. For\n    example, to prove that $T_2$ preserves addition, consider two\n    arbitrary vectors\n    \\begin{equation*}\n      \\vect{v} =\n      \\begin{mymatrix}{c}\n        x_1 \\\\\n        y_1 \\\\\n        z_1 \\\\\n      \\end{mymatrix}\n      \\quad\\mbox{and}\\quad\n      \\vect{w} =\n      \\begin{mymatrix}{c}\n        x_2 \\\\\n        y_2 \\\\\n        z_2 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n    We have\n    \\begin{equation*}\n      T_2(\\vect{v}+\\vect{w})\n      ~=~ T_2\\paren{\n        \\begin{mymatrix}{c}\n          x_1+x_2 \\\\\n          y_1+y_2 \\\\\n          z_1+z_2 \\\\\n        \\end{mymatrix}}\n      ~=~ \\begin{mymatrix}{c}\n        (x_1+x_2)+(y_1+y_2) \\\\\n        (x_1+x_2)+(y_1+y_2)+(z_1+z_2) \\\\\n        0\n      \\end{mymatrix}\n    \\end{equation*}\n    and\n    \\begin{equation*}\n      T_2(\\vect{v})+T_2(\\vect{w})\n      ~=~\n      \\begin{mymatrix}{c}\n        x_1+y_1 \\\\\n        x_1+y_1+z_1 \\\\\n        0 \\\\\n      \\end{mymatrix}\n      + \\begin{mymatrix}{c}\n        x_2+y_2 \\\\\n        x_2+y_2+z_2 \\\\\n        0 \\\\\n      \\end{mymatrix}\n      ~=~ \\begin{mymatrix}{c}\n        (x_1+y_1)+(x_2+y_2) \\\\\n        (x_1+y_1+z_1)+(x_2+y_2+z_2) \\\\\n        0 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n    Since the two sides are evidently equal, $T_2$ preserves\n    addition. The fact that it preserves scalar multiplication can be\n    shown by a similar calculation.\n  \\item[(c)] The function $T_3$ is not a linear transformation. For\n    example, consider\n    $\\vect{v}=\\begin{mymatrix}{c}0\\\\1\\\\0\\end{mymatrix}$ and\n    $\\vect{w}=\\begin{mymatrix}{c}1\\\\1\\\\0\\end{mymatrix}$.\n    Then\n    \\begin{equation*}\n      T_3(\\vect{v}+\\vect{w})\n      ~=~ T_3\\paren{\\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 0\\end{mymatrix}}\n      ~=~ \\begin{mymatrix}{c} e \\\\ \\sqrt{2} \\end{mymatrix},\n    \\end{equation*}\n    and\n    \\begin{equation*}\n      T_3(\\vect{v})+T_3(\\vect{w})\n      ~=~ \\begin{mymatrix}{c} 1 \\\\ 1 \\end{mymatrix}\n      + \\begin{mymatrix}{c} e \\\\ 1 \\end{mymatrix}\n      ~=~ \\begin{mymatrix}{c} e+1 \\\\ 2 \\end{mymatrix}.\n    \\end{equation*}\n    Since $T_3(\\vect{v}+\\vect{w})\\neq T_3(\\vect{v})+T_3(\\vect{w})$,\n    the vector function $T_3$ does not preserve addition, and therefore\n    it is not linear.\n  \\end{enumerate}\n\\end{solution}\n\nAn easy fact about linear transformation is that they preserve the\norigin, i.e., they satisfy $T(\\vect{0}) = \\vect{0}$. This can be seen,\nfor example, by considering\n$T(\\vect{0}) = T(\\vect{0}+\\vect{0}) = T(\\vect{0}) + T(\\vect{0})$ and\nthen subtracting $T(\\vect{0})$ from both sides of the equation.  This\ngives an easier way to see that $T_3$ in the above example is not a\nlinear transformation, since $T_3(\\vect{0}) \\neq \\vect{0}$. On the\nother hand, of course not every function that preserves the origin is\nlinear. For example, $T_1$ is not linear although it satisfies\n$T_1(\\vect{0})=\\vect{0}$.\n\nThe following characterization of linearity is often useful, as it\npermits us to check just one property instead of two.\n\n\\begin{proposition}{Alternative characterization of linear transformations}{linear-transformation-alternative}\n  A vector function $T:\\R^n\\to \\R^m$ is linear if and only if it\n  satisfies the following condition, for all\n  $\\vect{v},\\vect{w}\\in\\R^n$ and scalars $a,b$:\n  \\begin{equation*}\n    T(a\\vect{v}+b\\vect{w}) = aT(\\vect{v}) + bT(\\vect{w}).\n  \\end{equation*}\n\\end{proposition}\n\n\\begin{proof}\n  First, assume that $T$ is linear. Then from preservation of addition\n  and scalar multiplication, we have\n  $T(a\\vect{v}+b\\vect{w}) = T(a\\vect{v})+T(b\\vect{w}) = aT(\\vect{v}) +\n  bT(\\vect{w})$. Conversely, assume that $T$ satisfies\n  $T(a\\vect{v}+b\\vect{w}) = aT(\\vect{v}) + bT(\\vect{w})$ for all\n  vectors $\\vect{v},\\vect{w}$ and scalars $a,b$. Then we get\n  preservation of addition by setting $a=b=1$, and preservation of\n  scalar multiplication by setting $b=0$.\n\\end{proof}\n", "meta": {"hexsha": "d7919d954bbb933d41bf26e84702d9b696740ccd", "size": 7775, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/LinearTransformationsRn-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/LinearTransformationsRn-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/LinearTransformationsRn-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 38.3004926108, "max_line_length": 110, "alphanum_fraction": 0.6347266881, "num_tokens": 2801, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.8856314828740729, "lm_q1q2_score": 0.8035442746922958}}
{"text": "\n\\color{black}\n\\subsection*{action primitives from in-game data}\n\nGiven the sequence\n\\begin{equation*}\n\\vec{x}[1]:\\vec{x}[2]:\\vec{x}[3]:\\vec{x}[3]:\\cdots:\\vec{x}[n]\n\\end{equation*}\nof subsequent 3D locations contained in file \\texttt{q3dm1-path2.csv}, compute a sequence\n\\begin{equation*}\n\\vec{v}[1]:\\vec{v}[2]:\\vec{v}[3]:\\vec{x}[3]:\\cdots:\\vec{v}[n-1]\n\\end{equation*}\nof velocity vectors where \n\\begin{equation*}\n\\vec{v}[t] = \\vec{x}[t+1] - \\vec{x}[t]\n\\end{equation*}\n\n\n\n\n\n\\vspace{2cm}\nGiven your sequence of velocity vectors, compute their average\n\\begin{equation*}\n\\mathbb{E} \\bigl[ \\vec{v} \\bigr] = \\frac{1}{n-1} \\sum_{t=1}^{n-1} \\vec{v}[t]\n\\end{equation*}\nEnter your result here. That is, replace the dots in the following expression by the appropriate numbers rounded to \\emph{four} decimals. \\color{blue}\n%%%%%\n%%%%% enter your answer here, i.e. replace the \\ldots with the numbers you computed\n%%%%%\n\\begin{equation*}\n\\mathbb{E} \\bigl[ \\vec{v} \\bigr] = \\begin{bmatrix} -0.338 \\\\  0.1112 \\\\ 0.     \\end{bmatrix}\n\\end{equation*}\n%%%%%\n%%%%%\n%%%%%\n\\color{black}\n\n\n\n\n\n\\vspace{2cm}\nRun $k$-means clustering on the velocity vectors $\\vec{v}[t]$ to estimate representative velocities or \\emph{action primitives} $\\vec{a}_1, \\vec{a}_2, \\ldots, \\vec{a}_k$. For $k=24$, compute the average\n\\begin{equation*}\n\\mathbb{E} \\bigl[ \\vec{a} \\bigr] = \\frac{1}{k} \\sum_{i=1}^{k} \\vec{a}_i\n\\end{equation*}\nEnter your result here. That is, replace the dots in the following expression by the appropriate numbers rounded to \\emph{four} decimals. \\color{blue}\n%%%%%\n%%%%% enter your answer here, i.e. replace the \\ldots with the numbers you computed\n%%%%%\n\\begin{equation*}\n\\mathbb{E} \\bigl[ \\vec{a} \\bigr] = \\begin{bmatrix} -7.8100e-02 \\\\ -5.9163e+00 \\\\ -4.0000e-04 \\end{bmatrix}\n\\end{equation*}\n%%%%%\n%%%%%\n%%%%%\n\\color{black}", "meta": {"hexsha": "0485e42e816e24c4736017c3f7b9c7c0638fdc85", "size": 1813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SelfTest2SS2020/selfTestProblem2.tex", "max_stars_repo_name": "baraaHassan/Game-AI-Course", "max_stars_repo_head_hexsha": "dd4ed04b10b2231aac2f98b3b88274f7ab0cc339", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SelfTest2SS2020/selfTestProblem2.tex", "max_issues_repo_name": "baraaHassan/Game-AI-Course", "max_issues_repo_head_hexsha": "dd4ed04b10b2231aac2f98b3b88274f7ab0cc339", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SelfTest2SS2020/selfTestProblem2.tex", "max_forks_repo_name": "baraaHassan/Game-AI-Course", "max_forks_repo_head_hexsha": "dd4ed04b10b2231aac2f98b3b88274f7ab0cc339", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.2586206897, "max_line_length": 202, "alphanum_fraction": 0.6607832322, "num_tokens": 670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.8856314753275017, "lm_q1q2_score": 0.8035442700648386}}
{"text": "\\subsection{Polynomials}\r\n\\noindent\r\nWe'll use our derivative formula and induction to show that\r\n\\begin{equation*}\r\n\t\\Laplace{t^n} = \\frac{n!}{s^{n+1}} \\text{, } n \\geq 0.\r\n\\end{equation*}\r\nAlthough the formula for $n = 0$ is clearly the same as $\\Laplace{1}$, we'll use $n = 1$ as a base case to get a little more insight into where the formula comes from.\\\\\r\n\\begin{equation*}\r\n\t\\Laplace{1} = \\Laplace{t'} = \\frac{1}{s}.\r\n\\end{equation*}\r\nUsing our derivative formula,\r\n\\begin{align*}\r\n\t\\frac{1}{s} &= s\\Laplace{t} - 0^{1} \\\\\r\n\t&\\implies \\Laplace{t} = \\frac{1}{s^2}.\r\n\\end{align*}\r\nAssuming the following is true,\r\n\\begin{equation*}\r\n\t\\Laplace{t^n} = \\frac{n!}{s^{n+1}} \\text{, } n \\geq 0.\r\n\\end{equation*}\r\nWe'll show that the $n+1$ case follows.\r\n\\begin{equation*}\r\n\t\\Laplace{t^n} = \\Laplace{\\left(\\frac{t^{n+1}}{n+1}\\right)'} = \\frac{n!}{s^{n+1}}.\r\n\\end{equation*}\r\nUsing our derivative formula and the linearity of the Laplace transform,\r\n\\begin{align*}\r\n\t\\frac{n!}{s^{n+1}} &= \\frac{s}{n+1}\\Laplace{t^{n+1}} - 0^{n+1} \\\\\r\n\t&\\implies \\Laplace{t^{n+1}} = \\frac{(n+1)!}{s^{n+2}},\r\n\\end{align*}\r\nwhich is the $n+1$ case, meaning we have proven the general formula as correct.", "meta": {"hexsha": "024af447def4c5e88ba071fb6f25b1d5260dc2f9", "size": 1179, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/laplaceTransforms/derivations/polynomial.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/laplaceTransforms/derivations/polynomial.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/laplaceTransforms/derivations/polynomial.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 40.6551724138, "max_line_length": 170, "alphanum_fraction": 0.6276505513, "num_tokens": 465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.8856314738181875, "lm_q1q2_score": 0.8035442642561413}}
{"text": "\n\\subsection{Defining circles}\n\n\\(x^2 + y^2 = r^2\\)\n\n\\subsection{Area of a circle}\n\n\\(A=\\pi r^2\\)\n\n\\subsection{Circumference of a circle}\n\n\\(C=2\\pi r\\)\n\n", "meta": {"hexsha": "e448b6293a56a85f16288009ff180d7666694f74", "size": 153, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/geometryAlgebraic/01-01-circle.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/geometryAlgebraic/01-01-circle.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/geometryAlgebraic/01-01-circle.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 10.9285714286, "max_line_length": 38, "alphanum_fraction": 0.6274509804, "num_tokens": 59, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9693242000616579, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.8035104390835941}}
{"text": "\\lab{Complex Numbers}{Complex Numbers}\n\\label{Lab:complex_intro}\n\n\\objective{Create visualizations of complex functions. Visually estimate their zeros and poles, and gain intuition about their behavior in the complex plane.}\n\n\\section*{Representations of Complex Numbers}\n\nA complex number $z = x+iy$ can be written in \\emph{polar coordinates} as $re^{i\\theta}$ where\n\\begin{itemize}\n\\item $r=\\sqrt{x^2+y^2}$ is the magnitude of $z$, and\n\\item $\\theta = \\arctan(y/x)$ is the angle between $z$ and 0, as in Figure \\ref{fig:polar_coords}.\n\\end{itemize}\nConversely, Euler's formula implies $re^{i\\theta} = r\\cos(\\theta) + ir\\sin(\\theta)$. Then if we set $re^{i\\theta}=x+iy$ and equate real and imaginary parts, we find $x=r\\cos(\\theta)$ and $y=r\\sin(\\theta)$.\n\n\\begin{figure}\n\\begin{tikzpicture}[dot/.style={circle,fill=black,minimum size=3pt,inner sep=0pt,\n            outer sep=-1pt}, >=stealth', thick, xscale=1.4]\n\n\\draw[-](-.5,0)--(3,0);\n\\draw[-](0,-.5)--(0,3);\n\n\\draw[-, dashed, gray, anchor=east](2.6,2.3)--(0,2.3);\n\\node[draw=none]()at(-.3,2.3){$iy$};\n\\draw[-, dashed, gray, anchor=north ](2.6,2.3)--(2.6,0);\n\\node[draw=none]()at(2.6,-.3){$x$};\n\n\\draw[gray](.75,0) arc (0:45:.7 and .7);\n\n\\draw[-](0,0)--(2.6,2.3);\n\\node[dot,draw](point)at(2.6,2.3){};\n\\node[draw=none]()at(.9,.35){$\\theta$};\n\n\\draw [decorate,decoration={brace,amplitude=10pt},rotate=-45, gray] (0,0) --(.2,3.45);\n\\node[draw=none]()at(.95,1.55){$r$};\n\n\n\\end{tikzpicture}\n\\caption{The complex number represented by the black dot equals both $x+iy$ and $re^{i\\theta}$, when $\\theta$ is written in radians.}\n\\label{fig:polar_coords}\n\\end{figure}\n\nNumPy makes it easy to work with complex numbers and convert between coordinate systems. \nThe function \\li{np.angle()} returns the angle of a complex number (between $-\\pi$ and $\\pi$) and the function \\li{np.absolute()} returns the magnitude.\nUse these to compute $\\theta$ and $r$, respectively.\nThese functions also operate elementwise on NumPy arrays.\n\nNote that in Python, \\li{1j} is used for the complex number $i=\\sqrt{-1}$.\nSee the code below for an example.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from matplotlib import pyplot as plt\n# Set z = 2 - 2i\n>>> z = 2 - 2*1j\n>>> theta = np.angle(z)\n>>> r = np.absolute(z)\n# np.angle() returns a value between -pi and pi.\n>>> print r, theta\n(2.8284271247461903, -0.78539816339744828)\n# Check that z=re^(i*theta)\n>>> np.allclose(z, r*np.exp(1j*theta))\nTrue\n\\end{lstlisting}\n\n\\section*{Visualizing complex functions}\nSuppose we wish to graph a function $f(z): \\mathbb{C} \\rightarrow \\mathbb{C}$. \nThe difficulty is that $\\mathbb{C}$ has 2 real dimensions, so the graph of $f$ should use 4 real dimensions.\n Since we already have ways to visualize 3 dimensions, we should choose one dimension to ignore. \n We will ignore the magnitude $r = |f(z)|$ of the output.\n\nTo visualize $f$, we will assign a color to each point $z \\in \\mathbb{C}$. \nThe color will correspond to the angle $\\theta$ of the output $f(z)$. \nAs an example, we have plotted the identity function $f(z)=z$ in Figure \\ref{fig:identity}.\nAs $\\theta$ goes from 0 to $2\\pi$, the colors cycle smoothly counterclockwise from red to green to purple and back to red.\n\nThis kind of plot uses rectangular coordinates in the domain and polar coordinates (or rather, just the $\\theta$-coordinate) in the codomain.\nNote that this kind of plot tells us nothing about $|f(z)|$.\n\nYou can create the plot in Figure \\ref{fig:identity} as follows.\nBegin by creating a grid of complex numbers.\nWe create the real and imaginary parts separately, and then use \\li{np.meshgrid()} to turn them into a single array of complex numbers.\n\\begin{lstlisting}\n>>> x = np.linspace(-1, 1, 401)\n>>> y = np.linspace(-1, 1, 401)\n>>> X, Y = np.meshgrid(x, y)\n>>> Z = X + 1j*Y\n\\end{lstlisting}\n\nNow we compute the angles of the points in \\li{Z} and plot them using \\li{plt.pcolormesh()}. \nWe use the colormap \\li{'hsv'}, which is red at both ends, so that $0$ and $2 \\pi$ will map to the same color.\n\n\\begin{lstlisting}\n>>> plt.pcolormesh(X, Y, np.angle(Z), cmap='hsv')\n>>> plt.show()\n\\end{lstlisting}\n\n\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{Identity.png}\n\\caption{Plot of $f: \\mathbb{C} \\rightarrow \\mathbb{C}$ defined by $f(z)=z$. \nThe color at each point $z$ represents the argument of $f(z)$.}\n\\label{fig:identity}\n\\end{figure}\n\n\n\n\n\n\\begin{problem}\nWrite the following function to plot any function from $\\mathbb{C}$ to $\\mathbb{C}$.\nPlot the angle only, as above, ignoring the magnitude.\n\\begin{lstlisting}\ndef plot_complex(f, xbounds, ybounds, res=401):\n    '''Plot the complex function f.\n    \n    INPUTS:\n    f        - A function handle. Should represent a function \n    \t\t\tfrom C to C.\n    xbounds  - A tuple (xmin, xmax) describing the bounds on the real part \n    \t\t\tof the domain.\n    ybounds  - A tuple (ymin, ymax) describing the bounds on the imaginary \n    \t\t\tpart of the domain.\n    res      - A scalar that determines the resolution of the plot. \n    \t\t\tDefaults to 401.\n    '''\n\\end{lstlisting}\nCheck your function on $f(z) = z$ (graphed in Figure \\ref{fig:identity}) and on the function $f(z) = \\sqrt{z^2+1}$, which is graphed in Figure \\ref{fig:check_plot}.\n\nHint: When you call \\li{plt.pcolormesh()}, specify the keyword arguments \\li{vmin} and \\li{vmax}. \nThese define which values should map to each end of the color scale. \nWe want $-\\pi$ to map to the low end of the color scale, and $\\pi$ to map to the high end.\nIf not specified, matplotlib will scale the colormap to fit your data exactly.\n\n\\label{prob:plot_complex}\n\\end{problem}\n\n\\begin{figure}[H]\n\\includegraphics[width=.6\\textwidth]{check_plot.png}\n\\caption{Plot of the angle of $\\sqrt{z^2+1}$ on the domain $\\{x+iy \\mid x \\in [-3,3] , \\; y \\in [-3,3]\\}$ created by \\li{plot_complex()}.}\n\\label{fig:check_plot}\n\\end{figure}\n\nThe choice to ignore the magnitude may seem arbitrary. \nWe can also write a complex plotting function to ignore the angle and only plot the magnitude.\nThis will give us some different intuition about the function, while losing some information that we would get from the angle plot.\n\n\\begin{problem}\nWrite a new complex plotting function called \\li{plot_complex_magnitude} which ignores the angle and plots only the magnitude.\nThis should resemble your answer to Problem \\ref{prob:plot_complex}, with small modifications.\nLeave \\li{vmin} and \\li{vmax} unspecified when plotting.\n\nCheck your function on $f(z) = \\sqrt{z^2+1}$. \nYour plot should look like the right subplot in Figure \\ref{fig:check_plot_2}.\nNote the difference between this plot and the one from the previous problem.\n\nHint: A wraparound colormap like \\li{'hsv'} doesn't work well here. \nUse any sequential colormap that makes it easy to distinguish between high and low values. See the matplotlib documentation for a list of colormaps.\n\n\\end{problem}\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{check_plot_magnitude.png}\n\\caption{Plots of $\\sqrt{z^2+1}$ on $\\{x+iy \\mid x \\in [-3,3] , \\; y \\in [-3,3]\\}$, visualizing the angle and the magnitude of the function.\nNotice how a discontinuity is clearly visible on the left, but disappears from the plot on the right.}\n\\label{fig:check_plot_2}\n\\end{figure}\n\n\n\\section*{Analyzing Complex Plots}\n\nThe angle plot is generally more useful than the magnitude plot for visualizing function behavior, zeros, and poles. \nThroughout the rest of the lab, use \\li{plot_complex} to plot only the angle, and ignore the magnitude.\n\n\\subsection*{Zeros}\n\nComplex plots can be surprisingly informative. \nFrom an angle plot we can estimate not only a function's zeros, but also their multiplicities.\n\n\\begin{problem}\\label{prob:zeros}\n\\leavevmode\n\\begin{enumerate}\n\\item Use \\li{plot_complex()} to plot the functions $z^2$, $z^3$, and $z^4$.\n\\item Plot $z^3 - iz^4 - 3z^6$ on the domain $\\{x+iy \\mid x \\in [-1,1] , \\; y \\in [-1,1]\\}$ (this plot is Figure \\ref{fig:zeros}). \nCompare it to your plot of $z^3$, especially near the origin.\nBased on these plots, what can you learn about the zeros of a function from its graph?\n\\end{enumerate}\n\\end{problem}\n\nIn Problem \\ref{prob:zeros} you should have noticed that in a plot $z^n$, the colors cycle $n$ times counterclockwise around 0. \n(Note: For the remainder of this lab we will define red $\\rightarrow$ yellow $\\rightarrow$ green $\\rightarrow$ blue $\\rightarrow$ red to be the ``forward\" direction, such that the colors are circling counterclockwise in Figure \\ref{fig:identity}.)\n\nThis is explained by looking at $z^n$ in polar coordinates:\n\\[\nz^n = (re^{i \\theta})^n = r^n e^{i(n\\theta)}.\n\\]\nMultiplying $\\theta$ by a number greater than $1$ compresses the graph along the ``$\\theta$-axis'' by a factor of $n$. \nIn other words, the output angle repeats itself $n$ times in one cycle of $\\theta$.\nCompare this to replacing $f(x)$ with $f(nx)$ when $f$ is a function from $\\mathbb{R}$ to $\\mathbb{R}$.\n\nFrom Problem \\ref{prob:zeros} you should also have noticed that the plot of $z^3 - iz^4 - 3z^6$ looks a lot like the plot of $z^3$ near the origin.\nThis is because when $z$ is very small, $z^4$ and $z^6$ are much smaller than $z^3$, and so the behavior of $z^3$ dominates the function.\n\nIn general, $f(z)$ has a \\emph{zero of order $n$ at $z_0$} if the Taylor series of $f(z)$ centered at $z_0$ can be written as \n\\[\nf(z) = \\sum_{k=n}^{\\infty} a_k(z-z_0)^k \\qquad \\text{with} \\; a_n \\neq 0.\n\\]\nIn other words, $f(z) = a_n(z-z_0)^n + a_{n+1}(z-z_0)^{n+1} + \\ldots$. \nIn a small neighborhood of $z_0$, the quantity $|z-z_0|^{n+k}$ is much smaller than $|z-z_0|^n$, and so the function behaves like $a_n(z-z_0)^n$.\nThis explains why we can estimate the order of a zero by counting the number of times the colors circle a point (see Figure \\ref{fig:zeros}).\n\n\\begin{figure}\n\\includegraphics[width=.6\\textwidth]{zeros.png}\n\\caption{Plot of $f(z)=z^3 - iz^4 - 3z^6$ on the domain $\\{x+iy \\mid x \\in [-1,1] , \\; y \\in [-1,1]\\}$.\nFrom this plot we see that $f(z)$ has a zero of order 3 at the origin, and 3 zeros of order 1 scattered around it. \nThis accounts for the 6 roots of $f(z)$ that are guaranteed to exist by the Fundamental Theorem of Algebra.}\n\\label{fig:zeros}\n\\end{figure}\n\n\n\\subsection*{Poles}\n\nThe plots created by \\li{plot_complex()} also contain information about the poles of the function plotted.\n\n\\begin{problem}\\label{prob:poles}\n\\leavevmode\n\\begin{enumerate}\n\\item Use \\li{plot_complex()} to plot the function $f(z) = 1/z$. \nCompare this to the plot of $f(z)=z$ in Figure \\ref{fig:identity}.\n\\item Plot $z^{-2}$, $z^{-3}$, and $z^2+iz^{-1}+z^{-3}$ on the domain $\\{x+iy \\mid x \\in [-1,1] , \\; y \\in [-1,1]\\}$. \nCompare the plots of the last two functions near the origin.\nBased on these plots, what can you learn about the poles of a function from its graph?\n\\end{enumerate}\n\\end{problem}\n\nIn Problem \\ref{prob:poles} you should have noticed that in the graph of $1/z^{n}$, the colors cycle $n$ times \\emph{clockwise} around 0.\nAgain this can be explained by looking at the polar representation:\n\\[\nz^{-n} = (re^{i \\theta})^{-n} = r^{-n} e^{i(-n\\theta)}.\n\\]\nThe minus-sign on the $\\theta$ reverses the direction of the colors, and the $n$ makes them cycle $n$ times.\n\nIn general, a function has a \\emph{pole of order n} at $z_0$ if its Laurent series on a punctured neighborhood of $z_0$ is\n\\[\nf(z) = \\sum_{k=-n}^\\infty a_k(z-z_0)^k  \\qquad \\text{with} \\; a_{-n} \\neq 0.\n\\]\nIn other words, $f(z) = a_{-n}(z-z_0)^{-n}+a_{-n+1}(z-z_0)^{-n+1} + \\ldots$.\nSince $|z-z_0|^{-n+k}$ is much smaller than $|z-z_0|^{-n}$ when $|z-z_0|$ is small, near $z_0$ the function behaves like $a_{-n}(z-z_0)^{-n}$.\nThis explains why we can estimate the order of a pole by counting the number of times the colors circle a point in the clockwise direction.\n\nFinally, a function has an \\emph{essential pole} at $z_0$ if its Laurent series in a punctured neighborhood of $z_0$ requires infinitely many terms with negative exponents.\nFor example, \n\\[\ne^{1/z} = \\sum_{k=0}^{\\infty}\\frac{1}{n! z^n} = 1+\\frac{1}{z}+\\frac{1}{2}\\frac{1}{z^2}+\\frac{1}{6}\\frac{1}{z^3}+\\ldots.\n\\]\nThe plot of $f(z) = e^{1/z}$ is in Figure \\ref{fig:essential_singularity}. \nThe colors cycle infinitely many times around an essential singularity.\n\n\\begin{figure}\n\\includegraphics[width=.6\\textwidth]{essential_pole.png}\n\\caption{Plot of $e^{1/z}$ on the domain $\\{x+iy \\mid x \\in [-1,1] , \\; y \\in [-1,1]\\}$.\nThe colors circle clockwise around the origin because it is a singularity, not a zero.\nBecause the singularity is essential, the colors repeat infinitely many times.}\n\\label{fig:essential_singularity}\n\\end{figure}\n\n\\subsection*{Using Plots to Estimate Poles and Zeros}\nTo summarize, poles and zeros can be estimated from a complex plot with the following rules.\n\\begin{itemize}\n\\item Colors circle counterclockwise around zeros.\n\\item Colors circle clockwise around poles.\n\\item The number of times the colors cycle equals the order of the zero or pole.\n\\end{itemize}\n\n\\begin{problem}\\label{prob:findpz}\nPlot these functions on the domains given.\nEstimate the number and order of their poles and zeros.\n\\begin{itemize}\n\\item $f(z) = e^z$ on $\\{ x+iy \\mid x \\in [-8,8], \\; y \\in [-8,8]\\}$\n%\\item $z^2-2z^7+2z^6-4z^5+2z^4-2z^3-5z^2+4z-4$ from $x \\in [-2.5,2.5]$ and $y \\in [-2.5,2.5]$ \n\\item $f(z) = \\tan(z)$ on $\\{x+iy \\mid x \\in [-8,8], \\; y \\in [-8,8]\\}$\n\\item $f(z) = \\frac{16z^4+32z^3+32z^2+16z+4}{16z^4-16z^3+5z^2}$ on $\\{x+iy \\mid x \\in [-1,1], \\; y \\in [-1,1]\\}$\n%\\item $f(z) = \\sin{\\frac{1}{z}}$ on ${x+iy \\mid x \\in [-.8,.8], y \\in [-.8,.8]\\}$\n\\end{itemize}\n\\end{problem}\n\nOne useful application of complex plots is to estimate the zeros of polynomials and their multiplicity.\n\n\\begin{problem}\\label{prob:find_roots}\nUse complex plots to determine the multiplicity of the zeros of each of the following polynomials.\nUse the Fundamental Theorem of Algebra to ensure that you have found them all.\n\\begin{enumerate}\n\\item $-4z^5+2z^4-2z^3-4z^2+4z-4$\n\\item $z^7 + 6z^6 - 131z^5 - 419z^4 + 4906z^3 - 131z^2 - 420z + 4900$\n\\end{enumerate}\n\\end{problem}\n\nPlotting functions is not a substitute for rigorous mathematics. \nOften, plots can be deceptive.\n\n\\begin{problem}\\label{prob:caution}\n\\leavevmode\n\\begin{enumerate}\n\\item This example shows that sometimes you have to ``zoom in'' to see all the information about a pole.\n\\begin{enumerate}\n\\item Plot the function $f(z) =\\sin( \\frac{1}{100z})$ on the domain $\\{x+iy \\mid x \\in [-1,1],\\; y \\in [-1,1]\\}$.\nWhat might you conclude about this function?\n\\item Now plot $f(z)$ on $\\{x+iy \\mid x \\in [-.01,.01], \\; y \\in [-.01,.01]\\}$.\nNow what do you conclude about the function?\n\\end{enumerate}\n\\item This example shows that from far away, two distinct zeros (or poles) can appear to be a single zero (or pole) of higher order.\n\\begin{enumerate}\n\\item Plot the function $f(z) = z+1000z^2$ on the domain $\\{x+iy \\mid x \\in [-1,1], \\; y \\in [-1,1]\\}$.\nWhat does this plot imply about the zeros of this function?\n\\item Calculate the true zeros of $f(z)$.\n\\item Plot $f(z)$ on a domain that allows you to see the true nature of its zeros.\n\\end{enumerate}\n\\end{enumerate}\n\\end{problem}\n\n\n\n\n\n%%% Long Comment: Old problems having to do with branch cuts and contour integration%%%\n\\begin{comment}\n\nFrom these plots you can see the poles and zeros. The zeros are the black dots and the poles are the white dots on the plots. the order of the pole or zero can be read from the number of times the full set of colors show up around the pole or zero. As you can see from Figure \\ref{fig:funcplot} $x^2-1$ has two zeros of order one at $1$ and $-1$. $x^4-\\frac{1}{x^4}$ has eight zeros of order one and a pole of order four. \nFor essential singularities the colors circle outward like in \\ref{fig:e}, the plot of $e^\\frac{1}{z}$.\n\n\\begin{figure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{function.png}\n\\end{subfigure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{function2.png}\n\\end{subfigure}\n\\caption{Colorplot of the  function $x^2 - 1$ and $x^4-\\frac{1}{x^4}$.}\n\\label{fig:funcplot}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{function1.png}\n\\caption{Color plot of the $e^\\frac{1}{z}$.}\n\\label{fig:e}\n\\end{figure}\n\n\\begin{problem}\n\nPlot the following functions and look at the plots. Write a function that prints out an estimate of the roots and/or poles and their order.\n\\begin{itemize}\n\\item Plot $e^z$ from $x \\in [-8,8]$ and $y \\in [-8,8]$, \\item $z^2-2z^7+2z^6-4z^5+2z^4-2z^3-5z^2+4z-4$ from $x \\in [-2.5,2.5]$ and $y \\in [-2.5,2.5]$ \n\\item Plot $\\frac{16z^4+32z^3+32z^2+16z+4}{16z^4-16z^3+5z^2}$ from $x \\in [-1,1]$ and $y \\in [-1,1]$,\n\\item Plot $\\sin{\\frac{1}{z}}$ from $x \\in [-.8,.8]$ and $y \\in [-.8,.8]$,\n\\end{itemize}\n\n\\end{problem}\n\n\\section*{Multi-Valued Functions}\n\nAnother important topic in Complex Analysis is the study of multiple valued functions.\nThese functions arise as we consider the inverses of functions that are not strictly one to one on the complex plane.\nA classic example is $\\sqrt{x}$, which may take two values for every nonzero point of the complex plane.\n\nIn the Real numbers we worked with functions like this by simply restricting their output on a certain domain.\nWe can do a similar thing in the Complex plane.\nLoosely speaking, such a restriction is called a branch.\nComputationally we restrict the output to a single portion of the actual possible values of the multifunction.\nWe call inverse functions that have multiple values like this ``multi-valued functions\" or ``multifunctions.\"\nNumPy automatically restricts the output of multi-valued functions. So to get other cuts you have to modify the function to get the cut you want, like multiplying the output of the $\\sqrt{x}$ by $-1$.\nFigure \\ref{fig:sqrt} shows the two cuts surfaces for $\\sqrt{z}$ in the complex plane.\n\n\\begin{figure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{possqrt.png}\n\\end{subfigure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{negsqrt.png}\n\\end{subfigure}\n\\caption{The positive and negative cut respectively of the function $\\sqrt{z}$.}\n\\label{fig:sqrt}\n\\end{figure}\n\nThese are some very basic examples.\nAnother simple example is $\\ln\\left(z\\right)$, which has a single value for the real part and infinitely many possible values for its imaginary part.\nThis is because for any complex $z\\neq 0$, we have $e^z=e^{z+2n\\pi}$ where $n$ is any integer.\n\n\\begin{problem}\nPlot three cuts of $\\ln\\left(z\\right)$ and$\\arctan{x}$ on $x \\in [-2,2]$ and $y \\in [-2,2]$\n\\end{problem}\n\nAll three of these functions can be made analytic at almost any point, except at their singularities, but that depends on how we cut the domain to give it a single value.\nWhen Integrating such functions, be careful about integrating across such cuts in the domain.\n\n\n\\begin{problem}\nWrite two functions, both accepting a natural number $n$.\nHave one function plot the Riemann surface for the real part $f(z)=\\sqrt[n]{z}$ and the other plot the imaginary part.\n\nHint: Convert $z$ in $f(z)=\\sqrt[n]{z}$ to polar form as $z=re^{\\theta + 2k\\pi}$\nIf you then plug this into $\\sqrt[n]{z}$ the function takes the form\n\\[f(z)=\\sqrt[n]{r} e^{i \\frac{\\theta + 2 \\pi k}{n}}\\]\nNotice that here $f(z)$ has distinct values for $k = 0, 1, \\dots, n-1$ (a total of $n$ different values). Each value of $k$ corresponds to a different branch, which you can plot as $n$ separate surfaces.\n\nIf you use just one surface to plot each branch you will get erroneous vertical lines from jump discontinuities. Split each branch into two surfaces to get rid of these lines. You can investigate where the discontinuities occur by first plotting it as just one surface. The discontinuities happen at the same place for all $n$;\n\\end{problem}\n\n\n\\section*{Contour Integrals in the Complex Plane}\n\nFrom multivariable calculus, you may recall that an integral may be taken along a path.\nThis is very similar to what can be done in the complex plane.\nConsider the function $f(z)$ on the complex plane.\nLet $z=x+iy$.\nLet $u$ and $v$ be the real and imaginary parts of $f$ respectively.\nWe integrate $f$ along some contour $C$ in the complex plane, beginning at $z=a$ and ending at $z=b$.\nThis integral may be written\n\\[\\int_c f(z)dz\\]\nParameterizing $z$, we have\n\\[\\int_a^b f\\left( c\\left(t\\right)\\right) c'\\left(t\\right) dt\\]\nExpanding into real and imaginary parts (where $c\\left(t\\right) = x\\left(t\\right) + i y\\left(t\\right)$), we have\n\\[\\int_a^b \\left(u \\left(c \\left(t\\right)\\right) x'\\left(t\\right)-v\\left(c \\left(t\\right)\\right) y'\\left(t\\right)\\right) dt + i \\int_a^b\\left(v \\left(c \\left(t\\right)\\right)x'\\left(t\\right)+u\\left(c \\left(t\\right)\\right) y'\\left(t\\right)\\right) dt\\]\nWe have now written this complex integral as the sum of two real valued integrals in $\\mathbb{R}$.\nNote that this implies that $\\int_C f(z) dz$ may depend on the contour we choose and not just on the endpoints $a$ and $b$.\n\n\\begin{problem}\nWrite a function which takes a complex function $f(z)$, a contour parameterization $c(t)$ of a contour $c$, and the integration bounds on $t$ and returns the integral of $f$ along the contour $c$.\nUse the numerical integration function \\li{sympy.mpmath.quad} and the numerical derivative function \\li{sympy.mpmath.diff} included in mpmath (which is, in turn, included as a submodule of sympy).\nThese functions already work for complex numbers.\nTo do something similar with the integration routines in SciPy, we would have to separate the function into real and imaginary parts, as is shown above.\n\nUsing the function you just defined, integrate the following functions along the following contours\n\\begin{itemize}\n\\item $\\bar{z}$ counterclockwise along the unit ball starting and ending at $1$\n\\item $\\bar{z}$ along a straight line from $0$ to $1+i$\n\\item $\\bar{z}$ along the real axis from $0$ to $1$, then along the line from $1$ to $1+i$\n\\item $\\bar{z}$ along the unit ball centered at $i$ from $0$ to $1+i$\n\\item $e^z$ counterclockwise along the unit ball starting and ending at $1$\n\\item $e^z$ along a straight line from $0$ to $1+i$\n\\item $e^z$ along the real axis from $0$ to $1$, then along the line from $1$ to $1+i$\n\\item $e^z$ along the unit ball centered at $i$ from $0$ to $1+i$\n\\end{itemize}\n\\end{problem}\n\nNotice that, for a holomorphic function on a simply connected domain, the integrals from one point to another are not path dependent for any contours that lie within the domain.\nAn immediate consequence of the theorem is that for a complex function $f$, holomorphic on a simply connected domain $D$, and a contour $C$ lying entirely within $D$ which begins and ends at some point $a\\in D$,\n\\[\\int_C f(z)dz=0\\]\n\nThe quadrature algorithms used in many of the integration algorithms work along a straight line between the integration bounds in the complex plane, so for holomorphic functions we should be able to use the integration function we wrote earlier.\nFor example, integrating $e^z$ from $-1-i$ to $1+i$ can be done numerically like this:\n\\begin{lstlisting}\nfrom sympy import mpmath as mp\nmp.quad(lambda z: mp.exp(z), (complex(-1, -1), complex(1, 1)))\n\\end{lstlisting}\n\n\\section*{The Cauchy Integral Formula}\n\nAnother major theorem in complex analysis is called Cauchy's Integral Formula (not to be confused with Cauchy's Integral Theorem).\nIt states that for a domain $D$ in the complex plane, containing some contour $C$ and the interior of $C$, for any $z_0$ in the interior of $C$,\n\\[f(z_0)=\\frac{1}{2\\pi i} \\int_C \\frac{f(z)}{z-z_0} dz\\]\n\nWith more work, this theorem can be used to show that any function $f$ holomorphic on some domain $D$ is also infinitely differentiable on that domain.\nIn fact, the $n$th derivative of $f$ is given by the formula\n\\[f^{(n)}(z_0) = \\frac{n!}{2\\pi i} \\int_C \\frac{f(z)}{(z-z_0)^{n+1}} dz\\]\nThis result is also important because it allows us to relate the value of $f$ on the inside of a contour to the value of $f$ on the contour itself.\nIn other words, the values of $f$ inside the contour depend only on the values of $f$ along the contour itself.\nA related theorem (the Morera theorem) states that if some function $f$ is continuous on a domain $D$ and for every contour beginning and ending at the same point, the formula $\\int_C f(z) dz = 0$ holds, then $f$ is holomorphic on $D$.\n\n\\begin{problem}\nUsing Cauchy's Integral Formula, write a python function which returns a callable function which evaluates a complex function $f$ along the interior of a contour $C$.\nIt should accept a callable function for the parameterization of $C$, a callable function for the values of $f$ along $C$, and the bounds on the parameter used.\nAssume in your function that $C$ begins and ends at the same point and that $f$ also begins and ends at the same value (so that $f$ is continuous along $C$)\nTry it out on simple functions like $e^x$ with complex values and compare what you get with what calling the functions normally gives you.\n\\end{problem}\n\nNotice that in Cauchy's Integral Formula, we are integrating along a contour that begins and ends at the same point.\nThe function is also holomorphic at every point except $z_0$. At $z_0$ the integrand is undefined and has a singularity.\nThis integral around a singularity has some useful properties.\nWe will discuss these properties later on.\n\n\\end{comment}\n%%%End of long comment%%%\n\n\n\n\\subsection*{Multi-Valued Functions}\nEvery complex number has two complex square roots, since if $w^2=z$, then also $(-w)^2=z$.\nIf $z$ is not zero, these roots are distinct.\n\nOver the nonnegative real numbers, it is possible to define a continuous square root function.\nHowever, it is not possible to define a continuous square root function over any open set of the complex numbers that contains 0.\nThis is intuitive after graphing $\\sqrt{z}$ on the complex plane.\n\n\\begin{problem}\n\\begin{enumerate}\n\\item Use \\li{plot_complex} to graph $f(z) = \\sqrt{z}$.\nUse \\li{np.sqrt()} to take the square root.\n\\item Now plot $f(z) = -\\sqrt{z}$ to see the ``other square root'' of $z$. \nDescribe why these two plots look the way they do.\n\\end{enumerate}\n\\end{problem}\n\nJust as raising $z$ to a positive integer ``compresses the $\\theta$-axis'', making the color wheel repeat itself $n$ times around 0, raising $z$ to a negative power \\emph{stretches} the $\\theta$-axis, so that only one $n^{th}$ of the color wheel appears around 0.\nThe colors at the ends of this $n^{th}$-slice are not the same, but they appear next to each other in the plot of $z^{-n}$.\nThis discontinuity will appear in every neighborhood of the origin. \n\n\nIf your domain does not contain the origin, it is possible to define a continuous root function by picking one of the roots.\n\n\n\\section*{Appendix}\nIt is possible to visualize the argument and the modulus of the output of a complex function $f(z)$. \nOne way to do so is to assign the modulus to a \\emph{lightness} of color.\nFor example, suppose we have a complex number with argument 0, so it will map to red in the color plots described above.\nIf its modulus is very small, then we can map it to a blackish red, and if its modulus is large, we can map it to a whitish red.\nWith this extra rule, our complex plots will still be very much the same, except that zeros will look like black dots and poles will look like white dots (see Figure \\ref{fig:example} for an example).\n\nThe code below implements the map we just described.\nBe warned that this implementation does not scale well.\nFor example, if you try to plot a complex function whose outputs are all very small in modulus, the entire plot will appear black.\n\n\n\\begin{lstlisting}\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom colorsys import hls_to_rgb\n\ndef colorize(z):\n    ''' \n    Map a complex number to a color (or hue) and lightness.\n    \n    INPUT:\n    z - an array of complex numbers in rectangular coordinates\n    \n    OUTPUT:\n    If z is an n x m array, return an n x m x 3 array whose third axis encodes \n    (hue, lightness, saturation) tuples for each entry in z. This new array can \n    be plotted by plt.imshow().\n    '''\n    \n    zy=np.flipud(z)\n    r = np.abs(zy)\n    arg = np.angle(zy)\n\n    # Define hue (h), lightness (l), and saturation (s)\n    # Saturation is constant in our visualizations\n    h = (arg + np.pi)  / (2 * np.pi) + 0.5\n    l = 1.0 - 1.0/(1.0 + r**0.3)\n    s = 0.8\n\n    # Convert the HLS values to RGB values.\n    # This operation returns a tuple of shape (3,n,m).\n    c = np.vectorize(hls_to_rgb) (h,l,s) \n    \n    # Convert c to an array and change the shape to (n,m,3)\n    c = np.array(c)  \n    c = c.swapaxes(0,2)\n    c = c.swapaxes(0,1)\n    return c\n\\end{lstlisting}\n\nThe following code uses the \\li{colorize()} function to plot  $\\frac{z^2 - 1}{z}$. The output is Figure \\ref{fig:example}.\n\n\\begin{lstlisting}\n>>> f = lambda z :  (z**2-1)/z\n>>> x = np.linspace(-.5, 1.5, 401)\n>>> y = np.linspace(-1, 1, 401)\n>>> X,Y = np.meshgrid(x,y)\n>>> Z=f(X+Y*1j)\n>>> Zc=colorize(Z)\n>>> plt.imshow(Zc, extent=(-.5, 1.5, -1, 1))\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{example.png}\n\\caption{Plot of the function $\\frac{z^2 - 1}{z}$ created with \\li{colorize()}.\nNotice that the zero at 1 is a black dot and the pole at 0 is a white dot.}\n\\label{fig:example}\n\\end{figure}\n\n%The only thing I can think of is to specify more clearly is to set vmin and vmax to -pi to pi.  Otherwise I thought it was all fine!", "meta": {"hexsha": "f3a341cd9590134b173c2be8c067efe6bac2b6d3", "size": 29353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1B/Complex1-Plots/Complex1.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol1B/Complex1-Plots/Complex1.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol1B/Complex1-Plots/Complex1.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 50.5215146299, "max_line_length": 422, "alphanum_fraction": 0.7109665111, "num_tokens": 8816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218864, "lm_q2_score": 0.9173026539338222, "lm_q1q2_score": 0.8033617227976387}}
{"text": "\\noindent\r\n\\subsubsection{Sine}\r\nLet $a$ be a constant.\\\\\r\nBy definitions of a Laplace transform and an improper integral,\r\n\\begin{align*}\r\n\t\\Laplace{\\sin{(at)}} &= \\lim\\limits_{n\\to\\infty}{\\int_{0}^{n}{\\sin{(at)}e^{-st}\\mathrm{d}t}} \\\\\r\n\t&= \\frac{-1}{s^2 + a^2}\\lim\\limits_{n\\to\\infty}{\\left[e^{-st}\\left(s\\sin{(at)} + a\\cos{(at)}\\right)\\right]_{0}^{n}} \\\\\r\n\t&= \\frac{-1}{s^2 + a^2}\\left(\\lim\\limits_{n\\to\\infty}\\left(e^{-sn}\\left(s\\sin{(an)} + a\\cos{(an)}\\right)\\right) - \\left(e^{-s\\cdot 0}\\left(s\\sin{(a\\cdot 0)} + a\\cos{(a\\cdot 0)}\\right)\\right)\\right).\r\n\\end{align*}\r\nBoth $\\sin$ and $\\cos$ have maximum values of 1, so we can say that the left part of them expression has a maximum value at most $s + a$.\r\nFor positive $s$, the exponential dominates and the expression goes to 0 in the limit.\r\n\\begin{align*}\r\n\t&= \\frac{-1}{s^2 + a^2}\\left(0 - a\\right) \\text{, } s > 0 \\\\\r\n\t&= \\frac{a}{s^2 + a^2} \\text{, } s > 0.\r\n\\end{align*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\Laplace{\\sin{(at)}} = \\frac{a}{s^2 + a^2} \\text{, } s > 0.\r\n\\end{equation*}", "meta": {"hexsha": "070090668c3a45251cddac5edde11449fbd5a080", "size": 1037, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/laplaceTransforms/derivations/sin.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/laplaceTransforms/derivations/sin.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/laplaceTransforms/derivations/sin.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 54.5789473684, "max_line_length": 200, "alphanum_fraction": 0.5959498554, "num_tokens": 424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8633916152464016, "lm_q1q2_score": 0.8033498594603561}}
{"text": "\\lab{Applications}{Least-squares fitting I}{Least-squares fitting I}\n\\label{LeastSquaresCircle}\n\n\\objective{This section will introduce Least Squares and teach a more advanced application of Least Squares: fitting data to an circle.}\n\\section*{Least Squares}\n\nIt is well known that the displacement of a spring is proportional to the force acting upon it, that is, $F = k x$.  The proportionality constant $k$ is called Hooke's spring constant.  Consider a laboratory experiment where different loads are placed on a spring and the displacement is measured and recorded in the table below:\n\\vspace{5mm}\\\\\n\\begin{center}\n\\begin{tabular}{|c|c|}\n\t\\hline\nx & F \\\\\n(cm) & (dyne)\\\\\n\\hline\n1.04  & 3.11 \\\\\n2.03  &  6.01\\\\\n2.95  &  9.07\\\\\n3.92  &  11.99\\\\\n5.06  &  15.02\\\\\n6.00  &  17.91\\\\\n7.07  &  21.12\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\vspace{5mm}\nTo find the spring constant $k$, we simply need to solve the following linear system\n\\[\n\\begin{pmatrix}\n1.04\\\\\n2.03\\\\\n2.95\\\\\n3.92\\\\\n5.06\\\\\n6.00\\\\\n7.07\\\\\n\\end{pmatrix}\n\\begin{pmatrix}k\\end{pmatrix} = \n\\begin{pmatrix}\n3.11 \\\\\n6.01\\\\\n9.07\\\\\n11.99\\\\\n15.02\\\\\n17.91\\\\\n21.12\\\\\n\\end{pmatrix}.\n\\]\nHowever, there is no solution to this system because it is overdetermined.  Instead, we seek the ``best'' $k$ that fits the data.  Least squares (which we mentioned in a previous exercise) allows us to find that ``best'' solution. We can find the least squares solution by computing the following in Python:\n\\begin{lstlisting}[style=python]\n: A = sp.vstack([1.04,2.03,2.95,3.92,5.06,6.00,7.07])\n: b = sp.vstack([3.11,6.01,9.07,11.99,15.02,17.91,21.12])\n: k = sp.dot(sp.dot(la.inv(sp.dot(A.T,A)),A.T),b);k\n: # Using the built in least squares function this is just: k=la.lstsq(A,b);k\narray([[ 2.99568294]])\n\\end{lstlisting}\nHence, we find the spring constant to be $k = 2.9957$.  We plot the data against the best fit as follows:\n\\begin{figure}[h!]\n\\label{fig1}\n\\begin{center}\n\\includegraphics[width=\\textwidth]{line_lstsq}\n\\caption{The graph of the spring data together with its linear fit}\n\\label{Fig:SpringFit}\n\\end{center}\n\\end{figure}\n\n\\begin{lstlisting}[style=python]\n: x0 = sp.linspace(0,8,100)\n: y0 = k[0]*x0\n: from matplotlib import pyplot as plt\n: plt.plot(A,b,'*',x0,y0)\n: plt.show()\n\\end{lstlisting}\nSee Figure \\ref{Fig:SpringFit} to see how well the line fits the data.\n\n\n\\section*{General Line Fitting}\n\nSuppose that we wish to fit a general line, that is $y=m x+b$, to the data set $\\{(x_k,y_k)\\}^n_{k=1}$.  Assume that the line does not cross through the origin, as in the previous example.  Then we seek both a slope and a $y$-intercept.  In this case, we set up the following linear system $A x = b$, or more precisely\n\\[\n\\begin{pmatrix}\nx_1 & 1\\\\\nx_2 & 1\\\\\nx_3 & 1\\\\\n\\vdots & \\vdots\\\\\nx_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\nm\\\\\nb\n\\end{pmatrix}=\n\\begin{pmatrix}\ny_1\\\\\ny_2\\\\\ny_3\\\\\n\\vdots\\\\\ny_n\n\\end{pmatrix}.\n\\]\nNote that $A$ has rank $2$ as long as not all of the $x_k$ values are the same.  Hence, the least squares solution will fit the best line for this data.\n\n\n\\begin{problem}\nLoad the \\texttt{linepts} array from \\texttt{data.npz}.\nThis consists of two columns corresponding to the $x$ and $y$ values of a given data set.  Use least squares to find the slope and $y$-intercept that best fits the data.  Then plot the data points and the line on the same graph.  Finish off the problem with a discussion of what you've learned.\n\\end{problem}\n\n\\section*{Fitting data to a circle}\n\nRecall that the equation of a circle, with radius $r$ centered at $(c_1,c_2)$, is given by\n\\begin{equation}\n\\label{circle}\n(x-c_1)^2 + (y-c_2)^2 = r^2.\n\\end{equation}\nSuppose we are given a set of data points closely forming a circle $\\{(x_i,y_i)\\}^n_{i=1}$.  The ``best'' fit is found via least squares by expanding \\eqref{circle} to get\n\\[\n2 c_1 x + 2 c_2 y + c_3 = x^2 + y^2,\n\\]\nwhere $c_3 = r^2 - c_1^2 - c_2^2$.  Then we can write the linear system $A x = b$ as\n\\[\n\\begin{pmatrix}\n2 x_1 & 2 y_1 & 1\\\\\n2 x_2 & 2 y_2 & 1\\\\\n\\vdots & \\vdots & \\vdots \\\\\n2 x_n & 2 y_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\nc_1\\\\\nc_2\\\\\nc_3\n\\end{pmatrix}=\n\\begin{pmatrix}\nx_1^2 + y_1^2\\\\\nx_2^2 + y_2^2\\\\\n\\vdots\\\\\nx_n^2 + y_n^2\n\\end{pmatrix},\n\\]\nwhere the matrix $A$ and the vector $b$ are obtained by the given data and the unknown $x$ contains the information about the center and radius of the circle and is obtained by finding the least squares solution.\n\n\\section*{Example}\n\nIn this section, we fit the following points to a circle:\n\\begin{align*}\n&(134,76),(104,146),(34,176),(-36,146),\\\\\n&(-66,76),(-36,5),(34,-24),(104,5),(134,76)\n\\end{align*}\n\nWe enter them into Python as a $9\\times 2$ array:\n\\begin{lstlisting}[style=python]\n: P = sp.array([[134,76],[ 104,146],[ 34,176],[ -36,146],[ -66,76],[ -36,5],[ 34,-24],[ 104,5],[ 134,76]])\n\\end{lstlisting}\nThen we can separate the $x$ and $y$ coordinates by the commands \\li{P[:,0]} and \\li{P[:,1]}, respectively.  Hence, we compute $A$ and $b$ by entering the following:\n\\begin{lstlisting}[style=python]\n: A = sp.column_stack((2*P,sp.ones((9,1),dtype=sp.int_)))\n: b = P[:,0]**2 + P[:,1]**2\n\\end{lstlisting}\nHence, we get the least squares solution\n\\begin{lstlisting}[style=python]\n: x = sp.dot(sp.dot(la.inv(sp.dot(A.T,A)),A.T),b)\n\\end{lstlisting}\nThen we find $c_1$, $c_2$, and $r$ by:\n\\begin{lstlisting}[style=python]\n: c1 = x[0]\n: c2 = x[1]\n: c3 = x[2]\n: r = sp.sqrt(c1**2 + c2**2 + c3)\n\\end{lstlisting}\nWe plot this by executing\n\\begin{lstlisting}[style=python]\n: theta = sp.linspace(0,2*sp.pi,200)\n: plt.plot(r*sp.cos(theta)+c1,r*sp.sin(theta)+c2,'-',P[:,0],P[:,1],'*')\n: plt.show()\n\\end{lstlisting}\n\n\n\\begin{problem}\nLoad the \\texttt{circlepts} array from \\texttt{data.npz}.\nThis consists of two columns corresponding to the $x$ and $y$ values of a given data set.  Use least squares to find the center and radius of the circle that best fits the data.  Then plot the data points and the circle on the same graph.  Finish off the problem with a discussion of what you've learned.\n\\end{problem}\n\n\\begin{problem}\nThe general equation for an ellipse is:\n\\[\nA(x-x_0)^2 + B(x-x_0)(y-y_0) + C(y-y_0)^2 = 1\n\\]\n\nWrite a program that uses least squares to fit data to an ellipse. One option to finding the center point $(x_0,y_0)$ is to use the mean function. Test the program on \\texttt{circlepts}. Also test it against sp.dot(circlepts, sp.array([[2,0],[0,1]]) ) . Plot the result. How well does your function work?\n\\end{problem}\n", "meta": {"hexsha": "ab69d6a739fb30e1911e34321dec5f6e3950be9e", "size": 6395, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/LeastSquares/LeastSquares.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Applications/LeastSquares/LeastSquares.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Applications/LeastSquares/LeastSquares.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.835978836, "max_line_length": 329, "alphanum_fraction": 0.6863174355, "num_tokens": 2224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8633916152464016, "lm_q1q2_score": 0.8033498594603561}}
{"text": "\\section{Indicator Variables}\n\nIndicator variables are useful devices that simplify probability calculations involving binary outcomes, namely wether the outcome lies in a certain region of event space or not. Specifically, they allow one to translate set expressions into algebraic expressions. \n\nLet $A\\subseteq S$ be a subset of event space $S$ (ex. $A\\equiv$ \"it rains tomorrow\"). Then the indicator variable $I_A$: \n\n\\begin{equation}\nI_A = \\left\\{\\begin{array}{l} 1 \\mathrm{\\ if\\ outcome\\ in\\ A}\\\\0 \\mathrm{\\ if\\ outcome\\ in\\ A^c} \\end{array}\\right.\n\\end{equation}\n\nWhich means that:\n\\begin{equation}\n\\mathbb{E}(I_A) = 1\\times p(A) + 0\\times p(A^c)= p(A)\n\\end{equation}\n\nTo indicator variables for different events $A,B,C...$ can also be combined:\n\\begin{equation}\nI_{A\\cap B\\cap C\\cap ...} = I_A I_B I_C ...\n\\end{equation}\n\nAnd indicator variables for the complement can be constructed trivially:\n\\begin{equation}\nI_{A^c} = 1 - I_A\n\\end{equation}\n\nWhenever accounting for complicated combinations of events becomes overwhelming, indicator variables are often a good approach.\n\n\\subsection{Example: The Party Problem}\n\nThe party problem is a typical interview question, so I will include the two easier problems that do not make use of indicator variables. (This version of my notes also still has bitterness included.)\n\nThere are $n$ drunk kids at a party that is presumably getting shut down by the fun police in Cambridge, MA. They (meaning the kids, presumably) grab their coats at random, and the problem is built around thinking about how many people wind up with the correct coat.\n\n\\subsubsection{Lame Interview Question 1: Every one finds their coat}\nThe common version of this problem asks \"what is the probability that all of the kids wind up with the right coat\". This is much easier than the general case. Imagine the list of party guests as a sequence $(1,2,3,4,...,n-1,n)$ and the coats they grab as a random permutation of that sequence, such as $\\alpha = (6,1,40,21,9,...)_n$. There are $n!$ such permutations, and they are all equally likely. The probability of all guests getting the correct coat is the probability that the permutation happens to be the single correct one, i.e. $p(\\alpha = (1,2,3,4,...,n-1,n)_n)$, which is the probality of one particular permutation, i.e. $p(\\alpha = (1,2,3,4,...,n-1,n)_n) = \\frac{1}{n!}$.\n\n\\subsubsection{Lame Interview Question 2: At least r people find their coat}\nThis is still pretty easy, because the permutations that are correct are easily counted. If at least $r$ coats are correctly assigned, then there are $\\left(\\begin{array}{l}n\\\\r\\end{array}\\right)$ ways of choosing wich of the $r$ people wind up with the right coat. Then, while the location of $r$ indices in the sequence is fixed, $n-r$ indices can be assigned arbitrarily.\n\nThe number of permutations where at least $r$ are assigned correctly are then:\n\n\\begin{equation}\n\\left(\n\\begin{array}{l}\nn\\\\\nr\n\\end{array}\n\\right)(n-r)!\n\\end{equation}\n\nAnd the probability of at least $r$ people finding their coat is the number of permutations multiplied with the probability of an individual permutation (that is, $\\frac{1}{n!}$):\n\n\\begin{equation}\np(\\mathrm{\\#\\ correct} \\geq r)=\\left(\n\\begin{array}{l}\nn\\\\\nr\n\\end{array}\n\\right)\\frac{(n-r)!}{n!} = \\frac{1}{r!}\n\\end{equation}\n\nWhere $r\\leq n$.\n\n\\subsubsection{Not lame: Exactly r people find their coat}\nSo, then, what's the probability that exactly nobody finds their coat? What's the probability that 2 people find their coat but nobody else does? What's the probability that $r$ out of $n$ people find their coat? After thinking quickly on your feet for two seconds, you realize that the answer is obviously:\n\n\\begin{equation}\np(\\mathrm{\\#\\ correct} = r) = \\frac{1}{r!}\\sum_{s=0}^{n-r} \\frac{(-1)^s}{s!}\n\\end{equation}\n\nThe interviewer grunts ambiguously. They never call you back. You never find out why. You can't sleep. You can't eat. You become an anarchist and you declare war on the system.\n\nThe first two versions here are what I've come across in interview prep-type materials. I find them a bit annoying, because they represent particular cases that are much simpler than the general case. Applicants in the habit of studying stupid interview questions are rewarded because those answers are easily memorized (false positive). Applicants who intuit the complexity of the general problem, and who don't know the answer beforehand, might become overwhelmed during an interview and fail (false-ish negative).\n\n/ rant\n\nMy approach here follows the extraordinary lecture notes https://mast.queensu.ca/~stat455/ by Glen Takahara at the University of Queensland. The difficulty of the problem is that events of a coat being picked up are interrelated: whether one person picks up their correct coat alters the probability of another person also picking up their correct coat. The beauty of this solution is that, rather than messing about with conditional probabilities, it looks at subsets of the event space, and then uses indicator variables to translate set expressions into algebraic expressions.\n\nIt uses the properties:\n\n\\begin{equation}\nI_A = \\left\\{\\begin{array}{l} 1 \\mathrm{\\ if\\ outcome\\ in\\ A}\\\\0 \\mathrm{\\ if\\ outcome\\ in\\ A^c} \\end{array}\\right.\n\\end{equation}\n\nWhich means that:\n\\begin{equation}\n\\mathbb{E}(I_A) = 1\\times p(A) + 0\\times p(A^c)= p(A)\n\\end{equation}\n\nTo indicator variables for different events can also be combined:\n\\begin{equation}\nI_{A\\cap B\\cap C\\cap ...} = I_A I_B I_C ...\n\\end{equation}\n\nAnd indicator variables for the complement can be constructed trivially:\n\\begin{equation}\nI_{A^c} = 1 - I_A\n\\end{equation}\n\nLet $A_i$ be the region of state space in which guest $i$ grabbed the right coat. Let's say a *particular* subset $\\{i\\}_r$ of $r$ guests grabs their correct coats (for example, $\\{i\\}_r = \\{5,9,11,24,...\\}_r)$, and that the set of remaining $n-r$ guests $\\{j\\}_{n-r}= \\{1,2,3,...\\}_n\\setminus\\{i\\}_r$ grab the wrong coat. The area of state space that corresponds to this outcome is:\n\n\\begin{equation}\nA_{\\{i\\}_r,\\{j\\}_{n-r}}=\\bigcap_{i\\in\\{i\\}_r}A_i\\bigcap_{j\\in\\{j\\}_{n-r}}A_j^c\n\\end{equation}\n\nThe event that the outcome lies within that region of configuration space can be described with an indicator function:\n\n\\begin{equation}\nI_{A_{\\{i\\}_r,\\{j\\}_{n-r}}} = \\prod_{\\{i\\}_r}I_{A_i}\\prod_{\\{j\\}_{n-r}}(1-I_{A_j})\n\\end{equation}\n\nAnd the probability of those *particular* $r$ people finding their coat is it's expectation value, $p(A_{\\{i\\}_r,\\{j\\}_{n-r}}) = \\mathbb{E}(I_{A_{\\{i\\}_r,\\{j\\}_{n-r}}})$. Good stuff.\n\nThe expression above will consist of a bunch of products of indicator variables that describe whether a particular guest wound up with the correct coat. We know that the product of indicator variables corresponds to an indicator variable for the *intersection* of the corresponding subsets of the state space. Explicitly, if it is a product of $s$ indicator variables for some particular set of coats coat $\\{k\\}_s$:\n\n\\begin{equation}\n\\prod_{k} I_{A_k} = I_{\\bigcap_{k}A_k}\n\\end{equation}\n\nAnd $\\mathbb{E}(I_{\\bigcap_{k} A_k}) = p(\\bigcap_{k} A_k)$ is the probability of a particular $s$ coats being picked up correctly, which is $(n-s)!/n!$. (There is no binomial factor, because it's one *specific* set of $s$ coats).\n\nProducts of the sort $\\prod^n (1-x_i)$ can be expanded:\n\n\\begin{equation}\n\\prod^n (1-x_i) = \\sum_{s=0}^n (-1)^s \\sum_{1\\leq i_1,...,i_s\\leq n} x_{i_1}x_{i_2}...x_{i_s}\n\\end{equation}\n\nThe sum $\\sum_{1\\leq i_1,...,i_s\\leq n}$ is over all possible sets of up to $s$ indices that can be drawn from $\\{1,2,3,...,n\\}$. A simple example with $n=3$:\n\n\\begin{equation}\n(1-x_1)(1-x_2)(1-x_3) = \\underbrace{1}_{s=0} - \\underbrace{(x_1 + x_2 + x_3)}_{s=1} + \\underbrace{(x_1x_2 + x_2x_3 + x_1x_3)}_{s=2} - \\underbrace{(x_1x_2x_3)}_{s=3}\n\\end{equation}\n\nThe number of terms of order $s$ is the amount of ways that $s$ indices can be sampled from $n$ indices, $\\left(\\begin{array}{l}n\\\\s\\end{array}\\right)$.\n\nReturning to the original problem, then:\n\n\\begin{equation}\n\\begin{array}{ll}\nI_{A_{\\{i\\}_r,\\{j\\}_{n-r}}} &= \\prod_{\\{i\\}_r}I_{A_i}\\prod_{\\{j\\}_{n-r}}(1-I_{A_j})\\\\\n&=\\sum_{s=0}^{n-r} (-1)^s \\underbrace{\\sum_{n-r\\leq j_1,...,j_s\\leq n}}_{\\mathrm{sum\\ of\\ }\\left(\\begin{array}{l}n-r\\\\s\\end{array}\\right)\\mathrm{\\ terms\\ \\ }} \\underbrace{\\prod_{\\{i\\}_r} I_{A_i}\\prod_{\\{j\\}_s}I_{A_j}}_{\\mathrm{product\\ of\\ r+s\\ terms\\ \\ }}\n\\end{array}\n\\end{equation}\n\nBy linearity of expected value, and using the relationship of the expected value of indicator variables to their probabilities:\n\n\\begin{equation}\n\\begin{array}{rl}\n\\mathbb{E}(I_{A_{\\{i\\}_r,\\{j\\}_{n-r}}}) &= \\sum_{s=0}^{n-r} (-1)^s \\underbrace{\\sum_{n-r\\leq j_1,...,j_s\\leq n}}_{\\mathrm{sum\\ of\\ }\\left(\\begin{array}{l}n-r\\\\s\\end{array}\\right)\\mathrm{\\ terms\\ \\ }} p\\left(\\underbrace{I_{\\bigcap_{\\{i\\}_r}A_i\\bigcap_{\\{j\\}_s}A_j}}_{\\mathrm{r+s\\ coats\\ picked\\ up\\ correctly}}\\right)\\\\\n&=\\sum_{s=0}^{n-r} (-1)^s \\left(\\begin{array}{c}n-r\\\\s\\end{array}\\right)\\frac{(n-r-s)!}{n!}\n\\end{array}\n\\end{equation}\n\nNow, this is already a pretty neat expression for the probability of a *particular* $r$ coats being picked up correctly (i.e. Joe, Mary, and \"Hans\" picked up the right coat). We don't really care which of the $r$ guests got lucky, though, so since there are $\\left(\\begin{array}{c}n\\\\r\\end{array}\\right)$ ways of $r$ coats having been picked out correctly, you sum over all of them:\n\n\\begin{equation}\n\\begin{array}{ll}\np(\\mathrm{\\#\\ correct} = r) &= \\left(\\begin{array}{c}n\\\\r\\end{array}\\right) \\sum_{s=0}^{n-r} (-1)^s \\left(\\begin{array}{c}n-r\\\\s\\end{array}\\right)\\frac{(n-r-s)!}{n!}\\\\\n&= \\sum_{s=0}^{n-r} (-1)^s \\frac{n!}{r!(n-r)!}\\frac{(n-r)!}{s!(n-r-s)!}\\frac{(n-r-s)!}{n!}\\\\\n&= \\frac{1}{r!}\\sum_{s=0}^{n-r} \\frac{(-1)^s}{s!}\n\\end{array}\n\\end{equation}\n\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=0.7\\textwidth]{partyproblem.png}\n    \\caption{Simulated and analytically calculated probabilities that exactly $r$ people at a $n=100$ people party randomly pick up their coat.}\n    \\label{fig:proba_partyproblem}\n\\end{figure}\n", "meta": {"hexsha": "d9a503dc6c8258837586cc0e13255fbcac61f114", "size": 10051, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/proba_indicatorvariables.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/proba_indicatorvariables.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/proba_indicatorvariables.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.7777777778, "max_line_length": 686, "alphanum_fraction": 0.7124664213, "num_tokens": 3128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582612793112, "lm_q2_score": 0.863391611731321, "lm_q1q2_score": 0.8033498578546671}}
{"text": "\\chapter{Linear Transformations}\nLet's pause the discussion of tensor product spaces and dual spaces, and consider again the underlying vector space $V$ with a basis $\\{\\vec{e}_\\mu\\}$.\nThe only thing to recall about the dual space is that $V^*$ has a basis $\\{\\vec{e}^\\nu\\}$ chosen such that $\\langle \\vec{e}^\\nu, \\vec{e}_\\mu \\rangle = \\delta^\\nu_\\mu$.\nAs with any vector space, in order for $\\{\\vec{e}_\\mu\\}$ to be a basis, it must\n\\begin{enumerate}\n    \\item span $V$, and\n    \\item be a linearly independent set.\n\\end{enumerate}\nThere are infinitely many such basis which meet the requirements, so our choice of basis for $V$ is rather arbitrary\\footnote{As an example, take any basis of $V$, and scale one component by a scalar factor from $\\mathbb{F}$ to create a new, valid basis.}.\nAs long as $\\{\\vec{e}_\\mu\\}$ is a basis for $V$, any vector $\\vec{v} \\in V$ can be written as a linear combination of $\\{\\vec{e}_\\mu\\}$, so\n\\[ \\vec{v} = A^\\mu \\vec{e}_\\mu,\\;A \\in \\mathbb{F}. \\]\nBut suppose that we have another basis for $V$, called $\\{\\unit{e}_\\nu\\}$.\nWe can also write $\\vec{v}$ as a linear combination of these basis vectors,\nso\n\\[ \\vec{v} = B^\\nu \\unit{e}_\\nu,\\;B \\in \\mathbb{F}. \\]\nThe vector itself hasn't changed when we represent it in different ways, so we know that these two linear expressions must be equal to one another.\nIf we want, we can change from one basis to the other, and we do so via \\emph{linear transformations}.\n\n\\subsection{Change of Basis}\nLet's begin by writing one set of basis vectors in terms of the other.\nOur goal will be to write each member of $\\{\\unit{e}_\\nu\\}$ in terms of linear combinations of $\\{\\vec{e}_\\mu\\}$.\nTo do so, we say that each element of $\\{\\unit{e}_\\nu\\}$ can be represented by the sum of scalar products of each element of $\\{\\vec{e}_\\mu\\}$, so\n\\begin{align*}\n    \\unit{e}_0 &= \\tensor{\\Lambda}{_0^0}\\vec{e}_0 + \\tensor{\\Lambda}{_0^1}\\vec{e}_1 + \\cdots \\\\\n    \\unit{e}_1 &= \\tensor{\\Lambda}{_1^0}\\vec{e}_0 + \\tensor{\\Lambda}{_1^1}\\vec{e}_1 + \\cdots \\\\\n    &\\vdots \\\\\n    \\unit{e}_\\nu &= \\tensor{\\Lambda}{_\\nu^\\mu}\\vec{e}_\\mu.\n\\end{align*}\nHere, the lower index $\\nu$ on $\\Lambda$ tells us which of $\\{\\unit{e}_\\nu\\}$ we are writing, and the upper index $\\mu$ tells us which of our original basis vectors $\\vec{e}_\\mu$ we are scaling.\nIf you treat this as a linear algebra problem, it becomes apparent that $\\tensor{\\Lambda}{_\\nu^\\mu}$ is a matrix representing the linear transformation between two vectors.\nFor the sake of brevity, if we were to hold that $V$ is a four dimensional vector space, then we could write the entire transformation as\n\\[\n    \\begin{bmatrix}\n        \\unit{e}_0 \\\\\n        \\unit{e}_1 \\\\\n        \\unit{e}_2 \\\\\n        \\unit{e}_3\n    \\end{bmatrix} = \n    \\begin{bmatrix}\n        \\tensor{\\Lambda}{_0^0} & \\tensor{\\Lambda}{_0^1} & \\tensor{\\Lambda}{_0^2} & \\tensor{\\Lambda}{_0^3} \\\\\n        \\tensor{\\Lambda}{_1^0} & \\tensor{\\Lambda}{_1^1} & \\tensor{\\Lambda}{_1^2} & \\tensor{\\Lambda}{_1^3} \\\\\n        \\tensor{\\Lambda}{_2^0} & \\tensor{\\Lambda}{_2^1} & \\tensor{\\Lambda}{_2^2} & \\tensor{\\Lambda}{_2^3} \\\\\n        \\tensor{\\Lambda}{_3^0} & \\tensor{\\Lambda}{_3^1} & \\tensor{\\Lambda}{_3^2} & \\tensor{\\Lambda}{_3^3}\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        \\vec{e}_0 \\\\\n        \\vec{e}_1 \\\\\n        \\vec{e}_2 \\\\\n        \\vec{e}_3\n    \\end{bmatrix},\n\\]\nwhere the lower index $\\nu$ represents the row and the upper index $\\mu$, the column.\n\nHowever, it's very important to note that this transformation matrix is \\emph{not} a tensor, even though it kind of looks like one.\nOne way we can tell that this is not a tensor is that the indices are in the wrong order; all tensors have upper indices first, and then lower indices.\nAnother key difference is the lack of a basis; while $\\{\\unit{e}_\\nu\\}$ and $\\{\\vec{e}_\\mu\\}$ are basis vectors of $V$, $\\tensor{\\Lambda}{_\\nu^\\mu}$ is not a vector in this space, and we haven't defined any basis for $\\tensor{\\Lambda}{_\\nu^\\mu}$, or even a tensor product space for $\\tensor{\\Lambda}{_\\nu^\\mu}$ to live in.\nFinally, recall that tensors are maps between the Cartesian products of covectors and vectors to a scalar field,\n\\[ \\tensor{T}{^\\mu_\\nu} : V^* \\times V \\to \\mathbb{F}, \\]\nwhile $\\tensor{\\Lambda}{_\\nu^\\mu}$ is mapping between vectors and other vectors in the same space, so \n\\[ \\tensor{\\Lambda}{_\\nu^\\mu} : V \\to V. \\]\n\n\\subsection{Transforming Vectors}\nSuppose we have a vector $\\vec{w}$, written equivalently in our two different bases as $A^\\mu \\vec{e}_\\mu$ and $B^\\nu \\unit{e}_\\nu$.\nSince we defined a linear transformation $\\unit{e}_\\nu = \\tensor{\\Lambda}{_\\nu^\\mu} \\vec{e}_\\mu$ to change between basis vectors, we can rewrite this as\n\\[ \\vec{w} = B^\\nu \\unit{e}_\\nu = B^\\nu \\tensor{\\Lambda}{_\\nu^\\mu} \\vec{e}^\\mu. \\]\nNow $\\vec{w}$ is written in terms of the $\\vec{e}_\\mu$ basis, and since we already know that $\\vec{w} = A^\\mu \\vec{e}_\\mu$, we know that\n\\[ A^\\mu = B^\\nu\\tensor{\\Lambda}{_\\nu^\\mu}. \\]\nThis allows us to transform the coefficients between bases, along with basis vectors, which means that we can transform \\emph{any} vector now using this method.\n\n\\subsection{Reverse Transformations}\nWe've just demonstrated how to go from a $\\vec{e}_\\mu$ to $\\unit{e}_\\nu$, and from $B^\\nu$ to $A^\\mu$, but what if we want to go the other direction?\nWell, since all these transformations are \\emph{linear}, and therefore \\emph{invertable}\\footnote{There's actually an additional requirement placed on us here. Not all linear transformations are invertible, since some destroy information. Consider the transformation $T : x \\mapsto 0$, which takes any input and spits out $0$. You can check that this satisfies every property of linearity, but its clear that it's not an invertible transformation: if I give you an $x$, you can tell me that $T(x)$ is zero, but if I ask ``what number did I plug into $T$ to get $0$?'', you'll have infinitely many possibilities. In order for $\\Lambda$ to be invertible, it must have a non-zero determinant. You can think of the determinant as the ``signed volume'' of the unit $n$-cube after transformation by $\\Lambda$, where $n = \\dim(\\Lambda)$. It's a good excercise to think about why we know for certain that transformations between bases are always invertible.}, we can simply use the inverse matrix $\\tensor{\\left(\\Lambda^{-1}\\right)}{_\\mu^\\nu}$ to do just that.\nThis gives us a nice table to show how various structures transform using $\\Lambda$:\n\\[\n    \\begin{matrix}\n        \\unit{e}_\\nu = \\tensor{\\Lambda}{_\\nu^\\mu} \\vec{e}_\\mu &  & \\vec{e}_\\mu = \\tensor{\\left(\\Lambda^{-1}\\right)}{_\\mu^\\nu}\\unit{e}_\\nu \\\\\n        & & \\\\\n         A^\\mu = B^\\nu\\tensor{\\Lambda}{_\\nu^\\mu} & & B^\\nu = A^\\mu \\tensor{\\left(\\Lambda^{-1}\\right)}{_\\mu^\\nu}\n    \\end{matrix}\n\\]\nEntries in the first column transform using $\\Lambda$, while entries in the second transform using $\\Lambda^{-1}$.\nThe first row shows how the basis vectors transform, and the second row shows how the coefficients transform. \nIts important to notice a few things here.\n\\begin{itemize}\n    \\item When we invert the transformation $\\Lambda$, the indices switch places; in $\\tensor{\\Lambda}{_\\nu^\\mu}$, $\\nu$ is the lower index while $\\mu$ is the upper, while in $\\tensor{\\left(\\Lambda^{-1}\\right)}{_\\mu^\\nu}$, $\\mu$ is the lower index while $\\nu$ is the upper.\n    \\item Basis vectors transform with $\\Lambda$ or $\\Lambda^{-1}$ on the left, while coefficients transform with it on the right; this is because the coefficients are scalars, while the basis vectors are vectors, and so $\\Lambda$ acts as an operator.\n    \\item In each change of basis, we need to change both the basis vector and the coefficient. However, basis vectors and coefficients in the same transformation use \\emph{different} matrices; we don't just use $\\Lambda$ to go from the $\\nu$ vectors to the $\\mu$ vectors, we need both $\\Lambda$ and $\\Lambda^{-1}$.\n    Consider that if we want to change $B^\\nu \\unit{e}_\\nu$ into a $\\mu$ basis, we use the following two transformations to do so:\n    \\[\n        \\begin{matrix}\n            \\unit{e}_\\nu = \\tensor{\\Lambda}{_\\nu^\\mu} \\vec{e}_\\mu &  & \\mathcolor{gray}{\\vec{e}_\\mu = \\tensor{\\left(\\Lambda^{-1}\\right)}{_\\mu^\\nu}\\unit{e}_\\nu} \\\\\n            & & \\\\\n             \\mathcolor{gray}{A^\\mu = B^\\nu\\tensor{\\Lambda}{_\\nu^\\mu}} & & B^\\nu = A^\\mu \\tensor{\\left(\\Lambda^{-1}\\right)}{_\\mu^\\nu}\n        \\end{matrix}\n    \\]\n    To see why we need both $\\Lambda$ and $\\Lambda^{-1}$ in a single transformation, let's go back to our vector $\\vec{w}$, and transform it entirely from the $\\nu$ basis back to the $\\mu$ basis.\n    \\[\n        \\vec{w} = B^\\nu \\unit{e}_\\nu = A^\\mu \\tensor{\\left(\\Lambda^{-1}\\right)}{_\\mu^\\nu} \\tensor{\\Lambda}{_\\nu^\\mu} \\vec{e}_\\mu = A^\\mu \\vec{e}_\\mu.\n    \\]\n    Notice how the $\\Lambda$ and $\\Lambda^{-1}$ end up right next to one another, and because they are inverses of one another, they cancel out, leaving us with just the resultant components and basis vectors.\n    If we want to end up with no matrices in our final vector, we have to use both $\\Lambda$ and $\\Lambda^{-1}$ to transform between bases.\n    \\item $\\Lambda$ and $\\Lambda^{-1}$ are arbitrary choices based on the direction of transformation we define.\n    The above table is based on going from $\\unit{e}_\\nu$ basis vectors to $\\vec{e}_\\mu$ basis vectors, but we could just as easily have defined $\\Lambda$ in a way that we go from $\\vec{e}_\\mu$ back to $\\unit{e}_\\nu$.\n    However, regardless of which way we choose, notice that the components of vectors always transform using the inverse transformation as the basis vectors do; if $\\vec{e}_\\mu$ uses $\\Lambda$, then $A^\\mu$ will use $\\Lambda^{-1}$, and if $\\unit{e}_\\nu$ uses $\\Lambda^{-1}$, then $B^\\nu$ will use $\\qty(\\Lambda^{-1})^{-1} = \\Lambda$.\n\\end{itemize}\n\n\\subsection{Covariance and Contravariance}\nThe fact that components of basis vectors transform using the inverse transformation is where we get the notion of \\emph{covariance} and \\emph{contravariance}; a \\emph{covariant} object is anything that transforms in the same way as the basis vectors, while a \\emph{contravariant} object is anything that transforms in the inverse way.\nThis distinction is one of the major benefits of using the Einstein summation convention, since it let's us know at a glance how a given object will transform: anything with lower indices, like basis vectors, will transform covariantly, while anything with upper indices, like scalar components, will transform contravariantly.\n\nNote that contravariant $\\not=$ `uses $\\Lambda^{-1}$'.\nContravariance is always defined with respect to how the basis transforms.\nIf the basis transforms with $\\Lambda$, then a contravariant object \\emph{will} use $\\Lambda^{-1}$, but if the basis transforms using $\\Lambda^{-1}$, then a contravariant object will transform with $\\Lambda$.\n", "meta": {"hexsha": "5391d1cf59935a495071f68443aceb10b110a6af", "size": 10794, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/linear_transformations.tex", "max_stars_repo_name": "jopetty/tensor-notes", "max_stars_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/linear_transformations.tex", "max_issues_repo_name": "jopetty/tensor-notes", "max_issues_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/linear_transformations.tex", "max_forks_repo_name": "jopetty/tensor-notes", "max_forks_repo_head_hexsha": "64f3e51910118e6b031e9668a2b48a6af06c8600", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 94.6842105263, "max_line_length": 1052, "alphanum_fraction": 0.6860292755, "num_tokens": 3129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.8633916099737807, "lm_q1q2_score": 0.8033498512245085}}
{"text": "This section provides some additional examples for the features listed\nin the paper.\n\n\\subsection{Simplification}\n\\begin{itemize}\n\\item \\texttt{expand}:\n\\begin{verbatim}\n>>> expand((x + y)**3)\nx**3 + 3*x**2*y + 3*x*y**2 + y**3\n\\end{verbatim}\n\n\\item \\texttt{factor}:\n\\begin{verbatim}\n>>> factor(x**3 + 3*x**2*y + 3*x*y**2 + y**3)\n(x + y)**3\n\\end{verbatim}\n\n\\item \\texttt{collect}:\n\\begin{verbatim}\n>>> collect(y*x**2 + 3*x**2 - x*y + x - 1, x)\nx**2*(y + 3) + x*(-y + 1) - 1\n\\end{verbatim}\n\n\\item \\texttt{cancel}:\n\\begin{verbatim}\n>>> cancel((x**2 + 2*x + 1)/(x**2 - 1))\n(x + 1)/(x - 1)\n\\end{verbatim}\n\n\\item \\texttt{apart}:\n\\begin{verbatim}\n>>> apart((x**3 + 4*x - 1)/(x**2 - 1))\nx + 3/(x + 1) + 2/(x - 1)\n\\end{verbatim}\n\n\\item \\texttt{trigsimp}:\n\\begin{verbatim}\n>>> trigsimp(cos(x)**2*tan(x) - sin(2*x))\n-sin(2*x)/2\n\\end{verbatim}\n\n\\item \\texttt{hyperexpand} (showing ${{}_{2}F_{1}\\left(\\begin{matrix} 1, 1 \\\\\n        2 \\end{matrix}\\middle| {- x} \\right)} = \\frac{\\log{\\left (x + 1 \\right )}}{x}$):\n\\begin{verbatim}\n>>> hyperexpand(hyper([1, 1], [2], -x))\nlog(x + 1)/x\n\\end{verbatim}\n\\end{itemize}\n\n\\subsection{Polynomials}\n%% TODO - explain why these matter\n\\begin{itemize}\n\\item Factorization:\n\\begin{verbatim}\n>>> t = symbols('t')\n>>> f = (2115*x**4*y + 45*x**3*z**3*t**2 - 45*x**3*t**2 -\n...      423*x*y**4 - 47*x*y**3 + 141*x*y*z**3 + 94*x*y*z*t -\n...      9*y**3*z**3*t**2 + 9*y**3*t**2 - y**2*z**3*t**2 +\n...      y**2*t**2 + 3*z**6*t**2 +  2*z**4*t**3 - 3*z**3*t**2 -\n...      2*z*t**3)\n>>> factor(f)\n(t**2*z**3 - t**2 + 47*x*y)*(2*t*z + 45*x**3 - 9*y**3 - y**2 +\n 3*z**3)\n\\end{verbatim}\n\n\\item Gr\\\"{o}bner bases:\n\\begin{verbatim}\n>>> x0, x1, x2 = symbols('x0 x1 x2')\n>>> I = [x0 + 2*x1 + 2*x2 - 1,\n...      x0**2 + 2*x1**2 + 2*x2**2 - x0,\n...      2*x0*x1 + 2*x1*x2 - x1]\n>>> groebner(I, order='lex')\nGroebnerBasis([7*x0 - 420*x2**3 + 158*x2**2 + 8*x2 - 7,\n7*x1 + 210*x2**3 - 79*x2**2 + 3*x2,\n84*x2**4 - 40*x2**3 + x2**2 + x2], x0, x1, x2, domain='ZZ',\norder='lex')\n\\end{verbatim}\n\n\\item Root isolation:\n\\begin{verbatim}\n>>> f = 7*z**4 - 19*z**3 + 20*z**2 + 17*z + 20\n>>> intervals(f, all=True, eps=0.001)\n([],\n [((-425/1024 - 625*I/1024, -1485/3584 - 2185*I/3584), 1),\n  ((-425/1024 + 2185*I/3584, -1485/3584 + 625*I/1024), 1),\n  ((3175/1792 - 2605*I/1792, 1815/1024 - 10415*I/7168), 1),\n  ((3175/1792 + 10415*I/7168, 1815/1024 + 2605*I/1792), 1)])\n\\end{verbatim}\n\\end{itemize}\n\\subsection{Solvers}\n\n\\begin{itemize}\n\\item Single solution:\n\\begin{verbatim}\n>>> solveset(x - 1, x)\n{1}\n\\end{verbatim}\n\n\\item Finite solution set, quadratic equation:\n\\begin{verbatim}\n>>> solveset(x**2 - pi**2, x)\n{-pi, pi}\n\\end{verbatim}\n\n\\item No solution:\n\\begin{verbatim}\n>>> solveset(1, x)\nEmptySet()\n\\end{verbatim}\n\n\\item Interval solution:\n\\begin{verbatim}\n>>> solveset(x**2 - 3 > 0, x, domain=S.Reals)\n(-oo, -sqrt(3)) U (sqrt(3), oo)\n\\end{verbatim}\n\n\\item Infinitely many solutions:\n% SymPy 1.0 sstr() prints S.Complexes incorrectly\n% no-doctest\n\\begin{verbatim}\n>>> solveset(x - x, x, domain=S.Reals)\n(-oo, oo)\n>>> solveset(x - x, x, domain=S.Complexes)\nS.Complexes\n\\end{verbatim}\n\n\\item Linear systems (\\texttt{linsolve})\n\\begin{verbatim}\n>>> A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 10]])\n>>> b = Matrix([3, 6, 9])\n>>> linsolve((A, b), x, y, z)\n{(-1, 2, 0)}\n>>> linsolve(Matrix(([1, 1, 1, 1], [1, 1, 2, 3])), (x, y, z))\n{(-y - 1, y, 2)}\n\\end{verbatim}\n\\end{itemize}\n\nBelow are examples of \\texttt{solve} applied to problems not yet handled by \\texttt{solveset}.\n\n\\begin{itemize}\n\\item Nonlinear (multivariate) system of equations (the intersection of a circle\nand a parabola):\n\\begin{verbatim}\n>>> solve([x**2 + y**2 - 16, 4*x - y**2 + 6], x, y)\n[(-2 + sqrt(14), -sqrt(-2 + 4*sqrt(14))),\n (-2 + sqrt(14), sqrt(-2 + 4*sqrt(14))),\n (-sqrt(14) - 2, -I*sqrt(2 + 4*sqrt(14))),\n (-sqrt(14) - 2, I*sqrt(2 + 4*sqrt(14)))]\n\\end{verbatim}\n\n\\item Transcendental equations:\n\\begin{verbatim}\n>>> solve((x + log(x))**2 - 5*(x + log(x)) + 6, x)\n[LambertW(exp(2)), LambertW(exp(3))]\n>>> solve(x**3 + exp(x))\n[-3*LambertW((-1)**(2/3)/3)]\n\\end{verbatim}\n\\end{itemize}\n\n\\subsection{Matrices}\n\n\\begin{itemize}\n\\item Matrix expressions\n\\begin{verbatim}\n>>> m, n, p = symbols('m n p', integer=True)\n>>> R = MatrixSymbol('R', m, n)\n>>> S = MatrixSymbol('S', n, p)\n>>> T = MatrixSymbol('T', m, p)\n>>> U = R*S + 2*T\n>>> U.shape\n(m, p)\n>>> U[0, 1]\n2*T[0, 1] + Sum(R[0, _k]*S[_k, 1], (_k, 0, n - 1))\n\\end{verbatim}\n\n\\item Block Matrices\n\\begin{verbatim}\n>>> n, m, l = symbols('n m l')\n>>> X = MatrixSymbol('X', n, n)\n>>> Y = MatrixSymbol('Y', m ,m)\n>>> Z = MatrixSymbol('Z', n, m)\n>>> B = BlockMatrix([[X, Z], [ZeroMatrix(m, n), Y]])\n>>> B\nMatrix([\n[X, Z],\n[0, Y]])\n>>> B[0, 0]\nX[0, 0]\n>>> B.shape\n(m + n, m + n)\n\\end{verbatim}\n\\end{itemize}\n", "meta": {"hexsha": "4f2c361ae23006efb7f7088629828c112299ef53", "size": 4717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples.tex", "max_stars_repo_name": "ProgZone/sympy-paper", "max_stars_repo_head_hexsha": "b3b85809cc92d1fd588971f944abda9fa995a426", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2016-03-27T06:55:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-22T18:42:39.000Z", "max_issues_repo_path": "examples.tex", "max_issues_repo_name": "ProgZone/sympy-paper", "max_issues_repo_head_hexsha": "b3b85809cc92d1fd588971f944abda9fa995a426", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 205, "max_issues_repo_issues_event_min_datetime": "2016-03-17T03:08:15.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-01T17:09:29.000Z", "max_forks_repo_path": "examples.tex", "max_forks_repo_name": "ProgZone/sympy-paper", "max_forks_repo_head_hexsha": "b3b85809cc92d1fd588971f944abda9fa995a426", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2016-03-17T16:02:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-15T15:06:54.000Z", "avg_line_length": 24.4404145078, "max_line_length": 94, "alphanum_fraction": 0.5622217511, "num_tokens": 2003, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090322, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.8033498462296673}}
{"text": "\\lab{Gaussian Quadrature}{Gaussian Quadrature}\n\\label{Lab:GaussQuad}\n\n\\objective{\nNumerical quadrature is an important numerical integration technique.\nThe popular Newton-Cotes quadrature uses uniformly spaced points to approximate the integral, but Gibbs phenomenon prevents Newton-Cotes from being effective for many functions.\nThe Gaussian Quadrature method uses carefully chosen points and weights to mitigate this problem.\n}\n\n\\section*{Shifting the Interval of Integration}\n\nAs with all quadrature methods, we begin by choosing a set of points $x_i$ and weights $w_i$ to approximate an integral.\n\\[\n\\int_{a}^b f(x) dx \\approx \\sum_{i=1}^n w_if(x_i).\n\\]\n\nWhen we do guassian quadrature, we are required to choose a weight function $W(x)$.\nThis function determines both the $x_i's$ and the $w_i's$.\nTheoretically, the weight function determines a set of orthogonal polynomials to approximate the function $f$.\n\nThe weight function also determines the interval over which the integration will occur.\nFor example, we choose the weight function as $W(x) = 1$ over $[-1,1]$ to integrate functions on $[-1,1]$.\nTo calculate the definite integrate over any interval, we perform a u-substitution.\nThis results in the following formula.\n\\[\n\\int_a^b f(x) dx = \\frac{b-a}{2}\\int_{-1}^1 f(\\frac{b-a}{2}z + \\frac{a+b}{2})dz.\n\\]\n\nOnce we have changed the interval, we may apply quadrature to the integral from $-1$ to $1$ and then scale it appropriately to get the answer we want.\n\\[\n\\int_a^b f(x) dx \\approx \\frac{b - a}{2} \\sum_i w_if(\\frac{(b-a)}{2}x_i + \\frac{(b+a)}{2})\n\\]\n\n% Problem 1: shift the integral for a particular function.\n\\begin{problem}\nLet $f(x) = x^2$ on $[1,4]$. Then $g(x)$ will be the interval-adjusted version of $f$ on $[-1,1]$, with $W(x)=1$, $a=1$, and $b=4$. So,\n\\begin{align*}\ng(x) &= f(\\frac{b-a}{2}x + \\frac{b+a}{2}) \\\\\n&= \\frac{9}{4} x^2 + \\frac{15 x}{2} + \\frac{25}{4}\n\\end{align*}\n\nand the interval-adjusted integral of $f(x)$ will be\n\n\\begin{align*}\nG(x) &= \\frac{b - a}{2} \\int f(\\frac{b - a}{2} x + \\frac{b + a}{2})dx \\\\\n&= \\frac{9}{8} x^3 + \\frac{45}{8} x^2 + \\frac{75}{8} x\n\\end{align*}\n\nVerify that evaluating $G(1) - G(-1) = \\int_1^4 f(x)dx$.\n\\end{problem}\n\n% Problem 2: general integral shift.\n\\begin{problem}\nWrite a function that will accept a function $f$ and an interval $[a,b]$ and return a function $g$ on $[-1,1]$ that has the same integral (scaled by a constant) as $f$.\n\nUse your function to plot $f(x) = x^2$ on $[1, 4]$ and the corresponding function $\\frac{\\left(b - a\\right)}{2}g$ on $[-1,1]$.\nNote that the functions will not look the same plotted, since they are defined over intervals with different lengths, but they integrate to the same value.\n\\end{problem}\n\n\\section*{Integrating with Given Weights and Points}\n\nWe now give an example of quadrature with known weights and points.\nWe use the constant weight function $W(x) = 1$ from $-1$ to $1$ (this weight function corresponds to the Legendre polynomials) to calculate the integral of $f(x) = sin(x)$ from $-\\pi$ to $\\pi$, with $5$ interpolation points.\n\nFirst, we change the interval from $[-\\pi,\\pi]$ to $[-1,1]$.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> a, b = - np.pi, np.pi\n\n# f is the function to integrate.\n>>> f = np.sin\n\n# g is the function with the interval changed.\n>>> g = lambda x: f((b - a) / 2 * x + (a + b) / 2)\n\\end{lstlisting}\n\n\\begin{table}[h!]\n\\begin{center}\n\\begin{tabular}{|c|c|}\n\\hline\npoint $x_i$ & weight $w_i$ \\\\\n\\hline\n$-\\frac{1}{3}\\sqrt{5 + 2\\sqrt{\\frac{10}{7}}}$ &  $\\frac{322-13\\sqrt{70}}{900}$ \\\\\n\\hline\n$-\\frac{1}{3}\\sqrt{5 - 2\\sqrt{\\frac{10}{7}}}$ & $\\frac{322+13\\sqrt{70}}{900}$ \\\\\n\\hline\n$0$ & $\\frac{128}{225}$ \\\\\n\\hline\n$\\frac{1}{3}\\sqrt{5 - 2\\sqrt{\\frac{10}{7}}}$ & $\\frac{322+13\\sqrt{70}}{900}$ \\\\\n\\hline\n$\\frac{1}{3}\\sqrt{5 + 2\\sqrt{\\frac{10}{7}}}$ & $\\frac{322-13\\sqrt{70}}{900}$ \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\caption{Quadrature points and weights on $\\left[-1, 1\\right]$.}\n\\label{intro_table}\n\\end{table}\n\nThe weights($w_i$) and points at which $f$ is evaluated ($x_i$) are given in order in Table \\ref{intro_table}.\nWe put them into an array here.\n\n%TODO: fix these thingies.\n\\begin{lstlisting}\n>>> from math import sqrt\n>>> points = np.array([- sqrt(5 + 2 * sqrt(10. / 7)) / 3,\n                       - sqrt(5 - 2 * sqrt(10. / 7)) / 3,\n                       0,\n                       sqrt(5 - 2 * sqrt(10. / 7)) / 3,\n                       sqrt(5 + 2 * sqrt(10. / 7)) / 3])\n>>> weights = np.array([(322 - 13 * sqrt(70)) / 900,\n                        (322 + 13 * sqrt(70)) / 900,\n                        128. / 225,\n                        (322 + 13 * sqrt(70)) / 900,\n                        (322 - 13 * sqrt(70)) / 900])\n\\end{lstlisting}\n\nWe now calculate the integral\n\n\\begin{lstlisting}\n>>> integral = (b - a)/2 * np.inner(weights, g(points))\n\\end{lstlisting}\n\n% Problem 3: Integrating with Weights.\n\\begin{problem}\nWrite a function that accepts a function f, an array of points, an array of weights, and limits of integration and returns the integral.\nDon't forget to adjust the interval as in the above example.\n\\end{problem}\n\n\\section*{Calculating Weights and Points}\n\nCalculating an integral when the weights and points are given is straightforward.\nBut, how are these weights and points found?\nThere are many publications that will give tables of points for various weight functions.\nWe will demonstrate how to find such a list using the Golub-Welsch algorithm.\n\n\\subsection*{The Golub-Welsch Algorithm}\n\nThis Golub-Welsch algorithm builds a tri-diagonal matrix and finds its eigenvalues.\nThese eigenvalues are the points at which a function is evaluated for Guassian quadrature.\nThe weights are the length of $\\left[a, b\\right]$ times the first coordinate of each eigenvector squared.\nWe note that finding eigenvalues for a tridiagonal matrix is a well conditioned, relatively painless problem.\nUsing a good eigenvalue solver gives the Golub-Welsch algorithm a complexity of $O(n^2)$.\nA full treatment of the Golub-Welsch algorithm may be found at \\url{http://gubner.ece.wisc.edu/gaussquad.pdf}.\n\nWe mentioned that the choice of weight function corresponds to a class of orthogonal polyomials.\nAn important fact about orthogonal polynomials is that any set of orthogonal polynomials $\\{u_i\\}_{i=1}^{N}$ satisfies a three term recurrence relation\n\\[\nu_{i}(x) = (\\gamma_{i-1}x-\\alpha_i)u_{i-1}(x) - \\beta_iu_{i-2}(x)\n\\]\nwhere $u_{-1}(x) = 0$ and $u_0(x) = 1$.\nThe coefficients $\\{\\gamma_k, \\alpha_i, \\beta_i\\}$ have been calculated for several classes of orthogonal polynomials, and may be determined for an arbitrary class using the procedure found in ``Calculation of Gauss Quadrature Rules'' by Golub and Welsch.\nUsing these coefficients we may create a tri-diagonal matrix\n\n\\[\nJ = \\begin{bmatrix}\n\na_1 & b_1 & 0 & 0 & ... & 0 \\\\\nb_1 & a_2 & b_2 & 0 & ... & 0 \\\\\n0 & b_2 & a_3 & b_3 & ... & 0 \\\\\n\\vdots & & & & & \\vdots \\\\\n\\vdots & & & & & \\vdots \\\\\n0 & ... & & & & b_{N-1} \\\\\n0 & ... & & & b_{N-1} & a_N\n\n\\end{bmatrix}\n\\]\n\nWhere $a_i = \\frac{-\\beta_i}{\\alpha_i}$ and $b_i = (\\frac{\\gamma_{i+1}}{\\alpha_i \\alpha_{i+1}})^{\\frac{1}{2}}$.\nThis matrix is called the Jacobi matrix.\nThe eigenvalues of this matrix give us the points $x_i$ and the length of $\\left[a, b\\right]$ times the squares of the first entries of the corresponding eigenvectors gives the weights.\n\n% Problem 4: Construct the Jacobi matrix.\n\\begin{problem}\nWrite a function that will accept three arrays representing the coefficients $\\{\\gamma_i, \\alpha_i, \\beta_i\\}$ from the recurrence relation above and return the Jacobi matrix.\n\\end{problem}\n\n\\begin{problem}\nThe coefficients of the Legendre polynomials (which correspond to the weight function $W(x) = 1$ on $[-1,1]$ are given by\n\\begin{align}\\nonumber\n\\alpha_i = \\frac{2i - 1}{i} && \\beta_i = 0 && \\gamma_i = \\frac{i-1}{i}\n\\end{align}\n\nWrite a function that accepts an integer $n$ representing the number of points to use in the quadrature. Calculate $\\alpha$, $\\beta$, and $\\gamma$ as above, calculate the Jacobi matrix, then use it to find the points $x_i$ and weights $w_i$ that correspond to this weight function.\nWhen $n=5$, do they match the ones given in the first part of this lab?\n\n\\end{problem}\n\n% Problem: integrate!\n\\begin{problem}\nWrite a new function that accepts a function $f$, bounds $a$ and $b$, and $n$ for the number of points to use.\nUse the previously defined functions to estimate $\\int_a^b f(x)dx$ using the coefficients of the Legendre polynomials.\n\nThis completes our implementation of the Gaussian Quadrature for a particular set orthogonal polynomials.\n\\end{problem}\n\n\\section*{scipy.integrate}\n\nThere are other techniques for finding the weights and points for a given weighting function.\nThis is, in fact, not even the fastest method.\nIn general practice, we use \\li{scipy.integrate} to calculate integrals.\n\\li{scipy.integrate.quadrature} offers a reasonably fast Gaussian quadrature implementation.\n\nAnother common hallmark of quadrature is that it can be used adaptively.\nIt is common in practice to refine the points of a quadrature estimate on an interval where a function is observed to be changing rapidly.\nThis allows for more accurate computation at a relatively low computational cost.\nThis is the approach used by the function \\li{scipy.integrate.quad}.\n\n\\begin{problem}\nThe standard normal distribution is an important object of study in probability and statistic.\nIt is defined by the probability density function $p(x) = \\frac{1}{\\sqrt{2 \\pi}} e^{-x^2/2}$ (here we are assuming a mean of $0$ and a variance of $1$).\nThis is a function that cannot be integrated symbollically.\n\nThe probability that a normally distributed random variable $X$ will take on a value less than (or equal to) a given value $x$ is\n\\[P(X \\le x) = \\int_{-\\infty}^x \\frac{1}{\\sqrt{2 \\pi}} e^{-t^2/2} dt\\]\nThis function is essentially zero for values of $x$ that lie reasonably far from the mean, so we can estimate this probability by integrating from $-5$ to $x$ instead of from $-\\infty$ to $x$.\n\nWrite a function that uses \\li{scipy.integrate.quad} to estimate the probability that this normally distributed random variable will take a value less than a given number $x$ that lies relatively close to the mean.\nYou can test your result at $x = 1$ by comparing it with the following code:\n\\begin{lstlisting}\nfrom scipy.stats import norm\nN = norm()\nN.cdf(1)\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{comment}\n%Another exercise could be Chebyshev polynomials.  See wikipedia for the weight function.\n\\section*{Additional Material}\n\n\\begin{problem}\nGauss Quadrature with Chebyshev polynomials.\n\\end{problem}\n\\end{comment}\n", "meta": {"hexsha": "f0fccc83889dece7f5baf097eac0929ca75585cd", "size": 10629, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol2A/GaussianQuadrature/GaussianQuadrature.tex", "max_stars_repo_name": "joshualy/numerical_computing", "max_stars_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vol2A/GaussianQuadrature/GaussianQuadrature.tex", "max_issues_repo_name": "joshualy/numerical_computing", "max_issues_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vol2A/GaussianQuadrature/GaussianQuadrature.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 45.229787234, "max_line_length": 281, "alphanum_fraction": 0.6975256374, "num_tokens": 3126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.8962513724408292, "lm_q1q2_score": 0.8032665132883446}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage{enumitem}\n\\usepackage{physics}\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{1em}\n\\relpenalty=10000\n\\binoppenalty=10000\n\n\\begin{document}\n\\section*{Inequalities}\n\t\\begin{enumerate}\n\t\\item \\textbf{General mean inequality.}\n\tThe mean of order $p$ of positive real numbers $x_1,\\dots,x_n$ is defined as:\n\t$$M_p=\n\t\\begin{cases}\n\t\\left(\\frac{x_1^p+ \\dots + x_n^p}{n}\\right)^{1/p} &\\text{for } p \\ne 0 \\\\\n\t\\sqrt[n]{x_1 \\dots x_n}                           &\\text{for } p=0\n\t\\end{cases}\n\t$$\n\tIn particular \n\t\\begin{center}\n\t\t\\begin{tabular}{lcl}\n\t\t\tSmallest element & $\\min\\{x_i\\}$ & $M_{-\\infty}$ \\\\\n\t\t\tHarmonic mean & HM & $M_{-1}$ \\\\\n\t\t\tGeometric mean & GM & $M_0$ \\\\\n\t\t\tArithmetic mean & AM & $M_1$ \\\\\n\t\t\tQuadratic mean & QM & $M_2$ \\\\\t\t\t\n\t\t\tLargest element & $\\max\\{x_i\\}$ & $M_{\\infty}$ \n\t\t\\end{tabular}\n\t\\end{center}\n\tThen for any real $p$ and $q$\n\t$$M_p \\leq M_q \\iff p \\leq q $$\n\n\t\\item \\textbf{Cauchy inequality.}\n\tFor real numbers $x_1, \\dots , x_n, y_1, \\dots , y_n$\n\t\n\t$$\\left(\\sum_{i=1}^{n} x_i y_i\\right)^2 \\leq \\sum_{i=1}^{n} x_i^2 \\sum_{i=1}^{n} y_i^2 $$\n\t \n\t\\item \\textbf{Chebyshev inequality.}\n\tFor real numbers $x_1 \\geq \\dots \\geq x_n$ and $y_1 \\geq \\dots \\geq y_n$\n\t$$\\frac{1}{n} \\sum_{i=1}^{n} x_iy_i\n\t\\geq\n\t\\left(\\frac{1}{n}\\sum_{i=1}^{n}x_i\\right)\n\t\\left(\\frac{1}{n}\\sum_{i=1}^{n}y_i\\right) \n\t\\geq\n\t\\frac{1}{n} \\sum_{i=1}^{n} x_iy_{n+1-i} $$\n\t\n\t\\item \\textbf{Jensen inequality.}\n\tGiven positive real numbers $\\lambda_1,\\hdots,\\lambda_n$ for which $\\lambda_1+\\hdots+\\lambda_n=1$  and a convex function $f(x)$ the following holds:\n\t$$f(\\lambda_1 x_1 + \\hdots + \\lambda_n x_n) \\leq \\lambda_1 f(x_1) + \\hdots + \\lambda_n f(x_n)$$\n\tSimilarly, when $f(x)$ is a concave function, then \n\t$$f(\\lambda_1 x_1 + \\hdots + \\lambda_n x_n) \\geq \\lambda_1 f(x_1) + \\hdots + \\lambda_n f(x_n)$$\n\t\t\t\t\n\t\\end{enumerate}\n\t\n\t\\newpage\n\\section*{Problems}\n\t\\begin{enumerate}\n\t\\item % vorrat 97\n\tLet $a_1,\\dots,a_n$ be positive real numbers such that $a_1\\dots a_n =1$ Prove that \n\t$$(1+a_1)\\dots (1+a_n) \\geq 2^n$$\n\t\\item % vorrat 100\n\tFor real numbers $x_1, \\dots , x_n, y_1, \\dots , y_n$ the following holds\n\t$$x_1+\\dots+x_n \\geq x_1y_1 + \\dots + x_ny_n$$\n\tProve that\n\t$$x_1+\\dots+x_n \\leq \\frac{x_1}{y_1} + \\dots + \\frac{x_n}{y_n}$$\n\t\n\t\\item % vorrat 99\n\tLet $n$ be an integer ($n\\geq 2$) and $a_1,\\dots,a_n$ be positive real numbers such that $a_1+\\dots+a_n=1$. Prove the following inequality for any positive real numbers $x_1,\\dots,x_n$ for which $x_1+\\dots+x_n=1$ \n\t$$2\\sum_{i<j} x_ix_j \\leq \\frac{n-2}{n-1} + \\sum_{i=1}^n \\frac{a_ix_i^2}{1-a_i}$$\n\tWhen does the equality hold?\n\t\n\t\\item % vorrat 102\n\tProve that for any positive real numbers $a_1,\\dots,a_n$\n\t$$\\frac{1}{\\frac{1}{1+a_1}+\\dots+\\frac{1}{1+a_n}} - \\frac{1}{\\frac{1}{a_1}+\\dots+\\frac{1}{a_n}} \\geq n$$\n\t\n\t\\item % vorrat 103\n\tLet $x_1,\\dots,x_n$ be positive real numbers such that\n\t$$\\frac{1}{1+x_1} + \\dots + \\frac{1}{1+x_n}=1$$\n\tProve that\n\t$$x_1 \\dots x_n \\geq (n-1)^n$$\n\t\n\t\\item % vorrat 123\n\tProve for real numbers $x_1,\\dots,x_5$\n\t$$x_1^2 + x_2^2 + x_3^2 + x_4^2 + x_5^2 \\geq \\frac{2}{\\sqrt{3}}(x_1x_2 + x_2x_3 + x_3x_4 + x_4x_5) $$\n\t\n\t\\item % vorrat 106\n\tLet $a,b,c$ be positive real numbers. Prove that\n\t$$\\left(1+\\frac{a}{b}\\right) \\left(1+\\frac{b}{c}\\right)  \\left(1+\\frac{c}{a}\\right) \\geq \n\t2\\left(1+\\frac{a+b+c}{\\sqrt[3]{abc}}\\right)$$\n\t\n\t\\item % vorrat 104\n\tGiven positive real numbers $x_1,\\dots,x_n$ for which $x_1^2+\\dots+x_n^2=1$, find the minimal value of the expression\n\t$$\\frac{x_1^5}{x_2+x_3+\\dots+x_n} + \\frac{x_2^5}{x_1+x_3+\\dots+x_n} + \\dots +\\frac{x_n^5}{x_1+x_2+\\dots+x_{n-1}}$$\n\t\n\t\\item % vorrat 101\n\tLet $x_1,\\dots,x_n$ be positive real numbers for which $x_1+\\dots+x_n=1$. Prove that\n\t$$\\frac{x_1}{\\sqrt{1-x_1}} + \\dots + \\frac{x_n}{\\sqrt{1-x_n}} \n\t\\geq\n\t\\frac{\\sqrt{x_1}+\\dots+\\sqrt{x_n}}{\\sqrt{n-1}} $$\n\t\n\t\\item % http://artofproblemsolving.com/wiki/index.php?title=2004_USAMO_Problems/Problem_5\n\tLet $a,b,c$ be positive real numbers. Prove that\n\t$$(a^5-a^2+3)(b^5-b^2+3)(c^5-c^2+3)\\geq (a+b+c)^3$$\n\t\n\t\n\t\n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "166f6cc6fdd5180536a44e26c80759ae244e8b7b", "size": 4159, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12_inequalities.tex", "max_stars_repo_name": "ZhaoWanLong/maths-olympiad", "max_stars_repo_head_hexsha": "0dcacba8a6d1769bbccfedda89d08fa22c3f55a1", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-21T21:57:43.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-21T21:57:43.000Z", "max_issues_repo_path": "12_inequalities.tex", "max_issues_repo_name": "ZhaoWanLong/maths-olympiad", "max_issues_repo_head_hexsha": "0dcacba8a6d1769bbccfedda89d08fa22c3f55a1", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "12_inequalities.tex", "max_forks_repo_name": "ZhaoWanLong/maths-olympiad", "max_forks_repo_head_hexsha": "0dcacba8a6d1769bbccfedda89d08fa22c3f55a1", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-08T07:04:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-08T07:04:43.000Z", "avg_line_length": 36.8053097345, "max_line_length": 214, "alphanum_fraction": 0.6340466458, "num_tokens": 1841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.8032539213139813}}
{"text": "\\textbf{Modify Program 7 so that you can verify that the data in the first curve of Output 7 match the prediction of Theorem 4(a). Verify also that the third and fourth curves match the predictions of parts (c) and (d).}\n\\newline\n\nIn this problem we verify the convergence rates of Theorem 4. For all cases let $w$ be the $v$th spectral derivative on the grid $h\\mathbb{Z}$. Since we are going to be working with the first derivative, $v=1$.\n\nFirst, we focus on the function $u=|sin(x)|^3$, which has $2=p-1$ continuous derivatives in $L^2(\\mathbb{R})$ and a $p=3$rd derivative of bounded variation. Hence,\n\\begin{align*}\n|w_j - u^{(v)}(x_j)| = \\mathcal{O}(h^{p-v}) = \\mathcal{O}(h^{3-1}) = \\mathcal{O}(h^{2})~\\text{as}~h \\rightarrow 0,\n\\end{align*}\nwhich we can verify in the next figure.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=.7]{P4_1.eps}\\caption{Error convergence for $u=|sin(x)|^3$.}\n\\end{figure}\n\nSecond, the function $ u = \\frac{1}{1+\\sin^2(x/2)}$ is analytic in a strip in the complex plane. We find this strip as follows\n\\begin{align*}\n1 + \\sin^2(z/2) = 0 ~\\Rightarrow ~a = \\text{Imag}(2 \\arcsin(i))~\\Rightarrow~ a \\approx 1.76~.\n\\end{align*}\nThen, according to the theorem,\n\\begin{align*}\n|w_j - u^{(v)}(x_j)| = \\mathcal{O}\\left(e^{-(a-\\varepsilon)/h)}\\right)~\\text{as}~h \\rightarrow 0~,\n\\end{align*}\nfor every $\\varepsilon>0$ (we have chosen $10^{-4}$). We can verify this result in the following figure.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=.7]{P4_2.eps}\\caption{Error convergence for $ u = \\frac{1}{1+\\sin^2(x/2)}$.}\n\\end{figure}\n\nLastly, $u = \\sin(10x)$ is band-limited. It is possible to find $a >0$ such that $u$ can be extended to an entire function and for $z \\in \\mathbb{C}$, $|u(z)| = o(e^{a|z|})$ as $z \\rightarrow \\infty$. Note that\n\n\\begin{align*}\n|\\sin(10z)| = \\biggl| \\frac{e^{i10z}-e^{-i10z}}{2i} \\biggr| = \\biggl| \\frac{e^{i10x}e^{-10y} - e^{-i10x}e^{10y}}{2i} \\biggr| \\leq \\biggl| \\frac{e^{-10y}-e^{10y}}{2} \\biggr| \\leq e^{10|z|}~,\n\\end{align*}\nwhere we have made $z=x+iy$. Further,\n\\begin{align*}\n\\lim_{z \\rightarrow \\infty} \\frac{|\\sin(10z)|}{|e^{a|z|}|} \\leq \\lim_{z \\rightarrow \\infty} \\frac{e^{10|z|}}{e^{a|z|}} = 0 ~\\Rightarrow ~a > 10.\n\\end{align*}\nAccording to the theorem,\n\\begin{align*}\nw_j = u^{(v)}(x_j),\n\\end{align*}\nas long as $h =2\\pi/N \\leq \\pi/a$. Hence,\n\\begin{align*}\nw_j = u^{(v)}(x_j),\n\\end{align*}\nfor $N>2a=20$, which is clearly seen in the next figure, where for $N>20$ the error is machine precision.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=.7]{P4_3.eps}\\caption{Error convergence for $u = \\sin(10x)$.}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 4\nclose all\nfigformat='epsc';\nlinewidth=2;\n% Compute derivatives for various values of N:\nNmax = 50; E = zeros(3,Nmax/2-2);\nfor N = 6:2:Nmax\n    h = 2*pi/N; x = h*(1:N)';\n    column = [0 .5*(-1).^(1:N-1).*cot((1:N-1)*h/2)]';\n    D = toeplitz(column,column([1 N:-1:2]));\n    v = abs(sin(x)).^3;                     % 3rd deriv in BV\n    vprime = 3*sin(x).*cos(x).*abs(sin(x));\n    E(1,N/2-2) = norm(D*v-vprime,inf);\n    v = exp(-sin(x/2).^(-2));               % C-infinity\n    vprime = .5*v.*sin(x)./sin(x/2).^4;\n    E(2,N/2-2) = norm(D*v-vprime,inf);\n    v = 1./(1+sin(x/2).^2);                 % analytic in a strip\n    vprime = -sin(x/2).*cos(x/2).*v.^2;\n    E(3,N/2-2) = norm(D*v-vprime,inf);\n    v = sin(10*x); vprime = 10*cos(10*x);   % band-limited\n    E(4,N/2-2) = norm(D*v-vprime,inf);\nend\nNvector = 6:2:Nmax;\nhvector = 2*pi./Nvector;\n\n\np = 3;\nv = 1;\n\nfigure\nsemilogy(Nvector,E(1,:),'*')\nhold on\nsemilogy(Nvector,hvector.^(p-v),'linewidth',linewidth)\ngrid on\nxlabel('$N$','interpreter','latex')\nylabel('$|w_j-u^{(v)(x_j)}|$','interpreter','latex')\nset(gca,'fontsize',14)\ntxt='Latex/FIGURES/P4_1';\nsaveas(gcf,txt,figformat)\n\na = 1.76;\ne = 1e-4;\n\nfigure\nsemilogy(Nvector,E(3,:),'*')\nhold on\nsemilogy(Nvector,exp(-pi*(a-e)./hvector),'linewidth',linewidth)\ngrid on\nxlabel('$N$','interpreter','latex')\nylabel('$|w_j-u^{(v)(x_j)}|$','interpreter','latex')\nset(gca,'fontsize',14)\ntxt='Latex/FIGURES/P4_2';\nsaveas(gcf,txt,figformat)\n\nfigure\nsemilogy(Nvector,E(4,:),'*')\nhold on\nplot([20 20],[1e-16 10],'r--','linewidth',linewidth)\naxis([5 51 1e-16 2e1])\ngrid on\nxlabel('$N$','interpreter','latex')\nylabel('$|w_j-u^{(v)(x_j)}|$','interpreter','latex')\nset(gca,'fontsize',14)\ntxt='Latex/FIGURES/P4_3';\nsaveas(gcf,txt,figformat)\n\\end{verbatim}\n", "meta": {"hexsha": "6c1402f3127bd2bf0ed06a34881946ab61d5632d", "size": 4426, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework2/Latex/problem4.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework2/Latex/problem4.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework2/Latex/problem4.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.9837398374, "max_line_length": 220, "alphanum_fraction": 0.6296882061, "num_tokens": 1683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.9086178975514609, "lm_q1q2_score": 0.8032539163089485}}
{"text": "\\section{Data Approximation and Neville's Method}\n\\begin{defn}\nThe Lagrange Polynomial that agrees with $f(x)$ at the $k$ distinct points $x_{m_1},x_{m_2},\\cdots,x_{m_k}$ is denoted $P_{m_1,m_2,\\cdots m_k}(x)$.\n\\end{defn}\n\\begin{theo}\nLet $f$ be defined at $x_0,x_1,\\cdots,x_k$, then\n\\[\nP(x)=\\frac{(x-x_j)P_{0,\\cdots,j-1,j+1,\\cdots,k}(x)-(x-x_i)P_{0,\\cdots,i-1,i+1,\\cdots,k}(x)}{x_i-x_j}\n\\]\nis the $k$th Lagrange polynomial that interpolates $f$ at the $k+1$ points.\n\\end{theo}\n\n\\subsection{Neville's Method}\nTo avoid the multiple subscripts, we let $Q_{i,j}\\,(0\\leq j\\leq i)$ denote the interpolating polynomial of degree $j$ on the $(j+1)$ numbers $x_{i-j},\\cdots,x_{i}$.\n\\[\nQ_{i,j} = P_{i-j,i-j+1,\\cdots,i-1,i}\n\\]\nthen for $i=1:n$, $j=1:i$,\n\\[\nQ_{i,j}=\\frac{(x-x_{i-j})Q_{i,j-1}-(x-x_i)Q_{i-1,j-1}}{x_i-x_{i-j}}\n\\]", "meta": {"hexsha": "0e1f5abd7efa286c25ae6cb86537b719c329b75d", "size": 817, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/3.2_Data_approximation_and_nevilles_method.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/3.2_Data_approximation_and_nevilles_method.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/3.2_Data_approximation_and_nevilles_method.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9047619048, "max_line_length": 164, "alphanum_fraction": 0.6450428397, "num_tokens": 358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8723473630627235, "lm_q1q2_score": 0.8032484419064928}}
{"text": "\n\\subsection{Back propagation}\n\n\\subsubsection{Adapting the delta rule}\n\nTo arrive at the delta rule we considered the cost function:\n\n\\(E=\\sum_j\\dfrac{1}{2}(y_j-a_j)^2\\)\n\nAnd used the chain rule:\n\n\\(\\dfrac{\\delta E}{\\delta \\theta_i }=\\dfrac{\\delta E}{\\delta a_j}\\dfrac{\\delta a_j}{\\delta z_j}\\dfrac{\\delta z_j}{\\delta \\theta_i}\\)\n\nThis gave us:\n\n\\(\\Delta \\theta_i=\\alpha \\sum_j(y_j-a_j)a'(z_j)x_{ij}\\)\n\nOr, setting \\(\\delta_i=-\\dfrac{\\delta E}{\\delta z_j}=\\sum_j(y_j-a_j)a'(z_j)\\)\n\n\\(\\Delta \\theta_i=\\alpha \\delta_j x_{ij}\\)\n\nLet's update the rule for multiple layers:\n\n\\(\\dfrac{\\delta E}{\\delta \\theta_{li}}=\\dfrac{\\delta E}{\\delta a_{lj}}\\dfrac{\\delta a_{lj}}{\\delta z_{lj}}\\dfrac{\\delta z_{lj}}{\\delta \\theta_{li}}\\)\n\nPreviously \\(\\dfrac{\\delta z_{lj}}{\\delta \\theta_{li}}=x_i\\). We now use the more general \\(a_{li}\\). For the first layer, these will be the same.\n\nWe can then instead write:\n\n\\(\\Delta \\theta_i=\\alpha \\delta_{lj} a_{li}\\)\n\n\\subsubsection{Calculating delta values}\n\nNow we need a way of calculating the value of \\(\\delta_{lj}\\) for all neurons.\n\n\\(\\delta_i=-\\dfrac{\\delta E}{\\delta z_{lj}}\\)\n\nIf this is an output node, then this is simply \\(\\sum_j(y_j-a_j)a'(z_j)\\)\n\nIf this is not an output node, then the impact of change in the parameter will affect the results through all intermediate neurons.\n\nIn this case:\n\n\\(\\dfrac{\\delta E}{\\delta z_{lj}}=\\sum_{k\\in succ{l}}\\dfrac{\\delta E}{\\delta z_{k}}\\dfrac{\\delta z_{k}}{\\delta z_{lj}}\\)\n\n\\(\\dfrac{\\delta E}{\\delta z_{lj}}=\\sum_{k\\in succ{l}}-\\delta_{k}\\dfrac{\\delta z_{k}}{\\delta a_{kj}}\\dfrac{\\delta a_{kj}}{\\delta z_{lj}}\\)\n\n\\(\\dfrac{\\delta E}{\\delta z_{lj}}=\\sum_{k\\in succ{l}}-\\delta_{k}\\theta_{kj}a'_{kj}\\)\n\n\\(\\delta_i=a'_{kj}\\sum_{k\\in succ{l}}\\delta_{k}\\theta_{kj}\\)\n\nFor each layer there is a matrix, where the columns and rows represent the \\(theta \\) between the current layer and the next layer. We have a matrix for each layer in the network.\n\n", "meta": {"hexsha": "c32b86bc81f6d404115ae34650b0b2f25c22ad1d", "size": 1927, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/neuralNetworks/01-03-backPropagation.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/neuralNetworks/01-03-backPropagation.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/neuralNetworks/01-03-backPropagation.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.6851851852, "max_line_length": 179, "alphanum_fraction": 0.6787752984, "num_tokens": 645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947055100817, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.803218266219621}}
{"text": "\\chapter{Groups}\nA group is one of the most basic structures in higher mathematics.\nIn this chapter I will tell you only the bare minimum:\nwhat a group is, and when two groups are the same.\n\n\\section{Definition and examples of groups}\n\\prototype{The additive group of integers $(\\ZZ,+)$ and the cyclic group $\\Zc m$.\nJust don't let yourself forget that most groups are non-commutative.}\n\nA group consists of two pieces of data: a set $G$,\nand an associative binary operation $\\star$ with some properties.\nBefore I write down the definition of a group, let me give two examples.\n\n\\begin{example}[Additive integers]\n\tThe pair $(\\ZZ, +)$ is a group:\n\t$\\ZZ = \\left\\{ \\dots,-2,-1,0,1,2,\\dots \\right\\}$ is the set\n\tand the associative operation is \\emph{addition}.\n\tNote that\n\t\\begin{itemize}\n\t\t\\ii The element $0 \\in \\ZZ$ is an \\emph{identity}:\n\t\t$a+0=0+a = a$ for any $a$.\n\t\t\\ii Every element $a \\in \\ZZ$ has an additive \\emph{inverse}: $a + (-a) = (-a) + a = 0$.\n\t\\end{itemize}\n\tWe call this group $\\ZZ$.\n\\end{example}\n\\begin{example}[Nonzero rationals]\n\tLet $\\QQ^\\times$ be the set of \\emph{nonzero rational numbers}.\n\tThe pair $(\\QQ^\\times, \\cdot)$ is a group:\n\tthe set is $\\QQ^\\times$\n\tand the associative operation is \\emph{multiplication}.\n\n\tAgain we see the same two nice properties.\n\t\\begin{itemize}\n\t\t\\ii The element $1 \\in \\QQ^\\times$ is an \\emph{identity}:\n\t\tfor any rational number, $a \\cdot 1 = 1 \\cdot a = a$.\n\t\t\\ii For any rational number $x \\in \\QQ^\\times$,\n\t\twe have an inverse $x\\inv$, such that\n\t\t\\[ x \\cdot x\\inv = x\\inv \\cdot x = 1. \\]\n\t\\end{itemize}\n\\end{example}\n\nFrom this you might already have a guess what the definition of a group is.\n\\begin{definition}\n\tA \\vocab{group} is a pair $G = (G, \\star)$\n\tconsisting of a set of elements $G$, and a binary operation $\\star$ on $G$, such that:\n\t\\begin{itemize}\n\t\t\\ii $G$ has an \\vocab{identity element}, usually denoted $1_G$\n\t\tor just $1$, with the property that\n\t\t\\[ 1_G \\star g = g \\star 1_G = g \\text{ for all $g \\in G$}. \\]\n\t\t\\ii The operation is \\vocab{associative}, meaning\n\t\t$(a \\star b) \\star c = a \\star (b \\star c)$\n\t\tfor any $a,b,c \\in G$.\n\t\tConsequently we generally don't write the parentheses.\n\t\t\\ii Each element $g \\in G$ has an \\vocab{inverse}, that is, an element $h \\in G$ such that \\[ g \\star h = h \\star g = 1_G. \\]\n\t\\end{itemize}\n\t\\label{def:group}\n\\end{definition}\n\\begin{remark}\n\t[Unimportant pedantic point]\n\tSome authors like to add a ``closure'' axiom,\n\ti.e.\\ to say explicitly that $g \\star h \\in G$.\n\tThis is implied already by the fact that $\\star$\n\tis a binary operation on $G$,\n\tbut is worth keeping in mind for the examples below.\n\\end{remark}\n\n\\begin{remark}\n\tIt is not required that $\\star$ is commutative ($a \\star b = b \\star a$).\n\tSo we say that a group is \\vocab{abelian} if the operation is\n\tcommutative and \\vocab{non-abelian} otherwise.\n\\end{remark}\n\n% Now that I've made clear what the criteria of a group are,\n% let us write down some non-examples of groups.\n\n\\begin{example}[Non-Examples of groups]\n\t\\listhack\n\t\\begin{itemize}\n\t\t\\ii The pair $(\\QQ, \\cdot)$ is NOT a group.\n\t\t(Here $\\QQ$ is rational numbers.)\n\t\tWhile there is an identity element, the element $0 \\in \\QQ$\n\t\tdoes not have an inverse.\n\t\t\\ii The pair $(\\ZZ, \\cdot)$ is also NOT a group. (Why?)\n\t\t\\ii Let $\\Mat_{2 \\times 2}(\\RR)$ be the set of $2 \\times 2$ real matrices.\n\t\tThen $(\\Mat_{2 \\times 2}(\\RR), \\cdot)$\n\t\t(where $\\cdot$ is matrix multiplication) is NOT a group.\n\t\tIndeed, even though we have an identity matrix\n\t\t\\[ \n\t\t\t\\begin{bmatrix}\n\t\t\t\t1 & 0 \\\\ 0 & 1\n\t\t\t\\end{bmatrix}\n\t\t\\]\n\t\twe still run into the same issue as before:\n\t\tthe zero matrix does not have a multiplicative inverse.\n\n\t\t(Even if we delete the zero matrix from the set,\n\t\tthe resulting structure is still not a group:\n\t\tthose of you that know some linear algebra\n\t\tmight recall that any matrix with determinant zero\n\t\tcannot have an inverse.)\n\t\\end{itemize}\n\\end{example}\n\nLet's resume writing down examples.\nHere are some more \\textbf{abelian examples} of groups:\n\\begin{example}\n\t[Complex unit circle]\n\tLet $S^1$ denote the set of complex numbers $z$ with absolute value one; that is\n\t\\[ S^1 \\defeq \\left\\{ z \\in \\CC \\mid \\left\\lvert z \\right\\rvert = 1 \\right\\}. \\]\n\tThen $(S^1, \\times)$ is a group because\n\t\\begin{itemize}\n\t\t\\ii The complex number $1 \\in S^1$ serves as the identity, and\n\t\t\\ii Each complex number $z \\in S^1$ has an inverse $\\frac 1z$ which is also in $S^1$, since $\\left\\lvert z\\inv \\right\\rvert = \\left\\lvert z \\right\\rvert\\inv = 1$.\n\t\\end{itemize}\n\tThere is one thing I ought to also check: that $z_1 \\times z_2$ is actually still in $S^1$.\n\tBut this follows from the fact that $\\left\\lvert z_1z_2 \\right\\rvert = \\left\\lvert z_1 \\right\\rvert \\left\\lvert z_2 \\right\\rvert = 1$.\n\\end{example}\n\n\\begin{example}\n\t[Addition mod $n$]\n\tHere is an example from number theory:\n\tLet $n > 1$ be an integer,\n\tand consider the residues (remainders) modulo $n$.\n\tThese form a group under addition.\n\tWe call this the \\vocab{cyclic group of order $n$},\n\tand denote it as $\\Zc n$, with elements $\\ol 0, \\ol 1, \\dots$.\n\tThe identity is $\\ol 0$.\n\t\\label{def:cyclic_group}\n\\end{example}\n\\begin{example}\n\t[Multiplication mod $p$]\n\tLet $p$ be a prime.\n\tConsider the \\emph{nonzero residues modulo $p$},\n\twhich we denote by $\\Zm p$.\n\tThen $\\left( \\Zm p, \\times \\right)$ is a group.\n\t\\label{def:mult_mod_p}\n\\end{example}\n\\begin{ques}\n\tWhy do we need the fact that $p$ is prime?\n\\end{ques}\n(Digression: the notation $\\Zc n$ and $\\Zm p$ may seem strange\nbut will make sense when we talk about rings and ideals.\nSet aside your worry for now.)\n\n\nHere are some \\textbf{non-abelian examples}:\n\\begin{example}\n\t[General linear group]\n\tLet $n$ be a positive integer.\n\tThen $\\GL_n(\\RR)$ is defined as the set of $n \\times n$ real matrices\n\twhich have nonzero determinant.\n\tIt turns out that with this condition,\n\tevery matrix does indeed have an inverse,\n\tso $(\\GL_n(\\RR), \\times)$ is a group, called the\n\t\\vocab{general linear group}.\n\n\t(The fact that $\\GL_n(\\RR)$ is closed under $\\times$ follows\n\tfrom the linear algebra fact that $\\det (AB) = \\det A \\det B$,\n\tproved in later chapters.)\n\\end{example}\n\\begin{example}\n\t[Special linear group]\n\tFollowing the example above, let $\\SL_n(\\RR)$ denote \n\tthe set of $n \\times n$ matrices whose determinant is actually $1$.\n\tAgain, for linear algebra reasons\n\tit turns out that $(\\SL_n(\\RR), \\times)$ is also a group,\n\tcalled the \\vocab{special linear group}.\n\\end{example}\n\n\\begin{example}\n\t[Symmetric groups]\n\tLet $S_n$ be the set of permutations of $\\left\\{ 1,\\dots,n \\right\\}$.\n\tBy viewing these permutations as functions from $\\left\\{ 1,\\dots,n \\right\\}$ to itself, we can consider \\emph{compositions} of permutations.\n\tThen the pair $(S_n, \\circ)$ (here $\\circ$ is function composition)\n\tis also a group, because\n\t\\begin{itemize}\n\t\t\\ii There is an identity permutation, and\n\t\t\\ii Each permutation has an inverse.\n\t\\end{itemize}\n\tThe group $S_n$ is called the \\vocab{symmetric group} on $n$ elements.\n\\end{example}\n\\begin{example}\n\t[Dihedral group]\n\tThe \\vocab{dihedral group of order $2n$}, denoted $D_{2n}$,\n\tis the group of symmetries of a regular $n$-gon $A_1A_2 \\dots A_n$,\n\twhich includes rotations and reflections.\n\tIt consists of the $2n$ elements\n\t\\[ \\left\\{ 1, r, r^2, \\dots, r^{n-1}, s, sr, sr^2, \\dots, sr^{n-1} \\right\\}. \\]\n\tThe element $r$ corresponds to rotating the $n$-gon by $\\frac{2\\pi}{n}$,\n\twhile $s$ corresponds to reflecting it across the line $OA_1$\n\t(here $O$ is the center of the polygon).\n\tSo $rs$ mean ``reflect then rotate''\n\t(like with function composition, we read from right to left).\n\n\tIn particular, $r^n = s^2 = 1$. You can also see that $r^k s = sr^{-k}$.\n\\end{example}\n\nHere is a picture of some elements of $D_{10}$.\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(12cm);\n\t\tpicture aoeu(string a, string b, string c, string d, string e,\n\t\t\t\t\tstring x) {\n\t\t\tdraw(dir(0)--dir(72)--dir(144)--dir(216)--dir(288)--cycle);\n\t\t\tMP(a, dir(0), dir(0));\n\t\t\tMP(b, dir(72), dir(72));\n\t\t\tMP(c, dir(144), dir(144));\n\t\t\tMP(d, dir(216), dir(216));\n\t\t\tMP(e, dir(288), dir(288));\n\t\t\tMP(x, origin, origin);\n\t\t\treturn CC();\n\t\t}\n\t\tpicture one = aoeu(\"1\", \"2\", \"3\", \"4\", \"5\", \"1\");\n\t\tpicture r = aoeu(\"5\", \"1\", \"2\", \"3\", \"4\", \"r\");\n\t\tpicture s = aoeu(\"1\", \"5\", \"4\", \"3\", \"2\", \"s\");\n\t\tpicture sr = aoeu(\"5\", \"4\", \"3\", \"2\", \"1\", \"sr\");\n\t\tpicture rs = aoeu(\"2\", \"1\", \"5\", \"4\", \"3\", \"rs\");\n\t\tadd(shift( (0,0) ) * one);\n\t\tadd(shift( (3,0) ) * r);\n\t\tadd(shift( (6,0) ) * s);\n\t\tadd(shift( (9,0) ) * sr);\n\t\tadd(shift( (12,0) ) * rs);\n\t\\end{asy}\n\\end{center}\nTrivia: the dihedral group $D_{12}$ is my favorite example of a non-abelian group,\nand is the first group I try for any exam question of the form ``find an example\\dots''.\n\nMore examples:\n\\begin{example}\n\t[Products of groups]\n\tLet $(G, \\star)$ and $(H, \\ast)$ be groups.\n\tWe can define a \\vocab{product group} $(G \\times H, {\\cdot})$, as follows.\n\tThe elements of the group will be ordered pairs $(g,h) \\in G \\times H$.\n\tThen\n\t\\[ (g_1, h_1) \\cdot (g_2, h_2) = (g_1 \\star g_2, h_1 \\ast h_2) \\in G \\times H\n\t\t\\]\n\tis the group operation.\n\t\\label{def:product_group}\n\\end{example}\n\\begin{ques}\n\tWhat are the identity and inverses of the product group?\n\\end{ques}\n\n\\begin{example}\n\t[Trivial group]\n\tThe \\vocab{trivial group}, often denoted $0$ or $1$,\n\tis the group with only an identity element.\n\tI will use the notation $\\{1\\}$.\n\\end{example}\n\n\\begin{exercise}\n\tWhich of these are groups?\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Rational numbers with odd denominators (in simplest form), where the operation is addition.\n\t\t(This includes integers, written as $n/1$, and $0 = 0/1$).\n\t\t\\ii The set of rational numbers with denominator at most $2$, where the operation is addition.\n\t\t\\ii The set of rational numbers with denominator at most $2$, where the operation is multiplication.\n\t\t\\ii The set of nonnegative integers, where the operation is addition.\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\\section{Properties of groups}\n\\prototype{$\\Zm p$ is possibly best.}\n\\begin{abuse}\n\tFrom now on, we'll often refer to a group $(G, \\star)$ by just $G$.\n\tMoreover, we'll abbreviate $a \\star b$ to just $ab$.\n\tAlso, because the operation $\\star$ is associative,\n\twe will omit unnecessary parentheses: $(ab)c = a(bc) = abc$.\n\\end{abuse}\n\\begin{abuse}\n\tFrom now on, for any $g \\in G$ and $n \\in \\NN$ we abbreviate\n\t\\[ g^n\n\t\t=\n\t\t\\underbrace{g \\star \\dots \\star g}_{\\text{$n$ times}}.\\]\n\tMoreover, we let $g\\inv$ denote the inverse of $g$,\n\tand $g^{-n} = (g\\inv)^n$.\n\\end{abuse}\n\nIn mathematics, a common theme is to require\nthat objects satisfy certain minimalistic properties,\nwith certain examples in mind,\nbut then ignore the examples on paper\nand try to deduce as much as you can just from the properties alone.\n(Math olympiad veterans are likely familiar with\n``functional equations''\nin which knowing a single property about a function\nis enough to determine the entire function.)\nLet's try to do this here,\nand see what we can conclude just from knowing \\Cref{def:group}.\n\nIt is a law in Guam and 37 other states that\nI now state the following proposition.\n\\begin{fact}\n\tLet $G$ be a group.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The identity of a group is unique.\n\t\t\\ii The inverse of any element is unique.\n\t\t\\ii For any $g \\in G$, $(g\\inv)\\inv = g$.\n\t\\end{enumerate}\n\\end{fact}\n\\begin{proof}\n\tThis is mostly just some formal manipulations,\n\tand you needn't feel bad skipping it on a first read.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii If $1$ and $1'$ are identities, then $1 = 1 \\star 1' = 1'$.\n\t\t\\ii If $h$ and $h'$ are inverses to $g$, then $1_G = g \\star h\n\t\t\\implies h' = (h' \\star g) \\star h = 1_G \\star h = h$.\n\t\t\\ii Trivial; omitted. \\qedhere\n\t\\end{enumerate}\n\\end{proof}\n\nNow we state a slightly more useful proposition.\n\\begin{proposition}[Inverse of products]\n\tLet $G$ be a group, and $a,b \\in G$.\n\tThen $(ab)\\inv = b\\inv a\\inv$.\n\\end{proposition}\n\\begin{proof}\n\tDirect computation. We have\n\t\\[ (ab)(b\\inv a\\inv)\n\t\t= a (bb\\inv) a\\inv = aa\\inv = 1_G. \\]\n\tHence $(ab)\\inv = b\\inv a\\inv$.\n\tSimilarly, $(b\\inv a\\inv)(ab) = 1_G$ as well.\n\\end{proof}\n\nFinally, we state a very important lemma about groups,\nwhich highlights why having an inverse is so valuable.\n\\begin{lemma}[Left multiplication is a bijection]\n\tLet $G$ be a group, and pick a $g \\in G$.\n\tThen the map $G \\to G$ given by $x \\mapsto gx$ is a bijection.\n\t\\label{lem:group_mult_biject}\n\\end{lemma}\n\\begin{exercise}\n\tCheck this by showing injectivity and surjectivity directly.\n\t(If you don't know what these words mean,\n\tconsult \\Cref{ch:sets_functions}.)\n\\end{exercise}\n\\begin{example}\n\tLet $G = \\Zm 7$ (as in \\Cref{def:mult_mod_p}) and pick $g=3$.\n\tThe above lemma states that the map $x \\mapsto 3 \\cdot x$ is a bijection, and we can see this explicitly:\n\t\\begin{align*}\n\t\t1 &\\overset{\\times 3}{\\longmapsto} 3 \\pmod 7 \\\\\n\t\t2 &\\overset{\\times 3}{\\longmapsto} 6 \\pmod 7 \\\\\n\t\t3 &\\overset{\\times 3}{\\longmapsto} 2 \\pmod 7 \\\\\n\t\t4 &\\overset{\\times 3}{\\longmapsto} 5 \\pmod 7 \\\\\n\t\t5 &\\overset{\\times 3}{\\longmapsto} 1 \\pmod 7 \\\\\n\t\t6 &\\overset{\\times 3}{\\longmapsto} 4 \\pmod 7.\n\t\\end{align*}\n\\end{example}\nThe fact that the map is injective is often called the \\vocab{cancellation law}.\n(Why do you think so?)\n\n\\begin{abuse}\n\t[Later on, sometimes the identity is denoted $0$ instead of $1$]\n\tYou don't need to worry about this for a few chapters,\n\tbut I'll bring it up now anyways.\n\tIn most of our examples up until now the operation $\\star$\n\twas thought of like multiplication of some sort,\n\twhich is why $1 = 1_G$ was a natural notation for the identity element.\n\n\tBut there are groups like $\\ZZ = (\\ZZ,+)$\n\twhere the operation $\\star$ is thought of as addition,\n\tin which case the notation $0 = 0_G$ might make more sense instead.\n\t(In general, whenever an operation is denoted $+$,\n\tthe operation is almost certainly commutative.)\n\tWe will eventually start doing so too\n\twhen we discuss rings and linear algebra.\n\\end{abuse}\n\n\\section{Isomorphisms}\n\\prototype{$\\ZZ \\cong 10\\ZZ$.}\nFirst, let me talk about what it means for groups to be isomorphic.\nConsider the two groups\n\\begin{itemize}\n\t\\ii $\\ZZ = (\\left\\{ \\dots,-2,-1,0,1,2,\\dots \\right\\}, +)$.\n\t\\ii $10\\ZZ = (\\left\\{ \\dots, -20, -10, 0, 10, 20, \\dots \\right\\}, +)$.\n\\end{itemize}\nThese groups are ``different'', but only superficially so -- you might even say they only differ in the names of the elements.\nThink about what this might mean formally for a moment.\n\nSpecifically the map\n\\[ \\phi : \\ZZ \\to 10 \\ZZ  \\text{ by } x \\mapsto 10 x \\]\nis a bijection of the underlying sets which respects the group action.\nIn symbols,\n\\[ \\phi(x + y) = \\phi(x) + \\phi(y). \\]\nIn other words, $\\phi$ is a way of re-assigning names of the elements\nwithout changing the structure of the group.\nThat's all just formalism for\ncapturing the obvious fact that $(\\ZZ,+)$\nand $(10 \\ZZ, +)$ are the same thing.\n\nNow, let's do the general definition.\n\\begin{definition}\n\tLet $G = (G, \\star)$ and $H = (H, \\ast)$ be groups.\n\tA bijection $\\phi : G \\to H$ is called an \\vocab{isomorphism} if\n\t\\[ \\phi(g_1 \\star g_2) = \\phi(g_1) \\ast \\phi(g_2) \\quad\n\t\t\\text{for all $g_1, g_2 \\in G$}. \\]\n\tIf there exists an isomorphism from $G$ to $H$,\n\tthen we say $G$ and $H$ are \\vocab{isomorphic} and write $G \\cong H$.\n\\end{definition}\nNote that in this definition, the left-hand side\n$\\phi(g_1 \\star g_2)$ uses the operation of $G$\nwhile the right-hand side $\\phi(g_1) \\ast \\phi(g_2)$\nuses the operation of $H$.\n\n\\begin{example}\n\t[Examples of isomorphisms]\n\tLet $G$ and $H$ be groups. We have the following isomorphisms.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\ZZ \\cong 10 \\ZZ$, as above.\n\t\t\\ii There is an isomorphism\n\t\t\\[ G \\times H \\cong H \\times G\\]\n\t\tby the map $(g,h) \\mapsto (h,g)$.\n\t\t\\ii The identity map $\\id : G \\to G$\n\t\tis an isomorphism, hence $G \\cong G$.\n\t\t\\ii There is another isomorphism of $\\ZZ$ to itself: send every $x$ to $-x$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{example}\n\t[Primitive roots modulo $7$]\n\tAs a nontrivial example, we claim that $\\Zc 6 \\cong \\Zm 7$.\n\tThe bijection is\n\t\\[ \\phi(\\text{$a$ mod $6$}) = \\text{$3^a$ mod $7$}. \\]\n\tTo check that this is an isomorphism, we need to verify several things.\n\t\\begin{itemize}\n\t\t\\ii First, we need to check this map actually makes sense:\n\t\twhy is it the case that if $a \\equiv b \\pmod 6$, then $3^a \\equiv 3^b \\pmod 7$?\n\t\tThe reason is that Fermat's little theorem guarantees that $3^6 \\equiv 1 \\pmod 7$.\n\t\t\\ii Next, we need to check that this map is a bijection.\n\t\tYou can do this explicitly:\n\t\t\\[ (3^1, 3^2, 3^3, 3^4, 3^5, 3^6)\n\t\t\t\\equiv (3,2,6,4,5,1) \\pmod 7. \\]\n\t\t\\ii Finally, we need to verify that this map respects the group action.\n\t\tIn other words, we want to see that\n\t\t$\\phi(a+b) = \\phi(a) \\phi(b)$\n\t\tsince the operation of $\\Zc 6$ is addition\n\t\twhile the operation of $\\Zm 7$ is multiplication.\n\t\tThat's just saying that $3^{a+b} \\equiv 3^a 3^b \\pmod 7$,\n\t\twhich is true.\n\t\\end{itemize}\n\\end{example}\n\\begin{example}\n\t[Primitive roots]\n\tMore generally, for any prime $p$, there exists\n\tan element $g \\in \\Zm p$ called a \\vocab{primitive root} modulo $p$\n\tsuch that $1, g, g^2, \\dots, g^{p-2}$ are all different modulo $p$.\n\tOne can show by copying the above proof that\n\t\\[ \\Zcc{p-1} \\cong \\Zm p \\text{ for all primes $p$}. \\]\n\tThe example above was the special case $p=7$ and $g=3$.\n\\end{example}\n\\begin{exercise}\n\tAssuming the existence of primitive roots,\n\testablish the isomorphism $\\Zcc{p-1} \\cong \\Zm p$ as above.\n\\end{exercise}\n\nIt's not hard to see that $\\cong$ is an equivalence relation (why?).\nMoreover, because we really only care about the structure of groups,\nwe'll usually consider two groups to be the same when they are isomorphic.\nSo phrases such as ``find all groups'' really mean \n``find all groups up to isomorphism''.\n\n\\section{Orders of groups, and Lagrange's theorem}\n\\prototype{$\\Zm p$.}\n\nAs is typical in math, we use the word ``order'' for way too many things.\nIn groups, there are two notions of order.\n\\begin{definition}\n\tThe \\vocab{order of a group} $G$ is the number of elements of $G$.\n\tWe denote this by $\\left\\lvert G \\right\\rvert$.\n\tNote that the order may not be finite, as in $\\ZZ$.\n\tWe say $G$ is a \\vocab{finite group} just to mean that $\\left\\lvert G \\right\\rvert$ is finite.\n\\end{definition}\n\\begin{example}[Orders of groups]\n\tFor a prime $p$, $\\left\\lvert \\Zm p \\right\\rvert = p-1$.\n\tIn other words, the order of $\\Zm p$ is $p-1$.\n\tAs another example,\n\tthe order of the symmetric group $S_n$ is $\\left\\lvert S_n \\right\\rvert = n!$\n\tand the order of the dihedral group $D_{2n}$ is $2n$.\n\\end{example}\n\n\\begin{definition}\n\tThe \\vocab{order of an element} $g \\in G$ is the smallest positive integer $n$\n\tsuch that $g^n = 1_G$, or $\\infty$ if no such $n$ exists.\n\tWe denote this by $\\ord g$.\n\\end{definition}\n\\begin{example}[Examples of orders]\n\tThe order of $-1$ in $\\QQ^\\times$ is $2$,\n\twhile the order of $1$ in $\\ZZ$ is infinite.\n\\end{example}\n\\begin{ques}\n\tFind the order of each of the six elements of $\\Zc 6$,\n\tthe cyclic group on six elements.\n\t(See \\Cref{def:cyclic_group} if you've forgotten what $\\Zc 6$ means.)\n\\end{ques}\n\\begin{example}[Primitive roots]\n\tIf you know olympiad number theory, this coincides with the definition of an order of a residue mod $p$.\n\tThat's why we use the term ``order'' there as well.\n\tIn particular, a primitive root is precisely an element $g \\in \\Zm p$\n\tsuch that $\\ord g = p-1$.\n\\end{example}\nYou might also know that if $x^n \\equiv 1 \\pmod p$,\nthen the order of $x \\pmod p$ must divide $n$.\nThe same is true in a general group for exactly the same reason.\n\\begin{fact}\n\tIf $g^n = 1_G$ then $\\ord g$ divides $n$.\n\\end{fact}\nAlso, you can show that any element\nof a finite group has a finite order.\nThe proof is just an olympiad-style pigeonhole argument.\nConsider the infinite sequence $1_G, g, g^2, \\dots$,\nand find two elements that are the same.\n\\begin{fact}\n\tLet $G$ be a finite group.\n\tFor any $g \\in G$, $\\ord g$ is finite.\n\\end{fact}\n\nWhat's the last property of $\\Zm p$ that you know from olympiad math?\nWe have Fermat's little theorem: for any $a \\in \\Zm p$,\nwe have $a^{p-1} \\equiv 1 \\pmod p$.\nThis is no coincidence:\nexactly the same thing is true in a more general setting.\n\n\\begin{theorem}\n\t[Lagrange's theorem for orders]\n\tLet $G$ be any finite group.\n\tThen $x^{\\left\\lvert G \\right\\rvert} = 1_G$ for any $x \\in G$.\n\\end{theorem}\nKeep this result in mind! We'll prove it later in\nthe generality of \\Cref{thm:lagrange_grp}.\n\n\\section{Subgroups}\n\\prototype{$\\SL_n(\\RR)$ is a subgroup of $\\GL_n(\\RR)$.}\nEarlier we saw that $\\GL_n(\\RR)$, the $n \\times n$ matrices with nonzero determinant, formed a group under matrix multiplication.\nBut we also saw that a subset of $\\GL_n(\\RR)$, namely $\\SL_n(\\RR)$, also formed a group with the same operation.\nFor that reason we say that $\\SL_n(\\RR)$ is a subgroup of $\\GL_n(\\RR)$.\nAnd this definition generalizes in exactly the way you expect.\n\n\\begin{definition}\n\tLet $G = (G, \\star)$ be a group.\n\tA \\vocab{subgroup} of $G$ is exactly what you would expect it to be:\n\ta group $H = (H, \\star)$ where $H$ is a subset of $G$.\n\tIt's a \\vocab{proper subgroup} if $H \\neq G$.\n\\end{definition}\n\n\\begin{remark}\n\tTo specify a group $G$, I needed to tell you both what the set $G$ was and the operation $\\star$ was.\n\tBut to specify a subgroup $H$ of a given group $G$, I only need to tell you who its elements are: the operation of $H$ is just inherited from the operation of $G$.\n\\end{remark}\n\n\\begin{example}\n\t[Examples of subgroups]\n\t\\listhack\n\t\\begin{enumerate}[(a) ]\n\t\t\\ii $2\\ZZ$ is a subgroup of $\\ZZ$, which is isomorphic to $\\ZZ$ itself!\n\t\t\\ii Consider again $S_n$, the symmetric group on $n$ elements.\n\t\tLet $T$ be the set of permutations $\\tau : \\{1, \\dots, n\\} \\to \\{1, \\dots, n\\}$\n\t\tfor which $\\tau(n) = n$.  Then $T$ is a subgroup of $S_n$;\n\t\tin fact, it is isomorphic to $S_{n-1}$.\n\t\t\\ii Consider the group $G \\times H$ (\\Cref{def:product_group})\n\t\tand the elements $ \\left\\{ (g, 1_H) \\mid g \\in G \\right\\} $.\n\t\tThis is a subgroup of $G \\times H$ (why?).\n\t\tIn fact, it is isomorphic to $G$\n\t\tby the isomorphism $(g,1_H) \\mapsto g$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{example}\n\t[Stupid examples of subgroups]\n\tFor any group $G$, the trivial group $\\{1_G\\}$\n\tand the entire group $G$ are subgroups of $G$.\n\\end{example}\n%\\begin{example}\n%\t[Center of a Group]\n%\tLet $G$ be a group.\n%\tIts \\vocab{center}, denoted $Z(G)$, is the set $x \\in G$ such that\n%\t$gx = xg$ for every $g \\in G$; in other words, it is the set of\n%\t$x \\in G$ which commute with every element of $G$.\n%\\end{example}\n%You can check the center is indeed a group (some boring details\\dots).\n\nNext is an especially important example that we'll talk about more in later chapters.\n\\begin{example}[Subgroup generated by an element]\n\tLet $x$ be an element of a group $G$.\n\tConsider the set\n\t\\[ \\left<x\\right> = \\left\\{ \\dots, x^{-2}, x^{-1}, 1, x, x^2, \\dots \\right\\}. \\]\n\tThis is also a subgroup of $G$, called the subgroup generated by $x$.\n\\end{example}\n\\begin{exercise}\n\tIf $\\ord x = 2015$, what is the above subgroup equal to?\n\tWhat if $\\ord x = \\infty$?\n\\end{exercise}\n\nFinally, we present some non-examples of subgroups.\n\\begin{example}[Non-examples of subgroups]\n\tConsider the group $\\ZZ = (\\ZZ, +)$.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The set $\\left\\{ 0,1,2,\\dots \\right\\}$ is\n\t\tnot a subgroup of $\\ZZ$ because it does not contain inverses.\n\t\t\\ii The set $\\{ n^3 \\mid n \\in \\ZZ \\}\n\t\t= \\{ \\dots, -8, -1, 0, 1, 8, \\dots \\}$ is not a subgroup\n\t\tbecause it is not closed under addition;\n\t\tthe sum of two cubes is not in general a cube.\n\t\t\\ii The empty set $\\varnothing$ is not a subgroup\n\t\tof $\\ZZ$ because it lacks an identity element.\n\t\\end{enumerate}\n\\end{example}\n\n\\section{Groups of small orders}\nJust for fun, here is a list of all groups of order less than or equal to ten\n(up to isomorphism, of course).\n\\begin{enumerate}\n\t\\ii The only group of order $1$ is the trivial group.\n\t\\ii The only group of order $2$ is $\\Zc 2$.\n\t\\ii The only group of order $3$ is $\\Zc 3$.\n\t\\ii The only groups of order $4$ are\n\t\\begin{itemize}\n\t\t\\ii $\\Zc 4$, the cyclic group on four elements,\n\t\t\\ii $\\Zc 2 \\times \\Zc 2$, called the Klein Four Group.\n\t\\end{itemize}\n\t\\ii The only group of order $5$ is $\\Zc 5$.\n\t\\ii The groups of order six are\n\t\\begin{itemize}\n\t\t\\ii $\\Zc 6$, the cyclic group on six elements.\n\t\t\\ii $S_3$, the permutation group of three elements.\n\t\tThis is the first non-abelian group.\n\t\\end{itemize}\n\tSome of you might wonder where $\\Zc 2 \\times \\Zc 3$ is.\n\tAll I have to say is: Chinese remainder theorem!\n\n\tYou might wonder where $D_6$ is in this list.\n\tIt's actually isomorphic to $S_3$.\n\t\\ii The only group of order $7$ is $\\Zc 7$.\n\t\\ii The groups of order eight are more numerous.\n\t\\begin{itemize}\n\t\t\\ii $\\Zc 8$, the cyclic group on eight elements.\n\t\t\\ii $\\Zc 4 \\times \\Zc 2$.\n\t\t\\ii $\\Zc 2 \\times \\Zc 2 \\times \\Zc 2$.\n\t\t\\ii $D_8$, the dihedral group with eight elements, which is not abelian.\n\t\t\\ii A non-abelian group $Q_8$, called the \\emph{quaternion group}.\n\t\tIt consists of eight elements $\\pm 1$, $\\pm i$, $\\pm j$, $\\pm k$\n\t\twith $i^2=j^2=k^2=ijk=-1$.\n\t\\end{itemize}\n\t\\ii The groups of order nine are\n\t\\begin{itemize}\n\t\t\\ii $\\Zc 9$, the cyclic group on nine elements.\n\t\t\\ii $\\Zc 3 \\times \\Zc 3$.\n\t\\end{itemize}\n\t\\ii The groups of order $10$ are\n\t\\begin{itemize}\n\t\t\\ii $\\Zc{10} \\cong \\Zc5 \\times \\Zc2$ (again Chinese remainder theorem).\n\t\t\\ii $D_{10}$, the dihedral group with $10$ elements.\n\t\tThis group is non-abelian.\n\t\\end{itemize}\n\\end{enumerate}\n\n\\section{Unimportant long digression}\nA common question is: why these axioms?\nFor example, why associative but not commutative?\nThis answer will likely not make sense until later,\nbut here are some comments that may help.\n\nOne general heuristic is:\nWhenever you define a new type of general object,\nthere's always a balancing act going on.\nOn the one hand, you want to include enough constraints that your\nobjects are ``nice''.\nOn the other hand, if you include too many constraints,\nthen your definition applies to too few objects.\n\nSo, for example, we include ``associative''\nbecause that makes our lives easier\nand most operations we run into are associative.\nIn particular, associativity is required for the inverse\nof an element to necessarily be unique.\nHowever we don't include ``commutative'', because examples below\nshow that there are lots of non-abelian groups we care about.\n(But we introduce another name ``abelian''\nbecause we still want to keep track of it.)\n\nAnother comment: a good motivation for the inverse axioms\nis that you get a large amount of \\emph{symmetry}.\nThe set of positive integers with addition is not a group,\nfor example, because you can't subtract $6$ from $3$:\nsome elements are ``larger'' than others.\nBy requiring an inverse element to exist, you get rid of this issue.\n(You also need identity for this;\nit's hard to define inverses without it.)\n\nEven more abstruse comment:\n\\Cref{thm:cayley_theorem} shows that groups are actually shadows of\nthe so-called symmetric groups (defined later, also called permutation groups).\nThis makes rigorous the notion that ``groups are very symmetric''.\n\n\\section{\\problemhead}\n\n\\begin{problem}\n\tWhat is the joke in the following figure? (Source: \\cite{img:snsd}.)\n\t\\begin{center}\n\t\t\\includegraphics[height=8cm]{media/love-proper-isomorphic-subgroup.jpg}\n\t\t%\\caption{$\\heartsuit$ is a group, $G \\subsetneq \\heartsuit$ a subgroup and $G \\cong \\heartsuit$.}\n\t\\end{center}\n\t\\begin{hint}\n\t\tOrders.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThe point is that $\\heartsuit$ is a group, $G \\subsetneq \\heartsuit$ a subgroup and $G \\cong \\heartsuit$.\n\t\tThis can only occur if $\\left\\lvert \\heartsuit \\right\\rvert = \\infty$;\n\t\totherwise, a proper subgroup would have strictly smaller size than the original.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\tProve Lagrange's theorem for orders in the special case\n\tthat $G$ is a finite abelian group.\n\t\\begin{hint}\n\t\tCopy the proof of Fermat's little theorem, using\n\t\t\\Cref{lem:group_mult_biject}.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tLet $\\{g_1, g_2, \\dots, g_n\\}$ denote the elements of $G$.\n\t\tFor any $g \\in G$, this is the same as the set $\\{gg_1, \\dots, gg_n\\}$.\n\t\tTaking the entire product and exploiting commutativity gives\n\t\t$g^n \\cdot g_1g_2 \\dots g_n = g_1g_2 \\dots g_n$, hence $g^n=1$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\tShow that $D_6 \\cong S_3$ but $D_{24} \\not\\cong S_4$.\n\t\\begin{hint}\n\t\tFor the former,\n\t\tdecide where the isomorphism should send $r$ and $s$,\n\t\tand the rest will follow through.\n\t\tFor the latter, look at orders.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tOne can check manually that $D_6 \\cong S_3$,\n\t\tusing the map $r \\mapsto (1 \\; 2 \\; 3)$ and $s \\mapsto (1 \\; 2)$.\n\t\t(The right-hand sides are in ``cycle notation'',\n\t\tas mentioned in \\Cref{subsec:cycle_notation}.)\n\t\tOn the other hand $D_{24}$ contains an element of order $12$\n\t\twhile $S_4$ does not.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{sproblem}\n\tLet $p$ be a prime.\n\tShow that the only group of order $p$ is $\\Zc p$.\n\t\\begin{hint}\n\t\tGenerated groups.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tLet $G$ be a group of order $p$, and $1 \\neq g \\in G$.\n\t\tLook at the group $H$ generated by $g$ and use Lagrange's theorem.\n\t\\end{sol}\n\\end{sproblem}\n\n\\begin{problem}\n\t[A hint for Cayley's theorem]\n\tFind a subgroup $H$ of $S_8$\n\twhich is isomorphic to $D_8$,\n\tand write the isomorphism explicitly.\n\\end{problem}\n\n\\begin{dproblem}\n\t\\gim\n\tLet $G$ be a finite group.\\footnote{In other words,\n\t\tpermutation groups can be arbitrarily weird.\n\t\tI remember being highly unsettled\n\t\tby this theorem when I first heard of it,\n\t\tbut in hindsight it is not so surprising.}\n\tShow that there exists a positive integer $n$ such that\n\t\\begin{enumerate}[(a)]\n\t\t\\ii (Cayley's theorem) $G$ is isomorphic to some subgroup of the symmetric group $S_n$.\n\t\t\\ii (Representation Theory) $G$ is isomorphic to some subgroup of\n\t\tthe general linear group $\\GL_n(\\RR)$.\n\t\t(This is the group of invertible $n \\times n$ matrices.)\n\t\\end{enumerate}\n\t\\label{thm:cayley_theorem}\n\t\\begin{hint}\n\t\tUse $n = \\left\\lvert G \\right\\rvert$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThe idea is that each element $g \\in G$ can be thought of as a permutation\n\t\t$G \\to G$ by $x \\mapsto gx$.\n\t\\end{sol}\n\\end{dproblem}\n\n\\begin{problem}\n\t[IMO SL 2005 C5] \\gim\n\tThere are $n$ markers, each with one side white and the other side black.\n\tIn the beginning, these $n$ markers are aligned in a row so that their white sides are all up.\n\tIn each step, if possible, we choose a marker whose white side is up\n\t(but not one of the outermost markers),\n\tremove it, and reverse the closest marker to the left of it\n\tand also reverse the closest marker to the right of it.\n\t\n\tProve that if $n \\equiv 1 \\pmod 3$ it's impossible to reach a state\n\twith only two markers remaining.\n\t(In fact the converse is true as well.)\n\t% http://www.artofproblemsolving.com/Forum/viewtopic.php?f=41&t=90046&p=3573800\n\t\\begin{hint}\n\t\tDraw inspiration from $D_6$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tWe have $www = bb$, $bww = wb$, $wwb = bw$, $bwb = ww$.\n\t\tInterpret these as elements of $D_6$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t\\gim\n\tLet $p$ be a prime and $F_1 = F_2 = 1$, $F_{n+2} = F_{n+1} + F_n$\n\tbe the Fibonacci sequence.\n\tShow that $F_{2p(p^2-1)}$ is divisible by $p$.\n\t\\begin{hint}\n\t\tLook at the group of $2 \\times 2$ matrices mod $p$\n\t\twith determinant $\\pm 1$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tLook at the group $G$ of $2 \\times 2$ matrices mod $p$\n\t\twith determinant $\\pm 1$ (whose entries are the integers mod $p$).\n\t\tLet $g = \\begin{bmatrix} 1 & 1 \\\\ 1 & 0 \\end{bmatrix}$\n\t\tand then use $g^{\\left\\lvert G \\right\\rvert} = 1_G$.\n\t\\end{sol}\n\\end{problem}\n\n%\\begin{problem}[Hard]\n%\tExhibit two groups $G$ and $H$ which are not isomorphic with the property that\n%\tfor every positive integer $n$,\n%\tthe number of elements $g \\in G$ with $\\ord g = n$\n%\tequals the number of elements $h \\in H$ with $\\ord h = n$.\n%\\end{problem}\n", "meta": {"hexsha": "8cd75c83fc895719019f18345299e2459a3966ae", "size": 31789, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/H113/grp-intro.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/H113/grp-intro.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/H113/grp-intro.tex", "max_forks_repo_name": "aDotInTheVoid/ltxmk", "max_forks_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2079326923, "max_line_length": 164, "alphanum_fraction": 0.6855516059, "num_tokens": 10448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.8991213684847575, "lm_q1q2_score": 0.8031935730980357}}
{"text": "\\subsection{Circles}\r\n\\noindent\r\nYou should already recognize $x^2 + y^2 = r^2$ as the equation of a circle with radius $r$ centered at the origin.\r\nA circle as a VVF in $\\R^2$ is $\\vec{r}(t) = \\langle r\\cos{t}, r\\sin{t} \\rangle$, which is identical to the parametric form of a circle.\r\nIn $\\mathbb{R}^3$, the z-component is some constant that tells us which plane, $z=c$, the circle is in.\r\nWe can also have circles parallel to $x=0$ and $y=0$ planes by changing the positions of the $\\sin$, $\\cos$, and $c$ terms.\r\nFor example, $\\vec{r}(t) = \\langle \\cos{t}, c, \\sin{t} \\rangle$ is a circle in the $y=c$ plane.", "meta": {"hexsha": "42c12ca622b20f93e12c9ff3d539f338210e70f1", "size": 612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/circles.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorValuedFunctions/circles.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorValuedFunctions/circles.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 87.4285714286, "max_line_length": 137, "alphanum_fraction": 0.6748366013, "num_tokens": 200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007597, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.8030731256759838}}
{"text": "\\section{The Least Mean Square (LMS) Algorithm}\n\n\\begin{enumerate}[label=\\alph*), leftmargin=*]\n\n%% a)\n\\item\n%\n\nA general AR(2) process $x(n)$ with parameters $a_{1}, a_{2}$ satisfies the difference equation:\n\n\\begin{equation}\n    x(n) = a_{1} x(n - 1) + a_{2} x(n - 2) + \\eta(n)\n\\label{eq:ar_2}\n\\end{equation}\n\nwhere $\\eta(n) \\sim \\mathcal{N}(0, \\sigma_{\\eta}^{2})$. The Least Mean Square (LMS) algorithm is used to approximate\nthe autoregressive parameters $a_{1}, a_{2}$ from data, treating $\\mathbf{x}(n) = [x(n-1), x(n-2)]^{T}$ and\n$y(n) = x(n)$ as the input (features) vector and the output (target), respectively.\n\nThe correlation matrix $\\mathbf{R}_{xx}$ of the input vector $\\mathbf{x}(n)$ is given by:\n\n\\begin{equation}\n    \\mathbf{R}_{xx} = \\E[\\mathbf{x}(n) \\mathbf{x}^{T}(n)] = \\E\n    \\begin{bmatrix}\n        x(n-1) x(n-1) & x(n-1) x(n-2) \\\\\n        x(n-1) x(n-2) & x(n-2) x(n-2)\n    \\end{bmatrix} =\n    \\begin{bmatrix}\n        r_{xx}(0) & r_{xx}(1) \\\\\n        r_{xx}(1) & r_{xx}(0)\n    \\end{bmatrix}\n\\label{eq:cov_ar_2}\n\\end{equation}\n\nwhere $r_{xx}(k)$ the autocorrelation function (ACF) of $x(n)$. To obtain the ACF of the AR(2) process, multiply equation (\\ref{eq:ar_2}) by $x(n-k)$ and take expectations:\n\n\\begin{align}\n    r_{xx}(k) = \\E[ x(n) x(n-k) ]   &= \\E \\bigg[ a_{1} x(n - 1) x(n-k) + a_{2} x(n - 2) x(n-k) + \\eta(n) x(n-k) \\bigg] \\nonumber\\\\\n    r_{xx}(k) = \\E[ x(n) x(n-k) ]   &= a_{1} \\E \\big[ x(n - 1) x(n-k) \\big] + a_{2} \\E \\big[ x(n - 2) x(n-k) \\big] + \\E \\big[ \\eta(n) x(n-k) \\big]\n\\end{align}\n\nNotice that $\\E [\\eta(n) x(n-k)]$ vanishes when $k > 0$, then:\n\n\\begin{align}\n    r_{xx}(0)   &= a_{1} r_{xx}(1) + a_{2} r_{xx}(2) + \\sigma_{\\eta}^{2} \\\\\n    r_{xx}(k)   &= a_{1} r_{xx}(k-1) + a_{2} r_{xx}(k-2), k > 0\n\\label{eq:acf_ar_2}\n\\end{align}\n\nNote that ACF is an even function or equivalently $r_{xx}(-k) = r_{xx}(k), \\forall k \\in \\sZ$, thus using the true process parameters $a_{1} = 0.1$, $a_{2} = 0.8$\nand $\\sigma_{\\eta}^{2} = 0.25$, we obtain the three simultaneous equations with three unknowns:\n\n\\begin{align}\n    r_{xx}(0)   &= a_{1} r_{xx}(1) + a_{2} r_{xx}(2) + \\sigma_{\\eta}^{2} \\\\\n    r_{xx}(1)   &= a_{1} r_{xx}(0) + a_{2} r_{xx}(-1) = a_{1} r_{xx}(0) + a_{2} r_{xx}(1) \\\\\n    r_{xx}(2)   &= a_{1} r_{xx}(1) + a_{2} r_{xx}(0)\n\\end{align}\n\nwith the unique solution $r_{xx}(k) = [\\frac{25}{27}, \\frac{25}{54}, \\frac{85}{108}]$ for $k=1, 2, 3$.\n\nHence by substitution in equation (\\ref{eq:cov_ar_2}) we obtain the  correlation matrix of the input vector $\\mathbf{x}(n)$:\n\n\\begin{equation}\n    \\mathbf{R}_{xx} = \n    \\frac{25}{54}\n    \\begin{bmatrix}\n        2 & 1 \\\\\n        1 & 2\n    \\end{bmatrix}\n\\label{eq:cov_ar_2_result}\n\\end{equation}\n\nConvergence of the LMS algorithm depends on the step size $\\mu$, which should satisfy:\n\n\\begin{equation}\n    0 < \\mu < \\frac{2}{\\lambda_{max}}\n\\label{cond:mu_max}\n\\end{equation}\n\nwhere $\\lambda_{max}$ the largest eigenvalue of the correlation matrix $\\mathbf{R}_{xx}$. Performing the eigendecomposition of $\\mathbf{R}_{xx}$, we obtain\n$\\lambda_{1} = 0.4630$ and $\\lambda_{2} = \\lambda_{max} = 1.3889$ and as a result, convergence to the Wiener optimal solution is guaranteed for:\n\n\\begin{equation}\n    0 < \\mu < 1.44\n\\label{cond:mu_max_val}\n\\end{equation}\n\n%% b)\n\\item\n%\n\nThe LMS algorithm is implemented and tested on $N=1000$ samples of 100 different realisations of $x(n)$ process. The squared prediction error over time\nfor one and the average of the 100 realisations is provided at figure \\ref{fig:3_1_b} for two different step-sizes $\\mu_{1} = 0.01$ and $\\mu_{2} = 0.05$.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/the-least-mean-square-algorithm/assets/b/squared_prediction_error_1}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/adaptive-signal-processing/the-least-mean-square-algorithm/assets/b/squared_prediction_error_ens}\n    \\end{subfigure}\n    \\caption{LMS: squared prediction error over time and $\\mu$ convergence rate.}\n    \\label{fig:3_1_b}\n\\end{figure}\n\nConcentrating on the averaged of 100 realisation prediction error (reduced variance of estimate), we notice that the larger step-size $\\mu_{2} = 0.05$ converges\nwithin 50 timesteps, while $\\mu_{1}$ converges in 200 timesteps, verifying the theoretical argument that larger $\\mu$ values allow steeper decent of the error surface,\nas long as the condition (\\ref{cond:mu_max_val}) is satisfied. Nonetheless, fast convergence is traded with larger oscillations around the true parameter values,\nmotivating the use of an adaptive step-size, which decays over time.\n\n%% c)\n\\item\n%\n\nThe theoretical Misadjustment, $\\mathcal{M}_{LMS}$, of the LMS algorithm is obtained by the approximation formula:\n\n\\begin{equation}\n    \\mathcal{M}_{LMS} \\approx \\frac{\\mu}{2} Tr\\{ \\mathbf{R}_{xx} \\} = \\frac{\\mu}{2} 1.8519\n\\end{equation}\n\nwhere $\\mathbf{R}_{xx}$ from (\\ref{eq:cov_ar_2_result}) is used.\n\nAccording to figure \\ref{fig:3_1_b} the squared prediction error plateaus for both $\\mu$ values after $t > 200$. To guarantee that a steady-state has been reached,\nwe time average the squared prediction error for $t_{0} > 500$, in order to obtain a Mean Squared Error (MSE) estimate. The empirical misadjustment, $\\mathcal{M}_{emp}$,\nis then obtained using the formula:\n\n\\begin{equation}\n    \\mathcal{M}_{emp} = \\frac{\\mathtt{MSE}}{\\sigma_{\\eta}^{2}} - 1\n\\end{equation}\n\nTable \\ref{tab:3_1_c} summarises the empirical and theoretical misadjustments of the simple LMS algorithm for the $x(n)$ process.\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{|c|c|c|}\n\\hline\n$\\boldsymbol{\\mu}$ & $\\mathcal{M}_{LMS}$ & $\\mathcal{M}_{emp}$ \\\\\n\\hline\n\\hline\n$0.01$ & $0.0093$ & $0.00766$ \\\\\n\\hline\n$0.05$ & $0.0463$ & $0.04912$ \\\\\n\\hline\n\\end{tabular}\n\\caption{LMS: empirical and theoretical approximation of misadjustment comparison matrix.}\n\\label{tab:3_1_c}\n\\end{table}\n\n%% d)\n\\item\n%\n\nThe evolution of the LMS filter coefficients over time is shown in figure \\ref{fig:3_1_d}, along with the true AR(2) process parameters, for step-sizes $\\mu_{1} = 0.01$ and $\\mu_{2} = 0.05$.\nThe illustrated curves represent the average of the coefficients of 100 independently trained LMS filters on different realisations of the same $x(n)$ stochastic process.\n\nClearly, for both $\\mu$ values, $\\hat{a}_{1}$ coefficient converges to the true $a_{1}$ parameter, while the second coefficient $\\hat{a}_{2}$ has a negative offset\n($3.75\\%$ for $\\mu_{1} = 0.01$ and $10\\%$ for $\\mu_{2} = 0.05$). Moreover, we note that a larger step-size (i.e $\\mu_{2}$) compromises oscillations around the true values and a greater offset\nfor faster convergence. In more detail, within 200 timesteps $\\mu_{1}$ reaches the $10\\%$ error bounds, while $\\mu_{2}$ needs 350 timesteps.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/adaptive-signal-processing/the-least-mean-square-algorithm/assets/d/weights_evolution-mu_0.01}.pdf}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/adaptive-signal-processing/the-least-mean-square-algorithm/assets/d/weights_evolution-mu_0.05}.pdf}\n    \\end{subfigure}\n    \\caption{LMS: steady state values of the adaptive filter coefficients for different step-sizes $\\mu$.}\n    \\label{fig:3_1_d}\n\\end{figure}\n\n%% e)\n\\item\n%\n\nLet the objective function $\\mathcal{J}_{2}$, such that:\n\n\\begin{equation}\n    \\mathcal{J}_{2}(n) = \\frac{1}{2} \\bigg( e^{2}(n) + \\gamma \\| \\vw(n) \\|_{2}^{2} \\bigg)\n\\label{eq:J_2}\n\\end{equation}\n\nExpressing the error term, $e(n)$, in terms of the input vector $\\mathbf{x}_{n}$ and the target value $y_{n}$:\n\n\\begin{align}\n    \\mathcal{J}_{2}(n)  &= \\frac{1}{2} \\bigg( \\| y(n) - \\vw(n)^{T} \\mathbf{x}(n) \\|_{2}^{2} + \\gamma \\| \\vw(n) \\|_{2}^{2} \\bigg) \\\\\n    \\mathcal{J}_{2}(n)  &= \\frac{1}{2} \\bigg( \\big( y(n) - \\vw(n)^{T} \\mathbf{x}(n))^{T} (y(n) - \\vw(n)^{T} \\mathbf{x}(n) \\big) + \\gamma \\vw(n)^{T} \\vw(n) \\bigg)\n\\end{align}\n\nCalculating the gradient of the objective function, $\\nabla_{\\vw} \\mathcal{J}_{2}$, with respect to the weights $\\vw$:\n\n\\begin{align}\n    \\nabla_{\\vw} \\mathcal{J}_{2}(n) &= - ( y(n) - \\vw(n)^{T} \\mathbf{x}(n) ) \\mathbf{x}(n) + \\gamma \\vw(n) \\\\\n    \\nabla_{\\vw} \\mathcal{J}_{2}(n) &= - e(n) \\mathbf{x}(n) + \\gamma \\vw(n)\n\\end{align}\n\nApplying the gradient descent update to weights $\\vw$ to minimise the objective function $\\mathcal{J}_{2}$:\n\n\\begin{align}\n    \\vw(n + 1)  &= \\vw(n) - \\mu \\nabla_{\\vw} \\mathcal{J}_{2}(n) \\\\\n    \\vw(n + 1)  &= \\vw(n) - \\mu \\big( - e(n) \\mathbf{x}(n) + \\gamma \\vw(n) \\big) \\\\\n    \\vw(n + 1)  &= (1 - \\mu \\gamma) \\vw(n) + \\mu e(n) \\mathbf{x}(n)\n\\label{eq:leaky_lms}\n\\end{align}\n\nHence we proved that the Leaky LMS algorithm following the update rule in (\\ref{eq:leaky_lms}) is equivalent to the minimisation of the objective function $\\mathcal{J}_{2}$\ndefined in (\\ref{eq:J_2}).\n\n%% f)\n\\item\n%\n\nIn figure \\ref{fig:3_1_f} the Leaky LMS filter coefficients for different leakage coefficient $\\gamma$ and step-sizes $\\mu$\nare provided, against the true AR(2) process parameters.\n\nThe predicted filter coefficients do not converge to the true parameters, and increasing $\\gamma$ values introduce\na greater bias between the estimates and the process autoregressive parameters.\n\nThe offline, non-adaptive but optimal solution to this linear system is the Wiener filter, which has access to all the\nobserved samples and relies on the construction of the autocorrelation matrix, $\\mathbf{R} = \\E [ \\mathbf{X} \\mathbf{X}^{T} ]$,\nand the crosscorrelation vector (between desired output value and input vector), $\\mathbf{p}$, then the optimal filter weights,\n$\\vw_{*}$, are given by:\n\n\\begin{equation}\n    \\vw_{*} = \\mathbf{R}^{-1} \\vp\n\\end{equation}\n\nwhere $\\mathbf{R}$ needs to be invertible. The LMS algorithm can be shown to converge to this solution if (\\ref{cond:mu_max})\nis true. Invertibility of the autocorrelation matrix is not guaranteed, since it is positive semi-definite and not strictly\npositive definite. The Leaky LMS algorithm can be shown to converge to the solution:\n\n\\begin{equation}\n    \\vw_{reg} = (\\mathbf{R} + \\gamma \\mathbf{I})^{-1} \\vp\n\\end{equation}\n\nwhere the leakage coefficient $\\gamma > 0$ acts as a regularization parameter ensuring invertibility of the \"modified\"\nautocorrelation matrix $(\\mathbf{R} + \\gamma \\mathbf{I})$. Nonetheless, this is a common example of bias-variance trade-off\nsince larger values of $\\gamma$ introduce bias but penalise variance of estimates\n(due to the $L_{2}$ norm term in $\\mathcal{J}_{2}$).\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/adaptive-signal-processing/the-least-mean-square-algorithm/assets/f/weights_evolution-mu_0.01-gamma_0.2}.pdf}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/adaptive-signal-processing/the-least-mean-square-algorithm/assets/f/weights_evolution-mu_0.05-gamma_0.2}.pdf}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/adaptive-signal-processing/the-least-mean-square-algorithm/assets/f/weights_evolution-mu_0.01-gamma_0.6}.pdf}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/adaptive-signal-processing/the-least-mean-square-algorithm/assets/f/weights_evolution-mu_0.05-gamma_0.6}.pdf}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/adaptive-signal-processing/the-least-mean-square-algorithm/assets/f/weights_evolution-mu_0.01-gamma_1.0}.pdf}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/adaptive-signal-processing/the-least-mean-square-algorithm/assets/f/weights_evolution-mu_0.05-gamma_1.0}.pdf}\n    \\end{subfigure}\n    \\caption{Leaky LMS: filter weights evolution for different leakage coefficient $\\gamma$.}\n    \\label{fig:3_1_f}\n\\end{figure}\n\n%\n\\end{enumerate}", "meta": {"hexsha": "71eb49605885075a69b801c2c102bce141c5ffb3", "size": 12357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/adaptive-signal-processing/the-least-mean-square-algorithm/index.tex", "max_stars_repo_name": "filangel/ASPMI", "max_stars_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-02-20T14:43:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-13T21:13:02.000Z", "max_issues_repo_path": "tex/report/adaptive-signal-processing/the-least-mean-square-algorithm/index.tex", "max_issues_repo_name": "AmjadHisham/ASPMI", "max_issues_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/report/adaptive-signal-processing/the-least-mean-square-algorithm/index.tex", "max_forks_repo_name": "AmjadHisham/ASPMI", "max_forks_repo_head_hexsha": "9d985f50787f0b9a3ccf1c6537c0cb6b0d9d8cce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-07-17T08:32:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-12T18:26:18.000Z", "avg_line_length": 43.2062937063, "max_line_length": 191, "alphanum_fraction": 0.6703892531, "num_tokens": 4185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.9241418241572634, "lm_q1q2_score": 0.8029191744247303}}
{"text": "\\newpage\n\\section[Numerical Sequences and Series]{\\hyperlink{toc}{Numerical Sequences and Series}}\n\\subsection{Sequences}\nWe begin by formally defining a sequence.\n\\begin{ndef}{: Sequences}{}\n    Let $X$ be a metric space. A \\textbf{sequence} is a function $f: \\NN \\mapsto X$. We can denote a term in the sequence as $f(n) = x_n$, or the entire sequence as $\\set{x_n}_{n=1}^\\infty$, $\\set{x_n}$, $(x_n)$, or $\\set{x_1, x_2, x_3 \\ldots}$. \n\\end{ndef}\n\\noindent We now discuss the notion of convergence of a sequence. Intuitively, we can equate convergence with the notion of points getting closer together.\n\\begin{definition}{Convergence of Sequences}{3.1}\n    A sequence $\\set{p_n}_{n=1}^\\infty$ \\textbf{converges} to $p \\in X$ if for all $\\e > 0$, there exists $N \\in \\NN$ such that $n \\geq N$ implies $d(p_n, p) < \\e$. In this case, we say that $\\set{p_n}$ converges to $p$, or that $p$ is the limit of $\\set{p_n}$, and denote this as $p_n \\rightarrow p$ or $\\lim_{n \\rightarrow \\infty} p_n = p$. If $\\set{p_n}$ does not converge, we say it \\textbf{diverges}.\n\\end{definition}\n\\noindent To phrase this definition in another way, we fix some $\\e > 0$, and then we have that all points in the sequence past some $N \\in \\NN$ are contained in the neighbourhood $N_\\e(p)$. In practice, it can be difficult to apply this definition of convergence if we don't know what the limiting $p$ is, as the definition implicitly uses the value of the limit. We will later discuss another definition of convergence (in $\\RR^k$) that does not use the value of the limit.\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}[mycirc/.style={circle,fill, minimum size=0.15cm, inner sep = 0pt}]\n        \\draw[red, dotted, thick, fill = white!60!red] (-1, 0) circle (30pt);\n        \\node[mycirc, label=above:{$p$}, fill = red] at (-1, 0) {};\n        \\node[mycirc, label=above:{$p_1$}] at (1.5, 0) {};\n        \\node[mycirc, label=above:{$p_2$}] at (1, -0.25) {};\n        \\node[mycirc, label=above:{$p_3$}] at (0.5, -0.5) {};\n        \\node[mycirc, label=above:{$p_4$}] at (0, -0.5) {};\n        \\node[mycirc, label=above:{$p_5$}] at (-0.35, -0.4) {};\n        \\node[mycirc] at (-0.65, -0.2) {};\n        \\node[mycirc] at (-0.75, -0.15) {};\n        \\node[mycirc] at (-0.85, -0.1) {};\n        \\node[mycirc] at (-0.95, -0.05) {};\n        \\draw[<->] (-1.08, 0) -- (-2.05, 0);\n        \\node[label=above:{$\\e$}] at (-1.5, -0.15) {};\n    \\end{tikzpicture}\n    \\caption{Visualization of a sequence $\\set{p_n} \\subset \\RR^2$ converging to a point $p$. For the $\\e > 0$ shown in the picture, we have that all points of the sequence past $N = 5$ lie in the open disk of radius $\\e$ around $p$.}\n    \\label{fig15}\n\\end{figure}\n\n\\noindent As a remark, consider that convergence can depend on our choice of metric space; for example, $\\set{\\frac{1}{n}}$ as a sequence in $\\RR$ converges to $0$, but the same sequence in the strictly positive reals ($\\RR^+ = \\set{x \\in \\RR: x > 0}$) does not converge.\n\nAnother interesting example (that again shows us the importance of the choice of metric space). Is $\\RR$ equipped with the discrete metric. A question we can ask is ``given some points $p \\in \\RR$, what sequences converge to $p$?'' The answer turns out to be eventually constant sequences only; that is, sequences for which $p_n = p$ for $n \\geq N$ for some $N$. \n\\begin{proof}\n    If $p_n \\rightarrow p$, then setting $\\e = \\frac{1}{2}$, we have that there exists $N \\in NN$ such that for all $n \\geq N$, $d(p_n, p) < \\e = \\frac{1}{2}$. Under the discrete metric, this is only possible if $p_n = p$. \n\\end{proof}\nThis of course is a strikingly different picture for $\\RR$ with the standard metric of $d(x, y) = \\abs{x - y}$. For example, the sequnce $p_n = \\frac{1}{n}$ has no term equal to zero, but converges to $p = 0$. The takeaway message here can be that in the Euclidean metric, points can ``get closer'' but in the discrete metric, they cannot.\n\n\\stepcounter{rudin}\n\\begin{theorem}{}{3.3}\n    Suppose $\\set{s_n}, \\set{t_n}$ are complex sequences that converge, with $\\linf s_n \\rightarrow s$ and $\\linf t_n \\rightarrow t$. Then:\n    \\begin{enumerate}\n        \\item $\\linf(s_n + t_n) = s + t$.\n        \\item $\\linf cs_n = cs$ and $\\linf (c + s_n) = c + s$ for all $c \\in \\CC$.\n        \\item $\\linf s_nt_n = st$\n        \\item $\\linf \\frac{1}{s_n} = \\frac{1}{s}$ provided $s \\neq 0$ and $s_n \\neq 0$ for all $n$.\n    \\end{enumerate}\n\\end{theorem}\n\\begin{nproof}\n    \\begin{enumerate}\n        \\item Let $\\e > 0$. There exist $N_1, N_2 \\in \\NN$ such that $\\abs{s_{n_1} - s} < \\frac{\\e}{2}$ for $n_1 \\geq N_1$ and $\\abs{t_{n_2} - t} < \\frac{\\e}{2}$ for $n_2 \\geq N_2$. Take $N = \\max{N_1, N_2}$, and using the triangle inequality, it follows that for $n \\geq N$:\n        \\begin{align*}\n            \\abs{(s_n + t_n) - (s + t)} \\leq \\abs{s_n - s} + \\abs{t_n - t} < \\frac{\\e}{2} + \\frac{\\e}{2} = \\e\n        \\end{align*} \n        We conclude that $\\linf (s_n + t_n) = s + t$. \n        \\item Let $\\e > 0$. If $c = 0$ then the first sequence trivially converges to $0$, so suppose that $c \\neq 0$. There exists $N$ such that $\\abs{s_n - s} < \\frac{\\e}{\\abs{c}}$ for $n \\geq N$, so it follows that:\n        \\begin{align*}\n            \\abs{cs_n - cs} = \\abs{c}\\abs{s_n - s} < \\abs{c}\\frac{\\e}{\\abs{c}} = \\e.\n        \\end{align*} For the second identity, we have that $c_n \\rightarrow c$ for any constant sequence $c_n = c$ so we may apply (a).\n        \\item Let $\\e > 0$. There exist $N_1, N_2$ such that $\\abs{s_{n_1} - s} < \\sqrt{2}$ for $n_1 \\geq N_1$ and $\\abs{t_{n_2} - t} < \\sqrt{2}$ for $n_2 \\geq N_2$. We then consider that:\n        \\begin{align*}\n        s_nt_n - st = (s_n - s)(t_n - t) + s(t_n - t) + t(s_n - s)\n        \\end{align*}\n        For $n \\geq N = \\max{N_1, N_2}$, we have that:\n        \\begin{align*}\n            (s_n - s)(t_n - t) < \\e\n        \\end{align*}\n        And we hence observe that $\\linf (s_n - s)(t_n - t) = 0$. We can then use (a) and (b) to find that:\n        \\begin{align*}\n            \\linf s(t_n - t) = 0, \\quad \\linf t(s_n - s) = 0\n        \\end{align*}\n        So we conclude that $\\linf (s_nt_n - st) = 0$ and hence $s_nt_n \\rightarrow st$.\n    \\end{enumerate}\n\\end{nproof}\n\\begin{nproofcont}\n    \\begin{enumerate}\n        \\setcounter{enumi}{3}\n        \\item Choose $m$ such that $\\abs{s_n - s} < \\frac{1}{2}\\abs{s}$ if $n \\geq m$. We then have that $\\abs{s_n} > \\frac{1}{2}\\abs{s}$ for $n \\geq m$. Let $\\e > )0$. Then, there exists $N$ with $N > m$ such that for $n \\geq N$:\n        \\begin{align*}\n            \\abs{s_n - s} < \\frac{1}{2}\\abs{s}^2\\e\n        \\end{align*}\n        Hence, for $n \\geq N$:\n        \\begin{align*}\n            \\abs{\\frac{1}{s_n} - \\frac{1}{s}} = \\abs{\\frac{s_n - s}{s_ns}} < \\frac{2}{\\abs{s}^2}\\abs{s_n - s} < \\e\n        \\end{align*}\n        \\qed\n    \\end{enumerate}\n\\end{nproofcont}\n\n\\begin{nlemma}{: Squeeze Lemma}{}\n    Let $\\set{x_n}$, $\\set{s_n}$ be real-valued sequences. Then, if $0 \\leq x_n \\leq s_n$ for all $n$, and $\\linf s_n = 0$, then $\\linf x_n = 0$.\n\\end{nlemma}\n\\begin{nproof}\n    Let $\\e > 0$. Choose $N \\in \\NN$ such that $n \\geq N$ implies $0 \\leq s_n < \\e$. Then, we have that for $n \\geq N$, $0 \\leq x_n \\leq s_n < \\e$ and hence $x_n \\rightarrow 0$ as claimed. \\qed\n\\end{nproof}\n\n\\noindent Note that we can prove a more generalized version of the Squeeze Lemma. \n\n\\begin{nlemma}{: Generalized Squeeze Lemma}{}\n    Suppose we have sequences $\\set{l_n}, \\set{x_n}, \\set{u_n}$ such that $l_n \\leq x_n \\leq u_n$ for all $n$ and $\\linf l_n = \\linf u_n = L \\in \\RR$. Then, $\\linf x_n = L$.\n\\end{nlemma}\n\n\\begin{nproof}\n    We have that $0 \\leq a_n - l_n \\leq u_n - l_n$. We have that $\\linf u_n - l_n = 0$ by Theorem \\ref{thm:3.3}(a), so by the (original) Squeeze Lemma we have that $\\linf a_n - l_n = 0$. It then follows that $\\linf a_n = \\linf l_n = L$ as claimed. \\qed\n\\end{nproof}\n\n\\setcounter{rudin}{19}\n\\begin{theorem}{}{3.20}\n    \\begin{enumerate}\n        \\item Let $p > 0$. Then, $\\linf \\frac{1}{n^p} = 0$.\n        \\item Let $p > 0$. Then, $\\linf \\sqrt[n]{p} = 1$.\n        \\item $\\linf \\sqrt[n]{n} = 1$.\n        \\item Let $p > 0$ and $\\alpha \\in \\RR$. Then, $\\linf \\frac{n^\\alpha}{(1+p)^n} = 0$.\n        \\item Let $\\abs{x} < 1$. Then, $\\linf x^n = 0$. \n    \\end{enumerate}\n\\end{theorem}\n\\begin{nproof}\n    \\begin{enumerate}\n        \\item Let $\\e > 0$. Choose $N$ such that $\\frac{1}{N^p} < \\e$, namely $N > \\left(\\frac{1}{\\e}\\right)^{1/p}$. Then, for $n \\geq N$, $\\frac{1}{n^p} < \\frac{1}{N^p} < \\e$. \n        \n        \\item If $p = 1$, the sequence is constant and the conclusion immediate. \n        \n        If $p > 1$, then let $x_n = \\sqrt[n]{p} - 1$. We then have that:\n        \\begin{align*}\n            p = (x_n + 1)^n = \\sum_{k=0}^n \\binom{n}{k}x_n^k \\geq nx_n\n        \\end{align*}\n        Where the second equality follows from the binomial theorem (where $\\binom{n}{k} = \\frac{n!}{k!(n-k)!}$), and the inequality follows by considering that we just keep the $k = 1$ term (and the series is non-negative). Hence, we have that $x_n \\leq \\frac{p}{n}$, and $x_n \\rightarrow 0$ by (a). \n        \n        If $p < 1$, then let $q = \\frac{1}{p} > 1$. Then, $\\sqrt[n]{q} \\rightarrow 1$ by the argument above. By Theorem \\ref{thm:3.3}(d), we then have that $\\sqrt[n]{p} = \\frac{1}{\\sqrt[n]{q}} \\rightarrow \\frac{1}{1} = 1$.\n\n        \\item Let $x_n = \\sqrt[n]{n} - 1$. Then, we have that:\n        \\begin{align*}\n            n = (x_n + 1)^n = \\sum_{k=0}^n\\binom{n}{k}x_n^k \\geq \\frac{n(n-1)}{2}x_n^2\n        \\end{align*}\n        Where the inequality follows from keeping the $k = 2$ term only. We then have that $x_n \\leq \\sqrt{\\frac{2}{n-1}}$ and hence $x_n \\rightarrow 0$ by the Squeeze Lemma.\n        \\item We want to show $\\frac{n^\\alpha}{(1+p)^n} \\rightarrow 0$; we therefore want an upper bound on the expression, and hence a lower bound on $(1+p)^n$. Applying the Binomial Theorem we have that:\n        \\begin{align*}\n            (1+p)^n = \\sum_{k=0}^n\\binom{n}{k}p^k = \\left((n)(n-1)(n-2)\\cdots(n-k+1)\\right)\\frac{p^k}{n!}\n        \\end{align*}\n        Now, we pick $k > \\alpha$. For $2n > k$, we then have that:\n        \\begin{align*}\n            (1+p)^n \\geq \\left(\\frac{n}{2}\\right)^k\\frac{p^k}{k!}\n        \\end{align*}\n        We therefore have that:\n        \\begin{align*}\n            \\frac{n^\\alpha}{(1+p)^k} \\leq \\frac{2^kk!}{p^k}n^{\\alpha - k} \\rightarrow 0\n        \\end{align*}\n        And the claim follows by the Squeeze Lemma.\n        \n        \\item Taking $\\alpha = 0$ in (d), the claim follows by setting $\\abs{x} = \\frac{1}{1+p} < 1$ (as $p > 0$) and recognizing that $x_n \\rightarrow 0 \\iff \\abs{x^n} = \\abs{x}^n \\rightarrow 0$. \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\subsection{Subsequences}\n\n\\setcounter{rudin}{1}\n\\begin{theorem}{}{3.2}\n    Let $\\set{p_n}$ be a sequence in $X$.\n    \\begin{enumerate}\n        \\item $p_n \\rightarrow p$ in $X$ if and only if for all $r > 0$, $N_r(p)$ contains all but finitely many points of $\\set{p_n}$.\n        \\item If $p_n \\rightarrow p$ and $p_n \\rightarrow p'$ then $p = p'$. In other words, the limit is unique.\n        \\item If $\\set{p_n}$ is convergent, then it is bounded (that is, for any $q \\in X$ there exists $M \\in \\RR$ such that $d(q, p_n) \\leq M$ for all $n \\in \\NN$).\n        \\item If $E \\subset X$ has a limit point $p$, then there exists $\\set{p_n}$ in $E$ such that $p_n \\rightarrow p$. \n    \\end{enumerate}\n\\end{theorem}\n\\begin{nproof}\n    \\begin{enumerate}\n        \\item The claim follows immediately from the definition of convergence; for any $r = \\e > 0$, there exists $N \\in \\NN$ such that $N_r(p)$ contains $\\set{p_n: n \\geq N}$.\n        \\item There exist $N_1, N_2$ such that $d(p, p_{n_1}) < \\frac{\\e}{2}$ if $n_1 \\geq N_1$ and $d(p, p_{n_2}) < \\frac{\\e}{2}$ if $n_2 \\geq N_2$. Then for $n \\geq N = \\max{N_1, N_2}$ we have (using the triangle inequality) that:\n        \\begin{align*}\n            d(p, p') \\leq d(p, p_n) + d(p_n, p') < \\frac{\\e}{2} + \\frac{\\e}{2} = \\e\n        \\end{align*}\n        Since $\\e$ is arbitrary, $d(p, p') = 0$ and hence $p = p'$.\n\n        \\item If $p_n \\rightarrow p$, there exists $N$ such that $d(p_n, p) < 1$ for all $n \\geq N$. Set:\n        \\begin{align*}\n            r = \\max\\set{1, d(p_1, p), d(p_2, p), \\ldots ,d(p_{N-1}, p)}\n        \\end{align*}\n        For any $q \\in X$, we then have that:\n        \\begin{align*}\n            d(q, p_n) \\leq d(q, p) + d(p, p_n) \\leq d(q, p) + r\n        \\end{align*}\n        so the claim follows with $M = r + d(q, p) + 1$.\n        \\item Pick $p_n \\in E$ such that $d(p_n, p) < \\frac{1}{n}$. Let $\\e > 0$, and $N > \\frac{1}{\\e}$. Then, $n \\geq N$ implies $\\frac{1}{n} \\leq \\frac{1}{N} < \\e$ and hence $d(p_n, p) < \\e$ for all $n \\geq N$, and hence $p_n \\rightarrow p$ as desired. \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\setcounter{rudin}{4}\n\\begin{definition}{Subsequences}{3.5}\n    Given $\\set{p_n}$ and $n_1 < n_2 < n_3 < \\ldots$, we say that $\\set{p_{n_j}}$ is a \\textbf{subsequence} of $\\set{p_n}$.\n\\end{definition}\n\n\\noindent We first consider some examples. Let $p_n = n$. Then some valid subsequences of $\\set{p_n}$ are $\\set{1, 2, 3, 4, 5, \\ldots}$ (the original sequence), $\\set{1, 3, 5, 7, \\ldots}$ (the odds), $\\set{2, 3, 5, 7, 11, 13, \\ldots}$ (the primes). Next, let $p_n = i^n$. We have that $\\set{p_n} = \\set{i, -1, -i, 1, i, -1, -i, 1, \\ldots}$ which is clearly divergent. However, the subsequences $\\set{i, i, i, \\ldots}$, $\\set{-1, -1, -1, \\ldots}$, $\\set{-i, -i, -i, \\ldots}$ and $\\set{1, 1, 1, \\ldots}$ are all convergent! It is hence possible for a divergent sequence to have a convergent subsequence.\n\n\\begin{nlemma}{}{}\n    If $p_n \\rightarrow p$, then every subsequence of $\\set{p_n}$ converges to $p$. \n\\end{nlemma}\n\n\\begin{nproof}\n    Suppose $p_n \\rightarrow p$ and let $\\set{p_{n_j}}$ be a subsequence of $p_n$. Let $\\e > 0$. Then, there exists some $N \\in \\NN$ such that $d(p, p_n) < \\e$ if $n \\geq N$. Hence, $d(p, p_{n_j}) < \\e$ if $n_j \\geq N$ and hence $p_{n_j} \\rightarrow p$. \\qed\n\\end{nproof}\n\n\\begin{theorem}{Bolzano\u2013Weierstrass}{3.6}\n    \\begin{enumerate}\n        \\item If $\\set{p_n} \\subset X$ with $X$ compact, then $\\set{p_n}$ has a convergenct subsequence.\n        \\item If $\\set{p_n} \\subset \\RR^k$ and $\\set{p_n}$ is bounded, then $\\set{p_n}$ has a convergent subsequence.\n    \\end{enumerate}\n\\end{theorem}\n\\begin{nproof}\n    \\begin{enumerate}\n        \\item Let $E$ be the range of $\\set{p_n}$. If $E$ is finite, then there exists $x \\in X$ and $n_1 < n_2 < n_3 < \\ldots$ such that $p_{n_j} = x$ for all $j$. Therefore $p_{n_j} \\rightarrow x$ and we are done. If $E$ is infinite, then by compactness, $E \\subset X$ has a limit point in $X$ by Theorem \\ref{thm:2.37}. By Theorem \\ref{thm:3.2}(d) there exists a sequence $\\set{p_{n_j}}$ in $E$ such that $p_{n_j} \\rightarrow p$.\n        \\item By Theorem \\ref{thm:2.41}, $E$ (being bounded) lies in a compact subset of $\\RR^k$. We then apply (a). \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\subsection{Cauchy Sequences and Completeness}\n\n\\setcounter{rudin}{7}\n\\begin{definition}{Cauchy Sequences}{3.8}\n    A sequence $\\set{p_n} \\subset X$ is a \\textbf{Cauchy sequence} if for all $\\e > 0$, there exists $N \\in \\NN$ such that for all $n, m \\geq N$, $d(p_n, p_m) < \\e$. \n\\end{definition}\n\\noindent Note the fact that this definition does not refer to a particular $p$ that the sequence may converge to! It instead formalizes the notion of the points of a sequence getting ``closer together'' as the sequence goes on. It is therefore easier to check if a sequence is Cauchy than if it converges, as we don't need to know the value of the limit. To this end, it is useful to know in what situations a sequence being Cauchy implies that the sequence is convergent. We will soon arrive at a theorem that addresses this question, but first we establish a little more machinery.\n\n\\begin{definition}{Diameter}{3.9}\n    Let $E \\subset X$. Then the \\textbf{diameter} of $E$, denoted $\\diam E$ is defined as $\\diam E = \\sup\\set{d(p, q): p, q \\in E}$. It follows from the definition that a sequence $\\set{p_n}$ is Cauchy if and only if $\\lim_{N \\rightarrow \\infty} \\diam E_n = 0$ where $E_n = \\set{p_n}_{n=N}^\\infty$ (the tail of the sequence).\n\\end{definition}\n\n\\begin{nexample}{}{}\n    \\begin{enumerate}\n        \\item If $E = (a, b) \\subset \\RR$ or $E = [a, b] \\subset \\RR$, then $\\diam E = b - a$.\n        \\item If $E = (0, 1) \\times (0,1) \\subset \\RR^2$, then $\\diam E = \\sqrt{2}$ (the diagonal of the open square).\n    \\end{enumerate}\n\\end{nexample}\n\n\\begin{theorem}{}{3.10}\n    \\begin{enumerate}\n        \\item Let $E \\subset X$. Then, $\\diam \\overline{E} = \\diam E$.\n        \\item If $K_n \\subset X$ are compact, $K_{n+1} \\subset K_n$ for all $n$, and $\\linf \\diam K_n  = 0$, then $\\bigcap_{n=1}^\\infty K_n$ consists of exactly one point.\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{nproof}\n    \\begin{enumerate}\n        \\item Since $E \\subset \\overline{E}$, it is clear that $\\diam \\overline{E} \\geq \\diam E$. Next, let $\\e > 0$ and $p, q \\in \\overline{E}$. Choose $p', q' \\in E$ such that $d(p, p') < \\frac{\\e}{2}$, $d(q, q') < \\frac{\\e}{2}$ (this choice is possible as either $p, q$ are in $E$, or $p, q$ are limit points of $E$). Then, we have that:\n        \\begin{align*}\n            d(p, q) \\leq d(p, p') + d(p', q) \\leq d(p, p') + d(p', q') + d(q', q) < \\frac{\\e}{2} + \\diam E + \\frac{\\e}{2} = \\diam E + \\e\n        \\end{align*}\n        $\\e, p$, and $q$ are arbitrary, so it follows that $\\diam \\overline{E} \\leq \\diam E + \\e$ from the definition of the diameter. It then follows that $\\diam \\overline{E} \\leq \\diam E$. We conclude that $\\diam \\overline{E} = \\diam E$.\n        \\item Let $K = \\bigcap_{n=1}^\\infty K_n$. By the corollary to Theorem \\ref{thm:2.36}, we have that $K \\neq \\emptyset$, so $K$ contains at least one point. Since $K \\subset K_n$, it follows that $\\diam K \\leq \\diam K_n$ for any $n$, and since $\\diam K_n \\rightarrow 0$, $\\diam K = 0$. If there were $p, q \\in K$ such that $p \\neq q$, then $\\diam K \\neq 0$, so it must follow that $K$ has at most one point. We conclude that $K$ has exactly one point. \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\begin{nlemma}{}{}\n    If a sequence $\\set{p_n}$ is Cauchy, then it is bounded.\n\\end{nlemma}\n\\begin{nproof}\n    If $\\set{p_n}$ is Cauchy, then we have that $\\lim_{N \\rightarrow \\infty} \\diam E_N = \\lim_{N \\rightarrow \\infty} \\diam \\set{p_n}_{n = N}^\\infty = 0$. Then for some $N \\in \\NN$, $\\diam E_N < 1$. The range of $\\set{p_n}$ is the union of $E_N$ and the finite set $\\set{p_1, \\ldots, p_{N-1}}$ and hence $\\set{p_n}$ is bounded. \\qed\n\\end{nproof}\n\n\\begin{theorem}{}{3.11}\n    \\begin{enumerate}\n        \\item If a sequence $\\set{p_n} \\subset X$ converges, then it is Cauchy.\n        \\item If a sequence $\\set{p_n} \\subset X$ is Cauchy and $X$ is compact, then $\\set{p_n}$ converges to some $p \\in X$.\n        \\item In $\\RR^k$, every Cauchy sequence is convergent.\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{nproof}\n    \\begin{enumerate}\n        \\item Let $p_n \\rightarrow p$ and let $\\e > 0$. There exists $N \\in \\NN$ such that $d(p_n, p) < \\frac{\\e}{2}$ if $n \\geq N$. Then, for $n, m \\geq N$, we have that:\n        \\begin{align*}\n            d(p_n, p_m) \\leq d(p_n, p) + d(p, p_m) < \\frac{\\e}{2} + \\frac{\\e}{2} = \\e\n        \\end{align*}\n        so $\\set{p_n}$ is Cauchy.\n        \\item Let $E_N = \\set{p_n}_{n = N}^{\\infty}$. Then, $\\overline{E}_N \\subset X$ is closed, so by the compactness of $X$ we have that $\\overline{E}_N$ is compact by Theorem \\ref{thm:2.35}. Since $E_{N+1} \\subset E_N$, we have that $\\overline{E}_{N+1} \\subset \\overline{E}_N$, and additionally we have that $\\lim_{N \\rightarrow \\infty} \\overline{E}_N =\\lim_{N \\rightarrow \\infty} E_N = 0$ where the first equality follows from Theorem \\ref{thm:3.10}(a) and the second equality follows from the fact that $\\set{p_n}$ is Cauchy and Definition \\ref{def:3.9}. Thus, Theorem \\ref{thm:3.10}(b) says that there exists a unique point $p \\in \\bigcap_{n=1}^\\infty \\overline{E}_N$. Next, let $\\e > 0$. Then, there exists $N_0$ such that $\\diam \\overline{E}_N < \\e$ for all $N \\geq N_0$. So, $d(p, q) < \\e$ for all $q \\in \\overline{E}_N$, so the same holds for all $q \\in E_N$. Hence, $d(p, p_n) < \\e$ for all $n \\geq N_0$, which shows that $p_n \\rightarrow p$ and proves the claim. \n        \\item By the above Lemma, Cauchy sequences are bounded. Hence, $\\set{p_n} \\subset I$ for some $k$-cell $I \\subset \\RR^k$. Since $I$ is compact in $\\RR^k$, the claim follows from (b). \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\begin{definition}{Completeness}{3.12}\n    A metric space $X$ is called \\textbf{complete} if every Cauchy sequence converges in $X$. \n\\end{definition}\nIt might be tempting at first to think that every space would be complete, but this is not the case. For example, something that can go wrong is a sequnece can be Cauchy, but the limit can lie ``outside'' of the space. To see this, consider again the sequence $\\set{\\frac{1}{n}}$ in the metric space $\\RR^+ = \\RR \\setminus \\set{x \\in \\RR: x \\leq 0}$. The sequence is Cauchy, but does not converge in $\\RR^+$ (as it converges to 0, which lies outside of the space).\n\n\\begin{nexample}{}{}\n    \\begin{enumerate}[(i)]\n        \\item Compact sets are complete by Theorem \\ref{thm:3.11}(b).\n        \\item $\\RR^k$ (and $\\CC$) are complete by Theorem \\ref{thm:3.11}(c).\n        \\item $\\QQ$ is not complete. We can make a sequence of rational points that converges to an irrational number in $\\RR$ which is Cauchy, but does not converge in $\\QQ$ (Example \\ref{exam:1.1b} gives a way one might construct such a sequence). \n    \\end{enumerate}\n\\end{nexample}\n\\noindent Note that $\\QQ$ can be completed to $\\RR$, and in general for any $(X, d)$ which is not complete, there exists $(X^*, d^*)$ that is complete such that $\\abs{X} = X^*$. Indeed, this is another way we can construct the real numbers! $\\RR$ can be viewed as equivalence classes of Cauchy sequences in $\\QQ$. The idea is to define an equivalnence relation $\\sim$ such that $p_n \\sim q_n$ if $\\linf d(p_n, q_n) = 0$. $X^*$ is then defined as the set of equivalence classes under that equivalence relation, equipped with the metric $d^*([p], [q]) = \\linf d(p_n, q_n)$. It can then be checked that $d^*$ is a valid metric and that $X^*$ is complete. For the full proof, see HW7, or exercises 3.23-3.25 in Rudin (note: this proof is quite technical/difficult).\n\nTo motivate the next theorem, consider that all convergent sequences in $\\RR$ (and in general) are bounded (as we saw in Theorem \\ref{thm:3.2}(c)). However, this is not always true; for example consider $p_n = (-1)^n$ which is clearly bounded but divergent. What then are conditions that a bounded sequence may converge?\n\n\\begin{definition}{Monotonic Sequences}{3.13}\n    A sequence $\\set{p_n} \\subset \\RR$ is \\textbf{monotonically increasing} if $p_{n+1} \\geq p_n$ for all $n$, and \\textbf{montonically decreasing} if $p_{n+1} \\leq p_n$.\n\\end{definition}\n\n\\begin{theorem}{}{3.14}\n    Suppose $\\set{p_n} \\subset \\RR$ is montonic. Then, $\\set{p_n}$ is convergent if and only if it is bounded. \n\\end{theorem}\n\n\\begin{nproof}\n    $\\boxed{\\implies}$ See Theorem \\ref{thm:3.2}(c).\n\n    $\\boxed{\\impliedby}$ We show the proof for the increasing case as the decreasing case is analogous. Let $p = \\sup{p_n: n \\in \\NN}$ which exists as $\\set{p_n}$ is bounded and $\\RR$ has the LUB property. Then, $p_n \\leq p$ for all $n$. Let $\\e > 0$. Then, there exists $N \\in \\NN$ such that $p - \\e < p_{N} < p_{N+1}$. By the monotonicity of $\\set{p_n}$, it follows that $\\abs{p_n - p} < \\e$ for all $n \\geq N$. Hence, $p_n \\rightarrow p$. \\qed\n\\end{nproof}\n\n\\begin{definition}{Limits to Infinity}{3.15}\n    Let $\\set{p_n} \\subset \\RR$. If for all $M \\in \\RR$, there exists $N \\in \\NN$ such that $p_n > M$ for all $n \\geq N$, then we write $p_n \\rightarrow \\infty$. If instead for all $M \\in \\RR$ there exists $N \\in \\NN$ such that $p_n < M$ for all $n \\geq N$, then we write $p_n \\rightarrow -\\infty$.\n\\end{definition}\n\n\n\n\\subsection{Limit Supremum and Limit Infimum}\nAs a motivating question, how would we say something about the largest and smallest accumulation points of a sequence? This leads us to the following definition.\n\\begin{definition}{limsup and liminf}{3.16}\n    Let $\\set{s_n} \\subset \\RR$, then, we define the \\textbf{limit supremum} as:\n    \\begin{align*}\n        \\limsup_{n \\rightarrow \\infty} s_n = \\inf_{n \\geq 1}\\sup_{m \\geq n} s_m = \\lim_{n \\rightarrow \\infty} \\sup_{m \\geq n} s_m\n    \\end{align*}\n    And the \\textbf{limit infimum} as:\n    \\begin{align*}\n        \\liminf_{n \\rightarrow \\infty} s_n = \\sup_{n \\geq 1}\\inf_{m \\geq n} s_m = \\lim_{n \\rightarrow \\infty} \\inf_{m \\geq n} s_m\n    \\end{align*}\n    Note that unlike the limit of a real-valued sequence, the limsup and liminf always exist.\n\\end{definition}\n\n\\noindent In the above definition, the equivalence of $inf_{n \\geq 1}\\sup_{m \\geq n} s_m$ and $\\lim_{n \\rightarrow \\infty} \\sup_{m \\geq n} s_m$ may be slightly confusing. To see this, consider the fact that the sequence $q_n = \\sup \\set{p_n: n \\geq 1}$ is a strictly decreasing sequence in $n$ (with increasing $n$, we take the supremum over less terms each time), so taking the limit of $n \\rightarrow \\infty$ or taking the infimum over $n$ are equivalent. \n\nNote that Rudin defines the limsup/liminf differently, but perfectly equivalently. Namely, if $\\set{p_n} \\subset \\RR$ is a sequence, then $E$ is the set of all subsequential limits (i.e. there is a subsequence of $\\set{p_n}$ with a given limit). Then, $\\limsup^* p_n = \\sup E$ (we use the $*$ to denote Rudin's definition). The equivalence is not immediately obvious, so we here give a sketch to show that the two definitions coincide. We will use the general technique of showing that the two expressions are $\\e$ close to one another. Namely, for any $\\e > 0$, we show that the following two statements hold:\n\\begin{enumerate}[1)]\n    \\item $\\limsup^* p_n \\leq \\limsup p_n + \\e$\n    \\item $\\limsup^* p_n + \\e \\geq \\limsup p_n$\n\\end{enumerate}\nTo show 1), for each $N$, we let $n_N$ be an index such that $p_{n_N}$ satisfies:\n\\begin{align*}\n    p_{n_N} \\geq \\sup\\set{p_n: n \\geq N} - \\frac{\\e}{N}\n\\end{align*}\nAnd then we claim that $\\linf p_{n_N} = \\limsup p_n$ (Exercise). There is one slight technical issue in that $\\set{p_{n_N}}$ may not be a subsequence of $\\set{p_n}$, in particular we don't know that $n_{N_1} < n_{N_2} < n_{N_3} < \\ldots$ just by the above construction (but in order for this to be a valid subsequence, we need this to be the case). Fortunately, this is a fixable issue. We do know that $n_{N_1} \\geq 1$, $n_{N_2} \\geq 2$, $n_{N_3} \\geq 3$ by construction, so if it turns out to be the case that $n_{N_1} < n_{N_2}$ doesn't hold, we can skip ahead into the sequence until we find the first $j$ for which the equality holds. Concretely, if $n_{N_1} = 1000$ (as an example), then if we skip ahead to $n_{N_{1001}}$, it is guaranteed that $n_{N_1} < n_{N_{1001}}$ and we can from there construct a valid sequence. The sketch for 2) is left as an exercise. \n\n\\begin{nexample}{}{}\n    \\begin{enumerate}\n        \\item Consider $s_n = (-1)^n\\left(1 + \\frac{1}{n^2}\\right)$. Then, we have that $1 \\leq \\sup_{m \\geq n} s_n \\leq 1 + \\frac{1}{1^2} = 2$, so $\\limsup_{n \\rightarrow \\infty} s_n = 1$. Similarly, $\\limsup_{n \\rightarrow \\infty} s_n = -1$. Note that this sequence has no limit (it oscillates indefinitely and does not converge) but these quantities are well defined. We notice that the limsup is greater than the liminf in this case, and indeed it is true in general that $\\liminf_{n \\rightarrow \\infty} s_n \\leq \\limsup_{n \\rightarrow \\infty} s_n$. \n        \\item If $\\set{s_n}$ is not bounded above, then $\\sup_{m \\geq n} s_n = \\infty$ for all $n$ and we write $\\limsup_{n \\rightarrow} s_n = \\infty$. Similarly, if $\\set{s_n}$ is not bounded below, then $\\inf_{m \\geq n} s_n = -\\infty$ for all $n$ and we write $\\limsup_{n \\rightarrow \\infty} s_n = -\\infty$.\n    \\end{enumerate}\n\\end{nexample}\n\n\\noindent One difficulty with discussing the convergence of a sequence is that the definition is difficult to apply; we need to know what the sequence converges to. The notion of a Cauchy sequence then begins helpful (as Cauchy and convergent are equivalent in complete metric spaces). In addition, it is helpful to consider the limsup and liminf, as we can bound the limit above and below with these quantities respectively. In particular, the limit of the supremum of the tail of the sequence equals the limit of the infinimum of the tail of the sequence equals the limit of the sequence if the sequence is convergent.\n\n\\setcounter{rudin}{17}\n\\begin{theorem}{}{3.18}\n    Let $\\set{s_n} \\subset \\RR$. Then, $\\linf s_n = L$ if and only if $\\limsup_{n \\rightarrow \\infty} s_n = \\liminf_{n \\rightarrow \\infty} = L$.\n\\end{theorem}\n\\begin{nproof}\n    $\\boxed{\\implies}$ Let $\\e > 0$. Then, there exists $N \\in \\NN$ such that $s_m \\in (L - \\e, L + \\e)$ for all $m \\geq N$> Then, we have that:\n    \\begin{align*}\n        L - \\e \\leq \\inf_{m \\geq N} s_m \\leq \\sup_{m \\geq N} \\leq L + \\e\n    \\end{align*}\n    Taking limits we have:\n    \\begin{align*}\n        L - \\e \\leq \\liminf_{n \\rightarrow \\infty} \\leq \\limsup_{n \\rightarrow \\infty} s_n  \\leq L + \\e\n    \\end{align*}\n    $\\e$ is arbitrary, so we have that $\\limsup_{n \\rightarrow \\infty} s_n = \\liminf_{n \\rightarrow \\infty} = L$ .\n\n    $\\boxed{\\impliedby}$ We have that:\n    \\begin{align*}\n        \\inf_{m \\geq n} s_n \\leq s_n \\leq \\sup_{m \\geq n} s_m\n    \\end{align*}\n    for all $n \\in \\NN$. By assumption we have $\\limsup_{n \\rightarrow \\infty} s_n = \\liminf_{n \\rightarrow \\infty} = L$ so by the Generalized Squeeze Lemma we conclude that $\\linf s_n = L$. \\qed\n\\end{nproof}\n\\subsection{Series}\n\n\\setcounter{rudin}{20}\n\\begin{definition}{Infinite Series}{3.21}\n    Let $\\set{a_n} \\subset \\CC$. We then form a new sequence of $s_n = \\sum_{j=1}^n a_j$ (the sequence of partial sums). Then, if $s_n \\rightarrow s$. We say that the series $\\sum_{j = 1}^\\infty a_j$ converges, and write $\\sum_{j = 1}^\\infty a_j = s$. If $s_n$ does not converge, we say that $\\sum_{j=1}^\\infty a_j$ diverges. As a notational point, we will sometimes omit the bounds of summation and write $\\sum a_j$ to denote an infinite series, where the meaning is clear from context.\n\\end{definition}\n\\noindent Note that series are just a specific subset of sequences. Although the above definition states that $\\set{a_n} \\subset \\CC$, it is in general possible to define series over general vector spaces, with $\\set{a_n} \\in V$ and $\\set{s_n} \\in V$. \n\nNote that this generalization allows us to state an equivalent notion of completeness for vector spaces, namely that $V$ is compelte if and only if for all sequences $\\set{a_n} \\subset V$, the sum $\\sum_{n=0}^\\infty \\norm{a_n}$ converges to a point in $V$. As before, $\\RR, \\RR^k$ (both over the field $\\RR$), are complete vector spaces. An example of a vector space that is not complete is the set of functions $f: \\RR \\mapsto \\CC$ such that $\\int_{-\\infty}^\\infty \\abs{f(x)}^2 dx < \\infty$ (where the integral is the familiar Riemann integral from first year calculus, to be defined more rigorously in Chapter 6). For example, the sequence $f_n \\subset V$ such that:\n\\begin{align*}\n    f_n = \\begin{cases}\n        1 & \\text{for the first $n$ rationals}\n        \\\\ 0 & \\text{elsewhere}\n    \\end{cases}\n\\end{align*}\ndoes not converge to a function in $V$. In fact, Lebesgue integration (which is not covered in this course, but will be the primary focus of a course in measure theory) deals with this issue.\n\nWe will now restate the Cauchy criterion (Theorem \\ref{thm:3.11}) for series.\n\n\\begin{theorem}{}{3.22}\n    A series $\\sum a_j$ converges if and only if for all $\\e > 0$, there exists $N \\in \\NN$ such that $\\abs{\\sum_{j=m}^n a_j} < \\e$ for all $n \\geq m \\geq N$.\n\\end{theorem}\n\\begin{nproof}\n    $\\sum a_j$ converges if and only if $\\set{s_n}$ converges if and only if $\\set{s_n}$ is Cauchy. So by definition there exists $N$ such that for $n \\geq m - 1 \\geq N$:\n    \\begin{align*}\n        \\abs{s_n - s_m} = \\abs{\\sum_{j=1}^n a_j - \\sum_{j=1}^{m-1} a_j} = \\abs{\\sum_{j=m}^n a_j} < \\e\n    \\end{align*}\n    which proves the claim. \\qed\n\\end{nproof}\n\n\\begin{theorem}{Divergence Test}{3.23}\n    If $\\sum a_n$ converges, then $\\linf a_n = 0$.\n\\end{theorem}\n\\begin{nproof}\n    Choose $n = m$ in Theorem \\ref{thm:3.22}. \\qed\n\\end{nproof}\n\\noindent Note that this criteria gives us the ability to easily check if a series diverges; if $a_j$ does not converge to $0$, then $\\sum a_j$ diverges. However, note that the reverse implication does NOT hold! $\\sum \\frac{1}{n}$ diverges (as we will show next lecture) even though clearly $\\frac{1}{n} \\rightarrow 0$. \n\n\\begin{theorem}{}{3.24}\n    Let $\\set{a_n} \\subset \\RR$ and $a_n \\geq 0$ for all $n$. Then, we have that $\\sum a_n$ converges if and only if the sequence of partial sums $\\set{s_n}$ is bounded.\n\\end{theorem}\n\\begin{nproof}\n    If $a_n \\geq 0$, then $\\set{s_n}$ is monotonically increasing. Then by Theorem \\ref{thm:3.14}, $\\set{s_n}$ converges if and only if it is bounded. \\qed\n\\end{nproof}\n\n\\begin{theorem}{Comparison Test}{3.25}\n    \\begin{enumerate}\n        \\item Let $\\set{a_n} \\subset \\CC$ and $\\set{c_n} \\subset \\RR$. Then, if $\\abs{a_n} \\leq c_n$ for all $n \\geq N_0$ for some $N_0 \\in \\NN$, and $\\sum c_n$ converges, then $\\sum a_n$ converges. \n        \\item Let $\\set{a_n} \\subset \\RR$ and $\\set{d_n} \\subset \\RR$. If $a_n \\geq d_n \\geq 0$ for all $n \\geq N_0$ for some $N_0 \\in \\NN$ and $\\sum d_n$ diverges, then $\\sum a_n$ diverges.\n    \\end{enumerate}\n\\end{theorem}\n\\begin{nproof}\n    \\begin{enumerate}\n        \\item Let $\\e > 0$. Then, there exists $N \\in \\NN$ such that $\\sum_{j = m}^n c_n < \\e$ for all $n \\geq m \\geq N$. Then, take $N \\geq N_0$, and we have that:\n        \\begin{align*}\n            \\abs{\\sum_{j=m}^n a_j} \\leq \\sum_{j=m}^n \\abs{a_j} \\leq \\sum_{j=m}^n c_j < \\e\n        \\end{align*}\n        Where in the first inequality we apply the triangle inequality (Theorem \\ref{thm:1.37}). We conclude that $\\sum a_j$ converges by the Cauchy criterion (Theorem \\ref{thm:3.22}).\n        \\item The claim follows by considering the contrapositive of (a). \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\begin{theorem}{The Geometric Series}{3.26}\n    If $0 \\leq x < 1$, then $\\sum_{j=0}^\\infty x^j = \\frac{1}{1-x}$. If $x \\geq 1$, then $\\sum_{j=0}^\\infty x^j$ diverges.\n\\end{theorem}\n\\begin{nproof}\n    Suppose $x = 1$. Then, $x_n = 1$ does not converge to zero, so by Theorem \\ref{thm:3.24} $\\sum_{j=0}^\\infty x^j$ diverges. Suppose then that $x \\neq 1$. We have that $s_n = 1 + x + x^2 + \\ldots + x^n$. Hence, $xs_n = x + x^2 + x^3 + \\ldots + x^n + x^{n+1}$. Hence, $(1-x)s_n = 1 + x^{n+1}$ and therefore a closed form expression for $s_n$ is:\n    \\begin{align*}\n        s_n = \\frac{1 + x^{n+1}}{1 - x}\n    \\end{align*}\n    If $x > 1$, we have that $s_n$ diverges (again) by Theorem \\ref{thm:3.24}. If $x < 1$, then $x^{n+1} \\rightarrow 0$ by \\ref{thm:3.20}(e), so $s_n \\rightarrow \\frac{1}{1-x}$. \\qed\n\\end{nproof}\n\\noindent Note that by the comparison test, the above result can be generalized to see that $\\sum z^j$ for $z \\in \\CC$ converges for $\\abs{z} < 1$ and diverges for $\\abs{z} \\geq 1$. \n\n\\begin{theorem}{Cauchy Condensation Test}{3.27}\n    Suppose $\\set{a_n} \\subset \\RR$ and $a_1 \\geq a_2 \\geq a_3 \\geq \\ldots \\geq 0$. Then, $\\sum a_j$ converges if and only if $\\sum_{n=1}^\\infty 2^n a_{2^n}$ converges.\n\\end{theorem}\n\\begin{nproof}\n    $\\boxed{\\implies}$ For $2^k < n$, using the fact that the sequence is decreasing, we have that:\n    \\begin{align*}\n        a_1 + a_2 + \\ldots + a_n &\\geq a_1 + a_2 + (a_3 + a_4) + \\ldots + (a_{2^{k-1}+1} + \\ldots + a_{2^k})\n        \\\\ &\\geq \\frac{1}{2}a_1 + a_2 + 2a_4 + \\ldots + 2^{k-1}a_{2^k}\n        \\\\ &= \\frac{1}{2}(a_1 + 2a_2 + 4a_4 + \\ldots + 2^ka_{2^k})\n    \\end{align*}\n    Hence by the comparison test (Theorem \\ref{thm:3.25}) we have that $\\sum 2^n a_{2^n}$ converges if $\\sum a_j$ converges.\n\n    $\\boxed{\\impliedby}$ We show the contrapositive. For $2^k > n$, We have that:\n    \\begin{align*}\n        a_1 + a_2 + \\ldots + a_n &\\leq a_1 + (a_2 + a_3) + \\ldots + (a_{2^k} + \\ldots + a_{2^{k+1}-1})\n        \\\\ &\\leq a_1 + 2a_2 + 4a_4 + \\ldots + 2^ka_{2^k}\n    \\end{align*}\n    Hence by the comparison test (Theorem \\ref{thm:3.25}) we have that $\\sum 2^n a_{2^n}$ diverges if $\\sum a_j$ diverges. \\qed\n\\end{nproof}\n\n\\subsection{p-Series and Euler's Number}\nWe now use the result of Theorem \\ref{thm:3.27} to prove a result about a familiar subset of series.\n\n\\begin{theorem}{p-Series}{3.28}\n    $\\sum_{n=1}^\\infty \\frac{1}{n^p}$ converges if $p > 1$ and diverges if $p \\leq 1$. \n\\end{theorem}\n\\begin{nproof}\n    If $p \\leq 0$, then $n^p$ does not converge to $0$ and hence $\\sum \\frac{1}{n^p}$ diverges by Theorem \\ref{thm:3.23}. If $p > 0$, then $\\frac{1}{n^p}$ is a monotonically decreasing sequence of positive terms. Hence, we can apply the result of Theorem \\ref{thm:3.27}. $\\sum \\frac{1}{n^p}$ converges if and only if $\\sum_k 2^k \\frac{1}{2^{kp}} = \\sum_k \\left(\\frac{1}{2^{p-1}}\\right)^k$ converges. By Theorem \\ref{thm:3.26}, this last expression is convergent if and only if $0 < \\frac{1}{2^{p-1}} < 1$, i.e. if $p > 1$, proving the claim. \\qed\n\\end{nproof}\n\\noindent From the above result, we have that the $p$-series converges if $p > 1$ and diverges otherwise. Is there something ``in between'' these two regions?\n\n\\begin{theorem}{}{3.29}\n    $\\sum_{n=2}^\\infty \\frac{1}{n(\\log n)^p}$ converges if $p > 1$ and diverges if $p \\leq 1$.\n\\end{theorem}\n\\begin{nproof}\n    $\\log n$ is monotonically increasing for $p > 0$. So, $\\frac{1}{n(\\log n)^p}$ is monotonically decreasing. Hence, $\\sum \\frac{1}{n(\\log n)^p}$ converges if and only if $\\sum_k 2^k \\frac{1}{2^k}\\frac{1}{(\\log 2^k)^p} = \\sum_k \\frac{1}{k^p}$ converges, and hence the claim follows from Theorem \\ref{thm:3.28}. \\qed\n\\end{nproof}\n\n\\begin{definition}{Euler's Number}{3.30}\n    $e = \\sum_{n=0}^\\infty \\frac{1}{n!}$, where $0! = 1$ and $n! = n\\cdot (n-1)! = n \\cdot (n-1) \\cdot \\ldots \\cdot 2 \\cdot 1$ for $n \\geq 1$. \n\\end{definition}\n\\noindent We should check that this expression is well defined (namely, that the series converges). We first observe that $\\frac{1}{n!} \\leq \\frac{1}{2^{n-1}}$ for $n \\geq 1$. Therefore, we have that:\n\\begin{align*}\n    s_n = \\sum_{j=0}^n \\frac{1}{j!} \\leq 1 + \\sum_{j=1}^n \\frac{1}{2^{j-1}} \\leq 1 + \\sum_{j=0}^\\infty \\frac{1}{2^j} = 1 + \\frac{1}{1-\\frac{1}{2}} = 3\n\\end{align*}\nWhere we use Theorem \\ref{thm:3.26} in the second last equality. Hence, we conclude that $\\sum_{j=0}^n \\frac{1}{j!}$ converges by comparison, and moreover, that $0 < e < 3$. \n\nIt will also be of interest to investigate the rate of convergence of this series. To this end, we observe:\n\n\\begin{align*}\n    0 < e - s_q = \\frac{1}{(q+1)!} + \\frac{1}{(q+2)!} + \\ldots &\\leq \\frac{1}{(q+1)!}\\left(1 + \\frac{1}{q+1} + \\frac{1}{(q+1)^2} + \\ldots \\right) \n    \\\\ &= \\frac{1}{(q+1)!}\\frac{1}{1-\\frac{1}{q+1}} = \\frac{1}{(q+1)!}\\frac{q+1}{q} = \\frac{1}{q!q}\n\\end{align*}\nHence we have that the error goes to zero extremely quickly! Moreover, we can use this fact to show that $e$ is irrational.\n\n\\setcounter{rudin}{31}\n\\begin{theorem}{Irrationality of e}{3.32}\n    $e \\notin \\QQ$.\n\\end{theorem}\n\\begin{nproof}\n    Suppose $e = \\frac{p}{q}$ for $p, q \\in \\NN$. Then, by the argument above, we have that $0 < e - s_q < \\frac{1}{q!q}$. Hence, we have that $0 < q! q - q!s_q < \\frac{1}{q} \\leq 1$. But, $q!e = q!\\frac{p}{q} = (q-1)!p \\in \\NN$, and $q!s_q = \\sum_{j=0}^q q!\\frac{1}{j!} \\in \\NN$. Hence, $q! e - q! s_q \\in \\ZZ$, but this is a contradiction as $0 < q! e  - q! s_q < 1$. \\qed\n\\end{nproof}\n\\noindent There is another familiar definition of $e$ involving a limit that one may recall from first year calculus. These definitions are equivalent, as we will show in the next theorem.\n\n\\setcounter{rudin}{30}\n\\begin{theorem}{}{3.31}\n    $e = \\linf \\left(1 + \\frac{1}{n}\\right)^n$.\n\\end{theorem}\n\\begin{nproof}\n    Let $t_n = \\left(1 + \\frac{1}{n}\\right)^n$. By the Binomial theorem, we have that:\n    \\begin{align*}\n        t_n = \\sum_{j=0}^n \\binom{n}{j}\\left(\\frac{1}{n}\\right)^j = \\sum_{j=0}^n \\frac{1}{j!}\\left(\\frac{n}{n}\\cdot\\frac{(n-1)}{n}\\cdots \\frac{(n-j+1)}{n}\\right) \\leq s_n\n    \\end{align*}\n    Where the last inequality follows from the fact tha the term in brackets is less than (or equal to) 1. Hence, we have that $\\limsup_{n \\rightarrow \\infty} t_n \\leq \\limsup_{n\\rightarrow \\infty} s_n = \\linf s_n = e$. \n\n    On the other hand, fix $m \\in \\NN$ and let $n \\geq m$. Then, we have that:\n    \\begin{align*}\n        t_n \\geq \\sum_{j=0}^m \\binom{n}{j}\\frac{1}{n^j} = \\sum_{j=0}^m \\frac{1}{j!}\\left(\\left(1 - \\frac{1}{n}\\right)\\left(1 - \\frac{2}{n}\\right) \\cdots \\left(1 - \\frac{j-1}{n}\\right)\\right)\n    \\end{align*}\n    The infimum of the term in the brackets is just $1$, so we therefore have that:\n    \\begin{align*}\n        \\inf_{n \\geq m} t_n = \\sum_{j=0}^m \\frac{1}{j!} = s_m\n    \\end{align*}\n    Now, we take $m \\rightarrow \\infty$ to find that $\\liminf_{m \\rightarrow \\infty} t_m \\geq \\liminf_{m \\rightarrow \\infty} s_m = \\lim_{m \\rightarrow \\infty} s_m = e$. \n\n    Having shown that $\\liminf_{n \\rightarrow \\infty} t_n \\geq e \\geq \\limsup_{n \\rightarrow \\infty} t_n$, we conclude that $\\limsup_{n \\rightarrow \\infty} = \\liminf_{n \\rightarrow \\infty} = e$ and hence $\\linf t_n = e$. \\qed\n\\end{nproof}\n\n\\subsection{The Ratio and Root Tests}\n\\setcounter{rudin}{32}\n\\begin{theorem}{The Root Test}{3.33}\n    Let $\\sum a_n$ be a series, and put $\\alpha = \\limsup_{n \\rightarrow \\infty} \\sqrt[n]{\\abs{a_n}}$. Then,\n    \\begin{enumerate}[(i)]\n        \\item $\\sum a_n$ converges if $\\alpha < 1$.\n        \\item $\\sum a_n$ diverges if $\\alpha > 1$. \n        \\item If $\\alpha = 1$, the test is inconclusive.\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{nproof}\n    \\begin{enumerate}[(i)]\n        \\item Suppose $\\limsup_{n \\rightarrow \\infty} \\sqrt[n]{\\abs{a_n}} = \\alpha < 1$. Take $\\beta$ such that $\\alpha < \\beta < 1$ and $N \\in \\NN$ such that $\\sqrt[n]{\\abs{a_n}} < \\beta$ for all $n \\geq N$. Hence, for $n \\geq N$, $\\abs{a_n} < \\beta^n$, and $\\beta < 1$. The result follows by using the comparison Test with the geometric series.\n        \\item Suppose $\\limsup_{n \\rightarrow \\infty} \\sqrt[n]{\\abs{a_n}} = \\alpha > 1$. Then, there exists a subsequence such that $\\sqrt[n_j]{\\abs{a_{n_j}}} \\rightarrow \\alpha$. Therefore, there exists $N$ such that for $j \\geq N$, $\\sqrt[n_j]{\\abs{a_{n_j}}} > 1$, that is to say, $\\sqrt[n_j]{\\abs{a_{n_j}}} > 1$ for infinitely many terms. Hence, $\\sqrt[n]{\\abs{a_{n}}}$ does not converge to zero, and hence the series does not converge by the divergence test.\n        \\item Consider $\\sum \\frac{1}{n}$ and $\\sum \\frac{1}{n^2}$. $\\alpha = 1$ for both sums, but by Theorem \\ref{thm:3.28} the former diverges and the latter converges. \\qed\n    \\end{enumerate}\n\\end{nproof}\n\n\\begin{theorem}{The Ratio Test}{3.34}\n    Let $\\sum a_n$ be a series such that $a_n \\neq 0$ for all $n$. Then,\n    \\begin{enumerate}[(i)]\n        \\item $\\sum a_n$ converges if $\\limsup_{n \\rightarrow \\infty} \\abs{\\frac{a_{n+1}}{a_n}} < 1$. \n        \\item Diverges if there exists $N_0$ such that $\\abs{\\frac{a_{n+1}}{a_n}} \\geq 1$ for all $n \\geq N_0$. \n    \\end{enumerate}\n\\end{theorem}\n\\noindent In other cases, the test is inconclusive.\n\\begin{nproof}\n    \\begin{enumerate}[(i)]\n        \\item By assumption, there exists $\\beta < 1$ such that for some $N$, $\\abs{\\frac{a_{n+1}}{a_n}} < \\beta$ for all $n \\geq N$. We then have that $\\abs{a_{N+1}} < \\beta \\abs{a_N}$, that $\\abs{a_{N+1}} < \\beta \\abs{a_{N+1}} < \\beta^2 \\abs{a_N}$ and inductively we obtain that $\\abs{a_{N+p}} < \\beta^p \\abs{a_N}$. In other words, we have that for $n \\geq N$, $\\abs{a_n} < \\abs{a_N}\\beta^{-N}\\beta^{n}$. Since $\\sum \\beta^n$ converges (convergent geometric series), $\\sum a_n$ converges by the comparison test.\n        \\item For $n \\geq N_0$, we have that $\\abs{a_n} \\leq \\abs{a_{N+1}}$. Hence, $a_n$ does not converge to 0, and the claim follows by the divergence test. \\qed\n    \\end{enumerate}\n\\end{nproof}\n\\noindent As a remark, the the ratio test is less powerful than the root test. For any series for which the ratio test is conclusive, the root test is also conclusive. But the converse is not true. However, the ratio test is easier to apply in practice. We also note that the above ratio test implies the (perhaps more familiar) version from first year calculus:\n\\begin{ncorollary}{}{}\n    Let $\\sum a_n$ be a series such that $a_n \\neq 0$ for all $n$. Then:\n    \\begin{enumerate}[(i)]\n        \\item $\\sum a_n$ converges if $\\linf \\abs{\\frac{a_{n+1}}{a_n}} < 1$.\n        \\item $\\sum a_n$ diverges if $\\linf \\abs{\\frac{a_{n+1}}{a_n}} > 1$.\n        \\item $\\sum a_n$ diverges if $\\liminf \\abs{\\frac{a_{n+1}}{a_n}} > 1$.\n    \\end{enumerate}\n\\end{ncorollary}\n\n\\begin{example}{}{3.35}\n    Consider the series:\n    \\begin{align*}\n        \\frac{1}{2} + 1 + \\frac{1}{8} + \\frac{1}{4} + \\frac{1}{32} + \\frac{1}{16} + \\ldots\n    \\end{align*}\n    We then have that the ratio $\\frac{a_{n+1}}{a_n}$ is the sequence $2, \\frac{1}{8}, 2, \\frac{1}{8}, \\ldots$. Therefore, $\\limsup_{n \\rightarrow \\infty} \\abs{\\frac{a_{n+1}}{a_n}} = 2 > 1$ and $\\liminf_{n \\rightarrow \\infty} \\abs{\\frac{a_{n+1}}{a_n}} = \\frac{1}{8} < 1$ and the ratio test is inconclusive/tells us nothing. We then consider the root test. For $n \\geq 3$, we have that:\n    \\begin{align*}\n        a_n = \\begin{cases}\n            \\left(\\frac{1}{4}\\right)^k = \\left(\\frac{1}{4}\\right)^{\\frac{n-1}{2}} = 2\\left(\\frac{1}{4}\\right)^{\\frac{n}{2}} & n = 2k + 1\n            \\\\ \\frac{1}{2}\\left(\\frac{1}{4}\\right)^{k} = \\frac{1}{2}\\left(\\frac{1}{4}\\right)^{\\frac{n}{2}} & n = 2k\n        \\end{cases}\n    \\end{align*}\n    Since $\\linf \\sqrt[n]{p} = 1$ for $p > 0$ (Theorem \\ref{thm:3.20}(b)), we have that:\n    \\begin{align*}\n        \\linf \\sqrt[n]{a_n} = \\linf \\sqrt[n]{c\\left(\\frac{1}{4}\\right)^{\\frac{n}{2}}} = \\linf \\sqrt[n]{c} \\frac{1}{2} = \\frac{1}{2} < 1\n    \\end{align*}\n    where the above limit holds for either $c = \\frac{1}{2}$ or $c = 2$. Hence, we conclude that the series converges by the root test. This example demonstrates how the root test is ``sharper'' than the ratio test (though harder to apply).\n\\end{example}\n\n\\subsection{Power Series}\n\n\\setcounter{rudin}{37}\n\\begin{definition}{Power Series}{3.38}\n    For $z \\in \\CC$ and a sequence $\\set{c_n}$, $\\sum_{n=0}^\\infty c_n z^n$ is called a \\textbf{power series}.\n\\end{definition}\n\n\\begin{theorem}{Radius of Convergence}{3.39}\n    Let $R = \\frac{1}{\\limsup_{n \\rightarrow \\infty}\\sqrt[n]{\\abs{c_n}}}$, with the convention $R = \\infty$ if $\\limsup_{n \\rightarrow \\infty}\\sqrt[n]{\\abs{c_n}} = 0$ and $R = 0$ if $\\limsup_{n \\rightarrow \\infty}\\sqrt[n]{\\abs{c_n}} = \\infty$. Then, $\\sum_{n=0}^\\infty c_n z^n$ converges if $\\abs{z} < R$ and diverges if $\\abs{z} > R$. $R$ is called the \\textbf{radius of convergence} of $\\sum c_n z_n$. We note that on the circle $\\abs{z} = R$, the behavior is varied; the series can be divergent or convergent, and it can also depend on the particular choice of $z$ on the circle.\n\\end{theorem}\n\n\\begin{nproof}\n    We have that $\\limsup_{n \\rightarrow \\infty} \\sqrt[n]{c_n z^n} = \\limsup_{n \\rightarrow \\infty} \\sqrt[n]{c_n} \\abs{z} = \\frac{\\abs{z}}{R}$. Therefore, by the root test (Theorem \\ref{thm:3.33}) the series converges if $\\abs{z} < R$ and diverges if $\\abs{z} > R$ (and nothing can be said if $\\abs{z} = R$). \\qed\n\\end{nproof}\n\\noindent Note that we can use the ratio test to determine $R$ as well, as we will see in the next few examples.\n\n\\begin{example}{}{3.40}\n    \\begin{enumerate}\n        \\item $\\sum n! z^n$. By the ratio test, we have that $\\linf \\abs{\\frac{(n+1)!z^{n+1}}{n!z^n}} = \\linf (n+1)\\abs{z} = \\infty$ for all $z \\neq 0$. Hence the diverges for all $z \\in \\CC \\neq \\set{0}$, and we conclude that $R = 0$. \n        \\item $\\sum \\frac{z^n}{n^n}$. By Theorem \\ref{thm:3.39}, we have that:\n        \\begin{align*}\n            R = \\frac{1}{\\limsup_{n \\rightarrow \\infty}\\sqrt[n]{\\frac{1}{n^n}}} = \\frac{1}{\\limsup_{n \\rightarrow \\infty} \\frac{1}{n}} = \\frac{1}{\\linf \\frac{1}{n}} = \\infty\n        \\end{align*}\n        \\item $\\sum \\frac{z^n}{n!}$ also has $R = \\infty$ (as can be checked easily with the ratio test). For $R = 1$, the series is equal to $e$. As we will define later in Chapter 8, this series is equal to $e^z$. \n        \\item $\\sum \\frac{z^n}{n^p}$ with $p > 1$. By Theorem \\ref{thm:3.39}, we have that:\n        \\begin{align*}\n            R = \\frac{1}{\\limsup_{n \\rightarrow \\infty}\\sqrt[n]{\\frac{1}{n^p}}} = \\frac{1}{\\limsup_{n \\rightarrow \\infty} \\left(\\frac{1}{\\sqrt[n]{n}}\\right)^p} = \\frac{1}{1^p} = 1\n        \\end{align*}\n        where for the second last equality we apply Theorem \\ref{thm:3.20}(c). Note that this series converges for all $\\abs{z} \\leq 1$ (although the above calculation does not show convergence on the boundary).\n    \\end{enumerate}\n\\end{example}\n\\noindent Before moving on, let us consider some further examples. Suppose $a_n = 1$ for all $n$. Then, our power series if just $\\sum_{n=0}^\\infty z^n$, which is just the Geometric series. By Theorem \\ref{thm:3.26}, we have that the series converges if $\\abs{z} < 1$ to $\\frac{1}{1-z}$.\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tikzpicture}\n        \\draw[latex-latex,very thick] (-2,0)--(2,0);\n        \\draw[latex-latex,very thick] (0,-2)--(0,2);\n        \\draw[fill = black] (0, 1) circle (1pt);\n        \\node[xshift = 0.25cm, yshift = 0.25cm] at (0, 1) {$i$};\n        \\draw[fill = black] (1, 0) circle (1pt);\n        \\node[xshift = 0.25cm, yshift = 0.25cm] at (1, 0) {$1$};\n        \\draw[fill = black] (-1, 0) circle (1pt);\n        \\node[xshift = -0.25cm, yshift = 0.25cm] at (-1, 0) {$-1$};\n        \\draw[fill = black] (0, -1) circle (1pt);\n        \\node[xshift = 0.25cm, yshift = -0.25cm] at (0, -1) {$-i$};\n        \\draw[dotted, fill = white!60!black, fill opacity=0.3] (0, 0) circle (28.5pt);\n        \\node[] at (1.6, 1.6) {$\\CC$};\n    \\end{tikzpicture}\n    \\caption{Visualization of the radius of convergence of the Geometric Series. The series converges in the shaded region, and diverges outside of it. On the boundary, the series diverges at $z = 1$ and converges everywhere else.}\n    \\label{fig16}\n\\end{figure}\n\n\nAs another example, consider the series $\\sum_{n=1}^\\infty \\frac{1}{n}z^n$. By the ratio test, we find that $R = 1$, as:\n\\begin{align*}\n    \\limsup_{n\\rightarrow \\infty} \\abs{\\frac{\\frac{1}{n+1}z^{n+1}}{\\frac{1}{n}z^n}} = \\limsup_{n\\rightarrow \\infty}\\abs{\\frac{n}{n+1}z} = \\abs{z} \\limsup_{n\\rightarrow \\infty}\\abs{1 - \\frac{1}{n+1}} = \\abs{z}\n\\end{align*}\nSo this series converges if $\\abs{z} < 1$, diverges if $\\abs{z} > 1$. What happens for $\\abs{z} = 1$? At $z = 1$, we have that the series is just the standard harmonic series and diverges (by Theorem \\ref{thm:3.28}). At $z = -1$, we have an alternating series (a series whose terms are decreasing and tend to zero, and alternate in sign with each term), so we can apply the Alternating series test (below) to conclude that it converges. What about elsewhere on the circle? Let's look at $z = i$. We then have that the terms look like:\n\\begin{align*}\n    1 + \\frac{i}{2} - \\frac{1}{3} - \\frac{i}{4} + \\frac{1}{5} + \\frac{i}{6} - \\ldots\n\\end{align*}\nwe then have that the real and imaginary parts of the series are separately alternating series that decrease in magnitude; hence both parts are convergent, and the series as a whole is convergent at $z = i$. The same argument can be applied to conclude convergence of the series at $z = -i$. In fact, this series converges everywhere on the unit circle except at $z = 1$, which is a conclusion that follows from Theorem 3.44 (not covered in lecture, but feel free to refer to Rudin)!\n\n\\setcounter{rudin}{42}\n\\begin{theorem}{The Alternating Series Test}{3.43}\n    Let $\\set{a_n} \\subset \\CC$ and suppose that:\n    \\begin{enumerate}\n        \\item $\\abs{a_1} \\geq \\abs{a_2} \\geq \\abs{a_3} \\ldots$.\n        \\item $a_{2m-1} \\geq 0, a_{2m} \\leq 1$ for $m \\in \\NN$\n        \\item $\\linf a_n = 0$.\n    \\end{enumerate}\n    Then, $\\sum a_n$ converges.\n\\end{theorem}\n\\begin{nproof}\n    Rudin establishes a partial summation formula (Theorem 3.41) and proves a more general theorem (Theorem 3.42) to prove this claim. However, an alternative proof in the case where $\\set{a_n}$ is real is left as homework (HW7). \\qed\n\\end{nproof}\n\n\\subsection{Absolute Convergence}\n\\begin{ndef}{: Absolute Convergence}{}\n    $\\sum a_n$ is \\textbf{absolutely convergent} if $\\sum \\abs{a_n}$ converges. Note that if $\\sum a_n$ is convergenct but $\\sum \\abs{a_n}$ diverges, then $\\sum a_n$ is \\textbf{conditionally convergent}. Note that for real series with strictly positive terms, absolute convergence and conditional convergence are equivalent. Also, note that the root and ratio tests test for absolute convergence, and hence do not yield any information for conditional convergence. \n\\end{ndef}\n\\noindent As an example, consider that $\\sum \\frac{(-1)^n}{n}$ converges, but $\\sum \\frac{1}{n}$ diverges, so $\\sum \\frac{(-1)^n}{n}$ is conditionally convergent.\n\n\\setcounter{rudin}{44}\n\\begin{theorem}{}{3.45}\n    If $\\sum a_n$ converges absolutely, then $\\sum a_n$ converges.\n\\end{theorem}\n\\begin{nproof}\n    We have that:\n    \\begin{align*}\n        \\abs{\\sum_{j=m}^n a_j} \\leq \\sum_{j=m}^n\\abs{a_j} < \\e\n    \\end{align*}\n    For all $n \\geq m \\geq N$ for some $N$ by the fact that $\\sum \\abs{a_j}$ converges. Hence, $\\sum a_j$ is convergent by the Cauchy Criterion. \\qed\n\\end{nproof}\n\\noindent For absolutely convergent series, we can freely change the order of the additions without affecting the value of the sum (as we will soon see). However, for series that are not absolutely convergent, this turns out to not be the case!\n\n\\setcounter{rudin}{51}\n\\begin{definition}{Rearrangements}{3.52}\n    Given a bijection $K: \\NN \\rightarrow \\NN$, the series:\n    \\begin{align*}\n        \\sum_n a_n' = \\sum_n a_{K(n)}\n    \\end{align*}\n    is called a rearrangement of $\\sum_n a_n$. \n\\end{definition}\n\n\\setcounter{rudin}{54}\n\\begin{theorem}{}{3.55}\n    If $\\sum a_n$ is absolutely convergent, every rearrangement $\\sum a_n'$ converges to the same limit.\n\\end{theorem}\n\\begin{nproof}\n    Let $\\set{s_n'}$ beth sequence of partial sums of the rearrangement $\\sum a_n'$. Let $\\e > 0$. By the absolute convergent of the original series, there exists $N \\in \\NN$ such that for all $n \\geq m \\geq N$, $\\sum_{j=m}^n \\abs{a_j} < \\e$. Then, pick $p$ such that $\\set{1, 2, \\ldots N} \\subset \\set{K(1), K(2), K(3), \\ldots K(p)}$. Then, the summands $a_1, a_2, \\ldots a_N$ cancel out in $s_n - s_n'$ for $n \\geq p$, leaving only terms $a_{K(j)}$ past $a_N$. Hence, $\\abs{s_n - s_n'} < \\e$ for $n \\geq p \\geq N$, and we conclude that $\\sum a_n'$ converges to the same limit as $\\sum a_n$. \\qed\n\\end{nproof}\n\n\\setcounter{rudin}{53}\n\\begin{theorem}{Riemann Rearrangment Theorem}{3.54}\n    If $\\sum a_n$ is a conditionally convergent series of real numbers, and $- \\infty \\leq \\alpha \\leq \\beta \\leq \\infty$, then there is a rearrangement $\\sum a_n'$ such that $\\liminf_{n \\rightarrow \\infty} s_n' = \\alpha$ and $\\limsup_{n \\rightarrow \\infty} a_n' = \\beta$. Taking $\\alpha = \\beta$, we have that for any real number, there exists a rearrangement that converges to it. \n\\end{theorem}\n\\begin{nproof}\n    Not covered in lecture, see Rudin. \\qed\n\\end{nproof}\n\\noindent For example, given $\\sum (-1)^n a_n$ with $a_n \\geq 0$ and $\\linf a_n = 0$, we can rearrange this series to converge to any point in $\\RR$ that we like (for example, $\\pi$). The idea is to select positive terms from the series until we overshoot $\\pi$, then choose a sequnece of alternating negative/positive terms of decreasing magnitude until the $\\e$ distance from $\\pi$ decreases to zero.\n\n\\subsection{Addition and Multiplication of Series}\n\\setcounter{rudin}{46}\n\\begin{theorem}{Series Addition}{3.47}\n    Let $\\sum a_n = A$ and $\\sum b_n = B$. Then, $\\sum(a_n + b_n) = A + B$ and $\\sum c a_n = cA$ for any fixed $c \\in \\CC$.\n\\end{theorem}\n\\begin{nproof}\n    Let $A_n = \\sum_{j=0}^n a_j$ and $B_n = \\sum_{j=0}^n b_j$. Then, $A_n + B_n = \\sum_{j=0}^n a_j + b_j$ and since $\\linf A_n = A$ and $\\linf B_n = B$, it follows that:\n    \\begin{align*}\n        \\linf(A_n + B_n) = A + B.\n    \\end{align*}\n    For the second assertion, we have that $\\linf c A_n = c \\linf A_n = cA$. \\qed\n\\end{nproof}\n\n\\begin{definition}{Series Multiplication}{3.48}\n    Let $\\sum a_n$ and $\\sum b_n$ be two series. Then, the \\textbf{product} of of the two series is the series $\\sum c_n$ where:\n    \\begin{align*}\n        c_n = \\sum_{j=0}^n a_jb_{n-j} = \\sum_{j=0}^n a_{n-j}b_j\n    \\end{align*}\n\\end{definition}\n\\noindent Any student who has studied Fourier Series prior to this course will notice the similarity of the above definition to the convolution of two functions.\n\n\\setcounter{rudin}{49}\n\\begin{theorem}{}{3.50}\n    Suppose that $\\sum a_n$ converges absolutely and $\\sum b_n$ converges. Let $\\sum a_n = A$ and $\\sum b_n = B$. Then, $\\sum c_n$ converges and $\\sum c_n = AB$.\n\\end{theorem}\n\\begin{nproof}\n    Let $A_n = \\sum_{j=0}^n a_j$ and $B_n = \\sum_{j=0}^n b_j$. Let $\\beta_n = B_n - B$ (note that $\\beta_n \\rightarrow 0$). Now, we have that:\n    \\begin{align*}\n        C_n  = \\sum_{k=0}^n c_k = \\sum_{k=0}^n \\sum_{j=0}^k a_j b_{k-j} = \\sum_{j=0}^n \\sum_{k=j}^n a_j a_{k-j} = \\sum_{j=0}^n a_j \\sum_{k=j}^n b_{k-j} = \\sum_{j=0}^n a_j B_{n-j} = \\sum_{j=0}^n a_j(B + \\beta_{n-j})\n    \\end{align*}\n    From here, we split the sum and then we have that:\n    \\begin{align*}\n        C_n = \\sum_{j=0}^n a_jB + \\sum_{j=0}^n a_j\\beta_{n-j}\n    \\end{align*}\n    Defining $\\gamma_n = \\sum_{j=0}^n a_j\\beta_{n-j}$ and taking the limit of $n \\rightarrow \\infty$, we have:\n    \\begin{align*}\n        \\linf C_n = C = \\linf \\left(\\sum_{j=0}^n a_jB + \\gamma_n\\right) = \\linf \\sum_{j=0}^n a_jB + \\linf \\gamma_n = AB + \\linf \\gamma_n\n    \\end{align*}\n    So the claim is proven if $\\linf \\gamma_n = 0$. Let $\\alpha = \\sum \\abs{a_n} < \\infty$ (by assumption of absolute convergence). Let $\\e > 0$. Then, tere exists $N \\in \\NN$ such that $\\abs{\\beta_j} < \\frac{\\e}{\\alpha}$ for all $j \\geq N$ (as $\\beta_n \\rightarrow 0$). Hence, \n    \\begin{align*}\n        \\abs{\\gamma_n} \\leq \\abs{\\sum_{j=0}^n a_{n-j}\\beta_j} \\leq \\abs{\\sum_{j=0}^N a_{n-j}\\beta_j} + \\abs{\\sum_{j=N+1}^n a_{n-j}\\beta_j} < \\abs{\\sum_{j=0}^N a_{n-j}\\beta_j} + \\sum_{j=N+1}^n\\abs{a_{n-j}}\\frac{\\e}{\\alpha} \\leq \\abs{\\sum_{j=0}^N a_{n-j}\\beta_j} + \\e\n    \\end{align*}\n    Letting $n \\rightarrow \\infty$ with $N$ fixed, we have the first term goes to $0$ as $a_n \\rightarrow 0$ as $n \\rightarrow 0$. Hence, We have that:\n    \\begin{align*}\n        \\linf \\abs{\\gamma_n} < \\e\n    \\end{align*}\n    And as $\\e$ is arbitrary, $\\linf \\abs{\\gamma_n} = 0$ and the claim follows. \\qed\n\\end{nproof}", "meta": {"hexsha": "e6fd82b6b6335f8e18180b54d6204c9e3f9ff940", "size": 58723, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/ch3.tex", "max_stars_repo_name": "RioWeil/MATH320-321-Notes", "max_stars_repo_head_hexsha": "532c4bf12a8e4ea80a58a83508de05e1f121a79a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/ch3.tex", "max_issues_repo_name": "RioWeil/MATH320-321-Notes", "max_issues_repo_head_hexsha": "532c4bf12a8e4ea80a58a83508de05e1f121a79a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-10T23:18:29.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-25T17:05:30.000Z", "max_forks_repo_path": "Chapters/ch3.tex", "max_forks_repo_name": "RioWeil/MATH320-321-notes", "max_forks_repo_head_hexsha": "532c4bf12a8e4ea80a58a83508de05e1f121a79a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.3628088427, "max_line_length": 976, "alphanum_fraction": 0.6322905846, "num_tokens": 21097, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522813, "lm_q2_score": 0.9241418189341296, "lm_q1q2_score": 0.8029191447761306}}
{"text": "\n\\subsection{The group commutator}\n\nThe group commutator is:\n\n\\([a,b]=a^{-1}b^{-1}ab\\)\n\nIf the group is abelian then \\([a,b]=0\\). The group commutator is a measure of how non-abelian the group is.\n\nThis has the following properties:\n\n\\begin{itemize}\n\\item Alternativity: \\([A,A]=I\\)\n\\end{itemize}\n\n", "meta": {"hexsha": "435ae016f853afb025ee454f94ea6258893553ce", "size": 298, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/03-01-commutator.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/groups/03-01-commutator.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/groups/03-01-commutator.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.625, "max_line_length": 108, "alphanum_fraction": 0.6912751678, "num_tokens": 97, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.8028945163330724}}
{"text": "\\chapter{Primitive recursive functions}\n\n\\section{Introduction}\nPrimitive recursive functions are a small class of total functions, corresponding to the expressive power of a simple imperative programming language without \\textbf{while} loops, in which every program execution terminates.\n\nPrimitive recursive functions are total functions from $\\mathbb{N}^n$ to\n$\\mathbb{N}$, for some $n\\in\\mathbb{N}$. Note that not all \ntotal $n$-ary recursive functions are primitive recursive\n(see for instance Sect.~\\vref{sect:ack-not-PR}).\n\nThe traditional definition of the set of primitive recursive functions is structured as an inductive definition \nin five rules: three base cases, and two recursive construction rules. \n\n\\begin{description}\n  \\item[zero] the constant function of value $0$ is primitive recursive.\n\\item[S] The successor function $S:\\mathbb{N}\\rightarrow\\mathbb{N}$ is primitive recursive.\n \\item[projections] For any pair $0< i\\leq n$, the projection $\\pi_{i,n}: \\mathbb{N}^n\\rightarrow\\mathbb{N}$, defined by $\\pi_{i,n}(x_1,x_2,\\dots,x_{n})=x_i$, is primitive recursive.\n\\item[composition] For any $n$ and $m$, if $h: \\mathbb{N}^m\\rightarrow\\mathbb{N}$, and\n$g_0,\\dots, g_{m-1}: \\mathbb{N}^n\\rightarrow\\mathbb{N}$ are primitive recursive of $n$ arguments, then the function which maps any\ntuple $(x_0,\\dots,x_{n-1})$ to $h(g_0(x0,\\dots,x_{n-1}),\\dots, g_{m-1}(x0,\\dots,x_{n-1})): \\mathbb{N}^n\\rightarrow\\mathbb{N}$ is primitive recursive.\n\\item[primitive recursion]\nIf $g: \\mathbb{N}^n\\rightarrow\\mathbb{N}$ and $h: \\mathbb{N}^{n+2}\\rightarrow\\mathbb{N}$ are primitive recursive, then the function from $\\mathbb{N}^{n+1}$ into $\\mathbb{N}$ defined by\n\\begin{align}\nf(0,x_1,\\dots,x_n)&=g(x_1,\\dots,x_n)\\\\\nf(S(p),x_1,\\dots,x_n)&=h(p,f(p, x_1,\\dots,x_n),  x_1,\\dots,x_n)\n\\end{align} \nis primitive recursive.\n\\end{description}\n\n\nPlease note the use of dots: $\\ldots$ in the definition above. \nDots are not part of \\gallina's syntax. Thus, the formal definition of the set of primitive recursive function will have to overcome this representation problem.\n\n  We present in this chapter a formalization of  primitive recursive functions, taken from  Russel O'Connor's formalization in \\coq{} of\nG\\\"odel's incompleteness theorems~\\cite{OConnor05}.\n\n\\begin{remark}\n The theory of primitive recursive function is now hosted in\nthe \\texttt{theories/ordinals/Ackermann} directory.\nThe specific part on G\\\"odel's theorem,  is also on\ncoq-community (\\url{https://github.com/coq-community/goedel}) and requires the \n\\href{https://github.com/coq-community/pocklington}{Pocklington library} for lemmas on primality.\n\\end{remark}\n\nThis chapter contains some comments on Russel's library, as well as a few extensions.\nContributions (under the form of comments, new examples or exercises) are welcome!. \n\n\n\n\\section{First look at the Ackermann library}\n\nO'Connor's library on G\u00f6del's incompleteness theorems contains a little more \nthan 45K lines of scripts. The part dedicated to primitive recursive functions and Peano arithmetics is 32K lines long and is originally structured in 38 modules.\nThus, we propose a partial exploration of this library, through examples and exercises. Our additions to the original library --- mainly examples and counter-examples ---,\nare stored in the directory \\texttt{theories/ordinals/MoreAck}.\n\nIn particular, the library \\href{../theories/html/hydras.MoreAck.AckNotPR.html}{MoreAck.AckNotPR} contains the well-known  proof that the Ackermann function is not primitive recursive (see Section~\\vref{sect:ack-not-PR}).\nMoreOver, the library \\href{../theories/html/hydras.Hydra.Hydra_Theorems.html}{Hydra.Hydra\\_Theorems} contains \na proof that the length of an hydra battle (according to the initial replication factor) is not primitive recursive in general.\n\n\\section{Basic definitions}\n\\index{maths}{Primitive recursive functions}\n\nThe formal definition of primitive recursive functions lies in the library\n\\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec},\nwith preliminary definitions in \n\\href{../theories/html/hydras.Ackermann.extEqualNat.html}{Ackermann.extEqualNat}\nand\n\\href{../theories/html/hydras.Ackermann.misc.html}{Ackermann.misc}.\n\n\\subsection{Functions of arbitrary arity}\n\nThe  \\texttt{primRec} library allows us to consider primitive functions on \\texttt{nat}, with any number of arguments, in \ncurried form. This is made possible in \n\\href{../theories/html/hydras.Ackermann.extEqualNat.html}{Ackermann.extEqualNat} by the following definition:\n\n\\index{primrec}{Types!naryFunc}\n\\begin{Coqsrc}\nFixpoint naryFunc (n : nat) : Set :=\n  match n with\n  | O => nat\n  | S n => nat -> naryFunc n\n  end.\n\\end{Coqsrc}\n\nFor instance (\\texttt{naryFunc 1}) is convertible to \\texttt{nat -> nat} and (\\texttt{naryFunc 3})\nto \\texttt{nat -> nat -> nat -> nat}.\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.PrimRecExamples.html}{MoreAck.PrimRecExamples}}.\n\\begin{Coqsrc}\nRequire Import primRec.\nImport extEqualNat.\n\nCompute naryFunc 3.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= nat -> nat -> nat -> nat\n  : Set  \n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCheck plus: naryFunc 2.\n\nCheck 42: naryFunc 0.\n\nCheck (fun n p q : nat =>  n * p + q): naryFunc 3.\n\\end{Coqsrc}\n\n\nLikewise, arbitrary boolean predicates may have an arbitrary number of arguments. The dependent type\n(\\texttt{naryRel $n$}), defined in the same way as \\texttt{naryFunc}, is the type of $n$-ary functions from\n\\texttt{nat} into \\texttt{bool}.\n\n\\begin{Coqsrc}\nCompute naryRel 2.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = nat -> nat -> bool\n     : Set\n\\end{Coqanswer}\n\nThe magic of dependent types makes it possible to define recursively extensional equality between functions of the same arity.\n\n\\index{coq}{Dependent types}\n\\index{coq}{Dependently typed functions}\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.Ackermann.extEqualNat.html}{Ackermann.extEqualNat}}\n\n\\index{primrec}{Predicates!extEqual}\n\n\\begin{Coqsrc}\nFixpoint  extEqual (n : nat) : forall  (a b : naryFunc n), Prop :=\n  match n with\n    0 => fun a b => a = b\n  | S p => fun a b => forall c, extEqual p (a c) (b c)\n  end.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nCompute extEqual 2.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n     = fun a b : naryFunc 2 => forall x x0 : nat, a x x0 = b x x0\n     : naryFunc 2 -> naryFunc 2 -> Prop\n \\end{Coqanswer}\n \n\\begin{Coqsrc}\nExample extEqual_ex1 : extEqual 2 mult (fun x y =>  y * x + x - x) .\nProof.\n  intros x y.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n  x, y : nat\n  ============================\n  extEqual 0 (x * y) (y * x)\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n  cbn.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n1 subgoal (ID 10)\n  \n  x, y : nat\n  ============================\n  x * y = y * x + x - x\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n  rewrite <- Nat.add_sub_assoc, Nat.sub_diag.\n  - ring.\n  - apply le_n.  \nQed.\n\\end{Coqsrc}\n\n\\subsection{A Data-type for Primitive Recursive Functions}\n\nO'Connor's formalization of primitive recursive functions takes the form of two mutually inductive dependent data types, each constructor of which is associated with one of these  rules.\nThese two types are (\\texttt{PrimRec $n$}) (primitive recursive functions of $n$ arguments), and\n(\\texttt{PrimRecs $n$ $m$}) ($m$-tuples of primitive recursive functions of $n$ arguments).\n\n\n\\index{coq}{Dependent types}\n\\index{coq}{Mutually inductive types}\n\n\\index{primrec}{Types!PrimRec}\n\\index{primrec}{Types!PrimRecs}\n\\label{def:Primrec}\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}.}\n\\begin{Coqsrc}\nInductive PrimRec : nat -> Set :=\n  | succFunc : PrimRec 1\n  | zeroFunc : PrimRec 0\n  | projFunc : forall n m : nat, m < n -> PrimRec n\n  | composeFunc :\n      forall (n m : nat) (g : PrimRecs n m) (h : PrimRec m), PrimRec n\n  | primRecFunc :\n      forall (n : nat) (g : PrimRec n) (h : PrimRec (S (S n))), \n      PrimRec (S n)\nwith PrimRecs : nat -> nat -> Set :=\n  | PRnil : forall n : nat, PrimRecs n 0\n  | PRcons : forall n m : nat, PrimRec n -> PrimRecs n m -> \n                   PrimRecs n (S m).\n\\end{Coqsrc}\n\n\\begin{remark}\n\\label{projFunc-order-of-args}\nBeware of the conventions used in the \\texttt{primRec} library!\nThe constructor (\\texttt{projFunc $n$ $m$})  is associated with the projection $\\pi_{n-m,n}$ and \\emph{not}\n$\\pi_{n, m}$.\nFor instance, the projection $\\pi_{2,5}$ defined by $\\pi_{2,5}(a,b,c,d,e)=b$ corresponds to the term\n(\\texttt{projFunc 5 3 H}), where \\texttt{H} is a proof of $3<5$.\n This fact is reported in the comments of \\texttt{primRec.v}. We presume that this convention makes it easier to define the evaluation function (\\texttt{evalProjFunc $n$}) (see the next sub-section). Trying the other convention is left as an exercise.\n\\end{remark}\n\n\n\n\\subsection{A little bit of semantics} \nPlease note that inhabitants of type (\\texttt{PrimRec $n$}) are not \\coq{} functions like \\texttt{Nat.mul}, or factorial, etc. The data-type (\\texttt{PrimRec $n$}) is indeed an abstract syntax for the language of primitive recursive functions. The bridge between this language and the word of usual functions\nis an interpretation function (\\texttt{evalprimRec $n$})  of type\n$\\texttt{PrimRec}\\,n \\rightarrow  \\texttt{naryFunc}\\,n$.\nThis function is defined by mutual recursion,  together with the  function \n(\\texttt{evalprimRecS $n$ $m$}) of type \n$\\texttt{PrimRecs}\\,n\\,m \\rightarrow  \\texttt{Vector.t}\\,(\\texttt{naryFunc}\\,n)\\,m$.\n\n\\index{primrec}{Functions!evalPrimRec}\n\\index{primrec}{Functions!evalPrimRecs}\n\n\\index{coq}{Dependent pattern matching}\nBoth functions are mutually defined through dependent pattern matching. We advise the readers who \nwould feel uneasy with dependent types to consult Adam Chlipala's \\emph{cpdt}  book~\\cite{chlipalacpdt2011}. We leave it to the reader  to look also at the helper functions in\n\\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}.\n\n\n\\begin{Coqsrc}\nFixpoint evalPrimRec (n : nat) (f : PrimRec n) {struct f} : \n naryFunc n :=\n  match f in (PrimRec n) return (naryFunc n) with\n  | succFunc => S\n  | zeroFunc => 0\n  | projFunc n m pf => evalProjFunc n m pf\n  | composeFunc n m l f =>\n      evalComposeFunc n m (evalPrimRecs _ _ l) (evalPrimRec _ f)\n  | primRecFunc n g h =>\n      evalPrimRecFunc n (evalPrimRec _ g) (evalPrimRec _ h)\n  end\nwith evalPrimRecs (n m : nat) (fs : PrimRecs n m) {struct fs} :\n Vector.t (naryFunc n) m :=\n  match fs in (PrimRecs n m) return (Vector.t (naryFunc n) m) with\n  | PRnil a => Vector.nil  (naryFunc a)\n  | PRcons a b g gs =>\n       Vector.cons _ (evalPrimRec _ g) _  (evalPrimRecs _ _ gs)\n  end.\n\\end{Coqsrc}\n\nLooks complicated? The following examples show that, when\nthe arity is fixed, these definitions behave well w.r.t. \n\\coq's reduction rules. Moreover, they make the interpretation functions more ``concrete''.\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.PrimRecExamples.html}{MoreAck.PrimRecExamples}.}\n\\begin{Coqsrc}\nExample Ex1 : evalPrimRec 0 zeroFunc = 0.\nProof. reflexivity. Qed.\n\nExample Ex2 a : evalPrimRec 1 succFunc a = S a.\nProof. reflexivity. Qed.\n\nExample Ex3 a b c d e f: forall (H: 2 < 6),\n    evalPrimRec 6\n                (projFunc 6 2 H) a b c d e f = d.\nProof. reflexivity. Qed.\n\nExample Ex4 (x y z : PrimRec 2) (t: PrimRec 3):\n  let u := composeFunc 2 3\n                       (PRcons 2 _ x\n                               (PRcons 2 _ y\n                                       (PRcons 2 _ z\n                                               (PRnil 2))))\n                       t in\n  let f := evalPrimRec 2 x in\n  let g := evalPrimRec 2 y in\n  let h := evalPrimRec 2 z in\n  let i := evalPrimRec 3 t in\n  let j := evalPrimRec 2 u in\n  forall a b, j a b = i (f a b) (g a b) (h a b).\nProof. reflexivity. Qed.\n\nExample Ex5 (x : PrimRec 2)(y: PrimRec 4):\n  let g := evalPrimRec _ x in\n  let h := evalPrimRec _ y in\n  let f := evalPrimRec _ (primRecFunc _ x y) in\n  forall a b,  f 0 a b = g a b.\nProof. reflexivity.   Qed.                          \n\nExample Ex6 (x : PrimRec 2)(y: PrimRec 4):\n  let g := evalPrimRec _ x in\n  let h := evalPrimRec _ y in\n  let f := evalPrimRec _ (primRecFunc _ x y) in\n  forall n a b,  f (S n) a b = h n (f n a b) a b.\nProof. reflexivity.   Qed.                          \n\\end{Coqsrc}\n\n\nAnother example?\nLet us consider the following term\\footnote{Of course, we never typed this term \\emph{verbatim}; we obtained it by an interactive proof the reader will be able to make after \nreading Sect.\\vref{sect:proofs-of-isPR}.}:\n\n\\label{sect:bigfac}\n\\begin{Coqsrc}\nExample bigPR : PrimRec 1 :=\nprimRecFunc 0\n  (composeFunc 0 1 (PRcons 0 0 zeroFunc (PRnil 0)) succFunc)\n  (composeFunc 2 2\n    (PRcons 2 1\n      (composeFunc 2 1\n         (PRcons 2 0 (projFunc 2 1 (le_n 2))\n                 (PRnil 2))\n         succFunc)\n      (PRcons 2 0\n        (composeFunc 2 1\n          (PRcons 2 0\n             (projFunc 2 0\n                       (le_S 1 1 (le_n 1)))\n             (PRnil 2))\n          (projFunc 1 0 (le_n 1))) (PRnil 2)))\n    (primRecFunc 1 (composeFunc 1 0 (PRnil 1) zeroFunc)\n       (composeFunc 3 2\n         (PRcons 3 1\n            (projFunc 3 1 (le_S 2 2 (le_n 2)))\n            (PRcons 3 0 (projFunc 3 0\n                          (le_S 1 2\n                                (le_S 1 1 (le_n 1))))\n                    (PRnil 3)))\n         (primRecFunc 1 (projFunc 1 0 (le_n 1))\n                      (composeFunc 3 1\n                          (PRcons 3 0\n                                  (projFunc 3 1 (le_S 2 2 (le_n 2)))\n                                  (PRnil 3))\n                          succFunc))))). \n\\end{Coqsrc}\n\nLet us now interpret this term as an arithmetic function.\n\n\\begin{Coqsrc}\nExample  mystery_fun : nat -> nat := evalPrimRec 1 bigPR.\n\nCompute map mystery_fun[0;1;2;3;4;5;6] : t nat _.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = 1 :: 1 :: 2 :: 6 :: 24 :: 120 :: 720 :: nil\n     : t nat 7\n\\end{Coqanswer}\n\nAfter this test, the term \\texttt{bigPR} looks to be a primitive recursive definition of the factorial function, although we haven't proved this fact yet. Fortunately, we will see in the following sections simple ways to prove that a given function is primitive recursive, whithout building such an unreadable term.\n\n\\section{Proving that a given arithmetic function is primitive recursive}\n\\label{sect:proofs-of-isPR}\n\nThe example in the preceding section clearly shows that, in order to prove that a given arithmetic function\n(defined in \\gallina{} as usual) is primitive recursive, trying to give  by hand a term  of type (\\texttt{PrimRec $n$}) is not a good method, since such terms may be huge and complex, even for simple arithmetic functions. The method proposed in Library \\texttt{primRec} is the following one:\n\n\\begin{enumerate}\n\\item Define a type corresponding to the statement \"the function \\texttt{$f$:naryFunc $n$} is primitive recursive ''.\n\\item Prove handy lemmas which may help to prove that a given function is primitive recursive.\n\\end{enumerate}\n\nThus, the proof that a function, like \\texttt{factorial}, is primitive recursive may be interactive, whithout having to type complex terms at any step of the development.\n\n\\subsection{The predicate \\texttt{isPR}}\n\n\\index{primrec}{Predicates!isPR}\n\\index{coq}{Extensionnaly equal functions}\n\nLet $f$ be an arithmetic function of arity $n$. We say that $f$ is primitive recursive if $f$ is \\textbf{extensionnaly}\nequal to the interpretation of some term of type \\texttt{PrimRec $n$}. \n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}.}\n\\begin{Coqsrc}\nDefinition isPR (n : nat) (f : naryFunc n) : Set :=\n  {p : PrimRec n | extEqual n (evalPrimRec _ p) f}.  \n\\end{Coqsrc}\n\nThe library \\texttt{primRec} contains a large catalogue of lemmas allowing to prove statements \nof the form (\\texttt{isPR $n$ $f$}). We won't list all these lemmas here, but give a few examples of\nhow they may be applied.\n\n\\begin{remark}\nIn the library \\texttt{primRec}, all these lemmas are opaque (registered with \\texttt{Qed}. Thus they do not allow the user to look at the witness of a proof of a \\texttt{isPR} statement. Our example of page\\pageref{sect:bigfac} was built using a  copy of \\texttt{primRec.v} where many \\texttt{Qed}s have been replaced with\n\\texttt{Defined}s.\n\nIf it does not cause compatibility problems (with \n\\href{https://github.com/coq-community/goedel}{goedel library} for instance), we plan to make all theses lemmas transparent.\n\\end{remark}\n\n\\subsubsection{Elementary proofs of \\texttt{isPR} statements}\n\nThe constructors \\texttt{zeroFunc}, \\texttt{succFunc},  and \\texttt{projFunc} of type\n\\texttt{PrimRec} allows us to write trivial proofs of primitive recursivity. \nAlthough  the following lemmas are already proven in \n\\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec},\nwe wrote alternate proofs in \n\\href{../theories/html/hydras.MoreAck.PrimRecExamples.html}%\n{Ackermann.MoreAck.PrimRecExamples.v}, in order to illustrate the main proof patterns.\n\n\\begin{Coqsrc}\nModule Alt.\n  \nLemma zeroIsPR : isPR 0 0.\nProof.\n  exists zeroFunc.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n1 subgoal (ID 90)\n  \n  ============================\n  extEqual 0 (evalPrimRec 0 zeroFunc) 0\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n  cbn.\n\\end{Coqsrc}\n\n\n\\begin{Coqanswer}\n1 subgoal (ID 91)\n  \n  ============================\n  0 = 0\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n  reflexivity.\nQed.\n\\end{Coqsrc}\n\n\nLikewise, we prove that the successor function on \\texttt{nat} is primitive recursive too.\n\n\\begin{Coqsrc}\nLemma SuccIsPR : isPR 1 S.\nProof.\n  exists succFunc; cbn; reflexivity.\nQed.\n\\end{Coqsrc}\n\nProjections are proved primitive recursive, case by case (many examples in \n\\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}).\n\\emph{Please notice again that the name of the projection follows the mathematical tradition, \nwhilst the arguments of  \\texttt{projFunc} use another convention (\\emph{cf} remark~\\vref{projFunc-order-of-args}).}\n\n\\begin{Coqsrc}\nLemma pi2_5IsPR : isPR 5 (fun a b c d e => b).\nProof.\n assert (H: 3 < 5) by auto.\n exists (projFunc 5 3 H).\n cbn; reflexivity.\nQed.\n\\end{Coqsrc}\n\nPlease note that the projection $\\pi_{1,1}$ is just the identity on \\texttt{nat}, and is realized by \n(\\texttt{projFunc 1 0}).\n\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}.}\n\n\\begin{Coqsrc}\nLemma idIsPR : isPR 1 (fun x : nat => x).\nProof.\n  assert (H: 0 < 1) by auto.\n  exists (projFunc 1 0 H); cbn; auto.\nQed.\n\\end{Coqsrc}\n\n\\subsubsection{Using function composition}\n\nLet us look at the proof that any constant $n$ of type \\texttt{nat} has type (\\texttt{PR 0})\n(lemma  \\texttt{const1\\_NIsPR} of \\texttt{primRec}). We carry out a proof by induction on $n$, the base case of which is already proven.\nNow, let us assume $n$ is \\texttt{PR $n$}, with $x:\\texttt{PrimRec}\\,0$ as a ``realizer''.\nThus we would like to compose this constant function with the unary successor function.\n\nThis is exactly the role of the instance \\texttt{composeFunc 0 1} of the dependently typed\nfunction \\texttt{composeFunc}, as shown by the following lemma.\n\n\\begin{Coqsrc}\nFact compose_01 :\n    forall (x:PrimRec 0) (t : PrimRec 1),\n    let c := evalPrimRec 0 x in\n    let f := evalPrimRec 1 t in\n    evalPrimRec 0 (composeFunc 0 1\n                               (PRcons 0 0 x (PRnil 0))\n                               t)  =\n     f c.\nProof. reflexivity. Qed.\n\\end{Coqsrc}\n\nThus, we get a quite simple proof of \\texttt{const1\\_NIsPR}.\n\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.PrimRecExamples.html}{MoreAck.PrimRecExamples}}.\n\\begin{Coqsrc}\nLemma  const1_NIsPR n : isPR 0 n. \nProof.\n  induction n.\n  - apply zeroIsPR.\n  - destruct IHn as [x Hx].\n   exists (composeFunc 0 1 (PRcons 0 0 x (PRnil 0)) succFunc). \n   cbn in *; intros; now rewrite Hx.\nQed.\n\\end{Coqsrc}\n\n\n\\subsubsection{Proving that \\texttt{plus} is primitive recursive}\n\nThe lemma \\texttt{plusIsPR} is already proven in \\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}. We present in \n\\href{../theories/html/hydras.MoreAck.PrimRecExamples.html}{MoreAck.PrimRecExamples}\na commented version of this proof, \n\nFirst, we look for lemmas which may help to prove that a given function obtained with the recursor \\texttt{nat\\_rec} is primitive recursive.\n\n\\begin{Coqsrc}\nSearch (is_PR 2 (fun _ _ => nat_rec _ _ _ _)).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\nind1ParamIsPR:\n  forall f : nat -> nat -> nat -> nat,\n  isPR 3 f ->\n  forall g : nat -> nat,\n  isPR 1 g ->\n  isPR 2\n    (fun a b : nat =>\n     nat_rec (fun _ : nat => nat)\n                 (g b) (fun x y : nat => f x y b) a)\n\\end{Coqanswer}\n\nWe prove that the library function \\texttt{plus} is extensionally equal to a function defined with\n\\texttt{nat\\_rec}.\n\n\\begin{Coqsrc}\nDefinition plus_alt x y  :=\n              nat_rec  (fun n : nat => nat)\n                       y\n                       (fun z t =>  S t)\n                       x.\n\nLemma plus_alt_ok:\n  extEqual 2 plus_alt plus.\nProof.\n  intro x; induction x; cbn; auto.\n  intros y; cbn; now rewrite <- (IHx y).\nQed.\n\\end{Coqsrc}\n\nA last lemma before the proof:\n\n\\begin{Coqsrc}\nLemma isPR_extEqual_trans n : forall f g, isPR n f ->\n                                    extEqual n f g ->\n                                    isPR n g.\nProof.\n intros f g [x Hx]; exists x.\n apply extEqualTrans with f; auto.\nQed.\n\\end{Coqsrc}\n\nLet us start now.\n\n\\begin{Coqsrc}\nLemma plusIsPR : isPR 2 plus.\nProof.\n  apply isPR_extEqual_trans with plus_alt.\n  - unfold plus_alt; apply ind1ParamIsPR.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n2 subgoals (ID 126)\n  \n  ============================\n  isPR 3 (fun _ y _ : nat => S y)\n\nsubgoal 2 (ID 127) is:\n isPR 1 (fun b : nat => b)\n\\end{Coqanswer}\n\nWe already proved that \\texttt{S} is \\texttt{PR 1}, but we need to consider a function of three arguments, which ignores its first and third arguments.\nFortunately, the library \\texttt{primRec} already contains lemmas adapted to this kind of situation.\n\n\\begin{Coqanswer}\nfilter010IsPR :\nforall g : nat -> nat, isPR 1 g -> isPR 3 (fun _ b _ : nat => g b)\n\\end{Coqanswer}\n\nThus, our first subgoal is solved easily. The rest of the proof \nis just an application of already proven lemmas.\n\n\n\\begin{Coqsrc}\n - unfold plus_alt; apply ind1ParamIsPR.\n    + apply filter010IsPR, succIsPR.\n    + apply idIsPR.\n  - apply plus_alt_ok. \nQed.\n\\end{Coqsrc}\n\n\n\\begin{todo}\nComment more examples from   \\href{../theories/html/hydras.MoreAck.PrimRecExamples.html}{MoreAck.PrimRecExamples}.\n\\end{todo}\n\n\\index{primrec}{Exercises}\n\\begin{exercise}\nThere is a lot of lemmas similar to \\texttt{filter010IsPR} in the \\texttt{primRec} library, useful to control the arity of functions.\nThus, the reader may look at them, and invent simple examples of application for each lemma.\n\\end{exercise}\n\n\\index{primrec}{Exercises}\n\\begin{exercise}\nMultiplication of natural number is already proven in the \\texttt{primRec} library. Write a proof of your own, then compare to the library's version.\n\\end{exercise}\n\n\\subsubsection{More examples}\n\nThe following proof decomposes the \\texttt{double} function as the composition of \nmultiplication with the identity and the constant function which returns $2$.\n\\emph{Note that the lemma \\texttt{const1\\_NIsPR} considers this function as an unary function (unlike \\texttt{const0\\_NIsPR})}. \n\n\\begin{Coqsrc}\nLemma doubleIsPR : isPR 1 double.\nProof.\n  unfold double; apply compose1_2IsPR.\n  - apply idIsPR.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\nsubgoal 1 (ID 110) is:\n isPR 1 (fun _ : nat => 2)\nsubgoal 2 (ID 111) is:\n isPR 2 Init.Nat.mul\n\\end{Coqanswer}\n\n \\begin{Coqsrc}\n  - apply const1_NIsPR.\n  - apply multIsPR.\nQed.\n\\end{Coqsrc}\n\n\\index{primrec}{Exercises}\n\\begin{exercise}\nProve that the following functions are primitive recursive. \n\n\\begin{Coqsrc}\nFixpoint fact n :=\n  match n with \n          | 0 => 1\n          | S p  => n * fact p\n  end.\n\nFixpoint exp n p :=\n  match p with\n  | 0 => 1\n  | S m =>  exp n m * n\n  end.\n\nFixpoint tower2 n :=\n  match n with\n  | 0 => 1\n  | S p => exp 2 (tower2 p)\n  end.\n\\end{Coqsrc}\n\n\n\n\\textbf{Hint:} You may have to look again at the lemmas of the library\n\\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec} if you meet some difficulty.\nYou may start this exercise with the file\n    \\href{https://https://github.com/coq-community/hydra-battles/blob/master/exercises/primrec/MorePRExamples.v}{exercises/primrec/MorePRExamples.v}.\n\\end{exercise}\n\n\n\n\\index{primrec}{Exercises}\n\\begin{exercise}\nShow that the function \\texttt{min: naryFunc\\,2} is primitive\nrecursive.\n\n\\emph{You may start this exercise with\n    \\href{https://https://github.com/coq-community/hydra-battles/blob/master/exercises/primrec/MinPR.v}{exercises/primrec/MinPR.v}.}\n\n\\end{exercise}\n\n\\index{primrec}{Exercises}\n\n\\begin{exercise}\nWrite a simple and readable proof that the Fibonacci function is primitive recursive.\n\n\n\\begin{Coqsrc}\nFixpoint fib (n:nat) : nat :=\n  match n with\n  | 0 => 1\n  | 1 => 1\n  | S ((S p) as q) => fib q + fib p\n  end.\n\\end{Coqsrc}\n\n\\textbf{Hint:}  You may use as a helper the function which computes the pair \\linebreak\n$(\\texttt{fib}(n+1),\\texttt{fib}(n))$. \nLibrary \\href{../theories/html/hydras.Ackermann.cPair.html}{Ackermann.cPair} contains\nthe definition of the encoding of $\\mathbb{N}^2$ into $\\mathbb{N}$, and the proofs that \nthe associated constructor and projections are primitive recursive.\n\\emph{You may start this exercise with the file\n    \\href{https://github.com/coq-community/hydra-battles/blob/master/exercises/primrec/FibonacciPR.v}{exercises/primrec/FibonacciPR.v}.}\n\n\\end{exercise}\n\n\\index{primrec}{Exercises}\n\\begin{exercise}\nProve the following lemmas (which may help to solve the next  exercise).\n\n\\begin{Coqsrc}\nLemma boundedSearch3 (P: naryRel 2) (b  : nat), \n    boundedSearch P b <= b. \n\nLemma boundedSearch4 (P: naryRel 2) (b  : nat):\n  P b b = true -> P b (boundedSearch P b) = true.\n\\end{Coqsrc}\n\\end{exercise}\n\n\\index{primrec}{Exercises}\n\n\\begin{exercise}\nProve that the function which returns the  integer square root of any natural number  is primitive recursive.\n\n\\emph{You may start this exercise with the file\n    \\href{https://github.com/coq-community/hydra-battles/blob/master/exercises/primrec/isqrt.v}{exercises/primrec/isqrt.v}.}\n\n\\end{exercise}\n\n\\section{Proving that a given function is \\emph{not} primitive recursive}\n\\label{sect:ack-not-PR}\n\nThe best known example of a total recursive function which is not primitive recursive is the Ackermann function. We show how to adapt the classic proof (see for instance~\\cite{planetmath}) to the constraints of \\gallina. We hope this formal proof \n is a nice opportunity to explore\nthe treatment of primitive recursive functions by R. O'Connor,\nand to play with dependent types.\n\n\\subsection{Ackermann function}\n\nAckermann function is traditionally defined as a function from \n$\\mathbb{N}\\times \\mathbb{N}$ into $\\mathbb{N}$, through\nthree equations:\n\n\\begin{align}\nA(0,n)&=n+1\\\\\nA(m+1,0)&=A(m,1)\\\\\nA(m+1,n+1)&=A(m,A(m+1,n))\n\\end{align}\n\nLet us try to define this function in \\coq{} (in curried form).\n\n\\begin{Coqsrc}\nFail\n  Fixpoint Ack (m n : nat) : nat :=\n  match m, n with\n  | 0, n => S n\n  | S m, 0 => Ack m 1\n  | S m0, S p => Ack m0 (Ack m p)\n  end.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\nThe command has indeed failed with message:\nCannot guess decreasing argument of fix.\n\\end{Coqanswer}\n\nA possible workaround is to make \\texttt{m} be the \ndecreasing argument, and define --- within \\texttt{m}'s scope --- a local helper function which computes (\\texttt{Ack m n}) for any \\texttt{n}.\nThis way, both functions \\texttt{Ack} and \\texttt{Ackm} have a (structurally) strictly decreasing argument.\n\n\\begin{Coqsrc}\nModule Alt.\n\n   Fixpoint Ack (m n : nat) : nat :=\n     match m with\n     | O => S n\n     | S p => let fix Ackm (n : nat) :=\n                  match n with\n                  | O => Ack p 1\n                  | S q => Ack p (Ackm q)\n                  end\n              in Ackm n\n     end.\n\n    Compute Ack 3 2.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n  = 29 : nat\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nEnd Alt.\n\\end{Coqsrc}\n\nWe prefered to define a variant which uses explicitely \n the functional \\texttt{iterate},\nwhere (\\texttt{iterate\\,$f$\\,$n$})\nis the $n$-th iteration of $f$\\,\\footnote{Please not confuse with \\texttt{primRec.iterate}, which is monomorphic and does not share the same order of arguments.}. It makes it possible to apply a few lemmas proved in \n\\href{../theories/html/hydras.Prelude.Iterates.html}{Prelude.Iterates}, for instance about the monotony of the $n$-th iterate of a given function. \n\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.Prelude.Iterates.html}{Prelude.Iterates}}.\n\\index{hydras}{Library Prelude!iterate}\n\\begin{Coqsrc}\nFixpoint iterate {A:Type}(f : A -> A) (n: nat)(x:A) :=\n  match n with\n  | 0 => x\n  | S p => f (iterate  f p x)\n  end.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma iterate_le_n_Sn:\nforall f : nat -> nat,\n(forall x : nat, x <= f x) ->\nforall n x : nat, iterate f n x <= iterate f (S n) x.\n\\end{Coqsrc}\n\n\n\n\n\nThus, our definition of the Ackermann function is as follows:\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.Ack.html}{MoreAck.Ack}}.\n\\index{maths}{Ackermann function}\n\\index{primrec}{Ackermann function}\n\n\\begin{Coqsrc}\nFixpoint Ack (m:nat) : nat -> nat :=\n  match m with\n  | 0 => S\n  | S n => fun k =>  iterate (Ack n) (S k) 1\n  end.\n\nCompute Ack 3 2.\n\\end{Coqsrc}\n \n\\begin{Coqanswer}\n  = 29 : nat\n\\end{Coqanswer}\n\n\n\n\n\n\n\\index{hydras}{Exercises}\n\n\\begin{exercise}\nThe file \\href{../theories/html/hydras.MoreAck.Ack.html}{MoreAck.Ack} presents two other definitions\\footnote{post on \\href{https://stackoverflow.com/questions/10292421/error-in-defining-ackermann-in-coq} by Anton Trunov.} of the Ackermann functions based on the lexicographic ordering on $\\mathbb{N}\\times\\mathbb{N}$.\nProve that the four functions are extensionnally equal.\n\\end{exercise}\n\n\n\\subsubsection{First properties of the Ackermann function}\n\nThe three first lemmas make us sure that our function \n\\texttt{Ack} satifies the ``usual'' equations.\n\n\\begin{Coqsrc}\nLemma Ack_0 : Ack 0 = S.\nProof refl_equal.\n\nLemma Ack_S_0 m : Ack (S m) 0 = Ack m 1. \nProof. reflexivity. Qed.\n\nLemma Ack_S_S : forall m p,\n    Ack (S m) (S p) = Ack m (Ack (S m) p).\nProof. reflexivity. Qed.\n\\end{Coqsrc}\n\nThe order of growth of the Ackermann function w.r.t. its first argument is illustrated by the following equalities.\n\n\\begin{Coqsrc}\nLemma Ack_1_n n: Ack 1 n = S  (S n).\n\nLemma Ack_2_n n: Ack 2 n = 2 * n + 3.\n\nLemma Ack_3_n n: Ack 3 n = exp2 (S (S (S n))) - 3.\n\nLemma Ack_4_n n: Ack 4 n = hyper_exp2 (S (S (S n))) - 3.\n\\end{Coqsrc}\n\n\n\\begin{remark}\n The statements above can be rewritten in a more uniform way:\n\n \\begin{quote}\n   For $m\\in 1..4$, $\\texttt{Ack}\\,m\\,n = f_m\\,(n+3)-3$, where \n   \\begin{align*}\n   f_1(n)=&\\,n+2 \\\\\n   f_2(n)=&\\,n\\times 2\\\\\n   f_3(n)=&\\,2^n\\\\\n   f_4(n)=&\\,2^{2^{\\dots^2}}\\quad(n\\;\\textit{levels})\n   \\end{align*}\n \\end{quote}\n\\end{remark}\n\n\nAn important property of the Ackermann function helps us \nto overcome the difficulty raised by nested recursion, by climbing up the hierarchy $\\texttt{Ack}\\,n\\,\\_\\;(n\\in\\mathbb{N})$.\n\n\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.Ack.html}{MoreAck.Ack}}.\n\\begin{Coqsrc}\nLemma nested_Ack_bound : forall k m n, \n    Ack k (Ack m n) <= Ack (2 + max k m) n.\n\\end{Coqsrc}\n\n\n\nPlease note also that for any given $n$, the unary function\n(\\texttt{Ack\\,$n$}) is primitive recursive.\n\n\\vspace{4pt}\n\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.AckNotPR.html}{MoreAck.AckNotPR}}.\n\\begin{Coqsrc}\nTheorem Ackn_IsPR (n: nat) : isPR 1 (Ack n).\n\\end{Coqsrc}\n\n\n\n\\subsection{A proof by induction on all primitive recursive functions}\n\n\u00ccn order to prove that \\texttt{Ack} (considered as a function of two arguments) is not primitive recursive, the usual method consists in two steps:\n\n\n\\begin{enumerate}\n\\item Prove that for any primitive recursive function $f:\\mathbb{N}\\rightarrow\\mathbb{N}\\rightarrow\\mathbb{N}$, there exists some natural number $n$ depending on $f$, such that, for any $x$ and $y$, \n$f\\,x\\,y \\leq \\texttt{Ack}\\,n\\,(\\textrm{max}\\,x\\,y)$ (we say that $f$ is \\emph{``majorized''}  by \\texttt{Ack}).\n\\item Show that \\texttt{Ack} fails to satisfy this property.\n\\end{enumerate}\n\nFirst, we prove that any primitive function of two arguments is majorized by \\texttt{Ack}.\nIf we look at the inductive definition of primitive recursive functions, page~\\pageref{def:Primrec}, it is obvious that a proof by induction on the construction of primitive recursive functions must consider functions of any arity.\n\nThe following scheme allows us to write proofs by induction on the class of primitive recursive functions. \n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}.}\n\n\\index{coq}{Commands!Scheme}\n\\begin{Coqsrc}\nScheme PrimRec_PrimRecs_ind := Induction for PrimRec\n  Sort Prop\n  with PrimRecs_PrimRec_ind := Induction for PrimRecs \n  Sort Prop.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\nPrimRec_PrimRecs_ind :\nforall (P : forall n : nat, PrimRec n -> Prop)\n  (P0 : forall n n0 : nat, PrimRecs n n0 -> Prop),\n(* successor *)\nP 1 succFunc ->\n\n(* zero *)\nP 0 zeroFunc ->\n\n(* projections *)\n(forall (n m : nat) (l : m < n), P n (projFunc n m l)) ->\n\n(* composition *) \n(forall (n m : nat) (g : PrimRecs n m),\n      P0 n m g -> forall h : PrimRec m, P m h -> \n      P n (composeFunc n m g h)) ->\n\n(* primitive recursion *)\n(forall (n : nat) (g : PrimRec n),\n P n g ->\n    forall h : PrimRec (S (S n)), P (S (S n)) h -> \n     P (S n) (primRecFunc n g h)) ->\n\n(* empty list of functions *)\n(forall n : nat, P0 n 0 (PRnil n)) ->\n\n(* add a function to a list *)\n(forall (n m : nat) (p : PrimRec n),\n   P n p -> \n   forall p0 : PrimRecs n m, P0 n m p0 -> \n   P0 n (S m) (PRcons n m p p0)) ->\n\n(* conclusion ! *)\nforall (n : nat) (p : PrimRec n), P n p\n\\end{Coqanswer}\n\nFor instance, proving a property shared by any primitive recursive function of arity 2 leads to consider the case where that function is obtained by composition with a function of any \narity $m$. The same problem happens with primitive \nrecursion, where a function of arity $n$ is built out of a function of arity $n+1$ and a function of arity $n-1$.\n\nThus the lemma we will have to prove is the following one:\n\n\n  \\begin{quote}\n    For any $n$, and any primitive recursive function $f$ of  arity $n$, there exists some natural number $q$ such that the following inequality holds:\n \\[\n  \\forall x_1,\\dots,x_n, \n      f(x_1,\\dots,\\,x_n)\\leq\\textrm{Ack}(q,\\textrm{max}(x_1,\\dots,x_n))\n\\]\n \\end{quote}\n\n\nBut dots don't belong to \\gallina's syntax! So, we may use \\coq's vectors for denoting arbitrary tuples.\n\nFirst, we extend \\texttt{max} to vectors of natural numbers (using the notations of module \\texttt{VectorNotations} and some more definitions from \n\\href{../theories/html/hydras.Prelude.MoreVectors.html}{Prelude.MoreVectors}). So, (\\texttt{t\\,$A$\\,$n$}) is the type of vectors of $n$ elements of type $A$, and the constants \\texttt{cons}, \\texttt{nil}, \\texttt{map}, etc., refer to vectors and not to lists. Likewise, the notation \\texttt{x::v} is an abbreviation for\n\\texttt{VectorDef.cons x \\_ v}.\n\n\\index{coq}{Dependently typed functions}\n\\begin{Coqsrc}\nFixpoint max_v {n:nat} : forall (v: Vector.t nat n) , nat :=\n  match n as n0 return (Vector.t nat n0 -> nat)\n  with\n    0 => fun v => 0\n  | S p => fun (v : Vector.t nat (S p)) =>\n             max (Vector.hd v) (max_v  (Vector.tl v))\n  end. \n\nLemma max_v_2 : forall x y,  max_v (x::y::nil) = max x y.\n\nLemma max_v_lub : forall n (v: t nat n) y,\n    (Forall (fun x =>  x <= y) v) -> max_v v <= y.\n\nLemma max_v_ge : forall n (v: t nat n) y,  In  y  v -> y <= max_v v.\n\\end{Coqsrc}\n\n\nWe have also to convert any application\n$(f\\,x_1\\,x_2\\,\\dots\\,x_n)$ into an application of a function \nto a single argument: the vector of all the $x_i$\\,s.\nThis is already defined in \nLibrary~\\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}.\n\n\n\\begin{Coqsrc}\nFixpoint evalList (m : nat) (l : Vector.t nat m) {struct l} :\n naryFunc m -> nat :=\n  match l in (Vector.t _ m) return (naryFunc m -> nat) with\n  | Vector.nil => fun x : naryFunc 0 => x\n  | Vector.cons a n l' => fun x : naryFunc (S n) => evalList n l' (x a)\n  end.\n\\end{Coqsrc}\n\nIndeed, (\\texttt{evalList $m$ $v$ $f$}) is the application to the vector $v$ of\nan uncurried version of $f$.\nIn Library\\href{../theories/html/hydras.MoreAck.AckNotPR.html}{MoreAck.AckNotPR}, we introduce a lighter notation.\n\n\\index{coq}{Dependently typed functions}\n\\begin{Coqsrc}\n(**  uncurried apply:\n \n[v_apply f (x1::x2:: ... ::xn::nil)]  is [f x1 x2 ... xn] \n *)\n\nNotation \"'v_apply' f v\" := (evalList _ v f) \n     (at level 10, f at level 9).\n\nExample Ex2: forall (f: naryFunc 2) x y,\n    v_apply f (x::y::nil) = f x y.\nProof.   intros; now cbn. Qed.\n\nExample Ex4: forall (f: naryFunc 4) x y z t,\n    v_apply f (x::y::z::t::nil) = f x y z t.\nProof.  intros; now cbn. Qed.\n\\end{Coqsrc}\n\nWe are now able to translate in \\gallina{} the notion of ``majorization'':\n\n\\index{coq}{Dependently typed functions}\n\\begin{Coqsrc}\nDefinition majorized {n} (f: naryFunc n) (A: naryFunc 2) : Prop :=\n  exists (q:nat), forall (v: t nat n),\n      v_apply f v <= A q  (max_v v).\n\nDefinition majorizedPR {n} (x: PrimRec n) A := \n           majorized (evalPrimRec n x) A.\n\n(** For vectors of functions *)\n\nDefinition majorizedS {n m} (fs : Vector.t (naryFunc n) m)\n           (A : naryFunc 2):=\n  exists N, forall (v: t nat n),\n      max_v (map (fun f => v_apply f v) fs) <= A N (max_v v).\n\nDefinition majorizedSPR {n m} (x : PrimRecs n m) :=\n  majorizedS (evalPrimRecs _ _ x).\n\\end{Coqsrc}\n\nNow, it remains to prove that any primitive function is majorized by \\texttt{Ack}.\nThe three base cases  are as follows:\n\n\\begin{Coqsrc}\nLemma majorSucc : majorizedPR  succFunc Ack.\n\nLemma majorZero : majorizedPR  zeroFunc Ack.\n\nLemma majorProjection (n m:nat)(H: m < n):\n  majorizedPR (projFunc n m H) Ack.\n\\end{Coqsrc}\n\n\nThe rest of the cases are proved within a mutual  induction.\n\n\\index{coq}{Mutual induction}\n\n\\begin{Coqsrc}\nLemma majorAnyPR:  forall n (x: PrimRec n),  majorizedPR  x Ack.\nProof.\n  intros n x; induction x using PrimRec_PrimRecs_ind with\n                  (P0 := fun n m y => majorizedSPR  y Ack).\n  - apply majorSucc.\n  - apply majorZero.\n  - apply majorProjection. \n  \\end{Coqsrc}\n\n  \\begin{Coqsrc}\n  - (** function composition *)\n\\end{Coqsrc}\n\\begin{Coqanswer}\n1 subgoal (ID 265)\n\n  n, m : nat\n  g : PrimRecs n m\n  x : PrimRec m\n  IHx : majorizedSPR g Ack\n  IHx0 : majorizedPR x Ack\n  ============================\n  majorizedPR (composeFunc n m g x) Ack\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n  ...\n - (** primitive recursion *)\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n1 subgoal (ID 265)\n  \n  n : nat\n  x1 : PrimRec n\n  x2 : PrimRec (S (S n))\n  IHx1 : majorizedPR x1 Ack\n  IHx2 : majorizedPR x2 Ack\n  ============================\n  majorizedPR (primRecFunc n x1 x2) Ack\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n assert (L1 : forall i (v: t nat n) ,\n               v_apply f (i::v)  <= Ack q (i + max_v v)).\n    { induction i.\n      ...\n    }\n    ...\n-  (** empty list of functions *)\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n1 subgoal (ID 266)\n  \n  n : nat\n  ============================\n  majorizedSPR (PRnil n) Ack\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n  ...\n- (** non-empty list of functions *)\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n1 subgoal (ID 273)\n  \n  n, m : nat\n  x : PrimRec n\n  p : PrimRecs n m\n  IHx : majorizedPR x Ack\n  IHx0 : majorizedSPR p Ack\n  ============================\n  majorizedSPR (PRcons n m x p) Ack\n\\end{Coqanswer}\n  \n\\begin{Coqsrc}\n ...\nQed.\n\\end{Coqsrc}\n\n\\subsection{Looking for a contradiction}\n\nThe following lemma is just a specialization of \\texttt{majorAnyPR} to\nbinary functions (forgetting vectors, coming back to usual notations).\n\n\\begin{Coqsrc}\nLemma majorPR2 (f: naryFunc 2)(Hf : isPR 2 f)\n  : exists (n:nat), forall x y,  f x y <= Ack n (max x  y).\n\\end{Coqsrc}\n\nWe prove also a strict version of this lemma, thanks to the following property (proved in Library\n\\href{../theories/html/hydras.MoreAck.Ack.html}{MoreAck.Ack}~).\n\n\\begin{Coqsrc}\nLemma Ack_strict_mono_l : forall n m p, n < m ->\n                                        Ack n (S p) < Ack m (S p).\n\\end{Coqsrc}\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.AckNotPR.html}{MoreAck.AckNotPR}.}\n\n\\begin{Coqsrc}\nLemma majorPR2_strict (f: naryFunc 2)(Hf : isPR 2 f):\n    exists (n:nat),\n    forall x y, 2 <= x -> 2 <= y -> f x y < Ack n (max x  y).\n\\end{Coqsrc}\n\n\n\nIf the Ackermann function were primitive recursive, then there would exist some natural number $n$, such that, for all $x$ and $y$, the inequality \n$\\texttt{Ack}\\,x\\,y\\leq \\texttt{Ack}\\,n\\,(\\texttt{max}\\,x\\,y)$ holds.\nThus, our impossibility proof is just a sequence of easy small steps.\n\n\\begin{Coqsrc}\nSection Impossibility_Proof.\n\n  Hypothesis HAck : isPR 2 Ack.\n  \n  Lemma Ack_not_PR : False.\n  Proof.\n    destruct (majorPR2_strict Ack HAck) as [m Hm];\n    pose (X := max 2 m); specialize (Hm X X).\n    rewrite max_idempotent in Hm; \n    assert (Ack m X <= Ack X X) by (apply Ack_mono_l; lia).\n    lia.\n  Qed.\n\nEnd Impossibility_Proof.\n\\end{Coqsrc}\n\n\n\\begin{remark}\nIt is easy to prove that any unary function which dominatates \\texttt{fun n => Ack n n} fails to be primitive recursive. We use an instance of \\texttt{majorAnyPR} for unary functions.\n\n\\vspace{4pt}\n\\noindent\n\n\\emph{From \\href{../theories/html/hydras.MoreAck.AckNotPR.html}{MoreAck.AckNotPR}}.\n\\begin{Coqsrc}\nLemma majorPR1  (f: naryFunc 1)(Hf : isPR 1 f)\n  : exists (n:nat), forall x, f x <= Ack n x.\n(* ... *)\n\\end{Coqsrc}\n\nThen, we write  a short proof by contradiction.\n\n\\begin{Coqsrc}\nSection dom_AckNotPR.\n\n  Variable f : nat -> nat.\n  Hypothesis Hf : dominates f (fun n => Ack n n).\n\n Lemma dom_AckNotPR: isPR 1 f -> False.\n  Proof.\n    intros H;  destruct Hf as [N HN].\n    destruct  (majorPR1 _ H) as [M HM].\n    pose (X := Max.max N M).\n    specialize (HN X  (Max.le_max_l N M)).\n    specialize (HM X);\n      assert (Ack M X <= Ack X X) by (apply Ack_mono_l; subst; lia).\n    lia.\n  Qed.\n\nEnd dom_AckNotPR.\n\\end{Coqsrc}\n\\end{remark}\n\n\\begin{remark}\nNote that the Ackermann function is a counter-example to the (false) statement:\n\\begin{quote}\n{\\color{red}\n  ``Let $f$ be a function of type \\texttt{naryFunc\\,2}. If, for any $n$, the fonction $f(n)$ is primitive recursive, then f is primitive recursive.''}\n\\end{quote}\n\\end{remark}\n\n\n\\section{The length of standard hydra battles}\n\\label{sect:battle-length-notPR}\n\nThe module \\href{../theories/html/hydras.Hydra.Hydra_Theorems.html}{Hydra\\_Theorems} contains a proof that the function which computes the length of standard hydra battles is not primitive recursive. More precisely, we consider, for a given hydra $h=\\iota(\\alpha)$, the length of a standard battle which starts with the replication factor $k$ (see Sect~\\vref{def:L-alpha}).\n\nThis proof is  a little more complex than the preceding one.\n\n\\subsection{Definitions}\n\nThe function we consider is defined and proven correct in\nModule~\\href{../theories/html/hydras.Hydra.Battle_length.html}{Hydra.Battle\\_length}.\n\n\\begin{Coqsrc}\nDefinition l_std alpha k := (L_ alpha (S k) - k)%nat.\n\nLemma l_std_ok : forall alpha : E0,\n    alpha <> Zero ->\n    forall k : nat,\n      1 <= k -> battle_length standard k (iota (cnf alpha))\n                              (l_std alpha k).\n(* ... *)\n\\end{Coqsrc}\n\n\\subsection{Proof steps}\n\nNow, let us assume that the function \\texttt{l\\_std} is primitive recursive.\n\n\n\\emph{From \\href{../theories/html/hydras.Hydra.Hydra_Theorems.html}{Hydra.Hydra\\_Theorems}}.\n\n\\begin{Coqsrc}\nSection battle_lenght_notPR.\n\n  (** We assume that the function with computes the length \n      of standard battles is primitive recursive *)\n  \n  Hypothesis H: forall alpha, isPR 1 (l_std alpha). \n\\end{Coqsrc}\n\nLet us consider the hydra represented by the ordinal $\\omega^\\omega$.\n\n\\begin{Coqsrc}\nLet alpha := Phi0 omega%e0.\nLet h := iota (cnf alpha).\n\\end{Coqsrc}\n\nIn order to get rid of the substraction in the definition of \\texttt{l\\_std}, we work with a helper function.\n\n\\begin{Coqsrc}\nLet m k := L_ alpha (S k).\n\nRemark m_eqn : forall k, m k = (l_std alpha k + k)%nat.\n(* ... *)\n\\end{Coqsrc}\n\nUnder the hypothesis \\texttt{H}, $m$ is also primitive recursive.\n\n\\begin{Coqsrc}\nRemark mIsPR : isPR 1 m.\n(* ... *)\n\\end{Coqsrc}\n\n\n\\subsubsection{Comparison between $F$ and $H'$}\n\nIn \\href{../theories/html/hydras.Epsilon0.F_alpha.html}{Epsilon0.F\\_alpha}, we prove a relation between the $F$ and $H'$ functional. For any $\\alpha$ and $k>0$,\n$H'_{\\omega^\\alpha}(k)\\geq F_\\alpha(k)$.\n\n\\begin{Coqsrc}\nH'_F : forall (alpha : E0) (n : nat), \n     F_ alpha (S n) <= H'_ (Phi0 alpha) (S n) \n\\end{Coqsrc}\n\n\nOur proof of this lemma is not trivial at all. One of it sub-goals is the following one:\n\n\\begin{Coqsrc}\n  alpha : E0\n  IHalpha : forall beta : E0, beta o< alpha -> P beta\n  Halpha : Limitb alpha\n  n : nat\n  ============================\n  H'_ (Phi0 (CanonS alpha n)) (S n) <= \n  H'_ (Phi0 (CanonS alpha (S n))) (S n)\n\\end{Coqsrc}\n\nIn mathematical notation: $H'_{\\omega^{\\canonseq{\\alpha}{n}}}(n+1) \\leq\nH'_{\\omega^{\\canonseq{\\alpha}{n+1}}}(n+1)$.\n\n\\vspace{4pt}\n\nBut there exists no lemma saying that, if \n$\\beta\\leq \\alpha$, then $H'_\\beta(k)\\leq H'_\\alpha(k)$, for any $\\alpha$ and $\\beta$. For instance, \n$H'_{42}(3)=45> H'_\\omega(3)=7$.\n\n\nLooking for lemmas of the form $H'_\\beta(k)\\leq H'_\\alpha(k)$, we find this one (from our library\n\\href{../theories/html/hydras.Epsilon0.Hprime.html}{Epsilon0.Hprime}):\n\n\\begin{Coqanswer}\nH'_restricted_mono_l : \n    forall (alpha beta : E0) (n : nat), \n      Canon_plus n alpha beta -> \n      H'_ beta n <= H'_ alpha n.\n\\end{Coqanswer}\n\nThus, it remains to prove that \nthere exists a path from ${\\omega^{\\canonseq{\\alpha}{n+1}}}$\nto ${\\omega^{\\canonseq{\\alpha}{n}}}$ composed of \n$n+1$-steps.\n\nFortunately, the Ketonen-Solovay machinery contains three lemmas which help us to build such a path.\n\n\n\\begin{Coqanswer}\nKS_thm_2_4_lemma5 :\n  forall [i : nat] [alpha beta : T1],\n  const_pathS i alpha beta ->\n  nf alpha -> alpha <> zero -> \n  const_pathS i (phi0 alpha) (phi0 beta)\n\nKS_thm_2_4 :\n  forall [lambda : T1], nf lambda ->limitb lambda ->\n  forall i j : nat, i < j -> \n   const_pathS 0 (canonS lambda j) (canonS lambda i)\n\nCor12_1 :\nforall [alpha : T1], nf alpha ->\n      forall (beta : T1) (i n : nat),\n      beta t1< alpha ->\n     i <= n -> const_pathS i alpha beta -> \n     const_pathS n alpha beta\n\\end{Coqanswer}\n  \n\\subsubsection{End of the proof}\n\nWe finish the proof by comparing several fast growing functions.\n\n\\emph{From \\href{../theories/html/hydras.Epsilon0.L_alpha.html}{Epsilon0.L\\_alpha}}\n\n\\begin{Coqsrc}\nH'_L_ : forall (alpha : E0) (i : nat), H'_ alpha i <= L_ alpha (S i)\n\\end{Coqsrc}\n\n\n\\emph{From \\href{../theories/html/hydras.Epsilon0.F_omega.html}{Epsilon0.F\\_omega}}\n\n\\begin{Coqsrc}\nF_vs_Ack : forall n : nat, 2 <= n -> Ack n n <= F_ omega n\n\\end{Coqsrc}\n\n\n\nBy transitivity, we get the inequality\n$F_\\omega(k+1)\\leq m(k+1)$, for any $k$.\n\n\\begin{Coqsrc}\nRemark m_ge_F_omega : forall k,  F_ omega (S k) <= m (S k).\n\\end{Coqsrc}\n\n\nWe finish the proof by noting that the function $m$ (composed with \\texttt{S}) dominates the Ackermann function, which leads to a contradiction.\n\n\\begin{Coqsrc}\nRemark m_dominates_Ack : \n     dominates (fun n =>  S (m n)) (fun n => Ack.Ack n n).\n(* ... *)\n\nRemark SmNotPR : isPR 1 (fun n => S (m n)) -> False.\n(* ... *)\n\nTheorem LNotPR : False.\n  Proof.\n    apply SmNotPR,  compose1_1IsPR.\n    - apply mIsPR.\n    - apply succIsPR.\n  Qed.\n\nEnd battle_lenght_notPR.\n\\end{Coqsrc}\n\n", "meta": {"hexsha": "31dcec1529f9d14de6ec570b8650d389fceb6204", "size": 47647, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/chapter-primrec.tex", "max_stars_repo_name": "start974/hydra-battles", "max_stars_repo_head_hexsha": "83322c9b4e8522c1bde2d6151d61105ca3c012ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/chapter-primrec.tex", "max_issues_repo_name": "start974/hydra-battles", "max_issues_repo_head_hexsha": "83322c9b4e8522c1bde2d6151d61105ca3c012ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/chapter-primrec.tex", "max_forks_repo_name": "start974/hydra-battles", "max_forks_repo_head_hexsha": "83322c9b4e8522c1bde2d6151d61105ca3c012ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.6591362126, "max_line_length": 373, "alphanum_fraction": 0.6809033098, "num_tokens": 15142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8774767986961403, "lm_q1q2_score": 0.8028043651833445}}
{"text": "\\section{Random Walk on a Grid} \nA `particle' takes a random walk on a $4 \\times 8$ grid. At each step of the walk, the particle may move up, down, left, or right with equal probability. The particle continues this process until it exits the grid. If the particle exits the top of the grid, the particle scores 1 point for the walk. If the particle exits the left, bottom or right sides of the grid, the particle scores 0 points for the walk. \nIn this project, you will compute the expected score of the particle as a function of the starting coordinates.\\\\\n\n\\noindent \\textit{Hint:} For each starting point, you may estimate the expected score of the particle by simulating many, many random paths and taking their average score.\\\\\n\\begin{center}\n\\begin{tikzpicture}\n    \\pgfmathsetmacro{\\N}{8}\n    \\pgfmathsetmacro{\\M}{4}\n    \\draw[thick, densely dotted] (1,1) grid (\\N,\\M);\n    \\draw[line width = 3,color = green, opacity = .5,->] (3,2) -- (4,2) --(4,3) --(5,3) -- (6,3) --(6,4) --(5,4) -- (5,4.5);\n    \\draw[line width = 3,color = purple, opacity = .5,->] (3,2) -- (3,1) --(2,1) --(2,0.5);\n    \\draw[line width = 3,color = orange, opacity = .5,->] (3,2) -- (2,2) --(2,3) --(1,3) -- (1,2)--(0.5,2);\n    % Right\n    \\foreach \\j in {1,...,\\M}\n    {\n    \\draw[thick, densely dotted] (\\N+1,\\j) -- (\\N,\\j);\n    \\draw[ultra thick,color=orange!50!black,fill = white] (\\N+1,\\j) node {0} circle (.3);\n    }\n    % Top\n    \\foreach \\i in {1,...,\\N}\n    {\n        \\draw[thick, densely dotted] (\\i,\\M) -- (\\i,\\M+1);\n        \\draw[ultra thick,color=blue!50!black,fill = white] (\\i,\\M+1) node {1} circle (.3);\n    }\n    % Left\n    \\foreach \\j in {1,...,\\M}\n    {\n        \\draw[thick, densely dotted] (1,\\j) -- (0,\\j);\n        \\draw[ultra thick,color=orange!50!black,fill = white] (0,\\j) node {0} circle (.3);\n    }\n    % Bottom\n    \\foreach \\i in {1,...,\\N}\n    {\n        \\draw[thick, densely dotted] (\\i,0) -- (\\i,1);\n        \\draw[ultra thick,color=orange!50!black,fill = white] (\\i,0) node {0} circle (.3);\n    }\n    \\draw[color = black,fill=black!70!white,opacity = .7] (3,2) circle  (.2);\n\\end{tikzpicture}\n\\end{center}\n\\textit{Illustration:} The figure shows three sample paths of the random walk that all begin at the initial point (3,2). For the red path, the particle (randomly) takes the steps $(\\downarrow, \\leftarrow, \\downarrow)$, and exits the grid at the bottom scoring zero points for the walk. The other paths are the results of the steps:\n\\begin{align*}\n&\\text{Steps: }  (\\downarrow \\ \\leftarrow \\ \\downarrow) &&\\text{(See red path)} && \\text{Exit: Bottom} && \\text{Score: 0}\\\\\n&\\text{Steps: }  (\\leftarrow \\ \\uparrow \\ \\leftarrow \\ \\downarrow \\ \\leftarrow) &&\\text{(See orange path)} && \\text{Exit: Left} && \\text{Score: 0}\\\\\n&\\text{Steps: }  (\\rightarrow \\ \\uparrow \\ \\rightarrow \\ \\rightarrow \\ \\uparrow \\ \\leftarrow \\ \\uparrow) &&\\text{(See green path)}&& \\text{Exit: Top} && \\text{Score: 1}\n\\end{align*}\n\n\n\n\\noindent\\textit{Bonus:} In this project, we have computed the solution to a problem by simulating many random events. This `indirect' approach is always computationally inefficient, so it is often worth looking for a `direct' approach. For this problem, there \\textit{is} a method of computing the solution directly. Can you find it?\n\n", "meta": {"hexsha": "3841b2d6afa598a09cadbbaa47c1c3c98d035da3", "size": 3254, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "random-walk.tex", "max_stars_repo_name": "colinlclark/integration_workshop", "max_stars_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "random-walk.tex", "max_issues_repo_name": "colinlclark/integration_workshop", "max_issues_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "random-walk.tex", "max_forks_repo_name": "colinlclark/integration_workshop", "max_forks_repo_head_hexsha": "16845412db0bd18469db67075d31a6189d968c56", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-07-25T18:18:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-27T01:10:02.000Z", "avg_line_length": 62.5769230769, "max_line_length": 410, "alphanum_fraction": 0.6355255071, "num_tokens": 1070, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.9149009596336303, "lm_q1q2_score": 0.8028043549233712}}
{"text": "\\subsection{Degree of Connectedness}\n  We would like to have a measure of how well connected is the graph. A network with a lot of disconnected cliques should\n  score lower than a loosely connected network. This measure can be expressed as the expected indirect trust, defined\n  incrementally as follows:\n  \\begin{align*}\n    Tr(A) = \\sum\\limits_{B \\in \\mathcal{V} \\setminus \\{A\\}}Tr_{A \\rightarrow B} && \\mbox{ (Total indirect trust for player\n    }A\\mbox{)} \\\\\n    ETr\\left(A\\right) = \\frac{Tr(A)}{|\\mathcal{V} \\setminus \\{A\\}|} = \\frac{Tr(A)}{|\\mathcal{V}| - 1} && \\mbox{ (Expected\n    indirect trust for player }A\\mbox{)} \\\\\n    ETr = \\frac{1}{|\\mathcal{V}|}\\sum\\limits_{A \\in \\mathcal{V}}ETr\\left(A\\right) && \\mbox{ (Expected indirect trust)}\n  \\end{align*}\n", "meta": {"hexsha": "89b21f6bc98ed9cc9e8598bc6b42b5de700505f5", "size": 763, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "may31deliverable/networkhealth/expectedtrust.tex", "max_stars_repo_name": "OrfeasLitos/TrustNet", "max_stars_repo_head_hexsha": "dfd45afb78ba92d7c0b0a64222aaf173e9627c09", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2017-03-15T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T14:07:45.000Z", "max_issues_repo_path": "may31deliverable/networkhealth/expectedtrust.tex", "max_issues_repo_name": "OrfeasLitos/DecentralisedTrustNetwork", "max_issues_repo_head_hexsha": "dfd45afb78ba92d7c0b0a64222aaf173e9627c09", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2017-03-07T12:25:26.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-31T14:42:20.000Z", "max_forks_repo_path": "may31deliverable/networkhealth/expectedtrust.tex", "max_forks_repo_name": "OrfeasLitos/DecentralisedTrustNetwork", "max_forks_repo_head_hexsha": "dfd45afb78ba92d7c0b0a64222aaf173e9627c09", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-03-07T10:49:58.000Z", "max_forks_repo_forks_event_max_datetime": "2017-08-28T06:32:33.000Z", "avg_line_length": 63.5833333333, "max_line_length": 122, "alphanum_fraction": 0.6736566186, "num_tokens": 250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305318133554, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.8026836871347762}}
{"text": "\\chapter{Selection}\n\nConsider the following problem: given an array $A$ of $n$ elements,\noutput the $i$-th smallest element of $A$.\n\nAs a simple first solution, we can sort $A$ and then return $A[i]$.\nSince sorting takes $O(nlogn)$ time and returning $A[i]$ takes $O(1)$\ntime, this solution takes $O(nlogn) + O(1) = O(nlogn)$ time.\n\nBut it should be easy to see that we can do better in specific cases\nlike $i=1$ or $i=n$.  Simply iterate once over the array and store the\nminimum ($i=1$) or maximum ($i=n$) value.  Since looking at a\nparticular element of the array takes $O(1)$ time, and we look at all\n$n$ elements, this takes total $n \\cdot O(1) = O(n)$ time.\n\nWe can also tell that this is optimal, because we know that to\ndetermine the $i$-th element, we need to look at all $n$ elements in\nthe array, so we have a lower bound of $\\Omega (n)$ time.\n\nBut is this possible in general, for any value of $i$?  Yes.\n\nSuppose in linear time we can find element $x$ such that\n\n{\n  % Current graphic is hand-drawn by John Howat.\n  % Should replace asap with a nicer diagram\n  \\includegraphics[scale=0.6]{selection}\n  %\\caption{Desirable properties of element x.}\n  \\label{fig:selection}\n}\n\n$x$ is somewhere around the middle of the array, and is preceded only\nby elements smaller than $x$, and followed only by elements larger\nthan $x$.  We also know that there are $ \\geq (1-\\alpha)n $ and $ \\leq\n\\alpha n $ elements both before and after $x$.\n\nWe can calculate this $x$ as follows:\n\n\\begin{enumerate}\n\n\\item Split $A$ into groups of 5.  There will be $\\frac{n}{5}$ of\n  these groups.\n\\item Compute the median $m_j$ of each group $M_j$ for $ 1 \\leq j \\leq\n  \\frac{n}{5} $.\n\\item Compute the median $x$ of $m_1,m_2,...,m_{n/5}$.\n\n\\end{enumerate}\n\nIt should be clear that step 1 takes constant time, step 2 takes\nconstant time for each group of constant size and $O(n)$ time total\nfor all $\\frac{n}{5}$ groups, and step 3 takes $T(n/5)$ time.\n\n\\begin{claim}\nThis $x$ has the properties we needed above.\n\\end{claim}\n\n\\begin{proof}\n\nWe know that $\\frac{1}{2}$ of $m_j$ are smaller than $x$, and since\nthere are $ \\frac{n}{5} m_j$s, we know $\\frac{n}{10}$ of $m_j$ are $\n\\leq x $.\n\nSo for each $m_j$ where $m_j \\leq x$ \n\n\\begin{itemize} \n\n\\item there are 3 elements that are $ \\leq m_j $\n\\item so 3 (or more) elements are $ \\leq x $\n\n\\end{itemize}\n%\n\\end{proof}\n%\nNow we must put $x$ into its position in the array using partitioning.\nAs a side note, partitioning is used in quicksort.\n\n\\begin{enumerate}\n\n\\item Find $x$, put it at the end\n\\item Partition elements around $x$\n\\item Put $x$ into its proper position\n\n\\end{enumerate}\n\nWe now have an $x$ that satisfies the properties we needed, and it is\nproperly located at position $q$ in $A$.  We are left with 3 cases:\n\n\\begin{enumerate}\n\n\\item If $i = q$: $x$ is the $i$-th element of $A$.\n\\item If $i < q$: recurse on the subarray which is $ < x $\n\n\\item If $i > q$: recurse on the subarray which is $ > x $, and $ i\n  \\leftarrow i - q $\n\n\\end{enumerate}\n\nThis last step gives a recurrence of $ T \\left( \\frac{7n}{10} \\right)\n$ in the worst case because at least $ \\frac{3n}{10} $ elements in $A$\nare smaller than $x$.\n\n\\section{Analysis}\n\nWe now have the following recurrence:\n%\n\\begin{displaymath}\nT(n) = T \\left( \\frac{n}{5} \\right) +T \\left( \\frac{7n}{10} \\right) + O(n)\n\\end{displaymath}\n\n\\begin{claim}\n$ T(n) \\leq cn $\n\\end{claim}\n\n\\begin{proof}\n\\begin{align*}\nT(n)\n&= dn + T \\left( \\frac{n}{5} \\right) +T \\left( \\frac{7n}{10} \\right) \\\\\n&\\leq dn + c \\frac{n}{5} + c \\frac{7n}{10} \\\\\n&= dn + \\frac{9}{10}cn \\\\\n&= cn \\left( \\frac{d}{c} + \\frac{9}{10} \\right)\n&\\leq cn\n\\end{align*}\n\nAs long as\n\n\\begin{align*}\n\\frac{d}{c} + \\frac{9}{10} &\\leq 1 \\\\\n\\frac{d}{c} &\\leq \\frac{1}{10} \\\\\n10 d &\\leq c\n\\end{align*}\n\\end{proof}\n\n\\section{What is special about 5?}\n\nFirst of all, we need an odd number for there to be a median.\nSecondly, notice:\n%\n\\begin{displaymath}\n\\frac{1}{5} + \\frac{7}{10} = \\frac{9}{10} < 1\n\\end{displaymath}\n\nDividing into groups of 3 doesn't work because:\n%\n\\begin{displaymath}\nT(n) = O(n) + T(n/3) + T(2n/3) = \\Theta(nlogn)\n\\end{displaymath}\n\nDividing into groups of 7 actually does work because:\n%\n\\begin{displaymath}\nT(n) = O(n) + T(n/7) + T(5n/7) = \\Theta(n)\n\\end{displaymath}\n", "meta": {"hexsha": "ebb0a1efd20d48f550c53b8f17f6551400b88e77", "size": 4249, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "selection.tex", "max_stars_repo_name": "SteamedPears/AllTheAlgorithms", "max_stars_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-12T19:16:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-01T03:13:05.000Z", "max_issues_repo_path": "selection.tex", "max_issues_repo_name": "SteamedPears/AllTheAlgorithms", "max_issues_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "selection.tex", "max_forks_repo_name": "SteamedPears/AllTheAlgorithms", "max_forks_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.7712418301, "max_line_length": 74, "alphanum_fraction": 0.6667451165, "num_tokens": 1437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642945, "lm_q2_score": 0.9046505421702797, "lm_q1q2_score": 0.8026101248162216}}
{"text": "\n\\subsection{Separable first-order Ordinary Differential Equations}\n\nFor some we can write:\n\n\\(\\dfrac{dy}{dt}=f(t,y)\\)\n\n\\(\\dfrac{dy}{dt}=\\dfrac{g(t)}{h(y)}\\)\n\nWe can then do the following:\n\n\\(h(y)\\dfrac{dy}{dt}=g(t)\\)\n\n\\(\\int h(y)\\dfrac{dy}{dt}dt=\\int g(t)dt + C\\)\n\n\\(\\int h(y)dy=\\int g(t)dt + C\\)\n\nIn some cases, these functions can then be integrated and solved.\n\n\n", "meta": {"hexsha": "c7506986c646850810e0999840622330144e63ed", "size": 367, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/ODE/02-03-separableFirstODE.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/ODE/02-03-separableFirstODE.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/ODE/02-03-separableFirstODE.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.4761904762, "max_line_length": 66, "alphanum_fraction": 0.6348773842, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133548753619, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.8026040003976925}}
{"text": "\\section{Application: Matrix powers}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Use diagonalization to raise a matrix to a high power.\n  \\item Use diagonalization to compute a square root of a matrix.\n  \\end{enumerate}\n\\end{outcome}\n\nSuppose we have a matrix $A$ and we want to find $A^{50}$. One could\ntry to multiply $A$ with itself 50 times, but this is a lot of work\n(try it!). However, diagonalization allows us to compute high powers\nof a matrix relatively easily.  Suppose $A$ is diagonalizable, so that\n$P^{-1}AP=D$. We can rearrange this equation to write $A=PDP^{-1}$.\nNow, consider $A^2$. Since $A=PDP^{-1}$, it follows that\n\\begin{equation*}\n  A^2 = (PDP^{-1})^2=PDP^{-1}PDP^{-1}=PD^2P^{-1}.\n\\end{equation*}\nSimilarly,\n\\begin{equation*}\n  A^3 = (PDP^{-1})^3=PDP^{-1}PDP^{-1}PDP^{-1}=PD^3P^{-1}.\n\\end{equation*}\nIn general,\n\\begin{equation*}\n  A^n = (PDP^{-1})^n=PD^nP^{-1}.\n\\end{equation*}\nTherefore, we have reduced the problem to finding $D^n$. But as we\nsaw in Example~\\ref{exa:sums-products-diagonal}, computing a power of\na diagonal matrix is easy. To compute $D^n$, we only need to raise\nevery entry on the diagonal to the power of $n$. Through this method,\nwe can compute large powers of matrices.\n\n\\begin{example}{Raising a matrix to a high power}{matrix-high-power}\n  Let%\n  \\index{matrix!raising to a power}%\n  \\index{power!of a matrix} $A=\\begin{mymatrix}{rrr}\n    2 & 1 & 0 \\\\\n    0 & 1 & 0 \\\\\n    -1 & -1 & 1\n  \\end{mymatrix}$. Find $A^{50}$.\n\\end{example}\n\n\\begin{solution}\n  First, we will diagonalize $A$. Following the usual steps, we find\n  that the eigenvalues are $\\eigenvar=1$ and $\\eigenvar=2$. The basic\n  eigenvectors corresponding to $\\eigenvar=1$ are\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_2 = \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 0 \\end{mymatrix},\n  \\end{equation*}\n  and the basic eigenvector corresponding to $\\eigenvar = 2$ is\n  \\begin{equation*}\n    \\vect{v}_3 = \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Now we construct $P$ by using the basic eigenvectors of $A$ as the\n  columns of $P$.  Thus\n  \\begin{equation*}\n    P =\n    \\begin{mymatrix}{rrr}\n      0 & -1 & -1 \\\\\n      0 & 1 & 0 \\\\\n      1 & 0 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  The inverse of $P$ is\n  \\begin{equation*}\n    P^{-1}=\\begin{mymatrix}{rrr}\n      1 & 1 & 1 \\\\\n      0 & 1 & 0 \\\\\n      -1 & -1 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  Then\n  \\begin{equation*}\n    P^{-1}AP\n    ~=~\n    \\begin{mymatrix}{rrr}\n      1 & 1 & 1 \\\\\n      0 & 1 & 0 \\\\\n      -1 & -1 & 0\n    \\end{mymatrix} \\begin{mymatrix}{rrr}\n      2 & 1 & 0 \\\\\n      0 & 1 & 0 \\\\\n      -1 & -1 & 1\n    \\end{mymatrix} \\begin{mymatrix}{rrr}\n      0 & -1 & -1 \\\\\n      0 & 1 & 0 \\\\\n      1 & 0 & 1\n    \\end{mymatrix} \\\\\n    ~=~\n    \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & 2\n    \\end{mymatrix} \\\\\n    ~=~\n    D.\n  \\end{equation*}\n  Now it follows by rearranging the equation that $A=PDP^{-1}$, and\n  therefore, as noted above,\n  \\begin{eqnarray*}\n    A^{50}\n    \\quad=\\quad\n    PD^{50}P^{-1}\n    &=&\\begin{mymatrix}{rrr}\n      0 & -1 & -1 \\\\\n      0 & 1 & 0 \\\\\n      1 & 0 & 1\n    \\end{mymatrix} \\begin{mymatrix}{rrr}\n      1^{50} & 0      & 0 \\\\\n      0      & 1^{50} & 0 \\\\\n      0      & 0      & 2^{50}\n    \\end{mymatrix} \\begin{mymatrix}{rrr}\n      1 & 1 & 1 \\\\\n      0 & 1 & 0 \\\\\n      -1 & -1 & 0\n    \\end{mymatrix} \\\\\n    &=&\\begin{mymatrix}{ccc}\n      2^{50} & -1+2^{50} & 0 \\\\\n      0 & 1 & 0 \\\\\n      1-2^{50} & 1-2^{50} & 1\n    \\end{mymatrix}.\n  \\end{eqnarray*}\n  \\vspace{-6ex}\\par\n\\end{solution}\n\nThus, through diagonalization, we have efficiently computed a high\npower of $A$. The following example shows that we can also use the\nsame technique for finding a square root of a matrix.\n\n\\begin{example}{Square root of a matrix}{matrix-root}\n  Let%\n  \\index{matrix!square root of}%\n  \\index{square root!of a matrix} $A=\\begin{mymatrix}{rrr}\n    1  &  3 & 3 \\\\\n    -1 &  5 & 3 \\\\\n    1  & -1 & 1 \\\\\n  \\end{mymatrix}$. Find a square root of $A$, i.e., find a matrix $B$\n  such that $A=B^2$.\n\\end{example}\n\n\\begin{solution}\n  We first diagonalize $A$. The characteristic polynomial is\n  \\begin{eqnarray*}\n    \\begin{absmatrix}{ccc}\n      1-\\eigenvar  &  3 & 3 \\\\\n      -1 &  5-\\eigenvar & 3 \\\\\n      1  & -1 & 1-\\eigenvar \\\\\n    \\end{absmatrix}\n    &=&\n    (1-\\eigenvar)(5-\\eigenvar)(1-\\eigenvar) + 9 + 3\n    - 3(5-\\eigenvar) + 3(1-\\eigenvar) + 3(1-\\eigenvar)\n    \\\\\n    &=& -\\eigenvar^3 + 7\\eigenvar^2 - 14\\eigenvar + 8,\n  \\end{eqnarray*}\n  with roots $\\eigenvar=1$, $\\eigenvar=2$, and $\\eigenvar=4$. The\n  corresponding eigenvectors are\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ -1 \\end{mymatrix},\n    \\quad\n    \\vect{v}_2 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ -1 \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_3 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix},\n  \\end{equation*}\n  respectively. Therefore we have $P^{-1}AP = D$, where\n  \\begin{equation*}\n    P = \\begin{mymatrix}{rrr}\n      1  &  0 & 1 \\\\\n      1  &  1 & 1 \\\\\n      -1 & -1 & 0 \\\\\n    \\end{mymatrix},\n    \\quad\n    P^{-1} = \\begin{mymatrix}{rrr}\n      1  & -1 & -1 \\\\\n      -1 &  1 &  0 \\\\\n      0  &  1 &  1 \\\\\n    \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    D = \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      0 & 2 & 0 \\\\\n      0 & 0 & 4 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  We can equivalently write $A = PDP^{-1}$. Finding a square root of a\n  diagonal matrix is easy:\n  \\begin{equation*}\n    D^{\\frac{1}{2}} =\n    \\begin{mymatrix}{ccc}\n      1 & 0        & 0 \\\\\n      0 & \\sqrt{2} & 0 \\\\\n      0 & 0        & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  If we now define $B=PD^{\\frac{1}{2}}P^{-1}$, we clearly have $B^2 =\n  PD^{\\frac{1}{2}}P^{-1}PD^{\\frac{1}{2}}P^{-1} = PDP^{-1} = A$. So the\n  desired square root of $A$ is\n  \\begin{equation*}\n    B\n    ~=~\n    PD^{\\frac{1}{2}}P^{-1}\n    ~=~\n    \\begin{mymatrix}{rrr}\n      1  &  0 & 1 \\\\\n      1  &  1 & 1 \\\\\n      -1 & -1 & 0 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{ccc}\n      1 & 0        & 0 \\\\\n      0 & \\sqrt{2} & 0 \\\\\n      0 & 0        & 2 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      1  & -1 & -1 \\\\\n      -1 &  1 &  0 \\\\\n      0  &  1 &  1 \\\\\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{ccc}\n      1           &  1          &  1 \\\\\n      1-\\sqrt{2}  &  1+\\sqrt{2} &  1 \\\\\n      -1+\\sqrt{2} &  1-\\sqrt{2} &  1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Finally, we verify that we have computed $B$ correctly by squaring\n  it and double-checking that we really get $A$.\n  \\begin{equation*}\n    B^2 ~=~\n    \\begin{mymatrix}{ccc}\n      1           &  1          &  1 \\\\\n      1-\\sqrt{2}  &  1+\\sqrt{2} &  1 \\\\\n      -1+\\sqrt{2} &  1-\\sqrt{2} &  1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{ccc}\n      1           &  1          &  1 \\\\\n      1-\\sqrt{2}  &  1+\\sqrt{2} &  1 \\\\\n      -1+\\sqrt{2} &  1-\\sqrt{2} &  1 \\\\\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{rrr}\n      1  &  3 & 3 \\\\\n      -1 &  5 & 3 \\\\\n      1  & -1 & 1 \\\\\n    \\end{mymatrix}\n    ~=~\n    A.\n  \\end{equation*}\n  We note that the square root of a matrix is not unique. In fact,\n  $D$ has 8 different square roots, all of the form\n  \\begin{equation*}\n    \\begin{mymatrix}{ccc}\n      \\pm 1 & 0            & 0 \\\\\n      0     & \\pm \\sqrt{2} & 0 \\\\\n      0     & 0            & \\pm 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  It follows that $A$ has 8 different square roots as well. We leave\n  it as an exercise to compute them all.\n\\end{solution}\n\nThe same method can also be used to compute other powers of a matrix,\nfor example a cube root.\n", "meta": {"hexsha": "96011859a8138f6688ae63a83f2fb91ec438fe12", "size": 7627, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Eigenvalues-Application-Power.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Eigenvalues-Application-Power.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Eigenvalues-Application-Power.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 28.8901515152, "max_line_length": 70, "alphanum_fraction": 0.5296971286, "num_tokens": 3068, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797081106935, "lm_q2_score": 0.9111797154386841, "lm_q1q2_score": 0.8025644337222406}}
{"text": "\\documentclass[11pt,twoside]{article}\n\n\\pagestyle{myheadings}\n\\markboth{Actor ranking}{Actor ranking}\n\n\\input{../../fncextra}\n\n\\begin{document}\n    \n\\begin{center}\n  \\bf Not Kevin Bacon\n\\end{center}\n    \nSuppose we have a graph or network with $n$ nodes and some connections between them. The matrix $\\mA$ whose entries are \n\\begin{equation}\n  A_{ij} = \n  \\begin{cases}\n    1, & \\text{if node $i$ connects to $j$},\\\\\n    0, & \\text{otherwise,}\n  \\end{cases}\n\\end{equation}\nis the \\textbf{adjacency matrix} of the network. Note that these connections have direction, and $i$ connecting to $j$ does not automatically imply that $j$ connects to $i$ (i.e., this is a directed graph). Let $s_i = \\sum_{j=1}^n A_{ij}$ be the number of nodes that node $i$ connects to. If we were to randomly select a link leaving node $i$, each link would have probability $1/s_i$ of being selected. \n     \nLet $\\bfx$ be a vector of positive values. We will require that $\\sum_i x_i = 1$, so that $\\bfx$ has the interpretation of a probability distribution over the nodes. If all connections are given equal weighting, the probability of following a connection from any node to node $i$ is\n\\begin{equation}\n  z_i = \\sum_{j\\in P_i} \\frac{x_j}{s_j} ,\n\\end{equation} \nwhere $P_i$ is the set of nodes that connect to node $i$. These are the rows with ones in column $i$ of $\\mA$. By the definition of $\\mA$, this is the same as  \n\\begin{equation}\n  \\label{eq:yvec}\n  z_i = \\sum_{j=1}^n \\frac{A_{ji} x_j}{s_j} =\\sum_{j=1}^n B_{ij} x_j,\n\\end{equation} \nwhere we defined $B_{ij}=A_{ji}/s_j$. Put simply, $\\bfz=\\mB \\bfx$. \n\nIt's important to introduce some overall randomness into the jumps between nodes---this is the only way to escape a self-contained clique (disconnected subgraph). The probability of hopping to any node $i$ entirely at random is just $1/n$. We blend link-following with random hopping as follows. Choose some $p\\in[0,1]$, and suppose that a hop between nodes follows one of the connections with probability $p$, or is a random hop with probability $1-p$. Using $\\bm{1}$ to denote the $n$-vector of all ones, then \n\\begin{equation}\n  \\label{eq:totalmap}\n  \\bfy = p \\mB \\bfx + \\frac{1-p}{n} \\bm{1}\n\\end{equation}\ndescribes how to update probabilities after each hop. Finally, the fact that \n\\begin{equation}\n  1 = \\sum_i x_i = \\bm{1}^T \\bfx,\n\\end{equation}\nallows us to express the map~\\eqref{eq:totalmap} as\n\\begin{equation}\n  \\label{eq:matvec}\n  \\bfy =  \\left[ p \\mB + \\frac{1-p}{n} \\bm{1}\\bm{1}^T \\right] \\bfx = \\mR\\bfx,\n\\end{equation}  \nfor a square matrix $\\mR$. If the probabilities are unchanged by hopping (i.e., $\\bfz=\\bfx$), then $\\bfx$ is an eigenvector of $\\mR$ with associated eigenvalue $\\lambda=1$. We won't prove this, but $\\mR$ is guaranteed to have $\\lambda=1$ as the leading eigenvalue, making power iteration possible. The resulting eigenvector $\\bfx$ can be sorted to find out which nodes are most likely to be visited in the long run.\n\nNote that $\\mR$ is \\emph{not} sparse and should never be formed. However, $\\mR\\bfx$ as defined in~\\eqref{eq:totalmap} can be computed efficiently if $\\mB$ is sparse. That is all we need to do a power iteration with $\\mR$. Since we are working with probability, normalization is not required in the power iteration: $\\bfx_{k+1}=\\mR \\bfx_k$, provided $\\bfx_1$ has positive entries and $\\|\\bfx\\|_1=1$.  \n\n\n\\subsection*{Goals}\n\nYou will use an adjacency matrix for movie actors to perform the power iteration and find the leading eigenvector of $\\mR$, and using that vector to rank the actors in influence.\n    \n\n\\subsection*{Preparation}\n\nRead section 8.2. Answer the following questions based on the above description.\n\n\\begin{enumerate}\n\\item Show using \\eqref{eq:yvec} that $\\displaystyle \\sum_{i=1}^n z_i = 1$. This proves that $\\bfz$ is also a probability distribution.\n  \\item Show using \\eqref{eq:totalmap} that $\\bfy$ is a probability distribution. \n\\end{enumerate}\n \n%\\vspace{1ex}     \n%\\noindent \\textbf{Notable MATLAB functions:} \\texttt{whos}, \\texttt{nnz}, \\texttt{sort}, \\texttt{histogram}\n\n    \n\\subsection*{Procedure}\n\nDownload the script template and the data file \\texttt{actornetwork.mat}.\n\n\\begin{enumerate}\n\\item Load \\texttt{actornetwork.mat} file from the assignment site. It has a vector \\texttt{actor} of unique actor names for all credited roles in films released from 2004 through 2013. It also has a sparse adjacency matrix \\texttt{A}, where a (symmetric) link between actors means that they appeared in at least one film together.\n\\item Use \\texttt{nnz} to compute the density (number of nonzeros over total number of elements) of \\texttt{A}. Use \\texttt{whos} to find the memory usage of \\texttt{A} in bytes. Also calculate the memory usage of an equivalent full (non-sparse) matrix. \n\\item Compute the vector $\\mathbf{s}$ whose entries are $s_i$ as defined above. Make a histogram of its entries using 32 bins.  \n\\item  Construct the matrix $\\mB$ appearing in~\\eqref{eq:yvec} above. It helps to use the fact that $\\mA$ is symmetric. (It's reasonable to loop over one dimension of the matrix, but not over all of the elements.)\n\\item Set $p=0.9$ and let $\\bfx_1$ be a random vector of positive numbers. Normalize $\\bfx_1$ to be a probability distribution. By repeatedly applying~\\eqref{eq:totalmap}, do 100 power iterations to get $\\bfx_{101}$. \\emph{Important: Do not attempt to define the matrix $\\mR$}, and do \\emph{not} use the book's power iteration function; instead use~\\eqref{totalmap} to compute $\\mR\\bfx$. Check that $\\|\\bfx_{101}-\\bfx_{100}\\|_1$ is less than $10^{-6}$. \n\\item Sort the entries of $\\bfx$ in descending order, using the second output to print out the names of the 10 ``most collaborative'' actors. \n\\end{enumerate}\n\n\\subsection*{Discussion}\n\\begin{enumerate}\n\\item The data file also includes an $m\\times n$ sparse matrix $\\m{M}$. Its $(i,j)$ entry is one if actor $j$ appeared in film $i$, and zero otherwise. Give a simple interpretation of the matrix $\\m{M}^T\\m{M}$.\n%\\item[E2.] Repeat the ranking process using $\\m{M}^T\\m{M}$ in place of $\\mA$. How many movies is the top actor credited with appearing in? \n\\item What is the interpretation of $\\m{M}\\m{M}^T$? What would a ranking using this matrix reveal? \n\\end{enumerate}\n    \n    \n    \n\\end{document}\n\n", "meta": {"hexsha": "ea4bee4280484afd878e859e0e831f7ec9675301", "size": 6259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter08/PageRankActors/ActorRank.tex", "max_stars_repo_name": "snowdj/fnc-extras", "max_stars_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 109, "max_stars_repo_stars_event_min_datetime": "2018-04-21T09:02:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T19:03:54.000Z", "max_issues_repo_path": "labs/chapter08/PageRankActors/ActorRank.tex", "max_issues_repo_name": "snowdj/fnc-extras", "max_issues_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-12-04T22:17:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T21:04:47.000Z", "max_forks_repo_path": "labs/chapter08/PageRankActors/ActorRank.tex", "max_forks_repo_name": "snowdj/fnc-extras", "max_forks_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 49, "max_forks_repo_forks_event_min_datetime": "2017-04-02T17:21:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T17:19:57.000Z", "avg_line_length": 65.1979166667, "max_line_length": 512, "alphanum_fraction": 0.7216807797, "num_tokens": 1855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.9111797069968975, "lm_q1q2_score": 0.802564429137869}}
{"text": "\n\\subsection{Markov's inequality and Chebyshev's inequality}\n\\subsubsection{Lemma 1}\n\n\\(E[I_{X\\ge a}]=P(X\\ge a)\\)\n\nConsider the indicator function.\n\n\\(I_{X\\ge a}\\)\n\nThis is equal to \\(0\\) if \\(X\\) is below \\(a\\) and \\(1\\) otherwise.\n\nWe can take expectations of this.\n\n\\(E[I_{X\\ge a}]=P(X\\ge a).1+P(X<a).0=P(X\\ge a)\\)\n\n\\(E[I_{X\\ge a}]=P(X\\ge a)\\)\n\n\\subsubsection{Lemma 2}\n\n\\(aI_{X\\ge a}\\le X\\)\n\nWhile \\(X\\) is below \\(a\\) the left side is equal to \\(0\\), which holds.\n\nWhile \\(X\\) is equal to \\(a\\) the left side is equal to \\(X\\), which holds.\n\nWhile \\(X\\) is above \\(a\\) the left side is equal to \\(a\\), which holds.\n\n\\subsubsection{Markov\u2019s inequality}\n\n\\(P(X\\ge a)\\le \\dfrac{\\mu  }{a}\\)\n\nFrom above:\n\n\\(aI_{X\\ge a}\\le X\\)\n\nWe can take expectations of both sides:\n\n\\(E[aI_{X\\ge a}]\\le E[X]\\)\n\n\\(aP(X\\ge a)\\le E[X]\\)\n\n\\(P(X\\ge a)\\le \\dfrac{\\mu  }{a}\\)\n\n\\subsubsection{Chebyshev\u2019s inequality}\n\nWe know from Markov\u2019s inequality that:\n\n\\(P(X\\ge a)\\le \\dfrac{\\mu }{a}\\)\n\nLet\u2019s take the variable \\(X\\) to be \\((X-\\mu )^2\\)\n\n\\(P((X-\\mu )^2\\ge a)\\le \\dfrac{E[(X-\\mu )^2]}{a}\\)\n\n\\(P((X-\\mu )^2\\ge a)\\le \\dfrac{\\sigma^2}{a}\\)\n\n\\(P(|X-\\mu | \\ge \\sqrt{a})\\le \\dfrac{\\sigma^2}{a}\\)\n\nTake \\(a\\) to be a multiple \\(k^2\\) of the variance \\(\\sigma^2\\).\n\n\\(a=k^2\\sigma^2\\)\n\n\\(P(|X-\\mu | \\ge k\\sigma )\\le \\dfrac{\\sigma^2}{k^2\\sigma^2}\\)\n\n\\(P(|X-\\mu | \\ge k\\sigma )\\le \\dfrac{1}{k^2}\\)\n\n", "meta": {"hexsha": "9f127f3d60a823842fcc391da7a18b2ce7ee2ae1", "size": 1370, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityMomentsMarkov/01-01-singleChebMark.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/probabilityMomentsMarkov/01-01-singleChebMark.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/probabilityMomentsMarkov/01-01-singleChebMark.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.447761194, "max_line_length": 75, "alphanum_fraction": 0.5773722628, "num_tokens": 552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.880797085800514, "lm_q1q2_score": 0.8025644268456827}}
{"text": "\\chapter{Binary Mathematics Operations}\\label{ch03}\n\\section{Binary Addition}\n\nAdding binary numbers is a simple task similar to the longhand addition of decimal numbers. As with decimal numbers, the bits are added one column at a time, from right to left. Unlike decimal addition, there is little to memorize in the way of an ``Addition Table,'' as seen in Table \\ref{MO:tab:binary_addition_table}\n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ c c c | c c } \\hline\n      \\multicolumn{3}{c|}{\\textbf{Inputs}} & \\multicolumn{2}{c}{\\textbf{Outputs}} \\\\\n      \\hline\n      \\rowcolor{black!75}\n      \\head{Carry In} & \\head{Augend} & \\head{Addend} & \\head{Sum} & \\head{Carry Out} \\\\\n      \\hline\n      0        & 0      & 0      & 0   & 0 \\\\\n      0        & 0      & 1      & 1   & 0 \\\\\n      0        & 1      & 0      & 1   & 0 \\\\\n      0        & 1      & 1      & 0   & 1 \\\\\n      1        & 0      & 0      & 1   & 0 \\\\\n      1        & 0      & 1      & 0   & 1 \\\\\n      1        & 1      & 0      & 0   & 1 \\\\\n      1        & 1      & 1      & 1   & 1 \\\\ \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Addition Table}\n  \\label{MO:tab:binary_addition_table}\n\\end{table} \n\nJust as with decimal addition, two binary integers are added one column at a time, starting from the \\ac{LSB} (the right-most bit in the integer): \n\n\\begin{binDisp}[commandchars=~\\[\\]]\n      1001101\n     +~underline[0010010]\n      1011111\n\\end{binDisp}\n\nWhen the sum in one column includes a carry out, it is added to the next column to the left (again, like decimal addition). Consider the following examples:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n       11  1  <--Carry Bits\n      1001001\n     +~underline[0011001]\n      1100010\n\\end{binDisp}\n\n\\begin{binDisp}[commandchars=~\\[\\], samepage=true]\n         11   <--Carry Bits\n      1000111\n     +~underline[0010110]\n      1011101\n\\end{binDisp}\n\nThe ``ripple-carry'' process is simple for humans to understand, but it causes a significant problem for designers of digital circuits. Consequently, ways were developed to carry a bit to the left in an electronic adder circuit and that is covered in Section \\ref{CL:sec:adders_and_subtractors}, page \\pageref{CL:sec:adders_and_subtractors}.\n\nBinary numbers that include a fractional component are added just like binary integers; however, the radix points must align so the augend and addend may need to be padded with zeroes on either the left or the right. Here is an example: \n\n\\begin{binDisp}[commandchars=~\\[\\]]\n       111 1    <--Carry Bits\n      1010.0100\n     +~underline[0011.1101]\n      1110.0001\n\\end{binDisp}\n\n\\subsection{Overflow Error}\n\\label{MO:sub:overflow_error}\n\nOne problem circuit designers must consider is a carry out bit in the \\ac{MSB} (left-most bit) in the answer. Consider the following:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n      11 11    <--Carry Bits\n      10101110\n     +~underline[11101101]\n     110011011\n\\end{binDisp}\n\nThis example illustrates a significant problem for circuit designers. Suppose the above calculation was done with a circuit that could only accommodate eight data bits. The augend and addend are both eight bits wide, so they are fine; however, the sum is nine bits wide due to the carry out in the \\ac{MSB}. In an eight-bit circuit (that is, a circuit where the devices and data lines can only accommodate eight bits of data), the carry out bit would be dropped since there is not enough room to accommodate it.\n\nThe result of a dropped bit cannot be ignored. The example problem above, when calculated in decimal, is $ 174_{10} + 237_{10} = 411_{10} $. If, though, the \\ac{MSB} carry out is dropped, then the answer becomes $ 155_{10} $, which is, of course, incorrect. This type of error is called an \\emph{Overflow Error}, and a circuit designer must find a way to correct overflow. One typical solution is to simply alert the user that there was an overflow error. For example, on a handheld calculator, the display may change to something like \\emph{-E-} if there is an error of any sort, including overflow. \n\n\\subsection{Sample Binary Addition Problems}\n\\label{MO:sub:sample_binary_addition_problems}\nThe following table lists several binary addition problems that can be used for practice.\n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ S S S }\n      \\hline\n      \\rowcolor{black!75}\n      {\\head{Augend}} & {\\head{Addend}} & {\\head{Sum}}     \\\\\n      \\hline\n      10110.   & 11101.   & 110011.   \\\\ \n      111010.  & 110011.  & 1101101.  \\\\\n      1011.    & 111000.  & 1000011.  \\\\ \n      1101001. & 11010.   & 10000011. \\\\ \n      1010.111 & 1100.001 & 10111.000 \\\\ \n      101.01   & 1001.001 & 1110.011  \\\\ \n      \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Binary Addition Problems}\n  \\label{MO:tab:binary_addition_problems}\n\\end{table} \n\n\\section{Binary Subtraction}\n\\label{MO:sec:binary_subtraction}\n\\subsection{Simple Manual Subtraction}\n\\label{MO:sub:simple_manual_subtraction}\n\nSubtracting binary numbers is similar to subtracting decimal numbers and uses the same process children learn in primary school. The minuend and subtrahend are aligned on the radix point, and then columns are subtracted one at a time, starting with the least significant place and moving to the left. If the subtrahend is larger than the minuend for any one column, an amount is ``borrowed'' from the column to the immediate left. Binary numbers are subtracted in the same way, but it is important to keep in mind that binary numbers have only two possible values: zero and one. Consider the following problem: \n\n\\begin{binDisp}[commandchars=~\\[\\]]\n      10.1\n     -~underline[01.0]\n      01.1\n\\end{binDisp}\n\nIn this problem, the \\ac{LSB} column is $ 1 - 0 $, and that equals one. The middle column, though, is $ 0 - 1 $, and one cannot be subtracted from zero. Therefore, one is borrowed from the most significant bit, so the problem in middle column becomes $ 10 - 1 $. (Note: do not think of this as ``ten minus one'' - remember that this is binary so this problem is ``one-zero minus one,'' or two minus one in decimal) The middle column is $ 10 - 1 = 1 $, and the \\ac{MSB} column then becomes $ 0 - 0 = 0 $. \n\nThe radix point must be kept in alignment throughout the problem, so if one of the two operands has too few places it is padded on the left or right (or both) to make both operands the same length. As an example, subtract: $ 101101.01 - 1110.1 $: \n\n\\begin{binDisp}[commandchars=~\\[\\], samepage=true]\n      101101.01\n     -~underline[001110.10]\n       11110.11\n\\end{binDisp}\n\nThere is no difference between decimal and binary as far as the subtraction process is concerned. In each of the problems in this section the minuend is greater than the subtrahend, leading to a positive difference; however, if the minuend is less than the subtrahend, the result is a negative number and negative numbers are developed in the next section of this chapter. \n\nTable \\ref{MO:tab:binary_subtraction_problems} includes some subtraction problems for practice: \n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ S S S }\n      \\hline\n      \\rowcolor{black!75}\n      {\\head{Minuend}} & {\\head{Subtrahend}} & {\\head{Difference}}     \\\\\n      \\hline\n      1001011.      & 0111010.    & 10001.   \\\\ \n      100010.       & 010010.     & 10000.  \\\\\n      101110110.    & 11001010.   & 10101100.  \\\\ \n      1110101.      & 111010.     & 111011. \\\\ \n      11011010.1101 & 101101.1    & 10101101.0101 \\\\ \n      10101101.1    & 1101101.101 & 111111.111  \\\\ \n      \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Binary Subtraction Problems}\n  \\label{MO:tab:binary_subtraction_problems}\n\\end{table} \n\n\\subsection{Representing Negative Binary Numbers Using Sign-and-Magnitude}\n\\label{MO:sub:representing_negative_sign_magnitude}\n\n\\marginpar{Sign-and-magnitude was used in early computers since it mimics real number arithmetic, but has been replaced by more efficient negative number systems in modern computers.} Binary numbers, like decimal numbers, can be both positive and negative. While there are several methods of representing negative binary numbers; one of the most intuitive is using \\emph{sign-and-magnitude}, which is essentially the same as placing a ``\u2013'' in front of a decimal number. With the sign-and-magnitude system, the circuit designer simply designates the \\ac{MSB} as the \\emph{sign bit} and all others as the magnitude of the number. When the sign bit is one the number is negative, and when it is zero the number is positive. Thus, $ -5_{10} $ would be written as $ 1101_2 $. \n\nUnfortunately, despite the simplicity of the sign-and-magnitude approach, it is not very practical for binary arithmetic, especially when done by a computer. For instance, negative five ($ 1101_2 $) cannot be added to any other binary number using standard addition technique since the sign bit would interfere. As a general rule, errors can easily occur when bits are used for any purpose other than standard place-weighted values; for example, $ 1101_2 $ could be misinterpreted as the number $ 13_{10} $ when, in fact, it is meant to represent $ -5 $. To keep things straight, the circuit designer must first decide how many bits are going to be used to represent the largest numbers in the circuit, add one more bit for the sign, and then be sure to never exceed that bit field length in arithmetic operations. For the above example, three data bits plus a sign bit would limit arithmetic operations to numbers from negative seven ($ 1111_2 $) to positive seven ($ 0111_2 $), and no more. \n\nThis system also has the quaint property of having two values for zero. If using three magnitude bits, these two numbers are both zero: $ 0000_2 $ (positive zero) and $ 1000_2 $ (negative zero). \n\n\\subsection{Representing Negative Binary Numbers Using Signed Complements }\n\\label{MO:sub:representing_negative_sign_complement}\n\n\\subsubsection{About Complementation}\n\\label{MO:subsub:about_complementation}\n\nBefore discussing negative binary numbers, it is important to understand the concept of complementation. To start, recall that the \\emph{radix} (or base) of any number system is the number of ciphers available for counting; the decimal (or base-ten) number system has ten ciphers ($ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 $) while the binary (or base-two) number system has two ciphers ($ 0, 1 $). By definition, a number plus its complement equals the radix (this is frequently called the \\emph{radix complement}). For example, in the decimal system four is the radix complement of six since $ 4 + 6 = 10 $. Another type of complement is the \\emph{diminished radix complement}, which is the complement of the radix minus one. For example, in the decimal system six is the diminished radix complement of three since $ 6 + 3 = 9 $ and nine is equal to the radix minus one.\n\n\\paragraph{Decimal.} In the decimal system the radix complement is usually called the \\emph{tens} complement since the radix of the decimal system is ten. Thus, the tens complement of eight is two since $ 8 + 2 = 10 $. The diminished radix complement is called the \\emph{nines} complement in the decimal system. As an example, the nines complement of decimal eight is one since $ 8 + 1 = 9 $ and nine is the diminished radix of the decimal system. \n\nTo find the nines complement for a number larger than one place, the nines complement must be found for each place in the number. For example, to find the nines complement for $ 538_{10} $, find the nines complement for each of those three digits, or $ 461 $. The easiest way to find the tens complement for a large decimal number is to first find the nines complement and then add one. For example, the tens complement of $ 283 $ is $ 717 $, which is calculated by finding the nines complement, $ 716 $, and then adding one.\n\n\\paragraph{Binary.} Since the radix for a binary number is $ 10_2 $, (be careful! this is not ten, it is one-zero in binary) the diminished radix is $ 1_2 $. The diminished radix complement is normally called the \\emph{ones complement} and is obtained by reversing (or ``flipping'') each bit in a binary number; so the ones complement of $ 100101_2 $ is $ 011010_2 $. \n\nThe radix complement (or \\emph{twos complement}) of a binary number is found by first calculating the ones complement and then adding one to that number. The ones complement of $ 101101_2 $ is $ 010010_2 $, so the twos complement is $ 010010_2 + 1_2 = 010011_2 $.  \n\n\\subsubsection{Signed Complements} \n\\label{MO:subsub:signed_complement}\nIn circuits that use binary mathematics, a circuit designer can opt to use ones complement for negative numbers and designate the most significant bit as the sign bit; and, if so, the other bits are the magnitude of the number. This is similar to the \\emph{sign-and-magnitude} system discussed on page \\pageref{MO:sub:representing_negative_sign_magnitude}. By definition, when using ones complement negative numbers, if the most significant bit is zero, then the number is positive and the magnitude of the number is determined by the remaining bits; but if the most significant bit is one, then the number is negative and the magnitude of the number is determined by calculating the ones complement of the number. Thus: $ 0111_2 = +7_{10} $, and $ 1000_2 = -7_{10} $ (the ones complement for $ 1000_2 $ is $ 0111_2 $). Table \\ref{MO:tab:ones_complement} may help to clarify this concept: \n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ S c c } \n      \\hline\n      \\rowcolor{black!75}\n      {\\head{Decimal}} & {\\head{Positive}} & {\\head{Negative}} \\\\\n      \\hline\n      0 & 0000 & 1111 \\\\\n      1 & 0001 & 1110 \\\\\n      2 & 0010 & 1101 \\\\\n      3 & 0011 & 1100 \\\\\n      4 & 0100 & 1011 \\\\\n      5 & 0101 & 1010 \\\\\n      6 & 0110 & 1001 \\\\\n      7 & 0111 & 1000 \\\\\n      \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Ones Complement}\n  \\label{MO:tab:ones_complement}\n\\end{table} \n\nIn a four-bit binary number, any decimal number from $ -7 $ to $ +7 $ can be represented; but, notice that, like the sign-and-magnitude system, there are two values for zero, one positive and one negative. This requires extra circuitry to test for both values of zero after subtraction operations.\n\nTo simplify circuit design, a designer can opt to use twos complement negative numbers and designate the most significant bit as the sign bit so the other bits are the number's magnitude. To use twos complement numbers, if the most significant bit is zero, then the number is positive and the magnitude of the number is determined by the remaining bits; but if the most significant bit is one, then the number is negative and the magnitude of the number is determined by taking the twos complement of the number (that is, the ones complement plus one). Thus: $ 0111 = 7 $, and $ 1001 = -7 $ (the ones complement of $ 1001 $ is $ 0110 $, and $ 0110 + 1 = 0111 $). Table \\ref{MO:tab:twos_complement} may help to clarify this concept:\n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ S c c } \n      \\hline\n      \\rowcolor{black!75}\n      {\\head{Decimal}} & {\\head{Positive}} & {\\head{Negative}} \\\\\n      \\hline\n      0 & 0000 & 10000 \\\\\n      1 & 0001 & 1111 \\\\\n      2 & 0010 & 1110 \\\\\n      3 & 0011 & 1101 \\\\\n      4 & 0100 & 1100 \\\\\n      5 & 0101 & 1011 \\\\\n      6 & 0110 & 1010 \\\\\n      7 & 0111 & 1001 \\\\\n      8 & N/A & 1000 \\\\\n      \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Twos Complement}\n  \\label{MO:tab:twos_complement}\n\\end{table} \n\nThe twos complement removes that quirk of having two values for zero. Table \\ref{MO:tab:twos_complement} shows that zero is either $ 0000 $ or $ 10000 $; but since this is a four-bit number the initial one is discarded, leaving $ 0000 $ for zero whether the number is positive or negative. Also, $ 0000 $ is considered a positive number since the sign bit is zero. Finally, notice that $ 1000 $ is $ -8 $ (ones complement of $ 1000 $ is $ 0111 $, and $ 0111 + 1 = 1000 $). \\marginpar{Programmers reading this book may have wondered why the maximum/minimum values for various types of variables is asymmetrical.}This means that binary number systems that use a twos complement method of designating negative numbers will be asymmetrical; running, for example, from $ -8 $ to $ +7 $. A twos complement system still has the same number of positive and negative numbers, but zero is considered positive, not neutral.\n\n\\marginpar{All modern computer systems use radix (or twos) complements to represent negative numbers.} One other quirk about the twos complement system is that the decimal value of the binary number can be quickly calculated by assuming the sign bit has a negative place value and all other places are added to it. For example, in the negative number $ 1010_2 $, if the sign bit is assumed to be worth $ -8 $ and the other places are added to that, the result is $ -8+2 $, or $ -6 $; and $ -6 $ is the value of $ 1010_2 $ in a twos complement system.\n\n\\subsubsection{About Calculating the Twos Complement}\n\\label{MO:subsub:about_calculating_twos_complement}\n\nIn the above section, the twos (or radix) complement is calculated by finding the ones complement of a number and then adding one. For machines, this is the most efficient method of calculating the twos complement; but there is a method that is much easier for humans to use to find the twos complement of a number. Start with the \\ac{LSB} (the right-most bit) and then read the number from right to left. Look for the first one and then invert every bit to the left of that one. As an example, the twos complement for $ 1010\\underline{10}_2 $ is formed by starting with the least significant bit (the zero on the right), and working to the left, looking for the first one, which is in the second place from the right. Then, every bit to the left of that one is inverted, ending with: $ 0101\\underline{10}_2 $ (the two \\acp{LSB} are underlined to show that they are the same in both the original and twos complement number).\n\nTable \\ref{MO:tab:example_twos_comp} displays a few examples:\n\n\\begin{table}[H]\n  \\sisetup{parse-numbers = false}\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ r l } \n      \\hline\n      \\rowcolor{black!75}\n      {\\head{Number}} & {\\head{Twos Complement}} \\\\\n      \\hline\n      0110100   & 1001100   \\\\\n      11010     & 00110     \\\\\n      001010    & 110110    \\\\\n      1001011   & 0110101   \\\\\n      111010111 & 000101001 \\\\\n      \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Example Twos Complement}\n  \\label{MO:tab:example_twos_comp}\n\\end{table} \n\n\\subsection{Subtracting Using the Diminished Radix Complement }\n\\label{MO:sub:subtracting_using_diminished_radix}\n\nWhen thinking about subtraction, it is helpful to remember that $ A - B $ is the same as $ A + (-B) $. Computers can find the complement of a particular number and add it to another number much faster and easier than attempting to create separate subtraction circuits. Therefore, subtraction is normally carried out by adding the complement of the subtrahend to the minuend.\n\n\\subsubsection{Decimal}\n\\label{MO:subsub:decimal_subtraction_with_diminished_radix}\n\n\\marginpar{This method is commonly used by stage performers who can subtract large numbers in their heads. While it seems somewhat convoluted, it is fairly easy to master.} It is possible to subtract two decimal numbers by adding the nines complement, as in the following example:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n      735\n     -~underline[142]\n\\end{binDisp}\n\nCalculate the nines complement of the subtrahend: $ 857 $ (that is $ 9-1 $, $ 9-4 $, and $ 9-2 $). Then, add that nines complement to the minuend: \n\n\\begin{binDisp}[commandchars=~\\[\\]]\n      735\n     +~underline[857]\n     1592\n\\end{binDisp}\n\nThe initial one in the sum (the thousands place) is dropped so the number of places in the answer is the same as for the two addends, leaving $ 592 $. Because the diminished radix used to create the subtrahend is one less than the radix, one must be added to the answer; giving $ 593 $, which is the correct answer for $ 735-142 $.\n\n\\subsubsection{Binary}\n\\label{MO:subsub:binary_subtraction_with_diminished_radix}\n\nThe diminished radix complement (or ones complement) of a binary number is found by simply ``flipping'' each bit. Thus, the ones complement of $ 11010 $ is $ 00101 $. Just as in decimal, a binary number can be subtracted from another by adding the diminished radix complement of the subtrahend to the minuend, and then adding one to the sum. Here is an example: \n\n\\begin{binDisp}[commandchars=~\\[\\]]\n      101001\n     -~underline[011011]\n\\end{binDisp}\n\nAdd the ones complement of the subtrahend:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n      101001\n     +~underline[100100]\n     1001101\n\\end{binDisp}\n\nThe most significant bit is discarded so the solution has the same number of bits as for the two addends. This leaves $ 001101_2 $ and adding one to that number (because the diminished radix is one less than the radix) leaves $ 1110_2 $. In decimal, the problem is $ 41-27=14 $.\n\nOften, diminished radix subtraction circuits are created such that they use \\emph{end around} carry bits. In this case, the most significant bit is carried around and added to the final sum. If that bit is one, then that increases the final answer by one, and the answer is a positive number. If, though, the most significant bit is zero, then there is no end around carry so the answer is negative and must be complemented to find the true value. Either way, the correct answer is found. \n\nHere is an example:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n      0110  (6)\n     -~underline[0010  (2)]\n\\end{binDisp}\n\nSolution:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n      0110  (6)\n     +~underline[1101  (-2 in ones complement)]\n     10011\n         1  (End-around carry the MSB)\n     =0100  (4)\n\\end{binDisp}\n\nAnswer: 4 (since there was an end-around carry the solution is a positive number). Here is a second example:\n\n\\begin{binDisp}[commandchars=~\\[\\], samepage=true]\n      0010  (2)\n     -~underline[0110  (6)]\n\\end{binDisp}\n\nSolution:\n\n\\begin{binDisp}[commandchars=~\\[\\], samepage=true]\n      0010  (2)\n     +~underline[1001  (-6 in ones complement)]\n      1011  (No end-around carry, so ones complement)\n     =0100  (-4: no end-around carry so negative answer)\n\\end{binDisp}\n\nBecause the diminished radix (or ones) complement of a binary number includes that awkward problem of having two representations for zero, this form of subtraction is not used in digital circuits; instead, the radix (or twos) complement is used (this process is discussed next). It is worth noting that subtracting by adding the diminished radix of the subtrahend and then adding one is awkward for humans, but complementing and adding is a snap for digital circuits. In fact, many early mechanical calculators used a system of adding complements rather than having to turn gears backwards for subtraction. \n\n\\subsection{Subtracting Using the Radix Complement}\n\\label{MO:sub:subtracting_using_radix_complement}\n\n\\subsubsection{Decimal}\n\\label{MO:subsub:decimal_subtraction_with_radix_complement}\n\nThe radix (or tens) complement of a decimal number is the nines complement plus one. Thus, the tens complement of $ 7 $ is $ 3 $; or ($ (9-7)+1 $) and the tens complement of $ 248 $ is $ 752 $ (find the nines complement of each place and then add one to the complete number: $ 751 + 1 $). It is possible to subtract two decimal numbers using the tens complement, as in the following example: \n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     735\n    -~underline[142]\n\\end{binDisp}\n\nCalculate the tens complement of the subtrahend, $ 142 $, by finding the nines complement for each digit and then adding one to the complete number: $ 858 $ (that is $ 9-1 $, $ 9-4 $, and $ 9-2+1 $). Then, add that tens complement number to the original minuend: \n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     735\n    +~underline[858]\n    1593\n\\end{binDisp}\n\nThe initial one in the answer (the thousands place) is dropped so the answer has the same number of decimal places as the addends, leaving $ 593 $, which is the correct answer for $ 735-142 $.\n\n\\subsubsection{Binary}\n\\label{MO:subsub:binary_subtraction_with_radix_complement}\n\nTo find the radix (or twos) complement of a binary number, each bit in the number is ``flipped'' (making the ones complement) and then one is added to the result. Thus, the twos complement of $ 11010_2 $ is $ 00110_2 $ (or $ (00101_2)+1_2 $). Just as in decimal, a binary number can be subtracted from another by adding the radix complement of the subtrahend to the minuend. Here's an example: \n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     101001\n    -~underline[011011]\n\\end{binDisp}\n\nAdd the twos complement of the subtrahend:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     101001\n    +~underline[011011]\n    1001110\n\\end{binDisp}\n\nThe most significant bit is discarded so the solution has the same number of bits as for the two addends. This leaves $ 001110_2 $ (or $ 14_{10} $). Converting all of this to decimal, the original problem is $ 41-27=14 $.\n\nHere are two worked out examples:\n\nCalculate $ 0110_2 - 0010_2 $ (or $ 6_{10} - 2_{10} $):\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     0110  (6)\n    -~underline[0010  (2)]\n\\end{binDisp}\n\nSolution:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     0110  (6)\n    +~underline[1110  (-2 in twos complement)]\n    10100  (Discard the MSB, the answer is 4)\n\\end{binDisp}\n\nCalculate $ 0010_2 - 0110_2 $ (or $ 2_{10} - 6_{10} $)\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     0010  (2)\n    -~underline[0110  (6)]\n\\end{binDisp}\n\nSolution:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     0010  (2)\n    +~underline[1010  (-6 in twos complement)]\n     1100\n     0100  (Twos complement of the sum, -4)\n\\end{binDisp}\n\n\\subsection{Overflow}\n\\label{MO:sub:overflow}\n\nOne caveat with signed binary numbers is that of overflow, where the answer to an addition or subtraction problem exceeds the magnitude which can be represented with the allotted number of bits. Remember that the sign bit is defined as the most significant bit in the number. For example, with a six-bit number, five bits are used for magnitude, so there is a range from $ 00000_2 $ to $ 11111_2 $, or $ 0_{10} $ to $ 31_{10} $. If a sign bit is included, and using twos complement, numbers as high as $ 011111_2 $ ($ +31_{10} $) or as low as $ 100000_2 $ ($ -32_{10} $) are possible. However, an addition problem with two signed six-bit numbers that results in a sum greater than $ +31_{10} $ or less than $ -32_{10} $ will yield an incorrect answer. As an example, add $ 17_{10} $ and $ 19_{10} $ with signed six-bit numbers: \n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     010001  (17)\n    +~underline[010011  (19)]\n     100100\n\\end{binDisp}\n\nThe answer ($ 100100_2 $), interpreted with the most significant bit as a sign, is equal to $ -28_{10} $, not $ +36_{10} $ as expected. Obviously, this is not correct. The problem lies in the restrictions of a six-bit number field. Since the true sum ($ 36 $) exceeds the allowable limit for our designated bit field (five magnitude bits, or $ +31 $), it produces what is called an overflow error. Simply put, six places is not large enough to represent the correct sum if the \\ac{MSB} is being used as a sign bit, so whatever sum is obtained will be incorrect. A similar error will occur if two negative numbers are added together to produce a sum that is too small for a six-bit binary field. As an example, add $ -17_{10} $ and $ -19_{10} $: \n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     -17 = 101111\n     -19 = 101101\n\n     101111  (-17)\n    +~underline[101101  (-19)]\n    1011100\n\\end{binDisp}\n\nThe solution as shown: $ 011100_2 $ = $ +28_{10} $. (Remember that the most significant bit is dropped in order for the answer to have the same number of places as the two addends.) The calculated (incorrect) answer for this addition problem is $ 28 $ because true sum of $ -17 + -19 $ was too small to be properly represented with a five bit magnitude field.\n\nHere is the same overflow problem again, but expanding the bit field to six magnitude bits plus a seventh sign bit. In the following example, both $ 17 + 19 $ and $ (-17) + (-19) $ are calculated to show that both can be solved using a seven-bit field rather than six-bits. \n\nAdd 17 + 19:\n\n\\begin{binDisp}[commandchars=~\\[\\], samepage=true]\n     0010001  (17)\n    +~underline[0010011  (19)]\n     0100100  (36)\n\\end{binDisp}\n\nAdd (-17) + (-19):\n\n\\begin{binDisp}[commandchars=~\\[\\], samepage=true]\n     -17 = 1101111\n     -19 = 1101101\n\n     1101111  (-17)\n    +~underline[1101101  (-19)]\n    11011100  (-36)\n\\end{binDisp}\n\nThe correct answer is only found by using bit fields sufficiently large to handle the magnitude and sign bits in the sum.\n\n\\subsubsection{Error Detection}\n\\label{MO:subsub:error_detection}\n\nOverflow errors in the above problems were detected by checking the problem in decimal form and then comparing the results with the binary answers calculated. For example, when adding $ +17 $ and $ +19 $, the answer was supposed to be $ +36 $, so when the binary sum was $ -28 $, something had to be wrong. Although this is a valid way of detecting overflow errors, it is not very efficient, especially for computers. After all, the whole idea is to reliably add binary numbers together and not have to double-check the result by adding the same numbers together in decimal form. This is especially true when building logic circuits to add binary quantities: the circuit must detect an overflow error without the supervision of a human who already knows the correct answer.\n\nThe simplest way to detect overflow errors is to check the sign of the sum and compare it to the signs of the addends. Obviously, two positive numbers added together will give a positive sum and two negative numbers added together will give a negative sum. With an overflow error, however, the sign of the sum is always opposite that of the two addends: $ (+17) + (+19) = -28 $ and $ (-17) + (-19) = +28 $. By checking the sign bits an overflow error can be detected. \n\nIt is not possible to generate an overflow error when the two addends have opposite signs. The reason for this is apparent when the nature of overflow is considered. Overflow occurs when the magnitude of a number exceeds the range allowed by the size of the bit field. If a positive number is added to a negative number then the sum will always be closer to zero than either of the two added numbers; its magnitude must be less than the magnitude of either original number, so overflow is impossible.\n\n\\section{Binary Multiplication}\n\\label{MO:sec:binary_multiplication}\n\n\\subsection{Multiplying Unsigned Numbers}\n\\label{MO:sub:multiplying_unsigned_numbers}\n\nMultiplying binary numbers is very similar to multiplying decimal numbers. There are only four entries in the Binary Multiplication Table:\n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{1}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ c } \n      $ 0X0=0 $   \\\\\n      $ 0X1=0 $   \\\\\n      $ 1X0=0 $   \\\\\n      $ 1X1=1 $\n    \\end{tabular}\n  \\end{center}\n  \\caption{Binary Multiplication Table}\n  \\label{MO:tab:binary_multiplication}\n\\end{table} \n\nTo multiply two binary numbers, work through the multiplier one number at a time (right-to-left) and if that number is one, then shift left and copy the multiplicand as a partial product; if that number is zero, then shift left but do not copy the multiplicand (zeros can be used as placeholders if desired). When the multiplying is completed add all partial products. This sounds much more complicated than it actually is in practice and is the same process that is used to multiply two decimal numbers. Here is an example problem.\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n        1011  (11)\n      X ~underline[1101  (13)]\n        1011\n       0000\n      1011\n     ~underline[1011          ]\n    10001111  (143)\n\\end{binDisp}\n\n\\subsection{Multiplying Signed Numbers}\n\\label{MO:sub:multiplying_signed_numbers}\n\nThe simplest method used to multiply two numbers where one or both are negative is to use the same technique that is used for decimal numbers: multiply the two numbers and then determine the sign from the signs of the original numbers: if those signs are the same then the result is positive, if they are different then the result is negative. Multiplication by zero is a special case where the result is always zero.\n\nThe multiplication method discussed above works fine for paper-and-pencil; but is not appropriate for designing binary circuits. Unfortunately, the mathematics for binary multiplication using an algorithm that can become an electronic circuit is beyond the scope of this book. Fortunately, though, \\acp{IC} already exist that carry out multiplication of both signed and floating-point numbers, so a circuit designer can use a pre-designed circuit and not worry about the complexity of the multiplication process.\n\n\\section{Binary Division}\n\\label{MO:sec:binary_division}\n\nBinary division is accomplished by repeated subtraction and a right shift function; the reverse of multiplication. The actual process is rather convoluted and complex and is not covered in this book. Fortunately, though, \\acp{IC} already exist that carry out division of both signed and floating-point numbers, so a circuit designer can use a pre-designed circuit and not worry about the complexity of the division process.\n\n\\section{Bitwise Operations}\n\\label{MO:sec:bitwise_operations}\n\nIt is sometimes desirable to find the value of a given bit in a byte. For example, if the \\ac{LSB} is zero then the number is even, but if it is one then the number is odd. To determine the ``evenness'' of a number, a bitwise mask is multiplied with the original number. As an example, imagine that it is desired to know if $ 1001010_2 $ is even, then:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n         1001010  <- Original Number\n    BitX ~underline[0000001]  <- \"Evenness\" Mask\n         0000000\n\\end{binDisp}\n\nThe bits are multiplied one position at a time, from left-to-right. Any time a zero appears in the mask that bit position in the product will be zero since any number multiplied by zero yields zero. When a one appears in the mask, then the bit in the original number will be copied to the solution. In the given example, the zero in the least significant bit of the top number is multiplied with one and the result is zero. If that \\ac{LSB} in the top number had been one then the \\ac{LSB} in the result would have also been one. Therefore, an ``even'' original number would yield a result of all zeros while an odd number would yield a one.\n\n\\section{Codes}\n\\label{MO:sec:codes}\n\n\\subsection{Introduction}\n\\label{MO:sub:codes_introduction}\n\nCodes are nothing more than using one system of symbols to represent another system of symbols or information. Humans have used codes to encrypt secret information from ancient times. However, digital logic codes have nothing to do with secrets; rather, they are only concerned with the efficient storage, retrieval, and use of information. \n\n\\subsubsection{Morse Code}\n\\label{MO:subsub:morse_code}\n\nAs an example of a familiar code, Morse code changes letters to electric pulses that can be easily transmitted over a radio or telegraph wire. Samuel Morse's code uses a series of dots and dashes to represent letters so an operator at one end of the wire can use electromagnetic pulses to send a message to some receiver at a distant end. Most people are familiar with at least one phrase in Morse code: \\emph{SOS}. Here is a short sentence in Morse: \n\n\\begin{binDisp}[commandchars=~\\[\\]]\n  -.-. --- -.. . ...   .- .-. .   ..-. ..- -.\n   c    o   d  e  s    a   r  e    f    u  n\n\\end{binDisp}\n\n\\subsubsection{Braille Alphabet}\n\\label{MO:subsub:braille_alphabet}\n\nAs one other example of a commonly-used code, in $ 1834 $ Louis Braille, at the age of $ 15 $, created a code of raised dots that enable blind people to read books. For those interested in this code, the Braille alphabet can be found at \\url{http://braillebug.afb.org/braille_print.asp}. \n\n\\subsection{Computer Codes}\n\\label{MO:sub:computer_codes}\n\nThe fact is, computers can only work with binary numbers; that is how information is stored in memory, how it is processed by the \\ac{CPU}, how it is transmitted over a network, and how it is manipulated in any of a hundred different ways. It all boils down to binary numbers. However, humans generally want a computer to work with words (such as email or a word processor), ciphers (such as a spreadsheet), or graphics (such as photos). All of that information must be encoded into binary numbers for the computer and then decoded back into understandable information for humans. Thus, binary numbers stored in a computer are often codes used to represent letters, programming steps, or other non-numeric information. \n\n\\subsubsection{ASCII}\n\\label{MO:subsub:ascii}\n\nComputers must be able to store and process letters, like those on this page. At first, it would seem easiest to create a code by simply making \\lstinline[columns=fixed]|A=1|, \\lstinline[columns=fixed]|B=2|, and so forth. While this simple code does not work for a number of reasons, the idea is on the right track and the code that is actually used for letters is similar to this simple example. \n\nIn the early $ 1960 $s, computer scientists came up with a code they named \\ac{ASCII} and this is still among the most common ways to encode letters and other symbols for a computer. If the computer program knows that a particular spot in memory contains binary numbers that are actually ASCII-coded letters, it is a fairly easy job to convert those codes to letters for a screen display. For simplicity, \\ac{ASCII} is usually represented by hexadecimal numbers rather than binary. For example, the word \\emph{Hello} in \\ac{ASCII} is: $ 048 \\; 065 \\; 06C \\; 06C \\; 06F $.\n\n\\ac{ASCII} code also has a predictable relationship between letters. For example, capital letters are exactly $ 20_{16} $ higher in ASCII than their lower-case version. Thus, to change a letter from lower-case to upper-case, a programmer can add $ 20_{16} $ to the \\ac{ASCII} code for the lower-case letter. This can be done in a single processing step by using what is known as a \\emph{bit-wise \\textsf{AND}} on the bit representing $ 20_{16} $ in the \\ac{ASCII} code's binary number.\n\nAn \\ac{ASCII} chart using hexadecimal values is presented in Table \\ref{MO:tab:ascii_table}. The most significant digit is read across the top row and the least significant digit is read down the left column. For example, the letter \\emph{A} is $ 41_{16} $ and the number \\emph{6} is $ 36_{16} $.\n\n\\begin{table}[H]\n  \\sisetup{parse-numbers = false}\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ c c c c c c c c c } \n      \\hline\n      \\rowcolor{black!75}\n      & {\\head{0}} & {\\head{1}} & {\\head{2}} & {\\head{3}}\n      & {\\head{4}} & {\\head{5}} & {\\head{6}} & {\\head{7}} \\\\\n      \\hline  \n      \\cellcolor{black!75}\\head{0} & {NUL} & {DLE} & {} & {0} & {@} & \n      {P} & {'} & {p} \n      \\\\\n      \\cellcolor{black!75}\\head{1} & {SOH} & {DC1} & {!} & {1} & {A} & \n      {Q} & {a} & {q} \n      \\\\\n      \\cellcolor{black!75}\\head{2} & {STX} & {DC2} & {''} & {2} & {B} & \n      {R} & {b} & {r} \n      \\\\\n      \\cellcolor{black!75}\\head{3} & {ETX} & {DC3} & {\\#} & {3} & {C} & \n      {S} & {c} & {s} \n      \\\\\n      \\cellcolor{black!75}\\head{4} & {EOT} & {DC4} & {\\$} & {4} & {D} & \n      {T} & {d} & {t} \n      \\\\\n      \\cellcolor{black!75}\\head{5} & {ENQ} & {NAK} & {\\%} & {5} & {E} & \n      {U} & {e} & {u} \n      \\\\\n      \\cellcolor{black!75}\\head{6} & {ACK} & {SYN} & {\\&} & {6} & {F} & \n      {V} & {f} & {v} \n      \\\\\n      \\cellcolor{black!75}\\head{7} & {BEL} & {ETB} & {'} & {7} & {G} & \n      {W} & {g} & {w} \n      \\\\\n      \\cellcolor{black!75}\\head{8} & {BS} & {CAN} & {(} & {8} & {H} & \n      {X} & {h} & {x}\n      \\\\\n      \\cellcolor{black!75}\\head{9} & {HT} & {EM} & {)} & {9} & {I} & \n      {Y} & {i} & {y} \n      \\\\\n      \\cellcolor{black!75}\\head{A} & {LF} & {SUB} & {*} & {:} & {J} & \n      {Z} & {j} & {z} \n      \\\\\n      \\cellcolor{black!75}\\head{B} & {VT} & {ESC} & {+} & {;} & {K} & \n      $ [ $ & {k} & \\{ \n      \\\\\n      \\cellcolor{black!75}\\head{C} & {FF} & {FS} & {,} & $ < $ & {L} & \n      \\textbackslash & {l} & {$ \\arrowvert $} \n      \\\\\n      \\cellcolor{black!75}\\head{D} & {CR} & {GS} & {-} & {=} & {M} & \n      $ ] $ & {m} & {\\}} \n      \\\\\n      \\cellcolor{black!75}\\head{E} & {SO} & {RS} & {.} & $ > $ & {N} & \n      $ \\wedge $ & {n} & $ \\sim $ \n      \\\\\n      \\cellcolor{black!75}\\head{F} & {SI} & {US} & {/} & {?} & {O} & \n      {\\_} & {o} & {DEL}       \n      \\\\\n      \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{ASCII Table}\n  \\label{MO:tab:ascii_table}\n\\end{table}\n\n\\marginpar{Teletype operators from decades past tell stories of sending 25 or more $ 07_{16} $ codes (ring the bell) to a receiving terminal just to irritate another operator in the middle of the night.} \\ac{ASCII} $ 20_{16} $ is a space character used to separate words in a message and the first two columns of ASCII codes (where the high-order nibble are zero and one) were codes essential for teletype machines, which were common from the $ 1920 $s until the $ 1970 $s. The meanings of a few of those special codes are given in Table \\ref{MO:tab:ascii_symbols}.\n\n\\begin{table}[H]\n  \\sisetup{parse-numbers = false}\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{1}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ c l } \n      \\hline \\hline % The gray in the first row overwrites the first hline - so do it twice.\n      {NUL} & {All Zeros (a ``null'' byte)} \\\\\n      {SOH} & {Start of Header} \\\\\n      {STX} & {Start of Text} \\\\\n      {ETX} & {End of Text} \\\\\n      {EOT} & {End of Transmission} \\\\\n      {ENQ} & {Enquire (is the remote station on?)} \\\\\n      {ACK} & {Acknowledge (the station is on)} \\\\\n      {BEL} & {Ring the terminal bell (get the operator's attention)} \\\\\n      \\hline  \n    \\end{tabular}\n  \\end{center}\n  \\caption{ASCII Symbols}\n  \\label{MO:tab:ascii_symbols}\n\\end{table}\n\nTable \\ref{MO:tab:ascii_practice} contains a few phrases in both plain text and ASCII for practice.\n\n\\begin{table}[H]\n  \\sisetup{parse-numbers = false}\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ c l } \n      \\hline\n      \\rowcolor{black!75}\n      {\\head{Plain Text}} & {\\head{ASCII}} \\\\\n      \\hline    \n      {codes are fun} & {63 6f 64 65 73 20 61 72 65 20 66 75 6e} \\\\\n      {This is ASCII} & {54 68 69 73 20 69 73 20 41 53 43 49 49} \\\\\n      {365.25 days} & {33 36 35 2e 32 35 20 64 61 79 73} \\\\\n      {It's a gr8 day!} & {49 74 27 73 20 61 20 67 72 38 20 64 61 79 21} \\\\\n      \\hline  \n    \\end{tabular}\n  \\end{center}\n  \\caption{ASCII Practice}\n  \\label{MO:tab:ascii_practice}\n\\end{table}\n% Pull Quote - Marginal Note - Sidebar\n\nWhile the ASCII code is the most commonly used text representation, it is certainly not the only way to encode words. Another popular code is \\ac{EBCDIC} (pronounced like ``Eb See Deck''), which was invented by IBM in $ 1963 $ and has been used in most of their computers ever since.\n\nSince the early 2000's, computer programs have begun to use Unicode character sets, which are similar to ASCII but multiple bytes are combined to expand the number of characters available for non-English languages like Cyrillic.\n\n\\subsubsection{Binary Coded Decimal (BCD)}\n\\label{MO:subsub:binary_coded_decimal}\n\nIt is often desirable to have numbers coded in such a way that they can be easily translated back and forth between decimal (which is easy for humans to manipulate) and binary (which is easy for computers to manipulate). \\ac{BCD} is the code used to represent decimal numbers in binary systems. \\ac{BCD} is useful when working with decimal input (keypads or transducers) and output (displays) devices.\n\nThere are, in general, two types of \\ac{BCD} systems: non-weighted and weighted. Non-weighted codes are special codes devised for a single purpose where there is no implied relationship between one value and the next. As an example, $ 1001 $ could mean one and $ 1100 $ could mean two in some device. The circuit designer would create whatever code meaning is desired for the application. \n\nWeighted \\ac{BCD} is a more generalized system where each bit position is assigned a ``weight,'' or value. These types of \\ac{BCD} systems are far more common than non-weighted and are found in all sorts of applications. Weighted \\ac{BCD} codes can be converted to decimal by adding the place value for each position in exactly the same way that Expanded Positional Notation is used for to covert between decimal and binary numbers. As an example, the weights for the Natural \\ac{BCD} system are $ 8-4-2-1 $. (These are the same weights used for binary numbers; thus the name ``natural'' for this system.) The code $ 1001_{BCD} $ is converted to decimal like this: \n\n\\begin{align}\n  1001_{BCD} &= (1X8)+(0X4)+(0X2)+(1X1) \\\\\n  \\nonumber\n  &= (8)+(0)+(0)+(1) \\\\\n  \\nonumber\n  &= 9_{10}\n\\end{align}\n\nBecause there are ten decimal ciphers ($ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 $), it requires four bits to represent all decimal digits; so most \\ac{BCD} code systems are four bits wide. In practice, only a few different weighted \\ac{BCD} code systems are commonly used and the most common are shown in Table \\ref{MO:tab:bcd_systems}. \n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ c c c c c } \n      \\hline\n      \\rowcolor{black!75}\n      {\\head{Decimal}} & {\\head{8421 (Natural)}} & \\head{2421} \n      & \\head{Ex3} & \\head{5421} \\\\\n      \\hline    \n      0 & 0000 & 0000 & 0011 & 0000 \\\\\n      1 & 0001 & 0001 & 0100 & 0001 \\\\\n      2 & 0010 & 0010 & 0101 & 0010 \\\\\n      3 & 0011 & 0011 & 0110 & 0011 \\\\\n      4 & 0100 & 0100 & 0111 & 0100 \\\\\n      5 & 0101 & 1011 & 1000 & 1000 \\\\\n      6 & 0110 & 1100 & 1001 & 1001 \\\\\n      7 & 0111 & 1101 & 1010 & 1010 \\\\\n      8 & 1000 & 1110 & 1011 & 1011 \\\\\n      9 & 1001 & 1111 & 1100 & 1100 \\\\\n      \\hline  \n    \\end{tabular}\n  \\end{center}\n  \\caption{BCD Systems}\n  \\label{MO:tab:bcd_systems}\n\\end{table}\n\n\\marginpar{Remember that BCD is a code system, not a number system; so the meaning of each combination of four-bit codes is up to the designer and will not necessarily follow any sort of binary numbering sequence.}The name of each type of \\ac{BCD} code indicates the various place values. Thus, the $ 2421 $ \\ac{BCD} system gives the most significant bit of the number a value of two, not eight as in the natural code. The \\emph{Ex3} code (for ``Excess 3'') is the same as the natural code, but each value is increased by three (that is, three is added to the natural code). \n\nIn each of the \\ac{BCD} code systems in Table \\ref{MO:tab:bcd_systems} there are six unused four-bit combinations; for example, in the \\emph{Natural} system the unused codes are: $ 1010, 1011, 1100, 1101, 1110, $ and $ 1111 $. Thus, any circuit designed to use \\ac{BCD} must include some sort of check to ensure that if unused binary values are accidentally input into a circuit it does not create an undefined outcome.\n\nNormally, two \\ac{BCD} codes, each of which are four bits wide, are packed into an eight-bit byte in order to reduce wasted computer memory. Thus, the packed \\ac{BCD} $ 0111 0010 $ contains two BCD numbers: $ 72 $. In fact, a single 32-bit word, which is common in many computers, can contain $ 8 $ \\ac{BCD} codes. It is a trivial matter for software to either pack or unpack \\ac{BCD} codes from a longer word.\n\nIt is natural to wonder why there are so many different ways to code decimal numbers. Each of the \\ac{BCD} systems shown in Table \\ref{MO:tab:bcd_systems} has certain strengths and weaknesses and a circuit designer would choose a specific system based upon those characteristics.\n\n\\paragraph{Converting between BCD and Other Systems.} One thing that makes \\ac{BCD} so useful is the ease of converting from \\ac{BCD} to decimal. Each decimal digit is converted into a four-bit \\ac{BCD} code, one at a time. Here is $ 37_{10} $ in Natural \\ac{BCD}:\n\n\\begin{binDisp}\n     0011 0111\n       3    7\n\\end{binDisp}\n\nIt is, generally, very easy to convert Natural \\ac{BCD} to decimal since the \\ac{BCD} codes are the same as binary numbers. Other \\ac{BCD} systems use different place values, and those require more thought to convert (though the process is the same). The place values for \\ac{BCD} systems other than Natural are indicated in the name of the system; so, for example, the $ 5421 $ system would interpret the number $ 1001_{BCD5421} $ as:\n\n\\begin{align}\n  1001_{BCD5421} &= (1X5)+(0X4)+(0X2)+(1X1) \\\\\n  \\nonumber\n  &= (5)+(0)+(0)+(1) \\\\\n  \\nonumber\n  &= 6_{10}\n\\end{align}\n\nConverting from decimal to \\ac{BCD} is also a rather simple process. Each decimal digit is converted to a four-bit \\ac{BCD} equivalent. In the case of Natural \\ac{BCD} the four-bit code is the binary equivalent to the decimal number, other weighted \\ac{BCD} codes would be converted with a similar process.\n\n\\begin{binDisp}\n      2    4    5\n    0010 0100 0101\n\\end{binDisp}\n\n%TODO If codes are separated from this chapter then the Double-Dabble system could be explained in some detail.\n\nTo convert binary to \\ac{BCD} is no trivial exercise and is best done with an automated process. The normal method used is called the \\emph{Shift Left and Add Three} algorithm (or, frequently, \\emph{Double-Dabble}). The process involves a number of steps where the binary number is shifted left and occasionally three is added to the resulting shift. Wikipedia (\\url{https://en.wikipedia.org/wiki/Double_dabble}) has a good explanation of this process, along with some examples.\n\nConverting \\ac{BCD} to any other system (like hexadecimal) is most easily done by first converting to binary and then to whatever base is desired. Unfortunately, converting \\ac{BCD} to binary is not as simple as concatenating two \\ac{BCD} numbers; for example, $ 0100 0001 $ is 41 in \\ac{BCD}, but those two \\ac{BCD} numbers concatenated, $ 01000001 $, is $ 65 $ in binary. One way to approach this type of problem is to use the reverse of the \\emph{Double-Dabble} process: \\emph{Shift Right and Subtract Three}. As in converting binary to \\ac{BCD}, this is most easily handled by an automated process.\n\n\\paragraph{Self-Complementing.} The Excess-3 code (called \\emph{Ex3} in the table) is self-complementing; that is, the nines complement of any decimal number is found by complementing each bit in the Ex3 code. As an example, find the nines complement for $ 127_{10} $:\n\n\\begin{table}[H]\n  \\sisetup{parse-numbers = false}\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    %\\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ c | c l } \n      \\hline\n      1 & $ 127_{10} $ & {Original Number} \\\\\n      2 & $ 0100 \\; 0101 \\; 1010_{Ex3} $ & {Convert 127 to Excess 3} \\\\\n      3 & $ 1011 \\; 1010 \\; 0101_{Ex3} $ & {Ones Complement} \\\\\n      4 & $ 872_{10} $ & {Convert to Decimal} \\\\\n      \\hline  \n    \\end{tabular}\n  \\end{center}\n  \\caption{Nines Complement for 127}\n  \\label{MO:tab:nines_complement}\n\\end{table}\n\nThus, $ 872_{10} $, is the nines complement of $ 127_{10} $. It is a powerful feature to be able to find the nines complement of a decimal number by simply complementing each bit of its Ex3 \\ac{BCD} representation. \n\n\\paragraph{Reflexive.} Some \\ac{BCD} codes exhibit a reflexive property where each of the upper five codes are complementary reflections of the lower five codes. For example, $ 0111_{Ex3} $ (4) and $ 1000_{Ex3} $ (5) are complements, $ 0110_{Ex3} $ (3) and $ 1001_{Ex3} $ (6) are complements, and so forth. The reflexive property for the $ 5421 $ code is different. Notice that the codes for zero through four are the same as those for five through nine, except for the \\ac{MSB} (zero for the lower codes, one for the upper codes). Thus, $ 0000_{5421} $ (zero) is the same as $ 1000_{5421} $ (five) except for the first bit, $ 0001_{5421} $ (one) is the same as $ 1001_{5421} $ (six) except for the first bit, and so forth. Studying Table \\ref{MO:tab:bcd_systems} should reveal the various reflexive patterns found in these codes.\n\n\\paragraph{Practice.} Table \\ref{MO:tab:bcd_practice} shows several decimal numbers in various \\ac{BCD} systems which can be used for practice in converting between these number systems.\n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    {\\small         \n      \\begin{tabular}{ c c c c c } \n        \\hline\n        \\rowcolor{black!75}\n        {\\head{Dec}} & {\\head{8421}} & \\head{2421} \n        & \\head{Ex3} & \\head{5421} \\\\\n        \\hline    \n        57  & 0101 1110      & 10111 1101     \n            & 1000 1010      & 1000 1010 \\\\\n        79  & 0111 1001      & 1101 1111      \n            & 1010 1100      & 1010 1100 \\\\\n        \n        28  & 0010 1000      & 0010 1110      \n            & 0101 1011      & 0010 1011 \\\\\n        421 & 0100 0010 0001 & 0100 0010 0001 \n            & 0111 0101 0100 & 0100 0010 0001 \\\\\n        \n        903 & 1001 0000 0011 & 1111 0000 0011 \n            & 1100 0011 0110 & 1100 0000 0011 \\\\\n        \\hline  \n      \\end{tabular}\n    }  % End small font size\n  \\end{center}\n  \\caption{BCD Practice}\n  \\label{MO:tab:bcd_practice}\n\\end{table}\n\n\\paragraph{Adding BCD Numbers.} \\ac{BCD} numbers can be added in either of two ways. Probably the simplest is to convert the \\ac{BCD} numbers to binary, add them as binary numbers, and then convert the sum back to \\ac{BCD}. However, it is possible to add two \\ac{BCD} numbers without converting. When two \\ac{BCD} numbers are added such that the result is less than ten, then the addition is the same as for binary numbers:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     0101  (5)\n    +~underline[0010  (2)]\n     0111  (7)\n\\end{binDisp}\n\nHowever, four-bit binary numbers greater than $ 1001_2 $ (that is: $ 9_{10} $) are invalid \\ac{BCD} codes, so adding two \\ac{BCD} numbers where the result is greater than nine requires a bit more effort:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     0111  (7)\n    +~underline[0101  (5)]\n     1100  (12 -- not valid in BCD)\n\\end{binDisp}\n\nWhen the sum is greater than nine, then six must be added to that result since there are six invalid binary codes in \\ac{BCD}.\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     1100  (12 -- from previous addition)\n    +~underline[0110  (6)]\n   1 0010  (12 in BCD)\n\\end{binDisp}\n\nWhen adding two-digit \\ac{BCD} numbers, start with the \\ac{LSN}, the right-most nibble, then add the nibbles with carry bits from the right. Here are some examples to help clarify this concept:\n\n\\begin{binDisp}[commandchars=~\\[\\], samepage=true]\n     0101 0010  (52)\n    +~underline[0011 0110  (36)]\n     1000 1000  (88 in BCD)\n\\end{binDisp}\n\n\\begin{binDisp}[commandchars=~\\[\\], samepage=true]\n     0101 0010  (52)\n    +~underline[0101 0110  (56)]\n     1010 1000  (1010, MSN, invalid BCD code)\n    +~underline[0110 0000  (Add 6 to invalid code)]\n   1 0000 1000  (108 in BCD)\n\\end{binDisp}\n\n\\begin{binDisp}[commandchars=~\\[\\], samepage=true]\n     0101 0101  (55)\n    +~underline[0101 0110  (56)]\n     1010 1011  (both nibbles invalid BCD code)\n    +~underline[0000 0110  (Add 6 to LSN)]\n     1011 0001  (1 carried over to MSN)\n    +~underline[0110 0000  (Add 6 to MSN)]\n   1 0001 0001  (111 in BSD)\n\\end{binDisp}\n\n\\paragraph{Negative Numbers.} \\ac{BCD} codes do not have any way to store negative numbers, so a sign nibble must be used. One approach to this problem is to use a sign-and-magnitude value where a sign nibble is prefixed onto the \\ac{BCD} value. By convention, a sign nibble of $ 0000 $ makes the \\ac{BCD} number positive while $ 1001 $ makes it negative. Thus, the \\ac{BCD} number $ 0000 0010 0111 $ is $ 27 $, but $ 1001 0010 0111 $ is $ -27 $. \n\nA more mathematically rigorous, and useful, method of indicating negative \\ac{BCD} numbers is use the tens complement of the \\ac{BCD} number since \\ac{BCD} is a code for decimal numbers, exactly like the twos complement is used for binary numbers. It may be useful to review Section \\ref{MO:subsub:about_complementation} on page \\pageref{MO:subsub:about_complementation} for information about the tens complement. In the \\emph{Natural BCD} system the tens complement is found by adding one to the nines complement, which is found by subtracting each digit of the original \\ac{BCD} number from nine. Here are some examples to clarify this concept:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n    0111 (7 in BCD)\n    0010 (2, the 9's complement of 7 since 9-7=2)\n    0011 (3, the 10's complement of 7, or 2+1)\n\\end{binDisp}\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n    0010 0100 (24 in BCD)\n    0111 0101 (75, the 9's complement of 24)\n    0111 0110 (76, the 10's complement of 24)\n\\end{binDisp}\n\nAlso, some \\ac{BCD} code systems are designed to easily create the tens complement of a number. For example, in the $ 2421 $ \\ac{BCD} system the tens complement is found by nothing more than inverting the \\ac{MSB}. Thus, three is the tens complement of seven and in the $ 2421 $ \\ac{BCD} system $ 0011_{BCD2421} $ is the tens complement of $ 1101_{BCD2421} $, a difference of only the \\ac{MSB}. Therefore, designers creating circuits that must work with negative \\ac{BCD} numbers may opt to use the $ 2421 $ \\ac{BCD} system.\n\n\\paragraph{Subtracting BCD Numbers.} A \\ac{BCD} number can be subtracted from another by changing it to a negative number and adding. Just like in decimal, $ 5 - 2 $ is the same as $ 5 + (-2) $. Either a nines or tens complement can be used to change a \\ac{BCD} number to its negative, but for this book, the tens complement will be used. If there is a carry-out bit then it can be ignored and the result is positive, but if there is no carry-out bit then answer is negative so the magnitude must be found by finding the tens complement of the calculated sum. Compare this process with subtracting regular binary numbers. Here are a few examples:\n\n\\begin{minipage}{\\linewidth} % This keeps the block on the same page\n\\begin{binDisp}[commandchars=~\\[\\]]\n\n    7 - 3 = 4\n\n          0111  (7 in BCD)\n         +~underline[0111  (add the 10's complement of 3)]\n          1110  (invalid BCD code)\n         +~underline[0110  (add 6 to invalid BCD code)]\n        1 0100  (4 - drop the carry bit)\n\n\\end{binDisp}\n\\end{minipage}\n\n\\begin{minipage}{\\linewidth} % This keeps the block on the same page\n\\begin{binDisp}[commandchars=~\\[\\]]\n\n    7 - 9 = -2\n\n          0111  (7 in BCD)\n         +~underline[0001  (10's complement of 9)]\n          1000  (valid BCD code)\n          0010  (10's complement)\n\n\\end{binDisp}\n\\end{minipage}\n\n\\begin{minipage}{\\linewidth} % This keeps the block on the same page\n\\begin{binDisp}[commandchars=~\\[\\]]\n\n    32 - 15 = 17\n\n          0011 0010  (32 in BCD)\n         +~underline[1000 0101  (10's complement of 15)]\n          1011 0111  (MSB is invalid BCD code)\n         +~underline[0110 0000  (add 6 to MSB)]\n        1 0001 0111  (17, drop the carry bit)\n\n\\end{binDisp}\n\\end{minipage}\n\n\\begin{minipage}{\\linewidth} % This keeps the block on the same page\n\\begin{binDisp}[commandchars=~\\[\\]]\n\n    427 - 640 = -213\n\n          0100 0010 0111  (427 in BCD)\n         +~underline[0011 0110 0000  (10's complement of 640)]\n          0111 1000 0111  (no invalid BCD code)\n          0010 0001 0011  (10's complement)\n\n\\end{binDisp}\n\\end{minipage}\n\n\\begin{minipage}{\\linewidth} % This keeps the block on the same page\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n\n    369 - 532 = -163\n\n          0011 0110 1001  (369 in BCD)\n         +~underline[0100 0110 1000  (10's complement of 532)]\n          0111 1100 0001  (two invalid BCD codes)\n         +~underline[0000 0110 0110  (add 6 to invalid codes)]\n          1000 0011 0111  (sum)\n          0001 0110 0011  (10's complement)\n\n\\end{binDisp}\n\\end{minipage}\n\nHere are some notes on the last example: adding the \\ac{LSN} yields $ 1001+1000=10001 $. The initial one is ignored, but this is an invalid \\ac{BCD} code so this byte needs to be corrected by adding six to it. Then the result of that addition includes an understood carry into the next nibble after the correction is applied. In the same way, the middle nibble was corrected: $ 1100+0110=10011 $ but the initial one in this answer is carried to the \\ac{MSN} and added there.\n\n\\subsubsection{Gray Code}\n\\label{MO:subsub:gray_code}\n\n% Draw a Gray Code Wheel\n% Cite: http://tex.stackexchange.com/questions/56176/handling-of-wrapfig-pictures-in-latex\n\\begin{wrapfigure}{r}{0.3\\textwidth}\n  \\caption{Optical Disc}\n  \\label{MO:fig:gray_code_disc}\n  \\centering\n\n  \\xdef\\IntRad{2}\n  \\xdef\\Rad{.5}\n\n  \\newcommand{\\Sector}[2][]{%\n    \\draw[#1] (22.5:#2) arc (22.5:0:#2)\n    --(#2+\\Rad,0) arc (0:22.5:#2+\\Rad)\n    -- cycle ;\n  }\n\n\\begin{tikzpicture}[scale=0.40]\n\n  \\foreach \\Loop [count=\\j from 0] in {%\n    {white,,,white,white,,,white,white,,,white,white,,,white},\n    {,,white,white,white,white,,,,,white,white,white,white,,},\n    {white,white,white,white,white,white,white,white,,,,,,,,},\n    {white,white,white,white,,,,,,,,,white,white,white,white}}\n  {\\foreach \\col [count=\\i from 0] in \\Loop {%\n      \\begin{scope}[rotate={22.5*\\i}]\n      \\Sector[fill=\\col]{\\IntRad+\\j*\\Rad} ;   \n      \\end{scope}\n    }\n  }\n\n  \\begin{scope}[rotate=11.75]\n  \\draw[fill=white] (\\IntRad-.2,-.5*\\Rad) rectangle (\\IntRad+.2+4*\\Rad,.5*\\Rad) ;\n\n  \\foreach \\col [count=\\i from 0, evaluate=\\i as \\j using 0.5+\\i]\n  in {white,black,white,white} {%\n    \\draw[fill=\\col] (\\IntRad+\\j*\\Rad,0) circle (.25*\\Rad) ;\n  }\n  \\end{scope}\n\\end{tikzpicture}\n\\end{wrapfigure}\n\nIt is often desirable to use a wheel to encode digital input for a circuit. As an example, consider the tuning knob on a radio. The knob is attached to a shaft that has a small, clear disk which is etched with a code, similar to Figure \\ref{MO:fig:gray_code_disc}. As the disk turns, the etched patterns pass or block a laser beam from reaching an optical sensor, and that pass/block pattern is encoded into binary input. \n\nOne of the most challenging aspects of using a mechanical device to encode binary is ensuring that the input is stable. As the wheel turns past the light beam, if two of the etched areas change at the same time (thus, changing two bits at once), it is certain that the input will fluctuate between those two values for a tiny, but significant, period of time. For example, imagine that the encoded circuit changes from $ 1111 $ to $ 0000 $ at one time. Since it is impossible to create a mechanical wheel precise enough to change those bits at exactly the same moment in time (remember that the light sensors will ``see'' an input several million times a second), as the bits change from $ 1111 $ to $ 0000 $ they may also change to $ 1000 $ or $ 0100 $ or any of dozens of other possible combinations for a few microseconds. The entire change may form a pattern like $ 1111-0110-0010-0000 $ and that instability would be enough to create havoc in a digital circuit. \n\nThe solution to the stability problem is to etch the disk with a code designed in such a way that only one bit changes at a time. The code used for that task is the Gray code. Additionally, a Gray code is cyclic, so when it reaches its maximum value it can cycle back to its minimum value by changing only a single bit. In Figure \\ref{MO:fig:gray_code_disc}, each of the concentric rings encodes one bit in a four-bit number. Imagine that the disk is rotating past the fixed laser beam reader \\textemdash the black areas (``blocked light beam'') change only one bit at a time, which is characteristic of a Gray code pattern.\n\nIt is fairly easy to create a Gray code from scratch. Start by writing two bits, a zero and one: \n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     0\n     1\n\\end{binDisp}\n\nThen, reflect those bits by writing them in reverse order underneath the original bits:\n\n\\begin{binDisp}[commandchars=~\\[\\]]\n     0\n     1\n   -----\n     1\n     0\n\\end{binDisp}\n\nNext, prefix the top half of the group with a zero and the bottom half with a one to get a two-bit Gray code. \n\n\\begin{binDisp}\n     00\n     01\n     11\n     10  (2-bit Gray code)\n\\end{binDisp}\n\nNow, reflect all four values of the two-bit Gray code.\n\n\\begin{binDisp}\n     00\n     01\n     11\n     10\n   ------\n     10\n     11\n     01\n     00\n\\end{binDisp}\n\nNext, prefix the top half of the group with a zero and the bottom half with a one to get a three-bit Gray code.\n\n\\begin{binDisp}\n     000\n     001\n     011\n     010\n     110\n     111\n     101\n     100  (3-bit Gray code)\n\\end{binDisp}\n\nNow, reflect all eight values of a three-bit Gray code.\n\n\\begin{binDisp}\n     000\n     001\n     011\n     010\n     110\n     111\n     101\n     100\n   -------\n     100\n     101\n     111\n     110\n     010\n     011\n     001\n     000\n\\end{binDisp}\n\nFinally, prefix the top half of the group with a zero and the bottom half with a one to get a four-bit Gray code. \n\n\\begin{binDisp}\n     0000\n     0001\n     0011\n     0010\n     0110\n     0111\n     0101\n     0100\n     1100\n     1101\n     1111\n     1110\n     1010\n     1011\n     1001\n     1000  (four-bit Gray code)\n\\end{binDisp}\n\nThe process of reflecting and prefixing can continue indefinitely to create a Gray code of any desired bit length. Of course, Gray code tables are also available in many different bit lengths. Table \\ref{MO:tab:gray_codes} contains a two-bit, three-bit, and four-bit Gray code:\n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}    \n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n    \\begin{tabular}{ c c c } \n      \\hline\n      \\rowcolor{black!75}\n      {\\head{2-Bit Code}} & {\\head{3-Bit Code}} & \\head{4-Bit Code} \\\\ \n      \\hline    \n      00  & 000 & 0000 \\\\     \n      01  & 001 & 0001 \\\\     \n      11  & 011 & 0011 \\\\     \n      10  & 010 & 0010 \\\\     \n      & 110 & 0110 \\\\     \n      & 111 & 0111 \\\\     \n      & 101 & 0101 \\\\     \n      & 100 & 0100 \\\\     \n      &     & 1100 \\\\     \n      &     & 1101 \\\\     \n      &     & 1111 \\\\     \n      &     & 1110 \\\\     \n      &     & 1010 \\\\     \n      &     & 1011 \\\\     \n      &     & 1001 \\\\     \n      &     & 1000 \\\\     \n      \\hline  \n    \\end{tabular}\n  \\end{center}\n  \\caption{Gray Codes}\n  \\label{MO:tab:gray_codes}\n\\end{table}\n\n", "meta": {"hexsha": "8f086a2f1d208d6e25e5ac42046fe2191f0f4c29", "size": 67679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/03_Math_Operations.tex", "max_stars_repo_name": "grself/CIS221_Text", "max_stars_repo_head_hexsha": "e5d78f880e0bae66b33823ee22c68ed16696af3c", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2019-03-10T15:35:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T17:09:02.000Z", "max_issues_repo_path": "Chapters/03_Math_Operations.tex", "max_issues_repo_name": "grself/CIS221_Text", "max_issues_repo_head_hexsha": "e5d78f880e0bae66b33823ee22c68ed16696af3c", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-05-09T19:18:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-09T19:18:59.000Z", "max_forks_repo_path": "Chapters/03_Math_Operations.tex", "max_forks_repo_name": "grself/CIS221_Text", "max_forks_repo_head_hexsha": "e5d78f880e0bae66b33823ee22c68ed16696af3c", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-01-20T17:30:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-20T06:06:00.000Z", "avg_line_length": 57.4037319763, "max_line_length": 993, "alphanum_fraction": 0.6937011481, "num_tokens": 19760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970748488296, "lm_q2_score": 0.911179711217791, "lm_q1q2_score": 0.8025644243022316}}
{"text": "\\section*{Ex.34.3-3}\n\\subsection*{ $\\bar{L}\\leq_P L \\Leftrightarrow L \\leq_P \\bar{L}$}\n\nWe start by showing $\\Rightarrow$:\n\\\\\nSo assume $\\bar{L}\\leq_P L$.\n\nWe want to show that for every $x\\in \\bar{L} \\Leftrightarrow  f(x) \\in L$\n\nFor all $x\\in \\bar{L}$ it holds that\n\\begin{align*}\nx\\in \\bar{L} & \\Leftrightarrow x \\not\\in L \t\t\t\t\t&\\text{as $L$ and $\\bar{L}$ are complements}\\\\\n\t\t\t\t\t\t & \\Leftrightarrow f(x) \\not\\in \\bar{L} &\\text{as $\\leq_P$ implies a reducible function exists}\\\\\n\t\t\t\t\t\t & \\Leftrightarrow f(x) \\in L \t\t\t\t\t&\\text{as $L$ and $\\bar{L}$ are complements}\n\\end{align*}\nWhich show the first part.\n\nNow we show $\\Leftarrow$:\n\\\\\nAssume $L \\leq_P \\bar{L}$.\n\nWe want to show that for every $x\\in L \\Leftrightarrow  f(x) \\in \\bar{L}$\n\nFor all $x\\in L$ it holds that\n\\begin{align*}\nx\\in L       & \\Leftrightarrow x \\not\\in \\bar{L} \t\t\t\t\t&\\text{as $L$ and $\\bar{L}$ are complements}\\\\\n\t\t\t\t\t\t & \\Leftrightarrow f(x) \\not\\in L  &\\text{as $\\leq_P$ implies a reducible function exists}\\\\\n\t\t\t\t\t\t & \\Leftrightarrow f(x) \\in \\bar{L} \t\t\t\t\t&\\text{as $L$ and $\\bar{L}$ are complements}\n\\end{align*}\nWhich show the other arrow in the bi--implication. Hence we have shown what we wanted.", "meta": {"hexsha": "2a18783f520be4d598840553f13dc32aa78345e2", "size": 1178, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge4/Ex.34.3-3.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge4/Ex.34.3-3.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge4/Ex.34.3-3.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.2666666667, "max_line_length": 103, "alphanum_fraction": 0.6324278438, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.880797068590724, "lm_q1q2_score": 0.8025644090400423}}
{"text": "%% Jonathan's notes here\n\n\\section{Bayesian Statistics}\nA Bayesian statistical model approximates a `true' probability distribution over a set $X$\nfrom a collection of independent samples $x_1,...,x_n\\in X$ (the data) drawn from the distribution. \nHere we call $X$ the sample space.\n\nThe Bayesian model consists of a set of parameters $\\Theta$, along with an initial probability distribution $\\mathbb{P}$ over \nthe product space $\\Theta\\times X$. To avoid technical issues, we will assume that $X$ and $\\Theta$ are either finite\nsets or subsets of Euclidean space $\\mathbb{R}^d$. This means that $X$ and $\\Theta$ have a natural measure\n$\\mu_X$ and $\\mu_\\Theta$, respectively, which are either counting measure or Lesbesgue measure.\nWe will also assume that the distribution $\\mathbb{P}$ is absolutely\ncontinuous with respect to the product measure $\\mu_\\Theta\\times \\mu_X$, and thus has a density, which we denote by\n$\\mathbb{P}(\\theta,x)$.\n\nAbusing notation, we denote the marginal distributions of $X$ and $\\Theta$ as follows\n$$\\mathbb{P}(x) = \\int_{\\Theta} \\mathbb{P}(\\theta,x)d\\mu_\\Theta$$\n$$\\mathbb{P}(\\theta) = \\int_{X} \\mathbb{P}(\\theta,x)d\\mu_x$$\nand the conditional distributions as\n$$\\mathbb{P}(x|\\theta) = \\frac{\\mathbb{P}(\\theta,x)}{\\mathbb{P}(\\theta)}$$\n$$\\mathbb{P}(\\theta|x) = \\frac{\\mathbb{P}(\\theta,x)}{\\mathbb{P}(x)}$$\n\nWe want to update the joint distribution $\\mathbb{P}(\\theta,x)$ after seeing the data $D = \\{x_1,...,x_n\\}$. We denote this\nnew distribution by $\\mathbb{P}(\\theta,x|D)$. Additionally, we denote the new marginal and conditional distributions as follows\n$$\\mathbb{P}(x|D) = \\int_{\\Theta} \\mathbb{P}(\\theta,x|D)d\\mu_\\Theta$$\n$$\\mathbb{P}(\\theta|D) = \\int_{X} \\mathbb{P}(\\theta,x|D)d\\mu_x$$\n$$\\mathbb{P}(x|s,D) = \\frac{\\mathbb{P}(\\theta,x|D)}{\\mathbb{P}(\\theta)}$$\n$$\\mathbb{P}(\\theta|x,D) = \\frac{\\mathbb{P}(\\theta,x|D)}{\\mathbb{P}(x)}$$\n\nThe question now becomes how to update this distribution after seeing the data. The key constraint\nis that we choose to update $\\mathbb{P}(\\theta,x)$ in a way which keeps the conditional distributions \n$\\mathbb{P}(x|\\theta)$ fixed for each $\\theta\\in \\Theta$. This means that we only need to specify how the marginal distribution\n$\\mathbb{P}(\\theta)$ should be updated, as $\\mathbb{P}(\\theta,x) = \\mathbb{P}(x|\\theta)\\mathbb{P}(\\theta)$.\n\nGiven a sample $x_i$, we choose to set the marginal distribution $\\mathbb{P}(\\theta)$ equal to the conditional distribution\n$\\mathbb{P}(\\theta|x_i)$. A formula for this new distribution is provided by Bayes' Law, which\nfollows easily from the definitions above:\n\\begin{equation}\\label{bayes_law}\n  \\mathbb{P}(\\theta|x_i) = \\frac{\\mathbb{P}(x_i|\\theta)\\mathbb{P}(\\theta)}{\\mathbb{P}(x_i)}\n\\end{equation}\nOften, the normalizing constant $\\mathbb{P}(x_i)$ (which is independent of $\\theta$) is suppressed and this is written\n\\begin{equation}\n  \\mathbb{P}(\\theta|x_i) \\sim \\mathbb{P}(x_i|\\theta)\\mathbb{P}(\\theta)\n\\end{equation}\nwhere $\\sim$ means `is proportional to.'\n\nGiven $n$ independent samples $x_1,...,x_n$, this formula is iterated to obtain\n\\begin{equation}\n  \\mathbb{P}(\\theta|D) \\sim \\mathbb{P}(x_1|\\theta)\\mathbb{P}(x_2|\\theta)\\cdots\\mathbb{P}(x_n|\\theta)\\mathbb{P}(\\theta)\n\\end{equation}\nand the predicted (or approximated) distribution over $X$ given the data is obtained by marginalizing out the \nparameter $\\theta$ (remember that we choose to keep the conditional distributions $\\mathbb{P}(x|\\theta)$ fixed independently\nof the data $D$)\n\\begin{equation}\n  \\mathbb{P}(x|D) = \\int_{\\Theta} \\mathbb{P}(\\theta,x|D)d\\mu_\\Theta = \\int_{\\Theta} \\mathbb{P}(x|\\theta)\\mathbb{P}(\\theta|D)d\\mu_\\Theta\n\\end{equation}\n\nThis ideal approach is almost always intractable. Consequently, much research in the statistics literature is concerned with\ncomputationally efficient approximations to this approach. Two of the most common approaches are either to approximate\nthe posterior by a distirbution from a specified class (this is called the variational Bayes' approach) or to design an\nalgorithm which generates (often approximately) a sample from the posterior distribution.\n\n\\subsection{Sample Mean Estimation Example}\n\\subsection{Application to Image Classification}\nFor the problem of image classification, we want to estimate more than just a single distribution. We are trying to\nestimate a distribution over the labels for every possible image $I$.\n\nThe Bayesian setup is now similar, it consists of a parameters space $\\Theta$, together with an initial probability\ndistribution over $\\Theta\\times X$ for every image $I$ (here $X$ is the set of possible labels). We make the same assumptions\nas before, im particular for each image $I$ we obtain a density over $\\Theta\\times X$, wehich we write $\\mathbb{P}(s,x|I)$.\n\nWe introduce the same notation as before, this time everything depends upond the image $I$. The marginal distributions\nare denoted\n$$\\mathbb{P}(x|I) = \\int_{\\Theta} \\mathbb{P}(\\theta,x|I)d\\mu_\\Theta$$\n$$\\mathbb{P}(\\theta|I) = \\int_{X} \\mathbb{P}(\\theta,x|I)d\\mu_x$$\nand the conditional distributions as\n$$\\mathbb{P}(x|\\theta,I) = \\frac{\\mathbb{P}(\\theta,x|I)}{\\mathbb{P}(\\theta|I)}$$\n$$\\mathbb{P}(\\theta|x,I) = \\frac{\\mathbb{P}(\\theta,x|I)}{\\mathbb{P}(x|I)}$$\n\nWe make one additional important assumption. We assume that in our model the marginal distribution \n$\\mathbb{P}(\\theta|I)$ is independent of $I$\nand we remove the $I$ in our notation and write $\\mathbb{P}(\\theta)$. Essentially, we are assuming that our\nparameter distribution is fixed independently of the image $I$. Note that this assumption does hold for our\nNeural Network models.\n\nAs before, the question becomes how to update the distributions $\\mathbb{P}(s,x|I)$ when data $D = \\{(x_1,I_1),...,(x_N,D_N)\\}$\nare available. We choose to update this distribution so that $\\mathbb{P}(x|\\theta,I)$ remains fixed for all\n$\\theta$ and $I$, and also so that $\\mathbb{P}(\\theta)$ remains independent of $I$.\n\nSimilar to the previous setup, when we see the data point $(x_1,I_1)$ we update the distribution $\\mathbb{P}(\\theta)$\nby setting it equal to $\\mathbb{P}(\\theta|x_1,I_1)$ and Bayes' formula gives\n\\begin{equation}\n \\mathbb{P}(\\theta|x_1,I_1) = \\frac{\\mathbb{P}(\\theta,x_1|I_1)\\mathbb{P}(\\theta)}{\\mathbb{P}(x|I)}\n\\end{equation}\n\nOne often omits the normalizing factor $\\mathbb{P}(x|I)$ and simply writes \n\\begin{equation}\n \\mathbb{P}(\\theta|x_1,I_1) \\sim \\mathbb{P}(\\theta,x_1|I_1)\\mathbb{P}(\\theta)\n\\end{equation}\nIterating this, we see that the new distribution (called the Bayes' posterior distribution) after seeing the data\nis given by\n\\begin{equation}\n \\mathbb{P}(\\theta|D) \\sim \\mathbb{P}(\\theta,x_1|I_1)\\mathbb{P}(\\theta,x_2|I_2)\\cdots\\mathbb{P}(\\theta,x_N|I_N)\\mathbb{P}(\\theta)\n\\end{equation}\nTo make a prediction given an image $I$ we marginalize out the parameters to obtain (recalling again that $\\mathbb{P}(x|\\theta,I)$\nremains fixed)\n\\begin{equation}\n \\mathbb{P}(x|I,D) = \\int_{\\Theta} \\mathbb{P}(x|\\theta,I)\\mathbb{P}(\\theta|D)d\\mu_{\\Theta}\n\\end{equation}\n\n\\section{Smoluchowski Dynamics}\nThe Smoluchowski dynamics, or `noisy gradient flow' is given by the SDE\n\\begin{equation}\\label{Smoluchowski}\n dX_t = -\\nabla V(x_t)dt + \\sqrt{2\\beta^{-1}} dW_t\n\\end{equation}\nwhere $V$ is some potential (in our application the Neural Network loss function).\n\nThe Fokker-Planck equation corresponding to this dynamics is\n\\begin{equation}\\label{Smoluchowski_FP}\n \\frac{d}{dt}\\rho = \\nabla \\cdot ((\\nabla V)\\rho + \\beta^{-1}\\nabla \\rho)\n\\end{equation}\nThis means that if $X_0$ is distributed according to $\\rho_0$, then $X_t$ will be distributed\naccording to $\\rho_t$ which solves the above equation. We have the following convergence result.\n\\begin{theorem}\n\n Assume that $V$ is a confining potential, which means that $$e^{-\\beta V(x)}\\in L^1$$\n for all $\\beta > 0$. \n \n Then\n the solution to the Fokker-Planck equation (\\ref{Smoluchowski_FP}) converges exponentially to the\n equilibrium distribution\n \\begin{equation}\\label{equilibrium_dist}\n \\rho_{eq}(x) \\sim e^{-\\beta V(x)}\n \\end{equation}\n which satisfies\n \\begin{equation}\\label{equilibrium_eq}\n (\\nabla V)\\rho_{eq} + \\beta^{-1}\\nabla \\rho_{eq} = 0\n \\end{equation}\n \n The convergence is in the following sense. If $\\rho_0 = f_0\\rho_{eq}$ with $f_0\\in L^2(\\rho_{eq}dx)$,\n then $\\rho_t = f_t\\rho_{eq}$ for $f_t\\in L^2(\\rho_{eq}dx)$ and \n \\begin{equation}\\label{decay_rate}\n  \\|f_t - 1\\|_{L^2(\\rho_{eq}dx)} \\leq e^{-\\alpha t}\\|f_0 - 1\\|_{L^2(\\rho_{eq}dx)}\n \\end{equation}\n for some convergence rate $\\alpha > 0$.\n\\end{theorem}\n\nWe won't formally prove this, but let us explain where this theorem comes from and how to determine the decay rate\n$\\alpha$.\n\nFirst, a simple calculation shows that $\\rho_{eq}$ satisfies equation (\\ref{equilibrium_eq}). Namely, the chain rule gives\n$$\\nabla \\rho_{eq} = -\\beta (\\nabla V)\\rho_{eq}$$\nregardless of the normalizing factor. This implies that $\\rho_{eq}$ is stationary, i.e. that by equation (\\ref{Smoluchowski_FP}),\n$$\\left.\\frac{d}{dt}\\rho\\right|_{\\rho_{eq}} = 0$$\n\nTo understand the decay rate, let $\\rho_0 = f_0\\rho_{eq}$ (here the subscript denotes the time $t$) with $f_0\\in L^2(\\rho_{eq}dx)$.\nThis space is the Hilbert space generated by the inner product\n\\begin{equation}\n \\langle f,g\\rangle_{L^2(\\rho_{eq}dx)} = \\int f(x)g(x)\\rho_{eq}(x)dx\n\\end{equation}\n\nWe now use the equation (\\ref{Smoluchowski_FP}) to derive an equation for $f_t$. We obtain (using equation (\\ref{equilibrium_eq}))\n\\begin{equation}\n \\frac{d}{dt} f = \\nabla V\\cdot\\nabla f + \\beta^{-1}\\Delta f = Lf\n\\end{equation}\nwhere we have set $L = \\nabla V\\cdot\\nabla  + \\beta^{-1}\\Delta$.\n\nA similar calculation shows that $L$ is self-adjoint with respect to the inner product \n$\\langle \\cdot, \\cdot\\rangle_{L^2(\\rho_{eq}dx)}$. The decay rate to equilibrium can now be determined from \nthe spectrum of $L$. These calculations can be explicitly carried out for a quadratic objective, which we will\ndo later in this section.\n\n\\subsection{Relation to Stochastic Gradient Descent}\nStochastic gradient descent is given by the following iteration\n\\begin{equation}\\label{sgd}\n x_{n+1} = x_n - s_n(\\nabla V(x_n) + \\nu_n)\n\\end{equation}\nwhere $V$ is the objective we are trying to minimize, $s_n$ is the step size, and $\\nu_n$ is a random variable\nrepresenting the noise in our gradient sample. If the random variable $\\nu_n$ satisfies\n\\begin{equation}\n \\mathbb{E}(\\nu_n) = 0,~\\mathbb{E}(\\nu_n^2) = \\frac{2\\beta^{-1}}{\\sqrt{s_n}}\n\\end{equation}\nthen the iteration (\\ref{sgd}) converges to the dynamics (\\ref{Smoluchowski}) by Donsker's theorem.\n\nIf we set $V$ to be the average log-likelihood loss function\n\\begin{equation}\n V(\\theta) = -\\frac{1}{N}\\displaystyle\\sum_{j = 1}^N \\log(\\mathbb{P}(x_j|\\theta,I_j))\n\\end{equation}\nand set the inverse temperature $\\beta = N$, then the equilibrium distribution corresponding to the\ndynamics (\\ref{Smoluchowski}) is exactly the Bayes Posterior distribution (with improper prior)\n$$\\mathbb{P}(\\theta|D) \\sim \\mathbb\\prod_{j = 1}^N \\log(\\mathbb{P}(x_j|\\theta,I_j))$$\n\nSo we see that the relationship between the step size and the noise in our gradient sample which produces\nan approximate Bayes posterior sample is\n\\begin{equation}\n \\mathbb{E}(\\nu_n^2)\\sqrt{s_n} = \\frac{2}{N}\n\\end{equation}\nwhere $N$ is the number of samples. This helps explain many phenomena, for instance why taking the step size too small produces\nworse results and why increasing the minibatch size (which decreases the sample variance) allows for a greater step size.\n\n\\section{Langevin Dynamics}", "meta": {"hexsha": "d04b31841007262b03f1c72611dbfd09123c8eb7", "size": 11468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Bayesian.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/Bayesian.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/Bayesian.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.0547263682, "max_line_length": 135, "alphanum_fraction": 0.7241018486, "num_tokens": 3605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602593, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.802490538799381}}
{"text": "\\section{Paths whose image curve is a circle}\n\n\\subsection{Unit Circle}\n\nUnit circle is set of points in $\\R^2$ defined as $C=\\{(x,y)\\in\\mathbb{R} ^2|x^2+y^2=1\\}$. Ellipse is\n$C=\\{(x,y)\\in\\mathbb{R} ^2|\\frac{x^2}{a^2}+\\frac{y^2}{b^2}=1\\}$\nHas standard parameterization of $\\textbf{c}(t)=\\big(\\cos(t),\\sin(t)\\big)$.\nWhen parameterizing, always start from $t=0$ reference unless otherwise given.\\newline \n\n\\begin{center}\n    \\includegraphics[scale=0.3]{figures/unit-circle.png}\n\\end{center}\n\n\\noindent Properties\n\\begin{itemize}\n    \\item Image of $\\textbf{c}$ is a closed curve (has no endpoints, plane is divided into $\\geq 2$ disjoint regions)\n    \\item Image of $\\textbf{c}$ is a simple curve; no self-intersection \n    \\item $\\textbf{c}(t)$ is an \\textbf{injective path}; path is considered injective if $\\textbf{c}(t_1)=\\textbf{c}(t_2)$, which implies that $t_1=t_2$ where \n    these are on the open interval $(a,b)$ even if $a=b$\n    \\item Orientation of $\\textbf{c}$ is counter-clockwise in traversal\n\\end{itemize}\n\n\\subsection{Observations}\n\n\\[\\boxed{\\textbf{p}(t)=(a\\cos (\\pm (nt \\pm\\theta)) + x_0, b\\sin (\\pm (nt \\pm \\theta)) + y_0)}\\]\n\nIf $-t$ for $t$, orientation is CW, CCW is $t$. If $a=b$, then curve is \na circle of radius $a$ or $b$, else an ellipse with horizontal and vertical radii.\n$x_0$ and $y_0$ simply shift the center coordinate. $n>0\\in \\R$ determines how many times\nthe circle is traversed given $t\\in[0,2\\pi]$, for example. $\\theta$ is the phase shift.\nWhen changing direction of traversal, cannot have $a>b$ for $[a,b]$ so to decrease argument of $\\sin$ or $\\cos$\nmust have $-t$ for $t$. Starting out, $-t$ goes through the angle range and $t$ is just a sign flip.\n\n\\section{Paths whose image is a line or line segment in the plane}\n\n\\subsection{Line Parametrics}\n\nA line is a 1D subspace of $\\R^2$, so $L=\\{t\\textbf{m}|t\\in\\R\\}$ for $\\textbf{m}\\in\\R^2$.\n$\\textbf{m}=\\begin{bmatrix}m_x\\\\m_y\\end{bmatrix}$ is the \\textbf{slope vector}.\nPath given by image of $L$: \n\n\\[\\textbf{c}(t)=\\left(m_{x} t, m_{y} t\\right),t\\in\\R\\]\n\nCan represent $\\textbf{c}(t)=t\\textbf{m}$ as well.\\newline\n\n\\noindent\nLines Main Ideas\n\\begin{itemize}\n    \\item Image of a line is a curve (e.g. $y=x$ represents image curve of $\\textbf{c}(t)=(t,t)$)\n    \\item Lines can have nonzero intercepts, so $\\textbf{c}(t)=t\\textbf{m}$ represents $y=2x+1$. Line\n    that has intercept vector $P_0=(x_0,y_0)$ $\\parallel$ $\\textbf{m}=(m_x,m_y)$ can be expressed as:\n\n    \\[\\boxed{\\textbf{c} (t)=(x_0+tm_x, y_0+m_yt)= \\textbf{$P_0$}+t \\textbf{m} }\\]\n\n    Note endpoint of $\\textbf{c}(t)$ is on image line (curve).\n\n\\end{itemize}\n\n\\subsection{General Forms}\n\n2 parametric lines \\textbf{collide} if they intersect and the point of intersection corresponds\nto the same $t$ in both curves. If you set the parameter vector coordinates equal to each\nother and solve for $t$, a solution indicates they collide. Intersection is found by \\textbf{eliminating}\nthe parameter (solve for $t$ in terms of either $x$ or $y$ and plug into the other).\\newline\n\n\\noindent\nGeneral form of parameterized curve can be expressed as the following:\n\n\\[\\boxed{\\textbf{c}(t)=(\\frac{m_x}{\\Delta t}(t-a)+x_0,\\frac{m_y}{\\Delta t}(t-a)+y_0)}\\]\n\nwhere $\\Delta t$ is the domain interval over $[a,b]$ and $(x_0,y_0)$ represents the desired \\textbf{starting coordinate}.\nThis is important as when going in reverse, other coordinate can be used and slope might be negative.\n$a$ is used in $(t-a)$ because everything is conventionally done with respect to starting coordinate.\n\n\\section{Paths whose image curve is a line in R3}\n\n\\subsection{R3 parameterization}\n\nIf $\\textbf{m}$ is a nonzero vector along $L$ through origin in $\\R^3$, then $L=\\{t\\textbf{m}|t\\in\\R\\}$;\nfollows that $\\textbf{m}=(m_x,m_y,m_z)$, the slope or direction vector of the line. The basic parameterization is:\n\n\\[\\textbf{c}(t)=(m_x t,m_y t,m_z t)\\]\n\nBasis vectors in $\\R^3$ are $\\textbf{i}, \\textbf{j}, \\textbf{k}$. Rewriting parameterization: \n\n\\[\\textbf{c}(t)=(x_0+m_x t) \\textbf{i}+(y_0+m_y t) \\textbf{j}+(z_0+m_z t) \\textbf{k}\\]\n\n2 lines $\\textbf{c}_1(t)=P_0+\\textbf{m}_1t$ and $\\textbf{c}_2(t)=Q_0+\\textbf{m}_2t$ are parallel if\ndirection vectors are parallel ($\\textbf{$m_1$}=k\\textbf{m}_2$). Collisions still exist. If neither parallel nor intersecting, considered as skew.\\newline\n\n\\noindent\nTo determine skew, parallel, or coincide, use parameters $s,t$ for each line and solve SOE.\nIf same slope, rule out skew clearly, then check if $s,t\\in\\R$: if not, then parallel, if so, then they coincide. If intersecting and want to check if collide, some $t$\nmust satisfy all relations.\n\n\\section{Cycloid Problem}\n\n\\begin{center}\n    \\includegraphics*[scale=0.9]{figures/cycloid.png}\n\\end{center}\n\nWith radius 1 and passing through the origin:\n\n\\[\\textbf{c}(t)=(t-\\sin t, 1 - \\cos t)\\]\n\nObserve that:\n\n\\[\\textbf{c}^\\prime(t)=(1-\\cos t, \\sin t)\\]\n\nCan define the vector $\\textbf{u}=\\left(\\begin{array}{c}x^{\\prime}(t) \\\\0\\end{array}\\right)$\nsuch that $\\textbf{u}$ is always horizontal and $||\\textbf{u}||=|x^\\prime(t)|$. Reaches maximum\nvalue at $t\\in[k\\pi|k\\in\\R]$ and is has minimum cusp where it is 0 at $t\\in [2k\\pi|k\\in\\R]$.\nThus, $x^\\prime(t)\\geq 0$ always, as the x-coordinate is never decreasing. \\newline\n\n\\noindent\nCan also define the vector $\\textbf{v}=\\left(\\begin{array}{c}0 \\\\y^{\\prime}(t)\\end{array}\\right)$\nwith the same properties. Reaches maximum value when $t\\in[k\\frac{\\pi}{2}|k\\in\\R]$.\nCan change, as observe $t$ when $\\sin t < 0$ or $ >0 $.\n\n\\subsection{Hypercycloid Derivation}\n\n\\begin{center}\n    \\includegraphics*[scale=0.5]{figures/Screen Shot 2021-02-06 at 9.40.41 AM.png}\n\\end{center}\n\n\\subsection{Hypocycloid Derivation}\n\n\\begin{center}\n    \\includegraphics*[scale=0.6]{figures/Screen Shot 2021-02-06 at 9.58.04 AM.png}\n\\end{center}\n\n\\section{Velocity Vector}\n\n\\subsection{Definitions}\n\nVector $\\textbf{u}(t_0)+\\textbf{v}(t_0)$ is he velocity vector to the curve $\\textbf{c}(t)$ at $t=t_0$.\\newline\n\n\\noindent\nLet $\\textbf{c}:\\;[a,b]\\rightarrow \\R^n$ have a path $\\textbf{c}(t)=\\left(x_{1}(t), x_{2}(t), x_{3}(t), \\ldots, x_{n}(t)\\right)$ (let $x_i(t):[a,b]\\rightarrow \\R$ for each $i$)\n\\begin{itemize}\n    \\item If $t_0\\in[a,b]$, then $\\textbf{c}^{\\prime}\\left(t_{0}\\right):=\\left(x_{1}^{\\prime}\\left(t_{0}\\right), x_{2}^{\\prime}\\left(t_{0}\\right), x_{3}^{\\prime}\\left(t_{0}\\right), \\ldots, x_{n}^{\\prime}\\left(t_{0}\\right)\\right)$; the velocity vector to $\\textbf{c}$ at $t_0$\n    \\item The path $\\textbf{c}^{\\prime}\\left(t_{0}\\right):=\\left(x_{1}^{\\prime}\\left(t_{0}\\right), x_{2}^{\\prime}\\left(t_{0}\\right), x_{3}^{\\prime}\\left(t_{0}\\right), \\ldots, x_{n}^{\\prime}\\left(t_{0}\\right)\\right)$; the velocity vector to $\\textbf{c}$ is referred to as velocity of $\\textbf{c}(t)$\n\\end{itemize}\n\nRecall chain rule: if $y=f(x)$ where $x$ is a function of $t$, $y\\,'(t)=x\\,'f\\,'(x)$, not to be confused with product rule.\nCan write $f\\,'(x)=\\frac{y\\,'(t)}{x\\,'(t)}$\n\n\\begin{itemize}\n    \\item If $\\textbf{p}(t)=\\textbf{c}(t)+\\textbf{r}(t),$ then $\\textbf{p}^{\\prime}(t)=\\textbf{c}^{\\prime}(t)+\\textbf{r}^{\\prime}(t)$\n    \\item If $g(t)=\\textbf{c}(t) \\cdot \\textbf{r}(t),$ then $g^{\\prime}(t)=\\textbf{c}^{\\prime}(t) \\cdot \\textbf{r}(t)+\\textbf{c}(t) \\cdot \\textbf{r}^{\\prime}(t)$\n    \\item If $\\textbf{p}(t)=f(t) \\textbf{c}(t),$ then $\\textbf{p}^{\\prime}(t)=f^{\\prime}(t) \\textbf{c}(t)+f(t) \\textbf{c}^{\\prime}(t)$\n    \\item If $\\textbf{p}(t)=\\textbf{c}(t) \\times \\textbf{r}(t),$ then $\\textbf{p}^{\\prime}(t)=\\textbf{c}^{\\prime}(t) \\times \\textbf{r}(t)+\\textbf{c}(t) \\times \\textbf{r}^{\\prime}(t)$\n    \\item If $\\textbf{p}(t)=\\textbf{c}(f(t)),$ then $\\textbf{p}^{\\prime}(t)=f^{\\prime}(t) \\textbf{c}^{\\prime}(f(t))$\n    \\item If $g(t)=\\|\\textbf{c}(t)\\|,$ then $g^{\\prime}(t)=\\frac{\\textbf{c}(t) \\cdot \\textbf{c}^{\\prime}(t)}{\\|\\textbf{c}(t)\\|}$\n\\end{itemize}\n\n\\subsection{Tangent Line}\n\nTangent line can be visualized as a base vector in standard position plus a velocity vector\ntangent to the tip which traces a shifted line in some interval. General formula with base vector $\\textbf{c}(t_0)$ and slope $\\textbf{c}\\,'(t_0)$:\n\n\\[\\boxed{\\ell(t)=\\textbf{c}(t_0)+(t-t_0)\\textbf{c}\\,'(t_0)}\\]\n\n\\section{Space Curves}\n\n\\begin{itemize}\n    \\item Projection into the $x y$ plane is the path $(x(t), y(t), 0)$.\n    \\item Projection into the $x z-$ plane is the path $(x(t), 0, z(t))$.\n    \\item Projection into the $y z$ plane is the path $(0, y(t), z(t))$.\n\\end{itemize}\n\n\\section{Speed and Arclength}\n\n\\subsection{Speed}\n\nSpeed of a parametric function in $\\R^n$ is given by:\n\n$$||\\textbf{c}\\,'(t)||=\\sqrt{\\displaystyle\\sum_{i=1}^{n}c_i(t)^2}$$\n\n(being the magnitude of the velocity vector)\n\n\\subsection{Arclength}\n\nArclength of a parametric function is given by:\n\n\\[S=\\int_a^b ||\\textbf{c}\\,'(t)||dt=\\int_a^b\\sqrt{(\\frac{dx}{dt})^2+(\\frac{dy}{dt})^2+(\\frac{dz}{dt})^2+\\cdots}\\;dt\\]\n\nCan approximate arclength as a sum of the lengths of secant vector approximations\n$\\textbf{s}_i=\\textbf{c}(t_i)-\\textbf{c}(t_{i-1})$:\n\n\\[\\mbox{arclength}\\approx\\sum_{i=1}^n||\\textbf{s}_i||\\]\n\nAccording to the MVT, there exists a $\\hat{t}_i$ in $(t_{i-1},t_i)$ (open interval due to differentiability requirement) such that:\n\n\\begin{align*}\n    x\\,'(\\hat{t}_i)&=\\frac{x(t_i)-x(t_{i-1})}{t_i-t_{i-1}}\\\\\n    y\\,'(\\hat{t}_i)&=\\frac{y(t_i)-y(t_{i-1})}{t_i-t_{i-1}}\n\\end{align*}\n\nThis means that, since $\\textbf{s}_i$ is given as the difference between 2 points,\nbeing a secant:\n\n\\begin{align*}\n    \\textbf{s}_i&=\\left((t_i-t_{i-1})x(\\hat{t}_i), (t_i-t_{i-1})y(\\hat{t}_i)\\right )\\\\\n    \\textbf{s}_i&=(t_i-t_{i-1})\\left(x\\,'(\\hat{t}_i),y\\,'(\\hat{t}_i)\\right)\\\\\n    \\textbf{s}_i&=(t_i-t_{i-1})\\textbf{c}\\,\\,'(\\hat{t}_i)\n\\end{align*}\n\nThus,\n\n\\begin{align*}\n    \\mbox{arclength}&\\approx\\sum_{i=1}^n||\\textbf{s}_i||\\\\\n    \\mbox{arclength}&\\approx\\sum_{i=1}^n||\\Delta t \\,\\textbf{c}\\,\\,'(\\hat{t}_i)||\\\\\n    \\mbox{arclength}&\\approx\\sum_{i=1}^n\\Delta t||\\textbf{c}\\,\\,'(\\hat{t}_i)||\n\\end{align*}\n\nCan define the arclength differential as follows:\n\n\\[\\mathrm{d}s=\\sqrt{\\mathrm{d}x^2+\\mathrm{d}y^2}\\]\n\nCan just define arclength as $\\text{arclength}=\\int \\mathrm{ds}$\n\n\\subsection{Arclength Parameterization}\n\nHigher the speed of a curve, farther the points are spaced apart.\nAn arclength parametrization of a curve is a path whose image is the desired curve and whose speed is constantly one.\nOr, $\\textbf{c}:[a,b]\\to\\mathbb{R}^n$ with $||\\textbf{c}\\,\\,'(t)||=1$ for $t\\in[a,b]$.\nIf a curve is not an arclength parameterization, then can do $\\frac{\\textbf{c}(t)}{||\\textbf{c}\\,'(t)||}$ but only dividing the coefficients (slopes).\\newline\n\n\\noindent\nWhen speed is variable, is difficult to define arclength parameterization.\nThus, can define displacement to be $s(t)=\\int_a^b \\tb{c}(t)dt$. If $v(t)!\\neq 0$,\nthen $s$ is injective because according to FTC, $s\\,'(t)=v(t)$.\nBy definition, $v\\,'(t)\\geq 0$ always since it is composed of a radical, so it must be \\textbf{increasing}.\nThus, if $t_1=t_2$, $s(t_1)\\neq s(t_2)$. Arclength parameterization:\n\n\\[s(t)=\\int_0^t||\\textbf{c}\\,'(u)||du\\]\n\n\\noindent\nThis means that $s$ is invertible, so can solve for $t$ to get $t=\\varphi(s)$.\nAn arclength parameterization can be found by:\n\n\\[\\boxed{\\textbf{p}(s)=\\textbf{c}(\\varphi(s))}\\]\n\n\\section{Curvature}\n\n\\subsection{Proofs}\n\nRecall that to make an arclength parameterization accumulate the magnitudes of infinitesimal velocity vectors:\n\n\\[s(t)=\\int_a^t ||\\textbf{r}\\,'(u)||du\\]\n\nGiven some curve $\\textbf{r}(t)$, define an arclength parameterization by $\\textbf{r}(g(s))\\rightarrow \\textbf{r}_1(s)$, so \n$\\textbf{r}$ is defined in terms of $s$. The unit tangent vector $\\textbf{T}_1(s)$ is then $\\frac{\\textbf{r}_1\\,'(s)}{||\\textbf{r}_1\\,'(s)||}=\\textbf{r}_1\\,'(s)$.\n\n\\begin{align*}\n    \\textbf{T}_1(s)&=\\textbf{r}_1\\,'(s)\\\\\n    &=\\frac{d}{ds}\\textbf{r}_1(s)\\\\\n    &=\\frac{d}{ds}\\textbf{r}(g(s))\\\\\n    &=\\textbf{r}\\,'(g(s))\\cdot g\\,'(s)=\\textbf{r}\\,'(t)\\cdot \\frac{dt}{ds}\\\\\n    &=\\frac{\\textbf{r}\\,'(t)}{\\frac{ds}{dt}}=\\frac{\\textbf{r}\\,'(t)}{||\\textbf{r}\\,'(t)||}\n\\end{align*}\n\nThis means that $\\textbf{T}_1(s)=\\tb T(t)$\n\nContinuing, to find curvature $\\kappa(t)$:\n\n\\begin{align*}\n    \\textbf{T}_1\\,'(s)&=\\frac{d}{ds}\\textbf{T}(t)\\\\\n    &=\\frac{d}{ds}\\textbf{T}(g(s))\\\\\n    &=\\textbf{T}\\,'(t)\\cdot \\frac{dt}{ds}\\\\\n    &=\\frac{\\textbf{T}\\,'(t)}{\\frac{ds}{dt}}\\\\\n    &=\\frac{\\textbf{T}\\,'(t)}{||\\textbf{r}\\,'(t)||}\\\\\n\\end{align*}\n\nThus, $\\boxed{\\kappa(t)=\\frac{||\\textbf{T}\\,'(t)||}{||\\textbf{r}\\,'(t)||}}$\n\n\\subsection{Definition}\n\nGiven a curve $C$ parameterized with arclength by the path $\\textbf{c}:[a,b]\\rightarrow \\R^n$,\ncurvature is defined as:\n\n\\[\\boxed{\\kappa(s)=||\\textbf{T}\\,'(s)||}\\]\n\nwhere $\\textbf{c}\\,'(s)\\neq 0$ and $\\textbf{T}(s)=\\frac{\\textbf{c}\\,'(s)}{||\\textbf{c}\\,'(s)||}$ (normalized slope vector).\\newline\n\nA loose geometric interpretation is that a greater $\\kappa(s)$ implies\nmore curvature, that is, the curve is changing at a greater rate there.\nWhen $\\textbf{c}\\,'(s)\\neq 0$ is always true for a curve, it is \\textbf{regular}.\nIs defined in terms of arclength parameterization so curvature\nis an intrinsic property of the curve independent of parameterization.\\newline\n\n\\noindent\nFormula for curvature at the point $\\textbf{c}(t)$:\n\n\\[\\boxed{\\kappa(t)=\\frac{||T\\,'(t)||}{||\\textbf{c}\\,\\,'(t)||}=\\frac{||\\textbf{c}\\,\\,'(t)\\times \\textbf{c}\\,\\,'\\,'(t)||}{||\\textbf{c}\\,\\,'(t)||^3}}\\]\n\n\\section{Motion in 3D space}\n\nGiven a path $\\textbf{c}: \\mathbb{R} \\rightarrow \\mathbb{R}^{3}$ with $\\textbf{c}(t)=(x(t), y(t), z(t)),$ then we have defined:\n\\begin{itemize}\n    \\item $\\cdot \\textbf{v}(t)=\\textbf{c}^{\\prime}(t)=\\left(x^{\\prime}(t), y^{\\prime}(t), z^{\\prime}(t)\\right)$ is also path in $\\mathbb{R}^{3}$ called the velocity of $\\textbf{c}$\n    \\item $\\textbf{a}(t)=\\textbf{v}^{\\prime}(t)=\\textbf{c}^{\\prime \\prime}(t)=\\left(x^{\\prime \\prime}(t), y^{\\prime \\prime}(t), z^{\\prime \\prime}(t)\\right)$ is also a path in $\\mathbb{R}^{3}$ called the acceleration of $\\textbf{c}$\n    \\item $v(t)=\\|\\textbf{v}(t)\\|=\\left\\|\\textbf{c}^{\\prime}(t)\\right\\|$ is a scalar valued function on $\\mathbb{R}$ (that\\,'s a fancy way of saying the domain and codomain of this function are both $\\mathbb{R}$ ) called the speed of $\\textbf{c}$\n    \\item $\\textbf{T}(t)=\\frac{\\textbf{c}^{\\prime}(t)}{v(t)}$ is also a path in $\\mathbb{R}^{3}$ called the unit tangent to $\\textbf{c}$\n    \\item $\\kappa(t)=\\frac{\\textbf{T}^{\\prime}(t)}{v(t)}=\\frac{\\left\\|\\textbf{c}^{\\prime}(t) \\times \\textbf{c}^{\\prime \\prime}(t)\\right\\|}{\\left\\|\\textbf{c}^{\\prime}(t)\\right\\|^{3}}$ is a scalar valued function on $\\mathbb{R}$ called the curvature of $\\textbf{c}$\n\\end{itemize}\n\nNote that $\\textbf{T}\\cdot \\textbf{T}=||\\textbf{v}||^2=1$.\nComputing the derivative, $\\frac{\\mathrm{d}}{\\mathrm{d} t} \\textbf{T} \\cdot \\textbf{T}=2 \\textbf{T} \\cdot \\textbf{T}^{\\prime}=0$\nThis means that $\\textbf{T}\\perp \\textbf{T}\\,'$.\\newline\n\n\\noindent\nDefine $\\boxed{\\textbf{N}(t)=\\frac{\\textbf{T}^{\\prime}(t)}{\\left\\|\\textbf{T}^{\\prime}(t)\\right\\|}}$ as\nthe unit normal vector, which is the unit tangent to the unit tangent. From observation, $\\textbf{T}\\perp \\textbf{N}$.\nFact: the acceleration vector always lies in the plane spanned by $\\textbf{N}$ and $\\textbf{T}$.\\newline\n\n\\noindent\nAcceleration $\\textbf{a}(t)$ is thus split component-wise into $a_T$ from $\\textbf{T}$\nand $a_N$ from $\\textbf{N}$:\n\n\\[\\boxed{a_T=v\\,'(t)=\\frac{\\tb a(t)\\cdot \\textbf{v}(t)}{v(t)}}\\]\n\\[\\boxed{a_N=\\kappa(t)v(t)^2=\\frac{||\\textbf{a}(t)\\times \\textbf{v}(t)||}{v(t)}=\\sqrt{\\|\\textbf{a}(t)\\|^{2}-\\left|a_{T}\\right|^{2}}}\\]\n\n\\section{Derivatives of parameterized curves}\n\n\\subsection{Arclength parameterization derivation}\n\nTake the following function:\n\n\\[\\textbf{r}(t)=\\langle x(t),y(t) \\rangle\\]\n\nAn arclength parameterization is achieved with the following computation:\n\n\\[s=\\int_0^t \\sqrt{x\\,'(u)^2+y\\,'(u)^2}\\;du\\]\n\nCan say that $t=g(s)$, so the arclength parameterization, which is the path in terms of $s$:\n\n\\[\\textbf{r}_1(s)=\\langle x(g(s)),y(g(s))\\rangle\\]\n\nTaking the derivative by the chain rule:\n\n\\begin{align*}\n    \\textbf{r}_1\\,'(s)&=\\langle x\\,'(g(s))\\cdot g\\,'(s),y\\,'(g(s))\\cdot g\\,'(s)\\rangle \\\\\n    &=g\\,'(s)\\langle x\\,'(t),y\\,'(t) \\rangle \\\\\n\\end{align*}\n\nNote that $g\\,'(s)=\\frac{dt}{ds}=\\frac{1}{\\frac{ds}{dt}}=\\frac{1}{||\\textbf{r}\\,'(t)||}$ by taking the derivative of the integral for arclength:\n\n\\[\\textbf{r}_1\\,'(s)=\\frac{1}{||\\textbf{r}\\,'(t)||}\\langle x\\,'(t),y\\,'(t) \\rangle=\\textbf{T}(t)\\]\n\nFollowing from this, $g\\,'(s)=\\frac{1}{||\\textbf{r}\\,'(g(s))||}$ so $g\\,'\\,'(s)=-\\frac{1}{||\\textbf{r}\\,'(g(s))||^2}\\cdot g\\,'(s)=-\\frac{1}{||\\textbf{r}\\,'(t)||^3}$\n\n\\subsection{Orthogonal derivative and position vectors}\n\nObserve that $\\textbf{r}\\cdot \\textbf{r}=||\\textbf{r}||^2$.\nThus, $\\frac{d}{dt}[\\textbf{r}\\cdot \\textbf{r}]=2\\textbf{r}\\cdot\\textbf{r}\\,'=2||\\textbf{r}||||\\textbf{r}||\\,'$.\nRearranging: $\\frac{\\textbf{r}\\cdot \\textbf{r}}{||\\textbf{r}||}=||\\textbf{r}||\\,'$.\nMeans that magnitude of position vector has to be a constant value in order for it\nto be $\\perp$ to derivative.\n\n\\section{Planetary motion}\n\n\\begin{itemize}\n    \\item Law of ellipses -- orbit of planet is ellipse with sun as focus\n    \\item Law of equal area in equal time -- position vector pointing from sun to planet sweeps out equal area in equal time (so speed must increase/decrease)\n\\end{itemize}\n\nCan approximate the area swept in time by $\\frac{dA}{dt}=\\frac{1}{2}||\\textbf{r}(t)\\times \\textbf{r}\\,'(t)||=\\frac{1}{2}||\\textbf{J}||$.\nThe differential equation for each of Kepler\\,'s laws is: $\\textbf{r}\\,'\\,'(t)=-\\frac{k}{||\\textbf{r}(t)||^3}\\textbf{r}(t)$, so it is in the direction of $\\textbf{r}(t)$.\nThus, differentiating $\\frac{d\\textbf{J}}{dt}=\\frac{d}{dt}(\\textbf{r}\\,'(t)\\times \\textbf{r}\\,'\\,'(t))=0$.\n\n\\subsection{Cross-product identities}\n\nCross product identities:\n\\begin{itemize}\n    \\item $\\boxed{\\textbf{u}\\times(\\textbf{v}\\times \\textbf{w})=(u\\cdot w)\\textbf{v}-(\\textbf{u}\\cdot \\textbf{v})\\textbf{w}}$\n    \\item $\\boxed{u\\cdot(\\textbf{v}\\times \\textbf{w})=v\\cdot(\\textbf{w}\\times \\textbf{u})=\\textbf{w}\\cdot(\\textbf{u}\\times \\textbf{v})}$\n\\end{itemize}\n", "meta": {"hexsha": "2f6cc630015d576ec0c9f53fad64c924a4a62d21", "size": 18036, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multivariable-calculus/tex/unit-1.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multivariable-calculus/tex/unit-1.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multivariable-calculus/tex/unit-1.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.4631578947, "max_line_length": 298, "alphanum_fraction": 0.6459303615, "num_tokens": 6762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.905989826094673, "lm_q1q2_score": 0.8023730994788151}}
{"text": "\\section{Functions}\n\n\\subsection{Definition and Terminology}\nIn this section, we will answer two questions. Namely, what is a function, and what do functions do?\n\nFrom prior experience in precalculus and calculus courses most people have an intuitive picture of what functions are. For most purposes, they are ``rules'' that sends values to other values. In other words:\n\n\\begin{tcolorbox}\nA function is a rule that assigns to certain elements in a set, certain elements to another set.\n\\end{tcolorbox}\n\nThe word rule is not very clear or rigorous. For example, we might consider the real valued functions $f(x) = x^3$ and $g(x) = x^3 + 3x - 3(x + 3) + 9$. These have the same value everywhere, but the rule for evaluating them is slightly different.\n\nIt turns out that when defining functions rigorously, the ``rule'' is a means to an end. All we care about when talking about any specific function is the output given the input. \n\n\\begin{definition}\nA function $f:A \\to B$ (read as ``$f$ from $A$ to $B$'') is defined as a set of ordered pairs $(a, b)$ where $a \\in A$ and $b \\in B$ (more specifically, a subset of the set of ordered pairs $A \\times B$). $f$ has the following properties:\n\\begin{enumerate}\n    \\item For all $a \\in A$, there exists some $b \\in B$ such that $(a, b) \\in f$.\n    \\item For all $a \\in A$, $b, c \\in B$, if $(a,b) \\in f$ and $(a, c) \\in f$, then $b = c$.\n\\end{enumerate}\n\\end{definition}\n\nIn other words, every value $a \\in A$ will have some value $b$ such that $(a, b)$ is in $f$. Moreover, this value is \\textbf{unique}. We define $f(a)$ as the unique value in $B$ such that $(a, f(a)) \\in f$.\n\nHere is some more terminology.\n\\begin{definition}\nLet $f: A \\to B$ be a function. We say $A$ is the \\textbf{domain} of the function $f$ and $B$ is the \\textbf{codomain} of $f$. We say that $a$ is mapped to $b$ or $f$ maps $a$ to $b$ if $(a, b) \\in f$. You can also write $a \\mapsto b$ as long as it is clear what $f$ is.\n\\end{definition}\n\nUsing these definitions, we can say the following: Given any function $f:A \\to B$, every value in the domain will be mapped to exactly one value in the codomain.\n\n\\subsection{Injectivity, Surjectivity, Bijectivity}\n\nHere are the relevant definitions:\n\\begin{itemize}\n    \\item A function $f:A \\to B$ is injective (or one to one) if $f(a) = f(b) \\implies a = b$. So two different values in $A$ do not map to the same value in $B$.\n    \\item A function $f:A \\to B$ is surjective (or onto) if for all $b \\in B$ we can find a value in $A$ such that $f(a) = b$.\n    \\item A function $f$ is bijective if it is both injective and surjective.\n\\end{itemize}\n\nHere is an interesting observation: if $f: A \\to B$ is a bijection, then there is an inverse function $g: B \\to A$. For each $b \\in B$, we can define $g(b)$ as the unique value $a \\in A$ such that $f(a) = b$. We know such a value exists because $f$ is surjective, and we know that this value is unique because $f$ is injective.\n\n%%NOTE: define inverse functions.\n\n\\section{Relations}\n\nLet $A$ be a set. Traditionally, we have lots of different notation for when we might want to \\textit{compare} two objects in $A$. For example, the $=$ notation ``compares'' for equality, and the $\\leq$ symbol compares two objects for magnitude. Relations generalize these comparison operators.\n\n\\begin{definition}\nLet $A$ be a set. A relation $R$ on $A$ is a subset of $A \\times A$. That is, $R$ is any subset of ordered pairs $(a, b)$ where $a \\in A$ and $b \\in A$.\n\\end{definition}\n\nThis definition can used as a comparison property as we demonstrate using the following terminology. We say that an element $a \\in A$ is related to an element $b \\in A$ if $(a, b) \\in R$. So in fact it is beneficial to just think of $R$ as the set of all possible relations.\n\n\\begin{definition}\nLet $A$ be a set and $R$ be a relation on $A \\times A$. A relation is\n\\begin{itemize}\n    \\item \\textit{reflexive} if $(a, a) \\in R$ for every $a \\in A$,\n    \\item \\textit{symmetric}, if for all $a, b \\in A$, $(a, b) \\in R \\implies (b, a) \\in R$.\n    \\item \\textit{transitive} if for all $a, b, c \\in A$, $(a, b) \\in R, (b, c) \\in R \\implies (a, c) \\in R$.\n\\end{itemize}\n\nUsually, given a relation $R$, we will write $aRb$ if $(a, b) \\in R$. This will save use space and ink.\n\n\\end{definition}\n\n", "meta": {"hexsha": "44010828d79c6dbce236cadee93117879e9e477a", "size": 4278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch3/fr.tex", "max_stars_repo_name": "jonlin1000/discr_math", "max_stars_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:31:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T02:26:40.000Z", "max_issues_repo_path": "Ch3/fr.tex", "max_issues_repo_name": "jonlin1000/discr_math", "max_issues_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch3/fr.tex", "max_forks_repo_name": "jonlin1000/discr_math", "max_forks_repo_head_hexsha": "f18413d1eb0ed598b325e5cd8052fcc571337926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.9117647059, "max_line_length": 327, "alphanum_fraction": 0.688172043, "num_tokens": 1306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.9059898108646849, "lm_q1q2_score": 0.8023730941951985}}
{"text": "\\paragraph{Lemma:} \n\nIf $G$ is a graph of diameter at least $3$, then $\\overline{G}$ has diameter\nat most $3$.\n\n\\paragraph{Proof of Lemma:} \n\nIf $G$ is a graph of diameter at least $3$, then there are\ntwo vertices $u$ and $v$ in $G$ with $d_G(u,v) \\ge 3$. $uv$ is not an edge in $G$\n(or else $d_G(u,v)$ would be $1$), so $uv$ is an edge in $\\overline{G}$. Now\nlet $w$ be a vertex distinct from $u$ and $v$. Then suppose neither $wu$ or\n$wv$ were edges in $\\overline{G}$. Then both must be edges in $G$, and\n$(u,w,v)$ is a $u-v$ path of length $2$, a contradiction since $d_G(u,v) \\ge 3$.\nSo every vertex is adjacent to $u$ or $v$ in $\\overline{G}$ (including $u$ and $v$) and \nthe two sets $U=\\text{nbd}_{\\overline{G}} u$ and $V=\\text{nbd}_{\\overline{G}} v$ cover\n$V(G)$.\n\nLet $w_1, w_2$ be in  $U$, then $(w_1,u,w_2)$ is a $w_1-w_2$ walk in $\\overline{G}$\nof length $2$, so $d_{\\overline{G}}(w_1,w_2)\\le 2$. Similarly if $x_1,x_2 \\in V$,\n$d_{\\overline{G}}(x_1,x_2)\\le 2$. If $y \\in U, z \\in V$, then $(y,u,v,z)$ is a $y-z$\nwalk in $\\overline{G}$ of length $3$, so $d(y,z) \\le 3$. Hence the distance between\nany two vertices in $\\overline{G}$ is at most $3$, and $diam\\ \\overline{G} \\le 3$. This\nconcludes the proof of the lemma.\n\n\\paragraph{Main Proof:}\nLet $G$ be a graph which is isomorphic to its complement.\nIf $diam\\ G >3$, then also \n$diam\\ G = diam\\ \\overline{G} \\le 3$\nby the lemma, a contradiction. Otherwise $diam\\ G \\le 3$. If $diam\\ G = 1$, then\nevery vertex is adjacent to every other vertex, so $G \\cong K_n$ if $G$ is of order\n$n$. But then $\\overline{G} \\cong \\overline{K}_n$, which is not isomorphic to $K_n$\nwhen it is nontrivial. So $diam\\ G$ is $2$ or $3$.\n", "meta": {"hexsha": "5ca59aaf43f1edd280ccf623d524d69b82ed422e", "size": 1678, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tut2/2.16.tex", "max_stars_repo_name": "h4tguy/gt-hons", "max_stars_repo_head_hexsha": "a9b4a271a9bdc31c68571507f6bff16b7bedd12b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tut2/2.16.tex", "max_issues_repo_name": "h4tguy/gt-hons", "max_issues_repo_head_hexsha": "a9b4a271a9bdc31c68571507f6bff16b7bedd12b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tut2/2.16.tex", "max_forks_repo_name": "h4tguy/gt-hons", "max_forks_repo_head_hexsha": "a9b4a271a9bdc31c68571507f6bff16b7bedd12b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.8484848485, "max_line_length": 88, "alphanum_fraction": 0.6394517282, "num_tokens": 649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.8577680977182186, "lm_q1q2_score": 0.8023103995459644}}
{"text": "\\vfill\\eject\r\n\\section{Other Combinatorics Stuff}\r\n  \\begin{tabular}{@{}l|l|l@{}}\r\n  \\toprule\r\n  Catalan\t&\t$C_0=1$, $C_n=\\frac{1}{n+1}\\binom{2n}{n} = \\sum_{i=0}^{n-1}C_iC_{n-i-1} = \\frac{4n-2}{n+1}C_{n-1}$  & \\\\\r\n  Stirling 1st kind & $\\left[{0\\atop 0}\\right]=1$, $\\left[{n\\atop 0}\\right]=\\left[{0\\atop n}\\right]=0$, $\\left[{n\\atop k}\\right]=(n-1)\\left[{n-1\\atop k}\\right]+\\left[{n-1\\atop k-1}\\right]$ & \\#perms of $n$ objs with exactly $k$ cycles\\\\\r\n  Stirling 2nd kind & $\\left\\{{n\\atop 1}\\right\\}=\\left\\{{n\\atop n}\\right\\}=1$, $\\left\\{{n\\atop k}\\right\\} = k \\left\\{{ n-1 \\atop k }\\right\\} + \\left\\{{n-1\\atop k-1}\\right\\}$ & \\#ways to partition $n$ objs into $k$ nonempty sets\\\\\r\n  Euler\t& $\\left \\langle {n\\atop 0} \\right \\rangle = \\left \\langle {n\\atop n-1} \\right \\rangle = 1 $, $\\left \\langle {n\\atop k} \\right \\rangle = (k+1) \\left \\langle {n-1\\atop {k}} \\right \\rangle + (n-k)\\left \\langle {{n-1}\\atop {k-1}} \\right \\rangle$ & \\#perms of $n$ objs with exactly $k$ ascents \\\\\r\n  Euler 2nd Order &  $\\left \\langle \\!\\!\\left \\langle {n\\atop k} \\right \\rangle \\!\\! \\right \\rangle = (k+1) \\left \\langle \\!\\! \\left \\langle {{n-1}\\atop {k}} \\right \\rangle \\!\\! \\right \\rangle +(2n-k-1)\\left \\langle \\!\\! \\left \\langle {{n-1}\\atop {k-1}} \\right \\rangle  \\!\\! \\right \\rangle$ & \\#perms of ${1,1,2,2,...,n,n}$ with exactly $k$ ascents \\\\\r\n  Bell & $B_1 = 1$, $B_n = \\sum_{k=0}^{n-1} B_k \\binom{n-1}{k} = \\sum_{k=0}^n\\left\\{{n\\atop k}\\right\\}$ & \\#partitions of $1..n$ (Stirling 2nd, no limit on k)\\\\\r\n  \\bottomrule\r\n  \\end{tabular}\r\n\r\n  \\vspace{10pt}\r\n  \\begin{tabular}{ll}\r\n    \\#labeled rooted trees & $n^{n-1}$ \\\\\r\n    \\#labeled unrooted trees & $n^{n-2}$ \\\\\r\n    \\#forests of $k$ rooted trees & $\\frac{k}{n}\\binom{n}{k}n^{n-k}$ \\\\\r\n    % Kirchoff's theorem\r\n    $\\sum_{i=1}^n i^2 = n(n+1)(2n+1)/6$ & $\\sum_{i=1}^n i^3 = n^2(n+1)^2/4$ \\\\\r\n    $!n = n\\times!(n-1)+(-1)^n$ & $!n = (n-1)(!(n-1)+!(n-2))$ \\\\\r\n    $\\sum_{i=1}^n \\binom{n}{i} F_i = F_{2n}$ & $\\sum_{i} \\binom{n-i}{i} = F_{n+1}$ \\\\\r\n    $\\sum_{k=0}^n \\binom{k}{m} = \\binom{n+1}{m+1}$ & $x^k = \\sum_{i=0}^k i!\\stirling{k}{i}\\binom{x}{i} = \\sum_{i=0}^k \\left\\langle {k \\atop i} \\right\\rangle\\binom{x+i}{k}$ \\\\\r\n\r\n    $a\\equiv b\\pmod{x,y} \\Rightarrow a\\equiv b\\pmod{\\lcm(x,y)}$ & $\\sum_{d|n} \\phi(d) = n$ \\\\\r\n    $ac\\equiv bc\\pmod{m} \\Rightarrow a\\equiv b\\pmod{\\frac{m}{\\gcd(c,m)}}$ & $(\\sum_{d|n} \\sigma_0(d))^2 = \\sum_{d|n} \\sigma_0(d)^3$ \\\\\r\n    $p$ prime $\\Leftrightarrow (p-1)!\\equiv -1\\pmod{p}$ & $\\gcd(n^a-1,n^b-1) = n^{\\gcd(a,b)}-1$ \\\\\r\n    $\\sigma_x(n) = \\prod_{i=0}^{r} \\frac{p_i^{(a_i + 1)x} - 1}{p_i^x - 1}$ & $\\sigma_0(n) = \\prod_{i=0}^r (a_i + 1)$ \\\\\r\n    $\\sum_{k=0}^m (-1)^k \\binom{n}{k} = (-1)^m \\binom{n-1}{m}$ & \\\\\r\n    $2^{\\omega(n)} = O(\\sqrt{n})$ & $\\sum_{i=1}^n 2^{\\omega(i)} = O(n \\log n)$ \\\\\r\n    % Kinematic equations\r\n    $d = v_i t + \\frac{1}{2}at^2$ & $v_f^2 = v_i^2 + 2ad$ \\\\\r\n    $v_f = v_i + at$ & $d = \\frac{v_i + v_f}{2}t$ \\\\\r\n  \\end{tabular}\r\n  \\subsection{The Twelvefold Way}\r\n    Putting $n$ balls into $k$ boxes.\\\\\r\n  \\begin{tabular}{@{}c|c|c|c|c|l@{}}\r\n  Balls & same & distinct & same & distinct & \\\\\r\n  Boxes & same & same & distinct & distinct & Remarks\\\\\r\n  \\hline\r\n    - & $\\mathrm{p}_k(n)$ & $\\sum_{i=0}^k \\stirling{n}{i}$ & $\\binom{n+k-1}{k-1}$ & $k^n$ & $\\mathrm{p}_k(n)$: \\#partitions of $n$ into $\\le k$ positive parts \\\\\r\n    $\\mathrm{size}\\ge 1$ & $\\mathrm{p}(n,k)$ & $\\stirling{n}{k}$ & $\\binom{n-1}{k-1}$ & $k!\\stirling{n}{k}$ & $\\mathrm{p}(n,k)$: \\#partitions of $n$ into $k$ positive parts \\\\\r\n    $\\mathrm{size}\\le 1$ & $[n \\le k]$ & $[n \\le k]$ & $\\binom{k}{n}$ & $n!\\binom{k}{n}$ & $[cond]$: $1$ if $cond=true$, else $0$\\\\\r\n  \\bottomrule\r\n  \\end{tabular}\r\n\r\n\\clearpage\r\n", "meta": {"hexsha": "45b8fd7430b6845e4f314dc3d67a53bf2a710fc0", "size": 3685, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebook/tex/other_combinatorics.tex", "max_stars_repo_name": "bullybutcher/progvar-library", "max_stars_repo_head_hexsha": "4d4b351c8a2540c522d00138e1bcf0edc528b540", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-10-16T13:22:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-29T22:03:44.000Z", "max_issues_repo_path": "notebook/tex/other_combinatorics.tex", "max_issues_repo_name": "bullybutcher/progvar-library", "max_issues_repo_head_hexsha": "4d4b351c8a2540c522d00138e1bcf0edc528b540", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2021-11-27T14:40:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:14:59.000Z", "max_forks_repo_path": "notebook/tex/other_combinatorics.tex", "max_forks_repo_name": "bullybutcher/progvar-library", "max_forks_repo_head_hexsha": "4d4b351c8a2540c522d00138e1bcf0edc528b540", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2022-03-11T20:53:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T07:08:46.000Z", "avg_line_length": 76.7708333333, "max_line_length": 352, "alphanum_fraction": 0.5253731343, "num_tokens": 1712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873763, "lm_q2_score": 0.8723473630627234, "lm_q1q2_score": 0.802247744718293}}
{"text": "\\section{Propositional logic}\n\\label{sect:background-propositional-logic}\n\nWe denote Boolean constants \\false and \\true by symbols $\\bot$ and $\\top$, respectively.\nIn arithmetic expressions, $\\bot$ is interpreted as integer $0$ and $\\top$ as integer $1$.\nA variable $x$ that takes values from the Boolean domain $\\booldom=\\{\\bot,\\top\\}$ is called a Boolean variable.\nA \\textit{literal} is a variable itself (a \\textit{positive} literal) or the negation of a variable (a \\textit{negative} literal).\nFor a literal $l$, let $\\vl{l}$ denote the variable of $l$.\nBoolean connectives $\\lnot, \\lor, \\land, \\limply, \\equiv$ are used under their conventional semantics.\nOver a finite set $V$ of Boolean variables,\nwe define a \\textit{well-formed formula} $\\pf$ with the following Backus-Naur-form (BNF) grammar:\n\\begin{align}\n    \\pf ::= x\\in V | \\lnot\\pf | (\\pf\\lor\\pf) | (\\pf\\land\\pf) | (\\pf\\limply\\pf) | (\\pf\\equiv\\pf).\n\\end{align}\nGiven a well-formed formula $\\pf$, let $\\vf{\\pf}$ denote the set of Boolean variables appearing in $\\pf$.\nIn the following, a variable is Boolean if not otherwise specified.\nWe shall consider well-formed formulas only and refer to them as \\textit{Boolean formulas}.\n\n\\subsection{Conjunctive and disjunctive normal forms}\nAmong various representations of a Boolean formula,\nwe are particularly interested in normal-form representations because their simplicity allows efficient analyses.\n\nA Boolean formula is in \\textit{conjunctive normal form} (CNF) if it is a conjunction of \\textit{clauses},\nwhere a clause is a disjunction of literals.\nA Boolean formula is in \\textit{disjunctive normal form} (DNF) if it is a disjunction of \\textit{cubes},\nwhere a cube is a conjunction of literals.\nA variable $x$ is said to be \\textit{pure} in a formula if its appearances in the formula are all positive literals or negative literals.\nWe alternatively treat a clause or a cube as a set of literals,\nand a CNF (resp. DNF) formula as a set of clauses (resp. cubes).\nIn the rest of the dissertation, a Boolean formula is assumed to be given in CNF if not otherwise specified.\n\n\\subsection{Boolean satisfiability}\nAn \\textit{assignment} $\\as$ over a variable set $V$ is a mapping from $V$ to $\\booldom$.\nWe denote the set of all assignments over $V$ by $\\av{V}$.\nGiven a Boolean formula $\\pf$,\nan assignment $\\as$ over $\\vf{\\pf}$ is called a \\textit{complete} assignment for $\\pf$.\nIf $\\as$ is over a proper subset of $\\vf{\\pf}$, it is called a \\textit{partial} assignment.\nThe resultant formula of $\\pf$ induced by an assignment $\\as$ over a variable set $V$,\ndenoted as $\\pcf{\\pf}{\\as}$,\nis obtained via substituting the occurrences of every $x\\in V$ in $\\pf$ with its assigned value $\\as(x)$.\nSuch substitution is called \\textit{cofactoring} $\\pf$ with $\\as$.\nIf $V=\\{x\\}$, we write $\\pcf{\\pf}{x}$ (resp. $\\ncf{\\pf}{x}$) to denote the resultant formula of $\\pf$ under an assignment that maps $x$ to $\\top$ (resp. $\\bot$),\nand call this formula the \\textit{positive} (resp. \\textit{negative}) \\textit{cofactor} of $\\pf$ with respect to variable $x$.\n\nA complete assignment $\\as$ \\textit{satisfies} $\\pf$, denoted as $\\as\\models\\pf$, if $\\pcf{\\pf}{\\as}=\\top$.\nSuch complete assignment $\\as$ is called a \\textit{satisfying complete assignment} for $\\pf$.\nOn the other hand, if $\\pcf{\\pf}{\\as}=\\bot$, $\\as$ is called an \\textit{unsatisfying complete assignment}.\nSimilarly, a partial assignment $\\as^+$ over $X\\subset\\vf{\\pf}$ is called a \\textit{satisfying} (resp. an \\textit{unsatisfying}) \\textit{partial assignment} for $\\pf$\nif for some (resp. every) assignment $\\mu$ over $\\vf{\\pf}\\setminus X$,\n$\\pf$ valuates to $\\top$ (resp. $\\bot$) under the complete assignment that combines $\\as$ and $\\mu$.\nWe alternatively represent an assignment $\\as$ for $\\pf$ as a cube.\nA cube is called a \\textit{minterm} of formula $\\pf$ when it corresponds to a complete assignment over $\\vf{\\pf}$.\nGiven two Boolean formulas $\\pf_1$ and $\\pf_2$ over a same set $V$ of variables,\nwe write $\\pf_1\\limply\\pf_2$ if the following condition holds:\n$\\forall\\as\\in\\av{V}.\\as\\models\\pf_1\\limply\\as\\models\\pf_2$.\n\nA Boolean formula $\\pf$ is \\textit{satisfiable} if it has a satisfying complete assignment.\nOtherwise, $\\pf$ is \\textit{unsatisfiable}.\nA Boolean formula $\\pf$ is a \\textit{tautology} if the following condition holds:\n$\\forall\\as\\in\\av{\\vf{\\pf}}.\\as\\models\\pf$.\nThe Boolean satisfiability problem asks to decide whether a Boolean formula is satisfiable or not.\nIt is a well-known NP-complete~\\cite{Cook1971} problem.\nWe write $\\sat{\\pf}$ (resp. $\\unsat{\\pf}$) to indicate $\\pf$ is satisfiable (resp. unsatisfiable).\nA satisfying complete assignment of $\\pf$ is also called a \\textit{model} of $\\pf$, which is denoted by $\\model{\\pf}$.\n\nA set $\\base\\subseteq\\vf{\\pf}$ is a \\textit{base set} for $\\pf$ if\nfor any (partial) assignment $\\as^+$ over $\\base$,\nthere exists at most one assignment $\\mu$ over $\\vf{\\pf}\\setminus\\base$\nsuch that $\\pf$ is satisfied by the combined assignment of $\\as^+$ and $\\mu$ over $\\vf{\\pf}$.\nObserve that, given any Boolean formula $\\pf$,\na base set must exist ($\\vf{\\pf}$ is a trivial base set of $\\pf$) but may not be unique.\nLet $\\as^+$ be an assignment over a base set $\\base\\subseteq\\vf{\\pf}$.\nIf there exists an assignment $\\mu$ over $\\vf{\\pf}\\setminus\\base$\nsuch that the combined assignment $\\nu$ satisfies $\\pf$,\nthen we say that $\\pf$ is satisfiable under $\\as^+$ and write $\\as^+\\models\\pf$ to mean $\\nu\\models\\pf$.\nIf there does not exist such an assignment $\\mu$ over $\\vf{\\pf}\\setminus\\base$,\nthen $\\pf$ is unsatisfiable under $\\as^+$, denoted by $\\as^+\\not\\models\\pf$.\n\nAn $n$-variable \\textit{Boolean function} is a mapping from $\\booldom^n$ to $\\booldom$.\nNote that a Boolean formula $\\pf$ induces a Boolean function with a domain $\\av{\\vf{\\pf}}$.\nWe shall not distinguish between a Boolean formula and its induced Boolean function.", "meta": {"hexsha": "5e4fbb68e6ae686d6af51b695ddf6b7d7bb72a3e", "size": 5880, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/background/propositional-logic.tex", "max_stars_repo_name": "nianzelee/PhD-Dissertation", "max_stars_repo_head_hexsha": "061e22dd55b4e58b3de3b0e58bb1cbe11435decd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-11T19:38:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T19:38:13.000Z", "max_issues_repo_path": "paper/background/propositional-logic.tex", "max_issues_repo_name": "nianzelee/PhD-Dissertation", "max_issues_repo_head_hexsha": "061e22dd55b4e58b3de3b0e58bb1cbe11435decd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/background/propositional-logic.tex", "max_forks_repo_name": "nianzelee/PhD-Dissertation", "max_forks_repo_head_hexsha": "061e22dd55b4e58b3de3b0e58bb1cbe11435decd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 72.5925925926, "max_line_length": 166, "alphanum_fraction": 0.7215986395, "num_tokens": 1672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.8723473647220786, "lm_q1q2_score": 0.8022477424017983}}
{"text": "%\n% Chapter 1.1\n%\n\n\\section*{1.1 Representing Functions}\n\nA \\textbf{function} \\(f\\) is a rule that assigns to each element \\(x\\) in set \\(D\\) exactly one element, called \\(f(x)\\), in a set \\(E\\).\n\\\\\\\\\n\\textbf{Vertical Line Test}: A curve in the \\(xy\\)-plane is the graph of a function of \\(x\\) if and only if no vertical line intersects the curve more than once.\n\\\\\\\\\nA \\textbf{piecewise function} is a function defined for multiple sub-functions applying to a certain interval of the main function's domain.\n\n\\[ f(x)=\n    \\begin{cases} \n      1-x & x\\leq -1 \\\\\n      \\frac{3-x}{4} & -1 < x < 100 \\\\\n      2x & x\\geq 100\n   \\end{cases}\n\\]\n\\\\\nA function is \\textbf{even} if \\(f(-x)=f(x)\\) for every number \\(x\\) in its domain.\n\\\\\\\\\nA function is \\textbf{odd} if \\(f(-x)=-f(x)\\) for every number \\(x\\) in its domain.\n\\\\\\\\\nA function \\(f\\) is \\textbf{decreasing} on an interval \\(I\\) if \\(f(x_1)<f(x_2)\\) whenever \\(x_1 < x_2\\) in \\(I\\).\nA function \\(f\\) is \\textbf{increasing} on \\(I\\) if \\(f(x_1)>f(x_2)\\) whenever \\(x_1<x_2\\) in \\(I\\).\n", "meta": {"hexsha": "f6560a19807eec5ea5cec0f4cb9083abf1fb59a9", "size": 1036, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/1-1.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/1-1.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/1-1.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.3703703704, "max_line_length": 161, "alphanum_fraction": 0.6158301158, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.8022448999508281}}
{"text": "\\lab{Python}{NumPy Arrays and NumPy and SciPy}{NumPy Arrays and NumPy and SciPy} \n\\objective{Create and manipulate powerful NumPy $n$-dimensional arrays and learn features available in NumPy and SciPy.}\n\\label{lab:NumPyArrays}\n\n\\section*{Why Use Arrays?} Python has a reasonably efficient list object, \nso why should we use arrays? Let's begin with a simple demonstration of why\narrays are important for numerical computation, in which\nwe will square a matrix that is represented as a two dimensional list (i.e. a list of lists). The lists form the rows of the matrix, and are \"stacked\" to form the columns; we obtain the elements of the jth column by taking the jth element of each row.\n\nThe following is a function that will accept two matrices, $A$ and $B$, and return $AB$ following the usual rules\nof matrix multiplication. \n\n\\lstinputlisting[style=fromfile]{arr_mult.py}\n\nWe can initialize a $k \\times k$ array of integers like this:\n\\begin{lstlisting}\n>>> k = 10 \n>>> A = [range(i, i+k) for i in range(0, k**2, k)]\n\\end{lstlisting}\n\n\\section*{NumPy} NumPy is one of the fundamental packages for scientific\ncomputing with Python. At its heart lies an efficient \\li{ndarray}\nobject for fast computations. These $n$-dimensional arrays form\nthe foundation for all computations done in NumPy and SciPy (a\nhigher-level scientific computing library built on top of NumPy), and are a generalization of matrices. Just as a matrix (of dimension 2) can be thought of as a list of rows (of dimension 1), when we create an $n$-dimensional array, we create a list of arrays of dimension $n-1$. NumPy\nis typically imported like this: \n\n\n\\begin{lstlisting}\n>>> import numpy as np\n\\end{lstlisting}\n\n\n\\begin{problem} \nTime how long the \\li{arr_mult} function \nlisted above and the NumPy method for matrix multiplication take to square matrices of size \\li{k = 100, 200,}\nand \\li{300} and report the computed times. Briefly comment on the time needed to \nsquare a two dimensional list vs. a two dimensional NumPy array. \n\nImport timeit and NumPy. Create an array of the appropriate dimensions and square it, \nusing both the function and the NumPy Method. (Be sure know the difference\n between doing element-wise multiplication and matrix multiplication).\n\nIn IPython you can time how long it takes for a line of code to execute\nby prefacing it with \\li{\\%timeit}. If you aren't using IPython, you will need\nto use the timeit function documented here: \\url{https://docs.python.org/2/library/timeit.html}.\n\n\\end{problem}\n\n% Below is a comparison of runtimes needed to square a matrix\n% \\begin{center} \\begin{tabular}{|c|l|l|} \\hline Data Structure & Size &\n% Time (s) \\\\ \\hline Python List & $1\\times1$ & 0.0000181198 \\\\\n% \\cline{2-3} & $10\\times10$ & 0.0002758503 \\\\ \\cline{2-3} &\n% $100\\times100$ & 0.1336028576 \\\\ \\cline{2-3} & $1000\\times1000$ &\n% 200.4009799957 \\\\ \\hline \\hline NumPy Array & $1\\times1$ &\n% 0.0000298023 \\\\ \\cline{2-3} & $10\\times10$ & 0.0000109673 \\\\\n% \\cline{2-3} & $100\\times100$ & 0.0009210110 \\\\ \\cline{2-3} &\n% $1000\\times1000$ & 2.1682999134 \\\\ \\hline \\end{tabular}\n% %\n% \\end{center}\n% \n% \n% \nThe reason for the drastic speed difference is that Python, as a high\nlevel interpreted language, tends to be slower than lower level compiled\nlanguages such as C. The algorithms in NumPy are heavily optimized and\nare usually implemented in C or Fortran. Instead of operating purely in\nPython they use Python to run code that is written and optimized in\nother, faster, languages. NumPy interfaces with some of the best packages\navailable for doing computational linear algebra and can be used to\nwrite relatively fast programs.\n\n\n\\section*{Creating Arrays} The most elementary way to create an array is\nto define it explicitly using \\li{np.array()} (this creates a one dimensional array). \n\\begin{lstlisting}\n>>> a = np.array([0, 3, 8, 6, 3.14]) \n>>> a\narray([0, 3, 8, 6, 3.14]) \n\\end{lstlisting} \n\nNumPy provides a variety of\nways to easily create different kinds of arrays. \\li{np.arange()}\ncreates a ranged array much the same way that Python's \\li{range}\nstatement creates a list. \\li{np.arange([start], stop, [step])} requires a\nstop value, and can also take start and step values (optional). It returns the range\nof evenly spaced values starting with the start value (default 0) and up to,\nbut not including, the stop value. \n\\begin{lstlisting}\n>>> b = np.arange(10) \n>>> b\narray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) \n\\end{lstlisting}\n \nWe can also create an array of evenly spaced numbers over a desired interval.\nThis is done using \\li{np.linspace(start, stop, num=50)} whose first\nand second arguments define the endpoints of this closed interval while \nthe third argument defines the number of samples. Note that the number\nof samples defaults to 50. \n\\begin{lstlisting}\n# Return an array of 4 values ranging evenly from 0 to 32.\n>>> c = np.linspace(0, 32, 4) \n>>> c\narray([  0.        ,  10.66666667,  21.33333333,  32.        ])\n\\end{lstlisting} \n\n\nWe can also create arrays that\nconsist entirely of ones or zeros using \\li{np.ones()} and\n\\li{np.zeros()} respectively. \n\\begin{lstlisting}\n>>> d = np.ones(5) \n>>> d\narray([ 1.,  1.,  1.,  1.,  1.])\n\\end{lstlisting} \n\nWe can even create arrays using random values chosen\nfrom a variety of probability distributions. These functions are stored\nin a submodule of NumPy called \\li{np.random}. \n\\begin{lstlisting}\n>>> e = np.random.rand(5) # uniformly distributed values \n>>> e\narray([ 0.21845499,  0.73352537,  0.28064456,  0.66878454,  0.44138609])\n# Return an array of 6 randomly generated integers uniformly\n# distributed in [0, 5).\n>>> f = np.random.randint(0, 5, 6) \n>>> f\narray([ 3,  1,  0,  3,  4,  1])\n\n\\end{lstlisting} \n\nWe can also allocate an array without initializing its\nvalues. This is most useful when the initial values of an\narray do not matter (like when you are constructing an array filled with\nspecific values or when you are going to overwrite it).\n\\begin{lstlisting}\n>>> g = np.empty(5) \n>>> g\narray([  0.00000000e+000,   1.30586451e-316,   1.17126324e-316,\n0.00000000e+000,   2.37151510e-322]) \n\\end{lstlisting} \n\nWe can also create an array with the same shape and type as another given array. \nTo verify this we can check the shape and data type of both arrays. More information\non \\li{shape} and \\li{dtype} will be provided shortly.\n\\begin{lstlisting}\n# Note that 2,3 dictates a 2 by 3 array of random values\n>>> h = np.random.rand(2,3) \n>>> h.shape\n(2,3)\n>>> h.dtype\ndtype('float64')\n>>> j = np.empty_like(h)\n>>> j.shape\n(2,3)\n>>> j.dtype\ndtype('float64')\n\\end{lstlisting} \nNote that you can also dictate that your new array be\nfilled entirely with ones or zeros by using the \\li{np.ones_like} or\n\\li{np.zeros_like}, respectively.\n\n\n\\section*{Array Objects} \nUnlike Python containers, all of the elements\nof an array must have the same data type. These datatypes are\nmachine-native data types that avoid the overhead (time consumption and inefficiency)\n of Python objects. For example,  an \\li{int} in NumPy is not the same as an \\li{int} in Python;\nthe \\li{int} data type native to NumPy stores integers in a way that uses less processor power to handle. The benefit\nof using these machine-native types is a tremendous speedup of\nnumerical operations. Datatypes supported by NumPy are shown in Table \\ref{numpytypes}.\n\\begin{table} \n\\begin{tabular}{l|l} \nData type & Description \n\\\\ \\hline \n\\li{bool} & Boolean \\\\ \n\\li{int8} & 8-bit integer \\\\ \n\\li{int16} & 16-bit integer \\\\ \n\\li{int32} & 32-bit integer \\\\\n\\li{int64} & 64-bit integer \\\\ \n\\li{int} & Platform integer (depends on platform) \\\\ \n\\li{uint8} & Unsigned 8-bit integer \\\\ \n\\li{uint16} & Unsigned 16-bit integer \\\\ \n\\li{uint32} & Unsigned 32-bit integer \\\\\n\\li{uint64} & Unsigned 64-bit integer \\\\ \n\\li{float16} & Half precision float \\\\ \n\\li{float32} & Single precision float \\\\ \n\\li{float64} & Double precision float (also \\li{float}) \\\\ \n\\li{complex64} & Complex number represented by two single precision floats \\\\ \n\\li{complex128} & Complex number represented by two double precision floats (also \\li{complex})\n\\end{tabular} \n\\caption{Native numerical data types available in NumPy.}\n\\label{numpytypes} \n\\end{table} \n\nLike any other object in Python, \\li{ndarray} objects have methods and properties associated with them. \nWe can derive information from arrays by looking at their different attributes. The data type of the array\n is stored in the \\li{dtype} property. Many of the array constructors accept an optional\n\\li{dtype} keyword that lets you specify the data type of the array to be created. \n\n\\begin{lstlisting}\n>>> a.dtype\ndtype('float64')\n>>> a = np.array(range(5), dtype=np.uint8) \n>>> a.dtype\ndtype('uint8') \n\\end{lstlisting} \n\nWe can check the number of dimensions an\narray has by looking at the value of the \\li{ndim} property. \n\\begin{lstlisting}\n>>> a.ndim\n1 \n\\end{lstlisting} \n\nWe can see the sizes of each dimension by looking at\nthe \\li{shape} property. This will return a Python tuple of the size of\neach dimension. \n\\begin{lstlisting}\n>>> a.shape\n(5,)\n# Return the size of the first dimension.\n>>> a.shape[0]\n5 \n# Return the total number of elements in the array.\n>>> a.size \n5\n\\end{lstlisting} \n\nFor a single dimensional array, these properties are\nuninteresting. However, these array properties are the most efficient way \nto understand the size and shape of an array.\n\nLet's look at higher dimensional arrays. One, two, and three dimensional\narrays are easy to visualize. As previously mentioned, higher dimensional NumPy arrays can simply be\nthought of as arrays within arrays. A three dimensional array can just\nbe thought of as an array of two dimensional arrays, or an array of arrays of (one dimensional) arrays. The 3D index, \\li{A[3, 5,\n1]}, essentially means \\emph{take the second element} \\li{(1)} \\emph{of the sixth\nsubarray} \\li{(5)} \\emph{of the fourth subarray} \\li{(3)} \\emph{of A}. \n Each dimension is called an \\emph{axis} in NumPy (ie. a 3D array has 3 axes).  \nIn a 2D array, we may refer to the rows as the zero axis and the columns as the\none axis. Many of NumPy's functions can be restricted to an axis. \n\nMost of the array constructors we have considered thus far support \ncreating arrays with an arbitrary number of dimensions. However, some are restricted to lower dimensions, making them convenient for matrix operations; for example, we can easily create an identity matrix with \\li{np.eye}, \\li{np.identity},\n or \\li{np.diag}. \n \n\\li{np.eye} is the most versatile of these methods and allows for non-square outputs, \nin which case it puts ones on the diagonal and zeros everywhere else. \n\\li{np.diag} is an interesting function.  If given an existing 2D array, \nit will extract the diagonal elements and return a 1D array. However, if given \na 1D array or a list, it will construct a 2D array with the list elements as the diagonal.\n\n\\begin{lstlisting}\n>>> h = np.eye(3) \n>>> h\narray([[ 1.,  0.,  0.],\n       [ 0.,  1.,  0.],\n       [ 0.,  0.,  1.]])\n>>> np.eye(3, 4)\narray([[ 1.,  0.,  0.,  0.],\n       [ 0.,  1.,  0.,  0.],\n       [ 0.,  0.,  1.,  0.]])\n>>> np.identity(3)\narray([[ 1.,  0.,  0.],\n       [ 0.,  1.,  0.],\n       [ 0.,  0.,  1.]])\n>>> np.diag(h)\narray([ 1.,  1.,  1.])\n>>> i = np.diag(np.arange(5))\n>>> i\narray([[0, 0, 0, 0, 0],\n       [0, 1, 0, 0, 0],\n       [0, 0, 2, 0, 0],\n       [0, 0, 0, 3, 0],\n       [0, 0, 0, 0, 4]])\n\\end{lstlisting} \n\nAnother powerful function is\n\\li{np.tile()}. Tiling allows us to construct an arbitrary-dimensional array by repeating an existing array\n in a specified pattern. \\li{np.tile()} allows us to tile arrays across one or more dimensions. \n\\begin{lstlisting}\n>>> j = np.array([1, 9, 5, 2])\n# Repeat j three times in the first dimension \nnp.tile(j, 3)\narray([1, 9, 5, 2, 1, 9, 5, 2, 1, 9, 5, 2])\n# Make an array of three lists (third dimension) of three lists \n# (second dimension) of two copies of j each (first dimension)\n>>> k = np.tile(j, (3, 3, 2)) \n>>> k\narray([[[1, 9, 5, 2, 1, 9, 5, 2],\n        [1, 9, 5, 2, 1, 9, 5, 2],\n        [1, 9, 5, 2, 1, 9, 5, 2]],\n\n       [[1, 9, 5, 2, 1, 9, 5, 2],\n        [1, 9, 5, 2, 1, 9, 5, 2],\n        [1, 9, 5, 2, 1, 9, 5, 2]],\n\n       [[1, 9, 5, 2, 1, 9, 5, 2],\n        [1, 9, 5, 2, 1, 9, 5, 2],\n        [1, 9, 5, 2, 1, 9, 5, 2]]])\n\n\\end{lstlisting}\n\n\nWe often find it useful to create arrays that represent a\ntwo-dimensional grid of coordinates. This is done using the\n\\li{meshgrid()} function, for example:\n\\begin{lstlisting}\n>>> x = np.arange(4) \n>>> y = np.arange(4, 8) \n>>> X, Y = np.meshgrid(x, y) \n>>> X\narray([[0, 1, 2, 3],\n       [0, 1, 2, 3],\n       [0, 1, 2, 3],\n       [0, 1, 2, 3]])\n>>> Y\narray([[4, 4, 4, 4],\n       [5, 5, 5, 5],\n       [6, 6, 6, 6],\n       [7, 7, 7, 7]])\n\\end{lstlisting} \nAs you can see, \\li{X} is an array representing the $x$-coordinates for a 4x4 grid of points and \\li{Y} is an array representing the\n$y$-coordinates of that same grid of points. For example, the (0,0) entries in X and Y correspond to the point (0,4), the (2,3) entries correspond to the point (3,6), and so on.\n\n\\begin{comment} \nWhen\ncreating large grids of points this can use large amounts of RAM, so the\nmeshgrid function includes the \\li{copy} argument which, when set to\nfalse, returns arrays that are views of the original arrays instead of\ncopies (views and copies are discussed later in this lab). For example,\ninstead of running \\li{np.meshgrid(x, y)} you could run\n\\li{np.meshgrid(x, y, copy=False)}. This can be much faster, but should\nprobably only be used if you do not intend to make any additional\nchanges to the coordinates grid independent of the values stored in the\noriginal arrays.\n\nEvery NumPy array has five flags that give important information about\nthe array. We can check if an array is read-only by looking at its\nflags, or we can check how the array's contents are laid out in memory.\nOnly the \\texttt{WRITEABLE} and \\texttt{ALIGNED} flags can be modified. \nThe other flags are read-only. The \\texttt{OWNDATA} flag lets us know if\nthe array is a view or not. We will explain array views later in this\nlab. \\begin{lstlisting}\n>>> i.flags\n  C_CONTIGUOUS : True F_CONTIGUOUS : False OWNDATA : True WRITEABLE :\n  True ALIGNED : True UPDATEIFCOPY : False \\end{lstlisting} NumPy has\n  two different memory orderings for an array. Many array constructors\n  allow you to specify an \\li{order} keyword that determines the memory\n  layout of the array. \\begin{description} \\item[Row-major:] Arrays are\n  stored by rows in continuous memory. Languages such as C and Python\n  use row-major indexing. NumPy arrays by default use this indexing\n  convention. When an array is stored in memory the addresses to its\n  values are stored linearly. In simplest terms, the ordering of an\n  array determines whether its rows or its columns are stored in\n  contiguous blocks (for example: row 0, row 1, row 2, ... as opposed to\n  column 1, column 2, column 3, ...). For an array where the rows are in\n  contiguous blocks in memory, performing any sort of operation along a\n  column will be slower than performing that same operation along a row\n  of the same length. This difference is because of the irregular memory\n  access pattern. In NumPy, row-major arrays are identified as \\emph{C\n  contiguous} (\\li{order=`C'}). \\item[Column-major:] Arrays are stored\n  by columns in contiguous memory. Languages like FORTRAN, MATLAB, and R\n  use column-major indexing. For a column major array, operations that\n  run along rows are slower. In NumPy, column-major arrays are\n  identified as \\emph{FORTRAN contiguous} (\\li{order=`F'}).\n  \\end{description} Paying attention to how your arrays are indexed will\n  be beneficial to the performance of your algorithms. Speed is not\n  usually a critical concern, but it is good to know these things when\n  speed does become an issue.\n\n% \\section*{Iterating Through Arrays} Iterating through an array\n% mitigates most, if not all, speed advantages of NumPy. The advantage\n% of NumPy is that all of the iterating has been pushing into the highly\n% efficient looping structures of C or Fortran. Implementing that loop\n% in Python dramatically slows down the speed of execution. There are\n% however some valid cases where iterating over the array is necessary.\n% NumPy provides several efficient iterators that can be used in such\n% instances.\n% \n\\end{comment}\n\n\\section*{Iterating Through Arrays} Iterating through an array\nmitigates most, if not all, speed advantages of NumPy. The advantage\nof NumPy is that all of the iterating has been pushing into the highly\nefficient looping structures of C or Fortran. Implementing that loop\nin Python dramatically slows down the speed of execution. There are\nhowever some valid cases where iterating over the array is necessary.\nNumPy provides several efficient iterators that can be used in such\ninstances.\n\n\\section*{Array Views and Copies} It is important to understand that\nNumPy has two ways of returning an array. Slice operations always return\na \\emph{view} and fancy indexing always returns a \\emph{copy}.\nUnderstand that even though they may look the same, views and copies are\nvery different.\n\nViews are special arrays that are unique objects, but reference the same memory as the array they \nreference; changing elements in a view also changes the array it references. \nBelow, we demonstrate the behavior of a view. Notice that \\li{m} looks like a copy\nof \\li{k} even though it is not. \nThe \\li{np.reshape()} method will be discussed in greater detail \nfurther on in this lab.\n\\begin{lstlisting}\n>>> k = np.reshape(np.arange(25), (5,5)) \n>>> k\narray([[ 0,  1,  2,  3,  4],\n       [ 5,  6,  7,  8,  9],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19],\n       [20, 21, 22, 23, 24]])\n# Although m appears to be a copy of k, it is actually a view. \n>>> m = k[:]\n>>> m\narray([[ 0,  1,  2,  3,  4],\n       [ 5,  6,  7,  8,  9],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19],\n       [20, 21, 22, 23, 24]]) \n# This indicates that m and k are unique objects.\n>>> id(m) == id(k) \nFalse\n# Change the third element of m (itself a list) to 500\n>>> m[2] = 500 \n>>> m\narray([[  0,   1,   2,   3,   4],\n       [  5,   6,   7,   8,   9],\n       [500, 500, 500, 500, 500],\n       [ 15,  16,  17,  18,  19],\n       [ 20,  21,  22,  23,  24]])\n# Changing m also changed k.\n>>> k \narray([[  0,   1,   2,   3,   4],\n       [  5,   6,   7,   8,   9],\n       [500, 500, 500, 500, 500],\n       [ 15,  16,  17,  18,  19],\n       [ 20,  21,  22,  23,  24]])\n\\end{lstlisting} \n\nThe reason that changing the array \\li{m} also changed\nthe array \\li{k} is because \\li{m} and \\li{k} contain references to the\nsame data in memory, even though they are different Python objects.\nViews reduce the overhead of making copies of arrays and are useful when\nwe want to change certain parts of the array.\n\nA copy of an array is a separate array with its own memory. An array can\nbe copied using the \\li{np.copy()} function (also available as a method of \nthe array object). \n\n\\begin{lstlisting}\n>>> j = np.reshape(np.arange(25), (5,5))\n>>> n = np.copy(j) \n# We still have unique objects.\n>>> id(n) == id(j) \nFalse\n>>> n[2] = 500 \n>>> n\narray([[  0,   1,   2,   3,   4],\n       [  5,   6,   7,   8,   9],\n       [500, 500, 500, 500, 500],\n       [ 15,  16,  17,  18,  19],\n       [ 20,  21,  22,  23,  24]])\n>>> j\narray([[ 0,  1,  2,  3,  4],\n       [ 5,  6,  7,  8,  9],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19],\n       [20, 21, 22, 23, 24]])\n# Fills the values of an existing array, j, with n.\n>>> j[:] = n\n>>> j\narray([[  0,   1,   2,   3,   4],\n       [  5,   6,   7,   8,   9],\n       [500, 500, 500, 500, 500],\n       [ 15,  16,  17,  18,  19],\n       [ 20,  21,  22,  23,  24]])\n\\end{lstlisting} \nChanging the data in a copy of an array does not affect the data in the \noriginal array because the two arrays have different locations in memory.\n\n\\section*{Indexing and Slicing} Every element of an array has a unique\nnumeric address, or index, that can be used for accessing that element. \"Indexing\" \nrefers to the methods we use to access elements with specified indices.\nAll indices in Python and NumPy starts with \\li{0} as the first value. \nNegative indexing can also be used for NumPy arrays. \n\\begin{lstlisting}\n>>> a = np.arange(3, 9) \n>>> a[0]\n3\n# Return the last element of a; a[-2] would return the second to last element\n>>> a[-1]\n8 \n\\end{lstlisting} \nWhen indexing a multidimensional array, it might be\ntempting to use the \\li{f[i][j][k]} form of indexing. This is a \\emph{very}\ninefficient way to access NumPy arrays. NumPy has provided an optimized\nindexing syntax in which the precise index is expressed as a tuple (the\n\\li{k[i,j,k]} form).  This optimized indexing becomes significantly\nfaster when we work with arrays of more than one dimension. The reason that the\nunoptimized \\li{f[i][j][k]} indexing is slow is that each bracket is returning an\narray slice. For a 3D array, \\li{k[0][0][0]} will create temporary\nslices of \\li{k} from each dimension (\\li{k[0]}, \\li{k[0][0]}, and\n\\li{k[0][0][0]}) and return the last slice. Using tuples as indices allows\nNumPy to access the element directly (without creating intermediate slices \nalong the way), which is much more efficient.\n\nIt is also possible to index an array with an object such as a list or\nan array instead of requesting slices with specified indices, but in this case \nNumPy behaves a little differently. This feature is commonly referred to as fancy\nindexing. One difference is that fancy indexing always returns a copy of an array\ninstead of a view. \nThere are two types of fancy indexing: boolean and integer. \nBoolean indexing uses an array of \\li{True} or \\li{False} values to \ndetermine which elements of the array to take. \n\\begin{lstlisting}\n>>> b = np.arange(25).reshape((5,5)) \n>>> b\narray([[ 0,  1,  2,  3,  4],\n       [ 5,  6,  7,  8,  9],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19],\n       [20, 21, 22, 23, 24]])\n# We refer to this array as \"bmask\" because we are \"masking\" the\n# values not specified instead of deleting them.\n>>> bmask = (b > 15) & (b < 23) \n# Note that logic operations on arrays result in true-false valued arrays.\n>>> bmask \narray([[False, False, False, False, False],\n       [False, False, False, False, False],\n       [False, False, False, False, False],\n       [False,  True,  True,  True,  True],\n       [ True,  True,  True, False, False]], dtype=bool)\n>>> b[bmask]\narray([16, 17, 18, 19, 20, 21, 22])\n# This is the condensed form. \n>>> b[(b > 15) & (b < 23)] \narray([16, 17, 18, 19, 20, 21, 22])\n>>> b[~bmask] # invert the mask\narray([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 23, 24])\n# Return an array of elements b[0,0], b[2,2], and b[4,4].\n>>> b[(0, 2, 4), (0, 2, 4)] \narray([ 0, 12, 24])\n# This is the same as above, but with ranges instead of tuples; \n# the range(0, 5, 2) is equivalent to the tuple (0, 2, 4).\n>>> b[range(0, 5, 2), range(0, 5, 2)] \narray([ 0, 12, 24])\n# Take the first (0) and last (-1) columns. Note that this is a list of discrete\n# indices, not a slice. The : indicates a slice including all of that axis.\n>>> b[:, [0, -1]]  \narray([[ 0,  4], [ 5,  9], [10, 14], [15, 19], [20, 24]])\n\\end{lstlisting}\n\nThough fancy indexing does not return a view of an array, it \\emph{can}\nbe used for assignment. For example, we can set all values of an array\nthat are less than \\li{.5} to \\li{0} in the following way: \n\\begin{lstlisting}\n>>> from numpy.random import rand \n>>> A = rand(10, 10) \n>>> A[A<.5] = 0.\n\\end{lstlisting}\n\nSlicing an array is very similar to slicing a Python list. An array\nslice returns some subset of an array. We can access ranges of elements\nusing Python lists. We can also more concisely select ranges using the\n\\li{array[start:stop:step]} range notation. \n\\begin{lstlisting}\n>>> k = np.arange(25).reshape((5,5)) \n>>> k\narray([[ 0,  1,  2,  3,  4],\n       [ 5,  6,  7,  8,  9],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19],\n       [20, 21, 22, 23, 24]])\n# Return every other element of the rows and every third element of\n# the columns.  \n>>> k[::2, ::3] \narray([[ 0,  3],\n       [10, 13],\n       [20, 23]])\n# Reverse the order of the columns; the : indicates a slice including\n# all of that axis.\n>>>k[:, ::-1] \narray([[ 4,  3,  2,  1,  0],\n       [ 9,  8,  7,  6,  5],\n       [14, 13, 12, 11, 10],\n       [19, 18, 17, 16, 15],\n       [24, 23, 22, 21, 20]])\n# Extract the lower right 2x2 subarray.\n>>> k[3:, 3:] \narray([[18, 19],\n       [23, 24]])\n# Extract the second column. The returned array is 1D.\n>>> k[:, 1] \narray([ 1,  6, 11, 16, 21]) \n\\end{lstlisting} \n\nOperations like those above\nare examples of array slicing. Array slices are views, not copies, of\nportions of the data of the original array.\n\n% \\begin{problem} Generate a random $1000 \\times 1000$ array \\li{A}. Now\n% create an uninitialized array \\li{B} with all the same attributes as\n% \\li{A}. Now do the following 100 times: \\begin{itemize} \\item\n% Overwrite \\li{B} so that it is an array of new random values like\n% \\li{A}. This can be done like this: \\li{B[:] = rand(1000,1000)} \\item\n% Use fancy indexing to make \\li{A} the maximum of \\li{A} and \\li{B}.\n% \\end{itemize} Now take \\li{exp(A)} and have NumPy store the output\n% directly in \\li{A}. Take the maximum along the vertical axis and\n% average the result. The final number should be very close to $e$.\n% \\end{problem}\n% \n\\section*{Manipulating Arrays} NumPy provides a variety of functions for\nworking with already existing arrays. The shape of a NumPy array can be\nchanged by using the \\li{np.reshape()} function (also available as a\nmethod of array objects). The reshape function gives an array a new\nshape without changing the data of the array. It is imperative that \nthe new shape be compatible with the size of the array. \nIt returns a view whenever possible, otherwise it will return \na copy of the reshaped array.\n\\begin{lstlisting}\n>>> k = np.arange(36)\narray([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35])\n>>> k.shape\n(36,)\n>>> k.reshape((12, 3))\narray([[ 0,  1,  2],\n       [ 3,  4,  5],\n       [ 6,  7,  8],\n       [ 9, 10, 11],\n       [12, 13, 14],\n       [15, 16, 17],\n       [18, 19, 20],\n       [21, 22, 23],\n       [24, 25, 26],\n       [27, 28, 29],\n       [30, 31, 32],\n       [33, 34, 35]])\n\\end{lstlisting} \nSometimes it is best to work on the entire array in single dimension. \nWe can reshape the array to a single dimension, or use \\li{np.ravel}. \nThe \\li{flat} method is an iterator that will iterate over a \nflattened array efficiently.\n\\begin{lstlisting}\n>>> k.ravel()\narray([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35])\n# The -1 in the axis tells NumPy to make the axis as long as is necessary.\n>>> k.reshape((-1,)) \narray([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35])\n>>> timeit k.ravel()\n1000000 loops, best of 3: 291 ns per loop\n>>> timeit k.reshape((-1,))\n1000000 loops, best of 3: 418 ns per loop \n\\end{lstlisting} \nThe transpose \\li{np.T} is another efficient NumPy operation that returns an array\nview. \n\n\\begin{lstlisting}\n>>> b = np.arange(16).reshape((4,4)) \n>>> b.T\narray([[ 0,  4,  8, 12],\n       [ 1,  5,  9, 13],\n       [ 2,  6, 10, 14],\n       [ 3,  7, 11, 15]])\n\\end{lstlisting}\n\n\\begin{comment}\n\nWe can also manipulate the axes of an existing array using\n\\li{np.swapaxes} and \\li{np.rollaxis}. Functions can also be applied\nacross one or more axes using \\li{np.apply_across_axis} or\n\\li{np.apply_across_axes}. The function \\li{np.unique} will return the\nsorted unique elements of the input array. There are also methods for\nconstructing arrays from individual subarrays. While they may be useful,\nuse them very carefully as they can have a very negative impact on\nperformance. Functions like \\li{np.hstack} and \\li{np.vstack} will\nhorizontally or vertically stack the input arrays into a new NumPy\narray.\n\n\\end{comment}\n\n\\begin{problem} \nOperations that create completely new arrays are often slower than \noperations that create views because allocating an array can be time \nconsuming. \n\\begin{enumerate}\n\\item Create an $1000 \\times 1000$ array \\li{A} of random floating point values. \n\\item Compare the speed of the operations \\li{A.reshape(A.size)}\nand \\li{A.flatten()}. Note that we are calling the methods of the arrays. \nThey are the same as \\li{np.reshape(A, A.size)}, and \\li{np.flatten(A)}\nrespectively. \n\\item Why is there such a difference in speed? \n\\end{enumerate}\n\\end{problem}\n\n\\begin{problem} \nOne good application of array slicing is the Jacobi\nmethod for solving Laplace's equation, which is used to model\nsteady-state heat flow on a square. This is an example of a simple\niterative method. In this case we will modify our array in place. \n\\begin{enumerate}\n\\item Make a function that accepts an array and a tolerance as input and does the\nfollowing: \n\\item Make a copy of the array. \n\\item Create a variable to track the difference between the arrays. Initialize\nit as the tolerance parameter your function accepts. \n\\item While the difference is greater than or equal\nto the tolerance \n\\begin{enumerate} \n\\item set all points that are not on an edge of the new array equal to the average of their 4 immediate neighbors. Use the values from the old array for this computation. \nThis should only take one line and should be based entirely on array slicing, NOT iterating through the array.\n(Hint: given a 2D array \\li{A}, the slice \\li{A[1:-1,1:-1]} references\nall non-edge entries, \\li{A[:-2,1:-1]} references the upper neighbors,\nand \\li{A[1:-1,2:]} references the right neighbors.) \n\\item update the difference to be the maximum of the absolute value of the new array\nminus the old one. \n\\item copy the values from the new array into the old\none (without creating a new array). \n\\end{enumerate} \n\\end{enumerate}\n\nNow use the following code to generate a plot of your results\n\\lstinputlisting[style=fromfile]{laplace_plot.py} \nIt should resemble the following figure.\n\n\\begin{figure} [H]\n\\includegraphics[width=.75\\textwidth]{laplace.pdf}\n\\end{figure} \n\\end{problem}\n\n\\section*{Logical Operations} \nLogical operations return arrays of only true or false values. \nThese arrays are often useful in masking values in other arrays. \n\n\\begin{lstlisting}\n>>> a = np.random.rand(5,5) \n>>> a<.5\narray([[False,  True,  True, False, False],\n       [False,  True,  True, False,  True],\n       [ True,  True,  True,  True,  True],\n       [False,  True,  True, False, False],\n       [ True,  True, False, False, False]], dtype=bool)\n>>> a[a<.5]\narray([ 0.30726555,  0.45395769,  0.05825412,  0.04896835,  0.02053107,\n        0.33587884,  0.14637301,  0.2109408 ,  0.13908897,  0.12292625,\n        0.24329939,  0.053114  ,  0.40227096,  0.21899495])\n>>> a[a<.3] = 0 \n>>> a\narray([[ 0.90428049,  0.30726555,  0.45395769,  0.99935736,  0.96856189],\n       [ 0.69711146,  0.        ,  0.        ,  0.88489964,  0.        ],\n       [ 0.33587884,  0.        ,  0.        ,  0.        ,  0.        ],\n       [ 0.75447365,  0.        ,  0.        ,  0.58333895,  0.67131309],\n       [ 0.40227096,  0.        ,  0.60919998,  0.94026012,  0.52745694]])\n\\end{lstlisting} \nAll the comparison operators can be used like this when working with arrays. \nWe can quickly test if \\emph{all} elements of a given axis\nevaluate to true with \\li{np.all}.  \nLikewise, we can test if \\emph{any} element evaluates to true with \n\\li{np.any}. \n\nMost floating point numbers cannot be represented perfectly \nas a binary fraction and are thus an approximation when stored. \nConsider the following example where \\li{x_1, x_2, x_3} are all \nincreasingly better approximations of 1/3, but no matter how\nmany more digits you're willing to append, the value will never be \nexactly 1/3. \n\\begin{lstlisting}\n>>> x_1 = .333\n>>> x_2 = .33333\n>>> x_3 = .3333333 \n>>> x_1 == x_2\nFalse\n>>> x_2 == x_3\nFalse\n\\end{lstlisting}\nIt is almost impossible to accurately test the equality\nof elements within two arrays. NumPy provides a special function,\n\\li{np.allclose}, to check if two arrays are \\emph{almost} the same (or\nwithin some specified tolerances). \n\\begin {lstlisting}\n>>> np.allclose(x_1, x_2)\nFalse\n>>> np.allclose(x_1, x_2, .001)\nTrue\n>>> np.allclose(x_2, x_3)\nTrue\n>>> np.allclose(x_2, x_3, .000001)\nFalse\n\\end{lstlisting}\n\\emph{Please note that in some rare\ncases} \\li{np.allclose(a, b)} \\emph{will not match} \\li{np.allclose(b,\na)}. This is because the equation the function uses for checking\ncloseness is not symmetric ($\\abs{a-b} \\leq \\mbox{atol} +\n\\mbox{rtol}*\\abs{b}$). \n\n\\begin{comment}\n\nNumPy also allows bitwise operations on arrays\nusing the standard Python bitwise operators: \\li{&}, \\li{|}, and \\li{^},\nas well as \\li{&=}, \\li{|=}, and \\li{^=}.\n\n\\end{comment}\nPlease also remember that the features, operations, and functions\ndiscussed in these labs are \\emph{not} an exhaustive list\nof what is included in NumPy. Always refer to the official\ndocumentation found at \\url{http://docs.scipy.org/doc/}\n\n\\section*{Methods of NumPy Arrays} \nAs we have just mentioned, there are\nmany different functions included in NumPy that can manipulate arrays. Some of the most useful functions are also included as\nmethods of array objects. Methods are functions that are \nattached to a particular object. Table \\ref{ndarraymethods} displays some of \nthe more common methods of NumPy arrays. A more comprehensive list can be found at\n\\url{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.\nhtml}\n\n\\begin{table}\n\\centering \n\\begin{tabular}{l|p{10cm}}\n    \\hline\n    Function & Description \\\\\n    \\hline\n    \\li{all} & returns True if all elements evaluate to True \\\\\n    \\li{any} & returns True if any elements evaluate to True \\\\\n    \\li{argmax} & indices of maximum value(s) \\\\\n    \\li{argmin} & indices of minimum value(s) \\\\\n    \\li{argsort} & indices that would sort the array \\\\\n    \\li{astype} & casts a copy of an array to a different data type \\\\\n    \\li{clip} & restrict values in an array to fit within a given range\\\\\n    \\li{conj} & return the complex conjugate of the array \\\\\n    \\li{copy} & return a copy of the array\\\\\n    \\li{diagonal} & return a given diagonal of the array \\\\\n    \\li{dot} & matrix multiplication \\\\\n    \\li{max} & max element of the array \\\\\n    \\li{mean} & average of the array \\\\\n    \\li{min} & minimum element of the array \\\\\n    \\li{prod} & product of elements of the array \\\\\n    \\li{ravel} & make a flattened version of an array, return a view if\n    possible \\\\\n    \\li{reshape} & return a view of the array with a changed shape \\\\\n    \\li{round} & return a rounded version of the array \\\\\n    \\li{sort} & sort the array in place \\\\\n    \\li{std} & compute the standard deviation \\\\\n    \\li{sum} & sum the elements of the array \\\\\n    \\li{swapaxes} & return a view with the given axes swapped \\\\\n    \\li{tolist} & return the array represented as a list or nested list\\\\\n    \\li{trace} & return the sum of the elements along the main diagonal\\\\\n    \\li{var} & return the variance of the array \\\\\n    \\hline\n    \\end{tabular} \\caption{A few of the methods of NumPy arrays.}\n    \\label{ndarraymethods} \\end{table}\n\nWe previously mentioned a zero axis in reference to the rows of a matrix\nand a first axis in reference to the columns of a matrix. It would \nperhaps be best to think about operating on the zero axis as iterating\nthrough the rows to acquire information from the columns. A similar process\ncan be used to think about operating on the first axis. \nMany of these methods we've discussed allow the user to specify an axis \nalong which to operate. For example, \\li{A.mean(axis=0)} computes the average\nby iterating through each row to compute the mean along each column. \n\nHere are a few examples of how to use these methods.\n\\begin{lstlisting}\n# Create a 4x4 array of random integers in [0, 10). \n>>> A = randint(0, 10, (4,4)) \n>>> A\narray([[3, 9, 6, 3],\n       [5, 1, 9, 1],\n       [6, 5, 4, 8],\n       [1, 8, 2, 7]])\n# Iterate through each row and acquire the max of each column.\n>>> A.max(axis=0) \narray([6, 9, 9, 8])\n# Iterate through each column and take the sum of each row.\n>>> A.sum(axis=1)\narray([21, 16, 23, 18])\n\\end{lstlisting}\n\n\\begin{problem}\n% There should be more problems like this in the vectorization lab. I'll\n% include this one here for now though.\nWrite a function which, given an integer $n$, makes an $n\\times n$ array\nof random normally distributed floating point values, computes the mean\n(iterate along each column to compute the mean from each row), \nthen computes the variance of these means. The\ncomputation of the variance should only take one line. \nAs you increase the value of n, what do you notice about the output of \nthe function? This illustrates one version of\nthe Law of Large Numbers, about which you will learn more later on.\n\\end{problem}\n\n\\begin{comment}\n\\section*{Saving Arrays} It is often useful to save an array as a file.\nNumPy provides several easy methods for saving and loading array data.\n\n\\begin{table*}\n\\begin{tabular}{l|l}\n\\hline\n\\li{np.save(file, arr)} & Save an array to a binary file \\\\\n\\li{np.savez(file, *arrs)} & Save multiple arrays to a binary file \\\\\n\\li{np.savetxt(file, arr)} & Save an array to a text file \\\\\n\\hline\n\\end{tabular}\n\\end{table*}\n\n\\begin{table*}\n\\begin{tabular}{l|l}\n\\hline\n\\li{np.load(file)} & Load and return an array from a binary file \\\\\n\\li{np.loadtxt(file)} & Load and return an array from text file \\\\\n\\hline\n\\end{tabular}\n\\end{table*}\n\nLet's practice saving an array to a file and loading it again.\nNote that, when saving an array, NumPy automatically appends the extension \\li{.npy} if it is not already present.\n\\begin{lstlisting}\na = np.arange(30)\nnp.save('test_arr', a)\nnew_a = np.load('test_arr.npy')\nnp.savez('test_multi', a=a, new_a=new_a)\narrs = np.load('test_multi.npz')\n\\end{lstlisting}\nThe variable \\li{arrs} points to a dictionary object with the keys \\li{a} and \\li{new_a} which reference the arrays that have been saved.\nThe \\li{.npz} file extension is the file type used to store multiple arrays.\n\\end{comment}\n\n% \\lab{Python}{NumPy and SciPy}{NumPy and SciPy}\n\\section*{NumPy and SciPy}\n%\\objective{Learn some other features available in NumPy and SciPy.}\n%\\label{lab:NumPySciPy}\nNumerical Python (NumPy) and Scientific Python (SciPy) are packages found\nwithin Python used for scientific computing in mathematics, science, and\nengineering. They contain sophisticated (broadcasting) functions,\ntools for integrating C/C++ and Fortran code, linear algebra, \nFourier transform, random number capabilities, matplotlib, IPython,\nsympy, and pandas.\n\n\\begin{comment}\n\n\\section*{Logic Operations}\nLogic operations return arrays of only true or false values depending on whether they satisfy a given condition.\nThese arrays are often useful for masking values in other arrays.\n\\begin{lstlisting}\n>>> a = np.random.rand(5,5)\n>>> a<.5\narray([[ True, False, False,  True, False],\n       [ True,  True, False,  True, False],\n       [False,  True,  True, False, False],\n       [False, False,  True, False,  True],\n       [ True, False, False,  True, False]], dtype=bool)\n>>> a[a<.5]\narray([ 0.46121936,  0.11294639,  0.37868745,  0.23435659,  0.25898226,\n        0.09095808,  0.19124312,  0.41124911,  0.09823221,  0.03739077,\n        0.08655778])\n>>> a[a<.3] = 0\n>>> a\narray([[ 0.46121936,  0.83080909,  0.5632045 ,  0.        ,  0.59581868],\n       [ 0.37868745,  0.        ,  0.54977124,  0.        ,  0.753893  ],\n       [ 0.79744663,  0.        ,  0.        ,  0.57981239,  0.95839037],\n       [ 0.66512744,  0.63471169,  0.41124911,  0.6466058 ,  0.        ],\n       [ 0.        ,  0.50692736,  0.54082953,  0.        ,  0.5173614 ]])\n\\end{lstlisting}\nThe comparison operators can all be used like this with arrays.\nWe can quickly test if all elements of a given axis evaluate to true with \\li{np.all}.  Likewise, we can test if any element evaluates to true with \\li{np.any}.\nBecause of the nature of floating point numbers, it is next to impossible to accurately test the equality of elements of two arrays.\nNumPy provides a special function, \\li{np.allclose}, to check if two arrays are \\emph{almost} the same (or within some specified tolerances).\n\\emph{Please note that in some rare cases \\li{np.allclose(a, b)} will not match \\li{np.allclose(b, a)}.}  This is because the equation the function uses for checking closeness is not symmetric ($\\abs{a-b} \\leq \\mbox{atol} + \\mbox{rtol}*\\abs{b}$).\n\\begin{lstlisting}\n>>> a = np.ones((5, 5))\n>>> np.allclose(a, a+1e-5)\nTrue\n>>> np.allclose(a, a+1e-4)\nFalse\n\\end{lstlisting}\n\nNumPy also allows bitwise operations on arrays using the standard Python bitwise operators: \\li{&}, \\li{|}, and \\li{^}.\nThey are also available as NumPy functions: \\li{np.bitwise_and}, \\li{np.bitwise_or}, and \\li{np.bitwise_xor} respectively.\nNumPy makes available logical, or boolean, operators as well: \\li{np.logical_and}, \\li{np.logical_or}, and \\li{np.logical_xor}.\nThese are analogous to Pythons logical operators: \\li{and}, \\li{or}.\nThe difference between bitwise and logical operators is simple.\nBitwise operators compare operands using their bit representations.\nLogical operators compare operands using their boolean values.\n\n\\end{comment}\n\n\\section*{Broadcasting Array Dimensions}\nMost array operations require array sizes to be compatible.\nFor example, two arrays can only be added together if they are the same shape.\nArray broadcasting allows NumPy to work effectively with arrays of sizes \nthat don't match exactly. This can be useful in a host of different \nsituations and often saves both time and memory. There are four basic rules \nto determine the behavior of broadcasted arrays:\n\\begin{enumerate}\n\\item All input arrays of lesser dimension than the input array with the\nlargest dimension have 1's prepended to their shapes.\n\\item The size in each dimension of the output shape is the maximum of all \nthe input sizes in that dimension.\n\\item An input can be used in the calculation if its size in a particular \ndimension either matches the output size in that dimension or has a size \nof exactly 1.\n\\item If an input has a dimension size of 1 in its shape, the first data \nentry in that dimension will be used for all calculations along that \ndimension.\n\\end{enumerate}\n\nOne simple example is multiplying a two dimensional array by a set of numbers \nalong its rows or columns. \n\n\\begin{lstlisting}\n>>> A = np.ones((3, 3))\n>>> B = np.vstack([1, 2, 3])\n# Multiply the rows of A by each entry of B.\n>>> A * B\narray([[ 1.,  1.,  1.],\n       [ 2.,  2.,  2.],\n       [ 3.,  3.,  3.]])\n# Multiply the columns of A by each entry of B. Note the use of the transpose.\n>>> A * B.T \narray([[ 1.,  2.,  3.],\n       [ 1.,  2.,  3.],\n       [ 1.,  2.,  3.]])\n>>> A = np.array([1, 2, 3]).reshape((3,1))\n>>> B = np.array([1, 2])\n>>> A + B\narray([[2, 3],\n       [3, 4],\n       [4, 5]])\n>>> A = np.arange(3)\n>>> B = np.arange(3, 6)\n# np.newaxis can be used to add a new axis (a new dimension of size 1) \n# and to affect broadcasting\n>>> A[np.newaxis,:] * B[:,np.newaxis] \narray([[ 0,  3,  6],\n       [ 0,  4,  8],\n       [ 0,  5, 10]])\n\\end{lstlisting}\n\nIt is important to note that broadcasting does not explicitly construct the \nlarger array. In fact, internally, broadcasting uses no extra memory. However, \nyou should still be careful when broadcasting large arrays because you can fill the \nRAM on your computer, which can sometimes freeze the system completely.\nFor a more detailed description of array broadcasting rules, see \n\\url{http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html}.\n\n\\begin{problem}\nCreate a $100\\times100\\times3$ array of integers taking values in the range \n[0, 256]. Such an array can represent an RGB image of $100\\times100$ pixels, \nwhere each pixel is associated with an array of three integers indicating the \namounts of red, green, and blue color present in that pixel, respectively.\nUse array broadcasting to multiply the red and green values by $0.5$. \n(Such an operation would tone down the red and green colors and make the \nimage appear more blue.) \n\\end{problem}\n\n\\section*{Universal Functions}\nNumPy and SciPy include a wide variety of functions that are designed to \noperate on arrays. Such functions, which take in an array and return an array \nof the same size and datatype, are called \\emph{universal functions}, or \n\\texttt{ufuncs}. To illustrate this point, consider the universal function \n\\li{numpy.sin} and the standard function \\li{math.sin}. If $A$ is an array \nof floats (of any size), \\li{math.sin(A)} throws an error, whereas \n\\li{numpy.sin(A)} returns an array of floats containing the sines of the \nentries of $A$. Other simple examples from NumPy include \\li{cos}, \\li{sqrt}, \n\\li{exp}, and \\li{log} all the way to special functions like \\li{polygamma} \nin the \\li{scipy.misc} submodule. There are far more functions available in \nNumPy than could possibly be included here, so become \nfamiliar with the NumPy and SciPy documentation at \\url{docs.scipy.org/doc/}.\nIf you need to do any sort of simple operation on the individual elements of an array, \nyou can usually find a universal function to do so. These functions are almost always \nfaster and more convenient than iterating through the entire array.\n\nMost of these functions also allow you to specify an array for the output.\nThis can be useful to avoid unnecessary memory allocation. The output array does need to be the correct shape \nto store the output.\nFor example:\n\n\\begin{lstlisting}\n>>> A = np.array([0., 1., np.exp(1)])\n# Take exp(A) and store the result in A.\n>>> np.exp(A, out=A) \n>>> A\narray([  1.        ,   2.71828183,  15.15426224])\n\\end{lstlisting}\n\n\\begin{comment}\nOther useful examples are \\li{max}, \\li{min}, \\li{absolute}, and \\li{average}.\nEach of these operations also allows you to specify whether you want to \noperate across a particular axis or over the entire array.\nFor example:\n\nThe above example returns a row of A which represents the maximum of all the \nrows of A. If we had set \\li{axis=1}, it would have taken the maximum of all \nthe columns. If, for purposes of broadcasting (discussed later) you need the \noutput of one of these functions to have the same number of dimensions as the \noriginal array, you can also include the argument \\li{keepdims=True}.\n\n\\end{comment}\n\nUniversal functions are designed to apply elementwise operations on each \nelement of an array. Accordingly, there can be significant overhead \nwhen using a \\texttt{ufunc} on a single value.\n\n\\begin{lstlisting}\n>>> timeit np.sin(.5)\n1000000 loops, best of 3: 1.37 mu\u00b5s per loop\n>>> timeit np.math.sin(.5)\n10000000 loops, best of 3: 144 ns per loop\n\\end{lstlisting}\n\nWe can see that performance increases when we know how to use a \n\\texttt{ufunc}. However, they should only be used on arrays as they are \nnot designed to handle single values efficiently.\n\n\\section*{Linear Algebra}\nAmong the most useful functions available in NumPy and SciPy are the \nlinear algebra functions. Even though NumPy has a linear algebra library, \nSciPy contains all the functions that NumPy has as well as a few more advanced \nfunctions. The linear algebra library is typically imported as\n\n\\begin{lstlisting}\nfrom scipy import linalg as la\n\\end{lstlisting}\n\n\\begin{comment}\nTo shorten the amount of typing, it can be aliased as \n\\li{from scipy import linalg as la}.\n\\end{comment}\n\nIt is important to note that there exists a \\li{matrix} class that is very \nsimilar to a NumPy array. The matrix class is convenient when doing matrix \noperations--it behaves much like MATLAB's matrix object.\nHowever, using the matrix class is generally discouraged because its benefits \nare relatively equivalent to that of the standard 2D NumPy array. \nAll other functions in NumPy and SciPy are written to take advantage \nof the features of the \\li{ndarray}. Therefore, future references to a matrix in these lab \nmanuals will refer to the mathematical object or an \\li{ndarray} (not the matrix class).\n\nThe linear algebra library contains several functions to construct special \nmatrices. These matrices are common in specific areas of interest.\nThe functions for constructing these special matrices are located in \n\\li{linalg.special_matrices}. Linear algebra functions available in SciPy \nare very feature rich. There are functions that will find inverses, \ndeterminants, norms, and solutions to linear systems; solve least squares \nproblems; and decompose matrices.\n\nA least squares solution can be found with \\li{la.lstsq}.\nWe can use \\li{la.solve} to solve linear systems.  \n\\li{la.det} will return the determinant of a matrix and \n\\li{la.inv} will find the inverse of a matrix.\n\nYou can read more about the linear algebra capabilities of SciPy in the \ndocumentation for the \\li{linalg} module found at\n(\\url{http://docs.scipy.org/doc/scipy/reference/linalg.html}).\n\n\\begin{comment}\n\\begin{problem}\nBlock ciphers are ciphers that encode blocks of input symbols at a time \ninstead of one symbol at a time. In the days before computers, the Hill \ncipher was the first cipher that allowed practical encoding of more than \nthree symbols at a time. It was invented by Lester Hill in 1929.\nThe Hill cipher is considered a classical substitution cipher.\nThe entire cipher is based on linear algebra and uses a matrix key.\nAll substitution ciphers work with the 26 letters.\nThus, all our operations will be done mod 26 (modulo 26).\nTo do this, we introduce you to the \\li{\\%} operator in Python.\nThis new operator allows us to do modular arithmetic.\nWhen applied to an array it takes the elementwise mod.\n\nThis problem has a number of parts.  You will write a function that \naccepts \\emph{plaintext} and returns the encoded \\emph{ciphertext}.\nYou will also write a decoder that will accept ciphertext and return \nplaintext.\n\nThe Encoder: \\begin{enumerate}\n\\item We must first gather the plaintext to encode and a block size, $n$.\nWe must split this plaintext into blocks removing any spaces.  We need to \nconvert each character to a number. We use the index of \\li{string.lowercase} \n(found in the \\li{string} module of the Python standard library).\nWe can easily build a lookup table that will let you easily find the index.\nWith a lookup table, we map each letter to its index.\n\n\\begin{lstlisting}\nfrom string import lowercase\nlut = {a:i for i, a in enumerate(lowercase)}\ns = \"this is a message\"\ns = \"\".join(s.split()) #remove all whitespace\nmap(lut.__getitem__, s) #return a list of indices\n[19, 7, 8, 18, 8, 18, 0, 12, 4, 18, 18, 0, 6, 4]\n\\end{lstlisting}\n\nAnother way is to use \\li{lowercase.index()} in a loop to find the index \neach time.\n% \\begin{lstlisting}\n% >>> indices = []\n% >>> for letter in s:\n%         indices.append(lowercase.index(letter))\n% \\end{lstlisting}\nWe need to split the list of indices into $n$-length arrays and store them \nin a list. If the input is not a multiple of $n$, you will need to pad the \ninput until it is a multiple of $n$. Pick any character to pad the input \n(typically it is a rarely used letter). The \\li{itertools} module is useful \nfor this.  One of the common recipes for doing this task is available in \nthe \\li{itertools} documentation.\n\n\\begin{lstlisting}\ndef grouper(iterable, n, fillvalue=None):\n    \"Collect data into fixed-length chunks or blocks\"\n    # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx\n    args = [iter(iterable)] * n\n    return itertools.izip_longest(fillvalue=fillvalue, *args)\n\\end{lstlisting}\n\nIt will be useful to wrap all of this step in a separate function as we will \nneed to do the same thing when decoding (except for removing whitespace).\n\n\\item Find a suitable cipher key.  The keys of a Hill cipher are square \nmatrices.  Let $K$, be our key. $K$ must be invertible mod 26.\nRemember from linear algebra, that the determinant of square matrix will \ntell you if that matrix is invertible. To find a matrix that is invertible \nmod 26, we need to find a matrix with a determinant that is relatively prime \nto 26 (they share no common factors). The Euclidean algorithm can be used to \ndetermine if two numbers are co-prime (i.e. $\\gcd(d, 26) = 1$). Write a \nfunction that generate random integer matrices using NumPy, checking the \ndeterminant, and returns a suitable key, $K$.\n\n\\item Write a function that will accept a message and a key matrix.\nThe message should already be broken into $n$ length blocks (you can do this \ninside the encode function if needed) and the matrix should be $n \\times n$.\nA Hill cipher is the dot product of the block with the key.  Return a \nciphertext that is letters (the numbers correspond the indices in \n\\li{string.lower}).\n\n\\item Write a function that will compute $K^{-1} \\pmod{26}$.  This will \nnecessarily be an integer inverse.\nUse \\li{linalg.inv} to find the inverse of $K$.\nThen \\[K^{-1} = \\det(K)K^{-1}\\det(K)^{-1}  \\pmod{26}\\] where $\\det(K)^{-1}$ \nis the inverse of the determinant mod 26.\nYou will need to round the determinant to the nearest integer before doing \nthese steps.  You will also need to round the results of each of your \nmultiplications.\nYou can check that you have the integer inverse by checking $KK^{-1} = I$.\n\n\\item Write a function that will decode a message given a ciphertext and the \nkey. You will need to invert the key before decoding.  Break the message into \nblocks of size $n$ and calculate the dot product of each block with the \ninverted key. Return a plaintext that is letters (the numbers, again, \ncorrespond to indices in \\li{string.lower}).\n\\end{enumerate}\n\nExperiment with your Hill cipher.  If you are in a classroom setting, try \nsending encoded messages to friends (they will need the key you used to \nencode).\n\\end{problem}\n\\end{comment}\n\n\\section*{Polynomials}\nMany other useful functions are available in NumPy.  One of particular \ninterest is the polynomial array. This is a convenience object that \nrepresents the coefficients of a polynomial. One good way of representing \na polynomial in NumPy is the \\li{np.poly1d} object, which represents the \npolynomial coefficients as a 1D array. \n\n\\begin{lstlisting}\n>>> a = np.poly1d([3, 5, 1, 2, 0, 1])\n>>> print a\n   5     4     3     2\n3 x + 5 x + 1 x + 2 x + 1\n\\end{lstlisting}\n\nThis particular object represents the polynomial $3x^5+5x^4+x^3+2x^2+1$.\nWhen representing a polynomial as an array of coefficients, NumPy \nprovides special methods to treat them as polynomials (see Table \\ref{poly1dmethods}.)\n\n\\begin{table}\n\\centering\n\\begin{tabular}{l|l}\nFunction & Description \\\\\n\\hline\n\\li{np.polyadd} & Add two polynomial arrays \\\\\n\\li{np.polyder} & Find the derivative of a polynomial array \\\\\n\\li{np.polydiv} & Divide two polynomial arrays \\\\\n\\li{np.polyfit} & Find a least squares polynomial fit \\\\\n\\li{np.polyint} & Find the integral of a polynomial array \\\\\n\\li{np.polymul} & Multiply two polynomial arrays \\\\\n\\li{np.polysub} & Subtract two polynomial arrays \\\\\n\\li{np.polyval} & Evaluate a polynomial at specific points\n\\end{tabular} \\caption{A few methods of NumPy polynomial arrays.}\n\\label{poly1dmethods}\\end{table}\n\nThese polynomial objects make evaluating series approximations to functions very easy.\nFor example, you are probably familiar with the fact that\n\\[\ne^x = \\sum_{n=0}^{\\infty} \\frac{x^n}{n!}\n\\]\nThis series can be evaluated easily as follows:\n\n\\lstinputlisting[style=fromfile]{exp.py}\n\\begin{comment}\n\\begin{lstlisting}\nfrom scipy.misc import factorial\nn = 18 # number of terms\np = 1. / factorial(np.arange(18, -1, -1)) # compute coefficients\nX = np.random.rand(10000) # where to evaluate the series\nP = np.poly1d(p) # make polynomial object\nP(X)\n\\end{lstlisting}\n\\end{comment}\nThe last two lines can be condensed by using\n\n\\begin{lstlisting}\nnp.polyval(p, X)\n\\end{lstlisting}\n\n\\begin{problem}\n\\begin{enumerate}[a)]\n\\item Use the NumPy's polynomial objects to approximate the following series.\n\\[\n\\arcsin x = \\sum_{n=0}^{\\infty} \\frac{\\left(2 n\\right) ! x^{2 n + 1}}{\\left(2 n + 1\\right)\\left(n!\\right)^2 4^n}\n\\]\nUse your approximation to find a close approximation of $\\pi$. Hint: think of the powers of $x$ that\nare not included in the series as having zero coefficients.\n\n\\item The lambert W function is the inverse of $x e^x$.\nIt's taylor series is\n\\[\nW(x) = \\sum_{n=1}^{\\infty} \\frac{\\left(-n\\right)^{n-1} x^n}{n!}\n\\]\nThis series has a radius of convergence of $\\frac{1}{e}$.\nUse the series to find a number $x$ such that $x e^x = \\frac{1}{4}$.\nVerify that your computation is correct.\n\n(Note: Be careful with your indices; check to see where each taylor series begins!)\n\\end{enumerate}\n\\end{problem}\n\n\\begin{comment}\n\\section*{Useful Functions}\nThe following table contains a list of useful NumPy functions. \nFor more information please refer to the NumPy documentation.\n\\begin{table}\n\\centering\n\\begin{tabular}{l|l}\nFunction & Description \\\\\n\\hline\n\\li{np.intersect1d} & Return the intersection of two flattened arrays. \\\\\n\\li{np.union} & Return the union of two flattened arrays. \\\\\n\\li{np.diff} & Calculates a discrete difference of order $n$. \\\\\n\\li{np.absolute} & Return the elementwise absolute value of an array. \\\\\n\\li{np.pad} & \\\\\n\\li{np.nonzero} & \\\\\n\\li{np.count_nonzero} & \\\\\n\\li{np.select} & \\\\\n\\li{np.nan} & Represent IEEE NAN (not-a-number). \\\\\n\\li{np.inf} & Represent IEEE INF (infinity). \\\\\n\\li{np.who} & Print information about defined NumPy arrays in a variable scope. \\\\\n\\li{np.unique} & Return a sorted array of unique elements of an array. \\\\\n\\end{tabular} \n\\end{table}\n\\end{comment}\n\n\\section*{Specifications}\nWe suggest that you submit your \\li{solutions.py} file using the following format.\n\\begin{lstlisting}\nimport math\nimport timeit\nimport string\nimport itertools\nimport numpy as np\nfrom fractions import gcd\nfrom numpy.random import randn\nfrom scipy import linalg as la\nfrom scipy.misc import factorial\nfrom matplotlib import pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\n\n# Problem 1\n\ndef arr_mult(A,B):\n    new = []\n    for i in range(len(A)):\n        newrow = []\n        for k in range(len(B[0])):\n            tot = 0\n            for j in range(len(B)):\n                tot += A[i][j] * B[j][k]\n            newrow.append(tot)\n        new.append(newrow)\n    return new\n    \ndef timefunction(f, *args, **kwargs):\n\tpfunc = lambda: f(*args, **kwargs)\n\tprint min(timeit.repeat(pfunc, number = 1, repeat = 1))\n\ndef problem1():\n\tprint \"LIST: k = 100: <time>\"\n\tprint \"LIST: k = 200: <time>\"\n\tprint \"LIST: k = 300: <time>\"\n\tprint \"ARRAY: k = 100: <time>\"\n\tprint \"ARRAY: k = 200: <time>\"\n\tprint \"ARRAY: k = 300: <time>\"\n\t\n'''\nResponse to question\n'''\n\n# Problem 2\n\ndef problem2():\n    print \"A.reshape(A.size) had a best time of <time>\"\n    print \"A.flatten() had a best time of <time>\"\n    print \"A.reshape((1, A.size)) had a best time of <time>\"\n    \n'''\nResponse to question\n'''\n\n# Problem 3\n\ndef laplace(U, tol):\n\tpass\n        \nn = 100\ntol = .0001\t\nU = np.ones((n, n ))\nU [:,0] = 100 # set north boundary condition\nU [:,-1] = 100 # set south boundary condition\nU [0] = 0 # set west boundary condition\nU [-1] = 0 # set east boundary condition\n# U has been changed in place.\nlaplace(U, tol) \nx = np.linspace (0, 1, n)\ny = np.linspace (0, 1, n)\nX, Y = np.meshgrid (x, y)\nfig = plt.figure()\nax = fig.gca( projection = '3d')\nax.plot_surface (X, Y, U, rstride=5)\nplt.show()\n\n# Problem 4\n\ndef problem4(n):\n\treturn var\n\t\n'''\nResponse to question\n'''\n\n# Problem 5\n\n# [red, green, blue]\ndef problem 5():\n\tpass\n\n# Problem 6\n\ndef arcsin_approx():\n\treturn sol\n\ndef W_approx():\n\treturn sol\n\n\\end{lstlisting}\n\n", "meta": {"hexsha": "b6e44553032f4c5d90c2cb81fc31fffe9a337ec2", "size": 59595, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/Arrays/Arrays.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Python/Arrays/Arrays.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Python/Arrays/Arrays.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.6791808874, "max_line_length": 285, "alphanum_fraction": 0.6990687138, "num_tokens": 17884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325346, "lm_q2_score": 0.9416541528387691, "lm_q1q2_score": 0.8022448798375842}}
{"text": "\\paragraph{\\underline{Conf. intervals for the mean}}\n$\\mu$ \\hspace{0pt} \\newline\nConf. interval: $ \\left( \\mean - k, \\mean + k \\right) $\n\n\\vspace{5pt} \\noindent \\textbf{\\em Model 1}:\n$X$ i.i.d. $\\distnormal(\\mu, \\sigma)$, known $\\sigma$\n\\[ k = z_{1-\\alpha/2}\\frac{\\sigma}{\\sqrt{n}} \\]\n\n\\noindent \\textbf{\\em Model 2}:\n$X$ i.i.d. $\\distnormal(\\mu, \\sigma)$, $\\sigma=?$\n\\[ k = \\diststudentt^{[n-1]}_{1-\\alpha/2}\\frac{s_X}{\\sqrt{n}} \\]\n\n\\noindent \\textbf{\\em Model 3}:\n$X$ i.i.d. ?, large $n$\n\\[ k = z_{1-\\alpha/2}\\frac{s_X}{\\sqrt{n}} \\]\n\n\\paragraph{\\underline{Conf. intervals for variance}}\n$\\sigma^2$ \\hspace{0pt} \\newline\nor $\\var X$ are, in case of first 2 models, defined as:\n\\[ \\left( f(1-\\alpha/2), f(\\alpha/2) \\right) \\]\nand $f(k)$ is defined for each. The third model has its own definition.\n\n\\vspace{5pt} \\noindent \\textbf{\\em Model 1}:\n$X$ i.i.d. $\\distnormal(\\mu, \\sigma)$, known $\\mu$\n\\[ f(k) = \\frac{n\\tilde{s}_X^2}{\\distchisquare_{k,n}} \\]\n\n\\noindent \\textbf{\\em Model 2}:\n$X$ i.i.d. $\\distnormal(\\mu, \\sigma)$, $\\mu=?$\n\\[ f(k) = \\frac{(n-1)\\tilde{s}_X^2}{\\distchisquare_{k,n-1}} \\]\n\n\\noindent \\textbf{\\em Model 3}:\n$X$ i.i.d. ?, large $n$,\n\nConf. interval: $ \\left( f(-1) , f(1) \\right) $\n\\[ f(k) = \\frac{(2n-2)\\tilde{s}_X^2}{\\sqrt{2n-3} + (k)z_{1-\\alpha/2}} \\]\n\n\\paragraph{\\underline{Conf. interval for proportion}}\n$p$ \\hspace{0pt} \\newline\ni.e. probability of success.\n\n\\vspace{5pt} \\noindent \\textbf{\\em Model 1}:\n$X$ i.i.d. $\\distbernoulli(p)$, large $n$\n\nConf. interval: $ \\left( \\hat{p}-l , \\hat{p}+l \\right) $\n\\[ \\hat{p} = \\frac{1}{n} \\sum_{i=1}^n X_i \\mbox{ and }\nl = z_{1-\\frac{\\alpha}{2}}\\sqrt{\\frac{\\hat{p}(1-\\hat{p})}{n}} \\]\n", "meta": {"hexsha": "96db392a9175b5e3cd70da89e6359fdbbb16a94b", "size": 1651, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_5b_estim_interval_example.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_5b_estim_interval_example.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_5b_estim_interval_example.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.1276595745, "max_line_length": 72, "alphanum_fraction": 0.5941853422, "num_tokens": 684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191335436405, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.8022139244879999}}
{"text": "\\section{Exponential and Logarithmic Functions}\nIn the previous section we dealt with functions composed of integer powers of $x$. We will now shortly focus on functions where $x$ is in the power itself and their inverse functions.\n\nAn \\emph{exponential function}, or simply an \\emph{exponential}, is a real function of the type\n\\begin{equation}\n\tf(x) = b^{x},\n\t\\label{eq:exponent}\n\\end{equation}\nwhere $b>0$ is called the \\emph{base} of the exponentiation, and $x$ the exponential. All exponents, regardless of base, are always positive. In addition, all exponents pass through the point $(0,1)$ since $b^{0}=1$ for any real positive number, and through the point $(1,b)$ since $b^{1}=b$. When $b>1$ the function is increasing on $\\mathbb{R}$, while for $b<1$ the function is descending on $\\mathbb{R}$.\n\n\\begin{example}{Exponential functions}{exponents}\n\tThe following are graphs of the exponential functions \\textcolor{xred}{$\\bm{1.5^{x}}$}, \\textcolor{xblue}{$\\bm{2^{x}}$} and \\textcolor{xgreen}{$\\bm{3.5^{x}}$}:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tgraph2d,\n\t\t\t\t\ty axis line style={-stealth, thick},\n\t\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\t\txmin=-5, xmax=3,\n\t\t\t\t\tymin=0, ymax=4,\n\t\t\t\t\tdomain=-5:3,\n\t\t\t\t\trestrict y to domain=0:5,\n\t\t\t\t]\n\t\t\t\t\\addplot[function, xred] {(1.5)^\\x};\n\t\t\t\t\\addplot[function, xblue] {2^\\x};\n\t\t\t\t\\addplot[function, xgreen] {3.5^\\x};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\n\tAnd the following are graphs of the exponential functions \\textcolor{xpurple}{$\\bm{0.7^{x}}$}, \\textcolor{xorange}{$\\bm{0.5^{x}}$} and $\\bm{0.2^{x}}$:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tgraph2d,\n\t\t\t\t\ty axis line style={-stealth, thick},\n\t\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\t\txmin=-5, xmax=3,\n\t\t\t\t\tymin=0, ymax=4,\n\t\t\t\t\tdomain=-5:3,\n\t\t\t\t\trestrict y to domain=0:5,\n\t\t\t\t]\n\t\t\t\t\\addplot[function, xpurple] {0.7^\\x};\n\t\t\t\t\\addplot[function, xorange] {0.5^\\x};\n\t\t\t\t\\addplot[function, black] {0.2^\\x};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{example}\n\nAs a reminder, the following are two well known properties of exponents: given a base $b>0$,\n\\begin{align}\n\tb^{-x} &= \\frac{1}{b^{x}},\\\\\n\tb^{x}b^{y} &= b^{x+y}.\n\t\\label{eq:exponents_properties}\n\\end{align}\n\nA special base for exponential functions is the real, non-algebraic number $\\eu$. This number has many names, among them is \\emph{Euler's number}, but in the constant of exponentials it is known as the \\emph{natural base}. Its exact value is not entirely important for the moment: it is about $2.718$, and in any case it is not possible to write it as there it has infinitely many digits after the period. It is very common across different fields of mathematics and science to write $\\exp(x)$ instead of $\\eu^{x}$.\n\nThe inverse function to exponentials are the \\emph{logarithmic functions} (or simply \\emph{logarithms}), i.e.\\ for any real $b>0,\\ b\\neq1$,\n\\begin{equation}\n\t\\log_{b}\\left( b^{x} \\right) = b^{\\log_{b}(x)} = x.\n\t\\label{eq:logarithms}\n\\end{equation}\nIn essence, the logarithm in base $b$ of a number $x$ answers the question \\textit{``what is the number $a$ for which $b^{a}=x$?''}. Being the inverses of exponential functions, all logarithms go through the point $(1,0)$, and each also passes through its own point $(b,1)$.\n\n\\begin{example}{Logarithmic functions}{logarithms}\n\tThe following are graphs of the logarithmic functions \\textcolor{xred}{${\\log_{1.5}(x)}$}, \\textcolor{xblue}{${\\log_{2}(x)}$} and \\textcolor{xgreen}{${\\log_{3.5}(x)}$}:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tgraph2d,\n\t\t\t\t\tx axis line style={-stealth, thick},\n\t\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\t\txmin=0, xmax=4,\n\t\t\t\t\tymin=-5, ymax=3,\n\t\t\t\t\tdomain=0:4,\n\t\t\t\t\trestrict y to domain=-10:4,\n\t\t\t\t]\n\t\t\t\t\\addplot[function, xred] {ln(\\x)/ln(1.5)};\n\t\t\t\t\\addplot[function, xblue] {ln(\\x)/ln(2)};\n\t\t\t\t\\addplot[function, xgreen] {ln(\\x)/ln(3.5)};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\n\t...and the following are graphs of the exponential functions \\textcolor{xpurple}{$\\log_{0.75}(x)$}, \\textcolor{xorange}{$\\log_{0.5}(x)$} and $\\log_{0.2}(x)$:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tgraph2d,\n\t\t\t\t\tx axis line style={-stealth, thick},\n\t\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\t\txmin=0, xmax=4,\n\t\t\t\t\tymin=-3, ymax=5,\n\t\t\t\t\tdomain=0:4,\n\t\t\t\t\trestrict y to domain=-4:10,\n\t\t\t\t]\n\t\t\t\t\\addplot[function, xpurple] {ln(\\x)/ln(0.75)};\n\t\t\t\t\\addplot[function, xorange] {ln(\\x)/ln(0.5)};\n\t\t\t\t\\addplot[function, black] {ln(\\x)/ln(0.2)};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{example}\n\nA useful property of logarithms is that they can help reduce ranges spanning several orders of magnitude to numbers humans can deal with. The easiest way to see this is using $b=10$: $10^{1}=10$, and so $\\log_{10}(10)=1$. $10^{2}=100$, and so $\\log_{10}(100)=2$. $10^{3}=1000$, and so $\\log_{10}(1000)=3$, etc. The value of the logarithm goes by $1$ for each raise in order of magnitude of its argument.\n\nTherefore, if we have some measurement $x$ which can hold values spanning several orders of magnitude (say $x\\in[3,1500000000]$), then it can sometimes be useful to use instead the logarithmic value of $x$ (which in our case would span the range $\\log_{10}(x)\\in[0.477,9.176]$). This is done in many fields of science, for example some definitions of entropy\\footnote{$S=k_{\\text{B}}\\log\\left( \\Omega \\right)$}, acid dissociation constants\\footnote{$\\text{p}K_{a}=-\\log\\left( K_{\\text{diss}} \\right)$}, pH\\footnote{$\\text{pH}=-\\log\\left(\\ce{[H+]}\\right)$} and more.\n\n\\begin{example}{Logarithms as evaluating orders of magnitude}{}\n\tIn the following graph of $\\log_{2}(x)$, each increase by power of two in $x$ (i.e. $x=1,2,4,8,16,\\dots$) yields only a single increase in $y$ (i.e. $y=0,1,2,3,4,\\dots$). This shows how logarithms shift our perspective from absolute values to orders of magnitude.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tgraph2d,\n\t\t\t\t\tx axis line style={-stealth, thick},\n\t\t\t\t\twidth=10cm, height=8cm,\n\t\t\t\t\txmin=0, xmax=16,\n\t\t\t\t\tymin=-4, ymax=8,\n\t\t\t\t\tdomain=0:16,\n\t\t\t\t\trestrict y to domain=-7:10,\n\t\t\t\t\tgrid=major,\n\t\t\t\t\txtick={0,1,2,4,8,16},\n\t\t\t\t\tytick={-4,-3,...,8},\n\t\t\t\t]\n\t\t\t\t\\addplot[function, xpurple] {ln(\\x)/ln(2)};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{example}\n\nUsing the definition of the logarithmic function $\\log_{b}(x)$ (\\autoref{eq:logarithms}) and the product rule for exponentials (\\autoref{eq:exponents_properties}), a similar rule can be derived for logarithms. Let $x,y>0$ and $b>0,\\ b\\neq1$ all be real numbers. We define\n\\begin{equation}\n\t\\log_{b}(x)=M,\\ \\log_{b}(y)=N,\n\t\\label{eq:log_addition_rule_step1}\n\\end{equation}\nwhich means\n\\begin{equation}\n\tb^{M}=x,\\ b^{N}=y.\n\t\\label{eq:log_addition_rule_step2}\n\\end{equation}\nFrom \\autoref{eq:exponents_properties} we know that\n\\begin{equation}\n\txy = b^{M}b^{N} = b^{M+N},\n\t\\label{eq:log_addition_rule_step3}\n\\end{equation}\nand by re-applying the definition of logarithmic functions we get that\n\\begin{equation}\n\t\\log_{b}(xy) = M+N = \\log_{b}(x) + \\log_{b}(y).\n\t\\label{eq:log_addition_rule_step4}\n\\end{equation}\n\nSimilarly to \\autoref{eq:log_addition_rule_step4}, division yields subtraction:\n\\begin{equation}\n\t\\log_{b}\\left(\\frac{x}{y}\\right) = \\log_{b}(x)-\\log_{b}(y).\n\t\\label{eq:log_subtraction_rule}\n\\end{equation}\n\nEquations \\ref{eq:log_addition_rule_step4} and \\ref{eq:log_subtraction_rule} reveal another valuable property of logarithms: they reduce multiplication to addition (and subsequently division to subtraction). While today this property doesn't seem very impressive, in pre-computers days it helped carrying on complicated calculations, using tables of pre-calculated logarithms (called simply \\emph{logarithm tables}) - a sight rarely seen today.\n\nTaking one step forward in regards to reduction of operations, logarithms reduce powers to multiplication:\n\\begin{equation}\n\t\\log_{b}\\left( x^{k} \\right) = k\\log_{b}(x).\n\t\\label{eq:log_product_rule}\n\\end{equation}\nfor any $k\\in\\mathbb{R}$.\n\n(TBW:\\@ proving this will be in the chapter questions to the reader)\n\nAny logarithm $\\log_{b}(x)$ can be expressed using another base, i.e. $\\log_{a}(x)$ (where $a>0,\\ a\\neq1$) using the following formula:\n\\begin{equation}\n\t\\log_{a}(x) = \\log_{b}(x)\\cdot\\log_{a}(b).\n\t\\label{eq:log_base_change}\n\\end{equation}\n(TBW:\\@ proving this too will be a question to the reader)\n\n\\begin{example}{Changing logarithm base}{}\n\tExpressing $\\log_{4}(x)$ in terms of $\\log_{2}(x)$:\n\t\\[\n\t\t\\log_{4}(x) = \\log_{2}(x)\\cdot\\underbrace{\\log_{4}(2)}_{=\\frac{1}{2}} = \\frac{1}{2}\\log_{2}(x).\n\t\\]\n\\end{example}\n\nMuch like with exponentials, the number $e$ plays an important role when it comes to logarithms, for reasons that are discussed in the calculus chapter (ref). For now, we will just mention that $\\log_{e}(x)$ gets a special notation: $\\ln(x)$, which stands for \\emph{natural logarithm}. This notation is mainly used in applied mathematics and science, while in pure mathematics the notation is simply $\\log(x)$, i.e. without mentioning the base \\footnote{Depending on convention and context, this notation can refer to logarithm in any other base, most commonly $\\log_{10}(x)$ and $\\log_{2}(x)$.}.\n\nFor reason we will see in the calculus chapter, it is relatively simple to calculate both the exponential and logarithm in base $e$. Therefore, many operations in modern computations are actually done using these functions, for example calculating logarithms in other bases:\n\\begin{equation}\n\t\\log_{b}(x) = \\frac{\\ln(x)}{\\ln(b)}.\n\t\\label{eq:ln_base_change}\n\\end{equation}\nAnother operation commonly using both $\\eu^{x}$ and $\\ln(x)$ is raising a real number $a$ to a real power $b$: using the properties of both exponential and logarithmic functions, any such power can be expressed as\n\\begin{equation}\n\ta^{b} = \\eu^{b\\ln(a)}.\n\t\\label{eq:powers_using_e}\n\\end{equation}\n", "meta": {"hexsha": "d50eb3ff4ae72b32c80b381ec47fde26f045df7a", "size": 9866, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/intro/exponentials_logarithms.tex", "max_stars_repo_name": "JASory/maths_book", "max_stars_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-25T20:02:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T17:57:59.000Z", "max_issues_repo_path": "chapters/intro/exponentials_logarithms.tex", "max_issues_repo_name": "JASory/maths_book", "max_issues_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2022-01-17T05:01:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-20T06:18:24.000Z", "max_forks_repo_path": "chapters/intro/exponentials_logarithms.tex", "max_forks_repo_name": "JASory/maths_book", "max_forks_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2022-01-17T10:15:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-02T10:45:13.000Z", "avg_line_length": 48.8415841584, "max_line_length": 596, "alphanum_fraction": 0.6888303264, "num_tokens": 3250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.8791467770088162, "lm_q1q2_score": 0.802165303429596}}
{"text": "\\section{Definition of deep neural networks (DNN)} \nIn this section, we will give a brief introduction to a special\nfunction class related to deep neural networks (DNN) used in machine\nlearning.  We then explore the relationship between DNN (with ReLU as\nactivation function) and linear finite element methods. \n\nGiven $n, m\\ge 1$, the first ingredient in defining a deep neural\nnetwork (DNN) is (vector) linear functions of the form\n\\begin{equation}\\label{thetamap1}\n\\theta:\\mathbb{R}^{n}\\to\\mathbb{R}^{m} ,\n\\end{equation}as $\\theta(x)=Wx+b$ where\n$W=(w_{ij})\\in\\mathbb{R}^{m\\times n}$, $b\\in\\mathbb{R}^{m}$. \nThe second main ingredient is a nonlinear activation function, usually\ndenoted as \n\\begin{equation}\\label{sigma}\n\\sigma: \\mathbb{R} \\to \\mathbb{R}.\n\\end{equation} \nBy applying the function to each component, we can extend this\nnaturally to \n$$\n\\sigma:\\mathbb R^{n}\\mapsto \\mathbb R^{n}.\n$$\n\n\n\\subsection{Definition of neurons}\n\\begin{enumerate}\n\t\\item Primary variables $n_0=d$\n\t$$\n\tx^0=x=\n\t\\begin{pmatrix}\n\tx_1\\\\\n\tx_2\\\\\n\t\\vdots \\\\  \n\tx_{d}\n\t\\end{pmatrix}\n\t$$\n\t\\item $n_1$ hyperplanes $\\theta^{0}(x^0) = W^0 x + b^0$ where $W^0: \\mathbb{R}^{d} \\mapsto \\mathbb{R}^{n_1}$:\n\t$$\n\tW^0x+b^0=\n\t\\begin{pmatrix}\n\tw^0_1x+b^0_1\\\\\n\tw^0_2x+b^0_2\\\\\n\t\\vdots \\\\  \n\tw^0_{n_1}x+b^0_{n_1}\n\t\\end{pmatrix}\\quad \\mbox{with }\\quad W^0=\n\t\\begin{pmatrix}\n\tw^0_1\\\\\n\tw^0_2\\\\\n\t\\vdots \\\\  \n\tw^0_{n_1}\n\t\\end{pmatrix},\\quad b^0=\n\t\\begin{pmatrix}\n\tb^0_1\\\\\n\tb^0_2\\\\\n\t\\vdots \\\\  \n\tb^0_{n_1}\n\t\\end{pmatrix}\n\t$$\n\t\\item $n_1$-neurons:\n\t$$\n\tx^1=\\sigma(W^0x+b^0)\n\t=\\begin{pmatrix}\n\t\\sigma(w^0_1x+b^0_1)\\\\\n\t\\sigma(w^0_2x+b^0_2)\\\\\n\t\\vdots \\\\  \n\t\\sigma(w^0_{n_1}x+b^0_{n_1})\n\t\\end{pmatrix}\n\t$$\n%\t\\begin{center}\n%\t\\includegraphics[height=.5\\textwidth]{ANN}\n%\t\\end{center}\n\t\n\t\\item $n_2$-hyperplanes $\\theta^{1}(x^1) = W^1 x + b^1$ where $W^1: \\mathbb{R}^{n_1} \\mapsto \\mathbb{R}^{n_2}$:\n\t$$\n\tW^1x^1+b^1=\n\t\\begin{pmatrix}\n\tw^1_1x^1+b^1_1\\\\\n\tw^1_2x^1+b^1_2\\\\\n\t\\vdots \\\\  \n\tw^1_{n_2}x^1+b^1_{n_2}\n\t\\end{pmatrix}\\quad \\mbox{with }\\quad \n\tW^1=\n\t\\begin{pmatrix}\n\tw^1_1 \\\\\n\tw^1_2 \\\\\n\t\\vdots \\\\  \n\tw^1_{n_2} \n\t\\end{pmatrix},\\ \n\tb^1=\n\t\\begin{pmatrix}\n\tb^1_1\\\\\n\tb^1_2\\\\\n\t\\vdots \\\\  \n\tb^1_{n_2}\n\t\\end{pmatrix}\n\t$$\n\t\\item $n_2$-neurons:\n\t$$\n\tx^2=\\sigma(W^1x+b^1)\n\t=\\begin{pmatrix}\n\t\\sigma(w^1_1x+b^1_1)\\\\\n\t\\sigma(w^1_2x+b^1_2)\\\\\n\t\\vdots \\\\  \n\t\\sigma(w^1_{n_2}x+b^1_{n_2})\n\t\\end{pmatrix}\n\t$$\n\t\\item $\\cdots$\n\\end{enumerate} \n\n\\subsection{Definition of deep neural network functions}\\label{sec:DNN}\nGiven $d, k\\in\\mathbb{N}^+$ and  \n$$\nn_1,\\dots,n_{k}\\in\\mathbb{N} \\mbox{ with }n_0=d, n_{k+1}=1, \n$$\na general DNN function from $\\mathbb{R}^d$ to $\\mathbb{R}$ is given by\n\\begin{align*}\nf^0(x)   &=\\theta^0(x) \\\\ \nf^{\\ell}(x) &= [  \\theta^{\\ell} \\circ \\sigma ](f^{\\ell-1}(x)) \\quad \\ell = 1:k \\\\\nf(x) &= f^k(x). \n\\end{align*}\nThe following more concise notation is often used in computer science literature:\n\\begin{equation}\n\\label{compress-dnn}\nf(x) = \\theta^{k}\\circ \\sigma \\circ \\theta^{k-1} \\circ \\sigma \\cdots \\circ \\theta^1 \\circ \\sigma \\circ \\theta^0(x),\n\\end{equation}\nhere $\\theta^i: \\mathbb{R}^{n_{i}}\\to\\mathbb{R}^{n_{i+1}}$ are linear\nfunctions as defined in \\eqref{thetamap1}.  Such a DNN is called a\n$(k+1)$-layer DNN, and is said to have $k$-hidden layers. The size of\nthis DNN is $n_1+\\cdots+n_k$.\n\nThus, we have the following connection of neurons and DNN functions\n$$\nf^k(x) = \\theta^{k}(x^k) = \\theta^{k} \\circ \\sigma \\circ \\theta^{k-1}(x^{k-1}) = [\\theta^{k} \\circ \\sigma ] (f^{k-1}),\n$$\nor we can see that\n$$\nx^k = \\sigma(f^{k-1}) = \\sigma \\circ \\theta^{k-1} \\circ \\sigma (f^{k-2}) = [\\sigma \\circ \\theta^{k-1}] (x^{k-1}).\n$$\nBased on these notation and connections, we have the following definition of\ngeneral artificial neural network functions.\n\nShallow (one hidden layer) neural network functions:\n\\begin{equation}\n\\label{NN1}\n\\dnn(\\sigma; n_1) \n=\\bigg\\{ f^1(x) = \\theta^1 (x^1), \\mbox{ with } W^\\ell\\in \\mathbb R^{n_{\\ell+1}\\times\n\tn_{\\ell}}, b^\\ell\\in\\mathbb R^{n_\\ell}, \\ell=0, 1, n_0=d, n_2 = 1\\bigg\\}  \n\\end{equation}\nDeep neural network functions:\n\\begin{equation}\n\\label{NNL}\n\\dnn(\\sigma; n_1,n_2,\\ldots, n_L)=\\bigg\\{ f^{L}(x) = \\theta^L (x^{L}), \n \\mbox{ with } W^\\ell\\in \\mathbb R^{n_{\\ell+1}\\times\n\tn_{\\ell}}, b^\\ell\\in\\mathbb R^{n_\\ell}, \\ell=0:L, n_0=d, n_{L+1}=1\\bigg\\}  \n\\end{equation}\nIf we ignore the width (number of neurons) of network functions, we may \ndenote the general deep neural network functions with certain layers.\n\nThe 1-hidden layer (shallow) neural network is defined as:\n\\begin{equation}\n\\dnn=\\dnn(\\sigma) = \\dnn^1(\\sigma)\n=\\bigcup_{n_1\\ge 1} \\dnn(\\sigma;n_1,1)\n\\end{equation}\nGenerally, we can define the L-hidden layer neural network as:\n\\begin{equation}\n\\dnn^L(\\sigma) := \\bigcup_{n_1, n_2, \\cdots, n_{L}\\ge 1} \\dnn(\\sigma;n_1,n_2,\\cdots,n_L, 1).\n\\end{equation}\n\n\n\n\n\n\n\n\\subsection{ReLU DNN}\nIn this section, we mainly consider a special activation function,\nknown as the {\\it rectified linear unit} (ReLU), and defined as $\\rm\nReLU: \\mathbb R\\mapsto \\mathbb R$,\n\\begin{equation}\n\\label{relu}\n {\\rm ReLU}(x):=\\max(0,x), \\quad x\\in\\mathbb{R}. \n\\end{equation}\nA ReLU DNN with $k$ hidden layers might be written as:\n\\begin{equation}\n\\label{relu-dnn}\nf(x) = \\theta^{k}\\circ {\\rm ReLU} \\circ \\theta^{k-1} \\circ {\\rm ReLU} \\cdots \\circ \\theta^1 \\circ {\\rm ReLU} \\circ \\theta^0(x).\n\\end{equation}\n\nWe note that $\\rm ReLU$ is a continuous piecewise linear (CPWL) function.\nSince the composition of two CPWL functions is still a CPWL\nfunction, we have the following observation~\\cite{arora2016understanding}.\n\\begin{lemma}\\label{dnn-cpwl}\n\tEvery ReLU DNN: $\\mathbb{R}^d\\to\\mathbb{R}^c$ is a continuous\n\tpiecewise linear function.  More specifically, given any ReLU DNN,\n\tthere is a polyhedral decomposition of $\\mathbb R^d$ such that this\n\tReLU DNN is linear on each polyhedron in such a decomposition.\n\\end{lemma}\n\nHere is a simple example for the ``grid\" created by some 2-layer ReLU DNNs in $\\mathbb{R}^2$.\n\n\\begin{figure}[ht]\n\t\\includegraphics[width=.3\\textwidth]{figures/2to5to5to1-eps-converted-to.pdf}  \n\t\\includegraphics[width=.3\\textwidth]{figures/2to10to10to1-eps-converted-to.pdf}  \n\t\\includegraphics[width=.3\\textwidth]{figures/2to20to20to1-eps-converted-to.pdf}  \n\t\\caption{Projections of the domain partitions formed by 2-layer ReLU DNNs with sizes $(n_0, n_1, n_2, n_3)= (2, 5, 5, 1), (2, 10, 10, 1) \\text{and}\\ (2, 20, 20, 1)$ with random parameters.}\n\t\\label{fig:dnn-region}\n\\end{figure}\n\nFor convenience of exposition,  we introduce the following notation:\n%\\begin{equation}\n%\\begin{aligned}\n%{\\rm{DNN}_L} :=\\{& f:f=\n%\\theta^L \\circ {\\rm ReLU} \\circ \\theta^{L-1} \\cdots {\\rm ReLU}\\circ \\theta^0(x), \\\\\n%&\\theta^\\ell \\in \\mathbb{R}^{n_{\\ell} \\times (n_\\ell+1)}, \\quad n^0 = d, \\quad n^{L+1} = 1, \\quad n^\\ell \\in \\mathbb{N}^+\\}.\n%\\end{aligned}\n%\\end{equation}\nNamely $\\dnn^L({\\sigma})$ represents the DNN model with $L$ hidden layers and\nReLU activation function with arbitrary size, if $\\sigma = {\\rm ReLU}$.\n\n", "meta": {"hexsha": "fee292843b5549f4f5880d4cfac0e5679feb4ae3", "size": 6931, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DefineDNN.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/DefineDNN.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/DefineDNN.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5045454545, "max_line_length": 190, "alphanum_fraction": 0.6615207041, "num_tokens": 2794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107896491796, "lm_q2_score": 0.8558511506439707, "lm_q1q2_score": 0.8021129327171947}}
{"text": "\\subsection{Matrix multiplication}\n\nThe multiplication of a matrix and a vector from the previous section\nis a special case of the operation of multiplying two matrices, which\nwe now define.\n\n\\begin{definition}{Matrix multiplication}{matrix-multiplication}\n  Let $A=\\mat{a_{ij}}$ be an $m\\times n$-matrix, and let\n  $B=\\mat{b_{jk}}$ be an $n\\times p$-matrix. Then their product%\n  \\index{matrix!multiplication}%\n  \\index{multiplication!of matrices}%\n  \\index{product|see{multiplication}}%\n  \\index{matrix!multiplication!componentwise method}%\n  \\index{componentwise method!matrix multiplication} is the\n  $m\\times p$-matrix $AB=\\mat{c_{ik}}$ whose $(i,k)$-entry is defined\n  by\n  \\begin{equation*}\n    c_{ik} = a_{i1}b_{1k} + a_{i2}b_{2k} + \\ldots + a_{in}b_{nk}.\n  \\end{equation*}\n\\end{definition}\n\nFor matrices $A$ and $B$, in order to form the product $AB$, the\nnumber of columns of $A$ must equal the number of rows of\n$B$. Consider a product $AB$ where $A$ has dimensions $m\\times n$ and\n$B$ has dimensions $n \\times p$. Then the dimensions of the product\nare given by\n\\begin{equation*}\n  (\\overset{\\text{these must match!}}{m\\times\\widehat{n)\\;(n}\\times p})=m\\times p.\n\\end{equation*}\nNote that the two outside numbers give the dimensions of the\nproduct. If the two middle numbers do not match, we cannot multiply\nthe matrices.\n\nTo better visualize the rule of matrix multiplication, suppose\n\\begin{equation*}\n  A = \\begin{mymatrix}{cccc}\n    a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n    a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n    \\vdots & \\vdots & \\ddots & \\vdots \\\\\n    a_{m1} & a_{m2} & \\cdots & a_{mn} \\\\\n  \\end{mymatrix}\n  \\quad\\mbox{and}\\quad\n  B = \\begin{mymatrix}{cccc}\n    b_{11} & b_{12} & \\cdots & b_{1p} \\\\\n    b_{21} & b_{22} & \\cdots & b_{2p} \\\\\n    \\vdots & \\vdots & \\ddots & \\vdots \\\\\n    b_{n1} & b_{n2} & \\cdots & b_{np} \\\\\n  \\end{mymatrix}.\n\\end{equation*}\nThen their product\n\\begin{equation*}\n  AB = \\begin{mymatrix}{cccc}\n    c_{11} & c_{12} & \\cdots & c_{1p} \\\\\n    c_{21} & c_{22} & \\cdots & c_{2p} \\\\\n    \\vdots & \\vdots & \\ddots & \\vdots \\\\\n    c_{m1} & c_{m2} & \\cdots & c_{mp} \\\\\n  \\end{mymatrix}\n\\end{equation*}\nis an $m\\times p$-matrix whose $(i,k)$-entry is defined by\n\\begin{equation*}\n  c_{ik} = a_{i1}b_{1k} + a_{i2}b_{2k} + \\ldots + a_{in}b_{nk}.\n\\end{equation*}\nNote that we can also write this as\n\\begin{equation*}\n  c_{ik} ~=~ \\begin{mymatrix}{cccc}a_{i1} & a_{i2} & \\cdots & a_{in}\\end{mymatrix}\n  \\begin{mymatrix}{c}b_{1k} \\\\ b_{2k} \\\\ \\vdots \\\\ b_{nk}\\end{mymatrix}.\n\\end{equation*}\nIn other words, the $(i,k)$-entry of the matrix product $AB$ is a kind\nof dot product of the $i\\th$ row of $A$ with the $k\\th$ column of $B$.\n\n\\begin{example}{Matrix multiplication}{matrix-multiplication}\n  Find $AB$, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & 2 & 1 \\\\\n      0 & 2 & 1\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    B = \\begin{mymatrix}{rrr}\n      1 & 2 & 0 \\\\\n      0 & 3 & 1 \\\\\n      -2 & 1 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  First, let us note that since $A$ has size $2\\times 3$ and $B$ has\n  size $3\\times 3$, the product $AB$ is well-defined and has size\n  $2\\times 3$. Let $C=AB$. We compute each of the six entries of $C$:\n  \\begin{itemize}\n  \\item The $(1,1)$-entry is the first row of $A$ times the first\n    column of $B$: $c_{11} = 1\\cdot 1+2\\cdot 0+1\\cdot(-2) = -1$.\n  \\item The $(1,2)$-entry is the first row of $A$ times the second\n    column of $B$: $c_{12} = 1\\cdot 2+2\\cdot 3+1\\cdot 1 = 9$.\n  \\item The $(1,3)$-entry is the first row of $A$ times the third\n    column of $B$: $c_{13} = 1\\cdot 0+2\\cdot 1+1\\cdot 1 = 3$.\n  \\item The $(2,1)$-entry is the second row of $A$ times the first\n    column of $B$: $c_{21} = 0\\cdot 1+2\\cdot 0+1\\cdot(-2) = -2$.\n  \\item The $(2,2)$-entry is the second row of $A$ times the second\n    column of $B$: $c_{22} = 0\\cdot 2+2\\cdot 3+1\\cdot 1 = 7$.\n  \\item The $(2,3)$-entry is the second row of $A$ times the third\n    column of $B$: $c_{23} = 0\\cdot 0+2\\cdot 1+1\\cdot 1 = 3$.\n  \\end{itemize}\n  Therefore, we have\n  \\begin{equation*}\n    AB = \\begin{mymatrix}{rrr}\n      -1 & 9 & 3 \\\\\n      -2 & 7 & 3\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nAs this example shows, calculating matrix products one component at a\ntime can be an extremely repetitive and tedious process. Fortunately,\nwe can speed this up by considering whole columns at once.\n\n\\begin{proposition}{Matrix multiplication, column method}{matrix-multiplication-columns}\n  Let $A$ be an $m\\times n$-matrix, and let $B$ be an\n  $n\\times p$-matrix.  Suppose that the columns of $B$ are\n  $\\vect{b}_1,\\vect{b}_2,\\ldots,\\vect{b}_p$. Then the columns of $AB$\n  are%\n  \\index{matrix!multiplication!column method}%\n  \\index{column method!matrix multiplication}\n  \\begin{equation*}\n    A\\vect{b}_1,~A\\vect{b}_2,~\\ldots,~A\\vect{b}_p.\n  \\end{equation*}\n  In other words, the $k\\th$ column of the matrix product $AB$ is\n  equal to $A$ times the $k\\th$ column of $B$.\n\\end{proposition}\n\n\\begin{example}{Matrix multiplication by the column method}{matrix-multiplication-columns}\n  Find the matrix product $AB$ by the column method, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & 2 & 1 \\\\\n      0 & 2 & 1\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    B = \\begin{mymatrix}{rrr}\n      1 & 2 & 0 \\\\\n      0 & 3 & 1 \\\\\n      -2 & 1 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We multiply $A$ by each of the columns of $B$:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 1 \\\\\n      0 & 2 & 1\n    \\end{mymatrix}\n    \\begin{mymatrix}{r}\n      1 \\\\\n      0 \\\\\n      -2\n    \\end{mymatrix}\n    ~=~\n    1 \\begin{mymatrix}{r} 1 \\\\ 0 \\end{mymatrix}\n    + 0 \\begin{mymatrix}{r} 2 \\\\ 2 \\end{mymatrix}\n    - 2 \\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r}\n      -1 \\\\\n      -2\n    \\end{mymatrix},\n  \\end{equation*}\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 1 \\\\\n      0 & 2 & 1\n    \\end{mymatrix}\n    \\begin{mymatrix}{r}\n      2 \\\\\n      3 \\\\\n      1\n    \\end{mymatrix}\n    ~=~\n    2 \\begin{mymatrix}{r} 1 \\\\ 0 \\end{mymatrix}\n    + 3 \\begin{mymatrix}{r} 2 \\\\ 2 \\end{mymatrix}\n    + 1 \\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r}\n      9 \\\\\n      7\n    \\end{mymatrix},\n  \\end{equation*}\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 1 \\\\\n      0 & 2 & 1\n    \\end{mymatrix}\n    \\begin{mymatrix}{r}\n      0 \\\\\n      1 \\\\\n      1\n    \\end{mymatrix}\n    ~=~\n    0 \\begin{mymatrix}{r} 1 \\\\ 0 \\end{mymatrix}\n    + 1 \\begin{mymatrix}{r} 2 \\\\ 2 \\end{mymatrix}\n    + 1 \\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{r}\n      3 \\\\\n      3\n    \\end{mymatrix}.\n  \\end{equation*}\n  The resulting three column vectors form the columns of $AB$.  Thus,\n  \\begin{equation*}\n    AB ~=~ \\begin{mymatrix}{rrr}\n      -1 & 9 & 3 \\\\\n      -2 & 7 & 3\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nOf course, the answer in\nExample~\\ref{exa:matrix-multiplication-columns} is the same as that in\nExample~\\ref{exa:matrix-multiplication}. Please convince yourself that\nboth methods of matrix multiplication give the same answer, since they\neach ultimately calculate the same thing. Nevertheless, with a bit of\npractice, the column method is much faster, and you can even learn to\nmultiply matrices in your head! The key to understanding the column\nmethod is that each column of $B$ provides instructions for taking a\nlinear combination of the columns of $A$. The method works especially\nwell if $B$ contains many zeros and ones.\n\nSince column vectors are simply $n\\times 1$-matrices, and row vectors\nare $1\\times m$-matrices, we can also multiply a column vector by a\nrow vector or vice versa.\n\n\\begin{example}{Column vector times row vector}{column-times-row}\n  Multiply $\\begin{mymatrix}{r}\n    1 \\\\\n    2 \\\\\n    1\n  \\end{mymatrix}\n  \\begin{mymatrix}{rrrr}\n    1 & 2 & 1 & 0\n  \\end{mymatrix}$.\n\\end{example}\n\n\\begin{solution}\n  Here we are multiplying a $3\\times 1$-matrix by a\n  $1\\times 4$-matrix, so the result will be a $3\\times\n  4$-matrix. Using the column method, we can compute this product as\n  follows:\n  \\begin{equation*}\n    \\begin{mymatrix}{r}\n      1 \\\\\n      2 \\\\\n      1\n    \\end{mymatrix} \\begin{mymatrix}{rrrr}\n      1 & 2 & 1 & 0\n    \\end{mymatrix} =\n    \\mat{\n      \\overset{\\text{First column}}{\n        \\overbrace{\n          \\begin{mymatrix}{r}\n            1 \\\\\n            2 \\\\\n            1\n          \\end{mymatrix}\n          \\begin{mymatrix}{r}\n            1\n          \\end{mymatrix}\n        }\n      },\n      \\overset{\\text{Second column}}{\n        \\overbrace{\n          \\begin{mymatrix}{r}\n            1 \\\\\n            2 \\\\\n            1\n          \\end{mymatrix}\n          \\begin{mymatrix}{r}\n            2\n          \\end{mymatrix}\n        }\n      },\n      \\overset{\\text{Third column}}{\n        \\overbrace{\n          \\begin{mymatrix}{r}\n            1 \\\\\n            2 \\\\\n            1\n          \\end{mymatrix}\n          \\begin{mymatrix}{r}\n            1\n          \\end{mymatrix}\n        }\n      },\n      \\overset {\\text{Fourth column}}{\n        \\overbrace{\n          \\begin{mymatrix}{r}\n            1 \\\\\n            2 \\\\\n            1\n          \\end{mymatrix}\n          \\begin{mymatrix}{r}\n            0\n          \\end{mymatrix}\n        }}\n    }\n    ~=~\n    \\begin{mymatrix}{rrrr}\n      1 & 2 & 1 & 0 \\\\\n      2 & 4 & 2 & 0 \\\\\n      1 & 2 & 1 & 0\n    \\end{mymatrix}\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Row vector times column vector}{row-times-column}\n  Multiply $\\begin{mymatrix}{rrrr}\n    1 & 2 & 3\n  \\end{mymatrix}\n  \\begin{mymatrix}{r}\n    1 \\\\\n    2 \\\\\n    -1\n  \\end{mymatrix}$.\n\\end{example}\n\n\\begin{solution}\n  Here we are multiplying a $1\\times 3$-matrix by a $3\\times\n  1$-matrix, so the result will be a $1\\times 1$-matrix, or in other\n  words, a scalar. (We regard a scalar and a $1\\times 1$-matrix as the\n  same thing). We have:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr}\n      1 & 2 & 3\n    \\end{mymatrix}\n    \\begin{mymatrix}{r}\n      1 \\\\\n      2 \\\\\n      -1\n    \\end{mymatrix}\n    ~=~\n    1\\cdot 1 + 2\\cdot 2 + 3\\cdot(-1) = 2.\n  \\end{equation*}\n  Therefore, multiplying a row vector by a column vector works very\n  similarly to an ordinary dot product (except that the dot product is\n  defined between two column vectors, not a row vector and a column\n  vector).\n\\end{solution}\n\n\\begin{example}{A multiplication that is not defined}{undefined-matrix-multiplication}\n  Find $BA$, where\n  \\begin{equation*}\n    B = \\begin{mymatrix}{rrr}\n      1 & 2 & 0 \\\\\n      0 & 3 & 1 \\\\\n      -2 & 1 & 1\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    A = \\begin{mymatrix}{rrr}\n      1 & 2 & 1 \\\\\n      0 & 2 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The product $BA$ is not defined, since $B$ is a $3\\times 3$-matrix\n  and $A$ is a $2\\times 3$-matrix. Since the number of columns of $B$\n  does not match the number of rows of $A$, the product is not defined.\n\\end{solution}\n\nNotice that the matrices in\nExample~\\ref{exa:undefined-matrix-multiplication} are the same as\nthose in Example~\\ref{exa:matrix-multiplication}.  This\ndemonstrates an important property of matrix multiplication: it is\npossible that $AB$ is defined by $BA$ is undefined. Even if $AB$ and\n$BA$ are both defined, they may not be equal, as the following example\nshows. Therefore, matrix multiplication is not commutative.\n\n\\begin{example}{Matrix multiplication is not commutative}{matrix-multiplication-not-commutative}\n  Compute $AB$ and $BA$, where\n  \\begin{equation*}\n    A ~=~ \\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      3 & 4\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    B ~=~ \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      1 & 0\n    \\end{mymatrix}\n  \\end{equation*}\n  Are they equal?\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{equation*}\n    AB ~=~\n    \\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      3 & 4\n    \\end{mymatrix}\n    \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      1 & 0\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{rr}\n      2 & 1 \\\\\n      4 & 3\n    \\end{mymatrix}\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    BA ~=~\n    \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      1 & 0\n    \\end{mymatrix}\n    \\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      3 & 4\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{rr}\n      3 & 4 \\\\\n      1 & 2\n    \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, $AB$ and $BA$ are not equal. Matrix multiplication is not\n  commutative.\n\\end{solution}\n\nWe have seen two methods for matrix multiplication: one component at a\ntime, and by the column method. There is also a third method, called\nthe row method. It is exactly symmetric to the column method.\n\n\\begin{proposition}{Matrix multiplication, row method}{matrix-multiplication-rows}\n  Let $A$ be an $m\\times n$-matrix, and let $B$ be an\n  $n\\times p$-matrix.  Suppose that the rows of $A$ are\n  $\\vect{a}_1,\\vect{a}_2,\\ldots,\\vect{a}_m$. Then the rows of $AB$\n  are%\n  \\index{matrix!multiplication!row method}%\n  \\index{row method!matrix multiplication}\n  \\begin{equation*}\n    \\vect{a}_1B,~\\vect{a}_2B,~\\ldots,~\\vect{a}_mB.\n  \\end{equation*}\n  In other words, the $i\\th$ column of the matrix product $AB$ is\n  equal to the $i\\th$ column of $A$ times $B$.\n\\end{proposition}\n\n\\begin{example}{Matrix multiplication by the row method}{matrix-multiplication-rows}\n  Find the matrix product $AB$ by the row method, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & 2 & 1 \\\\\n      0 & 2 & 1\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    B = \\begin{mymatrix}{rrr}\n      1 & 2 & 0 \\\\\n      0 & 3 & 1 \\\\\n      -2 & 1 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We multiply each of the rows of $A$ by $B$:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 1\n    \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 0 \\\\\n      0 & 3 & 1 \\\\\n      -2 & 1 & 1\n    \\end{mymatrix}\n    ~=~\n    1 \\begin{mymatrix}{rrr} 1 & 2 & 0 \\end{mymatrix}\n    + 2 \\begin{mymatrix}{rrr} 0 & 3 & 1 \\end{mymatrix}\n    + 1 \\begin{mymatrix}{rrr} -2 & 1 & 1 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{rrr} -1 & 9 & 3 \\end{mymatrix},\n  \\end{equation*}\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      0 & 2 & 1\n    \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 0 \\\\\n      0 & 3 & 1 \\\\\n      -2 & 1 & 1\n    \\end{mymatrix}\n    ~=~\n    0 \\begin{mymatrix}{rrr} 1 & 2 & 0 \\end{mymatrix}\n    + 2 \\begin{mymatrix}{rrr} 0 & 3 & 1 \\end{mymatrix}\n    + 1 \\begin{mymatrix}{rrr} -2 & 1 & 1 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{rrr} -2 & 7 & 3 \\end{mymatrix}.\n  \\end{equation*}\n  The resulting two row vectors form the rows of $AB$.  Thus,\n  \\begin{equation*}\n    AB ~=~ \\begin{mymatrix}{rrr}\n      -1 & 9 & 3 \\\\\n      -2 & 7 & 3\n    \\end{mymatrix}.\n  \\end{equation*}\n  Once again this is the same answer as in\n  Examples~\\ref{exa:matrix-multiplication-columns} and\n  {\\ref{exa:matrix-multiplication}}. All three methods give the same\n  result. But notice how in the row method, each row of $A$ provides\n  instructions for taking a linear combinations of the rows of $B$.\n\\end{solution}\n\nWe finish this section by introducing an important square matrix\ncalled the identity matrix.\n\n\\begin{definition}{Identity matrix}{identity-matrix}\n  The \\textbf{identity matrix}%\n  \\index{matrix!identity}%\n  \\index{identity matrix} of size $n\\times n$ has ones along the\n  diagonal, and zeros everywhere else. In other words, it is the\n  matrix $\\mat{\\delta_{ij}}$ where $\\delta_{ij}=1$ if $i=j$ and\n  $\\delta_{ij}=0$ otherwise. The identity matrix is always a square\n  matrix. Here are some identity matrices of various sizes.\n  \\begin{equation*}\n    \\begin{mymatrix}{r}\n      1\n    \\end{mymatrix},\n    \\quad\n    \\begin{mymatrix}{cc}\n      1 & 0 \\\\\n      0 & 1\n    \\end{mymatrix},\n    \\quad\n    \\begin{mymatrix}{ccc}\n      1 & 0 & 0 \\\\\n      0 & 1 & 0 \\\\\n      0 & 0 & 1\n    \\end{mymatrix},\n    \\quad\n    \\begin{mymatrix}{cccc}\n      1 & 0 & 0 & 0 \\\\\n      0 & 1 & 0 & 0 \\\\\n      0 & 0 & 1 & 0 \\\\\n      0 & 0 & 0 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  When it is necessary to distinguish which size of identity matrix is\n  being discussed, we will use the notation $I_n$ for the $n\\times n$\n  identity matrix.\n\\end{definition}\n\n\\begin{example}{Multiplying by the identity matrix}{identity-multiply}\n  Calculate $AI$, where $I$ is the $2\\times 2$ identity matrix and\n  \\begin{equation*}\n    A ~=~ \\begin{mymatrix}{rr}\n      a_{11} & a_{12} \\\\\n      a_{21} & a_{22} \\\\\n      a_{31} & a_{32} \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We need to calculate\n  \\begin{equation*}\n    AI ~=~\n    \\begin{mymatrix}{rr}\n      a_{11} & a_{12} \\\\\n      a_{21} & a_{22} \\\\\n      a_{31} & a_{32} \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  Using the column method, we find that the first column of $AI$ is\n  \\begin{equation*}\n    \\begin{mymatrix}{rr}\n      a_{11} & a_{12} \\\\\n      a_{21} & a_{22} \\\\\n      a_{31} & a_{32} \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{r}\n      1 \\\\\n      0\n    \\end{mymatrix}\n    ~=~\n    1 \\begin{mymatrix}{rr}\n      a_{11} \\\\\n      a_{21} \\\\\n      a_{31} \\\\\n    \\end{mymatrix}\n    + 0 \\begin{mymatrix}{rr}\n      a_{12} \\\\\n      a_{22} \\\\\n      a_{32} \\\\\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{rr}\n      a_{11} \\\\\n      a_{21} \\\\\n      a_{31} \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  which is exactly the same as the first column of $A$.\n  Similarly, the second column of $AI$ is\n  \\begin{equation*}\n    \\begin{mymatrix}{rr}\n      a_{11} & a_{12} \\\\\n      a_{21} & a_{22} \\\\\n      a_{31} & a_{32} \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{r}\n      0 \\\\\n      1\n    \\end{mymatrix}\n    ~=~\n    0 \\begin{mymatrix}{rr}\n      a_{11} \\\\\n      a_{21} \\\\\n      a_{31} \\\\\n    \\end{mymatrix}\n    + 1 \\begin{mymatrix}{rr}\n      a_{12} \\\\\n      a_{22} \\\\\n      a_{32} \\\\\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{rr}\n      a_{12} \\\\\n      a_{22} \\\\\n      a_{32} \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  which is exactly the same as the second column of $A$. Therefore\n  \\begin{equation*}\n    AI ~=~\n    \\begin{mymatrix}{rr}\n      a_{11} & a_{12} \\\\\n      a_{21} & a_{22} \\\\\n      a_{31} & a_{32} \\\\\n    \\end{mymatrix}\n    ~=~ A.\n  \\end{equation*}\n\\end{solution}\n\nThe calculation of the last example generalizes to matrices of all\nsizes, and is summarized in the following proposition.\n\n\\begin{proposition}{Multiplying by the identity matrix}{identity-matrix}\n  Let $A$ be any $m\\times n$-matrix. Then\n  \\begin{equation*}\n    I_mA = A = AI_n.\n  \\end{equation*}\n\\end{proposition}\n\nWe can also raise a square matrix to a power. For example, $A^5$ means\n$A\\cdot A\\cdot A\\cdot A\\cdot A$.\n\n\\begin{example}{Raising a matrix to a power}{matrix-power}\n  Compute $A^3$, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      -2 & 3 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{equation*}\n    A^3 = A\\cdot A\\cdot A\n    = \\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      -2 & 3 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      -2 & 3 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      -2 & 3 \\\\\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rr}\n      -3 & 8 \\\\\n      -8 & 5 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      -2 & 3 \\\\\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rr}\n      -19 & 18 \\\\\n      -18 & -1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n", "meta": {"hexsha": "6df52600ff24b39227d593c025fca1f228c9c9a4", "size": 19519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Multiplication-Multiplication.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-Multiplication-Multiplication.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-Multiplication-Multiplication.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 27.6082036775, "max_line_length": 96, "alphanum_fraction": 0.5841487781, "num_tokens": 7230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543454, "lm_q2_score": 0.8840392848011834, "lm_q1q2_score": 0.8020996450473703}}
{"text": "\\subsection{Conversions}\r\n\\noindent\r\n\\begin{itemize}\r\n\t\\item From Cylindrical to Cartesian\r\n\t\t\\begin{equation*}\r\n\t\t\t(r, \\theta, z) = (r\\cos{\\theta}, r\\sin{\\theta}, z)\r\n\t\t\\end{equation*}\r\n\t\\item From Cartesian to Cylindrical\r\n\t\t\\begin{equation*}\r\n\t\t\t(x, y, z)=\\left(\\sqrt{x^2 + y^2}, \\tan^{-1}{\\frac{y}{x}}, z\\right)\r\n\t\t\\end{equation*}\r\n\\end{itemize}\r\n", "meta": {"hexsha": "f0a893c41edcca537fdcdf4114d125f2e20ef2ae", "size": 351, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/curvilinearCoordinates/conversions_cylindrical.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/curvilinearCoordinates/conversions_cylindrical.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/curvilinearCoordinates/conversions_cylindrical.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 27.0, "max_line_length": 70, "alphanum_fraction": 0.6153846154, "num_tokens": 139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355091, "lm_q2_score": 0.8840392893839085, "lm_q1q2_score": 0.8020996425583861}}
{"text": "\\section{Generative Learning: Naive Bayes}\n\\subsection{Assumptions}\nThe naive bayes model supposes that the features of each data point are all\nindependent:\n\\begin{equation}\n  P(x|y)=P(x_1,x_2,...,x_n|y)=P(x_1|y)P(x_2|y)...P(x_n|y)=\\prod_{i=1}^nP(x_i|y)\n\\end{equation}\n\\subsection{Estimation}\nWe can write the likelihood of the data as:\n\\begin{equation}\n  \\mathcal{L}(\\phi_y, \\phi_{j=l|y=k}) = \\prod_{i=1}^m P(x^{(i)}, y^{(i)})\n\\end{equation}\nwith classes denoted by $k$ and features $x_j = l$ ($x_j$ takes on value $l$).\nBy maximizing the estimates, we get:\n\\begin{equation}\n  \\phi_y = P(y=k)=\\frac{1}{m} \\sum_{i=1}^m 1_{\\{y^{(i)}=k\\}}\n\\end{equation}\n\\begin{equation}\n  \\phi_{j=l|y=k} = P(x_j=l|y=k)= \\frac{ \\sum_{i=1}^m 1_{\\{y^{(i)}=k \\, \\wedge \\, x_j^{(i)} = l\\}} }{ \\sum_{i=1}^m 1_{\\{y^{(i)}=k\\}} }\n\\end{equation}\n\\subsubsection{Laplace Smoothing}\nLaplace smoothing allows for unseen data to have a probability, and not automatically\ndestory the prediciton process by setting all classes to $0$. We can replace\nour feature estimates with the following:\n\\begin{equation}\n  \\phi_j = \\frac{ \\sum_{i=1}^m 1_{\\{x^{(i)}=j\\}} +1} { m + k }\n\\end{equation}\nOr more generically:\n\\begin{equation}\n  \\phi_{j=l|y=k} = \\frac{ \\sum_{i=1}^m 1_{\\{x_j^{(i)}=l \\wedge y^{(i)} = k\\}} + 1 } { \\sum_{i=1}^m 1_{\\{y^{(i)}=k\\}} + |K| }\n\\end{equation}\nwhere $|K|$ is the number of classes\n\\subsection{Prediction}\nTo classify a point $x$, we find the class $y=k$ which maximizes the probability:\n\\begin{equation}\n  \\hat{y} = \\underset{k}{\\textrm{arg max}} \\,\\, P(y=k) \\cdot\\prod_{i=j}^n P(x_j | y=k)\n\\end{equation}\n", "meta": {"hexsha": "0e3e4691a24b331339fe641d28ecc54adfc5ee76", "size": 1592, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/naive_bayes.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/naive_bayes.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/naive_bayes.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.8947368421, "max_line_length": 133, "alphanum_fraction": 0.6444723618, "num_tokens": 653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109798251322, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.8020471656914611}}
{"text": "\\section*{Ex.34.1-5}\n\\subsection*{Show that if an algorithm makes at most a constant number of calls to polynomial-time subroutines and performs an additional amount of work that also takes polynomial times, then it runs in polynomial time}\n\nEach subroutine $i$ takes $O(n^{k_i}_i)$ time, and there are $m$ subroutines. So in total, the algorithms takes\n$$\n\\sum^m_{i=1} O(n^{k_i}_i) = c_1n^{k_1}_1 + c_2n^{k_2}_2 + \\ldots + c_m n^{k_m}_m \\leq m\\cdot c_{max}n^{k_{max}}_{max} = O(n^{k_{max}}_{max}),\n$$\nwhere the index $max$ represents the subroutine, that takes the longest time.\n\\\\\nSince both $m$ and $c$ are constants, the total running time is still (bounded by) $O(n^k)$.\n\n\\subsection*{Show that a polynomial number of calls to polynomial-time subroutines a may result in an exponential-time algorithm}\n\nWe show an example:\n\\\\\nLet the subroutine be a recursive function, where an integer $x$ is multiplied with $x-1$, then $x-2$, then $x-3$, and so on, $x-1$ times which is linearly many times. The outcome of the recursive function is:\n$$\nx\\cdot (x-1)\\cdot (x-2)\\cdot (x-3)\\cdots 1 = x!\n$$\nNote, that $x!\\in \\omega(e^x)$,\n\\\\\nIt will take an exponential number of bits to represent this, so it must also take exponential time to perform.", "meta": {"hexsha": "ec8c95909c90cc7cc24ae06e29ac4bbf11c591e9", "size": 1241, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge4/Ex.34.1-5.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge4/Ex.34.1-5.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge4/Ex.34.1-5.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.4090909091, "max_line_length": 219, "alphanum_fraction": 0.716357776, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894689081711, "lm_q2_score": 0.896251371055247, "lm_q1q2_score": 0.8019562883147446}}
{"text": "\\documentclass{article}\n    % General document formatting\n    \\usepackage[margin=0.7in]{geometry}\n    \\usepackage[parfill]{parskip}\n    \\usepackage[utf8]{inputenc}\n    \\usepackage{amsmath}\n    \\usepackage{amssymb}\n    \\usepackage{amsthm}\n    \\usepackage{tikz}\n    \\usepackage{fancyhdr}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\\rhead{Edgar Jacob Rivera Rios - A01184125}\n\n\\renewcommand{\\labelenumi}{\\alph{enumi})}\n\\renewcommand{\\labelenumii}{\\roman{enumii})}\n\n\\begin{document}\n\\section*{1.4.1 Proof by simple induction}\n\\begin{enumerate}\n    \\item Use simple induction to show that for every positive integer $n$, $5^n - 1$ is divisible by 4\\\\\n    $5^{n}-1$ is divisible by 4\\\\\n    Base case:\n    \\begin{align*}\n        5^{1}-1 &= 4j\\\\\n        &= 4 = 4j\\\\\n        5^{k}-1 &= 4j\\\\\n        5^{k}&= 4j+1\n    \\end{align*}\n    Induction step:\n    \\begin{align*}\n        &= 5^{k+ 1}-1\\\\\n        &= 5^{k} \\cdot 5 - 1\\\\\n        &=(4j+1) \\cdot 5 - 1\\\\\n        &=(20j + 5) -1\\\\\n        &=20j + 4\\\\\n        &=4\\cdot(5j + 1)\\\\\n        &\\implies true\\ for\\ n = k + 1\n    \\end{align*}\n    \\item Use simple induction to show that for every positive integer $n$, $n^3- n$ is divisible by 3. (Hint: In the induction step, you will need to make use of the arithmetic fact that $(k+1)^3 = k^3 + 3k^2 + 3k +1$)\\\\\n    $n^3- n$ is divisible by 3\\\\\n    Base case:\n    \\begin{align*}\n        1^3- 1 &= 3j\\\\\n        &= 0 = 3j\\\\\n        k^{3}-k &= 3j\\\\\n        k^{3}&= 3j+k\n    \\end{align*}\n    Induction step:\n    \\begin{align*}\n        &= (k + 1)^{3}-(k +1)\\\\\n        &= (k^3 + 3k^2 + 3k +1) - (k +1)\\\\\n        &= k^3 + 3k^2 + 2k\\\\\n        &= (3j+k) + 3k^2 + 2k\\\\\n        &= 3j+ 3k^2 + 3k\\\\\n        &=3\\cdot(j + k^2 + k)\\\\\n        &\\implies true\\ for\\ n = k + 1\n    \\end{align*}\n    \\item Show by simple induction that for every natural number $n$, $\\sum_{i=0}^{n} 2^{i} = 2^{n+1} - 1$\\\\\n    $f(n) = 2^{n+1} - 1 $\\\\\n    Base case:\n    \\begin{align*}\n        f(1) &= 2^{1+1} - 1\\\\\n        f(1) &= 4 - 1\\\\\n        f(1) &= 3\\\\\n        f(k) &= 2^{k+1} - 1\n    \\end{align*}\n    Induction step:\n    \\begin{align*}\n        f(k +1) &= 2^{k + 2} - 1\\\\\n        f(k +1) &= 2^1 + 2^2 ... + 2^{k} + 2^{k +1}\\\\\n        &=f(k) + 2^{k +1}\\\\\n        &=2^{k+1} - 1 + 2^{k +1}\\\\\n        &=2(2^{k+1}) - 1\\\\\n        &=2^{1} \\cdot 2^{k+1} - 1\\\\\n        &=2^{k+1 +1} - 1\\\\\n        &=2^{k+2} - 1\\\\\n        &\\implies true\\ for\\ n = k + 1\n    \\end{align*}\n\\end{enumerate}\n\\section*{1.4.2: Definition by simple recursion}\n\\begin{enumerate}\n    \\item  Let $f: N \\rightarrow N$ be the function defined by putting $f (0) = 0$ and $f(n+1) = n$ for all $n \\in N$.\n    \\begin{enumerate}\n        \\item Evaluate this function bottom-up for all arguments 0\u20135.\n        \\begin{align*}\n            f(0) &= 0\\\\\n            f(1) &= 0\\\\\n            f(2) &= 1\\\\\n            f(3) &= 2\\\\\n            f(4) &= 3\\\\\n            f(5) &= 4\n        \\end{align*}\n        \\item Explain what f does by expressing it in explicit terms (i.e. without a recursion).\\\\\n        This function is not recursive, it only returns the antecesor of the current value\n    \\end{enumerate}\n    \\item Let $f : N^{+} \\rightarrow N$ be the function that takes each positive integer $n$ to the greatest natural number $p$ with $2^{p} \\leq n$. Define this function by a simple recursion. (Hint: You will need to divide the recursion step into two cases.)\n    \\begin{align*}\n        &f(n) = 0& &, when\\ n = 1\\\\\n        &f(n) = f(n-1)& &, when\\ n > 1, \\log_{2}(n) \\notin N\\\\\n        &f(n) = f(n-1) + 1& &, when\\ n > 1, \\log_{2}(n) \\in N\n    \\end{align*}\n    \\item Let $g: NXN \\rightarrow N$ be defined by putting $g(m,0)= m$ for all $m \\in N$ and $g(m,n+1)=f (g(m,n))$ where $f$ is the function defined in part (a) of this exercise.\n    \\begin{enumerate}\n        \\item Evaluate $g(3,4)$ top-down.\n        \\begin{align*}\n            g(3, 4) &= f(g(3, 3))\\\\\n            &= f(f(g(3, 2)))\\\\\n            &= f(f(f(g(3, 1))))\\\\\n            &= f(f(f(f(g(3, 0)))))\\\\\n            &= f(f(f(f(f(3)))))\\\\\n            &= f(f(f(f(2))))\\\\\n            &= f(f(f(1)))\\\\\n            &= f(f(0))\\\\\n            &= f(0)\\\\\n            &= 0\\\\\n        \\end{align*}\n        \\item Explain what $g$ does by expressing it in explicit terms (i.e. without a recursion).\\\\\n        It substracts the right item from the left, but if the remain is negative, it returns 0\n    \\end{enumerate}\n\\end{enumerate}\n\n\\section*{1.4.3: Proof by cumulative induction}\n\\begin{enumerate}\n    \\item Use cumulative induction to show that any postage cost of four or more pence can be covered by two-pence and five-pence stamps.\\\\\n    $2x + 5y = n$, when $n \\geq 4$\\\\\n    Base case:\n    \\begin{align*}\n        n &= 4 &4 &= 2(2) + 5(0)\n    \\end{align*}\n    Induction step:\n    \\begin{align*}\n        hypothesis &\\rightarrow \\forall j < k,\\ j = 2x +5y\\\\\n        goal &\\rightarrow k = 2x + 3y\\\\\n        case (1) &\\rightarrow k\\ is\\ multiple\\ of\\ two \\implies y = 0\\ and\\ x \\in N\\\\\n        case (2) &\\rightarrow k\\ is\\ multiple\\ of\\ five \\implies x = 0\\ and\\ y \\in N\\\\\n        case (3) &\\rightarrow k\\ is\\ not\\ multiple\\ of\\ any \\implies y \\in N\\ and\\ x \\in N\\\\\n    \\end{align*}\n    \\item Use cumulative induction to show that for every natural number $n$, $F(n) \\leq 2^{n}-1$, where $F$ is the Fibonacci function.\\\\\n    $F(n) \\leq 2^{n} -1$, \\\\\n    Base case:\n    \\begin{align*}\n        n &\\leq 1 &1 &\\leq 2^{1} - 1\n    \\end{align*}\n    Induction step:\n    \\begin{align*}\n        hypothesis &\\rightarrow \\forall j < k,\\ F(j) \\leq 2^{j} - 1\\\\\n        goal &\\rightarrow F(k) \\leq 2^{k} -1\\\\\n        case (1) &\\rightarrow F(k)\\ is\\ greater\\ than\\ 2^{k} -1 \\implies 2^{k+1} -1 < F(j +1)\\\\\n        &Impossible\\ given\\ that\\ F\\ grows\\ at\\ F(k)\\ and\\ 2^{k} -1\\ grows\\ at\\ double\\ rate\\\\\n        case (2) &\\rightarrow F(k)\\ is\\ less\\ or\\ equal\\ than\\ 2^{k} -1e \\implies This\\ must\\ be\\ true\\ then\n    \\end{align*}\n    \\item Calculate F(5) top-down, and then again bottom-up, where again $F$ is the Fibonacci function\\\\\n    Top-down:\n    \\begin{align*}\n        F(5) &= F(4) + F(3) \\\\\n        F(5) &= (F(3) + F(2)) + (F(2) + F(1)) \\\\\n        F(5) &= ((F(2) + F(1)) + (F(1) + F(0))) + ((F(1) + F(0)) + 1)\\\\\n        F(5) &= (((F(1) + F(0)) + 1) + (1 + 0)) + ((1 + 0) + 1)\\\\\n        F(5) &= (((1+ 0) + 1) + (1 + 0)) + ((1 + 0) + 1)\\\\\n        F(5) &= ((1 + 1) + (1)) + (1 + 1)\\\\\n        F(5) &= (2 + 1) + (2)\\\\\n        F(5) &= 3 + 2\\\\\n        F(5) &= 5\n    \\end{align*}\n    Bottom-up\n    \\begin{align*}\n        F(0) &= 0 \\\\\n        F(1) &= 1 \\\\\n        F(2) &= F(1) + F(0) = 1 + 0 = 1\\\\\n        F(3) &= F(2) + F(1) = 1 + 1 = 2\\\\\n        F(4) &= F(3) + F(2) = 2 + 1 = 3\\\\\n        F(5) &= F(4) + F(3) = 3 + 2 = 5\n    \\end{align*}\n    \\item Express each of the numbers 14, 15 and 16 as a sum of $3s$ and/or $8s$. Using this fact in your basis, show by cumulative induction that every positive integer $n \\leq 14$ may be expressed as a sum of $3s$ and/or $8s$.\\\\\n    $n = 3x + 8y$, when $n > 14$\\\\\n    Base case:\n    \\begin{align*}\n        n &= 14 & 14 = 3(2) + 8(1)\\\\\n        n &= 15 & 15 = 3(5) + 8(0)\\\\\n        n &= 16 & 16 = 3(0) + 8(2)\\\\\n    \\end{align*}\n    Induction step:\n    \\begin{align*}\n        hypothesis &\\rightarrow \\forall j < k,\\ j = 3x + 8y\\\\\n        goal &\\rightarrow k = 3x + 8y\\\\\n        case (1) &\\rightarrow k\\ is\\ multiple\\ of\\ three \\implies y = 0\\ and\\ x \\in N\\\\\n        case (2) &\\rightarrow k\\ is\\ multiple\\ of\\ eigth \\implies x = 0\\ and\\ y \\in N\\\\\n        case (3) &\\rightarrow k\\ is\\ not\\ multiple\\ of\\ any \\implies y \\in N\\ and\\ x \\in N\\\\\n    \\end{align*}\n    \\item Show by induction that for every natural number $n$, $A(1,n) = n+2$, where $A$ is the Ackermann function.\n    \\[   \n    A(m,n) = \n    \\begin{cases}\n        n + 1 &\\quad if\\ m=0\\\\\n        A(m-1, 1) &\\quad if\\ m >0\\ and\\ n=0\\\\\n        A(m-1, A(m, n - 1)) &\\quad if\\ m >0\\ and\\ n >0\\\\\n    \\end{cases}\n    \\]\n    Base case:\n    \\begin{align*}\n        n &= 0 & A(1, 0) &= A(0, 1)\\\\\n        & & &=2\\\\\n        & & &=(0) +2\\\\\n        n &= 1 & A(1, 1) &= A(0, A(1, 0))\\\\\n        & & &=A(0, 2)\\\\\n        & & &=3\\\\\n        & & &=(1) +2\\\\\n    \\end{align*}\n    Induction step:\n    \\begin{align*}\n        hypothesis &\\rightarrow \\forall j < k,\\ A(1,j) = j + 2\\\\\n        goal &\\rightarrow A(1,k) = k + 2\\\\\n        A(1, k + 1) &= (k + 1) + 2\\\\\n        &= A(0, A(1, k))\\\\\n        &= A(1, k) +1\\\\\n        &= (k + 2) +1\\\\\n        A(1, k + 1) &= k + 3\\\\\n        &\\therefore A(1,k) = k + 2\n    \\end{align*}\n\\end{enumerate}\n\n\\end{document}", "meta": {"hexsha": "92db2c344c21a2a8900ff482ac20024bea94523f", "size": 8428, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/Homework1_4.tex", "max_stars_repo_name": "edjacob25/Applied-Maths", "max_stars_repo_head_hexsha": "0a0f8e5b88083a1b0ec85069efbf266b6a12c741", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Homework/Homework1_4.tex", "max_issues_repo_name": "edjacob25/Applied-Maths", "max_issues_repo_head_hexsha": "0a0f8e5b88083a1b0ec85069efbf266b6a12c741", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework/Homework1_4.tex", "max_forks_repo_name": "edjacob25/Applied-Maths", "max_forks_repo_head_hexsha": "0a0f8e5b88083a1b0ec85069efbf266b6a12c741", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.625, "max_line_length": 259, "alphanum_fraction": 0.4747271001, "num_tokens": 3401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8947894625955064, "lm_q1q2_score": 0.8019562845167167}}
{"text": "\n\\subsection{Gradient}\n\nIn a scalar field we can calculate the partial derivative at any point with respect to one input.\n\nWe may wish to consider these collectively. To do that we use the gradient operator.\n\nWe previously introduced the Del operator where:\n\n\\(\\nabla =(\\sum_{i=1}^n e_i\\dfrac{\\delta }{\\delta x_i})\\)\n\nWhere \\(e\\) are the basis vectors.\n\nThis on its own means nothing. It is similar to the partial differentiation function.\n\nWe now multiply Del by the function. This gives us:\n\n\\(\\nabla f=(\\sum_{i=1}^n e_i\\dfrac{\\delta f}{\\delta x_i})\\). This gives us a vector in the underlying vector space.\n\nThis is the gradient.\n\n", "meta": {"hexsha": "541ef472be59c06c3b115ee0c781ea46c82e843f", "size": 634, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/multiScalar/01-03-gradient.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/multiScalar/01-03-gradient.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/multiScalar/01-03-gradient.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8181818182, "max_line_length": 115, "alphanum_fraction": 0.7397476341, "num_tokens": 163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248259606259, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.8018452724805204}}
{"text": "\\renewcommand{\\Pr}{\\text{Pr}}\n\\newcommand{\\Var}{\\text{Var}}\n\n\\chapter{Probability}\n\nBefore we can discuss probablistic and randomized algorithms, we must\nfirst develop the tools necessary to rigorously discuss probability.\n\nWe are concerned with the probability of sets of events, and for\nsimplicity we will simply call these sets events.\n\nThe probability of a event $A$ is $\\Pr(A)$.  The probability of an\nevent $A$ given that event $B$ has occured is $\\Pr(A | B)$.\n\nThe probability of events $A$ and $B$ both happening is\n\n\\begin{center}\n\\begin{math}\n\\Pr(A \\cap B)\n= \\Pr(A|B)\\Pr(B) = \\Pr(A)\\Pr(B|A)\n\\end{math}\n\\end{center}\n\nwhich is the definition of \\emph{conjunctive probability}.\n\nThe probability of either events $A$ or $B$ happening is\n\n\\begin{center}\n\\begin{math}\n  \\Pr(A \\cup B)\n  = \\Pr(A) + \\Pr(B) - \\Pr(A \\cap B)\n\\end{math}\n\\end{center}\n\nwhich is the definition of \\emph{disjunctive probability}.\n\nIf the outcome of event $A$ does not affect that of $B$, we say $A$\nand $B$ are \\emph{independent}.\n\nIf we have a set of independent events $S$, from the definition of\ndisjunctive probability we get\n\n\\begin{displaymath}\n  %\n  \\Pr \\left( \\bigcup_{s \\in S} s \\right) = \\sum_{s \\in S} \\Pr(s)\n  %\n\\end{displaymath}\n\nwhich is the \\emph{linearity of independent probability}.\n\n\\section{Linearity of Expectation}\n\nOften, we are interested in the outcome of some event with intrinsic\nvalue, such as the result of rolling a die.  In this case, we may be\ninterested in the average value.  Since not all values are equally\nlikely, it is important to weight each value by its probability.  We\ncall such a weighted average the \\emph{Expected Value}.\n\nThe expected value of a random variable $X$ is\n\n\\begin{displaymath}\n  %\n  E(X) = \\sum_{x \\in X} x \\cdot \\Pr(x)\n  %\n\\end{displaymath}\n\nwhich is the definition of \\emph{expectation}.\n\nIf we have two events $X$ and $Y$, we have\n\n\\begin{center}\n\\begin{math}\n  E(X + Y) = E(X) + E(Y)\n\\end{math}\n\\end{center}\n\nwhich is the \\emph{linearity of expectation}.\n\n\\section{Markov's Inequality}\n\nWe often wish to establish bounds on probability, for which one\nimportant result is for any random variable $X$ and $a > 0$\n\n\\begin{center}\n\\begin{math}\n  \\Pr(X \\geq a) \\leq \\frac{E(X)}{a}\n\\end{math}\n\\end{center}\n\nwhich is \\emph{Markov's Inequality}.\n\n\\section{Variance}\n\nGiven a random variable $X$ we have\n\n\\begin{center}\n  \\begin{math}\n    \\Var (X) = E(X^2) - E(X)^2    \n  \\end{math}\n\\end{center}\n\nwhich is the definition of \\emph{variance}.\n\nIf we have an independent and identically distributed set of events\n$X$ then\n\n\\begin{displaymath}\n  \\Var (\\sum_{x \\in X} x) = \\sum_{x \\in X} \\Var (x)\n\\end{displaymath}\n\n\\section{Chebyshev's Inequality}\n\nFor any random variable $X$ and $a > 0$ we have\n\n\\begin{center}\n  \\begin{math}\n    \\Pr ( | X - E(X) | \\geq a ) \\leq \\frac{\\Var{X}}{a^2}\n  \\end{math}\n\\end{center}\n\nwhich is \\emph{Chebyshev's Inequality}.\n\n\\section{Chernoff Bounds}\n\nWhere $X$ is the sum of indicator random variables, for any $ \\epsilon\n> 0 $ we have\n\n\\begin{center}\n  \\begin{math}\n    \\Pr ( X \\geq ( 1 + \\epsilon ) E(X) ) \\leq e^{ \\frac{-\\epsilon^2 E(X)}{3}}\n  \\end{math}\n\\end{center}\n\nand\n\n\\begin{center}\n  \\begin{math}\n    \\Pr ( X \\geq ( 1 - \\epsilon ) E(X) ) \\leq e^{ \\frac{-\\epsilon^2 E(X)}{2}}\n  \\end{math}\n\\end{center}\n\nwhich are \\emph{Chernoff Bounds}.\n", "meta": {"hexsha": "4f78a42cf59aad5b24adc6f13239577a1e7f9d83", "size": 3304, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability.tex", "max_stars_repo_name": "SteamedPears/AllTheAlgorithms", "max_stars_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-12T19:16:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-01T03:13:05.000Z", "max_issues_repo_path": "probability.tex", "max_issues_repo_name": "SteamedPears/AllTheAlgorithms", "max_issues_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "probability.tex", "max_forks_repo_name": "SteamedPears/AllTheAlgorithms", "max_forks_repo_head_hexsha": "13a04cc4a6bd8dec5e35c1a42b96680d47a98962", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1048951049, "max_line_length": 77, "alphanum_fraction": 0.6828087167, "num_tokens": 1082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629193, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.8018182489446831}}
{"text": "\\section{SVD as an eigen problem}\n\\label{sec:svd-lanczos-eigen}\n\nAiming to calculate numerically the SVD factorizations, made\nresearchers reformulate that problem as the quite related\neigen decomposition (or eigenproblem). Such problem consists in\nfinding, for an square matrix $A$, the eigenvalues and\neigenvectors. If we arrange the eigenvectors in an orthogonal matrix\n$Q$ and the eigenvalues in a diagonal matrix $\\Lambda$, the eigen\nproblem can be restated as the following factorization: \\\\\n\n\\[\nA = Q \\Sigma \\trans{Q}\n\\]\n\\hfill\n\nIn order to see the connection between the SVD and the eigenproblem,\nwe need to recall the gramian matrix $\\trans{A}A$ from the theory\nchapter. It was the gramian, which provided the matrix $V$ on the\nfirst place; because the vectors \n$\\vec{v}$ were its eigenvectors (see \\cref{cha:svd-theory}. Finding\nthe matrix $V$ then, can be thought as the eigenproblem for matrix\n$\\trans{A}A$; which can be stated as finding its diagonal\nfactorization $\\suchthat$: \n\n\\begin{equation}\n\\label{eq:eigenprob-doc}\n\\trans{A}A = V\\Sigma^2\\trans{V}\n\\end{equation}\n\\hfill\n\nBut the same is true for matrix $U$, if we now consider the matrix\n$A\\trans{A}$, which can be diagonalized if one finds its eigenvectors\nand place them into the matrix $U$ (the eigenvalues are the same as\nthe gramian): \n\n\\begin{equation}\n\\label{eq:eigenprob-term}\nA\\trans{A} = U\\Sigma^2\\trans{U}\n\\end{equation}\n\\hfill\n\nIt is the second eigenvalue problem equivalence, that is used for this\ndistributed algorithm of chapter \\cref{cha:svd-dist}. Per the SVD\nfactorization $A = U\\Sigma\\trans{V}$, if we have the original matrix\n$A$, plus the diagonal $\\Sigma$ and the matrix $U$;  we can\nreconstruct the matrix $V$ (if required): \n\n\\[\n\\trans{V} = \\inv{S} \\trans{U} A = P A\n\\]\n\\hfill\n\nThe matrix $P = \\inv{S} \\trans{U}$ is called the projection matrix, and\nis used in LSI for ``folding-in'' new document vectors \\vec{x}, by\ncalculating $P\\vec{x}$; that is, the matrix $P$ is used as a\npredictive (rather than descriptive) model, to predict where the\nposition of document \\vec{x} will be in the latent space. \\\\\n\nFor this chapter though, we could use either eigenproblem from\n\\cref{eq:eigenprob-doc} or \\cref{eq:eigenprob-term}. Actually, the literature\noriginally reported the former, perhaps due the early shape of the\nmatrices used for LSI (more terms than documents). Today's LSI\napplications have much more documents than terms, but still these\nearly algorithms are useful, as we will see in \\cref{cha:svd-dist}\n(where the original matrix is split into several submatrices, which do\nhave the shape expected by Lanczos algorithm that we document here).\n\n", "meta": {"hexsha": "026403f032c5c7c33823147e86bcd82ee31f7d57", "size": 2642, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-lanczos-eigen.tex", "max_stars_repo_name": "rzavalet/svd-lsi-project-master", "max_stars_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "svd-lanczos-eigen.tex", "max_issues_repo_name": "rzavalet/svd-lsi-project-master", "max_issues_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "svd-lanczos-eigen.tex", "max_forks_repo_name": "rzavalet/svd-lsi-project-master", "max_forks_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2898550725, "max_line_length": 77, "alphanum_fraction": 0.7551097653, "num_tokens": 751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055544, "lm_q2_score": 0.9173026646724284, "lm_q1q2_score": 0.8017933859731301}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find the algebraic and geometric multiplicity of each eigenvalue of\n  the following matrices. Which of the matrices are diagonalizable?\n  \\begin{equation*}\n    (a)\\quad\n    A = \\begin{mymatrix}{rr} 1 & 1 \\\\ -1 & 3 \\end{mymatrix},\n    \\quad\n    (b)\\quad\n    B = \\begin{mymatrix}{rr} -7 & 8 \\\\ -4 & 5 \\end{mymatrix},\n  \\end{equation*}\n  \\begin{equation*}\n    (c)\\quad\n    C = \\begin{mymatrix}{rrr}\n      2 & -1 & -1 \\\\\n      0 & 4 & 2 \\\\\n      0 & -1 & 1 \\\\\n    \\end{mymatrix},\n    \\quad\n    (d)\\quad\n    D = \\begin{mymatrix}{rrr}\n      3 & 1 & -1 \\\\\n      0 & 2 & 1 \\\\\n      0 & -1 & 4 \\\\\n    \\end{mymatrix},\n    \\quad\n    (e)\\quad\n    E = \\begin{mymatrix}{rrr}\n      -2 & 0 & 1 \\\\\n      -1 & -1 & 1 \\\\\n      -2 & 1 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item $\\eigenvar=2$ has algebraic multiplicity 2 and geometric\n      multiplicity 1. Since the sum of the geometric multiplicities of\n      all eigenvalues is $1$, the matrix is not diagonalizable.\n    \\item $\\eigenvar=1$ has algebraic and geometric\n      multiplicity 1; $\\eigenvar=-3$ has algebraic and geometric\n      multiplicity 1. Since the sum of the geometric multiplicities is\n      $2$, the matrix is diagonalizable.\n    \\item $\\eigenvar=2$ has algebraic and geometric\n      multiplicity 2, $\\eigenvar=3$ has algebraic and geometric\n      multiplicity 1. Since the sum of the geometric multiplicities is\n      $3$, the matrix is diagonalizable.\n    \\item $\\eigenvar=3$ has algebraic multiplicity 3 and geometric\n      multiplicity 2. Since the sum of the geometric multiplicities of\n      all eigenvalues is $2$, the matrix is not diagonalizable.\n    \\item $\\eigenvar = -1$ has algebraic multiplicity 3 and geometric\n      multiplicity 1. Since the sum of the geometric multiplicities of\n      all eigenvalues is $1$, the matrix is not diagonalizable.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Determine which of the following matrices are diagonalizable.\n  \\begin{enumerate}\n  \\item $A$ is a $3\\times 3$-matrix with eigenvalues $-1$ and $3$. The\n    eigenvalue $-1$ has algebraic multiplicity $2$ and geometric\n    multiplicity $1$. The eigenvalue $3$ has algebraic and geometric\n    multiplicity $1$.\n  \\item $B$ is a $4\\times 4$-matrix with eigenvalues $2$ and $-2$. The\n    eigenvalue $2$ has algebraic and geometric multiplicity $1$. The\n    eigenvalue $-2$ has algebraic and geometric multiplicity $3$.\n  \\item $C$ is a $5\\times 5$-matrix with eigenvalues $1$ and $3$. The\n    eigenvalue $1$ has algebraic and geometric multiplicity $2$, and\n    the eigenvalue $3$ has algebraic and geometric multiplicity $1$.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item Not diagonalizable.\n    \\item Diagonalizable.\n    \\item Not diagonalizable.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "71f81c21efeb5ba8841553e6b670402c27252f49", "size": 2857, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Eigenvalues-Properties.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Eigenvalues-Properties.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Eigenvalues-Properties.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 35.2716049383, "max_line_length": 70, "alphanum_fraction": 0.6468323416, "num_tokens": 914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241802, "lm_q2_score": 0.9173026601509102, "lm_q1q2_score": 0.801793363967197}}
{"text": "% \n\\chapter{\\label{chap-common}Common knowledge, part 1}\n\nIn this chapter we will consider some well known mathematical theories.\nIf you already know them you may skip reading this chapter (or its\nparts).\n\n\n\\section{Order theory}\n\n\n\\subsection{Posets}\n\\begin{defn}\n\\index{identity relation}The \\emph{identity relation} on a set $A$\nis $\\id_{A}=\\setcond{(a,a)}{a\\in A}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{preorder}A \\emph{preorder} on a set $A$ is a binary relation~$\\sqsubseteq$ on~$A$ which is:\n\\begin{itemize}\n\\item \\emph{reflexive} on $A$ that is $\\opinparens{\\sqsubseteq}\\supseteq\\id_{A}$ or what is the same $\\forall x\\in A:x\\sqsubseteq x$;\n\\item \\emph{transitive} that is $\\opinparens{\\sqsubseteq}\\circ\\opinparens{\\sqsubseteq}\\subseteq\\opinparens{\\sqsubseteq}$\n or what is the same \\[ \\forall x,y,z:(x\\sqsubseteq y\\land y\\sqsubseteq z\\Rightarrow x\\sqsubseteq z). \\]\n\\end{itemize}\n\\end{defn}\n\n\\begin{defn}\n\\index{partial order}A \\emph{partial order} on a set $A$ is a preorder\non $A$ which is \\emph{antisymmetric} that is $\\opinparens{\\sqsubseteq}\\cap\\opinparens{\\sqsubseteq}\\subseteq\\id_A$\nor what is the same \\[ \\forall x,y\\in A:(x\\sqsubseteq y\\land y\\sqsubseteq x\\Rightarrow x=y). \\]\n\\end{defn}\nThe reverse relation is denoted $\\sqsupseteq$.\n\n\\begin{defn}\n\\index{subelement}$a$ is a subelement of $b$ (or what is the same\n$a$ is \\emph{contained} in $b$ or $b$ \\emph{contains} $a$) iff\n$a\\sqsubseteq b$.\\end{defn}\n\\begin{obvious}\nThe reverse of a partial order is also a partial order.\\end{obvious}\n\\begin{defn}\n\\index{set!partially ordered}\\index{poset}A set $A$ together with\na partial order on it is called a \\emph{partially ordered set} (\\emph{poset}\nfor short).\n\\end{defn}\n\nAn example of a poset is the set~$\\mathbb{R}$ of real numbers with $\\mathord{\\sqsubseteq} = \\mathord{\\leq}$.\n\nAnother example is the set~$\\subsets A$ of all subsets of an arbitrary fixed set~$A$ with $\\mathord{\\sqsubseteq} = \\mathord{\\subseteq}$.\nNote that this poset is (in general) not linear (see definition of \\emph{linear} poset below.)\n\n\\begin{defn}\n\\index{partial order!strict}Strict partial order $\\sqsubset$ corresponding\nto the partial order $\\sqsubseteq$ on a set $A$ is defined by the\nformula $\\opinparens{\\sqsubset}=\\opinparens{\\sqsubseteq}\\setminus\\id_{A}$.\nIn other words, \\[ a\\sqsubset b\\Leftrightarrow a\\sqsubseteq b\\land a\\ne b. \\]\n\\end{defn}\n\nAn example of strict partial order is~$<$ on the set~$\\mathbb{R}$ of real numbers.\n\n\\begin{defn}\n\\index{partial order!restricted}A partial order on a set $A$ \\emph{restricted}\nto a set $B\\subseteq A$ is $\\opinparens{\\sqsubseteq}\\cap(B\\times B)$.\\end{defn}\n\\begin{obvious}\nA partial order on a set $A$ restricted to a set $B\\subseteq A$\nis a partial order on $B$.\\end{obvious}\n\\begin{defn}\n~\n\\begin{itemize}\n\\item \\index{least element}The \\emph{least} element $\\bot$ of a poset\n$\\mathfrak{A}$ is defined by the formula $\\forall a\\in\\mathfrak{A}:\\bot\\sqsubseteq a$.\n\\item \\index{greatest element}The \\emph{greatest} element $\\top$ of a\nposet $\\mathfrak{A}$ is defined by the formula $\\forall a\\in\\mathfrak{A}:\\top\\sqsupseteq a$.\n\\end{itemize}\n\\end{defn}\n\\begin{prop}\nThere exist no more than one least element and no more than one greatest\nelement (for a given poset).\\end{prop}\n\\begin{proof}\nBy antisymmetry.\\end{proof}\n\\begin{defn}\n\\index{dual!order}The \\emph{dual} order for $\\sqsubseteq$ is $\\sqsupseteq$.\\end{defn}\n\\begin{obvious}\nDual of a partial order is a partial order.\\end{obvious}\n\\begin{defn}\n\\index{dual!poset}The \\emph{dual} poset for a poset $(A,\\mathord{\\sqsubseteq})$\nis the poset $(A,\\mathord{\\sqsupseteq})$.\n\\end{defn}\nI will denote dual of a poset~$\\mathfrak{A}$ as $(\\dual\\mathfrak{A})$\nand dual of an element~$a\\in\\mathfrak{A}$ (that is the same element\nin the dual poset) as $(\\dual a)$.\n\n\\index{duality!partial order}Below we will sometimes use \\emph{duality}\nthat is replacement of the partial order and all related operations\nand relations with their duals. In other words, it is enough to prove\na theorem for an order $\\sqsubseteq$ and the similar theorem for\n$\\sqsupseteq$ follows by duality.\n\n\\begin{defn}\n\\index{bounded above}\n\\index{bounded below}\nA subset~$P$ of a poset~$\\mathfrak{A}$ is called \\emph{bounded\nabove} if there exists $t\\in\\mathfrak{A}$ such that\n$\\forall x\\in P:t\\sqsupseteq x$. \\emph{Bounded below} is\ndefined dually.\n\\end{defn}\n\n\\subsubsection{Intersecting and joining elements}\n\nLet $\\mathfrak{A}$ be a poset.\n\\begin{defn}\n\\index{intersecting elements}Call elements $a$ and $b$ of $\\mathfrak{A}$\n\\emph{intersecting}, denoted $a\\nasymp b$, when there exists a non-least\nelement $c$ such that $c\\sqsubseteq a\\land c\\sqsubseteq b$.\n\\end{defn}\n\n\\begin{defn}\n$a\\asymp b\\eqdef\\lnot(a\\nasymp b)$.\\end{defn}\n\\begin{obvious}\n$a_{0}\\nasymp b_{0}\\land a_{1}\\sqsupseteq a_{0}\\land b_{1}\\sqsupseteq b_{0}\\Rightarrow a_{1}\\nasymp b_{1}$.\\end{obvious}\n\\begin{defn}\n\\index{joining elements}I call elements $a$ and $b$ of $\\mathfrak{A}$\n\\emph{joining} and denote $a\\equiv b$ when there is no a non-greatest\nelement $c$ such that $c\\sqsupseteq a\\land c\\sqsupseteq b$.\n\\end{defn}\n\n\\begin{defn}\n$a\\nequiv b\\eqdef\\lnot(a\\equiv b)$.\\end{defn}\n\\begin{obvious}\nIntersecting is the dual of non-joining.\n\\end{obvious}\n\n\\begin{obvious}\n$a_{0}\\equiv b_{0}\\land a_{1}\\sqsupseteq a_{0}\\land b_{1}\\sqsupseteq b_{0}\\Rightarrow a_{1}\\equiv b_{1}$.\n\\end{obvious}\n\n\\subsection{Linear order}\n\\begin{defn}\n\\index{linearly ordered set}A poset $\\mathfrak{A}$ is called \\emph{linearly\nordered set} (or what is the same, \\emph{totally ordered set}) if\n$a\\sqsupseteq b\\lor b\\sqsupseteq a$ for every $a,b\\in\\mathfrak{A}$.\\end{defn}\n\\begin{example}\nThe set of real numbers with the customary order is a linearly ordered\nset.\\end{example}\n\\begin{defn}\n\\index{chain}A set $X\\in\\subsets\\mathfrak{A}$ where $\\mathfrak{A}$\nis a poset is called \\emph{chain} if $\\mathfrak{A}$ restricted to\n$X$ is a total order.\n\\end{defn}\n\n\\subsection{Meets and joins}\n\nLet $\\mathfrak{A}$ be a poset.\n\\begin{defn}\n\\index{least element}Given a set $X\\in\\subsets\\mathfrak{A}$ the\n\\emph{least element} (also called \\emph{minimum} and denoted $\\min X$)\nof $X$ is such $a\\in X$ that $\\forall x\\in X:a\\sqsubseteq x$.\n\\end{defn}\nLeast element does not necessarily exists. But if it exists:\n\\begin{prop}\nFor a given $X\\in\\subsets\\mathfrak{A}$ there exist no more than one\nleast element.\\end{prop}\n\\begin{proof}\nIt follows from anti-symmetry.\n\\end{proof}\n\\emph{Greatest element} is the dual of least element:\n\\begin{defn}\n\\index{greatest element}Given a set $X\\in\\subsets\\mathfrak{A}$ the\n\\emph{greatest element} (also called \\emph{maximum} and denoted $\\max X$)\nof $X$ is such $a\\in X$ that $\\forall x\\in X:a\\sqsupseteq x$.\\end{defn}\n\\begin{rem}\nLeast and greatest elements of a set $X$ is a trivial generalization\nof the above defined least and greatest element for the entire poset.\\end{rem}\n\\begin{defn}\n~\n\\begin{itemize}\n\\item \\index{minimal element}A \\emph{minimal} element of a set $X\\in\\subsets\\mathfrak{A}$\nis such $a\\in\\mathfrak{A}$ that $\\nexists x\\in X:a\\sqsupset x$.\n\\item \\index{maximal element}A \\emph{maximal} element of a set $X\\in\\subsets\\mathfrak{A}$\nis such $a\\in\\mathfrak{A}$ that $\\nexists x\\in X:a\\sqsubset x$.\n\\end{itemize}\n\\end{defn}\n\\begin{rem}\nMinimal element is not the same as minimum, and maximal element is\nnot the same as maximum.\\end{rem}\n\\begin{obvious}\n~\n\\begin{enumerate}\n\\item The least element (if it exists) is a minimal element.\n\\item The greatest element (if it exists) is a maximal element.\n\\end{enumerate}\n\\end{obvious}\n\\begin{xca}\nShow that there may be more than one minimal and more than one maximal\nelement for some poset.\\end{xca}\n\\begin{defn}\n\\index{bounds!upper}\\emph{Upper bounds} of a set $X$ is the set\n$\\setcond{y\\in\\mathfrak{A}}{\\forall x\\in X:y\\sqsupseteq x}$.\n\\end{defn}\nThe dual notion:\n\\begin{defn}\n\\index{bounds!lower}\\emph{Lower bounds} of a set $X$ is the set\n$\\setcond{y\\in\\mathfrak{A}}{\\forall x\\in X:y\\sqsubseteq x}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{join}\\index{supremum}\\emph{Join} $\\bigsqcup X$ (also called\n\\emph{supremum} and denoted ``$\\sup X$'') of a set $X$ is the\nleast element of its upper bounds (if it exists).\n\\end{defn}\n\n\\begin{defn}\n\\index{meet}\\index{infimum}\\emph{Meet} $\\bigsqcap X$ (also called\n\\emph{infimum} and denoted ``$\\inf X$'') of a set $X$ is the greatest\nelement of its lower bounds (if it exists).\n\\end{defn}\nWe will also denote $\\bigsqcup_{i\\in X}f(i)=\\bigsqcup\\setcond{f(i)}{x\\in X}$\nand $\\bigsqcap_{i\\in X}f(i)=\\bigsqcap\\setcond{f(i)}{x\\in X}$.\n\nWe will write $b=\\bigsqcup X$ when $b\\in\\mathfrak{A}$ is the join\nof $X$ or say that $\\bigsqcup X$ does not exist if there are no\nsuch $b\\in\\mathfrak{A}$. (And dually for meets.)\n\\begin{xca}\nProvide an example of $\\bigsqcup X\\notin X$ for some set $X$ on\nsome poset.\\end{xca}\n\\begin{prop}\n~\n\\begin{enumerate}\n\\item If $b$ is the greatest element of $X$ then $\\bigsqcup X=b$.\n\\item If $b$ is the least element of $X$ then $\\bigsqcap X=b$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\nWe will prove only the first as the second is dual.\n\nLet $b$ be the greatest element of $X$. Then upper bounds of $X$\nare $\\setcond{y\\in\\mathfrak{A}}{y\\sqsupseteq b}$. Obviously $b$\nis the least element of this set, that is the join.\\end{proof}\n\\begin{defn}\n\\index{join!binary}\\emph{Binary joins and meets} are defined by the\nformulas\n\\[\nx\\sqcup y=\\bigsqcup\\{x,y\\}\\quad\\text{and}\\quad x\\sqcup y=\\bigsqcap\\{x,y\\}.\n\\]\n\\end{defn}\n\\begin{obvious}\n$\\sqcup$ and $\\sqcap$ are symmetric operations (whenever these are\ndefined for given $x$ and $y$).\\end{obvious}\n\\begin{thm}\n~\n\\begin{enumerate}\n\\item If $\\bigsqcup X$ exists then $y\\sqsupseteq\\bigsqcup X\\Leftrightarrow\\forall x\\in X:y\\sqsupseteq x$.\n\\item If $\\bigsqcap X$ exists then $y\\sqsubseteq\\bigsqcap X\\Leftrightarrow\\forall x\\in X:y\\sqsubseteq x$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nI will prove only the first as the second follows by duality.\n\n$y\\sqsupseteq\\bigsqcup X\\Leftrightarrow y\\text{ is an upper bound for }X\\Leftrightarrow\\forall x\\in X:y\\sqsupseteq x$.\n\\end{proof}\n\\begin{cor}\n~\n\\begin{enumerate}\n\\item If $a\\sqcup b$ exists then $y\\sqsupseteq a\\sqcup b\\Leftrightarrow y\\sqsupseteq a\\land y\\sqsupseteq b$.\n\\item If $a\\sqcap b$ exists then $y\\sqsubseteq a\\sqcap b\\Leftrightarrow y\\sqsubseteq a\\land y\\sqsubseteq b$.\n\\end{enumerate}\n\\end{cor}\nI will denote meets and joins for a specific poset $\\mathfrak{A}$\nas $\\bigsqcap^{\\mathfrak{A}}$, $\\bigsqcup^{\\mathfrak{A}}$, $\\sqcap^{\\mathfrak{A}}$,\n$\\sqcup^{\\mathfrak{A}}$.\n\n\n\\subsection{Semilattices}\n\\begin{defn}\n~\n\\begin{enumerate}\n\\item \\index{semilattice!join-semilattice}A \\emph{join-semilattice} is\na poset $\\mathfrak{A}$ such that $a\\sqcup b$ is defined for every\n$a,b\\in\\mathfrak{A}$.\n\\item \\index{semilattice!meet-semilattice}A \\emph{meet-semilattice} is\na poset $\\mathfrak{A}$ such that $a\\sqcap b$ is defined for every\n$a,b\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{defn}\n\\begin{thm}\n~\n\\begin{enumerate}\n\\item The operation $\\sqcup$ is associative for any join-semilattice.\n\\item The operation $\\sqcap$ is associative for any meet-semilattice.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nI will prove only the first as the second follows by duality.\n\nWe need to prove $(a\\sqcup b)\\sqcup c=a\\sqcup(b\\sqcup c)$ for every\n$a,b,c\\in\\mathfrak{A}$.\n\nTaking into account the definition of join, it is enough to prove\nthat\n\\[\nx\\sqsupseteq(a\\sqcup b)\\sqcup c\\Leftrightarrow x\\sqsupseteq a\\sqcup(b\\sqcup c)\n\\]\nfor every $x\\in\\mathfrak{A}$. Really, this follows from the chain\nof equivalences:\n\\begin{align*}\nx\\sqsupseteq(a\\sqcup b)\\sqcup c & \\Leftrightarrow\\\\\nx\\sqsupseteq a\\sqcup b\\land x\\sqsupseteq c & \\Leftrightarrow\\\\\nx\\sqsupseteq a\\land x\\sqsupseteq b\\land x\\sqsupseteq c & \\Leftrightarrow\\\\\nx\\sqsupseteq a\\land x\\sqsupseteq b\\sqcup c & \\Leftrightarrow\\\\\nx\\sqsupseteq a\\sqcup(b\\sqcup c).\n\\end{align*}\n\\end{proof}\n\\begin{obvious}\n$a\\nasymp b$ iff $a\\sqcap b$ is non-least, for every elements $a$,\n$b$ of a meet-semilattice.\n\\end{obvious}\n\n\\begin{obvious}\n$a\\equiv b$ iff $a\\sqcup b$ is the greatest element, for every elements\n$a$, $b$ of a join-semilattice.\n\\end{obvious}\n\n\\subsection{Lattices and complete lattices}\n\\begin{defn}\n\\index{poset!bounded}A \\emph{bounded} poset is a poset having both\nleast and greatest elements.\n\\end{defn}\n\n\\begin{defn}\n\\index{lattice}\\emph{Lattice} is a poset which is both join-semilattice\nand meet-semilattice.\n\\end{defn}\n\n\\begin{defn}\n\\index{lattice!complete}A \\emph{complete lattice} is a poset $\\mathfrak{A}$\nsuch that for every $X\\in\\subsets\\mathfrak{A}$ both $\\bigsqcup X$\nand $\\bigsqcap X$ exist.\\end{defn}\n\\begin{obvious}\nEvery complete lattice is a lattice.\\end{obvious}\n\\begin{prop}\nEvery complete lattice is a bounded poset.\\end{prop}\n\\begin{proof}\n$\\bigsqcup\\emptyset$ is the least and $\\bigsqcap\\emptyset$ is the\ngreatest element.\\end{proof}\n\\begin{thm}\nLet $\\mathfrak{A}$ be a poset.\n\\begin{enumerate}\n\\item If $\\bigsqcup X$ is defined for every $X\\in\\subsets\\mathfrak{A}$,\nthen $\\mathfrak{A}$ is a complete lattice.\n\\item If $\\bigsqcap X$ is defined for every $X\\in\\subsets\\mathfrak{A}$,\nthen $\\mathfrak{A}$ is a complete lattice.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nSee \\cite{pm:complete-lattice-criteria} or any lattice theory reference.\\end{proof}\n\\begin{obvious}\nIf $X\\subseteq Y$ for some $X,Y\\in\\subsets\\mathfrak{A}$ where $\\mathfrak{A}$\nis a complete lattice, then\n\\begin{enumerate}\n\\item $\\bigsqcup X\\sqsubseteq\\bigsqcup Y$;\n\\item $\\bigsqcap X\\sqsupseteq\\bigsqcap Y$.\n\\end{enumerate}\n\\end{obvious}\n\\begin{prop}\nIf $S\\in\\subsets\\subsets\\mathfrak{A}$ then for every complete lattice\n$\\mathfrak{A}$\n\\begin{enumerate}\n\\item $\\bigsqcup\\bigcup S=\\bigsqcup_{X\\in S}\\bigsqcup X$;\n\\item $\\bigsqcap\\bigcup S=\\bigsqcap_{X\\in S}\\bigsqcap X$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\nWe will prove only the first as the second is dual.\n\nBy definition of joins, it is enough to prove $y\\sqsupseteq\\bigsqcup\\bigcup S\\Leftrightarrow y\\sqsupseteq\\bigsqcup_{X\\in S}\\bigsqcup X$.\n\nReally,\n\\begin{align*}\ny\\sqsupseteq\\bigsqcup\\bigcup S & \\Leftrightarrow\\\\\n\\forall x\\in\\bigcup S:y\\sqsupseteq x & \\Leftrightarrow\\\\\n\\forall X\\in S\\forall x\\in X:y\\sqsupseteq x & \\Leftrightarrow\\\\\n\\forall X\\in S:y\\sqsupseteq\\bigsqcup X & \\Leftrightarrow\\\\\ny\\sqsupseteq\\bigsqcup_{X\\in S}\\bigsqcup X.\n\\end{align*}\n\\end{proof}\n\\begin{defn}\nA \\emph{sublattice} of a lattice is it subset closed regarding~$\\sqcup$\nand~$\\sqcap$.\\end{defn}\n\\begin{obvious}\nSublattice with induced order is also a lattice.\n\\end{obvious}\n\n\\subsection{Distributivity of lattices}\n\\begin{defn}\n\\index{lattice!distributive}A \\emph{distributive} lattice is such\nlattice $\\mathfrak{A}$ that for every $x,y,z\\in\\mathfrak{A}$\n\\begin{enumerate}\n\\item $x\\sqcap(y\\sqcup z)=(x\\sqcap y)\\sqcup(x\\sqcap z)$;\n\\item $x\\sqcup(y\\sqcap z)=(x\\sqcup y)\\sqcap(x\\sqcup z)$.\n\\end{enumerate}\n\\end{defn}\n\\begin{thm}\nFor a lattice to be distributive it is enough just one of the conditions:\n\\begin{enumerate}\n\\item $x\\sqcap(y\\sqcup z)=(x\\sqcap y)\\sqcup(x\\sqcap z)$;\n\\item $x\\sqcup(y\\sqcap z)=(x\\sqcup y)\\sqcap(x\\sqcup z)$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\n\\begin{align*}\n(x\\sqcup y)\\sqcap(x\\sqcup z) & =\\\\\n((x\\sqcup y)\\sqcap x)\\sqcup((x\\sqcup y)\\sqcap z) & =\\\\\nx\\sqcup((x\\sqcap z)\\sqcup(y\\sqcap z)) & =\\\\\n(x\\sqcup(x\\sqcap z))\\sqcup(y\\sqcap z) & =\\\\\nx\\sqcup(y\\sqcap z)\n\\end{align*}\n\n\n(applied $x\\sqcap(y\\sqcup z)=(x\\sqcap y)\\sqcup(x\\sqcap z)$ twice).\n\\end{proof}\n\n\\subsection{Difference and complement}\n\\begin{defn}\n\\index{difference}\\index{substractive}Let $\\mathfrak{A}$ be a distributive\nlattice with least element $\\bot$. The \\emph{difference} (denoted\n$a\\setminus b$) of elements $a$ and $b$ is such $c\\in\\mathfrak{A}$\nthat $b\\sqcap c=\\bot$ and $a\\sqcup b=b\\sqcup c$. I will call $b$\n\\emph{substractive} from \\textbf{$a$} when $a\\setminus b$ exists.\\end{defn}\n\\begin{thm}\nIf $\\mathfrak{A}$ is a distributive lattice with least element $\\bot$,\nthere exists no more than one difference of elements $a$, $b$.\\end{thm}\n\\begin{proof}\nLet $c$ and $d$ be both differences $a\\setminus b$. Then $b\\sqcap c=b\\sqcap d=\\bot$\nand $a\\sqcup b=b\\sqcup c=b\\sqcup d$. So\n\\[\nc=c\\sqcap(b\\sqcup c)=c\\sqcap(b\\sqcup d)=(c\\sqcap b)\\sqcup(c\\sqcap d)=\\bot\\sqcup(c\\sqcap d)=c\\sqcap d.\n\\]\n\n\nSimilarly $d=d\\sqcap c$. Consequently $c=c\\sqcap d=d\\sqcap c=d$.\\end{proof}\n\\begin{defn}\n\\index{complementive}I will call $b$ \\emph{complementive} to $a$\niff there exists $c\\in\\mathfrak{A}$ such that $b\\sqcap c=\\bot$ and\n$b\\sqcup c=a$.\\end{defn}\n\\begin{prop}\n$b$ is complementive to $a$ iff $b$ is substractive from $a$ and\n$b\\sqsubseteq a$.\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Leftarrow$}] Obvious.\n\\item [{$\\Rightarrow$}] We deduce $b\\sqsubseteq a$ from $b\\sqcup c=a$.\nThus $a\\sqcup b=a=b\\sqcup c$.\n\\end{description}\n\\end{proof}\n\\begin{prop}\nIf $b$ is complementive to $a$ then $(a\\setminus b)\\sqcup b=a$.\\end{prop}\n\\begin{proof}\nBecause $b\\sqsubseteq a$ by the previous proposition.\\end{proof}\n\\begin{defn}\n\\index{complement}Let $\\mathfrak{A}$ be a bounded distributive lattice.\nThe \\emph{complement} (denoted $\\bar{a}$) of an element $a\\in\\mathfrak{A}$\nis such $b\\in\\mathfrak{A}$ that $a\\sqcap b=\\bot$ and $a\\sqcup b=\\top$.\\end{defn}\n\\begin{prop}\nIf $\\mathfrak{A}$ is a bounded distributive lattice then $\\bar{a}=\\top\\setminus a$.\\end{prop}\n\\begin{proof}\n$b=\\bar{a}\\Leftrightarrow b\\sqcap a=\\bot\\land b\\sqcup a=\\top\\Leftrightarrow b\\sqcap a=\\bot\\land\\top\\sqcup a=a\\sqcup b\\Leftrightarrow b=\\top\\setminus a$.\\end{proof}\n\\begin{cor}\nIf $\\mathfrak{A}$ is a bounded distributive lattice then exists no\nmore than one complement of an element $a\\in\\mathfrak{A}$.\\end{cor}\n\\begin{defn}\n\\index{complemented!element}An element of bounded distributive lattice\nis called \\emph{complemented} when its complement exists.\n\\end{defn}\n\n\\begin{defn}\n\\index{complemented!lattice}A distributive lattice is a \\emph{complemented\nlattice} iff every its element is complemented.\\end{defn}\n\\begin{prop}\nFor a distributive lattice $(a\\setminus b)\\setminus c=a\\setminus(b\\sqcup c)$\nif $a\\setminus b$ and $(a\\setminus b)\\setminus c$ are defined.\\end{prop}\n\\begin{proof}\n$((a\\setminus b)\\setminus c)\\sqcap c=\\bot$; $((a\\setminus b)\\setminus c)\\sqcup c=(a\\setminus b)\\sqcup c$;\n$(a\\setminus b)\\sqcap b=\\bot$; $(a\\setminus b)\\sqcup b=a\\sqcup b$.\n\nWe need to prove $((a\\setminus b)\\setminus c)\\sqcap(b\\sqcup c)=\\bot$\nand $((a\\setminus b)\\setminus c)\\sqcup(b\\sqcup c)=a\\sqcup(b\\sqcup c)$.\n\nIn fact,\n\\begin{align*}\n((a\\setminus b)\\setminus c)\\sqcap(b\\sqcup c) & =\\\\\n(((a\\setminus b)\\setminus c)\\sqcap b)\\sqcup(((a\\setminus b)\\setminus c)\\sqcap c) & =\\\\\n(((a\\setminus b)\\setminus c)\\sqcap b)\\sqcup\\bot & =\\\\\n((a\\setminus b)\\setminus c)\\sqcap b & \\sqsubseteq\\\\\n(a\\setminus b)\\sqcap b & =\\bot,\n\\end{align*}\n\n\nso $((a\\setminus b)\\setminus c)\\sqcap(b\\sqcup c)=\\bot$;\n\\begin{align*}\n((a\\setminus b)\\setminus c)\\sqcup(b\\sqcup c) & =\\\\\n(((a\\setminus b)\\setminus c)\\sqcup c)\\sqcup b & =\\\\\n(a\\setminus b)\\sqcup c\\sqcup b & =\\\\\n((a\\setminus b)\\sqcup b)\\sqcup c & =\\\\\na\\sqcup b\\sqcup c.\n\\end{align*}\n\n\\end{proof}\n\n\\subsection{Boolean lattices}\n\\begin{defn}\n\\index{lattice!boolean}A \\emph{boolean lattice} is a complemented\ndistributive lattice.\n\\end{defn}\nThe most important example of a boolean lattice is $\\subsets A$ where\n\\textbf{$A$} is a set, ordered by set inclusion.\n\\begin{thm}\n\\index{Morgan's laws}(\\noun{De Morgan}'s laws) For every elements $a$,\n$b$ of a boolean lattice\n\\begin{enumerate}\n\\item $\\overline{a\\sqcup b}=\\bar{a}\\sqcap\\bar{b}$;\n\\item $\\overline{a\\sqcap b}=\\bar{a}\\sqcup b$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nWe will prove only the first as the second is dual.\n\nIt is enough to prove that $a\\sqcup b$ is a complement of $\\bar{a}\\sqcap\\bar{b}$.\nReally:\n\\begin{gather*}\n(a\\sqcup b)\\sqcap(\\bar{a}\\sqcap\\bar{b})\\sqsubseteq a\\sqcap(\\bar{a}\\sqcap\\bar{b})=(a\\sqcap\\bar{a})\\sqcap\\bar{b}=\\bot\\sqcap\\bar{b}=\\bot;\\\\\n(a\\sqcup b)\\sqcup(\\bar{a}\\sqcap\\bar{b})=((a\\sqcup b)\\sqcup\\bar{a})\\sqcap((a\\sqcup b)\\sqcup\\bar{b})\\sqsupseteq(a\\sqcup\\bar{a})\\sqcap(b\\sqcup\\bar{b})=\\top\\sqcap\\top=\\top.\n\\end{gather*}\n\n\nThus $(a\\sqcup b)\\sqcap(\\bar{a}\\sqcap\\bar{b})=\\bot$ and $(a\\sqcup b)\\sqcup(\\bar{a}\\sqcap\\bar{b})=\\top$.\\end{proof}\n\\begin{defn}\n\\index{join infinite distributive}A complete lattice $\\mathfrak{A}$\nis \\emph{join infinite distributive} when $x\\sqcap\\bigsqcup S=\\bigsqcup\\rsupfun{x\\sqcap}S$;\n\\index{meet infinite distributive}a complete lattice $\\mathfrak{A}$\nis \\emph{meet infinite distributive} when $x\\sqcup\\bigsqcap S=\\bigsqcap\\rsupfun{x\\sqcup}S$\nfor all $x\\in\\mathfrak{A}$ and $S\\in\\subsets\\mathfrak{A}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{infinite distributive}\\emph{Infinite distributive complete\nlattice} is a complete lattice which is both join infinite distributive\nand meet infinite distributive.\\end{defn}\n\n\\begin{thm}\\label{bool-inf-distr1}\nFor every boolean lattice~$\\mathfrak{A}$, $x\\in\\mathfrak{A}$ and $S\\in\\subsets\\mathfrak{A}$ we have:\n\\begin{enumerate}\n\\item $\\bigsqcup\\rsupfun{x\\sqcap}S$ is defined and $x\\sqcap\\bigsqcup S=\\bigsqcup\\rsupfun{x\\sqcap}S$ whenever $\\bigsqcup S$ is defined.\n\\item $\\bigsqcap\\rsupfun{x\\sqcup}S$ is defined and $x\\sqcup\\bigsqcap S=\\bigsqcap\\rsupfun{x\\sqcup}S$ whenever $\\bigsqcap S$ is defined.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nWe will prove only the first, as the other is dual.\n\nWe need to prove that $x\\sqcap\\bigsqcup S$ is the least upper bound of $\\rsupfun{x\\sqcap}S$.\n\nThat $x\\sqcap\\bigsqcup S$ is an upper bound of $\\rsupfun{x\\sqcap}S$ is obvious.\n\nNow let \\textbf{$u$} be any upper bound of $\\rsupfun{x\\sqcap}S$,\nthat is $x\\sqcap y\\sqsubseteq u$ for all $y\\in S$. Then\n\\[\ny=y\\sqcap(x\\sqcup\\bar{x})=(y\\sqcap x)\\sqcup(y\\sqcap\\bar{x})\\sqsubseteq u\\sqcup\\bar{x},\n\\]\nand so $\\bigsqcup S\\sqsubseteq u\\sqcup\\bar{x}$. Thus\n\\[\nx\\sqcap\\bigsqcup S\\sqsubseteq x\\sqcap(u\\sqcup\\bar{x})=(x\\sqcap u)\\sqcup(x\\sqcap\\bar{x})=(x\\sqcap u)\\sqcup\\bot=x\\sqcap u\\sqsubseteq u,\n\\]\nthat is $x\\sqcap\\bigsqcup S$ is the least upper bound of $\\rsupfun{x\\sqcap}S$.\\end{proof}\n\n\\begin{cor}\\label{bool-inf-distr}\nEvery complete boolean lattice is both join infinite distributive\nand meet infinite distributive.\\end{cor}\n\\begin{thm}\n\\index{De Morgan's laws!infinite}(infinite \\noun{De Morgan}'s laws) For\nevery subset $S$ of a complete boolean lattice\n\\begin{enumerate}\n\\item $\\overline{\\bigsqcup S}=\\bigsqcap_{x\\in S}\\bar{x}$;\n\\item $\\overline{\\bigsqcap S}=\\bigsqcup_{x\\in S}\\bar{x}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nIt's enough to prove that $\\bigsqcup S$ is a complement of $\\bigsqcap_{x\\in S}\\bar{x}$\n(the second follows from duality). Really, using the previous theorem:\n\\begin{gather*}\n\\bigsqcup S\\sqcup\\bigsqcap_{x\\in S}\\bar{x}=\\bigsqcap_{x\\in S}\\rsupfun{\\bigsqcup S\\sqcup}\\bar{x}=\\bigsqcap\\setcond{\\bigsqcup S\\sqcup\\bar{x}}{x\\in S}\\sqsupseteq\\bigsqcap\\setcond{x\\sqcup\\bar{x}}{x\\in S}=\\top;\\\\\n\\bigsqcup S\\sqcap\\bigsqcap_{x\\in S}\\bar{x}=\\bigsqcup_{y\\in S}\\rsupfun{\\bigsqcap_{x\\in S}\\bar{x}\\sqcap}y=\\bigsqcup\\setcond{\\bigsqcap_{x\\in S}\\bar{x}\\sqcap y}{y\\in S}\\sqsubseteq\\bigsqcup\\setcond{\\bar{y}\\sqcap y}{y\\in S}=\\bot.\n\\end{gather*}\n\n\nSo $\\bigsqcup S\\sqcup\\bigsqcap_{x\\in S}\\bar{x}=\\top$ and $\\bigsqcup S\\sqcap\\bigsqcap_{x\\in S}\\bar{x}=\\bot$.\n\\end{proof}\n\n\\subsection{Center of a lattice}\n\\begin{defn}\n\\index{lattice!center}The \\emph{center} $Z(\\mathfrak{A})$ of a bounded\ndistributive lattice $\\mathfrak{A}$ is the set of its complemented\nelements.\\end{defn}\n\\begin{rem}\nFor a definition of center of non-distributive lattices see \\cite{neutralelements}.\n\\end{rem}\n\n\\begin{rem}\nIn \\cite{ADTCGSBVA} the word center and the notation $Z(\\mathfrak{A})$\nare used in a different sense.\\end{rem}\n\\begin{defn}\n\\index{sublattice!closed}A sublattice $K$ of a complete lattice\n$L$ is a \\emph{closed sublattice} of $L$ if $K$ contains the meet\nand the join of any its nonempty subset.\\end{defn}\n\\begin{thm}\nCenter of an infinitely distributive lattice is its closed sublattice.\\end{thm}\n\\begin{proof}\nSee \\cite{center-inf-distr}.\\end{proof}\n\\begin{rem}\nSee \\cite{center-complete} for a more strong result.\\end{rem}\n\\begin{thm}\nThe center of a bounded distributive lattice constitutes its sublattice.\\end{thm}\n\\begin{proof}\nLet $\\mathfrak{A}$ be a bounded distributive lattice and $Z(\\mathfrak{A})$\nbe its center. Let $a,b\\in Z(\\mathfrak{A})$. Consequently $\\bar{a},\\bar{b}\\in Z(\\mathfrak{A})$.\nThen $\\bar{a}\\sqcup\\bar{b}$ is the complement of $a\\sqcap b$ because\n\\begin{align*}\n(a\\sqcap b)\\sqcap(\\bar{a}\\sqcup\\bar{b})=(a\\sqcap b\\sqcap\\bar{a})\\sqcup(a\\sqcap b\\sqcap\\bar{b})=\\bot\\sqcup\\bot=\\bot & \\text{\\quad and}\\\\\n(a\\sqcap b)\\sqcup(\\bar{a}\\sqcup\\bar{b})=(a\\sqcup\\bar{a}\\sqcup\\bar{b})\\sqcap(b\\sqcup{\\bar{a}\\sqcup\\bar{b}})=\\top\\sqcap\\top=\\top.\n\\end{align*}\n\n\nSo $a\\sqcap b$ is complemented. Similarly $a\\sqcup b$ is complemented.\\end{proof}\n\\begin{thm}\n\\label{centr-bool}The center of a bounded distributive lattice constitutes\na boolean lattice.\\end{thm}\n\\begin{proof}\nBecause it is a distributive complemented lattice.\n\\end{proof}\n\n\\subsection{Atoms of posets}\n\\begin{defn}\n\\index{atom}An atom of a poset is an element~$a$ such that (for every its element~$x$)\n$x\\sqsubset a$ if and only if $x$ is the least element.\\end{defn}\n\\begin{rem}\nThis definition is valid even for posets without least element.\n\\end{rem}\n\n\\begin{prop}\nElement~$a$ is an atom iff both:\n\\begin{enumerate}\n\\item\\label{atm-i} $x\\sqsubset a$ implies $x$ is the least element;\n\\item\\label{atm-nl} $a$ is non-least.\n\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n~\n\\begin{description}\n\\item[$\\Rightarrow$] Let $a$ be an atom.\n\\ref{atm-i} is obvious. If $a$ is least then $a\\sqsubset a$ what is impossible, so~\\ref{atm-nl}.\n\\item[$\\Leftarrow$] Let~\\ref{atm-i} and~\\ref{atm-nl} hold.\nWe need to prove only that $x$ is least implies that $x\\sqsubset a$ but this follows from $a$ being non-least.\n\\end{description}\n\n\\end{proof}\n\n\\begin{example}\nAtoms of the boolean algebra~$\\subsets A$ (ordered by set inclusion) are one-element sets.\n\\end{example}\n\nI will denote $\\atoms^{\\mathfrak{A}}a$ or just $(\\atoms a)$ the\nset of atoms contained in an element $a$ of a poset $\\mathfrak{A}$.\nI will denote $\\atoms^{\\mathfrak{A}}$ the set of all atoms of a poset\n$\\mathfrak{A}$.\n\\begin{defn}\n\\index{atomic}A poset $\\mathfrak{A}$ is called \\emph{atomic} iff\n$\\atoms a\\neq\\emptyset$ for every non-least element $a$ of the poset\n$\\mathfrak{A}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{atomistic}\\emph{Atomistic poset} is such a poset that $a=\\bigsqcup\\atoms a$\nfor every element $a$ of this poset.\\end{defn}\n\\begin{obvious}\nEvery atomistic poset is atomic.\\end{obvious}\n\\begin{prop}\nLet $\\mathfrak{A}$ be a poset. If $a$ is an atom of $\\mathfrak{A}$\nand $B\\in\\mathfrak{A}$ then \n\\[\na\\in\\atoms B\\Leftrightarrow a\\sqsubseteq B\\Leftrightarrow a\\nasymp B.\n\\]\n\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$a\\in\\atoms B\\Leftrightarrow a\\sqsubseteq B$}] Obvious.\n\\item [{$a\\sqsubseteq B\\Rightarrow a\\nasymp B$}] $a\\sqsubseteq B\\Rightarrow a\\sqsubseteq a\\land a\\sqsubseteq B$,\nthus $a\\nasymp B$ because $a$ is not least.\n\\item [{$a\\sqsubseteq B\\Leftarrow a\\nasymp B$}] $a\\nasymp B$ implies\nexistence of non-least element $x$ such that $x\\sqsubseteq B$ and\n$x\\sqsubseteq a$. Because $a$ is an atom, we have $x=a$. So $a\\sqsubseteq B$.\n\\end{description}\n\\end{proof}\n\\begin{thm}\nA poset is atomistic iff every its element can be represented as join of atoms.\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item[$\\Rightarrow$] Obvious.\n\\item[$\\Leftarrow$] Let $a = \\bigsqcup S$ where $S$ is a set of atoms. We will prove that $a$ is\nthe least upper bound of $\\atoms a$.\n\nThat $a$ is an upper bound of $\\atoms a$ is obvious. Let $x$ is an upper\nbound of $\\atoms a$. Then $x \\sqsupseteq \\bigsqcup S$ because $S\\subseteq \\atoms a$. Thus $x \\sqsupseteq a$.\n\\end{description}\n\n\\end{proof}\n\n\\begin{thm}\\label{atoms-infmeet}\n$\\atoms\\bigsqcap S=\\bigcap\\rsupfun{\\atoms}S$ whenever $\\bigsqcap S$\nis defined for every $S\\in\\subsets\\mathfrak{A}$ where $\\mathfrak{A}$\nis a poset.\\end{thm}\n\\begin{proof}\nFor any atom\n\\begin{align*}\nc\\in\\atoms\\bigsqcap S & \\Leftrightarrow\\\\\nc\\sqsubseteq\\bigsqcap S & \\Leftrightarrow\\\\\n\\forall a\\in S:c\\sqsubseteq a & \\Leftrightarrow\\\\\n\\forall a\\in S:c\\in\\atoms a & \\Leftrightarrow\\\\\nc\\in\\bigcap\\rsupfun{\\atoms}S.\n\\end{align*}\n\\end{proof}\n\\begin{cor}\n\\label{atoms-meet}$\\atoms(a\\sqcap b)=\\atoms a\\cap\\atoms b$ for an\narbitrary meet-semilattice.\\end{cor}\n\\begin{thm}\nA complete boolean lattice is atomic iff it is atomistic.\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Leftarrow$}] Obvious.\n\\item [{$\\Rightarrow$}] Let $\\mathfrak{A}$ be an atomic boolean lattice.\nLet $a\\in\\mathfrak{A}$. Suppose $b=\\bigsqcup\\atoms a\\sqsubset a$.\nIf $x\\in\\atoms(a\\setminus b)$ then $x\\sqsubseteq a\\setminus b$ and\nso $x\\sqsubseteq a$ and hence $x\\sqsubseteq b$. But we have $x=x\\sqcap b\\sqsubseteq(a\\setminus b)\\sqcap b=\\bot$\nwhat contradicts to our supposition.\n\\end{description}\n\\end{proof}\n\n\\subsection{\\index{Kuratowski's lemma}Kuratowski's lemma}\n\\begin{thm}\n(\\noun{Kuratowski}'s lemma) Any chain in a poset is contained in a maximal\nchain (if we order chains by inclusion).\n\\end{thm}\nI will skip the proof of \\noun{Kuratowski}'s lemma as this proof can be found\nin any set theory or order theory reference.\n\n\n\\subsection{Homomorphisms of posets and lattices}\n\\begin{defn}\n\\index{monotone}\\index{order homomorphism}A \\emph{monotone} function\n(also called \\emph{order homomorphism}) from a poset $\\mathfrak{A}$\nto a poset $\\mathfrak{B}$ is such a function $f$ that $x\\sqsubseteq y\\Rightarrow fx\\sqsubseteq fy$\nfor every $x,y\\in\\mathfrak{A}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{antitone}A \\emph{antitone} function (also called \\emph{antitone\norder homomorphism}) from a poset $\\mathfrak{A}$ to a poset $\\mathfrak{B}$\nis such a function $f$ that $x\\sqsubseteq y\\Rightarrow fx\\sqsupseteq fy$\nfor every $x,y\\in\\mathfrak{A}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{order embedding}\\emph{Order embedding} is a function~$f$ from poset~$\\mathfrak{A}$ to a poset~$\\mathfrak{B}$\nsuch that $x\\sqsubseteq y\\Leftrightarrow fx\\sqsubseteq fy$ for every $x,y\\in\\mathfrak{A}$.\n\\end{defn}\n\n\\begin{prop}\nEvery order embedding is injective.\n\\end{prop}\n\n\\begin{proof}\n$fx=fy$ implies $x\\sqsubseteq y$ and $y\\sqsubseteq x$.\n\\end{proof}\n\n\\begin{obvious}\nEvery order embedding is an order homomorphism.\n\\end{obvious}\n\n\\begin{defn}\n\\index{antitone order embedding}\\emph{Antitone order embedding} is a function~$f$ from poset~$\\mathfrak{A}$ to a poset~$\\mathfrak{B}$\nsuch that $x\\sqsubseteq y\\Leftrightarrow fx\\sqsupseteq fy$ for every $x,y\\in\\mathfrak{A}$.\n\\end{defn}\n\n\\begin{obvious}\nAntitone order embedding is an order embedding between a poset and a dual of (another) poset.\n\\end{obvious}\n\n\\begin{defn}\n\\index{order isomorphism}\\emph{Order isomorphism} is a surjective\norder embedding.\n\\end{defn}\nOrder isomorphism preserves properties of posets, such as order, joins\nand meets, etc.\n\\begin{defn}\n\\index{antitone order isomorphism}\\emph{Antitone order isomorphism}\nis a surjective antitone order embedding.\n\\end{defn}\n\n\\begin{defn}\n~\n\\begin{enumerate}\n\\item \\index{join semilattice!homomorphism}\\emph{Join semilattice homomorphism}\nis a function $f$ from a join semilattice $\\mathfrak{A}$ to a join\nsemilattice $\\mathfrak{B}$, such that $f(x\\sqcup y)=fx\\sqcup fy$\nfor every $x,y\\in\\mathfrak{A}$.\n\\item \\index{meet semilattice!homomorphism}\\emph{Meet semilattice homomorphism}\nis a function $f$ from a meet semilattice $\\mathfrak{A}$ to a meet\nsemilattice $\\mathfrak{B}$, such that $f(x\\sqcap y)=fx\\sqcap fy$\nfor every $x,y\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{defn}\n\\begin{obvious}\n~\n\\begin{enumerate}\n\\item Join semilattice homomorphisms are monotone.\n\\item Meet semilattice homomorphisms are monotone.\n\\end{enumerate}\n\\end{obvious}\n\\begin{defn}\n\\index{lattice!homomorphism}A \\emph{lattice homomorphism} is a function\nfrom a lattice to a lattice, which is both join semilattice homomorphism\nand meet semilattice homomorphism.\n\\end{defn}\n\n\\begin{defn}\n\\index{complete lattice!homomorphism}\\emph{Complete lattice homomorphism}\nfrom a complete lattice $\\mathfrak{A}$ to a complete lattice $\\mathfrak{B}$\nis a function f from $\\mathfrak{A}$ to $\\mathfrak{B}$ which preserves\nall meets and joins, that is $f\\bigsqcup S=\\bigsqcup\\rsupfun fS$\nand $f\\bigsqcap S=\\bigsqcap\\rsupfun fS$ for every $S\\in\\subsets\\mathfrak{A}$.\n\\end{defn}\n\n\\subsection{Galois connections}\n\nSee \\cite{galois-and-fixed,primer-galois} for more detailed treatment\nof Galois connections.\n\\begin{defn}\n\\index{Galois!connection}Let $\\mathfrak{A}$ and $\\mathfrak{B}$\nbe two posets. A \\emph{Galois connection} between $\\mathfrak{A}$\nand $\\mathfrak{B}$ is a pair of functions $f=(f^{\\ast},f_{\\ast})$\nwith $f^{\\ast}:\\mathfrak{A}\\rightarrow\\mathfrak{B}$ and $f_{\\ast}:\\mathfrak{B}\\rightarrow\\mathfrak{A}$\nsuch that:\n\\[\n\\forall x\\in\\mathfrak{A},y\\in\\mathfrak{B}:(f^{\\ast}x\\sqsubseteq y\\Leftrightarrow x\\sqsubseteq f_{\\ast}y).\n\\]\n\n\n\\index{adjoint!lower}\\index{adjoint!upper}$f_{\\ast}$ is called\n\\emph{the upper adjoint} of $f^{\\ast}$ and $f^{\\ast}$ is called\n\\emph{the lower adjoint} of $f_{\\ast}$.\\end{defn}\n\\begin{thm}\n\\label{galois-second}A pair $(f^{\\ast},f_{\\ast})$ of functions $f^{\\ast}:\\mathfrak{A}\\rightarrow\\mathfrak{B}$\nand $f_{\\ast}:\\mathfrak{B}\\rightarrow\\mathfrak{A}$ is a Galois connection\niff both of the following: \n\\begin{enumerate}\n\\item \\label{galois-second-mono}$f^{\\ast}$ and $f_{\\ast}$ are monotone.\n\\item \\label{galois-second-ineq}$x\\sqsubseteq f_{\\ast}f^{\\ast}x$ and $f^{\\ast}f_{\\ast}y\\sqsubseteq y$\nfor every $x\\in\\mathfrak{A}$ and $y\\in\\mathfrak{B}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Rightarrow$}]~\n\n\\begin{disorder}\n\\item [{\\ref{galois-second-ineq}}] $x\\sqsubseteq f_{\\ast}f^{\\ast}x$ since\n$f^{\\ast}x\\sqsubseteq f^{\\ast}x$; $f^{\\ast}f_{\\ast}y\\sqsubseteq y$\nsince $f_{\\ast}y\\sqsubseteq f_{\\ast}y$.\n\\item [{\\ref{galois-second-mono}}] Let $a,b\\in\\mathfrak{A}$ and $a\\sqsubseteq b$.\nThen $a\\sqsubseteq b\\sqsubseteq f_{\\ast}f^{\\ast}b$. So by definition\n$f^{\\ast}a\\sqsubseteq f^{\\ast}b$ that is $f^{\\ast}$ is monotone.\nAnalogously $f_{\\ast}$ is monotone.\n\\end{disorder}\n\\item [{$\\Leftarrow$}] $f^{\\ast}x\\sqsubseteq y\\Rightarrow f_{\\ast}f^{\\ast}x\\sqsubseteq f_{\\ast}y\\Rightarrow x\\sqsubseteq f_{\\ast}y$.\nThe other direction is analogous.\n\\end{description}\n\\end{proof}\n\\begin{thm}\n~\n\\begin{enumerate}\n\\item \\label{galois-three-a}$f^{\\ast}\\circ f_{\\ast}\\circ f^{\\ast}=f^{\\ast}$.\n\\item \\label{galois-three-b}$f_{\\ast}\\circ f^{\\ast}\\circ f_{\\ast}=f_{\\ast}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{disorder}\n\\item [{\\ref{galois-three-a}}] Let $x\\in\\mathfrak{A}$. We have $x\\sqsubseteq f_{\\ast}f^{\\ast}x$;\nconsequently $f^{\\ast}x\\sqsubseteq f^{\\ast}f_{\\ast}f^{\\ast}x$. On\nthe other hand, $f^{\\ast}f_{\\ast}f^{\\ast}x\\sqsubseteq f^{\\ast}x$.\nSo $f^{\\ast}f_{\\ast}f^{\\ast}x=f^{\\ast}x$.\n\\item [{\\ref{galois-three-b}}] Similar.\n\\end{disorder}\n\\end{proof}\n\\begin{defn}\n\\index{idempotent}A function $f$ is called \\emph{idempotent} iff $f(f(X))=f(X)$\nfor every argument $X$.\\end{defn}\n\\begin{prop}\n$f^{\\ast}\\circ f_{\\ast}$ and $f_{\\ast}\\circ f^{\\ast}$ are idempotent.\\end{prop}\n\\begin{proof}\n$f^{\\ast}\\circ f_{\\ast}$ is idempotent because $f^{\\ast}f_{\\ast}f^{\\ast}f_{\\ast}y=f^{\\ast}f_{\\ast}y$.\n$f_{\\ast}\\circ f^{\\ast}$ is similar.\\end{proof}\n\\begin{thm}\n\\label{adj-by-other}Each of two adjoints is uniquely determined by\nthe other.\\end{thm}\n\\begin{proof}\nLet $p$ and $q$ be both upper adjoints of $f$. We have for all\n$x\\in\\mathfrak{A}$ and $y\\in\\mathfrak{B}$:\n\\[\nx\\sqsubseteq p(y)\\Leftrightarrow f(x)\\sqsubseteq y\\Leftrightarrow x\\sqsubseteq q(y).\n\\]\n\n\nFor $x=p(y)$ we obtain $p(y)\\sqsubseteq q(y)$ and for $x=q(y)$\nwe obtain $q(y)\\sqsubseteq p(y)$. So $q(y)=p(y)$.\\end{proof}\n\\begin{thm}\\label{adj-max}\nLet $f$ be a function from a poset $\\mathfrak{A}$ to a poset $\\mathfrak{B}$.\n\\begin{enumerate}\n\\item Both:\n\n\\begin{enumerate}\n\\item \\label{max-gal}If $f$ is monotone and $g(b)=\\max\\setcond{x\\in\\mathfrak{A}}{fx\\sqsubseteq b}$\nis defined for every $b\\in\\mathfrak{B}$ then $g$ is the upper adjoint\nof $f$.\n\\item \\label{gal-max}If $g:\\mathfrak{B}\\rightarrow\\mathfrak{A}$ is the\nupper adjoint of $f$ then $g(b)=\\max\\setcond{x\\in\\mathfrak{A}}{fx\\sqsubseteq b}$\nfor every $b\\in\\mathfrak{B}$.\n\\end{enumerate}\n\\item Both:\n\n\\begin{enumerate}\n\\item If $f$ is monotone and $g(b)=\\min\\setcond{x\\in\\mathfrak{A}}{fx\\sqsupseteq b}$\nis defined for every $b\\in\\mathfrak{B}$ then $g$ is the lower adjoint\nof $f$.\n\\item If $g:\\mathfrak{B}\\rightarrow\\mathfrak{A}$ is the lower adjoint of\n$f$ then $g(b)=\\min\\setcond{x\\in\\mathfrak{A}}{fx\\sqsupseteq b}$\nfor every $b\\in\\mathfrak{B}$.\n\\end{enumerate}\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nWe will prove only the first as the second is its dual.\n\\begin{widedisorder}\n\\item [{\\ref{max-gal}}] Let $g(b)=\\max\\setcond{x\\in\\mathfrak{A}}{fx\\sqsubseteq b}$\nfor every $b\\in\\mathfrak{B}$. Then\n\\[\nx\\sqsubseteq gy\\Leftrightarrow x\\sqsubseteq\\max\\setcond{x\\in\\mathfrak{A}}{fx\\sqsubseteq y}\\Rightarrow fx\\sqsubseteq y\n\\]\n(because $f$ is monotone) and\n\\[\nx\\sqsubseteq gy\\Leftrightarrow x\\sqsubseteq\\max\\setcond{x\\in\\mathfrak{A}}{fx\\sqsubseteq y}\\Leftarrow fx\\sqsubseteq y.\n\\]\n\n\n\nSo $fx\\sqsubseteq y\\Leftrightarrow x\\sqsubseteq gy$ that is $f$\nis the lower adjoint of $g$.\n\n\\item [{\\ref{gal-max}}] We have\n\\[\ng(b)=\\max\\setcond{x\\in\\mathfrak{A}}{fx\\sqsubseteq b}\\Leftrightarrow fgb\\sqsubseteq b\\land\\forall x\\in\\mathfrak{A}:(fx\\sqsubseteq b\\Rightarrow x\\sqsubseteq gb).\n\\]\nwhat is true by properties of adjoints.\n\\end{widedisorder}\n\\end{proof}\n\\begin{thm}\nLet $f$ be a function from a poset $\\mathfrak{A}$ to a poset $\\mathfrak{B}$.\n\\begin{enumerate}\n\\item \\label{all-inf}If $f$ is an upper adjoint, $f$ preserves all existing\ninfima in $\\mathfrak{A}$.\n\\item \\label{inf-then-adj}If $\\mathfrak{A}$ is a complete lattice and\n$f$ preserves all infima, then $f$ is an upper adjoint of a function\n$\\mathfrak{B}\\rightarrow\\mathfrak{A}$.\n\\item If $f$ is a lower adjoint, $f$ preserves all existing suprema in\n$\\mathfrak{A}$.\n\\item If $\\mathfrak{A}$ is a complete lattice and $f$ preserves all suprema,\nthen $f$ is a lower adjoint of a function $\\mathfrak{B}\\rightarrow\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\nWe will prove only first two items because the rest items are similar.\n\\begin{widedisorder}\n\\item [{\\ref{all-inf}}] Let $S\\in\\subsets\\mathfrak{A}$ and $\\bigsqcap S$\nexists. $f\\bigsqcap S$ is a lower bound for $\\rsupfun fS$ because\n$f$ is order-preserving. If $a$ is a lower bound for $\\rsupfun fS$\nthen $\\forall x\\in S:a\\sqsubseteq fx$ that is $\\forall x\\in S:ga\\sqsubseteq x$\nwhere $g$ is the lower adjoint of $f$. Thus $ga\\sqsubseteq\\bigsqcap S$\nand hence $f\\bigsqcap S\\sqsupseteq a$. So $f\\bigsqcap S$ is the\ngreatest lower bound for $\\rsupfun fS$.\n\\item [{\\ref{inf-then-adj}}] Let $\\mathfrak{A}$ be a complete lattice\nand $f$ preserves all infima. Let\n\\[\ng(a)=\\bigsqcap\\setcond{x\\in\\mathfrak{A}}{fx\\sqsupseteq a}.\n\\]\n\n\n\nSince $f$ preserves infima, we have\n\\[\nf(g(a))=\\bigsqcap\\setcond{f(x)}{x\\in\\mathfrak{A},fx\\sqsupseteq a}\\sqsupseteq a.\n\\]\n$g(f(b))=\\bigsqcap\\setcond{x\\in\\mathfrak{A}}{fx\\sqsupseteq fb}\\sqsubseteq b$.\n\n\nObviously $f$ is monotone and thus $g$ is also monotone.\n\n\nSo $f$ is the upper adjoint of $g$.\n\n\\end{widedisorder}\n\\end{proof}\n\\begin{cor}\\label{adj-cons}\nLet $f$ be a function from a complete lattice $\\mathfrak{A}$ to\na poset $\\mathfrak{B}$. Then:\n\\begin{enumerate}\n\\item $f$ is an upper adjoint of a function $\\mathfrak{B}\\rightarrow\\mathfrak{A}$\niff $f$ preserves all infima in $\\mathfrak{A}$.\n\\item $f$ is a lower adjoint of a function $\\mathfrak{B}\\rightarrow\\mathfrak{A}$\niff $f$ preserves all suprema in $\\mathfrak{A}$.\n\\end{enumerate}\n\\end{cor}\n\n\\subsubsection{Order and composition of Galois connections}\n\nFollowing~\\cite{tprod-dist-lat} we will denote the set of Galois connection between posets~$\\mathfrak{A}$ and~$\\mathfrak{B}$\nas $\\mathfrak{A}\\otimes\\mathfrak{B}$.\n\n\\begin{defn}\nI will order Galois connections by the formula: $f\\sqsubseteq g\\Leftrightarrow f^{\\ast}\\sqsubseteq g^{\\ast}$\n(where $f^{\\ast}\\sqsubseteq g^{\\ast}\\Leftrightarrow\\forall x\\in\\mathfrak{A}:f^{\\ast}x\\sqsubseteq g^{\\ast}x$).\n\\end{defn}\n\n\\begin{obvious}\nGalois connections $\\mathfrak{A}\\otimes\\mathfrak{B}$ between two given posets form a poset.\n\\end{obvious}\n\n\\begin{prop}\n$f\\sqsubseteq g\\Leftrightarrow f_{\\ast}\\sqsupseteq g_{\\ast}$.\n\\end{prop}\n\n\\begin{proof}\nIt is enough to prove $f\\sqsubseteq g\\Rightarrow f_{\\ast}\\sqsupseteq g_{\\ast}$ (the rest follows from the fact that a Galois connection is determined by one adjoint).\n\nReally, let $f\\sqsubseteq g$. Then $f_0^{\\ast} \\sqsubseteq f_1^{\\ast}$ and thus:\n\n$f_{0 \\ast} (b) = \\max \\setcond{ x \\in \\mathfrak{A} }{\nf_0^{\\ast} x \\sqsubseteq b }$, $f_{1 \\ast} (b) = \\max \\setcond{ x \\in\n\\mathfrak{A} }{ f_1^{\\ast} x \\sqsubseteq b }$.\n\nThus $f_{0 \\ast} (b) \\sqsupseteq f_{1 \\ast} (b)$ for every $b\\in\\mathfrak{B}$ and so $f_{0 \\ast} \\sqsupseteq f_{1 \\ast}$.\n\\end{proof}\n\n\\begin{defn}\nComposition of Galois connections is defined by the formula:\n$g\\circ f=(g^{\\ast}\\circ f^{\\ast},f_{\\ast}\\circ g_{\\ast})$.\n\\end{defn}\n\n\\begin{prop}\nComposition of Galois connections is a Galois connection.\n\\end{prop}\n\n\\begin{proof}\n$g^{\\ast}\\circ f^{\\ast}$ and $f_{\\ast}\\circ g_{\\ast}$ are monotone as composition of monotone functions;\n\\[\n(g^{\\ast}\\circ f^{\\ast})x\\sqsubseteq z \\Leftrightarrow g^{\\ast}f^{\\ast}x\\sqsubseteq z \\Leftrightarrow\nf^{\\ast}x\\sqsubseteq g_{\\ast} z \\Leftrightarrow x\\sqsubseteq f_{\\ast}g_{\\ast} z \\Leftrightarrow x\\sqsubseteq(f_{\\ast}\\circ g_{\\ast})z.\n\\]\n\\end{proof}\n\n\\begin{obvious}\nComposition of Galois connections preserves order.\n\\end{obvious}\n\n\\subsubsection{Antitone Galois connections}\n\n\\begin{defn}\nAn \\emph{antitone Galois connection} between posets~$\\mathfrak{A}$ and~$\\mathfrak{B}$ is a Galois connection\nbetween~$\\mathfrak{A}$ and~$\\dual\\mathfrak{B}$.\n\\end{defn}\n\n\\begin{obvious}\nAn antitone Galois connection is a pair of antitone functions~$f:\\mathfrak{A}\\rightarrow\\mathfrak{B}$, $g:\\mathfrak{B}\\rightarrow\\mathfrak{A}$\nsuch that $b\\sqsubseteq fa \\Leftrightarrow a\\sqsubseteq gb$ for every $a\\in\\mathfrak{A}$, $b\\in\\mathfrak{B}$.\n\\end{obvious}\n\nSuch $f$ and~$g$ are called \\emph{polarities} (between~$\\mathfrak{A}$ and~$\\mathfrak{B}$).\n\n\\begin{obvious}\\label{polar-flip}\n$f\\bigsqcup S = \\bigsqcap \\rsupfun{f}S$ if $f$ is a polarity between~$\\mathfrak{A}$ and~$\\mathfrak{B}$ and $S\\in\\subsets\\mathfrak{A}$.\n\\end{obvious}\n\nGalois connections (particularly between boolean lattices) are studied in~\\cite{tprod-dist-lat}\nand~\\cite{shmuely1974}.\n\n\\subsection{Co-Brouwerian lattices}\n\\begin{defn}\n\\index{pseudocomplement}Let $\\mathfrak{A}$ be a poset. \\emph{Pseudocomplement}\nof $a\\in\\mathfrak{A}$ is\n\\[\n\\max\\setcond{c\\in\\mathfrak{A}}{c\\asymp a}.\n\\]\n\n\nIf $z$ is the pseudocomplement of $a$ we will denote $z=a^{\\ast}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{pseudocomplement!dual}Let $\\mathfrak{A}$ be a poset. \\emph{Dual\npseudocomplement} of $a\\in\\mathfrak{A}$ is\n\\[\n\\min\\setcond{c\\in\\mathfrak{A}}{c\\equiv a}.\n\\]\n\n\nIf $z$ is the dual pseudocomplement of $a$ we will denote $z=a^{+}$.\\end{defn}\n\\begin{prop}\\label{compl-is-pseud}\nIf $a$ is a complemented element of a bounded distributive lattice,\nthen $\\bar{a}$ is both pseudocomplement and dual pseudocomplement\nof $a$.\\end{prop}\n\\begin{proof}\nBecause of duality it is enough to prove that $\\bar{a}$ is pseudocomplement\nof $a$.\n\nWe need to prove $c\\asymp a\\Rightarrow c\\sqsubseteq\\bar{a}$ for every\nelement c of our poset, and $\\bar{a}\\asymp a$. The second is obvious.\nLet's prove $c\\asymp a\\Rightarrow c\\sqsubseteq\\bar{a}$.\n\nReally, let $c\\asymp a$. Then $c\\sqcap a=\\bot$; $\\bar{a}\\sqcup(c\\sqcap a)=\\bar{a}$;\n$(\\bar{a}\\sqcup c)\\sqcap(\\bar{a}\\sqcup a)=\\bar{a}$; $\\bar{a}\\sqcup c=\\bar{a}$;\n$c\\sqsubseteq\\bar{a}$.\\end{proof}\n\\begin{defn}\n\\index{pseudodifference}Let $\\mathfrak{A}$ be a join-semilattice.\nLet $a,b\\in\\mathfrak{A}$. \\emph{Pseudodifference} of $a$ and $b$\nis\n\\[\n\\min\\setcond{z\\in\\mathfrak{A}}{a\\sqsubseteq b\\sqcup z}.\n\\]\n\n\nIf $z$ is a pseudodifference of $a$ and $b$ we will denote $z=a\\psetminus b$.\\end{defn}\n\\begin{rem}\nI do not require that $a^{\\ast}$ is undefined if there are no pseudocomplement\nof $a$ and likewise for dual pseudocomplement and pseudodifference.\nIn fact below I will define quasicomplement, dual quasicomplement,\nand quasidifference which generalize pseudo-{*} counterparts. I will\ndenote $a^{\\ast}$ the more general case of quasicomplement than of\npseudocomplement, and likewise for other notation.\\end{rem}\n\\begin{obvious}\nDual pseudocomplement is the dual of pseudocomplement.\\end{obvious}\n\n\\begin{thm}\nLet $\\mathfrak{A}$ be a distributive lattice with least element. Let $a,b\\in\\mathfrak{A}$.\nIf $a\\setminus b$ exists, then $a\\psetminus b$ also exists and $a\\psetminus b=a\\setminus b$.\n\\end{thm}\n\n\\begin{proof}\nBecause $\\mathfrak{A}$ be a distributive lattice with least element, the definition of $a\\setminus b$\nis correct.\n\nLet $x=a\\setminus b$ and let $S=\\setcond{y\\in\\mathfrak{A}}{a\\sqsubseteq b\\sqcup y}$.\n\nWe need to show\n\\begin{enumerate}\n\\item\\label{pmin-a} $x\\in S$;\n\\item\\label{pmin-b} $y\\in S\\Rightarrow x\\sqsubseteq y$ (for every $y\\in\\mathfrak{A}$).\n\\end{enumerate}\n\nReally,\n\\begin{disorder}\n\\item[\\ref{pmin-a}] Because $b\\sqcup x=a\\sqcup b$.\n\n\\item[\\ref{pmin-b}] ~\n\\begin{align*}\n& y\\in S \\\\\n\\Rightarrow \\quad& a\\sqsubseteq b\\sqcup y & \\quad \\text{(by definition of $S$)} \\\\\n\\Rightarrow \\quad& a\\sqcup b\\sqsubseteq b\\sqcup y \\\\\n\\Rightarrow \\quad& x\\sqcup b\\sqsubseteq b\\sqcup y & \\quad \\text{(since $x\\sqcup b=a\\sqcup b$)} \\\\\n\\Rightarrow \\quad& x\\sqcap(x\\sqcup b)\\sqsubseteq x\\sqcap(b\\sqcup y) \\\\\n\\Rightarrow \\quad& (x\\sqcap x)\\sqcup (x\\sqcap b)\\sqsubseteq (x\\sqcap b)\\sqcup(x\\sqcap y) & \\quad \\text{(by distributive law)} \\\\\n\\Rightarrow \\quad& x\\sqcup \\bot\\sqsubseteq \\bot\\sqcup(x\\sqcap y) & \\quad \\text{(since $x\\sqcap b=\\bot$)} \\\\\n\\Rightarrow \\quad& x\\sqsubseteq x\\sqcap y & \\quad \\\\\n\\Rightarrow \\quad& x\\sqsubseteq y.\n\\end{align*}\n\\end{disorder}\n\\end{proof}\n\n\\begin{defn}\n\\index{lattice!co-brouwerian}\\emph{Co-brouwerian lattice} is a lattice\nfor which pseudodifference of any two its elements is defined.\\end{defn}\n\\begin{prop}\nEvery non-empty co-brouwerian lattice $\\mathfrak{A}$ has least element.\\end{prop}\n\\begin{proof}\nLet $a$ be an arbitrary lattice element. Then\n\\[\na\\psetminus a=\\min\\setcond{z\\in\\mathfrak{A}}{a\\sqsubseteq a\\sqcup z}=\\min\\mathfrak{A}.\n\\]\n\n\nSo $\\min\\mathfrak{A}$ exists.\\end{proof}\n\\begin{defn}\n\\index{lattice!co-Heyting}\\emph{Co-Heyting lattice} is co-brouwerian\nlattice with greatest element.\n\\end{defn}\n\n\\begin{defn}\nA \\emph{co-frame} is the same as a complete co-brouwerian lattice.\\end{defn}\n\\begin{thm}\\label{cobrow}\n\\label{cobrow-adj}For a co-brouwerian lattice $a\\sqcup\\mathord-$\nis an upper adjoint of $\\mathord-\\psetminus a$ for every $a\\in\\mathfrak{A}$.\\end{thm}\n\\begin{proof}\n$g(b)=\\min\\setcond{x\\in\\mathfrak{A}}{a\\sqcup x\\sqsupseteq b}=b\\psetminus a$\nexists for every $b\\in\\mathfrak{A}$ and thus is the lower adjoint\nof $a\\sqcup\\mathord-$.\\end{proof}\n\\begin{cor}\n\\label{adjoint-brow-full}$\\forall a,x,y\\in\\mathfrak{A}:(x\\psetminus a\\sqsubseteq y\\Leftrightarrow x\\sqsubseteq a\\sqcup y)$\nfor a co-brouwerian lattice.\\end{cor}\n\n\\begin{cor}\nFor a co-brouwerian lattice $a\\sqcup\\bigsqcap S=\n\\bigsqcap\\rsupfun{a\\sqcup}S$ whenever $\\bigsqcap S$\nexists (for $a$ being a lattice element and~$S$ being\na set of lattice elements).\n\\end{cor}\n\n\\begin{defn}\n\\index{quasidifference}Let $a,b\\in\\mathfrak{A}$ where $\\mathfrak{A}$\nis a complete lattice. \\emph{Quasidifference} $a\\psetminus b$ is\ndefined by the formula:\n\\[\na\\psetminus b=\\bigsqcap\\setcond{z\\in\\mathfrak{A}}{a\\sqsubseteq b\\sqcup z}.\n\\]\n\\end{defn}\n\\begin{rem}\nA more detailed theory of quasidifference (as well as quasicomplement\nand dual quasicomplement) will be considered below.\\end{rem}\n\\begin{lem}\n$(a\\psetminus b)\\sqcup b=a\\sqcup b$ for elements $a$, $b$ of a\nmeet infinite distributive complete lattice.\\end{lem}\n\\begin{proof}\n~\n\\begin{align*}\n(a\\psetminus b)\\sqcup b & =\\\\\n\\bigsqcap\\setcond{z\\in\\mathfrak{A}}{a\\sqsubseteq b\\sqcup z}\\sqcup b & =\\\\\n\\bigsqcap\\setcond{z\\sqcup b}{z\\in\\mathfrak{A},a\\sqsubseteq b\\sqcup z} & =\\\\\n\\bigsqcap\\setcond{t\\in\\mathfrak{A}}{t\\sqsupseteq b,a\\sqsubseteq t} & =\\\\\na\\sqcup b.\n\\end{align*}\n\\end{proof}\n\\begin{thm}\n\\label{brow-crit}The following are equivalent for a complete lattice~$\\mathfrak{A}$:\n\\begin{enumerate}\n\\item \\label{cobrow-cnd-frame}$\\mathfrak{A}$ is a co-frame.\n\\item \\label{cobrow-cnd-dist}$\\mathfrak{A}$ is meet infinite distributive.\n\\item \\label{cobrow-cnd-cobrow}$\\mathfrak{A}$ is a co-brouwerian lattice.\n\\item \\label{cobrow-cnd-cohey}$\\mathfrak{A}$ is a co-Heyting lattice.\n\\item \\label{cobrow-cnd-adj}$a\\sqcup\\mathord-$ has lower adjoint for every\n$a\\in\\mathfrak{A}$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\\end{proof}\n\\begin{description}\n\\item [{\\ref{cobrow-cnd-frame}$\\Leftrightarrow$\\ref{cobrow-cnd-cobrow}}] Because it is complete.\n\\item [{\\ref{cobrow-cnd-cobrow}$\\Leftrightarrow$\\ref{cobrow-cnd-cohey}}] Obvious\n(taking into account completeness of $\\mathfrak{A}$).\n\\item [{\\ref{cobrow-cnd-adj}$\\Rightarrow$\\ref{cobrow-cnd-dist}}] Let\n$\\mathord-\\psetminus a$ be the lower adjoint of $a\\sqcup\\mathord-$.\nLet $S\\in\\subsets\\mathfrak{A}$. For every $y\\in S$ we have $y\\sqsupseteq(a\\sqcup y)\\psetminus a$\nby properties of Galois connections; consequently $y\\sqsupseteq\\left(\\bigsqcap\\rsupfun{a\\sqcup}S\\right)\\psetminus a$;\n$\\bigsqcap S\\sqsupseteq\\left(\\bigsqcap\\rsupfun{a\\sqcup}S\\right)\\psetminus a$.\nSo\n\\[\na\\sqcup\\bigsqcap S\\sqsupseteq\\left(\\left(\\bigsqcap\\rsupfun{a\\sqcup}S\\right)\\psetminus a\\right)\\sqcup a\\sqsupseteq\\bigsqcap\\rsupfun{a\\sqcup}S.\n\\]\n\n\n\nBut $a\\sqcup\\bigsqcap S\\sqsubseteq\\bigsqcap\\rsupfun{a\\sqcup}S$ is\nobvious.\n\n\\item [{\\ref{cobrow-cnd-dist}$\\Rightarrow$\\ref{cobrow-cnd-cobrow}}] Let\n$a\\psetminus b=\\bigsqcap\\setcond{z\\in\\mathfrak{A}}{a\\sqsubseteq b\\sqcup z}$.\nTo prove that $\\mathfrak{A}$ is a co-brouwerian lattice it is enough\nto prove $a\\sqsubseteq b\\sqcup(a\\psetminus b)$. But it follows from\nthe lemma.\n\\item [{\\ref{cobrow-cnd-cobrow}$\\Rightarrow$\\ref{cobrow-cnd-adj}}] $a\\psetminus b=\\min\\setcond{z\\in\\mathfrak{A}}{a\\sqsubseteq b\\sqcup z}$.\nSo $a\\sqcup\\mathord-$ is the upper adjoint of $\\mathord-\\psetminus a$.\n\\item [{\\ref{cobrow-cnd-dist}$\\Rightarrow$\\ref{cobrow-cnd-adj}}] Because\n$a\\sqcup\\mathord-$ preserves all meets.\\end{description}\n\\begin{cor}\nCo-brouwerian lattices are distributive.\n\\end{cor}\nThe following theorem is essentially borrowed from \\cite{stone-spaces}:\n\\begin{thm}\nA lattice $\\mathfrak{A}$ with least element $\\bot$ is co-brouwerian\nwith pseudodifference $\\psetminus$ iff $\\psetminus$ is a binary\noperation on $\\mathfrak{A}$ satisfying the following identities:\n\\begin{enumerate}\n\\item \\label{cbpd-aa}$a\\psetminus a=\\bot$;\n\\item \\label{cbpd-aba}$a\\sqcup(b\\psetminus a)=a\\sqcup b$;\n\\item \\label{cbpd-bba}$b\\sqcup(b\\psetminus a)=b$;\n\\item \\label{cbpd-bca}$(b\\sqcup c)\\psetminus a=(b\\psetminus a)\\sqcup(c\\psetminus a)$.\n\\end{enumerate}\n\\end{thm}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\Leftarrow$}] We have\n\\[\nc\\sqsupseteq b\\psetminus a\\Rightarrow c\\sqcup a\\sqsupseteq a\\sqcup(b\\psetminus a)=a\\sqcup b\\sqsupseteq b;\n\\]\n\n\n\n$c\\sqcup a\\sqsupseteq b\\Rightarrow c=c\\sqcup(c\\psetminus a)\\sqsupseteq(a\\psetminus a)\\sqcup(c\\psetminus a)=(a\\sqcup c)\\psetminus a\\sqsupseteq b\\psetminus a$.\n\n\nSo $c\\sqsupseteq b\\psetminus a\\Leftrightarrow c\\sqcup a\\sqsupseteq b$\nthat is $a\\sqcup\\mathord-$ is an upper adjoint of $\\mathord-\\psetminus a$.\nBy a theorem above our lattice is co-brouwerian. By another theorem\nabove $\\psetminus$ is a pseudodifference.\n\n\\item [{$\\Rightarrow$}] ~\n\n\\begin{disorder}\n\\item [{\\ref{cbpd-aa}}] Obvious.\n\\item [{\\ref{cbpd-aba}}] ~\n\\begin{align*}\na\\sqcup(b\\psetminus a) & =\\\\\na\\sqcup\\bigsqcap\\setcond{z\\in\\mathfrak{A}}{b\\sqsubseteq a\\sqcup z} & =\\\\\n\\bigsqcap\\setcond{a\\sqcup z}{z\\in\\mathfrak{A},b\\sqsubseteq a\\sqcup z} & =\\\\\na\\sqcup b.\n\\end{align*}\n\n\\item [{\\ref{cbpd-bba}}] $b\\sqcup(b\\psetminus a)=b\\sqcup\\bigsqcap\\setcond{z\\in\\mathfrak{A}}{b\\sqsubseteq a\\sqcup z}=\\bigsqcap\\setcond{b\\sqcup z}{z\\in\\mathfrak{A},b\\sqsubseteq a\\sqcup z}=b$.\n\\item [{\\ref{cbpd-bca}}] Obviously $(b\\sqcup c)\\psetminus a\\sqsupseteq b\\psetminus a$\nand $(b\\sqcup c)\\psetminus a\\sqsupseteq c\\psetminus a$. Thus $(b\\sqcup c)\\psetminus a\\sqsupseteq(b\\psetminus a)\\sqcup(c\\psetminus a)$.\nWe have\n\\begin{align*}\n(b\\psetminus a)\\sqcup(c\\psetminus a)\\sqcup a & =\\\\\n((b\\psetminus a)\\sqcup a)\\sqcup((c\\psetminus a)\\sqcup a) & =\\\\\n(b\\sqcup a)\\sqcup(c\\sqcup a) & =\\\\\na\\sqcup b\\sqcup c & \\sqsupseteq\\\\\nb\\sqcup c.\n\\end{align*}\n\n\n\nFrom this by definition of adjoints: $(b\\psetminus a)\\sqcup(c\\psetminus a)\\sqsupseteq(b\\sqcup c)\\psetminus a$.\n\n\\end{disorder}\n\\end{description}\n\\end{proof}\n\\begin{thm}\n\\label{cup-pdiff}$\\left(\\bigsqcup S\\right)\\psetminus a=\\bigsqcup_{x\\in S}(x\\psetminus a)$\nfor all $a\\in\\mathfrak{A}$ and $S\\in\\subsets\\mathfrak{A}$ where\n$\\mathfrak{A}$ is a co-brouwerian lattice and $\\bigsqcup S$ is defined.\\end{thm}\n\\begin{proof}\nBecause lower adjoint preserves all suprema.\\end{proof}\n\\begin{thm}\n$(a\\psetminus b)\\psetminus c=a\\psetminus(b\\sqcup c)$ for elements\n$a$, $b$, $c$ of a co-frame.\\end{thm}\n\\begin{proof}\n$a\\psetminus b=\\bigsqcap\\setcond{z\\in\\mathfrak{A}}{a\\sqsubseteq b\\sqcup z}$.\n\n$(a\\psetminus b)\\psetminus c=\\bigsqcap\\setcond{z\\in\\mathfrak{A}}{a\\psetminus b\\sqsubseteq c\\sqcup z}$.\n\n$a\\psetminus(b\\sqcup c)=\\bigsqcap\\setcond{z\\in\\mathfrak{A}}{a\\sqsubseteq b\\sqcup c\\sqcup z}$.\n\nIt is left to prove $a\\psetminus b\\sqsubseteq c\\sqcup z\\Leftrightarrow a\\sqsubseteq b\\sqcup c\\sqcup z$.\nBut this follows from corollary~\\ref{adjoint-brow-full}.\\end{proof}\n\\begin{cor}\n$(((a_{0}\\psetminus a_{1})\\psetminus\\dots)\\psetminus a_{n})=a_{0}\\psetminus(a_{1}\\sqcup\\dots\\sqcup a_{n})$.\\end{cor}\n\\begin{proof}\nBy math induction.\n\\end{proof}\n\n\\subsection{Dual pseudocomplement on co-Heyting lattices}\n\\begin{thm}\nFor co-Heyting algebras $\\top\\psetminus b=b^{+}$.\\end{thm}\n\\begin{proof}\n~\n\\[\n\\top\\psetminus b=\\min\\setcond{z\\in\\mathfrak{A}}{\\top\\sqsubseteq b\\sqcup z}=\\min\\setcond{z\\in\\mathfrak{A}}{\\top=b\\sqcup z}=\\min\\setcond{z\\in\\mathfrak{A}}{b\\equiv z}=b^{+}.\n\\]\n\\end{proof}\n\\begin{thm}\\label{dpdfiff-meet}\n$(a\\sqcap b)^{+}=a^{+}\\sqcup b^{+}$ for every elements $a$, $b$\nof a co-Heyting algebra.\\end{thm}\n\\begin{proof}\n$a\\sqcup(a\\sqcap b)^{+}\\sqsupseteq(a\\sqcap b)\\sqcup(a\\sqcap b)^{+}\\sqsupseteq\\top$.\nSo $a\\sqcup(a\\sqcap b)^{+}\\sqsupseteq\\top$; $(a\\sqcap b)^{+}\\sqsupseteq\\top\\psetminus a=a^{+}$.\n\nWe have $(a\\sqcap b)^{+}\\sqsupseteq a^{+}$. Similarly $(a\\sqcap b)^{+}\\sqsupseteq b^{+}$.\nThus $(a\\sqcap b)^{+}\\sqsupseteq a^{+}\\sqcup b^{+}$.\n\nOn the other hand, $a^{+}\\sqcup b^{+}\\sqcup(a\\sqcap b)=(a^{+}\\sqcup b^{+}\\sqcup a)\\sqcap(a^{+}\\sqcup b^{+}\\sqcup b)$\n. Obviously $a^{+}\\sqcup b^{+}\\sqcup a=a^{+}\\sqcup b^{+}\\sqcup b=\\top$.\nSo $a^{+}\\sqcup b^{+}\\sqcup(a\\sqcap b)\\sqsupseteq\\top$ and thus $a^{+}\\sqcup b^{+}\\sqsupseteq\\top\\psetminus(a\\sqcap b)=(a\\sqcap b)^{+}$.\n\nSo $(a\\sqcap b)^{+}=a^{+}\\sqcup b^{+}$.\n\\end{proof}\n\n\\section{\\index{category theory}Intro to category theory}\n\nThis is a \\emph{very} basic introduction to category theory.\n\\begin{defn}\n\\index{multigraph!directed}A \\emph{directed multigraph} (also known\nas \\emph{quiver}) is:\n\\begin{enumerate}\n\\item \\index{vertex}a set $\\mathcal{O}$ (\\emph{vertices});\n\\item \\index{edge}a set $\\mathcal{M}$ (\\emph{edge}s);\n\\item \\index{source}\\index{destination}functions $\\Src$ and $\\Dst$ (\\emph{source}\nand \\emph{destination}) from $\\mathcal{M}$ to $\\mathcal{O}$.\n\\end{enumerate}\n\\end{defn}\n\\index{object}\\index{morphism}Note that in category theory vertices\nare called \\emph{objects} and edges are called \\emph{morphisms}.\n\\begin{defn}\n\\index{precategory}A \\emph{precategory} is a directed multigraph\ntogether with a partial binary operation $\\circ$ on the set $\\mathcal{M}$\nsuch that $g\\circ f$ is defined iff $\\Dst f=\\Src g$ (for every morphisms\n$f$ and $g$) such that\n\\begin{enumerate}\n\\item $\\Src(g\\circ f)=\\Src f$ and $\\Dst(g\\circ f)=\\Dst g$ whenever the\ncomposition $g\\circ f$ of morphisms $f$ and $g$ is defined.\n\\item $(h\\circ g)\\circ f=h\\circ(g\\circ f)$ whenever compositions in this\nequation are defined.\n\\end{enumerate}\n\\end{defn}\n\n\\begin{defn}\nThe set $\\Hom(A,B)$ (also denoted as $\\Hom_{C}(A,B)$ or just $C(A,B)$,\nwhere $C$ is our category) (morphisms from an object $A$ to an object\n$B$) is exactly morphisms which have $A$ as the source and $B$\nas the destination.\n\\end{defn}\n\n\\begin{defn}\n\\index{morphism!identity}\\emph{Identity morphism} is such a morphism\n$e$ that $e\\circ f=f$ and $g\\circ e=g$ whenever compositions in\nthese formulas are defined.\n\\end{defn}\n\n\\begin{defn}\n\\index{category}A \\emph{category} is a precategory with additional\nrequirement that for every object $X$ there exists identity morphism\n$1_{X}$.\\end{defn}\n\\begin{prop}\nFor every object $X$ there exist no more than one identity morphism.\\end{prop}\n\\begin{proof}\nLet $p$ and $q$ be both identity morphisms for a object $X$. Then\n$p=p\\circ q=q$.\\end{proof}\n\\begin{defn}\n\\index{isomorphism}\\index{inverse}An \\emph{isomorphism} is such\na morphism $f$ of a category that there exists a morphism $f^{-1}$\n(\\emph{inverse} of $f$) such that $f\\circ f^{-1}=1_{\\Dst f}$ and\n$f^{-1}\\circ f=1_{\\Src f}$.\\end{defn}\n\\begin{prop}\nAn isomorphism has exactly one inverse.\\end{prop}\n\\begin{proof}\nLet $g$ and $h$ be both inverses of $f$. Then $h=h\\circ1_{\\Dst f}=h\\circ f\\circ g=1_{\\Src f}\\circ g=g$.\\end{proof}\n\\begin{defn}\n\\index{groupoid}A \\emph{groupoid} is a category all of whose morphisms\nare isomorphisms.\n\\end{defn}\n\n\\begin{defn}\n\\index{endomorphism}A morphism whose source is the same as destination\nis called \\emph{endomorphism}.\n\\end{defn}\n\n\\begin{defn}\n\\index{involution}\\index{morphism!involutive}An \\emph{involution}\nor \\emph{involutive morphism} is an endomorphism~$f$ that $f\\circ f=1_{\\Ob f}$.\nIn other words, an involution is such a self-inverse (that is conforming\nto the formula~$f=f^{-1}$) isomorphism.\n\\end{defn}\n\n\\begin{defn}\n\\emph{Functor} from category~$C$ to category~$D$ is a mapping~$F$\nwhich associates every object~$X$ of~$C$ with an object~$F(X)$\nof~$D$ and every morphism~$f:X\\rightarrow Y$ of~$C$ with morphism\n$F(f):F(X)\\rightarrow F(Y)$ of~$D$, such that:\n\\begin{enumerate}\n\\item $F(g\\circ f)=F(g)\\circ F(f)$ for every composable morphisms $f$,~$g$\nof $C$;\n\\item $F(1_{X}^{C})=1_{FX}^{D}$ for every object~$X$ of~$C$.\n\\end{enumerate}\n\\end{defn}\n\n\\begin{defn}\n\\emph{Opposite category} $C^{\\operatorname{op}}$ of category~$C$ is the category where\n``all arrows are reversed'' that is every morphism~$f$ is replaced with so called\n\\emph{opposite morphism}~$f^{\\operatorname{op}}$ such that\n$\\Src f^{\\operatorname{op}} = \\Dst f$, $\\Dst f^{\\operatorname{op}} = \\Src f$ and\n$g^{\\operatorname{op}}\\circ f^{\\operatorname{op}} = (f\\circ g)^{\\operatorname{op}}$\n(composition taken in the ``opposite order'').\n\\end{defn}\n\n\\begin{defn}\nA \\emph{monomorphism} (also called a \\emph{monic} morphism or a \\emph{mono}) is a left-cancellative morphism. That is, an arrow~$f\\colon X\\to Y$ such that for all objects~$Z$ and all morphisms~$g_1,g_2\\colon Z\\to X$,\n\\[ f\\circ g_1=f\\circ g_2\\Rightarrow g_1=g_2. \\]\n\\end{defn}\n\nMonomorphisms are a categorical generalization of injective functions (also called ``one-to-one functions''); in some categories the notions coincide, but monomorphisms are more general.\n\n\\begin{defn}\nThe categorical dual of a monomorphism is an \\emph{epimorphism}, i.e.\\ a monomorphism in a category~$C$ is an epimorphism in the dual category~$C^{\\operatorname{op}}$ that is it\nconforms to the formula\n\\[ g_1\\circ f=g_2\\circ f\\Rightarrow g_1=g_2. \\]\n\\end{defn}\n\n\\subsection{Some important examples of categories}\n\\begin{xca}\nProve that the below examples of categories are really categories.\\end{xca}\n\\begin{defn}\nThe category $\\mathbf{Set}$ is:\n\\begin{itemize}\n\\item Objects are small sets.\n\\item Morphisms from an object $A$ to an object $B$ are triples $(A,B,f)$\nwhere $f$ is a function from $A$ to $B$.\n\\item Composition of morphisms is defined by the formula: $(B,C,g)\\circ(A,B,f)=(A,C,g\\circ f)$\nwhere $g\\circ f$ is function composition.\n\\end{itemize}\n\\end{defn}\n\n\\begin{defn}\nThe category $\\mathbf{Rel}$ is:\n\\begin{itemize}\n\\item Objects are small sets.\n\\item Morphisms from an object $A$ to an object $B$ are triples $(A,B,f)$\nwhere $f$ is a binary relation between $A$ and $B$.\n\\item Composition of morphisms is defined by the formula: $(B,C,g)\\circ(A,B,f)=(A,C,g\\circ f)$\nwhere $g\\circ f$ is relation composition.\n\\end{itemize}\n\\end{defn}\nI will denote $\\GR(A,B,f)=f$ for any morphism $(A,B,f)$ of either\n$\\mathbf{Set}$ or $\\mathbf{Rel}$.\n\n\n\\begin{defn}\nA \\emph{subcategory} of a category~$C$ is a category whose set of\nobjects is a subset of the set of objects of~$C$ and whose set of\nmorphisms is a subset of the set of morphisms of~$C$.\n\\end{defn}\n\n\\begin{defn}\n\\index{subcategory!wide}\\emph{Wide subcategory} of a category $(\\mathcal{O},\\mathcal{M})$\nis a category $(\\mathcal{O},\\mathcal{M}')$ where $\\mathcal{M}\\subseteq\\mathcal{M}'$\nand the composition on $(\\mathcal{O},\\mathcal{M}')$ is a restriction\nof composition of $(\\mathcal{O},\\mathcal{M})$. (Similarly \\emph{wide\nsub-precategory} can be defined.)\n\\end{defn}\n\n\\subsection{Commutative diagrams}\n\\begin{defn}\nA \\emph{finite path in directed multigraph} is a tuple $\\llbracket e_{0},\\ldots,e_{n}\\rrbracket$\nof edges (where $i\\in\\mathbb{N}$) such that $\\Dst e_{i}=\\Src e_{i+1}$\nfor every $i=0,\\dots,n-1$.\n\\end{defn}\n\n\\begin{defn}\nThe vertices of a finite path are $\\Src e_{0}$, $\\Dst e_{0}=\\Src e_{1}$,\n$\\Dst e_{1}=\\Src e_{2}$, \\ldots{}, $\\Dst e_{n}$.\n\\end{defn}\n\n\\begin{defn}\nComposition of finite paths $\\llbracket e_{0},\\ldots,e_{n}\\rrbracket$\nand $\\llbracket e_{k},\\ldots,e_{m}\\rrbracket$ (where $\\Dst e_{n}=\\Src e_{k}$)\nis the path $\\llbracket e_{0},\\ldots,e_{n},e_{k},\\dots e_{m}\\rrbracket$.\n(It is a path because $\\Dst e_{n}=\\Src e_{k}$.)\n\\end{defn}\n\n\\begin{defn}\nA \\emph{cycle} is a finite path whose first vertex is the same as\nthe last vertex (in other words $\\Dst e_{n}=\\Src e_{0}$).\n\\end{defn}\n\n\\begin{defn}\nA \\emph{diagram} in~$C$ is a directed multigraph, whose vertices\nare labeled with objects of~$C$ and whose edges are labeled with\nmorphisms of~$C$.\n\nI will denote the morphism corresponding to a edge~$e$ as $D(e)$.\n\\end{defn}\n\n\\begin{defn}\nA diagram in~$C$ is \\emph{commutative} when the composition of morphisms\ncorresponding to a finite path is always the same for finite paths\nfrom a fixed vertex~$A$ to a fixed vertex~$B$ independently of the\npath choice.\n\nWe will say ``\\emph{commutative diagram}'' when commutativity of\na diagram is implied by the context.\\end{defn}\n\\begin{rem}\nSee \\href{https://en.wikipedia.org/wiki/Commutative_diagram}{Wikipedia}\nfor more on definition and examples of commutative diagrams.\n\\end{rem}\nThe following is an example of a commutative diagram in~$\\mathbf{Set}$\n(because $x+5-3=x+4-2$):\n\\[\n\\begin{tikzcd}\n\\mathbb{N} \\arrow[r, \"+5\"] \\arrow[d, \"+4\"] & \\mathbb{N} \\arrow[d, \"-3\"] \\\\\n\\mathbb{N} \\arrow[r, \"-2\"] & \\mathbb{N}\n\\end{tikzcd}\n\\]\n\nWe are especially interested in the special case of commutative diagrams\nevery morphism of which is an isomorphism. So, the below theorem.\n\\begin{thm}\n\\label{rehash-isos}If morphisms corresponding to every edge~$e_{i}$\nof a cycle $\\llbracket e_{0},\\ldots,e_{n}\\rrbracket$ are isomorphisms\nthen the following are equivalent:\n\\begin{itemize}\n\\item The morphism induced by $\\llbracket e_{0},\\ldots,e_{n}\\rrbracket$\nis identity.\n\\item The morphism induced by $\\llbracket e_{n},e_{0},\\ldots,e_{n-1}\\rrbracket$\nis identity.\n\\item The morphism induced by $\\llbracket e_{n-1},e_{n},e_{0},\\ldots,e_{n-2}\\rrbracket$\nis identity.\n\\item \\ldots{}\n\\item The morphism induced by $\\llbracket e_{1},e_{2},\\ldots,e_{n},e_{0}\\rrbracket$\nis identity.\n\\end{itemize}\nIn other words, the cycle being an identity does not depend on the\nchoice of the start edge in the cycle.\\end{thm}\n\\begin{proof}\nEach step in the proof is like:\n\\begin{multline*}\nD(n)\\circ\\dots\\circ D(e_{0})=1_{\\Src D(e_{0})}\\Leftrightarrow\\\\\nD(n)^{-1}\\circ D(n)\\circ\\dots\\circ D(e_{0})\\circ D(n)=D(n)^{-1}\\circ1_{\\Src D(e_{0})}\\circ D(n)\\Leftrightarrow\\\\\nD(n-1)\\circ\\dots\\circ D(e_{0})\\circ D(n)=1_{\\Src D(e_{n})}.\n\\end{multline*}\n\\end{proof}\n\\begin{lem}\n\\label{three-loop-lem}Let $f$, $g$, $h$ be isomorphisms. Let $g\\circ f=h^{-1}$.\nThe diagram at the figure~\\ref{three-loop} is commutative, every\ncycle in the diagram is an identity.\n\n\\begin{figure}[ht]\n\\begin{tikzcd}[row sep=2.5cm, column sep=1.5cm]\n& \\bullet\n\\arrow[rd, shift left, \"f\"]\n\\arrow[ld, shift left, \"h^{-1}\"] \\\\\n\\bullet\n\\arrow[ru, shift left, \"h\"]\n\\arrow[rr, shift left, \"g^{-1}\"]\n& & \\bullet\n\\arrow[lu, shift left, \"f^{-1}\"]\n\\arrow[ll, shift left, \"g\"]\n\\end{tikzcd}\n\\caption{\\label{three-loop}}\n\\end{figure}\n\\end{lem}\n\\begin{proof}\nWe will prove by induction that every cycle of the length~$N$ in\nthe diagram is an identity.\n\nFor cycles of length~$2$ it holds by definition of isomorphism.\n\nFor cycles of length~$3$ it holds by theorem~\\ref{rehash-isos}.\n\nConsider a cycle of length above~$3$. It is easy to show that this\ncycle contains a sub-cycle of length~$3$ or below. (Consider three\nfirst edges $a\\overset{e_{0}}{\\rightarrow}b\\overset{e_{1}}{\\rightarrow}c\\overset{e_{2}}{\\rightarrow}d$\nof the path, by pigeonhole principle we have that there are equal\nelements among $a$, $b$, $c$,~$d$.) We can exclude the sub-cycle\nbecause it is identity. Thus we reduce to cycles of lesser length.\nApplying math induction, we get that every cycle in the diagram is\nan identity.\n\nThat the diagram is commutative follows from it (because for paths~$\\sigma$,~$\\tau$\nwe have the paths $\\sigma\\circ\\tau^{-1}$ and $\\tau\\circ\\sigma^{-1}$\nbeing identities).\\end{proof}\n\\begin{lem}\n\\label{four-loop-lem}Let $f$, $g$, $h$, $t$ be isomorphisms.\nLet $t\\circ h\\circ g\\circ f=1_{\\Src f}$. The diagram at the figure~\\ref{four-loop}\nis commutative, every cycle in the diagram is an identity.\n\n\\begin{figure}[ht]\n\\begin{tikzcd}[row sep=1.5cm, column sep=1.5cm]\n\\circled{(0,0)} \\arrow[r, shift left, \"f\"] \\arrow[d, shift left, \"t^{-1}\"]\n  & \\circled{(0,1)} \\arrow[d, shift left, \"g\"] \\arrow[l, shift left, \"f^{-1}\"] \\\\\n\\circled{(1,0)} \\arrow[u, shift left, \"t\"] \\arrow[r, shift left, \"h^{-1}\"]\n  & \\circled{(1,1)} \\arrow[l, shift left, \"h\"] \\arrow[u, shift left, \"g^{-1}\"]\n\\end{tikzcd}\n\\caption{\\label{four-loop}}\n\\end{figure}\n\\end{lem}\n\\begin{proof}\nAssign to every vertex $(i,j)$ of the diagram morphism $W(i,j)$\ndefined by the table~\\ref{square-table}.\n\n\\begin{table}[ht]\n\\caption{\\label{square-table}}\n\\begin{tabular}{|c|c|c|}\n\\hline \n$i$ & $j$ & $W(i,j)$\\tabularnewline\n\\hline \n\\hline \n$0$ & $0$ & $1_{\\Src f}$\\tabularnewline\n\\hline \n$0$ & $1$ & $f$\\tabularnewline\n\\hline \n$1$ & $0$ & $t^{-1}$\\tabularnewline\n\\hline \n$1$ & $1$ & $g\\circ f$\\tabularnewline\n\\hline \n\\end{tabular}\n\\end{table}\n\n\nIt is easy to verify by induction that the morphism corresponding to\nevery path in the diagram starting at the vertex $(0,0)$ and ending\nwith a vertex $(x,y)$ is $W(x,y)$.\n\nThus the morphism corresponding to every cycle starting at the vertex\n$(0,0)$ is identity.\n\nBy symmetry, the morphism corresponding to every cycle is identity.\n\nThat the diagram is commutative follows from it (because for paths~$\\sigma$,~$\\tau$\nwe have the paths $\\sigma\\circ\\tau^{-1}$ and $\\tau\\circ\\sigma^{-1}$\nbeing identities).\n\\end{proof}\n\n\\section{\\index{group theory}Intro to group theory}\n\\begin{defn}\n\\index{semigroup}A \\emph{semigroup} is a pair of a set $G$ and an associative\nbinary operation on $G$.\n\\end{defn}\n\n\\begin{defn}\n\\index{group}A \\emph{group} is a pair of a set $G$ and a binary operation\n$\\cdot$ on $G$ such that:\n\\begin{enumerate}\n\\item $(h\\cdot g)\\cdot f=h\\cdot(g\\cdot f)$ for every $f,g,h\\in G$.\n\\item \\index{identity}There exists an element $e$ (\\emph{identity}) of\n$G$ such that $f\\cdot e=e\\cdot f=f$ for every $f\\in G$.\n\\item For every element $f$ there exists an element $f^{-1}$ (\\emph{inverse} of~$f$) such that\n$f\\cdot f^{-1}=f^{-1}\\cdot f=e$.\n\\end{enumerate}\n\\end{defn}\n\\begin{obvious}\nEvery group is a semigroup.\\end{obvious}\n\\begin{prop}\nIn every group there exists exactly one identity element.\\end{prop}\n\\begin{proof}\nIf $p$ and $q$ are both identities, then $p=p\\cdot q=q$.\\end{proof}\n\\begin{prop}\nEvery group element has exactly one inverse.\\end{prop}\n\\begin{proof}\nLet $p$ and $q$ be both inverses of $f\\in G$. Then $f\\cdot p=p\\cdot f=e$\nand $f\\cdot q=q\\cdot f=e$. Then $p=p\\cdot e=p\\cdot f\\cdot q=e\\cdot q=q$.\\end{proof}\n\\begin{prop}\n$(g\\cdot f)^{-1}=f^{-1}\\cdot g^{-1}$ for every group elements $f$\nand $g$.\\end{prop}\n\\begin{proof}\n$(f^{-1}\\cdot g^{-1})\\cdot(g\\cdot f)=f^{-1}\\cdot g^{-1}\\cdot g\\cdot f=f^{-1}\\cdot e\\cdot f=f^{-1}\\cdot f=e$.\nSimilarly $(g\\cdot f)\\cdot(f^{-1}\\cdot g^{-1})=e$. So $f^{-1}\\cdot g^{-1}$\nis the inverse of $g\\cdot f$.\\end{proof}\n\\begin{defn}\n\\index{group!permutation}A \\emph{permutation group} on a set $D$\nis a group whose elements are functions on $D$ and whose composition\nis function composition.\\end{defn}\n\\begin{obvious}\nElements of a permutation group are bijections.\\end{obvious}\n\\begin{defn}\n\\index{group!permutation!transitive}A \\emph{transitive} permutation\ngroup on a set $D$ is such a permutation group $G$ on $D$ that\nfor every $x,y\\in D$ there exists $r\\in G$ such that $y=r(x)$.\n\\end{defn}\nA groupoid with single (arbitrarily chosen) object corresponds to\nevery group. The morphisms of this category are elements of the group\nand the composition of morphisms is the group operation.\n", "meta": {"hexsha": "7c4e89db0e78223221eca93af69aedd7427499ef", "size": 69013, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-common.tex", "max_stars_repo_name": "vporton/algebraic-general-topology", "max_stars_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-06-26T00:14:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-03T04:56:16.000Z", "max_issues_repo_path": "chap-common.tex", "max_issues_repo_name": "vporton/algebraic-general-topology", "max_issues_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-12-30T07:16:23.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-13T02:05:02.000Z", "max_forks_repo_path": "chap-common.tex", "max_forks_repo_name": "vporton/algebraic-general-topology", "max_forks_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.4902398215, "max_line_length": 223, "alphanum_fraction": 0.712242621, "num_tokens": 25559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8774767922879693, "lm_q1q2_score": 0.8017299408287779}}
{"text": "% section 2\r\n\\chapter {Systems of Linear Equations}\r\n\r\n%\\section{Introduction to Systems of Linear Equations}\r\n%\\section{Solving Linear Systems by Row Reduction}\r\n\r\n\\section{Introduction to Systems of Linear Equatios}\r\n\r\nNo MATLAB problems in this section.\r\n\r\n\\section{Solving Linear Ssytems by Row Reduction}\r\n\\begin{exer}\r\n(\\textit{Reduced Row Echelon Form with Pivot Columns and Ranks}) \\\\\r\nIn MATLAB, there are several useful commands for matrices such as \\textit{rref} command which produces the reduced row echelon form together with the pivot columns, and \\textit{rank} command which gives the number of the leading $1$'s without finding its row echelon form. Find the reduced row echelon form, the pivot columns, and the rank of the matrix $A$, where\r\n\\vspace{2mm}\r\n\\begin{displaymath}\r\nA = \\left[\\begin{array}{rrrrr} 2& \\hspace{1mm}-3& \\hspace{1mm} 1& \\hspace{3mm} 0& \\hspace{2mm} 4 \\\\ 1 & 1 & 2 & 2 & 0 \\\\ 3 & 0 & -1 & 4 & 5 \\\\ 1 & 6 & 5 & 6 & -4 \\end{array} \\right].\r\n\\end{displaymath}\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\n% Construct the matrix A.\r\nA=[2 -3 1 0 4; 1 1 2 2 0; 3 0 -1 4 5; 1 6 5 6 -4]; \r\n\r\n% Display the format of each entry as a rational form\r\nformat rat; \r\n\r\n% Find the reduced row echelon form \r\n% and the pivot columns of the matrix A.\r\n[rref_A pivotcols] = rref(A);\r\n\r\n% Find the rank of the matrix A.\r\nrank_A = rank(A); \r\n\r\ndisp('The reduced row echelon form is'); disp(rref_A);\r\ndisp('The pivot columns are'); disp(pivotcols);\r\ndisp('The number of the leading 1 is'); disp(rank_A);\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nThe reduced row echelon form is\r\n       1    0    0   17/13   3/2\r\n       0    1    0   11/13  -1/2\r\n       0    0    1   -1/13  -1/2\r\n       0    0    0      0     0\r\n\r\nThe pivot columns are\r\n       1    2    3\r\n\r\nThe number of leading 1 is\r\n       3\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{sol}\r\n\r\n\r\n\\vspace{5mm}\r\n\\begin{exer}\r\n(\\textit{Linear Combinations}) Use the MATLAB command \\textit{rref} to express the vector $\\mathbf{b}=(-21, \\hspace{1mm}-60, \\hspace{1mm}-3, \\hspace{1mm}108, \\hspace{1mm}84)$ as a linear combination of $\\mathbf{v_{1}}$, $\\mathbf{v_{2}}$, and $\\mathbf{v_{3}}$ where \r\n$\\mathbf{v_{1}}=(1, \\hspace{1mm} -1, \\hspace{1mm}3, \\hspace{1mm}11, \\hspace{1mm}20)$, \r\n$\\mathbf{v_{2}}=(10, \\hspace{1mm}5, \\hspace{1mm}15, \\hspace{1mm}20, \\hspace{1mm}11)$, \r\nand \r\n$\\mathbf{v_{3}}=(3, \\hspace{1mm}3, \\hspace{1mm}4, \\hspace{1mm}4, \\hspace{1mm}9)$.\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\n% Construct b as a column vector.\r\nb = [-21 -60 -3 108 84]';\r\n% Set v1, v2, v3 as column vectors. \r\nv1 = [1 -1 3 11 20]'; \r\nv2 = [10 5 15 20 11]'; \r\nv3 = [3 3 4 4 9]';\r\n% Set a matrix A with column vectors v1, v2 and v3. \r\nA = [v1 v2 v3]; \r\n% Augmented matrix [A | b].\r\naugA = [A b]; \r\n% Reduced row echelon form of augA.\r\nrref_augA = rref(augA);\r\n% Solution vector from rref_augA. \r\nx = rref_augA(1:3, 4); \r\n\r\n% Display the result as an integer form.\r\nformat rat; \r\ndisp('b is a linear combination of x(1)*v1+x(2)*v2+x(3)*v3, where');\r\ndisp('x(1) ='); disp(x(1)); disp('x(2) ='); disp(x(2));\r\ndisp('x(3) ='); disp(x(3));\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nb is a linear combination of x(1)*v1+x(2)*v2+x(3)*v3, where\r\nx(1) =\r\n      12\r\n\r\nx(2) =\r\n       3\r\n\r\nx(3) =\r\n     -21\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{sol}", "meta": {"hexsha": "9f24096ec181fa6ffa8631bd44817b380c620228", "size": 3331, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_codes/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/section2.tex", "max_stars_repo_name": "mireiffe/mas109_matlab_2021_2", "max_stars_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_codes/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/section2.tex", "max_issues_repo_name": "mireiffe/mas109_matlab_2021_2", "max_issues_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-19T08:29:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-19T08:29:55.000Z", "max_forks_repo_path": "files/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/section2.tex", "max_forks_repo_name": "mireiffe/mas109_matlab_2021_2", "max_forks_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7410714286, "max_line_length": 365, "alphanum_fraction": 0.6247373161, "num_tokens": 1240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.8017299373690366}}
{"text": "\\subsection{PageRank}\n\nOne of the most well-known ranking and scoring measures is called PageRank\n\\cite{pr}. Made famous by Google in late 90's, its main idea is to use the\nauxiliary information, mainly the \\emph{link structure}, present in the World\nWide Web as an \\emph{authority measure} of the web pages contained within.\nRepresenting the web as a graph were each node is a web page and the edges the\nlinks between a page and another, it is intuitive to see that nodes with higher\nnumber of \\emph{inlinks} (that is, the number of links arriving into a node) are\nof higher importance than the ones with no inlinks at all, just like a\nscientific article which is cited by several different sources, for example.\n\n% One of the core mechanics of the algorithm is the propagation of ranking through\n% links. That is, for every outlink of a web page in the graph, its ranking is\n% distributed evenly among all of them. That covers both the cases when a web page\n% has several different low-ranked inlinks or when it has few high-ranked ones,\n% they may have similar ranks since it is not the count that matters.\n\n% The PageRank algorithm outputs a probability, that is, the chance that an\n% imaginary user will arrive at that web page, starting at any random node. The\n% user interactions with web pages can be seen as a set of \\emph{random walks}\n% where each user follows a link until they are done surfing or they are\n% \\emph{bored} of following links and jump to another random web page instead.\n% This bored state, which is also a probability  and normally taken as $15\\%$, is\n% important as to also give a score to web pages which have no inlinks at all,\n% for example web pages just recently created.\n\n\\subsubsection{PageRank in the Twitter graph}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=3.5in,natwidth=534,natheight=345]{images/PageRank.png}\n\\caption{PageRank applied to the Twitter database. Every user is a node, while every mention in tweets is an edge. The size of the node is its relative rank among others.}\n\\label{fig:pagerank}\n\\end{figure}\n\n\n\nAlthough the original PageRank algorithm was modeled with focus on the World\nWide Web, its method could be applied to any problem which can be modelled as a\ngraph. Specifically for Twitter, one could see each \\emph{user} of the platform\nas a node and every \\emph{mention} in the tweets of a user to another as a link.\nIn the same way that web pages with high number of inlinks have a higher rank,\nusers that are mentioned frequently will be considered more relevant for our\nrecommendation engine, this process can be more clearly seen in Figure\n\\ref{fig:pagerank}. Note that we actually do not analyse the content of the\ntweet, so tweets with positive or negative sentiment will have the same\nimportance for ranking, one could think of it being a \"any publicity is good\npublicity\" kind of model.\n\n% In our case, the probability of following a user (outlink) is proportional to\n% the number of followers the corresponding user has.\nThe original PageRank algorithm considered following an outlink with equal\nprobability among all the possible links. That is reasonable with the\nunstructured meta information available in the Web today, but is intuitive to\nreason that, with more information about these users, different probabilities\ncould be applied to each one of them, depending on the task that we have at\nhand. For a user recommender engine, our approach used the \\emph{number of\nfollowers} as a good measure of importance. That is, users with high number of\nfollowers will be jumped to with higher probability in the random walk, so their\nscore will be naturally higher. Our engine implemented both methods for\nevaluation, and the results are reported in the Experiments section.\n\n\\subsubsection{PageRank Monte Carlo}\n\nThe standard implementation of the PageRank computation is done via a method called power iteration. This method, although popular and still used today\nby Google, has its drawbacks mainly regarding the speed of convergence, several\npasses may be needed until the desired precision is obtained. In our approach we\nexplored a relatively new method, which utilize \\emph{Monte Carlo algorithms} as proposed by Avrachenkov et al.\n\\cite{prmc} to\nestimate the score of the nodes of the graph.\n\nOf the several different algorithms proposed, our engine implements the\n\\emph{Monte Carlo complete path}, which is detailed in the Algorithm\n\\ref{alg:prmc}. For every user in the Twitter database, we start a random walk\nbeginning in that user and ending when the user is bored of following mentions.\nWe keep track of the total steps of all random walks and how many times each\nuser was visited. A new user is selected to be followed in the walk from all the\nusers the user mentions, which can be done by applying equal probabilities to\neach one of them or with increased chance for higher number of followers. If a\nuser does not mention anyone, we consider it a \\emph{sink} and jump to any other\nuser in the database with the same method. After every user has been at the\nbeginning of the random walk for a set number of walks, we calculate the user\nrank by dividing the number of times each user was visited over all random walks\nwith the total steps taken.\n\n\\begin{algorithm}[H]\n\\caption{PageRank Monte Carlo, complete path}\\label{alg:prmc}\n\\begin{algorithmic}\n\\Procedure{PageRank}{}\n\\ForAll{walks}\n\\ForAll{user in users}\n\t\\State $\\textit{username} \\gets \\textit{user['username']}$\n    \\State $\\textit{bored} \\gets \\textit{False}$\n    \\While{$\\neg bored$}\n\t\t\\State $\\textit{totalSteps} \\gets $\\textit{totalSteps} + 1\n        \\State $\\textit{userSteps['username']} \\gets \\textit{userSteps['username']} + 1$\n        \\State $\\textit{mentions} \\gets \\textit{getUserMentions(username)}$\n     \t\\If{$mentions \\in \\emptyset$ }\n                \\State $\\textit{username} \\gets \\textit{getRandomUser(users)}$\n        \\Else\n     \t\t\\State $\\textit{username} \\gets \\textit{getRandomUser(mentions)}$\n        \\EndIf\n        \\State $\\textit{bored} \\gets \\textit{isUserBored()}$\n    \\EndWhile\n\\EndFor\n\\EndFor\n\n\\ForAll{user in users}\n\t\\State $\\textit{username} \\gets \\textit{user['username']}$\n\t\\State $\\textit{ranks['username']} \\gets userSteps['username'] \\div totalSteps $\n\\EndFor\n\n\\State \\Return {$ranks$}\n\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n", "meta": {"hexsha": "06700f71fa8e1d3609270a61a3e941b79a2db94a", "size": 6322, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/method_pr.tex", "max_stars_repo_name": "helderm/stalkr", "max_stars_repo_head_hexsha": "4d98ef673f0c34992a3b05065f9c6f9dd8fad461", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/method_pr.tex", "max_issues_repo_name": "helderm/stalkr", "max_issues_repo_head_hexsha": "4d98ef673f0c34992a3b05065f9c6f9dd8fad461", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/method_pr.tex", "max_forks_repo_name": "helderm/stalkr", "max_forks_repo_head_hexsha": "4d98ef673f0c34992a3b05065f9c6f9dd8fad461", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.1260504202, "max_line_length": 171, "alphanum_fraction": 0.7714330908, "num_tokens": 1541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.8017299373024663}}
{"text": "\n\\subsection{Fourier series}\n\n\\subsubsection{Fourier series}\n\nMotivation: we have a function we want to display as another sort of function.\n\nMore specifically, a function can be shown as a combination of sinusoidal waves.\n\nTo frame this let\u2019s imagine a sound wave, with values \\(f(t)\\) for all time values \\(t\\). We can imagine this as a summation of sinusoidal functions. That is:\n\n\\(f(t)=\\sum_{n=0}^{\\inf } a_ncos(nw_0t)\\)\n\nWe want to get another function \\(F(\\xi )\\) for all frequencies \\(\\xi \\).\n\n\\subsubsection{Combinations of wave functions}\n\nWe can add sinusoidal waves to get new waves.\n\nFor example\n\n\\(s_N(x)=2\\sin(x+3)+\\sin(-4x)+\\dfrac{1}{2}\\cos(x)\\)\n\n\\subsubsection{As a summation of series}\n\nWe can simplify arbitrary series using the following identities:\n\n\\(\\cos(x)=\\sin(x+\\dfrac{\\tau }{8})\\)\n\n\\(\\sin(-x)=-\\sin(x)\\)\n\nSo we have:\n\n\\(s(x)=2\\sin(x+3)-\\sin(4x)+\\dfrac{1}{2}\\sin(x+\\dfrac{\\tau }{8})\\)\n\nWe can put this into the following format:\n\n\\(s(x)=\\sum^m_{i=1}a_i\\sin(b_ix+c_i)\\)\n\nWhere:\n\n\\(a=[2,-1,\\dfrac{1}{2}]\\)\n\n\\(b=[1,4,1]\\)\n\n\\(c=[3,0,\\dfrac{\\tau}{8}]\\)\n\n\\subsubsection{Ordering by \\(b\\)}\n\nWe can move terms around to get:\n\n\\(s(x)=\\sum^m_{i=1}a_i\\sin(b_ix+c_i)\\)\n\nWhere:\n\n\\(a=[2,\\dfrac{1}{2},-1]\\)\n\n\\(b=[1,1,4]\\)\n\n\\(c=[3,\\dfrac{\\tau}{8},0]\\)\n\n\\subsubsection{Adding waves with same frequency}\n\nWe know that:\n\n\\(\\sin(a+b)=\\sin(a)\\cos(b)+\\sin(b)\\cos(a)\\)\n\nSo:\n\n\\(\\sin(b_ix+c_i)=\\sin(b_ix)\\cos(c_i)+\\sin(c_i)\\cos(b_ix)\\)\n\nIf \\(2\\) terms have the same value for \\(b_i\\), then:\n\n\\(a_i\\sin(b_ix+c_i)+a_j\\sin(b_jx+c_j)=a_i\\sin(b_ix+c_i)+a_j\\sin(b_ix+c_j)\\)\n\n\\(a_i\\sin(b_ix+c_i)+a_j\\sin(b_jx+c_j)=a_i\\sin(b_ix)\\cos(c_i)+a_i\\sin(c_i)\\cos(b_ix)+a_j\\sin(b_ix)\\cos(c_j)+a_j\\sin(c_j)\\cos(b_ix)\\)\n\nSo we now get for:\n\n\\(s(x)=\\sum^m_{i=1}a_i\\sin(b_ix+c_i)\\)\n\n\\(a=[,-1]\\)\n\n\\(b=[,4]\\)\n\n\\(c=[,0]\\)\n\n", "meta": {"hexsha": "7129bb623a971dcc925fb13e98981d68ee7ab210", "size": 1800, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/transformations/03-03-fourierSeries.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/transformations/03-03-fourierSeries.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/transformations/03-03-fourierSeries.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.4545454545, "max_line_length": 158, "alphanum_fraction": 0.6366666667, "num_tokens": 679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.8017299332439116}}
{"text": "\\subsection{Evaluation metrics}\nFor evaluating the performance of the proposed models, the mean intersection over union \\(IoU\\) was applied as the accuracy metric as depicted in Eq.~\\ref{eqn:iou}. \n\\begin{equation}\n\tIoU=\\frac{Intersection}{Union}=\\frac{\\hat{Y} \\cap Y}{\\hat{Y} \\cup Y}\n\t\\label{eqn:iou}\n\\end{equation}\nwhere \\(\\hat{Y}\\) is the predicted output, and \\(Y\\) is the ground truth.\n\nA regularization technique, Early stopping was employed for stopping the training once the value of mean \\(IoU\\) on the validation dataset was not increasing anymore and the model with the best mean \\(IoU\\) value on validation data was saved for further use on the test and experimental data.\n%The model was saved at Epoch = 196, at which the mean IoU values were noted as 0.91, 0.89 on train and validation datasets respectively.\n", "meta": {"hexsha": "dadaddd0677aa885084248c3b00d783613d22bb8", "size": 823, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/journal_papers/ConvLSTM Paper/Evaluation_metrics.tex", "max_stars_repo_name": "IFFM-PAS-MISD/aidd", "max_stars_repo_head_hexsha": "9fb0ad6d5e6d94531c34778a66127e5913a3830c", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-03T05:36:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T05:36:07.000Z", "max_issues_repo_path": "reports/journal_papers/ConvLSTM Paper/Evaluation_metrics.tex", "max_issues_repo_name": "IFFM-PAS-MISD/aidd", "max_issues_repo_head_hexsha": "9fb0ad6d5e6d94531c34778a66127e5913a3830c", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "reports/journal_papers/ConvLSTM Paper/Evaluation_metrics.tex", "max_forks_repo_name": "IFFM-PAS-MISD/aidd", "max_forks_repo_head_hexsha": "9fb0ad6d5e6d94531c34778a66127e5913a3830c", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.8181818182, "max_line_length": 292, "alphanum_fraction": 0.7594167679, "num_tokens": 211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.8016253427115198}}
{"text": "\\textbf{Modify the code \\textsc{fluidflow.m} to solve the equations \n\\begin{align*}\n\\omega_t+\\psi_y\\omega_x-\\psi_x\\omega_y &= Pr\\Delta\\omega+RaPrT_x,\\\\\nT_t+\\psi_yT_x-\\psi_xT_y &= \\Delta T,\\\\\n\\Delta\\psi &= -\\omega,\n\\end{align*}\nwhere $(x,y)\\in (0,1)\\times (0,1)$ and $t>0$. Here $\\omega$ is the fluid vorticity, $\\psi$ the stream function and $T$ the temperature. The independent non-dimensional constants are the Rayleigh number $Ra$, which reflects the buoyant contribution, and the Prandtl number $Pr$, which is the ratio of viscous to thermal diffusion. For this exercise, set to $Ra = 2\\cdot 10^5$ and $Pr=0.71$ (air). The fluid is at rest at $t= 0$, with $T=\\psi=\\omega= 0$. The boundary condition for the stream function is $\\left.\\psi\\right|_{\\Gamma}=0$, which implies that there is no mass transfer through the boundary $\\Gamma$. The value of the vorticity at the walls is expressed as $\\omega_{\\Gamma}=-\\left.\\Delta\\psi\\right|_{\\Gamma}$ and the temperature at $\\Gamma$ is defined by\n\\begin{align*}\nT(t,x,y) = \n\\begin{cases}\n       2^9\\tanh^4(100t)x^5(x-1)^4,&  y=0, x\\in [0,1], t>0,\\\\\n       0,& (x,y)\\in\\Gamma, y\\neq 0, t>0.\n\\end{cases}\n\\end{align*}\n}\n\\newline\n\nWe first compute the vorticity from the velocity field,\n\\begin{align*}\n\\omega = vD_p-Du,\n\\end{align*}\nwhere $D_p$ is the transpose of $D$, the Chebyshev differentiation matrix. Then we advance the vorticity and the temperature,\n\\begin{align*}\n\\omega &= \\omega + \\Delta t\\left[-v.D\\omega-u.\\omega D_p+Pr\\left(wD_{2p}+D_2\\omega\\right)+RaPrTD_p\\right],\\\\\nT &= T + \\Delta t\\left[-v.DT-u.TD_p+TD_{2p}+D_2T\\right].\n\\end{align*}\nFurther, we recompute the stream function in the interior (the exterior keeps being zero). To solve the Poisson equation we are going to use the Sylvester equation and algorithm instead of LU factorization (see figures 6 and 7 for comparison between the two methods).\n\\begin{align*}\nD_2\\psi+\\psi D_{2p}&=-w,\\\\\nA\\psi+\\psi B &= C.\n\\end{align*}\nTo finish, we recalculate the velocities from the streamfunction,\n\\begin{align*}\nu &= D\\psi,\\\\\nv &= -\\psi D_{p},\n\\end{align*}\nand impose boundary conditions on the velocities and the temperature,\n\\begin{align*}\nu_{\\Gamma}&=0,\\\\\nv_{\\Gamma}&=0,\\\\\nT_{\\Gamma}&=0,\\\\\nT_{\\Gamma}(t,x,y= 0)&=2^9\\tanh^4(100t)x^5(x-1)^4.\n\\end{align*}\n\nIn the following figure we show the ratio between the time spent in solving the Poisson equation using LU factorization and Sylvester's algorithm versus the number of iterations. The red lines indicate the average and the standard deviation of the date. We can see that using Sylvester's equation leads to an improvement of a factor greater than 3. In figure 7 we can see the difference in the solutions is of the order of $10^{-11}$, concluding that it is advisable for this problem to use the Sylvester's approach to solve the Poisson equation. \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.9]{P5_comparison.png}\\caption{Performance comparison between LU and Sylvester's algorithm for the Poisson equation.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.9]{P5_diff.png}\\caption{Differnce between the $\\psi$ obtained using LU and Sylvester's algorithm.}\n\\end{figure}\n\nIn the next figure we see how the natural convection makes the fluid move. The hot floor makes the fluid ascend and given the no divergence condition and the non-uniformity of the temperature at the base, it is forced to rotate as we can see from the streamlines, vorcitity and velocity fields. We can see a very different situation if the hot surface is placed on top. Given the blocked convection the fluid would not move as much, as we see in figure 9. We can still see that the fluid moves, but its movement is confined to the upper part of the domain. This results are at $t=0.1$.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1.2]{P5.png}\\caption{Results obtained for natural convection at $t=0.1$.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1.2]{P5_blocked.png}\\caption{Results obtained for blocked convection at $t=0.1$.}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\n\n\\begin{verbatim}\n%% Homework 4, Problem 5 -  Francisco Castillo\nclear all; close all; clc;\n\n% Parameters\nN = 40;  %40\nPr = 0.71;\nRa = 2e5;\ndt = 2e-6;\n \n% Grid and diff matrices\n[D,xch] = cheb(N-1);\nx = (-xch+1)/2; D = -2*D;   % To trasnlate the domain to [0,1]\n[xx,yy] = meshgrid(x);\n\nDp = D';\nD2 = D^2; D2p = D2';\nindb = find(xx==0|xx==1|yy==0|yy==1); % For what?? Impose BCs in velocities\n \n\n% Laplacian of the interior\nL = kron(eye(N-2),D2(2:end-1,2:end-1))+kron(D2(2:end-1,2:end-1),eye(N-2));  \n%Linv = inv(L);\n[lo,up,per] = lu(L,'vector');  % LU factorization\n \n% Initial velocity & pre-allocate memory\nT = 0*xx;\npsi = T;\npsi2 = T;\nw = T;\nu = T;\nv = T;\n% Everything initialized to zero\ncount = 0;\nt = 0;\n\n% boundary condition\nTopt = 'blocked convection';\nif (strcmp(Topt,'natural convection'))\n    T(1,:) = TempBC(t,x);\nelseif (strcmp(Topt,'blocked convection'))\n\tT(end,:) = TempBC(t,x);\nend\n\n% main loop\ni=0;\nwhile t<.1%200\n    i=i+1;\n    % vorticity \n    w = v*Dp-D*u;  % w = dvdx-dudy\n\n    % Advance Vorticity\n    w =  w + dt*(-v.*(D*w)-u.*(w*Dp)+Pr*(w*D2p+D2*w)+Ra*Pr*T*Dp);\n\n    % Advance Temperature\n    T = T + dt*(-v.*(D*T)-u.*(T*Dp)+T*D2p+D2*T);\n\n    % compute stream function\n    %    tic \n    %    wi = w(2:end-1,2:end-1); wi=wi(:);\n    %    psi(2:end-1,2:end-1) = reshape(up\\(lo\\(-wi(per))),N-2,N-2);\n    %    time1(i) = toc;\n    %    tic\n    psi(2:end-1,2:end-1) = sylvester(D2(2:end-1,2:end-1),D2p(2:end-1,2:end-1),-w(2:end-1,2:end-1));\n    %    time2(i) = toc;\n    %    diff(i) = norm(psi-psi2);\n\n    % Update Velocity\n    u = D*psi;\n    v = -psi*Dp;\n\n    % BC's for u,v,T. Vorticity is calculated from u,v. Stream-function is\n    % obtained from w.\n    u(indb) = 0;\n    v(indb) = 0;\n    T(:,1) = 0;\n    T(:,end) = 0;\n    if (strcmp(Topt,'natural convection'))\n        T(1,:) = TempBC(t,x); \n        T(end,:) = 0;\n    elseif (strcmp(Topt,'blocked convection'))\n        T(1,:) = 0;\n        T(end,:) = TempBC(t,x);\n    end\n\n    % Advance time\n    t = t+dt;\n\n   count = count + 1;\n   if count == 200\n       \n       subplot(2,2,1)\n       contourf(xx,yy,psi)\n       axis([0 1 0 1]), axis square\n       colormap(hot)\n       title('Streamlines','fontsize',16)\n        \n       subplot(2,2,2)\n       contourf(xx,yy,w,30)\n       axis([0 1 0 1]), axis square\n       title('Vorticity','fontsize',16)\n      \n       subplot(2,2,3)\n       contourf(xx,yy,T)\n       axis([0 1 0 1]), axis square\n       title('Temperature','fontsize',16)\n       colormap(jet)\n       colorbar\n       caxis([0 1])\n       \n       speed = sqrt(u.^2+v.^2);\n       \n       subplot(2,2,4)\n       quiver(xx,yy,u./speed,v./speed)\n       axis([0 1 0 1]), axis square\n       title('Velocity','fontsize',16)\n       \n       drawnow\n              \n       count = 0;\n   end\n\nend\nif (strcmp(Topt,'natural convection'))\n    saveas(gcf,'Latex/FIGURES/P5','png')\nelseif (strcmp(Topt,'blocked convection'))\n    saveas(gcf,'Latex/FIGURES/P5_blocked','png')\nend\n\n%%\n% n = 1:i;\n% figure\n% plot(n,time1./time2)\n% hold on\n% plot(n,mean(time1./time2)*ones(size(n)),'r')\n% plot(n,(mean(time1./time2)+std(time1./time2))*ones(size(n)),'r-.')\n% plot(n,(mean(time1./time2)-std(time1./time2))*ones(size(n)),'r-.')\n% grid on\n% xlim([0 n(end)])\n% xlabel('$n$','interpreter','latex','fontsize',14)\n% ylabel('$time_1/time_2$','interpreter','latex','fontsize',14)\n% ylabel('$t_{LU}/t_{Sylvester}$','interpreter','latex','fontsize',14)\n% saveas(gcf,'Latex/FIGURES/P5_comparison','png')\n% \n% figure\n% plot(n,diff)\n% grid on\n% xlabel('$n$','interpreter','latex','fontsize',14)\n% ylabel('$\\|\\psi_{LU}-\\psi_{Sylvester}\\|$','interpreter','latex','fontsize',14)\n% ylabel('$\\|\\psi_{LU}-\\psi_{Sylvester}\\|_2$','interpreter','latex','fontsize',14)\n% xlim([0 n(end)])\n% saveas(gcf,'Latex/FIGURES/P5_diff','png')\n\n\nfunction Ty0 = TempBC(t,x)\n    Ty0 = 2^9*(tanh(100*t))^4*x.^5.*(x-1).^4;\nend\n\\end{verbatim}", "meta": {"hexsha": "ed817f32f0bb8a2ccd216889925920e80ea91007", "size": 7924, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework4/Latex/problem5.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework4/Latex/problem5.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework4/Latex/problem5.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.7543859649, "max_line_length": 764, "alphanum_fraction": 0.6467693084, "num_tokens": 2655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747658, "lm_q2_score": 0.8887588008585926, "lm_q1q2_score": 0.8015899483141268}}
{"text": "%!TEX root = TDT4265-Summary.tex\r\n\\section{Frequency filtering}\r\n\r\n\\begin{equation}\r\n    \\euler^{\\ramuno \\theta}\r\n    =\r\n    \\cos \\theta\r\n    +\r\n    \\ramuno \\sin \\theta\r\n\\end{equation}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Fourier transformation}\r\n\r\n\\subsubsection{1D continuous Fourier transform (CFT)}\r\nThe following equations define the forward and backward CFTs:\r\n\\begin{gather}\r\n    F(u) = \\int_{-\\infty}^{\\infty} f(x) \\euler^{-2 \\pi u x} \\dif x \\\\\r\n    f(x) = \\int_{-\\infty}^{\\infty} F(u) \\euler^{\\ramuno 2 \\pi u x} \\dif u \\\\\r\n\\end{gather}\r\nIn many fields $f(x)$ is a function of time, but in image processing it is usually a function that maps from spatial position in an image to image intensity. Then $F(u)$ is a complex function of frequency, with a magnitude and phase (usually only magnitude is displayed).\r\n\r\n\\subsubsection{2D discrete Fourier transform (DFT)}\r\nDigital images have discrete values, and are 2D, so we need a 2D DFT to convert them to the frequency domain. For an image of size $M \\times N$, it is\r\n\\begin{equation}\r\n    F(u,v)\r\n    =\r\n    \\sum_{x=0}^{M-1}\r\n    \\sum_{y=0}^{N-1}\r\n    f(x,y)\r\n    \\euler^{-\\ramuno 2 \\pi (\\frac{ux}{N}+\\frac{vy}{N})}\r\n\\end{equation}\r\nand the inverse transform is\r\n\\begin{equation}\r\n    f(x,y)\r\n    =\r\n    \\frac{1}{MN}\r\n    \\sum_{u=0}^{M-1}\r\n    \\sum_{v=0}^{N-1}\r\n    F(u,v)\r\n    \\euler^{\\ramuno 2 \\pi (\\frac{ux}{M}+\\frac{vy}{N})}\r\n    .\r\n\\end{equation}\r\n\r\n\\begin{figure}[htbp]\r\n    \\hfill\r\n    \\subfigure[Intensity image]{\\includegraphics[width=.45\\linewidth]{images/sin3.png}}\r\n    \\hfill\r\n    \\subfigure[Frequency image]{\\includegraphics[width=.45\\linewidth]{images/sin3real.png}}\r\n    \\hfill\r\n    \\caption{An image and its Fourier transform}\r\n\\end{figure}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Convolution}\r\n\r\n\\paragraph{Convolution theorem} Convolution in one domain is equal to multiplication in the other:\r\n\\begin{equation}\\label{eq:convolution-theorem}\r\n\\begin{split}\r\n    h(x) \\conv f(x) &\\iff H(x) \\cdot F(x) \\\\\r\n    h(x) \\cdot f(x) &\\iff H(x) \\conv F(x)\r\n\\end{split}\r\n\\end{equation}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{The sampling theorem}\r\nIf samples are taken at a rate over twice the highest frequency of a function, it can be recreated without loss of information. This limit is the sampling theorem:\r\n\\begin{equation}\r\n    \\frac{1}{\\Delta T} > 2 \\mu\\sub{max}\r\n\\end{equation}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Basics of frequency domain filtering}\r\nFiltering of an image $F(u,v)$ in the frequency domain with a filter $H(u,v)$ is done by\r\n\\begin{equation}\r\n    g(x,y) = \\fourier^{-1}[H(u,v) F(u,v)]\r\n\\end{equation}\r\nwhere $H$ is a matrix of equal size to the image. (The multiplication $H F$ is done elementwise.)\r\n\r\n\\paragraph{Shifting}\r\nTo obtain a centered Fourier transform, multiply the image by $(-1)^{x+y}$ before transforming. Then $F(0,0)$ will be at the center. Alternatively swap the quadrants after transforming.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Frequency domain smoothing}\r\n\r\n\\subsubsection{Ideal low-pass filter (ILPF)}\r\nAn ILPF is a filter with no attenuation for frequencies below a threshold (the \\emph{cutoff frequency}), and full attenuation for all frequencies above:\r\n\\begin{equation}\r\n    H(u,v) =\r\n    \\begin{cases}\r\n        1 \\quad\\mbox{if } D(u,v) \\leq D_0 \\\\\r\n        0 \\quad\\mbox{if } D(u,v) >    D_0\r\n    \\end{cases}\r\n\\end{equation}\r\nThe spatial representation of the ILPF is the $\\sinc$ function (in 2D, that means any cross-section through the origin is a $\\sinc$ function).\r\n\r\nThe convolution theorem \\eqref{eq:convolution-theorem} then reveals why the ringing effect occurs: Multiplying with an ILPF in the frequency domain is equivalent to convolving with a $\\sinc$ filter (Figure \\ref{fig:sinc}) in the spatial domain.\r\n\r\n\\begin{figure}[htbp]\r\n    \\centering\r\n    % \\includegraphics[width=.8\\linewidth]{images/sinc_x_plot}\r\n    \\includegraphics[width=.8\\linewidth]{images/sinc_2d_plot}\r\n    \\caption{The $\\sinc$ function}\r\n    \\label{fig:sinc}\r\n\\end{figure}\r\n\r\n\\subsubsection{Butterworth low-pass filter (BLPF)}\r\nDefined as\r\n\\begin{equation}\r\n    H(u,v)\r\n    =\r\n    \\frac{1}{1 + [D(u,v)/D_0]^{2n}}\r\n\\end{equation}\r\nwhere $n$ is the order and $D(u,v)$ is the distance in the frequency domain between $(u,v)$ and the center. This gives a smooth cutoff, which reduces ringing (depending on order). Order 1 has no ringing, 2 very little, and higher orders may have visible ringing. (A BLPF with $n = \\infty$ is equal to an ILPF.)\r\n\r\n\\subsubsection{Gaussian low-pass filter (GLPF)}\r\nGiven in 2D as\r\n\\begin{equation}\r\n    H(u,v) = \\euler^{-\\frac{D^2(u,v)}{2 D_0}}.\r\n\\end{equation}\r\n\r\nThe inverse Fourier of this is also a Gaussian function, so it will have no ringing. It's pretty nice.\r\n\r\n\\subsubsection{Some examples of lowpass filtering}\r\n\\begin{itemize}\r\n    \\item Smoothing digitized text to fill gaps and improve legibility, especially for machine processing.\r\n    \\item Cosmetic processing, such as softening skin on images of people.\r\n    \\item Removing artifacts, such as noise and scan lines.\r\n    \\item However, smoothing is mostly used for preprocessing.\r\n\\end{itemize}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Frequency domain sharpening}\r\nDone with high-pass filters, which are pretty much the opposite of low-pass filters:\r\n\\begin{equation}\\label{eq:frequency-hp-lp-relation}\r\n    H\\sub{highpass}(u,v) = 1 - H\\sub{lowpass}(u,v)\r\n\\end{equation}\r\n\r\n\\subsubsection{Ideal high-pass filter (IHPF)}\r\nDefined as\r\n\\begin{equation}\r\n    H(u,v) =\r\n    \\begin{cases}\r\n        0 \\quad\\mbox{if } D(u,v) \\leq D_0 \\\\\r\n        1 \\quad\\mbox{if } D(u,v) >    D_0\r\n    \\end{cases}\r\n\\end{equation}\r\n\r\n\\subsubsection{Butterworth high-pass filter (BHPF)}\r\n\\begin{equation}\r\n    H(u,v) =\r\n    \\frac{1}{1 + [D_0 / D(u,v)]^{2n}}\r\n\\end{equation}\r\n\r\n\\subsubsection{Gaussian high-pass filter (GHPF)}\r\n\\begin{equation}\r\n    H(u,v) = 1 - \\euler^{-\\frac{D^2(u,v)}{2 D_0^2}}\r\n\\end{equation}\r\n\r\n\\subsubsection{Frequency domain Laplacian filter}\r\nThe Laplacian works the same way in the frequency domain as in the spatial domain. With\r\n\\begin{equation}\r\n    H(u,v) = -4\\pi^2(u^2 + v^2)\r\n\\end{equation}\r\nthe Laplacian image is\r\n\\begin{equation}\r\n    \\nabla^2 f(x,y) = \\fourier^{-1} \\left\\{ H(u,v) F(u,v) \\right\\}\r\n\\end{equation}\r\nand the enhanced image is\r\n\\begin{equation}\r\n    g(x,y) = f(x,y) + c \\nabla^2 f(x,y)\r\n\\end{equation}\r\n\r\n\\subsubsection{Unsharp masking, highboost filtering, high-frequency emphasis filtering}\r\nLike in the spatial domain \\eqref{eq:unsharp-masking}, unsharp masking and highboost filtering can be be done in the frequency domain:\r\n\\begin{equation}\r\n\\begin{split}\r\n    g(x,y)\r\n    &=\r\n    \\fourier^{-1}\r\n    \\left\\{\r\n        \\left[\r\n            1 + k \\cdot [1 - H\\sub{LP}(u,v)]\r\n        \\right]\r\n        F(u,v)\r\n    \\right\\} \\\\\r\n    &=\r\n    \\fourier^{-1}\r\n    \\left\\{\r\n        [1 + k \\cdot H\\sub{HP}(u,v)] F(u,v)\r\n    \\right\\}\r\n\\end{split}\r\n\\end{equation}\r\nRemember \\eqref{eq:frequency-hp-lp-relation}. This leads to the high-frequency emphasis filter\r\n\\begin{equation}\r\n    g(x,y)\r\n    =\r\n    \\fourier^{-1}\r\n    \\left\\{\r\n        [k_1 + k_2 \\cdot H\\sub{HP}(u,v)] F(u,v)\r\n    \\right\\}\r\n\\end{equation}\r\nwhere $k_1 \\geq 0$ is the DC term, and $k_2 \\geq 0$ sets the contribution of high frequencies. By setting a nonzero DC term, the low frequency grey levels is not lost. High-frequency emphasis filtering followed by histogram equalization can enhance clarity and detail significantly, and is useful for e.g. X-ray images.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Selective filters}\r\nThese filters only affect parts of the frequency spectrum.\r\n\r\n\\subsubsection{Bandreject and bandpass}\r\nFilters that remove all frequencies inside or outside a given range. Like normal filters, these can be created as ideal, Butterworth, or Gaussian filters.\r\n\r\n\\subsubsection{Notch filters}\r\nThese filters reject (or pass) frequencies at chosen locations in the frequency rectangle. A common example is removing periodic noise, such as moir\u00e9.\r\n", "meta": {"hexsha": "d5a77721ce75cd9e69fd81fc23926434d4a13ffc", "size": 8213, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TDT4265 Computer vision/04-filtering-in-the-frequency-domain.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TDT4265 Computer vision/04-filtering-in-the-frequency-domain.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TDT4265 Computer vision/04-filtering-in-the-frequency-domain.tex", "max_forks_repo_name": "jakoblover/ntnu-course-summaries", "max_forks_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.3785046729, "max_line_length": 320, "alphanum_fraction": 0.6398392792, "num_tokens": 2362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.8633916222765629, "lm_q1q2_score": 0.8015803804474058}}
{"text": "% Copyright 2018 Melvin Eloy Irizarry-Gelp\u00ed\n\\chapter{Mechanic Energy}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Preliminary}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThere are many kinds of energy. You have \\textbf{kinetic energy}, which is associated with motion. The amount of kinetic energy $K$ depends on the amount of mass $m$ and the amount of speed $v$:\n\\begin{equation}\n    K = \\frac{1}{2} m v^{2}\n\\end{equation}\nNote that kinetic energy changes if the velocity of the object changes.\n\nYou have \\textbf{gravitational energy} (a form of potential energy), which is associated to being in a region with a gravitational field. The amount of gravitational energy $U_{g}$ depends on the amount of mass $m$, the amount of gravitational acceleration $g$, and the amount of height $h$ measured from a reference point:\n\\begin{equation}\n    U_{g} = m g h\n\\end{equation}\nNote that the gravitational energy changes if the height of the object changes.\n\nFinally, you have \\textbf{mechanic energy}. The amount of mechanic energy $E$ is just the sum of kinetic energy $K$ and potential energy. In the case when the potential energy is only gravitational in nature, then the mechanic energy is\n\\begin{equation}\n    E = K + U_{g}\n\\end{equation}\nEnergy cannot be created nor destroyed; it can only be transformed into other forms of energy. In a closed system, where energy is not added nor removed by an external source, mechanic energy $E$ is \\textbf{constant in time}.\n\nIf the object only moves and feels gravity, then the mechanic energy $E$ is given by\n\\begin{equation}\n    E = \\frac{1}{2} m v^{2} + m g h\n\\end{equation}\nSolving for $v^{2}$ you get\n\\begin{equation} \\label{eq.07.vv}\n    v^{2} = \\left( - 2 g \\right) h + \\left( \\frac{2 E}{m} \\right)\n\\end{equation}\nThis relation predicts that $v^{2}$ is a \\textbf{linear function} of $h$ with the slope being $-2g$ and the intercept being $2 E / m$. That is, the data in a $v^{2}$ versus $h$ graph should have a \\textbf{linear shape}.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Experiment}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIn order to study a system where there is gravitational energy, and also that that gravitational changes with time, we used an object moving along an incline. With a motion sensor, we recorded the \\textbf{position} $d$ and \\textbf{velocity} $v$ along the incline as they changed with time. You also recorded some height measurements to determine the sine of the angle of inclination $\\theta$ of the incline. Also, you recorded the mass $m$ of the cart.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Analysis}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nWe would like to test two predictions:\n\\begin{enumerate}\n    \\item Mechanic energy does not change with time.\n    \\item There is a linear relation between $v^{2}$ and $h$ given by equation (\\ref{eq.07.vv}).\n\\end{enumerate}\nTo test the first prediction, we need to compute the mechanic energy with the data that we collected. To test the second prediction, we need to make a graph with $v^{2}$ in the vertical axis and $h$ in the horizontal axis.\n\nHere are some steps to complete the analysis.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Calculate Sine}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nYou measured the heights of four positions along the incline:\n\\begin{equation}\n    h_{1} \\qquad h_{2} \\qquad h_{3} \\qquad h_{4}\n\\end{equation}\nAssuming that the four positions are equally separated by a distance $x$ (I used 10 cm; some people used that also; others did 20 cm), then the sine of the angle should be given by the following three calculations:\n\\begin{equation}\n    \\sin{(\\theta_{1})} = \\frac{h_{2} - h_{1}}{x}, \\qquad \\sin{(\\theta_{2})} = \\frac{h_{3} - h_{2}}{x}, \\qquad \\sin{(\\theta_{3})} = \\frac{h_{4} - h_{3}}{x}\n\\end{equation}\nYou can think of each of these as an independent measurement, so take the average value of the three and use that as the value for the sine of the angle:\n\\begin{equation}\n    \\sin{(\\theta)} = \\frac{1}{3} \\left[ \\sin{(\\theta_{1})} + \\sin{(\\theta_{2})} + \\sin{(\\theta_{3})} \\right]\n\\end{equation}\nYou need this sine because the height $h$ at the incline is related to the position $d$ along the incline by the relation\n\\begin{equation}\n    h = d \\sin{(\\theta)}\n\\end{equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Truncate the Data}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nBefore you can do anything with the data from the experiment, you need to isolated the part of the data where the motion along the incline is happening. In order to know where to cut the data, it is best to make a scatter plot with velocity in the vertical axis and time in the horizontal axis. There are three kinds of truncation:\n\\begin{enumerate}\n    \\item Upward motion only: find the time just after the velocity values begin the diagonal downward trend, and the time when the velocity is close to zero\n    \\item Downward motion only: find the time when the velocity is close to zero, and the time just before the velocity ends the diagonal downward trend\n    \\item Upward and downward motion: find the time just after the velocity values begin the diagonal downward trend, and the time just before the downward trend ends\n\\end{enumerate}\nOnce you know the initial time and the final time of the motion, just delete the data outside of this time interval.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Calculate Height}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIn a separate column, you should compute the value of the height on the incline using the values in the position column. If $d$ is a position value, then the corresponding height is given by\n\\begin{equation}\n    h = d \\sin{(\\theta)}\n\\end{equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Calculate Kinetic Energy}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIn a separate column, you should compute the value of the kinetic energy using the values in the velocity column. If $v$ is a velocity value, then the corresponding kinetic energy is given by\n\\begin{equation}\n    K = \\frac{1}{2} m v^{2}\n\\end{equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Calculate Gravitational Energy}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIn a separate column, you should compute the value of the gravitational energy using the values in the height column. If $h$ is a height value, then the corresponding gravitational energy is given by\n\\begin{equation}\n    U_{g} = m g h\n\\end{equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Calculate Mechanic Energy}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIn a separate column, you should compute the value of the mechanic energy using the values in the kinetic and gravitational energy columns. If $K$ is a value in the kinetic energy column, and $U_{g}$ is a value in the gravitational energy column, then the mechanic energy is given by\n\\begin{equation}\n    E = K + U_{g}\n\\end{equation}\nMake sure that you add values that are evaluated at the same time.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Graph Mechanic Energy vs Time}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nOne of the goals of this experiment is to verify that mechanic energy is constant in time. To check this, you can make a scatter plot with time in the horizontal axis and mechanic energy in the vertical axis. In principle, you should see that the values of mechanic energy do not change with time. In practice, we see that in general the mechanic energy decreases as time passes. This is actually true, since in this experiment we could not completely remove friction and this force leads to a dissipation of energy. However, the amount of change in energy over time is very small, so effectively and approximately mechanic energy is constant.\n\nIn particular, note that the energy values in my run 6 (figure \\ref{figure.07.run.6.e}) appear to be random. This strongly suggest that the variations are more related to noise than anything physical.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.71]{image/07-mechanic/run-1-energy.png}\n    \\caption{}\n    \\label{figure.07.run.1.e}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.71]{image/07-mechanic/run-2-energy.png}\n    \\caption{}\n    \\label{figure.07.run.2.e}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.71]{image/07-mechanic/run-5-energy.png}\n    \\caption{}\n    \\label{figure.07.run.5.e}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.71]{image/07-mechanic/run-6-energy.png}\n    \\caption{}\n    \\label{figure.07.run.6.e}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Calculate Velocity Squared}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIn a separate column, you should calculate the velocity squared using the values in the velocity column. If $v$ is a velocity values, then the velocity square is $v^2$ or equivalently $v \\times v$.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Graph $v^2$ vs $h$}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe other goal of this experiment was to verify the linear relation between $v^{2}$ and $h$ suggested by equation (\\ref{eq.07.vv}) due to conservation of energy. Since the relation is a linear function, the data points should arrange themselves to form a linear shape. You can use Google Sheets or Excel to find the best linear fit. In Google Sheets, this is under ``Series'' in the chart editor. You need to check the ``Trend line'' box and make sure that it is ``Linear''. It is good practice to reduce the size of the data points (I use 2px) and to use a color for the trend line that is different from the color of the data points. In my case I have blue data points for the experimental data and red line for the best fit line.\n\nIf the data were perfect, then the slope of this linear fit should be given by\n\\begin{equation} \\label{eq.07.slope}\n    \\text{slope } = -2g = 19.6 \\text{ m/s}^{2}\n\\end{equation}\nand the intercept would be related to the amount of mechanic energy via\n\\begin{equation}\n    \\text{intercept } = \\frac{2 E}{m}\n\\end{equation}\nThe slope is negative, so we should see a diagonal line that is downward as height increases. From the intercept you can get a value for mechanic energy that should be close to what you found in the mechanic energy column:\n\\begin{equation} \\label{eq.07.intercept}\n    E = \\frac{m \\times \\text{ intercept}}{2}\n\\end{equation}\nYou can also compare this value with the average of the mechanic energy column (use the \\texttt{AVERAGE} function to compute this). Note that this is an average over time.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.71]{image/07-mechanic/run-1-fit.png}\n    \\caption{}\n    \\label{figure.07.run.1.fit}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.71]{image/07-mechanic/run-2-fit.png}\n    \\caption{}\n    \\label{figure.07.run.2.fit}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.71]{image/07-mechanic/run-5-fit.png}\n    \\caption{}\n    \\label{figure.07.run.5.fit}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.71]{image/07-mechanic/run-6-fit.png}\n    \\caption{}\n    \\label{figure.07.run.6.fit}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{My Data}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nI collected ten runs of data. In run 1, I used a truncation that only kept the upward motion. In run 2, I used a truncation that kept the upward and the downward motion. For run 5 and 6, I used a truncation that only kept the downward motion. As you can see, the linear fits are very appropriate, so the data does satisfy a linear relation. Furthermore, the values for the slope agree with the prediction: they are all very close to the predicted value in (\\ref{eq.07.slope}). Also, the value of the intercept can be used in equation (\\ref{eq.07.intercept}) to obtain an energy value that agrees with the time average mechanic energy.\n\nLet us extract these values from a graph. Look at graph \\ref{figure.07.run.6.fit} for run 6. The slope is -19.5 m/s$^{2}$. The intercept is 1.49 m$^{2}$/s$^{2}$. If the mass is 0.5 kg, then\n\\begin{equation}\n    \\frac{m \\times \\text{ intercept}}{2} = \\frac{1}{2} (0.5 \\text{ kg}) (1.49 \\text{ m}^{2}\\text{/s}^{2}) = 0.3717 \\text{ J}\n\\end{equation}\nThis number is close to the time-average of the mechanic energy: 0.3728 J.\n\nHere is a table summarizing some of my results.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{table}\n\t\\centering\n    \\begin{tabular}{|r|r|r|r|r|}\\hline\n        Run & 1 & 2 & 5 & 6 \\\\ \\hline\n        Slope (m/s$^{2}$) & -21.1 & -19.9 & -19.3 & -19.5 \\\\\n        Intercept (m$^{2}$/s$^{2}$) & 1.78 & 1.33 & 1.82 & 1.49 \\\\\n        $E$ from intercept (J) & 0.4460 & 0.3326 & 0.4540 & 0.3717 \\\\\n        Time-averaged $E$ (J) & 0.4210 & 0.3283 & 0.4587 & 0.3728 \\\\\n        \\hline\n    \\end{tabular}\n    \\caption{Summary of results}\n    \\label{table.07.results}\n\\end{table}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Your Data}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nYou should have ten runs of data as well.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Your Lab Report}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nFor your lab report, I want you to look at three of your ten runs. You are free to choose which three runs. For the first run you should use a truncation that leaves the upward motion only. For the second run, use a truncation with the downward motion only. For the third run, use a truncation with both upward and downward motion.\n\nFor each of the three runs you should\n\\begin{enumerate}\n    \\item produce a mechanic energy versus time graph\n    \\item produce a $v^{2}$ versus $h$ graph; include the best linear fit and extract the slope and the intercept\n\\end{enumerate}\nYou should also have a table like the one above summarizing the results (my table has four runs; your table should have three).", "meta": {"hexsha": "ca55be492e3522b402d67704b78e47a459d73168", "size": 15827, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/07-mechanic.tex", "max_stars_repo_name": "meridethfrey/phys-207L", "max_stars_repo_head_hexsha": "372e7c08b2782171fd56a5204dda7cbdb2d066b3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter/07-mechanic.tex", "max_issues_repo_name": "meridethfrey/phys-207L", "max_issues_repo_head_hexsha": "372e7c08b2782171fd56a5204dda7cbdb2d066b3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter/07-mechanic.tex", "max_forks_repo_name": "meridethfrey/phys-207L", "max_forks_repo_head_hexsha": "372e7c08b2782171fd56a5204dda7cbdb2d066b3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.2198275862, "max_line_length": 732, "alphanum_fraction": 0.5828647248, "num_tokens": 3579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.8652240843146881, "lm_q1q2_score": 0.8014602933203374}}
{"text": "\\section{Error Introduced by Linear Interpolation}\nWe obtain the initial conditions for the standing accretion shock problem with an external code. We then have to interpolate these data onto the grid for use in \\texttt{thornado}. We start by proving that linear interpolation is a convex combination of the solution at the boundary points.\n\n\\subsection{Proof that Linear Interpolation is a Convex Combination of Boundary-Points}\nLinear interpolation of a function, $f$, of a variable, $r$, bounded by two points $r_{L}$ and $r_{H}$, with $r_{H}>r_{L}$, can be written as:\n\\begin{equation}\n    f\\left(r\\right)=f\\left(r_{L}\\right)+\\f{f\\left(r_{H}\\right)-f\\left(r_{L}\\right)}{r_{H}-r_{L}}\\left(r-r_{L}\\right).\n\\end{equation}\nBy making a change of variables from $r$ to $\\eta$, where:\n\\begin{equation}\n    r\\left(\\eta\\right)=\\eta\\,r_{H}+\\left(1-\\eta\\right)r_{L}=r_{L}+\\eta\\,\\Delta r\\implies\\eta=\\f{r-r_{L}}{\\Delta r},\\hspace{1em}\\eta\\in\\left[0,1\\right],\n\\end{equation}\nsuch that $r\\left(\\eta=0\\right)=r_{L}$ and $r\\left(\\eta=1\\right)=r_{H}$, we have that:\n\\begin{align}\n    f\\left(\\eta\\right)&=f\\left(0\\right)+\\f{f\\left(1\\right)-f\\left(0\\right)}{1-0}\\left(\\eta-0\\right)=f\\left(0\\right)+\\left(f\\left(1\\right)-f\\left(0\\right)\\right)\\eta\\\\\n    \\implies f\\left(\\eta\\right)&=\\eta\\,f\\left(1\\right)+\\left(1-\\eta\\right)f\\left(0\\right).\n\\end{align}\n\nSo when we interpolate a fluid variable, say the mass-density $\\rho$, we have:\n\\begin{equation}\n    \\rho\\left(r\\right)=\\rho_{L}+\\f{\\Delta\\rho}{\\Delta r}\\left(r-r_{L}\\right)\\longrightarrow\\rho\\left(\\eta\\right)=\\eta\\,\\rho_{H}+\\left(1-\\eta\\right)\\rho_{L},\n\\end{equation}\nwhere $\\rho_{L}\\equiv\\rho\\left(r_{L}\\right)$ and $\\rho_{H}=\\rho\\left(r_{H}\\right)$.\n\n\n\\subsection{Example: $f\\left(x\\right)=x^{2}$}\nWe can show this directly for simple functions. We take as an example $f\\left(x\\right)=x^{2}$:\n\\begin{align}\n    f\\left(x\\right)&=x^{2}=\\left[x_{L}+\\eta\\left(x_{R}-x_{L}\\right)\\right]^{2}=x_{L}^{2}+\\eta^{2}\\left(x_{R}-x_{L}\\right)^{2}+2\\,x_{L}\\,\\eta\\left(x_{R}-x_{L}\\right)\\\\\n    &=x_{L}^{2}+\\eta^{2}\\,x_{R}^{2}+\\eta^{2}\\,x_{L}^{2}-2\\,\\eta^{2}\\,x_{L}\\,x_{R}+2\\,\\eta\\,x_{L}\\,x_{R}-2\\,\\eta\\,x_{L}^{2}.\n\\end{align}\nNow we add and subtract the interpolated solution: $\\eta\\,x_{H}^{2}+\\left(1-\\eta\\right)x_{L}^{2}$. This yields:\n\\begin{align}\n    x^{2}&=x_{L}^{2}+\\eta^{2}\\,x_{R}^{2}+\\eta^{2}\\,x_{L}^{2}-2\\,\\eta^{2}\\,x_{L}\\,x_{R}+2\\,\\eta\\,x_{L}\\,x_{R}-2\\,\\eta\\,x_{L}^{2}+\\eta\\,x_{H}^{2}+\\left(1-\\eta\\right)x_{L}^{2}-\\eta\\,x_{H}^{2}-\\left(1-\\eta\\right)x_{L}^{2}\\\\\n    &=\\left[\\eta\\,x_{H}^{2}+\\left(1-\\eta\\right)x_{L}^{2}\\right]+\\left[-\\eta\\left(1-\\eta\\right)x_{L}^{2}-\\eta\\left(1-\\eta\\right)x_{H}^{2}+2\\,\\eta\\,x_{L}\\,x_{H}\\left(1-\\eta\\right)\\right]\\\\\n    &=\\left[\\eta\\,x_{H}^{2}+\\left(1-\\eta\\right)x_{L}^{2}\\right]-\\eta\\left(1-\\eta\\right)\\left[x_{L}^{2}+x_{H}^{2}-2\\,x_{L}\\,x_{H}\\right]\\\\\n    &=\\left[\\eta\\,x_{H}^{2}+\\left(1-\\eta\\right)x_{L}^{2}\\right]-\\eta\\left(1-\\eta\\right)\\left(x_{H}-x_{L}\\right)^{2}\\\\\n    &=\\left[\\eta\\,x_{H}^{2}+\\left(1-\\eta\\right)x_{L}^{2}\\right]-\\eta\\left(1-\\eta\\right)\\left(\\Delta x\\right)^{2}.\n\\end{align}\nThe term in square brackets is the interpolated solution, and the second term is the remainder, i.e. the error in the interpolated solution. So we see that when using linear interpolation to interpolate the function $f\\left(x\\right)=x^{2}$ we introduce an error (of the order $\\left(\\Delta x\\right)^{2}$) that goes to zero as the step-size goes to zero.\n\nAs a final step we replace $\\eta$ with $x$, yielding:\n\\begin{align}\n    f\\left(x\\right)=x^{2}&=x_{L}^{2}+\\f{x_{H}^{2}-x_{L}^{2}}{x_{H}-x_{L}}\\left(x-x_{L}\\right)-\\left(x-x_{L}\\right)\\left(x_{H}-x\\right)\\\\\n    &=f\\left(x_{L}\\right)+\\f{\\Delta f}{\\Delta x}\\left(x-x_{L}\\right)-\\left(x-x_{L}\\right)\\left(x_{H}-x\\right).\n\\end{align}\n\nWe show the results of this in the following figure:\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{LinearInterpolationError}\n\\end{figure}\n\n\\subsection{Mass Constant}\nThe mass constant, $C_{D}$, from the 3+1 GR hydrodynamics equations is:\n\\begin{equation}\n    C_{D}\\left(r\\right)=\\psi\\left(r\\right)^{6}\\,\\alpha\\left(r\\right)\\,r^{2}\\,\\rho\\left(r\\right)\\,W\\left[v\\left(r\\right)\\right]\\,v\\left(r\\right).\n\\end{equation}\nWhen we map from the radial coordinates from the original data to the mesh in \\texttt{thornado} we don't introduce any error, because it is a linear map. This means that all the error we introduce must be due to $\\rho$, $W$, and $v$. So, when deriving the error we consider the different function:\n\\begin{equation}\n    C'_{D}\\left(r\\right)\\equiv\\f{C_{D}\\left(r\\right)}{\\psi\\left(r\\right)^{6}\\,\\alpha\\left(r\\right)\\,r^{2}}=\\rho\\left(r\\right)\\,W\\left[v\\left(r\\right)\\right]\\,v\\left(r\\right).\n\\end{equation}\n\nFrom the data we have this exact value at the two endpoints:\n\\begin{align}\n    C'_{D}\\left(r_{L}\\right)&\\equiv C'^{L}_{D}=\\rho_{L}\\,W_{L}\\,v_{L}\\\\\n    C'_{D}\\left(r_{H}\\right)&\\equiv C'^{H}_{D}=\\rho_{H}\\,W_{H}\\,v_{H}.\n\\end{align}\n", "meta": {"hexsha": "bb56157cdb9ac814415f0a50862e527c3046bb21", "size": 4912, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/Euler/SamsTexFiles/LinearInterpolationError.tex", "max_stars_repo_name": "srichers/thornado", "max_stars_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-12-08T16:16:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T19:31:21.000Z", "max_issues_repo_path": "Documents/Euler/SamsTexFiles/LinearInterpolationError.tex", "max_issues_repo_name": "srichers/thornado", "max_issues_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2019-07-10T20:13:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-11T13:21:00.000Z", "max_forks_repo_path": "Documents/Euler/SamsTexFiles/LinearInterpolationError.tex", "max_forks_repo_name": "srichers/thornado", "max_forks_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-11-14T01:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T02:08:20.000Z", "avg_line_length": 71.1884057971, "max_line_length": 353, "alphanum_fraction": 0.6504478827, "num_tokens": 1924, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642944, "lm_q2_score": 0.90329420279886, "lm_q1q2_score": 0.8014067742831231}}
{"text": "\\chapter{Probability Distribution}\n\\label{ch:prob_distr}\n\n\\section{List of supported probability distributions}\nStatAnaly supports the following probability distributions, in alphabetical order:\n\n\\begin{enumerate}\n    \\item Cauchy distribution\n    \\item Chi distribution\n    \\item Chi Squared distribution\n    \\item Erlang distribution\n    \\item Exponential distribution\n    \\item Gamma distribution\n    \\item Irwin-Hall distribution\n    \\item Non-central Chi distribution\n    \\item Non-central Chi Squared distribution\n    \\item Normal distribution\n    \\item Rayleigh distribution\n    \\item Standard Normal distribution\n    \\item Uniform distribution (Continuous)\n\\end{enumerate}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Cauchy distribution}\n\n\\subsubsection*{PDF}\n\\[\n    P(x) = \\frac{1}{\\pi} \\frac{b}{(x-m)^2 + b^2}\n\\]\nwhere $b$ is the scale parameter which specifies the half-width at half-maximum; \n$m$ is the location parameter which specifies the location of the peak of the distribution.\n\n\\subsubsection*{CDF}\n\\[\n    D(x) = \\frac{1}{\\pi} \\arctan{(\\frac{x-m}{b})} + \\frac{1}{2}\n\\]\n\n\\subsubsection*{Mean}\n\\[\n    \\text{Undefined}\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    \\text{Undefined}\n\\]\n\n\\subsubsection*{Skewness}\n\\[\n    \\text{Undefined}\n\\]\n\nReference:\n\\href{https://mathworld.wolfram.com/CauchyDistribution.html}{WolframMathWorld}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Chi distribution} \n\n\\subsubsection*{PDF}\n\\[\n    P(x) = \\frac{2^{1-k/2} x^{k-1} \\exp{(-x^2/2)}}{\\Gamma(k/2)}\n\\]\nwhere $k$ is the degrees of freedom.\n\n\\subsubsection*{CDF}\n\\[\n    D(x) = P(k/2, x^2/2)\n\\]\nwhere $P(a,b)$ is the regularized gamma function.\n\n\\subsubsection*{Mean}\n\\[\n    \\mu = \\sqrt{2} \\frac{\\Gamma((k+1)/2)}{\\Gamma(k/2)}\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    \\sigma^2 = k-\\mu^2\n\\]\n\n\\subsubsection*{Skewness}\n\\[\n    \\frac{\\mu}{\\sigma^3} (1-2\\sigma^2)\n\\]\n\nReference:\n\\href{https://en.wikipedia.org/wiki/Chi_distribution}{Wikipedia}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Chi Squared distribution}\n\nA Chi Squared distribution with $k$ degrees of freedom is the \ndistribution of a sum of the squares of $k$ independent \nstandard normal random variables.\n\n\\subsubsection*{PDF}\n\\[\n    P(x) = \\frac{x^{k/2-1} \\exp(-x/2)}{2^{k/2} \\Gamma(k/2)}\n\\]\nwhere $k$ is the degrees of freedom; $\\Gamma(a)$ is the gamma function.\n\n\\subsubsection*{CDF}\n\\[\n    D(x) = P(k/2, x/2)\n\\]\nwhere $P(a,b)$ is the regularized gamma function.\n\n\\subsubsection*{Mean}\n\\[\n    \\mu = k\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    2k\n\\]\n\n\\subsubsection*{Skewness}\n\\[\n    \\sqrt{8/k}\n\\]\n\nReference:\n\\href{https://en.wikipedia.org/wiki/Chi-squared_distribution}{Wikipedia}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Erlang distribution}\n\n\\subsubsection*{PDF}\n\\[\n    P(x) = \\frac{\\lambda^k x^{k-1} \\exp{(\\lambda x)}}{(k-1)!}\n\\]\nwhere $k$ is the shape parameter; $\\lambda$ is the rate parameter.\n\n\\subsubsection*{CDF}\n\\[\n    D(x) = \\frac{\\gamma(k, \\lambda x)}{(k-1)!}\n\\]\nwhere $\\gamma(a,b)$ is the lower gamma function.\n\n\\subsubsection*{Mean}\n\\[\n    \\frac{k}{\\lambda}\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    \\frac{k}{\\lambda^2}\n\\]\n\n\\subsubsection*{Skewness}\n\\[\n    \\frac{2}{\\sqrt{k}}\n\\]\n\nReference:\n\\href{https://en.wikipedia.org/wiki/Erlang_distribution}{Wikipedia}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Exponential distribution}\n\n\\subsubsection*{PDF}\n\\[\n    P(x) = \\begin{cases} \n        \\lambda \\exp{(-\\lambda x)} & x\\geq 0,\\\\\n        0 & x<0.\n        \\end{cases}\n\\]\n\n\\subsubsection*{CDF}\n\\[\n    D(x) = \\begin{cases}\n        1-\\exp{(-\\lambda x)} & x \\ge 0, \\\\\n        0 & x < 0.\n        \\end{cases}\n\\]\n\n\\subsubsection*{Mean}\n\\[\n    \\frac{1}{\\lambda}\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    \\frac{1}{\\lambda^2}\n\\]\n\n\\subsubsection*{Skewness}\n\\[\n    2\n\\]\n\nReference:\n\\href{https://en.wikipedia.org/wiki/Exponential_distribution}{Wikipedia}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Gamma distribution}\n\n\\subsubsection*{PDF}\n\\[\n    P(x)= \\frac{1}{\\Gamma(\\alpha)\\theta^{\\alpha}} \n            x^{\\alpha-1} \\exp{(-\\frac{x}{\\theta})}\n\\]\nwhere $\\alpha$ is the shape parameter; $\\theta$ is the scale parameter.\n\n\\subsubsection*{CDF}\n\\[\n    D(x)= \\frac{1}{\\Gamma(\\alpha)} \\gamma(\\alpha, \\frac{x}{\\theta})\n\\]\n\n\\subsubsection*{Mean}\n\\[\n    k \\theta\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    k \\theta^2\n\\]\n\n\\subsubsection*{Skewness}\n\\[\n    \\frac{2}{\\sqrt(\\alpha)}\n\\]\n\nReference:\n\\href{https://mathworld.wolfram.com/GammaDistribution.html}{WolframMathWorld}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Irwin-Hall distribution}\n\n\\subsubsection*{PDF}\n\\[\n    P(x) = \\frac{1}{(n-1)!} \\sum_{{k=0}}^{{\\lfloor x\\rfloor }}\n        (-1)^{k}{\\binom{n}{k}}(x-k)^{{n-1}}\n\\]\nwhere $n$ is number of IDD of uniform distributions.\n\n\\subsubsection*{CDF}\n\\[\n    D(x) = \\frac{1}{n!} \\sum_{{k=0}}^{{\\lfloor x\\rfloor}}\n        (-1)^{k}{\\binom{n}{k}}(x-k)^{n}\n\\]\n\n\\subsubsection*{Mean}\n\\[\n    \\frac{n}{2}\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    \\frac{n}{12}\n\\]\n\n\\subsubsection*{Skewness}\n\\[\n    0\n\\]\n\nReference:\n\\href{https://en.wikipedia.org/wiki/Irwin%E2%80%93Hall_distribution}{WolframMathWorld}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Non-central Chi distribution}\n\n\\subsubsection*{PDF}\n\\[\n    P(x) = {\\frac{\\exp{(-(x^{2}+\\lambda^{2})/2)}x^{k}\\lambda}\n        {(\\lambda x)^{k/2}}}\n        I_{k/2-1}(\\lambda x)\n\\]\nwhere $k$ is the degrees of freedom; $\\lambda$ is the distance parameter;\n$I_M(a)$ is a modified cylindrical Bessel function of the first kind.\n\n\\subsubsection*{CDF}\n\\[\n    D(x) = 1-Q_{\\frac {k}{2}}\\left(\\lambda ,x\\right)\n\\]\nwhere $Q_M(a,b)$ is Marcum Q-function.\n\n\\subsubsection*{Mean}\n\\[\n    \\text{To be implemented.}\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    \\text{To be implemented.}\n\\]\n\nReference:\n\\href{https://en.wikipedia.org/wiki/Noncentral_chi_distribution}{Wikipedia}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Non-central Chi Squared distribution}\n\n\\subsubsection*{PDF}\n\\[\n    P(x) = {\\frac {1}{2}}e^{-(x+\\lambda )/2}\\left({\\frac {x}{\\lambda }}\\right)\n    ^{k/4-1/2}I_{k/2-1}({\\sqrt {\\lambda x}})\n\\]\nwhere $k$ is the degrees of freedom; $\\lambda$ is the distance parameter;\n\n\\subsubsection*{CDF}\n\\[\n    D(x) = 1-Q_{\\frac {k}{2}}\\left({\\sqrt {\\lambda }},{\\sqrt {x}}\\right)\n\\]\nwhere $Q_M(a,b)$ is Marcum Q-function.\n\n\\subsubsection*{Mean}\n\\[\n    k + \\lambda\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    2(k+2\\lambda)\n\\]\n\n\\subsubsection*{Skewness}\n\\[\n    \\frac{2^{3/2}(k+3\\lambda)}{(k+2\\lambda)^{3/2}}\n\\]\n\nReference:\n\\href{https://en.wikipedia.org/wiki/Noncentral_chi-squared_distribution}{Wikipedia}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Normal distribution}\n\n\\subsubsection*{PDF}\n\\[\n    P(x) = {\\frac{1}{\\sigma{\\sqrt {2\\pi }}}}\n        \\exp{(-{\\frac {1}{2}} \n        \\left({\\frac {x-\\mu }{\\sigma }}\\right)^{2})}\n\\]\nwhere $\\mu$ is the expection of the distribution; \n$\\sigma$ is the standard deviation.\n\n\\subsubsection*{CDF}\n\\[\n    D(x) = {\\frac{1}{2}} \\left[1+\\operatorname {erf} \n        \\left({\\frac {x-\\mu }{\\sigma {\\sqrt {2}}}}\\right)\\right]\n\\]\nwhere $erf(a)$ is the error function.\n\n\\subsubsection*{Mean}\n\\[\n    \\mu\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    \\sigma^2\n\\]\n\n\\subsubsection*{Skewness}\n\\[\n    0\n\\]\n\nReference:\n\\href{https://en.wikipedia.org/wiki/Normal_distribution}{Wikipedia}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Rayleigh distribution}\n\n\\subsubsection*{PDF}\n\\[\n    P(x) = {\\frac {x}{\\sigma ^{2}}}e^{-x^{2}/\\left(2\\sigma ^{2}\\right)}\n\\]\n\n\\subsubsection*{CDF}\n\\[\n    D(x) = 1 - e^{-x^{2}/\\left(2\\sigma ^{2}\\right)}\n\\]\n\n\\subsubsection*{Mean}\n\\[\n    \\sigma \\sqrt{\\frac{\\pi}{2}}\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    {\\frac {4-\\pi }{2}}\\sigma ^{2}\n\\]\n\n\\subsubsection*{Skewness}\n\\[\n    {\\frac {2{\\sqrt {\\pi }}(\\pi -3)}{(4-\\pi )^{3/2}}}\n\\]\n\nReference:\n\\href{https://en.wikipedia.org/wiki/Rayleigh_distribution}{Wikipedia}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Standard Normal distribution}\n\n\\subsubsection*{PDF}\n\\[\n    P(x) = \\frac{1}{\\sqrt {2\\pi }}\n        \\exp{(-{\\frac {1}{2}} x^{2})}\n\\]\nwhere $\\mu$ is the expection of the distribution; \n$\\sigma$ is the standard deviation.\n\n\\subsubsection*{CDF}\n\\[\n    D(x) = {\\frac{1}{2}} \\left[1+\\operatorname {erf} \n        \\left( {\\frac{x}{{\\sqrt {2}}}} \\right) \\right]\n\\]\nwhere $\\operatorname {erf}(a)$ is the error function.\n\n\\subsubsection*{Mean}\n\\[\n    0\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    1\n\\]\n\n\\subsubsection*{Skewness}\n\\[\n    0\n\\]\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Uniform distribution (Continuous)}\n\n\\subsubsection*{PDF}\n\\[\n    P(x) = \\begin{cases}\n        {\\frac {1}{b-a}}&{\\text{for }}x\\in [a,b]\\\\\n        0&{\\text{otherwise}}\n    \\end{cases}\n\\]\nwhere $a$ is the lower bound; $b$ is the upper bound.\n\n\\subsubsection*{CDF}\n\\[\n    D(x) = \\begin{cases}\n        0&{\\text{for }}x<a\\\\\n        {\\frac {x-a}{b-a}}&{\\text{for }}x\\in [a,b]\\\\\n        1&{\\text{for }}x>b\n    \\end{cases}\n\\]\n\n\\subsubsection*{Mean}\n\\[\n    \\frac{1}{2}(a+b)\n\\]\n\n\\subsubsection*{Variance}\n\\[\n    \\frac{1}{12}(b-a)^2\n\\]\n\n\\subsubsection*{Skewness}\n\\[\n    0\n\\]\n\nReference:\n\\href{https://en.wikipedia.org/wiki/Continuous_uniform_distribution}{Wikipedia}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Mixture distribution}\n\nA \\textbf{mixture distribution} is the probability distribution of a random variable \nthat is derived from a collection of other random varibales. \nThe probability density function (and the cumulative distribution function) \ncan be expressed as the a convex combination of other distribution functions.\nThe individual distributions that are combined to form the mixture distribution are called \nthe \\textbf{mixture components}. The weights associated with each component are called the \\textbf{mixture weights}.\n(\\href{https://www.overleaf.com/learn/latex/Bold,_italics_and_underlining}{Wikipedia})\n\n\n\\subsubsection*{PDF}\nGiven the mixture components' PDF ${P_1(x), ..., P_n(x)}$ and weights ${w_1,...,w_n}$,\nthe mixture's PDF is a convex combination:\n\\[\n    P_\\text{mixture}(x) = \\sum^n_{i=1} w_i P_i(x)\n\\]\n\n\\subsubsection*{CDF}\nGiven the mixture components' CDF ${D_1(x), ..., D_n(x)}$ and weights ${w_1,...,w_n}$,\nthe mixture's CDF is a convex combination:\n\\[\n    D_\\text{mixture}(x) = \\sum^n_{i=1} w_i D_i(x)\n\\]\n\n\nThe moments of a mixture distribution are not as mathematically simple as PDF or CDF. \nTo acquire the mathematically expressions for Mean, Variance, and Skewness, we need to \nclarify the three types of moments:\n\\begin{enumerate}\n    \\item $k^\\text{th}$ non-central moment: $\\mu^{(k)} = \\mathbb{E}[x^k]$\n    \\item $k^\\text{th}$ central moment: $\\mu^{(k)}_c = \\mathbb{E}[(x-\\mu^{(1)})^k]$\n    \\item $k^\\text{th}$ standardized moment: $\\mu^{(k)}_s = \\mathbb{E}[(\\frac{x-\\mu^{(1)}}{\\sigma})^k]$\n\\end{enumerate}\n, where $^{(k)}$ denotes the $k^\\text{th}$ moment.\n\n\n\n\\subsubsection*{Mean}\nMean is also known as the first non-central moment. \nThe $k^\\text{th}$ non-central moment of a random variable can be rewritten in terms of integrals as:\n\\begin{align}\n    \\mu^{(k)} &= \\mathbb{E}[x^k] \\\\\n              &= \\int_{-\\infty}^{\\infty} x^k f(x) dx \\\\\n              &= \\int_{-\\infty}^{\\infty} x^k \\sum^n_{i=1} w_i f_i(x) dx \\\\\n              &= \\sum^n_{i=1} w_i \\int_{-\\infty}^{\\infty} x^k f_i(x) dx \\\\\n              &= \\sum^n_{i=1} w_i \\mathbb{E}_{f_i}[x^k] \\\\\n              &= \\sum^n_{i=1} w_i \\mu_i^{(k)}\n\\end{align}\n, where $\\mu_i^{(k)}$ is the $k^\\text{th}$ non-central moment of distribution function $f_i$.\n\nGiven the mixture components' mean ${\\mu_1, ..., \\mu_n}$ and weights ${w_1,...,w_n}$,\nit is easy to see the mixture's mean is just a convex combination:\n\\[\n    \\mu^{(1)}_\\text{mixture} = \\sum^n_{i=1} w_i \\mu^{(1)}_i\n\\]\n\n\n\n\\subsubsection*{Variance}\nVariance is also known as the second central moment. The $k^\\text{th}$ central moment \nfollows a deriavation similar to the non-central moment:\n\\begin{align}\n    \\sigma^2 \\coloneqq \\mu^{(2)}_c &= \\mathbb{E}[(x-\\mu^{(1)})^{2}] \\\\\n        &= \\mathbb{E}[x^2] - (\\mathbb{E}[x])^2 \\\\\n        &= \\mu^{(2)} - (\\mu^{(1)})^2 \\\\\n        &= \\sum^n_{i=1} w_i \\mu^{(2)}_i - \\left(\\sum^n_{i=1} w_i \\mu^{(1)}_i \\right)^2  \\\\\n        &= \\sum^n_{i=1} w_i \\left( \\sigma^2_i + (\\mu^{(1)}_i)^2 \\right) - \\left(\\sum^n_{i=1} w_i \\mu^{(1)}_i \\right)^2  \\\\\n        &= \\sum^n_{i=1} w_i \\sigma^2_i + \\sum^n_{i=1} w_i (\\mu^{(1)}_i)^2 - \\left(\\sum^n_{i=1} w_i \\mu^{(1)}_i \\right)^2 \n\\end{align}\n, where $\\sigma_i^2$ is $i^{th}$ component's variance, and $\\mu^{(1)}_i$ is $i^{th}$ component's mean.\n\nWith simplified the notations, we get a familiar expression for the mixture's variance.\n\\[\n    \\sigma^2_\\text{mixture} = \\sum^n_{i=1} w_i (\\sigma^2_i+\\mu^2_i) - \\mu^2_\\text{mixture}\n\\]\n\n\n\n\\subsubsection*{Skewness}\nSkewness is also known as the third standardized moment. \n\\begin{align}\n    \\mu^{(3)}_s &= \\mathbb{E}[ \\left( \\frac{x-\\mu^{(1)}}{\\sigma} \\right) ^3] \\\\\n                &= \\frac{\\mathbb{E}[x^3] - 3 \\mu^{(1)} \\mathbb{E}[x^2] + 3 (\\mu^{(1)})^2 \\mathbb{E}[x] - (\\mu^{(1)})^3}{\\sigma^3} \\\\\n                &= \\frac{\\mathbb{E}[x^3] - 3 \\mu^{(1)} \\sigma^2 - (\\mu^{(1)})^3}{\\sigma^3} \n\\end{align}\n\nTo rewrite it in terms of the skewness of each component $(\\mu^{(3)}_s)_i$, let's start by rewriting the third non-central moment:\n\\[\n    \\mathbb{E}[x^3] = \\sum^n_{i=1} w_i \\mu^{(3)}_i = \\sum^n_{i=1} w_i \\left( \\sigma^3_i (\\mu^{(3)}_s)_i + 3 \\mu^{(1)}_i \\sigma^2_i + (\\mu^{(1)}_i)^3 \\right)\n\\]\n\nNow the Skewness of the mixture can be rewritten to:\n\\[\n    \\mu^{(3)}_s = \\frac{ \\sum^n_{i=1} w_i \\left( \\sigma^3_i (\\mu^{(3)}_s)_i + 3 \\mu^{(1)}_i \\sigma^2_i + (\\mu^{(1)}_i)^3 \\right)  - 3 \\mu^{(1)} \\sigma^2 - (\\mu^{(1)})^3 }{\\sigma^3}\n\\]\nwhere $\\mu^{(1)}$ is the mean of the mixture, and $\\sigma^2$ is the variance of the mixture.", "meta": {"hexsha": "e52b1fdcab44f1e00e38b4a8c70d50928acb562f", "size": 14042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/Documentation/chapter_distributions.tex", "max_stars_repo_name": "AnselGitAccount/StatAnaly", "max_stars_repo_head_hexsha": "93cbffd54d212056e023fce90b0386825af49a88", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/Documentation/chapter_distributions.tex", "max_issues_repo_name": "AnselGitAccount/StatAnaly", "max_issues_repo_head_hexsha": "93cbffd54d212056e023fce90b0386825af49a88", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/Documentation/chapter_distributions.tex", "max_forks_repo_name": "AnselGitAccount/StatAnaly", "max_forks_repo_head_hexsha": "93cbffd54d212056e023fce90b0386825af49a88", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7218309859, "max_line_length": 180, "alphanum_fraction": 0.571855861, "num_tokens": 4628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.8872045832787205, "lm_q1q2_score": 0.8014067579270968}}
{"text": "% !TEX encoding = UTF-8 Unicode\n% !TEX spellcheck = en_US\n% !TEX root = ../../../ICMA2020.tex\n\n\\subsection{Parameter Estimation}\n\\label{subsec:ParameterEstimation}\n\nThe base parameter form of the dynamics in (\\ref{eq:model_regressor}) is used to estimate\nthe parameter vector $\\boldsymbol{\\theta} \\in \\mathbb{R}^{35}$.\n%\nUsing a sufficient number of samples in the estimation process leads to an over-determined system of linear equations:\n\n\\begin{equation} \\label{eq:ParameterEstimation_problem}\n\\begin{aligned}\n    \\boldsymbol{y} &= \\boldsymbol{C} \\boldsymbol{\\theta} + \\boldsymbol{\\epsilon}, \\\\\n    \\begin{pmatrix}\n        \\boldsymbol{\\tau}(t_1) \\\\\n        \\vdots \\\\\n        \\boldsymbol{\\tau}(t_N) \\\\\n    \\end{pmatrix} &= \n    \\begin{pmatrix}\n        \\boldsymbol{X}(t_1) \\\\\n        \\vdots \\\\\n        \\boldsymbol{X}(t_N) \\\\\n    \\end{pmatrix} \\boldsymbol{\\theta} +\n    \\begin{pmatrix}\n        \\boldsymbol{e}(t_1) \\\\\n        \\vdots \\\\\n        \\boldsymbol{e}(t_N) \\\\\n    \\end{pmatrix}.\n\\end{aligned}\n\\end{equation}\n\nHere $\\boldsymbol{y}$ contains the $N$ samples of the torque vector $\\boldsymbol{\\tau}$, $\\boldsymbol{C}$ denotes the design matrix and $\\boldsymbol{\\epsilon}$ is the vector of errors.\n\nEquation \\eqref{eq:ParameterEstimation_problem} can be solved for $\\boldsymbol{\\theta}$ using a least squares estimator. The weighted least squares (WLS)  \\cite{Gautier.2013,M.Gautier.1995,V.Bargsten.2013,Swevers.1997} is used to account for different levels of noise in the measurements: \n\\begin{equation} \\label{eq:ParameterEstimation_WLS}\n    \\begin{aligned}\n\t    \\hat{\\boldsymbol{\\theta}} &= \\arg \\min_{{\\boldsymbol{\\theta}}} (\\boldsymbol{y} - \\boldsymbol{C} \\boldsymbol{\\theta})^\\mathrm{T} \\boldsymbol{W} (\\boldsymbol{y} - \\boldsymbol{C} \\boldsymbol{\\theta}) \\\\\n\t    &= (\\boldsymbol{C}^\\mathrm{T} \\boldsymbol{W} \\boldsymbol{C})^{-1} \\boldsymbol{C}^\\mathrm{T} \\boldsymbol{W} \\boldsymbol{y}.\n\t\\end{aligned}\n\\end{equation}\nMatrix $\\boldsymbol{W}$ contains the weights of the individual samples, see also Sec.\\,\\ref{subsec:SignalProcessing}.\n", "meta": {"hexsha": "cf2bc0c64e59cf90bd3fb0dbfc473efdb1c820f0", "size": 2044, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/Chapters/Theoretical_Background/Parameter_Estimation/Parameter_Estimation.tex", "max_stars_repo_name": "SchapplM/robotics-paper_icma2020", "max_stars_repo_head_hexsha": "f81c6599ec7a9341e6a467a4ff9b31091aa50e75", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "paper/Chapters/Theoretical_Background/Parameter_Estimation/Parameter_Estimation.tex", "max_issues_repo_name": "SchapplM/robotics-paper_icma2020", "max_issues_repo_head_hexsha": "f81c6599ec7a9341e6a467a4ff9b31091aa50e75", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/Chapters/Theoretical_Background/Parameter_Estimation/Parameter_Estimation.tex", "max_forks_repo_name": "SchapplM/robotics-paper_icma2020", "max_forks_repo_head_hexsha": "f81c6599ec7a9341e6a467a4ff9b31091aa50e75", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.4545454545, "max_line_length": 289, "alphanum_fraction": 0.6839530333, "num_tokens": 619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542840900507, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.8013576197930219}}
{"text": "\\section*{Ex.2.5}\n\\subsection*{what is the probability that there is a key $y \\in S$ such that $h(y) = h(x)$ and $s(y) = s(x)$}\nThe set $(h(x)=h(y))\\cap(s(x)=s(y))$ is the set where the hash function and the signature function gives the same value for two distinct keys $x,y$. Hence the probability we want to determine is the probability for that set over all possible $y$ values in $S$. So we look at\n\\begin{align*}\n\\sum_{y\\in S}P[(h(x)=h(y))\\cap(s(x)=s(y))] \n             &= \\sum_{y\\in S}P(h(x)=h(y))P(s(x)=s(y))\\\\\n             &= nP(h(x)=h(y))P(s(x)=s(y))\\\\\n             &\\leq n\\frac{1}{n}\\frac{1}{n^3}\\\\\n             &= \\frac{1}{n^3}\n\\end{align*}\nThe first equality holds because the hash functions are independent. The next equality uses that $\\abs{S}=n$. The inequality uses that the $h$ and $s$ are universal hash functions. So the probability for the hash function and for the signature function to have a collision for two distinct keys are less than $1/n^3$", "meta": {"hexsha": "6153ab2b328f2c35f25608d8e74099980fc53f87", "size": 968, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge3/Ex.2.5.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge3/Ex.2.5.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge3/Ex.2.5.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 88.0, "max_line_length": 316, "alphanum_fraction": 0.6404958678, "num_tokens": 303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.8013205962573359}}
{"text": "\\section{Probability modeling}\nFind $h(x)$ that min. pred. error:\\\\\n$\\highlight*{R(h) = \\mathbb{E}_{x,y}[\\ell(y;h(x))]} = \\int\\!P(x,y)\\,\\ell(y;h) \\diff x \\!\\diff y$\n\n% ===\n\\emph{Bayes optimal predictor\n\\normalfont\\sffamily $\\normalcolor\\to \\hat y = h^\\ast(x)$}\n\n$\\deriv{\\ell(\\hat y)}{\\hat y} = 0 \\to \\highlight*{\\hat y = \\mathbb{E} [Y\\vert X\\!\\!=\\!x] = \\int\\!y\\!\\cdot\\!\\hat P(y\\vert X\\!\\!=\\!x) \\diff y}$\n\n%\\subsection*{For least squares regression}\n%Best $h$: $h^*(x) = \\mathbb{E}[Y|X=x]$ \\\\\n%Pred.: $\\hat{y} = \\hat{\\mathbb{E}}[Y|X=\\hat{x}] = \\int \\hat{P}(y|X=\\hat{x}) y \\partial y$\n\n% ===\n\\emph{MLE \\enskip $-\\log P(y\\vert x,w)$}\n\n{\\small $\\theta^* \\!=\\! \\arg\\!\\max\\limits_\\theta \\hat{P}(y_{1:n}\\vert x_{1:n},\\theta) \\overset{\\textrm{iid}}{=} \\highlight*{\\arg\\!\\min\\limits_\\theta \\!-\\!\\sum_{i=1}^n \\ln P(y_i\\vert x_i,\\theta)} $}\n\ne.g. lin. Gauss: $y_i = w^\\top \\!x_i + \\varepsilon_i$, \\enskip $\\varepsilon_i \\!\\sim\\! \\mathcal{N}(0, \\sigma^2)$\\\\\ni.e. $y_i \\!\\sim\\! \\mathcal{N}(w^\\top \\!x_i, \\sigma^2)$\n$\\xrightarrow{\\text{MLE and}\\,\\log\\;}$ LS regression\n\n% ===\n\\emph{Bias/Variance/Noise}\n\nPrediction error = $\\normalcolor \\textrm{Bias}^2 + \\textrm{Variance} + \\textrm{Noise}$\\\\\n- Noise: risk incurred by the optimal model,\\\\\n\\phantom{- Noise:} $P(y\\vert x)$ loss/likelihood fct.\\\\\n- Variance: est. model from limited data\\\\\n- Bias: incurred by regularizer\\\\\nhigher bias implies much lower variance\n\n% ===\n\\emph{MAP \\enskip $-\\log P(w)$}\n\n\\textbf{Prior:} bias on param's, e.g. $w_i \\!\\sim\\! \\mathcal{N}(0, \\beta^2)$\\\\\n$\\xrightarrow{\\text{\\!Bay.}}$ $P(w|x_{1:n},y_{1:n}) = \\frac{P(w|x) P(y|x,w)}{P(y|x)} = \\frac{P(w) P(y|x,w)}{P(y|x)}$\n\n% ===\n\\emph{Logistic regression (Classification)}\n\n\\textbf{Link fct.:} $\\sigma(w^\\top x) = \\frac{1}{1+\\exp(-w^\\top x)}$ \\enskip \\textbf{(Sigmoid)}\\\\\n$P(y\\vert x,w) = Ber (y; \\sigma(w^\\top\\!x)) = \\sigma(yw^\\top x)$\n\n\\textbf{MLE:}\n$\\hat w = \\arg\\!\\min\\limits_w \\sum_i \\log(1+\\exp(-y_iw^\\top\\!x_i))$\\vspace{-3pt}\\\\\n\\phantom{\\textbf{MLE:}} with $\\hat R(w) = \\sum_{i=1}^n \\ell\\ped{logistic} (w; x_i, y_i)$\n\n\\textbf{Grad.:} $\\nabla\\!_w \\ell(w) = P(Y\\!\\!\\neq\\!y \\vert x) \\; (-yx)$\n\\hfill {\\color{gray}\\small $\\to (Y\\!\\!=\\!-\\!y)$}\n\n\\textbf{MAP:} Gauss. prior $\\to \\norm{w}_2^2$, \\enskip Lap. $\\to \\norm{w}_1^1$\n", "meta": {"hexsha": "6069b362ac335c5fec38f371e81d41906000f45b", "size": 2239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/IML19/sections/ProbabilityModeling.tex", "max_stars_repo_name": "tstreule/eth-cheat-sheets", "max_stars_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-26T23:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T23:11:57.000Z", "max_issues_repo_path": "src/IML19/sections/ProbabilityModeling.tex", "max_issues_repo_name": "tstreule/eth-cheat-sheets", "max_issues_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/IML19/sections/ProbabilityModeling.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.462962963, "max_line_length": 197, "alphanum_fraction": 0.5828494864, "num_tokens": 965, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.8013205863292534}}
{"text": "% -*- root: Main.tex -*-\n\\section{Notes}\n\\textbullet Proof that eigenvectors of symmetric matrix are orthogonal: $\\lambda \\langle x,y \\rangle = \\langle \\lambda x,y \\rangle = \\langle Ax,y \\rangle = \\langle x,A^\\top y \\rangle = \\langle x,A y \\rangle = \\langle x,\\mu y \\rangle = \\mu \\langle x,y \\rangle \\Rightarrow (\\lambda-\\mu)\\langle x,y\\rangle=0$ where $\\lambda \\neq \\mu$.\\\\\n\\textbullet K-means vs GMM: k-means has hard assignments, cheaper to train (less params). GMM has soft assginments, more expressive because cluster is described by a MVN i.e shape is defined by an arbitrary covariance martix and not restricted to spherical clusters. GMM is generative model i.e we can do outlier detection, generate data points, uncertainty estimation. \\\\\n\\textbullet SVD and PCA: if $A=UDV^\\top$. Columns of $U$ are eigenvectors of $AA^\\top$. Columns of $V$ are eigenvectors of $A^\\top A$. Eigenvalues of $A^\\top A$ and $AA^\\top$ are singular values$^2$ of $A$. \\\\\n\\textbullet orthogonal Haar Basis for $4$-dim signals: \\\\\n$U = \\frac{1}{2}\n\\begin{bmatrix}\n    1 & 1 & \\sqrt{2} & 0 \\\\\n    1 & 1 & -\\sqrt{2} & 0 \\\\\n    1 & -1 & 0 & \\sqrt{2} \\\\\n    1 & -1 & 0 & -\\sqrt{2}\n\\end{bmatrix}\n$", "meta": {"hexsha": "f8e4cda6e0827dd5c3eb4361d3e6c2810357f7aa", "size": 1177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes.tex", "max_stars_repo_name": "florianmorath/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-19T15:10:37.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-19T15:10:37.000Z", "max_issues_repo_path": "notes.tex", "max_issues_repo_name": "florianmorath/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes.tex", "max_forks_repo_name": "florianmorath/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "4a2c4942dd9ddec30c3eed2097ee935a9caf6499", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.0714285714, "max_line_length": 372, "alphanum_fraction": 0.6754460493, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341999997378, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.8012959054660073}}
{"text": "\n\\subsection{Laplacian matrix}\n\nThe Laplacian matrix \\(L\\) is formed using the degree matrix \\(D\\) and the adjacency matrix \\(A\\). \\(L=D-A\\).\n\n", "meta": {"hexsha": "6aa18e9f93afccd1fc5f8557e2ceda8653625387", "size": 143, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/graph/04-04-matrixLaplacian.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/graph/04-04-matrixLaplacian.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/graph/04-04-matrixLaplacian.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.8333333333, "max_line_length": 109, "alphanum_fraction": 0.6853146853, "num_tokens": 41, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104933824754, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.8010951606917806}}
{"text": "\\lab{Algorithm}{Pseudorandom Number Generators}{Pseudorandom Number Generators}\n\\label{lab:PRNG}\n\n\\objective{Learn about the strengths and weaknesses of a few a pseudorandom number generators}\n\n\\section*{Random Numbers}\nLotteries, most board games, and statistics need random numbers.\nIn real life, we roll dice, take balls out of a bag, or spin a wheel.\nComputers are, by nature, deterministic, meaning that they do exactly what they are told.\nBecause of this, random number generation on a computer can be difficult.\nWe can have a device measure a random process and use the data to generate random numbers, \nBut such sampling is often too slow and too expensive for practical use.\nPseudorandom number generators (PRNGs) are a common solution to this problem.\nThe numbers are not truly random, but they are based on a complex formula that makes them look ``random.\"\nFor convenient use, these generateors must also run quickly.\nThe goal is to have something that is fast and looks random.\n\nThere are many different algorithms for developing pseudorandom numbers.\nRobert R. Coveyou titled an article ``The generation of random numbers is too important to be left to chance.\"\nThere has been much study about different PRNGs.\nThis lab will cover two of them: Linear Congruiental Generators and The Mersenne Twister.\n\n\\section*{Linear Congruential Genterators}\nLinear Congruential Generators (LCG) are one of the oldest ways of generating random numbers.\nThe Generator is defined by the recurrence relation:\n$X_{n+1}=(a*X_n + c)$ mod $m$ where\n\n\\begin{itemize}\n\\item $X$ is a sequence of pseudorandom values, and\n\\item $m$, $0<m$ is the modulus\n\\item $a$, $0<a<m$ is the multiplier\n\\item $c$, $0\\leq c<m$ is the increment\n\\item $X_0$, $0\\leq X_0 <m$ is the seed\n\\end{itemize}\n\neach of these are integer constants.\n\n\\begin{problem}\nWrite a LCG that produces an array of pseudorandom numbers between $0.0$ and $1.0$.\nLet the arguments be size of the array and let a, c, mod, and seed be optional arguments.\nI recommend $a=1103515245$, $c=12345$, $m=2^{31}-1$, and $seed=4329$ as the default values.\n\\end{problem}\n\n\\begin{problem}\nWrite a LCG that produces an array of pseudorandom numbers of integers between two input arguments.\nDo it by calling your algorithm from problem one and multiplying it by the values and casting the array as an int using the .astype() function.\nLet the arguments be size of array and the two integers.\nLet a, c, mod, and seed continue to be optional arguments.\n\\end{problem}\n\nOne easy way to ``see\" if your generator is random is to look at a bitmap of the output.\nIn python, use the plt.imshow() function to see a bitmap of the array produced by your LCG.\nResize your output to be $512 \\times 512$.\n\n\\begin{figure}\n\\includegraphics[width=.4\\textwidth]{PRNG1.png}\n\\caption{\nThe bitmap with $a=3$, $c=2$, $m=2^{16}$.\nThere is a clear pattern in the random numbers.}\n\\end{figure}\n\n\\begin{problem}\nFor what values of $a$, $c$, and $m$ does your LCG have a visible pattern.\n\\end{problem}\n\nThis method is not rigorous, but there are several other ways to test the randomness of your output.\n\nThe length over which your random number generator repeats is called the period.\nThe period is at most m, but it may be shorter based on the values of a and c.\n \n\\begin{comment}\nAccording to the Hull-Dobell Theorem (TO DO: find a source), a LCG will have a full period if and only if, \n1. $c$ and $m$ are relatively prime,\n2. $a-1$ is divisible by all prime factors of $m$,\n3. $a-1$ is a multiple of 4 if $m$ is a multiple of 4\n\n\\begin{problem}\nTest values of $a$,$c$, and $m$ that fit these requirements. \n\\end{problem}\n\\end{comment}\n\nThis algorithm is used as the default random number generator in Java, and C++ and is still used in a wide variety of situations.\n\n\\section*{Mersenne Twister}\n\\begin{comment}\n(TO DO: decide how much of  this we want to keep) All numbers can be represented in bits as a base two number.\nComputers are optimized to work with numbers in that manner.\nThe operators XOR, OR, and AND work on the bit representation of two numbers.\n\nAND - if both numbers have a 1 in the ith place then the ith place is 1.\nOtherwise the ith place is 0.\n\nOR - if one or both numbers have a 1 in the ith place then the ith place is 1.\nOtherwise the ith place is 0.\n\nXOR - if only one of the two numbers has a 1 in the ith place then the ith place is 1.\nIf both or neither of the numbers has a 1 in the ith place, the ith place is 0.\n\nIn addition you can shift the bitwise number over a number of values.\nFor example, shifting 10100 to the right by one yields 1010 and shifting it to the left by one yields 101000.\nThis is really just division and multiplication by 2.\nThis can be done by $\\ll$ and $\\gg$ in python. \n\\end{comment}\n\nThe Mersenne twister PRNG does a series of bitwise operations to generate random numbers.\nThe Random class in python uses the Mersenne twister algorithm. \n\n\\begin{problem}\nLook at the bitmap of output of \\li{np.random.rand(512,512)}.\nCan you see any patterns?\n\\end{problem}\n\n\\section*{Randomness Tests}\nThere have been statistical tests devised for measuring the quality of a random number generator. One is these is the overlapping permutations test. Analyze sequences of five consecutive random numbers. The 120 possible orderings should occur with statistically equal probability.\n\n\\begin{problem}\nUse the overlappng permutations test to see how random python's random number generator is compared to the LCG you wrote in problem 1.\n\\end{problem}\n\n\\section*{Blackjack}\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{Blackjack_game_1.jpg}\n\\caption{Initial Round of a BlackJack game.}\n\\end{figure}\n\nBlack Jack is a card game that involves the use of randomness.\nThe game is simple.\nThe dealer deals the player and himself each two cards.\nHe flips over his first card so that the player can see it.\nThe player has to choose to take another card (\"hit\") or not (\"stand\").\nIf the player hits he gets another card and again has the choice to hit or stand.\n\nThe goal is to get your hand to be at or as close to 21 without going over.\nFace cards are worth 10 points.\nAces can count either as 11 or 1.\nThe value of all other cards are equal to number on the card.\n\nOnce the player has decided to stand the dealer flips over his second card and deals himself cards until his hand value is 17 or greater. \n\nIf the player value goes above 21 he automatically loses.\nIf his value is 21 and below and dealer has above 21 then the player wins.\nIf they both have 21 or under than the player with the hand of highest value wins.\nIf both hands have the same value, the game is a tie.\n\n\\section*{Shuffling Algorithms}\nOne use of Pseudorandom Number Generators (PRNGs) is to shuffle cards.\nThe main goal of these algorithms is that the card order be random--so that no single player has an advantage based on order.\nOften, as strange as it may seem, online gambling sites will post their shuffling algorithms online.\nThe only things they do not post are their seed values.\nOften the time in milliseconds from midnight is used as the seed value.\n\nJohn von Neumann said ``Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin.\"\nAs seen in the last lab, weak PRNGs are periodic and are predictable once a few outputs are known.\nThis lab will have you break blackjack based on a weak PRNG.\n\n\\section*{Cracking Blackjack}\nFor these next problems you will need three files that are provided with this lab: Black.py, BlackEasy.py, and bjHelp.py.\nBlack.py and BlackEasy.py are are programs that run games of Blackjack that use a Linear Congruentail Generator (LCG) to shuffle the cards.\nThey generate 52 random numbers and then the argsort of those numbers is the order of the cards.\nThe parameters for BlackEasy.py are a$=2521$, c$=13$, mod$=2^{16}$.\nFor Black.py they are a$=25214903917$, c$=11$, mod$=2^{48}$.\nIn order to play them type \\li{python <<filename>> <<numberofgames>>} in your command line.\nThey are both seeded initially by the time.\n\nbjHelp.py contains two functions that will help you \"predict\" the cards:\nSuffleHack(n,a,c,mod,seed) gives the first $n$ card shuffles given the parameters for a LCG.\nThe shuffles are represented by numbers.\nHacker(Stats,['card','card','card']) Stats is the output of SuffleHack and takes a list of 3 cards (see below).\nIt prints all shuffles as a list of cards in Stats that have the same first three cards as the inputted list.\n\nThe trick to being able to \"predict\" the cards is to find the initial seed value.\n\nCards- A, 2-10, J, Q, or K combined with heart, diamond, club, or spade in single quotes.\nExamples: '6diamond', 'Kclub'.\n\n\\begin{warn}\nBoth BlackEasy.py and Black.py use functions that are incompatible with ipython. They need to run \\li{python Black.py} in command line.\n\\end{warn}\n\n\n\n\\begin{problem}\nPlay 10 games of BlackEasy.py and by the 5th game be able to predict the cards.\nYou can write your own functions or use the ones in bjHelp.py.\nYou will want to open two command prompts, one to play the game and one to predict the cards. \n\\end{problem}\n\nNot too hard.\nThat is because there is only $2^{16}$ seed values.\nThis next one you will have to look at more hands until you can find out the initial seed value.\n\n\\begin{problem}\nPlay 20 games of Black.py and by the 15th game be able to predict the cards.\n\\end{problem}\n", "meta": {"hexsha": "e5f5a1a66f63f2ea3c811ab1d6605ed13c7cfee2", "size": 9366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/PRNG/PRNG.tex", "max_stars_repo_name": "lcbendall/numerical_computing", "max_stars_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/PRNG/PRNG.tex", "max_issues_repo_name": "lcbendall/numerical_computing", "max_issues_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/PRNG/PRNG.tex", "max_forks_repo_name": "lcbendall/numerical_computing", "max_forks_repo_head_hexsha": "565cde92525ea44c55abe933c6419c1543f9800b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.0307692308, "max_line_length": 280, "alphanum_fraction": 0.765214606, "num_tokens": 2369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.9111797124237604, "lm_q1q2_score": 0.8010606930272396}}
{"text": "\\section{Deterministic finite automata}\n \nTransition diagrams are useful graphical representations of instances\nof the mathematical concept of \\emph{deterministic finite automaton}\n(\\emph{DFA}). Formally, a DFA \\(\\mathcal{D}\\) is a 5-tuple\n\\(\\mathcal{D} = (Q, \\Sigma, \\delta, q_0, F)\\) where\n\\begin{enumerate*}\n\n  \\item a finite set of \\emph{states}, often noted \\(Q\\);\n\n  \\item an \\emph{initial state} \\(q_0 \\in Q\\);\n\n  \\item a set of \\emph{final (\\emph{or} accepting)\n  states} \\(F \\subseteq Q\\);\n\n  \\item a finite set of \\emph{input symbols}, often noted \\(\\Sigma\\);\n\n  \\item a \\emph{transition function} \\(\\delta\\) that takes a state and\n    an input symbol and returns a state: if~\\(q\\) is a state with an\n    edge labelled \\(a\\), the edge leads to the state \\(\\delta(q, a)\\).\n\n\\end{enumerate*}\n\n\\subsection*{Recognised words}\n\nIndependently of the interpretation of the states, we can define how a\ngiven word is accepted (or recognised) or rejected by a given DFA. For\nexample, the word \\(a_1 a_2 \\cdots a_n\\), with \\(a_i \\in \\Sigma\\), is\nrecognised by the DFA \\(\\mathcal{D} = (Q, \\Sigma, \\delta, q_0, F)\\)\nif, for all \\(0 \\leqslant i \\leqslant n-1\\), there is a sequence of\nstates \\(q_i \\in Q\\) such that \\(\\delta (q_i, a_{i+1}) = q_{i+1}\\) and\n\\(q_n \\in F\\). The language recognised by \\(\\mathcal{D}\\), noted\n\\(L(\\mathcal{D})\\) is the set of words recognised\nby~\\(\\mathcal{D}\\). For example, consider the DFA in\n\\fig~\\vref{fig:trie_then}.\n\\begin{figure}[b]\n\\centering\n\\includegraphics[bb=48 644 218 730,scale=0.93]{trie_then}\n\\caption{A trie recognising \\textsf{they}, \\textsf{then},\n  \\textsf{this} and \\textsf{thus} \\label{fig:trie_then}}\n\\end{figure}\nThe word \\textsf{then} is recognised because there is a sequence of\nstates \\((q_0, q_1, q_2, q_4, q_5)\\) connected by edges which\nsatisfies \\(\\delta (q_0, \\textsf{t}) = q_1, \\delta (q_1, \\textsf{h}) =\nq_2, \\delta (q_2, \\textsf{e}) = q_4 \\,\\text{and}\\, \\delta (q_4,\n\\textsf{n}) = q_5\\), with \\(q_5 \\in F\\), that is, \\(q_5\\)~is a final\nstate.\n\n\\subsection*{Recognised language}\n\nIt is easy to define formally \\(L(\\mathcal{D})\\). Let \\(\\mathcal{D} =\n(Q, \\Sigma, \\delta, q_0, F)\\). First, let us extend~\\(\\delta\\) to\nwords and let us call this extension~\\(\\hat{\\delta}\\):\n\\begin{itemize*}\n\n  \\item for all state \\(q \\in Q\\), let \\(\\hat{\\delta} (q, \\varepsilon)\n    = q\\), where \\(\\varepsilon\\) is the empty string;\n\n  \\item for all state \\(q \\in Q\\), all word \\(w \\in \\Sigma^{*}\\), all\n    input \\(a \\in \\Sigma\\), let us define \\(\\hat{\\delta} (q, wa) =\n    \\delta (\\hat{\\delta}(q,w),a)\\).\n\n\\end{itemize*}\nThen the word \\(w\\) is recognised by \\(\\mathcal{D}\\) if\n\\(\\hat{\\delta}(q_0, w) \\in F\\). The language \\(L(\\mathcal{D})\\)\nrecognised by~\\(\\mathcal{D}\\) is defined as \\(L(\\mathcal{D}) = \\{w \\in\n\\Sigma^{*} \\; \\lvert \\; \\hat{\\delta}(q_0, w) \\in F\\}\\). For example,\nin our last example:\n\\begin{equation*}\n\\begin{aligned}\n   \\hat{\\delta}(q_0, \\epsilon)\n&= q_0,\\\\\n   \\hat{\\delta}(q_0, \\textsf{t})\n&= \\delta (\\hat{\\delta}(q_0, \\epsilon), \\textsf{t})\n= \\delta (q_0, \\textsf{t})\n= q_1,\\\\\n   \\hat{\\delta}(q_0, \\textsf{th})\n&= \\delta (\\hat{\\delta}(q_0, \\textsf{t}), \\textsf{h})\n= \\delta (q_1, \\textsf{h})\n= q_2,\\\\\n   \\hat{\\delta}(q_0, \\textsf{the})\n&= \\delta (\\hat{\\delta}(q_0, \\textsf{th}), \\textsf{e})\n= \\delta (q_2, \\textsf{e})\n= q_4,\\\\\n   \\hat{\\delta}(q_0, \\textsf{then}) \n&= \\delta (\\hat{\\delta}(q_0, \\textsf{the}), \\textsf{n})\n= \\delta (q_4, \\textsf{n})\n= q_5 \\in F.\n\\end{aligned}\n\\end{equation*}\n\n\\subsection*{Transition diagrams}\n \nWe can also redefine transition diagrams in terms of the concept of\nDFA. A transition diagram for a DFA \\(\\mathcal{D} = (Q, \\Sigma,\n\\delta, q_0, F)\\) is a graph defined as follows:\n\\begin{enumerate*}\n\n  \\item for each state \\(q\\) in \\(Q\\) there is a \\emph{node}, \\emph{i.e.,} a\n    single circle with \\(q\\) inside;\n\n  \\item for each state \\(q \\in Q\\) and each input symbol \\(a \\in\n    \\Sigma\\), if \\(\\delta (q, a)\\) exists, then there is an\n    \\emph{edge}, \\emph{i.e.,} an arrow, from the node denoting~\\(q\\) to the\n    node denoting \\(\\delta (q, a)\\) labelled by \\(a\\); multiple edges\n    can be merged into one and the labels are then separated by\n    commas;\n\n  \\item there is an edge coming to the node denoting~\\(q_0\\) without\n    origin;\n\n  \\item nodes corresponding to final states are doubly circled.\n\n\\end{enumerate*}\nHere is a transition diagram for the language over alphabet \\(\\{0,\n1\\}\\), called \\emph{binary alphabet}, which contains the\nstring~\\(01\\):\n\\begin{center}\n\\includegraphics[bb=48 710 185 760]{dfa_01}\n\\end{center} \n\n\\subsection*{Transition table}\n\nThere is a compact textual way to represent the transition function of\na DFA: a \\emph{transition table}. The rows of the table correspond to\nthe states and the columns correspond to the inputs (symbols). In\nother words, the entry for the row corresponding to state~\\(q\\) and\nthe column corresponding to input~\\(a\\) is the state~\\(\\delta (q,\na)\\), as seen in \\fig~\\ref{fig:gen_table}.\n\\begin{figure}\n\\centering\n\\subfloat[General table\\label{fig:gen_table}]{\n\\(\\begin{array}{c||c|c|c}\n\\delta & \\ldots & a & \\ldots\\\\\n\\hhline{=::===}\n\\vdots & & &\\\\\n\\hline\nq & & \\delta (q, a)\\\\\n\\hline\n\\vdots & & &\n\\end{array}\n\\)}\n\\qquad\n\\subfloat[Example\\label{fig:example_table}]{\n\\(\\begin{array}{r@{}l||c|c}\n\\multicolumn{2}{c||}{\\mathcal{D}} & 0 & 1\\\\\n\\hhline{==::==}\n\\rightarrow & q_0 & q_1 & q_0\\\\\n            & q_1 & q_1 & q_2\\\\\n         \\# & q_2 & q_2 & q_2\\\\\n            &     &     &\n\\end{array}\\)\n}\n\\caption{Transition tables}\n\\end{figure}\nFor instance, the transition table corresponding to the\nfunction~\\(\\delta\\) of our last example is found in\n\\fig~\\vref{fig:example_table}. Actually, we added some extra\ninformation in the table: the initial state is marked with\n\\(\\rightarrow\\) and the final states are marked\nwith~\\(\\#\\). Therefore, it is not only~\\(\\delta\\) which is defined by\nmeans of the transition table here, but the whole DFA~\\(\\mathcal{D}\\).\n\nLet us consider another example. We want to define formally a DFA\nwhich recognises the language \\(L\\) whose words contain an even number\nof 0's and an even number of 1's (the alphabet is binary). We should\nunderstand that the role of the states here is to \\emph{not} count the\nexact number of 0's and 1's that have been recognised before, but,\ninstead, this number \\emph{modulo~2}. Therefore, there are four states\nbecause there are four cases:\n\\begin{enumerate*}\n\n  \\item there has been an even number of 0's and 1's (state \\(q_0\\));\n\n  \\item there has been an even number of 0's and an odd number of 1's\n    (state \\(q_1\\));\n\n  \\item there has been an odd number of 0's and an even number of 1's\n    (state \\(q_2\\));\n\n  \\item there has been an odd number of 0's and 1's (state \\(q_3\\)).\n\n\\end{enumerate*}\nWhat about the initial and final states?\n\\begin{itemize*}\n\n  \\item State~\\(q_0\\) is the initial state because before considering\n  any input, the number of 0's and 1's is zero and zero is even;\n\n  \\item state~\\(q_0\\) is the lone final state because its definition\n  matches exactly the characteristic of~\\(L\\) and no other state\n  matches.\n\n\\end{itemize*}\nWe almost know now how to specify the DFA for the language~\\(L\\). It\nis\n\\begin{equation*}\n\\mathcal{D} = (\\{q_0,q_1,q_2,q_3\\}, \\{0,1\\}, \\delta,q_0, \\{q_0\\}),\n\\end{equation*}\nwhere the transition function~\\(\\delta\\) is described by the\ntransition diagram in \\fig~\\vref{fig:dfa_even01}.\n\\begin{figure}\n\\centering\n\\subfloat[The DFA\\label{fig:dfa_even01}]{\n\\includegraphics[bb=48 653 138 737]{dfa_even01}\n}\n\\qquad\n\\subfloat[The table\\label{fig:table_even01}]{\n\\includegraphics{table_even01}\n}\n\\caption{A deterministic finite automaton and its table}\n\\end{figure}\nNotice how each input~0 causes the state to cross the horizontal\nline. Thus, after seeing an even number of 0's we are always above the\nhorizontal line, in state~\\(q_0\\) or~\\(q_1\\), and after seeing an odd\nnumber of 0's we are always below this line, in state~\\(q_2\\)\nor~\\(q_3\\). There is a vertically symmetric situation for transitions\non~1. We can also represent this DFA by the transition table in\n\\fig~\\vref{fig:table_even01}. We can use that table to illustrate the\nconstruction of~\\(\\hat{\\delta}\\) from~\\(\\delta\\). Suppose the input is\n\\(110101\\). Since this string has even numbers of 0's and 1's, it\nbelongs to~\\(L\\), that is, we expect \\(\\hat{\\delta}(q_0,110101) =\nq_0\\), since \\(q_0\\)~is the sole final state. We can check this by\ncomputing step by step \\(\\hat{\\delta}(q_0,\\verb+110101+)\\), from the\nshortest prefix to the longest, which is the word \\verb+110101+\nitself:\n\\begin{align*}\n  \\hat{\\delta} (q_0, \\varepsilon) \n&= q_0,\\\\\n   \\hat{\\delta} (q_0, \\texttt{1}) \n&= \\delta (\\hat{\\delta} (q_0, \\varepsilon), \\texttt{1})\n= \\delta (q_0, \\texttt{1})\n= q_1,\\\\\n   \\hat{\\delta} (q_0, \\texttt{11}) \n&= \\delta (\\hat{\\delta} (q_0, \\texttt{1}), \\texttt{1}) \n= \\delta (q_1, \\texttt{1}) \n= q_0,\\\\\n   \\hat{\\delta} (q_0, \\texttt{110}) \n&= \\delta (\\hat{\\delta} (q_0, \\texttt{11}), \\texttt{0}) \n= \\delta (q_0, \\texttt{0}) \n= q_2,\\\\\n   \\hat{\\delta} (q_0, \\texttt{1101}) \n&= \\delta (\\hat{\\delta} (q_0, \\texttt{110}), \\texttt{1}) \n= \\delta (q_2, \\texttt{1}) \n= q_3,\\\\\n   \\hat{\\delta} (q_0, \\texttt{11010}) \n&= \\delta (\\hat{\\delta} (q_0, \\texttt{1101}), \\texttt{0}) \n= \\delta (q_3, \\texttt{0}) \n= q_1,\\\\\n   \\hat{\\delta} (q_0, \\texttt{110101}) \n&= \\delta (\\hat{\\delta} (q_0, \\texttt{11010}), \\texttt{1}) \n= \\delta (q_1, \\texttt{1}) \n= q_0 \\in F.\n\\end{align*}\n", "meta": {"hexsha": "7c03bee9b54ca09b4e265cf328ef65ee7725a1d0", "size": 9383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dfa.tex", "max_stars_repo_name": "rinderknecht/Book", "max_stars_repo_head_hexsha": "6f302ab1319c8ae9b3ea690c45fdb3d2b6fbca16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dfa.tex", "max_issues_repo_name": "rinderknecht/Book", "max_issues_repo_head_hexsha": "6f302ab1319c8ae9b3ea690c45fdb3d2b6fbca16", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dfa.tex", "max_forks_repo_name": "rinderknecht/Book", "max_forks_repo_head_hexsha": "6f302ab1319c8ae9b3ea690c45fdb3d2b6fbca16", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.7960784314, "max_line_length": 76, "alphanum_fraction": 0.6602365981, "num_tokens": 3344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.868826784729373, "lm_q1q2_score": 0.8009903854127494}}
{"text": "\\subsection{Hyperbolic Paraboloids}\r\n\\noindent\r\nHyperbolic paraboloids have the form\r\n\\begin{equation*}\r\n\tz = x^2 - y^2.\r\n\\end{equation*} \r\nThey are not radially symmetric and look like a saddle or Pringle's chip.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.33\\textwidth]{./Images/differentialMultivariableCalculus/hyperbolic_paraboloid.png}\r\n\t\\caption{A hyperbolic paraboloid}\r\n\\end{figure}", "meta": {"hexsha": "ba5933451e3d7f54751ed8ba5cc3397b8998fae1", "size": 408, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/hyperbolicParaboloids.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/hyperbolicParaboloids.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/hyperbolicParaboloids.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.3846153846, "max_line_length": 110, "alphanum_fraction": 0.7647058824, "num_tokens": 127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.8688267677469952, "lm_q1q2_score": 0.8009903641648252}}
{"text": "\\chapter{Cardinalities of Sets}\n\\label{chapter:cardinality}\n\\Cref{part:combinatorics} discusses sizes of sets; however, this notion was\nnever defined formally. This part is going to close this gap and study\nproperties of sizes of sets.\n\n\n\\section{Definition}\nOne may notice that if we have a bijection $f$ from $\\range{n}$ to a set $S$ we\nenumerate all the elements of $S$: $f(1)$, \\dots, $f(n)$.\nThis observation allows us to define the cardinality of a set.\n\\begin{definition}\n  Let $S$ be a set, we say that cardinality of $S$ is equal to $n$ (we write\n  that $\\cardinality{S} = n$) iff there is a bijection from $\\range{n}$ to $S$.\n\n  We also say that a set $T$ is finite if there is an integer $n$ such that\n  $\\cardinality{T} = n$.\n\\end{definition}\n\nNote that this definition does not guarantee that cardinality is unique so\nwe need the following theorem.\n\\begin{theorem}\n\\label{theorem:correctness-of-cardinality}\n    For any set $S$, if there are bijections $f : \\range{n} \\to S$ and\n    $g : \\range{m} \\to S$, then $n = m$.\n\\end{theorem}\n\\begin{proof}[Proof of Theorem~\\ref{theorem:correctness-of-cardinality}]\n    Let us consider the inverse $g^{-1}$ of $g$ (it exists by\n    Theorem~\\ref{theorem:inverse-of-bijections} since $g$ is a\n    bijection). Note that $h = g^{-1} \\circ f$\n    is a bijection from $\\range{n}$ to $\\range{m}$.\n\n    We prove using induction by $n$ that for any $n, m \\in \\N$,\n    if there is a bijection $h'$ from $\\range{n}$ to $\\range{m}$, then $n = m$.\n    The base case is for $n = 1$; if $m \\ge 2$,\n    then there are $x, y \\in [1]$ such that $h'(x) = 1$ and $h'(y) = 2$, but\n    $x \\neq y$ and we have only one element in $[1]$.\n\n    The induction step is also simple. Assume that there is a bijection $h'$ from\n    $[n + 1]$ to $\\range{m}$. We define a function\n    $h'' : \\range{n} \\to \\range{m - 1}$ as follows:\n    \\[\n        h''(i) =\n        \\begin{cases}\n            h'(i) & \\text{if } h'(i) < h'(n + 1) \\\\\n            h'(i) - 1 & \\text{otherwise}\n        \\end{cases}.\n    \\]\n    We prove that $h''$ is a bijection.\n    \\begin{itemize}\n        \\item Let $i_1 \\neq i_2 \\in \\range{n}$. If\n            $h'(i_1), h'(i_2) < h'(n + 1)$ or $h'(i_1), h'(i_2) \\ge h'(n + 1)$,\n            then $h''(i_1) \\neq h''(i_2)$ since $h'(i_1) \\neq h'(i_2)$.\n            Otherwise, without loss of generality we may assume that\n            $h'(i_1) < h'(n + 1) < h'(i_2)$ but it implies that\n            $h''(i_1) = h'(i_1) < h'(n + 1) \\le h'(i_2) - 1 = h''(i_2)$.\n        \\item Let $j \\in [m - 1]$. We need to consider two cases.\n            \\begin{enumerate}\n                \\item Let $j < h(n + 1)$. There is $i \\in [n + 1]$ such that\n                    $h'(i) = j$ since $h'$ is a bijection\n                    (note that $i \\neq n + 1$). Thus $h''(i) = j$.\n                \\item Otherwise, there is $i \\in [n + 1]$ such that\n                    $h'(i) = j + 1$ since $h'$ is a bijection\n                    (note that $i \\neq n + 1$). Thus $h''(i) = j$.\n            \\end{enumerate}\n    \\end{itemize}\n    Since $h''$ is a bijection, the induction hypothesis implies that\n    $n = m - 1$. As a result, $n + 1 = m$.\n\\end{proof}\n\n\nAlso, using this definition we may finally prove\n\\Cref{theorem:bijection-to-equality}.\n\\begin{proof}[Proof of \\Cref{theorem:bijection-to-equality}]\n    Let $\\cardinality{X} = n$, and $g : \\range{n} \\to X$ be a bijection.\n    Note that $f \\circ g : \\range{n} \\to Y$ is a bijection, hence\n    $\\cardinality{Y} = n$.\n\\end{proof}\n\n\\section{Proofs of Combinatorial Principles}\nWe start from proving the additive principle. Recall that it says that if two\nfinite sets $X = \\set{x_1, \\dots, x_n}$ and $Y = \\set{y_1, \\dots, y_m}$ are\ndisjoint, then their union contains $n + m$ elements. Informally this statement\nis very easy since we can simply enumerate elements of the set $X$ first and\nafter that enumerate elements of $Y$:\n\\[\n  \\begin{matrix}\n    x_1 & x_2 & \\dots & x_n & y_1    & y_2   & \\dots & y_m \\\\\n    1   & 2   & \\dots & n   & n + 1  & n + 2 & \\dots & n + m.\n  \\end{matrix}\n\\]\nUsing the definition of cardinality, this informal proof can be formalized as\nfollows. \n\\begin{proof}[Proof of \\Cref{theorem:additive-principle}]\n  Let $\\cardinality{X} = n$, $\\cardinality{Y} = m$ and $g : \\range{n} \\to X$ and $h : \\range{m} \\to Y$ be\n  bijections. In order to prove it we just construct a bijection\n  $f : [n + m] \\to (X \\cup Y)$.\n\n  \\[\n    f(i) =\n    \\begin{cases}\n        g(i) & i < n \\\\\n        h(i  - n) & i > n\n    \\end{cases}.\n  \\]\n\n  It's easy to see that $f$ is an injection. Let us start by assuming the opposite i.e.\n  that $i_0 \\neq i_1 \\in X \\cup Y$ such that $f(i_0) = f(i_1)$.\n  There are three cases.\n  \\begin{itemize}\n    \\item The first is when $i_0, i_1 \\in \\range{n}$. In this case $g(i_0) = g(i_1)$\n      which contradicts the assumption that $g$ is a bijection.\n    \\item The second is when $i_0, i_1 \\in \\set{n + 1, n + 2, \\dots, m}$.\n      In this case $h(i_0 - n) = h(i_1 - n)$ which contradicts the assumption\n      that $h$ is a bijection.\n    \\item Finally, the last case is when $i_0 \\in \\range{n}$ and\n      $i_1 \\in \\set{n + 1, n + 2, \\dots, m}$. It is easy to see that this\n      implies that $g(i_0) = h(i_1 - n)$. However, it\n      means that $g(i_0) = h(i_1 - n) \\in (X \\cap Y)$, which contradicts the\n      assumption that $X \\cap Y = \\emptyset$.\n  \\end{itemize}\n\n  To finish the proof we need to show that $f$ is a surjection. Let\n  $w \\in (X \\cup Y)$. Consider the following two cases.\n  \\begin{itemize}\n    \\item Let $w \\in X$. There is $i \\in \\range{n}$ such that $f(i) = g(i) = w$ since\n      $g$ is a bijection.\n    \\item Otherwise, $w \\in Y$. In this case, there is $i \\in \\range{m}$ such that\n      $f(i + n) = h(i) = w$ since $h$ is a bijection.\n  \\end{itemize}\n\\end{proof}\n\nUsing the additive principle it is pretty easy to prove the multiplicative\nprinciple. Recall that the multiplicative principle says that the Cartesian\nproduct of two finite sets $X = \\set{x_1, \\dots, x_n}$ and \n$Y = \\set{y_1, \\dots, y_m}$ has size $nm$. It is easy to justify this statement\ninformally; indeed, note that $X \\times Y$ has the following elements:\n\\[\n  \\begin{matrix}\n    (x_1, y_1) & (x_1, y_2) & \\dots & (x_1, y_m) \\\\\n    (x_2, y_1) & (x_2, y_2) & \\dots & (x_2, y_m) \\\\\n    \\dots \\\\\n    (x_n, y_1) & (x_n, y_2) & \\dots & (x_n, y_m);\n  \\end{matrix}\n\\]\neach line has $m$ elements and there are $n$ lines, so there are $nm$ elements\naltogether that can be enumerated as follows:\n\\[\n  \\begin{matrix}\n    (x_1, y_1) & (x_1, y_2) & \\dots & (x_1, y_m) \\\\\n    1          & 2          & \\dots & m \\\\\n    (x_2, y_1) & (x_2, y_2) & \\dots & (x_2, y_m) \\\\\n    m + 1      & m + 2      & \\dots & m + m \\\\\n    \\dots \\\\\n    (x_n, y_1) & (x_n, y_2) & \\dots & (x_n, y_m) \\\\\n    (n - 1) m + 1 & (n - 1) m + 2 & \\dots & (n - 1) m + m\n  \\end{matrix}\n\\]\nThe definition of cardinality gives us a simple formalization of this argument.\n\\begin{proof}[Proof of \\Cref{theorem:multiplicative-principle}]\n  If one of the sets $X$ and $Y$ is empty, then $X \\times Y$ is empty as well\n  and the statement is as follows.\n\n  Assume that none of the sets are empty. Let $\\cardinality{X} = n$,\n  $\\cardinality{Y} = m$, and\n  $f : \\range{n} \\to X$ and $g : \\range{m} \\to Y$ be bijections.\n  Note that\n  \\[\n    \\bigcup_{i = 1}^n (\\set{f(i)} \\times Y) = X \\times Y.\n  \\]\n  Additionally, note that $(\\set{f(i)} \\times Y) \\cap (\\set{f(j)} \\times Y) =\n  \\emptyset$ for $i \\neq j$. Finally, it is easy to see that $g_i : \\range{m} \\to\n  (\\set{f(i)} \\times Y)$ such that $g_i(j) = (f(i), g(j))$ is a bijection.\n  Hence,\n  $\\cardinality{X \\times Y} = \\sum_{i = 1}^n \\cardinality{\\set{f(i)} \\times Y} = n \\cdot m$.\n\\end{proof}\n\n\n\\section{Generalized Commutative Operations}\n\\label{section:generalized-sum}\nUsing the notion of cardinality we can formalize the summation operation over\nsets:\n\\[\n    \\sum_{i \\in S ~:~ P(i)} f(i) = \\sum_{j = 1}^k f(i_j),\n\\]\nwhere $\\set[P(i)]{i \\in S} = \\set{i_1, \\dots, i_k}$. More formally,\n\\[\n    \\sum_{i \\in S ~:~ P(i)} f(i) = \\sum_{j = 1}^k f(g(j)),\n\\]\nwhere $k = \\cardinality{\\set[P(i)]{i \\in S}}$ and $g : \\set[P(i)]{i \\in S} \\to \\range{k}$ is\na bijection.\n\n\\begin{theorem}\n\\label{theorem:sum-correctness}\n    The definition of $\\sum_{i \\in S : P(i)} f(i)$ does not depend on the choice\n    of $g$;\n    i.e. $\\sum_{i = 1}^k f(g_1(i)) = \\sum_{i = 1}^k f(g_2(i))$\n    for any two bijections $g_1, g_2 : \\set[P(i)]{i \\in S} \\to \\range{k}$.\n\\end{theorem}\nBefore we prove this statement we need to give a couple of definitions.\nWe say that a function $h : \\range{n} \\to \\range{n}$ is a \\emph{permutation} of\n$\\range{n}$ iff $h$ is a bijection. We also say that\n$i, j \\in \\range{k}$ form the inversion in $h$ iff $h(i) > h(j)$ and $i < j$.\nWe denote by $I(h)$ the number of inversions in $h$; i.e. $I(h) =\n\\cardinality{\\set[i, j \\text{ form an inversion in } h]{(i, j)}}$.\n\\nomenclature[C]{$I(h)$}{denotes the number of inversions in $h$}\n\nImportant examples of permutations are transposition: for any\n$i, j \\in \\range{n}$, $\\tau_{i, j} : \\range{n} \\to \\range{n}$ such that\n\\[\n    \\tau_{i, j}(x) =\n    \\begin{cases}\n        j & \\text{if } x = i \\\\\n        i & \\text{if } x = j \\\\\n        x & \\text{otherwise}\n    \\end{cases}.\n\\]\nis called a transposition of $i$ and $j$.\n\\nomenclature[F]{$\\tau_{i, j}$}{denotes the transposition of $i$ and $j$}\n\nIt is easy to see that $I(h) = 0$ iff $h(i) = i$ for any $i \\in \\range{k}$.\nIt is also clear that if $i, j$ form an inversion in $h$, then $I(h) > I(h')$,\nwhere $h' = h \\circ \\tau_{i, j}$, i.e.\n\\[\n    h'(x) =\n    \\begin{cases}\n        h(j) & \\text{if } x = i \\\\\n        h(i) & \\text{if } x = j \\\\\n        h(x) & \\text{otherwise}\n    \\end{cases}.\n\\]\n\n\n\\begin{proof}[Proof of Theorem~\\ref{theorem:sum-correctness}]\n    Proof of this theorem consists of two parts.\n    First, we prove that\n    \\begin{equation}\n        \\label{equation:summation-with-respect-to_bijection}\n        \\sum_{i = 1}^k f(g(i)) = \\sum_{i = 1}^k f(g(h(i)))\n    \\end{equation}\n    for any bijections $g : \\set[P(i)]{i \\in S} \\to \\range{k}$ and\n    $h : \\range{k} \\to \\range{k}$.\n\n    We prove Equation~\\ref{equation:summation-with-respect-to_bijection} using the\n    induction by $I(h)$.\n    \\begin{description}\n        \\item[(the base case)] If $I(h) = 0$, then $h$ is the identity function and\n            $g(i) = g(h(i))$. Hence,\n            Equation~\\ref{equation:summation-with-respect-to_bijection} is true.\n        \\item[(the induction step)] By the induction hypothesis, for any permutation\n            $h' : \\range{k} \\to \\range{k}$,\n            if $I(h') < \\ell$, then\n            \\[\n                \\sum_{i = 1}^k f(g(i)) = \\sum_{i = 1}^k f(g(h'(i))).\n            \\]\n            Let us consider a permutation $h : \\range{k} \\to \\range{k}$ such that\n            $I(h) = \\ell$. Let $i$ and $j$ form an inversion in $h$ (such $i$ and $j$\n            exist since $I(h) \\neq 0$). Let $h' = h \\circ \\tau_{i, j}$.\n            Note that by the induction hypothesis,\n            \\[\n                \\sum_{i = 1}^k f(g(i)) = \\sum_{i = 1}^k f(g(h'(i)))\n            \\]\n            since $I(h') < I(h) = \\ell$ and it is clear that\n            \\[\n                \\sum_{i = 1}^k f(g(h'(i))) = \\sum_{i = 1}^k f(g(h(i))).\n            \\]\n            As a result,\n            Equation~\\ref{equation:summation-with-respect-to_bijection} is true.\n    \\end{description}\n\n    Now we are ready to finish proof of the theorem.\n    Consider $g_1, g_2 : \\set[P(i)]{i \\in S} \\to \\range{k}$ and define\n    $h = g_1^{-1} \\circ g_2$. Note that $h : \\range{k} \\to \\range{k}$ is a\n    permutation and $g_1(h(i)) = g_2(i)$. Thus we proved that\n    \\[\n        \\sum_{i = 1}^k f(g_1(i)) = \\sum_{i = 1}^k f(g(h(i))) =\n        \\sum_{i = 1}^k f(g_2(i)).\n    \\]\n\\end{proof}\n\nSimilarly one may define a generalized union and intersection of sets.\nLet $\\Omega$ and $S$ be some sets, $X : S \\to 2^\\Omega$ and $P(i)$ be a\npredicate. Then\n\\begin{gather*}\n    \\bigcup_{i \\in S ~:~ P(i)} X(i) = \\bigcup_{i = 1}^k X(g(i)) \\\\\n    \\text{and}\\\\\n    \\bigcap_{i \\in S ~:~ P(i)} X(i) = \\bigcap_{i = 1}^k X(g(i)),\n\\end{gather*}\nwhere $k = \\cardinality{\\set[P(i)]{i \\in S}}$ and $g : \\set[P(i)]{i \\in S} \\to \\range{k}$ is\na bijection.\n\\nomenclature[S]{$\\bigcup_{i \\in S ~:~ P(i)} A_i$}{denotes $A_{i_1} \\cup \\dots\n\\cup A_{i_k}$, where $\\set[P(i)]{i \\in S} = \\set{i_1, \\dots, i_k}$}\n\\nomenclature[S]{$\\bigcap_{i \\in S ~:~ P(i)} A_i$}{denotes $A_{i_1} \\cap \\dots\n\\cap A_{i_k}$, where $\\set[P(i)]{i \\in S} = \\set{i_1, \\dots, i_k}$}\n\n\\begin{exercise}\n    Show that the definitions of $\\bigcup_{i \\in S : P(i)} X(i)$ and\n    $\\bigcap_{i \\in S : P(i)} X(i)$ are correct,\n    i.e. that they do not depend on the choice of $g$.\n\\end{exercise}\n\n\n\\begin{chapterendexercises}\n    \\exercise Prove Theorem~\\ref{theorem:injections-surjections-inequalities}.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "ff837859cf039e98959abdf1d9f7363735e0a5cb", "size": 12817, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_5/chapter_24_cardinality.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_5/chapter_24_cardinality.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_5/chapter_24_cardinality.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 41.885620915, "max_line_length": 105, "alphanum_fraction": 0.5753296403, "num_tokens": 4672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.9059898254600902, "lm_q1q2_score": 0.8009305862651469}}
{"text": "\\section{Exponents and roots}\n\\begin{center}\n    \\begin{longtable}{lcr}\n        $a^n \\cdot a^m = a^{(n + m)}$\n        &\n        $\\frac{a^n}{a^m} = a^{(n - m)}$\n        &\n        $a^{-n} = \\frac{1}{a^n}$\n        \\\\\n        $\\left(a^n\\right)^m = a^{(n \\cdot m)}$\n        &\n        $(a \\cdot b)^n = a^n \\cdot b^n$\n        &\n        $\\left(\\frac{a}{b}\\right)^n = \\frac{a^n}{b^n}$\n        \\\\\n        $\\sqrt[q]{a} = a^\\frac{1}{q}$\n        &\n        $\\sqrt[q]{a^p} = a^\\frac{p}{q}$\n        &\n        $\\sqrt[q]{a \\cdot b} = \\sqrt[q]{a} \\cdot \\sqrt[q]{b}$\n        \\\\\n        $\\sqrt[q]{\\frac{a}{b}} = \\frac{\\sqrt[q]{a}}{\\sqrt[q]{b}}$\n        &\n        $a^0 = 1$\n        &\n        $a^1 = a$\n        \\\\\n        $(a \\pm b)^2 = a^2 + b^2 \\pm 2ab$\n        &\n        $(-1)^n = \\begin{cases}\n            1 & \\text{if } n \\text{ is even}\n            \\\\\n            -1 & \\text{if } n \\text{ is odd}\n        \\end{cases} $\n        &\n        $\\frac{1}{\\sqrt{a}} = \\frac{\\sqrt{a}}{a}$\n        \\\\\n        $(a + b)(a - b) = a^2 - b^2$\n        &\n        $a \\cdot \\sqrt{a} = a^\\frac{3}{2}$\n    \\end{longtable}\n\\end{center}\n", "meta": {"hexsha": "ff8b3b831feb82e2d8dd35d446089549c88f7b7c", "size": 1096, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/exponents_and_roots.tex", "max_stars_repo_name": "KongBorup/algebraic-tricks", "max_stars_repo_head_hexsha": "ea3e187203fffdaf03b3bc64994dcf95cf6f80c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sections/exponents_and_roots.tex", "max_issues_repo_name": "KongBorup/algebraic-tricks", "max_issues_repo_head_hexsha": "ea3e187203fffdaf03b3bc64994dcf95cf6f80c8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/exponents_and_roots.tex", "max_forks_repo_name": "KongBorup/algebraic-tricks", "max_forks_repo_head_hexsha": "ea3e187203fffdaf03b3bc64994dcf95cf6f80c8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-22T21:54:51.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-22T21:54:51.000Z", "avg_line_length": 25.488372093, "max_line_length": 65, "alphanum_fraction": 0.3312043796, "num_tokens": 424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517072737737, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.8007846945671899}}
{"text": "\\section{Estimators}\n\nA \\textbf{statistic} is any measurable function calculated with the data ($\\bar{X_n}, max(X_i),$ etc).\\\\\n\nAn \\textbf{estimator} $\\hat{\\theta }_ n$ of $\\theta$ is any statistic which does not depend on $\\theta$.\\\\\n\nEstimators are random variables if they depend on the data (= realizations of random variables).\\\\\n\nAn estimator $\\hat{\\theta }_ n$ is \\textbf{weakly consistent} if: $\\displaystyle \\lim _{n \\to \\infty } \\hat{\\theta }_ n = \\theta$ or $ \\hat{\\theta}_n \\xrightarrow[n \\rightarrow \\infty]{P} \\mathbb{E}[g(X)]$. If the convergence is almost surely it is \\textbf{strongly consistent}.\\\\\n\\textbf{Asymptotic normality of an estimator:}\n\\[\\sqrt(n) (\\hat{\\theta}_n-\\theta) \\xrightarrow[n \\rightarrow \\infty]{(d)} N(0,\\sigma^2)\\]\n$\\sigma^2$ is called the \\textbf{Asymptotic Variance} of the estimator $\\hat{\\theta}_n$. In the case of the sample mean it is the same variance as as the single $X_i$.\\\\\nIf the estimator is a function of the sample mean the \\textbf{Delta Method} is needed to compute the asymptotic variance.\\textbf{Asymptotic Variance} $\\neq$ Variance of an estimator.\\\\\n\\textbf{Bias of an estimator:}\n\\[Bias(\\hat{\\theta}_n) = \\mathbb{E}[\\hat{\\theta_n}] - \\theta\\]\n\\textbf{Quadratic risk of an estimator}\n\\begin{align*}\nR(\\hat{\\theta}_n) & = \\mathbb{E}[(\\hat{\\theta}_n-\\theta)^2]\\\\\n& = Bias^2 + Variance\n\\end{align*}", "meta": {"hexsha": "4ee23bce6f67535745d422385f2dedf325f1ac48", "size": 1355, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/estimators.tex", "max_stars_repo_name": "kpsunkara/MITx_capstone_2", "max_stars_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2019-04-24T02:24:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T10:26:41.000Z", "max_issues_repo_path": "content/estimators.tex", "max_issues_repo_name": "kpsunkara/MITx_capstone_2", "max_issues_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-07T20:24:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-06T08:24:47.000Z", "max_forks_repo_path": "content/estimators.tex", "max_forks_repo_name": "kpsunkara/MITx_capstone_2", "max_forks_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2019-03-11T14:20:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T16:31:34.000Z", "avg_line_length": 67.75, "max_line_length": 280, "alphanum_fraction": 0.7055350554, "num_tokens": 433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133548753619, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.8007618215931217}}
{"text": "\\subsubsection{Underdamped ($\\Delta < 0$)}\r\nThis is probably the most complicated case. Here, both roots are complex. Specifically,\r\n\\begin{equation*}\r\n\tr = \\frac{-b}{2m} \\pm i\\frac{\\sqrt{\\abs{\\Delta}}}{2m}\r\n\\end{equation*}\r\nLetting the coefficient of the imaginary part be $\\omega$,\r\n\\begin{equation*}\r\n\tr = \\frac{-b}{2m} \\pm i\\omega\r\n\\end{equation*}\r\nSo, our solution becomes\r\n\\begin{equation*}\r\n\ty = e^{\\frac{-b}{2m} t}\\left(C_1\\cos{(\\omega t)} + C_2\\sin{(\\omega t)}\\right)\r\n\\end{equation*}\r\nRewriting in terms of $\\cos$ and a phase shift,\r\n\\begin{equation*}\r\n\ty = Ae^{\\frac{-b}{2m} t}\\cos{(\\omega t - \\phi)} \\text{ where }\r\n\tA = \\sqrt{A^2 + B^2} \\text{, } \\phi = \\begin{cases}\r\n\t\t\\arctan{\\left(\\frac{B}{A}\\right)} + \\pi & A \\leq 0 \\\\\r\n\t\t\\arctan{\\left(\\frac{B}{A}\\right)} & A > 0\r\n\t\\end{cases}\r\n\\end{equation*}\r\n\\begin{center}\r\n\t\\includegraphics[width=0.5\\textwidth]{./higherOrder/freeVibrs/underdamped.png}\r\n\\end{center}\r\nHere, the exponential term dominates the limit, so\r\n\\begin{equation*}\r\n\t\\lim\\limits_{t \\to 0}{Ae^{\\frac{-b}{2m}t}\\cos{(\\omega t - \\phi)}} = 0\r\n\\end{equation*}\r\nmeaning the mass's oscillation decays over time, bounded by the exponential curves. ", "meta": {"hexsha": "b994e90ff68d15cc052e9893f84392e34328ed46", "size": 1170, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/freeVibrs/underdamped.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/higherOrder/freeVibrs/underdamped.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/higherOrder/freeVibrs/underdamped.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.3448275862, "max_line_length": 88, "alphanum_fraction": 0.6487179487, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922389, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.8007618201591804}}
{"text": "\n%% 8\n\\section{ Y Combinator. }\n\n% https://mvanier.livejournal.com/2897.html\n\n% See also http://r6.ca/blog/20060919T084800Z.html\n\n$$\nY = \u03bbf.(\u03bbx.f(xx))(\u03bbx.f(xx))\n$$\n\n\\begin{align*} \nY\\ g &= (\u03bbx.g(xx))(\u03bbx.g(xx)) \\\\\n     &= g ((\u03bbx.g(xx)) (\u03bbx.g(xx))) \\\\\n     &= g (Y\\ g) \\\\\n     &= g (g (g (g (g \\ldots))))\n\\end{align*} \nand it never ends if we use it like that. Still, if we take (using Haskell notation)\n\\begin{minted}{haskell}\ng h x | x == 1    = 1\n      | otherwise = x * (h $ x - 1)\n\\end{minted}\nthen for example \n\\begin{align*} \nY\\ g\\ 4 &= g\\ (Y\\ g)\\ 4                \\\\\n        &= 4 * ((Y\\ g)\\ 3)             \\\\\n        &= 4 * (g\\ (Y\\ g)\\ 3)          \\\\\n        &= 4 * 3 * ((Y\\ g)\\ 2)         \\\\\n        &= 4 * 3 * (g\\ (Y\\ g)\\ 2)      \\\\\n        &= 4 * 3 * 2 * ((Y\\ g)\\ 1)     \\\\\n        &= 4 * 3 * 2 * (g\\ (Y\\ g)\\ 1)  \\\\\n        &= 4 * 3 * 2 * 1               \\\\\n        &= 24,\\text{ also known as } 4!\n\\end{align*} \n\nHere, we have a definition of a recursive function (factorial) in a language that does\nnot directly allow recursion. Of course, that requires lazy evaluation ---\nand the definitions for naturals and multiplication.\n", "meta": {"hexsha": "8c909061a45e1935e878b3d0852ef8299e83266e", "size": 1137, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ps1/ps1_q8.tex", "max_stars_repo_name": "alf239/procats", "max_stars_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ps1/ps1_q8.tex", "max_issues_repo_name": "alf239/procats", "max_issues_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ps1/ps1_q8.tex", "max_forks_repo_name": "alf239/procats", "max_forks_repo_head_hexsha": "b825b19385f1c435f77bc855e246cd190472e696", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.425, "max_line_length": 86, "alphanum_fraction": 0.471416007, "num_tokens": 423, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.8007618108903326}}
{"text": "\n\\subsection{Calculus of sine and cosine}\n\n\\subsubsection{Unity}\n\nNote that with imaginary numbers we can reverse all \\(i\\)s. So:\n\n\\(e^{i\\theta }=\\cos (\\theta )+i\\sin (\\theta )\\)\n\n\\(e^{-i\\theta }=\\cos (\\theta )-i\\sin (\\theta )\\)\n\n\\(e^{i\\theta }e^{-i\\theta }=(\\cos (\\theta )+i\\sin (\\theta ))(\\cos (\\theta )-i\\sin (\\theta ))\\)\n\n\\(e^{i\\theta }e^{-i\\theta }=\\cos (\\theta )^2+\\sin (\\theta )^2\\)\n\n\\(e^{i\\theta }e^{-i\\theta }=e^{i\\theta -i\\theta }=e^0=1\\)\n\nSo:\n\n\\(\\cos (\\theta )^2+\\sin (\\theta )^2=1\\)\n\nNote that if \\(\\cos (\\theta )^2=0\\), then \\(\\sin (\\theta )^2=\\pm 1\\)\n\nThat is, if the real part of \\(e^{i\\theta }\\) is \\(0\\), the imaginary part is \\(\\pm 1\\). And visa versa.\n\nSimilarly if the derivative of the real part of \\(e^{i\\theta }\\) is \\(0\\), the imaginary part is \\(\\pm 1\\). And visa versa.\n\n\\subsubsection{Sine and cosine are linked by their derivatives}\n\nNote that these functions are linked in their derivatives.\n\n\\(\\dfrac{\\delta }{\\delta \\theta }\\cos (\\theta )=\\sum_{j=0}^\\infty \\dfrac{(\\theta )^{(4j+3)}}{(4j+3)!}-\\sum_{j=0}^\\infty \\dfrac{(\\theta )^{4j+1}}{(4j+1)!}\\)\n\n\\(\\dfrac{\\delta }{\\delta \\theta }\\cos (\\theta )=-\\sin (\\theta )\\)\n\nSimilarly:\n\n\\(\\dfrac{\\delta }{\\delta \\theta }\\sin (\\theta )=cos(\\theta )\\)\n\n\\subsubsection{Both sine and cosine oscillate}\n\n\\(\\dfrac{\\delta^2 }{\\delta \\theta^2}\\sin (\\theta )=-\\sin (\\theta )\\)\n\n\\(\\dfrac{\\delta^2 }{\\delta \\theta^2}\\cos (\\theta )=-\\cos (\\theta )\\)\n\nSo for either of:\n\n\\(y=\\cos (\\theta )\\)\n\n\\(y=\\sin (\\theta )\\)\n\nWe know that\n\n\\(\\dfrac{\\delta^2 }{\\delta \\theta^2}y(\\theta )=-y(\\theta )\\)\n\nConsider \\(\\theta =0\\).\n\n\\(e^{i.0}=\\cos (0)+i\\sin (0)\\)\n\n\\(1=\\cos (0)+i\\sin (0)\\)\n\n\\(\\sin (0)=0\\)\n\n\\(\\cos (0)=1\\)\n\nSimilarly we know that the derivative:\n\n\\(\\sin'(0)=\\cos(0)=1\\)\n\n\\(\\cos'(0)=-\\sin(0)=0\\)\n\nConsider \\(\\cos(\\theta )\\). \n\nAs \\(\\cos (0)\\) is static at \\(\\theta =0\\), and is positive, it will fall until \\(\\cos (\\theta )=0\\).\n\nWhile this is happening, \\(\\sin (\\theta )\\) is increasing. As:\n\n\\(\\cos (\\theta )^2+\\sin (\\theta )^2=1\\)\n\n\\(\\sin (\\theta )\\) will equal \\(1\\) where \\(\\cos (\\theta )=0\\).\n\nDue to symmetry this will repeat \\(4\\) times.\n\nLet's call the length of this period \\(\\tau \\).\n\nWhere \\(\\theta =\\tau *0\\)\n\n\\begin{itemize}\n\\item \\(\\cos (\\theta )=1\\)\n\\item \\(\\sin (\\theta )=0\\)\n\\end{itemize}\n\nWhere \\(\\theta =\\tau *\\dfrac{1}{4}\\)\n\n\\begin{itemize}\n\\item \\(\\cos (\\theta )=0\\)\n\\item \\(\\sin (\\theta )=1\\)\n\\end{itemize}\n\nWhere \\(\\theta =\\tau *\\dfrac{2}{4}\\)\n\n\\begin{itemize}\n\\item \\(\\cos (\\theta )=-1\\)\n\\item \\(\\sin (\\theta )=0\\)\n\\end{itemize}\n\nWhere \\(\\theta =\\tau *\\dfrac{3}{4}\\)\n\n\\begin{itemize}\n\\item \\(\\cos (\\theta )=0\\)\n\\item \\(\\sin (\\theta )=-1\\)\n\\end{itemize}\n\n\\subsubsection{Relationship between\\( \\cos (\\theta )\\) and \\(\\sin(\\theta )\\)}\n\nNote that \\(\\sin(\\theta + \\dfrac{\\tau }{4})=\\cos(\\theta )\\)\n\nNote that \\(\\sin (\\theta )=\\cos (\\theta )\\) at\n\n\\begin{itemize}\n\\item \\(\\tau *\\dfrac{1}{8}\\)\n\\item \\(\\tau *\\dfrac{5}{8}\\)\n\\end{itemize}\n\nAnd that all these answers loop. That is, add any integer multiple of \\(\\tau \\) to \\(\\theta \\) and the results hold.\n\n\\(e^{i\\theta } = e^{i\\theta +n\\tau }\\)\n\n\\(n \\in \\mathbb{N}\\)\n\n\\(e^{i\\theta } = \\cos(\\theta )+i\\sin(\\theta )\\)\n\n\\(e^{i\\theta } = \\cos(\\theta +n\\tau )+i\\sin(\\theta +n\\tau ) \\)\n\n\\(e^{i\\theta } = e^{i(\\theta +n\\tau )}\\)\n\n\n\\subsubsection{Calculus of trig}\n\nRelationship between cos and sine\n\n\\(\\sin(x+\\dfrac{\\pi }{2})=\\cos(x)\\)\n\n\\(\\cos(x+\\dfrac{\\pi }{2})=-\\sin(x)\\)\n\n\\(\\sin(x+\\pi )=-\\sin(x)\\)\n\n\\(\\cos(x+\\pi )=-\\cos(x)\\)\n\n\\(\\sin(x+\\tau )=\\sin(x)\\)\n\n\\(\\cos(x+\\tau )=\\cos(x)\\)\n\n", "meta": {"hexsha": "d305ee1242cf5da56ee231027cf6c5a6480790f8", "size": 3500, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/trigonometry/01-05-differentiation.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/trigonometry/01-05-differentiation.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/trigonometry/01-05-differentiation.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.7272727273, "max_line_length": 155, "alphanum_fraction": 0.5665714286, "num_tokens": 1336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.8007484295977615}}
{"text": "\\sec{Some integral functions}\nHere we study some \\emph{integral}\\footnote{pun intended} functions that will help us later.\\\\\nThe reader may skip this section for now and return to this when referenced later.\\\\\nWe skip the formal discussion about convergence of improper Riemann integrals. (These are different from the integrals done in MA 105.) A discussion can be found in Professor GKS' notes mentioned.\n\\subsection{The Gamma Function}\n\\begin{defn}[The Gamma Function]\n\tThe Gamma function is defined for $a > 0$ as follows:\n\t\\begin{equation*} \n\t\t\\Gamma(a) := \\int_{0}^{\\infty} t^{a-1}e^{-t} dt.\n\t\\end{equation*}\n\\end{defn}\n\\begin{mdframed}[style=boxstyle, frametitle={Some results}]\n\t\\begin{enumerate}[leftmargin=*]\n\t\t\\item $\\Gamma(n) = (n - 1)!$ for all $n \\in \\mathbb{Z}^+ = \\{1, 2, \\ldots\\}.$\n\t\t\\item $\\Gamma(x+1) = x\\Gamma(x)$ for all $x > 0.$\n\t\t\\item $\\Gamma\\left(\\dfrac{1}{2}\\right) = \\sqrt{\\pi}.$\n\t\t\\item The last two relations now let us calculate $\\Gamma$ for all half-integers.\n\t\t\\item And that's as far as we can get. Other values of Gamma are not known in such elementary terms. \n\t\t\\item Note that we can still calculate ratios such as\n\t\t\\begin{equation*} \n\t\t\t\\Gamma\\left(\\dfrac{5}{4}\\right)\\bigg/\\Gamma\\left(\\dfrac{1}{4}\\right).\n\t\t\\end{equation*}\n\t\\end{enumerate}\n\\end{mdframed}\n\n\\subsection{The Beta Function}\n\\begin{defn}[The Beta Function]\n\tThis is a function of two variables defined for $a > 0, b > 0$ as \n\t\\begin{equation*} \n\t\tB(a, b) := \\int_{0}^{1} x^{a-1}(1 - x)^{b-1} dx\n\t\\end{equation*}\n\\end{defn}\n\\begin{mdframed}[style=boxstyle, frametitle={Some identities}]\n\t\\begin{enumerate}[leftmargin=*]\n\t\t\\item $B(a, b) = B(b, a).$\n\t\t\\item $B(a + 1, b) = \\dfrac{a}{b}B(a, b+1).$\n\t\t\\item $B(a + 1, b) + B(a, b+1) = B(a, b).$\n\t\t\\item $B\\left(\\dfrac{1}{2}, \\dfrac{1}{2}\\right) = \\pi.$\n\t\\end{enumerate}\n\\end{mdframed}\n\\begin{thm}[The Beta-Gamma Relation] \n\t\\begin{equation*} \n\t\t\\Gamma(a)\\Gamma(b) = \\Gamma(a + b)B(a, b) \\quad \\forall\\; a, b > 0.\n\t\\end{equation*}\n\\end{thm}\n\\begin{thm}[Euler's Reflection Formula]\n\t\\begin{equation*} \n\t\t\\Gamma(a)\\Gamma(1 - a) = \\dfrac{\\pi}{\\sin(\\pi a)} \\quad \\forall\\;0 < a < 1\n\t\\end{equation*}\n\\end{thm}\n\n\\begin{mdframed}[style=boxstyle2, frametitle={An integral computation}]\n\t\\begin{thm} \\label{thm:randomintegral}\n\t\t\\begin{equation*} \n\t\t\t\\int_{0}^{\\infty} \\dfrac{x^{a-1}}{1 + x} dx = \\dfrac{\\pi}{\\sin \\pi a} \\quad \\text{ for } 0 < a < 1\n\t\t\\end{equation*}\n\t\\end{thm}\n\t\\begin{proof} \n\t\tPut $t = \\dfrac{1}{1 + x}.$ The integral transforms as\n\t\t\\begin{align*} \n\t\t\t& \\int_{0}^{1} (1 - t)^{a - 1}t^{-a} dt\\\\\n\t\t\t& = B(a, 1 - a)\\\\\n\t\t\t& = \\Gamma(a)\\Gamma(1 - a)\\\\\n\t\t\t& = \\dfrac{\\pi}{\\sin \\pi a}.\n\t\t\\end{align*}\n\t\\end{proof}\n\\end{mdframed}\n\n", "meta": {"hexsha": "df4d399b1dc1672e0a23d88137656c53a2fad48e", "size": 2681, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tuts/ma-108/summary/integralfunc.tex", "max_stars_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_stars_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-12-17T20:34:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T09:58:57.000Z", "max_issues_repo_path": "tuts/ma-108/summary/integralfunc.tex", "max_issues_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_issues_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-03-04T10:23:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-28T10:29:01.000Z", "max_forks_repo_path": "tuts/ma-108/summary/integralfunc.tex", "max_forks_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_forks_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-08-30T18:19:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-17T12:09:09.000Z", "avg_line_length": 38.8550724638, "max_line_length": 196, "alphanum_fraction": 0.637075718, "num_tokens": 1064, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.8007445538739842}}
{"text": "\\begin{solution}\nIn this problem we are going to see how inadequate it is to use equispaced nodes instead of, for instance, Chebishev nodes. In the interval $[-1,1]$ we are going to use polynomial approximation with equispaced nodes to apporximate the function \n\\begin{align*}\nf(x)=\\frac{1}{1+25x^2},\n\\end{align*}\nand compute the $L_{\\infty}$ error. In the following figure we ca see how the error grows with the number of nodes used. This clearly telling us that the nodes are not well distributed since using more nodes should give us more precision (at least for not too exotic problems). To understand this, as we saw in class, let's look at the function and the polynomial of degree 100 (highest degree used) together in the figure. It is obvious that the polynomial does not approximate the function at all when we get close to the boundries. This is causing the increasing error with $N$.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace*{\\fill}\n\\subfigure[Error dependency on $N$.]{\\includegraphics[scale=0.5]{IMAGES/problem5_1.eps}}\n\\hfill\n\\subfigure[Function and polynomial comparison.]{\\includegraphics[scale=0.5]{IMAGES/problem5_2.eps}}\n\\hspace*{\\fill}\n\\caption{Polynomial interpolation using equispaced nodes for the function $f(x)=\\frac{1}{1+25x^2}$.}\n\\end{figure}\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\nff = @(x) 1./(1+25*x.^2);\nN = 1:100;\nerr = 0*N;\nxx = linspace(-1,1,1000)';\nfor k = 1:length(N)\n    x = linspace(-1,1,N(k))';\n    W = baryWeights(x);\n    y = ff(x);\n    yy = bary(xx,y,x,W);\n    err(k) = norm(ff(xx)-yy,inf);\nend\nfigure\nsemilogy(N,err,'*',N,N.^-1,'--',N,N.^-3,'--')\nset(gca,'fontsize',14)\ngrid on\nxlabel('$N$','fontsize',20,'interpreter','latex')\nylabel('Error (log scale)','fontsize',20,'interpreter','latex')\nsaveas(gcf,'IMAGES/problem5_1','epsc')\n\nfigure\nplot(xx,ff(xx))\nhold on\nplot(xx,yy,'r--')\nxlabel('$x$','fontsize',20,'interpreter','latex')\nylabel('$f(x),p(x)$','fontsize',20,'interpreter','latex')\nlegend({'$f(x)$','$p(x)$'},'Interpreter','latex','Location','north','fontsize',16)\naxis([-1 1 -2 2])\ngrid on\nsaveas(gcf,'IMAGES/problem5_2','epsc')\n\\end{verbatim}\n\\end{solution}\n", "meta": {"hexsha": "98662c466006d81376763d5a76548e322d99eb68", "size": 2148, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 1/problem5.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 1/problem5.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 1/problem5.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.96, "max_line_length": 581, "alphanum_fraction": 0.7020484171, "num_tokens": 644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.894789464699728, "lm_q1q2_score": 0.800648179861508}}
{"text": "\\section{Unilinear Grammar}\n\nA grammar is unilinear iff all rules are either all left-linear or right-linear. It can also be required that it has:\n\\begin{itemize}\n    \\item Strictly unilinear rules: $A \\rarr aB$ with $a\\in \\Sigma \\cup \\epsilon$ and $B \\in V \\cup \\epsilon$\n    \\item All terminal rules are empty: $B \\rarr b$ replaced with $B \\rarr bB'$, $B' \\rarr \\epsilon$\n\\end{itemize}\n\n\\subsection{From Unilinear to Regular Expression}\n\n\\textbf{Assumptions}: strictly right unilinear, all terminal rules empty.\n\nFor every nonterminal $A$ defined by $A \\rarr a_1A_1|\\ldots|a_kA_k|\\epsilon$:\n$L_A = a_1L_{A_1} \\cup | \\ldots | \\cup a_kL_{A_k} \\cup \\epsilon$\n\n\\textbf{Arden Identity}: $X = KX \\cup L$ (with $K$ nonempty) has exactly one solution $X = K^*L$.\n\n\\textbf{Example} $S \\rarr sS | eA$, $A \\rarr sS|\\epsilon$\n\\begin{alignat*}{2}\n&\n    \\begin{cases}\n        L_S = sL_S \\cup eL_A \\\\\n        L_A = sL_S \\cup \\epsilon\n    \\end{cases}\n&&\n    \\begin{cases}\n        L_S = sL_S \\cup e(sL_S \\cup \\epsilon) \\\\\n        L_A = sL_S \\cup \\epsilon\n    \\end{cases}\n\\\\\n&\n    \\begin{cases}\n        L_S = (s \\cup es) L_S \\cup e \\\\\n        L_A = sL_S \\cup \\epsilon\n    \\end{cases}\n&&\n    \\begin{cases}\n        L_S = (s \\cup es)^*e \\\\\n        L_A = sL_S \\cup \\epsilon = s(s \\cup es)^*e \\cup \\epsilon\n    \\end{cases}\n\\end{alignat*}\n", "meta": {"hexsha": "eb75ad65989a589d4f5be4720cd1dcc6c754e86b", "size": 1317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "grammars/unilinear.tex", "max_stars_repo_name": "TiberioG/FLC-cheatsheet", "max_stars_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-01-13T14:36:20.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-18T16:22:18.000Z", "max_issues_repo_path": "grammars/unilinear.tex", "max_issues_repo_name": "TiberioG/FLC-cheatsheet", "max_issues_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "grammars/unilinear.tex", "max_forks_repo_name": "TiberioG/FLC-cheatsheet", "max_forks_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-21T11:05:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-17T14:59:50.000Z", "avg_line_length": 31.3571428571, "max_line_length": 117, "alphanum_fraction": 0.622627183, "num_tokens": 473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8705972667296309, "lm_q1q2_score": 0.8006382740117058}}
{"text": "\\section{Interpolation and the Lagrange Polynomial}\n\n\\begin{theo}[Weierstrass Approximation Theorem]\n$f\\in C[a,b]$, $\\forall$ polynomial $P(x)$, s.t. $\\left|f(x)-P(x)\\right|<\\epsilon$ for all $x\\in [a,b]$.\n\\end{theo}\n\n\\begin{theo}[$n$th Lagrange Interpolating Polynomial]\n$x_0,\\ldots,x_n$ are $n+1$ distinct numbers, then a unique polynomial $P(x)$ of degree at most $n$ exists with\n\\begin{align*}\n  f(x_k)=P(x_k)\\quad for\\space k=0:n \\\\\n  \\begin{cases}\n    P(x)=\\sum_{k=0}^{n}f(x_k)L_{n,k}(x) \\\\\n    L_{n,k}=\\prod_{\\substack{i=0\\\\i\\neq k}}^{k}\\frac{(x-x_i)}{x_k-x_i} \\\\\n    L_{n,k}(x_j)=\\delta_{k,j}\n  \\end{cases}\n\\end{align*}\nIf $f\\in C^{n+1}[a,b]$, $\\exists\\xi(x)\\in (a,b)$, s.t.\n\\[\nf(x) = P(x) + \\frac{f^{(n+1)}\\left(\\xi\\left(x\\right)\\right)}{(n+1)!}\\prod_{i=0}^{n}(x-x_i)\n\\]\n\\end{theo}\n\n\\begin{proof}\nlet \\[g(t)=f(t)-P(t)-\\left[f(x)-g(x)\\right]\\prod_{i=0}^{n}\\frac{(t-x_i)}{x-x_i},\\]\n$g(t)$ satisfies\n\\begin{align*}\n  \\begin{cases}\n  g(x_k)=0 & k=0:n\\\\\n  g(x)=0 & \\\\\n  g\\in C^{n+1}[a,b] \\\\\n  \\end{cases}\n\\end{align*}\nBy \\emph{Generalized Rolle's Theorem}, $\\exists\\xi\\in (a,b)$, s.t. $g^{(n+1)}(\\xi)=0$, then we have\n\\begin{align*}\n& 0 = g^{(n+1)}(\\xi)=f^{(n+1)}(\\xi)-P^{(n+1)}(\\xi)-\\left[f(x)-P(x)\\right]\\frac{\\D^{n+1}}{\\D t^{n+1}}\\left[\\prod_{i=0}^{n}\\frac{(t-x_i)}{x-x_i}\\right]_{t=\\xi} \\\\\n\\Rightarrow & 0 = f^{(n+1)}(\\xi)-\\left[f(x)-P(x)\\right]\\frac{(n+1)!}{\\prod_{i=0}^{n}(x-x_i)} \\\\\n\\Rightarrow & f(x) = P(x) + \\frac{f^{(n+1)}\\left(\\xi\\left(x\\right)\\right)}{(n+1)!}\\prod_{i=0}^{n}(x-x_i).\n\\end{align*}\n\\end{proof} ", "meta": {"hexsha": "81b0fcd1c88cddeba8b8edc56f8bfc4c9c18b4de", "size": 1525, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/3.1_Interpolation_and_the_lagrange_polynomial.tex", "max_stars_repo_name": "Iydon/NumericalAnalysisNotes", "max_stars_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-11-08T15:48:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T10:07:33.000Z", "max_issues_repo_path": "Notes/sections/3.1_Interpolation_and_the_lagrange_polynomial.tex", "max_issues_repo_name": "iydon/NumericalAnalysisNotes", "max_issues_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/sections/3.1_Interpolation_and_the_lagrange_polynomial.tex", "max_forks_repo_name": "iydon/NumericalAnalysisNotes", "max_forks_repo_head_hexsha": "ef1e37b97522fce9837142d242676fdd16e74712", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.1025641026, "max_line_length": 160, "alphanum_fraction": 0.5632786885, "num_tokens": 706, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8824278772763472, "lm_q1q2_score": 0.8006376019453627}}
{"text": "\\documentclass[11pt,letterpaper]{article}\n\\usepackage[T1]{fontenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\n\\usepackage[charter]{mathdesign}\n\\usepackage{fullpage}\n\\pagestyle{empty}\n\n\\input{../fncextra}\n\n\\begin{document}\n\t\n\\begin{center}\n  \\bf \n  Project: Deblur, denoise, delight!\n\\end{center}\n\t\nRecall that an image may be represented as an $m\\times n$ matrix $\\mX$ of pixel intensities. A fair way to simulate blurring the image is by\n\\begin{equation}\n\\label{blurmat}\n\\mZ =  (\\mB_m)^p \\mX \\, (\\mB_n^T)^p,\n\\end{equation}\nwhere $p$ is a positive integer and each $\\m{B}_k$ is a $k\\times k$ symmetric tridiagonal matrix with $1/2$ all along the main diagonal, and $1/4$ all along both the sub- and superdiagonals. As can easily be verified, the mapping from $\\mX$ to $\\mZ$ is linear, so if we represent the images as vectors (say, by stacking columns), then $\\bfz=\\mG \\bfx$. The matrix $\\m{G}$ must be $mn\\times mn$, and can be found explicitly, but we consider it to be unavailable. \n\nSuppose that the image $\\mZ$ is derived from both blurring of $\\mX$ and some added noise. We can write this as \n\\begin{equation}\n\\label{forward}\n\\bfz = \\mG \\bfx + \\bfy, \\quad \\text{for some $\\bfy$ with $\\|\\bfy\\|^2=\\delta^2$},\n\\end{equation}\nwhere $\\delta$ is a small(?) number. Our goal is the reconstruction problem: for known $\\bfz$, $\\mG$, and $\\delta$, return the best (most likely) $\\bfx$. An optimization is essential, since there are many possible solutions of~\\eqref{forward}. \n\nTruly random noise will look like static, with lots of value jumps from pixel to pixel. Real images, on the other hand, usually have large patches of slowly-varying values. Consider the $k\\times k$ matrix \n\\begin{equation}\n\\mR_k = \n\\begin{bmatrix}\n  -2 & 1      &        &        &    \\\\\n  1  & -2     & 1      &        &    \\\\\n     & \\ddots & \\ddots & \\ddots &    \\\\\n     &        & 1      & -2     & 1  \\\\\n     &        &        & 1      & -2 \\\\\n\\end{bmatrix}.\n\\end{equation}\n$\\mR_k$ is a scaled finite-difference approximation of the second derivative, so $\\|\\mR_k\\bfu\\|$ is a measure of the ``roughness'' of the vector $\\bfu$. The 2D equivalent of this process on an image matrix $\\mX$ is to apply roughening from both the left and the right, in the form \n\\begin{equation}\n  \\label{roughmat}\n   \\mR_m\\mX + \\mX\\mR_n^T.\n\\end{equation}\nThis too is a linear transformation of the image $\\mX$, which we denote by $\\m{L}\\bfx$ for an unspecified matrix $\\mL$. Minimizing roughness, as measured by $\\|\\mL\\bfx\\|$, seems like a reasonable optimization criterion. \n\nWe now have a complete problem to state:\n\\begin{equation}\n   \\label{consopt}\n   \\min \\| \\mL \\bfx\\|^2 \\; \\text{over all $\\bfx$ satisfying $\\|\\mG\\bfx-\\bfz\\| = \\delta$.}\n\\end{equation}\nThis is a multidimensional minimization subject to a scalar constraint function, a problem nicely changed to an unconstrained form by the method of Lagrange multipliers. Introducing the unknown scalar $\\lambda$, we obtain the simultaneous equations\n\\begin{align}\n    (\\mL^T\\mL + \\lambda \\mG^T\\mG)\\bfx &= \\lambda \\mG\\bfz \\label{lineq}\\\\\n    \\|\\mG\\bfx - \\bfz\\| - \\delta & = 0. \\label{nonlineq}\n\\end{align}\n\nEquation~\\eqref{lineq} is an $mn\\times mn$ linear system that defines $\\bfx$ when $\\lambda$ is given. We could pose~\\eqref{nonlineq} as a rootfinding problem for $\\lambda$. However, we rarely know a good value for $\\delta$ in advance, so it makes more sense to regard the solution $\\widehat{\\bfx}$ of~\\eqref{lineq} as a function of a tunable parameter $\\lambda$. As $\\lambda\\to0$, greater emphasis is placed on minimizing roughness (increased smoothing), and as $\\lambda\\to\\infty$, more emphasis is on deblurring (increased sharpness).\n\nThe matrices $\\mL$ and $\\mG$ are never needed for these computations. It's possible to show that $\\mL$ and $\\mG$ are both symmetric, so $\\mL^T\\mL\\bfx=\\mL(\\mL\\bfx)$ and $\\mG^T\\mG\\bfx=\\mG(\\mG\\bfx)$. For implementation, the multiplication $\\mL\\bfx$ or $\\mG\\bfx$ is achieved by reshaping $\\bfx$ to the image matrix $\\mX$,  applying~\\eqref{roughmat} or~\\eqref{blurmat}, respectively, and then reshaping back into a vector. Hence, given $\\lambda$, the operator on the left side of~\\eqref{lineq} can be implemented by writing a function that can be passed to \\texttt{gmres} in lieu of a matrix.\n\nA final note: Adding a constant to all the entries of $\\mZ$ can improve the reconstruction. A typical choice is to make the mean value of the pixels equal to zero. This doesn't affect the plot using \\texttt{imagesc}, which maps min and max pixel values to black and white. \n\n\\subsection*{Project assignment}\n\\label{sec:project-assignment}\n\nSubmit a zip archive with files as directed here. Don't forget to convert an imported image to a 2D matrix of class \\texttt{double}. \\textbf{You should use \\texttt{imagesc} for plotting all images, and after each image plot use}\n\\begin{verbatim}\n    colormap(gray(256))), axis equal\n\\end{verbatim}\n\n\\begin{description}\n\\item[\\textbf{Objective 1.}] Derive~\\eqref{lineq}--\\eqref{nonlineq} from~\\eqref{consopt}. You will need to consult a calculus book, and to take the gradients of expressions like $\\mC^T \\mC \\bfu$ and $\\bfu^T \\bfc$ with respect to $\\bfu$. \n\nFor this objective, submit the following:\n\\begin{itemize}\n\\item A PDF, \\texttt{objective1.pdf}, typeset nicely or scanned from a neatly written document and showing the derivation in convincing detail.\n\\end{itemize}\n\n\\item[\\textbf{Objective 2.}]  Write two functions:\n\\begin{verbatim}\n    function Z = blur(X,p)\n    function Z = roughen(X)\n\\end{verbatim}\nThey implement the equivalent of $\\mG\\bfx$ and $\\mL\\bfx$, respectively, but by operating on $m\\times n$ images via~\\eqref{blurmat} and~\\eqref{roughmat}. In practice, both $m$ and $n$ are small enough that it's not important to use sparse matrices. \nYou can test your functions on the image \\texttt{checkeredflag} available on the website. \n\nFor this objective, submit the following:\n\\begin{itemize}\n\\item Files \\texttt{blur.m} and \\texttt{rough.m}. Each should be self-contained. \n\\item Two PNG images. One shows the original and blurred (with $p=2$) checkered flag images side by side, and the other shows the original and roughened images side by side. \n\\end{itemize}\n\n\\item[\\textbf{Objective 3.}] Write a function\n\\begin{verbatim}\n    function y = linop(x,lambda,p,m,n)\n\\end{verbatim}\nThe inputs are a vectorized $mn\\times 1$ image $\\bfx$, a positive scalar value for $\\lambda$, and the size $m\\times n$ of the original image. The output is $\\bfy=(\\mL^T\\mL + \\lambda \\mG^T\\mG)\\bfx$, computed using calls to \\texttt{blur} and \\texttt{roughen}.\n\nFor this objective, submit the following:\n\\begin{itemize}\n\\item The file \\texttt{linop.m}. It should depend only on native MATLAB commands and \\texttt{blur} and \\texttt{roughen}.\n\\item A PNG file showing the result of applying \\texttt{linop} to the checkered flag image with $\\lambda=8$, $p=4$.\n\\end{itemize}\n\n\\item[{Objective 4.}] Download \\texttt{fonzie.png} from the website and import it as the degraded image $\\mZ$. For $p=3$ and $\\lambda=0.05,0.2,1,5$, apply \\texttt{gmres} using \\texttt{linop} to reconstruct the image $\\widehat{\\mX}$ (the matrix form of the solution of~\\eqref{lineq}).\n\nFor this objective, submit the following:\n\\begin{itemize}\n\\item Four PNG images, each showing one of your reconstructions with the value of $\\lambda$ in the title.\n\\end{itemize}\n\n\n\\item[Objective 5.] Download \\texttt{plate.png} from the website and import it as the degraded image $\\mZ$. It's a severely degraded image of a license plate. Experiment with $p$ and $\\lambda$ and do your best to identify all of the characters on the plate. You might want to use different parameter values for different characters.\n\nFor this objective, submit the following:\n\\begin{itemize}\n\\item One or more PNG images, showing your best reconstructions for the characters on the plate. The title of each image should show the values of $p$ and $\\lambda$ used to generate it.\n\\end{itemize}\n\n\\end{description}\n\n\\end{document}", "meta": {"hexsha": "1ec03f984c7a119838fb5d5ffa26ce8e8757c664", "size": 7991, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "projects/deblur/deblur.tex", "max_stars_repo_name": "snowdj/fnc-extras", "max_stars_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 109, "max_stars_repo_stars_event_min_datetime": "2018-04-21T09:02:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T19:03:54.000Z", "max_issues_repo_path": "projects/deblur/deblur.tex", "max_issues_repo_name": "snowdj/fnc-extras", "max_issues_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-12-04T22:17:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T21:04:47.000Z", "max_forks_repo_path": "projects/deblur/deblur.tex", "max_forks_repo_name": "snowdj/fnc-extras", "max_forks_repo_head_hexsha": "ef51fada748de1326a4ce645fbcb0c2499cb2b8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 49, "max_forks_repo_forks_event_min_datetime": "2017-04-02T17:21:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T17:19:57.000Z", "avg_line_length": 61.9457364341, "max_line_length": 587, "alphanum_fraction": 0.7204354899, "num_tokens": 2371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.8824278757303678, "lm_q1q2_score": 0.8006375983310667}}
{"text": "\\section{Cup product, continued}\nWe can construct an explicit map $S^p(X)\\otimes S^q(Y)\\xrightarrow{\\times} S^{p+q}(Y)$ via:\n\\begin{equation*}\n(f\\times g)(\\sigma)=f(\\sigma_1\\circ\\alpha_p)g(\\sigma_2\\circ\\omega_q)\n\\end{equation*}\nwhere $\\alpha_p:\\Delta^p\\to\\Delta^{p+q}$ takes $k\\mapsto k$ where $k\\in[p]$, and $\\omega_q:\\Delta^q\\to\\Delta^{p+q}$ sends $\\ell\\mapsto \\ell+p$ where $\\ell\\in[q]$.\n\nI would like to modify this definition a bit, and correct what I said. I think it's more natural to put a sign so that:\n\\begin{equation*}\n(f\\times g)(\\sigma)=(-1)^{pq}f(\\sigma_1\\circ\\alpha_p)g(\\sigma_2\\circ\\omega_q)\n\\end{equation*}\nYou'll see why we're adding the sign soon. The claim is that $\\times$ is a chain map, so we get a map $ H(S^p(X)\\otimes S^q(Y))\\to H_{p+q}(X\\times Y)$. There is a map $ H_p(X)\\otimes H_q(Y)\\xrightarrow{\\mu} H(S^p(X)\\otimes S^q(Y))$ defined as follows. Given chain complexes $C_\\bullet$ and $D_\\bullet$, define $\\mu: H(C_\\bullet)\\otimes H(D_\\bullet)\\to H(C_\\bullet\\otimes D_\\bullet)$. We've done this before, but let me just say: $\\mu:[x]\\otimes [y]\\mapsto [x\\otimes y]$. For some reason, he said that we'll not call this $\\mu$. But I don't want to delete the $\\mu$ so I'll just leave it there.\n\nWe get the cup product as follows. Given $\\Delta:X\\to X\\times X$, we get $\\cup: H_p(X)\\otimes H_q(X)\\to H_{p+q}(X\\times X)\\xrightarrow{\\Delta^\\ast} H_{p+q}(X)$. We proved that there was a class $1\\in H_0(X)=\\Map(\\pi_0(X),R)\\ni (\\alpha\\mapsto 1)$. This acts as a unit for the cup product. Also, the cup product is strictly associative.\n\\begin{definition}\nLet $R$ be a commutative ring. A \\emph{graded $R$-algebra} is a graded $R$-module $\\cdots,A_{-1},A_0, A_1,A_2,\\cdots$ (integer graded sequence) (some people take a direct sum, but I find no reason for doing that) with maps $A_p\\otimes_R A_q\\to A_{p+q}$ and a map $R\\to A_0$ (that determines the unit), that makes the following diagram commute.\n\\begin{equation*}\n\\xymatrix{\n\tA_p\\otimes_R (A_q\\otimes_R A_r)\\ar[r]\\ar[d] & A_p\\otimes_R A_{q+r}\\ar[d]\\\\\n\t(A_{p+q})\\otimes_R A_r \\ar[r] & A_{p+q+r}\n}\n\\end{equation*}\n\\end{definition}\n\\begin{definition}\nA graded $R$-algebra $A$ is said to be (graded) commutative id the following diagram commutes:\n\\begin{equation*}\n\\xymatrix{\n\tx\\otimes y\\ar@{|->}[rr] & & (-1)^{|x|\\cdot|y|}y\\otimes x\\\\\n\tA\\otimes A\\ar[rr]^{\\tau}\\ar[dr] & & A\\otimes A\\ar[dl]\\\\\n\t & A & \n}\n\\end{equation*}\n\\end{definition}\nWe claim that $ H_\\ast(X)$ forms a graded commutative ring under the cup product. This is nontrivial. On the cochain level, this is clearly not graded commutative. We're going to have to work hard -- in fact, so hard that you're going to do some of it for homework.\n\nWe'll do a chain level construction. I say there's a map $\\alpha:S_n(X\\times Y)\\to \\bigoplus_{p+q=n}S_p(X)\\otimes S_n(Y)$. First I'll tell you what happens to $n$-simplices $\\sigma:\\Delta^n\\to X\\times Y$. Let $\\sigma_1:\\Delta^n\\to X\\times Y\\to X$, and similarly for $\\sigma_2$. Define $S_n(X\\times Y)\\xrightarrow{\\alpha} \\bigoplus_{p+q=n}S_p(X)\\otimes S_n(Y)$ by sending:\n\\begin{equation*}\n\\sigma\\mapsto\\sum_{p+q=n}(\\sigma_1\\circ\\alpha_p)\\otimes(\\sigma_2\\otimes\\omega_q)\n\\end{equation*}\nWe claim that this is a chain map, and that this induces the cross product on cochains.\n\\begin{remark}\nThis map $\\alpha$ is called the Alexander-Whitney map.\n\\end{remark}\nIf I have two chain complexes, I want to consider a map $\\mu:\\Hom(C_\\bullet,R)\\otimes \\Hom(D_\\bullet,R)\\to \\Hom(C_\\bullet\\otimes D_\\bullet,R)$ given by $f\\otimes g\\mapsto(x\\otimes y\\mapsto (-1)^{pq}f(x)g(y))$ where $|f|=|x|=p$ and $|g|=|y|=q$. I haven't quite done the right thing here, have I? I have to write:\n\\begin{equation*}\nf\\otimes g\\mapsto\\begin{cases}\n(x\\otimes y\\mapsto (-1)^{pq}f(x)g(y)) & |x|=|f|=p, |y|=|g|=q\\\\\n0 & \\text{else}\n\\end{cases}\n\\end{equation*}\nYou should check that this is a chain map.\n\nRecall that we have: $S^p(X)\\otimes S^q(Y)=\\Hom(S_p(X),R)\\otimes_R \\Hom(S_q(Y),R)$. The map $\\mu$ we constructed just now gives a map $\\Hom(S_p(X),R)\\otimes_R \\Hom(S_q(Y),R)\\xrightarrow{\\mu}\\Hom(S_p(X)\\otimes S_q(Y),R)\\xrightarrow{\\alpha}\\Hom(S_{p+q}(X\\times Y),R)=S^{p+q}(X\\times Y)$. This is exactly the cross product $\\times:S^p(X)\\otimes S^q(Y)\\to S^{p+q}(X\\times Y)$.\n\nNow, $\\alpha$ is a natural transformation. Acyclic models comes into play. For homework, you're going to check that the following diagram commutes.\n\\begin{equation*}\n\\xymatrix{S_\\ast(X\\times Y)\\ar[r]^{T_\\ast}\\ar[d]_{\\alpha_{X,Y}} & S_\\ast(Y\\times X)\\ar[d]^{\\alpha_{Y,X}}\\\\\nS_\\ast(X)\\otimes_R S_\\ast(Y)\\ar[r]^{\\tau} & S_\\ast(Y)\\otimes_R S_\\ast(X)}\n\\end{equation*}\nAcyclic models helps us prove things like this.\n\nAll of this implies that $ H_\\ast(X;R)$ is graded commutative. It's a theorem that you can't find a commutative multiplication. This is where Steenrod operations come from. They're called cohomology operations, and we'll talk more about this in 18.906.\n\nMy goal is to compute the cohomology of some space.\n\\begin{prop}\n$ H^\\ast(X)\\otimes H^\\ast(Y)\\xrightarrow{\\times} H^\\ast(X\\times Y)$ is a $R$-algebra homomorphism.\n\\end{prop}\nIf $A$ and $B$ are graded $R$-algebras, then $(A\\otimes B)_n=\\bigoplus_{p+q=n}A_p\\otimes_R B_q$, and $(a\\otimes b)(a^\\prime\\otimes b^\\prime)=(-1)^{|a^\\prime|\\cdot|b|}aa^\\prime\\otimes bb^\\prime$. This tensor product is graded commutative if $A$ and $B$ are.\n\\begin{proof}\nI have $\\Delta_X:X\\to X\\times X$ and $\\Delta_Y:Y\\to Y\\times Y$. I also have $\\Delta_{X\\times Y}:X\\times Y\\to X\\times Y\\times X\\times Y$, which factors as $(1\\times T\\times 1)\\circ(\\Delta_X\\times \\Delta_Y)$. Let $\\alpha_1,\\alpha_2\\in H^\\ast(X)$ and $\\beta_1,\\beta_2\\in H^\\ast(Y)$. Then $\\alpha_1\\times \\beta_1,\\alpha_2\\times\\beta_2\\in H^\\ast(X\\times Y)$. I want to calculate what $(\\alpha_1\\times\\beta_1)\\cup(\\alpha_2\\times\\beta_2)$ is. Let's see:\n\\begin{align*}\n(\\alpha_1\\times\\beta_1)\\cup(\\alpha_2\\times\\beta_2) & = \\Delta_{X\\times Y}^\\ast(\\alpha_1\\times\\beta_1\\times\\alpha_2\\times\\beta_2)\\\\\n& = (\\Delta_X\\times\\Delta_Y)^\\ast(1\\times T\\times 1)^\\ast(\\alpha_1\\times\\beta_1\\times\\alpha_2\\times\\beta_2)\\\\\n& = (\\Delta_X\\times\\Delta_Y)^\\ast(\\alpha_1\\times T^\\ast(\\beta_1\\times\\alpha_2)\\times\\beta_2)\\\\\n& = (-1)^{|\\alpha_2|\\cdot|\\beta_1|}(\\Delta_X\\times\\Delta_Y)^\\ast(\\alpha_1\\times\\alpha_2\\times\\beta_1\\times\\beta_2)\n\\end{align*}\nNow, I have a diagram:\n\\begin{equation*}\n\\xymatrix{\n\t H^\\ast(X\\times Y) & \\ar[l]^{\\times_{X\\times Y}} H^\\ast(X)\\otimes_R H^\\ast(Y)\\\\\n\t H^\\ast(X\\times X\\times Y\\times Y)\\ar[u]^{(\\Delta_X\\times\\Delta_Y)^\\ast} & H^\\ast(X\\times X)\\otimes H^\\ast(Y\\times Y)\\ar[l]_{\\times_{X\\times X,Y\\times Y}}\\ar[u]^{\\Delta_X^\\times\\otimes\\Delta_Y^\\ast}\n}\n\\end{equation*}\nThis diagram commutes because the cross product is natural. This is exactly what commutativity of the diagram means. This means that:\n\\begin{align*}\n(\\alpha_1\\times\\beta_1)\\cup(\\alpha_2\\times\\beta_2) & = (-1)^{|\\alpha_2|\\cdot|\\beta_1|}(\\Delta_X\\times\\Delta_Y)^\\ast(\\alpha_1\\times\\alpha_2\\times\\beta_1\\times\\beta_2)\\\\\n& = (-1)^{|\\alpha_2|\\cdot|\\beta_1|}(\\alpha_1\\cup\\alpha_2)\\times(\\beta_1\\cup\\beta_2)\n\\end{align*}\nThat's exactly what we wanted.\n\\end{proof}\n\\begin{example}\nHow about $ H^\\ast(S^p)$? Let $p>0$. This is: $ H^k(S_p) = \\begin{cases}\\Z & k=0,p\\\\ 0 & \\text{else}\\end{cases}$. Say that $\\sigma_p$ generates $ H^p(S^p)$. We now have $ H^\\ast(S^p)\\otimes H^\\ast(S^q)\\to H^\\ast(S^p\\times S^q)$. From the K\\\"unneth theorem, we know that $ H^k(S^p\\times S^q)=\\begin{cases}\\Z & k=0,p,q,p+q\\\\ 0 & \\text{else}\\end{cases}$. This structure $ H^\\ast(S^p)\\otimes H^\\ast(S^q)\\cong\\Z[\\sigma_p,\\sigma_q]/(\\sigma_p^2,\\sigma_q^2)\\cong H^\\ast(S^p\\times S^q)$ where $\\sigma_p\\sigma_q=(-1)^{|p|\\cdot|q|}\\sigma_q\\sigma_p$ where by $\\Z[\\sigma_p,\\sigma_q]$ I mean the free $\\Z$-algebra on $\\sigma_p,\\sigma_q$. When $p=q=1$, this gives an exterior algebra.\n\\end{example}\nThis is to be contrasted with $X=S^p\\vee S^q\\vee S^{p+q}$. This has the same homology as the product of two spheres. But in cohomology, the product of the generators must be zero. There is a diagram:\n\\begin{equation*}\n\\xymatrix{\n\tX\\ar[r] & S^p\\vee S^q\\\\\n\tS^p\\ar@{^(->}[u]\n}\n\\end{equation*}\nOn cohomology, notice that $\\sigma_p\\sigma_q=0$ in $ H^\\ast(S^p\\vee S^q)$ because there's no $(p+q)$-dimensional cohomology. Therefore we find that $S^p\\vee S^q\\vee S^{p+q}\\not\\simeq S^p\\times S^q$.\n\nIt's very interesting to think about what the attaching map is:\n\\begin{equation*}\n\\xymatrix{\n\tS^{p+q-1}\\ar[r]\\ar[d] & S^p\\vee S^q\\ar[d]\\\\\n\tD^{p+q}\\ar[r] & S^p\\times S^q\n}\n\\end{equation*}\nOn Wednesday we'll have a relaxed talk about surfaces. BTW I might not TeX that.\n", "meta": {"hexsha": "28f44e2d39040130bad9ac75e4ecf6a0357561af", "size": 8519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-29-cup-products-contd.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "old-905/lec-29-cup-products-contd.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "old-905/lec-29-cup-products-contd.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 76.7477477477, "max_line_length": 669, "alphanum_fraction": 0.6871698556, "num_tokens": 3205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.8824278556326344, "lm_q1q2_score": 0.8006375712497071}}
{"text": "\\documentclass{article}\n\\usepackage[section]{placeins}\n\\usepackage{graphicx, wrapfig, amsmath, amssymb, physics, hyperref, mathtools}\n\\hypersetup{\n    colorlinks=true,\n    linkcolor=blue,\n    filecolor=magenta,      \n    urlcolor=cyan,\n    }\n\n\\author{Yaghoub Shahmari}\n\\title{Report - Problem Set No 6}\n\\date{\\today}\n\\graphicspath{ {../Figs/} }\n\n\\begin{document}\n    \\maketitle\n    \\section{RC circuit equation}\n    \\textbf{Basic description:}\n\n    In an RC circuit, the amount of electric charge passing through the circuit is as follows:\n\n    $$R \\frac{d q}{d t}+\\frac{q}{C}=V_0 \\Rightarrow \\dot{q} = \\frac{V_0}{R} - \\frac{q}{RC}  \\xRightarrow[q_{(0)} = 0]{q_0 \\coloneqq V C} q_{(t)}=q_0 (1-e^{-t/RC})$$\n\n    where C, V, and R are the potential difference, capacitor capacity, and circuit resistance, respectively.\n    \n    I have solved this equation with RK1(Euler), RK2, and RK4 methods. Below you can see the results next to the exact answer:\n\n    \\textbf{The results:}\n\n    \\begin{figure}[!htb]\n        \\centering\n        \\includegraphics[scale = 0.25]{/Q1/RCEu}\n        \\label{fig:1.1}\n        \\includegraphics[scale = 0.25]{/Q1/RKComp}\n        \\label{fig:1.2}\n        \\caption{Plot of the results of the mentioned methods.}\n    \\end{figure}\n\n    \\pagebreak\n\n    And at last, we want to find and analyze the effect of $\\Delta t$ in the amount of global error for each method.\n    We calculated the global error for a range of $\\Delta t$ and drew the results in the following graph:\n\n    \\begin{figure}[!htb]\n        \\centering\n        \\includegraphics[scale = 0.3]{/Q1/error}\n        \\label{fig:1.3}\n        \\caption{Plot of the global error for each $\\Delta t$.}\n    \\end{figure}\n\n    To show the effect of floating-point error,\n    I exported data in two types of float16 and float64.\n    For float64 we can't find floating-point error well but in float16 type,\n    it is easier to find the effect.\n\n    As the final part of this section, we will solve the above equation with an unstable method presented in class. The results are as follow:\n\n    \\begin{figure}[!htb]\n        \\centering\n        \\includegraphics[scale = 0.5]{/Q1/Instability}\n        \\label{fig:1.4}\n        \\caption{Plot of the results of the mentioned method and the exact answer.}\n    \\end{figure}\n\n    \\section{Simple Harmonic Osillation}\n    \\textbf{Basic description:}\n    \n    In this section, we want to solve the second-order equation of simple harmonic oscillation using numerical methods.\n    The oscillator follows this equation:\n\n    $$\n    \\ddot{x} = -\\omega x \\Rightarrow\n    \\begin{cases}\n        x(t) = x_0\\cos(\\omega t) \\\\\n        v(t) = x_0\\omega\\sin(\\omega t)\n    \\end{cases}\n    $$\n\n    which the $\\omega$ is angular velocity and $x_0$ is the initial position.\n\n    \\begin{figure}[!htb]\n        \\centering\n        \\includegraphics[scale = 0.3]{/Q2/SHO}\n        \\label{fig:2.1}\n        \\caption{Plot of the numerical solution for each method and the exact answer for simple harmonic oscillation.}\n    \\end{figure}\n\n    As you can see, the RK4 method has the best accuracy among the other methods.\n    Also, it is obvious that RK1 and RK2 methods are unstable and do not follow the energy conservation.\n\n    As the final part of this section,\n    we drew the phase diagram of oscillation.\n\n    \\begin{figure}[!htb]\n        \\centering\n        \\includegraphics[scale = 0.3]{/Q2/Phase}\n        \\label{fig:2.2}\n        \\caption{Phase diagram of the oscillation.}\n    \\end{figure}\n\n    In this section as well, we can see the energy conservation for each method and we can see that RK1 and RK2 methods do not follow that.\n\n    \\section{Logistic Map and bifurcations}\n    \\textbf{Basic description:}\n    \n    For this section, I wrote a code that creates a standard logistic map,\n    finds bifurcation points, and exports their data.\n    Then, find the wanted constant using exported data.\n\n    \\textbf{The results:}\n\n    \\begin{figure}[!htb]\n        \\centering\n        \\includegraphics[scale = 0.4]{/Q3/logmap.jpg}\n        \\label{fig:3.1}\n        \\includegraphics[scale = 0.4]{/Q3/R-N}\n        \\label{fig:3.2}\n        \\caption{Logistic Map diagram and bifurcation points.}\n    \\end{figure}\n\n    Calculated constants:\n    $$\\delta = 4.6316,\\ \\alpha = 2.7143$$(take a look at the notebooks)\n\n    \\pagebreak\n\n    \\centering\n    \\textbf{The whole data I gathered is in \\href{https://github.com/shahmari/ComputationalPhysics-Fall2021/tree/main/ProblemSet7/Data}{this link}}\n\n    Thanks for watching :)\n\\end{document}", "meta": {"hexsha": "83afbe57b1fff2ada6ef8e6cc76fd8776254889f", "size": 4502, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ProblemSet9/TEXfiles/report.tex", "max_stars_repo_name": "shahmari/ComputationalPhysics-Fall2021", "max_stars_repo_head_hexsha": "f1681e32258c55697d11009e1702eb86d5f119d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ProblemSet9/TEXfiles/report.tex", "max_issues_repo_name": "shahmari/ComputationalPhysics-Fall2021", "max_issues_repo_head_hexsha": "f1681e32258c55697d11009e1702eb86d5f119d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ProblemSet9/TEXfiles/report.tex", "max_forks_repo_name": "shahmari/ComputationalPhysics-Fall2021", "max_forks_repo_head_hexsha": "f1681e32258c55697d11009e1702eb86d5f119d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-10-21T11:07:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-21T11:07:08.000Z", "avg_line_length": 34.3664122137, "max_line_length": 164, "alphanum_fraction": 0.6639271435, "num_tokens": 1288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.8933094159957173, "lm_q1q2_score": 0.800629783292832}}
{"text": "\\chapter{Introduction to partitions}\n\n\n\n\\section{Background}\n\nA partition of a positive integer $n$ is a way of writing $n$ as the sum of positive integers. Two sums that differ only in the order of their summands are considered the same partition. The notation $\\lambda \\vdash n$ means that $\\lambda$ is a partition of $n$. \n\nA summand in a partition is also called a part. The length of a partition refers to the number of parts in the partition and is denoted by $n(\\lambda)$ for a partition $\\lambda$. Its largest part, is denoted by $l(\\lambda)$. As an example, 4 can be partitions in five distinct ways as follows\n\\begin{align*}\n4 &= 4\n  \\\\&= 3 + 1 = 2 + 2 \n  \\\\&= 2 + 1 + 1 \n  \\\\&= 1 + 1 + 1 + 1.\n\\end{align*}\n\nWhere, $n((2,1,1)) = 3$ and $l((2,1,1)) = 2$.\n\\newpage\n\n\\section{Definitions and Terminology}\n\\subsection{$q$-Pochhammer Symbol}\n\nThe $q$-Pochhammer symbol is defined as\n\n\\begin{equation*}\n    (a)_0 := (a;q)_0 := 1, \\quad (a; q)_n := \\prod_{k=0}^{n-1} (1- aq^k) \\quad n \\geq 1,\n\\end{equation*}\n\\begin{equation*}\n    (a)_\\infty := (a;q)_\\infty := \\prod_{k=0}^{\\infty} (1- aq^k) \\quad |q| < 1.\n\\end{equation*}\nIf the identification of $q$ is clear, we omit $q$ from the notation.\nWe state several basic identities used for simplification later as mentioned in [5].\n\\begin{equation}\n    (q^a;q^b)_\\infty(-q^a;q^b)_\\infty = (q^{2a};q^{2b})_\\infty\n\\end{equation}\n\\begin{equation}\n    (cq^a;q^{2b})_\\infty(cq^{a+b};q^{2b})_\\infty = (cq^a;q^b)_\\infty\n\\end{equation}\nWe will be using the following shorthand notations throughout the report and are also used in [1, 18, 19]:\n\\begin{equation*}\n    (a_1,...,a_k;q)_n := (a_1,q)_n...(a_k;q)_n\n\\end{equation*}\n\\begin{equation*}\n    J_b := (q^b;q^b)_\\infty\n\\end{equation*}\n\\begin{equation*}\n    J_{a,b} := (q^a,q^{b-a},q^b;q^b)_\\infty\n\\end{equation*}\n\\begin{equation*}\n    \\chi(q) := (-q;q^2)_\\infty\n\\end{equation*}\n\\subsection{Ramanujan's General Theta Function}\nThe famous Ramanujan's Theta function used in various proofs is as follows:\n\\begin{equation}\n    f(a, b) := \\sum_{n = -\\infty}^\\infty a^{n(n+1)/2}b^{n(n-1)/2}, \\quad |ab| < 1.\n\\end{equation}\nSome shorthand related to the above generating functions will be used as [5]\n\\begin{align*}\n    \\varphi(q) &:= f(q,q) = (-q,-q,q^2;q^2)_\\infty,\n    \\\\ \\psi(q) &:= f(q,q^3) = \\frac{(q^2;q^2)_\\infty}{(q;q^2)_\\infty}.\n\\end{align*}\n\n\\subsection{Definitions Relating to Partitions}\n\\subsubsection{Partition Functions}\nIf $n$ is a positive integer, let $p(n)$ denote the number of unrestricted representations of $n$ as a sum of positive integers, where representations with different orders of the same summands are not regarded as distinct. We call $p(n)$ the partition function. We further use the notation $p_m(n)$ to denote the number of partitions of $n$ into parts that are no larger than $m$.\n\nIn general for a set $S$, $p(S, m, n)$ denotes the number of partitions of $n$ into exactly $m$ parts of $S$. Furthermore, we denote $p(m,n)$ as the number of partitions of $n$ into exactly $m$ parts.\n\nWe denote $Q(n)$ as the number of partitions into distinct parts. More generally, $Q( S, m, n)$ denotes the number of partitions of $n$ into $m$ distinct parts of $S$. Similarly $Q( m, n )$ is the number of partitions of $n$ into exactly $m$ distinct parts.\n\n\\subsubsection{Overpartitions}\nAn overpartition of $n$ is a partition of $n$ in which the first occurrence of a number may be over-lined. For example, the over partitions of 3 are:\n\\begin{align*}\n      \\{ 3, \\overline 3\n    , 2 + 1 , 2 + \\overline 1 , \\overline 2 + 1 , \\overline 2 + \\overline 1  \n    , 1 + 1 + 1 , \\overline 1 + 1 + 1 \\}\n\\end{align*}\n\nThe number of overpartitions of $n$ is denoted by $\\overline p(n)$. This results in\n    $$\\overline p(n) = \\sum_{n_1 + n _2 = n} p(n_1)*Q(n_2)$$\n\nwhich is a discrete convolution between $p$ and $Q$, giving us $\\overline p = p*Q$. Analogous to Dyson's rank function definitions for partitions we have $\\overline N(s, n)$ and $\\overline N(s, m, n)$ for overpartitions.\n\n\\subsection{Generating Functions}\nThe term generating function is used to describe an infinite sequence of numbers $(a_n)$ by treating them as the coefficients of a series expansion. This infinite series is the generating function.\n\nThe generating function for the partition function $p(n)$ is represented as\n\\begin{align*}\n\\sum_{n=0}^\\infty p(n)q^n\n&= \\sum_{n_i \\geq 0}q^{1n_1 + 2n_2 + \\dots + kn_k + \\dots}\\\\\n&= \\frac{1}{1-q} \\frac{1}{1-q^2} \\dots \\frac{1}{1-q^k} \\dots\\\\\n&= \\frac{1}{\\prod_{k=0}^\\infty (1-qq^k)}\\\\\n&= \\frac{1}{(q;q)_\\infty}\n\\end{align*}\n\\newpage\nFor general partition functions, we get\n\\begin{align*}\n\\sum_{n=0}^\\infty \\sum_{m=0}^\\infty p( S, m, n )z^mq^n &= \\prod_{k \\epsilon S} \\frac{1}{1-zq^k},\\\\\n\\sum_{n=0}^\\infty \\sum_{m=0}^\\infty Q( S, m, n )z^mq^n &= \\prod_{k \\epsilon S} (1+zq^k).\n\\end{align*}\n\nThe generating function for overpartitions,  $\\sum_{n=0}^\\infty \\overline p(n)q^n$ is the product of general partitions and that for partitions with distinct parts as it is given by their convolution. Therefore,\n\\begin{align*}\n\\sum_{n=0}^\\infty \\overline p(n)q^n = \\frac{(-q;q)_\\infty}{(q;q)_\\infty}\n\\end{align*}\n\n\n", "meta": {"hexsha": "4c938b93fc8ad9cfc8e6732cd22fca36f8f621e9", "size": 5124, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter1.tex", "max_stars_repo_name": "Cheran-Senthil/BTP-Project", "max_stars_repo_head_hexsha": "93092556037234df1e2590f47c718a317cd40b96", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-29T04:25:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-29T04:25:43.000Z", "max_issues_repo_path": "chapter1.tex", "max_issues_repo_name": "Cheran-Senthil/BTP-Project", "max_issues_repo_head_hexsha": "93092556037234df1e2590f47c718a317cd40b96", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter1.tex", "max_forks_repo_name": "Cheran-Senthil/BTP-Project", "max_forks_repo_head_hexsha": "93092556037234df1e2590f47c718a317cd40b96", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-02-10T04:54:36.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-10T04:54:36.000Z", "avg_line_length": 47.4444444444, "max_line_length": 381, "alphanum_fraction": 0.6711553474, "num_tokens": 1806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.8962513800615312, "lm_q1q2_score": 0.8006297778153385}}
{"text": "\\appendix\n\\section{Appendix}\n%\\pagenumbering{roman}\n\\subsection{Deriving the approximate expression of 2SLS Bias}\nThis derivation has been adopted from \\cite{results}. Start with the representation of the 2SLS estimator as shown in equation (2.8).\n\\begin{equation}\n\\hat{\\beta }_{2SLS}=(\\textbf{X}'P_{Z}\\textbf{X})^{-1}\\textbf{X}'P_{Z}\\textbf{Y}=\\beta+(\\textbf{X}'P_{Z}\\textbf{X})^{-1}\\textbf{X}'P_{Z}\\varepsilon\n\\end{equation}\nwhere $P_{Z}=\\textbf{Z}(\\textbf{Z}'\\textbf{Z})^{-1}\\textbf{Z}'$ is the projection matrix.\nSo the bias of $\\hat{\\beta }_{2SLS}$ will be\n\\begin{equation}\n\\hat{\\beta }_{2SLS}-\\beta = (\\textbf{X}'P_{Z}\\textbf{X})^{-1}(\\pi'\\textbf{Z}'+\\eta')P_{Z}\\varepsilon\n                          = (\\textbf{X}'P_{Z}\\textbf{X})^{-1}\\pi'\\textbf{Z}'\\varepsilon +(\\textbf{X}'P_{Z}\\textbf{X})^{-1}\\eta' P_{Z}\\varepsilon\n\\end{equation}\nUsing group asymptotics the expectation of this expression can presented as:\n\\begin{equation}\n    E[\\hat{\\beta }_{2SLS}-\\beta ]\\approx (E[{\\textbf{X}}'P_{Z}\\textbf{X}])^{-1}E[{\\pi}'{\\textbf{Z}}'\\varepsilon ]+(E[{\\textbf{X}}'P_{Z}\\textbf{X}])^{-1}E[{\\eta }'P_{Z}\\varepsilon ]\n\\end{equation}\n$Z_{i}$ instruments are uncorrelated with $\\varepsilon_{i}$ and $\\eta_{i}$, so $E[{\\pi }'{\\textbf{Z}}'\\varepsilon ]=0 $ and we will have\n\\begin{equation}\n    E[\\hat{\\beta }_{2SLS}-\\beta ]\\approx (E[{\\textbf{X}}'P_{Z}\\textbf{X}])^{-1}E[{\\pi}'{\\textbf{Z}}'\\varepsilon ]+(E[{\\textbf{X}}'P_{Z}\\textbf{X}])^{-1}E[{\\eta }'P_{Z}\\varepsilon ]=(E[{\\textbf{X}}'P_{Z}\\textbf{X}])^{-1}E[{\\eta }'P_{Z}\\varepsilon]\n\\end{equation}\nSubstituting the first stage equation $\\textbf{X}=\\textbf{Z}\\pi +\\eta$ we have\n\\begin{equation}\nE[\\hat{\\beta }_{2SLS}-\\beta ]\\approx (E[({\\pi }'{\\textbf{Z}}'+{\\eta }')P_{Z}(\\textbf{Z}\\pi +\\eta )])^{-1}E[{\\eta }'P_{Z}\\varepsilon ]\n\\end{equation}\nWe have that $E[{\\pi }'{\\textbf{Z}}'\\eta ]=0 $, so\n\\begin{equation}\n    E[\\hat{\\beta }_{2SLS}-\\beta ]\\approx[E({\\pi }'{\\textbf{Z}}'\\textbf{Z}\\pi )+E({\\eta }'P_{Z}\\eta )]^{-1}E({\\eta }'P_{Z}\\varepsilon )\n\\end{equation}\nNotice that ${\\eta }'P_{Z}\\eta$ is a scalar and is equal to its trace. $P_{Z}$ is an idempotent matrix, so its trace is equal to its rank, Q. So\n\\begin{equation}\n    E({\\eta }'P_{Z}\\eta)=E[tr({\\eta }'P_{Z}\\eta)]=E[tr(P_{Z}\\eta{\\eta }')]=tr(P_{Z}E[\\eta{\\eta }'])=tr(P_{Z}\\sigma _{\\eta }^{2}I)=\\sigma _{\\eta }^{2}tr(P_{Z})=\\sigma _{\\eta }^{2}Q\n\\end{equation}\nWith a similar technique we can show that  $E({\\eta }'P_{Z}\\varepsilon)$ is equal to $\\sigma _{\\varepsilon \\eta }Q$.\nSubstituting these results in equation (A.6) we have\n\\begin{equation}\n   E[\\hat{\\beta }_{2SLS}-\\beta]\\approx\\sigma _{\\varepsilon \\eta }Q[E({\\pi }'{\\textbf{Z}}'\\textbf{Z}\\pi )+\\sigma _{\\eta }^{2}Q]^{-1}=\\frac{\\sigma_{\\varepsilon\\eta }}{\\sigma  _{\\eta }^{2}}[\\frac{E(\\pi'\\textbf{Z}'\\textbf{Z}\\pi)/Q}{\\sigma _{\\eta }^{2}}+1]^{-1}\n\\end{equation}\nThe population F-statistic for the first stage regression is the following\n\\begin{equation}\n    F=\\frac{E(\\pi'\\textbf{Z}'\\textbf{Z}\\pi)/Q}{\\sigma _{\\eta }^{2}}\n    \\end{equation}\nSo (A.8) can be expressed as\n\\begin{equation}\n    E[\\hat{\\beta }_{2SLS}-\\beta]\\approx \\frac{\\sigma_{\\varepsilon\\eta }}{\\sigma  _{\\eta }^{2}}\\frac{1}{F+1}\n\\end{equation}\n\nAssume that the ${\\pi}$ coefficients are zero and $F=0$. In this case $\\sigma_{X}^{2}=\\sigma_{\\eta }^{2}$ and\n\\begin{equation}\n    E[\\hat{\\beta }_{2SLS}-\\beta]\\approx \\frac{\\sigma_{\\varepsilon\\eta }}{\\sigma  _{X}^{2}}\n\\end{equation}\n\nThus, when $\\pi\\neq 0$ and F is small, then 2SLS will be biased towards OLS. \n\nNote that $\\frac{\\sigma_{\\varepsilon\\eta }}{\\sigma  _{X}^{2}}$ is also the bias of OLS estimator, because when $\\pi=0$, $cov(\\varepsilon _{i},X_{i})=\\sigma _{\\eta \\varepsilon }$ and\n\\begin{equation}\n    \\beta _{OLS} = \\frac{cov(Y_{i},X_{i})}{var(X_{i})} = \\frac{cov(\\beta X_{i}+\\varepsilon  _{i},X_{i})}{var(X_{i})} = \\beta + \\frac{cov(\\varepsilon  _{i},X_{i})}{var(X_{i})} = \\frac{\\sigma _{\\varepsilon \\eta }}{\\sigma _{X}^{2}}\n\\end{equation}\nHence in this case OLS and 2SLS estimators on average are the same. And if $\\pi$ is different from zero, $\\hat{\\beta }_{2SLS}$ will be biased in the direction of OLS estimator. If we add weak instruments to the regression bias of 2SLS will only increase. \\\\\n\n\\newpage\n\n\n", "meta": {"hexsha": "562d0cba8170f860e29212f0d580c9a5989b013d", "size": 4200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendix.tex", "max_stars_repo_name": "mchandra12/research_module_econometrics", "max_stars_repo_head_hexsha": "2e65411b69d6924495c5e321857b64d06f1ce7ff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "appendix.tex", "max_issues_repo_name": "mchandra12/research_module_econometrics", "max_issues_repo_head_hexsha": "2e65411b69d6924495c5e321857b64d06f1ce7ff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "appendix.tex", "max_forks_repo_name": "mchandra12/research_module_econometrics", "max_forks_repo_head_hexsha": "2e65411b69d6924495c5e321857b64d06f1ce7ff", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.6153846154, "max_line_length": 257, "alphanum_fraction": 0.6338095238, "num_tokens": 1705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.8962513793687401, "lm_q1q2_score": 0.8006297771964618}}
{"text": "\\chapter{Axiomatic Construction of Rooted Trees}\n\nHere is one way of considering rooted trees. We start with a set $N$, whose\nelements we call \\emph{nodes}.  We'll assume that $N \\neq \\emptyset$, because\nempty trees are not very interesting. Then we introduce an irreflexive,\nantisymmetric relation on $N$, noted $<$:\n\\begin{align}\nn \\nless n & & \\forall \\; n \\in N & & \\text{irreflexivity} \\\\\nm < n \\Rightarrow n \\nless m &  & \\forall \\; m, n \\in N & &  \\text{antisymmetry}\n\\end{align}\nIn other words, $<$ is a binary relation on $N$ such that no node is\nrelated to itself, and if node $n$ is related to $m$, then $m$ is \\emph{not}\nrelated to $n$. If $m < n$, we say that $m$ is a \\emph{parent} of $n$.\n\nNow we introduce axioms that produce rooted trees.\n\\begin{axiom}\nThere exists a node that has no parent:\n\\[ \\exists \\; r \\in N \\; | \\; n \\nless r \\qquad \\forall \\; n \\in N \\]\n\\end{axiom}\n\n\\begin{axiom}\nThere is only one node that has no parent. Let $S = \\{x \\in N\\,|\\, n \\nless x \\; \\forall \\; n \\in N \\}$ be the set of parent-less nodes of $N$. Then:\n\\[ r, s \\in S \\quad \\Rightarrow \\quad r = s \\qquad \\forall \\;r, s \\in N \\]\n\\end{axiom} \n\nThe unique parent-less node of $N$ is called the \\emph{root}.\n\n\\begin{axiom}\nEvery node except the root has a parent.\n\\end{axiom} \n\n\\begin{axiom}\nNo node has more than one parent.\n\\end{axiom} \n\nWe can now speak of \\emph{the} parent of node $n$ (unless $n$ is the root), and we will note it $\\mathrm{par}(n)$.\n", "meta": {"hexsha": "08c94d691ccc14f668c35ef199dd221980c70d24", "size": 1455, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tree_axioms.tex", "max_stars_repo_name": "Cactusolo/newick_utils", "max_stars_repo_head_hexsha": "da121155a977197cab9fbb15953ca1b40b11eb87", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2015-01-08T22:22:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T09:12:51.000Z", "max_issues_repo_path": "doc/tree_axioms.tex", "max_issues_repo_name": "Cactusolo/newick_utils", "max_issues_repo_head_hexsha": "da121155a977197cab9fbb15953ca1b40b11eb87", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 24, "max_issues_repo_issues_event_min_datetime": "2015-01-22T19:34:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-27T10:53:41.000Z", "max_forks_repo_path": "doc/tree_axioms.tex", "max_forks_repo_name": "Cactusolo/newick_utils", "max_forks_repo_head_hexsha": "da121155a977197cab9fbb15953ca1b40b11eb87", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-05-07T09:23:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T02:43:50.000Z", "avg_line_length": 39.3243243243, "max_line_length": 149, "alphanum_fraction": 0.6639175258, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750360641185, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.8004974321404349}}
{"text": "\\section{Definite Integrals \\& Antiderivatives}\r\n\r\n\\subsection{Definition of a Definite Integral}\r\nWe saw several approximations for the areas under any type of curve.\r\nWe also saw how these approximations get better the narrower our ``strips''.\r\nIn the limit, we get exactly the area under the curve, which defines the definite integral.\r\n\r\n\\begin{definition}\r\n\tLet $f$ be continuous on the closed interval $[a,b]$.\r\n\tLet this interval be partitioned into $n$ equal\\footnote{Technically, the intervals don't need to be of equal size, as long as the width of all intervals goes to 0 in the limit.} sub-intervals, each of length $\\Delta x = \\frac{b-a}{n}$.\r\n\tThe definite integral of $f$ over $[a,b]$ is given by\r\n\t\\begin{equation*}\r\n\t\t\\int_{a}^{b}{f(x)\\mathrm{d}x} = \\lim_{n\\to \\infty}{\\sum_{k=0}^{n-1}{f(c_k)\\Delta x}}\r\n\t\\end{equation*}\r\n\twhere $c_k$ is any arbitrary value in the $k$th sub-interval.\r\n\tThis particular type of limit of a sum is called a Riemann Sum.\r\n\\end{definition}\r\n\r\nNote that the left, right, and midpoint approximations are all different ways of choosing $c_i$, all of which in the limit give the area under the curve and definite integral from $a$ to $b$.\r\n\r\n\\begin{example}\r\n\tFind the value of the following definite integral using Riemann sums.\r\n\t\\begin{equation*}\r\n\t\t\\int_{0}^{1}{x^2\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe'll use a Riemann sum with a left-endpoint approximation.\r\n\t\\begin{align*}\r\n\t\t\\int_{0}^{1}{x^2\\d{x}} &= \\lim_{n\\to\\infty}{\\sum_{k=0}^{n-1}{f\\left(0+\\frac{k}{n}\\right)\\frac{1-0}{n}}} \\\\\r\n\t\t&= \\lim_{n\\to\\infty}{\\sum_{k=0}^{n-1}{\\left(\\frac{k}{n}\\right)^2\\frac{1}{n}}} \\\\\r\n\t\t&= \\lim_{n\\to\\infty}{\\sum_{k=0}^{n-1}{\\frac{k^2}{n^3}}} \\\\\r\n\t\t&= \\lim_{n \\to \\infty}{\\frac{1}{n^3}\\left(\\frac{n(n-1)(2n-1)}{6}\\right)} \\\\\r\n\t\t&= \\lim_{n\\to\\infty}{\\frac{1}{6}\\left(2-\\frac{3}{n}+\\frac{1}{n^2}\\right)} \\\\\r\n\t\t&= \\frac{1}{3}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\r\nNote that area below the $x$-axis is counted as negative area.\r\nIn general\r\n\\begin{equation*}\r\n\t\\int_{a}^{b}{f(x)\\d{x}} = \\text{ area above $x$-axis } - \\text{ area below $x$-axis}.\r\n\\end{equation*}\r\n\r\n\\subsection{Basic Properties of Definite Integrals}\r\nThe following are properties of definite integrals.\r\nMany should look familiar from properties of limits and derivatives.\r\nLet $f$ and $g$ be continuous functions of $x$.\r\nLet $a$, $b$, and $c$ be real constants where $a \\neq b$.\r\nLet $f_{[a,b]}$ be the values of $f$ on the interval $[a,b]$.\r\n\\begin{align*}\r\n\t\\textbf{Order of Integration Rule: }& \\int_{a}^{b}{f(x)\\d{x}} = -\\int_{b}^{a}{f(x)\\d{x}} \\\\\r\n\t\\textbf{Sum and Difference Rule: }& \\int_{a}^{b}{(f(x) \\pm g(x))\\d{x}} = \\int_{a}^{b}{f(x)\\d{x}} \\pm \\int_{a}^{b}{g(x)\\d{x}} \\\\\r\n\t\\textbf{Zero Rule: }& \\int_{a}^{a}{f(x)\\d{x}} = 0 \\\\\r\n\t\\textbf{Constant Multiple Rule: }& \\int_{a}^{b}{cf(x)\\d{x}} = c\\int_{a}^{b}{f(x)\\d{x}} \\\\\r\n\t\\textbf{Additivity Rule: }& \\int_{a}^{b}{f(x)\\d{x}} + \\int_{b}^{c}{f(x)\\d{x}} = \\int_{a}^{c}{f(x)\\d{x}} \\\\\r\n\t\\textbf{Max-Min Rule: }& (b-a)\\min{f_{[a,b]}} \\leq \\int_{a}^{b}{f(x)\\d{x}} \\leq (b-a)\\max{f_{[a,b]}} \\\\\r\n\t\\textbf{Domination Rule: }& \\min{f_{[a,b]}} \\geq \\max{g_{[a,b]}} \\implies \\int_{a}^{b}{f(x)\\d{x}} \\geq \\int_{a}^{b}{g(x)\\d{x}}.\r\n\\end{align*}\r\n\r\n\\subsubsection{Mean Value Theorem for Definite Integrals}\r\nThe mean value of $f$ over the interval $[a,b]$ is given by\r\n\\begin{equation*}\r\n\t\\frac{1}{b-a}\\int_{a}^{b}{f(x)\\d{x}}.\r\n\\end{equation*}\r\nYou can effectively think of this as the definition of the average: adding up all the values and dividing by the number of values.\r\nThis is exactly what happens if you work through the Riemann sums.\r\nMuch like the Mean Value Theorem for Derivatives, since the function is continuous, it will take on its average value somewhere in the interval.\r\n\\begin{theorem}[Mean Value Theorem for Definite Integrals]\r\n\tIf $f$ is continuous on the interval $[a,b]$, then there is some point $c$ in the interval such that\r\n\t\\begin{equation*}\r\n\t\tf(c) = \\frac{1}{b-a}\\int_{a}^{b}{f(x)\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{theorem}\r\n\r\n\\begin{figure}[H]\r\n\t\\label{mvt_integrals}\r\n\t\\centering\r\n\t\\includegraphics[width = 0.33\\textwidth]{./integrals/mvt.png}\r\n\t\\caption{A continuous function always takes on its mean value}\r\n\\end{figure}\r\n\r\n\\begin{example}\r\n\tA plane's airspeed is given by $v(t) = t/8\\text{, }t\\geq 0$.\r\n\tWhat what time $t$ does the Mean Value Theorem guarantee that the plane's speed was 1?\r\n\tWhen is this time?\r\n\\end{example}\r\n\\begin{answer}\r\n\tRather than go through the trouble of evaluating a limit to find the definite integral, we can notice that the graph of the plane's airspeed is a triangle, which we know how to find the area of geometrically.\r\n\t\\begin{equation*}\r\n\t\t\\text{Area}(t) = \\frac{1}{2}t v(t).\r\n\t\\end{equation*}\r\n\t\r\n\tDividing by the length of the interval to get the average airspeed,\r\n\t\\begin{equation*}\r\n\t\t\\text{Avg}(t) = \\frac{1}{t-0}\\hspace{3pt}\\frac{1}{2}tv(t) = \\frac{1}{2}v(t).\r\n\t\\end{equation*}\r\n\t\r\n\tSolving for $t$ when $\\text{Avg}(t)=1$,\r\n\t\\begin{equation*}\r\n\t\t\\frac{1}{2}\\hspace{3pt}\\frac{t}{8} = 1 \\implies t = 16.\r\n\t\\end{equation*}\r\n\t\r\n\tSo, at time $t=16$, the Mean Value Theorem tells us that the plane's speed was 1.\r\n\tLooking at the graph, we can see that at time $t=8$ the plane's speed was indeed 1.\r\n\\end{answer}\r\n\r\n\\subsection{Fundamental Theorem of Calculus}\r\nAlthough it's nice to be able to evaluate definite integrals for numerical bounds, it'd be more convenient if we only had to do the work of integrating once and could then have a function that would tell us the area like so:\r\n\\begin{equation*}\r\n\tF(x) = \\int_{a}^{x}{f(t)\\d{t}}.\r\n\\end{equation*}\r\nLet's try taking the derivative of $F$ using the limit definition.\r\n\\begin{align*}\r\n\tF^\\prime(x) &= \\lim_{\\Delta x \\to 0}{\\frac{F(x+\\Delta x)-F(x)}{\\Delta x}} \\\\\r\n\t&= \\lim_{\\Delta x\\to 0}{\\frac{\\int_{a}^{x+\\Delta x}f(t)\\d{t} - \\int_{a}^{x}{f(t)\\d{t}}}{\\Delta x}} \\\\\r\n\t&= \\lim_{\\Delta x\\to 0}{\\frac{\\int_{x}^{x+\\Delta x}{f(t)\\d{t}}}{\\Delta x}}\\text{ (by Integral Rules)}\\\\\r\n\t&= \\lim_{\\Delta x\\to 0}{\\frac{f(k)\\Delta x}{\\Delta x}}\\text{, }x\\leq k \\leq x + \\Delta x\\text{ (by Mean Value Theorem)} \\\\\r\n\t&= \\lim_{\\Delta x\\to 0}{f(k)} \\\\\r\n\t&= f(x) \\text{ (by Sandwich Theorem)}.\r\n\\end{align*}\r\nTaking the derivative seems to undo the integration.\r\nThe same fact applies if we take the integral of a derivative.\r\nStarting with what we've just shown,\r\n\\begin{equation*}\r\n\t\\dd{}{x}\\int_{0}^{x}{f(t)\\d{t}} = f(x).\r\n\\end{equation*}\r\nLet $g(x) = \\dd{}{x}f(x)$.\r\n\\begin{equation*}\r\n\t\\dd{}{x}\\int_{0}^{x}{g(t)\\d{t}} = g = \\dd{}{x}f(x).\r\n\\end{equation*}\r\nSince the derivatives are equal, we know the functions must differ by at most a constant $C$.\r\n\\begin{align*}\r\n\t\\int_{0}^{x}{g(t)\\d{t}} &= f(x) + C \\\\\r\n\t\\int_{0}^{x}{\\left[\\dd{}{x}f(t)\\right]\\d{t}} &= f(x) + C.\r\n\\end{align*}\r\nSo, the integral of the derivative gets us a function that differs from the original by at most a constant.\r\n\r\n\r\nThis idea that the integral and derivative undo each other is captured by the Fundamental Theorem of Calculus.\r\n\\begin{theorem}[Fundamental Theorem of Calculus]\r\n\tLet $f$ be a continuous function on the interval $[a,b]$.\r\n\tThen\r\n\t\\begin{equation*}\r\n\t\tF(x) = \\int_{a}^{x}{f(t)\\d{t}}\r\n\t\\end{equation*}\r\n\thas a derivative at every point in $[a,b]$, and\r\n\t\\begin{equation*}\r\n\t\t\\dd{F}{x} = \\dd{}{x}\\int_{a}^{x}{f(t)\\d{t}} = f(x).\r\n\t\\end{equation*}\r\n\tFurther, if $F$ is the antiderivative of $f$ on $[a,b]$, then\r\n\t\\begin{equation*}\r\n\t\t\\int_{a}^{b}{f(x)\\d{x}} = F(b) - F(a).\r\n\t\\end{equation*}\r\n\\end{theorem}\r\n\r\nThis last equation is especially useful for calculating definite integrals.\r\nRather than evaluating a limit of a Riemann sum, if we know the antiderivative, we can just evaluate at two points.\r\n\r\n\\begin{example}\r\n\tEvaluate the following definite integral using antiderivatives.\r\n\t\\begin{equation*}\r\n\t\t\\int_{0}^{1}{\\frac{\\d{x}}{1+x^2}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe previously derived that the derivative of $\\arctan{x}$ is $\\frac{1}{1+x^2}$.\r\n\tSo, $\\arctan{x}$ is the antiderivative of $\\frac{1}{1+x^2}$.\r\n\tApplying the Fundamental Theorem of Calculus (FTC),\r\n\t\\begin{align*}\r\n\t\t\\int_{0}^{1}{\\frac{\\d{x}}{1+x^2}} &= \\arctan{1} - \\arctan{0} \\\\\r\n\t\t&= \\frac{\\pi}{4} - 0 \\\\\r\n\t\t&= \\frac{\\pi}{4}.\r\n\t\\end{align*} \r\n\\end{answer}\r\n\r\n\\subsection{Integrals of Symmetric Functions}\r\nSuppose f is continuous on $[-a, a]$. Then we have\r\n\\begin{equation*}\r\n\t\\int_{-a}^{a}{f(x)\\d{x}} = 2 \\int_{0}^{a}{f(x)\\d{x}}\r\n\\end{equation*}\r\nif f is even and\r\n\\begin{equation*}\r\n\t\\int_{-a}^{a}{f(x)\\d{x}} = 0\r\n\\end{equation*}\r\nif f is odd.\\bigskip\r\n\r\n\\noindent\r\nIntuitively, since even functions are symmetric about the $y$-axis, it should make sense that the area under the curve from $-a$ to $a$ should be twice the area under the curve from 0 to $a$. \r\nLikewise, odd functions are symmetric about the origin, so any area under the curve above the $x$-axis will be canceled out by some corresponding area underneath the $x$-axis on the opposite side of the axis.\r\n\r\n\\begin{example}\r\n\tEvaluate the following definite integral.\r\n\t\\begin{equation*}\r\n\t\t\\int_{-1}^{1}{\\frac{\\tan{x}}{1 + x^2 + x^4}\\d{x}}\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tAt first, this looks like a nasty integral to evaluate. \r\n\tHowever, we notice that $f(-x) = -\\frac{\\tan{x}}{1 + x^2 + x^4}$.\r\n\tSince $f(-x) = -f(x)$, the function is odd, and since the limits of integration are additive inverses of one another, we have\r\n\t\\begin{equation*}\r\n\t\t\\int_{-1}^{1}{\\frac{\\tan{x})}{1 + x^2 + x^4}} = 0.\r\n\t\\end{equation*}\r\n\\end{answer}", "meta": {"hexsha": "13b74b02c22291958fd0b9ab09dea203b3051efe", "size": 9485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/integrals/definite_integrals.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/integrals/definite_integrals.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/integrals/definite_integrals.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 46.0436893204, "max_line_length": 238, "alphanum_fraction": 0.6472324723, "num_tokens": 3386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699436, "lm_q2_score": 0.8902942348544447, "lm_q1q2_score": 0.8004825786178189}}
{"text": "\\section{Notes on BCH formula}\n\nBaker--Campbell--Hausdorff\n\n\\begin{nameddef}{Linear adjoint endomophism}\n\\begin{align}\n\t\\ad_X^{(0)} Y &\\coloneqq Y, \\\\\n\t\\ad_X^{(n)} Y &\\coloneqq \\sbr{X, \\ad_X^{(n-1)} Y}_-,\\qquad\\forall n\\ge 1.\\\\\n\\end{align}\nSpecifically,\n\\begin{equation}\n\t\\ad_X Y \\coloneqq \\ad_X^{(1)} Y \\equiv \\sbr{X, Y}_-.\n\\end{equation}\n\\end{nameddef} % Linear adjoint endomophism\n\n\\begin{namedthm}{Lemma}\n\\begin{equation}\n\t\\ee^{X} Y \\ee^{-X} = \\sum_{n=0}^{+\\infty} \\frac{1}{n!}\\ad_X^{(n)}Y\n\t\\label{eq:bch-sandwich}\n\\end{equation}\n\\label{lem:bch-sandwich}\n\\end{namedthm} % Lemma\n\n\\begin{namedthm}{Corollary}\n\tFor $\\sbr{X, Y}_-$ central, i.e.\\ commuting with both $X$ and $Y$,\n\t\\begin{equation}\n\t\t\\ee^X\\ee^Y = \\ee^{X+Y+\\sbr{X, Y}_-/2}.\n\t\\end{equation}\n\t\\label{thm:bch-merging}\n\\end{namedthm} % Corollary\n\n\n\\begin{namedthm}{Theorem}[Braiding identity]\n\\begin{equation}\n\\ee^X \\ee^Y = \\rfun{\\exp}{\\sum_{n=0}^{+\\infty} \\frac{1}{n!}\\ad_X^{(n)}Y}\\ee^X.\n\\end{equation}\n\\label{thm:bch-brading}\n\\end{namedthm} % Braiding identity\n\n\n\\begin{nameddef}{A factorisation algorithm for quadratic $x$ and $p$}\nGiven $a_i\\in\\BbbR$, solve\n\\begin{align}\n\tU &= \\cfun{\\expi}{a_1 x^2 + a_2 \\frac{xp+px}{2} + a_3 p^2}\n\t\\nonumber \\\\\n\t&= \\cfun{\\expi}{b_1 x^2} \\cfun{\\expi}{b_2\\frac{xp+px}{2}}\n\t\t\\cfun{\\expi}{b_3 p^2}\n\t\t\\label{eq:to-be-factorised}\n\\end{align}\nfor $b_i$, $i = 1, 2, 3$.\n\nLet\n\\begin{align}\n\\rfun{L}{t} &\\coloneqq\n\\cfun{\\expi}{t\\rbr{a_1 x^2 + a_2 \\frac{xp+px}{2} + a_3 p^2}}, \\\\\n\\rfun{R}{t} &\\coloneqq\n\\cfun{\\expi}{\\rfun{c_1}{t} x^2} \\cfun{\\expi}{\\rfun{c_2}{t}\\frac{xp+px}{2}} \n\\cfun{\\expi}{\\frac{c_3}{t} p^2},\n\\end{align}\nwhere $0 \\le t \\le 1$.\nOne hopes to solve\n\\begin{equation}\n\t\\rfun{L}{t} = \\rfun{R}{t}\n\t\\label{eq:L=R}\n\\end{equation}\nfor $\\rfun{c_i}{t}$. By setting $t = 0$ and observing $\\rfun{L}{1} = \n\\rfun{R}{1} = U$, one recognises the boundary conditions\n\\begin{equation}\n\\rfun{c_i}{0} = 0,\\qquad \\rfun{c_i}{1} = b_i.\n\\end{equation}\n\nBy \\eqref{eq:L=R} one has\n\\begin{equation}\n\t\\dot{L}L^\\dagger = \\dot{R}R^\\dagger.\n\t\\label{eq:LdLdg=RdRdg}\n\\end{equation}\nEvaluating the right hand side of \\eqref{eq:LdLdg=RdRdg} with the formulas \nabove and comparing the corresponding coefficients, one derives\ncoefficients\n\\begin{equation}\n\t\\left\\{\\begin{array}{l}\n\t\ta_1 = \\dot c_1 - 2 c_1 \\dot{c}_2 + 4 c_1^2 \\ee^{-2 c_2}\\dot{c}_3 \\\\\n\t\ta_2 = \\dot{c}_2 - 4 c_1 \\ee^{-2 c_2} \\dot{c}_3 \\\\\n\t\ta_3 = \\ee^{-2 c_2} \\dot{c}_3,\n\t\\end{array}\\right.\n\\end{equation}\nwhich further transforms to\n\\begin{equation}\n\t\\left\\{\\begin{array}{l}\n\t\t\\dot{c}_1 = a_1 + 2 a_2 c_1 + 4 a_3 c_1^2 \\\\\n\t\t\\dot{c}_2 = a_2 + 4 a_3 c_1 \\\\\n\t\t\\dot{c}_3 = a_3 \\ee^{2 c_2}.\n\t\\end{array}\\right.\n\t\\label{eq:one-by-one}\n\\end{equation}\n\\Cref{eq:one-by-one} can be integrated on by one.\n\\end{nameddef} % A factorisation algorithm", "meta": {"hexsha": "de3470b4f372f2c3983104e9a4928d1fc9929813", "size": 2770, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/gen-coh-squ/sections/bch.tex", "max_stars_repo_name": "cmp0xff/Notes", "max_stars_repo_head_hexsha": "afd712c1e42275bf781a030d6c5f1b7f4c6ec57b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "old/gen-coh-squ/sections/bch.tex", "max_issues_repo_name": "cmp0xff/Notes", "max_issues_repo_head_hexsha": "afd712c1e42275bf781a030d6c5f1b7f4c6ec57b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/gen-coh-squ/sections/bch.tex", "max_forks_repo_name": "cmp0xff/Notes", "max_forks_repo_head_hexsha": "afd712c1e42275bf781a030d6c5f1b7f4c6ec57b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5567010309, "max_line_length": 78, "alphanum_fraction": 0.6393501805, "num_tokens": 1287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.8887588038050466, "lm_q1q2_score": 0.8003537731283494}}
{"text": "\\section*{Problem 1 Solution}\n\nFirst, let's note that we will use the shorthand U5 and U8 in subscripts to denote $^{235}$U and $^{238}$U respectively. \n\nTo begin we note that the densities of $^{235}$U and $^{238}$U can be found as fractions of the total UO$_2$. Since the partial densities are dependent on the mass of the components, the fractions are equivalent to the weight \\% enrichment.\n$$ \\rho_{\\text{UO}_2} = \\rho_{\\text{U5O}_2} + \\rho_{\\text{U8O}_2}$$\n$$ \\begin{array}{lr}\n        \\rho_{\\text{U5O}_2} = w\\rho_{\\text{UO}_2}    \\\\\n        \\rho_{\\text{U8O}_2} = (1-w)\\rho_{\\text{UO}_2}\\\\\n        \\end{array} \\text{ where } w = 0.05 $$\n        \nNow, we can use the fact that the number density of a material, $n$, is equal to the material's density, $\\rho$, multiplied by Avogadro's number, $N_A$, and divided by the molar mass, $m$, of the material. \n$$ n = \\frac{\\rho N_A}{m} $$\nWe find\n$$ n_{\\text{U5O}_2} = \\frac{\\rho_{\\text{U5O}_2} N_A}{m_{\\text{U5O}_2}} $$\n$$ n_{\\text{U8O}_2} = \\frac{\\rho_{\\text{U8O}_2} N_A}{m_{\\text{U8O}_2}} $$\nIf we make the simplification that $n_{\\text{U5}} = n_{\\text{U5O}_2}$ and $n_{\\text{U8}} = n_{\\text{U8O}_2}$, and also substitute our equations for $\\rho_{\\text{U5O}_2}$ and $\\rho_{\\text{U8O}_2}$ in terms of $\\rho_{\\text{UO}_2}$ from above, then we find \n\\begin{align*}\nn_{\\text{U5}} &= \\frac{w\\rho_{\\text{UO}_2} N_A}{m_{\\text{U5O}_2}} \\\\\nn_{\\text{U8}} &= \\frac{(1-w)\\rho_{\\text{UO}_2} N_A}{m_{\\text{U8O}_2}} \\\\\n\\end{align*}\nAt this point, we can also separate our molar masses into molar masses of the components, for which we can find data. \n$$ m_{\\text{U5O}_2} = m_{\\text{U5}} + 2m_{\\text{O}} $$\n$$ m_{\\text{U8O}_2} = m_{\\text{U8}} + 2m_{\\text{O}} $$\nWe now have enough information to solve for both of these quantities, and so we plug in values. We also note that $n_O = 2(n_{\\text{U8}} + n_{\\text{U8}})$ since each uranium atom is bonded to 2 oxygen atoms.\n\\begin{align*}\nn_{\\text{U5}}\t&= \\frac{w\\rho_{\\text{UO}_2} N_A}{m_{\\text{U5}} + 2m_{\\text{O}}}\t\t& \\boxed{n_{\\text{U5}}= 1.174 \\times 10^{21} \\text{ cm}^{-3} }\\\\\nn_{\\text{U8}}\t&= \\frac{(1-w)\\rho_{\\text{UO}_2} N_A}{m_{\\text{U8}} + 2m_{\\text{O}}} \t& \\boxed{n_{\\text{U8}}= 2.205 \\times 10^{22} \\text{ cm}^{-3} }\\\\\nn_{\\text{O}}\t&= 2(n_{\\text{U5}} + n_{\\text{U8}})  \t\t\t\t\t\t\t\t\t& \\boxed{n_{\\text{O}}= 4.645 \\times 10^{22} \\text{ cm}^{-3} }\\\\\n\\end{align*}\n\n", "meta": {"hexsha": "a957a8e3a5b51db54e280ef1908b2292b2c95520", "size": 2352, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc02/disc02_solution01.tex", "max_stars_repo_name": "mitchnegus/NE150-discussion", "max_stars_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/drafts/disc02/disc02_solution01.tex", "max_issues_repo_name": "mitchnegus/NE150-discussion", "max_issues_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/drafts/disc02/disc02_solution01.tex", "max_forks_repo_name": "mitchnegus/NE150-discussion", "max_forks_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.5, "max_line_length": 254, "alphanum_fraction": 0.6228741497, "num_tokens": 977, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122720843811, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.800319935277822}}
{"text": "\\documentclass[letterpaper,11pt]{article}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{amsmath, amssymb, setspace, esint}\n\\usepackage{algorithm}\n\\usepackage{graphicx}\n\\usepackage{placeins}\n\\usepackage{algpseudocode}\n\\usepackage{tikz}\n\n\\usepackage{fontspec}\n\\usepackage{minted}\n\n\\allowdisplaybreaks[1]\n\n\\makeatletter\n\\newcommand\\blx@unitmark{23sp}\n\\makeatother\n\n\\newcommand{\\LOne}[1]{ \\lvert \\lvert #1 \\rvert \\rvert_1 }\n\\newcommand{\\LTwoSqr}[1]{ \\lvert \\lvert #1 \\rvert \\rvert_2^2 }\n\\newcommand{\\LInf}[1]{ \\lvert \\lvert #1 \\rvert \\rvert_{\\infty} }\n\n\\newcommand\\tikzmark[1]{%\n  \\tikz[remember picture,overlay]\\node[inner sep=2pt] (#1) {};}\n\\newcommand\\DrawBox[3][]{%\n  \\tikz[remember picture,overlay]\\draw[#1] ([xshift=-3.5em,yshift=7pt]#2.north west) rectangle (#3.south east);}\n\n\\algnewcommand\\algorithmicinput{\\textbf{Input:}}\n\\algnewcommand\\Input{\\item[\\algorithmicinput]}\n\n\\algnewcommand\\algorithmicoutput{\\textbf{Output:}}\n\\algnewcommand\\Output{\\item[\\algorithmicoutput]}\n\n\\algdef{SE}[DOWHILE]{Do}{doWhile}{\\algorithmicdo}[1]{\\algorithmicwhile\\ #1}%\n\n\\begin{document}\n\n\\section*{Algorithm to compute  $\\pi$}\n\n\\subsection*{Question 1:}\n\nConstruct an algorithm in C++ to approximate $\\pi$. Assume that you are working on a project\n with a small development team and your algorithm will be used\n as a part of a larger code base.\n\n\\begin{itemize}\n  \\item Assume that the required precision of the calculation is not known until run-time.\n  \\item You do not need to determine the error $\\lvert x - \\pi \\rvert$ associated with\n   your calculation.\n  \\item Your algorithm should be able to work with single or double-precision floating point numbers\n  \\item Assume you have access to a compiler that supports any version of C and/or C++ that you would like\n  numbers.\n\\end{itemize}\n\nYou can use any method, libraries etc. that you would\nlike with the exception of functions that approximate transcendental numbers ( e.g.\n std::asin, M\\_PI or similar ).\n\nIt might be useful to know that $\\pi = 4 \\sum_{k=1}^{\\infty} \\frac{ (-1)^{k+1} }{ 2k - 1 }$\n( known as the Gregory Series ). The first few terms in the series are $\n4( 1 - \\frac{1}{3} + \\frac{1}{5} - \\frac{1}{7} + \\dots )$.\n\nThis is not the only way to compute $\\pi$ and there is no special reason why this\n method should be preferred over any other method.\n\nYou do need to write a Make file, compiler/linker commands or\nexplicitly write out \\#include statements, but you are responsible for appropriately\n  using namespaces.\n\n\\subsection*{Possible Answer 1:}\n\n\\subsubsection*{Solution using Gregory Series:}\nStart with the identity $\\pi \\approx 4 \\sum_{k=0}^{N} \\frac{ (-1)^{k+1} }{ 2k - 1 }$\n\n\\begin{minted}[mathescape,\n               linenos,\n               numbersep=5pt,\n               gobble=2,\n               frame=lines,\n               framesep=2mm]{cpp}\n\n    \\* run_time_pi.h *\\\n\n    namespace wbp {\n\n    template< typename T >\n    T partial_sum( T (*f)(uint index), uint sum_start, uint sum_end ) {\n\n       T sum_total = static_cast<T>( 0 );\n\n       for( uint i = sum_start; i <= sum_end ; i++ ) {\n           sum_total += f(i);\n       }\n\n       return sum_total;\n\n    }\n\n    template < typename T >\n    T alt_sign( uint k ) {\n       return ( ( k + 1 )%2 == 0 )?( static_cast<T>( 1 ) ):( static_cast<T>( -1 ) );\n    }\n\n    template < typename T >\n    T gregory_term( uint k ) {\n\n       return alt_sign<T>( k )*static_cast<T>(1) / static_cast<T>( 2*k - 1 );\n    }\n\n    template< typename T >\n    T gregory_pi( uint num_iter ) {\n\n      static_assert( std::is_floating_point<T>::value,\n       \"Template parameter must be a floating-point value.\");\n      return static_cast<T>( 4 )*partial_sum( &gregory_term<T>, 1, num_iter );\n\n    }\n\n    }\n\\end{minted}\n\n\\subsubsection*{Solution using Power Series:}\nStart with the identity $\\pi \\approx \\sqrt{ 6 \\sum_{k=1}^{N} \\frac{1}{k^2} }$\n\n\\begin{minted}[mathescape,\n               linenos,\n               numbersep=5pt,\n               gobble=2,\n               frame=lines,\n               framesep=2mm]{cpp}\n\n    \\* run_time_pi.h *\\\n\n    namespace wbp {\n\n    template< typename T >\n    T partial_sum( T (*f)(uint index), uint sum_start, uint sum_end ) {\n\n       T sum_total = static_cast<T>( 0 );\n\n       for( uint i = sum_start; i <= sum_end ; i++ ) {\n           sum_total += f(i);\n       }\n\n       return sum_total;\n\n    }\n\n    template < typename T >\n    T pow_term( uint k ) {\n\n        return static_cast<T>( 1 )/static_cast<T>( k * k );\n\n    }\n\n    template< typename T >\n    T power_pi( uint num_iter ) {\n\n        static_assert( std::is_floating_point<T>::value,\n        \"Template parameter must be a floating-point value.\");\n        return std::sqrt( static_cast<T>( 6 )*partial_sum( &pow_term<T>, 1, num_iter ) );\n\n    }\n\n    }\n\\end{minted}\n\n\\subsection*{Question 2:}\n\nSuppose your team notices that your algorithm is a performance bottle-neck,\nhow would you speed it up?\n\n\\subsection*{Possible Answer 2:}\n\nFor any of these series methods the terms in the series are independent, as\n they only depend on index. The series terms can be computed in a canonical ``for''\n  loop and easily parallelized using OpenMP for similar.\n\nFor a method like the Monte Carlo method each point can be assigned a position\nindependently of one another.\n\n\\subsection*{Question 3:}\n\nSuppose someone else in your team has written an algorithm to compute $\\pi$\n using the Gregory Series $ \\left( \\pi = 4 \\sum_{k=0}^{\\infty} \\frac{ (-1)^{k+1} }{ 2k - 1 } \\right)$.\n\nTheir algorithm, in pseudo-code, takes the following form:\n\n \\FloatBarrier\n \\begin{algorithm}[!htbp]\n   \\caption{ Estimate $\\pi$ using Gregory Sum formula, using pairs of terms.}\n   \\begin{algorithmic}[1]\n    \\Input{$n \\in \\mathbb{N} $}\\Comment{Specify the number of terms in the series -- must be an even number}\n    \\State $x \\gets 0$\\Comment{ Initialize the total sum to zero. }\n     \\For{ $k \\in [ 1, 3, 5, \\dots, n/2 - 1 ]$ }\n      \\State $x \\gets x + \\left( \\frac{1}{2k-1} - \\frac{1}{2( k + 1 ) -1} \\right)$\n     \\EndFor\n   \\end{algorithmic}\n   \\Return $4 x$\n \\end{algorithm}\n \\FloatBarrier\n\nThe first few terms using this algorithm would read $\n4( ( 1 - \\frac{1}{3} ) + ( \\frac{1}{5} - \\frac{1}{7} ) + \\dots )$.\n\nYou notice that after a large number of iterations this algorithm exhibits some strange\n behavior -- it does not seem to converge to $\\pi$. You decide to investigate further\n and notice the error term $\\lvert x - \\pi \\rvert$ does not go to zero. What\n  might be causing this problem?\n\n\\subsection*{Possible Answer 3:}\n\nAs $k$ grows large we will find that $\\frac{1}{2k-1} \\approx \\frac{1}{2( k + 1 ) -1}\n\\leftrightarrow \\frac{1}{2k-1} - \\frac{1}{2( k + 1 ) -1} \\approx 0$.\nWe also expect that these terms will have similar numbers of significant digits --\n this is a situation that will almost certainly result in loss of significance /\n catastrophic cancellation. The result of this ( might ) be the error term\n converging to some non-zero constant, or diverging.\n\n\\subsection*{Question 4:}\n\nSuppose your team decides that the number of iterations/recursions necessary\nto guarantee required precision can be determined\n at compile time. Further it has been determined that\n double-precision floating-point numbers are the only type that needs to be\n supported.\n\n How would you re-write your algorithm to be\n computed at compile time instead of run time?\n\n\\subsection*{Possible Answer 4:}\n\nPossible answer if starting with the Gregory Sum is stated below -- answer for\nother series methods are similar.\n\n\\begin{minted}[mathescape,\n               linenos,\n               numbersep=5pt,\n               gobble=2,\n               frame=lines,\n               framesep=2mm]{cpp}\n\n    \\* meta_pi.h *\\\n    namespace wbp {\n\n    // General case\n    template<unsigned int N, typename T = double>\n    struct GregorySum {\n        static constexpr T sum =\n         ( (N % 2) ? 1.0 : -1.0 ) / ( 2*N - 1 ) +  GregorySum<N - 1, T>::sum;\n    };\n\n    // Specialized stop case\n    template<typename T>\n    struct GregorySum<1, T> {\n        static constexpr T sum = 1;\n    };\n\n    template< unsigned int N >\n    double compute_meta_pi() {\n        return 4.0*GregorySum< N >::sum;\n    }\n\n    }\n\\end{minted}\n\nUsage: \\verb|wbp::compute_meta_pi<101>()|\n\n\\end{document}\n", "meta": {"hexsha": "473b547312df242ba8fa02f7acce6b3321fc5f75", "size": 8211, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Questions/With_Answers/cpp_dev_white_board_question.tex", "max_stars_repo_name": "bejphil/CPP_Algorithms_Interview_Questions", "max_stars_repo_head_hexsha": "1c55776558fcf29e724129a6cbd4e89ecfa2447b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Questions/With_Answers/cpp_dev_white_board_question.tex", "max_issues_repo_name": "bejphil/CPP_Algorithms_Interview_Questions", "max_issues_repo_head_hexsha": "1c55776558fcf29e724129a6cbd4e89ecfa2447b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Questions/With_Answers/cpp_dev_white_board_question.tex", "max_forks_repo_name": "bejphil/CPP_Algorithms_Interview_Questions", "max_forks_repo_head_hexsha": "1c55776558fcf29e724129a6cbd4e89ecfa2447b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.4111111111, "max_line_length": 112, "alphanum_fraction": 0.6576543661, "num_tokens": 2363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.9086179012632543, "lm_q1q2_score": 0.8003079867448437}}
{"text": "\\section{Definitions and Properties}\r\n\\begin{definition}\r\n    Let $\\Omega$ be a set, and $\\mathscr F$ a set of subset of $\\Omega$.\r\n    We call $\\mathscr F$ a $\\sigma$-algebra on $\\Omega$ if\\\\\r\n    1. $\\Omega\\in\\mathscr F$.\\\\\r\n    2. $A\\in\\mathscr F\\implies A^c\\in\\mathscr F$.\\\\\r\n    3. For any countable sequence $(A_n)_{n\\in\\mathbb N}\\in\\mathscr F$, we have\r\n    $$\\bigcup_{n\\in\\mathbb N}A_n\\in\\mathscr F$$\r\n    If $\\mathscr F$ is a $\\sigma$-algebra, then a function $\\mathbb P:\\mathscr F\\to [0,1]$ is called a probablity measure if\\\\\r\n    1. $\\mathbb P(\\Omega)=1$.\\\\\r\n    2. For every sequence of disjoint sets $(A_n)_{n\\in\\mathbb N}\\in\\mathscr F$, we have\r\n    $$\\mathbb P\\left( \\bigcup_{n\\in\\mathbb N}A_n \\right)=\\sum_{n\\in\\mathbb N}\\mathbb P(A_n)$$\r\n    If $\\mathbb P$ is a probablity measure, then we call $(\\Omega,\\mathscr F,\\mathbb P)$ a probablity space.\r\n\\end{definition}\r\n\\begin{remark}\r\n    When $\\Omega$ is countable, we usually take $\\mathscr F=2^\\Omega$.\r\n\\end{remark}\r\n\\begin{definition}\r\n    The elements of $\\Omega$ are called outcomes and the elements of $\\mathbb F$ are called events.\r\n    If $A\\in\\mathscr F$, we interpret $\\mathbb P(A)$ as the probablity that $A$ happens.\r\n    Note that we only talk about probablity of events instead of outcomes.\r\n\\end{definition}\r\nWe will see later that if we take a random point from $[0,1]$, the probablity of a certain point being taken is $0$ (consequently any countable subset of $[0,1]$).\r\n\\begin{proposition}\r\n    Let $A,B\\in\\mathscr F$.\r\n    1. $\\mathbb P(A^c)=1-\\mathbb P(A)$.\\\\\r\n    2. $\\mathbb P(\\varnothing)=0$.\\\\\r\n    3. $A\\subset B\\implies\\mathbb P(B)\\ge \\mathbb P(A)$.\\\\\r\n    4. $\\mathbb P(A\\cup B)=\\mathbb P(A)+\\mathbb P(B)-\\mathbb P(A\\cap B)$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    All follow from definition.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. Rolling a fair die.\r\n    So $\\Omega=\\{1,2,3,4,5,6\\}$ and $\\mathscr F=2^\\Omega$, and $\\forall A\\subset\\Omega,\\mathbb P(A)=|A|/6$.\\\\\r\n    2. Equality likely outcomes.\r\n    $\\Omega$ is just a finite set of size $n>0$ and $\\mathscr F=2^\\Omega$, and $\\forall A\\subset\\Omega,\\mathbb P(A)=|A|/n$.\r\n    This is the model of a randomly chosen point of $\\Omega$.\r\n    Taking $n=6$ gives the first example.\\\\\r\n    3. Picking balls from a bag.\r\n    Suppose we have a bag with $n$ labelled balls $1,2,\\ldots n$ and indistinguishable by touch.\r\n    We pick $k\\le n$ balls at random (i.e. all outcomes are equally likely) without looking.\r\n    Then $\\Omega=\\{A\\subset \\{1,2,\\ldots,n\\}:|A|=k\\}$ and $\\mathscr F=2^\\Omega$, so $\\forall A\\subset\\Omega,\\mathbb P(A)=|A|/\\binom{n}{k}$.\\\\\r\n    4. A deck of cards.\r\n    Suppose we have a well-shuffled (i.e. all possible ordering of the cards are equally likely) deck of $52$ cards (excluding jokers).\r\n    So $\\Omega=S_{52},\\mathscr F=2^\\Omega$ and $\\forall A\\subset\\Omega,\\mathbb P(A)=|A|/52!$.\r\n    Hence $\\mathbb P(\\text{first two cards are aces})=(4\\times 3\\times 50!)/52!=1/221$.\\\\\r\n    5. Largest digit.\r\n    Consider a string of random digits (all outcomes equally possible) $0,1,\\ldots,9$ of length $n$.\r\n    Take $\\Omega=\\{0,1,\\ldots,9\\}^n$ and $\\mathscr F,\\mathbb P$ as in before.\r\n    Let $A_k=\\{\\text{no digit exceeds $k$}\\}$ and $B_k=\\{\\text{largest digit is $k$}\\}$.\r\n    Since $|A_k|=(k+1)^n$ we have $|B_k|=|A_k\\setminus A_{k-1}|=(k+1)^n-k^n$, so $\\mathbb P(B_k)=((k+1)^n-k^n)/10^n$.\\\\\r\n    6. Birthday problem.\r\n    Suppose there are $n$ people in the room.\r\n    What is the probability of at least two people sharing the same birthday, given that nobody is born on 29 Feb and any other day in the year is equally probable.\r\n    So $\\Omega=\\{1,2,\\ldots,365\\}^n$, and again $\\mathscr F$ and $\\mathbb P$ are taken as before (equally likely outcome).\r\n    Let $A$ be the event that all birthdays are different, then\r\n    $$\\mathbb P(A)=\\frac{|A|}{|\\Omega|}=\\frac{365\\times 364\\times\\ldots (365-n+1)}{365^n}$$\r\n    Then the probablity of two having the same birthday is $p=1-\\mathbb P(A)$.\r\n    If you take $n=22$, then you get $p\\approx .476$, and when $n=23$, $p\\approx .507$.\r\n\\end{example}", "meta": {"hexsha": "32bb45c04592f3eb8c0606693ab00ad4722f8580", "size": 4060, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/defns.tex", "max_stars_repo_name": "david-bai-notes/IA-Probability", "max_stars_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1/defns.tex", "max_issues_repo_name": "david-bai-notes/IA-Probability", "max_issues_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1/defns.tex", "max_forks_repo_name": "david-bai-notes/IA-Probability", "max_forks_repo_head_hexsha": "47487b998f0975ea0a342e17b5b9dffa0bb8e9ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.4838709677, "max_line_length": 165, "alphanum_fraction": 0.6408866995, "num_tokens": 1411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.8723473879530491, "lm_q1q2_score": 0.8002065731354858}}
{"text": "\n\\subsection{Ideals}\n\nAn ideal is a subring where the multiplication of any element of the ideal with any element of the ring is also in the ideal.\n\n\\subsubsection{Examples}\n\nEven numbers are an ideal of the integers.\n\nOdd numbers are not an ideal. For example \\(1\\) is in the ideal, but multiplied by \\(2\\) gives \\(2\\), which is not in the ideal.\n\n", "meta": {"hexsha": "523deecdac3b03401d3b8d2d6b0da461c459ed98", "size": 349, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/rings/06-02-ideals.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/rings/06-02-ideals.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/rings/06-02-ideals.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0833333333, "max_line_length": 128, "alphanum_fraction": 0.7421203438, "num_tokens": 84, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9481545274901875, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.8001429566301417}}
{"text": "\n\\subsection{G\u00f6del numbering}\n\nG\u00f6del numbering assigns a unique number to each formula.\n\nTo contruct this we first assign a natural number to each symbol.\n\nThis gives us a sequence:\n\n\\(\\{x_1, x_2, x_3,...,x_n\\}\\)\n\nWe can assign a unique number to this by using the first \\(n\\) prime numbers.\n\n\\(2^{x_1}3^{x_2}5^{x_3}...\\)\n\nThis number can then be prime factored to recover the sequence, and therefore the formula.\n\n", "meta": {"hexsha": "b2f18f7b6d7534cd0285754bf55e2dfa19df73fc", "size": 415, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/godelNumbering/01-01-godelNumbering.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/godelNumbering/01-01-godelNumbering.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/godelNumbering/01-01-godelNumbering.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.0555555556, "max_line_length": 90, "alphanum_fraction": 0.7228915663, "num_tokens": 119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068041, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.8000803372881855}}
{"text": "%\n% Chapter 5.2\n%\n\n\\section*{5.2 Volumes}\n\n\\subsubsection*{Definition of Volume (Disk Method)}\n\nLet \\(S\\) be a solid that lies between \\(x=a\\) and \\(x=b\\). If the cross-sectional area of \\(S\\) in the plane \\(P_x\\), through \\(x\\) and perpendicular to the \\(x\\)-axis, is \\(A(s)\\), where \\(A\\) is a continuous function, then the volume of \\(a\\) is \n\n\\[ V = \\lim_{n \\to \\infty} \\sum_{i=1}^n A(x_i^*) \\Delta x = \\int_a^b A(x) dx\\]\n", "meta": {"hexsha": "1b90c1221ba6c4da45d2bc880ad676d529111400", "size": 426, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/5-2.tex", "max_stars_repo_name": "davidcorbin/calc-1-study-guide", "max_stars_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/5-2.tex", "max_issues_repo_name": "davidcorbin/calc-1-study-guide", "max_issues_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/5-2.tex", "max_forks_repo_name": "davidcorbin/calc-1-study-guide", "max_forks_repo_head_hexsha": "b6b0a43ef551d1735ba4af55f3917ed1ed39e926", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.5, "max_line_length": 249, "alphanum_fraction": 0.6150234742, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896671963206, "lm_q2_score": 0.8688267864276107, "lm_q1q2_score": 0.8000067275259284}}
