Skip to content

Commit 879f430

Browse files
authored
Merge pull request rocq-community#58 from rocq-community/minor-tutorial-updates
Minor tutorial updates
2 parents 756f0bf + 8f74863 commit 879f430

11 files changed

Lines changed: 53 additions & 43 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ in the [INSTALL.md file](INSTALL.md).
7777

7878
## Documentation
7979

80-
See the [tutorial](artifact-doc/TUTORIAL.md) for concrete use cases.
80+
See the [tutorial](https://rocq-community.org/trocq/index.html#/quick-start) for concrete use cases.
8181

8282
In short, the plugin provides a tactic:
8383
- `trocq` (without arguments) which attempts to run a translation on

docs/home.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,7 @@ and readable code with respect to a sequent-style theoretical presentation.
4545

4646
## Building and installation instructions
4747

48-
As **Trocq** is a prototype, it is currently unreleased, and depends on a
49-
[custom version](https://github.com/ecranceMERCE/coq-elpi/tree/strat)
50-
of **Coq-Elpi**. It is not yet packaged in **Opam** or **Nix**, but will be in
51-
the near future.
52-
53-
There are however three ways to develop it and experiment with it,
54-
they are documented in the [INSTALL.md file](https://github.com/coq-community/trocq/blob/master/INSTALL.md) of the repository.
48+
See the [INSTALL.md file](https://github.com/coq-community/trocq/blob/master/INSTALL.md) of the repository.
5549

5650
## Documentation
5751

docs/quick-start.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ First, we present the use of Trocq to perform proof transfer along type equivale
55
Then, we handle the case of weaker, directed relations.
66
Finally, we give several examples of multiple transfer featuring polymorphic and dependent containers.
77

8+
## Installation
9+
10+
See the [INSTALL.md file](https://github.com/coq-community/trocq/blob/master/INSTALL.md) of the repository.
11+
We recommend the Nix or OPAM solutions, other solutions mentionned in that file may be outdated.
12+
813
## Proof transfer with type isomorphisms
914

1015
In this first section, we show two examples of isomorphisms: natural numbers with unary and binary representations, and bitvectors.
@@ -34,6 +39,8 @@ Inductive N : Set :=
3439
| Npos : positive -> N.
3540
```
3641

42+
?> These definitions, along with a few results to be used later, are available in file [N.v](https://github.com/coq-community/trocq/blob/master/examples/std/N.v).
43+
3744
A binary natural number of type `N` is either zero (`N0`) or a `positive` binary number (`Npos`) composed of a sequence of digits (`xI` and `xO`), starting from the least significant byte and always ending with a one (`xH`).
3845

3946
Both `nat` and `N` types come with an induction principle generated by Coq.
@@ -62,6 +69,8 @@ Lemma N_Srect : forall (P : N -> Type),
6269
Proof. Fail apply nat_rect. Abort.
6370
```
6471

72+
?> See file [artifact_paper_example.v](https://github.com/coq-community/trocq/blob/master/examples/std/artifact_paper_example.v).
73+
6574
Unfortunately, `nat_rect` cannot be used directly to prove `N_Srect` here, since the types of the induction principles cannot be unified.
6675
Indeed, by default, Coq does not know `N` and `nat` represent the same concept, and that the zero and successors of `N` are associated to the ones of `nat`.
6776

@@ -117,10 +126,17 @@ Such functions and properties can be packed into an `Iso` record and given to Tr
117126
```coq
118127
Definition N_nat_iso : Iso.type N nat := Iso.Build N_to_natK N_of_natK.
119128
120-
Definition N_nat_R : Param44.Rel N nat := Iso.toParam N_nat_iso.
129+
Definition N_nat_R : Param44.Rel N nat := Iso.toParamSym N_nat_iso.
121130
Trocq Use N_nat_R.
122131
```
123132

133+
?> See files
134+
[N.v](https://github.com/coq-community/trocq/blob/master/examples/std/N.v)
135+
and
136+
[artifact_paper_example.v](https://github.com/coq-community/trocq/blob/master/examples/std/artifact_paper_example.v)
137+
where `N_to_natK` and `N_of_natK` are named respectively `to_natK` and
138+
`of_natK` and the notation `(N <=> nat)%P` stands for `Param44.Rel N nat`.
139+
124140
In order to perform proof transfer for `N_Srect`, we need to declare in Trocq all the remaining constants appearing in the goal, that is, `N0` and `N_succ`.
125141

126142
#### Operations and constants
@@ -157,6 +173,8 @@ Proof.
157173
Qed.
158174
```
159175

176+
?> See file [artifact_paper_example.v](https://github.com/coq-community/trocq/blob/master/examples/std/artifact_paper_example.v)
177+
160178
?> A careful analysis shows that in order to transfer this goal to `nat`, only information up to level `(2a,3)` in `N_nat_R` was used. It means that we could have only proved `N_to_natK` and the transfer would still have been possible. A way to declare the minimal amount of information is to run `trocq` without adding any information, and follow the error message asking for a specific level, until all the requirements are met and the tactic succeeds.
161179

162180
### Bounded natural numbers and bitvectors
@@ -168,6 +186,9 @@ Definition bounded_nat (k : nat) := {n : nat & n < 2^k}.
168186
Definition bitvector (k : nat) := Vector.t bool k.
169187
```
170188

189+
?> See file
190+
[Vector_tuple.v](https://github.com/coq-community/trocq/blob/master/examples/std/Vector_tuple.v).
191+
171192
The required type of the Trocq relation between these type formers is the following:
172193
```coq
173194
forall (k k' : nat) (kR : natR k k'), ParamXY.Rel (bounded_nat k) (bitvector k')
@@ -342,6 +363,9 @@ Definition Z_Zmodp_R : Param42a.Rel Z Zmodp := SplitSurj.toParam Z_Zmodp_surj.
342363
Trocq Use Z_Zmodp_R.
343364
```
344365

366+
?> See file
367+
[flt3_step.v](https://github.com/coq-community/trocq/blob/master/examples/std/flt3_step.v).
368+
345369
?> To give a slightly different example, here we relate `Z` to `Zmodp`, aiming to rephrase a goal expressed with the bigger type `Z` as a goal expressed with `Zmodp`, instead of pulling the goal in the subtype back to a more general goal, as it was done for `positive` and `N` above.
346370

347371
If we define an equality over `Z` checking whether both values are congruent to each other modulo `p`, and use it in a general goal expressed with `Z`, if we relate it to a classic equality over `Zmodp`, Trocq can rephrase the general goal as a goal over `Zmodp` (we omit the details about multiplication and the zero here, as they have been covered in the previous examples):
@@ -369,6 +393,9 @@ Qed.
369393

370394
!> Coming soon...
371395

396+
?> Meanwhile, one can look into file
397+
[summable.v](https://github.com/coq-community/trocq/blob/master/examples/std/summable.v).
398+
372399
## Polymorphic and dependent container types
373400

374401
As shown in the first section of this tutorial, as Trocq has support for the whole syntax of CCω, in particular, it supports dependent types.
@@ -532,6 +559,9 @@ Definition option_list_inj (A : Type) : @SplitInj.type (option A) (list A) :=
532559
Definition Param_option_list_d (A : Type) : Param42b.Rel (option A) (list A) :=
533560
SplitInj.toParam (option_list_inj A).
534561
```
562+
?> See file
563+
[list_option.v](https://github.com/coq-community/trocq/blob/master/examples/std/list_option.v).
564+
535565
?> Note that again, we assume we are in a setup where relations linking the target standard type were defined previously. Here, it allows relating `option A` to `list A` and leaving the step changing the parameter `A` to an `A'` to the parametricity lemma over lists.
536566

537567
By transitivity, we can state the full relation and add it to Trocq:
@@ -590,4 +620,4 @@ Such an approach enables refinement-like transfer, by expressing the statements
590620

591621
Consider the encoding of matrices in the [MathComp library](https://github.com/math-comp/math-comp), where `'M[T](m,n)` denotes a matrix of size `m`X`n` with elements in `T`.
592622

593-
!> To be continued...
623+
!> To be continued...

examples/N.v

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
(* * see LICENSE file for the text of the license *)
1212
(*****************************************************************************)
1313

14+
Require Import ssreflect.
1415
From Trocq Require Import Stdlib Common.
15-
From mathcomp Require Import ssreflect.
1616

1717
Set Universe Polymorphism.
1818
Set Bullet Behavior "Strict Subproofs".
@@ -109,18 +109,11 @@ Fixpoint of_nat (n : nat) : N :=
109109

110110
(* from ssrnat, inlined because ssrnat clashes with HoTT. *)
111111
Lemma addn0 : forall n, (n + 0)%nat = n.
112-
Proof.
113-
move=> n; induction n as [|n IHn] => //= ;
114-
rewrite IHn ;
115-
done.
116-
Qed.
112+
Proof. by move=> n; induction n as [|n IHn] => //=; rewrite IHn. Qed.
117113
Lemma addSn : forall n m, (S n + m)%nat = S (n + m)%nat.
118-
Proof. done. Qed.
114+
Proof. by []. Qed.
119115
Lemma addnS : forall n m, (n + S m)%nat = S (n + m)%nat.
120-
Proof.
121-
move=> n m; induction n as [|n IHn] => /= [//|].
122-
by rewrite IHn //.
123-
Qed.
116+
Proof. by move=> n m; induction n as [|n IHn] => /= [//|]; rewrite IHn //. Qed.
124117

125118
Lemma of_natD i j : of_nat (i + j) = (of_nat i + of_nat j)%N.
126119
Proof.

examples/artifact_paper_example.v

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414
Require Import ssreflect.
1515
From Trocq Require Import Stdlib Trocq.
1616
From Trocq_examples Require Import N.
17-
From elpi Require Import elpi.
1817

1918
Set Universe Polymorphism.
2019

21-
(*Elpi Trace.*)
22-
2320
(** In this example, we transport the induction principle on natural numbers
2421
from two equivalent representations of `N`: the unary one `nat` and the binary
2522
one `N`. We introduce the `Trocq Use` command to register such translations.
@@ -45,4 +42,3 @@ Proof. trocq. (* replaces N by nat in the goal *) exact nat_rect. Defined.
4542
independence. *)
4643
Set Printing Depth 20.
4744
Print Assumptions N_Srec.
48-

examples/std/Vector_tuple.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ Definition Param44_bnat_bv (k k' : nat) (kR : natR k k') :
362362
Param44.Rel (bounded_nat k) (bitvector k').
363363
Proof.
364364
unshelve eapply (@Param44_trans _ (bitvector k) _).
365-
- exact Param44_bnat_bv_d.
365+
- exact Param44_bnat_bv_d.
366366
- exact (Vector.Param44 bool bool Param44_Bool k k' kR).
367367
Defined.
368368

@@ -382,7 +382,7 @@ Axiom getBit_bnat : forall {k : nat}, bounded_nat k -> nat -> bool.
382382
Axiom setBitR :
383383
forall
384384
(k k' : nat) (kR : natR k k')
385-
(bn : bounded_nat k) (bv' : bitvector k')
385+
(bn : bounded_nat k) (bv' : bitvector k')
386386
(r : R_trans
387387
(@R_bnat_bv k) (Vector.Param44 bool bool Param44_Bool k k' kR) bn bv')
388388
(n n' : nat) (nR : natR n n')
@@ -395,7 +395,7 @@ Axiom setBitR :
395395
Axiom getBitR :
396396
forall
397397
(k k' : nat) (kR : natR k k')
398-
(bn : bounded_nat k) (bv' : bitvector k')
398+
(bn : bounded_nat k) (bv' : bitvector k')
399399
(r : R_trans
400400
(@R_bnat_bv k) (Vector.Param44 bool bool Param44_Bool k k' kR) bn bv')
401401
(n n' : nat) (nR : natR n n'),

examples/std/flt3_step.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
(* * see LICENSE file for the text of the license *)
1212
(*****************************************************************************)
1313

14-
Require Import ssreflect.
1514
From mathcomp Require Import all_ssreflect all_algebra.
1615
From Trocq Require Import Stdlib Trocq.
1716

@@ -164,7 +163,7 @@ Trocq Use Param01_Empty.
164163
Trocq Use Param10_Empty.
165164

166165
Lemma flt3_step : forall (m n p : ℤ),
167-
((m * n * p)%Z % 3)%Z ≢ 0 -> (m³ + n³)%ℤ ≠ p³%ℤ.
166+
((m * n * p)%Z % 3)%Z ≢ 0 -> (m³ + n³)%ℤ ≠ p³%ℤ.
168167
Proof.
169168
trocq=> /=.
170169

examples/std/square_and_cube_mod7.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
(* * see LICENSE file for the text of the license *)
1212
(*****************************************************************************)
1313

14-
Require Import ssreflect.
1514
From mathcomp Require Import all_ssreflect all_algebra.
1615
From Trocq Require Import Stdlib Trocq.
1716

examples/std/stuck.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,3 @@ reflexivity.
6868
Qed.
6969

7070
End Works.
71-

examples/std/trocq_setoid_rewrite.v

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ Existing Instance eqp_sym.
3232
#[local] Axiom (eqp_trans : Transitive eqmodp).
3333
Existing Instance eqp_trans.
3434

35-
#[local] Axiom add_morph :
36-
forall m m' : int, (m == m')%int ->
37-
forall n n' : int, (n == n')%int ->
38-
(m + n == m' + n')%int.
35+
#[local] Axiom add_morph :
36+
forall m m' : int, (m == m')%int ->
37+
forall n n' : int, (n == n')%int ->
38+
(m + n == m' + n')%int.
3939

40-
Definition eqmodp_morph :
41-
forall m m' : int, (m == m')%int ->
42-
forall n n' : int, (n == n')%int ->
40+
Definition eqmodp_morph :
41+
forall m m' : int, (m == m')%int ->
42+
forall n n' : int, (n == n')%int ->
4343
(m' == n')%int -> (m == n)%int.
4444
Proof.
4545
move=> m m' Rm n n' Rn Rmn.
4646
exact (eqp_trans _ _ _ Rm (eqp_trans _ _ _ Rmn (eqp_sym _ _ Rn))).
4747
Qed.
4848

49-
Lemma eqmodp01 :
50-
forall m m' : int, (m == m')%int ->
51-
forall n n' : int, (n == n')%int ->
49+
Lemma eqmodp01 :
50+
forall m m' : int, (m == m')%int ->
51+
forall n n' : int, (n == n')%int ->
5252
Param01.Rel (m == n)%int (m' == n')%int.
5353
Proof.
5454
move=> m m' Rm n n' Rn.

0 commit comments

Comments
 (0)