-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw6.lean
145 lines (132 loc) · 3.6 KB
/
hw6.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import Mathlib.Data.Real.Basic
import Mathlib.Tactic.IntervalCases
import Library.Theory.Comparison
import Library.Theory.Parity
import Library.Theory.Prime
import Library.Tactic.ModCases
import Library.Tactic.Extra
import Library.Tactic.Numbers
import Library.Tactic.Addarith
import Library.Tactic.Cancel
import Library.Tactic.Use
-- 4a
example {P Q : α → Prop} (h : ∀ x, P x ↔ Q x) : (∃ x, P x) ↔ (∃ x, Q x) := by
constructor
. intro h_exP -- let's go from exists x px to exists x qx
obtain ⟨x, h_exP⟩ := h_exP
have h_Px_eq_Qx := h x
obtain ⟨h_right, h_left⟩ := h_Px_eq_Qx
have h_eQ: ∃x, Q x
· use x
apply h_right h_exP
apply h_eQ
. intro h_exQ -- vice versa
obtain ⟨x, h_exQ⟩ := h_exQ
have h_Px_eq_Qx := h x
obtain ⟨h_right, h_left⟩ := h_Px_eq_Qx
have h_eP: ∃x, P x
· use x
apply h_left h_exQ
apply h_eP
-- 4b
example (P : α → β → Prop) : (∃ x y, P x y) ↔ ∃ y x, P x y := by
constructor
. intro h_exyP
obtain ⟨x, h_eyP⟩ := h_exyP
obtain ⟨y, h_P⟩ := h_eyP
have h_new_exP: ∃x, P x y
· use x
apply h_P
have h_new_eyxP: ∃ y x, P x y
· use y
apply h_new_exP
apply h_new_eyxP
. intro h_eyxP -- replace x with y and y with x in the above steps
obtain ⟨y, h_exP⟩ := h_eyxP
obtain ⟨x, h_P⟩ := h_exP
have h_new_eyP: ∃y, P x y
· use y
apply h_P
have h_new_exyP: ∃ x y, P x y
· use x
apply h_new_eyP
apply h_new_exyP
-- 4c
example (P : α → β → Prop) : (∀ x y, P x y) ↔ ∀ y x, P x y := by
constructor
. intro h_axyP
have h_ayxP: ∀ y x, P x y
· intro y x
apply h_axyP
apply h_ayxP
. intro h_ayxP
have h_axyP: ∀ x y, P x y
· intro x y
apply h_ayxP
apply h_axyP
-- 4d
example (P : α → Prop) (Q : Prop) : ((∃ x, P x) ∧ Q) ↔ ∃ x, (P x ∧ Q) := by
constructor
. intro h
obtain ⟨h_exP, h_Q⟩ := h
obtain ⟨x, h_P⟩ := h_exP
have h_px_a_q_1: ∃x, P x ∧ Q
· use x
constructor
. apply h_P
. apply h_Q
apply h_px_a_q_1
. intro h
obtain ⟨x, h_PQ⟩ := h
have h_px_a_q_2: (∃x, P x) ∧ Q
. constructor
. use x
apply And.left h_PQ -- take p(x)
. apply And.right h_PQ -- take Q
apply h_px_a_q_2
-- copy from MoP
def Tribalanced (x : ℝ) : Prop := ∀ n : ℕ, (1 + x / n)^n < 3
def Superpowered (k : ℕ) : Prop := ∀ n : ℕ, Prime (k^k^n + 1)
theorem superpowered_one : Superpowered 1 := by
intro n
conv => ring_nf -- simplifies goal from `Prime (1 ^ 1 ^ n + 1)` to `Prime 2`
apply prime_two
-- 5a
example : ∃ x : ℝ, Tribalanced x ∧ ¬ Tribalanced (x + 1) := by
by_cases h: Tribalanced 1
. use 1
constructor
. apply h
. ring
intro h_2
simp [Tribalanced] at h
have h_t_2:= h_2 2
simp at h_t_2
have : 4 < 3 := by -- calc Tribalanced(2) for n=2.
{
calc
4 = (1 + 1) ^ 2 := by ring
_ < 3 := by addarith[h_t_2]
}
contradiction
. use 0
constructor
. intro n
simp
numbers
. ring; apply h
-- 5b
example : ∃ k : ℕ, Superpowered k ∧ ¬ Superpowered (k + 1) := by
use 1
constructor
. apply superpowered_one
. intro h
simp [Superpowered] at h
have h_4294967297_p : Prime ((1+1) ^ (1+1) ^ 5 + 1) := h 5 -- this is 4294967297
conv at h_4294967297_p => numbers
have h_4294967297_n_pr : ¬ Prime 4294967297
· apply not_prime 641 6700417
· numbers -- 641 not eq 1
· numbers -- 641 not eq 4294967297
· ring
contradiction