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, 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: Place n indistinguishable items into k distinguishable boxes

2008-02-27 Thread Mark Dickinson
Here's a possible solution. I'm sure others will comment on how to fix up its inefficiencies (like the potentially slow string concatenations...). def comb(n, k): if n == k == 0: yield '' else: if n > 0: for x in comb(n-1, k): yield ' ' + x

Re: Place n indistinguishable items into k distinguishable boxes

2008-02-27 Thread Mark Dickinson
On Feb 27, 11:38 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote: >             yield map(len, (''.join(s)).split('|')) That line should have been just: yield map(len, s.split('|')) of course. Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: Place n indistinguishable items into k distinguishable boxes

2008-02-28 Thread Mark Dickinson
On Feb 28, 5:02 am, Michael Robertson <[EMAIL PROTECTED]> wrote: > Thanks again for your efforts here.  This particular problem didn't > appear in any course I took...certainly similar problems did. And here's the obligatory not-very-obfuscated one-liner: from itertools import combinations as c;

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 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 > >

Re: Bit twiddling floating point numbers

2008-03-05 Thread Mark Dickinson
On Mar 5, 3:25 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I can pack and unpack a float into a long > e.g. > struct.unpack('I',struct.pack('f',0.123))[0] > but then I'm not sure how to work with the resulting long. > > Any suggestions? One alternative to using struct is to use math.ldexp

Re: float / rounding question

2008-03-07 Thread Mark Dickinson
On Mar 7, 5:12 pm, Piet van Oostrum <[EMAIL PROTECTED]> wrote: > Python just uses the C library for printing, I presume, and the conversion > routines in the C library are rather simplistic. It is, however, possible > to do better, so that 53.6 -- although internally represented as something > that

Re: float / rounding question

2008-03-08 Thread Mark Dickinson
On Mar 7, 11:23 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Fri, 07 Mar 2008 23:12:27 +0100, Piet van Oostrum wrote: > > Sorry to come in so late in this discussion. Although it is correct to > > say that many real numbers that have an exact decimal representation > > can

Re: float / rounding question

2008-03-08 Thread Mark Dickinson
On Mar 8, 11:34 am, Mark Dickinson <[EMAIL PROTECTED]> wrote: > following, which arises from Python arbitrarily stripping trailing > zeros from the result returned by the C library functions: Correction: on closer examination it's not Python doing the stripping of trailing

Re: Arbitrary precision integer arithmetic: ceiling?

2008-03-08 Thread Mark Dickinson
On Mar 8, 6:26 pm, Paul Rubin wrote: > Alasdair <[EMAIL PROTECTED]> writes: > > What is the best way of finding a ceiling of a quotient of arbitrary sized > > integers? > > ceiling(a/b) = (a+b-1)//b I prefer: ceiling(a/b) = -(-a)//b which also works if a and b are some

Re: Arbitrary precision integer arithmetic: ceiling?

2008-03-08 Thread Mark Dickinson
On Mar 8, 8:48 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Sat, 08 Mar 2008 17:09:11 -0800, Mark Dickinson wrote: > > I prefer: > > > ceiling(a/b) = -(-a)//b > > Unfortunately it doesn't give the right answer. > > >>&

Re: Arbitrary precision integer arithmetic: ceiling?

2008-03-08 Thread Mark Dickinson
On Mar 8, 9:19 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > Obvious typo: -(-a)//b == a//b > > This should be -(-a//b) == -((-a)//b) Yes: thanks for the correction! A lesson to me to include parentheses even when redundant... This reminds me of the following parenthesization gem (see next to

Re: How to factor using Python?

