File size: 4,529 Bytes
f18e7de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.LinearAlgebra.MatrixMultiplication.Recovery.PermutationMatchingMoments

namespace OAI

/-! Finite orbit symmetries, masks and exact recovery operations. -/

noncomputable section

namespace MatrixMultiplication.PermutationMatching

open scoped BigOperators
open Classical

variable {P : Type*} [Fintype P] [DecidableEq P]

def twoHalfCount (A B : Finset P) (left right : Equiv.Perm P) : ℝ :=
  ∑ i : P, if left i ∈ A ∧ right i ∈ B then 1 else 0

theorem twoHalfCount_eq_matchingCount (A B : Finset P)
    (left right : Equiv.Perm P) :
    twoHalfCount A B left right =
      matchingCount A B (left.symm.trans right) := by
  classical
  unfold twoHalfCount matchingCount membership
  calc
    _ = ∑ i : P, if i ∈ A ∧ right (left.symm i) ∈ B then (1 : ℝ) else 0 := by
      simpa only [Equiv.symm_apply_apply] using
        Equiv.sum_comp left (fun i =>
          if i ∈ A ∧ right (left.symm i) ∈ B then (1 : ℝ) else 0)
    _ = ∑ i : P, if i ∈ A then
        (if right (left.symm i) ∈ B then (1 : ℝ) else 0) else 0 := by
      apply Finset.sum_congr rfl
      intro i _
      split_ifs <;> simp_all
    _ = _ := by
      simp only [Equiv.trans_apply, Fintype.sum_ite_mem]
      apply Finset.sum_congr rfl
      intro i _
      apply if_congr <;> rfl

def relativePairEquiv :
    (Equiv.Perm P × Equiv.Perm P) ≃ (Equiv.Perm P × Equiv.Perm P) where
  toFun lr := (lr.1, lr.1.symm.trans lr.2)
  invFun lq := (lq.1, lq.1.trans lq.2)
  left_inv := by
    rintro ⟨left, right⟩
    dsimp only
    apply Prod.ext
    · rfl
    · ext i
      simp
  right_inv := by
    rintro ⟨left, relative⟩
    dsimp only
    apply Prod.ext
    · rfl
    · ext i
      simp

theorem average_relativePerm (f : Equiv.Perm P → ℝ) :
    average (fun lr : Equiv.Perm P × Equiv.Perm P =>
      f (lr.1.symm.trans lr.2)) = average f := by
  calc
    _ = average (fun lq : Equiv.Perm P × Equiv.Perm P => f lq.2) :=
      average_equiv relativePairEquiv (fun lq => f lq.2)
    _ = _ := average_prod_snd f

theorem average_twoHalfCount (A B : Finset P) (f : ℝ → ℝ) :
    average (fun lr : Equiv.Perm P × Equiv.Perm P =>
      f (twoHalfCount A B lr.1 lr.2)) =
      average (fun p : Equiv.Perm P => f (matchingCount A B p)) := by
  simp_rw [twoHalfCount_eq_matchingCount]
  exact average_relativePerm (fun p => f (matchingCount A B p))

theorem twoHalfCount_statisticPositions {X Y S T : Type*}
    (leftWord : P → X) (rightWord : P → Y) (sl : X → S) (sr : Y → T)
    (s : S) (t : T) (left right : Equiv.Perm P) :
    twoHalfCount (statisticPositions leftWord sl s)
        (statisticPositions rightWord sr t) left right =
      ∑ i : P, if sl (leftWord (left i)) = s ∧ sr (rightWord (right i)) = t
        then (1 : ℝ) else 0 := by
  classical
  simp [twoHalfCount, statisticPositions]

section Families

variable {C : Type*} (Q : C → Type*)

def relativeFamily
    (left right : ∀ c, Equiv.Perm (Q c)) : ∀ c, Equiv.Perm (Q c) :=
  fun c => (left c).symm.trans (right c)

def relativeFamilyPairEquiv :
    ((∀ c, Equiv.Perm (Q c)) × (∀ c, Equiv.Perm (Q c))) ≃
      ((∀ c, Equiv.Perm (Q c)) × (∀ c, Equiv.Perm (Q c))) where
  toFun lr := (lr.1, relativeFamily Q lr.1 lr.2)
  invFun lq := (lq.1, fun c => (lq.1 c).trans (lq.2 c))
  left_inv := by
    rintro ⟨left, right⟩
    dsimp only
    apply Prod.ext
    · rfl
    · funext c
      ext i
      simp [relativeFamily]
  right_inv := by
    rintro ⟨left, relative⟩
    dsimp only
    apply Prod.ext
    · rfl
    · funext c
      ext i
      simp [relativeFamily]

variable [Fintype C] [DecidableEq C]
  [∀ c, Fintype (Q c)] [∀ c, DecidableEq (Q c)]

theorem average_relativeFamily (f : (∀ c, Equiv.Perm (Q c)) → ℝ) :
    average (fun lr :
        (∀ c, Equiv.Perm (Q c)) × (∀ c, Equiv.Perm (Q c)) =>
      f (relativeFamily Q lr.1 lr.2)) = average f := by
  calc
    _ = average (fun lq :
        (∀ c, Equiv.Perm (Q c)) × (∀ c, Equiv.Perm (Q c)) => f lq.2) :=
      average_equiv (relativeFamilyPairEquiv Q) (fun lq => f lq.2)
    _ = _ := average_prod_snd f

omit [DecidableEq C] in
theorem sum_twoHalfCount_eq_matchingCount
    (A B : ∀ c, Finset (Q c)) (left right : ∀ c, Equiv.Perm (Q c)) :
    (∑ c, twoHalfCount (A c) (B c) (left c) (right c)) =
      ∑ c, matchingCount (A c) (B c) (relativeFamily Q left right c) := by
  simp only [twoHalfCount_eq_matchingCount, relativeFamily]

end Families

end MatrixMultiplication.PermutationMatching

end

end OAI