Skip to content

Commit

Permalink
Merge pull request #65 from VUISIS/fix_counting_constraint_bug
Browse files Browse the repository at this point in the history
Assert equality between all elements of intermediate comprehension te…
  • Loading branch information
balasub authored Sep 13, 2024
2 parents 93b634d + 2d99d40 commit 348a805
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Src/Core/Common/Symbols/OpLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,11 @@ internal static Term SymEvaluator_Count(SymExecuter facts, Bindable[] values)
bool wasAdded;
var res = facts.Query(values[0].Binding, out nResults);

if (nResults == 0)
{
return facts.Index.MkCnst(new Rational(nResults), out wasAdded);
}

int baseCount = 0; // always 0 for now
List<Term> realTerms = new List<Term>();
List<Term> fakeTerms = new List<Term>();
Expand Down
19 changes: 15 additions & 4 deletions Src/Core/Solver/Execution/TermEncIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,19 @@ private Z3Expr GetSymCountExpr(SymExecuter facts, Term x, IEnumerable<Z3Expr> ch
Term comprTerms = facts.GetSymbolicCountTerm(x.Args[2], index);

int numTerms = comprTerms.Args.Count() - 2;
Z3Expr[] termExprs = new Z3Expr[numTerms];
List<Z3Expr>[] termExprs = new List<Z3Expr>[numTerms];
Z3BoolExpr[] boolExprs = new Z3BoolExpr[numTerms];
Term normalized;

for (int i = 0; i < comprTerms.Args.Count() - 2; i++)
{
var e1Term = comprTerms.Args[i + 2].Args[0];
termExprs[i] = GetTerm(e1Term, out normalized, facts);
termExprs[i] = new List<Z3Expr>();
for (int j = 0; j < comprTerms.Args[i + 2].Args.Length; j++)
{
var t = comprTerms.Args[i + 2].Args[j];
termExprs[i].Add(GetTerm(t, out normalized, facts));
}

boolExprs[i] = facts.GetSideConstraints(comprTerms.Args[i + 2]); // TODO: check if we need comprTerms.Args[i + 2].Args[0] here
}

Expand All @@ -369,7 +374,13 @@ private Z3Expr GetSymCountExpr(SymExecuter facts, Term x, IEnumerable<Z3Expr> ch
List<Z3BoolExpr> currExprs = new List<Z3BoolExpr>();
for (int j = i + 1; j < numTerms; j++)
{
currExpr = facts.Solver.Context.MkEq(termExprs[i], termExprs[j]);
currExpr = facts.Solver.Context.MkEq(termExprs[i].ElementAt(0), termExprs[j].ElementAt(0));
for (int k = 1; k < termExprs[i].Count; k++)
{
var tempExpr = facts.Solver.Context.MkEq(termExprs[i].ElementAt(k), termExprs[j].ElementAt(k));
currExpr = facts.Solver.Context.MkAnd(currExpr, tempExpr);
}

currExpr = facts.Solver.Context.MkAnd(currExpr, boolExprs[i]);
currExpr = facts.Solver.Context.MkAnd(currExpr, boolExprs[j]);
currExprs.Add(currExpr);
Expand Down

0 comments on commit 348a805

Please sign in to comment.