math / data /lean /OAI /Computability /LoopMatching /Accumulator.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
2.29 kB
import Mathlib.Data.Nat.Factorial.Basic
import Mathlib.Data.Rat.BigOperators
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Positivity
namespace OAI
/-! Polynomial-time approximation of weighted matchings with singleton loops. -/
namespace LoopMatching.Accumulator
open scoped BigOperators
def Q (a : β„• β†’ β„•) : β„• β†’ β„•
| 0 => a 0
| n + 1 => (n + 1) * Q a n + a (n + 1)
@[simp] theorem Q_zero (a : β„• β†’ β„•) : Q a 0 = a 0 := rfl
@[simp] theorem Q_succ (a : β„• β†’ β„•) (n : β„•) :
Q a (n + 1) = (n + 1) * Q a n + a (n + 1) := rfl
theorem denominator_pos (n : β„•) : 0 < n.factorial := Nat.factorial_pos n
theorem quotient_eq_sum (a : β„• β†’ β„•) (n : β„•) :
(Q a n : β„š) / (n.factorial : β„š) =
βˆ‘ j ∈ Finset.range (n + 1), (a j : β„š) / (j.factorial : β„š) := by
induction n with
| zero => simp [Q]
| succ n ih =>
rw [Finset.sum_range_succ, ← ih, Q_succ, Nat.factorial_succ]
push_cast
have hn : (n : β„š) + 1 β‰  0 := by positivity
have hf : (n.factorial : β„š) β‰  0 := by
exact_mod_cast Nat.factorial_ne_zero n
field_simp [hn, hf]
theorem Q_le_factorial_mul (a : β„• β†’ β„•) (n B : β„•)
(ha : βˆ€ j ≀ n, a j ≀ B) :
Q a n ≀ (n + 1).factorial * B := by
induction n generalizing B with
| zero => simpa using ha 0 (Nat.le_refl 0)
| succ n ih =>
have hprev : Q a n ≀ (n + 1).factorial * B :=
ih B (fun j hj => ha j (Nat.le_trans hj (Nat.le_succ n)))
have hlast : a (n + 1) ≀ B := ha (n + 1) (Nat.le_refl _)
have hfac : 1 ≀ (n + 1).factorial := Nat.factorial_pos (n + 1)
have hB : B ≀ (n + 1).factorial * B := by
simpa only [one_mul] using Nat.mul_le_mul_right B hfac
calc
Q a (n + 1) = (n + 1) * Q a n + a (n + 1) := rfl
_ ≀ (n + 1) * ((n + 1).factorial * B) + B :=
Nat.add_le_add (Nat.mul_le_mul_left (n + 1) hprev) hlast
_ ≀ (n + 1) * ((n + 1).factorial * B) +
(n + 1).factorial * B := Nat.add_le_add_left hB _
_ = (n + 1 + 1).factorial * B := by
rw [Nat.factorial_succ (n + 1)]
ring
end LoopMatching.Accumulator
end OAI