Exact source recovery and operation bounds for indexed snapshot histories
ProvedPvsNP.LazyCopyIndex.snapshot_history_index_boundsConsider a history of operations on a tape of integer-valued source labels. An operation either assigns labels given by an affine function of the destination address on a half-open interval, or copies labels from a source range as they were before that operation. Source and destination ranges may overlap. The history is stored newest first. Form the sorted set of all target interval endpoints and let be the bit length of its size. Build a persistent interval index that stores the last writer at every version. To recover the current label at an address, use the index to find its last writer and, for a copy, continue at the corresponding source address in the preceding version.
The index returns the same label as eager evaluation for every initial labeling and address. With the sorted endpoints supplied, building the index uses at most counted endpoint comparisons and tree-node visits in total. A query uses at most of these counted operations per last-writer lookup and makes at most such lookups. There are at most distinct endpoints.
import Definitions.Def_PvsNP_SnapshotHistoryIndex import Mathlib.Data.Finset.Sort import Mathlib.Data.Nat.Size open PvsNP.LazyCopyIndex PvsNP.SourceIntervalMap
theorem PvsNP.LazyCopyIndex.snapshot_history_index_bounds (history : List Instruction) (initial : Origins) (address : ℕ) :
let cuts := cutsOf history
let keys := cuts.sort.toArray
let depth := cuts.card.size
let table := buildFast keys depth history
let result := resolveFast table.1 keys initial history.length address
result.origin = eval history initial address ∧
table.2 ≤ (6*depth+1)*history.length ∧
result.nodeVisits ≤ (2*depth+1)*result.probes ∧
result.probes ≤ history.length+1 ∧
cuts.card ≤ 2*history.length := by sorry