Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yices #46

Merged
merged 13 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Various fixes
  • Loading branch information
Bupaheh committed Feb 13, 2023
commit 2e9156daaaab813f8e68624c6a9c205bb8241436
Binary file modified ksmt-yices/dist/com.sri.yices.jar
Binary file not shown.
Binary file modified ksmt-yices/dist/yices-native-win32-x86-64-0.0.zip
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ open class KYicesContext : AutoCloseable {
val one = mkTerm { Terms.intConst(1L) }
val minusOne = mkTerm { Terms.intConst(-1L) }

private inline fun mkTerm(mk: () -> YicesSort): YicesSort {
private inline fun mkTerm(mk: () -> YicesTerm): YicesTerm {
val term = mk()

if (yicesTerms.add(term))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ import org.ksmt.expr.KTrue
import org.ksmt.expr.KUnaryMinusArithExpr
import org.ksmt.expr.KUniversalQuantifier
import org.ksmt.expr.KXorExpr
import org.ksmt.expr.rewrite.KExprSubstitutor
import org.ksmt.solver.util.KExprInternalizerBase
import org.ksmt.sort.KArithSort
import org.ksmt.sort.KArraySort
Expand Down Expand Up @@ -658,7 +659,7 @@ open class KYicesExprInternalizer(
val transformedExpr = yicesCtx.substituteDecls(expr) { term ->
with(term) {
val newIndex = indexVarDecl.sort.mkFreshConstDecl(indexVarDecl.name)
val transformer = KDeclSubstitutor(ctx).apply {
val transformer = KExprSubstitutor(ctx).apply {
substitute(indexVarDecl, newIndex)
}
ctx.mkArrayLambda(newIndex, transformer.apply(body))
Expand Down Expand Up @@ -793,7 +794,7 @@ open class KYicesExprInternalizer(
val transformedExpr = yicesCtx.substituteDecls(expr) { term: T ->
with(term) {
val newBounds = bounds.map { it.sort.mkFreshConstDecl(it.name) }
val transformer = KDeclSubstitutor(ctx).apply {
val transformer = KExprSubstitutor(ctx).apply {
bounds.zip(newBounds).forEach { (bound, newBound) ->
substitute(bound.uncheckedCast(), newBound)
}
Expand Down
18 changes: 16 additions & 2 deletions ksmt-yices/src/main/kotlin/org/ksmt/solver/yices/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@ import org.ksmt.KContext
import org.ksmt.expr.KExpr
import org.ksmt.sort.KBvSort
import org.ksmt.sort.KRealSort
import java.math.BigInteger

typealias YicesTerm = Int
typealias YicesSort = Int

private fun BooleanArray.extractByte(start: Int): Byte {
val end = Integer.min(start + Byte.SIZE_BITS, size)

return copyOfRange(start, end).mapIndexed { index, b ->
val bit = if (b) 1 else 0

bit * (1 shl index)
}.sum().toByte()
}

fun KContext.mkBv(bits: BooleanArray, sizeBits: UInt): KExpr<KBvSort> {
val value = bits.map { if (it) 1 else 0 }.reversed().joinToString(separator = "")
val length = (bits.size + Byte.SIZE_BITS - 1) / Byte.SIZE_BITS
val byteArray = ByteArray(length) {
bits.extractByte((length - it - 1) * Byte.SIZE_BITS)
}

return mkBv(value, sizeBits)
return mkBv(BigInteger(1, byteArray), sizeBits)
}

fun KContext.mkRealNum(value: BigRational): KExpr<KRealSort> =
Expand Down