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

String theory support #165

Draft
wants to merge 65 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
183449f
Add string sort to core
raf-nr Dec 3, 2024
25db759
Add regex sort to core
raf-nr Dec 3, 2024
3b52e78
Add string and regex sorts to context
raf-nr Dec 3, 2024
6815d4d
Implement string literal's expr and decl
raf-nr Dec 3, 2024
e98b386
Implement regex literal's expr and decl
raf-nr Dec 3, 2024
c52235a
Implement strings concatenation
raf-nr Dec 3, 2024
2bdb945
Implement strings length expr and decl
raf-nr Dec 3, 2024
779b5c2
Implement expr and decl for translation string to a regex
raf-nr Dec 3, 2024
4b8d5ad
Implement regular expressions concatenation
raf-nr Dec 3, 2024
0099dc3
Implement regular expressions union
raf-nr Dec 3, 2024
ce1a550
Implement regular expressions intersection
raf-nr Dec 3, 2024
743b758
Implement regular expressions difference and Kleene closure
raf-nr Dec 3, 2024
3a1c7c1
Implement regular expressions Kleene cross
raf-nr Dec 3, 2024
5a139cd
Implement prefixOf and suffixOf strings' operations
raf-nr Dec 3, 2024
fd259a5
Implement operation to check whether a string belongs to a regex
raf-nr Dec 4, 2024
2a500d7
Implement operations for comparing strings
raf-nr Dec 4, 2024
d771e78
Implement regular expression complement operation
raf-nr Dec 4, 2024
c8cb6bf
Fix imports
raf-nr Dec 4, 2024
844db59
Add regular expression constants
raf-nr Dec 4, 2024
4182e5a
Implement operation to make regex optional
raf-nr Dec 4, 2024
79b6f20
Implement strings' contains operation
raf-nr Dec 4, 2024
0837aa9
Describe operations on strings and regex that have not yet been imple…
raf-nr Dec 8, 2024
45bd801
Syntactic sugar for comparing string expressions
raf-nr Dec 8, 2024
f9da6a6
Syntactic sugar for strings and regex concatenation
raf-nr Dec 8, 2024
ee0ff54
Syntactic sugar for strings literals and length expr
raf-nr Dec 8, 2024
eb068cc
Syntactic sugar for suffixOf, prefixOf, contains operations
raf-nr Dec 8, 2024
1b38d12
Syntactic sugar for inRegex, toRegex operations
raf-nr Dec 8, 2024
f42d7eb
Implement replace operations for strings
raf-nr Dec 8, 2024
01a57ef
Implement regex range operation
raf-nr Dec 8, 2024
1d22225
Implement operations, that maps strings to and from integers
raf-nr Dec 8, 2024
4363af9
Implement strings' replace operations based on regex
raf-nr Dec 8, 2024
7cfad2e
Implement remaining operations on strings and transformers for strings
raf-nr Dec 9, 2024
98f82c9
Describe and implement transformers interfaces for regex
raf-nr Dec 9, 2024
8e0fafb
Add string and regex declarations in visitor
raf-nr Dec 9, 2024
889642f
Add exceptions that Bitwuzla does not support string theory
raf-nr Dec 9, 2024
c8958dc
Add string theory to KTheory class
raf-nr Dec 9, 2024
c5b9f7e
Fix str name in KTheory class
raf-nr Dec 9, 2024
2e2286d
Implement string and regex sorts cvc5 internalizer
raf-nr Dec 9, 2024
eac27d5
Add string and regex expressions internalizer for cvc5
raf-nr Dec 10, 2024
3dc16f8
Add cvc5 internalizer for substrings and indexOf expressions
raf-nr Dec 10, 2024
62b1a6a
Implement converter from cvc5 to ksmt
raf-nr Dec 10, 2024
811d531
Implement string/regex methods for cvc5 uninterpreted sort collector
raf-nr Dec 10, 2024
97bead4
Add exceptions that Yices does not support string theory
raf-nr Dec 10, 2024
b3ecd8a
Fix typo in exceptions' messages
raf-nr Dec 10, 2024
81ac05f
Fix yices solver configuration after adding string theory
raf-nr Dec 11, 2024
ca8bff6
Delete regex literal expression
raf-nr Dec 11, 2024
b54264f
Fix string theory name in KTheory class
raf-nr Dec 11, 2024
6daeecc
Change the names of classes and methods, do the code formatting
raf-nr Dec 12, 2024
ce19526
Update sort visitor implementation for theory requirement
raf-nr Dec 12, 2024
c9e2e19
Add string and regex sorts to z3 sort internalizer
raf-nr Dec 12, 2024
07bdf4b
Implement z3 internalizer some methods for strings
raf-nr Dec 12, 2024
18d690d
Add string literals printer with quotes
raf-nr Dec 12, 2024
3e7f8bd
Implement toLower, toUpper and reverse string operations
raf-nr Dec 12, 2024
a124b8b
Add string and regex default values
raf-nr Dec 14, 2024
ceb95a2
Fix bug with regex constants in cvc5
raf-nr Dec 14, 2024
9c2e89b
Add string and regex sorts serializer and deserializer
raf-nr Dec 17, 2024
1e31092
Add string and regex expressions serializer/deserializer
raf-nr Dec 17, 2024
17d40f5
Partially implement z3 string internalizer/converter
raf-nr Dec 17, 2024
8f0921e
Fully implement z3 converter
raf-nr Dec 18, 2024
d16f8d9
Implement regex power and loop operations
raf-nr Dec 18, 2024
57db57a
Fix regex power and loop expr deserializer
raf-nr Dec 18, 2024
4f3c819
Add stubs in symfpu visitors
raf-nr Dec 18, 2024
0c22147
Fix typo in z3 converter
raf-nr Dec 19, 2024
dbb8531
Describe functions for further simplification of expressions
raf-nr Dec 19, 2024
a865074
Fix cvc5 sort converter
raf-nr Dec 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import io.ksmt.expr.KFunctionAsArray
import io.ksmt.expr.KUniversalQuantifier
import io.ksmt.expr.transformer.KNonRecursiveTransformer
import io.ksmt.solver.KSolverException
import io.ksmt.solver.KSolverUnsupportedFeatureException
import org.ksmt.solver.bitwuzla.bindings.BitwuzlaNativeException
import org.ksmt.solver.bitwuzla.bindings.BitwuzlaSort
import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTerm
Expand All @@ -34,6 +35,8 @@ import io.ksmt.sort.KFpRoundingModeSort
import io.ksmt.sort.KFpSort
import io.ksmt.sort.KIntSort
import io.ksmt.sort.KRealSort
import io.ksmt.sort.KStringSort
import io.ksmt.sort.KRegexSort
import io.ksmt.sort.KSort
import io.ksmt.sort.KSortVisitor
import io.ksmt.sort.KUninterpretedSort
Expand Down Expand Up @@ -362,6 +365,12 @@ open class KBitwuzlaContext(val ctx: KContext) : AutoCloseable {
override fun visit(sort: KRealSort) {
}

override fun visit(sort: KStringSort) {
}

override fun visit(sort: KRegexSort) {
}

override fun <S : KBvSort> visit(sort: S) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,48 @@ import io.ksmt.expr.KUnaryMinusArithExpr
import io.ksmt.expr.KUninterpretedSortValue
import io.ksmt.expr.KUniversalQuantifier
import io.ksmt.expr.KXorExpr
import io.ksmt.expr.KStringConcatExpr
import io.ksmt.expr.KStringLenExpr
import io.ksmt.expr.KStringToRegexExpr
import io.ksmt.expr.KStringInRegexExpr
import io.ksmt.expr.KStringSuffixOfExpr
import io.ksmt.expr.KStringPrefixOfExpr
import io.ksmt.expr.KStringLtExpr
import io.ksmt.expr.KStringLeExpr
import io.ksmt.expr.KStringGtExpr
import io.ksmt.expr.KStringGeExpr
import io.ksmt.expr.KStringContainsExpr
import io.ksmt.expr.KStringSingletonSubExpr
import io.ksmt.expr.KStringSubExpr
import io.ksmt.expr.KStringIndexOfExpr
import io.ksmt.expr.KStringIndexOfRegexExpr
import io.ksmt.expr.KStringReplaceExpr
import io.ksmt.expr.KStringReplaceAllExpr
import io.ksmt.expr.KStringReplaceWithRegexExpr
import io.ksmt.expr.KStringReplaceAllWithRegexExpr
import io.ksmt.expr.KStringToLowerExpr
import io.ksmt.expr.KStringToUpperExpr
import io.ksmt.expr.KStringReverseExpr
import io.ksmt.expr.KStringIsDigitExpr
import io.ksmt.expr.KStringToCodeExpr
import io.ksmt.expr.KStringFromCodeExpr
import io.ksmt.expr.KStringToIntExpr
import io.ksmt.expr.KStringFromIntExpr
import io.ksmt.expr.KStringLiteralExpr
import io.ksmt.expr.KRegexConcatExpr
import io.ksmt.expr.KRegexUnionExpr
import io.ksmt.expr.KRegexIntersectionExpr
import io.ksmt.expr.KRegexStarExpr
import io.ksmt.expr.KRegexCrossExpr
import io.ksmt.expr.KRegexDifferenceExpr
import io.ksmt.expr.KRegexComplementExpr
import io.ksmt.expr.KRegexOptionExpr
import io.ksmt.expr.KRegexRangeExpr
import io.ksmt.expr.KRegexPowerExpr
import io.ksmt.expr.KRegexLoopExpr
import io.ksmt.expr.KRegexEpsilon
import io.ksmt.expr.KRegexAll
import io.ksmt.expr.KRegexAllChar
import io.ksmt.expr.rewrite.simplify.rewriteBvAddNoUnderflowExpr
import io.ksmt.expr.rewrite.simplify.rewriteBvMulNoUnderflowExpr
import io.ksmt.expr.rewrite.simplify.rewriteBvNegNoOverflowExpr
Expand Down Expand Up @@ -183,6 +225,8 @@ import io.ksmt.sort.KFpRoundingModeSort
import io.ksmt.sort.KFpSort
import io.ksmt.sort.KIntSort
import io.ksmt.sort.KRealSort
import io.ksmt.sort.KStringSort
import io.ksmt.sort.KRegexSort
import io.ksmt.sort.KSort
import io.ksmt.sort.KSortVisitor
import io.ksmt.sort.KUninterpretedSort
Expand Down Expand Up @@ -1405,6 +1449,174 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL
)
}

