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
#! /usr/local/bin/perl -w | |
use strict; | |
use warnings; | |
for ( my $i=0 ; $i<5 ; $i++ ) { | |
my $var; | |
sub returnvar { return $var; } | |
$var = $i; | |
print "\$i=$i, \$var=$var, returnvar returns ", returnvar, "\n"; | |
} |
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
// JavaScript functions to replace "th" by the letter thorn throughout | |
// a document. Use this with `thornifyDoc(window.document)`. | |
// Written by David A. Madore, 2022-04-02. Public Domain. | |
function thornifyString(s) { | |
return s.replace(/T[Hh]/g, "\u00DE").replace(/th/g, "\u00FE"); | |
} | |
function thornifyDoc(doc) { |
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
### The case of E_6 | |
WCR = WeylCharacterRing("E6", style="coroots") | |
weylcovec = sum([rt.associated_coroot() for rt in WCR.positive_roots()])/2 | |
R.<t> = QQ['t'] | |
weyldenom = prod([t^rt.scalar(weylcovec)-1 for rt in WCR.positive_roots()]) | |
weylnumertab = [None] + [prod([t^(rt.scalar(weylcovec)+(1 if WCR.fundamental_weights()[i].scalar(rt.associated_coroot())>0 else 0))-1 for rt in WCR.positive_roots()]) for i in range(1,6+1)] | |
counttab = [None] + [R(weylnumertab[i]/weyldenom) for i in range(1,6+1)] | |
def realize(pol): | |
d = pol.degree() | |
def v(x): |
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
#! /usr/local/bin/perl -w | |
# Generate a ticking sound where the intervals between ticks are | |
# distributed following a Gamma distribution. | |
# Produces raw 48k 16-bit signed single channel audio. So pipe this to: | |
# sox -t raw -r 48k -c 1 -e signed -b 16 -L - -t wav ticks.wav | |
# Command-line parameters are: | |
# -r <number>: the average tick rate in ticks per second (defaults to 2) |
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
# Base 3-w where w is a 6-th root of unity | |
w = N(exp(I*pi/3)) | |
def dragonpoints(depth): | |
if depth <= 0: | |
return [(1+w)/3] | |
else: | |
parta = [z+1 for z in dragonpoints(depth-1)] | |
partb = [z/w+w for z in dragonpoints(depth-1)] | |
partc = [z+w for z in dragonpoints(depth-1)] | |
return [z/(3-w) for z in parta+partb+partc] |
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
# Return cnt solutions of the Pell-Fermat equation x^2 - d*y^2 = 1 | |
def pell_equation(d, cnt): | |
if cnt < 1: | |
return [] | |
# First, find the "fundamental" solution | |
cf = continued_fraction(QQbar(sqrt(d))) | |
i = 0 | |
(xfun,yfun) = (None,None) | |
while True: | |
r = cf.convergent(i) |
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
# Try to find an approximate pentagon in a square lattice: | |
# For this, we use LLL to try to find (v_0,v_1,v_2,v_3) four | |
# integer-valued vectors of size 2 such that v_1 is close to R(v_0), | |
# v_2 is close to R^2(v_0) and v_3 is close to R^3(v_0), where R is | |
# rotation by 2*pi/5, and v_0 is not too large. | |
# How much weight to give to the size of the approximation: | |
weight = 1/200 |
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
size = 4 | |
valtab = [] | |
for n in range(2^(size*size)): | |
m = Matrix(QQ,size,size,[(n>>i)&1 for i in range(size*size)]) | |
for v in m.eigenvalues(): | |
valtab.append(v) | |
numtab = [N(v) for v in valtab] | |
numdict = {} | |
for v in numtab: |
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
*** 2022-01-21 | |
2022-01-14,545,2190 | |
2022-01-15,473,2157 | |
2022-01-16,436,2088 | |
2022-01-17,528,2420 | |
2022-01-18,437,2325 | |
2022-01-19,437,2321 | |
2022-01-20,338,1780 | |
*** 2022-01-22 | |
2022-01-14,545,2188 |
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
#! /usr/local/bin/perl -w | |
# Find auto-descriptive sentences in English, such as the following: | |
# To do this, we iterate replacing a sentence by its description | |
# until, hopefully, we reach a fixed point. Generally this won't | |
# happen (we hit a loop instead). When this happens, we randomly | |
# change the initial blurb and try iterating again with this new blurb | |
# to break out of the loop. |