Re: How about adding rational fraction to Python?

2008-03-12 Thread Mark Dickinson
On Mar 12, 7:20 am, Piet van Oostrum <[EMAIL PROTECTED]> wrote: > But if the answer is incorrect (in the float calculation) the error is > limited. IEEE 754 prescribes that the error should be at most 1 LSB, IIRC. > And then the number of errors is the proper measure. There are two operations here

Re: How about adding rational fraction to Python?

2008-03-12 Thread Piet van Oostrum
> "Gabriel Genellina" <[EMAIL PROTECTED]> (GG) wrote: >GG> En Tue, 04 Mar 2008 11:46:48 -0200, NickC <[EMAIL PROTECTED]> escribió: >>> A mildly interesting Py3k experiment: >>> >>> Python 3.0a3+ (py3k:61229, Mar 4 2008, 21:38:15) >>> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)]

Re: How about adding rational fraction to Python?

2008-03-04 Thread Paul Rubin
Mark Dickinson <[EMAIL PROTECTED]> writes: > For randomly chosen(*) base B floats x and y, the probability that > (x/y)*y == x is approximately given by I remember hearing that IEEE 754 was carefully designed to make this identity hold as often as possible when y is a small integer. -- http://mai

Re: How about adding rational fraction to Python?

2008-03-04 Thread Mark Dickinson
On Mar 4, 9:39 am, Mark Dickinson <[EMAIL PROTECTED]> wrote: > On Mar 4, 8:46 am, NickC <[EMAIL PROTECTED]> wrote: > > > The increased number of inaccurate answers with Decimal (31% vs 10%) > > is probably due to the fact that it is actually more precise than > > float > > I suspect it has more to

Re: How about adding rational fraction to Python?

2008-03-04 Thread Gabriel Genellina
En Tue, 04 Mar 2008 11:46:48 -0200, NickC <[EMAIL PROTECTED]> escribi�: > A mildly interesting Py3k experiment: > > Python 3.0a3+ (py3k:61229, Mar 4 2008, 21:38:15) > [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 > Type "help", "copyright", "credits" or "license" for more i

Re: How about adding rational fraction to Python?

2008-03-04 Thread Mark Dickinson
On Mar 4, 8:46 am, NickC <[EMAIL PROTECTED]> wrote: > The increased number of inaccurate answers with Decimal (31% vs 10%) > is probably due to the fact that it is actually more precise than > float I suspect it has more to do with the fact that 10 is bigger than 2, though I'm not sure I could pre

Re: How about adding rational fraction to Python?

2008-03-04 Thread NickC
On Mar 4, 7:11 am, Lie <[EMAIL PROTECTED]> wrote: > On Mar 2, 11:36 pm, Paul Rubin wrote: > > > > Try with a=7, b=25 > > > > They should still compare true, but they don't. The reason why they > > > don't is because of float's finite precision, which is not exactly > > >

Re: How about adding rational fraction to Python?

2008-03-03 Thread Lie
On Mar 2, 11:36 pm, Paul Rubin wrote: > Lie <[EMAIL PROTECTED]> writes: > > You hit the right note, but what I meant is the numeric type > > unification would make it _appear_ to consist of a single numeric type > > (yeah, I know it isn't actually, but what appears from o

Re: How about adding rational fraction to Python?

2008-03-03 Thread Arnaud Delobelle
On Mar 3, 4:39 pm, Paul Rubin wrote: [...] > You are right, C is even worse than I remembered. It's good enough to be the language used for the reference implementation of python :-) [...] -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: How about adding rational fraction to Python?

2008-03-03 Thread Paul Rubin
Jeff Schwab <[EMAIL PROTECTED]> writes: > > User defined types in python are fairly heavyweight compared with the > > built-in types, > > Yet they continue to form the basis of almost all non-trivial Python > programs. Anyway, it's a bit soon to be optimizing. :) Large python programs usually ha

Re: How about adding rational fraction to Python?

2008-03-02 Thread Jeff Schwab
Paul Rubin wrote: > Jeff Schwab <[EMAIL PROTECTED]> writes: >> Better yet, how hard would it be to define an otherwise int-like type >> that did not define a non-flooring division operator? Are there any >> real use cases for such a type? > > User defined types in python are fairly heavyweight co

Re: How about adding rational fraction to Python?

2008-03-02 Thread Paul Rubin
Jeff Schwab <[EMAIL PROTECTED]> writes: > Better yet, how hard would it be to define an otherwise int-like type > that did not define a non-flooring division operator? Are there any > real use cases for such a type? User defined types in python are fairly heavyweight compared with the built-in ty

sympy: nifty, but... (was: How about adding rational fraction to Python?)

2008-03-02 Thread Mensanator
On Mar 1, 12:29 pm, "Anand Patil" <[EMAIL PROTECTED]> wrote: > Not sure if this is common knowledge yet but > Sympy,http://code.google.com/p/sympy, has a rational type. I hadn't heard of this before, thanks for the link. Very nifty, lots of goodies not found in gmpy (although it seems to lack a

Re: How about adding rational fraction to Python?

2008-03-02 Thread Jeff Schwab
Paul Rubin wrote: > I can live with int/int=float but > find it sloppy and would be happier if int/int always threw an error > (convert explicitly if you want a particular type result). Better yet, how hard would it be to define an otherwise int-like type that did not define a non-flooring divisi

Re: How about adding rational fraction to Python?

2008-03-02 Thread Paul Rubin
Lie <[EMAIL PROTECTED]> writes: > You hit the right note, but what I meant is the numeric type > unification would make it _appear_ to consist of a single numeric type > (yeah, I know it isn't actually, but what appears from outside isn't > always what's inside). That is clearly not intended; floa

Re: How about adding rational fraction to Python?

2008-03-02 Thread Lie
On Mar 2, 10:02 pm, Paul Rubin wrote: > Lie <[EMAIL PROTECTED]> writes: > > Anyway, I don't think Python should > > work that way, because Python have a plan for numerical integration > > which would unify all numerical types into an apparent single type, > > which requir

Re: How about adding rational fraction to Python?

2008-03-02 Thread Paul Rubin
Lie <[EMAIL PROTECTED]> writes: > That's quite complex and restrictive, but probably it's because my > mind is not tuned to Haskell yet. That aspect is pretty straightforward, other parts like only being able to do i/o in functions having a special type are much more confusing. > Anyway, I don't

Re: How about adding rational fraction to Python?

2008-03-02 Thread Lie
On Mar 2, 2:02 pm, Paul Rubin wrote: > Lie <[EMAIL PROTECTED]> writes: > > So basically they refused to satisfy everything that is still possible > > individually but would conflict if done together. > > I can't understand that. > > > x = 1 > > a = x + 1<< decides it'

Re: How about adding rational fraction to Python?

2008-03-01 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > def mean(data): return sum(data)/len(data) > > That does the right thing for data, no matter of what it consists of: > floats, ints, Decimals, rationals, complex numbers, or a mix of all of > the above. One of those types is not like the others: for

Re: How about adding rational fraction to Python?

2008-03-01 Thread Paul Rubin
Lie <[EMAIL PROTECTED]> writes: > So basically they refused to satisfy everything that is still possible > individually but would conflict if done together. I can't understand that. > x = 1 > a = x + 1<< decides it's an int No, so far a and x are both Num (indeterminate) > b = x + 1.0 <<

Re: How about adding rational fraction to Python?

2008-03-01 Thread Lie
On Feb 29, 5:33 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > > > And rightly rejected by many other programming languages, including > > > modern Python, not to mention calculators, real mathematics and > > > common sense. > > > Lost me again.  I was not aware that calculator

Re: How about adding rational fraction to Python?

2008-03-01 Thread Lie
On Mar 2, 2:32 am, Paul Rubin wrote: > Lie <[EMAIL PROTECTED]> writes: > > I see, but the same arguments still holds true: the second line have > > an implicit side-effect of redefining x's type into Fractional type. > > If I were the designer of the language, I'd leave x

Re: How about adding rational fraction to Python?

2008-03-01 Thread Paul Rubin
Lie <[EMAIL PROTECTED]> writes: > I see, but the same arguments still holds true: the second line have > an implicit side-effect of redefining x's type into Fractional type. > If I were the designer of the language, I'd leave x's type as it is > (as Num) and coerce x for current calculation only.

Re: How about adding rational fraction to Python?

2008-03-01 Thread Anand Patil
Not sure if this is common knowledge yet but Sympy, http://code.google.com/p/sympy, has a rational type. In [2]: from sympy import * In [3]: Rational(21,4) Out[3]: 21/4 In [4]: Rational(21,4)+Rational(3,4) Out[4]: 6 -- http://mail.python.org/mailman/listinfo/python-list

Re: How about adding rational fraction to Python?

2008-03-01 Thread Lie
On Mar 1, 11:23 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: (snip) > But the type of `x` must be specialized somehow.  `x` doesn't start as > `Int` or `Integer` but the very generic and AFAIK abstract type class `Num`. > > After seeing the second line the compiler finds an implementatio

Re: How about adding rational fraction to Python?

2008-03-01 Thread Marc 'BlackJack' Rintsch
On Fri, 29 Feb 2008 17:29:32 -0800, Lie wrote: > On Feb 28, 10:00 am, Paul Rubin wrote: >> More examples: >> >>x = 1 >>y = len(s) + x >> >> => ok, decides that x is an int >> >>x = 1 >>y = x + 3.0 >> >> => ok, decides that x is a float >> >>x = 1 >>

Re: How about adding rational fraction to Python?

2008-03-01 Thread Arnaud Delobelle
On Mar 1, 5:49 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > | Perhaps it'll be like when I quit smoking six years ago.  I didn't > | enjoy it although I knew it was good for me... And now I don't regret > | it ev

Re: How about adding rational fraction to Python?

2008-02-29 Thread Terry Reedy
"Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Perhaps it'll be like when I quit smoking six years ago. I didn't | enjoy it although I knew it was good for me... And now I don't regret | it even though I still have the occasional craving. In following the devel

Re: How about adding rational fraction to Python?

2008-02-29 Thread Steve Holden
Dan Bishop wrote: > On Feb 29, 12:55 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: >> On Thu, 28 Feb 2008 10:39:51 -, Steven D'Aprano >> <[EMAIL PROTECTED]> declaimed the following in >> comp.lang.python: >> >>> By that logic, we should see this: >> len("a string") >>> '8' >> Why

Re: How about adding rational fraction to Python?

2008-02-29 Thread Dan Bishop
On Feb 29, 12:55 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Thu, 28 Feb 2008 10:39:51 -, Steven D'Aprano > <[EMAIL PROTECTED]> declaimed the following in > comp.lang.python: > > > By that logic, we should see this: > > > >>> len("a string") > > '8' > > Why? len() is a functio

Re: How about adding rational fraction to Python?

2008-02-29 Thread Lie
On Feb 28, 10:00 am, Paul Rubin wrote: > More examples: > >x = 1 >y = len(s) + x > > => ok, decides that x is an int > >x = 1 >y = x + 3.0 > > => ok, decides that x is a float > >x = 1 >y = x + 3.0 >z = len(s) + x > > => forbidden, x cannot be

Re: How about adding rational fraction to Python?

2008-02-29 Thread Arnaud Delobelle
On Feb 29, 10:10 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message > > | What screws me is that I'm going to have to type p//q in the future. > > When I compare that pain to the gain of not having to type an otherwise > extraneous 'float(...)', a

Re: How about adding rational fraction to Python?

2008-02-29 Thread Terry Reedy
"Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message | What screws me is that I'm going to have to type p//q in the future. When I compare that pain to the gain of not having to type an otherwise extraneous 'float(...)', and the gain of disambiguating the meaning of a/b (for builtin numbers

Re: How about adding rational fraction to Python?

2008-02-29 Thread Terry Reedy
"Ross Ridge" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Ross Ridge wrote: | > You're just going to have to accept that there that there is no | > concensus on this issue and there never was. | | Steven D'Aprano <[EMAIL PROTECTED]> wrote: | >But that's not true. The consensus,

Re: How about adding rational fraction to Python?

2008-02-28 Thread Ross Ridge
Ross Ridge wrote: > You're just going to have to accept that there that there is no > concensus on this issue and there never was. Steven D'Aprano <[EMAIL PROTECTED]> wrote: >But that's not true. The consensus, across the majority of people (both >programmers and non-programmers alike) is that

Re: How about adding rational fraction to Python?

2008-02-28 Thread Arnaud Delobelle
On Feb 28, 10:41 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: [...] > The interesting case is -1/2. According to the argument that "2 doesn't > go into 1", -1/2 should also return 0. But that's not what Python > returns, so it looks like the "int division" camp is screwed no ma

Re: How about adding rational fraction to Python?

2008-02-28 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > > Calculating machines that handled > > floating point are older than Python by far. > > Yes, and they almost universally give the result 1/2 -> 0.5. Can you name an example of a calculating machine that both: 1) represents the integer 1 and the rea

Re: How about adding rational fraction to Python?

2008-02-28 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > any restriction that functions must return the same > type as all its arguments is just crazy. I don't think anyone is saying that they should necessarily do that in general. Just in some specific cases. -- http://mail.python.org/mailman/listinfo/py

Re: How about adding rational fraction to Python?

2008-02-28 Thread Steven D'Aprano
On Thu, 28 Feb 2008 14:41:56 -0500, Ross Ridge wrote: > You're just going to have to accept that there that there is no > concensus on this issue and there never was. But that's not true. The consensus, across the majority of people (both programmers and non-programmers alike) is that 1/2 should

Re: How about adding rational fraction to Python?

2008-02-28 Thread Steven D'Aprano
On Thu, 28 Feb 2008 11:22:43 -0500, D'Arcy J.M. Cain wrote: > Calculating machines that handled > floating point are older than Python by far. Yes, and they almost universally give the result 1/2 -> 0.5. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How about adding rational fraction to Python?

2008-02-28 Thread Steven D'Aprano
On Thu, 28 Feb 2008 11:13:27 -0500, D'Arcy J.M. Cain wrote: >> >Automatic conversions, okay... but converting a result when all >> > inputs are of one time, NO... >> >> What? How does that make any sense? >> >> By that logic, we should see this: >> >> >>> len("a string") >> '8' >> >>> len([

Re: How about adding rational fraction to Python?

2008-02-28 Thread D'Arcy J.M. Cain
On 28 Feb 2008 12:25:14 -0800 Paul Rubin <"http://phr.cx"@NOSPAM.invalid> wrote: > "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes: > > > I'd like to point out that now you are talking about int OP int > > > returning a tuple, not an int. > > > > Which would be stupid. Good thing I don't think that

Re: How about adding rational fraction to Python?

2008-02-28 Thread Paul Rubin
"D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes: > > I'd like to point out that now you are talking about int OP int > > returning a tuple, not an int. > > Which would be stupid. Good thing I don't think that "obvious" should > be the criteria. We already have that function (divmod) and it is very

Re: How about adding rational fraction to Python?

2008-02-28 Thread D'Arcy J.M. Cain
On Thu, 28 Feb 2008 13:32:06 -0500 "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote: > On Thu, 2008-02-28 at 11:22 -0500, D'Arcy J.M. Cain wrote: > > Not obvious to you. You are using subjective perception as if it was > > a > > law of nature. If "obvious" was the criteria then I would argue that > > th

Re: How about adding rational fraction to Python?

2008-02-28 Thread Ross Ridge
D'Arcy J.M. Cain wrote: > Not obvious to you. You are using subjective perception as if it was > a law of nature. If "obvious" was the criteria then I would argue that > the only proper result of integer division is (int, int). Give me the > result and the remainder and let me figure it out. J

Re: How about adding rational fraction to Python?

2008-02-28 Thread J. Cliff Dyer
On Thu, 2008-02-28 at 11:22 -0500, D'Arcy J.M. Cain wrote: > Not obvious to you. You are using subjective perception as if it was > a > law of nature. If "obvious" was the criteria then I would argue that > the only proper result of integer division is (int, int). Give me the > result and the re

Re: How about adding rational fraction to Python?

2008-02-28 Thread D'Arcy J.M. Cain
On Thu, 28 Feb 2008 06:10:13 -0800 (PST) Carl Banks <[EMAIL PROTECTED]> wrote: > On Feb 28, 3:30 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > > Automatic conversions, okay... but converting a result when all > > inputs are of one time, NO... > > People, this is so cognitive dissonanc

Re: How about adding rational fraction to Python?

2008-02-28 Thread D'Arcy J.M. Cain
On Thu, 28 Feb 2008 10:39:51 - "Steven D'Aprano" <[EMAIL PROTECTED]> wrote: > On Thu, 28 Feb 2008 00:30:11 -0800, Dennis Lee Bieber wrote: > > Automatic conversions, okay... but converting a result when all > > inputs are of one time, NO... > > What? How does that make any sense? > > By t

Re: How about adding rational fraction to Python?

2008-02-28 Thread Carl Banks
On Feb 28, 9:36 am, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2008-02-28, Carl Banks <[EMAIL PROTECTED]> wrote: > > >> Automatic conversions, okay... but converting a result when > >> all inputs are of one time, NO... > > > People, this is so cognitive dissonance it's not even funny. > > > Ther

Re: How about adding rational fraction to Python?

2008-02-28 Thread Torsten Bronger
Hallöchen! Grant Edwards writes: > [...] > >> You people can't tell the difference between "obvious" and >> "learned conventions that came about because in limitations in >> the hardware at the time". > > It seems to me that the expectation that 1/2 yield 0.5 is just as > much a convention as tha

Re: How about adding rational fraction to Python?

2008-02-28 Thread Grant Edwards
On 2008-02-28, Carl Banks <[EMAIL PROTECTED]> wrote: >> Automatic conversions, okay... but converting a result when >> all inputs are of one time, NO... > > People, this is so cognitive dissonance it's not even funny. > > There is absolutely nothing obvious about 1/2 returning a number that > isn'

Re: How about adding rational fraction to Python?

2008-02-28 Thread Carl Banks
On Feb 28, 3:30 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > Automatic conversions, okay... but converting a result when all > inputs are of one time, NO... People, this is so cognitive dissonance it's not even funny. There is absolutely nothing obvious about 1/2 returning a number

Re: How about adding rational fraction to Python?

2008-02-28 Thread Steven D'Aprano
On Thu, 28 Feb 2008 00:30:11 -0800, Dennis Lee Bieber wrote: > On Thu, 28 Feb 2008 01:25:32 -, Steven D'Aprano > <[EMAIL PROTECTED]> declaimed the following in > comp.lang.python: > >> When it comes to mixed arithmetic, it's just too darn inconvenient to >> forbid automatic conversions. Other

Re: How about adding rational fraction to Python?

2008-02-28 Thread Paul Rubin
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes: > For implementing this in Python you have to carry an "is allowed to be > coerced to float" flag with every integer object to decide at run time if > it is an error to add it to a float or not. Yeah, I guess it's not workable in a dynamic langu

Re: How about adding rational fraction to Python?

2008-02-27 Thread Marc 'BlackJack' Rintsch
On Wed, 27 Feb 2008 19:00:19 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> Okay, that's just insane, making distinctions between literals and >> variables like that. >> >> 1 + 1.0 # okay > > => Yes > >> x = 1 >> x + 1.0 # is this okay or not? who knows? > > => Ye

Re: How about adding rational fraction to Python?

2008-02-27 Thread Steven D'Aprano
On Wed, 27 Feb 2008 18:43:24 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> def pmean(data): # Paul Rubin's mean >> """Returns the arithmetic mean of data, unless data is all ints, in >> which case returns the mean rounded to the nearest integer less >> than

Re: How about adding rational fraction to Python?

2008-02-27 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Okay, that's just insane, making distinctions between literals and > variables like that. > > 1 + 1.0 # okay => Yes > x = 1 > x + 1.0 # is this okay or not? who knows? => Yes, ok > len('s') + 1.0 # forbidden Yes, forbidden. More examples:

Re: How about adding rational fraction to Python?

2008-02-27 Thread Steven D'Aprano
On Wed, 27 Feb 2008 18:08:29 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> When it comes to mixed arithmetic, it's just too darn inconvenient to >> forbid automatic conversions. Otherwise you end up either forbidding >> things like 1 + 1.0 on the basis that it isn't cle

Re: How about adding rational fraction to Python?

2008-02-27 Thread Dan Bishop
On Feb 26, 11:21 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote: > On Feb 26, 11:55 pm, Paul Rubin wrote: > > > So use: return sum(number_list) / float(len(number_list)) > > That makes it somewhat more explicit what you want. Otherwise > > But that fails for a list of Dec

Re: How about adding rational fraction to Python?

2008-02-27 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > def pmean(data): # Paul Rubin's mean > """Returns the arithmetic mean of data, unless data is all > ints, in which case returns the mean rounded to the nearest > integer less than the arithmetic mean.""" > s = sum(data) > if isins

Re: How about adding rational fraction to Python?

2008-02-27 Thread Steven D'Aprano
On Wed, 27 Feb 2008 17:07:37 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> Oh come on. With a function named "mean" that calculates the sum of a >> list of numbers and then divides by the number of items, what else >> could it be? > > You have a bunch of marbles you wa

Re: How about adding rational fraction to Python?

2008-02-27 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > When it comes to mixed arithmetic, it's just too darn inconvenient to > forbid automatic conversions. Otherwise you end up either forbidding > things like 1 + 1.0 on the basis that it isn't clear whether the > programmer wants an int result or a floa

Re: How about adding rational fraction to Python?

2008-02-27 Thread Steven D'Aprano
On Tue, 26 Feb 2008 21:41:16 -0800, Paul Rubin wrote: > Mark Dickinson <[EMAIL PROTECTED]> writes: >> > So use:  return sum(number_list) / float(len(number_list)) That makes >> > it somewhat more explicit what you want.  Otherwise >> >> But that fails for a list of Decimals... > > Again, that de

Re: How about adding rational fraction to Python?

2008-02-27 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Oh come on. With a function named "mean" that calculates the sum of a > list of numbers and then divides by the number of items, what else could > it be? You have a bunch of marbles you want to put into bins. The division tells you how many marbles

Re: How about adding rational fraction to Python?

2008-02-27 Thread Steven D'Aprano
On Tue, 26 Feb 2008 20:55:14 -0800, Paul Rubin wrote: > Mark Dickinson <[EMAIL PROTECTED]> writes: >> def mean(number_list): >> return sum(number_list)/len(number_list) >> >> If you pass a list of floats, complex numbers, Fractions, or Decimal >> instances to mean() then it'll work just fine.

Re: How about adding rational fraction to Python?

2008-02-27 Thread Ross Ridge
Mark Dickinson <[EMAIL PROTECTED]> wrote: >True division and floor division are different operations. It doesn't >seem ridiculous to use different operators for them. I don't have a problem with there being different operators for integer and floating-point division. I have a problem with the b

Re: How about adding rational fraction to Python?

2008-02-26 Thread Paul Rubin
"Gabriel Genellina" <[EMAIL PROTECTED]> writes: > They exist since this semantic change was introduced *seven* *years* > ago, in 2001, so it's not that suddenly the Python world is going to > be upside down... I can't believe how long this thread is by now... I don't think it's a sudden uproar a

Re: How about adding rational fraction to Python?

2008-02-26 Thread Paul Rubin
Mark Dickinson <[EMAIL PROTECTED]> writes: > > So use:  return sum(number_list) / float(len(number_list)) > > That makes it somewhat more explicit what you want.  Otherwise > > But that fails for a list of Decimals... Again, that depends on what your application considers to be failure. Heck, int

Re: How about adding rational fraction to Python?

2008-02-26 Thread Gabriel Genellina
En Wed, 27 Feb 2008 00:39:09 -0200, Mark Dickinson <[EMAIL PROTECTED]> escribió: > On Feb 26, 9:00 pm, Paul Rubin wrote: >> Certainly, I'd expect that if x and y are both integers and x is an >> exact multiple of y, then x/y will be computable and not overflow. >> But t

Re: How about adding rational fraction to Python?

2008-02-26 Thread Mark Dickinson
On Feb 26, 11:55 pm, Paul Rubin wrote: > So use:  return sum(number_list) / float(len(number_list)) > That makes it somewhat more explicit what you want.  Otherwise But that fails for a list of Decimals... Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: How about adding rational fraction to Python?

2008-02-26 Thread Paul Rubin
Mark Dickinson <[EMAIL PROTECTED]> writes: > def mean(number_list): > return sum(number_list)/len(number_list) > > If you pass a list of floats, complex numbers, Fractions, or Decimal > instances to mean() then it'll work just fine. But if you pass > a list of ints or longs, it'll silently r

Re: How about adding rational fraction to Python?

2008-02-26 Thread Jeff Schwab
Mark Dickinson wrote: > On Feb 26, 9:00 pm, Paul Rubin wrote: >> Certainly, I'd expect that if x and y are both integers and x is an >> exact multiple of y, then x/y will be computable and not overflow. >> But try computing 10**5000 / 10**4000 under future division (that

Re: How about adding rational fraction to Python?

2008-02-26 Thread Gabriel Genellina
En Tue, 26 Feb 2008 15:01:57 -0200, Jeff Schwab <[EMAIL PROTECTED]> escribió: > J. Cliff Dyer wrote: >> Of course. That's why I think you ought to spell it 3//4. Nobody gets >> confused when a strange operator that they've never seen before does >> something unusual. Average Jo off the street

Re: How about adding rational fraction to Python?

2008-02-26 Thread Mark Dickinson
On Feb 26, 4:59 pm, Ross Ridge <[EMAIL PROTECTED]> wrote: > No, the discussion has been about the behaviour of the division operator > in Python when used with Python's integral and floating-point data types. > These data types include many numbers that are not natural numbers. I'm surprised that

Re: How about adding rational fraction to Python?

2008-02-26 Thread Mark Dickinson
On Feb 26, 9:00 pm, Paul Rubin wrote: > Certainly, I'd expect that if x and y are both integers and x is an > exact multiple of y, then x/y will be computable and not overflow. > But try computing 10**5000 / 10**4000 under future division (that is > supposed to give a flo

Re: How about adding rational fraction to Python?

2008-02-26 Thread Grant Edwards
On 2008-02-27, J. Clifford Dyer <[EMAIL PROTECTED]> wrote: > But I don't think that *was* the issue in the first place. The > issue is whether python's division should only yield integers > when given integer inputs. "Natural" is a polemical term no > matter who is using it in this argument, so l

Re: How about adding rational fraction to Python?

2008-02-26 Thread Paul Rubin
"J. Clifford Dyer" <[EMAIL PROTECTED]> writes: > If the issue is that it should > remain an integer because that mimics how the computer works, than I > think it is worth pointing out that allowing a conversion to a long also > goes against how the computer works; the computer would have a register

Re: How about adding rational fraction to Python?

2008-02-26 Thread J. Clifford Dyer
On Tue, 2008-02-26 at 14:08 -0800, Jeff Schwab wrote: > J. Cliff Dyer wrote: > > On Tue, 2008-02-26 at 13:51 -0500, D'Arcy J.M. Cain wrote: > >> On Tue, 26 Feb 2008 13:39:38 -0500 > >> "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote: > >> a = 2 * 2 > >> b = 20 * 20 > >> type(a

Re: How about adding rational fraction to Python?

2008-02-26 Thread Jeff Schwab
Grant Edwards wrote: > On 2008-02-26, Jeff Schwab <[EMAIL PROTECTED]> wrote: >> Grant Edwards wrote: >> >>> I guess it must depend on where you went to shool. >> Temple Israel. You? > > Good one. :) I make a lot of typo's on Usenet, so I'm always secretly relieved when other people do, too. (I

Re: How about adding rational fraction to Python?

2008-02-26 Thread Jeff Schwab
Paul Rubin wrote: > "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes: >>> http://en.wikipedia.org/wiki/Natural_number >> Recheck the context. I was talking about the natural result, not >> natural numbers. > > The natural result of doing arithmetic with natural numbers is more > natural numbers.

Re: How about adding rational fraction to Python?

2008-02-26 Thread Jeff Schwab
J. Cliff Dyer wrote: > On Tue, 2008-02-26 at 13:51 -0500, D'Arcy J.M. Cain wrote: >> On Tue, 26 Feb 2008 13:39:38 -0500 >> "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote: >> a = 2 * 2 >> b = 20 * 20 >> type(a) >>> >> type(b) >>> >> A long int is still integral which is

Re: How about adding rational fraction to Python?

2008-02-26 Thread Steven D'Aprano
On Tue, 26 Feb 2008 14:46:04 -0500, D'Arcy J.M. Cain wrote: > I am really having a hard time accepting that "TRUTH (tm)" is determined > by election. But you're apparently perfectly comfortable that "TRUTH (tm)" is decided by fiat. -- Steven -- http://mail.python.org/mailman/listinfo/python-

Re: How about adding rational fraction to Python?

2008-02-26 Thread Arnaud Delobelle
On Feb 26, 9:47 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Tue, 26 Feb 2008 11:43:56 -0500, D'Arcy J.M. Cain wrote: > > Integer division means integer result to me in a very real sense. > > So, when you have five children over for a birthday party, and one cake, > do you

Re: How about adding rational fraction to Python?

2008-02-26 Thread Ross Ridge
Ross Ridge <[EMAIL PROTECTED]> writes: > D'Arcy said nothing about natural numbers, and bringing them up adds > nothing to this discussion. Paul Rubin wrote: > The numbers D'Arcy is proposing to operate on that way are natural > numbers whether he says so or not. No, t

Re: How about adding rational fraction to Python?

2008-02-26 Thread Torsten Bronger
Hallöchen! Grant Edwards writes: > On 2008-02-26, Torsten Bronger <[EMAIL PROTECTED]> wrote: > >> Grant Edwards writes: >> >>> [...] >>> >>> Nope. I would prefer that int OP int always produce an int. >> >> And 2**-1? > > An error. ? Not here. Tschö, Torsten. -- Torsten Bronger, aquisgrana,

Re: How about adding rational fraction to Python?

2008-02-26 Thread Steven D'Aprano
On Tue, 26 Feb 2008 11:43:56 -0500, D'Arcy J.M. Cain wrote: > Integer division means integer result to me in a very real sense. So, when you have five children over for a birthday party, and one cake, do you say "Sorry kids, no cake for you: one cake divided by five is zero"? Of course you do,

Re: How about adding rational fraction to Python?

2008-02-26 Thread Grant Edwards
On 2008-02-26, Torsten Bronger <[EMAIL PROTECTED]> wrote: > Hallöchen! > > Grant Edwards writes: > >> [...] >> >> Nope. I would prefer that int OP int always produce an int. > > And 2**-1? An error. > Your formulation tries to suggest some sort of logical > consequence but in my opinion, it's st

Re: How about adding rational fraction to Python?

2008-02-26 Thread Grant Edwards
On 2008-02-26, Paul Rubin wrote: > "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes: >> > http://en.wikipedia.org/wiki/Natural_number >> Recheck the context. I was talking about the natural result, not >> natural numbers. > > The natural result of doing arithmetic with natural numbers is more > natu

Re: How about adding rational fraction to Python?

2008-02-26 Thread Paul Rubin
Ross Ridge <[EMAIL PROTECTED]> writes: > > The natural result of doing arithmetic with natural numbers is more > > natural numbers. > > D'Arcy said nothing about natural numbers, and bringing them up adds > nothing to this discussion. The numbers D'Arcy is proposing to operate on that way are n

Re: How about adding rational fraction to Python?

2008-02-26 Thread Ross Ridge
Paul Rubin wrote: > http://en.wikipedia.org/wiki/Natural_number "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes: > Recheck the context. I was talking about the natural result, not > natural numbers. Paul Rubin wrote: > The natural result of d

Re: How about adding rational fraction to Python?

2008-02-26 Thread Paul Rubin
"D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes: > > http://en.wikipedia.org/wiki/Natural_number > Recheck the context. I was talking about the natural result, not > natural numbers. The natural result of doing arithmetic with natural numbers is more natural numbers. -- http://mail.python.org/ma

Re: How about adding rational fraction to Python?

2008-02-26 Thread Ross Ridge
D'Arcy J.M. Cain <[EMAIL PROTECTED]> wrote: >I don't think that it is a travesty either. I would also not be so >offended if the language treated it that way from the start although I >would still have had to get used to it having spent so much time in C >and assembler which has natural results.

Re: How about adding rational fraction to Python?

2008-02-26 Thread Terry Reedy
"Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message | >>> 3/5 | 0.59998 I think this either changed in 3.0a2 or may in upcoming releases. -- http://mail.python.org/mailman/listinfo/python-list

Re: How about adding rational fraction to Python?

2008-02-26 Thread D'Arcy J.M. Cain
On 26 Feb 2008 12:53:48 -0800 Paul Rubin <"http://phr.cx"@NOSPAM.invalid> wrote: > "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes: > > Note, I use the word "natural" above. Natural is an opinion and that > > happens to be mine. > > http://en.wikipedia.org/wiki/Natural_number Recheck the context

Re: How about adding rational fraction to Python?

2008-02-26 Thread Paul Rubin
"D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes: > Note, I use the word "natural" above. Natural is an opinion and that > happens to be mine. http://en.wikipedia.org/wiki/Natural_number -- http://mail.python.org/mailman/listinfo/python-list

Re: How about adding rational fraction to Python?

2008-02-26 Thread Torsten Bronger
Hallöchen! Grant Edwards writes: > [...] > > Nope. I would prefer that int OP int always produce an int. And 2**-1? Your formulation tries to suggest some sort of logical consequence but in my opinion, it's still a mere matter of taste and habits. I remember my first steps in C++ 12 years ago

Re: How about adding rational fraction to Python?

2008-02-26 Thread D'Arcy J.M. Cain
On Tue, 26 Feb 2008 14:16:20 -0500 "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote: > I agree that integer division is useful and important, but I don't think > it's a travesty to support other kinds of division, especially when > integer division still has its own operator. I don't think that it is a t

Re: How about adding rational fraction to Python?

2008-02-26 Thread Grant Edwards
On 2008-02-26, J. Cliff Dyer <[EMAIL PROTECTED]> wrote: > So do you believe that you should not be able to do natural > division without explicitly casting ints as floats, IMO, you're begging the question by using the phrase "natural division" when what you mean is "floating point division", but

Re: How about adding rational fraction to Python?

2008-02-26 Thread Grant Edwards
On 2008-02-26, Mensanator <[EMAIL PROTECTED]> wrote: >> How soon before 2.x is completely deprecated and I have to become a >> Walmart greeter? > > Personally, I plan to drop Python if support for the gmpy module > ever dries up. But I won't be a quitter, just have to start using > C which will su

Re: How about adding rational fraction to Python?

2008-02-26 Thread Grant Edwards
On 2008-02-26, Jeff Schwab <[EMAIL PROTECTED]> wrote: > Grant Edwards wrote: > >> I guess it must depend on where you went to shool. > > Temple Israel. You? Good one. :) -- Grant Edwards grante Yow! Do you think the at

  1   2   >