not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

400 lines
13 KiB

  1. \documentclass[12pt]{article}%
  2. \usepackage{amsfonts}
  3. \usepackage{fancyhdr}
  4. \usepackage{comment}
  5. \usepackage[a4paper, top=2.5cm, bottom=2.5cm, left=2.2cm, right=2.2cm]%
  6. {geometry}
  7. \usepackage{times}
  8. \usepackage{amsmath}
  9. \usepackage{changepage}
  10. \usepackage{amssymb}
  11. \usepackage{enumitem}
  12. \usepackage{algorithm}
  13. \usepackage[noend]{algpseudocode}
  14. \usepackage{scrextend}
  15. \usepackage{graphicx}%
  16. \setcounter{MaxMatrixCols}{30}
  17. \newtheorem{theorem}{Theorem}
  18. \newtheorem{acknowledgement}[theorem]{Acknowledgement}
  19. \newtheorem{algorithm}[theorem]{Algorithm}
  20. \newtheorem{axiom}{Axiom}
  21. \newtheorem{case}[theorem]{Case}
  22. \newtheorem{claim}[theorem]{Claim}
  23. \newtheorem{conclusion}[theorem]{Conclusion}
  24. \newtheorem{condition}[theorem]{Condition}
  25. \newtheorem{conjecture}[theorem]{Conjecture}
  26. \newtheorem{corollary}[theorem]{Corollary}
  27. \newtheorem{criterion}[theorem]{Criterion}
  28. \newtheorem{definition}[theorem]{Definition}
  29. \newtheorem{example}[theorem]{Example}
  30. \newtheorem{exercise}[theorem]{Exercise}
  31. \newtheorem{lemma}[theorem]{Lemma}
  32. \newtheorem{notation}[theorem]{Notation}
  33. \newtheorem{problem}[theorem]{Problem}
  34. \newtheorem{proposition}[theorem]{Proposition}
  35. \newtheorem{remark}[theorem]{Remark}
  36. \newtheorem{solution}[theorem]{Solution}
  37. \newtheorem{summary}[theorem]{Summary}
  38. \newenvironment{proof}[1][Proof]{\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
  39. \newcommand{\Q}{\mathbb{Q}}
  40. \newcommand{\R}{\mathbb{R}}
  41. \newcommand{\C}{\mathbb{C}}
  42. \newcommand{\Z}{\mathbb{Z}}
  43. \documentclass{minimal}
  44. \usepackage{mathtools}
  45. \DeclarePairedDelimiter\ceil{\lceil}{\rceil}
  46. \DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
  47. \begin{document}
  48. \title{Homework 3}
  49. \author{Jeffery Russell}
  50. \date{\today}
  51. \maketitle
  52. \section{Strassen's algorithm}
  53. \begin{enumerate}[label=(\alph*)]
  54. \item
  55. $$
  56. \begin{bmatrix}
  57. 1 & 3\\
  58. 7 & 5
  59. \end{bmatrix} \odot
  60. \begin{bmatrix}
  61. 6 & 8\\
  62. 4 & 2
  63. \end{bmatrix}\\*
  64. $$
  65. $S_1 = 6, S_2 = 4$\\
  66. $S_3 = 12, S_4 = -2$\\
  67. $S_5 = 5, S_6 = 8$\\
  68. $S_9 = -6, S_{10} = 14$\\
  69. \\
  70. $P_1 = 1*6 = 6, P_2 = 4*2 = 8$\\
  71. $P_3 = 6*12 = 72, P_4 = -2*5 = -10$\\
  72. $P_5 = 6*8 = 48, P_6 = -2*6 = -12$\\
  73. $P_7 = -6*14 = -84$\\
  74. $$
  75. =
  76. \begin{bmatrix}
  77. c_{11} & c_{12}\\
  78. c_{21} & c_{22}
  79. \end{bmatrix} =
  80. \begin{bmatrix}
  81. (P_5 + P_4 - P_2 + P_6) & (P_1+P_2)\\
  82. (P_3+P_4) & (P-5+P_1 - P_3 + P_7)
  83. \end{bmatrix}
  84. $$
  85. $$
  86. =
  87. \begin{bmatrix}
  88. (48 + (-10) - 8 + (-12)) & (6 + 8)\\
  89. (72 + (-10)) & (48 + 6 - 72 - (-84))
  90. \end{bmatrix} =
  91. \begin{bmatrix}
  92. 18 & 14\\
  93. 62 & 66
  94. \end{bmatrix}
  95. $$
  96. \item
  97. $$
  98. A \odot B =
  99. \begin{cases}
  100. A*B & \text{if } A_{rows} = 1 \\
  101. \begin{bmatrix}
  102. c_{11} & c_{12}\\
  103. c_{21} & c_{22}
  104. \end{bmatrix} & \text{otherwise}
  105. \end{cases}
  106. $$
  107. Where:
  108. $A =
  109. \begin{bmatrix}
  110. A_{11} & A_{12}\\
  111. A_{21} & A_{22}
  112. \end{bmatrix}$
  113. $B =
  114. \begin{bmatrix}
  115. B_{11} & B_{12}\\
  116. B_{21} & B_{22}
  117. \end{bmatrix}$
  118. $c_{11} = A_{11} \odot B_{11} + A_{12} \odot B_{21}$\\
  119. $c_{12} = A_{11} \odot B_{12} + A_{12} \odot B_{22}$\\
  120. $c_{21} = A_{21} \odot B_{11} + A_{22} \odot B_{21}$\\
  121. $c_{22} = A_{21} \odot B_{12} + A_{22} \odot B_{22}$
  122. \newpage
  123. \begin{algorithm}
  124. \caption{Strassen's Algorithm}\label{euclid}
  125. \begin{algorithmic}[1]
  126. \Procedure{Strassen(A,B):}{}
  127. \State $\textit{n} \gets \text{number of rows in}\textit{ A}$
  128. \State $C \gets \textit{new n by n matrix}$
  129. \If {$\textit{n} = 1$}
  130. \State $c \gets A[1][1] * B[1][1]$
  131. \Else{}
  132. \State Sub partition A into 4 equal matrix quadrants A11, A12, A21, A22
  133. \State Sub partition B into 4 equal matrix quadrants B11, B12, B21, B22
  134. \State $s1 \gets B12 - B22$
  135. \State $s2 \gets A11 + A12$
  136. \State $s3 \gets A21 + A22$
  137. \State $s4 \gets B21 - B11$
  138. \State $s5 \gets A11 + A22$
  139. \State $s6 \gets B11 + B22$
  140. \State $s7 \gets A12 - A22$
  141. \State $s8 \gets B21 + B22$
  142. \State $s9 \gets A11 - A21$
  143. \State $s10 \gets B11 + B12$
  144. \State $p1 \gets Strassen(A11,S1)$
  145. \State $p2 \gets Strassen(S2,B22)$
  146. \State $p3 \gets Strassen(S3,B11)$
  147. \State $p4 \gets Strassen(A22,S4)$
  148. \State $p5 \gets Strassen(S5,S6)$
  149. \State $p6 \gets Strassen(S7,S8)$
  150. \State $p7 \gets Strassen(S9,S10)$
  151. \State $C[1][1] \gets p5 + p4 - p2 + p6$
  152. \State $C[1][2] \gets p1 + p2$
  153. \State $C[2][1] \gets p3 + p4$
  154. \State $C[2][2] \gets p5 + p1 - p3 + p7$
  155. \EndIf
  156. \State \textbf{return} C
  157. \EndProcedure
  158. \end{algorithmic}
  159. \end{algorithm}
  160. \item
  161. $T(1) = 1$\\
  162. $T(n) = 7T(\frac{n}{2}) + \frac{9}{2}n^2$\\
  163. $T(2^0) = 1$\\
  164. $T(2^m) = 7T(2^{m-1}) + \frac{9}{2}(2^m)^2$\\
  165. $= 7(7T(n^{m-2}) + \frac{9}{2}(2^{m-1})^2) + \frac{9}{2}(2^m)^2$\\
  166. $= 7^2T(n^{m-2}) + 7*\frac{9}{2}(2^{m-1})^2 + 7^0*\frac{9}{2}(2^m)^2$\\
  167. $= 7^2(7T(2^{m-3}) + \frac{9}{2}(2^{m-2})^2) + 7*\frac{9}{2}(2^{m-1})^2 + 7^0*\frac{9}{2}(2^m)^2$\\
  168. $= 7^3T(2^{m-3}) + 7^2\frac{9}{2}(2^{m-2})^2 + 7*\frac{9}{2}(2^{m-1})^2 + 7^0*\frac{9}{2}(2^m)^2$\\
  169. $= 7^kT(2^{m-k}) + 7^{(k-1)}\frac{9}{2}(2^{m-(k-1)})^2 + ... + 7^{k-k}*\frac{9}{2}(2^{m-(k-k)})^2$\\
  170. Let $m = k$\\
  171. $T(2^m)= 7^mT(2^{m-m}) + 7^{(m-1)}\frac{9}{2}(2^{m-(m-1)})^2 + ... + 7^{m-m}*\frac{9}{2}(2^{m-(m-m)})^2$\\
  172. $T(2^m)= 7^m + 7^{(m-1)}\frac{9}{2}(2^{1})^2 + ... + 7^{0}*\frac{9}{2}(2^{m})^2$\\
  173. $= 7^m + \frac{9}{2}\sum_{k=0}^{m-1}7^k(2^{m-k})^2$\\
  174. $= \frac{9}{2}\sum_{k=0}^{m}7^k(2^{2(m-k)}) - \frac{9}{2}7^m$\\
  175. $= \frac{9}{2}\sum_{k=0}^{m}7^k(2^{2m})(2^{-2k}) - \frac{9}{2}7^m$\\
  176. $= (2^{2m})\frac{9}{2}\sum_{k=0}^{m}7^k(2^{-2k}) - \frac{9}{2}7^m + 7^m$\\
  177. $= (2^{2m})\frac{9}{2}\sum_{k=0}^{m}\frac{7^k}{2^{2k}}) - \frac{7}{2}7^m$\\
  178. $= (2^{2m})\frac{9}{2}\sum_{k=0}^{m}(\frac{7}{4})^k - \frac{7}{2}7^m$\\
  179. $= (2^{2m})\frac{9}{2}(\frac{\frac{7}{4}^{m+1} -1)}{1.75-1}) - \frac{7}{2}7^m$\\
  180. $= (2^m)^2\frac{9}{2}\frac{4}{3}((\frac{7}{4})^{m+1}-1) - (\frac{7}{2})7^m$\\
  181. $= 6(2^m)^2((\frac{7}{4})^{m+1}-1) - (\frac{7}{2})7^m$\\
  182. $= 6(2^m)^2\frac{7}{4} - 6(2^m)^2 - (\frac{7}{2})7^m$\\
  183. $= \frac{21*7^m}{2} - 6(2^m)^2 - (\frac{7}{2})7^m$\\
  184. $= 7*7^m - 6 * 4^m$\\
  185. $T(n)= 7*n^{lg(7)} - 6 * n^2$\\
  186. $T(n) \approx 7*n^{2.81} - 6 * n^2$\\
  187. \item Modifying Strassen's Algorithm
  188. To make Strassen's algorithm to work with any n x n matrix we would pad the two matrices being multiplied with zeros to become two m x m matrix where m is a power of 2. The answer would be the result but only taking out the n x n section out of the m x m product.\\
  189. To prove that this is still asymptotically equal we will demonstrate that at most the dimensions of the matrix being multiply double.
  190. let m = length of new padded matrices being multiplied \\
  191. let n = length of original matrices being multiplied \\
  192. Since:
  193. $2^{k-1} < n < 2^k = m$\\
  194. Note:
  195. $2n > 2^{k+1} > m$\\
  196. Hence:
  197. $T(n) \in \Theta((2n)^{lg(7)}) = \Theta(n^{lg7})$
  198. \item
  199. $(a+bi)(c+di)$\\
  200. $= ac + adi + bci + bdi^2$\\
  201. $= ac + adi + bci - bd$\\
  202. $Real Part= ac - bd$\\
  203. $Imaginary Part= (a + b)(c+d) -ac - bd$\\
  204. Consider:\\
  205. $A_1 = ac$\\
  206. $A_2 = bd$\\
  207. $A_3 = (a+b)(c+d)$\\
  208. Then:\\
  209. Real Part = $A_1 - A_2$\\
  210. Imaginary Part = $A_3 - A_1 - A_2$\\
  211. \end{enumerate}
  212. \section{Recurrence}
  213. \begin{enumerate}[label=(\alph*)]
  214. \item
  215. \textbf{Lemma 1}: For any n $\in \mathbb{N}, \left\lfloor\dfrac{n+1}{2}\right\rfloor = \left\lceil\dfrac{n}{2}\right\rceil$\\
  216. \textbf{Proof By Cases:}\\
  217. \textbf{Even Case:}\\
  218. n can be represented as 2m for some value of m\\
  219. $LHS = \left\lfloor\dfrac{n+1}{2}\right\rfloor = \left\lfloor\dfrac{2m+1}{2}\right\rfloor$\\
  220. $=\left\lfloor m + \dfrac{1}{2}\right\rfloor = m$\\
  221. $RHS = \left\lceil\dfrac{n}{2}\right\rceil = \left\lceil\dfrac{2m}{2}\right\rceil$
  222. $=\left\lceil m \right\rceil = m = LHS$
  223. \textbf{Odd Case:}\\
  224. n can be represented as (2m + 1) for some value of m\\
  225. $LHS = \left\lfloor\dfrac{n+1}{2}\right\rfloor = \left\lfloor\dfrac{2m +1+1}{2}\right\rfloor$\\
  226. $=\left\lfloor m + 1\right\rfloor = m +1$\\
  227. $RHS = \left\lceil\dfrac{n}{2}\right\rceil = \left\lceil\dfrac{2m +1}{2}\right\rceil$
  228. $=\left\lceil m + \dfrac{1}{2} \right\rceil = m +1 = LHS$
  229. $\Box$\\
  230. \item
  231. \textbf{Lemma 2}: For any n $\in \mathbb{N}, \left\lfloor\dfrac{n}{2}\right\rfloor + 1 = \left\lceil\dfrac{n+1}{2}\right\rceil$
  232. \textbf{Proof By Cases:}\\
  233. \textbf{Even Case:}\\
  234. n can be represented as 2m for some value of m\\
  235. $LHS = \left\lfloor\dfrac{n}{2}\right\rfloor +1= \left\lfloor\dfrac{2m}{2}\right\rfloor + 1$\\
  236. $=\left\lfloor m \right\rfloor = m + 1$\\
  237. $RHS = \left\lceil\dfrac{n + 1}{2}\right\rceil = \left\lceil\dfrac{2m + 1}{2}\right\rceil$
  238. $=\left\lceil m + \dfrac{1}{2} \right\rceil = m + 1 = LHS$
  239. \textbf{Odd Case:}\\
  240. n can be represented as (2m + 1) for some value of m\\
  241. $LHS = \left\lfloor\dfrac{n}{2}\right\rfloor + 1 = \left\lfloor\dfrac{2m + 1}{2}\right\rfloor + 1 = \left\lfloor m +\dfrac{1}{2}\right\rfloor + 1$\\
  242. $=\left\lfloor m \right\rfloor + 1 = m +1$\\
  243. $RHS = \left\lceil\dfrac{n + 1}{2}\right\rceil = \left\lceil\dfrac{2m + 1 +1}{2}\right\rceil$
  244. $=\left\lceil m + 1 \right\rceil = m +1 = LHS$\\
  245. $\Box$\\
  246. \item
  247. \textbf{Let:} $T(1) = 0, T(n) = T(\left\lfloor\dfrac{n}{2}\right\rfloor) + T(\left\lceil\dfrac{n}{2}\right\rceil) + n$\\
  248. \textbf{Let:} $D(n) = T(n+1) - T(n)$\\
  249. \textbf{Lemma 3:} $D(1) = 2$\\
  250. \textbf{Direct Proof:}\\
  251. $D(1) = T(2) - T(1)$\\
  252. $= T(\left\lfloor\dfrac{2}{2}\right\rfloor) + T(\left\lceil\dfrac{2}{2}\right\rceil) + 2 - T(0)$\\
  253. $= T(1) + T(1) + 2 - T(0)$\\
  254. $= 2$\\
  255. $\Box$\\
  256. \textbf{Lemma 4:} $D(n) = D(\left\lfloor\dfrac{n}{2}\right\rfloor) + 1$\\
  257. \textbf{Direct Proof:}\\
  258. $D(n) = T(n+1) - T(n)$\\
  259. $=T(\left\lfloor\dfrac{n + 1}{2}\right\rfloor) + T(\left\lceil\dfrac{n + 1}{2}\right\rceil) + (n+1) - T(n)$\\
  260. $=T(\left\lceil\dfrac{n}{2}\right\rceil) + T(\left\lfloor\dfrac{n}{2}\right\rfloor + 1) + (n+1) - T(n)$ \textit{by lemma 1, 2}\\
  261. $=T(\left\lceil\dfrac{n}{2}\right\rceil) + T(\left\lfloor\dfrac{n}{2}\right\rfloor + 1) + (n+1) - T(\left\lfloor\dfrac{n}{2}\right\rfloor) - T(\left\lceil\dfrac{n}{2}\right\rceil) - n$\\
  262. $=T(\left\lfloor\dfrac{n}{2}\right\rfloor + 1) - T(\left\lfloor\dfrac{n}{2}\right\rfloor) +1$\\
  263. $= D(\left\lfloor\dfrac{n}{2}\right\rfloor) + 1$\\
  264. $\Box$\\
  265. \item
  266. \textbf{Lemma 5:} For any $n \in \mathbb{N}$, if $n > 1$ and n is even then :\\
  267. $\left\lfloor lg(\left\lfloor\dfrac{n}{2}\right\rfloor)\right\rfloor = \left\lfloor\ lg(n) -1\right\rfloor$\\
  268. \textbf{Direct Proof:}\\
  269. Suppose that n is even:\\
  270. $\left\lfloor lg(\left\lfloor\dfrac{n}{2}\right\rfloor)\right\rfloor = \left\lfloor lg(\left\dfrac{n}{2}\right)\right\rfloor$ \textit{since n is even}\\
  271. $= \left\lfloor lg(n) - lg(2)\right\rfloor$\\
  272. $= \left\lfloor lg(n) - 1\right\rfloor$\\
  273. $= \left\lfloor lg(n)\right\rfloor -1$\\
  274. $\Box$\\
  275. \textbf{Lemma 6:} For any $m \in \mathbb{N}$, if $m > 0$ then:\\
  276. $\left\lfloor lg(\left\lfloor 2m+1 \right\rfloor)\right\rfloor = \left\lfloor\ lg(2m)\right\rfloor$\\
  277. \textbf{Direct Proof:}\\
  278. Let $k = \left\lfloor lg(\left\lfloor 2m+1 \right\rfloor)\right\rfloor$\\
  279. $\left\lfloor lg(\left\lfloor 2m+1 \right\rfloor)\right\rfloor = k \xrightarrow[]{} k \leq lg(2m + 1) < k + 1$\\
  280. $\xrightarrow[]{} 2^k \leq 2m+1 < 2^{k+1}$\\
  281. $\xrightarrow{} 2^{k} -1 \leq 2m < 2^{k+1} -1 \textit{by transitivity}$\\
  282. $\xrightarrow{} 2^k -1 \leq 2m < 2^{k+1}$\\
  283. $\xrightarrow[]{} 2^k \leq 2m < 2^{k+1}$\textit{Since 2m is even}\\
  284. $\xrightarrow{} k \leq lg(2m) < k + 1$\\
  285. $\xrightarrow{}\left\lfloor\ lg(2m)\right\rfloor = k$\\
  286. $\Box$\\
  287. \textbf{Lemma 7:} For any $n \in \mathbb{N}$, if $n > 1$ and n is odd then :\\
  288. $\left\lfloor lg(\left\lfloor\dfrac{n}{2}\right\rfloor)\right\rfloor = \left\lfloor\ lg(n) -1\right\rfloor$\\
  289. \textbf{Direct Proof:}\\
  290. $\left\lfloor lg(\left\lfloor\dfrac{n}{2}\right\rfloor)\right\rfloor = \left\lfloor\ lg(\dfrac{n-1}{2})\right\rfloor$\textit{Gets an even number since n is odd}\\
  291. $= \left\lfloor\ lg(n-1) - lg(2)\right\rfloor$\\
  292. $= \left\lfloor\ lg(n-1) - 1\right\rfloor$\\
  293. $= \left\lfloor\ lg(n-1)\right\rfloor -1$\\
  294. $= \left\lfloor\ lg(n)\right\rfloor -1$\textit{By lemma 6}\\
  295. $\Box$\\
  296. \textbf{Corollary 1:}
  297. By lemmas 5 and 7, for any $n \in \mathbb{N}$, if $n > 1$ then :\\
  298. $\left\lfloor lg(\left\lfloor\dfrac{n}{2}\right\rfloor)\right\rfloor = \left\lfloor\ lg(n) -1\right\rfloor$\\
  299. \textbf{Lemma 8:} For any for any $n \in \mathbb{N}$, if $n > 1$ then $D(n) = \left\lfloor\ lg(n)\right\rfloor +2$\\
  300. \textbf{Proof via Strong Induction:}\\
  301. \textbf{base case: n =1}\\
  302. $D(1) = 2$ \textit{lemma 3}\\
  303. $D(1) = \left\lfloor\ lg(1)\right\rfloor +2$\\
  304. $= 0 + 2 = 2$\\
  305. \textbf{Inductive Step:} Assume proposition holds up to but not including n.\\ Show that n follows.\\
  306. $D(n) = D(\left\lfloor\dfrac{n}{2} \right\rfloor) +1$\\
  307. $= \left\lfloor lg(\left\lfloor \dfrac{n}{2}\right\rfloor)\right\rfloor + 2 + 1$\textit{ By I.H}\\
  308. $=\left\lfloor\ lg(n)\right\rfloor -1 + 2 + 1$ \textit{ Corollary 1}\\
  309. $=\left\lfloor\ lg(n)\right\rfloor +2$\\
  310. $\Box$\\
  311. \item
  312. \textbf{Lemma 9:} $T(n) - T(1) = \sum^{n-1}_{k = 1}D(k)$\\
  313. \textbf{Direct Proof:}\\
  314. $\sum^{n-1}_{k = 1}D(k) = D(1) + D(2) + D(3) + ... + D(n-3) + D(n-2) + D(n-1)$\\
  315. $= T(2) - T(1) + T(3) - T(2) + T(4) - T(3) +\\ ... + T(n-2) - T(n-3) + T(n-1) - T(n-2) + T(n) - T(n-1)$\\
  316. $=T(n)-T(1)$\textit{Due to cancellations}\\
  317. $\Box$\\
  318. \textbf{Corollary 2:}\\
  319. By lemmas 9 and 8, $T(n) = \sum^{n-1}_{k = 1}\left\lfloor\ (lg(n) + 2)\right\rfloor$\\
  320. \item
  321. \textbf{Lemma 10:} $T(n) \in O(nlog(n))$\\
  322. $T(n) = \sum^{n-1}_{k = 1}\left\lfloor\ (lg(n) + 2)\right\rfloor$\\
  323. $= \sum^{n-1}_{k = 1}\left\lfloor\ (lg(n))\right\rfloor + \sum^{n-1}_{k = 1}2$\\
  324. $\leq nlg(n) + 2n$\\
  325. $\xrightarrow[]{} T(n) \in O(nlog(n))$\\
  326. $\Box$\\
  327. \end{enumerate}
  328. \end{document}