#Please do not post homework #Caroline Cote, March 7th, 2026, Assignment 12 HelpHW12:= proc(): print(`A41c1(n), A41c(N), Phi(j,lambda), OddToDis(p), DisToOdd(d)`): end: with(combinat): read "C12.txt": read "C13.txt": #Problem 1 #A41c(N): inputs and outputs A41 sequence using # p(n)= Sum((-1)^(j-1)*p(n-(3*j^2-j)/2,j=1..infinity)+ Sum((-1)^(j-1)*p(n-(3*j^2+j)/2,j=1..infinity) # w the convention that p(n) = 0 if n is negative #A41c1(n): compute p(n) A41c1:= proc(n) local j, s: option remember: if n < 0 then RETURN(0): fi: if n=0 then RETURN(1): fi: s:= 0: for j from 1 to n while (3*j^2 - j)/2 <= n do s:=s+ (-1)^(j-1)*A41c1(n-(3*j^2-j)/2): if (3*j^2+j)/2 <= n then s:= s + (-1)^(j-1)*A41c1(n-(3*j^2+j)/2): fi: od: s: end: A41c := proc(N) local n: [seq(A41c1(n), n=1..N)]: end: time(A41c(1000)); # 0.058 time(A41ok(1000)); # 9.422 #A41c was a lot faster than A41ok #Problem 2: #Phi(j, lambda): inputs partition lambda = lambda(1), lambda(2), ..., lambda(t) # lambda in Par(n - a(j)) #Phi(lambda) = (t+3j-1, lambda(1) -1, ..., lambda(t)-1) in Par(n -a(j-1)) if t+3j >= lambda(1) # = (lambda(2)+1, ..., lambda(t) +1, 1, 1, ..., 1) in Par(n-a(j+1)) if t +3j < lambda(1), #where there are lambda(1) - 3j -t -1 1's at the end #outputs the new partition with either j-1 or j+1 Phi:=proc(j, lambda) local t, par, i, num: t:= nops(lambda): if t+3*j >= lambda[1] then par := [t+3*j -1, seq(lambda[i] -1, i=1..t-1)]: RETURN([j-1, par]): else num:= lambda[1] - 3*j - t - 1: par := [seq(lambda[i]+1, i = 2..t), 1$num]: RETURN([j+1, par]): fi: end: #problem 3 #OddToDis(p): converts odd partition to distinct partition #by writing it like [2a1+ 1, ..., 2a, 1 m] OddToDis:= proc(p) local n, r, m, a1,i, q, T: n :=nops(p): if n = 0 then RETURN([]): fi: if p[1] = 1 then RETURN([n]): fi: m:=0: i := n: while i >=1 and p[i] = 1 do m:= m+1: i:= i-1: od: r:= n -m: a1 := (p[1]-1)/2: if r = 1 then T:=[]: else q:=[ seq(p[i]-2, i=2..r)]: T:= OddToDis(q): fi: [a1+r+m, a1+r-1, op(T)]: end: #DisToOdd(d): inputs a distinct partition and DisToOdd := proc(d) local s, q, t, m,i: s:=nops(d): if s=0 then RETURN([]): fi: if s = 1 then RETURN([1$d[1]]): fi: if s<= 2 then q:= []: else q := DisToOdd([op(3..s, d )]): fi: m:= d[1]-d[2]-1: t:=nops(q): [2*(d[2] -t) +1, seq(q[i]+2, i = 1..t), 1$m]: end: