Search in sources :

Example 86 with IAST

use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.

the class F method expand.

/**
	 * Apply <code>Expand()</code> to the given expression if it's an <code>IAST</code>. If expanding wasn't possible
	 * this method returns the given argument.
	 * 
	 * @param a
	 *            the expression which should be evaluated
	 * @param expandNegativePowers
	 *            TODO
	 * @param distributePlus
	 *            TODO
	 * @return the evaluated expression
	 * @see EvalEngine#evaluate(IExpr)
	 */
public static IExpr expand(IExpr a, boolean expandNegativePowers, boolean distributePlus) {
    if (a.isAST()) {
        EvalEngine engine = EvalEngine.get();
        IAST ast = engine.evalFlatOrderlessAttributesRecursive((IAST) a);
        if (!ast.isPresent()) {
            ast = (IAST) a;
        }
        return Algebra.expand(ast, null, expandNegativePowers, distributePlus).orElse(a);
    }
    return a;
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) IAST(org.matheclipse.core.interfaces.IAST)

Example 87 with IAST

use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.

the class AbstractIntegerSym method factorInteger.

/** {@inheritDoc} */
@Override
public IAST factorInteger() {
    IInteger factor;
    IInteger last = F.CN2;
    int count = 0;
    final IAST iFactors = factorize(F.ListAlloc(10));
    final IAST list = List();
    IAST subList = null;
    for (int i = 1; i < iFactors.size(); i++) {
        factor = (IInteger) iFactors.get(i);
        if (!last.equals(factor)) {
            if (subList != null) {
                subList.append(AbstractIntegerSym.valueOf(count));
                list.append(subList);
            }
            count = 0;
            subList = F.ListAlloc(2);
            subList.append(factor);
        }
        count++;
        last = factor;
    }
    if (subList != null) {
        subList.append(AbstractIntegerSym.valueOf(count));
        list.append(subList);
    }
    return list;
}
Also used : IInteger(org.matheclipse.core.interfaces.IInteger) IAST(org.matheclipse.core.interfaces.IAST)

Example 88 with IAST

use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.

the class IntegerSym method divisors.

/**
	 * Return the divisors of this integer number.
	 * 
	 * <pre>
	 * divisors(24) ==> {1,2,3,4,6,8,12,24}
	 * </pre>
	 */
@Override
public IAST divisors() {
    if (isOne() || isMinusOne()) {
        return F.List(F.C1);
    }
    Set<IInteger> set = new TreeSet<IInteger>();
    final IAST primeFactorsList = factorize(F.List());
    int len = primeFactorsList.size() - 1;
    // build the k-subsets from the primeFactorsList
    for (int k = 1; k < len; k++) {
        final KSubsetsList iter = Subsets.createKSubsets(primeFactorsList, k, F.List(), 1);
        for (IAST subset : iter) {
            if (subset == null) {
                break;
            }
            // create the product of all integers in the k-subset
            IInteger factor = F.C1;
            for (int j = 1; j < subset.size(); j++) {
                factor = factor.multiply((IInteger) subset.get(j));
            }
            // add this divisor to the set collection
            set.add(factor);
        }
    }
    // build the final divisors list from the tree set
    final IAST resultList = F.ListAlloc(set.size() + 1);
    resultList.append(F.C1);
    for (IInteger entry : set) {
        resultList.append(entry);
    }
    resultList.append(this);
    return resultList;
}
Also used : TreeSet(java.util.TreeSet) IInteger(org.matheclipse.core.interfaces.IInteger) IAST(org.matheclipse.core.interfaces.IAST) KSubsetsList(org.matheclipse.core.builtin.Combinatoric.Subsets.KSubsetsList)

Example 89 with IAST

use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.

the class F method eval.

/**
	 * Create a function with 1 argument and evaluate it.
	 * 
	 * @param head
	 * @param a0
	 * @return the evaluated object
	 */
public static IExpr eval(final ISymbol head, final IExpr a0) {
    final IAST ast = ast(head);
    ast.append(a0);
    return EvalEngine.get().evaluate(ast);
}
Also used : IAST(org.matheclipse.core.interfaces.IAST)

Example 90 with IAST

use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.

the class F method Times.

public static IAST Times(final IExpr a0, final IExpr a1) {
    if (a0 != null && a1 != null) {
        if (a0.isTimes() || a1.isTimes()) {
            int size = 0;
            if (a0.isTimes()) {
                size += ((IAST) a0).size();
            } else {
                size++;
            }
            if (a1.isTimes()) {
                size += ((IAST) a1).size();
            } else {
                size++;
            }
            IAST result = TimesAlloc(size);
            if (a0.isTimes()) {
                result.appendArgs((IAST) a0);
            } else {
                result.append(a0);
            }
            if (a1.isTimes()) {
                result.appendArgs((IAST) a1);
            } else {
                result.append(a1);
            }
            EvalAttributes.sort(result);
            return result;
        }
        if (a0.compareTo(a1) > 0) {
            // swap arguments
            return binary(Times, a1, a0);
        }
    }
    return binary(Times, a0, a1);
}
Also used : IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

IAST (org.matheclipse.core.interfaces.IAST)413 IExpr (org.matheclipse.core.interfaces.IExpr)248 ISymbol (org.matheclipse.core.interfaces.ISymbol)76 IInteger (org.matheclipse.core.interfaces.IInteger)34 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)30 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)22 ExpVector (edu.jas.poly.ExpVector)15 ArrayList (java.util.ArrayList)14 BigRational (edu.jas.arith.BigRational)13 JASIExpr (org.matheclipse.core.convert.JASIExpr)13 VariablesSet (org.matheclipse.core.convert.VariablesSet)13 INum (org.matheclipse.core.interfaces.INum)13 ExprPolynomial (org.matheclipse.core.polynomials.ExprPolynomial)12 GenPolynomial (edu.jas.poly.GenPolynomial)11 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)11 IFraction (org.matheclipse.core.interfaces.IFraction)11 INumber (org.matheclipse.core.interfaces.INumber)11 IComplex (org.matheclipse.core.interfaces.IComplex)10 ModLong (edu.jas.arith.ModLong)9 ExprPolynomialRing (org.matheclipse.core.polynomials.ExprPolynomialRing)9