/// <summary> /// Creates formula /// </summary> /// <param name="tree">Operation tree</param> /// <param name="level">Formula level</param> /// <param name="sizes">Sizes of symbols</param> /// <returns>The formula</returns> public MathFormula CreateFormula(ObjectFormulaTree tree, byte level, int[] sizes) { MathFormula form = new MathFormula(level, sizes); MathSymbol sym = new SeriesSymbol(index); sym.Append(form); sym = new BracketsSymbol(); sym.Append(form); form.Last[0] = FormulaCreator.CreateFormula(tree[0], level, sizes); form.Last[1] = new MathFormula((byte)(level + 1), sizes); return(form); }
/// <summary> /// Creates symbol from string vector and sets it to formula /// </summary> /// <param name="f">the formula to set</param> /// <param name="v">the string vector</param> /// <param name="b">the begin position of symbol on string vector</param> /// <param name="e">the end position of symbol on string vector</param> /// <returns>The symbol</returns> public static MathSymbol CreateSymbol(MathFormula f, List <byte[]> v, int b, int e) { char c = (char)GetByte(v, b); byte by = GetByte(v, b + 1); char cb = (char)by; MathSymbol s = null; switch (by) { case (byte)'1': if (c == '%') { s = new SimpleSymbol('%', (byte)FormulaConstants.Variable, true, "\u03c0"); break; } s = new SimpleSymbol(c); break; case (byte)'2': if (c == 'P') { s = new BracketsSymbol(); } else if (c == 'F') { s = new FractionSymbol(); } else if (c == 'A') { s = new BinaryFunctionSymbol('A', "atan2"); } else if (c == 'M') { return(new AbsSymbol()); } else { s = new RootSymbol(); } break; case (byte)'3': string ss = ""; ss += c; if (c == (byte)'*') { ss = "\u2219"; } s = new BinarySymbol(c, false, ss); break; case (byte)'4': s = new SimpleSymbol(c, false, (byte)FormulaConstants.Unary); break; case (byte)'5': s = new SimpleSymbol(c, false, (byte)FormulaConstants.Number); break; case (byte)'7': s = new SeriesSymbol(Int32.Parse(c + "")); break; } s.Append(f); MathSymbol symb = f.Last; int j = b + SHIFT; if (symb.Count > 0) { for (int i = 0; i < symb.Count; i++) { int m = 0; for (int k = j; /*k <= e*/; k++) { byte bt = GetByte(v, k); if (bt == BEGIN_SEPARATOR) { m++; } else if (bt == END_SEPARATOR) { m--; } if (m == 0) { if (symb[i] != null) { MathFormula formula = new MathFormula(symb[i].Level, f.Sizes, v, j + 1, k - 1); symb[i] = formula; j = k + 1; break; } } } } } return(symb); }
/// <summary> /// Detects operation /// </summary> /// <param name="s">First symbol of the formula</param> /// <returns>Acceptor of operation</returns> public override IOperationAcceptor Detect(MathSymbol s) { //Double a = 0; if (s.Symbol == '~') { return(new BitwiseOperation()); } if (s.Symbol == '¬') { return(NegationOperation.Object); } if (s.Symbol == '-') { return(Minus); } if (s.Symbol == '\u03B4') { return(new DeltaFunction()); } if (s is SeriesSymbol) { SeriesSymbol ss = s as SeriesSymbol; if (ss.Acceptor is IUnary) { return(new ElementaryUnaryOperation(ss.Acceptor as IUnary, ss.Index)); } return(ss.Acceptor); } if (s is TernaryFunctionSymbol) { if (s.Symbol == '3') { return(TernaryBrackets.Singleton); } } if (s is BinaryFunctionSymbol) { if (s.Symbol == '2') { return(BinaryBrackets.Singleton); } return(ElementaryAtan2.Object); } if (s is RootSymbol) { return(new ElementaryRoot()); } if (s is FractionSymbol) { return(ElementaryFraction.Object); } if (s is BracketsSymbol) { return(Brakets); } if (s is SubscriptedSymbol) { SubscriptedSymbol sym = s as SubscriptedSymbol; if (table != null) { } return(new ElementaryObjectVariable(sym.Pair, table)); } if (s.SymbolType == (byte)FormulaConstants.Variable) { if (s.Symbol == '%') { return(new TranscredentRealConstant('p')); } if (s.Symbol == 'e') { return(new TranscredentRealConstant('e')); } if (s.String.Equals("True")) { return(new BooleanConstant(true)); } if (s.String.Equals("False")) { return(new BooleanConstant(false)); } IOperationAcceptor var = detector.Detect(s); if (var != null) { return(var); } else { return(null); } } if (s.SymbolType == (byte)FormulaConstants.Number) { if (s.Symbol == '?') { return(new ElementaryRealConstant(s.DoubleValue)); } else { return(new ElementaryULongConstant(s.ULongValue)); } } if (s.SymbolType == (byte)FormulaConstants.Unary & s.Symbol != '\u2211' & !(s.Symbol + "").Equals("'")) { string str = s.Symbol + ""; if (str.Equals(str.ToLower())) { if (s.Symbol == 'w') { return(new TimeOperation()); } if (s.Symbol == 'o') { return(TimeToDoubleOperation.Object); } return(new ElementaryFunctionOperation(s.Symbol)); } return(new ElementaryIntegerOperation(s.Symbol)); } return(null); }
/// <summary> /// Detects operation /// </summary> /// <param name="s">First symbol of the formula</param> /// <returns>Acceptor of operation</returns> public virtual IOperationAcceptor Detect(MathSymbol s) { if (s.Symbol == '~') { return(new BitwiseOperation()); } if (s.Symbol == '¬') { return(NegationOperation.Object); } if (s.Symbol == '-') { return(Minus); } if (s is SeriesSymbol) { SeriesSymbol ss = s as SeriesSymbol; if (ss.Acceptor is IUnary) { return(new ElementaryUnaryOperation(ss.Acceptor as IUnary, ss.Index)); } return(ss.Acceptor); } if (s is BinaryFunctionSymbol) { return(ElementaryAtan2.Object); } if (s is RootSymbol) { return(new ElementaryRoot()); } if (s is FractionSymbol) { return(ElementaryFraction.Object); } if (s is BracketsSymbol) { return(Brakets); } if (s is AbsSymbol) { return(new ElementaryAbs()); } if (s.SymbolType == (byte)FormulaConstants.Variable) { if (s.Symbol == '%') { return(new TranscredentRealConstant('p')); } if (s.Symbol == 'e') { return(new TranscredentRealConstant('e')); } return(new ElementaryObjectVariable(s.Symbol)); } if (s.SymbolType == (byte)FormulaConstants.Number) { return(new ElementaryRealConstant(s.DoubleValue)); } if (s.SymbolType == (byte)FormulaConstants.Unary & s.Symbol != '\u2211' & !(s.Symbol + "").Equals("'")) { string str = s.Symbol + ""; if (str.Equals(str.ToLower())) { return(new ElementaryFunctionOperation(s.Symbol)); } return(new ElementaryIntegerOperation(s.Symbol)); } if (s is SimpleSymbol) { SimpleSymbol ss = s as SimpleSymbol; if (!ss.Bold & !ss.Italic) { return(new StringOperationAcceptor(ss.String)); } } return(null); }