P: n/a

Quick question:
I have python code that does a lot of floating point arithmetic. How
do I make it do the arithmetic in 64 bit? (I have a 64 bit CPU.) If
I'll install a 64bit operating system, will that do the trick?  
Share this Question
P: n/a
 ra********@gmail.com wrote:
Quick question:
I have python code that does a lot of floating point arithmetic. How
do I make it do the arithmetic in 64 bit? (I have a 64 bit CPU.) If
I'll install a 64bit operating system, will that do the trick?
The Python float type uses a C double internally which is 64 bit even on 32
bit CPUs.
Peter  
P: n/a

On Jun 15, 2:48*pm, Peter Otten <__pete...@web.dewrote:
ram.rac...@gmail.com wrote:
Quick question:
I have python code that does a lot of floating point arithmetic. How
do I make it do the arithmetic in 64 bit? (I have a 64 bit CPU.) If
I'll install a 64bit operating system, will that do the trick?
The Python float type uses a C double internally which is 64 bit even on 32
bit CPUs.
Peter
Does it mean that even now it does arithmetic in 64 bit?
I'm not getting enough precision. Is there any way to increase it?
Ram.  
P: n/a
 ra********@gmail.com wrote:
On Jun 15, 2:48Â*pm, Peter Otten <__pete...@web.dewrote:
>ram.rac...@gmail.com wrote:
Quick question:
I have python code that does a lot of floating point arithmetic. How
do I make it do the arithmetic in 64 bit? (I have a 64 bit CPU.) If
I'll install a 64bit operating system, will that do the trick?
The Python float type uses a C double internally which is 64 bit even on 32 bit CPUs.
Peter
Does it mean that even now it does arithmetic in 64 bit?
Yes. See http://en.wikipedia.org/wiki/IEEE_fl...ecision_64_bit
for details.
I'm not getting enough precision. Is there any way to increase it?
http://gmpy.sourceforge.net/
If by "not enough precision" you mean you are bothered by
>>.1
0.10000000000000001
have a look at the decimal module, see http://docs.python.org/lib/moduledecimal.html
Peter  
P: n/a
 ra********@gmail.com wrote:
Does it mean that even now it does arithmetic in 64 bit?
I'm not getting enough precision. Is there any way to increase it?
Buy a good book about numerics or take a course. ;)
Seriously, computers and IEEE 754 floating point numbers have a lot of
pit falls. If you chose the wrong algorithm you *will* get wrong
results. With floats a*b*c and a*c*b can give you a different result.
The decimal module is not an option if you need speed.  
P: n/a

On Jun 15, 5:05*pm, Christian Heimes <li...@cheimes.dewrote:
ram.rac...@gmail.com wrote:
Does it mean that even now it does arithmetic in 64 bit?
I'm not getting enough precision. Is there any way to increase it?
Buy a good book about numerics or take a course. ;)
Seriously, computers and IEEE 754 floating point numbers have a lot of
pit falls. If you chose the wrong algorithm you *will* get wrong
results. With floats a*b*c and a*c*b can give you a different result.
The decimal module is not an option if you need speed.
I do need speed. Is there an option?  
P: n/a

I do need speed. Is there an option?
Mind telling us what you *actually* want to achieve? (What do you want to
calculate?)
Christian  
P: n/a

On Jun 15, 6:58*pm, Christian Meesters <meest...@unimainz.dewrote:
I do need speed. Is there an option?
Mind telling us what you *actually* want to achieve? (What do you want to
calculate?)
Christian
Physical simulations of objects with nearlightspeed velocity.  
P: n/a
 ra********@gmail.com wrote:
On Jun 15, 6:58Â*pm, Christian Meesters <meest...@unimainz.dewrote:
I do need speed. Is there an option?
Mind telling us what you *actually* want to achieve? (What do you want to calculate?)
Christian
Physical simulations of objects with nearlightspeed velocity.
How did you determine that standard python floats are not good enough?
Everything beyond that is unlikely to be supported by the hardware and will
therefore introduce a speed penalty.
Did you try gmpy?
Peter  
P: n/a

Peter Otten wrote:
>
How did you determine that standard python floats are not good enough?
Everything beyond that is unlikely to be supported by the hardware and
will therefore introduce a speed penalty.
Did you try gmpy?
I would like to add: If Python's precision (or that of additional modules)
won't do it for you, look around what other people in the physics community
are using.
Christian  
P: n/a

On Jun 15, 7:43*pm, Peter Otten <__pete...@web.dewrote:
ram.rac...@gmail.com wrote:
On Jun 15, 6:58*pm, Christian Meesters <meest...@unimainz.dewrote:
I do need speed. Is there an option?
Mind telling us what you *actually* want to achieve? (What do you want to
calculate?)
Christian
Physical simulations of objects with nearlightspeed velocity.
How did you determine that standard python floats are not good enough?
I have a physical system set up in which a body is supposed to
accelerate and to get very close to lightspeed, while never really
attaining it. After approx. 680 seconds, Python gets stuck and tells
me the object has passed lightspeed. I put the same equations in
Mathematica, again I get the same mistake around 680 seconds. So I
think, I have a problem with my model! Then I pump up the
WorkingPrecision in Mathematica to about 10. I run the same equations
again, and it works! At least for the first 10,000 seconds, the object
does not pass lightspeed.
I concluded that I need Python to work at a higher precision.
Everything beyond that is unlikely to be supported by the hardware and will
therefore introduce a speed penalty.
I have thought of that as well. However I have no choice. I must do
these calculations. If you know of any way that is supported by the
hardware, it will be terrific, but for now the slower things will have
to do.
Did you try gmpy?
Not yet: I was kind of set back when I saw their homepage was last
updated 2002. But I'll give it a try. You think it's the best thing
there is?
Thanks,
Ram.  
P: n/a
 ra********@gmail.com wrote:
I have a physical system set up in which a body is supposed to
accelerate and to get very close to lightspeed, while never really
attaining it. After approx. 680 seconds, Python gets stuck and tells
me the object has passed lightspeed. I put the same equations in
Mathematica, again I get the same mistake around 680 seconds. So I
think, I have a problem with my model! Then I pump up the
WorkingPrecision in Mathematica to about 10. I run the same equations
again, and it works! At least for the first 10,000 seconds, the object
does not pass lightspeed.
That the values are possible doesn't mean that you can trust them.
I concluded that I need Python to work at a higher precision.
How is WorkingPrecision defined? Python floats have about 16 significant
digits in base 10, so at first glance I would guess that you switched to
a /lower/ precision.
But I've come to agree with Christian that it would be good to show your
model to a physics and/or numerical maths expert. Perhaps you can find a
way for the errors to cancel out rather than accumulate.
Peter  
P: n/a

Not yet: I was kind of set back when I saw their homepage was last
updated 2002. But I'll give it a try. You think it's the best thing
there is?
Thanks,
Ram.
gmpy has moved to Google. http://code.google.com/p/gmpy/
gmpy only support the basic floating point operations so it may not be
sufficient for your needs.
A couple alternatives:
1) mpmath is a purePython, arbitrary precision floatingpoint
package. It will be faster than Decimal but slower than gmpy. http://code.google.com/p/mpmath/
2) Sage is an opensource mathematics software package. It uses Python
as it glue/scripting language. It includes support for MPFR, a
multipleprecision floating point library based on GMP. www.sagemath.org
casevh  
P: n/a

On Jun 15, 12:10*pm, "ram.rac...@gmail.com" <ram.rac...@gmail.com>
wrote:
On Jun 15, 7:43*pm, Peter Otten <__pete...@web.dewrote:
ram.rac...@gmail.com wrote:
On Jun 15, 6:58*pm, Christian Meesters <meest...@unimainz.dewrote:
I do need speed. Is there an option?
>Mind telling us what you *actually* want to achieve? (What do you want to
>calculate?)
>Christian
Physical simulations of objects with nearlightspeed velocity.
How did you determine that standard python floats are not good enough?
I have a physical system set up in which a body is supposed to
accelerate and to get very close to lightspeed, while never really
attaining it. After approx. 680 seconds, Python gets stuck and tells
me the object has passed lightspeed. I put the same equations in
Mathematica, again I get the same mistake around 680 seconds. So I
think, I have a problem with my model! Then I pump up the
WorkingPrecision in Mathematica to about 10. I run the same equations
again, and it works! At least for the first 10,000 seconds, the object
does not pass lightspeed.
I concluded that I need Python to work at a higher precision.
Everything beyond that is unlikely to be supported by the hardware and will
therefore introduce a speed penalty.
I have thought of that as well. However I have no choice. I must do
these calculations. If you know of any way that is supported by the
hardware, it will be terrific, but for now the slower things will have
to do.
Did you try gmpy?
Not yet: I was kind of set back when I saw their homepage was last
updated 2002.
Try looking here: http://code.google.com/p/gmpy/
The developers have abandoned SourceForge.
But I'll give it a try. You think it's the best thing
there is?
I haven't tried everything, but it's very good.
You might also want to go to the GMP site itself
and get their manual. Likee anything else, your
results will be no better than your algorithms.
>
Thanks,
Ram.
 
P: n/a

<ra********@gmail.comwrote in message
news:12**********************************@2g2000hs n.googlegroups.com...
How did you determine that standard python floats are not good enough?
 I have a physical system set up in which a body is supposed to
 accelerate and to get very close to lightspeed, while never really
attaining it.
Just a thought. You might do better if you can rearrange your equations in
terms of cv instead of v. Letting c=1, you cannot accutrately express
v = .99999999999999999999
in Python, but can easily express
1v = .00000000000000000001.
And so on.
tjr  
P: n/a

On Jun 15, 10:01*pm, "Terry Reedy" <tjre...@udel.eduwrote:
<ram.rac...@gmail.comwrote in message
news:12**********************************@2g2000hs n.googlegroups.com...
How did you determine that standard python floats are not good enough?
 I have a physical system set up in which a body is supposed to
 accelerate and to get very close to lightspeed, while never really
attaining it.
Just a thought. *You might do better if you can rearrange your equationsin
terms of cv instead of v. *Letting c=1, you cannot accutrately express
v = .99999999999999999999
in Python, but can easily express
1v = .00000000000000000001.
And so on.
tjr
Good idea Terry, I'll think about it.  
P: n/a

On Jun 15, 8:52*pm, Peter Otten <__pete...@web.dewrote:
ram.rac...@gmail.com wrote:
I have a physical system set up in which a body is supposed to
accelerate and to get very close to lightspeed, while never really
attaining it. After approx. 680 seconds, Python gets stuck and tells
me the object has passed lightspeed. I put the same equations in
Mathematica, again I get the same mistake around 680 seconds. So I
think, I have a problem with my model! Then I pump up the
WorkingPrecision in Mathematica to about 10. I run the same equations
again, and it works! At least for the first 10,000 seconds, the object
does not pass lightspeed.
That the values are possible doesn't mean that you can trust them.
I do not understand this comment.
I concluded that I need Python to work at a higher precision.
How is WorkingPrecision defined? Python floats have about 16 significant
digits in base 10, so at first glance I would guess that you switched to
a /lower/ precision.
I don't know how WorkingPrecision is defined. However, I think it's
not lower, it's higher.
But I've come to agree with Christian that it would be good to show your
model to a physics and/or numerical maths expert. Perhaps you can find a
way for the errors to cancel out rather than accumulate.
I might try that.  
P: n/a

On Jun 15, 9:31*pm, casevh <cas...@gmail.comwrote:
Not yet: I was kind of set back when I saw their homepage was last
updated 2002. But I'll give it a try. You think it's the best thing
there is?
Thanks,
Ram.
gmpy has moved to Google.
http://code.google.com/p/gmpy/
gmpy only support the basic floating point operations so it may not be
sufficient for your needs.
A couple alternatives:
1) mpmath is a purePython, arbitrary precision floatingpoint
package. It will be faster than Decimal but slower than gmpy.http://code.google.com/p/mpmath/
2) Sage is an opensource mathematics software package. It uses Python
as it glue/scripting language. It includes support for MPFR, a
multipleprecision floating point library based on GMP. *www.sagemath.org
casevh
Thanks a bundle!  
P: n/a

On Jun 15, 9:41*pm, Mensanator <mensana...@aol.comwrote:
On Jun 15, 12:10*pm, "ram.rac...@gmail.com" <ram.rac...@gmail.com>
wrote:
On Jun 15, 7:43*pm, Peter Otten <__pete...@web.dewrote:
ram.rac...@gmail.com wrote:
On Jun 15, 6:58*pm, Christian Meesters <meest...@unimainz.dewrote:
I do need speed. Is there an option?
Mind telling us what you *actually* want to achieve? (What do you want to
calculate?)
Christian
Physical simulations of objects with nearlightspeed velocity.
How did you determine that standard python floats are not good enough?
I have a physical system set up in which a body is supposed to
accelerate and to get very close to lightspeed, while never really
attaining it. After approx. 680 seconds, Python gets stuck and tells
me the object has passed lightspeed. I put the same equations in
Mathematica, again I get the same mistake around 680 seconds. So I
think, I have a problem with my model! Then I pump up the
WorkingPrecision in Mathematica to about 10. I run the same equations
again, and it works! At least for the first 10,000 seconds, the object
does not pass lightspeed.
I concluded that I need Python to work at a higher precision.
Everything beyond that is unlikely to be supported by the hardware andwill
therefore introduce a speed penalty.
I have thought of that as well. However I have no choice. I must do
these calculations. If you know of any way that is supported by the
hardware, it will be terrific, but for now the slower things will have
to do.
Did you try gmpy?
Not yet: I was kind of set back when I saw their homepage was last
updated 2002.
Try looking here:
http://code.google.com/p/gmpy/
The developers have abandoned SourceForge.
But I'll give it a try. You think it's the best thing
there is?
I haven't tried everything, but it's very good.
You might also want to go to the GMP site itself
and get their manual. Likee anything else, your
results will be no better than your algorithms.
Thanks,
Ram.
I'll check it out, thanks.  
P: n/a
 ra********@gmail.com wrote:
I have a physical system set up in which a body is supposed to
accelerate and to get very close to lightspeed, while never really
attaining it. After approx. 680 seconds, Python gets stuck and tells
me the object has passed lightspeed. I put the same equations in
Mathematica, again I get the same mistake around 680 seconds. So I
think, I have a problem with my model! Then I pump up the
WorkingPrecision in Mathematica to about 10. I run the same equations
again, and it works! At least for the first 10,000 seconds, the object
does not pass lightspeed.
I concluded that I need Python to work at a higher precision.
I conclude that your algorithm is numerical wrong. It probably suffers
from a rounding error which increases itself in every iteration.
Increasing the precision doesn't solve your problem. It's only going to
hide the fact that your algorithm doesn't do its job.
Please don't get me wrong. I don't want to imply that you are an idiot
who doesn't know what he is doing. :] Most likely you weren't taught how
to write numerical sound algorithms. Let's all blame your school or
university. *g*
Numerics is a complex area and it took me more than a year to learn the
basics. Don't be embarrassed!  
P: n/a

On Jun 15, 11:30*pm, Christian Heimes <li...@cheimes.dewrote:
ram.rac...@gmail.com wrote:
I have a physical system set up in which a body is supposed to
accelerate and to get very close to lightspeed, while never really
attaining it. After approx. 680 seconds, Python gets stuck and tells
me the object has passed lightspeed. I put the same equations in
Mathematica, again I get the same mistake around 680 seconds. So I
think, I have a problem with my model! Then I pump up the
WorkingPrecision in Mathematica to about 10. I run the same equations
again, and it works! At least for the first 10,000 seconds, the object
does not pass lightspeed.
I concluded that I need Python to work at a higher precision.
I conclude that your algorithm is numerical wrong. It probably suffers
from a rounding error which increases itself in every iteration.
Increasing the precision doesn't solve your problem. It's only going to
hide the fact that your algorithm doesn't do its job.
Please don't get me wrong. I don't want to imply that you are an idiot
who doesn't know what he is doing. :] Most likely you weren't taught how
to write numerical sound algorithms. Let's all blame your school or
university. *g*
Numerics is a complex area and it took me more than a year to learn the
basics. Don't be embarrassed!
I'll try to read some. But I used mpmath to pump up the precision in
my code, and now the problem doesn't happen. So I think it's okay for
now.  
P: n/a

On Jun 16, 12:57*am, "ram.rac...@gmail.com" <ram.rac...@gmail.com>
wrote:
On Jun 15, 11:30*pm, Christian Heimes <li...@cheimes.dewrote:
ram.rac...@gmail.com wrote:
I have a physical system set up in which a body is supposed to
accelerate and to get very close to lightspeed, while never really
attaining it. After approx. 680 seconds, Python gets stuck and tells
me the object has passed lightspeed. I put the same equations in
Mathematica, again I get the same mistake around 680 seconds. So I
think, I have a problem with my model! Then I pump up the
WorkingPrecision in Mathematica to about 10. I run the same equations
again, and it works! At least for the first 10,000 seconds, the object
does not pass lightspeed.
I concluded that I need Python to work at a higher precision.
I conclude that your algorithm is numerical wrong. It probably suffers
from a rounding error which increases itself in every iteration.
Increasing the precision doesn't solve your problem. It's only going to
hide the fact that your algorithm doesn't do its job.
Please don't get me wrong. I don't want to imply that you are an idiot
who doesn't know what he is doing. :] Most likely you weren't taught how
to write numerical sound algorithms. Let's all blame your school or
university. *g*
Numerics is a complex area and it took me more than a year to learn the
basics. Don't be embarrassed!
I'll try to read some. But I used mpmath to pump up the precision in
my code, and now the problem doesn't happen. So I think it's okay for
now.
Thanks to all contributors for your advice.
Ram Rachum.  
P: n/a
 ra********@gmail.com wrote:
On Jun 15, 7:43 pm, Peter Otten <__pete...@web.dewrote:
>ram.rac...@gmail.com wrote:
>>On Jun 15, 6:58 pm, Christian Meesters <meest...@unimainz.dewrote: I do need speed. Is there an option? Mind telling us what you *actually* want to achieve? (What do you want to calculate?) Christian Physical simulations of objects with nearlightspeed velocity.
How did you determine that standard python floats are not good enough?
I have a physical system set up in which a body is supposed to
accelerate and to get very close to lightspeed, while never really
attaining it. After approx. 680 seconds, Python gets stuck and tells
me the object has passed lightspeed. I put the same equations in
Mathematica, again I get the same mistake around 680 seconds. So I
think, I have a problem with my model! Then I pump up the
WorkingPrecision in Mathematica to about 10. I run the same equations
again, and it works! At least for the first 10,000 seconds, the object
does not pass lightspeed.
I concluded that I need Python to work at a higher precision.
>Everything beyond that is unlikely to be supported by the hardware and will therefore introduce a speed penalty.
I have thought of that as well. However I have no choice. I must do
these calculations. If you know of any way that is supported by the
hardware, it will be terrific, but for now the slower things will have
to do.
You need to change your representation. Try redoing the algebra using
(cv) as the independent variable, and calculate that.
Cheers,
Phil Hobbs  
P: n/a

On Jun 17, 3:13*pm, Phil Hobbs
<pcdhSpamMeSensel...@electrooptical.netwrote:
ram.rac...@gmail.com wrote:
On Jun 15, 7:43 pm, Peter Otten <__pete...@web.dewrote:
ram.rac...@gmail.com wrote: On Jun 15, 6:58 pm, Christian Meesters <meest...@unimainz.dewrote: I do need speed. Is there an option? Mind telling us what you *actually* want to achieve? (What do you want to calculate?) Christian Physical simulations of objects with nearlightspeed velocity.
How did you determine that standard python floats are not good enough?
I have a physical system set up in which a body is supposed to
accelerate and to get very close to lightspeed, while never really
attaining it. After approx. 680 seconds, Python gets stuck and tells
me the object has passed lightspeed. I put the same equations in
Mathematica, again I get the same mistake around 680 seconds. So I
think, I have a problem with my model! Then I pump up the
WorkingPrecision in Mathematica to about 10. I run the same equations
again, and it works! At least for the first 10,000 seconds, the object
does not pass lightspeed.
I concluded that I need Python to work at a higher precision.
Everything beyond that is unlikely to be supported by the hardware and will
therefore introduce a speed penalty.
I have thought of that as well. However I have no choice. I must do
these calculations. If you know of any way that is supported by the
hardware, it will be terrific, but for now the slower things will have
to do.
You need to change your representation. *Try redoing the algebra using
(cv) as the independent variable, and calculate that.
Cheers,
Phil Hobbs
That was suggested. Problem is, that sometimes the velocities are near
zero. So this solution, by itself, is not general enough.  
P: n/a

