Search in sources :

Example 6 with IAST

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

the class List method convert.

/** {@inheritDoc} */
public boolean convert(final StringBuffer buf, final IAST ast, final int precedence) {
    int[] dims = ast.isMatrix();
    if (dims != null) {
        // create a LaTeX matrix
        buf.append("\\left(\n\\begin{array}{");
        for (int i = 0; i < dims[1]; i++) {
            buf.append("c");
        }
        buf.append("}\n");
        if (ast.size() > 1) {
            for (int i = 1; i < ast.size(); i++) {
                IAST row = ast.getAST(i);
                for (int j = 1; j < row.size(); j++) {
                    fFactory.convert(buf, row.get(j), 0);
                    if (j < row.size() - 1) {
                        buf.append(" & ");
                    }
                }
                if (i < ast.size() - 1) {
                    buf.append(" \\\\\n");
                } else {
                    buf.append(" \n");
                }
            }
        }
        buf.append("\\end{array}\n\\right) ");
    // \begin{pmatrix} x & y \\ u & v \end{pmatrix}
    // buf.append("\\begin{pmatrix} ");
    // if (ast.size() > 1) {
    // for (int i = 1; i < ast.size(); i++) {
    // IAST row = ast.getAST(i);
    // for (int j = 1; j < row.size(); j++) {
    // fFactory.convert(buf, row.get(j), 0);
    // if (j < row.size() - 1) {
    // buf.append(" & ");
    // }
    // }
    // if (i < ast.size() - 1) {
    // buf.append(" \\\\ ");
    // }
    // }
    // }
    // buf.append(" \\end{pmatrix} ");
    } else if ((ast.getEvalFlags() & IAST.IS_VECTOR) == IAST.IS_VECTOR) {
        // create a LaTeX row vector
        // \begin{pmatrix} x & y \end{pmatrix}
        buf.append("\\begin{pmatrix} ");
        if (ast.size() > 1) {
            for (int j = 1; j < ast.size(); j++) {
                fFactory.convert(buf, ast.get(j), 0);
                if (j < ast.size() - 1) {
                    buf.append(" & ");
                }
            }
        }
        buf.append(" \\end{pmatrix} ");
    } else {
        buf.append("\\{");
        if (ast.size() > 1) {
            fFactory.convert(buf, ast.arg1(), 0);
            for (int i = 2; i < ast.size(); i++) {
                buf.append(',');
                fFactory.convert(buf, ast.get(i), 0);
            }
        }
        buf.append("\\}");
    }
    return true;
}
Also used : IAST(org.matheclipse.core.interfaces.IAST)

Example 7 with IAST

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

the class Plus method convert.

