Post Reply 
Dividing factorials on 15C CE
01-10-2024, 08:38 PM
Post: #21
RE: Dividing factorials on 15C CE
(01-10-2024 07:54 PM)Thomas Klemm Wrote:  I just hope we clarified that David was not talking about the division 49/2 but about (1 * 50/1 * 49)/2.
Which is indeed an integer.

I understood it in that way too, but I already knew this property of the algorithm.


Now about my previous comment:

(01-09-2024 04:38 PM)J-F Garnier Wrote:  
(01-09-2024 01:23 AM)Thomas Klemm Wrote:  P(50, 45) = 1 * 50 * 49 * 48 * 47 * 46

Code:
def perm(n, k):
    p = 1
    while n > k:
        p *= n
        n -= 1
    return p

It seems to me a singular way to compute permutations... Smile

Nobody responded to my remark, and I'm not sure Thomas fully understood it.
My point is that Perm(50, 45) is NOT 1 * 50 * 49 * 48 * 47 * 46 . This is Perm(50,5).
And so the Python perm code Thomas posted is wrong.

Also, the Python comb code is very inefficient to compute simple values such as comb(50,5), that the code computes as:
comb(50,5) = 1 * 50/1 * 49/2 * 48/3 * 47/4 * 46/5 * 45/6 * 44/7 * 43/8 * ... * 7/44 * 6/45
This kills the claim of avoiding rounding errors.
Instead it should just be:
comb(50,5) = 1 * 50/1 * 49/2 * 48/3 * 47/4 * 46/5

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
01-10-2024, 08:44 PM
Post: #22
RE: Dividing factorials on 15C CE
(01-09-2024 01:23 AM)Thomas Klemm Wrote:  
P(50, 45) = 1 * 50 * 49 * 48 * 47 * 46


This does not agree with my 35s, or my 50g where 50 45 PERM returns a 63-digit number, ~2.5345E62.
Find all posts by this user
Quote this message in a reply
01-10-2024, 08:59 PM
Post: #23
RE: Dividing factorials on 15C CE
(01-10-2024 08:38 PM)J-F Garnier Wrote:  Nobody responded to my remark, and I'm not sure Thomas fully understood it.
My point is that Perm(50, 45) is NOT 1 * 50 * 49 * 48 * 47 * 46 . This is Perm(50,5).
And so the Python perm code Thomas posted is wrong.

Quote:‘When I use a word,’ Humpty Dumpty said in rather a scornful tone, ‘it means just what I choose it to mean–neither more nor less.’

(01-10-2024 08:38 PM)J-F Garnier Wrote:  Also, the Python comb code is very inefficient …

That's true. Feel free to post an improved version.
But the point of these two functions was to illustrate how Phil's calculations can be done without rounding errors.
Find all posts by this user
Quote this message in a reply
01-11-2024, 07:13 PM
Post: #24
RE: Dividing factorials on 15C CE
(01-10-2024 07:54 PM)Thomas Klemm Wrote:  I just hope we clarified that David was not talking about the division 49/2 but about (1 * 50/1 * 49)/2.
Which is indeed an integer.
Exactly right. When we evaluate 1 * 50 / 1 * 49 / 2 * 48 / 3 * 47 / 4 * 46 / 5 * 45 / 6 * 44 / 7 * 43 / 8 * ... * 7 / 44 * 6 / 45 from left to right, each division results in an integer.
Find all posts by this user
Quote this message in a reply
01-11-2024, 10:04 PM
Post: #25
RE: Dividing factorials on 15C CE
(01-11-2024 07:13 PM)David Hayden Wrote:  
(01-10-2024 07:54 PM)Thomas Klemm Wrote:  I just hope we clarified that David was not talking about the division 49/2 but about (1 * 50/1 * 49)/2.
Which is indeed an integer.
Exactly right. When we evaluate 1 * 50 / 1 * 49 / 2 * 48 / 3 * 47 / 4 * 46 / 5 * 45 / 6 * 44 / 7 * 43 / 8 * ... * 7 / 44 * 6 / 45 from left to right, each division results in an integer.

Yes, it's an integer, but not necessary free of rounding errors if the intermediate results exceed the digit capacity of the machine.
This could happen here on a 15c for instance (if it was using this implementation for comb, that it does not) since the intermediate values exceed 1e14 for a final result of about 2118760.

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)