From 688d1ec426dd6d3a413deefd7e16f1f4c86eef15 Mon Sep 17 00:00:00 2001 From: bluepython508 Date: Wed, 1 Nov 2023 08:55:40 +0000 Subject: [PATCH] Initial work --- CS1029/notes-2023-09-19 | 6 + CS1029/notes-2023-09-20 | 4 + CS1029/notes-2023-09-26 | 2 + CS1029/notes-2023-10-03 | 0 CS1029/notes-2023-10-10 | 0 CS1029/notes-2023-10-11 | 8 + CS1029/notes-2023-10-17 | 1 + CS1029/notes-2023-10-18 | 1 + CS1029/notes-2023-10-24 | 0 CS1029/notes-2023-10-25 | 7 + CS1029/notes-2023-10-31 | 13 + CS1029/practical-2023-09-29/datasci | 11 + CS1029/practical-2023-09-29/numbers | 6 + CS1029/practical-2023-10-06/prop | 93 +++++++ CS1029/practical-2023-10-13/sets | 46 ++++ CS1029/practical-2023-10-20/functions | 52 ++++ CS1029/practical-2023-10-20/m.py | 22 ++ CS1029/practical-2023-10-20/sequences | 35 +++ CS1032/assesments | 5 + CS1032/notes-2023-09-21 | 2 + CS1032/notes-2023-09-28 | 1 + CS1032/notes-2023-10-05 | 1 + CS1032/notes-2023-10-06 | 1 + CS1032/notes-2023-10-12 | 1 + CS1032/notes-2023-10-13 | 1 + CS1032/notes-2023-10-26 | 0 CS1032/notes-2023-10-27 | 1 + .../practical-2023-09-27/challenges-1.janet | 4 + .../practical-2023-09-27/challenges-2.janet | 15 ++ .../practical-2023-09-27/challenges-5.janet | 8 + CS1032/practical-2023-09-27/forth.janet | 117 +++++++++ CS1032/practical-2023-10-04/tasks | 37 +++ CS1032/practical-2023-10-04/workshop.py | 14 + CS1032/practical-2023-10-18/fn1.py | 7 + CS1032/practical-2023-10-18/fn2.py | 20 ++ CS1032/practical-2023-10-18/fn3.py | 7 + CS1032/practical-2023-10-18/task1.py | 9 + CS1032/practical-2023-10-18/task2.py | 2 + CS1032/practical-2023-10-18/task3.py | 4 + CS1032/practical-2023-10-25/dicts | 13 + MA1006/complex.tex | 170 ++++++++++++ MA1006/decls.tex | 58 +++++ MA1006/linear.tex | 243 ++++++++++++++++++ MA1006/notes-2023-09-21 | 9 + MA1006/polynomials.tex | 34 +++ MA1006/tmpl.tex | 6 + MA1006/tut-2023-10-10.tex | 42 +++ MA1006/tut-2023-10-17.tex | 9 + 48 files changed, 1148 insertions(+) create mode 100644 CS1029/notes-2023-09-19 create mode 100644 CS1029/notes-2023-09-20 create mode 100644 CS1029/notes-2023-09-26 create mode 100644 CS1029/notes-2023-10-03 create mode 100644 CS1029/notes-2023-10-10 create mode 100644 CS1029/notes-2023-10-11 create mode 100644 CS1029/notes-2023-10-17 create mode 100644 CS1029/notes-2023-10-18 create mode 100644 CS1029/notes-2023-10-24 create mode 100644 CS1029/notes-2023-10-25 create mode 100644 CS1029/notes-2023-10-31 create mode 100644 CS1029/practical-2023-09-29/datasci create mode 100644 CS1029/practical-2023-09-29/numbers create mode 100644 CS1029/practical-2023-10-06/prop create mode 100644 CS1029/practical-2023-10-13/sets create mode 100644 CS1029/practical-2023-10-20/functions create mode 100644 CS1029/practical-2023-10-20/m.py create mode 100644 CS1029/practical-2023-10-20/sequences create mode 100644 CS1032/assesments create mode 100644 CS1032/notes-2023-09-21 create mode 100644 CS1032/notes-2023-09-28 create mode 100644 CS1032/notes-2023-10-05 create mode 100644 CS1032/notes-2023-10-06 create mode 100644 CS1032/notes-2023-10-12 create mode 100644 CS1032/notes-2023-10-13 create mode 100644 CS1032/notes-2023-10-26 create mode 100644 CS1032/notes-2023-10-27 create mode 100644 CS1032/practical-2023-09-27/challenges-1.janet create mode 100644 CS1032/practical-2023-09-27/challenges-2.janet create mode 100644 CS1032/practical-2023-09-27/challenges-5.janet create mode 100644 CS1032/practical-2023-09-27/forth.janet create mode 100644 CS1032/practical-2023-10-04/tasks create mode 100644 CS1032/practical-2023-10-04/workshop.py create mode 100644 CS1032/practical-2023-10-18/fn1.py create mode 100644 CS1032/practical-2023-10-18/fn2.py create mode 100644 CS1032/practical-2023-10-18/fn3.py create mode 100644 CS1032/practical-2023-10-18/task1.py create mode 100644 CS1032/practical-2023-10-18/task2.py create mode 100644 CS1032/practical-2023-10-18/task3.py create mode 100644 CS1032/practical-2023-10-25/dicts create mode 100644 MA1006/complex.tex create mode 100644 MA1006/decls.tex create mode 100644 MA1006/linear.tex create mode 100644 MA1006/notes-2023-09-21 create mode 100644 MA1006/polynomials.tex create mode 100644 MA1006/tmpl.tex create mode 100644 MA1006/tut-2023-10-10.tex create mode 100644 MA1006/tut-2023-10-17.tex diff --git a/CS1029/notes-2023-09-19 b/CS1029/notes-2023-09-19 new file mode 100644 index 0000000..1833599 --- /dev/null +++ b/CS1029/notes-2023-09-19 @@ -0,0 +1,6 @@ +Test in late October & late November, final exams in December (20%, 20%, 80%); all multiple choice? +Books: (reccommended) + - Discrete Mathematics and Its Applications, 8th edition,Kenneth H. Rosen + - Mathematics for Calculus, 6th edition. Stewart et al. + + diff --git a/CS1029/notes-2023-09-20 b/CS1029/notes-2023-09-20 new file mode 100644 index 0000000..9c0e26f --- /dev/null +++ b/CS1029/notes-2023-09-20 @@ -0,0 +1,4 @@ +Why must we review *rounding*, how negatives multiply, assoc/commut/distrib properties - all of this is early secondary school or primary school! + exponentiation, absolute values + + Is this not assumed knowledge?! diff --git a/CS1029/notes-2023-09-26 b/CS1029/notes-2023-09-26 new file mode 100644 index 0000000..5b0b005 --- /dev/null +++ b/CS1029/notes-2023-09-26 @@ -0,0 +1,2 @@ +# Propositional Logic + diff --git a/CS1029/notes-2023-10-03 b/CS1029/notes-2023-10-03 new file mode 100644 index 0000000..e69de29 diff --git a/CS1029/notes-2023-10-10 b/CS1029/notes-2023-10-10 new file mode 100644 index 0000000..e69de29 diff --git a/CS1029/notes-2023-10-11 b/CS1029/notes-2023-10-11 new file mode 100644 index 0000000..88e41f4 --- /dev/null +++ b/CS1029/notes-2023-10-11 @@ -0,0 +1,8 @@ +image = range +codomain: set that a function is stated to evaluate to; range: values that are possible from a function +onto function: surjection +bijective: injective & surjective +injective: \forall x, y \in \operatorname{Domain}.~ f(x) = f(y) \implies x = y \tag{one-to-one} +surjective: \forall y \in \operatorname{Codomain}.~\exists x \in \operatorname{Domain}.~ f(x) = y \tag{codomain = range} + +inverse only a function for bijective functions - not surjective means undefined for some values of the domain, not injective means multi-valued for some values of the domain diff --git a/CS1029/notes-2023-10-17 b/CS1029/notes-2023-10-17 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CS1029/notes-2023-10-17 @@ -0,0 +1 @@ + diff --git a/CS1029/notes-2023-10-18 b/CS1029/notes-2023-10-18 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CS1029/notes-2023-10-18 @@ -0,0 +1 @@ + diff --git a/CS1029/notes-2023-10-24 b/CS1029/notes-2023-10-24 new file mode 100644 index 0000000..e69de29 diff --git a/CS1029/notes-2023-10-25 b/CS1029/notes-2023-10-25 new file mode 100644 index 0000000..bc48811 --- /dev/null +++ b/CS1029/notes-2023-10-25 @@ -0,0 +1,7 @@ +Closure of a relation R is the smallest relation containing R and meeting a property + EG. reflexive closure of R (on A) is R | { (a, a) | a \in A } + symmetric closure of R is R | mirror(R) + +Equivalent: R is reflexive, symmetric, and transitive - f(x) = f(y) for some function f +Equivalence classes: sets of values which R considers equivalent + disjoint, nonempty subsets of domain \ No newline at end of file diff --git a/CS1029/notes-2023-10-31 b/CS1029/notes-2023-10-31 new file mode 100644 index 0000000..cc20ebf --- /dev/null +++ b/CS1029/notes-2023-10-31 @@ -0,0 +1,13 @@ +Simple Graph: unique connections, no reflexive connections +Multigraphs: multiple connections between two vertices permitted +Directed graphs/digraph +Pseudograph: permits self-links +Degree of vertex in an undirected graph: edges connected to vertex (loops contribute twice) + in a directed graph: in-degree is edges pointing to a vertex, out-degree is pointing out + +Pendant vertex has degree 1 +Sum of the degree of all vertices in an undirected graphs is twice the number of edges: handshake theorem +Bipartite: can be partitioned into two sets of vertices such that no edge connects two vertices in the same set + Complete bipartite: two vertices are connected \iff they are in seperate partitions + + Matching in a bipartite graph: find a subgraph such that all vertices have *exactly* 1 edge attached \ No newline at end of file diff --git a/CS1029/practical-2023-09-29/datasci b/CS1029/practical-2023-09-29/datasci new file mode 100644 index 0000000..efe4e3f --- /dev/null +++ b/CS1029/practical-2023-09-29/datasci @@ -0,0 +1,11 @@ +Books: id.loc.gov + Library of Congress linked data + Already in relatively usable formats: XML, JSONLD, etc; further work would be dependent on type of analysis + +Disease risk: data.gov.ie - large amounts of discharge data in Health/HSE section + Something could be stitched together estimating risks + +Universities: https://www.ucas.com/data-and-analysis/undergraduate-statistics-and-reports + All CSVs in zips + + diff --git a/CS1029/practical-2023-09-29/numbers b/CS1029/practical-2023-09-29/numbers new file mode 100644 index 0000000..828ad80 --- /dev/null +++ b/CS1029/practical-2023-09-29/numbers @@ -0,0 +1,6 @@ +06. 1 0 1/2 π +07. commutativity (+), commutativity (*), associativity (+), associativity (*), distributivity of * over + +08. 3x+3y 8a-8b 28y-14x 3ab+3ac-6ad +09. 17/30 9/20 3 1/36 +11. 100 -12 6/24 2 -1 1 +13. 109.9884 48.36 30.24 42313990.36 diff --git a/CS1029/practical-2023-10-06/prop b/CS1029/practical-2023-10-06/prop new file mode 100644 index 0000000..23c078d --- /dev/null +++ b/CS1029/practical-2023-10-06/prop @@ -0,0 +1,93 @@ +01. TFTF----FF +02. a) Linda is older than Sanjay (given that age is continuous) + b) Mei does not make more money than Isabella (salaries are discrete) + c) Moshe is shorter than Monica (height is continuous) + d) Abby is not richer than Ricardo (is wealth continuous?) + e) Quincy is not smarter than Venkat (unquantifiable ∴ continuous) + f) 2 + 1 /= 3 + g) The summer in Maine is not hot and sunny + i) Jennifer and Teja are not friends +03. TTFF +4 a) I did not buy a lottery ticket this week + b) I bought a lottery ticket this week and I won the million dollar jackpot + c) If I bought a lottery ticket this week, I won the million dollar jackpot + d) I bought a lottery ticket this week, or I won the million dollar jackpot + e) I bought a lottery ticket if and only if I won the million dollar jackpot + f) If I didn't buy a lottery ticket this week, I didn't win the million dollar jackpot + g) I didn't buy a lottery ticket this week, and I didn't win the million dollar jackpot + h) I didn't buy a lottery ticket this week, or I did buy a lottery ticket this week and I won the million dollar jackpot + -> If I bought a lottery ticket this week, I won the million dollar jackpot +05. a) !p + b) p & !q + c) p -> q + d) !p -> !q + e) p -> q + f) q & !p + g) p <-> q +06. a) r & !p + b) !p & q & r + c) r -> (!p <-> q) + d) !q & !p & r + e) q -> (!r & !p) + f) (p & r) -> !q +07. TFTF +08. FTTT +09. a) If one does not wash the boss's car, one is not promoted + b) If there exist winds from the south, there will exist a spring thaw + c) If the computer was bought less than a year ago, the warranty is good + d) If Willy cheats, he is caught + e) If you do not pay a subscription fee, you cannot access the website + f) If one knows the right people, one is elected + g) If Carol is on a boat, she gets seasick +10. a) p !p p -> !p + T F F + F T T + b) p !p p <-> !p + T F F + F T F + c) p q p ^ (p | q) (== !p & q) + T T F + T F F + F T T + F F F + d) p q (p | q) -> (p & q) + T T T + T F F + F T T + F F T +11. OR AND XOR + 111_1111 000_0000 111_1111 + 1111_1010 1010_0000 0101_1010 + 10_0111_1001 00_0100_0000 10_0011_1001 +12. a) 11000 + b) 10001 + +13. + a) p q r (p | q) ((p | q) | r) (q | r) (p | (q | r)) + T T T T T T T + T T F T T T T + T F T T T T T + T F F T T F T + F T T T T T T + F T F T T T T + F F T F T T T + F F F F F F F + b) p q r (p & q) ((p & q) & r) (q & r) (p & (q & r)) + T T T T T T T + T T F T F F F + T F T F F F F + T F F F F F F + F T T F F T F + F T F F F F F + F F T F F F F + F F F F F F F + +14. a) Jan is not rich or is not happy + b) Carlos will not run and will not bicycle tomorrow + c) Mei does not walk and does not take the bus to class + d) Ibrahim is not smart or is not hard-working + +15. (p -> q) & (p -> r) + ≣ (!p | q) & (!p | r) # Definition of -> + ≣ (!p | (q & r)) # Distribution of | over & + ≣ p -> (q & r) # Definition of -> \ No newline at end of file diff --git a/CS1029/practical-2023-10-13/sets b/CS1029/practical-2023-10-13/sets new file mode 100644 index 0000000..35873c7 --- /dev/null +++ b/CS1029/practical-2023-10-13/sets @@ -0,0 +1,46 @@ +1. a) the students who either live within 1 mile of the school or who walk to classes + b) the students who live within 1 mile of the school and walk to classes + c) the students who live within 1 mile of the school and do not walk to classes + d) the students who walk to classes and do not live within 1 mile of the school + +2. a) { 0, 1, 2, 3, 4, 5, 6 } + b) { 3 } + c) { 1, 2, 4, 5 } + d) { 0, 6 } + +3. a) { a, b, c, d, e, f, g, h } + b) { a, b, c, d, e } + c) {} + d) { f, g, h } + +5. A \union B = { x | x in A || x in B }; commutative as OR is commutative + A \intersect B = { a | x in A && x in B }; commutative as AND is commutative + +6. A - B = { x | x \in A \and x \nin B } + !B = { x | x \nin B } + A & !B = { x | x \in A \and x \in !B } = { x | x \in A \and x \nin B } + + (A & B) | (A & !B) = (A | A) & (B | !B) (distribution of & over |) + = A & U + = A + +7. a) { 4 6 } + b) { 0 1 2 3 4 5 6 7 8 9 10 } + c) { 4 5 6 8 10 } + d) { 0 2 4 5 6 7 8 9 10 } + +9. { 2 5 } + +11. A ^ B = { x | x in A ^ x in B } = { x | (x in A | x in B) & !(x in A & x in B) } + = { x | x in A | x in B } - { x | x in A & x in B } + = (A | B) - (A & B) + +12. a) { a: 3, b: 3, c: 1, d: 4 } + b) { a: 2, b: 2 } + c) { a: 1, c: 1 } + d) { b: 1, d: 4 } + e) { a: 5, b: 5, c: 1, d: 4} + +14. A_i = { x | x in Z, x <= i } + a) A_1 + b) A_n diff --git a/CS1029/practical-2023-10-20/functions b/CS1029/practical-2023-10-20/functions new file mode 100644 index 0000000..e2abea1 --- /dev/null +++ b/CS1029/practical-2023-10-20/functions @@ -0,0 +1,52 @@ +1. a) f(x) is undefined for x = 0 + b) f(x) is complex for x < 0 + c) multivalued + +2. a) multivalued + b) It is + c) undefined at x = 2 + +3. a) Z >= 0, {0..9} + b) 0.. -> 1..? + c) All bit strings -> N + d) All bit strings -> N + e) (Z^+)^2 -> Z^+ + f) (Z^+)^2 -> Z^+ + +4. a) 1 b) 2 c) -1 d) 0 e) 2 f) 3 g) 0 h) 2 +5. a) 1 b) 0 c) 0 d) -1 e) 3 f) -1 g) 2 h) 1 + +8. a) 6 b) 24 c) 120 d) 3_628_800 + +10. a)y b)n c)n +11. {a} + +12. a) y b) n c) n d) n +13. a) y b) n) c) y) d) n + +14. ynyy + +15. a) everyone has a phone number (phone numbers should already be uniquie) + b) None (student ids should already be unique) + c) Every student gets a unique grade + d) no two people come from the same town + +16. a) the set of phone numbers + b) the set of student ids + c) 1..100 + d) all towns + +17. ynnn +18. a) { 1 } + b) { -1, 1, 5, 9, 15 } + c) { 0, 1, 2 } + d) { 0, 1, 2 } + +19. f.g = x^2 + 4x + 5, g.f = x^2 + 3 +20. f + g = x^2 + x + 3 + fg = x^3 + 2x^2 + x + 2 + +21. f^-1 doesn't exist, assuming f^-1(x) = +sqrt(x) + a) { 1 } + b) { x | 0 < x < 1 } + c) { x | x > 2 } \ No newline at end of file diff --git a/CS1029/practical-2023-10-20/m.py b/CS1029/practical-2023-10-20/m.py new file mode 100644 index 0000000..873eada --- /dev/null +++ b/CS1029/practical-2023-10-20/m.py @@ -0,0 +1,22 @@ +def floor(n): + return n - (n % 1) + +def ceil(n): + return n - (n % -1) + + +assert floor(-1) == -1 +assert floor(1) == 1 +assert floor(1.2) == 1 +assert floor(-1.2) == -2 +assert floor(0) == 0 +assert floor(0.1) == 0 +assert floor(-0.1) == -1 +assert ceil(-1) == -1 +assert ceil(1) == 1 +assert ceil(1.2) == 2 +assert ceil(-1.2) == -1 +assert ceil(0) == 0 +assert ceil(0.1) == 1 +assert ceil(-0.1) == 0 + diff --git a/CS1029/practical-2023-10-20/sequences b/CS1029/practical-2023-10-20/sequences new file mode 100644 index 0000000..879d214 --- /dev/null +++ b/CS1029/practical-2023-10-20/sequences @@ -0,0 +1,35 @@ +1. a) 3 + b) -1 + c) 787 + d) 2639 + +2. a) 128 + b) 7 + c) 2 + d) -256 + +3. a) 1, -2, 4, -8 + b) 3, 3, 3, 3 + c) 8, 13, 23, 71 + d) 2, 0, 8, 0 + +4. a) 2, 5, 8, 11, 14, 17, 20, 23, 26, 29 + b) 0, 0, 0, 1, 1, 1, 2, 2, 2, 3 + c) 1, 1, 3, 3, 5, 5, 7, 7, 9, 9 + d) 3, 6, 12, 24, 48, 96, 192, 384, 768, 1336 + +5. a_0 = 3, a_n = a_{n - 1} + 2 (i.e. the odd integers starting at 3) + the primes starting at three + - one more + +6. a) 2, 12, 72, 432, 2592 + b) 2, 4, 16, 256, 65536 + c) 1, 2, 5, 11, 26 + d) 1, 1, 6, 27, 204 + +7. a) a_n = -3a_{n-1} + 4a_{n-2} = -3(0) + 4(0) = 0 = a_n + b) a_n = -3(1) + 4(1) = 4 - 3 = 1 = a_n + c) a_n = -3((-4)^{n-1}) + 4((-4)^{n-2}) = -3(-4)(-4^{n-2}) + 4((-4)^{n-2}) = (-4)^{n-2}((-3)(-4) + 4) = (-4)^{n-1}(-3 - 1) = (-4)^n = a_n + d) a_n = -3(2*(-4)^{n-1} + 3) + 4(2 * (-4)^{n-2} + 3) = -6(-4)^{n-1} - 9 - 2(-4)^{n-1} + 12 = -8(-4)^{n-1} + 3 = 2(-4)^n + 3 = a_n + +8. \ No newline at end of file diff --git a/CS1032/assesments b/CS1032/assesments new file mode 100644 index 0000000..6ef8160 --- /dev/null +++ b/CS1032/assesments @@ -0,0 +1,5 @@ +Type of Assessment |ILOs (7)|% Weighting|Release Date|Due Time|Due Date |C6|Feedback Due |Feedback Provided +Online MCQ Test 1 (1hour/48hour)|1,2,3,5 |20 |09/10/2023 |23:59 |11/10/2023 | |25/10/2023 | +Programming Exercise |7 |30 |16/10/2023 |23:59 |06/11/2023 | |20/11/2023 | +Exam (2h, on campus, MCQ) |4,5,6 |50 | | |Assessment Weeks| |After Exam Mtg.| + |100 | | | | | | | diff --git a/CS1032/notes-2023-09-21 b/CS1032/notes-2023-09-21 new file mode 100644 index 0000000..54fd6ec --- /dev/null +++ b/CS1032/notes-2023-09-21 @@ -0,0 +1,2 @@ +Look into industry projects + diff --git a/CS1032/notes-2023-09-28 b/CS1032/notes-2023-09-28 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CS1032/notes-2023-09-28 @@ -0,0 +1 @@ + diff --git a/CS1032/notes-2023-10-05 b/CS1032/notes-2023-10-05 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CS1032/notes-2023-10-05 @@ -0,0 +1 @@ + diff --git a/CS1032/notes-2023-10-06 b/CS1032/notes-2023-10-06 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CS1032/notes-2023-10-06 @@ -0,0 +1 @@ + diff --git a/CS1032/notes-2023-10-12 b/CS1032/notes-2023-10-12 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CS1032/notes-2023-10-12 @@ -0,0 +1 @@ + diff --git a/CS1032/notes-2023-10-13 b/CS1032/notes-2023-10-13 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CS1032/notes-2023-10-13 @@ -0,0 +1 @@ + diff --git a/CS1032/notes-2023-10-26 b/CS1032/notes-2023-10-26 new file mode 100644 index 0000000..e69de29 diff --git a/CS1032/notes-2023-10-27 b/CS1032/notes-2023-10-27 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CS1032/notes-2023-10-27 @@ -0,0 +1 @@ + diff --git a/CS1032/practical-2023-09-27/challenges-1.janet b/CS1032/practical-2023-09-27/challenges-1.janet new file mode 100644 index 0000000..51eb052 --- /dev/null +++ b/CS1032/practical-2023-09-27/challenges-1.janet @@ -0,0 +1,4 @@ +(def names ["Monkey" "Rooster" "Dog" "Pig" "Rat" "Ox" "Tiger" "Hare" "Dragon" "Snake" "Horse" "Sheep"]) + + +(defn main [_ arg] (print (names (% (scan-number arg) 12)))) \ No newline at end of file diff --git a/CS1032/practical-2023-09-27/challenges-2.janet b/CS1032/practical-2023-09-27/challenges-2.janet new file mode 100644 index 0000000..fa6159f --- /dev/null +++ b/CS1032/practical-2023-09-27/challenges-2.janet @@ -0,0 +1,15 @@ +(def grades { + "A+" "4.0" + "A" "4.0" + "A-" "3.7" + "B+" "3.3" + "B" "3.0" + "B-" "2.7" + "C+" "2.3" + "C" "2.0" + "C-" "1.7" + "D+" "1.3" + "D" "1.0" +}) + +(defn main [_ arg] (print (or (grades arg) "Not a grade"))) \ No newline at end of file diff --git a/CS1032/practical-2023-09-27/challenges-5.janet b/CS1032/practical-2023-09-27/challenges-5.janet new file mode 100644 index 0000000..b56d7ad --- /dev/null +++ b/CS1032/practical-2023-09-27/challenges-5.janet @@ -0,0 +1,8 @@ +(def old (peg/compile ~(* (repeat 3 (range "AZ")) " " (repeat 3 (range "09")) -1))) +(def new (peg/compile ~(* (repeat 4 (range "09")) " " (repeat 3 (range "AZ")) -1))) + +(defn main [_ arg] (print (cond + (peg/match old arg) "Old" + (peg/match new arg) "New" + true "Not a license plate" +))) \ No newline at end of file diff --git a/CS1032/practical-2023-09-27/forth.janet b/CS1032/practical-2023-09-27/forth.janet new file mode 100644 index 0000000..7400aa8 --- /dev/null +++ b/CS1032/practical-2023-09-27/forth.janet @@ -0,0 +1,117 @@ +(def grammar (peg/compile ~{ + :main (* :tok (any (* :s+ :tok)) -1) + :tok (+ (<- :word) (number (some (+ (range "09") ".")))) + :word (* :init-char (any :rest-char)) + :init-char (+ (range "AZ") (range "az") (set ":/{}><,.[]+=-_*&^%$#@!;()")) + :rest-char (+ :init-char (range "09")) +})) + +# State @{ :dictionary @{ word { :definition [word] :immediate } } :stack @[] :mode fn } +(defn immediate [state word] + (cond + (or (number? word) (array? word) (tuple? word)) (array/push (state :stack) word) + (let + (word (or ((state :dictionary) word) (error (string "No such word defined: " word)))) + ((word :definition) state) +))) + +(defn deferred [state word] (let + (definition ((state :dictionary) word)) (if (and definition (definition :immediate)) + (immediate state word) + (array/push (array/peek (state :stack)) word) +))) + +(defmacro fixed-word [args ret] ~{ + :definition (fn [state] + (do + ,;(map (fn [name] ~(def ,name (,array/pop (state :stack)))) (reverse args)) + (array/concat (state :stack) ,ret) + ) + ) +}) + +(defn run-state [state words] + (loop [word :in words] (:mode state word)) +) + +(defn word-as [& words] { :definition (fn [state] (run-state state words)) }) + +(defn truthy [a] (and a (not (= a 0)))) + +(def std-dict @{ + "pick" (fixed-word [a b] [a b a]) + "drop" (fixed-word [a] []) + "swap" (fixed-word [a b] [b a]) + "dup" (fixed-word [a] [a a]) + "-" (fixed-word [a b] (- a b)) + "+" (fixed-word [a b] (+ a b)) + "*" (fixed-word [a b] (* a b)) + "/" (fixed-word [a b] (/ a b)) + "=" (fixed-word [a b] (= a b)) + ">" (fixed-word [a b] (> a b)) + "<" (fixed-word [a b] (< a b)) + "len" (fixed-word [a] (length a)) + "true" (fixed-word [] true) + "false" (fixed-word [] false) + "dec" (word-as 1 "-") + "inc" (word-as 1 "+") + "negate" (word-as 0 "swap" "-") + "." (fixed-word [a] (do (print a) [])) + ".s" { :definition (fn [state] (pp (state :stack)))} + "{" { :definition (fn [state] + (array/push (state :stack) @[]) + (set (state :mode) deferred) + )} + "}" { :definition (fn [state] + (def words (array/peek (state :stack))) + (if (> (count |(= $ "{") words) (count |(= $ "}") words)) + (array/push words "}") + (do + (def dictionary (table/clone (state :dictionary))) + (array/pop (state :stack)) # Remove wordlist that's on stack top + (array/push (state :stack) (fn [state &opt recur] + (when recur (set (dictionary "recur") { :definition recur })) + (def state @{ :dictionary dictionary :stack (state :stack) :mode immediate }) + (run-state state words) + )) + (set (state :mode) immediate) + ) + ) + ) :immediate true } + "()" { :definition (fn [state] ((array/pop (state :stack)) state)) } + ":" { :definition (fn [state] + (set (state :mode) (fn [state word] + (def exec (array/pop (state :stack))) + (set ((state :dictionary) word) { :definition (fn [state] (exec state exec)) }) + (set (state :mode) immediate) + )) + )} + "if" (fixed-word [cond when-true when-false] (do ((if (truthy cond) when-true when-false) state) [])) + "loop" { :definition (fn [state] + (def body (array/pop (state :stack))) + (body state) + (while (truthy (array/pop (state :stack))) (body state)) + )} + "while" { :definition (fn [state] + (def body (array/pop (state :stack))) + (while (truthy (array/pop (state :stack))) (body state)) + )} + "repeat" (fixed-word [count body] (for x 0 count (body state))) + "[" { :immediate true :definition (fn [state] + (set (state :mode) immediate) + )} + "]" { :definition (fn [state] + (def val (array/pop (state :stack))) + (array/push (array/peek (state :stack)) val) + (set (state :mode) deferred) + )} +}) + + + +(defn main [_ arg] (let ( + words (peg/match grammar arg) + state @{ :dictionary (table/clone std-dict) :stack @[] :mode immediate } + ) + (run-state state words) +)) diff --git a/CS1032/practical-2023-10-04/tasks b/CS1032/practical-2023-10-04/tasks new file mode 100644 index 0000000..3f44c6d --- /dev/null +++ b/CS1032/practical-2023-10-04/tasks @@ -0,0 +1,37 @@ +based on user input, mapping "a" to "you chose the first option", "b" to "you chose the second option", +"c" to "you chose the third option", otherwise "invalid choice" + +# getting user input +option = input ("Please enter a value for choice: ") + +#verifying equality to "a" +if option == "a": + # printing message + print (“you choose the first option”) +# equality to b +elif option == "b": + # printing message + print (“you choose the second option”) +# equality to c +elif option == "c": + # printing message + print (“you choose the third option”) +#otherwise +else: + # printing message + print("Invalid choice.") + +Task 2 +x is undefined - prepend "x = int(input())\n" +# if x is non-negative + # if x less than 10 + # print message + +Task 3 +x is undefined - prepend "x = int(input())\n" +# if x is positive + # increase x, inform user +# otherwise + # decrease x, inform user +# print message + \ No newline at end of file diff --git a/CS1032/practical-2023-10-04/workshop.py b/CS1032/practical-2023-10-04/workshop.py new file mode 100644 index 0000000..f146f27 --- /dev/null +++ b/CS1032/practical-2023-10-04/workshop.py @@ -0,0 +1,14 @@ +from typing import Iterable + +def split(delim: str, s: str) -> Iterable[str]: + while len(s): + idx = s.find(delim) + if idx == -1: idx = len(s) + yield s[:idx] + s = s[idx + len(delim):] + +for x in split(", ", "Aberdeen, Dundee, Edinburgh, Glasgow"): print(x) + +# Swap M and D names in the definitions +d, m, y = tuple(split("/", "11/9/2001")) +print(f"Day = {d}, Month = {m}, Year = {y}") \ No newline at end of file diff --git a/CS1032/practical-2023-10-18/fn1.py b/CS1032/practical-2023-10-18/fn1.py new file mode 100644 index 0000000..6309564 --- /dev/null +++ b/CS1032/practical-2023-10-18/fn1.py @@ -0,0 +1,7 @@ +def trapezium_area(w1, w2, h): + return h * (w1 + w2) / 2 + +w1 = int(input("Width of the top: ")) +w2 = int(input("Width of the bottom: ")) +h = int(input("Height: ")) +print(f"Area is {trapezium_area(w1, w2, h)}") diff --git a/CS1032/practical-2023-10-18/fn2.py b/CS1032/practical-2023-10-18/fn2.py new file mode 100644 index 0000000..665d31e --- /dev/null +++ b/CS1032/practical-2023-10-18/fn2.py @@ -0,0 +1,20 @@ +def bmi(weight, height): + return weight * height ** -2 + +def bmi_category(bmi): + if bmi < 18.5: + return "underweight" + elif bmi < 25: + return "healthy" + elif bmi < 30: + return "overweight" + elif bmi < 40: + return "obese" + else: + return "severely obese" + +weight = float(input("Weight? ")) +height = float(input("Height? ")) +bmi = bmi(weight, height) +print(f"BMI is {bmi:.3}") +print(f"The BMI is in the {bmi_category(bmi)} category") diff --git a/CS1032/practical-2023-10-18/fn3.py b/CS1032/practical-2023-10-18/fn3.py new file mode 100644 index 0000000..048d635 --- /dev/null +++ b/CS1032/practical-2023-10-18/fn3.py @@ -0,0 +1,7 @@ +def exp(n, p): + if p == 0: return 1 + return n * exp(n, p - 1) + +base = float(input("Base? ")) +power = int(input("Exponent? ")) +print(exp(base, power)) diff --git a/CS1032/practical-2023-10-18/task1.py b/CS1032/practical-2023-10-18/task1.py new file mode 100644 index 0000000..3f78b3a --- /dev/null +++ b/CS1032/practical-2023-10-18/task1.py @@ -0,0 +1,9 @@ +import random + +randnumber = random.randint(1, 50) + +while True: + mynumber = int(input("Please enter a value: ")) + if randnumber == mynumber: + print("[perfect guess, you won....") + break diff --git a/CS1032/practical-2023-10-18/task2.py b/CS1032/practical-2023-10-18/task2.py new file mode 100644 index 0000000..e185e7d --- /dev/null +++ b/CS1032/practical-2023-10-18/task2.py @@ -0,0 +1,2 @@ +for i in range(10, 0, -1): + print(i) diff --git a/CS1032/practical-2023-10-18/task3.py b/CS1032/practical-2023-10-18/task3.py new file mode 100644 index 0000000..643f320 --- /dev/null +++ b/CS1032/practical-2023-10-18/task3.py @@ -0,0 +1,4 @@ +# If the example output is intended +terms = int(input("Enter the Total Number of Terms:\n")) +for i in range(16): + print(f"2 raised to the power {i} is {2 ** i}") diff --git a/CS1032/practical-2023-10-25/dicts b/CS1032/practical-2023-10-25/dicts new file mode 100644 index 0000000..7036b28 --- /dev/null +++ b/CS1032/practical-2023-10-25/dicts @@ -0,0 +1,13 @@ +counts = { 'chuck': 1, 'annie': 42, 'jan': 100 } + +for key in counts: + if (count := counts[key]) > 1: + print(key, count) + + + +lst = list(counts.keys()) +print(lst) +lst.sort() +for key in lst: + print(key, counts[key]) \ No newline at end of file diff --git a/MA1006/complex.tex b/MA1006/complex.tex new file mode 100644 index 0000000..c5a7cda --- /dev/null +++ b/MA1006/complex.tex @@ -0,0 +1,170 @@ +\input{decls.tex} +\title{Complex Numbers} + +\begin{document} +\maketitle +\section*{Operations} +\begin{align*} + \forall z \in \C & \\ + & \mod{z} = \sqrt{\Re{z}^2 + \Im{z}^2} \tag{modulus} \\ + & \conj{z} = \Re{z} - i\Im{z} \tag{conjugate} +\end{align*} +\section*{Identities} +\begin{align*} + \forall z, w \in \C&: \\ + & z\conj{z} \equiv \mod{z}^2 \\ + & \conj{\conj{z}} \equiv z \\ + & |\conj{z}| \equiv \mod{z} \\ + & z + \conj{z} \equiv 2\Re{z} \\ + & z - \conj{z} \equiv {-2\Im{z}} \\ + & \Re{z} \leq \mod{z} & \Re{z} \leq \abs{\Re{z}} = \sqrt{\Re{z}^2} \leq \sqrt{\Re{z}^2 + \Im{z}^2} = \mod{z} \\ + & \Im{z} \leq \mod{z} & \Im{z} \leq \abs{\Im{z}} = \sqrt{\Im{z}^2} \leq \sqrt{\Im{z}^2 + \Re{z}^2} = \mod{z} \\ + & \conj{zw} \equiv \conj{z}\cdot\conj{w} \\ + & \conj{z + w} \equiv \conj{z} + \conj{w} \\ + & \conj{\paren{\frac{z}{w}}} \equiv \frac{\conj{z}}{\conj{w}} \text { where } w \neq 0 \\ + & \mod{zw} \equiv \mod{z}\mod{w} \\ + & \mod{\frac{z}{w}} \equiv \frac{\mod{z}}{\mod{w}} \text{ where } w \neq 0 \\ +\end{align*} +\section*{Triangle Inequality} +\begin{align*} + \forall z, w \in \C. & \mod{z + w} \leq \mod{z} + \mod{w} \text {, as} \\ + & \mod{z + w}^2 \\ + & = \paren{z + w}\conj{\paren{z + w}} \\ + & = z\conj{z} + w\conj{w} + z\conj{w} + w\conj{z} \\ + & = \mod{z}^2 + \mod{w}^2 + z\conj{w} + \conj{z\conj{w}} \\ + & = \mod{z}^2 + \mod{w}^2 + 2\Re{z\conj{w}} \\ + & \leq \mod{z}^2 + \mod{w}^2 + 2\mod{z\conj{w}} \\ + & = \mod{z}^2 + \mod{w}^2 + 2\mod{z}\mod{w} \\ + & = \paren{\mod{z} + \mod{w}}^2 \\ + & \\ + & \mod{z + w}^2 \geq \paren{\mod{z} + \mod{w}}^2 \\ + & \mod{z + w} \geq \mod{z} + \mod{w} &\text{as moduli are non-negative} +\end{align*} +\section*{Division} +\begin{align*} + \forall z, w \in \C &, w \neq 0. \\ + & \frac{z}{w} = \frac{z}{w}\frac{\conj{w}}{\conj{w}} + = \frac{z\conj{w}}{\mod{w}^2} +\end{align*} +\section*{Square Root} +\begin{align*} + \forall z \in \C &. \\ + & \sqrt{z} = \sqrt{\frac{\mod{z} + \Re{z}}{2}} + i\frac{\abs{b}}{b}\sqrt{\frac{\mod{z} - \Re{z}}{2}} \\ + & \equiv \sqrt{\mod{z}}\paren{\cos{\frac{\arg{z}}{2}} + i\sin{\frac{\arg{z}}{2}}} +\end{align*} +\section*{Polar Form} +\begin{align*} + \forall z \in \C &. \\ + & \arg{z} = \arctan{\frac{\Im{z}}{\Re{z}}} \paren{+\pi \text{ if } \Re{z} < 0} \\ + & \Re{z} = \mod{z}\cos{\arg{z}} + & \Im{z} = \mod{z}\sin{\arg{z}} +\end{align*} +\section*{Locii} +\begin{description} +\item[Locus] A graph of an inequality on complex numbers, generally of their modulus +\item[Annulus] A locus of the form $a \leq \mod{z - b} \leq c$ for constants $a$, $b$, and $c$ +\item[Principal Argument] The argument of a complex number in $[0, 2\pi)$ +\end{description} +\subsection*{Hyperbolae} +\[ \frac{x^2}{r^2} - \frac{y^2}{R^2} = c\quad \text{ for constant $r$, $R$, $c$ } \] +\section*{De Moivre's Theorem} +\begin{align*} + \forall z, w \in \C. & \arg{zw} = \arg{z} + \arg{w} \\ + \text{Proof:} \\ + & \text{Let } \alpha = \arg{z} \text{ and } \beta = \arg{w} \\ + & zw = \polar{\mod{z}}{\alpha}\polar{\mod{w}}{\beta} \\ + & = \mod{z}\mod{w}\paren{\cos{\alpha}\cos{\beta} - \sin{\alpha}\sin{\beta} + i\paren{\cos{\alpha}\sin{\beta} + \sin{\alpha}\cos{\beta}}} \\ + & = \polar{\mod{zw}}{\alpha + \beta} & \text{Trigonometric identites - addition of angles} \\ +\end{align*} +Multiplication can then use $\mod{zw}$ and $\arg{zw}$, and exponentiation by induction ($z^{\paren{n - 1}} z$), and for negative exponents $\paren{z^{-1}}^{\abs{n}}$ +\subsection*{Example} +\begin{align*} +& \frac{2i^3}{\paren{1+\sqrt{3}i}^4} \\ +& = \frac{\paren{2^3\cdot i^3}}{\polar{\mod{1+\sqrt{3}i}^4}{4\cdot\arg{1+\sqrt{3}i}}} \\ +& = \frac{-8i}{\polar{\sqrt{10}^4}{4\cdot\arctan{\frac{\sqrt{3}}{1}}}} \\ +& = \frac{-8i}{\polar{100}{4\cdot\arctan{\sqrt{3}}}} \\ +& = \frac{-8i}{\polar{100}{\frac{4\pi}{3}}} \\ +& = \paren{-8i}\cdot\paren{\polar{100}{\frac{4\pi}{3}}}^{-1} \\ +& = \paren{-8i}\cdot\paren{\polar{100^{-1}}{\frac{-4\pi}{3}}} \\ +& = \polar{8}{\frac{\pi}{2}}\cdot\polar{\frac{1}{100}}{\frac{-4\pi}{3}} \\ +& = \polar{\frac{8}{100}}{\frac{\pi}{2} + \frac{-4\pi}{3}} \\ +& = \polar{\frac{8}{100}}{\frac{3\pi}{6}+\frac{-8\pi}{6}} \\ +& = \polar{\frac{8}{100}}{\frac{-5\pi}{6}} \\ +& = \frac{8}{100}\cdot\paren{\frac{-\sqrt{3}}{2} - \frac{1}{2}i} \\ +& = \frac{-\sqrt{3}}{25} + \frac{1}{25}i \\ +\end{align*} + +\subsection*{$n^\text{th}$ Roots} +\begin{align*} + i & = \polar{1}{\frac{\pi}{2} + 2k\pi} \\ + & \sqrt[3]{i} = \polar{\sqrt[3]{1}}{\frac{\pi}{2}\cdot\frac{1}{3} + 2k\pi\cdot\frac{1}{3}} \text{ - cyclic at $k\,$mod$\,3$} +\end{align*} +\\ \\ +\[\forall z \in \C, n \in \N.\quad \exists~ n \text{ distinct $n^\text{th}$ roots of $z$, which are } \] +\[ \paren{\sqrt[n]{z}}_{k+1} = \polar{\sqrt[n]{\mod{z}}}{\frac{\arg{z} + 2k\pi}{n}} \forall k \in \N, [0, n) \] +Roots of unity are the $n^\text{th}$ complex roots of 1\\ +\begin{align*} + \sqrt[n]{1} & = \polar{1}{\frac{2k\pi}{n}} \forall k \in 0..n \\ + & = 1, .. +\end{align*} +Distributed around the unit circle evenly spaced +\subsection*{Use in Trigonometry} +To find $\cos{n\theta}$ or $\sin{n\theta}$ in terms of $\cos{\theta}$ and $\sin{\theta}$ +\begin{align*} +\paren{\cos{\theta} + i\sin{\theta}}^n & = \cos{n\theta} + i\sin{n\theta} \\ +& \Re{\paren{\cos{\theta} + i\sin{\theta}}^n} = \cos{n\theta} \\ +& \Im{\paren{\cos{\theta} + i\sin{\theta}}^n} = \sin{n\theta} \\ +\end{align*} + +Binomial Expansion by Pascal's Triangle - sum of powers of the term are the number in pascal's triangle \\ +1, sum of two above + +\section*{Power Series} +\begin{align*} +\forall x \in \R .& ~ e^x = \sum_{n=0}^{\infty}\frac{x^n}{n!} \\ +& \cos{x} = \sum_{n=0}^\infty\paren{\paren{-1}^n\cdot\frac{x^{2n}}{\paren{2n}!}} +& \sin{x} = \sum_{n=0}^\infty\paren{\paren{-1}^n\cdot\frac{x^{2n+1}}{\paren{2n+1}!}} +\end{align*} +Define these for $x \in \C$ in the same way +\begin{align*} +\forall b \in \R . & ~ e^{bi} = 1 + bi + \frac{(bi)^2}{2!} + \frac{(bi)^3}{3!} + ...\\ +& = \paren{1 - \frac{b^2}{2!} + \frac{b^4}{4!}} + i\paren{b - \frac{b^3}{3!} + \frac{b^5}{5!}} \\ +& = \cos{b} + i\sin{b} \\ +\therefore \\ +& e^{a + bi} = e^a\cdot e^{bi} = \polar{e^a}{b} +\end{align*} +\subsection*{Consequences} +$$ e^{i\pi} = -1 $$ +De Moivre's Theorem: $$ e^{i\alpha}e^{i\beta} = e^{i\paren{\alpha+\beta}} $$ +\subsection*{$\sin$, $\cos$ of Complex Numbers} +\begin{align*} +\forall \theta \in \R. \quad & e^{i\theta} + e^{-i\theta} = \cos{\theta} + i\sin{\theta} + \cos{-\theta} + i\sin{-\theta} \\ +& = \cos{\theta} + i\sin{\theta} + \cos{\theta} - i\sin{\theta} \\ +& = 2\cos{\theta} \\ +\therefore \\ +& \cos{\theta} = \frac{e^{i\theta} + e^{-i\theta}}{2} \quad \forall \theta \in \R +\end{align*} +Similarly, \[ \sin{\theta} = \frac{e^{i\theta} - e^{-i\theta}}{2i}\quad\forall\theta\in\R \] \\ +Define $\cos{\theta}$ as \[ \frac{e^{i\theta} + e^{-i\theta}}{2}$ $~\forall \theta \in \C \] +Define $\sin{\theta}$ as \[ \frac{e^{i\theta} - e^{-i\theta}}{2i}$ $~\forall \theta \in \C \] +\subsubsection*{Examples} +\begin{align*} + \cos{\paren{1 + i}} = \frac{e^{i\paren{1 + i}} + e^{-i\paren{1 + i}}}{2} = \frac{e^{i - 1} + e^{1 - i}}{2} + = \frac{1}{2}\paren{\polar{e^{-1}}{1} + \polar{e}{-1}} +\end{align*} + +\subsection*{Logarithms of Complex Numbers} +$$ \forall y \in \R, y > 0. \quad e^{\ln{y}} = y $$ +\begin{align*} +\forall z \in \C. \quad & e^{\ln{z}} = z \\ +& \text{let } w = \ln{z} = c + di \\ +& e^w = e^{c + di} = \polar{e^c}{d} = z \\ +& \implies e^c = \mod{z}, d = \arg{z} \\ +& \implies w = c + di = \ln{\mod{z}} + i\arg{z} +\end{align*} +Note: $\arg{z}$ is multivalued, therefore $\ln{z}$ is multivalued +$$ \ln{z} = \ln{\mod{z}} + i\arg{z} $$ +Sidenote: $\forall a \in \R, a < 0. \quad \ln{a} = \ln{\abs{a}} + i\pi\paren{2n + 1} \forall n \in \N$ +$$ \forall z, w \in \C. \quad z^w = e^{w\ln{z}} $$ +Exponents of complex numbers are \emph{odd}. $\quad z^{w_1\cdot w_2} \leq \paren{z^{w_1}}^{w_2}$ - They aren't necessarily equal +\end{document} \ No newline at end of file diff --git a/MA1006/decls.tex b/MA1006/decls.tex new file mode 100644 index 0000000..89327a8 --- /dev/null +++ b/MA1006/decls.tex @@ -0,0 +1,58 @@ +\documentclass[fleqn]{article} +\usepackage{amsmath,amssymb} +\usepackage[margin=0.25in]{geometry} +\usepackage{enumitem} +\usepackage{systeme} +\usepackage{mathtools} + +\date{} +\author{} + +\renewcommand{\Re}[1]{\operatorname{\mathbb{R}e}(#1)} +\renewcommand{\Im}[1]{\operatorname{\mathbb{{I}}m}(#1)} +\newcommand{\C}{\mathbb{C}} +\newcommand{\N}{\mathbb{N}} +\newcommand{\Z}{\mathbb{Z}} +\newcommand{\Q}{\mathbb{Q}} +\newcommand{\R}{\mathbb{R}} +\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}}}} + +\makeatletter +\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{% + \hskip -\arraycolsep + \let\@ifnextchar\new@ifnextchar + \array{#1}} +\makeatother + + +% https://gitlab.com/jim.hefferon/linear-algebra/-/blob/master/src/sty/linalgjh.sty +\newlength{\grsteplength} +\setlength{\grsteplength}{1.5ex plus .1ex minus .1ex} + +\newcommand{\grstep}[2][\relax]{% + \ensuremath{\mathrel{ + \hspace{\grsteplength}\mathop{\longrightarrow}\limits^{#2\mathstrut}_{ + \begin{subarray}{l} #1 \end{subarray}}\hspace{\grsteplength}}}} +\newcommand{\repeatedgrstep}[2][\relax]{\hspace{-\grsteplength}\grstep[#1]{#2}} + +\newcommand{\swap}{\leftrightarrow} + +% https://tex.stackexchange.com/a/198806 +\makeatletter +\newcommand{\subalign}[1]{% + \vcenter{% + \Let@ \restore@math@cr \default@tag + \baselineskip\fontdimen10 \scriptfont\tw@ + \advance\baselineskip\fontdimen12 \scriptfont\tw@ + \lineskip\thr@@\fontdimen8 \scriptfont\thr@@ + \lineskiplimit\lineskip + \ialign{\hfil$\m@th\scriptstyle##$&$\m@th\scriptstyle{}##$\hfil\crcr + #1\crcr + }% + }% +} +\makeatother \ No newline at end of file diff --git a/MA1006/linear.tex b/MA1006/linear.tex new file mode 100644 index 0000000..cc9a7c7 --- /dev/null +++ b/MA1006/linear.tex @@ -0,0 +1,243 @@ +\input{decls.tex} +\title{Linear Algebra} +\begin{document} +\maketitle +\section*{Allowable Operations on a Linear System} +Solutions invariant. +\begin{itemize} +\item Multiply an equation by a non-zero scalar +\item Swap two equations +\item Add a multiple of one equation to another +\end{itemize} +\subsection*{Example} +\begin{align*} +&\systeme{ + x - 2y + 2z = 6, + -x + 3y + 4z = 2, + 2x + y - 2z = -2 +}\\\\ + E_2 & \implies E_2 + E_1 \\ + E_3 & \implies E_3 + E_1 \\ +&\systeme{ + x - 2y + 2z = 6, + y + 6z = 8, + 5y - 6z = -14 +}\\\\ + E_3 & \implies E_3 - 5E_2 \\ +&\systeme{ + x - 2y + 2z = 6, + y + 6z = 8, + z = \frac{3}{2} +}\\\\ + E_1 & \implies E_1 - 2E_3 \\ + E_2 & \implies E_2 - 6E_3 \\ +&\systeme{ + x - 2y = 3, + y = -1, + z = \frac{3}{2} +}\\\\ + E_1 & \implies E_1 + 2E_2 \\ +&\systeme{ + x = 1, + y = -1, + z = \frac{3}{2} +}\\\\ +\end{align*} +\section*{As Matrices} +\begin{align*} +\systeme{ + x + 2y = 1, + 2x - y = 3 +} +\quad=\quad +\begin{pmatrix}[cc|c] +1 & 2 & 1 \\ +2 & -1 & 3 +\end{pmatrix} +& \systeme{ + x - y + z = -2, + 2x + 3y + z = 7, + x - 2y - z = -2 +} \quad=\quad \begin{pmatrix}[ccc|c] + 1 & -1 & 1 & -2 \\ + 2 & 3 & 1 & 7 \\ + 1 & -2 & -1 & -2 +\end{pmatrix} \\ +\grstep[R_3 - R_1]{R_2 - 2R_1} & \begin{pmatrix}[ccc|c] + 1 & -1 & 1 & -2 \\ + 0 & 5 & -1 & 11 \\ + 0 & -1 & -2 & 0 +\end{pmatrix} \\ +\grstep{5R_3 + R_2} & \begin{pmatrix}[ccc|c] + 1 & -1 & 1 & -2 \\ + 0 & 5 & -1 & 11 \\ + 0 & 0 & -11 & 11 \\ +\end{pmatrix} \\ +\grstep{-11^{-1}R_3} & \begin{pmatrix}[ccc|c] + 1 & -1 & 1 & -2 \\ + 0 & 5 & -1 & 11 \\ + 0 & 0 & 1 & -1 +\end{pmatrix} \\ +\grstep[R_1 - R_3]{R_2 + R_3} & \begin{pmatrix}[ccc|c] + 1 & -1 & 0 & -1 \\ + 0 & 5 & 0 & 10 \\ + 0 & 0 & 1 & -1 +\end{pmatrix} \\& +\grstep{5^{-1}R_2} & \begin{pmatrix}[ccc|c] + 1 & -1 & 0 & -1 \\ + 0 & 1 & 0 & 2 \\ + 0 & 0 & 1 & -1 \\ +\end{pmatrix} \\ +\grstep{R_1 + R_2} & \begin{pmatrix}[ccc|c] + 1 & 0 & 0 & 1 \\ + 0 & 1 & 0 & 2 \\ + 0 & 0 & 1 & -1 +\end{pmatrix} \\ += & \quad +\left\{ +\subalign{ + x & ~= ~1 \\ + y & ~= ~2 \\ + z & ~= ~-1 +} +\right. +\end{align*} +\section*{Row-Echelon Form} +\begin{description} +\item[Row-Echelon Form] The leading entry in each row is 1 and is further to the right than the previous row's leading entry, +all 0 rows are at the end +\item[Reduced Row-Echelon Form] every other entry in a column containing a leading 1 is 0 +\item[Theorem:] A matrix can be transformed to reduced row-echelon form using a finite number of allowable row operations +\end{description} +\subsection*{Example} +\begin{align*} +& \systeme{3x_1 + 2x_2 = 1, + x_1 - x_2 = 4, + 2x_1 + x_2 = 5} = \begin{pmatrix}[cc|c] + 3 & 2 & 1 \\ + 1 & -1 & 4 \\ + 2 & 1 & 5 + \end{pmatrix} \\ +\grstep{R_1\swap R_2} & \begin{pmatrix}[cc|c] + 1 & -1 & 4 \\ + 3 & 2 & 1 \\ + 2 & 1 & 5 +\end{pmatrix} \\ +\grstep[R_2 - 3R_1]{R_3 - 2R_1} & \begin{pmatrix}[cc|c] + 1 & -1 & 4 \\ + 0 & 5 & -11 \\ + 0 & 3 & -3 +\end{pmatrix} \\ +\grstep{5^{-1}R_2} & \begin{pmatrix}[cc|c] + 1 & -1 & 4 \\ + 0 & 1 & \frac{-11}{5} \\ + 0 & 3 & -3 +\end{pmatrix} \\ +\grstep{R_3 - 2R_2} & \begin{pmatrix}[cc|c] + 1 & -1 & 4 \\ + 0 & 1 & \frac{-11}{5} \\ + 0 & 0 & \frac{18}{5} +\end{pmatrix} \\ += & \systeme{ + x_1 - x_2 = 4, + x_2 = \frac{-11}{5}, + 0x_1 + 0x_2 = \frac{18}{5} +} +\end{align*} +\begin{align*} +& \begin{pmatrix}[cccc|c] +1 & -1 & 1 & 1 & 6 \\ +-1 & 1 & -2 & 1 & 3 \\ +2 & 0 & 1 & 4 & 1 \\ +\end{pmatrix} \\ +\grstep[R_2 + R_1]{R_3 - 2R_1} & \begin{pmatrix}[cccc|c] + 1 & -1 & 1 & 1 & 6 \\ + 0 & 0 & -1 & 2 & 9 \\ + 0 & 2 & -1 & 2 & -11 +\end{pmatrix} \\ +\grstep[R_2\swap R_3]{2^{-1}R_3} & \begin{pmatrix}[cccc|c] + 1 & -1 & 1 & 1 & 6 \\ + 0 & 1 & \frac{1}{2} & 1 & \frac{-11}{2} \\ + 0 & 0 & -1 & 2 & 9 \\ +\end{pmatrix} \\ +\grstep[R_1 + R_3]{R_2 - 2^{-1}R_3} & \begin{pmatrix}[cccc|c] + 1 & -1 & 0 & 3 & 15 \\ + 0 & 1 & 0 & 0 & -10 \\ + 0 & 0 & -1 & 2 & 9 \\ +\end{pmatrix} \\ +\grstep[-R_3]{R_1 + R_2} & \begin{pmatrix}[cccc|c] + 1 & 0 & 0 & 3 & 15 \\ + 0 & 1 & 0 & 0 & -10 \\ + 0 & 0 & 1 & -2 & -9 \\ +\end{pmatrix} \\ += & \systeme{ + x_1 + 3x_4 = 5, + x_2 = -10, + x_3 - 2x_4 = -9 +} \\ += & \left\{\substack{ + x_1 = 5 - 3t \\ + x_2 = -10 \\ + x_3 = -9 + 2t +}\right. +\end{align*} +\section*{Determinants} +The determinant of a matrix is defined only for square matrices. +\[\det{A} \neq 0 \iff \exists \text{ a unique solution to the linear system represented by } A\] +Let +\[A = \begin{pmatrix} + a_{11} & a_{12} & a_{1n} \\ + a_{21} & \ddots & \vdots \\ + a_{31} & \ldots & a_{3n} \\ +\end{pmatrix} +\] +\begin{description} +\item[$i, j$ minor of $A$] an $n$x$n$ matrix constructed by removing the $i^\text{th}$ row and $j^\text{th}$ column of $A$ \\ +Denoted by $A_{ij}$ +\end{description} +\begin{align*} +& \det{A} \text{ where } n = 1. = a_{11} \\ +& \det{A} = a_{11}\det{A_{11}} - a_{12}\det{A_{12}} + ... + (-1)^{n+1}a_{1n} \tag{Laplace expansion of the first row} \\ +& \qquad \text{or laplace expansion along other row or column} +\text{For } n = 2:& \\ +& \det{A} = a_{11}\cdot a_{22} - a_{12}\cdot a_{21} +\end{align*} +\begin{description} +\item[Upper Triangular] lower left triangle is 0 - $d_{ij} = 0 \quad \forall{i > j}$ +\item[Lower Triangular] upper right triangle is 0 - $d_{ij} = 0 \quad \forall{i < j}$ +\item[Diagonal] only values on the diagonal - $d_{ij} = 0 \quad \forall{i \neq j}$ \\ +$\det{A} = \prod^{N}_{i=0}~a_{ij} \forall~\text{ row-echelon }A$ +\end{description} +\begin{itemize} +\item Multiplying a row of a square matrix $A$ by $r$ multiplies $\det{A}$ by $r$ +\item Swapping two rows of a square matrix $A$ multiplies $\det{A}$ by $-1$ +\item Adding a multiple of a row does not effect the determinant +\end{itemize} +\section*{Transposition} +\begin{description} +\item[$A^T$] $a^T_{ij} = a_{ji}~ \forall~i,j$ +\end{description} +Note: $\det{A} = \det{A^T}~\forall~A$ +\section*{Matrix Multiplication} +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*} + \begin{pmatrix}[c|c|c] + 2 & 1 + 1 & 3 + 6 \\ + 4(2) & 4 + 1 & 3(4) + 6 \\ + 0 & 2 & 2(6) \\ + \end{pmatrix} = \begin{pmatrix} + 2 & 2 & 9 \\ + 8 & 5 & 18 \\ + 0 & 2 & 12 + \end{pmatrix} +\end{align*} +\begin{align*} +\begin{pmatrix}1 \\ 2 \\ 3 \end{pmatrix}\begin{pmatrix}1 & 2 & 3 & 4\end{pmatrix} + \begin{pmatrix} + 1 & 2 & 3 & 4 \\ + 5 & 6 & 7 & 8 \\ + 9 & 10 & 11 & 12 \\ +\end{pmatrix} +\end{align*} +\end{document} \ No newline at end of file diff --git a/MA1006/notes-2023-09-21 b/MA1006/notes-2023-09-21 new file mode 100644 index 0000000..ff0d4ce --- /dev/null +++ b/MA1006/notes-2023-09-21 @@ -0,0 +1,9 @@ +Leading coefficient of a polynomial is the coefficient of the highest power of x. +Leading coefficient is inherently non-zero +Monic polynomials: leading coefficient == 1 + +Rational Root Theorem: + forall P(x): polynomial of degree n with integer coefficients + forall p, q: Z such that p/q is a root of P(x) + p is a factor of a[0] + q is a factor of a[n] diff --git a/MA1006/polynomials.tex b/MA1006/polynomials.tex new file mode 100644 index 0000000..ce63841 --- /dev/null +++ b/MA1006/polynomials.tex @@ -0,0 +1,34 @@ +\input{decls.tex} +\title{Polynomials} +\begin{document} +\maketitle +\begin{itemize}[leftmargin=10em] + \item[Polynomial in $\C$] \quad $\forall n \in \N, a_{i \in [0, n]} \in \C, a_n \neq 0. \quad P(x) = \sum_{i=0}^{n} a_{i}x^i$ + \item[Degree] \quad $n$ + \item[Leading Coefficient] \quad $a_n$ + \item[Monic Polynomial] \quad Polynomial with $a_n = 1$ +\end{itemize} +The Abel-Ruffini theorem states that there exists a degree-5 polynomial with roots that cannot be expressed with $+ - * / \surd$ +\section*{Rational Root Theorem} +\[ + \forall \text{ polynomials } P(x) \text { with } \forall i. a_i \in \Z.\quad \forall \frac{p}{q} \in \Q.~P\paren{\frac{p}{q}} = 0 \implies p|a_0 \land q|a_n \\ % x|y x divides y +\] +This means that monic polynomials have no rational non-integral roots. +\section*{Polynomial Division} +\[\forall P(x), D(x).~ \exists Q(x), R(x).~ P(x) = D(x)Q(x) + R(x), \operatorname{degree}(R) < \operatorname{degree}(D)\] +\section*{Remainder Theorem} +\[\forall P(x), c. P(c) = 0 \iff \paren{x - c}|P(x)\] +Proof: +\begin{align*} + \text{Given that }& P(c) = 0: \\ + & \exists Q(x), R(x).~P(x) = Q(x)(x - c) + R(x) & \text{Division of polynomials} \\ + & P(c) = Q(c)(c - c) + R(c) & \\ + & 0 = Q(c)(0) + R(c) & \\ + & R(c) = 0 & \\ + & \forall x.~R(x) = 0 & \text{As $D(x)$ has degree $1$, $R(x)$ must have degree $0$} \\ + & \therefore~(x - c)|P(x) \\ + \text{Given that }& (x - c)|P(x) \\ + & \exists Q(x).~P(x) = Q(x)(x - c) & \text{Division of polynomials, remainder $0$} \\ + & \therefore~P(c) = Q(c)(c - c) = 0\cdot Q(c) = 0 +\end{align*} +\end{document} \ No newline at end of file diff --git a/MA1006/tmpl.tex b/MA1006/tmpl.tex new file mode 100644 index 0000000..4275eb2 --- /dev/null +++ b/MA1006/tmpl.tex @@ -0,0 +1,6 @@ +\input{decls.tex} +\title{} +\begin{document} +\maketitle + +\end{document} \ No newline at end of file diff --git a/MA1006/tut-2023-10-10.tex b/MA1006/tut-2023-10-10.tex new file mode 100644 index 0000000..21ec405 --- /dev/null +++ b/MA1006/tut-2023-10-10.tex @@ -0,0 +1,42 @@ +\input{decls.tex} +\title{Tutorial 2023-10-10} +\begin{document} +\maketitle +\section{} +\section{} +They're rotated by 90 degrees +\section{} +\begin{tabular}{ c c c c } +$\theta$ & $\cos\theta$ & $\sin\theta$ & $\tan\theta$ \\ \hline +$0$ & $ 1 $ & $ 0 $ & $ 0 $ \\ \hline +$\pi/6$ & $\sqrt{3}/2$ & $1/2$ & $\sqrt{3}/3$ \\ \hline +$\pi/4$ & $\sqrt{2}/2$ & $\sqrt{2}/2$ & $1$ \\ \hline +$\pi/3$ & $1/2$ & $\sqrt{3}/2$ & $\sqrt{3}$ \\ \hline +$\pi/2$ & $0$ & $1$ & undefined \\ \hline +$-\pi/6$ & $\sqrt{3}/2$ & $-1/2$ & $-\sqrt{3}/3$ \\ \hline +$-\pi/4$ & $\sqrt{2}/2$ & $-\sqrt{2}/2$ & -1 \\ \hline +$-\pi/3$ & $1/2$ & $-\sqrt{3}/2$ & $-\sqrt{3}$ \\ \hline +$-\pi/2$ & $0$ & $-1$ & undefined \\ \hline +\end{tabular} +\section{} +\subsection{} +\begin{align*} +& +1 = \polar{1}{0} & {-1} = \polar{1}{\pi} \\ +& +i = \polar{1}{\frac{\pi}{2}} & {-i} = \polar{1}{-\frac{\pi}{2}} +\end{align*} +\subsection{} +\[1 - i = \polar{\sqrt{2}}{\frac{-\pi}{4}}\] +\[1 + i = \polar{\sqrt{2}}{\frac{\pi}{4}} \] +\subsection{} +\[-1 + i\sqrt{3} = \polar{2}{\frac{-\pi}{3}}\] +\[-1 - i\sqrt{3} = \polar{2}{\frac{+\pi}{3}}\] +\subsection{} +\[\] +\section{} +\subsection{} +\[i\] +\subsection{} +\[\sqrt{2} + \sqrt{2}i\] +\subsection{} + +\end{document} \ No newline at end of file diff --git a/MA1006/tut-2023-10-17.tex b/MA1006/tut-2023-10-17.tex new file mode 100644 index 0000000..9f3d3f9 --- /dev/null +++ b/MA1006/tut-2023-10-17.tex @@ -0,0 +1,9 @@ +\input{decls.tex} +\title{Tutorial} +\date{2023-10-17} +\begin{document} +\maketitle +\section{} +\subsection{} +\begin{align*} +\end{document} \ No newline at end of file