K
Klueless
For a different base B, other than 10, use
1+Floor(Log(Gamma(N+1))/Log(B))
1+Floor(Log(Gamma(N+1))/Log(B))
Pascal Bourguignon said:Of course, but this sum (before rounding) is 10! (log10(n!) actually,
but it's the same) You have computed the factorial when it was asked
to avoid it!
Pascal Bourguignon said:The function "number of digits" is a logarithm function, so computing
it is equivalent to compute the product.
jmcgill said:Hello.
Is there a method for computing the number of digits, in a given numeric
base, of N factorial, without actually computing the factorial?
For example, 8! has 5 digits in base 10; 10! has 7 digits in base 10.
Is there a way to compute that information without actually evaluating
the factorial?
James McGill said:I was looking for a way to format the output of a "Pascal's Triangle" of
an arbitrary number of rows, centering each row, without computing all the
rows before formatting, so coarse approximations are fine.
Stuart said:As the number of digits grows quite quickly, such "formatting" for the
latter rows is going to give very long rows. It will also make early rows,
containing 1-2 digit numbers look quite barren.
10^3! = 2568jmcgill said:Is there a method for computing the number of digits, in a given numeric
base, of N factorial, without actually computing the factorial?
Yes. For base 10 :
Let Pi = 3.14159265358979323846
C = 1 / log(10) log = Neperian logarithm
K = log(2*Pi) / 2
L = N.(log(N) - 1 ) + log(N) / 2 + 1/(12.N) + K N > 3
Number of digits of N! = [C. L ] +1 [ ] means floor of
Example: Number of digits of 100! = 158
Proginoskes said:Oh, really?
log 1 = 0
log 2 = 0.3010299957
log 3 = 0.4771212547
log 4 = 0.6020599914
log 5 = 0.6989700043
log 6 = 0.7781512504
log 7 = 0.8450980400
log 8 = 0.9030899871
log 9 = 0.9542425094
log 10 = 1.0
(All are accurate except for possibly to the last digit.)
The sum is 6.559763033 (last 2 digits possibly wrong, but the rest
are correct).
The answer is 7.
Where did I use the fact that 10! = 3,628,800?
jmcgill said:Hello.
Is there a method for computing the number of digits, in a given numeric
base, of N factorial, without actually computing the factorial?
For example, 8! has 5 digits in base 10; 10! has 7 digits in base 10.
Is there a way to compute that information without actually evaluating
the factorial?
CBFalconer said:Proginoskes said:Oh, really?
log 1 = 0
log 2 = 0.3010299957
log 3 = 0.4771212547
log 4 = 0.6020599914
log 5 = 0.6989700043
log 6 = 0.7781512504
log 7 = 0.8450980400
log 8 = 0.9030899871
log 9 = 0.9542425094
log 10 = 1.0
(All are accurate except for possibly to the last digit.)
The sum is 6.559763033 (last 2 digits possibly wrong, but the rest
are correct).
The answer is 7.
Where did I use the fact that 10! = 3,628,800?
Ingenious. [...]
Proginoskes said:CBFalconer said:Proginoskes said:Pascal Bourguignon wrote:
jmcgill wrote:
Is there a method for computing the number of digits, in a
given numeric base, of N factorial, without actually computing
the factorial?
For example, 8! has 5 digits in base 10; 10! has 7 digits in
base 10. Is there a way to compute that information without
actually evaluating the factorial?
I think the number of digits (base 10) in 10! should be:
sum (1<= x <= 10 | log10(x))
With appropriate rounding, of course.
Of course, but this sum (before rounding) is 10! (log10(n!)
actually, but it's the same) You have computed the factorial
when it was asked to avoid it!
Oh, really?
log 1 = 0
log 2 = 0.3010299957
log 3 = 0.4771212547
log 4 = 0.6020599914
log 5 = 0.6989700043
log 6 = 0.7781512504
log 7 = 0.8450980400
log 8 = 0.9030899871
log 9 = 0.9542425094
log 10 = 1.0
(All are accurate except for possibly to the last digit.)
The sum is 6.559763033 (last 2 digits possibly wrong, but the rest
are correct).
The answer is 7.
Where did I use the fact that 10! = 3,628,800?
Ingenious. [...]
Only relatively speaking. Evidently Pascal Bourguignon has not taken a
course involving logarithms (which are taught in College Algebra here
in the USA).
Pascal said:Proginoskes said:Only relatively speaking. Evidently Pascal Bourguignon has not taken aCBFalconer said:Proginoskes wrote:
Pascal Bourguignon wrote:
Of course, but this sum (before rounding) is 10! (log10(n!)
actually, but it's the same) You have computed the factorial
when it was asked to avoid it!
Oh, really?
log 1 = 0
log 2 = 0.3010299957
log 3 = 0.4771212547
log 4 = 0.6020599914
log 5 = 0.6989700043
log 6 = 0.7781512504
log 7 = 0.8450980400
log 8 = 0.9030899871
log 9 = 0.9542425094
log 10 = 1.0
(All are accurate except for possibly to the last digit.)
The sum is 6.559763033 (last 2 digits possibly wrong, but the rest
are correct).
The answer is 7.
Where did I use the fact that 10! = 3,628,800?
Ingenious. [...]
course involving logarithms (which are taught in College Algebra here
in the USA).
No, I learned logarithms in France. And in France,
log(3628800)=6.55976303287679375...
which is the sum you've computed.
Since there is an isomorphism between (R+*,*) and (R,+), computing
log(f(x)) or f(x) is the same thing.
Logan Shaw said:Pascal said:Proginoskes said:CBFalconer wrote:
Proginoskes wrote:
Pascal Bourguignon wrote:
Of course, but this sum (before rounding) is 10! (log10(n!)
actually, but it's the same) You have computed the factorial
when it was asked to avoid it!
Oh, really?
log 1 = 0
log 2 = 0.3010299957
log 3 = 0.4771212547
log 4 = 0.6020599914
log 5 = 0.6989700043
log 6 = 0.7781512504
log 7 = 0.8450980400
log 8 = 0.9030899871
log 9 = 0.9542425094
log 10 = 1.0
(All are accurate except for possibly to the last digit.)
The sum is 6.559763033 (last 2 digits possibly wrong, but the rest
are correct).
The answer is 7.
Where did I use the fact that 10! = 3,628,800?
Ingenious. [...]
Only relatively speaking. Evidently Pascal Bourguignon has not taken a
course involving logarithms (which are taught in College Algebra here
in the USA).No, I learned logarithms in France. And in France,
log(3628800)=6.55976303287679375...
which is the sum you've computed.
Since there is an isomorphism between (R+*,*) and (R,+), computing
log(f(x)) or f(x) is the same thing.
I think Proginoskes' point was that if you understood logarithms, you
would have thought to apply them by taking the sum of logarithms
rather than the logarithm of products. It is true that they are
mathematically equivalent, but they are not computationally equivalent.
Pascal said:.... snip ...
The question wasn't to compute the result in a computationally
efficient way, it was to do it without computing the factorial.
My point is that summing the logs IS computing the factorial.
How could I make this point if I didn't understood logarithms?
1000! = 2568jmcgill said:Is there a method for computing the number of digits, in a given numeric
base, of N factorial, without actually computing the factorial?
Yes. For base 10 :
Let Pi = 3.14159265358979323846
C = 1 / log(10) log = Neperian logarithm
K = log(2*Pi) / 2
L = N.(log(N) - 1 ) + log(N) / 2 + 1/(12.N) + K N > 3
Number of digits of N! = [C. L ] +1 [ ] means floor of
Example: Number of digits of 100! = 158
The question wasn't to compute the result in a computationally
efficient way, it was to do it without computing the factorial.
My point is that summing the logs IS computing the factorial.
How could I make this point if I didn't understood logarithms?
Logan Shaw said:True enough, it shows a knowledge of logarithms. But I don't think
it's a valid argument about computation.
Computing log(fact(n)) is not equivalent to computing fact(n). Yes,
an isomorphism exists, and that's noteworthy, but computation is
about transforming information. If you haven't done the whole
transformation, you haven't done the whole computation. There's an
isomorphism between a set of messages and the set of encrypted
versions of those messages as well. Does that mean encrypting,
transmitting, and decrypting is equivalent to just encrypting,
transmitting, and storing the encrypted messages?
For that matter, here are two sets that are isomorphic. The
first set is this:
{
( 1, "(defun fact (n) (if (eq n 0) 1 (* n (fact (- n 1)))))" ),
( 2, "(defun fact (n) (if (eq n 0) 1 (* n (fact (- n 1)))))" ),
( 3, "(defun fact (n) (if (eq n 0) 1 (* n (fact (- n 1)))))" ),
( 4, "(defun fact (n) (if (eq n 0) 1 (* n (fact (- n 1)))))" ),
( 5, "(defun fact (n) (if (eq n 0) 1 (* n (fact (- n 1)))))" )
}
And the second set:
{ 1, 2, 6, 24, 120 }
If I gave the input { 1, 2, 3, 4, 5 } to two programs, and if one computed
the first set while the other computed the second, would you say that the
two programs had computed the same thing? I wouldn't.
So, I would say that computing log(fact(n)) is not equivalent to
computing fact(n). It's close, but there is one step at the end
that has been left out, so it's different.
Pascal said:Logan Shaw said:Pascal said:CBFalconer wrote:
Proginoskes wrote:
Pascal Bourguignon wrote:Of course, but this sum (before rounding) is 10! (log10(n!)
actually, but it's the same) You have computed the factorial
when it was asked to avoid it!Oh, really?
log 1 = 0
log 2 = 0.3010299957
log 3 = 0.4771212547
log 4 = 0.6020599914
log 5 = 0.6989700043
log 6 = 0.7781512504
log 7 = 0.8450980400
log 8 = 0.9030899871
log 9 = 0.9542425094
log 10 = 1.0
(All are accurate except for possibly to the last digit.)
The sum is 6.559763033 (last 2 digits possibly wrong, but the rest
are correct).
The answer is 7.
Where did I use the fact that 10! = 3,628,800?Ingenious. [...]Only relatively speaking. Evidently Pascal Bourguignon has not taken a
course involving logarithms (which are taught in College Algebra here
in the USA).No, I learned logarithms in France. And in France,
log(3628800)=6.55976303287679375...
which is the sum you've computed.
Since there is an isomorphism between (R+*,*) and (R,+), computing
log(f(x)) or f(x) is the same thing.
I think Proginoskes' point was that if you understood logarithms, you
would have thought to apply them by taking the sum of logarithms
rather than the logarithm of products. It is true that they are
mathematically equivalent, but they are not computationally equivalent.
The question wasn't to compute the result in a computationally
efficient way, it was to do it without computing the factorial.
My point is that summing the logs IS computing the factorial.
How could I make this point if I didn't understood logarithms?
Proginoskes said:Which I did. Again, the number 3,628,800 does not appear anywhere in my
calculations. Therefore, I calculated the number 7 "without computing
the factorial".
...
Andrey Tarasevich said:The only reason you are having this argument is that you forgot to agree
on the terminology.
You are saying that "number 3,628,800 does not appear anywhere" in your
calculations. How do you know that? May I remind you that '3,628,800' is
_not_ really a number. We call it a "number" in everyday conversations
because in most everyday contexts calling '3,628,800' a "number" is not
a big error. It is an error, but, once again, everybody understands what
we are really trying to say.
Now, in this discussion the difference becomes more important. So, what
'3,628,800' really is, if it not a "number"? '3,628,800' is a _decimal_
_representation_ of a number. Numbers are mathematical abstractions that
cannot be seen, smelt or touched. The only things about numbers that we
can see, smell or touch are particular _representations_ of numbers.
What you are really claiming above is that there's no decimal
representation of 10! an any point in your program. Fine, I'd be more
surprised it it was there. You can also safely claim that there's no
binary representation of 10! at any point in your program. That'd make
more sense, but that still misses the point. Because anyone can claim
that your sum of logarithms is noting less than an exotic representation
of 10! and, therefore, you are calculating 10! in your code. You just
choose an obscure representation for the result in order to throw the
wolves off your trail.
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.