Subject: Re: Printing Error Messages to Messages Window? > Can I arrange for error messages (things like NIntegrate::ploss : and > more or less any others of this sort) to be printed to the Messages > window rather than the notebook that's being evaluated? (but still with > the usual beep) Yes. Format | Option Inspector... [2] Type in messag and hit return. [3] Change KernelMessageAction so that it has PrintToConsole rather than PrintToNotebook > I assume that this has something to do with setting the options for > $FrontEnd, but I don't find documentation for terms like > PrintToConsole and PrintToNotebook that I find when I look at those > options. They are explained under the KernelMessageAction entry. Try typing K into the input field when Front End is selected in the HelpBrowser. You can also view (and set) the options from the command line using commands like MessageOptions /. Options[$FrontEnd] Paul -- Paul Abbott Phone: +61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Information about subscripted function when I define a function with a subscript in its name: (cell content below) In[1]:= !(f_1[x_] := x^2) I can't see it by use of information operator: In[2]:= !((? f_1)) Information::ssym Out[2]:= !(Information[f_1, LongForm -> False]) of course I may ask: In[3]:= ? Subscript but then I get ALL functions which have subscripts in their names! so, how to ask about the defintions of subscripted functions ? Seb. === Subject: Re: Re: How input stacked characters with vertical bar OK, that does stack th subscript and superscript -- but they are not placed where proper mathematical notation says they should appear with such a vertical bar. I've tried both the | key on the keyboard as well as the VerticalSeparator symbol (on the Complete Characters palette). And those symbols do (almost) automatically expand to the height of what's immediately to their left, e.g., a stacked: 2 x --- 2 But the subscript and superscript I type then are NOT located near the top and bottom of the vertical bar, where they ought to appear. Rather, they are quite close together vertically, as if they were the subscript and superscript on a single letter. >>In a text cell, as part of an in-line mathematical expression, how do I >>type a stacked pair of expressions, both the same size. For example, >>the stacked b above a, next to a long vertical bar, as you would see in >>a statement of the Fundamental Theorem of Calculus that expresses the >>definite integral as F(b) - F(a). > Just as you do for an integral or a sum. Use > [ControlKey] - > (subscript) for the lower limit and toggle to the upper limit using > [ControlKey] 5 > These are in the > Edit | Expression Input > menu. >>And which is the appropriate symbol for that vertical bar? > [VerticalSeparator] > The keyboard shortcut is > esc | esc >>Is there some way to force it to expand vertically to the extent of the >>stacked expressions next to it, or must one do so manually. > Select the VerticalSeparator, open the Option Inspector, type in span, > hit return, and set the SpanMaxSize to Infinity. > Here is an example of such a cell: > Cell[BoxData[FormBox[RowBox[{RowBox[{F, (, x, )}], > SubsuperscriptBox[StyleBox[[VerticalSeparator], > SpanMaxSize->Infinity], a, b]}], > TraditionalForm]], Input > ] > Paul -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: please solve [LinearAlgebra] > Could someone please solve this symbolically? > This is just the ols formula for beta-hat but I need a symbolic > solution for this special case. > b = inv(x'x)x'y > where > x = 1 t t^2 > 1 t t^2 > 1 t t^2 > and simplify simplify simplify!! For a singular matrix you need to compute the PseudoInverse: X = Table[t^(i-1), {3}, {i, 3}] Y = Table[y[i], {i, 3}] b = PseudoInverse[X] . Y // Simplify Assuming that t is real, you obtain Simplify[b, Element[t, Reals]] { (y[1] + y[2] + y[3])/(3 (t^4 + t^2 + 1)), t (y[1] + y[2] + y[3])/(3 (t^4 + t^2 + 1)), t^2 (y[1] + y[2] + y[3])/(3 (t^4 + t^2 + 1))} You get exactly the same result if you compute PseudoInverse[Transpose[X] . X] . Transpose[X] . Y and simplify. In 5.1, if you paste the following cell into a Notebook and click on the button it will take you to the advanced documentation: Cell[TextData[{See the , ButtonBox[Advanced Documentation, ButtonData:>Advanced Documentation: Linear Algebra, ButtonStyle->RefGuideLink], for Linear Algebra for more information, particularly the section on pseudoinverse in the Basic Operations section of Section 4.}], Text] Paul -- Paul Abbott Phone: +61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: mcmc >Hi! >I'd like to know if there is something made for Mathematica using >Montecarlo Markov Chain numerical integration methods. I'd be very >Jose M. MCMC methods such as metropolis-hastings and gibbs sampling can be programmed directly in Mathematica. The algorithms are available in written in S-plus or Xlispstat, but can be modified for Mathematica code. Code can been found on the web. I found a MH algorithem (in S-plus), and have been modifying it to suite each problem as they come up. I can provide the address later if you're interested. There are programs specifically for MCMC. One is BUGS, which is available on the web. A search can easily bring up the address. (search BUGS, Bayesian). I do know of one paper called Bayesian Statistics Using Mathematica in the American Statistician, 1995 vol. 49. Authors Cook and Broemeling. It might be of interest to you in exploring your specific problem. It discusses Monte Carlo integration and sampling-importance-resampling. (but not MCMC exactly) Laura === Subject: Re: Primes (again) > this is probably a naive question, but how does Mathematica give the result of > Prime[k]? Since the numbers are not stored anywhere, and there is no > algorithm to compute them, how does Mathematica produce them? OF COURSE there's an algorithm to compute primes (the Sieve of Eratosthenes, for instance), and how do you KNOW they're not stored anywhere? I have quite a few stored here and there, and probably Mathematica does, too. In fact, according to implementation notes in Help: Prime and PrimePi use sparse caching and sieving. For large n, the Lagarias-Miller-Odlyzko algorithm for PrimePi is used, based on asymptotic estimates of the density of primes, and is inverted to give Prime. I think sparse caching means that some answers are stored in advance. Possibly it works something like this: If we ask for Prime[n] and n ISN'T large in the sense of that paragraph, then {n,Prime[n]} may be pre-stored. If not, the code starts with the nearest pre-stored {k,Prime[k]} and searches (using PrimeQ or NextPrime) until it finds Abs[n-k] consecutive primes. (The same method is used to compute PrimePi in that range, I suppose.) If n is large, an asymptotic estimate of Prime[n] is computed (which may not be prime), a nearby prime p is found (using PrimeQ or NextPrime), and PrimePi is used to find k so that Prime[k] = p. Then, as before, the code has to find Abs[n-k] consecutive primes. Here's a link to what I suppose is the Lagarias-Miller-Odlyzko algorithm: Enjoy! Bobby > this is probably a naive question, but how does Mathematica give the result of > Prime[k]? Since the numbers are not stored anywhere, and there is no > algorithm to compute them, how does Mathematica produce them? > answering my previous questions. > George -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Primes (again) > this is probably a naive question, but how does Mathematica give the > result of > Prime[k]? Since the numbers are not stored anywhere, and there is no > algorithm to compute them, how does Mathematica produce them? > answering my previous questions. > George > -- > -------- > George Szpiro > Neue Z=FCrcher Zeitung (Switzerland) > POB 6278 > Jerusalem 91060 > Israel It uses the function PrimePi and some numerical root finding method like FindRoot. (It is very easy to write such a function yourself). Thus the computation reduces to having a reasonably fast algorithm for PrimePi. There is such an algorithm due to Legendre (using Legendre Sum). All this can be found in most texts on number theory. A good place to look is Bressoud and Wagon A Course Computational Number Theory which is Mathematica based. Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/ === Subject: Re: GUIKit - ScrollPane Tables within Wizard > I am having a few problems getting Widget[Table] to work how i want > within a Widget[ScrollPane] when constructing a wizard. The Table > needs columns for; Name, Colour, Move up, Move down. Basically a list > of objects with associated colours and the ability to move up/down in > the order. > The first thing I have tried to do is resize the table columns > automatically to fit the column headers(or largest entry in the column) > so that the tables are more appropriately distributed. > However, there does not appear to be a command to adjust column width, > only to change the defaut AutoResize from 2(fill screen evenly) to 0 > (leave at default size and use horizontal scroll bar). ... To answer the first question in this email separately... One way to adjust column widths in a table is to set the PreferredWidth and/or MinWidth, MaxWidth and Resizable properties on the columns of the table. The column widgets of a table are available through the ColumnModel of the table. To illustrate this with an example notice the default behavior of the table column width choices that evenly distributes spacing: GUIRun[ Widget[Panel, { Widget[ScrollPane, { PreferredSize -> Widget[Dimension, {Width -> 300, Height -> 110}], ViewportView -> Widget[Table, { Items -> {{A, True, A longer column value}, {B, False, Another longer column value}}, PropertyValue[Model, Name -> myTableModel], SetPropertyValue[{myTableModel, ColumnIdentifiers}, {Index, Active, Description}] }, Name -> myTable] }] }] ] We would really like to have the Description column use most of the spacing and the boolean checkbox column does not need to be resizable from the user standpoint since it doesn't take up much space. Below I show through an extra setup Script how you can get access to the column widgets of the table and then use various combinations of the PreferredWidth, MinWidth, MaxWidth and Resizable properties to control not only whether a column is resizable but ranges of valid widths that the user can use: GUIRun[ Widget[Panel, { Widget[ScrollPane, { PreferredSize -> Widget[Dimension, {Width -> 300, Height -> 110}], ViewportView -> Widget[Table, { Items -> {{A, True, A longer column value}, {B, False, Another longer column value}}, PropertyValue[Model, Name -> myTableModel], SetPropertyValue[{myTableModel, ColumnIdentifiers}, {Index, Active, Description}], PropertyValue[ColumnModel, Name -> columnModel], Script[ col = PropertyValue[{columnModel, Column, 1}]; SetPropertyValue[{col, PreferredWidth}, 50]; SetPropertyValue[{col, MaxWidth}, 50]; SetPropertyValue[{col, Resizable}, True]; col = PropertyValue[{columnModel, Column, 2}]; SetPropertyValue[{col, PreferredWidth}, 50]; SetPropertyValue[{col, MaxWidth}, 50]; SetPropertyValue[{col, MinWidth}, 50]; ] }, Name -> myTable] }] }] ] Jeff Adams Wolfram Research === Subject: Re: Re: GUIKit - ScrollPane Tables within Wizard > Another thing i find useful is to check on variable values. For > example, AutoResize in Java uses AUTO_RESIZE_SUBSEQUENT_COLUMNS, > AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, whereas Mathematioca uses > 2,1,0 for the same values. One feature of GUIKit is to also allow access to static public fields through PropertyValue, so if you prefer 'readable' named code that will also work in the future if the underlying objects decide to change the mapped values you can also do the following: PropertyValue[{myTable, AUTO_RESIZE_SUBSEQUENT_COLUMNS}] instead of 2 or even PropertyValue[{myTable, Auto_Resize_Subsequent_Columns}] since property value names (and event and method names) are case insensitive to provide support for Mathematica's casing standards Jeff Adams Wolfram Research === Subject: Re: Mathematica is not very clever If you use NIntegrate (as your answer is numerical) you get the answer you were looking for, at least in 5.01. Cliff > Mathematica refuses to compute the following > integral: > Integrate [ArcTan[Sqrt[x^2 + 2]]/((x^2 + 1)*Sqrt[x^2 > + 2]), {x, 0, 1}] > Why is that? > The correct result is 5*Pi^2 / 96, which can be > proved. > Klaus G. === Subject: Re: Re: finite domains Paul, However that case fell back in the definition on an already existing infinite domain of the same order namely Z. There is also a similar definition in the Book for Odd numbers. In my case I cannot fall back on an existing finite domain, or I do not know how to explore/exploite it with Boolean. I am thinking of a domain named Irany having elements {North,East,South,West}. How can I do that without a reference to a more basic domain as foundation and expect that Element[NorthWest,Irany] will give me False? J.87nos >> When I look the book I see just infinite built-in domains, like >> Integer etc... I am wondering if finite domains can be created and if >> all the domain related functions would work on it. As an example, I >> have {North, West, South, East} in mind. > To add a domain see The Mathematica Journal 7(4): 450-451. > Paul > -- Paul Abbott Phone: +61 8 6488 2734 > School of Physics, M013 Fax: +61 8 6488 1014 > The University of Western Australia (CRICOS Provider No 00126G) 35 > Stirling Highway > Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA > http://physics.uwa.edu.au/~paul ---------------------------------------------- Trying to argue with a politician is like lifting up the head of a corpse. (S. Lem: His Master Voice) === Subject: Re: All Factors of a number Needs[DiscreteMath`Combinatorica`]; bt=Table[KSubsets[{1,2,3,5},a],{a,3}]; ((Times@@#)&/@#)&/@bt {{1, 2, 3, 5}, {2, 3, 5, 6, 10, 15}, {6, 10, 15, 30}} Bob Hanlon === > Subject: All Factors of a number > Following is a test code that I am trying to get down to a set of > instructions that will allways put all of the factors of a number in a table > or list. > bt contains all of the factors if I multiply each list entry, however I > cannot accomplish that with a single line, as an example I have broken into > the three lists needed for this example. The results of each Times@@ is > what I am after all placed into one table. All of my attempts have proved > disasterous, I am new to Mathematica and could do this with nested loops in > any programming language, but this has me stumped. > Thanx! > < bt=Table[KSubsets[{1,2,3,5},a],{a,3}] > {{{1},{2},{3},{5}},{{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}},{{1,2,3},{1,2,5},{1 > ,3,5},{2,3,5}}} > bt1=bt[[1,All]] > {{1},{2},{3},{5}} > Table[Times@@bt1[[a]],{a,4}] > {1,2,3,5} > bt2=bt[[2,All]] > {{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}} > Table[Times@@bt2[[a]],{a,6}] > {2,3,5,6,10,15} > bt3=bt[[3,All]] > {{1,2,3},{1,2,5},{1,3,5},{2,3,5}} > Table[Times@@bt3[[a]],{a,4}] > {6,10,15,30} === Subject: Re: All Factors of a number A shorter method than my first response: Needs[DiscreteMath`Combinatorica`]; bt=Table[KSubsets[{1,2,3,5},a],{a,3}]; Times@@@#&/@bt {{1, 2, 3, 5}, {2, 3, 5, 6, 10, 15}, {6, 10, 15, 30}} Bob Hanlon === > Subject: Re: All Factors of a number > Needs[DiscreteMath`Combinatorica`]; > bt=Table[KSubsets[{1,2,3,5},a],{a,3}]; > ((Times@@#)&/@#)&/@bt > {{1, 2, 3, 5}, {2, 3, 5, 6, 10, 15}, {6, 10, 15, 30}} > Bob Hanlon > === > Subject: All Factors of a number > > Following is a test code that I am trying to get down to a set of > instructions that will allways put all of the factors of a number in a table > or list. > bt contains all of the factors if I multiply each list entry, however I > cannot accomplish that with a single line, as an example I have broken into > the three lists needed for this example. The results of each Times@@ is > what I am after all placed into one table. All of my attempts have proved > disasterous, I am new to Mathematica and could do this with nested loops > in > any programming language, but this has me stumped. > Thanx! > > < bt=Table[KSubsets[{1,2,3,5},a],{a,3}] > {{{1},{2},{3},{5}},{{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}},{{1,2,3},{1,2,5},{1 > ,3,5},{2,3,5}}} > bt1=bt[[1,All]] > {{1},{2},{3},{5}} > Table[Times@@bt1[[a]],{a,4}] > {1,2,3,5} > bt2=bt[[2,All]] > {{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}} > Table[Times@@bt2[[a]],{a,6}] > {2,3,5,6,10,15} > bt3=bt[[3,All]] > {{1,2,3},{1,2,5},{1,3,5},{2,3,5}} > Table[Times@@bt3[[a]],{a,4}] > {6,10,15,30} > > Bob Hanlon Chantilly, VA === Subject: Re: Re: Mathematica language issues >> In[5]:= >> Unevaluated[1 + 1]*2 >> 2*Unevaluated[1 + 1] >> >> Out[5]= >> 4 >> >> Out[6]= >> 2*Unevaluated[1 + 1] >> > This is not a glitch but works exactly as one woudl expect. You can > see the difference and the reason by looking at Trace in both cases > (although there is no need for that, if you understand Unevaluated you > can see it right away). > First: > 2*Unevaluated[1+1]//Trace > {2 (1+1),2 Unevaluated[1+1]} > First Unevaluated is stipped away and Mathematica attempts ot evaluate > 2*(1+1). Since it knows no rule to apply and the expression has not > changed Unevaluated is restored and evaluation is completed with the > output you see. > Unevaluated[1+1]*2//Trace > {(1+1) 2,2 (1+1),{1+1,2},2 2,4} > As before, first Unevaluated is stripped away and Mathematica tires to > evaluate 2*(1+1). It now knows a rule to apply, which is given by the > Orderless attribute and the canonical ordering, so it converts the > expression into the form 2 (1+1). But now Unevaluated is not restored > because the expression has changed so evaluation continues with 1+1 > evaluationg to 2 and finally you obtain 4. > Now, I have honstly considered this case only because I could see at > once what what was going on. I do not knwo if any of the others are > glitches but jusdging by my experience with the past language > glitches you have reported (unlike the more serious problems desribed > in your last posting) I rather doubt it. However I have no time to > spend on this just to prove a point (again). > Andrzej Kozlowski > Chiba, Japan > http://www.akikoz.net/~andrzej/ > http://www.mimuw.edu.pl/~akoz/ >> I do not agree. Suppose we evaluate z*Unevaluated[1 + 1]; according to >> your explanation, after the reordering of the factors Unevaluated >> should >> disappear from the final result. However, the expression evaluates to >> Unevaluated[1 + 1]*z. Further, suppose we take Unevaluated[1 >> + 1]*Sin[Pi/4]: Sin[Pi/4] evaluates to 1/Sqrt[2], so in this case an >> evaluation step definitely takes place; however, the output is >> Unevaluated[1 + 1]/Sqrt[2]. Your theory simply doesn't work. But even >> if >> it did, there is another problem: suppose I use Sin[Pi/8] instead of >> Sin[Pi/4] -- then first you would need to know whether Mathematica has >> a >> built-in rule for Sin[Pi/8] to arrive at any conclusion as to how it >> might >> work with Unevaluated (that is, what will count as an evaluation >> step?). >> So to apply your explanation we would have to search through all the >> built-in rules of Mathematica. >> Maxim Rytin >> m.r@inbox.ru > The principle behind Unevaluated, which I described above and which > gos like this : strip off Unevaluated, keep applying all known rules to > the expression (without evaluating the part that is supposed to be > Unevaluated) then check if the expression has changed, if not restore > Unevaluated, if yes do not restore it. I have not invented it, it can > be found in several perfectly reliable sources including Michael > Trott's Giudebooks (section 4.7 of the programming volume). > You can go on saying as long as you like that you don't agree wiht this > or that and that you have discovered glitches (as you imagine you > have done in the past with patterns and significance arithmetic) but > that is your and not my problem. It also does not seem to be a problem > for WRI since they rightly continue to ignore it. You seem to think > that anything that you do not understand is a glitch or is wrong. I > have seen people with this attitude and I have long ago learned that it > can't be cured and that its best to just ignore it. > Returning for the last time to this issue: what you have discovered is > not a glitch but one of the many peculiarities of Unevaluated and > also of the (very special) functions Times and Plus. They do not > matter at all to the user because none of the examples you present have > any realistic application. > The point seems to be in deciding when an expression has changed or > has not changed. In this respect as in many others the functions > Times and Plus are peculiar because they treat numerical expressions > and symbolic ones in a different way. > In general, if f is any function with the Orderless attribute f[a,b] > and f[b,a] will be considered as the same expression. Thus; > SetAttributes[g,{Orderless,Flat,OneIdentity}] > Trace[g[ Unevaluated[f[1 , 1]],2]] > {g(f(1,1),2),g(2,f(1,1)),g(2,Unevaluated[f(1,1)])} > Here although the Orderless attribute of g was used in the above to > reverse the order of parameters of g the expression is considered not > to have changed and Unevaluated is restored. > This behaviour however changes when g is one of the functions Times or > Plus: > Block[{g=Times},Trace[g[ Unevaluated[f[1 , 1]],2]]] > {{g,Times},f(1,1) 2,2 f(1,1)} > Block[{g=Plus},Trace[g[ Unevaluated[f[1 , 1]],2]]] > {{g,Plus},f(1,1)+2,f(1,1)+2} > It will not, however, happen when 2 is replace by a symbol: > Block[{g=Times},Trace[g[ Unevaluated[f[1 , 1]],z]]] > {{g,Times},f(1,1) z,z f(1,1),z Unevaluated[f(1,1)]} > Block[{g=Plus},Trace[g[ Unevaluated[f[1 , 1]],z]]] > {{g,Plus},z+f(1,1),z+f(1,1),z+Unevaluated[f(1,1)]} > In other words, the issue amounts to the way Mathematica views the > operation of commuting a number and (effectively) a symbol. In such > cases expressions that differ only in the order of factors are > considered different. Even simpler cases are: > Unevaluated[a]*2 > 2 a > 2*Unevaluated[a] > 2 Unevaluated[a] > and the same with Times, as compared with using two symbols: > Unevaluated[a]*z > Unevaluated[a] z > Unevaluated[z]*a > a Unevaluated[z] > you can even do this: > Times[0,Unevaluated[Infinity]] > Times[Unevaluated[Infinity],0] > Indeterminate expression 0* Infinity encountered. > O.K. so finally so what? Mathematica clearly treats the operation of > adding or multiplying a number and a symbol differently than it does > adding or multiplying two symbols or two numbers. This is not > documented but not really surprising. There are thousands of such > undocumented aspects of Mathematica but this does not matter because > they are totally irrelevant to the user. Nobody is ever going to use > any of the above for any purpose. There is no glitch , there is no > reason to change anything (and nothing will be changed. Your posting > seems to me like a waste of effort, but that is your problem. Reading > it and thinking about it is a waste of time and that is my problem. I > think I shall form now on leave it to those who like this sort of > thing. > Andrzej Kozlowski > Chiba, Japan > http://www.akikoz.net/~andrzej/ > http://www.mimuw.edu.pl/~akoz/ Basically you're saying that it works one way for numbers and another way for symbols, one way for Plus and another way for other Orderless functions; but how does that explain anything? It would be more precise to say that the result depends on whether Mathematica applies any built-in rules on intermediate evaluation steps, but this isn't a sufficient explanation either; consider In[1]:= Unevaluated[2]/Sqrt[2] Unevaluated[Sqrt[2] + Sqrt[2]]/Sqrt[2] Out[1]= Sqrt[2] Out[2]= Unevaluated[Sqrt[2] + Sqrt[2]]/Sqrt[2] In the first case 2/Sqrt[2] is reduced to Sqrt[2], which means that some basic arithmetic rules are applied; in the second case (Sqrt[2] + Sqrt[2])/Sqrt[2] is not reduced to 2, so some basic arithmetic rules are not applied; how can you tell which it's going to be in any given case? Next, compare In[3]:= Unevaluated[Sqrt[2]*(Sqrt[3] + 1)]*Csc[Pi/12] Unevaluated[Sqrt[6] + Sqrt[2]]*Csc[Pi/12] Out[3]= 2*(1 + Sqrt[3])^2 Out[4]= Sqrt[2]*Unevaluated[Sqrt[6] + Sqrt[2]]*(1 + Sqrt[3]) The difference is that in the first case the argument of Unevaluated exactly matches the result of the evaluation of Csc[Pi/12], and Mathematica transforms a*a to a^2; in the second case the argument of Unevaluated is the same numerically but has a different structure, and Mathematica cannot simplify the product further, thus Unevaluated remains. I have to repeat what I said in my previous post: to predict the outcome you need to know exactly what the part which isn't wrapped in Unevaluated evaluates to; in other words, you need to see the output first and only after that you can explain to me why it was exactly the output you had been expecting. Maxim Rytin m.r@inbox.ru === Subject: Re: All Factors of a number > Following is a test code that I am trying to get down to a set of > instructions that will allways put all of the factors of a number in a table > or list. > bt contains all of the factors if I multiply each list entry, however I > cannot accomplish that with a single line, as an example I have broken into > the three lists needed for this example. The results of each Times@@ is > what I am after all placed into one table. All of my attempts have proved > disasterous, I am new to Mathematica and could do this with nested loops in > any programming language, but this has me stumped. > Thanx! > < bt=Table[KSubsets[{1,2,3,5},a],{a,3}] > {{{1},{2},{3},{5}},{{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}},{{1,2,3},{1,2,5},{1 > ,3,5},{2,3,5}}} > bt1=bt[[1,All]] > {{1},{2},{3},{5}} > Table[Times@@bt1[[a]],{a,4}] > {1,2,3,5} > bt2=bt[[2,All]] > {{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}} > Table[Times@@bt2[[a]],{a,6}] > {2,3,5,6,10,15} > bt3=bt[[3,All]] > {{1,2,3},{1,2,5},{1,3,5},{2,3,5}} > Table[Times@@bt3[[a]],{a,4}] > {6,10,15,30} Apply[Times, bt, {2}] {{1, 2, 3, 5}, {2, 3, 5, 6, 10, 15}, {6, 10, 15, 30}} is what you want. Read chapter 2.1.7 in the Mathematica book (Levels in Expressions) - but it's not easy for beginners. Peter -- Peter Pein Berlin === Subject: Re: All Factors of a number > Following is a test code that I am trying to get down to a set of > instructions that will allways put all of the factors of a number in a table > or list. > bt contains all of the factors if I multiply each list entry, however I > cannot accomplish that with a single line, as an example I have broken into > the three lists needed for this example. The results of each Times@@ is > what I am after all placed into one table. All of my attempts have proved > disasterous, I am new to Mathematica and could do this with nested loops in > any programming language, but this has me stumped. > Thanx! > < bt=Table[KSubsets[{1,2,3,5},a],{a,3}] {{{1},{2},{3},{5}},{{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}},{{1,2,3},{1,2,5},{1 > ,3,5},{2,3,5}}} > bt1=bt[[1,All]] > {{1},{2},{3},{5}} > Table[Times@@bt1[[a]],{a,4}] > {1,2,3,5} > bt2=bt[[2,All]] > {{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}} > Table[Times@@bt2[[a]],{a,6}] > {2,3,5,6,10,15} > bt3=bt[[3,All]] > {{1,2,3},{1,2,5},{1,3,5},{2,3,5}} > Table[Times@@bt3[[a]],{a,4}] > {6,10,15,30} In[9]:= Map[Map[Times@@#&,#]&,bt] Out[9]= {{1,2,3,5},{2,3,5,6,10,15},{6,10,15,30}} === Subject: Re: All Factors of a number FactorInteger does this already. Just for grins, here's code to list factorizations of Mersenne numbers in Xmas tree format. toPowers = {{a_Integer, 1} -> HoldForm[a], {a_Integer, b_Integer} -> HoldForm[a]^HoldForm[b], List -> Times}; toStars = StringReplace[ToString[#1 /. toPowers], -> * ] & ; n = 1; {totalTime, results} = Timing[First[Last[Reap[While[n <= 54, p = Prime[n]; Sow[Timing[{n, p, FactorInteger[2^p - 1]}]]; n++]]]]] /. {(s_)*Second, {n_, p_, f_}} :> {n, p, s, toStars[f]}; TableForm[results, TableAlignments -> {Center, Center, Right}, TableHeadings -> {None, {n, p = Prime[n]*1, Seconds, Factors of 2^p-1}}] Print[Total Time: , totalTime] Bobby > Following is a test code that I am trying to get down to a set of > instructions that will allways put all of the factors of a number in a table > or list. > bt contains all of the factors if I multiply each list entry, however I > cannot accomplish that with a single line, as an example I have broken into > the three lists needed for this example. The results of each Times@@ is > what I am after all placed into one table. All of my attempts have proved > disasterous, I am new to Mathematica and could do this with nested loops in > any programming language, but this has me stumped. > Thanx! > < bt=Table[KSubsets[{1,2,3,5},a],{a,3}] > {{{1},{2},{3},{5}},{{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}},{{1,2,3},{1,2,5},{1 > ,3,5},{2,3,5}}} > bt1=bt[[1,All]] > {{1},{2},{3},{5}} > Table[Times@@bt1[[a]],{a,4}] > {1,2,3,5} > bt2=bt[[2,All]] > {{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}} > Table[Times@@bt2[[a]],{a,6}] > {2,3,5,6,10,15} > bt3=bt[[3,All]] > {{1,2,3},{1,2,5},{1,3,5},{2,3,5}} > Table[Times@@bt3[[a]],{a,4}] > {6,10,15,30} -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: All Factors of a number > Following is a test code that I am trying to get down to a set of > instructions that will allways put all of the factors of a number in a > table > or list. > bt contains all of the factors if I multiply each list entry, however I > cannot accomplish that with a single line, as an example I have broken > into > the three lists needed for this example. The results of each Times@@ > is > what I am after all placed into one table. All of my attempts have > proved > disasterous, I am new to Mathematica and could do this with nested > loops in > any programming language, but this has me stumped. > Thanx! > < bt=Table[KSubsets[{1,2,3,5},a],{a,3}] > {{{1},{2},{3},{5}},{{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}},{{1,2,3},{1,2, > 5},{1 > ,3,5},{2,3,5}}} > bt1=bt[[1,All]] > {{1},{2},{3},{5}} > Table[Times@@bt1[[a]],{a,4}] > {1,2,3,5} > bt2=bt[[2,All]] > {{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}} > Table[Times@@bt2[[a]],{a,6}] > {2,3,5,6,10,15} > bt3=bt[[3,All]] > {{1,2,3},{1,2,5},{1,3,5},{2,3,5}} > Table[Times@@bt3[[a]],{a,4}] > {6,10,15,30} Are you trying to define something like: Divisors[30] {1,2,3,5,6,10,15,30} ?? Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/