Direct Encoding Division
Overview
SafeDiv(SATInt(a), SATInt(b)) ~> SATInt(c)
What this rule does
- Calculates the exact minimum and maximum possible quotient values to tightly bound the output domain.
- Generates a new direct-encoded integer for the quotient with one boolean variable per possible value.
- Builds a 2D lookup table of clauses mapping
numerator_i AND denominator_jto the correspondingquotient_k. - Enforces that the output is a valid direct encoding by adding at-most-one constraints across all output bits.
Lookup table strategy
Instead of mimicking a hardware division circuit, this rule relies on a lookup table strategy leveraging the one-hot property of direct encoding:
- Calculate domain bounds - compute the smallest and largest possible quotient (
quot_min,quot_max) across all combinations of the numerator and denominator bounds. - Allocate output bits - create one new boolean variable for every value in
[quot_min, quot_max]. - Map inputs to outputs - for every possible numerator value
iand denominator valuej, calculatek = floor_div(i, j)(or0ifj == 0). Then, add a CNF clause stating that ifnumerator = ianddenominator = j, thenquotient = k. This is encoded directly asNOT n_i OR NOT d_j OR q_k. - Constrain output - ensure the output quotient does not take more than one value simultaneously by adding pairwise exclusion clauses (at-most-one constraints) across all
q_kbits.
This exploits the fact that exactly one numerator bit and exactly one denominator bit will be true, driving exactly one quotient bit to be true.