lemmaboxRows_holds {n B : ℕ} (x : Fin n →ℝ) :
(∀ q∈boxRows n B, q.RealHolds x) ↔∀ j, |x j|≤(B:ℝ) :=by
proof · 16
lines
have he (i : Fin n) (c : ℚ) : (coordinateRow i c B).RealHolds x ↔ (c:ℝ)*x i≤(B:ℝ) :=by
change (coordinateRow i c B).realValue x≤((B:ℚ):ℝ) ↔ _
rw [coordinateRow_value,Rat.cast_natCast]
simp only [boxRows,List.forall_mem_append,List.forall_mem_ofFn_iff,he]
constructor
· rintro ⟨hp,hm⟩ j
havehpj : x j≤(B:ℝ) :=by simpa using hp j
havehmj : -x j≤(B:ℝ) :=by simpa using hm j
exact abs_le.mpr ⟨by linarith,hpj⟩
· intro h
constructor
· intro j
simpa using (abs_le.mp (h j)).2
· intro j
have hh := (abs_le.mp (h j)).1
simpa using (show -x j≤(B:ℝ) by linarith)
lemmarowMatrix_region {n : ℕ} (rows : List (Row n)) (x : Fin n →ℝ) :
x∈region (fun i j => (rowMatrix rows i j:ℝ)) (fun i => (rowBounds rows i:ℝ)) ↔∀ q∈rows, q.RealHolds x :=by
proof · 7
lines
constructor
· intro h q hq
obtain ⟨i,hi,he⟩ :=List.mem_iff_getElem.mp hq
havehh : rows[i].RealHolds x := h ⟨i,hi⟩
rwa [he] at hh
· intro h i
exact h _ (List.getElem_mem _)
lemmafinalFace_feasible {n : ℕ} (rows : List (Row n)) (B : ℕ)
(hfeas : ∃x : Fin n →ℝ, (∀ q∈rows,q.RealHolds x) ∧ (∀ j,|x j|≤(B:ℝ))) :
∃ x, Face (withBox rows B) (finalFace rows B) B x :=by
proof · 4
lines
apply (selectFace_spec (withBox rows B) B (withBox rows B) [] ?_).2.1
obtain ⟨x,hx,hb⟩ := hfeas
refine ⟨x,⟨?_,by simp,hb⟩⟩
exact List.forall_mem_append.mpr ⟨hx,(boxRows_holds x).mpr hb⟩
theoremfinalFace_kernel {n : ℕ} (rows : List (Row n)) (B : ℕ)
(hfeas : ∃x : Fin n →ℝ, (∀ q∈rows,q.RealHolds x) ∧ (∀ j,|x j|≤(B:ℝ)))
(u : Fin n →ℝ) (hu : ∀ q∈finalFace rows B, ∑ j, (q.coeff j:ℝ)*u j=0) : u=0:=by
proof · 29
lines
let base := withBox rows Blet picked := finalFace rows Blet all := faceRows base picked
obtain ⟨x0,hx0⟩ := finalFace_feasible rows B hfeas
have hbox (x : Fin n →ℝ) (hx : ∀ q∈all, q.RealHolds x) : ∀ j, |x j|≤(B:ℝ) :=byhave hh := (faceRows_holds base picked x).mp hx
exact (boxRows_holds x).mp (fun q hq => hh.1 q (List.mem_append_right _ hq))
obtain ⟨x,hx,hker⟩ := bounded_extreme (fun i j => (rowMatrix all i j:ℝ))
(fun i => (rowBounds all i:ℝ)) B
⟨x0,(rowMatrix_region all x0).mpr ((faceRows_holds base picked x0).mpr ⟨hx0.1,hx0.2.1⟩)⟩
(fun x hx j => abs_le.mp (hbox x ((rowMatrix_region all x).mp hx) j))
havehxp : Face base picked B x :=byhave hh := (rowMatrix_region all x).mp hx
have hf := (faceRows_holds base picked x).mp hh
exact ⟨hf.1,hf.2,hbox x hh⟩
havehf0 : ∃ y, Face base [] B y := ⟨x0,⟨hx0.1,by simp,hx0.2.2⟩⟩
have hactive := (selectFace_spec base B base [] hf0).2.2 x hxp
apply hker u
intro i hi
havehm : all[i]∈all :=List.getElem_mem _
change all[i].realValue x=(all[i].bound:ℝ) at hi
change (∑ j, (all[i].coeff j:ℝ)*u j)=0
rcases List.mem_append.mp hm with hm|hm
· rcases List.mem_append.mp hm with hm|hm
· exact hu _ (hactive _ hm hi)
· exact hu _ hm
· obtain ⟨q,hq,he⟩ :=List.mem_map.mp hm
rw [←he]
simp only [reverseRow,Rat.cast_neg,neg_mul,Finset.sum_neg_distrib,hu q hq,neg_zero]
defsolve : (n : ℕ) →Matrix (Fin n) (Fin n) ℚ→ (Fin n →ℚ) → (Fin n →ℚ)
body · 6
lines
| 0,_,_ =>Fin.elim0
| n+1,M,b =>letS:= freezeMat (schur M)
let d := freezeVec (rhs M b)
let x := freezeVec (solve n S d)
freezeVec (Fin.cons ((b 0-∑ j, M0 j.succ*x j)/M00) x)
have he (i j : Fin (n+1)) : M j i=M i j :=by simpa using congrFun (congrFun hM i) j
ext i j
simp only [conjTranspose_apply,star_trivial,schur]
rw [he j.succ i.succ,he 0 i.succ,he j.succ 0]
ring
apply posDef_iff_dotProduct_mulVec.mpr
refine ⟨schur_isHermitian M hM.1,?_⟩
intro x hx
letz : Fin (n+1) →ℚ:=Fin.cons (-(∑ j, M0 j.succ*x j)/M00) x
havehz : z≠0:=by
intro he
apply hx
funext j
exact congrFun he j.succ
havehd : M00≠0:= hM.diag_pos.ne'
havehh : (M *ᵥ z) 0=0:=by
simp only [mulVec,dotProduct,Fin.sum_univ_succ,z,Fin.cons_zero,Fin.cons_succ]
field_simp
ring
have ht (i : Fin n) : (M *ᵥ z) i.succ=(schur M *ᵥ x) i :=by
rw [schur_mulVec]
simp only [mulVec,dotProduct,Fin.sum_univ_succ,z,Fin.cons_zero,Fin.cons_succ]
ring
have hp := hM.dotProduct_mulVec_pos hz
simpa only [star_trivial,dotProduct,Fin.sum_univ_succ,hh,mul_zero,zero_add,z,Fin.cons_succ,ht] using hp
theoremsolve_correct (n : ℕ) (M : Matrix (Fin n) (Fin n) ℚ) (b : Fin n →ℚ)
(hM : M.PosDef) : M *ᵥ solve n M b=b :=by
proof · 16
lines
induction n with
| zero => exact Subsingleton.elim _ _
| succ n ih =>havehd : M00≠0:= hM.diag_pos.ne'
have hx := ih (schur M) (rhs M b) (schur_posDef M hM)
simp only [solve,freezeVec_eq,freezeMat_eq]
ext i
refine Fin.cases ?_ (fun i => ?_) i
· simp only [mulVec,dotProduct,Fin.sum_univ_succ,Fin.cons_zero,Fin.cons_succ]
field_simp
ring
· have hi := congrFun hx i
rw [schur_mulVec] at hi
simp only [mulVec,dotProduct,Fin.sum_univ_succ,Fin.cons_zero,Fin.cons_succ]
dsimp [rhs] at hi
linear_combination hi