The Wikipedia Article on the Hilbert Cube includes functions that encode/decode arbitrary indices to/from arbitrary points on the Hilbert Curve. Those algorithms aren't constant-time. Is there a constant-time algorithm that, given an actual point on the curve (and, perhaps, some required state), generates the next point (and the next state)?
Formally, I want a type State
, and a tuple (initialState, nextState) :: (State, State -> ((Nat, Nat), State)
, such that each application of nextState
gives us the next point of the Hilbert curve, and such that that nextState
is optimal, which is probably not the case for the algorithm presented on Wikipedia, since it possibly misses the opportunity for incremental computation that we have here. Illustration:
data State = _
initialState :: State
initialState = _
-- This must be optimal
nextState :: State -> ((Nat, Nat), State)
nextState = _
-- Returns the `nth point` of the hilbert curve
hilbertPoint :: Nat -> (Nat, Nat)
hilbertPoint n = iterate (snd.nextState) initialState !! n