File size: 5,566 Bytes
e5a97c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Combinatorics.MatrixRemoval.CanonicalHorizontal
import OAI.Combinatorics.MatrixRemoval.HostVerticalLocalization

namespace OAI

/-!
# Exhaustive localization of bodies in canonical host modes

All entry and role hypotheses refer to the actual canonical host. The numerical
order premise is exactly the four parent comparisons supplied by the two tree
orders.
-/
namespace Problem348.Construction
open ModeLocalization

/-- The necessary parent comparison for an ordered body in each of the six modes. -/
def BodyNodeOrder {h : ℕ} (t : Mode h) (r₀ r₁ c₀ c₁ : Position h) : Prop :=
  if kind t = 0 then positionNode r₀ / 2 ≤ positionNode r₁
  else if kind t = 1 then positionNode r₀ ≤ positionNode r₁ / 2
  else if kind t < 4 then positionNode c₀ ≤ positionNode c₁ / 2
  else positionNode c₀ / 2 ≤ positionNode c₁

theorem rowRole_first_variable {h : ℕ} {t : Mode h} {x : Position h}
    (hx : rowRole t 0 x) : ∃ v : VariablePosition h, x = Sum.inr (Sum.inl v) := by
  rcases x with a | (v | d)
  · simp [rowRole] at hx
  · exact ⟨v, rfl⟩
  · simp [rowRole] at hx

theorem colRole_horizontal_variable {h : ℕ} {t : Mode h} {j : Fin 2}
    {x : Position h} (hk : 2 ≤ kind t) (hx : colRole t j x) :
    ∃ v : VariablePosition h, x = Sum.inr (Sum.inl v) := by
  rcases x with a | (v | d)
  · simp [colRole] at hx
  · exact ⟨v, rfl⟩
  · simp [colRole] at hx
    omega

/-- The horizontal plus roles cannot realize the body's top row. -/
theorem host_horizontal_plus_not_body {h : ℕ} {t : Mode h}
    (hklo : 2 ≤ kind t) (hkhi : kind t < 4) {r₀ r₁ c₀ c₁ : Position h}
    (hr₀ : rowRole t 0 r₀) (hc₀ : colRole t 0 c₀) (hc₁ : colRole t 1 c₁)
    (horder : positionNode c₀ ≤ positionNode c₁ / 2) :
    ¬ IsP (host r₀ c₀) (host r₀ c₁) (host r₁ c₀) (host r₁ c₁) := by
  obtain ⟨r, rfl⟩ := rowRole_first_variable hr₀
  obtain ⟨c, rfl⟩ := colRole_horizontal_variable hklo hc₀
  obtain ⟨d, rfl⟩ := colRole_horizontal_variable hklo hc₁
  have hk0 : kind t ≠ 0 := by omega
  have hk1 : kind t ≠ 1 := by omega
  have hk2 : ¬ kind t < 2 := by omega
  have hr : AtLevel (level t) true r ∧ node r % 2 = kind t % 2 := by
    simpa [rowRole, hk0, hk1, hkhi] using hr₀
  have hc : AtLevel (level t - 1) true c := by
    simpa [colRole, hk2, hkhi] using hc₀
  have hd : AtLevel (level t) true d ∧ node d % 2 = kind t % 2 := by
    simpa [colRole, hk2, hkhi] using hc₁
  have hl : level t - 1 + 1 = level t := by have := level_pos t; omega
  intro hb
  exact horizontal_plus_entries_impossible (hl ▸ hr.1) hc (hl ▸ hd.1)
    horder (hr.2.trans hd.2.symm) hb.1 hb.2.1

