Exemple #1
0
        public static bool Is(this IValue a, IValue b)
        {
            a = a.Simple();
            b = b.Simple();
            if (a.Integerable && b.Integerable)
            {
                return(a.ToInteger() == b.ToInteger());
            }

            if (a.Fractionable && b.Fractionable)
            {
                Fraction fa = a.ToFraction();
                Fraction fb = b.ToFraction();
                return(fa.Numerator.Is(fb.Numerator) && fa.Denominator.Is(fb.Denominator));
            }

            if (a.Radicalable && b.Radicalable)
            {
                Radical ra = a.ToRadical();
                Radical rb = b.ToRadical();
                return(ra.Radicant.Is(rb.Radicant) && ra.Coefficient.Is(rb.Coefficient));
            }

            return(a.Value == b.Value);
        }
Exemple #2
0
        public Product(IValue first, IValue second)
        {
            first  = first.Direct();
            second = second.Direct();

            if (first.Integerable && second.Integerable)
            {
                First  = first.ToInteger() * second.ToInteger();
                Second = new Integer(1);
                return;
            }
            if (first.Fractionable && second.Fractionable)
            {
                Fraction a = first.ToFraction();
                Fraction b = second.ToFraction();
                First  = new Fraction(new Product(a.Numerator, b.Numerator).Simple(), new Product(a.Denominator, b.Denominator).Simple());
                Second = new Integer(1);
                return;
            }
            if (first.Radicalable && second.Radicalable)
            {
                Radical a = first.ToRadical();
                Radical b = second.ToRadical();

                First  = new Radical(new Product(a.Radicant, b.Radicant).Simple(), new Product(a.Coefficient, b.Coefficient).Simple(), true);
                Second = new Integer(1);
                return;
            }
            if (First is Sum firstSum)
            {
                First  = new Sum(new Product(firstSum.First, Second).Simple(), new Product(firstSum.Second, Second));
                Second = new Integer(1);
                return;
            }
            if (Second is Sum secondSum)
            {
                First  = new Sum(new Product(secondSum.First, First).Simple(), new Product(secondSum.Second, First));
                Second = new Integer(1);
                return;
            }

            First  = first.Simple();
            Second = second.Simple();
        }