A Formal Framework for Naturally Specifying and Verifying Sequential Algorithms

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Yang, Chengxi, Wu, Shushu, Cao, Qinxiang
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866908343676698624
author Yang, Chengxi
Wu, Shushu
Cao, Qinxiang
author_facet Yang, Chengxi
Wu, Shushu
Cao, Qinxiang
contents Current approaches for formal verification of algorithms face important limitations. For specification, they cannot express algorithms naturally and concisely, especially for algorithms with states and flexible control flow. For verification, formal proof based on Hoare logic cannot reflect the logical structure of natural proof. To address these challenges, we introduce a formal framework for naturally specifying and verifying sequential algorithms in Coq. We use the state relation monad to integrate Coq's expressive type system with the flexible control flow of imperative languages. It supports nondeterministic operations and customizable program states, enabling specifying algorithms at an appropriate level of abstraction. For verification, we build a Hoare logic for the monad and propose a novel two-stage proof approach that separates natural logical reasoning from mechanical composition. It reflects the logical structure of natural proof, enhancing modularity and readability. We evaluate the framework by formalizing the Depth-First Search (DFS) algorithm and verifying the Knuth-Morris-Pratt (KMP) algorithm.
format Preprint
id arxiv_https___arxiv_org_abs_2504_19852
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle A Formal Framework for Naturally Specifying and Verifying Sequential Algorithms
Yang, Chengxi
Wu, Shushu
Cao, Qinxiang
Programming Languages
Current approaches for formal verification of algorithms face important limitations. For specification, they cannot express algorithms naturally and concisely, especially for algorithms with states and flexible control flow. For verification, formal proof based on Hoare logic cannot reflect the logical structure of natural proof. To address these challenges, we introduce a formal framework for naturally specifying and verifying sequential algorithms in Coq. We use the state relation monad to integrate Coq's expressive type system with the flexible control flow of imperative languages. It supports nondeterministic operations and customizable program states, enabling specifying algorithms at an appropriate level of abstraction. For verification, we build a Hoare logic for the monad and propose a novel two-stage proof approach that separates natural logical reasoning from mechanical composition. It reflects the logical structure of natural proof, enhancing modularity and readability. We evaluate the framework by formalizing the Depth-First Search (DFS) algorithm and verifying the Knuth-Morris-Pratt (KMP) algorithm.
title A Formal Framework for Naturally Specifying and Verifying Sequential Algorithms
topic Programming Languages
url https://arxiv.org/abs/2504.19852