3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-08 10:25:18 +00:00

Equalities in C# UP-Propagation (#6786)

* Query Boolean Assignment in the UP

* UP's decide ref arguments => next_split

* Fixed wrapper

* More fixes

* Equalities in C# UP-Propagation

---------

Co-authored-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Clemens Eisenhofer 2023-06-26 19:59:57 +02:00 committed by GitHub
parent 7221c84156
commit d42693d5b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 80 additions and 1 deletions

View file

@ -254,9 +254,19 @@ namespace Microsoft.Z3
/// Propagate consequence
/// </summary>
public void Propagate(IEnumerable<Expr> terms, Expr conseq)
{
Propagate(terms, new EqualityPairs(), conseq);
}
/// <summary>
/// Propagate consequence
/// </summary>
public void Propagate(IEnumerable<Expr> terms, EqualityPairs equalities, Expr conseq)
{
var nTerms = Z3Object.ArrayToNative(terms.ToArray());
Native.Z3_solver_propagate_consequence(ctx.nCtx, this.callback, (uint)nTerms.Length, nTerms, 0u, null, null, conseq.NativeObject);
var nLHS = Z3Object.ArrayToNative(equalities.LHS.ToArray());
var nRHS = Z3Object.ArrayToNative(equalities.RHS.ToArray());
Native.Z3_solver_propagate_consequence(ctx.nCtx, this.callback, (uint)nTerms.Length, nTerms, (uint)equalities.Count, nLHS, nRHS, conseq.NativeObject);
}
@ -375,4 +385,72 @@ namespace Microsoft.Z3
}
}
}
/// <summary>
/// A list of equalities used as justifications for propagation
/// </summary>
public class EqualityPairs {
readonly List<Expr> lhsList = new List<Expr>();
readonly List<Expr> rhsList = new List<Expr>();
/// <summary>
/// The left hand sides of the equalities
/// </summary>
public Expr[] LHS => lhsList.ToArray();
/// <summary>
/// The right hand sides of the equalities
/// </summary>
public Expr[] RHS => rhsList.ToArray();
/// <summary>
/// The number of equalities
/// </summary>
public int Count => lhsList.Count;
/// <summary>
/// Adds an equality to the list. The sorts of the arguments have to be the same.
/// <param name="lhs">The left hand side of the equality</param>
/// <param name="rhs">The right hand side of the equality</param>
/// </summary>
public void Add(Expr lhs, Expr rhs) {
lhsList.Add(lhs);
rhsList.Add(rhs);
}
/// <summary>
/// Checks if two equality lists are equal.
/// The function does not take symmetries, shuffling, or duplicates into account.
/// </summary>
public override bool Equals(object obj) {
if (ReferenceEquals(this, obj))
return true;
if (!(obj is EqualityPairs other))
return false;
if (lhsList.Count != other.lhsList.Count)
return false;
for (int i = 0; i < lhsList.Count; i++) {
if (!lhsList[i].Equals(other.lhsList[i]))
return false;
}
return true;
}
/// <summary>
/// Gets a hash code for the list of equalities
/// </summary>
public override int GetHashCode() {
int hash = lhsList.Count;
unchecked {
for (int i = 0; i < lhsList.Count; i++) {
hash ^= lhsList[i].GetHashCode();
hash *= 17;
hash ^= rhsList[i].GetHashCode();
hash *= 29;
}
return hash;
}
}
}
}

View file

@ -226,6 +226,7 @@ DLL_VIS JNIEXPORT void JNICALL Java_com_microsoft_z3_Native_propagateAdd(JNIEnv
}
}
DLL_VIS JNIEXPORT bool JNICALL Java_com_microsoft_z3_Native_propagateNextSplit(JNIEnv * jenv, jclass cls, jobject jobj, jlong ctx, jlong solver, jlong javainfo, jlong e, long idx, int phase) {
JavaInfo *info = (JavaInfo*)javainfo;
Z3_solver_callback cb = info->cb;