Skip to content

Commit ff64670

Browse files
committed
Renamed Sinz to sequential counter
1 parent ee22a6a commit ff64670

4 files changed

Lines changed: 160 additions & 160 deletions

File tree

lib_info.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ cardinality/
1212
| amk.lean Defines the at-most-k constraint, amk.
1313
| direct_amo.lean Defines the direct at-most-one encoding and proves it correct and well-behaved.
1414
| distinct.lean A helpful notion for the at-most-one constraint that refers to two distinct positions in a list.
15-
| sinz_amk.lean Defines the Sinz at-most-k constraint and proves it correct and well-behaved.
16-
| sinz_amo.lean Defines the Sinz at-most-one constraint, recursively and non-, and proves it correct and well-behaved.
15+
| sc_amk.lean Defines the sequential counter at-most-k constraint and proves it correct and well-behaved.
16+
| sc_amo.lean Defines the sequential counter at-most-one constraint, recursively and non-, and proves it correct and well-behaved.
1717

1818
cnf/
1919
| assignment.lean Defines the assignment type, the agree_on judgment, and aite to combine two assignments.
Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/-
2-
The Sinz at-most-one encoding.
2+
The sequential counter at-most-one encoding.
33
44
Authors: Cayden Codel, Jeremy Avigad, Marijn Heule
55
Carnegie Mellon University
@@ -15,7 +15,7 @@ import cardinality.alk
1515

1616
variables {V : Type*} [inhabited V] [decidable_eq V]
1717

18-
namespace sinz_amk
18+
namespace sc_amk
1919

2020
open list nat prod
2121
open literal clause cnf assignment distinct gensym encoding amk alk
@@ -40,7 +40,7 @@ def matrix (g : gensym V) (n : nat) : sig_var_matrix V :=
4040
@[inline] def ternary (S : sig_var_matrix V) (n row col : nat) (lit : literal V) : cnf V :=
4141
if (0 < col) then [[lit.flip, Neg (S row (col - 1)), Pos (S (row + 1) col)]] else []
4242

43-
def sinz_amk (k : nat) : enc_fn V
43+
def sc_amk (k : nat) : enc_fn V
4444
| [] g := ⟨[], g⟩
4545
| l g :=
4646
let n := length l in
@@ -56,13 +56,13 @@ def sinz_amk (k : nat) : enc_fn V
5656
[[Neg (S k (n - 1))]],
5757
(g.nfresh ((k + 1) * length l)).2
5858

