本文整理汇总了C#中Microsoft.Z3.Context.MkDistinct方法的典型用法代码示例。如果您正苦于以下问题:C# Context.MkDistinct方法的具体用法?C# Context.MkDistinct怎么用?C# Context.MkDistinct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Z3.Context
的用法示例。
在下文中一共展示了Context.MkDistinct方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run()
{
using (Context ctx = new Context())
{
BoolExpr p = ctx.MkBoolConst("p");
BoolExpr q = ctx.MkBoolConst("q");
Console.WriteLine(ctx.MkAnd(p, q));
Console.WriteLine(ctx.MkOr(p, q));
Console.WriteLine(ctx.MkAnd(p, ctx.MkTrue()));
Console.WriteLine(ctx.MkOr(p, ctx.MkFalse()));
Console.WriteLine(ctx.MkNot(p));
Console.WriteLine(ctx.MkImplies(p, q));
Console.WriteLine(ctx.MkEq(p, q).Simplify());
Console.WriteLine(ctx.MkEq(p, q));
BoolExpr r = ctx.MkBoolConst("r");
Console.WriteLine(ctx.MkNot(ctx.MkEq(p, ctx.MkNot(ctx.MkEq(q, r)))));
Console.WriteLine(ctx.MkNot(ctx.MkEq(ctx.MkNot(ctx.MkEq(p, q)), r)));
Console.WriteLine(ctx.MkEq(p, ctx.MkTrue()));
Console.WriteLine(ctx.MkEq(p, ctx.MkFalse()));
Console.WriteLine(ctx.MkEq(p, ctx.MkTrue()).Simplify());
Console.WriteLine(ctx.MkEq(p, ctx.MkFalse()).Simplify());
Console.WriteLine(ctx.MkEq(p, p).Simplify());
Console.WriteLine(ctx.MkEq(p, q).Simplify());
Console.WriteLine(ctx.MkAnd(p, q, r));
Console.WriteLine(ctx.MkOr(p, q, r));
IntExpr x = ctx.MkIntConst("x");
Console.WriteLine(x is BoolExpr);
Console.WriteLine(p is BoolExpr);
Console.WriteLine(ctx.MkAnd(p, q) is BoolExpr);
Console.WriteLine(p is BoolExpr);
Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)) is BoolExpr);
Console.WriteLine(p.IsAnd);
Console.WriteLine(ctx.MkOr(p, q).IsOr);
Console.WriteLine(ctx.MkAnd(p, q).IsAnd);
Console.WriteLine(x.IsNot);
Console.WriteLine(p.IsNot);
Console.WriteLine(ctx.MkNot(p));
Console.WriteLine(ctx.MkNot(p).IsDistinct);
Console.WriteLine(ctx.MkEq(p, q).IsDistinct);
Console.WriteLine(ctx.MkDistinct(p, q).IsDistinct);
Console.WriteLine(ctx.MkDistinct(x, ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkAdd(x, ctx.MkInt(2))).IsDistinct);
Console.WriteLine();
Console.WriteLine(ctx.MkBool(true));
Console.WriteLine(ctx.MkBool(false));
Console.WriteLine(ctx.BoolSort);
Context ctx1 = new Context();
Console.WriteLine(ctx1.MkBool(true));
Console.WriteLine(ctx1.BoolSort);
Console.WriteLine(ctx1.MkBool(true).Sort == ctx1.BoolSort);
Console.WriteLine(ctx1.MkBool(true).Sort == ctx.BoolSort);
Console.WriteLine(ctx1.MkBool(true).Sort != ctx.BoolSort);
}
}
示例2: Run
public void Run()
{
using (Context ctx = new Context())
{
Sort U = ctx.MkUninterpretedSort("U");
Console.WriteLine(U);
Expr a = ctx.MkConst("a", U);
a = ctx.MkConst("a", U);
Expr b = ctx.MkConst("b", U);
Expr c = ctx.MkConst("c", U);
IntExpr x = ctx.MkIntConst("x");
IntExpr y = ctx.MkIntConst("y");
Console.WriteLine(ctx.MkAnd(ctx.MkEq(a, b), ctx.MkEq(a, c)));
Console.WriteLine(U == ctx.IntSort);
Sort U2 = ctx.MkUninterpretedSort("U");
Console.WriteLine(U == U2);
U2 = ctx.MkUninterpretedSort("U2");
Console.WriteLine(U == U2);
Console.WriteLine(ctx.MkDistinct(a, b, c));
FuncDecl f = ctx.MkFuncDecl("f", new Sort[] { U, U }, U);
Console.WriteLine(ctx.MkEq(f[a,b], b));
}
}
示例3: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() { };
using (Context ctx = new Context(cfg))
{
FuncDecl f = ctx.MkFuncDecl("f", ctx.IntSort, ctx.IntSort);
FuncDecl g = ctx.MkFuncDecl("g", ctx.IntSort, ctx.IntSort);
IntExpr a = ctx.MkIntConst("a");
IntExpr b = ctx.MkIntConst("b");
IntExpr c = ctx.MkIntConst("c");
IntExpr x = ctx.MkIntConst("x");
Solver s = ctx.MkSolver();
Params p = ctx.MkParams();
p.Add("AUTO_CONFIG", false);
p.Add("MBQI", false);
s.Parameters = p;
s.Assert(ctx.MkForall(new Expr[] { x }, ctx.MkEq(f[g[x]], x), 1, new Pattern[] { ctx.MkPattern(f[g[x]]) }));
s.Assert(ctx.MkEq(a, g[b]));
s.Assert(ctx.MkEq(b, c));
s.Assert(ctx.MkDistinct(f[a], c));
Console.WriteLine(s);
Console.WriteLine(s.Check());
}
}
示例4: Run
public void Run()
{
using (Context ctx = new Context())
{
BoolExpr p = ctx.MkBoolConst("p");
Console.WriteLine(ctx.MkNot(p));
Console.WriteLine(ctx.MkNot(p));
IntExpr x = ctx.MkIntConst("x");
IntExpr y = ctx.MkIntConst("y");
Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)));
Console.WriteLine(ctx.MkAdd(ctx.MkInt(1), x));
Console.WriteLine(ctx.MkAdd(x, y));
Console.WriteLine(ctx.MkMul(ctx.MkInt(2), x));
Console.WriteLine(ctx.MkMul(x, ctx.MkInt(2)));
Console.WriteLine(ctx.MkMul(x, y));
Console.WriteLine(ctx.MkDiv(x, y));
Console.WriteLine(ctx.MkMod(x, y));
Console.WriteLine(ctx.MkEq(x, y));
Console.WriteLine(ctx.MkDistinct(x, y, x));
Console.WriteLine(ctx.MkNot(ctx.MkEq(x, y)));
Console.WriteLine(ctx.MkEq(x, y));
Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)));
Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)));
BoolExpr q = ctx.MkBoolConst("q");
Console.WriteLine(ctx.MkNot(p));
Console.WriteLine(ctx.MkNot(p));
Console.WriteLine(ctx.MkAnd(p, q));
Console.WriteLine(ctx.MkAnd(p, q));
Console.WriteLine(ctx.MkEq(x, y));
}
}
示例5: Run
public void Run()
{
using (Context ctx = new Context())
{
FuncDecl f = ctx.MkFuncDecl("f", new Sort[] { ctx.IntSort, ctx.RealSort }, ctx.IntSort);
try
{
Console.WriteLine(f.Domain[3]);
}
catch (IndexOutOfRangeException ex)
{
Console.WriteLine("failed: " + ex.Message);
}
IntExpr x = ctx.MkIntConst("x");
Console.WriteLine(f[ctx.MkInt(1), ctx.MkReal(1)]);
Console.WriteLine(f[ctx.MkInt(1), ctx.MkReal(1)].Sort);
Console.WriteLine(f[ctx.MkInt(1), ctx.MkReal(1)].NumArgs);
foreach (Expr e in f[ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkReal(1)].Args)
Console.WriteLine(e);
Console.WriteLine(f[ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkReal(1)].Args[0]);
Console.WriteLine(f[ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkReal(1)].Args[0].Equals(ctx.MkAdd(x, ctx.MkInt(1))));
Console.WriteLine(f[ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkReal(1)].FuncDecl[ctx.MkInt(2), ctx.MkInt2Real((IntExpr)ctx.MkAdd(x, ctx.MkInt(1)))]);
Console.WriteLine(ctx.MkInt(1).IsExpr);
Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)).IsExpr);
Console.WriteLine(ctx.MkForall(new Expr[] { x }, ctx.MkGt(x, ctx.MkInt(0))).IsExpr);
Console.WriteLine(ctx.MkInt(1).IsConst);
Console.WriteLine(x.IsConst);
Console.WriteLine(ctx.MkAdd(x, ctx.MkInt(1)).IsConst);
Console.WriteLine(ctx.MkForall(new Expr[] { x }, ctx.MkGt(x, ctx.MkInt(0))).IsConst);
Console.WriteLine(ctx.MkForall(new Expr[] { x }, ctx.MkGt(x, ctx.MkInt(0))).Body.Args[0]);
Console.WriteLine(ctx.MkForall(new Expr[] { x }, ctx.MkGt(x, ctx.MkInt(0))).Body.Args[0].IsExpr);
Console.WriteLine(ctx.MkForall(new Expr[] { x }, ctx.MkGt(x, ctx.MkInt(0))).Body.Args[0].IsConst);
Console.WriteLine(ctx.MkForall(new Expr[] { x }, ctx.MkGt(x, ctx.MkInt(0))).Body.Args[0].IsVar);
Console.WriteLine(x.IsVar);
Console.WriteLine(ctx.MkITE(ctx.MkTrue(), x, ctx.MkAdd(x, ctx.MkInt(1))));
Context ctx1 = new Context();
Console.WriteLine(ctx1.MkITE(ctx1.MkTrue(), x.Translate(ctx1), ctx.MkAdd(x, ctx.MkInt(1)).Translate(ctx1)));
Console.WriteLine(ctx.MkITE(ctx.MkTrue(), ctx.MkInt(1), ctx.MkInt(1)));
Console.WriteLine(ctx.MkDistinct(x, ctx.MkAdd(x, ctx.MkInt(1)), ctx.MkAdd(x, ctx.MkInt(2))));
Console.WriteLine(ctx1.MkAnd(ctx1.MkDistinct(x.Translate(ctx1), ctx1.MkInt(1)),
ctx1.MkGt((IntExpr)x.Translate(ctx1), ctx1.MkInt(0))));
}
}
示例6: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "AUTO_CONFIG", "true" },
{ "MODEL", "true" } };
using (Context ctx = new Context(cfg))
{
Constructor c_leaf = ctx.MkConstructor("leaf", "is_leaf", new string[] { "val" }, new Sort[] { ctx.IntSort });
Constructor c_node = ctx.MkConstructor("node", "is_node", new string[] { "left", "right" }, new Sort[] { null, null }, new uint[] { 1, 1 });
Constructor[] constr_1 = new Constructor[] { c_leaf, c_node };
Constructor c_nil = ctx.MkConstructor("nil", "is_nil");
Constructor c_cons = ctx.MkConstructor("cons", "is_cons", new string[] { "car", "cdr" }, new Sort[] { null, null }, new uint[] { 0, 1 });
Constructor[] constr_2 = new Constructor[] { c_nil, c_cons };
DatatypeSort[] ts = ctx.MkDatatypeSorts(new string[] { "Tree", "TreeList" },
new Constructor[][] { constr_1, constr_2 });
DatatypeSort Tree = ts[0];
DatatypeSort TreeList = ts[1];
FuncDecl leaf = Tree.Constructors[0];
FuncDecl node = Tree.Constructors[1];
FuncDecl val = Tree.Accessors[0][0];
FuncDecl nil = TreeList.Constructors[0];
FuncDecl cons = TreeList.Constructors[1];
Expr t1 = leaf[ctx.MkInt(10)];
Expr tl1 = cons[t1, nil.Apply()];
Expr t2 = node[tl1, nil.Apply()];
Console.WriteLine(t2);
Console.WriteLine(val.Apply(t1).Simplify());
t1 = ctx.MkConst("t1", TreeList);
t2 = ctx.MkConst("t2", TreeList);
Expr t3 = ctx.MkConst("t3", TreeList);
Solver s = ctx.MkSolver();
s.Assert(ctx.MkDistinct(t1, t2, t3));
Console.WriteLine(s.Check());
Console.WriteLine(s.Model);
}
}
示例7: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "AUTO_CONFIG", "true" } };
using (Context ctx = new Context(cfg))
{
ArithExpr[] Q = new ArithExpr[8];
for (uint i = 0; i < 8; i++)
Q[i] = ctx.MkIntConst(string.Format("Q_{0}", i + 1));
BoolExpr[] val_c = new BoolExpr[8];
for (uint i = 0; i < 8; i++)
val_c[i] = ctx.MkAnd(ctx.MkLe(ctx.MkInt(1), Q[i]),
ctx.MkLe(Q[i], ctx.MkInt(8)));
BoolExpr col_c = ctx.MkDistinct(Q);
BoolExpr[][] diag_c = new BoolExpr[8][];
for (uint i = 0; i < 8; i++)
{
diag_c[i] = new BoolExpr[i];
for (uint j = 0; j < i; j++)
diag_c[i][j] = (BoolExpr)ctx.MkITE(ctx.MkEq(ctx.MkInt(i), ctx.MkInt(j)),
ctx.MkTrue(),
ctx.MkAnd(ctx.MkNot(ctx.MkEq(ctx.MkSub(Q[i], Q[j]),
ctx.MkSub(ctx.MkInt(i), ctx.MkInt(j)))),
ctx.MkNot(ctx.MkEq(ctx.MkSub(Q[i], Q[j]),
ctx.MkSub(ctx.MkInt(j), ctx.MkInt(i))))));
}
Solver s = ctx.MkSolver();
s.Assert(val_c);
s.Assert(col_c);
foreach (var c in diag_c)
s.Assert(c);
Console.WriteLine(s.Check());
Console.WriteLine(s.Model);
}
}
示例8: SudokuExample
/// <summary>
/// Sudoku solving example.
/// </summary>
static void SudokuExample(Context ctx)
{
Console.WriteLine("SudokuExample");
// 9x9 matrix of integer variables
IntExpr[][] X = new IntExpr[9][];
for (uint i = 0; i < 9; i++)
{
X[i] = new IntExpr[9];
for (uint j = 0; j < 9; j++)
X[i][j] = (IntExpr)ctx.MkConst(ctx.MkSymbol("x_" + (i + 1) + "_" + (j + 1)), ctx.IntSort);
}
// each cell contains a value in {1, ..., 9}
Expr[][] cells_c = new Expr[9][];
for (uint i = 0; i < 9; i++)
{
cells_c[i] = new BoolExpr[9];
for (uint j = 0; j < 9; j++)
cells_c[i][j] = ctx.MkAnd(ctx.MkLe(ctx.MkInt(1), X[i][j]),
ctx.MkLe(X[i][j], ctx.MkInt(9)));
}
// each row contains a digit at most once
BoolExpr[] rows_c = new BoolExpr[9];
for (uint i = 0; i < 9; i++)
rows_c[i] = ctx.MkDistinct(X[i]);
// each column contains a digit at most once
BoolExpr[] cols_c = new BoolExpr[9];
for (uint j = 0; j < 9; j++)
{
IntExpr[] column = new IntExpr[9];
for (uint i = 0; i < 9; i++)
column[i] = X[i][j];
cols_c[j] = ctx.MkDistinct(column);
}
// each 3x3 square contains a digit at most once
BoolExpr[][] sq_c = new BoolExpr[3][];
for (uint i0 = 0; i0 < 3; i0++)
{
sq_c[i0] = new BoolExpr[3];
for (uint j0 = 0; j0 < 3; j0++)
{
IntExpr[] square = new IntExpr[9];
for (uint i = 0; i < 3; i++)
for (uint j = 0; j < 3; j++)
square[3 * i + j] = X[3 * i0 + i][3 * j0 + j];
sq_c[i0][j0] = ctx.MkDistinct(square);
}
}
BoolExpr sudoku_c = ctx.MkTrue();
foreach (BoolExpr[] t in cells_c)
sudoku_c = ctx.MkAnd(ctx.MkAnd(t), sudoku_c);
sudoku_c = ctx.MkAnd(ctx.MkAnd(rows_c), sudoku_c);
sudoku_c = ctx.MkAnd(ctx.MkAnd(cols_c), sudoku_c);
foreach (BoolExpr[] t in sq_c)
sudoku_c = ctx.MkAnd(ctx.MkAnd(t), sudoku_c);
// sudoku instance, we use '0' for empty cells
int[,] instance = {{0,0,0,0,9,4,0,3,0},
{0,0,0,5,1,0,0,0,7},
{0,8,9,0,0,0,0,4,0},
{0,0,0,0,0,0,2,0,8},
{0,6,0,2,0,1,0,5,0},
{1,0,2,0,0,0,0,0,0},
{0,7,0,0,0,0,5,2,0},
{9,0,0,0,6,5,0,0,0},
{0,4,0,9,7,0,0,0,0}};
BoolExpr instance_c = ctx.MkTrue();
for (uint i = 0; i < 9; i++)
for (uint j = 0; j < 9; j++)
instance_c = ctx.MkAnd(instance_c,
(BoolExpr)
ctx.MkITE(ctx.MkEq(ctx.MkInt(instance[i, j]), ctx.MkInt(0)),
ctx.MkTrue(),
ctx.MkEq(X[i][j], ctx.MkInt(instance[i, j]))));
Solver s = ctx.MkSolver();
s.Assert(sudoku_c);
s.Assert(instance_c);
if (s.Check() == Status.SATISFIABLE)
{
Model m = s.Model;
Expr[,] R = new Expr[9, 9];
for (uint i = 0; i < 9; i++)
for (uint j = 0; j < 9; j++)
R[i, j] = m.Evaluate(X[i][j]);
Console.WriteLine("Sudoku solution:");
for (uint i = 0; i < 9; i++)
{
for (uint j = 0; j < 9; j++)
//.........这里部分代码省略.........
示例9: ArrayExample3
/// <summary>
/// Show that <code>distinct(a_0, ... , a_n)</code> is
/// unsatisfiable when <code>a_i</code>'s are arrays from boolean to
/// boolean and n > 4.
/// </summary>
/// <remarks>This example also shows how to use the <code>distinct</code> construct.</remarks>
public static void ArrayExample3(Context ctx)
{
Console.WriteLine("ArrayExample3");
for (int n = 2; n <= 5; n++)
{
Console.WriteLine("n = {0}", n);
Sort bool_type = ctx.MkBoolSort();
Sort array_type = ctx.MkArraySort(bool_type, bool_type);
Expr[] a = new Expr[n];
/* create arrays */
for (int i = 0; i < n; i++)
{
a[i] = ctx.MkConst(String.Format("array_{0}", i), array_type);
}
/* assert distinct(a[0], ..., a[n]) */
BoolExpr d = ctx.MkDistinct(a);
Console.WriteLine("{0}", (d));
/* context is satisfiable if n < 5 */
Model model = Check(ctx, d, n < 5 ? Status.SATISFIABLE : Status.UNSATISFIABLE);
if (n < 5)
{
for (int i = 0; i < n; i++)
{
Console.WriteLine("{0} = {1}",
a[i],
model.Evaluate(a[i]));
}
}
}
}