Search in sources :

Example 1 with MultiQuantifierEliminator

use of com.sri.ai.grinder.api.MultiQuantifierEliminator in project aic-expresso by aic-sri-international.

the class BruteForceFunctionTheory method getSingleQuantifierEliminatorStepSolver.

@Override
public ExpressionLiteralSplitterStepSolver getSingleQuantifierEliminatorStepSolver(SingleQuantifierEliminationProblem problem, Context context) {
    Expression variable = problem.getIndex();
    Expression type = GrinderUtil.getTypeExpressionOfExpression(variable, context);
    Expression indexExpression = IndexExpressions.makeIndexExpression(variable, type);
    ExtensionalIndexExpressionsSet indexExpressionsSet = new ExtensionalIndexExpressionsSet(indexExpression);
    MultiQuantifierEliminator quantifierEliminator = new BruteForceMultiQuantifierEliminator(context.getTheory().getTopRewriter());
    // TODO: return conditional steps on literals on free variables.
    // We are solving it straight here because there are no literals in this theory,
    // however a more sophisticated solution would return conditional steps on literals on free variables.
    Expression solution = quantifierEliminator.extendContextAndSolve(problem.getGroup(), indexExpressionsSet, problem.getConstraint(), problem.getBody(), context);
    return new ConstantExpressionStepSolver(solution);
}
Also used : ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) Expression(com.sri.ai.expresso.api.Expression) BruteForceMultiQuantifierEliminator(com.sri.ai.grinder.interpreter.BruteForceMultiQuantifierEliminator) MultiQuantifierEliminator(com.sri.ai.grinder.api.MultiQuantifierEliminator) BruteForceMultiQuantifierEliminator(com.sri.ai.grinder.interpreter.BruteForceMultiQuantifierEliminator) ConstantExpressionStepSolver(com.sri.ai.grinder.theory.base.ConstantExpressionStepSolver)

Example 2 with MultiQuantifierEliminator

use of com.sri.ai.grinder.api.MultiQuantifierEliminator in project aic-expresso by aic-sri-international.

the class Compilation method compile.

/**
 * Compiles an expression to a normalized (decision-tree-like) expression.
 * @param inputExpression
 * @param mapFromVariableNameToTypeName
 * @param mapFromCategoricalTypeNameToSizeString
 * @param additionalTypes
 * @param solverListener if not null, invoked on solver used for compilation, before and after compilation starts; returned solver on 'before' invocation is used (it may be the same one used as argument, of course).
 * @return
 */
public static Expression compile(Expression inputExpression, Theory theory, Map<String, String> mapFromVariableNameToTypeName, Map<String, String> mapFromUniquelyNamedConstantToTypeName, Map<String, String> mapFromCategoricalTypeNameToSizeString, Collection<Type> additionalTypes, Function<MultiQuantifierEliminator, MultiQuantifierEliminator> solverListener) {
    // the group actually does not matter, because we are not going to have any indices.
    AssociativeCommutativeGroup group = new Max();
    // The solver for the parameters above.
    MultiQuantifierEliminator solver = new DefaultMultiQuantifierEliminator();
    if (solverListener != null) {
        solver = solverListener.apply(solver);
    }
    // We use the Prolog convention of small-letter initials for constants, but we need an exception for the random variables.
    Predicate<Expression> isPrologConstant = new PrologConstantPredicate();
    Predicate<Expression> isUniquelyNamedConstantPredicate = e -> isPrologConstant.apply(e) && !mapFromVariableNameToTypeName.containsKey(e);
    Map<String, String> mapFromSymbolNameToTypeName = new LinkedHashMap<>(mapFromVariableNameToTypeName);
    mapFromSymbolNameToTypeName.putAll(mapFromUniquelyNamedConstantToTypeName);
    // Solve the problem.
    // no indices; we want to keep all variables
    List<Expression> indices = Util.list();
    Expression result = solver.solve(group, inputExpression, indices, mapFromSymbolNameToTypeName, mapFromCategoricalTypeNameToSizeString, additionalTypes, isUniquelyNamedConstantPredicate, theory);
    if (solverListener != null) {
        solverListener.apply(null);
    }
    return result;
}
Also used : Type(com.sri.ai.expresso.api.Type) Collection(java.util.Collection) Expression(com.sri.ai.expresso.api.Expression) DefaultMultiQuantifierEliminator(com.sri.ai.grinder.core.solver.DefaultMultiQuantifierEliminator) Function(java.util.function.Function) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Theory(com.sri.ai.grinder.api.Theory) AssociativeCommutativeGroup(com.sri.ai.grinder.group.AssociativeCommutativeGroup) Predicate(com.google.common.base.Predicate) Map(java.util.Map) Util(com.sri.ai.util.Util) PrologConstantPredicate(com.sri.ai.grinder.core.PrologConstantPredicate) Max(com.sri.ai.grinder.group.Max) MultiQuantifierEliminator(com.sri.ai.grinder.api.MultiQuantifierEliminator) Max(com.sri.ai.grinder.group.Max) Expression(com.sri.ai.expresso.api.Expression) PrologConstantPredicate(com.sri.ai.grinder.core.PrologConstantPredicate) AssociativeCommutativeGroup(com.sri.ai.grinder.group.AssociativeCommutativeGroup) DefaultMultiQuantifierEliminator(com.sri.ai.grinder.core.solver.DefaultMultiQuantifierEliminator) MultiQuantifierEliminator(com.sri.ai.grinder.api.MultiQuantifierEliminator) DefaultMultiQuantifierEliminator(com.sri.ai.grinder.core.solver.DefaultMultiQuantifierEliminator) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with MultiQuantifierEliminator

use of com.sri.ai.grinder.api.MultiQuantifierEliminator in project aic-expresso by aic-sri-international.

the class FallbackQuantifierEliminationStepSolver method solveWithFallbackAndReturnExpression.

private Expression solveWithFallbackAndReturnExpression(Context context) {
    MultiQuantifierEliminator fallbackMultiIndexQuantifierEliminator = makeFallbackMultiIndexQuantifierEliminator(context);
    Expression resultExpression = fallbackMultiIndexQuantifierEliminator.solveSingleIndexQuantifierEliminationProblem(problem, context);
    return resultExpression;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) MultiQuantifierEliminator(com.sri.ai.grinder.api.MultiQuantifierEliminator)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)3 MultiQuantifierEliminator (com.sri.ai.grinder.api.MultiQuantifierEliminator)3 Predicate (com.google.common.base.Predicate)1 Type (com.sri.ai.expresso.api.Type)1 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)1 Theory (com.sri.ai.grinder.api.Theory)1 PrologConstantPredicate (com.sri.ai.grinder.core.PrologConstantPredicate)1 DefaultMultiQuantifierEliminator (com.sri.ai.grinder.core.solver.DefaultMultiQuantifierEliminator)1 AssociativeCommutativeGroup (com.sri.ai.grinder.group.AssociativeCommutativeGroup)1 Max (com.sri.ai.grinder.group.Max)1 BruteForceMultiQuantifierEliminator (com.sri.ai.grinder.interpreter.BruteForceMultiQuantifierEliminator)1 ConstantExpressionStepSolver (com.sri.ai.grinder.theory.base.ConstantExpressionStepSolver)1 Util (com.sri.ai.util.Util)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1