2023-11-15

This commit is contained in:
bluepython508
2023-11-15 08:53:39 +00:00
parent a8f2fd86e2
commit d320a956f8
14 changed files with 553 additions and 191 deletions

6
CS1029/notes-2023-11-01 Normal file
View File

@@ -0,0 +1,6 @@
Edge contractions: merge two vertices, removing an edge between them
Representations: adjacency list
adjacency matrix
What does the determinant of an adjacency matrix mean?
incidence matrix: vertices against edges, 1 where edge is connected to vertex

1
CS1029/notes-2023-11-07 Normal file
View File

@@ -0,0 +1 @@

1
CS1029/notes-2023-11-08 Normal file
View File

@@ -0,0 +1 @@

1
CS1029/notes-2023-11-14 Normal file
View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,58 @@
1. a) {(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 2), (2, 3), (2, 4), (2, 5), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5), (5, 5) }
Reflexive: \forall x. (x, x) \in R
Antisymmetric (& not symmetric): all pairs have x <= y. forall x, y. x <= y, !(y <= x) || y == x
Transitive
b) {(1, 2), (1, 4), (2, 1), (2, 3), (3, 2), (3, 4), (4, 1), (4, 3)}
Not reflexive: there are no pairs of (x, x)
Symmetric - all pairs have their reverse represented
Not antisymmetric: symmetric and anti-symmetric are mutually exclusive
Not transitive: (1, 2) and (2, 3) - 1 + 3 is not odd
2. {(item, quantity)}
{(Name, {(key, value)})}
{(Name, Address, {(Room type, price, {(key, value)})}, ...)}
3. 105 305 306 505 705 707 905 906 909
4. a) ab ac bc cb
b) {(a, a), (a, b), (a, c), (b, b), (b, a), (b, c), (c, a), (c, b), (d, d)}
5.a) {(1, 1), (1, 2), (1, 4), (2, 1), (2, 3), (3, 2), (3, 3), (3, 4), (4, 1), (4, 3), (4, 4)}
Not reflexive: (2, 2) is not present
Symmetric, therefore not anti-symmetric
Not transitive: (1, 2) and (2, 3), but not (1, 3)
b) 12 21 14 41 32 23 43 34
Not reflexive
Symmetric, therefore not antisymmetric
Not transitive: 12 and 23 but not 13
6. 1 1 0 0
1 1 0 0
1 0 1 1
0 0 0 1
Yes, it's reflexive
8. {(a, b) | a divides b OR b divides a}
9. No, it's not transitive. (a, b) & (b, d), but not (a, d)
10. a) Not equivalence relation: missing transitivity
(1, 3) and (3, 2), but not (1, 2)
b) {0}, {1, 2}, {3}
11. \forall n \in N_0:
0 + 3n
1 + 3n
2 + 3n
12. a) Y
b) N: 0 is in both - not disjoint
c) Y
d) N: 0 is missing
13. a) 00 11 22 33 44 55 12 21 34 43 35 53 45 54
b) 00 11 22 33 44 55 01 10 23 32 45 54
c) 00 11 22 33 44 55 01 10 02 20 12 21 34 43 35 53 45 54
14. a) Y, trivially
b) N: not antisymmetric ((2, 3) and (3, 2))
c) N: not reflexive (no (3, 3))

View File

@@ -0,0 +1,64 @@
1. Undirected, unlooped, multi-edged: multigraph
b) directed, looped, multi-edged: directed pseudo-multigraph
2. ac bd
b) cd cd dd ee ab bc
3. {{paper}}
4. vertices: 6
edges: 6
degree: a: 2 b: 4 c: 1 f: 3 e: 2 d: 0
isolated: d
pendant: c
b) vertices: 5
edges: 14
degree: a: 6 b: 6 c: 6 d: 5 e: 3
isolated: -
pendant: -
5. vertices: 4
in-a : 2
out-a: 2
in-b: 3
out-b: 4
in-c: 2
out-c: 1
in-d: 1
out-d: 1
6. {ac} {bde}
b) Not bipartite: 3-loop bcf would require 3 sets
7. {{ paper }}
8. a -> abcd
b -> d
c -> ab
d -> bcd
9. | a b c d
--+--------
a | 1 1 1 1
b | 0 0 0 1
c | 1 1 0 0
d | 0 1 1 1
10. {{ paper }}
11. v1 -> u1
v2 -> u4
v3 -> u2
v4 -> u5
v5 -> u3
12. v1 -> u4
v2 -> u3
v3 -> u1
v4 -> u2
13. PSCL
a) YNN4
b) N---
c) N---
d) YYY5

