Ramanujan's Notebooks, Part I, Ch. 1: ch1DiagSum
DefinitionRamanujanNotebooks_ch01_ch1DiagSumnumber-theoryramanujan-notebooks
Sum of the main diagonal M 0 0 + M 1 1 + ⋯ + M (n-1) (n-1) of an n × n array of
natural numbers (rows indexed first, top to bottom; columns second, left to right).
A finite sum: no domain restriction, no junk value.
Reference: for ![![6, 1, 8], ![7, 5, 3], ![2, 9, 4]] the value is 6 + 5 + 4 = 15.
Definition code
import Mathlib
namespace RamanujanNotebooks
/-- Sum of the main diagonal `M 0 0 + M 1 1 + ⋯ + M (n-1) (n-1)` of an `n × n` array of
natural numbers (rows indexed first, top to bottom; columns second, left to right).
A finite sum: no domain restriction, no junk value.
Reference: for `![![6, 1, 8], ![7, 5, 3], ![2, 9, 4]]` the value is `6 + 5 + 4 = 15`. -/
def ch1DiagSum {n : ℕ} (M : Fin n → Fin n → ℕ) : ℕ :=
∑ i : Fin n, M i i
end RamanujanNotebooks
Source
Bruce C. Berndt, Ramanujan's Notebooks, Part I (Springer, 1985), Chapter 1.