2008-03-11 Thread Mark Dickinson
On Mar 10, 7:32 pm, Nathan Pinno <[EMAIL PROTECTED]> wrote: > Thanks on the factoring bit, but I did mean factorial, not factoring. > How do I code that correctly, so that I can figure the following > equation out: cos(Pi * (z-1)! / z). Is z an integer in this expression? (Note: it's not an equat

Re: How to factor using Python?

2008-03-11 Thread Mark Dickinson
On Mar 10, 7:32 pm, Nathan Pinno <[EMAIL PROTECTED]> wrote: > Thanks on the factoring bit, but I did mean factorial, not factoring. > How do I code that correctly, so that I can figure the following > equation out: cos(Pi * (z-1)! / z). Python returns a invalid syntax > error and highlight the !. S

Re: urllib proxy support confusion

2008-03-11 Thread Mark Dickinson
On Mar 11, 11:35 am, Grant Edwards <[EMAIL PROTECTED]> wrote: > That seems a bit baffling.  If it urlopen doesn't support > specifying proxies, why are there examples showing how to do > it? If it does support specifying proxies, what is the pragraph > quoted above supposed to mean? Looks like a d

Re: urllib proxy support confusion

2008-03-11 Thread Mark Dickinson
On Mar 11, 12:26 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > Before I submit a bug, I'll give it a try to find out if it > does support explicit specification of proxys or not. Sounds good. If it does, then I think the whole paragraph (from "The urlopeen() function does not support explicit pr

Re: List Combinations

2008-03-12 Thread Mark Dickinson
On Mar 12, 10:18 am, Gerdus van Zyl <[EMAIL PROTECTED]> wrote: > I have a list that looks like this: > [['3'], ['9', '1'], ['5'], ['4'], ['2', '5', '8']] > > how can I get all the combinations thereof that looks like as follows: You could wait for Python 2.6, or download the current alpha: Python

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: ValueError in pickle module during unpickling a infinite float (python 2.5.2)

2008-03-12 Thread Mark Dickinson
On Mar 12, 11:22 am, [EMAIL PROTECTED] wrote: > Unpickling an infinite float caused a ValueError in the pickle module. > I need to pickle and load infinite floats in my project. Do you have > any suggestions how to solve the issue? Have you tried this on the recent 2.6 alpha (Python2.6a1)? It's a

Re: no more comparisons

2008-03-13 Thread Mark Dickinson
On Mar 13, 3:48 pm, Alan Isaac <[EMAIL PROTECTED]> wrote: > So maybe this is not as bad as I feared.  What are some use > > cases that will clearly be harder (i.e., at least require > > a slightly elaborate wrapper) after this change? Sorting tuples, where the second item in the tuple should have

Re: no more comparisons

2008-03-13 Thread Mark Dickinson
On Mar 13, 5:10 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote: > (1, '14') represents 14 should be -14, of course. -- http://mail.python.org/mailman/listinfo/python-list

Re: no more comparisons

2008-03-13 Thread Mark Dickinson
On Mar 13, 8:38 pm, Alan Isaac <[EMAIL PROTECTED]> wrote: > Does this do it? :: > >     key= lambda x: (-x[1],int(x2)) > > Here I am depending on the lexicographic sorting of tuples. > Without that there would be real trouble. Close. :-) I think it needs to be something like: key = lambda x: (-x

Re: urllib proxy support confusion

2008-03-14 Thread Mark Dickinson
On Mar 11, 11:35 am, Grant Edwards <[EMAIL PROTECTED]> wrote: > Reading through the doc athttp://docs.python.org/lib/module-urllib.html, > there are several paragraphs (including code examples) showing > how you specify what proxies to use when calling urlopen(): See http://bugs.python.org/issue22

Re: Newbie: unsigned shift right

2008-03-26 Thread Mark Dickinson
On Mar 26, 5:42 pm, Sal <[EMAIL PROTECTED]> wrote: > Is there any way to do an unsigned shift right in Python? When I enter > (-1>>1) the answer is -1. What I'm looking for is the equivalent of an > unsigned shift in C or the ">>>" operator in Java. What answer were you hoping for, and why? 2**31

Re: nth root

2009-01-31 Thread Mark Dickinson
On Jan 31, 5:43 am, "Tim Roberts" wrote: > Dan, > > Thanks - you're probably right - just my intuition said to me that rather > than calculating that the 13th root of > 4021503534212915433093809093996098953996019232 > is 3221.2904208350265 > there must be a quicker way of finding out its bet

Re: nth root

2009-01-31 Thread Mark Dickinson
On Jan 31, 1:23 pm, Steve Holden wrote: > [Mark] > > power operation.  The integer -> float conversion is probably quite > > significant, timewise. > > I bow to your superior intuition! Here's another timing that shows the significance of the int -> float conversion: (non-debug build of the trunk

Re: nth root

2009-01-31 Thread Mark Dickinson
On Jan 31, 1:23 pm, Steve Holden wrote: > Much more significant points, given the limited precision of the doubles > Python will be using. Could gmpy do this better, I wonder? Almost certainly, if exact results are wanted! At least, GMP has an mpz_root function; I don't know offhand whether gmpy

Re: nth root

2009-01-31 Thread Mark Dickinson
On Jan 31, 4:48 pm, Dan Goodman wrote: > I don't think accuracy is too big a problem here actually (at least for > 13th roots). I just tested it with several hundred thousand random 100 > digit numbers and it never made a mistake. Well, random numbers is one thing. But how about the following:

Re: nth root

2009-01-31 Thread Mark Dickinson
On Jan 31, 7:04 pm, ajaksu wrote: > also a great way make some innocent bystander waste his eyesight > trying to figure out the magic trick :D Oh, come on! At least I put the two lines next to each other! :-) Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: Number of bits/sizeof int

