NLA-lib Explorer

Ordinary CG

Implementation of Conjugate gradient (CG)

Mathematical method

Algorithm

The standard carried-residual implementation of CG.

The detailed CG preview requires matching core-source metadata. This section will be filled by the source adapter.

Model of arithmetic

Definitions of the arithmetic models · Other programs of this algorithm: CG with full reorthogonalization (Exact arithmetic · BLAS + matvec)

The first three models are for the program of the listing, built from vector operations and a matrix–vector product that is a primitive. They differ in what those operations may return. The last model is for a program lowered from it: the matrix is stored entry by entry, and every matrix–vector product and vector operation is written out as scalar loops, so its only primitives are scalar operations and comparisons.

Operations and Storage

These counts are at the level of vector operations and hold for the three models built from BLAS and matvec calls. The stored scalar program has its own instruction count, stated with its theorem.

The detailed CG preview requires matching core-source metadata. This section will be filled by the source adapter.

Accuracy

The detailed CG preview requires matching core-source metadata. This section will be filled by the source adapter.

The detailed CG preview requires matching core-source metadata. This section will be filled by the source adapter.

The detailed CG preview requires matching core-source metadata. This section will be filled by the source adapter.

The certified program is Krylov.CG.HSCG.Carried.Rounded.Stored.scalarProgram. It starts from \mathbf{x}_0=\mathbf 0, and its rounds are those of the listing with each vector operation and each matrix–vector product replaced by scalar loops over the stored entries. Its work is a count of instructions.

Theorem (Termination, operation count and energy-norm error). Let \mathbf{A}\in\mathbb{R}^{n\times n} be symmetric with spectrum in [a,a^{\prime}], a>0, stored entry by entry, let \mathbf{b}\in\mathbb{R}^n, let k be the iteration cap, and put \kappa=a^{\prime}/a. Scalar arithmetic is any machine in the standard model with unit roundoff u, and comparisons of stored numbers are exact. Let E\le1/100 be an allowance that dominates the rounding of one scalar operation (16u\le E), of one dot product, vector update and scaling of length n, and of one row-by-row matrix–vector product, and assume

3Ea^{\prime}\le a,\qquad k^2\sqrt k\,E\,\kappa^2\le10^{-5}.

Then, for every such input and every tape, the run succeeds, and:

  • it executes at most 33n^2k+157nk+242k+50n+127 instructions, each of unit cost: scalar operations, comparisons, index arithmetic, operand addressing, loop control and allocation;
  • it performs some number m\le k of rounds and stores an iterate \widehat{\mathbf{x}} and a residual vector \widehat{\mathbf{r}}; if m<k, then \widehat{\mathbf{r}}=\mathbf 0;
  • for every solution \mathbf{x} of \mathbf{A}\mathbf{x}=\mathbf{b},

\begin{aligned}&\|\mathbf{x}-\widehat{\mathbf{x}}\|_{\mathbf{A}}^2\\&\quad\le4\Bigl(\frac{\sqrt{2\kappa+1}-1}{\sqrt{2\kappa+1}+1}\Bigr)^{2m}\|\mathbf{x}\|_{\mathbf{A}}^2\\&\quad+\frac{12000\,m^2\sqrt m\,E\,\kappa\,a^{\prime}\,\|\mathbf{b}\|_2^2}{a^2}\\&\quad+\frac{135\,m^2E\,\kappa\,\|\mathbf{b}\|_2^2}{a}.\end{aligned}

Here \|\mathbf{v}\|_{\mathbf{A}}^2=\mathbf{v}^{\mathsf{T}}\mathbf{A}\mathbf{v}. The first term is the exact CG rate at the condition number 2\kappa+1; the other two are the accumulated rounding. The bound is in the number m of rounds performed: reaching the cap is not a convergence claim. The instruction count is an upper bound read off the fixed program.

Lean statement and details

Standard rounding

