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
fix: repair many examples in manual to run in isolation (#617)
There are a few dozen `:::example` directives in the manual that won't
run correctly if you copy and paste them into
https://live.lean-lang.org/ . Fix them all, and include a CI check to
ensure that they are all fixes. A sampling of reasons include:
- `#check_decl` is defined in reference manual but not available in live
- `import`s of `Lean` or `Std` are missing
- `open`s prior to the `:::example` are necessary
- important definitions are in `+error` blocks and needed to be hoisted
.
Progress towards leanprover/verso#569 .
Copy file name to clipboardExpand all lines: Manual/Axioms.lean
+18-13Lines changed: 18 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -272,8 +272,8 @@ Consider the following three constants:
272
272
273
273
```lean
274
274
defaddThree (n : Nat) : Nat := 1 + n + 2
275
-
theoremexcludedMiddle (P : Prop) : P ∨ ¬ P := Classical.em P
276
-
theoremsimpleEquality (P : Prop) : (P ∨ False) = P := or_false P
275
+
theoremexcluded_middle (P : Prop) : P ∨ ¬ P := Classical.em P
276
+
theoremsimple_equality (P : Prop) : (P ∨ False) = P := or_false P
277
277
```
278
278
279
279
Regular functions like {lean}`addThree` that we might want to actually evaluation typically do not depend on any axioms:
@@ -288,35 +288,40 @@ Regular functions like {lean}`addThree` that we might want to actually evaluatio
288
288
The excluded middle theoremisonlytrueifweuseclassicalreasoning,sothefoundationforclassicalreasoningshowsupalongsideotheraxioms:
289
289
290
290
```lean (name := printAxEx1)
291
-
#print axioms excludedMiddle
291
+
#print axioms excluded_middle
292
292
```
293
293
```leanOutput printAxEx1
294
-
'excludedMiddle' depends on axioms: [propext, Classical.choice, Quot.sound]
294
+
'excluded_middle' depends on axioms: [propext, Classical.choice, Quot.sound]
295
295
```
296
296
297
297
Finally, the idea that two equivalent propositions are equal directly relies on {tech}[propositional extensionality].
298
298
299
299
```lean (name := printAxEx3)
300
-
#print axioms simpleEquality
300
+
#print axioms simple_equality
301
301
```
302
302
```leanOutput printAxEx3
303
-
'simpleEquality' depends on axioms: [propext]
303
+
'simple_equality' depends on axioms: [propext]
304
304
```
305
305
:::
306
306
307
307
:::example"Using {keywordOf Lean.Parser.Command.printAxioms}`#print axioms` with {keywordOf Lean.guardMsgsCmd}`#guard_msgs`"
308
308
309
-
You can use {keywordOf Lean.Parser.Command.printAxioms}`#print axioms` togetherwith {keywordOf Lean.guardMsgsCmd}`#guard_msgs` to ensure that updates to libraries from other projects cannot silently introduce unwanted dependencies on axioms.
309
+
You can use {keywordOf Lean.Parser.Command.printAxioms}`#print axioms`
310
+
together with {keywordOf Lean.guardMsgsCmd}`#guard_msgs` to ensure
311
+
that updates to libraries from other projects cannot silently
312
+
introduce unwanted dependencies on axioms.
310
313
311
-
Perhaps you are worried that some future update to {lean}`or_false`inthe previous example's {lean}`simpleEquality` proof might quietly introduce a new axiomdependency.
312
-
Youcanguardagainstthisbywritingacommandthatwillfailif {lean}`simpleEquality` uses any axioms besides {lean}`propext`:
314
+
For example, ifthe proof of {name}`double_neg_elim` below changed in such a way that it used more
315
+
axioms than those listed, then the {keywordOf Lean.guardMsgsCmd}`#guard_msgs` would report an error.
313
316
314
317
```lean
315
-
/--
316
-
info: 'simpleEquality' depends on axioms: [propext]
@@ -64,6 +68,10 @@ In many programming languages, it is important to remember to check for the null
64
68
When using {name}`Option`, the type system requires these checks in the right places: {lean}`Option α` and {lean}`α` are not the same type, and converting from one to the other requires handling the case of {lean (type := "Option α")}`none`.
65
69
This can be done via helpers such as {name}`Option.getD`, or with pattern matching.
Copy file name to clipboardExpand all lines: Manual/Grind/Algebra.lean
+27-1Lines changed: 27 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,9 @@ open Lean Grind
37
37
```
38
38
39
39
:::example"Commutative Rings" (open := true)
40
+
```lean -show
41
+
open Lean.Grind
42
+
```
40
43
```lean
41
44
example [CommRing α] (x : α) : (x + 1) * (x - 1) = x ^ 2 - 1 := by
42
45
grind
@@ -45,6 +48,9 @@ example [CommRing α] (x : α) : (x + 1) * (x - 1) = x ^ 2 - 1 := by
45
48
:::example"Ring Characteristics" (open := true)
46
49
The solver “knows” that `16*16 = 0` because the [ring characteristic](https://en.wikipedia.org/wiki/Characteristic_%28algebra%29) (that is, the minimum number of copies of the multiplicative identity that sum to the additive identity) is `256`, which is provided by the {name}`IsCharP` instance.
Even when the characteristic is not initially known, when `grind` discovers that `n = 0` for some numeral `n`, it makes inferences about the characteristic:
97
115
```lean
98
116
example [CommRing α] (a b c : α)
@@ -163,7 +181,9 @@ It also rewrites every disequality `p ≠ 0` as the equality `p * p⁻¹ = 1`.
163
181
:::
164
182
165
183
::::example"Fields and `grind`"
166
-
184
+
```lean -show
185
+
open Lean.Grind
186
+
```
167
187
This example requires its {name}`Field`instance:
168
188
169
189
```lean
@@ -198,6 +218,9 @@ For example, the polynomial `2 * x * y + 4 * z = 0` is simplified to `x * y + 2
198
218
Italsousedwhenprocessingdisequalities.
199
219
200
220
:::example"Using `NoNatZeroDivisors`"
221
+
```lean -show
222
+
open Lean.Grind
223
+
```
201
224
In this example, {tactic}`grind` relies on the {name}`NoNatZeroDivisors`instancetosimplifythegoal:
202
225
```lean
203
226
example [CommRing α] [NoNatZeroDivisors α] (a b : α) :
@@ -310,6 +333,9 @@ example (x y : Nat) :
310
333
Gröbner basis computation can be very expensive. You can limit the number of steps performed by the `ring` solver using the option `grind (ringSteps := <num>)`
311
334
312
335
:::example"Limiting `ring` Steps"
336
+
```lean -show
337
+
open Lean.Grind
338
+
```
313
339
This example cannot be solved by performing at most 100 steps:
314
340
```lean +error (name := ring100)
315
341
example [CommRing α] [IsCharP α 0] (d t c : α) (d_inv PSO3_inv : α) :
:::example"Commutative Ring Goals Decided by `linarith`" (open := true)
72
-
78
+
```imports
79
+
import Std
80
+
```
81
+
```lean -show
82
+
open Lean.Grind
83
+
```
73
84
For types that are commmutative rings (that is, types in which the multiplication operator is commutative) with {name}`CommRing` instances, `linarith` has more capabilities.
0 commit comments