Course Test · University: upper level
Combinatorics: RatMath answers
The same twenty exercises, answered with RatMath Core and the Shelf libraries only. The code below was run when this page was built; its output is shown as printed, and compared with the independent answer.
Agrees 20
Libraries used here: core, discrete. In this code each library is in scope under its own name (linalg.det, stats.tTest), and Core's names (R, Rational, …) are in scope directly.
- 1.Multinomial coefficientsAgreesHow many distinct arrangements of the letters of MISSISSIPPI are there?Independent answer11 letters: M once, I four times, S four times, P twice. .RatMath code
discrete.multinomial(4, 4, 2, 1)Output34650n
- 2.Stars and barsAgreesHow many solutions in non-negative integers does have?Independent answer.RatMath code
discrete.multichoose(4, 10)Output286n
- 3.Inclusion–exclusionAgreesHow many integers from 1 to 100 are divisible by 2, 3 or 5?Independent answer.RatMath code
const by = (d) => Array.from({ length: 100 }, (_, i) => i + 1).filter((n) => n % d === 0); discrete.inclusionExclusion([by(2), by(3), by(5)]).unionOutput74n
- 4.DerangementsAgreesIn how many ways can 5 letters go into 5 addressed envelopes with none in the right one?Independent answer.RatMath code
discrete.derangementCount(5)Output44n
- 5.SurjectionsAgreesHow many functions from a 5-set onto a 3-set are there?Independent answer().RatMath code
discrete.surjections(5, 3)Output150n
- 6.Stirling and Bell numbersAgreesFind and the Bell number .Independent answer. .RatMath code
[discrete.stirling2(5, 2), discrete.bell(5)]Output[15n, 52n]
- 7.Stirling numbers of the first kindAgreesHow many permutations of 5 elements have exactly 2 cycles?Independent answer: from .RatMath code
discrete.stirling1(5, 2)Output50n
- 8.Eulerian numbersAgreesHow many permutations of have exactly one descent?Independent answer.RatMath code
discrete.eulerian(4, 1)Output11n
- 9.Integer partitionsAgreesFind , the number of partitions of 10.Independent answer(by the pentagonal-number recurrence: ).RatMath code
discrete.partitionCount(10)Output42n
- 10.CompositionsAgreesHow many ways can 6 be written as an ordered sum of 3 positive integers?Independent answer.RatMath code
discrete.compositionCount(6, 3)Output10n
- 11.Catalan numbersAgreesHow many balanced strings of 3 pairs of brackets are there? What is ?Independent answer: ((())), (()()), (())(), ()(()), ()()(). .RatMath code
[discrete.dyckWords(3).count, discrete.catalan(5)]Output[5n, 42n]
- 12.Vandermonde's identityAgreesEvaluate .Independent answerChoose 10 of 20 split into two groups of 10: .RatMath code
let s = 0n; for (let k = 0; k <= 10; k++) s += discrete.binomial(10, k) ** 2n; [s, discrete.binomial(20, 10)]Output[184756n, 184756n]
- 13.Linear recurrencesAgreesSolve , , .Independent answerCharacteristic roots 2 and 3: , , : , . .RatMath code
String(discrete.recurrence({ coefficients: [5, -6], initial: [1, 4] }).closedForm())Outputa(n) = −2^n + 2·3^n
- 14.Jacobsthal numbersAgreesSolve , , , and list .Independent answerRoots 2 and : . Terms 0, 1, 1, 3, 5, 11, 21, 43.RatMath code
const r = discrete.recurrence({ coefficients: [1, 2], initial: [0, 1] }); [String(r.closedForm()), r.terms(8)]Output["a(n) = −(1/3)·(−1)^n + (1/3)·2^n", [0, 1, 1, 3, 5, 11, 21, 43]]
- 15.Generating functionsAgreesIn how many ways can 25 cents be made from pennies, nickels and dimes?Independent answerThe coefficient of in : with dimes (0, 1, 2) the nickels range over : .RatMath code
const den = (k) => discrete.series(Array.from({ length: k + 1 }, (_, i) => (i === 0 ? 1 : i === k ? -1 : 0))); den(1).multiply(den(5)).multiply(den(10)).reciprocal().coefficient(25)Output12
- 16.Labelled treesAgreesHow many labelled trees are there on 5 vertices?Independent answerCayley's formula: .RatMath code
discrete.labelledTrees(5).countOutput125n
- 17.Burnside countingAgreesHow many ways can the 4 vertices of a square be coloured with 3 colours, up to rotation? Up to rotation and reflection?Independent answerRotations: . With reflections (two diagonal flips fix each, two edge flips each): .RatMath code
[discrete.countColourings(discrete.symmetry.cyclic(4), 3), discrete.countColourings(discrete.symmetry.dihedral(4), 3)]Output[24n, 21n]
- 18.Cycle indexAgreesWrite the cycle index of the rotation group of a square acting on its vertices.Independent answerIdentity , quarter turns (twice), half turn : .RatMath code
String(discrete.cycleIndex(discrete.symmetry.cyclic(4)))Output(1/2) s4 + (1/4) s2^2 + (1/4) s1^4
- 19.Binomial coefficientsAgreesHow many lattice paths go from to with unit steps right and up?Independent answerChoose which 3 of the 7 steps go up: .RatMath code
discrete.binomial(7, 3)Output35n
- 20.Steiner triple systemsAgreesA Steiner triple system on 7 points has every pair in exactly one triple. How many triples does it have?Independent answer(the Fano plane).RatMath code
const S = discrete.steinerTripleSystem(7); Object.keys(S).lengthOutput7
The system comes back as a plain object of 7 triples keyed 0 to 6, not an array or a block design with its parameters.