[issue36228] Support coercion of complex to float/int

2019-03-08 Thread Fredrik Johansson
Fredrik Johansson added the comment: I can think of two reasons to extend floor() and ceil() to complex numbers, and they lead to different extensions. The first is as a way to map complex numbers to nearby Gaussian integers by defining floor(z) = floor(z.real) + floor(z.imag)*1j, etc

ANN: mpmath 0.17 (Python 3 support and more)

2011-02-01 Thread Fredrik Johansson
/build/index.html or http://mpmath.googlecode.com/svn/tags/0.17/doc/build/index.html Bug reports and other comments are welcome on the issue tracker at http://code.google.com/p/mpmath/issues/list or the mpmath mailing list: http://groups.google.com/group/mpmath Enjoy, Fredrik Johansson -- http

ANN: mpmath 0.15 released

2010-06-07 Thread Fredrik Johansson
list: http://groups.google.com/group/mpmath Enjoy, Fredrik Johansson -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/

ANN: mpmath 0.14 released

2010-02-06 Thread Fredrik Johansson
mailing list: http://groups.google.com/group/mpmath Enjoy, and extra thanks to Juan Arias de Reyna, Vinzent Steinberg, Jorn Baayen and Chris Smith who contributed to this version. Fredrik Johansson -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software

ANN: mpmath 0.13 released

2009-08-14 Thread Fredrik Johansson
resources to support this project, and for providing much encouragement. The new version of mpmath will soon be available in Sage. Enjoy, Fredrik Johansson -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf

ANN: mpmath 0.12 released

2009-06-10 Thread Fredrik Johansson
Hi all, Mpmath version 0.12 is now available from the website: http://code.google.com/p/mpmath/ It can also be downloaded from the Python Package Index: http://pypi.python.org/pypi/mpmath/0.12 Mpmath is a pure-Python library for arbitrary-precision floating-point arithmetic that implements an

[issue2706] datetime: define division timedelta/timedelta

2009-03-10 Thread Fredrik Johansson
Fredrik Johansson fredrik.johans...@gmail.com added the comment: I think datetime division would be a fine application for Fractions. -- message_count: 18.0 - 19.0 nosy: +fredrikj nosy_count: 7.0 - 8.0 ___ Python tracker rep...@bugs.python.org http

[issue5139] Add combinatoric counting functions to the math module.

2009-02-03 Thread Fredrik Johansson
Fredrik Johansson fredrik.johans...@gmail.com added the comment: I understand the connection with itertools, but why not just call a binomial coefficient a binomial coefficient? Probably 90% of all math libraries call this function 'binomial' or 'bincoef' and I suspect that's the name most

ANN: mpmath 0.11 released

2009-01-26 Thread Fredrik Johansson
Hi all, Mpmath version 0.11 is now available from the website: http://code.google.com/p/mpmath/ It can also be downloaded from the Python Package Index: http://pypi.python.org/pypi/mpmath/0.11 Mpmath is a pure-Python library for arbitrary-precision floating-point arithmetic that implements an

Re: math module for Decimals

2009-01-06 Thread Fredrik Johansson
On Dec 28 2008, 4:55 pm, jerry.carl...@gmail.com wrote: - are you usingDecimalfor the base-10-ness or the   extra precisionDecimalprovides?  Or significant zeros?   Or compatibility with existingDecimalcode, or what? Oh boy, now I will finally prove myself illiterate... well, so be it.

Re: math module for Decimals

2009-01-06 Thread Fredrik Johansson
On Jan 6, 8:29 pm, Mark Dickinson dicki...@gmail.com wrote: Note that it's still subject to the same limitations as anything else for trig_function(really huge argument), of course: import mpmath mpmath.cos(mpmath.mpf('1e9')) [... still waiting for a result 30 minutes later ...]

[issue3439] create a numbits() method for int and long types

2008-12-16 Thread Fredrik Johansson
Fredrik Johansson fredrik.johans...@gmail.com added the comment: When did the name change back to numbits? Anyway, I think this reference implementation is better: def numbits(x): x = abs(x) n = 0 while x: n += 1 x //= 2 return n (//= 2 could be changed to = 1

[issue3439] create a numbits() method for int and long types

2008-12-13 Thread Fredrik Johansson
Fredrik Johansson fredrik.johans...@gmail.com added the comment: FYI, Brent Zimmermann call this function nbits(n) in Modern Computer Arithmetic: http://www.loria.fr/~zimmerma/mca/pub226.html I don't really care much about the name though. In the documentation, should same value

[issue3439] create a numbits() method for int and long types

2008-11-11 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: In stdtypes.rst, x.numbits should be listed in the table under Bit-string Operations on Integer Types and not in the table of operations supported by all numeric types. (1) the number of bits should be computed first directly using C

[issue4128] Performance regression in long division in 2.6

2008-10-17 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: I propose to close this as won't fix; I'm not interested in 150ms speed differences when dividing 10 digit numbers. Sure. (I care about differences like this, because they have a tendency to add up. But it's a minor issue

[issue4128] Performance regression in long division in 2.6

2008-10-15 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: The speed difference comes from different compiler options. I figured as much. I'm using the binaries from python.org (see the .txt file; it includes version headers). The question is why the compilation changes for 2.6 slowed down

[issue4128] Performance regression in long division in 2.6

2008-10-15 Thread Fredrik Johansson
New submission from Fredrik Johansson [EMAIL PROTECTED]: On my laptop (Windows XP, 32-bit), long division is about 15% slower in 2.6 compared to 2.5. See the attached .txt for timings. I noticed this when comparing the unit tests for mpmath (http://code.google.com/p/mpmath/) under 2.5 and 2.6

[issue3439] math.frexp and obtaining the bit size of a large integer

2008-10-14 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: Some elaboration (that perhaps could be adapted into the documentation or at least source comments). There are two primary uses for numbits, both of which justify (0).numbits() == 0. The first is that for positive k, n = k.numbits() gives

[issue3439] create a numbits() method for int and long types

2008-10-14 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: Another tack is to notice that numbits is the length of the bit sequence representation of an int (excepting 0) and give ints a .__len__ method ;-). I would not expect that suggestion to fly very far, though. FWIW, I'm one of the people

[issue3439] create a numbits() method for int and long types

2008-10-14 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: One other note: in Fredrik's patch there's commented out code for a numbits *property* (rather than a method). Is there any good reason to make this a property? Aesthetically, I think numbits as a function would make more sense

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

2008-10-06 Thread Fredrik Johansson
On Oct 5, 5:26 pm, [EMAIL PROTECTED] wrote: Hi, My question to the group: Does anyone know of a non-hackish way to determine the required bit position in python? I know that my two ideas can be combined to get something working. But is there a *better* way, that isn't that hackish? No

[issue3944] faster long multiplication

2008-09-26 Thread Fredrik Johansson
Changes by Fredrik Johansson [EMAIL PROTECTED]: -- nosy: +fredrikj ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3944 ___ ___ Python-bugs-list mailing

ANN: mpmath 0.9 released

2008-08-23 Thread Fredrik Johansson
Hi, Mpmath version 0.9 is now available from the website: http://code.google.com/p/mpmath/ It can also be downloaded from the Python Package Index: http://pypi.python.org/pypi/mpmath/0.9 Mpmath is a pure-Python library for arbitrary-precision floating-point arithmetic that implements an

[issue3439] math.frexp and obtaining the bit size of a large integer

2008-08-18 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: Wow, newbie error. Thanks for spotting! In every case I can think of, I've wanted (0).numbits() to be 0. The explanation in the docstring can probably be improved. What other documentation is needed (where

[issue3451] Asymptotically faster divmod and str(long)

2008-08-06 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: Indeed, that seems to be much faster. In the mean time, do you mind if I steal the code? :-) ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3451

[issue3470] Wrong name for getrandbits in docstring and documentation

2008-07-30 Thread Fredrik Johansson
New submission from Fredrik Johansson [EMAIL PROTECTED]: The docstring for random.Random mentions a method getrandombits(). Surely this should be getrandbits()? This ghost method is also mentioned in the Library Reference page for the random module. -- assignee: georg.brandl components

[issue3451] Asymptotically faster divmod and str(long)

2008-07-27 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: Yes, definitely! Though it depends a little bit how much complication is involved. Not that much, I think, the pure Python version being just a few lines of code (plus a few more lines of boilerplate). But I'm not too familiar

[issue3451] Asymptotically faster divmod and str(long)

2008-07-27 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: For your convenience, I have split the division and numeral code off to a standalone .py file which I'm attaching here. I also updated the remainder logic to use the default divmod instead of repeated subtraction, which ensures worst-case

[issue3451] Asymptotically faster divmod and str(long)

2008-07-27 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: And here some timings on my laptop. Both int-str and balanced division become faster somewhere between 1000 and 2000 digits. This is after editing the division benchmark to use random numbers instead of exact powers of ten (interestingly

[issue3451] Asymptotically faster divmod and str(long)

2008-07-26 Thread Fredrik Johansson
New submission from Fredrik Johansson [EMAIL PROTECTED]: A few weeks ago, I blogged about taking advantage of Karatsuba multiplication and Newton's method to divide big integers quickly (some of you may have read it, as it was posted to Daily Python-URL among other places): http://fredrik

[issue3439] math.frexp and obtaining the bit size of a large integer

2008-07-24 Thread Fredrik Johansson
New submission from Fredrik Johansson [EMAIL PROTECTED]: Python 3.0b2 (r30b2:65106, Jul 18 2008, 18:44:17) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import math math.frexp(10**100) (0.5714936956411375, 333) math.frexp(10**1000

[issue3439] math.frexp and obtaining the bit size of a large integer

2008-07-24 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: Raymond, yes, I think that a separate numbits function would better, although exposing this functionality would not prevent also changing the behavior of frexp. As I said, math.log already knows about long integers, so handling long integers

[issue2487] ldexp(x,n) misbehaves when abs(n) is large

2008-05-09 Thread Fredrik Johansson
Fredrik Johansson [EMAIL PROTECTED] added the comment: I'm not qualified to comment on the implementation. The test cases all look right. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2487

[issue2487] ldexp(x,n) misbehaves when abs(n) is large

2008-03-25 Thread Fredrik Johansson
New submission from Fredrik Johansson [EMAIL PROTECTED]: Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. from math import ldexp from sys import maxint ldexp(1.234, maxint//2) Traceback (most

Re: About Rational Number (PEP 239/PEP 240)

2007-12-15 Thread Fredrik Johansson
On Dec 15, 2007 10:05 PM, Lie [EMAIL PROTECTED] wrote: Random ramble past here: Actually, my vision would be not only fractions, but also rooted number (square root, cube root, etc), it could be possible to implement a type where a number consist of a rooted number times a multiplier plus a

Re: Trouble getting loop to break

2007-11-25 Thread Fredrik Johansson
On Nov 25, 2007 9:00 AM, Dick Moores [EMAIL PROTECTED] wrote: Fredrik, I'm afraid I'm just too dumb to see how to use your first suggestion of cached_factorials. Where do I put it and def()? Could you show me, even on-line, what to do? http://py77.python.pastebin.com/f48e4151c You (or

Re: Trouble getting loop to break

2007-11-25 Thread Fredrik Johansson
On Nov 25, 2007 2:47 PM, Dick Moores [EMAIL PROTECTED] wrote: Wow. your f() is ingenious, Frederik. Thanks very much. Any more tricks up your sleeve? You did say a post or so ago, Further improvements are possible. The next improvement would be to find a recurrence formula for the terms

Re: Next float?

2007-11-22 Thread Fredrik Johansson
On Nov 22, 2007 4:04 AM, Steven D'Aprano [EMAIL PROTECTED] wrote: Is there a simple, elegant way in Python to get the next float from a given one? By next float, I mean given a float x, I want the smallest float larger than x. Bonus points if I can go in either direction (i.e. the previous

Re: Trouble getting loop to break

2007-11-20 Thread Fredrik Johansson
On Nov 20, 2007 8:41 AM, Dick Moores [EMAIL PROTECTED] wrote: I'm writing a demo of the infinite series x**0/0! + x**1/1! + x**2/2! + x**3/3! + ... = e**x (x is non-negative) It works OK for many x, but for many the loop doesn't break. Is there a way to get it to break where I want it

Re: Trouble getting loop to break

2007-11-20 Thread Fredrik Johansson
On Nov 20, 2007 10:00 PM, Dick Moores [EMAIL PROTECTED] wrote: And also with the amazing Chudnovsky algorithm for pi. See http://python.pastebin.com/f4410f3dc Nice! I'd like to suggest two improvements for speed. First, the Chudnovsky algorithm uses lots of factorials, and it's rather

Re: Help with sympy, please

2007-11-18 Thread Fredrik Johansson
On Nov 19, 2007 1:05 AM, Dick Moores [EMAIL PROTECTED] wrote: At 03:42 PM 11/18/2007, Dennis Lee Bieber wrote: On Sun, 18 Nov 2007 13:02:01 -0800, Dick Moores [EMAIL PROTECTED] declaimed the following in comp.lang.python: This gets: Traceback (most recent call last): File

Re: Help with sympy, please

2007-11-18 Thread Fredrik Johansson
On Nov 19, 2007 2:03 AM, Dick Moores [EMAIL PROTECTED] wrote: At 04:26 PM 11/18/2007, Fredrik Johansson wrote: On Nov 19, 2007 1:05 AM, Dick Moores [EMAIL PROTECTED] wrote: Hi Dick, I recognize you from python-list, where you had a question about mpmath. Your code still won't work if you

Re: Help with sympy, please

2007-11-18 Thread Fredrik Johansson
On Nov 19, 2007 2:09 AM, Dennis Lee Bieber [EMAIL PROTECTED] wrote: On Sun, 18 Nov 2007 16:05:15 -0800, Dick Moores [EMAIL PROTECTED] declaimed the following in comp.lang.python: TypeError: unsupported operand type(s) for /: 'float' and 'Float' blinkblink What restrictive

Re: Help with sympy, please

2007-11-18 Thread Fredrik Johansson
On Nov 19, 2007 2:23 AM, Dick Moores [EMAIL PROTECTED] wrote: OK, I tried mpmath again, and to my surprise, it went well! === #!/usr/bin/env python #coding=utf-8 from mpmath import * mpf.dps = 50 n = 1 k = 0 prod = mpf(1) while k 10: k += 1

re: mpmath puzzle

2007-11-14 Thread Fredrik Johansson
Dick Moores wrote: For 1234 ** 10.9, why the wrong result from mpmath.power()? #!/usr/bin/env python #coding=utf-8 from mpmath import * mpf.dps = 32 x = mpf(1234) y = mpf(10.9) print power(x,y) print 4.9583278648155041477415234438717e+33 #

Re: mpmath puzzle

2007-11-14 Thread Fredrik Johansson
On Nov 14, 2007 8:21 PM, [EMAIL PROTECTED] wrote: You could also use the Decimal module to keep things accurate. Some people like numpy or scipy for the more complex math problems they do. Unlike mpmath, the decimal module doesn't support non-integer powers (except for square roots), and nor

Going past the float size limits?

2007-10-28 Thread Fredrik Johansson
jimmy.musselwhite at gmail.com wrote: Hello all It would be great if I could make a number that can go beyond current size limitations. Is there any sort of external library that can have infinitely huge numbers? Way way way way beyond say 5x10^350 or whatever it is? I'm hitting that inf

Re: A brief question.

2005-07-02 Thread Fredrik Johansson
On 7/3/05, Tom Anderson [EMAIL PROTECTED] wrote: That's one way. I'd do: root = value ** 0.5 Does that mean we can expect Guido to drop math.sqrt in py3k? :) I'd rather like to see a well implemented math.nthroot. 64**(1/3.0) gives 3.9996, and this error could be avoided.

Re: Modules for inclusion in standard library?

2005-06-27 Thread Fredrik Johansson
it if it was in the standard library. -- Fredrik Johansson -- http://mail.python.org/mailman/listinfo/python-list