@@ -251,6 +251,31 @@ by rw [coe_singleton, set.singleton_subset_iff]
251
251
{a} ⊆ s ↔ a ∈ s :=
252
252
singleton_subset_set_iff
253
253
254
+ /-! ### cons -/
255
+
256
+ /-- `cons a s h` is the set `{a} ∪ s` containing `a` and the elements of `s`. It is the same as
257
+ `insert a s` when it is defined, but unlike `insert a s` it does not require `decidable_eq α`,
258
+ and the union is guaranteed to be disjoint. -/
259
+ def cons {α} (a : α) (s : finset α) (h : a ∉ s) : finset α :=
260
+ ⟨a :: s.1 , multiset.nodup_cons.2 ⟨h, s.2 ⟩⟩
261
+
262
+ @[simp] theorem mem_cons {α a s h b} : b ∈ @cons α a s h ↔ b = a ∨ b ∈ s :=
263
+ by rcases s with ⟨⟨s⟩⟩; apply list.mem_cons_iff
264
+
265
+ @[simp] theorem cons_val {a : α} {s : finset α} (h : a ∉ s) : (cons a s h).1 = a :: s.1 := rfl
266
+
267
+ /-! ### disjoint union -/
268
+
269
+ /-- `disj_union s t h` is the set such that `a ∈ disj_union s t h` iff `a ∈ s` or `a ∈ t`.
270
+ It is the same as `s ∪ t`, but it does not require decidable equality on the type. The hypothesis
271
+ ensures that the sets are disjoint. -/
272
+ def disj_union {α} (s t : finset α) (h : ∀ a ∈ s, a ∉ t) : finset α :=
273
+ ⟨s.1 + t.1 , multiset.nodup_add.2 ⟨s.2 , t.2 , h⟩⟩
274
+
275
+ @[simp] theorem mem_disj_union {α s t h a} :
276
+ a ∈ @disj_union α s t h ↔ a ∈ s ∨ a ∈ t :=
277
+ by rcases s with ⟨⟨s⟩⟩; rcases t with ⟨⟨t⟩⟩; apply list.mem_append
278
+
254
279
/-! ### insert -/
255
280
section decidable_eq
256
281
variables [decidable_eq α]
@@ -276,6 +301,9 @@ mem_ndinsert_of_mem h
276
301
theorem mem_of_mem_insert_of_ne {a b : α} {s : finset α} (h : b ∈ insert a s) : b ≠ a → b ∈ s :=
277
302
(mem_insert.1 h).resolve_left
278
303
304
+ @[simp] theorem cons_eq_insert {α} [decidable_eq α] (a s h) : @cons α a s h = insert a s :=
305
+ ext $ λ a, by simp
306
+
279
307
@[simp, norm_cast] lemma coe_insert (a : α) (s : finset α) :
280
308
↑(insert a s) = (insert a ↑s : set α) :=
281
309
set.ext $ λ x, by simp only [mem_coe, mem_insert, set.mem_insert_iff]
@@ -289,10 +317,10 @@ eq_of_veq $ ndinsert_of_mem h
289
317
insert_eq_of_mem $ mem_singleton_self _
290
318
291
319
theorem insert.comm (a b : α) (s : finset α) : insert a (insert b s) = insert b (insert a s) :=
292
- ext $ λ x, by simp only [finset. mem_insert, or.left_comm]
320
+ ext $ λ x, by simp only [mem_insert, or.left_comm]
293
321
294
322
@[simp] theorem insert_idem (a : α) (s : finset α) : insert a (insert a s) = insert a s :=
295
- ext $ λ x, by simp only [finset. mem_insert, or.assoc.symm, or_self]
323
+ ext $ λ x, by simp only [mem_insert, or.assoc.symm, or_self]
296
324
297
325
@[simp] theorem insert_ne_empty (a : α) (s : finset α) : insert a s ≠ ∅ :=
298
326
ne_empty_of_mem (mem_insert_self a s)
@@ -342,8 +370,8 @@ def subtype_insert_equiv_option {t : finset α} {x : α} (h : x ∉ t) :
342
370
{i // i ∈ insert x t} ≃ option {i // i ∈ t} :=
343
371
begin
344
372
refine
345
- { to_fun := λ y, if h : ↑y = x then none else some ⟨y, (finset. mem_insert.mp y.2 ).resolve_left h⟩,
346
- inv_fun := λ y, y.elim ⟨x, finset. mem_insert_self _ _⟩ $ λ z, ⟨z, finset. mem_insert_of_mem z.2 ⟩,
373
+ { to_fun := λ y, if h : ↑y = x then none else some ⟨y, (mem_insert.mp y.2 ).resolve_left h⟩,
374
+ inv_fun := λ y, y.elim ⟨x, mem_insert_self _ _⟩ $ λ z, ⟨z, mem_insert_of_mem z.2 ⟩,
347
375
.. },
348
376
{ intro y, by_cases h : ↑y = x,
349
377
simp only [subtype.ext_iff, h, option.elim, dif_pos, subtype.coe_mk],
@@ -366,6 +394,9 @@ ndunion_eq_union s₁.2
366
394
367
395
@[simp] theorem mem_union {a : α} {s₁ s₂ : finset α} : a ∈ s₁ ∪ s₂ ↔ a ∈ s₁ ∨ a ∈ s₂ := mem_ndunion
368
396
397
+ @[simp] theorem disj_union_eq_union {α} [decidable_eq α] (s t h) : @disj_union α s t h = s ∪ t :=
398
+ ext $ λ a, by simp
399
+
369
400
theorem mem_union_left {a : α} {s₁ : finset α} (s₂ : finset α) (h : a ∈ s₁) : a ∈ s₁ ∪ s₂ :=
370
401
mem_union.2 $ or.inl h
371
402
0 commit comments