2009-02-02 Thread Mark Dickinson
On Jan 31, 7:03 am, Jon Clements wrote: > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. It's a bit cheeky, but: from decimal import _nbits as nbits should also work in 2.5.2 (but not in 2.5.1)! Mark -- http://mail.python.org/mailman/listinfo/python-l

Re: Number of bits/sizeof int

2009-02-03 Thread Mark Dickinson
On Feb 3, 1:19 am, Mark Wooding wrote: > Yeah, I made some arbitrary choices about what to do with non-positive > inputs.  If you prefer other answers, use 'em.  My ones work well with > signed-magnitude representations where the sign is stored separately. Not *that* arbitrary: they're the same

Re: sys.float_info.epsilon

2009-02-04 Thread Mark Dickinson
On Feb 4, 7:18 pm, Tim Rowe wrote: > I didn't realise that float() could return anything with an absolute > value less than sys.float_value.epsilon other than 0.0 (which I think > all representations can represent exactly).  What am I missing here? There are many positive floating-point values sm

Re: sys.float_info.epsilon

2009-02-04 Thread Mark Dickinson
On Feb 4, 7:52 pm, Scott David Daniels wrote: > You are missing the whole thing that mes floating point tricky. > I _believe_ that the epsilon is the smallest positive x such that >     1.0 != 1.0 + x Nitpick alert: this isn't quite the same thing, since that definition is affected by rounding.

Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.

