本文整理汇总了C#中Z3Provider.MkNeq方法的典型用法代码示例。如果您正苦于以下问题:C# Z3Provider.MkNeq方法的具体用法?C# Z3Provider.MkNeq怎么用?C# Z3Provider.MkNeq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Z3Provider
的用法示例。
在下文中一共展示了Z3Provider.MkNeq方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestUTF8Encode
//[TestMethod]
public void TestUTF8Encode()
{
Z3Provider solver = new Z3Provider();
var stb = BekConverter.BekFileToSTb(solver, sampleDir + "bek/UTF8Encode.bek");
var tmp = stb.ToST();
var sft = stb.Explore();
var sft1 = sft.ToST();
//sft.ShowGraph();
//sft1.SaveAsDot("C:/tmp/dot/utf8encode.dot");
#region data for the popl paper
var st = sft.ToST();
int n = st.StateCount;
var moves = new List<Move<Rule<Expr>>>(st.GetMoves());
moves.RemoveAll(x => x.Label.IsFinal);
int m = moves.Count;
int t = System.Environment.TickCount;
var st_o_st = st + st;
int n1 = st_o_st.StateCount;
var moves1 = new List<Move<Rule<Expr>>>(st_o_st.GetMoves());
moves1.RemoveAll(y => y.Label.IsFinal);
int m1 = moves1.Count;
bool diff = st.Eq1(st_o_st);
t = System.Environment.TickCount - t;
#endregion
var restr = sft.ToST().RestrictDomain(".+");
restr.AssertTheory();
Expr inputConst = solver.MkFreshConst("input", restr.InputListSort);
Expr outputConst = solver.MkFreshConst("output", restr.OutputListSort);
solver.MainSolver.Assert(restr.MkAccept(inputConst, outputConst));
//validate correctness for some values against the actual UTF8Encode
//TBD: validate also exceptional behavior, when the generated code throws an exception
//the builtin one must contain the character 0xFFFD
int K = 50;
for (int i = 0; i < K; i++)
{
var model = solver.MainSolver.GetModel(solver.True, inputConst, outputConst);
string input = model[inputConst].StringValue;
string output = model[outputConst].StringValue;
Assert.IsFalse(string.IsNullOrEmpty(input));
Assert.IsFalse(string.IsNullOrEmpty(output));
byte[] encoding = Encoding.UTF8.GetBytes(input);
char[] chars = Array.ConvertAll(encoding, b => (char)b);
string output_expected = new String(chars);
string output_generated = UTF8Encode_F.Apply(input);
string output_generated2 = UTF8Encode.Apply(input);
string output_generated3 = UTF8Encode_B.Apply(input);
Assert.AreEqual<string>(output_expected, output_generated);
Assert.AreEqual<string>(output_expected, output_generated2);
Assert.AreEqual<string>(output_expected, output_generated3);
Assert.AreEqual<string>(output_expected, output);
//exclude this solution, before picking the next one
solver.MainSolver.Assert(solver.MkNeq(inputConst, model[inputConst].Value));
}
}
示例2: TestCssEncode6
//[TestMethod]
public void TestCssEncode6()
{
var solver = new Z3Provider();
var st = BekConverter.BekFileToST(solver, sampleDir + "bek/CssEncode6.bek");
//st.STb.ShowGraph();
//st.STb.ExploreBools().ShowGraph();
var sft = st.Explore();
//sft.Simplify();
//sft.ShowGraph(20);
//just to get longer input strings
var restr = sft.RestrictDomain("^[^\0-\x32]{5,}$");
restr.AssertTheory();
Expr inputConst = solver.MkFreshConst("input", sft.InputListSort);
Expr outputConst = solver.MkFreshConst("output", sft.OutputListSort);
solver.MainSolver.Assert(restr.MkAccept(inputConst, outputConst));
int okCnt = 0;
int error0Cnt = 0;
int error1Cnt = 0;
//validate correctness for some values against the actual CssEncode
//validate also exceptional behavior
for (int i = 0; i < 10; i++)
{
var model = solver.MainSolver.GetModel(solver.True, inputConst, outputConst);
string input = model[inputConst].StringValue;
string output = model[outputConst].StringValue;
Assert.IsFalse(string.IsNullOrEmpty(output));
char lastChar = output[output.Length - 1];
//try
//{
var output_expected = System.Web.Security.AntiXss.AntiXssEncoder.CssEncode(input);
Assert.AreEqual<string>(output_expected, output);
okCnt += 1;
//}
//catch (Microsoft.Security.Application.InvalidSurrogatePairException)
//{
// Assert.AreEqual<char>('\0', lastChar);
// error0Cnt += 1;
//}
//catch (Microsoft.Security.Application.InvalidUnicodeValueException)
//{
// Assert.AreEqual<char>('\x01', lastChar);
// error1Cnt += 1;
//}
//exclude this solution, before picking the next one
solver.MainSolver.Assert(solver.MkNeq(inputConst, model[inputConst].Value));
}
Console.WriteLine(string.Format("okCnt={0}, error0Cnt={1}, error1Cnt={2}", okCnt, error0Cnt, error1Cnt));
}
示例3: TestCssEncode
//[TestMethod]
public void TestCssEncode()
{
var solver = new Z3Provider();
var st = BekConverter.BekFileToST(solver, "../../Samples/bek/CssEncode.bek");
var st1 = st;// st.ExploreBools();
//st1.Simplify();
//st1.ShowGraph(10);
var comp = st1 + st1;
//comp.Simplify();
//comp.ShowGraph(10);
//5 or more characters in the input
var restr = st1.RestrictDomain("^[^\0-\x32]{7,}$");
//restr.ShowGraph(10);
restr.AssertTheory();
comp.AssertTheory();
Expr inp = solver.MkFreshConst("inp", comp.InputListSort);
Expr out1 = solver.MkFreshConst("out1", comp.OutputListSort);
Expr out2 = solver.MkFreshConst("out2", comp.OutputListSort);
solver.MainSolver.Assert(restr.MkAccept(inp, out1));
solver.MainSolver.Assert(comp.MkAccept(inp, out2));
solver.MainSolver.Assert(solver.MkNeq(out1, out2));
//validate correctness for some values
for (int i = 0; i < 5; i++)
{
var model = solver.MainSolver.GetModel(solver.True, inp, out1, out2);
string input = model[inp].StringValue;
string output1 = model[out1].StringValue;
string output2 = model[out2].StringValue;
var output1_expected = System.Web.Security.AntiXss.AntiXssEncoder.CssEncode(input);
var output2_expected = System.Web.Security.AntiXss.AntiXssEncoder.CssEncode(output1_expected);
Assert.AreNotEqual(output1, output2);
Assert.AreEqual(output1_expected, output1);
Assert.AreEqual(output2_expected, output2);
solver.MainSolver.Assert(solver.MkNeq(inp, model[inp].Value));
}
}
示例4: TestCssEncode5
//[TestMethod]
public void TestCssEncode5()
{
var solver = new Z3Provider();
var stb = BekConverter.BekFileToSTb(solver, sampleDir + "bek/CssEncode5.bek");
//stb.Explore().ShowGraph();
var st = stb.ToST();
//st.ShowGraph(10);
var sft = st.Explore();
//sft.ShowGraph(10);
//just to get longer input strings
var restr = sft.RestrictDomain("(.){3,}$");
restr.Simplify();
//restr.ShowGraph(10);
restr.AssertTheory();
Expr inputConst = solver.MkFreshConst("input", sft.InputListSort);
Expr outputConst = solver.MkFreshConst("output", sft.OutputListSort);
solver.MainSolver.Assert(restr.MkAccept(inputConst, outputConst));
int okCnt = 0;
int error0Cnt = 0;
int error1Cnt = 0;
//validate correctness for some values against the actual CssEncode
//TBD: validate also exceptional behavior
int K = 10;
for (int i = 0; i < K; i++)
{
var model = solver.MainSolver.GetModel(solver.True, inputConst, outputConst);
string input = model[inputConst].StringValue;
string output = model[outputConst].StringValue;
Assert.IsFalse(string.IsNullOrEmpty(input));
Assert.IsFalse(string.IsNullOrEmpty(output));
if ((input != ""))
{
char lastChar = '\0'; //output[output.Length - 1];
try
{
var output_expected = System.Web.Security.AntiXss.AntiXssEncoder.CssEncode(input);
Assert.AreEqual<string>(output_expected, output);
okCnt += 1;
}
catch (Exception)
{
Assert.AreEqual<char>('\0', lastChar);
error0Cnt += 1;
}
}
//exclude this solution, before picking the next one
solver.MainSolver.Assert(solver.MkNeq(inputConst, model[inputConst].Value));
}
Assert.AreEqual(K, okCnt);
}
示例5: TupleTest
public void TupleTest()
{
Z3Provider z3p = new Z3Provider();
//create the tuple sort for mouth
FuncDecl mouth;
FuncDecl[] mouth_accessors;
var MOUTH = z3p.MkTupleSort("MOUTH", new string[] { "open", "teeth" }, new Sort[] { z3p.BoolSort, z3p.IntSort }, out mouth, out mouth_accessors);
Func<Expr,Expr,Expr> mk_mouth = ((o,t) => z3p.MkApp(mouth, o, t));
Func<Expr,Expr> get_open = (m => z3p.MkApp(mouth_accessors[0], m));
Func<Expr,Expr> get_teeth = (m => z3p.MkApp(mouth_accessors[1], m));
//create the tuple sort for nose
FuncDecl nose;
FuncDecl[] nose_accessors;
var NOSE = z3p.MkTupleSort("NOSE", new string[] { "size" }, new Sort[] { z3p.IntSort }, out nose, out nose_accessors);
Func<Expr,Expr> mk_nose = (s => z3p.MkApp(nose, s));
Func<Expr,Expr> get_size = (n => z3p.MkApp(nose_accessors[0], n));
//create the tuple sort for head
FuncDecl head;
FuncDecl[] head_accessors;
var HEAD = z3p.MkTupleSort("HEAD", new string[] { "bald", "nose", "mouth" }, new Sort[] { z3p.BoolSort, NOSE, MOUTH }, out head, out head_accessors);
Func<Expr,Expr,Expr,Expr> mk_head = ((b,n,m) => z3p.MkApp(head, b,n,m));
Func<Expr,Expr> get_bald = (h => z3p.MkApp(head_accessors[0], h));
Func<Expr,Expr> get_nose = (h => z3p.MkApp(head_accessors[1], h));
Func<Expr,Expr> get_mouth = (h => z3p.MkApp(head_accessors[2], h));
//------------------------
// create a transformation "punch" from HEAD tp HEAD that removes k teeth, k is the second parameter of the transformation
var punch = z3p.MkFuncDecl("punch", new Sort[]{HEAD, z3p.IntSort}, HEAD);
var x = z3p.MkVar(0, HEAD); // <-- this is the input HEAD
var y = z3p.MkVar(1, z3p.IntSort); // <-- this is the n parameter
//this is the actual transformation of x that removes one tooth
var new_mouth = mk_mouth(get_open(get_mouth(x)), z3p.MkSub(get_teeth(get_mouth(x)), y));
var old_nose = get_nose(x);
var old_bald = get_bald(x);
var punch_def = mk_head(old_bald, old_nose,new_mouth);
var punch_axiom = z3p.MkEqForall(z3p.MkApp(punch, x , y), punch_def, x, y);
Func<Expr,Expr,Expr> punch_app = ((h,k) => z3p.MkApp(punch, h,k));
z3p.MainSolver.Assert(punch_axiom);
//------------------------
// create a transformation "hit" from HEAD tp HEAD that doubles the size of the nose
var hit = z3p.MkFuncDecl("hit", HEAD, HEAD);
var hit_def = mk_head(get_bald(x), mk_nose(z3p.MkMul(z3p.MkInt(2),get_size(get_nose(x)))), get_mouth(x));
var hit_axiom = z3p.MkEqForall(z3p.MkApp(hit, x), hit_def, x);
Func<Expr,Expr> hit_app = (h => z3p.MkApp(hit, h));
z3p.MainSolver.Assert(hit_axiom);
//-------------------------------
// Analysis
var H = z3p.MkConst("H", HEAD);
var N = z3p.MkConst("N", z3p.IntSort);
// check that hit and punch commute
z3p.MainSolver.Push();
z3p.MainSolver.Assert(z3p.MkNeq(punch_app(hit_app(H), N), hit_app(punch_app(H, N))));
Status status = z3p.Check(); //here status must be UNSATISFIABLE
z3p.MainSolver.Pop(); //remove the temporary context
//check that hit is not idempotent
z3p.MainSolver.Push();
z3p.MainSolver.Assert(z3p.MkNeq(hit_app(hit_app(H)), hit_app(H)));
status = z3p.Check(); //here status must not be UNSATISFIABLE (it is UNKNOWN due to use of axioms)
var model1 = z3p.Z3S.Model;
var witness1 = model1.Evaluate(H, true); //a concrete instance of HEAD that shows when hitting twice is not the same as hitting once
z3p.MainSolver.Pop();
//but it is possible that hitting twice does no harm (when nose has size 0)
z3p.MainSolver.Push();
z3p.MainSolver.Assert(z3p.MkEq(hit_app(hit_app(H)), hit_app(H)));
status = z3p.Check();
var model2 = z3p.Z3S.Model;
var witness2 = model2.Evaluate(H, true);
z3p.MainSolver.Pop();
}