moduleRSAGL.Auxiliary(doubles,loopedDoubles,consecutives,loopedConsecutives,dropRandomElements,matrixMultiplyImpl,loopList,shiftR,zeroToOne,constrain,debugTime,waitParList)whereimportData.ArrayimportSystem.RandomimportSystem.CPUTimeimportControl.ParallelimportControl.Parallel.StrategiesimportDebug.Trace-- doubles transforms a list to a list of adjacent elements.-- doubles [1,2,3,4,5] = [(1,2),(2,3),(3,4),(4,5)]doubles::[a]->[(a,a)]doubles[]=[]doubles[_]=[]doubles(x:y:zs)=(x,y):doubles(y:zs)-- loopedDoubles transforms a list to a list of adjacent elements, looping back to the beginning of the list.-- loopedDoubles [1,2,3,4,5] = [(1,2),(2,3),(3,4),(4,5),(5,1)]loopedDoubles::[a]->[(a,a)]loopedDoublesas=loopedDoubles_(headas)aswhereloopedDoubles__[]=[]loopedDoubles_a[x]=[(x,a)]loopedDoubles_a(x:y:zs)=(x,y):loopedDoubles_a(y:zs)-- consecutives answers a list containing every sequence of n consecutive-- elements in the parameter.--consecutives 3 [1,2,3,4] = [[1,2,3],[2,3,4]]consecutives::Int->[a]->[[a]]consecutivesnxs=lettaken=takenxsinif(lengthtaken==n)then(taken:(consecutivesn$tailxs))else[]-- loopedConsecutives answers a list containing every sequence of n consecutive-- elements in the parameter, looping back to the beginning of the list.-- consecutives 3 [1,2,3,4] = [[1,2,3],[2,3,4],[3,4,1],[4,1,2]]loopedConsecutives::Int->[a]->[[a]]loopedConsecutivesnxs=consecutivesn$take(n+lengthxs-1)$cyclexs-- dropRandomElements removes some elements of a list at random. The first parameter is the number of elements out of 100 that should be included (not dropped).-- The second is the random number generator, and the third is the list to be operated on.dropRandomElements::Int->StdGen->[a]->[a]dropRandomElementspercent__|percent>100=error"dropRandomElements: percent > 100"dropRandomElementspercent__|percent<0=error"dropRandomElements: percent < 100"dropRandomElements__[]=[]dropRandomElementspercentrand_intsthings=let(next_int,next_gen)=nextrand_intsrest=dropRandomElementspercentnext_gen(tailthings)inif(next_int`mod`100<percent)then((headthings):rest)elserest-- matrixMultiplyImpl implements matrix multiplication.matrixMultiplyImpl::(b->c->c)->c->(a->a->b)->[[a]]->[[a]]->[[c]]matrixMultiplyImpladdOpzeromultiplyOpmn=[[foldraddOpzero$zipWithmultiplyOpm'n'|n'<-n]|m'<-m]-- loopList appends the first element of a list to the end of the list. The result is a list of one greater length.-- shiftR shifts every element of a list to the right, recyling the last element as the first. The result is a list of the same length.loopList::[a]->[a]loopListps=ps++[headps]shiftR::[a]->[a]shiftRps=lastps:initps-- zeroToOne creates a list of numbers from 0.0 to 1.0, using n steps.zeroToOne::Integer->[Double]zeroToOnen|n>100000=trace("Warning: zeroToOne was asked for "++shown++" subdivisions, which seems high. Using 100,000 instead.")zeroToOne100000zeroToOnen|n<=1000=ztos!nzeroToOnen=zeroToOnePrimnzeroToOnePrim::Integer->[Double]zeroToOnePrimn=map(*x)[0..(fromInteger$n-1)]wherex=recip(fromInteger$n-1)ztos::ArrayInteger[Double]ztos=listArray(0,1000)$map(zeroToOnePrim)[0..1000]-- constrain restricts the effective domain of a function. Outside of the restricted domain, the function is idconstrain::(a->Bool)->(a->a)->a->aconstrainfgx=iffxthengxelsex-- debugTime prints a statement indicating how long an IO action takes to completedebugTime::String->IOa->IOadebugTimemsgio_action=doprint$"debugTime: starting "++msgstart_time<-getCPUTimeresult<-io_actionend_time<-getCPUTimeprint$"debugTime: done with "++msg++" "++show(end_time-start_time)returnresult-- as parList, but waits until the list is fully evaluated.waitParList::Strategya->Strategy[a]waitParListsa=parListsa`pseq`seqListsa