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
import Mathlib

-- Random exercises from MIL

example (a b c : ) : c * b * a = b * (a * c) := by
  sorry

example (a b c d e f : ) (h : a * b = c * d) (h' : e = f) : a * (b * e) = c * (d * f) := by
  sorry

example (a b c d : ) : (a + b) * (c + d) = a * c + a * d + b * c + b * d := by
  sorry

example (a b c : ) (h : a + b = c) : (a + b) * (a + b) = a * c + b * c := by
  sorry

example (a b : ) : a + b + -b = a := by
  sorry

example (x y z : ) (h₀ : x  y) (h₁ : y  z) : x  z := by
  sorry

example (h : 2 * a  3 * b) (h' : 1  a) (h'' : d = 2) : d + a  5 * b := by
  sorry

example (a b c d e : ) (h₀ : a  b) (h₁ : c < d) : a + Real.exp c + e < b + Real.exp d + e := by
  sorry

example (a b : ) (h : a  b) : Real.log (1 + Real.exp a)  Real.log (1 + Real.exp b) := by
  sorry

example : 0  a ^ 2 := by
  sorry

example (a b : ) : |a*b|  (a^2 + b^2)/2 := by
  sorry

example (a b : ) : min a b = min b a := by
  sorry

example : Nat.gcd m n = Nat.gcd n m := by
  sorry

example (h : a  b) : 0  b - a := by
  sorry

example :  x y ε : , 0 < ε  ε  1  |x| < ε  |y| < ε  |x * y| < ε := by
  sorry

example {n : } (h : Odd n) : Even n.succ := by
  sorry

example :  x : , 2 < x  x < 3 := by
  sorry

def SumOfSquares [CommRing α] (x : α) :=  a b, x = a ^ 2 + b ^ 2

example [CommRing α] {x y : α} (sosx : SumOfSquares x) (sosy : SumOfSquares y) : SumOfSquares (x * y) := by
  sorry

open Function in
example {g : β  γ} {f : α  β} (surjg : Surjective g) (surjf : Surjective f) : Surjective fun x  g (f x) := by
  sorry

example (P : α  Prop) (h : ¬ x, P x) :  x, ¬P x := by
  sorry

example {x y : } (h₀ : x  y) (h₁ : ¬y  x) : x  y  x  y := by
  sorry

example :  m n : , 4 < m  m < n  n < 10  Nat.Prime m  Nat.Prime n := by
  sorry

example {x y : } (h : x ^ 2 + y ^ 2 = 0) : x = 0 := by
  sorry

example (x : ) : |x + 3| < 5  -8 < x  x < 2 := by
  sorry

example (h : y > x ^ 2) : y > 0  y < -1 := by
  sorry

example (h : x ^ 2 = y ^ 2) : x = y  x = -y := by
  sorry

example {m n k : } (h : m  n  m  k) : m  n * k := by
  sorry

example :  f : α  Set α, ¬Function.Surjective f := by
  sorry

example (n : ) :  i  Finset.range (n + 1), i ^ 2 = n * (n + 1) * (2 * n + 1) / 6 := by
  sorry

example :  n,  p > n, Nat.Prime p := by
  sorry

-- Exercises from TPIL and other random sources

namespace TPIL

variable (men : Type) (barber : men)
variable (shaves : men  men  Prop)

example (h :  x : men, shaves barber x  ¬ shaves x x) : False :=
  sorry

end TPIL

namespace InsertionSort

variable [LinearOrder α] (xs : List α)

def ins (a : α)
  | [] => [a]
  | x :: xs =>
    if a  x then a :: x :: xs else x :: ins a xs

def insSort : List α  List α
  | [] => []
  | x :: xs => ins x (insSort xs)

inductive Sorted : List α  Prop where
  | nil : Sorted []
  | single x : Sorted [x]
  | cons_cons x x' xs : x  x'  Sorted (x' :: xs)  Sorted (x :: x' :: xs)

theorem insertCorrect x : (Sorted xs  Sorted (ins x xs))  (x :: xs).Perm (ins x xs) := by
  sorry

theorem insertionSortCorrect : Sorted (insSort xs)  xs.Perm (insSort xs) := by
  sorry

end InsertionSort