Search in sources :

Example 11 with VariablesSet

use of org.matheclipse.core.convert.VariablesSet in project symja_android_library by axkr.

the class NMaximize method numericEval.

@Override
public IExpr numericEval(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 3);
    if (ast.arg1().isList() && ast.arg2().isList()) {
        IAST list1 = (IAST) ast.arg1();
        IAST list2 = (IAST) ast.arg2();
        VariablesSet vars = new VariablesSet(list2);
        if (list1.isAST2()) {
            IExpr function = list1.arg1();
            IExpr listOfconstraints = list1.arg2();
            if (listOfconstraints.isAnd()) {
                // lc1 && lc2 && lc3...
                LinearObjectiveFunction objectiveFunction = getObjectiveFunction(vars, function);
                List<LinearConstraint> constraints = getConstraints(vars, listOfconstraints);
                return simplexSolver(vars, objectiveFunction, objectiveFunction, new LinearConstraintSet(constraints), GoalType.MAXIMIZE, new NonNegativeConstraint(true), PivotSelectionRule.BLAND);
            }
        }
    }
    return F.NIL;
}
Also used : LinearConstraintSet(org.hipparchus.optim.linear.LinearConstraintSet) NonNegativeConstraint(org.hipparchus.optim.linear.NonNegativeConstraint) LinearObjectiveFunction(org.hipparchus.optim.linear.LinearObjectiveFunction) LinearConstraint(org.hipparchus.optim.linear.LinearConstraint) IAST(org.matheclipse.core.interfaces.IAST) VariablesSet(org.matheclipse.core.convert.VariablesSet) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 12 with VariablesSet

use of org.matheclipse.core.convert.VariablesSet in project symja_android_library by axkr.

the class MonomialList method evaluate.

@Override
public IExpr evaluate(final IAST ast, final EvalEngine engine) {
    Validate.checkRange(ast, 2, 5);
    IExpr expr = F.evalExpandAll(ast.arg1());
    VariablesSet eVar;
    IAST symbolList = F.List();
    List<IExpr> varList;
    if (ast.isAST1()) {
        // extract all variables from the polynomial expression
        eVar = new VariablesSet(ast.arg1());
        eVar.appendToList(symbolList.args());
        varList = eVar.getArrayList();
    } else {
        symbolList = Validate.checkSymbolOrSymbolList(ast, 2);
        varList = new ArrayList<IExpr>(symbolList.size() - 1);
        for (int i = 1; i < symbolList.size(); i++) {
            varList.add(symbolList.get(i));
        }
    }
    TermOrder termOrder = TermOrderByName.Lexicographic;
    try {
        if (ast.size() > 3) {
            if (ast.arg3() instanceof IStringX) {
                // NegativeLexicographic
                String orderStr = ast.arg3().toString();
                termOrder = Options.getMonomialOrder(orderStr, termOrder);
            }
            final Options options = new Options(ast.topHead(), ast, 2, engine);
            IExpr option = options.getOption("Modulus");
            if (option.isSignedNumber()) {
                return monomialListModulus(expr, varList, termOrder, option);
            }
        }
        if (USE_JAS_POLYNOMIAL) {
            return monomialList(expr, varList, termOrder);
        } else {
            ExprPolynomialRing ring = new ExprPolynomialRing(symbolList, new ExprTermOrder(termOrder.getEvord()));
            ExprPolynomial poly = ring.create(expr);
            return poly.monomialList();
        }
    } catch (JASConversionException jce) {
        // toInt() conversion failed
        if (Config.DEBUG) {
            jce.printStackTrace();
        }
    }
    return F.NIL;
}
Also used : Options(org.matheclipse.core.eval.util.Options) TermOrder(edu.jas.poly.TermOrder) ExprTermOrder(org.matheclipse.core.polynomials.ExprTermOrder) VariablesSet(org.matheclipse.core.convert.VariablesSet) JASConversionException(org.matheclipse.core.eval.exception.JASConversionException) ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) ExprTermOrder(org.matheclipse.core.polynomials.ExprTermOrder) JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) IStringX(org.matheclipse.core.interfaces.IStringX) ExprPolynomial(org.matheclipse.core.polynomials.ExprPolynomial)

Example 13 with VariablesSet

use of org.matheclipse.core.convert.VariablesSet in project symja_android_library by axkr.

the class CoefficientRules method evaluate.

@Override
public IExpr evaluate(final IAST ast, final EvalEngine engine) {
    Validate.checkRange(ast, 2, 5);
    IExpr expr = F.evalExpandAll(ast.arg1());
    VariablesSet eVar;
    IAST symbolList = F.List();
    List<IExpr> varList;
    if (ast.isAST1()) {
        // extract all variables from the polynomial expression
        eVar = new VariablesSet(ast.arg1());
        eVar.appendToList(symbolList.args());
        varList = eVar.getArrayList();
    } else {
        symbolList = Validate.checkSymbolOrSymbolList(ast, 2);
        varList = new ArrayList<IExpr>(symbolList.size() - 1);
        for (int i = 1; i < symbolList.size(); i++) {
            varList.add((ISymbol) symbolList.get(i));
        }
    }
    TermOrder termOrder = TermOrderByName.Lexicographic;
    try {
        if (ast.size() > 3) {
            if (ast.arg3() instanceof IStringX) {
                String orderStr = ast.arg3().toString();
                termOrder = Options.getMonomialOrder(orderStr, termOrder);
            }
            final Options options = new Options(ast.topHead(), ast, 2, engine);
            IExpr option = options.getOption("Modulus");
            if (option.isSignedNumber()) {
                return coefficientRulesModulus(expr, varList, termOrder, option);
            }
        }
        if (MonomialList.USE_JAS_POLYNOMIAL) {
            return coefficientRules(expr, varList, termOrder);
        } else {
            ExprPolynomialRing ring = new ExprPolynomialRing(symbolList, new ExprTermOrder(termOrder.getEvord()));
            ExprPolynomial poly = ring.create(expr);
            return poly.coefficientRules();
        }
    } catch (JASConversionException jce) {
        // toInt() conversion failed
        if (Config.DEBUG) {
            jce.printStackTrace();
        }
    }
    return F.NIL;
}
Also used : Options(org.matheclipse.core.eval.util.Options) TermOrder(edu.jas.poly.TermOrder) ExprTermOrder(org.matheclipse.core.polynomials.ExprTermOrder) VariablesSet(org.matheclipse.core.convert.VariablesSet) JASConversionException(org.matheclipse.core.eval.exception.JASConversionException) ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) ExprTermOrder(org.matheclipse.core.polynomials.ExprTermOrder) JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) IStringX(org.matheclipse.core.interfaces.IStringX) ExprPolynomial(org.matheclipse.core.polynomials.ExprPolynomial)

Aggregations

VariablesSet (org.matheclipse.core.convert.VariablesSet)13 IAST (org.matheclipse.core.interfaces.IAST)13 IExpr (org.matheclipse.core.interfaces.IExpr)11 ExprPolynomial (org.matheclipse.core.polynomials.ExprPolynomial)4 ExprPolynomialRing (org.matheclipse.core.polynomials.ExprPolynomialRing)4 JASIExpr (org.matheclipse.core.convert.JASIExpr)3 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)3 TermOrder (edu.jas.poly.TermOrder)2 LinearConstraint (org.hipparchus.optim.linear.LinearConstraint)2 LinearConstraintSet (org.hipparchus.optim.linear.LinearConstraintSet)2 LinearObjectiveFunction (org.hipparchus.optim.linear.LinearObjectiveFunction)2 NonNegativeConstraint (org.hipparchus.optim.linear.NonNegativeConstraint)2 Options (org.matheclipse.core.eval.util.Options)2 ASTRange (org.matheclipse.core.expression.ASTRange)2 IStringX (org.matheclipse.core.interfaces.IStringX)2 ISymbol (org.matheclipse.core.interfaces.ISymbol)2 ExprTermOrder (org.matheclipse.core.polynomials.ExprTermOrder)2 HornerScheme (org.matheclipse.core.polynomials.HornerScheme)2 BigRational (edu.jas.arith.BigRational)1 Complex (edu.jas.poly.Complex)1