Search in sources :

Example 56 with IAST

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

the class ExprParser method getFunction.

/**
	 * Get a function f[...][...]
	 * 
	 */
IAST getFunction(final IExpr head) throws SyntaxError {
    final IAST function = F.ast(head, 10, false);
    getNextToken();
    if (fRelaxedSyntax) {
        if (fToken == TT_PRECEDENCE_CLOSE) {
            getNextToken();
            if (fToken == TT_PRECEDENCE_OPEN) {
                return function;
            }
            if (fToken == TT_ARGUMENTS_OPEN) {
                return getFunctionArguments(function);
            }
            return function;
        }
    } else {
        if (fToken == TT_ARGUMENTS_CLOSE) {
            getNextToken();
            if (fToken == TT_ARGUMENTS_OPEN) {
                return getFunctionArguments(function);
            }
            return function;
        }
    }
    fRecursionDepth++;
    try {
        getArguments(function);
    } finally {
        fRecursionDepth--;
    }
    if (fRelaxedSyntax) {
        if (fToken == TT_PRECEDENCE_CLOSE) {
            getNextToken();
            if (fToken == TT_PRECEDENCE_OPEN) {
                return function;
            }
            if (fToken == TT_ARGUMENTS_OPEN) {
                return getFunctionArguments(function);
            }
            return function;
        }
    } else {
        if (fToken == TT_ARGUMENTS_CLOSE) {
            getNextToken();
            if (fToken == TT_ARGUMENTS_OPEN) {
                return getFunctionArguments(function);
            }
            return function;
        }
    }
    if (fRelaxedSyntax) {
        throwSyntaxError("')' expected.");
    } else {
        throwSyntaxError("']' expected.");
    }
    return null;
}
Also used : IAST(org.matheclipse.core.interfaces.IAST)

Example 57 with IAST

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

the class ExprParser method rewriteLessGreaterAST.

/**
	 * Convert less or greater relations on input. Example: convert expressions like <code>a<b<=c</code> to
	 * <code>Less[a,b]&&LessEqual[b,c]</code>.
	 * 
	 * @param ast
	 * @param compareHead
	 * @return
	 */
private IExpr rewriteLessGreaterAST(final IAST ast, ISymbol compareHead) {
    IExpr temp;
    boolean evaled = false;
    IAST andAST = F.ast(F.And);
    for (int i = 1; i < ast.size(); i++) {
        temp = ast.get(i);
        if (temp.isASTSizeGE(compareHead, 3)) {
            IAST lt = (IAST) temp;
            andAST.append(lt);
            ast.set(i, lt.get(lt.size() - 1));
            evaled = true;
        }
    }
    if (evaled) {
        andAST.append(ast);
        return andAST;
    } else {
        return ast;
    }
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) Apint(org.apfloat.Apint)

Example 58 with IAST

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

the class OutputFormFactory method convertPart.

/**
	 * This method will only be called if <code>list.isAST2()==true</code> and the head equals "Part".
	 * 
	 * @param buf
	 * @param list
	 * @throws IOException
	 */
