You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/quick-start.md
+32-2Lines changed: 32 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,11 @@ First, we present the use of Trocq to perform proof transfer along type equivale
5
5
Then, we handle the case of weaker, directed relations.
6
6
Finally, we give several examples of multiple transfer featuring polymorphic and dependent containers.
7
7
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
+
8
13
## Proof transfer with type isomorphisms
9
14
10
15
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 :=
34
39
| Npos : positive -> N.
35
40
```
36
41
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
+
37
44
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`).
38
45
39
46
Both `nat` and `N` types come with an induction principle generated by Coq.
?> See file [artifact_paper_example.v](https://github.com/coq-community/trocq/blob/master/examples/std/artifact_paper_example.v).
73
+
65
74
Unfortunately, `nat_rect` cannot be used directly to prove `N_Srect` here, since the types of the induction principles cannot be unified.
66
75
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`.
67
76
@@ -117,10 +126,17 @@ Such functions and properties can be packed into an `Iso` record and given to Tr
117
126
```coq
118
127
Definition N_nat_iso : Iso.type N nat := Iso.Build N_to_natK N_of_natK.
119
128
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.
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
+
124
140
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`.
125
141
126
142
#### Operations and constants
@@ -157,6 +173,8 @@ Proof.
157
173
Qed.
158
174
```
159
175
176
+
?> See file [artifact_paper_example.v](https://github.com/coq-community/trocq/blob/master/examples/std/artifact_paper_example.v)
177
+
160
178
?> 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.
?> 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.
346
370
347
371
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):
?> 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.
536
566
537
567
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
590
620
591
621
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`.
0 commit comments