LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Huge number calculations (https://www.linuxquestions.org/questions/programming-9/huge-number-calculations-4175470690/)

jefro 07-23-2013 09:54 PM

Huge number calculations
 
Has any work been done that improves the java huge number work. I need to work with some really large computations but I also can't have any errors or rounding.

Thanks.

John VV 07-24-2013 12:42 AM

Large data crunching in java ?
LOL

think CUDA

why java ?
i do a lot with multi GIG data sets and would never think of using java
c++, FORTRAN, Perl, or cuda yes but not java

pan64 07-24-2013 01:05 AM

Yes, why java? What about BigDecimal?

jefro 07-24-2013 02:59 PM

I may have led you astray. I really need any method that would work in a modern x86-64 since that is my target device right now.

All I found was a biginteger set of java for this task that had exact results.

I never thought about using cuda or video card to do number calculations. I'll have to study on that since I know nothing about cuda.

There are some web pages that can do huge calculations like 30000 raised to 30000 for example but they fail at some point as the numbers get close to what I am working on. Or example maybe simple like 3 raised to 3 raised to 3.

Thanks for the ideas. I have not worked with python or ruby at all either so it will be an uphill battle.

John VV 07-24-2013 04:06 PM

CUDA is a pain in the bleep , so unless you can program in it ,it might not be a great choice

There is Perl and a mess of perl mods for math and calculations

Quote:

There are some web pages that can do huge calculations like 30000 raised to 30000 for example but they fail at some point as the numbers get close to what I am working on. Or example maybe simple like 3 raised to 3 raised to 3.
that sounds a bit like the 32 bit cut off or the long , double and int values set up in the code

PTrenholme 07-24-2013 04:59 PM

Or you could install the genius package (and the needed libraries). Then use the GEL script to program your computation to whatever degree of precision you want. For example:
Code:

$ printf "FloatPrecision=1000;sum n=1 to 500 do 1/n\n" | genius
6 77421451437497033795232306235083075377047642888468868316076570503457478332206708245946938688923108952784535733...

Note that it is impossible to get an exact, non integer, result for a computation on a digital computer. You can find an interval containing such a result. See the mpfi library package for multiple precision floating point interval computation routines.

reza_zah1991 07-24-2013 07:52 PM

you can do your other work with java & each time you need to calculate the huge Number,,use power of ShellScript from java(connect from java to OS consol),,
and save the huge number in the string,,

jefro 07-24-2013 08:14 PM

Again thanks for the ideas and I appreciate any ideas. This is now simply a hobby sort of quest.

I had considered a purpose designed chip even but the end product would have to be an add on card for the task.

I have been looking at crypto tech on this also and did study up on cuda. It may be possible but as you say, a lot going on for a newbie to program.

"Note that it is impossible to get an exact, non integer, result for a computation on a digital computer"
This is my problem. I can't have any guesses and other built in cheats that have been wrongly added into the entire math portion of x86. It needs to be precise.

It is a true integer but in a very great length. I am only working with whole real numbers. At some point in the calculation, I need to end up with this huge number.

reza_zah1991, thanks for the idea, doing that over a network is what I am trying to avoid actually. Yes, a different system could do this.

ntubski 07-24-2013 10:07 PM

Quote:

Originally Posted by PTrenholme (Post 4996172)
Note that it is impossible to get an exact, non integer, result for a computation on a digital computer.

You can get exact results for a computation involving rational numbers. Obviously, you can't get exact results for irrational numbers, but that's independent of whether or not you are performing the computation on a computer, digital or otherwise.

Unless you are thinking of symbolic manipulation of real numbers? That can also be done on a digital computer.

Quote:

Originally Posted by jefro
It is a true integer but in a very great length. I am only working with whole real numbers.

So what is wrong with BigInteger? Is it too slow? Doesn't implement the functions you need?

PTrenholme 07-25-2013 09:37 PM

Quote:

Originally Posted by ntubski (Post 4996314)
You can get exact results for a computation involving rational numbers. Obviously, you can't get exact results for irrational numbers, but that's independent of whether or not you are performing the computation on a computer, digital or otherwise.

O.K., I was being a little sloppy.:redface: What I was trying to say was that representation of real numbers in IEEE format on a digital computer is almost always inexact. That is, the set of points where the representation is exact has measure zero for most reasonable metrics. In fact, that set, for any finite precision, is (necessarily) finite.

It is also obvious that the set of integers that can be used by any (finite) digital computer is finite.

The size of those sets can be made quite large, but never infinite.

ta0kira 07-26-2013 02:32 PM

Quote:

Originally Posted by ntubski (Post 4996314)
You can get exact results for a computation involving rational numbers. Obviously, you can't get exact results for irrational numbers, but that's independent of whether or not you are performing the computation on a computer, digital or otherwise.

You can get an exact fractional representation of a rational number, but not necessarily the exact decimal notation. A fractional representation is merely a very simple case of algebraically representing a number, just like a floating-point is an exact representation of a particular number broken down into a mantissa and an exponent. Just to be facetious, I can compute 2*pi exactly: it's 2*pi. I just run into problems when I try to expand it into a finite decimal representation. Similarly, I can express pi as an algorithm of finite length.

The nice thing about rational numbers is that they're a commutative ring, and by definition they all have a fractional representation, so arithmetic doesn't cause the representation of the result to be more complicated than the operands. I believe numbers of the form [a+sqrt(b)]/[c+sqrt(d)] (for integers a-d) are also a commutative ring, so you could also perform exact arithmetic on them.

Kevin Barry

ntubski 07-26-2013 05:53 PM

Quote:

Originally Posted by ta0kira (Post 4997451)
You can get an exact fractional representation of a rational number, but not necessarily the exact decimal notation. A fractional representation is merely a very simple case of algebraically representing a number, just like a floating-point is an exact representation of a particular number broken down into a mantissa and an exponent.
...

Hah, the nipicker becomes the nitpickee :) A fair point, though.

I'm mainly concerned with clarifying that this isn't specific to (digital) computers.

Quote:

Originally Posted by PTrenholme
It is also obvious that the set of integers that can be used by any human (or (finite) digital computer) is finite.

Fixed that for you.

jefro 07-29-2013 08:43 PM

Sorry I didn't get back to this.

Biginteger isn't bad and may be all that there is. I was looking for options. The cuda idea is one that I'll pursue maybe. If anyone has done this in python or perl I'd like their opinions.

dugan 07-29-2013 10:18 PM

Python can handle 30000 to the power of 30000 just fine.

Code:

a = 30000 ** 30000
print a


jefro 07-30-2013 02:59 PM

a = 30000 * 30000

Should that be 30000 ** 30000 ?

Or maybe

math.pow(30000, 30000)

I guess I need to learn python and install it and try it.


All times are GMT -5. The time now is 02:19 PM.