New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(data/finsupp/lex): linear order on finsupps #15984
Conversation
Co-authored-by: Violeta Hernández <vi.hdz.p@gmail.com>
…munity/mathlib into adomani_finsupp_lex
src/data/finsupp/lex.lean
Outdated
|
||
variables {α N : Type*} [has_zero N] | ||
|
||
open_locale classical |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does removing this prevent things being noncomputable
below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing open_locale classical
prevents union in finsupp from existing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you're missing decidable_eq α
on a lemma somewhere. If you find yourself addnig open_locale classical
to make a lemma statement compile, you've made a wrong turn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I then also add decidable_pred (λ (a : α), ⇑f a ≠ ⇑g a)
, which now Lean asks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Or maybe decidable_eq N
?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eric-wieser, I take it that you are happy with the decidable_eq
assumption, instead of the ne
version that is needed? Is there some rationale between preferring one over the other (besides simplicity of stating)?
Can you copy over as many of the |
Co-authored-by: Violeta Hernández <vi.hdz.p@gmail.com>
…munity/mathlib into adomani_finsupp_lex
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
If I understand correctly, in the |
I think the suggestion is to prove the |
Sure, but those lemmas involve inequalities on the non-lex type, which does not have an order currently. |
What about this one? mathlib/src/data/finsupp/order.lean Line 37 in a21a8bc
|
Eric, thanks! I was missing the import! I added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget the lemmas finsupp.to_lex_apply
and finsupp.of_lex_apply
!
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
…munity/mathlib into adomani_finsupp_lex
These lemmas are in! I tried to use the #check @pi.lex.linear_order
pi.lex.linear_order :
Π {ι : Type u_3} {β : ι → Type u_4} [_inst_1 : linear_order ι]
[_inst_2 : is_well_order ι has_lt.lt] -- <-- here
[_inst_3 : Π (a : ι), linear_order (β a)], linear_order (lex (Π (i : ι), β i)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a constructive version that doesn't need wit
:
private def lt_trichotomy_rec {P : lex (α →₀ N)→ lex (α →₀ N) → Sort*}
(h_lt : Π {f g}, f < g → P f g) (h_eq : Π {f g}, f = g → P f g) (h_gt : Π {f g}, g < f → P f g)
(f g) : P f g :=
(λ f g : α →₀ N, show P (to_lex f) (to_lex g), from
match _, rfl : ∀ y, (f.diff g).min = y → _ with
| ⊤, h := h_eq (finsupp.diff_eq_empty.mp (finset.min_eq_top.mp h))
| (wit : α), h :=
have hne : f wit ≠ g wit := mem_diff.mp (finset.mem_of_min h),
-- have hne' : f ≠ g := finsupp.diff_eq_empty.not.mp (ne_empty_o_,
if hwit : f wit < g wit then
h_lt ⟨wit, by exact λ j hj, begin
refine mem_diff.not_left.mp _,
replace hj := (with_top.coe_lt_coe.mpr hj).trans_eq h.symm,
contrapose! hj,
exact finset.min_le_coe_of_mem hj,
end, hwit⟩
else
have hwit' : g wit < f wit := hne.lt_or_lt.resolve_left hwit,
h_gt ⟨wit, by exact λ j hj, begin
rw diff_comm at h,
refine mem_diff.not_left.mp _,
replace hj := (with_top.coe_lt_coe.mpr hj).trans_eq h.symm,
contrapose! hj,
exact finset.min_le_coe_of_mem hj,
end, hwit'⟩
end) (of_lex f) (of_lex g)
instance lex.decidable_le : @decidable_rel (lex (α →₀ N)) (≤) :=
lt_trichotomy_rec
(λ f g h, is_true $ or.inr h)
(λ f g h, is_true $ or.inl $ congr_arg _ h)
(λ f g h, is_false $ λ h', (lt_irrefl _ (h.trans_le h')).elim)
instance lex.decidable_lt : @decidable_rel (lex (α →₀ N)) (<) :=
lt_trichotomy_rec
(λ f g h, is_true h)
(λ f g h, is_false h.not_lt)
(λ f g h, is_false h.asymm)
/-- The linear order on `finsupp`s obtained by the lexicographic ordering. -/
instance lex.linear_order : linear_order (lex (α →₀ N)) :=
{ le_total := lt_trichotomy_rec
(λ f g h, or.inl h.le)
(λ f g h, or.inl h.le)
(λ f g h, or.inr h.le),
decidable_lt := by apply_instance,
decidable_le := by apply_instance,
decidable_eq := by apply_instance,
..lex.partial_order }
There's one obvious duplication there that would be solved either by wit
or more API for diff
…munity/mathlib into adomani_finsupp_lex
@eric-wieser, if you are happy with this version feel free to push it! I am partly in favour of Also, my eventual goal is to be able to prove that several |
I've pushed a slightly cleaner version. I think the problem with your |
@eric-wieser, do you mind if I PR the |
This PR has been essentially replaced by #16127. |
…in (#16192) These four lemmas were proved and used by Eric in his decidable version of `finsupp.lex`, replacing my previous undecidable one. They are extracted from #15984 (now closed) and used in #16127 (which replaces the closed PR). Authored-by: Eric Wieser <[wieser.eric@gmail.com](mailto:wieser.eric@gmail.com)> Submitted by me 😄
…t classes (#16127) This PR constructs a linear order on `finsupp`s where both source and target are linearly ordered. This is useful for #15983, where these linear orders help prove that (some) `add_monoid_algebra`s have no non-trivial zero-divisors. The PR also proves that the lexicographic linear order on finitely supported functions preserves a few covariant class assumptions. As always, comments and suggestions are really really appreciated! [Zulip discussion](https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/linear.20order.20on.20finsupps) This PR supersedes #15984.
EDIT: #16127 is an evolution of this PR. This PR has been closed.
This PR constructs a linear order on
finsupp
s where both source and target are linearly ordered. This is useful for #15983, where these linear orders are used to prove that add_monoid_algebras have no non-trivial zero-divisors.The PR also proves that the lexicographic linear order on finitely supported functions preserves (one) covariant class assumption.
This is a further step in proving that many
add_monoid_algebra
s have no zero-divisors.This PR is work in progress and comments or suggestions are as usual really really appreciated!
Zulip discussion
lex
/order_dual
#16122