Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Combinators.TakeDropUnary

Taking and dropping list elements in linear time #

Taking or dropping the first n elements of a list encoded by Turing.MultiTapeTM.encList, with n in unary, has cost and output degree one. Both are computed by the one-tape machine Turing.MultiTapeTM.TakeDropUnary.toTM, which copies the count to its work tape and then streams the encoded list once, moving the work head at every element boundary. Folding over the count or over the list would cost quadratic time.

Main results #

Taking the first n elements, with n in unary, in linear time.

Dropping the first n elements, with n in unary, in linear time.