Zulip Chat Archive
Stream: batteries
Topic: move Mathlib.Data.Prod.Basic to batteries
Bulhwi Cha (Oct 16 2024 at 12:03):
I want to prove the following theorem, List.commonPrefixWithRest_comm
, but the function Prod.swap
is in Mathlib.Data.Prod.Basic
. Do you think it's worth moving the function and its lemmas to Lean's core library or Batteries?
namespace List
/-- Extract the longest common prefix of two lists, and the remainder of each list. -/
def commonPrefixWithRest [DecidableEq α] : (l₁ l₂ : List α) → List α × List α × List α
| [], l₂ => ([], [], l₂)
| l₁, [] => ([], l₁, [])
| a₁::l₁, a₂::l₂ =>
if a₁ = a₂ then
Prod.map (a₁ :: ·) id (commonPrefixWithRest l₁ l₂)
else
([], a₁ :: l₁, a₂ :: l₂)
theorem commonPrefixWithRest_comm [DecidableEq α] (l₁ l₂ : List α) :
commonPrefixWithRest l₁ l₂ = Prod.map id Prod.swap (commonPrefixWithRest l₂ l₁) := by
sorry
end List
François G. Dorais (Oct 16 2024 at 12:34):
That's an unexpected omission! Probably belongs in Lean core.
Kim Morrison (Oct 16 2024 at 22:46):
Kim Morrison (Oct 16 2024 at 22:47):
(commonPrefixWithRest
should be made tail-recursive)
Eric Wieser (Oct 16 2024 at 23:03):
Kim Morrison said:
Is it appropriate to upstream these to batteries anyway in the meantime, rather than waiting 2-3 weeks until the next Lean release?
Kim Morrison (Oct 16 2024 at 23:39):
Yes, no problem. I'd be happy to hit merge on PRs doing that, but won't do it myself.
Eric Wieser (Oct 16 2024 at 23:59):
Perhaps there should be a Lean.Upstreamed
folder in batteries for things that are already in lean, and have been backported? That would make your bumps just a matter of deleting everything in the directory
Kim Morrison (Oct 17 2024 at 00:46):
I don't think that's necessary for batteries. lake build
quickly tells me what to delete.
Bulhwi Cha (Oct 17 2024 at 01:40):
Kim Morrison said:
(
commonPrefixWithRest
should be made tail-recursive)
François G. Dorais has already made its tail-recursive version. :big_smile:
https://github.com/leanprover-community/batteries/pull/994#discussion_r1802832306
Last updated: May 02 2025 at 03:31 UTC