home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!rpi!usenet.coe.montana.edu!news.u.washington.edu!zermelo.math.washington.edu!petry
- From: petry@zermelo.math.washington.edu (David Petry)
- Newsgroups: sci.math.symbolic
- Subject: Re: "shut up and deal the cards"
- Date: 30 Dec 1992 23:28:58 GMT
- Organization: University of Washington, Mathematics, Seattle
- Lines: 75
- Message-ID: <1htbbqINNdli@shelley.u.washington.edu>
- References: <Bzs70r.B1B@news.cso.uiuc.edu> <Bzv5LK.969@news.cso.uiuc.edu>
- NNTP-Posting-Host: zermelo.math.washington.edu
-
-
-
- [we're comparing the following programs]
-
- >Transpose[Sort[Transpose[{Table[Random[],{Length[lis]}], lis}]]][[2]]
-
-
- >randomize[L_] := Module[{a,b,k,p=L},
- > For[k=Length[L],k>1,k--,
- > b=Random[Integer,{1,k}];
- > a=p[[k]];
- > p[[k]]=p[[b]];
- > p[[b]]=a];
- > p]
-
-
- In article <Bzv5LK.969@news.cso.uiuc.edu> gaylord@ux1.cso.uiuc.edu (Richard J. Gaylord) writes:
- >
- > ... i found David's procedural program very difficult to
- >decipher (i had to spend time figuring out all of the assignment
- >satements)
-
- The assignment statements are a standard method for swapping the elements
- of a list. For clarity, I should have written a separate procedure
- called "swap" to do that.
-
- > while i was able to write my functional program in a direct
- >way by simply implementing what i wanted to do with the entire list using
- > built-in functions
-
- Likewise, I was able to write my program in a direct way, while I had some
- difficulty deciphering Mr. Gaylord's. All that shows is that it is
- relatively easy to transform an idea into a program, but a little harder
- to read a program and figure out its underlying idea.
-
- >many people may not find 'functional' thinking to be obvious to do but
- >that's primarily because they haven't learned how to do it
-
- Well, it seems that this whole issue came up because it wasn't obvious
- how to use functional programming to randomize the order of elements
- in a list. In afterthought it may be obvious.
-
-
- >... functional programming does appear to be a trick to the person
- >unfamiliar with it
-
- One point I was trying to make is that the program can be written
- procedurely in a very straightforward manner using very simple assignment
- statements which virtually any programming language has. In contrast,
- the functional program requires intimate knowledge of complex functions,
- and seems to use them in peculiar ways.
-
- How many people out there know how the Mathematica function "Sort" behaves
- on a nested list like {{1,4},{5,1},{3,2}} ? Why doesn't it return
- {{1,4}, {1,5}, {2,3}} ?
-
- Why should a matrix operation like "Transpose" appear in a function that
- randomizes the order of elements in a list?
-
- In this particular case, the issue of time complexity of programs doesn't
- really arise, since the procedural program is O(n) while the functional
- program is O(n log(n)), but in many instances the functional program
- can be much much worse than the procedural program.
-
- Is there any theory behind Mathematica which says that its functions are
- in some sense 'complete' or 'orthogonal' ? It seems to me that if you
- insist on functional programming, then you are limited by the functions
- available to you.
-
-
-
-
- David Petry
-
-
-