当前位置: 首页>>代码示例>>Java>>正文


Java Expressions.isNumber方法代码示例

本文整理汇总了Java中com.sri.ai.expresso.helper.Expressions.isNumber方法的典型用法代码示例。如果您正苦于以下问题:Java Expressions.isNumber方法的具体用法?Java Expressions.isNumber怎么用?Java Expressions.isNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sri.ai.expresso.helper.Expressions的用法示例。


在下文中一共展示了Expressions.isNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractGeneralizedVariables

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
private static void extractGeneralizedVariables(Expression polynomialExpression, Set<Expression> generalizedVariables) {
	if (Expressions.isSymbol(polynomialExpression)) {
		if (!Expressions.isNumber(polynomialExpression)) {
			generalizedVariables.add(polynomialExpression);
		}
	}
	else if (Expressions.hasFunctor(polynomialExpression, PLUS_FUNCTOR)     ||
			 Expressions.hasFunctor(polynomialExpression, MINUS_FUNCTOR)    ||
			 Expressions.hasFunctor(polynomialExpression, TIMES_FUNCTOR)    ||
			 Expressions.hasFunctor(polynomialExpression, DIVISION_FUNCTOR) ||
			 Expressions.hasFunctor(polynomialExpression, EXPONENTIATION_FUNCTOR)) {
		for (Expression arg : polynomialExpression.getArguments()) {
			extractGeneralizedVariables(arg, generalizedVariables);
		}
	}
	else {
		// An unknown functor or other type of expression not expected
		// by a standard polynomial expression
		generalizedVariables.add(polynomialExpression);
	}
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:22,代码来源:DefaultPolynomial.java

示例2: simplifyExponentIfPossible

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
static Expression simplifyExponentIfPossible(Expression exponent) {
	Expression result = exponent;
	
	if (exponent.hasFunctor(Exponentiation.EXPONENTIATION_FUNCTOR)) {
		Expression base  = exponent.get(0);
		Expression power = exponent.get(1);
		
		Expression simplifiedPower = simplifyExponentIfPossible(power);
		if (Expressions.isNumber(base) && isLegalExponent(simplifiedPower)) {
			result = Expressions.makeSymbol(base.rationalValue().pow(simplifiedPower.intValueExact()));
		}
		else if (!power.equals(simplifiedPower)) {
			result = new DefaultFunctionApplication(Exponentiation.EXPONENTIATION_FUNCTOR, Arrays.asList(base, simplifiedPower));
		}
	}
	
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:19,代码来源:DefaultMonomial.java

示例3: simplify

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
static public Expression simplify(Expression expression) {
	Expression result = expression;
	
	Expression first = expression.get(0);
	Expression second = expression.get(1);

	if (Expressions.isNumber(first)) {
		Rational firstValue = first.rationalValue();
		if (Expressions.isNumber(second)) {
			Rational secondValue = second.rationalValue();
			result = Expressions.makeSymbol(firstValue.subtract(secondValue));
		} 
		else if (firstValue.isZero()) {
			result = Expressions.apply("-", second);
		}
	} 
	else if (Expressions.isNumber(second) && second.rationalValue().isZero()) {
		result = first;
	}
		
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:23,代码来源:BinaryMinus.java

示例4: testSimpleRecursiveRewriter

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Test
public void testSimpleRecursiveRewriter() {
	RewriterFromStepMaker rewriter = 
			(Expression e, Context c) -> {
				if (Expressions.isNumber(e)) {
					return new Solution(DefaultSymbol.createSymbol(e.intValue() + 1));
				}
				return new Solution(e);
			};

			Expression initial;
			Expression expected;

			initial = parse("7");
			expected = parse("8");
			runTest(rewriter, initial, expected, map());

			initial = parse("f(9,g(8,7,6))");
			expected = parse("f(10,g(9,8,7))");
			runTest(rewriter, initial, expected, map());

			initial = parse("(6)(9,g(8,7,6))");
			expected = parse("(7)(10,g(9,8,7))");
			runTest(rewriter, initial, expected, map());
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:26,代码来源:RecursiveTest.java

示例5: isLegalExponent

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
static boolean isLegalExponent(Expression exponentExpression) {
	boolean result = false;
	if (Expressions.isNumber(exponentExpression)) {
		Rational exponent = exponentExpression.rationalValue();
		if (exponent.isInteger() && exponent.signum() != -1) {
			result = true;
		}
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:11,代码来源:DefaultMonomial.java

示例6: simplify

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
public static Expression simplify(Expression expression) {
	Expression base     = expression.get(0);
	Expression exponent = expression.get(1);

	Rational exponentValue = null;
	Rational baseValue     = null;
	
	if (Expressions.isNumber(exponent)) {
		exponentValue = exponent.rationalValue();
		if (exponentValue.isZero()) {
			return Expressions.ONE;
		}
		if (exponentValue.isOne()) {
			return base;
		}
	}
	
	if (Expressions.isNumber(base)) {
		baseValue = base.rationalValue();
		if (baseValue.isOne()) {
			return Expressions.ONE;
		}
		// we refrain from simplifying 0^x to 0, because x could be 0 itself.
	}
	
	if (baseValue != null && exponentValue != null) {
		Rational   pow    = baseValue.pow(exponentValue);
		Expression result = Expressions.makeSymbol(pow);
		return result;
	}

	return expression;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:34,代码来源:Exponentiation.java

示例7: getTypeLowerBoundAndStrictness

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
protected Pair<Expression, Boolean> getTypeLowerBoundAndStrictness(Context context) {
	if (typeLowerBoundAndStrictness == null) {
		IntegerInterval type = getType(context);
		Expression nonStrictLowerBound = type.getNonStrictLowerBound();
		if (Expressions.isNumber(nonStrictLowerBound)) {
			typeLowerBoundAndStrictness = pair(makeSymbol(nonStrictLowerBound.intValue() - 1), true /* strict */);
		}
		else { // has to be -infinity
			typeLowerBoundAndStrictness = pair(MINUS_INFINITY, true /* strict */);
		}
	}
	return typeLowerBoundAndStrictness;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:14,代码来源:AbstractSingleVariableDifferenceArithmeticConstraintFeasibilityRegionStepSolver.java

示例8: simplify

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
public static Expression simplify(Expression expression, Context context) {
		Expression result = expression;
		
		if (Expressions.hasFunctor(expression, FunctorConstants.GET) 
				&& expression.numberOfArguments() == 2) {
			Expression tupleArg = expression.get(0);
			Expression indexArg = expression.get(1);
			if (Tuple.isTuple(tupleArg)) {
				// NOTE: Tuple's are indexed starting from 1 not 0.
// TODO - do we really want this ^^^
				if (Expressions.isNumber(indexArg)) {
					// We have a constant
					int constantIndex = indexArg.intValueExact();
					if (constantIndex > 0 && constantIndex <= tupleArg.numberOfArguments()) {
						result = tupleArg.get(constantIndex -1); // NOTE: the API is 0 based.
					}
					else {
						throw new IndexOutOfBoundsException("Index "+indexArg+" is out of bounds on "+tupleArg);
					}
				}
				else {
					// Construct a conditional
					result = constructConditional(tupleArg, indexArg, 0);
				}
			}
		}
		

		return result;
	}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:31,代码来源:TupleGetSimplifier.java

示例9: simplify

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
public static Expression simplify(Expression expression, Context context) {
		Expression result = expression;
		
		if (Expressions.hasFunctor(expression, FunctorConstants.SET) 
				&& expression.numberOfArguments() == 3) {
			Expression tupleArg = expression.get(0);
			Expression indexArg = expression.get(1);
			Expression setToArg = expression.get(2);
			if (Tuple.isTuple(tupleArg)) {
				// NOTE: Tuple's are indexed starting from 1 not 0.
// TODO - do we really want this ^^^
				if (Expressions.isNumber(indexArg)) {
					// We have a constant
					int constantIndex = indexArg.intValueExact();
					if (constantIndex > 0 && constantIndex <= tupleArg.numberOfArguments()) {
						result = tupleArg.set(constantIndex -1, setToArg); // NOTE: the API is 0 based.
					}
					else {
						throw new IndexOutOfBoundsException("Index "+indexArg+" is out of bounds on "+tupleArg);
					}
				}
				else {
					// Construct a conditional
					result = constructConditional(tupleArg, indexArg, setToArg, 0);
				}
			}
		}
		

		return result;
	}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:32,代码来源:TupleSetSimplifier.java

示例10: testSimpleExhaustiveRewriter

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Test
public void testSimpleExhaustiveRewriter() {
	RewriterFromStepMaker rewriter = 
			(Expression e, Context c) -> {
				if (Expressions.isNumber(e) && e.intValue() < 10) {
					return new Solution(DefaultSymbol.createSymbol(e.intValue() + 1));
				}
				return new Solution(e);
			};
	Expression initial = parse("1");
	Expression expected = parse("10");

	runTest(rewriter, initial, expected, map());
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:15,代码来源:ExhaustiveTest.java

示例11: isUnknownConstant

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
boolean isUnknownConstant(Expression expr, Map<Expression, ConstantDeclaration> scopedConstants) {
	boolean result = Expressions.isSymbol(expr) &&
					!Expressions.isNumber(expr) &&
					!isQuantifiedExpression(expr) &&
					!scopedConstants.containsKey(expr) &&
					!randoms.containsKey(expr) &&
					!sorts.containsKey(expr) &&
					!sortConstants.contains(expr) &&
					!Expressions.isStringLiteral(expr);
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:12,代码来源:HOGModel.java

示例12: fullGrounding

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
/**
 * @param factor
 * @param randomVariablesInFactor
 * @param listener
 * @param randomVariableNameToTypeSizeAndUniqueConstants
 * @param typeToValues
 * @param inferencer
 * @param context
 */
private static void fullGrounding(Expression factor, List<Expression> randomVariablesInFactor, Listener listener, Map<Expression, Triple<Expression, Integer, List<Expression>>> randomVariableNameToTypeSizeAndUniqueConstants, Map<Expression, List<Expression>> typeToValues, InferenceForFactorGraphAndEvidence inferencer, Context context) {
	int[] radices                    = new int[randomVariablesInFactor.size()];
	List<List<Expression>> factorRandomVariableTypeValues = new ArrayList<>();
	for (int i = 0; i < randomVariablesInFactor.size(); i++) {
		Expression randomVariable = randomVariablesInFactor.get(i);
		Expression type               = randomVariableNameToTypeSizeAndUniqueConstants.get(randomVariable).first;
		radices[i]                    = randomVariableNameToTypeSizeAndUniqueConstants.get(randomVariable).second;
		factorRandomVariableTypeValues.add(typeToValues.get(type));
	}
	
	boolean didIncrement     = true;
	MixedRadixNumber mrn     = new MixedRadixNumber(BigInteger.ZERO, radices);
	int numberFactorValues   = mrn.getMaxAllowedValue().intValue()+1;
	do {
		Expression groundedFactor = factor;
		for (int i = 0; i < randomVariablesInFactor.size(); i++) {
			int valueIndex = mrn.getCurrentNumeralValue(i);
			groundedFactor = groundedFactor.replaceAllOccurrences(randomVariablesInFactor.get(i), factorRandomVariableTypeValues.get(i).get(valueIndex), context);
		}  		
		Expression value = inferencer.simplify(groundedFactor, context);
		//				Expression value = inferencer.evaluate(groundedFactor);
		if (!Expressions.isNumber(value)) {
			throw new IllegalStateException("Unable to compute a number for the grounded factor ["+groundedFactor+"], instead got:"+value);
		}

		boolean isFirstValue = mrn.getValue().intValue() == 0;
		boolean isLastValue = mrn.getValue().intValue() == numberFactorValues - 1;
		listener.factorValue(numberFactorValues, isFirstValue, isLastValue, value.rationalValue());

		if (didIncrement = mrn.canIncrement()) {
			mrn.increment();
		}				
	} while (didIncrement);
}
 
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:44,代码来源:HOGModelGrounding.java

示例13: apply

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Override
public boolean apply(Expression e) {
	boolean result = uniquelyNamedConstants.contains(e) || Expressions.isNumber(e) || Expressions.isBooleanSymbol(e);
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:6,代码来源:UniquelyNamedConstantIncludingBooleansAndNumbersPredicate.java

示例14: addMonomialsWithSameSignature

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
private Monomial addMonomialsWithSameSignature(Monomial m1, Monomial m2) {
	Monomial result;
	
	// Both have the same signature
	Monomial m1Coefficient = m1.getCoefficient(getVariables());
	Monomial m2Coefficient = m2.getCoefficient(getVariables());
	Expression summedCoefficient;
	if (m1Coefficient.isNumericConstant() && m2Coefficient.isNumericConstant()) {
		// We can add them
		summedCoefficient = Expressions.makeSymbol(m1Coefficient.getNumericFactor().add(m2Coefficient.getNumericFactor()));
	}
	else if (m1Coefficient.equals(m2Coefficient)) { // Compactly represent non-numeric coefficients that are equal 
		summedCoefficient = new DefaultFunctionApplication(TIMES_FUNCTOR, Arrays.asList(Expressions.TWO, m1Coefficient));
	}
	else {
		List<Expression> plusArgs = new ArrayList<>();
		if (!m1Coefficient.isZero()) {
			plusArgs.add(m1Coefficient);
		}
		if (!m2Coefficient.isZero()) {
			plusArgs.add(m2Coefficient);
		}
		if (plusArgs.size() == 2) {
			summedCoefficient = new DefaultFunctionApplication(PLUS_FUNCTOR, Arrays.asList(m1Coefficient, m2Coefficient));
		}
		else {
			summedCoefficient = plusArgs.get(0);
		}
	}
	
	if (!Expressions.ZERO.equals(summedCoefficient)) {
		List<Expression> args = new ArrayList<Expression>();
		Rational numericConstantFactor = Rational.ONE;
		if (Expressions.isNumber(summedCoefficient)) {
			numericConstantFactor = summedCoefficient.rationalValue();
		}
		else if (summedCoefficient.hasFunctor(TIMES_FUNCTOR)) { // i.e. coefficients are equal so write in compact form.
			numericConstantFactor = summedCoefficient.get(0).rationalValue();
			args.add(summedCoefficient.get(1));
		} else {
			args.add(summedCoefficient);
		}
		args.addAll(getVariables());
		Collections.sort(args, _factorComparator);
		List<Rational> orderedPowers = new ArrayList<>();
		for (Expression factor : args) {
			if (factor == summedCoefficient) {
				orderedPowers.add(Rational.ONE);
			}
			else {
				orderedPowers.add(m1.getPowerOfFactor(factor));
			}
		}
		result = DefaultMonomial.make(numericConstantFactor, args, orderedPowers);
	}
	else {
		result = DefaultMonomial.ZERO;
	}
	
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:62,代码来源:DefaultPolynomial.java

示例15: getCoefficient

import com.sri.ai.expresso.helper.Expressions; //导入方法依赖的package包/类
@Override
public Monomial getCoefficient(List<Expression> factors) {
	Monomial result;
	
	if (isZero()) {
		result = ZERO;
	}
	else if (factors.size() == 0) {
		result = this;
	}
	else {
		// NOTE: This set will preserve the required ordering			
		Set<Expression> coefficientFactors = new LinkedHashSet<>(getFactors());
		coefficientFactors.removeAll(factors);
		
		// If the factors provided don't overlap with the factors in this monomial
		// then you just want to return this monomial.
		if (coefficientFactors.size() == getFactors().size()) {
			result = this;
		}
		else {
			// TODO: (Sept 2017) This treatment of coefficient factors (basically, combining factors into a single one)
			// seems overly complicated and unnecessary.

			// Check if the numeric constant is to be considered part of the coefficient or not
			// (i.e. could be included in set of given factors to exclude)
			Rational resultNumericFactor = Rational.ONE;
			if (coefficientFactors.contains(this.numericFactorExpression)) {
				resultNumericFactor = getNumericFactor();
			}
			
			List<Expression> resultOrderedFactors = new ArrayList<>(this.orderedNonNumericFactors.size());
			List<Rational>   resultOrderedFactorPowers  = new ArrayList<>(this.orderedNonNumericFactorPowers.size());
			for (Expression coefficientFactor : coefficientFactors) {
				if (!Expressions.isNumber(coefficientFactor)) {
					resultOrderedFactors.add(coefficientFactor);
					resultOrderedFactorPowers.add(getPowerOfFactor(coefficientFactor));
				}
			}
		
			result = make(resultNumericFactor, resultOrderedFactors, resultOrderedFactorPowers);
		}
	}
	
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:47,代码来源:DefaultMonomial.java


注:本文中的com.sri.ai.expresso.helper.Expressions.isNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。