title: Speeding up random walk for many particles

text: I am trying to speed up this code for many particles to take a random walk. I'm not sure why it is so slow for such a simple task. I got a few hints from colleagues to reduce the precision of the calculations, compile some of the functions, parallelize the code, or implement C code. I tried to implement each of these, but I most likely don't know what I'm doing because I couldn't get it to work. The particles can and should be simulated in parallel to take advantage of the two cores. I have a bunch (10,000) particles that each take 1000 fixed steps in random directions. I have a bunch of lists with the length of number of particles, and I operate on those lists. This is faster than doing a nested loop, where I first loop over every particle and then loop over each time step. Two random angles are generated for each particle at each time step. Each particle's position is then incremented. I also want to know how many times each particle has crossed a spherical shell. The history of each particle is important: eventually, I will distinguish particles by the number of times they cross the shell so that they take bigger steps the more they have crossed. I tried timing each step, and it seems like the trig functions slow things down. Is there any way to speed this up? Is there a better way to write this code to make it much faster? Eventually, I would like to add some more complications to this code and run it for many more time steps and particles. So, any general speed tips would help. For comparison, the absolute timing of the Do loop is 3 seconds on my laptop with Core i5 M 540 @ 2.53 GHz, with 4 GB RAM.               numparticles = 10^4;     numsteps = 10^3;     radius = 1.;(*radius of shell*)     particlesx = Table[1.001, {numparticles}];(*x-coordinate for each particle*)     particlesy = Table[0., {numparticles}];(*y-coordinate for each particle*)     particlesz = Table[0., {numparticles}];     numcrossings = Table[0., {numparticles}];(*counts the number of crossings for each particle*)          Do[        \[Theta]rand = RandomReal[{0., Pi}, numparticles];(*random polar angle for each particle*)        \[Phi]rand = RandomReal[{0, 2.*Pi}, numparticles];(*random azimuthal angle for each particle*)        rold = particlesx^2 + particlesy^2 + particlesz^2;(*original distance from origin for each particle*)        particlesx = particlesx + 0.01*Sin[\[Theta]rand]*Cos[\[Phi]rand];(*update each particle's position*)        particlesy = particlesy + 0.01*Sin[\[Theta]rand]*Sin[\[Phi]rand];        particlesz = particlesz + 0.01*Cos[\[Theta]rand];        rnew = particlesx^2 + particlesy^2 + particlesz^2;(*new distance from origin*)        isitoutside = (rold - radius)*(rnew - radius);(*yields negative number if the particle crossed the sphere, else positive*)        switchsides = Map[If[# < 0, 1, 0] &, isitoutside];(*if the particle crossed, it increments numcrossings*)        numcrossings = numcrossings + switchsides;        , {step, 1, numsteps}]; // AbsoluteTiming


title: Where in the documentation can I find a list of function argument types?

text: Recently, I learned that it is possible to assign "types" to function arguments in the definition of a function. Suppose I have a function `stringFun` that does some operation (e.g., `StringSplit`) on an input string `str`. I could define the function in this way:               stringFun[str_] := StringSplit[str]      Or, I could define the argument `str_` as being of type `String`:               stringFun[str_String] := StringSplit[str]      What other argument "types" exist in Mathematica? Can I use, for example, `Real`, `List`, or `Table`? I am using Mathematica 7, and I am having some difficulty locating a list of "types" in the documentation. Thanks for your time.


title: Delete duplicates from hierarchy of lists

text: Is it possible for _Mathematica_ to compare a number of lists of different sizes, and delete duplicates in a hierarchical manner? For example, given the following lists:               list1 = {2, 5, 10, 11, 12, 17, 18};     list2 = {5, 8, 11, 16, 19, 21};     list3 = {5, 8, 9, 11, 16, 19, 21, 23};      I would like to output:               list1 = {2, 5, 10, 11, 12, 17, 18}     list2 = {8, 16, 19, 21}     list3 = {9, 23}      where `list1` keeps all its original elements, `list2` keeps only elements belonging to `list2` and not `list1`, and `list3` keeps only those elements not contained in `lists 1 & 2`. If this will take an inordinately long time, I am happy with just comparing the list with the previous list and deleting the duplicates from the second list.


title: DeleteDuplicates[] does not work as expected on floating point values

text: Here is my simple example, and in this case function `DeleteDuplicates` does not work as expected. I want to `FindRoot` of my function $\chi[\nu]$, and since function $\chi$ is very sensitive to initial guess I decided to generate many initial conditions and leave only those solutions which are distinct. For this purpose I want to apply `DeleteDuplicates` on the resulting list of solution. Here is the definition of my function:               χ[ν_] := 2*PolyGamma[1] - PolyGamma[1/2 + I*ν] - PolyGamma[1/2 - I*ν]      Here I generate many solution according to many random initial guesses               m = Table[v /. FindRoot[χ[v] == -1.2 - 0.2*I, {v, RandomComplex[]}], {i, 1, 10}]      And finally, I want to leave only distinct solutions:               DeleteDuplicates[m]      Unfortunately, the operation `DeleteDuplicates[m]` does not change the list `m`, although there are many identical values. Namely:               DeleteDuplicates[m]      > >     {1.06423 + 0.0968739 I, 1.06423 + 0.0968739 I, >      1.06423 + 0.0968739 I, 1.06423 + 0.0968739 I, 0.0250407 + 1.00352 I, >      1.06423 + 0.0968739 I, 1.06423 + 0.0968739 I, 1.06423 + 0.0968739 I, >      0.0250407 + 1.00352 I, 1.06423 + 0.0968739 I} >   I'm puzzled. Any help or suggestions are very welcome! Thanks!


title: Additive SparseArray Assembly

text: The goal is to assemble a `SparseArray` in an additive fashion. Let us assume we have a large `List` of indices (some will be repeated). We generate a simple test list of indices and values               ind = RandomInteger[{1, 4}, {10, 2}];     val = RandomReal[{-1,1}, Length[ind]];      where each value corresponds to an index from `ind`. I would like to build a `SparseArray` in a way such that the repeated index values are summed into the array. If we simply use:               SparseArray[ind -> val, {4,4}]      only the first index encounter is written into the `SparseArray`, all repeated indices are ignored. **Current Solution (slow + ugly)** This solution is slow and is only shown to make precise what exactly I am trying to accomplish. We pre-allocate a sparse array of the correct size and use `Do` to accumulate the values at each index:               n = 5;     ind = RandomInteger[{1, n}, {3*n, 2}];     val = RandomReal[{1, 1}, Length[ind]];     A = SparseArray[{1, 1} -> 0, {n, n}];     Do[        A[[Sequence @@ ind[[i]]]] += val[[i]]     ,{i, 1, Length[val]}     ]      There are some great tips on working with `SparseArrays` in Efficient by- element updates to SparseArrays and SparseArray row operations. A clever combination of `GatherBy`, `Sort`, etc. operations on `ind` and `val` may be good path to head down. I just can't see it yet.


title: Closed form for convolutions of random variables

text: Is it possible to get Mathematica (9) to calculate PDF's for combined distributions? I can't seem to find the right notation, if this is possible at all. My attempts:               PDF[NormalDistribution[0, 1] + NormalDistribution[0, 1], x]      Nor can we store a distribution to a variable:               z \[Distributed] NormalDistribution[0, 1]     PDF[z, x]


title: Conditional Table

text: I have following :               SeedRandom[2]     Table[Table[RandomInteger[100, {100, 10}][[r, s]] == x[r + s], {r, 1, 10}], {s,1,10}]      How can I set condition inside Tables?Such as if `r>s` set 40 times of `x` value?Or something like this ?I want to have many of those conditions inside two tables? Any suggestion for using other commands?


title: Handling vector comparisons in "Piecewise" function

text: Is it possible for the Piecewise function to process a vector comparison? For example, my input vector is               x={0,1,2,3,4}      I would like to define a function that gives me x^2 if x<3.5, and x+3 otherwise. i.e. I would like my output to be {0,1,4,9,7}. Here I define a function:               myfunc[x_] := Piecewise[{{x^2,x<3.5},{x+3,x>=3.5}}]      which obviously does not work. Is there a way to let Mathematica know that I want to compare x with 3.5 elementwise and apply that particular value to the segment as appropriate? I'm used to R programming where I can use the ifelse function for this job, but I'm relatively new to Mathematica and don't know if this is possible. Thanks!


title: Plotting a 2-D shape given its border points

text: I have the border points of a 2-D body and wish to fill its interior with a solid color. Let us say I have $N$ such points stacked in the $N \times 2$ matrix $A$ so that the first column indicates the $x$ co-ordinates and the second column denotes the corresponding $y$ co-ordinates.


title: How to compile effectively?

text: What are the best practices of compiling functions? I understand that this is a vague question, but let me list some aspects that might trigger useful answers. Some of these have already been answered (these don't need answers) but I included them for sake of clarity and completeness:   1. Which functions are allowed in `Compile` (see these lists: functions, distributions)?   2. There are structures which are not allowed by the _Mathematica_ virtual machine, e.g. boolean tensors are not supported (see this question, particularly Oleksandr's comment). Are there other disallowed objects?   3. Which operations should be left for the main evaluation to do? (e.g. `x = x + c1[y]` or `x = c2[x, y]`, where the compiled function `c2` contains the addition inside).   4. Which practice is better: partition a large computation into smaller compiled functions, or wrap the whole into one big function? What factors should be considered when making a decision? One such factor is for example that a large compiled function cannot easily return intermediate values (at least it is not trivial how to do this, see this post, and perhaps it also decreases performance).   5. Type-conversions: `Compile` silently converts `Integer`/`Real` input to the appropriate type, and it also packs non packed arrays, but I'm not sure what the cost of it is. Is it efficient/safe to leave the compiler to deal with type-conversions?   6. How to call for custom functions in the compiled code? This involves calls for external user functions, recursive calls (perhaps recursive calls passing arguments by reference), or directly injecting code into a held `Compile`.   7. Anything else...? As I'm in the process of understanding `Compile`, I have a very basic understanding at the moment. Please feel free to add any knowledge to this post.


title: Why to do parentheses change the results of a calculation?

text: I'm getting results that are sensitive to where I place parentheses with respect to operations that are associative1 (and should thus be insensitive to such placement). For example, if I define2               << Units`; << PhysicalConstants`;     stellarDayTextbook = 1/(1/Day + 1/Convert[SiderealYear, Day])      and then calculate               1/stellarDayTextbook - 1/Day - 1/Convert[SiderealYear, Day]      I get precisely zero, as expected. But if I add parentheses               (1/stellarDayTextbook - 1/Day) - 1/Convert[SiderealYear, Day]      I get               -(3.03577*10^-17/Day)      What's causing this? * * * 1. Remember, this isn't C, it's math: "subtraction" of $x$ is just the addition of $-x$. Check `TreeForm`. 2. I realize this isn't the definition of a "stellar day", but merely a textbook approximation. The distinction is not material to the question.


title: Cut and paste data from a spreadsheet

text: I have a set of data points in two columns in a spreadsheet (OpenOffice Calc): ![enter image description here](http://i.stack.imgur.com/IPNz9.png) I would like to get these into _Mathematica_ in this format:               data = {{1, 3.3}, {2, 5.6}, {3, 7.1}, {4, 11.4}, {5, 14.8}, {6, 18.3}}      I have Googled for this, but what I find is about importing the entire document, which seems like overkill. Is there a way to kind of cut and paste those two columns into _Mathematica_?


title: Using results of Reduce

text: Suppose I have function f:               f[x_, y_] := 50000 + x 30000 + y 35000;      Now I want to find the x and y when f[]<=200000. I use Reduce:               Reduce[f[x, y] <= 200000 && 1 <= x <= 8 && 1 <= y <= 8 , {x,y}, Integers]      The result is:               (x == 1 && y == 1) || (x == 1 && y == 2) || (x == 1 && y == 3) ||      (x == 2 && y == 1) || (x == 2 && y == 2) || (x == 3 && y == 1)      Now I would like to use these results back into f[] but it requires formatting. I use:               results = Reduce[f[x, y] <= 200000 && 1 <= x <= 8 && 1 <= y <= 8,                 {x, y},Integers] /.                   Or[a__, b__] -> {a, b} /.                    And[a_ == c_, b_ == d_] -> {c, d}      And I use:               f[#[[1]], #[[2]]] & /@ results      to get:               {115000, 150000, 185000, 145000, 180000, 175000}      I wonder if this is the right way to do this or if it can be done easier. It seems reduce can generate different (depending on the equations of course) formats of the results and this would mean that for every type of result new rules will be needed. Is this a fact of life?


title: Day of the week vs time on BoxWhiskerChart

text: I am completely stuck on how to approach this problem: I'm basically trying to figure out when is the best time to tweet on twitter, based on a list of timestamps: Here are the raw values:               {2012-02-15 11:58:38 -0500,2012-02-14 20:18:03 -0500,2012-02-14 15:59:18 -0500,2012-02-14 15:46:30 -0500,2012-02-14 15:44:11 -0500,2012-02-14 15:34:23 -0500,2012-02-14 13:14:45 -0500,2012-02-14 12:09:18 -0500,2012-02-14 11:44:13 -0500,2012-02-13 21:30:05 -0500,2012-02-13 17:12:31 -0500,2012-02-13 17:12:11 -0500,2012-02-13 13:03:09 -0500,2012-02-12 23:34:37 -0500,2012-02-12 23:30:04 -0500,2012-02-12 23:22:53 -0500,2012-02-12 12:56:40 -0500,2012-02-11 14:52:10 -0500,2012-02-10 20:08:30 -0500,2012-02-10 16:24:57 -0500,2012-02-09 16:34:40 -0500,2012-02-09 12:41:37 -0500,2012-02-09 12:41:04 -0500,2012-02-09 11:07:45 -0500,2012-02-09 11:06:29 -0500,2012-02-09 09:53:11 -0500,2012-02-09 09:51:12 -0500,2012-02-09 07:31:04 -0500,2012-02-08 20:38:18 -0500,2012-02-08 19:39:10 -0500,2012-02-08 19:16:42 -0500,2012-02-08 18:54:37 -0500,2012-02-08 18:00:31 -0500,2012-02-07 20:25:14 -0500,2012-02-07 17:36:19 -0500,2012-02-07 16:54:37 -0500,2012-02-07 14:32:31 -0500,2012-02-07 13:53:10 -0500,2012-02-07 13:31:14 -0500,2012-02-07 12:22:51 -0500,2012-02-07 12:21:57 -0500,2012-02-07 11:12:31 -0500,2012-02-06 17:56:32 -0500,2012-02-05 20:29:34 -0500,2012-02-05 10:05:09 -0500,2012-02-04 17:05:16 -0500,2012-02-03 19:34:13 -0500,2012-02-03 15:36:14 -0500,2012-02-03 14:21:04 -0500,2012-02-03 12:25:53 -0500,2012-02-03 00:44:51 -0500,2012-02-03 00:37:29 -0500,2012-02-02 16:39:31 -0500,2012-02-02 16:38:39 -0500,2012-01-29 13:23:25 -0500,2012-01-28 18:55:28 -0500,2012-01-26 13:13:43 -0500,2012-01-26 11:42:41 -0500,2012-01-26 08:58:36 -0500,2012-01-26 07:42:36 -0500,2012-01-25 22:51:27 -0500,2012-01-25 22:51:27 -0500,2012-01-25 20:43:29 -0500,2012-01-25 20:12:00 -0500,2012-01-25 20:11:28 -0500,2012-01-25 20:11:28 -0500,2012-01-25 18:47:40 -0500,2012-01-25 17:01:58 -0500,2012-01-25 17:01:18 -0500,2012-01-25 15:27:57 -0500,2012-01-25 13:00:05 -0500,2012-01-25 12:54:50 -0500,2012-01-25 12:33:31 -0500,2012-01-25 11:08:38 -0500,2012-01-25 00:29:32 -0500,2012-01-24 20:17:27 -0500,2012-01-24 16:23:31 -0500,2012-01-24 16:23:31 -0500,2012-01-24 12:12:50 -0500,2012-01-24 11:19:45 -0500,2012-01-23 21:00:46 -0500,2012-01-23 18:52:58 -0500,2012-01-22 20:28:58 -0500,2012-01-22 16:33:37 -0500,2012-01-21 22:03:11 -0500,2012-01-21 16:08:24 -0500,2012-01-20 21:34:39 -0500,2012-01-20 10:25:51 -0500,2012-01-19 21:03:46 -0500,2012-01-19 21:03:46 -0500,2012-01-18 23:44:54 -0500,2012-01-18 19:56:17 -0500,2012-01-18 19:55:32 -0500,2012-01-18 13:05:58 -0500,2012-01-17 19:58:55 -0500,2012-01-17 19:55:15 -0500,2012-01-17 19:02:29 -0500,2012-01-17 18:53:18 -0500,2012-01-14 18:43:48 -0500,2012-01-13 10:26:19 -0500,2012-01-12 13:40:40 -0500,2012-01-09 17:37:17 -0500,2012-01-07 16:34:57 -0500,2012-01-07 16:32:02 -0500,2012-01-07 14:00:37 -0500,2012-01-07 13:22:10 -0500,2012-01-06 17:51:10 -0500,2012-01-05 21:38:14 -0500,2012-01-05 20:47:39 -0500,2012-01-05 15:48:12 -0500,2012-01-04 22:23:46 -0500,2011-12-27 00:14:42 -0500,2011-12-19 15:09:40 -0500,2011-12-19 10:43:57 -0500,2011-12-15 20:34:51 -0500,2011-12-07 12:27:24 -0500,2011-12-06 19:30:24 -0500,2011-12-06 19:28:55 -0500,2011-12-06 00:25:02 -0500,2011-12-05 22:41:22 -0500,2011-12-02 12:09:20 -0500,2011-12-01 17:38:05 -0500,2011-12-01 17:23:27 -0500,2011-12-01 12:03:03 -0500,2011-11-30 00:46:32 -0500,2011-11-29 23:27:49 -0500,2011-11-29 23:27:00 -0500,2011-11-29 22:04:02 -0500,2011-11-29 16:14:55 -0500,2011-11-29 12:41:53 -0500,2011-11-25 19:26:40 -0500,2011-11-18 16:57:25 -0500,2011-11-18 11:39:16 -0500,2011-11-17 14:03:08 -0500,2011-11-15 19:42:14 -0500,2011-11-15 10:25:33 -0500,2011-11-14 15:01:43 -0500,2011-11-14 14:58:02 -0500,2011-11-11 17:00:57 -0500,2011-11-11 11:53:42 -0500,2011-11-09 00:23:44 -0500,2011-11-08 16:44:13 -0500,2011-11-08 16:04:56 -0500,2011-11-08 15:52:51 -0500,2011-11-08 15:34:00 -0500,2011-11-08 15:17:47 -0500,2011-11-06 17:05:51 -0500,2011-11-02 17:34:12 -0400,2011-11-02 15:51:16 -0400,2011-11-02 15:43:52 -0400,2011-10-29 17:30:45 -0400,2011-10-28 11:53:05 -0400,2011-10-27 14:39:18 -0400,2011-10-27 09:41:25 -0400,2011-10-27 07:57:52 -0400,2011-10-25 18:40:57 -0400,2011-10-25 18:13:56 -0400,2011-10-21 09:58:03 -0400,2011-10-20 23:18:37 -0400,2011-10-18 13:48:37 -0400,2011-10-18 13:39:08 -0400,2011-10-16 16:47:01 -0400,2011-10-14 22:09:44 -0400,2011-10-14 11:19:29 -0400,2011-10-14 09:59:44 -0400,2011-10-14 09:59:43 -0400,2011-10-14 07:38:01 -0400,2011-10-13 19:33:15 -0400,2011-10-13 16:07:06 -0400,2011-10-13 16:01:53 -0400,2011-10-11 14:46:15 -0400,2011-10-07 11:14:26 -0400,2011-10-07 09:57:19 -0400,2011-10-07 09:55:37 -0400,2011-10-07 09:49:49 -0400,2011-10-07 08:32:01 -0400,2011-10-07 08:06:20 -0400,2011-10-07 01:47:19 -0400,2011-10-06 20:59:52 -0400,2011-10-06 17:18:06 -0400,2011-10-06 17:02:57 -0400,2011-10-05 23:41:20 -0400,2011-10-05 23:34:18 -0400,2011-10-05 23:33:34 -0400,2011-10-04 18:01:30 -0400,2011-10-04 14:54:11 -0400,2011-10-04 13:27:48 -0400,2011-10-04 13:26:40 -0400,2011-10-04 13:22:45 -0400,2011-10-04 13:21:20 -0400,2011-10-04 13:09:04 -0400,2011-10-01 02:05:42 -0400,2011-09-30 20:41:54 -0400,2011-09-29 01:42:44 -0400,2011-09-28 17:20:14 -0400,2011-09-25 17:41:25 -0400,2011-09-25 16:25:20 -0400,2011-09-25 16:23:48 -0400,2011-09-25 16:23:17 -0400,2011-09-25 16:22:35 -0400}      I think it'll be best to have x-axis as the "days of the week", and the y axis as time. So I `GatherBy` the above here:               {{{Wednesday,11:58:38},{Wednesday,20:38:18},{Wednesday,19:39:10},{Wednesday,19:16:42},{Wednesday,18:54:37},{Wednesday,18:00:31},{Wednesday,22:51:27},{Wednesday,22:51:27},{Wednesday,20:43:29},{Wednesday,20:12:00},{Wednesday,20:11:28},{Wednesday,20:11:28},{Wednesday,18:47:40},{Wednesday,17:01:58},{Wednesday,17:01:18},{Wednesday,15:27:57},{Wednesday,13:00:05},{Wednesday,12:54:50},{Wednesday,12:33:31},{Wednesday,11:08:38},{Wednesday,00:29:32},{Wednesday,23:44:54},{Wednesday,19:56:17},{Wednesday,19:55:32},{Wednesday,13:05:58},{Wednesday,22:23:46},{Wednesday,12:27:24},{Wednesday,00:46:32},{Wednesday,00:23:44},{Wednesday,17:34:12},{Wednesday,15:51:16},{Wednesday,15:43:52},{Wednesday,23:41:20},{Wednesday,23:34:18},{Wednesday,23:33:34},{Wednesday,17:20:14}},{{Tuesday,20:18:03},{Tuesday,15:59:18},{Tuesday,15:46:30},{Tuesday,15:44:11},{Tuesday,15:34:23},{Tuesday,13:14:45},{Tuesday,12:09:18},{Tuesday,11:44:13},{Tuesday,20:25:14},{Tuesday,17:36:19},{Tuesday,16:54:37},{Tuesday,14:32:31},{Tuesday,13:53:10},{Tuesday,13:31:14},{Tuesday,12:22:51},{Tuesday,12:21:57},{Tuesday,11:12:31},{Tuesday,20:17:27},{Tuesday,16:23:31},{Tuesday,16:23:31},{Tuesday,12:12:50},{Tuesday,11:19:45},{Tuesday,19:58:55},{Tuesday,19:55:15},{Tuesday,19:02:29},{Tuesday,18:53:18},{Tuesday,00:14:42},{Tuesday,19:30:24},{Tuesday,19:28:55},{Tuesday,00:25:02},{Tuesday,23:27:49},{Tuesday,23:27:00},{Tuesday,22:04:02},{Tuesday,16:14:55},{Tuesday,12:41:53},{Tuesday,19:42:14},{Tuesday,10:25:33},{Tuesday,16:44:13},{Tuesday,16:04:56},{Tuesday,15:52:51},{Tuesday,15:34:00},{Tuesday,15:17:47},{Tuesday,18:40:57},{Tuesday,18:13:56},{Tuesday,13:48:37},{Tuesday,13:39:08},{Tuesday,14:46:15},{Tuesday,18:01:30},{Tuesday,14:54:11},{Tuesday,13:27:48},{Tuesday,13:26:40},{Tuesday,13:22:45},{Tuesday,13:21:20},{Tuesday,13:09:04}},{{Monday,21:30:05},{Monday,17:12:31},{Monday,17:12:11},{Monday,13:03:09},{Monday,17:56:32},{Monday,21:00:46},{Monday,18:52:58},{Monday,17:37:17},{Monday,15:09:40},{Monday,10:43:57},{Monday,22:41:22},{Monday,15:01:43},{Monday,14:58:02}},{{Sunday,23:34:37},{Sunday,23:30:04},{Sunday,23:22:53},{Sunday,12:56:40},{Sunday,20:29:34},{Sunday,10:05:09},{Sunday,13:23:25},{Sunday,20:28:58},{Sunday,16:33:37},{Sunday,17:05:51},{Sunday,16:47:01},{Sunday,17:41:25},{Sunday,16:25:20},{Sunday,16:23:48},{Sunday,16:23:17},{Sunday,16:22:35}},{{Saturday,14:52:10},{Saturday,17:05:16},{Saturday,18:55:28},{Saturday,22:03:11},{Saturday,16:08:24},{Saturday,18:43:48},{Saturday,16:34:57},{Saturday,16:32:02},{Saturday,14:00:37},{Saturday,13:22:10},{Saturday,17:30:45},{Saturday,02:05:42}},{{Friday,20:08:30},{Friday,16:24:57},{Friday,19:34:13},{Friday,15:36:14},{Friday,14:21:04},{Friday,12:25:53},{Friday,00:44:51},{Friday,00:37:29},{Friday,21:34:39},{Friday,10:25:51},{Friday,10:26:19},{Friday,17:51:10},{Friday,12:09:20},{Friday,19:26:40},{Friday,16:57:25},{Friday,11:39:16},{Friday,17:00:57},{Friday,11:53:42},{Friday,11:53:05},{Friday,09:58:03},{Friday,22:09:44},{Friday,11:19:29},{Friday,09:59:44},{Friday,09:59:43},{Friday,07:38:01},{Friday,11:14:26},{Friday,09:57:19},{Friday,09:55:37},{Friday,09:49:49},{Friday,08:32:01},{Friday,08:06:20},{Friday,01:47:19},{Friday,20:41:54}},{{Thursday,16:34:40},{Thursday,12:41:37},{Thursday,12:41:04},{Thursday,11:07:45},{Thursday,11:06:29},{Thursday,09:53:11},{Thursday,09:51:12},{Thursday,07:31:04},{Thursday,16:39:31},{Thursday,16:38:39},{Thursday,13:13:43},{Thursday,11:42:41},{Thursday,08:58:36},{Thursday,07:42:36},{Thursday,21:03:46},{Thursday,21:03:46},{Thursday,13:40:40},{Thursday,21:38:14},{Thursday,20:47:39},{Thursday,15:48:12},{Thursday,20:34:51},{Thursday,17:38:05},{Thursday,17:23:27},{Thursday,12:03:03},{Thursday,14:03:08},{Thursday,14:39:18},{Thursday,09:41:25},{Thursday,07:57:52},{Thursday,23:18:37},{Thursday,19:33:15},{Thursday,16:07:06},{Thursday,16:01:53},{Thursday,20:59:52},{Thursday,17:18:06},{Thursday,17:02:57},{Thursday,01:42:44}}}      From here I'm stuck on how to actually display this onto a chart (preferably, `BoxWhiskerChart`) ### Input Form:               {{{"Wednesday", "11:58:38"}, {"Wednesday", "20:38:18"}, {"Wednesday",         "19:39:10"}, {"Wednesday", "19:16:42"}, {"Wednesday",         "18:54:37"}, {"Wednesday", "18:00:31"}, {"Wednesday",         "22:51:27"}, {"Wednesday", "22:51:27"}, {"Wednesday",         "20:43:29"}, {"Wednesday", "20:12:00"}, {"Wednesday",         "20:11:28"}, {"Wednesday", "20:11:28"}, {"Wednesday",         "18:47:40"}, {"Wednesday", "17:01:58"}, {"Wednesday",         "17:01:18"}, {"Wednesday", "15:27:57"}, {"Wednesday",         "13:00:05"}, {"Wednesday", "12:54:50"}, {"Wednesday",         "12:33:31"}, {"Wednesday", "11:08:38"}, {"Wednesday",         "00:29:32"}, {"Wednesday", "23:44:54"}, {"Wednesday",         "19:56:17"}, {"Wednesday", "19:55:32"}, {"Wednesday",         "13:05:58"}, {"Wednesday", "22:23:46"}, {"Wednesday",         "12:27:24"}, {"Wednesday", "00:46:32"}, {"Wednesday",         "00:23:44"}, {"Wednesday", "17:34:12"}, {"Wednesday",         "15:51:16"}, {"Wednesday", "15:43:52"}, {"Wednesday",         "23:41:20"}, {"Wednesday", "23:34:18"}, {"Wednesday",         "23:33:34"}, {"Wednesday", "17:20:14"}}, {{"Tuesday",         "20:18:03"}, {"Tuesday", "15:59:18"}, {"Tuesday",         "15:46:30"}, {"Tuesday", "15:44:11"}, {"Tuesday",         "15:34:23"}, {"Tuesday", "13:14:45"}, {"Tuesday",         "12:09:18"}, {"Tuesday", "11:44:13"}, {"Tuesday",         "20:25:14"}, {"Tuesday", "17:36:19"}, {"Tuesday",         "16:54:37"}, {"Tuesday", "14:32:31"}, {"Tuesday",         "13:53:10"}, {"Tuesday", "13:31:14"}, {"Tuesday",         "12:22:51"}, {"Tuesday", "12:21:57"}, {"Tuesday",         "11:12:31"}, {"Tuesday", "20:17:27"}, {"Tuesday",         "16:23:31"}, {"Tuesday", "16:23:31"}, {"Tuesday",         "12:12:50"}, {"Tuesday", "11:19:45"}, {"Tuesday",         "19:58:55"}, {"Tuesday", "19:55:15"}, {"Tuesday",         "19:02:29"}, {"Tuesday", "18:53:18"}, {"Tuesday",         "00:14:42"}, {"Tuesday", "19:30:24"}, {"Tuesday",         "19:28:55"}, {"Tuesday", "00:25:02"}, {"Tuesday",         "23:27:49"}, {"Tuesday", "23:27:00"}, {"Tuesday",         "22:04:02"}, {"Tuesday", "16:14:55"}, {"Tuesday",         "12:41:53"}, {"Tuesday", "19:42:14"}, {"Tuesday",         "10:25:33"}, {"Tuesday", "16:44:13"}, {"Tuesday",         "16:04:56"}, {"Tuesday", "15:52:51"}, {"Tuesday",         "15:34:00"}, {"Tuesday", "15:17:47"}, {"Tuesday",         "18:40:57"}, {"Tuesday", "18:13:56"}, {"Tuesday",         "13:48:37"}, {"Tuesday", "13:39:08"}, {"Tuesday",         "14:46:15"}, {"Tuesday", "18:01:30"}, {"Tuesday",         "14:54:11"}, {"Tuesday", "13:27:48"}, {"Tuesday",         "13:26:40"}, {"Tuesday", "13:22:45"}, {"Tuesday",         "13:21:20"}, {"Tuesday", "13:09:04"}}, {{"Monday",         "21:30:05"}, {"Monday", "17:12:31"}, {"Monday",         "17:12:11"}, {"Monday", "13:03:09"}, {"Monday",         "17:56:32"}, {"Monday", "21:00:46"}, {"Monday",         "18:52:58"}, {"Monday", "17:37:17"}, {"Monday",         "15:09:40"}, {"Monday", "10:43:57"}, {"Monday",         "22:41:22"}, {"Monday", "15:01:43"}, {"Monday",         "14:58:02"}}, {{"Sunday", "23:34:37"}, {"Sunday",         "23:30:04"}, {"Sunday", "23:22:53"}, {"Sunday",         "12:56:40"}, {"Sunday", "20:29:34"}, {"Sunday",         "10:05:09"}, {"Sunday", "13:23:25"}, {"Sunday",         "20:28:58"}, {"Sunday", "16:33:37"}, {"Sunday",         "17:05:51"}, {"Sunday", "16:47:01"}, {"Sunday",         "17:41:25"}, {"Sunday", "16:25:20"}, {"Sunday",         "16:23:48"}, {"Sunday", "16:23:17"}, {"Sunday",         "16:22:35"}}, {{"Saturday", "14:52:10"}, {"Saturday",         "17:05:16"}, {"Saturday", "18:55:28"}, {"Saturday",         "22:03:11"}, {"Saturday", "16:08:24"}, {"Saturday",         "18:43:48"}, {"Saturday", "16:34:57"}, {"Saturday",         "16:32:02"}, {"Saturday", "14:00:37"}, {"Saturday",         "13:22:10"}, {"Saturday", "17:30:45"}, {"Saturday",         "02:05:42"}}, {{"Friday", "20:08:30"}, {"Friday",         "16:24:57"}, {"Friday", "19:34:13"}, {"Friday",         "15:36:14"}, {"Friday", "14:21:04"}, {"Friday",         "12:25:53"}, {"Friday", "00:44:51"}, {"Friday",         "00:37:29"}, {"Friday", "21:34:39"}, {"Friday",         "10:25:51"}, {"Friday", "10:26:19"}, {"Friday",         "17:51:10"}, {"Friday", "12:09:20"}, {"Friday",         "19:26:40"}, {"Friday", "16:57:25"}, {"Friday",         "11:39:16"}, {"Friday", "17:00:57"}, {"Friday",         "11:53:42"}, {"Friday", "11:53:05"}, {"Friday",         "09:58:03"}, {"Friday", "22:09:44"}, {"Friday",         "11:19:29"}, {"Friday", "09:59:44"}, {"Friday",         "09:59:43"}, {"Friday", "07:38:01"}, {"Friday",         "11:14:26"}, {"Friday", "09:57:19"}, {"Friday",         "09:55:37"}, {"Friday", "09:49:49"}, {"Friday",         "08:32:01"}, {"Friday", "08:06:20"}, {"Friday",         "01:47:19"}, {"Friday", "20:41:54"}}, {{"Thursday",         "16:34:40"}, {"Thursday", "12:41:37"}, {"Thursday",         "12:41:04"}, {"Thursday", "11:07:45"}, {"Thursday",         "11:06:29"}, {"Thursday", "09:53:11"}, {"Thursday",         "09:51:12"}, {"Thursday", "07:31:04"}, {"Thursday",         "16:39:31"}, {"Thursday", "16:38:39"}, {"Thursday",         "13:13:43"}, {"Thursday", "11:42:41"}, {"Thursday",         "08:58:36"}, {"Thursday", "07:42:36"}, {"Thursday",         "21:03:46"}, {"Thursday", "21:03:46"}, {"Thursday",         "13:40:40"}, {"Thursday", "21:38:14"}, {"Thursday",         "20:47:39"}, {"Thursday", "15:48:12"}, {"Thursday",         "20:34:51"}, {"Thursday", "17:38:05"}, {"Thursday",         "17:23:27"}, {"Thursday", "12:03:03"}, {"Thursday",         "14:03:08"}, {"Thursday", "14:39:18"}, {"Thursday",         "09:41:25"}, {"Thursday", "07:57:52"}, {"Thursday",         "23:18:37"}, {"Thursday", "19:33:15"}, {"Thursday",         "16:07:06"}, {"Thursday", "16:01:53"}, {"Thursday",         "20:59:52"}, {"Thursday", "17:18:06"}, {"Thursday",         "17:02:57"}, {"Thursday", "01:42:44"}}}


title: ParametricPlot3D output without the meshlines

text: Caveat: Mathematica version 3.0. if (or when) it matters. I define a 3D-object with ParametricPlot3D, say, the following:               tube=ParametricPlot3D[2{Cos[t],Sin[t],u},{t,0,2Pi},{u,-5,5}]      This is rendered just fine, I can save and use it (in eps-format) in my TeX- docs just fine. But the surface is kinda crowded with the meshlines, and I want to draw my students attention to the curves I draw on this surface anyway. Therefore the meshlines are a nuisance and must go. But how to render this without them? Listing some options...   1. RTFM. Searching in the help gives promising hits such as EdgeForm[], Mesh->None et cetera, but none seem to work with ParametricPlot3D. I tried to print _tube_ using FullForm in order to strip the Graphics3D-header, and insert an EdgeForm[] at the beginning, but something went wrong, and I'm not experienced enough Mathematica user to really figure that out.   2. Look from Wolfram's on-line help. It lists _Mesh->None_ as an option of ParametricPlot3D, but that must (?) refer to a newer version, as it didn't work with mine.   3. Do it yourself! I like to think I'm enough of a programmer to build the required list of polygons myself, and insert the EdgeForm[]-command there. But this is a lot of work, and I'm kinda in a hurry.   4. Upgrade? I work at a Uni. I could get to use a departmental license for an upgraded version. But then I would be behind the license-daemon, couldn't easily use it at home et cetera. That's the charm of the old license for version 3.0, when all you had to do was to inser your activation code (or whatever).


title: How can I suppress Print in parallel evaluation?

text: When using a function that includes `Print` statements, one can suppress the output by `Print; Unprotect[Print]; Print = Null &` This doesn't work when the function is evaluated in `ParallelTable[function[i],{i,1,10}]` Is there a way to do that? Thank you!


title: How to control the page size when exporting as a PDF?

text: When I used Mathematica under Windows, I could control the page size of the pdf files created by `Export[...,"PDF"]` by setting the paper size in the print menu to the desired size before executing the `Export` command. In particular, I would set the paper size to `Ledger`, and when I opened the resulting files in Acrobat the page size would be listed as 10.83 x 16.83 in. Now, I'm using Mathematica under Mac OS X, and this trick doesn't work. Is there some option for `Export[...,"PDF"]` that allows me to control the PDF page size of the output directly? **Update** The item I'm exporting is of the form `CreateDocument[{item1,item2}]`, where item2 is a `GraphicsGrid` that contains `ImageSize` information. Unfortunately, when that information gets wrapped inside `CreateDocument`, `Export[...,"PDF"]` seems to ignore it when setting the PDF page size.


title: Syntax Coloring for "Possible Unwanted Assignment" Issue

text: Apparently Mathematica's syntax coloring engine believes that the second assignment in the following code excerpt (concocted for illustration purposes only) is a "Possible Unwanted Assignment" since unchecking this box in Preferences causes the red highlighting to disappear: ![enter image description here](http://i.stack.imgur.com/37FIf.png) Any ideas why Mathematica should believe that this assignment is possibly unwanted? The variable `b` is used after all in the test conditional for the `While` loop whereas `f` and `g` are not.


title: Why does setting $Assumptions make my Fourier transforms slow?

text: Consider these Fourier transforms               FourierTransform[Exp[-I ω0 t] (Exp[-(t)^2]), t, ω]; // AbsoluteTiming     FourierTransform[Exp[-I ω0 t] (Exp[-(t/T0)^2]), t, ω]; // AbsoluteTiming     FourierTransform[Exp[-I ω0 t] (Exp[-((t + τ)/T0)^2]), t, ω]; // AbsoluteTiming     FourierTransform[Exp[-I ω0 t] (Exp[-((t - τ)/T0)^2] + Exp[-((t + τ)/T0)^2]), t, ω]; // AbsoluteTiming          (*{0.022893,Null}*)     (*{0.167016,Null}*)     (*{0.051487,Null}*)     (*{0.183451,Null}*)      It's pretty fast, but if I setting the assumption, then it becomes much slower               $Assumptions = T0 > 0 && ω0 > 0 && τ > 0;          FourierTransform[Exp[-I ω0 t] (Exp[-(t)^2]), t, ω]; // AbsoluteTiming     FourierTransform[Exp[-I ω0 t] (Exp[-(t/T0)^2]), t, ω]; // AbsoluteTiming     FourierTransform[Exp[-I ω0 t] (Exp[-((t + τ)/T0)^2]), t, ω]; // AbsoluteTiming     FourierTransform[Exp[-I ω0 t] (Exp[-((t - τ)/T0)^2] + Exp[-((t + τ)/T0)^2]), t, ω]; // AbsoluteTiming          (*{0.018221,Null}*)     (*{6.465289,Null}*)     (*{9.765310,Null}*)     (*{48.956260,Null}*)      Why does the performance decrease a lot? And is there a way to use the global assumption while maintain the performance?


title: Evaluate function from a table

text: I want to define list of functions and also use them for evaluation. But this just doesn't work. For example               f=Table[0,{i,3}]     f[[1]]=x^2     f[[2]]=x^3     f[[3]]=f[[1]]*f[[2]]      So far, fine, because f[[3]] is in fact x^5. Let's say I also need value of second function at $x=2$. However `f[[2]][2]` does not return `8`.


title: How do I find where the maximum is?

text: I have a function given by:               f[x_, y_, J1_, J2_] :=        1/2916 (4          (3 - 3 J1^2 Cos[x]^2 + 3 Cos[x] Cos[Sqrt[3] y] - (3 + J1 - 2 J2 Sin[x]^2)^2)^3 +          (27 J1 Cos[x] (Cos[x] + Cos[Sqrt[3] y]) +             9 (1 + 2 J1^2 Cos[x]^2 + Cos[x] Cos[Sqrt[3] y]) (3 + J1 - 2 J2 Sin[x]^2) -               2 (3 + J1 - 2 J2 Sin[x]^2)^3)^2)      x and y are the independent variables, and J1 and J2 are two parameters. I tried               Reduce[D[f[x, y, J1, J2], x] == 0 && D[f[x, y, J1, J2], y] == 0 &&        J1 > 0 && J2 > 0, {x, y}, Reals]      to find the extrema. However, it takes forever for _Mathematica_ to give a result.


title: Integrating a Simple Piecewise Function

text: If I define               f[x_]:=If[x<0,-1,1]      and then integrate,say               Integrate[f[x],{x,-3,7}]      I get what I expect, namely 4. But if I do the same thing with a different function               f[x_] := If[x < -1, 1/(2x^2), If[x > 1, 1/(2x^2), 0]]      and if I then integrate               Integrate[f[x], {x, -3, 7}]      I do not, as expected, get 16/21; instead I just get an expression consisting of an integral sign with -3 and 7 at the limits, followed by the definition of f just as I typed it above (with all the If statements, etc) and then a dx. I can of course break the integral into two parts, either of which Mathematica handles perfectly well. But how do I get it to evaluate this expression without my manual intervention?


title: How to faster map density matrix element to make differential equations

text: I have a time dependent matrix $M(t)$ of $L^n \times L^n$ size and want to write differential equations like `D[M[i,j][t],t] = H[i,j][t]` Here is my code:               L=3; n=3;     Rho[t_] = Table[M[i,j][t], {i,L^n}, {j,L^n}]; //Timing(*Rho2[t]//MatrixForm*)     (* {0.00100,Null} *)          Hop[t_, i_] =         Transpose[           Table[If[i == j, 1, Cos[t]], {i, {1}}, {j, L}]]         . Table[If[i == j, 1, Sin[t]], {i, {2}}, {j, L}]          I1[i_Integer] := I1[i]=IdentityMatrix[L^(i-1)];     I2[i_Integer] := I2[i]=IdentityMatrix[L^(n-i)];          H[t_] = Sum[FixedPoint[ArrayFlatten, I1[i] \[TensorProduct] Hop[t,i]          \[TensorProduct]I2[i]],{i,n}];          Rho1[t_] =         Table[             D[Rho[t],t][[i,j]] == H[t][[i,j]],             {i,L^n}, {j,L^n}]; // Timing(*Rho1[t]//MatrixForm*)     (* {0.33500,Null} *)      I can make it faster by using the `Parallel` command:               Rho2[t_] =         ParallelTable[             D[Rho[t],t][[i,j]] == H[t][[i,j]],             {i,L^n}, {j,L^n}]; // Timing(*Rho1[t]//MatrixForm*)     (* {0.08100,Null} *)      Is there any other way by using `Map` or `Transpose` to make it more efficient?


title: Maximum number of literal values for SetDelayed?

text: Under what circumstances should I expect _Mathematica_ to turn a delayed assignment into an immediate assignment? I have put together a minimal example (available here) which demonstrates this behavior. There is a package which contains basically the following, where each line has its own cell in the notebook from which the package is generated:               setMyVar[a] := (var = 1;)     setMyVar[b] := (var = 2;)     setMyVar[c] := (var = 3;)     setMyVar[d] := (var = 4;)     setMyVar[e] := (var = 5;)     setMyVar[f] := (var = 6;)     setMyVar[g] := (var = 7;)     setMyVar[h] := (var = 8;)     setMyVar[i] := (var = 9;)     setMyVar[j] := (var = 10;)     setMyVar[k] := (var = 11;)     setMyVar[l] := (var = 12;)     setMyVar[m] := (var = 13;)     setMyVar[n] := (var = 14;)     setMyVar[o] := (var = 15;)     setMyVar[p] := (var = 16;)     setMyVar[q] := (var = 17;)     setMyVar[r] := (var = 18;)     setMyVar[s] := (var = 19;)     setMyVar[t] := (var = 20;)      When I load this package and then evaluate `Definition[setMyVar]` every assignment is defined as a `Set` rather than a `SetDelayed` in _Mathematica 9.0.0.0_. However if I comment out any three of these, everything returns to being `SetDelayed`. Does anyone have any idea why _Mathematica_ would do this? If so, is there a system variable I can change to address this problem? The tarball also contains a notebook which demonstrates the behavior in a setting which is not loaded from a package. This does not come up if everything is in a single cell, but arranging everything in such a way is not practical for the actual application in which I ran across this. To address why this might be considered to be a problem, I ran across this while using `DistributeDefinitions["Context"]` which as stated in the documentation essentially runs `ParallelEvaluate` on every statement in the context, and this is causing things to be evaluated which should not be. * * * Edit to add: I have confirmed that this occurs with _Mathematica 9.0.1.0_ as well. Both machines tested are Linux x86-64.


title: Finding a better way to define a matrix

text: I first defined a 171x171 matrix containing only zeros and then replaced 18 specific rows with nonzero entries. The other $153$ rows will be average of $2$ of the existing $18$ rows. Rows $2$ through $18$ are the averages of Row $1$ and every other defined row since there are $17$ other rows for Row $1$ to combine with. Now we need to see average of Row $19$ being combined with the $18$ other rows. But the average of Row $19$ and Row $1$ has already been defined since it is also the same as the average of Row $1$ and Row $19$. So Row $19$ only needs to be combined with $16$ other rows. When we wish to see the average of Row $36$ combined with the other defined rows,the average of Row $36$ and Row $1$,and the average of Row $36$ and Row $19$ have already been defined, so there are only $15$ possible remaining rows for Row $36$ to combine with. This pattern continues until every row of the matrix is defined. This matrix is already well defined and there are no errors. The code works but I'm wondering if there is a better and certainly much shorter way to define this matrix with iterative functions such as `Do, Array or Table`. Any feedback, comments, or corrections is greatly appreciated. Thank you.               o = Array[0 &, {171, 171}]          o[[1]] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1, 1,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1, 1, 1, 1, 1, 1, 1,        1, 1, 1, 1, .5, 0, 1, 1, .5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, .5, 0, 1,        1, .5, 1, 1, 1, 1, 1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1, 1, 1, 1, 1,        1, 1, 1, .5, 0, 1, 1, .5, 1, 1, 1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1,        1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1,        1, 1, 1, .5, 0, 1, 1, .5, 1, 1, 1, .5, 0, 1, 1, .5, 1, 1, .5, 0, 1,        1, .5, 1, .5, 0, .5, .5, .25, .5, 0, 0, 0, 0, 0, 1, 1, .5, 1, 1, .5,        1, .5, .5, 1}          o[[19]] = {1, .5, .5, 1, 2, 2, 1, 1, 1, 1, 1, 2, .5, 1, .5, 1, 2,        1, .5, .25, .5, 1, 1, .5, .5, .5, .5, .5, 1, .25, .5, .25, .5,        1, .5, .5, .5, 1, 1, .5, .5, .5, .5, .5, 1, .25, .5, .25, .5, 1, .5,        1, 2, 2, 1, 1, 1, 1, 1, 2, .5, 1, .5, 1, 2, 1, 2, 4, 2, 2, 2, 2, 2,        4, 1, 2, 1, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 1, 2, 1, 2, 4, 2, 1, 1,        1, 1, 1, 2, .5, 1, .5, 1, 2, 1, 1, 1, 1, 1, 2, .5, 1, .5, 1, 2, 1,        1, 1, 1, 2, .5, 1, .5, 1, 2, 1, 1, 1, 2, .5, 1, .5, 1, 2, 1, 1,        2, .5, 1, .5, 1, 2, 1, 2, 1, 2, 1, 2, 4, 2, .5, .5, .25, .5, 1, .5,        1, .5, 1, 2, 1, .5, .5, 1, .5, 1, 2, 1, 2, 2, 1}          o[[36]] = {1, 2, .5, 1, .5, 1, 1, 1, 2, 1, 1, 1, 2, 1, .5, 1, 1, 1, 2,        1, 2, 1, 2, 2, 2, 4, 2, 2, 2, 4, 2, 1, 2, 2,        2, .5, .5, .25, .5, .5, .5, 1, .5, .5, .5, 1, .5, .25, .5, .5, .5,        1, .5, 1, 1, 1, 2, 1, 1, 1, 2, 1, .5, 1, 1, 1, .5, .5, .5, .5,        1, .5, .5, .5, 1, .5, .25, .5, .5, .5, 1, 1, 1, 2, 1, 1, 1, 2,        1, .5, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, .5, 1, 1, 1, 1, 2, 1, 1, 1,        2, 1, .5, 1, 1, 1, 2, 2, 2, 2, 4, 2, 1, 2, 2, 2, 1, 1, 1, 2, 1, .5,        1, 1, 1, 1, 1, 2, 1, .5, 1, 1, 1, 1, 2, 1, .5, 1, 1, 1, 2, 2, 1, 2,        2, 2, 1, .5, 1, 1, 1, .5, .5, .5, .5, 1, 1, 1, 1, 1, 1}          o[[52]] = {1, 1, 2, .5, .5, 1, 1, 1, 0, 2, 1, 1, 1, 1, .5, 1, 1, 1, 1,        2, .5, .5, 1, 1, 1, 0, 2, 1, 1, 1, 1, .5, 1, 1, 1, 2, 1, 1, 2, 2,        2, 0, 4, 2, 2, 2, 2, 1, 2, 2, 2, .5, .25, .5, .5, .5, 0,        1, .5, .5, .5, .5, .25, .5, .5, .5, .5, .5, .5, .5, 0,        1, .5, .5, .5, .5, .25, .5, .5, .5, 1, 1, 1, 0, 2, 1, 1, 1, 1, .5,        1, 1, 1, 1, 1, 0, 2, 1, 1, 1, 1, .5, 1, 1, 1, 1, 0, 2, 1, 1, 1,        1, .5, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 1, 2,        2, 2, 1, 1, 1, 1, .5, 1, 1, 1, 1, 1, 1, .5, 1, 1, 1, 1, 1, .5, 1, 1,        1, 1, .5, 1, 1, 1, .5, .5, .5, .5, 1, 1, 1, 1, 1, 1}          o[[67]] = {1, .5, 2, 1, .5, 1, 1, .5, 2, .5, 1, .5, 2, 1, .5, 1, .5,        1, .5, 1, .5, .25, .5, .5, .25, 1, .25, .5, .25,        1, .5, .25, .5, .25, .5, 2, 2, 1, 2, 2, 1, 4, 1, 2, 1, 4, 2, 1, 2,        1, 2, 1, .5, 1, 1, .5, 2, .5, 1, .5, 2, 1, .5, 1, .5,        1, .5, .5, .5, .25, 1, .25, .5, .25, 1, .5, .25, .5, .25, .5, 1,        1, .5, 2, .5, 1, .5, 2, 1, .5, 1, .5, 1, 1, .5, 2, .5, 1, .5, 2,        1, .5, 1, .5, 1, .5, 1, .25, .5, .25, 1, .5, .25, .5, .25, .5, 2, 1,        2, 1, 4, 2, 1, 2, 1, 2, .5, .5, .25, 1, .5, .25, .5, .25, .5,        1, .5, 2, 1, .5, 1, .5, 1, .5, 1, .5, .25, .5, .25, .5, 2, 2, 1, 2,        1, 2, 1, .5, 1, .5, 1, .5, .5, .25, .5, 1, .5, 1, .5, .5, 1}          o[[81]] = {1, .5, .5, 1, 2, .5, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, .5,        1, .5, .25, .5, 1, .25, .5, .5, 1, 1, .5, .5, .5, .5,        1, .5, .25, .5, .5, .5, 1, .25, .5, .5, 1, 1, .5, .5, .5, .5,        1, .5, .25, .5, 1, 2, .5, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, .5, 1, 2, 1,        2, 2, 4, 4, 2, 2, 2, 2, 4, 2, 1, 2, .5, .5, .5, 1,        1, .5, .5, .5, .5, 1, .5, .25, .5, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, .5,        1, 1, 2, 2, 1, 1, 1, 1, 2, 1, .5, 1, 2, 4, 2, 2, 2, 2, 4, 2, 1, 2,        2, 2, 2, 2, 2, 4, 2, 1, 2, 1, 1, 1, 1, 2, 1, .5, 1, 1, 1, 1, 2,        1, .5, 1, 1, 1, 2, 1, .5, 1, 1, 2, 1, .5, 1, 2, 2, 1, 2, 1, .5,        1, .5, .5, 1}          o[[94]] = {2, 2, 2, 2, 2, 4, 2, 1, 2, 1, 1, 1, 4, 0, 2, 4, 4, 1, 1, 1,        1, 1, 2, 1, .5, 1, .5, .5, .5, 2, 0, 1, 2, 2, .5, 1, 1, 1, 2,        1, .5, 1, .5, .5, .5, 2, 0, 1, 2, 2, .5, 1, 1, 2, 1, .5,        1, .5, .5, .5, 2, 0, 1, 2, 2, .5, 1, 2, 1, .5, 1, .5, .5, .5, 2, 0,        1, 2, 2, .5, 2, 2, 1, 2, 1, 1, 1, 4, 0, 2, 4, 4, 1, 1, .5,        1, .5, .5, .5, 2, 0, 1, 2, 2, .5, .5, .5, .25, .25, .25, 1, 0, .5,        1, 1, .25, 1, .5, .5, .5, 2, 0, 1, 2, 2, .5, .5, .25, .25, 1, 0, .5,        1, 1, .25, .5, .25, 1, 0, .5, 1, 1, .25, .5, 1, 0, .5, 1, 1, .25,        2, 0, 2, 4, 4, 1, 0, 0, 0, 0, 0, 1, 2, 2, .5, 2, 4, 1, 2, 1, .5}          o[[106]] = {1, 1, 1, 1, 2, 1, 1, .5, .5, 1, 1, 1, .5, .5, 1, 1, 0, 2,        1, 1, 1, 2, 1, 1, .5, .5, 1, 1, 1, .5, .5, 1, 1, 0, 2, 1, 1, 2, 1,        1, .5, .5, 1, 1, 1, .5, .5, 1, 1, 0, 2, 1, 2, 1, 1, .5, .5, 1, 1,        1, .5, .5, 1, 1, 0, 2, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 0, 4, 1,        1, .5, .5, 1, 1, 1, .5, .5, 1, 1, 0, 2, 1, .5, .5, 1, 1, 1, .5, .5,        1, 1, 0, 2, .5, .25, .5, .5, .5, .25, .25, .5, .5, 0,        1, .5, .5, .5, .5, .25, .25, .5, .5, 0, 1, 1, 1, 1, .5, .5, 1, 1, 0,        2, 1, 1, .5, .5, 1, 1, 0, 2, 1, .5, .5, 1, 1, 0,        2, .5, .25, .5, .5, 0, 1, .5, .5, .5, 0, 1, 1, 1, 0, 2, 1, 0, 2, 0,        0, 2}          o[[117]] = {1, 2, 1, 2, .5, 1, 1, 2, 1, 0, 1, .5, 2, 1, 1, 1, 2, 1, 2,        2, 4, 1, 2, 2, 4, 2, 0, 2, 1, 4, 2, 2, 2, 4, 2, 1, 2, .5, 1, 1, 2,        1, 0, 1, .5, 2, 1, 1, 1, 2, 1, 2, 1, 2, 2, 4, 2, 0, 2, 1, 4, 2, 2,        2, 4, 2, .5, .5, .5, 1, .5, 0, .5, .25, 1, .5, .5, .5, 1, .5, 1, 1,        2, 1, 0, 1, .5, 2, 1, 1, 1, 2, 1, 1, 2, 1, 0, 1, .5, 2, 1, 1, 1, 2,        1, 2, 2, 0, 2, 1, 4, 2, 2, 2, 4, 2, 1, 0, 1, .5, 2, 1, 1, 1, 2, 1,        0, 0, 0, 0, 0, 0, 0, 0, 0, 1, .5, 2, 1, 1, 1, 2, 1, .5,        1, .5, .5, .5, 1, .5, 2, 2, 2, 2, 4, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1,        1, 2, 1, 2, 1, 1}          o[[127]] = {1, 1, 1, .5, 2, 1, 2, 1, 1, 1, 1, 2, .5, 1, 1, 1, .5, 1,        1, 1, .5, 2, 1, 2, 1, 1, 1, 1, 2, .5, 1, 1, 1, .5, 1, 1, .5, 2, 1,        2, 1, 1, 1, 1, 2, .5, 1, 1, 1, .5, 1, .5, 1, .5, 1, .5, .5, .5, .5,        1, .25, .5, .5, .5, .25, .5, 2, 2, 4, 2, 2, 2, 2, 4, 1, 2, 2, 2, 1,        2, 1, 2, 1, 1, 1, 1, 2, .5, 1, 1, 1, .5, 1, 2, 2, 2, 2, 2, 4, 1, 2,        2, 2, 1, 2, 1, 1, 1, 1, 2, .5, 1, 1, 1, .5, 1, 1, 1, 1, 2, .5, 1, 1,        1, .5, 1, 1, 1, 2, .5, 1, 1, 1, .5, 1, 1, 2, .5, 1, 1, 1, .5, 1, 2,        1, 2, 2, 2, 1, 2, .5, .5, .5, .5, .25, .5, 1, 1, 1, .5, 1, 1,        1, .5, 1, 1, .5, 1, .5, .5, 1}          o[[136]] = {1, 1, 1, 1, 1, 1, 2, 2, 1, 1, .5, 1, 1, 1, 1, 0, .5, 1, 1,        1, 1, 1, 1, 2, 2, 1, 1, .5, 1, 1, 1, 1, 0, .5, 1, 1, 1, 1, 1, 2, 2,        1, 1, .5, 1, 1, 1, 1, 0, .5, 1, 1, 1, 1, 2, 2, 1, 1, .5, 1, 1, 1,        1, 0, .5, 1, 1, 1, 2, 2, 1, 1, .5, 1, 1, 1, 1, 0, .5, 1, 1, 2, 2, 1,        1, .5, 1, 1, 1, 1, 0, .5, 1, 2, 4, 2, 2, 1, 2, 2, 2, 2, 0, 1, 2, 2,        2, 2, 1, 2, 2, 2, 2, 0, 1, 2, 1, 1, .5, 1, 1, 1, 1, 0, .5, 1,        1, .5, 1, 1, 1, 1, 0, .5, 1, .5, .5, .5, .5, .5, 0, .25, .5, 1, 1,        1, 1, 0, .5, 1, 1, 1, 1, 0, .5, 1, 1, 1, 0, .5, 1, 1, 0, .5, 1, 0,        0, 0, .5, .5, 1}          o[[144]] = {1, .5, 1, 1, 2, 1, .5, .5, 1, .5, 2, 1, 1, .5, 1,        2, .5, .5, .5, .5, .5, 1, .5, .25, .25, .5, .25, 1, .5, .5, .25, .5,        1, .25, .25, 1, 1, 2, 1, .5, .5, 1, .5, 2, 1, 1, .5, 1, 2, .5, .5,        1, 2, 1, .5, .5, 1, .5, 2, 1, 1, .5, 1, 2, .5, .5, 2, 2, 1, 1, 2, 1,        4, 2, 2, 1, 2, 4, 1, 1, 1, .5, .5, 1, .5, 2, 1, 1, .5, 1,        2, .5, .5, .5, .25, .5, .25, 1, .5, .5, .25, .5,        1, .25, .25, .5, .5, .25, 1, .5, .5, .25, .5, 1, .25, .25, 1, .5, 2,        1, 1, .5, 1, 2, .5, .5, .5, 1, .5, .5, .25, .5, 1, .25, .25, 2, 2,        2, 1, 2, 4, 1, 1, 1, 1, .5, 1, 2, .5, .5, 1, .5, 1,        2, .5, .5, .5, .5, 1, .25, .25, 1, 2, .5, .5, 2, 1, 1, .5, .25, .5}          o[[151]] = {1, 2, 1, 1, 1, 2, .5, 1, .5, 2, 1, 2, 1, 1, 1, 1, .5, 1,        2, 2, 2, 2, 4, 1, 2, 1, 4, 2, 4, 2, 2, 2, 2, 1, 2, 1, 1, 1, 2, .5,        1, .5, 2, 1, 2, 1, 1, 1, 1, .5, 1, 1, 1, 2, .5, 1, .5, 2, 1, 2, 1,        1, 1, 1, .5, 1, 1, 2, .5, 1, .5, 2, 1, 2, 1, 1, 1, 1, .5, 1, 2, 1,        2, 1, 4, 2, 4, 2, 2, 2, 2, 1, 2, .5, .5, .25, 1, .5,        1, .5, .5, .5, .5, .25, .5, 1, .5, 2, 1, 2, 1, 1, 1, 1, .5, 1, .5,        1, .5, 1, .5, .5, .5, .5, .25, .5, 2, 2, 4, 2, 2, 2, 2, 1, 2, 1, 2,        1, 1, 1, 1, .5, 1, 2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, .5, 1, 1, 1,        1, .5, 1, 1, 1, .5, 1, 1, .5, 1, .5, .5, 1}          o[[157]] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,        1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, 1, 1, 1, 1, 1, 1, 1,        1, 1, 2, 1, 1, 2, 1, .5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2,        1, .5, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, 1, 1, 1, 1, 1,        1, 2, 1, 1, 2, 1, .5, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, 1, 1,        1, 1, 2, 1, 1, 2, 1, .5, 1, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, 1, 1, 2,        1, 1, 2, 1, .5, 1, 1, 2, 2, 2, 4, 2, 1, 2, 2, 1, 1, 2, 1, .5, 1, 1,        1, 2, 1, .5, 1, 1, 2, 2, 1, 2, 2, 1, .5, 1, 1, .5, .5, .5, 1, 1, 1}          o[[162]] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, .5, 0, 1,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, .5, 0, 1, 1, 1, 1, 1, 1,        1, 1, 1, 1, 1, 1, 2, 1, .5, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,        1, .5, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, .5, 0, 1, 1, 1, 1, 1,        1, 1, 1, 1, 2, 1, .5, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, .5, 0, 1, 1,        1, 1, 1, 1, 1, 2, 1, .5, 0, 1, 1, 1, 1, 1, 1, 2, 1, .5, 0, 1, 1, 1,        1, 1, 2, 1, .5, 0, 1, 1, 1, 1, 2, 1, .5, 0, 1, 1, 1, 2, 1, .5, 0, 1,        1, 2, 1, .5, 0, 1, 2, 1, .5, 0, 2, 2, 1, 0, 1, .5, 0, .5, 0, 0}          o[[166]] = {1, 1, 1, 1, 1, 1, .5, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, .5,        1, 1, 1, 1, 1, .5, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, .5, 1, 1, 1,        1, .5, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, .5, 1, 1, 1, .5, 1, 1, 1, 2,        1, 1, 2, 1, .5, 1, .5, 1, 1, .5, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, .5,        1, .5, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, .5, .5, .5, .5, .5, 1, .5, .5,        1, .5, .25, .5, .25, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, .5, 1, 1, 2, 1,        1, 2, 1, .5, 1, .5, 1, 2, 1, 1, 2, 1, .5, 1, .5, 2, 2, 2, 4, 2, 1,        2, 1, 1, 1, 2, 1, .5, 1, .5, 1, 2, 1, .5, 1, .5, 2, 2, 1, 2, 1,        1, .5, 1, .5, .5, 1, .25, 1, .5, .5}          o[[169]] = {1, .5, .5, .5, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, .5,        2, .5, .25, .25, .5, 1, .5, .5, .5, .5, .5, .5, 1, .5, .5, .5, .25,        1, .5, .25, .5, 1, .5, .5, .5, .5, .5, .5, 1, .5, .5, .5, .25,        1, .5, .5, 1, .5, .5, .5, .5, .5, .5, 1, .5, .5, .5, .25, 1, 1, 2,        1, 1, 1, 1, 1, 1, 2, 1, 1, 1, .5, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2,        2, 1, 4, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, .5, 2, 1, 1, 1, 1, 1, 2, 1,        1, 1, .5, 2, 1, 1, 1, 1, 2, 1, 1, 1, .5, 2, 1, 1, 1, 2, 1, 1, 1, .5,        2, 1, 1, 2, 1, 1, 1, .5, 2, 1, 2, 1, 1, 1, .5, 2, 2, 2, 2, 2, 1, 4,        1, 1, 1, .5, 2, 1, 1, .5, 2, 1, .5, 2, .5, 1, 2}          o[[171]] = {1, .5, 1, 1, 1, 1, 2, .5, 1, 1, 1, 1, 1, 1, 2, 2, .5,        1, .5, .5, .5, .5, .5, 1, .25, .5, .5, .5, .5, .5, .5, 1,        1, .25, .5, 1, 1, 1, 1, 2, .5, 1, 1, 1, 1, 1, 1, 2, 2, .5, 1, 1, 1,        1, 2, .5, 1, 1, 1, 1, 1, 1, 2, 2, .5, 1, 1, 1, 2, .5, 1, 1, 1, 1, 1,        1, 2, 2, .5, 1, 1, 2, .5, 1, 1, 1, 1, 1, 1, 2, 2, .5, 1, 2, 1, 2,        2, 2, 2, 2, 2, 4, 4, 1, 2, .5, .5, .5, .5, .5, .5, .5, 1,        1, .25, .5, 1, 1, 1, 1, 1, 1, 2, 2, .5, 1, 1, 1, 1, 1, 1, 2, 2, .5,        1, 1, 1, 1, 1, 2, 2, .5, 1, 1, 1, 1, 2, 2, .5, 1, 1, 1, 2, 2, .5, 1,        1, 2, 2, .5, 1, 2, 4, 1, 2, 2, 1, 2, .5, .5, 1}          o[[2]] = (o[[1]] + o[[19]])/2     o[[3]] = (o[[1]] + o[[36]])/2     o[[4]] = (o[[1]] + o[[52]])/2     o[[5]] = (o[[1]] + o[[67]])/2     o[[6]] = (o[[1]] + o[[81]])/2     o[[7]] = (o[[1]] + o[[94]])/2     o[[8]] = (o[[1]] + o[[106]])/2     o[[9]] = (o[[1]] + o[[117]])/2     o[[10]] = (o[[1]] + o[[127]])/2     o[[11]] = (o[[1]] + o[[136]])/2     o[[12]] = (o[[1]] + o[[144]])/2     o[[13]] = (o[[1]] + o[[151]])/2     o[[14]] = (o[[1]] + o[[157]])/2     o[[15]] = (o[[1]] + o[[162]])/2     o[[16]] = (o[[1]] + o[[166]])/2     o[[17]] = (o[[1]] + o[[169]])/2     o[[18]] = (o[[1]] + o[[171]])/2          o[[20]] = (o[[19]] + o[[36]])/2     o[[21]] = (o[[19]] + o[[52]])/2     o[[22]] = (o[[19]] + o[[67]])/2     o[[23]] = (o[[19]] + o[[81]])/2     o[[24]] = (o[[19]] + o[[94]])/2     o[[25]] = (o[[19]] + o[[106]])/2     o[[26]] = (o[[19]] + o[[117]])/2     o[[27]] = (o[[19]] + o[[127]])/2     o[[28]] = (o[[19]] + o[[136]])/2     o[[29]] = (o[[19]] + o[[144]])/2     o[[30]] = (o[[19]] + o[[151]])/2     o[[31]] = (o[[19]] + o[[157]])/2     o[[32]] = (o[[19]] + o[[162]])/2     o[[33]] = (o[[19]] + o[[166]])/2     o[[34]] = (o[[19]] + o[[169]])/2     o[[35]] = (o[[19]] + o[[171]])/2          o[[37]] = (o[[36]] + o[[52]])/2     o[[38]] = (o[[36]] + o[[67]])/2     o[[39]] = (o[[36]] + o[[81]])/2     o[[40]] = (o[[36]] + o[[94]])/2     o[[41]] = (o[[36]] + o[[106]])/2     o[[42]] = (o[[36]] + o[[117]])/2     o[[43]] = (o[[36]] + o[[127]])/2     o[[44]] = (o[[36]] + o[[136]])/2     o[[45]] = (o[[36]] + o[[144]])/2     o[[46]] = (o[[36]] + o[[151]])/2     o[[47]] = (o[[36]] + o[[157]])/2     o[[48]] = (o[[36]] + o[[162]])/2     o[[49]] = (o[[36]] + o[[166]])/2     o[[50]] = (o[[36]] + o[[169]])/2     o[[51]] = (o[[36]] + o[[171]])/2          o[[53]] = (o[[52]] + o[[67]])/2     o[[54]] = (o[[52]] + o[[81]])/2     o[[55]] = (o[[52]] + o[[94]])/2     o[[56]] = (o[[52]] + o[[106]])/2     o[[57]] = (o[[52]] + o[[117]])/2     o[[58]] = (o[[52]] + o[[127]])/2     o[[59]] = (o[[52]] + o[[136]])/2     o[[60]] = (o[[52]] + o[[144]])/2     o[[61]] = (o[[52]] + o[[151]])/2     o[[62]] = (o[[52]] + o[[157]])/2     o[[63]] = (o[[52]] + o[[162]])/2     o[[64]] = (o[[52]] + o[[166]])/2     o[[65]] = (o[[52]] + o[[169]])/2     o[[66]] = (o[[52]] + o[[171]])/2          o[[68]] = (o[[67]] + o[[81]])/2     o[[69]] = (o[[67]] + o[[94]])/2     o[[70]] = (o[[67]] + o[[106]])/2     o[[71]] = (o[[67]] + o[[117]])/2     o[[72]] = (o[[67]] + o[[127]])/2     o[[73]] = (o[[67]] + o[[136]])/2     o[[74]] = (o[[67]] + o[[144]])/2     o[[75]] = (o[[67]] + o[[151]])/2     o[[76]] = (o[[67]] + o[[157]])/2     o[[77]] = (o[[67]] + o[[162]])/2     o[[78]] = (o[[67]] + o[[166]])/2     o[[79]] = (o[[67]] + o[[169]])/2     o[[80]] = (o[[67]] + o[[171]])/2          o[[82]] = (o[[81]] + o[[94]])/2     o[[83]] = (o[[81]] + o[[106]])/2     o[[84]] = (o[[81]] + o[[117]])/2     o[[85]] = (o[[81]] + o[[127]])/2     o[[86]] = (o[[81]] + o[[136]])/2     o[[87]] = (o[[81]] + o[[144]])/2     o[[88]] = (o[[81]] + o[[151]])/2     o[[89]] = (o[[81]] + o[[157]])/2     o[[90]] = (o[[81]] + o[[162]])/2     o[[91]] = (o[[81]] + o[[166]])/2     o[[92]] = (o[[81]] + o[[169]])/2     o[[93]] = (o[[81]] + o[[171]])/2          o[[95]] = (o[[94]] + o[[106]])/2     o[[96]] = (o[[94]] + o[[117]])/2     o[[97]] = (o[[94]] + o[[127]])/2     o[[98]] = (o[[94]] + o[[136]])/2     o[[99]] = (o[[94]] + o[[144]])/2     o[[100]] = (o[[94]] + o[[151]])/2     o[[101]] = (o[[94]] + o[[157]])/2     o[[102]] = (o[[94]] + o[[162]])/2     o[[103]] = (o[[94]] + o[[166]])/2     o[[104]] = (o[[94]] + o[[169]])/2     o[[105]] = (o[[94]] + o[[171]])/2          o[[107]] = (o[[106]] + o[[117]])/2     o[[108]] = (o[[106]] + o[[127]])/2     o[[109]] = (o[[106]] + o[[136]])/2     o[[110]] = (o[[106]] + o[[144]])/2     o[[111]] = (o[[106]] + o[[151]])/2     o[[112]] = (o[[106]] + o[[157]])/2     o[[113]] = (o[[106]] + o[[162]])/2     o[[114]] = (o[[106]] + o[[166]])/2     o[[115]] = (o[[106]] + o[[169]])/2     o[[116]] = (o[[106]] + o[[171]])/2          o[[118]] = (o[[117]] + o[[127]])/2     o[[119]] = (o[[117]] + o[[136]])/2     o[[120]] = (o[[117]] + o[[144]])/2     o[[121]] = (o[[117]] + o[[151]])/2     o[[122]] = (o[[117]] + o[[157]])/2     o[[123]] = (o[[117]] + o[[162]])/2     o[[124]] = (o[[117]] + o[[166]])/2     o[[125]] = (o[[117]] + o[[169]])/2     o[[126]] = (o[[117]] + o[[171]])/2          o[[128]] = (o[[127]] + o[[136]])/2     o[[129]] = (o[[127]] + o[[144]])/2     o[[130]] = (o[[127]] + o[[151]])/2     o[[131]] = (o[[127]] + o[[157]])/2     o[[132]] = (o[[127]] + o[[162]])/2     o[[133]] = (o[[127]] + o[[166]])/2     o[[134]] = (o[[127]] + o[[169]])/2     o[[135]] = (o[[127]] + o[[171]])/2          o[[137]] = (o[[136]] + o[[144]])/2     o[[138]] = (o[[136]] + o[[151]])/2     o[[139]] = (o[[136]] + o[[157]])/2     o[[140]] = (o[[136]] + o[[162]])/2     o[[141]] = (o[[136]] + o[[166]])/2     o[[142]] = (o[[136]] + o[[169]])/2     o[[143]] = (o[[136]] + o[[171]])/2          o[[145]] = (o[[144]] + o[[151]])/2     o[[146]] = (o[[144]] + o[[157]])/2     o[[147]] = (o[[144]] + o[[162]])/2     o[[148]] = (o[[144]] + o[[166]])/2     o[[149]] = (o[[144]] + o[[169]])/2     o[[150]] = (o[[144]] + o[[171]])/2          o[[152]] = (o[[151]] + o[[157]])/2     o[[153]] = (o[[151]] + o[[162]])/2     o[[154]] = (o[[151]] + o[[166]])/2     o[[155]] = (o[[151]] + o[[169]])/2     o[[156]] = (o[[151]] + o[[171]])/2          o[[158]] = (o[[157]] + o[[162]])/2     o[[159]] = (o[[157]] + o[[166]])/2     o[[160]] = (o[[157]] + o[[169]])/2     o[[161]] = (o[[157]] + o[[171]])/2          o[[163]] = (o[[162]] + o[[166]])/2     o[[164]] = (o[[162]] + o[[169]])/2     o[[165]] = (o[[162]] + o[[171]])/2          o[[167]] = (o[[166]] + o[[169]])/2     o[[168]] = (o[[166]] + o[[171]])/2          o[[170]] = (o[[169]] + o[[171]])/2          o


title: Write a function using pattern test to test whether the input is polynomial and print error message if not

text: I am doing this which is supposed to be an easy problem and which I think my code should be correct but for some reasons it is not working. May anyone help correcting my mistakes? How should I write the correct code? This is the question: > Write a function that takes a polynomial in the variable x as input and > computes its degree. Using a pattern test your function should print an > error message when the input is not a polynomial. (It is acceptable if your > function regards a string object such as "Math" as a polynomial of degree > zero). My answer:               If[Function[y, PolynomialQ[y, x]][x^2 + 3 x], Exponent[y, x], Print["error"]]      My code always returns zero and I have no idea why. Also, do we have to use Function[] to write a function? Many thanks in advance for all the helps! Edit:   Thanks @0x4A4D for suggestion.   Here is my edited code:               If[Function[x, PolynomialQ[x^2, x]], Exponent[y, x], Print["error"]]      which I think doesn't quite make any sense, the code does not even produce any output. I guess something is wrong with Function[], but not sure how. I would be grateful if anyone could lend some help. I have been doing this question for quite a long time. Thanks!


title: FindRoot error, Solving equations

text: I'm trying to solve this problem but FindRoot function seem unable to find the root when r equals 4.               rs = 4.015551971775909`;     e = 0.39720753208826703`;          r = {3., 3.2, 3.4, 3.6, 3.8, 4., 4.2, 4.4, 4.6, 4.8, 5., 6., 8., 10.};     Ei = {6.60253, 2.6477, 0.779688, -0.029736, -0.329679, -0.39753, -0.3717, \     -0.315756, -0.256599, -0.204246, -0.160965, -0.050085, -0.007812, \     -0.001953};     Er = Table[{r[[i]], Ei[[i]]}, {i, 1, Length[Ei]}];     pot[r_, x_] := -e (1 - (1 - Exp[-(x) (r - rs)])^2)     Do[Xi[i] =        FindRoot[pot[Er[[i]][[1]], x] == Er[[i]][[2]], {x, 1.6},         MaxIterations -> 300], {i, 1, Length[Ei]}]     X = Table[x /. Xi[i], {i, 1, Length[Ei]}]      it reports the closest value to be 0.0000165374 and gives the below message. while the actual value should be 1.5989. > The line search decreased the step size to within tolerance specified \ by > AccuracyGoal and PrecisionGoal but was unable to find a sufficient \ > decrease in the merit function. You may need more than \ MachinePrecision > digits of working precision to meet these tolerances.


title: NDSolve Initial Condition Returned as True

text: I am attempting to use an NDSolve solution as an initial condition for another NDSolve as suggested in this post: Using NDSolve solution as initial condition for another NDSolve ; however, Mathematica does not evaluate NDSolve, but rather returns NDSolve with "True" in place of the initial condition. How can I change my input so that the initial condition is not entered as True? Thanks for any help. Here's my code:                    d2 = Quiet@            NDSolve[{p'[x] ==                p[x]^3/0.2501*                Sqrt[2 *4.85017 - 0.2501^2/p[x]^2 - 2 Sqrt[1 - p[x]^2] +                   2 Log[Sqrt[1 - p[x]^2]/p[x] + 1/p[x]]],               p[15.9944121790131434664021335530341817351882269699843332105813704010026\     04820513129389631782732451812`60.] == 0.0655951920387433`}, p, {x, 15.9944121790131434664021335530341817351882269699843332105813704010026\     04820513129389631782732451812`60., 1000},              WorkingPrecision -> 60]; dom1 =           InterpolatingFunctionDomain[First[p /. d2]]; {lim1, c1} =           dom1[[1]];           d3 = Quiet@            NDSolve[{p'[x] ==                p[x]^3/0.2501*                Sqrt[2*4.85017 - 0.2501^2/p[x]^2 - 2 Sqrt[1 - p[x]^2] +                   2 Log[Sqrt[1 - p[x]^2]/p[x] + 1/p[x]]],               p[c1] == p[c1] /. d2}, p, {x, c1, 1000},              WorkingPrecision -> 60]; dom2 =           InterpolatingFunctionDomain[First[p /. d3]]; {lim2, c2} = dom2[[1]];


title: How to embed a movie into a Mathematica-made presentation?

text: The question is completely formulated in the title. However, to make it more presize, I am making presentations for lectures. The presentations are done in Mma. I have some illustrative material to show in a form of movies (avi and gif). It is possible to remove Mma from the screen, open a file with the movies and play one. I would like, however, to be able to call a movie from Mma just for the sake of speed. In addition it is aestetically better. I tried to embed a hyperlink into the presentation notebook to call the movie file. This does not work. It opens an empty notebook with the title of the movie-file in question, and after a rather long waiting the notebook becomes filled by some symbols. Evidently, it opens the file rather than plays it. So, can I do anything?


title: Find elements of a list which are empty

text: Sorry for the most basic of questions. How would I find the positions of a list of elements which are empty, for example I have the list               a = {1, 2, {}, {}, 3, 5};      and I want to find the indices of the empty elements.


title: What is the best distribution for my histogram?

text: I defined a security bound for a random walk (cube with 15 lengh) and i have this code to obtain a sample of the random times at which the random walk crosses the boundary for the first time:               w = Do[i = 0; NestWhile[(i++; # + RandomReal[{-1, 1}, 3]) &, {0, 0, 0},Norm[#] < 15 &];    Sow[i], {1000}] // Reap       (take the code from here Sample of the random times at which the random walk crosses the boundary) And i constructed a histogram with w: ![enter image description here](http://i.stack.imgur.com/qXvx6.jpg) And now i want to know the distribution of this data, i tought that is was a gamma because of the histogram but i run some tests in excel and i concluded that it isnt but i would like to confirm that with mathematica, is that possible? And when i do this               \[ScriptCapitalH] = DistributionFitTest[w[[2, 1]], Automatic, "HypothesisTestData"];          \[ScriptCapitalH]["FittedDistribution"]      I have for output: NormalDistribution[233.588, 150.231], but sweekness[w]=1.83 (if it was a normal it should be aproxematly zero). Would like some help please :)


title: Computing lists using AstronomicalData

text: # Edit: Initially in my question I asked how I could search the database of `AstronomicalData["Exoplanets"]` and return 2 filtered values that only contained valued cases, which would be placed into a `ListLogPlot`. The necessity was to achieve 3 lists that had 2 sets of data, however my method required having to manually copy the results into their lists that didn't contain _Missing data. The lists required categorization of the radii of exoplanets in relation to Jupiter and Neptune;   * Exoplanets that are larger than Jupiter, **exoplanet > Jupiter**   * Exoplanets that are larger than Neptune but smaller than Jupiter, **Neptune < exoplanet < Jupiter**   * Exoplanets that are smaller than Neptune, **exoplanet < Neptune** As an example, I sorted the radii by value to make finding correlating sizes easier, my search method was;               Sort[{AstronomicalData[#, "Radius"],AstronomicalData[#,"SemimajorAxis"]}->#&/@AstronomicalData["Exoplanet"]]      An extract from the example returns;               {3.63*10^6, 2.25*10^9} -> "KOI961d", {4.65*10^6, 8.75*10^8} -> "KOI961c"...      I found no concept which allowed me to use `DeleteCases` that allowed me to keep the syntax for naming using `#`


title: FlipView can't handle CurrentValue["MouseOver"]. Kernel crash

text: Is this code crashing your Mathematica session? ( _it can so look out :P_ )               DynamicModule[{a = 1},           FlipView[{        Framed["(", Background -> Dynamic[If[CurrentValue["MouseOver"], Blue, LightBlue]]],        Framed["<", Background -> Dynamic[If[CurrentValue["MouseOver"], Blue, LightBlue]]]        }, a]           ]      > ![enter image description here](http://i.stack.imgur.com/cZEPW.png) Fast workaround would be to take `Framed` outside `FlipView`. I'm just curious if this happens to all of you and if it should be marked as a bug.


title: Panel size undesired behaviour

text: This is next question from the series: _better avoid_ `Panel` _if you care about details._ previous about `FrameMargins` In the following example `ImageSize` is on purpose not big enough to display `1`, we will see that this causes the `Panel` to fool us about it's `ImageSize`. First case:               With[{opt = Sequence[ImageSize -> {20, 20}, ImageMargins -> 0, Background -> Orange]},      Row[{        Panel[1, opt],        Panel[1, opt]        }]]      > ![enter image description here](http://i.stack.imgur.com/S7Jzy.png)               With[{opt = Sequence[ImageSize -> {20, 20}, ImageMargins -> 0, Background -> Orange]},          Row[{            Panel[1, opt],            Panel[1, opt, FrameMargins -> 0]            }]]      > ![enter image description here](http://i.stack.imgur.com/QNsrl.png) Again, there is no problem with `Framed`. WinXP V9.0.1 Is this OS dependent problem too? Is bugs appriopriate tag?, because I see no reason that `FrameMargins` should affect overall `ImageSize`.


title: Forcing Mathematica to typeset parentheses

text: I use the definitions from this post to typeset formulas in lecture slides. This is my function definition:               Attributes[equation] = {HoldAll, HoldAllComplete};     equation[eq___] := Panel[TraditionalForm[Style[HoldForm@Defer[eq], 21]]]      I also had to set:               SetOptions[$FrontEndSession,  UnderoverscriptBoxOptions -> {LimitsPositioning -> False}]      It works nicely in many cases. For instance:               equation[\[ScriptCapitalP][k, "N", \[Rho]] == \[ScriptCapitalP][X <= k] == \!\(\*UnderoverscriptBox[\(\[Sum]\), \(n = 0\), \(k\)]\(Binomial["\<N\>",       m] \*SuperscriptBox[\(\[Rho]\), \(n\)] \*SuperscriptBox[\((1 - \[Rho])\), \("\<N\>" - n\)]\)\)]      ![enter image description here](http://i.stack.imgur.com/cxB4q.gif) Now, there are some things, the frontend just refuses to typeset, for instance parentheses it considers superfluous. For example, I want to reproduce: $$ \overline{\left(\frac{X}{y}\right)}_\mathrm{geom}=\frac{\overline{X}_\mathrm{geom}}{\overline{Y}_\mathrm{geom}} $$ The best I could get was:               equation[Subscript[(\!\(\*OverscriptBox[\((\*FractionBox[\(X\), \(Y\)])\), \(_\)]\)), geom] == Subscript[\!\(\*OverscriptBox[\(X\), \(_\)]\), geom]/Subscript[\!\(\*OverscriptBox[\(Y\), \(_\)]\), geom]]      ![enter image description here](http://i.stack.imgur.com/3W5jn.gif) Any ideas on how to improve?


title: Join lists of lists with unique id

text: Sorry for the vague title, but I can't describe my problem properly and shortly. I am maintaining a list of players and their games with the following form:               gamesPerPlayer =        {{playerId -> playerId1, games-> {game11, game12, game13}},        {playerId -> playerId2, games-> {game21, game22, game23, game24}}}      Each game is a complex structure of nested lists but it has a unique field, so we can simply and think that each `game` is just `{idGame, infoGame}`. Thus my list is like this               gamesPerPlayer =        {{playerId -> playerId1,            games -> {{idGame11, infoGame11}, {idGame12, infoGame12}, {idGame13, infoGame13}}},        {playerId -> playerId2,            games -> {{idGame21, infoGame21}, {idGame22, infoGame22}}}      How can I write a (fast) function to join two of this lists eliminating duplicates? The order of the playerId and the games in the new list is not important. Just to clarify, an example:               list1 = {{playerId -> 1, game s-> {{11, "info"}, {12, "info"}}},              {playerId -> 2, games->{{21, "info"}}}};     list2 = {{playerId -> 1, games -> {{11, "info"}, {13, "info"}}},              {playerId -> 3, games -> {{31, "info"}}}};     newList = myJoinFunction[list1, list2];      Expected result: > >     {{playerId -> 1, games -> {{11, "info"}, {12, "info"}, {13, "info"}}}, >      {playerId -> 2, games -> {{21, "info"}}, {playerId -> 3, games -> {{31, > "info"}}} >


title: Equation involving hypergeometric functions

text: I want to solve this equation but nor `NSolve` nor `Solve` are able to do this.               Gamma[1 + 8 (-1 + r) r]/(Gamma[1 + r] Gamma[1 - 9 r + 8 r^2]) - (      Gamma[1 + 14 r] Gamma[        1 + 8 (-2 + r) r] HypergeometricPFQRegularized[{1, -((15 r)/2), -(          r/2)}, {1 + (13 r)/2, 1 - (33 r)/2 + 8 r^2}, 1])/(      Gamma[1 + r/2] Gamma[1 + (15 r)/2])==0      I want to find a solution for $r \in \mathbb{N}$, $r>2$.               NSolve[Gamma[1 + 8 (-1 + r) r]/(       Gamma[1 + r] Gamma[1 - 9 r + 8 r^2]) - (       Gamma[1 + 14 r] Gamma[         1 + 8 (-2 + r) r] HypergeometricPFQRegularized[{1, -((15 r)/2), -(           r/2)}, {1 + (13 r)/2, 1 - (33 r)/2 + 8 r^2}, 1])/(       Gamma[1 + r/2] Gamma[1 + (15 r)/2]), r, Integers]      Any suggestion? I get the following error message:               NSolve::nsmet: This system cannot be solved with the methods available to NSolve.


title: How to get the indices of values in a list which are NOT an specific integer?

text: I got a real array `A`, where `Dimensions[A] == {5000, 5000, 5}`. Some of the values in `A` are `-1`, others are not. How can I use `Position[]` to find the indices of those values which are **not** `-1`?


title: With limited memory, how can I export very long Print results into a PDF or a notebook file?

text: I have a script with a long loop and very long formatted outputs like the following example code:               Do[Print[Style[Table[RandomReal[], {30}, {15}] // MatrixForm, Blue]], {10000}]      In order to display all the output in the desired format and save them into `*.nb` or `*.pdf`, at least 2GB memory is needed, which exceeds the available upper limits of x86 OS. How can I export the formatted results immediately into a `*.nb` or a PDF file so that the code does not demand so much computer memory?


title: Combine a contour plot of a conic and an inset with an polygon such as all its vertices are on the conic

text: I have a difficulty to programmatically adjust the size of a polygon within an inset of a conic (here I limit myself to a circle) in order to have all its vertices on the circle:               a = {-2, 0}; b = {2, 0}; c = {Sqrt[2], Sqrt[2]}; d = {-Sqrt[2], Sqrt[     2]}; e = {0, 2}; f = {0, -2};         ContourPlot[{x^2 + y^2 - 4 == 0}, {x, -2.5, 2.5}, {y, -2.5, 2.5},      ContourStyle -> {Blue, Thin}, Frame -> None, Axes -> True,      AspectRatio -> 1, Epilog ->      {        {Blue, PointSize[0.02], Point[a],            (Text[Style[#1, 14], #2 + {-0.1, .1}] & @@ {"a", a})},        {Blue, PointSize[0.02], Point [b],         (Text[Style[#1, 14], #2 + {-0.1, .1}] & @@ {"b", b})},        {Blue, PointSize[0.02], Point[c],         (Text[Style[#1, 14], #2 + {-0.1, .1}] & @@ {"c", c})},        {Blue, PointSize[0.02], Point[d],         (Text[Style[#1, 14], #2 + {-0.1, .1}] & @@ {"d", d})},        {Blue, PointSize[0.02], Point[e],         (Text[Style[#1, 14], #2 + {-0.1, .1}] & @@ {"e", e})},        {Blue, PointSize[0.02], Point[f],         (Text[Style[#1, 14], #2 + {-0.1, .1}] & @@ {"f", f})},        {Inset[Graphics[         {ColorData["Legacy", "Banana"], EdgeForm[{Thick, Pink}],           Opacity[0.15], Polygon[{a, b, c, d}]}], {0, 0}, {0, 0}, 4.2]},        {Inset[Graphics[         {ColorData["Legacy", "SlateBlue"], EdgeForm[{Thick, Pink}],           Opacity[0.15], Polygon[{a, e, c, f}]}], {0, 0}, {0, 0}, 3.6]}      }]       Although the two polygons I defined here out of six points have coordinates that are on the circle, I need to adjust the `size` parameter of the `Inset`, for every different position of a set of four points.   By trial an error I achieved something but far from satisfactory: I need to include the code above in a notebook under development where all the points are on the conic and dynamic and the polygon is constructed in the `Epilog` with these points.   Is there a way with MMA to compute the value of the `Inset size` parameter according to the vertices coordinates?


title: How to plot a certain surface? What is its parametric equation?

text: The surface show below is very beautiful; however, I don't know its function either as an implicit function or in parametric form. Anyone have an idea about it and how to draw it with _Mathematica_? ![Beautiful surface](http://i.stack.imgur.com/LXGS9.png)


title: How to make the Menu key on my keyboard work in Mathematica

text: My Menu key works in Windows Explorer, Internet Explorer, many apps, but does not work in _Mathematica's_ notebook. The function is like that of Right-Click with the mouse. _Function expected_ : Select some text in the cell, and tap the menu-key comes out the menu. In my keyboard, it's between the Right-ALT-Key and the Right-Ctrl-key. If this is not possible, how to make one key, or combination of some Control Keys to do the same thing, ie use the keyboard to substitute the right-click of mouse?


title: Plotting a dot product

text: From a conic equation obtained from a dot product, I want to plot its 2D graph, while being able to manipulate the variable.               Manipulate[        K = {Sin[t] Cos[p], Sin[t] Sin[p], Cos[t]};        oP = {x, y, 1};        noP = Assuming[Element[{x, y, z}, Reals], Simplify[Norm[oP]]];        nK = Assuming[Element[{t, p, x, y, z}, Reals], Simplify[Norm[K]]];        {(K.oP)^2 == (Cos[a]*nK*noP)^2},        {a, Pi/16, Pi, Pi/16, ControlPlacement -> Left},        {t, 0, \[Pi], \[Pi]/256, ControlPlacement -> Left},        {p, 0, \[Pi], \[Pi]/256, ControlPlacement -> Left}      ]      ![Mathematica graphics](http://i.stack.imgur.com/Umfmr.png) I do get the correct equation, but I am unable to plot it in any way when I take it separately.               ParametricPlot[ 1 == (1 + x^2 + y^2) Cos[\[Pi]/16]^2, {x, -14, 14}, {y, -14, 14}]      show the axes, but not the graph. Only when I try with the == function do I get the graph, which is not really useful... What should I change?


title: How to estimate the matrix condition number in the 2-Norm?

text: The _Mathematica_ documentation say it is possible to estimate the Matrix condition number in norm 1, 2, Infinity. But the 2-Norm raise a message. This is an extract from reference documentation "tutorial/LinearAlgebraMatrixComputations" where I changed the expression to compute the 2-Norm. ![error](http://i.stack.imgur.com/4yrps.png) ### UPDATE As requested, if you want to try by yourself and check the error on your system, simply type:               mat = {{1., 2.}, {3., 4.}};     LinearAlgebra`MatrixConditionNumber[mat, Norm -> 2]


title: How can we use RowReduce with a modulous AND variables?

text: We can use `RowReduce` with a field. For example, we state               RowReduce[{{1,3,5},{0,1,2}},Modulous->23]      ...which then returns:               {{1,0,22},{0,1,2}}      ...So we will have effectively solved a linear system in a field. **THE QUESTION** Can we somehow use this to solve a system with variables, i.e. solve a symbolic system? As an example, I would like to somehow solve:               RowReduce[{{1,3,a},{0,1,b}},Modulous->23]      The idea is that we should get a result essentially stating something like:               {{1,0,a - 3b},{0,1,b}}      or possibly even better:               {{1,0,a + 20b},{0,1,b}}      The first result is just the solution without the `modulous` included. I'm wondering if there is some way to get the second result.


title: Changing FrontEnd automatic scrolling in version 8

text: In _Mathematica_ versions < 8, the FrontEnd has a very intelligent behavior:   * On evaluation, it by default automatically scrolls down the Notebook window to the last printed Output cell but also allows a user to scroll the Notebook window up by hand and then does not scroll down the window again automatically.   * If the user wishes to restore automatic scrolling it is sufficient to scroll down the window to the last currently printed Output cell and automatic scrolling will be restored. I feel such behavior very comfortable. But in _Mathematica_ 8 we have no such behavior by default. I found that it may be partially restored by setting               SetOptions[$FrontEnd,       EvaluationCompletionAction -> {"ScrollToOutput"}]      But then it is not possible to stop automatic scrolling by scrolling the window by hands. It is possible to restore the old scrolling behavion?


title: Adding Manipulate to Dynamic Module

text: DynamicModule[{n = 7}, solns = Solve[x^n - 1 == 0, x];       myxvals = x /. solns;       myarrows =        Table[Arrow[{{0, 0}, {Re[myxvals[[k]]], Im[myxvals[[k]]]}}], {k, 1,          n}]; mytext =        Table[Text[         ComplexExpand[x /. solns[[k]]], {Re[myxvals[[k]]] + 0.1`,           Im[myxvals[[k]]] - 0.1`}, {-1, 0}], {k, 1, n}];       Graphics[{{Red, myarrows}, {PointSize[Large], Blue, Point[{0, 0}]}},        PlotLabel ->         Style[Row[{Style["x", Italic]^n, -1, " = ", 0}], 24, Bold],        Epilog -> mytext, PlotRange -> {{-1.1`, 1.4`}, {-1.5`, 1.1`}},        ImageSize -> {300, 300}]]      I am trying to tranform this by using Manipulate. What I was to do is to give n a range between 1 and 8 and be able to manipulate the graph afterwards with these values. How do I do that????????


title: Can (compiled) matrix permanent evaluation be further sped-up?

text: **Update**   Multiple optimizations that were suggested by members "ssch" and Simon Woods have in aggregate yielded a ~5X code-speedup; and these optimizations now are incorporated in the example code. Thank you both very much. Further improvements are welcome, needless to say. In particular, for nxn matrix arguments, a further O(n) speedup can be achieved (in principle) by exploiting the Gray code structure of "[Delta]PermutationList". However, this would come at the cost of substantially increased code complexity and generally larger round-off error. * * * For research in BosonSampling (for example) it is desirable to compute matrix permanents by the fastest feasible algorithm. The appended Mathematica code uses Glynn's formula to compute the complex-valued matrix permanent. This code computes the permanent of a 20x20 matrix in ~250 ms (on a 2.93 GHz MacBook Pro laptop) > **The Question Asked**   Can further speed gains be achieved in numerical > computation of the (complex-valued) matrix permanent? The matrices of interest typically have dimension 10x10 to 25x25, and speed- of-execution for repeated permanent evaluations at fixed matrix-dimension is the sole figure-of-merit. Suggestions for improvements will cheerfully be adopted! --- code follows --- * * *               BeginPackage["PermanentCode`"];          Permanent::usage = "\<\     Permanent[mArg_List/;MatrixQ[a]] is computed by Glynn's formula.          The algorithm requires O(m^2 2^m) operations, where m is the dimension      of the matrix arg.          When the argument is numeric, compiled C-code is executed.          When the argument is non-numeric, a \"Permanent::symbolic\" message      is issued, and the permanent is calculated symbolically.          Implementation Notes:           (1) Glynn's formula is simplified with a view to speed-by-simplicity          (at negligible cost in formal efficiency); in brief the algorithm         is implemented as a sequence of BLAS-compatible calls to built-in          Mathematica (BLAS) functions.          (2) At present the algorithm does not fully exploit the Gray-code          structure of the permutation list \[Delta]PermutationList.              URL: http://en.wikipedia.org/wiki/Computing_the_permanent#Glynn_formula     URL: http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms\>";          Permanent::symbolic = "\<\     ADVISORY: Permanent[_] argument is a non-numeric `1`\[Cross]`2` matrix\>";     On[Permanent::symbolic];          \[Delta]PermutationList::usage = "\<\     List of Gray-code permutations, saved in-memory      for use by Permanent[_]'s Glynn formula.\>";          classicalPermanent::usage = "\<\     classicalPermanent[_] computes the matrix permanent     (slowly!) by expansion of the index permutation\     \>";          Begin["`Private`"];          classicalPermanent[mArg_] := Block[         {rowList,colPerms},         rowList = Table[i,{i,1,mArg//Length}];         colPerms = rowList//Permutations;         Map[             (MapThread[mArg[[#1,#2]]&,{rowList,#}]//               Times@@#&)&,             colPerms         ]//Plus@@#&     ];          \[Delta]PermutationList[1] = {{1}};     \[Delta]PermutationList[m_Integer]/;(m>1) := (         (* Conserve memory by purging irrelevant DownValues.            These rules may exist for arbitrarily large arguments,             so a pattern-matched undefine "=." is applied *)         (\[Delta]PermutationList//DownValues)[[All,1]]//           ReplaceAll[#,HoldPattern[\[Delta]PermutationList[a_]]:>a]&//ReleaseHold//             Select[#,(IntegerQ[#]&&(#!=1)&&(#!=m-1))&]&//               Map[(\[Delta]PermutationList[#]=.;)&,#]&;         (* now define-and-return the requested \[Delta]PermutationList *)         \[Delta]PermutationList[m] = \[Delta]PermutationList[m-1]//         (* idiom: the pipe holds \[Delta]PermutationList[m-1], so conserve             memory by deleting its DownValue immediately *)         (If[m>2,\[Delta]PermutationList[m-1]=.;];#)&//(               (* reflect DownValue[m-1] in Gray-code order *)               Map[({1,1}~Join~(#//Rest))&,#] ~ Join ~               Map[({1,-1}~Join~(#//Rest))&,#//Reverse]           )&     );          Permanent[ (* numeric evaluation *)         mArg_List/;(MatrixQ[mArg,NumericQ])     ] := compiledGlynnAlgorithm[             \[Delta]PermutationList[mArg//Length],             mArg         ]//Total[#[[1 ;; ;; 2]]] - Total[#[[2 ;; ;; 2]]]&//           #/2^((mArg//Length)-1)&          compiledGlynnAlgorithm = Compile[{             {d, _Integer, 1},             {a, _Complex, 2}         },         Apply[Times,(d.a)],         CompilationTarget -> "C",          RuntimeAttributes -> {Listable},         Parallelization -> True     ];          Permanent[ (* symbolic evaluation *)         mArg_List/;             (                 MatrixQ[mArg] &&                 (!MatrixQ[mArg,NumericQ]) &&                 (mArg//Length//Message[Permanent::symbolic,#,#]&;True)             )     ] := Map[         Apply[Times,(#.mArg)]&,         \[Delta]PermutationList[mArg//Length]     ]//Total[#[[1 ;; ;; 2]]] - Total[#[[2 ;; ;; 2]]]&//       #/2^((mArg//Length)-1)&;          End[];     EndPackage[];      Code to validate and benchmark               nPerm = 4;     Table[\[DoubleStruckCapitalC][i,j],{i,1,nPerm},{j,1,nPerm}]//       Permanent[#]-classicalPermanent[#]&//         Expand//           If[               #===0,               Print["VALIDATED: ",nPerm,"\[Cross]",nPerm," symbolic permanent"];,               Print["ERROR: ",nPerm,"\[Cross]",nPerm," symbolic permanent"];           ]&;          nPerm = 5;     Table[\[DoubleStruckCapitalC][i,j],{i,1,nPerm},{j,1,nPerm}]//       Permanent[#]-classicalPermanent[#]&//         Expand//           If[               #===0,               Print["VALIDATED: ",nPerm,"\[Cross]",nPerm," symbolic permanent"];,               Print["ERROR: ",nPerm,"\[Cross]",nPerm," symbolic permanent"];           ]&;          nPerm = 6;     nPerm//{#,#}&//(                 1*RandomVariate[NormalDistribution[0,1],#]+                 I*RandomVariate[NormalDistribution[0,1],#]       )*1/Sqrt[2]&//         {Permanent[#],classicalPermanent[#]}&//           (#[[1]]-#[[2]])/Sqrt[#[[2]]\[Conjugate]*#[[2]]]&//           If[               Abs[#]<1000*10^(-$MachinePrecision),               Print["VALIDATED: ",nPerm,"\[Cross]",nPerm," compiled numeric permanent"];,               Print["ERROR: ",nPerm,"\[Cross]",nPerm," compiled numeric permanent"];           ]&;          nPerm = 7;     nPerm//{#,#}&//(                 1*RandomVariate[NormalDistribution[0,1],#]+                 I*RandomVariate[NormalDistribution[0,1],#]       )*1/Sqrt[2]&//         {Permanent[#],classicalPermanent[#]}&//           (#[[1]]-#[[2]])/Sqrt[#[[2]]\[Conjugate]*#[[2]]]&//           If[               Abs[#]<100*10^(-$MachinePrecision),               Print["VALIDATED: ",nPerm,"\[Cross]",nPerm," compiled numeric permanent"];,               Print["ERROR: ",nPerm,"\[Cross]",nPerm," compiled numeric permanent"];           ]&;          Print["--------------"];     Print["*** first Permanent[_] evaluation ***"];     Do[     nPerm//{#,#}&//(                 1*RandomVariate[NormalDistribution[0,1],#]+                 I*RandomVariate[NormalDistribution[0,1],#]       )*1/Sqrt[2]&//(             (* first call stores Gray-code array *)             (Permanent[#]//AbsoluteTiming)//First//1000*#&//Round//               Print["Benchmark: Permanent[ ",nPerm,"\[Cross]",nPerm," ] took ",#," ms"]&;         )&;,{nPerm,20,12,-1}];          Print["--------------"];     Print["*** second Permanent[_] evaluation ***"];     Do[     nPerm//{#,#}&//(                 1*RandomVariate[NormalDistribution[0,1],#]+                 I*RandomVariate[NormalDistribution[0,1],#]       )*1/Sqrt[2]&//(             (* second call runs fast *)             Permanent[#];              (Permanent[#]//AbsoluteTiming)//First//1000*#&//Round//               Print["Benchmark: Permanent[ ",nPerm,"\[Cross]",nPerm," ] took ",#," ms"]&;         )&;,{nPerm,20,12,-1}];          Print["--------------"];     Print["*** (large) Permanent[ 25\[Cross]25 ] evaluation ***"];          25//{#,#}&//(                 1*RandomVariate[NormalDistribution[0,1],#]+                 I*RandomVariate[NormalDistribution[0,1],#]       )*1/Sqrt[2]&//(             (Permanent[#]//AbsoluteTiming)//First//Round//               Print["Benchmark: Permanent[ ",25,"\[Cross]",25," ] took ",#," s"]&;             (Permanent[#]//AbsoluteTiming)//First//Round//               Print["Benchmark: Permanent[ ",25,"\[Cross]",25," ] took ",#," s"]&;         )&;      Results of validating and benchmarking               VALIDATED: 4\[Cross]4 symbolic permanent     VALIDATED: 5\[Cross]5 symbolic permanent     VALIDATED: 6\[Cross]6 compiled numeric permanent     VALIDATED: 7\[Cross]7 compiled numeric permanent     --------------     *** first Permanent[_] evaluation ***     Benchmark: Permanent[ 20\[Cross]20 ] took 1908 ms     Benchmark: Permanent[ 19\[Cross]19 ] took 926 ms     Benchmark: Permanent[ 18\[Cross]18 ] took 428 ms     Benchmark: Permanent[ 17\[Cross]17 ] took 235 ms     Benchmark: Permanent[ 16\[Cross]16 ] took 120 ms     Benchmark: Permanent[ 15\[Cross]15 ] took 52 ms     Benchmark: Permanent[ 14\[Cross]14 ] took 22 ms     Benchmark: Permanent[ 13\[Cross]13 ] took 13 ms     Benchmark: Permanent[ 12\[Cross]12 ] took 8 ms     --------------     *** second Permanent[_] evaluation ***     Benchmark: Permanent[ 20\[Cross]20 ] took 250 ms     Benchmark: Permanent[ 19\[Cross]19 ] took 118 ms     Benchmark: Permanent[ 18\[Cross]18 ] took 55 ms     Benchmark: Permanent[ 17\[Cross]17 ] took 27 ms     Benchmark: Permanent[ 16\[Cross]16 ] took 16 ms     Benchmark: Permanent[ 15\[Cross]15 ] took 22 ms     Benchmark: Permanent[ 14\[Cross]14 ] took 10 ms     Benchmark: Permanent[ 13\[Cross]13 ] took 4 ms     Benchmark: Permanent[ 12\[Cross]12 ] took 1 ms     --------------     *** (large) Permanent[ 25\[Cross]25 ] evaluation ***     Benchmark: Permanent[ 25\[Cross]25 ] took 75 s     Benchmark: Permanent[ 25\[Cross]25 ] took 11 s      Note that the initial evaluation is slower than subsequent evaluations, because initial evaluation creates Gray-code tables that are retained for subsequent use.


title: Integral not simplifying

text: I specify a function in terms of an integral and then try to evaluate it with `Simplify`. However, the answer is not really simplified to what it should be.               assumptions := {l > 0, Element[NN, Integers], NN > 0, b > 0, a > 0,          l > b, a > l, α > 0, β > 0};          Φ = Function[x,          If[x < l,             (NN*π*α*b^2 *(l^2 ArcCos[x/l] - x Sqrt[l^2 - x^2]))/(a^2 * β), 0]         ];     Px = Function[x, If[0 <= x <= a, 1/a, 0]];     FΦ = Function[φ, Simplify[Integrate[If[Φ[x] <= φ, 1, 0] Px[x], {x, 0, a}],          assumptions]];     Simplify[FΦ[0], assumptions]      However, it is easy to see that it should be reduced as first $\frac{1}{a} \int_0^a \text{If}\left[\text{If}\left[x<l,\frac{\text{NN} \pi \alpha b^2 \left(l^2 \text{ArcCos}\left[\frac{x}{l}\right]-x \sqrt{l^2-x^2}\right)}{a^2 \beta },0\right]\leq 0,1,0\right] \, dx$ and then $\frac{1}{a} \int_0^l \text{If}\left[\frac{\text{NN} \pi \alpha b^2 \left(l^2 \text{ArcCos}\left[\frac{x}{l}\right]-x \sqrt{l^2-x^2}\right)}{a^2 \beta }\leq 0,1,0\right] \, dx + \frac{1}{a} \int_l^a \text{If}\left[ 0 \leq 0,1,0\right] \, dx$ to $ \frac{1}{a} \int_0^l 0 \, dx + \frac{1}{a} \int_l^a 1 \, dx$ $=\frac{a-l}{a}$. How can I get Mathematica to simplify it correctly?


title: How to work around incorrect tooltips in plots exported to HTML

text: This is an issue that I always wanted to investigate but haven't gotten around to solving yet: The tooltips for contour lines in a plot like this can be very useful in the Notebook interface:               ContourPlot[3 x y^2 - x^3, {x, -1, 1}, {y, -1, 1},      ContourShading -> False, Contours -> Table[r^3, {r, -1.4, 1.4, .1}]]      However, when I export the Notebook containing the plot as an HTML file, I get the following image: ![enter image description here](http://i.stack.imgur.com/B2YNF.png) It appears to have tooltips, as the screen shot shows (the mouse arrow isn't captured, but the yellow tooltip is). However, those tooltips are generated by an image map that defines some very inaccurate target areas for the contour values to be displayed when the mouse hovers over them. The result is worse than having no tooltips at all, because the displayed values are plain wrong and hence confusing most of the time. To see the exported HTML in real life, look at this URL exported from Mathematica 7 (version 8 does the same thing, I've just had this problem for a long time...). My **first question** would be: what is the best way to _disable_ the use of image maps in the HTML generated by the `Save As HTML` operation? My current thought is that I'll have to post-process the generated HTML file to remove the `usemap` part of all image tags. But maybe someone knows a better way. I would also like to _keep_ the tooltips for the graphics in the Notebook. The **second question** is how one could export a plot like the above so that it can be used in a HTML file while _preserving_ correct tooltips. Here, my thought would be to export to `SVG` and add the tooltips to the generated lines in a post-processing step (the `SVG` file seems to contain enough information to allow this). However, I'm again hoping that someone has a better idea.


title: How can you stop ordering of InputField entries?

text: I have:               InputField[Dynamic[d]]          Dynamic[d]      If I enter e.g.               a b x^5 h m      the entry automatically gets sorted, as per screen grab: ![enter image description here](http://i.stack.imgur.com/ySQSJ.png) What is the best way to keep symbols entered into `InputField` in the same order that you entered them so that they always display in that order? What I am actually wanting to do is enter some text that contains things like subscripts and superscripts, integrals ... `InputField[expr, String]` is not the answer. On the other hand if I use               InputField[Dynamic[d], Hold[Expression]]      and then               d /. {Times -> List, Power -> Superscript} // ReleaseHold      I get a list that I can do things with: ![enter image description here](http://i.stack.imgur.com/APMAl.png) For example I could wrap `Row` with a default spacer or `TextCell` and so on around it. But this seems quite an indirect way of doing things. **Edit** Adding `HoldForm` to the second argument to `Dynamic` doesn't appear to offer any advantage and as Andrew points out you can end up with nested `HoldForm`. So I think this is not a good solution -- maybe a backwards step actually. ![enter image description here](http://i.stack.imgur.com/f8h1O.png) For Andrew's solution, using `Boxes` in `InputField` doesn't, in itself, prevent ordering when you eventually release `Hold` (e.g. after using `MakeExpression`). i.e. I don't see how to avoid apply a hold of some type and removing `Times` to stop the ordering. ![enter image description here](http://i.stack.imgur.com/I6glu.png) So using `Boxes` may in general provide more flexibility but I'm struggling to see how it adds anything for this specific problem.


title: Implicit differentiation to find the slope of the tangent line to the graph at the indicated point

text: I used `ContourPlot` to plot the graph of `x Sin[Pi y] - y Cos[Pi x] == 1` with the following input:               eqn[x_, y_] := (x Sin[Pi y] - y Cos[Pi x] )== 1     ContourPlot[Evaluate[eqn[x, y]], {x, 0, Pi}, {y, 0, Pi}]      To find $dy/dx$ I used the following code:               yprimeEq = D[eqn[x, y[x]], x];     sol = Solve[yprimeEq, y'[x]] // Simplify;     dydx = y'[x] /. First[sol] /. y[x] -> y;      I am stuck on finding the slope of the tangent line to the graph at $(2/3,2)$. I know I have to just plug in $2/3$ for $x$ and $2$ for $y$ but I don't know how to write it in Mathematica.


title: How does Mathematica decide that Log[2,8] is integer?

text: At school we learned that $\log_b(x)=\log(x)/\log(b)$, which is implemented in _Mathematica_ as `Log[b, x]`, but the results are different.               Log[8]/Log[2] // N      returns > >     3.  (* Real *) >   while               Log[2, 8]       returns > >     3  (* Integer *) >   If I want to validate the argument of my `hadamardMatrix[]` function as a power of 2:               hadamardMatrix[1] := {{1}}     hadamardMatrix[2] := {{1, 1}, {1, -1}}     hadamardMatrix[n_ /; IntegerQ[Log[2, n]]] :=             KroneckerProduct[hadamardMatrix[2], hadamardMatrix[n/2]]      How can I be sure that any `Log[2, 2`N`]` will always be regarded as integer?


title: How to generate a formula of a graph with three key points

text: I have three key points on a graph. How do I find out what the formula for this graph would be? The points are: (3,0) (5,2) (7,6). It is known that the graph will be a quadratic. Thanks


title: How to find a specific color in one picture?

text: In a picture, there are many different colors. How can I just want to find the position of one color. In the following picture, if I would like to find the coordinates of the position of blue, how can I achieve that? Thank you very much! ![enter image description here](http://i.stack.imgur.com/1wEvU.jpg)


title: Cursor Position / Insertion Point

text: Is there a way to access (or even set) the **cursor** position in a Notebook? (By **Cursor** I refer to the keyboard input postion, or "Insertion Point". For the Mouse we have `CurrentValue["MousePosition"]` or just `MousePosition[]`) Note that calling external tools is only the seconds best option for me. See Programmatically move the cursor to a desired location on the screen (which is also about the mouse)


title: import Excel sheets by name

text: I'm importing data from Excel. It appears that the sheet number needed in the Import statement is taken from the order that the sheets appear in the open Excel file. I need to import 2 of the sheets from an Excel file. I'd like to do it via the names of the sheets, or at least by some attribute that won't change if I add or delete other sheets or re-order the existing sheets. Can this be done?


title: FullSimplify with assumptions

text: Is there a way to write a FullSimplify at the end of the line with some assumptions? That is, if I write               a^2+b^2+2 a b //FullSimplify[...]      is there any way to include some assumptions for a,b?


title: formatting an InputField with Dynamic

text: I have the following code               Style["("       InputField[Dynamic[t], Number, ImageSize -> 30]       ")="        PDF[NormalDistribution[μ, σ], t],       16]      which doesn't result in > "f(inputfield) = result of PDF calculations based on input" Any ideas?


title: Filling a curve between a line and the x-axis

text: I'm trying to plot the function $f(x)=\dfrac{1}{x^2}$, filling the square area from (0,0) to (1,1) with purple and filling the area under the curve from 1 to 4 with red. However, _Mathematica_ is not showing the purple filling, and the red part is not completely filled down to the x-axis. My current code:               Show[Plot[1/(x^2), {x, 0, 4}, PlotStyle -> Blue, AspectRatio -> 1],     Plot[{1/(x^2), 1}, {x, 0, 1}, PlotStyle -> Blue, Filling -> {1 -> {{2}, {Purple, None}}}],     Plot[1/(x^2), {x, 1, 4}, PlotStyle -> Blue, Filling -> Axis, FillingStyle -> Red]]      What _Mathematica_ gives me: ![](http://i.imgur.com/uj1bMHy.jpg?) What's wrong with my code? (I'm also very new to _Mathematica_ , so any suggestions on a more elegant way to fill the curve would be appreciated.)