Comment #12 on issue 3223 by [email protected]: degree((x+1)**10000) takes too long
http://code.google.com/p/sympy/issues/detail?id=3223

After going through the source code, I devised that changing degree functions to the following in polytools.py

Line no :1662
    def degree(f, gen=0):
        """
        Returns degree of ``f`` in ``x_j``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + y*x + 1, x, y).degree()
        2
        >>> Poly(x**2 + y*x + y, x, y).degree(y)
        1

        """
        j = f._gen_to_level(gen)
        if f.args[0].is_polynomial:
                eq=f.args[0]
                if not gen:
                        gen=f.gen
                try:
                        return -eq.subs(gen,1/gen).leadterm(gen)[1]
                except:
                        if hasattr(f.rep,'degree'):
                                return f.rep.degree(j)
                        else:
                                raise OperationNotSupported(f, 'degree')
        if hasattr(f.rep,'degree'):
                return f.rep.degree(j)
        else:
                raise OperationNotSupported(f, 'degree')

Line no: 39**
def degree(f, *gens, **args):
    """
    Return the degree of ``f`` in the given variable.

    Examples
    ========

    >>> from sympy import degree
    >>> from sympy.abc import x, y

    >>> degree(x**2 + y*x + 1, gen=x)
    2
    >>> degree(x**2 + y*x + 1, gen=y)
    1

    """
    options.allowed_flags(args, ['gen', 'polys'])

    try:
        if f.is_polynomial:
                eq=f
                if not gens:
                        gen=f.gen
                else:
                        gen=gens[0]
                try:
                        return -eq.subs(gen,1/gen).leadterm(gen)[1]
                except:
                        F, opt = poly_from_expr(f, *gens, **args)
                        return Integer(F.degree(opt.gen))
    except PolificationFailed, exc:
        raise ComputationFailed('degree', 1, exc)
    except:
        F, opt = poly_from_expr(f, *gens, **args)
    return Integer(F.degree(opt.gen))
could act as a quick solution to the time required in materializing degrees of the functions as described in this issue. It would be highly encouraging if someone could guide me if i am thinking in the right direction or not

I have also attached my polytools.py with the above changes.

Attachments:
        polytools.py  147 KB

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy-issues?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to