Example #1
0
            public static MathObject CoefficientGpe(this MathObject u, MathObject x, int j)
            {
                if (!(u is Sum))
                {
                    Tuple <MathObject, int> f = u.CoefficientMonomialGpe(x);
                    if (f == null)
                    {
                        return(null);
                    }
                    return(f.Item2 == j ? f.Item1 : 0);
                }
                if (u == x)
                {
                    return(j == 1 ? 1 : 0);
                }
                MathObject c = 0;

                foreach (Tuple <MathObject, int> f in ((Sum)u).elts.Select(elt => elt.CoefficientMonomialGpe(x)))
                {
                    if (f == null)
                    {
                        return(null);
                    }
                    if (f.Item2 == j)
                    {
                        c = c + f.Item1;
                    }
                }
                return(c);
            }
Example #2
0
            public static MathObject CoefficientGpe(this MathObject u, MathObject x, int j)
            {
                if (!(u is Sum))
                {
                    var f = u.CoefficientMonomialGpe(x);

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

                    if (f.Item2 == j)
                    {
                        return(f.Item1);
                    }

                    return(0);
                }

                if (u == x)
                {
                    return(j == 1 ? 1 : 0);
                }

                var c = (MathObject)0;

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

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

                    if (f.Item2 == j)
                    {
                        c = c + f.Item1;
                    }
                }

                return(c);
            }