Subject: Re: Critical memory leak with J/Link >I've encountered a curious, and completely disabling, memory leak when >I use J/Link. The memory leak is such that a program can easily >consume over 1.5GB of virtual memory and will crash the system if left >to run for an extended period of time. The leak occurs under both >Windows XP and Mac OS X (Panther), with both machines running >Mathematica 5.0 (J/Link version 2.1.1). The XP box has Sun Java >1.4.1_03 (build 2) installed, and the OS X box has java 1.4.2_03 (build >1.4.2_03-117.1) installed. >Here's the simplest example I've found. > // MemoryLeaker.java > import com.wolfram.jlink.*; > public class MemoryLeaker { > Expr expr; > public MemoryLeaker(Expr e) { > expr = e; > } > public Expr getExpr() { > return expr; > } > } >Once MemoryLeaker is compiled, load it into Mathematica and use it as >follows (adjusting the AddToClassPath command as necessary, of course). > In[1]:= > Needs[JLink`]; > < In[3]:= > AddToClassPath[/Users/jalex/Source/tmp/]; > In[4]:= > LoadJavaClass[MemoryLeaker]; > In[5]:= > g=GridGraph[50,50]; > In[6]:= > memoryLeaker=JavaNew[MemoryLeaker, > NormalizeVertices[g] > ]; > In[7]:= > Do[ > memoryLeaker@getExpr[],{50} > ]; >The above run leaves J/Link, on my OS X box, in the following state: >ID Name %CPU Real Memory Virtual Memory >1287 J/Link 0.00 265.50 MB 823.50 MB >Memory is not freed with calls to JavaGC[]. It is only freed with >QuitJava[] or quitting the kernel. >The real kicker is that if you replace line 6 with the following: > In[6]:= > memoryLeaker=JavaNew[MemoryLeaker, g ]; >no leak occurs. However, if you replace line 6 with > In[6]:= > g2 = NormalizeVertices[g]; > memoryLeaker = JavaNew[MemoryLeaker, g2]; >you still get the memory leak. >Would someone please explain what I'm doing wrong in the above example >or, if I'm not doing anything wrong, a work-around? Jason, that it is down inside MathLink itself and has to do with calling MLTransferExpression() to move certain unusual types of data between links. The leak can be easily duplicated in a C-language MathLink program. Until this is fixed, there is a parl workaround in your J/Link program that might be sufficient for you. You need to change the way the Expr is stored internally so that MLTransferExpression() is not used to send it to Mathematica. This can be done by calling any Expr method that unwinds the expression data off of its highly optimized cache on an internal loopback link. Any Expr method that inspects the expression in any way will perform this unwinding; here is an example that uses length(): // MemoryLeaker.java import com.wolfram.jlink.*; public class MemoryLeaker { Expr expr; public MemoryLeaker(Expr e) { expr = e; // ADDED LINE. This has the side effect of unwinding the // expression data off the internal loopback link: expr.length(); } public Expr getExpr() { return expr; } } This will make the movement of the data from Java to Mathematica not leak memory (it will also make it a bit slower, but this will probably not be a concern). Unfortunately, the inil send of the expression from Mathematica to Java still uses MLTransferExpression() internally and this cannot be changed. If you are only sending the data to Java once, and retrieving it many times, the fix provided above will be enough for you, but if you are sending expressions from Mathematica to Java as many times as the other way around, then you will still have a problem. If the above workaround is not sufficient for you, and you cannot wait for a fix to show up in MathLink, then contact me directly and we can discuss more complicated techniques, such as avoiding the Expr class entirely. Todd Gayley Wolfram Research === Subject: Re: A simple integral > A simple integration, under Version 4.1.2: > Integrate[x^2 Exp[-(x-μ)^2/(2 σ^2)],{x,-∞,∞}] > 2 > If[Re[σ ] > 0, > 2 > Sqrt[2 Pi] Sqrt[σ ] > 2 2 > (μ + σ ), > 2 > x > Integrate[----------------, > 2 2 > (x - μ) /(2 σ ) > E > {x, -Infinity, Infinity}]] > and the same under 5.0 > Integrate[x^2 Exp[-(x-μ)^2/(2 σ^2)],{x,-∞,∞}] > 2 μ > If[Re[σ ] > 0 && Re[--] < 0, > 2 > σ > 2 2 > Sqrt[2 Pi] μ (μ + σ ) > -(----------------------), > 2 > μ > Sqrt[--] > 2 > σ > 2 > x > Integrate[----------------, > 2 2 > (x - μ) /(2 σ ) > E > {x, -Infinity, Infinity}, > Assumptions - μ 2 > Re[--] >= 0 || Re[σ ] <= 0 > 2 > σ > ]] > Two questions: > 1. Whence the extra condition in Version 5? > 2. Why the negative sign in Version 5? Using PowerExpand then gives > a negative result for this integral which is patently, for real > parameters, positive. > Am I alone in feeling that Version 5 has introduced more problems than > it has solved? > > Department of Physics and Astronomy > University College London > Gower Street > LONDON > WC1E 6BT > (44)(0)207 679 3404 > a.harker@ucl.ac.uk The price of progress ;-) However, note that (in 5.0) Integrate[x^2*Exp[-(x - μ)^2/(2*σ^2)], {x, -Infinity, Infinity}, Assumptions -> {σ > 0}] Sqrt[2*Pi]*σ*(μ^2 + σ^2) Andrzej Kozlowski Chiba, Japan http://www.mimuw.edu.pl/~akoz/ === Subject: A simple integral A simple integration, under Version 4.1.2: Integrate[x^2 Exp[-(x-μ)^2/(2 σ^2)],{x,-∞,∞}] 2 If[Re[σ ] > 0, 2 Sqrt[2 Pi] Sqrt[σ ] 2 2 (μ + σ ), 2 x Integrate[----------------, 2 2 (x - μ) /(2 σ ) E {x, -Infinity, Infinity}]] and the same under 5.0 Integrate[x^2 Exp[-(x-μ)^2/(2 σ^2)],{x,-∞,∞}] 2 μ If[Re[σ ] > 0 && Re[--] < 0, 2 σ 2 2 Sqrt[2 Pi] μ (μ + σ ) -(----------------------), 2 μ Sqrt[--] 2 σ 2 x Integrate[----------------, 2 2 (x - μ) /(2 σ ) E {x, -Infinity, Infinity}, Assumptions -> μ 2 Re[--] >= 0 || Re[σ ] <= 0 2 σ ]] Two questions: 1. Whence the extra condition in Version 5? 2. Why the negative sign in Version 5? Using PowerExpand then gives a negative result for this integral which is patently, for real parameters, positive. Am I alone in feeling that Version 5 has introduced more problems than it has solved? Department of Physics and Astronomy University College London Gower Street LONDON WC1E 6BT (44)(0)207 679 3404 a.harker@ucl.ac.uk === Subject: Re: A simple integral Dr A.H. Harker schrieb im Newsbeitrag > A simple integration, under Version 4.1.2: > Integrate[x^2 Exp[-(x-μ)^2/(2 σ^2)],{x,-∞,∞}] > .... I tried 6 or 7 different character sets but it didn't help. Please repost using commonly used charset(s). -- Peter Pein, Berlin to write to me, start the subject with [ === Subject: Re: A simple integral The negative sign is easy to explain, since it appears under the assumption that mu is negative -- hence the result is positive WITH that negative sign. Version 5.0.1 gives yet another answer: Integrate[x^2/E^((x - [Micro])^2/ (2*s^2)), {x, -8, 8}] (1/2)*s*((2*s*(-8 + [Micro]))/ E^((8 + [Micro])^2/(2*s^2)) - (2*s*(8 + [Micro]))/ E^((-8 + [Micro])^2/(2*s^2)) - Sqrt[2*Pi]*(s^2 + [Micro]^2)* Erf[(-8 + [Micro])/(Sqrt[2]* s)] + Sqrt[2*Pi]* (s^2 + [Micro]^2)* Erf[(8 + [Micro])/(Sqrt[2]*s)]) Did you mean Infinity when you posted 8 in that integral? If so, Integrate[x^2/E^((x - [Micro])^2/ (2*s^2)), {x, -Infinity, Infinity}] If[Re[s^2] > 0 && Re[[Micro]/s^2] < 0, 0, Integrate[ x^2/E^((x - [Micro])^2/(2*s^2)), {x, -Infinity, Infinity}, Assumptions -> Re[s^2] <= 0 || Re[[Micro]/s^2] >= 0]] The second argument of THAT answer is manifestly wrong, since the integral can't be zero. (And the third argument seems rather useless.) Yes, v5 has apparently caused more problems than it solved. Bobby > A simple integration, under Version 4.1.2: > Integrate[x^2 Exp[-(x-μ)^2/(2 σ^2)],{x,-∞,∞}] > 2 > If[Re[σ ] > 0, > 2 > Sqrt[2 Pi] Sqrt[σ ] > 2 2 > (μ + σ ), > 2 > x > Integrate[----------------, > 2 2 > (x - μ) /(2 σ ) > E > {x, -Infinity, Infinity}]] > and the same under 5.0 > Integrate[x^2 Exp[-(x-μ)^2/(2 σ^2)],{x,-∞,∞}] > 2 μ > If[Re[σ ] > 0 && Re[--] < 0, > 2 > σ > 2 2 > Sqrt[2 Pi] μ (μ + σ ) > -(----------------------), > 2 > μ > Sqrt[--] > 2 > σ > 2 > x > Integrate[----------------, > 2 2 > (x - μ) /(2 σ ) > E > {x, -Infinity, Infinity}, > Assumptions -> > μ 2 > Re[--] >= 0 || Re[σ ] <= 0 > 2 > σ > ]] > Two questions: > 1. Whence the extra condition in Version 5? > 2. Why the negative sign in Version 5? Using PowerExpand then gives > a negative result for this integral which is patently, for real > parameters, positive. > Am I alone in feeling that Version 5 has introduced more problems than > it has solved? > > Department of Physics and Astronomy > University College London > Gower Street > LONDON > WC1E 6BT > (44)(0)207 679 3404 > a.harker@ucl.ac.uk === Subject: Start MathKernel at low priority how can I start the MathKernel with low priority? I suppose there should be some arguments which can be passed to MLOpen in the Kernel Properties. Rico === Subject: plot combination If I have n Table, how can i plot all the table together in the same graph Paolo === Subject: Re: Programming style While you _can_ use various paradigms when programming in Mathematica, the functional approach has several advantages, including: (1) efficiency; (2) clarity and readability -- once you know how to read functional constructs -- for two reasons: (a) programs are shorter, hence easier to take in at a glance; (b) you can think, and program, at a higher level, leaving implementation details to the Mathematica interpreter. Don't neglect the advantages, too, of using array-oriented programming and pattern-matching. > I am an experienced computer programmer having used ADA, C, Visual Basic > etc. for years. > Recently I bought the book Mathematica - A Practical Approach, where different > styles of programming are discussed, namely > Functional programming versus Procedural programming. > The book seems to suggest that most Scientist and professional Mathematica > users prefer the Functional programming approach. > For years I have been working with the Procedural method. > What are your feelings ? Is it worth the effort to learn the Functional > method ? Does it matter ? > Best Wishes > Laurence Keegan -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Programming style I would say it greatly depends what sort of programming you are intending to do. If it is to do with any kind of algebra than functional programming (prefarably with pattern matching a la Mathematica) is, in my opinion, not just the best way but the only way. For other things, e. g. numerics, it does not seem to matter that much. Andrzej Kozlowski > I am an experienced computer programmer having used ADA, C, Visual > Basic > etc. for years. > Recently I bought the book Mathematica - A Practical Approach, where > different > styles of programming are discussed, namely > Functional programming versus Procedural programming. > The book seems to suggest that most Scientist and professional > Mathematica > users prefer the Functional programming approach. > For years I have been working with the Procedural method. > What are your feelings ? Is it worth the effort to learn the Functional > method ? Does it matter ? > Best Wishes > Laurence Keegan === Subject: Programming style I am an experienced computer programmer having used ADA, C, Visual Basic etc. for years. Recently I bought the book Mathematica - A Practical Approach, where different styles of programming are discussed, namely Functional programming versus Procedural programming. The book seems to suggest that most Scientist and professional Mathematica users prefer the Functional programming approach. For years I have been working with the Procedural method. What are your feelings ? Is it worth the effort to learn the Functional method ? Does it matter ? Best Wishes Laurence Keegan === Subject: Re: Programming style Like you I am (or was) an experienced procedural programmer (Fortran, C, Basic, etc). It took a while for me to get used to the functional approach of Mathematica, but once the penny had dropped there was no going back. I wince when I look at the (procedural style of) Mathematica that I used to write in the early days. I could not imagine now giving up using the functional programming style because it is so well matched to my way of thinking (i.e. scientist/mathematician). In fact, I would go so far as to say that my style of thinking has improved since I became aware what functional programming was. Steve Luttrell > I am an experienced computer programmer having used ADA, C, Visual Basic > etc. for years. > Recently I bought the book Mathematica - A Practical Approach, where different > styles of programming are discussed, namely > Functional programming versus Procedural programming. > The book seems to suggest that most Scientist and professional Mathematica > users prefer the Functional programming approach. > For years I have been working with the Procedural method. > What are your feelings ? Is it worth the effort to learn the Functional > method ? Does it matter ? > Best Wishes > Laurence Keegan === Subject: Re: Programming style Lorenzo Here's my five-pennyworth, I expect that many others in this newsgroup will chip in with their own strongly-held, entirely reasonable and mutually contradictory opinions: Yes, it is worth the effort to learn the Mathematica way of doing things, the 'functional' method as you put it, just as it is worth the effort to learn the object-oriented way when learning Java or Smalltalk etc. Their are two reasons for making the effort: 1) equivalent programs written in the functional style and the procedural style usually execute faster, in Mathematica, in the functional style; 2) functional programs are often shorter, easier to write and easier to understand than procedural programs - once you have enough experience of Mathematica that is; 3) writing functional-style programs is much more natural in Mathematica than writing procedural programs; when I try to write procedural programs in Mathematica I always feel that I am fighting against the system rather than with it. (OK, so that make's three reasons ...) In my second paragraph I place the word functional in quotation marks, I won't be surprised to read other answers to your enquiry which deny that Mathematica is a functional language - pure functional languages don't do assignment for instance. I think it's functional enough to be considered a functional language. But you should also make some effort to get your head around the concept of Mathematica as a term rewriting system, transforming expressions in one form into an equivalent (usually simpler) form. If the book you have is the one by Nancy Blachman then stick with it. I think it is the best introductory text for general purpose Mathematica. Once you've finished with it you will be ready to digest The Mathematica Book itself. good luck Mark > I am an experienced computer programmer having used ADA, C, Visual Basic > etc. for years. > Recently I bought the book Mathematica - A Practical Approach, where different > styles of programming are discussed, namely > Functional programming versus Procedural programming. > The book seems to suggest that most Scientist and professional Mathematica > users prefer the Functional programming approach. > For years I have been working with the Procedural method. > What are your feelings ? Is it worth the effort to learn the Functional > method ? Does it matter ? > Best Wishes > Laurence Keegan === Subject: Re: Programming style My short comment is that Functional programming is more abstract, more complicated, more elegant, more fun and more fundemental then Procedural one. It follows the intuitiveness of logic. All well and cool, but note that in the background, the cpu does it procedurally. What do others think? Borut, Slovenia > I am an experienced computer programmer having used ADA, C, Visual Basic > etc. for years. > Recently I bought the book Mathematica - A Practical Approach, where different > styles of programming are discussed, namely > Functional programming versus Procedural programming. > The book seems to suggest that most Scientist and professional Mathematica > users prefer the Functional programming approach. > For years I have been working with the Procedural method. > What are your feelings ? Is it worth the effort to learn the Functional > method ? Does it matter ? > Best Wishes > Laurence Keegan === Subject: Plotting 3-trees in 6 vertices and evaluating their Prufer codes. Math friends, I would appreciate help with the following problem. I am trying to plot and evaluate Prufer codes for the 200 3-trees in 6 vertices. I will explain. There are twenty triangles with 6 vertices. Assume that the vertices are labeled a, b, c, d, e, f. Take one triangle, (a, b, c). Now from vertex d, attach edges to a, b, and c. Thus, you will have a tetrahedron in four vertices. Now from vertex e, attach three edges to an existing triangle in the tetrahedron. Call this new graph 5-gon. Then, with vertex f, attach it to three edges of an existing triangle in 5-gon. There are 200 of these 3-trees. I have gotten bogged down with redundancy, plotting, and perhaps evaluating the Prufer codes with Mathematica. The Prufer code is evaluated in the following way. Suppose that d and e are adjacent to our triangle (a, b, c). Then, suppose f ties to triangle (a, b, d). The Prufer code looks at the vertices of degree three in alphabetical order. 1. e is the first vertex of degree 3. It is adjacent to triangle (a, b, c). Remove it. 2. Then, c is the first vertex of degree 3. c is adjacent to triangle (a, b, d). Remove it. 3. You have a tetrahedron remaining, (a, b, d, f) The three latter letters are (b, d, f) So, remove a leaving (b, d, f). 4. So, the Prufer code for this, first listing the vertex removed first, is (a, b, c), (a, b, d), and (b, d, f). There will be 200 triads of triples. Can anyone help? Diana -- God made the integers, all else is the work of man. L. Kronecker, Jahresber. DMV 2, S. 19. === Subject: Re: Incidence/frequency of numbers in lists Hi Diana, I think the following lines will do what you intend In[20]:= Clear[PurgeData] In[21]:= PurgeData[data_, range_:6, requiredIncidence_:3] := Select[data, Function[lst, Min[ Map[Length[Cases[lst, #1]] &, Range[range] ] >= requiredIncidence] ] Then PurgeData[YourArray] will return the purged array. Sasha > Hi math folks, > I have a 24 - 455 table. I have named the table SortedEdgeSet. > The first few lines look like the following: > {{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6},... > The numbers 1 - 6 are listed 24 times in each of 455 sublists. > I would like to create a new table which does not contain the sublist > members which have two or fewer occurances of any of the six numbers in the > sublist. I only want sublists which have three or more of each of the > numbers. > So, for example, I would want to exclude the second sublist line: > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, > because it only has two 6's in it. > I don't know what an occurance function might be in Mathematica. Can anyone > help? > Diana M. === Subject: Re: Incidence/frequency of numbers in lists > Hi math folks, > I have a 24 - 455 table. I have named the table SortedEdgeSet. > The first few lines look like the following: > {{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, > 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, > 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, > 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, > 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, > 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, > 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, > 6},... > The numbers 1 - 6 are listed 24 times in each of 455 sublists. > I would like to create a new table which does not contain the sublist > members which have two or fewer occurances of any of the six numbers > in the > sublist. I only want sublists which have three or more of each of the > numbers. > So, for example, I would want to exclude the second sublist line: > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, > 6}, > because it only has two 6's in it. > I don't know what an occurance function might be in Mathematica. Can > anyone > help? > Diana M. > -- > God made the integers, all else is the work of man. > L. Kronecker, Jahresber. DMV 2, S. 19. You don't need any occurance function (there is a function Frequencies in the Statistics`DataManipulation` package but it is not needed here). If your sublists are already sorted, as in your example, then ls={{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6}}; Select[ls,Min[Length/@(Split[#])]>2&] {{1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,5,5,5,6,6,6},{1,1,1,1,1,2,2,2,2,2, 3,3, 3,3,4,4,4,4,5,5,5,6,6,6},{ 1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,5,5,5,5,6,6,6},{1,1,1,1,1,2,2,2,2,2,3, 3, 3,3,4,4,4,4,5,5,5,6,6,6},{ 1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,5,5,5,6,6,6,6}} does the job. If not then you need to include Sort before split: Select[ls,Min[Length/@(Split[Sort[#]])]>2&] Andrzej Kozlowski Chiba, Japan http://www.mimuw.edu.pl/~akoz/ === Subject: Incidence/frequency of numbers in lists Hi math folks, I have a 24 - 455 table. I have named the table SortedEdgeSet. The first few lines look like the following: {{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6},... The numbers 1 - 6 are listed 24 times in each of 455 sublists. I would like to create a new table which does not contain the sublist members which have two or fewer occurances of any of the six numbers in the sublist. I only want sublists which have three or more of each of the numbers. So, for example, I would want to exclude the second sublist line: {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, because it only has two 6's in it. I don't know what an occurance function might be in Mathematica. Can anyone help? Diana M. -- God made the integers, all else is the work of man. L. Kronecker, Jahresber. DMV 2, S. 19. === Subject: Re: Incidence/frequency of numbers in lists Diana schrieb im Newsbeitrag > Hi math folks, > I have a 24 - 455 table. I have named the table SortedEdgeSet. > The first few lines look like the following: > {{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6},... > The numbers 1 - 6 are listed 24 times in each of 455 sublists. > I would like to create a new table which does not contain the sublist > members which have two or fewer occurances of any of the six numbers in the > sublist. I only want sublists which have three or more of each of the > numbers. > So, for example, I would want to exclude the second sublist line: > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, > because it only has two 6's in it. > I don't know what an occurance function might be in Mathematica. Can anyone > help? > Diana M. > -- > God made the integers, all else is the work of man. > L. Kronecker, Jahresber. DMV 2, S. 19. Diana, Select[SortedEdgeSet, Min[Length /@ Split[#1]] >= 3 & ] splits each row in e.g. {{1,1,1,1,1},{2,2,2,2,2},..,{6,6}}, calculates the length of each sublist {5,5,...,2}, takes the minimum 2, takes this value to decide whether the row will be selected or not and finally returns the list of selected rows. -- Peter Pein, Berlin to write to me, start the subject with [ === Subject: Re: Incidence/frequency of numbers in lists Diana, Here is one possibility. In[7]:= lst={{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6}}; In[8]:= Cases[lst,a_/;MatchQ[Split[a],{{_,_,__},{_,_,__},{_,_,__},{_,_,__},{_,_,__}, {_,_,__}}]] Out[8]= {{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6}} Note the double dashes in the third entry of each sublist. If every single digit is always represented at least once, then you could simplify the above pattern to {{_,_,__}..} Carl Woll > Hi math folks, > I have a 24 - 455 table. I have named the table SortedEdgeSet. > The first few lines look like the following: > {{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6},... > The numbers 1 - 6 are listed 24 times in each of 455 sublists. > I would like to create a new table which does not contain the sublist > members which have two or fewer occurances of any of the six numbers in the > sublist. I only want sublists which have three or more of each of the > numbers. > So, for example, I would want to exclude the second sublist line: > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, > because it only has two 6's in it. > I don't know what an occurance function might be in Mathematica. Can anyone > help? > Diana M. > -- > God made the integers, all else is the work of man. > L. Kronecker, Jahresber. DMV 2, S. 19. === Subject: Re: Incidence/frequency of numbers in lists > Hi math folks, > I have a 24 - 455 table. I have named the table SortedEdgeSet. > The first few lines look like the following: > {{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6},... > The numbers 1 - 6 are listed 24 times in each of 455 sublists. > I would like to create a new table which does not contain the sublist > members which have two or fewer occurances of any of the six numbers in the > sublist. I only want sublists which have three or more of each of the > numbers. > So, for example, I would want to exclude the second sublist line: > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, > because it only has two 6's in it. > I don't know what an occurance function might be in Mathematica. Can anyone > help? First, we can define a function which counts the occurences of each element in a list and gives True if there are more than 2 and False if not - let's name this function proofli. In the case above you know that the elements are only the integers from 1 to 6, so prrofli can be formulated easy proofli[li_] := Module[{erg = True}, Do[If[Count[li, i] < 3, erg = False; Break[]], {i, 1, 6}]; erg] (If you would not know the elements in the sublists then it would be a little bit harder - you could generate with the function Union reference lists with only one occurence of each element and go through all elements for counting them in your sublists) And now, you can map proofly on your sublists and select the sublists for which proofly gives True: sourcelist = {{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6}} newlist = Select[sourcelist, proofli[#] == True &] HTH, Michael Taktikos, Hamburg === Subject: Re: Incidence/frequency of numbers in lists That's called a 455 by 24 matrix, not 24 - 255 table. The following code does what you want, I think: data={{1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,5,5,5,6,6,6},{1,1,1,1,1,2,2,2,2,2 , 3,3,3,3,4,4,4,4,5,5,5,5,6,6},{1,1, 1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,6,6,6},{1,1,1,1,1,2,2,2,2,2,3,3, 3,3,4,4,4,5,5,5,5,6,6,6},{1,1, 1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,6,6,6},{1,1,1,1,1,2,2,2,2,2,3,3, 3,3,4,4,4,4,5,5,6,6,6,6},{1,1, 1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,5,5,5,6,6,6,6}}; keepQ=Min[Frequencies[#][[All,1]]]>2&; keepQ/@data Select[data,keepQ] {True,False,True,True,True,False,True} {{1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,5,5,5,6,6,6},{1,1,1,1,1,2,2,2,2,2,3,3, 3,3,4,4,4,4,5,5,5,6,6,6},{ 1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,5,5,5,5,6,6,6},{1,1,1,1,1,2,2,2,2,2,3,3, 3,3,4,4,4,4,5,5,5,6,6,6},{ 1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,5,5,5,6,6,6,6}} Bobby > Hi math folks, > I have a 24 - 455 table. I have named the table SortedEdgeSet. > The first few lines look like the following: > {{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6}, > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6},... > The numbers 1 - 6 are listed 24 times in each of 455 sublists. > I would like to create a new table which does not contain the sublist > members which have two or fewer occurances of any of the six numbers in the > sublist. I only want sublists which have three or more of each of the > numbers. > So, for example, I would want to exclude the second sublist line: > {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, > because it only has two 6's in it. > I don't know what an occurance function might be in Mathematica. Can anyone > help? > Diana M. === Subject: Re: Programming style >Recently I bought the book Mathematica - A Practical Approach, >where different styles of programming are discussed, namely >Functional programming versus Procedural programming. >The book seems to suggest that most Scientist and professional >Mathematica users prefer the Functional programming approach. >What are your feelings ? Is it worth the effort to learn the >Functional method ? Does it matter ? If you will be using Mathematica extensively, then yes it does matter and is worthwhile to learn the functional paradigm. Mathematica seems to run much faster and more efficiently when functional programming is used instead of proceedural methods. For example, consider In[1]:= Timing[For[sum = 0; n = 1, n < 100001, n++, sum += n]] Out[1]= {1.2999999999999998*Second, Null} In[2]:= Timing[Plus @@ Range[10000]] Out[2]= {0.009999999999999787*Second, 50005000} Additionally, to me the functional paradigm is easier to debug since I don't need to keep track of array lengths etc. -- To reply via email subtract one hundred and four === Subject: Help: shift+enter doesn't give me any output suddenly! I am a beginner. shift+enter doesn't give me any output at notebook suddenly! after I restart the program, it doesn't work either. thank you! === Subject: Elliptic Curves and Cryptography Questions (sorry for the long question), I am working on a presentation with Elliptic Curves/Cryptography and had a few questions I was hoping someone could answer. I use Mathematica version 4.0 (wish I could afford 5.0). The elliptic curve I am using is E: y^2 == x^3 + x + 4 mod 23 (defined over F{23}, that is p = 23). Questions: 1. There are 29 solution set points ((x, y) pairs plus the point at infinity) to this elliptic curve. {{0,2}, {0,21},{1,11},{1,12},{4,7},{4,16},{7,3},{7,20},{8,8},{8,15},{9,11},{9,12},{1 0,5},{10,18},{11,9},{11,14},{13,11},{13,12},{14,5},{14,18},{15,6},{15,17},{1 7,9},{17,14},{18,9},{18,14},{22,5},{22,19}} Manually, one can check the quadratic residues and then determine if y^2 is in that set (a cumbersome approach). Is there a command in Mathematica to find this solution set? 2. These points are typically labeled P and one does point addition for P1+P2, etc, until you reach the point order. There are basically three operations one needs to do on E: check for a point at infinity, point addition and point doubling. a. If P = (x, y) E F{p}, then (x,y)+(x,-y) = O (that is, P = -P and that is the point at infinity). So we would just check for this condition on the current set of points we wanted to add. b. Point Addition: Let P = (x1, y1) and Q = (x2, y2) (obviously both are elements of F{23}), where P != +/- Q. Then P +Q = (x3, y3), where x3 = ((y2-y1)/(x2-x1))^2 - x1 - x2 y3 = ((y2-y1)/(x2-x1))(x1 - x3) - y1 c. Pont Doubling: Let P = (x1, y1), where P != -P (that is x, -y). Then 2P = (x3, y3), where x3 = ((3 x1^2 + a)/(2 y1))^2 -2 x1 y3 = ((3 x1^2 + a)/(2 y1))(x1-x3) - y1 Is there an easy way to code this in Mathematica so I can just pass the curve E, the prime p, and the two points to add? The module will determine if I have reached a. (the point at infinity), if this is b (just adding P+ Q) or c (point doubling to get 2P). 3. When I do ListPlot[a], I get the scatter plot that I want, but is there a way to show the grid, the points (x,y pairs) and to make the points a little larger? 4. When I do, << Graphics`ImplicitPlot` ImplicitPlot[y^2 == x^3+x+4, {x, -2,2}] I am wondering if there is a way to show the elliptic curve E and to superimpose the points above and their values so the points are visible and the plot is useable in a powerpoint slide? My email is alpha_flip@nethere.com_alpha (remove the _alpha's) === Subject: RE: Incidence/frequency of numbers in lists Let x be your 455 x 24 matrix. Define the function In[1]:= moreThanTwo[x_List]:=Min[Count[x,#]&/@Range[1,6]]>2 Then apply as follows: In[2]:= Select[x,moreThanTwo[#]&] This will produce the list you want. Try the example: In[33]:= ex=Table[Random[Integer,{1,6}],{455},{24}]; In[4]:= Select[ex,moreThanTwo[#]&] Tomas Garza Mexico City Original Message: ----------------- === Subject: Incidence/frequency of numbers in lists Hi math folks, I have a 24 - 455 table. I have named the table SortedEdgeSet. The first few lines look like the following: {{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6}, {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6},... The numbers 1 - 6 are listed 24 times in each of 455 sublists. I would like to create a new table which does not contain the sublist members which have two or fewer occurances of any of the six numbers in the sublist. I only want sublists which have three or more of each of the numbers. So, for example, I would want to exclude the second sublist line: {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6}, because it only has two 6's in it. I don't know what an occurance function might be in Mathematica. Can anyone help? Diana M. -- God made the integers, all else is the work of man. L. Kronecker, Jahresber. DMV 2, S. 19. -------------------------------------------------------------------- mail2web - Check your email from the web at http://mail2web.com/ . === Subject: RE: Programming style It is definitely worth the effort. Once you get used to it you'll never want to hear about Do's and For's again. It is enormously more powerful, and it's a beauty. I strongly recommend you spend a few hours learning it(since you are an experienced programmer, your main effort will be in changing your old paradigms). Tomas Garza Mexico City Original Message: ----------------- === Subject: Programming style I am an experienced computer programmer having used ADA, C, Visual Basic etc. for years. Recently I bought the book Mathematica - A Practical Approach, where different styles of programming are discussed, namely Functional programming versus Procedural programming. The book seems to suggest that most Scientist and professional Mathematica users prefer the Functional programming approach. For years I have been working with the Procedural method. What are your feelings ? Is it worth the effort to learn the Functional method ? Does it matter ? Best Wishes Laurence Keegan -------------------------------------------------------------------- mail2web - Check your email from the web at http://mail2web.com/ .