Add lean source and binary files (part 28)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- lean/OAI/Analysis/MatrixSigning/Matrices/PSDSeparation.leanAdded+59
- lean/OAI/Analysis/MatrixSigning/Matrices/PivotTerminalMachine.leanAdded+140
- lean/OAI/Analysis/MatrixSigning/Matrices/PosLower.leanAdded+50
- lean/OAI/Analysis/MatrixSigning/Matrices/PreservedMatrixRetrieval.leanAdded+50
- lean/OAI/Analysis/MatrixSigning/Matrices/RankFactor.leanAdded+88
- lean/OAI/Analysis/MatrixSigning/Matrices/RationalElimination.leanAdded+72
- lean/OAI/Analysis/MatrixSigning/Matrices/RationalPSDDecision.leanAdded+29
- lean/OAI/Analysis/MatrixSigning/Matrices/RealDecode.leanAdded+93
- lean/OAI/Analysis/MatrixSigning/Matrices/RealTrace.leanAdded+141
- lean/OAI/Analysis/MatrixSigning/Matrices/RealTraceSum.leanAdded+45
- lean/OAI/Analysis/MatrixSigning/Matrices/RealifyHermitian.leanAdded+40
- lean/OAI/Analysis/MatrixSigning/Matrices/RetractH.leanAdded+129
- lean/OAI/Analysis/MatrixSigning/Matrices/RowDotBody.leanAdded+110
- lean/OAI/Analysis/MatrixSigning/Matrices/RowDotBounds.leanAdded+186
- lean/OAI/Analysis/MatrixSigning/Matrices/RowDotControl.leanAdded+110
- lean/OAI/Analysis/MatrixSigning/Matrices/RowDotCounter.leanAdded+75
- lean/OAI/Analysis/MatrixSigning/Matrices/RowDotMachine.leanAdded+110
- lean/OAI/Analysis/MatrixSigning/Matrices/RowDotModel.leanAdded+74
- lean/OAI/Analysis/MatrixSigning/Matrices/RowDotPrimitives.leanAdded+105
- lean/OAI/Analysis/MatrixSigning/Matrices/RowDotRegisters.leanAdded+15
- lean/OAI/Analysis/MatrixSigning/Matrices/Sandwich.leanAdded+117
- lean/OAI/Analysis/MatrixSigning/Matrices/Sandwich2.leanAdded+92
- lean/OAI/Analysis/MatrixSigning/Matrices/SandwichCLM.leanAdded+49
- lean/OAI/Analysis/MatrixSigning/Matrices/SandwichShiftInverse.leanAdded+72
- lean/OAI/Analysis/MatrixSigning/Matrices/SavedPivotPacketMachine.leanAdded+130
- lean/OAI/Analysis/MatrixSigning/Matrices/SavedPivotStack.leanAdded+112
- lean/OAI/Analysis/MatrixSigning/Matrices/Space.leanAdded+139
- lean/OAI/Analysis/MatrixSigning/Matrices/SquareScalarBound.leanAdded+52
- lean/OAI/Analysis/MatrixSigning/Matrices/SquareShift.leanAdded+43
- lean/OAI/Analysis/MatrixSigning/Matrices/TraceCLM.leanAdded+98
- lean/OAI/Analysis/MatrixSigning/Matrices/UniformElimination.leanAdded+89
- lean/OAI/Analysis/MatrixSigning/Matrices/UniformEliminationHeight.leanAdded+49
- lean/OAI/Analysis/MatrixSigning/Model.leanAdded+137
- lean/OAI/Analysis/MatrixSigning/Optimization/Affine.leanAdded+100
- lean/OAI/Analysis/MatrixSigning/Optimization/AffineRealEval.leanAdded+125
- lean/OAI/Analysis/MatrixSigning/Optimization/BlockScalar.leanAdded+91
- lean/OAI/Analysis/MatrixSigning/Optimization/ComplexValueProgram.leanAdded+78
- lean/OAI/Analysis/MatrixSigning/Optimization/Coordinates.leanAdded+148
- lean/OAI/Analysis/MatrixSigning/Optimization/EliminationWitnessHeight.leanAdded+195
- lean/OAI/Analysis/MatrixSigning/Optimization/EquivSymmetricMap.leanAdded+22
- lean/OAI/Analysis/MatrixSigning/Optimization/FaceStencil.leanAdded+164
- lean/OAI/Analysis/MatrixSigning/Optimization/Feasible.leanAdded+89
- lean/OAI/Analysis/MatrixSigning/Optimization/FinRealify.leanAdded+156
- lean/OAI/Analysis/MatrixSigning/Optimization/FixedPart.leanAdded+114
- lean/OAI/Analysis/MatrixSigning/Optimization/InverseEliminationBounds.leanAdded+151
- lean/OAI/Analysis/MatrixSigning/Optimization/Level.leanAdded+90
- lean/OAI/Analysis/MatrixSigning/Optimization/Lookup.leanAdded+134
- lean/OAI/Analysis/MatrixSigning/Optimization/MinList.leanAdded+53
- lean/OAI/Analysis/MatrixSigning/Optimization/NearestEndpoint.leanAdded+95
- lean/OAI/Analysis/MatrixSigning/Optimization/NegativeDirection.leanAdded+135
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import Mathlib
namespace OAI
section
namespace KS.W17
open Matrix
def psdCutNormal {n : ℕ} (q : Fin n → ℚ) : Matrix (Fin n) (Fin n) ℚ := fun i j => -(q i * q j)
def psdCutEval {n : ℕ} (q : Fin n → ℚ) (M : Matrix (Fin n) (Fin n) ℚ) : ℚ := -(q ⬝ᵥ (M *ᵥ q))
noncomputable def psdCutEvalReal {n : ℕ} (q : Fin n → ℚ) (M : Matrix (Fin n) (Fin n) ℝ) : ℝ := -((fun i => (q i : ℝ)) ⬝ᵥ (M *ᵥ (fun i => (q i : ℝ))))
theorem psdCutEvalReal_cast {n : ℕ} (q : Fin n → ℚ) (M : Matrix (Fin n) (Fin n) ℚ) : psdCutEvalReal q (fun i j => (M i j : ℝ)) = (psdCutEval q M : ℝ) := by simp [psdCutEvalReal, psdCutEval, dotProduct, Matrix.mulVec, Rat.cast_sum, Rat.cast_mul, Rat.cast_neg]
theorem psdCutEvalReal_eq_sum {n : ℕ} (q : Fin n → ℚ) (M : Matrix (Fin n) (Fin n) ℝ) : psdCutEvalReal q M = ∑ i, ∑ j, (psdCutNormal q i j : ℝ) * M i j := by simp only [psdCutEvalReal, dotProduct, Matrix.mulVec, Finset.mul_sum] rw [← Finset.sum_neg_distrib] apply Finset.sum_congr rfl intro i _ rw [← Finset.sum_neg_distrib] apply Finset.sum_congr rfl intro j _ simp only [psdCutNormal, Rat.cast_neg, Rat.cast_mul] ring
theorem psdCutEvalReal_nonpos {n : ℕ} (q : Fin n → ℚ) (M : Matrix (Fin n) (Fin n) ℝ) (hM : M.PosSemidef) : psdCutEvalReal q M ≤ 0 := by have h := hM.dotProduct_mulVec_nonneg (fun i => (q i : ℝ)) simpa [psdCutEvalReal] using neg_nonpos.mpr h
theorem psdWitness_separates {n : ℕ} (q : Fin n → ℚ) (M : Matrix (Fin n) (Fin n) ℚ) (hneg : q ⬝ᵥ (M *ᵥ q) < 0) : 0 < psdCutEvalReal q (fun i j => (M i j : ℝ)) ∧ ∀ B : Matrix (Fin n) (Fin n) ℝ, B.PosSemidef → psdCutEvalReal q B ≤ 0 := by constructor · rw [psdCutEvalReal_cast] have hr : 0 < psdCutEval q M := neg_pos.mpr hneg exact_mod_cast hr · exact fun B hB => psdCutEvalReal_nonpos q B hB
end KS.W17
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.PivotDecisionPortsimport OAI.Analysis.MatrixSigning.Matrices.PivotReplayLoopimport OAI.Analysis.MatrixSigning.Optimization.TerminalWitnessMachine
namespace OAI
section
namespace KS.W17.FixedPSDopen KS.W01.FixedStack KS.W29.FixedSequential KS.W03.MachineCombinators KS.W07
def unitTerminal : Program 35 := compose (KS.W04.BinaryStackMoves.clearProgram 29) KS.W19.TerminalVectorReplace.unitProgramdef sparseTerminal : Program 35 := compose (KS.W04.BinaryStackMoves.clearProgram 29) KS.W19.TerminalWitnessMachine.program
def terminalSelect (heads : Fin 35 → Fin 3) (_coin : Bool) : KS.W29.FixedBranch.SelectInstruction 35 := ⟨if (heads 29).val = 1 then .left else .right, Vector.ofFn (fun _ => .stay)⟩def terminalProgram : Program 35 := KS.W29.FixedBranch.branch unitTerminal sparseTerminal 23 terminalSelect
def terminalState {n : ℕ} (saved : List Bool) (M : DenseRatMatrix n) (q : Fin n → ℚ) : Fin 35 → List Bool := Function.update (matrixState saved M) 23 (KS.W12.RowDot.vectorTape q)
def unitTicks (n : ℕ) : ℕ := KS.W19.TerminalZeroVector.ticks (n+1) + (KS.W19.TerminalVectorReplace.oneFrame.length+1+ (2*((KS.W19.TerminalVectorReplace.zeroPayloads (n+1)).flatMap KS.W01.frame).length+ 2*KS.W19.TerminalVectorReplace.oneFrame.length+3))
theorem unitTerminal_spec {n : ℕ} (saved : List Bool) (M : DenseRatMatrix (n+1)) : RunSpec unitTerminal (Function.update (matrixState saved M) 29 [false]) (terminalState saved M (Pi.single 0 1)) (2+unitTicks n) := by have hc := KS.W04.CleanRationalCompare.clear_spec (29 : Fin 35) (Function.update (matrixState saved M) 29 [false]) have he : KS.W04.CleanRationalCompare.clearState 29 (Function.update (matrixState saved M) 29 [false]) = matrixState saved M := by funext j; fin_cases j <;> simp [KS.W04.CleanRationalCompare.clearState,matrixState,state,Function.update] rw [he] at hc have hu := KS.W19.TerminalVectorReplace.unit_spec (matrixState saved M) (n+1) (by omega) rfl rfl rfl rfl rfl rfl rfl rw [KS.W19.TerminalVectorReplace.unit_tape] at hu exact hc.compose hu
theorem sparseTerminal_spec {n : ℕ} (saved : List Bool) (M : DenseRatMatrix (n+1)) (b : ℕ) (hnum : ∀ i j, (DenseRatMatrix.decode M i j).num.natAbs ≤ 2^b) (hden : ∀ i j, (DenseRatMatrix.decode M i j).den ≤ 2^b) (j : Fin n) : RunSpec sparseTerminal (Function.update (KS.W19.TerminalWitnessMachine.inputState saved M j.succ) 29 [true]) (terminalState saved M (zeroPivotWitness (DenseRatMatrix.decode M) 0 j.succ)) (2+KS.W19.TerminalWitnessMachine.ticks saved M b j.succ) := by have hc := KS.W04.CleanRationalCompare.clear_spec (29 : Fin 35) (Function.update (KS.W19.TerminalWitnessMachine.inputState saved M j.succ) 29 [true]) have he : KS.W04.CleanRationalCompare.clearState 29 (Function.update (KS.W19.TerminalWitnessMachine.inputState saved M j.succ) 29 [true]) = KS.W19.TerminalWitnessMachine.inputState saved M j.succ := by funext k; fin_cases k <;> simp [KS.W04.CleanRationalCompare.clearState, KS.W19.TerminalWitnessMachine.inputState,Function.update] rw [he] at hc have hs := KS.W19.TerminalWitnessMachine.full_spec saved M b hnum hden j.succ (Fin.succ_ne_zero j) have ho : KS.W19.TerminalWitnessMachine.outputState saved M j.succ = terminalState saved M (zeroPivotWitness (DenseRatMatrix.decode M) 0 j.succ) := by funext k; fin_cases k <;> simp [KS.W19.TerminalWitnessMachine.outputState, terminalState,matrixState,state,Function.update] rw [ho] at hs exact hc.compose hs
theorem terminal_unit_case {n : ℕ} (saved : List Bool) (M : DenseRatMatrix (n+1)) : RunSpec terminalProgram (Function.update (matrixState saved M) 29 [false]) (terminalState saved M (Pi.single 0 1)) ((2+unitTicks n)+1) := by apply KS.W06.RationalCompare.branch_spec_left unitTerminal sparseTerminal 23 terminalSelect _ _ _ _ (unitTerminal_spec saved M) intro coin simp [terminalSelect,observedHeads,KS.W29.topCode,Function.update,KS.W06.RationalCompare.stayActions]
theorem terminal_sparse_case {n : ℕ} (saved : List Bool) (M : DenseRatMatrix (n+1)) (b : ℕ) (hnum : ∀ i j, (DenseRatMatrix.decode M i j).num.natAbs ≤ 2^b) (hden : ∀ i j, (DenseRatMatrix.decode M i j).den ≤ 2^b) (j : Fin n) : RunSpec terminalProgram (Function.update (KS.W19.TerminalWitnessMachine.inputState saved M j.succ) 29 [true]) (terminalState saved M (zeroPivotWitness (DenseRatMatrix.decode M) 0 j.succ)) ((2+KS.W19.TerminalWitnessMachine.ticks saved M b j.succ)+1) := by apply KS.W06.RationalCompare.branch_spec_right unitTerminal sparseTerminal 23 terminalSelect _ _ _ _ (sparseTerminal_spec saved M b hnum hden j) intro coin simp [terminalSelect,observedHeads,KS.W29.topCode,Function.update,KS.W06.RationalCompare.stayActions]
theorem terminal_negative_spec {n : ℕ} (saved : List Bool) (M : DenseRatMatrix (n+1)) (hn : DenseRatMatrix.decode M 0 0 < 0) : RunSpec terminalProgram (withSaved saved (PivotDecision.result M)) (terminalState saved M (Pi.single 0 1)) ((2+unitTicks n)+1) := by rw [PivotDecision.result_negative M hn] have he : withSaved saved (Function.update (PivotRowLoop.initial M) 29 [false]) = Function.update (matrixState saved M) 29 [false] := by funext j; fin_cases j <;> simp [withSaved,PivotRowLoop.initial,PivotRowLoop.state, matrixState,state,Function.update,Computability.encodeNat,Computability.encodeNum] rw [he] exact terminal_unit_case saved M
theorem terminal_sparse_spec {n : ℕ} (saved : List Bool) (M : DenseRatMatrix (n+1)) (b : ℕ) (hnum : ∀ i j, (DenseRatMatrix.decode M i j).num.natAbs ≤ 2^b) (hden : ∀ i j, (DenseRatMatrix.decode M i j).den ≤ 2^b) (j : Fin n) (hz : DenseRatMatrix.decode M 0 0 = 0) (hj : firstNonzeroOffDiagonal (DenseRatMatrix.decode M) = some j) : RunSpec terminalProgram (withSaved saved (PivotDecision.result M)) (terminalState saved M (zeroPivotWitness (DenseRatMatrix.decode M) 0 j.succ)) ((2+KS.W19.TerminalWitnessMachine.ticks saved M b j.succ)+1) := by rw [PivotDecision.result_sparse M j hz hj] have he : withSaved saved (PivotRowLoop.finished M j.succ.val true) = Function.update (KS.W19.TerminalWitnessMachine.inputState saved M j.succ) 29 [true] := by funext k; fin_cases k <;> simp [withSaved,PivotRowLoop.finished, KS.W19.TerminalWitnessMachine.inputState,Function.update] rw [he] exact terminal_sparse_case saved M b hnum hden j
def finishTerminal : Program 35 := compose (KS.W04.CleanRationalCompare.clearListProgram 23 [31,26]) restoreAllProgram
theorem finishTerminal_spec {n N : ℕ} (h : PivotHistory n N) (M : DenseRatMatrix n) (q : Fin n → ℚ) : RunSpec finishTerminal (terminalState (historyTape h) M q) (state [] [] [] [] (KS.W12.RowDot.vectorTape (h.restore q))) ((KS.W08.denseMatrixTape M).length+(Computability.encodeNat n).length+3+restoreTicks h q) := by have hc := KS.W04.CleanRationalCompare.clearList_spec (23 : Fin 35) [31,26] (terminalState (historyTape h) M q) have he : KS.W04.CleanRationalCompare.clearListState [31,26] (terminalState (historyTape h) M q) = state (historyTape h) [] [] [] (KS.W12.RowDot.vectorTape q) := by funext j; fin_cases j <;> simp [KS.W04.CleanRationalCompare.clearListState_apply, terminalState,matrixState,state,Function.update] have ht : KS.W04.CleanRationalCompare.clearListTicks [31,26] (terminalState (historyTape h) M q) = (KS.W08.denseMatrixTape M).length+(Computability.encodeNat n).length+3 := by simp [KS.W04.CleanRationalCompare.clearListTicks,KS.W04.CleanRationalCompare.clearState, terminalState,matrixState,state,Function.update] omega rw [he,ht] at hc exact hc.compose (restoreAll_spec h q)
end KS.W17.FixedPSD
end
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.InnerRight
namespace OAI
noncomputable section
open Matrix
namespace CurrentKS.Hermitian
sectionopen Matrix Setopen scoped BigOperators ComplexOrder MatrixOrder Matrix.Norms.L2Operator
variable {d : ℕ}
lemma exists_pos_lower [NeZero d] {P : H d} (hP : P ∈ pd d) : ∃ a : ℝ, 0 < a ∧ a • (one : H d) ≤ P := by let : CStarAlgebra (Mat d) := {} obtain ⟨a, ha, hap⟩ := (CFC.exists_pos_algebraMap_le_iff (P : Mat d) P.property).mpr ((StarOrderedRing.isStrictlyPositive_iff_spectrum_pos (P : Mat d)).mp hP.isStrictlyPositive) refine ⟨a, ha, ?_⟩ change (a : ℂ) • (1 : Mat d) ≤ (P : Mat d) convert hap using 1 ext i j simp [Matrix.algebraMap_eq_diagonal, Matrix.diagonal_apply, Matrix.smul_apply, Matrix.one_apply]
end
open Matrix Setopen scoped BigOperators ComplexOrder MatrixOrder Matrix.Norms.Frobenius
variable {d : ℕ}
lemma eq_zero_of_inner_pd [NeZero d] {P Z : H d} (hP : P ∈ pd d) (hZ : Z ∈ psdCone d) (hz : inner ℝ P Z = 0) : Z = 0 := by obtain ⟨a, ha, hap⟩ := exists_pos_lower hP have hh := inner_nonneg_of_psd (P-a•one) Z (show P-a•one ∈ psdCone d from hap) hZ rw [inner_sub_left, inner_smul_leftH, inner_one, hz] at hh have htr := realTrace_nonneg hZ apply trace_zero_psd hZ nlinarith
end CurrentKS.Hermitian
end
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import Mathlibimport OAI.Analysis.MatrixSigning.Encoding.ReusableArrayLookupimport OAI.Analysis.MatrixSigning.Matrices.DenseMatrixSerializationimport OAI.Analysis.MatrixSigning.Complexity.StorageCost
namespace OAI
namespace KS.W08
open KS.W07 KS.W29.FixedSequentialopen KS.W04.ReusableArrayLookup
theorem run_preservedMatrix_lookup {n : ℕ} (M : DenseRatMatrix n) (i j : Fin n) (tail bits : List Bool) (hlen : 5 * (denseMatrixTape M ++ tail).length + i.val * n + j.val + 4 ≤ bits.length) : program.toMachine.run ⟨some program.initial, arrayStacks (denseMatrixTape M ++ tail) [] [] [] (denseMatrixCursor i j)⟩ bits = ⟨none, arrayStacks (denseMatrixTape M ++ tail) [] (KS.W01.encodeRat (AccessCounted.readMatrix M i j).value) [] []⟩ := by have hi : i.val * n + j.val < (denseMatrixPayloads M).length := by rw [denseMatrixPayloads_length] exact matrixEntryIndex_lt i j have h := run_program (denseMatrixPayloads M) (i.val * n + j.val) hi tail bits (by simpa only [denseMatrixTape, Nat.add_assoc] using hlen) simpa only [denseMatrixTape, denseMatrixCursor, denseMatrixPayloads_get, AccessCounted.readMatrix_value] using h
theorem preservedMatrix_lookup_time {n : ℕ} (M : DenseRatMatrix n) (b : ℕ) (hnum : ∀ i j, (DenseRatMatrix.decode M i j).num.natAbs ≤ 2 ^ b) (hden : ∀ i j, (DenseRatMatrix.decode M i j).den ≤ 2 ^ b) (i j : Fin n) : HaltsFromWithin program ⟨some program.initial, arrayStacks (denseMatrixTape M) [] [] [] (denseMatrixCursor i j)⟩ (n * n * (40 * b + 76) + 4) := by intro bits hlen have ht := denseMatrixTape_length_le M b hnum hden have hi := (matrixEntryIndex_lt i j).le have hb : 5 * (denseMatrixTape M ++ []).length + i.val * n + j.val + 4 ≤ bits.length := by rw [List.append_nil, hlen] calc _ ≤ 5 * (n * n * (8 * b + 15)) + n * n + 4 := by omega _ = _ := by ring have h := run_preservedMatrix_lookup M i j [] bits hb simp only [List.append_nil] at h exact congrArg (fun c => c.state) h
end KS.W08
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.RealTrace
namespace OAI
open Matrix
namespace CurrentKSnoncomputable sectionopen Matrixopen scoped BigOperators ComplexOrder
variable {d : ℕ}
lemma rank_one_factor (A : Matrix (Fin d) (Fin d) ℂ) (hA : A.PosSemidef) (hrank : A.rank ≤ 1) : ∃ u : Fin d → ℂ, A = vecMulVec u (star u) := by classical by_cases hzero : A = 0 · refine ⟨0, ?_⟩ rw [hzero] ext j k simp [vecMulVec] have he : ∃ i, hA.isHermitian.eigenvalues i ≠ 0 := by by_contra! hh apply hzero exact hA.isHermitian.eigenvalues_eq_zero_iff.mp (funext hh) obtain ⟨i,hi⟩ := he let U : Matrix (Fin d) (Fin d) ℂ := hA.isHermitian.eigenvectorUnitary let e : ℝ := hA.isHermitian.eigenvalues i have he0 : 0 ≤ e := hA.eigenvalues_nonneg i have hsqrt : (Real.sqrt e : ℂ) * (Real.sqrt e : ℂ) = (e : ℂ) := by exact_mod_cast Real.mul_self_sqrt he0 refine ⟨fun j => (Real.sqrt e : ℂ) * U j i, ?_⟩ have hspec := hA.isHermitian.spectral_theorem rw [Unitary.conjStarAlgAut_apply,Matrix.star_eq_conjTranspose] at hspec rw [hspec] ext j k change ∑ l, ((U * diagonal ((RCLike.ofReal : ℝ → ℂ) ∘ hA.isHermitian.eigenvalues)) j l) * U.conjTranspose l k = ((Real.sqrt e : ℂ)*U j i) * star ((Real.sqrt e : ℂ)*U k i) rw [Finset.sum_eq_single i] · simp only [Matrix.mul_diagonal,Function.comp_apply,Matrix.conjTranspose_apply, StarMul.star_mul,Complex.star_def,Complex.conj_ofReal] change U j i * (e : ℂ) * star (U k i) = ((Real.sqrt e : ℂ) * U j i) * (star (U k i) * (Real.sqrt e : ℂ)) rw [← hsqrt] ring · intro l _ hli have hl : hA.isHermitian.eigenvalues l = 0 := by by_contra hl exact hli (nonzero_eigenvalue_unique A hA.isHermitian hrank l i hl hi) simp only [Matrix.mul_diagonal,Function.comp_apply,hl,RCLike.ofReal_zero,mul_zero,zero_mul] · simp
lemma outer_sandwich (u : Fin d → ℂ) (B : Matrix (Fin d) (Fin d) ℂ) : vecMulVec u (star u) * B * vecMulVec u (star u) = (star u ⬝ᵥ (B *ᵥ u)) • vecMulVec u (star u) := by ext i j simp only [Matrix.mul_apply,vecMulVec_apply,Matrix.smul_apply,smul_eq_mul, Matrix.mulVec,dotProduct] simp only [Finset.sum_mul,Finset.mul_sum] rw [Finset.sum_comm] apply Finset.sum_congr rfl intro k _ apply Finset.sum_congr rfl intro l _ ring
lemma trace_outer_mul (u : Fin d → ℂ) (B : Matrix (Fin d) (Fin d) ℂ) : (vecMulVec u (star u) * B).trace = star u ⬝ᵥ (B *ᵥ u) := by simp only [Matrix.trace,Matrix.diag,Matrix.mul_apply,vecMulVec_apply,Matrix.mulVec,dotProduct, Finset.mul_sum] rw [Finset.sum_comm] apply Finset.sum_congr rfl intro i _ apply Finset.sum_congr rfl intro j _ ring
lemma rank_one_sandwich (A : Matrix (Fin d) (Fin d) ℂ) (hA : A.PosSemidef) (hrank : A.rank ≤ 1) (B : Matrix (Fin d) (Fin d) ℂ) : A*B*A = (A*B).trace • A := by obtain ⟨u,rfl⟩ := rank_one_factor A hA hrank rw [outer_sandwich,trace_outer_mul]
endend CurrentKS
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172import Mathlibimport OAI.Analysis.MatrixSigning.Optimization.NegativeWitness
namespace OAI
section
namespace KS.W17
def trailingMatrix {n : ℕ} (M : Matrix (Fin (n + 1)) (Fin (n + 1)) ℚ) : Matrix (Fin n) (Fin n) ℚ := fun i j => M i.succ j.succ
def schurTail {n : ℕ} (M : Matrix (Fin (n + 1)) (Fin (n + 1)) ℚ) : Matrix (Fin n) (Fin n) ℚ := fun i j => M i.succ j.succ - M i.succ 0 * M 0 j.succ / M 0 0
theorem trailingMatrix_isSymm {n : ℕ} (M : Matrix (Fin (n + 1)) (Fin (n + 1)) ℚ) (hM : M.IsSymm) : (trailingMatrix M).IsSymm := by apply Matrix.IsSymm.ext intro i j exact hM.apply i.succ j.succ
theorem schurTail_isSymm {n : ℕ} (M : Matrix (Fin (n + 1)) (Fin (n + 1)) ℚ) (hM : M.IsSymm) : (schurTail M).IsSymm := by apply Matrix.IsSymm.ext intro i j simp only [schurTail] rw [hM.apply i.succ j.succ, hM.apply 0 j.succ, hM.apply 0 i.succ] rw [mul_comm (M 0 j.succ) (M 0 i.succ)]
def schurWitnessLift {n : ℕ} (M : Matrix (Fin (n + 1)) (Fin (n + 1)) ℚ) (y : Fin n → ℚ) : Fin (n + 1) → ℚ := Fin.cons (-(∑ j, M 0 j.succ * y j) / M 0 0) y
def firstNonzeroOffDiagonal {n : ℕ} (M : Matrix (Fin (n + 1)) (Fin (n + 1)) ℚ) : Option (Fin n) := (List.finRange n).find? (fun j => decide (M 0 j.succ ≠ 0))
theorem firstNonzeroOffDiagonal_some {n : ℕ} (M : Matrix (Fin (n + 1)) (Fin (n + 1)) ℚ) (j : Fin n) (h : firstNonzeroOffDiagonal M = some j) : M 0 j.succ ≠ 0 := by have hj := List.find?_some h simpa using hj
theorem firstNonzeroOffDiagonal_none_iff {n : ℕ} (M : Matrix (Fin (n + 1)) (Fin (n + 1)) ℚ) : firstNonzeroOffDiagonal M = none ↔ ∀ j : Fin n, M 0 j.succ = 0 := by simp [firstNonzeroOffDiagonal, List.find?_eq_none]
def rationalNegativeWitness : (n : ℕ) → Matrix (Fin n) (Fin n) ℚ → Option (Fin n → ℚ) | 0, _ => none | n + 1, M => if M 0 0 < 0 then some (Pi.single 0 1) else if M 0 0 = 0 then match firstNonzeroOffDiagonal M with | some j => some (zeroPivotWitness M 0 j.succ) | none => (rationalNegativeWitness n (trailingMatrix M)).map (Fin.cons 0) else (rationalNegativeWitness n (schurTail M)).map (schurWitnessLift M)
theorem rationalNegativeWitness_negative_pivot {n : ℕ} (M : Matrix (Fin (n + 1)) (Fin (n + 1)) ℚ) (h : M 0 0 < 0) : rationalNegativeWitness (n + 1) M = some (Pi.single 0 1) := by simp [rationalNegativeWitness, h]
end KS.W17
end
end OAI1234567891011121314151617181920212223242526272829import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.EliminationCompleteness
namespace OAI
section
namespace KS.W17open Matrix
theorem rationalNegativeWitness_none_iff_psd (n : ℕ) (M : Matrix (Fin n) (Fin n) ℚ) (hM : M.IsSymm) : rationalNegativeWitness n M = none ↔ (M.map (fun q : ℚ => (q : ℝ))).PosSemidef := by constructor · exact rationalNegativeWitness_none_psd n M hM · intro hPSD cases ho : rationalNegativeWitness n M with | none => rfl | some q => have hs := computedPSDSeparator_separates n M hM q ho have hn := hs.2 (M.map (fun r : ℚ => (r : ℝ))) hPSD exact (not_lt_of_ge hn hs.1).elim
end KS.W17
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293import Mathlibimport OAI.Analysis.MatrixSigning.Machines.Realificationimport OAI.Analysis.MatrixSigning.Matrices.Space
namespace OAI
namespace CurrentKS.HermitianCoordinatesopen Matrixopen scoped BigOperators
variable {d : ℕ}
def realDecode {R : Type*} [Ring R] (x : Fin d × Fin d → R) : Matrix (Fin d ⊕ Fin d) (Fin d ⊕ Fin d) R := let re := fun i j => x (min i j,max i j) let im := fun i j => if i < j then x (j,i) else if j < i then -x (i,j) else 0 Matrix.fromBlocks re (-im) im re
private lemma realDecode_inl_inl {R : Type*} [Ring R] (x : Fin d × Fin d → R) (i j : Fin d) : realDecode x (Sum.inl i) (Sum.inl j) = x (min i j, max i j) := rfl
private lemma realDecode_inl_inr {R : Type*} [Ring R] (x : Fin d × Fin d → R) (i j : Fin d) : realDecode x (Sum.inl i) (Sum.inr j) = -(if i < j then x (j, i) else if j < i then -x (i, j) else 0) := rfl
private lemma realDecode_inr_inl {R : Type*} [Ring R] (x : Fin d × Fin d → R) (i j : Fin d) : realDecode x (Sum.inr i) (Sum.inl j) = (if i < j then x (j, i) else if j < i then -x (i, j) else 0) := rfl
private lemma realDecode_inr_inr {R : Type*} [Ring R] (x : Fin d × Fin d → R) (i j : Fin d) : realDecode x (Sum.inr i) (Sum.inr j) = x (min i j, max i j) := rfl
lemma realDecode_isSymm {R : Type*} [Ring R] (x : Fin d × Fin d → R) : (realDecode x).IsSymm := by apply Matrix.IsSymm.ext intro i j cases i with | inl i => cases j with | inl j => simp [realDecode_inl_inl,min_comm,max_comm] | inr j => rcases lt_trichotomy i j with h | h | h · simp [realDecode_inl_inr, realDecode_inr_inl,h,not_lt.mpr h.le] · subst j; simp [realDecode_inl_inr, realDecode_inr_inl] · simp [realDecode_inl_inr, realDecode_inr_inl,h,not_lt.mpr h.le] | inr i => cases j with | inl j => rcases lt_trichotomy i j with h | h | h · simp [realDecode_inl_inr, realDecode_inr_inl,h,not_lt.mpr h.le] · subst j; simp [realDecode_inl_inr, realDecode_inr_inl] · simp [realDecode_inl_inr, realDecode_inr_inl,h,not_lt.mpr h.le] | inr j => simp [realDecode_inr_inr,min_comm,max_comm]
lemma realDecode_eq_realify (x : Fin d × Fin d → ℝ) : realDecode x = KS.W08.realify (decode x) := by ext i j cases i <;> cases j <;> rfl
lemma realDecode_map {R S : Type*} [Ring R] [Ring S] (f : R →+* S) (x : Fin d × Fin d → R) : (realDecode x).map f=realDecode (f ∘ x) := by ext i j cases i <;> cases j <;> simp only [realDecode_inl_inl, realDecode_inl_inr, realDecode_inr_inl, realDecode_inr_inr, Matrix.map_apply, Function.comp_def,map_neg] all_goals split_ifs <;> simp only [map_neg,map_zero]
lemma realDecode_add {R : Type*} [Ring R] (x y : Fin d × Fin d → R) : realDecode (x+y)=realDecode x+realDecode y := by ext i j cases i <;> cases j <;> simp [realDecode_inl_inl, realDecode_inl_inr, realDecode_inr_inl, realDecode_inr_inr] <;> split_ifs <;> abel
lemma realDecode_smul {R : Type*} [CommRing R] (r : R) (x : Fin d × Fin d → R) : realDecode (r • x)=r • realDecode x := by ext i j cases i <;> cases j <;> simp [realDecode_inl_inl, realDecode_inl_inr, realDecode_inr_inl, realDecode_inr_inr]
def realDecodeLinear {R : Type*} [CommRing R] (d : ℕ) : (Fin d × Fin d → R) →ₗ[R] Matrix (Fin d ⊕ Fin d) (Fin d ⊕ Fin d) R where toFun := realDecode map_add' := realDecode_add map_smul' := realDecode_smul
lemma realDecode_ratCast (x : Fin d × Fin d → ℚ) : (realDecode x).map (fun q => (q:ℝ))=realDecode (fun i => (x i:ℝ)) := realDecode_map (algebraMap ℚ ℝ) xend CurrentKS.HermitianCoordinates
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141import Mathlib
namespace OAI
open Matrix
namespace CurrentKSnoncomputable sectionopen scoped BigOperators ComplexOrder
variable {d : ℕ}
def realTrace (A : Matrix (Fin d) (Fin d) ℂ) : ℝ := A.trace.re
def traceSign (A : Matrix (Fin d) (Fin d) ℂ) : ℝ := if 0 ≤ realTrace A then 1 else -1
theorem traceSign_mem (A : Matrix (Fin d) (Fin d) ℂ) : traceSign A = -1 ∨ traceSign A = 1 := by unfold traceSign split_ifs <;> simp
theorem nonzero_eigenvalues_card_le (A : Matrix (Fin d) (Fin d) ℂ) (hA : A.IsHermitian) : Fintype.card {i // hA.eigenvalues i ≠ 0} ≤ A.rank := by classical have h := hA.conjStarAlgAut_star_eigenvectorUnitary have hr : (Matrix.diagonal ((RCLike.ofReal : ℝ → ℂ) ∘ hA.eigenvalues)).rank ≤ A.rank := by rw [← h] simp only [Unitary.conjStarAlgAut_apply] exact (Matrix.rank_mul_le_left _ _).trans (Matrix.rank_mul_le_right _ _) rw [Matrix.rank_diagonal] at hr simpa only [Function.comp_apply, ne_eq, RCLike.ofReal_eq_zero] using hr
theorem nonzero_eigenvalue_unique (A : Matrix (Fin d) (Fin d) ℂ) (hA : A.IsHermitian) (hrank : A.rank ≤ 1) (i j : Fin d) (hi : hA.eigenvalues i ≠ 0) (hj : hA.eigenvalues j ≠ 0) : i = j := by have hcard : Fintype.card {i // hA.eigenvalues i ≠ 0} ≤ 1 := (nonzero_eigenvalues_card_le A hA).trans hrank have hs := Fintype.card_le_one_iff_subsingleton.mp hcard exact congrArg Subtype.val (hs.elim (⟨i, hi⟩ : {i // hA.eigenvalues i ≠ 0}) ⟨j, hj⟩)
theorem eigenvalue_eq_realTrace (A : Matrix (Fin d) (Fin d) ℂ) (hA : A.IsHermitian) (hrank : A.rank ≤ 1) (i : Fin d) (hi : hA.eigenvalues i ≠ 0) : hA.eigenvalues i = realTrace A := by classical unfold realTrace rw [hA.trace_eq_sum_eigenvalues, Complex.re_sum] symm apply Finset.sum_eq_single i · intro j _ hji have hj : hA.eigenvalues j = 0 := by by_contra hj exact hji (nonzero_eigenvalue_unique A hA hrank j i hj hi) simp [hj] · simp
theorem eigenvalue_eq_zero_or_trace (A : Matrix (Fin d) (Fin d) ℂ) (hA : A.IsHermitian) (hrank : A.rank ≤ 1) (i : Fin d) : hA.eigenvalues i = 0 ∨ hA.eigenvalues i = realTrace A := by by_cases hi : hA.eigenvalues i = 0 · exact Or.inl hi · exact Or.inr (eigenvalue_eq_realTrace A hA hrank i hi)
theorem realTrace_eq_zero_iff (A : Matrix (Fin d) (Fin d) ℂ) (hA : A.IsHermitian) (hrank : A.rank ≤ 1) : realTrace A = 0 ↔ A = 0 := by constructor · intro ht apply hA.eigenvalues_eq_zero_iff.mp funext i rcases eigenvalue_eq_zero_or_trace A hA hrank i with hi | hi · exact hi · exact hi.trans ht · rintro rfl simp [realTrace]
theorem traceSign_mul_trace (A : Matrix (Fin d) (Fin d) ℂ) : traceSign A * realTrace A = |realTrace A| := by unfold traceSign split_ifs with h · simp [abs_of_nonneg h] · simp [abs_of_neg (lt_of_not_ge h)]
theorem traceSign_sq (A : Matrix (Fin d) (Fin d) ℂ) : traceSign A * traceSign A = 1 := by rcases traceSign_mem A with h | h <;> rw [h] <;> norm_num
theorem traceSign_smul_posSemidef (A : Matrix (Fin d) (Fin d) ℂ) (hA : A.IsHermitian) (hrank : A.rank ≤ 1) : (traceSign A • A).PosSemidef := by change ((traceSign A : ℂ) • A).PosSemidef have hd : ((traceSign A : ℂ) • Matrix.diagonal ((RCLike.ofReal : ℝ → ℂ) ∘ hA.eigenvalues)).PosSemidef := by rw [← Matrix.diagonal_smul] apply Matrix.posSemidef_diagonal_iff.mpr intro i change 0 ≤ (traceSign A : ℂ) * (hA.eigenvalues i : ℂ) rw [← Complex.ofReal_mul, Complex.zero_le_real] rcases eigenvalue_eq_zero_or_trace A hA hrank i with hi | hi · simp [hi] · rw [hi, traceSign_mul_trace] exact abs_nonneg _ have hp := hd.mul_mul_conjTranspose_same (↑hA.eigenvectorUnitary : Matrix (Fin d) (Fin d) ℂ) have he := hA.spectral_theorem rw [Unitary.conjStarAlgAut_apply, Matrix.star_eq_conjTranspose] at he simpa only [Matrix.smul_mul, Matrix.mul_smul, ← he] using hp
theorem rank_one_square (A : Matrix (Fin d) (Fin d) ℂ) (hA : A.IsHermitian) (hrank : A.rank ≤ 1) : A * A = realTrace A • A := by let D : Matrix (Fin d) (Fin d) ℂ := Matrix.diagonal ((RCLike.ofReal : ℝ → ℂ) ∘ hA.eigenvalues) have hd : D * D = (realTrace A : ℂ) • D := by dsimp [D] rw [Matrix.diagonal_mul_diagonal, ← Matrix.diagonal_smul] congr 1 funext i change (hA.eigenvalues i : ℂ) * (hA.eigenvalues i : ℂ) = (realTrace A : ℂ) * (hA.eigenvalues i : ℂ) rcases eigenvalue_eq_zero_or_trace A hA hrank i with hi | hi · simp [hi] · rw [hi] have he : A = Unitary.conjStarAlgAut ℂ _ hA.eigenvectorUnitary D := hA.spectral_theorem calc A * A = Unitary.conjStarAlgAut ℂ _ hA.eigenvectorUnitary (D * D) := by rw [map_mul, ← he] _ = (realTrace A : ℂ) • A := by rw [hd, map_smul, ← he] _ = realTrace A • A := by ext i j; simp [Complex.real_smul]
theorem realTrace_smul (r : ℝ) (A : Matrix (Fin d) (Fin d) ℂ) : realTrace (r • A) = r * realTrace A := by simp [realTrace, Matrix.trace, Matrix.diag, Finset.mul_sum]
endend CurrentKS
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.TraceCLM
namespace OAI
open Matrix
namespace CurrentKS.Hermitiannoncomputable sectionopen Matrixopen scoped BigOperators ComplexOrder MatrixOrder Matrix.Norms.Frobenius
variable {d : ℕ}
lemma realTrace_sum {ι : Type*} (s : Finset ι) (A : ι → H d) : realTrace (∑ i ∈ s, A i) = ∑ i ∈ s, realTrace (A i) := by simp only [← inner_one, inner_sum]
lemma psd_sum {ι : Type*} (s : Finset ι) (A : ι → H d) (hA : ∀ i ∈ s, A i ∈ psdCone d) : (∑ i ∈ s, A i) ∈ psdCone d := by exact (mem_psd_iff_nonneg _).mpr (Finset.sum_nonneg fun i hi => (mem_psd_iff_nonneg _).mp (hA i hi))
lemma smul_order {A B : H d} (h : A ≤ B) {r : ℝ} (hr : 0 ≤ r) : r • A ≤ r • B := by apply sub_nonneg.mp rw [← smul_sub r B A] exact (mem_psd_iff_nonneg _).mp (psd_smul ((mem_psd_iff_nonneg _).mpr (sub_nonneg.mpr h)) hr)
lemma scalar_mono_psd {A : H d} (hA : A ∈ psdCone d) {r s : ℝ} (hrs : r ≤ s) : r • A ≤ s • A := by apply sub_nonneg.mp rw [← sub_smul s r A] exact (mem_psd_iff_nonneg _).mp (psd_smul hA (sub_nonneg.mpr hrs))
lemma invH_scalar (a : ℝ) : invH (a • (Hermitian.one : H d)) = a⁻¹ • (Hermitian.one : H d) := by apply Subtype.ext change (a • (1 : Mat d))⁻¹ = a⁻¹ • (1 : Mat d) have h (r : ℝ) : r • (1 : Mat d) = (r : ℂ) • (1 : Mat d) := by ext i j exact Complex.real_smul rw [h a, h a⁻¹, Complex.ofReal_inv] exact scalar_inv a
endend CurrentKS.Hermitian
end OAI12345678910111213141516171819202122232425262728293031323334353637383940import Mathlibimport OAI.Analysis.MatrixSigning.Machines.RealificationSPD
namespace OAI
open Matrix
namespace KS.W08open Matrixopen scoped ComplexOrder BigOperators
lemma realify_isHermitian_iff {n : Type*} (A : Matrix n n ℂ) : (realify A).IsHermitian ↔ A.IsHermitian := by refine ⟨?_,realify_isHermitian A⟩ intro h apply realify_injective rw [realify_conjTranspose] simpa using h.eq
theorem realify_posSemidef_iff {n : Type*} [Fintype n] (A : Matrix n n ℂ) : (realify A).PosSemidef ↔ A.PosSemidef := by constructor · intro h refine Matrix.PosSemidef.of_dotProduct_mulVec_nonneg ((realify_isHermitian_iff A).mp h.isHermitian) ?_ intro v have hv := h.dotProduct_mulVec_nonneg (realifyVector v) rw [star_trivial,← realify_mulVec,realifyVector_dotProduct] at hv exact Complex.nonneg_iff.mpr ⟨hv,((realify_isHermitian_iff A).mp h.isHermitian |>.im_star_dotProduct_mulVec_self v).symm⟩ · intro h refine Matrix.PosSemidef.of_dotProduct_mulVec_nonneg (realify_isHermitian A h.isHermitian) ?_ intro v have hv := h.dotProduct_mulVec_nonneg (complexifyVector v) have hr : 0 ≤ (star (complexifyVector v) ⬝ᵥ (A *ᵥ complexifyVector v)).re := Complex.nonneg_iff.mp hv |>.1 rw [← realifyVector_dotProduct,realify_mulVec,realifyVector_complexify] at hr simpa only [star_trivial] using hr
end KS.W08
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.JordanCLM
namespace OAI
noncomputable section
open Matrix
namespace CurrentKS.Hermitianopen Matrix Setopen scoped BigOperators ComplexOrder MatrixOrder Matrix.Norms.Frobenius
variable {d : ℕ}
private local instance : NormedAddCommGroup (Mat d) := inferInstanceprivate local instance : NormedSpace ℝ (Mat d) := inferInstanceprivate local instance : TopologicalSpace (Mat d) := (inferInstance : NormedAddCommGroup (Mat d)).toUniformSpace.toTopologicalSpace
private local instance : NormedAddCommGroup (H d) := inferInstanceprivate local instance : NormedSpace ℝ (H d) := inferInstanceprivate local instance : TopologicalSpace (H d) := (inferInstance : NormedAddCommGroup (H d)).toUniformSpace.toTopologicalSpace
def retractH : Mat d →L[ℝ] H d := (hermitianSubmodule d).orthogonalProjectionOnto
@[simp] lemma retractH_coe (A : H d) : retractH (A : Mat d) = A := Submodule.orthogonalProjectionOnto_mem_subspace_eq_self A
lemma invH_retract (A : H d) : invH A = retractH (Ring.inverse (A : Mat d)) := by rw [← Matrix.nonsing_inv_eq_ringInverse] exact (retractH_coe (invH A)).symm
lemma contDiffAt_invH {A : H d} (hA : A ∈ pd d) {n : WithTop ℕ∞} : ContDiffAt ℝ n invH A := by obtain ⟨a,ha⟩ := hA.isUnit have hi : ContDiffAt ℝ n Ring.inverse (A : Mat d) := by rw [← ha] exact contDiffAt_ringInverse ℝ a have hc := (retractH (d := d)).contDiff.contDiffAt.comp A (hi.comp A (hermitianSubmodule d).subtypeL.contDiff.contDiffAt) apply hc.congr_of_eventuallyEq exact Filter.Eventually.of_forall fun B => invH_retract B
lemma hasFDerivAt_invH {A : H d} (hA : A ∈ pd d) : HasFDerivAt invH (-sandwichCLM (invH A)) A := by obtain ⟨a,ha⟩ := hA.isUnit have hi : HasFDerivAt (fun B : Mat d => B⁻¹) (-ContinuousLinearMap.mulLeftRight ℝ (Mat d) (A : Mat d)⁻¹ (A : Mat d)⁻¹) (A : Mat d) := by rw [← ha] simpa only [Matrix.nonsing_inv_eq_ringInverse, Matrix.coe_units_inv] using (hasFDerivAt_ringInverse (𝕜 := ℝ) a) have hc := (retractH (d := d)).hasFDerivAt.comp A (hi.comp A (hermitianSubmodule d).subtypeL.hasFDerivAt) have he : (fun B : H d => retractH ((B : Mat d)⁻¹)) = invH := by funext B exact retractH_coe (invH B) change HasFDerivAt (fun B : H d => retractH ((B : Mat d)⁻¹)) _ A at hc rw [he] at hc refine hc.congr_fderiv ?_ symm apply ContinuousLinearMap.ext intro U change -sandwich (invH A) U = retractH (-((A : Mat d)⁻¹ * (U : Mat d) * (A : Mat d)⁻¹)) rw [map_neg] exact congrArg Neg.neg (retractH_coe (sandwich (invH A) U)).symm
lemma contDiff_sandwich {n : WithTop ℕ∞} : ContDiff ℝ n (fun z : H d × H d => sandwich z.1 z.2) := by have hf : (fun z : H d × H d => sandwich z.1 z.2) = (fun z : H d × H d => retractH ((z.1 : Mat d) * (z.2 : Mat d) * (z.1 : Mat d))) := by funext z exact (retractH_coe (sandwich z.1 z.2)).symm rw [hf] apply (retractH (d := d)).contDiff.comp exact (((hermitianSubmodule d).subtypeL.contDiff.comp contDiff_fst).mul ((hermitianSubmodule d).subtypeL.contDiff.comp contDiff_snd)).mul ((hermitianSubmodule d).subtypeL.contDiff.comp contDiff_fst)
lemma hasFDerivAt_invSandwich (A P : H d) (hA : A ∈ pd d) : HasFDerivAt (fun z : H d × H d => sandwich (invH z.1) z.2) ((-jordanCLM (invH A) (sandwich (invH A) P)).comp (ContinuousLinearMap.fst ℝ (H d) (H d)) + (sandwichCLM (invH A)).comp (ContinuousLinearMap.snd ℝ (H d) (H d))) (A,P) := by let val := (hermitianSubmodule d).subtypeL have hInv := val.hasFDerivAt.comp (A,P) ((hasFDerivAt_invH hA).comp (A,P) (hasFDerivAt_fst (p := (A,P)))) have hMid := val.hasFDerivAt.comp (A,P) (hasFDerivAt_snd (p := (A,P))) have hm := (hInv.mul' hMid).mul' hInv have hh := (retractH (d := d)).hasFDerivAt.comp (A,P) hm have he : (fun z : H d × H d => retractH (((invH z.1 : H d) : Mat d) * (z.2 : Mat d) * ((invH z.1 : H d) : Mat d))) = (fun z : H d × H d => sandwich (invH z.1) z.2) := by funext z exact retractH_coe (sandwich (invH z.1) z.2) change HasFDerivAt (fun z : H d × H d => retractH (((invH z.1 : H d) : Mat d) * (z.2 : Mat d) * ((invH z.1 : H d) : Mat d))) _ (A,P) at hh rw [he] at hh refine hh.congr_fderiv ?_ symm apply ContinuousLinearMap.ext intro z change -jordanCLM (invH A) (sandwich (invH A) P) z.1 + sandwich (invH A) z.2 = retractH (((invH A : H d) : Mat d) * (P : Mat d) * (-(((invH A : H d) : Mat d) * (z.1 : Mat d) * ((invH A : H d) : Mat d))) + (((invH A : H d) : Mat d) * (z.2 : Mat d) + (-(((invH A : H d) : Mat d) * (z.1 : Mat d) * ((invH A : H d) : Mat d))) * (P : Mat d)) * ((invH A : H d) : Mat d)) rw [← retractH_coe (-jordanCLM (invH A) (sandwich (invH A) P) z.1 + sandwich (invH A) z.2)] congr 1 simp only [Submodule.coe_add, Submodule.coe_neg, jordanCLM_val, sandwich_val] noncomm_ring
lemma contDiffAt_invSandwich (A P : H d) (hA : A ∈ pd d) {n : WithTop ℕ∞} : ContDiffAt ℝ n (fun z : H d × H d => sandwich (invH z.1) z.2) (A,P) := by have hi : ContDiffAt ℝ n (fun z : H d × H d => invH z.1) (A,P) := (contDiffAt_invH (d := d) (A := A) (n := n) hA).fst' (y := P) have hp : ContDiffAt ℝ n (fun z : H d × H d => (invH z.1, z.2)) (A,P) := hi.prodMk (contDiffAt_snd (𝕜 := ℝ) (n := n) (p := (A,P))) have hs : ContDiffAt ℝ n (fun u : H d × H d => sandwich u.1 u.2) (invH A,P) := (contDiff_sandwich (d := d) (n := n)).contDiffAt exact hs.comp (A,P) hp
end CurrentKS.Hermitian
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.RowDotCounterimport OAI.Analysis.MatrixSigning.Matrices.RowDotModelimport OAI.Analysis.MatrixSigning.Matrices.RowDotPrimitives
namespace OAI
namespace KS.W12.RowDotopen KS.W01.FixedStack KS.W29.FixedSequential KS.W03.MachineCombinators
def copyColumn : Program 29 := copyProgram 24 0 (by decide) (by decide) (by decide)def copyRow : Program 29 := copyProgram 21 1 (by decide) (by decide) (by decide)def copyDimension : Program 29 := copyProgram 22 2 (by decide) (by decide) (by decide)def collectProgram : Program 29 := compose (compose (compose (compose decodeProgram copyColumn) copyRow) copyDimension) readProgram
def pairProgram : Program 29 := compose (compose (compose (StackTransfer.program 27 28 26) (StackTransfer.program 0 28 26)) frameProgram) appendProgram
def body : Program 29 := compose (compose collectProgram pairProgram) incrementProgram
def collectTicks (n b k row : ℕ) (q : ℚ) : ℕ := 3 * (KS.W01.encodeRat q).length + 2 + (2 * (Computability.encodeNat k).length + 2) + (2 * (Computability.encodeNat row).length + 2) + (2 * (Computability.encodeNat n).length + 2) + 1024 * (n + 1) ^ 2 * (b + 1)
def pairTicks (a q : ℚ) : ℕ := (2 * (KS.W01.encodeRat q).length + 2) + (2 * (KS.W01.encodeRat a).length + 2) + (4 * (KS.W01.encodeRat a ++ KS.W01.encodeRat q).length + 3) + ((KS.W01.frame (KS.W01.encodeRat a ++ KS.W01.encodeRat q)).length + 1)
def bodyTicks {n : ℕ} (M : KS.W07.DenseRatMatrix n) (b : ℕ) (i : Fin n) (p : Fin n × ℚ) : ℕ := collectTicks n b p.1.val i.val p.2 + pairTicks (KS.W07.DenseRatMatrix.decode M i p.1) p.2 + incrementTicks p.1.val
theorem collect_spec {n : ℕ} (M : KS.W07.DenseRatMatrix n) (b : ℕ) (hnum : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).num.natAbs ≤ 2 ^ b) (hden : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).den ≤ 2 ^ b) (x : Fin n → ℚ) (i : Fin n) (p : Fin n × ℚ) (xs : List (Fin n × ℚ)) (out : List Bool) : RunSpec collectProgram (boundary M x i (p :: xs) p.1.val out) (put (put (boundary M x i xs p.1.val out) 27 (KS.W01.encodeRat p.2)) 0 (KS.W01.encodeRat (KS.W07.DenseRatMatrix.decode M i p.1))) (collectTicks n b p.1.val i.val p.2) := by let s0 := boundary M x i (p :: xs) p.1.val out let s1 := put (boundary M x i xs p.1.val out) 27 (KS.W01.encodeRat p.2) let s2 := put s1 0 (Computability.encodeNat p.1.val) let s3 := put s2 1 (Computability.encodeNat i.val) let s4 := put s3 2 (Computability.encodeNat n) have h1 : RunSpec decodeProgram s0 s1 (3 * (KS.W01.encodeRat p.2).length + 2) := by convert decode_spec s0 (KS.W01.encodeRat p.2) (tailTape xs) rfl rfl rfl using 1 funext j fin_cases j <;> simp [s0, s1, boundary, state, put] have h2 : RunSpec copyColumn s1 s2 (2 * (Computability.encodeNat p.1.val).length + 2) := copy_spec 24 0 (by decide) (by decide) (by decide) s1 rfl rfl have h3 : RunSpec copyRow s2 s3 (2 * (Computability.encodeNat i.val).length + 2) := copy_spec 21 1 (by decide) (by decide) (by decide) s2 rfl rfl have h4 : RunSpec copyDimension s3 s4 (2 * (Computability.encodeNat n).length + 2) := copy_spec 22 2 (by decide) (by decide) (by decide) s3 rfl rfl have h5 : RunSpec readProgram s4 (put s1 0 (KS.W01.encodeRat (KS.W07.DenseRatMatrix.decode M i p.1))) (1024 * (n + 1) ^ 2 * (b + 1)) := by exact read_spec M b hnum hden i p.1 s1 rfl (by intro r; fin_cases r <;> rfl) exact (((h1.compose h2).compose h3).compose h4).compose h5
theorem pair_spec (s : Fin 29 → List Bool) (a q : ℚ) (h0 : s 0 = KS.W01.encodeRat a) (h27 : s 27 = KS.W01.encodeRat q) (h4 : s 4 = []) (h26 : s 26 = []) (h28 : s 28 = []) : RunSpec pairProgram s (put (put (put s 0 []) 27 []) 25 ((FixedDot.pairWire (a, q)).reverse ++ s 25)) (pairTicks a q) := by let s1 := StackTransfer.after 27 28 s let s2 := StackTransfer.after 0 28 s1 let s3 := put s2 28 (KS.W01.frame (s2 28)) have h1 := StackTransfer.spec (27 : Fin 29) 28 26 (by decide) (by decide) (by decide) s h26 have h2 := StackTransfer.spec (0 : Fin 29) 28 26 (by decide) (by decide) (by decide) s1 (by simp [s1, StackTransfer.after, h26]) have h3 := frame_spec s2 (by simp [s2, s1, StackTransfer.after, h4]) (by simp [s2, s1, StackTransfer.after, h26]) have h4' := append_spec s3 have h := ((h1.compose h2).compose h3).compose h4' convert h using 1 <;> (try rfl) · funext j fin_cases j <;> simp [s1, s2, s3, put, StackTransfer.after, h0, h27, h28, FixedDot.pairWire, FixedDot.pairPayload] · simp [pairTicks, s1, s2, s3, StackTransfer.after, put, h0, h27, h28]
theorem body_spec {n : ℕ} (M : KS.W07.DenseRatMatrix n) (b : ℕ) (hnum : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).num.natAbs ≤ 2 ^ b) (hden : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).den ≤ 2 ^ b) (x : Fin n → ℚ) (i : Fin n) (p : Fin n × ℚ) (xs : List (Fin n × ℚ)) (out : List Bool) : RunSpec body (boundary M x i (p :: xs) p.1.val out) (boundary M x i xs (p.1.val + 1) ((FixedDot.pairWire (KS.W07.DenseRatMatrix.decode M i p.1, p.2)).reverse ++ out)) (bodyTicks M b i p) := by let s := put (put (boundary M x i xs p.1.val out) 27 (KS.W01.encodeRat p.2)) 0 (KS.W01.encodeRat (KS.W07.DenseRatMatrix.decode M i p.1)) let t := put (put (put s 0 []) 27 []) 25 ((FixedDot.pairWire (KS.W07.DenseRatMatrix.decode M i p.1, p.2)).reverse ++ s 25) have h1 := collect_spec M b hnum hden x i p xs out have h2 := pair_spec s (KS.W07.DenseRatMatrix.decode M i p.1) p.2 rfl rfl rfl rfl rfl have h3 := increment_spec t p.1.val rfl rfl rfl have h := (h1.compose h2).compose h3 convert h using 1 <;> (try rfl) funext j fin_cases j <;> simp [t, s, put, boundary, state]
end KS.W12.RowDot
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186import Mathlibimport OAI.Analysis.MatrixSigning.Machines.FixedDotBoundsimport OAI.Analysis.MatrixSigning.Matrices.RowDotMachine
namespace OAI
section
namespace KS.W12.RowDotopen Matrixopen KS.W01 KS.W01.FixedStack KS.W07open scoped BigOperators
def storedLength {n : ℕ} (M : DenseRatMatrix n) (x : Fin n → ℚ) (i : Fin n) : ℕ := (KS.W08.denseMatrixTape M).length + (vectorTape x).length + (Computability.encodeNat i.val).length + (Computability.encodeNat n).length
theorem payload_le_framed (xs : List (List Bool)) (p : List Bool) (hp : p ∈ xs) : p.length ≤ (xs.flatMap frame).length := by induction xs with | nil => simp at hp | cons q qs ih => simp only [List.mem_cons] at hp simp only [List.flatMap_cons, List.length_append, length_frame] rcases hp with rfl | hp · omega · have h := ih hp; omega
theorem count_le_framed (xs : List (List Bool)) : xs.length ≤ (xs.flatMap frame).length := by induction xs with | nil => simp | cons q qs ih => simp only [List.length_cons, List.flatMap_cons, List.length_append, length_frame]; omega
theorem matrix_entry_length {n : ℕ} (M : DenseRatMatrix n) (i j : Fin n) : ratLength (DenseRatMatrix.decode M i j) ≤ (KS.W08.denseMatrixTape M).length := by apply payload_le_framed have h := List.getElem_mem (l := KS.W08.denseMatrixPayloads M) (n := i.val * n + j.val) (by simpa using KS.W08.matrixEntryIndex_lt i j) simpa only [KS.W08.denseMatrixPayloads_get] using h
theorem vector_entry_length {n : ℕ} (x : Fin n → ℚ) (j : Fin n) : ratLength (x j) ≤ (vectorTape x).length := by apply payload_le_framed simp only [List.mem_ofFn] exact ⟨j, rfl⟩
theorem dimension_le_vector {n : ℕ} (x : Fin n → ℚ) : n ≤ (vectorTape x).length := by simpa [vectorTape] using count_le_framed (List.ofFn (fun j => encodeRat (x j)))
theorem matrix_parts_stored {n : ℕ} (M : DenseRatMatrix n) (x : Fin n → ℚ) (i : Fin n) : (∀ j k, (DenseRatMatrix.decode M j k).num.natAbs ≤ 2 ^ storedLength M x i) ∧ (∀ j k, (DenseRatMatrix.decode M j k).den ≤ 2 ^ storedLength M x i) := by have hlen : ∀ j k, ratLength (DenseRatMatrix.decode M j k) ≤ storedLength M x i := by intro j k have h := matrix_entry_length M j k unfold storedLength omega constructor <;> intro j k · exact (rational_parts_le_two_pow_length _).1.trans (Nat.pow_le_pow_right (by decide) (hlen j k)) · exact (rational_parts_le_two_pow_length _).2.trans (Nat.pow_le_pow_right (by decide) (hlen j k))
theorem encodeNat_length_le_self (k : ℕ) : (Computability.encodeNat k).length ≤ k := by rw [KS.W19.encodeNat_length_eq_size] exact Nat.size_le.mpr Nat.lt_two_pow_self
theorem pair_stream_length {n : ℕ} (M : DenseRatMatrix n) (x : Fin n → ℚ) (i : Fin n) : (FixedDot.inputWire (rowPairs M i (indexedVector x))).length ≤ 5 * (storedLength M x i + 1) ^ 2 := by have hn : n ≤ storedLength M x i := by have h := dimension_le_vector x unfold storedLength omega have hsum : (FixedDot.inputWire (rowPairs M i (indexedVector x))).length ≤ n * (4 * storedLength M x i + 1) := by simp only [rowPairs, indexedVector, List.map_ofFn, FixedDot.inputWire, List.length_flatMap, List.map_ofFn, List.sum_ofFn] calc _ ≤ ∑ _j : Fin n, (4 * storedLength M x i + 1) := by apply Finset.sum_le_sum intro j _ have ha := matrix_entry_length M i j have hq := vector_entry_length x j simp only [Function.comp_def, FixedDot.pairWire_length, FixedDot.pairPayload, List.length_append] unfold ratLength at ha hq unfold storedLength omega _ = _ := by simp calc _ ≤ n * (4 * storedLength M x i + 1) := hsum _ ≤ storedLength M x i * (4 * storedLength M x i + 1) := Nat.mul_le_mul_right _ hn _ ≤ _ := by nlinarith
theorem bodyTicks_stored {n : ℕ} (M : DenseRatMatrix n) (x : Fin n → ℚ) (i j : Fin n) : bodyTicks M (storedLength M x i) i (j, x j) ≤ 2000 * (storedLength M x i + 1) ^ 3 := by let L := storedLength M x i have hn : n ≤ L := by have h := dimension_le_vector x; dsimp [L, storedLength]; omega have hi : i.val ≤ L := i.isLt.le.trans hn have hj : j.val ≤ L := j.isLt.le.trans hn have hni := encodeNat_length_le_self i.val have hnj := encodeNat_length_le_self j.val have hnn := encodeNat_length_le_self n have hnjs := encodeNat_length_le_self (j.val + 1) have ha := matrix_entry_length M i j have hq := vector_entry_length x j have hla : (encodeRat (DenseRatMatrix.decode M i j)).length ≤ L := by dsimp [L, storedLength]; unfold ratLength at ha; omega have hlq : (encodeRat (x j)).length ≤ L := by dsimp [L, storedLength]; unfold ratLength at hq; omega have had := KS.W13.RationalAdd.canonicalAddTicks_le (Computability.encodeNat j.val) [true] have hread : 1024 * (n + 1) ^ 2 * (L + 1) ≤ 1024 * (L + 1) ^ 3 := by calc _ ≤ 1024 * (L + 1) ^ 2 * (L + 1) := by gcongr _ = _ := by ring unfold bodyTicks collectTicks pairTicks incrementTicks simp only [List.length_append, KS.W01.length_frame, List.length_cons, List.length_nil] at * change _ ≤ 2000 * (L + 1) ^ 3 have hl : 60 * L + 60 ≤ 976 * (L + 1) ^ 3 := by nlinarith [Nat.zero_le (L ^ 3)] dsimp only [L] at * omega
theorem loopTicks_stored {n : ℕ} (M : DenseRatMatrix n) (x : Fin n → ℚ) (i : Fin n) : loopTicks M (storedLength M x i) i (indexedVector x) ≤ 3000 * (storedLength M x i + 1) ^ 4 := by let L := storedLength M x i have haux : ∀ xs : List (Fin n × ℚ), (∀ p ∈ xs, p.2 = x p.1) → loopTicks M L i xs ≤ 1 + xs.length * (1 + 2000 * (L + 1) ^ 3) := by intro xs hx induction xs with | nil => simp [loopTicks] | cons p ps ih => have hp := hx p (by simp) have ht := ih (by intro q hq; exact hx q (by simp [hq])) have hb := bodyTicks_stored M x i p.1 rw [← hp] at hb simp only [loopTicks, List.length_cons] dsimp only [L] at * nlinarith have h := haux (indexedVector x) (by intro p hp; simp [indexedVector] at hp; rcases hp with ⟨j, rfl⟩; rfl) have hn : n ≤ L := by have h := dimension_le_vector x; dsimp [L, storedLength]; omega simp only [indexedVector, List.length_ofFn] at h calc _ ≤ 1 + n * (1 + 2000 * (L + 1) ^ 3) := h _ ≤ 1 + L * (1 + 2000 * (L + 1) ^ 3) := by gcongr _ ≤ _ := by nlinarith [Nat.zero_le (L ^ 2), Nat.zero_le (L ^ 3)]
theorem totalTicks_stored {n : ℕ} (M : DenseRatMatrix n) (x : Fin n → ℚ) (i : Fin n) : totalTicks M (storedLength M x i) x i ≤ KS.W29.polynomialFuel 1000000000000 8 (storedLength M x i) := by let L := storedLength M x i let ps := rowPairs M i (indexedVector x) have hloop := loopTicks_stored M x i have hwire := pair_stream_length M x i have hdot := FixedDot.totalTicks_le_polynomial ps have hv : (vectorTape x).length ≤ L := by dsimp [L, storedLength]; omega have hn : (Computability.encodeNat n).length ≤ L := by dsimp [L, storedLength]; omega have hw1 : (FixedDot.inputWire ps).length + 1 ≤ 6 * (L + 1) ^ 2 := by dsimp [ps, L] at * nlinarith have hp : ((FixedDot.inputWire ps).length + 1) ^ 4 ≤ (6 * (L + 1) ^ 2) ^ 4 := by gcongr have hdot' : FixedDot.totalTicks ps ≤ 259200000000 * (L + 1) ^ 8 := by calc _ ≤ 200000000 * ((FixedDot.inputWire ps).length + 1) ^ 4 := hdot _ ≤ 200000000 * (6 * (L + 1) ^ 2) ^ 4 := Nat.mul_le_mul_left _ hp _ = _ := by ring have hgrow : (L + 1) ^ 4 ≤ (L + 1) ^ 8 := Nat.pow_le_pow_right (by omega) (by decide) have hgrow2 : (L + 1) ^ 2 ≤ (L + 1) ^ 8 := Nat.pow_le_pow_right (by omega) (by decide) have hgrow1 : L + 1 ≤ (L + 1) ^ 8 := by simpa only [pow_one] using (Nat.pow_le_pow_right (n := L + 1) (by omega) (show 1 ≤ 8 by decide)) unfold totalTicks prepareTicks finishTicks KS.W29.polynomialFuel change _ ≤ 1000000000000 * (L + 1) ^ 8 dsimp only [L, ps] at * omega
theorem polynomial_spec {n : ℕ} (M : DenseRatMatrix n) (x : Fin n → ℚ) (i : Fin n) : KS.W03.MachineCombinators.RunSpec program (initialStacks M x i) (put (initialStacks M x i) 17 (encodeRat ((DenseRatMatrix.decode M *ᵥ x) i))) (KS.W29.polynomialFuel 1000000000000 8 (storedLength M x i)) := by obtain ⟨hn, hd⟩ := matrix_parts_stored M x i exact (full_spec M (storedLength M x i) hn hd x i).mono (totalTicks_stored M x i)
end KS.W12.RowDot
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.RowDotBody
namespace OAI
section
namespace KS.W12.RowDotopen KS.W01.FixedStack KS.W29.FixedSequential KS.W03.MachineCombinators
def guard (heads : Fin 29 → Fin 3) (_ : Bool) : KS.W29.FixedLoop.GuardInstruction 29 := ⟨if (heads 23).val = 0 then .halt else .call, Vector.ofFn (fun _ => .stay)⟩def loopProgram : Program 29 := KS.W29.FixedLoop.loop body guard
def loopTicks {n : ℕ} (M : KS.W07.DenseRatMatrix n) (b : ℕ) (i : Fin n) : List (Fin n × ℚ) → ℕ | [] => 1 | p :: ps => 1 + bodyTicks M b i p + loopTicks M b i ps
theorem step_empty {n : ℕ} (M : KS.W07.DenseRatMatrix n) (x : Fin n → ℚ) (i : Fin n) (k : ℕ) (out : List Bool) (coin : Bool) : loopProgram.toMachine.step ⟨some loopProgram.initial, boundary M x i [] k out⟩ coin = ⟨none, boundary M x i [] k out⟩ := by change (KS.W29.FixedLoop.loop body guard).toMachine.step ⟨some (KS.W29.FixedLoop.guardState body), boundary M x i [] k out⟩ coin = _ rw [KS.W29.FixedLoop.step_guard] change Config.mk none _ = Config.mk none _ congr 1 funext j fin_cases j <;> rfl
theorem step_cons {n : ℕ} (M : KS.W07.DenseRatMatrix n) (x : Fin n → ℚ) (i : Fin n) (p : Fin n × ℚ) (xs : List (Fin n × ℚ)) (k : ℕ) (out : List Bool) (coin : Bool) : loopProgram.toMachine.step ⟨some loopProgram.initial, boundary M x i (p :: xs) k out⟩ coin = KS.W29.FixedLoop.liftBody body ⟨some body.initial, boundary M x i (p :: xs) k out⟩ := by change (KS.W29.FixedLoop.loop body guard).toMachine.step ⟨some (KS.W29.FixedLoop.guardState body), boundary M x i (p :: xs) k out⟩ coin = _ rw [KS.W29.FixedLoop.step_guard] have hhead : KS.W29.topCode ((boundary M x i (p :: xs) k out) 23) ≠ 0 := by change KS.W29.topCode (KS.W01.frame (KS.W01.encodeRat p.2) ++ tailTape xs) ≠ 0 cases hp : KS.W01.encodeRat p.2 with | nil => simp [KS.W01.frame, KS.W29.topCode] | cons b bs => simp [KS.W01.frame, KS.W29.topCode] simp only [guard, observedHeads, hhead, ↓reduceIte] change Config.mk (some (KS.W29.FixedLoop.bodyState body body.initial)) _ = Config.mk (some (KS.W29.FixedLoop.bodyState body body.initial)) _ congr 1 funext j simp [KS.W29.FixedLoop.guardInstruction, Instruction.action, KS.W29.StackAction.apply]
theorem run_loop {n : ℕ} (M : KS.W07.DenseRatMatrix n) (b : ℕ) (hnum : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).num.natAbs ≤ 2 ^ b) (hden : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).den ≤ 2 ^ b) (x : Fin n → ℚ) (i : Fin n) (xs : List (Fin n × ℚ)) (k : ℕ) (hc : Consecutive k xs) (out bits : List Bool) (hlen : loopTicks M b i xs ≤ bits.length) : loopProgram.toMachine.run ⟨some loopProgram.initial, boundary M x i xs k out⟩ bits = ⟨none, boundary M x i [] (k + xs.length) ((FixedDot.inputWire (rowPairs M i xs)).reverse ++ out)⟩ := by induction xs generalizing k out bits with | nil => cases bits with | nil => simp [loopTicks] at hlen | cons coin rest => rw [Machine.run, step_empty, Machine.run_halted _ _ rfl] simp | cons p xs ih => obtain ⟨hk, htail⟩ := (consecutive_cons k p xs).mp hc subst k cases bits with | nil => simp [loopTicks] at hlen | cons coin rest => have ht : bodyTicks M b i p + loopTicks M b i xs ≤ rest.length := by simp only [loopTicks, List.length_cons] at hlen omega obtain ⟨remaining, hremaining, hreturn⟩ := (body_spec M b hnum hden x i p xs out).loop_body_then guard rest (by omega) rw [Machine.run, step_cons] change loopProgram.toMachine.run (KS.W29.FixedLoop.liftBody body ⟨some body.initial, boundary M x i (p :: xs) p.1.val out⟩) rest = loopProgram.toMachine.run ⟨some loopProgram.initial, boundary M x i xs (p.1.val + 1) ((FixedDot.pairWire (KS.W07.DenseRatMatrix.decode M i p.1, p.2)).reverse ++ out)⟩ remaining at hreturn rw [hreturn] have hn : loopTicks M b i xs ≤ remaining.length := by omega simpa [loopProgram, KS.W29.FixedLoop.loop_initial, FixedDot.inputWire_cons, List.reverse_append, List.append_assoc, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using ih (p.1.val + 1) htail ((FixedDot.pairWire (KS.W07.DenseRatMatrix.decode M i p.1, p.2)).reverse ++ out) remaining hn
theorem loop_spec {n : ℕ} (M : KS.W07.DenseRatMatrix n) (b : ℕ) (hnum : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).num.natAbs ≤ 2 ^ b) (hden : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).den ≤ 2 ^ b) (x : Fin n → ℚ) (i : Fin n) : RunSpec loopProgram (boundary M x i (indexedVector x) 0 []) (boundary M x i [] n ((FixedDot.inputWire (rowPairs M i (indexedVector x))).reverse)) (loopTicks M b i (indexedVector x)) := by intro bits hbits simpa [indexedVector] using run_loop M b hnum hden x i (indexedVector x) 0 (consecutive_indexedVector x) [] bits hbits.ge
end KS.W12.RowDot
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475import Mathlibimport OAI.Analysis.MatrixSigning.Machines.MachineTransportimport OAI.Analysis.MatrixSigning.Machines.StackTransferimport OAI.Analysis.MatrixSigning.Arithmetic.RationalAddPrimitivesimport OAI.Analysis.MatrixSigning.Matrices.RowDotRegisters
namespace OAI
namespace KS.W12.RowDotopen KS.W01.FixedStack KS.W29.FixedSequential KS.W03.MachineCombinators
def oneDispatch (_ : Fin 1) (_heads : Fin 29 → Fin 3) (_coin : Bool) : Instruction 29 1 := ⟨none, Vector.ofFn (fun j => if j = 7 then .push true else .stay)⟩def oneProgram : Program 29 := ofMachine (compile 0 7 7 oneDispatch)
theorem one_spec (s : Fin 29 → List Bool) : RunSpec oneProgram s (put s 7 (true :: s 7)) 1 := by intro bits hbits cases bits with | nil => simp at hbits | cons coin rest => have hr : rest = [] := by simpa using hbits subst rest refine (KS.W19.MachineTransport.run_ofMachine (compile (0 : Fin 1) (7 : Fin 29) 7 oneDispatch) (⟨some (0 : Fin 1), s⟩ : Config 29 1) [coin]).trans ?_ simp only [Machine.run] refine (step_compile (0 : Fin 1) (7 : Fin 29) 7 oneDispatch (0 : Fin 1) s coin).trans ?_ change Config.mk none _ = Config.mk none _ congr 1 funext j by_cases hj : j = 7 · subst j simp [oneDispatch, put, Instruction.action, KS.W29.StackAction.apply] · simp [oneDispatch, put, Instruction.action, KS.W29.StackAction.apply, hj]
def incrementPorts : Fin 3 ↪ Fin 29 := ⟨![24, 7, 26], by decide⟩def incrementAdd : Program 29 := KS.W13.RationalAdd.canonicalAddProgram incrementPorts
def incrementProgram : Program 29 := compose (compose oneProgram incrementAdd) (StackTransfer.program 7 24 26)
def incrementTicks (k : ℕ) : ℕ := 1 + KS.W13.RationalAdd.canonicalAddTicks (Computability.encodeNat k) [true] + (2 * (Computability.encodeNat (k + 1)).length + 2)
theorem increment_spec (s : Fin 29 → List Bool) (k : ℕ) (hk : s 24 = Computability.encodeNat k) (h7 : s 7 = []) (h26 : s 26 = []) : RunSpec incrementProgram s (put s 24 (Computability.encodeNat (k + 1))) (incrementTicks k) := by let t := put s 7 [true] let u := put (put s 24 []) 7 (Computability.encodeNat (k + 1)) have h1 : RunSpec oneProgram s t 1 := by simpa [t, h7] using one_spec s have hv : KS.W13.RationalAdd.addResult (Computability.encodeNat k) [true] = Computability.encodeNat (k + 1) := by simp [KS.W13.RationalAdd.addResult, KS.W19.bitsValue_encodeNat, KS.W19.bitsValue, KS.W19.digit] have h2 : RunSpec incrementAdd t u (KS.W13.RationalAdd.canonicalAddTicks (Computability.encodeNat k) [true]) := by convert KS.W13.RationalAdd.canonicalAdd_spec incrementPorts s (Computability.encodeNat k) [true] using 1 <;> (try rfl) <;> funext j <;> fin_cases j <;> simp [t, u, put, KS.W19.UnsignedPairSerializer.registers, incrementPorts, hk, h26, hv] have h3 := StackTransfer.spec (7 : Fin 29) 24 26 (by decide) (by decide) (by decide) u (by simp [u, put, h26]) have he : StackTransfer.after 7 24 u = put s 24 (Computability.encodeNat (k + 1)) := by funext j fin_cases j <;> simp [StackTransfer.after, put, u, h7] have h := (h1.compose h2).compose h3 simpa [incrementProgram, incrementTicks, he, u, put] using h
end KS.W12.RowDot
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.RowDotControlimport OAI.Analysis.MatrixSigning.Machines.FixedDotMachine
namespace OAI
namespace KS.W12.RowDotopen Matrixopen KS.W01.FixedStack KS.W29.FixedSequential KS.W03.MachineCombinators
def initialStacks {n : ℕ} (M : KS.W07.DenseRatMatrix n) (x : Fin n → ℚ) (i : Fin n) : Fin 29 → List Bool := state (KS.W08.denseMatrixTape M) (vectorTape x) (Computability.encodeNat i.val) (Computability.encodeNat n) [] [] []
def copyVector : Program 29 := copyProgram 20 23 (by decide) (by decide) (by decide)def prepareProgram : Program 29 := compose copyVector loopProgram
def prepareTicks {n : ℕ} (M : KS.W07.DenseRatMatrix n) (b : ℕ) (x : Fin n → ℚ) (i : Fin n) : ℕ := (2 * (vectorTape x).length + 2) + loopTicks M b i (indexedVector x)
theorem prepare_spec {n : ℕ} (M : KS.W07.DenseRatMatrix n) (b : ℕ) (hnum : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).num.natAbs ≤ 2 ^ b) (hden : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).den ≤ 2 ^ b) (x : Fin n → ℚ) (i : Fin n) : RunSpec prepareProgram (initialStacks M x i) (boundary M x i [] n ((FixedDot.inputWire (rowPairs M i (indexedVector x))).reverse)) (prepareTicks M b x i) := by have hc : RunSpec copyVector (initialStacks M x i) (boundary M x i (indexedVector x) 0 []) (2 * (vectorTape x).length + 2) := by convert copy_spec (20 : Fin 29) 23 (by decide) (by decide) (by decide) (initialStacks M x i) rfl rfl using 1 <;> (try rfl) funext j fin_cases j <;> simp [initialStacks, boundary, state, put, Computability.encodeNat] rfl exact hc.compose (loop_spec M b hnum hden x i)
def clearCounter : Program 29 := KS.W04.BinaryStackMoves.clearProgram 24def restoreWire : Program 29 := KS.W04.BinaryStackMoves.moveProgram 25 16def dotPorts : Fin 19 ↪ Fin 29 := Fin.castLEEmb (by decide)def dotProgram : Program 29 := KS.W29.FixedSequential.liftPorts FixedDot.program dotPorts
def finishProgram : Program 29 := compose (compose clearCounter restoreWire) dotProgram
def finishTicks (n : ℕ) (ps : List (ℚ × ℚ)) : ℕ := ((Computability.encodeNat n).length + 1) + ((FixedDot.inputWire ps).length + 1) + FixedDot.totalTicks ps
theorem finish_spec {n : ℕ} (M : KS.W07.DenseRatMatrix n) (x : Fin n → ℚ) (i : Fin n) (ps : List (ℚ × ℚ)) : RunSpec finishProgram (boundary M x i [] n (FixedDot.inputWire ps).reverse) (put (initialStacks M x i) 17 (KS.W01.encodeRat (FixedDot.dotValue ps))) (finishTicks n ps) := by let s0 := boundary M x i [] n (FixedDot.inputWire ps).reverse let s1 := KS.W15.RationalMultiply.clearAfter 24 s0 let s2 := KS.W15.RationalMultiply.moveAfter 25 16 s1 have h1 := KS.W15.RationalMultiply.clear_spec (24 : Fin 29) s0 have h2 := KS.W15.RationalMultiply.move_spec (25 : Fin 29) 16 (by decide) s1 have h3 : RunSpec dotProgram s2 (put (initialStacks M x i) 17 (KS.W01.encodeRat (FixedDot.dotValue ps))) (FixedDot.totalTicks ps) := by apply KS.W01.FixedPortRunSpec.lift_runSpec _ _ _ _ _ _ _ (FixedDot.full_spec ps) · intro j fin_cases j <;> simp [s0, s1, s2, boundary, state, dotPorts, FixedDot.initialStacks, FixedDot.registers, KS.W15.RationalMultiply.clearAfter, KS.W15.RationalMultiply.moveAfter] · intro j fin_cases j <;> simp [put, initialStacks, state, dotPorts, FixedDot.boundary, FixedDot.registers] · intro j hj have h16 : j ≠ 16 := hj 16 have h17 : j ≠ 17 := hj 17 fin_cases j <;> simp_all [s0, s1, s2, put, initialStacks, boundary, state, KS.W15.RationalMultiply.clearAfter, KS.W15.RationalMultiply.moveAfter] have h := (h1.compose h2).compose h3 simp [finishProgram, finishTicks, s0, s1, boundary, state, KS.W15.RationalMultiply.clearAfter] at h ⊢ exact h
def program : Program 29 := compose prepareProgram finishProgram
def totalTicks {n : ℕ} (M : KS.W07.DenseRatMatrix n) (b : ℕ) (x : Fin n → ℚ) (i : Fin n) : ℕ := prepareTicks M b x i + finishTicks n (rowPairs M i (indexedVector x))
theorem full_spec {n : ℕ} (M : KS.W07.DenseRatMatrix n) (b : ℕ) (hnum : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).num.natAbs ≤ 2 ^ b) (hden : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).den ≤ 2 ^ b) (x : Fin n → ℚ) (i : Fin n) : RunSpec program (initialStacks M x i) (put (initialStacks M x i) 17 (KS.W01.encodeRat ((KS.W07.DenseRatMatrix.decode M *ᵥ x) i))) (totalTicks M b x i) := by have h := (prepare_spec M b hnum hden x i).compose (finish_spec M x i (rowPairs M i (indexedVector x))) simp only [rowPairs_dotValue] at h exact h
theorem transient_payload {n : ℕ} (M : KS.W07.DenseRatMatrix n) (x : Fin n → ℚ) (i : Fin n) (bits : List Bool) (j : Fin 29) : ((program.toMachine.run ⟨some program.initial, initialStacks M x i⟩ bits).«stacks» j).length ≤ (KS.W08.denseMatrixTape M).length + (vectorTape x).length + (Computability.encodeNat i.val).length + (Computability.encodeNat n).length + bits.length := by have h := program.toMachine.run_stack_length_le (⟨some program.initial, initialStacks M x i⟩ : Config 29 program.states) bits j have hs : ((initialStacks M x i) j).length ≤ (KS.W08.denseMatrixTape M).length + (vectorTape x).length + (Computability.encodeNat i.val).length + (Computability.encodeNat n).length := by fin_cases j <;> simp [initialStacks, state] <;> omega exact h.trans (Nat.add_le_add_right hs _)
end KS.W12.RowDot
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374import Mathlibimport OAI.Analysis.MatrixSigning.Machines.FixedDotModelimport OAI.Analysis.MatrixSigning.Matrices.DenseMatrixSerialization
namespace OAI
section
namespace KS.W12.RowDotopen KS.W07 Matrixopen scoped BigOperators
def vectorTape {n : ℕ} (x : Fin n → ℚ) : List Bool := (List.ofFn (fun j => KS.W01.encodeRat (x j))).flatMap KS.W01.frame
def valueTape (xs : List ℚ) : List Bool := xs.flatMap (fun q => KS.W01.frame (KS.W01.encodeRat q))
def indexedVector {n : ℕ} (x : Fin n → ℚ) : List (Fin n × ℚ) := List.ofFn (fun j => (j, x j))
def tailTape {n : ℕ} (xs : List (Fin n × ℚ)) : List Bool := valueTape (xs.map Prod.snd)
def rowPairs {n : ℕ} (M : DenseRatMatrix n) (i : Fin n) (xs : List (Fin n × ℚ)) : List (ℚ × ℚ) := xs.map (fun p => (DenseRatMatrix.decode M i p.1, p.2))
def Consecutive {n : ℕ} (k : ℕ) (xs : List (Fin n × ℚ)) : Prop := xs.map (fun p => p.1.val) = List.range' k xs.length
theorem consecutive_cons {n : ℕ} (k : ℕ) (p : Fin n × ℚ) (xs : List (Fin n × ℚ)) : Consecutive k (p :: xs) ↔ p.1.val = k ∧ Consecutive (k + 1) xs := by simp [Consecutive, List.range'_succ]
theorem consecutive_indexedVector {n : ℕ} (x : Fin n → ℚ) : Consecutive 0 (indexedVector x) := by unfold Consecutive indexedVector apply List.ext_getElem · simp · intro j hj hk simp
@[simp] theorem tailTape_indexedVector {n : ℕ} (x : Fin n → ℚ) : tailTape (indexedVector x) = vectorTape x := by simp only [tailTape, indexedVector, valueTape, vectorTape, List.map_ofFn] rw [show (List.ofFn (fun j => KS.W01.encodeRat (x j))) = (List.ofFn x).map KS.W01.encodeRat by simp [Function.comp_def]] rw [List.flatMap_map] rfl
@[simp] theorem tailTape_nil {n : ℕ} : tailTape ([] : List (Fin n × ℚ)) = [] := rfl@[simp] theorem tailTape_cons {n : ℕ} (p : Fin n × ℚ) (xs : List (Fin n × ℚ)) : tailTape (p :: xs) = KS.W01.frame (KS.W01.encodeRat p.2) ++ tailTape xs := rfl
@[simp] theorem rowPairs_nil {n : ℕ} (M : DenseRatMatrix n) (i : Fin n) : rowPairs M i [] = [] := rfl@[simp] theorem rowPairs_cons {n : ℕ} (M : DenseRatMatrix n) (i : Fin n) (p : Fin n × ℚ) (xs : List (Fin n × ℚ)) : rowPairs M i (p :: xs) = (DenseRatMatrix.decode M i p.1, p.2) :: rowPairs M i xs := rfl
theorem rowPairs_dotValue {n : ℕ} (M : DenseRatMatrix n) (i : Fin n) (x : Fin n → ℚ) : FixedDot.dotValue (rowPairs M i (indexedVector x)) = (DenseRatMatrix.decode M *ᵥ x) i := by simp [rowPairs, indexedVector, FixedDot.dotValue, Matrix.mulVec, dotProduct, List.sum_ofFn]
def state (matrix vector row dim remaining counter reversed : List Bool) : Fin 29 → List Bool := fun j => if j = 19 then matrix else if j = 20 then vector else if j = 21 then row else if j = 22 then dim else if j = 23 then remaining else if j = 24 then counter else if j = 25 then reversed else []
def boundary {n : ℕ} (M : DenseRatMatrix n) (x : Fin n → ℚ) (i : Fin n) (remaining : List (Fin n × ℚ)) (k : ℕ) (out : List Bool) : Fin 29 → List Bool := state (KS.W08.denseMatrixTape M) (vectorTape x) (Computability.encodeNat i.val) (Computability.encodeNat n) (tailTape remaining) (Computability.encodeNat k) out
end KS.W12.RowDot
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105import Mathlibimport OAI.Analysis.MatrixSigning.Machines.MachineTransportimport OAI.Analysis.MatrixSigning.Matrices.MatrixReadProgramimport OAI.Analysis.MatrixSigning.Matrices.RowDotRegisters
namespace OAI
namespace KS.W12.RowDotopen KS.W01.FixedStack KS.W29.FixedSequential KS.W03.MachineCombinators
def copyPorts (source target : Fin 29) (hst : source ≠ target) (hs : source ≠ 26) (ht : target ≠ 26) : Fin 3 ↪ Fin 29 := ⟨![source, target, 26], by intro i j h fin_cases i <;> fin_cases j <;> simp_all⟩
def copyProgram (source target : Fin 29) (hst : source ≠ target) (hs : source ≠ 26) (ht : target ≠ 26) : Program 29 := KS.W01.FixedCopy.program (copyPorts source target hst hs ht)
theorem copy_spec (source target : Fin 29) (hst : source ≠ target) (hs : source ≠ 26) (ht : target ≠ 26) (s : Fin 29 → List Bool) (hdst : s target = []) (hscratch : s 26 = []) : RunSpec (copyProgram source target hst hs ht) s (put s target (s source)) (2 * (s source).length + 2) := by intro bits hbits refine (KS.W19.MachineTransport.run_ofMachine (KS.W01.FixedCopy.machine (copyPorts source target hst hs ht)) _ bits).trans ?_ exact KS.W01.FixedCopy.run_copy_restore (copyPorts source target hst hs ht) s (s source) bits rfl hdst hscratch hbits
def readPorts : Fin 8 ↪ Fin 29 := ⟨![0, 1, 2, 3, 4, 5, 6, 19], by decide⟩def readProgram : Program 29 := KS.W29.FixedSequential.liftPorts KS.W08.MatrixRead.program readPorts
def readBefore (s : Fin 29 → List Bool) (col row dim : List Bool) : Fin 29 → List Bool := put (put (put s 0 col) 1 row) 2 dim
theorem read_spec {n : ℕ} (M : KS.W07.DenseRatMatrix n) (b : ℕ) (hnum : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).num.natAbs ≤ 2 ^ b) (hden : ∀ i j, (KS.W07.DenseRatMatrix.decode M i j).den ≤ 2 ^ b) (i j : Fin n) (s : Fin 29 → List Bool) (hsource : s 19 = KS.W08.denseMatrixTape M) (hclear : ∀ r : Fin 7, s ⟨r.val, by omega⟩ = []) : RunSpec readProgram (readBefore s (Computability.encodeNat j.val) (Computability.encodeNat i.val) (Computability.encodeNat n)) (put s 0 (KS.W01.encodeRat (KS.W07.DenseRatMatrix.decode M i j))) (1024 * (n + 1) ^ 2 * (b + 1)) := by have hsmall : RunSpec KS.W08.MatrixRead.program (KS.W08.MatrixRead.workspace (KS.W08.denseMatrixTape M) (Computability.encodeNat j.val) (Computability.encodeNat i.val) (Computability.encodeNat n) []) (KS.W08.MatrixRead.workspace (KS.W08.denseMatrixTape M) (KS.W01.encodeRat (KS.W07.DenseRatMatrix.decode M i j)) [] [] []) (1024 * (n + 1) ^ 2 * (b + 1)) := by intro bits hbits exact KS.W08.MatrixRead.run_matrix_read M b hnum hden i j bits hbits.ge have hclearPhysical : ∀ r : Fin 29, r.val < 7 → s r = [] := by intro r hr exact hclear ⟨r.val, hr⟩ apply KS.W01.FixedPortRunSpec.lift_runSpec _ _ _ _ _ _ _ hsmall · intro r fin_cases r <;> simp [readBefore, put, readPorts, KS.W08.MatrixRead.workspace, hsource] all_goals exact hclearPhysical _ (by decide) · intro r fin_cases r <;> simp [put, readPorts, KS.W08.MatrixRead.workspace, hsource] all_goals exact hclearPhysical _ (by decide) · intro r hr have h0 : r ≠ 0 := hr 0 have h1 : r ≠ 1 := hr 1 have h2 : r ≠ 2 := hr 2 simp [put, readBefore, h0, h1, h2]
def decodePorts : Fin 3 ↪ Fin 29 := ⟨![23, 27, 26], by decide⟩def decodeProgram : Program 29 := KS.W11.FrameWireCodec.unframeProgram decodePorts
theorem decode_spec (s : Fin 29 → List Bool) (payload tail : List Bool) (hs : s 23 = KS.W01.frame payload ++ tail) (hq : s 27 = []) (ht : s 26 = []) : RunSpec decodeProgram s (put (put s 23 tail) 27 payload) (3 * payload.length + 2) := by convert KS.W11.FrameWireCodec.unframe_spec decodePorts s payload tail using 1 <;> (try rfl) <;> funext j <;> fin_cases j <;> simp [put, KS.W28.FixedPositiveSerializer.registers, decodePorts, hs, hq, ht]
def framePorts : Fin 3 ↪ Fin 29 := ⟨![4, 28, 26], by decide⟩def frameProgram : Program 29 := KS.W11.FrameWireCodec.frameProgram framePorts
theorem frame_spec (s : Fin 29 → List Bool) (h4 : s 4 = []) (ht : s 26 = []) : RunSpec frameProgram s (put s 28 (KS.W01.frame (s 28))) (4 * (s 28).length + 3) := by convert KS.W11.FrameWireCodec.frame_spec framePorts s (s 28) using 1 <;> (try rfl) <;> funext j <;> fin_cases j <;> simp [put, KS.W28.FixedPositiveSerializer.registers, framePorts, h4, ht]
def appendProgram : Program 29 := KS.W04.BinaryStackMoves.moveProgram 28 25
theorem append_spec (s : Fin 29 → List Bool) : RunSpec appendProgram s (put (put s 28 []) 25 ((s 28).reverse ++ s 25)) ((s 28).length + 1) := by convert KS.W15.RationalMultiply.move_spec (28 : Fin 29) 25 (by decide) s using 1 <;> (try rfl) funext j fin_cases j <;> simp [put, KS.W15.RationalMultiply.moveAfter]
end KS.W12.RowDot
end OAI123456789101112131415import Mathlib
namespace OAI
section
namespace KS.W12.RowDot
abbrev put (s : Fin 29 → List Bool) (j : Fin 29) (v : List Bool) := Function.update s j v
end KS.W12.RowDot
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.InvH
namespace OAI
noncomputable section
open Matrix
namespace CurrentKS.Hermitian
section L2Operator
open Matrix Setopen scoped BigOperators ComplexOrder MatrixOrder Matrix.Norms.L2Operator
variable {d : ℕ}
lemma isOpen_pd [NeZero d] : IsOpen (pd d) := by let : CStarAlgebra (Mat d) := {} have he : pd d = interior (psdCone d : Set (H d)) ∩ {A : H d | IsUnit (A : Mat d)} := by ext A constructor · intro hA exact ⟨posDef_mem_interior A hA, hA.isUnit⟩ · rintro ⟨hA, hu⟩ exact (interior_subset hA).posDef_iff_isUnit.mpr hu rw [he] exact isOpen_interior.inter (Units.isOpen.preimage continuous_subtype_val)
def sandwich (A U : H d) : H d := ⟨(A : Mat d) * (U : Mat d) * (A : Mat d), by have hh := Matrix.isHermitian_mul_mul_conjTranspose (A : Mat d) U.property rw [A.property.eq] at hh exact hh⟩
@[simp] lemma sandwich_val (A U : H d) : (sandwich A U : Mat d) = (A : Mat d) * (U : Mat d) * (A : Mat d) := rfl
lemma sandwich_psd (A U : H d) (hU : U ∈ psdCone d) : sandwich A U ∈ psdCone d := by have hh := hU.mul_mul_conjTranspose_same (A : Mat d) rw [A.property.eq] at hh exact hh
def matrixTraceCLM : Mat d →L[ℝ] ℝ := Complex.reCLM.comp (Matrix.traceLinearMap (Fin d) ℝ ℂ).toContinuousLinearMap
@[simp] lemma matrixTraceCLM_apply (A : Mat d) : matrixTraceCLM A = A.trace.re := rfl
lemma hasDerivAt_matrix_inverse (A U : H d) (hA : A ∈ pd d) : HasDerivAt (fun r : ℝ => ((A : Mat d) + r • (U : Mat d))⁻¹) (-((A : Mat d)⁻¹ * (U : Mat d) * (A : Mat d)⁻¹)) 0 := by obtain ⟨a, ha⟩ := hA.isUnit have hcurve : HasDerivAt (fun r : ℝ => (A : Mat d) + r • (U : Mat d)) (U : Mat d) 0 := by have hh := (hasDerivAt_const (0 : ℝ) (A : Mat d)).add ((hasDerivAt_id' (0 : ℝ)).smul_const (U : Mat d)) simp only [zero_add, one_smul] at hh exact hh have hInv := (hasFDerivAt_ringInverse (𝕜 := ℝ) a) rw [ha] at hInv have hz : (A : Mat d) = (fun r : ℝ => (A : Mat d) + r • (U : Mat d)) 0 := by ext i j simp [Matrix.add_apply] have hd := hInv.comp_hasDerivAt_of_eq (0 : ℝ) hcurve hz have hi : (↑a⁻¹ : Mat d) = (A : Mat d)⁻¹ := by rw [Matrix.coe_units_inv, ha] convert hd using 1 <;> try rfl · funext r exact Matrix.nonsing_inv_eq_ringInverse _ · simp only [_root_.neg_apply, ContinuousLinearMap.mulLeftRight_apply, hi]
end L2Operator
section Frobenius
open Matrix Setopen scoped BigOperators ComplexOrder MatrixOrder Matrix.Norms.Frobenius
variable {d : ℕ}
lemma inner_sandwich (A U P : H d) : inner ℝ P (sandwich A U) = inner ℝ (sandwich A P) U := by rw [inner_eq_trace, inner_eq_trace] change ((P : Mat d) * ((A : Mat d) * (U : Mat d) * (A : Mat d))).trace.re = ((A : Mat d) * (P : Mat d) * (A : Mat d) * (U : Mat d)).trace.re rw [← mul_assoc, ← mul_assoc, Matrix.trace_mul_comm ((P : Mat d) * (A : Mat d) * (U : Mat d))] simp only [mul_assoc]
lemma hasDerivAt_trace_inverse (A U P : H d) (hA : A ∈ pd d) : HasDerivAt (fun r : ℝ => inner ℝ P (invH (A + r • U))) (-inner ℝ (sandwich (invH A) P) U) 0 := by have hi := hasDerivAt_matrix_inverse A U hA have hm := (hasDerivAt_const (0 : ℝ) (P : Mat d)).mul hi have ht := (matrixTraceCLM (d := d)).hasFDerivAt.comp_hasDerivAt (0 : ℝ) hm have hfun : (fun r : ℝ => (matrixTraceCLM (d := d)) ((P : Mat d) * ((A : Mat d) + r • (U : Mat d))⁻¹)) = (fun r : ℝ => inner ℝ P (invH (A + r • U))) := by funext r rw [inner_eq_trace] rfl change HasDerivAt (fun r : ℝ => (matrixTraceCLM (d := d)) ((P : Mat d) * ((A : Mat d) + r • (U : Mat d))⁻¹)) _ (0 : ℝ) at ht rw [hfun] at ht simp only [zero_mul, zero_add, mul_neg] at ht convert ht using 1 rw [← inner_sandwich, inner_eq_trace] change -((P : Mat d) * ((A : Mat d)⁻¹ * (U : Mat d) * (A : Mat d)⁻¹)).trace.re = (-((P : Mat d) * ((A : Mat d)⁻¹ * (U : Mat d) * (A : Mat d)⁻¹))).trace.re simp only [Matrix.trace_neg, Complex.neg_re]
end Frobenius
end CurrentKS.Hermitian
end
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.PosLower
namespace OAI
open Matrix
namespace CurrentKS.Hermitiannoncomputable sectionopen Matrix Setopen scoped BigOperators ComplexOrder MatrixOrder Matrix.Norms.Frobenius
variable {d : ℕ}
lemma sandwich_zero (A : H d) : sandwich A 0 = 0 := by apply Subtype.ext simp [sandwich]
lemma sandwich_eq_zero_iff [NeZero d] (U B : H d) (hB : B ∈ pd d) : sandwich U B = 0 ↔ U = 0 := by constructor · intro he have hz : inner ℝ B (sandwich U Hermitian.one) = 0 := by rw [real_inner_comm, ← inner_sandwich, he, inner_zero_right] have hs := eq_zero_of_inner_pd hB (sandwich_psd U _ one_mem_psdCone) hz apply (inner_self_eq_zero (𝕜 := ℝ)).mp rw [inner_eq_trace] have hv : (U : Mat d) * (U : Mat d) = 0 := by have hh := congrArg Subtype.val hs simpa only [sandwich_val, one_val, mul_one, ZeroMemClass.coe_zero] using hh rw [hv] simp · rintro rfl apply Subtype.ext simp [sandwich]
lemma inverse_remainder (X Z : H d) (hX : X ∈ pd d) (hZ : Z ∈ pd d) : invH Z - invH X + sandwich (invH X) (Z-X) = sandwich (invH X) (sandwich (Z-X) (invH Z)) := by have hx := (Matrix.isUnit_iff_isUnit_det (X : Mat d)).mp hX.isUnit have hz := (Matrix.isUnit_iff_isUnit_det (Z : Mat d)).mp hZ.isUnit apply Subtype.ext change (Z : Mat d)⁻¹ - (X : Mat d)⁻¹ + (X : Mat d)⁻¹ * ((Z : Mat d)-(X : Mat d)) * (X : Mat d)⁻¹ = (X : Mat d)⁻¹ * (((Z : Mat d)-(X : Mat d)) * (Z : Mat d)⁻¹ * ((Z : Mat d)-(X : Mat d))) * (X : Mat d)⁻¹ symm calc _ = ((X : Mat d)⁻¹ - (Z : Mat d)⁻¹) * ((Z : Mat d)-(X : Mat d)) * (X : Mat d)⁻¹ := by rw [Matrix.inv_sub_inv (show IsUnit (X : Mat d) ↔ IsUnit (Z : Mat d) from ⟨fun _ => hZ.isUnit, fun _ => hX.isUnit⟩)] simp only [mul_assoc] _ = _ := by simp only [sub_mul, mul_sub, mul_assoc, Matrix.mul_nonsing_inv _ hx, Matrix.nonsing_inv_mul_cancel_left _ _ hz, mul_one] abel
lemma inverse_trace_gap (P X Z : H d) (hX : X ∈ pd d) (hZ : Z ∈ pd d) : (inner ℝ P (invH Z) + inner ℝ (sandwich (invH X) P) Z) - (inner ℝ P (invH X) + inner ℝ (sandwich (invH X) P) X) = inner ℝ P (sandwich (invH X) (sandwich (Z-X) (invH Z))) := by rw [← inverse_remainder X Z hX hZ, inner_add_right, inner_sub_right, inner_sandwich, inner_sub_right] ring
lemma inverse_trace_gap_nonneg (P X Z : H d) (hP : P ∈ psdCone d) (hX : X ∈ pd d) (hZ : Z ∈ pd d) : inner ℝ P (invH X) + inner ℝ (sandwich (invH X) P) X ≤ inner ℝ P (invH Z) + inner ℝ (sandwich (invH X) P) Z := by apply sub_nonneg.mp rw [inverse_trace_gap P X Z hX hZ] exact inner_nonneg_of_psd P _ hP (sandwich_psd _ _ (sandwich_psd _ _ hZ.inv.posSemidef))
lemma inverse_trace_gap_zero [NeZero d] (P X Z : H d) (hP : P ∈ pd d) (hX : X ∈ pd d) (hZ : Z ∈ pd d) (he : inner ℝ P (invH X) + inner ℝ (sandwich (invH X) P) X = inner ℝ P (invH Z) + inner ℝ (sandwich (invH X) P) Z) : X = Z := by have hz : inner ℝ P (sandwich (invH X) (sandwich (Z-X) (invH Z))) = 0 := by rw [← inverse_trace_gap P X Z hX hZ, he, sub_self] have hr := eq_zero_of_inner_pd hP (sandwich_psd _ _ (sandwich_psd _ _ hZ.inv.posSemidef)) hz have hc := congrArg (sandwich X) hr rw [sandwich_inverse_cancel X _ hX, sandwich_zero] at hc have hu := (sandwich_eq_zero_iff (Z-X) (invH Z) hZ.inv).mp hc exact (sub_eq_zero.mp hu).symm
endend CurrentKS.Hermitian
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.InnerRight
namespace OAI
open Matrix
namespace CurrentKS.Hermitiannoncomputable sectionopen Matrix Setopen scoped BigOperators ComplexOrder MatrixOrder Matrix.Norms.Frobenius
variable {d : ℕ}
private local instance : NormedAddCommGroup (H d) := inferInstanceprivate local instance : NormedSpace ℝ (H d) := inferInstanceprivate local instance : TopologicalSpace (H d) := (inferInstance : NormedAddCommGroup (H d)).toUniformSpace.toTopologicalSpace
lemma sandwich_sub (A U V : H d) : sandwich A (U-V) = sandwich A U - sandwich A V := by apply Subtype.ext change (A : Mat d) * ((U : Mat d)-(V : Mat d)) * (A : Mat d) = _ simp only [mul_sub, sub_mul] rfl
lemma invH_involutive (X : H d) (hX : X ∈ pd d) : invH (invH X) = X := by apply Subtype.ext exact Matrix.nonsing_inv_nonsing_inv _ ((Matrix.isUnit_iff_isUnit_det _).mp hX.isUnit)
lemma sandwich_inverse_cancel' (X P : H d) (hX : X ∈ pd d) : sandwich (invH X) (sandwich X P) = P := by simpa only [invH_involutive X hX] using sandwich_inverse_cancel (invH X) P hX.inv
def sandwichCLM (A : H d) : H d →L[ℝ] H d := ({ toFun := sandwich A map_add' := sandwich_add A map_smul' := fun r U => sandwich_smul r A U } : H d →ₗ[ℝ] H d).toContinuousLinearMap
@[simp] lemma sandwichCLM_apply (A U : H d) : sandwichCLM A U = sandwich A U := rfl
lemma psd_pointed (A : H d) (hA : A ∈ psdCone d) (hnA : -A ∈ psdCone d) : A = 0 := by have h0 := (mem_psd_iff_nonneg A).mp hA have h1 := (mem_psd_iff_nonneg (-A)).mp hnA exact le_antisymm (neg_nonneg.mp h1) h0
endend CurrentKS.Hermitian
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.Sandwichimport OAI.Analysis.MatrixSigning.Matrices.RankFactor
namespace OAI
noncomputable section
open Matrix
namespace CurrentKS.Hermitianopen Matrix Setopen scoped BigOperators ComplexOrder MatrixOrder Matrix.Norms.Frobenius
variable {d : ℕ}
lemma sandwich_shift_inverse (X U : H d) (hX : X ∈ pd d) (r : ℝ) : sandwich (U-r • X) (invH X) = sandwich U (invH X) - (2*r) • U + r^2 • X := by have hx := (Matrix.isUnit_iff_isUnit_det (X : Mat d)).mp hX.isUnit apply Subtype.ext change ((U : Mat d)-r • (X : Mat d)) * (X : Mat d)⁻¹ * ((U : Mat d)-r • (X : Mat d)) = (U : Mat d) * (X : Mat d)⁻¹ * (U : Mat d) - (2*r) • (U : Mat d) + r^2 • (X : Mat d) simp only [sub_mul,mul_sub,smul_mul_assoc,mul_smul_comm, mul_assoc, Matrix.mul_nonsing_inv_cancel_left _ _ hx, Matrix.nonsing_inv_mul _ hx, mul_one] module
lemma trace_inverse_cauchy (A X U : H d) (hA : A ∈ psdCone d) (hX : X ∈ pd d) : (inner ℝ A U)^2 ≤ inner ℝ A X * inner ℝ A (sandwich U (invH X)) := by have hn (r : ℝ) := inner_nonneg_of_psd A (sandwich (U-r • X) (invH X)) hA (sandwich_psd _ _ hX.inv.posSemidef) have hn' (r : ℝ) : 0 ≤ inner ℝ A (sandwich U (invH X)) - (2*r)*inner ℝ A U + r^2*inner ℝ A X := by have hh := hn r rw [sandwich_shift_inverse X U hX,inner_add_right,inner_sub_right, real_inner_smul_right A U (2*r),real_inner_smul_right A X (r^2)] at hh exact hh have hh := discrim_le_zero (a := inner ℝ A X) (b := -2*inner ℝ A U) (c := inner ℝ A (sandwich U (invH X))) (fun r => by nlinarith [hn' r]) rw [discrim] at hh nlinarith
lemma trace_mul_real (A B : H d) : (((A : Mat d)*(B : Mat d)).trace.re : ℂ) = ((A : Mat d)*(B : Mat d)).trace := by have hs : star (((A : Mat d)*(B : Mat d)).trace) = ((A : Mat d)*(B : Mat d)).trace := by rw [← Matrix.trace_conjTranspose,Matrix.conjTranspose_mul,A.property.eq,B.property.eq,Matrix.trace_mul_comm] exact Complex.conj_eq_iff_re.mp hs
lemma sandwich_rank_one (A B : H d) (hA : A ∈ psdCone d) (hrank : (A : Mat d).rank ≤ 1) : sandwich A B = (inner ℝ A B) • A := by apply Subtype.ext change (A : Mat d)*(B : Mat d)*(A : Mat d) = (inner ℝ A B) • (A : Mat d) rw [CurrentKS.rank_one_sandwich _ hA hrank,inner_eq_trace] have hs (r : ℝ) : r • (A : Mat d) = (r : ℂ) • (A : Mat d) := by ext i j exact Complex.real_smul rw [hs,trace_mul_real]
lemma trace_inverse_young (A X U : H d) (hA : A ∈ psdCone d) (hX : X ∈ pd d) {s : ℝ} (hs : 0 < s) (t : ℝ) : 2*t*inner ℝ A U ≤ s*inner ℝ A (sandwich U (invH X)) + t^2/s*inner ℝ A X := by have hn := inner_nonneg_of_psd A (sandwich (U-(t/s) • X) (invH X)) hA (sandwich_psd _ _ hX.inv.posSemidef) rw [sandwich_shift_inverse X U hX,inner_add_right,inner_sub_right, real_inner_smul_right A U (2*(t/s)),real_inner_smul_right A X ((t/s)^2)] at hn have hh := mul_nonneg hs.le hn field_simp at hh ⊢ nlinarith
end CurrentKS.Hermitian
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130import Mathlibimport OAI.Analysis.MatrixSigning.Encoding.FrameWireCodecimport OAI.Analysis.MatrixSigning.Encoding.WireAppend
namespace OAI
section
namespace KS.W08.SavedPivotPacketopen KS.W01.FixedStack KS.W29.FixedSequential KS.W03.MachineCombinatorsopen KS.W28.FixedPositiveSerializer (registers)
theorem frame_at {k : ℕ} (ports : Fin 3 ↪ Fin k) (before : Fin k → List Bool) (payload : List Bool) (h0 : before (ports 0) = []) (h1 : before (ports 1) = payload) (h2 : before (ports 2) = []) : RunSpec (KS.W11.FrameWireCodec.frameProgram ports) before (Function.update before (ports 1) (KS.W01.frame payload)) (4 * payload.length + 3) := by have h := KS.W11.FrameWireCodec.frame_spec ports before payload have hi : registers ports before [] payload [] = before := by funext j by_cases hj0 : j = ports 0 · subst j; simp [registers, h0] · by_cases hj1 : j = ports 1 · subst j; simp [registers, hj0, h1] · by_cases hj2 : j = ports 2 · subst j; simp [registers, hj0, hj1, h2] · simp [registers, hj0, hj1, hj2] have ho : registers ports before [] (KS.W01.frame payload) [] = Function.update before (ports 1) (KS.W01.frame payload) := by funext j by_cases hj0 : j = ports 0 · subst j; simp [registers, Function.update, h0, ports.injective.eq_iff] · by_cases hj1 : j = ports 1 · subst j; simp [registers, hj0, Function.update] · by_cases hj2 : j = ports 2 · subst j; simp [registers, hj0, hj1, h2, Function.update] · simp [registers, hj0, hj1, hj2, Function.update] rw [hi, ho] at h exact h
def workspace (saved dim row : List Bool) : Fin 5 → List Bool := ![saved, dim, row, [], []]def dimPorts : Fin 3 ↪ Fin 5 := ⟨![3, 1, 4], by decide⟩def packetPorts : Fin 3 ↪ Fin 5 := ⟨![1, 2, 4], by decide⟩def payload (dim row : List Bool) : List Bool := KS.W01.frame dim ++ row
def program : Program 5 := compose (compose (compose (KS.W11.FrameWireCodec.frameProgram dimPorts) (KS.W07.WireAppend.program 1 2 3)) (KS.W11.FrameWireCodec.frameProgram packetPorts)) (KS.W07.WireAppend.program 2 0 3)
theorem full_spec (saved dim row : List Bool) : RunSpec program (workspace saved dim row) (workspace (KS.W01.frame (payload dim row) ++ saved) [] []) (24 * dim.length + 8 * row.length + 22) := by have h1 := frame_at dimPorts (workspace saved dim row) dim rfl rfl rfl have e1 : Function.update (workspace saved dim row) (dimPorts 1) (KS.W01.frame dim) = workspace saved (KS.W01.frame dim) row := by funext j; fin_cases j <;> simp [workspace, dimPorts, Function.update] rw [e1] at h1 have h2 := KS.W07.WireAppend.spec (1 : Fin 5) 2 3 (by decide) (by decide) (by decide) (workspace saved (KS.W01.frame dim) row) rfl have e2 : KS.W07.WireAppend.after 1 2 (workspace saved (KS.W01.frame dim) row) = workspace saved [] (payload dim row) := by funext j; fin_cases j <;> simp [workspace, payload, KS.W07.WireAppend.after] rw [e2] at h2 have h3 := frame_at packetPorts (workspace saved [] (payload dim row)) (payload dim row) rfl rfl rfl have e3 : Function.update (workspace saved [] (payload dim row)) (packetPorts 1) (KS.W01.frame (payload dim row)) = workspace saved [] (KS.W01.frame (payload dim row)) := by funext j; fin_cases j <;> simp [workspace, packetPorts, Function.update] rw [e3] at h3 have h4 := KS.W07.WireAppend.spec (2 : Fin 5) 0 3 (by decide) (by decide) (by decide) (workspace saved [] (KS.W01.frame (payload dim row))) rfl have e4 : KS.W07.WireAppend.after 2 0 (workspace saved [] (KS.W01.frame (payload dim row))) = workspace (KS.W01.frame (payload dim row) ++ saved) [] [] := by funext j; fin_cases j <;> simp [workspace, KS.W07.WireAppend.after] rw [e4] at h4 have h := ((h1.compose h2).compose h3).compose h4 have ht : (((4 * dim.length + 3) + (2 * (workspace saved (KS.W01.frame dim) row 1).length + 2)) + (4 * (payload dim row).length + 3)) + (2 * (workspace saved [] (KS.W01.frame (payload dim row)) 2).length + 2) = 24 * dim.length + 8 * row.length + 22 := by change (((4 * dim.length + 3) + (2 * (KS.W01.frame dim).length + 2)) + (4 * (payload dim row).length + 3)) + (2 * (KS.W01.frame (payload dim row)).length + 2) = _ simp only [payload, List.length_append, KS.W01.length_frame] omega rw [ht] at h exact h
def outerPorts : Fin 3 ↪ Fin 5 := ⟨![0, 2, 3], by decide⟩def innerPorts : Fin 3 ↪ Fin 5 := ⟨![2, 1, 3], by decide⟩def popProgram : Program 5 := compose (KS.W11.FrameWireCodec.unframeProgram outerPorts) (KS.W11.FrameWireCodec.unframeProgram innerPorts)
theorem pop_spec (saved dim row : List Bool) : RunSpec popProgram (workspace (KS.W01.frame (payload dim row) ++ saved) [] []) (workspace saved dim row) (9 * dim.length + 3 * row.length + 7) := by have h1 := KS.W11.FrameWireCodec.unframe_spec outerPorts (workspace [] [] []) (payload dim row) saved have e1 : registers outerPorts (workspace [] [] []) (KS.W01.frame (payload dim row) ++ saved) [] [] = workspace (KS.W01.frame (payload dim row) ++ saved) [] [] := by funext j; fin_cases j <;> simp [registers, outerPorts, workspace] have e2 : registers outerPorts (workspace [] [] []) saved (payload dim row) [] = workspace saved [] (payload dim row) := by funext j; fin_cases j <;> simp [registers, outerPorts, workspace] rw [e1, e2] at h1 have h2 := KS.W11.FrameWireCodec.unframe_spec innerPorts (workspace saved [] []) dim row have e3 : registers innerPorts (workspace saved [] []) (KS.W01.frame dim ++ row) [] [] = workspace saved [] (payload dim row) := by funext j; fin_cases j <;> simp [registers, innerPorts, workspace, payload] have e4 : registers innerPorts (workspace saved [] []) row dim [] = workspace saved dim row := by funext j; fin_cases j <;> simp [registers, innerPorts, workspace] rw [e3, e4] at h2 have h := h1.compose h2 have ht : (3 * (payload dim row).length + 2) + (3 * dim.length + 2) = 9 * dim.length + 3 * row.length + 7 := by simp only [payload, List.length_append, KS.W01.length_frame] omega rw [ht] at h exact h
end KS.W08.SavedPivotPacket
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112import Mathlibimport OAI.Analysis.MatrixSigning.Encoding.FrameWireCodecimport OAI.Analysis.MatrixSigning.Encoding.WireAppend
namespace OAI
section
namespace KS.W08.SavedPivotStack
open KS.W01.FixedStack KS.W29.FixedSequential KS.W03.MachineCombinatorsopen KS.W28.FixedPositiveSerializer (registers)
def workspace (saved payload : List Bool) : Fin 4 → List Bool := ![saved, payload, [], []]
def framePorts : Fin 3 ↪ Fin 4 := ⟨![2, 1, 3], by decide⟩def popPorts : Fin 3 ↪ Fin 4 := ⟨![0, 1, 2], by decide⟩
def pushProgram : Program 4 := compose (KS.W11.FrameWireCodec.frameProgram framePorts) (KS.W07.WireAppend.program 1 0 2)
def popProgram : Program 4 := KS.W11.FrameWireCodec.unframeProgram popPorts
theorem push_spec (saved payload : List Bool) : RunSpec pushProgram (workspace saved payload) (workspace (KS.W01.frame payload ++ saved) []) (8 * payload.length + 7) := by have hf := KS.W11.FrameWireCodec.frame_spec framePorts (workspace saved []) payload have hi : registers framePorts (workspace saved []) [] payload [] = workspace saved payload := by funext j fin_cases j <;> simp [registers, framePorts, workspace] have ho : registers framePorts (workspace saved []) [] (KS.W01.frame payload) [] = workspace saved (KS.W01.frame payload) := by funext j fin_cases j <;> simp [registers, framePorts, workspace] rw [hi, ho] at hf have ha := KS.W07.WireAppend.spec (1 : Fin 4) 0 2 (by decide) (by decide) (by decide) (workspace saved (KS.W01.frame payload)) rfl have he : KS.W07.WireAppend.after 1 0 (workspace saved (KS.W01.frame payload)) = workspace (KS.W01.frame payload ++ saved) [] := by funext j fin_cases j <;> simp [KS.W07.WireAppend.after, workspace] rw [he] at ha have h := hf.compose ha have ht : (4 * payload.length + 3) + (2 * (workspace saved (KS.W01.frame payload) 1).length + 2) = 8 * payload.length + 7 := by change (4 * payload.length + 3) + (2 * (KS.W01.frame payload).length + 2) = _ rw [KS.W01.length_frame] omega rw [ht] at h exact h
theorem pop_spec (saved payload : List Bool) : RunSpec popProgram (workspace (KS.W01.frame payload ++ saved) []) (workspace saved payload) (3 * payload.length + 2) := by have h := KS.W11.FrameWireCodec.unframe_spec popPorts (workspace [] []) payload saved have hi : registers popPorts (workspace [] []) (KS.W01.frame payload ++ saved) [] [] = workspace (KS.W01.frame payload ++ saved) [] := by funext j fin_cases j <;> simp [registers, popPorts, workspace] have ho : registers popPorts (workspace [] []) saved payload [] = workspace saved payload := by funext j fin_cases j <;> simp [registers, popPorts, workspace] rw [hi, ho] at h exact h
def stackTape (payloads : List (List Bool)) : List Bool := payloads.flatMap KS.W01.frame
@[simp] theorem stackTape_cons (payload : List Bool) (tail : List (List Bool)) : stackTape (payload :: tail) = KS.W01.frame payload ++ stackTape tail := rfl
@[simp] theorem stackTape_nil : stackTape [] = [] := rfl
theorem push_stack_spec (tail : List (List Bool)) (payload : List Bool) : RunSpec pushProgram (workspace (stackTape tail) payload) (workspace (stackTape (payload :: tail)) []) (8 * payload.length + 7) := push_spec _ _
theorem pop_stack_spec (tail : List (List Bool)) (payload : List Bool) : RunSpec popProgram (workspace (stackTape (payload :: tail)) []) (workspace (stackTape tail) payload) (3 * payload.length + 2) := pop_spec _ _
theorem stackTape_length (payloads : List (List Bool)) : (stackTape payloads).length = 2 * (payloads.map List.length).sum + payloads.length := by induction payloads with | nil => rfl | cons p ps ih => simp [stackTape_cons, KS.W01.length_frame, ih]; omega
theorem stackTape_length_le (payloads : List (List Bool)) (b : ℕ) (h : ∀ p ∈ payloads, p.length ≤ b) : (stackTape payloads).length ≤ payloads.length * (2 * b + 1) := by induction payloads with | nil => simp | cons p ps ih => have hp := h p (by simp) have ht := ih (fun q hq => h q (by simp [hq])) simp only [stackTape_cons, List.length_append, KS.W01.length_frame, List.length_cons] calc 2 * p.length + 1 + (stackTape ps).length ≤ (2 * b + 1) + ps.length * (2 * b + 1) := by omega _ = (ps.length + 1) * (2 * b + 1) := by simp only [Nat.add_mul, Nat.one_mul] omega
end KS.W08.SavedPivotStack
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.HermitianMat
namespace OAI
open Matrix
namespace CurrentKS.HermitianCoordinatesnoncomputable sectionopen CurrentKS.Hermitian Matrixopen scoped BigOperators Matrix.Norms.Frobenius
variable {d : ℕ}local instance : NormedAddCommGroup (H d) := inferInstancelocal instance : NormedSpace ℝ (H d) := inferInstance
abbrev Space (d : ℕ) := EuclideanSpace ℝ (Fin d × Fin d)local instance : NormedAddCommGroup (Space d) := inferInstancelocal instance : NormedSpace ℝ (Space d) := inferInstance
def decode (x : Fin d × Fin d → ℝ) : Mat d := fun i j => ⟨x (min i j,max i j),if i < j then x (j,i) else if j < i then -x (i,j) else 0⟩
def encode (A : H d) : Fin d × Fin d → ℝ := fun p => if p.1 ≤ p.2 then (A.val p.1 p.2).re else (A.val p.2 p.1).im
lemma decode_hermitian (x : Fin d × Fin d → ℝ) : (decode x).IsHermitian := by apply Matrix.IsHermitian.ext intro i j apply Complex.ext · simp [decode,min_comm,max_comm] · simp only [decode,Complex.star_def,Complex.conj_im] rcases lt_trichotomy i j with hij | hij | hji · simp [hij,not_lt.mpr hij.le] · subst j; simp · simp [hji,not_lt.mpr hji.le]
def assemble (x : Space d) : H d := ⟨decode x,decode_hermitian x⟩def extract (A : H d) : Space d := WithLp.toLp 2 (encode A)
lemma extract_assemble (x : Space d) : extract (assemble x)=x := by ext p rcases p with ⟨i,j⟩ by_cases hij : i ≤ j · simp [extract,assemble,encode,decode,hij] · have hji := lt_of_not_ge hij simp [extract,assemble,encode,decode,hij,hji]
lemma assemble_extract (A : H d) : assemble (extract A)=A := by apply Subtype.ext ext i j have hh := Matrix.IsHermitian.apply A.property i j have hd := Matrix.IsHermitian.apply A.property i i rcases lt_trichotomy i j with hij | hij | hji · apply Complex.ext <;> simp [assemble,extract,encode,decode,hij,hij.le,not_le.mpr hij] · subst j apply Complex.ext · simp [assemble,extract,encode,decode] · have him := congrArg Complex.im hd simp only [Complex.star_def,Complex.conj_im] at him simp [assemble,extract,encode,decode] linarith · apply Complex.ext · have hre := congrArg Complex.re hh simp only [Complex.star_def,Complex.conj_re] at hre simpa [assemble,extract,encode,decode,hji,hji.le,not_le.mpr hji, min_eq_right hji.le,max_eq_left hji.le] using hre · have him := congrArg Complex.im hh simp only [Complex.star_def,Complex.conj_im] at him simpa [assemble,extract,encode,decode,hji,hji.le,not_lt.mpr hji.le, not_le.mpr hji] using him
lemma decode_add (x y : Fin d × Fin d → ℝ) : decode (x+y)=decode x+decode y := by ext i j apply Complex.ext · simp [decode,Matrix.add_apply] · simp only [decode,Matrix.add_apply,Pi.add_apply,Complex.add_im] split_ifs <;> ring
lemma decode_smul (r : ℝ) (x : Fin d × Fin d → ℝ) : decode (r • x)=r • decode x := by ext i j apply Complex.ext · simp [decode,Matrix.smul_apply] · simp only [decode,Matrix.smul_apply,Pi.smul_apply,smul_eq_mul,Complex.real_smul,Complex.mul_im, Complex.ofReal_re,Complex.ofReal_im,zero_mul] split_ifs <;> ring
def assembleLinear (d : ℕ) : Space d →ₗ[ℝ] H d where toFun := assemble map_add' x y := Subtype.ext (decode_add x y) map_smul' r x := Subtype.ext (decode_smul r x)
lemma norm_decode_entry (x : Fin d × Fin d → ℝ) (i j : Fin d) : ‖decode x i j‖^2 ≤ x (i,j)^2+x (j,i)^2 := by rw [Complex.sq_norm] simp only [Complex.normSq_apply] rcases lt_trichotomy i j with hij | hij | hji · simp [decode,min_eq_left hij.le,max_eq_right hij.le,hij,pow_two] · subst j simp only [decode,min_self,max_self,lt_self_iff_false,ite_false] nlinarith [sq_nonneg (x (i,i))] · simp [decode,min_eq_right hji.le,max_eq_left hji.le,hji,not_lt.mpr hji.le,pow_two] ring_nf rfl
lemma norm_assemble_sq (x : Space d) : ‖assemble x‖^2 ≤ 2*‖x‖^2 := by have hm : ‖assemble x‖^2 = ∑ i : Fin d, ∑ j : Fin d, ‖decode x i j‖^2 := by change ‖asL2 (decode x)‖^2 = _ rw [PiLp.norm_sq_eq_of_L2] simp only [asL2,PiLp.toLp_apply,PiLp.norm_sq_eq_of_L2] rw [hm,PiLp.norm_sq_eq_of_L2] have hb := Finset.sum_le_sum (fun i (_ : i ∈ (Finset.univ : Finset (Fin d))) => Finset.sum_le_sum (fun j (_ : j ∈ (Finset.univ : Finset (Fin d))) => norm_decode_entry x i j)) have he : (∑ i : Fin d, ∑ j : Fin d, x (j,i)^2) = ∑ i : Fin d, ∑ j : Fin d, x (i,j)^2 := Finset.sum_comm simpa only [Finset.sum_add_distrib,Fintype.sum_prod_type,Real.norm_eq_abs,sq_abs, two_mul,he] using hb
lemma norm_assemble (x : Space d) : ‖assemble x‖ ≤ 2*‖x‖ := by have h := norm_assemble_sq x nlinarith [norm_nonneg x,norm_nonneg (assemble x)]
private local instance : TopologicalSpace (H d) := (inferInstance : NormedAddCommGroup (H d)).toUniformSpace.toTopologicalSpace
private local instance : TopologicalSpace (Space d) := (inferInstance : NormedAddCommGroup (Space d)).toUniformSpace.toTopologicalSpace
def assembleCLM (d : ℕ) : Space d →L[ℝ] H d := (assembleLinear d).mkContinuous 2 norm_assemble
lemma norm_assembleCLM : ‖(assembleCLM d : Space d →L[ℝ] H d)‖ ≤ (2:ℝ) := ContinuousLinearMap.opNorm_le_bound _ (by norm_num) norm_assemble
endend CurrentKS.HermitianCoordinates
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.SandwichCLM
namespace OAI
open Matrix
namespace CurrentKS.Hermitiannoncomputable sectionopen Matrix Setopen scoped BigOperators ComplexOrder MatrixOrder
variable {d : ℕ}section Operatoropen scoped Matrix.Norms.L2Operator
lemma square_scalar_bound (A : H d) {a : ℝ} (ha : 0 ≤ a) (hApos : A ∈ psdCone d) (hA : A ≤ a • (Hermitian.one : H d)) : sandwich A Hermitian.one ≤ a^2 • (Hermitian.one : H d) := by let : CStarAlgebra (Mat d) := {} have hnorm : ‖(A : Mat d)‖ ≤ a := by apply (CStarAlgebra.norm_le_iff_le_algebraMap (A : Mat d) ha hApos.nonneg).mpr simp only [Algebra.algebraMap_eq_smul_one] exact hA have hsqpos : ((A : Mat d)*(A : Mat d)).PosSemidef := by have hh : ((sandwich A Hermitian.one : H d) : Mat d).PosSemidef := sandwich_psd A Hermitian.one one_mem_psdCone simpa only [sandwich_val, one_val, mul_one] using hh have hsqnorm : ‖(A : Mat d)*(A : Mat d)‖ ≤ a^2 := (norm_mul_le _ _).trans (by nlinarith [norm_nonneg (A : Mat d)]) have hb := (CStarAlgebra.norm_le_iff_le_algebraMap ((A : Mat d)*(A : Mat d)) (sq_nonneg a) hsqpos.nonneg).mp hsqnorm change (A : Mat d)*1*(A : Mat d) ≤ (a^2 : ℝ) • (1 : Mat d) simpa only [Algebra.algebraMap_eq_smul_one, mul_one] using hb
end Operator
lemma inverse_lower_of_upper (X : H d) (hX : X ∈ pd d) {a : ℝ} (ha : 0 < a) (h : X ≤ a • (Hermitian.one : H d)) : a⁻¹ • (Hermitian.one : H d) ≤ invH X := by exact inverse_bound_below ha hX.inv (by rwa [invH_involutive X hX])
lemma inverse_upper_of_lower (X : H d) (hX : X ∈ pd d) {a : ℝ} (ha : 0 < a) (h : a • (Hermitian.one : H d) ≤ X) : invH X ≤ a⁻¹ • (Hermitian.one : H d) := by have hi := inverse_antitone (scalar_posDef ha) hX h rw [scalar_inv] at hi change (X : Mat d)⁻¹ ≤ ((a⁻¹ : ℝ) : ℂ) • (1 : Mat d) simpa only [Complex.ofReal_inv] using hi
endend CurrentKS.Hermitian
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.Sandwichimport OAI.Analysis.MatrixSigning.Matrices.RealTraceSum
namespace OAI
open Matrix
namespace CurrentKS.Hermitiannoncomputable sectionopen Matrixopen scoped BigOperators ComplexOrder MatrixOrder
variable {d : ℕ}lemma square_shift (X : H d) (a : ℝ) : sandwich (X-a • (Hermitian.one : H d)) Hermitian.one = sandwich X Hermitian.one-(2*a) • X+a^2 • (Hermitian.one : H d) := by apply Subtype.ext change ((X : Mat d)-a • 1)*1*((X : Mat d)-a • 1) = (X : Mat d)*1*(X : Mat d)-(2*a) • (X : Mat d)+a^2 • 1 simp only [mul_one,sub_mul,mul_sub,mul_smul_comm,smul_mul_assoc,one_mul] module
lemma square_lower (X : H d) {a : ℝ} (ha : 0 ≤ a) (hX : a • (Hermitian.one : H d) ≤ X) : a^2 • (Hermitian.one : H d) ≤ sandwich X Hermitian.one := by have hsq := (mem_psd_iff_nonneg _).mp (sandwich_psd (X-a • (Hermitian.one : H d)) (Hermitian.one : H d) one_mem_psdCone) rw [square_shift] at hsq have hlo := smul_order hX (mul_nonneg (by norm_num : (0 : ℝ) ≤ 2) ha) rw [smul_smul] at hlo have hh := add_le_add hsq hlo have he : sandwich X Hermitian.one-(2*a) • X+a^2 • (Hermitian.one : H d)+(2*a) • X = sandwich X Hermitian.one+a^2 • (Hermitian.one : H d) := by abel rw [zero_add,he] at hh have he' : (2*a*a) • (Hermitian.one : H d) = a^2 • (Hermitian.one : H d)+a^2 • (Hermitian.one : H d) := by module rw [he'] at hh exact (add_le_add_iff_right (a^2 • (Hermitian.one : H d))).mp hhendend CurrentKS.Hermitian
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.InvH
namespace OAI
open Matrix
namespace CurrentKS.Hermitiannoncomputable sectionopen Matrix Setopen scoped BigOperators ComplexOrder MatrixOrder Matrix.Norms.Frobenius
variable {d : ℕ}
@[simp] lemma realTrace_zero : realTrace (0 : H d) = 0 := by simp [realTrace]
@[simp] lemma realTrace_add (A B : H d) : realTrace (A+B) = realTrace A + realTrace B := by change ((A : Mat d) + (B : Mat d)).trace.re = _ simp [Matrix.trace_add, realTrace]
@[simp] lemma realTrace_sub (A B : H d) : realTrace (A-B) = realTrace A - realTrace B := by change ((A : Mat d) - (B : Mat d)).trace.re = _ simp [Matrix.trace_sub, realTrace]
@[simp] lemma realTrace_smul (r : ℝ) (A : H d) : realTrace (r • A) = r * realTrace A := by change ((r : ℂ) • (A : Mat d)).trace.re = _ rw [Matrix.trace_smul] simp only [smul_eq_mul, Complex.mul_re, Complex.ofReal_re, Complex.ofReal_im, zero_mul, sub_zero, realTrace]
@[simp] lemma realTrace_one : realTrace (one : H d) = d := by simp [realTrace]
lemma realTrace_nonneg {A : H d} (hA : A ∈ psdCone d) : 0 ≤ realTrace A := (Complex.nonneg_iff.mp hA.trace_nonneg).1
lemma realTrace_pos [NeZero d] {A : H d} (hA : A ∈ pd d) : 0 < realTrace A := (Complex.pos_iff.mp hA.trace_pos).1
lemma realTrace_mono {A B : H d} (hab : A ≤ B) : realTrace A ≤ realTrace B := by have hh := realTrace_nonneg (show B-A ∈ psdCone d from hab) simpa using hh
def traceCLM : H d →L[ℝ] ℝ := innerSL ℝ one
@[simp] lemma traceCLM_apply (A : H d) : traceCLM A = realTrace A := inner_one A
lemma continuous_realTrace : Continuous (realTrace : H d → ℝ) := by have he : (fun A : H d => traceCLM A) = realTrace := funext traceCLM_apply rw [← he] exact (traceCLM (d := d)).continuous
lemma continuousAt_invH {A : H d} (hA : A ∈ pd d) : ContinuousAt invH A := by have hm : ContinuousAt (Inv.inv : Mat d → Mat d) (A : Mat d) := by apply continuousAt_matrix_inv have he : (Ring.inverse : ℂ → ℂ) = Inv.inv := funext Ring.inverse_eq_inv rw [he] exact continuousAt_inv₀ hA.det_pos.ne' apply tendsto_subtype_rng.mpr exact hm.comp continuousAt_subtype_val
lemma pd_of_lower {a : ℝ} (ha : 0 < a) {A : H d} (hA : a • one ≤ A) : A ∈ pd d := by have hp : ((A : Mat d) - (a : ℂ) • 1).PosSemidef := hA have hs := (scalar_posDef ha).add_posSemidef hp simp only [add_sub_cancel] at hs exact hs
lemma inverse_bound_below {a : ℝ} (ha : 0 < a) {A : H d} (hA : A ∈ pd d) (he : invH A ≤ a • one) : a⁻¹ • one ≤ A := by let : Invertible (A : Mat d) := hA.isUnit.invertible have hi := inverse_antitone hA.inv (scalar_posDef ha) he rw [scalar_inv, Matrix.inv_inv_of_invertible] at hi change ((a⁻¹ : ℝ) : ℂ) • (1 : Mat d) ≤ (A : Mat d) simpa only [Complex.ofReal_inv] using hi
lemma psd_nonneg {A : H d} (hA : A ∈ psdCone d) : 0 ≤ A := hA.nonneg
lemma mem_psd_iff_nonneg (A : H d) : A ∈ psdCone d ↔ 0 ≤ A := by constructor · exact psd_nonneg · intro hA have hh : (0 : Mat d) ≤ (A : Mat d) := hA exact hh.posSemidef
lemma scalar_one_mono {r s : ℝ} (hrs : r ≤ s) : r • (one : H d) ≤ s • one := by apply sub_nonneg.mp erw [← sub_smul] exact psd_nonneg (psd_smul one_mem_psdCone (sub_nonneg.mpr hrs))
lemma trace_bound_above {A : H d} (hA : A ∈ psdCone d) : A ≤ realTrace A • one := le_trace_smul_one hA
endend CurrentKS.Hermitian
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.RationalElimination
namespace OAI
section
namespace KS.W17
@[simp] theorem schurTail_zero_pivot {n : ℕ} (M : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) (h : M 0 0 = 0) : schurTail M = trailingMatrix M := by funext i j simp [schurTail, trailingMatrix, h]
@[simp] theorem schurWitnessLift_zero_pivot {n : ℕ} (M : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) (h : M 0 0 = 0) (y : Fin n → ℚ) : schurWitnessLift M y = Fin.cons 0 y := by simp [schurWitnessLift, h]
def pivotTerminal {n : ℕ} (M : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) : Option (Fin (n+1) → ℚ) := if M 0 0 < 0 then some (Pi.single 0 1) else if M 0 0 = 0 then (firstNonzeroOffDiagonal M).map (fun j => zeroPivotWitness M 0 j.succ) else none
def uniformNegativeWitness : (n : ℕ) → Matrix (Fin n) (Fin n) ℚ → Option (Fin n → ℚ) | 0, _ => none | n+1, M => match pivotTerminal M with | some q => some q | none => (uniformNegativeWitness n (schurTail M)).map (schurWitnessLift M)
theorem uniformNegativeWitness_eq (n : ℕ) (M : Matrix (Fin n) (Fin n) ℚ) : uniformNegativeWitness n M = rationalNegativeWitness n M := by induction n with | zero => rfl | succ n ih => by_cases hn : M 0 0 < 0 · simp [uniformNegativeWitness, pivotTerminal, rationalNegativeWitness, hn] · by_cases hz : M 0 0 = 0 · cases hf : firstNonzeroOffDiagonal M with | none => have hl : schurWitnessLift M = (fun y : Fin n → ℚ => Fin.cons (0 : ℚ) y) := by funext y exact schurWitnessLift_zero_pivot M hz y simp [uniformNegativeWitness, pivotTerminal, rationalNegativeWitness, hz, hf, ih, hl] | some j => simp [uniformNegativeWitness, pivotTerminal, rationalNegativeWitness, hz, hf] · simp [uniformNegativeWitness, pivotTerminal, rationalNegativeWitness, hn, hz, ih]
inductive PivotHistory : ℕ → ℕ → Type | nil (n : ℕ) : PivotHistory n n | push {n N : ℕ} (M : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) (rest : PivotHistory (n+1) N) : PivotHistory n N
namespace PivotHistory
def restore : {n N : ℕ} → PivotHistory n N → (Fin n → ℚ) → (Fin N → ℚ) | _, _, .nil _, q => q | _, _, .push M rest, q => restore rest (schurWitnessLift M q)
def depth : {n N : ℕ} → PivotHistory n N → ℕ | _, _, .nil _ => 0 | _, _, .push _ rest => depth rest + 1
theorem dimension_depth {n N : ℕ} (h : PivotHistory n N) : n + depth h = N := by induction h with | nil n => simp [depth] | @push n N M rest ih => simpa [depth, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using ih
@[simp] theorem restore_push {n N : ℕ} (M : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) (h : PivotHistory (n+1) N) (q : Fin n → ℚ) : restore (.push M h) q = restore h (schurWitnessLift M q) := rfl
theorem descent_restore {n N : ℕ} (M : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) (h : PivotHistory (n+1) N) (ht : pivotTerminal M = none) : (uniformNegativeWitness n (schurTail M)).map (restore (.push M h)) = (uniformNegativeWitness (n+1) M).map (restore h) := by simp [uniformNegativeWitness, ht, Option.map_map, Function.comp_def, restore]
end PivotHistoryend KS.W17
end
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.UniformEliminationimport OAI.Analysis.MatrixSigning.Matrices.EliminationCallBounds
namespace OAI
section
namespace KS.W17open KS.W07
theorem pivotTerminal_none_cases {n : ℕ} (M : Matrix (Fin (n+1)) (Fin (n+1)) ℚ) (ht : pivotTerminal M = none) : (M 0 0 = 0 ∧ firstNonzeroOffDiagonal M = none) ∨ 0 < M 0 0 := by have hn : ¬ M 0 0 < 0 := by intro h simp [pivotTerminal,h] at ht by_cases hz : M 0 0 = 0 · left refine ⟨hz,?_⟩ cases hf : firstNonzeroOffDiagonal M with | none => rfl | some j => simp [pivotTerminal,hz,hf] at ht · right exact lt_of_le_of_ne (not_lt.mp hn) (Ne.symm hz)
theorem DenseEliminationCall.uniform_child {N n : ℕ} {A : DenseRatMatrix N} {M : DenseRatMatrix (n+1)} (h : DenseEliminationCall A M) (ht : pivotTerminal (DenseRatMatrix.decode M) = none) : DenseEliminationCall A (DenseRatMatrix.ofMatrix (schurTail (DenseRatMatrix.decode M))) := by rcases pivotTerminal_none_cases (DenseRatMatrix.decode M) ht with ⟨hz,hr⟩ | hp · rw [schurTail_zero_pivot _ hz] exact .zero h hz hr · exact .positive h hp
theorem DenseEliminationCall.uniform_child_parts {N n : ℕ} {A : DenseRatMatrix N} {M : DenseRatMatrix (n+1)} (h : DenseEliminationCall A M) (ht : pivotTerminal (DenseRatMatrix.decode M) = none) (b : ℕ) (hnum : ∀ i j, (DenseRatMatrix.decode A i j).num.natAbs ≤ 2^b) (hden : ∀ i j, (DenseRatMatrix.decode A i j).den ≤ 2^b) (i j : Fin n) : Nat.size (schurTail (DenseRatMatrix.decode M) i j).num.natAbs ≤ KS.W30.inverseBitBound N b ∧ Nat.size (schurTail (DenseRatMatrix.decode M) i j).den ≤ KS.W30.inverseBitBound N b := by simpa using (h.uniform_child ht).entry_parts_size_le b hnum hden i j
end KS.W17
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137import Mathlib
namespace OAI
namespace CurrentKS
/-- Escaped binary words. -/def frame : List Bool → List Bool | [] => [true] | b :: bs => false :: b :: frame bs
def encodeNat (n : ℕ) : List Bool := frame (Computability.encodeNat n)
def encodeInt : ℤ → List Bool | .ofNat n => false :: encodeNat n | .negSucc n => true :: encodeNat n
/-- The two binary fields are a numerator and a positive denominator. -/structure RationalEntry where numerator : ℤ denominator : ℕ denominator_pos : 0 < denominator
def RationalEntry.value (a : RationalEntry) : ℚ := (a.numerator : ℚ) / (a.denominator : ℚ)
def RationalEntry.encode (a : RationalEntry) : List Bool := encodeInt a.numerator ++ encodeNat a.denominator
abbrev RationalComplex := RationalEntry × RationalEntry
def encodeComplex (z : RationalComplex) : List Bool := z.1.encode ++ z.2.encode
def toComplex (z : RationalComplex) : ℂ := ⟨(z.1.value : ℝ), (z.2.value : ℝ)⟩
structure Input where d : ℕ N : ℕ entries : Fin N → Matrix (Fin d) (Fin d) RationalComplex
/-- Row-major entries; a matrix-record delimiter retains explicit list lengthalso for order-zero matrices. This constant-per-matrix framing is polynomiallyequivalent to dense binary matrix listing in positive dimension. -/def Input.encodeMatrix (x : Input) (i : Fin x.N) : List Bool := true :: ((List.ofFn fun j : Fin x.d => (List.ofFn fun k : Fin x.d => x.entries i j k).flatMap encodeComplex).flatten)
def Input.encode (x : Input) : List Bool := encodeNat x.d ++ encodeNat x.N ++ (List.ofFn x.encodeMatrix).flatten
def Input.length (x : Input) : ℕ := x.encode.length
def Input.matrix (x : Input) (i : Fin x.N) : Matrix (Fin x.d) (Fin x.d) ℂ := (x.entries i).map toComplex
noncomputable def opNorm {d : ℕ} (A : Matrix (Fin d) (Fin d) ℂ) : ℝ := ‖Matrix.toEuclideanCLM (𝕜 := ℂ) A‖
def Admissible (x : Input) : Prop := ∀ i, (x.matrix i).IsHermitian ∧ (x.matrix i).rank ≤ 1
def signValue (b : Bool) : ℝ := if b then 1 else -1
noncomputable def signedSum (x : Input) (bits : List Bool) : Matrix (Fin x.d) (Fin x.d) ℂ := ∑ i, signValue (bits.getD i.val false) • x.matrix i
noncomputable def variance (x : Input) : Matrix (Fin x.d) (Fin x.d) ℂ := ∑ i, x.matrix i * x.matrix i
def GoodOutput (x : Input) (bits : List Bool) : Prop := bits.length = x.N ∧ opNorm (signedSum x bits) ≤ 40 * Real.sqrt (opNorm (variance x))
inductive StackAction where | stay | pop | push (bit : Bool) deriving DecidableEq
def StackAction.apply : StackAction → List Bool → List Bool | .stay, xs => xs | .pop, xs => xs.tail | .push b, xs => b :: xs
structure Instruction (k q : ℕ) where next : Option (Fin q) actions : Fin k → StackAction
def Instruction.halt (k q : ℕ) : Instruction k q := ⟨none, fun _ => .stay⟩
structure Machine where stackCount : ℕ states : ℕ initial : Fin states inputStack : Fin stackCount outputStack : Fin stackCount table : List (Instruction stackCount states)
structure Config (k q : ℕ) where state : Option (Fin q) «stacks» : Fin k → List Bool
def topCode : List Bool → ℕ | [] => 0 | false :: _ => 1 | true :: _ => 2
def headsCode : (k : ℕ) → (Fin k → List Bool) → ℕ | 0, _ => 0 | k + 1, s => topCode (s 0) + 3 * headsCode k (fun j => s j.succ)
def Machine.step (M : Machine) (c : Config M.stackCount M.states) : Config M.stackCount M.states := match c.state with | none => c | some q => let instruction := M.table.getD (3 ^ M.stackCount * q.val + headsCode M.stackCount c.stacks) (Instruction.halt M.stackCount M.states) ⟨instruction.next, fun j => (instruction.actions j).apply (c.stacks j)⟩
def Machine.init (M : Machine) (input : List Bool) : Config M.stackCount M.states := ⟨some M.initial, fun j => if j = M.inputStack then input else []⟩
def Machine.run (M : Machine) (input : List Bool) (fuel : ℕ) : Config M.stackCount M.states := (M.step^[fuel]) (M.init input)
def DeterministicRankOneSigning : Prop := ∃ M : Machine, ∃ C degree : ℕ, 0 < C ∧ ∀ x : Input, Admissible x → let result := M.run x.encode (C * (x.length + 1) ^ degree) result.state = none ∧ GoodOutput x (result.stacks M.outputStack)
end CurrentKS
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100import Mathlibimport OAI.Analysis.MatrixSigning.Optimization.Pencil
namespace OAI
open Matrix
namespace CurrentKS.RationalSDPopen Matrixopen scoped BigOperators
variable {n m p : ℕ}
lemma vector_eq_sum_single {R : Type*} [Semiring R] (x : Fin n → R) : x=∑ i : Fin n,x i • (Pi.single i 1 : Fin n → R) := by classical ext j simp [Pi.single_apply]
def Pencil.ofAffine (C : Matrix (Fin m) (Fin m) ℚ) (L : (Fin n → ℚ) →ₗ[ℚ] Matrix (Fin m) (Fin m) ℚ) (hC : C.IsSymm) (hL : ∀ y,(L y).IsSymm) : Pencil n m where constant := C coeff i := L (Pi.single i 1) symmetric_constant := hC symmetric_coeff index := hL (Pi.single index 1)
lemma Pencil.ofAffine_eval (C : Matrix (Fin m) (Fin m) ℚ) (L : (Fin n → ℚ) →ₗ[ℚ] Matrix (Fin m) (Fin m) ℚ) (hC : C.IsSymm) (hL : ∀ y,(L y).IsSymm) (y : Fin n → ℚ) : (Pencil.ofAffine C L hC hL).eval y=C+L y := by change C+∑ i,y i • L (Pi.single i 1)=C+L y congr 1 conv_rhs => rw [vector_eq_sum_single y] simp
def blockDiagonal {R : Type*} [Zero R] (A : Matrix (Fin m) (Fin m) R) (B : Matrix (Fin p) (Fin p) R) : Matrix (Fin (m+p)) (Fin (m+p)) R := (Matrix.fromBlocks A 0 0 B).submatrix finSumFinEquiv.symm finSumFinEquiv.symm
lemma blockDiagonal_symm {R : Type*} [AddMonoid R] (A : Matrix (Fin m) (Fin m) R) (B : Matrix (Fin p) (Fin p) R) (hA : A.IsSymm) (hB : B.IsSymm) : (blockDiagonal A B).IsSymm := (Matrix.IsSymm.fromBlocks hA (by simp) hB).submatrix _
lemma blockDiagonal_posSemidef (A : Matrix (Fin m) (Fin m) ℝ) (B : Matrix (Fin p) (Fin p) ℝ) : (blockDiagonal A B).PosSemidef ↔ A.PosSemidef ∧ B.PosSemidef := by let C := Matrix.fromBlocks A (0 : Matrix (Fin m) (Fin p) ℝ) 0 B have he : (blockDiagonal A B).PosSemidef ↔ C.PosSemidef := by constructor · intro h have hd := h.submatrix (fun i : Fin m ⊕ Fin p => finSumFinEquiv i) simp only [blockDiagonal,Matrix.submatrix_submatrix,Function.comp_def, Equiv.symm_apply_apply] at hd exact hd · exact fun h => h.submatrix _ rw [he] constructor · intro h exact ⟨h.submatrix (Sum.inl : Fin m → Fin m ⊕ Fin p),h.submatrix (Sum.inr : Fin p → Fin m ⊕ Fin p)⟩ · rintro ⟨hA,hB⟩ apply Matrix.posSemidef_iff_dotProduct_mulVec.mpr refine ⟨?_,?_⟩ · apply Matrix.isHermitian_fromBlocks_iff.mpr exact ⟨hA.isHermitian,by simp,by simp,hB.isHermitian⟩ · intro x have ha := hA.dotProduct_mulVec_nonneg (x ∘ Sum.inl) have hb := hB.dotProduct_mulVec_nonneg (x ∘ Sum.inr) simpa only [C,Matrix.fromBlocks_mulVec,Matrix.zero_mulVec,add_zero,zero_add, dotProduct,Fintype.sum_sum_type,Sum.elim_inl,Sum.elim_inr,Pi.star_apply, star_trivial,Function.comp_def] using add_nonneg ha hb
lemma blockDiagonal_realMap (A : Matrix (Fin m) (Fin m) ℚ) (B : Matrix (Fin p) (Fin p) ℚ) : (blockDiagonal A B).map (fun x => (x:ℝ)) = blockDiagonal (A.map (fun x => (x:ℝ))) (B.map (fun x => (x:ℝ))) := by ext i j change ((Matrix.fromBlocks A 0 0 B) (finSumFinEquiv.symm i) (finSumFinEquiv.symm j):ℝ)=_ change _=(Matrix.fromBlocks (A.map (fun x => (x:ℝ))) 0 0 (B.map (fun x => (x:ℝ)))) (finSumFinEquiv.symm i) (finSumFinEquiv.symm j) cases finSumFinEquiv.symm i <;> cases finSumFinEquiv.symm j <;> simp
def Pencil.blockDiagonal (A : Pencil n m) (B : Pencil n p) : Pencil n (m+p) where constant := CurrentKS.RationalSDP.blockDiagonal A.constant B.constant coeff i := CurrentKS.RationalSDP.blockDiagonal (A.coeff i) (B.coeff i) symmetric_constant := blockDiagonal_symm _ _ A.symmetric_constant B.symmetric_constant symmetric_coeff i := blockDiagonal_symm _ _ (A.symmetric_coeff i) (B.symmetric_coeff i)
lemma Pencil.blockDiagonal_realEval (A : Pencil n m) (B : Pencil n p) (z : Fin n → ℝ) : (A.blockDiagonal B).realEval z = CurrentKS.RationalSDP.blockDiagonal (A.realEval z) (B.realEval z) := by ext i j simp only [Pencil.realEval,Pencil.blockDiagonal,blockDiagonal_realMap, Matrix.add_apply,Matrix.sum_apply,Matrix.smul_apply,smul_eq_mul] cases hi : finSumFinEquiv.symm i <;> cases hj : finSumFinEquiv.symm j <;> simp [CurrentKS.RationalSDP.blockDiagonal,hi,hj,Matrix.sum_apply]
end CurrentKS.RationalSDP
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125import Mathlibimport OAI.Analysis.MatrixSigning.Optimization.ValueDimension
namespace OAI
open Matrix
namespace CurrentKS.RationalSDPopen Matrix CurrentKS.HermitianCoordinatesopen scoped BigOperators
variable {n m p d N : ℕ}
lemma Pencil.ofAffine_realEval (C : Matrix (Fin m) (Fin m) ℚ) (L : (Fin n → ℚ) →ₗ[ℚ] Matrix (Fin m) (Fin m) ℚ) (hC : C.IsSymm) (hL : ∀ y,(L y).IsSymm) (L' : (Fin n → ℝ) →ₗ[ℝ] Matrix (Fin m) (Fin m) ℝ) (hcast : ∀ y,(L y).map (fun q => (q:ℝ))=L' (fun i => (y i:ℝ))) (y : Fin n → ℝ) : (Pencil.ofAffine C L hC hL).realEval y=C.map (fun q => (q:ℝ))+L' y := by change _+∑ i,y i • (L (Pi.single i 1)).map (fun q => (q:ℝ))=_ simp_rw [hcast] have hs (i : Fin n) : (fun j => ((Pi.single i 1 : Fin n → ℚ) j:ℝ))=Pi.single i 1 := by ext j simp [Pi.single_apply,apply_ite] simp_rw [hs] congr 1 conv_rhs => rw [vector_eq_sum_single y] simp
lemma realFinDecode_cast (x : Fin d × Fin d → ℚ) : (realFinDecode d x).map (fun q => (q:ℝ))=realFinDecode d (fun i => (x i:ℝ)) := by change ((realDecode x).submatrix _ _).map _=(realDecode _).submatrix _ _ rw [← Matrix.submatrix_map,realDecode_ratCast]
lemma matrixVariable_cast (second : Bool) (v : Fin (valueDimension d) → ℚ) : (matrixVariable d second v).map (fun q => (q:ℝ))= matrixVariable d second (fun i => (v i:ℝ)) := by change (realFinDecode d _).map _=realFinDecode d _ rw [realFinDecode_cast] rfl
lemma cast_matrix_sum {ι : Type*} (s : Finset ι) (A : ι → Matrix (Fin m) (Fin m) ℚ) : (∑ i ∈ s,A i).map (fun q => (q:ℝ))=∑ i ∈ s,(A i).map (fun q => (q:ℝ)) := by ext i j simp [Matrix.sum_apply,Rat.cast_sum]lemma cast_matrix_smul (r : ℚ) (A : Matrix (Fin m) (Fin m) ℚ) : (r • A).map (fun q => (q:ℝ))=(r:ℝ) • A.map (fun q => (q:ℝ)) := by ext i j simp [Matrix.smul_apply]lemma cast_matrix_one : (1 : Matrix (Fin m) (Fin m) ℚ).map (fun q => (q:ℝ))=1 := by exact Matrix.map_one _ (by simp) (by simp)lemma cast_matrix_zero : (0 : Matrix (Fin m) (Fin m) ℚ).map (fun q => (q:ℝ))=0 := by ext i j simplemma cast_matrix_add (A B : Matrix (Fin m) (Fin m) ℚ) : (A+B).map (fun q => (q:ℝ))=A.map (fun q => (q:ℝ))+B.map (fun q => (q:ℝ)) := by ext i j simplemma cast_matrix_sub (A B : Matrix (Fin m) (Fin m) ℚ) : (A-B).map (fun q => (q:ℝ))=A.map (fun q => (q:ℝ))-B.map (fun q => (q:ℝ)) := by ext i j simplemma cast_matrix_neg (A : Matrix (Fin m) (Fin m) ℚ) : (-A).map (fun q => (q:ℝ))= -A.map (fun q => (q:ℝ)) := by ext i j simplemma cast_matrix_mul (A B : Matrix (Fin m) (Fin m) ℚ) : (A*B).map (fun q => (q:ℝ))=A.map (fun q => (q:ℝ))*B.map (fun q => (q:ℝ)) := by exact Matrix.map_mul (f := algebraMap ℚ ℝ)
lemma rationalSum_cast (coords : Fin N → Fin d × Fin d → ℚ) (x : Fin N → ℚ) : (rationalSum coords x).map (fun q => (q:ℝ))= rationalSum (fun i j => (coords i j:ℝ)) (fun i => (x i:ℝ)) := by simp only [rationalSum,cast_matrix_sum,cast_matrix_smul,realFinDecode_cast]
lemma rationalEta_cast (coords : Fin N → Fin d × Fin d → ℚ) (θ : Fin N → ℚ) (Z : Matrix (Fin (d+d)) (Fin (d+d)) ℚ) : (rationalEta coords θ Z).map (fun q => (q:ℝ))= rationalEta (fun i j => (coords i j:ℝ)) (fun i => (θ i:ℝ)) (Z.map (fun q => (q:ℝ))) := by simp only [rationalEta,LinearMap.sum_apply,LinearMap.smul_apply,cast_matrix_sum, cast_matrix_smul,sandwichLinear,LinearMap.coe_mk,AddHom.coe_mk,cast_matrix_mul, realFinDecode_cast,Rat.cast_mul,Rat.cast_ofNat]
lemma schurPencil_realEval (coords : Fin N → Fin d × Fin d → ℚ) (x θ : Fin N → ℚ) (second : Bool) (v : Fin (valueDimension d) → ℝ) : (schurPencil coords x θ second).realEval v = (Matrix.fromBlocks (timeCoordinate d v • (1 : Matrix (Fin (d+d)) (Fin (d+d)) ℝ)+ (if second then rationalSum (fun i j => (coords i j:ℝ)) (fun i => (x i:ℝ)) else -rationalSum (fun i j => (coords i j:ℝ)) (fun i => (x i:ℝ)))- rationalEta (fun i j => (coords i j:ℝ)) (fun i => (θ i:ℝ)) (matrixVariable d (!second) v)) 1 1 (matrixVariable d second v)).submatrix finSumFinEquiv.symm finSumFinEquiv.symm := by let L' := diagonalLinear (identityLinear (d+d) (timeCoordinate d)- (rationalEta (fun i j => (coords i j:ℝ)) (fun i => (θ i:ℝ))).comp (matrixVariable d (!second))) (matrixVariable d second) have hcast (y : Fin (valueDimension d) → ℚ) : (diagonalLinear (identityLinear (d+d) (timeCoordinate d)- (rationalEta coords θ).comp (matrixVariable d (!second))) (matrixVariable d second) y).map (fun q => (q:ℝ))=L' (fun i => (y i:ℝ)) := by change (blockDiagonal _ _).map _=blockDiagonal _ _ rw [blockDiagonal_realMap] congr 1 · change ((timeCoordinate d y : ℚ) • (1 : Matrix (Fin (d+d)) (Fin (d+d)) ℚ)-rationalEta coords θ _).map _=_ rw [cast_matrix_sub,cast_matrix_smul,cast_matrix_one,rationalEta_cast,matrixVariable_cast] rfl · exact matrixVariable_cast _ _ erw [schurPencil,Pencil.ofAffine_realEval _ _ _ _ L' hcast] have hS : ((if second then rationalSum coords x else -rationalSum coords x).map (fun q => (q:ℝ))) = if second then rationalSum (fun i j => (coords i j:ℝ)) (fun i => (x i:ℝ)) else -rationalSum (fun i j => (coords i j:ℝ)) (fun i => (x i:ℝ)) := by split <;> simp only [rationalSum_cast,cast_matrix_neg] ext i j cases hi : finSumFinEquiv.symm i <;> cases hj : finSumFinEquiv.symm j <;> simp [L',diagonalLinear,blockDiagonal,hi,hj,identityLinear,Matrix.add_apply,Matrix.sub_apply] · rename_i i' j' have hs := congrFun (congrFun hS i') j' change ((if second=true then rationalSum coords x else -rationalSum coords x) _ _ : ℝ)=_ at hs rw [hs] abel · simp [Matrix.one_apply,apply_ite] · simp [Matrix.one_apply,apply_ite]
end CurrentKS.RationalSDP
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091import Mathlibimport OAI.Analysis.MatrixSigning.Optimization.Pencil
namespace OAI
open Matrix
namespace CurrentKS.RationalSDPopen Matrixopen scoped BigOperators
variable {n m : ℕ}
def blockScalar {R : Type*} [Zero R] (A : Matrix (Fin m) (Fin m) R) (b : R) : Matrix (Fin (m+1)) (Fin (m+1)) R := (Matrix.fromBlocks A 0 0 (Matrix.of fun (_ _ : Fin 1) => b)).submatrix finSumFinEquiv.symm finSumFinEquiv.symm
lemma blockScalar_symm (A : Matrix (Fin m) (Fin m) ℚ) (hA : A.IsSymm) (b : ℚ) : (blockScalar A b).IsSymm := by exact (Matrix.IsSymm.fromBlocks hA (by simp) (by rfl)).submatrix _
lemma blockScalar_posSemidef (A : Matrix (Fin m) (Fin m) ℝ) (b : ℝ) : (blockScalar A b).PosSemidef ↔ A.PosSemidef ∧ 0 ≤ b := by let C := Matrix.fromBlocks A (0 : Matrix (Fin m) (Fin 1) ℝ) 0 (Matrix.of fun (_ _ : Fin 1) => b) have he : (blockScalar A b).PosSemidef ↔ C.PosSemidef := by constructor · intro h have hd := h.submatrix (fun i : Fin m ⊕ Fin 1 => finSumFinEquiv i) simp only [blockScalar,Matrix.submatrix_submatrix,Function.comp_def, Equiv.symm_apply_apply] at hd exact hd · exact fun h => h.submatrix _ rw [he] constructor · intro h have hA := h.submatrix (Sum.inl : Fin m → Fin m ⊕ Fin 1) have hb := h.submatrix (Sum.inr : Fin 1 → Fin m ⊕ Fin 1) refine ⟨by simp only [C,Matrix.submatrix,Matrix.fromBlocks_apply₁₁] at hA; exact hA,?_⟩ have hh := hb.diag_nonneg (i := (0 : Fin 1)) exact hh · rintro ⟨hA,hb⟩ apply Matrix.posSemidef_iff_dotProduct_mulVec.mpr refine ⟨?_,?_⟩ · apply Matrix.isHermitian_fromBlocks_iff.mpr exact ⟨hA.isHermitian,by simp,by simp,by ext i j; simp⟩ · intro x have hh := hA.dotProduct_mulVec_nonneg (x ∘ Sum.inl) simp only [dotProduct,Pi.star_apply,star_trivial,Function.comp_def] at hh change 0 ≤ ∑ i : Fin m, x (Sum.inl i)*(A *ᵥ (x ∘ Sum.inl)) i at hh have hs : 0 ≤ b*(x (Sum.inr 0))^2 := mul_nonneg hb (sq_nonneg _) simpa only [C,Matrix.fromBlocks_mulVec,Matrix.zero_mulVec,add_zero,zero_add, dotProduct, Fintype.sum_sum_type,Sum.elim_inl,Sum.elim_inr,Pi.star_apply,star_trivial, Function.comp_def,Matrix.mulVec,Fin.sum_univ_one,Matrix.fromBlocks_apply₁₁, Matrix.fromBlocks_apply₁₂,Matrix.fromBlocks_apply₂₁,Matrix.fromBlocks_apply₂₂, Matrix.zero_apply,Matrix.of_apply,zero_mul,Finset.sum_const_zero] using show 0 ≤ (∑ i : Fin m, x (Sum.inl i)*(A *ᵥ (x ∘ Sum.inl)) i)+ x (Sum.inr 0)*(b*x (Sum.inr 0)) by nlinarith
lemma blockScalar_realMap (A : Matrix (Fin m) (Fin m) ℚ) (b : ℚ) : (blockScalar A b).map (fun x => (x:ℝ)) = blockScalar (A.map (fun x => (x:ℝ))) (b:ℝ) := by ext i j change ((Matrix.fromBlocks A 0 0 (Matrix.of fun (_ _ : Fin 1) => b)) (finSumFinEquiv.symm i) (finSumFinEquiv.symm j) : ℝ) = _ change _ = (Matrix.fromBlocks (A.map (fun x => (x:ℝ))) 0 0 (Matrix.of fun (_ _ : Fin 1) => (b:ℝ))) (finSumFinEquiv.symm i) (finSumFinEquiv.symm j) cases finSumFinEquiv.symm i <;> cases finSumFinEquiv.symm j <;> simp
def Pencil.withLevel (B : Pencil n m) (f : Fin n → ℚ) (q : ℚ) : Pencil n (m+1) where constant := blockScalar B.constant q coeff i := blockScalar (B.coeff i) (-f i) symmetric_constant := blockScalar_symm _ B.symmetric_constant _ symmetric_coeff i := blockScalar_symm _ (B.symmetric_coeff i) _
lemma Pencil.withLevel_realEval (B : Pencil n m) (f : Fin n → ℚ) (q : ℚ) (z : Fin n → ℝ) : (B.withLevel f q).realEval z = blockScalar (B.realEval z) ((q:ℝ)-(fun i => (f i:ℝ)) ⬝ᵥ z) := by ext i j simp only [Pencil.realEval,Pencil.withLevel,blockScalar_realMap, Matrix.add_apply,Matrix.sum_apply,Matrix.smul_apply,smul_eq_mul] cases hi : finSumFinEquiv.symm i <;> cases hj : finSumFinEquiv.symm j <;> simp [blockScalar,hi,hj,Matrix.sum_apply,dotProduct,mul_comm,sub_eq_add_neg]
lemma Pencil.withLevel_feasible (B : Pencil n m) (f : Fin n → ℚ) (q : ℚ) (z : EuclideanSpace ℝ (Fin n)) : ((B.withLevel f q).realEval z).PosSemidef ↔ (B.realEval z).PosSemidef ∧ (fun i => (f i:ℝ)) ⬝ᵥ z ≤ (q:ℝ) := by rw [B.withLevel_realEval,blockScalar_posSemidef,sub_nonneg]end CurrentKS.RationalSDP
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778import Mathlibimport OAI.Analysis.MatrixSigning.Optimization.FinRealify
namespace OAI
open Matrix
namespace CurrentKS.RationalSDPopen Matrix CurrentKS.HermitianCoordinatesopen scoped BigOperators ComplexOrder
variable {d N : ℕ}
lemma scalar_one_psd_iff (r : ℝ) : (r • (1 : Matrix (Fin 1) (Fin 1) ℝ)).PosSemidef ↔ 0 ≤ r := by constructor · intro h simpa using h.diag_nonneg (i := (0 : Fin 1)) · intro hr exact (Matrix.PosSemidef.one : (1 : Matrix (Fin 1) (Fin 1) ℝ).PosSemidef).smul hr
lemma lowerMatrixPencil_psd (second : Bool) (v : Fin (valueDimension d) → ℝ) : ((lowerMatrixPencil d second).realEval v).PosSemidef ↔ (decode (matrixCoordinate d second v)-(1/400:ℝ) • (1 : Matrix (Fin d) (Fin d) ℂ)).PosSemidef := by rw [lowerMatrixPencil_realEval,← finRealify_psd] simp only [finRealify_sub,finRealify_smul,finRealify_one,finRealify_decode, matrixVariable,LinearMap.comp_apply]lemma upperMatrixPencil_psd (ε : ℚ) (second : Bool) (v : Fin (valueDimension d) → ℝ) : ((upperMatrixPencil d ε second).realEval v).PosSemidef ↔ ((200/(ε:ℝ)) • (1 : Matrix (Fin d) (Fin d) ℂ)- decode (matrixCoordinate d second v)).PosSemidef := by rw [upperMatrixPencil_realEval,← finRealify_psd] simp only [finRealify_sub,finRealify_smul,finRealify_one,finRealify_decode, matrixVariable,LinearMap.comp_apply]
def complexValueProgram (ε : ℝ) (S : Matrix (Fin d) (Fin d) ℂ) (η : Matrix (Fin d) (Fin d) ℂ → Matrix (Fin d) (Fin d) ℂ) (t : ℝ) (X Y : Matrix (Fin d) (Fin d) ℂ) : Prop := (Matrix.fromBlocks (t • (1 : Matrix (Fin d) (Fin d) ℂ)-S-η Y) 1 1 X).PosSemidef ∧ (Matrix.fromBlocks (t • (1 : Matrix (Fin d) (Fin d) ℂ)+S-η X) 1 1 Y).PosSemidef ∧ (X-(1/400:ℝ) • (1 : Matrix (Fin d) (Fin d) ℂ)).PosSemidef ∧ ((200/ε) • (1 : Matrix (Fin d) (Fin d) ℂ)-X).PosSemidef ∧ (Y-(1/400:ℝ) • (1 : Matrix (Fin d) (Fin d) ℂ)).PosSemidef ∧ ((200/ε) • (1 : Matrix (Fin d) (Fin d) ℂ)-Y).PosSemidef ∧ 0 ≤ t ∧ t ≤ 100
lemma valuePencil_psd (coords : Fin N → Fin d × Fin d → ℚ) (x θ : Fin N → ℚ) (ε : ℚ) (v : Fin (valueDimension d) → ℝ) : ((valuePencil coords x θ ε).realEval v).PosSemidef ↔ complexValueProgram (ε:ℝ) (complexSum (fun i j => (coords i j:ℝ)) (fun i => (x i:ℝ))) (complexEta (fun i j => (coords i j:ℝ)) (fun i => (θ i:ℝ))) (timeCoordinate d v) (decode (matrixCoordinate d false v)) (decode (matrixCoordinate d true v)) := by simp only [valuePencil,Pencil.blockDiagonal_realEval,blockDiagonal_posSemidef, schurPencil_psd,lowerMatrixPencil_psd,upperMatrixPencil_psd, lowerTimePencil_realEval,upperTimePencil_realEval,scalar_one_psd_iff, Bool.false_eq_true,ite_false,Bool.not_false,ite_true,Bool.not_true, complexValueProgram,sub_eq_add_neg] simp only [← sub_eq_add_neg,sub_nonneg] tauto
lemma trace_decode (x : Fin d × Fin d → ℝ) : (Matrix.trace (decode x)).re=∑ i,x (i,i) := by simp [Matrix.trace,decode]
lemma valueObjective_complex (ε : ℚ) (v : Fin (valueDimension d) → ℚ) : (valueObjective d ε v : ℝ)=timeCoordinate d (fun i => (v i:ℝ))+(ε:ℝ)* ((Matrix.trace (decode (matrixCoordinate d false (fun i => (v i:ℝ))))).re+ (Matrix.trace (decode (matrixCoordinate d true (fun i => (v i:ℝ))))).re) := by rw [valueObjective_apply] push_cast rw [trace_decode,trace_decode,← Finset.sum_add_distrib] rfl
end CurrentKS.RationalSDP
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148import Mathlibimport OAI.Analysis.MatrixSigning.Modelimport OAI.Analysis.MatrixSigning.Matrices.Spaceimport OAI.Analysis.MatrixSigning.Potential.Normalizer
namespace OAI
open Matrix
namespace CurrentKS.RationalInputopen scoped BigOperators ComplexOrderopen CurrentKS.Hermitian CurrentKS.HermitianCoordinates
def coordinates (x : Input) (i : Fin x.N) : Fin x.d × Fin x.d → ℚ := fun p => if p.1 ≤ p.2 then (x.entries i p.1 p.2).1.value else (x.entries i p.2 p.1).2.value
def trace (x : Input) (i : Fin x.N) : ℚ := ∑ j,(x.entries i j j).1.value
def orientation (x : Input) (i : Fin x.N) : ℚ := if 0 ≤ trace x i then 1 else -1
def scale (x : Input) : ℚ := ∑ i,|trace x i|
def indices (x : Input) : List (Fin x.N) := (List.finRange x.N).filter (fun i => decide (trace x i ≠ 0))
def index (x : Input) : Fin (indices x).length → Fin x.N := (indices x).get
def normalizedCoordinates (x : Input) (j : Fin (indices x).length) : Fin x.d × Fin x.d → ℚ := (scale x)⁻¹ • (orientation x (index x j) • coordinates x (index x j))
lemma index_injective (x : Input) : Function.Injective (index x) := ((List.nodup_finRange x.N).filter _).injective_get
lemma index_range (x : Input) (i : Fin x.N) : (∃ j,index x j=i) ↔ trace x i ≠ 0 := by change (∃ j,(indices x).get j=i) ↔ _ rw [← List.mem_iff_get] simp [indices]
lemma index_trace_ne (x : Input) (j : Fin (indices x).length) : trace x (index x j) ≠ 0 := (index_range x _).mp ⟨j,rfl⟩
lemma indices_length_le (x : Input) : (indices x).length ≤ x.N := by have hh := List.length_filter_le (fun i => decide (trace x i ≠ 0)) (List.finRange x.N) simp only [List.length_finRange] at hh exact hh
noncomputable section
lemma trace_cast (x : Input) (i : Fin x.N) : (trace x i : ℝ)=CurrentKS.realTrace (x.matrix i) := by simp [trace,CurrentKS.realTrace,Matrix.trace,Matrix.diag,Input.matrix,toComplex]
lemma orientation_cast (x : Input) (i : Fin x.N) : (orientation x i : ℝ)=traceSign (x.matrix i) := by have hh : 0 ≤ trace x i ↔ (0:ℝ) ≤ CurrentKS.realTrace (x.matrix i) := by rw [←trace_cast];exact_mod_cast Iff.rfl simp only [orientation,traceSign,hh] split_ifs <;> norm_num
lemma scale_cast (x : Input) : (scale x : ℝ)=normalizer x.matrix := by simp [scale,normalizer,←trace_cast]
lemma coordinates_cast (x : Input) (hx : Admissible x) (i : Fin x.N) : (fun p => (coordinates x i p:ℝ))=HermitianCoordinates.encode ⟨x.matrix i,(hx i).1⟩ := by funext p simp only [coordinates,HermitianCoordinates.encode,Input.matrix,Matrix.map_apply,toComplex] split_ifs <;> rfl
lemma decode_coordinates (x : Input) (hx : Admissible x) (i : Fin x.N) : decode (fun p => (coordinates x i p:ℝ))=x.matrix i := by rw [coordinates_cast x hx i] exact congrArg Subtype.val (assemble_extract (⟨x.matrix i,(hx i).1⟩ : H x.d))
lemma trace_zero_iff (x : Input) (hx : Admissible x) (i : Fin x.N) : trace x i=0 ↔ x.matrix i=0 := by rw [← realTrace_eq_zero_iff (x.matrix i) (hx i).1 (hx i).2,←trace_cast] exact_mod_cast Iff.rfl
lemma scale_pos (x : Input) (hne : (indices x).length ≠ 0) : 0 < scale x := by have hl : 0 < (indices x).length := Nat.pos_of_ne_zero hne let j : Fin (indices x).length := ⟨0,hl⟩ exact Finset.sum_pos' (fun i _ => abs_nonneg _) ⟨index x j,Finset.mem_univ _, abs_pos.mpr (index_trace_ne x j)⟩
lemma dimension_ne (x : Input) (hx : Admissible x) (hne : (indices x).length ≠ 0) : x.d ≠ 0 := by intro hd let i := index x ⟨0,Nat.pos_of_ne_zero hne⟩ have hz : x.matrix i=0 := by ext j k have hj := j.isLt omega exact index_trace_ne x _ ((trace_zero_iff x hx i).mpr hz)
lemma decode_normalizedCoordinates (x : Input) (hx : Admissible x) (j : Fin (indices x).length) : decode (fun p => (normalizedCoordinates x j p:ℝ))=normalizedMatrix x.matrix (index x j) := by have he : (fun p => (normalizedCoordinates x j p:ℝ))= (scale x:ℝ)⁻¹ • ((orientation x (index x j):ℝ) • (fun p => (coordinates x (index x j) p:ℝ))) := by funext p simp [normalizedCoordinates] rw [he,decode_smul,decode_smul,decode_coordinates x hx,scale_cast,orientation_cast] rfl
lemma normalized_input_properties (x : Input) (hx : Admissible x) (hne : (indices x).length ≠ 0) : let A := fun j => assemble (WithLp.toLp 2 fun p => (normalizedCoordinates x j p:ℝ)) (∀ j,A j∈psdCone x.d) ∧ (∀ j,A j≠0) ∧ (∀ j,(A j:Mat x.d).rank ≤ 1) ∧ (∑ j,Hermitian.realTrace (A j))=1 := by let A := fun j => assemble (WithLp.toLp 2 fun p => (normalizedCoordinates x j p:ℝ)) have hA (j) : (A j:Mat x.d)=normalizedMatrix x.matrix (index x j) := decode_normalizedCoordinates x hx j have hD : normalizer x.matrix ≠ 0 := by rw [←scale_cast] exact_mod_cast (scale_pos x hne).ne' refine ⟨?_,?_,?_,?_⟩ · intro j change (A j:Mat x.d).PosSemidef rw [hA] exact normalizedMatrix_posSemidef x.matrix (fun i => (hx i).1) (fun i => (hx i).2) _ · intro j hj change A j=0 at hj have hz : normalizedMatrix x.matrix (index x j)=0 := by rw [←hA j,hj];rfl exact index_trace_ne x j ((trace_zero_iff x hx _).mpr ((normalizedMatrix_eq_zero_iff x.matrix hD _).mp hz)) · intro j rw [hA] exact normalizedMatrix_rank x.matrix (fun i => (hx i).2) _ · change (∑ j,Hermitian.realTrace (A j))=1 have he : (∑ j,CurrentKS.realTrace (normalizedMatrix x.matrix (index x j)))= ∑ i,CurrentKS.realTrace (normalizedMatrix x.matrix i) := by apply Fintype.sum_of_injective (index x) (index_injective x) · intro i hi have hz : trace x i=0 := by by_contra hz exact hi ((index_range x i).mpr hz) have hm := (trace_zero_iff x hx i).mp hz rw [(normalizedMatrix_eq_zero_iff x.matrix hD i).mpr hm] simp [CurrentKS.realTrace] · intro j;rfl have ht := normalized_trace_sum x.matrix hD rw [←he] at ht convert ht using 1 apply Finset.sum_congr rfl intro j _ change CurrentKS.realTrace (A j:Mat x.d)=_ rw [hA]
endend CurrentKS.RationalInput
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.EliminationCallBoundsimport OAI.Analysis.MatrixSigning.Machines.CommonDenominatorLiftimport OAI.Analysis.MatrixSigning.Optimization.TerminalWitnessBounds
namespace OAI
section
namespace KS.W17
open KS.W07
def CommonHeight {n : ℕ} (y : Fin n → ℚ) (E : ℕ) : Prop := ∃ D : ℕ, 0 < D ∧ D ≤ 2 ^ E ∧ ∃ Z : Fin n → ℤ, (∀ i, y i = (Z i : ℚ) / D) ∧ ∀ i, (Z i).natAbs ≤ 2 ^ E
theorem CommonHeight.mono {n E F : ℕ} {y : Fin n → ℚ} (h : CommonHeight y E) (hEF : E ≤ F) : CommonHeight y F := by obtain ⟨D, hD, hDb, Z, hy, hZ⟩ := h have hp := Nat.pow_le_pow_right (by decide : 0 < 2) hEF exact ⟨D, hD, hDb.trans hp, Z, hy, fun i => (hZ i).trans hp⟩
theorem CommonHeight.parts_bound {n E : ℕ} {y : Fin n → ℚ} (h : CommonHeight y E) (i : Fin n) : (y i).num.natAbs ≤ 2 ^ E ∧ (y i).den ≤ 2 ^ E := by obtain ⟨D, hD, hDb, Z, hy, hZ⟩ := h have hd : (D : ℤ) ≠ 0 := Int.natCast_ne_zero.mpr (Nat.ne_of_gt hD) have he : y i = Rat.divInt (Z i) (D : ℤ) := by rw [Rat.divInt_eq_div, Int.cast_natCast] exact hy i rw [he] exact ⟨(KS.W30.divInt_num_natAbs_le _ _ hd).trans (hZ i), (KS.W30.divInt_den_le _ _ hd).trans (by simpa using hDb)⟩
theorem commonHeight_single {n : ℕ} (i : Fin n) : CommonHeight (Pi.single i (1 : ℚ)) 0 := by refine ⟨1, by decide, by simp, Pi.single i 1, ?_, ?_⟩ · intro j by_cases hj : j = i <;> simp [hj] · intro j by_cases hj : j = i <;> simp [hj]
theorem CommonHeight.cons_zero {n E : ℕ} {y : Fin n → ℚ} (h : CommonHeight y E) : CommonHeight (Fin.cons 0 y) E := by obtain ⟨D, hD, hDb, Z, hy, hZ⟩ := h refine ⟨D, hD, hDb, Fin.cons 0 Z, ?_, ?_⟩ · intro i exact Fin.cases (by simp) (fun j => by simpa using hy j) i · intro i exact Fin.cases (by simp) (fun j => by simpa using hZ j) i
theorem schurWitnessLift_eq_prependLinear {n : ℕ} (M : Matrix (Fin (n + 1)) (Fin (n + 1)) ℚ) (y : Fin n → ℚ) : schurWitnessLift M y = KS.W30.prependLinear (fun j => -(M 0 j.succ / M 0 0)) y := by unfold schurWitnessLift KS.W30.prependLinear apply congrArg (fun z : ℚ => (Fin.cons z y : Fin (n + 1) → ℚ)) calc -(∑ j, M 0 j.succ * y j) / M 0 0 = ∑ j, -(M 0 j.succ * y j) / M 0 0 := by simp_rw [div_eq_mul_inv] rw [← Finset.sum_neg_distrib, Finset.sum_mul] _ = ∑ j, -(M 0 j.succ / M 0 0) * y j := by apply Finset.sum_congr rfl intro j _ ring
theorem DenseEliminationCall.lift_coefficient_parts {N t : ℕ} {A : DenseRatMatrix N} {S : DenseRatMatrix (t + 1)} (h : DenseEliminationCall A S) (b : ℕ) (hnum : ∀ i j, (DenseRatMatrix.decode A i j).num.natAbs ≤ 2 ^ b) (hden : ∀ i j, (DenseRatMatrix.decode A i j).den ≤ 2 ^ b) (j : Fin t) : let c := -(DenseRatMatrix.decode S 0 j.succ / DenseRatMatrix.decode S 0 0) c.num.natAbs ≤ 2 ^ (2 * KS.W30.inverseBitBound N b) ∧ c.den ≤ 2 ^ (2 * KS.W30.inverseBitBound N b) := by have hp := h.entry_parts_size_le b hnum hden 0 0 have hr := h.entry_parts_size_le b hnum hden 0 j.succ have hd := KS.W30.div_parts_le_two_pow _ _ (KS.W30.inverseBitBound N b) (KS.W30.inverseBitBound N b) (Nat.le_of_lt (Nat.size_le.mp hr.1)) (Nat.le_of_lt (Nat.size_le.mp hr.2)) (Nat.le_of_lt (Nat.size_le.mp hp.1)) (Nat.le_of_lt (Nat.size_le.mp hp.2)) simpa [Rat.num_neg_eq_neg_num, Rat.den_neg_eq_den, Int.natAbs_neg, two_mul] using hd
theorem CommonHeight.schurWitnessLift {n E H : ℕ} (M : Matrix (Fin (n + 1)) (Fin (n + 1)) ℚ) {y : Fin n → ℚ} (hy : CommonHeight y E) (hcnum : ∀ j : Fin n, (-(M 0 j.succ / M 0 0)).num.natAbs ≤ 2 ^ H) (hcden : ∀ j : Fin n, (-(M 0 j.succ / M 0 0)).den ≤ 2 ^ H) : CommonHeight (schurWitnessLift M y) (E + (n + 1) * H + n + 1) := by obtain ⟨D, hD, hDb, Z, hy, hZ⟩ := hy rw [schurWitnessLift_eq_prependLinear] exact KS.W30.prependLinear_common_height _ y H E hcnum hcden D hD hDb Z hy hZ
def witnessHeightBudget (N b t : ℕ) : ℕ := (t + 1) * ((N + 2) * (3 * KS.W30.inverseBitBound N b + 4))
theorem DenseEliminationCall.dimension_le {N t : ℕ} {A : DenseRatMatrix N} {S : DenseRatMatrix t} (h : DenseEliminationCall A S) : t ≤ N := by obtain ⟨k, p, r, hp⟩ := h.pivotTrace have hs := hp.size_bound omega
theorem denseNegativeWitness_commonHeight {N t : ℕ} (A : DenseRatMatrix N) (b : ℕ) (hnum : ∀ i j, (DenseRatMatrix.decode A i j).num.natAbs ≤ 2 ^ b) (hden : ∀ i j, (DenseRatMatrix.decode A i j).den ≤ 2 ^ b) (S : DenseRatMatrix t) (hcall : DenseEliminationCall A S) (y : Vector ℚ t) (hout : denseNegativeWitness t S = some y) : CommonHeight (decodeRatVector y) (witnessHeightBudget N b t) := by let H := KS.W30.inverseBitBound N b let K := (N + 2) * (3 * H + 4) have hK : 3 * H + 3 ≤ K := by dsimp [K]; nlinarith change CommonHeight (decodeRatVector y) ((t + 1) * K) induction t with | zero => simp [denseNegativeWitness] at hout | succ t ih => let M := DenseRatMatrix.decode S have hentry : ∀ i j, (M i j).num.natAbs ≤ 2 ^ H ∧ (M i j).den ≤ 2 ^ H := by intro i j have hb := hcall.entry_parts_size_le b hnum hden i j exact ⟨Nat.le_of_lt (Nat.size_le.mp hb.1), Nat.le_of_lt (Nat.size_le.mp hb.2)⟩ by_cases hn : M 0 0 < 0 · have he : y = Vector.ofFn (Pi.single 0 (1 : ℚ)) := by simpa [denseNegativeWitness, M, hn] using hout.symm subst y simpa using (commonHeight_single (0 : Fin (t + 1))).mono (Nat.zero_le ((t + 2) * K)) · by_cases hz : M 0 0 = 0 · cases hf : firstNonzeroOffDiagonal M with | some j => have he : y = Vector.ofFn (zeroPivotWitness M 0 j.succ) := by simpa [denseNegativeWitness, M, hn, hz, hf] using hout.symm subst y have hq := hentry j.succ j.succ have hr := hentry 0 j.succ have hc : CommonHeight (zeroPivotWitness M 0 j.succ) (3 * H + 3) := by exact KS.W30.zeroPivot_pair_common_height 0 j.succ (Fin.succ_ne_zero j).symm (M j.succ j.succ) (M 0 j.succ) H hq.1 hq.2 hr.1 hr.2 simpa using hc.mono (show 3 * H + 3 ≤ (t + 2) * K by nlinarith) | none => let T := DenseRatMatrix.ofMatrix (trailingMatrix M) have ht : DenseEliminationCall A T := DenseEliminationCall.zero hcall hz hf rw [denseNegativeWitness_zero_recurse S hz hf] at hout change (denseNegativeWitness t T).map (fun z => Vector.ofFn (Fin.cons 0 (decodeRatVector z))) = some y at hout cases ho : denseNegativeWitness t T with | none => simp [ho] at hout | some z => have he : y = Vector.ofFn (Fin.cons 0 (decodeRatVector z)) := by simpa [ho] using hout.symm subst y have hc := (ih T ht z ho).cons_zero simpa using hc.mono (show (t + 1) * K ≤ (t + 2) * K by nlinarith) · have hp : 0 < M 0 0 := lt_of_le_of_ne (not_lt.mp hn) (Ne.symm hz) let T := DenseRatMatrix.ofMatrix (schurTail M) have ht : DenseEliminationCall A T := DenseEliminationCall.positive hcall hp rw [denseNegativeWitness_positive_recurse S hp] at hout change (denseNegativeWitness t T).map (fun z => Vector.ofFn (schurWitnessLift M (decodeRatVector z))) = some y at hout cases ho : denseNegativeWitness t T with | none => simp [ho] at hout | some z => have he : y = Vector.ofFn (schurWitnessLift M (decodeRatVector z)) := by simpa [ho] using hout.symm subst y have hc := CommonHeight.schurWitnessLift M (ih T ht z ho) (fun j => (hcall.lift_coefficient_parts b hnum hden j).1) (fun j => (hcall.lift_coefficient_parts b hnum hden j).2) have hdim := hcall.dimension_le have hinc : (t + 1) * (2 * H) + t + 1 ≤ K := by have hmul := Nat.mul_le_mul (show t + 1 ≤ N + 2 by omega) (show 2 * H + 1 ≤ 3 * H + 4 by omega) dsimp [K] nlinarith simpa [H] using hc.mono (show (t + 1) * K + (t + 1) * (2 * H) + t + 1 ≤ (t + 2) * K by nlinarith)
theorem denseNegativeWitness_output_parts {N : ℕ} (A : DenseRatMatrix N) (b : ℕ) (hnum : ∀ i j, (DenseRatMatrix.decode A i j).num.natAbs ≤ 2 ^ b) (hden : ∀ i j, (DenseRatMatrix.decode A i j).den ≤ 2 ^ b) (y : Vector ℚ N) (hout : denseNegativeWitness N A = some y) (i : Fin N) : Nat.size (decodeRatVector y i).num.natAbs ≤ witnessHeightBudget N b N + 1 ∧ Nat.size (decodeRatVector y i).den ≤ witnessHeightBudget N b N + 1 := by have h := (denseNegativeWitness_commonHeight A b hnum hden A DenseEliminationCall.initial y hout).parts_bound i have hp : 2 ^ witnessHeightBudget N b N < 2 ^ (witnessHeightBudget N b N + 1) := by rw [pow_succ] have hpos : 0 < 2 ^ witnessHeightBudget N b N := pow_pos (by decide) _ omega exact ⟨Nat.size_le.mpr (h.1.trans_lt hp), Nat.size_le.mpr (h.2.trans_lt hp)⟩
end KS.W17
end
end OAI12345678910111213141516171819202122import Mathlib
namespace OAI
open Matrix
namespace CurrentKS.KKTnoncomputable sectionvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
lemma equiv_symmetric_of_map_eq (L : E ≃L[ℝ] E) (F : E →L[ℝ] E) (he : L.toContinuousLinearMap = F) (hF : F.toLinearMap.IsSymmetric) : L.toLinearEquiv.toLinearMap.IsSymmetric := by intro u v change inner ℝ (L.toContinuousLinearMap u) v = inner ℝ u (L.toContinuousLinearMap v) rw [he] exact hF u v
endend CurrentKS.KKT
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164import Mathlibimport OAI.Analysis.MatrixSigning.Potential.C1Rationalimport OAI.Analysis.MatrixSigning.Potential.Parameters2import OAI.Analysis.MatrixSigning.Potential.FaceState
namespace OAI
open Matrix
namespace CurrentKS.RationalFaceopen CurrentKS.RationalSDP CurrentKS.Schedule CurrentKS.Difference CurrentKS.Descent
variable {d N : ℕ}
def faceStencil (coords : Fin N → Fin d × Fin d → ℚ) (base : Fin N → ℚ) (ν lam : ℚ) : (Fin (activeIndices base).length → ℚ) → ℚ := fun y => faceQuery coords base y ν lam (parameters d (activeIndices base).length ν lam).stencilError
def faceScore (coords : Fin N → Fin d × Fin d → ℚ) (base : Fin N → ℚ) (ν lam : ℚ) : (Fin (activeIndices base).length → ℚ) → ℚ := fun y => faceQuery coords base y ν lam (parameters d (activeIndices base).length ν lam).selectionError
def faceCandidates (coords : Fin N → Fin d × Fin d → ℚ) (base : Fin N → ℚ) (ν lam : ℚ) [NeZero (activeIndices base).length] : List (Fin (activeIndices base).length → ℚ) := let p := parameters d (activeIndices base).length ν lam allCandidates (faceStencil coords base ν lam) (faceState base) p.h p.a p.M p.s p.ρ
def faceChoice (coords : Fin N → Fin d × Fin d → ℚ) (base : Fin N → ℚ) (ν lam : ℚ) [NeZero (activeIndices base).length] : Fin (activeIndices base).length → ℚ := select (faceScore coords base ν lam) (faceState base) (faceCandidates coords base ν lam)
noncomputable sectionopen CurrentKS.Hermitian CurrentKS.State CurrentKS.Variational CurrentKS.Scalaropen scoped BigOperators MatrixOrder Matrix.Norms.Frobenius ContDiff
lemma faceCandidates_cube [NeZero d] (coords : Fin N → Fin d × Fin d → ℚ) (base : Fin N → ℚ) [NeZero (activeIndices base).length] {ν lam : ℚ} (hν : 0 < ν) (hν1 : ν ≤ 1) (hlam : 0 < lam) (hlam1 : lam ≤ 1) (hx : ∀ i,|faceState base i| ≤ 1-lam^2/ν) : ∀ y∈faceCandidates coords base ν lam, ∀ i,|y i| ≤ 1 := by let p := parameters d (activeIndices base).length ν lam have hp : p.Valid (activeIndices base).length := parameters_valid (NeZero.pos d) (NeZero.pos _) hν hν1 hlam hlam1 exact allCandidates_cube _ _ _ _ _ _ _ p.σ hp.threshold_pos hp.threshold_le hp.bound_one hp.step_pos.le hp.mesh_pos hp.mesh_error (by linarith [hp.step_strip,hp.strip_pos]) hp.strip_pos.le hx
lemma faceStencil_correct [NeZero d] (coords : Fin N → Fin d × Fin d → ℚ) (base : Fin N → ℚ) [NeZero (activeIndices base).length] (hA : ∀ i,rationalAtoms coords i∈psdCone d) (htr : ∑ i,Hermitian.realTrace (rationalAtoms coords i)=1) {ν lam : ℚ} (hν : 0 < ν) (hν1 : ν ≤ 1) (hlam : 0 < lam) (hlam1 : lam ≤ 1) (hvar : (∑ i,sandwich (rationalAtoms coords i) (Hermitian.one : H d)) ≤ (ν:ℝ) • (Hermitian.one : H d)) (hb : ∀ i,|base i| ≤ 1) (hx : ∀ i,|faceState base i| ≤ 1-lam^2/ν) : let p := parameters d (activeIndices base).length ν lam ∀ y,‖pointCast y-pointCast (faceState base)‖ ≤ 2*(p.h:ℝ) → |(faceStencil coords base ν lam y:ℝ)-activePotential coords base ν lam (pointCast y)| ≤ (p.a:ℝ)*(p.h:ℝ)^2/(128*(activeIndices base).length) := by let p := parameters d (activeIndices base).length ν lam have hp : p.Valid (activeIndices base).length := parameters_valid (NeZero.pos d) (NeZero.pos _) hν hν1 hlam hlam1 dsimp only intro y hy have hyc := nearby_rational_cube (faceState base) y (r:=2*p.h) (σ:=p.σ) (by linarith [hp.stencil_pos]) hx (by simpa only [Rat.cast_mul,Rat.cast_ofNat] using hy) (by linarith [hp.stencil_strip,hp.strip_pos]) have hq := activeQuery_correct coords base y hA htr hν hν1 hlam.le hp.stencilError_pos hp.stencilError_le hvar hb hyc apply hq.trans_eq simp only [p,parameters,Rat.cast_div,Rat.cast_mul,Rat.cast_pow,Rat.cast_ofNat,Rat.cast_natCast]
lemma faceCandidates_progress [NeZero d] (coords : Fin N → Fin d × Fin d → ℚ) (base : Fin N → ℚ) [NeZero (activeIndices base).length] (hA : ∀ i,rationalAtoms coords i∈psdCone d) (hA0 : ∀ i,rationalAtoms coords i≠0) (hrank : ∀ i,(rationalAtoms coords i : Mat d).rank ≤ 1) (htr : ∑ i,Hermitian.realTrace (rationalAtoms coords i)=1) {ν lam : ℚ} (hν : 0 < ν) (hν1 : ν ≤ 1) (hlam : 0 < lam) (hlam1 : lam ≤ 1) (hvar : (∑ i,sandwich (rationalAtoms coords i) (Hermitian.one : H d)) ≤ (ν:ℝ) • (Hermitian.one : H d)) (hb : ∀ i,|base i| ≤ 1) (hx : ∀ i,|faceState base i| ≤ 1-lam^2/ν) : let p := parameters d (activeIndices base).length ν lam ∃ y∈faceCandidates coords base ν lam, activePotential coords base ν lam (pointCast y) ≤ activePotential coords base ν lam (pointCast (faceState base))-2*(p.a:ℝ)*(p.s:ℝ)^2 := by let p := parameters d (activeIndices base).length ν lam have hp : p.Valid (activeIndices base).length := parameters_valid (NeZero.pos d) (NeZero.pos _) hν hν1 hlam hlam1 have hepd : p.ε*(d:ℚ) ≤ 1 := (epsilon_spec (d:=d) hν hν1).2.2 have hbr : Cube (fun i => (base i:ℝ)) := fun i => (show |(base i:ℝ)| ≤ 1 by exact_mod_cast hb i) have hxc : Cube (pointCast (faceState base)) := by intro i change |(base (activeIndex base i):ℝ)| ≤ 1 exact_mod_cast hb (activeIndex base i) have hord := face_order_bounds (activeIndex base) (activeIndex_injective base) (fun i => (base i:ℝ)) (rationalAtoms coords) hA htr hbr _ hxc have hη := face_eta_one_bound (activeIndex base) (activeIndex_injective base) (fun i => (base i:ℝ)) (rationalAtoms coords) (variance_le_one _ hν1 hvar) hbr (real_active_outside_endpoint base hb) _ hxc have hregular := activePotential_regular (lam:=lam) coords base hA htr hν hν1 hp.strip_pos hvar hb hx (show (0:ℝ) ≤ (p.s+2*p.h:ℚ) by exact_mod_cast (show (0:ℚ) ≤ p.s+2*p.h by linarith [hp.step_pos,hp.stencil_pos])) (show ((p.s+2*p.h:ℚ):ℝ) ≤ (p.σ:ℝ)/2 by exact_mod_cast hp.radius) have hreg : ∀ y,‖y-pointCast (faceState base)‖ ≤ (p.s:ℝ)+2*(p.h:ℝ) → ContDiffAt ℝ 3 (activePotential coords base ν lam) y := by intro y hy exact (hregular y (by simpa only [Rat.cast_add,Rat.cast_mul,Rat.cast_ofNat] using hy)).1 have hders : ∀ y,‖y-pointCast (faceState base)‖ ≤ (p.s:ℝ)+2*(p.h:ℝ) → ∀ u,‖u‖ ≤ 1 → |iteratedDeriv 2 (fun t : ℝ => activePotential coords base ν lam (y+t • u)) 0| ≤ (p.M:ℝ) ∧ |iteratedDeriv 3 (fun t : ℝ => activePotential coords base ν lam (y+t • u)) 0| ≤ (p.M:ℝ) := by intro y hy exact (hregular y (by simpa only [Rat.cast_add,Rat.cast_mul,Rat.cast_ofNat] using hy)).2 exact face_candidates_progress (fun j => rationalAtoms coords (activeIndex base j)) (fixedPart (activeIndex base) (fun i => (base i:ℝ)) (rationalAtoms coords)) (faceState base) (faceStencil coords base ν lam) p.ε lam p.σ p.h p.a p.M p.s p.ρ hp.epsilon_pos hp.epsilon_le hepd hlam hp.strip_pos hx (fun j => hA _) (fun j => hA0 _) (fun j => hrank _) hord.1 hord.2 hη rfl hp.threshold_pos hp.threshold_le hp.bound_one hp.step_pos hp.step_le hp.step_strip hp.step_curvature hp.stencil_pos hp.stencil_le hp.stencil_curvature hp.mesh_pos hp.mesh_error hreg hders (faceStencil_correct coords base hA htr hν hν1 hlam hlam1 hvar hb hx)
theorem faceChoice_spec [NeZero d] (coords : Fin N → Fin d × Fin d → ℚ) (base : Fin N → ℚ) [NeZero (activeIndices base).length] (hA : ∀ i,rationalAtoms coords i∈psdCone d) (hA0 : ∀ i,rationalAtoms coords i≠0) (hrank : ∀ i,(rationalAtoms coords i : Mat d).rank ≤ 1) (htr : ∑ i,Hermitian.realTrace (rationalAtoms coords i)=1) {ν lam : ℚ} (hν : 0 < ν) (hν1 : ν ≤ 1) (hlam : 0 < lam) (hlam1 : lam ≤ 1) (hvar : (∑ i,sandwich (rationalAtoms coords i) (Hermitian.one : H d)) ≤ (ν:ℝ) • (Hermitian.one : H d)) (hb : ∀ i,|base i| ≤ 1) (hx : ∀ i,|faceState base i| ≤ 1-lam^2/ν) : let p := parameters d (activeIndices base).length ν lam (∀ i,|faceChoice coords base ν lam i| ≤ 1) ∧ activePotential coords base ν lam (pointCast (faceChoice coords base ν lam)) ≤ activePotential coords base ν lam (pointCast (faceState base))- 3*((p.a:ℝ)*(p.s:ℝ)^2)/2 := by let p := parameters d (activeIndices base).length ν lam have hp : p.Valid (activeIndices base).length := parameters_valid (NeZero.pos d) (NeZero.pos _) hν hν1 hlam hlam1 have hcube : ∀ y∈faceState base::faceCandidates coords base ν lam,∀ i,|y i| ≤ 1 := by intro y hy rcases List.mem_cons.mp hy with rfl|hy · exact fun i => hb (activeIndex base i) · exact faceCandidates_cube coords base hν hν1 hlam hlam1 hx y hy have herr : ∀ y∈faceState base::faceCandidates coords base ν lam, |(faceScore coords base ν lam y:ℝ)-activePotential coords base ν lam (pointCast y)| ≤ ((p.a:ℝ)*(p.s:ℝ)^2)/4 := by intro y hy have hq := activeQuery_correct coords base y hA htr hν hν1 hlam.le hp.selectionError_pos hp.selectionError_le hvar hb (hcube y hy) apply hq.trans_eq simp only [p,parameters,Rat.cast_div,Rat.cast_mul,Rat.cast_pow,Rat.cast_ofNat] have hprog := faceCandidates_progress coords base hA hA0 hrank htr hν hν1 hlam hlam1 hvar hb hx refine ⟨hcube _ (select_mem _ _ _),?_⟩ apply select_decrease (fun y => activePotential coords base ν lam (pointCast y)) (faceScore coords base ν lam) (faceState base) (faceState base) _ herr obtain ⟨y,hy,hd⟩ := hprog refine ⟨y,List.mem_cons_of_mem _ hy,?_⟩ nlinarith
endend CurrentKS.RationalFace
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889import Mathlibimport OAI.Analysis.MatrixSigning.Optimization.RealVector
namespace OAI
open Matrix
namespace CurrentKS.RationalSDPopen scoped BigOperators RealInnerProductSpaceopen Set
variable {n m : ℕ}
noncomputable def Pencil.feasible (B : Pencil n m) : Set (EuclideanSpace ℝ (Fin n)) := {z | (B.realEval z).PosSemidef}
lemma Pencil.next_eq_self (B : Pencil n m) (step mesh : ℚ) (y : Fin n → ℚ) (hy : B.witness y=none) : B.next step mesh y=y := by simp [Pencil.next,hy]
lemma Pencil.next_decrease (B : Pencil n m) (step mesh : ℚ) (y : Fin n → ℚ) (c : EuclideanSpace ℝ (Fin n)) {r R : ℝ} (hr : 0 < r) (hR : 0 ≤ R) (hmesh : 0 < mesh) (hstep : (step : ℝ)=r/(n+1)) (hball : Metric.closedBall c r ⊆ B.feasible) (hsmall : 2*(R+step)*((n+1)*mesh)+((n+1)*mesh)^2 ≤ (step : ℝ)^2/2) (hy : ‖realVector y-c‖ ≤ R) (hfail : B.witness y ≠ none) : ‖realVector (B.next step mesh y)-c‖^2 ≤ ‖realVector y-c‖^2-(step : ℝ)^2/2 := by obtain ⟨v,hv⟩ := Option.ne_none_iff_exists'.mp hfail have hc : c ∈ B.feasible := hball (Metric.mem_closedBall_self hr.le) have ha := B.normal_ne_zero y v hv c hc have hm := normalized_margin B.feasible c y (B.normal v) hr.le ha hball (fun z hz => by have h := B.central_cut y v hv z hz change (∑ i : Fin n, (z i-(y i : ℝ))*(B.normal v i : ℝ)) ≤ 0 simpa only [dotProduct,Pi.sub_apply,mul_comm] using h) have hround := realVector_round_error mesh hmesh (fun i => y i-step*B.normal v i/l1 (B.normal v)) rw [realVector_step] at hround have hp : 0 ≤ (step : ℝ) := by rw [hstep]; positivity have hδ : 0 ≤ (n+1 : ℝ)*(mesh : ℝ) := by positivity rw [Pencil.next,hv] exact CurrentKS.RationalOptimization.rounded_step_decrease _ c _ _ hp hR hδ hy (normalized_norm_le_one _) (hstep ▸ hm) hround hsmall
theorem Pencil.search_feasible (B : Pencil n m) (step mesh : ℚ) (y : Fin n → ℚ) (c : EuclideanSpace ℝ (Fin n)) {r R : ℝ} (hr : 0 < r) (hR : 0 ≤ R) (hmesh : 0 < mesh) (hstep : (step : ℝ)=r/(n+1)) (hball : Metric.closedBall c r ⊆ B.feasible) (hsmall : 2*(R+step)*((n+1)*mesh)+((n+1)*mesh)^2 ≤ (step : ℝ)^2/2) (hy : ‖realVector y-c‖ ≤ R) (T : ℕ) (hT : R^2 < T*(step : ℝ)^2/2) : B.witness ((B.next step mesh)^[T] y)=none := by have hp : 0 < (step : ℝ) := by rw [hstep]; positivity have hbound : ∀ k : ℕ, B.witness ((B.next step mesh)^[k] y)=none ∨ ‖realVector ((B.next step mesh)^[k] y)-c‖^2 ≤ R^2-k*(step : ℝ)^2/2 := by intro k induction k with | zero => right simpa using (sq_le_sq₀ (norm_nonneg _) hR).mpr hy | succ k ih => rcases ih with hh|hh · left rw [Function.iterate_succ_apply',B.next_eq_self _ _ _ hh] exact hh · by_cases ha : B.witness ((B.next step mesh)^[k] y)=none · left rw [Function.iterate_succ_apply',B.next_eq_self _ _ _ ha] exact ha · right have hdist : ‖realVector ((B.next step mesh)^[k] y)-c‖ ≤ R := by apply (sq_le_sq₀ (norm_nonneg _) hR).mp calc _ ≤ R^2-k*(step : ℝ)^2/2 := hh _ ≤ R^2 := sub_le_self _ (by positivity) have hd := B.next_decrease step mesh ((B.next step mesh)^[k] y) c hr hR hmesh hstep hball hsmall hdist ha rw [Function.iterate_succ_apply'] push_cast linarith rcases hbound T with h|h · exact h · have hn := sq_nonneg ‖realVector ((B.next step mesh)^[T] y)-c‖ linarith
end CurrentKS.RationalSDP
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.RealifyHermitianimport OAI.Analysis.MatrixSigning.Arithmetic.RealifyAddimport OAI.Analysis.MatrixSigning.Optimization.AffineRealEval
namespace OAI
open Matrix
namespace CurrentKS.RationalSDPopen Matrix CurrentKS.HermitianCoordinates KS.W08open scoped BigOperators ComplexOrder
variable {n m p d N : ℕ}
lemma lowerMatrixPencil_realEval (second : Bool) (v : Fin (valueDimension d) → ℝ) : (lowerMatrixPencil d second).realEval v = matrixVariable d second v-(1/400:ℝ) • 1 := by rw [lowerMatrixPencil,Pencil.ofAffine_realEval _ _ _ _ (matrixVariable d second) (matrixVariable_cast second),cast_matrix_smul,cast_matrix_one] norm_num abellemma upperMatrixPencil_realEval (ε : ℚ) (second : Bool) (v : Fin (valueDimension d) → ℝ) : (upperMatrixPencil d ε second).realEval v = (200/(ε:ℝ)) • 1-matrixVariable d second v := by have hc (y : Fin (valueDimension d) → ℚ) : ((-(matrixVariable (R := ℚ) d second)) y).map (fun q => (q:ℝ))= (-(matrixVariable (R := ℝ) d second)) (fun i => (y i:ℝ)) := by simp only [LinearMap.neg_apply,cast_matrix_neg,matrixVariable_cast] erw [upperMatrixPencil,Pencil.ofAffine_realEval _ _ _ _ (-(matrixVariable (R := ℝ) d second)) hc, cast_matrix_smul,cast_matrix_one] simp only [Rat.cast_div,Rat.cast_ofNat,LinearMap.neg_apply,sub_eq_add_neg]lemma lowerTimePencil_realEval (v : Fin (valueDimension d) → ℝ) : (lowerTimePencil d).realEval v=timeCoordinate d v • (1 : Matrix (Fin 1) (Fin 1) ℝ) := by have hc (y : Fin (valueDimension d) → ℚ) : (identityLinear 1 (timeCoordinate d) y).map (fun q => (q:ℝ))= identityLinear 1 (timeCoordinate d) (fun i => (y i:ℝ)) := by change ((timeCoordinate d y : ℚ) • (1 : Matrix (Fin 1) (Fin 1) ℚ)).map _=_ rw [cast_matrix_smul,cast_matrix_one] rfl erw [lowerTimePencil,Pencil.ofAffine_realEval _ _ _ _ (identityLinear 1 (timeCoordinate d)) hc, cast_matrix_zero,zero_add] rfllemma upperTimePencil_realEval (v : Fin (valueDimension d) → ℝ) : (upperTimePencil d).realEval v=(100-timeCoordinate d v) • (1 : Matrix (Fin 1) (Fin 1) ℝ) := by have hc (y : Fin (valueDimension d) → ℚ) : ((-(identityLinear (R := ℚ) 1 (timeCoordinate d))) y).map (fun q => (q:ℝ))= (-(identityLinear (R := ℝ) 1 (timeCoordinate d))) (fun i => (y i:ℝ)) := by change (-((timeCoordinate d y : ℚ) • (1 : Matrix (Fin 1) (Fin 1) ℚ))).map _=_ rw [cast_matrix_neg,cast_matrix_smul,cast_matrix_one] rfl erw [upperTimePencil,Pencil.ofAffine_realEval _ _ _ _ (-(identityLinear (R := ℝ) 1 (timeCoordinate d))) hc, cast_matrix_smul,cast_matrix_one] norm_num only [Rat.cast_ofNat] change (100:ℝ) • (1 : Matrix (Fin 1) (Fin 1) ℝ) + -(timeCoordinate d v • 1)=_ module
lemma posSemidef_reindex_iff {α β : Type*} [Fintype α] [Fintype β] (A : Matrix α α ℝ) (e : β ≃ α) : (A.submatrix e e).PosSemidef ↔ A.PosSemidef := by constructor · intro h have hh := h.submatrix e.symm simp only [Matrix.submatrix_submatrix,Function.comp_def,Equiv.apply_symm_apply] at hh exact hh · exact fun h => h.submatrix _
noncomputable def finRealify (A : Matrix (Fin d) (Fin d) ℂ) : Matrix (Fin (d+d)) (Fin (d+d)) ℝ := (realify A).submatrix finSumFinEquiv.symm finSumFinEquiv.symm
lemma finRealify_psd (A : Matrix (Fin d) (Fin d) ℂ) : (finRealify A).PosSemidef ↔ A.PosSemidef := by rw [finRealify,posSemidef_reindex_iff,realify_posSemidef_iff]lemma finRealify_decode (x : Fin d × Fin d → ℝ) : finRealify (decode x)=realFinDecode d x := by unfold finRealify rw [← realDecode_eq_realify] rfllemma finRealify_one : finRealify (1 : Matrix (Fin d) (Fin d) ℂ)=1 := by unfold finRealify rw [realify_one] ext i j simp [Matrix.one_apply]lemma finRealify_add (A B : Matrix (Fin d) (Fin d) ℂ) : finRealify (A+B)=finRealify A+finRealify B := by simp only [finRealify,realify_add,Matrix.submatrix_add,Pi.add_apply]lemma finRealify_smul (r : ℝ) (A : Matrix (Fin d) (Fin d) ℂ) : finRealify (r • A)=r • finRealify A := by simp only [finRealify,realify_smul,Matrix.submatrix_smul,Pi.smul_apply]lemma finRealify_neg (A : Matrix (Fin d) (Fin d) ℂ) : finRealify (-A)= -finRealify A := by have h : realify (-A) = -realify A := by ext (i|i) (j|j) <;> simp [realify,Matrix.fromBlocks] simp only [finRealify,h,Matrix.submatrix_neg] rfllemma finRealify_sub (A B : Matrix (Fin d) (Fin d) ℂ) : finRealify (A-B)=finRealify A-finRealify B := by simp only [sub_eq_add_neg,finRealify_add,finRealify_neg]lemma finRealify_mul (A B : Matrix (Fin d) (Fin d) ℂ) : finRealify (A*B)=finRealify A*finRealify B := by rw [finRealify,realify_mul] exact (Matrix.submatrix_mul_equiv _ _ _ finSumFinEquiv.symm _).symmlemma finRealify_sum {ι : Type*} (s : Finset ι) (A : ι → Matrix (Fin d) (Fin d) ℂ) : finRealify (∑ i ∈ s,A i)=∑ i ∈ s,finRealify (A i) := by ext i j simp only [finRealify,realify_sum,Matrix.submatrix_apply,Matrix.sum_apply]
lemma realify_schur (T X : Matrix (Fin d) (Fin d) ℂ) : (realify (Matrix.fromBlocks T 1 1 X)).submatrix (Equiv.sumSumSumComm (Fin d) (Fin d) (Fin d) (Fin d)) (Equiv.sumSumSumComm (Fin d) (Fin d) (Fin d) (Fin d))= Matrix.fromBlocks (realify T) 1 1 (realify X) := by ext i j rcases i with i | i <;> rcases i with i | i <;> rcases j with j | j <;> rcases j with j | j <;> simp [realify,Matrix.fromBlocks,Equiv.sumSumSumComm,Matrix.one_apply,apply_ite]
lemma finRealify_schur_psd (T X : Matrix (Fin d) (Fin d) ℂ) : (Matrix.fromBlocks (finRealify T) 1 1 (finRealify X)).PosSemidef ↔ (Matrix.fromBlocks T (1 : Matrix (Fin d) (Fin d) ℂ) 1 X).PosSemidef := by let e := (finSumFinEquiv.symm : Fin (d+d) ≃ Fin d ⊕ Fin d).sumCongr (finSumFinEquiv.symm : Fin (d+d) ≃ Fin d ⊕ Fin d) have he : Matrix.fromBlocks (finRealify T) 1 1 (finRealify X)= (Matrix.fromBlocks (realify T) 1 1 (realify X)).submatrix e e := by ext i j cases i <;> cases j <;> simp [finRealify,e,Matrix.one_apply] rw [he,posSemidef_reindex_iff,← realify_schur,posSemidef_reindex_iff,realify_posSemidef_iff]
noncomputable def complexSum (coords : Fin N → Fin d × Fin d → ℝ) (x : Fin N → ℝ) : Matrix (Fin d) (Fin d) ℂ := ∑ i,x i • decode (coords i)noncomputable def complexEta (coords : Fin N → Fin d × Fin d → ℝ) (θ : Fin N → ℝ) (Z : Matrix (Fin d) (Fin d) ℂ) : Matrix (Fin d) (Fin d) ℂ := ∑ i,(384*θ i) • (decode (coords i)*Z*decode (coords i))lemma finRealify_complexSum (coords : Fin N → Fin d × Fin d → ℝ) (x : Fin N → ℝ) : finRealify (complexSum coords x)=rationalSum coords x := by simp only [complexSum,finRealify_sum,finRealify_smul,finRealify_decode,rationalSum]lemma finRealify_complexEta (coords : Fin N → Fin d × Fin d → ℝ) (θ : Fin N → ℝ) (Z : Matrix (Fin d) (Fin d) ℂ) : finRealify (complexEta coords θ Z)=rationalEta coords θ (finRealify Z) := by simp only [complexEta,finRealify_sum,finRealify_smul,finRealify_mul,finRealify_decode, rationalEta,LinearMap.sum_apply,LinearMap.smul_apply,sandwichLinear,LinearMap.coe_mk,AddHom.coe_mk]
lemma schurPencil_psd (coords : Fin N → Fin d × Fin d → ℚ) (x θ : Fin N → ℚ) (second : Bool) (v : Fin (valueDimension d) → ℝ) : ((schurPencil coords x θ second).realEval v).PosSemidef ↔ (Matrix.fromBlocks (timeCoordinate d v • (1 : Matrix (Fin d) (Fin d) ℂ)+ (if second then complexSum (fun i j => (coords i j:ℝ)) (fun i => (x i:ℝ)) else -complexSum (fun i j => (coords i j:ℝ)) (fun i => (x i:ℝ)))- complexEta (fun i j => (coords i j:ℝ)) (fun i => (θ i:ℝ)) (decode (matrixCoordinate d (!second) v))) 1 1 (decode (matrixCoordinate d second v))).PosSemidef := by rw [schurPencil_realEval,posSemidef_reindex_iff,← finRealify_schur_psd] simp only [finRealify_sub,finRealify_add,finRealify_smul,finRealify_one, finRealify_complexEta,finRealify_decode] split <;> simp only [finRealify_complexSum,finRealify_neg,matrixVariable,LinearMap.comp_apply]
end CurrentKS.RationalSDP
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114import Mathlibimport OAI.Analysis.MatrixSigning.Potential.Potentialimport OAI.Analysis.MatrixSigning.Optimization.RootToleranceimport OAI.Analysis.MatrixSigning.Optimization.Lookup
namespace OAI
noncomputable section
open Matrix
namespace CurrentKS.RationalFaceopen CurrentKS.Hermitian CurrentKS.Scalar CurrentKS.State CurrentKS.Variationalopen scoped BigOperators MatrixOrder Matrix.Norms.Frobenius
variable {d N n : ℕ}
def fixedPart (e : Fin n → Fin N) (base : Coordinates N) (A : Fin N → H d) : H d := ∑ i,(lookup e i).elim (base i • A i) (fun _ => 0)
lemma S_extend (e : Fin n → Fin N) (he : Function.Injective e) (base : Coordinates N) (A : Fin N → H d) (y : Coordinates n) : S A (extend e base y)=fixedPart e base A+S (fun j => A (e j)) y := by exact sum_extend e he (fun (i : Fin N) (t : ℝ) => (t • A i : H d)) base y
lemma penalty_extend (e : Fin n → Fin N) (he : Function.Injective e) (base : Coordinates N) (hb : ∀ i,lookup e i=none → |base i|=1) (y : Coordinates n) : (∑ i,psi (extend e base y i))=∑ j,psi (y j) := by rw [sum_extend e he (fun _ t => psi t) base y] have hz : (∑ i,(lookup e i).elim (psi (base i)) (fun _ => 0))=0 := by apply Finset.sum_eq_zero intro i _ cases hi : lookup e i with | none => exact psi_endpoint (hb i hi) | some j => rfl rw [hz,zero_add]
lemma eta_extend (e : Fin n → Fin N) (he : Function.Injective e) (base : Coordinates N) (A : Fin N → H d) (hb : ∀ i,lookup e i=none → |base i|=1) (y : Coordinates n) (c : ℝ) : eta c A (extend e base y)=eta c (fun j => A (e j)) y := by apply ContinuousLinearMap.ext intro Z rw [eta_apply,eta_apply] have hsum := sum_extend e he (fun (i : Fin N) (t : ℝ) => ((c*psi t) • sandwich (A i) Z : H d)) base y rw [hsum] have hz : (∑ i,(lookup e i).elim ((c*psi (base i)) • sandwich (A i) Z) (fun _ => 0))=0 := by apply Finset.sum_eq_zero intro i _ cases hi : lookup e i with | none => simp only [Option.elim_none,psi_endpoint (hb i hi),mul_zero,zero_smul] | some j => rfl rw [hz,zero_add]
lemma potential_extend (e : Fin n → Fin N) (he : Function.Injective e) (base : Coordinates N) (A : Fin N → H d) (hb : ∀ i,lookup e i=none → |base i|=1) (y : Coordinates n) (ε lam : ℝ) : value ε (S A (extend e base y)) (eta 384 A (extend e base y))+ lam*∑ i,psi (extend e base y i)= value ε (fixedPart e base A+S (fun j => A (e j)) y) (eta 384 (fun j => A (e j)) y)+ lam*∑ j,psi (y j) := by rw [S_extend e he,eta_extend e he base A hb,penalty_extend e he base hb]
end CurrentKS.RationalFace
namespace CurrentKS.RationalSDPopen CurrentKS.RationalFace
variable {d N n : ℕ}
def faceQuery (coords : Fin N → Fin d × Fin d → ℚ) (base : Fin N → ℚ) (y : Fin (activeIndices base).length → ℚ) (ν lam error : ℚ) : ℚ := potentialQuery coords (extend (activeIndex base) base y) ν lam error
open CurrentKS.Hermitian CurrentKS.HermitianCoordinates CurrentKS.Variational CurrentKS.State CurrentKS.Scalaropen scoped BigOperators MatrixOrder Matrix.Norms.Frobenius
lemma faceQuery_correct [NeZero d] (coords : Fin N → Fin d × Fin d → ℚ) (base : Fin N → ℚ) (y : Fin (activeIndices base).length → ℚ) (hA : ∀ i,rationalAtoms coords i ∈ psdCone d) (htr : ∑ i,Hermitian.realTrace (rationalAtoms coords i)=1) {ν lam error : ℚ} (hν : 0<ν) (hν1 : ν≤1) (hlam : 0≤lam) (he : 0<error) (he1 : error≤1) (hvar : (∑ i,sandwich (rationalAtoms coords i) (Hermitian.one : H d)) ≤ (ν:ℝ) • (Hermitian.one : H d)) (hb : ∀ i,|base i|≤1) (hy : ∀ j,|y j|≤1) : |(faceQuery coords base y ν lam error:ℝ)- (value ((ν:ℝ)/d) (fixedPart (activeIndex base) (fun i => (base i:ℝ)) (rationalAtoms coords)+ S (fun j => rationalAtoms coords (activeIndex base j)) (fun j => (y j:ℝ))) (eta 384 (fun j => rationalAtoms coords (activeIndex base j)) (fun j => (y j:ℝ)))+ (lam:ℝ)*∑ j,psi (y j:ℝ))|≤(error:ℝ) := by have hcube : Cube (fun i => ((extend (activeIndex base) base y i : ℚ):ℝ)) := by intro i change |((extend (activeIndex base) base y i : ℚ):ℝ)| ≤ 1 exact_mod_cast extend_cube (e := activeIndex base) base y hb hy i have hq := potentialQuery_correct coords (extend (activeIndex base) base y) hA htr hν hν1 hlam he he1 hvar hcube have heq := potential_extend (activeIndex base) (activeIndex_injective base) (fun i => (base i:ℝ)) (rationalAtoms coords) (real_active_outside_endpoint base hb) (fun j => (y j:ℝ)) ((ν:ℝ)/d) (lam:ℝ) have hext := map_extend (fun q : ℚ => (q:ℝ)) (activeIndex base) base y have hext' : ∀ i, ((extend (activeIndex base) base y i : ℚ):ℝ) = extend (activeIndex base) (fun i => (base i:ℝ)) (fun j => (y j:ℝ)) i := fun i => congrFun hext i simp_rw [hext'] at hq rw [heq] at hq exact hq
end CurrentKS.RationalSDP
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151import Mathlibimport OAI.Analysis.MatrixSigning.Optimization.Variables
namespace OAI
noncomputable section
open Matrix
namespace CurrentKS.KKTopen scoped RealInnerProductSpace
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]
lemma inverse_elimination_bounds (e : E) (L : E ≃L[ℝ] E) (hL : L.toLinearEquiv.toLinearMap.IsSymmetric) (H : E →L[ℝ] E) (z rhs : Variables E) (hz : jacobian e L.toContinuousLinearMap H z = rhs) {b H0 δ : ℝ} (hb : 0 ≤ b) (hH0 : 0 ≤ H0) (hδ : 0 < δ) (hB : ‖L.symm.toContinuousLinearMap‖ ≤ b) (hBe : ‖L.symm e‖ ≤ b) (hH : ‖H‖ ≤ H0) (hden : δ ≤ inner ℝ (L.symm e) (H (L.symm e))) (hrhs : ‖rhs‖ ≤ 1) : |z.1| ≤ (1+b+H0*b^2)/δ ∧ ‖z.2.1‖ ≤ b*(1+|z.1|) ∧ ‖z.2.2‖ ≤ b*(1+H0*‖z.2.1‖) := by have hr : |rhs.1| ≤ 1 := by exact (norm_fst_le rhs).trans hrhs have hf : ‖rhs.2.1‖ ≤ 1 := (norm_fst_le rhs.2).trans ((norm_snd_le rhs).trans hrhs) have hg : ‖rhs.2.2‖ ≤ 1 := (norm_snd_le rhs.2).trans ((norm_snd_le rhs).trans hrhs) have hbn (x : E) : ‖L.symm x‖ ≤ b*‖x‖ := (L.symm.toContinuousLinearMap.le_opNorm x).trans (mul_le_mul_of_nonneg_right hB (norm_nonneg _)) have hhn (x : E) : ‖H x‖ ≤ H0*‖x‖ := (H.le_opNorm x).trans (mul_le_mul_of_nonneg_right hH (norm_nonneg _)) obtain ⟨hu,_hp,hh⟩ := inverse_elimination e L hL H z rhs hz have hscalar : |z.1| ≤ (1+b+H0*b^2)/δ := by have hnum : |inner ℝ (L.symm e) rhs.2.2 + inner ℝ (L.symm e) (H (L.symm rhs.2.1)) - rhs.1| ≤ b+H0*b^2+1 := by calc _ ≤ |inner ℝ (L.symm e) rhs.2.2|+|inner ℝ (L.symm e) (H (L.symm rhs.2.1))|+|rhs.1| := (abs_sub _ _).trans (add_le_add (abs_add_le _ _) (le_refl _)) _ ≤ ‖L.symm e‖*‖rhs.2.2‖+‖L.symm e‖*‖H (L.symm rhs.2.1)‖+1 := by gcongr <;> exact abs_real_inner_le_norm _ _ _ ≤ b*1+b*(H0*(b*1))+1 := by have hnorm : ‖H (L.symm rhs.2.1)‖ ≤ H0*(b*1) := (hhn _).trans (mul_le_mul_of_nonneg_left ((hbn _).trans (mul_le_mul_of_nonneg_left hf hb)) hH0) exact add_le_add (add_le_add (mul_le_mul hBe hg (norm_nonneg _) hb) (mul_le_mul hBe hnorm (norm_nonneg _) hb)) (le_refl 1) _ = _ := by ring rw [← hh,abs_mul,abs_of_pos (hδ.trans_le hden)] at hnum have hm := mul_le_mul_of_nonneg_left hden (abs_nonneg z.1) exact (le_div_iff₀ hδ).mpr (by linarith) refine ⟨hscalar,?_,?_⟩ · rw [hu] calc _ ≤ ‖L.symm rhs.2.1‖+‖z.1 • L.symm e‖ := norm_sub_le _ _ _ ≤ b*1+|z.1| * b := by rw [norm_smul,Real.norm_eq_abs] exact add_le_add ((hbn _).trans (mul_le_mul_of_nonneg_left hf hb)) (mul_le_mul_of_nonneg_left hBe (abs_nonneg _)) _ = _ := by ring · have hg' : z.2.2 = L.symm (rhs.2.2+H z.2.1) := by apply L.injective rw [L.apply_symm_apply] have he := congrArg (fun w : Variables E => w.2.2) hz change L z.2.2-H z.2.1 = rhs.2.2 at he exact sub_eq_iff_eq_add.mp he rw [hg'] calc _ ≤ b*‖rhs.2.2+H z.2.1‖ := hbn _ _ ≤ b*(‖rhs.2.2‖+‖H z.2.1‖) := mul_le_mul_of_nonneg_left (norm_add_le _ _) hb _ ≤ b*(1+H0*‖z.2.1‖) := mul_le_mul_of_nonneg_left (add_le_add hg (hhn _)) hb
lemma inverse_elimination_numeric {d b h u p : ℝ} (hd : 0 < d) (hb : 0 ≤ b) (hh : |h| ≤ (1+b+16000000*b^2)/(1/(100*d))) (hu : u ≤ b*(1+|h|)) (hp : p ≤ b*(1+16000000*u)) : |h| ≤ 10^18*(d+1)*(1+b)^4 ∧ u ≤ 10^18*(d+1)*(1+b)^4 ∧ p ≤ 10^18*(d+1)*(1+b)^4 := by let s := 1+b have hs : 1 ≤ s := by dsimp [s]; linarith have hs0 : 0 ≤ s := le_trans zero_le_one hs have hbs : b ≤ s := by dsimp [s]; linarith have hD : 1 ≤ d+1 := by linarith have hD0 : 0 ≤ d+1 := by linarith have hs2 : 1 ≤ s^2 := one_le_pow₀ hs have hs3 : 1 ≤ s^3 := one_le_pow₀ hs have hs4 : 1 ≤ s^4 := one_le_pow₀ hs have hs12 : s ≤ s^2 := by nlinarith have hb2 : b^2 ≤ s^2 := pow_le_pow_left₀ hb hbs _ have hD2 : 1 ≤ (d+1)*s^2 := one_le_mul_of_one_le_of_one_le hD hs2 have hD3 : 1 ≤ (d+1)*s^3 := one_le_mul_of_one_le_of_one_le hD hs3 have hsmall : |h| ≤ 2000000000*(d+1)*s^2 := by have hfrac : (1+b+16000000*b^2)/(1/(100*d)) = 100*d*(1+b+16000000*b^2) := by field_simp rw [hfrac] at hh calc _ ≤ 100*d*(1+b+16000000*b^2) := hh _ ≤ 100*d*(16000001*s^2) := by apply mul_le_mul_of_nonneg_left _ (by positivity) dsimp [s] at hs12 nlinarith _ ≤ 2000000000*(d+1)*s^2 := by nlinarith [mul_nonneg hd.le (sq_nonneg s)] have hu' : u ≤ 3000000000*(d+1)*s^3 := by calc _ ≤ b*(1+|h|) := hu _ ≤ s*(1+2000000000*(d+1)*s^2) := by gcongr _ ≤ s*(3000000000*(d+1)*s^2) := by apply mul_le_mul_of_nonneg_left _ hs0 nlinarith _ = _ := by ring have hp' : p ≤ 50000000000000000*(d+1)*s^4 := by calc _ ≤ b*(1+16000000*u) := hp _ ≤ b*(1+16000000*(3000000000*(d+1)*s^3)) := by gcongr _ ≤ s*(1+16000000*(3000000000*(d+1)*s^3)) := by gcongr _ ≤ s*(50000000000000000*(d+1)*s^3) := by apply mul_le_mul_of_nonneg_left _ hs0 nlinarith _ = _ := by ring have hs24 : s^2 ≤ s^4 := pow_le_pow_right₀ hs (by omega) have hs34 : s^3 ≤ s^4 := pow_le_pow_right₀ hs (by omega) change |h| ≤ (10:ℝ)^18*(d+1)*s^4 ∧ u ≤ (10:ℝ)^18*(d+1)*s^4 ∧ p ≤ (10:ℝ)^18*(d+1)*s^4 refine ⟨hsmall.trans ?_,hu'.trans ?_,hp'.trans ?_⟩ · gcongr; norm_num · gcongr; norm_num · gcongr; norm_num
lemma jacobian_inverse_norm_100 (e : E) (L : E ≃L[ℝ] E) (hL : L.toLinearEquiv.toLinearMap.IsSymmetric) (H : E →L[ℝ] E) (J : Variables E ≃L[ℝ] Variables E) (hJ : ∀ z,J z = jacobian e L.toContinuousLinearMap H z) {ε d : ℝ} (hε : 0 < ε) (hd : 0 < d) (hB : ‖L.symm.toContinuousLinearMap‖ ≤ ε⁻¹) (hBe : ‖L.symm e‖ ≤ ε⁻¹) (hH : ‖H‖ ≤ 16000000) (hden : 1/(100*d) ≤ inner ℝ (L.symm e) (H (L.symm e))) : ‖J.symm.toContinuousLinearMap‖ ≤ 10^18*(d+1)*(1+ε⁻¹)^4 := by apply ContinuousLinearMap.opNorm_le_of_unit_norm (by positivity) intro rhs hrhs have heq : jacobian e L.toContinuousLinearMap H (J.symm rhs) = rhs := by rw [← hJ,J.apply_symm_apply] obtain ⟨hh,hu,hp⟩ := inverse_elimination_bounds e L hL H _ rhs heq (inv_nonneg.mpr hε.le) (show (0:ℝ)≤16000000 by norm_num) (show 0<1/(100*d) by positivity) hB hBe hH hden hrhs.le obtain ⟨hh',hu',hp'⟩ := inverse_elimination_numeric hd (inv_nonneg.mpr hε.le) hh hu hp change max |(J.symm rhs).1| (max ‖(J.symm rhs).2.1‖ ‖(J.symm rhs).2.2‖) ≤ _ exact max_le hh' (max_le hu' hp')
end CurrentKS.KKT
end
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990import Mathlibimport OAI.Analysis.MatrixSigning.Optimization.SearchStepimport OAI.Analysis.MatrixSigning.Optimization.BlockScalar
namespace OAI
open Matrix
namespace CurrentKS.RationalSDPopen scoped BigOperators RealInnerProductSpaceopen Set
variable {n m : ℕ}
def level (δ U : ℚ) (k : ℕ) : ℚ := -U+k*δ
def Pencil.levelCandidate (B : Pencil n m) (f : Fin n → ℚ) (δ r R U : ℚ) (k : ℕ) : Fin n → ℚ := (B.withLevel f (level δ U k)).search r R 0
def Pencil.optimize (B : Pencil n m) (f : Fin n → ℚ) (δ r R U : ℚ) : ℕ → Fin n → ℚ | 0 => B.levelCandidate f δ r R U 0 | k+1 => let y := B.optimize f δ r R U k if (B.withLevel f (level δ U k)).witness y = none then y else B.levelCandidate f δ r R U (k+1)
lemma Pencil.witness_withLevel (B : Pencil n m) (f : Fin n → ℚ) (q : ℚ) (y : Fin n → ℚ) : (B.withLevel f q).witness y = none ↔ realVector y ∈ B.feasible ∧ (fun i => (f i:ℝ)) ⬝ᵥ realVector y ≤ (q:ℝ) := by rw [Pencil.witness_none_iff] change realVector y ∈ (B.withLevel f q).feasible ↔ _ exact B.withLevel_feasible f q (realVector y)
lemma level_mono {δ U : ℚ} (hδ : 0 ≤ δ) : Monotone (level δ U) := by intro k l hkl unfold level exact add_le_add (le_refl (-U)) (mul_le_mul_of_nonneg_right (show (k:ℚ) ≤ (l:ℚ) by exact_mod_cast hkl) hδ)
lemma Pencil.optimize_preserves (B : Pencil n m) (f : Fin n → ℚ) (δ r R U : ℚ) (hδ : 0 ≤ δ) {k l : ℕ} (hkl : k ≤ l) (hk : (B.withLevel f (level δ U k)).witness (B.optimize f δ r R U k)=none) : B.optimize f δ r R U l = B.optimize f δ r R U k := by induction l, hkl using Nat.le_induction with | base => rfl | succ l hkl ih => have hl : (B.withLevel f (level δ U l)).witness (B.optimize f δ r R U l)=none := by rw [ih,B.witness_withLevel] obtain ⟨hm,ho⟩ := (B.witness_withLevel _ _ _).mp hk refine ⟨hm,ho.trans ?_⟩ exact_mod_cast level_mono hδ hkl rw [Pencil.optimize,ite_eq_left hl,ih]
lemma Pencil.optimize_accepts (B : Pencil n m) (f : Fin n → ℚ) (δ r R U : ℚ) (hδ : 0 ≤ δ) (k : ℕ) (hk : (B.withLevel f (level δ U k)).witness (B.levelCandidate f δ r R U k)=none) : (B.withLevel f (level δ U k)).witness (B.optimize f δ r R U k)=none := by cases k with | zero => exact hk | succ k => by_cases h : (B.withLevel f (level δ U k)).witness (B.optimize f δ r R U k)=none · simp only [Pencil.optimize,h,ite_true] rw [B.witness_withLevel] at h ⊢ refine ⟨h.1,h.2.trans ?_⟩ exact_mod_cast level_mono hδ (Nat.le_succ k) · simpa only [Pencil.optimize,h,ite_false] using hk
theorem Pencil.optimize_bound (B : Pencil n m) (f : Fin n → ℚ) (δ r R U : ℚ) (hδ : 0 ≤ δ) {k K : ℕ} (hkK : k ≤ K) (hk : (B.withLevel f (level δ U k)).witness (B.levelCandidate f δ r R U k)=none) : realVector (B.optimize f δ r R U K) ∈ B.feasible ∧ (fun i => (f i:ℝ)) ⬝ᵥ realVector (B.optimize f δ r R U K) ≤ (level δ U k:ℝ) := by have ha := B.optimize_accepts f δ r R U hδ k hk rw [B.optimize_preserves f δ r R U hδ hkK ha] exact (B.witness_withLevel _ _ _).mp ha
lemma Pencil.levelCandidate_accepts (B : Pencil n m) (f : Fin n → ℚ) (δ r R U : ℚ) (k : ℕ) (c : EuclideanSpace ℝ (Fin n)) (hr : 0 < r) (hr1 : r ≤ 1) (hR : 0 ≤ R) (hc : ‖c‖ ≤ (R:ℝ)) (hball : Metric.closedBall c (r:ℝ) ⊆ B.feasible ∩ {y | (fun i => (f i:ℝ)) ⬝ᵥ y ≤ (level δ U k:ℝ)}) : (B.withLevel f (level δ U k)).witness (B.levelCandidate f δ r R U k)=none := by apply Pencil.search_accepts _ _ _ _ c hr hr1 hR · intro y hy exact (B.withLevel_feasible f _ y).mpr (hball hy) · have hz : realVector (0 : Fin n → ℚ)=0 := by ext i; simp [realVector] simpa only [hz,zero_sub,norm_neg] using hc
end CurrentKS.RationalSDP
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134import Mathlib
namespace OAI
open Matrix
namespace CurrentKS.RationalFacevariable {N n : ℕ}
def lookup (e : Fin n → Fin N) (i : Fin N) : Option (Fin n) := (List.finRange n).find? (fun j => e j == i)
lemma lookup_some {e : Fin n → Fin N} {i : Fin N} {j : Fin n} (h : lookup e i=some j) : e j=i := by have hh := List.find?_some h exact of_decide_eq_true hh
lemma lookup_none_iff (e : Fin n → Fin N) (i : Fin N) : lookup e i=none ↔ ∀ j,e j≠i := by simp [lookup,List.find?_eq_none]
lemma lookup_self {e : Fin n → Fin N} (he : Function.Injective e) (j : Fin n) : lookup e (e j)=some j := by cases hh : lookup e (e j) with | none => exact False.elim ((lookup_none_iff e (e j)).mp hh j rfl) | some k => have hk := he (lookup_some hh) cases hk rfl
def extend {β : Type*} (e : Fin n → Fin N) (base : Fin N → β) (y : Fin n → β) : Fin N → β := fun i => (lookup e i).elim (base i) y
lemma extend_at {β : Type*} {e : Fin n → Fin N} (he : Function.Injective e) (base : Fin N → β) (y : Fin n → β) (j : Fin n) : extend e base y (e j)=y j := by simp [extend,lookup_self he]
lemma extend_outside {β : Type*} (e : Fin n → Fin N) (base : Fin N → β) (y : Fin n → β) (i : Fin N) (hi : ∀ j,e j≠i) : extend e base y i=base i := by simp [extend,(lookup_none_iff e i).mpr hi]
lemma extend_self {β : Type*} (e : Fin n → Fin N) (base : Fin N → β) : extend e base (fun j => base (e j))=base := by funext i unfold extend cases hh : lookup e i with | none => rfl | some j => simp only [Option.elim_some,lookup_some hh]
lemma map_extend {β γ : Type*} (f : β → γ) (e : Fin n → Fin N) (base : Fin N → β) (y : Fin n → β) : (fun i => f (extend e base y i))=extend e (fun i => f (base i)) (fun j => f (y j)) := by funext i unfold extend cases lookup e i <;> rfl
def activeIndices (x : Fin N → ℚ) : List (Fin N) := (List.finRange N).filter (fun i => decide (|x i|<1))
def activeIndex (x : Fin N → ℚ) : Fin (activeIndices x).length → Fin N := (activeIndices x).get
lemma activeIndices_mem (x : Fin N → ℚ) (i : Fin N) : i∈activeIndices x ↔ |x i|<1 := by simp [activeIndices]
lemma activeIndex_injective (x : Fin N → ℚ) : Function.Injective (activeIndex x) := by exact ((List.nodup_finRange N).filter _).injective_get
lemma activeIndex_range (x : Fin N → ℚ) (i : Fin N) : (∃ j,activeIndex x j=i) ↔ |x i|<1 := by rw [←activeIndices_mem] exact List.mem_iff_get.symm
lemma activeIndex_interior (x : Fin N → ℚ) (j : Fin (activeIndices x).length) : |x (activeIndex x j)|<1 := (activeIndex_range x _).mp ⟨j,rfl⟩
lemma activeIndices_length_le (x : Fin N → ℚ) : (activeIndices x).length≤N := by have hh := List.length_filter_le (fun i : Fin N => decide (|x i|<1)) (List.finRange N) simp only [List.length_finRange] at hh exact hh
lemma extend_cube {e : Fin n → Fin N} (x : Fin N → ℚ) (y : Fin n → ℚ) (hx : ∀ i,|x i|≤1) (hy : ∀ j,|y j|≤1) : ∀ i,|extend e x y i|≤1 := by intro i unfold extend cases lookup e i with | none => exact hx i | some j => exact hy j
lemma extended_difference_bound (e : Fin n → Fin N) (x : Fin N → ℝ) (y : Fin n → ℝ) {r : ℝ} (hr : 0≤r) (hy : ‖y-(fun j => x (e j))‖≤r) : ‖extend e x y-x‖≤r := by apply (pi_norm_le_iff_of_nonneg hr).mpr intro i have hj := (pi_norm_le_iff_of_nonneg hr).mp hy change ‖extend e x y i-x i‖≤r unfold extend cases hh : lookup e i with | none => simpa using hr | some j => simpa only [Option.elim_some,Pi.sub_apply,lookup_some hh] using hj j
lemma sum_lookup {β : Type*} [AddCommMonoid β] (e : Fin n → Fin N) (he : Function.Injective e) (f : Fin N → Fin n → β) : (∑ i,(lookup e i).elim 0 (f i))=∑ j,f (e j) j := by symm apply Fintype.sum_of_injective e he · intro i hi have hn : ∀ j,e j≠i := fun j hj => hi ⟨j,hj⟩ simp only [(lookup_none_iff e i).mpr hn,Option.elim_none] · intro j simp only [lookup_self he,Option.elim_some]
lemma sum_extend {β γ : Type*} [AddCommMonoid γ] (e : Fin n → Fin N) (he : Function.Injective e) (f : Fin N → β → γ) (base : Fin N → β) (y : Fin n → β) : (∑ i,f i (extend e base y i))= (∑ i,(lookup e i).elim (f i (base i)) (fun _ => 0))+(∑ j,f (e j) (y j)) := by rw [←sum_lookup e he (fun i j => f i (y j)),←Finset.sum_add_distrib] apply Finset.sum_congr rfl intro i _ unfold extend cases lookup e i <;> simp
lemma real_active_outside_endpoint (x : Fin N → ℚ) (hx : ∀ i,|x i|≤1) (i : Fin N) (hi : lookup (activeIndex x) i=none) : |(x i:ℝ)|=1 := by have hn : ¬|x i|<1 := by intro h obtain ⟨j,hj⟩ := (activeIndex_range x i).mpr h exact (lookup_none_iff _ _).mp hi j hj have he : |x i|=1 := le_antisymm (hx i) (le_of_not_gt hn) exact_mod_cast he
end CurrentKS.RationalFace
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import Mathlibimport OAI.Analysis.MatrixSigning.Optimization.Select
namespace OAI
open Matrix
namespace CurrentKS.Descent
def minList : List ℚ → ℚ | [] => 1 | a::as => min a (minList as)
lemma minList_pos (l : List ℚ) (h : ∀ a∈l,0<a) : 0 < minList l := by induction l with | nil => norm_num [minList] | cons a as ih => exact lt_min (h a (by simp)) (ih (fun b hb => h b (by simp [hb])))
lemma minList_le {l : List ℚ} {a : ℚ} (ha : a∈l) : minList l≤a := by induction l with | nil => simp at ha | cons b bs ih => rcases List.mem_cons.mp ha with rfl|ha · exact min_le_left _ _ · exact (min_le_right _ _).trans (ih ha)
def fuel (r : ℚ) : ℕ := ⌈100/r⌉₊+1
lemma fuel_spec {r : ℚ} (hr : 0<r) : (100:ℝ)<(fuel r:ℝ)*(r:ℝ) := by have hc : (100:ℚ)/r < (fuel r:ℚ) := by have hh := Nat.le_ceil (100/r) dsimp [fuel] push_cast linarith have hh : (100:ℚ)<(fuel r:ℚ)*r := (div_lt_iff₀ hr).mp hc exact_mod_cast hh
lemma run_value_le {α : Type*} (step : α → Option α) (P : α → Prop) (f : α → ℝ) (hp : ∀ x y,P x → step x=some y → P y) (hd : ∀ x y,P x → step x=some y → f y≤f x) (k : ℕ) (x : α) (hx : P x) : f (run step k x)≤f x := by induction k generalizing x with | zero => exact le_refl _ | succ k ih => rw [run] cases he : step x with | none => exact le_refl _ | some y => exact (ih y (hp x y hx he)).trans (hd x y hx he)
end CurrentKS.Descent
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495import Mathlib
namespace OAI
open Matrix
namespace CurrentKS.RationalFacevariable {N : ℕ}
def nearestEndpoint (r : ℚ) : ℚ := if 0≤r then 1 else -1
def freezeOne (σ : ℚ) (x : Fin N → ℚ) (i : Fin N) : Fin N → ℚ := if 1-|x i|≤σ then Function.update x i (nearestEndpoint (x i)) else x
def freezeList (σ : ℚ) : (Fin N → ℚ) → List (Fin N) → (Fin N → ℚ) | x,[] => x | x,i::is => freezeList σ (freezeOne σ x i) is
def freezeAll (σ : ℚ) (x : Fin N → ℚ) : Fin N → ℚ := freezeList σ x (List.finRange N)
lemma nearestEndpoint_abs (r : ℚ) : |nearestEndpoint r|=1 := by unfold nearestEndpoint split <;> norm_num
lemma nearestEndpoint_dist {r : ℚ} (hr : |r|≤1) : |nearestEndpoint r-r|=1-|r| := by unfold nearestEndpoint split · rename_i h rw [abs_of_nonneg h,abs_of_nonneg (by linarith [(abs_le.mp hr).2])] · rename_i h have hn : r≤0 := (lt_of_not_ge h).le rw [abs_of_nonpos hn,abs_of_nonpos (by linarith [(abs_le.mp hr).1])] ring
lemma freezeOne_cube (σ : ℚ) (x : Fin N → ℚ) (hx : ∀ i,|x i|≤1) (i : Fin N) : ∀ j,|freezeOne σ x i j|≤1 := by unfold freezeOne split · intro j by_cases hj : j=i · subst j;simpa using (nearestEndpoint_abs (x i)).le · simpa only [Function.update_of_ne hj] using hx j · exact hx
lemma freezeOne_other (σ : ℚ) (x : Fin N → ℚ) (i j : Fin N) (hji : j≠i) : freezeOne σ x i j=x j := by unfold freezeOne split <;> simp [Function.update_of_ne hji]
lemma freezeOne_assigned (σ : ℚ) (x : Fin N → ℚ) (i : Fin N) : |freezeOne σ x i i|=1 ∨ σ<1-|freezeOne σ x i i| := by unfold freezeOne split · exact Or.inl (by simpa using nearestEndpoint_abs (x i)) · exact Or.inr (lt_of_not_ge ‹¬1-|x i|≤σ›)
lemma freezeOne_preserves_assigned (σ : ℚ) (x : Fin N → ℚ) (i j : Fin N) (h : |x j|=1 ∨ σ<1-|x j|) : |freezeOne σ x i j|=1 ∨ σ<1-|freezeOne σ x i j| := by by_cases hji : j=i · subst j;exact freezeOne_assigned σ x i · simpa only [freezeOne_other σ x i j hji] using h
lemma freezeList_cube (σ : ℚ) (x : Fin N → ℚ) (hx : ∀ i,|x i|≤1) (l : List (Fin N)) : ∀ j,|freezeList σ x l j|≤1 := by induction l generalizing x with | nil => exact hx | cons i is ih => exact ih _ (freezeOne_cube σ x hx i)
lemma freezeList_preserves_assigned (σ : ℚ) (x : Fin N → ℚ) (l : List (Fin N)) (j : Fin N) (h : |x j|=1 ∨ σ<1-|x j|) : |freezeList σ x l j|=1 ∨ σ<1-|freezeList σ x l j| := by induction l generalizing x with | nil => exact h | cons i is ih => exact ih _ (freezeOne_preserves_assigned σ x i j h)
lemma freezeList_assigned (σ : ℚ) (x : Fin N → ℚ) (l : List (Fin N)) (j : Fin N) (hj : j∈l) : |freezeList σ x l j|=1 ∨ σ<1-|freezeList σ x l j| := by induction l generalizing x with | nil => simp at hj | cons i is ih => rcases List.mem_cons.mp hj with hij|hj · subst j exact freezeList_preserves_assigned σ _ is i (freezeOne_assigned σ x i) · exact ih _ hj
lemma freezeAll_strip (σ : ℚ) (x : Fin N → ℚ) (j : Fin N) (hj : |freezeAll σ x j|<1) : |freezeAll σ x j|<1-σ := by have hh := freezeList_assigned σ x (List.finRange N) j (List.mem_finRange j) change |freezeAll σ x j|=1 ∨ σ<1-|freezeAll σ x j| at hh rcases hh with h|h <;> linarith
end CurrentKS.RationalFace
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135import Mathlibimport OAI.Analysis.MatrixSigning.Matrices.EliminationCompletenessimport OAI.Analysis.MatrixSigning.Optimization.SqSum
namespace OAI
open Matrix
namespace CurrentKS.RationalRoot
sectionopen Matrixopen scoped BigOperators
variable {N : ℕ}
def negativeDirection (M : Matrix (Fin N) (Fin N) ℚ) (β : ℚ) : Option (Fin N → ℚ) := (KS.W17.rationalNegativeWitness N M).map (fun v => normalize v β)
lemma quadratic_scale (M : Matrix (Fin N) (Fin N) ℚ) (v : Fin N → ℚ) (c : ℚ) : (fun i => c*v i) ⬝ᵥ (M *ᵥ (fun i => c*v i)) = c^2*(v ⬝ᵥ (M *ᵥ v)) := by simp only [dotProduct,mulVec,Finset.mul_sum] apply Finset.sum_congr rfl intro i _ apply Finset.sum_congr rfl intro j _ ring
theorem negativeDirection_spec (M : Matrix (Fin N) (Fin N) ℚ) (hM : M.IsSymm) (β : ℚ) (hβ : 0 < β) (hβ1 : β ≤ 1) : match negativeDirection M β with | none => (M.map (fun q : ℚ => (q:ℝ))).PosSemidef | some w => 1-(β:ℝ) ≤ ‖realVector w‖ ∧ ‖realVector w‖ ≤ 1 ∧ w ⬝ᵥ (M *ᵥ w) < 0 := by unfold negativeDirection cases he : KS.W17.rationalNegativeWitness N M with | none => exact KS.W17.rationalNegativeWitness_none_psd N M hM he | some v => simp only [Option.map_some] have hv := KS.W17.rationalNegativeWitness_sound N M hM v he have hv0 : v ≠ 0 := by intro h simp only [h,Matrix.mulVec_zero,dotProduct_zero] at hv exact (lt_irrefl 0 hv) obtain ⟨hl,hu,c,hc,hwe⟩ := normalize_spec v hv0 β hβ hβ1 refine ⟨hl,hu,?_⟩ rw [hwe,quadratic_scale] exact mul_neg_of_pos_of_neg (sq_pos_of_pos hc) hvend
open scoped BigOperators
variable {N : ℕ}
def nearest (t : ℚ) : ℤ := if 0 ≤ t then ⌈t-1/2⌉ else -⌈-t-1/2⌉
def roundMesh (ρ : ℚ) (v : Fin N → ℚ) : Fin N → ℚ := fun i => ρ*(nearest (v i/ρ):ℚ)
lemma nearest_error (t : ℚ) : |(nearest t:ℚ)-t| ≤ 1/2 := by unfold nearest split_ifs with ht · have hl := Int.le_ceil (t-1/2) have hu := Int.ceil_lt_add_one (t-1/2) rw [abs_le] constructor <;> linarith · have hl := Int.le_ceil (-t-1/2) have hu := Int.ceil_lt_add_one (-t-1/2) rw [Int.cast_neg,abs_le] constructor <;> linarith
lemma roundMesh_coord_error (ρ : ℚ) (hρ : 0 < ρ) (v : Fin N → ℚ) (i : Fin N) : |roundMesh ρ v i-v i| ≤ ρ/2 := by have he : roundMesh ρ v i-v i=ρ*((nearest (v i/ρ):ℚ)-v i/ρ) := by dsimp [roundMesh] field_simp rw [he,abs_mul,abs_of_pos hρ] exact (mul_le_mul_of_nonneg_left (nearest_error _) hρ.le).trans_eq (by ring)
lemma norm_le_sum_abs (v : EuclideanSpace ℝ (Fin N)) : ‖v‖ ≤ ∑ i,|v i| := by rw [EuclideanSpace.norm_eq] apply Real.sqrt_le_iff.mpr refine ⟨Finset.sum_nonneg (fun _ _ => abs_nonneg _),?_⟩ simpa only [Real.norm_eq_abs] using Finset.sum_sq_le_sq_sum_of_nonneg (s := Finset.univ) (fun i _ => abs_nonneg (v i))
lemma roundMesh_error (ρ : ℚ) (hρ : 0 < ρ) (v : Fin N → ℚ) : ‖realVector (roundMesh ρ v)-realVector v‖ ≤ N*(ρ:ℝ)/2 := by apply (norm_le_sum_abs _).trans calc (∑ i, |(realVector (roundMesh ρ v)-realVector v) i|) ≤ ∑ _ : Fin N,(ρ:ℝ)/2 := by apply Finset.sum_le_sum intro i _ change |(roundMesh ρ v i:ℝ)-(v i:ℝ)| ≤ (ρ:ℝ)/2 exact_mod_cast roundMesh_coord_error ρ hρ v i _ = N*(ρ:ℝ)/2 := by simp; ring
lemma realVector_scale (v : Fin N → ℚ) (c : ℚ) : realVector (fun i => c*v i)=(c:ℝ) • realVector v := by apply PiLp.ext intro i simp only [realVector,WithLp.ofLp_toLp,PiLp.smul_apply,smul_eq_mul,Rat.cast_mul]
theorem curvature_rounding (w : Fin N → ℚ) (s τ ρ : ℚ) (hs : 0 ≤ s) (hτ : 0 ≤ τ) (hτ1 : τ ≤ 1) (hρ : 0 < ρ) (hmesh : (N:ℚ)*ρ/2 ≤ s*τ/8) (hw : ‖realVector w‖ ≤ 1) : let q := roundMesh ρ (fun i => s*(1-τ)*w i) ‖realVector q-((s:ℝ)*(1-(τ:ℝ))) • realVector w‖ ≤ (s:ℝ)*τ/8 ∧ ‖realVector q‖ ≤ s ∧ ‖realVector q-(s:ℝ) • realVector w‖ ≤ 9*(s:ℝ)*τ/8 := by let q := roundMesh ρ (fun i => s*(1-τ)*w i) have hs' : (0:ℝ) ≤ s := by exact_mod_cast hs have ht' : (0:ℝ) ≤ τ := by exact_mod_cast hτ have ht1' : (τ:ℝ) ≤ 1 := by exact_mod_cast hτ1 have hm : (N:ℝ)*(ρ:ℝ)/2 ≤ (s:ℝ)*τ/8 := by exact_mod_cast hmesh have he := (roundMesh_error ρ hρ (fun i => s*(1-τ)*w i)).trans hm rw [realVector_scale] at he push_cast at he have ht : ‖((s:ℝ)*(1-(τ:ℝ))) • realVector w‖ ≤ (s:ℝ)*(1-(τ:ℝ)) := by rw [norm_smul,Real.norm_eq_abs,abs_of_nonneg (mul_nonneg hs' (sub_nonneg.mpr ht1'))] exact mul_le_of_le_one_right (mul_nonneg hs' (sub_nonneg.mpr ht1')) hw have hqn : ‖realVector q‖ ≤ s := by have hb := norm_le_norm_sub_add (realVector q) (((s:ℝ)*(1-(τ:ℝ))) • realVector w) nlinarith [mul_nonneg hs' ht'] refine ⟨he,hqn,?_⟩ have hd : ‖((s:ℝ)*(1-(τ:��))) • realVector w-(s:ℝ) • realVector w‖ ≤ (s:ℝ)*τ := by rw [← sub_smul,norm_smul,Real.norm_eq_abs] have hx : (s:ℝ)*(1-(τ:ℝ))-(s:ℝ) = -((s:ℝ)*τ) := by ring rw [hx,abs_neg,abs_of_nonneg (mul_nonneg hs' ht')] exact mul_le_of_le_one_right (mul_nonneg hs' ht') hw have hb := norm_sub_le_norm_sub_add_norm_sub (realVector q) (((s:ℝ)*(1-(τ:ℝ))) • realVector w) ((s:ℝ) • realVector w) linarithend CurrentKS.RationalRoot
end OAIlean/OAI/Analysis/MatrixSigning/Matrices/PSDSeparation.leanAdded+59
lean/OAI/Analysis/MatrixSigning/Matrices/PivotTerminalMachine.leanAdded+140
lean/OAI/Analysis/MatrixSigning/Matrices/PosLower.leanAdded+50
lean/OAI/Analysis/MatrixSigning/Matrices/PreservedMatrixRetrieval.leanAdded+50
lean/OAI/Analysis/MatrixSigning/Matrices/RankFactor.leanAdded+88
lean/OAI/Analysis/MatrixSigning/Matrices/RationalElimination.leanAdded+72
lean/OAI/Analysis/MatrixSigning/Matrices/RationalPSDDecision.leanAdded+29
lean/OAI/Analysis/MatrixSigning/Matrices/RealDecode.leanAdded+93
lean/OAI/Analysis/MatrixSigning/Matrices/RealTrace.leanAdded+141
lean/OAI/Analysis/MatrixSigning/Matrices/RealTraceSum.leanAdded+45
lean/OAI/Analysis/MatrixSigning/Matrices/RealifyHermitian.leanAdded+40
lean/OAI/Analysis/MatrixSigning/Matrices/RetractH.leanAdded+129
lean/OAI/Analysis/MatrixSigning/Matrices/RowDotBody.leanAdded+110
lean/OAI/Analysis/MatrixSigning/Matrices/RowDotBounds.leanAdded+186
lean/OAI/Analysis/MatrixSigning/Matrices/RowDotControl.leanAdded+110
lean/OAI/Analysis/MatrixSigning/Matrices/RowDotCounter.leanAdded+75
lean/OAI/Analysis/MatrixSigning/Matrices/RowDotMachine.leanAdded+110
lean/OAI/Analysis/MatrixSigning/Matrices/RowDotModel.leanAdded+74
lean/OAI/Analysis/MatrixSigning/Matrices/RowDotPrimitives.leanAdded+105
lean/OAI/Analysis/MatrixSigning/Matrices/RowDotRegisters.leanAdded+15
lean/OAI/Analysis/MatrixSigning/Matrices/Sandwich.leanAdded+117
lean/OAI/Analysis/MatrixSigning/Matrices/Sandwich2.leanAdded+92
lean/OAI/Analysis/MatrixSigning/Matrices/SandwichCLM.leanAdded+49
lean/OAI/Analysis/MatrixSigning/Matrices/SandwichShiftInverse.leanAdded+72
lean/OAI/Analysis/MatrixSigning/Matrices/SavedPivotPacketMachine.leanAdded+130
lean/OAI/Analysis/MatrixSigning/Matrices/SavedPivotStack.leanAdded+112
lean/OAI/Analysis/MatrixSigning/Matrices/Space.leanAdded+139
lean/OAI/Analysis/MatrixSigning/Matrices/SquareScalarBound.leanAdded+52
lean/OAI/Analysis/MatrixSigning/Matrices/SquareShift.leanAdded+43
lean/OAI/Analysis/MatrixSigning/Matrices/TraceCLM.leanAdded+98
lean/OAI/Analysis/MatrixSigning/Matrices/UniformElimination.leanAdded+89
lean/OAI/Analysis/MatrixSigning/Matrices/UniformEliminationHeight.leanAdded+49
lean/OAI/Analysis/MatrixSigning/Model.leanAdded+137
lean/OAI/Analysis/MatrixSigning/Optimization/Affine.leanAdded+100
lean/OAI/Analysis/MatrixSigning/Optimization/AffineRealEval.leanAdded+125
lean/OAI/Analysis/MatrixSigning/Optimization/BlockScalar.leanAdded+91
lean/OAI/Analysis/MatrixSigning/Optimization/ComplexValueProgram.leanAdded+78
lean/OAI/Analysis/MatrixSigning/Optimization/Coordinates.leanAdded+148
lean/OAI/Analysis/MatrixSigning/Optimization/EliminationWitnessHeight.leanAdded+195
lean/OAI/Analysis/MatrixSigning/Optimization/EquivSymmetricMap.leanAdded+22
lean/OAI/Analysis/MatrixSigning/Optimization/FaceStencil.leanAdded+164
lean/OAI/Analysis/MatrixSigning/Optimization/Feasible.leanAdded+89
lean/OAI/Analysis/MatrixSigning/Optimization/FinRealify.leanAdded+156
lean/OAI/Analysis/MatrixSigning/Optimization/FixedPart.leanAdded+114
lean/OAI/Analysis/MatrixSigning/Optimization/InverseEliminationBounds.leanAdded+151
lean/OAI/Analysis/MatrixSigning/Optimization/Level.leanAdded+90
lean/OAI/Analysis/MatrixSigning/Optimization/Lookup.leanAdded+134
lean/OAI/Analysis/MatrixSigning/Optimization/MinList.leanAdded+53
lean/OAI/Analysis/MatrixSigning/Optimization/NearestEndpoint.leanAdded+95
lean/OAI/Analysis/MatrixSigning/Optimization/NegativeDirection.leanAdded+135