本文整理汇总了C#中Microsoft.Z3.Context.MkDatatypeSort方法的典型用法代码示例。如果您正苦于以下问题:C# Context.MkDatatypeSort方法的具体用法?C# Context.MkDatatypeSort怎么用?C# Context.MkDatatypeSort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Z3.Context
的用法示例。
在下文中一共展示了Context.MkDatatypeSort方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "AUTO_CONFIG", "true" },
{ "MODEL", "true" } };
using (Context ctx = new Context(cfg))
{
Constructor cred = ctx.MkConstructor("red", "is_red");
Constructor cgreen = ctx.MkConstructor("green", "is_green");
Constructor cblue = ctx.MkConstructor("blue", "is_blue");
DatatypeSort color = ctx.MkDatatypeSort("Color", new Constructor[] { cred, cgreen, cblue });
Expr Red = ctx.MkConst(color.Constructors[0]);
Expr Green = ctx.MkConst(color.Constructors[1]);
Expr Blue = ctx.MkConst(color.Constructors[2]);
Expr c = ctx.MkConst("c", color);
Solver s = ctx.MkSolver();
s.Assert(ctx.MkNot(ctx.MkOr(ctx.MkEq(c, Red), ctx.MkEq(c, Green), ctx.MkEq(c, Blue))));
Console.WriteLine(s.Check()); // must be unsat
BoolExpr c_is_red = (BoolExpr)color.Recognizers[0][c];
BoolExpr c_is_green = (BoolExpr)color.Recognizers[1][c];
BoolExpr c_is_blue = (BoolExpr)color.Recognizers[2][c];
s = ctx.MkSolver();
s.Assert(ctx.MkOr(c_is_red, c_is_green, c_is_blue));
Console.WriteLine(s.Check()); // must be sat
s = ctx.MkSolver();
s.Assert(ctx.MkNot(ctx.MkOr(c_is_red, c_is_green, c_is_blue)));
Console.WriteLine(s.Check()); // must be unsat
}
}
示例2: 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);
}
示例3: GenerateEnvironment
private Environment GenerateEnvironment(Context context)
{
var environment = new Environment();
// Class instances
// TODO: support NULL values
foreach (var instancesPerClassType in _instances.GroupBy(_ => _.Value.GetType()))
{
string classType = instancesPerClassType.Key.Name;
EnumSort instancesEnumSort = context.MkEnumSort(classType + "_instances", instancesPerClassType.Select(_ => _.Key).ToArray());
environment.Types.Add(instancesPerClassType.Key, instancesEnumSort);
Expr[] instancesEnumSortValues = instancesEnumSort.Consts;
int instancesIndex = 0;
foreach (KeyValuePair<string, object> instance in instancesPerClassType)
{
environment.Instances.Add(instance.Key,
new InstanceInfo(instancesEnumSortValues[instancesIndex++], objectInstance: instance.Value));
}
}
// Super Types
foreach (var superType in _superTypes)
{
var subTypeSorts = environment.Types.Where(t => t.Key.IsSubclassOf(superType)).Select(t => t.Value).ToList();
if (subTypeSorts.Count == 0)
continue;
var superTypeConstructors = new List<Constructor>();
foreach (var subTypeSort in subTypeSorts)
{
var subTypeConstr = context.MkConstructor(
name: subTypeSort.Name.ToString(),
recognizer: "Is" + subTypeSort.Name,
fieldNames: new[] { subTypeSort.Name + "2" + superType.Name },
sorts: new[] { subTypeSort },
sortRefs: null);
superTypeConstructors.Add(subTypeConstr);
}
DatatypeSort superTypeSort = context.MkDatatypeSort(superType.Name, superTypeConstructors.ToArray());
//DatatypeSort = context.MkDatatypeSort("Types", new Constructor[] {
// context.MkConstructor("ValTypes", "isValType", new String[] {"Val2Type"}, new Sort[] {ValTypeSort}, null),
// context.MkConstructor("RefTypes", "isRefType", new String[] {"Ref2Type"}, new Sort[] {RefTypeSort}, null)
//});
environment.Types.Add(superType, superTypeSort);
}
// Strings
if (_possibleStringValues.Any())
{
EnumSort enumSort = context.MkEnumSort("Strings", _possibleStringValues.ToArray());
environment.PossibleStringValues = enumSort;
}
foreach (var member in _members)
{
LambdaExpressionToConstraintGenerator.GetOrAddMemberAccessFunction(context, environment, member);
}
return environment;
}