Download data/lean/OAI/Computability/MaxCut/Estimates/Rename.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.31 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MaxCut/Estimates/Rename.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/MaxCut/Estimates/Rename.lean
-
curl -L -o Rename.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MaxCut/Estimates/Rename.lean
5.31 kB
| import Mathlib | |
| import OAI.Computability.MaxCut.Estimates.Put | |
| namespace OAI | |
| noncomputable section | |
| namespace OptimalMaxCut.CounterMachine.Expr | |
| open scoped BigOperators | |
| open Finset | |
| def rename (Ο : β β β) : Expr β Expr | |
| | .const n => .const n | |
| | .arg i => .arg (Ο i) | |
| | .length => .length | |
| | .bit e => .bit (rename Ο e) | |
| | .add a b => .add (rename Ο a) (rename Ο b) | |
| | .sub a b => .sub (rename Ο a) (rename Ο b) | |
| | .mul a b => .mul (rename Ο a) (rename Ο b) | |
| | .zero a => .zero (rename Ο a) | |
| | .sum b f => .sum (rename Ο b) (rename (bind (fun i => Ο i+1) 0) f) | |
| @[simp] theorem rename_eval (e : Expr) (Ο : β β β) (input : List Bool) (args : β β β) : | |
| (e.rename Ο).eval input args = e.eval input (fun i => args (Ο i)) := by | |
| induction e generalizing Ο args <;> simp only [rename, eval] at * | |
| all_goals try simp_all | |
| case sum b f ib iF => | |
| apply sum_congr rfl | |
| intro i hi | |
| congr 1 | |
| funext j | |
| cases j <;> rfl | |
| def bindExpr (Ο : β β Expr) (e : Expr) : β β Expr | |
| | 0 => e | |
| | i+1 => Ο i | |
| def subst (Ο : β β Expr) : Expr β Expr | |
| | .const n => .const n | |
| | .arg i => Ο i | |
| | .length => .length | |
| | .bit e => .bit (subst Ο e) | |
| | .add a b => .add (subst Ο a) (subst Ο b) | |
| | .sub a b => .sub (subst Ο a) (subst Ο b) | |
| | .mul a b => .mul (subst Ο a) (subst Ο b) | |
| | .zero a => .zero (subst Ο a) | |
| | .sum b f => .sum (subst Ο b) (subst (bindExpr (fun i => (Ο i).rename Nat.succ) (.arg 0)) f) | |
| @[simp] theorem subst_eval (e : Expr) (Ο : β β Expr) (input : List Bool) (args : β β β) : | |
| (e.subst Ο).eval input args = e.eval input (fun i => (Ο i).eval input args) := by | |
| induction e generalizing Ο args <;> simp only [subst, eval] at * | |
| all_goals try simp_all | |
| case sum b f ib iF => | |
| apply sum_congr rfl | |
| intro i hi | |
| congr 1 | |
| funext j | |
| cases j with | |
| | zero => rfl | |
| | succ j => simp [bindExpr, bind] | |
| def positive (a : Expr) : Expr := .zero (.zero a) | |
| def equal (a b : Expr) : Expr := .zero (.add (.sub a b) (.sub b a)) | |
| def le (a b : Expr) : Expr := .zero (.sub a b) | |
| def lt (a b : Expr) : Expr := le (.add a (.const 1)) b | |
| @[simp] theorem positive_eval (a : Expr) (input : List Bool) (args : β β β) : | |
| (positive a).eval input args = if a.eval input args β 0 then 1 else 0 := by | |
| simp [positive, eval] | |
| @[simp] theorem equal_eval (a b : Expr) (input : List Bool) (args : β β β) : | |
| (equal a b).eval input args = if a.eval input args = b.eval input args then 1 else 0 := by | |
| by_cases h : a.eval input args = b.eval input args | |
| Β· simp only [equal, eval, h, Nat.sub_self, Nat.zero_add, βreduceIte] | |
| Β· have hn : a.eval input args-b.eval input args+(b.eval input args-a.eval input args) β 0 := by omega | |
| simp only [equal, eval, ite_eq_right h] | |
| exact ite_eq_right hn | |
| @[simp] theorem le_eval (a b : Expr) (input : List Bool) (args : β β β) : | |
| (le a b).eval input args = if a.eval input args β€ b.eval input args then 1 else 0 := by | |
| simp [le, eval, Nat.sub_eq_zero_iff_le] | |
| @[simp] theorem lt_eval (a b : Expr) (input : List Bool) (args : β β β) : | |
| (lt a b).eval input args = if a.eval input args < b.eval input args then 1 else 0 := by | |
| simp [lt, eval] | |
| def cond (c a b : Expr) : Expr := .add (.mul (positive c) a) (.mul (.zero c) b) | |
| @[simp] theorem cond_eval (c a b : Expr) (input : List Bool) (args : β β β) : | |
| (cond c a b).eval input args = if c.eval input args β 0 then a.eval input args else b.eval input args := by | |
| simp only [cond, eval, positive_eval]; split_ifs <;> simp_all | |
| def quotient (a b : Expr) : Expr := | |
| .mul (positive b) (.sum a (le (.mul (.add (.arg 0) (.const 1)) (b.rename Nat.succ)) (a.rename Nat.succ))) | |
| theorem quotient_sum (a b : β) (hb : 0 < b) : | |
| (β i β range a, if (i+1)*b β€ a then (1:β) else 0) = a/b := by | |
| have hcond (i : β) : (i+1)*b β€ a β i < a/b := by | |
| rw [β Nat.le_div_iff_mul_le hb, Nat.add_one_le_iff] | |
| simp_rw [hcond] | |
| rw [sum_boole] | |
| have hs : {i β range a | i < a/b} = range (a/b) := by | |
| ext i; simp only [mem_filter, mem_range] | |
| exact and_iff_right_of_imp (fun hi => hi.trans_le (Nat.div_le_self _ _)) | |
| simp only [hs, card_range, Nat.cast_id] | |
| @[simp] theorem quotient_eval (a b : Expr) (input : List Bool) (args : β β β) : | |
| (quotient a b).eval input args = a.eval input args / b.eval input args := by | |
| simp only [quotient, eval, positive_eval, le_eval, rename_eval, bind] | |
| by_cases hb : b.eval input args = 0 | |
| Β· simp [hb] | |
| Β· simp only [hb, ne_eq, not_false_eq_true, βreduceIte, one_mul] | |
| simpa using quotient_sum (a.eval input args) (b.eval input args) (by omega) | |
| def remainder (a b : Expr) : Expr := .sub a (.mul (quotient a b) b) | |
| @[simp] theorem remainder_eval (a b : Expr) (input : List Bool) (args : β β β) : | |
| (remainder a b).eval input args = a.eval input args % b.eval input args := by | |
| simp only [remainder, eval, quotient_eval] | |
| exact Nat.mod_eq_sub_div_mul.symm | |
| def power (a : Expr) : β β Expr | |
| | 0 => .const 1 | |
| | n+1 => .mul (power a n) a | |
| @[simp] theorem power_eval (a : Expr) (n : β) (input : List Bool) (args : β β β) : | |
| (power a n).eval input args = (a.eval input args)^n := by | |
| induction n <;> simp [power, eval, pow_succ, *] | |
| end OptimalMaxCut.CounterMachine.Expr | |
| end | |
| end OAI | |