#Please do not post homework #Guy Adami, 2026-02-22, Assignment 8 #————— with(combinat) #————— xnP:=proc(n,p) option remember: if n=1 then 2: else (xnP(n-1,p)+n-1)*xnP(n-1,p)*n^(-1) mod p: fi: end: #————— #ExtractCycle(pi,i): The cycle corresponding to the member i of the permutation pi #For example ExtractCycle([2,1,4,3],1)=[1,2] ExtractCycle:=proc(pi,i) local C,ng: C:=[i]: ng:=pi[i]: while ng<>i do C:=[op(C),ng]: ng:=pi[ng]: od: C: end: #CycDec(pi): The full cyclic decomposition of pi CycDec:=proc(pi) local n,i,StillToDo,S,C,ng: n:=nops(pi): StillToDo:={seq(i,i=1..n)}: S:={}: while StillToDo<>{} do ng:=StillToDo[1]; C:=ExtractCycle(pi,ng): S:=S union {C}: #S\T : S minus T StillToDo:=StillToDo minus {op(C)}: od: S: end: #————— #LtoR(pi): The list places that are larger than anything #to the left pi=[2,1,4,3] LtoR:=proc(pi) local n,L,i,ma: n:=nops(pi): L:=[1]: #ma is the current world record ma:=pi[1]: for i from 2 to n do if pi[i]>ma then L:=[op(L), i ]: ma:=pi[i]: fi: od: L: end: #————— Foata:= proc(pi) local dec,cfc,n,i,P,phi: dec:= CycDec(pi): n:=nops(dec): cfc:=[]: for i from 1 to n do cfc:= [op(cfc),CFC(dec[i])] od: P:= sort(cfc): n:= nops(P): phi:=[]: for i from 1 to n do phi:= [op(phi),op(P[i])]: od: phi: end: #————— #xn(n): The solution of the recurrence xn(n)=(1+add(xn(i)^2,i=0..n-1))/n: xn:=proc(n) local i: option remember: if n=0 then 1: else (1+add(xn(i)^2,i=0..n-1))/n: fi: end: #xnC(n): clever version of xn(n) only having to remember what happened yesterday xnC:=proc(n) option remember: if n=1 then 2: else (xnC(n-1)+n-1)*xnC(n-1)/n: fi: end: #xnP(n,p): For a prime p, a fast way to compute xn(n) mod p for n
nops(CycDec(pi)) then countfalse:=countfalse + 1: fi: od: if countfalse <> 0 then RETURN(false); elif countfalse = 0 then RETURN(true); fi: end: #This function returned true, so this equality hold for all permutations of length <= 7 #————— #Question 3 #Foata means putting a CycDec into canonical form will take any subcycle andalways put the greatest value at the start. #By ordering it such that each subcycle of a permutation is ordered in ascending order of its first element #means that for each sub cycle, the greatest value is always first, #in addition to having the following cycle begin with a greater value than the previous. #This will create a form of { [i, xi, x’