本文整理汇总了C#中Microsoft.Z3.Context.MkBoolConst方法的典型用法代码示例。如果您正苦于以下问题:C# Context.MkBoolConst方法的具体用法?C# Context.MkBoolConst怎么用?C# Context.MkBoolConst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Z3.Context
的用法示例。
在下文中一共展示了Context.MkBoolConst方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
{
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);
}
}
示例3: 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));
}
}
示例4: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "AUTO_CONFIG", "true" } };
using (Context ctx = new Context(cfg))
{
BoolExpr a = ctx.MkBoolConst("a");
BoolExpr b = ctx.MkBoolConst("b");
BoolExpr c = ctx.MkBoolConst("c");
BoolExpr d = ctx.MkBoolConst("d");
BoolExpr e = ctx.MkBoolConst("e");
BoolExpr f = ctx.MkBoolConst("f");
BoolExpr g = ctx.MkBoolConst("g");
BoolExpr z = ctx.MkBoolConst("z");
Console.WriteLine("Check 1");
InstallCheck(ctx, new BoolExpr[] {
DependsOn(ctx, a, new BoolExpr[] { b, c, z }),
DependsOn(ctx, b, new BoolExpr[] { d }),
DependsOn(ctx, c, new BoolExpr[] { ctx.MkOr(d, e), ctx.MkOr(f, g) }),
Conflict(ctx, d, e),
Conflict(ctx, d, g),
a, z });
Console.WriteLine("Check 2");
InstallCheck(ctx, new BoolExpr[] {
DependsOn(ctx, a, new BoolExpr[] { b, c, z }),
DependsOn(ctx, b, new BoolExpr[] { d }),
DependsOn(ctx, c, new BoolExpr[] { ctx.MkOr(d, e), ctx.MkOr(f, g) }),
Conflict(ctx, d, e),
Conflict(ctx, d, g),
a, z, g });
}
}
示例5: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "AUTO_CONFIG", "true" } };
using (Context ctx = new Context(cfg))
{
BoolExpr a = ctx.MkBoolConst("a");
BoolExpr b = ctx.MkBoolConst("b");
BoolExpr c = ctx.MkBoolConst("c");
BoolExpr d = ctx.MkBoolConst("d");
BoolExpr e = ctx.MkBoolConst("e");
BoolExpr f = ctx.MkBoolConst("f");
BoolExpr g = ctx.MkBoolConst("g");
BoolExpr z = ctx.MkBoolConst("z");
Solver s = ctx.MkSolver();
s.Assert(DependsOn(ctx, a, new BoolExpr[] { b, c, z }));
s.Assert(DependsOn(ctx, b, new BoolExpr[] { d }));
s.Assert(DependsOn(ctx, c, new BoolExpr[] { ctx.MkOr(d, e), ctx.MkOr(f, g) }));
s.Assert(Conflict(ctx, d, e));
s.Assert(a);
s.Assert(z);
Console.WriteLine(s.Check());
Console.WriteLine(s.Model);
}
}
示例6: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "AUTO_CONFIG", "true" } };
using (Context ctx = new Context(cfg))
{
IntExpr[] X = new IntExpr[5];
for (uint i = 0; i < 5; i++)
X[i] = ctx.MkIntConst(string.Format("x_{0}", i));
RealExpr[] Y = new RealExpr[5];
for (uint i = 0; i < 5; i++)
Y[i] = ctx.MkRealConst(string.Format("y_{0}", i));
BoolExpr[] P = new BoolExpr[5];
for (uint i = 0; i < 5; i++)
P[i] = ctx.MkBoolConst(string.Format("p_{0}", i));
foreach (Expr x in X)
Console.WriteLine(x);
foreach (Expr x in Y)
Console.WriteLine(x);
foreach (Expr x in P)
Console.WriteLine(x);
foreach (ArithExpr y in Y)
Console.WriteLine(ctx.MkPower(y, ctx.MkReal(2)));
ArithExpr[] Yp = new ArithExpr[Y.Length];
for (uint i = 0; i < Y.Length; i++)
Yp[i] = ctx.MkPower(Y[i], ctx.MkReal(2));
Console.WriteLine(ctx.MkAdd(Yp));
}
}
示例7: 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));
}
}
示例8: Run
public void Run()
{
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "AUTO_CONFIG", "true" },
{ "PROOF_MODE", "2" } };
using (Context ctx = new Context(cfg))
{
BoolExpr p = ctx.MkBoolConst("p");
Solver s = ctx.MkSolver();
s.Assert(p);
s.Assert(ctx.MkNot(p));
Console.WriteLine(s.Check());
Console.WriteLine(s.Proof);
}
}
示例9: UnsatCoreAndProofExample2
/// <summary>
/// Extract unsatisfiable core example with AssertAndTrack
/// </summary>
public static void UnsatCoreAndProofExample2(Context ctx)
{
Console.WriteLine("UnsatCoreAndProofExample2");
Solver solver = ctx.MkSolver();
BoolExpr pa = ctx.MkBoolConst("PredA");
BoolExpr pb = ctx.MkBoolConst("PredB");
BoolExpr pc = ctx.MkBoolConst("PredC");
BoolExpr pd = ctx.MkBoolConst("PredD");
BoolExpr f1 = ctx.MkAnd(new BoolExpr[] { pa, pb, pc });
BoolExpr f2 = ctx.MkAnd(new BoolExpr[] { pa, ctx.MkNot(pb), pc });
BoolExpr f3 = ctx.MkOr(ctx.MkNot(pa), ctx.MkNot(pc));
BoolExpr f4 = pd;
BoolExpr p1 = ctx.MkBoolConst("P1");
BoolExpr p2 = ctx.MkBoolConst("P2");
BoolExpr p3 = ctx.MkBoolConst("P3");
BoolExpr p4 = ctx.MkBoolConst("P4");
solver.AssertAndTrack(f1, p1);
solver.AssertAndTrack(f2, p2);
solver.AssertAndTrack(f3, p3);
solver.AssertAndTrack(f4, p4);
Status result = solver.Check();
if (result == Status.UNSATISFIABLE)
{
Console.WriteLine("unsat");
Console.WriteLine("core: ");
foreach (Expr c in solver.UnsatCore)
{
Console.WriteLine("{0}", c);
}
}
}
示例10: FindModelExample1
/// <summary>
/// Find a model for <code>x xor y</code>.
/// </summary>
public static void FindModelExample1(Context ctx)
{
Console.WriteLine("FindModelExample1");
BoolExpr x = ctx.MkBoolConst("x");
BoolExpr y = ctx.MkBoolConst("y");
BoolExpr x_xor_y = ctx.MkXor(x, y);
Model model = Check(ctx, x_xor_y, Status.SATISFIABLE);
Console.WriteLine("x = {0}, y = {1}",
model.Evaluate(x),
model.Evaluate(y));
}
示例11: Run
public void Run()
{
using (Context ctx = new Context())
{
RealExpr x = ctx.MkRealConst("x");
RealExpr y = ctx.MkRealConst("y");
RealExpr z = ctx.MkRealConst("z");
IntExpr a = ctx.MkIntConst("a");
IntExpr b = ctx.MkIntConst("b");
IntExpr c = ctx.MkIntConst("c");
ctx.UpdateParamValue(":pp-flat-assoc", "false");
Console.WriteLine(ctx.MkAdd(x, y, ctx.MkInt2Real(a)));
Console.WriteLine(ctx.MkAdd(x, ctx.MkReal(1)));
Console.WriteLine(ctx.MkAdd(ctx.MkReal(2), y));
Console.WriteLine(ctx.MkMul(x, y));
Console.WriteLine(ctx.MkAdd(ctx.MkInt(2), ctx.MkInt(3)));
Console.WriteLine(ctx.MkMul(ctx.MkReal(2), x));
Console.WriteLine(ctx.MkAdd(ctx.MkInt2Real((IntExpr)ctx.MkAdd(ctx.MkInt(2), ctx.MkInt(3))), x));
Console.WriteLine(ctx.MkAdd((RealExpr)ctx.MkInt2Real((IntExpr)ctx.MkAdd(ctx.MkInt(2), ctx.MkInt(3))).Simplify(), x));
Console.WriteLine(ctx.MkAdd(a, b, ctx.MkInt(1)));
Console.WriteLine(ctx.MkDiv(x, y));
Console.WriteLine(ctx.MkDiv(x, ctx.MkReal(2)));
Console.WriteLine(ctx.MkDiv(ctx.MkReal(2), y));
Console.WriteLine(ctx.MkDiv(a, ctx.MkInt(2)));
Console.WriteLine(ctx.MkDiv(ctx.MkAdd(a, b), ctx.MkInt(2)));
Console.WriteLine(ctx.MkDiv(ctx.MkInt(3), a));
Console.WriteLine(ctx.MkMod(a, b));
Console.WriteLine(ctx.MkMod(a, ctx.MkInt(2)));
Console.WriteLine(ctx.MkMod(ctx.MkInt(3), a));
Console.WriteLine(ctx.MkSub(a, ctx.MkInt(2)));
Console.WriteLine(ctx.MkUnaryMinus(a));
Console.WriteLine(ctx.MkUnaryMinus(x));
Console.WriteLine(ctx.MkSub(a, b));
Console.WriteLine(a.IsAdd);
Console.WriteLine(ctx.MkAdd(a, b).IsAdd);
Console.WriteLine(ctx.MkSub(a, b).IsAdd);
Console.WriteLine(ctx.MkInt(10).IsAdd);
Console.WriteLine(ctx.MkMul(a, b).IsMul);
Console.WriteLine(ctx.MkMul(x, ctx.MkInt2Real(b)).IsMul);
Console.WriteLine(ctx.MkAdd(a, b).IsMul);
Console.WriteLine(ctx.MkDiv(a, ctx.MkInt(2)).IsDiv);
Console.WriteLine(ctx.MkDiv(ctx.MkReal(3), x).IsDiv);
Console.WriteLine(ctx.MkDiv(x,y).IsDiv);
Console.WriteLine(ctx.MkDiv(a, ctx.MkInt(2)).IsIDiv);
Console.WriteLine(ctx.MkAdd(ctx.MkInt(2), ctx.MkInt(3)).Simplify().IsAdd);
Console.WriteLine();
Console.WriteLine(a is ArithExpr);
Console.WriteLine(ctx.MkInt(2) is ArithExpr);
Console.WriteLine(ctx.MkAdd(a, b) is ArithExpr);
Console.WriteLine(ctx.MkBoolConst("p") is ArithExpr);
Console.WriteLine(ctx.MkInt(2) is IntNum);
Console.WriteLine(ctx.MkInt(2) is RatNum);
Console.WriteLine(ctx.MkReal(2, 3));
Console.WriteLine(ctx.MkReal(2, 3).IsReal);
Console.WriteLine(ctx.MkReal(2, 3) is ArithExpr);
Console.WriteLine(ctx.MkReal(2, 3).IsConst);
Console.WriteLine(ctx.MkReal(2, 3).Simplify() is RatNum);
Console.WriteLine(ctx.MkReal(2, 3).Simplify().IsRatNum);
Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)).Simplify().IsAlgebraicNumber);
Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)).Simplify() is AlgebraicNum);
Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)).IsAlgebraicNumber);
Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)) is AlgebraicNum);
Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 2)));
Console.WriteLine(ctx.MkPower(ctx.MkReal(2), ctx.MkReal(1, 3)));
}
}
示例12: UnsatCoreAndProofExample
/// <summary>
/// Extract unsatisfiable core example
/// </summary>
public static void UnsatCoreAndProofExample()
{
Console.WriteLine("UnsatCoreAndProofExample");
Dictionary<string, string> cfg = new Dictionary<string, string>() { { "PROOF_MODE", "2" } };
using (Context ctx = new Context(cfg))
{
Solver solver = ctx.MkSolver();
BoolExpr pa = ctx.MkBoolConst("PredA");
BoolExpr pb = ctx.MkBoolConst("PredB");
BoolExpr pc = ctx.MkBoolConst("PredC");
BoolExpr pd = ctx.MkBoolConst("PredD");
BoolExpr p1 = ctx.MkBoolConst("P1");
BoolExpr p2 = ctx.MkBoolConst("P2");
BoolExpr p3 = ctx.MkBoolConst("P3");
BoolExpr p4 = ctx.MkBoolConst("P4");
BoolExpr[] assumptions = new BoolExpr[] { ctx.MkNot(p1), ctx.MkNot(p2), ctx.MkNot(p3), ctx.MkNot(p4) };
BoolExpr f1 = ctx.MkAnd(new BoolExpr[] { pa, pb, pc });
BoolExpr f2 = ctx.MkAnd(new BoolExpr[] { pa, ctx.MkNot(pb), pc });
BoolExpr f3 = ctx.MkOr(ctx.MkNot(pa), ctx.MkNot(pc));
BoolExpr f4 = pd;
solver.Assert(ctx.MkOr(f1, p1));
solver.Assert(ctx.MkOr(f2, p2));
solver.Assert(ctx.MkOr(f3, p3));
solver.Assert(ctx.MkOr(f4, p4));
Status result = solver.Check(assumptions);
if (result == Status.UNSATISFIABLE)
{
Console.WriteLine("unsat");
Console.WriteLine("proof: {0}", solver.Proof);
Console.WriteLine("core: ");
foreach (Expr c in solver.UnsatCore)
{
Console.WriteLine("{0}", c);
}
}
}
}
示例13: Solve
internal ObjectTheoremResult Solve()
{
var settings = new Dictionary<string, string> {
{ "model", "true" },
{ "unsat_core", "true" }
};
using (var context = new Context(settings))
{
var stopwatch = Stopwatch.StartNew();
Environment environment = GenerateEnvironment(context);
BoolExpr[] assertions = GenerateConstraints(context, environment, _assertions);
BoolExpr[] allAssertions = GenerateAllConstraints(context, environment, _allAssertions);
Solver solver = context.MkSimpleSolver();
int assertionCount = 0;
foreach (var assertion in assertions.Concat(allAssertions))
{
assertionCount++;
solver.Assert(assertion);
}
int assumptionCount = 0;
var assumptions = new Dictionary<LambdaExpression, BoolExpr>();
foreach (var assumption in _assumptions)
{
var generator = new LambdaExpressionToConstraintGenerator(context, environment);
var assumptionExpr = generator.Visit(assumption);
var assumptionCheck = context.MkBoolConst(Guid.NewGuid().ToString());
solver.Assert(context.MkEq(assumptionExpr, assumptionCheck));
assumptionCount++;
assumptions.Add(assumption, assumptionCheck);
}
stopwatch.Stop();
var constraintGenerationTimeSpan = stopwatch.Elapsed;
var solverString = solver.ToString();
var totalConstraintsCount = solverString.Split('\n').Count(l => l.StartsWith(" ("));
Trace.WriteLine("Statistics:");
Trace.WriteLine("assertionCount: " + assertionCount);
Trace.WriteLine("assumptionCount: " + assumptionCount);
Trace.WriteLine("totalConstraintsCount: " + totalConstraintsCount);
Trace.WriteLine("constraintGenerationTimeSpan: " + constraintGenerationTimeSpan);
var classCount = environment.Types.Count(t => !t.Key.IsValueType && t.Key.Name != "String");
var propertyCount = environment.Types
.Where(t => !t.Key.IsValueType && t.Key.Name != "String")
.Select(p => p.Key.GetProperties())
.Count();
stopwatch.Restart();
Microsoft.Z3.Status status = solver.Check(assumptions.Values.ToArray());
stopwatch.Stop();
var solvingTimeSpan = stopwatch.Elapsed;
Trace.WriteLine("solvingTimeSpan: " + solvingTimeSpan);
if (status != Microsoft.Z3.Status.SATISFIABLE)
{
if (solver.UnsatCore.Length > 0)
{
var result = new ObjectTheoremResult(context, environment, solver, status);
result.SetUnsatCore(assumptions, solver.UnsatCore);
return result;
}
return null;
}
var modelString = solver.Model.ToString();
return new ObjectTheoremResult(context, environment, solver, status);
}
}