Skip to content

[Merged by Bors] - feat(ModelTheory): define linear and semilinear sets - #27342

Closed
staroperator wants to merge 38 commits into
leanprover-community:masterfrom
staroperator:semilinear_def
Closed

staroperator wants to merge 38 commits into
leanprover-community:masterfrom
staroperator:semilinear_def

Conversation

@staroperator

@staroperator staroperator commented Jul 22, 2025 •

Copy link
Copy Markdown
Collaborator

@github-actions

github-actions Bot commented Jul 22, 2025 •

Copy link
Copy Markdown

PR summary 6c38ba4b23

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.ModelTheory.Arithmetic.Presburger.Semilinear.Defs (new file) 887

Declarations diff

+ IsLinearSet
+ IsLinearSet.add
+ IsLinearSet.closure
+ IsLinearSet.closure_finset
+ IsLinearSet.closure_of_finite
+ IsLinearSet.image
+ IsLinearSet.isProperSemilinearSet
+ IsLinearSet.isSemilinearSet
+ IsLinearSet.of_fg
+ IsLinearSet.singleton
+ IsLinearSet.univ
+ IsLinearSet.vadd
+ IsProperLinearSet
+ IsProperLinearSet.isLinearSet
+ IsProperLinearSet.isProperSemilinearSet
+ IsProperLinearSet.singleton
+ IsProperSemilinearSet
+ IsProperSemilinearSet.biUnion
+ IsProperSemilinearSet.biUnion_finset
+ IsProperSemilinearSet.empty
+ IsProperSemilinearSet.isSemilinearSet
+ IsProperSemilinearSet.sUnion
+ IsProperSemilinearSet.union
+ IsSemilinearSet
+ IsSemilinearSet.add
+ IsSemilinearSet.biUnion
+ IsSemilinearSet.biUnion_finset
+ IsSemilinearSet.closure
+ IsSemilinearSet.closure_finset
+ IsSemilinearSet.closure_of_finite
+ IsSemilinearSet.empty
+ IsSemilinearSet.iUnion
+ IsSemilinearSet.image
+ IsSemilinearSet.isProperSemilinearSet
+ IsSemilinearSet.of_fg
+ IsSemilinearSet.of_finite
+ IsSemilinearSet.proj
+ IsSemilinearSet.proj'
+ IsSemilinearSet.sUnion
+ IsSemilinearSet.singleton
+ IsSemilinearSet.union
+ IsSemilinearSet.univ
+ IsSemilinearSet.vadd
+ isLinearSet_iff
+ isLinearSet_iff_exists_fg_eq_vadd
+ isProperLinearSet_iff
+ isSemilinearSet_image_iff

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/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).

# Linear and semilinear sets

This file defines linear and semilinear sets over any `AddCommMonoid`. A linear set is a finitely
generated `ℕ`-submodule added by a single element, and a semilinear set is a finite union of linear

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.

Is all of this easier to do over ℕ or ℤ? I usually see Presburger studied in the latter, as it is a group, and model-theoretically it is not so hard to transfer afterwards.

@staroperator staroperator Jul 22, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The ℕ(-submodule) here is for the coefficients and can not be replaced with ℤ. This PR is only for properties that hold in a general AddCommMonoid α, which includes both α = ℕ and α = ℤ.

@staroperator staroperator Jul 22, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

