Search in sources :

Example 1 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 2 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 3 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)

Example 4 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 5 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)

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