public Node(Z3_decl_kind type, List <Node> children, Expr expr, Context ctx) { _id = _idCounter; _idCounter++; Expr = expr; Children = children; Type = type; Ctx = ctx; }
bool IsInfixOperator(Z3_decl_kind declKind) { return (declKind == Z3_decl_kind.Z3_OP_OR || declKind == Z3_decl_kind.Z3_OP_AND || declKind == Z3_decl_kind.Z3_OP_UGT || declKind == Z3_decl_kind.Z3_OP_UGEQ || declKind == Z3_decl_kind.Z3_OP_ULEQ || declKind == Z3_decl_kind.Z3_OP_ULT || declKind == Z3_decl_kind.Z3_OP_EQ || declKind == Z3_decl_kind.Z3_OP_ADD || declKind == Z3_decl_kind.Z3_OP_SUB || declKind == Z3_decl_kind.Z3_OP_MUL || declKind == Z3_decl_kind.Z3_OP_BADD || declKind == Z3_decl_kind.Z3_OP_BSUB || declKind == Z3_decl_kind.Z3_OP_BMUL || declKind == Z3_decl_kind.Z3_OP_BAND || declKind == Z3_decl_kind.Z3_OP_BOR || declKind == Z3_decl_kind.Z3_OP_BUDIV || declKind == Z3_decl_kind.Z3_OP_BUREM || declKind == Z3_decl_kind.Z3_OP_DIV || declKind == Z3_decl_kind.Z3_OP_REM || declKind == Z3_decl_kind.Z3_OP_BLSHR || declKind == Z3_decl_kind.Z3_OP_BSHL); }
bool IsDisjOrConj(Z3_decl_kind declKind) { return (declKind == Z3_decl_kind.Z3_OP_OR || declKind == Z3_decl_kind.Z3_OP_AND); }
bool IsBitDisjOrConj(Z3_decl_kind declKind) { return (declKind == Z3_decl_kind.Z3_OP_BOR || declKind == Z3_decl_kind.Z3_OP_BAND); }
string DescribeInfixOperator(Z3_decl_kind declKind) { switch (declKind) { case Z3_decl_kind.Z3_OP_OR: return "||"; case Z3_decl_kind.Z3_OP_AND: return "&&"; case Z3_decl_kind.Z3_OP_GT: case Z3_decl_kind.Z3_OP_UGT: return ">"; case Z3_decl_kind.Z3_OP_LT: case Z3_decl_kind.Z3_OP_ULT: return "<"; case Z3_decl_kind.Z3_OP_LE: case Z3_decl_kind.Z3_OP_ULEQ: return "<="; case Z3_decl_kind.Z3_OP_GE: case Z3_decl_kind.Z3_OP_UGEQ: return ">="; case Z3_decl_kind.Z3_OP_EQ: return "=="; case Z3_decl_kind.Z3_OP_ADD: return "+"; case Z3_decl_kind.Z3_OP_SUB: return "-"; case Z3_decl_kind.Z3_OP_MUL: return "*"; case Z3_decl_kind.Z3_OP_BADD: return "+"; case Z3_decl_kind.Z3_OP_BSUB: return "-"; case Z3_decl_kind.Z3_OP_BMUL: return "*"; case Z3_decl_kind.Z3_OP_BAND: return "&"; case Z3_decl_kind.Z3_OP_BOR: return "|"; case Z3_decl_kind.Z3_OP_BUDIV: return "/"; case Z3_decl_kind.Z3_OP_BUREM: return "%"; case Z3_decl_kind.Z3_OP_DIV: return "/"; case Z3_decl_kind.Z3_OP_REM: return "%"; case Z3_decl_kind.Z3_OP_BLSHR: return ">>"; case Z3_decl_kind.Z3_OP_BSHL: return "<<"; default: throw new AutomataException(AutomataExceptionKind.UnspecifiedOperatorDeclarationKind); } }
/** * Compute the symbolic successors from a given symbolic formula over the system variables * * From formula \phi(q) : Post(\phi(q)) = \exists q . T(q, q') and \phi(q) */ public List <Expr> symbolicSuccessors(Expr prestate) { List <Expr> succs = new List <Expr>(); foreach (Location la in this._cha.Locations) { foreach (Transition t in la.Transitions) { // todo: just want to do this over the concrete system? // todo: make sure we add the successor states due to discrete location changes to the terms... Expr ts; List <Expr> rel = new List <Expr>(); rel.Add(prestate); // add the control location prestate from this location rel.Add(Controller.Instance.Z3.MkEq(Controller.Instance.Q["i"], Controller.Instance.Z3.MkInt(la.Value))); rel.Add(t.ToTerm()); // add the control location post-state due to this transition if (t.Guard != null) { List <Expr> allj = new List <Expr>(); allj.Add(Controller.Instance.Indices["j"]); Expr g = Controller.Instance.Z3.MkAnd(Controller.Instance.Z3.MkNot(Controller.Instance.Z3.MkEq(Controller.Instance.Indices["i"], Controller.Instance.Indices["j"])), t.Guard); g = Controller.Instance.Z3.MkForall(allj.ToArray(), g); rel.Add(g); } if (t.Reset != null) { rel.Add(t.Reset); } ts = Controller.Instance.Z3.MkAnd((BoolExpr[])rel.ToArray()); //ts = Controller.Instance.Z3.Simplify(ts); //Pattern[] pats = new Pattern[] { Controller.Instance.Z3.MkPattern(new Term[] { Controller.Instance.Indices["j"] }) }; List <Pattern> pats = new List <Pattern>(); List <String> names = new List <String>(); List <Sort> sorts = new List <Sort>(); // todo: change this and next loop to: foreach variable, extract type, add sort quantifier. foreach (var pair in Controller.Instance.Q) { //pats.Add(Controller.Instance.Z3.MkPattern(new Term[] { pair.Value })); //bound.Add(pair.Value); //names.Add(pair.Key); names.Add("q"); FuncDecl d = pair.Value.FuncDecl; Symbol dn = d.Name; Z3_decl_kind dk = d.DeclKind; //sorts.Add(pair.Value.GetSort()); //TODO: Sort s = Controller.Instance.Z3.MkSort("(Int) " + pair.Value.GetSort().ToString()); // function sort: maps process indices to location type //sorts.Add(s); //sorts.Add(Controller.Instance.Z3.MkArraySort(Controller.Instance.IntType, Controller.Instance.RealType)); break; } foreach (var pair in Controller.Instance.IndexedVariables) { //pats.Add(Controller.Instance.Z3.MkPattern(new Term[] { pair.Value })); //names.Add(pair.Key); names.Add(pair.Key.Key); //sorts.Add(pair.Value.GetSort()); //TODO: Sort s = Controller.Instance.Z3.MkSort("(Int) " + pair.Value.GetSort().ToString()); // function sort: maps process indices to variable type // todo: add hash table to look up variable types //sorts.Add(s); break; } //TODO: ts = Controller.Instance.Z3.MkExists(sorts.ToArray(), names.ToArray(), ts); List <Expr> bound = new List <Expr>(); foreach (var pair in Controller.Instance.Indices) { //pats.Add(Controller.Instance.Z3.MkPattern(new Term[] { pair.Value })); bound.Add(pair.Value); } ts = Controller.Instance.Z3.MkExists(bound.ToArray(), ts); //TODO: ts = Controller.Instance.Z3.Simplify(ts); // unprime all variables foreach (var pair in Controller.Instance.QPrimed) { Controller.Instance.Z3.replaceTerm(ref ts, ts, pair.Value, Controller.Instance.Q[pair.Key], true); } foreach (var pair in Controller.Instance.IndexedVariablesPrimed) { Controller.Instance.Z3.replaceTerm(ref ts, ts, pair.Value, Controller.Instance.IndexedVariables[new KeyValuePair <String, String>(pair.Key.Key.Replace("'", ""), pair.Key.Value)], true); } //ts = Controller.Instance.Z3.Simplify(ts); succs.Add(ts); } //} } return(succs); }