Post Reply 
[VA] SRC #013 - Pi Day 2023 Special
03-29-2023, 01:16 AM
Post: #30
RE: [VA] SRC #013 - Pi Day 2023 Special
.
Hi, all,

Adding to this:

Valentin Albillo Wrote:Alas, as J-F discovered, it does not, possibly because of some rounding error, but the solution is quite simple because the only operations which can result in such errors are the square root (which is innocent) and divisions. A little examination reveals that the culprit is IP(T/(K*K)) at line 2, and changing it to (T DIV (K*K)), like this: [...]

Indeed IP(T/(K*K)) and T DIV (K*K), which would appear at first sight to be equivalent, do really differ at times (though very rarely and for large values of T, it seems,) when the former's rounding does not match the latter's truncation.

A trivial program I wrote (relatively) quickly finds all mismatches for various very large integer T and for K from 2 to IP(√T) (i.e. ~ one million possible cases for the first eight values of T listed):
          T              # Mismatches            K
    -----------------------------------------------------------
    999,999,999,999      31 instances      2, 5, 8, 16, 20, ...
    999,999,999,998      19 instances      2, 3, 8, 20, 25, ...
    999,999,999,997      12 instances      3, 8, 25, 80, ...
    999,999,999,996       3 instances      3, 3125, 31250, ...
    999,999,999,995       3 instances      2, 3, 254
    999,999,999,994       1 instance       254
    999,999,999,993       1 instance       254
    999,999,999,992       0 instances       -
     99,999,999,999       0 instances       -
As you can see, for T = 999,999,999,999 there are 31 different instances (in about a million) where IP(T/(K*K)) differs from T DIV (K*K), for K ranging from 1 to IP(√T). The instances begin at K = 2 (249,999,999,999 vs. 250,000,000,000, respectively) and end at K = 500,000 (3 vs. 4, respectively).

Doing the same with T = 999,999,999,998, there's just 19 instances reported instead of 31, and with T = 999,999,999,997 just 12. By the time T equals 999,999,999,995, a mere 3 faulty instances remain (namely for K = 2, 3 and 254), then 999,999,999,994 and 999,999,999,993 have just the one mismatch (in a million !) and for 999,999,999,992 and below there seems to be none.

Also, as expected, running this small program for input values with less than 12 digits, say T = 99,999,999,999 instead, i.e. 1E11 - 1, no instances of mismatches appear at all, and probably the same happens for all smaller T.

V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC #013 - Pi Day 2023 Special - Valentin Albillo - 03-29-2023 01:16 AM



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