Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.forth    |    Forth programmers eat a lot of Bratwurst    |    117,927 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 116,634 of 117,927    |
|    Gerry Jackson to Krishna Myneni    |
|    Re: exercise in double number arithmetic    |
|    15 Jul 24 23:39:37    |
      From: do-not-use@swldwa.uk              On 15/07/2024 02:15, Krishna Myneni wrote:       > On 7/14/24 16:43, Marc Olschok wrote:       >> On Sat, 06 Jul 2024 22:20:45 Krishna Myneni wrote:       > ...       >>> How many different ways can you choose 42 distinct objects, 21 at a       >>> time? This is "n choose k" or the binomial coefficent.       >>       >> Yes, M*/ comes in handy for C(n,0) = 1 , C(n+1,k+1) = C(n,k)*n/k       >>       >> 42 21 binom d.       >> gives 538257874440       >>       >> where       >>       >> : binom ( n1 n2 -- nd ) \ n k --> C(n,k)       >> dup 0=       >> IF 2drop 1 s>d       >> ELSE 2dup 1- swap 1- swap binom 2swap m*/       >> THEN ;       >>       >> Gforth SEE nicely replaced the original 'recurse' with 'binom' for       >> better readability.       >>       >       > THank you for the recursive version. It's nice to have both looping and       > recursive examples.       >       > There's a reason why RECURSE (or equivalent) is preferable to having the       > name of the word in the output of SEE in Forth. This is because it is       > possible to have an earlier definition with the same name and to call it       > from within the definition e.g.       >       > : binom ... ;       >       > : binom ... binom ... ;       >       > In the later definition of BINOM Forth requires the call to BINOM be the       > earlier definition if it exists in the search order. If it does not       > exist in the search order, then I believe the standard would require an       > error to occur.       >              That's why the simplest way to achieve recursion by name is:              synonym binom recurse       : binom ... binom ... ;       but Gforth's RECURSIVE is better              --       Gerry              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca