Search in sources :

Example 61 with IAST

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

the class Limit method convert.

/** {@inheritDoc} */
public boolean convert(final StringBuffer buf, final IAST f, final int precedence) {
    if (f.isAST2() && f.arg2().isRuleAST()) {
        final IAST rule = (IAST) f.arg2();
        buf.append("\\lim_{");
        fFactory.convertSubExpr(buf, rule.arg1(), 0);
        buf.append("\\to ");
        fFactory.convertSubExpr(buf, rule.arg2(), 0);
        buf.append(" }\\,");
        fFactory.convertSubExpr(buf, f.arg1(), 0);
        // fFactory.convert(buf, f.arg1(), 0);
        return true;
    }
    return false;
}
Also used : IAST(org.matheclipse.core.interfaces.IAST)

Example 62 with IAST

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

the class Symbol method definitionToString.

/** {@inheritDoc} */
@Override
public String definitionToString() throws IOException {
    StringWriter buf = new StringWriter();
    OutputFormFactory off = OutputFormFactory.get(EvalEngine.get().isRelaxedSyntax());
    off.setIgnoreNewLine(true);
    List<IAST> list = definition();
    buf.append("{");
    for (int i = 0; i < list.size(); i++) {
        off.convert(buf, list.get(i));
        if (i < list.size() - 1) {
            buf.append(",\n ");
            off.setColumnCounter(0);
        }
    }
    buf.append("}\n");
    return buf.toString();
}
Also used : StringWriter(java.io.StringWriter) IAST(org.matheclipse.core.interfaces.IAST) OutputFormFactory(org.matheclipse.core.form.output.OutputFormFactory)

Example 63 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 64 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 65 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)

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