/-- The horizontal minus roles force the body's top-left entry onto a shared leaf. -/
theorem host_horizontal_minus_leaf_diagonal {h : ℕ} {t : Mode h}
    (hklo : 4 ≤ kind t) {r₀ r₁ c₀ c₁ : Position h}
    (hr₀ : rowRole t 0 r₀) (hc₀ : colRole t 0 c₀) (hc₁ : colRole t 1 c₁)
    (horder : positionNode c₀ / 2 ≤ positionNode c₁)
    (hb : IsP (host r₀ c₀) (host r₀ c₁) (host r₁ c₀) (host r₁ c₁)) :
    ∃ z : Fin (2 ^ h),
      r₀ = Sum.inr (Sum.inl (Fin.last (2 * h), z)) ∧
      c₀ = Sum.inr (Sum.inl (Fin.last (2 * h), z)) := by
  obtain ⟨r, rfl⟩ := rowRole_first_variable hr₀
  obtain ⟨c, rfl⟩ := colRole_horizontal_variable (by omega) hc₀
  obtain ⟨d, rfl⟩ := colRole_horizontal_variable (by omega) hc₁
  have hk0 : kind t ≠ 0 := by omega
  have hk1 : kind t ≠ 1 := by omega
  have hk2 : ¬ kind t < 2 := by omega
  have hk4 : ¬ kind t < 4 := by omega
  have hr : AtLevel (level t) false r ∧ node r % 2 = kind t % 2 := by
    simpa [rowRole, hk0, hk1, hk4] using hr₀
  have hc : AtLevel (level t) false c ∧ node c % 2 = kind t % 2 := by
    simpa [colRole, hk2, hk4] using hc₀
  have hd : AtLevel (level t - 1) false d := by
    simpa [colRole, hk2, hk4] using hc₁
  have hl : level t - 1 + 1 = level t := by have := level_pos t; omega
  obtain ⟨_, z, hz, hcz⟩ := horizontal_minus_entries_localize
    (hl ▸ hr.1) (hl ▸ hc.1) hd horder (hr.2.trans hc.2.symm) hb.1 hb.2.1
  exact ⟨z, congrArg (fun v => Sum.inr (Sum.inl v)) hz,
    congrArg (fun v => Sum.inr (Sum.inl v)) hcz⟩

/-- Under `BodyNodeOrder`, every ordered body in any canonical mode has its
top-left cell on the shared leaf diagonal. -/
theorem host_body_leaf_diagonal {h : ℕ} {t : Mode h} {r₀ r₁ c₀ c₁ : Position h}
    (hr₀ : rowRole t 0 r₀) (hr₁ : rowRole t 1 r₁)
    (hc₀ : colRole t 0 c₀) (hc₁ : colRole t 1 c₁)
    (horder : BodyNodeOrder t r₀ r₁ c₀ c₁)
    (hb : IsP (host r₀ c₀) (host r₀ c₁) (host r₁ c₀) (host r₁ c₁)) :
    ∃ z : Fin (2 ^ h),
      r₀ = Sum.inr (Sum.inl (Fin.last (2 * h), z)) ∧
      c₀ = Sum.inr (Sum.inl (Fin.last (2 * h), z)) := by
  by_cases hk0 : kind t = 0
  · exact False.elim (host_vertical_plus_not_body hk0 hr₀ hr₁ hc₀ hc₁
      (by simpa [BodyNodeOrder, hk0] using horder) hb)
  by_cases hk1 : kind t = 1
  · exact False.elim (host_vertical_minus_not_body hk1 hr₀ hr₁ hc₀ hc₁
      (by simpa [BodyNodeOrder, hk0, hk1] using horder) hb)
  by_cases hk4 : kind t < 4
  · exact False.elim (host_horizontal_plus_not_body (by omega) hk4 hr₀ hc₀ hc₁
      (by simpa [BodyNodeOrder, hk0, hk1, hk4] using horder) hb)
  · exact host_horizontal_minus_leaf_diagonal (by omega) hr₀ hc₀ hc₁
      (by simpa [BodyNodeOrder, hk0, hk1, hk4] using horder) hb

end Problem348.Construction

end OAI