Skip to content

Commit f0fe51e

Browse files
committed
correctly typed terms with constant propagation
1 parent e901c96 commit f0fe51e

5 files changed

Lines changed: 55 additions & 7 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(set-logic HORN)
2+
3+
(declare-fun I1 ((_ BitVec 32)) Bool)
4+
(declare-fun I2 ((_ BitVec 32)) Bool)
5+
(declare-fun I3 ((_ BitVec 32)) Bool)
6+
(declare-fun I4 ((_ BitVec 32)) Bool)
7+
8+
(assert (I1 (_ bv10 32)))
9+
10+
(assert (forall ((x (_ BitVec 32))) (=> (I1 x) (I2 x))))
11+
(assert (forall ((x (_ BitVec 32))) (=> (I1 x) (I3 x))))
12+
(assert (forall ((x (_ BitVec 32))) (=> (I2 x) (I4 x))))
13+
(assert (forall ((x (_ BitVec 32))) (=> (I3 x) (I4 x))))
14+
15+
(assert (forall ((x (_ BitVec 32))) (=> (I4 x) (= x (_ bv10 32)))))
16+
17+
(check-sat)
18+

regression-tests/horn-bv/runtests

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ for name in $TESTS; do
2525
$LAZABS -cex -abstract:off "$@" $name 2>&1 | grep -v 'at '
2626
done
2727

28+
TESTS="constants.smt2"
29+
30+
for name in $TESTS; do
31+
echo
32+
echo $name
33+
$LAZABS -scex -ssol -abstract:off "$@" $name 2>&1 | grep -v 'at '
34+
done
35+
2836
TESTS="int2bv.smt2"
2937

3038
for name in $TESTS; do

src/main/scala/lazabs/horn/preprocessor/ConstantPropagator.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ object SimplePropagators {
143143
val subst =
144144
(for (((arg, sort), ind) <-
145145
(constantArgs.iterator zip sorts.iterator).zipWithIndex)
146-
yield (arg getOrElse v(ind, sort))).toList
146+
yield {
147+
arg match {
148+
case Some(c) => SymbolSplitter.toCtorTerm(c, sort)
149+
case None => v(ind, sort)
150+
}
151+
}).toList
147152
val simpSol = SimplifyingVariableSubstVisitor(sol, (subst, 0))
148153

149154
and(for ((Some(t), ind) <- constantArgs.iterator.zipWithIndex)

src/main/scala/lazabs/horn/preprocessor/SymbolSplitter.scala

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import ap.types.MonoSortedPredicate
4040
import ap.types.Sort
4141
import IExpression._
4242
import ap.util.Seqs
43+
import ap.theories.ModuloArithmetic
4344

4445
import scala.collection.mutable.{HashSet => MHashSet, HashMap => MHashMap,
4546
LinkedHashSet, ArrayBuffer}
@@ -231,16 +232,30 @@ object SymbolSplitter extends HornPreprocessor {
231232

232233
//////////////////////////////////////////////////////////////////////////////
233234

235+
import ModuloArithmetic.{mod_cast, evalModCast, ModSort}
236+
234237
protected[preprocessor] def solutionEquation(argNum : Int,
235238
argSort : Sort,
236239
t : ITerm) : IFormula =
237-
t match {
240+
(t, argSort) match {
238241
// don't introduce a simple equation in case of
239242
// False, this would be too strong
240-
case Sort.MultipleValueBool.False =>
243+
case (Sort.MultipleValueBool.False, Sort.MultipleValueBool) =>
241244
(v(argNum, argSort) =/= Sort.MultipleValueBool.True)
242-
case arg =>
243-
(v(argNum, argSort) === arg)
245+
case (Const(value), ModSort(lower, upper)) =>
246+
(v(argNum, argSort) === mod_cast(lower, upper, value))
247+
case (t, argSort) =>
248+
(v(argNum, argSort) === t)
249+
}
250+
251+
protected[preprocessor] def toCtorTerm(arg : ITerm, sort : Sort) : ITerm =
252+
(arg, sort) match {
253+
case (IIntLit(value), ModSort(lower, upper)) => {
254+
assert(evalModCast(lower, upper, value) == value)
255+
mod_cast(lower, upper, value)
256+
}
257+
case (t, _) =>
258+
t
244259
}
245260

246261
//////////////////////////////////////////////////////////////////////////////
@@ -274,6 +289,8 @@ object SymbolSplitter extends HornPreprocessor {
274289
object ConcreteTerm {
275290
def unapply(t : ITerm) : Option[ITerm] = t match {
276291
case t : IIntLit => Some(t)
292+
case IFunApp(`mod_cast`, Seq(Const(l), Const(u), Const(v)))
293+
=> Some(IIntLit(evalModCast(l, u, v)))
277294
case IConstant(c) => constValue get c
278295
case True | False => Some(t)
279296
case _ => None

src/main/scala/lazabs/horn/preprocessor/UniqueConstructorExpander.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2020-2025 Philipp Ruemmer. All rights reserved.
2+
* Copyright (c) 2020-2026 Philipp Ruemmer. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions are met:
@@ -233,7 +233,7 @@ class UniqueConstructorExpander extends ArgumentExpander {
233233
adtSort = sort.asInstanceOf[ADT.ADTProxySort];
234234
adt = adtSort.adtTheory;
235235
if adt.ctorIdsPerSort(adtSort.sortNum).size > 1) yield {
236-
adt.hasCtor(v(argInd), ctorInd)
236+
adt.hasCtor(v(argInd, sort), ctorInd)
237237
}
238238
f &&& and(ctorConstraints)
239239
}

0 commit comments

Comments
 (0)