Skip to content
Snippets Groups Projects
Forked from David Hamelin / jscoq-light
414 commits behind the upstream repository.
index.html 8.84 KiB
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta name="description" content="An Online IDE for the Coq Theorem Prover" />
    <link rel="icon" href="ui-images/favicon.png">

    <link rel="stylesheet" type="text/css" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
    <style>
      kbd { background: #0003; color: #333; font-size: 80%; }
      table.doc-actions th, table.doc-actions td {
        padding: .2em .5em;
        vertical-align: top;
        border: 1px solid #999;
      }
      table.doc-actions td {
        padding-bottom: .25em;
      }
      h4 {
        background: #f6f9f9;
        padding: 3px;
        color: #089;
        margin-top: 1em;
      }
      h5 {
        margin-top: 12px;
        margin-bottom: 7px;
        font-size: 110%;
        font-style: italic;
        color: #089;
      }
      span.jscoq-name {
        color: #363;
      }
      #team {
        margin-top: 2em;
        border: 1px solid #eee;
        padding: 5px;
      }
      a#scratchpad {
        height: 30px;
        width: 30px;
        background: url(ui-images/scratchpad.png);
        background-repeat: no-repeat;
        background-size: contain;
        border: none;
        outline: none;
        position: absolute;
        top: 5px;
        right: 40px;
      }
    </style>
    <title>jsCoq – Use Coq in Your Browser</title>
  </head>

<body class="jscoq-main">
  <div id="ide-wrapper" class="toggled">
  <div id="code-wrapper">
  <div id="document">
  <a id="scratchpad" href="examples/scratchpad.html" title="Open scratchpad"></a>
  <div>
    <h3>Welcome to the <span class="jscoq-name">jsCoq</span> Interactive Online System!</h3>
    <p>
      Welcome to the <span class="jscoq-name">jsCoq</span> technology demo!
      <span class="jscoq-name">jsCoq</span> is an interactive,
      web-based environment for the Coq Theorem prover, and is a collaborative
      development effort. See the <a href="#team">list of contributors</a>
      below.
    </p>
    <p>
      <span class="jscoq-name">jsCoq</span> is open source. If you find any problem or want to make
      any contribution, you are extremely welcome! We await your
      feedback at <a href="https://github.com/jscoq/jscoq">GitHub</a>
      and <a href="https://coq.zulipchat.com/#narrow/stream/256336-jsCoq">Zulip</a>.
    </p>
    <h4>Instructions:</h4>
    <p>
      The following document contains embedded Coq code.
      All the code is editable and can be run directly on the page.
      Once <span class="jscoq-name">jsCoq</span> finishes loading, you are
      free to experiment by stepping through the proof and viewing intermediate
      proof states on the right panel.
    </p>
    <h5>Actions:</h5>
    <table class="doc-actions">
      <tr><th>Button</th><th>Key binding</th><th>Action</th></tr>
      <tr>
        <td><img src="ui-images/down.png" height="15px"><img src="ui-images/up.png" height="15px"></td>
        <td>
          <kbd>Alt</kbd>+<kbd>↓</kbd>/<kbd>↑</kbd> or<br/>
          <kbd>Alt</kbd>+<kbd>N</kbd>/<kbd>P</kbd>
        </td>
        <td>Move through the proof.</td>
      </tr>
      <tr>
        <td><img src="ui-images/to-cursor.png" height="20px"></td>
        <td>
          <kbd>Alt</kbd>+<kbd>Enter</kbd> or<br/> <kbd>Alt</kbd>+<kbd>→</kbd>
        </td>
        <td>Run (or go back) to the current point.</td>
      </tr>
      <tr>
        <td><img src="ui-images/power-button-512-black.png" height="20px"></td>
        <td><kbd>F8</kbd></td>
        <td>Toggles the goal panel.</td>
      </tr>
    </table>
    <h5>Creating your own proof scripts:</h5>
    <p>
      The <a href="examples/scratchpad.html">scratchpad</a> offers simple, local
      storage functionality. It also allows you to share your development with
      other users in a manner that is similar to Pastebin.
    </p>

    <h4>A First Example: The Infinitude of Primes</h4>
    <p>
      If you are new to Coq, check out this
      <a href="examples/nahas_tutorial.html">introductory tutorial</a> by
      <a href="https://mdnahas.github.io">Mike Nahas</a>.
      As a more advanced showcase, we display a proof of the infinitude of primes in Coq.
      The proof relies on the <a href="https://math-comp.github.io">Mathematical Components</a>
      library from the
      <a href="http://ssr.msr-inria.inria.fr/">MSR/Inria</a> team led
      by Georges Gonthier, so our first step will be to load it:
    </p>
  </div>
  <div>
    <textarea id="addnC" >
