File size: 7,912 Bytes
cdec422
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import OAI.LinearAlgebra.MatrixMultiplication.Completion.HierarchyWords
import OAI.LinearAlgebra.MatrixMultiplication.Entropy.ComplexConditionalHierarchyStage
import OAI.LinearAlgebra.MatrixMultiplication.Separation.ComplexPrefixSeparationOrientations
import OAI.LinearAlgebra.MatrixMultiplication.Tensor.ComplexGeometricStageCoordinates

namespace OAI

/-! Readable tensor completion and its finite arithmetic realization. -/

noncomputable section

namespace MatrixMultiplication.CompletionGeometricValues

open MatrixMultiplication.Foundation
open CompletionHierarchyWords ConditionalPrefixWords
open ConditionalHierarchyStage PrefixSeparationPolynomialStage PrefixSeparationOrientations
open StageHierarchyResources
open scoped Classical

variable {A X Y Z : Type*} [Fintype A] (H : ReadableHierarchy A X Y Z)
variable {Position : Type*} [Fintype Position] {counts : A → ℕ} {n t : ℕ}

abbrev size (counts : A → ℕ) (n t : ℕ) := stageRefinementCount counts H.labels n t

theorem actualPool_decode (old : ExactPrefix counts H.labels n t Position)
    (code : Fin (size H counts n t)) :
    decodePool (actualPool counts H.labels n t id) (size H counts n t)
      (actualPool_card counts H.labels n t id) old code =
        ((conditionalPoolEquivFin old).symm code).val := rfl

theorem decode_eq_iff_eligible (old : ExactPrefix counts H.labels n t Position)
    (code : Fin (size H counts n t))
    (u : Position → X) (v : Position → Y) (w : Position → Z)
    (word : Position → A) (hword : Represents H id old u v w word) :
    decodePool (actualPool counts H.labels n t id) (size H counts n t)
      (actualPool_card counts H.labels n t id) old code = (fun i => H.labels n (word i)) ↔
        eligible H id (appendCode old code) u v w := by
  rw [actualPool_decode]
  exact (eligible_appendCode_iff_of_represents H old code u v w word hword).symm

theorem raw_XY_normal
    (old : ExactPrefix counts H.labels n t Position) (hn : n < H.depth)
    (hp : H.pair n = .xy)
    (x : (Position → X) × InformedOutput (size H counts n t))
    (y : (Position → Y) × InformedOutput (size H counts n t))
    (z : (Position → Z) × MissingOutput (size H counts n t))
    (word : Position → A) (hword : Represents H id old x.1 y.1 z.1 word) :
    rawPoolLeading (actualPool counts H.labels n t id) (size H counts n t)
      (stageRefinementCount_pos counts H.labels n t) (actualPool_card counts H.labels n t id)
      (readXYX H id hp) (readXYY H id hp) old x y z =
        if x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧
          eligible H id (appendCode old x.2.1) x.1 y.1 z.1 then
            (GeometricStageCoordinates.xy (size H counts n t)).tensor x.2.2 y.2.2 z.2.2
        else 0 := by
  have hx : readXYX H id hp old x.1 = fun i => H.labels n (word i) := by
    rw [hword.1]
    exact readXYX_on_original_word H id hp old word hn hword.2.2.2
  have hy : readXYY H id hp old y.1 = fun i => H.labels n (word i) := by
    rw [hword.2.1]
    exact readXYY_on_original_word H id hp old word hn hword.2.2.2
  rw [rawPoolLeading_eq_decodedLeading    (actualPool counts H.labels n t id) (size H counts n t)    (stageRefinementCount_pos counts H.labels n t) (actualPool_card counts H.labels n t id)    (readXYX H id hp) (readXYY H id hp) (fun _ _ _ _ => fun i => H.labels n (word i))    old x y z hx hy]
  unfold decodedLeading
  simp only [decode_eq_iff_eligible H old x.2.1 x.1 y.1 z.1 word hword,    GeometricStageCoordinates.xy_tensor_apply]
  simp only [ite_and]

