Skip to content

Commit 5eb06c6

Browse files
authored
Expression arguments ordering (#89)
* Parametrized and/or simplifiers * Arguments ordering option for AND,OR,EQ,DISTINCT * Version up (0.4.5)
1 parent 4cddd01 commit 5eb06c6

File tree

15 files changed

+306
-149
lines changed

15 files changed

+306
-149
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ repositories {
1414
}
1515

1616
// core
17-
implementation("com.github.UnitTestBot.ksmt:ksmt-core:0.4.4")
17+
implementation("com.github.UnitTestBot.ksmt:ksmt-core:0.4.5")
1818
// z3 solver
19-
implementation("com.github.UnitTestBot.ksmt:ksmt-z3:0.4.4")
19+
implementation("com.github.UnitTestBot.ksmt:ksmt-z3:0.4.5")
2020
```
2121

2222
## Usage

buildSrc/src/main/kotlin/org.ksmt.ksmt-base.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
}
1010

1111
group = "org.ksmt"
12-
version = "0.4.4"
12+
version = "0.4.5"
1313

1414
repositories {
1515
mavenCentral()

docs/getting-started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ repositories {
1818
```kotlin
1919
dependencies {
2020
// core
21-
implementation("com.github.UnitTestBot.ksmt:ksmt-core:0.4.4")
21+
implementation("com.github.UnitTestBot.ksmt:ksmt-core:0.4.5")
2222
}
2323
```
2424

2525
#### 3. Add one or more SMT solver dependencies:
2626
```kotlin
2727
dependencies {
2828
// z3
29-
implementation("com.github.UnitTestBot.ksmt:ksmt-z3:0.4.4")
29+
implementation("com.github.UnitTestBot.ksmt:ksmt-z3:0.4.5")
3030
// bitwuzla
31-
implementation("com.github.UnitTestBot.ksmt:ksmt-bitwuzla:0.4.4")
31+
implementation("com.github.UnitTestBot.ksmt:ksmt-bitwuzla:0.4.5")
3232
}
3333
```
3434
SMT solver specific packages are provided with solver native binaries.

examples/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ repositories {
1010

1111
dependencies {
1212
// core
13-
implementation("com.github.UnitTestBot.ksmt:ksmt-core:0.4.4")
13+
implementation("com.github.UnitTestBot.ksmt:ksmt-core:0.4.5")
1414
// z3 solver
15-
implementation("com.github.UnitTestBot.ksmt:ksmt-z3:0.4.4")
15+
implementation("com.github.UnitTestBot.ksmt:ksmt-z3:0.4.5")
1616
}
1717

1818
java {

ksmt-core/src/main/kotlin/org/ksmt/KContext.kt

Lines changed: 119 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ import org.ksmt.expr.KUnaryMinusArithExpr
291291
import org.ksmt.expr.KUniversalQuantifier
292292
import org.ksmt.expr.KXorExpr
293293
import org.ksmt.expr.rewrite.simplify.simplifyAnd
294-
import org.ksmt.expr.rewrite.simplify.simplifyAndNoFlat
295294
import org.ksmt.expr.rewrite.simplify.simplifyArithAdd
296295
import org.ksmt.expr.rewrite.simplify.simplifyArithDiv
297296
import org.ksmt.expr.rewrite.simplify.simplifyArithGe
@@ -392,7 +391,6 @@ import org.ksmt.expr.rewrite.simplify.simplifyIntToReal
392391
import org.ksmt.expr.rewrite.simplify.simplifyIte
393392
import org.ksmt.expr.rewrite.simplify.simplifyNot
394393
import org.ksmt.expr.rewrite.simplify.simplifyOr
395-
import org.ksmt.expr.rewrite.simplify.simplifyOrNoFlat
396394
import org.ksmt.expr.rewrite.simplify.simplifyRealIsInt
397395
import org.ksmt.expr.rewrite.simplify.simplifyRealToFpExpr
398396
import org.ksmt.expr.rewrite.simplify.simplifyRealToInt
@@ -666,17 +664,56 @@ open class KContext(
666664
private val andNaryCache = mkAstInterner<KAndNaryExpr>()
667665
private val andBinaryCache = mkAstInterner<KAndBinaryExpr>()
668666

669-
open fun mkAnd(args: List<KExpr<KBoolSort>>): KExpr<KBoolSort> =
670-
mkSimplified(args, KContext::simplifyAnd, ::mkAndNoSimplify)
667+
/**
668+
* Create boolean AND expression.
669+
*
670+
* @param flat flat nested AND expressions
671+
* @param order reorder arguments to ensure that (and a b) == (and b a)
672+
* */
673+
@JvmOverloads
674+
open fun mkAnd(
675+
args: List<KExpr<KBoolSort>>,
676+
flat: Boolean = true,
677+
order: Boolean = true
678+
): KExpr<KBoolSort> = mkSimplified(
679+
args,
680+
simplifier = { exprArgs -> simplifyAnd(exprArgs, flat, order) },
681+
createNoSimplify = ::mkAndNoSimplify
682+
)
671683

684+
@Deprecated(
685+
"NoFlat builders are deprecated",
686+
replaceWith = ReplaceWith("mkAnd(args, flat = false)"),
687+
level = DeprecationLevel.ERROR
688+
)
672689
open fun mkAndNoFlat(args: List<KExpr<KBoolSort>>): KExpr<KBoolSort> =
673-
mkSimplified(args, KContext::simplifyAndNoFlat, ::mkAndNoSimplify)
690+
mkAnd(args, flat = false)
674691

675-
open fun mkAnd(lhs: KExpr<KBoolSort>, rhs: KExpr<KBoolSort>): KExpr<KBoolSort> =
676-
mkSimplified(lhs, rhs, KContext::simplifyAnd, ::mkAndNoSimplify)
692+
/**
693+
* Create boolean binary AND expression.
694+
*
695+
* @param flat flat nested AND expressions
696+
* @param order reorder arguments to ensure that (and a b) == (and b a)
697+
* */
698+
@JvmOverloads
699+
open fun mkAnd(
700+
lhs: KExpr<KBoolSort>,
701+
rhs: KExpr<KBoolSort>,
702+
flat: Boolean = true,
703+
order: Boolean = true
704+
): KExpr<KBoolSort> = mkSimplified(
705+
lhs, rhs,
706+
simplifier = { a, b -> simplifyAnd(a, b, flat, order) },
707+
createNoSimplify = ::mkAndNoSimplify
708+
)
677709

710+
@Deprecated(
711+
"NoFlat builders are deprecated",
712+
replaceWith = ReplaceWith("mkAnd(lhs, rhs, flat = false)"),
713+
level = DeprecationLevel.ERROR
714+
)
678715
open fun mkAndNoFlat(lhs: KExpr<KBoolSort>, rhs: KExpr<KBoolSort>): KExpr<KBoolSort> =
679-
mkSimplified(lhs, rhs, KContext::simplifyAndNoFlat, ::mkAndNoSimplify)
716+
mkAnd(lhs, rhs, flat = false)
680717

681718
open fun mkAndNoSimplify(args: List<KExpr<KBoolSort>>): KAndExpr =
682719
if (args.size == 2) {
@@ -697,17 +734,56 @@ open class KContext(
697734
private val orNaryCache = mkAstInterner<KOrNaryExpr>()
698735
private val orBinaryCache = mkAstInterner<KOrBinaryExpr>()
699736

700-
open fun mkOr(args: List<KExpr<KBoolSort>>): KExpr<KBoolSort> =
701-
mkSimplified(args, KContext::simplifyOr, ::mkOrNoSimplify)
737+
/**
738+
* Create boolean OR expression.
739+
*
740+
* @param flat flat nested OR expressions
741+
* @param order reorder arguments to ensure that (or a b) == (or b a)
742+
* */
743+
@JvmOverloads
744+
open fun mkOr(
745+
args: List<KExpr<KBoolSort>>,
746+
flat: Boolean = true,
747+
order: Boolean = true
748+
): KExpr<KBoolSort> = mkSimplified(
749+
args,
750+
simplifier = { exprArgs -> simplifyOr(exprArgs, flat, order) },
751+
createNoSimplify = ::mkOrNoSimplify
752+
)
702753

754+
@Deprecated(
755+
"NoFlat builders are deprecated",
756+
replaceWith = ReplaceWith("mkOr(args, flat = false)"),
757+
level = DeprecationLevel.ERROR
758+
)
703759
open fun mkOrNoFlat(args: List<KExpr<KBoolSort>>): KExpr<KBoolSort> =
704-
mkSimplified(args, KContext::simplifyOrNoFlat, ::mkOrNoSimplify)
760+
mkOr(args, flat = false)
705761

706-
open fun mkOr(lhs: KExpr<KBoolSort>, rhs: KExpr<KBoolSort>): KExpr<KBoolSort> =
707-
mkSimplified(lhs, rhs, KContext::simplifyOr, ::mkOrNoSimplify)
762+
/**
763+
* Create boolean binary OR expression.
764+
*
765+
* @param flat flat nested OR expressions
766+
* @param order reorder arguments to ensure that (or a b) == (or b a)
767+
* */
768+
@JvmOverloads
769+
open fun mkOr(
770+
lhs: KExpr<KBoolSort>,
771+
rhs: KExpr<KBoolSort>,
772+
flat: Boolean = true,
773+
order: Boolean = true
774+
): KExpr<KBoolSort> = mkSimplified(
775+
lhs, rhs,
776+
simplifier = { a, b -> simplifyOr(a, b, flat, order) },
777+
createNoSimplify = ::mkOrNoSimplify
778+
)
708779

780+
@Deprecated(
781+
"NoFlat builders are deprecated",
782+
replaceWith = ReplaceWith("mkOr(lhs, rhs, flat = false)"),
783+
level = DeprecationLevel.ERROR
784+
)
709785
open fun mkOrNoFlat(lhs: KExpr<KBoolSort>, rhs: KExpr<KBoolSort>): KExpr<KBoolSort> =
710-
mkSimplified(lhs, rhs, KContext::simplifyOrNoFlat, ::mkOrNoSimplify)
786+
mkOr(lhs, rhs, flat = false)
711787

712788
open fun mkOrNoSimplify(args: List<KExpr<KBoolSort>>): KOrExpr =
713789
if (args.size == 2) {
@@ -767,8 +843,21 @@ open class KContext(
767843

768844
private val eqCache = mkAstInterner<KEqExpr<out KSort>>()
769845

770-
open fun <T : KSort> mkEq(lhs: KExpr<T>, rhs: KExpr<T>): KExpr<KBoolSort> =
771-
mkSimplified(lhs, rhs, KContext::simplifyEq, ::mkEqNoSimplify)
846+
/**
847+
* Create EQ expression.
848+
*
849+
* @param order reorder arguments to ensure that (= a b) == (= b a)
850+
* */
851+
@JvmOverloads
852+
open fun <T : KSort> mkEq(
853+
lhs: KExpr<T>,
854+
rhs: KExpr<T>,
855+
order: Boolean = true
856+
): KExpr<KBoolSort> = mkSimplified(
857+
lhs, rhs,
858+
simplifier = { l, r -> simplifyEq(l, r, order) },
859+
createNoSimplify = ::mkEqNoSimplify
860+
)
772861

773862
open fun <T : KSort> mkEqNoSimplify(lhs: KExpr<T>, rhs: KExpr<T>): KEqExpr<T> =
774863
eqCache.createIfContextActive {
@@ -778,8 +867,20 @@ open class KContext(
778867

779868
private val distinctCache = mkAstInterner<KDistinctExpr<out KSort>>()
780869

781-
open fun <T : KSort> mkDistinct(args: List<KExpr<T>>): KExpr<KBoolSort> =
782-
mkSimplified(args, KContext::simplifyDistinct, ::mkDistinctNoSimplify)
870+
/**
871+
* Create DISTINCT expression.
872+
*
873+
* @param order reorder arguments to ensure that (distinct a b) == (distinct b a)
874+
* */
875+
@JvmOverloads
876+
open fun <T : KSort> mkDistinct(
877+
args: List<KExpr<T>>,
878+
order: Boolean = true
879+
): KExpr<KBoolSort> = mkSimplified(
880+
args,
881+
simplifier = { exprArgs -> simplifyDistinct(exprArgs, order) },
882+
createNoSimplify = ::mkDistinctNoSimplify
883+
)
783884

784885
open fun <T : KSort> mkDistinctNoSimplify(args: List<KExpr<T>>): KDistinctExpr<T> =
785886
distinctCache.createIfContextActive {

0 commit comments

Comments
 (0)