From Coq Require Import ssreflect ssrfun ssrbool.
From mathcomp Require Import eqtype ssrnat div prime. </textarea>
  </div>
  <div>
    <h5>Ready to do Proofs!</h5>
    <p>
      Once the basic environment has been set up, we can proceed to
      the proof:
    </p>
  </div> <!-- panel-heading -->
  <div>
    <textarea id="prime_above1" >
(* A nice proof of the infinitude of primes, by Georges Gonthier *)
Lemma prime_above m : {p | m < p & prime p}.
Proof. </textarea>
    <p>
      The lemma states that for any number <code>m</code>,
      there is a prime number larger than <code>m</code>.

      Coq is a <em>constructive system</em>, which among other things
      implies that to show the existence of an object, we need to
      actually provide an algorithm that will construct it.

      In this case, we need to find a prime number <code>p</code>
      that is greater than <code>m</code>.
      What would be a suitable <code>p</code>?

      Choosing <code>p</code> to be the first prime divisor of <code>m! + 1</code>
      works.
      As we will shortly see, properties of divisibility will imply that
      <code>p</code> must be greater than <code>m</code>.
    </p>
    <textarea id="prime_above2" >
have /pdivP[p pr_p p_dv_m1]: 1 < m`! + 1
  by rewrite addn1 ltnS fact_gt0.</textarea>
    <p>
      Our first step is thus to use the library-provided lemma
      <code>pdivP</code>, which states that every number is divided by a
      prime. Thus, we obtain a number <code>p</code> and the corresponding
      hypotheses <code>pr_p : prime p</code> and <code>p_dv_m1</code>,
      "p divides m! + 1".
      The ssreflect tactic <code>have</code> provides a convenient way to
      instantiate this lemma and discard the side proof obligation
      <code>1 &lt; m! + 1</code>.
    </p>
    <textarea id="prime_above3" >
exists p => //; rewrite ltnNge; apply: contraL p_dv_m1 => p_le_m.</textarea>
    <p>
      It remains to prove that <code>p</code> is greater than <code>m</code>.
      We reason by
      contraposition with the divisibility hypothesis, which gives us
      the goal "if <code>p ≤ m</code> then <code>p</code> is not a prime divisor of 
      <code>m! + 1</code>".
    </p>
    <textarea id="prime_above4" >
by rewrite dvdn_addr ?dvdn_fact ?prime_gt0 // gtnNdvd ?prime_gt1.
Qed.</textarea>
    <p>
      The goal follows from basic properties of divisibility, plus
      from the fact that if <code>p ≤ m</code>, then <code>p</code> divides
      <code>m!</code>, so that for <code>p</code> to divide
      <code>m! + 1</code> it must also divide 1,
      in contradiction to <code>p</code> being prime.
    </p>
    <hr/>
  <p>
    <span class="jscoq-name">jsCoq</span> provides many other packages,
    including Coq's standard library and the
    <a href="https://math-comp.github.io"></a>mathematical components</a>
    library.
    Feel free to experiment, and bear with the beta status of this demo.
  </p>
  <p>
    <i>¡Salut!</i>
  </p>
  </div> <!-- /#panel body -->
  <div id="team">
    <a name="team"></a>
      <p><i>The dev team</i></p>
    <ul>
      <li>
        <a href="https://www.irif.fr/~gallego/">Emilio Jesús Gallego Arias</a>
        (<a href="https://www.inria.fr">Inria</a>,
         <a href="https://u-paris.fr">Université de Paris</a>,
         <a href="https://www.irif.fr">IRIF</a>)
      </li>
      <li>
        <a href="https://www.cs.technion.ac.il/~shachari/">Shachar Itzhaky</a>
        (<a href="https://cs.technion.ac.il">Technion</a>)
      </li>
    </ul>
    <p><i>Contributors</i></p>
    <ul>
      <li>
        Benoît Pin
        (<a href="https://www.cri.ensmp.fr/">CRI</a>,
         <a href="http://www.mines-paristech.eu">MINES ParisTech</a>)
      </li>
    </ul>
  </div>
  </div> <!-- /#document -->
  </div> <!-- /#code-wrapper -->
  </div> <!-- /#ide-wrapper -->

  <script src="ui-js/jscoq-loader.js" type="text/javascript"></script>
  <script type="text/javascript">

    var jscoq_ids  = ['addnC', 'prime_above1', 'prime_above2', 'prime_above3', 'prime_above4' ];
    var jscoq_opts = {
        implicit_libs: false,
        focus: false,
        base_path: './',
        editor: { mode: { 'company-coq': true } },
        init_pkgs: ['init'],
        all_pkgs:  ['coq', 'mathcomp', 'equations', 'elpi', 'quickchick', 'lf', 'plf']
    };

    /* Global reference */
    var coq;

    JsCoq.start(jscoq_ids, jscoq_opts).then(res => coq = res);
  </script>
</body>
</html>