sequence multiplied by -1

Discussion in 'Python' started by Yingjie Lan, Sep 25, 2010.

  1. Yingjie Lan

    Yingjie Lan Guest

    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
     
    Yingjie Lan, Sep 25, 2010
    #1
    1. Advertising

  2. On 25 Sep, 09:22, Yingjie Lan <> 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
     
    Arnaud Delobelle, Sep 25, 2010
    #2
    1. Advertising

  3. Yingjie Lan

    BartC Guest

    "Yingjie Lan" <> wrote in message
    news:...
    > 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
     
    BartC, Sep 26, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    552
    ma740988
    Dec 17, 2005
  2. klior

    2 Multiplied clock sync.

    klior, Jul 31, 2007, in forum: VHDL
    Replies:
    0
    Views:
    512
    klior
    Jul 31, 2007
  3. Thomas Jollans

    Re: sequence multiplied by -1

    Thomas Jollans, Sep 25, 2010, in forum: Python
    Replies:
    45
    Views:
    954
    Albert van der Horst
    Oct 6, 2010
  4. Yingjie Lan

    Re: sequence multiplied by -1

    Yingjie Lan, Sep 25, 2010, in forum: Python
    Replies:
    3
    Views:
    250
    Bruno Desthuilliers
    Oct 3, 2010
  5. Yingjie Lan

    Re: sequence multiplied by -1

    Yingjie Lan, Sep 25, 2010, in forum: Python
    Replies:
    3
    Views:
    245
    Steven D'Aprano
    Sep 26, 2010
Loading...

Share This Page