本文整理汇总了C#中Microsoft.Z3.Context.MkImplies方法的典型用法代码示例。如果您正苦于以下问题:C# Context.MkImplies方法的具体用法?C# Context.MkImplies怎么用?C# Context.MkImplies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Z3.Context
的用法示例。
在下文中一共展示了Context.MkImplies方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "AUTO_CONFIG", "true" } };
using (Context ctx = new Context(cfg))
{
BoolExpr p1 = ctx.MkBoolConst("p1");
BoolExpr p2 = ctx.MkBoolConst("p2");
BoolExpr p3 = ctx.MkBoolConst("p3");
IntExpr x = ctx.MkIntConst("x");
IntExpr y = ctx.MkIntConst("y");
Solver s = ctx.MkSolver();
s.Assert(ctx.MkImplies(p1, ctx.MkGt(x, ctx.MkInt(10))),
ctx.MkImplies(p1, ctx.MkGt(y, x)),
ctx.MkImplies(p2, ctx.MkLt(y, ctx.MkInt(5))),
ctx.MkImplies(p3, ctx.MkGt(y, ctx.MkInt(0))));
Console.WriteLine(s);
Console.WriteLine(s.Check(p1, p2, p3));
Console.WriteLine("Core: ");
foreach (Expr e in s.UnsatCore)
Console.WriteLine(e);
Console.WriteLine(s.Check(p1, p3));
Console.WriteLine(s.Model);
}
}
示例2: Run
public void Run()
{
using (Context ctx = new Context()) {
var s = ctx.MkFixedpoint();
BoolSort B = ctx.BoolSort;
Sort BV8 = ctx.MkBitVecSort(8);
FuncDecl edge = ctx.MkFuncDecl("edge", new Sort[]{BV8, BV8}, B);
FuncDecl path = ctx.MkFuncDecl("path", new Sort[]{BV8, BV8}, B);
BitVecExpr x = (BitVecExpr)ctx.MkBound(0,BV8);
BitVecExpr y = (BitVecExpr)ctx.MkBound(1,BV8);
BitVecExpr z = (BitVecExpr)ctx.MkBound(2,BV8);
s.RegisterRelation(edge);
s.RegisterRelation(path);
s.AddRule(ctx.MkImplies((BoolExpr)edge[x,y],(BoolExpr)path[x,y]));
s.AddRule(ctx.MkImplies(ctx.MkAnd((BoolExpr)path[x,y],(BoolExpr)path[y,z]),
(BoolExpr)path[x,z]));
for (uint i = 0; i < 128; ++i) {
s.AddFact(edge, i, i+1);
}
Console.WriteLine(s.Query((BoolExpr)path[ctx.MkBV(0,8),ctx.MkBV(129,8)]));
Console.WriteLine(s.GetAnswer());
Console.WriteLine(s.Query((BoolExpr)path[ctx.MkBV(0,8),ctx.MkBV(128,8)]));
Console.WriteLine(s.GetAnswer());
Console.WriteLine(s.Query((BoolExpr)path[x,ctx.MkBV(20,8)]));
Console.WriteLine(s.GetAnswer());
Console.WriteLine(s.Query(ctx.MkAnd((BoolExpr)path[x,y],
(BoolExpr)path[y,ctx.MkBV(20,8)])));
Console.WriteLine(s.GetAnswer());
}
}
示例3: MkRandomExpr
/// <summary>
/// Generates a slightly randomized expression.
/// </summary>
static BoolExpr MkRandomExpr(Context ctx, System.Random rng)
{
int limit = 1073741823;
Sort i = ctx.IntSort;
Sort b = ctx.BoolSort;
Symbol sr1 = ctx.MkSymbol(rng.Next(0, limit));
Symbol sr2 = ctx.MkSymbol(rng.Next(0, limit));
Symbol sr3 = ctx.MkSymbol(rng.Next(0, limit));
FuncDecl r1 = ctx.MkFuncDecl(sr1, i, b);
FuncDecl r2 = ctx.MkFuncDecl(sr2, i, b);
FuncDecl r3 = ctx.MkFuncDecl(sr3, i, b);
Symbol s = ctx.MkSymbol(rng.Next(0, limit));
Expr x = ctx.MkConst(s, i);
BoolExpr r1x = (BoolExpr)ctx.MkApp(r1, x);
BoolExpr r2x = (BoolExpr)ctx.MkApp(r2, x);
BoolExpr r3x = (BoolExpr)ctx.MkApp(r3, x);
Expr[] vars = { x };
BoolExpr rl1 = ctx.MkForall(vars, ctx.MkImplies(r1x, r2x));
BoolExpr rl2 = ctx.MkForall(vars, ctx.MkImplies(r2x, r1x));
BoolExpr rl3 = (BoolExpr)ctx.MkApp(r1, ctx.MkInt(3));
BoolExpr q = (BoolExpr)ctx.MkApp(r3, ctx.MkInt(2));
BoolExpr a1 = ctx.MkNot(q);
BoolExpr q1 = ctx.MkExists(vars, ctx.MkAnd(r3x, r2x));
BoolExpr q2 = ctx.MkExists(vars, ctx.MkAnd(r3x, r1x));
BoolExpr[] all = { a1, q1, q2 };
return ctx.MkAnd(all);
}
示例4: Run
public void Run()
{
using (Context ctx = new Context()) {
ctx.UpdateParamValue("DL_ENGINE","1");
ctx.UpdateParamValue("DL_PDR_USE_FARKAS","true");
// ctx.UpdateParamValue("VERBOSE","2");
var s = ctx.MkFixedpoint();
BoolSort B = ctx.BoolSort;
IntSort I = ctx.IntSort;
FuncDecl mc = ctx.MkFuncDecl("mc", new Sort[]{I, I}, B);
ArithExpr x = (ArithExpr)ctx.MkBound(0,I);
ArithExpr y = (ArithExpr)ctx.MkBound(1,I);
ArithExpr z = (ArithExpr)ctx.MkBound(2,I);
s.RegisterRelation(mc);
BoolExpr gt = ctx.MkGt(x, ctx.MkInt(100));
s.AddRule(ctx.MkImplies(gt,(BoolExpr)mc[x,ctx.MkSub(x,ctx.MkInt(10))]));
s.AddRule(ctx.MkImplies(ctx.MkAnd(ctx.MkNot(gt),
(BoolExpr) mc[ctx.MkAdd(x,ctx.MkInt(11)),y],
(BoolExpr) mc[y,z]),
(BoolExpr) mc[x,z]));
Console.WriteLine(s.Query(ctx.MkAnd((BoolExpr)mc[x,y], ctx.MkGt(y,ctx.MkInt(100)))));
Console.WriteLine(s.GetAnswer());
Console.WriteLine(s.Query(ctx.MkAnd((BoolExpr)mc[x,y], ctx.MkLt(y,ctx.MkInt(91)))));
Console.WriteLine(s.GetAnswer());
}
}
示例5: ArrayExample2
/// <summary>
/// Prove <tt>store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3))</tt>.
/// </summary>
/// <remarks>This example demonstrates how to use the array theory.</remarks>
public static void ArrayExample2(Context ctx)
{
Console.WriteLine("ArrayExample2");
Sort int_type = ctx.IntSort;
Sort array_type = ctx.MkArraySort(int_type, int_type);
ArrayExpr a1 = (ArrayExpr)ctx.MkConst("a1", array_type);
ArrayExpr a2 = ctx.MkArrayConst("a2", int_type, int_type);
Expr i1 = ctx.MkConst("i1", int_type);
Expr i2 = ctx.MkConst("i2", int_type);
Expr i3 = ctx.MkConst("i3", int_type);
Expr v1 = ctx.MkConst("v1", int_type);
Expr v2 = ctx.MkConst("v2", int_type);
Expr st1 = ctx.MkStore(a1, i1, v1);
Expr st2 = ctx.MkStore(a2, i2, v2);
Expr sel1 = ctx.MkSelect(a1, i3);
Expr sel2 = ctx.MkSelect(a2, i3);
/* create antecedent */
BoolExpr antecedent = ctx.MkEq(st1, st2);
/* create consequent: i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3) */
BoolExpr consequent = ctx.MkOr(new BoolExpr[] { ctx.MkEq(i1, i3), ctx.MkEq(i2, i3), ctx.MkEq(sel1, sel2) });
/* prove store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3)) */
BoolExpr thm = ctx.MkImplies(antecedent, consequent);
Console.WriteLine("prove: store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3))");
Console.WriteLine("{0}", (thm));
Prove(ctx, thm);
}
示例6: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "AUTO_CONFIG", "true" } };
using (Context ctx = new Context(cfg))
{
Sort A = ctx.MkUninterpretedSort("A");
Sort B = ctx.MkUninterpretedSort("B");
FuncDecl f = ctx.MkFuncDecl("f", A, B);
Expr a1 = ctx.MkConst("a1", A);
Expr a2 = ctx.MkConst("a2", A);
Expr b = ctx.MkConst("b", B);
Expr x = ctx.MkConst("x", A);
Expr y = ctx.MkConst("y", A);
Solver s = ctx.MkSolver();
s.Assert(ctx.MkNot(ctx.MkEq(a1, a2)));
s.Assert(ctx.MkEq(f[a1], b));
s.Assert(ctx.MkEq(f[a2], b));
s.Assert(ctx.MkForall(new Expr[] { x, y }, ctx.MkImplies(ctx.MkEq(f[x], f[y]),
ctx.MkEq(x, y)),
1,
new Pattern[] { ctx.MkPattern(f[x], f[y]) }));
Console.WriteLine(s);
Console.WriteLine(s.Check());
}
}
示例7: DependsOn
public BoolExpr DependsOn(Context ctx, BoolExpr pack, BoolExpr[] deps)
{
BoolExpr[] q = new BoolExpr[deps.Length];
for (uint i = 0; i < deps.Length; i++)
q[i] = ctx.MkImplies(pack, deps[i]);
return ctx.MkAnd(q);
}
示例8: 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);
}
}
示例9: Run
public void Run()
{
using (Context ctx = new Context()) {
var s = ctx.MkFixedpoint();
BoolExpr a = ctx.MkBoolConst("a");
BoolExpr b = ctx.MkBoolConst("b");
BoolExpr c = ctx.MkBoolConst("c");
s.RegisterRelation(a.FuncDecl);
s.RegisterRelation(b.FuncDecl);
s.RegisterRelation(c.FuncDecl);
s.AddRule(ctx.MkImplies(a, b));
s.AddRule(ctx.MkImplies(b, c));
Console.WriteLine(s.Query(c));
s.AddRule(a);
Console.WriteLine(s.Query(c));
}
}
示例10: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "AUTO_CONFIG", "true" } };
using (Context ctx = new Context(cfg))
{
Sort T = ctx.MkUninterpretedSort("Type");
FuncDecl subtype = ctx.MkFuncDecl("subtype", new Sort[] { T, T }, ctx.BoolSort);
FuncDecl array_of = ctx.MkFuncDecl("array_of", T, T);
Expr root = ctx.MkConst("root", T);
Expr x = ctx.MkConst("x", T);
Expr y = ctx.MkConst("y", T);
Expr z = ctx.MkConst("z", T);
BoolExpr[] axioms = new BoolExpr[] {
ctx.MkForall(new Expr[] { x }, subtype[x, x]),
ctx.MkForall(new Expr[] { x, y , z }, ctx.MkImplies(ctx.MkAnd((BoolExpr)subtype[x,y], (BoolExpr)subtype[y,z]), (BoolExpr)subtype[x,z])),
ctx.MkForall(new Expr[] { x, y }, ctx.MkImplies(ctx.MkAnd((BoolExpr)subtype[x, y], (BoolExpr)subtype[y,x]), ctx.MkEq(x, y))),
ctx.MkForall(new Expr[] { x, y, z }, ctx.MkImplies(ctx.MkAnd((BoolExpr)subtype[x,y],(BoolExpr)subtype[x,z]),
ctx.MkOr((BoolExpr)subtype[y,z], (BoolExpr)subtype[z,y]))),
ctx.MkForall(new Expr[] { x, y }, ctx.MkImplies((BoolExpr)subtype[x,y], (BoolExpr)subtype[array_of[x], array_of[y]])),
ctx.MkForall(new Expr[] { x }, (BoolExpr) subtype[root, x])
};
Solver s = ctx.MkSolver();
s.Assert(axioms);
Console.WriteLine(s);
Console.WriteLine(s.Check());
Expr[] universe = s.Model.SortUniverse(T);
foreach (var e in universe)
Console.WriteLine(e);
Console.WriteLine(s.Model);
}
}
示例11: Run
public void Run()
{
using (Context ctx = new Context()) {
var s = ctx.MkFixedpoint();
BoolSort B = ctx.BoolSort;
Sort BV8 = ctx.MkBitVecSort(8);
FuncDecl f = ctx.MkFuncDecl("f", BV8, B);
FuncDecl g = ctx.MkFuncDecl("g", BV8, B);
BitVecExpr b0 = (BitVecExpr)ctx.MkBound(0,BV8);
s.RegisterRelation(f);
s.RegisterRelation(g);
s.AddRule((BoolExpr)f[b0]);
BitVecExpr mask0 = ctx.MkBV(0xFE,8);
BoolExpr even = ctx.MkEq(b0,ctx.MkBVAND(b0,mask0));
s.AddRule(ctx.MkImplies(ctx.MkAnd((BoolExpr)f[b0],even), (BoolExpr)g[b0]));
Console.WriteLine(s.Query((BoolExpr)g[b0]));
Console.WriteLine(s.GetAnswer());
}
}
示例12: ForestExample
//.........这里部分代码省略.........
Sort tree, forest;
FuncDecl nil1_decl, is_nil1_decl, cons1_decl, is_cons1_decl, car1_decl, cdr1_decl;
FuncDecl nil2_decl, is_nil2_decl, cons2_decl, is_cons2_decl, car2_decl, cdr2_decl;
Expr nil1, nil2, t1, t2, t3, t4, f1, f2, f3, l1, l2, x, y, u, v;
//
// Declare the names of the accessors for cons.
// Then declare the sorts of the accessors.
// For this example, all sorts refer to the new types 'forest' and 'tree'
// being declared, so we pass in null for both sorts1 and sorts2.
// On the other hand, the sort_refs arrays contain the indices of the
// two new sorts being declared. The first element in sort1_refs
// points to 'tree', which has index 1, the second element in sort1_refs array
// points to 'forest', which has index 0.
//
Symbol[] head_tail1 = new Symbol[] { ctx.MkSymbol("head"), ctx.MkSymbol("tail") };
Sort[] sorts1 = new Sort[] { null, null };
uint[] sort1_refs = new uint[] { 1, 0 }; // the first item points to a tree, the second to a forest
Symbol[] head_tail2 = new Symbol[] { ctx.MkSymbol("car"), ctx.MkSymbol("cdr") };
Sort[] sorts2 = new Sort[] { null, null };
uint[] sort2_refs = new uint[] { 0, 0 }; // both items point to the forest datatype.
Constructor nil1_con, cons1_con, nil2_con, cons2_con;
Constructor[] constructors1 = new Constructor[2], constructors2 = new Constructor[2];
Symbol[] sort_names = { ctx.MkSymbol("forest"), ctx.MkSymbol("tree") };
/* build a forest */
nil1_con = ctx.MkConstructor(ctx.MkSymbol("nil"), ctx.MkSymbol("is_nil"), null, null, null);
cons1_con = ctx.MkConstructor(ctx.MkSymbol("cons1"), ctx.MkSymbol("is_cons1"), head_tail1, sorts1, sort1_refs);
constructors1[0] = nil1_con;
constructors1[1] = cons1_con;
/* build a tree */
nil2_con = ctx.MkConstructor(ctx.MkSymbol("nil2"), ctx.MkSymbol("is_nil2"), null, null, null);
cons2_con = ctx.MkConstructor(ctx.MkSymbol("cons2"), ctx.MkSymbol("is_cons2"), head_tail2, sorts2, sort2_refs);
constructors2[0] = nil2_con;
constructors2[1] = cons2_con;
Constructor[][] clists = new Constructor[][] { constructors1, constructors2 };
Sort[] sorts = ctx.MkDatatypeSorts(sort_names, clists);
forest = sorts[0];
tree = sorts[1];
//
// Now that the datatype has been created.
// Query the constructors for the constructor
// functions, testers, and field accessors.
//
nil1_decl = nil1_con.ConstructorDecl;
is_nil1_decl = nil1_con.TesterDecl;
cons1_decl = cons1_con.ConstructorDecl;
is_cons1_decl = cons1_con.TesterDecl;
FuncDecl[] cons1_accessors = cons1_con.AccessorDecls;
car1_decl = cons1_accessors[0];
cdr1_decl = cons1_accessors[1];
nil2_decl = nil2_con.ConstructorDecl;
is_nil2_decl = nil2_con.TesterDecl;
cons2_decl = cons2_con.ConstructorDecl;
is_cons2_decl = cons2_con.TesterDecl;
FuncDecl[] cons2_accessors = cons2_con.AccessorDecls;
car2_decl = cons2_accessors[0];
cdr2_decl = cons2_accessors[1];
nil1 = ctx.MkConst(nil1_decl);
nil2 = ctx.MkConst(nil2_decl);
f1 = ctx.MkApp(cons1_decl, nil2, nil1);
t1 = ctx.MkApp(cons2_decl, nil1, nil1);
t2 = ctx.MkApp(cons2_decl, f1, nil1);
t3 = ctx.MkApp(cons2_decl, f1, f1);
t4 = ctx.MkApp(cons2_decl, nil1, f1);
f2 = ctx.MkApp(cons1_decl, t1, nil1);
f3 = ctx.MkApp(cons1_decl, t1, f1);
/* nil != cons(nil,nil) */
Prove(ctx, ctx.MkNot(ctx.MkEq(nil1, f1)));
Prove(ctx, ctx.MkNot(ctx.MkEq(nil2, t1)));
/* cons(x,u) = cons(x, v) => u = v */
u = ctx.MkConst("u", forest);
v = ctx.MkConst("v", forest);
x = ctx.MkConst("x", tree);
y = ctx.MkConst("y", tree);
l1 = ctx.MkApp(cons1_decl, x, u);
l2 = ctx.MkApp(cons1_decl, y, v);
Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(u, v)));
Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(x, y)));
/* is_nil(u) or is_cons(u) */
Prove(ctx, ctx.MkOr((BoolExpr)ctx.MkApp(is_nil1_decl, u),
(BoolExpr)ctx.MkApp(is_cons1_decl, u)));
/* occurs check u != cons(x,u) */
Prove(ctx, ctx.MkNot(ctx.MkEq(u, l1)));
}
示例13: TreeExample
/// <summary>
/// Create a binary tree datatype.
/// </summary>
public static void TreeExample(Context ctx)
{
Console.WriteLine("TreeExample");
Sort cell;
FuncDecl nil_decl, is_nil_decl, cons_decl, is_cons_decl, car_decl, cdr_decl;
Expr nil, l1, l2, x, y, u, v;
BoolExpr fml, fml1;
string[] head_tail = new string[] { "car", "cdr" };
Sort[] sorts = new Sort[] { null, null };
uint[] sort_refs = new uint[] { 0, 0 };
Constructor nil_con, cons_con;
nil_con = ctx.MkConstructor("nil", "is_nil", null, null, null);
cons_con = ctx.MkConstructor("cons", "is_cons", head_tail, sorts, sort_refs);
Constructor[] constructors = new Constructor[] { nil_con, cons_con };
cell = ctx.MkDatatypeSort("cell", constructors);
nil_decl = nil_con.ConstructorDecl;
is_nil_decl = nil_con.TesterDecl;
cons_decl = cons_con.ConstructorDecl;
is_cons_decl = cons_con.TesterDecl;
FuncDecl[] cons_accessors = cons_con.AccessorDecls;
car_decl = cons_accessors[0];
cdr_decl = cons_accessors[1];
nil = ctx.MkConst(nil_decl);
l1 = ctx.MkApp(cons_decl, nil, nil);
l2 = ctx.MkApp(cons_decl, l1, nil);
/* nil != cons(nil, nil) */
Prove(ctx, ctx.MkNot(ctx.MkEq(nil, l1)));
/* cons(x,u) = cons(x, v) => u = v */
u = ctx.MkConst("u", cell);
v = ctx.MkConst("v", cell);
x = ctx.MkConst("x", cell);
y = ctx.MkConst("y", cell);
l1 = ctx.MkApp(cons_decl, x, u);
l2 = ctx.MkApp(cons_decl, y, v);
Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(u, v)));
Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(x, y)));
/* is_nil(u) or is_cons(u) */
Prove(ctx, ctx.MkOr((BoolExpr)ctx.MkApp(is_nil_decl, u), (BoolExpr)ctx.MkApp(is_cons_decl, u)));
/* occurs check u != cons(x,u) */
Prove(ctx, ctx.MkNot(ctx.MkEq(u, l1)));
/* destructors: is_cons(u) => u = cons(car(u),cdr(u)) */
fml1 = ctx.MkEq(u, ctx.MkApp(cons_decl, ctx.MkApp(car_decl, u), ctx.MkApp(cdr_decl, u)));
fml = ctx.MkImplies((BoolExpr)ctx.MkApp(is_cons_decl, u), fml1);
Console.WriteLine("Formula {0}", fml);
Prove(ctx, fml);
Disprove(ctx, fml1);
}
示例14: ListExample
/// <summary>
/// Create a list datatype.
/// </summary>
public static void ListExample(Context ctx)
{
Console.WriteLine("ListExample");
Sort int_ty;
ListSort int_list;
Expr nil, l1, l2, x, y, u, v;
BoolExpr fml, fml1;
int_ty = ctx.MkIntSort();
int_list = ctx.MkListSort(ctx.MkSymbol("int_list"), int_ty);
nil = ctx.MkConst(int_list.NilDecl);
l1 = ctx.MkApp(int_list.ConsDecl, ctx.MkInt(1), nil);
l2 = ctx.MkApp(int_list.ConsDecl, ctx.MkInt(2), nil);
/* nil != cons(1, nil) */
Prove(ctx, ctx.MkNot(ctx.MkEq(nil, l1)));
/* cons(2,nil) != cons(1, nil) */
Prove(ctx, ctx.MkNot(ctx.MkEq(l1, l2)));
/* cons(x,nil) = cons(y, nil) => x = y */
x = ctx.MkConst("x", int_ty);
y = ctx.MkConst("y", int_ty);
l1 = ctx.MkApp(int_list.ConsDecl, x, nil);
l2 = ctx.MkApp(int_list.ConsDecl, y, nil);
Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(x, y)));
/* cons(x,u) = cons(x, v) => u = v */
u = ctx.MkConst("u", int_list);
v = ctx.MkConst("v", int_list);
l1 = ctx.MkApp(int_list.ConsDecl, x, u);
l2 = ctx.MkApp(int_list.ConsDecl, y, v);
Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(u, v)));
Prove(ctx, ctx.MkImplies(ctx.MkEq(l1, l2), ctx.MkEq(x, y)));
/* is_nil(u) or is_cons(u) */
Prove(ctx, ctx.MkOr((BoolExpr)ctx.MkApp(int_list.IsNilDecl, u),
(BoolExpr)ctx.MkApp(int_list.IsConsDecl, u)));
/* occurs check u != cons(x,u) */
Prove(ctx, ctx.MkNot(ctx.MkEq(u, l1)));
/* destructors: is_cons(u) => u = cons(head(u),tail(u)) */
fml1 = ctx.MkEq(u, ctx.MkApp(int_list.ConsDecl, ctx.MkApp(int_list.HeadDecl, u),
ctx.MkApp(int_list.TailDecl, u)));
fml = ctx.MkImplies((BoolExpr)ctx.MkApp(int_list.IsConsDecl, u), fml1);
Console.WriteLine("Formula {0}", fml);
Prove(ctx, fml);
Disprove(ctx, fml1);
}
示例15: ProveExample1
/// <summary>
/// Prove <tt>x = y implies g(x) = g(y)</tt>, and
/// disprove <tt>x = y implies g(g(x)) = g(y)</tt>.
/// </summary>
/// <remarks>This function demonstrates how to create uninterpreted
/// types and functions.</remarks>
public static void ProveExample1(Context ctx)
{
Console.WriteLine("ProveExample1");
/* create uninterpreted type. */
Sort U = ctx.MkUninterpretedSort(ctx.MkSymbol("U"));
/* declare function g */
FuncDecl g = ctx.MkFuncDecl("g", U, U);
/* create x and y */
Expr x = ctx.MkConst("x", U);
Expr y = ctx.MkConst("y", U);
/* create g(x), g(y) */
Expr gx = g[x];
Expr gy = g[y];
/* assert x = y */
BoolExpr eq = ctx.MkEq(x, y);
/* prove g(x) = g(y) */
BoolExpr f = ctx.MkEq(gx, gy);
Console.WriteLine("prove: x = y implies g(x) = g(y)");
Prove(ctx, ctx.MkImplies(eq, f));
/* create g(g(x)) */
Expr ggx = g[gx];
/* disprove g(g(x)) = g(y) */
f = ctx.MkEq(ggx, gy);
Console.WriteLine("disprove: x = y implies g(g(x)) = g(y)");
Disprove(ctx, ctx.MkImplies(eq, f));
/* Print the model using the custom model printer */
Model m = Check(ctx, ctx.MkNot(f), Status.SATISFIABLE);
Console.WriteLine(m);
}