13

What would be some useful guidelines for converting Coq source to Idris (e.g. how similar are their type systems and what can be made of translating the proofs)? From what I gather, Idris' built-in library of tactics is minimal yet extendable, so I suppose with some extra work this should be possible.

Arets Paeglis
  • 3,856
  • 4
  • 35
  • 44
  • 1
    I would love to be able to do "software foundations" via Idris. It seems a good way to learn it. 6 upvotes and 4 stars. Anyone care to provide feedback? Lots of newbs want to know. –  Aug 25 '15 at 00:31
  • 1
    This is maybe not related, but I guess that you would like a language to do both proofs and programming. You can also directly use Coq to do programming, with the (rather new) [Coq.io](http://coq.io/) library. This library adds IO and concurrency primitives to Coq, with some techniques to certify them. _Full disclamer: I am the main author of Coq.io_ – Clarus Nov 25 '15 at 15:21

1 Answers1

8

I've recently translated a chunk of Software Foundations and did a partial port of {P|N|Z}Arith, some observations I've made in the process:

Generally using Idris tactics (in their Pruvloj/Elab.Reflection form) is not really recommended at the moment, this facility is somewhat fragile, and pretty hard to debug when something goes wrong. It's better to use the so-called "Agda style", relying on pattern matching where possible. Here are some rough equivalences for simpler Coq tactics:

  • intros - just mention variables on the LHS
  • reflexivity - Refl
  • apply- calling the function directly
  • simpl - simplification is done automatically by Idris
  • unfold - also done automatically for you
  • symmetry - sym
  • congruence/f_equal - cong
  • split - split in LHS
  • rewrite - rewrite ... in
  • rewrite <- - rewrite sym $ ... in
  • rewrite in - to rewrite inside something you have as a parameter you can use the replace {P=\x=>...} equation term construct. Sadly Idris is not able to infer P most of the time, so this becomes a bit bulky. Another option is to extract the type into a lemma and use rewrites, however this won't always work (e.g., when replace makes a large chunk of a term disappear)
  • destruct - if on a single variable, try splitting in LHS, otherwise use the with construct
  • induction - split in LHS and use a recursive call in a rewrite or directly. Make sure that at least one of arguments in recursion is structurally smaller, or you'll fail totality and won't be able to use the result as a lemma. For more complex expressions you can also try SizeAccessible from Prelude.WellFounded.
  • trivial - usually amounts to splitting in LHS as much as possible and solving with Refls
  • assert - a lemma under where
  • exists - dependent pair (x ** prf)
  • case - either case .. of or with. Be careful with case however - don't use it in anything you will later want to prove things about, otherwise you'll get stuck on rewrite (see issue #4001). A workaround is to make top-level (currently you can't refer to lemmas under where/with, see issue #3991) pattern-matching helpers.
  • revert - "unintroduce" a variable by making a lambda and later applying it to said variable
  • inversion - manually define and use trivial lemmas about constructors:

    -- injectivity, used same as `cong`/`sym`
    FooInj : Foo a = Foo b -> a = b
    FooInj Refl = Refl
    
    -- disjointness, this sits in scope and is invoked when using `uninhabited`/`absurd`
    Uninhabited (Foo = Bar) where   
      uninhabited Refl impossible   
    
  • 1
    This is great, thank you for your effort and the detailed answer. For that matter, would you happen to know if Pruviloj or something similar to it is to be developed further? – Arets Paeglis Oct 02 '17 at 16:41
  • 1
    Probably not by its creator, David Christiansen, I think he is mostly working on Racket nowadays. Contributions are still welcome, I've personally added a couple of tactics to Pruviloj :) In the longer run, there's an ongoing effort by Edwin Brady to rewrite the Idris core in Idris itself, which will likely include a rewrite of the elaborator as well. – Alexander Gryzlov Oct 02 '17 at 17:27
  • 1
    A bunch of comments to this nice answer: (1) `intros` is a little bit more than just adding some parameters if one uses the so-called `intros`-patterns (these are mostly parameters + destructuring + rewriting); (2) `reflexivity` is quite a complex tactic, it has several fall-backs, can work with setoids and one-constructor datatypes; (3) `apply` does some extra stuff as well; (4) Coq's `congruence` tactic is much more powerful than the `cong` lemma from Idris. `congruence` is a decision procedure for ground equalities with uninterpreted symbols. – Anton Trunov Oct 02 '17 at 20:29
  • Wow, the software foundations rewrite looks awesome! I really wish that I have found it earlier while learning Idris, but it will still be very helpful for me! Thank you very much! – Isti115 Apr 02 '19 at 18:18