Download data/lean/OAI/Computability/LoopMatching/Approximation.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.75 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/LoopMatching/Approximation.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/LoopMatching/Approximation.lean
-
curl -L -o Approximation.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/LoopMatching/Approximation.lean
5.75 kB
| import OAI.Computability.LoopMatching.Accumulator | |
| import OAI.Computability.LoopMatching.CountDecomposition | |
| import OAI.Computability.LoopMatching.ExpandInput | |
| import OAI.Computability.MatchingCount.BinarySolve | |
| namespace OAI | |
| /-! Polynomial-time approximation of weighted matchings with singleton loops. -/ | |
| namespace LoopMatching | |
| open scoped BigOperators | |
| namespace Approximation | |
| def term (G : Input) (j : β) : β := | |
| BinaryMatching.Raw.InputData.sparseEstimate (expand G j) | |
| def output (G : Input) : β Γ β := | |
| (Accumulator.Q (term G) G.n, G.n.factorial) | |
| theorem term_bounds (G : Input) (j : β) : | |
| term G j β€ BinaryMatching.count (expand G j) β§ | |
| BinaryMatching.count (expand G j) β€ 2 ^ (9 * (G.n + j)) * term G j β§ | |
| (term G j = 0 β BinaryMatching.count (expand G j) = 0) := by | |
| simpa only [term, expand_n] using | |
| BinaryMatching.Raw.InputData.sparseEstimate_correct (expand G j) | |
| theorem output_den_pos (G : Input) : 0 < (output G).2 := Nat.factorial_pos _ | |
| theorem output_value (G : Input) : | |
| outputValue (output G) = | |
| β j β Finset.range (G.n + 1), (term G j : β) / (j.factorial : β) := | |
| Accumulator.quotient_eq_sum (term G) G.n | |
| theorem factorial_profile_bounds (a b : β β β) (C n : β) | |
| (hlo : β j β€ n, a j β€ j.factorial * b j) | |
| (hhi : β j β€ n, j.factorial * b j β€ C * a j) : | |
| Accumulator.Q a n β€ n.factorial * (β j β Finset.range (n + 1), b j) β§ | |
| n.factorial * (β j β Finset.range (n + 1), b j) β€ C * Accumulator.Q a n := by | |
| revert hlo hhi | |
| induction n with | |
| | zero => | |
| intro hlo hhi | |
| simpa using And.intro (hlo 0 (by omega)) (hhi 0 (by omega)) | |
| | succ n ih => | |
| intro hlo hhi | |
| obtain β¨hl, huβ© := ih (fun j hj => hlo j (by omega)) | |
| (fun j hj => hhi j (by omega)) | |
| have hlastlo := hlo (n + 1) (by omega) | |
| have hlasthi := hhi (n + 1) (by omega) | |
| rw [Accumulator.Q_succ, Finset.sum_range_succ] | |
| constructor | |
| Β· calc | |
| (n + 1) * Accumulator.Q a n + a (n + 1) β€ | |
| (n + 1) * (n.factorial * (β j β Finset.range (n + 1), b j)) + | |
| (n + 1).factorial * b (n + 1) := | |
| Nat.add_le_add (Nat.mul_le_mul_left _ hl) hlastlo | |
| _ = (n + 1).factorial * | |
| ((β j β Finset.range (n + 1), b j) + b (n + 1)) := by | |
| rw [Nat.factorial_succ]; ring | |
| Β· calc | |
| (n + 1).factorial * | |
| ((β j β Finset.range (n + 1), b j) + b (n + 1)) = | |
| (n + 1) * (n.factorial * (β j β Finset.range (n + 1), b j)) + | |
| (n + 1).factorial * b (n + 1) := by | |
| rw [Nat.factorial_succ]; ring | |
| _ β€ (n + 1) * (C * Accumulator.Q a n) + C * a (n + 1) := | |
| Nat.add_le_add (Nat.mul_le_mul_left _ hu) hlasthi | |
| _ = C * ((n + 1) * Accumulator.Q a n + a (n + 1)) := by ring | |
| theorem output_bounds_of_expanded_count (G : Input) | |
| (expanded_count : β j β€ G.n, | |
| BinaryMatching.count (expand G j) = j.factorial * countWithLoops G j) : | |
| (output G).1 β€ (output G).2 * count G β§ | |
| (output G).2 * count G β€ 2 ^ (18 * G.n) * (output G).1 β§ | |
| ((output G).1 = 0 β count G = 0) := by | |
| have hlo : β j β€ G.n, term G j β€ j.factorial * countWithLoops G j := by | |
| intro j hj | |
| rw [β expanded_count j hj] | |
| exact (term_bounds G j).1 | |
| have hhi : β j β€ G.n, | |
| j.factorial * countWithLoops G j β€ 2 ^ (18 * G.n) * term G j := by | |
| intro j hj | |
| rw [β expanded_count j hj] | |
| apply (term_bounds G j).2.1.trans | |
| apply Nat.mul_le_mul_right | |
| apply Nat.pow_le_pow_right (by omega : 1 β€ (2 : β)) | |
| omega | |
| obtain β¨hl, huβ© := factorial_profile_bounds (term G) (countWithLoops G) | |
| (2 ^ (18 * G.n)) G.n hlo hhi | |
| rw [β count_eq_sum_countWithLoops G] at hl hu | |
| change (output G).1 β€ (output G).2 * count G at hl | |
| change (output G).2 * count G β€ 2 ^ (18 * G.n) * (output G).1 at hu | |
| refine β¨hl, hu, ?_β© | |
| constructor | |
| Β· intro hz | |
| rw [hz, mul_zero] at hu | |
| have hprod : (output G).2 * count G = 0 := Nat.eq_zero_of_le_zero hu | |
| exact (Nat.mul_eq_zero.mp hprod).resolve_left (Nat.ne_of_gt (output_den_pos G)) | |
| Β· intro hz | |
| rw [hz, mul_zero] at hl | |
| exact Nat.eq_zero_of_le_zero hl | |
| theorem output_magnitude (G : Input) (B : β) | |
| (hB : β j β€ G.n, term G j β€ B) : | |
| (output G).1 β€ (G.n + 1).factorial * B β§ | |
| (output G).2 = G.n.factorial := | |
| β¨Accumulator.Q_le_factorial_mul (term G) G.n B hB, rflβ© | |
| private theorem succ_le_two_pow (n : β) : n + 1 β€ 2 ^ n := by | |
| induction n with | |
| | zero => simp | |
| | succ n ih => | |
| rw [pow_succ] | |
| have hp : 0 < 2 ^ n := by positivity | |
| omega | |
| theorem factorial_le_two_pow_square (n : β) : n.factorial β€ 2 ^ (n * n) := by | |
| induction n with | |
| | zero => simp | |
| | succ n ih => | |
| calc | |
| (n + 1).factorial = (n + 1) * n.factorial := Nat.factorial_succ n | |
| _ β€ 2 ^ n * 2 ^ (n * n) := Nat.mul_le_mul (succ_le_two_pow n) ih | |
| _ = 2 ^ (n + n * n) := (pow_add 2 n (n * n)).symm | |
| _ β€ 2 ^ ((n + 1) * (n + 1)) := by | |
| apply Nat.pow_le_pow_right (by omega : 1 β€ (2 : β)) | |
| nlinarith | |
| theorem output_exponential_magnitude (G : Input) (B : β) | |
| (hB : β j β€ G.n, term G j β€ 2 ^ B) : | |
| (output G).1 β€ 2 ^ ((G.n + 1) * (G.n + 1) + B) β§ | |
| (output G).2 β€ 2 ^ (G.n * G.n) := by | |
| constructor | |
| Β· calc | |
| (output G).1 β€ (G.n + 1).factorial * 2 ^ B := | |
| (output_magnitude G (2 ^ B) hB).1 | |
| _ β€ 2 ^ ((G.n + 1) * (G.n + 1)) * 2 ^ B := | |
| Nat.mul_le_mul_right _ (factorial_le_two_pow_square (G.n + 1)) | |
| _ = 2 ^ ((G.n + 1) * (G.n + 1) + B) := (pow_add _ _ _).symm | |
| Β· exact factorial_le_two_pow_square G.n | |
| end Approximation | |
| end LoopMatching | |
| end OAI | |