Skip to content

Commit

Permalink
Fixed horn problems
Browse files Browse the repository at this point in the history
  • Loading branch information
leventeBajczi committed Nov 4, 2024
1 parent affcbbe commit 8b388ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import hu.bme.mit.theta.core.type.booltype.BoolExprs.*
import hu.bme.mit.theta.core.type.booltype.BoolType
import hu.bme.mit.theta.core.type.functype.FuncExprs
import hu.bme.mit.theta.core.type.functype.FuncType
import hu.bme.mit.theta.core.type.inttype.IntExprs.Int
import hu.bme.mit.theta.core.utils.ExprUtils
import java.util.*

Expand Down Expand Up @@ -55,8 +56,7 @@ open class Relation(val name: String, vararg paramTypes: Type) {

val arity: Int = paramTypes.size
val rules: MutableList<Rule> = LinkedList()
val constDecl =
if (arity == 0) Const(name, Bool()) else Const(name, funcType(paramTypes.toList(), Bool()))
val constDecl = Const(name, funcType(paramTypes.toList(), Bool()))

open operator fun invoke(params: List<Expr<*>>) = RelationApp(this, params)

Expand Down Expand Up @@ -114,11 +114,17 @@ data class RelationApp(

data class Rule(val head: Expr<BoolType>, val constraints: List<Expr<BoolType>>) {

fun toExpr() =
Forall(
ExprUtils.getParams(head) + ExprUtils.getParams(constraints),
Imply(And(constraints), head),
)
fun toExpr(): Expr<BoolType> {
val params = ExprUtils.getParams(head) + ExprUtils.getParams(constraints)
val nontrivialConstraints = constraints.filter { it != True() }
return if (params.isNotEmpty()) {
Forall(params, Imply(And(nontrivialConstraints), head))
} else if (nontrivialConstraints.isNotEmpty()) {
Forall(listOf(Param("__dummy__", Int())), Imply(And(nontrivialConstraints), head))
} else {
head
}
}
}

operator fun Expr<BoolType>.plus(other: Expr<BoolType>) = listOf(this, other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ class XcfaCliVerifyTest {
@JvmStatic
fun cFilesShortInt(): Stream<Arguments> {
return Stream.of(
Arguments.of("/c/litmustest/singlethread/00assignment.c", null),
Arguments.of("/c/litmustest/singlethread/01cast.c", null),
Arguments.of("/c/litmustest/singlethread/02types.c", null),
Arguments.of("/c/litmustest/singlethread/15addition.c", null),
Arguments.of("/c/litmustest/singlethread/20testinline.c", null),
Arguments.of("/c/litmustest/singlethread/21namecollision.c", null),
Arguments.of("/c/litmustest/singlethread/22nondet.c", null),
Expand Down

0 comments on commit 8b388ff

Please sign in to comment.