-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolveMax.v
More file actions
214 lines (190 loc) · 6.85 KB
/
Copy pathSolveMax.v
File metadata and controls
214 lines (190 loc) · 6.85 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
Require Coq.Arith.PeanoNat.
Require Import Omega.
Require Import LibTactics.
Require Import General.
Arguments max n m : simpl nomatch.
Ltac spec_max_with_guard m n :=
match goal with
| H: m < n |- _ => fail 1
| H: n <= m |- _ => fail 1
| _ =>
let ineq:=fresh "ineq" in
let eq:=fresh "eq" in
destruct (Max.max_spec m n) as [[ineq eq]|[ineq eq]];
rewrite eq in *
end.
Ltac le_gives_eq_tac m n :=
let H:=fresh in
assert (H: m <= n);
[omega |
rewrite (Max.max_l m n H) in *;
rewrite (Max.max_r n m H) in *].
Lemma lt_max_right : forall m n o, m < n -> m < max o n.
Proof. intuition. spec_max_with_guard o n; omega. Qed.
Lemma lt_max_left : forall m n o, m < n -> m < max n o.
Proof. intuition. spec_max_with_guard n o; omega. Qed.
Lemma max_lt : forall m n o, m < o -> n < o -> max m n < o.
Proof. intuition. spec_max_with_guard m n; omega. Qed.
Lemma max_lt_imp_left : forall m n o, max m n < o -> m < o.
Proof. intuition. spec_max_with_guard m n; omega. Qed.
Lemma max_lt_imp_right : forall m n o, max m n < o -> n < o.
Proof. intuition. spec_max_with_guard m n; omega. Qed.
Hint Resolve
lt_max_right
lt_max_left
max_lt
max_lt_imp_left
max_lt_imp_right.
Lemma le_max_right : forall m n o, m <= n -> m <= max o n.
Proof. intuition. spec_max_with_guard o n; omega. Qed.
Lemma le_max_left : forall m n o, m <= n -> m <= max n o.
Proof. intuition. spec_max_with_guard n o; omega. Qed.
Lemma max_le : forall m n o, m <= o -> n <= o -> max m n <= o.
Proof. intuition. spec_max_with_guard m n; omega. Qed.
Lemma max_le_imp_left : forall m n o, max m n <= o -> m <= o.
Proof. intuition. spec_max_with_guard m n; omega. Qed.
Lemma max_le_imp_right : forall m n o, max m n <= o -> n <= o.
Proof. intuition. spec_max_with_guard m n; omega. Qed.
Hint Resolve
le_max_right
le_max_left
max_le
max_le_imp_left
max_le_imp_left.
Lemma lt_S : forall n m, n < m -> S n < S m.
Proof. intuition. Qed.
Lemma le_S : forall n m, n <= m -> S n <= S m.
Proof. intuition. Qed.
Lemma eq_S : forall n m, n = m -> S n = S m.
Proof. congruence. Qed.
Lemma lt_P : forall n m, S n < S m -> n < m.
Proof. intuition. Qed.
Lemma le_P : forall n m, S n <= S m -> n <= m.
Proof. intuition. Qed.
Lemma eq_P : forall n m, S n = S m -> n = m.
Proof. congruence. Qed.
Lemma S_max_strategy : forall m n, S (max m n) = max (S m) (S n).
Proof. simpl. congruence. Qed.
Lemma lt_max_strategy : forall m n p,
m < max n p <-> ((m < n /\ p <= n) \/ (m < p /\ n < p)).
Proof. intuition. spec_max_with_guard n p; intuition. Qed.
Lemma max_lt_strategy : forall m n p,
max m n < p <-> (m < p /\ n < p).
Proof. intros m n p. spec_max_with_guard m n; intuition. Qed.
Lemma le_max_strategy : forall m n p,
m <=max n p <-> ((m <=n /\ p <= n) \/ (m <=p /\ n <=p)).
Proof. intuition. spec_max_with_guard n p; intuition. Qed.
Lemma max_le_strategy : forall m n p,
max m n <=p <-> (m <=p /\ n <=p).
Proof. intros m n p. spec_max_with_guard m n; intuition. Qed.
Lemma brute_force_max_eq : forall n m o,
n = max m o <-> (n = m /\ o <= m) \/ (n = o /\ m < o).
Proof.
intros n m o. destruct (Max.max_spec m o) as [[]|[]]; omega.
Qed.
Lemma brute_force_max_lt : forall n m o,
max n m < o <-> (n < o /\ m < o).
Proof.
intros n m o. destruct (Max.max_spec n m) as [[]|[]]; omega.
Qed.
Lemma brute_force_lt_max : forall n m o,
n < max m o <-> (n < m /\ o <= m) \/ (n < o /\ m < o).
Proof.
intros n m o. destruct (Max.max_spec m o) as [[]|[]]; omega.
Qed.
Lemma brute_force_max_le : forall n m o,
max n m <= o <-> (n <= o /\ m <= o).
Proof.
intros n m o. destruct (Max.max_spec n m) as [[]|[]]; omega.
Qed.
Lemma brute_force_le_max : forall n m o,
n <= max m o <-> (n <= m /\ o <= m) \/ (n <= o /\ m <= o).
Proof.
intros n m o. destruct (Max.max_spec m o) as [[]|[]]; omega.
Qed.
Ltac rewrite_triple_tac p m n o :=
(let m':=fresh in
let n':=fresh in
let o':=fresh in
remember m as m';
remember n as n';
remember o as o';
rewrite (p m' n' o') in *) .
Ltac explain_max' n p :=
let m:=fresh in
remember (max n p) as m;
rewrite_triple_tac brute_force_max_eq m n p.
Ltac explain_max :=
repeat match goal with
| _ => rewrite Max.max_idempotent in *
| _ => apply lt_S || apply le_S || apply eq_S
| H: _ |- _ => apply lt_P in H
| H: _ |- _ => apply le_P in H
| H: _ |- _ => apply le_P in H
| _ => rewrite Max.max_idempotent in *
| H: context[?n <= max ?m ?p] |- _ =>
rewrite_triple_tac brute_force_le_max ?n ?m ?p
| H: context[max ?n ?m <= ?p] |- _ =>
rewrite_triple_tac brute_force_max_le ?n ?m ?p
| H: context[?n < max ?m ?p] |- _ =>
rewrite_triple_tac brute_force_lt_max ?n ?m ?p
| H: context[max ?n ?m < ?p] |- _ =>
rewrite_triple_tac brute_force_max_lt ?n ?m ?p
(* these last two are all that are really needed *)
| |- context[max ?n ?p] => explain_max' n p
| H: context[max ?n ?p] |- _ => explain_max' n p
end.
(* I was trying to come up with an incomplete decision
procedure for solveing systems of equations involving
max without employing omega to do sat solving. *)
(*
Ltac solve_max_search n :=
match n with
| S ?n' =>
repeat match goal with
| _ => rewrite Max.max_idempotent in *
| _ => solve[assumption || congruence || omega]
| _ => apply lt_S || apply le_S || apply eq_S
| H: _ |- _ =>
apply lt_P in H || apply le_S in H || apply eq_P in H
| |- _ < max _ _ =>
(apply lt_max_left; omega_max_search)
|| (apply lt_max_right; omega_max_search)
| |- max _ _ < _ => apply max_lt
end
end.
*)
Ltac solve_max :=
intros;
try rewrite Max.max_0_l in *;
try rewrite Max.max_0_r in *;
try rewrite Max.max_idempotent in *;
explain_max;
subst;
omega.
Ltac max_tac :=
intuition solve[repeat autounfold in *;
simpl in *;
solve_max].
Example lt1 : forall n m o p, n < m -> n < max o (max p m).
Proof. max_tac. Qed.
Example lt2 : forall n m o p, n < m -> n < max (max p m) o.
Proof. max_tac. Qed.
Example eq1 : forall n m o p s t,
S (max (max (max n m) (max o p)) (max s t))
=
S (max (max (max o p) (max n m)) (max s t)).
Proof. max_tac. Qed.
Example le0 : forall t1 t2 x x1, x = x1 -> x <= max t1 t2 ->
S (max (max t1 t2) (max x x1))
<=
S (max t1 t2).
Proof. max_tac. Qed.
Example le1 : forall t0 t6 t4 t5 c1 c2 t8 t9,
(max (max t0 t6) (max t4 t5)) <=
(max (max (max (max t0 t6) (max t8 t9))
(max c1 c2))
(max (max t4 t5) (max t4 t5))).
Proof.
intros. max_tac.
Qed.