public PSymbol this[PSymbol value]
 {
     get
     {
         PSymbol ret = new PSymbol("sin(" + value.Expression + ")");
         return(ret);
     }
 }
Beispiel #2
0
 public PSymbol this[string variable]
 {
     get
     {
         PSymbol ret = new PSymbol(variable);
         Variables.Add(variable);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ret.Variable = variable;
         ret.parent = this;
         return(ret);
     }
 }
        public static PSymbol DF(PSymbol psym)
        {
            PSymbol ret = null;

            TokenFactory tf = new TokenFactory();

            tf.ParseExpression(psym.Expression);

            foreach (Symbol sym in tf.symbolList)
            {
            }
            return(ret);
        }
        public static PSymbol operator ^(PSymbol a, PSymbol b)
        {
            SetParent(a, b);
            PSymbol ret = new PSymbol(a.Expression + "^" + b.Expression);

            if (a.Expression.IndexOf(" + ") != -1)
            {
                ret = new PSymbol("(" + a.Expression + ")^" + b.Expression);
            }
            ret.parent = a.parent;
            ret.lstSymbols.Add(a);
            ret.lstSymbols.Add(b);
            return(ret);
        }
        public static int Test_SymbolStuff()
        {
            PSymbolFactory pf = new PSymbolFactory();

            PSymbol x = pf["x"];
            PSymbol y = pf["y"];

            Sin sin = new Sin();

            PSymbol r = 2 * x ^ 2 * sin[x];

            //PSymbol r2 = r^3;
            Console.WriteLine("{0}", DerivativeStatePattern.DF(r));
            return(0);
        }
        private static void SetId(PSymbol sym)
        {
            long id = 1;

            if (lstIds.Count == 0)
            {
                lstIds.Add(1);
            }
            else
            {
                id = lstIds[lstIds.Count - 1] + 1;
                lstIds.Add(id);
            }

            sym.PSymbolId = id;

            htSymbols[id] = sym;
        }
        public static PSymbol operator /(PSymbol a, PSymbol b)
        {
            PSymbol ret = null;

            SetParent(a, b);
            if (a.Expression == b.Expression)
            {
                ret = new PSymbol("1");
            }
            else
            {
                ret = new PSymbol(a.Expression + "/" + b.Expression);
            }

            ret.parent = a.parent;
            ret.lstSymbols.Add(a);
            ret.lstSymbols.Add(b);
            return(ret);
        }
        private static void SetParent(PSymbol a, PSymbol b)
        {
            if (a.parent != null && b.parent != null)
            {
                return;
            }

            if (a.parent == null && b.parent == null)
            {
                a.parent = b.parent = new PSymbolFactory();
            }
            else if (a.parent != null && b.parent == null)
            {
                b.parent = a.parent;
            }
            else if (b.parent != null && a.parent == null)
            {
                a.parent = b.parent;
            }
        }
        public static PSymbol SymbolToPSymbol(Symbol sym)
        {
            PSymbol ret = new PSymbol();

            for (int i = 0; i < sym.Tokens.Count; i++)
            {
                Token t = sym.Tokens[i];
                if (t.Type == "Literal")
                {
                    ret += new PSymbol(Rational.Parse(t.Value));
                }
                else if (t.Type == "Variable")
                {
                    if (i > 0 && sym.Tokens[i - 1].Type == "Literal")
                    {
                    }
                }
            }

            return(ret);
        }
Beispiel #10
0
        public static string DF(PSymbol psym)
        {
            string exp = psym.Expression.Replace("*", "");

            return(DF(new Symbol(exp), true));
        }