Skip to content
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(ModelTheory): Set.Definable is transitive #19695

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Timeroot
Copy link
Collaborator

@Timeroot Timeroot commented Dec 2, 2024

Upstreamed from the EquationalTheories project.

The main new theorem in this PR is Set.Definable_trans, which is that definability of sets in first order logic is transitive. The other work (in Syntax/Semantics) is pretty much all to facilitate that statement and proof.


@github-actions github-actions bot added the large-import Automatically added label for PRs with a significant increase in transitive imports label Dec 2, 2024
Copy link

github-actions bot commented Dec 2, 2024

PR summary 4ff2da0ee9

Import changes exceeding 2%

% File
+6.36% Mathlib.ModelTheory.Definability
+4.05% Mathlib.ModelTheory.Semantics
+3.91% Mathlib.ModelTheory.Syntax

Import changes for modified files

Dependency changes

File Base Count Head Count Change
Mathlib.ModelTheory.Definability 692 736 +44 (+6.36%)
Mathlib.ModelTheory.Semantics 691 719 +28 (+4.05%)
Mathlib.ModelTheory.Syntax 690 717 +27 (+3.91%)
Import changes for all files
Files Import difference
3 files Mathlib.ModelTheory.Algebra.Field.CharP Mathlib.ModelTheory.Algebra.Field.IsAlgClosed Mathlib.ModelTheory.Algebra.Ring.FreeCommRing
1
Mathlib.FieldTheory.AxGrothendieck Mathlib.ModelTheory.Algebra.Ring.Definability 16
Mathlib.ModelTheory.Order 17
Mathlib.ModelTheory.Fraisse Mathlib.ModelTheory.Graph 19
4 files Mathlib.ModelTheory.Complexity Mathlib.ModelTheory.Equivalence Mathlib.ModelTheory.Satisfiability Mathlib.ModelTheory.Types
20
Mathlib.ModelTheory.Encoding 22
8 files Mathlib.ModelTheory.Bundled Mathlib.ModelTheory.DirectLimit Mathlib.ModelTheory.ElementaryMaps Mathlib.ModelTheory.ElementarySubstructures Mathlib.ModelTheory.FinitelyGenerated Mathlib.ModelTheory.PartialEquiv Mathlib.ModelTheory.Skolem Mathlib.ModelTheory.Substructures
23
Mathlib.ModelTheory.Ultraproducts 25
Mathlib.ModelTheory.Algebra.Field.Basic 26
Mathlib.ModelTheory.Syntax 27
3 files Mathlib.ModelTheory.Algebra.Ring.Basic Mathlib.ModelTheory.Quotients Mathlib.ModelTheory.Semantics
28
Mathlib.ModelTheory.Definability 44

Declarations diff

+ BoundedFormula.subst_definitions
+ Definable.trans
+ Formula.subst_definitions
+ Functions.term
+ LEquiv.onTerm
+ LEquiv.onTerm_symm
+ Term.subst_definitions
+ TermDefinable
+ TermDefinable.Definable
+ TermDefinable.TermDefinable₁
+ TermDefinable.map_expansion
+ TermDefinable.mono
+ TermDefinable.trans
+ TermDefinable₁
+ TermDefinable₁.Definable₂
+ TermDefinable₁_comp
+ TermDefinable₁_comp_TermDefinable
+ TermDefinable₁_const
+ TermDefinable₁_id
+ TermDefinable₁_iff_TermDefinable
+ empty_termDefinable_iff
+ realize_foldr_imp
+ realize_function_term
+ substFunc
+ subst_definitions_extraVals
+ subst_definitions_extraVals_X
+ subst_definitions_extraVals_spec
+ termDefinable_iff_empty_termDefinable_with_params
+ tupleGraph
+++ subst_definitions_eq

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

@Timeroot Timeroot added the blocked-by-other-PR This PR depends on another PR to Mathlib (this label is automatically managed by a bot) label Dec 2, 2024
@Timeroot Timeroot requested a review from fpvandoorn December 2, 2024 21:42
@Timeroot Timeroot added the t-logic Logic (model theory, etc) label Dec 2, 2024
@madvorak
Copy link
Collaborator

madvorak commented Dec 3, 2024

Some of the parts are not written in the Mathlib style. Do you want pointers to concrete places that need to be changed?

@Timeroot
Copy link
Collaborator Author

Timeroot commented Dec 3, 2024

Some of the parts are not written in the Mathlib style. Do you want pointers to concrete places that need to be changed?

Yes please! I tried to adhere to the style but I'm sure I missed some things.

