Download lean/OAI/Combinatorics/PerfectMatching/Basic.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 4.06 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/PerfectMatching/Basic.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Combinatorics/PerfectMatching/Basic.lean
-
curl -L -o Basic.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/PerfectMatching/Basic.lean
4.06 kB
| import OAI.Combinatorics.PerfectMatching.Model | |
| import OAI.Combinatorics.PerfectMatching.Simplex | |
| namespace OAI | |
| /-! | |
| Finite loopless multigraphs, perfect matching indicators, and their convex hull. | |
| The edge type distinguishes parallel edges. Feasible laws are probability vectors | |
| on perfect matchings with a prescribed mean. | |
| -/ | |
| noncomputable section | |
| open scoped BigOperators Topology | |
| open Filter | |
| namespace MatchingEntropy | |
| variable {V E : Type*} [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] | |
| namespace LooplessGraph | |
| instance incidentDecidable (G : LooplessGraph V E) (v : V) (e : E) : | |
| Decidable (G.Incident v e) := inferInstanceAs (Decidable (G.left e = v ∨ G.right e = v)) | |
| def indicator (G : LooplessGraph V E) (M : G.Matching) (e : E) : ℝ := | |
| if e ∈ M.val then 1 else 0 | |
| def polytope (G : LooplessGraph V E) : Set (E → ℝ) := | |
| convexHull ℝ (Set.range G.indicator) | |
| def mean (G : LooplessGraph V E) (p : G.Matching → ℝ) (e : E) : ℝ := | |
| ∑ M, p M * G.indicator M e | |
| def feasibleLaws (G : LooplessGraph V E) (y : E → ℝ) : Set (G.Matching → ℝ) := | |
| {p | p ∈ probabilitySimplex G.Matching ∧ G.mean p = y} | |
| omit [Fintype V] [Fintype E] [DecidableEq V] in | |
| @[simp] theorem indicator_nonneg (G : LooplessGraph V E) (M : G.Matching) (e : E) : | |
| 0 ≤ G.indicator M e := by | |
| simp only [indicator] | |
| split <;> norm_num | |
| omit [Fintype V] [Fintype E] [DecidableEq V] in | |
| @[simp] theorem indicator_le_one (G : LooplessGraph V E) (M : G.Matching) (e : E) : | |
| G.indicator M e ≤ 1 := by | |
| simp only [indicator] | |
| split <;> norm_num | |
| omit [Fintype V] [DecidableEq V] in | |
| theorem continuous_mean (G : LooplessGraph V E) : Continuous G.mean := by | |
| unfold mean | |
| fun_prop | |
| def meanLinear (G : LooplessGraph V E) : (G.Matching → ℝ) →ₗ[ℝ] (E → ℝ) where | |
| toFun := G.mean | |
| map_add' p q := by | |
| ext e | |
| simp [mean, add_mul, Finset.sum_add_distrib] | |
| map_smul' a p := by | |
| ext e | |
| simp [mean, mul_assoc, Finset.mul_sum] | |
| omit [Fintype V] [DecidableEq V] in | |
| theorem mean_mem_polytope (G : LooplessGraph V E) {p : G.Matching → ℝ} | |
| (hp : p ∈ probabilitySimplex G.Matching) : G.mean p ∈ G.polytope := by | |
| have h := (convex_convexHull ℝ (Set.range G.indicator)).sum_mem | |
| (fun M _ ↦ hp.1 M) hp.2 (fun M _ ↦ subset_convexHull ℝ _ (Set.mem_range_self M)) | |
| have he : G.mean p = ∑ M, p M • G.indicator M := by | |
| ext e | |
| simp [mean] | |
| rw [he] | |
| exact h | |
| omit [Fintype V] [DecidableEq V] in | |
| @[simp] theorem mean_single (G : LooplessGraph V E) (M : G.Matching) : | |
| G.mean (Pi.single M 1) = G.indicator M := by | |
| classical | |
| ext e | |
| simp [mean, Pi.single_apply, ite_mul] | |
| omit [Fintype V] [DecidableEq V] in | |
| /-- Exact equivalence between the convex hull of matching indicators and feasible finite laws. -/ | |
| theorem mem_polytope_iff (G : LooplessGraph V E) (y : E → ℝ) : | |
| y ∈ G.polytope ↔ (G.feasibleLaws y).Nonempty := by | |
| classical | |
| constructor | |
| · intro hy | |
| have hc : Convex ℝ (G.mean '' probabilitySimplex G.Matching) := | |
| (convex_probabilitySimplex G.Matching).linear_image G.meanLinear | |
| have hs : Set.range G.indicator ⊆ G.mean '' probabilitySimplex G.Matching := by | |
| rintro _ ⟨M, rfl⟩ | |
| exact ⟨Pi.single M 1, single_mem_probabilitySimplex M, G.mean_single M⟩ | |
| obtain ⟨p, hp, rfl⟩ := convexHull_min hs hc hy | |
| exact ⟨p, hp, rfl⟩ | |
| · rintro ⟨p, hp, rfl⟩ | |
| exact G.mean_mem_polytope hp | |
| omit [Fintype V] [DecidableEq V] in | |
| theorem compact_feasibleLaws (G : LooplessGraph V E) (y : E → ℝ) : | |
| IsCompact (G.feasibleLaws y) := by | |
| exact (isCompact_probabilitySimplex G.Matching).inter_right | |
| (isClosed_eq G.continuous_mean continuous_const) | |
| omit [Fintype V] [DecidableEq V] in | |
| theorem compact_polytope (G : LooplessGraph V E) : IsCompact G.polytope := by | |
| have heq : G.polytope = G.mean '' probabilitySimplex G.Matching := by | |
| ext y | |
| rw [G.mem_polytope_iff] | |
| rfl | |
| rw [heq] | |
| exact (isCompact_probabilitySimplex G.Matching).image G.continuous_mean | |
| end LooplessGraph | |
| end MatchingEntropy | |
| end | |
| end OAI | |