public void convertPart(final Appendable buf, final IAST list) throws IOException {
    IExpr arg1 = list.arg1();
    if (!(arg1 instanceof IAST)) {
        append(buf, "(");
    }
    convert(buf, arg1);
    append(buf, "[[");
    for (int i = 2; i < list.size(); i++) {
        convert(buf, list.get(i));
        if (i < list.size() - 1) {
            append(buf, ",");
        }
    }
    append(buf, "]]");
    if (!(arg1 instanceof IAST)) {
        append(buf, ")");
    }
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 59 with IAST

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

the class MathMLContentFormFactory method convert.

public void convert(final StringBuffer buf, final IExpr o, final int precedence) {
    if (o instanceof IAST) {
        final IAST f = ((IAST) o);
        // System.out.println(f.getHeader().toString());
        // IConverter converter = (IConverter)
        // operTab.get(f.getHeader().toString());
        // if (converter == null) {
        // converter = reflection(f.getHeader().toString());
        // if (converter == null || (converter.convert(buf, f, 0) == false))
        // {
        // convertHeadList(buf, f);
        // }
        // } else {
        // if (converter.convert(buf, f, precedence) == false) {
        // convertHeadList(buf, f);
        // }
        // }
        IAST ast = f;
        IAST temp;
        if (f.topHead().hasFlatAttribute()) {
            // associative
            if ((temp = EvalAttributes.flatten(f)).isPresent()) {
                ast = temp;
            }
        }
        IExpr h = ast.head();
        if (h.isSymbol()) {
            IConverter converter = reflection(((ISymbol) h).getSymbolName());
            if (converter != null) {
                StringBuffer sb = new StringBuffer();
                if (converter.convert(sb, ast, precedence)) {
                    buf.append(sb);
                    return;
                }
            }
        }
        convertAST(buf, ast);
        return;
    }
    if (o instanceof INum) {
        convertDouble(buf, (INum) o, precedence);
        return;
    }
    if (o instanceof IComplexNum) {
        convertDoubleComplex(buf, (IComplexNum) o, precedence);
        return;
    }
    if (o instanceof IInteger) {
        convertInteger(buf, (IInteger) o, precedence);
        return;
    }
    if (o instanceof IFraction) {
        convertFraction(buf, (IFraction) o, precedence);
        return;
    }
    if (o instanceof IComplex) {
        convertComplex(buf, (IComplex) o, precedence);
        return;
    }
    if (o instanceof ISymbol) {
        convertSymbol(buf, (ISymbol) o);
        return;
    }
    convertString(buf, o.toString());
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IComplex(org.matheclipse.core.interfaces.IComplex) ISymbol(org.matheclipse.core.interfaces.ISymbol) IInteger(org.matheclipse.core.interfaces.IInteger) IComplexNum(org.matheclipse.core.interfaces.IComplexNum) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr) INum(org.matheclipse.core.interfaces.INum)

Example 60 with IAST

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

the class MathMLFormFactory method convert.

public void convert(final StringBuffer buf, final IExpr o, final int precedence) {
    String str = CONSTANT_EXPRS.get(o);
    if (str != null) {
        buf.append(str);
        return;
    }
    if (o instanceof IAST) {
        final IAST f = ((IAST) o);
        IAST ast = f;
        IAST temp;
        if (f.topHead().hasFlatAttribute()) {
            // associative
            if ((temp = EvalAttributes.flatten(f)).isPresent()) {
                ast = temp;
            }
        }
        IExpr h = ast.head();
        if (h.isSymbol()) {
            IConverter converter = reflection(((ISymbol) h).getSymbolName());
            if (converter != null) {
                StringBuffer sb = new StringBuffer();
                if (converter.convert(sb, ast, precedence)) {
                    buf.append(sb);
                    return;
                }
            }
        }
        convertAST(buf, ast);
        return;
    }
    if (o instanceof INum) {
        convertDouble(buf, (INum) o, precedence);
        return;
    }
    if (o instanceof IComplexNum) {
        convertDoubleComplex(buf, (IComplexNum) o, precedence);
        return;
    }
    if (o instanceof IInteger) {
        convertInteger(buf, (IInteger) o, precedence);
        return;
    }
    if (o instanceof IFraction) {
        convertFraction(buf, (IFraction) o, precedence);
        return;
    }
    if (o instanceof IComplex) {
        convertComplex(buf, (IComplex) o, precedence);
        return;
    }
    if (o instanceof ISymbol) {
        convertSymbol(buf, (ISymbol) o);
        return;
    }
    convertString(buf, o.toString());
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IComplex(org.matheclipse.core.interfaces.IComplex) ISymbol(org.matheclipse.core.interfaces.ISymbol) IInteger(org.matheclipse.core.interfaces.IInteger) IComplexNum(org.matheclipse.core.interfaces.IComplexNum) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr) INum(org.matheclipse.core.interfaces.INum)

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