Search in sources :

Example 41 with ISymbol

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

the class Definition method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 2);
    ISymbol symbol = Validate.checkSymbolType(ast, 1);
    PrintStream stream;
    stream = engine.getOutPrintStream();
    if (stream == null) {
        stream = System.out;
    }
    try {
        stream.println(symbol.definitionToString());
    } catch (IOException e) {
        stream.println(e.getMessage());
        if (Config.DEBUG) {
            e.printStackTrace();
        }
    }
    return F.Null;
}
Also used : PrintStream(java.io.PrintStream) ISymbol(org.matheclipse.core.interfaces.ISymbol) IOException(java.io.IOException)

Example 42 with ISymbol

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

the class Exponent method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkRange(ast, 3, 4);
    final IExpr form = engine.evalPattern(ast.arg2());
    if (form.isList()) {
        return ((IAST) form).mapThread(ast, 2);
    }
    ISymbol sym = F.Max;
    if (ast.isAST3()) {
        final IExpr arg3 = engine.evaluate(ast.arg3());
        if (arg3.isSymbol()) {
            sym = (ISymbol) arg3;
        }
    }
    Set<IExpr> collector = new TreeSet<IExpr>();
    IExpr expr = F.evalExpandAll(ast.arg1());
    if (expr.isZero()) {
        collector.add(F.CNInfinity);
    } else if (expr.isAST()) {
        IAST arg1 = (IAST) expr;
        final IPatternMatcher matcher = new PatternMatcher(form);
        if (arg1.isPower()) {
            if (matcher.test(arg1.arg1())) {
                collector.add(arg1.arg2());
            } else {
                collector.add(F.C0);
            }
        } else if (arg1.isPlus()) {
            for (int i = 1; i < arg1.size(); i++) {
                if (arg1.get(i).isAtom()) {
                    if (arg1.get(i).isSymbol()) {
                        if (matcher.test(arg1.get(i))) {
                            collector.add(F.C1);
                        } else {
                            collector.add(F.C0);
                        }
                    } else {
                        collector.add(F.C0);
                    }
                } else if (arg1.get(i).isPower()) {
                    IAST pow = (IAST) arg1.get(i);
                    if (matcher.test(pow.arg1())) {
                        collector.add(pow.arg2());
                    } else {
                        collector.add(F.C0);
                    }
                } else if (arg1.get(i).isTimes()) {
                    timesExponent((IAST) arg1.get(i), matcher, collector);
                } else {
                    collector.add(F.C0);
                }
            }
        } else if (arg1.isTimes()) {
            timesExponent(arg1, matcher, collector);
        }
    } else if (expr.isSymbol()) {
        final PatternMatcher matcher = new PatternMatcher(form);
        if (matcher.test(expr)) {
            collector.add(F.C1);
        } else {
            collector.add(F.C0);
        }
    } else {
        collector.add(F.C0);
    }
    IAST result = F.ast(sym);
    if (collector.size() == 0) {
        collector.add(F.C0);
    }
    for (IExpr exponent : collector) {
        result.append(exponent);
    }
    return result;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) TreeSet(java.util.TreeSet) IPatternMatcher(org.matheclipse.core.patternmatching.IPatternMatcher) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) IPatternMatcher(org.matheclipse.core.patternmatching.IPatternMatcher) PatternMatcher(org.matheclipse.core.patternmatching.PatternMatcher)

Example 43 with ISymbol

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

the class Structure method threadPlusLogicEquationOperators.

/**
	 * Maps the elements of the <code>expr</code> with the cloned <code>replacement</code>. <code>replacement</code> is
	 * an IAST where the argument at the given position will be replaced by the currently mapped element.
	 * 
	 * 
	 * @param expr
	 * @param replacement
	 *            an IAST there the argument at the given position is replaced by the currently mapped argument of this
	 *            IAST.
	 * @param position
	 * @return
	 */
public static IAST threadPlusLogicEquationOperators(IExpr expr, IAST replacement, int position) {
    if (expr.isAST()) {
        IAST ast = (IAST) expr;
        if (ast.size() > 1) {
            IAST cloned = replacement.clone();
            cloned.set(position, null);
            ISymbol[] plusLogicEquationHeads = { F.Plus, F.And, F.Or, F.Xor, F.Nand, F.Nor, F.Not, F.Implies, F.Equivalent, F.Equal, F.Unequal, F.Less, F.Greater, F.LessEqual, F.GreaterEqual };
            for (int i = 0; i < plusLogicEquationHeads.length; i++) {
                if (ast.isAST(plusLogicEquationHeads[i])) {
                    return ((IAST) ast).mapThread(cloned, position);
                }
            }
        }
    }
    return F.NIL;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) IAST(org.matheclipse.core.interfaces.IAST)

Example 44 with ISymbol

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

the class Structure method threadLogicEquationOperators.

/**
	 * Maps the elements of the <code>expr</code> with the cloned <code>replacement</code>. <code>replacement</code> is
	 * an IAST where the argument at the given position will be replaced by the currently mapped element.
	 * 
	 * 
	 * @param expr
	 * @param replacement
	 *            an IAST there the argument at the given position is replaced by the currently mapped argument of this
	 *            IAST.
	 * @param position
	 * @return
	 */
public static IAST threadLogicEquationOperators(IExpr expr, IAST replacement, int position) {
    if (expr.isAST()) {
        IAST ast = (IAST) expr;
        if (ast.size() > 1) {
            IAST cloned = replacement.clone();
            cloned.set(position, null);
            ISymbol[] logicEquationHeads = { F.And, F.Or, F.Xor, F.Nand, F.Nor, F.Not, F.Implies, F.Equivalent, F.Equal, F.Unequal, F.Less, F.Greater, F.LessEqual, F.GreaterEqual };
            for (int i = 0; i < logicEquationHeads.length; i++) {
                if (ast.isAST(logicEquationHeads[i])) {
                    return ((IAST) ast).mapThread(cloned, position);
                }
            }
        }
    }
    return F.NIL;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) IAST(org.matheclipse.core.interfaces.IAST)

Example 45 with ISymbol

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

the class PatternMatching method setDownRule.

public static Object[] setDownRule(IExpr leftHandSide, IExpr rightHandSide, boolean packageMode) {
    final Object[] result = new Object[] { null, rightHandSide };
    if (leftHandSide.isAST()) {
        final ISymbol lhsSymbol = ((IAST) leftHandSide).topHead();
        result[0] = lhsSymbol.putDownRule(ISymbol.RuleType.SET, false, leftHandSide, rightHandSide, packageMode);
        return result;
    }
    if (leftHandSide.isSymbol()) {
        final ISymbol lhsSymbol = (ISymbol) leftHandSide;
        if (lhsSymbol.hasLocalVariableStack()) {
            lhsSymbol.set(rightHandSide);
            return result;
        }
        result[0] = lhsSymbol.putDownRule(ISymbol.RuleType.SET, true, leftHandSide, rightHandSide, packageMode);
        return result;
    }
    throw new RuleCreationError(leftHandSide);
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) IPatternObject(org.matheclipse.core.interfaces.IPatternObject) IAST(org.matheclipse.core.interfaces.IAST) RuleCreationError(org.matheclipse.core.eval.exception.RuleCreationError)

Aggregations

ISymbol (org.matheclipse.core.interfaces.ISymbol)117 IExpr (org.matheclipse.core.interfaces.IExpr)79 IAST (org.matheclipse.core.interfaces.IAST)76 IInteger (org.matheclipse.core.interfaces.IInteger)18 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)12 INum (org.matheclipse.core.interfaces.INum)10 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)10 IFraction (org.matheclipse.core.interfaces.IFraction)9 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)8 IComplex (org.matheclipse.core.interfaces.IComplex)7 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)7 ArrayList (java.util.ArrayList)6 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)6 HashSet (java.util.HashSet)5 EvalEngine (org.matheclipse.core.eval.EvalEngine)5 Num (org.matheclipse.core.expression.Num)5 GenPolynomial (edu.jas.poly.GenPolynomial)4 Options (org.matheclipse.core.eval.util.Options)4 ExprPolynomialRing (org.matheclipse.core.polynomials.ExprPolynomialRing)4 ExpVector (edu.jas.poly.ExpVector)3