Skip to content

Instantly share code, notes, and snippets.

View dpiponi's full-sized avatar
🧱
In material form

Dan Piponi dpiponi

🧱
In material form
View GitHub Profile
@dpiponi
dpiponi / Circle packing
Created May 12, 2015 19:41
Julia code using Divide and Concur algorithm to pack circles in a circle
View Circle packing
function dm(Pa, Pb, y, β, n)
for i in 1:n
if i%100 == 0
print("Iteration $i/$n\n")
end
fay = (1-1/β)*Pa(y)+(1/β)*y
fby = (1+1/β)*Pb(y)-(1/β)*y
y = y+β*(Pa(fby)-Pb(fay))
# @show(y)
end
@dpiponi
dpiponi / example.cu
Created December 19, 2011 22:42
Minimal CUDA example
View example.cu
#include <stdio.h>
#define N 1000
__global__
void add(int *a, int *b) {
int i = blockIdx.x;
if (i<N) {
b[i] = 2*a[i];
}
View example.cpp
//
// On MacOSX compile with:
// g++ -framework OpenGL -framework GLUT -o example example.cpp
//
#include <stdlib.h>
#include <GLUT/glut.h>
GLuint program;
View main.lhs
> {-# LANGUAGE ExplicitForAll, RankNTypes #-}
> import Control.Monad.Cont
An Eilenberg-Moore algebra for a monad t (a t-algebra) is one of these:
> type Algebra t x = t x -> x
satisfying these laws (page 3):
@dpiponi
dpiponi / Main.hs
Created February 15, 2016 23:38
Haskell heat engine simulation. (Not quite complete.)
View Main.hs
{-# LANGUAGE FlexibleContexts #-}
import Data.Array
import Data.Array.IO
import Data.Foldable
import Data.List hiding (sum)
import System.Random
import Control.Monad.State
import Prelude hiding (sum)
--import Debug.Trace
@dpiponi
dpiponi / graph.hs
Created August 26, 2016 13:58
Perfect matchings and continued fractions
View graph.hs
import Data.Ratio
import Data.List
import Control.Monad
-- I'm using two Haskell types for the two vertex types in
-- a bipartite graph.
-- Edges only go from type a to type b.
data BipartiteGraph a b = G [a] [b] [(a, b)]
instance (Show a, Show b) => Show (BipartiteGraph a b) where
@dpiponi
dpiponi / elliptic-umbilic.py
Created September 10, 2016 16:29
The elliptic umbilic caustic rendered with diffraction
View elliptic-umbilic.py
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import random
import scipy.integrate as integrate
# Dimension of image in pixels
N = 129
# Number of samples to use for integration
View swallowtail.py
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as integrate
# Dimension of image in pixels
N = 256
# Number of samples to use for integration
M = 257
@dpiponi
dpiponi / swallowtail.py
Created September 11, 2016 19:38
The swallowtail catastrophe with diffraction
View swallowtail.py
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as integrate
# Dimension of image in pixels
N = 256
# Number of samples to use for integration
M = 257
@dpiponi
dpiponi / comb.hs
Created January 31, 2017 16:06
Compute formal power series for functional square root of sin function
View comb.hs
import Data.Ratio
(^+) a b = zipWith (+) a b
(^-) a b = zipWith (-) a b
(a : as) `convolve` (b : bs) = (a * b) :
((map (a *) bs) ^+ (as `convolve` (b : bs)))
compose (f : fs) (0 : gs) = f : (gs `convolve` (compose fs (0 : gs)))