Skip to content

feat(Data/List): decidability of HasPeriod and periods of repeated lists#41882

Open
theebayuser wants to merge 3 commits into
leanprover-community:masterfrom
theebayuser:daniel/list-hasperiod-decidable
Open

feat(Data/List): decidability of HasPeriod and periods of repeated lists#41882
theebayuser wants to merge 3 commits into
leanprover-community:masterfrom
theebayuser:daniel/list-hasperiod-decidable

Conversation

@theebayuser

Copy link
Copy Markdown

Hello, this PR extends Mathlib/Data/List/PeriodicityLemma.lean with:

  • a Decidable (List.HasPeriod w p) instance (it is a prefix test), and
  • two directions that relate periods to repetition:
    • hasPeriod_flatten_replicate(replicate n l).flatten has period l.length
    • eq_flatten_replicate_of_hasPeriod — a word with period p and length r * p is the r-fold repetition of its length-p prefix.

This characterizes r-th powers of words by a period plus a length constraint, which a future follow-up PR that I plan to work on will use.

AI disclosure: This code was mostly generated by Claude Fable 5 and Opus 4.8 as part of my larger project on combinatorics on words, which I then reviewed and revised to contribute to mathlib.

Extend PeriodicityLemma.lean with the correspondence between periods and
repetitions: (replicate n l).flatten has period l.length
(hasPeriod_flatten_replicate), and conversely a list with period p and
length exactly r * p is the r-fold repetition of its length-p prefix
(eq_flatten_replicate_of_hasPeriod). Also provide a Decidable instance
for HasPeriod, immediate from its definition as a prefix test.
@github-actions github-actions Bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Jul 18, 2026
@github-actions

Copy link
Copy Markdown

Welcome new contributor!

Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the awaiting-author tag, or another reason described in the Lifecycle of a PR. The review dashboard has a dedicated webpage which shows whether your PR is on the review queue, and (if not), why.

If you haven't already done so, please come to https://leanprover.zulipchat.com/, introduce yourself, and mention your new PR.

Thank you again for joining our community.

@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown

PR summary 728c687d4b

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ eq_flatten_replicate_of_hasPeriod
+ hasPeriod_flatten_replicate
+ instance [DecidableEq α] (w : List α) (p : ℕ) : Decidable (w.HasPeriod p)
+ length_flatten_replicate

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

Lean-aware diff — post-build, computed from the Lean environment (commit 728c687).

  • +4 new declarations
  • −0 removed declarations
+List.eq_flatten_replicate_of_hasPeriod
+List.hasPeriod_flatten_replicate
+List.instDecidableHasPeriodOfDecidableEq
+List.length_flatten_replicate

No changes to strong technical debt.

No changes to weak technical debt.

Current commit 728c687d4b
Reference commit abb22825db

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions Bot added the t-data Data (lists, quotients, numbers, etc) label Jul 18, 2026
@theebayuser

Copy link
Copy Markdown
Author

LLM-generated

@github-actions github-actions Bot added the LLM-generated PRs with substantial input from LLMs - review accordingly label Jul 18, 2026
Comment thread Mathlib/Data/List/PeriodicityLemma.lean Outdated
Comment thread Mathlib/Data/List/PeriodicityLemma.lean Outdated
Comment thread Mathlib/Data/List/PeriodicityLemma.lean Outdated
Comment thread Mathlib/Data/List/PeriodicityLemma.lean Outdated
- golf the Decidable instance via inferInstanceAs
- restructure hasPeriod_flatten_replicate as a recursive match with | 0 | 1 => simp
- reflow the eq_flatten_replicate_of_hasPeriod signature

Suggested-by: SnirBroshi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LLM-generated PRs with substantial input from LLMs - review accordingly new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-data Data (lists, quotients, numbers, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants