book/TPiL/InductionAndRecursion.lean
191 declarations, 7 contain sorry, 0 declared as axioms
Imports (2)
VersoManualTPiL.Examples
- def
sub1line 60 source - def
isZeroline 64 source - def
sub1line 73 source - def
isZeroline 76 source - example
(example at line 80)line 80 sourceSource comment
----example : sub1 0 = 0 := rfl
Mentions: sub1
- example
(example at line 81)line 81 source - example
(example at line 83)line 83 source - example
(example at line 84)line 84 source - example
(example at line 86)line 86 source - example
(example at line 87)line 87 source - def
sub1line 95 sourceSource comment
------def sub1 : Nat → Nat | 0 => 0 | x + 1 => x
Mentions: x
- def
isZeroline 99 source - def
swapline 112 source - def
fooline 115 sourceDistinct definitions of this name: book/TPiL/DependentTypeTheory.lean:779 (different declaration text), book/TPiL/InteractingWithLean.lean:784 (different declaration text). Qualify references as foo@path.
- def
barline 118 source - def
Hidden.notline 129 sourceSource comment
----def not : Bool → Bool | true => false | false => true
- theorem
Hidden.not_notline 133 source - example
(example at line 143)line 143 source - example
(example at line 146)line 146 source - def
sub2line 158 source - def
sub2line 173 source - example
(example at line 178)line 178 sourceSource comment
----example : sub2 0 = 0 := rfl
Mentions: sub2
- example
(example at line 179)line 179 source - example
(example at line 180)line 180 source - example
(example at line 182)line 182 source - def
sub2line 187 source - def
sub2line 199 source - example
(example at line 212)line 212 sourceSource comment
------example (p q : α → Prop) : (∃ x, p x ∨ q x) → (∃ x, p x) ∨ (∃ x, q x) | Exists.intro x (Or.inl px) => Or.inl (Exists.intro x px) | Exists.intro x (Or.inr qx) => Or.inr (Exists.intro x qx) - def
fooline 218 sourceDistinct definitions of this name: book/TPiL/DependentTypeTheory.lean:779 (different declaration text), book/TPiL/InteractingWithLean.lean:784 (different declaration text). Qualify references as foo@path.
- example
(example at line 225)line 225 source - def
fooline 231 sourceSource comment
------Distinct definitions of this name: book/TPiL/DependentTypeTheory.lean:779 (different declaration text), book/TPiL/InteractingWithLean.lean:784 (different declaration text). Qualify references as foo@path.
def foo : Nat → Nat → Nat | 0, n => 0 | m + 1, 0 => 1 | m + 1, n + 1 => 2 ``` Here is another example: ```lean set_option linter.unusedVariables false --------
- def
barline 242 sourceSource comment
------def bar : List Nat → List Nat → Nat | [], [] => 0 | a :: as, [] => a | [], b :: bs => b | a :: as, b :: bs => a + b ``` Note that the patterns are separated by commas. In each of the following examples, splitting occurs on only the first argument, even though the others are included among the list of patterns. …
- def
Hidden.andline 259 sourceSource comment
----def and : Bool → Bool → Bool | true, a => a | false, _ => false
- def
Hidden.orline 263 source - def
Hidden.condline 267 source - def
tailline 288 sourceSource comment
------def tail : List α → List α | [] => [] | a :: as => as ``` :::leanFirst As described in {ref "inductive-types"}[Inductive Types], - inductive
dataline 295 sourceDistinct definitions of this name: book/TPiL/StructuresAndRecords.lean:44 (different declaration text). Qualify references as data@path.
- def
tail1line 304 sourceSource comment
------def tail1 {α : Type u} : List α → List α | [] => [] | a :: as => as - def
tail2line 308 source - def
fooline 334 sourceSource comment
------Distinct definitions of this name: book/TPiL/DependentTypeTheory.lean:779 (different declaration text), book/TPiL/InteractingWithLean.lean:784 (different declaration text). Qualify references as foo@path.
def foo : Nat → Nat → Nat | 0, n => 0 | m + 1, 0 => 1 | m + 1, n + 1 => 2 ``` An alternative presentation is: ```lean set_option linter.unusedVariables false --------
- def
fooline 345 sourceSource comment
------Distinct definitions of this name: book/TPiL/DependentTypeTheory.lean:779 (different declaration text), book/TPiL/InteractingWithLean.lean:784 (different declaration text). Qualify references as foo@path.
def foo : Nat → Nat → Nat | 0, n => 0 | m, 0 => 1 | m, n => 2 ``` In the second presentation, the patterns overlap; for example, the pair of arguments {lit}`0, 0` matches all three cases. But Lean handles the ambiguity by using the first applicable equation, so in this example the net result is the same. In particular, the following equations hold definitionally: … - def
fooline 358 sourceDistinct definitions of this name: book/TPiL/DependentTypeTheory.lean:779 (different declaration text), book/TPiL/InteractingWithLean.lean:784 (different declaration text). Qualify references as foo@path.
- example
(example at line 363)line 363 sourceSource comment
----example : foo 0 0 = 0 := rfl
- example
(example at line 364)line 364 source - example
(example at line 365)line 365 source - example
(example at line 366)line 366 source - def
fooline 372 sourceDistinct definitions of this name: book/TPiL/DependentTypeTheory.lean:779 (different declaration text), book/TPiL/InteractingWithLean.lean:784 (different declaration text). Qualify references as foo@path.
- class
(class at line 390)line 390 source - def
f1line 405 source - example
(example at line 410)line 410 source - example
(example at line 411)line 411 source - example
(example at line 412)line 412 source - example
(example at line 413)line 413 source - def
f2line 415 source - example
(example at line 420)line 420 source - example
(example at line 421)line 421 source - example
(example at line 422)line 422 source - example
(example at line 423)line 423 source - def
barline 431 source - def
fooline 445 sourceSource comment
-----Distinct definitions of this name: book/TPiL/DependentTypeTheory.lean:779 (different declaration text), book/TPiL/InteractingWithLean.lean:784 (different declaration text). Qualify references as foo@path.
def foo : Char → Nat | 'A' => 1 | 'B' => 2 | _ => 3 #print foo.match_1 ``` # Structural Recursion and Induction %%% tag := "structural-recursion-and-induction" …
- def
fooline 469 sourceDistinct definitions of this name: book/TPiL/DependentTypeTheory.lean:779 (different declaration text), book/TPiL/InteractingWithLean.lean:784 (different declaration text). Qualify references as foo@path.
- def
addline 505 sourceDistinct definitions of this name: book/TPiL/DependentTypeTheory.lean:600 (different declaration text), book/TPiL/InteractingWithLean.lean:231 (different declaration text). Qualify references as add@path.
- theorem
add_zeroline 509 source - theorem
add_succline 510 source - theorem
zero_addline 512 source - def
mulline 516 source - def
addline 537 sourceDistinct definitions of this name: book/TPiL/DependentTypeTheory.lean:600 (different declaration text), book/TPiL/InteractingWithLean.lean:231 (different declaration text). Qualify references as add@path.
- theorem
zero_addline 541 sourceSource comment
---theorem zero_add : ∀ n, add zero n = n | zero => by simp [add] | succ n => by simp [add, zero_add] ``` As with definition by pattern matching, parameters to a structural recursion or induction may appear before the colon. Such parameters are simply added to the local context before the definition is processed. For example, the definition of addition may also be written as follows: ```lean …
- def
addline 554 sourceDistinct definitions of this name: book/TPiL/DependentTypeTheory.lean:600 (different declaration text), book/TPiL/InteractingWithLean.lean:231 (different declaration text). Qualify references as add@path.
- def
addline 563 sourceDistinct definitions of this name: book/TPiL/DependentTypeTheory.lean:600 (different declaration text), book/TPiL/InteractingWithLean.lean:231 (different declaration text). Qualify references as add@path.
- def
fibline 573 source - example
(example at line 578)line 578 source - example
(example at line 580)line 580 source - example
(example at line 582)line 582 source - example
(example at line 584)line 584 source - def
fibFastline 602 source - def
fibFastline 615 source - def
fibline 659 source - def
appendline 677 source - example
(example at line 681)line 681 source - def
listAddline 688 source - def
replicateline 706 source - def
replicateline 725 source - theorem
length_replicateline 731 sourceSource comment
----theorem length_replicate (n : Nat) (a : α) : (replicate n a).length = n := by … - def
replicateline 745 source - theorem
length_replicateline 752 source - example
(example at line 796)line 796 source - def
r'line 805 source - example
(example at line 807)line 807 source - example
(example at line 808)line 808 source - def
fline 833 sourceDistinct definitions of this name: book/TPiL/AxiomsComputation.lean:340 (different declaration text), book/TPiL/DependentTypeTheory.lean:416 (different declaration text), book/TPiL/InteractingWithLean.lean:468 (different declaration text), book/TPiL/Tactics.lean:1457 (different declaration text). Qualify references as f@path.
- theorem
div_lemmaline 878 source - def
div.Fline 881 source - def
divline 887 source - theorem
div_lemmaline 902 source - def
div.Fline 905 source - def
divline 911 source - example
(example at line 913)line 913 sourceSource comment
---example : div 8 2 = 4 := by rfl …
Mentions: div
- theorem
div_lemmaline 925 source - def
div.Fline 928 source - def
divline 934 source - example
(example at line 936)line 936 sourceSource comment
---example : div 8 2 = 4 := by …
Mentions: div
- def
divline 946 source - def
divline 967 source - example
(example at line 974)line 974 sourceSource comment
----example (x y : Nat) : div x y = if 0 < y ∧ y ≤ x then div (x - y) y + 1 else 0 := by … - example
(example at line 983)sorry line 983 source - def
natToBinsorry line 998 source - def
ackline 1018 source - def
ackline 1030 source - instance
(instance at line 1045)line 1045 source - def
takeWhileline 1055 source - def
takeWhileline 1073 source - theorem
div_lemmaline 1091 source - def
divline 1094 source - def
acksorry line 1106 source - def
natToBinsorry line 1123 source - def
unsoundsorry line 1138 sourceDistinct definitions of this name: book/TPiL/PropositionsAndProofs.lean:328 (different declaration text). Qualify references as unsound@path.
- def
ackline 1176 source - theorem
ack_gt_zeroline 1181 source - def
ackline 1229 source - theorem
ack_gt_zeroline 1234 sourceSource comment
-----------theorem ack_gt_zero : ack n m > 0 := by …
- def
fline 1245 sourceDistinct definitions of this name: book/TPiL/AxiomsComputation.lean:340 (different declaration text), book/TPiL/DependentTypeTheory.lean:416 (different declaration text), book/TPiL/InteractingWithLean.lean:468 (different declaration text), book/TPiL/Tactics.lean:1457 (different declaration text). Qualify references as f@path.
- def
fline 1257 sourceDistinct definitions of this name: book/TPiL/AxiomsComputation.lean:340 (different declaration text), book/TPiL/DependentTypeTheory.lean:416 (different declaration text), book/TPiL/InteractingWithLean.lean:468 (different declaration text), book/TPiL/Tactics.lean:1457 (different declaration text). Qualify references as f@path.
- theorem
f_orsorry line 1264 sourceSource comment
----theorem f_or : f b1 b2 b3 b4 b5 = (b1 || b2 || b3 || b4 || b5) := by …
- def
fline 1324 sourceDistinct definitions of this name: book/TPiL/AxiomsComputation.lean:340 (different declaration text), book/TPiL/DependentTypeTheory.lean:416 (different declaration text), book/TPiL/InteractingWithLean.lean:468 (different declaration text), book/TPiL/Tactics.lean:1457 (different declaration text). Qualify references as f@path.
- theorem
f_orline 1331 sourceSource comment
----theorem f_or : f b1 b2 b3 b4 b5 = (b1 || b2 || b3 || b4 || b5) := by …
- example
(example at line 1355)line 1355 source - example
(example at line 1358)line 1358 source - theorem
even_eq_not_oddline 1361 source - inductive
Evenline 1389 source - inductive
Oddline 1392 source - theorem
not_odd_zeroline 1398 source - theorem
even_of_odd_succline 1401 source - theorem
odd_of_even_succline 1404 source - inductive
Termline 1412 source - inductive
Termline 1420 source - def
sampleline 1436 source - inductive
Termline 1447 source - def
Term.numConstsline 1452 source - inductive
Vectline 1498 source - def
mapline 1502 source - def
zipline 1506 source - def
unzipline 1510 source - def
tailline 1516 source - inductive
familiesline 1527 source - inductive
Vectline 1536 source - inductive
Vectline 1568 source - def
Vect.tailAuxline 1573 sourceSource comment
----def tailAux (v : Vect α m) : m = n + 1 → Vect α n := …
- def
Vect.tailline 1580 source - inductive
Vectline 1605 source - def
Vect.headline 1610 sourceSource comment
----def head : {n : Nat} → Vect α (n+1) → α | n, cons a as => a - def
Vect.tailline 1613 source - theorem
Vect.etaline 1616 source - def
Vect.mapline 1619 source - def
Vect.zipline 1623 source - inductive
Vectline 1637 source - def
Vect.zipWithline 1642 sourceSource comment
-----def zipWith (f : α → β → γ) : {n : Nat} → Vect α n → Vect β n → Vect γ n | 0, nil, nil => nil | n+1, cons a as, cons b bs => cons (f a b) (zipWith f as bs) #print zipWith #print zipWith.match_1 ------ end Vect ``` :::setup ``` - inductive
Vectline 1654 source - inductive
ImageOfline 1695 source - def
inverseline 1700 source - def
inverse'line 1703 source - inductive
Vectline 1719 source - def
Vect.addline 1723 source - inductive
Vectline 1744 source - def
Vect.addline 1749 sourceSource comment
----def add [Add α] : {n : Nat} → Vect α n → Vect α n → Vect α n | .(_), nil, nil => nil | .(_), cons a as, cons b bs => cons (a + b) (add as bs) ------- end Vect ``` Marking the position as an inaccessible pattern tells the equation compiler first, that the form of the argument should be inferred from the constraints posed by the other arguments, and, second, that the first argument should _not_ participate in pattern matching. … - inductive
Vectline 1765 source - def
Vect.addline 1770 sourceSource comment
----def add [Add α] : {n : Nat} → Vect α n → Vect α n → Vect α n | _, nil, nil => nil | _, cons a as, cons b bs => cons (a + b) (add as bs) ------- end Vect ``` As we mentioned above, the argument {leanRef}`{n : Nat}` is part of the pattern matching, because it cannot be held fixed throughout the definition. Rather than requiring that these discriminants be provided explicitly, Lean implicitly includes these extra discriminants automatically for us. … - inductive
Vectline 1783 source - def
Vect.addline 1788 sourceSource comment
----def add [Add α] {n : Nat} : Vect α n → Vect α n → Vect α n | nil, nil => nil | cons a as, cons b bs => cons (a + b) (add as bs) ------- end Vect ``` When combined with the _auto bound implicits_ feature, you can simplify the declare further and write: ```lean - inductive
Vectline 1799 source - def
Vect.addline 1804 sourceSource comment
----def add [Add α] : Vect α n → Vect α n → Vect α n | nil, nil => nil | cons a as, cons b bs => cons (a + b) (add as bs) ------- end Vect ``` Using these new features, you can write the other vector functions defined in the previous sections more compactly as follows: ```lean set_option linter.unusedVariables false
- inductive
Vectline 1816 source - def
Vect.headline 1821 sourceSource comment
----def head : Vect α (n+1) → α | cons a as => a
- def
Vect.tailline 1824 source - theorem
Vect.etaline 1827 source - def
Vect.mapline 1830 source - def
Vect.zipline 1834 source - def
isNotZeroline 1852 sourceSource comment
----def isNotZero (m : Nat) : Bool := …
Mentions: m
- def
isNotZeroline 1865 sourceSource comment
-----def isNotZero (m : Nat) : Bool := …
Mentions: m
- def
filterline 1870 source - example
(example at line 1877)line 1877 source - def
fooline 1883 sourceDistinct definitions of this name: book/TPiL/DependentTypeTheory.lean:779 (different declaration text), book/TPiL/InteractingWithLean.lean:784 (different declaration text). Qualify references as foo@path.
- example
(example at line 1892)line 1892 source - def
bar₁line 1899 source - def
bar₂line 1902 source - def
bar₃line 1906 source - def
bar₄line 1909 source - example
(example at line 1918)line 1918 source - example
(example at line 1921)line 1921 source - example
(example at line 1926)line 1926 source - example
(example at line 1929)sorry line 1929 source