home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / sci / math / symbolic / 3343 < prev    next >
Encoding:
Internet Message Format  |  1992-12-30  |  3.1 KB

  1. Path: sparky!uunet!usc!rpi!usenet.coe.montana.edu!news.u.washington.edu!zermelo.math.washington.edu!petry
  2. From: petry@zermelo.math.washington.edu (David Petry)
  3. Newsgroups: sci.math.symbolic
  4. Subject: Re: "shut up and deal the cards"
  5. Date: 30 Dec 1992 23:28:58 GMT
  6. Organization: University of Washington, Mathematics, Seattle
  7. Lines: 75
  8. Message-ID: <1htbbqINNdli@shelley.u.washington.edu>
  9. References: <Bzs70r.B1B@news.cso.uiuc.edu> <Bzv5LK.969@news.cso.uiuc.edu>
  10. NNTP-Posting-Host: zermelo.math.washington.edu
  11.  
  12.  
  13.  
  14. [we're comparing the following programs]
  15.  
  16. >Transpose[Sort[Transpose[{Table[Random[],{Length[lis]}], lis}]]][[2]]
  17.  
  18.  
  19. >randomize[L_] := Module[{a,b,k,p=L}, 
  20. >            For[k=Length[L],k>1,k--,
  21. >                b=Random[Integer,{1,k}];
  22. >                a=p[[k]];
  23. >                p[[k]]=p[[b]];
  24. >                p[[b]]=a];
  25. >            p]
  26.  
  27.  
  28. In article <Bzv5LK.969@news.cso.uiuc.edu> gaylord@ux1.cso.uiuc.edu (Richard J. Gaylord) writes:
  29. >
  30. >  ...         i found David's procedural program very difficult to
  31. >decipher (i had to spend time figuring out all of the assignment
  32. >satements) 
  33.  
  34. The assignment statements are a standard method for swapping the elements
  35. of a list.  For clarity, I should have written a separate procedure
  36. called "swap" to do that.
  37.  
  38. >            while i was able to write my functional program in a  direct
  39. >way by simply implementing what i wanted to do with the entire list using
  40. > built-in functions 
  41.  
  42. Likewise, I was able to write my program in a direct way, while I had some
  43. difficulty deciphering Mr. Gaylord's.  All that shows is that it is 
  44. relatively easy to transform an idea into a program, but a little harder
  45. to read a program and figure out its underlying idea.
  46.  
  47. >many people may not find 'functional' thinking to be obvious to do but
  48. >that's primarily  because they haven't learned how to do it 
  49.  
  50. Well, it seems that this whole issue came up because it wasn't obvious
  51. how to use functional programming to randomize the order of elements
  52. in a list.  In afterthought it may be obvious.
  53.  
  54.  
  55. >...    functional programming does appear to be a trick to the person
  56. >unfamiliar with it
  57.  
  58. One point I was trying to make is that the program can be written
  59. procedurely in a very straightforward manner using very simple assignment
  60. statements which virtually any programming language has.  In contrast,
  61. the functional program requires intimate knowledge of complex functions,
  62. and seems to use them in peculiar ways.  
  63.  
  64. How many people out there know how the Mathematica function "Sort" behaves 
  65. on a nested list like {{1,4},{5,1},{3,2}} ?  Why doesn't it return
  66. {{1,4}, {1,5}, {2,3}} ?
  67.  
  68. Why should a matrix operation like "Transpose" appear in a function that 
  69. randomizes the order of elements in a list?
  70.  
  71. In this particular case, the issue of time complexity of programs doesn't 
  72. really arise, since the procedural program is O(n) while the functional
  73. program is O(n log(n)), but in many instances the functional program
  74. can be much much worse than the procedural program.
  75.  
  76. Is there any theory behind Mathematica which says that its functions are
  77. in some sense 'complete' or 'orthogonal' ?  It seems to me that if you 
  78. insist on functional programming, then you are limited by the functions
  79. available to you.
  80.  
  81.  
  82.  
  83.  
  84. David Petry
  85.  
  86.  
  87.