Is it possible to write C programs using Coq?
Asked Answered
S

2

10

I know that one can extract Coq programs into Haskell and OCaml programs. Is there a way to do this with C?

I am imagining a library that models the C language. Maybe such a library would contain a collection of axioms about how C constructs interact with process memory, and axioms and theorems about IEEE floating point numbers. Then it would be able to build a C program within Coq along with theorems about the program.

I would use such a library, say, to build a C quicksort algorithm that works on arrays of floats that would be compilable by GCC.

Sulfapyridine answered 23/10, 2017 at 21:3 Comment(0)
I
10

C is not available as an extraction target for Coq programs; only OCaml and Haskell are supported. However, we can still use Coq to write verified C software: the Verified Software Toolchain, for example, allows us to translate C programs to a format that Coq understands and prove theorems about their behavior. Note that these proofs have a different flavor than you might be used to if you have done any proofs about Coq programs, because the C program is simply converted to its syntax tree as a Coq data type, instead of a Coq function.

Irrawaddy answered 23/10, 2017 at 21:43 Comment(1)
The book edited by Andrew Appel is a bit out of date with the current VST, but it's a good introduction to the ideas.Closeknit
S
4

There is a new Software Foundations chapter that deals with the practicals of interfacing Coq and C.

Sulfapyridine answered 31/12, 2020 at 21:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.