Skip to content

Commit 4d97a15

Browse files
committed
feat: port Data.Finsupp.WellFounded (#2985)
1 parent de0323c commit 4d97a15

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ import Mathlib.Data.Finsupp.Order
611611
import Mathlib.Data.Finsupp.Pointwise
612612
import Mathlib.Data.Finsupp.Pwo
613613
import Mathlib.Data.Finsupp.ToDfinsupp
614+
import Mathlib.Data.Finsupp.WellFounded
614615
import Mathlib.Data.Fintype.Basic
615616
import Mathlib.Data.Fintype.BigOperators
616617
import Mathlib.Data.Fintype.Card
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/-
2+
Copyright (c) 2022 Junyan Xu. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Junyan Xu
5+
6+
! This file was ported from Lean 3 source module data.finsupp.well_founded
7+
! leanprover-community/mathlib commit 5fd3186f1ec30a75d5f65732e3ce5e623382556f
8+
! Please do not edit these lines, except to modify the commit id
9+
! if you have ported upstream changes.
10+
-/
11+
import Mathlib.Data.Dfinsupp.WellFounded
12+
import Mathlib.Data.Finsupp.Lex
13+
14+
/-!
15+
# Well-foundedness of the lexicographic and product orders on `Finsupp`
16+
17+
`Finsupp.Lex.wellFounded` and the two variants that follow it essentially say that if `(· > ·)` is
18+
a well order on `α`, `(· < ·)` is well-founded on `N`, and `0` is a bottom element in `N`, then the
19+
lexicographic `(· < ·)` is well-founded on `α →₀ N`.
20+
21+
`Finsupp.Lex.wellFoundedLT_of_finite` says that if `α` is finite and equipped with a linear order
22+
and `(· < ·)` is well-founded on `N`, then the lexicographic `(· < ·)` is well-founded on `α →₀ N`.
23+
24+
`Finsupp.wellFoundedLT` and `well_founded_lt_of_finite` state the same results for the product
25+
order `(· < ·)`, but without the ordering conditions on `α`.
26+
27+
All results are transferred from `Dfinsupp` via `Finsupp.toDfinsupp`.
28+
-/
29+
30+
31+
variable {α N : Type _}
32+
33+
namespace Finsupp
34+
35+
variable [Zero N] {r : α → α → Prop} {s : N → N → Prop} (hbot : ∀ ⦃n⦄, ¬s n 0)
36+
(hs : WellFounded s)
37+
38+
/-- Transferred from `Dfinsupp.Lex.acc`. See the top of that file for an explanation for the
39+
appearance of the relation `rᶜ ⊓ (≠)`. -/
40+
theorem Lex.acc (x : α →₀ N) (h : ∀ a ∈ x.support, Acc (rᶜ ⊓ (· ≠ ·)) a) :
41+
Acc (Finsupp.Lex r s) x := by
42+
rw [lex_eq_invImage_dfinsupp_lex]
43+
classical
44+
refine' InvImage.accessible toDfinsupp (Dfinsupp.Lex.acc (fun _ => hbot) (fun _ => hs) _ _)
45+
simpa only [toDfinsupp_support] using h
46+
#align finsupp.lex.acc Finsupp.Lex.acc
47+
48+
theorem Lex.wellFounded (hr : WellFounded <| rᶜ ⊓ (· ≠ ·)) : WellFounded (Finsupp.Lex r s) :=
49+
fun x => Lex.acc hbot hs x fun a _ => hr.apply a⟩
50+
#align finsupp.lex.well_founded Finsupp.Lex.wellFounded
51+
52+
theorem Lex.wellFounded' [IsTrichotomous α r] (hr : WellFounded (Function.swap r)) :
53+
WellFounded (Finsupp.Lex r s) :=
54+
(lex_eq_invImage_dfinsupp_lex r s).symm ▸
55+
InvImage.wf _ (Dfinsupp.Lex.wellFounded' (fun _ => hbot) (fun _ => hs) hr)
56+
#align finsupp.lex.well_founded' Finsupp.Lex.wellFounded'
57+
58+
instance Lex.wellFoundedLT {α N} [LT α] [IsTrichotomous α (· < ·)] [hα : WellFoundedGT α]
59+
[CanonicallyOrderedAddMonoid N] [hN : WellFoundedLT N] : WellFoundedLT (Lex (α →₀ N)) :=
60+
⟨Lex.wellFounded' (fun n => (zero_le n).not_lt) hN.wf hα.wf⟩
61+
#align finsupp.lex.well_founded_lt Finsupp.Lex.wellFoundedLT
62+
63+
variable (r)
64+
65+
theorem Lex.wellFounded_of_finite [IsStrictTotalOrder α r] [Finite α] [Zero N]
66+
(hs : WellFounded s) : WellFounded (Finsupp.Lex r s) :=
67+
InvImage.wf (@equivFunOnFinite α N _ _) (Pi.Lex.wellFounded r fun _ => hs)
68+
#align finsupp.lex.well_founded_of_finite Finsupp.Lex.wellFounded_of_finite
69+
70+
theorem Lex.wellFoundedLT_of_finite [LinearOrder α] [Finite α] [Zero N] [LT N]
71+
[hwf : WellFoundedLT N] : WellFoundedLT (Lex (α →₀ N)) :=
72+
⟨Finsupp.Lex.wellFounded_of_finite (· < ·) hwf.1
73+
#align finsupp.lex.well_founded_lt_of_finite Finsupp.Lex.wellFoundedLT_of_finite
74+
75+
protected theorem wellFoundedLT [Zero N] [Preorder N] [WellFoundedLT N] (hbot : ∀ n : N, ¬n < 0) :
76+
WellFoundedLT (α →₀ N) :=
77+
⟨InvImage.wf toDfinsupp (Dfinsupp.wellFoundedLT fun _ a => hbot a).wf⟩
78+
#align finsupp.well_founded_lt Finsupp.wellFoundedLT
79+
80+
instance well_founded_lt' {N} [CanonicallyOrderedAddMonoid N] [WellFoundedLT N] :
81+
WellFoundedLT (α →₀ N) :=
82+
Finsupp.wellFoundedLT fun a => (zero_le a).not_lt
83+
#align finsupp.well_founded_lt' Finsupp.well_founded_lt'
84+
85+
instance wellFoundedLT_of_finite [Finite α] [Zero N] [Preorder N] [WellFoundedLT N] :
86+
WellFoundedLT (α →₀ N) :=
87+
⟨InvImage.wf equivFunOnFinite Function.wellFoundedLT.wf⟩
88+
#align finsupp.well_founded_lt_of_finite Finsupp.wellFoundedLT_of_finite
89+
90+
end Finsupp

0 commit comments

Comments
 (0)