Skip to content

refactor: Language α as 1FS around Set (List α) - #46065

Open
Parcly-Taxel wants to merge 27 commits into
leanprover-community:masterfrom
Parcly-Taxel:language1fs-new
Open

Parcly-Taxel wants to merge 27 commits into
leanprover-community:masterfrom
Parcly-Taxel:language1fs-new

Conversation

@Parcly-Taxel

@Parcly-Taxel Parcly-Taxel commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Redefine

/-- A language is a set of strings over an alphabet. Implemented as a one-field structure. -/
@[ext]
structure Language (α : Type*) where
  /-- Convert a `Set (List α)` to a `Language α`. -/
  ofSetList ::
  /-- The underlying set -/
  toSetList : Set (List α)

This is step 2 of #mathlib4 > The new `Language` @ 💬. We also add some lemmas around SetSemiring singletons.

@github-actions github-actions Bot added the tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip label Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR summary 2b4be851eb

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ append_preimage_toSetList_acceptsFrom
+ comap
+ cons_preimage_toSetList_acceptsFrom
+ imageHom_singleton
+ instance : Add (Language α) where add := (· ⊔ ·)
+ instance : CompleteAtomicBooleanAlgebra (Language α) := toSetListEquiv.completeAtomicBooleanAlgebra
+ instance : Inhabited (Language α) where default := 0
+ instance : Insert (List α) (Language α) where insert a s := ofSetList (insert a s.toSetList)
+ instance : KStar (Language α)
+ instance : Membership (List α) (Language α) where mem s a := a ∈ s.toSetList
+ instance : Mul (Language α) where mul l m := ofSetList (image2 (· ++ ·) l.toSetList m.toSetList)
+ instance : One (Language α) where one := ofSetList {[]}
+ instance : Singleton (List α) (Language α) where singleton a := ofSetList {a}
+ instance : Sub (Language α) where sub := (· \ ·)
+ instance : Zero (Language α) where zero := ofSetList ∅
+ map_singleton
+ mem_comap
+ mem_ofSetList
+ mem_singleton_iff
+ mem_toSetList
+ ofSetList_eq_one_iff
+ ofSetList_eq_zero_iff
+ ofSetList_insert
+ ofSetList_singleton
+ ofSetList_toSetList
+ ofSet_eq_one_iff
+ ofSet_eq_zero_iff
+ one_sup_kstar_mul_self_eq_kstar
+ one_sup_self_mul_kstar_eq_kstar
+ singleton_one
+ singleton_pow
+ toSetListEquiv
+ toSetList_add
+ toSetList_eq_empty_iff
+ toSetList_eq_singleton_nil_iff
+ toSetList_iInf
+ toSetList_iSup
+ toSetList_insert
+ toSetList_kstar
+ toSetList_kstar_eq_ne_nil
+ toSetList_mul
+ toSetList_ofSetList
+ toSetList_one
+ toSetList_reverse
+ toSetList_singleton
+ toSetList_sub
+ toSetList_zero
+ toSet_eq_empty_iff
+ toSet_eq_singleton_one_iff
++ singleton_mul_singleton
++-- accepts
+-+- acceptsFrom
- ext
- instance : Add (Language α)
- instance : Inhabited (Language α) := ⟨(∅ : Set _)⟩
- instance : Insert (List α) (Language α) := ⟨Set.insert⟩
- instance : KStar (Language α) := ⟨fun l ↦ {x | ∃ L : List (List α), x = L.flatten ∧ ∀ y ∈ L, y ∈ l}⟩
- instance : Membership (List α) (Language α) := ⟨Set.Mem⟩
- instance : Mul (Language α)
- instance : One (Language α)
- instance : Singleton (List α) (Language α) := ⟨Set.singleton⟩
- instance : Sub (Language α)
- instance : Zero (Language α)

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 2b4be85).

  • +56 new declarations
  • −1 removed declarations
