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. 1.Multinomial coefficientsAgrees
    How many distinct arrangements of the letters of MISSISSIPPI are there?
    Independent answer
    11 letters: M once, I four times, S four times, P twice. 11!1! 4! 4! 2!=34650\dfrac{11!}{1!\,4!\,4!\,2!} = 34650.
    RatMath code
    discrete.multinomial(4, 4, 2, 1)
    Output
    34650n
  2. 2.Stars and barsAgrees
    How many solutions in non-negative integers does x1+x2+x3+x4=10x_1 + x_2 + x_3 + x_4 = 10 have?
    Independent answer
    (10+33)=286\binom{10 + 3}{3} = 286.
    RatMath code
    discrete.multichoose(4, 10)
    Output
    286n
  3. 3.Inclusion–exclusionAgrees
    How many integers from 1 to 100 are divisible by 2, 3 or 5?
    Independent answer
    50+33+20−16−10−6+3=7450 + 33 + 20 - 16 - 10 - 6 + 3 = 74.
    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)]).union
    Output
    74n
  4. 4.DerangementsAgrees
    In how many ways can 5 letters go into 5 addressed envelopes with none in the right one?
    Independent answer
    D5=5!(1−1+12−16+124−1120)=44D_5 = 5!\left(1 - 1 + \tfrac12 - \tfrac16 + \tfrac1{24} - \tfrac1{120}\right) = 44.
    RatMath code
    discrete.derangementCount(5)
    Output
    44n
  5. 5.SurjectionsAgrees
    How many functions from a 5-set onto a 3-set are there?
    Independent answer
    35−3⋅25+3⋅15=243−96+3=1503^5 - 3\cdot2^5 + 3\cdot1^5 = 243 - 96 + 3 = 150 (=3! S(5,3)= 3!\,S(5, 3)).
    RatMath code
    discrete.surjections(5, 3)
    Output
    150n
  6. 6.Stirling and Bell numbersAgrees
    Find S(5,2)S(5, 2) and the Bell number B5B_5.
    Independent answer
    S(5,2)=24−1=15S(5, 2) = 2^4 - 1 = 15. B5=1+15+25+10+1=52B_5 = 1 + 15 + 25 + 10 + 1 = 52.
    RatMath code
    [discrete.stirling2(5, 2), discrete.bell(5)]
    Output
    [15n, 52n]
  7. 7.Stirling numbers of the first kindAgrees
    How many permutations of 5 elements have exactly 2 cycles?
    Independent answer
    c(5,2)=50c(5, 2) = 50: from x(x+1)(x+2)(x+3)(x+4)=x5+10x4+35x3+50x2+24xx(x+1)(x+2)(x+3)(x+4) = x^5 + 10x^4 + 35x^3 + 50x^2 + 24x.
    RatMath code
    discrete.stirling1(5, 2)
    Output
    50n
  8. 8.Eulerian numbersAgrees
    How many permutations of {1,2,3,4}\{1, 2, 3, 4\} have exactly one descent?
    Independent answer
    A(4,1)=24−5=11A(4, 1) = 2^4 - 5 = 11.
    RatMath code
    discrete.eulerian(4, 1)
    Output
    11n
  9. 9.Integer partitionsAgrees
    Find p(10)p(10), the number of partitions of 10.
    Independent answer
    p(10)=42p(10) = 42 (by the pentagonal-number recurrence: p(9)+p(8)−p(5)−p(3)=30+22−7−3p(9) + p(8) - p(5) - p(3) = 30 + 22 - 7 - 3).
    RatMath code
    discrete.partitionCount(10)
    Output
    42n
  10. 10.CompositionsAgrees
    How many ways can 6 be written as an ordered sum of 3 positive integers?
    Independent answer
    (52)=10\binom{5}{2} = 10.
    RatMath code
    discrete.compositionCount(6, 3)
    Output
    10n
  11. 11.Catalan numbersAgrees
    How many balanced strings of 3 pairs of brackets are there? What is C5C_5?
    Independent answer
    C3=5C_3 = 5: ((())), (()()), (())(), ()(()), ()()(). C5=16(105)=42C_5 = \dfrac1{6}\binom{10}{5} = 42.
    RatMath code
    [discrete.dyckWords(3).count, discrete.catalan(5)]
    Output
    [5n, 42n]
  12. 12.Vandermonde's identityAgrees
    Evaluate ∑k=010(10k)2\displaystyle\sum_{k=0}^{10}\binom{10}{k}^2.
    Independent answer
    Choose 10 of 20 split into two groups of 10: (2010)=184756\binom{20}{10} = 184756.
    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. 13.Linear recurrencesAgrees
    Solve an=5an−1−6an−2a_n = 5a_{n-1} - 6a_{n-2}, a0=1a_0 = 1, a1=4a_1 = 4.
    Independent answer
    Characteristic roots 2 and 3: an=A 2n+B 3na_n = A\,2^n + B\,3^n, A+B=1A + B = 1, 2A+3B=42A + 3B = 4: B=2B = 2, A=−1A = -1. an=2⋅3n−2na_n = 2\cdot3^n - 2^n.
    RatMath code
    String(discrete.recurrence({ coefficients: [5, -6], initial: [1, 4] }).closedForm())
    Output
    a(n) = −2^n + 2·3^n
  14. 14.Jacobsthal numbersAgrees
    Solve an=an−1+2an−2a_n = a_{n-1} + 2a_{n-2}, a0=0a_0 = 0, a1=1a_1 = 1, and list a0,…,a7a_0, \dots, a_7.
    Independent answer
    Roots 2 and −1-1: an=2n−(−1)n3a_n = \dfrac{2^n - (-1)^n}{3}. 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. 15.Generating functionsAgrees
    In how many ways can 25 cents be made from pennies, nickels and dimes?
    Independent answer
    The coefficient of x25x^{25} in 1(1−x)(1−x5)(1−x10)\dfrac{1}{(1 - x)(1 - x^5)(1 - x^{10})}: with dd dimes (0, 1, 2) the nickels range over 0..⌊(25−10d)/5⌋0..\lfloor(25 - 10d)/5\rfloor: 6+4+2=126 + 4 + 2 = 12.
    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)
    Output
    12
  16. 16.Labelled treesAgrees
    How many labelled trees are there on 5 vertices?
    Independent answer
    Cayley's formula: 55−2=1255^{5-2} = 125.
    RatMath code
    discrete.labelledTrees(5).count
    Output
    125n
  17. 17.Burnside countingAgrees
    How many ways can the 4 vertices of a square be coloured with 3 colours, up to rotation? Up to rotation and reflection?
    Independent answer
    Rotations: (81+3+9+3)/4=24(81 + 3 + 9 + 3)/4 = 24. With reflections (two diagonal flips fix 2727 each, two edge flips 99 each): (81+3+9+3+27+27+9+9)/8=21(81 + 3 + 9 + 3 + 27 + 27 + 9 + 9)/8 = 21.
    RatMath code
    [discrete.countColourings(discrete.symmetry.cyclic(4), 3), discrete.countColourings(discrete.symmetry.dihedral(4), 3)]
    Output
    [24n, 21n]
  18. 18.Cycle indexAgrees
    Write the cycle index of the rotation group of a square acting on its vertices.
    Independent answer
    Identity s14s_1^4, quarter turns s4s_4 (twice), half turn s22s_2^2: Z=14(s14+s22+2s4)Z = \tfrac14(s_1^4 + s_2^2 + 2s_4).
    RatMath code
    String(discrete.cycleIndex(discrete.symmetry.cyclic(4)))
    Output
    (1/2) s4 + (1/4) s2^2 + (1/4) s1^4
  19. 19.Binomial coefficientsAgrees
    How many lattice paths go from (0,0)(0, 0) to (4,3)(4, 3) with unit steps right and up?
    Independent answer
    Choose which 3 of the 7 steps go up: (73)=35\binom73 = 35.
    RatMath code
    discrete.binomial(7, 3)
    Output
    35n
  20. 20.Steiner triple systemsAgrees
    A Steiner triple system on 7 points has every pair in exactly one triple. How many triples does it have?
    Independent answer
    (72)/(32)=21/3=7\binom72/\binom32 = 21/3 = 7 (the Fano plane).
    RatMath code
    const S = discrete.steinerTripleSystem(7);
    Object.keys(S).length
    Output
    7
    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.