NLAlib.Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.exec_scalarProgram_work_le_and_quadForm_le
  {lower upper : (Fin 2 → ℕ) → ℝ} {domain : (Fin 2 → ℕ) → Prop} {admitted : ∃ d, domain d}
  {supply :
    ∀ (d : Fin 2 → ℕ),
      domain d → ∃ x, Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.accepts lower upper d x}
  (M : Ops.Machine ℝ) (u : ℝ) (hM : Ops.StdModel u id M) (hu : 0 ≤ u) (em E : (Fin 2 → ℕ) → ℝ)
  (hMatvec : ∀ (d : Fin 2 → ℕ), domain d → Ops.ScalarProducts.roundoff u (d 0) * √↑(d 0) ≤ em d)
  (hAccuracy :
    ∀ (d : Fin 2 → ℕ), domain d → Ops.Standard.Accuracy (em d) u (E d) (Ops.Blas.seq.err u) (d 0))
  (ha : ∀ (d : Fin 2 → ℕ), domain d → 0 < lower d)
  (hprec : ∀ (d : Fin 2 → ℕ), domain d → 3 * E d * upper d ≤ lower d)
  (hwindow :
    ∀ (d : Fin 2 → ℕ), domain d → ↑(d 1) ^ 2 * √↑(d 1) * E d * (upper d / lower d) ^ 2 ≤ 1 / 10 ^ 5)
  {d : Fin 2 → ℕ} (hd : domain d)
  (x :
    (Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.problem lower upper domain admitted
          supply).Input
      d)
  (I : Ops.Interp Ops.ScalarOp Ops.CmpTst ℝ)
  (hI :
    (Ops.RoundedScalarBlas.model
          (Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.problem lower upper domain admitted
            supply)
          M).contracts
      d x I)
  (τ : Ops.Tape ℝ) :
  ∃ st,
    Ops.Reference.Execution Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.scalarProgram I
        Ops.RoundedScalarBlas.resources
        (Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.problem lower upper domain admitted
            supply).formats
        τ d
        ((Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.problem lower upper domain admitted
              supply).initial
          d x)
        st ∧
      Ops.RoundedScalarBlas.resources.work st.cost ≤
          33 * d 0 ^ 2 * d 1 + 157 * d 0 * d 1 + 242 * d 1 + 50 * d 0 + 127 ∧
        ∃ m ≤ d 1,
          ∃ s rho,
            Krylov.CG.HSCG.Carried.Rounded.StoresValues id (d 0) (2, 0) (3, 0) (4, 0) (5, 0) s rho
                st.mem ∧
              (m < d 1 → s.r = 0) ∧
                ∀ (xs : Fin (d 0) → ℝ),
                  Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.inputMatrix x *ᵥ xs =
                      Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.inputRhs x →
                    quadForm (Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.inputMatrix x)
                        (xs - s.x) ≤
                      4 *
                              ((√(2 * (upper d / lower d) + 1) - 1) /
                                  (√(2 * (upper d / lower d) + 1) + 1)) ^
                                (2 * m) *
                            quadForm
                              (Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.inputMatrix x)
                              xs +
                          2 *
                                ‖WithLp.toLp 2
                                      (Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.inputRhs
                                        x)‖ ^
                                  2 *
                              (6000 * ↑m ^ 2 * √↑m * E d * (upper d / lower d) * upper d) /
                            lower d ^ 2 +
                        135 * ↑m ^ 2 * E d * (upper d / lower d) *
                          (‖WithLp.toLp 2
                                  (Krylov.CG.HSCG.Carried.Rounded.Stored.Certification.inputRhs
                                    x)‖ ^
                              2 /
                            lower d)

Full source on GitHub

Copy link

Not yet presented

  • A certificate for a general starting guess in the rounded models. The rounded theorems above are for the program that starts from \mathbf{x}_0=\mathbf 0.
  • The exact and the BLAS-level rounded certificates of the stored program, in which the matrix is stored and the vector operations remain primitives.
  • The finite-precision results about the CG run model are on the theory page finite-precision Krylov methods, not on this page.