Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[with patch, with 2 positive reviews] sage/modules/free_module_element.pyx computing abs(vector(...)) #1954

Closed
mwhansen opened this issue Jan 28, 2008 · 3 comments

Comments

@mwhansen
Copy link
Contributor


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

Component: commutative algebra

Issue created by migration from https://trac.sagemath.org/ticket/1954

@mwhansen
Copy link
Contributor Author

comment:2

Attachment: 1954.patch.gz

@mwhansen mwhansen added this to the sage-2.10.1 milestone Jan 28, 2008
@sagetrac-dmharvey
Copy link
Mannequin

sagetrac-dmharvey mannequin commented Jan 28, 2008

comment:5

Looks good to me (I only ran doctests on that file, not on all files).

(If anyone has time, would be good to try doing this without the list call, and also I expect x*x is generally faster than x**2.)

@williamstein williamstein changed the title sage/modules/free_module_element.pyx computing abs(vector(...)) [with patch, with 2 positive reviews] sage/modules/free_module_element.pyx computing abs(vector(...)) Jan 28, 2008
@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Jan 28, 2008

comment:7

Merged in Sage 2.10.1.rc2

@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Jan 28, 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant