Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit ddbb813

Browse files
committed
feat(data/fintype): finite choices, computably
1 parent a7b749f commit ddbb813

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

data/fintype.lean

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,62 @@ set_fintype _
268268

269269
instance set.fintype [fintype α] [decidable_eq α] : fintype (set α) :=
270270
pi.fintype
271+
272+
def quotient.fin_choice_aux {ι : Type*} [decidable_eq ι]
273+
{α : ι → Type*} [S : ∀ i, setoid (α i)] :
274+
∀ (l : list ι), (∀ i ∈ l, quotient (S i)) → @quotient (Π i ∈ l, α i) (by apply_instance)
275+
| [] f := ⟦λ i, false.elim⟧
276+
| (i::l) f := begin
277+
refine quotient.lift_on₂ (f i (list.mem_cons_self _ _))
278+
(quotient.fin_choice_aux l (λ j h, f j (list.mem_cons_of_mem _ h)))
279+
_ _,
280+
exact λ a l, ⟦λ j h,
281+
if e : j = i then by rw e; exact a else
282+
l _ (h.resolve_left e)⟧,
283+
refine λ a₁ l₁ a₂ l₂ h₁ h₂, quotient.sound (λ j h, _),
284+
by_cases e : j = i; simp [e],
285+
{ subst j, exact h₁ },
286+
{ exact h₂ _ _ }
287+
end
288+
289+
theorem quotient.fin_choice_aux_eq {ι : Type*} [decidable_eq ι]
290+
{α : ι → Type*} [S : ∀ i, setoid (α i)] :
291+
∀ (l : list ι) (f : ∀ i ∈ l, α i), quotient.fin_choice_aux l (λ i h, ⟦f i h⟧) = ⟦f⟧
292+
| [] f := quotient.sound (λ i h, h.elim)
293+
| (i::l) f := begin
294+
simp [quotient.fin_choice_aux, quotient.fin_choice_aux_eq l],
295+
refine quotient.sound (λ j h, _),
296+
by_cases e : j = i; simp [e],
297+
subst j, refl
298+
end
299+
300+
def quotient.fin_choice {ι : Type*} [fintype ι] [decidable_eq ι]
301+
{α : ι → Type*} [S : ∀ i, setoid (α i)]
302+
(f : ∀ i, quotient (S i)) : @quotient (Π i, α i) (by apply_instance) :=
303+
quotient.lift_on (@quotient.rec_on _ _ (λ l : multiset ι,
304+
@quotient (Π i ∈ l, α i) (by apply_instance))
305+
finset.univ.1
306+
(λ l, quotient.fin_choice_aux l (λ i _, f i))
307+
(λ a b h, begin
308+
have := λ a, quotient.fin_choice_aux_eq a (λ i h, quotient.out (f i)),
309+
simp [quotient.out_eq] at this,
310+
simp [this],
311+
let g := λ a:multiset ι, ⟦λ (i : ι) (h : i ∈ a), quotient.out (f i)⟧,
312+
refine eq_of_heq ((eq_rec_heq _ _).trans (_ : g a == g b)),
313+
congr' 1, exact quotient.sound h,
314+
end))
315+
(λ f, ⟦λ i, f i (finset.mem_univ _)⟧)
316+
(λ a b h, quotient.sound $ λ i, h _ _)
317+
318+
319+
theorem quotient.fin_choice_eq {ι : Type*} [fintype ι] [decidable_eq ι]
320+
{α : ι → Type*} [∀ i, setoid (α i)]
321+
(f : ∀ i, α i) : quotient.fin_choice (λ i, ⟦f i⟧) = ⟦f⟧ :=
322+
begin
323+
let q, swap, change quotient.lift_on q _ _ = _,
324+
have : q = ⟦λ i h, f i⟧,
325+
{ dsimp [q],
326+
exact quotient.induction_on
327+
(@finset.univ ι _).1 (λ l, quotient.fin_choice_aux_eq _ _) },
328+
simp [this], exact setoid.refl _
329+
end

data/quot.lean

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ noncomputable def quotient.out [s : setoid α] : quotient s → α := quot.out
4141
theorem quotient.mk_out [s : setoid α] (a : α) : ⟦a⟧.out ≈ a :=
4242
quotient.exact (quotient.out_eq _)
4343

44+
instance pi_setoid {ι : Sort*} {α : ι → Sort*} [∀ i, setoid (α i)] : setoid (Π i, α i) :=
45+
{ r := λ a b, ∀ i, a i ≈ b i,
46+
iseqv := ⟨
47+
λ a i, setoid.refl _,
48+
λ a b h i, setoid.symm (h _),
49+
λ a b c h₁ h₂ i, setoid.trans (h₁ _) (h₂ _)⟩ }
50+
51+
noncomputable def quotient.choice {ι : Type*} {α : ι → Type*} [S : ∀ i, setoid (α i)]
52+
(f : ∀ i, quotient (S i)) : @quotient (Π i, α i) (by apply_instance) :=
53+
⟦λ i, (f i).out⟧
54+
55+
theorem quotient.choice_eq {ι : Type*} {α : ι → Type*} [∀ i, setoid (α i)]
56+
(f : ∀ i, α i) : quotient.choice (λ i, ⟦f i⟧) = ⟦f⟧ :=
57+
quotient.sound $ λ i, quotient.mk_out _
58+
4459
/-- `trunc α` is the quotient of `α` by the always-true relation. This
4560
is related to the propositional truncation in HoTT, and is similar
4661
in effect to `nonempty α`, but unlike `nonempty α`, `trunc α` is data,

0 commit comments

Comments
 (0)