1
CS1032/notes-2023-11-02 Normal file
View File

@@ -0,0 +1 @@

1
CS1032/notes-2023-11-03 Normal file
View File

@@ -0,0 +1 @@
Pencil & eraser for final exam

1
CS1032/notes-2023-11-09 Normal file
View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,21 @@
import sys, itertools
def open_arg(_arg0, filename = "-"): # Default of - means stdin
if filename == "-":
return sys.stdin
return open(filename, 'r')
def head(file):
for line in file.readlines()[:10]:
print(line, end = "")
if __name__ == '__main__':
try:
file = open_arg(*sys.argv)
head(file)
except FileNotFoundError:
print("File not found!", file=sys.stderr)
sys.exit(1)
except:
print("Some other error occured", file=sys.stderr)

View File

@@ -0,0 +1,21 @@
import sys, itertools
def open_arg(_arg0, filename = "-"): # Default of - means stdin
if filename == "-":
return sys.stdin
return open(filename, 'r')
def tail(file):
for line in file.readlines()[-10:]:
print(line, end = "")
if __name__ == '__main__':
try:
file = open_arg(*sys.argv)
tail(file)
except FileNotFoundError:
print("File not found!", file=sys.stderr)
sys.exit(1)
except:
print("Some other error occured", file=sys.stderr)

View File

@@ -0,0 +1,70 @@
# This function adds two numbers
def add(x, y):
return x + y
# This function subtracts two numbers
def subtract(x, y):
return x - y
# This function multiplies two numbers
def multiply(x, y):
return x * y
# This function divides two numbers
def divide(x, y):
return x / y
def avg(x, y):
return (x + y) / 2
def sci(x, y):
return x * 10 ** y
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
print("5.Average")
print("6.Scientific Notation")
while True:
# take input from the user
choice = input("Enter choice(1/2/3/4/5/6): ")
# check if choice is one of the four options
if choice in ('1', '2', '3', '4', '5', '6'):
try:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
except ValueError:
print("Invalid input. Please enter a number.")
continue
if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))
elif choice == '2':
print(num1, "-", num2, "=", subtract(num1, num2))
elif choice == '3':
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == '4':
print(num1, "/", num2, "=", divide(num1, num2))
elif choice == '5':
print(f"avg({num1}, {num2})", "=", avg(num1, num2))
elif choice == '6':
print(f"{num1}e{num2}", "=", sci(num1, num2))
# check if user wants another calculation
# break the while loop if answer is no
next_calculation = input("Let's do next calculation? (yes/no): ")
if next_calculation.lower().startswith('n'):
break
else:
print("Invalid Input")

View File

