{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"drawing\"\n", "

Experimental Mathematics Using SageMath — AIMS-ZA-2024-25

\n", "\n", "\n", "## Instructors: \n", "\n", "* **Evans Ocansey**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "****\n", "\n", "\n", "< [3. Starting to program](ems_2020_day_03_starting_to_program.ipynb)|[Table of contents](ems_2020_table_of_contents.ipynb) | [5. Sum Of Squares And Plotting](ems_2020_day_05_sum_of_squares_and_plotting.iynb)>\n", "\n", "\n", "****" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "\n", "In experimental science, sometimes you have to rethink your problem.  Perhaps a different experiment is needed, perhaps a different model, or something else. Likewise, in experimental mathematics, sometimes it is necessary to use a different approach.  We will look at one such approach today; we will turn questions about numbers into questions about geometry. Also, I know that some of you are excited to use more Sage for your computation outside of this class, so we will take a little time looking at resources.\n", "\n", "\n", "## Reviewing the Problem\n", "\n", "\n", "Our motivational problem is the following: Given positive integers $a$ and $b$, what numbers $n$ can be written in the form $ax+by$, where $x,y\\geq 0, \\in \\mathbb{Z}$?\n", "\n", "It has already led to several related questions.  That is exploration!\n", "\n", "\n", "Is there a number $N$ for which all $n\\geq N$ can be written $ax+by$, but $N-1$ cannot be?  (We called this the _conductor_.)\n", "\n", "If there is such a number, can we find a formula or some other means of computing it?\n", "How _many_ numbers can be written $ax+by$, if we know $a,b$?\n", "Remember, you can definitely try to organize your data.  Did anyone get these results?" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
Frobenius NumberConductor# Not Writable
None
\n", "
" ], "text/plain": [ "+---------+------------------+-----------+\n", "| $(a,b)$ | Frobenius Number | Conductor |\n", "+=========+==================+===========+\n", "| (2, 3) | 1 | 2 |\n", "+---------+------------------+-----------+\n", "| (3, 4) | 5 | 6 |\n", "+---------+------------------+-----------+\n", "| (3, 6) | +Infinity | None |\n", "+---------+------------------+-----------+\n", "| (5, 7) | 23 | 24 |\n", "+---------+------------------+-----------+\n", "| (7, 11) | 59 | 60 |\n", "+---------+------------------+-----------+\n", "| (9, 11) | 79 | 80 |\n", "+---------+------------------+-----------+" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L = [[(2,3), 1, 2], [(3, 4), 5, 6], [(3,6), oo, 'None'], [(5,7), 23, 24], [(7,11), 59, 60], [(9,11), 79, 80] ]\n", "\n", "table(L,header_row=[\"$(a,b)$\",'Frobenius Number', 'Conductor', '# Not Writable'], frame=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Let us work out by counting the numbers that are not writable. Let's start with $a=2$, $b=3$ and $a=3$, $b=4$.

" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

A Useful Fact

\n", "

Recall that we discussed a few facts about integers earlier.

\n", "

Fact: If $a$, $b>0$ are integers then we can write $a=qb+r$ with $0\\leq r\n", "

Fact: In this situation, $\\gcd(a,b)=\\gcd(b,r)$.

\n", "

Here is another useful fact for our situation.  Many of you already know this.

\n", "

Fact: For a given $n\\in \\mathbb{Z}$, the equation $ax+by=n$ has a solution in integers if and only if $\\gcd(a,b) \\mid n$.

\n", "

That is, you can't even write $ax+by=n$ if the greatest common divisor of $a$ and $b$ doesn't divide $n$.  This was studied by the Greeks, known by Aryabhata in the Indian Middle Ages, and rediscovered by Bachet de Méziriac about 1600.

\n", "

Implication For Us: If $a$ and $b$ have a common divisor bigger than 1, there cannot be a conductor.

\n", "

We already saw an example in class. I want you to think about why this might be.

\n", "

Rethinking the Problem

\n", "

I can prove the facts above.  But just proving things are true and using them isn't enough.  Why is it true, intuitively?  I believe the right place to do this is in geometry.

" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Widget Javascript not detected. It may not be installed or enabled properly. Reconnecting the current kernel may help.\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9e2e4e89671b4325893804a3fa80e10c" } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "@interact\n", "def _(a = slider(1, 20, 1, 3), \\\n", " b = slider(1, 20, 1, 4), \\\n", " c = slider(1, 30, 1, 6), \\\n", " viewsize = slider(5, 30, 1, 5)):\n", " \n", " # plot the equation of the line y = - (a/b)*x + c/b.\n", " \n", " p = plot(-(a/b) * x + c/b, (x, -1, viewsize), plot_points = 200)\n", " \n", " # integer coordiantes for the lattice \n", " \n", " lattice_pts = [[i,j] for i in [-1..viewsize] for j in [-viewsize..viewsize]]\n", " \n", " # plot integer lattice with pointsize set to 20 and rgbcolor set to (0, 0, 0).\n", " \n", " plot_lattice_pts = points(lattice_pts, rgbcolor = (0, 0, 0), pointsize = 20)\n", " \n", " # Check if gcd(a, b) divides c. \n", " \n", " if mod(c, gcd(a, b)) == 0:\n", " \n", " # Get integers coordinates x and y in lattice_pts that lies on the line y = - (a/b)*x + c/b. \n", " # That is, the integer coordinates that satisfy the equation a * x + b * y = c.\n", " \n", " line_pts = [coords for coords in lattice_pts if a * coords[0] + b * coords[1] == c]\n", " \n", " # Check if line_pts is empty. In other words, there are no integer coordinates x and y in lattice_pts \n", " # that lie on the line y = - (a/b)*x + c/b or satisfies the equation a * x + b * y = c. Note that\n", " # in general, this does not mean that there are no solution since there might exist integer \n", " # coordinates which are not contained in lattice_pts. \n", " \n", " if line_pts == []:\n", " \n", " # Define an empty Graphics object.\n", " \n", " plot_line_pts = Graphics()\n", " \n", " else:\n", " \n", " # plot the integer coordinates x and y in lattice_pts that lie on the line y = - (a/b)*x + c/b or \n", " # satisfies the equation a * x + b * y = c.\n", " \n", " plot_line_pts = points(line_pts, rgbcolor = (0, 0, 1), pointsize = 20)\n", " \n", " # Print sentence indicating the set of solution, (integer coordinates) satisfying the equation\n", " # a * x + b * y = c.\n", " \n", " pretty_print(html(r\"Showing solutions to $%s\\,x + %s\\,y = %s$ in this viewing window\" \\\n", " %(str(a), str(b), str(c))))\n", " \n", " # Combine the three plot objects together. \n", " \n", " show(p + plot_lattice_pts + plot_line_pts, figsize=[5, 5], xmin = -1, xmax = viewsize, \\\n", " ymin = -1, ymax = viewsize)\n", " \n", " # If gcd(a, b) does not divide c.\n", " \n", " else:\n", " \n", " # Print a sentence stating the gcd(a,b) does not divide c.\n", " \n", " pretty_print(html(r\"The gcd of $%s$ and $%s$ is $%s$, which does not divide $%s$,\"\\\n", " %(str(a), str(b), str(gcd(a,b)), str(c))))\n", " \n", " # Print a sentence stating that there are no integer solutions satisfying the equation \n", " \n", " pretty_print(html(r\"so there are no non-negative integer solutions to $%s\\,x + %s\\,y = %s$\"\\\n", " %(str(a), str(b), str(c))))\n", " \n", " # Combine plot objects.\n", " \n", " show(p + plot_lattice_pts, figsize = [5, 5], xmin = -1, xmax = viewsize, ymin = -1, ymax = viewsize)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

