public int Length(Z3Context ctx) { var sol = GetSolution(ctx, MaxLength); if (sol != null) { return(_LengthBuilder.Invoke(sol)); } return(-1); }
public T GetSolution(Z3Context ctx, int maxLength) { T toReturn; if (!_solutions.TryGetValue(maxLength, out toReturn)) { var theorem = this._TheoremBuilder.Invoke(ctx, maxLength); toReturn = theorem.Solve(); _solutions[maxLength] = toReturn; } return(toReturn); }
public bool IsMinimal(Z3Context ctx) { if (!_IsMinimal.HasValue) { if (Length(ctx) == -1) { _IsMinimal = false; } else { var sol = GetSolution(ctx, MaxLength - 1); _IsMinimal = sol == null; } } return(_IsMinimal.Value); }
public static T SearchMinimal(int maxLength, Func <Z3Context, int, Theorem <T> > theoremBuilder, Func <T, int> lengthBuilder) { var listToSearch = BuildBinarySearchList(maxLength, theoremBuilder, lengthBuilder); var target = new ShortestTheoremSearcher <T>(); int idxFound = -1; using (var ctx = new Z3Context()) { idxFound = listToSearch.BinarySearch(target, (obj1, obj2) => (obj1.IsMinimal(ctx) ? 0 : obj1.Length(ctx)) - (obj2.IsMinimal(ctx) ? 0 : obj2.Length(ctx))); if (idxFound > 0) { return(listToSearch[idxFound].Solution(ctx)); } } return(default(T)); }
public T Solution(Z3Context ctx) { return(GetSolution(ctx, MaxLength)); }
/// <summary> /// Creates a new pre-constrained theorem for the given Z3 context. /// </summary> /// <param name="context">Z3 context.</param> /// <param name="constraints">Constraints to apply to the created theorem.</param> protected Theorem(Z3Context context, IEnumerable <LambdaExpression> constraints) { _context = context; _constraints = constraints; }
/// <summary> /// Creates a new theorem for the given Z3 context. /// </summary> /// <param name="context">Z3 context.</param> protected Theorem(Z3Context context) : this(context, new List <LambdaExpression>()) { }
/// <summary> /// Creates a new pre-constrained theorem for the given Z3 context. /// </summary> /// <param name="context">Z3 context.</param> /// <param name="constraints">Constraints to apply to the created theorem.</param> internal Theorem(Z3Context context, IEnumerable <LambdaExpression> constraints) : base(context, constraints) { }
/// <summary> /// Creates a new theorem for the given Z3 context. /// </summary> /// <param name="context">Z3 context.</param> internal Theorem(Z3Context context) : base(context) { }