Skip to content

Instantly share code, notes, and snippets.

@stla
stla / ASCII00.R
Last active March 5, 2024 14:03
Braid groups
# hSepString :: HSep -> String
# hSepString hsep = case hsep of
# HSepEmpty -> ""
# HSepSpaces k -> replicate k ' '
# HSepString s -> s
hSepString <- function(hsep) {
sep <- attr(hsep, "sep")
switch(
sep,
"empty" = "",
@stla
stla / VennDiagrams00.R
Last active March 4, 2024 15:44
Venn diagrams
# -- | Given the cardinalities of some finite sets, we list all possible
# -- Venn diagrams.
# --
# -- Note: we don't include the empty zone in the tables, because it's always empty.
# --
# -- Remark: if each sets is a singleton set, we get back set partitions:
# --
# -- > > [ length $ enumerateVennDiagrams $ replicate k 1 | k<-[1..8] ]
# -- > [1,2,5,15,52,203,877,4140]
# -- >
@stla
stla / KostkaNumbers.R
Last active March 31, 2024 11:50
Kostka numbers with R
rg <- function(a, b) {
if(a <= b) a:b else integer(0L)
}
KostkaNumber <- function(lambda, mu) {
lambda <- as.integer(lambda)
mu <- as.integer(mu)
wmu <- sum(mu)
wlam <- sum(lambda)
if(wlam == 0L) {
@stla
stla / LittlewoodRichardsonRule00.R
Last active February 29, 2024 02:27
Littlewood-Richardson rule for skew Schur
insertWith <- function(f, mp, key, value) {
if(key %in% names(mp)) {
mp[[key]] <- f(value, mp[[key]])
} else {
mp[[key]] <- value
}
mp
}
zip3 <- function(v1, v2, v3) {
@stla
stla / LittlewoodRichardson00.R
Last active February 28, 2024 15:03
Littlewood-Richardson
insertWith <- function(f, mp, key, value) {
if(key %in% names(mp)) {
mp[[key]] <- f(value, mp[[key]])
} else {
mp[[key]] <- value
}
mp
}
drop <- function(n, x) {
@stla
stla / weierstrass.js
Last active December 20, 2023 01:56
Weierstrass p-function and its first three derivatives with JavaScript.
/*
Weierstrass p-function and its first three derivatives.
Author: Stéphane Laurent.
Depends on math.js <https://mathjs.org/>
and jacobi.js <https://gist.github.com/stla/955af9c1c2713a47883bc927a759bdc7>.
*/
var weierstrass = (function () {
const jtheta1 = jacobi.jtheta1;
@stla
stla / ellipticIntegrals.js
Last active December 19, 2023 13:42
Elliptic integrals with JavaScript - depends on math.js
/*
Carlson elliptic integrals and incomplete elliptic integrals.
Author: Stéphane Laurent.
Depends on math.js <https://mathjs.org/>.
*/
var ellipticIntegrals = (function () {
let CarlsonRF = function(x, y, z, err) {
if(err <= 0) {
@stla
stla / jacobi.js
Last active December 19, 2023 11:07
Jacobi theta functions with JavaScript - depends on math.js
/*
Jacobi theta functions.
Author: Stéphane Laurent.
The functions jtheta1, jtheta2, jtheta3 and jtheta4 are the Jacobi theta
functions. The function jtheta1 is 1-antiperiodic, and the functions
jtheta2, jtheta3 and jtheta4 are 1-periodic.
The function jthetaAB is the Jacobi theta function with characteristics.
The function jtheta1Prime0 is the derivative at 0 of jtheta1.
*/
@stla
stla / tesseract.jl
Last active October 12, 2023 21:29
Tesseract with Julia
import Meshes
using MeshViz
using GLMakie
using Makie
using Printf
# vectors obtained by changing signs of the given vectors
function changesOfSigns(vecs)
N = length(vecs[1])
signs = Iterators.product(ntuple(i -> (-1, 1), N)...)
@stla
stla / gyromesh.jl
Last active October 13, 2023 13:38
Gyromesh (hyperbolic mesh) with Julia
import Meshes
using LinearAlgebra
using MeshViz
using GLMakie
using Makie
using Printf
# beta factor
function betaF(A, s)
1.0 / √(1 + LinearAlgebra.norm_sqr(A) / (s*s))