openAI-math-dataset / lean /OAI /Combinatorics /MatchingCount /Complexity /TreePolynomialArithmetic.lean
Download lean/OAI/Combinatorics/MatchingCount/Complexity/TreePolynomialArithmetic.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 3.97 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/MatchingCount/Complexity/TreePolynomialArithmetic.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Combinatorics/MatchingCount/Complexity/TreePolynomialArithmetic.lean
-
curl -L -o TreePolynomialArithmetic.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/MatchingCount/Complexity/TreePolynomialArithmetic.lean
3.97 kB
| import Mathlib | |
| import OAI.Combinatorics.MatchingCount.Machines.TreePartialChoice | |
| import OAI.Combinatorics.MatchingCount.Complexity.TreePolynomial | |
| namespace OAI | |
| namespace MatchingFPRAS.TreeTyped | |
| open TreeData TreeFunction Polynomial | |
| lemma weight_bool (b : Bool) : weight b≤3 := by cases b <;> decide | |
| lemma weight_bits (bs : List Bool) : weight bs≤4*bs.length+1 := TreeData.bits_length bs | |
| lemma weight_nat (n : ℕ) : weight n=weight n.bits := rfl | |
| lemma weight_nat_le (n : ℕ) : weight n≤4*n.size+1 := by | |
| rw [weight_nat,←Nat.size_eq_bits_len]; exact weight_bits _ | |
| lemma size_le_weight (n : ℕ) : n.size≤weight n := by | |
| rw [weight_nat,←Nat.size_eq_bits_len]; exact list_length_le_weight _ | |
| lemma weight_nat_small {a b : ℕ} (h : a≤b) : weight a≤4*weight b+1 := by | |
| have h1:=Nat.size_le_size h | |
| have h2:=weight_nat_le a | |
| have h3:=size_le_weight b | |
| omega | |
| lemma nat_size_add (a b : ℕ) : (a+b).size≤ max a.size b.size+1 := by | |
| apply Nat.size_le.mpr | |
| have ha : a<2^(max a.size b.size) := (Nat.lt_size_self a).trans_le (Nat.pow_le_pow_right (by decide) (le_max_left _ _)) | |
| have hb : b<2^(max a.size b.size) := (Nat.lt_size_self b).trans_le (Nat.pow_le_pow_right (by decide) (le_max_right _ _)) | |
| rw [pow_succ]; omega | |
| lemma nat_size_mul (a b : ℕ) : (a*b).size≤a.size+b.size := by | |
| apply Nat.size_le.mpr | |
| rw [pow_add] | |
| exact (Nat.mul_le_mul_left a (Nat.le_of_lt (Nat.lt_size_self b))).trans_lt | |
| (Nat.mul_lt_mul_of_pos_right (Nat.lt_size_self a) (by positivity)) | |
| lemma weight_add (a b : ℕ) : weight (a+b)≤4*(weight a+weight b+1)+1 := by | |
| have h:=weight_nat_le (a+b) | |
| have h1:=nat_size_add a b | |
| have h2:=size_le_weight a | |
| have h3:=size_le_weight b | |
| have hm : max a.size b.size≤weight a+weight b := max_le (by omega) (by omega) | |
| omega | |
| lemma polynomial_add : PolynomialTime add := by | |
| refine ⟨20*X+30,fun ⟨a,b⟩=>?_⟩ | |
| have ha:=size_le_weight a | |
| have hb:=size_le_weight b | |
| have ho:=weight_add a b | |
| simp only [Polynomial.eval_add,Polynomial.eval_mul,Polynomial.eval_ofNat,Polynomial.eval_X,weight_prod] | |
| change (2*weight a+5+9*(a.bits.length+b.bits.length)+20)+weight (a+b)≤_ | |
| rw [Nat.size_eq_bits_len,Nat.size_eq_bits_len] | |
| omega | |
| lemma polynomial_less : PolynomialTime less := by | |
| refine ⟨8*X+40,fun ⟨a,b⟩=>?_⟩ | |
| have ha:=size_le_weight a | |
| have hb:=size_le_weight b | |
| have ho:=weight_bool (decide (a<b)) | |
| simp only [Polynomial.eval_add,Polynomial.eval_mul,Polynomial.eval_ofNat,Polynomial.eval_X,weight_prod] | |
| change (2*weight a+3*(a.bits.length+b.bits.length)+31)+weight (decide (a<b))≤_ | |
| rw [Nat.size_eq_bits_len,Nat.size_eq_bits_len] | |
| omega | |
| lemma polynomial_subtract : PolynomialTime subtract := by | |
| refine ⟨50*X+100,fun ⟨a,b⟩=>?_⟩ | |
| have ha:=size_le_weight a | |
| have hb:=size_le_weight b | |
| have hc:=weight_nat_small (Nat.sub_le a b) | |
| have ho:=weight_bool (decide (a<b)) | |
| simp only [Polynomial.eval_add,Polynomial.eval_mul,Polynomial.eval_ofNat,Polynomial.eval_X,weight_prod] | |
| change (2*weight a+3*(a.bits.length+b.bits.length)+31)+ | |
| (if decide (a<b) then weight (a,b)+2 else | |
| 2*weight a+9*(a.bits.length+b.bits.length)+4*weight (a-b)+32)+ | |
| 7*weight (a,b)+18+weight (a-b)≤_ | |
| rw [Nat.size_eq_bits_len,Nat.size_eq_bits_len,weight_prod] | |
| split <;> omega | |
| lemma polynomial_toBits : PolynomialTime toBits := by | |
| refine ⟨X+1,fun _=>?_⟩ | |
| simp only [Polynomial.eval_add,Polynomial.eval_X,Polynomial.eval_one] | |
| change 1+weight _ ≤ weight _+1 | |
| rw [weight_nat]; omega | |
| lemma polynomial_listCons {A : Type} [Codec A] : PolynomialTime (listCons (A:=A)) := by | |
| refine ⟨X+1,fun ⟨a,as⟩=>?_⟩ | |
| simp only [Polynomial.eval_add,Polynomial.eval_X,Polynomial.eval_one,weight_prod,weight_cons] | |
| change 1+(1+weight a+weight as)≤(1+weight a+weight as)+1 | |
| omega | |
| lemma polynomial_double : PolynomialTime double := | |
| polynomial_congr _ (polynomial_composition (polynomial_pair polynomial_identity polynomial_identity) polynomial_add) | |
| end MatchingFPRAS.TreeTyped | |
| end OAI | |