/// <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 = null; if (symbol is Char) { sym = new SimpleSymbol((char)symbol); } else if (symbol is StringPair) { StringPair sp = symbol as StringPair; sym = new SubscriptedSymbol(sp.First, sp.Second); } sym.Append(form); return(form); }
/// <summary> /// Converts symbol to string /// </summary> /// <param name="symbol">The sybmol</param> /// <returns>Conversion result</returns> public override string Convert(MathSymbol symbol) { string str = ""; if (symbol is SubscriptedSymbol) { SubscriptedSymbol sym = symbol as SubscriptedSymbol; StringPair p = sym.Pair; str = "\u2220|" + p.First + "|" + p.Second + "|"; } else if (symbol is FieldSymbol) { FieldSymbol sym = symbol as FieldSymbol; str = "\u2221|" + sym.String + "|"; } else { if (symbol.SymbolType == (int)FormulaConstants.Series) { string s = symbol.Index + ""; str += s; } else { str += symbol.Symbol; } Int32 t = symbol.SymbolType; char b = (t.ToString()[0]); str += b; } if (symbol.Count > 0) { for (int i = 0; i < symbol.Count; i++) { string vec = Convert(symbol[i]); str += "" + Separator + "" + BeginSeparator + vec + Separator + "" + EndSeparator; } } return(str); }
/// <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); }