Search in sources :

Example 1 with Expression

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

the class AbstractSingleVariableConstraintWithBinaryAtomsIncludingEquality method rewriteSignAndNormalizedAtomForValueVariableIsBoundTo.

private Expression rewriteSignAndNormalizedAtomForValueVariableIsBoundTo(boolean sign, Expression normalizedAtom, Expression valueVariableIsBoundTo, Context context) {
    Expression normalizedAtomInTermsOfValueVariableIsBoundTo = apply(normalizedAtom.getFunctor(), valueVariableIsBoundTo, normalizedAtom.get(1));
    Expression literal = sign ? normalizedAtomInTermsOfValueVariableIsBoundTo : not(normalizedAtomInTermsOfValueVariableIsBoundTo);
    Expression simplifiedLiteral = getTheory().simplify(literal, context);
    return simplifiedLiteral;
}
Also used : Expression(com.sri.ai.expresso.api.Expression)

Example 2 with Expression

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

the class AbstractTheoryWithBinaryAtomsTestingSupport method makeRandomAtomOn.

/**
	 * Makes a random atom by uniformly picking among the theory functors and testing variables.
	 */
@Override
public Expression makeRandomAtomOn(String mainVariable, Context context) {
    String mainVariableName = getVariableName(mainVariable);
    Type mainType = getTestingVariableType(mainVariable);
    Expression otherTerm = parse(pickTestingVariableAtRandom(mainType, otherName -> !otherName.equals(mainVariableName)));
    String functor = pickUniformly(getTheoryFunctors(), getRandom());
    Expression mainVariableExpression = parse(mainVariable);
    Expression possiblyTrivialAtom = getRandom().nextBoolean() ? apply(functor, mainVariableExpression, otherTerm) : apply(functor, otherTerm, mainVariableExpression);
    Expression result = getTheory().simplify(possiblyTrivialAtom, context);
    return result;
}
Also used : Util.pickUniformly(com.sri.ai.util.Util.pickUniformly) AbstractTheoryTestingSupport(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheoryTestingSupport) Type(com.sri.ai.expresso.api.Type) Expressions.apply(com.sri.ai.expresso.helper.Expressions.apply) Expressions.parse(com.sri.ai.expresso.helper.Expressions.parse) Collection(java.util.Collection) Random(java.util.Random) Expression(com.sri.ai.expresso.api.Expression) Context(com.sri.ai.grinder.sgdpllt.api.Context) Beta(com.google.common.annotations.Beta) Type(com.sri.ai.expresso.api.Type) Expression(com.sri.ai.expresso.api.Expression)

Example 3 with Expression

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

the class BruteForceFunctionTheory method getSingleVariableConstraintQuantifierEliminatorStepSolver.

@Override
public ExpressionLiteralSplitterStepSolver getSingleVariableConstraintQuantifierEliminatorStepSolver(AssociativeCommutativeGroup group, SingleVariableConstraint constraint, Expression body, Context context) {
    Expression variable = constraint.getVariable();
    Expression type = GrinderUtil.getTypeExpression(variable, context);
    Expression indexExpression = IndexExpressions.makeIndexExpression(variable, type);
    ExtensionalIndexExpressionsSet indexExpressionsSet = new ExtensionalIndexExpressionsSet(indexExpression);
    MultiIndexQuantifierEliminator quantifierEliminator = new BruteForceMultiIndexQuantifierEliminator(context.getTheory().getTopRewriter());
    Expression solution = quantifierEliminator.solve(group, indexExpressionsSet, constraint, body, context);
    return new ConstantExpressionStepSolver(solution);
}
Also used : ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) MultiIndexQuantifierEliminator(com.sri.ai.grinder.sgdpllt.api.MultiIndexQuantifierEliminator) BruteForceMultiIndexQuantifierEliminator(com.sri.ai.grinder.sgdpllt.interpreter.BruteForceMultiIndexQuantifierEliminator) Expression(com.sri.ai.expresso.api.Expression) BruteForceMultiIndexQuantifierEliminator(com.sri.ai.grinder.sgdpllt.interpreter.BruteForceMultiIndexQuantifierEliminator) ConstantExpressionStepSolver(com.sri.ai.grinder.sgdpllt.theory.base.ConstantExpressionStepSolver)

Example 4 with Expression

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

the class BruteForceFunctionTheoryTestingSupport method getSmallCategoricalTestingType.

public static Categorical getSmallCategoricalTestingType() {
    if (_someType == null) {
        ArrayList<Expression> knownConstants = mapIntoArrayList(list("a", "b", "c"), s -> makeSymbol(s));
        _someType = new Categorical("SmallSomeType", 3, knownConstants);
    }
    return _someType;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Categorical(com.sri.ai.expresso.type.Categorical)

Example 5 with Expression

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

the class BruteForceFunctionTheoryTestingSupport method makeFunctionApplication.

protected Expression makeFunctionApplication(String functorName, FunctionType functionType) {
    // Generate arguments for the application
    List<Expression> args = new ArrayList<>();
    for (Type argType : functionType.getArgumentTypes()) {
        // If constants supported, use at random
        if (argType.isSampleUniquelyNamedConstantSupported() && getRandom().nextBoolean()) {
            args.add(argType.sampleUniquelyNamedConstant(getRandom()));
        } else {
            // Otherwise retrieve a term variable matching that type and use it
            String termVariable = pickTestingVariableAtRandom(getTermVariableNamesAndTypesForTesting(), argType, variableName -> true);
            Type termType = getTermVariableNamesAndTypesForTesting().get(termVariable);
            if (termType instanceof FunctionType) {
                // Allow for nested function applications
                args.add(makeFunctionApplication(termVariable, (FunctionType) termType));
            } else {
                // Otherwise just assign the variable for the term.
                args.add(parse(termVariable));
            }
        }
    }
    Expression result = Expressions.apply(functorName, args.toArray(new Object[args.size()]));
    return result;
}
Also used : Type(com.sri.ai.expresso.api.Type) FunctionType(com.sri.ai.expresso.type.FunctionType) Expression(com.sri.ai.expresso.api.Expression) FunctionType(com.sri.ai.expresso.type.FunctionType) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)1392 Test (org.junit.Test)259 ArrayList (java.util.ArrayList)196 Context (com.sri.ai.grinder.api.Context)187 Type (com.sri.ai.expresso.api.Type)124 TrueContext (com.sri.ai.grinder.core.TrueContext)113 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)100 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)91 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)90 Context (com.sri.ai.grinder.sgdpllt.api.Context)87 Theory (com.sri.ai.grinder.api.Theory)78 Map (java.util.Map)78 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)71 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)68 List (java.util.List)68 DefaultLambdaExpression (com.sri.ai.expresso.core.DefaultLambdaExpression)63 CommonTheory (com.sri.ai.grinder.application.CommonTheory)55 LinkedHashMap (java.util.LinkedHashMap)55 LinkedHashSet (java.util.LinkedHashSet)54 Pair (com.sri.ai.util.base.Pair)52