示例#1
0
        List <Expression> GetSummandExpressionsAll(string aExpression)
        {
            string _pattern    = @"(?<VarName>[a-z])(\^(?<VarPow>\d+))?";
            string _patternVar = String.Format(@"(?<Coeff>([-]?\d+(,\d+)?))?(?<Var>({0})*)", _pattern);
            Regex  _regexVar   = new Regex(_patternVar);

            MatchCollection _mcVar = _regexVar.Matches(aExpression);

            List <Expression> _res = new List <Expression>();

            for (int i = 0; i < _mcVar.Count; i++)
            {
                Match  _m    = _mcVar[i];
                string _summ = _m.Value;
                if (_summ != String.Empty)
                {
                    GroupCollection _groups = _mcVar[i].Groups;
                    string          _coeff  = _groups["Coeff"].Value != String.Empty ? _groups["Coeff"].Value : "1";

                    Summand _summand = new Summand(Double.Parse(_coeff.Replace(" ", "")));

                    string _varsCapture = _groups["Var"].Value;

                    List <Variable> _vars = GetVariable(_varsCapture, _pattern);
                    _summand.AddVariableRange(_vars);
                    _summand.ToCanonical();

                    SummandExpression _exp = new SummandExpression(_m.Index, _m.Index + _m.Length - 1, _summand);
                    _res.Add(_exp);
                }
            }

            return(_res);
        }
示例#2
0
        public static Summand operator *(Summand a, Summand b)
        {
            Summand _res = new Summand(a.FCoeff * b.FCoeff);

            List <Variable> _variablesMult = new List <Variable>(a.FVariables);

            _variablesMult.AddRange(b.FVariables);
            _res.FVariables = _variablesMult;
            _res.ToCanonical();

            return(_res);
        }
示例#3
0
        public bool IsSimilarTo(Summand aVar)
        {
            this.ToCanonical();
            aVar.ToCanonical();

            if (this.FVariables.Count != aVar.FVariables.Count)
            {
                return(false);
            }

            for (int i = 0; i < this.FVariables.Count; i++)
            {
                if (this.FVariables[i] != aVar.FVariables[i])
                {
                    return(false);
                }
            }

            return(true);
        }
示例#4
0
 public void AddSummand(Summand aSummand)
 {
     this.FSummands.Add(aSummand);
 }
示例#5
0
 public SummandExpression(int aStart, int aEnd, Summand aSummand) :
     base(aStart)
 {
     this.FEnd     = aEnd;
     this.FSummand = aSummand;
 }