File size: 3,019 Bytes
5d5048e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import OAI.Combinatorics.LowSpaceSubsetSum.Storage.OrderedMixerCells
import OAI.Combinatorics.LowSpaceSubsetSum.Storage.BackgroundPreparationCells
import OAI.Combinatorics.LowSpaceSubsetSum.Storage.StoredLeafCells
import OAI.Combinatorics.LowSpaceSubsetSum.Representation.RepresentationLeafArrays

namespace OAI

/-! # Live storage while constructing all leaf profiles

The ordered mixer arrays and completed background rows stay shared through
all eight finite-set profile constructions.
-/

noncomputable section
namespace LowSpaceSubsetSum.LeafArraysCells

variable {n : ℕ}

def run (I : Instance n) (data : RepresentationPrefixArrays.Data n) :
    (Option (RepresentationLeafArrays.Leaves n) × ℕ) × ℕ :=
  let ordered := OrderedMixerCells.run data.layout
  match ordered.1.1 with
  | none => ((none, ordered.1.2+1), ordered.2+16*n+128)
  | some domains =>
    let background := BackgroundPreparationCells.run I data.layout.permutation data.guesses
    match background.1.1 with
    | none => ((none, ordered.1.2+background.1.2+2), ordered.2+background.2+16*n+128)
    | some rows =>
      let out := StoredLeafCells.run domains data.partitions rows data.guesses
      ((some out.1.1, ordered.1.2+background.1.2+out.1.2+3),
        ordered.2+background.2+out.2+16*n+128)

theorem value (I : Instance n) (data : RepresentationPrefixArrays.Data n) :
    (run I data).1 = RepresentationLeafArrays.run I data := by
  have ho₁ := congrArg Prod.fst (OrderedMixerCells.value data.layout)
  have ho₂ := congrArg Prod.snd (OrderedMixerCells.value data.layout)
  have hb₁ := congrArg Prod.fst (BackgroundPreparationCells.value I data.layout.permutation data.guesses)
  have hb₂ := congrArg Prod.snd (BackgroundPreparationCells.value I data.layout.permutation data.guesses)
  simp only [run, RepresentationLeafArrays.run, ho₁, ho₂, hb₁, hb₂]
  split
  · simp_all only
  · split
    · simp_all only
    · simp_all only [StoredLeafCells.value]

theorem cells (I : Instance n) (data : RepresentationPrefixArrays.Data n)
    (hl : ∀ j : Fin 3, data.layout.domains[j.val].length ≤ n) :
    (run I data).2 ≤ 16384*(n+1)^2 := by
  have ho := OrderedMixerCells.cells data.layout hl
  have hb := BackgroundPreparationCells.cells I data.layout.permutation data.guesses
  unfold run
  dsimp only
  split
  · nlinarith only [ho, Nat.zero_le (n^2)]
  next domains hd =>
    split
    · nlinarith only [ho, hb, Nat.zero_le (n^2)]
    next rows hr =>
      have hs : (RepresentationBackgroundPreparation.run I data.layout.permutation data.guesses).1 =
          some rows := by
        rw [← BackgroundPreparationCells.value I data.layout.permutation data.guesses]
        exact hr
      have hw := StoredLeafCells.cells domains data.partitions rows data.guesses
        (RepresentationBackgroundPreparation.lengths I data.layout.permutation data.guesses rows hs)
      change _+_+_+16*n+128 ≤ _
      nlinarith only [ho, hb, hw, Nat.zero_le (n^2)]

end LowSpaceSubsetSum.LeafArraysCells

end

end OAI