Posts

Binomial coefficients modulo m

Image
Today I (re)learned that you can compute binomial coefficients C(n,k) = n!/(k! (n-k)!), modulo some integer m, very efficiently.  NOT as chatGPT or brave.AI or some stackoverflow people suggest, by computing n! and the denominator (mod m), and then multiply the former by the modular inverse of the latter: That won't work because you will most likely (and certainly for n>m ) get 0 for numerator and probably also the denominator. However, when m is prime, we have the wonderful Lucas's theorem  that tells us that  C(n,k) =  ∏  (C(n[i], k[i] ) ; i=1..L)  (mod m)          (where  ∏ =  product) where n[ i ] and k[ i ] are the i -th digits of n and k in base p , and L is the length, i.e., number of base- p digits of k. (For example, { np = digits(n,p), kp = digits(k,p) } in the PARI/GP language.) Remark : In books and Wikipedia, you see the formula with "leading zeros" for k as to get the same length (i.e., L = max{ i...

COBOL, ALGOL, General Hopper

 Welcome to my first post on this new blog "TIL-this": Today I Learned This! Today I learned that COBOL  was developed in 1959, evolved from   FLOW-MATIC  (a.k.a. B-0, Business Language version 0), designed by Admiral  Grace Hopper  (nee Murray) *1906 +1992 because people wanted a machine independent language that resembles the English language, although FORTRAN was already there... (typical instructions are "MOVE value TO variable-a" etc) Remark: I can't understand well why FORTRAN wasn't considered convenient or "too complicated" compared to COBOL... CS students said "the symbols are too complicated, I don't want to learn symbols, we want to use english words."  ==> Symbols  means the "=" sign ?!  programs are rigidly divided in 4 sections : 01000 IDENTIFICATION DIVISION . 01100 PROGRAM-ID . 'HELLO' . 02000 ENVIRONMENT DIVISION . 02100 CONFIGURATION SECTION . 02200 SPECIAL-NAMES . ...