Skip to content

Instantly share code, notes, and snippets.

View VincentTam's full-sized avatar
🏀
Rolling around

Vincent Tam VincentTam

🏀
Rolling around
View GitHub Profile
@VincentTam
VincentTam / cantor_fct.typ
Created August 27, 2025 02:29
Cantor set & function
#set page(height: auto, width: auto, margin: 1em)
#import "@preview/cetz:0.4.1"
#let n = 4
#let vsep = 1
#let width = 1
#let lefts = range(2, n + 1).fold(
((1/3,),),
(a, e) => (..a, a.last().map(x => (x - 2*calc.pow(1/3, e), x + 4*calc.pow(1/3, e))).flatten())
)
@VincentTam
VincentTam / explanation.md
Created August 13, 2025 23:00
LaTeX advanced recursion (use output of an auxiliary function as argument of recursive function)

I was puzzled ats \expandafter, and I started with simple observations. Here're AI-generated explanations.

The command \expandafter is a low-level TeX primitive that controls the order of macro expansion. Its job is to force the expansion of a token that is not immediately next to it.

In the provided code, \expandafter is used to ensure that the recursive call \rrep receives a concrete number as its first argument, rather than an unexpanded macro sequence.

Let's break down the key line from the \rrep macro:

\expandafter\rrep\expandafter{\number\numexpr#1-1\relax}{\rep{#2}}
@VincentTam
VincentTam / exp_binom.tex
Last active August 14, 2025 13:16
approximations for exponential function using two different constructions
\newcommand*\mytablecontents{}
\gappto\mytablecontents{$n$ & $N=10^n$ & $(1+1/N)^N$}
\gappto\mytablecontents{\\\hline}
\foreach \i in {1,...,5}{
\FPeval\ii{pow(\i,10)}
\FPeval\ii{round(ii:0)}
\FPeval\ieval{round((1+1/ii)^ii:8)}
\xappto\mytablecontents{\i & $\ii$ & $\ieval$}
\gappto\mytablecontents{\\\hline}
}
@VincentTam
VincentTam / CSB.mkd
Created July 28, 2025 01:24
Cantor–Schröeder–Berstein Theorem

First attempt

Theoretical settings

  • $A = A_0 = \lbrace x^2 + y^2 \le 1 \rbrace$ ← unit circle
  • $B = B_0 = \lbrace \max(|x|,|y|) \le 1 \rbrace$ ← unit square
  • $f(x,y) = (x,y)/\sqrt2$ ← injection from $A$ to $B$ (shrinking by $1/\sqrt2$)
  • $g(x,y) = (x,y)/\varphi$ ← injection from $B$ to $A$ (shrinking by $1/\varphi$, where $\varphi$ is the golden ratio)

This gives a decreasing sequence of subsets of $A$ and $B$

  • $A_n = g(B_{n-1})$ is
  • a circle with radius $(\sqrt2)^{-k} \varphi^{-k}$ if $n = 2k$
@VincentTam
VincentTam / generalized_cauchy_schwarz.typ
Created June 2, 2025 15:30
Generalized Cauchy–Schwarz
#import "@preview/touying:0.6.1": *
#import themes.simple: *
#show: simple-theme.with(aspect-ratio: "16-9")
#import "@preview/theorion:0.3.3": *
#show: show-theorion
#import "@preview/cetz:0.3.4"
#import "@preview/mannot:0.3.0"
@VincentTam
VincentTam / example-002.typ
Created May 19, 2025 15:03
Typst Sample Article (two column layout)
// format the paper
#set page(
paper: "us-letter",
margin: (x: 1in, y: 1in),
numbering: "1/1",
header: [
#grid(columns: (1fr, 1fr, 1fr),
align(left)[BamDone Exmaple-002.typ],
align(center)[Center],
align(right)[Right]
@VincentTam
VincentTam / determinant-sildes.tex
Created May 1, 2025 20:57
Source code for the LaTeX beamer slides for my presentation on determinants for Simply Study Group
\documentclass[dvipsnames]{beamer}
\usetheme{Madrid}
\usepackage{annotate-equations}
\renewcommand{\eqnhighlightshade}{30}
\usepackage{gensymb}
\usepackage{quiver} % for "swap pathways"
\usepackage{cancel}
\usetikzlibrary{graphs.standard, quotes} % for coins
\usepackage{wrapfig} % for coins
\usepackage{extpfeil} % for extensible arrows
@VincentTam
VincentTam / example-001.typ
Created May 1, 2025 20:42
Typst Example 001
Hello world!
I'm typing here so that inline equaitons like $x=3$ appears in real-time.
$
f(x) = sin(x)
$
$
tan(x) (4x^2)/(3x+4)
@VincentTam
VincentTam / 250220-log-notes.mkd
Created February 22, 2025 16:32
F.2 Trigonometry and log (in simplified Chinese)

从前,有位富翁,他的家产有 $1 (一整份家产) 他的大儿子分走了当中的 1/2 (一半),富翁剩下 $1/2 他的二儿子分走了剩下的 1/2 ,富翁剩下 $1/4 他的三儿子分走了剩下的 1/2 ,富翁剩下 $1/8 他的四儿子分走了剩下的 1/2 ,富翁剩下 $1/16

如此类推

half quarter

@VincentTam
VincentTam / 231020-bdd.md
Last active October 22, 2023 15:26
vin's discord math notes chap. 2

由於 (1 + 1/n) 是二項式的 n 次方,要了解它的特性(如剛才展示的上下限),需要用上二項式定理。上面不等式最具技巧的一步在於藍色分母從 n! 變成 2⁻¹。 小問題:為何上標有 "-1"? 重點在於 n! = 1 ⋅ 2 ⋅ 3 ⋯ (n - 1) n 中,當 n! 變成 (n + 1)! 時,額外乘上的數字 n + 1 是隨 n 而增長,但 2 變成 2⁺¹ 時,額外乘上的數字永遠是 2,所以當 n「足夠大」(n > 3)時,n! > 2。 取倒數後不等式反轉,於是出現 1/n! < 1/2,然後就可以運用等比數列和公式,為 (1 + 1/n) 給出上限。

上面實驗發現 n 越大,(1 + 1/n) 也越大。即若 m < n,(1 + 1/m) < (1 + 1/n)。這種數列我們叫__嚴格遞增數列__。(「嚴格遞增」比「單調遞增」「嚴格」,只接受「>」,不接受「=」。) 練習:試證 (1 + 1/n) < (1 + 1/(n + 1))⁺¹ 提示:

  1. 如上面般展開 (1 + 1/n),分離最簡單兩項。
  2. 其餘 n - 1 項中,調整分子分母配對,先把 1 / k! 放在左邊。