本文整理汇总了C#中Z3Provider类的典型用法代码示例。如果您正苦于以下问题:C# Z3Provider类的具体用法?C# Z3Provider怎么用?C# Z3Provider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Z3Provider类属于命名空间,在下文中一共展示了Z3Provider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBitvectorOps
public void TestBitvectorOps()
{
string noop = @"
program noop(w) {
return iter(c in w) {
case (c <= 0xFF):
yield((((c >> 4) & 0xF) << 4)|(c & 0xF));
case (true):
yield(c);
};
}
";
string triv = @"
program triv(w) {
return iter(c in w) {
case (true):
yield(c);
};
}
";
var solver = new Z3Provider();
var A = BekConverter.BekToST(solver, noop);
var B = BekConverter.BekToST(solver, triv);
bool equiv = A.Eq1(B);
Assert.IsTrue(equiv);
//A.ShowGraph();
}
示例2: getAutomata
public Automaton<Expr> getAutomata(Z3Provider z3p, Expr universe, Expr var, Sort sort)
{ //Sort for pairs (input theory, BV)
var bv = z3p.Z3.MkBitVecSort(BVConst.BVSIZE);
var pairSort = z3p.MkTupleSort(sort, bv);
var dfapair = this.Normalize().PushQuantifiers().getAutomata(z3p, new List<string>(), universe, var, sort);
//Compute the new moves by dropping the last bit of every element in the phiMoves
var newMoves = Automaton<Expr>.Empty.GetMoves().ToList();
foreach (var oldMove in dfapair.GetMoves())
{
var oldCond = oldMove.Label;
//Compute the new condition as ()
Expr newCond = oldCond;
//Update the new set of moves
newMoves.Add(new Move<Expr>(oldMove.SourceState, oldMove.TargetState, newCond));
}
//Build the new dfa with the new moves
var automaton = Automaton<Expr>.Create(dfapair.InitialState, dfapair.GetFinalStates(), newMoves);
return automaton.Determinize(z3p).Minimize(z3p);
}
示例3: RunTestForGivenSize
private static void RunTestForGivenSize(int K)
{
Console.WriteLine(K);
Z3Provider Z = new Z3Provider();
var A = (Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "zero", "two" }, new int[] { 0, 2 }));
Func<int, Expr> beta = (i => Z.MkEq(Z.MkInt(1), Z.MkMod(Z.MkDiv(A.AttrVar, Z.MkInt(1 << (i%32))), Z.MkInt(2))));
Expr e1 = Z.MkEq(Z.MkInt(1), A.AttrVar);
Expr e2 = Z.MkEq(Z.MkInt(2), A.AttrVar);
Expr e3 = Z.MkEq(Z.MkInt(3), A.AttrVar);
var r1 = Z.TT.MkTreeAcceptorRule(A, 0, "zero", e1);
var r2 = Z.TT.MkTreeAcceptorRule(A, 1, "zero", e2);
var r3 = Z.TT.MkTreeAcceptorRule(A, 2, "zero", e3);
var rules = new List<TreeRule>();
rules.Add(r1);
rules.Add(r2);
rules.Add(r3);
for (int i = 0; i < K; i++)
{
rules.Add(Z.TT.MkTreeAcceptorRule(A, 3 * i + 3, "two", beta(i), 3 * i, 3 * i + 2));
rules.Add(Z.TT.MkTreeAcceptorRule(A, 3 * i + 4, "two", beta(i), 3 * i + 1, 3 * i + 2));
rules.Add(Z.TT.MkTreeAcceptorRule(A, 3 * i + 5, "two", beta(i), 3 * i + 2, 3 * i + 2));
}
var T = Z.TT.MkTreeAutomaton(new int[] { 3 * K , 3 * K +1 }, A, A, rules);
var comp = T.Complete();
Util.RunAllAlgorithms(T, comp, K.ToString(), Program.largeAlphabetFile);
}
示例4: HexProjTest2
public void HexProjTest2()
{
Z3Provider z3p = new Z3Provider();
Sort bv64 = z3p.MkBitVecSort(64);
Sort bv16 = z3p.MkBitVecSort(16);
Expr _0x654321 = z3p.MkNumeral((uint)0xF54321, bv64);
Expr _6 = z3p.MkHexProj(5, _0x654321, bv16).Simplify();
Expr _5 = z3p.MkHexProj(4, _0x654321, bv16).Simplify();
Expr _4 = z3p.MkHexProj(3, _0x654321, bv16).Simplify();
Expr _3 = z3p.MkHexProj(2, _0x654321, bv16).Simplify();
Expr _2 = z3p.MkHexProj(1, _0x654321, bv16).Simplify();
Expr _1 = z3p.MkHexProj(0, _0x654321, bv16).Simplify();
int _6v = (int)z3p.GetNumeralInt(_6);
int _5v = (int)z3p.GetNumeralInt(_5);
int _4v = (int)z3p.GetNumeralInt(_4);
int _3v = (int)z3p.GetNumeralInt(_3);
int _2v = (int)z3p.GetNumeralInt(_2);
int _1v = (int)z3p.GetNumeralInt(_1);
Assert.AreEqual<int>(0xF, _6v);
Assert.AreEqual<int>(5, _5v);
Assert.AreEqual<int>(4, _4v);
Assert.AreEqual<int>(3, _3v);
Assert.AreEqual<int>(2, _2v);
Assert.AreEqual<int>(1, _1v);
}
示例5: 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);
}
示例6: DecodeDecode
// [TestMethod]
public void DecodeDecode()
{
Z3Provider solver = new Z3Provider();
var A = BekConverter.BekToSTb(solver, BekConverter.BekFileToBekProgram(sampleDir + "bek/Base64decode.bek")).ExploreBools().ToST();
var ID = ST<FuncDecl, Expr, Sort>.MkId(solver, solver.CharSort);
var st = A.Compose(A);
//st.ShowGraph();
var sfa1 = st.ToSFA().Automaton;
var sfa = ConvertToAutomatonOverBvSet(solver, sfa1).Determinize().MinimizeHopcroft();
//solver.CharSetProvider.ShowGraph(sfa, "test");
}
示例7: EmptyTupleTest
public void EmptyTupleTest()
{
Z3Provider Z = new Z3Provider();
Sort sort = Z.MkTupleSort();
Expr unit = Z.MkTuple();
Expr t = Z.MkVar(0, sort);
Expr t_eq_unit = Z.MkEq(t, unit);
var v = new List<IValue<Expr>>(Z.MainSolver.FindAllMembers(t_eq_unit));
Assert.IsTrue(v.Count == 1);
Assert.AreEqual(unit, v[0].Value);
}
示例8: TestCreationOfTwoAlphabets1
public void TestCreationOfTwoAlphabets1()
{
Z3Provider Z = new Z3Provider();
var A = Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "zero", "one", "two" }, new int[] { 0, 1, 2 });
var B = Z.TT.MkRankedAlphabet("B", Z.IntSort, new string[] { "zero", "one", "two" }, new int[] { 0, 1, 2 });
Assert.IsTrue(A.ContainsConstructor("two"));
Assert.IsTrue(B.ContainsConstructor("two"));
var twoA = A.GetConstructor("two");
var twoB = B.GetConstructor("two");
Assert.AreNotEqual<FuncDecl>(twoA, twoB);
Assert.AreEqual<string>("two", twoA.Name.ToString());
Assert.AreEqual<string>("two", twoB.Name.ToString());
}
示例9: ZeroOneTwoAlphabetTest2
public void ZeroOneTwoAlphabetTest2()
{
Z3Provider z3p = new Z3Provider();
try
{ //number of ranks is wrong
var A = z3p.TT.MkRankedAlphabet("A", z3p.IntSort, new string[] { "zero", "one", "two" }, new int[] { 0, 1 });
Assert.IsTrue(false, "expecting exception RankedAlphabet_IsInvalid");
}
catch (AutomataException e)
{
Assert.IsTrue(AutomataExceptionKind.RankedAlphabet_IsInvalid == e.kind);
}
}
示例10: TestCreationOfTwoAlphabets2
public void TestCreationOfTwoAlphabets2()
{
try
{
Z3Provider Z = new Z3Provider();
var A = Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "zero", "one", "two" }, new int[] { 0, 1, 2 });
var B = Z.TT.MkRankedAlphabet("A", Z.IntSort, new string[] { "zero", "two" }, new int[] { 0, 1 });
Assert.IsTrue(false, "expecting exception RankedAlphabet_IsAlreadyDefined");
}
catch (AutomataException e)
{
Assert.IsTrue(e.kind == AutomataExceptionKind.RankedAlphabet_IsAlreadyDefined);
}
}
示例11: TestBase64Decode
public void TestBase64Decode()
{
Z3Provider solver = new Z3Provider();
var bek = BekConverter.BekFileToBekProgram(sampleDir + "bek/Base64decode.bek");
var st = BekConverter.BekToSTb(solver, bek).ExploreBools().ToST();
st.Simplify();
//st.ShowGraph();
var st0 = st.RestrictDomain(@"^([AB]{3})*$");
//st0.ShowGraph();
var st1 = st0.Explore();
//st1.Simplify();
//st1.ShowGraph();
//st.ToDot("c:/tmp/b64d.dot");
var sft = st.Explore();
var Q = sft.StateCount;
int M = 0;
int F = 0;
int tot = 0;
var tmp = new Dictionary<Expr, int>();
foreach (var m in sft.GetMoves())
{
if (m.Label.IsFinal)
{
F += 1;
tot += 1;
}
else
{
M += 1;
int k = 0;
if (tmp.TryGetValue(m.Label.Guard, out k))
tot += k;
else
{
foreach (var v in solver.MainSolver.FindAllMembers(m.Label.Guard))
k += 1;
tot += k;
tmp[m.Label.Guard] = k;
}
}
}
Console.WriteLine(tot);
Assert.AreEqual<int>(87, Q);
}
示例12: FuncDeclTest3
public void FuncDeclTest3()
{
try
{
Z3Provider Z = new Z3Provider();
Z.MainSolver.Push();
FuncDecl f = Z.MkFuncDecl("temp", Z.IntSort, Z.IntSort);
Z.MainSolver.Push();
Z.MainSolver.Push();
Z.MainSolver.Pop();
Z.MainSolver.Pop();
FuncDecl g = Z.MkFuncDecl("temp", Z.IntSort, Z.IntSort);
Z.MainSolver.Push();
Z.MainSolver.Pop();
}
catch (AutomataException e)
{
Assert.AreEqual(e.kind, AutomataExceptionKind.FunctionIsAlreadyDeclared);
}
}
示例13: Test_aaa2b_Keep
public void Test_aaa2b_Keep()
{
string bek = @"
program a2b(_){
replace {
""aaa"" ==> [#1 + 1];
else ==> [#0];
}
}";
Z3Provider solver = new Z3Provider();
var st = BekConverter.BekToSTb(solver, bek).ToST();
//st.ShowGraph();
var st1 = st.ExploreBools();
//st1.ShowGraph();
var stb = st1.ToSTb();
//stb.ShowGraph();
var meth = stb.Compile();
var res = meth.Apply("ac_aaaaGGhh");
Assert.AreEqual<string>("ac_baGGhh", res);
}
示例14: Const
public Const(ConstDef def, FastTransducerInstance fti, Z3Provider z3p)
{
this.z3p = z3p;
this.name = def.id.text;
switch (def.sort.kind)
{
case (FastSortKind.Real):
{
sort = z3p.RealSort;
break;
}
case (FastSortKind.Bool):
{
sort = z3p.BoolSort;
break;
}
case (FastSortKind.Int):
{
sort = z3p.IntSort;
break;
}
case (FastSortKind.String):
{
sort = z3p.MkListSort(z3p.CharSort);
break;
}
case (FastSortKind.Tree):
{
foreach (var enumSort in fti.enums)
{
if (enumSort.name == def.sort.name.text)
{
sort = enumSort.sort;
break;
}
}
break;
}
}
this.value = GenerateZ3ExprFromExpr(def.expr, fti).Simplify();
}
示例15: TestCssEncode4eq5
public void TestCssEncode4eq5()
{
var solver = new Z3Provider();
var stb5 = BekConverter.BekFileToSTb(solver, sampleDir + "bek/CssEncode5.bek");
var stb4 = BekConverter.BekFileToSTb(solver, sampleDir + "bek/CssEncode4.bek");
//stb5.ShowGraph(10);
var fst4 = stb4.ToST().Explore();
var fst5 = stb5.ToST().Explore();
var dom4 = fst4.ToSFA();
var dom5 = fst5.ToSFA();
bool dom4_subsetof_dom5 = dom4.IsSubsetOf(dom5);
//var tmp = dom4.Minus(dom5);
//tmp.ShowGraph();
//var member = new List<Expr>(tmp.ChoosePathToSomeFinalState()).ToArray();
//var str = new String(Array.ConvertAll(member, m => solver.GetCharValue(solver.FindOneMember(m).Value)));
bool dom5_subsetof_dom4 = dom5.IsSubsetOf(dom4);
bool partial_equiv = fst4.Eq1(fst5);
Assert.IsTrue(dom4_subsetof_dom5);
Assert.IsTrue(partial_equiv);
Assert.IsTrue(dom5_subsetof_dom4);
}