本文整理汇总了Java中edu.jas.poly.Monomial类的典型用法代码示例。如果您正苦于以下问题:Java Monomial类的具体用法?Java Monomial怎么用?Java Monomial使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Monomial类属于edu.jas.poly包,在下文中一共展示了Monomial类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jasToPoly
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Transforms a JAS polynomial to a Polynomial object.
*
* @param j JAS polynomial
* @return polynomial of Polynomial class
*/
private Polynomial jasToPoly(GenPolynomial<BigInteger> j)
{
int numVariables = j.numberOfVariables();
Polynomial result = new Polynomial(numVariables, j.length());
for (Monomial<BigInteger> jasMono : j) {
java.math.BigInteger coeff = (jasMono.coefficient()).getVal();
ExpVector jasExpo = jasMono.exponent();
ArrayList<Integer> expo = new ArrayList<Integer>();
for (int var = 0; var < numVariables; var++) {
expo.add((int)jasExpo.getVal(var));
}
result.addTerm(coeff, expo);
}
return result;
}
示例2: fromPolynomial
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Get a UnivPowerSeries<C> from a GenPolynomial<C>.
* @param a GenPolynomial<C>.
* @return a UnivPowerSeries<C>.
*/
public UnivPowerSeries<C> fromPolynomial(GenPolynomial<C> a) {
if (a == null || a.isZERO()) {
return ZERO;
}
if (a.isONE()) {
return ONE;
}
if (a.ring.nvar != 1) {
throw new IllegalArgumentException("only for univariate polynomials");
}
HashMap<Integer, C> cache = new HashMap<Integer, C>(a.length());
for (Monomial<C> m : a) {
long e = m.exponent().getVal(0);
cache.put((int) e, m.coefficient());
}
return new UnivPowerSeries<C>(this, new Coefficients<C>(cache) {
@Override
public C generate(int i) {
// cached coefficients returned by get
return coFac.getZERO();
}
});
}
示例3: bitHeight
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Method bitHeight returns the bitlength of the greatest number occurring
* during the computation of a Groebner base.
*/
public int bitHeight(List<GenPolynomial<BigRational>> list) {
BigInteger denom = BigInteger.ONE;
BigInteger num = BigInteger.ONE;
for (GenPolynomial<BigRational> g : list) {
for (Monomial<BigRational> m : g) {
BigRational bi = m.coefficient();
BigInteger i = bi.denominator().abs();
BigInteger j = bi.numerator().abs();
if (i.compareTo(denom) > 0)
denom = i;
if (j.compareTo(num) > 0)
num = j;
}
}
int erg;
if (denom.compareTo(num) > 0) {
erg = denom.bitLength();
} else {
erg = num.bitLength();
}
return erg;
}
示例4: monomialListModulus
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Get the monomial list of a univariate polynomial with coefficients reduced by a modulo value.
*
* @param polynomial
* @param variable
* @param termOrder
* the JAS term ordering
* @param option
* the "Modulus" option
* @return the list of monomials of the univariate polynomial.
*/
private static IAST monomialListModulus(IExpr polynomial, List<IExpr> variablesList, final TermOrder termOrder,
IExpr option) throws JASConversionException {
try {
// found "Modulus" option => use ModIntegerRing
ModLongRing modIntegerRing = JASModInteger.option2ModLongRing((ISignedNumber) option);
JASModInteger jas = new JASModInteger(variablesList, modIntegerRing);
GenPolynomial<ModLong> polyExpr = jas.expr2JAS(polynomial);
IASTAppendable list = F.ListAlloc(polyExpr.length());
for (Monomial<ModLong> monomial : polyExpr) {
ModLong coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
IASTAppendable monomTimes = F.TimesAlloc(exp.length() + 1);
jas.monomialToExpr(F.integer(coeff.getVal()), exp, monomTimes);
list.append(monomTimes);
}
return list;
} catch (ArithmeticException ae) {
// toInt() conversion failed
if (Config.DEBUG) {
ae.printStackTrace();
}
}
return F.NIL;
}
示例5: isQuadratic
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Check if the polynomial has maximum degree 2 in 1 variable and return the coefficients.
*
* @param poly
* @return <code>false</code> if the polynomials degree > 2 and number of variables <> 1
*/
public static boolean isQuadratic(GenPolynomial<BigRational> poly, BigRational[] result) {
if (poly.degree() <= 2 && poly.numberOfVariables() == 1) {
result[0] = BigRational.ZERO;
result[1] = BigRational.ZERO;
result[2] = BigRational.ZERO;
for (Monomial<BigRational> monomial : poly) {
BigRational coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
for (int i = 0; i < exp.length(); i++) {
result[(int) exp.getVal(i)] = coeff;
}
}
return true;
}
return false;
}
示例6: isQuadratic
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Check if the polynomial has maximum degree 2 in 1 variable and return the
* coefficients.
*
* @param poly
* @return <code>null</code> if the polynomials degree > 2 and number of
* variables <> 1
*/
public static boolean isQuadratic(GenPolynomial<BigRational> poly, BigRational[] result) {
if (poly.degree() <= 2 && poly.numberOfVariables() == 1) {
result[0] = BigRational.ZERO;
result[1] = BigRational.ZERO;
result[2] = BigRational.ZERO;
for (Monomial<BigRational> monomial : poly) {
BigRational coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
for (int i = 0; i < exp.length(); i++) {
result[(int) exp.getVal(i)] = coeff;
}
}
return true;
}
return false;
}
示例7: integerPoly2Expr
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Convert a JAS integer polynomial to <code>IExpr</code>.
*
* @param poly
* @return
* @throws ArithmeticException
* @throws ClassCastException
*/
public IExpr integerPoly2Expr(final GenPolynomial<edu.jas.arith.BigInteger> poly)
throws ArithmeticException, ClassCastException {
if (poly.length() == 0) {
return F.C0;
}
IASTAppendable result = F.PlusAlloc(poly.length());
for (Monomial<edu.jas.arith.BigInteger> monomial : poly) {
edu.jas.arith.BigInteger coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
IASTAppendable monomTimes = F.TimesAlloc(exp.length()+1);
monomialToExpr(coeff, exp, monomTimes);
result.append(monomTimes.getOneIdentity(F.C1));
}
return result.getOneIdentity(F.C0);
}
示例8: complexPoly2Expr
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Convert a JAS complex polynomial to <code>IExpr</code>.
*
* @param poly
* @return
* @throws ArithmeticException
* @throws ClassCastException
*/
public IExpr complexPoly2Expr(final GenPolynomial<Complex<BigRational>> poly)
throws ArithmeticException, ClassCastException {
if (poly.length() == 0) {
return F.C0;
}
IASTAppendable result = F.PlusAlloc(poly.length());
for (Monomial<Complex<BigRational>> monomial : poly) {
Complex<BigRational> coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
IASTAppendable monomTimes = F.TimesAlloc(exp.length()+1);
monomialToExpr(coeff, exp, monomTimes);
result.append(monomTimes.getOneIdentity(F.C1));
}
return result.getOneIdentity(F.C0);
}
示例9: rationalPoly2Expr
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Converts a <a href="http://krum.rz.uni-mannheim.de/jas/">JAS</a>
* polynomial to a MathEclipse AST with head <code>Plus</code>
*
* @param poly
* a JAS polynomial
* @param variable
* @return
* @throws ArithmeticException
* @throws ClassCastException
*/
public IAST rationalPoly2Expr(final GenPolynomial<BigRational> poly)
throws ArithmeticException, ClassCastException {
if (poly.length() == 0) {
return F.Plus(F.C0);
}
IASTAppendable result = F.PlusAlloc(poly.length());
for (Monomial<BigRational> monomial : poly) {
BigRational coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
IASTAppendable monomTimes = F.TimesAlloc(exp.length()+1);
monomialToExpr(coeff, exp, monomTimes);
result.append(monomTimes.getOneIdentity(F.C1));
}
return result;
}
示例10: exprPoly2Expr
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Converts a <a href="http://krum.rz.uni-mannheim.de/jas/">JAS</a> polynomial to a MathEclipse AST with head
* <code>Plus</code>
*
* @param poly
* a JAS polynomial
* @param variable
* @return
* @throws ArithmeticException
* @throws ClassCastException
*/
public IExpr exprPoly2Expr(final GenPolynomial<IExpr> poly, IExpr variable) {
if (poly.length() == 0) {
return F.C0;
}
IASTAppendable result = F.PlusAlloc(poly.length());
for (Monomial<IExpr> monomial : poly) {
IExpr coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
IASTAppendable monomTimes = F.TimesAlloc(exp.length() + 1);
monomialToExpr(coeff, exp, monomTimes);
result.append(monomTimes.getOneIdentity(F.C1));
}
return result.getOneIdentity(F.C0);
}
示例11: coefficientRules
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Get exponent vectors and coefficients of monomials of a polynomial expression.
*
* @param polynomial
* @param variable
* @param termOrder
* the JAS term ordering
* @return the list of monomials of the univariate polynomial.
*/
public static IAST coefficientRules(IExpr polynomial, final List<IExpr> variablesList,
final TermOrder termOrder) throws JASConversionException {
JASIExpr jas = new JASIExpr(variablesList, ExprRingFactory.CONST, termOrder, false);
GenPolynomial<IExpr> polyExpr = jas.expr2IExprJAS(polynomial);
IASTAppendable resultList = F.ListAlloc(polyExpr.length());
for (Monomial<IExpr> monomial : polyExpr) {
IExpr coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
int len = exp.length();
IASTAppendable ruleList = F.ListAlloc(len);
for (int i = 0; i < len; i++) {
ruleList.append(F.integer(exp.getVal(len - i - 1)));
}
resultList.append(F.Rule(ruleList, coeff));
}
return resultList;
}
示例12: complexPoly2Expr
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Convert a JAS complex polynomial to <code>IExpr</code>.
*
* @param poly
* @return
* @throws ArithmeticException
* @throws ClassCastException
*/
public IExpr complexPoly2Expr(final GenPolynomial<Complex<BigRational>> poly)
throws ArithmeticException, ClassCastException {
if (poly.length() == 0) {
return F.C0;
}
IASTAppendable result = F.PlusAlloc(poly.length());
for (Monomial<Complex<BigRational>> monomial : poly) {
Complex<BigRational> coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
BigRational re = coeff.getRe();
BigRational im = coeff.getIm();
IASTAppendable monomTimes = F.Times(F.complex(F.fraction(re.numerator(), re.denominator()),
F.fraction(im.numerator(), im.denominator())));
long lExp;
for (int i = 0; i < exp.length(); i++) {
lExp = exp.getVal(i);
if (lExp != 0) {
monomTimes.append(F.Power(fVariables.get(i), F.integer(lExp)));
}
}
if (monomTimes.isAST1()) {
result.append(monomTimes.arg1());
} else {
result.append(monomTimes);
}
}
if (result.isAST1()) {
return result.arg1();
} else {
return result;
}
}
示例13: integerPoly2Expr
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Convert a JAS integer polynomial to <code>IExpr</code>.
*
* @param poly
* @return
* @throws ArithmeticException
* @throws ClassCastException
*/
public IExpr integerPoly2Expr(final GenPolynomial<edu.jas.arith.BigInteger> poly)
throws ArithmeticException, ClassCastException {
if (poly.length() == 0) {
return F.C0;
}
IASTAppendable result = F.PlusAlloc(poly.length());
for (Monomial<edu.jas.arith.BigInteger> monomial : poly) {
edu.jas.arith.BigInteger coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
IInteger coeffValue = F.integer(coeff.getVal());
IASTAppendable monomTimes = F.TimesAlloc(exp.length() + 1);
monomTimes.append(coeffValue);
long lExp;
for (int i = 0; i < exp.length(); i++) {
lExp = exp.getVal(i);
if (lExp != 0) {
monomTimes.append(F.Power(fVariables.get(i), F.integer(lExp)));
}
}
if (monomTimes.isAST1()) {
result.append(monomTimes.arg1());
} else {
result.append(monomTimes);
}
}
if (result.isAST1()) {
return result.arg1();
} else {
return result;
}
}
示例14: modLongPoly2Expr
import edu.jas.poly.Monomial; //导入依赖的package包/类
public IExpr modLongPoly2Expr(final GenPolynomial<ModLong> poly) throws ArithmeticException, ClassCastException {
if (poly.length() == 0) {
return F.Plus(F.C0);
}
IASTAppendable result = F.PlusAlloc(poly.length());
for (Monomial<ModLong> monomial : poly) {
ModLong coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
IInteger coeffValue = F.integer(coeff.getVal());
IASTAppendable monomTimes = F.TimesAlloc(exp.length() + 1);
monomialToExpr(coeffValue, exp, monomTimes);
result.append(monomTimes.getOneIdentity(F.C1));
}
return result.getOneIdentity(F.C0);
}
示例15: coefficientRulesModulus
import edu.jas.poly.Monomial; //导入依赖的package包/类
/**
* Get exponent vectors and coefficients of monomials of a polynomial expression.
*
* @param polynomial
* @param variable
* @param termOrder
* the JAS term ordering
* @param option
* the "Modulus" option
* @return the list of monomials of the univariate polynomial.
*/
private static IAST coefficientRulesModulus(IExpr polynomial, List<IExpr> variablesList,
final TermOrder termOrder, IExpr option) throws JASConversionException {
try {
// found "Modulus" option => use ModIntegerRing
ModLongRing modIntegerRing = JASModInteger.option2ModLongRing((ISignedNumber) option);
JASModInteger jas = new JASModInteger(variablesList, modIntegerRing);
GenPolynomial<ModLong> polyExpr = jas.expr2JAS(polynomial);
IASTAppendable resultList = F.ListAlloc(polyExpr.length());
for (Monomial<ModLong> monomial : polyExpr) {
ModLong coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
int len = exp.length();
IASTAppendable ruleList = F.ListAlloc(len);
for (int i = 0; i < len; i++) {
ruleList.append(F.integer(exp.getVal(len - i - 1)));
}
resultList.append(F.Rule(ruleList, F.integer(coeff.getVal())));
}
return resultList;
} catch (ArithmeticException ae) {
// toInt() conversion failed
if (Config.DEBUG) {
ae.printStackTrace();
}
}
return null;
}