Ticket #13736: trac_13736-unit_primpart.patch

File trac_13736-unit_primpart.patch, 5.9 KB (added by vbraun, 9 years ago)

Updated patch

  • sage/libs/ginac.pxd

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1371509363 25200
    #      Mon Jun 17 15:49:23 2013 -0700
    # Node ID 0e58b7cca8f5f112b5a1361e750344c57232aeb1
    # Parent  8e7081686d911735326aa28022a74cfb206e2aab
    Add unit and primpart
    
    diff --git a/sage/libs/ginac.pxd b/sage/libs/ginac.pxd
    a b  
    8888        GEx numer_denom()             except +
    8989        int degree(GEx expr)          except +
    9090        int ldegree(GEx expr)         except +
     91        GEx unit(GEx expr)            except +
    9192        GEx content(GEx expr)         except +
     93        GEx primpart(GEx expr)        except +
     94        void unitcontprim(GEx expr, GEx unit, GEx cont, GEx prim) except +
    9295        GEx rhs()                     except +
    9396        GEx lhs()                     except +
    9497        int nops()                    except +
  • sage/symbolic/expression.pyx

    diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
    a b  
    48344834        cdef Expression ss = self.coerce_in(s)
    48354835        return self._gobj.degree(ss._gobj)
    48364836
    4837     def _content(self, s):
    4838         """
    4839         Return the content of this expression with respect to the
    4840         expression ``s``.
     4837    def unit(self, s):
     4838        """
     4839        Return the unit of this expression when considered as a
     4840        polynomial in ``s``.
     4841
     4842        See also :meth:`content`, :meth:`primitive_part`, and
     4843        :meth:`unit_content_primitive`.
     4844
     4845        INPUT:
     4846       
     4847        - ``s`` -- a symbolic expression.
     4848
     4849        OUTPUT:
     4850
     4851        The unit part of a polynomial as a symbolic expression. It is
     4852        defined as the sign of the leading coefficient.
     4853       
     4854        EXAMPLES::
     4855
     4856            sage: (2*x+4).unit(x)
     4857            1
     4858            sage: (-2*x+1).unit(x)
     4859            -1
     4860            sage: (2*x+1/2).unit(x)
     4861            1
     4862            sage: var('y')
     4863            y
     4864            sage: (2*x - 4*sin(y)).unit(sin(y))
     4865            -1
     4866        """
     4867        cdef Expression ss = self.coerce_in(s)
     4868        return new_Expression_from_GEx(self._parent, self._gobj.unit(ss._gobj))
     4869
     4870    def content(self, s):
     4871        """
     4872        Return the content of this expression when considered as a
     4873        polynomial in ``s``.
     4874
     4875        See also :meth:`unit`, :meth:`primitive_part`, and
     4876        :meth:`unit_content_primitive`.
     4877
     4878        INPUT:
     4879       
     4880        - ``s`` -- a symbolic expression.
     4881
     4882        OUTPUT:
     4883
     4884        The content part of a polynomial as a symbolic expression. It
     4885        is defined as the gcd of the coefficients.
    48414886
    48424887        .. warning::
    48434888
    4844             The values returned by this function may not be compatible with
    4845             the output of the ``content()`` method provided by various
    4846             polynomial rings in Sage.
    4847 
    4848         EXAMPLES::
    4849 
    4850             sage: (2*x+4)._content(x)
     4889            The expression is considered to be a univariate polynomial
     4890            in ``s``. The output is different from the ``content()``
     4891            method provided by multivariate polynomial rings in Sage.
     4892
     4893        EXAMPLES::
     4894
     4895            sage: (2*x+4).content(x)
    48514896            2
    4852             sage: (2*x+1)._content(x)
     4897            sage: (2*x+1).content(x)
    48534898            1
    4854             sage: (2*x+1/2)._content(x)
     4899            sage: (2*x+1/2).content(x)
    48554900            1/2
    48564901            sage: var('y')
    48574902            y
    4858             sage: (2*x + 4*sin(y))._content(sin(y))
     4903            sage: (2*x + 4*sin(y)).content(sin(y))
    48594904            2
    48604905        """
    48614906        cdef Expression ss = self.coerce_in(s)
    48624907        return new_Expression_from_GEx(self._parent, self._gobj.content(ss._gobj))
    48634908
     4909    def primitive_part(self, s):
     4910        """
     4911        Return the primitive polynomial of this expression when
     4912        considered as a polynomial in ``s``.
     4913
     4914        See also :meth:`unit`, :meth:`content`, and
     4915        :meth:`unit_content_primitive`.
     4916
     4917        INPUT:
     4918       
     4919        - ``s`` -- a symbolic expression.
     4920
     4921        OUTPUT:
     4922
     4923        The primitive polynomial as a symbolic expression. It is
     4924        defined as the quotient by the :meth:`unit` and
     4925        :meth:`content` parts (with respect to the variable ``s``).
     4926
     4927        EXAMPLES::
     4928
     4929            sage: (2*x+4).primitive_part(x)
     4930            x + 2
     4931            sage: (2*x+1).primitive_part(x)
     4932            2*x + 1
     4933            sage: (2*x+1/2).primitive_part(x)
     4934            4*x + 1
     4935            sage: var('y')
     4936            y
     4937            sage: (2*x + 4*sin(y)).primitive_part(sin(y))
     4938            x + 2*sin(y)
     4939        """
     4940        cdef Expression ss = self.coerce_in(s)
     4941        return new_Expression_from_GEx(self._parent, self._gobj.primpart(ss._gobj))
     4942
     4943    def unit_content_primitive(self, s):
     4944        """
     4945        Return the factorization into unit, content, and primitive part.
     4946
     4947        INPUT:
     4948       
     4949        - ``s`` -- a symbolic expression, usually a symbolic
     4950          variable. The whole symbolic expression ``self`` will be
     4951          considered as a univariate polynomial in ``s``.
     4952
     4953        OUTPUT:
     4954
     4955        A triple (unit, content, primitive polynomial)` containing the
     4956        :meth:`unit <unit>`, :meth:`content <content>`, and
     4957        :meth:`primitive polynomial <primitive_part>`. Their product equals
     4958        ``self``.
     4959
     4960        EXAMPLES::
     4961       
     4962            sage: var('x,y')
     4963            (x, y)
     4964            sage: ex = 9*x^3*y+3*y
     4965            sage: ex.unit_content_primitive(x)
     4966            (1, 3*y, 3*x^3 + 1)
     4967            sage: ex.unit_content_primitive(y)
     4968            (1, 9*x^3 + 3, y)
     4969        """
     4970        cdef Expression ss = self.coerce_in(s)
     4971        cdef GEx unit, cont, prim
     4972        self._gobj.unitcontprim(ss._gobj, unit, cont, prim)
     4973        return (new_Expression_from_GEx(self._parent, unit),
     4974                new_Expression_from_GEx(self._parent, cont),
     4975                new_Expression_from_GEx(self._parent, prim))
     4976
    48644977    def poly(self, x=None):
    48654978        r"""
    48664979        Express this symbolic expression as a polynomial in *x*. If