But the ℕ/ℤ choice will become important when we prove things like semilinear sets are closed under intersection or complement. My experience is that you have to prove the closure under intersection for ℕ^d first (which you need Dickson's lemma), so I would prefer to define Presburger arithmetic over ℕ instead of ℤ.

@staroperator staroperator Jul 22, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

And as future work, there could be another PR to transfer things from ℕ^d to ℤ^d or even any finitely generated AddCommMonoid, as Eilenberg and Schützenberger did.

@staroperator staroperator Aug 27, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

FYI: #27789 generalizes the existing results to ℤ^d or any cancellative monoid.

@leanprover-community-bot-assistant leanprover-community-bot-assistant added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jul 22, 2025
@leanprover-community-bot-assistant

Copy link
Copy Markdown
Contributor

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

@JovanGerb

Copy link
Copy Markdown
Contributor

It looks to me like the theory you're developing about ℕ-modules can be generalized to general α-modules, is there any reason to not do it like that?

@staroperator

staroperator commented Aug 19, 2025 •

Copy link
Copy Markdown
Collaborator Author

It looks to me like the theory you're developing about ℕ-modules can be generalized to general α-modules, is there any reason to not do it like that?

Yes we can define R-semilinear sets (where R is any semiring) for any R-module. There are three reasons I'm not doing so:

  1. The most interesting properties of semilinear sets ([Merged by Bors] - feat(ModelTheory): Semilinear sets are closed under intersection, difference and complement #27414 and feat(ModelTheory): semilinear sets are closed under intersection and set difference #27789) does not hold for R in general. To use Dickson's lemma one need R to be linearly and well ordered, and it seems ℕ is the only meaningful example satisfying that.
  2. The proper decomposition (Set.Semilinear.proper_semilinear) does not hold in general also. It requires R to be linearly and canonically ordered, and again ℕ is the only meaningful example (maybe ℚ≥0 or ℝ≥0 also?).
  3. That definition will make Set.Semilinear take 2 arguments R and s. Instead of writing s.Semilinear, s.Semilinear R looks weird and Set.Semilinear R s is a bit clumsy.

Given the above reasons, I think it's not worth sacrificing readability for a generalization of only some trivial properties.

@staroperator

Copy link
Copy Markdown
Collaborator Author

It looks like the use of ℕ-submodules is making too much confusion. Let me try to refactor and use AddSubmonoid.clousre instead...

@staroperator
staroperator force-pushed the semilinear_def branch 3 times, most recently from 6c0b55e to e3bf0c7 Compare August 20, 2025 23:50
mathlib-bors Bot pushed a commit that referenced this pull request Aug 27, 2025
…for linearly and canonically ordered semiring (#27341)

If the semiring `R` is linearly and canonically ordered (e.g. `R = ℕ`), `LinearIndependent` can be proved from linear combination over two disjoint sets.

This result is stronger than `linearIndependent_iff'ₛ` and is particularly useful in #27342.

Co-authored-by: staroperator <[email protected]>
Co-authored-by: Jovan Gerbscheid <[email protected]>
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Aug 27, 2025
FormulaRabbit81 pushed a commit to YaelDillies/mathlib4 that referenced this pull request Aug 30, 2025
…for linearly and canonically ordered semiring (leanprover-community#27341)

If the semiring `R` is linearly and canonically ordered (e.g. `R = ℕ`), `LinearIndependent` can be proved from linear combination over two disjoint sets.

This result is stronger than `linearIndependent_iff'ₛ` and is particularly useful in leanprover-community#27342.

Co-authored-by: staroperator <[email protected]>
Co-authored-by: Jovan Gerbscheid <[email protected]>
@YaelDillies YaelDillies added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Sep 11, 2025
@staroperator staroperator added awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. and removed awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. labels Sep 11, 2025
@staroperator

Copy link
Copy Markdown
Collaborator Author

Thanks, everyone—especially @YaelDillies—for the valuable reviews ❤️. This is my most-commented PR so far!

bors r+

mathlib-bors Bot pushed a commit that referenced this pull request Sep 17, 2025
@mathlib-bors

mathlib-bors Bot commented Sep 17, 2025

Copy link
Copy Markdown
Contributor

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors Bot changed the title feat(ModelTheory): define linear and semilinear sets [Merged by Bors] - feat(ModelTheory): define linear and semilinear sets Sep 17, 2025
@mathlib-bors mathlib-bors Bot closed this Sep 17, 2025
joelriou pushed a commit to joelriou/mathlib4 that referenced this pull request Oct 2, 2025
zhuyizheng pushed a commit to zhuyizheng/mathlib4 that referenced this pull request Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). t-logic Logic (model theory, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants