Skip to content

Instantly share code, notes, and snippets.

@isomorphisms
isomorphisms / calculus.md
Last active March 28, 2017 16:38
calculus for programming language theorist

Here's a silly-but-perhaps-provocative way to talk about calculus.

The only atom to start with is +1+1+1+1+1+1+1+… ↣ 5+5+5+5+5+5+5+…. Some people call this "to quintuple" but I'll just call it ƒ. Repeated addition of the number 5. I'm going to build up large classes of functions from this, using "meta-moves" i.e. just operating on the function.

The first meta-move I'll allow myself is to stick the +5+5+5+5… anywhere I want on the number line. Tangent picking. Also known as b in y=mx+b.

@isomorphisms
isomorphisms / circle_shift.R
Created October 8, 2014 23:24
eigenvalues of a shift-average operation on a circle
# first page of www.math.sunysb.edu/~kirillov/mat552/liegroups.pdf
# However, explicitly computing the characteristic polynomial and finding the roots is a rather difficult problem.
#He must mean for general N because this seems to work for me??
require(magrittr)
require(matrixcalc)
@isomorphisms
isomorphisms / Rprofile.site
Created October 7, 2014 05:57
site-wide R profile
options(menu.graphics=FALSE)
options(editor='vi')
options(digits=10)
some <- car::some
#http://stackoverflow.com/questions/1448600/change-default-prompt-and-output-line-prefix-in-r
options(continue=" ")
@isomorphisms
isomorphisms / wegert.R
Last active February 1, 2019 14:26
make complex-plane Wegert plots (plot only the argument, knowing that the length=modulus works the same as in a "regular" Cartesian plot)
#run convenience functions first....
plat <- function(space,FUN,cex=2,chroma=45,a=66,b=4,c=3){ #a,b,c are tuning parameters
func=FUN(space) #eval for speedup
coleur=arg(func)%%360
light=a+b*mod(func)+c*l(coleur)
plot(space, pch=46,cex=cex, col=hcl( h=coleur, c=chroma, l=light ) )
}
#what this function does, is plot a boring series of points with nothing on them,
# moving the REAL ACTION to the colour parameter.
@isomorphisms
isomorphisms / setOutputColors.R
Last active August 29, 2015 14:06
formatting for colorOut
library(colorout)
# The function takes numeric vectors of at most three elements each.
# The three numbers indicate, respectively, formating, background
# color and foreground color. If a vector has only one element, the
# number will be used to set the foreground color; if it has two
# elements, they will be used to set the background and foreground
# colors.
#
# The table below shows valid values and their meanings as both
"360852405690179584","","","2013-07-26 20:01:32 +0000","<a href=""http://www.floodgap.com/software/ttytter/"" rel=""nofollow"">TTYtter</a>","Define ""clear"" Mogadishu: http://t.co/fr4NwFlMq2","","","","http://downloads.bbc.co.uk/podcasts/radio4/thpop/thpop_20130723-1000b.mp3"
"334368922310676480","","","2013-05-14 18:05:38 +0000","<a href=""http://www.floodgap.com/software/ttytter/"" rel=""nofollow"">TTYtter</a>","Romans &amp; medieval Xtians both thought women were sexually insatiable. So where did ""Lie back and think of your country"" come from? #radio4","","","",""
"334365448063823873","","","2013-05-14 17:51:49 +0000","<a href=""http://www.floodgap.com/software/ttytter/"" rel=""nofollow"">TTYtter</a>","Only within the last 200 years that a European city has overtaken the size (1mm people) of Juvenalian Rome. #radio4","","","",""
"334359389601419265","","","2013-05-14 17:27:45 +0000","<a href=""http://www.floodgap.com/software/ttytter/"" rel=""nofollow"">TTYtter</a>","ancient Romans slipping Greek into t
@isomorphisms
isomorphisms / _.vim
Created August 31, 2014 01:59
swap - and _ keys in vim
" RATIONALE:
" _ is used all the time in programming
" - is only used for "minus −" operator
" chords hurt my hands
" I avoid naming things with _ because it hurts
" I don't mind hitting <SHIFT> for "minus"
" because it's an operator
" and therefore requires more thought than
" "spacebar in a variable name".
@isomorphisms
isomorphisms / fizzbuzz.R
Created August 29, 2014 07:02
fizzbuzz
fb = function(n) {
f = ""
b = ""
if (!n %%3) f="fizz"
if (!n %%5) b="buzz"
print(paste0(f,b))
}
@isomorphisms
isomorphisms / fibonacci.R
Created August 27, 2014 07:12
Fibonacci series matrix version
#with expm
require(expm)
matrix( c(0,1,1,1), 2,2 ) -> fibonacci
c(1L,1L) -> start
start %*% (fibonacci %*% 1337) #1337'th term-pair in Fibonacci series
# [,1] [,2]
#[1,] 1.887894e+279 3.054677e+279
@isomorphisms
isomorphisms / peek.R
Last active August 29, 2015 14:05
don't use head and tail … always be sampling from the middle of the data.frame
taste <- function(soup, ladle=5L) sample.int(x=soup, size=ladle, replace=TRUE)
peek <- function(df,n=5L) df[ taste(nrow(df),n) , ] #dataframe[r,c] means "subset of dataframe row #r, column #c"
p <- function(df,n=5L) rbind(head(df,1L), peek(df,n), tail(df,1L))
#SAMPLE OUTPUT
require(bigvis)
data(movies)