override fun transform(expr: KStringConcatExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringLenExpr): KExpr<KIntSort> {
throw KSolverUnsupportedFeatureException("string and int theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringToRegexExpr): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringInRegexExpr): KExpr<KBoolSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringSuffixOfExpr): KExpr<KBoolSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringPrefixOfExpr): KExpr<KBoolSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringLtExpr): KExpr<KBoolSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringLeExpr): KExpr<KBoolSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringGtExpr): KExpr<KBoolSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringGeExpr): KExpr<KBoolSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringContainsExpr): KExpr<KBoolSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringSingletonSubExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringSubExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringIndexOfExpr): KExpr<KIntSort> {
throw KSolverUnsupportedFeatureException("string and int theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringIndexOfRegexExpr): KExpr<KIntSort> {
throw KSolverUnsupportedFeatureException("string and int theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringReplaceExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringReplaceAllExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringReplaceWithRegexExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringReplaceAllWithRegexExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringToLowerExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringToUpperExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringReverseExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringIsDigitExpr): KExpr<KBoolSort> {
throw KSolverUnsupportedFeatureException("string and int theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringToCodeExpr): KExpr<KIntSort> {
throw KSolverUnsupportedFeatureException("string and int theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringFromCodeExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string and int theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringToIntExpr): KExpr<KIntSort> {
throw KSolverUnsupportedFeatureException("string and int theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringFromIntExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string and int theory is not supported in Bitwuzla")
}

override fun transform(expr: KStringLiteralExpr): KExpr<KStringSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexConcatExpr): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexUnionExpr): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexIntersectionExpr): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexStarExpr): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexCrossExpr): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexDifferenceExpr): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexComplementExpr): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexOptionExpr): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexRangeExpr): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexPowerExpr): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexLoopExpr): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexEpsilon): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexAll): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

override fun transform(expr: KRegexAllChar): KExpr<KRegexSort> {
throw KSolverUnsupportedFeatureException("string theory is not supported in Bitwuzla")
}

private inline fun <T : KQuantifier> T.internalizeQuantifier(
crossinline mkQuantifierTerm: (LongArray) -> BitwuzlaTerm
): T {
Expand Down Expand Up @@ -1554,14 +1766,20 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL
}

/**
* Bitwuzla doesn't support integers and reals.
* Bitwuzla doesn't support strings, regular expressions, integers and reals.
* */
override fun visit(sort: KIntSort) =
throw KSolverUnsupportedFeatureException("Unsupported sort $sort")

override fun visit(sort: KRealSort) =
throw KSolverUnsupportedFeatureException("Unsupported sort $sort")

override fun visit(sort: KStringSort) =
throw KSolverUnsupportedFeatureException("Unsupported sort $sort")

override fun visit(sort: KRegexSort) =
throw KSolverUnsupportedFeatureException("Unsupported sort $sort")

/**
* Replace Uninterpreted sorts with (BitVec 32).
* The sort universe size is limited by 2^32 values which should be enough.
Expand Down Expand Up @@ -1704,6 +1922,8 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL
override fun visit(sort: KBoolSort): Boolean = false
override fun visit(sort: KIntSort): Boolean = false
override fun visit(sort: KRealSort): Boolean = false
override fun visit(sort: KStringSort): Boolean = false
override fun visit(sort: KRegexSort): Boolean = false
override fun <S : KBvSort> visit(sort: S): Boolean = false
override fun <S : KFpSort> visit(sort: S): Boolean = false
override fun visit(sort: KFpRoundingModeSort): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.ksmt.solver.KTheory.LIA
import io.ksmt.solver.KTheory.LRA
import io.ksmt.solver.KTheory.NIA
import io.ksmt.solver.KTheory.NRA
import io.ksmt.solver.KTheory.S
import org.ksmt.solver.bitwuzla.bindings.Bitwuzla
import org.ksmt.solver.bitwuzla.bindings.BitwuzlaOption
import org.ksmt.solver.bitwuzla.bindings.Native
Expand Down Expand Up @@ -52,7 +53,7 @@ class KBitwuzlaSolverConfigurationImpl(private val bitwuzla: Bitwuzla) : KBitwuz
override fun optimizeForTheories(theories: Set<KTheory>?, quantifiersAllowed: Boolean) {
if (theories.isNullOrEmpty()) return

if (setOf(LIA, LRA, NIA, NRA).intersect(theories).isNotEmpty()) {
if (setOf(LIA, LRA, NIA, NRA, S).intersect(theories).isNotEmpty()) {
throw KSolverUnsupportedFeatureException("Unsupported theories $theories")
}
}
Expand Down
Loading