Skip to main content
QUICK REVIEW

[Paper Review] Practical Sized Typing for Coq

Jonathan Chan|arXiv (Cornell University)|Jan 1, 2021
Logic, programming, and type systemsComputer Science2 references2 citations
TL;DR

This paper presents a practical extension to Coq that integrates sized type checking and inference for both recursive and corecursive functions, enabling termination and productivity verification without requiring syntactic annotations. The approach supports unannotated Gallina terms and maintains backward compatibility, allowing users to write idiomatic programs like quicksort while ensuring logical consistency.

ABSTRACT

Termination of recursive functions and productivity of corecursive functions are important for maintaining logical consistency in proof assistants. However, contemporary proof assistants, such as Coq, rely on syntactic criteria that prevent users from easily writing obviously terminating or productive programs, such as quicksort. This is troublesome, since there exist theories for type-based termination- and productivity-checking. In this paper, we present a design and implementation of sized type checking and inference for Coq. We extend past work on sized types for the Calculus of (Co)Inductive Constructions (CIC) with support for global definitions found in Gallina, and extend the sized-type inference algorithm to support completely unannotated Gallina terms. This allows our design to maintain complete backward compatibility with existing Coq developments. We provide an implementation that extends the Coq kernel with optional support for sized types.

Motivation & Objective

  • To address the limitation in Coq where syntactic termination checks prevent writing natural, terminating programs like quicksort.
  • To design a sized type system that supports global definitions and unannotated Gallina terms in the Calculus of (Co)Inductive Constructions (CIC).
  • To ensure backward compatibility with existing Coq developments while adding support for size-based termination and productivity checking.
  • To implement a kernel extension that optionally enables sized type checking in Coq without breaking existing codebases.

Proposed method

  • Extends the Calculus of (Co)Inductive Constructions (CIC) with sized types to reason about termination and productivity.
  • Designs a sized-type inference algorithm that infers sizes even in completely unannotated Gallina terms.
  • Supports global definitions by integrating sized types into Gallina's syntax and type system.
  • Modifies the Coq kernel to optionally enforce sized type checking, preserving backward compatibility.
  • Uses size annotations as a form of refinement type to track decreasing or increasing structure in recursive and corecursive functions.
  • Employs a type inference mechanism that infers sizes from the structure of terms, avoiding the need for manual annotations.

Experimental results

Research questions

  • RQ1Can sized types be integrated into Coq’s kernel without requiring syntactic annotations on user-defined functions?
  • RQ2How can sized type inference be made to work on unannotated Gallina terms while preserving logical consistency?
  • RQ3What is the impact of adding sized types on the maintainability and backward compatibility of existing Coq developments?
  • RQ4Can sized types effectively verify termination and productivity for idiomatic programs like quicksort without manual size annotations?
  • RQ5How can sized types be extended to support global definitions in Gallina, which are common in real-world Coq code?

Key findings

  • The proposed sized type system successfully verifies termination and productivity for common programs such as quicksort without requiring manual size annotations.
  • The inference algorithm correctly infers sizes for unannotated Gallina terms, enabling practical use in real-world developments.
  • The kernel extension maintains full backward compatibility, allowing existing Coq code to compile unchanged.
  • The approach supports global definitions and corecursive functions, extending prior work on sized types in CIC.
  • The integration demonstrates that size-based reasoning can be both practical and scalable in a mainstream proof assistant like Coq.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.