2009-02-05 Thread Mark Dickinson
On Feb 5, 1:18 am, Chris Rebert wrote: > For an integer: > is_even = bin(the_int)[2:].count('1') % 2 == 0 But the OP has to use if and while. How about: while 2+2 != 5: if 'wkw' in 'just being awkward': is_even = bin(the_int)[2:].count('1') % 2 == 0 break or (Python 2.5 com

Re: sys.float_info.epsilon

2009-02-05 Thread Mark Dickinson
On Feb 4, 9:44 pm, Tim Rowe wrote: > That just leaves me puzzled as to why Mark Summerfield used it instead > of a check against zero on user input. No idea: you'd have to ask Mark Summerfield. If there's an email address published in his book, I'm sure he wouldn't object to the question. > So

Re: Flattening lists

2009-02-05 Thread Mark Dickinson
On Feb 5, 1:17 pm, mk wrote: > Hello everybody, > > Any better solution than this? > > def flatten(x): Just out of interest, how often do people really need such a recursive flatten, as opposed to a single-level version? I often find myself needing a 'concat' method that turns a list of lists (o

Re: Is c.l.py becoming less friendly?

2009-02-06 Thread Mark Dickinson
On Feb 6, 6:23 am, "Hendrik van Rooyen" wrote: > I think this thread has buggered up a perfectly ^^^ Such language. I'm appalled. Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: datetime.time and midnight

2009-02-22 Thread Mark Dickinson
On Feb 21, 10:44 pm, Ethan Furman wrote: > --> midnight = datetime.time(0,0,0) > --> bool(midnight) > False I'd call this a bug. Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: datetime.time and midnight

2009-02-22 Thread Mark Dickinson
On Feb 22, 9:18 am, Mark Dickinson wrote: > On Feb 21, 10:44 pm, Ethan Furman wrote: > > > --> midnight = datetime.time(0,0,0) > > --> bool(midnight) > > False > > I'd call this a bug. ...although looking at the source (see the function time_nonzero in

Re: Enumerating k-segmentations of a sequence

2008-11-25 Thread Mark Dickinson
On Nov 25, 4:56 pm, bullockbefriending bard <[EMAIL PROTECTED]> wrote: > I'm not sure if my terminology is precise enough, but what I want to > do is: > [snip problem description] > Structural Recursion not being my strong point, any ideas on how to go > about this would be much appreciated! If yo

Re: Enumerating k-segmentations of a sequence

2008-11-25 Thread Mark Dickinson
On Nov 25, 5:34 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote: > If you have Python 2.6 available, itertools.combination might be That should be itertools.combinations, of course. The idea is that to give a partition of e.g., a 5-element list into 3 nonempty pieces, all you have to

Re: Rich Comparisons Gotcha

2008-12-07 Thread Mark Dickinson
On Dec 7, 4:23 pm, Rasmus Fogh <[EMAIL PROTECTED]> wrote: > If is is possible to change the language, how about having two > diferent functions, one for overloading the '==' operator, and another > for testing list and set membership, dictionary key identity, etc.? I've often thought that this wo

built-in functions as class attributes

2008-12-08 Thread Mark Dickinson
Here's a curiosity: after def my_hex(x): return hex(x) one might expect hex and my_hex to be interchangeable in most situations. But (with both Python 2.x and 3.x) I get: >>> def my_hex(x): return hex(x) ... >>> class T(object): f = hex ... >>> class T2(object): f = my_hex ... >>> T().f(12

Re: built-in functions as class attributes

2008-12-08 Thread Mark Dickinson
On Dec 8, 11:23 am, Peter Otten <[EMAIL PROTECTED]> wrote: > I don't know if there is something official, I google for > > http://users.rcn.com/python/download/Descriptor.htm > > or "descrintro" every time I need a refresher. Thank you! I'd read this before, but apparently I'd either not taken it

Re: Rich Comparisons Gotcha

2008-12-09 Thread Mark Dickinson
indeed NaN does behave this way > # in collections at the moment. All we are doing is documenting it clearly. > > # numpy > Numpy would have no __equal__ function, so we would have pure identity > semantics - 'equals(x,y)' would be the same as 'x is y' > > # or

Re: Factoring Polynomials

2008-12-18 Thread Mark Dickinson
On Dec 18, 8:47 pm, Scott David Daniels wrote: >      else: # a single result (discriminant is zero) >          return (-b / (2 * a),) Maybe make that (-b / (2. * a)) to avoid getting funny results when a and b are integers. (Or do a from __future__ import division, or use Python 3.0, or )

Re: no sign() function ?

2008-12-23 Thread Mark Dickinson
On Dec 23, 2:59 pm, Christian Heimes wrote: > All algorithm including my own suffer from one mistake. Nobody accounts > for NaN (not a number). You have to check for NaNs, too. NaNs have no > sign at all. I think that's not quite true: NaNs have a sign; it's just not accorded any particular mea

Re: no sign() function ?

2008-12-23 Thread Mark Dickinson
On Dec 23, 4:27 pm, ajaksu wrote: > Is "x ** 0 > 0." instead of "atan2(x, -1.) > 0." unreliable across > platforms? x**0 doesn't distinguish between x = -0.0 and x = 0.0. I suspect you're confusing -0.0**0.0 with (-0.0)**0.0. Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: math module for Decimals

2008-12-28 Thread Mark Dickinson
On Dec 28, 12:02 am, jerry.carl...@gmail.com wrote: > I have been looking for a Python module with math functions that would > both eat and spit Decimals. The standard math module eats Decimals > allright but spits floats. Yes: it just converts the input (whether float, int, Fraction or Decimal) t

Re: math module for Decimals

2008-12-28 Thread Mark Dickinson
On Dec 28, 7:28 am, Steven D'Aprano wrote: > Ah crap, I forgot that from_float() has been left out of the decimal API. > That's very annoying. Agreed. It's maybe even annoying enough that a feature request at bugs.python.org might be honoured. (Hint, hint!) It's fairly easy to emulate in Pytho

Re: math module for Decimals

2008-12-28 Thread Mark Dickinson
On Dec 28, 3:55 pm, jerry.carl...@gmail.com wrote: > But i am after the extra precision: > > >>> from math import * > >>> (1+1e-16)-1 > > 0.0 Sounds like you don't care too much about the base-10 part, so there may be other solutions out there. Have you tried: 1. mpmath? 2. sympy? 3. Sage? Any

Re: math module for Decimals

2009-01-03 Thread Mark Dickinson
On Dec 31 2008, 11:02 pm, Steven D'Aprano wrote: > On Sun, 28 Dec 2008 06:38:32 -0800, Mark Dickinson wrote: > > On Dec 28, 7:28 am, Steven D'Aprano > cybersource.com.au> wrote: > >> Ah crap, I forgot that from_float() has been left out of the decimal > >&

Re: math module for Decimals

2009-01-03 Thread Mark Dickinson
On Jan 3, 9:27 pm, Mark Dickinson wrote: > Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 > and Python 3.1, within 72 hours of Steven submitting the feature > request.  If only all issues could be resolved this quickly. :-) Rats. I left out the crucial line of

Re: math module for Decimals

2009-01-04 Thread Mark Dickinson
On Jan 4, 9:52 am, "alex goretoy" wrote: > Also, another reason why I'm posting to this thread. I noticed some > error/typo in line 683 of decimal.py located on public svn repo. This is > what is looks like. > >         sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 This line looks okay to me;

Re: math module for Decimals

2009-01-04 Thread Mark Dickinson
On Jan 4, 10:38 am, "alex goretoy" wrote: > haha python-svn # python Lib/decimal.py >   File "Lib/decimal.py", line 683 >     sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 >               ^ > SyntaxError: invalid syntax > > Although, It may be only because I ran it through python 2.4.3 Ah yes,

Re: math module for Decimals

2009-01-06 Thread Mark Dickinson
On Mon, Jan 5, 2009 at 4:50 PM, alex goretoy wrote: > I get this when importing decimal: > > Python 2.7a0 (trunk:68339M, Jan 5 2009, 05:18:41) > [GCC 3.4.6] on linux2 > Type "help", "copyright", "credits" or "license" for more information. import decimal > Traceback (most recent call last):

Re: math module for Decimals

2009-01-06 Thread Mark Dickinson
On Jan 6, 3:23 pm, Fredrik Johansson wrote: > FYI, mpmath (http://code.google.com/p/mpmath/) implements arbitrary- > precision standard transcendental functions in pure Python. It is much > faster than decimal, dmath, decimalfuncs and AJDecimalMathAdditions, > and handles huge arguments just fine.

Re: eval('07') works, eval('08') fails, why?

2009-01-08 Thread Mark Dickinson
On Jan 8, 9:31 am, Alex van der Spek wrote: > >>> eval('07') > 7 > >>> eval('08') > > Traceback (most recent call last): >   File "", line 1, in >     eval('08') >   File "", line 1 >     08 >      ^ > SyntaxError: invalid token An integer literal with a leading zero is interpreted as an octal

Re: Unexpected scientific notation

2009-01-09 Thread Mark Dickinson
On Jan 8, 1:00 am, Paul McNett wrote: > It displays '3E+1' instead of '30.0'. > > As I can't reproduce I'm looking for an idea brainstorm of what could be > causing > this. What would be choosing to display such a normal number in scientific > notation? > > Ideas? [I thought I replied to this e

Re: Unexpected scientific notation

2009-01-09 Thread Mark Dickinson
On Jan 9, 5:16 pm, Paul McNett wrote: > Thank you for the insight. I believe the problem is with my use of > normalize(), but I > still can't figure out why I can't reproduce the issue in my running app. Me neither. In particular, I can't see how it could this output could come out of a locale.

Re: Unexpected scientific notation

2009-01-09 Thread Mark Dickinson
On Jan 9, 5:38 pm, Paul McNett wrote: > I'll clarify my LOL: Mark initially replied to me directly, to which I > responded > directly. Because he replied directly, I kept my response offline, too, not > knowing > if he had a special reason to discuss this offline instead of in public. Yup, def

Re: how to get the thighest bit position in big integers?

2008-10-06 Thread Mark Dickinson
On Oct 5, 11:40 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > Your point, that taking floor(log2(x)) is redundant, is a good catch. > However, you should have added 'untested' ;-).  When value has more > significant bits than the fp mantissa can hold, this expression can be 1 > off (but no more, I a

Re: how to get the thighest bit position in big integers?

2008-10-08 Thread Mark Dickinson
On Oct 7, 5:19 pm, [EMAIL PROTECTED] wrote: > but I want to make clear that I think that (0).numbits()==-1 > is the natural solution. At least for all square-and-multiply-like > algorithms needed in [...] Can you clarify this? Why is -1 the natural solution? I can see a case for 0, for -infinity

Re: IBM integer and double formats

2008-11-10 Thread Mark Dickinson
On Nov 10, 7:20 pm, "john.goodleaf" <[EMAIL PROTECTED]> wrote: > does anyone know of an already-done means of writing > integers and floats out to their IBM mainframe equivalents? > I don't know of anything in Python that does this. There was a thread a while ago that may be relevant: http://mai

Re: IBM integer and double formats

2008-11-10 Thread Mark Dickinson
On Nov 10, 8:16 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote: > and how to handle out-of-range floats coming back (if I recall > correctly, the IBM format allows a wider range of exponents > than IEEE). > Whoops---wrong way around. It looks like it's IEEE that has th

Re: IBM integer and double formats

2008-11-10 Thread Mark Dickinson
On Nov 10, 7:20 pm, "john.goodleaf" <[EMAIL PROTECTED]> wrote: > my own routines, does anyone know of an already-done means of writing > integers and floats out to their IBM mainframe equivalents? Here's a quick attempt at converting doubles using Python. It uses the isnan and isinf functions that

Re: IBM integer and double formats

2008-11-11 Thread Mark Dickinson
On Nov 10, 11:49 pm, John Machin <[EMAIL PROTECTED]> wrote: > Call me crazy if you like, but I'd name that function IEEEtoIBM. But it's topsy-turvy day! Didn't you get the memo? Oh, all right. IEEEtoIBM it is. > That's a hexadecimal representation in lowercase with no leading > zeroes ... vari

Re: IBM integer and double formats

2008-11-11 Thread Mark Dickinson
On Nov 11, 12:07 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote: > "All character data are stored in ASCII, regardless of the > operating system." But character data is not the same thing as numeric data. Okay--- you win again, John. > Sheesh. [...] Apologies for ann

Re: IBM integer and double formats

2008-11-11 Thread Mark Dickinson
On Nov 11, 11:36 am, John Machin <[EMAIL PROTECTED]> wrote: > > wants to write the converted float out to an ASCII file, in hex. > > Sheesh. It's an *IBM mainframe* file. It would need to be in EBCDIC, > not ASCII. But why guess? He said he wanted to write it out in SAS > XPORT format. Which is st

Re: Sieve of Zakiya

2008-11-18 Thread Mark Dickinson
On Nov 18, 7:53 am, jzakiya <[EMAIL PROTECTED]> wrote: > www.4shared.com/account/dir/7467736/97bd7b71/sharing >From the introduction to the paper: "Thus began a process that culminated in my developing a new class of Number Theory Sieves (NTS) to generate prime numbers, and test primality of numb

Re: Sieve of Zakiya

2008-11-18 Thread Mark Dickinson
On Nov 18, 3:58 pm, jzakiya <[EMAIL PROTECTED]> wrote: > I am writing another paper explaining some of the mathematical basis > for the SoZ, with complexity analysis, but I keep finding > "interesting" features about the underlying math, which I hope real > mathematicians will investigate and revea

Re: Sieve of Zakiya

2008-11-19 Thread Mark Dickinson
On Nov 19, 5:16 am, jzakiya <[EMAIL PROTECTED]> wrote: [Lots of stuff snipped] > My SoZ mathematical analysis shows why its algorithmically faster than > both the SoA & SoE, to explain its demonstrated computational > superiority. Again, hopefully professional mathematicians will become > intereste

Re: Inheriting frozenset gives bug if i overwrite __repr__ method

2008-11-19 Thread Mark Dickinson
On Nov 19, 12:39 pm, srinivasan srinivas <[EMAIL PROTECTED]> wrote: > a1 = fs(1,2,3) > a2 = fs(3,4,5) > print a1.difference(a2) > > Error: >     return "%s(%r)" % (self.__class__.__name__, self.__data) > AttributeError: 'fs' object has no attribute '_fs__data' I guess you need to implement the dif

Re: Inheriting frozenset gives bug if i overwrite __repr__ method

2008-11-19 Thread Mark Dickinson
On Nov 19, 4:23 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > Yep; looks like a bug in the set/frozenset implementation. Thanks! I was about to report this to bugs.python.org, but it looks as though Raymond's been at the time machine again: http://bugs.python.org/issue1721812 It's fixed

Re: Quick nested loop syntax?

2008-11-19 Thread Mark Dickinson
On Nov 19, 5:48 pm, Johannes Bauer <[EMAIL PROTECTED]> wrote: > Hi group, > > if I remember correctly, wasn't there a way to quickly iterate through > nested loops? Something like Python 2.6 has itertools.product: http://docs.python.org/library/itertools.html#itertools.product If you don't have

Re: "/a" is not "/a" ?

2009-03-08 Thread Mark Dickinson
On Mar 7, 2:14 pm, Christian Heimes wrote: > Steven D'Aprano wrote: > > Yes. Floating point NANs are required to compare unequal to all floats, > > including themselves. It's part of the IEEE standard. > > As far as I remember that's not correct. It's just the way C has > interpreted the standard

Re: RichCompare and RichCompareBool

2009-03-09 Thread Mark Dickinson
On Mar 2, 10:33 am, Aaron Brady wrote: > The code for PyObject_RichCompare does not contain this, it doesn't > seem.  Is it a bug? It's not a bug. See revision 67204: http://svn.python.org/view?view=rev&revision=67204 Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: RichCompare and RichCompareBool

2009-03-09 Thread Mark Dickinson
On Mar 9, 3:22 pm, Aaron Brady wrote: > My complaint was that the docs for the function, as well as its name, > are misleading.  RichCompareBool should not take the short cut, and "x > in [x]" should call something else that does.  (I am not arguing > against the decided behavior of "x in [x]", bt

Re: parser module and doc

2009-03-20 Thread Mark Dickinson
On Mar 20, 7:26 am, Steven D'Aprano wrote: > "All source files mentioned here which are not part of the Python > installation are located in the Demo/parser/ directory of the > distribution." > > http://docs.python.org/library/parser.html#information-discovery > > What distribution? What does this

Re: how to convert from Decimal('1.23456789') to Decimal('1.234')

2009-03-23 Thread Mark Dickinson
On Mar 23, 7:01 am, alex23 wrote: > On Mar 23, 4:40 pm, valpa wrote: > > > I only need the 3 digits after '.' > > > Is there any way other than converting from/to string? > > I'm not sure if this is the canonical way but it works: > > >>> d = Decimal('1.23456789') > >>> three_places = Decimal('0.

Re: how to convert from Decimal('1.23456789') to Decimal('1.234')

2009-03-23 Thread Mark Dickinson
On Mar 23, 6:40 am, valpa wrote: > I only need the 3 digits after '.' > > Is there any way other than converting from/to string? And in Python 3.0, just use the built-in round function: >>> from decimal import Decimal >>> round(Decimal('1.23456789'), 3) Decimal('1.235') This uses the rounding s

Re: How can I do bit operation on python float value

2009-03-23 Thread Mark Dickinson
On Mar 23, 8:44 am, valpa wrote: > Yes, I want to do a & operation. Right, but what & operation, and why? Are you trying to do something that's mathematically meaningful? If so, there may be a better (more portable/faster/clearer) way than bit-twiddling. Mark -- http://mail.python.org/mailman/l

Re: any(), all() and empty iterable

2009-04-14 Thread Mark Dickinson
On Apr 14, 7:21 pm, Luis Alberto Zarrabeitia Gomez wrote: > It's more than that. Python's following the rules here. Maybe it could be > documented better, for those without a background in logic/discrete > mathematics, > but not changed. Agreed. I'd like to guess that in 93.7% of cases, when a

Re: Python and GMP.

2009-04-20 Thread Mark Dickinson
On Apr 20, 7:39 pm, Benjamin Peterson wrote: >   gmail.com> writes: > > > > > There are reasons why Python not used the GMP library for implementing > > its long type? > > Basically, GMP only becomes faster when the numbers are huge. That was true for one particular attempt in this direction (by

Re: Python and GMP.

2009-04-20 Thread Mark Dickinson
On Apr 20, 10:36 pm, Mark Dickinson wrote: > The other major issue is licensing:  as far as I recall, the > various discussions never came to a conclusion about the legal > implications of using GMP. It took me a while to find it... See the thread starting at http://mail.python.org/

Re: Python and GMP.

2009-04-21 Thread Mark Dickinson
On Apr 21, 12:04 pm, bearophileh...@lycos.com wrote: > Using inline ASM in Python sources isn't an option. Except when it is. :) There's a tiny amount of inline assembler in the sources already: see Python/pymath.c and Python/ceval.c. Not surprisingly, there's some in the ctypes module as well.

Re: Python and GMP.

2009-04-21 Thread Mark Dickinson
On Apr 21, 8:57 am, alessiogiovanni.bar...@gmail.com wrote: > Ok, thanks for your answers. I understand the problems of licensing, > but > we could to learn from GMP's source code to improve the Python's int > implementation, > mainly because, GMP is very fast. We could violate the GPL? Suggestion

Re: Into itertools

2009-04-27 Thread Mark Dickinson
On Apr 26, 5:32 pm, bearophileh...@lycos.com wrote: > 3) xpairs(seq) >     >>> list(xpairs(range(5))) >     [(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3), > (2, 4), (3, 4)] Doesn't itertools.combinations already do this for you? >>> list(itertools.combinations(range(5), 2)) [(

Re: for with decimal values?

2009-05-02 Thread Mark Dickinson
On May 2, 4:12 pm, Esmail wrote: > Is there a Python construct to allow me to do something like > this: > >     for i in range(-10.5, 10.5, 0.1): >       ... I'd recommend using integer arithmetic: for ten_times_i in range(-105, 106): i = ten_times_i / 10.0 ... This has the advantage th

Re: 4 hundred quadrillonth?

2009-05-22 Thread Mark Dickinson
On May 22, 3:28 pm, Steven D'Aprano wrote: > On Thu, 21 May 2009 18:30:17 -0700, Gary Herron wrote: > >> In py3k Eric Smith and Mark Dickinson have implemented Gay's floating > >> point algorithm for Python so that the shortest repr that will round > >&g

Re: 4 hundred quadrillonth?

2009-05-27 Thread Mark Dickinson
Luis Zarrabeitia wrote: > On Thursday 21 May 2009 08:50:48 pm R. David Murray wrote: > >> In py3k Eric Smith and Mark Dickinson have implemented Gay's floating >> point algorithm for Python so that the shortest repr that will round >> trip correctly is what is us

Re: Generating all combinations

2009-05-31 Thread Mark Dickinson
On May 31, 9:23 pm, Johannes Bauer wrote: > I'm trying to write a function in Python which does the following: For a > number of arguments which are all lists, return a list (or generator) > which yields all tuples of combination. E.g: > > foofunction() > # returns [ ] Are you sure that's what yo

Re: Mathematics in Python are not correct

2008-05-11 Thread Mark Dickinson
On May 11, 9:36 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > Do you have in mind any situations in which it is advantageous to have 0**0 > undefined? (Playing devil's advocate here.) If you regard x**y as exp(y*log(x)) then it's not at all clear that 0.**0. should be considered well-defined. And

Re: Mathematics in Python are not correct

2008-05-12 Thread Mark Dickinson
On May 12, 2:09 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > Then it seems equally dubious that 0.**y, y>0, should be well-defined. > It seems to me that lim as x goes to 0. exp(y*log(x)) is equally well > defined whether y is 0 or not, even though there is a discontinuity in the > limit. Well,

Re: Mathematics in Python are not correct

2008-05-12 Thread Mark Dickinson
On May 12, 11:15 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > But exp(y*log(x)) -> 1 as (x, y) -> (0, 0) along any analytic curve > which is not the x=0 axis (I think at least - it seems easy to prove > that given f and g analytic over R, f(x)*ln g(x) -> 0 as x -> 0 if > f(0)=g(0)=0 and g(x)>

Bug in floating-point addition: is anyone else seeing this?

2008-05-21 Thread Mark Dickinson
On SuSE 10.2/Xeon there seems to be a rounding bug for floating-point addition: [EMAIL PROTECTED]:~> python Python 2.5 (r25:51908, May 25 2007, 16:14:04) [GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = 1e16-2.

Re: Bug in floating-point addition: is anyone else seeing this?

2008-05-21 Thread Mark Dickinson
On May 21, 3:22 pm, Marc Christiansen <[EMAIL PROTECTED]> wrote: > On my system, it works: > >  Python 2.5.2 (r252:60911, May 21 2008, 18:49:26) >  [GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)] on linux2 >  Type "help", "copyright", "credits" or "license" for more information. >  >>> a = 1e16 - 2.; a >  99

Re: Bug in floating-point addition: is anyone else seeing this?

2008-05-22 Thread Mark Dickinson
On May 22, 5:09 am, Ross Ridge <[EMAIL PROTECTED]> wrote: > Henrique Dante de Almeida  <[EMAIL PROTECTED]> wrote: > > > Finally (and the answer is obvious). 387 breaks the standards and > >doesn't use IEEE double precision when requested to do so. > > Actually, the 80387 and the '87 FPU in all othe

<    1   2   3   4   5   >