/** {@inheritDoc} */
@Override
public boolean convert(final StringBuffer buf, final IAST f, final int precedence) {
    IExpr expr;
    precedenceOpen(buf, precedence);
    final Times timesConverter = new org.matheclipse.core.form.tex.reflection.Times();
    timesConverter.setFactory(fFactory);
    for (int i = 1; i < f.size(); i++) {
        expr = f.get(i);
        if ((i > 1) && (expr instanceof IAST) && expr.isTimes()) {
            timesConverter.convertTimesFraction(buf, (IAST) expr, fPrecedence, Times.PLUS_CALL);
        } else {
            if (i > 1) {
                if (expr.isNumber() && (((INumber) expr).complexSign() < 0)) {
                    buf.append("-");
                    expr = ((INumber) expr).negate();
                } else if (expr.isNegativeSigned()) {
                } else {
                    buf.append("+");
                }
            }
            fFactory.convert(buf, expr, fPrecedence);
        }
    }
    precedenceClose(buf, precedence);
    return true;
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 8 with IAST

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

the class OutputFormFactory method convertPlusArgument.

public void convertPlusArgument(final Appendable buf, IExpr plusArg, boolean caller) throws IOException {
    if (plusArg.isTimes()) {
        final IAST timesAST = (IAST) plusArg;
        // IExpr arg1 = timesAST.arg1();
        final InfixOperator TIMES_OPERATOR = (InfixOperator) ASTNodeFactory.MMA_STYLE_FACTORY.get("Times");
        convertTimesFraction(buf, timesAST, TIMES_OPERATOR, ASTNodeFactory.TIMES_PRECEDENCE, caller);
    } else {
        if (plusArg.isNegativeSigned()) {
            // special case negative number or -Infinity...
            convert(buf, plusArg);
        } else {
            if (caller == PLUS_CALL) {
                append(buf, "+");
            }
            convert(buf, plusArg, ASTNodeFactory.PLUS_PRECEDENCE, false);
        }
    }
}
Also used : IAST(org.matheclipse.core.interfaces.IAST) InfixOperator(org.matheclipse.parser.client.operator.InfixOperator)

Example 9 with IAST

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

the class OutputFormFactory method convertPlusOperatorReversed.

private void convertPlusOperatorReversed(final Appendable buf, final IAST plusAST, final InfixOperator oper, final int precedence) throws IOException {
    int operPrecedence = oper.getPrecedence();
    if (operPrecedence < precedence) {
        append(buf, "(");
    }
    String operatorStr = oper.getOperatorString();
    IExpr plusArg;
    int size = plusAST.size() - 1;
    // print Plus[] in reverse order (i.e. numbers at last)
    for (int i = size; i > 0; i--) {
        plusArg = plusAST.get(i);
        if (plusArg.isTimes()) {
            final String multCh = ASTNodeFactory.MMA_STYLE_FACTORY.get("Times").getOperatorString();
            boolean showOperator = true;
            final IAST timesAST = (IAST) plusArg;
            IExpr arg1 = timesAST.arg1();
            if (arg1.isNumber() && (((INumber) arg1).complexSign() < 0)) {
                if (((INumber) arg1).isOne()) {
                    showOperator = false;
                } else {
                    if (arg1.isMinusOne()) {
                        append(buf, "-");
                        showOperator = false;
                    } else {
                        convertNumber(buf, (INumber) arg1, operPrecedence, NO_PLUS_CALL);
                    }
                }
            } else {
                if (i < size) {
                    append(buf, operatorStr);
                }
                convert(buf, arg1, ASTNodeFactory.TIMES_PRECEDENCE, false);
            }
            IExpr timesArg;
            for (int j = 2; j < timesAST.size(); j++) {
                timesArg = timesAST.get(j);
                if (showOperator) {
                    append(buf, multCh);
                } else {
                    showOperator = true;
                }
                convert(buf, timesArg, ASTNodeFactory.TIMES_PRECEDENCE, false);
            }
        } else {
            if (plusArg.isNumber() && (((INumber) plusArg).complexSign() < 0)) {
                // special case negative number:
                convert(buf, plusArg);
            } else {
                if (i < size) {
                    append(buf, operatorStr);
                }
                convert(buf, plusArg, ASTNodeFactory.PLUS_PRECEDENCE, false);
            }
        }
    }
    if (operPrecedence < precedence) {
        append(buf, ")");
    }
}
Also used : INumber(org.matheclipse.core.interfaces.INumber) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 10 with IAST

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

the class Plus method convert.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.matheclipse.core.form.mathml.IConverter#convert(java.lang.StringBuffer, org.matheclipse.parser.interfaces.IAST, int)
	 */
@Override
public boolean convert(final StringBuffer buf, final IAST f, final int precedence) {
    IExpr expr;
    fFactory.tagStart(buf, fFirstTag);
    precedenceOpen(buf, precedence);
    final Times timesConverter = new org.matheclipse.core.form.mathml.reflection.Times();
    timesConverter.setFactory(fFactory);
    int size = f.size() - 1;
    for (int i = size; i > 0; i--) {
        expr = f.get(i);
        if ((i < size) && (expr instanceof IAST) && ((IAST) expr).head().equals(F.Times)) {
            timesConverter.convertTimesFraction(buf, (IAST) expr, fPrecedence, Times.PLUS_CALL);
        } else {
            if (i < size) {
                if ((expr instanceof ISignedNumber) && (((ISignedNumber) expr).isNegative())) {
                    fFactory.tag(buf, "mo", "-");
                    expr = ((ISignedNumber) expr).negate();
                } else {
                    fFactory.tag(buf, "mo", "+");
                }
            }
            fFactory.convert(buf, expr, fPrecedence);
        }
    }
    precedenceClose(buf, precedence);
    fFactory.tagEnd(buf, fFirstTag);
    return true;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) IExpr(org.matheclipse.core.interfaces.IExpr) 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