59-
theorem sinz_amk_mem_vars :
60-
∀ ⦃v⦄, v ∈ (sinz_amk k l g).1.vars → v ∈ (clause.vars l) ∨ (v ∈ (g.nfresh ((k + 1) * length l)).1) :=
59+
theorem sc_amk_mem_vars :
60+
∀ ⦃v⦄, v ∈ (sc_amk k l g).1.vars → v ∈ (clause.vars l) ∨ (v ∈ (g.nfresh ((k + 1) * length l)).1) :=
6161
begin
6262
cases l with lit₁ ls,
63-
{ simp [sinz_amk] },
63+
{ simp [sc_amk] },
6464
{ intros v hv,
65-
simp [sinz_amk, -length, -map_with_index_cons] at hv,
65+
simp [sc_amk, -length, -map_with_index_cons] at hv,
6666
rcases hv with (hmem | ⟨row, hrow, col, hcol, hmem⟩ | ⟨row, hrow, _, ⟨_, col, ⟨hcol, rfl⟩, rfl⟩, h⟩ | rfl),
6767
{ rcases mem_vars_iff_exists_mem_clause_and_mem.mp hmem with ⟨c, hc, hv⟩,
6868
simp [-length, -map_with_index_cons] at hc,
@@ -122,38 +122,38 @@ begin
122122
exact disj_right.mp hdis (nth_mem_stock _ _)
123123
end
124124

125-
theorem xi_to_si_mem_sinz_amk (g : gensym V) {i : nat} (Hi : i < length l) :
126-
[(l.nth_le i Hi).flip, Pos (matrix g (length l) 0 i)] ∈ (sinz_amk k l g).1 :=
125+
theorem xi_to_si_mem_sc_amk (g : gensym V) {i : nat} (Hi : i < length l) :
126+
[(l.nth_le i Hi).flip, Pos (matrix g (length l) 0 i)] ∈ (sc_amk k l g).1 :=
127127
begin
128128
cases l with lit₁ ls, { simp at Hi, contradiction },
129-
rw sinz_amk,
129+
rw sc_amk,
130130
simp [xi_to_si, -map_with_index_cons],
131131
left,
132132
use [(lit₁ :: ls).nth_le i Hi, i, Hi],
133133
exact ⟨rfl, rfl⟩
134134
end
135135

136-
theorem si_to_next_si_mem_sinz_amk (g : gensym V) {row col : nat} :
136+
theorem si_to_next_si_mem_sc_amk (g : gensym V) {row col : nat} :
137137
row < (k + 1) → col < (length l) - 1
138-
[Neg (matrix g (length l) row col), Pos (matrix g (length l) row (col + 1))] ∈ (sinz_amk k l g).1 :=
138+
[Neg (matrix g (length l) row col), Pos (matrix g (length l) row (col + 1))] ∈ (sc_amk k l g).1 :=
139139
begin
140140
intros hrow hcol,
141141
cases l with lit₁ ls, { simp at hcol, contradiction },
142-
rw sinz_amk,
142+
rw sc_amk,
143143
simp [si_to_next_si, -map_with_index_cons],
144144
right, left,
145145
use [row, hrow, col, hcol],
146146
simp at hcol, simp [hcol]
147147
end
148148

149-
theorem ternary_mem_sinz_amk (g : gensym V) {row col : nat} (hcol : col < length l) :
149+
theorem ternary_mem_sc_amk (g : gensym V) {row col : nat} (hcol : col < length l) :
150150
row < k → 0 < col →
151151
[(l.nth_le col hcol).flip, Neg (matrix g (length l) row (col - 1)),
152-
Pos (matrix g (length l) (row + 1) col)] ∈ (sinz_amk k l g).1 :=
152+
Pos (matrix g (length l) (row + 1) col)] ∈ (sc_amk k l g).1 :=
153153
begin
154154
intros hr hc,
155155
cases l with lit₁ ls, { simp at hcol, contradiction },
156-
rw sinz_amk,
156+
rw sc_amk,
157157
simp [ternary, -map_with_index_cons],
158158
right, right,
159159
use [row, hr, [[((lit₁ :: ls).nth_le col hcol).flip, Neg (matrix g (ls.length + 1) row (col - 1)),
@@ -163,13 +163,13 @@ begin
163163
{ exact mem_singleton_self _ }
164164
end
165165

166-
theorem neg_final_mem_sinz_amk (g : gensym V) (l : list (literal V)) :
167-
l ≠ [] → [Neg (matrix g (length l) k ((length l) - 1))] ∈ (sinz_amk k l g).1 :=
166+
theorem neg_final_mem_sc_amk (g : gensym V) (l : list (literal V)) :
167+
l ≠ [] → [Neg (matrix g (length l) k ((length l) - 1))] ∈ (sc_amk k l g).1 :=
168168
begin
169169
cases l with lit₁ ls,
170170
{ intro hcon, contradiction },
171171
{ intro hnil,
172-
rw sinz_amk,
172+
rw sc_amk,
173173
simp only [mem_append, mem_singleton, eq_self_iff_true, and_self, or_true] }
174174
end
175175

@@ -179,7 +179,7 @@ def row_and_col_from_var (S : sig_var_matrix V) (n : nat) (v : V) : nat → nat
179179
| (r + 1) 0 := if v = S (r + 1) 0 then ⟨r + 1, 0else row_and_col_from_var r (n - 1)
180180
| (r + 1) (c + 1) := if v = S (r + 1) (c + 1) then ⟨r + 1, c + 1else row_and_col_from_var (r + 1) c
181181

182-
def sinz_amk_tau (l : list (literal V)) (g : gensym V) (τ : assignment V) : assignment V :=
182+
def sc_amk_tau (l : list (literal V)) (g : gensym V) (τ : assignment V) : assignment V :=
183183
aite (clause.vars l) τ
184184
(λ v, let ⟨r, c⟩ := row_and_col_from_var (matrix g (length l)) (length l) v (k + 1) ((length l) - 1) in
185185
(alk (r + 1)).eval τ (l.take (c + 1)))
@@ -267,13 +267,13 @@ begin
267267
exact absurd hcon (ne_of_lt hrow') } } }
268268
end
269269

270-
theorem sinz_amk_eval_tt_under_sinz_amk_tau {k : nat} (hdis : disj l g) : ∀ (τ : assignment V),
271-
(amk k).eval τ l = tt → (sinz_amk k l g).1.eval (sinz_amk_tau k l g τ) = tt :=
270+
theorem sc_amk_eval_tt_under_sc_amk_tau {k : nat} (hdis : disj l g) : ∀ (τ : assignment V),
271+
(amk k).eval τ l = tt → (sc_amk k l g).1.eval (sc_amk_tau k l g τ) = tt :=
272272
begin
273273
intros τ heval,
274274
cases l with lit₁ ls,
275-
{ simp [sinz_amk] },
276-
{ rw sinz_amk,
275+
{ simp [sc_amk] },
276+
{ rw sc_amk,
277277
simp [-map_with_index_cons],
278278
split,
279279
{ rw eval_tt_iff_forall_clause_eval_tt,
@@ -284,17 +284,17 @@ begin
284284
cases hlit : ((lit₁ :: ls).nth_le i hi).eval τ,
285285
{ use [((lit₁ :: ls).nth_le i hi).flip],
286286
split, { exact mem_cons_self _ _ },
287-
{ simp only [eval_flip, bnot_eq_true_eq_eq_ff, sinz_amk_tau],
287+
{ simp only [eval_flip, bnot_eq_true_eq_eq_ff, sc_amk_tau],
288288
rw aite_pos_lit (mem_vars_of_mem (nth_le_mem (lit₁ :: ls) i hi)),
289289
exact hlit } },
290290
{ use [Pos (matrix g (ls.length + 1) 0 i)],
291291
simp [literal.eval],
292-
rw sinz_amk_tau,
292+
rw sc_amk_tau,
293293
have := (matrix_not_mem_vars hdis 0 i),
294294
rw length at this |-,
295295
rw [aite_neg this, succ_sub_one],
296296
rw row_and_col_from_var_eq_row_and_col_of_lt g (zero_le (_ + 1)) hi (lt_succ_self _),
297-
{ rw sinz_amk_tau._match_1,
297+
{ rw sc_amk_tau._match_1,
298298
rw alo_eval_tt_iff_exists_eval_tt,
299299
use [((lit₁ :: ls).nth_le _ hi), nth_le_mem_take_of_lt hi (lt_succ_self _), hlit] },
300300
{ exact (λ hcon, absurd hcon.symm (succ_ne_zero k)) } } },
@@ -308,21 +308,21 @@ begin
308308
cases halk : (alk (row + 1)).eval τ ((lit₁ :: ls).take (col + 1)),
309309
{ use [Neg (matrix g (ls.length + 1) row col), mem_cons_self _ _],
310310
simp [literal.eval],
311-
rw sinz_amk_tau,
311+
rw sc_amk_tau,
312312
have := (matrix_not_mem_vars hdis row col),
313313
rw length at this,
314314
rw aite_neg this, simp,
315315
rw row_and_col_from_var_eq_row_and_col_of_lt g (le_of_lt hrow) (lt_succ_of_lt hcol) (lt_succ_self _),
316-
{ rw sinz_amk_tau._match_1, exact halk },
316+
{ rw sc_amk_tau._match_1, exact halk },
317317
{ exact (λ hcon, absurd hcon (ne_of_lt hrow)) } },
318318
{ use Pos (matrix g (ls.length + 1) row (col + 1)),
319319
simp [literal.eval],
320-
rw sinz_amk_tau,
320+
rw sc_amk_tau,
321321
have := (matrix_not_mem_vars hdis row (col + 1)),
322322
rw length at this,
323323
rw aite_neg this, simp,
324324
rw row_and_col_from_var_eq_row_and_col_of_lt g (le_of_lt hrow) (succ_lt_succ hcol) (lt_succ_self _),
325-
{ rw sinz_amk_tau._match_1,
325+
{ rw sc_amk_tau._match_1,
326326
exact eval_take_succ_tt_of_eval_take_tt halk },
327327
{ exact (λ _, succ_le_of_lt hcol) } } },
328328
split,
@@ -338,51 +338,51 @@ begin
338338
cases hlit : ((lit₁ :: ls).nth_le _ hcol).eval τ,
339339
{ use [((lit₁ :: ls).nth_le _ hcol).flip, mem_cons_self _ _],
340340
simp [eval_flip, -nth_le],
341-
rw sinz_amk_tau,
341+
rw sc_amk_tau,
342342
rw aite_pos_lit (mem_vars_of_mem (nth_le_mem (lit₁ :: ls) _ hcol)),
343343
exact hlit },
344344
{ cases halk : (alk (row + 1)).eval τ ((lit₁ :: ls).take (col + 1)),
345345
{ use [Neg (matrix g (ls.length + 1) row col)],
346346
simp [literal.eval],
347-
rw sinz_amk_tau,
347+
rw sc_amk_tau,
348348
have := (matrix_not_mem_vars hdis row col),
349349
rw length at this,
350350
rw aite_neg this, simp,
351351
rw row_and_col_from_var_eq_row_and_col_of_lt g (le_of_lt (lt_succ_of_lt hrow)) (lt_of_succ_lt hcol) (lt_succ_self _),
352-
{ rw sinz_amk_tau._match_1, exact halk },
352+
{ rw sc_amk_tau._match_1, exact halk },
353353
{ rintro rfl, exact absurd (lt_of_succ_lt hrow) (not_lt.mpr (le_refl _)) } },
354354
{ use [Pos (matrix g (ls.length + 1) (row + 1) (col + 1))],
355355
simp [literal.eval],
356-
rw sinz_amk_tau,
356+
rw sc_amk_tau,
357357
have := (matrix_not_mem_vars hdis (row + 1) (col + 1)),
358358
rw length at this,
359359
rw aite_neg this, simp,
360360
rw row_and_col_from_var_eq_row_and_col_of_lt g
361361
(succ_le_of_lt (lt_succ_of_lt hrow)) hcol (lt_succ_self _),
362-
{ rw sinz_amk_tau._match_1, rw alk.eval_take_tail_pos hlit, exact halk },
362+
{ rw sc_amk_tau._match_1, rw alk.eval_take_tail_pos hlit, exact halk },
363363
{ exact (λ hcon, absurd hcon (ne_of_lt (succ_lt_succ hrow))) } } } } },
364364
{ simp [literal.eval],
365-
rw sinz_amk_tau,
365+
rw sc_amk_tau,
366366
have := (matrix_not_mem_vars hdis k ls.length),
367367
rw length at this,
368368
rw aite_neg this, simp,
369369
rw row_and_col_from_var_eq_row_and_col_of_lt g (le_succ k) (lt_succ_self _) (lt_succ_self _),
370-
{ rw sinz_amk_tau._match_1,
370+
{ rw sc_amk_tau._match_1,
371371
simp,
372372
rw [amk_eval_eq_alk_succ_eval, bnot_eq_true_eq_eq_ff] at heval, exact heval },
373373
{ exact (λ _, le_refl _) } } }
374374
end
375375

376376
-- TODO: verify if need hdis later...
377377
theorem signal_semantics {k : nat} :
378-
(sinz_amk k l g).1.eval τ = tt → ∀ ⦃row col : nat⦄, row < k + 1 → col < length l →
378+
(sc_amk k l g).1.eval τ = tt → ∀ ⦃row col : nat⦄, row < k + 1 → col < length l →
379379
τ (matrix g (length l) row col) = ff → (amk row).eval τ (l.take (col + 1)) = tt :=
380380
begin
381381
intros heval row col hrow hcol htau,
382382
rw eval_tt_iff_forall_clause_eval_tt at heval,
383383
induction row with row ihr generalizing col,
384384
{ induction col with col ihc,
385-
{ have := heval _ (xi_to_si_mem_sinz_amk k g hcol),
385+
{ have := heval _ (xi_to_si_mem_sc_amk k g hcol),
386386
simp [eval_flip, literal.eval, htau] at this,
387387
cases l with lit₁ ls,
388388
{ simp at hcol, contradiction },
@@ -397,10 +397,10 @@ begin
397397
{ simp at hcol,
398398
have : col < (lit₁ :: ls).length - 1,
399399
{ simp only [length, add_succ_sub_one, add_zero], exact succ_lt_succ_iff.mp hcol },
400-
have := heval _ (si_to_next_si_mem_sinz_amk k g hrow this),
400+
have := heval _ (si_to_next_si_mem_sc_amk k g hrow this),
401401
rw length at htau htau',
402402
simp [literal.eval, htau', htau] at this, contradiction } } },
403-
{ have := heval _ (xi_to_si_mem_sinz_amk k g hcol),
403+
{ have := heval _ (xi_to_si_mem_sc_amk k g hcol),
404404
simp [literal.eval, eval_flip, hlit, htau] at this, contradiction } } },
405405
{ induction col with col ihc,
406406
{ cases l with lit₁ ls; simp },
@@ -419,28 +419,28 @@ begin
419419
{ simp at hcol, contradiction },
420420
{ have : col < (lit₁ :: ls).length - 1,
421421
{ simp only [length, add_succ_sub_one, add_zero], exact succ_lt_succ_iff.mp hcol },
422-
have := heval _ (si_to_next_si_mem_sinz_amk k g hrow this),
422+
have := heval _ (si_to_next_si_mem_sc_amk k g hrow this),
423423
rw length at htau htau'',
424424
simp [literal.eval, htau, htau''] at this, contradiction } } },
425-
{ have := heval _ (ternary_mem_sinz_amk k g hcol (succ_lt_succ_iff.mp hrow) (ne_zero.pos (succ col))),
425+
{ have := heval _ (ternary_mem_sc_amk k g hcol (succ_lt_succ_iff.mp hrow) (ne_zero.pos (succ col))),
426426
simp [literal.eval, eval_flip, hlit, htau', htau] at this,
427427
contradiction } } } }
428428
end
429429

430-
theorem sinz_amk_formula_encodes_amk : is_correct (amk k) (sinz_amk k : enc_fn V) :=
430+
theorem sc_amk_formula_encodes_amk : is_correct (amk k) (sc_amk k : enc_fn V) :=
431431
begin
432432
intros l g hdis τ,
433433
split,
434434
{ intro hamk,
435-
use [sinz_amk_tau k l g τ, sinz_amk_eval_tt_under_sinz_amk_tau hdis τ hamk],
435+
use [sc_amk_tau k l g τ, sc_amk_eval_tt_under_sc_amk_tau hdis τ hamk],
436436
intros v hv,
437-
rw [sinz_amk_tau, aite_pos hv] },
437+
rw [sc_amk_tau, aite_pos hv] },
438438
{ rintros ⟨σ, hs, hagree_on⟩,
439439
have hs_copy := hs,
440440
rw eval_tt_iff_forall_clause_eval_tt at hs,
441441
cases l with lit₁ ls,
442442
{ simp },
443-
{ have hfinal := hs _ (neg_final_mem_sinz_amk k g (lit₁ :: ls) (ne_nil_of_mem (mem_cons_self _ _))),
443+
{ have hfinal := hs _ (neg_final_mem_sc_amk k g (lit₁ :: ls) (ne_nil_of_mem (mem_cons_self _ _))),
444444
simp [literal.eval] at hfinal,
445445
have : ls.length < (lit₁ :: ls).length,
446446
{ rw length, exact lt_succ_self _ },
@@ -455,26 +455,26 @@ begin
455455
exact (add_one_mul a b).symm,
456456
end
457457

458-
theorem sinz_amk_is_wb : is_wb (sinz_amk k : enc_fn V) :=
458+
theorem sc_amk_is_wb : is_wb (sc_amk k : enc_fn V) :=
459459
begin
460460
intros l g hdis,
461461
cases l with lit₁ ls,
462-
{ simp [sinz_amk] },
462+
{ simp [sc_amk] },
463463
{ split,
464-
{ simp [sinz_amk],
464+
{ simp [sc_amk],
465465
exact nfresh_stock_subset g ((k + 1) * (length ls + 1)) },
466466
{ intros v hv,
467-
rcases sinz_amk_mem_vars k hv with (h | h),
467+
rcases sc_amk_mem_vars k hv with (h | h),
468468
{ exact set.mem_union_left _ h },
469469
{ apply set.mem_union_right,
470470
split,
471471
{ exact nfresh_mem_stock h },
472-
{ rw sinz_amk,
472+
{ rw sc_amk,
473473
unfold prod.snd,
474474
exact nth_not_mem_nfresh_stock h } } } }
475475
end
476476

477-
theorem sinz_amk_encodes_amk : encodes (amk k) (sinz_amk k : enc_fn V) :=
478-
sinz_amk_formula_encodes_amk k, sinz_amk_is_wb k⟩
477+
theorem sc_amk_encodes_amk : encodes (amk k) (sc_amk k : enc_fn V) :=
478+
sc_amk_formula_encodes_amk k, sc_amk_is_wb k⟩
479479

480-
end sinz_amk
480+
end sc_amk

0 commit comments

Comments
 (0)