home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / a139_1 / !Hope_Programs_SimpleInt < prev    next >
Encoding:
Text File  |  1990-09-23  |  1.4 KB  |  71 lines

  1. !       ><HopeProgs$Dir>.SimpleInt         !
  2. !                                          !
  3. !------------------------------------------!
  4. !                                          !
  5. !  This is a collection of simple Hope     !
  6. !  functions over integers.                !
  7. !                                          !
  8. !------------------------------------------!
  9.  
  10.  
  11.  
  12.  
  13.  
  14. dec AddDigit : num # num  -> num;
  15. --- AddDigit(Number,Digit)  <=  (Number * 10) + Digit;
  16.  
  17.  
  18.  
  19. infix cat : 4;
  20. dec cat : num # num -> num;
  21. --- Number cat Digit  <=  (Number * 10) + Digit;
  22.  
  23.  
  24.  
  25. dec fact : num -> num;
  26. --- fact 0  <=  1;
  27. --- fact m  <=  m * fact(m-1);
  28.  
  29.  
  30.  
  31. dec gcd : num # num -> num;
  32. --- gcd (first , second)
  33.     <= if (first mod second) = 0
  34.          then second
  35.          else gcd ( second , (first mod second) );
  36.  
  37.  
  38.  
  39. dec ChangeBase : num # num -> num;
  40. --- ChangeBase ( Number , Base )
  41.     <= if (Number div Base) = 0
  42.          then Number
  43.          else ChangeBase((Number div Base),Base) cat (Number mod Base);
  44.  
  45.  
  46. infix perm : 7;
  47. dec perm : num # num -> num;
  48. --- n perm r
  49.     <= (fact n) div fact(n-r);
  50.  
  51.  
  52.  
  53. infix combl: 6;
  54. dec combl : num # num -> num;
  55. --- n combl r
  56.     <= (fact n) div ( (n - r) * fact r );
  57.  
  58.  
  59.  
  60. infix combe: 7;
  61. dec combe : num # num -> num;
  62. --- n combe r
  63.     <= (fact n) div ( (n - r) * fact r );
  64.  
  65.  
  66.  
  67. infix combg: 8;
  68. dec combg : num # num -> num;
  69. --- n combg r
  70.     <= (fact n) div ( (n - r) * fact r );
  71.