예제 #1
0
        public override string ToString()
        {
            var result = new List <string>();

            if (!Coefficient.Equals(NumberDecimal.One))
            {
                result.Add(Coefficient.ToString());
            }
            result.AddRange(Variables.Select(a => a.ToString()));
            result.AddRange(Others.Select(a => "(" + a.ToString() + ")"));
            return(string.Join("*", result));
        }
예제 #2
0
        public TermExpression(IValue coefficient, VariablePowExpression[] variablePows, VariableExpression[] variables, params IExpression[] others)
        {
            Coefficient = coefficient ?? new NumberDecimal(1, 0);
            if (Coefficient.Equals(NumberDecimal.Zero))
            {
                return;
            }
            var variablesR = TermExpression.Multiply(variablePows, variables?.Select(a => (VariablePowExpression)a))?.ToList();
            var othersR    = new List <IExpression>();

            if (others != null)
            {
                var result = new TermExpression(others);
                Coefficient = Coefficient.Multiply(result.Coefficient);
                variablesR.AddRange(result.Variables);
                othersR.AddRange(result.Others);
            }

            Variables = Unify(variablesR);
            Others    = othersR.ToArray();
        }