Search in sources :

Example 1 with ISymbol

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

the class Sum method iteratorStep.

/**
	 * See <a href="http://en.wikibooks.org/wiki/LaTeX/Mathematics">Wikibooks -
	 * LaTeX/Mathematics</a>
	 * 
	 * @param buf
	 * @param mathSymbol
	 *            the symbol for Sum or Product expressions
	 * @param f
	 * @param i
	 * 
	 * @return <code>true</code> if the expression could be transformed to LaTeX
	 */
public boolean iteratorStep(final StringBuffer buf, final String mathSymbol, final IAST f, int i) {
    if (i >= f.size()) {
        buf.append(" ");
        fFactory.convertSubExpr(buf, f.arg1(), 0);
        return true;
    }
    if (f.get(i).isList()) {
        IIterator iterator = Iterator.create((IAST) f.get(i), EvalEngine.get());
        if (iterator.isValidVariable() && iterator.getStep().isOne()) {
            buf.append(mathSymbol);
            buf.append("_{");
            fFactory.convertSubExpr(buf, iterator.getVariable(), 0);
            buf.append(" = ");
            fFactory.convertSubExpr(buf, iterator.getLowerLimit(), 0);
            buf.append("}^{");
            fFactory.convert(buf, iterator.getUpperLimit(), 0);
            buf.append('}');
            if (!iteratorStep(buf, mathSymbol, f, i + 1)) {
                return false;
            }
            return true;
        }
    } else if (f.get(i).isSymbol()) {
        ISymbol symbol = (ISymbol) f.get(i);
        buf.append(mathSymbol);
        buf.append("_{");
        fFactory.convertSymbol(buf, symbol);
        buf.append("}");
        if (!iteratorStep(buf, mathSymbol, f, i + 1)) {
            return false;
        }
        return true;
    }
    return false;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) IIterator(org.matheclipse.core.generic.interfaces.IIterator)

Example 2 with ISymbol

use of org.matheclipse.core.interfaces.ISymbol 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 ISymbol

use of org.matheclipse.core.interfaces.ISymbol 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 ISymbol

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

the class CompareToTestCase method testIssue122c.

public void testIssue122c() {
    ISymbol b = F.$s("b");
    ISymbol c = F.$s("c");
    ISymbol x1 = F.$s("x1");
    ISymbol x3 = F.$s("x3");
    ISymbol x4 = F.$s("x4");
    ISymbol x5 = F.$s("x5");
    IPattern x1_c = F.$p(x1, c);
    IPattern x3_b = F.$p(x3, b);
    IPattern x3_c = F.$p(x3, c);
    IPattern x5_c = F.$p(x5, c);
    IAST ast1 = F.Times(x3, x5, x5_c);
    IAST ast2 = F.Times(F.CN1, x1_c, x3_b, x3_c);
    int res = ast1.compareTo(ast2);
    assertEquals(2, res);
    res = ast2.compareTo(ast1);
    assertEquals(-2, res);
    check("-Infinity+b+a", "-Infinity+a+b");
}
Also used : IPattern(org.matheclipse.core.interfaces.IPattern) ISymbol(org.matheclipse.core.interfaces.ISymbol) IAST(org.matheclipse.core.interfaces.IAST)

Example 5 with ISymbol

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

the class CompareToTestCase method testIssue122a.

public void testIssue122a() {
    ISymbol b = F.$s("b");
    ISymbol c = F.$s("c");
    ISymbol x1 = F.$s("x1");
    ISymbol x3 = F.$s("x3");
    ISymbol x4 = F.$s("x4");
    ISymbol x5 = F.$s("x5");
    IPattern x1_c = F.$p(x1, c);
    IPattern x3_b = F.$p(x3, b);
    IPattern x3_c = F.$p(x3, c);
    IPattern x4_c = F.$p(x4, c);
    IAST ast1 = F.Times(F.CN1, x1_c, x3_b, x3_c);
    IAST ast2 = F.Times(F.CN1, x3, x5, x1_c, x4_c);
    int res = ast1.compareTo(ast2);
    assertEquals(-1, res);
    res = ast2.compareTo(ast1);
    assertEquals(1, res);
    check("-Infinity+b+a", "-Infinity+a+b");
}
Also used : IPattern(org.matheclipse.core.interfaces.IPattern) ISymbol(org.matheclipse.core.interfaces.ISymbol) IAST(org.matheclipse.core.interfaces.IAST)

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