#OK to post homework #Lucy Martinez, 03-19-2024, Assignment 16 # Problem 2: Write a procedure generalizing SR, call it qSR(q,INI,L,n) # that (i) inputs INI (a list of length nops(L) of integers in {0,...,q-1} # (ii) a list of pairs [c[i],a[i]] , i=1..r where c is in {1, ..., q-1}, # and ai are positive integers and a1<.. x[t]=c[1]*x[t-a[1]]+ ... + c[r]*x[t-a[r]] mod q qSR:=proc(q,INI,L,n) local r,i,ng,M,S: r:=nops(L): #checks that we have enough initial condition for the recurrence if nops(INI)<>L[r][2] then return(FAIL): fi: S:={}: for i from 1 to r do S:=S union {L[i][1]}: od: #check that c[i]'s are members of {1, ..., q-1} if not (S subset {seq(i,i=0..q-1)}) then return(FAIL): fi: if not (convert(INI,set) subset {seq(i,i=0..q-1)}) then return(FAIL): fi: if not ({seq(type(L[i][2],posint),i=1..nops(L))}={true} and sort([seq(L[i][2],i=1..r)])=[seq(L[i][2],i=1..r)]) then return(FAIL): fi: if not type(n,posint) then return(FAIL) fi: M:=INI: while nops(M)L[-1] then return(FAIL): fi: if not (convert(INI,set)={0,1} or convert(INI,set)={1}) then return(FAIL): fi: if not (type(L,list) and {seq(type(L[i],posint),i=1..nops(L))}={true} and sort(L)=L) then return(FAIL): fi: if not type(n,posint) then return(FAIL) fi: M:=INI: while nops(M)