Exemplo n.º 1
0
        /// <summary>
        /// Transforms an addition into a multiplication
        /// </summary>
        /// <returns>a list of possibles equation</returns>
        protected override IEnumerable <IArithmetic> MakeTransform()
        {
            List <IArithmetic> list = new List <IArithmetic>();
            Power          p        = new Power(this.LeftOperand, new NumericValue(2.0d));
            Soustraction   s        = new Soustraction(this.RightOperand, this.LeftOperand);
            Multiplication m        = new Multiplication(s, this.LeftOperand);
            Addition       a        = new Addition(p, m);

            list.Add(a);
            p = new Power(this.RightOperand, new NumericValue(2.0d));
            s = new Soustraction(this.LeftOperand, this.RightOperand);
            m = new Multiplication(s, this.RightOperand);
            a = new Addition(p, m);
            list.Add(a);
            return(list);
        }
Exemplo 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);
        }