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

Resolve track vars in unsat cores #105

Merged
merged 4 commits into from
Apr 27, 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
Next Next commit
Update examples
  • Loading branch information
Saloed committed Apr 27, 2023
commit 3376ec090e3689add470db6112cf28cfeb4dfd2c
8 changes: 4 additions & 4 deletions docs/custom-expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ class CustomSolver<C : KSolverConfiguration>(
solver.assert(transformer.apply(expr))

// expr can contain custom expressions -> rewrite
override fun assertAndTrack(expr: KExpr<KBoolSort>, trackVar: KConstDecl<KBoolSort>) =
solver.assertAndTrack(transformer.apply(expr), trackVar)
override fun assertAndTrack(expr: KExpr<KBoolSort>) =
solver.assertAndTrack(transformer.apply(expr))

// assumptions can contain custom expressions -> rewrite
override fun checkWithAssumptions(assumptions: List<KExpr<KBoolSort>>, timeout: Duration): KSolverStatus =
Expand Down Expand Up @@ -262,10 +262,10 @@ class CustomModel(
override val uninterpretedSorts: Set<KUninterpretedSort>
get() = model.uninterpretedSorts

override fun <T : KSort> interpretation(decl: KDecl<T>): KModel.KFuncInterp<T>? =
override fun <T : KSort> interpretation(decl: KDecl<T>): KFuncInterp<T>? =
model.interpretation(decl)

override fun uninterpretedSortUniverse(sort: KUninterpretedSort): Set<KExpr<KUninterpretedSort>>? =
override fun uninterpretedSortUniverse(sort: KUninterpretedSort): Set<KUninterpretedSortValue>? =
model.uninterpretedSortUniverse(sort)

override fun detach(): KModel = CustomModel(model.detach(), transformer)
Expand Down
17 changes: 7 additions & 10 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ with(ctx) {

/**
* Assert and track e2
* Track variable e2Track will appear in unsat core
* e2 will appear in unsat core
* */
val e2Track = solver.assertAndTrack(e2)
solver.assertAndTrack(e2)

/**
* Check satisfiability with e3 assumed.
Expand All @@ -328,18 +328,15 @@ with(ctx) {

// retrieve unsat core
val core = solver.unsatCore()
println("unsat core = $core") // [track!fresh!0, (not c)]
println("unsat core = $core") // [(not (and b a)), (not c)]

// simply asserted expression cannot be in unsat core
println("e1 in core = ${e1 in core}") // false
/**
* An expression added with assertAndTrack cannot be in unsat core.
* The corresponding track variable is used instead of the expression itself.
*/
println("e2 in core = ${e2 in core}") // false
println("e2Track in core = ${e2Track in core}") // true

//the assumed expression appears in unsat core as is
// an expression added with assertAndTrack appears in unsat core as is.
println("e2 in core = ${e2 in core}") // true

// the assumed expression appears in unsat core as is
println("e3 in core = ${e3 in core}") // true
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/src/main/kotlin/CustomExpressions.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import org.ksmt.KContext
import org.ksmt.cache.hash
import org.ksmt.cache.structurallyEqual
import org.ksmt.decl.KConstDecl
import org.ksmt.decl.KDecl
import org.ksmt.expr.KExpr
import org.ksmt.expr.KUninterpretedSortValue
Expand All @@ -13,6 +12,7 @@ import org.ksmt.solver.KModel
import org.ksmt.solver.KSolver
import org.ksmt.solver.KSolverConfiguration
import org.ksmt.solver.KSolverStatus
import org.ksmt.solver.model.KFuncInterp
import org.ksmt.sort.KBoolSort
import org.ksmt.sort.KBvSort
import org.ksmt.sort.KSort
Expand Down Expand Up @@ -174,8 +174,8 @@ class CustomSolver<C : KSolverConfiguration>(
solver.assert(transformer.apply(expr))

// expr can contain custom expressions -> rewrite
override fun assertAndTrack(expr: KExpr<KBoolSort>, trackVar: KConstDecl<KBoolSort>) =
solver.assertAndTrack(transformer.apply(expr), trackVar)
override fun assertAndTrack(expr: KExpr<KBoolSort>) =
solver.assertAndTrack(transformer.apply(expr))

// assumptions can contain custom expressions -> rewrite
override fun checkWithAssumptions(assumptions: List<KExpr<KBoolSort>>, timeout: Duration): KSolverStatus =
Expand Down Expand Up @@ -219,7 +219,7 @@ class CustomModel(
override val uninterpretedSorts: Set<KUninterpretedSort>
get() = model.uninterpretedSorts

override fun <T : KSort> interpretation(decl: KDecl<T>): KModel.KFuncInterp<T>? =
override fun <T : KSort> interpretation(decl: KDecl<T>): KFuncInterp<T>? =
model.interpretation(decl)

override fun uninterpretedSortUniverse(sort: KUninterpretedSort): Set<KUninterpretedSortValue>? =
Expand Down
17 changes: 7 additions & 10 deletions examples/src/main/kotlin/GettingStartedExample.kt
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ private fun unsatCoreGenerationExample(ctx: KContext) =

/**
* Assert and track e2
* Track variable e2Track will appear in unsat core
* e2 will appear in unsat core
* */
val e2Track = solver.assertAndTrack(e2)
solver.assertAndTrack(e2)

/**
* Check satisfiability with e3 assumed.
Expand All @@ -244,18 +244,15 @@ private fun unsatCoreGenerationExample(ctx: KContext) =

// retrieve unsat core
val core = solver.unsatCore()
println("unsat core = $core") // [track!fresh!0, (not c)]
println("unsat core = $core") // [(not (and b a)), (not c)]

// simply asserted expression cannot be in unsat core
println("e1 in core = ${e1 in core}") // false
/**
* An expression added with assertAndTrack cannot be in unsat core.
* The corresponding track variable is used instead of the expression itself.
*/
println("e2 in core = ${e2 in core}") // false
println("e2Track in core = ${e2Track in core}") // true

//the assumed expression appears in unsat core as is
// an expression added with assertAndTrack appears in unsat core as is.
println("e2 in core = ${e2 in core}") // true

// the assumed expression appears in unsat core as is
println("e3 in core = ${e3 in core}") // true
}
}