Re: Extracting bit fields from an IEEE-784 float

2012-07-30 Thread Mark Dickinson
On Monday, July 30, 2012 1:44:04 AM UTC+1, Steven D'Aprano wrote: > 1) Are there any known implementations or platforms where Python floats > are not C doubles? If so, what are they? Well, IronPython is presumably using .NET Doubles, while Jython will be using Java Doubles---in either case, that

Re: Extracting bit fields from an IEEE-784 float

2012-07-30 Thread Mark Dickinson
On Monday, July 30, 2012 3:16:05 PM UTC+1, Grant Edwards wrote: > The last ones I worked on that where the FP format wasn't IEEE were > > the DEC VAX and TI's line if 32-bit floating-point DSPs. I don't > > think Python runs on the latter, but it might on the former. For current hardware, there

Re: Float to String

2012-10-31 Thread Mark Dickinson
3ds.com> writes: > When formatting a float using the exponential format, the rounding is > different in Python-2.6 and Python-2.7. See example below. Is this > intentional? Yes, in a sense. Python <= 2.6 uses the OS-provided functionality (e.g., the C library's strtod, dtoa and sprintf functi

Re: surprising result all (generator) (bug??)

2012-01-31 Thread Mark Dickinson
On Jan 31, 6:40 am, Neal Becker wrote: > I was just bitten by this unexpected behavior: > > In [24]: all ([i > 0 for i in xrange (10)]) > Out[24]: False > > In [25]: all (i > 0 for i in xrange (10)) > Out[25]: True What does: >>> import numpy >>> all is numpy.all give you? -- Mark -- http://m

Re: surprising result all (generator) (bug??)

2012-01-31 Thread Mark Dickinson
On Jan 31, 7:24 am, Neal Becker wrote: > In [31]: all is numpy.all > Out[31]: True > > Excellent detective work, Mark!  But it still is unexpected, at least to me. Agreed that it's a bit surprising. It's a consequence of NumPy's general mechanisms for converting arbitrary inputs to arrays: >>>

Re: Numeric root-finding in Python

2012-02-12 Thread Mark Dickinson
On Feb 12, 6:41 am, Steven D'Aprano wrote: >             err = -a/b  # Estimate of the error in the current w. >             if abs(err) <= 1e-16: >                 break If the result you're expecting is around -1.005, this exit condition is rather optimistic: the difference between the two Py

Re: Fun and games with lambda

2011-06-17 Thread Mark Dickinson
On Jun 17, 5:10 pm, Steven D'Aprano wrote: > > print((lambda f:((lambda p:p[0]+'.'+p[1:])(str((lambda Q:2*Q[0]*Q[0]//Q > [3])((lambda F:(lambda S:f(lambda T,_:((T[0]+T[1])//2,S((T[0]*T[1])// > F),2*T[2],(T[3]-(T[2]*(((T[0]+T[1])//2)**2-(S((T[0]*T[1])//F))**2))//F)), > [0]*13,(F,(F*F)//S(2*F),2,F//

Re: Large number multiplication

2011-07-08 Thread Mark Dickinson
On Jul 7, 9:30 am, Ulrich Eckhardt wrote: > That said, I'm sure that the developers would accept a patch that switches > to a different algorithm if the numbers get large enough. I believe it > already doesn't use Karatsuba for small numbers that fit into registers, > too. I'm far from sure that

Re: Representation of floats (-> Mark Dickinson?)

2011-09-07 Thread Mark Dickinson
On Sep 7, 4:58 am, casevh wrote: > IIRC, Python > 3.2 changed (for floats) __str__ to call __repr__. Yes, exactly: str and repr of a float are identical in Python 3.2 + I'm also puzzled by the 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] [...] >>> 1.1 * 1.1 1.21 in jmf's

Re: builtin max() and weak ordering

2011-03-03 Thread Mark Dickinson
On Mar 3, 10:38 am, Stephen Evans wrote: > The CPython builtins min() and max() both return the first satisfactory > object found. This behaviour is undocumented. Examining the source in > bltinmodule.c shows that min() and max() both result in a call to min_max() > with Py_LT and Py_GT passed

Re: Python fails on math

2011-03-09 Thread Mark Dickinson
On Feb 25, 12:52 am, Grant Edwards wrote: > So I think the C standard actually > forces the compiler to convert results to 64-bits at the points where > a store to a temporary variable happens. I'm not sure that this is true. IIRC, C99 + Annex F forces this, but C99 by itself doesn't. > Indeed.

Re: Guido rethinking removal of cmp from sort method

2011-03-26 Thread Mark Dickinson
On Mar 25, 2:00 pm, Stefan Behnel wrote: > Westley Martínez, 25.03.2011 14:39: > > > On Fri, 2011-03-25 at 07:11 +0100, Stefan Behnel wrote: > >> Steven D'Aprano, 25.03.2011 06:46: > >>> On Thu, 24 Mar 2011 18:32:11 -0700, Carl Banks wrote: > > It's probably the least justified builtin other

Re: Some questions on pow and random

2011-03-27 Thread Mark Dickinson
On Mar 27, 11:07 am, joy99 wrote: > (i) By standard definition of Likelihood Estimation, we get if x EURO X, > where X is a countable set of types, p is probability and f is > frequency. > L(f;p)=Ðp(x)f(x) > > My question is python provides two functions, > (a)     pow for power. > (b)     reduce(

Re: Some questions on pow and random

2011-03-27 Thread Mark Dickinson
On Mar 27, 11:07 am, joy99 wrote: > (b) Suppose we have two distributions p(x1) and p(x2), of the Model M, > the E of EM algorithm, without going into much technical details is, > P0(x1,x2), P1(x1,x2) > > Now I am taking random.random() to generate both x1 and x2 and trying > to multiply the

Re: Some questions on pow and random

2011-03-27 Thread Mark Dickinson
On Mar 27, 3:00 pm, joy99 wrote: > (i) Suppose we have 8 which is 2^3 i.e., 3 is the power of 2, which we > are writing in Python as, > variable1=2 > variable2=3 > result=pow(variable1,variable2) > > In my first problem p(x) a list of float/decimals and f(x) is another > such. > Here, > variable1=

Re: Fibonacci series recursion error

2011-05-02 Thread Mark Dickinson
On May 2, 5:24 pm, Steven D'Aprano wrote: > As far as I'm concerned, there are only two definitions of Fibonacci > numbers that have widespread agreement in the mathematical community: > > 0,1,1,2,3 ... (starting from n=0) > 1,1,2,3,5 ... (starting from n=1) > > Any other definition is rather, sh

Re: Recursion or iteration (was Fibonacci series recursion error)

2011-05-13 Thread Mark Dickinson
On May 11, 11:06 pm, Hans Mulder wrote: > On 03/05/2011 09:52, rusi wrote: > > > [If you believe it is, then try writing a log(n) fib iteratively :D ] > > It took me a while, but this one seems to work: > > from collections import namedtuple > > Triple = namedtuple('Triple', 'hi mid lo') > Triple.

Re: Recursion or iteration (was Fibonacci series recursion error)

2011-05-15 Thread Mark Dickinson
On May 15, 4:32 am, rusi wrote: > On May 15, 2:19 am, Ian Kelly wrote: > > Yup, linear.  Assuming you optimize the even case so that it doesn't > > actually call fib(n//2) twice, the call tree can be approximated as a > > balanced binary tree with height log(n).  The total number of nodes in > >

Re: Recursion or iteration (was Fibonacci series recursion error)

2011-05-15 Thread Mark Dickinson
On May 15, 8:20 pm, Mark Dickinson wrote: > On May 15, 4:32 am, rusi wrote: > > > On May 15, 2:19 am, Ian Kelly wrote: > > > Yup, linear.  Assuming you optimize the even case so that it doesn't > > > actually call fib(n//2) twice, the call tree can be appr

Re: for / while else doesn't make sense

2016-05-23 Thread Mark Dickinson
Ben Bacarisse bsb.me.uk> writes: > [1] Not being a Python expert I don't know how you show that actual > value of a float. What is the Pythonic way to do that? I don't know about Pythonic, but here are some options. 1. Convert the float to Decimal, and print the result. This shows the exact

Speed quirk: redundant line gives six-fold speedup

2005-08-25 Thread Mark Dickinson
I have a simple 192-line Python script that begins with the line: dummy0 = 47 The script runs in less than 2.5 seconds. The variable dummy0 is never referenced again, directly or indirectly, by the rest of the script. Here's the surprise: if I remove or comment out this first line, the script t

Re: Speed quirk: redundant line gives six-fold speedup

2005-08-25 Thread Mark Dickinson
In article <[EMAIL PROTECTED]>, Bill Mill <[EMAIL PROTECTED]> wrote: > One of my own: what in the world made you think "maybe I'll add 29 > dummy global variables to speed things up?" You mean this isn't a well-known optimization technique? :) I was refactoring the code, and after making a part

Re: Speed quirk: redundant line gives six-fold speedup

2005-08-25 Thread Mark Dickinson
In article <[EMAIL PROTECTED]>, Stelios Xanthakis <[EMAIL PROTECTED]> wrote: > In the sudoku solver, there is a min (number, object) which is > probably what's affected by the extistance of the dummy variable. > Now, in sudoku puzzles some times the algorithm has to suppose > that in a box the r

Re: Speed quirk: redundant line gives six-fold speedup

2005-08-25 Thread Mark Dickinson
In article <[EMAIL PROTECTED]>, Bill Mill <[EMAIL PROTECTED]> wrote: > I'm also pretty sure I've caught a bug in his code, though I'm not > sure how it works exactly. I replaced the 'min' built-in with my own > min, and he's going to get nondeterministic results from this line: > >mm =

Re: 'complex' function with string argument.

2014-03-17 Thread Mark Dickinson
Jayanth Koushik gmail.com> writes: > "Note: When converting from a string, the string must not contain whitespace > around the central + or - operator. For example, complex('1+2j') is fine, but > complex('1 + 2j') raises ValueError." > > Why is this so? See http://bugs.python.org/issue9574 for

Re: Bug in Decimal??

2014-05-04 Thread Mark Dickinson
On Tue, 29 Apr 2014 19:37:17 -0700, pleasedontspam wrote: > Hello, I believe I found a bug in the Decimal library. The natural logarithm > results seem to be off in a certain range, as compared with Wolfram Alpha. I had a quick look: this isn't a bug - it's just the result of propagation of the e

Re: Bug in Decimal??

2014-05-19 Thread Mark Dickinson
isp.com> writes: > I've tested on all platforms I know of and confirmed it. The wrong digit > occurs in the middle of the number. Propagation error would have a bad digit > near the end, and garbage after that. Here there's a perfect sequence of > numbers, but with one single digit changed in th

Re: GCD in Fractions

2014-09-24 Thread Mark Dickinson
Mark Lawrence yahoo.co.uk> writes: > Somebody got there first http://bugs.python.org/issue22477 I think there's good reason to suspect that Brian Gladman and blindanagram are one and the same. :-) >>> sorted("BrianGladman".lower()) == sorted("blindanagram") True -- https://mail.python.o

Re: recursive algorithm for balls in numbered boxes

2011-09-11 Thread Mark Dickinson
On Sep 11, 1:43 am, "Dr. Phillip M. Feldman" wrote: > I've written a recursive class that creates an iterator to solve a general > formulation of the combinatorics problem known as "balls in numbered boxes" > (also known as "indistinguishable balls in distinguishable boxes").  The > code has been

Re: way to calculate 2**1000 without expanding it?

2011-09-18 Thread Mark Dickinson
On Sep 16, 9:17 pm, Arnaud Delobelle wrote: > Ah go on, let's make a codegolf contest out of it. > My entry: > > >>> sum(map(int,str(2**1000))) You could save another character by replacing "2**1000" with "2<<999" -- Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: help needed on decimal formatting issue

2011-09-19 Thread Mark Dickinson
On Sep 19, 1:42 pm, Robin Becker wrote: > I'm not really very used to the decimal module so I'm asking here if any one > can > help me with a problem in a well known third party web framework > > The code in question is > > def format_number(value, max_digits, decimal_places): >      """ >      F

Re: Operator commutativity

2011-09-21 Thread Mark Dickinson
On Sep 21, 2:07 am, Steven D'Aprano wrote: > After playing around with various combinations of C1, C2, D1 and D2, it > seems to me that the rule is: > > If the right-hand argument is a subclass of the left-hand argument, AND also > defines __radd__ directly rather than inheriting it, then its __ra

Re: random.randint() slow, esp in Python 3

2011-09-24 Thread Mark Dickinson
On Sep 24, 10:38 am, Ian Kelly wrote: > On Sat, Sep 24, 2011 at 12:55 AM, Steven D'Aprano > > > > > > > > > > wrote: > > If you want unbiased, random (or at least pseudo-random) integers chosen > > from an uniform distribution with proper error checking, you should use > > randint or randrange. >

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Mark Dickinson
On Sep 24, 2:53 pm, Steven D'Aprano wrote: > I'm trying to generate a sequence of equally-spaced numbers between a lower > and upper limit. Given arbitrary limits, what is the best way to generate a > list of equally spaced floats with the least rounding error for each point? > > For example, supp

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Mark Dickinson
On Sep 24, 5:46 pm, Steven D'Aprano wrote: > Speed is important, but secondary to correctness. To be honest, I never even > thought of using fractions as an intermediate result -- I was thinking of > generating lists of Fractions. I think I can use this approach. Speed could be improved greatly b

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Mark Dickinson
On Sep 24, 6:01 pm, Steven D'Aprano wrote: > Ah, I knew it was too easy! > > >>> from fractions import Fraction as F > >>> start, stop, n = 1, 3.1, 7 > >>> [float(F(start) + i*(F(stop)-F(start))/n) for i in range(n+1)] > > [1.0, 1.3, 1.6, 1.9001, 2.2, 2.5, 2.8003, 3.1] I b

Re: Implement comparison operators for range objects

2011-10-14 Thread Mark Dickinson
On Oct 12, 8:24 pm, Ian Kelly wrote: > On Wed, Oct 12, 2011 at 11:51 AM, MRAB wrote: > >> Aside: > > >> I'm astonished to see that range objects have a count method! What's the > >> purpose of that? Any value's count will either be 0 or 1, and a more > >> appropriate test would be `value in range

Re: unpack('>f', b'\x00\x01\x00\x00')

2011-12-02 Thread Mark Dickinson
On Dec 1, 10:21 am, Hrvoje Niksic wrote: > Chris Rebert writes: > > C does not have a built-in fixed-point datatype, so the `struct` > > module doesn't handle fixed-point numbers directly. > > The built-in decimal module supports fixed-point arithmetic, but the > struct module doesn't know about

Re: struct calcsize discrepency?

2011-12-05 Thread Mark Dickinson
On Dec 4, 3:17 pm, Chris Angelico wrote: > On Mon, Dec 5, 2011 at 1:51 AM, Dave Angel wrote: > > In C, the padding to the largest alignment occurs at the > > end of a structure as well as between items.  Otherwise, an array of the > > struct would not be safely aligned.  if you have an 8byte item

Re: struct calcsize discrepency?

2011-12-05 Thread Mark Dickinson
On Dec 5, 8:09 am, Chris Angelico wrote: > May be, yes, but since calcsize() is returning 12 when the elements > are put in the other order, it would seem to be not counting such > padding. Indeed. That's arguably a bug in the struct module, and one that people have had to find workarounds for i

python coding contest

2005-12-30 Thread Mark Dickinson
Here's a variant of André's brilliant idea that's 119 characters long, and fully printable: j=''.join;seven_seg=lambda z:j(j(' _ | |_ _|_|' [ord('^r|=Zm.:v\r'[int(a)])%u*2:][:3]for a in z) +"\n"for u in(3,7,8)) Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: Fast powerset function

2007-07-13 Thread Mark Dickinson
If you don't care about the order of the results, you can use a Gray code (http://en.wikipedia.org/wiki/Gray_code): this has the advantage of only adding or removing a single element to get from one subset to the next. def powerset(s): d = dict(zip( (1<>> list(powerset('abc')) [set

Re: Vector classes

2007-04-22 Thread Mark Dickinson
On Apr 22, 8:33 am, Mizipzor <[EMAIL PROTECTED]> wrote: > With 1, I can typ vec.x and vec.y, very nice. With 2, I need to do > vec.vals[0] and vec.vals[1], which makes my eyes bleed. If you add a __getitem__ method to the second vector class: def __getitem__(self, i): retu

Re: Does shuffle() produce uniform result ?

2007-08-24 Thread Mark Dickinson
On Aug 24, 8:54 am, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > tooru honda <[EMAIL PROTECTED]> writes: > > I have read the source code of the built-in random module, > > random.py. After also reading Wiki article on Knuth Shuffle > > algorithm, I wonder if the shuffle method implemented in random.

Re: Does shuffle() produce uniform result ?

2007-08-24 Thread Mark Dickinson
On Aug 24, 9:30 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote: > x = floor((n/2**53)*7) > > will produce 0, 1, 3 and 5 with probability (2**53//7+1)/2**53, and 2, > 4 and 6 with probability (2**53//7)/2*53. Oops---I lied; I forgot to take into account the rounding implicit

Re: int/long bug in locale?

2007-08-28 Thread Mark Dickinson
On Aug 28, 10:03 am, [EMAIL PROTECTED] wrote: > Is there an int/long related bug lurking in locale? Looks like this has already been reported: See http://bugs.python.org/issue1742669 Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: Biased random?

2007-08-30 Thread Mark Dickinson
On Aug 30, 3:55 pm, Ivan Voras <[EMAIL PROTECTED]> wrote: > I've noticed something interesting in my test: the value 0 appears less > often than other values (which behave as they should). That's because the call to abs() usually collapses two values to one (e.g. -2 and 2 both end up being 2), but

Re: Biased random?

2007-08-30 Thread Mark Dickinson
> One possible fix: do > > x = randint(0, 10) - randint(0, 10) > x = abs(x) - (x<0) > > This collapses -1 and 0 to 0, -2 and 1 to 1, etc. Or a slightly simpler formula that ends up producing the same distribution: x = min(randint(0, 10), randint(0, 10)) Mark -- http://mail.python.org/mail

Re: Why is this loop heavy code so slow in Python? Possible Project Euler spoilers

2007-09-02 Thread Mark Dickinson
On Sep 2, 9:45 am, [EMAIL PROTECTED] wrote: > [snip code] > > Thanks for that. I realise that improving the algorithm will speed > things up. I wanted to know why my less than perfect algorithm was so > much slower in python than exactly the same algorithm in C. Even when > turning off gcc's optimi

Re: Why is this loop heavy code so slow in Python? Possible Project Euler spoilers

2007-09-02 Thread Mark Dickinson
On Sep 2, 12:55 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > Mark Dickinson <[EMAIL PROTECTED]> wrote: > > Well, for one thing, you're creating half a million xrange objects in > > the course of the search. All the C code has > > to do is increment a few integers

Re: Why is this loop heavy code so slow in Python? Possible Project Euler spoilers

2007-09-02 Thread Mark Dickinson
On Sep 2, 7:51 am, [EMAIL PROTECTED] wrote: > The resulting executable takes 0.24 seconds to run. I'm not expecting > a scripting language to run faster than native code, but I was > surprised at how much slower it was in this case. Any ideas as to what > is causing python so much trouble in the ab

Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC, in case it's relevant.) >>> x, y = 0.0, -0.0 >>> x, y (0.0, 0.0) >>> x, y = -0.0, 0.0 >>> x, y (-0.0, -0.0) I would have expected y to be -0.0 in the first case, and 0.0 in the second. Should the above be considered a bug, or i

Re: Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
On Mar 11, 12:13 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Dan Bishop" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > | On Mar 11, 9:31 am, "Mark Dickinson" <[EMAIL PROTECTED]> wrote: > | > I get the follow

Re: Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
On Mar 11, 1:21 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > Tim Peters wrote inhttp://blog.gmane.org/gmane.comp.python.devel/day=20050409: > > > All Python behavior in the presence of a NaN, infinity, or signed zero > > is a platform-dependent accident. This is because C89 has no such > > concep

Re: Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
On Mar 11, 1:26 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > [Long analysis of probable cause of the problem] Thank you for this. I was suspecting something along these lines, but I don't yet know my way around the source well enough to figure out where the problem was coming from. > In the me

Re: Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
On Mar 11, 2:59 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > [...] > OTOH, Python 2.4 works just fine...: > > Python 2.4.3 (#1, Apr 7 2006, 10:54:33) > [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin > Type "help", "copyright", "credits" or "license" for more information.>>> > 0.0,-0.0

Re: Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
On Mar 11, 5:15 pm, Tim Peters <[EMAIL PROTECTED]> wrote: It's a bug that keeps resurfacing, probably because there's no portable > way to test that it stays fixed :-( (it's not an accident that the OP > relied on atan2 to distinguish +0.0 from -0.0! they act the same in > /almost/ all contexts).

Re: Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
On Mar 11, 9:56 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > That bug isn't formally closed yet, and the discussion's going on, we'll > see. Meanwhile can you try my patch 1678668 just to double check it > does fix everything? (It's agains the current HEAD of Python's svn). It does, and all te

Re: combination function in python

2007-04-15 Thread Mark Dickinson
On Apr 15, 8:37 am, Jussi Piitulainen <[EMAIL PROTECTED]> wrote: > def choose(n, k): >if 0 <= k <= n: >ntok = 1 >ktok = 1 >for t in xrange(1, min(k, n - k) + 1): > ntok *= n > ktok *= t > n -= 1 >return ntok // ktok >else: >

Re: combination function in python

2007-04-15 Thread Mark Dickinson
On Apr 15, 3:33 pm, [EMAIL PROTECTED] wrote: > With few tests, it seems this is faster than the version by Jussi only > with quite big n,k. > True---and for large n and k it's difficult to imagine any real-world applications that wouldn't be better served by using the lngamma function instead. Th

Re: Sets in Python

2007-09-19 Thread Mark Dickinson
On Sep 19, 7:26 pm, Karthik Gurusamy <[EMAIL PROTECTED]> wrote: > If I did, a = [10, 20] and I did d[a]= 'foo', then a.append(30). > If dict complains key error on d[a] now, I won't be surprised. If I do > d[[10, 20, 30]], I will be surprised if it doesn't find the item. Of > course, in today's beh

Re: Matrix convergence

2007-09-30 Thread Mark Dickinson
On Sep 30, 3:10 pm, Zhengzheng Pan <[EMAIL PROTECTED]> wrote: > I'm trying to check whether a (stochastic/transition) matrix > converges, i.e. a function/method that will return True if the input > matrix sequence shows convergence and False otherwise. The background > is a Markov progress, so the

Re: Conflicting needs for __init__ method

2007-01-15 Thread Mark Dickinson
On Jan 14, 7:49 pm, "Ziga Seilnacht" <[EMAIL PROTECTED]> wrote: > Mark wrote:[a lot of valid, but long concerns about types that return > an object of their own type from some of their methods] > > I think that the best solution is to use an alternative constructor > in your arithmetic methods. Th

Re: Conflicting needs for __init__ method

2007-01-15 Thread Mark Dickinson
On Jan 14, 10:43 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sun, 14 Jan 2007 15:32:35 -0800, dickinsm wrote: > > (You could include the normalization in __init__, but that's wasteful > Is it really? Have you measured it or are you guessing? Is it more or less > wasteful than any other so

Re: Conflicting needs for __init__ method

2007-01-16 Thread Mark Dickinson
On Jan 15, 4:54 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > Suppose you're writing a class "Rational" for rational numbers. The > > __init__ function of such a class has two quite different roles to > > play. > That should be your first clue to question whether you're

Re: Conflicting needs for __init__ method

2007-01-16 Thread Mark Dickinson
On Jan 16, 10:25 am, "Mark Dickinson" <[EMAIL PROTECTED]> wrote: > that is, I was working from the following two assumptions: > > (1) *Every* time a Rational is created, __init__ must eventually be > called, and > (2) The user of the class expects to call Rational(

cmath, __float__ and __complex__

2007-02-15 Thread Mark Dickinson
I was a little surprised by the following behaviour: Python 2.5 (r25, Oct 30 2006, 20:50:32) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from cmath import sqrt >>> class NumericType1(object): ... def __float

Re: mpmath puzzle

2007-11-14 Thread Mark Dickinson
On Nov 14, 2:45 pm, "Fredrik Johansson" <[EMAIL PROTECTED]> wrote: > Unlike mpmath, the decimal module doesn't support non-integer powers > (except for square roots), and nor does gmpy (though you can do them > indirectly as mensanator showed earlier in the thread). And numpy / > scipy don't suppo

Re: Next float?

2007-11-22 Thread Mark Dickinson
On Nov 22, 5:41 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote: > On Nov 21, 11:48 pm, "Mark T" <[EMAIL PROTECTED]> wrote: > > > > > Here's some functions to get the binary representation of a float. Then > > just manipulate the bits (an exercise f

Re: Next float?

2007-11-22 Thread Mark Dickinson
On Nov 21, 11:48 pm, "Mark T" <[EMAIL PROTECTED]> wrote: > Here's some functions to get the binary representation of a float. Then > just manipulate the bits (an exercise for the reader): > > import struct > > def f2b(f): > return struct.unpack('I',struct.pack('f',f))[0] > > def b2f(b): >

Re: Compiling fails on Mac OS X 10.5

2008-01-12 Thread Mark Dickinson
On Jan 12, 9:41 am, mc <[EMAIL PROTECTED]> wrote: > Hi! > I'm trying to compile on my Macbook with OS X 10.5. I have all updates > and Xcode 3.0 installed. > > I checked python out with: svn > checkouthttp://svn.python.org/projects/python/branches/py3k > After that I did "./configure" in the  crea

Re: Compiling fails on Mac OS X 10.5

2008-01-12 Thread Mark Dickinson
On Jan 12, 12:05 pm, mc <[EMAIL PROTECTED]> wrote: > Alright! > ./configure output is here:http://rafb.net/p/NqSmqc25.html > and make output here:http://rafb.net/p/kzeb2e29.html Hmm. Doesn't seem to be anything unusual here. I was expecting to see some more informative error message somewhere. D

Re: When is min(a, b) != min(b, a)?

2008-01-21 Thread Mark Dickinson
On Jan 21, 9:55 am, Jason <[EMAIL PROTECTED]> wrote: > display.  On windows, "float('nan')" will cause an exception, as there > are no valid string representations of NAN that can be converted to > the special floating point value.  Also, if you manage to create a nan > under Windows, it displays a

Re: When is min(a, b) != min(b, a)?

2008-01-24 Thread Mark Dickinson
On Jan 24, 7:09 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > I'm having a lot of trouble finding the canonical IEEE-754 standard, so > I'm forced to judge by implementations and third party accounts. For > example, this is what IBM says: There's a recent draft of IEEE 754r (

Re: When is min(a, b) != min(b, a)?

2008-01-28 Thread Mark Dickinson
On Jan 28, 6:50 am, Antoon Pardon <[EMAIL PROTECTED]> wrote: > My personal preference would be that python would allow people the > choice, with the default being that any operation that resulted > in a non numeric result would throw an exception. > > People who somehow made it clear they know how

Re: When is min(a, b) != min(b, a)?

2008-01-28 Thread Mark Dickinson
On Jan 28, 6:50 am, Antoon Pardon <[EMAIL PROTECTED]> wrote: > People who somehow made it clear they know how to work with inf, and > NaN results, would get silent NaN where no exceptions would be thrown. One other thing: there's an excellent starting point for considering how things should work,

Re: extending Python - passing nested lists

2008-01-28 Thread Mark Dickinson
On Jan 28, 10:10 am, Christian Meesters <[EMAIL PROTECTED]> wrote: > Hi, > > I would like to write a C-extension function for an application of mine. For > this I need to pass a nested list (like: [[a, b, c], [d, e, f], ...], where > all letters are floats) to the C-function. Now, with the code I h

Re: Turn off ZeroDivisionError?

2008-02-10 Thread Mark Dickinson
On Feb 9, 5:03 pm, Neal Becker <[EMAIL PROTECTED]> wrote: > If I use C code to turn off the hardware signal, will that stop python from > detecting the exception, or is python checking for 0 denominator on it's > own (hope not, that would waste cycles). Yes, Python does do an explicit check for a

Re: Turn off ZeroDivisionError?

2008-02-10 Thread Mark Dickinson
On Feb 10, 3:10 pm, [EMAIL PROTECTED] wrote: > What Python run on a CPU that doesn't handle the nan correctly? How about platforms that don't even have nans? I don't think either IBM's hexadecimal floating-point format, or the VAX floating-point formats support NaNs. Python doesn't assume IEEE 7

Re: Turn off ZeroDivisionError?

2008-02-10 Thread Mark Dickinson
On Feb 10, 3:29 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > platform does".  Except it doesn't in cases like this. All my > platforms do exactly what I want for division by zero: they > generate a properly signed INF.  Python chooses to override > that (IMO correct) platform behavior with someth

Re: Turn off ZeroDivisionError?

2008-02-10 Thread Mark Dickinson
On Feb 10, 4:56 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > Exactly.  Espeically when Python supposedly leaves floating > point ops up to the platform. There's a thread at http://mail.python.org/pipermail/python-list/2005-July/329849.html that's quite relevant to this discussion. See especial

Re: Turn off ZeroDivisionError?

2008-02-10 Thread Mark Dickinson
On Feb 10, 5:50 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > Most people would not want this behaviour either:: > >     >>> 0.1 >     0.10001 Sure. And if it weren't for backwards-compatibility and speed issues one could reasonably propose making Decimal the default floating-point type

Re: Turn off ZeroDivisionError?

2008-02-10 Thread Mark Dickinson
On Feb 10, 7:08 pm, Carl Banks <[EMAIL PROTECTED]> wrote: > I understand your pain, but Python, like any good general-purpose > language, is a compromise.  For the vast majority of programming, > division by zero is a mistake and not merely a degenerate case, so > Python decided to treat it like on

Re: Turn off ZeroDivisionError?

2008-02-10 Thread Mark Dickinson
On Feb 10, 7:07 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2008-02-10, Christian Heimes <[EMAIL PROTECTED]> wrote: > from somemodule import ieee754 > with ieee754: > > ...    r = a/0 > > ...    print r > > inf > > That would be great. Seriously, in some of my crazier moments I've

Re: Regular Expression for Prime Numbers (or How I came to fail at them, and love the bomb)

2008-02-13 Thread Mark Dickinson
On Feb 13, 5:14 pm, [EMAIL PROTECTED] wrote: > Isn't the finite state machine "regular expression 'object'" really > large? There's no finite state machine involved here, since this isn't a regular expression in the strictest sense of the term---it doesn't translate to a finite state machine, sinc

Re: Turn off ZeroDivisionError?

2008-02-15 Thread Mark Dickinson
On Feb 15, 2:35 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > There are an uncountable number of infinities, all different. If you're talking about infinite cardinals or ordinals in set theory, then yes. But that hardly seems relevant to using floating-point as a model for the doubly extended rea

Re: Turn off ZeroDivisionError?

2008-02-15 Thread Mark Dickinson
On Feb 14, 11:09 pm, John Nagle <[EMAIL PROTECTED]> wrote: > You also need to think about how conditionals interact with > quiet NANs. Properly, comparisons like ">" have three possibilities: True. There was a recent change to Decimal to make comparisons (other than !=, ==) with NaNs do the

Re: Turn off ZeroDivisionError?

2008-02-15 Thread Mark Dickinson
On Feb 15, 1:38 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2008-02-15, Mark Dickinson <[EMAIL PROTECTED]> wrote: > > >> If you're doing such serious number-crunching that you really > >> want to handle NANs, you're probably not writing in Python

Re: Floating point bug?

2008-02-15 Thread Mark Dickinson
On Feb 15, 3:30 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > The point is that all numbering systems with a base + precision will > have (rational) values they can't exactly represent. Q\R is of course > out of the question by definition This 'Decimal is exact' myth has been appearing o

Re: Turn off ZeroDivisionError?

2008-02-15 Thread Mark Dickinson
On Feb 15, 5:27 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > True enough, but aren't they of indeterminate magnitude? Since infinity > == infinity + delta for any delta, comparison for equality seems a > little specious. The equality is okay; it's when you start trying to apply arithmetic laws l

Re: Turn off ZeroDivisionError?

2008-02-15 Thread Mark Dickinson
On Feb 15, 7:59 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Fri, 15 Feb 2008 14:35:34 -0500, Steve Holden wrote: > >> I don't understand: why would +INF not be equal to itself? Having INF > >> == INF be True seems like something that makes sense both > >> mathematically

Re: How about adding rational fraction to Python?

2008-02-16 Thread Mark Dickinson
On Feb 16, 1:35 pm, Lie <[EMAIL PROTECTED]> wrote: > Would all these problems with floating points be a rational reason to > add rational numbers support in Python or Py3k? (pun not intended) It's already in the trunk! Python will have a rational type (called Fraction) in Python 2.6 and Python 3.

Re: How about adding rational fraction to Python?

2008-02-16 Thread Mark Dickinson
On Feb 16, 1:35 pm, Lie <[EMAIL PROTECTED]> wrote: > Would all these problems with floating points be a rational reason to > add rational numbers support in Python or Py3k? (pun not intended) Forgot to give the link: http://docs.python.org/dev/library/fractions.html Mark -- http://mail.python.o

Re: Turn off ZeroDivisionError?

2008-02-16 Thread Mark Dickinson
On Feb 16, 7:08 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Fri, 15 Feb 2008 17:31:51 -0800, Mark Dickinson wrote: > > Not sure that alephs have anything to do with it.  And unless I'm > > missing something, minus aleph(0) is nonsense. (How

Re: Turn off ZeroDivisionError?

2008-02-16 Thread Mark Dickinson
On Feb 16, 7:30 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote: > The real line, considered as a topological space, has limit points. > Two of them. Ignore that. It was nonsense. A better statement: the completion (in the sense of lattices) of the real numbers is (isomorphic to

Re: Turn off ZeroDivisionError?

2008-02-16 Thread Mark Dickinson
On Feb 16, 9:39 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Sat, 16 Feb 2008 17:47:39 -0800, Mark Dickinson wrote: > > I've no clue where your (Steven's) idea that 'all ordinals are surreal > > numbers' came from.  They'

Re: How about adding rational fraction to Python?

2008-02-24 Thread Mark Dickinson
On Feb 24, 1:09 pm, Lie <[EMAIL PROTECTED]> wrote: > And this limit is much lower than n!. I think it's sum(primes(n)), but > I've got no proof for this one yet. It's the least common multiple of the integers 1 through n, or equivalently the product over all primes p <= n of the highest power of p

Re: PyEuler

2008-02-25 Thread Mark Dickinson
On Feb 25, 11:25 am, [EMAIL PROTECTED] wrote: > This is the first time I write something that looks like a little > rant :-) Surely I'll be wrong in many points, but I presume this isn't > going to damage people, so... Agreed on all points. :-) This looks a lot like someone trying to write Haskel

Re: PyEuler

2008-02-25 Thread Mark Dickinson
On Feb 25, 4:24 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > def genfib(a=0, b=1): >     for a, b in iter(lambda:(b, a+b), None): >         yield a > > ;-) > > Ahem.  I admit that somehow, I am proud of this. You're one sick puppy dog. :-) (P.S. Your mother was a hamster, and your father s

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

  1   2   3   4   5   >