coq / platform-docs

A project of short tutorials and how-to guides for Coq features and Coq Platform packages.
https://coq.inria.fr/platform-docs/
Other
19 stars 10 forks source link

Integrate Comments to Equations Tutorial Basics #19

Closed thomas-lamiaux closed 5 months ago

thomas-lamiaux commented 5 months ago

Integrate Comments to Equations Tutorial Basics

Hint Rewrite @nth_option_nil : nth_option.

And now the first `autorewrite` goes through.
I'm not sure it is something you want to flash here, or even later, but it might confuse learners that you talk about computation…
- [X] l187: on [a, …, a] -> on [a1, …, an]
- [X] l194: is it intentional that `map` is filled, but not the other two? (It would make sense to me that you want to give at least one example, but force people to look for themselves in the other too, until we get a better set-up for exercises)
- [X] l219: the functions -> functions, can not -> cannot (here and in other places)
- [X] l245-246: `Arguments` is probably not precise enough to be able to say what one would want to say ("simplify exactly when the list of arguments matches one of the patterns of the definition"), but your proposed version is *very aggressive*. Usually, for `app` I'd rather do `Arguments app !_ /.` (which means "unfold `app` when it is applied to at least one argument and that argument is a constructor). There's also the `simpl nomatch` invocation, which I've never used but seems relevant…
- [X] l266: mention how each equalities are named (it always takes me forever to find it again)? Although using the database is usually the sensible way to go, sometimes its useful to be able to summon the exact equality…
- [X] l266: declares -> proves, and again below
- [X] l266: in a database -> collected in a hint database
- [x] l271: when doing in proof as compared to cbn the user … -> in proofs compared to cbn, as the user…
Also, this is misleading: by using `cbn [f1 … fn]` one can obtain a similar behaviour. So it's maybe best not to mention this point at all.
- [X] l277: uses -> use
- [X] l278: We can similarly -> make this explicitly an exercise?
- [X] l295: detruct
- [X] l300: a more idiomatic way would be `induction l in n |- *` (although I know in the end you want to say "functional induction is better" anyway).
- [x] l309: I'd say the important aspect is not that the inductive types can get more complicated (although they certainly can), but that the functions might not be simply following the structure of the types, without even talking about [with]/[where] clauses? Like in the most trivial example

Equations half (n : nat) : nat := half 0 := 0 ; half 1 := 0 ; half (S (S n)) := S (half n).


- [X] l311-313: maybe mention that this is called functional induction? Attempt:
> Consequently, for each definition, [Equations] derives a functional induction
> principle: this is an induction principle that follows the structure of the
> function, including deep pattern-matching, [with] and [where] clauses,
> correct induction hypotheses and generalisation as in the above example, etc.
> This induction principle can be accessed by using the [funelim] tactic.
- [X] l318: do your induction -> do the induction on (or better? induct on)
- [X] l320: let's -> let us (here and other places)
- [X] l352: to automatically simply by when -> use for automatic simplification
- [X] l356: to make it automatic -> this way
- [X] l358: by the syntax -> with the following syntax
Maybe make it clear that this is not about Equations per se, but simply using the
general rewriting hint mechanism of Coq?
- [X] l360: name_function -> function_name
- [X] l362: provides us with -> provides a
- [X] l363-364: I would rephrase to
> However, note that this mechanism is expressive enough to be
> non-terminating if the wrong lemmas are added to the database.
- [x] Add something as to the fact that the default lemmas are always safe, ie
confluent and terminating?
- [X] In general, I would replace "please note" with simply "note"
- [X] l400: what is "it"?
- [X] l404: I would rephrase to "… happens in such proofs by functional induction that
after simplification we get a lot of uninteresting cases, that we would like to
deal with in an automatic but controlled way."
- [x] l409: a proof search by -> a proof search using
"a particular instance" is rather vague, do you mean it uses `try typeclasses eauto with …` using a given set of hints? Then you should say so, mention what the databases are and what they do.
- [X] l447: you are doing -> you want to do?
(Good examples, especially `app_nth2`, I would never have thought about doing
`funelim (nth_option n l)` despite `nth_option n l` appearing nowhere in my goal!)
- [x] It is a bit weird to mention the useful lemmas but not import the corresponding files. And you might suggest using `lia` instead, which gets rid of these arithmetic goals without needing to find the right lemma.
- [x] Maybe you should also mention somewhere that you can use `simp in H` and `simp in *` to also simplify in the hypotheses? This is useful in these exercises…
- [x] Before 2: you do not have any example of a deep pattern-matching, as in the `half` example above. Maybe it would be useful to have something like this to show the power of `funelim`?
- [X] l479: Agda -> dependently-typed programming community? (Ie Idris has it too for instance)
- [X] l498: verify -> satisfy
- [X] l532: |with] -> [with]
- [X] l537: makes a subclause… -> does a case-split corresponding to the [with] clause?
- [X] l539: the sentence is strange, attempt:
> For [filter], in the [p a = true] case, a [filter_clause_1] appears, and
> similarly in the [false] case.
- [X] l541: [Equations] -> [Equations]' 
- [X] l541-544: I wonder whether this is an opportunity for polishing on the Equations side…
- [X] l568: requiring for the input … different than -> requiring the input … different from
- [X] l566: They can also be useful to… -> Finally, [with] clauses can be used to…
- [X] l571: as -> has
- [X] l604: your function -> your functions
- [X] l625: using … -> using the usual [Equations] syntax/using [Equations]' usual syntax
- [X] l651: maybe add some `About rev_acc_elim.` at this point so that we get to see what its type is?
- [X] l656: `exact … ` -> `1: exact …` (I'm picky about goal selectors :p) (and below)
- [X] l665: automatised -> automated
- [X] l676: now you use `simp in` without having introduced it before!
thomas-lamiaux commented 5 months ago

@MevenBertrand can you elaborate on:

Also the behaviour of funelim should change soon, c.f. this comment https://github.com/Zimmi48/platform-docs/pull/1#issuecomment-2098810034

thomas-lamiaux commented 5 months ago

Refactored 1.2 to adapt to the comments

MevenBertrand commented 5 months ago

what is the point of reasoning with rewrite than cbn according to you ? I'm not sure I understand the question ^^'

I wanted to be more specific about simp, but I have no idea what subterm and Below are These are hint databases used to respectively solve goals related to the subterm relation (whenever you Derive Subterm … various lemmas about that subterm relation are generated and added to the hint database), and well-foundedness assumption. If you want to know what is in a hint database, Print HintDb … is your friend :)

thomas-lamiaux commented 5 months ago

@MevenBertrand Could you check section 1.2 and tell me if you are satisfied by the modifications ?

thomas-lamiaux commented 5 months ago

Merging now, thanks for the insight @MevenBertrand !