Instantly share code, notes, and snippets.

# Tom Harris tkmharris

Last active October 13, 2018 21:13
Calculate the Hurwitz-Radon number of a positive integer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 def hurwitz_radon(n): '''Takes a positve integer n; returns the Hurwitz-Radon number p(n). p(n) defined as follows: Let n = (2^v)m with m odd and write v = 4a + b, 0<= b < 4. Then p(n) = 8a + 2^b.''' if not isinstance(n, int): raise TypeError("hurwitz_radon only defined for positive integers") if n <= 0: raise ValueError("hurwitz_radon only defined for positive integers") # helper to get largest power of 2 divinding n
Last active October 14, 2018 15:12
Get integer solutions of the Mordell equation y^2 = x^3 - d for certain special values of d.
View mordell.sage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 ## Mordell's equation ''' Get integer solutions of the Mordell equation y^2 = x^3 - d for certain special values of d. See mordell.txt for details. ''' def mordell_test(d, x,y):
Created October 17, 2018 18:45
Haskell function for looking at next prime equivalence class bias, as described in https://arxiv.org/abs/1603.03720
View next_prime_bias.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 {-- We provide a function 'nextPrimeBias' that when called as nextPrimeBias a b n r returns the probability that, among the first r primes, a prime that is equivalent to a mod n is followed by a prime that is equivalent to b mod n. We see that these probabilities are not evenly distributed among equivalence classes, as described in https://arxiv.org/abs/1603.03720 : nextPrimeBias 7 1 10 100000 = 0.25736558 nextPrimeBias 7 3 10 100000 = 0.27695382 nextPrimeBias 7 7 10 100000 = 0.144993 nextPrimeBias 7 9 10 100000 = 0.3206876
Last active May 26, 2021 20:38
Short Haskell implementation of the Akiyama-Tanigawa algorithm for computing Bernoulli numbers.
View akiyama-tanigawa-bernoulli.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 {-- Implementation of the Akiyama-Tanigawa algorithm for computing Bernoulli numbers. --} {-- Implement the algorithm by: 1. Begin with list of reciprocals of positive integers. 2. Write function to get next row and iteratie it to get list of lists. 3. Take the head of each list in the list to get Bernoulli nums. Everything evaluates lazily, so we can do this nicely with infinite lists. See tkmh.space/flotsam/haskell-akiyama-tanigawa for more.--}
Last active December 24, 2019 16:37
Functions for creating images of hydrogen orbitals
View hydrogen-orbitals.ipynb
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Last active May 15, 2021 14:33
Quick implementation of the two trees for partitions discussed here: https://11011110.github.io/blog/2005/08/07/two-trees-on.html
View partitionTrees.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 """ Quick implementation of the two trees for partitions discussed here: https://11011110.github.io/blog/2005/08/07/two-trees-on.html """ from treelib import Node, Tree # partition class class InvalidPartitionError(Exception):
Last active May 24, 2021 22:53
Simulate a game of Dreidel
View dreidel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # coding: utf8 import random class OutOfTimeError(Exception): """Raised when game passes maximum number of turns""" pass class Player:
Last active June 11, 2021 22:14
Code for OEIS sequence A345209
View a345209.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 """ Function to calculate terms of OEIS sequence A345209. """ from sympy import primefactors def a345209(n): """ Calculate OEIS entry A345209(n) (Number of Petrie polygons on regular triangular map corresponding to the principal congruence subgroup Γ(n) of the mmodular group)
Last active June 11, 2021 23:04
Code for OEIS sequence 345225
View a345225.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 """ Function to calculate terms of OEIS sequence A345225. """ def a345225(n): """ Calculate OEIS entry A345225(n) (Orders of 2-primary subgroups of K_n(Z), the algebraic K-theory of the integers.) n: int, >=0
Last active June 13, 2021 20:23
Code for OEIS sequence A345262
View a345262.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 """ Function to calculate terms of the order of the image of the J-homomorphism. """ from sympy import bernoulli def a345262(n): """ Calculate the terms of OEIS entry A345262. (Order of the image of the J-homomorphism in the stable homotopy group π_n^S).