File size: 2,330 Bytes
16a4018 | 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 | import Mathlib
namespace OAI
universe u_1 u_2
namespace MatchingEntropy
structure LooplessGraph (V : Type u_1) (E : Type u_2) where
left : E → V
right : E → V
loopless : ∀ e, left e ≠ right e
namespace LooplessGraph
variable {V : Type u_1} {E : Type u_2} [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E]
def Incident (G : LooplessGraph V E) (v : V) (e : E) : Prop :=
G.left e=v ∨ G.right e=v
def IsPerfectMatching (G : LooplessGraph V E) (M : Finset E) : Prop :=
∀ v, ∃! e, e∈M ∧ G.Incident v e
abbrev Matching (G : LooplessGraph V E) := {M : Finset E // G.IsPerfectMatching M}
noncomputable instance matchingFintype (G : LooplessGraph V E) : Fintype G.Matching :=
Fintype.ofFinite _
end LooplessGraph
end MatchingEntropy
namespace BinaryMatching
abbrev Pair (n : ℕ) := {ij : Fin n × Fin n // ij.1 < ij.2}
def completeGraph (n : ℕ) : MatchingEntropy.LooplessGraph (Fin n) (Pair n) where
left e := e.val.1
right e := e.val.2
loopless e := ne_of_lt e.property
structure Record where
left : ℕ
right : ℕ
multiplicity : ℕ
deriving DecidableEq
structure Input where
n : ℕ
records : List Record
valid : ∀ e∈records, e.left < e.right ∧ e.right < n
unique : (records.map (fun e => (e.left,e.right))).Nodup
def multiplicity (G : Input) (e : Pair G.n) : ℕ :=
match G.records.find? (fun r => r.left=e.val.1.val && r.right=e.val.2.val) with
| none => 0
| some r => r.multiplicity
noncomputable def count (G : Input) : ℕ :=
∑ M : (completeGraph G.n).Matching, ∏ e∈M.val, multiplicity G e
def encodeNat (n : ℕ) : List Bool :=
List.replicate n.bits.length false ++ true :: n.bits
def encodeRecord (r : Record) : List Bool :=
encodeNat r.left ++ encodeNat r.right ++ encodeNat r.multiplicity
def encodeInput (G : Input) : List Bool :=
encodeNat G.n ++ encodeNat G.records.length ++ G.records.flatMap encodeRecord
theorem deterministic_approximate_counting :
∃ A : Input → ℕ,
∃ machine : Turing.TM2ComputableInPolyTime encodeInput Nat.bits A,
(∀ k, Finite (machine.tm.Γ k)) ∧
(∃ P : Polynomial ℕ, ∀ G,(A G).bits.length≤P.eval (encodeInput G).length) ∧
∀ G,A G≤count G ∧ count G≤2^(9*G.n)*A G ∧ (A G=0 ↔ count G=0) := by
sorry
end BinaryMatching
end OAI
|