Repository navigation
Expand file tree
/
Copy pathChallenge.lean
More file actions
134 lines (99 loc) · 4.44 KB
/
Copy pathChallenge.lean
File metadata and controls
134 lines (99 loc) · 4.44 KB
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
import Mathlib
namespace OAI
noncomputable section
namespace TruffetV4Counterexample
abbrev Coeff := WithBot ℝ
abbrev Form := Fin 3 → Coeff
abbrev Var := Fin 2
abbrev RowIndex := Fin 2
def column (j : Var) : Fin 3 := ⟨j.val, Nat.lt_trans j.isLt (by decide)⟩
def nullForm : Form := fun _ => ⊥
structure Row where
lhs : Form
rhs : Form
structure State where
rows : RowIndex → Row
cost : Form
remaining : Var → Prop
def wellFormed (s : State) : Prop := ∀ j, ¬ s.remaining j →
s.cost (column j) = ⊥ ∧ ∀ i,
(s.rows i).lhs (column j) = ⊥ ∧ (s.rows i).rhs (column j) = ⊥
def eval (f : Form) (w : Fin 3 → ℝ) : Coeff :=
max (f 0 + (w 0 : Coeff)) (max (f 1 + (w 1 : Coeff)) (f 2 + (w 2 : Coeff)))
def feasible (s : State) (w : Fin 3 → ℝ) : Prop :=
∀ i, eval (s.rows i).rhs w ≤ eval (s.rows i).lhs w
def lower (s : State) (i : RowIndex) (j : Var) : Prop :=
(s.rows i).lhs (column j) ≠ ⊥ ∧
(s.rows i).rhs (column j) < (s.rows i).lhs (column j)
def upper (s : State) (i : RowIndex) (j : Var) : Prop :=
(s.rows i).rhs (column j) ≠ ⊥ ∧
(s.rows i).lhs (column j) < (s.rows i).rhs (column j)
def dominating (s : State) (j : Var) : Prop :=
s.remaining j ∧ (∃ i, lower s i j) ∧ ∃ i, upper s i j
def eligible (s : State) (i : RowIndex) (j : Var) : Prop :=
s.remaining j ∧ lower s i j ∧ ((∃ k, dominating s k) → dominating s j)
def bounded (s : State) : Prop :=
∀ j, s.remaining j → (∃ i, lower s i j) ∨ ∃ i, upper s i j
def stop (s : State) : Prop := ∀ i, (s.rows i).rhs 2 ≤ (s.rows i).lhs 2
def switch (s : State) : Prop :=
(∀ j, s.remaining j → s.cost (column j) = ⊥) ∧ ¬ stop s ∧
(∃ j, s.remaining j) ∧
(¬ ∃ i j, s.remaining j ∧ lower s i j) ∧
∃ i j, s.remaining j ∧ upper s i j
def failure (s : State) : Prop := ¬ stop s ∧
((¬ ∃ j, s.remaining j) ∨
((¬ ∃ i j, s.remaining j ∧ lower s i j) ∧
(¬ ∃ i j, s.remaining j ∧ upper s i j)))
def lowerForm (s : State) (i : RowIndex) (j : Var) : Form := fun k =>
if k = column j then ⊥ else
(s.rows i).rhs k + ((-WithBot.unbotD 0 ((s.rows i).lhs (column j)) : ℝ) : Coeff)
def substitute (f : Form) (j : Var) (g : Form) : Form := fun k =>
if k = column j then ⊥ else max (f k) (f (column j) + g k)
def cleanup (r : Row) : Row := by
classical
exact if ∀ k, r.rhs k ≤ r.lhs k then ⟨nullForm, nullForm⟩ else r
def advance (s : State) (i : RowIndex) (j : Var) : State where
rows := fun r => cleanup ⟨substitute (s.rows r).lhs j (lowerForm s i j),
substitute (s.rows r).rhs j (lowerForm s i j)⟩
cost := substitute s.cost j (lowerForm s i j)
remaining := fun k => s.remaining k ∧ k ≠ j
def ForcedSingletonStep (s s' : State) (i : RowIndex) (j : Var) : Prop :=
wellFormed s ∧ wellFormed s' ∧
bounded s ∧ ¬ stop s ∧ ¬ switch s ∧ ¬ failure s ∧
(∀ r k, eligible s r k ↔ r = i ∧ k = j) ∧
(∃ k, (substitute s.cost j (lowerForm s i j)) k ≠ ⊥) ∧
s' = advance s i j
def initial : State where
rows := ![⟨![(0 : Coeff), 0, ⊥], ![⊥, ⊥, (0 : Coeff)]⟩,
⟨![(0 : Coeff), ⊥, ⊥], ![⊥, (1 : Coeff), ((-2 : ℝ) : Coeff)]⟩]
cost := ![(0 : Coeff), ⊥, ⊥]
remaining := fun _ => True
def middle : State where
rows := ![⟨nullForm, nullForm⟩,
⟨![(0 : Coeff), ⊥, ⊥], ![⊥, ⊥, (1 : Coeff)]⟩]
cost := ![(0 : Coeff), ⊥, ⊥]
remaining := fun j => j = 0
def finalState : State where
rows := fun _ => ⟨nullForm, nullForm⟩
cost := ![⊥, ⊥, (1 : Coeff)]
remaining := fun _ => False
def crossRowRestriction (s : State) : Prop :=
∀ i r : RowIndex, i ≠ r → ∀ α : ℝ, ∃ w : Fin 3 → ℝ,
eval (s.rows i).lhs w < (α : Coeff) + eval (s.rows r).rhs w
def output : Fin 3 → ℝ := ![1, 0, 0]
def better : Fin 3 → ℝ := ![0, -1, 0]
theorem finite_execution_not_optimal :
crossRowRestriction initial ∧
ForcedSingletonStep initial middle 0 1 ∧
ForcedSingletonStep middle finalState 1 0 ∧
(¬ ∃ j, finalState.remaining j) ∧ stop finalState ∧
feasible initial output ∧ feasible initial better ∧
output 2 = 0 ∧ better 2 = 0 ∧
(output 1 : Coeff) = eval (lowerForm initial 0 1) output ∧
(output 0 : Coeff) = eval (lowerForm middle 1 0) output ∧
eval initial.cost output = eval finalState.cost output ∧
eval initial.cost better < eval finalState.cost output := by
sorry
end TruffetV4Counterexample
end
end OAI