예제 #1
0
            public static Tuple <MathObject, int> CoefficientMonomialGpe(this MathObject u, MathObject x)
            {
                if (u == x)
                {
                    return(Tuple.Create((MathObject)1, 1));
                }

                if (u is Power &&
                    (u as Power).bas == x &&
                    (u as Power).exp is Integer &&
                    ((u as Power).exp as Integer).val > 1)
                {
                    return(Tuple.Create((MathObject)1, ((u as Power).exp as Integer).val));
                }

                if (u is Product)
                {
                    var m = 0;
                    var c = u;

                    foreach (var elt in (u as Product).elts)
                    {
                        var f = elt.CoefficientMonomialGpe(x);

                        if (f == null)
                        {
                            return(null);
                        }

                        if (f.Item2 != 0)
                        {
                            m = f.Item2;
                            c = u / (x ^ m);
                        }
                    }

                    return(Tuple.Create(c, m));
                }

                if (u.FreeOf(x))
                {
                    return(Tuple.Create(u, 0));
                }

                return(null);
            }
예제 #2
0
            public static Tuple <MathObject, int> CoefficientMonomialGpe(this MathObject u, MathObject x)
            {
                if (u == x)
                {
                    return(Tuple.Create((MathObject)1, 1));
                }
                if (u is Power &&
                    ((Power)u).bas == x &&
                    ((Power)u).exp is Integer &&
                    ((Integer)((Power)u).exp).val > 1)
                {
                    return(Tuple.Create((MathObject)1, ((Integer)((Power)u).exp).val));
                }

                if (!(u is Product))
                {
                    return(u.FreeOf(x) ? Tuple.Create(u, 0) : null);
                }
                int        m = 0;
                MathObject c = u;

                foreach (Tuple <MathObject, int> f in ((Product)u).elts.Select(elt => elt.CoefficientMonomialGpe(x)))
                {
                    if (f == null)
                    {
                        return(null);
                    }

                    if (f.Item2 == 0)
                    {
                        continue;
                    }
                    m = f.Item2;
                    c = u / (x ^ m);
                }
                return(Tuple.Create(c, m));
            }