(The little gray dots in the graph above are called the integer lattice.  You may treat this as a definition.  There are many lattices, but only one which is basically all the intersections of $y=m,x=n$ for all integers $m,n$.  So for instance $(-2,3)$ is probably visible; however, note that $(-1,1/2)$ is not a little dot, because it doesn't have integer values.)

\n", "

Since $ax+by=c$ may be thought of as a line (in fact, the line $$y=-\\frac{a}{b}x+\\frac{c}{b}$$ with slope $-\\frac{a}{b}$), we now have a completely different interpretation of this very basic number theory question (the \"linear Diophantine equation\").  It is simply asking, \"When (for what $a$, $b$, $c$ combinations) does the line hit this lattice?  If it does, can you tell me all intersections?\"   If you play around with the sliders you will quickly see that things work out just as promised in the theorems. 

\n", "

Now let's connect this to some of the conductor questions. Given positive integers $a$ and $b$:

\n", "\n", "
By the way, this second question is very closely related to an extremely applied area, integer programming.
" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Solutions to :" ], "text/plain": [ "Solutions to :" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Number of nonnegative lattice points = 1" ], "text/plain": [ "Number of nonnegative lattice points = 1" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAecAAAHnCAYAAACCDZVUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAPYQAAD2EBqD+naQAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAIABJREFUeJzt3Xt8VNW9/vFnh0uCkBmkAgYSkHIECbSAMJKEu2AKLVSUFu8EC3rgF1BKtS1qq+hp44VaBAeVejRFS/ESbgpeQEjCRXvUEj1WodhiESQUpc4A1VDT/ftjHakUIgQys9bMfN6v17wkQzLzZIg87D37u5bn+74vAADgjDTbAQAAwJEoZwAAHEM5AwDgGMoZAADHUM4AADiGcgYAwDGUMwAAjqGcAQBwDOUMAIBjKGcAABxDOQMA4JiEKGff9xWNRsUy4ACAVJAQ5bx//34Fg0Ht37/fdhQAAGIuIcoZAIBUQjkDAOAYyhkAAMdQzgAAOCbm5VxSUqJQKKTMzEy1adNGY8aM0datW2P9tAAAJKyYl3NFRYWKi4v1yiuvaPXq1frss89UWFiogwcPxvqpAQBISJ4f5+HhvXv3qk2bNqqoqNCgQYNO6GveeOMN9erVS5FIRIFAIMYJgdirra3VW2+9pZ49e9qOAjSY6upq/fOf/1S7du1sR0l4cX/PORKJSJJatWpV5+fU1NQoGo0qGo3qvffeU9++feMVD4iL2bNnq1evXnr66adtRwEaTL9+/dSrVy/bMZJC43g+me/7mjFjhgYMGKAePXrU+XklJSWaNWtWHJ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2VLq39+UNQAkK8oZCSM7W1q/XurVSxo+3KzNDQDJiHJGQgkGpeefl8aMkb7zHen++20nAoCGV+9RKsC29HRp0SKpXTtp2jRzkdjPf262owSAZEA5IyGlpUn33mtOdf/gB6agH37YLGICAImOckZCmzHDHEEXFUnV1WYuOjPTdioAODW854yEd+ml5n3o3/1OGjzYlDQAJDLKGUlh6FBzJfeePWYWeutW24kA4ORRzkgaX/+6mYVu1szMQr/yiu1EAHByKGcklQ4dzAIl3bpJ558vrVhhOxEA1B/ljKTTqpVZj3vkSOmii6SHHrKdCADqh3JGUsrIkJ58UpoyRZo8WfrpTyX3918DAINRKiStRo2kefOknBzpxz82s9APPig1aWI7GQB8OafLORwOKxwOq7a21nYUJCjPk370IzML/b3vSbt3myPqFi1sJwOAunm+7/7Jvmg0qmAwqEgkokAgYDsOEtTq1dLFF0vnnCOtXCm1aWM7EQAcG+85I2VccIFUWSnt3CkVFEjvvms7EQAcG+WMlNK7t7Rpk3k/uqBAevVV24kA4GiUM1JOp07Sxo1S587SkCHSqlW2EwHAkShnpKQzzpBeekkaPlz69relRx6xnQgA/oVyRso67TSzi9WkSdLEidIddzALDcANTo9SAbHWuLH0wANmX+if/MRcLBYOm/sBwBb+CkLK8zzplluk9u2la64xs9CLF5sjawCwgdPawP+5+mrpmWfMe9HDhkkffmg7EYBURTkDXzBypFReLv3pT2bbye3bbScCkIooZ+DfhEJmX+jaWik/X/r9720nApBqKGfgGDp3NouV5ORIgwdLL75oOxGAVEI5A3Vo00Zat04aOFD61rekxx6znQhAqqCcgS/RooW0fLk0fry53XUXs9AAYo9RKuA4mjSRHn7YzEL/+MdmFnrOHLM+NwDEAuUMnADPk2bNMrPQU6ZIH3wgPf641KyZ7WQAkhGntYF6uPZaaelS6bnnpMJCad8+24kAJCPKGainb3/bLFTyzjvSgAHSjh22EwFINpQzcBLy8822k598Yn795pu2EwFIJpQzcJK6djWLlbRta8at1q61nQhAsqCcgVNw5plSRYXUr580YoTZMAMATpXT5RwOh5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b/eaymg0qmAwaDMCAAAxFYlEFKjHQvTWy/l4R86S9PLLL2vcuHF6++231b59+1N6vlAopFdfffWUHiOZHycajSonJ0fvv/9+vX6QYpkpGR9n37596tSpU4O8zg2VKdaP88kn0sSJ0qpV0pw55oKxeORx8We6IR/LpcfZsmWL+vXr59Rr7crj1PfI2fppbc/zjvuHmJ+fL8l8c6f6B96oUaMG+cswWR/nc4FAgNc6xo8jNczrLLn3vR3rcQIBafly6brrzO5W+/ZJt95qrvCOdR7z/O78TDfkY7n0OOecc44kt15r1x7nRFkv53grLi7mceLEte/NtcdpSK59b3U9TqNG0v33m1nom26Sdu6UHnxQalzH30SuvdYNmSdR/sxsce37ivfrY/209onYuXPn4dNS2dnZtuMktc+vAajv+yOoH15n6de/liZNkr7xDemJJ6TmzWPzPLzW8cNr3XASYpQqPT39iP8idtLT03XrrbfyWscYr7NUVCQ9+6xUXi6df760d29snofXOn54rRtOQhw5868xIHm9/rr0zW+a96Sff17q3Nl2IsC+hDhyBpC8+vSRXn7ZXBhWUCC99prtRIB9lDMA6776VWnjRrNoyZAh5ggaSGUpd7U2ADe1bi298ortFIAbEuI9588XKqnvEDcAAIkoIU5rf75QCcXcMObPn69OnTopIyNDffr00fr16+v83NLSUnmed9Tt008/jWPi5FJZWanRo0erXbt28jxPy5Ytsx0podX39SwvLz/mz/SWLVvilDj5lJSUKBQKKTMzU23atNGYMWO0detW27ESWkKUMxrOE088oenTp+vmm2/W5s2bNXDgQI0cOVI7duyo82sCgYB27959xC0jIyOOqZPLwYMH1bNnT91///22oySFk309t27desTP9Nlnnx2jhMmvoqJCxcXFeuWVV7R69Wp99tlnKiws1MGDB21HS1gJcVobDadfv34699xz9cADDxy+r1u3bhozZoxKSkqO+vzS0lJNnz5dH3/8cTxjpgzP87R06VKNGTPGdpSkcCKvZ3l5uYYOHaq//e1vatmyZRzTpY69e/eqTZs2qqio0KBBg2zHSUgcOaeQQ4cO6fXXX1dhYeER9xcWFmrTpk11ft2BAwfUsWNHZWdna9SoUdq8eXOsowIx17t3b2VlZWnYsGFat26d7ThJJRKJSJJatWplOUniopxTyIcffqja2lq1bdv2iPvbtm2r6urqY37NOeeco9LSUq1YsUK//e1vlZGRof79+2vbtm3xiAw0uKysLC1YsEBlZWVasmSJunbtqmHDhqmystJ2tKTg+75mzJihAQMGqEePHrbjJCxGqVLQv19Y5/t+nRfb5eXlKS8v7/DH/fv317nnnqt58+Zp7ty5Mc0JxELXrl3VtWvXwx/n5+fr/fff1+zZszkF2wCmTp2qN998Uxs2bLAdJaFx5JxCzjjjDDVq1Oioo+S//vWvRx1N1yUtLU2hUIgjZySVvLw8fqYbwLRp07RixQqtW7eOTYpOEeWcQpo2bao+ffpo9erVR9y/evVqFRQUnNBj+L6vqqoqZWVlxSIiYMXmzZv5mT4Fvu9r6tSpWrJkidauXatOnTrZjpTwOK2dYmbMmKGrrrpKffv2VX5+vhYsWKAdO3Zo8uTJkqTx48erffv2h6/cnjVrlvLy8nT22WcrGo1q7ty5qqqqUjgctvltJLQDBw7o3XffPfzx9u3bVVVVpVatWqlDhw4WkyWm472eM2fO1K5du7Rw4UJJ0pw5c3TWWWepe/fuOnTokB5//HGVlZWprKzM1reQ8IqLi7Vo0SItX75cmZmZh8/OBYNBNWvWzHK6BOUj5YTDYb9jx45+06ZN/XPPPdevqKg4/HuDBw/2i4qKDn88ffp0v0OHDn7Tpk391q1b+4WFhf6mTZsspE4e69at8yUddfvi644Td7zXs6ioyB88ePDhz7/rrrv8zp07+xkZGf7pp5/uDxgwwF+5cqWd8EniWK+/JP/RRx+1HS1hMecMAIBjeM8ZAADHUM4AADiGcgYAwDGUMwAAjqGcAQBwDOUMAIBjKGcAABxDOQMA4BjKGQAAx1DOAAA4hnIGAMAxlDMAAI75/+wXNR4uPMnaAAAAAElFTkSuQmCC\n", "text/plain": [ "Graphics object consisting of 3 graphics primitives" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "@interact\n", "def _(a = slider(1, 20, 1, 3), b = slider(1, 20, 1, 4), c = slider(1, 40, 1, 4), viewsize = slider(5, 30, 1, 5), positive_only = False):\n", " \n", " ym = c/b + 1 # ym is the value of ymax\n", " xm = c/a + 1 # xm is the value of xmax\n", " \n", " # plot the equation of the line `y = - (a/b)*x + c/b`.\n", " \n", " p = plot(-(a/b) * x + c/b, -1, xm, plot_points = 200)\n", " \n", " # integer coordiantes for the lattice\n", " \n", " lattice_pts = [[i,j] for i in [0..xm] for j in [0..ym]]\n", " \n", " # plot integer lattice\n", " \n", " plot_lattice_pts = points(lattice_pts, rgbcolor = (0, 0, 0), pointsize = 2)\n", " \n", " # Check if gcd(a, b) divides c.\n", " \n", " if mod(c, gcd(a, b)) == 0:\n", " \n", " # If the parameter positive_only is True. That is, find positive x and y such that `a*x + b*y = c` holds.\n", " \n", " if positive_only:\n", " \n", " # Get positive integers x and y in lattice_pts that lies on the line `y = - (a/b)*x + c/b`. \n", " # These are positive integers that satisfy the equation `a * x + b * y = c`.\n", " \n", " line_pts = [coords for coords in lattice_pts if (coords[0] > 0) and (coords[1] > 0) and (a * coords[0] + b * coords[1] == c)]\n", " \n", " # If the parameter positive_only is False. That is, find non-negative x and y such that `a*x + b*y = c` holds.\n", " \n", " else:\n", " \n", " # Get non-negative integers x and y in lattice_pts that lies on the line `y = - (a/b)*x + c/b`. \n", " # These are non-negative integers that satisfy the equation a * x + b * y = c.\n", " \n", " line_pts = [coords for coords in lattice_pts if (coords[0] >= 0) and (coords[1] >= 0) and (a * coords[0] + b * coords[1] == c)]\n", " \n", " # Check if line_pts is empty. In other words, there are no non-negative integer points x and y in lattice_pts \n", " # that lies on the line y = - (a/b)*x + c/b or satisfies the equation a * x + b * y = c. Note that in general,\n", " # this in effect does not mean that there are no solution since there might exist integer pairs which are not \n", " # in lattice_pts.\n", " \n", " if len(line_pts) == 0:\n", " \n", " # Print solutions\n", " \n", " pretty_print(html('Solutions to $%s\\,x + %s\\,y = %s$:' %(str(a), str(b), str(c))))\n", " \n", " # If the parameter positive_only is True\n", " \n", " if positive_only:\n", " \n", " # Print no positive solution. \n", " \n", " pretty_print(html('No positive lattice points at all!'))\n", " \n", " # If the parameter positive_only is False\n", " \n", " else:\n", " \n", " # Print sentence \n", " \n", " pretty_print(html('No nonnegative lattice points at all!'))\n", " \n", " # Combine the two plot objects together.\n", " \n", " show(p + plot_lattice_pts, figsize = [5,5], xmin = 0, xmax = xm, ymin = 0, ymax = ym)\n", " \n", " else:\n", " \n", " # plot the integer points x and y in lattice_pts that lies on the line y = - (a/b)*x + c/b or \n", " # satisfies the equation a * x + b * y = c.\n", " \n", " plot_line_pts = points(line_pts, rgbcolor = (0, 0, 1), pointsize = 20)\n", " \n", " pretty_print(html('Solutions to $%s\\,x + %s\\,y = %s$:' %(str(a), str(b), str(c))))\n", " \n", " # If the parameter positive_only is True \n", " \n", " if positive_only:\n", " \n", " # Print sentence with positive integer solutions x and y in lattice_pts.\n", " \n", " pretty_print(html('Number of positive lattice points = ' + str(len(line_pts))))\n", " \n", " # If the parameter positive_only is False\n", " \n", " else:\n", " \n", " # Print sentence with non-negative integer solutions x and y in lattice_pts.\n", " \n", " pretty_print(html('Number of nonnegative lattice points = ' + str(len(line_pts))))\n", " \n", " # Combine the three plot objects together.\n", " \n", " show(p + plot_lattice_pts + plot_line_pts, figsize = [5,5], xmin = 0, xmax = xm, ymin = 0, ymax = ym)\n", " \n", " # If gcd(a, b) does not divide c.\n", " \n", " else:\n", " \n", " # Print solutions.\n", " \n", " pretty_print(html('Solutions to $%s\\,x + %s\\,y = %s$:' %(str(a), str(b), str(c))))\n", " \n", " # If the parameter positive_only is True\n", " \n", " if positive_only:\n", " \n", " # Print no positive integer solutions.\n", " \n", " pretty_print(html('No positive lattice points at all!'))\n", " \n", " else:\n", " \n", " # Print no non-negative integer solutions.\n", " \n", " pretty_print(html('No nonnegative lattice points at all!'))\n", " \n", " # Combine the two plot objects together.\n", " \n", " show(p + plot_lattice_pts, figsize = [5,5], xmin = 0, xmax = xm, ymin = 0, ymax = ym)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Let's explore this - even in cases where the conductor is not very interesting.  How many such points are there in the following cases?

\n", "\n", "

Again, you should be able to start exploring and experimenting.  Naturally, in this case I don't only expect you to use my graphic, which is a big challenge for you to program right now.  Try instead to write your own program to explore this question.

" ] } ], "metadata": { "kernelspec": { "display_name": "SageMath 10.4", "language": "sage", "name": "sagemath" }, "language": "python", "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.2" }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }