Opened 13 years ago

Closed 13 years ago

#1955 closed defect (duplicate)

bug in vector

Reported by: was Owned by: somebody
Priority: blocker Milestone: sage-duplicate/invalid/wontfix
Component: basic arithmetic Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

Hi,

It seems the __abs__ method for vectors is missing the part that is
supposed to square the components before they are added.

[e.g. abs(vector([1..5])) should really be
sqrt(1+4+9+16+25)=sqrt(55) ]

The code of the current version is included below.

   def __abs__(self):
       """
       Return the square root of the sum of the squares of the
entries of this vector.

       EXAMPLES:
           sage: v = vector([1..5]); abs(v)
           sqrt(15)
           sage: v = vector(RDF, [1..5]); abs(v)
           3.87298334621
       """
       return sum(self.list()).sqrt()

The last line should be something like

       return sum([x*x for x in self.list()]).sqrt()

(not sure if that is the most efficient way).

--Peter

Change History (1)

comment:1 Changed 13 years ago by mabshoff

  • Milestone changed from sage-2.10.1 to sage-duplicate/invalid
  • Resolution set to duplicate
  • Status changed from new to closed

This is a dupe of #1954, which already has a patch for review.

Note: See TracTickets for help on using tickets.