<ra********@gmail.comwrote in message
news:10**********************************@r66g2000 hsg.googlegroups.com...
>That was suggested. Problem is, that sometimes the velocities are near zero. So this solution, by itself, is not general enough.
Maybe working in p, and deltap would be more stable.  
P: n/a
 ra********@gmail.com wrote:
>
That was suggested. Problem is, that sometimes the velocities are near
zero. So this solution, by itself, is not general enough.
Are you sure? I sort of doubt that you're spending zillions of
iterations getting closer and closer to zero. It would be worth
actually doing the error analysis and finding out.
Cheers,
Phil Hobbs  
P: n/a

On Tue, 17 Jun 2008 08:13:40 0400, Phil Hobbs wrote:
ra********@gmail.com wrote:
[snip]
>I have a physical system set up in which a body is supposed to accelerate and to get very close to lightspeed, while never really attaining it. After approx. 680 seconds, Python gets stuck and tells me the object has passed lightspeed. I put the same equations in Mathematica, again I get the same mistake around 680 seconds. So I think, I have a problem with my model! Then I pump up the WorkingPrecision in Mathematica to about 10. I run the same equations again, and it works! At least for the first 10,000 seconds, the object does not pass lightspeed. I concluded that I need Python to work at a higher precision.
[snip]
You need to change your representation. Try redoing the algebra using
(cv) as the independent variable, and calculate that.
Or represent the velocity as c*tanh(b), where b is the independent
variable. If memory serves, this is the representation in which
constant acceleration corresponds to db/dt = constant.

To email me, substitute nowhere>spamcop, invalid>net.  
P: n/a

On Jun 17, 5:04*pm, "Richard Brodie" <R.Bro...@rl.ac.ukwrote:
<ram.rac...@gmail.comwrote in message
news:10**********************************@r66g2000 hsg.googlegroups.com...
That was suggested. Problem is, that sometimes the velocities are near
zero. So this solution, by itself, is not general enough.
Maybe working in p, and deltap would be more stable.
That's a good one. It will, however, involve complicated calculations
for obtaining v from p, so it might be slower than mpmath. I'll
consider it.  
P: n/a

On Jun 18, 7:12*pm, Peter Pearson <ppear...@nowhere.invalidwrote:
On Tue, 17 Jun 2008 08:13:40 0400, Phil Hobbs wrote:
ram.rac...@gmail.com wrote:
[snip]
I have a physical system set up in which a body is supposed to
accelerate and to get very close to lightspeed, while never really
attaining it. After approx. 680 seconds, Python gets stuck and tells
me the object has passed lightspeed. I put the same equations in
Mathematica, again I get the same mistake around 680 seconds. So I
think, I have a problem with my model! Then I pump up the
WorkingPrecision in Mathematica to about 10. I run the same equations
again, and it works! At least for the first 10,000 seconds, the object
does not pass lightspeed.
I concluded that I need Python to work at a higher precision.
[snip]
You need to change your representation. *Try redoing the algebra using
(cv) as the independent variable, and calculate that.
Or represent the velocity as c*tanh(b), where b is the independent
variable. *If memory serves, this is the representation in which
constant acceleration corresponds to db/dt = constant.

To email me, substitute nowhere>spamcop, invalid>net.
See my comment to Brodie.  
P: n/a

On Jun 18, 3:02*am, Phil Hobbs
<pcdhSpamMeSensel...@electrooptical.netwrote:
ram.rac...@gmail.com wrote:
That was suggested. Problem is, that sometimes the velocities are near
zero. So this solution, by itself, is not general enough.
Are you sure? *I sort of doubt that you're spending zillions of
iterations getting closer and closer to zero. * It would be worth
actually doing the error analysis and finding out.
Cheers,
Phil Hobbs
See my comment to Brodie.   This discussion thread is closed Replies have been disabled for this discussion.   Question stats  viewed: 5169
 replies: 29
 date asked: Jun 27 '08
