Skip to content

Add angelic encoding for division/remainder#478

Open
lsrcz wants to merge 1 commit intospr/main/03f0eba1from
spr/main/14cea5ad
Open

Add angelic encoding for division/remainder#478
lsrcz wants to merge 1 commit intospr/main/03f0eba1from
spr/main/14cea5ad

Conversation

@lsrcz
Copy link
Collaborator

@lsrcz lsrcz commented Jul 29, 2025

I tried to use this to help proving division/remainder but it does not help much. But still good to keep it there.


Stack:

⚠️ Part of a stack created by spr. Do not merge manually using the UI - doing so may have unexpected results.

@lsrcz lsrcz mentioned this pull request Jul 29, 2025
@lsrcz lsrcz force-pushed the spr/main/14cea5ad branch from 924b420 to bfa4203 Compare July 29, 2025 21:42
@lsrcz lsrcz requested a review from cdleary July 29, 2025 21:46
@lsrcz lsrcz force-pushed the spr/main/14cea5ad branch from bfa4203 to 6c2847c Compare July 29, 2025 22:00
Copy link
Contributor

@cdleary cdleary left a comment

Choose a reason for hiding this comment

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

Can you add to this a good definition of what "angelic" means / where it comes from as a term of art? Looks like it's a library implementation for some known operation that we expect might make things easier for the solver, but I'm not 100% sure (or why we'd pick this particular structure) -- documentation would be good. You can make a markdown with some design thoughts in xlsynth-g8r/docs/solver.md or something if it's an involved explanation. Thanks for explaining!

@lsrcz
Copy link
Collaborator Author

lsrcz commented Jul 30, 2025

Can you add to this a good definition of what "angelic" means / where it comes from as a term of art? Looks like it's a library implementation for some known operation that we expect might make things easier for the solver, but I'm not 100% sure (or why we'd pick this particular structure) -- documentation would be good. You can make a markdown with some design thoughts in xlsynth-g8r/docs/solver.md or something if it's an involved explanation. Thanks for explaining!

Ah this is not something I invented. The paper Programming with angelic nondeterminism could provide more context. I will add an explanation in the code tomorrow.

tl;dr in verification, we can consider the inputs as demonic nondeterminism such that it will be chosen to falsify our claim. Angelic nondeterminism, in contrast, works in favor for us and is chosen to provide a value to meet our specification, here, the division.

We try to reduce the division to multiplication with angelic nondeterminism by the relation such that for $(q, r) = \mathrm{divMod}(a, b)$, $q * b + r = a$. Divisions are in general the hardest operator for an SMT solver to reason about as after bitblasting the division circuit may require an iterative process that is far more complex than other arithmetic operations, including multiplication.

But for very large bit-width, multiplications are very hard too...so this may help, but we cannot expect too much.

I tried to use this to help proving division/remainder but it does not help much. But still good to keep it there.

commit-id:14cea5ad
@lsrcz lsrcz force-pushed the spr/main/14cea5ad branch from 6c2847c to 1da04d6 Compare July 30, 2025 16:21
@lsrcz lsrcz requested a review from cdleary July 30, 2025 20:16
lsrcz added a commit that referenced this pull request Aug 4, 2025
**Stack**:
- #478
- #477⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do
not merge manually using the UI - doing so may have unexpected results.*
@cdleary
Copy link
Contributor

cdleary commented Aug 8, 2025

Thanks for explaining angelic to me on the whiteboard -- now looking at the code I'm wondering, how do we usually know/determine if the angelic encoded properties are correct? e.g. if it was off somehow would we have an indicator or we just need to review it very carefully?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants