Skip to content

Trocq Interface Rework #76

Description

@MysaaJava

This Issue is here to discuss a rework of the interface of Trocq, so as to allow better control by the user.
Here are the things we would like to add:

  • Access the parametricity relation from Rocq i.e. use Trocq to compute X @ T ~ X' because XR, and allow the user to register X' and XR to the global context
  • A notion of Trocq databases in which Trocq translations are registered. The user can create and populate their own databases, and they can decide which ones to use when using trocq.
  • Add a way of directly opening a goal for the parametricity witness when one gives two grefs G and G' and a level at which they should be translated (see Trocq command opening goals #26)
  • Adding a etrocq tactic that open new goals for missing translations instead of failing (see this comment on Trocq command opening goals #26)

This issue aims at discussing the API syntax, which we want to be stable across Trocq updates.
Here is the latest syntax proposition:

(* Adds translations to a database*)
Trocq Register A B C. (* By default, core database is selected *)
Trocq Register A B C : mydb. (* Create or add to database mydb *)
Trocq Register D E : mydb mydb2. (* Adds the two translatinos to mydb and mydb2, which creates database mydb2 *)

Trocq Register G @ T ~ G' because GR (* This would add GR to the database and it would make sure it is understood correctly *)

#[unsafe]  Trocq Register D : mydb. (* Disables warning when D is registered to mydb *)

(* Database inclusion *)
Trocq Register DB mydbA mydbB : mydb1 mydb2. (* Links mydbA and mydbB to be included in mydb1 and mydb2 *)

(* Prove directly *)
Trocq Prove A at T ~ B. (* Opens a proof goal for [[T]] A B. Creates a Gref and adds it to database core *)
Trocq Prove A at T. (* Opens two proof goals for B : tr(T) and [[T]] A B. *)
#[because=truc_R] Trocq Prove A at T ~ B. (* Same as above, the created Gref has name truc_R *)
Trocq Prove A at T ~ B : mydb. (* Same as above, but we add the gref to the database mydb *)
Trocq Prove A at T ~ B : . (* Same as above, but we don't add the gref to any database *)

(* Registering axioms *)
Trocq Axiom axiom. (* Trocq should detect what kind has this axiom (whether it is univalence or funext) *)

(* Calling the `trocq` tactic in proof mode *)
trocq. (* By default, trocq with core *)
trocq with *. (* Emits warning: Which db actually used *)
trocq with mydb.
trocq using RNat. (* like Register + with but locally *)
trocq using *. (* Later ? Register all in local context *)
trocq to term.
etrocq. (* Same syntax as above, adds every remaining evar that cannot be computed as a goal. For example, when Trocq has a gref with no translation, or if the gref has a translation which is not strong enough. *)

(* Calling the full parametricity translation *)
(* This hooks the `derive` vernac that already exists in coq-elpi *)
(* That's why we can't change the interface as we want *)
#[with=(mydb)] derive truc.
#[using=(RNat)] derive truc.
#[to=blabla] derive truc.
#[at=aterm] derive truc. (* Or list of classes *)
#[as=truc'] derive truc.
#[because=truc_R] derive truc.
#[db= "mydb"] derive truc.

(* Activate coercion hooks *)
Trocq Coercion On. (* Activates the hook with database core *)
Trocq Coercion On with db1 db2. (* Activates the hook with databases db1 and db2 *) 

(* Prints *)
Trocq Print Translations. (* Prints translations in core *)
Trocq Print Translations A. (* Prints translations in core for gref A *)
Trocq Print Translations A with mydb. (* Prints translations in mydb for gref A *)
Trocq Print Translations with mydb. (* Prints all translations in mydb *)
Trocq Print Translations with *. (* Print all translations in every db -- This may be overkill *)
Trocq Print DB. (* Prints the name of every databases with their inclusion graph *)

(* Logging *)
Trocq Logging off. (* Trocq is silent except for Rocq warnings/errors and printing *)
Trocq Logging a b. (* Activates logging for modules a and b *)
Trocq Logging a -b. (* Activates logging for a and disables logging for module b *)

(* Help Message*)
Trocq Usage.

Questions:

  • Should databases be identified by string or by grefs ?
  • Should core be excluded when not specified, or should we add a special argument no-core ? Or maybe a special database ?
  • The questions i raised in this message have not been answered
(Personal references about how to implement the things above in Elpi)

The following code sample show an example on how to do it in Elpi and how we could use it.

From elpi Require elpi.

Elpi Tactic trocq.param44.
Elpi Accumulate lp:{{

solve (goal Ctx _ G Statement [trm From, trm To]) [] :-
  if (var G) (G = {{ Type}}) true,
  Statement = {{ True }}.

}}.
Elpi Export trocq.param44.

Lemma foo : trocq.param44 bool nat.
Check param44.

nat bool.

(this example is wrong, we should use trocq.param [44] 44 list array for example)

For creating a goal directly, here's the API, using api in this example, which is documented in README of coq-elpi

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Fields

No fields configured for Feature.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions