public SymElement(Term term, Z3Expr encoding, Z3Context context) { Contract.Requires(term != null && encoding != null && context != null); Term = term; Encoding = encoding; SideConstraints = new Map <int, Z3BoolExpr>(Compare); }
public TypeEmbedder( TermIndex index, Z3Context context, Map <BaseSortKind, uint> baseSortCosts) { Contract.Requires(index != null && context != null); Index = index; Context = context; //// Build base sorts Register(new RealEmbedding(this, baseSortCosts[BaseSortKind.Real])); Register(new IntegerEmbedding(this, baseSortCosts[BaseSortKind.Integer])); Register(new NaturalEmbedding(this, baseSortCosts[BaseSortKind.Natural])); Register(new PosIntegerEmbedding(this, baseSortCosts[BaseSortKind.PosInteger])); Register(new NegIntegerEmbedding(this, baseSortCosts[BaseSortKind.NegInteger])); Register(new StringEmbedding(this, baseSortCosts[BaseSortKind.String])); //// Build finite enumerations var sortToIndex = new Map <Term, Tuple <uint, UserSymbol> >(Term.Compare); MkEnumTypes(Index.SymbolTable.Root, sortToIndex); MkConUnnTypes(sortToIndex); SetDefaultValues(); RegisterEmbeddingAtoms(); }
public static Z3BVExpr Int2BV(this Z3IntExpr expr1, Z3Context context, uint size) { Contract.Requires(expr1 != null && context != null && size > 0); Z3IntExpr xj, pow; var xi = new Z3IntExpr[size]; var yi = new Z3BVExpr[size]; var zero = context.MkInt(0); var one = context.MkInt(1); var bvzero = context.MkBV(0, size); var bvone = context.MkBV(1, size); xi[size - 1] = expr1; for (int i = ((int)size) - 2; i >= 0; --i) { pow = context.MkInt(BigInteger.Pow(2, i + 1).ToString()); xj = xi[i + 1]; xi[i] = (Z3IntExpr)xj.Ge(context, pow).Ite(context, xj.Sub(context, pow), xj); } Z3BVExpr coercion = bvzero; for (int i = ((int)size) - 1; i >= 0; --i) { pow = context.MkInt(BigInteger.Pow(2, i).ToString()); coercion = (Z3BVExpr)xi[i].Ge(context, pow).Ite( context, context.MkBVAdd(context.MkBVSHL(coercion, bvone), bvone), context.MkBVSHL(coercion, bvone)); } Contract.Assert(coercion != null); return(coercion); }
/// <summary> /// Disjoins the current side constraint with constr /// </summary> /// <param name="constr"></param> /// <param name="context"></param> public void ExtendSideConstraint(int index, Z3BoolExpr constr, Z3Context context) { Z3BoolExpr crntConstr; if (SideConstraints.TryFindValue(index, out crntConstr)) { SideConstraints[index] = context.MkOr(crntConstr, constr); } else { SideConstraints.Add(index, constr); } }
public static Z3BoolExpr And(this Z3BoolExpr expr1, Z3Context context, Z3BoolExpr expr2) { if (expr1 == null) { return(expr2); } else if (expr2 == null) { return(expr1); } else { return(context.MkAnd(expr1, expr2)); } }
/// <summary> /// Fits a bit vector expression into a bit vector with size, /// either by truncating or zero padding. /// </summary> public static Z3BVExpr FitBV(this Z3BVExpr expr1, Z3Context context, uint size) { Contract.Requires(expr1 != null && context != null && size > 0); if (expr1.SortSize == size) { return(expr1); } else if (expr1.SortSize < size) { return(context.MkZeroExt(size - expr1.SortSize, expr1)); } else { return(context.MkExtract(size - 1, 0, expr1)); } }
public static Z3IntExpr BV2Int(this Z3BVExpr expr1, Z3Context context) { var size = expr1.SortSize; var parts = new Z3IntExpr[size]; var zero = context.MkInt(0); var bvzero = context.MkBV(0, 1); for (uint i = 0; i < size; ++i) { parts[i] = (Z3IntExpr)expr1.Index(context, i).Eq(context, bvzero).Ite( context, zero, context.MkInt(BigInteger.Pow(2, (int)i).ToString())); } return((Z3IntExpr)context.MkAdd(parts)); }
public static Z3BoolExpr IsEven(this Z3IntExpr expr1, Z3Context context) { Contract.Assert(expr1 != null); return(context.MkEq(context.MkRem(expr1, context.MkInt(2)), context.MkInt(0))); }
public static Z3ArithExpr Neg(this Z3ArithExpr expr1, Z3Context context) { Contract.Assert(expr1 != null); return(context.MkUnaryMinus(expr1)); }
public static Z3BoolExpr Not(this Z3BoolExpr expr1, Z3Context context) { Contract.Assert(expr1 != null); return(context.MkNot(expr1)); }
public static Z3BoolExpr Iff(this Z3BoolExpr expr1, Z3Context context, Z3BoolExpr expr2) { Contract.Assert(expr1 != null && expr2 != null); return(context.MkIff(expr1, expr2)); }
public static Z3BoolExpr NEq(this Z3Expr expr1, Z3Context context, Z3Expr expr2) { Contract.Requires(expr1 != null && expr2 != null); return(context.MkNot(context.MkEq(expr1, expr2))); }
public static Z3BVExpr Index(this Z3BVExpr expr1, Z3Context context, uint index) { Contract.Requires(expr1 != null && context != null); return(context.MkExtract(index, index, expr1)); }
public static Z3ArithExpr Mod(this Z3IntExpr expr1, Z3Context context, Z3IntExpr expr2) { Contract.Requires(expr1 != null && expr2 != null); return(context.MkMod(expr1, expr2)); }
public static Z3BoolExpr UGe(this Z3BVExpr expr1, Z3Context context, Z3BVExpr expr2) { Contract.Requires(expr1 != null && expr2 != null); return(context.MkBVUGE(expr1, expr2)); }
public static Z3Expr Ite(this Z3BoolExpr cond, Z3Context context, Z3Expr ifTrue, Z3Expr ifFalse) { Contract.Assert(cond != null && ifTrue != null && ifFalse != null); return(context.MkITE(cond, ifTrue, ifFalse)); }
public static Z3BoolExpr Ge(this Z3ArithExpr expr1, Z3Context context, Z3ArithExpr expr2) { Contract.Requires(expr1 != null && expr2 != null); return(context.MkGe(expr1, expr2)); }
/// <summary> /// Create and set the solver. Will get more complicated as /// params become clear. /// </summary> private void CreateContextAndSolver() { Context = new Z3Context(); Z3Solver = Context.MkSolver(); }