You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lean4game/doc/writing_exercises.md

57 lines
1.6 KiB
Markdown

11 months ago
# Writing exercises
This page deals in more details with the `Statement` command and all the options you have
to write better exercises/levels.
## Local `let` definitions
If you want to make a local definition/notation which only holds for this exercise (e.g.
a function `f : := fun x ↦ 2 * x`) the recommended way is to use a `let`-statement:
```lean
Statement (a : ) (h : 0 < a) :
let f : := fun x ↦ 2 * x
0 < f a := by
sorry
```
The game automatically `intros` such `let`-statements, such that you and the player will see
the following initial proof state:
```
a:
h: 0 < a
f: := fun x => 2 * x
⊢ 0 < f a
```
11 months ago
## "Preamble" & non-`Prop`-valued exercises
11 months ago
11 months ago
You can use the following syntax with `(preamble := tac)` where `tac` is a tactic sequence.
11 months ago
```
11 months ago
Statement my_statement (preamble := dsimp) (a : ) (h : 0 < a) :
11 months ago
0 < f a := by
sorry
```
This tactic sequence will be executed before the exercise is handed to the player.
11 months ago
For example, if your exercise is to construct a structure, you could use `preamble` to fill
11 months ago
all data fields correctly, leaving all `Prop`-valued fields of the structure as separate goals
for the player to proof.
11 months ago
Note: `(preamble := tac)` always has to be written between the optional name and the first
11 months ago
hypothesis. Nevertheless, you can use all hypotheses in the tactic sequence, because it is
only evaluated at the beginning of the proof.
## Attributes
You can add attributes as you would for a `theorem`. Most notably, you can make your named exercise a `simp` lemma:
```lean
@[simp]
Statement my_simp_lemma ...
```