/-- Equivalence between the Sigma type `(i : Fin m) × Fin (n i)` and `Fin (∑ i : Fin m, n i)`. -/
def finSigmaFinEquiv {m : ℕ} {n : Fin m → ℕ} : (i : Fin m) × Fin (n i) ≃ Fin (∑ i : Fin m, n i) :=
match m with
| 0 => @Equiv.equivOfIsEmpty _ _ _ (by simp; exact Fin.isEmpty')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you need @ here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the one argument I'm providing (and it seems necessary to manually provide) is an instance parameter which doesn't have name. An alternative would be to write

let _ : IsEmpty (Fin (∑ i, n i)) := by simpa using Fin.isEmpty'
Equiv.equivOfIsEmpty _ _

which works, if you think that's cleaner.

}
· intro h xs is
have ht₁ := t₁.subst_definitions_eq hFs _ (by
simp at is
Copy link
Collaborator

Choose a reason for hiding this comment

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

This proof looks weird.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Happy to change it if you tell me an equivalent/better way to write it. The actual statement of the have is quite long and ugly. I tried := t₁.subst_definitions_eq hFs _ ?_ so that I could fill in the missing proof as another goal, but the it can't infer the value of the underscore and it gives errors.

@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot removed the blocked-by-other-PR This PR depends on another PR to Mathlib (this label is automatically managed by a bot) label Jan 22, 2025
@mathlib4-dependent-issues-bot
Copy link
Collaborator

This PR/issue depends on:

@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 Jan 22, 2025
@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 Jan 28, 2025
@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 Feb 21, 2025
@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 Mar 4, 2025
@Timeroot Timeroot requested a review from awainverse March 6, 2025 15:25

## Main Results

- `L.DefinableSet A α` forms a `BooleanAlgebra`
- `Set.Definable.image_comp` shows that definability is closed under projections in finite
dimensions.
- `Set.Definable_trans` shows that `Set.Definable` is transitive, in the sense that if `S` can be
defined in `L` and all of `L`'s functions and relations can be defined in `L'`, then `S` is
also definanble in `L'`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
also definanble in `L'`.
also definable in `L'`.

* the realizations of all L.Functions have tupleGraph that's Definable on S,
* the realizations of all L.Relations are Definable on S,
then S is Definable on T, as well. -/
theorem Definable.trans {S : Set (α → M)} (h₁ : A.Definable L S)
Copy link
Contributor

Choose a reason for hiding this comment

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

The assumptions on this theorem are very close to some more-commonly used logic definitions, and it would be worth considering whether it's appropriate to do this through one of those.

  • If L extends the language L', then this is basically an extension-by-definition.
  • This is also very close to interpretability

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I poked at this a while (when I first wrote it) and this was the best set of assumptions I could come up with. I would not be all surprised though if you have something better. :)

Consider maybe, this as the "basic" statement, but then some specializations of this theorem with hypotheses that fit more naturally into certain uses...? I don't know.


/-- A `TermDefinable` function postcomposed with `TermDefinable₁` is `TermDefinable`. -/
@[fun_prop]
theorem TermDefinable₁_comp_TermDefinable {f : M → M} {g : (α → M) → M}
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also compose a higher-arity (term-)definable function with a tuple of (term-)definable functions.

rfl

/-- Maps a term's symbols along a language equivalence. Deprecated in favor of `LEquiv.onTerm`. -/
@[deprecated LEquiv.onTerm (since := "2024-12-02")]
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole PR seems quite big, and I expect it will help to split it up - if you do, it may be good to have one preliminary PR to just fix this nomenclature.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, that's a good point. I guess there are a few small lemmas/defs I have in this PR that I can also pull out separately (making explicit note of the names here also for myself):

  • realize_function_term
  • realize_foldr_imp
  • Functions.term
  • substFunc

Then, I can pull out the TermDefinable stuff into a separate PR.

That leaves something like 60% of this PR left, which is the various forms of subst_definitions_eq that all kind of need to coexist, describing how to substitute first-order formula (not just terms) into each other. That's the bulk here -- "substituting" formulas is a lot messier, since you really need to build them at the formula level but then pass the information through when you go in and recurse down the terms. If that makes sense.

Anyway, that would probably split the PR decently well.

Copy link
Contributor

@awainverse awainverse left a comment

Choose a reason for hiding this comment

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

I haven't gone through everything yet, but here are some observations.

@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 Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
large-import Automatically added label for PRs with a significant increase in transitive imports merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) t-logic Logic (model theory, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants