Ejemplo n.º 1
0
 /// <summary>
 /// Converts all sub-variables into an equation
 /// or into its value
 /// </summary>
 /// <returns>output new equation</returns>
 public override IArithmetic Converting()
 {
     if (this.IsVariableExists(this.Name))
     {
         IArithmetic f = this.GetVariable(this.Name);
         if (f is Function)
         {
             Function fe = f as Function;
             for (int index = 0; index < fe.Parameters.Count; ++index)
             {
                 if (fe.Parameters[index] is Coefficient)
                 {
                     Coefficient coeff = fe.Parameters[index] as Coefficient;
                     this.AddVariable(coeff.Name, this.Parameters[index].Converting());
                 }
                 if (fe.Parameters[index] is UnknownTerm)
                 {
                     UnknownTerm xt = fe.Parameters[index] as UnknownTerm;
                     this.AddVariable(xt.Name, this.Parameters[index].Converting());
                 }
                 if (fe.Parameters[index] is Function)
                 {
                     Function fun = fe.Parameters[index] as Function;
                     this.AddVariable(fun.Name, this.Parameters[index].Converting());
                 }
             }
             return(fe.RightOperand.Converting());
         }
     }
     return(this);
 }
Ejemplo n.º 2
0
        private Arithmetic calculate()
        {
            Arithmetic a = null, b = null;
            Arithmetic res = new NumericValue(0.0d);

            switch (this.stock[this.index])
            {
            case '=':
                ++this.index;
                a   = this.calculate();
                b   = this.calculate();
                res = new Equal(a, b);
                break;

            case '+':
                ++this.index;
                a   = this.calculate();
                b   = this.calculate();
                res = new Addition(a, b);
                break;

            case '-':
                ++this.index;
                a   = this.calculate();
                b   = this.calculate();
                res = new Soustraction(a, b);
                break;

            case '*':
                ++this.index;
                a   = this.calculate();
                b   = this.calculate();
                res = new Multiplication(a, b);
                break;

            case '/':
                ++this.index;
                a   = this.calculate();
                b   = this.calculate();
                res = new Division(a, b);
                break;

            case '^':
                ++this.index;
                a   = this.calculate();
                b   = this.calculate();
                res = new Power(a, b);
                break;

            case 'v':
                ++this.index;
                a   = this.calculate();
                b   = this.calculate();
                res = new Root(a, b);
                break;

            case 'p':
                ++this.index;
                string funp = this.words[(int)this.stock[this.index]];
                res = new Parenthese(Expression.Convert(funp));
                ++this.index;
                break;

            case 'g':
                ++this.index;
                string fung = this.words[(int)this.stock[this.index]];
                res = new Crochet(Expression.Convert(fung));
                ++this.index;
                break;

            case '@':
                ++this.index;
                res = new NumericValue((double)this.stock[this.index]);
                ++this.index;
                break;

            case 'ù':
                ++this.index;
                if (this.isNotLower(this.words[(int)this.stock[this.index]]))
                {
                    res = new UnknownTerm(this.words[(int)this.stock[this.index]]);
                }
                else
                {
                    res = new Coefficient(this.words[(int)this.stock[this.index]]);
                }
                ++this.index;
                break;

            case 'µ':
                ++this.index;
                string fun = this.words[(int)this.stock[this.index]];
                ++this.index;
                res = new Function(fun, this.calculate());
                break;

            case ',':
                string paramLeft = string.Empty, paramRight = string.Empty;
                if (this.stock[index] == ',')
                {
                    ++this.index;
                    a = this.calculate();
                }
                else
                {
                    b = this.calculate();
                }
                if (this.stock[index] == ',')
                {
                    ++this.index;
                    b = this.calculate();
                }
                else
                {
                    b = calculate();
                }
                List <IArithmetic> list = new List <IArithmetic>();
                if (a is Sequence)
                {
                    list.AddRange((a as Sequence).Items);
                }
                else
                {
                    list.Add(a);
                }
                if (b is Sequence)
                {
                    list.AddRange((b as Sequence).Items);
                }
                else
                {
                    list.Add(b);
                }
                res = new Sequence(list);
                break;
            }
            return(res);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Computes a weight from a coefficient object
 /// </summary>
 /// <param name="c">coefficient object</param>
 /// <returns>weight of this object</returns>
 public static Weight ComputeWeight(Coefficient c)
 {
     return(new Weight(CoefficientValueType, c.Name, c));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor for a simple term
 /// </summary>
 /// <param name="constant">store a constant value</param>
 /// <param name="letter">store a coefficient</param>
 /// <param name="unknown">store an unknown term</param>
 public Term(double constant, string letter, string unknown)
 {
     this[constantName] = new NumericValue(constant);
     this[coefName]     = new Coefficient(letter, 0.0d);
     this[unknownName]  = new UnknownTerm(unknown, new NumericValue(0.0d));
 }