Giter Club home page Giter Club logo

bertrand's Introduction

Bertrand

Docker CI Contributing Code of Conduct Zulip DOI

A Coq proof of Bertrand's postulate, which says that there always exists a prime between n and 2n for n greater than 2. Includes an application of the postulate to compute partitions.

Meta

Building and installation instructions

The easiest way to install the latest released version of Bertrand is via OPAM:

opam repo add coq-released https://coq.inria.fr/opam/released
opam install coq-bertrand

To instead build and install manually, do:

git clone https://github.com/coq-community/bertrand.git
cd bertrand
make   # or make -j <number-of-cores-on-your-machine> 
make install

Contents

This project consists of:

  • A Coq proof of Bertrand's postulate: there always exists a prime between n and 2n for n greater than 2 (Bertrand.v).
  • A little program in OCaml, based on code extracted from Coq, that generates a partition of 1..2n in pairs (i,j) such that i+j is always prime (run_partition.ml). The proof of correctness of this program is a direct consequence of Bertrand's postulate (Partition.v). This nice application of Bertrand's postulate was suggested by Gérard Huet.
  • A proof of correctness of an implementation of the algorithm for computing primes described in "The Art of Computer Programming: Fundamental Algorithms" by Knuth, pages 147-149. The proof uses the Why3 tool to generate verification conditions for the WhyML program that implements the algorithm. These verification conditions can then be discharged by Coq and the Alt-Ergo prover.

Extracting and running the OCaml partition program

To extract code and obtain the program, run

make run_partition.ml

Next, open an OCaml toplevel (e.g., ocaml) and do

#use "run_partition.ml";;

To get a partition from 1...30:

let part30 = part 15;;

Replaying the WhyML program correctness proof

To replay the proof of correctness for the WhyML program for computing primes, first make sure the following packages are installed (in addition to Coq 8.18.0 and the proof of Bertrand's postulate):

These packages can be installed via OPAM using the following command:

opam install alt-ergo.2.5.4 why3.1.7.2 why3-coq.1.7.2

Then, the proof can be replayed by running

make why

bertrand's People

Contributors

herbelin avatar letouzey avatar palmskog avatar ppedrot avatar thery avatar zimmi48 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bertrand's Issues

Idea: port Why program to C and verify with VST

The Why program (Knuth.mlw) is unfortunately out of date with respect to recent releases of the Why toolchain; there is a modern Why program version available that is, however, "less verified" than the program here. One way to solve this, and verify fully down to assembly level, would be to convert Knuth.mlw to C and use VST, bringing the program, its semantics, and the proof all fully into Coq. Such a conversion is not easy, so I will simply leave it here as a cool idea.

Transfer of Bertrand's postulate to CoqPrime

The first part of this project, the proof of Bertrand's postulate, is a generic result about primes, and could be useful to a larger audience. One way to accomplish this is to have the proof transferred into the CoqPrime project, which is in the Coq Platform and has regular releases compatible with the latest released version of Coq. However, this may require reorganization and adaptation to CoqPrime idioms.

After a tentative transfer, the project here could focus fully on providing verified programs that use Bertrand's postulate (on top of CoqPrime), both using the Why toolchain and using other means. Such programs and proofs are likely to have a much smaller audience, but are still very valuable to the community.

Opam package compiling with Coq 8.10

Hi @Zimmi48: I updated "bertrand" to 8.9 and 8.10 and pushed corresponding tags v8.9.0 and v8.10.0.

I did not create/update an opam package for compilation with 8.9 and 8.10. There is an opam template in the archive which I could use, but I lost track of whom is supposed to be in charge of it (the opam file says it is @palmskog but the header of the repository says it is @herbelin).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.