Search in sources :

Example 31 with IBuiltInSymbol

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

the class TeXFormFactory method convertInequality.

private boolean convertInequality(final StringBuilder buf, final IAST inequality, final int precedence) {
    StringBuilder tempBuffer = new StringBuilder();
    if (Precedence.EQUAL < precedence) {
        tempBuffer.append("(");
    }
    final int listSize = inequality.size();
    int i = 1;
    while (i < listSize) {
        convertInternal(tempBuffer, inequality.get(i++), 0);
        if (i == listSize) {
            if (Precedence.EQUAL < precedence) {
                tempBuffer.append(")");
            }
            buf.append(tempBuffer);
            return true;
        }
        IExpr head = inequality.get(i++);
        if (head.isBuiltInSymbol()) {
            int id = ((IBuiltInSymbol) head).ordinal();
            switch(id) {
                case ID.Equal:
                    tempBuffer.append(" == ");
                    break;
                case ID.Greater:
                    tempBuffer.append(" > ");
                    break;
                case ID.GreaterEqual:
                    tempBuffer.append("\\geq ");
                    break;
                case ID.Less:
                    tempBuffer.append(" < ");
                    break;
                case ID.LessEqual:
                    tempBuffer.append("\\leq ");
                    break;
                case ID.Unequal:
                    tempBuffer.append("\\neq ");
                    break;
                default:
                    return false;
            }
        } else {
            return false;
        }
    }
    if (Precedence.EQUAL < precedence) {
        tempBuffer.append(")");
    }
    buf.append(tempBuffer);
    return true;
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 32 with IBuiltInSymbol

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

the class MathMLFormFactory method convertInequality.

private boolean convertInequality(final StringBuilder buf, final IAST inequality, final int precedence) {
    StringBuilder tempBuffer = new StringBuilder();
    tagStart(tempBuffer, "mrow");
    if (Precedence.EQUAL < precedence) {
        // append(buf, "(");
        tag(tempBuffer, "mo", "(");
    }
    final int listSize = inequality.size();
    int i = 1;
    while (i < listSize) {
        convertInternal(tempBuffer, inequality.get(i++), Precedence.EQUAL, false);
        if (i == listSize) {
            if (Precedence.EQUAL < precedence) {
                // append(buf, ")");
                tag(tempBuffer, "mo", ")");
            }
            tagEnd(tempBuffer, "mrow");
            buf.append(tempBuffer);
            return true;
        }
        IExpr head = inequality.get(i++);
        if (head.isBuiltInSymbol()) {
            int id = ((IBuiltInSymbol) head).ordinal();
            switch(id) {
                case ID.Equal:
                    tag(tempBuffer, "mo", "==");
                    break;
                case ID.Greater:
                    tag(tempBuffer, "mo", "&gt;");
                    break;
                case ID.GreaterEqual:
                    tag(tempBuffer, "mo", "&gt;=");
                    break;
                case ID.Less:
                    tag(tempBuffer, "mo", "&lt;");
                    break;
                case ID.LessEqual:
                    tag(tempBuffer, "mo", "&lt;=");
                    break;
                case ID.Unequal:
                    tag(tempBuffer, "mo", "!=");
                    break;
                default:
                    return false;
            }
        } else {
            return false;
        }
    }
    if (Precedence.EQUAL < precedence) {
        // append(buf, ")");
        tag(tempBuffer, "mo", ")");
    }
    tagEnd(tempBuffer, "mrow");
    buf.append(tempBuffer);
    return true;
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 33 with IBuiltInSymbol

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

the class Documentation method getMarkdown.

/**
 * Get the pure <code>markdown</code> formatted information about the <code>builinFunctionName
 * </code>
 *
 * @param out
 * @param builinFunctionName
 * @return
 */
public static boolean getMarkdown(Appendable out, String builinFunctionName) {
    ISymbol symbol = F.symbol(builinFunctionName);
    String url = null;
    if (symbol instanceof IBuiltInSymbol) {
        url = SourceCodeFunctions.functionURL(symbol);
    }
    // read markdown file
    String fileName = buildFunctionFilename(builinFunctionName);
    // Get file from resources folder
    ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    try (BufferedReader f = getResourceReader(classloader, fileName)) {
        if (f != null) {
            String line;
            while ((line = f.readLine()) != null) {
                out.append(line);
                out.append("\n");
            }
            if (url != null) {
                out.append("[Github master](");
                out.append(url);
                out.append(")\n\n");
            }
            return true;
        }
    } catch (IOException e) {
        LOGGER.error("Documentation.getMarkdown() failed", e);
    }
    return false;
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) ISymbol(org.matheclipse.core.interfaces.ISymbol) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 34 with IBuiltInSymbol

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

the class Documentation method printDocumentation.

/**
 * Load the documentation from resource folder if available and print to output.
 *
 * @param symbolName
 */
public static boolean printDocumentation(Appendable out, String symbolName) {
    ISymbol symbol = F.symbol(symbolName);
    String url = null;
    if (symbol instanceof IBuiltInSymbol) {
        url = SourceCodeFunctions.functionURL(symbol);
    }
    // read markdown file
    String fileName = buildFunctionFilename(symbolName);
    // Get file from resources folder
    ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    try (BufferedReader f = getResourceReader(classloader, fileName)) {
        if (f != null) {
            String line;
            boolean emptyLine = false;
            while ((line = f.readLine()) != null) {
                if (line.startsWith("```")) {
                    continue;
                }
                if (line.trim().length() == 0) {
                    if (emptyLine) {
                        continue;
                    }
                    emptyLine = true;
                } else {
                    emptyLine = false;
                }
                out.append(line);
                out.append("\n");
            }
            if (url != null) {
                out.append("[Github master](");
                out.append(url);
                out.append(")\n\n");
            }
            return true;
        }
    } catch (IOException e) {
        LOGGER.error("Documentation.printDocumentation() failed", e);
    }
    return false;
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) ISymbol(org.matheclipse.core.interfaces.ISymbol) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Aggregations

IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)34 IExpr (org.matheclipse.core.interfaces.IExpr)20 IEvaluator (org.matheclipse.core.interfaces.IEvaluator)15 IAST (org.matheclipse.core.interfaces.IAST)13 ISymbol (org.matheclipse.core.interfaces.ISymbol)11 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)6 EvalEngine (org.matheclipse.core.eval.EvalEngine)5 IFunctionEvaluator (org.matheclipse.core.eval.interfaces.IFunctionEvaluator)4 IOException (java.io.IOException)3 IGraphics3D (org.matheclipse.core.graphics.IGraphics3D)3 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 BufferedReader (java.io.BufferedReader)2 ArrayList (java.util.ArrayList)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 ExprEvaluator (org.matheclipse.core.eval.ExprEvaluator)2 ComplexNum (org.matheclipse.core.expression.ComplexNum)2 Num (org.matheclipse.core.expression.Num)2 ByteArrayExpr (org.matheclipse.core.expression.data.ByteArrayExpr)2 IDistribution (org.matheclipse.core.interfaces.IDistribution)2