|
1 | 1 | /- |
2 | 2 | Copyright (c) 2024 Lean FRO LLC. All rights reserved. |
3 | 3 | Released under Apache 2.0 license as described in the file LICENSE. |
4 | | -Author: David Thrane Christiansen |
| 4 | +Author: David Thrane Christiansen, Joachim Breitner |
5 | 5 | -/ |
6 | 6 |
|
7 | 7 | import VersoManual |
8 | | -import Manual.Language.RecursiveDefs.Structural.RecursorExample |
9 | | -import Manual.Language.RecursiveDefs.Structural.CourseOfValuesExample |
| 8 | +import Manual.RecursiveDefs.Structural.RecursorExample |
| 9 | +import Manual.RecursiveDefs.Structural.CourseOfValuesExample |
10 | 10 |
|
11 | 11 | import Manual.Meta |
12 | 12 |
|
@@ -481,6 +481,10 @@ Describe mutual structural recursion over {ref "nested-inductive-types"}[nested |
481 | 481 |
|
482 | 482 |
|
483 | 483 | # Inferring Structural Recursion |
| 484 | +%%% |
| 485 | +tag := "inferring-structural-recursion" |
| 486 | +%%% |
| 487 | + |
484 | 488 |
|
485 | 489 | If no {keyword}`termination_by` clauses are present in a recursive or mutually recursive function definition, then Lean attempts to infer a suitable structurally decreasing argument, effectively by trying all suitable parameters in sequence. |
486 | 490 | If this search fails, Lean then attempts to infer {tech}[well-founded recursion]. |
@@ -511,13 +515,13 @@ Try this: termination_by structural x => x |
511 | 515 | In this section, the construction used to elaborate structurally recursive functions is explained in more detail. |
512 | 516 | This elaboration uses the {ref "recursor-elaboration-helpers"}[`below` and `brecOn` constructions] that are automatically generated from inductive types' recursors. |
513 | 517 |
|
514 | | -{spliceContents Manual.Language.RecursiveDefs.Structural.RecursorExample} |
| 518 | +{spliceContents Manual.RecursiveDefs.Structural.RecursorExample} |
515 | 519 |
|
516 | 520 | The structural recursion analysis attempts to translate the recursive pre-definition into a use of the appropriate structural recursion constructions. |
517 | 521 | At this step, pattern matching has already been translated into the use of matcher functions; these are treated specially by the termination checker. |
518 | 522 | Next, for each group of parameters, a translation using `brecOn` is attempted. |
519 | 523 |
|
520 | | -{spliceContents Manual.Language.RecursiveDefs.Structural.CourseOfValuesExample} |
| 524 | +{spliceContents Manual.RecursiveDefs.Structural.CourseOfValuesExample} |
521 | 525 |
|
522 | 526 | The `below` construction is a mapping from each value of a type to the results of some function call on _all_ smaller values; it can be understood as a memoization table that already contains the results for all smaller values. |
523 | 527 | The notion of “smaller value” that is expressed in the `below` construction corresponds directly to the definition of {tech}[strict sub-terms]. |
|
0 commit comments