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

unexpected failures with omega #1484

Closed
robertylewis opened this issue Sep 24, 2019 · 12 comments
Closed

unexpected failures with omega #1484

robertylewis opened this issue Sep 24, 2019 · 12 comments
Labels
bug t-meta Tactics, attributes or user commands wontfix

Comments

@robertylewis
Copy link
Member

omega fails when there are things in the context that are not linear inequalities and depend on the nat/int atoms. This makes it way less convenient than one would hope, since it's pretty common to have hypotheses like these floating around, and clearing them manually is a pain.

All of the following fail:

import tactic.omega

example (a b : ℕ) (h : a < b + 1) (ha : a.prime) : a ≤ b := 
by omega

example (a b c : ℕ) (h : a < b + 1) (ha : c.prime) : a ≤ b := 
by omega

example (a b : ℕ) (h : a < b + 1) (p : fin a) : a ≤ b := 
by omega

@skbaek would it be possible to improve the hypothesis filtering? I don't think it would be hard to check whether an expression is in the language omega understands.

@robertylewis
Copy link
Member Author

Additionally, tactic.interactive.omega is missing a doc string, which makes it hard to find the options omega manual, omega int, etc.

@robertylewis
Copy link
Member Author

Another example of strange behavior: the first one succeeds, the second fails. In other cases, omega doesn't care whether variables and hypotheses are in the context or the goal.

lemma int.pred_ne_self (n : ℤ) : n - 1 ≠ n :=
by intro h; omega

lemma int.pred_ne_self' (n : ℤ) : n - 1 ≠ n :=
by omega

@mukeshtiwari
Copy link

I believe that I have also found a case where omega fails to solve the goal. I got error for the lemma: lemma three_le_four : 3 < 4 := by omega
The error message is tactic failed, there is no goals to be solved. In general, it fails when the difference is 1, i.e. 3 < 4, 4 < 5, or 5 < 6. Interestingly, it solves a more general form happily lemma three_le_four (n : ℕ): n < n + 1 := by omega .

Version: 1.39.2
Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Date: 2019-10-15T15:33:00.827Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Darwin x64 19.0.0
Lean: 3.4.2

@robertylewis
Copy link
Member Author

Indeed, that's a bug. Note that norm_num is the more appropriate tactic there -- omega is mainly for goals with variables -- but omega should still succeed.

omega is a very big tactic and I'd rather not try to fix these things myself. @skbaek do you think you'll have a chance any time soon to investigate these issues?

@robertylewis robertylewis changed the title omega is sensitive to irrelevant things in the context unexpected failures with omega Oct 20, 2019
@mergify mergify bot closed this as completed in c2e81dd Oct 28, 2019
@robertylewis
Copy link
Member Author

@kbuzzard mentioned this example on Zulip:

example {X : Type} [fintype X] (n k : ℕ) (hk : k + 1 ≤ n) : n - k = n - (k + 1) + 1 := 
begin
  omega
end

omega tries to clear X, which fails because of the instance argument. @skbaek any thoughts? I'm not sure why these have to be cleared at all; can't they just be left alone in the local context?

@robertylewis robertylewis reopened this Nov 22, 2019
@fpvandoorn
Copy link
Member

here is another failure

1 goal
n : ℕ,
G_C G_L : list ℤ,
hG : length G_C + length G_L = n + 1,
iv : ℕ,
hi : iv < length G_C
⊢ iv + (length G_C - iv - 1) + length G_L = n

@robertylewis
Copy link
Member Author

I'm not sure what the expected behavior of omega is on goals with nat division (by constants). It seems not to treat m / 3 as an atom, but also doesn't treat it correctly. There's a bug here but I don't know in which direction.

-- omega isn't happy with nat division
lemma foo1 (m : ℕ) : m / 3 ≤ m :=
by omega -- failed 

-- it's even less happy when you try to help it out.
lemma foo2 (m : ℕ) : m / 3 ≤ m :=
by { have h : m % 3 + 3 * (m / 3) = m := nat.mod_add_div m 3, 
     omega } -- invalid eval_expr, expression must be closed

-- if you generalize the `/` in `h` it succeeds
lemma foo3 (m p : ℕ) (h : m % 3 + 3 * p = m) : p ≤ m :=
by omega -- succeeds

lemma foo4 (m p : ℕ) (h : m % 3 + 3 * p = m) (h2 : p = m / 3) : m / 3 ≤ m :=
by omega -- succeeds

@semorrison semorrison added bug t-meta Tactics, attributes or user commands and removed tactic bug labels Mar 28, 2020
@robertylewis
Copy link
Member Author

Another problem: this one seems easier to fix.

example (h : 0 > 1) : false := by omega -- Cannot reify expr : false

@robertylewis
Copy link
Member Author

And from #2376 :

import tactic.omega

set_option profiler true

example (m : ℕ)
(hm5 : m % 5 < 5)
(lh : m % 5 = 3)
(hm3 : m % 5 = 3 % 5)
(hm4 : m * 3 % 5 = 4)
(h : m * 3 = 7) :
  97 :=
begin
  -- ⊢ 9 ≤ 7
  omega -- <- finishes almost instantly
end

example (m : ℕ)
(hm5 : m % 5 < 5)
(lh : m % 5 = 3)
(hm3 : m % 5 = 3 % 5)
(hm4 : m * 3 % 5 = 4)
(h : m * 3 = 7) :
  9 ≤ (nat.succ (nat.succ (nat.succ (nat.succ (nat.succ (nat.succ (nat.succ nat.zero))))))) :=
begin
  -- ⊢ 9 ≤ 7
  omega -- <- takes three seconds
end

The contradiction is coming from h. In the bad case, each time I delete a hypothesis other than h, runtime halves. The same behaviour is not observed in the good case.

@kbuzzard
Copy link
Member

Gabriel pointed out that as a preprocessing step

nat.succ_eq_add_one

omega tries succ_eq_add_one, turning the bad 7 into 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1. If add_assoc and zero_add and add_zero were also added, the 7 would become a much nicer 7.

bors bot pushed a commit that referenced this issue Apr 10, 2020
…tation (#2377)

This is helpful when debugging issues such as #2376 and #1484.
anrddh pushed a commit to anrddh/mathlib that referenced this issue May 15, 2020
…ommunity#1484) (leanprover-community#1620)

* Fix omega bugs, add docstring

* style(tactic/omega/main): trivial cleaning
anrddh pushed a commit to anrddh/mathlib that referenced this issue May 15, 2020
anrddh pushed a commit to anrddh/mathlib that referenced this issue May 16, 2020
@robertylewis
Copy link
Member Author

This is an expected failure, but with an unexpected message:

import tactic.omega
example (p : ℕ) : p = p*p := by omega
-- invalid eval_expr, expression must be closed

@semorrison
Copy link
Collaborator

(omega will need a complete reimplementation in Lean4, hence the wontfix here. Perhaps when this happens, this issue can be re-incarnated as test cases.)

cipher1024 pushed a commit to cipher1024/mathlib that referenced this issue Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug t-meta Tactics, attributes or user commands wontfix
Projects
None yet
Development

No branches or pull requests

5 participants