Skip to content

Instantly share code, notes, and snippets.

View dannypsnl's full-sized avatar

Lîm Tsú-thuàn dannypsnl

View GitHub Profile
@dannypsnl
dannypsnl / EasierIndices.agda
Created September 29, 2025 18:49 — forked from yangzhixuan/EasierIndices.agda
Making working with de Brujin indices easier
{-
This file demonstrates a technique for making working with de Bruijn-indexed
terms easier that I learnt from the paper /The Linearity Monad/ by Jennifer
Paykin and Steve Zdancewic. After defining well-typed terms `Γ ⊢ τ` using de Bruijn
indices, we define an auxiliary function `lam` that takes in the variable term explicitly:
> lam : {V : Type} {Γ : Cxt V} {τ σ : Ty V}
> → (({Δ : Cxt V} → {{IsExt Δ (Γ , τ)}} → Δ ⊢ τ)
> → (Γ , τ) ⊢ σ)
> → Γ ⊢ τ ⇒ σ
@dannypsnl
dannypsnl / README.md
Last active September 1, 2025 07:09
Check given multiplication table form a grope structure or not

Grope

A grope is a set $G$ together with a binary operation $\circ$, in which the identity

$$ x \circ (y \circ x) = y $$

is satisfied for all $x, y \in G$.

@dannypsnl
dannypsnl / stuck.ss
Created February 21, 2025 13:13
Get chez scheme stuck
(import (chezscheme))
(define handler-key (gensym))
(define th #f)
(define x 0)
(define (sub)
(define n
(call/cc (lambda (k)
@dannypsnl
dannypsnl / miniKanren.rkt
Last active February 20, 2025 01:30
miniKanren in 40 minutes (so undone)
#lang racket
(require (for-syntax syntax/parse))
(define (reify-name n)
(string->symbol
(string-append "_" (number->string n))))
(struct fresh (value count)
#:methods gen:custom-write
[(define (write-proc self out mode)
(if (fresh-value self)
@dannypsnl
dannypsnl / substitution.rkt
Last active January 26, 2025 19:23
can naive substitution work, if we apply binding as sets of scopes?
#lang racket
(require nanopass)
(define-language L
(terminals
(symbol (x)))
(Expr (e)
(λ x e)
(e0 e1)
x))
@dannypsnl
dannypsnl / middle-convention.rkt
Last active January 23, 2025 05:02
math convention
#lang racket
(require (for-syntax syntax/parse))
(define-syntax (math stx)
(syntax-parse stx
#:datum-literals (+ *)
[(_ (o ...) op o* ...)
#'(let ([k (math o ...)])
(math k op o* ...))]
[(_ (o ...)) #'(math o ...)]
@dannypsnl
dannypsnl / mobius.rkt
Last active January 14, 2025 07:20
Möbius strip
#lang racket
(require plot
plot/utils)
(plot3d
(parametric-surface3d
(λ (θ t)
(define R 1)
(define s (/ t 2))
(list
@dannypsnl
dannypsnl / circle-in-complex-plane.rkt
Created December 1, 2024 06:31
circle in complex plane
#lang racket
(require plot)
(define (complex->vector z)
(vector (real-part z) (imag-part z)))
(define ps
(for/list ([x (in-range 0 1 1/100)])
(complex->vector (exp (* 0+1i 2 pi x)))))
@dannypsnl
dannypsnl / Ising-model.rkt
Last active November 23, 2024 16:39
Picturing 2D Ising model
#lang racket
(require pict
rebellion/collection/multiset)
(define (square bit)
(define pict-size 5)
(match bit
[1 (filled-rectangle pict-size pict-size)]
[0 (rectangle pict-size pict-size)]))
#lang racket
(define (d form)
(match form
[`(+ ,f ,g) `(+ ,(d f) ,(d g))]
[`(* ,f ,g) `(+ (* ,(d f) ,g) (* ,f ,(d g)))]
[`(∘ ,f ,g) `(* (∘ ,(d f) ,g) ,(d g))]
[`(d ,n ,o) `(d ,(add1 n) ,o)]
[o `(d 1 ,o)]))