Download data/lean/OAI/Combinatorics/ContingencyTables/Rooted/ForestScaledIdentification.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 6.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/ContingencyTables/Rooted/ForestScaledIdentification.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/ContingencyTables/Rooted/ForestScaledIdentification.lean
-
curl -L -o ForestScaledIdentification.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/ContingencyTables/Rooted/ForestScaledIdentification.lean
6.7 kB
| import OAI.Combinatorics.ContingencyTables.Rooted.ForestScaledPenalty | |
| import OAI.Combinatorics.ContingencyTables.Rooted.ForestPenaltyBound | |
| namespace OAI | |
| /-! # Integer free assignments use the original scaled affine tree values -/ | |
| namespace ContingencyTables.ForestScaledPenalty | |
| open scoped BigOperators Classical | |
| open CompanionFactorialApplication GraphCompletionCounts ForestAssignmentSplit | |
| open ForestAffineCoefficients ForestPhysicalCompletion ForestRootPenalty | |
| variable {I J : Type*} [Fintype I] [Fintype J] | |
| lemma free_coefficient_sum (A : Instance I J) (t : TreeCell A.T) (F : IΓJ β β) : | |
| (β f : FreeCell A.small A.T,coefficient A t f.val*F f.val)= | |
| β a : IΓJ,coefficient A t a*F a := by | |
| let p : IΓJ β Prop := fun a => A.small a.1 a.2=false β§ Β¬A.T.Adj (.inl a.1) (.inr a.2) | |
| calc | |
| _ = β a β Finset.univ.filter p,coefficient A t a*F a := | |
| (Finset.sum_subtype (p := p) (Finset.univ.filter p) (fun _ => by simp) | |
| (fun a => coefficient A t a*F a)).symm | |
| _ = _ := by | |
| apply Finset.sum_subset (Finset.filter_subset _ _) | |
| intro a _ ha | |
| have hp : Β¬p a := by simpa only [Finset.mem_filter,Finset.mem_univ,true_and] using ha | |
| change Β¬(A.small a.1 a.2=false β§ Β¬A.T.Adj (.inl a.1) (.inr a.2)) at hp | |
| simp only [coefficient,hp,ite_false,zero_mul] | |
| noncomputable def integerCube (A : Instance I J) (B : β) (f : FreeIndex A.small A.T A.b) : | |
| FreeCell A.small A.T β β := fun a => B*(f a).val/((A.b a.val.1 a.val.2:β)+1) | |
| /-- The scaled affine value at each original integer free assignment is | |
| exactly the manuscript's solved tree value divided by its capacity. -/ | |
| theorem scaledTree_integer (A : Instance I J) (B : β) (hB : 0 < B) | |
| (x q : I β J β β€) (f : FreeIndex A.small A.T A.b) (t : TreeCell A.T) : | |
| scaledTree A B x q (integerCube A B f) t= | |
| (solved A.small A.T A.r A.c x q | |
| (fun i j => (freeTable A.small A.T A.b f i j:β€)) t.val.1 t.val.2:β)/(A.b t.val.1 t.val.2:β) := by | |
| let F : IΓJ β β := fun a => (freeTable A.small A.T A.b f a.1 a.2:β) | |
| have hterm (a : FreeCell A.small A.T) : | |
| normalizedCoefficient A B t a*integerCube A B f a= | |
| coefficient A t a.val*F a.val/(A.b t.val.1 t.val.2:β) := by | |
| have hN : (A.b a.val.1 a.val.2:β)+1β 0 := by positivity | |
| have hbt : (A.b t.val.1 t.val.2:β)β 0 := by | |
| exact_mod_cast (Nat.ne_of_gt (A.hlarge _ _ (A.hTG t.property)).2) | |
| have hF : F a.val=(f a).val := by | |
| simp [F,freeTable,a.property] | |
| rw [hF] | |
| unfold normalizedCoefficient integerCube | |
| field_simp [hB.ne',hN,hbt] | |
| unfold scaledTree AffinePenalty.affineValue normalizedOffset | |
| simp_rw [hterm] | |
| rw [β Finset.sum_div,free_coefficient_sum,β add_div] | |
| have hh := solved_eq_affine A t x q | |
| (fun i j => (freeTable A.small A.T A.b f i j:β€)) | |
| unfold affineTree AffinePenalty.affineValue at hh | |
| apply congrArg (fun z : β => z/(A.b t.val.1 t.val.2:β)) | |
| simpa only [F,Int.cast_natCast] using hh.symm | |
| lemma intervalCost_div (x b : β) (hb : 0 < b) : | |
| intervalCost (x/b)=max 0 (max (-x) (x-b))/b := by | |
| unfold intervalCost | |
| have he : x/b-1=(x-b)/b := by field_simp [hb.ne'] | |
| rw [he,β neg_div, max_div_div_right hb.le] | |
| simpa only [zero_div] using max_div_div_right hb.le (0:β) (max (-x) (x-b)) | |
| /-- The root residual in the continuous display is the original root | |
| residual on every integer free assignment; it is independent of those | |
| free values by the proved component-cut cancellation. -/ | |
| theorem rootConstant_eq_assignment (A : Instance I J) (x q free : I β J β β€) : | |
| rootConstant A x q= | |
| β a,if ForestPenaltyApplication.rootFlag A.T a then | |
| |(signedResidual A.small A.T A.r A.c x q free a:β)| else 0 := by | |
| have hroot := root_eq_large A.small A.b A.T A.hTG A.hT A.hmax | |
| (fun i j hs => (A.hlarge i j hs).2) | |
| have hh := signedResidual_independent A.small A.T A.hTG A.r A.c x q free 0 A.X | |
| A.hXr A.hXc hroot | |
| unfold rootConstant | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| rw [hh] | |
| lemma tree_sum_eq (A : Instance I J) (F : IΓJ β β) : | |
| (β t : TreeCell A.T,F t.val)= | |
| β i,β j,if A.T.Adj (.inl i) (.inr j) then F (i,j) else 0 := by | |
| let p : IΓJ β Prop := fun a => A.T.Adj (.inl a.1) (.inr a.2) | |
| calc | |
| _ = β a β Finset.univ.filter p,F a := | |
| (Finset.sum_subtype (p := p) (Finset.univ.filter p) (fun _ => by simp) F).symm | |
| _ = β a : IΓJ,if p a then F a else 0 := Finset.sum_filter _ _ | |
| _ = _ := by rw [Fintype.sum_prod_type] | |
| /-- Thus the continuous display agrees term for term with the actual | |
| root/tree penalty in the original finite definition of h_j. -/ | |
| theorem penalty_at_integer (A : Instance I J) (C B : β) (hB : 0 < B) | |
| (z : View A β β) (f : FreeIndex A.small A.T A.b) : | |
| penalty A C B (fun i j => (ForestCountIdentification.smallX A.small z i j:β€)) | |
| (fun i j => ((A.b i j-ForestCountIdentification.smallY A.small z i j:β):β€)) | |
| (integerCube A B f)=C*ForestPenaltyBound.penalty A z f := by | |
| let x := ForestCountIdentification.smallX A.small z | |
| let y := ForestCountIdentification.smallY A.small z | |
| let free := freeTable A.small A.T A.b f | |
| let tree := solved A.small A.T A.r A.c (fun i j => (x i j:β€)) | |
| (fun i j => ((A.b i j-y i j:β):β€)) (fun i j => (free i j:β€)) | |
| have hroot : rootConstant A (fun i j => (x i j:β€)) (fun i j => ((A.b i j-y i j:β):β€))= | |
| β a,if ForestPenaltyApplication.rootFlag A.T a then | |
| |ForestLiteralCount.actualDeviation A.small A.T A.b x y free A.r A.c tree a| else 0 := by | |
| rw [rootConstant_eq_assignment A _ _ (fun i j => (free i j:β€))] | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| rw [ForestRootPenalty.abs_actualDeviation_solved] | |
| have htree : (β t : TreeCell A.T,intervalCost (scaledTree A B (fun i j => (x i j:β€)) | |
| (fun i j => ((A.b i j-y i j:β):β€)) (integerCube A B f) t))= | |
| β i,β j,if A.T.Adj (.inl i) (.inr j) then | |
| max 0 (max (-(tree i j:β)) ((tree i j:β)-A.b i j))/(A.b i j:β) else 0 := by | |
| calc | |
| _ = β t : TreeCell A.T, | |
| max 0 (max (-(tree t.val.1 t.val.2:β)) ((tree t.val.1 t.val.2:β)-A.b t.val.1 t.val.2))/ | |
| (A.b t.val.1 t.val.2:β) := by | |
| apply Finset.sum_congr rfl | |
| intro t _ | |
| rw [scaledTree_integer A B hB] | |
| exact intervalCost_div _ _ (by exact_mod_cast (A.hlarge _ _ (A.hTG t.property)).2) | |
| _ = _ := tree_sum_eq A (fun a => | |
| max 0 (max (-(tree a.1 a.2:β)) ((tree a.1 a.2:β)-A.b a.1 a.2))/(A.b a.1 a.2:β)) | |
| unfold penalty | |
| change C*(rootConstant A (fun i j => (x i j:β€)) (fun i j => ((A.b i j-y i j:β):β€))+_)=_ | |
| rw [hroot,htree] | |
| rfl | |
| end ContingencyTables.ForestScaledPenalty | |
| end OAI | |