We implement atmost 1 bs as (essentially) sumBits bs <=? encode 1 with overflow-checked one-bit numbers. The comparison checks that there is no overflow, and that the contents is <=? 1 - but this is trivially true, since its bit-width is one! Currently, that's not detected, so we produce clauses that turn out to be useless. A small change improves the situtaiton.
instance Orderable Bits where
Bits xs <=? Bits ys = orderHelper true xs ys
orderHelper :: Bit -> [Bit] -> [Bit] -> Bit
orderHelper c0 xs ys = foldl aux c0 (zipWithBits (,) xs ys)
where aux c (x,y) = c && x === y || x <? y
Function aux is called with c=true and y=true. Simplification gives not x || x, but we want true.
We implement
atmost 1 bs
as (essentially)sumBits bs <=? encode 1
with overflow-checked one-bit numbers. The comparison checks that there is no overflow, and that the contents is<=? 1
- but this is trivially true, since its bit-width is one! Currently, that's not detected, so we produce clauses that turn out to be useless. A small change improves the situtaiton.We get this formula
where variable 4 and its clauses are redundant
The reason is the implementation of
<=?
forBits
Function
aux
is called withc=true
andy=true
. Simplification givesnot x || x
, but we wanttrue
.We can get this when we change to
Then indeed
NB. this
atmost 1
looks reasonable also for larger argument lengthsThis looks good for propagation: assume, e.g., that
4 = true
gets assigned. Then we unit-propagate *-4
:5=false, 11=false, 14=false
10=true
, then2=false, 3=false
15=true
, then6=7=8=9=false
.For input width n, total number of clauses is
n log n
.We are still missing some sharing here? E.g., -15 occurs in 4 clauses but these two should be enough:
(-15 | 12) & (-15 | 13)
.