@@ -8,8 +8,9 @@
\date{}
\author{}
\renewcommand{\Re}[1]{\operatorname{\mathbb{R}e}(#1)}
\renewcommand{\Im}[1]{\operatorname{\mathbb{{I}}m}(#1)}
\newcommand{\paren}[1]{\left(#1\right)}
\renewcommand{\Re}[1]{\operatorname{\mathbb{R}e}\paren{#1}}
\renewcommand{\Im}[1]{\operatorname{\mathbb{{I}}m}\paren{#1}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
@@ -18,8 +19,8 @@
\newcommand{\conj}[1]{\overline{#1}}
\renewcommand{\mod}[1]{\left|#1\right|}
\newcommand{\abs}[1]{\left|#1\right|}
\newcommand{\paren}[1]{\left(#1\right)}
\newcommand{\polar}[2]{#1\paren{\cos{\paren{#2}} + i\sin{\paren{#2}}}}
\newcommand{\adj}[1]{\operatorname{adj}#1}
\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%

View File

@@ -219,7 +219,7 @@ $\det{A} = \prod^{N}_{i=0}~a_{ij} \forall~\text{ row-echelon }A$
\end{description}
Note: $\det{A} = \det{A^T}~\forall~A$
\section*{Matrix Multiplication}
LHS has columns $=$ rows of RHS
LHS has columns $=$ rows of RHS \\
It's the cartesian product
\[A\times B = (a_{i1}b_{j1} + a_{i2}b_{2j} + \ldots + a_{im}b_{mj})_{ij}\]
\begin{align*}
@@ -240,4 +240,119 @@ It's the cartesian product
9 & 10 & 11 & 12 \\
\end{pmatrix}
\end{align*}
\[A\vec{x} = \vec{b}\]
where $A$ is the coefficient matrix, $\vec{x}$ is the variables, and $\vec{b}$ is the values of the equations of a linear equation system.
\subsection*{Inverse Matrices}
The identity matrix exists as $I_n$ for size $n$.
\[AA^{-1} = I_n = A^{-1}A \quad \forall~\text{matrices }A \text{ of size } n\]
Assume that $A$ has two distinct inverses, $B$ and $C$.
\begin{align*}
& \text{matrix multiplication is associative} \\
\therefore~ & C(AB) = (CA)B \\
\therefore~ & C I_n = I_n B \\
\therefore~ & C = B \\
& \text{
As $B = C$, while $B$ and $C$ are assumed to be distinct, matrices have no more than one unique inverse by contradiction
}
\end{align*}
Matrices are invertible $\iff \det{A} \neq 0$
\[\det{AB} = \det{A}\det{B}\]
\[\therefore~ \det{A}\det{A^{-1}} = \det{I_n} = 1\]
\[\therefore~ \det{A} \neq 0 \]
\begin{align*}
\begin{pmatrix} a & b \\ c & d \end{pmatrix}^{-1} = \frac{1}{ad - bc}\begin{pmatrix} d & -b \\ -c & a \end{pmatrix}
\end{align*}
\subsubsection*{Computation thereof}
\[\det{A} = \sum_{k = 1}^{n}~a_{ik}(-1)^{i+j}\det{A_{ij}} \quad \text{ for any $i$}\]
\begin{description}
\item[Matrix of Cofactors: $C$] determinants of minors \& signs of laplace expansion \\
ie. $\sum A \odot C = \det{A}$
\item[$\adj{A}$ Adjucate of $A$ =] $C^T$
\end{description}
\begin{align*}
A & = \begin{pmatrix}
1 & 0 & 1 \\
-1 & 1 & 2 \\
2 & 0 & 1
\end{pmatrix} \\
C(A) & = \begin{pmatrix}
1 & 5 & -2 \\
0 & -1 & 0 \\
-1 & -3 & 1 \\
\end{pmatrix}
\end{align*}
$$ A^{-1} = \frac{\adj{A}}{\det{A}} $$
Gaussian elimination can also be used: augmented matrix with $I_n$ on the right,
reduce to reduced row-echelon. If the left is of the form $I_n$, the right is
the inverse. If there is a zero row, $\det{A} = 0$, and the $A$ has no inverse.
\section*{Linear Transformations}
\begin{align*}
f: & ~ \R^n \to \R^m \\
f & (x_1, \cdots, x_n) = (f_1(x_1, \cdots, x_n), f_2(x_1, \cdots, x_n), \cdots, f_m(x_1, \cdots, x_n))
\end{align*}
$f$ is a linear transformation if \(\forall i.~f_i(x_1, \cdots, x_n)\) is a
linear polynomial in $x_1, \cdots, x_n$ with a zero constant term
\begin{align*}
f(x_1,~ x_2) & = (x_1 + x_2,~ 3x_1 - x_2,~ 10x_2) \tag{is a linear transformation} \\
g(x_1,~ x_2,~ x_3) & = (x_1 x_2,~ x_3^2) \tag{not a linear transformation} \\
h(x_1,~ x_2) & = (3x_1 + 4,~ 2x_2 - 4) \tag{not a linear transformation} \\
\end{align*}
\[f: \R^n \to \R^m = \vec{x} \to A\vec{x} \]
\[\exists \text{ a matrix $A$ of dimension $n$x$m$ } \forall\text{ linear transforms } f \]
\[\forall \text{ matrices $A$ of dimension $n$x$m$ } \exists \text{ a linear transform $f$ of dimension $n$x$m$ such that } f(\vec{x}) = A\vec{x} \]
Function composition of linear translations is is just matrix multiplication:
\begin{align*}
f(\vec{x}) & = A\vec{x} \\
g(\vec{y}) & = B\vec{y} \\
(f\cdot g)(\vec{x}) & = g(f(\vec{x})) = BA\vec{x}
\end{align*}
A function \(f: \R^n \to \R^m\) is a linear transformation iff:
\begin{enumerate}
\item $f(\vec{x} + \vec{y}) = f(\vec{x}) + f(\vec{y}) \quad \forall~\vec{x},~\vec{y} \in \R^n $
\item $f(r\vec{x}) = r\cdot f(\vec{x}) \quad \forall~\vec{x} \in \R^n, r \in \R $
\end{enumerate}
\subsection*{Building the matrix of a linear transform}
\[ f(\vec{x}) = f(x_1\vec{e}_1 + x_2\vec{e}_2) = f(x_1\vec{e}_1) + f(x_2\vec{e}_2) = x_1f(\vec{e}_1) + x_2f(\vec{e}_2) \]
\[ A = \begin{pmatrix} f(\vec{e}_1) & f(\vec{e}_2) \end{pmatrix} \]
\begin{align*}
& \vec{e}_1 = \begin{pmatrix} 1 \\ 0 \end{pmatrix}
\\ & \vec{e}_2 = \begin{pmatrix} 0 \\ 1 \end{pmatrix}
\\ & \vdots
\\ & \forall \vec{x}.~ \vec{x} = \sum_{i}^{n}~\vec{e}_i x_i
\end{align*}
\subsection*{Composition}
\[ \paren{f \cdot g}\paren{\vec{x}} = f(g(\vec{x})) = AB\vec{x} \]
where: $f(\vec{x}) = A\vec{x}$, $g(\vec{x}) = B\vec{x}$
\subsection*{Geometry}
\begin{description}
\item[rotation of $x$ by $\theta$ anticlockwise] \( = R_\theta = \begin{pmatrix} \cos{\theta} & -\sin{\theta} \\ \sin{\theta} & \cos{\theta} \end{pmatrix} \)
\item[reflection about a line at angle $\alpha$ from the $x$-axis] \( = T_\alpha = R_{\alpha}T_0R_{-\alpha}\) where \( T_0 = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} \)
\item[scaling by $\lambda \in \R$] \( = S_\lambda = \lambda I_n\)
\item[Skew by $\alpha$ in $x$ and $\gamma$ in $y$] \( \begin{pmatrix} \alpha & 0 \\ 0 & \gamma \end{pmatrix}\)
\end{description}
The image of the unit square under the linear transform $A$ is a parallelogram of $(0, 0)$, $(a_{11}, a_{21})$, $(a_{12}, a_{22})$, $(a_{11} + a_{12}, a_{21} + a_{22})$, with area $ \abs{\det{A}} $
\subsection*{Inversion}
Inversion of a linear transformation is equivalent to inversion of its representative matrix
\subsection*{Eigen\{values, vectors\}}
\[ \begin{pmatrix} a & 0 \\ 0 & b \end{pmatrix}\begin{pmatrix} 1 \\ 0 \end{pmatrix} = \begin{pmatrix} a \\ 0 \end{pmatrix} = a\vec{e}_1\]
\[ \begin{pmatrix} a & 0 \\ 0 & b \end{pmatrix}\begin{pmatrix} 0 \\ 1 \end{pmatrix} = \begin{pmatrix} 0 \\ b \end{pmatrix} = b\vec{e}_2\]
\[ T_\alpha \vec{x} = \vec{x} \text{ for $\vec{x}$ along the line of transformation }\]
\begin{description}
\item[Eigenvector (of some transformation $f$)] A non-zero vector $\vec{x}$ such that $f(\vec{x}) = \lambda\vec{x}$ for some value $\lambda$
\item[Eigenvalue] $\lambda$ as above
\end{description}
\[ \forall \text{ eigenvectors of $A$ } \vec{x}, c \in R, \neq 0 .~ c\vec{x} \text{ is an eigenvector with eigenvalue } \lambda\]
\[ \forall A: \text{$n$x$n$ matrix}.\quad P_A\paren{\lambda} = \det{\paren{A - \lambda I_n}} \tag{characteristic polynomial in $\lambda$}\]
Eigenvalues of $A$ are the solutions of $P_A\paren{\lambda} = 0$
\begin{align*}
& A\vec{x} = \lambda\vec{x} & x \neq 0\\
\iff & A\vec{x} - \lambda\vec{x} = 0 \\
\iff & (A - \lambda I_n)\vec{x} = 0 \\
\iff & \det{\paren{A - \lambda I_n}} = 0 \\
& \quad \text{ or $\paren{A - \lambda I_n}$ is invertible and $x = 0$ }
\end{align*}
\[ P_{R\theta}(\lambda) = \frac{2\cos{\theta} \pm \sqrt{-4\lambda^2\sin^2{\theta}}}{2}\]
\[ R_\theta \text{ has eigenvalues }\iff \sin{\theta} = 0 \]
\end{document}