GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-May-2006, 06:33
vkiran_v vkiran_v is offline
New Member
 
Join Date: May 2006
Posts: 14
vkiran_v is on a distinguished road

How to deal with large numbers?


I'm facing problem in using large numbers that are generated while i'm trying to calculate factorial of 10,000, (10000!). i need this for calculating the probability of piosson distrubutions. i'm not able to store that even using long and double. so please help me in this...
  #2  
Old 01-May-2006, 08:29
cjavac#c++_vbP cjavac#c++_vbP is offline
Junior Member
 
Join Date: Mar 2006
Location: Miami, FL
Posts: 42
cjavac#c++_vbP is on a distinguished road

Re: How to deal with large numbers?


consider using __int64 instead of int.
  #3  
Old 01-May-2006, 08:59
cjavac#c++_vbP cjavac#c++_vbP is offline
Junior Member
 
Join Date: Mar 2006
Location: Miami, FL
Posts: 42
cjavac#c++_vbP is on a distinguished road

Re: How to deal with large numbers?


long int x = 100000000000101;
__int64 result = 100000000000101;
cout << "x: " << x << endl;
cout << "result: " << result << endl;

yields

x: 276447333
result: 100000000000101

as you can see, a regular long int cannot store large numbers like __int64 did. BEing that you are a programmer, this is now your turn to do some reading on the difference between ints, __int8, __int16, __int32, __int64.
  #4  
Old 01-May-2006, 10:09
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: How to deal with large numbers?


Quote:
Originally Posted by vkiran_v
I'm facing problem in using large numbers that are generated while i'm trying to calculate factorial of 10,000, (10000!). i need this for calculating the probability of piosson distrubutions. i'm not able to store that even using long and double. so please help me in this...

I respectfully suggest that you consider the magnitudes of the quantities involved before you start coding.

By Stirling's approximation, the value of 10000 factorial would require something over 118000 bits for its binary representation. I think it is safe to make a couple of assertions here:

1. No builtin integer data type for any system for which you are likely to have access will be able to represent 10000 factorial.

2. No builtin floating point data type for any system for which you are likely to have access will have a large enough mantissa to represent 10000 factorial exactly.

3. No builtin floating point data type for which you are likely to have access will be able even to represent Stirling's approximation of 10000 factorial (long doubles run out of steam at about 1751 factorial on my systems).

My Conclusion I
I think that it is very unlikely that you can even approximate 10000 factorial with any builtin data types. Maybe you could approximate the log of 10000 factorial (or, maybe not --- you might be able to figure it out), but does that help you?

My Conclusion II
If you want to consider using some "huge number" function library (such as GNU gmp), think about the size of the numbers that you will be dealing with and the number of operations to get to 10000 factorial. You might consider what it is that you are going to do with these 35660 decimal digit numbers?

My Conclusion III
Since people around the world use Poisson distributions for statistical analysis all of the time, I doubt that they have to calculate 10000 factorial (or use numbers of that magnitude in obtaining their results).

Note that my assertions all include an escape clause, and could be wrong (maybe you do have access to such a computer).

Note that I have used Roman Numerals for my Conclusions (like World Wars). They are open to discussion and refutation. They are opinions and, like all opinions, are just opinions.

Finally, a two-part question:

a. What results are you trying to obtain?

b. Are you sure that they require the calculation of 10000 factorial?

Regards,

Dave

"The purpose of computing is insight, not numbers."
---Richard W. Hamming
Last edited by davekw7x : 01-May-2006 at 11:17.
  #5  
Old 05-May-2006, 12:26
vkiran_v vkiran_v is offline
New Member
 
Join Date: May 2006
Posts: 14
vkiran_v is on a distinguished road

Re: How to deal with large numbers?


Actually in my program,I have to calculate the probability of arrival calls per hour,the call arrival rates (lamda)given are 1000,1100,...up to 1800.The number of arrival calls starting from 10000 up to 100000 calls per hour.My first problem how to calculate the probabiliy using poisson process formula with these large values(the pwer and factorial).Second problem is how to convert this probability to values in the software
  #6  
Old 05-May-2006, 13:37
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: RThis is my problem with large numbers


Quote:
Originally Posted by vkiran_v
,the call arrival rates (lamda)given are 1000,1100,...up to 1800.
.
.
.
The number of arrival calls starting from 10000 up to 100000 calls per hour

Help me out a little:

I think that you are saying this: You are given a model for which the call requests are assumed to have a Poisson distribution. What are the units that you are using? What does "1000" mean in your descripton?

In other words, if the Poisson parameter is lambda, and lambda = "something times t", we need to know the units for "something". If the "something" is 1000, does that mean 1000 calls per minute, 1000 calls per second, 1000 calls per hour, or what?) And, for a given value of lambda, I think you want to know what is the probability that you will see a certain number of calls in an hour, right? Or what?

In other words, would this be a statement of the problem for a given lambda and a given call arrival rate:

Given that the call request arrival distribution is Poisson with 1000 calls requests per minute, what is the probability that 10000 calls arrive in an hour?

I'm just guessing. If your real requirement is different, maybe you can give a complete problem discription.


If this does describe what you are trying to get at, I think that the problem is to use different values of lambda and for each value you want to calculate the probability of seeing the various numbers of calls in an hour.

This is certainly out of the range of elementary programming practices and techniques, but I think it points out the importance of stating (writing it down and telling us as well as yourself) the exact problem and making sure that one understands what will be required before starting to write code.

It is entirely possible that solving this problem will require calculations involving the evaluation of 10000 factorial. But maybe not. Let's make sure we are solving the right problem before we start.

I don't need to see all of your work (and I understand if you don't want to show other class members every thing that you are working on by posting on a public forum), but, in addition to the clarification that I requested, I would like to know a little more about how you are planning to use the value of 10000 factorial in solving the problem.

Is this a math class (probability/stochastic processes), a computer science class (programming), an electrical engineering class (communications theory) or what? I would be interested in knowing the prerequisites, to give me a little clue as to what level of advice you need.

In other words, if you were given an expression and told to write a program that evaluates that expression directly, for different parameter values, I would like to see the expression. On the other hand if you were given a problem involving, somehow, a random variable from a Poisson distribution and told to do something with it, I would like have a little more context about the level of mathematical expertise that class members are supposed to possess (and use).

Regards,

Dave
  #7  
Old 06-May-2006, 15:56
vkiran_v vkiran_v is offline
New Member
 
Join Date: May 2006
Posts: 14
vkiran_v is on a distinguished road

Re: How to deal with large numbers?


Quote:
Originally Posted by vkiran_v
Actually in my program,I have to calculate the probability of arrival calls per hour,the call arrival rates (lamda)given are 1000,1100,...up to 1800.The number of arrival calls starting from 10000 up to 100000 calls per hour.My first problem how to calculate the probabiliy using poisson process formula with these large values(the pwer and factorial).Second problem is how to convert this probability to values in the software

It is required from me to simulate a channel allocation model in cellular system(mobile compuing),the objective is to minimize the number of blocked calls in the system,it is assumed that the calls have a poisson distribution.I proposed some algorithm to solve the problem.But there are some parameters given to me and I should use them, they are as follows:
First, Lambda (the mean call arrival rate) which defined here as the number of call arrivals per hour.Lambda should have the values 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800.
Second parameter given is that the simulating results collected after the 10,000 calls and ends at 100,000 calls.
Since I don't have good idea about probability/statistics,so First I need to know how to calculate the probability of these calls which arrived per hour(the numbers seems to be very large).As you said exactly(Dave),the problem is I want to use different values of lambda (1000,1100,...1800), and for each value I want to calculate the probability of the various numbers of calls in hour.
Is it possible to convert the arrival rate to calls per second instead of per hour? and if possible how? and what expression should I use?(can I divide the above values by 3600 for example).So my problem is first in probability/stochastic and second in coding this probability in my program.
My work is a kind of research and not belong to any classes.

Thanking you in advance
  #8  
Old 07-May-2006, 02:10
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: How to deal with large numbers?


Quote:
Originally Posted by vkiran_v
It is required from me to simulate a channel allocation model in cellular system(mobile compuing),

This is a lot different than what I thought you were asking. (I had the impression that you were using a formula to calculate the probability of a number of calls in a given time interval for a particular statistical model of call arrivals.)

In order to simulate a channel allocation model, I assume that you intend to generate traffic using a random number generator. The random number function built into the C (and C++) standard libary returns uniformly distributed samples (at least that is what it attempts). There are a number of methods that use samples from a uniform distribution to create samples with other distributions.

If you haven't had any exposure to such things, I respectfully suggest that you should stop and read up on them before starting to write code. (None of the Poisson methods involve 10000 factorial or any other calculations directly using the Poisson distribution formula, by the way.) You can look in math or communications engineering textbooks (or with a search engine) for "non uniform random variate generation" or "poisson random variant generation" or some such thing.

I'll give you an on-line reference that I have found useful from time to time (actually, I have a hard copy that I bought some years ago, but I also downloaded some of the pdf files that I find useful):

Numerical Recipes Home Page. (See footnote.)

You can download chapter 7 of Numerical Recipes in C and read the sections on random number generation. There is C code for a uniform random number generator that is "better" than the good old C standard library function rand() for certain reasons, and there is a section (complete with C code) for generating Poisson variants. You might find the C++ textbook more suitable, but I don't think it is available for free download.

There are, of course many other resources, but I like to start with something that actually leads to reasonably functional executable code. Something that a lot of pretty good math books (and even engineering books) stop short of.

If you have any programming or language issues, you can post the code and explain what you don't understand about how it worked (or didn't work), but I don't think a generic public forum on programming like this is the place to work out the details of the project. (But it never hurts to ask.)

It is an interesting topic to me, but there are limits to the amount of personal bandwidth, not to mention board bandwidth, that I think should be used for details of such a specialized topic.

Regards,

Dave

Footnote:
A couple of my mathematician friends who can truly be called Numerical Analysts (unlike yours truly, who is, at best, a dilettante) tend to look on this work as being somewhat beneath them. That is, for almost every algorithm used to solve a problem in the book, they like to point out a "better" set of solutions that real Numerical Analysts all know about and have known for years. On the other hand, I feel that it is a pretty good place to see some practical solutions to a lot of problems. At least, I think it's a pretty good place to start.

My personal feelings about some of the code in the book are kind of negative (from a style point of view I can see some hangover from the FORTRAN style of the original text in this series), but, for the most part it works pretty much as I would expect from the description in the text. I suggest that, if you find the information useful, you can abstract the relevant bits of code and rearrange it to better satisfy your sense of form and style.

If something seems particularly obscure, then rewrite it totally with something more obvious to you (but then test and compare the results of your code with the stuff from the book).

That is my suggestion for all code, algorithms, or ideas in general that you get from other sources. Whether from books, classmates, public forums or other online references. Provided that you understand exactly the meaning and intent of every little piece of stuff that finds its way into your project, it's no sin to build your work on an expansion of information from other sources.

That is provided that you give due credit, of course --- regardless of any personal morality issues, remember that your boss or instructor or faculty adviser (or whoever) can use internet search engines and reference books also. Some of them may even lurk around gidforums from time to time.
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question re comparing large numbers earachefl C++ Forum 4 01-May-2006 09:15
Binary number systems: BCD, twos complement, ones complement, etc. machinated Miscellaneous Programming Forum 6 08-Feb-2006 11:51
subscript error in coding warborules C Programming Language 6 27-Nov-2005 18:16
Large numbers... Bruno Couto C Programming Language 2 30-Sep-2005 08:23
Linear Search eccoflame C Programming Language 3 19-Apr-2005 09:36

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 23:56.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.