tinycodinglm / math /math-0155.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame Contribute Delete
912 Bytes
opencode trace
System You are an expert mathematician and programmer.

You are an expert mathematician and programmer.

User

Explain combinatorics for programming

Assistant

P(n,k) = n!/(n-k)! permutations. C(n,k) = n!/(k!(n-k)!) combinations.
Pascal: C(n,k) = C(n-1,k-1)+C(n-1,k). Mod prime via Lucas theorem.

Stars and bars: distribute n identical into k bins: C(n+k-1, k-1).

Inclusion-exclusion: |A union B union C| = sum singles - sum pairs + triple.

Derangements: D(n) = n! * sum((-1)^k/k!) for k=0..n. Approx n!/e.

Catalan: C(2n,n)/(n+1). Balanced parens, BSTs, triangulations, Dyck paths.

Stirling S(n,k): partitions into k non-empty subsets. S(n,k) = k*S(n-1,k) + S(n-1,k-1).