├── README.md ├── assignments ├── 2018-01-12 │ ├── 2018-01-12.ipynb │ └── DUE_DATE.txt ├── 2018-01-19 │ ├── 2018-01-19.ipynb │ ├── DUE_DATE.txt │ └── comparison.sagews ├── 2018-01-26 │ ├── 2018-01-26.ipynb │ └── DUE_DATE.txt ├── 2018-02-02 │ ├── 2018-02-02.ipynb │ └── DUE_DATE.txt ├── 2018-02-09 │ ├── 2018-02-09.ipynb │ ├── DUE_DATE.txt │ └── qr.gif ├── 2018-02-16 │ ├── 2018-02-16.ipynb │ ├── DUE_DATE.txt │ └── state_capitals.xlsx ├── 2018-02-23 │ ├── 2018-02-23.ipynb │ └── DUE_DATE.txt ├── 2018-03-02 │ ├── 2018-03-02.ipynb │ └── DUE_DATE.txt ├── 2018-03-09 │ ├── 2018-03-09.ipynb │ └── DUE_DATE.txt └── 2018-03-16 │ ├── 2018-03-16-part1.ipynb │ ├── 2018-03-16-part2.ipynb │ └── DUE_DATE.txt ├── best_practices.md ├── final_project_calculation ├── Math 157 final project - Sheet1.csv ├── create-project-groups.ipynb └── template_chat.sage-chat ├── index.html ├── lectures ├── 2018-01-08 │ ├── 2018-01-08.ipynb │ ├── files.png │ └── logo.png ├── 2018-01-10 │ ├── 2018-01-10.ipynb │ ├── Revert.png │ ├── TimeTravel.png │ ├── folder.png │ └── home.png ├── 2018-01-12 │ └── 2018-01-12.ipynb ├── 2018-01-17 │ └── 2018-01-17.ipynb ├── 2018-01-19 │ └── 2018-01-19.ipynb ├── 2018-01-22 │ ├── 2018-01-22.ipynb │ └── SageMath_logo.png ├── 2018-01-24 │ └── 2018-01-24.ipynb ├── 2018-01-26 │ └── 2018-01-26.ipynb ├── 2018-01-29 │ └── 2018-01-29.ipynb ├── 2018-01-31 │ └── 2018-01-31.ipynb ├── 2018-02-02 │ └── 2018-02-02.ipynb ├── 2018-02-05 │ └── 2018-02-05.ipynb ├── 2018-02-07 │ └── 2018-02-07.ipynb ├── 2018-02-09 │ └── 2018-02-09.ipynb ├── 2018-02-12 │ └── 2018-02-12.ipynb ├── 2018-02-14 │ └── 2018-02-14.ipynb ├── 2018-02-16 │ └── 2018-02-16.ipynb ├── 2018-02-21 │ └── 2018-02-21.ipynb ├── 2018-02-23 │ ├── 2018-02-23.ipynb │ └── basketball_players.csv ├── 2018-02-26 │ └── 2018-02-26.ipynb ├── 2018-02-28 │ └── 2018-02-28.ipynb ├── 2018-03-02 │ └── 2018-03-02.ipynb ├── 2018-03-05 │ └── 2018-03-05.ipynb ├── 2018-03-07 │ └── 2018-03-07.ipynb ├── 2018-03-09 │ ├── 2018-03-09.ipynb │ └── 2018-03-16-part1.ipynb └── 2018-03-16 │ └── 2018-03-16.ipynb ├── solutions ├── 2018-01-19 │ └── 2018-01-19-solutions.ipynb ├── 2018-01-26 │ └── 2018-01-26-solutions.ipynb ├── 2018-02-02 │ └── 2018-02-02-solutions.ipynb ├── 2018-02-09 │ └── 2018-02-09.ipynb ├── 2018-02-16 │ └── 2018-02-16-solutions.ipynb ├── 2018-02-23 │ └── 2018-02-23-solutions.ipynb ├── 2018-03-02v1 │ └── 2018-03-02.ipynb └── 2018-03-09 │ └── 2018-03-09-solutions.ipynb ├── takeaway.md └── troubleshooting.md /README.md: -------------------------------------------------------------------------------- 1 | This repository contains the course materials from Math 157: Intro to Mathematical Software, taught by Kiran Kedlaya at UC San Diego during the winter 2018 quarter. These were adapted from a similar course (Math 152) taught by Kedlaya at UCSD during winter 2017, and ultimately from several courses (Math 480) taught by William Stein at University of Washington. 2 | 3 | The solution sets for the exercises were prepared by the Math 157 TAs: Thomas Grubb, Jun Bo Lau, and Peter Wear. Additional contributions were made by Alina Bucur, Alyson Deines, John Jeng, Harald Schilly, Simon Spicer, and Kartik Venkatram. 4 | 5 | All material is (c) 2018 Kiran S. Kedlaya and William Stein, and is subject to the [Creative Commons BY-SA 4.0 license](https://creativecommons.org/licenses/by-sa/4.0/). -------------------------------------------------------------------------------- /assignments/2018-01-12/2018-01-12.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "## Math 157: Intro to Mathematical Software\n", 10 | "## UC San Diego, winter 2018; materials by Kiran S. Kedlaya" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "collapsed": false 17 | }, 18 | "source": [ 19 | "## Homework 0 (practice): due January 12, 2018" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": { 25 | "collapsed": false 26 | }, 27 | "source": [ 28 | "This homework is not for credit. Its primary purpose is to give you a chance to practice with CoCalc, Jupyter notebooks, and the homework submission mechanism. A secondary purpose is to collect some feedback which might help us later." 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": { 34 | "collapsed": false 35 | }, 36 | "source": [ 37 | "In general, each homework will be presented as a single Jupyter notebook like this one. Each component of each problem will be followed by an empty cell in which you should provide your response (unless otherwise instructed). Please set the type of that cell appropriately: to \"code\" for executable code in some software package (the default), \"markdown\" for text wth formatting, or \"raw\" for text without formatting (we won't use this option much)." 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": { 43 | "collapsed": false 44 | }, 45 | "source": [ 46 | "## Problem 1: Background" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": { 52 | "collapsed": false 53 | }, 54 | "source": [ 55 | "1a. Please list (by name and course number) any programming classes you have taken." 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 0, 61 | "metadata": { 62 | "collapsed": false 63 | }, 64 | "outputs": [ 65 | ], 66 | "source": [ 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "metadata": { 72 | "collapsed": false 73 | }, 74 | "source": [ 75 | "1b. Are you familiar with any programming languages? If so, which ones?" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 0, 81 | "metadata": { 82 | "collapsed": false 83 | }, 84 | "outputs": [ 85 | ], 86 | "source": [ 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "metadata": { 92 | "collapsed": false 93 | }, 94 | "source": [ 95 | "1c. Have you used any mathematical software before (e.g., Mathematica, Maple, Matlab)? If so, in what way(s)?" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 0, 101 | "metadata": { 102 | "collapsed": false 103 | }, 104 | "outputs": [ 105 | ], 106 | "source": [ 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": { 112 | "collapsed": false 113 | }, 114 | "source": [ 115 | "1d. Feel free to make any more comments about your programming/math software background here, so we may better serve you." 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": 0, 121 | "metadata": { 122 | "collapsed": false 123 | }, 124 | "outputs": [ 125 | ], 126 | "source": [ 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": { 132 | "collapsed": false 133 | }, 134 | "source": [ 135 | "## Problem 2: Office hours" 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "metadata": { 141 | "collapsed": false 142 | }, 143 | "source": [ 144 | "Are you able to attend any of the scheduled office hours? (If you are unable to utilize your TA's office hours, you may use another other TA's office hours.)" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": { 150 | "collapsed": false 151 | }, 152 | "source": [ 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": { 158 | "collapsed": false 159 | }, 160 | "source": [ 161 | "## Problem 3: Paradigms for mathematical software" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": { 167 | "collapsed": false 168 | }, 169 | "source": [ 170 | "Most problem sets will include one or two verbal response questions in the following style." 171 | ] 172 | }, 173 | { 174 | "cell_type": "markdown", 175 | "metadata": { 176 | "collapsed": false 177 | }, 178 | "source": [ 179 | "3a. In your own words, explain the differences between the following concepts:\n", 180 | " - a programming language (e.g., Python);\n", 181 | " - a computer algebra system (e.g., Mathematica);\n", 182 | " - a collaborative mathematics environment (e.g., CoCalc).\n" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 0, 188 | "metadata": { 189 | "collapsed": false 190 | }, 191 | "outputs": [ 192 | ], 193 | "source": [ 194 | ] 195 | }, 196 | { 197 | "cell_type": "markdown", 198 | "metadata": { 199 | "collapsed": false 200 | }, 201 | "source": [ 202 | "3b. WolframAlpha is a web service based on Mathematica, but it is a \"computational knowledge engine\" rather than a \"collaborative mathematics environment\". Explain the difference between these two concepts by giving some examples (on both sides) of tasks that can be handled by one type of web service but not the other.\n" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 0, 208 | "metadata": { 209 | "collapsed": false 210 | }, 211 | "outputs": [ 212 | ], 213 | "source": [ 214 | ] 215 | }, 216 | { 217 | "cell_type": "markdown", 218 | "metadata": { 219 | "collapsed": false 220 | }, 221 | "source": [ 222 | "## Problem 4: Markdown syntax" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 0, 228 | "metadata": { 229 | "collapsed": false 230 | }, 231 | "outputs": [ 232 | ], 233 | "source": [ 234 | ] 235 | }, 236 | { 237 | "cell_type": "markdown", 238 | "metadata": { 239 | "collapsed": false 240 | }, 241 | "source": [ 242 | "Write some text in Markdown that illustrates at least three formatting features not used anywhere in this homework. Your text should also describe in words what these features are. (Do not use any examples based on TeX; that is, do not use the dollar sign \\$ in your text.)" 243 | ] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "execution_count": 0, 248 | "metadata": { 249 | "collapsed": false 250 | }, 251 | "outputs": [ 252 | ], 253 | "source": [ 254 | ] 255 | }, 256 | { 257 | "cell_type": "markdown", 258 | "metadata": { 259 | "collapsed": false 260 | }, 261 | "source": [ 262 | "## Problem 5: TeX syntax" 263 | ] 264 | }, 265 | { 266 | "cell_type": "markdown", 267 | "metadata": { 268 | "collapsed": false 269 | }, 270 | "source": [ 271 | "For Jupyter notebooks in CoCalc, markdown cells can contain mathematical formatting using TeX. Any text enclosed between a pair of dollar signs is parsed as TeX, for instance, $x^2$." 272 | ] 273 | }, 274 | { 275 | "cell_type": "markdown", 276 | "metadata": { 277 | "collapsed": false 278 | }, 279 | "source": [ 280 | "Use TeX to typeset the following equations/formulas:\n", 281 | " - Euler's identity (according to Wikipedia);\n", 282 | " - Stirling's approximation (the \"more precise variant\" according to Wikipedia);\n", 283 | " - Laplace's equation (the first form appearing in Wikipedia)." 284 | ] 285 | }, 286 | { 287 | "cell_type": "code", 288 | "execution_count": 0, 289 | "metadata": { 290 | "collapsed": false 291 | }, 292 | "outputs": [ 293 | ], 294 | "source": [ 295 | ] 296 | } 297 | ], 298 | "metadata": { 299 | "kernelspec": { 300 | "display_name": "Python 2 (SageMath)", 301 | "language": "python", 302 | "name": "python2" 303 | }, 304 | "language_info": { 305 | "codemirror_mode": { 306 | "name": "ipython", 307 | "version": 2 308 | }, 309 | "file_extension": ".py", 310 | "mimetype": "text/x-python", 311 | "name": "python", 312 | "nbconvert_exporter": "python", 313 | "pygments_lexer": "ipython2", 314 | "version": "2.7.14" 315 | } 316 | }, 317 | "nbformat": 4, 318 | "nbformat_minor": 0 319 | } -------------------------------------------------------------------------------- /assignments/2018-01-12/DUE_DATE.txt: -------------------------------------------------------------------------------- 1 | This assignment is due 2 | 3 | 1/12/2018, 8:00:00 PM -------------------------------------------------------------------------------- /assignments/2018-01-19/2018-01-19.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "## Math 157: Intro to Mathematical Software\n", 10 | "## UC San Diego, winter 2018" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "collapsed": false 17 | }, 18 | "source": [ 19 | "## Homework 1: due January 19, 2018" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": { 25 | "collapsed": false 26 | }, 27 | "source": [ 28 | "Please enter all answers within this notebook unless otherwise specified.\n", 29 | "\n", 30 | "Each problem's statement includes the criteria by which it will be graded. Correctness means in particular that all code that is supposed to execute must actually do so without errors! In addition, you may be marked off for not setting cells to the appropriate format (Code or Markdown), or for not answering textual questions in complete, grammatical English sentences with proper spelling and punctuation.\n", 31 | "\n", 32 | "Note: homework assignments may consist of variable numbers of problems, but the maximum possible scores will be renormalized to a common value for the computation of grades." 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": { 38 | "collapsed": false 39 | }, 40 | "source": [ 41 | "### Problem 1: Comparison of programming languages" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": { 47 | "collapsed": false 48 | }, 49 | "source": [ 50 | "Grading criterion: correctness." 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": { 56 | "collapsed": false 57 | }, 58 | "source": [ 59 | "1a. Explain the difference between 0-based arrays and 1-based arrays." 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 0, 65 | "metadata": { 66 | "collapsed": false 67 | }, 68 | "outputs": [ 69 | ], 70 | "source": [ 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": { 76 | "collapsed": false 77 | }, 78 | "source": [ 79 | "1b. Explain the difference between \"pass by reference\" and \"pass by value\"." 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 0, 85 | "metadata": { 86 | "collapsed": false 87 | }, 88 | "outputs": [ 89 | ], 90 | "source": [ 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "metadata": { 96 | "collapsed": false 97 | }, 98 | "source": [ 99 | "1c. Classify the following programming languages according to the criteria in parts a and b: Python, MATLAB, R, Javascript, Julia. For examples of the languages other than Python, see the Sage worksheet \"comparison.sagews\" in this folder." 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 0, 105 | "metadata": { 106 | "collapsed": false 107 | }, 108 | "outputs": [ 109 | ], 110 | "source": [ 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": { 116 | "collapsed": false 117 | }, 118 | "source": [ 119 | "### Problem 2: Truth values" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": { 125 | "collapsed": false 126 | }, 127 | "source": [ 128 | "Grading criterion: correctness and thoroughness." 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": { 134 | "collapsed": false 135 | }, 136 | "source": [ 137 | "An expression `e` will be called *truthy* if `bool(e)` is True (i.e., if `if e: stuff` executes `stuff`); otherwise `e` is falsy." 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": { 143 | "collapsed": false 144 | }, 145 | "source": [ 146 | "1a. Create a list `l` consisting of 10 different Python objects that are falsy. For correctness, your list must have the property that `a is b` evaluates to False whenever `a` and `b` are entries of the list in different positions. For thoroughness, the entries should look as different as possible. (Hint: `[]` is an example.)" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 0, 152 | "metadata": { 153 | "collapsed": false 154 | }, 155 | "outputs": [ 156 | ], 157 | "source": [ 158 | "l = [] #insert ten objects here" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 0, 164 | "metadata": { 165 | "collapsed": false 166 | }, 167 | "outputs": [ 168 | ], 169 | "source": [ 170 | "# Use this code to test correctness of your answer!\n", 171 | "print(len(l) == 10)\n", 172 | "print(all(not l[i] for i in range(10)))\n", 173 | "print(all(not (l[i] is l[j]) for i in range(10) for j in range(i+1,10)))" 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "metadata": { 179 | "collapsed": false 180 | }, 181 | "source": [ 182 | "1b. In Python, \"is\" means \"identical objects\", whereas \"==\" can be much more subtle. Create a list `l` consisting of 5 tuples `(a,b)` for each of which `a==b` evaluates to True but `a is b` evaluates to False." 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 0, 188 | "metadata": { 189 | "collapsed": false 190 | }, 191 | "outputs": [ 192 | ], 193 | "source": [ 194 | "l = [] #insert five objects here" 195 | ] 196 | }, 197 | { 198 | "cell_type": "markdown", 199 | "metadata": { 200 | "collapsed": false 201 | }, 202 | "source": [ 203 | "1c. By analogy with the code snippet given in 1a, write a code snippet to verify correctness of your answer to 1b. That is, the code snippet should print one or more True/False values, all of which are True if and only if the answer is correct." 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": 0, 209 | "metadata": { 210 | "collapsed": false 211 | }, 212 | "outputs": [ 213 | ], 214 | "source": [ 215 | "# Your code snippet goes here l[i][0] l[i][1]" 216 | ] 217 | }, 218 | { 219 | "cell_type": "markdown", 220 | "metadata": { 221 | "collapsed": false 222 | }, 223 | "source": [ 224 | "### Problem 3: Flow control" 225 | ] 226 | }, 227 | { 228 | "cell_type": "markdown", 229 | "metadata": { 230 | "collapsed": false 231 | }, 232 | "source": [ 233 | "Grading criterion: correctness of output." 234 | ] 235 | }, 236 | { 237 | "cell_type": "markdown", 238 | "metadata": { 239 | "collapsed": false 240 | }, 241 | "source": [ 242 | "Write a function named `fizz_buzz` that accepts an integer `N` and for each integer `m` from `1` to `N`, prints 'Fizz' if `m` is divisible by 2 but not 3, prints 'Buzz' if `m` is divisible by 3 but not 2, prints 'FizzBuzz' if `m` is divisible by 2 and 3, and prints 'Moot' if none of the above." 243 | ] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "execution_count": 0, 248 | "metadata": { 249 | "collapsed": false 250 | }, 251 | "outputs": [ 252 | ], 253 | "source": [ 254 | "# Your code goes here" 255 | ] 256 | }, 257 | { 258 | "cell_type": "code", 259 | "execution_count": 0, 260 | "metadata": { 261 | "collapsed": false 262 | }, 263 | "outputs": [ 264 | ], 265 | "source": [ 266 | "# Test your answer against the output below\n", 267 | "fizz_buzz(7)" 268 | ] 269 | }, 270 | { 271 | "cell_type": "raw", 272 | "metadata": { 273 | "collapsed": false 274 | }, 275 | "source": [ 276 | "Moot\n", 277 | "Fizz\n", 278 | "Buzz\n", 279 | "Fizz\n", 280 | "Moot\n", 281 | "FizzBuzz\n", 282 | "Moot" 283 | ] 284 | }, 285 | { 286 | "cell_type": "markdown", 287 | "metadata": { 288 | "collapsed": false 289 | }, 290 | "source": [ 291 | "### Problem 4: Better and worse" 292 | ] 293 | }, 294 | { 295 | "cell_type": "code", 296 | "execution_count": 0, 297 | "metadata": { 298 | "collapsed": false 299 | }, 300 | "outputs": [ 301 | ], 302 | "source": [ 303 | ] 304 | }, 305 | { 306 | "cell_type": "markdown", 307 | "metadata": { 308 | "collapsed": false 309 | }, 310 | "source": [ 311 | "Grading criterion: correctness (of the code) and thoroughness (of the explanation)." 312 | ] 313 | }, 314 | { 315 | "cell_type": "markdown", 316 | "metadata": { 317 | "collapsed": false 318 | }, 319 | "source": [ 320 | "4a. Read about *recursion* in Python. Then write two different functions that, on an input `N`, return the `N`th Fibonacci number: one using recursion, and one not." 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": 0, 326 | "metadata": { 327 | "collapsed": false 328 | }, 329 | "outputs": [ 330 | ], 331 | "source": [ 332 | "def fib1(N):\n", 333 | " # your code goes here" 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "execution_count": 0, 339 | "metadata": { 340 | "collapsed": false 341 | }, 342 | "outputs": [ 343 | ], 344 | "source": [ 345 | "def fib2(N):\n", 346 | " # your code goes here" 347 | ] 348 | }, 349 | { 350 | "cell_type": "markdown", 351 | "metadata": { 352 | "collapsed": false 353 | }, 354 | "source": [ 355 | "4b. State an identity of Fibonacci numbers other than the defining recurrence $F_n = F_{n-1} + F_{n-2}$; use TeX symbols to format this correctly. Then write some code that tests this identity using your two functions." 356 | ] 357 | }, 358 | { 359 | "cell_type": "code", 360 | "execution_count": 0, 361 | "metadata": { 362 | "collapsed": false 363 | }, 364 | "outputs": [ 365 | ], 366 | "source": [ 367 | "Your identity: (fill in here)" 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "execution_count": 0, 373 | "metadata": { 374 | "collapsed": false 375 | }, 376 | "outputs": [ 377 | ], 378 | "source": [ 379 | "# Your test code goes here" 380 | ] 381 | }, 382 | { 383 | "cell_type": "markdown", 384 | "metadata": { 385 | "collapsed": false 386 | }, 387 | "source": [ 388 | "4c. Give as detailed an explanation of possible of why your non-recursive function is \"better\" than the recursive one. You may wish to do some online research for this, in which case please cite your sources." 389 | ] 390 | }, 391 | { 392 | "cell_type": "code", 393 | "execution_count": 0, 394 | "metadata": { 395 | "collapsed": false 396 | }, 397 | "outputs": [ 398 | ], 399 | "source": [ 400 | ] 401 | }, 402 | { 403 | "cell_type": "markdown", 404 | "metadata": { 405 | "collapsed": false 406 | }, 407 | "source": [ 408 | "### Problem 5: Dictionaries" 409 | ] 410 | }, 411 | { 412 | "cell_type": "markdown", 413 | "metadata": { 414 | "collapsed": false 415 | }, 416 | "source": [ 417 | "Grading criterion: correctness and thoroughness." 418 | ] 419 | }, 420 | { 421 | "cell_type": "markdown", 422 | "metadata": { 423 | "collapsed": false 424 | }, 425 | "source": [ 426 | "5a. Search online and find as many names as you can for data structures that are like a Python \"dictionary\", but in other programming languages. (For example, in Javascript the analogue of a Python dictionary is called a \"Map\".)\n" 427 | ] 428 | }, 429 | { 430 | "cell_type": "code", 431 | "execution_count": 0, 432 | "metadata": { 433 | "collapsed": false 434 | }, 435 | "outputs": [ 436 | ], 437 | "source": [ 438 | ] 439 | }, 440 | { 441 | "cell_type": "markdown", 442 | "metadata": { 443 | "collapsed": false 444 | }, 445 | "source": [ 446 | "5b. Give a list `l1` of four Python objects that can't be the keys of a Python dictionary, and a list `l2` of four objects that can be keys of a Python dictionary. Then check that each object consists of four objects of different types; that is, `[type(obj) for obj in l1]` should contain no repeated entries, and similarly for `l2`. (The check should be in the form of a code snippet that prints True if the check passes and False if it fails.)" 447 | ] 448 | }, 449 | { 450 | "cell_type": "code", 451 | "execution_count": 0, 452 | "metadata": { 453 | "collapsed": false 454 | }, 455 | "outputs": [ 456 | ], 457 | "source": [ 458 | "# Define lists l1, l2 here" 459 | ] 460 | }, 461 | { 462 | "cell_type": "code", 463 | "execution_count": 5, 464 | "metadata": { 465 | "collapsed": false 466 | }, 467 | "outputs": [ 468 | ], 469 | "source": [ 470 | "# Check correctness of your answer here" 471 | ] 472 | }, 473 | { 474 | "cell_type": "markdown", 475 | "metadata": { 476 | "collapsed": false 477 | }, 478 | "source": [ 479 | "### Problem 6: List comprehensions" 480 | ] 481 | }, 482 | { 483 | "cell_type": "markdown", 484 | "metadata": { 485 | "collapsed": false 486 | }, 487 | "source": [ 488 | "Grading criterion: correctness." 489 | ] 490 | }, 491 | { 492 | "cell_type": "markdown", 493 | "metadata": { 494 | "collapsed": false 495 | }, 496 | "source": [ 497 | "Translate each of the following mathematical definitions of sets into a Python list comprehension:\n", 498 | "\n", 499 | "- $\\{x: 0 < x < 100, x \\not\\equiv 0 \\pmod{3} \\}$\n", 500 | "- $\\{x: 10 < x < 50, x^2 \\equiv 1 \\pmod{5}\\}$\n", 501 | "- $\\{(x,y): 0 < x < 1000, 0 < y < 1000, x^2 - y^3 = 1\\}$\n", 502 | "- $\\{(x,y): -10 < x < 10, -10 < y < 10, |x^2-y^2-y| < 3\\}$" 503 | ] 504 | }, 505 | { 506 | "cell_type": "code", 507 | "execution_count": 0, 508 | "metadata": { 509 | "collapsed": false 510 | }, 511 | "outputs": [ 512 | ], 513 | "source": [ 514 | ] 515 | }, 516 | { 517 | "cell_type": "code", 518 | "execution_count": 0, 519 | "metadata": { 520 | "collapsed": false 521 | }, 522 | "outputs": [ 523 | ], 524 | "source": [ 525 | ] 526 | }, 527 | { 528 | "cell_type": "code", 529 | "execution_count": 0, 530 | "metadata": { 531 | "collapsed": false 532 | }, 533 | "outputs": [ 534 | ], 535 | "source": [ 536 | ] 537 | }, 538 | { 539 | "cell_type": "code", 540 | "execution_count": 0, 541 | "metadata": { 542 | "collapsed": false 543 | }, 544 | "outputs": [ 545 | ], 546 | "source": [ 547 | ] 548 | } 549 | ], 550 | "metadata": { 551 | "kernelspec": { 552 | "display_name": "Python 3 (Ubuntu Linux)", 553 | "language": "python", 554 | "name": "python3" 555 | }, 556 | "language_info": { 557 | "codemirror_mode": { 558 | "name": "ipython", 559 | "version": 3 560 | }, 561 | "file_extension": ".py", 562 | "mimetype": "text/x-python", 563 | "name": "python", 564 | "nbconvert_exporter": "python", 565 | "pygments_lexer": "ipython3", 566 | "version": "3.5.2" 567 | } 568 | }, 569 | "nbformat": 4, 570 | "nbformat_minor": 0 571 | } -------------------------------------------------------------------------------- /assignments/2018-01-19/DUE_DATE.txt: -------------------------------------------------------------------------------- 1 | This assignment is due 2 | 3 | 1/19/2018, 8:00:00 PM -------------------------------------------------------------------------------- /assignments/2018-01-19/comparison.sagews: -------------------------------------------------------------------------------- 1 | ︠81d2d0a0-7c27-4cee-a4b6-d115fad94f96i︠ 2 | %md 3 | This file is a Sage worksheet. It behaves similarly to a Jupyter worksheet, in that it is divided into cells that can be individually executed by typing Shift-Enter. One difference is that it is possible to specify a different programming language for each cell, 4 | as illustrated by this worksheet. See the homework notebook 2018-01-19.ipynb for additional instructions. 5 | ︡0a36943f-53a8-426e-a965-c435f18719c6︡{"done":true,"md":"This file is a Sage worksheet. It behaves similarly to a Jupyter worksheet, in that it is divided into cells that can be individually executed by typing Shift-Enter. One difference is that it is possible to specify a different programming language for each cell,\nas illustrated by this worksheet. See the homework notebook 2018-01-19.ipynb for additional instructions."} 6 | ︠fe0de7b1-d6f0-4f71-a41f-8474055f5815i︠ 7 | %md 8 | Here is an example of arrays in Octave, an open-source system which emulates the syntax of MATLAB. We will compare linear-algebra functionality between MATLAB and Sage later. 9 | ︡9262851e-8a3d-472b-975b-854440cf32ef︡{"done":true,"md":"Here is an example of arrays in Octave, an open-source system which emulates the syntax of MATLAB. We will compare linear-algebra functionality between MATLAB and Sage later."} 10 | ︠66b01fb9-44ac-490a-b831-a6f371deba1ds︠ 11 | %octave 12 | a = [1,2,3]; 13 | b = a; 14 | b(1) = 5; 15 | a 16 | b 17 | ︡705c2407-10fe-44a4-b83d-b64275f89cf0︡{"stdout":"a =\n"}︡{"stdout":"\n"}︡{"stdout":" 1 2 3\n"}︡{"stdout":"\n"}︡{"stdout":"b =\n"}︡{"stdout":"\n"}︡{"stdout":" 5 2 3\n"}︡{"stdout":"\n"}︡{"done":true}︡ 18 | ︠00e4d263-8358-4823-9d10-ee0d41f10e42i︠ 19 | %md 20 | Here is an example of arrays in R, an open-source system for statistics which we will study later. 21 | ︡7d2fa51b-c1b4-4b1b-9c90-c8ed05b72f2e︡{"done":true,"md":"Here is an example of arrays in R, an open-source system for statistics which we will study later."} 22 | ︠8bc307ad-695b-4d78-a8a0-e87872ae4e87s︠ 23 | %r 24 | a <- c(1,2,3); 25 | b <- a; 26 | b[1] = 5; 27 | a 28 | b 29 | ︡4f714767-8038-41b5-a2a2-72ba8af0080a︡{"html":"
    \n\t
  1. 1
  2. \n\t
  3. 2
  4. \n\t
  5. 3
  6. \n
\n"}︡{"html":"
    \n\t
  1. 5
  2. \n\t
  3. 2
  4. \n\t
  5. 3
  6. \n
\n"}︡{"done":true}︡ 30 | ︠f368c54c-2265-4e03-a8e5-e9a46d7de571i︠ 31 | %md 32 | Here is an example of arrays in Javascript (for comparison only; we will not study this language further). 33 | ︡2b7e290e-4621-4aaa-921b-82832d463a55︡{"done":true,"md":"Here is an example of arrays in Javascript (for comparison only; we will not study this language further)."} 34 | ︠43487cbb-28d8-4054-b0dc-7da0b57c075f︠ 35 | %javascript 36 | a = [1,2,3]; 37 | b = a; 38 | b[0] = 5; 39 | print("a =",a) 40 | print("b =",b) 41 | ︡1736f98c-f67f-493a-a76e-51715c0b568f︡{"done":true,"javascript":{"code":"a = [1,2,3];\nb = a;\nb[0] = 5;\nprint(\"a =\",a)\nprint(\"b =\",b)"}} 42 | ︠7aa504e0-2727-45d1-b3db-135590c92076i︠ 43 | %md 44 | Here is an example of arrays in Julia, a new language for scientific computing which we will study later. 45 | ︡342e784f-7ebb-484c-89ff-646db8f175e2︡{"done":true,"md":"Here is an example of arrays in Julia, a new language for scientific computing which we will study later."} 46 | ︠305641ca-5daf-4aea-a458-3adaf9016301s︠ 47 | %julia 48 | a = [1,2,3]; 49 | b = a; 50 | b[1] = 5; 51 | println("a =", a, "\nb =", b); 52 | ︡b81baf40-0c6f-4abf-8815-4884da84fca2︡{"stdout":"a =[5, 2, 3]\nb =[5, 2, 3]\n"}︡{"done":true}︡ 53 | ︠cb7a6b20-a9c7-4120-8b8e-df2acafa1a89︠ 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /assignments/2018-01-26/2018-01-26.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "## Math 157: Intro to Mathematical Software\n", 10 | "## UC San Diego, winter 2018" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "collapsed": false 17 | }, 18 | "source": [ 19 | "## Homework 2: due January 26, 2018" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": { 25 | "collapsed": false 26 | }, 27 | "source": [ 28 | "Please enter all answers within this notebook unless otherwise specified. As usual, don't forget to cite sources and collaborators." 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": { 34 | "collapsed": false 35 | }, 36 | "source": [ 37 | "### Problem 1: Comparison of relevant software" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": { 43 | "collapsed": false 44 | }, 45 | "source": [ 46 | "Grading criterion: correctness. Remember to cite all sources!" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": { 52 | "collapsed": false 53 | }, 54 | "source": [ 55 | "1a. Specify whether each of the following computer algebra systems fits the Open Source Initiative definition of an \"open-source\" project (https://opensource.org/definition). If not, identify a criterion which fails to be met.\n", 56 | "\n", 57 | "- GAP\n", 58 | "- Geogebra\n", 59 | "- Magma\n", 60 | "- Maple\n", 61 | "- Mathematica\n", 62 | "- MATLAB\n", 63 | "- Pari/GP\n", 64 | "- Sage\n", 65 | "- Sympy" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 0, 71 | "metadata": { 72 | "collapsed": false 73 | }, 74 | "outputs": [ 75 | ], 76 | "source": [ 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": { 82 | "collapsed": false 83 | }, 84 | "source": [ 85 | "1b. For each of the following projects, give a one-sentence description of the project, and indicate in what year and by what person/organization the first version was released.\n", 86 | "\n", 87 | "- Cython\n", 88 | "- Julia\n", 89 | "- MacSyma / Maxima (treat as one project)\n", 90 | "- Numpy\n", 91 | "- Pandas\n", 92 | "- Python\n", 93 | "- R\n", 94 | "- Sage\n", 95 | "- Scipy\n", 96 | "- TeX / LaTeX (treat as one project)\n" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 0, 102 | "metadata": { 103 | "collapsed": false 104 | }, 105 | "outputs": [ 106 | ], 107 | "source": [ 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "metadata": { 113 | "collapsed": false 114 | }, 115 | "source": [ 116 | "### Problem 2: Under the hood" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": { 122 | "collapsed": false 123 | }, 124 | "source": [ 125 | "Grading criterion: correctness." 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": { 131 | "collapsed": false 132 | }, 133 | "source": [ 134 | "For each of the following Sage commands, identify one [external component of Sage](http://www.sagemath.org/links-components.html) which is used to execute that command, and indicate how you did so. (Hint: in addition to the Sage documentation, inspecting docstrings or even source code may be helpful.)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 0, 140 | "metadata": { 141 | "collapsed": false 142 | }, 143 | "outputs": [ 144 | ], 145 | "source": [ 146 | "factor(10^30-13)" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 0, 152 | "metadata": { 153 | "collapsed": false 154 | }, 155 | "outputs": [ 156 | ], 157 | "source": [ 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 0, 163 | "metadata": { 164 | "collapsed": false 165 | }, 166 | "outputs": [ 167 | ], 168 | "source": [ 169 | "plot(lambda x: sin(x), 0, 2*pi)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 0, 175 | "metadata": { 176 | "collapsed": false 177 | }, 178 | "outputs": [ 179 | ], 180 | "source": [ 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": 0, 186 | "metadata": { 187 | "collapsed": false 188 | }, 189 | "outputs": [ 190 | ], 191 | "source": [ 192 | "G = AlternatingGroup(4)\n", 193 | "G.subgroups()" 194 | ] 195 | }, 196 | { 197 | "cell_type": "code", 198 | "execution_count": 0, 199 | "metadata": { 200 | "collapsed": false 201 | }, 202 | "outputs": [ 203 | ], 204 | "source": [ 205 | ] 206 | }, 207 | { 208 | "cell_type": "code", 209 | "execution_count": 2, 210 | "metadata": { 211 | "collapsed": false 212 | }, 213 | "outputs": [ 214 | { 215 | "data": { 216 | "text/plain": [ 217 | "-(x + y)/z^2" 218 | ] 219 | }, 220 | "execution_count": 2, 221 | "metadata": { 222 | }, 223 | "output_type": "execute_result" 224 | } 225 | ], 226 | "source": [ 227 | "var('x,y,z')\n", 228 | "f = (x+y)/z\n", 229 | "f.derivative(z)" 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": 0, 235 | "metadata": { 236 | "collapsed": false 237 | }, 238 | "outputs": [ 239 | ], 240 | "source": [ 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 3, 246 | "metadata": { 247 | "collapsed": false 248 | }, 249 | "outputs": [ 250 | { 251 | "data": { 252 | "text/plain": [ 253 | "1" 254 | ] 255 | }, 256 | "execution_count": 3, 257 | "metadata": { 258 | }, 259 | "output_type": "execute_result" 260 | } 261 | ], 262 | "source": [ 263 | "z.derivative??" 264 | ] 265 | }, 266 | { 267 | "cell_type": "code", 268 | "execution_count": 0, 269 | "metadata": { 270 | "collapsed": false 271 | }, 272 | "outputs": [ 273 | ], 274 | "source": [ 275 | "R. = PolynomialRing(QQ)\n", 276 | "factor(x^3+y^3+z^3-3*x*y*z)" 277 | ] 278 | }, 279 | { 280 | "cell_type": "code", 281 | "execution_count": 0, 282 | "metadata": { 283 | "collapsed": false 284 | }, 285 | "outputs": [ 286 | ], 287 | "source": [ 288 | ] 289 | }, 290 | { 291 | "cell_type": "markdown", 292 | "metadata": { 293 | "collapsed": false 294 | }, 295 | "source": [ 296 | "### Problem 3: Mersenne primes" 297 | ] 298 | }, 299 | { 300 | "cell_type": "markdown", 301 | "metadata": { 302 | "collapsed": false 303 | }, 304 | "source": [ 305 | "Grading criteria: correctness of explanation and code." 306 | ] 307 | }, 308 | { 309 | "cell_type": "markdown", 310 | "metadata": { 311 | "collapsed": false 312 | }, 313 | "source": [ 314 | "3a. A *Mersenne prime* is a prime number of the form $2^p-1$ where $p$ is itself prime. (Note that these are the only possible primes of the form $2^n-1$ where $n$ is a positive integer). They are called this because Marin Mersenne was the first person to attempt to list these primes systematically: he claimed that for $p \\leq 257$, $2^p-1$ is prime if and only if\n", 315 | "$$p \\in \\{2, 3, 5, 7, 13, 17, 19, 31, 67, 127, 257\\}.$$\n", 316 | "This list turns out to be incorrect; write Sage code to compute the correct list." 317 | ] 318 | }, 319 | { 320 | "cell_type": "code", 321 | "execution_count": 0, 322 | "metadata": { 323 | "collapsed": false 324 | }, 325 | "outputs": [ 326 | ], 327 | "source": [ 328 | "# your code goes here" 329 | ] 330 | }, 331 | { 332 | "cell_type": "markdown", 333 | "metadata": { 334 | "collapsed": false 335 | }, 336 | "source": [ 337 | "3b. On January 3, 2018, the [Great Internet Mersenne Prime Search](https://www.mersenne.org/) announced that $2^{77232917}-1$ is the \"50th known Mersenne prime.\" Why didn't they announce that it is the \"50th Mersenne prime\"?" 338 | ] 339 | }, 340 | { 341 | "cell_type": "markdown", 342 | "metadata": { 343 | "collapsed": false 344 | }, 345 | "source": [ 346 | ] 347 | }, 348 | { 349 | "cell_type": "markdown", 350 | "metadata": { 351 | "collapsed": false 352 | }, 353 | "source": [ 354 | "3c. The little Fermat theorem states that if $p$ is prime, then $2^{p-1} \\equiv 1 \\pmod{p}$. This can be used as a test for primality (the *Fermat test*) which has no false negatives, but does have some false positives (see part (d)).\n", 355 | "\n", 356 | "Explain why the following code cannot be used to apply the Fermat test to the number $p = 2^{21701}-1$, then give an alternate approach that does work. " 357 | ] 358 | }, 359 | { 360 | "cell_type": "raw", 361 | "metadata": { 362 | "collapsed": false 363 | }, 364 | "source": [ 365 | "p = 2^21701 - 1\n", 366 | "print(2^(p-1) % p) # This won't work." 367 | ] 368 | }, 369 | { 370 | "cell_type": "markdown", 371 | "metadata": { 372 | "collapsed": false 373 | }, 374 | "source": [ 375 | "(your explanation goes here)" 376 | ] 377 | }, 378 | { 379 | "cell_type": "code", 380 | "execution_count": 0, 381 | "metadata": { 382 | "collapsed": false 383 | }, 384 | "outputs": [ 385 | ], 386 | "source": [ 387 | "# your better code goes here" 388 | ] 389 | }, 390 | { 391 | "cell_type": "markdown", 392 | "metadata": { 393 | "collapsed": false 394 | }, 395 | "source": [ 396 | "3d. Find all integers up to 1000 which are false positives for the Fermat test. These include *Carmichael numbers*, in case you want to read more about this phenomenon." 397 | ] 398 | }, 399 | { 400 | "cell_type": "code", 401 | "execution_count": 0, 402 | "metadata": { 403 | "collapsed": false 404 | }, 405 | "outputs": [ 406 | ], 407 | "source": [ 408 | "# your code goes here" 409 | ] 410 | }, 411 | { 412 | "cell_type": "markdown", 413 | "metadata": { 414 | "collapsed": false 415 | }, 416 | "source": [ 417 | "### Problem 4: Defining and evaluating a function" 418 | ] 419 | }, 420 | { 421 | "cell_type": "markdown", 422 | "metadata": { 423 | "collapsed": false 424 | }, 425 | "source": [ 426 | "Grading criteria: correctness of code." 427 | ] 428 | }, 429 | { 430 | "cell_type": "markdown", 431 | "metadata": { 432 | "collapsed": false 433 | }, 434 | "source": [ 435 | "4a. Define in Sage the symbolic function (not a Python function)\n", 436 | "$$f(x) = \\sinh(x^2-x-1) + e^{\\pi x} + \\arcsin(x) + \\frac{1}{x^3-x-e}$$." 437 | ] 438 | }, 439 | { 440 | "cell_type": "code", 441 | "execution_count": 0, 442 | "metadata": { 443 | "collapsed": false 444 | }, 445 | "outputs": [ 446 | ], 447 | "source": [ 448 | ] 449 | }, 450 | { 451 | "cell_type": "markdown", 452 | "metadata": { 453 | "collapsed": false 454 | }, 455 | "source": [ 456 | "4b. Compute $f(1/2)$ exactly (i.e., your answer should be a symbolic expression)." 457 | ] 458 | }, 459 | { 460 | "cell_type": "code", 461 | "execution_count": 0, 462 | "metadata": { 463 | "collapsed": false 464 | }, 465 | "outputs": [ 466 | ], 467 | "source": [ 468 | ] 469 | }, 470 | { 471 | "cell_type": "markdown", 472 | "metadata": { 473 | "collapsed": false 474 | }, 475 | "source": [ 476 | "4c. Compute $f(1/2)$ numerically (i.e., your answer should be a decimal expansion)." 477 | ] 478 | }, 479 | { 480 | "cell_type": "code", 481 | "execution_count": 0, 482 | "metadata": { 483 | "collapsed": false 484 | }, 485 | "outputs": [ 486 | ], 487 | "source": [ 488 | ] 489 | }, 490 | { 491 | "cell_type": "markdown", 492 | "metadata": { 493 | "collapsed": false 494 | }, 495 | "source": [ 496 | "4d. Plot $f(x)$ from $-1$ to $1$." 497 | ] 498 | }, 499 | { 500 | "cell_type": "code", 501 | "execution_count": 0, 502 | "metadata": { 503 | "collapsed": false 504 | }, 505 | "outputs": [ 506 | ], 507 | "source": [ 508 | ] 509 | }, 510 | { 511 | "cell_type": "markdown", 512 | "metadata": { 513 | "collapsed": false 514 | }, 515 | "source": [ 516 | "### Problem 5: Numerical root-finding" 517 | ] 518 | }, 519 | { 520 | "cell_type": "markdown", 521 | "metadata": { 522 | "collapsed": false 523 | }, 524 | "source": [ 525 | "Grading criteria: correctness (of code) and thoroughness (of explanation)." 526 | ] 527 | }, 528 | { 529 | "cell_type": "markdown", 530 | "metadata": { 531 | "collapsed": false 532 | }, 533 | "source": [ 534 | "5a. Plot the function $f(x) = \\displaystyle x^2 + \\sin(x)$ on the interval $[-2,2]$.\n" 535 | ] 536 | }, 537 | { 538 | "cell_type": "code", 539 | "execution_count": 0, 540 | "metadata": { 541 | "collapsed": false 542 | }, 543 | "outputs": [ 544 | ], 545 | "source": [ 546 | ] 547 | }, 548 | { 549 | "cell_type": "markdown", 550 | "metadata": { 551 | "collapsed": false 552 | }, 553 | "source": [ 554 | "5b. Use Sage to compute the derivative and antiderivative of $f$.\n" 555 | ] 556 | }, 557 | { 558 | "cell_type": "code", 559 | "execution_count": 0, 560 | "metadata": { 561 | "collapsed": false 562 | }, 563 | "outputs": [ 564 | ], 565 | "source": [ 566 | ] 567 | }, 568 | { 569 | "cell_type": "markdown", 570 | "metadata": { 571 | "collapsed": false 572 | }, 573 | "source": [ 574 | "5c. Find numerical approximations to *all* of the zeros of $f(x)$." 575 | ] 576 | }, 577 | { 578 | "cell_type": "code", 579 | "execution_count": 0, 580 | "metadata": { 581 | "collapsed": false 582 | }, 583 | "outputs": [ 584 | ], 585 | "source": [ 586 | ] 587 | }, 588 | { 589 | "cell_type": "markdown", 590 | "metadata": { 591 | "collapsed": false 592 | }, 593 | "source": [ 594 | "5d. In as much detail as you can, justify mathematically why your list in (c) is complete. Your explanation may include additional Sage code if necessary." 595 | ] 596 | }, 597 | { 598 | "cell_type": "code", 599 | "execution_count": 0, 600 | "metadata": { 601 | "collapsed": false 602 | }, 603 | "outputs": [ 604 | ], 605 | "source": [ 606 | ] 607 | }, 608 | { 609 | "cell_type": "markdown", 610 | "metadata": { 611 | "collapsed": false 612 | }, 613 | "source": [ 614 | "### Problem 6: Taylor series" 615 | ] 616 | }, 617 | { 618 | "cell_type": "markdown", 619 | "metadata": { 620 | "collapsed": false 621 | }, 622 | "source": [ 623 | "Grading criteria: correctness." 624 | ] 625 | }, 626 | { 627 | "cell_type": "markdown", 628 | "metadata": { 629 | "collapsed": false 630 | }, 631 | "source": [ 632 | "6a. Define the function $f(x) = \\sin(x^2)$. Find the degree 3 Taylor series $p_3$ of $f$ about $x_0 = 2\\pi$." 633 | ] 634 | }, 635 | { 636 | "cell_type": "code", 637 | "execution_count": 0, 638 | "metadata": { 639 | "collapsed": false 640 | }, 641 | "outputs": [ 642 | ], 643 | "source": [ 644 | ] 645 | }, 646 | { 647 | "cell_type": "markdown", 648 | "metadata": { 649 | "collapsed": false 650 | }, 651 | "source": [ 652 | "6b. Make a single Sage plot on the interval $x=[\\pi, 3\\pi]$ showing both $f(x)$ and its degree 10 Taylor series $p_{10}$ about $x_0 = 2\\pi$." 653 | ] 654 | }, 655 | { 656 | "cell_type": "code", 657 | "execution_count": 0, 658 | "metadata": { 659 | "collapsed": false 660 | }, 661 | "outputs": [ 662 | ], 663 | "source": [ 664 | ] 665 | } 666 | ], 667 | "metadata": { 668 | "kernelspec": { 669 | "display_name": "SageMath 8.1", 670 | "name": "sage-8.1" 671 | }, 672 | "language_info": { 673 | "codemirror_mode": { 674 | "name": "ipython", 675 | "version": 2 676 | }, 677 | "file_extension": ".py", 678 | "mimetype": "text/x-python", 679 | "name": "python", 680 | "nbconvert_exporter": "python", 681 | "pygments_lexer": "ipython2", 682 | "version": "2.7.14" 683 | } 684 | }, 685 | "nbformat": 4, 686 | "nbformat_minor": 0 687 | } -------------------------------------------------------------------------------- /assignments/2018-01-26/DUE_DATE.txt: -------------------------------------------------------------------------------- 1 | This assignment is due 2 | 3 | 1/26/2018, 8:00:00 PM -------------------------------------------------------------------------------- /assignments/2018-02-02/2018-02-02.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "## Math 157: Intro to Mathematical Software\n", 10 | "## UC San Diego, winter 2018" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "collapsed": false 17 | }, 18 | "source": [ 19 | "## Homework 3: due February 2, 2018" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": { 25 | "collapsed": false 26 | }, 27 | "source": [ 28 | "Please enter all answers within this notebook unless otherwise specified. As usual, don't forget to cite sources and collaborators.\n", 29 | "\n", 30 | "Through this problem set, use the SageMath 8.1 kernel unless otherwise specified." 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": { 36 | "collapsed": false 37 | }, 38 | "source": [ 39 | "### Problem 1: Gradient vector fields" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": { 45 | "collapsed": false 46 | }, 47 | "source": [ 48 | "Grading criterion: correctness of code." 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": { 54 | "collapsed": false 55 | }, 56 | "source": [ 57 | "1a. Compute the gradient of $f(x,y) = 3\\sin(x) - 2\\cos(2y) - x - y$." 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 0, 63 | "metadata": { 64 | "collapsed": false 65 | }, 66 | "outputs": [ 67 | ], 68 | "source": [ 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "metadata": { 74 | "collapsed": false 75 | }, 76 | "source": [ 77 | "1b. Plot the 2-dimensional vector field defined by the gradient of $f$ in the rectangle $(-2,-2) \\leq (x,y) \\leq (2,2)$." 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 0, 83 | "metadata": { 84 | "collapsed": false 85 | }, 86 | "outputs": [ 87 | ], 88 | "source": [ 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": { 94 | "collapsed": false 95 | }, 96 | "source": [ 97 | "### Problem 2: 3D plotting" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": { 103 | "collapsed": false 104 | }, 105 | "source": [ 106 | "Grading criterion: correctness of code." 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": { 112 | "collapsed": false 113 | }, 114 | "source": [ 115 | "2a. Draw a 3D plot of a torus." 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": 0, 121 | "metadata": { 122 | "collapsed": false 123 | }, 124 | "outputs": [ 125 | ], 126 | "source": [ 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": { 132 | "collapsed": false 133 | }, 134 | "source": [ 135 | "2b. Draw a single 3D plot containing the five regular polytopes in it: tetrahedron, cube, octahedron, dodecahedron, icosahedron. All five must be visible." 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 0, 141 | "metadata": { 142 | "collapsed": false 143 | }, 144 | "outputs": [ 145 | ], 146 | "source": [ 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": { 152 | "collapsed": false 153 | }, 154 | "source": [ 155 | "2c. Draw a 3D plot of the [Mexican hat function](https://en.wikipedia.org/wiki/Mexican_hat_wavelet). Try to choose the parameter $\\sigma$ to get an authentic \"sombrero\" look." 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 0, 161 | "metadata": { 162 | "collapsed": false 163 | }, 164 | "outputs": [ 165 | ], 166 | "source": [ 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": { 172 | "collapsed": false 173 | }, 174 | "source": [ 175 | "### Problem 3: MATLAB (and Octave) vs. Sage" 176 | ] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "metadata": { 181 | "collapsed": false 182 | }, 183 | "source": [ 184 | "Grading criterion: correctness of code." 185 | ] 186 | }, 187 | { 188 | "cell_type": "markdown", 189 | "metadata": { 190 | "collapsed": false 191 | }, 192 | "source": [ 193 | "This exercise refers to the [Math 18 MATLAB exercise set](http://www.math.ucsd.edu/~math18/)." 194 | ] 195 | }, 196 | { 197 | "cell_type": "markdown", 198 | "metadata": { 199 | "collapsed": false 200 | }, 201 | "source": [ 202 | "3a. Do MATLAB exercise 4.5 twice: once using Octave, and a second time using Sage. (For this problem, you will need to switch the kernel between Octave and SageMath.)" 203 | ] 204 | }, 205 | { 206 | "cell_type": "raw", 207 | "metadata": { 208 | "collapsed": false 209 | }, 210 | "source": [ 211 | "your Octave answer goes here" 212 | ] 213 | }, 214 | { 215 | "cell_type": "raw", 216 | "metadata": { 217 | "collapsed": false 218 | }, 219 | "source": [ 220 | "your SageMath answer goes here" 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "metadata": { 226 | "collapsed": false 227 | }, 228 | "source": [ 229 | "3b. Repeat with MATLAB exercise 5.6, using `numpy` to obtain the analogue of MATLAB's least squares functionality." 230 | ] 231 | }, 232 | { 233 | "cell_type": "raw", 234 | "metadata": { 235 | "collapsed": false 236 | }, 237 | "source": [ 238 | "your Octave answer goes here" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": 0, 244 | "metadata": { 245 | "collapsed": false 246 | }, 247 | "outputs": [ 248 | ], 249 | "source": [ 250 | "your SageMath answer goes here" 251 | ] 252 | }, 253 | { 254 | "cell_type": "markdown", 255 | "metadata": { 256 | "collapsed": false 257 | }, 258 | "source": [ 259 | "### Problem 4: Eigenvectors and eigenvalues" 260 | ] 261 | }, 262 | { 263 | "cell_type": "markdown", 264 | "metadata": { 265 | "collapsed": false 266 | }, 267 | "source": [ 268 | "Grading criteria: correctness of code and explanations." 269 | ] 270 | }, 271 | { 272 | "cell_type": "markdown", 273 | "metadata": { 274 | "collapsed": false 275 | }, 276 | "source": [ 277 | "Let $M$ be the following matrix with rational entries:\n", 278 | "$$\n", 279 | "M = \\left(\\begin{array}{rrrr}\n", 280 | "\\frac{1}{2} & 0 & -1 & 0 \\\\\n", 281 | "1 & \\frac{1}{2} & 1 & 1 \\\\\n", 282 | "0 & 1 & -1 & -1 \\\\\n", 283 | "2 & 1 & -2 & 1\n", 284 | "\\end{array}\\right)\n", 285 | "$$" 286 | ] 287 | }, 288 | { 289 | "cell_type": "markdown", 290 | "metadata": { 291 | "collapsed": false 292 | }, 293 | "source": [ 294 | "4a. State the Cayley-Hamilton theorem, then use Sage to verify that it holds for $M$." 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": 0, 300 | "metadata": { 301 | "collapsed": false 302 | }, 303 | "outputs": [ 304 | ], 305 | "source": [ 306 | ] 307 | }, 308 | { 309 | "cell_type": "markdown", 310 | "metadata": { 311 | "collapsed": false 312 | }, 313 | "source": [ 314 | "4b. Compute the eigenvalues and eigenvectors of $M$, and verify (using numerical approximations) that each eigenvector is indeed an eigenvector with the specified eigenvalue." 315 | ] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": 0, 320 | "metadata": { 321 | "collapsed": false 322 | }, 323 | "outputs": [ 324 | ], 325 | "source": [ 326 | ] 327 | }, 328 | { 329 | "cell_type": "markdown", 330 | "metadata": { 331 | "collapsed": false 332 | }, 333 | "source": [ 334 | "4c. State the relationship between the characteristic polynomial, the determinant, and the eigenvalues of a matrix; then verify numerically that this holds for $M$." 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 0, 340 | "metadata": { 341 | "collapsed": false 342 | }, 343 | "outputs": [ 344 | ], 345 | "source": [ 346 | ] 347 | }, 348 | { 349 | "cell_type": "code", 350 | "execution_count": 0, 351 | "metadata": { 352 | "collapsed": false 353 | }, 354 | "outputs": [ 355 | ], 356 | "source": [ 357 | ] 358 | }, 359 | { 360 | "cell_type": "markdown", 361 | "metadata": { 362 | "collapsed": false 363 | }, 364 | "source": [ 365 | "### Problem 5: Hilbert matrices and numerical stability" 366 | ] 367 | }, 368 | { 369 | "cell_type": "markdown", 370 | "metadata": { 371 | "collapsed": false 372 | }, 373 | "source": [ 374 | "Grading criterion: correctness of code and thoroughness of explanation." 375 | ] 376 | }, 377 | { 378 | "cell_type": "markdown", 379 | "metadata": { 380 | "collapsed": false 381 | }, 382 | "source": [ 383 | "5a. Define a Python function `f`, which on the input of a positive integer $n$, returns the $n \\times n$ Sage matrix over the rational numbers \n", 384 | "$$\n", 385 | "H_{ij} = \\frac{1}{i+j-1} \\qquad (i,j=1,\\dots,n).\n", 386 | "$$\n", 387 | "See below for a sample output.\n", 388 | "Hint: remember that Sage, like Python, starts indexing with 0 instead of 1." 389 | ] 390 | }, 391 | { 392 | "cell_type": "code", 393 | "execution_count": 29, 394 | "metadata": { 395 | "collapsed": false 396 | }, 397 | "outputs": [ 398 | { 399 | "ename": "IndentationError", 400 | "evalue": "expected an indented block (, line 2)", 401 | "output_type": "error", 402 | "traceback": [ 403 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m # your code goes here\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block\n" 404 | ] 405 | } 406 | ], 407 | "source": [ 408 | "def f(n):\n", 409 | " # your code goes here" 410 | ] 411 | }, 412 | { 413 | "cell_type": "raw", 414 | "metadata": { 415 | "collapsed": false 416 | }, 417 | "source": [ 418 | "## Sample output of f(3):\n", 419 | "[ 1 1/2 1/3]\n", 420 | "[1/2 1/3 1/4]\n", 421 | "[1/3 1/4 1/5]" 422 | ] 423 | }, 424 | { 425 | "cell_type": "markdown", 426 | "metadata": { 427 | "collapsed": false 428 | }, 429 | "source": [ 430 | "5b. Write Sage code to compute the inverse of `f(25)`, print out the top left entry (not the whole matrix), and verify that the whole answer agrees with the [formula in Wikipedia](https://en.wikipedia.org/wiki/Hilbert_matrix)." 431 | ] 432 | }, 433 | { 434 | "cell_type": "code", 435 | "execution_count": 0, 436 | "metadata": { 437 | "collapsed": false 438 | }, 439 | "outputs": [ 440 | ], 441 | "source": [ 442 | ] 443 | }, 444 | { 445 | "cell_type": "markdown", 446 | "metadata": { 447 | "collapsed": false 448 | }, 449 | "source": [ 450 | "5c. Use the `change_ring` method to redo the computation of the inverse of `f(25)` over the ring `RR` (i.e., using floating-point real numbers with double precision == 53 bits), agian printing out the top left entry." 451 | ] 452 | }, 453 | { 454 | "cell_type": "code", 455 | "execution_count": 0, 456 | "metadata": { 457 | "collapsed": false 458 | }, 459 | "outputs": [ 460 | ], 461 | "source": [ 462 | ] 463 | }, 464 | { 465 | "cell_type": "markdown", 466 | "metadata": { 467 | "collapsed": false 468 | }, 469 | "source": [ 470 | "5d. In as much detail as you can, explain what you have just observed. You may want to compute the determinant of `f(25)` and/or read about [numerical stability](https://en.wikipedia.org/wiki/Numerical_stability)." 471 | ] 472 | }, 473 | { 474 | "cell_type": "code", 475 | "execution_count": 0, 476 | "metadata": { 477 | "collapsed": false 478 | }, 479 | "outputs": [ 480 | ], 481 | "source": [ 482 | ] 483 | }, 484 | { 485 | "cell_type": "markdown", 486 | "metadata": { 487 | "collapsed": false 488 | }, 489 | "source": [ 490 | "### Problem 6: Linear algebra over Q" 491 | ] 492 | }, 493 | { 494 | "cell_type": "markdown", 495 | "metadata": { 496 | "collapsed": false 497 | }, 498 | "source": [ 499 | "Grading criteria: correctness of code and thoroughness of explanation." 500 | ] 501 | }, 502 | { 503 | "cell_type": "markdown", 504 | "metadata": { 505 | "collapsed": false 506 | }, 507 | "source": [ 508 | "6a. Explain in detail what the following code does and how it is being done. Assume that the input `M` is a matrix with entries in `QQ`." 509 | ] 510 | }, 511 | { 512 | "cell_type": "code", 513 | "execution_count": 0, 514 | "metadata": { 515 | "collapsed": false 516 | }, 517 | "outputs": [ 518 | ], 519 | "source": [ 520 | "def f(M):\n", 521 | " M = copy(M) # replace M with a copy to avoid clobbering the original\n", 522 | " n = M.dimensions()[0]\n", 523 | " if n != M.dimensions()[1]: raise ValueError\n", 524 | " for i in range(n):\n", 525 | " j = i\n", 526 | " while j \"We performed a large-scale study of RSA and DSA cryptographic keys in use on the Internet and discovered that significant numbers of keys are insecure due to insufficient randomness. **We found that 5.57% of TLS hosts and 9.60% of SSH hosts share public keys in an apparently vulnerable manner...**\" -- see https://factorable.net/\n" 397 | ] 398 | }, 399 | { 400 | "cell_type": "code", 401 | "execution_count": 0, 402 | "metadata": { 403 | "collapsed": false 404 | }, 405 | "outputs": [ 406 | ], 407 | "source": [ 408 | ] 409 | }, 410 | { 411 | "cell_type": "markdown", 412 | "metadata": { 413 | "collapsed": false 414 | }, 415 | "source": [ 416 | "4b. Use this backdoor to factor the numbers $a$ and $b$ defined below." 417 | ] 418 | }, 419 | { 420 | "cell_type": "markdown", 421 | "metadata": { 422 | "collapsed": false 423 | }, 424 | "source": [ 425 | "a = 659481018095533082202091938200108415755014729057676791347712890248315591033900561408617722880031918351642894659648847446299804878752991957454382452262126117247899544055830787469355702640917\n", 426 | "\n", 427 | "b = 223986669883088680371243199849357901244618017803455583407479556994195127176620839487674896299802613306139834600384565144314609009904613010988914195091967322701239166323910725912324556645705719757" 428 | ] 429 | }, 430 | { 431 | "cell_type": "code", 432 | "execution_count": 0, 433 | "metadata": { 434 | "collapsed": false 435 | }, 436 | "outputs": [ 437 | ], 438 | "source": [ 439 | ] 440 | }, 441 | { 442 | "cell_type": "markdown", 443 | "metadata": { 444 | "collapsed": false 445 | }, 446 | "source": [ 447 | "4c. Compare the size of $a$ and $b$ to the current state of the RSA Factoring Challenge. Would it have been feasible to factor them without the backdoor?" 448 | ] 449 | }, 450 | { 451 | "cell_type": "code", 452 | "execution_count": 0, 453 | "metadata": { 454 | "collapsed": false 455 | }, 456 | "outputs": [ 457 | ], 458 | "source": [ 459 | ] 460 | }, 461 | { 462 | "cell_type": "markdown", 463 | "metadata": { 464 | "collapsed": false 465 | }, 466 | "source": [ 467 | "### Problem 5: Primitive roots" 468 | ] 469 | }, 470 | { 471 | "cell_type": "markdown", 472 | "metadata": { 473 | "collapsed": false 474 | }, 475 | "source": [ 476 | "Grading criteria: correctness of code and explanations." 477 | ] 478 | }, 479 | { 480 | "cell_type": "markdown", 481 | "metadata": { 482 | "collapsed": false 483 | }, 484 | "source": [ 485 | "5a. Look up, then formulate in your own words, the statement of Artin's conjecture on primitive roots." 486 | ] 487 | }, 488 | { 489 | "cell_type": "code", 490 | "execution_count": 0, 491 | "metadata": { 492 | "collapsed": false 493 | }, 494 | "outputs": [ 495 | ], 496 | "source": [ 497 | ] 498 | }, 499 | { 500 | "cell_type": "markdown", 501 | "metadata": { 502 | "collapsed": false 503 | }, 504 | "source": [ 505 | "5b. Compute, to at least five decimal places, the prediction made by Artin's conjecture for the probability that 2 is a primitive root modulo a random prime $p$." 506 | ] 507 | }, 508 | { 509 | "cell_type": "code", 510 | "execution_count": 0, 511 | "metadata": { 512 | "collapsed": false 513 | }, 514 | "outputs": [ 515 | ], 516 | "source": [ 517 | ] 518 | }, 519 | { 520 | "cell_type": "markdown", 521 | "metadata": { 522 | "collapsed": false 523 | }, 524 | "source": [ 525 | "5c. Write a function that, given an input $n$, computes the probability that 2 is a primitive root modulo a random prime less than $n$." 526 | ] 527 | }, 528 | { 529 | "cell_type": "code", 530 | "execution_count": 0, 531 | "metadata": { 532 | "collapsed": false 533 | }, 534 | "outputs": [ 535 | ], 536 | "source": [ 537 | ] 538 | }, 539 | { 540 | "cell_type": "markdown", 541 | "metadata": { 542 | "collapsed": false 543 | }, 544 | "source": [ 545 | "5d. Make a plot of your answer to 5c for $n$ up to at least $10^6$, with at least 10 sample points (of your choice). Use a logarithmic scale on the $x$-axis." 546 | ] 547 | }, 548 | { 549 | "cell_type": "code", 550 | "execution_count": 0, 551 | "metadata": { 552 | "collapsed": false 553 | }, 554 | "outputs": [ 555 | ], 556 | "source": [ 557 | ] 558 | }, 559 | { 560 | "cell_type": "code", 561 | "execution_count": 0, 562 | "metadata": { 563 | "collapsed": false 564 | }, 565 | "outputs": [ 566 | ], 567 | "source": [ 568 | ] 569 | }, 570 | { 571 | "cell_type": "markdown", 572 | "metadata": { 573 | "collapsed": false 574 | }, 575 | "source": [ 576 | "### Problem 6: Graphs and number theory" 577 | ] 578 | }, 579 | { 580 | "cell_type": "markdown", 581 | "metadata": { 582 | "collapsed": false 583 | }, 584 | "source": [ 585 | "Grading criteria: correctness of code." 586 | ] 587 | }, 588 | { 589 | "cell_type": "markdown", 590 | "metadata": { 591 | "collapsed": false 592 | }, 593 | "source": [ 594 | "6a. Read the definition of a [Paley graph](https://en.wikipedia.org/wiki/Paley_graph), then write a function that, given a prime $p$ congruent to 1 modulo 4, constructs the Paley graph associated to that prime. (There also exist Paley graphs associated to prime powers, but your function need not construct those.)" 595 | ] 596 | }, 597 | { 598 | "cell_type": "code", 599 | "execution_count": 0, 600 | "metadata": { 601 | "collapsed": false 602 | }, 603 | "outputs": [ 604 | ], 605 | "source": [ 606 | ] 607 | }, 608 | { 609 | "cell_type": "markdown", 610 | "metadata": { 611 | "collapsed": false 612 | }, 613 | "source": [ 614 | "6b. Using your answer to 6a for $p=13$ and the [Paley construction](https://en.wikipedia.org/wiki/Paley_construction), construct (but do not print) a $28 \\times 28$ matrix which achieves the [Hadamard determinant bound](https://en.wikipedia.org/wiki/Hadamard%27s_inequality)." 615 | ] 616 | }, 617 | { 618 | "cell_type": "code", 619 | "execution_count": 0, 620 | "metadata": { 621 | "collapsed": false 622 | }, 623 | "outputs": [ 624 | ], 625 | "source": [ 626 | ] 627 | }, 628 | { 629 | "cell_type": "markdown", 630 | "metadata": { 631 | "collapsed": false 632 | }, 633 | "source": [ 634 | "6c. Check that your answer to 6b actually does achieve the Hadamard bound." 635 | ] 636 | }, 637 | { 638 | "cell_type": "code", 639 | "execution_count": 0, 640 | "metadata": { 641 | "collapsed": false 642 | }, 643 | "outputs": [ 644 | ], 645 | "source": [ 646 | ] 647 | } 648 | ], 649 | "metadata": { 650 | "kernelspec": { 651 | "display_name": "SageMath 8.1", 652 | "name": "sage-8.1" 653 | }, 654 | "language_info": { 655 | "codemirror_mode": { 656 | "name": "ipython", 657 | "version": 2 658 | }, 659 | "file_extension": ".py", 660 | "mimetype": "text/x-python", 661 | "name": "python", 662 | "nbconvert_exporter": "python", 663 | "pygments_lexer": "ipython2", 664 | "version": "2.7.14" 665 | } 666 | }, 667 | "nbformat": 4, 668 | "nbformat_minor": 0 669 | } -------------------------------------------------------------------------------- /assignments/2018-02-16/DUE_DATE.txt: -------------------------------------------------------------------------------- 1 | This assignment is due 2 | 3 | 2/16/2018, 8:00:00 PM -------------------------------------------------------------------------------- /assignments/2018-02-16/state_capitals.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kedlaya/math157/87f1d087b42b333d7835a8a5b9a3ab8419962c5d/assignments/2018-02-16/state_capitals.xlsx -------------------------------------------------------------------------------- /assignments/2018-02-23/2018-02-23.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "## Math 157: Intro to Mathematical Software\n", 10 | "## UC San Diego, winter 2018" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "collapsed": false 17 | }, 18 | "source": [ 19 | "## Homework 6: due February 23, 2018" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": { 25 | "collapsed": false 26 | }, 27 | "source": [ 28 | "Please enter all answers within this notebook unless otherwise specified. As usual, don't forget to cite sources and collaborators.\n", 29 | "\n", 30 | "Through this problem set, use the SageMath 8.1 kernel except as specified.\n", 31 | "\n", 32 | "This homework consists of 5 problems, each of equal value." 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": { 38 | "collapsed": false 39 | }, 40 | "source": [ 41 | "### Problem 1: The birthday paradox (and comedy)" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": { 47 | "collapsed": false 48 | }, 49 | "source": [ 50 | "Grading criteria: correctness of code and thoroughness of explanations." 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": { 56 | "collapsed": false 57 | }, 58 | "source": [ 59 | "1a. A well-known statement of mathematical folklore asserts that if you choose $N$ people at random, then the probability that two of them have the same birthday exceeds 50% as soon as $N \\geq 23$. This is sometimes called the *birthday paradox* not because of any logical inconsistency, but simply because people find this counterintuitive; a more accepted terminology is the [*birthday problem*](https://en.wikipedia.org/wiki/Birthday_problem).\n", 60 | "\n", 61 | "Write a function that, given $N$, computes this probability. For simplicity, you may assume that every year consists of 365 days (i.e., ignore leap years) and that birthdays are distributed uniformly at random." 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 0, 67 | "metadata": { 68 | "collapsed": false 69 | }, 70 | "outputs": [ 71 | ], 72 | "source": [ 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": { 78 | "collapsed": false 79 | }, 80 | "source": [ 81 | "1b. Verify numerically that the probability exceeds 0.5 if and only if $N \\geq 23$." 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 0, 87 | "metadata": { 88 | "collapsed": false 89 | }, 90 | "outputs": [ 91 | ], 92 | "source": [ 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": { 98 | "collapsed": false 99 | }, 100 | "source": [ 101 | "1c. If a year were to consist of $M$ days, how would the crossover value depend (asympotically) on $M$? Why?" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 0, 107 | "metadata": { 108 | "collapsed": false 109 | }, 110 | "outputs": [ 111 | ], 112 | "source": [ 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": { 118 | "collapsed": false 119 | }, 120 | "source": [ 121 | "1d. Explain, in your own words, what the following three things have in common.\n", 122 | "- The birthday problem.\n", 123 | "- The baby-step-giant-step attack on discrete logarithms.\n", 124 | "- The [mathematical theory of late-night comedy](https://youtu.be/_ODsLIMSBq0) reported by Slate last week. (Not a joke!)" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 0, 130 | "metadata": { 131 | "collapsed": false 132 | }, 133 | "outputs": [ 134 | ], 135 | "source": [ 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "metadata": { 141 | "collapsed": false 142 | }, 143 | "source": [ 144 | "### Problem 2: Chinks in the armor" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": { 150 | "collapsed": false 151 | }, 152 | "source": [ 153 | "Grading criteria: correctness of code and mathematical reasoning." 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": { 159 | "collapsed": false 160 | }, 161 | "source": [ 162 | "2a. There exist two primes $p$ and $q$ such that $N = pq$ and $\\varphi(N)$ have the following values. Find $p$ and $q$." 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 0, 168 | "metadata": { 169 | "collapsed": false 170 | }, 171 | "outputs": [ 172 | ], 173 | "source": [ 174 | "N = 46708822349259203361344297606349795508624596894610331963475250447878049614343188469958138667702672064437158794030506161936018920993393470466541259138024527655091597122885936534640983967743981020417066596244043571854706943422478922714341547167502363866097396753119154853150662020146962118536726679429506821989\n", 175 | "ph = 46708822349259203361344297606349795508624596894610331963475250447878049614343188469958138667702672064437158794030506161936018920993393470466541259138024513978876893776281066371789960571608641635171633767722385559809330963145405657507385159096521621672648416769760458924356578637127097073558518163200222200556\n" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 0, 181 | "metadata": { 182 | "collapsed": false 183 | }, 184 | "outputs": [ 185 | ], 186 | "source": [ 187 | ] 188 | }, 189 | { 190 | "cell_type": "markdown", 191 | "metadata": { 192 | "collapsed": false 193 | }, 194 | "source": [ 195 | "2b. The following integer $N$ is a product of two primes of roughly equal size (which are known to me but secret to you). The integer $t$ given below has the property that $M^3 \\equiv t \\pmod{N}$ for some positive integer $M$ not greater than $10^{105}$. Find $M$." 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": 0, 201 | "metadata": { 202 | "collapsed": false 203 | }, 204 | "outputs": [ 205 | ], 206 | "source": [ 207 | "N = 76423640358847412652374294300302041459529359752680987485518411448531451335119684258103920661719583680308606457161396261605016691913851993440982486450916973319097247600145790676526404213081447781619033665382062984788563242010572490285667221071318294609426838188283710453878988160806557791285882029204772981529\n", 208 | "t = 11807826974296406142491583468052817190645455044270507694732514014928570915157636104659010509935579145791187971616680786969637105700382114579562649014536639676091007952025381665220916825703280184232877376453652231909120222974982306195030361794694545267682687918232040294524659748461552986872564797138673247308\n" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 0, 214 | "metadata": { 215 | "collapsed": false 216 | }, 217 | "outputs": [ 218 | ], 219 | "source": [ 220 | ] 221 | }, 222 | { 223 | "cell_type": "markdown", 224 | "metadata": { 225 | "collapsed": false 226 | }, 227 | "source": [ 228 | "### Problem 3: Elliptic curve Diffie-Hellman" 229 | ] 230 | }, 231 | { 232 | "cell_type": "markdown", 233 | "metadata": { 234 | "collapsed": false 235 | }, 236 | "source": [ 237 | "Grading criteria: correctness of code." 238 | ] 239 | }, 240 | { 241 | "cell_type": "markdown", 242 | "metadata": { 243 | "collapsed": false 244 | }, 245 | "source": [ 246 | "3a. The following code defines an elliptic curve (whatever that is!) over $\\mathbb{F}_p$ for a certain prime $p$. This has the structure of an abelian group; compute the order of this group." 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": 14, 252 | "metadata": { 253 | "collapsed": false 254 | }, 255 | "outputs": [ 256 | ], 257 | "source": [ 258 | "p = 6501010882155498913\n", 259 | "E = EllipticCurve(GF(p), [0,1,0,1,-1])" 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 0, 265 | "metadata": { 266 | "collapsed": false 267 | }, 268 | "outputs": [ 269 | ], 270 | "source": [ 271 | ] 272 | }, 273 | { 274 | "cell_type": "markdown", 275 | "metadata": { 276 | "collapsed": false 277 | }, 278 | "source": [ 279 | "3b. Check that the following element is a generator." 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 15, 285 | "metadata": { 286 | "collapsed": false 287 | }, 288 | "outputs": [ 289 | ], 290 | "source": [ 291 | "g = E(4808979935694435458, 2167227988161099418)" 292 | ] 293 | }, 294 | { 295 | "cell_type": "code", 296 | "execution_count": 0, 297 | "metadata": { 298 | "collapsed": false 299 | }, 300 | "outputs": [ 301 | ], 302 | "source": [ 303 | ] 304 | }, 305 | { 306 | "cell_type": "markdown", 307 | "metadata": { 308 | "collapsed": false 309 | }, 310 | "source": [ 311 | "3c. Using $E$ and $g$, perform the analogue of a Diffie-Hellman key exchange. Hint: the analogue of modular multiplication is denoted by addition, and the analogue of exponentiation `g^n` is denoted `n*g`." 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": 0, 317 | "metadata": { 318 | "collapsed": false 319 | }, 320 | "outputs": [ 321 | ], 322 | "source": [ 323 | "g+g+g, 3*g" 324 | ] 325 | }, 326 | { 327 | "cell_type": "code", 328 | "execution_count": 0, 329 | "metadata": { 330 | "collapsed": false 331 | }, 332 | "outputs": [ 333 | ], 334 | "source": [ 335 | "# Your code goes here\n", 336 | "a = randint(0, p-1) # Alice's secret\n", 337 | "b = randint(0, p-1) # Bob's secret\n", 338 | "# ..." 339 | ] 340 | }, 341 | { 342 | "cell_type": "markdown", 343 | "metadata": { 344 | "collapsed": false 345 | }, 346 | "source": [ 347 | "Replacement values:" 348 | ] 349 | }, 350 | { 351 | "cell_type": "code", 352 | "execution_count": 9, 353 | "metadata": { 354 | "collapsed": false 355 | }, 356 | "outputs": [ 357 | { 358 | "name": "stdout", 359 | "output_type": "stream", 360 | "text": [ 361 | "\n" 362 | ] 363 | } 364 | ], 365 | "source": [ 366 | "p = 2430985831\n", 367 | "E = EllipticCurve(GF(p), [0,1,0,1,-1])\n", 368 | "g = E(1142679369, 725589986)" 369 | ] 370 | }, 371 | { 372 | "cell_type": "markdown", 373 | "metadata": { 374 | "collapsed": false 375 | }, 376 | "source": [ 377 | "### Problem 4: Attacking elliptic curve Diffie-Hellman" 378 | ] 379 | }, 380 | { 381 | "cell_type": "markdown", 382 | "metadata": { 383 | "collapsed": false 384 | }, 385 | "source": [ 386 | "Grading criteria: correctness of code." 387 | ] 388 | }, 389 | { 390 | "cell_type": "markdown", 391 | "metadata": { 392 | "collapsed": false 393 | }, 394 | "source": [ 395 | "Throughout this problem, use the same elliptic curve and generator as in problem 3." 396 | ] 397 | }, 398 | { 399 | "cell_type": "markdown", 400 | "metadata": { 401 | "collapsed": false 402 | }, 403 | "source": [ 404 | "4a. Take the code given in lecture for the baby-step-giant-step method for computing discrete logarithms, and adapt it to this elliptic curve." 405 | ] 406 | }, 407 | { 408 | "cell_type": "code", 409 | "execution_count": 0, 410 | "metadata": { 411 | "collapsed": false 412 | }, 413 | "outputs": [ 414 | ], 415 | "source": [ 416 | "def elliptic_bsgs(h):\n", 417 | " # your code goes here" 418 | ] 419 | }, 420 | { 421 | "cell_type": "markdown", 422 | "metadata": { 423 | "collapsed": false 424 | }, 425 | "source": [ 426 | "4b. Take the code given in lecture for the Chinese Remainder Theorem method for computing discrete logarithms, and adapt it to this elliptic curve. (Hint: first factor the order of $E$.)" 427 | ] 428 | }, 429 | { 430 | "cell_type": "code", 431 | "execution_count": 0, 432 | "metadata": { 433 | "collapsed": false 434 | }, 435 | "outputs": [ 436 | ], 437 | "source": [ 438 | "def elliptic_crt(h):\n", 439 | " # your code goes here" 440 | ] 441 | }, 442 | { 443 | "cell_type": "markdown", 444 | "metadata": { 445 | "collapsed": false 446 | }, 447 | "source": [ 448 | "4c. Test your solutions to 4a and 4b using the following code." 449 | ] 450 | }, 451 | { 452 | "cell_type": "code", 453 | "execution_count": 0, 454 | "metadata": { 455 | "collapsed": false 456 | }, 457 | "outputs": [ 458 | ], 459 | "source": [ 460 | "m = randint(0, p-1)\n", 461 | "h = m*g\n", 462 | "print(m)\n", 463 | "print(g.discrete_log(h))\n", 464 | "print(elliptic_bsgs(h))\n", 465 | "print(elliptic_crt(h))" 466 | ] 467 | }, 468 | { 469 | "cell_type": "code", 470 | "execution_count": 0, 471 | "metadata": { 472 | "collapsed": false 473 | }, 474 | "outputs": [ 475 | ], 476 | "source": [ 477 | ] 478 | }, 479 | { 480 | "cell_type": "markdown", 481 | "metadata": { 482 | "collapsed": false 483 | }, 484 | "source": [ 485 | "### Problem 5: A preview of R" 486 | ] 487 | }, 488 | { 489 | "cell_type": "markdown", 490 | "metadata": { 491 | "collapsed": false 492 | }, 493 | "source": [ 494 | "Grading criteria: correctness and thoroughness of explanations." 495 | ] 496 | }, 497 | { 498 | "cell_type": "markdown", 499 | "metadata": { 500 | "collapsed": false 501 | }, 502 | "source": [ 503 | "For the following exercise, switch your kernel to \"R (R-Project)\"." 504 | ] 505 | }, 506 | { 507 | "cell_type": "markdown", 508 | "metadata": { 509 | "collapsed": false 510 | }, 511 | "source": [ 512 | "In each of the following cells, run the R commands as indicated, then explain in words:\n", 513 | " - what is the data being analyzed;\n", 514 | " - what the code is doing;\n", 515 | " - one conclusion you drew from the data.\n", 516 | " \n", 517 | "You might want to consult the [documentation for the R datasets package](https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/00Index.html), from which these examples were taken." 518 | ] 519 | }, 520 | { 521 | "cell_type": "code", 522 | "execution_count": 0, 523 | "metadata": { 524 | "collapsed": false 525 | }, 526 | "outputs": [ 527 | ], 528 | "source": [ 529 | "pairs(mtcars)" 530 | ] 531 | }, 532 | { 533 | "cell_type": "markdown", 534 | "metadata": { 535 | "collapsed": false 536 | }, 537 | "source": [ 538 | ] 539 | }, 540 | { 541 | "cell_type": "code", 542 | "execution_count": 0, 543 | "metadata": { 544 | "collapsed": false 545 | }, 546 | "outputs": [ 547 | ], 548 | "source": [ 549 | "require(stats); require(graphics)\n", 550 | "coplot(circumference ~ age | Tree, data = Orange, show.given = FALSE)" 551 | ] 552 | }, 553 | { 554 | "cell_type": "markdown", 555 | "metadata": { 556 | "collapsed": false 557 | }, 558 | "source": [ 559 | ] 560 | }, 561 | { 562 | "cell_type": "code", 563 | "execution_count": 0, 564 | "metadata": { 565 | "collapsed": false 566 | }, 567 | "outputs": [ 568 | ], 569 | "source": [ 570 | "x <- apply(HairEyeColor, c(1, 2), sum)\n", 571 | "x\n", 572 | "mosaicplot(x)" 573 | ] 574 | }, 575 | { 576 | "cell_type": "code", 577 | "execution_count": 0, 578 | "metadata": { 579 | "collapsed": false 580 | }, 581 | "outputs": [ 582 | ], 583 | "source": [ 584 | ] 585 | } 586 | ], 587 | "metadata": { 588 | "kernelspec": { 589 | "display_name": "SageMath 8.1", 590 | "name": "sage-8.1" 591 | }, 592 | "language_info": { 593 | "codemirror_mode": { 594 | "name": "ipython", 595 | "version": 2 596 | }, 597 | "file_extension": ".py", 598 | "mimetype": "text/x-python", 599 | "name": "python", 600 | "nbconvert_exporter": "python", 601 | "pygments_lexer": "ipython2", 602 | "version": "2.7.14" 603 | } 604 | }, 605 | "nbformat": 4, 606 | "nbformat_minor": 0 607 | } -------------------------------------------------------------------------------- /assignments/2018-02-23/DUE_DATE.txt: -------------------------------------------------------------------------------- 1 | This assignment is due 2 | 3 | 2/23/2018, 8:00:00 PM -------------------------------------------------------------------------------- /assignments/2018-03-02/DUE_DATE.txt: -------------------------------------------------------------------------------- 1 | This assignment is due 2 | 3 | 3/2/2018, 8:00:00 PM -------------------------------------------------------------------------------- /assignments/2018-03-09/DUE_DATE.txt: -------------------------------------------------------------------------------- 1 | This assignment is due 2 | 3 | 3/10/2018, 8:00:00 PM -------------------------------------------------------------------------------- /assignments/2018-03-16/2018-03-16-part2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 0, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | ], 11 | "source": [ 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 0, 17 | "metadata": { 18 | "collapsed": false 19 | }, 20 | "outputs": [ 21 | ], 22 | "source": [ 23 | "###### Math 157: Intro to Mathematical Software\n", 24 | "## UC San Diego, winter 2018" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "collapsed": false 31 | }, 32 | "source": [ 33 | "## Final project, part 2: due March 16, 2018" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": { 39 | "collapsed": false 40 | }, 41 | "source": [ 42 | "The final project consists of two parts, each of equal value. Both parts will be submitted in this folder, just like a homework assignment. However, the final project is *not* equivalent to a homework assignment from the point of view of course grading; it is a separate contribution, and cannot be dropped." 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": { 48 | "collapsed": false 49 | }, 50 | "source": [ 51 | "Part 2 is an open-ended assignment, in which you will be making a presentation to some of your fellow students on one of these topics:\n", 52 | " - Combinatorial designs in Sage (see `sage.combinat.designs`)\n", 53 | " - Fast Fourier transforms (see `scipy.fftpack`)\n", 54 | " - Linear feedback shift registers in Sage (see `sage.crypto`)\n", 55 | " - Permutation groups in Sage (see `sage.groups` and related functions)\n", 56 | " - Model selection for machine learning (see `sklearn.model_selection`)\n", 57 | " - Numerical solution of ODEs (see `scipy.integrate.ode`)\n", 58 | " \n", 59 | "Detailed instructions are given below. Note that you are not being asked to edit *this* notebook in any way; any material added to this notebook will not be counted for credit." 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": { 65 | "collapsed": false 66 | }, 67 | "source": [ 68 | "To complete the final project successfully, please follow these steps.\n", 69 | "- As soon as possible (preferably by Wednesday, February 28), fill out this [Google Form](https://docs.google.com/forms/d/e/1FAIpQLScw8RMWcCdWyzJK2xUgBNHoCgIkQcFmhw0_AYjZZu_j5KcKkg/viewform?usp=sf_link) indicating your first and second choices of topic.\n", 70 | " - My intention is for everyone to get their first choice; however, if too many people have the same first choice, I will announce this on Wednesday, February 28 and give you a chance to reconsider.\n", 71 | " - You will also be assigned randomly to a group of 3 or 4 in which all of you have chosen *different* topics (this being the reason why not too many people can choose the same topic). These groups will be announced (and the list made available in the shared project) by Monday, March 5. If I do not have your topic preferences at this point, you will be assigned both a group *and* a topic.\n", 72 | "- Prepare a Jupyter notebook called \"presentation-xxx.ipynb\" where xxx is your UCSD email address (without the `@ucsd.edu` part).\n", 73 | " - Your notebook should be in the style of a lecture of this course, but of half the length (20-30 minutes).\n", 74 | " - Your intended audience is a typical student in this course. In particular, do not assume any prerequisites beyond those required for this course.\n", 75 | " - You should cover material that has not already been presented in the course.\n", 76 | " - You should include an appropriate balance of expository text, examples, and references for further information.\n", 77 | " - You should include at least two sample exercises *with solutions* for a hypothetical problem set on this topic; these should appear at the end of your notebook.\n", 78 | " - As always, cite all sources and collaborators.\n", 79 | "- Meet with your assigned group and have each person make a presentation based on their notebook (excluding the exercises).\n", 80 | " - I don't expect you to have access to a video projector (though if you do, so much the better). Just have everyone crowd around your device as you go through your presentation.\n", 81 | " - Your group can choose any mutually agreeable time(s) for the presentations as long as you get them done in time to submit the project. However, there will be no lectures on Monday, March 12 or Wednesday, March 14, so you may find it convenient to use these times for this purpose.\n", 82 | " - You may wish to share your notebook with the students in your group. You can do this by transferring files through the shared project; creating a new project with your group members as the collaborators; or downloading and uploading files out of CoCalc.\n", 83 | " - It is permitted to revise your notebook after making your presentation; in this case, you will be asked to submit an extra file summarizing these changes.\n", 84 | " - Please make contact with your group no later than Friday, March 9. If you are unable to contact one of the members of your group, please let me know as soon as possible.\n", 85 | "- Submit, in this folder, the following files.\n", 86 | " - `presentation-xxx.ipynb`: your presentation notebook.\n", 87 | " - `changes-xxx.txt` (optional): a description of any changes you made to your presentation based on feedback from your group.\n", 88 | " - `feedback-xxx-yyy.txt`: for each other member of your group, your comments on their presentation. Here `yyy` is the other person's UCSD email address, again without `@ucsd.edu`. (So if your group consists of 4 people, you will submit 3 files of this type.)\n" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": { 94 | "collapsed": false 95 | }, 96 | "source": [ 97 | "Grading criteria:\n", 98 | " - Presentation (50%):\n", 99 | " - Completeness: Did you include enough material for 20-30 minutes? Is your material at a suitable depth?\n", 100 | " - Correctness: Do your examples work?\n", 101 | " - Exposition: Does your text actually explain what is going on?\n", 102 | " - Exercise set and solution key (30%):\n", 103 | " - Completeness: Did you include enough material for two exercises? Is your material at a suitable depth?\n", 104 | " - Correctness: Are your solutions correct?\n", 105 | " - Exposition: Do your problems serve to elucidate your chosen topic?\n", 106 | " - Feedback (20%):\n", 107 | " - Thoroughness: Did you provide comments on all of your assigned presentations?\n", 108 | " - Thoughtfulness: Were you paying attention? Are your comments germane?" 109 | ] 110 | } 111 | ], 112 | "metadata": { 113 | "kernelspec": { 114 | "display_name": "SageMath 8.1", 115 | "name": "sage-8.1" 116 | }, 117 | "language_info": { 118 | "codemirror_mode": { 119 | "name": "ipython", 120 | "version": 2 121 | }, 122 | "file_extension": ".py", 123 | "mimetype": "text/x-python", 124 | "name": "python", 125 | "nbconvert_exporter": "python", 126 | "pygments_lexer": "ipython2", 127 | "version": "2.7.14" 128 | } 129 | }, 130 | "nbformat": 4, 131 | "nbformat_minor": 0 132 | } -------------------------------------------------------------------------------- /assignments/2018-03-16/DUE_DATE.txt: -------------------------------------------------------------------------------- 1 | This assignment is due 2 | 3 | 3/16/2018, 8:00:00 PM -------------------------------------------------------------------------------- /best_practices.md: -------------------------------------------------------------------------------- 1 | Compiled by Kiran Kedlaya. 2 | Last modified April 2, 2018. 3 | 4 | Things to explain to TAs at the first meeting: 5 | - Demonstrate features of the course project. 6 | - Indicate the location of the chat room (or Piazza). 7 | - Create the duty roster ahead of time (with virtual office hours and solution keys) and explain its use at the TA meeting. 8 | 9 | 10 | Preparation of overall course materials: 11 | - Clarify at the outset what communication is and is not allowed by email. In particular, routine questions about upcoming homework should generally be restricted to office hours or virtual office hours. (However, questions about technical issues with the homework are fair game, although don't promise individual answers.) 12 | - If each unit will be running MWF, have the corresponding problem set due the following Monday or Tuesday. And try to schedule sections and office hours with this in mind. 13 | - Tip from William Stein: create a "menu bar" file with links to various useful items: 14 | - lectures folder 15 | - assignments folder 16 | - chat room (and/or Piazza) 17 | - announcements 18 | 19 | Preparation of lectures and assignments: 20 | - It is safer to not do any file preparation in a folder to be pushed out, as sometimes "zombie versions" of files will persist. 21 | - Before pushing any handout, use the "edit handout" button and: 22 | - remove all cell output; 23 | - remove any extra files; 24 | - make sure the kernel is set correctly (to the first one to be used); 25 | - for assignments, check that the due date is correctly set (this creates an extra file in the project). 26 | - Specifically for lectures: 27 | - Maybe push out both (beforehand) the "clean" lecture and (afterwards) the "annotated" version from the live class. 28 | - Specifically for assignments: 29 | - Write the problem sets first, then construct lectures around them. 30 | - Ask students to self-report (possibly with some small grading incentive): 31 | - sources and collaborators (as we were doing); 32 | - the time spent on the assignment. 33 | - Since the later problem sets are naturally harder, maybe for balance they should also be shorter. (Or maybe just have fewer of them.) 34 | - Students appreciate having the next homework available as soon as the previous one is collected. 35 | 36 | During lectures: 37 | - For redundancy, always bring two laptops to class, and their chargers. 38 | - For the first two weeks, it may be helpful to have a TA present during lecture to help with course administration functions (e.g., adding students who join the course late). 39 | - The text on the projector can *always* be larger. Also, use global account settings to choose a sensible color scheme for the editor (e.g., Monokai). 40 | 41 | Other: 42 | - Archive the chat room periodically. 43 | 44 | -------------------------------------------------------------------------------- /final_project_calculation/Math 157 final project - Sheet1.csv: -------------------------------------------------------------------------------- 1 | Timestamp,Your name (as shown in CoCalc),First choice of topic,Second choice of topic 2 | ,,, 3 | 2/26/2018 22:09:21,,Numerical solution of ODEs,Model selection for machine learning 4 | 2/27/2018 19:16:49,,Fourier transforms,Model selection for machine learning 5 | 2/28/2018 1:19:02,,Model selection for machine learning,Linear feedback shift registers 6 | 3/2/2018 14:36:09,,Numerical solution of ODEs,Numerical solution of ODEs 7 | ,,, 8 | 2/26/2018 22:19:05,,Fourier transforms,Combinatorial designs 9 | 2/26/2018 22:27:05,,Combinatorial designs,Permutation groups 10 | 2/26/2018 17:54:05,,Model selection for machine learning,Model selection for machine learning 11 | ,,, 12 | 2/26/2018 22:16:24,,Combinatorial designs,Model selection for machine learning 13 | 2/28/2018 13:14:05,,Permutation groups,Numerical solution of ODEs 14 | 2/27/2018 15:58:05,,Numerical solution of ODEs,Permutation groups 15 | 3/2/2018 14:04:46,,Numerical solution of ODEs,Linear feedback shift registers 16 | 2/27/2018 0:43:47,,Model selection for machine learning,Numerical solution of ODEs 17 | 2/28/2018 13:54:52,,Model selection for machine learning,Combinatorial designs 18 | 3/2/2018 13:59:34,,Model selection for machine learning,Fourier transforms 19 | 2/26/2018 22:12:08,,Combinatorial designs,Permutation groups 20 | 2/28/2018 14:33:09,,Model selection for machine learning,Combinatorial designs 21 | 2/26/2018 4:38:53,,Numerical solution of ODEs,Model selection for machine learning 22 | ,,, 23 | 2/28/2018 14:06:51,,Numerical solution of ODEs,Combinatorial designs 24 | 2/26/2018 22:33:31,,Permutation groups,Numerical solution of ODEs 25 | ,,, 26 | 2/26/2018 22:27:15,,Model selection for machine learning,Permutation groups 27 | 2/27/2018 0:05:42,,Numerical solution of ODEs,Model selection for machine learning 28 | 2/26/2018 5:12:25,,Permutation groups,Fourier transforms 29 | 2/26/2018 5:49:45,,Model selection for machine learning,Linear feedback shift registers 30 | 2/28/2018 14:04:52,,Numerical solution of ODEs,Fourier transforms 31 | 2/28/2018 14:05:19,,Fourier transforms,Combinatorial designs 32 | 2/28/2018 22:00:01,,Numerical solution of ODEs,Fourier transforms 33 | 2/28/2018 13:50:49,,Permutation groups,Combinatorial designs 34 | 2/28/2018 0:20:44,,Model selection for machine learning,Fourier transforms 35 | 2/28/2018 1:05:42,,Combinatorial designs,Permutation groups 36 | 3/1/2018 0:57:09,,Permutation groups,Combinatorial designs 37 | 2/28/2018 14:17:23,,Model selection for machine learning,Fourier transforms 38 | 2/26/2018 22:14:42,,Permutation groups,Fourier transforms 39 | 2/26/2018 22:11:09,,Model selection for machine learning,Combinatorial designs 40 | 2/27/2018 20:36:35,,Numerical solution of ODEs,Fourier transforms 41 | 2/26/2018 22:23:38,,Combinatorial designs,Numerical solution of ODEs 42 | 2/28/2018 13:15:13,,Numerical solution of ODEs,Combinatorial designs 43 | 2/26/2018 22:46:27,,Fourier transforms,Combinatorial designs 44 | 2/27/2018 19:20:11,,Combinatorial designs,Permutation groups 45 | 2/28/2018 14:39:47,,Model selection for machine learning,Combinatorial designs 46 | 2/26/2018 19:25:58,,Combinatorial designs,Permutation groups 47 | 2/28/2018 12:43:00,,Numerical solution of ODEs,Linear feedback shift registers 48 | 2/28/2018 22:49:05,,Model selection for machine learning,Numerical solution of ODEs 49 | ,,, 50 | 2/27/2018 0:14:29,,Permutation groups,Combinatorial designs 51 | 2/28/2018 17:32:32,,Permutation groups,Model selection for machine learning 52 | 2/26/2018 22:08:36,,Permutation groups,Combinatorial designs 53 | 2/26/2018 22:06:04,,Combinatorial designs,Permutation groups 54 | 2/26/2018 22:52:54,,Model selection for machine learning,Model selection for machine learning 55 | 2/26/2018 22:07:32,,Model selection for machine learning,Combinatorial designs 56 | 3/2/2018 21:16:35,,Permutation groups,Combinatorial designs 57 | 3/1/2018 17:11:32,,Numerical solution of ODEs,Model selection for machine learning 58 | 3/2/2018 2:11:42,,Permutation groups,Permutation groups 59 | 2/28/2018 23:32:18,,Model selection for machine learning,Combinatorial designs 60 | 3/2/2018 16:38:47,,Permutation groups,Combinatorial designs 61 | 2/28/2018 13:55:45,,Model selection for machine learning,Combinatorial designs 62 | 2/26/2018 22:15:19,,Linear feedback shift registers,Combinatorial designs 63 | 2/26/2018 22:13:53,,Model selection for machine learning,Permutation groups 64 | 2/28/2018 22:55:46,,Numerical solution of ODEs,Combinatorial designs 65 | 2/26/2018 22:09:23,,Numerical solution of ODEs,Model selection for machine learning 66 | 2/28/2018 10:25:12,,Model selection for machine learning,Numerical solution of ODEs 67 | 2/27/2018 17:31:55,,Permutation groups,Combinatorial designs 68 | ,,, 69 | 2/28/2018 23:51:07,,Fourier transforms,Numerical solution of ODEs 70 | 2/27/2018 12:16:14,,Permutation groups,Combinatorial designs 71 | 2/26/2018 22:04:19,,Linear feedback shift registers,Numerical solution of ODEs 72 | ,,, 73 | ,,, 74 | 2/26/2018 21:59:50,,Permutation groups,Numerical solution of ODEs 75 | 2/26/2018 22:16:45,,Fourier transforms,Model selection for machine learning 76 | 2/26/2018 19:33:16,,Model selection for machine learning,Numerical solution of ODEs 77 | 2/26/2018 20:22:22,,Numerical solution of ODEs,Model selection for machine learning 78 | 2/26/2018 22:17:49,,Fourier transforms,Model selection for machine learning 79 | 2/27/2018 8:24:59,,Model selection for machine learning,Fourier transforms 80 | ,,, 81 | 2/26/2018 22:18:20,,Combinatorial designs,Model selection for machine learning 82 | 2/26/2018 22:14:48,,Numerical solution of ODEs,Permutation groups 83 | 2/27/2018 21:05:43,,Fourier transforms,Model selection for machine learning 84 | 2/27/2018 23:24:07,,Model selection for machine learning,Fourier transforms 85 | 2/28/2018 14:19:31,,Model selection for machine learning,Fourier transforms 86 | 2/28/2018 18:19:09,,Permutation groups,Numerical solution of ODEs 87 | 3/1/2018 17:22:32,,Model selection for machine learning,Combinatorial designs 88 | 2/28/2018 13:59:39,,Numerical solution of ODEs,Permutation groups 89 | 2/26/2018 22:07:22,,Combinatorial designs,Permutation groups 90 | 2/27/2018 14:46:27,,Model selection for machine learning,Combinatorial designs 91 | ,,, 92 | 2/28/2018 13:53:38,,Combinatorial designs,Permutation groups 93 | 3/1/2018 19:38:38,,Combinatorial designs,Model selection for machine learning 94 | 2/28/2018 14:01:58,,Permutation groups,Model selection for machine learning 95 | 2/28/2018 14:16:02,,Linear feedback shift registers,Permutation groups 96 | 2/28/2018 14:03:54,,Permutation groups,Combinatorial designs 97 | 2/26/2018 6:56:09,,Fourier transforms,Model selection for machine learning 98 | 2/28/2018 16:37:43,,Combinatorial designs,Permutation groups 99 | 2/28/2018 1:05:45,,Permutation groups,Combinatorial designs 100 | 2/28/2018 16:21:22,,Combinatorial designs,Permutation groups 101 | 3/2/2018 13:58:04,,Linear feedback shift registers,Permutation groups 102 | 2/26/2018 22:28:18,,Numerical solution of ODEs,Permutation groups 103 | ,,, 104 | 2/26/2018 21:58:05,,Numerical solution of ODEs,Model selection for machine learning 105 | 2/28/2018 9:31:33,,Linear feedback shift registers,Model selection for machine learning 106 | ,,, 107 | 2/28/2018 14:07:01,,Permutation groups,Combinatorial designs 108 | 2/28/2018 14:02:50,,Permutation groups,Model selection for machine learning 109 | 2/26/2018 22:46:45,,Numerical solution of ODEs,Model selection for machine learning 110 | 2/26/2018 7:43:16,,Model selection for machine learning,Combinatorial designs 111 | 2/26/2018 23:37:39,,Numerical solution of ODEs,Permutation groups 112 | 2/28/2018 14:23:18,,Fourier transforms,Numerical solution of ODEs 113 | ,,, 114 | 2/28/2018 11:44:31,,Permutation groups,Numerical solution of ODEs 115 | 2/26/2018 22:06:22,,Model selection for machine learning,Permutation groups 116 | 3/2/2018 14:01:30,,Fourier transforms,Model selection for machine learning 117 | 2/27/2018 6:37:49,,Numerical solution of ODEs,Permutation groups 118 | 2/27/2018 17:41:09,,Numerical solution of ODEs,Permutation groups 119 | 3/1/2018 11:02:44,,Permutation groups,Numerical solution of ODEs 120 | ,,, 121 | 2/26/2018 22:24:29,,Model selection for machine learning,Model selection for machine learning 122 | ,,, 123 | 3/1/2018 4:02:21,,Permutation groups,Numerical solution of ODEs 124 | 3/3/2018 13:47:35,,Model selection for machine learning,Combinatorial designs 125 | 2/28/2018 13:44:50,,Model selection for machine learning,Numerical solution of ODEs 126 | 2/26/2018 19:58:34,,Linear feedback shift registers,Fourier transforms 127 | 2/26/2018 22:17:29,,Numerical solution of ODEs,Model selection for machine learning 128 | 2/27/2018 2:11:30,,Model selection for machine learning,Numerical solution of ODEs 129 | 2/28/2018 14:02:20,,Numerical solution of ODEs,Fourier transforms 130 | 2/27/2018 1:38:20,,Numerical solution of ODEs,Permutation groups 131 | ,,, 132 | ,,, 133 | 2/26/2018 22:10:12,,Numerical solution of ODEs,Model selection for machine learning 134 | 2/28/2018 13:23:55,,Permutation groups,Numerical solution of ODEs 135 | ,,, 136 | 2/26/2018 22:25:01,,Combinatorial designs,Permutation groups 137 | 2/28/2018 13:48:24,,Combinatorial designs,Model selection for machine learning 138 | 2/28/2018 12:16:11,,Model selection for machine learning,Numerical solution of ODEs 139 | 2/26/2018 22:08:56,,Permutation groups,Combinatorial designs 140 | 3/1/2018 17:25:44,,Model selection for machine learning,Fourier transforms 141 | 2/28/2018 12:36:44,,Numerical solution of ODEs,Combinatorial designs 142 | 2/26/2018 22:50:55,,Model selection for machine learning,Permutation groups 143 | ,,, 144 | 2/27/2018 23:17:20,,Permutation groups,Model selection for machine learning 145 | 2/27/2018 17:12:16,,Fourier transforms,Numerical solution of ODEs 146 | 2/28/2018 14:34:59,,Permutation groups,Fourier transforms 147 | 2/27/2018 14:40:00,,Model selection for machine learning,Numerical solution of ODEs 148 | 3/1/2018 16:47:17,,Numerical solution of ODEs,Model selection for machine learning 149 | 2/27/2018 23:46:05,,Combinatorial designs,Numerical solution of ODEs 150 | 2/28/2018 14:22:53,,Permutation groups,Combinatorial designs 151 | -------------------------------------------------------------------------------- /final_project_calculation/template_chat.sage-chat: -------------------------------------------------------------------------------- 1 | {"sender_id":"4165f0a3-c8fe-4421-9a21-3be7449ed146","event":"chat","history":[{"author_id":"4165f0a3-c8fe-4421-9a21-3be7449ed146","content":"Hi! I've created this chat room for you to use to discuss the final project. (I will not be monitoring it, though.)","date":"2018-03-04T01:29:46.276Z"}],"date":"2018-03-04T01:29:46.276Z"} -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | Math 157 - Intro to Mathematical Software (Winter 2018) 3 | 4 | 5 |

Math 157 - Intro to Mathematical Software

6 | 7 |

8 | Information appearing below is subject to revision until the first lecture. Some additional 9 | information, particularly on the use of CoCalc, will be given in the first lecture; 10 | CoCalc also provides a tutorial for students. 11 |

12 | 13 |

14 | See this page for announcements. 15 |

16 | 17 |

18 | Course description: 19 | Math 157 is an introduction to the use of mathematical software. Although mathematics 20 | is still largely taught as a pencil-and-paper (and chalk) subject, this approach ignores the fundamental role 21 | played by computing technology in the process of mathematical reasoning and discovery. This course will introduce students to a broad but coherent collection of open-source software tools, and to diverse examples of their use in mathematical study and research. 22 | The course will be taught in a hands-on fashion; 23 | lectures will consist of interactive demonstrations, while assignments will involve guided experimentation and discovery. 24 | We will make extensive use of the Python programming language, 25 | the Jupyter notebook system, 26 | and the SageMath computer algebra system; however, 27 | no prior exposure to these tools, other mathematical software (Mathematica, Maple, Matlab, etc.), or computer programming will be assumed. 28 |

29 | 30 |

31 | This course is based on the cloud computing platform CoCalc (formerly SageMathCloud). 32 | As one component of the course grade is in-class participation, students are required 33 | to bring a laptop or large tablet to lectures; however, the only local software installation required is a web browser. More details on how CoCalc is to be used will be given in the first lecture. 34 |

35 | 36 |

37 | Officially, this course is being offered for the first time. However, a pilot version of the course was offered during winter 2017 as Math 152: Applicable Math and Computing (based on a course taught by William Stein at University of Washington). 38 | Here are the 39 | syllabus from that course, the lecture materials, and the 40 | CAPE report. 41 | (If you took my Math 152 course, please do not not register for Math 157!) 42 |

43 | 44 |

45 | Although Math 157 has been permanently added to the course catalog, it remains 46 | highly experimental in both its use of 47 | new technology and the approach to pedagogy. In addition to the final course evaluations, there will be several opportunities to submit feedback during the course; this feedback will help me evaluate some of the experiments and plan modifications for future iterations of the course. 48 |

49 | 50 |

51 | Since Math 157 is new, it may not yet appear in the list of approved courses for certain majors. 52 | I have confirmed that Math 157 is now an approved List B/C elective for Mathematics-Computer Science (MA30) majors 53 | and an approved upper-division elective for Probability and Statistics (MA35) majors. 54 | If you are interested in the course but are unsure whether it will count for your major, please contact me for guidance. 55 |

56 | 57 |

58 | Instructor: Kiran Kedlaya, 59 | kedlaya [at] ucsd [etcetera]. 60 |

61 | 62 |

63 | TAs: 64 |

    65 |
  • Thomas Grubb, tgrubb [at] ucsd [etcetera].
  • 66 |
  • Jun Bo Lau, jblau [at] ucsd [etcetera].
  • 67 |
  • Peter Wear, pwear [at] ucsd [etcetera].
  • 68 |
69 |

70 | 71 |

72 | Lectures: MWF 2:00-2:50pm in HSS 1330. No lectures on Monday, January 15 or Monday, February 19 (university holidays). There is a class participation component that contributes to the course grade; see below. 73 |

74 | 75 |

76 | Discussion sections: Tuesday 6:00-6:50pm (Wear), 7:00-7:50pm (Wear), 8:00-8:50pm (Grubb), 9:00-9:50pm (Lau) in APM 6402. 77 | Beware that the exterior doors to APM are locked each weekday after 9:20pm. 78 |

79 | 80 |

81 | Office hours: 82 |

    83 |
  • Kedlaya: Thursday 4-5pm, APM 7202. 84 |
  • 85 |
  • Grubb: Tuesday 11am-12pm, APM 6446. 86 |
  • 87 |
  • Lau: Thursday 11am-12pm, APM 6446. 88 |
  • 89 |
  • Wear: Wednesday 3-5pm, APM 6132. 90 |
  • 91 |
92 | In addition, we will be conducting "virtual office hours" Friday 3-7pm: during this time, the course staff will be monitoring the course chatroom on CoCalc to answer any questions that may arise. 93 |

94 | 95 |

96 | Textbook: 97 | None. In lieu of purchasing a textbook, students will need to create a free account on CoCalc in order to complete and submit assignments. 98 | (It is not necessary to pay for an upgraded account; equivalent functionality will be provided to enrolled students.) 99 | If you do not use your official UCSD email address to create the account, please provide the instructor with the address you used in order to gain access to the course materials. 100 |

101 | 102 |

103 | Prerequisites: 104 | 105 | Math 20D, plus any one of Math 18 or Math 20F or Math 31AH. As usual, these can be waived by the instructor, but I will be pretty strict because I have already made a substantial effort to keep the prerequisites low to begin with. 106 |

107 | 108 |

109 | Homework: Weekly problem sets, due Fridays at 8pm (one each during weeks 2-9). 110 | All assignments will be assigned, completed, submitted, evaluated, and returned using CoCalc; the process will be explained in the 111 | first lecture. For security reasons, grades will not be posted within CoCalc; check TritonEd for those. 112 |

113 | 114 |

115 | Midterms: None. 116 |

117 | 118 |

119 | Final exam: None. Instead, there will be a final project due on the last day of classes (Friday, March 16). This will include an in-class component on March 12 and March 14. 120 |

121 | 122 |

123 | Grading: 124 |

    125 |
  • 60% homework (best 6 assignments, weighted equally).
  • 126 |
  • 20% final project.
  • 127 |
  • 20% in-class participation (up to 20 of 24 lectures counted). Participation is evaluated based on changes in the lectures/[date] directory during the class hour (as timestamped by CoCalc). 128 | No evaluations for the first lecture (1/8) or during week 10 (March 12-16). 129 |
  • 130 |
131 | Since these parameters have been chosen to be somewhat forgiving, no additional excuses will be granted (not even for waitlisted students). No exceptions. 132 |

133 | 134 |

135 | For the conversion of raw scores into letter grades, the following minima are guaranteed: 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 |
Percentage 97 93 90 87 83 80 77 73 70
Minimum grade A+ A A- B+ B B- C+ C C-
162 | Additionally, any score in at least the 85th percentile or higher is guaranteed an A grade, while any score in the 65th percentile or higher is guaranteed a B grade. 163 |

164 | 165 |

166 | For future reference, the final conversion was made as follows: 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 |
Percentage 97 93 90 87 83 78 75 69 63
Letter grade A+ A A- B+ B B- C+ C C-
193 | 194 |

195 | 196 |

197 | Academic Integrity: 198 |

    199 |
  • You are welcome (and strongly encouraged) to work with other students in the class. However, you must clearly indicate who you worked with on each problem. In addition, you must write your solutions in your own words; do not copy/paste from others, as CoCalc's TimeTravel feature makes this trivial to detect. 200 |
  • 201 |
  • 202 | You are welcome (and expected) to do research online using the CoCalc documentation, Google, Wikipedia, Stack Overflow, etc; but be sure to provide links to sources you use in your solutions. 203 | Be as specific as possible; e.g., provide URLs to individual web pages rather than to whole web sites. 204 |
  • 205 |
  • Misuse of CoCalc will be considered a violation of academic integrity. This includes 206 | unauthorized access to other user accounts, and online behavior that violates UCSD's discrimination and harassment policies. 207 |
  • 208 |
  • 209 | Violations of academic integrity may be handled by zeroing out scores on individual assigments; 210 | assigning failing course grades; and/or campus disciplinary measures. 211 |
  • 212 | 213 |
214 | 215 |

216 | 217 |

Topics calendar:

218 | 219 |

220 | Some adjustments may be made as the term progresses. 221 |

222 |
    223 |
  • 224 | Weeks 1-2: CoCalc, Jupyter notebooks, markdown syntax, Python 225 |
  • 226 |
  • 227 | Week 3: Sage 228 |
  • 229 |
  • 230 | Week 4: Linear algebra (including comparison with MATLAB) 231 |
  • 232 |
  • 233 | Week 5: Discrete math (combinatorics, graph theory) 234 |
  • 235 |
  • 236 | Week 6: Algebra, number theory, cryptography 237 |
  • 238 |
  • 239 | Weeks 7-8: Statistics (including comparison with R), machine learning 240 |
  • 241 |
  • 242 | Week 9: Julia 243 |
  • 244 |
  • 245 | Week 10: Final project 246 |
  • 247 |
248 | 249 | 250 | 251 | -------------------------------------------------------------------------------- /lectures/2018-01-08/2018-01-08.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "## Math 157: Intro to Mathematical Software\n", 10 | "## UC San Diego, winter 2018\n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "collapsed": false 17 | }, 18 | "source": [ 19 | "## January 8, 2018: Introduction to CoCalc" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": { 25 | "collapsed": false 26 | }, 27 | "source": [ 28 | "Welcome to Math 157! This course is an introduction to the use of mathematical software. Although mathematics is still largely taught as a pencil-and-paper (and chalk) subject, this approach ignores the fundamental role played by computing technology in the subject. This course will introduce students to a broad but coherent collection of open-source software tools, and to diverse examples of their use in mathematical study and research." 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": { 34 | "collapsed": false 35 | }, 36 | "source": [ 37 | "This course will operate quite unlike any other math class you have taken. The goal of today's lecture is to both explain in words, and demonstrate visually, how the course will operate. I'll start with the explaining part, by going over the [course syllabus](http://www.math.ucsd.edu/~kedlaya/math157/)." 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": { 43 | "collapsed": false 44 | }, 45 | "source": [ 46 | "## What you need" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": { 52 | "collapsed": false 53 | }, 54 | "source": [ 55 | "CoCalc is a Web platform for using mathematical software *in the cloud* rather than installed locally. This means that you can access it, to the full extent required for this course, from any device with Internet access and a web browser. Other than the syllabus on my web site, and grades posted on [TritonEd](https://tritoned.ucsd.edu), all materials for this course will be distributed and collected using CoCalc." 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": { 61 | "collapsed": false 62 | }, 63 | "source": [ 64 | "Part of the course grade is based on using CoCalc during lectures (starting on Wednesday), so you will need to bring a suitable device to class. On one hand, it is pretty hard to use CoCalc on a phone, so I would advise against trying. On the other hand, you can see how big the chairs and desks are. I recommend using either a small laptop or a large (at least 8 inches diagonally) tablet with a physical keyboard. (You are of course free to use a different device outside of class!)" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": { 70 | "collapsed": false 71 | }, 72 | "source": [ 73 | "You will need to create an account to use CoCalc. This is easy (and free): go to https://cocalc.com and follow the instructions on the main page. If you use your official UCSD email address to create the account (recommended, and what happened if you answered the email invitation I issued from CoCalc), you will automatically be given access to the course materials. If you use another address (which might happen implicitly if you use a social media account to sign in), please email me to let me know what email address is associated to your account, so I can manually link you to the course." 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": { 79 | "collapsed": false 80 | }, 81 | "source": [ 82 | "If you are having trouble getting onto CoCalc, please take advantage of this week's sections and office hours to get help." 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": { 88 | "collapsed": false 89 | }, 90 | "source": [ 91 | "## Navigating CoCalc: projects" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": { 97 | "collapsed": false 98 | }, 99 | "source": [ 100 | "Once you have logged into CoCalc, you will probably start in the Projects view. You can always get to that screen by clicking on the CoCalc logo or the word \"Projects\" at the top left: ![CoCalc](logo.png).\n" 101 | ] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": { 106 | "collapsed": false 107 | }, 108 | "source": [ 109 | "You should start with two projects: \"Math 157 -- Winter 2018 (your name)\" (your *individual project*) and \"Shared Project -- Math 157\" (the *shared project*). If you cannot see one or both of these, contact me or your TA at once. (For example, this might happen if you didn't use your UCSD email address to create your account.)\n", 110 | "\n", 111 | "It is possible to create additional projects, but at no point will this be necessary. (Also, such projects will not be \"upgraded\" in the same way as the individual and shared projects are.)" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": { 117 | "collapsed": false 118 | }, 119 | "source": [ 120 | "Each project has its own file directory, which you will see if you click on the project in the Projects view. From within a project, you can always get to the Files view by cilcking the folder icon below the CoCalc logo at top left: ![folder icon](files.png).\n", 121 | "\n", 122 | "This is like a folder on your computer; in particular, it can have its own subfolders. Your individual project is yours alone; no one has access to it besides you, me, and the TAs. By contrast, the shared project is accessible to *everyone* in the course." 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "metadata": { 128 | "collapsed": false 129 | }, 130 | "source": [ 131 | "## Chat rooms" 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "metadata": { 137 | "collapsed": false 138 | }, 139 | "source": [ 140 | "In the shared project, you will find a file called \"master-chat.sage-chat\". Open this to get to the master chat room for this course.\n", 141 | "\n", 142 | "The master chat room will be used in various ways. I will occasionally make announcements here (e.g., updates about the homework). I and the TAs will conduct some \"virtual office hours\" here as well. At other times, feel free to ask (and answer) questions about the course.\n", 143 | "\n", 144 | "It is possible to create additional chat rooms in the shared project. For instance, if you are collaborating in a small group on a homework assignment, it is probably better to use a separate chat room to avoid cluttering the master chat." 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": { 150 | "collapsed": false 151 | }, 152 | "source": [ 153 | "## Workflow: lectures" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": { 159 | "collapsed": false 160 | }, 161 | "source": [ 162 | "When you arrive at each lecture, please perform the following steps.\n", 163 | "- Open your device, sign into CoCalc, and open your individual project.\n", 164 | "- From the Files view, navigate into the folders \"lectures\", then the subfolder \"2018-xx-xx\" with that day's date. For instance, if you were doing this today, you would open the subfolder \"2018-01-08\".\n", 165 | "- Open the file \"2018-xx-xx.ipynb\" with that day's date. For instance, if you were doing this today, you would find a copy of this file! (You should try this later to see that this works.)" 166 | ] 167 | }, 168 | { 169 | "cell_type": "markdown", 170 | "metadata": { 171 | "collapsed": false 172 | }, 173 | "source": [ 174 | "Each lecture will consist of a file like this, called a *Jupyter notebook*, and possibly some auxiliary files. Next time, we'll discuss in detail how Jupyter notebooks work; this will in particular explain how class participation is recorded for your course grade." 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": { 180 | "collapsed": false 181 | }, 182 | "source": [ 183 | "## Workflow: homework (and the final project)" 184 | ] 185 | }, 186 | { 187 | "cell_type": "markdown", 188 | "metadata": { 189 | "collapsed": false 190 | }, 191 | "source": [ 192 | "In order to work on a homework assignment, you will (in your individual project) navigate into the folder \"assignments\", then the subfolder \"2018-xx-xx\" with the due date of the assignment. There you will again find a file \"2018-xx-xx.ipynb\" with the due date of the assignment." 193 | ] 194 | }, 195 | { 196 | "cell_type": "markdown", 197 | "metadata": { 198 | "collapsed": false 199 | }, 200 | "source": [ 201 | "The format of assignments will vary over the term, but in general you will complete an assignment by filling in the Jupyter notebook as instructed; this will be similar to class participation. Any exceptional instructions will be included in the notebook itself." 202 | ] 203 | }, 204 | { 205 | "cell_type": "markdown", 206 | "metadata": { 207 | "collapsed": false 208 | }, 209 | "source": [ 210 | "One potentially confusing feature of CoCalc is that there is no way to *submit* your assignment for grading. What actually happens is, at (or shortly after) the due time, I will *collect* your assignment by copying the whole 2018-xx-xx subfolder out of your project. The TAs will then evaluate your assignment, possibly adding some feedback in a separate file, and eventually return it to you by copying the subfolder back into your project." 211 | ] 212 | }, 213 | { 214 | "cell_type": "markdown", 215 | "metadata": { 216 | "collapsed": false 217 | }, 218 | "source": [ 219 | "The final project will be handled the same way. The only difference is how it figures into your course grade." 220 | ] 221 | }, 222 | { 223 | "cell_type": "markdown", 224 | "metadata": { 225 | "collapsed": false 226 | }, 227 | "source": [ 228 | "## For more on CoCalc..." 229 | ] 230 | }, 231 | { 232 | "cell_type": "markdown", 233 | "metadata": { 234 | "collapsed": false 235 | }, 236 | "source": [ 237 | "... see the [CoCalc tutorial for students](https://tutorial.cocalc.com/students/)." 238 | ] 239 | }, 240 | { 241 | "cell_type": "markdown", 242 | "metadata": { 243 | "collapsed": false 244 | }, 245 | "source": [ 246 | "This is a new line that I added to the notebook." 247 | ] 248 | } 249 | ], 250 | "metadata": { 251 | "kernelspec": { 252 | "display_name": "SageMath 8.0", 253 | "name": "sage-8.0" 254 | }, 255 | "language_info": { 256 | "codemirror_mode": { 257 | "name": "ipython", 258 | "version": 2 259 | }, 260 | "file_extension": ".py", 261 | "mimetype": "text/x-python", 262 | "name": "python", 263 | "nbconvert_exporter": "python", 264 | "pygments_lexer": "ipython2", 265 | "version": "2.7.13" 266 | } 267 | }, 268 | "nbformat": 4, 269 | "nbformat_minor": 0 270 | } -------------------------------------------------------------------------------- /lectures/2018-01-08/files.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kedlaya/math157/87f1d087b42b333d7835a8a5b9a3ab8419962c5d/lectures/2018-01-08/files.png -------------------------------------------------------------------------------- /lectures/2018-01-08/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kedlaya/math157/87f1d087b42b333d7835a8a5b9a3ab8419962c5d/lectures/2018-01-08/logo.png -------------------------------------------------------------------------------- /lectures/2018-01-10/2018-01-10.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "## Math 157: Intro to Mathematical Software\n", 10 | "## UC San Diego, winter 2018\n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "collapsed": false 17 | }, 18 | "source": [ 19 | "## January 10, 2018: Jupyter notebooks" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": { 25 | "collapsed": false 26 | }, 27 | "source": [ 28 | "As I explained last time, you should start each lecture by performing the following steps. (Do them now.)\n", 29 | "- Open your device, sign into CoCalc, and open your individual project.\n", 30 | "- If necessary, get to the Files view by clicking the folder icon: ![Folder icon](folder.png)\n", 31 | "- If necessary, navigate to the top of your directory structure by clicking the home icon: ![Home icon](home.png)\n", 32 | "- Click on the folder \"lectures\", then the subfolder \"2018-01-10\".\n", 33 | "- Open the file \"2018-01-10.ipynb\" with that day's date. You should see this file!" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": { 39 | "collapsed": false 40 | }, 41 | "source": [ 42 | "This file is an example of a *Jupyter notebook*. In this lecture, we explain what Jupyter notebooks are, what you can do with them, and how they will be used in this course." 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": { 48 | "collapsed": false 49 | }, 50 | "source": [ 51 | "## Optional: chat room" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": { 57 | "collapsed": false 58 | }, 59 | "source": [ 60 | "You may also want to open a second tab or window, open the shared project in CoCalc, and enter the master chat room. Of course you are welcome to ask questions during the lecture, but you also have the possibility of using the chat room to ask a question of the rest of the class. I encourage you to take advantage of the knowledge of your classmates in this way! (Your social media can wait for an hour...)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": { 66 | "collapsed": false 67 | }, 68 | "source": [ 69 | "Also to be found in the shared project: a folder called first_steps. This is a little tutorial put together by the CoCalc team to walk you through some basic tasks. If you want to mess around with it, please make a copy of the folder first (demonstrate that here). You can also copy it into your course project, but you won't be able to add collaborators there." 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": { 75 | "collapsed": false 76 | }, 77 | "source": [ 78 | "## Project Jupyter" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": { 84 | "collapsed": false 85 | }, 86 | "source": [ 87 | "According to its home page http://jupyter.org/:\n", 88 | "\n", 89 | "> Project Jupyter exists to develop open-source software, open-standards, and services for interactive computing across dozens of programming languages." 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": { 95 | "collapsed": false 96 | }, 97 | "source": [ 98 | "To put that in context, the idea is to provide a uniform environment for both *doing* scientific computations, using a variety of software tools, and *communicating* the results, in a way that others can then *reproduce* the results. In this course, we'll use Jupyter to replace two older technologies: paper and the chalkboard." 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "metadata": { 104 | "collapsed": false 105 | }, 106 | "source": [ 107 | "## Notebooks and their structure" 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "metadata": { 113 | "collapsed": false 114 | }, 115 | "source": [ 116 | "The *Jupyter notebook* is Jupyter's analogue of a piece of paper (or an Excel spreadsheet, or a Word document, or ...). At the moment it looks like a pretty static object, but let's look more closely." 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": { 122 | "collapsed": false 123 | }, 124 | "source": [ 125 | "Click on this piece of text. You should see a blue outline appear around it. This outline delineates a *cell*; the notebook is composed of a sequence of such cells, of three kinds.\n", 126 | " - Markdown cells, like this one, display text with some formatting. For help with the formatting, go to the Help menu and select Markdown.\n", 127 | " - Code cells contain code to be executed by a particular piece of software (the *kernel*). We'll start working with code cells when we start with Python in the next lecture (or today if time permits).\n", 128 | " - Raw cells are in between: they look like code, but are static like markdown cells. These are useful if you want to display a piece of code but not actually execute it; but this probably won't come up very often for us." 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 1, 134 | "metadata": { 135 | "collapsed": false 136 | }, 137 | "outputs": [ 138 | { 139 | "data": { 140 | "text/plain": [ 141 | "3995" 142 | ] 143 | }, 144 | "execution_count": 1, 145 | "metadata": { 146 | }, 147 | "output_type": "execute_result" 148 | } 149 | ], 150 | "source": [ 151 | "17*235 # Example of a code cell, executes something" 152 | ] 153 | }, 154 | { 155 | "cell_type": "raw", 156 | "metadata": { 157 | "collapsed": false 158 | }, 159 | "source": [ 160 | "2+3 # Example of a raw cell, does not execute" 161 | ] 162 | }, 163 | { 164 | "cell_type": "markdown", 165 | "metadata": { 166 | "collapsed": false 167 | }, 168 | "source": [ 169 | "Now double-click on this cell (or any other). It should be replaced by a text editing box containing the contents of the cell. You should be able to edit this text as in a word processor. Go ahead and try editing some text now (don't worry about clobbering the original; we'll see in a moment how to undo changes). To close the editor, hit Shift-Enter. (The editor will not automatically close if you switch to another cell. If you have multiple open cells, the colored outline will indicate which one you are editing.)\n", 170 | "\n", 171 | "You can also try editing the code and raw cells above. They behave slightly differently; for instance, Shift-Enter in a code cell causes it to execute." 172 | ] 173 | }, 174 | { 175 | "cell_type": "markdown", 176 | "metadata": { 177 | "collapsed": false 178 | }, 179 | "source": [ 180 | "## Notebooks in this course" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": { 186 | "collapsed": false 187 | }, 188 | "source": [ 189 | "I can now explain how we will verify your in-class participation for the purposes of your course grade. During each lecture, I will be demonstrating a particular notebook; by following the instructions I gave you at the beginning, you will have access to your own private copy of the same notebook. In order to get credit for in-class participation on a particular day, you need to make a \"reasonable\" number of edits to that day's file during that day's lecture (which we will verify using file logs). So don't just sit there watching me; experiment on your own! I will sometimes pause to give you a chance to try something specific, but you should be trying things out even when I'm not specifically directing you to do so.\n", 190 | "\n", 191 | "For example, if you click immediately below this cell, a new cell will be inserted in between this cell and the next one. (If you are using a mouse, a colored bar should appear as you hover, indicating where you should click.) Try inserting a cell and fiddling with Markdown formatting (again using the Help menu).\n", 192 | "- Can you make some text appear in boldface? Strikethrough? Bold *and* italic at once?\n", 193 | "- Can you produce a numbered list? A list of lists? A checklist?\n", 194 | "- Can you make a piece of text (which is not itself a URL) appear as a link to a URL?\n", 195 | "- What emoji can you produce?" 196 | ] 197 | }, 198 | { 199 | "cell_type": "markdown", 200 | "metadata": { 201 | "collapsed": false 202 | }, 203 | "source": [ 204 | "Homework assignments will also be in the form of notebooks. To find the homework assignment due on a given date, we perform a similar process to the one we did to get started with this lecture. Let's try this with the \"assignment\" due this Friday (January 12).\n", 205 | "- Open your device, sign into CoCalc, and open your individual project.\n", 206 | "- If necessary, get to the Files view by clicking the folder icon: ![Folder icon](folder.png)\n", 207 | "- If necessary, navigate to the top of your directory structure by clicking the home icon: ![Home icon](home.png)\n", 208 | "- Click on the folder \"assignments\", then the subfolder \"2018-01-12\".\n", 209 | "- Open the file \"2018-01-12.ipynb\".\n", 210 | "\n", 211 | "In fact there is no assignment due this Friday; what you have is a \"practice assignment\" designed to let you get accustomed to working with CoCalc, and to show you some additional features. It will be collected, evaluated, and returned to you as if it were a homework assignment, but no grades will be assigned.\n", 212 | "\n", 213 | "I remind you that there is no mechanism for *submitting* your homework assignment. When the homework is due, we will simply copy the contents of the folder (the notebook plus any additional files) to another directory. When grading is complete, you will receive additional files in the same folder." 214 | ] 215 | }, 216 | { 217 | "cell_type": "markdown", 218 | "metadata": { 219 | "collapsed": false 220 | }, 221 | "source": [ 222 | "Can I make text appear in **boldface**? \n", 223 | "did this work?\n" 224 | ] 225 | }, 226 | { 227 | "cell_type": "markdown", 228 | "metadata": { 229 | "collapsed": false 230 | }, 231 | "source": [ 232 | "## TimeTravel" 233 | ] 234 | }, 235 | { 236 | "cell_type": "markdown", 237 | "metadata": { 238 | "collapsed": false 239 | }, 240 | "source": [ 241 | "Jupyter notebooks are a widely used format, and are most commonly manipulated using the standard Jupyter server. CoCalc instead implements a custom version of the Jupyter server which has some very useful features, notably TimeTravel." 242 | ] 243 | }, 244 | { 245 | "cell_type": "markdown", 246 | "metadata": { 247 | "collapsed": false 248 | }, 249 | "source": [ 250 | "Try clicking on ![the TimeTravel button](TimeTravel.png) near the top of the window. This takes you to a \"flat\" view of your notebook, in which nothing is editable. However, there is now a slider at the top of your window which you can use to scroll through historical versions of your document. CoCalc takes snapshots about once per second when there is activity on the file." 251 | ] 252 | }, 253 | { 254 | "cell_type": "markdown", 255 | "metadata": { 256 | "collapsed": false 257 | }, 258 | "source": [ 259 | "Note that the TimeTravel view is a separate tab from the original file. To get back without changing anything, just close the TimeTravel tab. If instead you want to roll back some changes, find the version you want in TimeTravel and then click on ![Revert live version to this](Revert.png)." 260 | ] 261 | }, 262 | { 263 | "cell_type": "markdown", 264 | "metadata": { 265 | "collapsed": false 266 | }, 267 | "source": [ 268 | "There are additional options in TimeTravel, such as highlight changes between two versions, and \"Load all history\" in case you want to go back to a *much* older version of the file." 269 | ] 270 | }, 271 | { 272 | "cell_type": "markdown", 273 | "metadata": { 274 | "collapsed": false 275 | }, 276 | "source": [ 277 | "When you copy a file, the history does not come along with it. So for example, if you want to revert this notebook back to its original state *and* save your changes, use the file view to copy the changed version to a new file (which now has no history), then do TimeTravel on the *original* file." 278 | ] 279 | }, 280 | { 281 | "cell_type": "markdown", 282 | "metadata": { 283 | "collapsed": false 284 | }, 285 | "source": [ 286 | "## Kernels and cell execution" 287 | ] 288 | }, 289 | { 290 | "cell_type": "markdown", 291 | "metadata": { 292 | "collapsed": false 293 | }, 294 | "source": [ 295 | "So far we have only seen text in Jupyter notebooks, but of course the whole point is to integrate explanatory text with code that actually *does* something. So let's talk a bit about how that is going to work. We'll get into this in more detail once we start discussing Python specifically (next time).\n", 296 | "\n", 297 | "CoCalc supports the use of many different \"kernels\". A kernel is basically a programming language; different kernels have different syntaxes for input (what you type into the kernel) and output (what comes back from the kernel), and often are useful for very different purposes. At any given time, a notebook is set to use a particular kernel, which is named at the top right of the window (right now you should see \"Python 3 (Ubuntu Linux)\".) One can change the running kernel using the \"Kernel\" menu, but you won't normally do this in the middle of a session (and I'll try to make sure the kernel is set correctly for each lecture)." 298 | ] 299 | }, 300 | { 301 | "cell_type": "markdown", 302 | "metadata": { 303 | "collapsed": false 304 | }, 305 | "source": [ 306 | "Communication between the user and the kernel is broken down into *cells*. When editing a code cell, hit Shift-Enter to execute the contents of the cell; the response from the kernel will be printed underneath." 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": 2, 312 | "metadata": { 313 | "collapsed": false 314 | }, 315 | "outputs": [ 316 | { 317 | "data": { 318 | "text/plain": [ 319 | "4" 320 | ] 321 | }, 322 | "execution_count": 2, 323 | "metadata": { 324 | }, 325 | "output_type": "execute_result" 326 | } 327 | ], 328 | "source": [ 329 | "2+2" 330 | ] 331 | }, 332 | { 333 | "cell_type": "markdown", 334 | "metadata": { 335 | "collapsed": false 336 | }, 337 | "source": [ 338 | "Note the difference between Shift-Enter and Enter: you can have multiple lines of code within a single cell." 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": 3, 344 | "metadata": { 345 | "collapsed": false 346 | }, 347 | "outputs": [ 348 | { 349 | "data": { 350 | "text/plain": [ 351 | "5" 352 | ] 353 | }, 354 | "execution_count": 3, 355 | "metadata": { 356 | }, 357 | "output_type": "execute_result" 358 | } 359 | ], 360 | "source": [ 361 | "x=2\n", 362 | "x+3" 363 | ] 364 | }, 365 | { 366 | "cell_type": "markdown", 367 | "metadata": { 368 | "collapsed": false 369 | }, 370 | "source": [ 371 | "Although the interaction is broken down into cells, in a single session all of the cell executions form a single \"dialogue\", with persistence of state between cells. For example, in the previous cell the line 'x=2' was an assignment: it declared a new variable 'x' and set it to have the value '2'. That value will persist if we perform another execution. (The \"Restart\" command under the \"Kernel\" menu can be used to end the current dialogue and start afresh.)" 372 | ] 373 | }, 374 | { 375 | "cell_type": "code", 376 | "execution_count": 4, 377 | "metadata": { 378 | "collapsed": false 379 | }, 380 | "outputs": [ 381 | { 382 | "data": { 383 | "text/plain": [ 384 | "7" 385 | ] 386 | }, 387 | "execution_count": 4, 388 | "metadata": { 389 | }, 390 | "output_type": "execute_result" 391 | } 392 | ], 393 | "source": [ 394 | "3*x+1" 395 | ] 396 | }, 397 | { 398 | "cell_type": "markdown", 399 | "metadata": { 400 | "collapsed": false 401 | }, 402 | "source": [ 403 | "One potential source of confusion: when you look at a notebook, you see a series of code cells in some order. However, in any given session, you can choose to execute the cells in any order; this includes repeatedly executing a single cell, or skipping one entirely. (Notice the \"In\" and \"Out\" tags in the left margin telling you about the execution order; this might look familiar if you have used Mathematica.) Try some experiments with this using the following example." 404 | ] 405 | }, 406 | { 407 | "cell_type": "code", 408 | "execution_count": 5, 409 | "metadata": { 410 | "collapsed": false 411 | }, 412 | "outputs": [ 413 | ], 414 | "source": [ 415 | "x=x+1 # Try executing this repeatedly, then one of the others" 416 | ] 417 | }, 418 | { 419 | "cell_type": "markdown", 420 | "metadata": { 421 | "collapsed": false 422 | }, 423 | "source": [ 424 | "That said, if you are preparing a notebook for someone else to read (e.g., when you are submitting homework!), you probably want to assume that the user plans to execute the cells in the order they are given. In fact, there is an easy way to do exactly that: the \"Run all\" command in the \"Cell\" menu. (Note: this picks up from the current state of the kernel; if you want a fresh start, instead use the \"Restart and run all...\" command under the \"Kernel\" menu.)" 425 | ] 426 | }, 427 | { 428 | "cell_type": "markdown", 429 | "metadata": { 430 | "collapsed": false 431 | }, 432 | "source": [ 433 | "On rare occasions, you may want to include a cell that looks like code (i.e., monospaced text without formatting) but shouldn't actually execute. This can be achieved by setting the cell type to \"Raw\"." 434 | ] 435 | }, 436 | { 437 | "cell_type": "raw", 438 | "metadata": { 439 | "collapsed": false 440 | }, 441 | "source": [ 442 | "this=looks like code\n", 443 | "but=does nothing" 444 | ] 445 | }, 446 | { 447 | "cell_type": "code", 448 | "execution_count": 0, 449 | "metadata": { 450 | "collapsed": false 451 | }, 452 | "outputs": [ 453 | ], 454 | "source": [ 455 | ] 456 | } 457 | ], 458 | "metadata": { 459 | "kernelspec": { 460 | "display_name": "Python 3 (Ubuntu Linux)", 461 | "language": "python", 462 | "name": "python3" 463 | }, 464 | "language_info": { 465 | "codemirror_mode": { 466 | "name": "ipython", 467 | "version": 3 468 | }, 469 | "file_extension": ".py", 470 | "mimetype": "text/x-python", 471 | "name": "python", 472 | "nbconvert_exporter": "python", 473 | "pygments_lexer": "ipython3", 474 | "version": "3.5.2" 475 | } 476 | }, 477 | "nbformat": 4, 478 | "nbformat_minor": 0 479 | } -------------------------------------------------------------------------------- /lectures/2018-01-10/Revert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kedlaya/math157/87f1d087b42b333d7835a8a5b9a3ab8419962c5d/lectures/2018-01-10/Revert.png -------------------------------------------------------------------------------- /lectures/2018-01-10/TimeTravel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kedlaya/math157/87f1d087b42b333d7835a8a5b9a3ab8419962c5d/lectures/2018-01-10/TimeTravel.png -------------------------------------------------------------------------------- /lectures/2018-01-10/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kedlaya/math157/87f1d087b42b333d7835a8a5b9a3ab8419962c5d/lectures/2018-01-10/folder.png -------------------------------------------------------------------------------- /lectures/2018-01-10/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kedlaya/math157/87f1d087b42b333d7835a8a5b9a3ab8419962c5d/lectures/2018-01-10/home.png -------------------------------------------------------------------------------- /lectures/2018-01-22/SageMath_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kedlaya/math157/87f1d087b42b333d7835a8a5b9a3ab8419962c5d/lectures/2018-01-22/SageMath_logo.png -------------------------------------------------------------------------------- /lectures/2018-02-28/2018-02-28.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "## Math 157: Intro to Mathematical Software\n", 10 | "## UC San Diego, winter 2018\n", 11 | "\n", 12 | "## February 28, 2018: More on machine learning" 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": { 18 | "collapsed": false 19 | }, 20 | "source": [ 21 | "Administrivia (to be updated):\n", 22 | "\n", 23 | "- CAPE evaluations are available! They close Monday, March 19 at 8am. Since this course is highly experimental, your feedback will be very helpful for shaping future offerings.\n", 24 | "- Attendance scores through Wednesday, February 21 are now posted on TritonEd. Contact Peter with any issues.\n", 25 | "- My office hours this week will be held Thursday, 3:30-4:30 (rather than 4-5).\n", 26 | "- Grades for HW5 will be available shortly.\n", 27 | "- The HW6 solution set is available.\n", 28 | "- HW 7 is now available. Some early comments:\n", 29 | " - Problem 1: The \"Orange\" dataset is not available via statsmodels. However, you can access it directly from R using the `rpy2` module. Also, some students have had issues with the \"FacetGrid\" command crashing their kernel; if this occurs, simply state that and skip this part of the problem. (Added in class: try restarting your project before giving up.)\n", 30 | " - Problem 3a: The mpg dataset is in ggplot, not statsmodels: `from ggplot import mpg`\n", 31 | "\n", 32 | "Added in class:\n", 33 | "- If you are unable to be on campus during week 10, please contact me immediately to set up a workaround for the final project.\n", 34 | "- It looks everyone can have their first choice for the final project. However, please fill out the Google Form (see Monday's lecture or Part 2 of the final project for the link) by Friday.\n", 35 | "\n", 36 | "Advance notice for week 9:\n", 37 | "- No sections on Tuesday, March 6. However, during this time, you are welcome to use APM 6402 as a study room; we will also try to monitor the chat room.\n", 38 | "- Thomas's office hours (usually Tuesday 11am-12pm) are moved to Friday 11:30am-12:50pm.\n", 39 | "- Peter's office hours (usually Wednesday 3-5pm) are moved to Wednesday 5-7pm. \n", 40 | "- There will be an extra virtual office hour Thursday 6-7pm.\n", 41 | "\n", 42 | "Advance notice for week 10:\n", 43 | "- No lectures on Monday, March 12 or Wednesday, March 14. You may wish to use this time to meet your assigned group for Part 2 of the final project.\n", 44 | "- There will be a lecture on Friday, March 16, on the topic of \"Where to go from here?\" This lecture will not be counted for course attendance; that is, the last lecture for which attendance counts is Friday, March 9.\n", 45 | "- My office hours on Thursday, March 15 are cancelled. All other sections and office hours meet as scheduled." 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 1, 51 | "metadata": { 52 | "collapsed": false 53 | }, 54 | "outputs": [ 55 | { 56 | "data": { 57 | "text/html": [ 58 | "

Machine Learning

Source: http://xkcd.com/1838
" 59 | ] 60 | }, 61 | "execution_count": 1, 62 | "metadata": { 63 | }, 64 | "output_type": "execute_result" 65 | } 66 | ], 67 | "source": [ 68 | "xkcd(1838)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "metadata": { 74 | "collapsed": false 75 | }, 76 | "source": [ 77 | "\n", 78 | "Machine learning is basically everywhere these days. Here a few common examples, together with some potential downsides caused by undesirable features of the input data (e.g., biased or insufficiently diverse training data). This [TED talk](https://www.ted.com/talks/joy_buolamwini_how_i_m_fighting_bias_in_algorithms) summarizes the key issue; it mentions [this book](https://weaponsofmathdestructionbook.com/) which takes a deeper look at the phenomenon (disclosure: the author is married to my PhD advisor).\n", 79 | "\n", 80 | "- Text inputs\n", 81 | " - spam filtering (downside: [can also be used to defeat spam filtering](https://www.usenix.org/legacy/event/leet08/tech/full_papers/nelson/nelson_html/))\n", 82 | " - machine translation (downside: [may reflect gender bias](https://www.fastcompany.com/3010223/google-translates-gender-problem-and-bing-translates-and-systrans))\n", 83 | " - chat bots (downside: [may reflect incivility](https://arstechnica.com/information-technology/2016/03/microsoft-terminates-its-tay-ai-chatbot-after-she-turns-into-a-nazi/))\n", 84 | "- Graphical inputs\n", 85 | " - face detection (downside: [may reflect racial bias](https://www.youtube.com/watch?v=t4DT3tQqgRM))\n", 86 | "- Sound inputs\n", 87 | " - speech-to-text (downside: [may discriminate based on accent](https://www.wired.com/2017/03/voice-is-the-next-big-platform-unless-you-have-an-accent/) or [based on gender](https://makingnoiseandhearingthings.com/2016/07/12/googles-speech-recognition-has-a-gender-bias/))\n", 88 | "- Location inputs\n", 89 | " - augmented reality (downside: [may reflect racial bias in housing](http://www.usatoday.com/story/tech/news/2016/08/09/pokemon-go-racist-app-redlining-communities-color-racist-pokestops-gyms/87732734/))\n", 90 | "- Situational inputs\n", 91 | " - recommendations (downside: [may reflect gender bias](https://phys.org/news/2016-09-gender-bias-algorithms.html))\n", 92 | " - online ads (downside: [may reflect racial bias](http://arxiv.org/ftp/arxiv/papers/1301/1301.6822.pdf))\n", 93 | " - crime prediction and prevention (downside: [may perpetuate racial disparities](https://www.sciencenews.org/blog/science-public/data-driven-crime-prediction-fails-erase-human-bias))\n", 94 | " - prison sentencing (downside: [may perpetuate racial disparaties](https://www.propublica.org/article/machine-bias-risk-assessments-in-criminal-sentencing))\n", 95 | " - content aggregation (downside: [may facilitate political manipulation](https://www.theguardian.com/technology/2017/sep/06/facebook-political-ads-russia-us-election-trump-clinton))" 96 | ] 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "metadata": { 101 | "collapsed": false 102 | }, 103 | "source": [ 104 | "The rest of this lecture is not about ethical issues; however, I did want to highlight them before continuing. The proliferation of such issues makes it important for *everyone* to understand a bit about how machine learning works." 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "metadata": { 110 | "collapsed": false 111 | }, 112 | "source": [ 113 | "### Modalities of machine learning" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": { 119 | "collapsed": false 120 | }, 121 | "source": [ 122 | "This [cheat sheet](http://scikit-learn.org/stable/tutorial/machine_learning_map/index.html) can be used to navigate the maze of estimators available in scikit-learn. While in many of the real-world examples the predictions being made are rather complex, at the most basic level machine-learning tasks tend to fall into one of the following two categories.\n", 123 | "\n", 124 | "- Predicting a *quantity* (i.e., one or more real numbers).\n", 125 | "- Predicting a *category* (i.e., an element of a prescribed finite set).\n", 126 | "\n", 127 | "This dichotomy parallels the conventional (and imprecise) distinction between *continuous* mathematics (like calculus) and *discrete* mathematics (like combinatorics).\n", 128 | "\n", 129 | "Pause to go through the cheat sheet." 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": { 135 | "collapsed": false 136 | }, 137 | "source": [ 138 | "### Demonstration on text data" 139 | ] 140 | }, 141 | { 142 | "cell_type": "markdown", 143 | "metadata": { 144 | "collapsed": false 145 | }, 146 | "source": [ 147 | "Let's try an example which shows off a lot of different estimators at once. Let's first take a look [here](http://scikit-learn.org/stable/auto_examples/text/document_classification_20newsgroups.html#sphx-glr-auto-examples-text-document-classification-20newsgroups-py).\n", 148 | "\n", 149 | "This being Python code, we can try it out here. But better yet, the download is available as a Jupyter notebook, so we can download that notebook *directly* into CoCalc and try it that way! \n", 150 | "\n", 151 | "**Try this now:** \n", 152 | "- Copy the link to the Jupyter notebook at the bottom of the example (which I've also reproduced [here](http://scikit-learn.org/stable/_downloads/document_classification_20newsgroups.ipynb)).\n", 153 | "- Go to the Files view in your project (the folder icon at top left).\n", 154 | "- Hit the \"Create...\" button.\n", 155 | "- Paste the URL into the text box at the top of the page.\n", 156 | "- Hit \"Download from Internet\". You should end up viewing a new Jupyter notebook called `document_classification_20newsgroups.ipynb` with the header \"Classification of text documents using sparse features\".\n", 157 | "- Select \"Run all\" from the \"Cell\" menu.\n", 158 | "- Examine the results!\n", 159 | "\n", 160 | "**Question for you:** Which estimator does the cheat sheet suggest to use in this case? Is this consistent with your experimental result?" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 0, 166 | "metadata": { 167 | "collapsed": false 168 | }, 169 | "outputs": [ 170 | ], 171 | "source": [ 172 | ] 173 | }, 174 | { 175 | "cell_type": "markdown", 176 | "metadata": { 177 | "collapsed": false 178 | }, 179 | "source": [ 180 | "### Clustering" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": { 186 | "collapsed": false 187 | }, 188 | "source": [ 189 | "While I formulated machine learning in terms of predicting a function, another modality is to identify *clusters* among a collection of objects. Let's try an example of this based on the US stock market. Let's first take a look [here](http://scikit-learn.org/stable/auto_examples/applications/plot_stock_market.html#sphx-glr-auto-examples-applications-plot-stock-market-py); then download and run the notebook using [this link](http://scikit-learn.org/stable/_downloads/plot_stock_market.ipynb)." 190 | ] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "metadata": { 195 | "collapsed": false 196 | }, 197 | "source": [ 198 | "**Question for you**: This notebook is attempting to classify stocks based on the extent to which their price movements are correlated. Can you identify what the various clusters have in common?\n" 199 | ] 200 | }, 201 | { 202 | "cell_type": "markdown", 203 | "metadata": { 204 | "collapsed": false 205 | }, 206 | "source": [ 207 | "Here is an other example of clustering in the form of *segmentation* in machine vision. Let's first take a look [here](http://scikit-learn.org/stable/auto_examples/cluster/plot_face_segmentation.html#sphx-glr-auto-examples-cluster-plot-face-segmentation-py), then download the notebook using [this link](http://scikit-learn.org/stable/_downloads/plot_face_segmentation.ipynb)." 208 | ] 209 | }, 210 | { 211 | "cell_type": "markdown", 212 | "metadata": { 213 | "collapsed": false 214 | }, 215 | "source": [ 216 | "Here the goal is to *discretize*, i.e., to take what is effectively a \"continuous\" (or at least high-resolution) input, and break it up into its key features. For some applications it is important to be able to do this *very* efficiently, e.g., autonomous vehicle navigation (\"self-driving cars\")." 217 | ] 218 | }, 219 | { 220 | "cell_type": "markdown", 221 | "metadata": { 222 | "collapsed": false 223 | }, 224 | "source": [ 225 | "### For this course..." 226 | ] 227 | }, 228 | { 229 | "cell_type": "markdown", 230 | "metadata": { 231 | "collapsed": false 232 | }, 233 | "source": [ 234 | "... you will not be expect to do much implementation \"from scratch\" of machine learning. To do this would require some more time to develop the relevant statistics background, and some more intricate programming than what we have done so far.\n", 235 | "\n", 236 | "What I mostly what you to take away here is the underlying taxonomy of ideas, that is, how to separate different machine-learning problems into related categories (you might call this \"meta-clustering\")." 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 0, 242 | "metadata": { 243 | "collapsed": false 244 | }, 245 | "outputs": [ 246 | ], 247 | "source": [ 248 | ] 249 | } 250 | ], 251 | "metadata": { 252 | "kernelspec": { 253 | "display_name": "SageMath 8.1", 254 | "name": "sage-8.1" 255 | }, 256 | "language_info": { 257 | "codemirror_mode": { 258 | "name": "ipython", 259 | "version": 2 260 | }, 261 | "file_extension": ".py", 262 | "mimetype": "text/x-python", 263 | "name": "python", 264 | "nbconvert_exporter": "python", 265 | "pygments_lexer": "ipython2", 266 | "version": "2.7.14" 267 | } 268 | }, 269 | "nbformat": 4, 270 | "nbformat_minor": 0 271 | } -------------------------------------------------------------------------------- /lectures/2018-03-09/2018-03-09.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "## Math 157: Intro to Mathematical Software\n", 10 | "## UC San Diego, winter 2018\n", 11 | "\n", 12 | "## March 9, 2018: Final product redux" 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": { 18 | "collapsed": false 19 | }, 20 | "source": [ 21 | "Administrivia:\n", 22 | "\n", 23 | "- CAPE evaluations are available! They close Monday, March 19 at 8am. Since this course is highly experimental, your feedback will be very helpful for shaping future offerings.\n", 24 | "- Today is the last lecture to be counted for course attendance.\n", 25 | "- HW 6 has been returned.\n", 26 | "- No lectures on Monday, March 12 or Wednesday, March 14. You may wish to use this time to meet your final project group.\n", 27 | "- There will be a lecture on Friday, March 16, on the topic of \"Where to go from here?\"\n", 28 | "- My office hours on Thursday, March 15 are cancelled. All other sections and office hours, including virtual office hours, meet as scheduled next week." 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": { 34 | "collapsed": false 35 | }, 36 | "source": [ 37 | "### Comments on HW 8" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": { 43 | "collapsed": false 44 | }, 45 | "source": [ 46 | "- As announced in the original notebook, this homework will be collected Saturday at 8pm.\n", 47 | "- Problem 2b: correct \"using your answer to 1a\" to \"using your answer to 2a\". You are supposed to produce a function with input and output as in Sage's `crt` function; however, if the input moduli are not coprime, it is okay if you simply return an error (although Sage does handle this case correctly).\n", 48 | "- Problem 3b: see the [Wikipedia article on Moore-Penrose pseudoinverses](https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse), particularly the application to linear least-squares, for the recipe for going from the pseudoinverse to the approximate solution of the linear system.\n", 49 | "- Problem 4c: correct \"modular inverse\" to \"matrix inverse\".\n", 50 | "- Problem 4d: keep in mind that the Hilbert matrix is essentially a worst-case scenario for numerical instability.\n", 51 | "- Problem 5c: beware that Nemo matrices do not support all of the same functionality as Julia matrices (e.g., taking row slices). You might find it convenient to do a list comprehension to convert your Nemo matrix back into a Julia matrix, e.g.,\n", 52 | "```\n", 53 | "H = [[Int(H[i,j]) for j in 1:28] for i in 1:28]\n", 54 | "```\n", 55 | "(Note that I'm also using `Int` to convert Nemo integers into Julia integers.)\n", 56 | "- Problem 6: when interpreting the given example, keep in mind that Python has its own native complex floating-point type. The expression `1j` is Python's native square root of -1." 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": { 62 | "collapsed": false 63 | }, 64 | "source": [ 65 | "Pause for additional questions about HW 8." 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 0, 71 | "metadata": { 72 | "collapsed": false 73 | }, 74 | "outputs": [ 75 | ], 76 | "source": [ 77 | "crt?" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": { 83 | "collapsed": false 84 | }, 85 | "source": [ 86 | "### Comments on the final project\n", 87 | "\n", 88 | "- Both parts will be collected Sunday, March 18 at 8pm.\n", 89 | "- By now, you should have checked the file `final_project_groups.md` in the shared project to find your group and topic assignment, and contacted the rest of your group. (A small number of groups were updated to remove students who have dropped the course.) Also in the shared project, you will find a workspace for your group and a chatroom which you can use to make contact (you are then free to use other channels of communication). If you are unable to reach one of the members of your group by 8pm tonight, please send me an email so I can make a note of this.\n", 90 | "\n", 91 | "Pause for additional questions about Part 2 of the final project." 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": { 97 | "collapsed": false 98 | }, 99 | "source": [ 100 | "### Discussion of part 1 of the final project" 101 | ] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": { 106 | "collapsed": false 107 | }, 108 | "source": [ 109 | "The remainder of this lecture will be devoted to discussion of part 1 of the final project. I have placed a copy of that notebook in this folder so that you can work there for attendance purposes; please switch to that notebook now." 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": 0, 115 | "metadata": { 116 | "collapsed": false 117 | }, 118 | "outputs": [ 119 | ], 120 | "source": [ 121 | ] 122 | } 123 | ], 124 | "metadata": { 125 | "kernelspec": { 126 | "display_name": "SageMath 8.1", 127 | "name": "sage-8.1" 128 | }, 129 | "language_info": { 130 | "codemirror_mode": { 131 | "name": "ipython", 132 | "version": 2 133 | }, 134 | "file_extension": ".py", 135 | "mimetype": "text/x-python", 136 | "name": "python", 137 | "nbconvert_exporter": "python", 138 | "pygments_lexer": "ipython2", 139 | "version": "2.7.14" 140 | } 141 | }, 142 | "nbformat": 4, 143 | "nbformat_minor": 0 144 | } -------------------------------------------------------------------------------- /lectures/2018-03-16/2018-03-16.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "## Math 157: Intro to Mathematical Software\n", 10 | "## UC San Diego, winter 2018\n", 11 | "\n", 12 | "## March 16, 2018: Where to go from here?" 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": { 18 | "collapsed": false 19 | }, 20 | "source": [ 21 | "Administrivia:\n", 22 | "\n", 23 | "- Last call for CAPE evaluations! They close Monday, March 19 at 8am. Since this course is highly experimental, your feedback will be very helpful for shaping future offerings.\n", 24 | "- This lecture is not being counted for course attendance. Relax and listen!\n", 25 | "- HW 7 has been returned. HW 8 and the final project will be returned sometime during exam week.\n", 26 | "- Both parts of the final project will be collected Sunday, March 18 at 8pm.\n", 27 | "- The last virtual office hours session runs today 3-7pm." 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": { 33 | "collapsed": false 34 | }, 35 | "source": [ 36 | "Pause for questions about the final project." 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": { 42 | "collapsed": false 43 | }, 44 | "source": [ 45 | "$\\frac{d^2y}{dt^2}$ $\\partial$ " 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": { 51 | "collapsed": false 52 | }, 53 | "source": [ 54 | "### Core mathematical subjects" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": { 60 | "collapsed": false 61 | }, 62 | "source": [ 63 | "Some of the topics we have seen occur in the following courses, albeit with somewhat less of a computational emphasis.\n", 64 | " - Linear algebra: Math 102\n", 65 | " - Algebra: Math 100ABC, Math 103AB\n", 66 | " - Combinatorics: Math 154, Math 184A (see also CSE 20)\n", 67 | " - Number theory: Math 104ABC\n", 68 | " - Statistics: Math 181AB, Math 185, Math 186 (for bioinformatics)\n", 69 | "\n", 70 | "The Department of Mathematics has just initiated a multi-year process to restructure its course offerings. If there is a particular topic that you wish you had had a chance to study in a math course, let me know and I can pass this on to the committee!" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": { 76 | "collapsed": false 77 | }, 78 | "source": [ 79 | "### Math 152: Applicable Mathematics and Computing" 80 | ] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "metadata": { 85 | "collapsed": false 86 | }, 87 | "source": [ 88 | "Math 152 is a variable-topics course usually centered on the interface between mathematics and computing. This course was itself originally offered as a Math 152 topic. Additional topics in recent years have included game theory, wavelets, and foundations of data science." 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": { 94 | "collapsed": false 95 | }, 96 | "source": [ 97 | "### Math 187A/B: Introduction to Cryptography / Mathematics of Modern Cryptography" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": { 103 | "collapsed": false 104 | }, 105 | "source": [ 106 | "Math 187A provides an introduction to selected mathematical topics as they arise in classical (private-key) cryptography, focusing on key historical examples. Math 187B concentrates on the mathematical ideas and constructions most relevant to modern (public-key) cryptography. Math 187B in particular has an emphasis on computational examples, and is taught using CoCalc; Math 157 is *very good preparation* for that class!" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": { 112 | "collapsed": false 113 | }, 114 | "source": [ 115 | "There is also a cryptography sequence offered in CSE (107A/B). These are somewhat different: the CSE version focuses more on the theoretical basis of cryptography, whereas the math version focuses more on the mathematical techniques that arise along the way." 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": { 121 | "collapsed": false 122 | }, 123 | "source": [ 124 | "### Math 189: Data Analysis and Inference" 125 | ] 126 | }, 127 | { 128 | "cell_type": "markdown", 129 | "metadata": { 130 | "collapsed": false 131 | }, 132 | "source": [ 133 | "The math department offers several courses in traditional statistics, notably Math 181AB. This is not such a course!" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 2, 139 | "metadata": { 140 | "collapsed": false 141 | }, 142 | "outputs": [ 143 | { 144 | "data": { 145 | "text/html": [ 146 | "

Machine Learning

Source: http://xkcd.com/1838
" 147 | ] 148 | }, 149 | "execution_count": 2, 150 | "metadata": { 151 | }, 152 | "output_type": "execute_result" 153 | } 154 | ], 155 | "source": [ 156 | "xkcd(1838)" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "metadata": { 162 | "collapsed": false 163 | }, 164 | "source": [ 165 | "Math 189 investigates modern methods of data science and how they are *and should be* informed by statistics. (This addresses a different sort of \"machine learning fail\" than what I talked about in class.)\n", 166 | "\n", 167 | "> A study of fundamental theoretical background of statistical methods and their applications, with the emphasis on real data analysis. The course covers the\n", 168 | "basic concepts of probability, estimation, testing and regression, all explained on a particular case study developed for it. After this course, you will be able to understand and speak the basic language of statistics and appreciate the strengths and limitations of each method and formulate conclusions accordingly. More importantly you will be able to perform statistical data analysis and formulate your conclusions in a statistical report. Finally, and\n", 169 | "most importantly, you will learn how to use open source software R and Python for an effective data analysis.\n", 170 | "\n", 171 | "I am told that in addition to R and Python, this course now uses Julia as well.\n", 172 | "\n", 173 | "Math 189 is required for the new data science major; see below." 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "metadata": { 179 | "collapsed": false 180 | }, 181 | "source": [ 182 | "### The Halıcıoğlu Data Science Institute" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "metadata": { 188 | "collapsed": false 189 | }, 190 | "source": [ 191 | "The [HDSI](http://hdsi.ucsd.edu/) (sorry, I'm not sure how to pronounce it either) is a new unit on campus devoted to the emerging discipline of *data science*. \n", 192 | "\n", 193 | "> Data has emerged in our society as an essential means by which we can better understand the world around us and vastly improve the way we conduct business, govern and deliver healthcare. Yet, the methods and tools of this emerging field of data science are still in its early stages of development and not yet in practice.\n", 194 | ">\n", 195 | "> [HDSI] is a new academic research unit at UC San Diego with a focused mission. To lay the groundwork for the scientific foundations of this emerging discipline, develop new methods and infrastructure, and train students, faculty and industrial partners to use data science in ways that will allow them to solve some of the world’s most pressing problems.\n", 196 | ">\n", 197 | "> By developing new tools and educating the next generation of data scientists, our goal is to improve our quality of life as digital data continues its integration into the infrastructure of commerce, healthcare, government and education.\n", 198 | "\n", 199 | "The [list of founding faculty](https://hdsi.ucsd.edu/people/founding-faculty.html) includes representatives from Mathematics (which includes a program in statistics), Computer Science and Engineering, Cognitive Science, Economics, Linguistics, SIO, Bioengineering, Medicine, Psychiatry, Visual Arts, ..." 200 | ] 201 | }, 202 | { 203 | "cell_type": "markdown", 204 | "metadata": { 205 | "collapsed": false 206 | }, 207 | "source": [ 208 | "### Undergraduate program in Data Science\n", 209 | "\n", 210 | "One key component of HDSI is the new [undergraduate program in data science](http://dsc.ucsd.edu/) which began in fall 2017. While it incorporates many existing courses in several departments, it also includes several new courses which may be of interest even to students in other majors.\n", 211 | "\n", 212 | "- DSC 10: Principles of Data Science. This course treats the basic of Python and Jupyter notebooks, and a bit of statistics in Python; it therefore is largely redundant with Math 157. If you plan to take a course with DSC 10 as a prerequisite, I would be happy to intervene to get that prerequisite waived.\n", 213 | "- DSC 20: Algorithms, Programming and Data Structures for Data Science I. This is a more advanced Python course.\n", 214 | "- DSC 30: Algorithms, Programming and Data Structures for Data Science II. This course will be taught for the first time in spring 2018.\n", 215 | "- CSE 20 (special section): Data Meets Theory I.\n", 216 | "- CSE 21 (special section): Data Meets Theory II. (These courses will eventually be relabeled under DSC.)" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": 0, 222 | "metadata": { 223 | "collapsed": false 224 | }, 225 | "outputs": [ 226 | ], 227 | "source": [ 228 | ] 229 | } 230 | ], 231 | "metadata": { 232 | "kernelspec": { 233 | "display_name": "SageMath 8.1", 234 | "name": "sage-8.1" 235 | }, 236 | "language_info": { 237 | "codemirror_mode": { 238 | "name": "ipython", 239 | "version": 2 240 | }, 241 | "file_extension": ".py", 242 | "mimetype": "text/x-python", 243 | "name": "python", 244 | "nbconvert_exporter": "python", 245 | "pygments_lexer": "ipython2", 246 | "version": "2.7.14" 247 | } 248 | }, 249 | "nbformat": 4, 250 | "nbformat_minor": 0 251 | } -------------------------------------------------------------------------------- /takeaway.md: -------------------------------------------------------------------------------- 1 | 2 | Possible changes for next time: 3 | - At the moment, most students come having seen C and/or Java in one of the basic CSE courses. 4 | - So maybe we can just formalize this; make them required and build the course around that. 5 | - Or, make the new DSC10 a formal prerequisite, and shorten the Python unit. 6 | - Hybrid: require one of CSE5A (C), CSE7 (Matlab), CSE8A (Java), or DSC10 (Python). Corequisite should be fine too. 7 | - More structured version of the week 1 survey. (Use Google Docs to get a spreadsheet.) 8 | - For programming languages (C/C++, Java, Matlab, Python): ask to choose between 9 | - never used before 10 | - seen it used in a class that was primarily about something else (e.g., Matlab in Math 18) 11 | - had a class primarily based on this 12 | - familiar with it beyond the level of a class. 13 | - Consider dropping the 20D prerequisite. It was mostly there as a holdover from 152, and also to keep the enrollment under control; but I waived it several times anyway. 14 | - Alternative: make use of it by adapting the 20D MATLAB material. 15 | - Deploy an instrument to assess learning gains (e.g., SALG). This will require defining more clearly the educational goals of the course. 16 | - Expose students to some of the conceptual difficulties in translating abstract mathematics into concrete computation. 17 | - Teach students not just about individual software systems, but also the meta-skill of mastering a new software system from scratch. 18 | - Provide a pedagogical laboratory for the math department, in which technological innovations can be tested on a small scale before being considered for wider deployment. 19 | - Make a formal list of conceptual topics to be treated. 20 | - Recursive versus nonrecursive functions 21 | - Numerical (in)stability in linear algebra 22 | - Modular exponentiation using repeated squaring 23 | - Intermediate complexity implosion in linear algebra over Q 24 | - Formalize the meta structure of a typical problem set. 25 | - First 2 problems are simply testing recall of lecture. 26 | - Next 2 problems are further exploration of the software. 27 | - Last 2 problems are exploration of conceptual issues. 28 | - For later in the course, when the problems get harder, maybe give only 5 problems instead of 6. 29 | - See about getting CoCalc to provide some tools for interactivity in lecture (a la iClicker). 30 | - Introduce pandas in the Python unit, since it is pretty easy and can then be used later for examples and exercises. (Possible downside: its syntax is not consistent with the rest of Python.) 31 | - Fill in more details in the graph theory unit, perhaps expanding it to 3 lectures. 32 | - Find a way for the course grader not to appear as a collaborator on student projects (reported to CoCalc). 33 | - Additional technologies to look into (may not yet be supported by CoCalc): 34 | - RISE 35 | - nbgrader 36 | - tutormagic 37 | - Restructure homework assigments: 38 | - Given the nature of programming assignments, one per week may be too many. Maybe shift to biweekly assignments due in weeks 2, 4, 6, 8, 10. 39 | - In the off weeks, do some sort of in-class assessment, like a "concept quiz". 40 | - Define the course focus more narrowly. 41 | - Rename the course to "Python for Mathematics". 42 | - Edit the course syllabus to focus more specifically on mathematical computation. 43 | - Specifically exclude data science, statistics, and machine learning, as these are covered in Math 189. 44 | - Consider using Piazza in addition to, or in conjunction with, the chat room. -------------------------------------------------------------------------------- /troubleshooting.md: -------------------------------------------------------------------------------- 1 | # Troubleshooting 2 | 3 | - Has the student created a CoCalc account? 4 | - If not, they can go directly to cocalc.com and create one. The email invitation is not necessary. 5 | - Students are strongly encouraged to use their UCSD email address on CoCalc. This makes it easier to avoid ambiguity: CoCalc's namespace is global, and it is entirely possible for multiple users to have the same first and last name. 6 | - Does the student have a course project? 7 | - Go to the course file in the master project, click the "Students" tab, and make sure that the student is listed. If not, use the text box at top right to add them. 8 | - If they are already listed but can't see their course project, open that project and (from its "Settings" tab) add the student as a collaborator. 9 | - Make sure that the student's course project has the correct upgrades: member hosting and Internet access should both be enabled. If not, ask me to fix this. 10 | - Note that adding a student to the course does not automatically give them all previous handouts. You may need to push those out manually. 11 | - Does the student have the shared project? 12 | - Open the shared project and (from its "Settings" tab) add the student as a collaborator. 13 | - Is the student missing a specific lecture or assignment? 14 | - You can push it out to them individually from within the course file. If you don't see the student there, add them to the course. 15 | - Beware that pushing a handout to all students often does not completely succeed the first time around. Check the outcome after CoCalc claims to have completed the operation! 16 | - Is a student's project behaving erratically? 17 | - In a notebook, try restarting the kernel. (Keep an eye on memory usage!) 18 | - Try closing and reopening the file in question. 19 | - Try restarting a student's project (under Settings). 20 | - Make sure that the project settings show the correct upgrades: member hosting and Internet access should both be enabled. If not, ask me to fix this. 21 | - Does a student's project fail to open or restart? 22 | - One possibility is a disk overrun. Ask me to fix this by allocating more disk space. 23 | - Is a shared chat room behaving erratically? 24 | - Try archiving the chat and creating a new room. 25 | - If all else fails, open a support ticket from within a project (click "Help") to contact the CoCalc staff. 26 | --------------------------------------------------------------------------------