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

kernel hangs on ac_nf expression #5699

Closed
3 tasks done
tobiasgrosser opened this issue Oct 14, 2024 · 4 comments · Fixed by #5708
Closed
3 tasks done

kernel hangs on ac_nf expression #5699

tobiasgrosser opened this issue Oct 14, 2024 · 4 comments · Fixed by #5708
Labels
bug Something isn't working

Comments

@tobiasgrosser
Copy link
Contributor

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

The following test case hangs in the kernel

axiom foo {p : Prop} {x : BitVec 32} (h : (!x == x + 0#32) = true) : p

theorem add_eq_sub_not_sub_one (x : BitVec 32) (h : (!x == x + (1#32 + 4294967295#32)) = true) : False := by
  simp only [BitVec.reduceAdd] at h
  exact foo h -- this works

theorem add_eq_sub_not_sub_one' (x : BitVec 32) (h : (!x == x + 1#32 + 4294967295#32) = true) : False := by
  ac_nf0 at h
  simp only [BitVec.reduceAdd] at h
  exact foo h -- this hangs here

Context

This issue arose when testing bv_decide with ac_nf enabled.

Steps to Reproduce

  1. Copy into Lean
  2. Wait for it to run
  3. Observe yellow line next to exact foo h not disappearing

Expected behavior: Proof should be confirmed by kernel

Actual behavior: Kernel is hanging

Versions

"4.12.0, commit 225e089"

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

@tobiasgrosser tobiasgrosser added the bug Something isn't working label Oct 14, 2024
@nomeata
Copy link
Collaborator

nomeata commented Oct 14, 2024

Didn't look closely yet. This might have a similar cause as #5384

@nomeata
Copy link
Collaborator

nomeata commented Oct 14, 2024

Fun fact: Enabling set_option debug.skipKernelTC true makes it go through (as expected), but then trying to paste the proof term into a theorem, to play around with it, makes the elaborator hit the recursion depth:

theorem add_eq_sub_not_sub_one'' : ∀ (x : BitVec 32), (!x == x + 1#32 + 4294967295#32) = true → False :=
fun x h =>
  foo
    (Eq.mp
      (congrArg (fun x_1 => (!x == x_1) = true)
        (Lean.Data.AC.Context.eq_of_norm
          { op := HAdd.hAdd, assoc := BitVec.instAssociativeHAdd, comm := some { down := BitVec.instCommutativeHAdd },
            idem := none,
            vars :=
              [{ value := x, neutral := none }, { value := 1#32, neutral := none },
                { value := 4294967295#32, neutral := none }],
            arbitrary := x }
          (((Lean.Data.AC.Expr.var 0).op (Lean.Data.AC.Expr.var 1)).op (Lean.Data.AC.Expr.var 2))
          ((Lean.Data.AC.Expr.var 0).op ((Lean.Data.AC.Expr.var 1).op (Lean.Data.AC.Expr.var 2))) (Eq.refl true)))
      h)

I'm fairly certain that it’s the same issue as #5384; like there, a strategically placed id can do wonders:


theorem add_eq_sub_not_sub_one'' : ∀ (x : BitVec 32), (!x == x + 1#32 + 4294967295#32) = true → False :=
fun x h =>
  foo
    (Eq.mp
      (congrArg (fun x_1 => (!x == x_1) = true)
        (@id (∀ (x y z : BitVec 32), x + y + z = x + (y + z))
        (fun (x y z : BitVec 32) =>
        (Lean.Data.AC.Context.eq_of_norm
          { op := HAdd.hAdd, assoc := BitVec.instAssociativeHAdd, comm := some { down := BitVec.instCommutativeHAdd },
            idem := none,
            vars :=
              [{ value := x, neutral := none }, { value := y, neutral := none },
                { value := z, neutral := none }],
            arbitrary := x }
          (((Lean.Data.AC.Expr.var 0).op (Lean.Data.AC.Expr.var 1)).op (Lean.Data.AC.Expr.var 2))
          ((Lean.Data.AC.Expr.var 0).op ((Lean.Data.AC.Expr.var 1).op (Lean.Data.AC.Expr.var 2))) (Eq.refl true))) x 1#32 4294967295#32))
      h)

nomeata added a commit that referenced this issue Oct 14, 2024
this fixes #5699.

A similar fix should help with #5384.

TODO: Abstract this out a bit, document it.

Maybe this should even use a form of `opaque id`, just to be sure.
(`opaque betaBlocker`?…)
@nomeata
Copy link
Collaborator

nomeata commented Oct 14, 2024

Indeed, and the fix seems to work (#5708).

@tobiasgrosser
Copy link
Contributor Author

tobiasgrosser commented Oct 14, 2024

Wow, what a fast turnaround. Thank you! 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants