Ticket #13393: combined.patch

File combined.patch, 3.1 KB (added by eviatarbach, 7 years ago)
  • sage/modules/free_module_element.pyx

    # HG changeset patch
    # User Eviatar Bach <eviatarbach@gmail.com>
    # Date 1356684325 28800
    # Node ID 7a7a592adc31337ff132997b899bb45be2ad4f01
    # Parent  33242a07d2ab0920994f3125881c78458b96181b
    * * *
    Trac 13393: new 'normalized' method for vectors, deprecating 'normalize'
    * * *
    Trac 13393: proper deprecation
    * * *
    Trac 13393: Docstring and doctest for .normalize()
    
    diff --git a/sage/modules/free_module_element.pyx b/sage/modules/free_module_element.pyx
    a b  
    25002500        self[i] = x
    25012501
    25022502
    2503     def normalize(self):
     2503    def monic(self):
    25042504        """
    25052505        Return this vector divided through by the first nonzero entry of
    25062506        this vector.
    25072507       
    25082508        EXAMPLES::
    25092509       
    2510             sage: v = vector(QQ,[0,4/3,5,1,2])
    2511             sage: v.normalize()
     2510            sage: v = vector(QQ, [0, 4/3, 5, 1, 2])
     2511            sage: v.monic()
    25122512            (0, 1, 15/4, 3/4, 3/2)
    25132513        """
    25142514        cdef Py_ssize_t i
     
    25172517                return (~self[i]) * self
    25182518        return self
    25192519
     2520    def normalize(self):
     2521        """
     2522        This function is deprecated. For division by the p-norm use
     2523        'normalized', and for division by the first nonzero entry use
     2524        'monic' (previously the purpose of this function).
     2525
     2526        EXAMPLES::
     2527
     2528            sage: v = vector(QQ, [0, 4/3, 5, 1, 2])
     2529            sage: v.normalize()
     2530            doctest:...: DeprecationWarning: 'normalize' is deprecated...
     2531            (0, 1, 15/4, 3/4, 3/2)
     2532        """
     2533        from sage.misc.superseded import deprecation
     2534        deprecation(13393, "'normalize' is deprecated. For division by the \
     2535p-norm use 'normalized', and for division by the first nonzero entry use \
     2536'monic'.")
     2537        return self.monic()
     2538
     2539    def normalized(self, p=sage.rings.integer.Integer(2)):
     2540        """
     2541        Return the input vector divided by the p-norm.
     2542
     2543        INPUT:
     2544
     2545        * "p" - default: 2 - p value for the norm
     2546
     2547        EXAMPLES::
     2548
     2549            sage: v = vector(QQ, [4, 1, 3, 2])
     2550            sage: v.normalized()
     2551            (2/15*sqrt(30), 1/30*sqrt(30), 1/10*sqrt(30), 1/15*sqrt(30))
     2552            sage: sum(v.normalized(1))
     2553            1
     2554
     2555        Note that normalizing the vector may change the base ring::
     2556
     2557            sage: v.base_ring() == v.normalized().base_ring()
     2558            False
     2559            sage: u = vector(RDF, [-3, 4, 6, 9])
     2560            sage: u.base_ring() == u.normalized().base_ring()
     2561            True
     2562        """
     2563        return self / self.norm(p)
     2564
    25202565    def conjugate(self):
    25212566        r"""
    25222567        Returns a vector where every entry has been replaced by its complex conjugate.
     
    25742619            sage: I*(x - x.conjugate()) in RDF^n
    25752620            True
    25762621
    2577         The parent of the conjugate is the same as that of the orginal vector.
     2622        The parent of the conjugate is the same as that of the original vector.
    25782623        We test this by building a specialized vector space with a non-standard
    25792624        inner product, and constructing a test vector in this space. ::
    25802625