book/TPiL/InductiveTypes.lean

GitHub source file

Explanation legend Lean4 Domain Explanation Language (L4DEL)

L4DEL explanations are a separate layer. They do not change the Lean source. Intuition is explanatory prose; numbered items are a reading path; sources link the wording back to evidence.

L4DEL
Lean4 Domain Explanation Language

Credit: The upstream authors and contributors retain credit for the project and mathematics. lean4-explainer only renders their pinned source and adds the separately disclosed explanation layer.

Project sources: Pinned Theorem Proving in Lean documentation, Pinned Theorem Proving in Lean 4 book index

152 declarations, 6 contain sorry, 0 declared as axioms

Imports (2)
  1. inductive Foo line 40 source

    Distinct definitions of this name: book/TPiL/PropositionsAndProofs.lean:608 (same statement text; different proof or body). Qualify references as Foo@path.

  2. inductive Foo line 48 source

    Distinct definitions of this name: book/TPiL/PropositionsAndProofs.lean:608 (same statement text; different proof or body). Qualify references as Foo@path.

  3. inductive Weekday line 101 source
  4. inductive Weekday line 115 source
  5. inductive Weekday line 138 source
  6. inductive Weekday line 150 source
  7. inductive Weekday line 190 source
  8. def numberOfDay line 201 source
  9. inductive Weekday line 224 source
  10. def numberOfDay line 235 source
  11. inductive Weekday line 262 source
  12. structure in line 279 source
  13. inductive Weekday line 287 source
  14. def Weekday.next line 298 source
  15. def Weekday.previous line 308 source
  16. example Weekday.(example at line 322) line 322 source
  17. inductive Weekday line 335 source
  18. def Weekday.next line 345 source
  19. def Weekday.previous line 354 source
  20. theorem Weekday.next_previous next undoes previous, by cases on the constructors line 364 source

    Source comment

    ----

    L4DEL explanation

    Weekday has seven constructors, so match gives seven cases, each true by computation.

    1. Weekday is an inductive type with constructors sunday through saturday, and next and previous move one day forward and back.
    2. theorem next_previous (d : Weekday) : next (previous d) = d is proved with match d with.
    3. In each of the seven cases the two sides reduce to the same constructor, so the proof is rfl.
    4. The book follows this with a shorter version of the proof.

    Sources and attribution: Pinned Lean source (4e28129fdd58)

    inductive type: a type generated freely by a list of constructors, such as the seven weekdays.

    theorem next_previous (d : Weekday) : next (previous d) = d :=
    …

    Mentions: Weekday.Weekday, Weekday.next, Weekday.previous

  21. inductive Weekday.Weekday line 379 source
  22. def Weekday.Weekday.next line 389 source
  23. def Weekday.Weekday.previous line 398 source
  24. theorem Weekday.Weekday.next_previous line 408 source

    Source comment

    ----
    theorem next_previous (d : Weekday) : next (previous d) = d := by
    …

    Mentions: Weekday.Weekday, Weekday.Weekday.next, Weekday.Weekday.previous

  25. inductive Weekday.Weekday.Hidden.Bool line 427 source

    Source comment

    ----
    inductive Bool where
    …
  26. def Weekday.Weekday.Hidden.and line 450 source

    Source comment

    ----
    def and (a b : Bool) : Bool :=
    …

    Mentions: b, Weekday.Weekday.Hidden.Bool

  27. inductive Weekday.Weekday.Hidden.Prod line 480 source

    Source comment

    ----
    inductive Prod (α : Type u) (β : Type v)
      | mk : α → β → Prod α β

    Mentions: α, β

  28. inductive Weekday.Weekday.Hidden.Sum line 483 source
  29. inductive Weekday.Weekday.Hidden.Prod line 501 source
  30. def Weekday.Weekday.Hidden.fst line 504 source

    Source comment

    ----
    def fst {α : Type u} {β : Type v} (p : Prod α β) : α :=
    …

    Mentions: α, β, Weekday.Weekday.Hidden.Prod

  31. def Weekday.Weekday.Hidden.snd line 508 source
  32. def Weekday.Weekday.prod_example line 531 source
  33. def Weekday.Weekday.sum_example line 564 source
  34. inductive Weekday.Weekday.Hidden.Prod line 623 source

    Source comment

    ----
    inductive Prod (α : Type u) (β : Type v) where
    …

    Mentions: α, β

  35. inductive Weekday.Weekday.Hidden.Sum line 626 source
  36. structure Weekday.Weekday.Hidden.Prod line 646 source

    Source comment

    ----
    structure Prod (α : Type u) (β : Type v) where
    …

    Mentions: α, β

  37. example Weekday.Weekday.(example at line 660) line 660 source
  38. structure Weekday.Weekday.Color line 664 source
  39. def Weekday.Weekday.yellow line 670 source
  40. structure Weekday.Weekday.Semigroup line 684 source
  41. inductive Weekday.Weekday.Hidden.Sigma line 698 source

    Source comment

    ----
    inductive Sigma {α : Type u} (β : α → Type v) where
    …

    Mentions: α, β

  42. inductive Weekday.Weekday.Hidden.Option line 710 source

    Source comment

    ----
    inductive Option (α : Type u) where
    …

    Mentions: α

  43. inductive Weekday.Weekday.Hidden.Inhabited line 714 source
  44. inductive Weekday.Weekday.Hidden.False line 762 source

    Source comment

    ----
    inductive False : Prop
  45. inductive Weekday.Weekday.Hidden.True line 764 source
  46. inductive Weekday.Weekday.Hidden.And line 767 source
  47. inductive Weekday.Weekday.Hidden.Or line 770 source
  48. inductive Weekday.Weekday.Hidden.Exists line 798 source

    Source comment

    ----
    inductive Exists {α : Sort u} (p : α → Prop) : Prop where
    …

    Mentions: α

  49. inductive Weekday.Weekday.Hidden.Subtype line 828 source

    Source comment

    ----
    inductive Subtype {α : Type u} (p : α → Prop) where
    …

    Mentions: α

  50. structure Weekday.Weekday.Hidden.Subtype line 845 source

    Source comment

    ----
    structure Subtype {α : Sort u} (p : α → Prop) where
    …

    Mentions: α

  51. inductive Weekday.Weekday.Hidden.Nat line 875 source

    Source comment

    ----
    inductive Nat where
    …
  52. def Weekday.Weekday.add line 939 source
  53. inductive Weekday.Weekday.Hidden.Nat line 957 source

    Source comment

    ----
    inductive Nat where
    …
  54. def Weekday.Weekday.Hidden.add line 962 source
  55. inductive Weekday.Weekday.Hidden.Nat line 981 source
  56. def Weekday.Weekday.Hidden.Nat.add line 988 source
  57. instance Weekday.Weekday.Hidden.Nat.(instance at line 993) line 993 source
  58. theorem Weekday.Weekday.Hidden.Nat.add_zero line 996 source
  59. theorem Weekday.Weekday.Hidden.Nat.add_succ line 997 source
  60. theorem Weekday.Weekday.Hidden.zero_add line 1027 source
  61. theorem Weekday.Weekday.Hidden.zero_add line 1053 source
  62. theorem Weekday.Weekday.Hidden.add_assoc line 1077 source
  63. theorem Weekday.Weekday.add_assoc line 1095 source
  64. theorem Weekday.Weekday.add_comm First attempt at commutativity of Nat addition (contains sorry) sorry line 1105 source

    L4DEL explanation

    Induct on the second argument; one equation in the step is not yet proved and is left as sorry.

    1. This is a work-in-progress block in the book: the last calc step ends with := sorry, so Lean accepts it only with a warning.
    2. Nat.recOn with motive fun x => m + x = x + m does induction on n; the base case m + 0 = 0 + m is proved with Nat.zero_add and Nat.add_zero.
    3. In the inductive step a calc rewrites m + succ n to succ (m + n), then to succ (n + m) using the induction hypothesis.
    4. The missing step succ (n + m) = succ n + m is what the book proves next as succ_add, then plugs in to replace the sorry.

    See also: Weekday.Weekday.succ_add

    Sources and attribution: Pinned Lean source (4e28129fdd58)

    induction hypothesis: in the inductive step, the assumption that the property holds for n, used to prove it for succ n.

    theorem add_comm (m n : Nat) : m + n = n + m :=
    …

    Mentions: m, n

  65. theorem Weekday.Weekday.succ_add sorry line 1122 source
  66. inductive Weekday.Weekday.Hidden.Nat line 1137 source
  67. def Weekday.Weekday.Hidden.add line 1142 source
  68. instance Weekday.Weekday.Hidden.(instance at line 1147) line 1147 source
  69. theorem Weekday.Weekday.Hidden.Nat.add_zero line 1151 source
  70. theorem Weekday.Weekday.Hidden.Nat.add_succ line 1153 source
  71. theorem Weekday.Weekday.Hidden.Nat.zero_add line 1155 source
  72. theorem Weekday.Weekday.Hidden.succ_add line 1163 source
  73. theorem Weekday.Weekday.Hidden.add_comm line 1168 source
  74. inductive Weekday.Weekday.Hidden.List line 1189 source

    Source comment

    ----
    inductive List (α : Type u) where
    …

    Mentions: α

  75. def Weekday.Weekday.Hidden.List.append line 1195 source
  76. theorem Weekday.Weekday.Hidden.List.nil_append line 1200 source
  77. theorem Weekday.Weekday.Hidden.List.cons_append line 1203 source
  78. inductive Weekday.Weekday.Hidden.List line 1222 source
  79. def Weekday.Weekday.Hidden.List.append line 1226 source
  80. theorem Weekday.Weekday.Hidden.List.nil_append line 1230 source
  81. theorem Weekday.Weekday.Hidden.List.cons_append line 1232 source
  82. theorem Weekday.Weekday.Hidden.List.append_nil sorry line 1236 source

    Source comment

    ----
    theorem append_nil (as : List α) :
        append as nil = as :=
    …

    Mentions: as, Weekday.Weekday.Hidden.List, α, Weekday.Weekday.Hidden.List.append

  83. theorem Weekday.Weekday.Hidden.List.append_assoc sorry line 1240 source
  84. def Weekday.Weekday.length line 1251 source
  85. def Weekday.Weekday.append line 1252 source
  86. inductive Weekday.Weekday.BinaryTree line 1263 source
  87. inductive Weekday.Weekday.CBTree line 1271 source
  88. def Weekday.Weekday.CBTree.succ line 1277 source
  89. def Weekday.Weekday.CBTree.toCBTree line 1280 source
  90. def Weekday.Weekday.CBTree.omega line 1284 source
  91. example Weekday.Weekday.(example at line 1312) line 1312 source
  92. example Weekday.Weekday.(example at line 1355) line 1355 source
  93. def Weekday.Weekday.f line 1369 source
  94. example Weekday.Weekday.(example at line 1372) line 1372 source
  95. example Weekday.Weekday.(example at line 1373) line 1373 source
  96. def Weekday.Weekday.Tuple line 1379 source
  97. def Weekday.Weekday.f line 1382 source
  98. def Weekday.Weekday.myTuple line 1385 source
  99. example Weekday.Weekday.(example at line 1388) line 1388 source
  100. inductive Weekday.Weekday.Foo line 1395 source
  101. def Weekday.Weekday.silly line 1399 source
  102. inductive Weekday.Weekday.Foo line 1409 source
  103. def Weekday.Weekday.silly line 1413 source

    Source comment

    ----
    def silly (x : Foo) : Nat := by
    …

    Mentions: x, Weekday.Weekday.Foo

  104. inductive Weekday.Weekday.Foo line 1425 source
  105. def Weekday.Weekday.silly line 1429 source

    Source comment

    ----
    def silly (x : Foo) : Nat := by
    …

    Mentions: x, Weekday.Weekday.Foo

  106. inductive Weekday.Weekday.Foo line 1439 source
  107. def Weekday.Weekday.silly line 1443 source

    Source comment

    ----
    def silly (x : Foo) : Nat := by
    …

    Mentions: x, Weekday.Weekday.Foo

  108. example Weekday.Weekday.(example at line 1457) line 1457 source
  109. example Weekday.Weekday.(example at line 1471) line 1471 source
  110. example Weekday.Weekday.(example at line 1493) line 1493 source
  111. example Weekday.Weekday.(example at line 1509) line 1509 source
  112. example Weekday.Weekday.(example at line 1527) line 1527 source
  113. theorem Weekday.Weekday.Hidden.zero_add line 1549 source

    Source comment

    ----
    theorem zero_add (n : Nat) : 0 + n = n := by
    …

    Mentions: n, Weekday.Weekday.Hidden.Nat

  114. theorem Weekday.Weekday.Hidden.zero_add line 1564 source

    Source comment

    ----
    theorem zero_add (n : Nat) : 0 + n = n := by
    …

    Mentions: n, Weekday.Weekday.Hidden.Nat

  115. inductive Weekday.Weekday.Hidden.Nat line 1579 source
  116. def Weekday.Weekday.Hidden.Nat.toNat line 1583 source
  117. def Weekday.Weekday.Hidden.Nat.ofNat line 1587 source
  118. def Weekday.Weekday.Hidden.add line 1591 source
  119. instance Weekday.Weekday.Hidden.(instance at line 1596) line 1596 source
  120. instance Weekday.Weekday.Hidden.(instance at line 1599) line 1599 source
  121. theorem Weekday.Weekday.Hidden.zero_zero line 1603 source
  122. theorem Weekday.Weekday.Hidden.add_zero line 1604 source
  123. theorem Weekday.Weekday.Hidden.add_succ line 1605 source
  124. theorem Weekday.Weekday.Hidden.zero_add line 1609 source
  125. theorem Weekday.Weekday.Hidden.succ_add line 1612 source
  126. theorem Weekday.Weekday.Hidden.add_comm line 1615 source
  127. theorem Weekday.Weekday.Hidden.add_assoc line 1618 source
  128. example Weekday.Weekday.(example at line 1637) line 1637 source
  129. example Weekday.Weekday.(example at line 1655) line 1655 source
  130. example Weekday.Weekday.(example at line 1666) line 1666 source
  131. example Weekday.Weekday.(example at line 1670) line 1670 source
  132. example Weekday.Weekday.(example at line 1691) line 1691 source
  133. example Weekday.Weekday.(example at line 1708) line 1708 source
  134. example Weekday.Weekday.(example at line 1711) line 1711 source
  135. example Weekday.Weekday.(example at line 1714) line 1714 source
  136. inductive Weekday.Weekday.foo line 1735 source
  137. inductive Weekday.Weekday.Vect line 1756 source
  138. inductive Weekday.Weekday.Hidden.Eq line 1772 source

    Source comment

    ----
    inductive Eq {α : Sort u} (a : α) : α → Prop where
    …

    Mentions: α

  139. theorem Weekday.Weekday.Hidden.subst line 1813 source

    Source comment

    ----
    theorem subst {α : Type u} {a b : α} {p : α → Prop}
        (h₁ : Eq a b) (h₂ : p a) : p b :=
    …

    Mentions: α, b, Weekday.Weekday.Hidden.Eq

  140. theorem Weekday.Weekday.Hidden.subst line 1825 source

    Source comment

    ----
    theorem subst {α : Type u} {a b : α} {p : α → Prop}
        (h₁ : Eq a b) (h₂ : p a) : p b :=
    …

    Mentions: α, b, Weekday.Weekday.Hidden.Eq

  141. theorem Weekday.Weekday.subst line 1837 source
  142. theorem Weekday.Weekday.Hidden.symm line 1864 source
  143. theorem Weekday.Weekday.Hidden.trans sorry line 1868 source
  144. theorem Weekday.Weekday.Hidden.congr sorry line 1871 source
  145. inductive Weekday.Weekday.definitions, line 1879 source
  146. inductive Weekday.Weekday.type line 1902 source
  147. inductive Weekday.Weekday.types line 1909 source
  148. inductive Weekday.Weekday.definitions line 1972 source
  149. inductive Weekday.Tree line 2027 source
  150. def Weekday.length line 2048 source
  151. def Weekday.reverse line 2051 source
  152. inductive Weekday.Term line 2058 source