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: add support for Fin to omega #517

Closed
wants to merge 6 commits into from

Conversation

dupuisf
Copy link
Contributor

@dupuisf dupuisf commented Jan 9, 2024

With this PR, omega can handle equalities and inequalities about variables in Fin n. For i : Fin n it will add both (i : Int) + 1 ≤ n and 0 ≤ i to the facts that are processed.

Std/Tactic/Omega/OmegaM.lean Outdated Show resolved Hide resolved
@dupuisf
Copy link
Contributor Author

dupuisf commented Jan 9, 2024

awaiting-review

@github-actions github-actions bot added the awaiting-review This PR is ready for review; the author thinks it is ready to be merged. label Jan 9, 2024
kim-em
kim-em previously approved these changes Jan 10, 2024
Copy link
Collaborator

@kim-em kim-em left a comment

Choose a reason for hiding this comment

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

Thinking about this some more, I'm unconvinced we're ready to add support for Fin.

The current PR doesn't support having goals in Fin, e.g. even

example (i j : Fin n) (w : i < j) : i < j := by omega

would fail. That itself is easy to fix; I have it locally.

However if a user sees that working I think they would expect also to be able to use arithmetic operations in Fin, e.g.

example (i j : Fin n) (w : i.succ < j.succ) : i < j := by omega
example (i j : Fin n) (w : i + i < j) : i < j := by omega

However it would be a fair bit more work to support this. (e.g. addition in Fin is saturating, so involves a case split).

I'd prefer to not scope keep until we can provide a good experience with Fin!

Can you show me where you wanted to use omega that prompted this PR?

@kim-em kim-em dismissed their stale review January 10, 2024 00:48

Second thoughts!

@dupuisf
Copy link
Contributor Author

dupuisf commented Jan 10, 2024

I considered also making it work for arithmetic operations on Fin, but as you say it would be a fair bit of work, and I don't get the sense that it's used all that much. (Also, addition in Fin is not saturating, #eval (2 : Fin 3) + (1 : Fin 3) gives me 0.) The fact that it doesn't work for literals at the moment is a bigger issue I think.

I'm currently working on a project that involves vectors of type Fin k → R and goals where omega doesn't work directly show up fairly often; even a quick fix that doesn't solve everything would be great.

Regarding the "proper" way to handle this eventually, I think it would be worth thinking about a way to make it extensible to be able to support types that are not in Std, like e.g. ZMod.

@kim-em
Copy link
Collaborator

kim-em commented Jan 10, 2024

I think the right strategy might just be some preprocessing tactics that are not part of omega, e.g. unfold_fin_arith which transforms the context by replacing all facts / goals about Fin with the corresponding statements in Nat.

@kim-em
Copy link
Collaborator

kim-em commented Jan 10, 2024

I pushed some changes, but I'm not happy yet. :-)

@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Jan 10, 2024
@kim-em kim-em removed the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Jan 10, 2024
@dupuisf
Copy link
Contributor Author

dupuisf commented Jan 12, 2024

Fair enough. I've been experimenting some more with the aesop approach for preprocessing, and that seems to work well enough. In any case, feel free to either adopt this PR or close it entirely.

@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Jan 12, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. and removed merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. labels Feb 8, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot removed the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Feb 21, 2024
@kim-em
Copy link
Collaborator

kim-em commented Feb 21, 2024

@dupuisf, I've moved this to Lean: leanprover/lean4#3427

It seems to work quite well now.

@kim-em kim-em closed this Feb 21, 2024
@dupuisf
Copy link
Contributor Author

dupuisf commented Mar 5, 2024

@dupuisf, I've moved this to Lean: leanprover/lean4#3427

It seems to work quite well now.

I just noticed this with the announcement today, somehow I had missed this message -- very nice! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review This PR is ready for review; the author thinks it is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants