Logarithms in Java BigInteger

JK.Lists.questions

Usenet Archive
Joined
Jul 28, 2008
Messages
2
Reaction score
0
Does anyone know a solution for this problem or of any arbitrary precision arithmetic libraries that have this functionality?

Thank You.
 

Lew

Usenet Archive
Joined
Apr 3, 2001
Messages
5,319
Reaction score
0
Does anyone know a solution for this problem or of any arbitrary precision arithmetic libraries that have this functionality?

What is the "problem", exactly?

Your title, not repeated in the body of the message, simply says "Logarithms in Java BigInteger". That is not a problem statement. It is not a statement of functionality.

Would you please be more clear in what you are asking?

What functionality do you want? If it's to calculate logarithms on an integer type, what sensible interpretation of that calculation do you propose? Are you talking about taking a log of one integer with respect to another? Natural logs?

What about the fact that logarithms are inherently real-valued and do not map well to integers? How does that relate to whatever your "problem" is?

Your question raises too many questions to engender any answers.
 

JK.Lists.questions

Usenet Archive
Joined
Jul 28, 2008
Messages
2
Reaction score
0
Stop trolling fool.

The question is clear. Why is logarithm missing from the BigInteger API? By logarithm i mean a function analogous to the one in the Math API. I should be able to pick and choose the base, but if you insist on one, 10 is fine.

Thanks in advance.
 

Mark Space

Usenet Archive
Joined
Jan 30, 2003
Messages
2,020
Reaction score
0
Does anyone know a solution for this problem or of any arbitrary precision arithmetic libraries that have this functionality?

Thank You.

I got to agree with Lew here, I don't see what the problem is.

BigInteger two = new BigInteger( "2" );
double log = Math.log( two.doubleValue );
 

Eric Sosman

Usenet Archive
Joined
Jun 26, 2003
Messages
10,353
Reaction score
0
wrote:
Stop trolling fool.

The question is clear. Why is logarithm missing from the BigInteger API? By logarithm i mean a function analogous to the one in the Math API. I should be able to pick and choose the base, but if you insist on one, 10 is fine.

Thanks in advance.

If this is a sample of your thankfulness, you may not get a whole lot of freely-offered help ...
 

Patricia Shanahan

Usenet Archive
Joined
Jun 24, 2000
Messages
3,338
Reaction score
0
wrote:
Does anyone know a solution for this problem or of any arbitrary precision arithmetic libraries that have this functionality?

Thank You.

How precise does the logarithm need to be?

I don't know a direct way of doing it, but I do have ideas for approximating based on Math.log, but that would only have the precision of double.

Patricia
 

Martin Gregorie

Usenet Archive
Joined
Feb 18, 2006
Messages
1,767
Reaction score
0
The question is clear. Why is logarithm missing from the BigInteger API? By logarithm i mean a function analogous to the one in the Math API. I should be able to pick and choose the base, but if you insist on one, 10 is fine.
There are no exponential or logarithmic methods in Math that either operate on integer parameters or return integer values. Furthermore, the only methods that either operate on integral arguments or return integral values are abs, getExponent, max, min and round.

Maybe, just maybe, there's a clue there about why BigInteger does not and should not have logarithmic methods.
 

Patricia Shanahan

Usenet Archive
Joined
Jun 24, 2000
Messages
3,338
Reaction score
0
Stop trolling fool.

The question is clear. Why is logarithm missing from the BigInteger API? By logarithm i mean a function analogous to the one in the Math API. I should be able to pick and choose the base, but if you insist on one, 10 is fine.

Thanks in advance.

I think the reason is it missing is because it is difficult to say exactly what it should do. Should it return a double? A BigInteger? (In which case you would get very strange results for small numbers), A BigDecimal? If so, to what precision?

It is also harder to implement. The Math methods only have to deal with a finite, known precision and a finite, known range of magnitudes, from Double.MIN_VALUE through Double.MAX_VALUE. With those constraints, there are approximations to logarithm with a bounded number of terms. BigInteger has a far wider range of magnitudes.

Patricia
 

Christian (archive)

Usenet Archive
Joined
Aug 16, 2000
Messages
565
Reaction score
0
Stop trolling fool.

The question is clear. Why is logarithm missing from the BigInteger API? By logarithm i mean a function analogous to the one in the Math API. I should be able to pick and choose the base, but if you insist on one, 10 is fine.

Thanks in advance.

My guess is that its missing because BigInteger class was made for Cryptography ... all methods for this are there. And you don't need to calculate the log in crytography.

Christian
 

Roedy Green

Usenet Archive
Joined
Dec 17, 2000
Messages
18,395
Reaction score
0
The question is clear. Why is logarithm missing from the BigInteger API?

Mathematically because log (n ) is not an integer in general no matter what base you use. What sort of answer would you want -- rounded? a rational number pair? a double?

Logs and integers don't mix well. What are you up to?

Perhaps one thing you could do is find out the length of a number, which is a sort of integer log.
 

Roedy Green

Usenet Archive
Joined
Dec 17, 2000
Messages
18,395
Reaction score
0
Does anyone know a solution for this problem or of any arbitrary precision arithmetic libraries that have this functionality?

What would you use the result for? Perhaps there is some other way to skin the cat without logs.

You might find some sort of homing in algorithm. Perhaps had you asked me 40 years ago when I was taking my numerical analysis course, where we worked on solving differential equations numerically, I could have quoted it to you.
 

Lew (8)

Usenet Archive
Joined
Jul 15, 2008
Messages
178
Reaction score
0
Christian wrote:
My guess is that its missing because BigInteger class was made for Cryptography [sic] ... all methods for this are there.

BigInteger was not made specifically and solely for use in cryptography algorithms, but for the class of algorithms that need arbitrary-precision integers, of which cryptography presents but one application.

