mathematics_in_lean

My solutions for this book

  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
  155. 155
  156. 156
  157. 157
  158. 158
  159. 159
import analysis.special_functions.log.basic

variables a b c d e : 
open real

#check (le_refl :  a : , a  a)
#check (le_trans : a  b  b  c  a  c)

section
variables (h : a  b) (h' : b  c)

#check (le_refl :  a : real, a  a)
#check (le_refl a : a  a)
#check (le_trans : a  b  b  c  a  c)
#check (le_trans h : b  c  a  c)
#check (le_trans h h' : a  c)
end

example (x y z : ) (h₀ : x  y) (h₁ : y  z) : x  z :=
begin
  apply le_trans,
  { apply h₀ },
  apply h₁
end

example (x y z : ) (h₀ : x  y) (h₁ : y  z) : x  z :=
begin
  apply le_trans h₀,
  apply h₁
end

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

example (x y z : ) (h₀ : x  y) (h₁ : y  z) : x  z :=
le_trans h₀ h₁

example (x : ) : x  x :=
by apply le_refl

example (x : ) : x  x :=
by exact le_refl x

example (x : ) : x  x :=
le_refl x

#check (le_refl  :  a, a  a)
#check (le_trans : a  b  b  c  a  c)
#check (lt_of_le_of_lt : a  b  b < c  a < c)
#check (lt_of_lt_of_le : a < b  b  c  a < c)
#check (lt_trans : a < b  b < c  a < c)

/- Try this. -/

example (h₀ : a  b) (h₁ : b < c) (h₂ : c  d)
    (h₃ : d < e) :
  a < e :=
sorry

example (h₀ : a  b) (h₁ : b < c) (h₂ : c  d)
    (h₃ : d < e) :
  a < e :=
by linarith

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

example (h : 1  a) (h' : b  c) :
  2 + a + exp b  3 * a + exp c :=
by linarith [exp_le_exp.mpr h']

#check (exp_le_exp : exp a  exp b  a  b)
#check (exp_lt_exp : exp a < exp b  a < b)
#check (log_le_log : 0 < a  0 < b  (log a  log b  a  b))
#check (log_lt_log : 0 < a  a < b  log a < log b)
#check (add_le_add : a  b  c  d  a + c  b + d)
#check (add_le_add_left : a  b   c, c + a  c + b)
#check (add_le_add_right : a  b   c, a + c  b + c)
#check (add_lt_add_of_le_of_lt : a  b  c < d  a + c < b + d)
#check (add_lt_add_of_lt_of_le : a < b  c  d  a + c < b + d)
#check (add_lt_add_left : a < b   c, c + a < c + b)
#check (add_lt_add_right : a < b   c, a + c < b + c)
#check (add_nonneg : 0  a  0  b  0  a + b)
#check (add_pos : 0 < a  0 < b  0 < a + b)
#check (add_pos_of_pos_of_nonneg : 0 < a  0  b  0 < a + b)
#check (exp_pos :  a, 0 < exp a)

#check @add_le_add_left
example (h : a  b) : exp a  exp b :=
begin
  rw exp_le_exp,
  exact h
end

example (h₀ : a  b) (h₁ : c < d) : a + exp c + e < b + exp d + e :=
begin
  apply add_lt_add_of_lt_of_le,
  { apply add_lt_add_of_le_of_lt h₀,
    apply exp_lt_exp.mpr h₁ },
  apply le_refl
end

example (h₀ : d  e) : c + exp (a + d)  c + exp (a + e) :=
begin
  sorry
end

example : (0 : ) < 1 :=
by norm_num

example (h : a  b) : log (1 + exp a)  log (1 + exp b) :=
begin
  have h₀ : 0 < 1 + exp a,
  { sorry },
  have h₁ : 0 < 1 + exp b,
  { sorry },
  apply (log_le_log h₀ h₁).mpr,
  sorry
end

    example : 0  a^2 :=
    begin
      -- library_search,
      exact pow_two_nonneg a
    end

example (h : a  b) : c - exp b  c - exp a :=
  sorry

example : 2*a*b  a^2 + b^2 :=
begin
  have h : 0  a^2 - 2*a*b + b^2,
  calc
    a^2 - 2*a*b + b^2 = (a - b)^2     : by ring
    ...  0                           : by apply pow_two_nonneg,
  calc
    2*a*b
        = 2*a*b + 0                   : by ring
    ...  2*a*b + (a^2 - 2*a*b + b^2) : add_le_add (le_refl _) h
    ... = a^2 + b^2                   : by ring
end

example : 2*a*b  a^2 + b^2 :=
begin
  have h : 0  a^2 - 2*a*b + b^2,
  calc
    a^2 - 2*a*b + b^2 = (a - b)^2 : by ring
    ...  0                       : by apply pow_two_nonneg,
  linarith
end

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

#check abs_le'.mpr