File size: 3,947 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
import OAI.Combinatorics.MatrixRemoval.Host
import OAI.Combinatorics.MatrixRemoval.TreePositions

namespace OAI

/-!
Comparison lemmas for the concrete depth-first tree orders used in
mode localization.
-/

namespace Problem348.Construction

open TreePositions

theorem eq_plusPos_of_atLevel {h i : ℕ} {v : VariablePosition h}
    (hv : AtLevel i true v) :
    v = TreePositions.plusPos i (hv.1 ▸ depth_le v) v.2 := by
  apply Prod.ext
  · apply Fin.ext
    have hc := v.1.isLt
    obtain ⟨hd, hs⟩ := hv
    simp only [depth] at hd
    change v.1.val = 2 * i
    rcases hs with hi | hs
    · omega
    · simp only [plus, decide_eq_true_eq] at hs
      omega
  · rfl

theorem eq_minusPos_of_atLevel {h i : ℕ} {v : VariablePosition h}
    (hv : AtLevel i false v) :
    v = TreePositions.minusPos i (hv.1 ▸ depth_le v) v.2 := by
  apply Prod.ext
  · apply Fin.ext
    have hc := v.1.isLt
    obtain ⟨hd, hs⟩ := hv
    simp only [depth] at hd
    change v.1.val = if i = h then 2 * h else 2 * i + 1
    split_ifs with hi
    · omega
    · rcases hs with hs | hs
      · exact (hi hs).elim
      · simp only [plus, decide_eq_false_iff_not] at hs
        omega
  · rfl

theorem node_eq_level_node {h i : ℕ} {v : VariablePosition h}
    (hv : depth v = i) : node v = TreePositions.node i v.2 := by
  simp [node, TreePositions.node, hv]

/-- Row plus child precedes row plus parent exactly for the stated parent-node inequality. -/
theorem row_plus_lt_iff {h i : ℕ} {child parent : VariablePosition h}
    (hc : AtLevel (i + 1) true child) (hp : AtLevel i true parent) :
    TreePositions.rowKey h child < TreePositions.rowKey h parent ↔
      node child / 2 ≤ node parent := by
  have hi : i < h := by have := hc.1 ▸ depth_le child; omega
  have hn₁ := node_eq_level_node hc.1
  have hn₂ := node_eq_level_node hp.1
  rw [hn₁, hn₂, eq_plusPos_of_atLevel hc, eq_plusPos_of_atLevel hp]
  exact TreePositions.row_plus_child_lt_parent hi child.2 parent.2

/-- Row minus parent precedes row minus child exactly for the parent-node inequality. -/
theorem row_minus_lt_iff {h i : ℕ} {child parent : VariablePosition h}
    (hc : AtLevel (i + 1) false child) (hp : AtLevel i false parent) :
    TreePositions.rowKey h parent < TreePositions.rowKey h child ↔
      node parent ≤ node child / 2 := by
  have hi : i < h := by have := hc.1 ▸ depth_le child; omega
  have hn₁ := node_eq_level_node hc.1
  have hn₂ := node_eq_level_node hp.1
  rw [hn₁, hn₂, eq_minusPos_of_atLevel hc, eq_minusPos_of_atLevel hp]
  exact TreePositions.row_minus_parent_lt_child hi child.2 parent.2

/-- Column plus parent precedes column plus child exactly for the parent-node inequality. -/
theorem column_plus_lt_iff {h i : ℕ} {child parent : VariablePosition h}
    (hc : AtLevel (i + 1) true child) (hp : AtLevel i true parent) :
    TreePositions.columnKey h parent < TreePositions.columnKey h child ↔
      node parent ≤ node child / 2 := by
  have hi : i < h := by have := hc.1 ▸ depth_le child; omega
  have hn₁ := node_eq_level_node hc.1
  have hn₂ := node_eq_level_node hp.1
  rw [hn₁, hn₂, eq_plusPos_of_atLevel hc, eq_plusPos_of_atLevel hp]
  exact TreePositions.column_plus_parent_lt_child hi child.2 parent.2

/-- Column minus child precedes column minus parent exactly for the parent-node inequality. -/
theorem column_minus_lt_iff {h i : ℕ} {child parent : VariablePosition h}
    (hc : AtLevel (i + 1) false child) (hp : AtLevel i false parent) :
    TreePositions.columnKey h child < TreePositions.columnKey h parent ↔
      node child / 2 ≤ node parent := by
  have hi : i < h := by have := hc.1 ▸ depth_le child; omega
  have hn₁ := node_eq_level_node hc.1
  have hn₂ := node_eq_level_node hp.1
  rw [hn₁, hn₂, eq_minusPos_of_atLevel hc, eq_minusPos_of_atLevel hp]
  exact TreePositions.column_minus_child_lt_parent hi child.2 parent.2

end Problem348.Construction

end OAI