Getting started with Sage in Number Theory

  • Ways you can use Sage
    • There is a free tier on CoCalc, a web-based math sofware server (use Sage notebook or Jupyter)
    • If you have a CU Identikey, there’s sage.colorado.edu (out of date: old Sage notebook; Sage version 8.3)
    • There’s the single cell Sage server (timeout limit)
    • I have a multi-cell version of the single cell server here.
  • Ways to figure out how to do something in Sage
    • search “python if statements” etc. — programming questions are Python not Sage
    • search “sagemath p-adics” etc. — keyword “sagemath” is best
    • ask ChatGPT or another AI (it’s quite good at this)
    • type a function with “?” after and documentation pops up
    • tab complete works in Jupyter and Sage notebooks
    • on an object, ex. myfield, you put a dot and then hit tab to see all available functions
  • My Sage Math Intro Worksheets
  • Tutorials on Sage in general
  • Tutorials on Number Theory in particular
  • Graphical things with Sage
  • Learn Sage By Doing A Project:
    • Graph the Farey subdivision or SL2 fundamental domains
      • for geodesics, one approach is to use circle() and then obscure the part below the x-axis with a white rect() z-positioned above everything
      • the Farey subdivision is particularly pleasing in that there’s a simple condition for which circles to draw; there is for SL2 also but it’s harder to discover
      • another approach is to iterate through SL2 via generators like S,T or R,L
      • plot the reduction of a quadratic form to the fundamental region
    • Graph elliptic curves over finite fields
      • you can just define an elliptic curve over a finite field and call plot() but it isn’t too satisfying
      • you might like matrix_plot() or scatter_plot() or another approach…
      • one thing I thought was fun was to plot the level sets of f(x) – x^3 – ax – b, not just the zero level set
      • what would it look like to plot varying coefficients?
    • Implement elliptic curve factoring
      • compare with Sage’s in-built factoring (which is actually PARI/gp)
      • what’s different about elliptic curves mod N composite than p prime?  could try graphing or doing multiplication tables on small examples
      • you might look up more about which methods are best in which regimes
    • Explore the distribution of primitive roots (pairs (a,p) for which a is a primitive root for p) — make conjectures!
      • Collect statistics or create a graphical visualization
    • Pythagorean triples
      • I just learned a cool theorem relating the Legendre symbols of a,b,c modulo p when $c^2 = a^2 + b^2$.  Can you discover it?
    • Prime counting function
      • recreate Gauss’ experiments on counting primes
      • how can you best compare data to a conjectured growth function?  try logarithmic plotting (plot_loglog(), plot_semilogx() etc)
      • what about primes that are in a single congruence class?  primes with a given primitive root?  primes that don’t include the digit 1?  etc.  conjecture and then compute
      • prime_pi() and li()
    • Continued fractions of rationals
      • Create a nice visualization or collection of data on the continued fraction expansions of rationals (maybe those of fixed denominator N, or another set you like), try to interpret it
      • continued_fraction()
    • p-adic computation
      • see Qp() in Sage & intro to p-adics
      • Implement Newton’s method for regular metric in R
      • modify this to use the p-adic metric — this is Hensel’s lemma!  do examples
    • Visualize p-adics
      • see Qp() in Sage & intro to p-adics
      • Try graphing the p-adic expansions of the positive integers as coloured stacks representing the coefficients (i.e. integers on y axis say, then in the corresponding row, colour each position according to the coefficient of the series as you head right, might find matrix_plot() helpful) — why does it look the way it looks?
      • Try graphing the p-adic metric |x-y| at position (x,y) as a colour (on integers x,y) — again matrix_plot() is nice here — why does it look the way it looks?
      • can you visualize p-adic addition or multiplication?
    • Investigate the topograph for non-integers
      • You could create something that draws topographs, but that is probably a lot of work
      • Another way to play with topographs would be to label the regions by strings of RL (or just binary strings) indicating their positions away from an initial position, and then just use these strings (no graphical interaction) — you’d need to make little functions for “stepping left” and “stepping right” and seeing what new values you have on edge and adjacent regions
      • Maybe you could create a function that walks to the river and then along the river, spitting out the sights it sees on the shores as it goes
      • Then you could consider non-integer topographs (since all the formulas are just formulas that work in any ring), and see what rivers look like
      • What about other rings?  maybe p-adics?