Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > sequence multiplied by -1

Reply
Thread Tools

sequence multiplied by -1

 
 
Yingjie Lan
Guest
Posts: n/a
 
      09-25-2010
Hi,

I noticed that in python3k, multiplying a sequence by a negative integer is the same as multiplying it by 0, and the result is an empty sequence. It seems to me that there is a more meaningful symantics.

Simply put, a sequence multiplied by -1 can give a reversed sequence.

Then for any sequence "seq", and integer n>0, we can have

"seq * -n" producing "(seq * -1) * n".

Any thoughts?

Yingjie



 
Reply With Quote
 
 
 
 
Arnaud Delobelle
Guest
Posts: n/a
 
      09-25-2010
On 25 Sep, 09:22, Yingjie Lan <(E-Mail Removed)> wrote:
> Hi,
>
> I noticed that in python3k, multiplying a sequence by a negative integer is the same as multiplying it by 0, and the result is an empty sequence. It seems to me that there is a more meaningful symantics.
>
> Simply put, a sequence multiplied by -1 can give a reversed sequence.
>
> Then for any sequence "seq", and integer n>0, we can have
>
> "seq * -n" producing "(seq * -1) * n".
>
> Any thoughts?
>
> Yingjie


If [1, 2]*-1 is correct, then, arguably, so should be -[1, 2]

Some answers have invoked mathematics to weigh the value of this
proposal, e.g. likening lists to vectors. But the obvious
mathematical analogy is that the set of all lists forms a monoid under
the operation of concatenation, which (unfortunately?) is performed
with the "+" operator in Python. So it is natural that "*" represents
repeated concatenation.

Now under concatenation, non-empty lists do not have an inverse, i.e.
for any non-empty list l, there does not exist a list l' such that l +
l' == []. So there is no natural interpretation of -l and therefore
of l*-1.

However, by using "+" for list (and string) concatenation, Python
already breaks the mathematical pledge of commutativity that this
operator implies.

--
Arnaud
 
Reply With Quote
 
 
 
 
BartC
Guest
Posts: n/a
 
      09-26-2010


"Yingjie Lan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I noticed that in python3k, multiplying a sequence by a negative integer
> is the same as multiplying it by 0, and the result is an empty sequence.
> It seems to me that there is a more meaningful symantics.
>
> Simply put, a sequence multiplied by -1 can give a reversed sequence.
>
> Then for any sequence "seq", and integer n>0, we can have
>
> "seq * -n" producing "(seq * -1) * n".
>
> Any thoughts?


Gimmicky.

Best to define multiplication only by unsigned or positive values.

--
Bartc

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: sequence multiplied by -1 Thomas Jollans Python 45 10-06-2010 01:28 PM
Re: sequence multiplied by -1 Yingjie Lan Python 3 10-03-2010 03:14 PM
Re: sequence multiplied by -1 Yingjie Lan Python 3 09-26-2010 02:11 AM
2 Multiplied clock sync. klior VHDL 0 07-31-2007 01:33 PM
problems at multiplication (Currency multiplied with float) abdul_n_khan@hotmail.com C++ 10 12-17-2005 01:59 AM



Advertisments