File size: 2,422 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Mathlib
import OAI.Combinatorics.MatchingCount.Machines.TreeReach
import OAI.Combinatorics.MatchingCount.Machines.TreeStateTable

namespace OAI

namespace MatchingFPRAS.ExecutableLadder
open TreeTyped Polynomial

variable {I E : Type} [Codec I] [Codec E] [DecidableEq I] [Inhabited I] [LinearOrder E]
abbrev StateEnvelope (I E : Type) := List IΓ—Finset E

def normalizeState (x : StateEnvelope I EΓ—StateTable I (Finset E)) : StateTable I (Finset E) :=
  x.1.1.map (fun i=>(i,lookup βˆ… (x.2,i)∩x.1.2))
def normalizeStateRealizer (Eq : Realizer (fun x : IΓ—I=>decide (x.1=x.2)))
    (EqE : Realizer (fun x : EΓ—E=>decide (x.1=x.2))) : Realizer (normalizeState (I:=I) (E:=E)) :=
  (composition (pair identity first.fst) (mapWith (pair second
    (composition (pair (composition (pair first.snd second) (lookupRealizer βˆ… Eq)) first.fst.snd)
      (finsetInter EqE))))).congr (fun _=>rfl)
lemma polynomial_normalizeState {Eq : Realizer (fun x : IΓ—I=>decide (x.1=x.2))}
    {EqE : Realizer (fun x : EΓ—E=>decide (x.1=x.2))}
    (hEq : PolynomialTime Eq) (hE : PolynomialTime EqE) : PolynomialTime (normalizeStateRealizer Eq EqE) := by
  unfold normalizeStateRealizer Realizer.fst Realizer.snd
  apply polynomial_congr
  have := polynomial_lookup (βˆ… : Finset E) hEq
  tree_cost

omit [Inhabited I] in
lemma normalizeState_weight (keys : List I) (univ : Finset E) (s : StateTable I (Finset E)) :
    weight (normalizeState ((keys,univ),s))≀(weight keys+1)*(weight univ+3) := by
  induction keys with
  | nil=>simp only [normalizeState,List.map_nil,weight_nil]; omega
  | cons i keys ih=>
    have hu : weight (lookup βˆ… (s,i)∩univ)≀weight univ := weight_finset_subset Finset.inter_subset_right
    change weight ((i,lookup βˆ… (s,i)∩univ)::normalizeState ((keys,univ),s))≀_
    rw [weight_cons,weight_prod,weight_cons]
    nlinarith

omit [Codec I] [Codec E] [Inhabited I] in
lemma normalizeState_rep {Ξ© : Type} (keys : List I) (univ : Finset E) (e : Ξ©β†’Finset E)
    (he : βˆ€ a,e aβŠ†univ) (s : Iβ†’Ξ©) :
    normalizeState ((keys,univ),stateRep keys (e ∘ s))=stateRep keys (e ∘ s) := by
  unfold normalizeState stateRep
  apply List.map_congr_left
  intro i hi
  change (i,lookup βˆ… (stateRep keys (e ∘ s),i)∩univ)=(i,e (s i))
  rw [lookup_stateRep βˆ… keys (e ∘ s) i hi]
  simp only [Function.comp_apply,Finset.inter_eq_left.mpr (he (s i))]
end MatchingFPRAS.ExecutableLadder

end OAI