theorem raw_XZ_normal
    (old : ExactPrefix counts H.labels n t Position) (hn : n < H.depth)
    (hp : H.pair n = .xz)
    (x : (Position → X) × InformedOutput (size H counts n t))
    (y : (Position → Y) × MissingOutput (size H counts n t))
    (z : (Position → Z) × InformedOutput (size H counts n t))
    (word : Position → A) (hword : Represents H id old x.1 y.1 z.1 word) :
    rawPoolLeadingXZ (actualPool counts H.labels n t id) (size H counts n t)
      (stageRefinementCount_pos counts H.labels n t) (actualPool_card counts H.labels n t id)
      (readXZX H id hp) (readXZZ H id hp) old x y z =
        if x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧
          eligible H id (appendCode old x.2.1) x.1 y.1 z.1 then
            (GeometricStageCoordinates.xz (size H counts n t)).tensor x.2.2 y.2.2 z.2.2
        else 0 := by
  have hx : readXZX H id hp old x.1 = fun i => H.labels n (word i) := by
    rw [hword.1]
    exact readXZX_on_original_word H id hp old word hn hword.2.2.2
  have hz : readXZZ H id hp old z.1 = fun i => H.labels n (word i) := by
    rw [hword.2.2.1]
    exact readXZZ_on_original_word H id hp old word hn hword.2.2.2
  unfold rawPoolLeadingXZ
  rw [rawPoolLeading_eq_decodedLeading    (actualPool counts H.labels n t id) (size H counts n t)    (stageRefinementCount_pos counts H.labels n t) (actualPool_card counts H.labels n t id)    (readXZX H id hp) (readXZZ H id hp) (fun _ _ _ _ => fun i => H.labels n (word i))    old x z y hx hz]
  unfold decodedLeading
  simp only [decode_eq_iff_eligible H old x.2.1 x.1 y.1 z.1 word hword,    GeometricStageCoordinates.xz_tensor_apply]
  have hswap :
      (x.2.1 = z.2.1 ∧ x.2.1 = y.2.1 ∧
        eligible H id (appendCode old x.2.1) x.1 y.1 z.1 ∧ x.2.2 = z.2.2) ↔
      (x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧
        eligible H id (appendCode old x.2.1) x.1 y.1 z.1 ∧ x.2.2 = z.2.2) :=
    and_left_comm
  simp only [hswap, ite_and]

theorem raw_YZ_normal
    (old : ExactPrefix counts H.labels n t Position) (hn : n < H.depth)
    (hp : H.pair n = .yz)
    (x : (Position → X) × MissingOutput (size H counts n t))
    (y : (Position → Y) × InformedOutput (size H counts n t))
    (z : (Position → Z) × InformedOutput (size H counts n t))
    (word : Position → A) (hword : Represents H id old x.1 y.1 z.1 word) :
    rawPoolLeadingYZ (actualPool counts H.labels n t id) (size H counts n t)
      (stageRefinementCount_pos counts H.labels n t) (actualPool_card counts H.labels n t id)
      (readYZY H id hp) (readYZZ H id hp) old x y z =
        if x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧
          eligible H id (appendCode old x.2.1) x.1 y.1 z.1 then
            (GeometricStageCoordinates.yz (size H counts n t)).tensor x.2.2 y.2.2 z.2.2
        else 0 := by
  have hy : readYZY H id hp old y.1 = fun i => H.labels n (word i) := by
    rw [hword.2.1]
    exact readYZY_on_original_word H id hp old word hn hword.2.2.2
  have hz : readYZZ H id hp old z.1 = fun i => H.labels n (word i) := by
    rw [hword.2.2.1]
    exact readYZZ_on_original_word H id hp old word hn hword.2.2.2
  unfold rawPoolLeadingYZ
  rw [rawPoolLeading_eq_decodedLeading    (actualPool counts H.labels n t id) (size H counts n t)    (stageRefinementCount_pos counts H.labels n t) (actualPool_card counts H.labels n t id)    (readYZY H id hp) (readYZZ H id hp) (fun _ _ _ _ => fun i => H.labels n (word i))    old y z x hy hz]
  have hguard :
      (y.2.1 = z.2.1 ∧ y.2.1 = x.2.1 ∧
        decodePool (actualPool counts H.labels n t id) (size H counts n t)
          (actualPool_card counts H.labels n t id) old y.2.1 = (fun i => H.labels n (word i)) ∧
        y.2.2 = z.2.2) ↔
      (x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧
        eligible H id (appendCode old x.2.1) x.1 y.1 z.1 ∧ y.2.2 = z.2.2) := by
    constructor
    · rintro ⟨hyz, hyx, hdecode, hpair⟩
      refine ⟨hyx.symm, hyx.symm.trans hyz, ?_, hpair⟩
      apply (decode_eq_iff_eligible H old x.2.1 x.1 y.1 z.1 word hword).mp
      simpa only [hyx] using hdecode
    · rintro ⟨hxy, hxz, he, hpair⟩
      refine ⟨hxy.symm.trans hxz, hxy.symm, ?_, hpair⟩
      have hdecode := (decode_eq_iff_eligible H old x.2.1 x.1 y.1 z.1 word hword).mpr he
      simpa only [hxy] using hdecode
  unfold decodedLeading
  simp only [hguard, GeometricStageCoordinates.yz_tensor_apply]
  simp only [ite_and]

end MatrixMultiplication.CompletionGeometricValues

end

end OAI