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

[Merged by Bors] - feat(tactic/zify): move nat propositions to int #3108

Closed
wants to merge 8 commits into from

Conversation

robertylewis
Copy link
Member


I've broken a chunk of the linarith preprocessing into a standalone tactic. IIRC @kbuzzard has talked about doing this by hand before.

Sometimes you're trying to prove a proposition about nats but it would be more convenient to treat them as ints so you can subtract them. zify will insert some casts and try to simplify things for you. It uses a new attribute @[zify] to insert the casts, and push_cast to do the simplification. It's extensible: throw @[zify] on a lemma of the right shape and it will take care of those propositions for you too.

example (a b c x y z : ℕ) (h : ¬ x*y*z < 0) : a + 3*b > c :=
begin
  zify at h ⊢,
  guard_hyp h := ¬↑x * ↑y * ↑z < (0 : ℤ),
  guard_target ↑c < (↑a : ℤ) + 3 * ↑b,
  admit
end

example (a b c : ℕ) (h : a - b < c) (hab : b ≤ a) : false :=
begin
  zify [hab] at h,
  guard_hyp h := (a : ℤ) - b < c,
  admit
end

@robertylewis
Copy link
Member Author

The name zify comes from the corresponding linear arithmetic preprocessing step in Coq. Happy to consider alternatives if people think this one is too silly. integerize? integralize? :)

@robertylewis robertylewis added the awaiting-review The author would like community review of the PR label Jun 18, 2020
@gebner
Copy link
Member

gebner commented Jun 18, 2020

How is this related to lift?

@robertylewis
Copy link
Member Author

How is this related to lift?

It goes in the opposite direction: lift will move nonnegative ints to nat.

example (a b : ℤ) (h : a ≥ 0) : a = b :=
begin 
  lift a to ℕ using h,
  /- a : ℕ, b : ℤ ⊢ ↑a = b -/
end 

lift will never change a relation symbol; zify will always change a relation symbol.

@bryangingechen bryangingechen added the t-meta Tactics, attributes or user commands label Jun 18, 2020
@jcommelin
Copy link
Member

jcommelin commented Jun 18, 2020

I really like this (type of) tactic. But maybe we also want qify, rify and cify... 😉
Is there a way to generalize this? (Maybe in a future PR?)

@robertylewis
Copy link
Member Author

I really like this (type of) tactic. But maybe we also want qify, rify and cify...
Is there a way to generalize this? (Maybe in a future PR?)

Yes, it's possible, but there are enough complications that I'd prefer to leave it for a future PR. This one blocks the linarith refactor and I'd like to get that finished.

@bryangingechen
Copy link
Collaborator

Similar to my comment on #3109, maybe this should be mentioned in the doc string / doc entry to lift and vice versa?

@robertylewis
Copy link
Member Author

Done and done, thanks Bryan!

@bryangingechen
Copy link
Collaborator

bors r+

@github-actions github-actions bot added ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) and removed awaiting-review The author would like community review of the PR labels Jun 21, 2020
bors bot pushed a commit that referenced this pull request Jun 21, 2020
Co-authored-by: Rob Lewis <rob.y.lewis@gmail.com>
@bors
Copy link

bors bot commented Jun 21, 2020

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(tactic/zify): move nat propositions to int [Merged by Bors] - feat(tactic/zify): move nat propositions to int Jun 21, 2020
@bors bors bot closed this Jun 21, 2020
@bors bors bot deleted the zify branch June 21, 2020 17:25
cipher1024 pushed a commit to cipher1024/mathlib that referenced this pull request Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) t-meta Tactics, attributes or user commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants