Formal Verification of COO to CSR Sparse Matrix Conversion (Invited Paper)
Appel
We describe a machine-checked correctness proof of a C program that converts a coordinate-form (COO) sparse matrix to a compressed-sparse-row (CSR) matrix. The classic algorithm (sort the COO entries in lexicographic order by row,column; fill in the CSR arrays left to right) is concise but has rather intricate invariants. We illustrate a bottom-up methodology for deriving the invariants from the program.
본 논문은 좌표 형식(COO) 희소 행렬을 압축 희소 행(CSR) 행렬로 변환하는 C 프로그램을 검증하기 위한 기계 검사 정확성 증명을 기술한다. 고전적 알고리즘(행과 열의 사전식 순서로 COO 항목을 정렬; 좌에서 우로 CSR 배열 채우기)은 간결하지만 상당히 복잡한 불변식을 가진다. 본 논문은 프로그램으로부터 불변식을 도출하기 위한 상향식 방법론을 제시한다.
struct csr_matrix *coo_to_csr_matrix(struct coo_matrix *p) {
// 1. COO 항목을 (행,열) 사전식 순서로 정렬
coo_quicksort(p, 0, n);
// 2. 중복되지 않은 좌표 쌍의 개수 계산
k = coo_count(p);
// 3. CSR 배열 공간 할당
// 4. 정렬된 COO 항목을 순회하여 CSR 구조 구성
for (i=0; i<n; i++) {
// 중복 항목, 새 열, 새 행 등의 경우 처리
}
}
Record coo_matrix (t: type) := {
coo_rows: Z;
coo_cols: Z;
coo_entries: list (Z * Z * ftype t)
}.
Record csr_matrix {t: type} := {
csr_cols: Z;
csr_vals: list (ftype t);
csr_col_ind: list Z;
csr_row_ptr: list Z;
csr_rows: Z := Zlength (csr_row_ptr) - 1
}.
Inductive sum_any {t}: list (ftype t) → ftype t → Prop :=
| Sum_Any_0: sum_any nil (Zconst t 0)
| Sum_Any_1: ∀ x, sum_any [x] x
| Sum_Any_split: ∀ al bl a b, sum_any al a → sum_any bl b →
sum_any (al++bl) (BPLUS a b)
| Sum_Any_perm: ∀ al bl s, Permutation al bl → sum_any al s → sum_any bl s.
Barrett et al. (1994): Templates for the Solution of Linear Systems - 희소 행렬 알고리즘의 고전 참고 자료
Appel & Kellison (2024): VCFloat2 - 부동소수점 오류 분석 도구
Cao et al. (2018): VST-Floyd - 분리 논리 검증 도구
Kellison et al. (2023): LAProof - 선형 대수 프로그램의 형식 증명 라이브러리
요약: 본 논문은 복잡한 수치 알고리즘의 완전한 형식 검증의 실행 가능성을 입증하고, 실용적인 검증 방법론을 제시하며, 신뢰할 수 있는 과학 계산 소프트웨어 개발에 중요한 기여를 한다. 검증 비용이 높지만, 실제 오류 발견의 가치와 제공되는 방법론 지침은 이를 해당 분야의 중요한 연구로 만든다.