A64 ==== Subject: Re: Re: Wrong Integral result for a Piecewise function > If you try instead >> g[x_] = FullSimplify[Integrate[UnitStep[2y + 2z - (x - 1)]*UnitStep[x >> - 2y - 2z], {y, 0, 1}, {z, 0, 1}]] (this takes a while to complete) then Plot[g[x],{x,0,5}] looks correct. Also In[18]:= >> NIntegrate[g[x], {x, 0, 5}] Out[18]= >> 1. In[19]:= >> Integrate[g[x], {x, 0, 5}] Out[19]= >> 1 This, of course, is the pre-Mathematica 5 way of doing these things >> which only goes to confirm that progress is not always >> improvement ;-) Andrzej Kozlowski >> Chiba, Japan In version 5.1.0 this gives an answer which is correct everywhere > except > at the integer points: In[1]:= > g[x_] = Integrate[UnitStep[2*y + 2*z - x + 1]*UnitStep[x - 2*y - 2*z], > {y, 0, 1}, {z, 0, 1}] Out[1]= > (1/8)*(2*(-1 + (-2 + x)*x)*UnitStep[1 - x] + 2*(-2 + x)^2*UnitStep > [2 - x] > + 2*(-2 + x)*x*UnitStep[2 - x] - 2*(7 + (-6 + x)*x)*UnitStep[3 - x] > - (-5 > + x)*UnitStep[5 - x]*(6 - 2*x + (-1 + x)*UnitStep[-3 + x]) + > UnitStep[4 - > x]*(-4*UnitStep[1 - x/2] + (-4 + x)*(4 - 2*x + x*UnitStep[-2 + x])) > + (-3 > + x)*UnitStep[3 - x]*(2 - 2*x + (1 + x)*UnitStep[-1 + x]) - 2*(-2 > + x^2)*UnitStep[-x] - (-4 + x^2)*UnitStep[2 - x, x]) In[2]:= > Reduce[g[x] != If[x == 3, 3/8, 0] + If[0 < x < 1, x^2/8, 0] + If[1 > <= x <= > 2, (1/8)*(-1 + 2*x), 0] + If[2 < x < 3, (1/8)*(-9 + 10*x - 2*x^2), 0] > + If[Inequality[3, Less, x, LessEqual, 4], (1/8)*(9 - 2*x), 0] + If > [4 < x > < 5, (1/8)*(-5 + x)^2, 0]] Out[2]= > x == 0 || x == 1 || x == 2 || x == 3 This is always a potential pitfall when the answer is returned as a > sum of > UnitStep terms, e.g. as UnitStep[-x] + (x + 1)*UnitStep[x]. It is > likely > that the value at x = 0 will be incorrect, because both terms are > equal to > 1 at zero, not just one of them. Thus Limit[g[x], x -> 0] is > correct but > g[0] isn't. Maxim Rytin > m.r@inbox.ru This suggests a simple but rather curious remedy. First define gg as above: gg[x_] = FullSimplify[Integrate[UnitStep[2y + 2z - (x - 1)]*UnitStep[x - 2y - 2z], {y, 0, 1}, {z, 0, 1}]]; and then define g simply as: g[x_] := Limit[gg[t], t -> x] This now gives correct answers though the more explicit answer given by the other methods seems clearly preferable. Andrzej Kozlowski Chiba, Japan ==== Subject: Re: Re: Complement replacement This looks at the effect of removing the redundancy from pp before using the complement mechanism pp=Table[Random[Integer,{1,1000}],{1000}]; r=Range[1000]; Timing[Length[c1= Complement[r,pp]]] {0.000913 Second,387} Timing[Length[c2= Select[r,!MemberQ[pp,#]&]]] {0.395094 Second,387} Timing[Length[c3= Cases[r,_?(!MemberQ[pp,#]&)]]] {0.400645 Second,387} Timing[Length[c4= DeleteCases[r,_?(MemberQ[pp,#]&)]]] {0.435794 Second,387} With Complement, removing the redundancy in pp first is detrimental to the overall timing Timing[p=Union[pp];Length[c5= Complement[r,pp]]] {0.00131 Second,387} However, the alternatives show a net improvement Timing[p=Union[pp];Length[c6= Select[r,!MemberQ[p,#]&]]] {0.261277 Second,387} Timing[p=Union[pp];Length[c7= Cases[r,_?(!MemberQ[p,#]&)]]] {0.267076 Second,387} Timing[p=Union[pp];Length[c8= DeleteCases[r,_?(MemberQ[p,#]&)]]] {0.261073 Second,387} c1==c2==c3==c4==c5==c6==c7==c8 True Bob Hanlon > ==== > Subject: Re: Complement replacement pp=Table[Random[Integer,{1,1000}],{1000}]; r=Range[1000]; Timing[Length[c1= > Complement[r,pp]]] {0.000934 Second,368} Timing[Length[c2= > Select[r,!MemberQ[pp,#]&]]] {0.39567 Second,368} Timing[Length[c3= > Cases[r,_?(!MemberQ[pp,#]&)]]] {0.401009 Second,368} Timing[Length[c4= > DeleteCases[r,_?(MemberQ[pp,#]&)]]] {0.401319 Second,368} c1==c2==c3==c4 True > Bob Hanlon ==== > Subject: Complement replacement hi > in the list: > pp=Table[Random[Integer, {1, 1000}], {i, 1000}]; > how could i know which numbers from 1 to 1000 does not exist in the > pp List. > but without using: > Complement[Table[i,{i,1000}],pp] > Bob Hanlon Chantilly, VA ==== Subject: Re: Updated my RootSearch package I, too, just updated RootSearch to the latest version from MathSource, and none of the examples in RootSearchExamples.nb gives an empty list. Note that the new version is installed as ExtraPackages`Ersek`RootSearch whereas the previous version was set up as ExtraPackages`Enhancements`RootSearch`. Do you by any chance still have the older version in that latter location? First, thank you for your work over the years on Mathematica. I'm a > relatively new user of Mathematica, but I'm always happy when I notice > that you've given some input (or, better, a notebook or package) about a > problem. > I've downloaded and installed your new RootSearch.m file, and am > trying to run the examples notebook. The package is correctly installed > and loads correctly (I think) because I can query its various functions; > in addition, if I call RootSearch on a function, there are no errors > generated. However, even in the cases in your example notebook, > RootSearch returns empty lists where it should return the roots of the > functions. I will go through the RootSearch.m file in a bit more detail > later, to see what I'm doing wrong, or if there is an extra semicolon > somewhere (or something!) but wanted to post this in case there's a > quick fix. Curtis O. >I just updated my RootSearch package which is posted on MathSource. >>You can get it from >> http://library.wolfram.com/infocenter/MathSource/4482/ The new version is more robust. Ted Ersek >> reply to: ted.ersek@navy.mil >> -- 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: GraphEdit.m & JavaGraphics.m [Note that version 5.2 is not an official release and so any comments about it should be considered preliminary - moderator] The reason I asked about GraphEdit.m and JavaGraphics.m is that they do not appear among the files in the new Mathematica version 5.2. And in 5.2 I did not find any function SetGraphics or ResetGraphics. Nor could I find any documentation about this change. (In fact, the What's New in Version 5.2 is annoyingly vague, with not a single hyperlink on the list of performance improvements and a last, vague item And many more enhancements & innovations.) > What are the packages GraphEdit.m and JavaGraphics.m that I find in >> the directory >> >> ToFileName[{$InstallationDirectory,SystemFiles,Graphics,Packages} ] of Mathematica 5.1? Are they part of the Mathematica 5.1 distribution? Or from some 3rd >> party Add-on? Hi Murray, Both _GraphEdit.m_ and _JavaGraphics.m_ packages are part of Mathematica > standard installation. _GraphEdit.m_ is said to render graphics with V5 front end, and > contains two functions: *SetGraphics* and *ResetGraphics*. The usage > massages read, respectively: SetGraphics[type] sets the type of graphics cells generated by graphics > commands. type may be SymbolicGraphics, PostScript, or > Compare, and ResetGraphics[] restores the display function used before the GraphEdit > package was loaded. According to the *ReadMe.txt* file located in the packages directory: > This directory contains files called by version-specific init.m files. > Most of them set up the correct mode for display of graphics on > different machines. [...] JavaGraphics.m : send graphics to Java > window. /J.M. -- 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: Mathematica: how to set the format of binary numbers in plotting? > I use BinaryReadList[filename, Integer16] to bring in an array of > numbers. I then do a bunch of operations on these numbers and then try > to plot them. They should be signed integers and interpreted in 2's > complement but apparently they have been converted to unsigned binary as > far as I can tell -- and the plots are horrible. Can someone tell me how you can specify the interpretation (signed or > Hi 1.156 :-) I do not think that the issue has anything to do with the plot command. Within Mathematica, the notions of signed, unsigned, long, double, char, etc. are irrelevant. The Mathematica language does not possess the notion of types, as you would find it in languages such as C, C++ or Java for instance, although it makes a clear distinction among exact, machine precision and arbitrary-precision arithmetic. To answer the last part of your question, you have no way of telling *ListPlot* that the numbers are signed or unsigned. Having said that, I strongly suspect that the problem comes either from the data file you have imported (corrupted, not in the expected format) or that it was created on another hardware platform, such as a Macintosh, which uses a different byte ordering (the most significant bit can be stored first or at the end of the word, think about that as sorting the most significant bits in ascending or descending order, or from left to right or vice versa). First you should check immediately after importing the data file that the numbers are what you have expected and/or change the bit ordering by using the option ByteOrdering -> -$ByteOrdering. See the example in http://documents.wolfram.com/mathematica/book/section-2.12.11 Hope this helps, /J.M. ==== Subject: Re: Mathematica: how to set the format of binary numbers in plotting? > I use BinaryReadList[filename, Integer16] to bring in an array of > numbers. I then do a bunch of operations on these numbers and then try > to plot them. They should be signed integers and interpreted in 2's > complement but apparently they have been converted to unsigned binary as > far as I can tell -- and the plots are horrible. Can someone tell me how you can specify the interpretation (signed or > Try to play around with the option ByteOrdering: BinaryReadList[filename, Integer16, ByteOrdering->-1], if the file has been written on a x86 machine (or any other Processor using little endian) and ByteOrdering->1 for the others. Hope this helps, Peter -- http://people.freenet.de/Peter_Berlin/ ==== Subject: Re: MultiLink.exe, MultiLinkServer.exe > What are the files MultiLink.exe and MultiLinkServer.exe that I find in > the root Mathematica 5.1 program directory? Are they part of the Mathematica 5.1 distribution? Or from some 3rd > party Add-on? > Hi Murray, I am not sure about MultiLink.exe (although I would dare a wild guess and say that they are related to the same application :-) but MultiLinkServer.exe is provided by the extra add-in package _Mathematica Link for Excel_, see the support note http://support.wolfram.com/applicationpacks/excel_link/multilinkserver.html /J.M. ==== Subject: Re: MultiLink.exe, MultiLinkServer.exe I just remembered what they are: Part of the Mathematica Link for Excel add-on. I do wish that authors of all windows .exe files would embed identification as to Company, File Version, Interla Name, etc. author so that they are visible on the Version tab of the file's Properties in Windows. (These two .exe's hav no such identification.) (That's one of several annoyances due to thoughtlessness on the part of software publishers.) > What are the files MultiLink.exe and MultiLinkServer.exe that I find in > the root Mathematica 5.1 program directory? Are they part of the Mathematica 5.1 distribution? Or from some 3rd > party Add-on? > -- 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: Complement replacement I suspect that from the solutions offered below you mean the procedural oriented paradigm which is given by the last solution. note, that fisrt it is recommended to Sort[] your table. This is usually done in O(n Log[2,n]) run time complexity and will improve any solution that you will choose to use later. I'm also sure that you will get many other solutions and approaches For the code offered below, the result is given in variable res, and the rest is to compare the run time (ignoring sorting that all rely on). sp = Sort[pp = Array[Random[Integer, {1, 1000}] &, 1000]]; (res = Table[If[! MemberQ[sp, i], i], {i, 1000}] // Union // Most) // Timing // First (res = Reap[Do[If[! MemberQ[sp, i], Sow[i]], {i, 1000}]] // Rest // Flatten) // Timing // First (res = Reap[Do[If[! MemberQ[sp, i], Sow[i]], {i, 1000}]] // Rest // Flatten) // Timing // First k = 1; (res = Rest[Reap[(While[k < #, If[++k < #, Sow[k]]]) & /@ sp]] // First // Flatten) // Timing // First The running times that I got on my computer for the specific example genrated by the rundom numbers are: 0.22 Second 0.191 Second 0.18 Second 0.01 Second yehuda > hi > in the list: > pp=Table[Random[Integer, {1, 1000}], {i, 1000}]; > how could i know which numbers from 1 to 1000 does not exist in the > pp List. > but without using: > Complement[Table[i,{i,1000}],pp] ==== Subject: Re: Complement replacement > hi > in the list: > pp=Table[Random[Integer, {1, 1000}], {i, 1000}]; > how could i know which numbers from 1 to 1000 does not exist in the > pp List. > but without using: > Complement[Table[i,{i,1000}],pp] > I am not sure to understand why you would not like to use such an efficient function as *Complement* to solve your problem (homework assignment perhaps?); anyway rather than a functional approach such as In[1]:= pp = Table[Random[Integer, {1, 10}], {i, 10}] Out[1]= {9, 1, 8, 4, 7, 2, 8, 3, 10, 8} In[2]:= Complement[Range[10], pp] Out[2]= {5, 6} you could use a procedural design for instance In[3]:= res = {}; i = 1; While[i <= Length[pp], j = 1; notInPP = True; While[j <= Length[pp] && notInPP == True, If[i == pp[[j]], notInPP = False]; j++; ]* If[notInPP == True, AppendTo[res, i]]; i++; ] res Out[6]= {5, 6} Now if you are looking for speed of execution (and also of coding), the functional approach is definitely better and much much faster. For example, In[7]:= pp = Table[Random[Integer, {1, 1000}], {i, 1000}]; In[8]:= Timing[Complement[Range[Length[pp]], pp]; ] Out[8]= {0.*Second, Null} In[9]:= Timing[res = {}; i = 1; While[i <= Length[pp], j = 1; notInPP = True; While[j <= Length[pp] && notInPP == True, If[i == pp[[j]], notInPP = False]; j++; ]* If[notInPP == True, AppendTo[res, i]]; i++; ]* res; ] Out[9]= {4.141*Second, Null} and here with a code slightly optimized (we sort the list pp and discard any duplicates before the main loop and also we use the functions *Reap* and *Sow* rather than *AppendTo*) In[10]:= Timing[i = 1; pp = Union[pp]; Reap[While[i <= 1000, j = 1; notInPP = True; While[j <= Length[pp] && notInPP == True, If[i == pp[[j]], notInPP = False]; j++; ]* If[notInPP == True, Sow[i]]; i++; ]]; ] Out[10]= {2.8120000000000003*Second, Null} In[11]:= $Version Out[11]= 5.1 for Microsoft Windows (January 27, 2005) Hope this helps, /J.M. ==== Subject: Re: Complement replacement > hi > in the list: > pp=Table[Random[Integer, {1, 1000}], {i, 1000}]; > how could i know which numbers from 1 to 1000 does not exist in the > pp List. > but without using: > Complement[Table[i,{i,1000}],pp] > Please tell us why you want to do so. Cleaning up and generating testing data (I took a million values instead of thousand for distinguishable timings): In[1]:= Clear[n, pp, missing]; n = 10^6; pp = Table[Random[Integer, {1, n}], {n}]; just as reference timing: First[Timing[missing[1] = Complement[Range[n], pp]; ]] Out[4]= 0.844*Second Sort the random list joined with the whole range, sort and split this list and get the unique elements: In[5]:= First[Timing[missing[2] = Cases[Split[Sort[Join[pp, Range[n]]]], {x_Integer} :> x]; ]] Out[5]= 1.875*Second Method 'mind the gap' ;-) : Build ranges out of the gaps in the random list: In[6]:= First[Timing[missing[3] = Inner[Range, Drop[#1, -1] + 1, Drop[#1, 1] - 1, Join]& [Union[pp, {0, n + 1}]]; ]] Out[6]= 1.609*Second Verification: In[7]:= SameQ @@ missing /@ {1, 2, 3} Out[7]= True -- http://people.freenet.de/Peter_Berlin/ ==== Subject: Re: Complement replacement > hi > in the list: > pp=Table[Random[Integer, {1, 1000}], {i, 1000}]; > how could i know which numbers from 1 to 1000 does not exist in the > pp List. > but without using: > Complement[Table[i,{i,1000}],pp] Perhaps you should explain why you do not want to use Complement as it will be very hard if not impossible to match its performance. Indeed, on ny machine I get: In[1]:= pp=Table[Random[Integer, {1, 1000}], {i, 1000}]; In[2]:= a=Complement[Range[1000],pp];//Timing Out[2]= {0.001657 Second,Null} while using the most obvious alternative: In[3]:= b=Select[Range[1000],Not[MemberQ[pp,#]]&];//Timing Out[3]= {0.408538 Second,Null} In[4]:= Union[b]==a Out[4]= True The difference in performance is huge. There are a number of ways that give a better performance but I can't find any that beets Complement. Here s one that is at least better than the most obvious way above. First define a function f: SetAttributes[f, Listable] Scan[(f[#]=Sequence[])&,pp];//Timing {0.020849 Second,Null} f[x_] := x (note that evaluating this defintion itself takes more time than running Complement) now: In[8]:= c=f[Range[1000]];//Timing Out[8]= {0.008274 Second,Null} In[9]:= Union[c]==a Out[9]= True Andrzej Kozlowski Chiba, Japan ==== Subject: Re: Complement replacement If you are looking to improve on the speed of Complement, ignore this solution. It's way too slow, but does avoid using Complement. In[20]:= pp = Table[Random[Integer, {1, 1000}], {i, 1000}]; In[21]:= r1 = Complement[Range[1000], pp]; In[22]:= r2 = Range[1000] //. ({p___, #1, q___} :> {p, q} & ) /@ pp; In[23]:= r1 == r2 Out[23]= True > hi > in the list: > pp=Table[Random[Integer, {1, 1000}], {i, 1000}]; > how could i know which numbers from 1 to 1000 does not exist in the > pp List. > but without using: > Complement[Table[i,{i,1000}],pp] *********************************** Ken Levasseur Mathematical Sciences UML http://faculty.uml.edu/klevasseur ==== Subject: Re: Complement replacement pp=Table[Random[Integer,{1,1000}],{1000}]; r=Range[1000]; Timing[Length[c1= Complement[r,pp]]] {0.000934 Second,368} Timing[Length[c2= Select[r,!MemberQ[pp,#]&]]] {0.39567 Second,368} Timing[Length[c3= Cases[r,_?(!MemberQ[pp,#]&)]]] {0.401009 Second,368} Timing[Length[c4= DeleteCases[r,_?(MemberQ[pp,#]&)]]] {0.401319 Second,368} c1==c2==c3==c4 True Bob Hanlon > ==== > Subject: Complement replacement hi > in the list: > pp=Table[Random[Integer, {1, 1000}], {i, 1000}]; > how could i know which numbers from 1 to 1000 does not exist in the > pp List. > but without using: > Complement[Table[i,{i,1000}],pp] ==== Subject: Re: SeedRandom and $SessionID > Hi Everyone, I'm doing some Monte-Carlo simulations on a cluster. Since by default > the random number seed is based on the system time, I sometimes get the > same seed being used in multiple Kernels if they're launched > simultaneously from a shell script (something to avoid). Is there any > danger in using $SessionID as the random number seed? Also, does anyone > know the bounds on $SessionID (compared to the bounds on the random > number seed) are and whether the processID is included in the > calculation of $SessionID? Alternatively, has anyone worked out a good > way to seed the random number generator in Mathematica? -Kerry Kim > Hi Kerry, Since *SeedRandom* can use a string as parameter, you can build a seed with a combination of absolute time and specific machine/session/process information. For example In[1]:= $MachineID Out[1]= 6102-07761-35533 In[2]:= $ProcessID Out[2]= 2692 In[3]:= $SessionID Out[3]= 21823539906304522724 In[4]:= seed = StringJoin[$MachineID, ToString[$SessionID], ToString[$ProcessID], ToString[AbsoluteTime[]]] Out[4]= 6102-07761-35533218235399063045227242692 9n3.3300079210000000 10 In[5]:= SeedRandom[seed] In[6]:= Random[] Out[6]= 0.38715300837241634 Hope this helps, /J.M. ==== Subject: FrameTicks bug Well, I guess it's not actually a bug, but . . . FrameTicks -> {Automatic, Automatic, None, None} puts tick marks AND numerical labels on bottom and left edges. FrameTicks -> {None, Automatic, Automatic, None} puts tick marks and numerical labels on left edge, tick marks and NO NUMERICAL LABELS on top edge. How can I put the same Automatic numbers that would have been created for the bottom edge, on the top edge? ==== Subject: Re: Mathematica: how to set the format of binary numbers in plotting? >I use BinaryReadList[filename, Integer16] to bring in an array of >numbers. I then do a bunch of operations on these numbers and then >try to plot them. They should be signed integers and interpreted in >2's complement but apparently they have been converted to unsigned >binary as far as I can tell -- and the plots are horrible. >Can someone tell me how you can specify the interpretation (signed >or unsigned) of numbers before they are used in ListPlot[] ? The determination as to whether the data is signed or unsigned is made by BinaryReadList not ListPlot. Using type Integer16, reads the data as signed 16 bit integers. If you want to treat the file as unsigned, you need to use type UnsignedInteger16 in place of Integer16. -- To reply via email subtract one hundred and four ==== Subject: Re: Complement replacement >hi in the list: pp=Table[Random[Integer, {1, 1000}], {i, 1000}]; >how could i know which numbers from 1 to 1000 does not exist in the >pp List. but without using: Complement[Table[i,{i,1000}],pp] You could use Complement[Range@1000,pp] which is probably a bit more efficient. And if you wanted you could find ways to achieve the same result without using Complement. For example, Split[Union@pp,#2-#1&] will group the set of numbers into blocks of contiguous integers. The missing integers could be found by looking at the last value of a block and the first value of the next block. But this is undoubtedly more computation than simply using Complement with Range as above. -- To reply via email subtract one hundred and four ==== Subject: Re: Complement replacement my previous question was submitted, because at first i do not know about the Complement function, i know that a function like this must be in the Union, Intersection family, but somehow i have not noticed pp = Table[Random[Integer, {1, 1000}], {i, 1000}]; r = Table[i,{i,1000}]; (lst = {}; Do[If[MemberQ[pp, r[[i]]] == False, lst = Join[lst, {r[[i]]}]; ] , {i, 1, Length[pp]}]; lst = Union[lst, lst];) // Timing {0.22 Second, Null} on P4 2 GHz 128k cache 256M ram after i have written my letter i have discovered the Complement function, and noticed its speed, so i keep my original message to compare different strategies and methods which may presented by this group marvelous contributors book) ==== Subject: Re: Complement replacement > hi > in the list: > pp=Table[Random[Integer, {1, 1000}], {i, 1000}]; > how could i know which numbers from 1 to 1000 does not exist in the > pp List. > but without using: > Complement[Table[i,{i,1000}],pp] Perhaps you should explain why you do not want to use Complement as it will be very hard if not impossible to match its performance. Indeed, on ny machine I get: In[1]:= pp=Table[Random[Integer, {1, 1000}], {i, 1000}]; In[2]:= a=Complement[Range[1000],pp];//Timing Out[2]= {0.001657 Second,Null} while using the most obvious alternative: In[3]:= b=Select[Range[1000],Not[MemberQ[pp,#]]&];//Timing Out[3]= {0.408538 Second,Null} In[4]:= Union[b]==a Out[4]= True The difference in performance is huge. There are a number of ways that give a better performance but I can't find any that beets Complement. Here s one that is at least better than the most obvious way above. First define a function f: SetAttributes[f, Listable] Scan[(f[#]=Sequence[])&,pp];//Timing {0.020849 Second,Null} f[x_] := x (note that evaluating this defintion itself takes more time than running Complement) now: In[8]:= c=f[Range[1000]];//Timing Out[8]= {0.008274 Second,Null} In[9]:= Union[c]==a Out[9]= True Andrzej Kozlowski Chiba, Japan > Peter Pein : > Please tell us why you want to do so. Cleaning up and generating testing data (I took a million values instead > of thousand for distinguishable timings): In[1]:= Clear[n, pp, missing]; > n = 10^6; > pp = Table[Random[Integer, {1, n}], {n}]; just as reference timing: First[Timing[missing[1] = Complement[Range[n], pp]; ]] > Out[4] 0.844*Second Sort the random list joined with the whole range, sort and split this > list and get the unique elements: In[5]: First[Timing[missing[2] Cases[Split[Sort[Join[pp, Range [n]]]], > {x_Integer} :> x]; > ]] > Out[5] 1.875*Second Method 'mind the gap' ;-) : > Build ranges out of the gaps in the random list: In[6]:First[Timing[missing[3] Inner[Range, Drop[#1, -1] + 1, Drop [#1, 1] > - 1, Join]& > [Union[pp, {0, n + 1}]]; > ]] > Out[6] 1.609*Second Verification: In[7]: SameQ @@ missing /@ {1, 2, 3} > Out[7] True -- > Peter Pein > Berlin > http://people.freenet.de/Peter_Berlin/ >