comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Large Numbers
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Large Numbers [message #64981] Fri, 06 February 2009 20:13 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paolo writes:

> You know about the function "factorial", right?

Holy smokes! No. And BINOMIAL is right there beside it!
Sheesh, I've spent all day re-inventing the wheel.

Well, at least no one can accuse me of not knowing statistics
from first principles. ;-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Large Numbers [message #64982 is a reply to message #64981] Fri, 06 February 2009 20:06 Go to previous messageGo to next message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
David Fanning wrote:
> Kenneth P. Bowman writes:
>
>> If you are dividing them, you don't really want to use
>> integers, do you? That's what floats (and doubles) are for.
>
> Humm. You might have a point there.
>
> Ok, how about a contest. Given two integers, x and n,
> with x le n, what is the most efficient way to evaluate
> this expression:
>
> n!/(x! * (n-x)!)

You know about the function "factorial", right?

Ciao,
Paolo

>
> The usual prize (as my children know well, a hug
> and a kiss) to the winner. :-)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Large Numbers [message #64983 is a reply to message #64982] Fri, 06 February 2009 19:59 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kenneth P. Bowman writes:

> If you are dividing them, you don't really want to use
> integers, do you? That's what floats (and doubles) are for.

Humm. You might have a point there.

Ok, how about a contest. Given two integers, x and n,
with x le n, what is the most efficient way to evaluate
this expression:

n!/(x! * (n-x)!)

The usual prize (as my children know well, a hug
and a kiss) to the winner. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Large Numbers [message #64984 is a reply to message #64983] Fri, 06 February 2009 19:53 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paolo writes:

> For instance, you can easily find that
> 1000!=4.023*10E2567

Humm. Maybe you can easily find it. All I found was
an old notebook with spider egg casings on the cover,
and what looks like the remains of an anchovy pizza
spilled on the phone number of that blonde in the
bikini who ended up with my roommate's older brother. :-(

Cheers,

David

P.S. Thanks for the tips. Who knew logarithms could
be so useful! :-)

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Large Numbers [message #64985 is a reply to message #64984] Fri, 06 February 2009 18:57 Go to previous messageGo to next message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <MPG.23f671b522eba5ef98a5f6@news.giganews.com>,
David Fanning <news@dfanning.com> wrote:

> Now, of course, the formula I was using has a large
> factorial number divided by another large factorial
> number, so the *actual* number I wanted to use in the
> calculation is not that big. But it begs the question:
> what strategy do computer scientists use to deal with
> one very, very big number divided by another very, very
> big number?

If you are dividing them, you don't really want to use
integers, do you? That's what floats (and doubles) are for.

Ken Bowman
Re: Large Numbers [message #64986 is a reply to message #64985] Fri, 06 February 2009 17:14 Go to previous messageGo to next message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
David Fanning wrote:
> David Fanning writes:
>
>> Uh, probably, if I can find those dusty books
>> down in the basement. :-(
>
> I found my slide rule. Maybe that will help.

For instance, you can easily find that
1000!=4.023*10E2567

How?

the trick is that
gamma(x+1)=factorial(x)

therefore, alog(factorial(1000))=lngamma(1001)=2567.6046
10^0.6046=4.023

1000!=4.023*10E2567

Ciao,
Paolo

>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Large Numbers [message #64989 is a reply to message #64986] Fri, 06 February 2009 16:54 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> Uh, probably, if I can find those dusty books
> down in the basement. :-(

I found my slide rule. Maybe that will help.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Large Numbers [message #64991 is a reply to message #64989] Fri, 06 February 2009 16:50 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paolo writes:

> Well, if you deal with very large numbers,
> you can do all the computations
> with the logarithm of the numbers.
>
> Simple, no?

Uh, probably, if I can find those dusty books
down in the basement. :-(

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Large Numbers [message #64992 is a reply to message #64991] Fri, 06 February 2009 16:49 Go to previous messageGo to next message
Chris[6] is currently offline  Chris[6]
Messages: 84
Registered: July 2008
Member
On Feb 6, 1:12 pm, David Fanning <n...@dfanning.com> wrote:
> Folks,
>
> I made a big mistake and signed up for an Applied Statistics
> class this semester. Now I pretty much spend every free
> waking moment doing stats homework. :-(
>
> Anyway, for lunch today I decided to grab a sandwich and
> give my youngest some support by calculating how many
> girls he had to ask out to have an 80% chance of getting
> a date for Saturday night.
>
> I made some conservative assumptions (I learned later
> my ideas about the college social scene apply more to the
> 1970s than they do to today), and off I went writing a
> couple of short IDL programs to do the calculations for
> the Binomial and Geometry Distributions, etc. All pretty
> straightforward.
>
> But then I started getting screwy results. (This, in itself,
> is not all that unusual in this particular class. In fact, I've
> begun to consider it something of a minor miracle if I'm within
> an order of magnitude of the right answer.) But even I know
> that negative probabilities don't show up until the second
> semester. What in the world!?
>
> It turns out that the recursive function I naively wrote to
> process a factorial calculation was overflowing my long
> integers, even with a simple calculation like 20! (twenty
> factorial). Yowser!
>
> Now, of course, the formula I was using has a large
> factorial number divided by another large factorial
> number, so the *actual* number I wanted to use in the
> calculation is not that big. But it begs the question:
> what strategy do computer scientists use to deal with
> one very, very big number divided by another very, very
> big number?
>
> I've solved my immediate problem for my little toy problem
> by using LONG64 variables. But this can't be the right solution.
> Does anyone know?
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Java, for example, has a bigInteger class, which internally represents
a big integer as an array of 32 bit integers - something like
decimal_equivalent = sum( array[i] * (2^32)^i )

http://developer.classpath.org/doc/java/math/BigInteger-sour ce.html

chris
Re: Large Numbers [message #64993 is a reply to message #64992] Fri, 06 February 2009 15:35 Go to previous messageGo to next message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
Well, if you deal with very large numbers,
you can do all the computations
with the logarithm of the numbers.

Simple, no?

Ciao,
Paolo


David Fanning wrote:
> Folks,
>
> I made a big mistake and signed up for an Applied Statistics
> class this semester. Now I pretty much spend every free
> waking moment doing stats homework. :-(
>
> Anyway, for lunch today I decided to grab a sandwich and
> give my youngest some support by calculating how many
> girls he had to ask out to have an 80% chance of getting
> a date for Saturday night.
>
> I made some conservative assumptions (I learned later
> my ideas about the college social scene apply more to the
> 1970s than they do to today), and off I went writing a
> couple of short IDL programs to do the calculations for
> the Binomial and Geometry Distributions, etc. All pretty
> straightforward.
>
> But then I started getting screwy results. (This, in itself,
> is not all that unusual in this particular class. In fact, I've
> begun to consider it something of a minor miracle if I'm within
> an order of magnitude of the right answer.) But even I know
> that negative probabilities don't show up until the second
> semester. What in the world!?
>
> It turns out that the recursive function I naively wrote to
> process a factorial calculation was overflowing my long
> integers, even with a simple calculation like 20! (twenty
> factorial). Yowser!
>
> Now, of course, the formula I was using has a large
> factorial number divided by another large factorial
> number, so the *actual* number I wanted to use in the
> calculation is not that big. But it begs the question:
> what strategy do computer scientists use to deal with
> one very, very big number divided by another very, very
> big number?
>
> I've solved my immediate problem for my little toy problem
> by using LONG64 variables. But this can't be the right solution.
> Does anyone know?
>
> Cheers,
>
> David
>
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Large Numbers [message #65024 is a reply to message #64993] Mon, 09 February 2009 20:28 Go to previous messageGo to next message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Feb 6, 6:35 pm, Paolo <pgri...@gmail.com> wrote:
> Well, if you deal with very large numbers,
> you can do all the computations
> with the logarithm of the numbers.
>
> Simple, no?
>
> Ciao,
> Paolo
>
> David Fanning wrote:
>> Folks,
>
>> I made a big mistake and signed up for an Applied Statistics
>> class this semester. Now I pretty much spend every free
>> waking moment doing stats homework. :-(
>
>> Anyway, for lunch today I decided to grab a sandwich and
>> give my youngest some support by calculating how many
>> girls he had to ask out to have an 80% chance of getting
>> a date for Saturday night.
>
>> I made some conservative assumptions (I learned later
>> my ideas about the college social scene apply more to the
>> 1970s than they do to today), and off I went writing a
>> couple of short IDL programs to do the calculations for
>> the Binomial and Geometry Distributions, etc. All pretty
>> straightforward.
>
>> But then I started getting screwy results. (This, in itself,
>> is not all that unusual in this particular class. In fact, I've
>> begun to consider it something of a minor miracle if I'm within
>> an order of magnitude of the right answer.) But even I know
>> that negative probabilities don't show up until the second
>> semester. What in the world!?
>
>> It turns out that the recursive function I naively wrote to
>> process a factorial calculation was overflowing my long
>> integers, even with a simple calculation like 20! (twenty
>> factorial). Yowser!
>
>> Now, of course, the formula I was using has a large
>> factorial number divided by another large factorial
>> number, so the *actual* number I wanted to use in the
>> calculation is not that big. But it begs the question:
>> what strategy do computer scientists use to deal with
>> one very, very big number divided by another very, very
>> big number?
>
>> I've solved my immediate problem for my little toy problem
>> by using LONG64 variables. But this can't be the right solution.
>> Does anyone know?
>
>> Cheers,
>
>> David
>
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
>

What I've run into a few times lately is taking sums and differences
of very large numbers. Logarithms are not so useful in those cases...
anyone have any general useful techniques (beyond the usual "re-phrase
your equations to only calculate the differences between sums instead
of the sums themselves")?

-Jeremy.
Re: Large Numbers [message #65111 is a reply to message #65024] Tue, 10 February 2009 09:28 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
Jeremy Bailin wrote:
> What I've run into a few times lately is taking sums and differences
> of very large numbers. Logarithms are not so useful in those cases...
> anyone have any general useful techniques (beyond the usual "re-phrase
> your equations to only calculate the differences between sums instead
> of the sums themselves")?

Absent techniques for the particular problem, you could always use Ron
Kneusel's BigNum (for integers) and Arbitrary precision floating point
packages. They are on the ITT VIS code contrib library.

Mike
--
www.michaelgalloy.com
Tech-X Corporation
Associate Research Scientist
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to read a multi-band image with IDL
Next Topic: Re: 12 bit jpeg

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 20:10:40 PDT 2025

Total time taken to generate the page: 0.01035 seconds