(f, u, K)
return dmp_strip(h, u)
Square dense polynomials in ``K[X]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x,y = ring("x,y", ZZ)

    >>> R.dmp_sqr(x**2 + x*y + y**2)
    x**4 + 2*x**3*y + 3*x**2*y**2 + 2*x*y**3 + y**4
Square dense polynomials in ``K[X]``.
Square dense polynomials in K [ X ] .
def dmp_sqr(f, u, K):
    """
    Square dense polynomials in ``K[X]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x,y = ring("x,y", ZZ)

    >>> R.dmp_sqr(x**2 + x*y + y**2)
    x**4 + 2*x**3*y + 3*x**2*y**2 + 2*x*y**3 + y**4

    """
    if not u:
        return dup_sqr(f, K)

    df = dmp_degree(f, u)

    if df < 0:
        return f

    h, v = [], u - 1

    for i in xrange(0, 2*df + 1):
        c = dmp_zero(v)

        jmin = max(0, i - df)
        jmax = min(i, df)

        n = jmax - jmin + 1

        jmax = jmin + n // 2 - 1

        for j in xrange(jmin, jmax + 1):
            c = dmp_add(c, dmp_mul(f[j], f[i - j], v, K), v, K)

        c = dmp_mul_ground(c, K(2), v, K)

        if n & 1:
            elem = dmp_sqr(f[jmax + 1], v, K)
            c = dmp_add(c, elem, v, K)

        h.append(c)

    return dmp_strip(h, u)
def dmp_sqr ( f , u , K ) : if not u : return dup_sqr ( f , K ) df = dmp_degree ( f , u ) if df < 0 : return f h , v = [ ] , u - 1 for i in xrange ( 0 , 2 * df + 1 ) : c = dmp_zero ( v ) jmin = max ( 0 , i - df ) jmax = min ( i , df ) n = jmax - jmin + 1 jmax = jmin + n // 2 - 1 for j in xrange ( jmin , jmax + 1 ) : c = dmp_add ( c , dmp_mul ( f [ j ] , f [ i - j ] , v , K ) , v , K ) c = dmp_mul_ground ( c , K ( 2 ) , v , K ) if n & 1 : elem = dmp_sqr ( f [ jmax + 1 ] , v , K ) c = dmp_add ( c , elem , v , K ) h . append ( c ) return dmp_strip ( h , u )