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;
}
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());
}
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());
}
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");
}
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");
}
Aggregations