                                What Makes In-context Learning Effective for Mathematical Reasoning

A. Proof of Theorem 1                                                        Therefore, now the question turns to evaluate
We interpret the attention mechanism in ICL setting as: 1)                                def                  −1
We have a linear function F(z) with initialized parameters                          L1 = ∇W L(htest , Ŵ )T · HŴ ∇W L(z0 , Ŵ ).            (31)

                        WV                                                   Specifically, L1 can be represented as L1 =
                   W0 = √ htest · (WK htest )T .                 (25)
                         d
                                                                                                                       −1
                                                                              (∇W L(z0 , Ŵ ) − ∇W L(htest , Ŵ ))T · HŴ ∇W L(htest , Ŵ )
2) We introduce a training data z0 = WK h to optimize the                     |                          {z
                                                                                                                   L11
                                                                                                                                          }
parameters, with the gradient at (z0 , W0 ) satisfies                                               T       −1
                                                                              + ∇W L(htest , Ŵ )        · HŴ ∇W L(htest , Ŵ )
                                       WV                                       |                        {z                   }
                      ∇F L(z0 , W0 ) = √ h.                      (26)                                    L12
                                        d                                                                                                    (32)

 3) We finally apply the optimized parameters to calculate                   Since HŴ is positive definite, there exists an orthogonal
the result of test data htest .                                              matrix O and a diagonal matrix Σ = diag(λ1 , ..., λdd′ )
                                                                                          −1
                                                                             satisfying HŴ   = OT · Σ · O, where λ1 ≥ λ2 ≥ ... ≥
Theorem 1. Assume ∇F L is Lipschitz continuous w.r.t                                                           −1
F with constant µ. If inequality (7) holds true, then                        λdd′ > 0 are the eigenvalues of HŴ  . For L11 , it equals
L(htest , Ŵ |D 1 | ,z0 ) < L(htest , Ŵ0,z0 ), i.e., introducing
               pre                                                           (O(∇W L(z0 , Ŵ ) − ∇W L(htest , Ŵ )))T diag(λ1 , ..., λdd′ )·
the training sample z0 (i.e., demonstration X) can reduce                    |                  {z                  }
                                                                                                    aT
the testing loss on htest . λ 1 ′ , λ11 are the largest and small-                                                       q       q
                             dd                                                                                ′             ′ 2      ′
est eigenvalues of HŴ , respectively.                                       O∇W L(htest , Ŵ ) = Σdd
                                                                                                   i=1 λi ai bi ≥ −       Σdd a
                                                                                                                           i=1 i   Σdd
                                                                                                                                    i=1 (λi bi )
                                                                                                                                                 2
                                                                             |    {z          }
                                                                                      b
 λdd′                                         WV
      ∥∇W L(htest , Ŵ )∥ > ∥htest − z0 ∥ · (∥ √ h∥ + µC1 )                  ≥ −λ1 ∥∇W L(htest , Ŵ )∥ · ∥∇W L(htest , Ŵ ) − ∇W L(z0 , Ŵ ))∥
  λ1                                            d                                                              
                WV                                                           ≥ −λ1 ∥∇W L(htest , Ŵ )∥ · ∥F lat ∇F L(htest , Ŵ ) · hT
                                                                                                                                     test
         C1 = ∥ √ htest ∥ · ∥WK htest ∥ · ∥htest ∥
                    d
                                                                                                     
                                                                                                   T
                                                        (27)                   − ∇F L(z0 , Ŵ ) · z0 ∥
                                                                                                         
Proof. With Ŵ , Ŵϵ,z0 , the influence of upweighting z0 on                 ≥ −λ1 ∥∇W L(htest , Ŵ )∥ · ∥F lat((∇F L(htest , Ŵ )−
the parameters Ŵ is (Ling, 1984; Koh & Liang, 2017):                                                                                                  
                                                                               ∇F L(z0 , Ŵ )) · hT                                              T
                                                                                                  test )∥ + ∥F lat(∇F L(z0 , Ŵ ) · (htest − z0 ) )∥
                                                                                                           
                                    dŴϵ,z0                                  = −λ1 ∥∇W L(htest , Ŵ )∥ · ∥∇F L(htest , Ŵ ) − ∇F L(z0 , Ŵ )∥
            Iparameter (z0 ) =
                                      dϵ                         (28)                                                       
                                       ϵ=0
                                   −1
                                                                               · ∥htest ∥ + ∥∇F L(z0 , Ŵ )∥ · ∥htest − z0 ∥ ,
                               = −HŴ ∇W L(z0 , Ŵ ),
                                                                                                                                           (33)
                                                                              where F lat(W ) is the operation that flatten a matrix W ∈
and the influence on the loss function is:                                     ′                             ′
                                                                             Rd ×d into a vector of length Rd d . Since ∇F L is Lipschitz
                                                                             continuous, we get L11 ≥
                   dL(htest , Ŵϵ,z0 )
   Iloss (z0 ) =
                         dϵ                                                    − λ1 ∥∇W L(htest , Ŵ )∥ · (µ∥Ŵ (htest − z0 )∥ · ∥htest ∥+
                                         ϵ=0

                                          dŴϵ,z0                (29)          ∥∇F L(z0 , Ŵ )∥ · ∥htest − z0 ∥)
              = ∇W L(htest , Ŵ )T ·                                                                                                         (34)
                                            dϵ
                                                    ϵ=0
                                       −1                                    Applying Eqs. (25)(26) to Eq. (34), we have:
              = −∇W L(htest , Ŵ )T · HŴ ∇W L(z0 , Ŵ )
                                                                                                     q
                                                                              ∥Ŵ (htest −z0 )∥ =     (htest − z0 )T Ŵ T Ŵ (htest − z0 )
Then, the testing loss L(htest , Ŵ |D 1 | ,z0 ) can be evaluated                           WV
                                           pre                                            =∥ √ htest ∥ · |(WK htest )T (htest − z0 )|        (35)
                                           1                                                  d
by Taylor approximation since |Dpre | is sufficiently small,
                                                                                            WV
i.e., L(htest , Ŵ |D 1 | ,z0 ) ≈                                                         ≤∥ √ htest ∥ · ∥WK htest ∥ · ∥htest − z0 ∥
                      pre                                                                     d

                               1     dL(htest , Ŵϵ,z0 )                                                          WV
      L(htest , Ŵ0,z0 ) +                                                    ∥∇F L(z0 , Ŵ )∥ · ∥htest − z0 ∥ = ∥ √ h∥ · ∥htest − z0 ∥ (36)
                             |Dpre |       dϵ                                                                       d
                                                           ϵ=0
                            1                                    (30)        For L12 , we similarly have:
    =L(htest , Ŵ0,z0 ) −         ∇W L(htest , Ŵ )T
                          |Dpre |
                                                                                                ′
          −1
       · HŴ ∇W L(z0 , Ŵ ).                                                      L12 = Σdd      2
                                                                                         i=1 λi bi ≥ λdd′ ∥∇W L(htest , Ŵ )∥
                                                                                                                              2
                                                                                                                                             (37)

                                                                        12