+Language.casesOn
+Language.comap
+Language.comap_apply
+Language.ctorIdx
+Language.instCompleteAtomicBooleanAlgebra
+Language.map_singleton
+Language.mem_comap
+Language.mem_ofSetList
+Language.mem_singleton_iff
+Language.mem_toSetList
+Language.noConfusion
+Language.noConfusionType
+Language.ofSetList
+Language.ofSetList.inj
+Language.ofSetList.injEq
+Language.ofSetList.noConfusion
+Language.ofSetList.sizeOf_spec
+Language.ofSetList_eq_one_iff
+Language.ofSetList_eq_zero_iff
+Language.ofSetList_insert
+Language.ofSetList_singleton
+Language.ofSetList_toSetList
+Language.one_sup_kstar_mul_self_eq_kstar
+Language.one_sup_self_mul_kstar_eq_kstar
+Language.rec
+Language.recOn
+Language.singleton_mul_singleton
+Language.toSetList
+Language.toSetListEquiv
+Language.toSetListEquiv_apply
+Language.toSetListEquiv_symm_apply_toSetList
+Language.toSetList_add
+Language.toSetList_eq_empty_iff
+Language.toSetList_eq_singleton_nil_iff
+Language.toSetList_iInf
+Language.toSetList_iSup
+Language.toSetList_insert
+Language.toSetList_kstar
+Language.toSetList_kstar_eq_ne_nil
+Language.toSetList_mul
+Language.toSetList_ofSetList
+Language.toSetList_one
+Language.toSetList_reverse
+Language.toSetList_singleton
+Language.toSetList_sub
+Language.toSetList_zero
+NFA.append_preimage_toSetList_acceptsFrom
+NFA.cons_preimage_toSetList_acceptsFrom
+SetSemiring.imageHom_singleton
+SetSemiring.ofSet_eq_one_iff
+SetSemiring.ofSet_eq_zero_iff
+SetSemiring.singleton_mul_singleton
+SetSemiring.singleton_one
+SetSemiring.singleton_pow
+SetSemiring.toSet_eq_empty_iff
+SetSemiring.toSet_eq_singleton_one_iff
-instCompleteAtomicBooleanAlgebraLanguage

Decrease in strong tech debt: (relative, absolute) = (14.00, 0.00)
Current number Change Type (strong)
3479 -14 backward.isDefEq.respectTransparency
No changes to weak technical debt.

Current commit 2b4be851eb
Reference commit 02a839bc62

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.py 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-computability Computability theory (TMs, DFAs, languages, grammars, etc) label Nov 16, 2026
Comment thread Mathlib/Computability/DFA.lean Resolved

@ctchou ctchou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ωLanguage in cslib is also defined as a one-field structure, but I found that I rarely need to mention ofSet and toSet (except in OmegaLanguage.lean itself). Perhaps the Coe and SetLike instances mentioned below can help.

Comment thread Mathlib/Computability/DFA.lean Resolved
Comment thread Mathlib/Computability/DFA.lean Resolved
Comment thread Mathlib/Computability/EpsilonNFA.lean Resolved
Comment thread Mathlib/Computability/MyhillNerode.lean Resolved
Comment thread Mathlib/Computability/NFA.lean Resolved
Comment thread Mathlib/Computability/NFA.lean Resolved
Comment thread Mathlib/Computability/NFA.lean Resolved
Comment thread Mathlib/Computability/NFA.lean Resolved
Comment thread Mathlib/Computability/Language.lean Resolved

@ctchou ctchou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, except the following issue.

Comment thread Mathlib/Computability/Language.lean Resolved

@ctchou ctchou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Comment thread Mathlib/Computability/Language.lean Resolved
Comment thread Mathlib/Computability/Language.lean Resolved
Comment thread Mathlib/Computability/Language.lean Resolved
Comment thread Mathlib/Computability/Language.lean Resolved
Comment thread Mathlib/Computability/Language.lean Resolved
Comment thread Mathlib/Computability/Language.lean Resolved
Comment thread Mathlib/Computability/Language.lean Resolved
Comment thread Mathlib/Data/Set/Semiring.lean Resolved
Comment thread Mathlib/Computability/Language.lean Resolved
Comment thread Mathlib/Computability/NFA.lean Resolved
Comment thread Mathlib/Computability/Language.lean Resolved
Comment thread Mathlib/Computability/Language.lean Resolved
@YaelDillies YaelDillies self-assigned this Nov 22, 2026
@YaelDillies YaelDillies added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Nov 22, 2026
@Parcly-Taxel Parcly-Taxel removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Nov 23, 2026
Comment thread Mathlib/Computability/Language.lean Resolved
Comment thread Mathlib/Computability/Language.lean Resolved
@YaelDillies YaelDillies added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Nov 23, 2026
@Parcly-Taxel Parcly-Taxel removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Nov 23, 2026

@YaelDillies YaelDillies left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

maintainer delegate

Comment thread Mathlib/Computability/Language.lean Resolved
@YaelDillies YaelDillies removed their assignment Nov 25, 2026
@github-actions

Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by YaelDillies.

@mathlib-triage mathlib-triage Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Nov 25, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 27, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. t-computability Computability theory (TMs, DFAs, languages, grammars, etc) tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants