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: Strict Ackermannization (bv_ac_eager) tactic for QF_UFBV #5657

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

bollu
Copy link
Contributor

@bollu bollu commented Oct 9, 2024

This PR implements strict Ackermannization, which is an algorithmic technique to reduce QF_UFBV into QF_BV.

The implementation walks over the goals and the hypotheses. When it encounters a function application (f x1 x2 ... xn) where the type signature of f is BitVec k1 -> BitVec k2 -> ... -> BitVec kn -> BitVec ko, it creates a new variable fAppX : BitVec k0, and an equation fAppX = f x1 ... xn. Next, when it encounters another application of the same function (f y1 y2 ... yn), it creates a new variable fAppY : BitVec k0, and another equation fAppY = f y1 ... yn.

After the walk, we loop over all pairs of applications of the function f we have abstracted. In this case, we have fAppX and fAppY. For these, we build an extensionality equation, which says that if

hAppXAppYExt: x1 = x2 -> y1 = y2 -> ... xn = yn -> fAppX = fAppY

Intuitively, this is the only fact that the theory UF can propagate, and we thus encode it directly as a SAT formula,
by abstracting out the actual function application into a new free variable.

This implementation creates the Ackermann variables (fAppX, fAppY) first and then, in a subsequent phase, adds all the Ackermann equations (hAppXAppYExt). This anticipates the next patches, which will implement incremental Ackermannization, where we will use the counterexample from the model to selectively add Ackerman equations.

@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Oct 9, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Oct 9, 2024

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase b814be6d6a5334784b172db15fd7fea39b4e3233 --onto 3e75d8f74297bc258352f8d89f71496aacefe7ae. (2024-10-09 04:37:48)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase fc4305ab15d7137f6bda64a557dc2ca9c6fc460f --onto 72e952eadc6a171310f1d8e9d6e78acf98421494. (2024-11-21 19:15:57)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase fc4305ab15d7137f6bda64a557dc2ca9c6fc460f --onto cb600ed9b436e4290b819b0529f8454490bffeb6. (2024-12-03 15:24:30)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 2a891a3889a2cf1ac9e0499b4d11b596bfd9d410 --onto cb600ed9b436e4290b819b0529f8454490bffeb6. (2024-12-03 19:24:56)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 2a891a3889a2cf1ac9e0499b4d11b596bfd9d410 --onto c5181569f959e4a0d9586954212125adcb6e44d0. (2024-12-05 09:14:01)

Copy link
Contributor

@alexkeizer alexkeizer left a comment

Choose a reason for hiding this comment

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

I did a partial pass, so far I'm missing some documentation to explain what's what, have not attempted to grok the correctness of the code yet

src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
@bollu bollu force-pushed the strict-ackermannization branch 2 times, most recently from b59b96f to cc0e4df Compare November 22, 2024 18:39
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
@bollu bollu force-pushed the strict-ackermannization branch 2 times, most recently from ffc62dc to 1a6ae3c Compare December 4, 2024 08:49
@bollu bollu marked this pull request as ready for review December 4, 2024 14:21
@bollu bollu requested review from TwoFX and kim-em as code owners December 4, 2024 14:21
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Tactic/BVAckermannize.lean Outdated Show resolved Hide resolved
@bollu bollu changed the title feat: Strict Ackermannization tactic (bv_ac_eager) for QF_UFBV feat: Strict Ackermannization (bv_ac_eager) tactic for QF_UFBV Dec 5, 2024
@bollu
Copy link
Contributor Author

bollu commented Dec 5, 2024

changelog-library

@bollu
Copy link
Contributor Author

bollu commented Dec 5, 2024

awaiting-review

@github-actions github-actions bot added changelog-library Library awaiting-review Waiting for someone to review the PR labels Dec 5, 2024
@bollu
Copy link
Contributor Author

bollu commented Dec 5, 2024

CC @hargoniX :)

@bollu
Copy link
Contributor Author

bollu commented Dec 5, 2024

awaiting-author

@github-actions github-actions bot added awaiting-author Waiting for PR author to address issues and removed awaiting-review Waiting for someone to review the PR labels Dec 5, 2024
@bollu
Copy link
Contributor Author

bollu commented Dec 5, 2024

awaiting-review

@github-actions github-actions bot added awaiting-review Waiting for someone to review the PR and removed awaiting-author Waiting for PR author to address issues labels Dec 5, 2024
@leanprover-bot leanprover-bot added the P-medium We may work on this issue if we find the time label Dec 6, 2024
Comment on lines +45 to +46
| .bool => m!"bool"
| .bitVec w => m!"BitVec {w}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
| .bool => m!"bool"
| .bitVec w => m!"BitVec {w}"
| .bool => m!"bool"
| .bitVec w => m!"bitVec {w}"

Consistently capitalize these, please!

Comment on lines +101 to +106
/--
NOTE: is it sensible to hash an array of arguments?
We may want to use something like a trie to index these.
Consider swiching to something like `Trie`.
-/
abbrev ArgumentArray := Array Argument
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to give this an actual descriptive docstring, and move the NOTE to a non-doc comment.

Comment on lines +35 to +41
/-- Types that can be bitblasted by bv_decide. -/
inductive BVTy
/-- Booleans. -/
| bool
/-- Bitvectors of a fixed width `w`. -/
| bitVec (w : Nat)
deriving Hashable, DecidableEq, Inhabited
Copy link
Contributor

Choose a reason for hiding this comment

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

Check your whitespace, I think this is indented one level too much

Comment on lines +121 to +122
end CallInfo
structure State where
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
end CallInfo
structure State where
end CallInfo
structure State where

/-- A counter for generating fresh names. -/
gensymCounter : Nat := 0

def State.init : State where
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def State.init : State where
def State.init : State := {}

The where without anything after reads a bit weird to me, I'd prefer something more explicit, but this is pure aesthethics/taste, so feel free to ignore

Comment on lines +344 to +355
/-- This is how we build the congruence lemma for `n` arguments. -/
private example (f : X1 → X2 → O)
-- we have these already.
(x1 x1' : X1) (x2 x2' : X2)
(ackEqApp : fx1x2 = f x1 x2)
(ackEqApp' : fx1'x2' = f x1' x2')
-- to be intros'd
(h1 : x1 = x1')
(h2 : x2 = x2') :
fx1x2 = fx1'x2' :=
let appEqApp : f x1 x2 = f x1' x2' := congr (congr (Eq.refl f) h1) h2
Eq.trans (Eq.trans ackEqApp appEqApp) (Eq.symm ackEqApp')
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like they were notes for the implementation, but do we want to keep them around?


initialize Lean.registerTraceClass `Meta.Tactic.bv_ack

namespace Ack
Copy link
Contributor

Choose a reason for hiding this comment

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

To me, "ack" means acknowledge. In the context of this file, the abbrevation makes sense, but for the namespace we might want to spell out Ackermannize fully

Comment on lines +30 to +32
Intuitively, this is the only fact that they theory UF can propagate,
and we thus encode it directly as a SAT formula,
by abstracting out the actual function application into a new free variable.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Intuitively, this is the only fact that they theory UF can propagate,
and we thus encode it directly as a SAT formula,
by abstracting out the actual function application into a new free variable.
Intuitively, this is the only fact that the theory UF can propagate,
and we thus encode it directly as a SAT formula,
by abstracting out the actual function application into a new free variable.

import Std.Tactic.BVAckermannize.Syntax

/-!
This directory contains the lazy ackermannization tactic.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This directory contains the lazy ackermannization tactic.
This directory contains the eager ackermannization tactic.


/-!
This directory contains the lazy ackermannization tactic.
This uses lean's builtin bitblaster to reduce uninterpreted functions + bitvectors to SAT.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it actually integrate bv_decide into the tactic? I thought it rather reduces uninterpreted functions + bitvectors to bitvectors (which bv_decide can then solve by reduction to SAT)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Waiting for someone to review the PR changelog-library Library P-medium We may work on this issue if we find the time toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants