public static IExpression Multiply(IExpression lhe, IExpression rhe)
        {
            var res = lhe.Clone();

            if (rhe is IVariableExpression)
            {
                res.Count.Multiply(rhe.Count);

                if (rhe.DimensionKey.Key == res.DimensionKey.Key)
                {
                    res.DimensionKey.Value += (Fraction)rhe.DimensionKey.Value;

                    if (res.DimensionKey.Value.Numerator == 0)
                    {
                        return(FromCount(res.Count));
                    }

                    return(res);
                }
            }

            var tmp = new FlatMultExpression();

            tmp.Add(res);
            tmp.Add(rhe.Clone());
            var r = tmp.Execute();

            return(r);
        }
        public void Multiply_Number_FlatMult()
        {
            //Arrange
            var expected = new FlatMultExpression();

            expected.Add(new VariableExpression("u", 2));
            expected.Add(new VariableExpression("y", 3));
            expected.Count = new Complex(12, 0);
            expected.Execute();

            var c = new NumberExpression(3);
            var n = new FlatMultExpression();

            n.Add(new VariableExpression("u", 2));
            n.Add(new VariableExpression("y", 3));
            n.Count = new Complex(4, 0);
            var expr = new BinaryExpression(c, OperatorTypes.Multiply, n);

            //Act
            var actual = expr.Execute();

            //Assert
            Assert.AreEqual(expected.Count.Re.ToNumber(), actual.Count.Re.ToNumber());
            Assert.AreEqual(expected.Count.Im.ToNumber(), actual.Count.Im.ToNumber());
        }
        public static IExpression Divide(IExpression lhe, IExpression rhe)
        {
            var res = lhe.Clone();

            if (rhe is IVariableExpression)
            {
                res.Count.Divide(rhe.Count);

                if (rhe.DimensionKey.Key == res.DimensionKey.Key)
                {
                    res.DimensionKey.Value -= (Fraction)rhe.DimensionKey.Value;

                    if (res.DimensionKey.Value.Numerator == 0)
                    {
                        return(new ComplexExpression(res.Count));
                    }

                    return(res);
                }
            }
            else if (rhe is NumberExpression || rhe is ComplexExpression)
            {
                res.Count.Divide(rhe.Count);
                return(res);
            }

            var tmp = new FlatMultExpression();

            tmp.Add(res);
            tmp.Add(new BinaryExpression(rhe.Clone(), OperatorTypes.Power, new NumberExpression(-1)));
            var r = tmp.Execute();

            return(r);
        }
        public static IExpression Divide(IExpression lhe, IExpression rhe)
        {
            var res = lhe.Clone();

            if (rhe is INumberExpression)
            {
                res.Count.Divide(rhe.Count);

                return(ReduceExpression(res));
            }
            else if (rhe is ComplexExpression rc)
            {
                res.Count.Divide(rc.Count);

                return(ReduceExpression(res));
            }
            else
            {
                var tmp = new FlatMultExpression();
                tmp.Add(lhe);
                tmp.Add(new BinaryExpression(rhe.Clone(), OperatorTypes.Power, new NumberExpression(-1)));
                var r = tmp.Execute();
                return(r);
            }
        }