File size: 2,642 Bytes
180bc03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import OAI.NumberTheory.TwoPoint.Walks.ColumnRunEncoding

namespace OAI

/-! Run bits may force a split at a perfect-block boundary without changing its label. -/

namespace TwoPointCorrelations

variable {α : Type*} [DecidableEq α]

def columnFlagsWithCuts : List (Option α × Bool) → Option α → List (Bool × Bool)
  | [], _ => []
  | (none, _) :: rest, _ => (true, false) :: columnFlagsWithCuts rest none
  | (some a, cut) :: rest, previous =>
      (false, cut || decide (previous ≠ some a)) :: columnFlagsWithCuts rest (some a)

def columnRunHeadsWithCuts : List (Option α × Bool) → Option α → List α
  | [], _ => []
  | (none, _) :: rest, _ => columnRunHeadsWithCuts rest none
  | (some a, cut) :: rest, previous =>
      if cut = false ∧ previous = some a then columnRunHeadsWithCuts rest (some a)
      else a :: columnRunHeadsWithCuts rest (some a)

@[simp] theorem columnFlagsWithCuts_length (entries : List (Option α × Bool)) (previous : Option α) :
    (columnFlagsWithCuts entries previous).length = entries.length := by
  induction entries generalizing previous with
  | nil => rfl
  | cons entry rest ih => rcases entry with ⟨a, cut⟩; cases a <;> simp [columnFlagsWithCuts, ih]

/-- A forced boundary consumes a run label even when the adjacent blocks
end and start with the same label. Arbitrary unused labels remain harmless. -/
theorem expandColumnRuns_cuts_recover (entries : List (Option CanonicalColumnLabel × Bool))
    (previous : Option CanonicalColumnLabel) (tail : List CanonicalColumnLabel) :
    expandColumnRuns (columnFlagsWithCuts entries previous)
      (columnRunHeadsWithCuts entries previous ++ tail) previous = entries.map Prod.fst := by
  induction entries generalizing previous with
  | nil => rfl
  | cons entry rest ih =>
      rcases entry with ⟨a, cut⟩
      cases a with
      | none => simpa [columnFlagsWithCuts, columnRunHeadsWithCuts, expandColumnRuns] using
          congrArg (List.cons none) (ih none)
      | some a =>
          cases cut with
          | true =>
              simpa [columnFlagsWithCuts, columnRunHeadsWithCuts, expandColumnRuns] using
                congrArg (List.cons (some a)) (ih (some a))
          | false =>
              by_cases h : previous = some a
              · subst previous
                simpa [columnFlagsWithCuts, columnRunHeadsWithCuts, expandColumnRuns] using
                  congrArg (List.cons (some a)) (ih (some a))
              · simpa [columnFlagsWithCuts, columnRunHeadsWithCuts, h, expandColumnRuns] using
                  congrArg (List.cons (some a)) (ih (some a))

end TwoPointCorrelations

end OAI