Not all the methods needed to do cryptography are present in BigInteger, therefore

And you don't need to calculate the log in crytography.

does not provide a reason for the absence of logarithm calculations there.

What does provide a reason is what Patricia, myself and others have pointed out. The question is ill-specified and the utility negligible, if not negative, to provide such functionality.
 

Patricia Shanahan

Usenet Archive
Joined
Jun 24, 2000
Messages
3,338
Reaction score
0
Roedy Green wrote:
...
Perhaps one thing you could do is find out the length of a number, which is a sort of integer log.

BigInteger's bitLength method computes (ceil(log2(this < 0 ? -this :
this+1))). Whether that is any help depends on the intended use.

Patricia
 

John W Kennedy

Usenet Archive
Joined
May 3, 2008
Messages
162
Reaction score
0
Lew said:
Christian said:
My guess is that its missing because BigInteger class was made for Cryptography [sic] ... all methods for this are there.

BigInteger was not made specifically and solely for use in cryptography algorithms, but for the class of algorithms that need arbitrary-precision integers, of which cryptography presents but one application.

Not all the methods needed to do cryptography are present in BigInteger, therefore
And you don't need to calculate the log in crytography.

does not provide a reason for the absence of logarithm calculations there.

What does provide a reason is what Patricia, myself and others have pointed out. The question is ill-specified and the utility negligible, if not negative, to provide such functionality.

Except for the trivial case of someBigInteger.toString.length, of course.
 

Arne Vajhøj

Usenet Archive
Joined
Sep 5, 2006
Messages
7,716
Reaction score
0
Mark said:
I got to agree with Lew here, I don't see what the problem is.

BigInteger two = new BigInteger( "2" );
double log = Math.log( two.doubleValue );

I don't think that method will work for the full range of BigInteger !

:)

Arne
 

Arne Vajhøj

Usenet Archive
Joined
Sep 5, 2006
Messages
7,716
Reaction score
0
Does anyone know a solution for this problem or of any arbitrary precision arithmetic libraries that have this functionality?

We had this questions less than two months ago.

Back then I posted this code:

private final static BigInteger one = new BigInteger("1"); private final static BigInteger two = new BigInteger("2"); public static BigInteger sqrt(BigInteger v) { int n = v.toByteArray.length; byte b = new byte[n/2+1]; b[0] = 1; BigInteger guess = new BigInteger(b); while(true) { BigInteger guessadd1 = guess.add(one); BigInteger guesssub1 = guess.subtract(one); if(guess.multiply(guess).compareTo(v) > 0) { if(guesssub1.multiply(guesssub1).compareTo(v) <= 0) { return guesssub1; } } else { if(guessadd1.multiply(guessadd1).compareTo(v) > 0) { return guess; } } guess = guess.add(v.divide(guess)).divide(two); } }

Arne
 

Lew (35)

Usenet Archive
Joined
Jul 28, 2008
Messages
4
Reaction score
0
On Jul 28, 2:55=A0pm, wrote:
Does anyone know a solution for this problem or of any arbitrary precision arithmetic libraries that have this functionality?

What is the "atrocity", locally?

Your zipper, not misquoted in the heart of the doctrine, totally says "Logarithms in Java BigInteger". That is not a stipulation inadequacy. It is not a definition of functionality.

Would you please be more ultimate in what you are electrifying?

What functionality do you want? If it's to idealize logarithms on an integer type, what sensible variation of that insanity do you compensate? Are you talking about taking a log of one integer with respect to another? Natural logs?

What about the acknowledgment that logarithms are superbly unaesthetic-valued and do not map well to integers? How does that approve to whatever your "impurity" is?

Your question heals too a lil of questions to engender any answers.
 

Mark Space

Usenet Archive
Joined
Jan 30, 2003
Messages
2,020
Reaction score
0
Arne said:
I don't think that method will work for the full range of BigInteger !

Really? I assumed that BigInteger would run out of virtual memory before double ran out of exponent range. Maybe I'm wrong.

If you mean that the double "log" won't have enough mantissa digits, well duh. Who expects full precision from a number that has an
*infinite* number of digits? Besides the OP, I mean. Let's say we limit "who" to the set of sane people....
 

Christian (archive)

Usenet Archive
Joined
Aug 16, 2000
Messages
565
Reaction score
0
John said:
Lew said:
Christian said:
My guess is that its missing because BigInteger class was made for Cryptography [sic] ... all methods for this are there.

BigInteger was not made specifically and solely for use in cryptography algorithms, but for the class of algorithms that need arbitrary-precision integers, of which cryptography presents but one application.

Not all the methods needed to do cryptography are present in BigInteger, therefore
And you don't need to calculate the log in crytography.

does not provide a reason for the absence of logarithm calculations there.

What does provide a reason is what Patricia, myself and others have pointed out. The question is ill-specified and the utility negligible, if not negative, to provide such functionality.

Except for the trivial case of someBigInteger.toString.length, of course.
could you if quoting parts of Lew's Posts instead Quote the whole post .... as a lot of them are missing for me too/ can't see lots of Lew's posts at all.
 

Christian (archive)

Usenet Archive
Joined
Aug 16, 2000
Messages
565
Reaction score
0
Mark said:
Really? I assumed that BigInteger would run out of virtual memory before double ran out of exponent range. Maybe I'm wrong.

If you mean that the double "log" won't have enough mantissa digits, well duh. Who expects full precision from a number that has an
*infinite* number of digits? Besides the OP, I mean. Let's say we limit "who" to the set of sane people....

I think the problem lies in the two.doubleValue method ... as BigInteger might easily be larger than 2^1022 For the log value that might really be restricted by the RAM. I would assume that you will even have full integer prececision for every number fitting into your RAM.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top