Documentation

CslibFrontier.Foundations.Data.Nat.BlockMove

Moving two adjacent finite blocks in raw natural indices #

The prefix is fixed and the following two blocks exchange places. Every index beyond the three-block interval stays fixed as well, so raw binary table entries retain a total inverse. On the two bounded blocks this is the existing finAddFlip, translated past the prefix. The native probe-append program uses the operation to move its old left probe behind the right body and probe, without choosing an abstract dart inverse at runtime.

def Nat.blockMove (before moved after i : ℕ) :

Exchange the blocks of lengths moved and after, fixing the prefix and every raw index past the three blocks. Zero-length blocks require no special input convention.

theorem Nat.blockMove_eq_finAddFlip (before moved after : ℕ) (i : Fin (moved + after)) :
before.blockMove moved after (before + ↑i) = before + ↑(finAddFlip i)

On a bounded suffix index, the raw block move is the existing finite block exchange.

theorem Nat.blockMove_inverse (before moved after i : ℕ) :
before.blockMove after moved (before.blockMove moved after i) = i

Exchanging the two lengths gives the literal inverse on every raw index, including out-of-range binary entries. This does not assume an index or table validity guard.

theorem Nat.blockMove_lt {before moved after i : ℕ} (hi : i < before + moved + after) :
before.blockMove moved after i < before + moved + after

An index inside the actual three blocks stays inside their unchanged total length.

theorem Nat.blockMove_zero_moved (a b i : ℕ) :
a.blockMove 0 b i = i

Moving an empty block fixes every raw index.

theorem Nat.blockMove_zero_after (a b i : ℕ) :
a.blockMove b 0 i = i

Moving a block past an empty block fixes every raw index.