lean-iap

IAP 2026 class about Lean (mirror)

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
  101. 101
  102. 102
  103. 103
  104. 104
  105. 105
  106. 106
  107. 107
  108. 108
  109. 109
  110. 110
  111. 111
  112. 112
  113. 113
  114. 114
  115. 115
  116. 116
  117. 117
  118. 118
  119. 119
  120. 120
  121. 121
  122. 122
  123. 123
  124. 124
  125. 125
  126. 126
  127. 127
  128. 128
  129. 129
  130. 130
  131. 131
  132. 132
  133. 133
  134. 134
  135. 135
  136. 136
  137. 137
  138. 138
  139. 139
  140. 140
  141. 141
  142. 142
  143. 143
  144. 144
  145. 145
  146. 146
  147. 147
  148. 148
  149. 149
  150. 150
  151. 151
  152. 152
  153. 153
  154. 154
import Std.Tactic.Do
import Mathlib

open Std.Do

/-
# Pset 3

## 3.1

Prove the following lemma.
-/

lemma bounded_by_reciprocals (x : ) (hx : 0  x) (h :  n, x  1 / n) : x = 0 := by
  sorry

/-
## 3.2

Prove the following lemmas.
-/

lemma imo1964_p1b (n : ) : (2 ^ n + 1) % 7  0 := by
  sorry

abbrev SolutionSet : Set <| Vector  14 := sorry

lemma usa1979_p1 :  e, e  SolutionSet  (e.map (· ^ 4)).sum = 1599 := by
  sorry

/-
## 3.3

Here's a weird sorting algorithm:
-/

namespace Sorting

variable [LinearOrder α] (A : Array α)

def ICan'tBelieveItCanSort := Id.run do
  let N := A.size
  let mut A := A.toVector
  for hi : i in [:N] do
    for hj : j in [:N] do
      if A[i] < A[j] then
        A := A.swap i j
  return A.toArray

#eval ICan'tBelieveItCanSort #[69, 420, 1, 1, 13, 1, 65536]

/-
First, write a natural language proof for why this algorithm is correct.

Next, prove in Lean that the algorithm returns a permutation of its input.
-/

theorem perm : ICan'tBelieveItCanSort A |>.Perm A := by
  generalize h : ICan'tBelieveItCanSort A = x
  apply Id.of_wp_run_eq h
  mvcgen
  sorry

/-
Now for the fun part!
-/

theorem sorted : ICan'tBelieveItCanSort A |>.Pairwise (·  ·) := by
  generalize h : ICan'tBelieveItCanSort A = x
  apply Id.of_wp_run_eq h
  mvcgen
  sorry

/-
Now we can declare victory!
-/

theorem ICan'tBelieveICanProveItCanSort : (ICan'tBelieveItCanSort A).Perm A
     (ICan'tBelieveItCanSort A).Pairwise (·  ·) :=
  perm A, sorted A

end Sorting

/-
## 3.4

Implement the function below that returns `42` if the input string is `"lean"` and otherwise leaves it unchanged. Since the type of this function is pretty complicated, we'll implement it using tactics mode, which isn't just for proofs!
-/

def leanTo42Type (x : String) : Type :=
  if x = "lean" then  else String

def leanTo42 (x : String) : leanTo42Type x := by
  sorry

/-
## 3.5

Prove the following lemma.
-/

lemma crazy_lemma [DecidableEq β] {A : Finset α} {g : α  Finset β}
    (hin :  y, x  g y  g (f y)  g y)
    (hnin :  y, x  g y  g (f y) = g y)
    (hf :  y, x  g (f y))
    (hA :  a  A, x  g a)
    : (A.map f).biUnion g  A.biUnion g :=
  sorry

/-
## 3.6

Implement these functions by looking carefully at the type signatures of what you're given.
-/

def yoneda (f : Type u  Type v) [Functor f] (g : {β : Type u}  (α  β)  f β) : f α :=
  sorry

def yoneda' (f : Type u  Type v) [Functor f] (y : f α) : {β : Type u}  (α  β)  f β :=
  sorry

/-
## 3.7

-/

/-
## 3.8

-/

/-
## 3.9

-/

def solution : String := sorry

open Nat Real Quaternion CoxeterMatrix Lean in
example : minFac ''.toNat|>λ_11(·+97)<$>[0/0,_11,-(1,0,2,4:[])^2|>.re.toNat,defaultMaxRecDepth%101,catalan 4,_11,(φφφφφφ<|4)!,((4:Fin 24)-6),deriv (sin ·^69) π,_11,Nat.card<|Aₙ 2|>.Group]
    = solution.toList.map Char.toNat := by
  sorry



/-
## 3.10

fenwick
-/

namespace Fenwick

end Fenwick