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

zify! tactic #7450

Open
BoltonBailey opened this issue Oct 1, 2023 · 1 comment
Open

zify! tactic #7450

BoltonBailey opened this issue Oct 1, 2023 · 1 comment
Labels
enhancement New feature or request t-meta Tactics, attributes or user commands

Comments

@BoltonBailey
Copy link
Collaborator

The zify tactic is considered the default way to deal with goals that use tsub natural subtraction. One of the more tedious aspects of using this tactic is manually inputting all of the inequalities that allow zify to determine if a - b cast to ints should be (a : Z) - (b : Z) or zero. Very often the answer is that it is always the former.

I would like a zify! tactic that automates some of this away. I could see two ways:

  1. Assume all the subtractions are not truncated for the purposes of the cast, and then spinning these off as additional goals.
  2. Recursively splitting into cases for each subgoal, and then letting the user deal with all the subcases (perhaps applying linarith or ring to each subcase to catch the trivial ones).
@BoltonBailey BoltonBailey added the enhancement New feature or request label Oct 1, 2023
@timotree3
Copy link
Collaborator

Here is an example proof that could be produced by option 2 above. In principle this approach generates 2^n cases (where n = # tsubs), but in this example, using the heuristic of starting with the nested substraction m - n resulted in only 6 cases.

import Mathlib

example (m n k : ℕ) : (m - n) - k = m - (n + k) := by
  -- zify!
  -- . linarith
  -- . linarith
  -- . linarith
  -- . ring
  cases Nat.lt_or_ge m n with
  | inl h1 =>
    simp only [zero_le, tsub_eq_zero_of_le, h1.le]
    cases Nat.lt_or_ge m (n + k) with
    | inl h2 =>
      simp only [zero_le, tsub_eq_zero_of_le, h2.le]
      -- case solved by simp
    | inr h2 =>
      zify [h2]
      -- all tsubs gone. hand over to user
      linarith
  | inr h1 =>
    cases Nat.lt_or_ge m (n + k) with
    | inl h2 =>
      simp only [zero_le, tsub_eq_zero_of_le, h2.le]
      cases Nat.lt_or_ge (m - n) k with
      | inl h3 =>
        simp only [zero_le, tsub_eq_zero_of_le, h3.le]
        -- case solved by simp
      | inr h3 =>
        zify [h1, h3]
        zify [h1] at h3 -- note: removing tsubs in hypotheses as well
        -- all tsubs gone
        linarith
    | inr h2 =>
      cases Nat.lt_or_ge (m - n) k with
      | inl h3 =>
        simp only [zero_le, tsub_eq_zero_of_le, h3.le]
        zify [h1, h2]
        zify [h1] at h3
        -- all tsubs gone
        linarith
      | inr h3 =>
        zify [h1, h2, h3]
        zify [h1] at h3
        -- all tsubs gone
        ring

@timotree3 timotree3 added the t-meta Tactics, attributes or user commands label Oct 3, 2023
@BoltonBailey BoltonBailey changed the title zify! tactic zify! tactic Oct 3, 2023
@BoltonBailey BoltonBailey mentioned this issue Feb 8, 2024
51 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request t-meta Tactics, attributes or user commands
Projects
None yet
Development

No branches or pull requests

2 participants