Download data/lean/OAI/Computability/WLIdentification/LocalPresentation.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.23 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/WLIdentification/LocalPresentation.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/WLIdentification/LocalPresentation.lean
-
curl -L -o LocalPresentation.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/WLIdentification/LocalPresentation.lean
5.23 kB
| import OAI.Computability.WLIdentification.PresentationArithmetic | |
| namespace OAI | |
| namespace WLIdentification | |
| namespace FinitePresentation | |
| open WordExpressions NumericFinite | |
| variable {C B : Word β Type} [β w, DecidableEq (C w)] | |
| structure Locals (CP : Presented C) (BP : Presented B) where | |
| coordinates : β w, B w β Finset (C w) | |
| size : β w b, (coordinates w b).card β€ 5 | |
| member : Test (BP.prod CP) (fun w p => decide (p.2 β coordinates w p.1)) | |
| namespace Locals | |
| variable {CP : Presented C} {BP : Presented B} (D : Locals CP BP) | |
| abbrev Value (w : Word) (b : B w) := (c : D.coordinates w b) β Bit | |
| def good (w : Word) (b c : β) : Bool := CP.good w c && D.member.eval w (Nat.pair b c) | |
| theorem good_iff (w : Word) (b : B w) (i : β) : | |
| D.good w (BP.code w b) i=true β β x : D.coordinates w b, CP.code w x.val=i := by | |
| simp only [good, Bool.and_eq_true] | |
| constructor | |
| Β· rintro β¨hc,hmβ© | |
| obtain β¨c,rflβ© := (CP.good_iff w i).mp hc | |
| have h := D.member.correct w (b,c) | |
| change D.member.eval w (Nat.pair (BP.code w b) (CP.code w c))=decide (cβD.coordinates w b) at h | |
| exact β¨β¨c,of_decide_eq_true (h βΈ hm)β©,rflβ© | |
| Β· rintro β¨c,rflβ© | |
| refine β¨CP.good_code w c.val,?_β© | |
| have h := D.member.correct w (b,c.val) | |
| change D.member.eval w (Nat.pair (BP.code w b) (CP.code w c.val))=_ at h | |
| rw [h,decide_eq_true_eq] | |
| exact c.property | |
| noncomputable def localP (w : Word) (b : B w) : Presented (fun _ => D.coordinates w b) := | |
| Presented.ofCode _ (NaturalCode.subtype (CP.code w) _) (CP.bound w) | |
| (D.good w (BP.code w b)) (fun c => CP.code_lt w c.val) (D.good_iff w b) | |
| def count (w : Word) (b : β) : β := NumericFinite.count (CP.bound w) (D.good w b) | |
| theorem count_eq (w : Word) (b : B w) : D.count w (BP.code w b)=(D.coordinates w b).card := by | |
| change (D.localP w b).card [] = _ | |
| rw [Presented.card_eq, Fintype.card_coe] | |
| def rank (w : Word) (b c : β) : β := NumericFinite.count c (D.good w b) | |
| noncomputable def valueEquiv (w : Word) (b : B w) : | |
| D.Value w b β Fin (2^(D.count w (BP.code w b))) := | |
| (Equiv.arrowCongr ((D.localP w b).rankEquiv []) (ZMod.finEquiv 2).toEquiv.symm).trans finFunctionFinEquiv | |
| noncomputable def valueCode (w : Word) (b : B w) : D.Value w b βͺ β := | |
| (D.valueEquiv w b).toEmbedding.trans (NaturalCode.fin _) | |
| def valueGood (w : Word) (b v : β) : Bool := decide (v < min (2^(D.count w b)) 32) | |
| theorem valueGood_iff (w : Word) (b : B w) (i : β) : | |
| D.valueGood w (BP.code w b) i=true β β v, D.valueCode w b v=i := by | |
| have h : 2^(D.count w (BP.code w b)) β€ 32 := by | |
| rw [D.count_eq] | |
| exact Nat.pow_le_pow_right (by decide) (D.size w b) | |
| simp only [valueGood, min_eq_left h, decide_eq_true_eq] | |
| exact β¨fun hi => β¨(D.valueEquiv w b).symm β¨i,hiβ©, congrArg Fin.val ((D.valueEquiv w b).apply_symm_apply _)β©, | |
| fun β¨v,hvβ© => hv βΈ (D.valueEquiv w b v).isLtβ© | |
| theorem good_poly {n} {w : (Fin n β Word) β Word} {b c : (Fin n β Word) β β} | |
| (hw : Poly w) (hb : NatPoly b) (hc : NatPoly c) : BoolPoly (fun S => D.good (w S) (b S) (c S)) := | |
| BoolPoly.and (CP.good_poly_of hw hc) (D.member.eval_poly hw (NatPoly.pair hb hc)) | |
| theorem count_poly {n} {w : (Fin n β Word) β Word} {b : (Fin n β Word) β β} | |
| (hw : Poly w) (hb : NatPoly b) : NatPoly (fun S => D.count (w S) (b S)) := by | |
| apply (NatPoly.filterCount (CP.bound_poly_of hw) | |
| (D.good_poly (hw.rename Fin.castSucc) (hb.rename Fin.castSucc) (NatPoly.var (Fin.last n)))).congr | |
| intro S | |
| simp only [Fin.snoc_comp_castSucc, Fin.snoc_last, unary, List.length_replicate] | |
| rfl | |
| theorem rank_poly {n} {w : (Fin n β Word) β Word} {b c : (Fin n β Word) β β} | |
| (hw : Poly w) (hb : NatPoly b) (hc : NatPoly c) : NatPoly (fun S => D.rank (w S) (b S) (c S)) := by | |
| apply (NatPoly.filterCount hc | |
| (D.good_poly (hw.rename Fin.castSucc) (hb.rename Fin.castSucc) (NatPoly.var (Fin.last n)))).congr | |
| intro S | |
| simp only [Fin.snoc_comp_castSucc, Fin.snoc_last, unary, List.length_replicate] | |
| rfl | |
| noncomputable def values : Presented (fun w => Ξ£ b : B w, D.Value w b) := | |
| BP.sigma (D.Value) D.valueCode (fun _ => 32) D.valueGood | |
| (by intro w b v; have := (D.valueEquiv w b v).isLt | |
| have h := D.size w b | |
| rw [β D.count_eq w b] at h | |
| exact this.trans_le (Nat.pow_le_pow_right (by decide) h)) | |
| D.valueGood_iff (NatPoly.const _) | |
| (NatPoly.lt (NatPoly.var 2) (NatPoly.cappedPow (NatPoly.const 2) | |
| (D.count_poly (Poly.var 0) (NatPoly.var 1)) (NatPoly.const 32))) | |
| def read (w : Word) (b v c : β) : β := NumericKernel.digit 2 v (D.rank w b c) | |
| theorem read_value (w : Word) (b : B w) (v : D.Value w b) (c : D.coordinates w b) : | |
| D.read w (BP.code w b) (D.valueCode w b v) (CP.code w c.val)=(v c).val := by | |
| have h := (D.valueEquiv w b).symm_apply_apply v | |
| have h' := congrArg (fun f => (f c).val) h | |
| exact h' | |
| theorem read_poly {n} {w : (Fin n β Word) β Word} {b v c : (Fin n β Word) β β} | |
| (hw : Poly w) (hb : NatPoly b) (hv : NatPoly v) (hc : NatPoly c) : | |
| NatPoly (fun S => D.read (w S) (b S) (v S) (c S)) := | |
| NatPoly.digit (NatPoly.const 2) hv (D.rank_poly hw hb hc) | |
| end Locals | |
| end FinitePresentation | |
| end WLIdentification | |
| end OAI | |