Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a tips page to the book #881

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
Draft

Add a tips page to the book #881

wants to merge 7 commits into from

Conversation

michaelpj
Copy link

This is a collection of tips I picked up during the workshop.

michaelpj and others added 3 commits June 2, 2023 09:10
This is a collection of tips I picked up during the workshop.
@wadler
Copy link
Member

wadler commented Jun 2, 2023

Thanks, Michael!

(Wen, I asked Michael to make this pull request. He has a useful tips file, and it makes sense to add it to the book as backmatter. I hope others will submit new tips.)

@michaelpj
Copy link
Author

Hmm, something is unhappy but I'm not sure what.

@wenkokke
Copy link
Collaborator

wenkokke commented Jun 4, 2023

Fixed the issue. You were missing an epub-type and, apparently, triggering some obscure Pandoc 2.19 bug?

@wenkokke wenkokke self-requested a review June 4, 2023 20:52
src/plfa/backmatter/Tips.md Show resolved Hide resolved
```
?2 = suc (suc (x + y)) = y_5244
```
i.e. your LHS and an unknown RHS (because it's a hole), but it will show the LHS fully computed, which you can copy into your file directly.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to disambiguate LHS and RHS for the reader.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also just remove ?2 and surrounding spaces (or replace it with refl) and then auto on the next ? below.

src/plfa/backmatter/Tips.md Show resolved Hide resolved
The first example computes to `foo b + (foo b + zero)`, but the second one does not compute at all: Agda can't pattern match on `foo b`, it could be anything!

Doing this lets Agda do more definitional simplification, which means you have to do less work.
Unfortunately it does require you to know _which_ arguments are the one that Agda can evaluate, which requires looking at the definitions of the functions.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some general advice we can probably give here to help people guess which arguments are evaluated, e.g., left associative operators tend to evaluate their left argument.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps tell people about jump-to-definition?


However, notably they all use the same supporting proofs!
That means you can often write the overall proof however you find easiest and then rewrite it into another form if you want.
For example, do the proof slowly with equational reasoning, and then turn it into a compact proof with `rewrite`.
Copy link
Collaborator

@wenkokke wenkokke Jun 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd hesitate to advise folks to rewrite their readable equational reasoning proofs into less readable rewrite ones.

I'd ask that you remove that particular tip.

(It's also not obvious that such a rewrite always works.)

∀ {s : ℕ} {s‵ : ℕ}
→ Tree A s
→ Tree A s
→ s‵ ≡ s + s
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a regular quote or a prime, but this seems to be a backtick?

@wenkokke wenkokke marked this pull request as draft November 13, 2023 19:27
This sets up a series of reasoning steps with holes for both the expressions at each step, and the step itself.
Since the reasoning steps are holes, Agda will always accept this, so you can make incremental progress while keeping your file compiling.

Now call "solve" (`C-c C-s` in Emacs).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run C-c C-a (auto) instead, which has the added benefit of getting rid of the hole in a single step. (At least in vscode I need to C-c C-space to give after solving.)

That means you can often write the overall proof however you find easiest and then rewrite it into another form if you want.
For example, do the proof slowly with equational reasoning, and then turn it into a compact proof with `rewrite`.

## Avoid mutual recursion in proofs by recursing outside the lemma
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand what this advice is trying to say, but it's a bit unclear. The title just adds to the confusion.

I think what you are trying to say here is that we should try to break up a proof into small lemmas, that do one reasoning step, which we then compose to get the overall goal?


## Avoiding "green slime"

"Green slime" is when you use a function in the index of a returned data type value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe some explanation why "green slime"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further reading here: https://proofassistants.stackexchange.com/a/1615 (There is also a link to Connor's paper that coined this term.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants